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: 20 75 6e 6c 65 73 73 20 70 72 65 76 65 6e 74 65 unless prevente
1a90: 64 20 62 79 0a 2a 2a 20 74 68 65 20 53 51 4c 49 d by.** the SQLI
1aa0: 54 45 5f 44 49 53 41 42 4c 45 5f 49 4e 54 52 49 TE_DISABLE_INTRI
1ab0: 4e 53 49 43 20 64 65 66 69 6e 65 2e 0a 2a 2f 0a NSIC define..*/.
1ac0: 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
1ad0: 49 54 45 5f 44 49 53 41 42 4c 45 5f 49 4e 54 52 ITE_DISABLE_INTR
1ae0: 49 4e 53 49 43 29 0a 23 20 20 69 66 20 64 65 66 INSIC).# if def
1af0: 69 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 ined(_MSC_VER) &
1b00: 26 20 5f 4d 53 43 5f 56 45 52 3e 3d 31 33 30 30 & _MSC_VER>=1300
1b10: 0a 23 20 20 20 20 69 66 20 21 64 65 66 69 6e 65 .# if !define
1b20: 64 28 5f 57 49 4e 33 32 5f 57 43 45 29 0a 23 20 d(_WIN32_WCE).#
1b30: 20 20 20 20 20 69 6e 63 6c 75 64 65 20 3c 69 6e include <in
1b40: 74 72 69 6e 2e 68 3e 0a 23 20 20 20 20 20 20 70 trin.h>.# p
1b50: 72 61 67 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 ragma intrinsic(
1b60: 5f 62 79 74 65 73 77 61 70 5f 75 73 68 6f 72 74 _byteswap_ushort
1b70: 29 0a 23 20 20 20 20 20 20 70 72 61 67 6d 61 20 ).# pragma
1b80: 69 6e 74 72 69 6e 73 69 63 28 5f 62 79 74 65 73 intrinsic(_bytes
1b90: 77 61 70 5f 75 6c 6f 6e 67 29 0a 23 20 20 20 20 wap_ulong).#
1ba0: 65 6c 73 65 0a 23 20 20 20 20 20 20 69 6e 63 6c else.# incl
1bb0: 75 64 65 20 3c 63 6d 6e 69 6e 74 72 69 6e 2e 68 ude <cmnintrin.h
1bc0: 3e 0a 23 20 20 20 20 65 6e 64 69 66 0a 23 20 20 >.# endif.#
1bd0: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a endif.#endif../*
1be0: 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 54 .** The SQLITE_T
1bf0: 48 52 45 41 44 53 41 46 45 20 6d 61 63 72 6f 20 HREADSAFE macro
1c00: 6d 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 20 must be defined
1c10: 61 73 20 30 2c 20 31 2c 20 6f 72 20 32 2e 0a 2a as 0, 1, or 2..*
1c20: 2a 20 30 20 6d 65 61 6e 73 20 6d 75 74 65 78 65 * 0 means mutexe
1c30: 73 20 61 72 65 20 70 65 72 6d 61 6e 65 6e 74 6c s are permanentl
1c40: 79 20 64 69 73 61 62 6c 65 20 61 6e 64 20 74 68 y disable and th
1c50: 65 20 6c 69 62 72 61 72 79 20 69 73 20 6e 65 76 e library is nev
1c60: 65 72 0a 2a 2a 20 74 68 72 65 61 64 73 61 66 65 er.** threadsafe
1c70: 2e 20 20 31 20 6d 65 61 6e 73 20 74 68 65 20 6c . 1 means the l
1c80: 69 62 72 61 72 79 20 69 73 20 73 65 72 69 61 6c ibrary is serial
1c90: 69 7a 65 64 20 77 68 69 63 68 20 69 73 20 74 68 ized which is th
1ca0: 65 20 68 69 67 68 65 73 74 0a 2a 2a 20 6c 65 76 e highest.** lev
1cb0: 65 6c 20 6f 66 20 74 68 72 65 61 64 73 61 66 65 el of threadsafe
1cc0: 74 79 2e 20 20 32 20 6d 65 61 6e 73 20 74 68 65 ty. 2 means the
1cd0: 20 6c 69 62 72 61 72 79 20 69 73 20 6d 75 6c 74 library is mult
1ce0: 69 74 68 72 65 61 64 65 64 20 2d 20 6d 75 6c 74 ithreaded - mult
1cf0: 69 70 6c 65 0a 2a 2a 20 74 68 72 65 61 64 73 20 iple.** threads
1d00: 63 61 6e 20 75 73 65 20 53 51 4c 69 74 65 20 61 can use SQLite a
1d10: 73 20 6c 6f 6e 67 20 61 73 20 6e 6f 20 74 77 6f s long as no two
1d20: 20 74 68 72 65 61 64 73 20 74 72 79 20 74 6f 20 threads try to
1d30: 75 73 65 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 use the same.**
1d40: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
1d50: 69 6f 6e 20 61 74 20 74 68 65 20 73 61 6d 65 20 ion at the same
1d60: 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 4f 6c 64 65 time..**.** Olde
1d70: 72 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 53 51 r versions of SQ
1d80: 4c 69 74 65 20 75 73 65 64 20 61 6e 20 6f 70 74 Lite used an opt
1d90: 69 6f 6e 61 6c 20 54 48 52 45 41 44 53 41 46 45 ional THREADSAFE
1da0: 20 6d 61 63 72 6f 2e 0a 2a 2a 20 57 65 20 73 75 macro..** We su
1db0: 70 70 6f 72 74 20 74 68 61 74 20 66 6f 72 20 6c pport that for l
1dc0: 65 67 61 63 79 2e 0a 2a 2f 0a 23 69 66 20 21 64 egacy..*/.#if !d
1dd0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 48 efined(SQLITE_TH
1de0: 52 45 41 44 53 41 46 45 29 0a 23 20 69 66 20 64 READSAFE).# if d
1df0: 65 66 69 6e 65 64 28 54 48 52 45 41 44 53 41 46 efined(THREADSAF
1e00: 45 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 E).# define SQ
1e10: 4c 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 20 LITE_THREADSAFE
1e20: 54 48 52 45 41 44 53 41 46 45 0a 23 20 65 6c 73 THREADSAFE.# els
1e30: 65 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c e.# define SQL
1e40: 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 20 31 ITE_THREADSAFE 1
1e50: 20 2f 2a 20 49 4d 50 3a 20 52 2d 30 37 32 37 32 /* IMP: R-07272
1e60: 2d 32 32 33 30 39 20 2a 2f 0a 23 20 65 6e 64 69 -22309 */.# endi
1e70: 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 f.#endif../*.**
1e80: 50 6f 77 65 72 73 61 66 65 20 6f 76 65 72 77 72 Powersafe overwr
1e90: 69 74 65 20 69 73 20 6f 6e 20 62 79 20 64 65 66 ite is on by def
1ea0: 61 75 6c 74 2e 20 20 42 75 74 20 63 61 6e 20 62 ault. But can b
1eb0: 65 20 74 75 72 6e 65 64 20 6f 66 66 20 75 73 69 e turned off usi
1ec0: 6e 67 0a 2a 2a 20 74 68 65 20 2d 44 53 51 4c 49 ng.** the -DSQLI
1ed0: 54 45 5f 50 4f 57 45 52 53 41 46 45 5f 4f 56 45 TE_POWERSAFE_OVE
1ee0: 52 57 52 49 54 45 3d 30 20 63 6f 6d 6d 61 6e 64 RWRITE=0 command
1ef0: 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 2e 0a 2a 2f -line option..*/
1f00: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
1f10: 50 4f 57 45 52 53 41 46 45 5f 4f 56 45 52 57 52 POWERSAFE_OVERWR
1f20: 49 54 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ITE.# define SQL
1f30: 49 54 45 5f 50 4f 57 45 52 53 41 46 45 5f 4f 56 ITE_POWERSAFE_OV
1f40: 45 52 57 52 49 54 45 20 31 0a 23 65 6e 64 69 66 ERWRITE 1.#endif
1f50: 0a 0a 2f 2a 0a 2a 2a 20 45 56 49 44 45 4e 43 45 ../*.** EVIDENCE
1f60: 2d 4f 46 3a 20 52 2d 32 35 37 31 35 2d 33 37 30 -OF: R-25715-370
1f70: 37 32 20 4d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 72 Memory alloca
1f80: 74 69 6f 6e 20 73 74 61 74 69 73 74 69 63 73 20 tion statistics
1f90: 61 72 65 20 65 6e 61 62 6c 65 64 20 62 79 0a 2a are enabled by.*
1fa0: 2a 20 64 65 66 61 75 6c 74 20 75 6e 6c 65 73 73 * default unless
1fb0: 20 53 51 4c 69 74 65 20 69 73 20 63 6f 6d 70 69 SQLite is compi
1fc0: 6c 65 64 20 77 69 74 68 20 53 51 4c 49 54 45 5f led with SQLITE_
1fd0: 44 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 DEFAULT_MEMSTATU
1fe0: 53 3d 30 20 69 6e 0a 2a 2a 20 77 68 69 63 68 20 S=0 in.** which
1ff0: 63 61 73 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f case memory allo
2000: 63 61 74 69 6f 6e 20 73 74 61 74 69 73 74 69 63 cation statistic
2010: 73 20 61 72 65 20 64 69 73 61 62 6c 65 64 20 62 s are disabled b
2020: 79 20 64 65 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 y default..*/.#i
2030: 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 f !defined(SQLIT
2040: 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 E_DEFAULT_MEMSTA
2050: 54 55 53 29 0a 23 20 64 65 66 69 6e 65 20 53 51 TUS).# define SQ
2060: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d LITE_DEFAULT_MEM
2070: 53 54 41 54 55 53 20 31 0a 23 65 6e 64 69 66 0a STATUS 1.#endif.
2080: 0a 2f 2a 0a 2a 2a 20 45 78 61 63 74 6c 79 20 6f ./*.** Exactly o
2090: 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ne of the follow
20a0: 69 6e 67 20 6d 61 63 72 6f 73 20 6d 75 73 74 20 ing macros must
20b0: 62 65 20 64 65 66 69 6e 65 64 20 69 6e 20 6f 72 be defined in or
20c0: 64 65 72 20 74 6f 0a 2a 2a 20 73 70 65 63 69 66 der to.** specif
20d0: 79 20 77 68 69 63 68 20 6d 65 6d 6f 72 79 20 61 y which memory a
20e0: 6c 6c 6f 63 61 74 69 6f 6e 20 73 75 62 73 79 73 llocation subsys
20f0: 74 65 6d 20 74 6f 20 75 73 65 2e 0a 2a 2a 0a 2a tem to use..**.*
2100: 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 53 59 53 * SQLITE_SYS
2110: 54 45 4d 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 TEM_MALLOC
2120: 20 20 20 20 2f 2f 20 55 73 65 20 6e 6f 72 6d 61 // Use norma
2130: 6c 20 73 79 73 74 65 6d 20 6d 61 6c 6c 6f 63 28 l system malloc(
2140: 29 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f ).** SQLITE_
2150: 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 20 20 20 20 WIN32_MALLOC
2160: 20 20 20 20 20 20 20 2f 2f 20 55 73 65 20 57 69 // Use Wi
2170: 6e 33 32 20 6e 61 74 69 76 65 20 68 65 61 70 20 n32 native heap
2180: 41 50 49 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 API.** SQLIT
2190: 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 20 20 20 E_ZERO_MALLOC
21a0: 20 20 20 20 20 20 20 20 20 2f 2f 20 55 73 65 20 // Use
21b0: 61 20 73 74 75 62 20 61 6c 6c 6f 63 61 74 6f 72 a stub allocator
21c0: 20 74 68 61 74 20 61 6c 77 61 79 73 20 66 61 69 that always fai
21d0: 6c 73 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 ls.** SQLITE
21e0: 5f 4d 45 4d 44 45 42 55 47 20 20 20 20 20 20 20 _MEMDEBUG
21f0: 20 20 20 20 20 20 20 20 2f 2f 20 44 65 62 75 67 // Debug
2200: 67 69 6e 67 20 76 65 72 73 69 6f 6e 20 6f 66 20 ging version of
2210: 73 79 73 74 65 6d 20 6d 61 6c 6c 6f 63 28 29 0a system malloc().
2220: 2a 2a 0a 2a 2a 20 4f 6e 20 57 69 6e 64 6f 77 73 **.** On Windows
2230: 2c 20 69 66 20 74 68 65 20 53 51 4c 49 54 45 5f , if the SQLITE_
2240: 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 5f 56 41 4c WIN32_MALLOC_VAL
2250: 49 44 41 54 45 20 6d 61 63 72 6f 20 69 73 20 64 IDATE macro is d
2260: 65 66 69 6e 65 64 20 61 6e 64 20 74 68 65 0a 2a efined and the.*
2270: 2a 20 61 73 73 65 72 74 28 29 20 6d 61 63 72 6f * assert() macro
2280: 20 69 73 20 65 6e 61 62 6c 65 64 2c 20 65 61 63 is enabled, eac
2290: 68 20 63 61 6c 6c 20 69 6e 74 6f 20 74 68 65 20 h call into the
22a0: 57 69 6e 33 32 20 6e 61 74 69 76 65 20 68 65 61 Win32 native hea
22b0: 70 20 73 75 62 73 79 73 74 65 6d 0a 2a 2a 20 77 p subsystem.** w
22c0: 69 6c 6c 20 63 61 75 73 65 20 48 65 61 70 56 61 ill cause HeapVa
22d0: 6c 69 64 61 74 65 20 74 6f 20 62 65 20 63 61 6c lidate to be cal
22e0: 6c 65 64 2e 20 20 49 66 20 68 65 61 70 20 76 61 led. If heap va
22f0: 6c 69 64 61 74 69 6f 6e 20 73 68 6f 75 6c 64 20 lidation should
2300: 66 61 69 6c 2c 20 61 6e 0a 2a 2a 20 61 73 73 65 fail, an.** asse
2310: 72 74 69 6f 6e 20 77 69 6c 6c 20 62 65 20 74 72 rtion will be tr
2320: 69 67 67 65 72 65 64 2e 0a 2a 2a 0a 2a 2a 20 49 iggered..**.** I
2330: 66 20 6e 6f 6e 65 20 6f 66 20 74 68 65 20 61 62 f none of the ab
2340: 6f 76 65 20 61 72 65 20 64 65 66 69 6e 65 64 2c ove are defined,
2350: 20 74 68 65 6e 20 73 65 74 20 53 51 4c 49 54 45 then set SQLITE
2360: 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 61 _SYSTEM_MALLOC a
2370: 73 0a 2a 2a 20 74 68 65 20 64 65 66 61 75 6c 74 s.** the default
2380: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
2390: 28 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d (SQLITE_SYSTEM_M
23a0: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
23b0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 57 49 4e 33 ined(SQLITE_WIN3
23c0: 32 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 2_MALLOC) \. +
23d0: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 5a defined(SQLITE_Z
23e0: 45 52 4f 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 ERO_MALLOC) \.
23f0: 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 + defined(SQLITE
2400: 5f 4d 45 4d 44 45 42 55 47 29 3e 31 0a 23 20 65 _MEMDEBUG)>1.# e
2410: 72 72 6f 72 20 22 54 77 6f 20 6f 72 20 6d 6f 72 rror "Two or mor
2420: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
2430: 6e 67 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 ng compile-time
2440: 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 6f 70 configuration op
2450: 74 69 6f 6e 73 5c 0a 20 61 72 65 20 64 65 66 69 tions\. are defi
2460: 6e 65 64 20 62 75 74 20 61 74 20 6d 6f 73 74 20 ned but at most
2470: 6f 6e 65 20 69 73 20 61 6c 6c 6f 77 65 64 3a 5c one is allowed:\
2480: 0a 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f . SQLITE_SYSTEM_
2490: 4d 41 4c 4c 4f 43 2c 20 53 51 4c 49 54 45 5f 57 MALLOC, SQLITE_W
24a0: 49 4e 33 32 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c IN32_MALLOC, SQL
24b0: 49 54 45 5f 4d 45 4d 44 45 42 55 47 2c 5c 0a 20 ITE_MEMDEBUG,\.
24c0: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
24d0: 4f 43 22 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 OC".#endif.#if d
24e0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 efined(SQLITE_SY
24f0: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 STEM_MALLOC) \.
2500: 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 + defined(SQLIT
2510: 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 E_WIN32_MALLOC)
2520: 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 \. + defined(SQ
2530: 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 LITE_ZERO_MALLOC
2540: 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 ) \. + defined(
2550: 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 SQLITE_MEMDEBUG)
2560: 3d 3d 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ==0.# define SQL
2570: 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f ITE_SYSTEM_MALLO
2580: 43 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a C 1.#endif../*.*
2590: 2a 20 49 66 20 53 51 4c 49 54 45 5f 4d 41 4c 4c * If SQLITE_MALL
25a0: 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 20 69 73 OC_SOFT_LIMIT is
25b0: 20 6e 6f 74 20 7a 65 72 6f 2c 20 74 68 65 6e 20 not zero, then
25c0: 74 72 79 20 74 6f 20 6b 65 65 70 20 74 68 65 0a try to keep the.
25d0: 2a 2a 20 73 69 7a 65 73 20 6f 66 20 6d 65 6d 6f ** sizes of memo
25e0: 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 62 ry allocations b
25f0: 65 6c 6f 77 20 74 68 69 73 20 76 61 6c 75 65 20 elow this value
2600: 77 68 65 72 65 20 70 6f 73 73 69 62 6c 65 2e 0a where possible..
2610: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
2620: 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f SQLITE_MALLOC_SO
2630: 46 54 5f 4c 49 4d 49 54 29 0a 23 20 64 65 66 69 FT_LIMIT).# defi
2640: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 ne SQLITE_MALLOC
2650: 5f 53 4f 46 54 5f 4c 49 4d 49 54 20 31 30 32 34 _SOFT_LIMIT 1024
2660: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 57 .#endif../*.** W
2670: 65 20 6e 65 65 64 20 74 6f 20 64 65 66 69 6e 65 e need to define
2680: 20 5f 58 4f 50 45 4e 5f 53 4f 55 52 43 45 20 61 _XOPEN_SOURCE a
2690: 73 20 66 6f 6c 6c 6f 77 73 20 69 6e 20 6f 72 64 s follows in ord
26a0: 65 72 20 74 6f 20 65 6e 61 62 6c 65 0a 2a 2a 20 er to enable.**
26b0: 72 65 63 75 72 73 69 76 65 20 6d 75 74 65 78 65 recursive mutexe
26c0: 73 20 6f 6e 20 6d 6f 73 74 20 55 6e 69 78 20 73 s on most Unix s
26d0: 79 73 74 65 6d 73 20 61 6e 64 20 66 63 68 6d 6f ystems and fchmo
26e0: 64 28 29 20 6f 6e 20 4f 70 65 6e 42 53 44 2e 0a d() on OpenBSD..
26f0: 2a 2a 20 42 75 74 20 5f 58 4f 50 45 4e 5f 53 4f ** But _XOPEN_SO
2700: 55 52 43 45 20 64 65 66 69 6e 65 20 63 61 75 73 URCE define caus
2710: 65 73 20 70 72 6f 62 6c 65 6d 73 20 66 6f 72 20 es problems for
2720: 4d 61 63 20 4f 53 20 58 2c 20 73 6f 20 6f 6d 69 Mac OS X, so omi
2730: 74 0a 2a 2a 20 69 74 2e 0a 2a 2f 0a 23 69 66 20 t.** it..*/.#if
2740: 21 64 65 66 69 6e 65 64 28 5f 58 4f 50 45 4e 5f !defined(_XOPEN_
2750: 53 4f 55 52 43 45 29 20 26 26 20 21 64 65 66 69 SOURCE) && !defi
2760: 6e 65 64 28 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 ned(__DARWIN__)
2770: 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 41 50 && !defined(__AP
2780: 50 4c 45 5f 5f 29 0a 23 20 20 64 65 66 69 6e 65 PLE__).# define
2790: 20 5f 58 4f 50 45 4e 5f 53 4f 55 52 43 45 20 36 _XOPEN_SOURCE 6
27a0: 30 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 00.#endif../*.**
27b0: 20 4e 44 45 42 55 47 20 61 6e 64 20 53 51 4c 49 NDEBUG and SQLI
27c0: 54 45 5f 44 45 42 55 47 20 61 72 65 20 6f 70 70 TE_DEBUG are opp
27d0: 6f 73 69 74 65 73 2e 20 20 49 74 20 73 68 6f 75 osites. It shou
27e0: 6c 64 20 61 6c 77 61 79 73 20 62 65 20 74 72 75 ld always be tru
27f0: 65 20 74 68 61 74 0a 2a 2a 20 64 65 66 69 6e 65 e that.** define
2800: 64 28 4e 44 45 42 55 47 29 3d 3d 21 64 65 66 69 d(NDEBUG)==!defi
2810: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
2820: 29 2e 20 20 49 66 20 74 68 69 73 20 69 73 20 6e ). If this is n
2830: 6f 74 20 63 75 72 72 65 6e 74 6c 79 20 74 72 75 ot currently tru
2840: 65 2c 0a 2a 2a 20 6d 61 6b 65 20 69 74 20 74 72 e,.** make it tr
2850: 75 65 20 62 79 20 64 65 66 69 6e 69 6e 67 20 6f ue by defining o
2860: 72 20 75 6e 64 65 66 69 6e 69 6e 67 20 4e 44 45 r undefining NDE
2870: 42 55 47 2e 0a 2a 2a 0a 2a 2a 20 53 65 74 74 69 BUG..**.** Setti
2880: 6e 67 20 4e 44 45 42 55 47 20 6d 61 6b 65 73 20 ng NDEBUG makes
2890: 74 68 65 20 63 6f 64 65 20 73 6d 61 6c 6c 65 72 the code smaller
28a0: 20 61 6e 64 20 66 61 73 74 65 72 20 62 79 20 64 and faster by d
28b0: 69 73 61 62 6c 69 6e 67 20 74 68 65 0a 2a 2a 20 isabling the.**
28c0: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
28d0: 6e 74 73 20 69 6e 20 74 68 65 20 63 6f 64 65 2e nts in the code.
28e0: 20 20 53 6f 20 77 65 20 77 61 6e 74 20 74 68 65 So we want the
28f0: 20 64 65 66 61 75 6c 74 20 61 63 74 69 6f 6e 0a default action.
2900: 2a 2a 20 74 6f 20 62 65 20 66 6f 72 20 4e 44 45 ** to be for NDE
2910: 42 55 47 20 74 6f 20 62 65 20 73 65 74 20 61 6e BUG to be set an
2920: 64 20 4e 44 45 42 55 47 20 74 6f 20 62 65 20 75 d NDEBUG to be u
2930: 6e 64 65 66 69 6e 65 64 20 6f 6e 6c 79 20 69 66 ndefined only if
2940: 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 2a 2a SQLITE_DEBUG.**
2950: 20 69 73 20 73 65 74 2e 20 20 54 68 75 73 20 4e is set. Thus N
2960: 44 45 42 55 47 20 62 65 63 6f 6d 65 73 20 61 6e DEBUG becomes an
2970: 20 6f 70 74 2d 69 6e 20 72 61 74 68 65 72 20 74 opt-in rather t
2980: 68 61 6e 20 61 6e 20 6f 70 74 2d 6f 75 74 0a 2a han an opt-out.*
2990: 2a 20 66 65 61 74 75 72 65 2e 0a 2a 2f 0a 23 69 * feature..*/.#i
29a0: 66 20 21 64 65 66 69 6e 65 64 28 4e 44 45 42 55 f !defined(NDEBU
29b0: 47 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 G) && !defined(S
29c0: 51 4c 49 54 45 5f 44 45 42 55 47 29 20 0a 23 20 QLITE_DEBUG) .#
29d0: 64 65 66 69 6e 65 20 4e 44 45 42 55 47 20 31 0a define NDEBUG 1.
29e0: 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
29f0: 65 64 28 4e 44 45 42 55 47 29 20 26 26 20 64 65 ed(NDEBUG) && de
2a00: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 fined(SQLITE_DEB
2a10: 55 47 29 0a 23 20 75 6e 64 65 66 20 4e 44 45 42 UG).# undef NDEB
2a20: 55 47 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a UG.#endif../*.**
2a30: 20 45 6e 61 62 6c 65 20 53 51 4c 49 54 45 5f 45 Enable SQLITE_E
2a40: 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f NABLE_EXPLAIN_CO
2a50: 4d 4d 45 4e 54 53 20 69 66 20 53 51 4c 49 54 45 MMENTS if SQLITE
2a60: 5f 44 45 42 55 47 20 69 73 20 74 75 72 6e 65 64 _DEBUG is turned
2a70: 20 6f 6e 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 on..*/.#if !def
2a80: 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
2a90: 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 LE_EXPLAIN_COMME
2aa0: 4e 54 53 29 20 26 26 20 64 65 66 69 6e 65 64 28 NTS) && defined(
2ab0: 53 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 23 20 SQLITE_DEBUG).#
2ac0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e define SQLITE_EN
2ad0: 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d ABLE_EXPLAIN_COM
2ae0: 4d 45 4e 54 53 20 31 0a 23 65 6e 64 69 66 0a 0a MENTS 1.#endif..
2af0: 2f 2a 0a 2a 2a 20 54 68 65 20 74 65 73 74 63 61 /*.** The testca
2b00: 73 65 28 29 20 6d 61 63 72 6f 20 69 73 20 75 73 se() macro is us
2b10: 65 64 20 74 6f 20 61 69 64 20 69 6e 20 63 6f 76 ed to aid in cov
2b20: 65 72 61 67 65 20 74 65 73 74 69 6e 67 2e 20 20 erage testing.
2b30: 57 68 65 6e 20 0a 2a 2a 20 64 6f 69 6e 67 20 63 When .** doing c
2b40: 6f 76 65 72 61 67 65 20 74 65 73 74 69 6e 67 2c overage testing,
2b50: 20 74 68 65 20 63 6f 6e 64 69 74 69 6f 6e 20 69 the condition i
2b60: 6e 73 69 64 65 20 74 68 65 20 61 72 67 75 6d 65 nside the argume
2b70: 6e 74 20 74 6f 0a 2a 2a 20 74 65 73 74 63 61 73 nt to.** testcas
2b80: 65 28 29 20 6d 75 73 74 20 62 65 20 65 76 61 6c e() must be eval
2b90: 75 61 74 65 64 20 62 6f 74 68 20 74 72 75 65 20 uated both true
2ba0: 61 6e 64 20 66 61 6c 73 65 20 69 6e 20 6f 72 64 and false in ord
2bb0: 65 72 20 74 6f 0a 2a 2a 20 67 65 74 20 66 75 6c er to.** get ful
2bc0: 6c 20 62 72 61 6e 63 68 20 63 6f 76 65 72 61 67 l branch coverag
2bd0: 65 2e 20 20 54 68 65 20 74 65 73 74 63 61 73 65 e. The testcase
2be0: 28 29 20 6d 61 63 72 6f 20 69 73 20 69 6e 73 65 () macro is inse
2bf0: 72 74 65 64 0a 2a 2a 20 74 6f 20 68 65 6c 70 20 rted.** to help
2c00: 65 6e 73 75 72 65 20 61 64 65 71 75 61 74 65 20 ensure adequate
2c10: 74 65 73 74 20 63 6f 76 65 72 61 67 65 20 69 6e test coverage in
2c20: 20 70 6c 61 63 65 73 20 77 68 65 72 65 20 73 69 places where si
2c30: 6d 70 6c 65 0a 2a 2a 20 63 6f 6e 64 69 74 69 6f mple.** conditio
2c40: 6e 2f 64 65 63 69 73 69 6f 6e 20 63 6f 76 65 72 n/decision cover
2c50: 61 67 65 20 69 73 20 69 6e 61 64 65 71 75 61 74 age is inadequat
2c60: 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c e. For example,
2c70: 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 testcase().** c
2c80: 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 6d 61 an be used to ma
2c90: 6b 65 20 73 75 72 65 20 62 6f 75 6e 64 61 72 79 ke sure boundary
2ca0: 20 76 61 6c 75 65 73 20 61 72 65 20 74 65 73 74 values are test
2cb0: 65 64 2e 20 20 46 6f 72 0a 2a 2a 20 62 69 74 6d ed. For.** bitm
2cc0: 61 73 6b 20 74 65 73 74 73 2c 20 74 65 73 74 63 ask tests, testc
2cd0: 61 73 65 28 29 20 63 61 6e 20 62 65 20 75 73 65 ase() can be use
2ce0: 64 20 74 6f 20 6d 61 6b 65 20 73 75 72 65 20 65 d to make sure e
2cf0: 61 63 68 20 62 69 74 0a 2a 2a 20 69 73 20 73 69 ach bit.** is si
2d00: 67 6e 69 66 69 63 61 6e 74 20 61 6e 64 20 75 73 gnificant and us
2d10: 65 64 20 61 74 20 6c 65 61 73 74 20 6f 6e 63 65 ed at least once
2d20: 2e 20 20 4f 6e 20 73 77 69 74 63 68 20 73 74 61 . On switch sta
2d30: 74 65 6d 65 6e 74 73 0a 2a 2a 20 77 68 65 72 65 tements.** where
2d40: 20 6d 75 6c 74 69 70 6c 65 20 63 61 73 65 73 20 multiple cases
2d50: 67 6f 20 74 6f 20 74 68 65 20 73 61 6d 65 20 62 go to the same b
2d60: 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 2c 20 74 65 lock of code, te
2d70: 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 61 6e 20 stcase().** can
2d80: 69 6e 73 75 72 65 20 74 68 61 74 20 61 6c 6c 20 insure that all
2d90: 63 61 73 65 73 20 61 72 65 20 65 76 61 6c 75 61 cases are evalua
2da0: 74 65 64 2e 0a 2a 2a 0a 2a 2f 0a 23 69 66 64 65 ted..**.*/.#ifde
2db0: 66 20 53 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 f SQLITE_COVERAG
2dc0: 45 5f 54 45 53 54 0a 20 20 76 6f 69 64 20 73 71 E_TEST. void sq
2dd0: 6c 69 74 65 33 43 6f 76 65 72 61 67 65 28 69 6e lite3Coverage(in
2de0: 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 74 65 73 t);.# define tes
2df0: 74 63 61 73 65 28 58 29 20 20 69 66 28 20 58 20 tcase(X) if( X
2e00: 29 7b 20 73 71 6c 69 74 65 33 43 6f 76 65 72 61 ){ sqlite3Covera
2e10: 67 65 28 5f 5f 4c 49 4e 45 5f 5f 29 3b 20 7d 0a ge(__LINE__); }.
2e20: 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 74 #else.# define t
2e30: 65 73 74 63 61 73 65 28 58 29 0a 23 65 6e 64 69 estcase(X).#endi
2e40: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 54 45 53 f../*.** The TES
2e50: 54 4f 4e 4c 59 20 6d 61 63 72 6f 20 69 73 20 75 TONLY macro is u
2e60: 73 65 64 20 74 6f 20 65 6e 63 6c 6f 73 65 20 76 sed to enclose v
2e70: 61 72 69 61 62 6c 65 20 64 65 63 6c 61 72 61 74 ariable declarat
2e80: 69 6f 6e 73 20 6f 72 0a 2a 2a 20 6f 74 68 65 72 ions or.** other
2e90: 20 62 69 74 73 20 6f 66 20 63 6f 64 65 20 74 68 bits of code th
2ea0: 61 74 20 61 72 65 20 6e 65 65 64 65 64 20 74 6f at are needed to
2eb0: 20 73 75 70 70 6f 72 74 20 74 68 65 20 61 72 67 support the arg
2ec0: 75 6d 65 6e 74 73 0a 2a 2a 20 77 69 74 68 69 6e uments.** within
2ed0: 20 74 65 73 74 63 61 73 65 28 29 20 61 6e 64 20 testcase() and
2ee0: 61 73 73 65 72 74 28 29 20 6d 61 63 72 6f 73 2e assert() macros.
2ef0: 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 .*/.#if !defined
2f00: 28 4e 44 45 42 55 47 29 20 7c 7c 20 64 65 66 69 (NDEBUG) || defi
2f10: 6e 65 64 28 53 51 4c 49 54 45 5f 43 4f 56 45 52 ned(SQLITE_COVER
2f20: 41 47 45 5f 54 45 53 54 29 0a 23 20 64 65 66 69 AGE_TEST).# defi
2f30: 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 29 20 20 ne TESTONLY(X)
2f40: 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 X.#else.# define
2f50: 20 54 45 53 54 4f 4e 4c 59 28 58 29 0a 23 65 6e TESTONLY(X).#en
2f60: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f 6d 65 74 dif../*.** Somet
2f70: 69 6d 65 73 20 77 65 20 6e 65 65 64 20 61 20 73 imes we need a s
2f80: 6d 61 6c 6c 20 61 6d 6f 75 6e 74 20 6f 66 20 63 mall amount of c
2f90: 6f 64 65 20 73 75 63 68 20 61 73 20 61 20 76 61 ode such as a va
2fa0: 72 69 61 62 6c 65 20 69 6e 69 74 69 61 6c 69 7a riable initializ
2fb0: 61 74 69 6f 6e 0a 2a 2a 20 74 6f 20 73 65 74 75 ation.** to setu
2fc0: 70 20 66 6f 72 20 61 20 6c 61 74 65 72 20 61 73 p for a later as
2fd0: 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 sert() statement
2fe0: 2e 20 20 57 65 20 64 6f 20 6e 6f 74 20 77 61 6e . We do not wan
2ff0: 74 20 74 68 69 73 20 63 6f 64 65 20 74 6f 0a 2a t this code to.*
3000: 2a 20 61 70 70 65 61 72 20 77 68 65 6e 20 61 73 * appear when as
3010: 73 65 72 74 28 29 20 69 73 20 64 69 73 61 62 6c sert() is disabl
3020: 65 64 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 ed. The followi
3030: 6e 67 20 6d 61 63 72 6f 20 69 73 20 74 68 65 72 ng macro is ther
3040: 65 66 6f 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f efore.** used to
3050: 20 63 6f 6e 74 61 69 6e 20 74 68 61 74 20 73 65 contain that se
3060: 74 75 70 20 63 6f 64 65 2e 20 20 54 68 65 20 22 tup code. The "
3070: 56 56 41 22 20 61 63 72 6f 6e 79 6d 20 73 74 61 VVA" acronym sta
3080: 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 56 65 72 69 nds for.** "Veri
3090: 66 69 63 61 74 69 6f 6e 2c 20 56 61 6c 69 64 61 fication, Valida
30a0: 74 69 6f 6e 2c 20 61 6e 64 20 41 63 63 72 65 64 tion, and Accred
30b0: 69 74 61 74 69 6f 6e 22 2e 20 20 49 6e 20 6f 74 itation". In ot
30c0: 68 65 72 20 77 6f 72 64 73 2c 20 74 68 65 0a 2a her words, the.*
30d0: 2a 20 63 6f 64 65 20 77 69 74 68 69 6e 20 56 56 * code within VV
30e0: 41 5f 4f 4e 4c 59 28 29 20 77 69 6c 6c 20 6f 6e A_ONLY() will on
30f0: 6c 79 20 72 75 6e 20 64 75 72 69 6e 67 20 76 65 ly run during ve
3100: 72 69 66 69 63 61 74 69 6f 6e 20 70 72 6f 63 65 rification proce
3110: 73 73 65 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 sses..*/.#ifndef
3120: 20 4e 44 45 42 55 47 0a 23 20 64 65 66 69 6e 65 NDEBUG.# define
3130: 20 56 56 41 5f 4f 4e 4c 59 28 58 29 20 20 58 0a VVA_ONLY(X) X.
3140: 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 56 #else.# define V
3150: 56 41 5f 4f 4e 4c 59 28 58 29 0a 23 65 6e 64 69 VA_ONLY(X).#endi
3160: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 41 4c 57 f../*.** The ALW
3170: 41 59 53 20 61 6e 64 20 4e 45 56 45 52 20 6d 61 AYS and NEVER ma
3180: 63 72 6f 73 20 73 75 72 72 6f 75 6e 64 20 62 6f cros surround bo
3190: 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 69 6f 6e olean expression
31a0: 73 20 77 68 69 63 68 20 0a 2a 2a 20 61 72 65 20 s which .** are
31b0: 69 6e 74 65 6e 64 65 64 20 74 6f 20 61 6c 77 61 intended to alwa
31c0: 79 73 20 62 65 20 74 72 75 65 20 6f 72 20 66 61 ys be true or fa
31d0: 6c 73 65 2c 20 72 65 73 70 65 63 74 69 76 65 6c lse, respectivel
31e0: 79 2e 20 20 53 75 63 68 0a 2a 2a 20 65 78 70 72 y. Such.** expr
31f0: 65 73 73 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 essions could be
3200: 20 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 omitted from th
3210: 65 20 63 6f 64 65 20 63 6f 6d 70 6c 65 74 65 6c e code completel
3220: 79 2e 20 20 42 75 74 20 74 68 65 79 0a 2a 2a 20 y. But they.**
3230: 61 72 65 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 are included in
3240: 61 20 66 65 77 20 63 61 73 65 73 20 69 6e 20 6f a few cases in o
3250: 72 64 65 72 20 74 6f 20 65 6e 68 61 6e 63 65 20 rder to enhance
3260: 74 68 65 20 72 65 73 69 6c 69 65 6e 63 65 0a 2a the resilience.*
3270: 2a 20 6f 66 20 53 51 4c 69 74 65 20 74 6f 20 75 * of SQLite to u
3280: 6e 65 78 70 65 63 74 65 64 20 62 65 68 61 76 69 nexpected behavi
3290: 6f 72 20 2d 20 74 6f 20 6d 61 6b 65 20 74 68 65 or - to make the
32a0: 20 63 6f 64 65 20 22 73 65 6c 66 2d 68 65 61 6c code "self-heal
32b0: 69 6e 67 22 0a 2a 2a 20 6f 72 20 22 64 75 63 74 ing".** or "duct
32c0: 69 6c 65 22 20 72 61 74 68 65 72 20 74 68 61 6e ile" rather than
32d0: 20 62 65 69 6e 67 20 22 62 72 69 74 74 6c 65 22 being "brittle"
32e0: 20 61 6e 64 20 63 72 61 73 68 69 6e 67 20 61 74 and crashing at
32f0: 20 74 68 65 20 66 69 72 73 74 0a 2a 2a 20 68 69 the first.** hi
3300: 6e 74 20 6f 66 20 75 6e 70 6c 61 6e 6e 65 64 20 nt of unplanned
3310: 62 65 68 61 76 69 6f 72 2e 0a 2a 2a 0a 2a 2a 20 behavior..**.**
3320: 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 In other words,
3330: 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 45 52 ALWAYS and NEVER
3340: 20 61 72 65 20 61 64 64 65 64 20 66 6f 72 20 64 are added for d
3350: 65 66 65 6e 73 69 76 65 20 63 6f 64 65 2e 0a 2a efensive code..*
3360: 2a 0a 2a 2a 20 57 68 65 6e 20 64 6f 69 6e 67 20 *.** When doing
3370: 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 6e 67 coverage testing
3380: 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 45 ALWAYS and NEVE
3390: 52 20 61 72 65 20 68 61 72 64 2d 63 6f 64 65 64 R are hard-coded
33a0: 20 74 6f 0a 2a 2a 20 62 65 20 74 72 75 65 20 61 to.** be true a
33b0: 6e 64 20 66 61 6c 73 65 20 73 6f 20 74 68 61 74 nd false so that
33c0: 20 74 68 65 20 75 6e 72 65 61 63 68 61 62 6c 65 the unreachable
33d0: 20 63 6f 64 65 20 74 68 65 79 20 73 70 65 63 69 code they speci
33e0: 66 79 20 77 69 6c 6c 0a 2a 2a 20 6e 6f 74 20 62 fy will.** not b
33f0: 65 20 63 6f 75 6e 74 65 64 20 61 73 20 75 6e 74 e counted as unt
3400: 65 73 74 65 64 20 63 6f 64 65 2e 0a 2a 2f 0a 23 ested code..*/.#
3410: 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
3420: 45 5f 43 4f 56 45 52 41 47 45 5f 54 45 53 54 29 E_COVERAGE_TEST)
3430: 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 41 59 53 .# define ALWAYS
3440: 28 58 29 20 20 20 20 20 20 28 31 29 0a 23 20 64 (X) (1).# d
3450: 65 66 69 6e 65 20 4e 45 56 45 52 28 58 29 20 20 efine NEVER(X)
3460: 20 20 20 20 20 28 30 29 0a 23 65 6c 69 66 20 21 (0).#elif !
3470: 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 0a defined(NDEBUG).
3480: 23 20 64 65 66 69 6e 65 20 41 4c 57 41 59 53 28 # define ALWAYS(
3490: 58 29 20 20 20 20 20 20 28 28 58 29 3f 31 3a 28 X) ((X)?1:(
34a0: 61 73 73 65 72 74 28 30 29 2c 30 29 29 0a 23 20 assert(0),0)).#
34b0: 64 65 66 69 6e 65 20 4e 45 56 45 52 28 58 29 20 define NEVER(X)
34c0: 20 20 20 20 20 20 28 28 58 29 3f 28 61 73 73 65 ((X)?(asse
34d0: 72 74 28 30 29 2c 31 29 3a 30 29 0a 23 65 6c 73 rt(0),1):0).#els
34e0: 65 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 41 59 e.# define ALWAY
34f0: 53 28 58 29 20 20 20 20 20 20 28 58 29 0a 23 20 S(X) (X).#
3500: 64 65 66 69 6e 65 20 4e 45 56 45 52 28 58 29 20 define NEVER(X)
3510: 20 20 20 20 20 20 28 58 29 0a 23 65 6e 64 69 66 (X).#endif
3520: 0a 0a 2f 2a 0a 2a 2a 20 44 65 63 6c 61 72 61 74 ../*.** Declarat
3530: 69 6f 6e 73 20 75 73 65 64 20 66 6f 72 20 74 72 ions used for tr
3540: 61 63 69 6e 67 20 74 68 65 20 6f 70 65 72 61 74 acing the operat
3550: 69 6e 67 20 73 79 73 74 65 6d 20 69 6e 74 65 72 ing system inter
3560: 66 61 63 65 73 2e 0a 2a 2f 0a 23 69 66 20 64 65 faces..*/.#if de
3570: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 46 4f 52 fined(SQLITE_FOR
3580: 43 45 5f 4f 53 5f 54 52 41 43 45 29 20 7c 7c 20 CE_OS_TRACE) ||
3590: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 defined(SQLITE_T
35a0: 45 53 54 29 20 7c 7c 20 5c 0a 20 20 20 20 28 64 EST) || \. (d
35b0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 efined(SQLITE_DE
35c0: 42 55 47 29 20 26 26 20 53 51 4c 49 54 45 5f 4f BUG) && SQLITE_O
35d0: 53 5f 57 49 4e 29 0a 20 20 65 78 74 65 72 6e 20 S_WIN). extern
35e0: 69 6e 74 20 73 71 6c 69 74 65 33 4f 53 54 72 61 int sqlite3OSTra
35f0: 63 65 3b 0a 23 20 64 65 66 69 6e 65 20 4f 53 54 ce;.# define OST
3600: 52 41 43 45 28 58 29 20 20 20 20 20 20 20 20 20 RACE(X)
3610: 20 69 66 28 20 73 71 6c 69 74 65 33 4f 53 54 72 if( sqlite3OSTr
3620: 61 63 65 20 29 20 73 71 6c 69 74 65 33 44 65 62 ace ) sqlite3Deb
3630: 75 67 50 72 69 6e 74 66 20 58 0a 23 20 64 65 66 ugPrintf X.# def
3640: 69 6e 65 20 53 51 4c 49 54 45 5f 48 41 56 45 5f ine SQLITE_HAVE_
3650: 4f 53 5f 54 52 41 43 45 0a 23 65 6c 73 65 0a 23 OS_TRACE.#else.#
3660: 20 64 65 66 69 6e 65 20 4f 53 54 52 41 43 45 28 define OSTRACE(
3670: 58 29 0a 23 20 75 6e 64 65 66 20 20 53 51 4c 49 X).# undef SQLI
3680: 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 TE_HAVE_OS_TRACE
3690: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 .#endif../*.** I
36a0: 73 20 74 68 65 20 73 71 6c 69 74 65 33 45 72 72 s the sqlite3Err
36b0: 4e 61 6d 65 28 29 20 66 75 6e 63 74 69 6f 6e 20 Name() function
36c0: 6e 65 65 64 65 64 20 69 6e 20 74 68 65 20 62 75 needed in the bu
36d0: 69 6c 64 3f 20 20 43 75 72 72 65 6e 74 6c 79 2c ild? Currently,
36e0: 0a 2a 2a 20 69 74 20 69 73 20 6e 65 65 64 65 64 .** it is needed
36f0: 20 62 79 20 22 6d 75 74 65 78 5f 77 33 32 2e 63 by "mutex_w32.c
3700: 22 20 28 77 68 65 6e 20 64 65 62 75 67 67 69 6e " (when debuggin
3710: 67 29 2c 20 22 6f 73 5f 77 69 6e 2e 63 22 20 28 g), "os_win.c" (
3720: 77 68 65 6e 0a 2a 2a 20 4f 53 54 52 41 43 45 20 when.** OSTRACE
3730: 69 73 20 65 6e 61 62 6c 65 64 29 2c 20 61 6e 64 is enabled), and
3740: 20 62 79 20 73 65 76 65 72 61 6c 20 22 74 65 73 by several "tes
3750: 74 2a 2e 63 22 20 66 69 6c 65 73 20 28 77 68 69 t*.c" files (whi
3760: 63 68 20 61 72 65 0a 2a 2a 20 63 6f 6d 70 69 6c ch are.** compil
3770: 65 64 20 75 73 69 6e 67 20 53 51 4c 49 54 45 5f ed using SQLITE_
3780: 54 45 53 54 29 2e 0a 2a 2f 0a 23 69 66 20 64 65 TEST)..*/.#if de
3790: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 48 41 56 fined(SQLITE_HAV
37a0: 45 5f 4f 53 5f 54 52 41 43 45 29 20 7c 7c 20 64 E_OS_TRACE) || d
37b0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 efined(SQLITE_TE
37c0: 53 54 29 20 7c 7c 20 5c 0a 20 20 20 20 28 64 65 ST) || \. (de
37d0: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 fined(SQLITE_DEB
37e0: 55 47 29 20 26 26 20 53 51 4c 49 54 45 5f 4f 53 UG) && SQLITE_OS
37f0: 5f 57 49 4e 29 0a 23 20 64 65 66 69 6e 65 20 53 _WIN).# define S
3800: 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 52 5f 4e QLITE_NEED_ERR_N
3810: 41 4d 45 0a 23 65 6c 73 65 0a 23 20 75 6e 64 65 AME.#else.# unde
3820: 66 20 20 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 f SQLITE_NEED_E
3830: 52 52 5f 4e 41 4d 45 0a 23 65 6e 64 69 66 0a 0a RR_NAME.#endif..
3840: 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 /*.** Return tru
3850: 65 20 28 6e 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 e (non-zero) if
3860: 74 68 65 20 69 6e 70 75 74 20 69 73 20 61 6e 20 the input is an
3870: 69 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 integer that is
3880: 74 6f 6f 20 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 too large.** to
3890: 66 69 74 20 69 6e 20 33 32 2d 62 69 74 73 2e 20 fit in 32-bits.
38a0: 20 54 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 This macro is u
38b0: 73 65 64 20 69 6e 73 69 64 65 20 6f 66 20 76 61 sed inside of va
38c0: 72 69 6f 75 73 20 74 65 73 74 63 61 73 65 28 29 rious testcase()
38d0: 0a 2a 2a 20 6d 61 63 72 6f 73 20 74 6f 20 76 65 .** macros to ve
38e0: 72 69 66 79 20 74 68 61 74 20 77 65 20 68 61 76 rify that we hav
38f0: 65 20 74 65 73 74 65 64 20 53 51 4c 69 74 65 20 e tested SQLite
3900: 66 6f 72 20 6c 61 72 67 65 2d 66 69 6c 65 20 73 for large-file s
3910: 75 70 70 6f 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 upport..*/.#defi
3920: 6e 65 20 49 53 5f 42 49 47 5f 49 4e 54 28 58 29 ne IS_BIG_INT(X)
3930: 20 20 28 28 28 58 29 26 7e 28 69 36 34 29 30 78 (((X)&~(i64)0x
3940: 66 66 66 66 66 66 66 66 29 21 3d 30 29 0a 0a 2f ffffffff)!=0)../
3950: 2a 0a 2a 2a 20 54 68 65 20 6d 61 63 72 6f 20 75 *.** The macro u
3960: 6e 6c 69 6b 65 6c 79 28 29 20 69 73 20 61 20 68 nlikely() is a h
3970: 69 6e 74 20 74 68 61 74 20 73 75 72 72 6f 75 6e int that surroun
3980: 64 73 20 61 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 ds a boolean.**
3990: 65 78 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 expression that
39a0: 69 73 20 75 73 75 61 6c 6c 79 20 66 61 6c 73 65 is usually false
39b0: 2e 20 20 4d 61 63 72 6f 20 6c 69 6b 65 6c 79 28 . Macro likely(
39c0: 29 20 73 75 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 ) surrounds.** a
39d0: 20 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 boolean express
39e0: 69 6f 6e 20 74 68 61 74 20 69 73 20 75 73 75 61 ion that is usua
39f0: 6c 6c 79 20 74 72 75 65 2e 20 20 54 68 65 73 65 lly true. These
3a00: 20 68 69 6e 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a hints could,.**
3a10: 20 69 6e 20 74 68 65 6f 72 79 2c 20 62 65 20 75 in theory, be u
3a20: 73 65 64 20 62 79 20 74 68 65 20 63 6f 6d 70 69 sed by the compi
3a30: 6c 65 72 20 74 6f 20 67 65 6e 65 72 61 74 65 20 ler to generate
3a40: 62 65 74 74 65 72 20 63 6f 64 65 2c 20 62 75 74 better code, but
3a50: 0a 2a 2a 20 63 75 72 72 65 6e 74 6c 79 20 74 68 .** currently th
3a60: 65 79 20 61 72 65 20 6a 75 73 74 20 63 6f 6d 6d ey are just comm
3a70: 65 6e 74 73 20 66 6f 72 20 68 75 6d 61 6e 20 72 ents for human r
3a80: 65 61 64 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 eaders..*/.#defi
3a90: 6e 65 20 6c 69 6b 65 6c 79 28 58 29 20 20 20 20 ne likely(X)
3aa0: 28 58 29 0a 23 64 65 66 69 6e 65 20 75 6e 6c 69 (X).#define unli
3ab0: 6b 65 6c 79 28 58 29 20 20 28 58 29 0a 0a 23 69 kely(X) (X)..#i
3ac0: 6e 63 6c 75 64 65 20 22 68 61 73 68 2e 68 22 0a nclude "hash.h".
3ad0: 23 69 6e 63 6c 75 64 65 20 22 70 61 72 73 65 2e #include "parse.
3ae0: 68 22 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 h".#include <std
3af0: 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c io.h>.#include <
3b00: 73 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 stdlib.h>.#inclu
3b10: 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 de <string.h>.#i
3b20: 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68 nclude <assert.h
3b30: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 64 >.#include <stdd
3b40: 65 66 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 ef.h>../*.** If
3b50: 63 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 20 61 20 compiling for a
3b60: 70 72 6f 63 65 73 73 6f 72 20 74 68 61 74 20 6c processor that l
3b70: 61 63 6b 73 20 66 6c 6f 61 74 69 6e 67 20 70 6f acks floating po
3b80: 69 6e 74 20 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 int support,.**
3b90: 73 75 62 73 74 69 74 75 74 65 20 69 6e 74 65 67 substitute integ
3ba0: 65 72 20 66 6f 72 20 66 6c 6f 61 74 69 6e 67 2d er for floating-
3bb0: 70 6f 69 6e 74 0a 2a 2f 0a 23 69 66 64 65 66 20 point.*/.#ifdef
3bc0: 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 SQLITE_OMIT_FLOA
3bd0: 54 49 4e 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 TING_POINT.# def
3be0: 69 6e 65 20 64 6f 75 62 6c 65 20 73 71 6c 69 74 ine double sqlit
3bf0: 65 5f 69 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 e_int64.# define
3c00: 20 66 6c 6f 61 74 20 73 71 6c 69 74 65 5f 69 6e float sqlite_in
3c10: 74 36 34 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e t64.# define LON
3c20: 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 73 71 6c GDOUBLE_TYPE sql
3c30: 69 74 65 5f 69 6e 74 36 34 0a 23 20 69 66 6e 64 ite_int64.# ifnd
3c40: 65 66 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 ef SQLITE_BIG_DB
3c50: 4c 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c L.# define SQL
3c60: 49 54 45 5f 42 49 47 5f 44 42 4c 20 28 28 28 73 ITE_BIG_DBL (((s
3c70: 71 6c 69 74 65 33 5f 69 6e 74 36 34 29 31 29 3c qlite3_int64)1)<
3c80: 3c 35 30 29 0a 23 20 65 6e 64 69 66 0a 23 20 64 <50).# endif.# d
3c90: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f 4d 49 efine SQLITE_OMI
3ca0: 54 5f 44 41 54 45 54 49 4d 45 5f 46 55 4e 43 53 T_DATETIME_FUNCS
3cb0: 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1.# define SQLI
3cc0: 54 45 5f 4f 4d 49 54 5f 54 52 41 43 45 20 31 0a TE_OMIT_TRACE 1.
3cd0: 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d # undef SQLITE_M
3ce0: 49 58 45 44 5f 45 4e 44 49 41 4e 5f 36 34 42 49 IXED_ENDIAN_64BI
3cf0: 54 5f 46 4c 4f 41 54 0a 23 20 75 6e 64 65 66 20 T_FLOAT.# undef
3d00: 53 51 4c 49 54 45 5f 48 41 56 45 5f 49 53 4e 41 SQLITE_HAVE_ISNA
3d10: 4e 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 N.#endif.#ifndef
3d20: 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a SQLITE_BIG_DBL.
3d30: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
3d40: 42 49 47 5f 44 42 4c 20 28 31 65 39 39 29 0a 23 BIG_DBL (1e99).#
3d50: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 endif../*.** OMI
3d60: 54 5f 54 45 4d 50 44 42 20 69 73 20 73 65 74 20 T_TEMPDB is set
3d70: 74 6f 20 31 20 69 66 20 53 51 4c 49 54 45 5f 4f to 1 if SQLITE_O
3d80: 4d 49 54 5f 54 45 4d 50 44 42 20 69 73 20 64 65 MIT_TEMPDB is de
3d90: 66 69 6e 65 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 fined, or 0.** a
3da0: 66 74 65 72 77 61 72 64 2e 20 48 61 76 69 6e 67 fterward. Having
3db0: 20 74 68 69 73 20 6d 61 63 72 6f 20 61 6c 6c 6f this macro allo
3dc0: 77 73 20 75 73 20 74 6f 20 63 61 75 73 65 20 74 ws us to cause t
3dd0: 68 65 20 43 20 63 6f 6d 70 69 6c 65 72 20 0a 2a he C compiler .*
3de0: 2a 20 74 6f 20 6f 6d 69 74 20 63 6f 64 65 20 75 * to omit code u
3df0: 73 65 64 20 62 79 20 54 45 4d 50 20 74 61 62 6c sed by TEMP tabl
3e00: 65 73 20 77 69 74 68 6f 75 74 20 6d 65 73 73 79 es without messy
3e10: 20 23 69 66 6e 64 65 66 20 73 74 61 74 65 6d 65 #ifndef stateme
3e20: 6e 74 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 nts..*/.#ifdef S
3e30: 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 QLITE_OMIT_TEMPD
3e40: 42 0a 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 B.#define OMIT_T
3e50: 45 4d 50 44 42 20 31 0a 23 65 6c 73 65 0a 23 64 EMPDB 1.#else.#d
3e60: 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 efine OMIT_TEMPD
3e70: 42 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a B 0.#endif../*.*
3e80: 2a 20 54 68 65 20 22 66 69 6c 65 20 66 6f 72 6d * The "file form
3e90: 61 74 22 20 6e 75 6d 62 65 72 20 69 73 20 61 6e at" number is an
3ea0: 20 69 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 integer that is
3eb0: 20 69 6e 63 72 65 6d 65 6e 74 65 64 20 77 68 65 incremented whe
3ec0: 6e 65 76 65 72 0a 2a 2a 20 74 68 65 20 56 44 42 never.** the VDB
3ed0: 45 2d 6c 65 76 65 6c 20 66 69 6c 65 20 66 6f 72 E-level file for
3ee0: 6d 61 74 20 63 68 61 6e 67 65 73 2e 20 20 54 68 mat changes. Th
3ef0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 e following macr
3f00: 6f 73 20 64 65 66 69 6e 65 20 74 68 65 0a 2a 2a os define the.**
3f10: 20 74 68 65 20 64 65 66 61 75 6c 74 20 66 69 6c the default fil
3f20: 65 20 66 6f 72 6d 61 74 20 66 6f 72 20 6e 65 77 e format for new
3f30: 20 64 61 74 61 62 61 73 65 73 20 61 6e 64 20 74 databases and t
3f40: 68 65 20 6d 61 78 69 6d 75 6d 20 66 69 6c 65 20 he maximum file
3f50: 66 6f 72 6d 61 74 0a 2a 2a 20 74 68 61 74 20 74 format.** that t
3f60: 68 65 20 6c 69 62 72 61 72 79 20 63 61 6e 20 72 he library can r
3f70: 65 61 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ead..*/.#define
3f80: 53 51 4c 49 54 45 5f 4d 41 58 5f 46 49 4c 45 5f SQLITE_MAX_FILE_
3f90: 46 4f 52 4d 41 54 20 34 0a 23 69 66 6e 64 65 66 FORMAT 4.#ifndef
3fa0: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
3fb0: 46 49 4c 45 5f 46 4f 52 4d 41 54 0a 23 20 64 65 FILE_FORMAT.# de
3fc0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 fine SQLITE_DEFA
3fd0: 55 4c 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 20 ULT_FILE_FORMAT
3fe0: 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4.#endif../*.**
3ff0: 44 65 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 Determine whethe
4000: 72 20 74 72 69 67 67 65 72 73 20 61 72 65 20 72 r triggers are r
4010: 65 63 75 72 73 69 76 65 20 62 79 20 64 65 66 61 ecursive by defa
4020: 75 6c 74 2e 20 20 54 68 69 73 20 63 61 6e 20 62 ult. This can b
4030: 65 0a 2a 2a 20 63 68 61 6e 67 65 64 20 61 74 20 e.** changed at
4040: 72 75 6e 2d 74 69 6d 65 20 75 73 69 6e 67 20 61 run-time using a
4050: 20 70 72 61 67 6d 61 2e 0a 2a 2f 0a 23 69 66 6e pragma..*/.#ifn
4060: 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 def SQLITE_DEFAU
4070: 4c 54 5f 52 45 43 55 52 53 49 56 45 5f 54 52 49 LT_RECURSIVE_TRI
4080: 47 47 45 52 53 0a 23 20 64 65 66 69 6e 65 20 53 GGERS.# define S
4090: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 QLITE_DEFAULT_RE
40a0: 43 55 52 53 49 56 45 5f 54 52 49 47 47 45 52 53 CURSIVE_TRIGGERS
40b0: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 0.#endif../*.**
40c0: 20 50 72 6f 76 69 64 65 20 61 20 64 65 66 61 75 Provide a defau
40d0: 6c 74 20 76 61 6c 75 65 20 66 6f 72 20 53 51 4c lt value for SQL
40e0: 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 ITE_TEMP_STORE i
40f0: 6e 20 63 61 73 65 20 69 74 20 69 73 20 6e 6f 74 n case it is not
4100: 20 73 70 65 63 69 66 69 65 64 0a 2a 2a 20 6f 6e specified.** on
4110: 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e the command-lin
4120: 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c e.*/.#ifndef SQL
4130: 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 0a 23 ITE_TEMP_STORE.#
4140: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 define SQLITE_T
4150: 45 4d 50 5f 53 54 4f 52 45 20 31 0a 23 20 64 65 EMP_STORE 1.# de
4160: 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 fine SQLITE_TEMP
4170: 5f 53 54 4f 52 45 5f 78 63 20 31 20 20 2f 2a 20 _STORE_xc 1 /*
4180: 45 78 63 6c 75 64 65 20 66 72 6f 6d 20 63 74 69 Exclude from cti
4190: 6d 65 2e 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a me.c */.#endif..
41a0: 2f 2a 0a 2a 2a 20 49 66 20 6e 6f 20 76 61 6c 75 /*.** If no valu
41b0: 65 20 68 61 73 20 62 65 65 6e 20 70 72 6f 76 69 e has been provi
41c0: 64 65 64 20 66 6f 72 20 53 51 4c 49 54 45 5f 4d ded for SQLITE_M
41d0: 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 AX_WORKER_THREAD
41e0: 53 2c 20 6f 72 20 69 66 0a 2a 2a 20 53 51 4c 49 S, or if.** SQLI
41f0: 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 73 TE_TEMP_STORE is
4200: 20 73 65 74 20 74 6f 20 33 20 28 6e 65 76 65 72 set to 3 (never
4210: 20 75 73 65 20 74 65 6d 70 6f 72 61 72 79 20 66 use temporary f
4220: 69 6c 65 73 29 2c 20 73 65 74 20 69 74 20 0a 2a iles), set it .*
4230: 2a 20 74 6f 20 7a 65 72 6f 2e 0a 2a 2f 0a 23 69 * to zero..*/.#i
4240: 66 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 f SQLITE_TEMP_ST
4250: 4f 52 45 3d 3d 33 20 7c 7c 20 53 51 4c 49 54 45 ORE==3 || SQLITE
4260: 5f 54 48 52 45 41 44 53 41 46 45 3d 3d 30 0a 23 _THREADSAFE==0.#
4270: 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 undef SQLITE_MA
4280: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
4290: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
42a0: 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 _MAX_WORKER_THRE
42b0: 41 44 53 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 ADS 0.#endif.#if
42c0: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f ndef SQLITE_MAX_
42d0: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 WORKER_THREADS.#
42e0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
42f0: 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 AX_WORKER_THREAD
4300: 53 20 38 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 S 8.#endif.#ifnd
4310: 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ef SQLITE_DEFAUL
4320: 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 T_WORKER_THREADS
4330: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
4340: 5f 44 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f _DEFAULT_WORKER_
4350: 54 48 52 45 41 44 53 20 30 0a 23 65 6e 64 69 66 THREADS 0.#endif
4360: 0a 23 69 66 20 53 51 4c 49 54 45 5f 44 45 46 41 .#if SQLITE_DEFA
4370: 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 ULT_WORKER_THREA
4380: 44 53 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f DS>SQLITE_MAX_WO
4390: 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 75 RKER_THREADS.# u
43a0: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f ndef SQLITE_MAX_
43b0: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 WORKER_THREADS.#
43c0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
43d0: 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 AX_WORKER_THREAD
43e0: 53 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 S SQLITE_DEFAULT
43f0: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a _WORKER_THREADS.
4400: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 #endif../*.** Th
4410: 65 20 64 65 66 61 75 6c 74 20 69 6e 69 74 69 61 e default initia
4420: 6c 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 66 6f 72 l allocation for
4430: 20 74 68 65 20 70 61 67 65 63 61 63 68 65 20 77 the pagecache w
4440: 68 65 6e 20 75 73 69 6e 67 20 73 65 70 61 72 61 hen using separa
4450: 74 65 0a 2a 2a 20 70 61 67 65 63 61 63 68 65 73 te.** pagecaches
4460: 20 66 6f 72 20 65 61 63 68 20 64 61 74 61 62 61 for each databa
4470: 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 se connection.
4480: 41 20 70 6f 73 69 74 69 76 65 20 6e 75 6d 62 65 A positive numbe
4490: 72 20 69 73 20 74 68 65 0a 2a 2a 20 6e 75 6d 62 r is the.** numb
44a0: 65 72 20 6f 66 20 70 61 67 65 73 2e 20 20 41 20 er of pages. A
44b0: 6e 65 67 61 74 69 76 65 20 6e 75 6d 62 65 72 20 negative number
44c0: 4e 20 74 72 61 6e 73 6c 61 74 69 6f 6e 73 20 6d N translations m
44d0: 65 61 6e 73 20 74 68 61 74 20 61 20 62 75 66 66 eans that a buff
44e0: 65 72 0a 2a 2a 20 6f 66 20 2d 31 30 32 34 2a 4e er.** of -1024*N
44f0: 20 62 79 74 65 73 20 69 73 20 61 6c 6c 6f 63 61 bytes is alloca
4500: 74 65 64 20 61 6e 64 20 75 73 65 64 20 66 6f 72 ted and used for
4510: 20 61 73 20 6d 61 6e 79 20 70 61 67 65 73 20 61 as many pages a
4520: 73 20 69 74 20 77 69 6c 6c 20 68 6f 6c 64 2e 0a s it will hold..
4530: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
4540: 45 5f 44 45 46 41 55 4c 54 5f 50 43 41 43 48 45 E_DEFAULT_PCACHE
4550: 5f 49 4e 49 54 53 5a 0a 23 20 64 65 66 69 6e 65 _INITSZ.# define
4560: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
4570: 50 43 41 43 48 45 5f 49 4e 49 54 53 5a 20 31 30 PCACHE_INITSZ 10
4580: 30 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 0.#endif.../*.**
4590: 20 47 43 43 20 64 6f 65 73 20 6e 6f 74 20 64 65 GCC does not de
45a0: 66 69 6e 65 20 74 68 65 20 6f 66 66 73 65 74 6f fine the offseto
45b0: 66 28 29 20 6d 61 63 72 6f 20 73 6f 20 77 65 27 f() macro so we'
45c0: 6c 6c 20 68 61 76 65 20 74 6f 20 64 6f 20 69 74 ll have to do it
45d0: 0a 2a 2a 20 6f 75 72 73 65 6c 76 65 73 2e 0a 2a .** ourselves..*
45e0: 2f 0a 23 69 66 6e 64 65 66 20 6f 66 66 73 65 74 /.#ifndef offset
45f0: 6f 66 0a 23 64 65 66 69 6e 65 20 6f 66 66 73 65 of.#define offse
4600: 74 6f 66 28 53 54 52 55 43 54 55 52 45 2c 46 49 tof(STRUCTURE,FI
4610: 45 4c 44 29 20 28 28 69 6e 74 29 28 28 63 68 61 ELD) ((int)((cha
4620: 72 2a 29 26 28 28 53 54 52 55 43 54 55 52 45 2a r*)&((STRUCTURE*
4630: 29 30 29 2d 3e 46 49 45 4c 44 29 29 0a 23 65 6e )0)->FIELD)).#en
4640: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f dif../*.** Macro
4650: 73 20 74 6f 20 63 6f 6d 70 75 74 65 20 6d 69 6e s to compute min
4660: 69 6d 75 6d 20 61 6e 64 20 6d 61 78 69 6d 75 6d imum and maximum
4670: 20 6f 66 20 74 77 6f 20 6e 75 6d 62 65 72 73 2e of two numbers.
4680: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 49 4e 28 .*/.#define MIN(
4690: 41 2c 42 29 20 28 28 41 29 3c 28 42 29 3f 28 41 A,B) ((A)<(B)?(A
46a0: 29 3a 28 42 29 29 0a 23 64 65 66 69 6e 65 20 4d ):(B)).#define M
46b0: 41 58 28 41 2c 42 29 20 28 28 41 29 3e 28 42 29 AX(A,B) ((A)>(B)
46c0: 3f 28 41 29 3a 28 42 29 29 0a 0a 2f 2a 0a 2a 2a ?(A):(B))../*.**
46d0: 20 53 77 61 70 20 74 77 6f 20 6f 62 6a 65 63 74 Swap two object
46e0: 73 20 6f 66 20 74 79 70 65 20 54 59 50 45 2e 0a s of type TYPE..
46f0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 57 41 50 28 */.#define SWAP(
4700: 54 59 50 45 2c 41 2c 42 29 20 7b 54 59 50 45 20 TYPE,A,B) {TYPE
4710: 74 3d 41 3b 20 41 3d 42 3b 20 42 3d 74 3b 7d 0a t=A; A=B; B=t;}.
4720: 0a 2f 2a 0a 2a 2a 20 43 68 65 63 6b 20 74 6f 20 ./*.** Check to
4730: 73 65 65 20 69 66 20 74 68 69 73 20 6d 61 63 68 see if this mach
4740: 69 6e 65 20 75 73 65 73 20 45 42 43 44 49 43 2e ine uses EBCDIC.
4750: 20 20 28 59 65 73 2c 20 62 65 6c 69 65 76 65 20 (Yes, believe
4760: 69 74 20 6f 72 0a 2a 2a 20 6e 6f 74 2c 20 74 68 it or.** not, th
4770: 65 72 65 20 61 72 65 20 73 74 69 6c 6c 20 6d 61 ere are still ma
4780: 63 68 69 6e 65 73 20 6f 75 74 20 74 68 65 72 65 chines out there
4790: 20 74 68 61 74 20 75 73 65 20 45 42 43 44 49 43 that use EBCDIC
47a0: 2e 29 0a 2a 2f 0a 23 69 66 20 27 41 27 20 3d 3d .).*/.#if 'A' ==
47b0: 20 27 5c 33 30 31 27 0a 23 20 64 65 66 69 6e 65 '\301'.# define
47c0: 20 53 51 4c 49 54 45 5f 45 42 43 44 49 43 20 31 SQLITE_EBCDIC 1
47d0: 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
47e0: 53 51 4c 49 54 45 5f 41 53 43 49 49 20 31 0a 23 SQLITE_ASCII 1.#
47f0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 endif../*.** Int
4800: 65 67 65 72 73 20 6f 66 20 6b 6e 6f 77 6e 20 73 egers of known s
4810: 69 7a 65 73 2e 20 20 54 68 65 73 65 20 74 79 70 izes. These typ
4820: 65 64 65 66 73 20 6d 69 67 68 74 20 63 68 61 6e edefs might chan
4830: 67 65 20 66 6f 72 20 61 72 63 68 69 74 65 63 74 ge for architect
4840: 75 72 65 73 0a 2a 2a 20 77 68 65 72 65 20 74 68 ures.** where th
4850: 65 20 73 69 7a 65 73 20 76 65 72 79 2e 20 20 50 e sizes very. P
4860: 72 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 reprocessor macr
4870: 6f 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 os are available
4880: 20 73 6f 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 so that the.**
4890: 74 79 70 65 73 20 63 61 6e 20 62 65 20 63 6f 6e types can be con
48a0: 76 65 6e 69 65 6e 74 6c 79 20 72 65 64 65 66 69 veniently redefi
48b0: 6e 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 ned at compile-t
48c0: 79 70 65 2e 20 20 4c 69 6b 65 20 74 68 69 73 3a ype. Like this:
48d0: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 63 .**.** c
48e0: 63 20 27 2d 44 55 49 4e 54 50 54 52 5f 54 59 50 c '-DUINTPTR_TYP
48f0: 45 3d 6c 6f 6e 67 20 6c 6f 6e 67 20 69 6e 74 27 E=long long int'
4900: 20 2e 2e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 ....*/.#ifndef
4910: 55 49 4e 54 33 32 5f 54 59 50 45 0a 23 20 69 66 UINT32_TYPE.# if
4920: 64 65 66 20 48 41 56 45 5f 55 49 4e 54 33 32 5f def HAVE_UINT32_
4930: 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 T.# define UINT
4940: 33 32 5f 54 59 50 45 20 75 69 6e 74 33 32 5f 74 32_TYPE uint32_t
4950: 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e .# else.# defin
4960: 65 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 6e e UINT32_TYPE un
4970: 73 69 67 6e 65 64 20 69 6e 74 0a 23 20 65 6e 64 signed int.# end
4980: 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 if.#endif.#ifnde
4990: 66 20 55 49 4e 54 31 36 5f 54 59 50 45 0a 23 20 f UINT16_TYPE.#
49a0: 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 31 ifdef HAVE_UINT1
49b0: 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 6_T.# define UI
49c0: 4e 54 31 36 5f 54 59 50 45 20 75 69 6e 74 31 36 NT16_TYPE uint16
49d0: 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 _t.# else.# def
49e0: 69 6e 65 20 55 49 4e 54 31 36 5f 54 59 50 45 20 ine UINT16_TYPE
49f0: 75 6e 73 69 67 6e 65 64 20 73 68 6f 72 74 20 69 unsigned short i
4a00: 6e 74 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 nt.# endif.#endi
4a10: 66 0a 23 69 66 6e 64 65 66 20 49 4e 54 31 36 5f f.#ifndef INT16_
4a20: 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 41 56 TYPE.# ifdef HAV
4a30: 45 5f 49 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 E_INT16_T.# def
4a40: 69 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 69 ine INT16_TYPE i
4a50: 6e 74 31 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 nt16_t.# else.#
4a60: 20 64 65 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 define INT16_TY
4a70: 50 45 20 73 68 6f 72 74 20 69 6e 74 0a 23 20 65 PE short int.# e
4a80: 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e ndif.#endif.#ifn
4a90: 64 65 66 20 55 49 4e 54 38 5f 54 59 50 45 0a 23 def UINT8_TYPE.#
4aa0: 20 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 ifdef HAVE_UINT
4ab0: 38 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 8_T.# define UI
4ac0: 4e 54 38 5f 54 59 50 45 20 75 69 6e 74 38 5f 74 NT8_TYPE uint8_t
4ad0: 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e .# else.# defin
4ae0: 65 20 55 49 4e 54 38 5f 54 59 50 45 20 75 6e 73 e UINT8_TYPE uns
4af0: 69 67 6e 65 64 20 63 68 61 72 0a 23 20 65 6e 64 igned char.# end
4b00: 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 if.#endif.#ifnde
4b10: 66 20 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 f INT8_TYPE.# if
4b20: 64 65 66 20 48 41 56 45 5f 49 4e 54 38 5f 54 0a def HAVE_INT8_T.
4b30: 23 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 # define INT8_T
4b40: 59 50 45 20 69 6e 74 38 5f 74 0a 23 20 65 6c 73 YPE int8_t.# els
4b50: 65 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 38 e.# define INT8
4b60: 5f 54 59 50 45 20 73 69 67 6e 65 64 20 63 68 61 _TYPE signed cha
4b70: 72 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 r.# endif.#endif
4b80: 0a 23 69 66 6e 64 65 66 20 4c 4f 4e 47 44 4f 55 .#ifndef LONGDOU
4b90: 42 4c 45 5f 54 59 50 45 0a 23 20 64 65 66 69 6e BLE_TYPE.# defin
4ba0: 65 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 e LONGDOUBLE_TYP
4bb0: 45 20 6c 6f 6e 67 20 64 6f 75 62 6c 65 0a 23 65 E long double.#e
4bc0: 6e 64 69 66 0a 74 79 70 65 64 65 66 20 73 71 6c ndif.typedef sql
4bd0: 69 74 65 5f 69 6e 74 36 34 20 69 36 34 3b 20 20 ite_int64 i64;
4be0: 20 20 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 /* 8-byt
4bf0: 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 e signed integer
4c00: 20 2a 2f 0a 74 79 70 65 64 65 66 20 73 71 6c 69 */.typedef sqli
4c10: 74 65 5f 75 69 6e 74 36 34 20 75 36 34 3b 20 20 te_uint64 u64;
4c20: 20 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 /* 8-byte
4c30: 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 unsigned intege
4c40: 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e r */.typedef UIN
4c50: 54 33 32 5f 54 59 50 45 20 75 33 32 3b 20 20 20 T32_TYPE u32;
4c60: 20 20 20 20 20 20 20 20 2f 2a 20 34 2d 62 79 74 /* 4-byt
4c70: 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 e unsigned integ
4c80: 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 er */.typedef UI
4c90: 4e 54 31 36 5f 54 59 50 45 20 75 31 36 3b 20 20 NT16_TYPE u16;
4ca0: 20 20 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 /* 2-by
4cb0: 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 te unsigned inte
4cc0: 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 ger */.typedef I
4cd0: 4e 54 31 36 5f 54 59 50 45 20 69 31 36 3b 20 20 NT16_TYPE i16;
4ce0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 /* 2-b
4cf0: 79 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 yte signed integ
4d00: 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 er */.typedef UI
4d10: 4e 54 38 5f 54 59 50 45 20 75 38 3b 20 20 20 20 NT8_TYPE u8;
4d20: 20 20 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 /* 1-by
4d30: 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 te unsigned inte
4d40: 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 ger */.typedef I
4d50: 4e 54 38 5f 54 59 50 45 20 69 38 3b 20 20 20 20 NT8_TYPE i8;
4d60: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 /* 1-b
4d70: 79 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 yte signed integ
4d80: 65 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c er */../*.** SQL
4d90: 49 54 45 5f 4d 41 58 5f 55 33 32 20 69 73 20 61 ITE_MAX_U32 is a
4da0: 20 75 36 34 20 63 6f 6e 73 74 61 6e 74 20 74 68 u64 constant th
4db0: 61 74 20 69 73 20 74 68 65 20 6d 61 78 69 6d 75 at is the maximu
4dc0: 6d 20 75 36 34 20 76 61 6c 75 65 0a 2a 2a 20 74 m u64 value.** t
4dd0: 68 61 74 20 63 61 6e 20 62 65 20 73 74 6f 72 65 hat can be store
4de0: 64 20 69 6e 20 61 20 75 33 32 20 77 69 74 68 6f d in a u32 witho
4df0: 75 74 20 6c 6f 73 73 20 6f 66 20 64 61 74 61 2e ut loss of data.
4e00: 20 20 54 68 65 20 76 61 6c 75 65 0a 2a 2a 20 69 The value.** i
4e10: 73 20 30 78 30 30 30 30 30 30 30 30 66 66 66 66 s 0x00000000ffff
4e20: 66 66 66 66 2e 20 20 42 75 74 20 62 65 63 61 75 ffff. But becau
4e30: 73 65 20 6f 66 20 71 75 69 72 6b 73 20 6f 66 20 se of quirks of
4e40: 73 6f 6d 65 20 63 6f 6d 70 69 6c 65 72 73 2c 20 some compilers,
4e50: 77 65 0a 2a 2a 20 68 61 76 65 20 74 6f 20 73 70 we.** have to sp
4e60: 65 63 69 66 79 20 74 68 65 20 76 61 6c 75 65 20 ecify the value
4e70: 69 6e 20 74 68 65 20 6c 65 73 73 20 69 6e 74 75 in the less intu
4e80: 69 74 69 76 65 20 6d 61 6e 6e 65 72 20 73 68 6f itive manner sho
4e90: 77 6e 3a 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 wn:.*/.#define S
4ea0: 51 4c 49 54 45 5f 4d 41 58 5f 55 33 32 20 20 28 QLITE_MAX_U32 (
4eb0: 28 28 28 75 36 34 29 31 29 3c 3c 33 32 29 2d 31 (((u64)1)<<32)-1
4ec0: 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 )../*.** The dat
4ed0: 61 74 79 70 65 20 75 73 65 64 20 74 6f 20 73 74 atype used to st
4ee0: 6f 72 65 20 65 73 74 69 6d 61 74 65 73 20 6f 66 ore estimates of
4ef0: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 72 the number of r
4f00: 6f 77 73 20 69 6e 20 61 0a 2a 2a 20 74 61 62 6c ows in a.** tabl
4f10: 65 20 6f 72 20 69 6e 64 65 78 2e 20 20 54 68 69 e or index. Thi
4f20: 73 20 69 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 s is an unsigned
4f30: 20 69 6e 74 65 67 65 72 20 74 79 70 65 2e 20 20 integer type.
4f40: 46 6f 72 20 39 39 2e 39 25 20 6f 66 0a 2a 2a 20 For 99.9% of.**
4f50: 74 68 65 20 77 6f 72 6c 64 2c 20 61 20 33 32 2d the world, a 32-
4f60: 62 69 74 20 69 6e 74 65 67 65 72 20 69 73 20 73 bit integer is s
4f70: 75 66 66 69 63 69 65 6e 74 2e 20 20 42 75 74 20 ufficient. But
4f80: 61 20 36 34 2d 62 69 74 20 69 6e 74 65 67 65 72 a 64-bit integer
4f90: 0a 2a 2a 20 63 61 6e 20 62 65 20 75 73 65 64 20 .** can be used
4fa0: 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 at compile-time
4fb0: 69 66 20 64 65 73 69 72 65 64 2e 0a 2a 2f 0a 23 if desired..*/.#
4fc0: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 36 34 42 ifdef SQLITE_64B
4fd0: 49 54 5f 53 54 41 54 53 0a 20 74 79 70 65 64 65 IT_STATS. typede
4fe0: 66 20 75 36 34 20 74 52 6f 77 63 6e 74 3b 20 20 f u64 tRowcnt;
4ff0: 20 20 2f 2a 20 36 34 2d 62 69 74 20 6f 6e 6c 79 /* 64-bit only
5000: 20 69 66 20 72 65 71 75 65 73 74 65 64 20 61 74 if requested at
5010: 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 2a 2f compile-time */
5020: 0a 23 65 6c 73 65 0a 20 74 79 70 65 64 65 66 20 .#else. typedef
5030: 75 33 32 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 u32 tRowcnt;
5040: 2f 2a 20 33 32 2d 62 69 74 20 69 73 20 74 68 65 /* 32-bit is the
5050: 20 64 65 66 61 75 6c 74 20 2a 2f 0a 23 65 6e 64 default */.#end
5060: 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 73 74 69 6d 61 if../*.** Estima
5070: 74 65 64 20 71 75 61 6e 74 69 74 69 65 73 20 75 ted quantities u
5080: 73 65 64 20 66 6f 72 20 71 75 65 72 79 20 70 6c sed for query pl
5090: 61 6e 6e 69 6e 67 20 61 72 65 20 73 74 6f 72 65 anning are store
50a0: 64 20 61 73 20 31 36 2d 62 69 74 0a 2a 2a 20 6c d as 16-bit.** l
50b0: 6f 67 61 72 69 74 68 6d 73 2e 20 20 46 6f 72 20 ogarithms. For
50c0: 71 75 61 6e 74 69 74 79 20 58 2c 20 74 68 65 20 quantity X, the
50d0: 76 61 6c 75 65 20 73 74 6f 72 65 64 20 69 73 20 value stored is
50e0: 31 30 2a 6c 6f 67 32 28 58 29 2e 20 20 54 68 69 10*log2(X). Thi
50f0: 73 0a 2a 2a 20 67 69 76 65 73 20 61 20 70 6f 73 s.** gives a pos
5100: 73 69 62 6c 65 20 72 61 6e 67 65 20 6f 66 20 76 sible range of v
5110: 61 6c 75 65 73 20 6f 66 20 61 70 70 72 6f 78 69 alues of approxi
5120: 6d 61 74 65 6c 79 20 31 2e 30 65 39 38 36 20 74 mately 1.0e986 t
5130: 6f 20 31 65 2d 39 38 36 2e 0a 2a 2a 20 42 75 74 o 1e-986..** But
5140: 20 74 68 65 20 61 6c 6c 6f 77 65 64 20 76 61 6c the allowed val
5150: 75 65 73 20 61 72 65 20 22 67 72 61 69 6e 79 22 ues are "grainy"
5160: 2e 20 20 4e 6f 74 20 65 76 65 72 79 20 76 61 6c . Not every val
5170: 75 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 61 ue is representa
5180: 62 6c 65 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d ble..** For exam
5190: 70 6c 65 2c 20 71 75 61 6e 74 69 74 69 65 73 20 ple, quantities
51a0: 31 36 20 61 6e 64 20 31 37 20 61 72 65 20 62 6f 16 and 17 are bo
51b0: 74 68 20 72 65 70 72 65 73 65 6e 74 65 64 20 62 th represented b
51c0: 79 20 61 20 4c 6f 67 45 73 74 0a 2a 2a 20 6f 66 y a LogEst.** of
51d0: 20 34 30 2e 20 20 48 6f 77 65 76 65 72 2c 20 73 40. However, s
51e0: 69 6e 63 65 20 4c 6f 67 45 73 74 20 71 75 61 6e ince LogEst quan
51f0: 74 69 74 69 65 73 20 61 72 65 20 73 75 70 70 6f tities are suppo
5200: 73 65 20 74 6f 20 62 65 20 65 73 74 69 6d 61 74 se to be estimat
5210: 65 73 2c 0a 2a 2a 20 6e 6f 74 20 65 78 61 63 74 es,.** not exact
5220: 20 76 61 6c 75 65 73 2c 20 74 68 69 73 20 69 6d values, this im
5230: 70 72 65 63 69 73 69 6f 6e 20 69 73 20 6e 6f 74 precision is not
5240: 20 61 20 70 72 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a a problem..**.*
5250: 2a 20 22 4c 6f 67 45 73 74 22 20 69 73 20 73 68 * "LogEst" is sh
5260: 6f 72 74 20 66 6f 72 20 22 4c 6f 67 61 72 69 74 ort for "Logarit
5270: 68 6d 69 63 20 45 73 74 69 6d 61 74 65 22 2e 0a hmic Estimate"..
5280: 2a 2a 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a **.** Examples:.
5290: 2a 2a 20 20 20 20 20 20 31 20 2d 3e 20 30 20 20 ** 1 -> 0
52a0: 20 20 20 20 20 20 20 20 20 20 20 20 32 30 20 2d 20 -
52b0: 3e 20 34 33 20 20 20 20 20 20 20 20 20 20 31 30 > 43 10
52c0: 30 30 30 20 2d 3e 20 31 33 32 0a 2a 2a 20 20 20 000 -> 132.**
52d0: 20 20 20 32 20 2d 3e 20 31 30 20 20 20 20 20 20 2 -> 10
52e0: 20 20 20 20 20 20 20 32 35 20 2d 3e 20 34 36 20 25 -> 46
52f0: 20 20 20 20 20 20 20 20 20 32 35 30 30 30 20 2d 25000 -
5300: 3e 20 31 34 36 0a 2a 2a 20 20 20 20 20 20 33 20 > 146.** 3
5310: 2d 3e 20 31 36 20 20 20 20 20 20 20 20 20 20 20 -> 16
5320: 20 31 30 30 20 2d 3e 20 36 36 20 20 20 20 20 20 100 -> 66
5330: 20 20 31 30 30 30 30 30 30 20 2d 3e 20 31 39 39 1000000 -> 199
5340: 0a 2a 2a 20 20 20 20 20 20 34 20 2d 3e 20 32 30 .** 4 -> 20
5350: 20 20 20 20 20 20 20 20 20 20 20 31 30 30 30 20 1000
5360: 2d 3e 20 39 39 20 20 20 20 20 20 20 20 31 30 34 -> 99 104
5370: 38 35 37 36 20 2d 3e 20 32 30 30 0a 2a 2a 20 20 8576 -> 200.**
5380: 20 20 20 31 30 20 2d 3e 20 33 33 20 20 20 20 20 10 -> 33
5390: 20 20 20 20 20 20 31 30 32 34 20 2d 3e 20 31 30 1024 -> 10
53a0: 30 20 20 20 20 34 32 39 34 39 36 37 32 39 36 20 0 4294967296
53b0: 2d 3e 20 33 32 30 0a 2a 2a 0a 2a 2a 20 54 68 65 -> 320.**.** The
53c0: 20 4c 6f 67 45 73 74 20 63 61 6e 20 62 65 20 6e LogEst can be n
53d0: 65 67 61 74 69 76 65 20 74 6f 20 69 6e 64 69 63 egative to indic
53e0: 61 74 65 20 66 72 61 63 74 69 6f 6e 61 6c 20 76 ate fractional v
53f0: 61 6c 75 65 73 2e 20 0a 2a 2a 20 45 78 61 6d 70 alues. .** Examp
5400: 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 30 2e les:.**.** 0.
5410: 35 20 2d 3e 20 2d 31 30 20 20 20 20 20 20 20 20 5 -> -10
5420: 20 20 20 30 2e 31 20 2d 3e 20 2d 33 33 20 20 20 0.1 -> -33
5430: 20 20 20 20 20 30 2e 30 36 32 35 20 2d 3e 20 2d 0.0625 -> -
5440: 34 30 0a 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 40.*/.typedef IN
5450: 54 31 36 5f 54 59 50 45 20 4c 6f 67 45 73 74 3b T16_TYPE LogEst;
5460: 0a 0a 2f 2a 0a 2a 2a 20 53 65 74 20 74 68 65 20 ../*.** Set the
5470: 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 6d SQLITE_PTRSIZE m
5480: 61 63 72 6f 20 74 6f 20 74 68 65 20 6e 75 6d 62 acro to the numb
5490: 65 72 20 6f 66 20 62 79 74 65 73 20 69 6e 20 61 er of bytes in a
54a0: 20 70 6f 69 6e 74 65 72 0a 2a 2f 0a 23 69 66 6e pointer.*/.#ifn
54b0: 64 65 66 20 53 51 4c 49 54 45 5f 50 54 52 53 49 def SQLITE_PTRSI
54c0: 5a 45 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 ZE.# if defined(
54d0: 5f 5f 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 __SIZEOF_POINTER
54e0: 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 __).# define S
54f0: 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 5f 5f QLITE_PTRSIZE __
5500: 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f SIZEOF_POINTER__
5510: 0a 23 20 65 6c 69 66 20 64 65 66 69 6e 65 64 28 .# elif defined(
5520: 69 33 38 36 29 20 20 20 20 20 7c 7c 20 64 65 66 i386) || def
5530: 69 6e 65 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 ined(__i386__)
5540: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 || defined(_M_I
5550: 58 38 36 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 X86) || \.
5560: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 defined(_M_A
5570: 52 4d 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 RM) || defined
5580: 28 5f 5f 61 72 6d 5f 5f 29 20 20 20 20 7c 7c 20 (__arm__) ||
5590: 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 29 0a 23 defined(__x86).#
55a0: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
55b0: 5f 50 54 52 53 49 5a 45 20 34 0a 23 20 65 6c 73 _PTRSIZE 4.# els
55c0: 65 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c e.# define SQL
55d0: 49 54 45 5f 50 54 52 53 49 5a 45 20 38 0a 23 20 ITE_PTRSIZE 8.#
55e0: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a endif.#endif../*
55f0: 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 .** Macros to de
5600: 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 termine whether
5610: 74 68 65 20 6d 61 63 68 69 6e 65 20 69 73 20 62 the machine is b
5620: 69 67 20 6f 72 20 6c 69 74 74 6c 65 20 65 6e 64 ig or little end
5630: 69 61 6e 2c 0a 2a 2a 20 61 6e 64 20 77 68 65 74 ian,.** and whet
5640: 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 61 74 20 her or not that
5650: 64 65 74 65 72 6d 69 6e 61 74 69 6f 6e 20 69 73 determination is
5660: 20 72 75 6e 2d 74 69 6d 65 20 6f 72 20 63 6f 6d run-time or com
5670: 70 69 6c 65 2d 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a pile-time..**.**
5680: 20 46 6f 72 20 62 65 73 74 20 70 65 72 66 6f 72 For best perfor
5690: 6d 61 6e 63 65 2c 20 61 6e 20 61 74 74 65 6d 70 mance, an attemp
56a0: 74 20 69 73 20 6d 61 64 65 20 74 6f 20 67 75 65 t is made to gue
56b0: 73 73 20 61 74 20 74 68 65 20 62 79 74 65 2d 6f ss at the byte-o
56c0: 72 64 65 72 0a 2a 2a 20 75 73 69 6e 67 20 43 2d rder.** using C-
56d0: 70 72 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 preprocessor mac
56e0: 72 6f 73 2e 20 20 49 66 20 74 68 61 74 20 69 73 ros. If that is
56f0: 20 75 6e 73 75 63 63 65 73 73 66 75 6c 2c 20 6f unsuccessful, o
5700: 72 20 69 66 0a 2a 2a 20 2d 44 53 51 4c 49 54 45 r if.** -DSQLITE
5710: 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 _RUNTIME_BYTEORD
5720: 45 52 3d 31 20 69 73 20 73 65 74 2c 20 74 68 65 ER=1 is set, the
5730: 6e 20 62 79 74 65 2d 6f 72 64 65 72 20 69 73 20 n byte-order is
5740: 64 65 74 65 72 6d 69 6e 65 64 0a 2a 2a 20 61 74 determined.** at
5750: 20 72 75 6e 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 69 run-time..*/.#i
5760: 66 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c fdef SQLITE_AMAL
5770: 47 41 4d 41 54 49 4f 4e 0a 63 6f 6e 73 74 20 69 GAMATION.const i
5780: 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 20 3d 20 nt sqlite3one =
5790: 31 3b 0a 23 65 6c 73 65 0a 65 78 74 65 72 6e 20 1;.#else.extern
57a0: 63 6f 6e 73 74 20 69 6e 74 20 73 71 6c 69 74 65 const int sqlite
57b0: 33 6f 6e 65 3b 0a 23 65 6e 64 69 66 0a 23 69 66 3one;.#endif.#if
57c0: 20 28 64 65 66 69 6e 65 64 28 69 33 38 36 29 20 (defined(i386)
57d0: 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f || defined(_
57e0: 5f 69 33 38 36 5f 5f 29 20 20 20 7c 7c 20 64 65 _i386__) || de
57f0: 66 69 6e 65 64 28 5f 4d 5f 49 58 38 36 29 20 7c fined(_M_IX86) |
5800: 7c 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 | \. defi
5810: 6e 65 64 28 5f 5f 78 38 36 5f 36 34 29 20 7c 7c ned(__x86_64) ||
5820: 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 5f 36 defined(__x86_6
5830: 34 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 4__) || defined(
5840: 5f 4d 5f 58 36 34 29 20 20 7c 7c 20 20 20 20 5c _M_X64) || \
5850: 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f 4d . defined(_M
5860: 5f 41 4d 44 36 34 29 20 7c 7c 20 64 65 66 69 6e _AMD64) || defin
5870: 65 64 28 5f 4d 5f 41 52 4d 29 20 20 20 20 20 7c ed(_M_ARM) |
5880: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 29 | defined(__x86)
5890: 20 20 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 || \.
58a0: 64 65 66 69 6e 65 64 28 5f 5f 61 72 6d 5f 5f 29 defined(__arm__)
58b0: 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 ) && !defined(SQ
58c0: 4c 49 54 45 5f 52 55 4e 54 49 4d 45 5f 42 59 54 LITE_RUNTIME_BYT
58d0: 45 4f 52 44 45 52 29 0a 23 20 64 65 66 69 6e 65 EORDER).# define
58e0: 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 SQLITE_BYTEORDE
58f0: 52 20 20 20 20 31 32 33 34 0a 23 20 64 65 66 69 R 1234.# defi
5900: 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 ne SQLITE_BIGEND
5910: 49 41 4e 20 20 20 20 30 0a 23 20 64 65 66 69 6e IAN 0.# defin
5920: 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 45 e SQLITE_LITTLEE
5930: 4e 44 49 41 4e 20 31 0a 23 20 64 65 66 69 6e 65 NDIAN 1.# define
5940: 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 SQLITE_UTF16NAT
5950: 49 56 45 20 20 53 51 4c 49 54 45 5f 55 54 46 31 IVE SQLITE_UTF1
5960: 36 4c 45 0a 23 65 6e 64 69 66 0a 23 69 66 20 28 6LE.#endif.#if (
5970: 64 65 66 69 6e 65 64 28 73 70 61 72 63 29 20 20 defined(sparc)
5980: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 70 || defined(__p
5990: 70 63 5f 5f 29 29 20 20 5c 0a 20 20 20 20 26 26 pc__)) \. &&
59a0: 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
59b0: 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 _RUNTIME_BYTEORD
59c0: 45 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ER).# define SQL
59d0: 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 ITE_BYTEORDER
59e0: 20 34 33 32 31 0a 23 20 64 65 66 69 6e 65 20 53 4321.# define S
59f0: 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 QLITE_BIGENDIAN
5a00: 20 20 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 1.# define SQ
5a10: 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 LITE_LITTLEENDIA
5a20: 4e 20 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c N 0.# define SQL
5a30: 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 ITE_UTF16NATIVE
5a40: 20 53 51 4c 49 54 45 5f 55 54 46 31 36 42 45 0a SQLITE_UTF16BE.
5a50: 23 65 6e 64 69 66 0a 23 69 66 20 21 64 65 66 69 #endif.#if !defi
5a60: 6e 65 64 28 53 51 4c 49 54 45 5f 42 59 54 45 4f ned(SQLITE_BYTEO
5a70: 52 44 45 52 29 0a 23 20 64 65 66 69 6e 65 20 53 RDER).# define S
5a80: 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 QLITE_BYTEORDER
5a90: 20 20 20 30 20 20 20 20 20 2f 2a 20 30 20 6d 65 0 /* 0 me
5aa0: 61 6e 73 20 22 75 6e 6b 6e 6f 77 6e 20 61 74 20 ans "unknown at
5ab0: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 22 20 2a 2f compile-time" */
5ac0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
5ad0: 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 28 2a _BIGENDIAN (*
5ae0: 28 63 68 61 72 20 2a 29 28 26 73 71 6c 69 74 65 (char *)(&sqlite
5af0: 33 6f 6e 65 29 3d 3d 30 29 0a 23 20 64 65 66 69 3one)==0).# defi
5b00: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
5b10: 45 4e 44 49 41 4e 20 28 2a 28 63 68 61 72 20 2a ENDIAN (*(char *
5b20: 29 28 26 73 71 6c 69 74 65 33 6f 6e 65 29 3d 3d )(&sqlite3one)==
5b30: 31 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1).# define SQLI
5b40: 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 TE_UTF16NATIVE
5b50: 28 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 (SQLITE_BIGENDIA
5b60: 4e 3f 53 51 4c 49 54 45 5f 55 54 46 31 36 42 45 N?SQLITE_UTF16BE
5b70: 3a 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 29 :SQLITE_UTF16LE)
5b80: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 43 .#endif../*.** C
5b90: 6f 6e 73 74 61 6e 74 73 20 66 6f 72 20 74 68 65 onstants for the
5ba0: 20 6c 61 72 67 65 73 74 20 61 6e 64 20 73 6d 61 largest and sma
5bb0: 6c 6c 65 73 74 20 70 6f 73 73 69 62 6c 65 20 36 llest possible 6
5bc0: 34 2d 62 69 74 20 73 69 67 6e 65 64 20 69 6e 74 4-bit signed int
5bd0: 65 67 65 72 73 2e 0a 2a 2a 20 54 68 65 73 65 20 egers..** These
5be0: 6d 61 63 72 6f 73 20 61 72 65 20 64 65 73 69 67 macros are desig
5bf0: 6e 65 64 20 74 6f 20 77 6f 72 6b 20 63 6f 72 72 ned to work corr
5c00: 65 63 74 6c 79 20 6f 6e 20 62 6f 74 68 20 33 32 ectly on both 32
5c10: 2d 62 69 74 20 61 6e 64 20 36 34 2d 62 69 74 0a -bit and 64-bit.
5c20: 2a 2a 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a 2f ** compilers..*/
5c30: 0a 23 64 65 66 69 6e 65 20 4c 41 52 47 45 53 54 .#define LARGEST
5c40: 5f 49 4e 54 36 34 20 20 28 30 78 66 66 66 66 66 _INT64 (0xfffff
5c50: 66 66 66 7c 28 28 28 69 36 34 29 30 78 37 66 66 fff|(((i64)0x7ff
5c60: 66 66 66 66 66 29 3c 3c 33 32 29 29 0a 23 64 65 fffff)<<32)).#de
5c70: 66 69 6e 65 20 53 4d 41 4c 4c 45 53 54 5f 49 4e fine SMALLEST_IN
5c80: 54 36 34 20 28 28 28 69 36 34 29 2d 31 29 20 2d T64 (((i64)-1) -
5c90: 20 4c 41 52 47 45 53 54 5f 49 4e 54 36 34 29 0a LARGEST_INT64).
5ca0: 0a 2f 2a 20 0a 2a 2a 20 52 6f 75 6e 64 20 75 70 ./* .** Round up
5cb0: 20 61 20 6e 75 6d 62 65 72 20 74 6f 20 74 68 65 a number to the
5cc0: 20 6e 65 78 74 20 6c 61 72 67 65 72 20 6d 75 6c next larger mul
5cd0: 74 69 70 6c 65 20 6f 66 20 38 2e 20 20 54 68 69 tiple of 8. Thi
5ce0: 73 20 69 73 20 75 73 65 64 0a 2a 2a 20 74 6f 20 s is used.** to
5cf0: 66 6f 72 63 65 20 38 2d 62 79 74 65 20 61 6c 69 force 8-byte ali
5d00: 67 6e 6d 65 6e 74 20 6f 6e 20 36 34 2d 62 69 74 gnment on 64-bit
5d10: 20 61 72 63 68 69 74 65 63 74 75 72 65 73 2e 0a architectures..
5d20: 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e 44 */.#define ROUND
5d30: 38 28 78 29 20 20 20 20 20 28 28 28 78 29 2b 37 8(x) (((x)+7
5d40: 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 )&~7)../*.** Rou
5d50: 6e 64 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 6e nd down to the n
5d60: 65 61 72 65 73 74 20 6d 75 6c 74 69 70 6c 65 20 earest multiple
5d70: 6f 66 20 38 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 of 8.*/.#define
5d80: 52 4f 55 4e 44 44 4f 57 4e 38 28 78 29 20 28 28 ROUNDDOWN8(x) ((
5d90: 78 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 41 73 x)&~7)../*.** As
5da0: 73 65 72 74 20 74 68 61 74 20 74 68 65 20 70 6f sert that the po
5db0: 69 6e 74 65 72 20 58 20 69 73 20 61 6c 69 67 6e inter X is align
5dc0: 65 64 20 74 6f 20 61 6e 20 38 2d 62 79 74 65 20 ed to an 8-byte
5dd0: 62 6f 75 6e 64 61 72 79 2e 20 20 54 68 69 73 0a boundary. This.
5de0: 2a 2a 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 ** macro is used
5df0: 20 6f 6e 6c 79 20 77 69 74 68 69 6e 20 61 73 73 only within ass
5e00: 65 72 74 28 29 20 74 6f 20 76 65 72 69 66 79 20 ert() to verify
5e10: 74 68 61 74 20 74 68 65 20 63 6f 64 65 20 67 65 that the code ge
5e20: 74 73 0a 2a 2a 20 61 6c 6c 20 61 6c 69 67 6e 6d ts.** all alignm
5e30: 65 6e 74 20 72 65 73 74 72 69 63 74 69 6f 6e 73 ent restrictions
5e40: 20 63 6f 72 72 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 correct..**.**
5e50: 45 78 63 65 70 74 2c 20 69 66 20 53 51 4c 49 54 Except, if SQLIT
5e60: 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 E_4_BYTE_ALIGNED
5e70: 5f 4d 41 4c 4c 4f 43 20 69 73 20 64 65 66 69 6e _MALLOC is defin
5e80: 65 64 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 ed, then the.**
5e90: 75 6e 64 65 72 6c 79 69 6e 67 20 6d 61 6c 6c 6f underlying mallo
5ea0: 63 28 29 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 c() implementati
5eb0: 6f 6e 20 6d 69 67 68 74 20 72 65 74 75 72 6e 20 on might return
5ec0: 75 73 20 34 2d 62 79 74 65 20 61 6c 69 67 6e 65 us 4-byte aligne
5ed0: 64 0a 2a 2a 20 70 6f 69 6e 74 65 72 73 2e 20 20 d.** pointers.
5ee0: 49 6e 20 74 68 61 74 20 63 61 73 65 2c 20 6f 6e In that case, on
5ef0: 6c 79 20 76 65 72 69 66 79 20 34 2d 62 79 74 65 ly verify 4-byte
5f00: 20 61 6c 69 67 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 alignment..*/.#
5f10: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 34 5f 42 ifdef SQLITE_4_B
5f20: 59 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c YTE_ALIGNED_MALL
5f30: 4f 43 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 OC.# define EIGH
5f40: 54 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 T_BYTE_ALIGNMENT
5f50: 28 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 (X) ((((char*)
5f60: 28 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 (X) - (char*)0)&
5f70: 33 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 20 64 3)==0).#else.# d
5f80: 65 66 69 6e 65 20 45 49 47 48 54 5f 42 59 54 45 efine EIGHT_BYTE
5f90: 5f 41 4c 49 47 4e 4d 45 4e 54 28 58 29 20 20 20 _ALIGNMENT(X)
5fa0: 28 28 28 28 63 68 61 72 2a 29 28 58 29 20 2d 20 ((((char*)(X) -
5fb0: 28 63 68 61 72 2a 29 30 29 26 37 29 3d 3d 30 29 (char*)0)&7)==0)
5fc0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 .#endif../*.** D
5fd0: 69 73 61 62 6c 65 20 4d 4d 41 50 20 6f 6e 20 70 isable MMAP on p
5fe0: 6c 61 74 66 6f 72 6d 73 20 77 68 65 72 65 20 69 latforms where i
5ff0: 74 20 69 73 20 6b 6e 6f 77 6e 20 74 6f 20 6e 6f t is known to no
6000: 74 20 77 6f 72 6b 0a 2a 2f 0a 23 69 66 20 64 65 t work.*/.#if de
6010: 66 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f fined(__OpenBSD_
6020: 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f _) || defined(__
6030: 51 4e 58 4e 54 4f 5f 5f 29 0a 23 20 75 6e 64 65 QNXNTO__).# unde
6040: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 f SQLITE_MAX_MMA
6050: 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 P_SIZE.# define
6060: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
6070: 53 49 5a 45 20 30 0a 23 65 6e 64 69 66 0a 0a 2f SIZE 0.#endif../
6080: 2a 0a 2a 2a 20 44 65 66 61 75 6c 74 20 6d 61 78 *.** Default max
6090: 69 6d 75 6d 20 73 69 7a 65 20 6f 66 20 6d 65 6d imum size of mem
60a0: 6f 72 79 20 75 73 65 64 20 62 79 20 6d 65 6d 6f ory used by memo
60b0: 72 79 2d 6d 61 70 70 65 64 20 49 2f 4f 20 69 6e ry-mapped I/O in
60c0: 20 74 68 65 20 56 46 53 0a 2a 2f 0a 23 69 66 64 the VFS.*/.#ifd
60d0: 65 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a 23 20 69 ef __APPLE__.# i
60e0: 6e 63 6c 75 64 65 20 3c 54 61 72 67 65 74 43 6f nclude <TargetCo
60f0: 6e 64 69 74 69 6f 6e 61 6c 73 2e 68 3e 0a 23 20 nditionals.h>.#
6100: 69 66 20 54 41 52 47 45 54 5f 4f 53 5f 49 50 48 if TARGET_OS_IPH
6110: 4f 4e 45 0a 23 20 20 20 75 6e 64 65 66 20 53 51 ONE.# undef SQ
6120: 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 LITE_MAX_MMAP_SI
6130: 5a 45 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 ZE.# define SQ
6140: 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 LITE_MAX_MMAP_SI
6150: 5a 45 20 30 0a 23 20 65 6e 64 69 66 0a 23 65 6e ZE 0.# endif.#en
6160: 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 dif.#ifndef SQLI
6170: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
6180: 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f 5f .# if defined(__
6190: 6c 69 6e 75 78 5f 5f 29 20 5c 0a 20 20 7c 7c 20 linux__) \. ||
61a0: 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 defined(_WIN32)
61b0: 5c 0a 20 20 7c 7c 20 28 64 65 66 69 6e 65 64 28 \. || (defined(
61c0: 5f 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 64 65 __APPLE__) && de
61d0: 66 69 6e 65 64 28 5f 5f 4d 41 43 48 5f 5f 29 29 fined(__MACH__))
61e0: 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 \. || defined(
61f0: 5f 5f 73 75 6e 29 20 5c 0a 20 20 7c 7c 20 64 65 __sun) \. || de
6200: 66 69 6e 65 64 28 5f 5f 46 72 65 65 42 53 44 5f fined(__FreeBSD_
6210: 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 _) \. || define
6220: 64 28 5f 5f 44 72 61 67 6f 6e 46 6c 79 5f 5f 29 d(__DragonFly__)
6230: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
6240: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
6250: 20 30 78 37 66 66 66 30 30 30 30 20 20 2f 2a 20 0x7fff0000 /*
6260: 32 31 34 37 34 31 38 31 31 32 20 2a 2f 0a 23 20 2147418112 */.#
6270: 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e 65 20 else.# define
6280: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
6290: 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 66 0a 23 SIZE 0.# endif.#
62a0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
62b0: 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 20 AX_MMAP_SIZE_xc
62c0: 31 20 2f 2a 20 65 78 63 6c 75 64 65 20 66 72 6f 1 /* exclude fro
62d0: 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 6e m ctime.c */.#en
62e0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 dif../*.** The d
62f0: 65 66 61 75 6c 74 20 4d 4d 41 50 5f 53 49 5a 45 efault MMAP_SIZE
6300: 20 69 73 20 7a 65 72 6f 20 6f 6e 20 61 6c 6c 20 is zero on all
6310: 70 6c 61 74 66 6f 72 6d 73 2e 20 20 4f 72 2c 20 platforms. Or,
6320: 65 76 65 6e 20 69 66 20 61 20 6c 61 72 67 65 72 even if a larger
6330: 0a 2a 2a 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 .** default MMAP
6340: 5f 53 49 5a 45 20 69 73 20 73 70 65 63 69 66 69 _SIZE is specifi
6350: 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 ed at compile-ti
6360: 6d 65 2c 20 6d 61 6b 65 20 73 75 72 65 20 74 68 me, make sure th
6370: 61 74 20 69 74 20 64 6f 65 73 0a 2a 2a 20 6e 6f at it does.** no
6380: 74 20 65 78 63 65 65 64 20 74 68 65 20 6d 61 78 t exceed the max
6390: 69 6d 75 6d 20 6d 6d 61 70 20 73 69 7a 65 2e 0a imum mmap size..
63a0: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
63b0: 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 E_DEFAULT_MMAP_S
63c0: 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c IZE.# define SQL
63d0: 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 ITE_DEFAULT_MMAP
63e0: 5f 53 49 5a 45 20 30 0a 23 20 64 65 66 69 6e 65 _SIZE 0.# define
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 5f 78 63 20 31 20 20 MMAP_SIZE_xc 1
6410: 2f 2a 20 45 78 63 6c 75 64 65 20 66 72 6f 6d 20 /* Exclude from
6420: 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 6e 64 69 ctime.c */.#endi
6430: 66 0a 23 69 66 20 53 51 4c 49 54 45 5f 44 45 46 f.#if SQLITE_DEF
6440: 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 3e 53 AULT_MMAP_SIZE>S
6450: 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 QLITE_MAX_MMAP_S
6460: 49 5a 45 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 IZE.# undef SQLI
6470: 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f TE_DEFAULT_MMAP_
6480: 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 SIZE.# define SQ
6490: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 LITE_DEFAULT_MMA
64a0: 50 5f 53 49 5a 45 20 53 51 4c 49 54 45 5f 4d 41 P_SIZE SQLITE_MA
64b0: 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 65 6e 64 X_MMAP_SIZE.#end
64c0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 6c 79 20 6f if../*.** Only o
64d0: 6e 65 20 6f 66 20 53 51 4c 49 54 45 5f 45 4e 41 ne of SQLITE_ENA
64e0: 42 4c 45 5f 53 54 41 54 33 20 6f 72 20 53 51 4c BLE_STAT3 or SQL
64f0: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 ITE_ENABLE_STAT4
6500: 20 63 61 6e 20 62 65 20 64 65 66 69 6e 65 64 2e can be defined.
6510: 0a 2a 2a 20 50 72 69 6f 72 69 74 79 20 69 73 20 .** Priority is
6520: 67 69 76 65 6e 20 74 6f 20 53 51 4c 49 54 45 5f given to SQLITE_
6530: 45 4e 41 42 4c 45 5f 53 54 41 54 34 2e 20 20 49 ENABLE_STAT4. I
6540: 66 20 65 69 74 68 65 72 20 61 72 65 20 64 65 66 f either are def
6550: 69 6e 65 64 2c 20 61 6c 73 6f 0a 2a 2a 20 64 65 ined, also.** de
6560: 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 fine SQLITE_ENAB
6570: 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 LE_STAT3_OR_STAT
6580: 34 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 4.*/.#ifdef SQLI
6590: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 0a TE_ENABLE_STAT4.
65a0: 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 # undef SQLITE_E
65b0: 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 20 64 65 NABLE_STAT3.# de
65c0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 fine SQLITE_ENAB
65d0: 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 LE_STAT3_OR_STAT
65e0: 34 20 31 0a 23 65 6c 69 66 20 53 51 4c 49 54 45 4 1.#elif SQLITE
65f0: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 20 _ENABLE_STAT3.#
6600: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e define SQLITE_EN
6610: 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 ABLE_STAT3_OR_ST
6620: 41 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c 49 AT4 1.#elif SQLI
6630: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f TE_ENABLE_STAT3_
6640: 4f 52 5f 53 54 41 54 34 0a 23 20 75 6e 64 65 66 OR_STAT4.# undef
6650: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
6660: 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 65 TAT3_OR_STAT4.#e
6670: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 45 4c 45 ndif../*.** SELE
6680: 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 CTTRACE_ENABLED
6690: 77 69 6c 6c 20 62 65 20 65 69 74 68 65 72 20 31 will be either 1
66a0: 20 6f 72 20 30 20 64 65 70 65 6e 64 69 6e 67 20 or 0 depending
66b0: 6f 6e 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f on whether or no
66c0: 74 0a 2a 2a 20 74 68 65 20 53 65 6c 65 63 74 20 t.** the Select
66d0: 71 75 65 72 79 20 67 65 6e 65 72 61 74 6f 72 20 query generator
66e0: 74 72 61 63 69 6e 67 20 6c 6f 67 69 63 20 69 73 tracing logic is
66f0: 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 turned on..*/.#
6700: 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
6710: 45 5f 44 45 42 55 47 29 20 7c 7c 20 64 65 66 69 E_DEBUG) || defi
6720: 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c ned(SQLITE_ENABL
6730: 45 5f 53 45 4c 45 43 54 54 52 41 43 45 29 0a 23 E_SELECTTRACE).#
6740: 20 64 65 66 69 6e 65 20 53 45 4c 45 43 54 54 52 define SELECTTR
6750: 41 43 45 5f 45 4e 41 42 4c 45 44 20 31 0a 23 65 ACE_ENABLED 1.#e
6760: 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 45 4c lse.# define SEL
6770: 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 ECTTRACE_ENABLED
6780: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 0.#endif../*.**
6790: 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
67a0: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
67b0: 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 20 ructure is used
67c0: 74 6f 20 73 74 6f 72 65 20 74 68 65 20 62 75 73 to store the bus
67d0: 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c y-handler.** cal
67e0: 6c 62 61 63 6b 20 66 6f 72 20 61 20 67 69 76 65 lback for a give
67f0: 6e 20 73 71 6c 69 74 65 20 68 61 6e 64 6c 65 2e n sqlite handle.
6800: 20 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 71 6c 69 .**.** The sqli
6810: 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 72 20 6d te.busyHandler m
6820: 65 6d 62 65 72 20 6f 66 20 74 68 65 20 73 71 6c ember of the sql
6830: 69 74 65 20 73 74 72 75 63 74 20 63 6f 6e 74 61 ite struct conta
6840: 69 6e 73 20 74 68 65 20 62 75 73 79 0a 2a 2a 20 ins the busy.**
6850: 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 74 68 65 callback for the
6860: 20 64 61 74 61 62 61 73 65 20 68 61 6e 64 6c 65 database handle
6870: 2e 20 45 61 63 68 20 70 61 67 65 72 20 6f 70 65 . Each pager ope
6880: 6e 65 64 20 76 69 61 20 74 68 65 20 73 71 6c 69 ned via the sqli
6890: 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 69 73 20 te.** handle is
68a0: 70 61 73 73 65 64 20 61 20 70 6f 69 6e 74 65 72 passed a pointer
68b0: 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 73 79 48 to sqlite.busyH
68c0: 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 75 73 79 andler. The busy
68d0: 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c 6c -handler.** call
68e0: 62 61 63 6b 20 69 73 20 63 75 72 72 65 6e 74 6c back is currentl
68f0: 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c 79 20 66 y invoked only f
6900: 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 67 65 72 rom within pager
6910: 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 .c..*/.typedef s
6920: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
6930: 72 20 42 75 73 79 48 61 6e 64 6c 65 72 3b 0a 73 r BusyHandler;.s
6940: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
6950: 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 46 75 6e r {. int (*xFun
6960: 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 29 3b 20 c)(void *,int);
6970: 20 2f 2a 20 54 68 65 20 62 75 73 79 20 63 61 6c /* The busy cal
6980: 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 lback */. void
6990: 2a 70 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 *pArg;
69a0: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 /* First a
69b0: 72 67 20 74 6f 20 62 75 73 79 20 63 61 6c 6c 62 rg to busy callb
69c0: 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 42 75 ack */. int nBu
69d0: 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 sy;
69e0: 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d 65 6e 74 /* Increment
69f0: 65 64 20 77 69 74 68 20 65 61 63 68 20 62 75 73 ed with each bus
6a00: 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a 0a 2f 2a y call */.};../*
6a10: 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 .** Name of the
6a20: 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 master database
6a30: 74 61 62 6c 65 2e 20 20 54 68 65 20 6d 61 73 74 table. The mast
6a40: 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 6c er database tabl
6a50: 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 63 69 61 e.** is a specia
6a60: 6c 20 74 61 62 6c 65 20 74 68 61 74 20 68 6f 6c l table that hol
6a70: 64 73 20 74 68 65 20 6e 61 6d 65 73 20 61 6e 64 ds the names and
6a80: 20 61 74 74 72 69 62 75 74 65 73 20 6f 66 20 61 attributes of a
6a90: 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 62 6c 65 ll.** user table
6aa0: 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 0a 2a s and indices..*
6ab0: 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 /.#define MASTER
6ac0: 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 73 71 6c _NAME "sql
6ad0: 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 64 65 66 ite_master".#def
6ae0: 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 45 52 5f ine TEMP_MASTER_
6af0: 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 5f 74 65 NAME "sqlite_te
6b00: 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f 2a 0a 2a mp_master"../*.*
6b10: 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 67 65 20 * The root-page
6b20: 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 of the master da
6b30: 74 61 62 61 73 65 20 74 61 62 6c 65 2e 0a 2a 2f tabase table..*/
6b40: 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 5f .#define MASTER_
6b50: 52 4f 4f 54 20 20 20 20 20 20 20 31 0a 0a 2f 2a ROOT 1../*
6b60: 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 .** The name of
6b70: 74 68 65 20 73 63 68 65 6d 61 20 74 61 62 6c 65 the schema table
6b80: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 ..*/.#define SCH
6b90: 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 20 28 28 EMA_TABLE(x) ((
6ba0: 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 26 26 28 !OMIT_TEMPDB)&&(
6bb0: 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 53 54 45 x==1)?TEMP_MASTE
6bc0: 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 5f 4e 41 R_NAME:MASTER_NA
6bd0: 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 63 6f 6e ME)../*.** A con
6be0: 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 6f 20 74 venience macro t
6bf0: 68 61 74 20 72 65 74 75 72 6e 73 20 74 68 65 20 hat returns the
6c00: 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e number of elemen
6c10: 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 72 72 61 ts in.** an arra
6c20: 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 41 72 y..*/.#define Ar
6c30: 72 61 79 53 69 7a 65 28 58 29 20 20 20 20 28 28 raySize(X) ((
6c40: 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 29 2f 73 int)(sizeof(X)/s
6c50: 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 0a 0a 2f izeof(X[0])))../
6c60: 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 *.** Determine i
6c70: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 69 f the argument i
6c80: 73 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f s a power of two
6c90: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 6f .*/.#define IsPo
6ca0: 77 65 72 4f 66 54 77 6f 28 58 29 20 28 28 28 58 werOfTwo(X) (((X
6cb0: 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 29 0a 0a )&((X)-1))==0)..
6cc0: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
6cd0: 69 6e 67 20 76 61 6c 75 65 20 61 73 20 61 20 64 ing value as a d
6ce0: 65 73 74 72 75 63 74 6f 72 20 6d 65 61 6e 73 20 estructor means
6cf0: 74 6f 20 75 73 65 20 73 71 6c 69 74 65 33 44 62 to use sqlite3Db
6d00: 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 65 20 73 Free()..** The s
6d10: 71 6c 69 74 65 33 44 62 46 72 65 65 28 29 20 72 qlite3DbFree() r
6d20: 6f 75 74 69 6e 65 20 72 65 71 75 69 72 65 73 20 outine requires
6d30: 74 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 69 two parameters i
6d40: 6e 73 74 65 61 64 20 6f 66 20 74 68 65 20 0a 2a nstead of the .*
6d50: 2a 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 72 20 * one parameter
6d60: 74 68 61 74 20 64 65 73 74 72 75 63 74 6f 72 73 that destructors
6d70: 20 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 2e 20 normally want.
6d80: 20 53 6f 20 77 65 20 68 61 76 65 20 74 6f 20 69 So we have to i
6d90: 6e 74 72 6f 64 75 63 65 20 0a 2a 2a 20 74 68 69 ntroduce .** thi
6da0: 73 20 6d 61 67 69 63 20 76 61 6c 75 65 20 74 68 s magic value th
6db0: 61 74 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f 77 at the code know
6dc0: 73 20 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 66 s to handle diff
6dd0: 65 72 65 6e 74 6c 79 2e 20 20 41 6e 79 20 0a 2a erently. Any .*
6de0: 2a 20 70 6f 69 6e 74 65 72 20 77 69 6c 6c 20 77 * pointer will w
6df0: 6f 72 6b 20 68 65 72 65 20 61 73 20 6c 6f 6e 67 ork here as long
6e00: 20 61 73 20 69 74 20 69 73 20 64 69 73 74 69 6e as it is distin
6e10: 63 74 20 66 72 6f 6d 20 53 51 4c 49 54 45 5f 53 ct from SQLITE_S
6e20: 54 41 54 49 43 0a 2a 2a 20 61 6e 64 20 53 51 4c TATIC.** and SQL
6e30: 49 54 45 5f 54 52 41 4e 53 49 45 4e 54 2e 0a 2a ITE_TRANSIENT..*
6e40: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
6e50: 5f 44 59 4e 41 4d 49 43 20 20 20 28 28 73 71 6c _DYNAMIC ((sql
6e60: 69 74 65 33 5f 64 65 73 74 72 75 63 74 6f 72 5f ite3_destructor_
6e70: 74 79 70 65 29 73 71 6c 69 74 65 33 4d 61 6c 6c type)sqlite3Mall
6e80: 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 57 ocSize)../*.** W
6e90: 68 65 6e 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f hen SQLITE_OMIT_
6ea0: 57 53 44 20 69 73 20 64 65 66 69 6e 65 64 2c 20 WSD is defined,
6eb0: 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 it means that th
6ec0: 65 20 74 61 72 67 65 74 20 70 6c 61 74 66 6f 72 e target platfor
6ed0: 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 75 m does.** not su
6ee0: 70 70 6f 72 74 20 57 72 69 74 61 62 6c 65 20 53 pport Writable S
6ef0: 74 61 74 69 63 20 44 61 74 61 20 28 57 53 44 29 tatic Data (WSD)
6f00: 20 73 75 63 68 20 61 73 20 67 6c 6f 62 61 6c 20 such as global
6f10: 61 6e 64 20 73 74 61 74 69 63 20 76 61 72 69 61 and static varia
6f20: 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 72 bles..** All var
6f30: 69 61 62 6c 65 73 20 6d 75 73 74 20 65 69 74 68 iables must eith
6f40: 65 72 20 62 65 20 6f 6e 20 74 68 65 20 73 74 61 er be on the sta
6f50: 63 6b 20 6f 72 20 64 79 6e 61 6d 69 63 61 6c 6c ck or dynamicall
6f60: 79 20 61 6c 6c 6f 63 61 74 65 64 20 66 72 6f 6d y allocated from
6f70: 0a 2a 2a 20 74 68 65 20 68 65 61 70 2e 20 20 57 .** the heap. W
6f80: 68 65 6e 20 57 53 44 20 69 73 20 75 6e 73 75 70 hen WSD is unsup
6f90: 70 6f 72 74 65 64 2c 20 74 68 65 20 76 61 72 69 ported, the vari
6fa0: 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f 6e able declaration
6fb0: 73 20 73 63 61 74 74 65 72 65 64 0a 2a 2a 20 74 s scattered.** t
6fc0: 68 72 6f 75 67 68 6f 75 74 20 74 68 65 20 53 51 hroughout the SQ
6fd0: 4c 69 74 65 20 63 6f 64 65 20 6d 75 73 74 20 62 Lite code must b
6fe0: 65 63 6f 6d 65 20 63 6f 6e 73 74 61 6e 74 73 20 ecome constants
6ff0: 69 6e 73 74 65 61 64 2e 20 20 54 68 65 20 53 51 instead. The SQ
7000: 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 72 LITE_WSD.** macr
7010: 6f 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 68 o is used for th
7020: 69 73 20 70 75 72 70 6f 73 65 2e 20 20 41 6e 64 is purpose. And
7030: 20 69 6e 73 74 65 61 64 20 6f 66 20 72 65 66 65 instead of refe
7040: 72 65 6e 63 69 6e 67 20 74 68 65 20 76 61 72 69 rencing the vari
7050: 61 62 6c 65 0a 2a 2a 20 64 69 72 65 63 74 6c 79 able.** directly
7060: 2c 20 77 65 20 75 73 65 20 69 74 73 20 63 6f 6e , we use its con
7070: 73 74 61 6e 74 20 61 73 20 61 20 6b 65 79 20 74 stant as a key t
7080: 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 72 75 6e o lookup the run
7090: 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 74 65 64 0a -time allocated.
70a0: 2a 2a 20 62 75 66 66 65 72 20 74 68 61 74 20 68 ** buffer that h
70b0: 6f 6c 64 73 20 72 65 61 6c 20 76 61 72 69 61 62 olds real variab
70c0: 6c 65 2e 20 20 54 68 65 20 63 6f 6e 73 74 61 6e le. The constan
70d0: 74 20 69 73 20 61 6c 73 6f 20 74 68 65 20 69 6e t is also the in
70e0: 69 74 69 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f 72 itializer.** for
70f0: 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c the run-time al
7100: 6c 6f 63 61 74 65 64 20 62 75 66 66 65 72 2e 0a located buffer..
7110: 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 75 73 75 **.** In the usu
7120: 61 6c 20 63 61 73 65 20 77 68 65 72 65 20 57 53 al case where WS
7130: 44 20 69 73 20 73 75 70 70 6f 72 74 65 64 2c 20 D is supported,
7140: 74 68 65 20 53 51 4c 49 54 45 5f 57 53 44 20 61 the SQLITE_WSD a
7150: 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 63 nd GLOBAL.** mac
7160: 72 6f 73 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f 70 ros become no-op
7170: 73 20 61 6e 64 20 68 61 76 65 20 7a 65 72 6f 20 s and have zero
7180: 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 6d 70 61 performance impa
7190: 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 ct..*/.#ifdef SQ
71a0: 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 20 LITE_OMIT_WSD.
71b0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 #define SQLITE_W
71c0: 53 44 20 63 6f 6e 73 74 0a 20 20 23 64 65 66 69 SD const. #defi
71d0: 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 28 ne GLOBAL(t,v) (
71e0: 2a 28 74 2a 29 73 71 6c 69 74 65 33 5f 77 73 64 *(t*)sqlite3_wsd
71f0: 5f 66 69 6e 64 28 28 76 6f 69 64 2a 29 26 28 76 _find((void*)&(v
7200: 29 2c 20 73 69 7a 65 6f 66 28 76 29 29 29 0a 20 ), sizeof(v))).
7210: 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
7220: 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 47 4c 4f GlobalConfig GLO
7230: 42 41 4c 28 73 74 72 75 63 74 20 53 71 6c 69 74 BAL(struct Sqlit
7240: 65 33 43 6f 6e 66 69 67 2c 20 73 71 6c 69 74 65 e3Config, sqlite
7250: 33 43 6f 6e 66 69 67 29 0a 20 20 69 6e 74 20 73 3Config). int s
7260: 71 6c 69 74 65 33 5f 77 73 64 5f 69 6e 69 74 28 qlite3_wsd_init(
7270: 69 6e 74 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a 20 int N, int J);.
7280: 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 5f 77 void *sqlite3_w
7290: 73 64 5f 66 69 6e 64 28 76 6f 69 64 20 2a 4b 2c sd_find(void *K,
72a0: 20 69 6e 74 20 4c 29 3b 0a 23 65 6c 73 65 0a 20 int L);.#else.
72b0: 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f #define SQLITE_
72c0: 57 53 44 20 0a 20 20 23 64 65 66 69 6e 65 20 47 WSD . #define G
72d0: 4c 4f 42 41 4c 28 74 2c 76 29 20 76 0a 20 20 23 LOBAL(t,v) v. #
72e0: 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 6c define sqlite3Gl
72f0: 6f 62 61 6c 43 6f 6e 66 69 67 20 73 71 6c 69 74 obalConfig sqlit
7300: 65 33 43 6f 6e 66 69 67 0a 23 65 6e 64 69 66 0a e3Config.#endif.
7310: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
7320: 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 65 20 wing macros are
7330: 75 73 65 64 20 74 6f 20 73 75 70 70 72 65 73 73 used to suppress
7340: 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e 69 6e compiler warnin
7350: 67 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 6d 61 6b gs and to.** mak
7360: 65 20 69 74 20 63 6c 65 61 72 20 74 6f 20 68 75 e it clear to hu
7370: 6d 61 6e 20 72 65 61 64 65 72 73 20 77 68 65 6e man readers when
7380: 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 61 a function para
7390: 6d 65 74 65 72 20 69 73 20 64 65 6c 69 62 65 72 meter is deliber
73a0: 61 74 65 6c 79 20 0a 2a 2a 20 6c 65 66 74 20 75 ately .** left u
73b0: 6e 75 73 65 64 20 77 69 74 68 69 6e 20 74 68 65 nused within the
73c0: 20 62 6f 64 79 20 6f 66 20 61 20 66 75 6e 63 74 body of a funct
73d0: 69 6f 6e 2e 20 54 68 69 73 20 75 73 75 61 6c 6c ion. This usuall
73e0: 79 20 68 61 70 70 65 6e 73 20 77 68 65 6e 0a 2a y happens when.*
73f0: 2a 20 61 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 * a function is
7400: 63 61 6c 6c 65 64 20 76 69 61 20 61 20 66 75 6e called via a fun
7410: 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 2e 20 46 ction pointer. F
7420: 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 65 20 0a or example the .
7430: 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f ** implementatio
7440: 6e 20 6f 66 20 61 6e 20 53 51 4c 20 61 67 67 72 n of an SQL aggr
7450: 65 67 61 74 65 20 73 74 65 70 20 63 61 6c 6c 62 egate step callb
7460: 61 63 6b 20 6d 61 79 20 6e 6f 74 20 75 73 65 20 ack may not use
7470: 74 68 65 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 the.** parameter
7480: 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 65 20 indicating the
7490: 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 number of argume
74a0: 6e 74 73 20 70 61 73 73 65 64 20 74 6f 20 74 68 nts passed to th
74b0: 65 20 61 67 67 72 65 67 61 74 65 2c 0a 2a 2a 20 e aggregate,.**
74c0: 69 66 20 69 74 20 6b 6e 6f 77 73 20 74 68 61 74 if it knows that
74d0: 20 74 68 69 73 20 69 73 20 65 6e 66 6f 72 63 65 this is enforce
74e0: 64 20 65 6c 73 65 77 68 65 72 65 2e 0a 2a 2a 0a d elsewhere..**.
74f0: 2a 2a 20 57 68 65 6e 20 61 20 66 75 6e 63 74 69 ** When a functi
7500: 6f 6e 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 on parameter is
7510: 6e 6f 74 20 75 73 65 64 20 61 74 20 61 6c 6c 20 not used at all
7520: 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 20 within the body
7530: 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2c 0a 2a of a function,.*
7540: 2a 20 69 74 20 69 73 20 67 65 6e 65 72 61 6c 6c * it is generall
7550: 79 20 6e 61 6d 65 64 20 22 4e 6f 74 55 73 65 64 y named "NotUsed
7560: 22 20 6f 72 20 22 4e 6f 74 55 73 65 64 32 22 20 " or "NotUsed2"
7570: 74 6f 20 6d 61 6b 65 20 74 68 69 6e 67 73 20 65 to make things e
7580: 76 65 6e 20 63 6c 65 61 72 65 72 2e 0a 2a 2a 20 ven clearer..**
7590: 48 6f 77 65 76 65 72 2c 20 74 68 65 73 65 20 6d However, these m
75a0: 61 63 72 6f 73 20 6d 61 79 20 61 6c 73 6f 20 62 acros may also b
75b0: 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 65 e used to suppre
75c0: 73 73 20 77 61 72 6e 69 6e 67 73 20 72 65 6c 61 ss warnings rela
75d0: 74 65 64 20 74 6f 0a 2a 2a 20 70 61 72 61 6d 65 ted to.** parame
75e0: 74 65 72 73 20 74 68 61 74 20 6d 61 79 20 6f 72 ters that may or
75f0: 20 6d 61 79 20 6e 6f 74 20 62 65 20 75 73 65 64 may not be used
7600: 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 63 6f depending on co
7610: 6d 70 69 6c 61 74 69 6f 6e 20 6f 70 74 69 6f 6e mpilation option
7620: 73 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c s..** For exampl
7630: 65 20 74 68 6f 73 65 20 70 61 72 61 6d 65 74 65 e those paramete
7640: 72 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 rs only used in
7650: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
7660: 6e 74 73 2e 20 49 6e 20 74 68 65 73 65 0a 2a 2a nts. In these.**
7670: 20 63 61 73 65 73 20 74 68 65 20 70 61 72 61 6d cases the param
7680: 65 74 65 72 73 20 61 72 65 20 6e 61 6d 65 64 20 eters are named
7690: 61 73 20 70 65 72 20 74 68 65 20 75 73 75 61 6c as per the usual
76a0: 20 63 6f 6e 76 65 6e 74 69 6f 6e 73 2e 0a 2a 2f conventions..*/
76b0: 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 5f .#define UNUSED_
76c0: 50 41 52 41 4d 45 54 45 52 28 78 29 20 28 76 6f PARAMETER(x) (vo
76d0: 69 64 29 28 78 29 0a 23 64 65 66 69 6e 65 20 55 id)(x).#define U
76e0: 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 32 NUSED_PARAMETER2
76f0: 28 78 2c 79 29 20 55 4e 55 53 45 44 5f 50 41 52 (x,y) UNUSED_PAR
7700: 41 4d 45 54 45 52 28 78 29 2c 55 4e 55 53 45 44 AMETER(x),UNUSED
7710: 5f 50 41 52 41 4d 45 54 45 52 28 79 29 0a 0a 2f _PARAMETER(y)../
7720: 2a 0a 2a 2a 20 46 6f 72 77 61 72 64 20 72 65 66 *.** Forward ref
7730: 65 72 65 6e 63 65 73 20 74 6f 20 73 74 72 75 63 erences to struc
7740: 74 75 72 65 73 0a 2a 2f 0a 74 79 70 65 64 65 66 tures.*/.typedef
7750: 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 20 struct AggInfo
7760: 41 67 67 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 AggInfo;.typedef
7770: 20 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e 74 struct AuthCont
7780: 65 78 74 20 41 75 74 68 43 6f 6e 74 65 78 74 3b ext AuthContext;
7790: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
77a0: 41 75 74 6f 69 6e 63 49 6e 66 6f 20 41 75 74 6f AutoincInfo Auto
77b0: 69 6e 63 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 incInfo;.typedef
77c0: 20 73 74 72 75 63 74 20 42 69 74 76 65 63 20 42 struct Bitvec B
77d0: 69 74 76 65 63 3b 0a 74 79 70 65 64 65 66 20 73 itvec;.typedef s
77e0: 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 43 6f truct CollSeq Co
77f0: 6c 6c 53 65 71 3b 0a 74 79 70 65 64 65 66 20 73 llSeq;.typedef s
7800: 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 43 6f 6c truct Column Col
7810: 75 6d 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 72 umn;.typedef str
7820: 75 63 74 20 44 62 20 44 62 3b 0a 74 79 70 65 64 uct Db Db;.typed
7830: 65 66 20 73 74 72 75 63 74 20 53 63 68 65 6d 61 ef struct Schema
7840: 20 53 63 68 65 6d 61 3b 0a 74 79 70 65 64 65 66 Schema;.typedef
7850: 20 73 74 72 75 63 74 20 45 78 70 72 20 45 78 70 struct Expr Exp
7860: 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 r;.typedef struc
7870: 74 20 45 78 70 72 4c 69 73 74 20 45 78 70 72 4c t ExprList ExprL
7880: 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ist;.typedef str
7890: 75 63 74 20 45 78 70 72 53 70 61 6e 20 45 78 70 uct ExprSpan Exp
78a0: 72 53 70 61 6e 3b 0a 74 79 70 65 64 65 66 20 73 rSpan;.typedef s
78b0: 74 72 75 63 74 20 46 4b 65 79 20 46 4b 65 79 3b truct FKey FKey;
78c0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
78d0: 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 46 FuncDestructor F
78e0: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 3b 0a 74 uncDestructor;.t
78f0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 ypedef struct Fu
7900: 6e 63 44 65 66 20 46 75 6e 63 44 65 66 3b 0a 74 ncDef FuncDef;.t
7910: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 ypedef struct Fu
7920: 6e 63 44 65 66 48 61 73 68 20 46 75 6e 63 44 65 ncDefHash FuncDe
7930: 66 48 61 73 68 3b 0a 74 79 70 65 64 65 66 20 73 fHash;.typedef s
7940: 74 72 75 63 74 20 49 64 4c 69 73 74 20 49 64 4c truct IdList IdL
7950: 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ist;.typedef str
7960: 75 63 74 20 49 6e 64 65 78 20 49 6e 64 65 78 3b uct Index Index;
7970: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
7980: 49 6e 64 65 78 53 61 6d 70 6c 65 20 49 6e 64 65 IndexSample Inde
7990: 78 53 61 6d 70 6c 65 3b 0a 74 79 70 65 64 65 66 xSample;.typedef
79a0: 20 73 74 72 75 63 74 20 4b 65 79 43 6c 61 73 73 struct KeyClass
79b0: 20 4b 65 79 43 6c 61 73 73 3b 0a 74 79 70 65 64 KeyClass;.typed
79c0: 65 66 20 73 74 72 75 63 74 20 4b 65 79 49 6e 66 ef struct KeyInf
79d0: 6f 20 4b 65 79 49 6e 66 6f 3b 0a 74 79 70 65 64 o KeyInfo;.typed
79e0: 65 66 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 ef struct Lookas
79f0: 69 64 65 20 4c 6f 6f 6b 61 73 69 64 65 3b 0a 74 ide Lookaside;.t
7a00: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4c 6f ypedef struct Lo
7a10: 6f 6b 61 73 69 64 65 53 6c 6f 74 20 4c 6f 6f 6b okasideSlot Look
7a20: 61 73 69 64 65 53 6c 6f 74 3b 0a 74 79 70 65 64 asideSlot;.typed
7a30: 65 66 20 73 74 72 75 63 74 20 4d 6f 64 75 6c 65 ef struct Module
7a40: 20 4d 6f 64 75 6c 65 3b 0a 74 79 70 65 64 65 66 Module;.typedef
7a50: 20 73 74 72 75 63 74 20 4e 61 6d 65 43 6f 6e 74 struct NameCont
7a60: 65 78 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 3b ext NameContext;
7a70: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
7a80: 50 61 72 73 65 20 50 61 72 73 65 3b 0a 74 79 70 Parse Parse;.typ
7a90: 65 64 65 66 20 73 74 72 75 63 74 20 50 72 69 6e edef struct Prin
7aa0: 74 66 41 72 67 75 6d 65 6e 74 73 20 50 72 69 6e tfArguments Prin
7ab0: 74 66 41 72 67 75 6d 65 6e 74 73 3b 0a 74 79 70 tfArguments;.typ
7ac0: 65 64 65 66 20 73 74 72 75 63 74 20 52 6f 77 53 edef struct RowS
7ad0: 65 74 20 52 6f 77 53 65 74 3b 0a 74 79 70 65 64 et RowSet;.typed
7ae0: 65 66 20 73 74 72 75 63 74 20 53 61 76 65 70 6f ef struct Savepo
7af0: 69 6e 74 20 53 61 76 65 70 6f 69 6e 74 3b 0a 74 int Savepoint;.t
7b00: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 65 ypedef struct Se
7b10: 6c 65 63 74 20 53 65 6c 65 63 74 3b 0a 74 79 70 lect Select;.typ
7b20: 65 64 65 66 20 73 74 72 75 63 74 20 53 51 4c 69 edef struct SQLi
7b30: 74 65 54 68 72 65 61 64 20 53 51 4c 69 74 65 54 teThread SQLiteT
7b40: 68 72 65 61 64 3b 0a 74 79 70 65 64 65 66 20 73 hread;.typedef s
7b50: 74 72 75 63 74 20 53 65 6c 65 63 74 44 65 73 74 truct SelectDest
7b60: 20 53 65 6c 65 63 74 44 65 73 74 3b 0a 74 79 70 SelectDest;.typ
7b70: 65 64 65 66 20 73 74 72 75 63 74 20 53 72 63 4c edef struct SrcL
7b80: 69 73 74 20 53 72 63 4c 69 73 74 3b 0a 74 79 70 ist SrcList;.typ
7b90: 65 64 65 66 20 73 74 72 75 63 74 20 53 74 72 41 edef struct StrA
7ba0: 63 63 75 6d 20 53 74 72 41 63 63 75 6d 3b 0a 74 ccum StrAccum;.t
7bb0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 61 ypedef struct Ta
7bc0: 62 6c 65 20 54 61 62 6c 65 3b 0a 74 79 70 65 64 ble Table;.typed
7bd0: 65 66 20 73 74 72 75 63 74 20 54 61 62 6c 65 4c ef struct TableL
7be0: 6f 63 6b 20 54 61 62 6c 65 4c 6f 63 6b 3b 0a 74 ock TableLock;.t
7bf0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 6f ypedef struct To
7c00: 6b 65 6e 20 54 6f 6b 65 6e 3b 0a 74 79 70 65 64 ken Token;.typed
7c10: 65 66 20 73 74 72 75 63 74 20 54 72 65 65 56 69 ef struct TreeVi
7c20: 65 77 20 54 72 65 65 56 69 65 77 3b 0a 74 79 70 ew TreeView;.typ
7c30: 65 64 65 66 20 73 74 72 75 63 74 20 54 72 69 67 edef struct Trig
7c40: 67 65 72 20 54 72 69 67 67 65 72 3b 0a 74 79 70 ger Trigger;.typ
7c50: 65 64 65 66 20 73 74 72 75 63 74 20 54 72 69 67 edef struct Trig
7c60: 67 65 72 50 72 67 20 54 72 69 67 67 65 72 50 72 gerPrg TriggerPr
7c70: 67 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 g;.typedef struc
7c80: 74 20 54 72 69 67 67 65 72 53 74 65 70 20 54 72 t TriggerStep Tr
7c90: 69 67 67 65 72 53 74 65 70 3b 0a 74 79 70 65 64 iggerStep;.typed
7ca0: 65 66 20 73 74 72 75 63 74 20 55 6e 70 61 63 6b ef struct Unpack
7cb0: 65 64 52 65 63 6f 72 64 20 55 6e 70 61 63 6b 65 edRecord Unpacke
7cc0: 64 52 65 63 6f 72 64 3b 0a 74 79 70 65 64 65 66 dRecord;.typedef
7cd0: 20 73 74 72 75 63 74 20 56 54 61 62 6c 65 20 56 struct VTable V
7ce0: 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 Table;.typedef s
7cf0: 74 72 75 63 74 20 56 74 61 62 43 74 78 20 56 74 truct VtabCtx Vt
7d00: 61 62 43 74 78 3b 0a 74 79 70 65 64 65 66 20 73 abCtx;.typedef s
7d10: 74 72 75 63 74 20 57 61 6c 6b 65 72 20 57 61 6c truct Walker Wal
7d20: 6b 65 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ker;.typedef str
7d30: 75 63 74 20 57 68 65 72 65 49 6e 66 6f 20 57 68 uct WhereInfo Wh
7d40: 65 72 65 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 ereInfo;.typedef
7d50: 20 73 74 72 75 63 74 20 57 69 74 68 20 57 69 74 struct With Wit
7d60: 68 3b 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 65 72 20 h;../*.** Defer
7d70: 73 6f 75 72 63 69 6e 67 20 76 64 62 65 2e 68 20 sourcing vdbe.h
7d80: 61 6e 64 20 62 74 72 65 65 2e 68 20 75 6e 74 69 and btree.h unti
7d90: 6c 20 61 66 74 65 72 20 74 68 65 20 22 75 38 22 l after the "u8"
7da0: 20 61 6e 64 20 0a 2a 2a 20 22 42 75 73 79 48 61 and .** "BusyHa
7db0: 6e 64 6c 65 72 22 20 74 79 70 65 64 65 66 73 2e ndler" typedefs.
7dc0: 20 76 64 62 65 2e 68 20 61 6c 73 6f 20 72 65 71 vdbe.h also req
7dd0: 75 69 72 65 73 20 61 20 66 65 77 20 6f 66 20 74 uires a few of t
7de0: 68 65 20 6f 70 61 71 75 65 0a 2a 2a 20 70 6f 69 he opaque.** poi
7df0: 6e 74 65 72 20 74 79 70 65 73 20 28 69 2e 65 2e nter types (i.e.
7e00: 20 46 75 6e 63 44 65 66 29 20 64 65 66 69 6e 65 FuncDef) define
7e10: 64 20 61 62 6f 76 65 2e 0a 2a 2f 0a 23 69 6e 63 d above..*/.#inc
7e20: 6c 75 64 65 20 22 62 74 72 65 65 2e 68 22 0a 23 lude "btree.h".#
7e30: 69 6e 63 6c 75 64 65 20 22 76 64 62 65 2e 68 22 include "vdbe.h"
7e40: 0a 23 69 6e 63 6c 75 64 65 20 22 70 61 67 65 72 .#include "pager
7e50: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 63 .h".#include "pc
7e60: 61 63 68 65 2e 68 22 0a 0a 23 69 6e 63 6c 75 64 ache.h"..#includ
7e70: 65 20 22 6f 73 2e 68 22 0a 23 69 6e 63 6c 75 64 e "os.h".#includ
7e80: 65 20 22 6d 75 74 65 78 2e 68 22 0a 0a 0a 2f 2a e "mutex.h".../*
7e90: 0a 2a 2a 20 45 61 63 68 20 64 61 74 61 62 61 73 .** Each databas
7ea0: 65 20 66 69 6c 65 20 74 6f 20 62 65 20 61 63 63 e file to be acc
7eb0: 65 73 73 65 64 20 62 79 20 74 68 65 20 73 79 73 essed by the sys
7ec0: 74 65 6d 20 69 73 20 61 6e 20 69 6e 73 74 61 6e tem is an instan
7ed0: 63 65 0a 2a 2a 20 6f 66 20 74 68 65 20 66 6f 6c ce.** of the fol
7ee0: 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
7ef0: 2e 20 20 54 68 65 72 65 20 61 72 65 20 6e 6f 72 . There are nor
7f00: 6d 61 6c 6c 79 20 74 77 6f 20 6f 66 20 74 68 65 mally two of the
7f10: 73 65 20 73 74 72 75 63 74 75 72 65 73 0a 2a 2a se structures.**
7f20: 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 in the sqlite.a
7f30: 44 62 5b 5d 20 61 72 72 61 79 2e 20 20 61 44 62 Db[] array. aDb
7f40: 5b 30 5d 20 69 73 20 74 68 65 20 6d 61 69 6e 20 [0] is the main
7f50: 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 61 6e database file an
7f60: 64 0a 2a 2a 20 61 44 62 5b 31 5d 20 69 73 20 74 d.** aDb[1] is t
7f70: 68 65 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 he database file
7f80: 20 75 73 65 64 20 74 6f 20 68 6f 6c 64 20 74 65 used to hold te
7f90: 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 73 2e 20 mporary tables.
7fa0: 20 41 64 64 69 74 69 6f 6e 61 6c 0a 2a 2a 20 64 Additional.** d
7fb0: 61 74 61 62 61 73 65 73 20 6d 61 79 20 62 65 20 atabases may be
7fc0: 61 74 74 61 63 68 65 64 2e 0a 2a 2f 0a 73 74 72 attached..*/.str
7fd0: 75 63 74 20 44 62 20 7b 0a 20 20 63 68 61 72 20 uct Db {. char
7fe0: 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
7ff0: 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 /* Name of this
8000: 64 61 74 61 62 61 73 65 20 2a 2f 0a 20 20 42 74 database */. Bt
8010: 72 65 65 20 2a 70 42 74 3b 20 20 20 20 20 20 20 ree *pBt;
8020: 20 20 20 2f 2a 20 54 68 65 20 42 2a 54 72 65 65 /* The B*Tree
8030: 20 73 74 72 75 63 74 75 72 65 20 66 6f 72 20 74 structure for t
8040: 68 69 73 20 64 61 74 61 62 61 73 65 20 66 69 6c his database fil
8050: 65 20 2a 2f 0a 20 20 75 38 20 73 61 66 65 74 79 e */. u8 safety
8060: 5f 6c 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 48 _level; /* H
8070: 6f 77 20 61 67 67 72 65 73 73 69 76 65 20 61 74 ow aggressive at
8080: 20 73 79 6e 63 69 6e 67 20 64 61 74 61 20 74 6f syncing data to
8090: 20 64 69 73 6b 20 2a 2f 0a 20 20 53 63 68 65 6d disk */. Schem
80a0: 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 20 a *pSchema;
80b0: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 64 61 /* Pointer to da
80c0: 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 28 70 tabase schema (p
80d0: 6f 73 73 69 62 6c 79 20 73 68 61 72 65 64 29 20 ossibly shared)
80e0: 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 */.};../*.** An
80f0: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
8100: 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
8110: 75 72 65 20 73 74 6f 72 65 73 20 61 20 64 61 74 ure stores a dat
8120: 61 62 61 73 65 20 73 63 68 65 6d 61 2e 0a 2a 2a abase schema..**
8130: 0a 2a 2a 20 4d 6f 73 74 20 53 63 68 65 6d 61 20 .** Most Schema
8140: 6f 62 6a 65 63 74 73 20 61 72 65 20 61 73 73 6f objects are asso
8150: 63 69 61 74 65 64 20 77 69 74 68 20 61 20 42 74 ciated with a Bt
8160: 72 65 65 2e 20 20 54 68 65 20 65 78 63 65 70 74 ree. The except
8170: 69 6f 6e 20 69 73 0a 2a 2a 20 74 68 65 20 53 63 ion is.** the Sc
8180: 68 65 6d 61 20 66 6f 72 20 74 68 65 20 54 45 4d hema for the TEM
8190: 50 20 64 61 74 61 62 61 65 73 20 28 73 71 6c 69 P databaes (sqli
81a0: 74 65 33 2e 61 44 62 5b 31 5d 29 20 77 68 69 63 te3.aDb[1]) whic
81b0: 68 20 69 73 20 66 72 65 65 2d 73 74 61 6e 64 69 h is free-standi
81c0: 6e 67 2e 0a 2a 2a 20 49 6e 20 73 68 61 72 65 64 ng..** In shared
81d0: 20 63 61 63 68 65 20 6d 6f 64 65 2c 20 61 20 73 cache mode, a s
81e0: 69 6e 67 6c 65 20 53 63 68 65 6d 61 20 6f 62 6a ingle Schema obj
81f0: 65 63 74 20 63 61 6e 20 62 65 20 73 68 61 72 65 ect can be share
8200: 64 20 62 79 20 6d 75 6c 74 69 70 6c 65 0a 2a 2a d by multiple.**
8210: 20 42 74 72 65 65 73 20 74 68 61 74 20 72 65 66 Btrees that ref
8220: 65 72 20 74 6f 20 74 68 65 20 73 61 6d 65 20 75 er to the same u
8230: 6e 64 65 72 6c 79 69 6e 67 20 42 74 53 68 61 72 nderlying BtShar
8240: 65 64 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 0a 2a ed object..** .*
8250: 2a 20 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 * Schema objects
8260: 20 61 72 65 20 61 75 74 6f 6d 61 74 69 63 61 6c are automatical
8270: 6c 79 20 64 65 61 6c 6c 6f 63 61 74 65 64 20 77 ly deallocated w
8280: 68 65 6e 20 74 68 65 20 6c 61 73 74 20 42 74 72 hen the last Btr
8290: 65 65 20 74 68 61 74 0a 2a 2a 20 72 65 66 65 72 ee that.** refer
82a0: 65 6e 63 65 73 20 74 68 65 6d 20 69 73 20 64 65 ences them is de
82b0: 73 74 72 6f 79 65 64 2e 20 20 20 54 68 65 20 54 stroyed. The T
82c0: 45 4d 50 20 53 63 68 65 6d 61 20 69 73 20 6d 61 EMP Schema is ma
82d0: 6e 75 61 6c 6c 79 20 66 72 65 65 64 20 62 79 0a nually freed by.
82e0: 2a 2a 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 ** sqlite3_close
82f0: 28 29 2e 0a 2a 0a 2a 2a 20 41 20 74 68 72 65 61 ()..*.** A threa
8300: 64 20 6d 75 73 74 20 62 65 20 68 6f 6c 64 69 6e d must be holdin
8310: 67 20 61 20 6d 75 74 65 78 20 6f 6e 20 74 68 65 g a mutex on the
8320: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 42 corresponding B
8330: 74 72 65 65 20 69 6e 20 6f 72 64 65 72 0a 2a 2a tree in order.**
8340: 20 74 6f 20 61 63 63 65 73 73 20 53 63 68 65 6d to access Schem
8350: 61 20 63 6f 6e 74 65 6e 74 2e 20 20 54 68 69 73 a content. This
8360: 20 69 6d 70 6c 69 65 73 20 74 68 61 74 20 74 68 implies that th
8370: 65 20 74 68 72 65 61 64 20 6d 75 73 74 20 61 6c e thread must al
8380: 73 6f 20 62 65 0a 2a 2a 20 68 6f 6c 64 69 6e 67 so be.** holding
8390: 20 61 20 6d 75 74 65 78 20 6f 6e 20 74 68 65 20 a mutex on the
83a0: 73 71 6c 69 74 65 33 20 63 6f 6e 6e 65 63 74 69 sqlite3 connecti
83b0: 6f 6e 20 70 6f 69 6e 74 65 72 20 74 68 61 74 20 on pointer that
83c0: 6f 77 6e 73 20 74 68 65 20 42 74 72 65 65 2e 0a owns the Btree..
83d0: 2a 2a 20 46 6f 72 20 61 20 54 45 4d 50 20 53 63 ** For a TEMP Sc
83e0: 68 65 6d 61 2c 20 6f 6e 6c 79 20 74 68 65 20 63 hema, only the c
83f0: 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 65 78 20 onnection mutex
8400: 69 73 20 72 65 71 75 69 72 65 64 2e 0a 2a 2f 0a is required..*/.
8410: 73 74 72 75 63 74 20 53 63 68 65 6d 61 20 7b 0a struct Schema {.
8420: 20 20 69 6e 74 20 73 63 68 65 6d 61 5f 63 6f 6f int schema_coo
8430: 6b 69 65 3b 20 20 20 2f 2a 20 44 61 74 61 62 61 kie; /* Databa
8440: 73 65 20 73 63 68 65 6d 61 20 76 65 72 73 69 6f se schema versio
8450: 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 69 n number for thi
8460: 73 20 66 69 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 s file */. int
8470: 69 47 65 6e 65 72 61 74 69 6f 6e 3b 20 20 20 20 iGeneration;
8480: 20 2f 2a 20 47 65 6e 65 72 61 74 69 6f 6e 20 63 /* Generation c
8490: 6f 75 6e 74 65 72 2e 20 20 49 6e 63 72 65 6d 65 ounter. Increme
84a0: 6e 74 65 64 20 77 69 74 68 20 65 61 63 68 20 63 nted with each c
84b0: 68 61 6e 67 65 20 2a 2f 0a 20 20 48 61 73 68 20 hange */. Hash
84c0: 74 62 6c 48 61 73 68 3b 20 20 20 20 20 20 20 20 tblHash;
84d0: 2f 2a 20 41 6c 6c 20 74 61 62 6c 65 73 20 69 6e /* All tables in
84e0: 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a 2f dexed by name */
84f0: 0a 20 20 48 61 73 68 20 69 64 78 48 61 73 68 3b . Hash idxHash;
8500: 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 28 /* All (
8510: 6e 61 6d 65 64 29 20 69 6e 64 69 63 65 73 20 69 named) indices i
8520: 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a ndexed by name *
8530: 2f 0a 20 20 48 61 73 68 20 74 72 69 67 48 61 73 /. Hash trigHas
8540: 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 h; /* All
8550: 74 72 69 67 67 65 72 73 20 69 6e 64 65 78 65 64 triggers indexed
8560: 20 62 79 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 by name */. Ha
8570: 73 68 20 66 6b 65 79 48 61 73 68 3b 20 20 20 20 sh fkeyHash;
8580: 20 20 20 2f 2a 20 41 6c 6c 20 66 6f 72 65 69 67 /* All foreig
8590: 6e 20 6b 65 79 73 20 62 79 20 72 65 66 65 72 65 n keys by refere
85a0: 6e 63 65 64 20 74 61 62 6c 65 20 6e 61 6d 65 20 nced table name
85b0: 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 53 65 71 */. Table *pSeq
85c0: 54 61 62 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 Tab; /* The
85d0: 20 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65 sqlite_sequence
85e0: 20 74 61 62 6c 65 20 75 73 65 64 20 62 79 20 41 table used by A
85f0: 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 2a 2f 0a UTOINCREMENT */.
8600: 20 20 75 38 20 66 69 6c 65 5f 66 6f 72 6d 61 74 u8 file_format
8610: 3b 20 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 ; /* Schema
8620: 20 66 6f 72 6d 61 74 20 76 65 72 73 69 6f 6e 20 format version
8630: 66 6f 72 20 74 68 69 73 20 66 69 6c 65 20 2a 2f for this file */
8640: 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 . u8 enc;
8650: 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 /* Text
8660: 65 6e 63 6f 64 69 6e 67 20 75 73 65 64 20 62 79 encoding used by
8670: 20 74 68 69 73 20 64 61 74 61 62 61 73 65 20 2a this database *
8680: 2f 0a 20 20 75 31 36 20 73 63 68 65 6d 61 46 6c /. u16 schemaFl
8690: 61 67 73 3b 20 20 20 20 20 2f 2a 20 46 6c 61 67 ags; /* Flag
86a0: 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 s associated wit
86b0: 68 20 74 68 69 73 20 73 63 68 65 6d 61 20 2a 2f h this schema */
86c0: 0a 20 20 69 6e 74 20 63 61 63 68 65 5f 73 69 7a . int cache_siz
86d0: 65 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 e; /* Numbe
86e0: 72 20 6f 66 20 70 61 67 65 73 20 74 6f 20 75 73 r of pages to us
86f0: 65 20 69 6e 20 74 68 65 20 63 61 63 68 65 20 2a e in the cache *
8700: 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 /.};../*.** Thes
8710: 65 20 6d 61 63 72 6f 73 20 63 61 6e 20 62 65 20 e macros can be
8720: 75 73 65 64 20 74 6f 20 74 65 73 74 2c 20 73 65 used to test, se
8730: 74 2c 20 6f 72 20 63 6c 65 61 72 20 62 69 74 73 t, or clear bits
8740: 20 69 6e 20 74 68 65 20 0a 2a 2a 20 44 62 2e 70 in the .** Db.p
8750: 53 63 68 65 6d 61 2d 3e 66 6c 61 67 73 20 66 69 Schema->flags fi
8760: 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 eld..*/.#define
8770: 44 62 48 61 73 50 72 6f 70 65 72 74 79 28 44 2c DbHasProperty(D,
8780: 49 2c 50 29 20 20 20 20 20 28 28 28 44 29 2d 3e I,P) (((D)->
8790: 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e aDb[I].pSchema->
87a0: 73 63 68 65 6d 61 46 6c 61 67 73 26 28 50 29 29 schemaFlags&(P))
87b0: 3d 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 20 44 ==(P)).#define D
87c0: 62 48 61 73 41 6e 79 50 72 6f 70 65 72 74 79 28 bHasAnyProperty(
87d0: 44 2c 49 2c 50 29 20 20 28 28 28 44 29 2d 3e 61 D,I,P) (((D)->a
87e0: 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 Db[I].pSchema->s
87f0: 63 68 65 6d 61 46 6c 61 67 73 26 28 50 29 29 21 chemaFlags&(P))!
8800: 3d 30 29 0a 23 64 65 66 69 6e 65 20 44 62 53 65 =0).#define DbSe
8810: 74 50 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 tProperty(D,I,P)
8820: 20 20 20 20 20 28 44 29 2d 3e 61 44 62 5b 49 5d (D)->aDb[I]
8830: 2e 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 .pSchema->schema
8840: 46 6c 61 67 73 7c 3d 28 50 29 0a 23 64 65 66 69 Flags|=(P).#defi
8850: 6e 65 20 44 62 43 6c 65 61 72 50 72 6f 70 65 72 ne DbClearProper
8860: 74 79 28 44 2c 49 2c 50 29 20 20 20 28 44 29 2d ty(D,I,P) (D)-
8870: 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d >aDb[I].pSchema-
8880: 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 3d 7e 28 >schemaFlags&=~(
8890: 50 29 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 P)../*.** Allowe
88a0: 64 20 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 d values for the
88b0: 20 44 42 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 DB.pSchema->fla
88c0: 67 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 gs field..**.**
88d0: 54 68 65 20 44 42 5f 53 63 68 65 6d 61 4c 6f 61 The DB_SchemaLoa
88e0: 64 65 64 20 66 6c 61 67 20 69 73 20 73 65 74 20 ded flag is set
88f0: 61 66 74 65 72 20 74 68 65 20 64 61 74 61 62 61 after the databa
8900: 73 65 20 73 63 68 65 6d 61 20 68 61 73 20 62 65 se schema has be
8910: 65 6e 0a 2a 2a 20 72 65 61 64 20 69 6e 74 6f 20 en.** read into
8920: 69 6e 74 65 72 6e 61 6c 20 68 61 73 68 20 74 61 internal hash ta
8930: 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 44 42 5f 55 bles..**.** DB_U
8940: 6e 72 65 73 65 74 56 69 65 77 73 20 6d 65 61 6e nresetViews mean
8950: 73 20 74 68 61 74 20 6f 6e 65 20 6f 72 20 6d 6f s that one or mo
8960: 72 65 20 76 69 65 77 73 20 68 61 76 65 20 63 6f re views have co
8970: 6c 75 6d 6e 20 6e 61 6d 65 73 20 74 68 61 74 0a lumn names that.
8980: 2a 2a 20 68 61 76 65 20 62 65 65 6e 20 66 69 6c ** have been fil
8990: 6c 65 64 20 6f 75 74 2e 20 20 49 66 20 74 68 65 led out. If the
89a0: 20 73 63 68 65 6d 61 20 63 68 61 6e 67 65 73 2c schema changes,
89b0: 20 74 68 65 73 65 20 63 6f 6c 75 6d 6e 20 6e 61 these column na
89c0: 6d 65 73 20 6d 69 67 68 74 0a 2a 2a 20 63 68 61 mes might.** cha
89d0: 6e 67 65 73 20 61 6e 64 20 73 6f 20 74 68 65 20 nges and so the
89e0: 76 69 65 77 20 77 69 6c 6c 20 6e 65 65 64 20 74 view will need t
89f0: 6f 20 62 65 20 72 65 73 65 74 2e 0a 2a 2f 0a 23 o be reset..*/.#
8a00: 64 65 66 69 6e 65 20 44 42 5f 53 63 68 65 6d 61 define DB_Schema
8a10: 4c 6f 61 64 65 64 20 20 20 20 30 78 30 30 30 31 Loaded 0x0001
8a20: 20 20 2f 2a 20 54 68 65 20 73 63 68 65 6d 61 20 /* The schema
8a30: 68 61 73 20 62 65 65 6e 20 6c 6f 61 64 65 64 20 has been loaded
8a40: 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 55 6e */.#define DB_Un
8a50: 72 65 73 65 74 56 69 65 77 73 20 20 20 20 30 78 resetViews 0x
8a60: 30 30 30 32 20 20 2f 2a 20 53 6f 6d 65 20 76 69 0002 /* Some vi
8a70: 65 77 73 20 68 61 76 65 20 64 65 66 69 6e 65 64 ews have defined
8a80: 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 2a 2f column names */
8a90: 0a 23 64 65 66 69 6e 65 20 44 42 5f 45 6d 70 74 .#define DB_Empt
8aa0: 79 20 20 20 20 20 20 20 20 20 20 20 30 78 30 30 y 0x00
8ab0: 30 34 20 20 2f 2a 20 54 68 65 20 66 69 6c 65 20 04 /* The file
8ac0: 69 73 20 65 6d 70 74 79 20 28 6c 65 6e 67 74 68 is empty (length
8ad0: 20 30 20 62 79 74 65 73 29 20 2a 2f 0a 0a 2f 2a 0 bytes) */../*
8ae0: 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 20 6f .** The number o
8af0: 66 20 64 69 66 66 65 72 65 6e 74 20 6b 69 6e 64 f different kind
8b00: 73 20 6f 66 20 74 68 69 6e 67 73 20 74 68 61 74 s of things that
8b10: 20 63 61 6e 20 62 65 20 6c 69 6d 69 74 65 64 0a can be limited.
8b20: 2a 2a 20 75 73 69 6e 67 20 74 68 65 20 73 71 6c ** using the sql
8b30: 69 74 65 33 5f 6c 69 6d 69 74 28 29 20 69 6e 74 ite3_limit() int
8b40: 65 72 66 61 63 65 2e 0a 2a 2f 0a 23 64 65 66 69 erface..*/.#defi
8b50: 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 ne SQLITE_N_LIMI
8b60: 54 20 28 53 51 4c 49 54 45 5f 4c 49 4d 49 54 5f T (SQLITE_LIMIT_
8b70: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 2b 31 WORKER_THREADS+1
8b80: 29 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 )../*.** Lookasi
8b90: 64 65 20 6d 61 6c 6c 6f 63 20 69 73 20 61 20 73 de malloc is a s
8ba0: 65 74 20 6f 66 20 66 69 78 65 64 2d 73 69 7a 65 et of fixed-size
8bb0: 20 62 75 66 66 65 72 73 20 74 68 61 74 20 63 61 buffers that ca
8bc0: 6e 20 62 65 20 75 73 65 64 0a 2a 2a 20 74 6f 20 n be used.** to
8bd0: 73 61 74 69 73 66 79 20 73 6d 61 6c 6c 20 74 72 satisfy small tr
8be0: 61 6e 73 69 65 6e 74 20 6d 65 6d 6f 72 79 20 61 ansient memory a
8bf0: 6c 6c 6f 63 61 74 69 6f 6e 20 72 65 71 75 65 73 llocation reques
8c00: 74 73 20 66 6f 72 20 6f 62 6a 65 63 74 73 0a 2a ts for objects.*
8c10: 2a 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 * associated wit
8c20: 68 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 64 h a particular d
8c30: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
8c40: 6f 6e 2e 20 20 54 68 65 20 75 73 65 20 6f 66 0a on. The use of.
8c50: 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c ** lookaside mal
8c60: 6c 6f 63 20 70 72 6f 76 69 64 65 73 20 61 20 73 loc provides a s
8c70: 69 67 6e 69 66 69 63 61 6e 74 20 70 65 72 66 6f ignificant perfo
8c80: 72 6d 61 6e 63 65 20 65 6e 68 61 6e 63 65 6d 65 rmance enhanceme
8c90: 6e 74 0a 2a 2a 20 28 61 70 70 72 6f 78 20 31 30 nt.** (approx 10
8ca0: 25 29 20 62 79 20 61 76 6f 69 64 69 6e 67 20 6e %) by avoiding n
8cb0: 75 6d 65 72 6f 75 73 20 6d 61 6c 6c 6f 63 2f 66 umerous malloc/f
8cc0: 72 65 65 20 72 65 71 75 65 73 74 73 20 77 68 69 ree requests whi
8cd0: 6c 65 20 70 61 72 73 69 6e 67 0a 2a 2a 20 53 51 le parsing.** SQ
8ce0: 4c 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a L statements..**
8cf0: 0a 2a 2a 20 54 68 65 20 4c 6f 6f 6b 61 73 69 64 .** The Lookasid
8d00: 65 20 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 e structure hold
8d10: 73 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 s configuration
8d20: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 information abou
8d30: 74 20 74 68 65 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 t the.** lookasi
8d40: 64 65 20 6d 61 6c 6c 6f 63 20 73 75 62 73 79 73 de malloc subsys
8d50: 74 65 6d 2e 20 20 45 61 63 68 20 61 76 61 69 6c tem. Each avail
8d60: 61 62 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f able memory allo
8d70: 63 61 74 69 6f 6e 20 69 6e 0a 2a 2a 20 74 68 65 cation in.** the
8d80: 20 6c 6f 6f 6b 61 73 69 64 65 20 73 75 62 73 79 lookaside subsy
8d90: 73 74 65 6d 20 69 73 20 73 74 6f 72 65 64 20 6f stem is stored o
8da0: 6e 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 n a linked list
8db0: 6f 66 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 of LookasideSlot
8dc0: 0a 2a 2a 20 6f 62 6a 65 63 74 73 2e 0a 2a 2a 0a .** objects..**.
8dd0: 2a 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 61 6c 6c ** Lookaside all
8de0: 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 6f 6e 6c ocations are onl
8df0: 79 20 61 6c 6c 6f 77 65 64 20 66 6f 72 20 6f 62 y allowed for ob
8e00: 6a 65 63 74 73 20 74 68 61 74 20 61 72 65 20 61 jects that are a
8e10: 73 73 6f 63 69 61 74 65 64 0a 2a 2a 20 77 69 74 ssociated.** wit
8e20: 68 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 64 h a particular d
8e30: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
8e40: 6f 6e 2e 20 20 48 65 6e 63 65 2c 20 73 63 68 65 on. Hence, sche
8e50: 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 ma information c
8e60: 61 6e 6e 6f 74 0a 2a 2a 20 62 65 20 73 74 6f 72 annot.** be stor
8e70: 65 64 20 69 6e 20 6c 6f 6f 6b 61 73 69 64 65 20 ed in lookaside
8e80: 62 65 63 61 75 73 65 20 69 6e 20 73 68 61 72 65 because in share
8e90: 64 20 63 61 63 68 65 20 6d 6f 64 65 20 74 68 65 d cache mode the
8ea0: 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 schema informat
8eb0: 69 6f 6e 0a 2a 2a 20 69 73 20 73 68 61 72 65 64 ion.** is shared
8ec0: 20 62 79 20 6d 75 6c 74 69 70 6c 65 20 64 61 74 by multiple dat
8ed0: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
8ee0: 73 2e 20 20 54 68 65 72 65 66 6f 72 65 2c 20 77 s. Therefore, w
8ef0: 68 69 6c 65 20 70 61 72 73 69 6e 67 0a 2a 2a 20 hile parsing.**
8f00: 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 schema informati
8f10: 6f 6e 2c 20 74 68 65 20 4c 6f 6f 6b 61 73 69 64 on, the Lookasid
8f20: 65 2e 62 45 6e 61 62 6c 65 64 20 66 6c 61 67 20 e.bEnabled flag
8f30: 69 73 20 63 6c 65 61 72 65 64 20 73 6f 20 74 68 is cleared so th
8f40: 61 74 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 at.** lookaside
8f50: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 allocations are
8f60: 6e 6f 74 20 75 73 65 64 20 74 6f 20 63 6f 6e 73 not used to cons
8f70: 74 72 75 63 74 20 74 68 65 20 73 63 68 65 6d 61 truct the schema
8f80: 20 6f 62 6a 65 63 74 73 2e 0a 2a 2f 0a 73 74 72 objects..*/.str
8f90: 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 20 7b 0a uct Lookaside {.
8fa0: 20 20 75 31 36 20 73 7a 3b 20 20 20 20 20 20 20 u16 sz;
8fb0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a /* Siz
8fc0: 65 20 6f 66 20 65 61 63 68 20 62 75 66 66 65 72 e of each buffer
8fd0: 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 75 in bytes */. u
8fe0: 38 20 62 45 6e 61 62 6c 65 64 3b 20 20 20 20 20 8 bEnabled;
8ff0: 20 20 20 20 20 20 20 2f 2a 20 46 61 6c 73 65 20 /* False
9000: 74 6f 20 64 69 73 61 62 6c 65 20 6e 65 77 20 6c to disable new l
9010: 6f 6f 6b 61 73 69 64 65 20 61 6c 6c 6f 63 61 74 ookaside allocat
9020: 69 6f 6e 73 20 2a 2f 0a 20 20 75 38 20 62 4d 61 ions */. u8 bMa
9030: 6c 6c 6f 63 65 64 3b 20 20 20 20 20 20 20 20 20 lloced;
9040: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 70 53 74 /* True if pSt
9050: 61 72 74 20 6f 62 74 61 69 6e 65 64 20 66 72 6f art obtained fro
9060: 6d 20 73 71 6c 69 74 65 33 5f 6d 61 6c 6c 6f 63 m sqlite3_malloc
9070: 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 4f 75 74 () */. int nOut
9080: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
9090: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 62 75 66 /* Number of buf
90a0: 66 65 72 73 20 63 75 72 72 65 6e 74 6c 79 20 63 fers currently c
90b0: 68 65 63 6b 65 64 20 6f 75 74 20 2a 2f 0a 20 20 hecked out */.
90c0: 69 6e 74 20 6d 78 4f 75 74 3b 20 20 20 20 20 20 int mxOut;
90d0: 20 20 20 20 20 20 20 20 2f 2a 20 48 69 67 68 77 /* Highw
90e0: 61 74 65 72 20 6d 61 72 6b 20 66 6f 72 20 6e 4f ater mark for nO
90f0: 75 74 20 2a 2f 0a 20 20 69 6e 74 20 61 6e 53 74 ut */. int anSt
9100: 61 74 5b 33 5d 3b 20 20 20 20 20 20 20 20 20 20 at[3];
9110: 2f 2a 20 30 3a 20 68 69 74 73 2e 20 20 31 3a 20 /* 0: hits. 1:
9120: 73 69 7a 65 20 6d 69 73 73 65 73 2e 20 20 32 3a size misses. 2:
9130: 20 66 75 6c 6c 20 6d 69 73 73 65 73 20 2a 2f 0a full misses */.
9140: 20 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 LookasideSlot
9150: 2a 70 46 72 65 65 3b 20 20 20 2f 2a 20 4c 69 73 *pFree; /* Lis
9160: 74 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 62 t of available b
9170: 75 66 66 65 72 73 20 2a 2f 0a 20 20 76 6f 69 64 uffers */. void
9180: 20 2a 70 53 74 61 72 74 3b 20 20 20 20 20 20 20 *pStart;
9190: 20 20 20 20 2f 2a 20 46 69 72 73 74 20 62 79 74 /* First byt
91a0: 65 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 6d e of available m
91b0: 65 6d 6f 72 79 20 73 70 61 63 65 20 2a 2f 0a 20 emory space */.
91c0: 20 76 6f 69 64 20 2a 70 45 6e 64 3b 20 20 20 20 void *pEnd;
91d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
91e0: 74 20 62 79 74 65 20 70 61 73 74 20 65 6e 64 20 t byte past end
91f0: 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 73 70 61 of available spa
9200: 63 65 20 2a 2f 0a 7d 3b 0a 73 74 72 75 63 74 20 ce */.};.struct
9210: 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 7b 0a LookasideSlot {.
9220: 20 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 LookasideSlot
9230: 2a 70 4e 65 78 74 3b 20 20 20 20 2f 2a 20 4e 65 *pNext; /* Ne
9240: 78 74 20 62 75 66 66 65 72 20 69 6e 20 74 68 65 xt buffer in the
9250: 20 6c 69 73 74 20 6f 66 20 66 72 65 65 20 62 75 list of free bu
9260: 66 66 65 72 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a ffers */.};../*.
9270: 2a 2a 20 41 20 68 61 73 68 20 74 61 62 6c 65 20 ** A hash table
9280: 66 6f 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 for function def
9290: 69 6e 69 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 initions..**.**
92a0: 48 61 73 68 20 65 61 63 68 20 46 75 6e 63 44 65 Hash each FuncDe
92b0: 66 20 73 74 72 75 63 74 75 72 65 20 69 6e 74 6f f structure into
92c0: 20 6f 6e 65 20 6f 66 20 74 68 65 20 46 75 6e 63 one of the Func
92d0: 44 65 66 48 61 73 68 2e 61 5b 5d 20 73 6c 6f 74 DefHash.a[] slot
92e0: 73 2e 0a 2a 2a 20 43 6f 6c 6c 69 73 69 6f 6e 73 s..** Collisions
92f0: 20 61 72 65 20 6f 6e 20 74 68 65 20 46 75 6e 63 are on the Func
9300: 44 65 66 2e 70 48 61 73 68 20 63 68 61 69 6e 2e Def.pHash chain.
9310: 0a 2a 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 .*/.struct FuncD
9320: 65 66 48 61 73 68 20 7b 0a 20 20 46 75 6e 63 44 efHash {. FuncD
9330: 65 66 20 2a 61 5b 32 33 5d 3b 20 20 20 20 20 20 ef *a[23];
9340: 20 2f 2a 20 48 61 73 68 20 74 61 62 6c 65 20 66 /* Hash table f
9350: 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a or functions */.
9360: 7d 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 };..#ifdef SQLIT
9370: 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 E_USER_AUTHENTIC
9380: 41 54 49 4f 4e 0a 2f 2a 0a 2a 2a 20 49 6e 66 6f ATION./*.** Info
9390: 72 6d 61 74 69 6f 6e 20 68 65 6c 64 20 69 6e 20 rmation held in
93a0: 74 68 65 20 22 73 71 6c 69 74 65 33 22 20 64 61 the "sqlite3" da
93b0: 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
93c0: 6e 20 6f 62 6a 65 63 74 20 61 6e 64 20 75 73 65 n object and use
93d0: 64 0a 2a 2a 20 74 6f 20 6d 61 6e 61 67 65 20 75 d.** to manage u
93e0: 73 65 72 20 61 75 74 68 65 6e 74 69 63 61 74 69 ser authenticati
93f0: 6f 6e 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 on..*/.typedef s
9400: 74 72 75 63 74 20 73 71 6c 69 74 65 33 5f 75 73 truct sqlite3_us
9410: 65 72 61 75 74 68 20 73 71 6c 69 74 65 33 5f 75 erauth sqlite3_u
9420: 73 65 72 61 75 74 68 3b 0a 73 74 72 75 63 74 20 serauth;.struct
9430: 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 sqlite3_userauth
9440: 20 7b 0a 20 20 75 38 20 61 75 74 68 4c 65 76 65 {. u8 authLeve
9450: 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 l;
9460: 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 61 75 /* Current au
9470: 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6c 65 76 thentication lev
9480: 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 75 74 el */. int nAut
9490: 68 50 57 3b 20 20 20 20 20 20 20 20 20 20 20 20 hPW;
94a0: 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 /* Size of
94b0: 20 74 68 65 20 7a 41 75 74 68 50 57 20 69 6e 20 the zAuthPW in
94c0: 62 79 74 65 73 20 2a 2f 0a 20 20 63 68 61 72 20 bytes */. char
94d0: 2a 7a 41 75 74 68 50 57 3b 20 20 20 20 20 20 20 *zAuthPW;
94e0: 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 73 73 /* Pass
94f0: 77 6f 72 64 20 75 73 65 64 20 74 6f 20 61 75 74 word used to aut
9500: 68 65 6e 74 69 63 61 74 65 20 2a 2f 0a 20 20 63 henticate */. c
9510: 68 61 72 20 2a 7a 41 75 74 68 55 73 65 72 3b 20 har *zAuthUser;
9520: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9530: 55 73 65 72 20 6e 61 6d 65 20 75 73 65 64 20 74 User name used t
9540: 6f 20 61 75 74 68 65 6e 74 69 63 61 74 65 20 2a o authenticate *
9550: 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 /.};../* Allowed
9560: 20 76 61 6c 75 65 73 20 66 6f 72 20 73 71 6c 69 values for sqli
9570: 74 65 33 5f 75 73 65 72 61 75 74 68 2e 61 75 74 te3_userauth.aut
9580: 68 4c 65 76 65 6c 20 2a 2f 0a 23 64 65 66 69 6e hLevel */.#defin
9590: 65 20 55 41 55 54 48 5f 55 6e 6b 6e 6f 77 6e 20 e UAUTH_Unknown
95a0: 20 20 20 20 30 20 20 20 20 20 2f 2a 20 41 75 74 0 /* Aut
95b0: 68 65 6e 74 69 63 61 74 69 6f 6e 20 6e 6f 74 20 hentication not
95c0: 79 65 74 20 63 68 65 63 6b 65 64 20 2a 2f 0a 23 yet checked */.#
95d0: 64 65 66 69 6e 65 20 55 41 55 54 48 5f 46 61 69 define UAUTH_Fai
95e0: 6c 20 20 20 20 20 20 20 20 31 20 20 20 20 20 2f l 1 /
95f0: 2a 20 55 73 65 72 20 61 75 74 68 65 6e 74 69 63 * User authentic
9600: 61 74 69 6f 6e 20 66 61 69 6c 65 64 20 2a 2f 0a ation failed */.
9610: 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 55 73 #define UAUTH_Us
9620: 65 72 20 20 20 20 20 20 20 20 32 20 20 20 20 20 er 2
9630: 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 74 65 64 /* Authenticated
9640: 20 61 73 20 61 20 6e 6f 72 6d 61 6c 20 75 73 65 as a normal use
9650: 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 r */.#define UAU
9660: 54 48 5f 41 64 6d 69 6e 20 20 20 20 20 20 20 33 TH_Admin 3
9670: 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 /* Authenti
9680: 63 61 74 65 64 20 61 73 20 61 6e 20 61 64 6d 69 cated as an admi
9690: 6e 69 73 74 72 61 74 6f 72 20 2a 2f 0a 0a 2f 2a nistrator */../*
96a0: 20 46 75 6e 63 74 69 6f 6e 73 20 75 73 65 64 20 Functions used
96b0: 6f 6e 6c 79 20 62 79 20 75 73 65 72 20 61 75 74 only by user aut
96c0: 68 6f 72 69 7a 61 74 69 6f 6e 20 6c 6f 67 69 63 horization logic
96d0: 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 */.int sqlite3U
96e0: 73 65 72 41 75 74 68 54 61 62 6c 65 28 63 6f 6e serAuthTable(con
96f0: 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 20 73 st char*);.int s
9700: 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 43 68 qlite3UserAuthCh
9710: 65 63 6b 4c 6f 67 69 6e 28 73 71 6c 69 74 65 33 eckLogin(sqlite3
9720: 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 38 *,const char*,u8
9730: 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
9740: 55 73 65 72 41 75 74 68 49 6e 69 74 28 73 71 6c UserAuthInit(sql
9750: 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ite3*);.void sql
9760: 69 74 65 33 43 72 79 70 74 46 75 6e 63 28 73 71 ite3CryptFunc(sq
9770: 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 lite3_context*,i
9780: 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 nt,sqlite3_value
9790: 2a 2a 29 3b 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 **);..#endif /*
97a0: 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 SQLITE_USER_AUTH
97b0: 45 4e 54 49 43 41 54 49 4f 4e 20 2a 2f 0a 0a 2f ENTICATION */../
97c0: 2a 0a 2a 2a 20 74 79 70 65 64 65 66 20 66 6f 72 *.** typedef for
97d0: 20 74 68 65 20 61 75 74 68 6f 72 69 7a 61 74 69 the authorizati
97e0: 6f 6e 20 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 on callback func
97f0: 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 tion..*/.#ifdef
9800: 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 SQLITE_USER_AUTH
9810: 45 4e 54 49 43 41 54 49 4f 4e 0a 20 20 74 79 70 ENTICATION. typ
9820: 65 64 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 74 edef int (*sqlit
9830: 65 33 5f 78 61 75 74 68 29 28 76 6f 69 64 2a 2c e3_xauth)(void*,
9840: 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c int,const char*,
9850: 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 const char*,cons
9860: 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 20 t char*,.
9870: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9880: 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 const ch
9890: 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
98a0: 29 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 64 );.#else. typed
98b0: 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 74 65 33 ef int (*sqlite3
98c0: 5f 78 61 75 74 68 29 28 76 6f 69 64 2a 2c 69 6e _xauth)(void*,in
98d0: 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f t,const char*,co
98e0: 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 nst char*,const
98f0: 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 20 20 20 char*,.
9900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9910: 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
9920: 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 0a *);.#endif.../*.
9930: 2a 2a 20 45 61 63 68 20 64 61 74 61 62 61 73 65 ** Each database
9940: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 20 61 connection is a
9950: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
9960: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
9970: 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 cture..*/.struct
9980: 20 73 71 6c 69 74 65 33 20 7b 0a 20 20 73 71 6c sqlite3 {. sql
9990: 69 74 65 33 5f 76 66 73 20 2a 70 56 66 73 3b 20 ite3_vfs *pVfs;
99a0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 53 /* OS
99b0: 20 49 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 Interface */.
99c0: 73 74 72 75 63 74 20 56 64 62 65 20 2a 70 56 64 struct Vdbe *pVd
99d0: 62 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a be; /*
99e0: 20 4c 69 73 74 20 6f 66 20 61 63 74 69 76 65 20 List of active
99f0: 76 69 72 74 75 61 6c 20 6d 61 63 68 69 6e 65 73 virtual machines
9a00: 20 2a 2f 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 70 */. CollSeq *p
9a10: 44 66 6c 74 43 6f 6c 6c 3b 20 20 20 20 20 20 20 DfltColl;
9a20: 20 20 20 20 2f 2a 20 54 68 65 20 64 65 66 61 75 /* The defau
9a30: 6c 74 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 lt collating seq
9a40: 75 65 6e 63 65 20 28 42 49 4e 41 52 59 29 20 2a uence (BINARY) *
9a50: 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 /. sqlite3_mute
9a60: 78 20 2a 6d 75 74 65 78 3b 20 20 20 20 20 20 20 x *mutex;
9a70: 20 20 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 /* Connection
9a80: 6d 75 74 65 78 20 2a 2f 0a 20 20 44 62 20 2a 61 mutex */. Db *a
9a90: 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 Db;
9aa0: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 /* All
9ab0: 62 61 63 6b 65 6e 64 73 20 2a 2f 0a 20 20 69 6e backends */. in
9ac0: 74 20 6e 44 62 3b 20 20 20 20 20 20 20 20 20 20 t nDb;
9ad0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
9ae0: 75 6d 62 65 72 20 6f 66 20 62 61 63 6b 65 6e 64 umber of backend
9af0: 73 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 s currently in u
9b00: 73 65 20 2a 2f 0a 20 20 69 6e 74 20 66 6c 61 67 se */. int flag
9b10: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 s;
9b20: 20 20 20 20 20 20 2f 2a 20 4d 69 73 63 65 6c 6c /* Miscell
9b30: 61 6e 65 6f 75 73 20 66 6c 61 67 73 2e 20 53 65 aneous flags. Se
9b40: 65 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 69 36 34 e below */. i64
9b50: 20 6c 61 73 74 52 6f 77 69 64 3b 20 20 20 20 20 lastRowid;
9b60: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 4f /* RO
9b70: 57 49 44 20 6f 66 20 6d 6f 73 74 20 72 65 63 65 WID of most rece
9b80: 6e 74 20 69 6e 73 65 72 74 20 28 73 65 65 20 61 nt insert (see a
9b90: 62 6f 76 65 29 20 2a 2f 0a 20 20 69 36 34 20 73 bove) */. i64 s
9ba0: 7a 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 zMmap;
9bb0: 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 /* Defa
9bc0: 75 6c 74 20 6d 6d 61 70 5f 73 69 7a 65 20 73 65 ult mmap_size se
9bd0: 74 74 69 6e 67 20 2a 2f 0a 20 20 75 6e 73 69 67 tting */. unsig
9be0: 6e 65 64 20 69 6e 74 20 6f 70 65 6e 46 6c 61 67 ned int openFlag
9bf0: 73 3b 20 20 20 20 20 20 20 2f 2a 20 46 6c 61 67 s; /* Flag
9c00: 73 20 70 61 73 73 65 64 20 74 6f 20 73 71 6c 69 s passed to sqli
9c10: 74 65 33 5f 76 66 73 2e 78 4f 70 65 6e 28 29 20 te3_vfs.xOpen()
9c20: 2a 2f 0a 20 20 69 6e 74 20 65 72 72 43 6f 64 65 */. int errCode
9c30: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
9c40: 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 63 65 6e /* Most recen
9c50: 74 20 65 72 72 6f 72 20 63 6f 64 65 20 28 53 51 t error code (SQ
9c60: 4c 49 54 45 5f 2a 29 20 2a 2f 0a 20 20 69 6e 74 LITE_*) */. int
9c70: 20 65 72 72 4d 61 73 6b 3b 20 20 20 20 20 20 20 errMask;
9c80: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 26 20 /* &
9c90: 72 65 73 75 6c 74 20 63 6f 64 65 73 20 77 69 74 result codes wit
9ca0: 68 20 74 68 69 73 20 62 65 66 6f 72 65 20 72 65 h this before re
9cb0: 74 75 72 6e 69 6e 67 20 2a 2f 0a 20 20 75 31 36 turning */. u16
9cc0: 20 64 62 4f 70 74 46 6c 61 67 73 3b 20 20 20 20 dbOptFlags;
9cd0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 6c /* Fl
9ce0: 61 67 73 20 74 6f 20 65 6e 61 62 6c 65 2f 64 69 ags to enable/di
9cf0: 73 61 62 6c 65 20 6f 70 74 69 6d 69 7a 61 74 69 sable optimizati
9d00: 6f 6e 73 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b ons */. u8 enc;
9d10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9d20: 20 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 65 /* Text e
9d30: 6e 63 6f 64 69 6e 67 20 2a 2f 0a 20 20 75 38 20 ncoding */. u8
9d40: 61 75 74 6f 43 6f 6d 6d 69 74 3b 20 20 20 20 20 autoCommit;
9d50: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
9d60: 65 20 61 75 74 6f 2d 63 6f 6d 6d 69 74 20 66 6c e auto-commit fl
9d70: 61 67 2e 20 2a 2f 0a 20 20 75 38 20 74 65 6d 70 ag. */. u8 temp
9d80: 5f 73 74 6f 72 65 3b 20 20 20 20 20 20 20 20 20 _store;
9d90: 20 20 20 20 20 20 20 2f 2a 20 31 3a 20 66 69 6c /* 1: fil
9da0: 65 20 32 3a 20 6d 65 6d 6f 72 79 20 30 3a 20 64 e 2: memory 0: d
9db0: 65 66 61 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6d efault */. u8 m
9dc0: 61 6c 6c 6f 63 46 61 69 6c 65 64 3b 20 20 20 20 allocFailed;
9dd0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
9de0: 65 20 69 66 20 77 65 20 68 61 76 65 20 73 65 65 e if we have see
9df0: 6e 20 61 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 n a malloc failu
9e00: 72 65 20 2a 2f 0a 20 20 75 38 20 64 66 6c 74 4c re */. u8 dfltL
9e10: 6f 63 6b 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 ockMode;
9e20: 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 /* Default
9e30: 20 6c 6f 63 6b 69 6e 67 2d 6d 6f 64 65 20 66 6f locking-mode fo
9e40: 72 20 61 74 74 61 63 68 65 64 20 64 62 73 20 2a r attached dbs *
9e50: 2f 0a 20 20 73 69 67 6e 65 64 20 63 68 61 72 20 /. signed char
9e60: 6e 65 78 74 41 75 74 6f 76 61 63 3b 20 20 20 20 nextAutovac;
9e70: 20 20 2f 2a 20 41 75 74 6f 76 61 63 20 73 65 74 /* Autovac set
9e80: 74 69 6e 67 20 61 66 74 65 72 20 56 41 43 55 55 ting after VACUU
9e90: 4d 20 69 66 20 3e 3d 30 20 2a 2f 0a 20 20 75 38 M if >=0 */. u8
9ea0: 20 73 75 70 70 72 65 73 73 45 72 72 3b 20 20 20 suppressErr;
9eb0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 /* D
9ec0: 6f 20 6e 6f 74 20 69 73 73 75 65 20 65 72 72 6f o not issue erro
9ed0: 72 20 6d 65 73 73 61 67 65 73 20 69 66 20 74 72 r messages if tr
9ee0: 75 65 20 2a 2f 0a 20 20 75 38 20 76 74 61 62 4f ue */. u8 vtabO
9ef0: 6e 43 6f 6e 66 6c 69 63 74 3b 20 20 20 20 20 20 nConflict;
9f00: 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 /* Value t
9f10: 6f 20 72 65 74 75 72 6e 20 66 6f 72 20 73 33 5f o return for s3_
9f20: 76 74 61 62 5f 6f 6e 5f 63 6f 6e 66 6c 69 63 74 vtab_on_conflict
9f30: 28 29 20 2a 2f 0a 20 20 75 38 20 69 73 54 72 61 () */. u8 isTra
9f40: 6e 73 61 63 74 69 6f 6e 53 61 76 65 70 6f 69 6e nsactionSavepoin
9f50: 74 3b 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 t; /* True if
9f60: 20 74 68 65 20 6f 75 74 65 72 6d 6f 73 74 20 73 the outermost s
9f70: 61 76 65 70 6f 69 6e 74 20 69 73 20 61 20 54 53 avepoint is a TS
9f80: 20 2a 2f 0a 20 20 69 6e 74 20 6e 65 78 74 50 61 */. int nextPa
9f90: 67 65 73 69 7a 65 3b 20 20 20 20 20 20 20 20 20 gesize;
9fa0: 20 20 20 20 2f 2a 20 50 61 67 65 73 69 7a 65 20 /* Pagesize
9fb0: 61 66 74 65 72 20 56 41 43 55 55 4d 20 69 66 20 after VACUUM if
9fc0: 3e 30 20 2a 2f 0a 20 20 75 33 32 20 6d 61 67 69 >0 */. u32 magi
9fd0: 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
9fe0: 20 20 20 20 20 20 2f 2a 20 4d 61 67 69 63 20 6e /* Magic n
9ff0: 75 6d 62 65 72 20 66 6f 72 20 64 65 74 65 63 74 umber for detect
a000: 20 6c 69 62 72 61 72 79 20 6d 69 73 75 73 65 20 library misuse
a010: 2a 2f 0a 20 20 69 6e 74 20 6e 43 68 61 6e 67 65 */. int nChange
a020: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
a030: 20 20 20 2f 2a 20 56 61 6c 75 65 20 72 65 74 75 /* Value retu
a040: 72 6e 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f rned by sqlite3_
a050: 63 68 61 6e 67 65 73 28 29 20 2a 2f 0a 20 20 69 changes() */. i
a060: 6e 74 20 6e 54 6f 74 61 6c 43 68 61 6e 67 65 3b nt nTotalChange;
a070: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
a080: 56 61 6c 75 65 20 72 65 74 75 72 6e 65 64 20 62 Value returned b
a090: 79 20 73 71 6c 69 74 65 33 5f 74 6f 74 61 6c 5f y sqlite3_total_
a0a0: 63 68 61 6e 67 65 73 28 29 20 2a 2f 0a 20 20 69 changes() */. i
a0b0: 6e 74 20 61 4c 69 6d 69 74 5b 53 51 4c 49 54 45 nt aLimit[SQLITE
a0c0: 5f 4e 5f 4c 49 4d 49 54 5d 3b 20 20 20 2f 2a 20 _N_LIMIT]; /*
a0d0: 4c 69 6d 69 74 73 20 2a 2f 0a 20 20 69 6e 74 20 Limits */. int
a0e0: 6e 4d 61 78 53 6f 72 74 65 72 4d 6d 61 70 3b 20 nMaxSorterMmap;
a0f0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 /* Max
a100: 69 6d 75 6d 20 73 69 7a 65 20 6f 66 20 72 65 67 imum size of reg
a110: 69 6f 6e 73 20 6d 61 70 70 65 64 20 62 79 20 73 ions mapped by s
a120: 6f 72 74 65 72 20 2a 2f 0a 20 20 73 74 72 75 63 orter */. struc
a130: 74 20 73 71 6c 69 74 65 33 49 6e 69 74 49 6e 66 t sqlite3InitInf
a140: 6f 20 7b 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f o { /* Info
a150: 72 6d 61 74 69 6f 6e 20 75 73 65 64 20 64 75 72 rmation used dur
a160: 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ing initializati
a170: 6f 6e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 65 on */. int ne
a180: 77 54 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 20 wTnum;
a190: 20 20 20 20 20 20 2f 2a 20 52 6f 6f 74 70 61 67 /* Rootpag
a1a0: 65 20 6f 66 20 74 61 62 6c 65 20 62 65 69 6e 67 e of table being
a1b0: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
a1c0: 20 20 20 20 75 38 20 69 44 62 3b 20 20 20 20 20 u8 iDb;
a1d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a1e0: 2f 2a 20 57 68 69 63 68 20 64 62 20 66 69 6c 65 /* Which db file
a1f0: 20 69 73 20 62 65 69 6e 67 20 69 6e 69 74 69 61 is being initia
a200: 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 20 75 38 20 lized */. u8
a210: 62 75 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 busy;
a220: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 52 55 45 /* TRUE
a230: 20 69 66 20 63 75 72 72 65 6e 74 6c 79 20 69 6e if currently in
a240: 69 74 69 61 6c 69 7a 69 6e 67 20 2a 2f 0a 20 20 itializing */.
a250: 20 20 75 38 20 6f 72 70 68 61 6e 54 72 69 67 67 u8 orphanTrigg
a260: 65 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a er; /*
a270: 20 4c 61 73 74 20 73 74 61 74 65 6d 65 6e 74 20 Last statement
a280: 69 73 20 6f 72 70 68 61 6e 65 64 20 54 45 4d 50 is orphaned TEMP
a290: 20 74 72 69 67 67 65 72 20 2a 2f 0a 20 20 20 20 trigger */.
a2a0: 75 38 20 69 6d 70 6f 73 74 65 72 54 61 62 6c 65 u8 imposterTable
a2b0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 ; /* B
a2c0: 75 69 6c 64 69 6e 67 20 61 6e 20 69 6d 70 6f 73 uilding an impos
a2d0: 74 65 72 20 74 61 62 6c 65 20 2a 2f 0a 20 20 7d ter table */. }
a2e0: 20 69 6e 69 74 3b 0a 20 20 69 6e 74 20 6e 56 64 init;. int nVd
a2f0: 62 65 41 63 74 69 76 65 3b 20 20 20 20 20 20 20 beActive;
a300: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
a310: 20 6f 66 20 56 44 42 45 73 20 63 75 72 72 65 6e of VDBEs curren
a320: 74 6c 79 20 72 75 6e 6e 69 6e 67 20 2a 2f 0a 20 tly running */.
a330: 20 69 6e 74 20 6e 56 64 62 65 52 65 61 64 3b 20 int nVdbeRead;
a340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
a350: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 69 * Number of acti
a360: 76 65 20 56 44 42 45 73 20 74 68 61 74 20 72 65 ve VDBEs that re
a370: 61 64 20 6f 72 20 77 72 69 74 65 20 2a 2f 0a 20 ad or write */.
a380: 20 69 6e 74 20 6e 56 64 62 65 57 72 69 74 65 3b int nVdbeWrite;
a390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
a3a0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 69 * Number of acti
a3b0: 76 65 20 56 44 42 45 73 20 74 68 61 74 20 72 65 ve VDBEs that re
a3c0: 61 64 20 61 6e 64 20 77 72 69 74 65 20 2a 2f 0a ad and write */.
a3d0: 20 20 69 6e 74 20 6e 56 64 62 65 45 78 65 63 3b int nVdbeExec;
a3e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a3f0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 /* Number of nes
a400: 74 65 64 20 63 61 6c 6c 73 20 74 6f 20 56 64 62 ted calls to Vdb
a410: 65 45 78 65 63 28 29 20 2a 2f 0a 20 20 69 6e 74 eExec() */. int
a420: 20 6e 56 44 65 73 74 72 6f 79 3b 20 20 20 20 20 nVDestroy;
a430: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
a440: 6d 62 65 72 20 6f 66 20 61 63 74 69 76 65 20 4f mber of active O
a450: 50 5f 56 44 65 73 74 72 6f 79 20 6f 70 65 72 61 P_VDestroy opera
a460: 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 6e tions */. int n
a470: 45 78 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 20 Extension;
a480: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
a490: 65 72 20 6f 66 20 6c 6f 61 64 65 64 20 65 78 74 er of loaded ext
a4a0: 65 6e 73 69 6f 6e 73 20 2a 2f 0a 20 20 76 6f 69 ensions */. voi
a4b0: 64 20 2a 2a 61 45 78 74 65 6e 73 69 6f 6e 3b 20 d **aExtension;
a4c0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
a4d0: 72 61 79 20 6f 66 20 73 68 61 72 65 64 20 6c 69 ray of shared li
a4e0: 62 72 61 72 79 20 68 61 6e 64 6c 65 73 20 2a 2f brary handles */
a4f0: 0a 20 20 76 6f 69 64 20 28 2a 78 54 72 61 63 65 . void (*xTrace
a500: 29 28 76 6f 69 64 2a 2c 63 6f 6e 73 74 20 63 68 )(void*,const ch
a510: 61 72 2a 29 3b 20 20 20 20 20 20 20 20 2f 2a 20 ar*); /*
a520: 54 72 61 63 65 20 66 75 6e 63 74 69 6f 6e 20 2a Trace function *
a530: 2f 0a 20 20 76 6f 69 64 20 2a 70 54 72 61 63 65 /. void *pTrace
a540: 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Arg;
a550: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
a560: 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 Argument to the
a570: 20 74 72 61 63 65 20 66 75 6e 63 74 69 6f 6e 20 trace function
a580: 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 50 72 6f */. void (*xPro
a590: 66 69 6c 65 29 28 76 6f 69 64 2a 2c 63 6f 6e 73 file)(void*,cons
a5a0: 74 20 63 68 61 72 2a 2c 75 36 34 29 3b 20 20 2f t char*,u64); /
a5b0: 2a 20 50 72 6f 66 69 6c 69 6e 67 20 66 75 6e 63 * Profiling func
a5c0: 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a tion */. void *
a5d0: 70 50 72 6f 66 69 6c 65 41 72 67 3b 20 20 20 20 pProfileArg;
a5e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a5f0: 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 /* Argument
a600: 74 6f 20 70 72 6f 66 69 6c 65 20 66 75 6e 63 74 to profile funct
a610: 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ion */. void *p
a620: 43 6f 6d 6d 69 74 41 72 67 3b 20 20 20 20 20 20 CommitArg;
a630: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
a640: 67 75 6d 65 6e 74 20 74 6f 20 78 43 6f 6d 6d 69 gument to xCommi
a650: 74 43 61 6c 6c 62 61 63 6b 28 29 20 2a 2f 20 20 tCallback() */
a660: 20 0a 20 20 69 6e 74 20 28 2a 78 43 6f 6d 6d 69 . int (*xCommi
a670: 74 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a tCallback)(void*
a680: 29 3b 20 20 20 20 2f 2a 20 49 6e 76 6f 6b 65 64 ); /* Invoked
a690: 20 61 74 20 65 76 65 72 79 20 63 6f 6d 6d 69 74 at every commit
a6a0: 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 52 6f . */. void *pRo
a6b0: 6c 6c 62 61 63 6b 41 72 67 3b 20 20 20 20 20 20 llbackArg;
a6c0: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 /* Argu
a6d0: 6d 65 6e 74 20 74 6f 20 78 52 6f 6c 6c 62 61 63 ment to xRollbac
a6e0: 6b 43 61 6c 6c 62 61 63 6b 28 29 20 2a 2f 20 20 kCallback() */
a6f0: 20 0a 20 20 76 6f 69 64 20 28 2a 78 52 6f 6c 6c . void (*xRoll
a700: 62 61 63 6b 43 61 6c 6c 62 61 63 6b 29 28 76 6f backCallback)(vo
a710: 69 64 2a 29 3b 20 2f 2a 20 49 6e 76 6f 6b 65 64 id*); /* Invoked
a720: 20 61 74 20 65 76 65 72 79 20 63 6f 6d 6d 69 74 at every commit
a730: 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 70 . */. void *pUp
a740: 64 61 74 65 41 72 67 3b 0a 20 20 76 6f 69 64 20 dateArg;. void
a750: 28 2a 78 55 70 64 61 74 65 43 61 6c 6c 62 61 63 (*xUpdateCallbac
a760: 6b 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f k)(void*,int, co
a770: 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 nst char*,const
a780: 63 68 61 72 2a 2c 73 71 6c 69 74 65 5f 69 6e 74 char*,sqlite_int
a790: 36 34 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 64);.#ifndef SQL
a7a0: 49 54 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 ITE_OMIT_WAL. i
a7b0: 6e 74 20 28 2a 78 57 61 6c 43 61 6c 6c 62 61 63 nt (*xWalCallbac
a7c0: 6b 29 28 76 6f 69 64 20 2a 2c 20 73 71 6c 69 74 k)(void *, sqlit
a7d0: 65 33 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 e3 *, const char
a7e0: 20 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 *, int);. void
a7f0: 20 2a 70 57 61 6c 41 72 67 3b 0a 23 65 6e 64 69 *pWalArg;.#endi
a800: 66 0a 20 20 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e f. void(*xCollN
a810: 65 65 64 65 64 29 28 76 6f 69 64 2a 2c 73 71 6c eeded)(void*,sql
a820: 69 74 65 33 2a 2c 69 6e 74 20 65 54 65 78 74 52 ite3*,int eTextR
a830: 65 70 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b ep,const char*);
a840: 0a 20 20 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 . void(*xCollNe
a850: 65 64 65 64 31 36 29 28 76 6f 69 64 2a 2c 73 71 eded16)(void*,sq
a860: 6c 69 74 65 33 2a 2c 69 6e 74 20 65 54 65 78 74 lite3*,int eText
a870: 52 65 70 2c 63 6f 6e 73 74 20 76 6f 69 64 2a 29 Rep,const void*)
a880: 3b 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6c 6c 4e ;. void *pCollN
a890: 65 65 64 65 64 41 72 67 3b 0a 20 20 73 71 6c 69 eededArg;. sqli
a8a0: 74 65 33 5f 76 61 6c 75 65 20 2a 70 45 72 72 3b te3_value *pErr;
a8b0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f 73 /* Mos
a8c0: 74 20 72 65 63 65 6e 74 20 65 72 72 6f 72 20 6d t recent error m
a8d0: 65 73 73 61 67 65 20 2a 2f 0a 20 20 75 6e 69 6f essage */. unio
a8e0: 6e 20 7b 0a 20 20 20 20 76 6f 6c 61 74 69 6c 65 n {. volatile
a8f0: 20 69 6e 74 20 69 73 49 6e 74 65 72 72 75 70 74 int isInterrupt
a900: 65 64 3b 20 2f 2a 20 54 72 75 65 20 69 66 20 73 ed; /* True if s
a910: 71 6c 69 74 65 33 5f 69 6e 74 65 72 72 75 70 74 qlite3_interrupt
a920: 20 68 61 73 20 62 65 65 6e 20 63 61 6c 6c 65 64 has been called
a930: 20 2a 2f 0a 20 20 20 20 64 6f 75 62 6c 65 20 6e */. double n
a940: 6f 74 55 73 65 64 31 3b 20 20 20 20 20 20 20 20 otUsed1;
a950: 20 20 20 20 2f 2a 20 53 70 61 63 65 72 20 2a 2f /* Spacer */
a960: 0a 20 20 7d 20 75 31 3b 0a 20 20 4c 6f 6f 6b 61 . } u1;. Looka
a970: 73 69 64 65 20 6c 6f 6f 6b 61 73 69 64 65 3b 20 side lookaside;
a980: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 6b /* Look
a990: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 63 6f 6e aside malloc con
a9a0: 66 69 67 75 72 61 74 69 6f 6e 20 2a 2f 0a 23 69 figuration */.#i
a9b0: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
a9c0: 54 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a T_AUTHORIZATION.
a9d0: 20 20 73 71 6c 69 74 65 33 5f 78 61 75 74 68 20 sqlite3_xauth
a9e0: 78 41 75 74 68 3b 20 20 20 20 20 20 20 20 20 20 xAuth;
a9f0: 2f 2a 20 41 63 63 65 73 73 20 61 75 74 68 6f 72 /* Access author
aa00: 69 7a 61 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e ization function
aa10: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 41 75 74 */. void *pAut
aa20: 68 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 hArg;
aa30: 20 20 20 20 2f 2a 20 31 73 74 20 61 72 67 75 6d /* 1st argum
aa40: 65 6e 74 20 74 6f 20 74 68 65 20 61 63 63 65 73 ent to the acces
aa50: 73 20 61 75 74 68 20 66 75 6e 63 74 69 6f 6e 20 s auth function
aa60: 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 */.#endif.#ifnde
aa70: 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 50 52 f SQLITE_OMIT_PR
aa80: 4f 47 52 45 53 53 5f 43 41 4c 4c 42 41 43 4b 0a OGRESS_CALLBACK.
aa90: 20 20 69 6e 74 20 28 2a 78 50 72 6f 67 72 65 73 int (*xProgres
aaa0: 73 29 28 76 6f 69 64 20 2a 29 3b 20 20 20 20 20 s)(void *);
aab0: 2f 2a 20 54 68 65 20 70 72 6f 67 72 65 73 73 20 /* The progress
aac0: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f callback */. vo
aad0: 69 64 20 2a 70 50 72 6f 67 72 65 73 73 41 72 67 id *pProgressArg
aae0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 ; /* A
aaf0: 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 70 rgument to the p
ab00: 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b rogress callback
ab10: 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 6e */. unsigned n
ab20: 50 72 6f 67 72 65 73 73 4f 70 73 3b 20 20 20 20 ProgressOps;
ab30: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
ab40: 20 6f 70 63 6f 64 65 73 20 66 6f 72 20 70 72 6f opcodes for pro
ab50: 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 2a gress callback *
ab60: 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 /.#endif.#ifndef
ab70: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 SQLITE_OMIT_VIR
ab80: 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 20 TUALTABLE. int
ab90: 6e 56 54 72 61 6e 73 3b 20 20 20 20 20 20 20 20 nVTrans;
aba0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c /* All
abb0: 6f 63 61 74 65 64 20 73 69 7a 65 20 6f 66 20 61 ocated size of a
abc0: 56 54 72 61 6e 73 20 2a 2f 0a 20 20 48 61 73 68 VTrans */. Hash
abd0: 20 61 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 20 aModule;
abe0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 70 6f 70 /* pop
abf0: 75 6c 61 74 65 64 20 62 79 20 73 71 6c 69 74 65 ulated by sqlite
ac00: 33 5f 63 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 3_create_module(
ac10: 29 20 2a 2f 0a 20 20 56 74 61 62 43 74 78 20 2a ) */. VtabCtx *
ac20: 70 56 74 61 62 43 74 78 3b 20 20 20 20 20 20 20 pVtabCtx;
ac30: 20 20 20 20 20 2f 2a 20 43 6f 6e 74 65 78 74 20 /* Context
ac40: 66 6f 72 20 61 63 74 69 76 65 20 76 74 61 62 20 for active vtab
ac50: 63 6f 6e 6e 65 63 74 2f 63 72 65 61 74 65 20 2a connect/create *
ac60: 2f 0a 20 20 56 54 61 62 6c 65 20 2a 2a 61 56 54 /. VTable **aVT
ac70: 72 61 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 rans;
ac80: 20 20 2f 2a 20 56 69 72 74 75 61 6c 20 74 61 62 /* Virtual tab
ac90: 6c 65 73 20 77 69 74 68 20 6f 70 65 6e 20 74 72 les with open tr
aca0: 61 6e 73 61 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 ansactions */.
acb0: 56 54 61 62 6c 65 20 2a 70 44 69 73 63 6f 6e 6e VTable *pDisconn
acc0: 65 63 74 3b 20 20 20 20 2f 2a 20 44 69 73 63 6f ect; /* Disco
acd0: 6e 6e 65 63 74 20 74 68 65 73 65 20 69 6e 20 6e nnect these in n
ace0: 65 78 74 20 73 71 6c 69 74 65 33 5f 70 72 65 70 ext sqlite3_prep
acf0: 61 72 65 28 29 20 2a 2f 0a 23 65 6e 64 69 66 0a are() */.#endif.
ad00: 20 20 46 75 6e 63 44 65 66 48 61 73 68 20 61 46 FuncDefHash aF
ad10: 75 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 unc;
ad20: 2f 2a 20 48 61 73 68 20 74 61 62 6c 65 20 6f 66 /* Hash table of
ad30: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 66 75 6e 63 connection func
ad40: 74 69 6f 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 tions */. Hash
ad50: 61 43 6f 6c 6c 53 65 71 3b 20 20 20 20 20 20 20 aCollSeq;
ad60: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 /* All
ad70: 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e collating sequen
ad80: 63 65 73 20 2a 2f 0a 20 20 42 75 73 79 48 61 6e ces */. BusyHan
ad90: 64 6c 65 72 20 62 75 73 79 48 61 6e 64 6c 65 72 dler busyHandler
ada0: 3b 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 63 ; /* Busy c
adb0: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 44 62 20 allback */. Db
adc0: 61 44 62 53 74 61 74 69 63 5b 32 5d 3b 20 20 20 aDbStatic[2];
add0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 /* St
ade0: 61 74 69 63 20 73 70 61 63 65 20 66 6f 72 20 74 atic space for t
adf0: 68 65 20 32 20 64 65 66 61 75 6c 74 20 62 61 63 he 2 default bac
ae00: 6b 65 6e 64 73 20 2a 2f 0a 20 20 53 61 76 65 70 kends */. Savep
ae10: 6f 69 6e 74 20 2a 70 53 61 76 65 70 6f 69 6e 74 oint *pSavepoint
ae20: 3b 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 ; /* List
ae30: 20 6f 66 20 61 63 74 69 76 65 20 73 61 76 65 70 of active savep
ae40: 6f 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 62 oints */. int b
ae50: 75 73 79 54 69 6d 65 6f 75 74 3b 20 20 20 20 20 usyTimeout;
ae60: 20 20 20 20 20 20 20 20 20 2f 2a 20 42 75 73 79 /* Busy
ae70: 20 68 61 6e 64 6c 65 72 20 74 69 6d 65 6f 75 74 handler timeout
ae80: 2c 20 69 6e 20 6d 73 65 63 20 2a 2f 0a 20 20 69 , in msec */. i
ae90: 6e 74 20 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 nt nSavepoint;
aea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
aeb0: 4e 75 6d 62 65 72 20 6f 66 20 6e 6f 6e 2d 74 72 Number of non-tr
aec0: 61 6e 73 61 63 74 69 6f 6e 20 73 61 76 65 70 6f ansaction savepo
aed0: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 ints */. int nS
aee0: 74 61 74 65 6d 65 6e 74 3b 20 20 20 20 20 20 20 tatement;
aef0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
af00: 72 20 6f 66 20 6e 65 73 74 65 64 20 73 74 61 74 r of nested stat
af10: 65 6d 65 6e 74 2d 74 72 61 6e 73 61 63 74 69 6f ement-transactio
af20: 6e 73 20 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 ns */. i64 nDe
af30: 66 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 ferredCons;
af40: 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 /* Net de
af50: 66 65 72 72 65 64 20 63 6f 6e 73 74 72 61 69 6e ferred constrain
af60: 74 73 20 74 68 69 73 20 74 72 61 6e 73 61 63 74 ts this transact
af70: 69 6f 6e 2e 20 2a 2f 0a 20 20 69 36 34 20 6e 44 ion. */. i64 nD
af80: 65 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 eferredImmCons;
af90: 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 /* Net d
afa0: 65 66 65 72 72 65 64 20 69 6d 6d 65 64 69 61 74 eferred immediat
afb0: 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f e constraints */
afc0: 0a 20 20 69 6e 74 20 2a 70 6e 42 79 74 65 73 46 . int *pnBytesF
afd0: 72 65 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 reed;
afe0: 20 2f 2a 20 49 66 20 6e 6f 74 20 4e 55 4c 4c 2c /* If not NULL,
aff0: 20 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 73 20 increment this
b000: 69 6e 20 44 62 46 72 65 65 28 29 20 2a 2f 0a 23 in DbFree() */.#
b010: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
b020: 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 BLE_UNLOCK_NOTIF
b030: 59 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f Y. /* The follo
b040: 77 69 6e 67 20 76 61 72 69 61 62 6c 65 73 20 61 wing variables a
b050: 72 65 20 61 6c 6c 20 70 72 6f 74 65 63 74 65 64 re all protected
b060: 20 62 79 20 74 68 65 20 53 54 41 54 49 43 5f 4d by the STATIC_M
b070: 41 53 54 45 52 20 0a 20 20 2a 2a 20 6d 75 74 65 ASTER . ** mute
b080: 78 2c 20 6e 6f 74 20 62 79 20 73 71 6c 69 74 65 x, not by sqlite
b090: 33 2e 6d 75 74 65 78 2e 20 54 68 65 79 20 61 72 3.mutex. They ar
b0a0: 65 20 75 73 65 64 20 62 79 20 63 6f 64 65 20 69 e used by code i
b0b0: 6e 20 6e 6f 74 69 66 79 2e 63 2e 20 0a 20 20 2a n notify.c. . *
b0c0: 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 55 *. ** When X.pU
b0d0: 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3d nlockConnection=
b0e0: 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 =Y, that means t
b0f0: 68 61 74 20 58 20 69 73 20 77 61 69 74 69 6e 67 hat X is waiting
b100: 20 66 6f 72 20 59 20 74 6f 0a 20 20 2a 2a 20 75 for Y to. ** u
b110: 6e 6c 6f 63 6b 20 73 6f 20 74 68 61 74 20 69 74 nlock so that it
b120: 20 63 61 6e 20 70 72 6f 63 65 65 64 2e 0a 20 20 can proceed..
b130: 2a 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 **. ** When X.p
b140: 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 BlockingConnecti
b150: 6f 6e 3d 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e on==Y, that mean
b160: 73 20 74 68 61 74 20 73 6f 6d 65 74 68 69 6e 67 s that something
b170: 20 74 68 61 74 20 58 20 74 72 69 65 64 0a 20 20 that X tried.
b180: 2a 2a 20 74 72 69 65 64 20 74 6f 20 64 6f 20 72 ** tried to do r
b190: 65 63 65 6e 74 6c 79 20 66 61 69 6c 65 64 20 77 ecently failed w
b1a0: 69 74 68 20 61 6e 20 53 51 4c 49 54 45 5f 4c 4f ith an SQLITE_LO
b1b0: 43 4b 45 44 20 65 72 72 6f 72 20 64 75 65 20 74 CKED error due t
b1c0: 6f 20 6c 6f 63 6b 73 0a 20 20 2a 2a 20 68 65 6c o locks. ** hel
b1d0: 64 20 62 79 20 59 2e 0a 20 20 2a 2f 0a 20 20 73 d by Y.. */. s
b1e0: 71 6c 69 74 65 33 20 2a 70 42 6c 6f 63 6b 69 6e qlite3 *pBlockin
b1f0: 67 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 2f 2a 20 gConnection; /*
b200: 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 68 61 74 20 Connection that
b210: 63 61 75 73 65 64 20 53 51 4c 49 54 45 5f 4c 4f caused SQLITE_LO
b220: 43 4b 45 44 20 2a 2f 0a 20 20 73 71 6c 69 74 65 CKED */. sqlite
b230: 33 20 2a 70 55 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 3 *pUnlockConnec
b240: 74 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 tion;
b250: 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f /* Connection to
b260: 20 77 61 74 63 68 20 66 6f 72 20 75 6e 6c 6f 63 watch for unloc
b270: 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 6e k */. void *pUn
b280: 6c 6f 63 6b 41 72 67 3b 20 20 20 20 20 20 20 20 lockArg;
b290: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
b2a0: 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 55 6e 6c Argument to xUnl
b2b0: 6f 63 6b 4e 6f 74 69 66 79 20 2a 2f 0a 20 20 76 ockNotify */. v
b2c0: 6f 69 64 20 28 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 oid (*xUnlockNot
b2d0: 69 66 79 29 28 76 6f 69 64 20 2a 2a 2c 20 69 6e ify)(void **, in
b2e0: 74 29 3b 20 20 2f 2a 20 55 6e 6c 6f 63 6b 20 6e t); /* Unlock n
b2f0: 6f 74 69 66 79 20 63 61 6c 6c 62 61 63 6b 20 2a otify callback *
b300: 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 4e 65 /. sqlite3 *pNe
b310: 78 74 42 6c 6f 63 6b 65 64 3b 20 20 20 20 20 20 xtBlocked;
b320: 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 73 /* Next in lis
b330: 74 20 6f 66 20 61 6c 6c 20 62 6c 6f 63 6b 65 64 t of all blocked
b340: 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 20 2a 2f 0a connections */.
b350: 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 #endif.#ifdef SQ
b360: 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e LITE_USER_AUTHEN
b370: 54 49 43 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 TICATION. sqlit
b380: 65 33 5f 75 73 65 72 61 75 74 68 20 61 75 74 68 e3_userauth auth
b390: 3b 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 72 ; /* User
b3a0: 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 authentication
b3b0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 23 information */.#
b3c0: 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 endif.};../*.**
b3d0: 41 20 6d 61 63 72 6f 20 74 6f 20 64 69 73 63 6f A macro to disco
b3e0: 76 65 72 20 74 68 65 20 65 6e 63 6f 64 69 6e 67 ver the encoding
b3f0: 20 6f 66 20 61 20 64 61 74 61 62 61 73 65 2e 0a of a database..
b400: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 45 4d */.#define SCHEM
b410: 41 5f 45 4e 43 28 64 62 29 20 28 28 64 62 29 2d A_ENC(db) ((db)-
b420: 3e 61 44 62 5b 30 5d 2e 70 53 63 68 65 6d 61 2d >aDb[0].pSchema-
b430: 3e 65 6e 63 29 0a 23 64 65 66 69 6e 65 20 45 4e >enc).#define EN
b440: 43 28 64 62 29 20 20 20 20 20 20 20 20 28 28 64 C(db) ((d
b450: 62 29 2d 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 b)->enc)../*.**
b460: 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 Possible values
b470: 66 6f 72 20 74 68 65 20 73 71 6c 69 74 65 33 2e for the sqlite3.
b480: 66 6c 61 67 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e flags..*/.#defin
b490: 65 20 53 51 4c 49 54 45 5f 56 64 62 65 54 72 61 e SQLITE_VdbeTra
b4a0: 63 65 20 20 20 20 20 20 30 78 30 30 30 30 30 30 ce 0x000000
b4b0: 30 31 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 74 01 /* True to t
b4c0: 72 61 63 65 20 56 44 42 45 20 65 78 65 63 75 74 race VDBE execut
b4d0: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ion */.#define S
b4e0: 51 4c 49 54 45 5f 49 6e 74 65 72 6e 43 68 61 6e QLITE_InternChan
b4f0: 67 65 73 20 20 30 78 30 30 30 30 30 30 30 32 20 ges 0x00000002
b500: 20 2f 2a 20 55 6e 63 6f 6d 6d 69 74 74 65 64 20 /* Uncommitted
b510: 48 61 73 68 20 74 61 62 6c 65 20 63 68 61 6e 67 Hash table chang
b520: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
b530: 4c 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 20 20 LITE_FullFSync
b540: 20 20 20 20 30 78 30 30 30 30 30 30 30 34 20 20 0x00000004
b550: 2f 2a 20 55 73 65 20 66 75 6c 6c 20 66 73 79 6e /* Use full fsyn
b560: 63 20 6f 6e 20 74 68 65 20 62 61 63 6b 65 6e 64 c on the backend
b570: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b580: 54 45 5f 43 6b 70 74 46 75 6c 6c 46 53 79 6e 63 TE_CkptFullFSync
b590: 20 20 30 78 30 30 30 30 30 30 30 38 20 20 2f 2a 0x00000008 /*
b5a0: 20 55 73 65 20 66 75 6c 6c 20 66 73 79 6e 63 20 Use full fsync
b5b0: 66 6f 72 20 63 68 65 63 6b 70 6f 69 6e 74 20 2a for checkpoint *
b5c0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
b5d0: 5f 43 61 63 68 65 53 70 69 6c 6c 20 20 20 20 20 _CacheSpill
b5e0: 30 78 30 30 30 30 30 30 31 30 20 20 2f 2a 20 4f 0x00000010 /* O
b5f0: 4b 20 74 6f 20 73 70 69 6c 6c 20 70 61 67 65 72 K to spill pager
b600: 20 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e cache */.#defin
b610: 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c 43 6f 6c e SQLITE_FullCol
b620: 4e 61 6d 65 73 20 20 20 30 78 30 30 30 30 30 30 Names 0x000000
b630: 32 30 20 20 2f 2a 20 53 68 6f 77 20 66 75 6c 6c 20 /* Show full
b640: 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6f 6e column names on
b650: 20 53 45 4c 45 43 54 20 2a 2f 0a 23 64 65 66 69 SELECT */.#defi
b660: 6e 65 20 53 51 4c 49 54 45 5f 53 68 6f 72 74 43 ne SQLITE_ShortC
b670: 6f 6c 4e 61 6d 65 73 20 20 30 78 30 30 30 30 30 olNames 0x00000
b680: 30 34 30 20 20 2f 2a 20 53 68 6f 77 20 73 68 6f 040 /* Show sho
b690: 72 74 20 63 6f 6c 75 6d 6e 73 20 6e 61 6d 65 73 rt columns names
b6a0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b6b0: 54 45 5f 43 6f 75 6e 74 52 6f 77 73 20 20 20 20 TE_CountRows
b6c0: 20 20 30 78 30 30 30 30 30 30 38 30 20 20 2f 2a 0x00000080 /*
b6d0: 20 43 6f 75 6e 74 20 72 6f 77 73 20 63 68 61 6e Count rows chan
b6e0: 67 65 64 20 62 79 20 49 4e 53 45 52 54 2c 20 2a ged by INSERT, *
b6f0: 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 /.
b700: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b710: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 /*
b720: 20 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 41 DELETE, or UPDA
b730: 54 45 20 61 6e 64 20 72 65 74 75 72 6e 20 2a 2f TE and return */
b740: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
b750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b760: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 /*
b770: 74 68 65 20 63 6f 75 6e 74 20 75 73 69 6e 67 20 the count using
b780: 61 20 63 61 6c 6c 62 61 63 6b 2e 20 2a 2f 0a 23 a callback. */.#
b790: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 75 define SQLITE_Nu
b7a0: 6c 6c 43 61 6c 6c 62 61 63 6b 20 20 20 30 78 30 llCallback 0x0
b7b0: 30 30 30 30 31 30 30 20 20 2f 2a 20 49 6e 76 6f 0000100 /* Invo
b7c0: 6b 65 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 ke the callback
b7d0: 6f 6e 63 65 20 69 66 20 74 68 65 20 2a 2f 0a 20 once if the */.
b7e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b7f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b800: 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 72 65 /* re
b810: 73 75 6c 74 20 73 65 74 20 69 73 20 65 6d 70 74 sult set is empt
b820: 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c y */.#define SQL
b830: 49 54 45 5f 53 71 6c 54 72 61 63 65 20 20 20 20 ITE_SqlTrace
b840: 20 20 20 30 78 30 30 30 30 30 32 30 30 20 20 2f 0x00000200 /
b850: 2a 20 44 65 62 75 67 20 70 72 69 6e 74 20 53 51 * Debug print SQ
b860: 4c 20 61 73 20 69 74 20 65 78 65 63 75 74 65 73 L as it executes
b870: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b880: 54 45 5f 56 64 62 65 4c 69 73 74 69 6e 67 20 20 TE_VdbeListing
b890: 20 20 30 78 30 30 30 30 30 34 30 30 20 20 2f 2a 0x00000400 /*
b8a0: 20 44 65 62 75 67 20 6c 69 73 74 69 6e 67 73 20 Debug listings
b8b0: 6f 66 20 56 44 42 45 20 70 72 6f 67 72 61 6d 73 of VDBE programs
b8c0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b8d0: 54 45 5f 57 72 69 74 65 53 63 68 65 6d 61 20 20 TE_WriteSchema
b8e0: 20 20 30 78 30 30 30 30 30 38 30 30 20 20 2f 2a 0x00000800 /*
b8f0: 20 4f 4b 20 74 6f 20 75 70 64 61 74 65 20 53 51 OK to update SQ
b900: 4c 49 54 45 5f 4d 41 53 54 45 52 20 2a 2f 0a 23 LITE_MASTER */.#
b910: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 define SQLITE_Vd
b920: 62 65 41 64 64 6f 70 54 72 61 63 65 20 30 78 30 beAddopTrace 0x0
b930: 30 30 30 31 30 30 30 20 20 2f 2a 20 54 72 61 63 0001000 /* Trac
b940: 65 20 73 71 6c 69 74 65 33 56 64 62 65 41 64 64 e sqlite3VdbeAdd
b950: 4f 70 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 23 64 Op() calls */.#d
b960: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 67 6e efine SQLITE_Ign
b970: 6f 72 65 43 68 65 63 6b 73 20 20 20 30 78 30 30 oreChecks 0x00
b980: 30 30 32 30 30 30 20 20 2f 2a 20 44 6f 20 6e 6f 002000 /* Do no
b990: 74 20 65 6e 66 6f 72 63 65 20 63 68 65 63 6b 20 t enforce check
b9a0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 constraints */.#
b9b0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 define SQLITE_Re
b9c0: 61 64 55 6e 63 6f 6d 6d 69 74 74 65 64 20 30 78 adUncommitted 0x
b9d0: 30 30 30 34 30 30 30 20 20 2f 2a 20 46 6f 72 20 0004000 /* For
b9e0: 73 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 shared-cache mod
b9f0: 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c e */.#define SQL
ba00: 49 54 45 5f 4c 65 67 61 63 79 46 69 6c 65 46 6d ITE_LegacyFileFm
ba10: 74 20 20 30 78 30 30 30 30 38 30 30 30 20 20 2f t 0x00008000 /
ba20: 2a 20 43 72 65 61 74 65 20 6e 65 77 20 64 61 74 * Create new dat
ba30: 61 62 61 73 65 73 20 69 6e 20 66 6f 72 6d 61 74 abases in format
ba40: 20 31 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 1 */.#define SQ
ba50: 4c 49 54 45 5f 52 65 63 6f 76 65 72 79 4d 6f 64 LITE_RecoveryMod
ba60: 65 20 20 20 30 78 30 30 30 31 30 30 30 30 20 20 e 0x00010000
ba70: 2f 2a 20 49 67 6e 6f 72 65 20 73 63 68 65 6d 61 /* Ignore schema
ba80: 20 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 errors */.#defi
ba90: 6e 65 20 53 51 4c 49 54 45 5f 52 65 76 65 72 73 ne SQLITE_Revers
baa0: 65 4f 72 64 65 72 20 20 20 30 78 30 30 30 32 30 eOrder 0x00020
bab0: 30 30 30 20 20 2f 2a 20 52 65 76 65 72 73 65 20 000 /* Reverse
bac0: 75 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 43 54 unordered SELECT
bad0: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
bae0: 49 54 45 5f 52 65 63 54 72 69 67 67 65 72 73 20 ITE_RecTriggers
baf0: 20 20 20 30 78 30 30 30 34 30 30 30 30 20 20 2f 0x00040000 /
bb00: 2a 20 45 6e 61 62 6c 65 20 72 65 63 75 72 73 69 * Enable recursi
bb10: 76 65 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 23 ve triggers */.#
bb20: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 6f define SQLITE_Fo
bb30: 72 65 69 67 6e 4b 65 79 73 20 20 20 20 30 78 30 reignKeys 0x0
bb40: 30 30 38 30 30 30 30 20 20 2f 2a 20 45 6e 66 6f 0080000 /* Enfo
bb50: 72 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 rce foreign key
bb60: 63 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a 2f 0a constraints */.
bb70: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
bb80: 75 74 6f 49 6e 64 65 78 20 20 20 20 20 20 30 78 utoIndex 0x
bb90: 30 30 31 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 00100000 /* Ena
bba0: 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 69 6e ble automatic in
bbb0: 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 dexes */.#define
bbc0: 20 53 51 4c 49 54 45 5f 50 72 65 66 65 72 42 75 SQLITE_PreferBu
bbd0: 69 6c 74 69 6e 20 20 30 78 30 30 32 30 30 30 30 iltin 0x0020000
bbe0: 30 20 20 2f 2a 20 50 72 65 66 65 72 65 6e 63 65 0 /* Preference
bbf0: 20 74 6f 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e to built-in fun
bc00: 63 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 cs */.#define SQ
bc10: 4c 49 54 45 5f 4c 6f 61 64 45 78 74 65 6e 73 69 LITE_LoadExtensi
bc20: 6f 6e 20 20 30 78 30 30 34 30 30 30 30 30 20 20 on 0x00400000
bc30: 2f 2a 20 45 6e 61 62 6c 65 20 6c 6f 61 64 5f 65 /* Enable load_e
bc40: 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 23 64 65 66 xtension */.#def
bc50: 69 6e 65 20 53 51 4c 49 54 45 5f 45 6e 61 62 6c ine SQLITE_Enabl
bc60: 65 54 72 69 67 67 65 72 20 20 30 78 30 30 38 30 eTrigger 0x0080
bc70: 30 30 30 30 20 20 2f 2a 20 54 72 75 65 20 74 6f 0000 /* True to
bc80: 20 65 6e 61 62 6c 65 20 74 72 69 67 67 65 72 73 enable triggers
bc90: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bca0: 54 45 5f 44 65 66 65 72 46 4b 73 20 20 20 20 20 TE_DeferFKs
bcb0: 20 20 30 78 30 31 30 30 30 30 30 30 20 20 2f 2a 0x01000000 /*
bcc0: 20 44 65 66 65 72 20 61 6c 6c 20 46 4b 20 63 6f Defer all FK co
bcd0: 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 nstraints */.#de
bce0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 72 fine SQLITE_Quer
bcf0: 79 4f 6e 6c 79 20 20 20 20 20 20 30 78 30 32 30 yOnly 0x020
bd00: 30 30 30 30 30 20 20 2f 2a 20 44 69 73 61 62 6c 00000 /* Disabl
bd10: 65 20 64 61 74 61 62 61 73 65 20 63 68 61 6e 67 e database chang
bd20: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
bd30: 4c 49 54 45 5f 56 64 62 65 45 51 50 20 20 20 20 LITE_VdbeEQP
bd40: 20 20 20 20 30 78 30 34 30 30 30 30 30 30 20 20 0x04000000
bd50: 2f 2a 20 44 65 62 75 67 20 45 58 50 4c 41 49 4e /* Debug EXPLAIN
bd60: 20 51 55 45 52 59 20 50 4c 41 4e 20 2a 2f 0a 23 QUERY PLAN */.#
bd70: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 61 define SQLITE_Va
bd80: 63 75 75 6d 20 20 20 20 20 20 20 20 20 30 78 30 cuum 0x0
bd90: 38 30 30 30 30 30 30 20 20 2f 2a 20 43 75 72 72 8000000 /* Curr
bda0: 65 6e 74 6c 79 20 69 6e 20 61 20 56 41 43 55 55 ently in a VACUU
bdb0: 4d 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c M */.#define SQL
bdc0: 49 54 45 5f 43 65 6c 6c 53 69 7a 65 43 6b 20 20 ITE_CellSizeCk
bdd0: 20 20 20 30 78 31 30 30 30 30 30 30 30 20 20 2f 0x10000000 /
bde0: 2a 20 43 68 65 63 6b 20 62 74 72 65 65 20 63 65 * Check btree ce
bdf0: 6c 6c 20 73 69 7a 65 73 20 6f 6e 20 6c 6f 61 64 ll sizes on load
be00: 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 73 */.../*.** Bits
be10: 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 33 2e of the sqlite3.
be20: 64 62 4f 70 74 46 6c 61 67 73 20 66 69 65 6c 64 dbOptFlags field
be30: 20 74 68 61 74 20 61 72 65 20 75 73 65 64 20 62 that are used b
be40: 79 20 74 68 65 0a 2a 2a 20 73 71 6c 69 74 65 33 y the.** sqlite3
be50: 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 53 51 _test_control(SQ
be60: 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f 4f 50 LITE_TESTCTRL_OP
be70: 54 49 4d 49 5a 41 54 49 4f 4e 53 2c 2e 2e 2e 29 TIMIZATIONS,...)
be80: 20 69 6e 74 65 72 66 61 63 65 20 74 6f 0a 2a 2a interface to.**
be90: 20 73 65 6c 65 63 74 69 76 65 6c 79 20 64 69 73 selectively dis
bea0: 61 62 6c 65 20 76 61 72 69 6f 75 73 20 6f 70 74 able various opt
beb0: 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 imizations..*/.#
bec0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 define SQLITE_Qu
bed0: 65 72 79 46 6c 61 74 74 65 6e 65 72 20 30 78 30 eryFlattener 0x0
bee0: 30 30 31 20 20 20 2f 2a 20 51 75 65 72 79 20 66 001 /* Query f
bef0: 6c 61 74 74 65 6e 69 6e 67 20 2a 2f 0a 23 64 65 lattening */.#de
bf00: 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f 6c 75 fine SQLITE_Colu
bf10: 6d 6e 43 61 63 68 65 20 20 20 20 30 78 30 30 30 mnCache 0x000
bf20: 32 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 63 61 2 /* Column ca
bf30: 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 che */.#define S
bf40: 51 4c 49 54 45 5f 47 72 6f 75 70 42 79 4f 72 64 QLITE_GroupByOrd
bf50: 65 72 20 20 20 30 78 30 30 30 34 20 20 20 2f 2a er 0x0004 /*
bf60: 20 47 52 4f 55 50 42 59 20 63 6f 76 65 72 20 6f GROUPBY cover o
bf70: 66 20 4f 52 44 45 52 42 59 20 2a 2f 0a 23 64 65 f ORDERBY */.#de
bf80: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 61 63 74 fine SQLITE_Fact
bf90: 6f 72 4f 75 74 43 6f 6e 73 74 20 30 78 30 30 30 orOutConst 0x000
bfa0: 38 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 8 /* Constant
bfb0: 66 61 63 74 6f 72 69 6e 67 20 2a 2f 0a 2f 2a 20 factoring */./*
bfc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6e n
bfd0: 6f 74 20 75 73 65 64 20 20 20 20 30 78 30 30 31 ot used 0x001
bfe0: 30 20 20 20 2f 2f 20 57 61 73 3a 20 53 51 4c 49 0 // Was: SQLI
bff0: 54 45 5f 49 64 78 52 65 61 6c 41 73 49 6e 74 20 TE_IdxRealAsInt
c000: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
c010: 45 5f 44 69 73 74 69 6e 63 74 4f 70 74 20 20 20 E_DistinctOpt
c020: 20 30 78 30 30 32 30 20 20 20 2f 2a 20 44 49 53 0x0020 /* DIS
c030: 54 49 4e 43 54 20 75 73 69 6e 67 20 69 6e 64 65 TINCT using inde
c040: 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 xes */.#define S
c050: 51 4c 49 54 45 5f 43 6f 76 65 72 49 64 78 53 63 QLITE_CoverIdxSc
c060: 61 6e 20 20 20 30 78 30 30 34 30 20 20 20 2f 2a an 0x0040 /*
c070: 20 43 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 Covering index
c080: 73 63 61 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 scans */.#define
c090: 20 53 51 4c 49 54 45 5f 4f 72 64 65 72 42 79 49 SQLITE_OrderByI
c0a0: 64 78 4a 6f 69 6e 20 30 78 30 30 38 30 20 20 20 dxJoin 0x0080
c0b0: 2f 2a 20 4f 52 44 45 52 20 42 59 20 6f 66 20 6a /* ORDER BY of j
c0c0: 6f 69 6e 73 20 76 69 61 20 69 6e 64 65 78 20 2a oins via index *
c0d0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
c0e0: 5f 53 75 62 71 43 6f 72 6f 75 74 69 6e 65 20 20 _SubqCoroutine
c0f0: 30 78 30 31 30 30 20 20 20 2f 2a 20 45 76 61 6c 0x0100 /* Eval
c100: 75 61 74 65 20 73 75 62 71 75 65 72 69 65 73 20 uate subqueries
c110: 61 73 20 63 6f 72 6f 75 74 69 6e 65 73 20 2a 2f as coroutines */
c120: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
c130: 54 72 61 6e 73 69 74 69 76 65 20 20 20 20 20 30 Transitive 0
c140: 78 30 32 30 30 20 20 20 2f 2a 20 54 72 61 6e 73 x0200 /* Trans
c150: 69 74 69 76 65 20 63 6f 6e 73 74 72 61 69 6e 74 itive constraint
c160: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
c170: 49 54 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f 69 6e ITE_OmitNoopJoin
c180: 20 20 20 30 78 30 34 30 30 20 20 20 2f 2a 20 4f 0x0400 /* O
c190: 6d 69 74 20 75 6e 75 73 65 64 20 74 61 62 6c 65 mit unused table
c1a0: 73 20 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a 23 64 s in joins */.#d
c1b0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 74 61 efine SQLITE_Sta
c1c0: 74 33 34 20 20 20 20 20 20 20 20 20 30 78 30 38 t34 0x08
c1d0: 30 30 20 20 20 2f 2a 20 55 73 65 20 53 54 41 54 00 /* Use STAT
c1e0: 33 20 6f 72 20 53 54 41 54 34 20 64 61 74 61 20 3 or STAT4 data
c1f0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
c200: 45 5f 41 6c 6c 4f 70 74 73 20 20 20 20 20 20 20 E_AllOpts
c210: 20 30 78 66 66 66 66 20 20 20 2f 2a 20 41 6c 6c 0xffff /* All
c220: 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 2a optimizations *
c230: 2f 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 /../*.** Macros
c240: 66 6f 72 20 74 65 73 74 69 6e 67 20 77 68 65 74 for testing whet
c250: 68 65 72 20 6f 72 20 6e 6f 74 20 6f 70 74 69 6d her or not optim
c260: 69 7a 61 74 69 6f 6e 73 20 61 72 65 20 65 6e 61 izations are ena
c270: 62 6c 65 64 20 6f 72 20 64 69 73 61 62 6c 65 64 bled or disabled
c280: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c ..*/.#ifndef SQL
c290: 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e ITE_OMIT_BUILTIN
c2a0: 5f 54 45 53 54 0a 23 64 65 66 69 6e 65 20 4f 70 _TEST.#define Op
c2b0: 74 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 62 6c timizationDisabl
c2c0: 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 28 28 ed(db, mask) ((
c2d0: 28 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 67 73 (db)->dbOptFlags
c2e0: 26 28 6d 61 73 6b 29 29 21 3d 30 29 0a 23 64 65 &(mask))!=0).#de
c2f0: 66 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f fine Optimizatio
c300: 6e 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 nEnabled(db, mas
c310: 6b 29 20 20 20 28 28 28 64 62 29 2d 3e 64 62 4f k) (((db)->dbO
c320: 70 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 3d ptFlags&(mask))=
c330: 3d 30 29 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e =0).#else.#defin
c340: 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 69 e OptimizationDi
c350: 73 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 sabled(db, mask)
c360: 20 20 30 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 0.#define Opti
c370: 6d 69 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 64 28 mizationEnabled(
c380: 64 62 2c 20 6d 61 73 6b 29 20 20 20 31 0a 23 65 db, mask) 1.#e
c390: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 ndif../*.** Retu
c3a0: 72 6e 20 74 72 75 65 20 69 66 20 69 74 20 4f 4b rn true if it OK
c3b0: 20 74 6f 20 66 61 63 74 6f 72 20 63 6f 6e 73 74 to factor const
c3c0: 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 73 20 ant expressions
c3d0: 69 6e 74 6f 20 74 68 65 20 69 6e 69 74 69 61 6c into the initial
c3e0: 69 7a 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 65 2e ization.** code.
c3f0: 20 54 68 65 20 61 72 67 75 6d 65 6e 74 20 69 73 The argument is
c400: 20 61 20 50 61 72 73 65 20 6f 62 6a 65 63 74 20 a Parse object
c410: 66 6f 72 20 74 68 65 20 63 6f 64 65 20 67 65 6e for the code gen
c420: 65 72 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 66 69 erator..*/.#defi
c430: 6e 65 20 43 6f 6e 73 74 46 61 63 74 6f 72 4f 6b ne ConstFactorOk
c440: 28 50 29 20 28 28 50 29 2d 3e 6f 6b 43 6f 6e 73 (P) ((P)->okCons
c450: 74 46 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a 2a 20 tFactor)../*.**
c460: 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 Possible values
c470: 66 6f 72 20 74 68 65 20 73 71 6c 69 74 65 2e 6d for the sqlite.m
c480: 61 67 69 63 20 66 69 65 6c 64 2e 0a 2a 2a 20 54 agic field..** T
c490: 68 65 20 6e 75 6d 62 65 72 73 20 61 72 65 20 6f he numbers are o
c4a0: 62 74 61 69 6e 65 64 20 61 74 20 72 61 6e 64 6f btained at rando
c4b0: 6d 20 61 6e 64 20 68 61 76 65 20 6e 6f 20 73 70 m and have no sp
c4c0: 65 63 69 61 6c 20 6d 65 61 6e 69 6e 67 2c 20 6f ecial meaning, o
c4d0: 74 68 65 72 0a 2a 2a 20 74 68 61 6e 20 62 65 69 ther.** than bei
c4e0: 6e 67 20 64 69 73 74 69 6e 63 74 20 66 72 6f 6d ng distinct from
c4f0: 20 6f 6e 65 20 61 6e 6f 74 68 65 72 2e 0a 2a 2f one another..*/
c500: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
c510: 4d 41 47 49 43 5f 4f 50 45 4e 20 20 20 20 20 30 MAGIC_OPEN 0
c520: 78 61 30 32 39 61 36 39 37 20 20 2f 2a 20 44 61 xa029a697 /* Da
c530: 74 61 62 61 73 65 20 69 73 20 6f 70 65 6e 20 2a tabase is open *
c540: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
c550: 5f 4d 41 47 49 43 5f 43 4c 4f 53 45 44 20 20 20 _MAGIC_CLOSED
c560: 30 78 39 66 33 63 32 64 33 33 20 20 2f 2a 20 44 0x9f3c2d33 /* D
c570: 61 74 61 62 61 73 65 20 69 73 20 63 6c 6f 73 65 atabase is close
c580: 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c d */.#define SQL
c590: 49 54 45 5f 4d 41 47 49 43 5f 53 49 43 4b 20 20 ITE_MAGIC_SICK
c5a0: 20 20 20 30 78 34 62 37 37 31 32 39 30 20 20 2f 0x4b771290 /
c5b0: 2a 20 45 72 72 6f 72 20 61 6e 64 20 61 77 61 69 * Error and awai
c5c0: 74 69 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a 23 64 ting close */.#d
c5d0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 efine SQLITE_MAG
c5e0: 49 43 5f 42 55 53 59 20 20 20 20 20 30 78 66 30 IC_BUSY 0xf0
c5f0: 33 62 37 39 30 36 20 20 2f 2a 20 44 61 74 61 62 3b7906 /* Datab
c600: 61 73 65 20 63 75 72 72 65 6e 74 6c 79 20 69 6e ase currently in
c610: 20 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 use */.#define
c620: 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 45 52 52 SQLITE_MAGIC_ERR
c630: 4f 52 20 20 20 20 30 78 62 35 33 35 37 39 33 30 OR 0xb5357930
c640: 20 20 2f 2a 20 41 6e 20 53 51 4c 49 54 45 5f 4d /* An SQLITE_M
c650: 49 53 55 53 45 20 65 72 72 6f 72 20 6f 63 63 75 ISUSE error occu
c660: 72 72 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 rred */.#define
c670: 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 5a 4f 4d SQLITE_MAGIC_ZOM
c680: 42 49 45 20 20 20 30 78 36 34 63 66 66 63 37 66 BIE 0x64cffc7f
c690: 20 20 2f 2a 20 43 6c 6f 73 65 20 77 69 74 68 20 /* Close with
c6a0: 6c 61 73 74 20 73 74 61 74 65 6d 65 6e 74 20 63 last statement c
c6b0: 6c 6f 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 lose */../*.** E
c6c0: 61 63 68 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e ach SQL function
c6d0: 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 is defined by a
c6e0: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
c6f0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 e following.** s
c700: 74 72 75 63 74 75 72 65 2e 20 20 41 20 70 6f 69 tructure. A poi
c710: 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 nter to this str
c720: 75 63 74 75 72 65 20 69 73 20 73 74 6f 72 65 64 ucture is stored
c730: 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 in the sqlite.a
c740: 46 75 6e 63 0a 2a 2a 20 68 61 73 68 20 74 61 62 Func.** hash tab
c750: 6c 65 2e 20 20 57 68 65 6e 20 6d 75 6c 74 69 70 le. When multip
c760: 6c 65 20 66 75 6e 63 74 69 6f 6e 73 20 68 61 76 le functions hav
c770: 65 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 2c e the same name,
c780: 20 74 68 65 20 68 61 73 68 20 74 61 62 6c 65 0a the hash table.
c790: 2a 2a 20 70 6f 69 6e 74 73 20 74 6f 20 61 20 6c ** points to a l
c7a0: 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 74 68 inked list of th
c7b0: 65 73 65 20 73 74 72 75 63 74 75 72 65 73 2e 0a ese structures..
c7c0: 2a 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 65 */.struct FuncDe
c7d0: 66 20 7b 0a 20 20 69 31 36 20 6e 41 72 67 3b 20 f {. i16 nArg;
c7e0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
c7f0: 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 mber of argument
c800: 73 2e 20 20 2d 31 20 6d 65 61 6e 73 20 75 6e 6c s. -1 means unl
c810: 69 6d 69 74 65 64 20 2a 2f 0a 20 20 75 31 36 20 imited */. u16
c820: 66 75 6e 63 46 6c 61 67 73 3b 20 20 20 20 20 20 funcFlags;
c830: 20 2f 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 6e 61 /* Some combina
c840: 74 69 6f 6e 20 6f 66 20 53 51 4c 49 54 45 5f 46 tion of SQLITE_F
c850: 55 4e 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 64 20 UNC_* */. void
c860: 2a 70 55 73 65 72 44 61 74 61 3b 20 20 20 20 20 *pUserData;
c870: 2f 2a 20 55 73 65 72 20 64 61 74 61 20 70 61 72 /* User data par
c880: 61 6d 65 74 65 72 20 2a 2f 0a 20 20 46 75 6e 63 ameter */. Func
c890: 44 65 66 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 Def *pNext;
c8a0: 20 2f 2a 20 4e 65 78 74 20 66 75 6e 63 74 69 6f /* Next functio
c8b0: 6e 20 77 69 74 68 20 73 61 6d 65 20 6e 61 6d 65 n with same name
c8c0: 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 46 75 */. void (*xFu
c8d0: 6e 63 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 nc)(sqlite3_cont
c8e0: 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 ext*,int,sqlite3
c8f0: 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 52 65 _value**); /* Re
c900: 67 75 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 2a gular function *
c910: 2f 0a 20 20 76 6f 69 64 20 28 2a 78 53 74 65 70 /. void (*xStep
c920: 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 )(sqlite3_contex
c930: 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 t*,int,sqlite3_v
c940: 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 41 67 67 72 alue**); /* Aggr
c950: 65 67 61 74 65 20 73 74 65 70 20 2a 2f 0a 20 20 egate step */.
c960: 76 6f 69 64 20 28 2a 78 46 69 6e 61 6c 69 7a 65 void (*xFinalize
c970: 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 )(sqlite3_contex
c980: 74 2a 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 t*);
c990: 20 20 20 20 2f 2a 20 41 67 67 72 65 67 61 74 65 /* Aggregate
c9a0: 20 66 69 6e 61 6c 69 7a 65 72 20 2a 2f 0a 20 20 finalizer */.
c9b0: 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
c9c0: 20 20 20 20 20 2f 2a 20 53 51 4c 20 6e 61 6d 65 /* SQL name
c9d0: 20 6f 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e of the function
c9e0: 2e 20 2a 2f 0a 20 20 46 75 6e 63 44 65 66 20 2a . */. FuncDef *
c9f0: 70 48 61 73 68 3b 20 20 20 20 20 20 2f 2a 20 4e pHash; /* N
ca00: 65 78 74 20 77 69 74 68 20 61 20 64 69 66 66 65 ext with a diffe
ca10: 72 65 6e 74 20 6e 61 6d 65 20 62 75 74 20 74 68 rent name but th
ca20: 65 20 73 61 6d 65 20 68 61 73 68 20 2a 2f 0a 20 e same hash */.
ca30: 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 FuncDestructor
ca40: 2a 70 44 65 73 74 72 75 63 74 6f 72 3b 20 20 20 *pDestructor;
ca50: 2f 2a 20 52 65 66 65 72 65 6e 63 65 20 63 6f 75 /* Reference cou
ca60: 6e 74 65 64 20 64 65 73 74 72 75 63 74 6f 72 20 nted destructor
ca70: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a function */.};..
ca80: 2f 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 /*.** This struc
ca90: 74 75 72 65 20 65 6e 63 61 70 73 75 6c 61 74 65 ture encapsulate
caa0: 73 20 61 20 75 73 65 72 2d 66 75 6e 63 74 69 6f s a user-functio
cab0: 6e 20 64 65 73 74 72 75 63 74 6f 72 20 63 61 6c n destructor cal
cac0: 6c 62 61 63 6b 20 28 61 73 0a 2a 2a 20 63 6f 6e lback (as.** con
cad0: 66 69 67 75 72 65 64 20 75 73 69 6e 67 20 63 72 figured using cr
cae0: 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 eate_function_v2
caf0: 28 29 29 20 61 6e 64 20 61 20 72 65 66 65 72 65 ()) and a refere
cb00: 6e 63 65 20 63 6f 75 6e 74 65 72 2e 20 57 68 65 nce counter. Whe
cb10: 6e 0a 2a 2a 20 63 72 65 61 74 65 5f 66 75 6e 63 n.** create_func
cb20: 74 69 6f 6e 5f 76 32 28 29 20 69 73 20 63 61 6c tion_v2() is cal
cb30: 6c 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 led to create a
cb40: 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 61 20 function with a
cb50: 64 65 73 74 72 75 63 74 6f 72 2c 0a 2a 2a 20 61 destructor,.** a
cb60: 20 73 69 6e 67 6c 65 20 6f 62 6a 65 63 74 20 6f single object o
cb70: 66 20 74 68 69 73 20 74 79 70 65 20 69 73 20 61 f this type is a
cb80: 6c 6c 6f 63 61 74 65 64 2e 20 46 75 6e 63 44 65 llocated. FuncDe
cb90: 73 74 72 75 63 74 6f 72 2e 6e 52 65 66 20 69 73 structor.nRef is
cba0: 20 73 65 74 20 74 6f 20 0a 2a 2a 20 74 68 65 20 set to .** the
cbb0: 6e 75 6d 62 65 72 20 6f 66 20 46 75 6e 63 44 65 number of FuncDe
cbc0: 66 20 6f 62 6a 65 63 74 73 20 63 72 65 61 74 65 f objects create
cbd0: 64 20 28 65 69 74 68 65 72 20 31 20 6f 72 20 33 d (either 1 or 3
cbe0: 2c 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 77 , depending on w
cbf0: 68 65 74 68 65 72 0a 2a 2a 20 6f 72 20 6e 6f 74 hether.** or not
cc00: 20 74 68 65 20 73 70 65 63 69 66 69 65 64 20 65 the specified e
cc10: 6e 63 6f 64 69 6e 67 20 69 73 20 53 51 4c 49 54 ncoding is SQLIT
cc20: 45 5f 41 4e 59 29 2e 20 54 68 65 20 46 75 6e 63 E_ANY). The Func
cc30: 44 65 66 2e 70 44 65 73 74 72 75 63 74 6f 72 0a Def.pDestructor.
cc40: 2a 2a 20 6d 65 6d 62 65 72 20 6f 66 20 65 61 63 ** member of eac
cc50: 68 20 6f 66 20 74 68 65 20 6e 65 77 20 46 75 6e h of the new Fun
cc60: 63 44 65 66 20 6f 62 6a 65 63 74 73 20 69 73 20 cDef objects is
cc70: 73 65 74 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 set to point to
cc80: 74 68 65 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a the allocated.**
cc90: 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 2e FuncDestructor.
cca0: 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 61 66 74 65 .**.** Thereafte
ccb0: 72 2c 20 77 68 65 6e 20 6f 6e 65 20 6f 66 20 74 r, when one of t
ccc0: 68 65 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 he FuncDef objec
ccd0: 74 73 20 69 73 20 64 65 6c 65 74 65 64 2c 20 74 ts is deleted, t
cce0: 68 65 20 72 65 66 65 72 65 6e 63 65 0a 2a 2a 20 he reference.**
ccf0: 63 6f 75 6e 74 20 6f 6e 20 74 68 69 73 20 6f 62 count on this ob
cd00: 6a 65 63 74 20 69 73 20 64 65 63 72 65 6d 65 6e ject is decremen
cd10: 74 65 64 2e 20 57 68 65 6e 20 69 74 20 72 65 61 ted. When it rea
cd20: 63 68 65 73 20 30 2c 20 74 68 65 20 64 65 73 74 ches 0, the dest
cd30: 72 75 63 74 6f 72 0a 2a 2a 20 69 73 20 69 6e 76 ructor.** is inv
cd40: 6f 6b 65 64 20 61 6e 64 20 74 68 65 20 46 75 6e oked and the Fun
cd50: 63 44 65 73 74 72 75 63 74 6f 72 20 73 74 72 75 cDestructor stru
cd60: 63 74 75 72 65 20 66 72 65 65 64 2e 0a 2a 2f 0a cture freed..*/.
cd70: 73 74 72 75 63 74 20 46 75 6e 63 44 65 73 74 72 struct FuncDestr
cd80: 75 63 74 6f 72 20 7b 0a 20 20 69 6e 74 20 6e 52 uctor {. int nR
cd90: 65 66 3b 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 ef;. void (*xDe
cda0: 73 74 72 6f 79 29 28 76 6f 69 64 20 2a 29 3b 0a stroy)(void *);.
cdb0: 20 20 76 6f 69 64 20 2a 70 55 73 65 72 44 61 74 void *pUserDat
cdc0: 61 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 a;.};../*.** Pos
cdd0: 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 sible values for
cde0: 20 46 75 6e 63 44 65 66 2e 66 6c 61 67 73 2e 20 FuncDef.flags.
cdf0: 20 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20 5f Note that the _
ce00: 4c 45 4e 47 54 48 20 61 6e 64 20 5f 54 59 50 45 LENGTH and _TYPE
ce10: 4f 46 0a 2a 2a 20 76 61 6c 75 65 73 20 6d 75 73 OF.** values mus
ce20: 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 t correspond to
ce30: 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 OPFLAG_LENGTHARG
ce40: 20 61 6e 64 20 4f 50 46 4c 41 47 5f 54 59 50 45 and OPFLAG_TYPE
ce50: 4f 46 41 52 47 2e 20 20 54 68 65 72 65 0a 2a 2a OFARG. There.**
ce60: 20 61 72 65 20 61 73 73 65 72 74 28 29 20 73 74 are assert() st
ce70: 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 atements in the
ce80: 63 6f 64 65 20 74 6f 20 76 65 72 69 66 79 20 74 code to verify t
ce90: 68 69 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 his..*/.#define
cea0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 4e 43 4d SQLITE_FUNC_ENCM
ceb0: 41 53 4b 20 20 30 78 30 30 30 33 20 2f 2a 20 53 ASK 0x0003 /* S
cec0: 51 4c 49 54 45 5f 55 54 46 38 2c 20 53 51 4c 49 QLITE_UTF8, SQLI
ced0: 54 45 5f 55 54 46 31 36 42 45 20 6f 72 20 55 54 TE_UTF16BE or UT
cee0: 46 31 36 4c 45 20 2a 2f 0a 23 64 65 66 69 6e 65 F16LE */.#define
cef0: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 49 4b SQLITE_FUNC_LIK
cf00: 45 20 20 20 20 20 30 78 30 30 30 34 20 2f 2a 20 E 0x0004 /*
cf10: 43 61 6e 64 69 64 61 74 65 20 66 6f 72 20 74 68 Candidate for th
cf20: 65 20 4c 49 4b 45 20 6f 70 74 69 6d 69 7a 61 74 e LIKE optimizat
cf30: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ion */.#define S
cf40: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 41 53 45 20 QLITE_FUNC_CASE
cf50: 20 20 20 20 30 78 30 30 30 38 20 2f 2a 20 43 61 0x0008 /* Ca
cf60: 73 65 2d 73 65 6e 73 69 74 69 76 65 20 4c 49 4b se-sensitive LIK
cf70: 45 2d 74 79 70 65 20 66 75 6e 63 74 69 6f 6e 20 E-type function
cf80: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
cf90: 45 5f 46 55 4e 43 5f 45 50 48 45 4d 20 20 20 20 E_FUNC_EPHEM
cfa0: 30 78 30 30 31 30 20 2f 2a 20 45 70 68 65 6d 65 0x0010 /* Epheme
cfb0: 72 61 6c 2e 20 20 44 65 6c 65 74 65 20 77 69 74 ral. Delete wit
cfc0: 68 20 56 44 42 45 20 2a 2f 0a 23 64 65 66 69 6e h VDBE */.#defin
cfd0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 e SQLITE_FUNC_NE
cfe0: 45 44 43 4f 4c 4c 20 30 78 30 30 32 30 20 2f 2a EDCOLL 0x0020 /*
cff0: 20 73 71 6c 69 74 65 33 47 65 74 46 75 6e 63 43 sqlite3GetFuncC
d000: 6f 6c 6c 53 65 71 28 29 20 6d 69 67 68 74 20 62 ollSeq() might b
d010: 65 20 63 61 6c 6c 65 64 2a 2f 0a 23 64 65 66 69 e called*/.#defi
d020: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c ne SQLITE_FUNC_L
d030: 45 4e 47 54 48 20 20 20 30 78 30 30 34 30 20 2f ENGTH 0x0040 /
d040: 2a 20 42 75 69 6c 74 2d 69 6e 20 6c 65 6e 67 74 * Built-in lengt
d050: 68 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a h() function */.
d060: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
d070: 55 4e 43 5f 54 59 50 45 4f 46 20 20 20 30 78 30 UNC_TYPEOF 0x0
d080: 30 38 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 080 /* Built-in
d090: 74 79 70 65 6f 66 28 29 20 66 75 6e 63 74 69 6f typeof() functio
d0a0: 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c n */.#define SQL
d0b0: 49 54 45 5f 46 55 4e 43 5f 43 4f 55 4e 54 20 20 ITE_FUNC_COUNT
d0c0: 20 20 30 78 30 31 30 30 20 2f 2a 20 42 75 69 6c 0x0100 /* Buil
d0d0: 74 2d 69 6e 20 63 6f 75 6e 74 28 2a 29 20 61 67 t-in count(*) ag
d0e0: 67 72 65 67 61 74 65 20 2a 2f 0a 23 64 65 66 69 gregate */.#defi
d0f0: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 ne SQLITE_FUNC_C
d100: 4f 41 4c 45 53 43 45 20 30 78 30 32 30 30 20 2f OALESCE 0x0200 /
d110: 2a 20 42 75 69 6c 74 2d 69 6e 20 63 6f 61 6c 65 * Built-in coale
d120: 73 63 65 28 29 20 6f 72 20 69 66 6e 75 6c 6c 28 sce() or ifnull(
d130: 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ) */.#define SQL
d140: 49 54 45 5f 46 55 4e 43 5f 55 4e 4c 49 4b 45 4c ITE_FUNC_UNLIKEL
d150: 59 20 30 78 30 34 30 30 20 2f 2a 20 42 75 69 6c Y 0x0400 /* Buil
d160: 74 2d 69 6e 20 75 6e 6c 69 6b 65 6c 79 28 29 20 t-in unlikely()
d170: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 function */.#def
d180: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
d190: 43 4f 4e 53 54 41 4e 54 20 30 78 30 38 30 30 20 CONSTANT 0x0800
d1a0: 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 69 6e 70 75 /* Constant inpu
d1b0: 74 73 20 67 69 76 65 20 61 20 63 6f 6e 73 74 61 ts give a consta
d1c0: 6e 74 20 6f 75 74 70 75 74 20 2a 2f 0a 23 64 65 nt output */.#de
d1d0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 fine SQLITE_FUNC
d1e0: 5f 4d 49 4e 4d 41 58 20 20 20 30 78 31 30 30 30 _MINMAX 0x1000
d1f0: 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 6d 69 6e /* True for min
d200: 28 29 20 61 6e 64 20 6d 61 78 28 29 20 61 67 67 () and max() agg
d210: 72 65 67 61 74 65 73 20 2a 2f 0a 23 64 65 66 69 regates */.#defi
d220: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 ne SQLITE_FUNC_S
d230: 4c 4f 43 48 4e 47 20 20 30 78 32 30 30 30 20 2f LOCHNG 0x2000 /
d240: 2a 20 22 53 6c 6f 77 20 43 68 61 6e 67 65 22 2e * "Slow Change".
d250: 20 56 61 6c 75 65 20 63 6f 6e 73 74 61 6e 74 20 Value constant
d260: 64 75 72 69 6e 67 20 61 0a 20 20 20 20 20 20 20 during a.
d270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d280: 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
d290: 73 69 6e 67 6c 65 20 71 75 65 72 79 20 2d 20 6d single query - m
d2a0: 69 67 68 74 20 63 68 61 6e 67 65 20 6f 76 65 72 ight change over
d2b0: 20 74 69 6d 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 time */../*.**
d2c0: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 The following th
d2d0: 72 65 65 20 6d 61 63 72 6f 73 2c 20 46 55 4e 43 ree macros, FUNC
d2e0: 54 49 4f 4e 28 29 2c 20 4c 49 4b 45 46 55 4e 43 TION(), LIKEFUNC
d2f0: 28 29 20 61 6e 64 20 41 47 47 52 45 47 41 54 45 () and AGGREGATE
d300: 28 29 20 61 72 65 0a 2a 2a 20 75 73 65 64 20 74 () are.** used t
d310: 6f 20 63 72 65 61 74 65 20 74 68 65 20 69 6e 69 o create the ini
d320: 74 69 61 6c 69 7a 65 72 73 20 66 6f 72 20 74 68 tializers for th
d330: 65 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 74 e FuncDef struct
d340: 75 72 65 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 46 55 ures..**.** FU
d350: 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 NCTION(zName, nA
d360: 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 rg, iArg, bNC, x
d370: 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 55 73 65 Func).** Use
d380: 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 d to create a sc
d390: 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 alar function de
d3a0: 66 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 finition of a fu
d3b0: 6e 63 74 69 6f 6e 20 7a 4e 61 6d 65 20 0a 2a 2a nction zName .**
d3c0: 20 20 20 20 20 69 6d 70 6c 65 6d 65 6e 74 65 64 implemented
d3d0: 20 62 79 20 43 20 66 75 6e 63 74 69 6f 6e 20 78 by C function x
d3e0: 46 75 6e 63 20 74 68 61 74 20 61 63 63 65 70 74 Func that accept
d3f0: 73 20 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 s nArg arguments
d400: 2e 20 54 68 65 0a 2a 2a 20 20 20 20 20 76 61 6c . The.** val
d410: 75 65 20 70 61 73 73 65 64 20 61 73 20 69 41 72 ue passed as iAr
d420: 67 20 69 73 20 63 61 73 74 20 74 6f 20 61 20 28 g is cast to a (
d430: 76 6f 69 64 2a 29 20 61 6e 64 20 6d 61 64 65 20 void*) and made
d440: 61 76 61 69 6c 61 62 6c 65 0a 2a 2a 20 20 20 20 available.**
d450: 20 61 73 20 74 68 65 20 75 73 65 72 2d 64 61 74 as the user-dat
d460: 61 20 28 73 71 6c 69 74 65 33 5f 75 73 65 72 5f a (sqlite3_user_
d470: 64 61 74 61 28 29 29 20 66 6f 72 20 74 68 65 20 data()) for the
d480: 66 75 6e 63 74 69 6f 6e 2e 20 49 66 20 0a 2a 2a function. If .**
d490: 20 20 20 20 20 61 72 67 75 6d 65 6e 74 20 62 4e argument bN
d4a0: 43 20 69 73 20 74 72 75 65 2c 20 74 68 65 6e 20 C is true, then
d4b0: 74 68 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f the SQLITE_FUNC_
d4c0: 4e 45 45 44 43 4f 4c 4c 20 66 6c 61 67 20 69 73 NEEDCOLL flag is
d4d0: 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 56 46 set..**.** VF
d4e0: 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e UNCTION(zName, n
d4f0: 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 Arg, iArg, bNC,
d500: 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 4c 69 xFunc).** Li
d510: 6b 65 20 46 55 4e 43 54 49 4f 4e 20 65 78 63 65 ke FUNCTION exce
d520: 70 74 20 69 74 20 6f 6d 69 74 73 20 74 68 65 20 pt it omits the
d530: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 SQLITE_FUNC_CONS
d540: 54 41 4e 54 20 66 6c 61 67 2e 0a 2a 2a 0a 2a 2a TANT flag..**.**
d550: 20 20 20 44 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 DFUNCTION(zNa
d560: 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 me, nArg, iArg,
d570: 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 bNC, xFunc).**
d580: 20 20 20 4c 69 6b 65 20 46 55 4e 43 54 49 4f 4e Like FUNCTION
d590: 20 65 78 63 65 70 74 20 69 74 20 6f 6d 69 74 73 except it omits
d5a0: 20 74 68 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 the SQLITE_FUNC
d5b0: 5f 43 4f 4e 53 54 41 4e 54 20 66 6c 61 67 20 61 _CONSTANT flag a
d5c0: 6e 64 0a 2a 2a 20 20 20 20 20 61 64 64 73 20 74 nd.** adds t
d5d0: 68 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 he SQLITE_FUNC_S
d5e0: 4c 4f 43 48 4e 47 20 66 6c 61 67 2e 20 20 55 73 LOCHNG flag. Us
d5f0: 65 64 20 66 6f 72 20 64 61 74 65 20 26 20 74 69 ed for date & ti
d600: 6d 65 20 66 75 6e 63 74 69 6f 6e 73 0a 2a 2a 20 me functions.**
d610: 20 20 20 20 61 6e 64 20 66 75 6e 63 74 69 6f 6e and function
d620: 73 20 6c 69 6b 65 20 73 71 6c 69 74 65 5f 76 65 s like sqlite_ve
d630: 72 73 69 6f 6e 28 29 20 74 68 61 74 20 63 61 6e rsion() that can
d640: 20 63 68 61 6e 67 65 2c 20 62 75 74 20 6e 6f 74 change, but not
d650: 20 64 75 72 69 6e 67 0a 2a 2a 20 20 20 20 20 61 during.** a
d660: 20 73 69 6e 67 6c 65 20 71 75 65 72 79 2e 0a 2a single query..*
d670: 2a 0a 2a 2a 20 20 20 41 47 47 52 45 47 41 54 45 *.** AGGREGATE
d680: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
d690: 72 67 2c 20 62 4e 43 2c 20 78 53 74 65 70 2c 20 rg, bNC, xStep,
d6a0: 78 46 69 6e 61 6c 29 0a 2a 2a 20 20 20 20 20 55 xFinal).** U
d6b0: 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 6e sed to create an
d6c0: 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 aggregate funct
d6d0: 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 ion definition i
d6e0: 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 0a 2a 2a mplemented by.**
d6f0: 20 20 20 20 20 74 68 65 20 43 20 66 75 6e 63 74 the C funct
d700: 69 6f 6e 73 20 78 53 74 65 70 20 61 6e 64 20 78 ions xStep and x
d710: 46 69 6e 61 6c 2e 20 54 68 65 20 66 69 72 73 74 Final. The first
d720: 20 66 6f 75 72 20 70 61 72 61 6d 65 74 65 72 73 four parameters
d730: 0a 2a 2a 20 20 20 20 20 61 72 65 20 69 6e 74 65 .** are inte
d740: 72 70 72 65 74 65 64 20 69 6e 20 74 68 65 20 73 rpreted in the s
d750: 61 6d 65 20 77 61 79 20 61 73 20 74 68 65 20 66 ame way as the f
d760: 69 72 73 74 20 34 20 70 61 72 61 6d 65 74 65 72 irst 4 parameter
d770: 73 20 74 6f 0a 2a 2a 20 20 20 20 20 46 55 4e 43 s to.** FUNC
d780: 54 49 4f 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 TION()..**.**
d790: 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 LIKEFUNC(zName,
d7a0: 6e 41 72 67 2c 20 70 41 72 67 2c 20 66 6c 61 67 nArg, pArg, flag
d7b0: 73 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 20 74 s).** Used t
d7c0: 6f 20 63 72 65 61 74 65 20 61 20 73 63 61 6c 61 o create a scala
d7d0: 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e r function defin
d7e0: 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e 63 74 ition of a funct
d7f0: 69 6f 6e 20 7a 4e 61 6d 65 20 0a 2a 2a 20 20 20 ion zName .**
d800: 20 20 74 68 61 74 20 61 63 63 65 70 74 73 20 6e that accepts n
d810: 41 72 67 20 61 72 67 75 6d 65 6e 74 73 20 61 6e Arg arguments an
d820: 64 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 d is implemented
d830: 20 62 79 20 61 20 63 61 6c 6c 20 74 6f 20 43 20 by a call to C
d840: 0a 2a 2a 20 20 20 20 20 66 75 6e 63 74 69 6f 6e .** function
d850: 20 6c 69 6b 65 46 75 6e 63 2e 20 41 72 67 75 6d likeFunc. Argum
d860: 65 6e 74 20 70 41 72 67 20 69 73 20 63 61 73 74 ent pArg is cast
d870: 20 74 6f 20 61 20 28 76 6f 69 64 20 2a 29 20 61 to a (void *) a
d880: 6e 64 20 6d 61 64 65 0a 2a 2a 20 20 20 20 20 61 nd made.** a
d890: 76 61 69 6c 61 62 6c 65 20 61 73 20 74 68 65 20 vailable as the
d8a0: 66 75 6e 63 74 69 6f 6e 20 75 73 65 72 2d 64 61 function user-da
d8b0: 74 61 20 28 73 71 6c 69 74 65 33 5f 75 73 65 72 ta (sqlite3_user
d8c0: 5f 64 61 74 61 28 29 29 2e 20 54 68 65 0a 2a 2a _data()). The.**
d8d0: 20 20 20 20 20 46 75 6e 63 44 65 66 2e 66 6c 61 FuncDef.fla
d8e0: 67 73 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 gs variable is s
d8f0: 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 et to the value
d900: 70 61 73 73 65 64 20 61 73 20 74 68 65 20 66 6c passed as the fl
d910: 61 67 73 0a 2a 2a 20 20 20 20 20 70 61 72 61 6d ags.** param
d920: 65 74 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 eter..*/.#define
d930: 20 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c FUNCTION(zName,
d940: 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 nArg, iArg, bNC
d950: 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 , xFunc) \. {nA
d960: 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f rg, SQLITE_FUNC_
d970: 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f CONSTANT|SQLITE_
d980: 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 UTF8|(bNC*SQLITE
d990: 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c _FUNC_NEEDCOLL),
d9a0: 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 \. SQLITE_INT
d9b0: 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 _TO_PTR(iArg), 0
d9c0: 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 , xFunc, 0, 0, #
d9d0: 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 zName, 0, 0}.#de
d9e0: 66 69 6e 65 20 56 46 55 4e 43 54 49 4f 4e 28 7a fine VFUNCTION(z
d9f0: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 Name, nArg, iArg
da00: 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a , bNC, xFunc) \.
da10: 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
da20: 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 UTF8|(bNC*SQLITE
da30: 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c _FUNC_NEEDCOLL),
da40: 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 \. SQLITE_INT
da50: 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 _TO_PTR(iArg), 0
da60: 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 , xFunc, 0, 0, #
da70: 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 zName, 0, 0}.#de
da80: 66 69 6e 65 20 44 46 55 4e 43 54 49 4f 4e 28 7a fine DFUNCTION(z
da90: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 Name, nArg, iArg
daa0: 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a , bNC, xFunc) \.
dab0: 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
dac0: 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c FUNC_SLOCHNG|SQL
dad0: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
dae0: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
daf0: 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 LL), \. SQLITE
db00: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 _INT_TO_PTR(iArg
db10: 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 ), 0, xFunc, 0,
db20: 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0, #zName, 0, 0}
db30: 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f .#define FUNCTIO
db40: 4e 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 N2(zName, nArg,
db50: 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 iArg, bNC, xFunc
db60: 2c 20 65 78 74 72 61 46 6c 61 67 73 29 20 5c 0a , extraFlags) \.
db70: 20 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f 46 {nArg,SQLITE_F
db80: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c UNC_CONSTANT|SQL
db90: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
dba0: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
dbb0: 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 5c LL)|extraFlags,\
dbc0: 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 . SQLITE_INT_T
dbd0: 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 O_PTR(iArg), 0,
dbe0: 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e xFunc, 0, 0, #zN
dbf0: 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 ame, 0, 0}.#defi
dc00: 6e 65 20 53 54 52 5f 46 55 4e 43 54 49 4f 4e 28 ne STR_FUNCTION(
dc10: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 zName, nArg, pAr
dc20: 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c g, bNC, xFunc) \
dc30: 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 . {nArg, SQLITE
dc40: 5f 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 _FUNC_SLOCHNG|SQ
dc50: 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 LITE_UTF8|(bNC*S
dc60: 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
dc70: 4f 4c 4c 29 2c 20 5c 0a 20 20 20 70 41 72 67 2c OLL), \. pArg,
dc80: 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 0, xFunc, 0, 0,
dc90: 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 #zName, 0, 0}.#
dca0: 64 65 66 69 6e 65 20 4c 49 4b 45 46 55 4e 43 28 define LIKEFUNC(
dcb0: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 67 zName, nArg, arg
dcc0: 2c 20 66 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 , flags) \. {nA
dcd0: 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f rg, SQLITE_FUNC_
dce0: 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f CONSTANT|SQLITE_
dcf0: 55 54 46 38 7c 66 6c 61 67 73 2c 20 5c 0a 20 20 UTF8|flags, \.
dd00: 20 28 76 6f 69 64 20 2a 29 61 72 67 2c 20 30 2c (void *)arg, 0,
dd10: 20 6c 69 6b 65 46 75 6e 63 2c 20 30 2c 20 30 2c likeFunc, 0, 0,
dd20: 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 #zName, 0, 0}.#
dd30: 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 54 45 define AGGREGATE
dd40: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 (zName, nArg, ar
dd50: 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 78 46 g, nc, xStep, xF
dd60: 69 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 67 2c inal) \. {nArg,
dd70: 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 6e 63 SQLITE_UTF8|(nc
dd80: 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 *SQLITE_FUNC_NEE
dd90: 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c DCOLL), \. SQL
dda0: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 ITE_INT_TO_PTR(a
ddb0: 72 67 29 2c 20 30 2c 20 30 2c 20 78 53 74 65 70 rg), 0, 0, xStep
ddc0: 2c 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 30 ,xFinal,#zName,0
ddd0: 2c 30 7d 0a 23 64 65 66 69 6e 65 20 41 47 47 52 ,0}.#define AGGR
dde0: 45 47 41 54 45 32 28 7a 4e 61 6d 65 2c 20 6e 41 EGATE2(zName, nA
ddf0: 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 rg, arg, nc, xSt
de00: 65 70 2c 20 78 46 69 6e 61 6c 2c 20 65 78 74 72 ep, xFinal, extr
de10: 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 aFlags) \. {nAr
de20: 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
de30: 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
de40: 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 61 46 6c EEDCOLL)|extraFl
de50: 61 67 73 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 ags, \. SQLITE
de60: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 _INT_TO_PTR(arg)
de70: 2c 20 30 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 , 0, 0, xStep,xF
de80: 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 30 2c 30 7d inal,#zName,0,0}
de90: 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 72 72 ../*.** All curr
dea0: 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 73 20 61 ent savepoints a
deb0: 72 65 20 73 74 6f 72 65 64 20 69 6e 20 61 20 6c re stored in a l
dec0: 69 6e 6b 65 64 20 6c 69 73 74 20 73 74 61 72 74 inked list start
ded0: 69 6e 67 20 61 74 0a 2a 2a 20 73 71 6c 69 74 65 ing at.** sqlite
dee0: 33 2e 70 53 61 76 65 70 6f 69 6e 74 2e 20 54 68 3.pSavepoint. Th
def0: 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 e first element
df00: 69 6e 20 74 68 65 20 6c 69 73 74 20 69 73 20 74 in the list is t
df10: 68 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 6c 79 he most recently
df20: 0a 2a 2a 20 6f 70 65 6e 65 64 20 73 61 76 65 70 .** opened savep
df30: 6f 69 6e 74 2e 20 53 61 76 65 70 6f 69 6e 74 73 oint. Savepoints
df40: 20 61 72 65 20 61 64 64 65 64 20 74 6f 20 74 68 are added to th
df50: 65 20 6c 69 73 74 20 62 79 20 74 68 65 20 76 64 e list by the vd
df60: 62 65 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 6f 69 be.** OP_Savepoi
df70: 6e 74 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a nt instruction..
df80: 2a 2f 0a 73 74 72 75 63 74 20 53 61 76 65 70 6f */.struct Savepo
df90: 69 6e 74 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e int {. char *zN
dfa0: 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
dfb0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
dfc0: 61 76 65 70 6f 69 6e 74 20 6e 61 6d 65 20 28 6e avepoint name (n
dfd0: 75 6c 2d 74 65 72 6d 69 6e 61 74 65 64 29 20 2a ul-terminated) *
dfe0: 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 /. i64 nDeferre
dff0: 64 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 dCons;
e000: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
e010: 72 20 6f 66 20 64 65 66 65 72 72 65 64 20 66 6b r of deferred fk
e020: 20 76 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f 0a 20 violations */.
e030: 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d i64 nDeferredIm
e040: 6d 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 mCons;
e050: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
e060: 66 20 64 65 66 65 72 72 65 64 20 69 6d 6d 20 66 f deferred imm f
e070: 6b 2e 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e k. */. Savepoin
e080: 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 t *pNext;
e090: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
e0a0: 61 72 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 20 arent savepoint
e0b0: 28 69 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b 0a 0a (if any) */.};..
e0c0: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
e0d0: 69 6e 67 20 61 72 65 20 75 73 65 64 20 61 73 20 ing are used as
e0e0: 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 61 6d the second param
e0f0: 65 74 65 72 20 74 6f 20 73 71 6c 69 74 65 33 53 eter to sqlite3S
e100: 61 76 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 20 61 avepoint(),.** a
e110: 6e 64 20 61 73 20 74 68 65 20 50 31 20 61 72 67 nd as the P1 arg
e120: 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 4f 50 5f ument to the OP_
e130: 53 61 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 75 Savepoint instru
e140: 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e ction..*/.#defin
e150: 65 20 53 41 56 45 50 4f 49 4e 54 5f 42 45 47 49 e SAVEPOINT_BEGI
e160: 4e 20 20 20 20 20 20 30 0a 23 64 65 66 69 6e 65 N 0.#define
e170: 20 53 41 56 45 50 4f 49 4e 54 5f 52 45 4c 45 41 SAVEPOINT_RELEA
e180: 53 45 20 20 20 20 31 0a 23 64 65 66 69 6e 65 20 SE 1.#define
e190: 53 41 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c 42 41 SAVEPOINT_ROLLBA
e1a0: 43 4b 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a 20 45 CK 2.../*.** E
e1b0: 61 63 68 20 53 51 4c 69 74 65 20 6d 6f 64 75 6c ach SQLite modul
e1c0: 65 20 28 76 69 72 74 75 61 6c 20 74 61 62 6c 65 e (virtual table
e1d0: 20 64 65 66 69 6e 69 74 69 6f 6e 29 20 69 73 20 definition) is
e1e0: 64 65 66 69 6e 65 64 20 62 79 20 61 6e 0a 2a 2a defined by an.**
e1f0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
e200: 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
e210: 74 75 72 65 2c 20 73 74 6f 72 65 64 20 69 6e 20 ture, stored in
e220: 74 68 65 20 73 71 6c 69 74 65 33 2e 61 4d 6f 64 the sqlite3.aMod
e230: 75 6c 65 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c ule.** hash tabl
e240: 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4d 6f 64 e..*/.struct Mod
e250: 75 6c 65 20 7b 0a 20 20 63 6f 6e 73 74 20 73 71 ule {. const sq
e260: 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 20 2a 70 4d lite3_module *pM
e270: 6f 64 75 6c 65 3b 20 20 20 20 20 20 20 2f 2a 20 odule; /*
e280: 43 61 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 65 72 Callback pointer
e290: 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 s */. const cha
e2a0: 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 r *zName;
e2b0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
e2c0: 61 6d 65 20 70 61 73 73 65 64 20 74 6f 20 63 72 ame passed to cr
e2d0: 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f eate_module() */
e2e0: 0a 20 20 76 6f 69 64 20 2a 70 41 75 78 3b 20 20 . void *pAux;
e2f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
e300: 20 20 20 20 20 20 20 20 2f 2a 20 70 41 75 78 20 /* pAux
e310: 70 61 73 73 65 64 20 74 6f 20 63 72 65 61 74 65 passed to create
e320: 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 76 _module() */. v
e330: 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 oid (*xDestroy)(
e340: 76 6f 69 64 20 2a 29 3b 20 20 20 20 20 20 20 20 void *);
e350: 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 64 65 /* Module de
e360: 73 74 72 75 63 74 6f 72 20 66 75 6e 63 74 69 6f structor functio
e370: 6e 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 45 n */. Table *pE
e380: 70 6f 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 poTab;
e390: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 /* E
e3a0: 70 6f 6e 79 6d 6f 75 73 20 74 61 62 6c 65 20 66 ponymous table f
e3b0: 6f 72 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 2a or this module *
e3c0: 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e 66 6f /.};../*.** info
e3d0: 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 rmation about ea
e3e0: 63 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 6e 20 ch column of an
e3f0: 53 51 4c 20 74 61 62 6c 65 20 69 73 20 68 65 6c SQL table is hel
e400: 64 20 69 6e 20 61 6e 20 69 6e 73 74 61 6e 63 65 d in an instance
e410: 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 .** of this stru
e420: 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 cture..*/.struct
e430: 20 43 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 61 72 Column {. char
e440: 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 2f 2a 20 *zName; /*
e450: 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 63 6f 6c Name of this col
e460: 75 6d 6e 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 umn */. Expr *p
e470: 44 66 6c 74 3b 20 20 20 20 20 2f 2a 20 44 65 66 Dflt; /* Def
e480: 61 75 6c 74 20 76 61 6c 75 65 20 6f 66 20 74 68 ault value of th
e490: 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 63 is column */. c
e4a0: 68 61 72 20 2a 7a 44 66 6c 74 3b 20 20 20 20 20 har *zDflt;
e4b0: 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 74 65 78 74 /* Original text
e4c0: 20 6f 66 20 74 68 65 20 64 65 66 61 75 6c 74 20 of the default
e4d0: 76 61 6c 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 value */. char
e4e0: 2a 7a 54 79 70 65 3b 20 20 20 20 20 2f 2a 20 44 *zType; /* D
e4f0: 61 74 61 20 74 79 70 65 20 66 6f 72 20 74 68 69 ata type for thi
e500: 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 63 68 s column */. ch
e510: 61 72 20 2a 7a 43 6f 6c 6c 3b 20 20 20 20 20 2f ar *zColl; /
e520: 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 * Collating sequ
e530: 65 6e 63 65 2e 20 20 49 66 20 4e 55 4c 4c 2c 20 ence. If NULL,
e540: 75 73 65 20 74 68 65 20 64 65 66 61 75 6c 74 20 use the default
e550: 2a 2f 0a 20 20 75 38 20 6e 6f 74 4e 75 6c 6c 3b */. u8 notNull;
e560: 20 20 20 20 20 20 2f 2a 20 41 6e 20 4f 45 5f 20 /* An OE_
e570: 63 6f 64 65 20 66 6f 72 20 68 61 6e 64 6c 69 6e code for handlin
e580: 67 20 61 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e g a NOT NULL con
e590: 73 74 72 61 69 6e 74 20 2a 2f 0a 20 20 63 68 61 straint */. cha
e5a0: 72 20 61 66 66 69 6e 69 74 79 3b 20 20 20 2f 2a r affinity; /*
e5b0: 20 4f 6e 65 20 6f 66 20 74 68 65 20 53 51 4c 49 One of the SQLI
e5c0: 54 45 5f 41 46 46 5f 2e 2e 2e 20 76 61 6c 75 65 TE_AFF_... value
e5d0: 73 20 2a 2f 0a 20 20 75 38 20 73 7a 45 73 74 3b s */. u8 szEst;
e5e0: 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 69 6d /* Estim
e5f0: 61 74 65 64 20 73 69 7a 65 20 6f 66 20 74 68 69 ated size of thi
e600: 73 20 63 6f 6c 75 6d 6e 2e 20 20 49 4e 54 3d 3d s column. INT==
e610: 31 20 2a 2f 0a 20 20 75 38 20 63 6f 6c 46 6c 61 1 */. u8 colFla
e620: 67 73 3b 20 20 20 20 20 2f 2a 20 42 6f 6f 6c 65 gs; /* Boole
e630: 61 6e 20 70 72 6f 70 65 72 74 69 65 73 2e 20 20 an properties.
e640: 53 65 65 20 43 4f 4c 46 4c 41 47 5f 20 64 65 66 See COLFLAG_ def
e650: 69 6e 65 73 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b ines below */.};
e660: 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c ../* Allowed val
e670: 75 65 73 20 66 6f 72 20 43 6f 6c 75 6d 6e 2e 63 ues for Column.c
e680: 6f 6c 46 6c 61 67 73 3a 0a 2a 2f 0a 23 64 65 66 olFlags:.*/.#def
e690: 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 50 52 49 4d ine COLFLAG_PRIM
e6a0: 4b 45 59 20 20 30 78 30 30 30 31 20 20 20 20 2f KEY 0x0001 /
e6b0: 2a 20 43 6f 6c 75 6d 6e 20 69 73 20 70 61 72 74 * Column is part
e6c0: 20 6f 66 20 74 68 65 20 70 72 69 6d 61 72 79 20 of the primary
e6d0: 6b 65 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 key */.#define C
e6e0: 4f 4c 46 4c 41 47 5f 48 49 44 44 45 4e 20 20 20 OLFLAG_HIDDEN
e6f0: 30 78 30 30 30 32 20 20 20 20 2f 2a 20 41 20 68 0x0002 /* A h
e700: 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 20 69 6e 20 idden column in
e710: 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 a virtual table
e720: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 22 43 6f 6c */../*.** A "Col
e730: 6c 61 74 69 6e 67 20 53 65 71 75 65 6e 63 65 22 lating Sequence"
e740: 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 is defined by a
e750: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
e760: 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 e following.** s
e770: 74 72 75 63 74 75 72 65 2e 20 43 6f 6e 63 65 70 tructure. Concep
e780: 74 75 61 6c 6c 79 2c 20 61 20 63 6f 6c 6c 61 74 tually, a collat
e790: 69 6e 67 20 73 65 71 75 65 6e 63 65 20 63 6f 6e ing sequence con
e7a0: 73 69 73 74 73 20 6f 66 20 61 20 6e 61 6d 65 20 sists of a name
e7b0: 61 6e 64 0a 2a 2a 20 61 20 63 6f 6d 70 61 72 69 and.** a compari
e7c0: 73 6f 6e 20 72 6f 75 74 69 6e 65 20 74 68 61 74 son routine that
e7d0: 20 64 65 66 69 6e 65 73 20 74 68 65 20 6f 72 64 defines the ord
e7e0: 65 72 20 6f 66 20 74 68 61 74 20 73 65 71 75 65 er of that seque
e7f0: 6e 63 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 43 6f nce..**.** If Co
e800: 6c 6c 53 65 71 2e 78 43 6d 70 20 69 73 20 4e 55 llSeq.xCmp is NU
e810: 4c 4c 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 61 LL, it means tha
e820: 74 20 74 68 65 0a 2a 2a 20 63 6f 6c 6c 61 74 69 t the.** collati
e830: 6e 67 20 73 65 71 75 65 6e 63 65 20 69 73 20 75 ng sequence is u
e840: 6e 64 65 66 69 6e 65 64 2e 20 20 49 6e 64 69 63 ndefined. Indic
e850: 65 73 20 62 75 69 6c 74 20 6f 6e 20 61 6e 20 75 es built on an u
e860: 6e 64 65 66 69 6e 65 64 0a 2a 2a 20 63 6f 6c 6c ndefined.** coll
e870: 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 6d ating sequence m
e880: 61 79 20 6e 6f 74 20 62 65 20 72 65 61 64 20 6f ay not be read o
e890: 72 20 77 72 69 74 74 65 6e 2e 0a 2a 2f 0a 73 74 r written..*/.st
e8a0: 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 7b 0a 20 ruct CollSeq {.
e8b0: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 char *zName;
e8c0: 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
e8d0: 66 20 74 68 65 20 63 6f 6c 6c 61 74 69 6e 67 20 f the collating
e8e0: 73 65 71 75 65 6e 63 65 2c 20 55 54 46 2d 38 20 sequence, UTF-8
e8f0: 65 6e 63 6f 64 65 64 20 2a 2f 0a 20 20 75 38 20 encoded */. u8
e900: 65 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 enc;
e910: 20 20 20 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 /* Text encod
e920: 69 6e 67 20 68 61 6e 64 6c 65 64 20 62 79 20 78 ing handled by x
e930: 43 6d 70 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 Cmp() */. void
e940: 2a 70 55 73 65 72 3b 20 20 20 20 20 20 20 20 20 *pUser;
e950: 20 2f 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 /* First argume
e960: 6e 74 20 74 6f 20 78 43 6d 70 28 29 20 2a 2f 0a nt to xCmp() */.
e970: 20 20 69 6e 74 20 28 2a 78 43 6d 70 29 28 76 6f int (*xCmp)(vo
e980: 69 64 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 76 id*,int, const v
e990: 6f 69 64 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 oid*, int, const
e9a0: 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 64 20 void*);. void
e9b0: 28 2a 78 44 65 6c 29 28 76 6f 69 64 2a 29 3b 20 (*xDel)(void*);
e9c0: 20 2f 2a 20 44 65 73 74 72 75 63 74 6f 72 20 66 /* Destructor f
e9d0: 6f 72 20 70 55 73 65 72 20 2a 2f 0a 7d 3b 0a 0a or pUser */.};..
e9e0: 2f 2a 0a 2a 2a 20 41 20 73 6f 72 74 20 6f 72 64 /*.** A sort ord
e9f0: 65 72 20 63 61 6e 20 62 65 20 65 69 74 68 65 72 er can be either
ea00: 20 41 53 43 20 6f 72 20 44 45 53 43 2e 0a 2a 2f ASC or DESC..*/
ea10: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ea20: 53 4f 5f 41 53 43 20 20 20 20 20 20 20 30 20 20 SO_ASC 0
ea30: 2f 2a 20 53 6f 72 74 20 69 6e 20 61 73 63 65 6e /* Sort in ascen
ea40: 64 69 6e 67 20 6f 72 64 65 72 20 2a 2f 0a 23 64 ding order */.#d
ea50: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f efine SQLITE_SO_
ea60: 44 45 53 43 20 20 20 20 20 20 31 20 20 2f 2a 20 DESC 1 /*
ea70: 53 6f 72 74 20 69 6e 20 61 73 63 65 6e 64 69 6e Sort in ascendin
ea80: 67 20 6f 72 64 65 72 20 2a 2f 0a 23 64 65 66 69 g order */.#defi
ea90: 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f 55 4e 44 ne SQLITE_SO_UND
eaa0: 45 46 49 4e 45 44 20 2d 31 20 2f 2a 20 4e 6f 20 EFINED -1 /* No
eab0: 73 6f 72 74 20 6f 72 64 65 72 20 73 70 65 63 69 sort order speci
eac0: 66 69 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 43 fied */../*.** C
ead0: 6f 6c 75 6d 6e 20 61 66 66 69 6e 69 74 79 20 74 olumn affinity t
eae0: 79 70 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 73 ypes..**.** Thes
eaf0: 65 20 75 73 65 64 20 74 6f 20 68 61 76 65 20 6d e used to have m
eb00: 6e 65 6d 6f 6e 69 63 20 6e 61 6d 65 20 6c 69 6b nemonic name lik
eb10: 65 20 27 69 27 20 66 6f 72 20 53 51 4c 49 54 45 e 'i' for SQLITE
eb20: 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 61 6e 64 _AFF_INTEGER and
eb30: 0a 2a 2a 20 27 74 27 20 66 6f 72 20 53 51 4c 49 .** 't' for SQLI
eb40: 54 45 5f 41 46 46 5f 54 45 58 54 2e 20 20 42 75 TE_AFF_TEXT. Bu
eb50: 74 20 77 65 20 63 61 6e 20 73 61 76 65 20 61 20 t we can save a
eb60: 6c 69 74 74 6c 65 20 73 70 61 63 65 20 61 6e 64 little space and
eb70: 20 69 6d 70 72 6f 76 65 0a 2a 2a 20 74 68 65 20 improve.** the
eb80: 73 70 65 65 64 20 61 20 6c 69 74 74 6c 65 20 62 speed a little b
eb90: 79 20 6e 75 6d 62 65 72 69 6e 67 20 74 68 65 20 y numbering the
eba0: 76 61 6c 75 65 73 20 63 6f 6e 73 65 63 75 74 69 values consecuti
ebb0: 76 65 6c 79 2e 20 20 0a 2a 2a 0a 2a 2a 20 42 75 vely. .**.** Bu
ebc0: 74 20 72 61 74 68 65 72 20 74 68 61 6e 20 73 74 t rather than st
ebd0: 61 72 74 20 77 69 74 68 20 30 20 6f 72 20 31 2c art with 0 or 1,
ebe0: 20 77 65 20 62 65 67 69 6e 20 77 69 74 68 20 27 we begin with '
ebf0: 41 27 2e 20 20 54 68 61 74 20 77 61 79 2c 0a 2a A'. That way,.*
ec00: 2a 20 77 68 65 6e 20 6d 75 6c 74 69 70 6c 65 20 * when multiple
ec10: 61 66 66 69 6e 69 74 79 20 74 79 70 65 73 20 61 affinity types a
ec20: 72 65 20 63 6f 6e 63 61 74 65 6e 61 74 65 64 20 re concatenated
ec30: 69 6e 74 6f 20 61 20 73 74 72 69 6e 67 20 61 6e into a string an
ec40: 64 0a 2a 2a 20 75 73 65 64 20 61 73 20 74 68 65 d.** used as the
ec50: 20 50 34 20 6f 70 65 72 61 6e 64 2c 20 74 68 65 P4 operand, the
ec60: 79 20 77 69 6c 6c 20 62 65 20 6d 6f 72 65 20 72 y will be more r
ec70: 65 61 64 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 4e eadable..**.** N
ec80: 6f 74 65 20 61 6c 73 6f 20 74 68 61 74 20 74 68 ote also that th
ec90: 65 20 6e 75 6d 65 72 69 63 20 74 79 70 65 73 20 e numeric types
eca0: 61 72 65 20 67 72 6f 75 70 65 64 20 74 6f 67 65 are grouped toge
ecb0: 74 68 65 72 20 73 6f 20 74 68 61 74 20 74 65 73 ther so that tes
ecc0: 74 69 6e 67 0a 2a 2a 20 66 6f 72 20 61 20 6e 75 ting.** for a nu
ecd0: 6d 65 72 69 63 20 74 79 70 65 20 69 73 20 61 20 meric type is a
ece0: 73 69 6e 67 6c 65 20 63 6f 6d 70 61 72 69 73 6f single compariso
ecf0: 6e 2e 20 20 41 6e 64 20 74 68 65 20 42 4c 4f 42 n. And the BLOB
ed00: 20 74 79 70 65 20 69 73 20 66 69 72 73 74 2e 0a type is first..
ed10: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
ed20: 45 5f 41 46 46 5f 42 4c 4f 42 20 20 20 20 20 27 E_AFF_BLOB '
ed30: 41 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 A'.#define SQLIT
ed40: 45 5f 41 46 46 5f 54 45 58 54 20 20 20 20 20 27 E_AFF_TEXT '
ed50: 42 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 B'.#define SQLIT
ed60: 45 5f 41 46 46 5f 4e 55 4d 45 52 49 43 20 20 27 E_AFF_NUMERIC '
ed70: 43 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 C'.#define SQLIT
ed80: 45 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 20 27 E_AFF_INTEGER '
ed90: 44 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 D'.#define SQLIT
eda0: 45 5f 41 46 46 5f 52 45 41 4c 20 20 20 20 20 27 E_AFF_REAL '
edb0: 45 27 0a 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 E'..#define sqli
edc0: 74 65 33 49 73 4e 75 6d 65 72 69 63 41 66 66 69 te3IsNumericAffi
edd0: 6e 69 74 79 28 58 29 20 20 28 28 58 29 3e 3d 53 nity(X) ((X)>=S
ede0: 51 4c 49 54 45 5f 41 46 46 5f 4e 55 4d 45 52 49 QLITE_AFF_NUMERI
edf0: 43 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 C)../*.** The SQ
ee00: 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b 20 76 61 LITE_AFF_MASK va
ee10: 6c 75 65 73 20 6d 61 73 6b 73 20 6f 66 66 20 74 lues masks off t
ee20: 68 65 20 73 69 67 6e 69 66 69 63 61 6e 74 20 62 he significant b
ee30: 69 74 73 20 6f 66 20 61 6e 0a 2a 2a 20 61 66 66 its of an.** aff
ee40: 69 6e 69 74 79 20 76 61 6c 75 65 2e 20 0a 2a 2f inity value. .*/
ee50: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ee60: 41 46 46 5f 4d 41 53 4b 20 20 20 20 20 30 78 34 AFF_MASK 0x4
ee70: 37 0a 0a 2f 2a 0a 2a 2a 20 41 64 64 69 74 69 6f 7../*.** Additio
ee80: 6e 61 6c 20 62 69 74 20 76 61 6c 75 65 73 20 74 nal bit values t
ee90: 68 61 74 20 63 61 6e 20 62 65 20 4f 52 65 64 20 hat can be ORed
eea0: 77 69 74 68 20 61 6e 20 61 66 66 69 6e 69 74 79 with an affinity
eeb0: 20 77 69 74 68 6f 75 74 0a 2a 2a 20 63 68 61 6e without.** chan
eec0: 67 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 ging the affinit
eed0: 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 53 51 4c y..**.** The SQL
eee0: 49 54 45 5f 4e 4f 54 4e 55 4c 4c 20 66 6c 61 67 ITE_NOTNULL flag
eef0: 20 69 73 20 61 20 63 6f 6d 62 69 6e 61 74 69 6f is a combinatio
ef00: 6e 20 6f 66 20 4e 55 4c 4c 45 51 20 61 6e 64 20 n of NULLEQ and
ef10: 4a 55 4d 50 49 46 4e 55 4c 4c 2e 0a 2a 2a 20 49 JUMPIFNULL..** I
ef20: 74 20 63 61 75 73 65 73 20 61 6e 20 61 73 73 65 t causes an asse
ef30: 72 74 28 29 20 74 6f 20 66 69 72 65 20 69 66 20 rt() to fire if
ef40: 65 69 74 68 65 72 20 6f 70 65 72 61 6e 64 20 74 either operand t
ef50: 6f 20 61 20 63 6f 6d 70 61 72 69 73 6f 6e 0a 2a o a comparison.*
ef60: 2a 20 6f 70 65 72 61 74 6f 72 20 69 73 20 4e 55 * operator is NU
ef70: 4c 4c 2e 20 20 49 74 20 69 73 20 61 64 64 65 64 LL. It is added
ef80: 20 74 6f 20 63 65 72 74 61 69 6e 20 63 6f 6d 70 to certain comp
ef90: 61 72 69 73 6f 6e 20 6f 70 65 72 61 74 6f 72 73 arison operators
efa0: 20 74 6f 0a 2a 2a 20 70 72 6f 76 65 20 74 68 61 to.** prove tha
efb0: 74 20 74 68 65 20 6f 70 65 72 61 6e 64 73 20 61 t the operands a
efc0: 72 65 20 61 6c 77 61 79 73 20 4e 4f 54 20 4e 55 re always NOT NU
efd0: 4c 4c 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 LL..*/.#define S
efe0: 51 4c 49 54 45 5f 4a 55 4d 50 49 46 4e 55 4c 4c QLITE_JUMPIFNULL
eff0: 20 20 20 30 78 31 30 20 20 2f 2a 20 6a 75 6d 70 0x10 /* jump
f000: 73 20 69 66 20 65 69 74 68 65 72 20 6f 70 65 72 s if either oper
f010: 61 6e 64 20 69 73 20 4e 55 4c 4c 20 2a 2f 0a 23 and is NULL */.#
f020: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 54 define SQLITE_ST
f030: 4f 52 45 50 32 20 20 20 20 20 20 30 78 32 30 20 OREP2 0x20
f040: 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 /* Store result
f050: 20 69 6e 20 72 65 67 5b 50 32 5d 20 72 61 74 68 in reg[P2] rath
f060: 65 72 20 74 68 61 6e 20 6a 75 6d 70 20 2a 2f 0a er than jump */.
f070: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e #define SQLITE_N
f080: 55 4c 4c 45 51 20 20 20 20 20 20 20 30 78 38 30 ULLEQ 0x80
f090: 20 20 2f 2a 20 4e 55 4c 4c 3d 4e 55 4c 4c 20 2a /* NULL=NULL *
f0a0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
f0b0: 5f 4e 4f 54 4e 55 4c 4c 20 20 20 20 20 20 30 78 _NOTNULL 0x
f0c0: 39 30 20 20 2f 2a 20 41 73 73 65 72 74 20 74 68 90 /* Assert th
f0d0: 61 74 20 6f 70 65 72 61 6e 64 73 20 61 72 65 20 at operands are
f0e0: 6e 65 76 65 72 20 4e 55 4c 4c 20 2a 2f 0a 0a 2f never NULL */../
f0f0: 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 63 74 20 6f *.** An object o
f100: 66 20 74 68 69 73 20 74 79 70 65 20 69 73 20 63 f this type is c
f110: 72 65 61 74 65 64 20 66 6f 72 20 65 61 63 68 20 reated for each
f120: 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 70 72 virtual table pr
f130: 65 73 65 6e 74 20 69 6e 0a 2a 2a 20 74 68 65 20 esent in.** the
f140: 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 2e database schema.
f150: 20 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 64 .**.** If the d
f160: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 69 atabase schema i
f170: 73 20 73 68 61 72 65 64 2c 20 74 68 65 6e 20 74 s shared, then t
f180: 68 65 72 65 20 69 73 20 6f 6e 65 20 69 6e 73 74 here is one inst
f190: 61 6e 63 65 20 6f 66 20 74 68 69 73 0a 2a 2a 20 ance of this.**
f1a0: 73 74 72 75 63 74 75 72 65 20 66 6f 72 20 65 61 structure for ea
f1b0: 63 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e ch database conn
f1c0: 65 63 74 69 6f 6e 20 28 73 71 6c 69 74 65 33 2a ection (sqlite3*
f1d0: 29 20 74 68 61 74 20 75 73 65 73 20 74 68 65 20 ) that uses the
f1e0: 73 68 61 72 65 64 0a 2a 2a 20 73 63 68 65 6d 61 shared.** schema
f1f0: 2e 20 54 68 69 73 20 69 73 20 62 65 63 61 75 73 . This is becaus
f200: 65 20 65 61 63 68 20 64 61 74 61 62 61 73 65 20 e each database
f210: 63 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 71 75 69 connection requi
f220: 72 65 73 20 69 74 73 20 6f 77 6e 20 75 6e 69 71 res its own uniq
f230: 75 65 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f ue.** instance o
f240: 66 20 74 68 65 20 73 71 6c 69 74 65 33 5f 76 74 f the sqlite3_vt
f250: 61 62 2a 20 68 61 6e 64 6c 65 20 75 73 65 64 20 ab* handle used
f260: 74 6f 20 61 63 63 65 73 73 20 74 68 65 20 76 69 to access the vi
f270: 72 74 75 61 6c 20 74 61 62 6c 65 20 0a 2a 2a 20 rtual table .**
f280: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 implementation.
f290: 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 sqlite3_vtab* ha
f2a0: 6e 64 6c 65 73 20 63 61 6e 20 6e 6f 74 20 62 65 ndles can not be
f2b0: 20 73 68 61 72 65 64 20 62 65 74 77 65 65 6e 20 shared between
f2c0: 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 6f 6e .** database con
f2d0: 6e 65 63 74 69 6f 6e 73 2c 20 65 76 65 6e 20 77 nections, even w
f2e0: 68 65 6e 20 74 68 65 20 72 65 73 74 20 6f 66 20 hen the rest of
f2f0: 74 68 65 20 69 6e 2d 6d 65 6d 6f 72 79 20 64 61 the in-memory da
f300: 74 61 62 61 73 65 20 0a 2a 2a 20 73 63 68 65 6d tabase .** schem
f310: 61 20 69 73 20 73 68 61 72 65 64 2c 20 61 73 20 a is shared, as
f320: 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 the implementati
f330: 6f 6e 20 6f 66 74 65 6e 20 73 74 6f 72 65 73 20 on often stores
f340: 74 68 65 20 64 61 74 61 62 61 73 65 0a 2a 2a 20 the database.**
f350: 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c connection handl
f360: 65 20 70 61 73 73 65 64 20 74 6f 20 69 74 20 76 e passed to it v
f370: 69 61 20 74 68 65 20 78 43 6f 6e 6e 65 63 74 28 ia the xConnect(
f380: 29 20 6f 72 20 78 43 72 65 61 74 65 28 29 20 6d ) or xCreate() m
f390: 65 74 68 6f 64 0a 2a 2a 20 64 75 72 69 6e 67 20 ethod.** during
f3a0: 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 69 initialization i
f3b0: 6e 74 65 72 6e 61 6c 6c 79 2e 20 54 68 69 73 20 nternally. This
f3c0: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
f3d0: 69 6f 6e 20 68 61 6e 64 6c 65 20 6d 61 79 0a 2a ion handle may.*
f3e0: 2a 20 74 68 65 6e 20 62 65 20 75 73 65 64 20 62 * then be used b
f3f0: 79 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 y the virtual ta
f400: 62 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 ble implementati
f410: 6f 6e 20 74 6f 20 61 63 63 65 73 73 20 72 65 61 on to access rea
f420: 6c 20 74 61 62 6c 65 73 20 0a 2a 2a 20 77 69 74 l tables .** wit
f430: 68 69 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 hin the database
f440: 2e 20 53 6f 20 74 68 61 74 20 74 68 65 79 20 61 . So that they a
f450: 70 70 65 61 72 20 61 73 20 70 61 72 74 20 6f 66 ppear as part of
f460: 20 74 68 65 20 63 61 6c 6c 65 72 73 20 0a 2a 2a the callers .**
f470: 20 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 74 68 transaction, th
f480: 65 73 65 20 61 63 63 65 73 73 65 73 20 6e 65 65 ese accesses nee
f490: 64 20 74 6f 20 62 65 20 6d 61 64 65 20 76 69 61 d to be made via
f4a0: 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 62 61 the same databa
f4b0: 73 65 20 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f se .** connectio
f4c0: 6e 20 61 73 20 74 68 61 74 20 75 73 65 64 20 74 n as that used t
f4d0: 6f 20 65 78 65 63 75 74 65 20 53 51 4c 20 6f 70 o execute SQL op
f4e0: 65 72 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 20 erations on the
f4f0: 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0a 2a virtual table..*
f500: 2a 0a 2a 2a 20 41 6c 6c 20 56 54 61 62 6c 65 20 *.** All VTable
f510: 6f 62 6a 65 63 74 73 20 74 68 61 74 20 63 6f 72 objects that cor
f520: 72 65 73 70 6f 6e 64 20 74 6f 20 61 20 73 69 6e respond to a sin
f530: 67 6c 65 20 74 61 62 6c 65 20 69 6e 20 61 20 73 gle table in a s
f540: 68 61 72 65 64 0a 2a 2a 20 64 61 74 61 62 61 73 hared.** databas
f550: 65 20 73 63 68 65 6d 61 20 61 72 65 20 69 6e 69 e schema are ini
f560: 74 69 61 6c 6c 79 20 73 74 6f 72 65 64 20 69 6e tially stored in
f570: 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 70 a linked-list p
f580: 6f 69 6e 74 65 64 20 74 6f 20 62 79 0a 2a 2a 20 ointed to by.**
f590: 74 68 65 20 54 61 62 6c 65 2e 70 56 54 61 62 6c the Table.pVTabl
f5a0: 65 20 6d 65 6d 62 65 72 20 76 61 72 69 61 62 6c e member variabl
f5b0: 65 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 70 e of the corresp
f5c0: 6f 6e 64 69 6e 67 20 54 61 62 6c 65 20 6f 62 6a onding Table obj
f5d0: 65 63 74 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e 20 ect..** When an
f5e0: 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 28 sqlite3_prepare(
f5f0: 29 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 72 ) operation is r
f600: 65 71 75 69 72 65 64 20 74 6f 20 61 63 63 65 73 equired to acces
f610: 73 20 74 68 65 20 76 69 72 74 75 61 6c 0a 2a 2a s the virtual.**
f620: 20 74 61 62 6c 65 2c 20 69 74 20 73 65 61 72 63 table, it searc
f630: 68 65 73 20 74 68 65 20 6c 69 73 74 20 66 6f 72 hes the list for
f640: 20 74 68 65 20 56 54 61 62 6c 65 20 74 68 61 74 the VTable that
f650: 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 corresponds to
f660: 74 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 the.** database
f670: 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 6f 69 6e 67 connection doing
f680: 20 74 68 65 20 70 72 65 70 61 72 69 6e 67 20 73 the preparing s
f690: 6f 20 61 73 20 74 6f 20 75 73 65 20 74 68 65 20 o as to use the
f6a0: 63 6f 72 72 65 63 74 0a 2a 2a 20 73 71 6c 69 74 correct.** sqlit
f6b0: 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 20 e3_vtab* handle
f6c0: 69 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 64 20 in the compiled
f6d0: 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 query..**.** Whe
f6e0: 6e 20 61 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 54 n an in-memory T
f6f0: 61 62 6c 65 20 6f 62 6a 65 63 74 20 69 73 20 64 able object is d
f700: 65 6c 65 74 65 64 20 28 66 6f 72 20 65 78 61 6d eleted (for exam
f710: 70 6c 65 20 77 68 65 6e 20 74 68 65 0a 2a 2a 20 ple when the.**
f720: 73 63 68 65 6d 61 20 69 73 20 62 65 69 6e 67 20 schema is being
f730: 72 65 6c 6f 61 64 65 64 20 66 6f 72 20 73 6f 6d reloaded for som
f740: 65 20 72 65 61 73 6f 6e 29 2c 20 74 68 65 20 56 e reason), the V
f750: 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 61 72 Table objects ar
f760: 65 20 6e 6f 74 20 0a 2a 2a 20 64 65 6c 65 74 65 e not .** delete
f770: 64 20 61 6e 64 20 74 68 65 20 73 71 6c 69 74 65 d and the sqlite
f780: 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 3_vtab* handles
f790: 61 72 65 20 6e 6f 74 20 78 44 69 73 63 6f 6e 6e are not xDisconn
f7a0: 65 63 74 28 29 65 64 20 0a 2a 2a 20 69 6d 6d 65 ect()ed .** imme
f7b0: 64 69 61 74 65 6c 79 2e 20 49 6e 73 74 65 61 64 diately. Instead
f7c0: 2c 20 74 68 65 79 20 61 72 65 20 6d 6f 76 65 64 , they are moved
f7d0: 20 66 72 6f 6d 20 74 68 65 20 54 61 62 6c 65 2e from the Table.
f7e0: 70 56 54 61 62 6c 65 20 6c 69 73 74 20 74 6f 0a pVTable list to.
f7f0: 2a 2a 20 61 6e 6f 74 68 65 72 20 6c 69 6e 6b 65 ** another linke
f800: 64 20 6c 69 73 74 20 68 65 61 64 65 64 20 62 79 d list headed by
f810: 20 74 68 65 20 73 71 6c 69 74 65 33 2e 70 44 69 the sqlite3.pDi
f820: 73 63 6f 6e 6e 65 63 74 20 6d 65 6d 62 65 72 20 sconnect member
f830: 6f 66 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 of the.** corres
f840: 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 20 ponding sqlite3
f850: 73 74 72 75 63 74 75 72 65 2e 20 54 68 65 79 20 structure. They
f860: 61 72 65 20 74 68 65 6e 20 64 65 6c 65 74 65 64 are then deleted
f870: 2f 78 44 69 73 63 6f 6e 6e 65 63 74 65 64 20 0a /xDisconnected .
f880: 2a 2a 20 6e 65 78 74 20 74 69 6d 65 20 61 20 73 ** next time a s
f890: 74 61 74 65 6d 65 6e 74 20 69 73 20 70 72 65 70 tatement is prep
f8a0: 61 72 65 64 20 75 73 69 6e 67 20 73 61 69 64 20 ared using said
f8b0: 73 71 6c 69 74 65 33 2a 2e 20 54 68 69 73 20 69 sqlite3*. This i
f8c0: 73 20 64 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 6f s done.** to avo
f8d0: 69 64 20 64 65 61 64 6c 6f 63 6b 20 69 73 73 75 id deadlock issu
f8e0: 65 73 20 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 6c es involving mul
f8f0: 74 69 70 6c 65 20 73 71 6c 69 74 65 33 2e 6d 75 tiple sqlite3.mu
f900: 74 65 78 20 6d 75 74 65 78 65 73 2e 0a 2a 2a 20 tex mutexes..**
f910: 52 65 66 65 72 20 74 6f 20 63 6f 6d 6d 65 6e 74 Refer to comment
f920: 73 20 61 62 6f 76 65 20 66 75 6e 63 74 69 6f 6e s above function
f930: 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
f940: 63 6b 4c 69 73 74 28 29 20 66 6f 72 20 61 6e 0a ckList() for an.
f950: 2a 2a 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 61 ** explanation a
f960: 73 20 74 6f 20 77 68 79 20 69 74 20 69 73 20 73 s to why it is s
f970: 61 66 65 20 74 6f 20 61 64 64 20 61 6e 20 65 6e afe to add an en
f980: 74 72 79 20 74 6f 20 61 6e 20 73 71 6c 69 74 65 try to an sqlite
f990: 33 2e 70 44 69 73 63 6f 6e 6e 65 63 74 0a 2a 2a 3.pDisconnect.**
f9a0: 20 6c 69 73 74 20 77 69 74 68 6f 75 74 20 68 6f list without ho
f9b0: 6c 64 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 lding the corres
f9c0: 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 2e ponding sqlite3.
f9d0: 6d 75 74 65 78 20 6d 75 74 65 78 2e 0a 2a 2a 0a mutex mutex..**.
f9e0: 2a 2a 20 54 68 65 20 6d 65 6d 6f 72 79 20 66 6f ** The memory fo
f9f0: 72 20 6f 62 6a 65 63 74 73 20 6f 66 20 74 68 69 r objects of thi
fa00: 73 20 74 79 70 65 20 69 73 20 61 6c 77 61 79 73 s type is always
fa10: 20 61 6c 6c 6f 63 61 74 65 64 20 62 79 20 0a 2a allocated by .*
fa20: 2a 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f * sqlite3DbMallo
fa30: 63 28 29 2c 20 75 73 69 6e 67 20 74 68 65 20 63 c(), using the c
fa40: 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 onnection handle
fa50: 20 73 74 6f 72 65 64 20 69 6e 20 56 54 61 62 6c stored in VTabl
fa60: 65 2e 64 62 20 61 73 20 0a 2a 2a 20 74 68 65 20 e.db as .** the
fa70: 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 2e 0a first argument..
fa80: 2a 2f 0a 73 74 72 75 63 74 20 56 54 61 62 6c 65 */.struct VTable
fa90: 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 {. sqlite3 *db
faa0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
fab0: 2a 20 44 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 * Database conne
fac0: 63 74 69 6f 6e 20 61 73 73 6f 63 69 61 74 65 64 ction associated
fad0: 20 77 69 74 68 20 74 68 69 73 20 74 61 62 6c 65 with this table
fae0: 20 2a 2f 0a 20 20 4d 6f 64 75 6c 65 20 2a 70 4d */. Module *pM
faf0: 6f 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 od;
fb00: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 6d 6f /* Pointer to mo
fb10: 64 75 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 dule implementat
fb20: 69 6f 6e 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 ion */. sqlite3
fb30: 5f 76 74 61 62 20 2a 70 56 74 61 62 3b 20 20 20 _vtab *pVtab;
fb40: 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f /* Pointer to
fb50: 20 76 74 61 62 20 69 6e 73 74 61 6e 63 65 20 2a vtab instance *
fb60: 2f 0a 20 20 69 6e 74 20 6e 52 65 66 3b 20 20 20 /. int nRef;
fb70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
fb80: 20 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 6e 74 Number of point
fb90: 65 72 73 20 74 6f 20 74 68 69 73 20 73 74 72 75 ers to this stru
fba0: 63 74 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 43 cture */. u8 bC
fbb0: 6f 6e 73 74 72 61 69 6e 74 3b 20 20 20 20 20 20 onstraint;
fbc0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
fbd0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 61 72 65 20 constraints are
fbe0: 73 75 70 70 6f 72 74 65 64 20 2a 2f 0a 20 20 69 supported */. i
fbf0: 6e 74 20 69 53 61 76 65 70 6f 69 6e 74 3b 20 20 nt iSavepoint;
fc00: 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 70 74 /* Dept
fc10: 68 20 6f 66 20 74 68 65 20 53 41 56 45 50 4f 49 h of the SAVEPOI
fc20: 4e 54 20 73 74 61 63 6b 20 2a 2f 0a 20 20 56 54 NT stack */. VT
fc30: 61 62 6c 65 20 2a 70 4e 65 78 74 3b 20 20 20 20 able *pNext;
fc40: 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 /* Next
fc50: 69 6e 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 28 in linked list (
fc60: 73 65 65 20 61 62 6f 76 65 29 20 2a 2f 0a 7d 3b see above) */.};
fc70: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 73 63 68 65 ../*.** The sche
fc80: 6d 61 20 66 6f 72 20 65 61 63 68 20 53 51 4c 20 ma for each SQL
fc90: 74 61 62 6c 65 20 61 6e 64 20 76 69 65 77 20 69 table and view i
fca0: 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e s represented in
fcb0: 20 6d 65 6d 6f 72 79 0a 2a 2a 20 62 79 20 61 6e memory.** by an
fcc0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
fcd0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
fce0: 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 ture..*/.struct
fcf0: 54 61 62 6c 65 20 7b 0a 20 20 63 68 61 72 20 2a Table {. char *
fd00: 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 2f zName; /
fd10: 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 * Name of the ta
fd20: 62 6c 65 20 6f 72 20 76 69 65 77 20 2a 2f 0a 20 ble or view */.
fd30: 20 43 6f 6c 75 6d 6e 20 2a 61 43 6f 6c 3b 20 20 Column *aCol;
fd40: 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 /* Informa
fd50: 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 20 tion about each
fd60: 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 column */. Inde
fd70: 78 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 20 20 x *pIndex;
fd80: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 53 51 4c 20 /* List of SQL
fd90: 69 6e 64 65 78 65 73 20 6f 6e 20 74 68 69 73 20 indexes on this
fda0: 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 53 65 6c 65 table. */. Sele
fdb0: 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 ct *pSelect;
fdc0: 20 2f 2a 20 4e 55 4c 4c 20 66 6f 72 20 74 61 62 /* NULL for tab
fdd0: 6c 65 73 2e 20 20 50 6f 69 6e 74 73 20 74 6f 20 les. Points to
fde0: 64 65 66 69 6e 69 74 69 6f 6e 20 69 66 20 61 20 definition if a
fdf0: 76 69 65 77 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 view. */. FKey
fe00: 2a 70 46 4b 65 79 3b 20 20 20 20 20 20 20 20 20 *pFKey;
fe10: 2f 2a 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 6f /* Linked list o
fe20: 66 20 61 6c 6c 20 66 6f 72 65 69 67 6e 20 6b 65 f all foreign ke
fe30: 79 73 20 69 6e 20 74 68 69 73 20 74 61 62 6c 65 ys in this table
fe40: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c */. char *zCol
fe50: 41 66 66 3b 20 20 20 20 20 20 20 2f 2a 20 53 74 Aff; /* St
fe60: 72 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 68 ring defining th
fe70: 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 61 e affinity of ea
fe80: 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 ch column */. E
fe90: 78 70 72 4c 69 73 74 20 2a 70 43 68 65 63 6b 3b xprList *pCheck;
fea0: 20 20 20 20 2f 2a 20 41 6c 6c 20 43 48 45 43 4b /* All CHECK
feb0: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
fec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fed0: 20 20 20 20 20 20 20 2f 2a 20 20 20 2e 2e 2e 20 /* ...
fee0: 61 6c 73 6f 20 75 73 65 64 20 61 73 20 63 6f 6c also used as col
fef0: 75 6d 6e 20 6e 61 6d 65 20 6c 69 73 74 20 69 6e umn name list in
ff00: 20 61 20 56 49 45 57 20 2a 2f 0a 20 20 69 6e 74 a VIEW */. int
ff10: 20 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 20 tnum;
ff20: 20 20 2f 2a 20 52 6f 6f 74 20 42 54 72 65 65 20 /* Root BTree
ff30: 70 61 67 65 20 66 6f 72 20 74 68 69 73 20 74 61 page for this ta
ff40: 62 6c 65 20 2a 2f 0a 20 20 69 31 36 20 69 50 4b ble */. i16 iPK
ff50: 65 79 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ey; /*
ff60: 20 49 66 20 6e 6f 74 20 6e 65 67 61 74 69 76 65 If not negative
ff70: 2c 20 75 73 65 20 61 43 6f 6c 5b 69 50 4b 65 79 , use aCol[iPKey
ff80: 5d 20 61 73 20 74 68 65 20 72 6f 77 69 64 20 2a ] as the rowid *
ff90: 2f 0a 20 20 69 31 36 20 6e 43 6f 6c 3b 20 20 20 /. i16 nCol;
ffa0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
ffb0: 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
ffc0: 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 this table */.
ffd0: 20 75 31 36 20 6e 52 65 66 3b 20 20 20 20 20 20 u16 nRef;
ffe0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
fff0: 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 74 of pointers to t
10000 68 69 73 20 54 61 62 6c 65 20 2a 2f 0a 20 20 4c his Table */. L
10010 6f 67 45 73 74 20 6e 52 6f 77 4c 6f 67 45 73 74 ogEst nRowLogEst
10020 3b 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 ; /* Estimated
10030 20 72 6f 77 73 20 69 6e 20 74 61 62 6c 65 20 2d rows in table -
10040 20 66 72 6f 6d 20 73 71 6c 69 74 65 5f 73 74 61 from sqlite_sta
10050 74 31 20 74 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f t1 table */. Lo
10060 67 45 73 74 20 73 7a 54 61 62 52 6f 77 3b 20 20 gEst szTabRow;
10070 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 /* Estimated
10080 73 69 7a 65 20 6f 66 20 65 61 63 68 20 74 61 62 size of each tab
10090 6c 65 20 72 6f 77 20 69 6e 20 62 79 74 65 73 20 le row in bytes
100a0 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
100b0 5f 45 4e 41 42 4c 45 5f 43 4f 53 54 4d 55 4c 54 _ENABLE_COSTMULT
100c0 0a 20 20 4c 6f 67 45 73 74 20 63 6f 73 74 4d 75 . LogEst costMu
100d0 6c 74 3b 20 20 20 20 20 2f 2a 20 43 6f 73 74 20 lt; /* Cost
100e0 6d 75 6c 74 69 70 6c 69 65 72 20 66 6f 72 20 75 multiplier for u
100f0 73 69 6e 67 20 74 68 69 73 20 74 61 62 6c 65 20 sing this table
10100 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 75 38 20 74 */.#endif. u8 t
10110 61 62 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 abFlags;
10120 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 54 46 5f 2a /* Mask of TF_*
10130 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 values */. u8
10140 6b 65 79 43 6f 6e 66 3b 20 20 20 20 20 20 20 20 keyConf;
10150 20 20 2f 2a 20 57 68 61 74 20 74 6f 20 64 6f 20 /* What to do
10160 69 6e 20 63 61 73 65 20 6f 66 20 75 6e 69 71 75 in case of uniqu
10170 65 6e 65 73 73 20 63 6f 6e 66 6c 69 63 74 20 6f eness conflict o
10180 6e 20 69 50 4b 65 79 20 2a 2f 0a 23 69 66 6e 64 n iPKey */.#ifnd
10190 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 ef SQLITE_OMIT_A
101a0 4c 54 45 52 54 41 42 4c 45 0a 20 20 69 6e 74 20 LTERTABLE. int
101b0 61 64 64 43 6f 6c 4f 66 66 73 65 74 3b 20 20 20 addColOffset;
101c0 20 2f 2a 20 4f 66 66 73 65 74 20 69 6e 20 43 52 /* Offset in CR
101d0 45 41 54 45 20 54 41 42 4c 45 20 73 74 6d 74 20 EATE TABLE stmt
101e0 74 6f 20 61 64 64 20 61 20 6e 65 77 20 63 6f 6c to add a new col
101f0 75 6d 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 umn */.#endif.#i
10200 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
10210 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 T_VIRTUALTABLE.
10220 20 69 6e 74 20 6e 4d 6f 64 75 6c 65 41 72 67 3b int nModuleArg;
10230 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
10240 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 of arguments to
10250 74 68 65 20 6d 6f 64 75 6c 65 20 2a 2f 0a 20 20 the module */.
10260 63 68 61 72 20 2a 2a 61 7a 4d 6f 64 75 6c 65 41 char **azModuleA
10270 72 67 3b 20 20 2f 2a 20 30 3a 20 6d 6f 64 75 6c rg; /* 0: modul
10280 65 20 31 3a 20 73 63 68 65 6d 61 20 32 3a 20 76 e 1: schema 2: v
10290 74 61 62 20 6e 61 6d 65 20 33 2e 2e 2e 3a 20 61 tab name 3...: a
102a0 72 67 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 rgs */. VTable
102b0 2a 70 56 54 61 62 6c 65 3b 20 20 20 20 20 2f 2a *pVTable; /*
102c0 20 4c 69 73 74 20 6f 66 20 56 54 61 62 6c 65 20 List of VTable
102d0 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a 23 65 6e 64 objects. */.#end
102e0 69 66 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 if. Trigger *pT
102f0 72 69 67 67 65 72 3b 20 20 20 2f 2a 20 4c 69 73 rigger; /* Lis
10300 74 20 6f 66 20 74 72 69 67 67 65 72 73 20 73 74 t of triggers st
10310 6f 72 65 64 20 69 6e 20 70 53 63 68 65 6d 61 20 ored in pSchema
10320 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 */. Schema *pSc
10330 68 65 6d 61 3b 20 20 20 20 20 2f 2a 20 53 63 68 hema; /* Sch
10340 65 6d 61 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ema that contain
10350 73 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a s this table */.
10360 20 20 54 61 62 6c 65 20 2a 70 4e 65 78 74 5a 6f Table *pNextZo
10370 6d 62 69 65 3b 20 20 2f 2a 20 4e 65 78 74 20 6f mbie; /* Next o
10380 6e 20 74 68 65 20 50 61 72 73 65 2e 70 5a 6f 6d n the Parse.pZom
10390 62 69 65 54 61 62 20 6c 69 73 74 20 2a 2f 0a 7d bieTab list */.}
103a0 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 ;../*.** Allowed
103b0 20 76 61 6c 75 65 73 20 66 6f 72 20 54 61 62 6c values for Tabl
103c0 65 2e 74 61 62 46 6c 61 67 73 2e 0a 2a 2a 0a 2a e.tabFlags..**.*
103d0 2a 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 61 * TF_OOOHidden a
103e0 70 70 6c 69 65 73 20 74 6f 20 76 69 72 74 75 61 pplies to virtua
103f0 6c 20 74 61 62 6c 65 73 20 74 68 61 74 20 68 61 l tables that ha
10400 76 65 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e ve hidden column
10410 73 20 74 68 61 74 20 61 72 65 0a 2a 2a 20 66 6f s that are.** fo
10420 6c 6c 6f 77 65 64 20 62 79 20 6e 6f 6e 2d 68 69 llowed by non-hi
10430 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 2e 20 20 45 dden columns. E
10440 78 61 6d 70 6c 65 3a 20 20 22 43 52 45 41 54 45 xample: "CREATE
10450 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 VIRTUAL TABLE x
10460 20 55 53 49 4e 47 0a 2a 2a 20 76 74 61 62 31 28 USING.** vtab1(
10470 61 20 48 49 44 44 45 4e 2c 20 62 29 3b 22 2e 20 a HIDDEN, b);".
10480 20 53 69 6e 63 65 20 22 62 22 20 69 73 20 61 20 Since "b" is a
10490 6e 6f 6e 2d 68 69 64 64 65 6e 20 63 6f 6c 75 6d non-hidden colum
104a0 6e 20 62 75 74 20 22 61 22 20 69 73 20 68 69 64 n but "a" is hid
104b0 64 65 6e 2c 0a 2a 2a 20 74 68 65 20 54 46 5f 4f den,.** the TF_O
104c0 4f 4f 48 69 64 64 65 6e 20 61 74 74 72 69 62 75 OOHidden attribu
104d0 74 65 20 77 6f 75 6c 64 20 61 70 70 6c 79 20 69 te would apply i
104e0 6e 20 74 68 69 73 20 63 61 73 65 2e 20 20 53 75 n this case. Su
104f0 63 68 20 74 61 62 6c 65 73 20 72 65 71 75 69 72 ch tables requir
10500 65 0a 2a 2a 20 73 70 65 63 69 61 6c 20 68 61 6e e.** special han
10510 64 6c 69 6e 67 20 64 75 72 69 6e 67 20 49 4e 53 dling during INS
10520 45 52 54 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a ERT processing..
10530 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 52 65 */.#define TF_Re
10540 61 64 6f 6e 6c 79 20 20 20 20 20 20 20 20 30 78 adonly 0x
10550 30 31 20 20 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 01 /* Read-on
10560 6c 79 20 73 79 73 74 65 6d 20 74 61 62 6c 65 20 ly system table
10570 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 45 70 */.#define TF_Ep
10580 68 65 6d 65 72 61 6c 20 20 20 20 20 20 20 30 78 hemeral 0x
10590 30 32 20 20 20 20 2f 2a 20 41 6e 20 65 70 68 65 02 /* An ephe
105a0 6d 65 72 61 6c 20 74 61 62 6c 65 20 2a 2f 0a 23 meral table */.#
105b0 64 65 66 69 6e 65 20 54 46 5f 48 61 73 50 72 69 define TF_HasPri
105c0 6d 61 72 79 4b 65 79 20 20 20 30 78 30 34 20 20 maryKey 0x04
105d0 20 20 2f 2a 20 54 61 62 6c 65 20 68 61 73 20 61 /* Table has a
105e0 20 70 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a primary key */.
105f0 23 64 65 66 69 6e 65 20 54 46 5f 41 75 74 6f 69 #define TF_Autoi
10600 6e 63 72 65 6d 65 6e 74 20 20 20 30 78 30 38 20 ncrement 0x08
10610 20 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 70 72 /* Integer pr
10620 69 6d 61 72 79 20 6b 65 79 20 69 73 20 61 75 74 imary key is aut
10630 6f 69 6e 63 72 65 6d 65 6e 74 20 2a 2f 0a 23 64 oincrement */.#d
10640 65 66 69 6e 65 20 54 46 5f 56 69 72 74 75 61 6c efine TF_Virtual
10650 20 20 20 20 20 20 20 20 20 30 78 31 30 20 20 20 0x10
10660 20 2f 2a 20 49 73 20 61 20 76 69 72 74 75 61 6c /* Is a virtual
10670 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e table */.#defin
10680 65 20 54 46 5f 57 69 74 68 6f 75 74 52 6f 77 69 e TF_WithoutRowi
10690 64 20 20 20 20 30 78 32 30 20 20 20 20 2f 2a 20 d 0x20 /*
106a0 4e 6f 20 72 6f 77 69 64 2e 20 20 50 52 49 4d 41 No rowid. PRIMA
106b0 52 59 20 4b 45 59 20 69 73 20 74 68 65 20 6b 65 RY KEY is the ke
106c0 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f y */.#define TF_
106d0 4e 6f 56 69 73 69 62 6c 65 52 6f 77 69 64 20 20 NoVisibleRowid
106e0 30 78 34 30 20 20 20 20 2f 2a 20 4e 6f 20 75 73 0x40 /* No us
106f0 65 72 2d 76 69 73 69 62 6c 65 20 22 72 6f 77 69 er-visible "rowi
10700 64 22 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 64 65 d" column */.#de
10710 66 69 6e 65 20 54 46 5f 4f 4f 4f 48 69 64 64 65 fine TF_OOOHidde
10720 6e 20 20 20 20 20 20 20 30 78 38 30 20 20 20 20 n 0x80
10730 2f 2a 20 4f 75 74 2d 6f 66 2d 4f 72 64 65 72 20 /* Out-of-Order
10740 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 2a hidden columns *
10750 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 65 73 74 20 74 /.../*.** Test t
10760 6f 20 73 65 65 20 77 68 65 74 68 65 72 20 6f 72 o see whether or
10770 20 6e 6f 74 20 61 20 74 61 62 6c 65 20 69 73 20 not a table is
10780 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e a virtual table.
10790 20 20 54 68 69 73 20 69 73 0a 2a 2a 20 64 6f 6e This is.** don
107a0 65 20 61 73 20 61 20 6d 61 63 72 6f 20 73 6f 20 e as a macro so
107b0 74 68 61 74 20 69 74 20 77 69 6c 6c 20 62 65 20 that it will be
107c0 6f 70 74 69 6d 69 7a 65 64 20 6f 75 74 20 77 68 optimized out wh
107d0 65 6e 20 76 69 72 74 75 61 6c 0a 2a 2a 20 74 61 en virtual.** ta
107e0 62 6c 65 20 73 75 70 70 6f 72 74 20 69 73 20 6f ble support is o
107f0 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 20 mitted from the
10800 62 75 69 6c 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 build..*/.#ifnde
10810 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 f SQLITE_OMIT_VI
10820 52 54 55 41 4c 54 41 42 4c 45 0a 23 20 20 64 65 RTUALTABLE.# de
10830 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 58 fine IsVirtual(X
10840 29 20 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 ) (((X)->ta
10850 62 46 6c 61 67 73 20 26 20 54 46 5f 56 69 72 74 bFlags & TF_Virt
10860 75 61 6c 29 21 3d 30 29 0a 23 20 20 64 65 66 69 ual)!=0).# defi
10870 6e 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d ne IsHiddenColum
10880 6e 28 58 29 20 28 28 28 58 29 2d 3e 63 6f 6c 46 n(X) (((X)->colF
10890 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f 48 lags & COLFLAG_H
108a0 49 44 44 45 4e 29 21 3d 30 29 0a 23 65 6c 73 65 IDDEN)!=0).#else
108b0 0a 23 20 20 64 65 66 69 6e 65 20 49 73 56 69 72 .# define IsVir
108c0 74 75 61 6c 28 58 29 20 20 20 20 20 20 30 0a 23 tual(X) 0.#
108d0 20 20 64 65 66 69 6e 65 20 49 73 48 69 64 64 65 define IsHidde
108e0 6e 43 6f 6c 75 6d 6e 28 58 29 20 30 0a 23 65 6e nColumn(X) 0.#en
108f0 64 69 66 0a 0a 2f 2a 20 44 6f 65 73 20 74 68 65 dif../* Does the
10900 20 74 61 62 6c 65 20 68 61 76 65 20 61 20 72 6f table have a ro
10910 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 48 wid */.#define H
10920 61 73 52 6f 77 69 64 28 58 29 20 20 20 20 20 28 asRowid(X) (
10930 28 28 58 29 2d 3e 74 61 62 46 6c 61 67 73 20 26 ((X)->tabFlags &
10940 20 54 46 5f 57 69 74 68 6f 75 74 52 6f 77 69 64 TF_WithoutRowid
10950 29 3d 3d 30 29 0a 23 64 65 66 69 6e 65 20 56 69 )==0).#define Vi
10960 73 69 62 6c 65 52 6f 77 69 64 28 58 29 20 28 28 sibleRowid(X) ((
10970 28 58 29 2d 3e 74 61 62 46 6c 61 67 73 20 26 20 (X)->tabFlags &
10980 54 46 5f 4e 6f 56 69 73 69 62 6c 65 52 6f 77 69 TF_NoVisibleRowi
10990 64 29 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 d)==0)../*.** Ea
109a0 63 68 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 63 ch foreign key c
109b0 6f 6e 73 74 72 61 69 6e 74 20 69 73 20 61 6e 20 onstraint is an
109c0 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
109d0 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
109e0 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 41 20 66 6f 72 ure..**.** A for
109f0 65 69 67 6e 20 6b 65 79 20 69 73 20 61 73 73 6f eign key is asso
10a00 63 69 61 74 65 64 20 77 69 74 68 20 74 77 6f 20 ciated with two
10a10 74 61 62 6c 65 73 2e 20 20 54 68 65 20 22 66 72 tables. The "fr
10a20 6f 6d 22 20 74 61 62 6c 65 20 69 73 0a 2a 2a 20 om" table is.**
10a30 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 20 63 the table that c
10a40 6f 6e 74 61 69 6e 73 20 74 68 65 20 52 45 46 45 ontains the REFE
10a50 52 45 4e 43 45 53 20 63 6c 61 75 73 65 20 74 68 RENCES clause th
10a60 61 74 20 63 72 65 61 74 65 73 20 74 68 65 20 66 at creates the f
10a70 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 2e 20 20 oreign.** key.
10a80 54 68 65 20 22 74 6f 22 20 74 61 62 6c 65 20 69 The "to" table i
10a90 73 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 s the table that
10aa0 20 69 73 20 6e 61 6d 65 64 20 69 6e 20 74 68 65 is named in the
10ab0 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 75 REFERENCES clau
10ac0 73 65 2e 0a 2a 2a 20 43 6f 6e 73 69 64 65 72 20 se..** Consider
10ad0 74 68 69 73 20 65 78 61 6d 70 6c 65 3a 0a 2a 2a this example:.**
10ae0 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 54 .** CREATE T
10af0 41 42 4c 45 20 65 78 31 28 0a 2a 2a 20 20 20 20 ABLE ex1(.**
10b00 20 20 20 61 20 49 4e 54 45 47 45 52 20 50 52 49 a INTEGER PRI
10b10 4d 41 52 59 20 4b 45 59 2c 0a 2a 2a 20 20 20 20 MARY KEY,.**
10b20 20 20 20 62 20 49 4e 54 45 47 45 52 20 43 4f 4e b INTEGER CON
10b30 53 54 52 41 49 4e 54 20 66 6b 31 20 52 45 46 45 STRAINT fk1 REFE
10b40 52 45 4e 43 45 53 20 65 78 32 28 78 29 0a 2a 2a RENCES ex2(x).**
10b50 20 20 20 20 20 29 3b 0a 2a 2a 0a 2a 2a 20 46 6f );.**.** Fo
10b60 72 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 22 66 r foreign key "f
10b70 6b 31 22 2c 20 74 68 65 20 66 72 6f 6d 2d 74 61 k1", the from-ta
10b80 62 6c 65 20 69 73 20 22 65 78 31 22 20 61 6e 64 ble is "ex1" and
10b90 20 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 69 73 the to-table is
10ba0 20 22 65 78 32 22 2e 0a 2a 2a 20 45 71 75 69 76 "ex2"..** Equiv
10bb0 61 6c 65 6e 74 20 6e 61 6d 65 73 3a 0a 2a 2a 0a alent names:.**.
10bc0 2a 2a 20 20 20 20 20 66 72 6f 6d 2d 74 61 62 6c ** from-tabl
10bd0 65 20 3d 3d 20 63 68 69 6c 64 2d 74 61 62 6c 65 e == child-table
10be0 0a 2a 2a 20 20 20 20 20 20 20 74 6f 2d 74 61 62 .** to-tab
10bf0 6c 65 20 3d 3d 20 70 61 72 65 6e 74 2d 74 61 62 le == parent-tab
10c00 6c 65 0a 2a 2a 0a 2a 2a 20 45 61 63 68 20 52 45 le.**.** Each RE
10c10 46 45 52 45 4e 43 45 53 20 63 6c 61 75 73 65 20 FERENCES clause
10c20 67 65 6e 65 72 61 74 65 73 20 61 6e 20 69 6e 73 generates an ins
10c30 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
10c40 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
10c50 0a 2a 2a 20 77 68 69 63 68 20 69 73 20 61 74 74 .** which is att
10c60 61 63 68 65 64 20 74 6f 20 74 68 65 20 66 72 6f ached to the fro
10c70 6d 2d 74 61 62 6c 65 2e 20 20 54 68 65 20 74 6f m-table. The to
10c80 2d 74 61 62 6c 65 20 6e 65 65 64 20 6e 6f 74 20 -table need not
10c90 65 78 69 73 74 20 77 68 65 6e 0a 2a 2a 20 74 68 exist when.** th
10ca0 65 20 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 e from-table is
10cb0 63 72 65 61 74 65 64 2e 20 20 54 68 65 20 65 78 created. The ex
10cc0 69 73 74 65 6e 63 65 20 6f 66 20 74 68 65 20 74 istence of the t
10cd0 6f 2d 74 61 62 6c 65 20 69 73 20 6e 6f 74 20 63 o-table is not c
10ce0 68 65 63 6b 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 hecked..**.** Th
10cf0 65 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 70 61 e list of all pa
10d00 72 65 6e 74 73 20 66 6f 72 20 63 68 69 6c 64 20 rents for child
10d10 54 61 62 6c 65 20 58 20 69 73 20 68 65 6c 64 20 Table X is held
10d20 61 74 20 58 2e 70 46 4b 65 79 2e 0a 2a 2a 0a 2a at X.pFKey..**.*
10d30 2a 20 41 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 * A list of all
10d40 63 68 69 6c 64 72 65 6e 20 66 6f 72 20 61 20 74 children for a t
10d50 61 62 6c 65 20 6e 61 6d 65 64 20 5a 20 28 77 68 able named Z (wh
10d60 69 63 68 20 6d 69 67 68 74 20 6e 6f 74 20 65 76 ich might not ev
10d70 65 6e 20 65 78 69 73 74 29 0a 2a 2a 20 69 73 20 en exist).** is
10d80 68 65 6c 64 20 69 6e 20 53 63 68 65 6d 61 2e 66 held in Schema.f
10d90 6b 65 79 48 61 73 68 20 77 69 74 68 20 61 20 68 keyHash with a h
10da0 61 73 68 20 6b 65 79 20 6f 66 20 5a 2e 0a 2a 2f ash key of Z..*/
10db0 0a 73 74 72 75 63 74 20 46 4b 65 79 20 7b 0a 20 .struct FKey {.
10dc0 20 54 61 62 6c 65 20 2a 70 46 72 6f 6d 3b 20 20 Table *pFrom;
10dd0 20 20 20 2f 2a 20 54 61 62 6c 65 20 63 6f 6e 74 /* Table cont
10de0 61 69 6e 69 6e 67 20 74 68 65 20 52 45 46 45 52 aining the REFER
10df0 45 4e 43 45 53 20 63 6c 61 75 73 65 20 28 61 6b ENCES clause (ak
10e00 61 3a 20 43 68 69 6c 64 29 20 2a 2f 0a 20 20 46 a: Child) */. F
10e10 4b 65 79 20 2a 70 4e 65 78 74 46 72 6f 6d 3b 20 Key *pNextFrom;
10e20 20 2f 2a 20 4e 65 78 74 20 46 4b 65 79 20 77 69 /* Next FKey wi
10e30 74 68 20 74 68 65 20 73 61 6d 65 20 69 6e 20 70 th the same in p
10e40 46 72 6f 6d 2e 20 4e 65 78 74 20 70 61 72 65 6e From. Next paren
10e50 74 20 6f 66 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 t of pFrom */.
10e60 63 68 61 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20 char *zTo;
10e70 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 61 62 /* Name of tab
10e80 6c 65 20 74 68 61 74 20 74 68 65 20 6b 65 79 20 le that the key
10e90 70 6f 69 6e 74 73 20 74 6f 20 28 61 6b 61 3a 20 points to (aka:
10ea0 50 61 72 65 6e 74 29 20 2a 2f 0a 20 20 46 4b 65 Parent) */. FKe
10eb0 79 20 2a 70 4e 65 78 74 54 6f 3b 20 20 20 20 2f y *pNextTo; /
10ec0 2a 20 4e 65 78 74 20 77 69 74 68 20 74 68 65 20 * Next with the
10ed0 73 61 6d 65 20 7a 54 6f 2e 20 4e 65 78 74 20 63 same zTo. Next c
10ee0 68 69 6c 64 20 6f 66 20 7a 54 6f 2e 20 2a 2f 0a hild of zTo. */.
10ef0 20 20 46 4b 65 79 20 2a 70 50 72 65 76 54 6f 3b FKey *pPrevTo;
10f00 20 20 20 20 2f 2a 20 50 72 65 76 69 6f 75 73 20 /* Previous
10f10 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 7a 54 with the same zT
10f20 6f 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 6f 6c 3b o */. int nCol;
10f30 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
10f40 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
10f50 20 74 68 69 73 20 6b 65 79 20 2a 2f 0a 20 20 2f this key */. /
10f60 2a 20 45 56 3a 20 52 2d 33 30 33 32 33 2d 32 31 * EV: R-30323-21
10f70 39 31 37 20 2a 2f 0a 20 20 75 38 20 69 73 44 65 917 */. u8 isDe
10f80 66 65 72 72 65 64 3b 20 20 20 20 20 20 20 2f 2a ferred; /*
10f90 20 54 72 75 65 20 69 66 20 63 6f 6e 73 74 72 61 True if constra
10fa0 69 6e 74 20 63 68 65 63 6b 69 6e 67 20 69 73 20 int checking is
10fb0 64 65 66 65 72 72 65 64 20 74 69 6c 6c 20 43 4f deferred till CO
10fc0 4d 4d 49 54 20 2a 2f 0a 20 20 75 38 20 61 41 63 MMIT */. u8 aAc
10fd0 74 69 6f 6e 5b 32 5d 3b 20 20 20 20 20 20 20 20 tion[2];
10fe0 2f 2a 20 4f 4e 20 44 45 4c 45 54 45 20 61 6e 64 /* ON DELETE and
10ff0 20 4f 4e 20 55 50 44 41 54 45 20 61 63 74 69 6f ON UPDATE actio
11000 6e 73 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 ns, respectively
11010 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 61 */. Trigger *a
11020 70 54 72 69 67 67 65 72 5b 32 5d 3b 2f 2a 20 54 pTrigger[2];/* T
11030 72 69 67 67 65 72 73 20 66 6f 72 20 61 41 63 74 riggers for aAct
11040 69 6f 6e 5b 5d 20 61 63 74 69 6f 6e 73 20 2a 2f ion[] actions */
11050 0a 20 20 73 74 72 75 63 74 20 73 43 6f 6c 4d 61 . struct sColMa
11060 70 20 7b 20 20 20 20 20 20 2f 2a 20 4d 61 70 70 p { /* Mapp
11070 69 6e 67 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 ing of columns i
11080 6e 20 70 46 72 6f 6d 20 74 6f 20 63 6f 6c 75 6d n pFrom to colum
11090 6e 73 20 69 6e 20 7a 54 6f 20 2a 2f 0a 20 20 20 ns in zTo */.
110a0 20 69 6e 74 20 69 46 72 6f 6d 3b 20 20 20 20 20 int iFrom;
110b0 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 /* Index
110c0 6f 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 70 46 72 of column in pFr
110d0 6f 6d 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a om */. char *
110e0 7a 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 zCol;
110f0 2f 2a 20 4e 61 6d 65 20 6f 66 20 63 6f 6c 75 6d /* Name of colum
11100 6e 20 69 6e 20 7a 54 6f 2e 20 20 49 66 20 4e 55 n in zTo. If NU
11110 4c 4c 20 75 73 65 20 50 52 49 4d 41 52 59 20 4b LL use PRIMARY K
11120 45 59 20 2a 2f 0a 20 20 7d 20 61 43 6f 6c 5b 31 EY */. } aCol[1
11130 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ]; /*
11140 20 4f 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 One entry for e
11150 61 63 68 20 6f 66 20 6e 43 6f 6c 20 63 6f 6c 75 ach of nCol colu
11160 6d 6e 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a mns */.};../*.**
11170 20 53 51 4c 69 74 65 20 73 75 70 70 6f 72 74 73 SQLite supports
11180 20 6d 61 6e 79 20 64 69 66 66 65 72 65 6e 74 20 many different
11190 77 61 79 73 20 74 6f 20 72 65 73 6f 6c 76 65 20 ways to resolve
111a0 61 20 63 6f 6e 73 74 72 61 69 6e 74 0a 2a 2a 20 a constraint.**
111b0 65 72 72 6f 72 2e 20 20 52 4f 4c 4c 42 41 43 4b error. ROLLBACK
111c0 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e processing mean
111d0 73 20 74 68 61 74 20 61 20 63 6f 6e 73 74 72 61 s that a constra
111e0 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 0a 2a 2a int violation.**
111f0 20 63 61 75 73 65 73 20 74 68 65 20 6f 70 65 72 causes the oper
11200 61 74 69 6f 6e 20 69 6e 20 70 72 6f 63 65 73 73 ation in process
11210 20 74 6f 20 66 61 69 6c 20 61 6e 64 20 66 6f 72 to fail and for
11220 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 72 61 the current tra
11230 6e 73 61 63 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 nsaction.** to b
11240 65 20 72 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 e rolled back.
11250 41 42 4f 52 54 20 70 72 6f 63 65 73 73 69 6e 67 ABORT processing
11260 20 6d 65 61 6e 73 20 74 68 65 20 6f 70 65 72 61 means the opera
11270 74 69 6f 6e 20 69 6e 20 70 72 6f 63 65 73 73 0a tion in process.
11280 2a 2a 20 66 61 69 6c 73 20 61 6e 64 20 61 6e 79 ** fails and any
11290 20 70 72 69 6f 72 20 63 68 61 6e 67 65 73 20 66 prior changes f
112a0 72 6f 6d 20 74 68 61 74 20 6f 6e 65 20 6f 70 65 rom that one ope
112b0 72 61 74 69 6f 6e 20 61 72 65 20 62 61 63 6b 65 ration are backe
112c0 64 20 6f 75 74 2c 0a 2a 2a 20 62 75 74 20 74 68 d out,.** but th
112d0 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 69 73 e transaction is
112e0 20 6e 6f 74 20 72 6f 6c 6c 65 64 20 62 61 63 6b not rolled back
112f0 2e 20 20 46 41 49 4c 20 70 72 6f 63 65 73 73 69 . FAIL processi
11300 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 0a 2a 2a ng means that.**
11310 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 the operation i
11320 6e 20 70 72 6f 67 72 65 73 73 20 73 74 6f 70 73 n progress stops
11330 20 61 6e 64 20 72 65 74 75 72 6e 73 20 61 6e 20 and returns an
11340 65 72 72 6f 72 20 63 6f 64 65 2e 20 20 42 75 74 error code. But
11350 20 70 72 69 6f 72 0a 2a 2a 20 63 68 61 6e 67 65 prior.** change
11360 73 20 64 75 65 20 74 6f 20 74 68 65 20 73 61 6d s due to the sam
11370 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 72 65 20 e operation are
11380 6e 6f 74 20 62 61 63 6b 65 64 20 6f 75 74 20 61 not backed out a
11390 6e 64 20 6e 6f 20 72 6f 6c 6c 62 61 63 6b 0a 2a nd no rollback.*
113a0 2a 20 6f 63 63 75 72 73 2e 20 20 49 47 4e 4f 52 * occurs. IGNOR
113b0 45 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 E means that the
113c0 20 70 61 72 74 69 63 75 6c 61 72 20 72 6f 77 20 particular row
113d0 74 68 61 74 20 63 61 75 73 65 64 20 74 68 65 20 that caused the
113e0 63 6f 6e 73 74 72 61 69 6e 74 0a 2a 2a 20 65 72 constraint.** er
113f0 72 6f 72 20 69 73 20 6e 6f 74 20 69 6e 73 65 72 ror is not inser
11400 74 65 64 20 6f 72 20 75 70 64 61 74 65 64 2e 20 ted or updated.
11410 20 50 72 6f 63 65 73 73 69 6e 67 20 63 6f 6e 74 Processing cont
11420 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 65 72 72 inues and no err
11430 6f 72 0a 2a 2a 20 69 73 20 72 65 74 75 72 6e 65 or.** is returne
11440 64 2e 20 20 52 45 50 4c 41 43 45 20 6d 65 61 6e d. REPLACE mean
11450 73 20 74 68 61 74 20 70 72 65 65 78 69 73 74 69 s that preexisti
11460 6e 67 20 64 61 74 61 62 61 73 65 20 72 6f 77 73 ng database rows
11470 20 74 68 61 74 20 63 61 75 73 65 64 0a 2a 2a 20 that caused.**
11480 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 a UNIQUE constra
11490 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 20 61 72 int violation ar
114a0 65 20 72 65 6d 6f 76 65 64 20 73 6f 20 74 68 61 e removed so tha
114b0 74 20 74 68 65 20 6e 65 77 20 69 6e 73 65 72 74 t the new insert
114c0 20 6f 72 0a 2a 2a 20 75 70 64 61 74 65 20 63 61 or.** update ca
114d0 6e 20 70 72 6f 63 65 65 64 2e 20 20 50 72 6f 63 n proceed. Proc
114e0 65 73 73 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 essing continues
114f0 20 61 6e 64 20 6e 6f 20 65 72 72 6f 72 20 69 73 and no error is
11500 20 72 65 70 6f 72 74 65 64 2e 0a 2a 2a 0a 2a 2a reported..**.**
11510 20 52 45 53 54 52 49 43 54 2c 20 53 45 54 4e 55 RESTRICT, SETNU
11520 4c 4c 2c 20 61 6e 64 20 43 41 53 43 41 44 45 20 LL, and CASCADE
11530 61 63 74 69 6f 6e 73 20 61 70 70 6c 79 20 6f 6e actions apply on
11540 6c 79 20 74 6f 20 66 6f 72 65 69 67 6e 20 6b 65 ly to foreign ke
11550 79 73 2e 0a 2a 2a 20 52 45 53 54 52 49 43 54 20 ys..** RESTRICT
11560 69 73 20 74 68 65 20 73 61 6d 65 20 61 73 20 41 is the same as A
11570 42 4f 52 54 20 66 6f 72 20 49 4d 4d 45 44 49 41 BORT for IMMEDIA
11580 54 45 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 TE foreign keys
11590 61 6e 64 20 74 68 65 0a 2a 2a 20 73 61 6d 65 20 and the.** same
115a0 61 73 20 52 4f 4c 4c 42 41 43 4b 20 66 6f 72 20 as ROLLBACK for
115b0 44 45 46 45 52 52 45 44 20 6b 65 79 73 2e 20 20 DEFERRED keys.
115c0 53 45 54 4e 55 4c 4c 20 6d 65 61 6e 73 20 74 68 SETNULL means th
115d0 61 74 20 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a at the foreign.*
115e0 2a 20 6b 65 79 20 69 73 20 73 65 74 20 74 6f 20 * key is set to
115f0 4e 55 4c 4c 2e 20 20 43 41 53 43 41 44 45 20 6d NULL. CASCADE m
11600 65 61 6e 73 20 74 68 61 74 20 61 20 44 45 4c 45 eans that a DELE
11610 54 45 20 6f 72 20 55 50 44 41 54 45 20 6f 66 20 TE or UPDATE of
11620 74 68 65 0a 2a 2a 20 72 65 66 65 72 65 6e 63 65 the.** reference
11630 64 20 74 61 62 6c 65 20 72 6f 77 20 69 73 20 70 d table row is p
11640 72 6f 70 61 67 61 74 65 64 20 69 6e 74 6f 20 74 ropagated into t
11650 68 65 20 72 6f 77 20 74 68 61 74 20 68 6f 6c 64 he row that hold
11660 73 20 74 68 65 0a 2a 2a 20 66 6f 72 65 69 67 6e s the.** foreign
11670 20 6b 65 79 2e 0a 2a 2a 20 0a 2a 2a 20 54 68 65 key..** .** The
11680 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 79 6d 62 6f following symbo
11690 6c 69 63 20 76 61 6c 75 65 73 20 61 72 65 20 75 lic values are u
116a0 73 65 64 20 74 6f 20 72 65 63 6f 72 64 20 77 68 sed to record wh
116b0 69 63 68 20 74 79 70 65 0a 2a 2a 20 6f 66 20 61 ich type.** of a
116c0 63 74 69 6f 6e 20 74 6f 20 74 61 6b 65 2e 0a 2a ction to take..*
116d0 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 4e 6f 6e /.#define OE_Non
116e0 65 20 20 20 20 20 30 20 20 20 2f 2a 20 54 68 65 e 0 /* The
116f0 72 65 20 69 73 20 6e 6f 20 63 6f 6e 73 74 72 61 re is no constra
11700 69 6e 74 20 74 6f 20 63 68 65 63 6b 20 2a 2f 0a int to check */.
11710 23 64 65 66 69 6e 65 20 4f 45 5f 52 6f 6c 6c 62 #define OE_Rollb
11720 61 63 6b 20 31 20 20 20 2f 2a 20 46 61 69 6c 20 ack 1 /* Fail
11730 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 6e the operation an
11740 64 20 72 6f 6c 6c 62 61 63 6b 20 74 68 65 20 74 d rollback the t
11750 72 61 6e 73 61 63 74 69 6f 6e 20 2a 2f 0a 23 64 ransaction */.#d
11760 65 66 69 6e 65 20 4f 45 5f 41 62 6f 72 74 20 20 efine OE_Abort
11770 20 20 32 20 20 20 2f 2a 20 42 61 63 6b 20 6f 75 2 /* Back ou
11780 74 20 63 68 61 6e 67 65 73 20 62 75 74 20 64 6f t changes but do
11790 20 6e 6f 20 72 6f 6c 6c 62 61 63 6b 20 74 72 61 no rollback tra
117a0 6e 73 61 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 nsaction */.#def
117b0 69 6e 65 20 4f 45 5f 46 61 69 6c 20 20 20 20 20 ine OE_Fail
117c0 33 20 20 20 2f 2a 20 53 74 6f 70 20 74 68 65 20 3 /* Stop the
117d0 6f 70 65 72 61 74 69 6f 6e 20 62 75 74 20 6c 65 operation but le
117e0 61 76 65 20 61 6c 6c 20 70 72 69 6f 72 20 63 68 ave all prior ch
117f0 61 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 anges */.#define
11800 20 4f 45 5f 49 67 6e 6f 72 65 20 20 20 34 20 20 OE_Ignore 4
11810 20 2f 2a 20 49 67 6e 6f 72 65 20 74 68 65 20 65 /* Ignore the e
11820 72 72 6f 72 2e 20 44 6f 20 6e 6f 74 20 64 6f 20 rror. Do not do
11830 74 68 65 20 49 4e 53 45 52 54 20 6f 72 20 55 50 the INSERT or UP
11840 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 DATE */.#define
11850 4f 45 5f 52 65 70 6c 61 63 65 20 20 35 20 20 20 OE_Replace 5
11860 2f 2a 20 44 65 6c 65 74 65 20 65 78 69 73 74 69 /* Delete existi
11870 6e 67 20 72 65 63 6f 72 64 2c 20 74 68 65 6e 20 ng record, then
11880 64 6f 20 49 4e 53 45 52 54 20 6f 72 20 55 50 44 do INSERT or UPD
11890 41 54 45 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 ATE */..#define
118a0 4f 45 5f 52 65 73 74 72 69 63 74 20 36 20 20 20 OE_Restrict 6
118b0 2f 2a 20 4f 45 5f 41 62 6f 72 74 20 66 6f 72 20 /* OE_Abort for
118c0 49 4d 4d 45 44 49 41 54 45 2c 20 4f 45 5f 52 6f IMMEDIATE, OE_Ro
118d0 6c 6c 62 61 63 6b 20 66 6f 72 20 44 45 46 45 52 llback for DEFER
118e0 52 45 44 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f RED */.#define O
118f0 45 5f 53 65 74 4e 75 6c 6c 20 20 37 20 20 20 2f E_SetNull 7 /
11900 2a 20 53 65 74 20 74 68 65 20 66 6f 72 65 69 67 * Set the foreig
11910 6e 20 6b 65 79 20 76 61 6c 75 65 20 74 6f 20 4e n key value to N
11920 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ULL */.#define O
11930 45 5f 53 65 74 44 66 6c 74 20 20 38 20 20 20 2f E_SetDflt 8 /
11940 2a 20 53 65 74 20 74 68 65 20 66 6f 72 65 69 67 * Set the foreig
11950 6e 20 6b 65 79 20 76 61 6c 75 65 20 74 6f 20 69 n key value to i
11960 74 73 20 64 65 66 61 75 6c 74 20 2a 2f 0a 23 64 ts default */.#d
11970 65 66 69 6e 65 20 4f 45 5f 43 61 73 63 61 64 65 efine OE_Cascade
11980 20 20 39 20 20 20 2f 2a 20 43 61 73 63 61 64 65 9 /* Cascade
11990 20 74 68 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a the changes */.
119a0 0a 23 64 65 66 69 6e 65 20 4f 45 5f 44 65 66 61 .#define OE_Defa
119b0 75 6c 74 20 20 31 30 20 20 2f 2a 20 44 6f 20 77 ult 10 /* Do w
119c0 68 61 74 65 76 65 72 20 74 68 65 20 64 65 66 61 hatever the defa
119d0 75 6c 74 20 61 63 74 69 6f 6e 20 69 73 20 2a 2f ult action is */
119e0 0a 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 .../*.** An inst
119f0 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c ance of the foll
11a00 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 owing structure
11a10 69 73 20 70 61 73 73 65 64 20 61 73 20 74 68 65 is passed as the
11a20 20 66 69 72 73 74 0a 2a 2a 20 61 72 67 75 6d 65 first.** argume
11a30 6e 74 20 74 6f 20 73 71 6c 69 74 65 33 56 64 62 nt to sqlite3Vdb
11a40 65 4b 65 79 43 6f 6d 70 61 72 65 20 61 6e 64 20 eKeyCompare and
11a50 69 73 20 75 73 65 64 20 74 6f 20 63 6f 6e 74 72 is used to contr
11a60 6f 6c 20 74 68 65 20 0a 2a 2a 20 63 6f 6d 70 61 ol the .** compa
11a70 72 69 73 6f 6e 20 6f 66 20 74 68 65 20 74 77 6f rison of the two
11a80 20 69 6e 64 65 78 20 6b 65 79 73 2e 0a 2a 2a 0a index keys..**.
11a90 2a 2a 20 4e 6f 74 65 20 74 68 61 74 20 61 53 6f ** Note that aSo
11aa0 72 74 4f 72 64 65 72 5b 5d 20 61 6e 64 20 61 43 rtOrder[] and aC
11ab0 6f 6c 6c 5b 5d 20 68 61 76 65 20 6e 46 69 65 6c oll[] have nFiel
11ac0 64 2b 31 20 73 6c 6f 74 73 2e 20 20 54 68 65 72 d+1 slots. Ther
11ad0 65 0a 2a 2a 20 61 72 65 20 6e 46 69 65 6c 64 20 e.** are nField
11ae0 73 6c 6f 74 73 20 66 6f 72 20 74 68 65 20 63 6f slots for the co
11af0 6c 75 6d 6e 73 20 6f 66 20 61 6e 20 69 6e 64 65 lumns of an inde
11b00 78 20 74 68 65 6e 20 6f 6e 65 20 65 78 74 72 61 x then one extra
11b10 20 73 6c 6f 74 0a 2a 2a 20 66 6f 72 20 74 68 65 slot.** for the
11b20 20 72 6f 77 69 64 20 61 74 20 74 68 65 20 65 6e rowid at the en
11b30 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4b 65 79 d..*/.struct Key
11b40 49 6e 66 6f 20 7b 0a 20 20 75 33 32 20 6e 52 65 Info {. u32 nRe
11b50 66 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 f; /*
11b60 4e 75 6d 62 65 72 20 6f 66 20 72 65 66 65 72 65 Number of refere
11b70 6e 63 65 73 20 74 6f 20 74 68 69 73 20 4b 65 79 nces to this Key
11b80 49 6e 66 6f 20 6f 62 6a 65 63 74 20 2a 2f 0a 20 Info object */.
11b90 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 20 u8 enc;
11ba0 20 20 20 20 20 2f 2a 20 54 65 78 74 20 65 6e 63 /* Text enc
11bb0 6f 64 69 6e 67 20 2d 20 6f 6e 65 20 6f 66 20 74 oding - one of t
11bc0 68 65 20 53 51 4c 49 54 45 5f 55 54 46 2a 20 76 he SQLITE_UTF* v
11bd0 61 6c 75 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e alues */. u16 n
11be0 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 20 2f Field; /
11bf0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6b 65 79 20 * Number of key
11c00 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 69 columns in the i
11c10 6e 64 65 78 20 2a 2f 0a 20 20 75 31 36 20 6e 58 ndex */. u16 nX
11c20 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 2f 2a Field; /*
11c30 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
11c40 6e 73 20 62 65 79 6f 6e 64 20 74 68 65 20 6b 65 ns beyond the ke
11c50 79 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 73 y columns */. s
11c60 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 qlite3 *db;
11c70 20 20 20 2f 2a 20 54 68 65 20 64 61 74 61 62 61 /* The databa
11c80 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f se connection */
11c90 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 . u8 *aSortOrde
11ca0 72 3b 20 20 20 20 20 2f 2a 20 53 6f 72 74 20 6f r; /* Sort o
11cb0 72 64 65 72 20 66 6f 72 20 65 61 63 68 20 63 6f rder for each co
11cc0 6c 75 6d 6e 2e 20 2a 2f 0a 20 20 43 6f 6c 6c 53 lumn. */. CollS
11cd0 65 71 20 2a 61 43 6f 6c 6c 5b 31 5d 3b 20 20 2f eq *aColl[1]; /
11ce0 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 * Collating sequ
11cf0 65 6e 63 65 20 66 6f 72 20 65 61 63 68 20 74 65 ence for each te
11d00 72 6d 20 6f 66 20 74 68 65 20 6b 65 79 20 2a 2f rm of the key */
11d10 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e .};../*.** An in
11d20 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f stance of the fo
11d30 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
11d40 65 20 68 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 74 e holds informat
11d50 69 6f 6e 20 61 62 6f 75 74 20 61 0a 2a 2a 20 73 ion about a.** s
11d60 69 6e 67 6c 65 20 69 6e 64 65 78 20 72 65 63 6f ingle index reco
11d70 72 64 20 74 68 61 74 20 68 61 73 20 61 6c 72 65 rd that has alre
11d80 61 64 79 20 62 65 65 6e 20 70 61 72 73 65 64 20 ady been parsed
11d90 6f 75 74 20 69 6e 74 6f 20 69 6e 64 69 76 69 64 out into individ
11da0 75 61 6c 0a 2a 2a 20 76 61 6c 75 65 73 2e 0a 2a ual.** values..*
11db0 2a 0a 2a 2a 20 41 20 72 65 63 6f 72 64 20 69 73 *.** A record is
11dc0 20 61 6e 20 6f 62 6a 65 63 74 20 74 68 61 74 20 an object that
11dd0 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 contains one or
11de0 6d 6f 72 65 20 66 69 65 6c 64 73 20 6f 66 20 64 more fields of d
11df0 61 74 61 2e 0a 2a 2a 20 52 65 63 6f 72 64 73 20 ata..** Records
11e00 61 72 65 20 75 73 65 64 20 74 6f 20 73 74 6f 72 are used to stor
11e10 65 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 e the content of
11e20 20 61 20 74 61 62 6c 65 20 72 6f 77 20 61 6e 64 a table row and
11e30 20 74 6f 20 73 74 6f 72 65 0a 2a 2a 20 74 68 65 to store.** the
11e40 20 6b 65 79 20 6f 66 20 61 6e 20 69 6e 64 65 78 key of an index
11e50 2e 20 20 41 20 62 6c 6f 62 20 65 6e 63 6f 64 69 . A blob encodi
11e60 6e 67 20 6f 66 20 61 20 72 65 63 6f 72 64 20 69 ng of a record i
11e70 73 20 63 72 65 61 74 65 64 20 62 79 0a 2a 2a 20 s created by.**
11e80 74 68 65 20 4f 50 5f 4d 61 6b 65 52 65 63 6f 72 the OP_MakeRecor
11e90 64 20 6f 70 63 6f 64 65 20 6f 66 20 74 68 65 20 d opcode of the
11ea0 56 44 42 45 20 61 6e 64 20 69 73 20 64 69 73 61 VDBE and is disa
11eb0 73 73 65 6d 62 6c 65 64 20 62 79 20 74 68 65 0a ssembled by the.
11ec0 2a 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 70 63 ** OP_Column opc
11ed0 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 ode..**.** This
11ee0 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 structure holds
11ef0 61 20 72 65 63 6f 72 64 20 74 68 61 74 20 68 61 a record that ha
11f00 73 20 61 6c 72 65 61 64 79 20 62 65 65 6e 20 64 s already been d
11f10 69 73 61 73 73 65 6d 62 6c 65 64 0a 2a 2a 20 69 isassembled.** i
11f20 6e 74 6f 20 69 74 73 20 63 6f 6e 73 74 69 74 75 nto its constitu
11f30 65 6e 74 20 66 69 65 6c 64 73 2e 0a 2a 2a 0a 2a ent fields..**.*
11f40 2a 20 54 68 65 20 72 31 20 61 6e 64 20 72 32 20 * The r1 and r2
11f50 6d 65 6d 62 65 72 20 76 61 72 69 61 62 6c 65 73 member variables
11f60 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 64 20 62 are only used b
11f70 79 20 74 68 65 20 6f 70 74 69 6d 69 7a 65 64 20 y the optimized
11f80 63 6f 6d 70 61 72 69 73 6f 6e 0a 2a 2a 20 66 75 comparison.** fu
11f90 6e 63 74 69 6f 6e 73 20 76 64 62 65 52 65 63 6f nctions vdbeReco
11fa0 72 64 43 6f 6d 70 61 72 65 49 6e 74 28 29 20 61 rdCompareInt() a
11fb0 6e 64 20 76 64 62 65 52 65 63 6f 72 64 43 6f 6d nd vdbeRecordCom
11fc0 70 61 72 65 53 74 72 69 6e 67 28 29 2e 0a 2a 2f pareString()..*/
11fd0 0a 73 74 72 75 63 74 20 55 6e 70 61 63 6b 65 64 .struct Unpacked
11fe0 52 65 63 6f 72 64 20 7b 0a 20 20 4b 65 79 49 6e Record {. KeyIn
11ff0 66 6f 20 2a 70 4b 65 79 49 6e 66 6f 3b 20 20 2f fo *pKeyInfo; /
12000 2a 20 43 6f 6c 6c 61 74 69 6f 6e 20 61 6e 64 20 * Collation and
12010 73 6f 72 74 2d 6f 72 64 65 72 20 69 6e 66 6f 72 sort-order infor
12020 6d 61 74 69 6f 6e 20 2a 2f 0a 20 20 75 31 36 20 mation */. u16
12030 6e 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 20 nField;
12040 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 /* Number of ent
12050 72 69 65 73 20 69 6e 20 61 70 4d 65 6d 5b 5d 20 ries in apMem[]
12060 2a 2f 0a 20 20 69 38 20 64 65 66 61 75 6c 74 5f */. i8 default_
12070 72 63 3b 20 20 20 20 20 20 2f 2a 20 43 6f 6d 70 rc; /* Comp
12080 61 72 69 73 6f 6e 20 72 65 73 75 6c 74 20 69 66 arison result if
12090 20 6b 65 79 73 20 61 72 65 20 65 71 75 61 6c 20 keys are equal
120a0 2a 2f 0a 20 20 75 38 20 65 72 72 43 6f 64 65 3b */. u8 errCode;
120b0 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 72 6f /* Erro
120c0 72 20 64 65 74 65 63 74 65 64 20 62 79 20 78 52 r detected by xR
120d0 65 63 6f 72 64 43 6f 6d 70 61 72 65 20 28 43 4f ecordCompare (CO
120e0 52 52 55 50 54 20 6f 72 20 4e 4f 4d 45 4d 29 20 RRUPT or NOMEM)
120f0 2a 2f 0a 20 20 4d 65 6d 20 2a 61 4d 65 6d 3b 20 */. Mem *aMem;
12100 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 /* Valu
12110 65 73 20 2a 2f 0a 20 20 69 6e 74 20 72 31 3b 20 es */. int r1;
12120 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 /* V
12130 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 69 alue to return i
12140 66 20 28 6c 68 73 20 3e 20 72 68 73 29 20 2a 2f f (lhs > rhs) */
12150 0a 20 20 69 6e 74 20 72 32 3b 20 20 20 20 20 20 . int r2;
12160 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 /* Value
12170 74 6f 20 72 65 74 75 72 6e 20 69 66 20 28 72 68 to return if (rh
12180 73 20 3c 20 6c 68 73 29 20 2a 2f 0a 7d 3b 0a 0a s < lhs) */.};..
12190 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 ./*.** Each SQL
121a0 69 6e 64 65 78 20 69 73 20 72 65 70 72 65 73 65 index is represe
121b0 6e 74 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20 62 nted in memory b
121c0 79 20 61 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 y an.** instance
121d0 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
121e0 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a g structure..**.
121f0 2a 2a 20 54 68 65 20 63 6f 6c 75 6d 6e 73 20 6f ** The columns o
12200 66 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 f the table that
12210 20 61 72 65 20 74 6f 20 62 65 20 69 6e 64 65 78 are to be index
12220 65 64 20 61 72 65 20 64 65 73 63 72 69 62 65 64 ed are described
12230 0a 2a 2a 20 62 79 20 74 68 65 20 61 69 43 6f 6c .** by the aiCol
12240 75 6d 6e 5b 5d 20 66 69 65 6c 64 20 6f 66 20 74 umn[] field of t
12250 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 his structure.
12260 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 73 75 70 For example, sup
12270 70 6f 73 65 0a 2a 2a 20 77 65 20 68 61 76 65 20 pose.** we have
12280 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 61 the following ta
12290 62 6c 65 20 61 6e 64 20 69 6e 64 65 78 3a 0a 2a ble and index:.*
122a0 2a 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 *.** CREATE
122b0 54 41 42 4c 45 20 45 78 31 28 63 31 20 69 6e 74 TABLE Ex1(c1 int
122c0 2c 20 63 32 20 69 6e 74 2c 20 63 33 20 74 65 78 , c2 int, c3 tex
122d0 74 29 3b 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 t);.** CREAT
122e0 45 20 49 4e 44 45 58 20 45 78 32 20 4f 4e 20 45 E INDEX Ex2 ON E
122f0 78 31 28 63 33 2c 63 31 29 3b 0a 2a 2a 0a 2a 2a x1(c3,c1);.**.**
12300 20 49 6e 20 74 68 65 20 54 61 62 6c 65 20 73 74 In the Table st
12310 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 69 ructure describi
12320 6e 67 20 45 78 31 2c 20 6e 43 6f 6c 3d 3d 33 20 ng Ex1, nCol==3
12330 62 65 63 61 75 73 65 20 74 68 65 72 65 20 61 72 because there ar
12340 65 0a 2a 2a 20 74 68 72 65 65 20 63 6f 6c 75 6d e.** three colum
12350 6e 73 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e ns in the table.
12360 20 20 49 6e 20 74 68 65 20 49 6e 64 65 78 20 73 In the Index s
12370 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 tructure describ
12380 69 6e 67 0a 2a 2a 20 45 78 32 2c 20 6e 43 6f 6c ing.** Ex2, nCol
12390 75 6d 6e 3d 3d 32 20 73 69 6e 63 65 20 32 20 6f umn==2 since 2 o
123a0 66 20 74 68 65 20 33 20 63 6f 6c 75 6d 6e 73 20 f the 3 columns
123b0 6f 66 20 45 78 31 20 61 72 65 20 69 6e 64 65 78 of Ex1 are index
123c0 65 64 2e 0a 2a 2a 20 54 68 65 20 76 61 6c 75 65 ed..** The value
123d0 20 6f 66 20 61 69 43 6f 6c 75 6d 6e 20 69 73 20 of aiColumn is
123e0 7b 32 2c 20 30 7d 2e 20 20 61 69 43 6f 6c 75 6d {2, 0}. aiColum
123f0 6e 5b 30 5d 3d 3d 32 20 62 65 63 61 75 73 65 20 n[0]==2 because
12400 74 68 65 20 0a 2a 2a 20 66 69 72 73 74 20 63 6f the .** first co
12410 6c 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 65 78 lumn to be index
12420 65 64 20 28 63 33 29 20 68 61 73 20 61 6e 20 69 ed (c3) has an i
12430 6e 64 65 78 20 6f 66 20 32 20 69 6e 20 45 78 31 ndex of 2 in Ex1
12440 2e 61 43 6f 6c 5b 5d 2e 0a 2a 2a 20 54 68 65 20 .aCol[]..** The
12450 73 65 63 6f 6e 64 20 63 6f 6c 75 6d 6e 20 74 6f second column to
12460 20 62 65 20 69 6e 64 65 78 65 64 20 28 63 31 29 be indexed (c1)
12470 20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 has an index of
12480 20 30 20 69 6e 0a 2a 2a 20 45 78 31 2e 61 43 6f 0 in.** Ex1.aCo
12490 6c 5b 5d 2c 20 68 65 6e 63 65 20 45 78 32 2e 61 l[], hence Ex2.a
124a0 69 43 6f 6c 75 6d 6e 5b 31 5d 3d 3d 30 2e 0a 2a iColumn[1]==0..*
124b0 2a 0a 2a 2a 20 54 68 65 20 49 6e 64 65 78 2e 6f *.** The Index.o
124c0 6e 45 72 72 6f 72 20 66 69 65 6c 64 20 64 65 74 nError field det
124d0 65 72 6d 69 6e 65 73 20 77 68 65 74 68 65 72 20 ermines whether
124e0 6f 72 20 6e 6f 74 20 74 68 65 20 69 6e 64 65 78 or not the index
124f0 65 64 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 6d 75 ed columns.** mu
12500 73 74 20 62 65 20 75 6e 69 71 75 65 20 61 6e 64 st be unique and
12510 20 77 68 61 74 20 74 6f 20 64 6f 20 69 66 20 74 what to do if t
12520 68 65 79 20 61 72 65 20 6e 6f 74 2e 20 20 57 68 hey are not. Wh
12530 65 6e 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 en Index.onError
12540 3d 4f 45 5f 4e 6f 6e 65 2c 0a 2a 2a 20 69 74 20 =OE_None,.** it
12550 6d 65 61 6e 73 20 74 68 69 73 20 69 73 20 6e 6f means this is no
12560 74 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 78 t a unique index
12570 2e 20 20 4f 74 68 65 72 77 69 73 65 20 69 74 20 . Otherwise it
12580 69 73 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 is a unique inde
12590 78 0a 2a 2a 20 61 6e 64 20 74 68 65 20 76 61 6c x.** and the val
125a0 75 65 20 6f 66 20 49 6e 64 65 78 2e 6f 6e 45 72 ue of Index.onEr
125b0 72 6f 72 20 69 6e 64 69 63 61 74 65 20 74 68 65 ror indicate the
125c0 20 77 68 69 63 68 20 63 6f 6e 66 6c 69 63 74 20 which conflict
125d0 72 65 73 6f 6c 75 74 69 6f 6e 20 0a 2a 2a 20 61 resolution .** a
125e0 6c 67 6f 72 69 74 68 6d 20 74 6f 20 65 6d 70 6c lgorithm to empl
125f0 6f 79 20 77 68 65 6e 65 76 65 72 20 61 6e 20 61 oy whenever an a
12600 74 74 65 6d 70 74 20 69 73 20 6d 61 64 65 20 74 ttempt is made t
12610 6f 20 69 6e 73 65 72 74 20 61 20 6e 6f 6e 2d 75 o insert a non-u
12620 6e 69 71 75 65 0a 2a 2a 20 65 6c 65 6d 65 6e 74 nique.** element
12630 2e 0a 2a 2a 0a 2a 2a 20 57 68 69 6c 65 20 70 61 ..**.** While pa
12640 72 73 69 6e 67 20 61 20 43 52 45 41 54 45 20 54 rsing a CREATE T
12650 41 42 4c 45 20 6f 72 20 43 52 45 41 54 45 20 49 ABLE or CREATE I
12660 4e 44 45 58 20 73 74 61 74 65 6d 65 6e 74 20 69 NDEX statement i
12670 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 65 n order to.** ge
12680 6e 65 72 61 74 65 20 56 44 42 45 20 63 6f 64 65 nerate VDBE code
12690 20 28 61 73 20 6f 70 70 6f 73 65 64 20 74 6f 20 (as opposed to
126a0 70 61 72 73 69 6e 67 20 6f 6e 65 20 72 65 61 64 parsing one read
126b0 20 66 72 6f 6d 20 61 6e 20 73 71 6c 69 74 65 5f from an sqlite_
126c0 6d 61 73 74 65 72 0a 2a 2a 20 74 61 62 6c 65 20 master.** table
126d0 61 73 20 70 61 72 74 20 6f 66 20 70 61 72 73 69 as part of parsi
126e0 6e 67 20 61 6e 20 65 78 69 73 74 69 6e 67 20 64 ng an existing d
126f0 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 29 2c atabase schema),
12700 20 74 72 61 6e 73 69 65 6e 74 20 69 6e 73 74 61 transient insta
12710 6e 63 65 73 0a 2a 2a 20 6f 66 20 74 68 69 73 20 nces.** of this
12720 73 74 72 75 63 74 75 72 65 20 6d 61 79 20 62 65 structure may be
12730 20 63 72 65 61 74 65 64 2e 20 49 6e 20 74 68 69 created. In thi
12740 73 20 63 61 73 65 20 74 68 65 20 49 6e 64 65 78 s case the Index
12750 2e 74 6e 75 6d 20 76 61 72 69 61 62 6c 65 20 69 .tnum variable i
12760 73 0a 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f s.** used to sto
12770 72 65 20 74 68 65 20 61 64 64 72 65 73 73 20 6f re the address o
12780 66 20 61 20 56 44 42 45 20 69 6e 73 74 72 75 63 f a VDBE instruc
12790 74 69 6f 6e 2c 20 6e 6f 74 20 61 20 64 61 74 61 tion, not a data
127a0 62 61 73 65 20 70 61 67 65 0a 2a 2a 20 6e 75 6d base page.** num
127b0 62 65 72 20 28 69 74 20 63 61 6e 6e 6f 74 20 2d ber (it cannot -
127c0 20 74 68 65 20 64 61 74 61 62 61 73 65 20 70 61 the database pa
127d0 67 65 20 69 73 20 6e 6f 74 20 61 6c 6c 6f 63 61 ge is not alloca
127e0 74 65 64 20 75 6e 74 69 6c 20 74 68 65 20 56 44 ted until the VD
127f0 42 45 0a 2a 2a 20 70 72 6f 67 72 61 6d 20 69 73 BE.** program is
12800 20 65 78 65 63 75 74 65 64 29 2e 20 53 65 65 20 executed). See
12810 63 6f 6e 76 65 72 74 54 6f 57 69 74 68 6f 75 74 convertToWithout
12820 52 6f 77 69 64 54 61 62 6c 65 28 29 20 66 6f 72 RowidTable() for
12830 20 64 65 74 61 69 6c 73 2e 0a 2a 2f 0a 73 74 72 details..*/.str
12840 75 63 74 20 49 6e 64 65 78 20 7b 0a 20 20 63 68 uct Index {. ch
12850 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
12860 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
12870 66 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a f this index */.
12880 20 20 69 31 36 20 2a 61 69 43 6f 6c 75 6d 6e 3b i16 *aiColumn;
12890 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 /* Wh
128a0 69 63 68 20 63 6f 6c 75 6d 6e 73 20 61 72 65 20 ich columns are
128b0 75 73 65 64 20 62 79 20 74 68 69 73 20 69 6e 64 used by this ind
128c0 65 78 2e 20 20 31 73 74 20 69 73 20 30 20 2a 2f ex. 1st is 0 */
128d0 0a 20 20 4c 6f 67 45 73 74 20 2a 61 69 52 6f 77 . LogEst *aiRow
128e0 4c 6f 67 45 73 74 3b 20 20 20 20 20 2f 2a 20 46 LogEst; /* F
128f0 72 6f 6d 20 41 4e 41 4c 59 5a 45 3a 20 45 73 74 rom ANALYZE: Est
12900 2e 20 72 6f 77 73 20 73 65 6c 65 63 74 65 64 20 . rows selected
12910 62 79 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a by each column *
12920 2f 0a 20 20 54 61 62 6c 65 20 2a 70 54 61 62 6c /. Table *pTabl
12930 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 e; /*
12940 54 68 65 20 53 51 4c 20 74 61 62 6c 65 20 62 65 The SQL table be
12950 69 6e 67 20 69 6e 64 65 78 65 64 20 2a 2f 0a 20 ing indexed */.
12960 20 63 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b 20 char *zColAff;
12970 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 72 /* Str
12980 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 68 65 ing defining the
12990 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 61 63 affinity of eac
129a0 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e h column */. In
129b0 64 65 78 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 dex *pNext;
129c0 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 65 /* The ne
129d0 78 74 20 69 6e 64 65 78 20 61 73 73 6f 63 69 61 xt index associa
129e0 74 65 64 20 77 69 74 68 20 74 68 65 20 73 61 6d ted with the sam
129f0 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 53 63 68 e table */. Sch
12a00 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 ema *pSchema;
12a10 20 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 /* Schema
12a20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 69 73 20 containing this
12a30 69 6e 64 65 78 20 2a 2f 0a 20 20 75 38 20 2a 61 index */. u8 *a
12a40 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 20 SortOrder;
12a50 20 20 20 20 2f 2a 20 66 6f 72 20 65 61 63 68 20 /* for each
12a60 63 6f 6c 75 6d 6e 3a 20 54 72 75 65 3d 3d 44 45 column: True==DE
12a70 53 43 2c 20 46 61 6c 73 65 3d 3d 41 53 43 20 2a SC, False==ASC *
12a80 2f 0a 20 20 63 68 61 72 20 2a 2a 61 7a 43 6f 6c /. char **azCol
12a90 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 l; /*
12aa0 41 72 72 61 79 20 6f 66 20 63 6f 6c 6c 61 74 69 Array of collati
12ab0 6f 6e 20 73 65 71 75 65 6e 63 65 20 6e 61 6d 65 on sequence name
12ac0 73 20 66 6f 72 20 69 6e 64 65 78 20 2a 2f 0a 20 s for index */.
12ad0 20 45 78 70 72 20 2a 70 50 61 72 74 49 64 78 57 Expr *pPartIdxW
12ae0 68 65 72 65 3b 20 20 20 20 20 2f 2a 20 57 48 45 here; /* WHE
12af0 52 45 20 63 6c 61 75 73 65 20 66 6f 72 20 70 61 RE clause for pa
12b00 72 74 69 61 6c 20 69 6e 64 69 63 65 73 20 2a 2f rtial indices */
12b10 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 61 43 6f . ExprList *aCo
12b20 6c 45 78 70 72 3b 20 20 20 20 20 20 2f 2a 20 43 lExpr; /* C
12b30 6f 6c 75 6d 6e 20 65 78 70 72 65 73 73 69 6f 6e olumn expression
12b40 73 20 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 6d 3b s */. int tnum;
12b50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12b60 2f 2a 20 44 42 20 50 61 67 65 20 63 6f 6e 74 61 /* DB Page conta
12b70 69 6e 69 6e 67 20 72 6f 6f 74 20 6f 66 20 74 68 ining root of th
12b80 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 4c 6f is index */. Lo
12b90 67 45 73 74 20 73 7a 49 64 78 52 6f 77 3b 20 20 gEst szIdxRow;
12ba0 20 20 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 /* Estima
12bb0 74 65 64 20 61 76 65 72 61 67 65 20 72 6f 77 20 ted average row
12bc0 73 69 7a 65 20 69 6e 20 62 79 74 65 73 20 2a 2f size in bytes */
12bd0 0a 20 20 75 31 36 20 6e 4b 65 79 43 6f 6c 3b 20 . u16 nKeyCol;
12be0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
12bf0 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 umber of columns
12c00 20 66 6f 72 6d 69 6e 67 20 74 68 65 20 6b 65 79 forming the key
12c10 20 2a 2f 0a 20 20 75 31 36 20 6e 43 6f 6c 75 6d */. u16 nColum
12c20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f n; /
12c30 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 * Number of colu
12c40 6d 6e 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 mns stored in th
12c50 65 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 38 20 e index */. u8
12c60 6f 6e 45 72 72 6f 72 3b 20 20 20 20 20 20 20 20 onError;
12c70 20 20 20 20 20 20 2f 2a 20 4f 45 5f 41 62 6f 72 /* OE_Abor
12c80 74 2c 20 4f 45 5f 49 67 6e 6f 72 65 2c 20 4f 45 t, OE_Ignore, OE
12c90 5f 52 65 70 6c 61 63 65 2c 20 6f 72 20 4f 45 5f _Replace, or OE_
12ca0 4e 6f 6e 65 20 2a 2f 0a 20 20 75 6e 73 69 67 6e None */. unsign
12cb0 65 64 20 69 64 78 54 79 70 65 3a 32 3b 20 20 20 ed idxType:2;
12cc0 20 20 20 2f 2a 20 31 3d 3d 55 4e 49 51 55 45 2c /* 1==UNIQUE,
12cd0 20 32 3d 3d 50 52 49 4d 41 52 59 20 4b 45 59 2c 2==PRIMARY KEY,
12ce0 20 30 3d 3d 43 52 45 41 54 45 20 49 4e 44 45 58 0==CREATE INDEX
12cf0 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 62 */. unsigned b
12d00 55 6e 6f 72 64 65 72 65 64 3a 31 3b 20 20 20 2f Unordered:1; /
12d10 2a 20 55 73 65 20 74 68 69 73 20 69 6e 64 65 78 * Use this index
12d20 20 66 6f 72 20 3d 3d 20 6f 72 20 49 4e 20 71 75 for == or IN qu
12d30 65 72 69 65 73 20 6f 6e 6c 79 20 2a 2f 0a 20 20 eries only */.
12d40 75 6e 73 69 67 6e 65 64 20 75 6e 69 71 4e 6f 74 unsigned uniqNot
12d50 4e 75 6c 6c 3a 31 3b 20 20 2f 2a 20 54 72 75 65 Null:1; /* True
12d60 20 69 66 20 55 4e 49 51 55 45 20 61 6e 64 20 4e if UNIQUE and N
12d70 4f 54 20 4e 55 4c 4c 20 66 6f 72 20 61 6c 6c 20 OT NULL for all
12d80 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 75 6e 73 columns */. uns
12d90 69 67 6e 65 64 20 69 73 52 65 73 69 7a 65 64 3a igned isResized:
12da0 31 3b 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 1; /* True if
12db0 20 72 65 73 69 7a 65 49 6e 64 65 78 4f 62 6a 65 resizeIndexObje
12dc0 63 74 28 29 20 68 61 73 20 62 65 65 6e 20 63 61 ct() has been ca
12dd0 6c 6c 65 64 20 2a 2f 0a 20 20 75 6e 73 69 67 6e lled */. unsign
12de0 65 64 20 69 73 43 6f 76 65 72 69 6e 67 3a 31 3b ed isCovering:1;
12df0 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 /* True if th
12e00 69 73 20 69 73 20 61 20 63 6f 76 65 72 69 6e 67 is is a covering
12e10 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 6e 73 69 index */. unsi
12e20 67 6e 65 64 20 6e 6f 53 6b 69 70 53 63 61 6e 3a gned noSkipScan:
12e30 31 3b 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 74 1; /* Do not t
12e40 72 79 20 74 6f 20 75 73 65 20 73 6b 69 70 2d 73 ry to use skip-s
12e50 63 61 6e 20 69 66 20 74 72 75 65 20 2a 2f 0a 23 can if true */.#
12e60 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
12e70 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
12e80 54 34 0a 20 20 69 6e 74 20 6e 53 61 6d 70 6c 65 T4. int nSample
12e90 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
12ea0 20 4e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 Number of eleme
12eb0 6e 74 73 20 69 6e 20 61 53 61 6d 70 6c 65 5b 5d nts in aSample[]
12ec0 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 6d 70 6c */. int nSampl
12ed0 65 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 2f eCol; /
12ee0 2a 20 53 69 7a 65 20 6f 66 20 49 6e 64 65 78 53 * Size of IndexS
12ef0 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d 20 61 6e 64 ample.anEq[] and
12f00 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 74 52 6f 77 so on */. tRow
12f10 63 6e 74 20 2a 61 41 76 67 45 71 3b 20 20 20 20 cnt *aAvgEq;
12f20 20 20 20 20 20 2f 2a 20 41 76 65 72 61 67 65 20 /* Average
12f30 6e 45 71 20 76 61 6c 75 65 73 20 66 6f 72 20 6b nEq values for k
12f40 65 79 73 20 6e 6f 74 20 69 6e 20 61 53 61 6d 70 eys not in aSamp
12f50 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 78 53 61 6d le */. IndexSam
12f60 70 6c 65 20 2a 61 53 61 6d 70 6c 65 3b 20 20 20 ple *aSample;
12f70 20 2f 2a 20 53 61 6d 70 6c 65 73 20 6f 66 20 74 /* Samples of t
12f80 68 65 20 6c 65 66 74 2d 6d 6f 73 74 20 6b 65 79 he left-most key
12f90 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 */. tRowcnt *a
12fa0 69 52 6f 77 45 73 74 3b 20 20 20 20 20 20 20 2f iRowEst; /
12fb0 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 * Non-logarithmi
12fc0 63 20 73 74 61 74 31 20 64 61 74 61 20 66 6f 72 c stat1 data for
12fd0 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 this index */.
12fe0 20 74 52 6f 77 63 6e 74 20 6e 52 6f 77 45 73 74 tRowcnt nRowEst
12ff0 30 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 0; /* Non
13000 2d 6c 6f 67 61 72 69 74 68 6d 69 63 20 6e 75 6d -logarithmic num
13010 62 65 72 20 6f 66 20 72 6f 77 73 20 69 6e 20 74 ber of rows in t
13020 68 65 20 69 6e 64 65 78 20 2a 2f 0a 23 65 6e 64 he index */.#end
13030 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c if.};../*.** All
13040 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 owed values for
13050 49 6e 64 65 78 2e 69 64 78 54 79 70 65 0a 2a 2f Index.idxType.*/
13060 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
13070 49 44 58 54 59 50 45 5f 41 50 50 44 45 46 20 20 IDXTYPE_APPDEF
13080 20 20 20 20 30 20 20 20 2f 2a 20 43 72 65 61 74 0 /* Creat
13090 65 64 20 75 73 69 6e 67 20 43 52 45 41 54 45 20 ed using CREATE
130a0 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 69 6e 65 INDEX */.#define
130b0 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f SQLITE_IDXTYPE_
130c0 55 4e 49 51 55 45 20 20 20 20 20 20 31 20 20 20 UNIQUE 1
130d0 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 73 20 61 20 /* Implements a
130e0 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 69 6e UNIQUE constrain
130f0 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c t */.#define SQL
13100 49 54 45 5f 49 44 58 54 59 50 45 5f 50 52 49 4d ITE_IDXTYPE_PRIM
13110 41 52 59 4b 45 59 20 20 32 20 20 20 2f 2a 20 49 ARYKEY 2 /* I
13120 73 20 74 68 65 20 50 52 49 4d 41 52 59 20 4b 45 s the PRIMARY KE
13130 59 20 66 6f 72 20 74 68 65 20 74 61 62 6c 65 20 Y for the table
13140 2a 2f 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 74 72 */../* Return tr
13150 75 65 20 69 66 20 69 6e 64 65 78 20 58 20 69 73 ue if index X is
13160 20 61 20 50 52 49 4d 41 52 59 20 4b 45 59 20 69 a PRIMARY KEY i
13170 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ndex */.#define
13180 49 73 50 72 69 6d 61 72 79 4b 65 79 49 6e 64 65 IsPrimaryKeyInde
13190 78 28 58 29 20 20 28 28 58 29 2d 3e 69 64 78 54 x(X) ((X)->idxT
131a0 79 70 65 3d 3d 53 51 4c 49 54 45 5f 49 44 58 54 ype==SQLITE_IDXT
131b0 59 50 45 5f 50 52 49 4d 41 52 59 4b 45 59 29 0a YPE_PRIMARYKEY).
131c0 0a 2f 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 ./* Return true
131d0 69 66 20 69 6e 64 65 78 20 58 20 69 73 20 61 20 if index X is a
131e0 55 4e 49 51 55 45 20 69 6e 64 65 78 20 2a 2f 0a UNIQUE index */.
131f0 23 64 65 66 69 6e 65 20 49 73 55 6e 69 71 75 65 #define IsUnique
13200 49 6e 64 65 78 28 58 29 20 20 20 20 20 20 28 28 Index(X) ((
13210 58 29 2d 3e 6f 6e 45 72 72 6f 72 21 3d 4f 45 5f X)->onError!=OE_
13220 4e 6f 6e 65 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 None)../*.** Eac
13230 68 20 73 61 6d 70 6c 65 20 73 74 6f 72 65 64 20 h sample stored
13240 69 6e 20 74 68 65 20 73 71 6c 69 74 65 5f 73 74 in the sqlite_st
13250 61 74 33 20 74 61 62 6c 65 20 69 73 20 72 65 70 at3 table is rep
13260 72 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 6d 6f resented in memo
13270 72 79 20 0a 2a 2a 20 75 73 69 6e 67 20 61 20 73 ry .** using a s
13280 74 72 75 63 74 75 72 65 20 6f 66 20 74 68 69 73 tructure of this
13290 20 74 79 70 65 2e 20 20 53 65 65 20 64 6f 63 75 type. See docu
132a0 6d 65 6e 74 61 74 69 6f 6e 20 61 74 20 74 68 65 mentation at the
132b0 20 74 6f 70 20 6f 66 20 74 68 65 0a 2a 2a 20 61 top of the.** a
132c0 6e 61 6c 79 7a 65 2e 63 20 73 6f 75 72 63 65 20 nalyze.c source
132d0 66 69 6c 65 20 66 6f 72 20 61 64 64 69 74 69 6f file for additio
132e0 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e nal information.
132f0 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 78 .*/.struct Index
13300 53 61 6d 70 6c 65 20 7b 0a 20 20 76 6f 69 64 20 Sample {. void
13310 2a 70 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 *p; /*
13320 50 6f 69 6e 74 65 72 20 74 6f 20 73 61 6d 70 6c Pointer to sampl
13330 65 64 20 72 65 63 6f 72 64 20 2a 2f 0a 20 20 69 ed record */. i
13340 6e 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 nt n;
13350 20 2f 2a 20 53 69 7a 65 20 6f 66 20 72 65 63 6f /* Size of reco
13360 72 64 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 rd in bytes */.
13370 20 74 52 6f 77 63 6e 74 20 2a 61 6e 45 71 3b 20 tRowcnt *anEq;
13380 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 /* Est. numbe
13390 72 20 6f 66 20 72 6f 77 73 20 77 68 65 72 65 20 r of rows where
133a0 74 68 65 20 6b 65 79 20 65 71 75 61 6c 73 20 74 the key equals t
133b0 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 20 his sample */.
133c0 74 52 6f 77 63 6e 74 20 2a 61 6e 4c 74 3b 20 20 tRowcnt *anLt;
133d0 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 /* Est. number
133e0 20 6f 66 20 72 6f 77 73 20 77 68 65 72 65 20 6b of rows where k
133f0 65 79 20 69 73 20 6c 65 73 73 20 74 68 61 6e 20 ey is less than
13400 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 this sample */.
13410 20 74 52 6f 77 63 6e 74 20 2a 61 6e 44 4c 74 3b tRowcnt *anDLt;
13420 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 /* Est. numbe
13430 72 20 6f 66 20 64 69 73 74 69 6e 63 74 20 6b 65 r of distinct ke
13440 79 73 20 6c 65 73 73 20 74 68 61 6e 20 74 68 69 ys less than thi
13450 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 7d 3b 0a 0a s sample */.};..
13460 2f 2a 0a 2a 2a 20 45 61 63 68 20 74 6f 6b 65 6e /*.** Each token
13470 20 63 6f 6d 69 6e 67 20 6f 75 74 20 6f 66 20 74 coming out of t
13480 68 65 20 6c 65 78 65 72 20 69 73 20 61 6e 20 69 he lexer is an i
13490 6e 73 74 61 6e 63 65 20 6f 66 0a 2a 2a 20 74 68 nstance of.** th
134a0 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 54 is structure. T
134b0 6f 6b 65 6e 73 20 61 72 65 20 61 6c 73 6f 20 75 okens are also u
134c0 73 65 64 20 61 73 20 70 61 72 74 20 6f 66 20 61 sed as part of a
134d0 6e 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a 2a n expression..**
134e0 0a 2a 2a 20 4e 6f 74 65 20 69 66 20 54 6f 6b 65 .** Note if Toke
134f0 6e 2e 7a 3d 3d 30 20 74 68 65 6e 20 54 6f 6b 65 n.z==0 then Toke
13500 6e 2e 64 79 6e 20 61 6e 64 20 54 6f 6b 65 6e 2e n.dyn and Token.
13510 6e 20 61 72 65 20 75 6e 64 65 66 69 6e 65 64 20 n are undefined
13520 61 6e 64 0a 2a 2a 20 6d 61 79 20 63 6f 6e 74 61 and.** may conta
13530 69 6e 20 72 61 6e 64 6f 6d 20 76 61 6c 75 65 73 in random values
13540 2e 20 20 44 6f 20 6e 6f 74 20 6d 61 6b 65 20 61 . Do not make a
13550 6e 79 20 61 73 73 75 6d 70 74 69 6f 6e 73 20 61 ny assumptions a
13560 62 6f 75 74 20 54 6f 6b 65 6e 2e 64 79 6e 0a 2a bout Token.dyn.*
13570 2a 20 61 6e 64 20 54 6f 6b 65 6e 2e 6e 20 77 68 * and Token.n wh
13580 65 6e 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 2e 0a 2a en Token.z==0..*
13590 2f 0a 73 74 72 75 63 74 20 54 6f 6b 65 6e 20 7b /.struct Token {
135a0 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
135b0 3b 20 20 20 20 20 2f 2a 20 54 65 78 74 20 6f 66 ; /* Text of
135c0 20 74 68 65 20 74 6f 6b 65 6e 2e 20 20 4e 6f 74 the token. Not
135d0 20 4e 55 4c 4c 2d 74 65 72 6d 69 6e 61 74 65 64 NULL-terminated
135e0 21 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 ! */. unsigned
135f0 69 6e 74 20 6e 3b 20 20 20 20 2f 2a 20 4e 75 6d int n; /* Num
13600 62 65 72 20 6f 66 20 63 68 61 72 61 63 74 65 72 ber of character
13610 73 20 69 6e 20 74 68 69 73 20 74 6f 6b 65 6e 20 s in this token
13620 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 */.};../*.** An
13630 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 instance of this
13640 20 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 structure conta
13650 69 6e 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 ins information
13660 6e 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 61 needed to genera
13670 74 65 0a 2a 2a 20 63 6f 64 65 20 66 6f 72 20 61 te.** code for a
13680 20 53 45 4c 45 43 54 20 74 68 61 74 20 63 6f 6e SELECT that con
13690 74 61 69 6e 73 20 61 67 67 72 65 67 61 74 65 20 tains aggregate
136a0 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a functions..**.**
136b0 20 49 66 20 45 78 70 72 2e 6f 70 3d 3d 54 4b 5f If Expr.op==TK_
136c0 41 47 47 5f 43 4f 4c 55 4d 4e 20 6f 72 20 54 4b AGG_COLUMN or TK
136d0 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e 20 74 68 _AGG_FUNCTION th
136e0 65 6e 20 45 78 70 72 2e 70 41 67 67 49 6e 66 6f en Expr.pAggInfo
136f0 20 69 73 20 61 0a 2a 2a 20 70 6f 69 6e 74 65 72 is a.** pointer
13700 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 to this structu
13710 72 65 2e 20 20 54 68 65 20 45 78 70 72 2e 69 43 re. The Expr.iC
13720 6f 6c 75 6d 6e 20 66 69 65 6c 64 20 69 73 20 74 olumn field is t
13730 68 65 20 69 6e 64 65 78 20 69 6e 0a 2a 2a 20 41 he index in.** A
13740 67 67 49 6e 66 6f 2e 61 43 6f 6c 5b 5d 20 6f 72 ggInfo.aCol[] or
13750 20 41 67 67 49 6e 66 6f 2e 61 46 75 6e 63 5b 5d AggInfo.aFunc[]
13760 20 6f 66 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 of information
13770 6e 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 61 needed to genera
13780 74 65 0a 2a 2a 20 63 6f 64 65 20 66 6f 72 20 74 te.** code for t
13790 68 61 74 20 6e 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 hat node..**.**
137a0 41 67 67 49 6e 66 6f 2e 70 47 72 6f 75 70 42 79 AggInfo.pGroupBy
137b0 20 61 6e 64 20 41 67 67 49 6e 66 6f 2e 61 46 75 and AggInfo.aFu
137c0 6e 63 2e 70 45 78 70 72 20 70 6f 69 6e 74 20 74 nc.pExpr point t
137d0 6f 20 66 69 65 6c 64 73 20 77 69 74 68 69 6e 20 o fields within
137e0 74 68 65 0a 2a 2a 20 6f 72 69 67 69 6e 61 6c 20 the.** original
137f0 53 65 6c 65 63 74 20 73 74 72 75 63 74 75 72 65 Select structure
13800 20 74 68 61 74 20 64 65 73 63 72 69 62 65 73 20 that describes
13810 74 68 65 20 53 45 4c 45 43 54 20 73 74 61 74 65 the SELECT state
13820 6d 65 6e 74 2e 20 20 54 68 65 73 65 0a 2a 2a 20 ment. These.**
13830 66 69 65 6c 64 73 20 64 6f 20 6e 6f 74 20 6e 65 fields do not ne
13840 65 64 20 74 6f 20 62 65 20 66 72 65 65 64 20 77 ed to be freed w
13850 68 65 6e 20 64 65 61 6c 6c 6f 63 61 74 69 6e 67 hen deallocating
13860 20 74 68 65 20 41 67 67 49 6e 66 6f 20 73 74 72 the AggInfo str
13870 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 ucture..*/.struc
13880 74 20 41 67 67 49 6e 66 6f 20 7b 0a 20 20 75 38 t AggInfo {. u8
13890 20 64 69 72 65 63 74 4d 6f 64 65 3b 20 20 20 20 directMode;
138a0 20 20 20 20 20 20 2f 2a 20 44 69 72 65 63 74 20 /* Direct
138b0 72 65 6e 64 65 72 69 6e 67 20 6d 6f 64 65 20 6d rendering mode m
138c0 65 61 6e 73 20 74 61 6b 65 20 64 61 74 61 20 64 eans take data d
138d0 69 72 65 63 74 6c 79 0a 20 20 20 20 20 20 20 20 irectly.
138e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
138f0 20 20 2a 2a 20 66 72 6f 6d 20 73 6f 75 72 63 65 ** from source
13900 20 74 61 62 6c 65 73 20 72 61 74 68 65 72 20 74 tables rather t
13910 68 61 6e 20 66 72 6f 6d 20 61 63 63 75 6d 75 6c han from accumul
13920 61 74 6f 72 73 20 2a 2f 0a 20 20 75 38 20 75 73 ators */. u8 us
13930 65 53 6f 72 74 69 6e 67 49 64 78 3b 20 20 20 20 eSortingIdx;
13940 20 20 20 2f 2a 20 49 6e 20 64 69 72 65 63 74 20 /* In direct
13950 6d 6f 64 65 2c 20 72 65 66 65 72 65 6e 63 65 20 mode, reference
13960 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 the sorting inde
13970 78 20 72 61 74 68 65 72 0a 20 20 20 20 20 20 20 x rather.
13980 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13990 20 20 20 2a 2a 20 74 68 61 6e 20 74 68 65 20 73 ** than the s
139a0 6f 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 ource table */.
139b0 20 69 6e 74 20 73 6f 72 74 69 6e 67 49 64 78 3b int sortingIdx;
139c0 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 73 /* Curs
139d0 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 65 or number of the
139e0 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 2a sorting index *
139f0 2f 0a 20 20 69 6e 74 20 73 6f 72 74 69 6e 67 49 /. int sortingI
13a00 64 78 50 54 61 62 3b 20 20 20 20 20 2f 2a 20 43 dxPTab; /* C
13a10 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 ursor number of
13a20 70 73 65 75 64 6f 2d 74 61 62 6c 65 20 2a 2f 0a pseudo-table */.
13a30 20 20 69 6e 74 20 6e 53 6f 72 74 69 6e 67 43 6f int nSortingCo
13a40 6c 75 6d 6e 3b 20 20 20 20 20 2f 2a 20 4e 75 6d lumn; /* Num
13a50 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 ber of columns i
13a60 6e 20 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e n the sorting in
13a70 64 65 78 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 dex */. int mnR
13a80 65 67 2c 20 6d 78 52 65 67 3b 20 20 20 20 20 20 eg, mxReg;
13a90 20 2f 2a 20 52 61 6e 67 65 20 6f 66 20 72 65 67 /* Range of reg
13aa0 69 73 74 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 isters allocated
13ab0 20 66 6f 72 20 61 43 6f 6c 20 61 6e 64 20 61 46 for aCol and aF
13ac0 75 6e 63 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 unc */. ExprLis
13ad0 74 20 2a 70 47 72 6f 75 70 42 79 3b 20 20 20 20 t *pGroupBy;
13ae0 20 2f 2a 20 54 68 65 20 67 72 6f 75 70 20 62 79 /* The group by
13af0 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 73 74 72 clause */. str
13b00 75 63 74 20 41 67 67 49 6e 66 6f 5f 63 6f 6c 20 uct AggInfo_col
13b10 7b 20 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 { /* For each
13b20 20 63 6f 6c 75 6d 6e 20 75 73 65 64 20 69 6e 20 column used in
13b30 73 6f 75 72 63 65 20 74 61 62 6c 65 73 20 2a 2f source tables */
13b40 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 54 61 62 . Table *pTab
13b50 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
13b60 20 53 6f 75 72 63 65 20 74 61 62 6c 65 20 2a 2f Source table */
13b70 0a 20 20 20 20 69 6e 74 20 69 54 61 62 6c 65 3b . int iTable;
13b80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
13b90 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f Cursor number o
13ba0 66 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 62 f the source tab
13bb0 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 43 le */. int iC
13bc0 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 olumn;
13bd0 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d /* Column num
13be0 62 65 72 20 77 69 74 68 69 6e 20 74 68 65 20 73 ber within the s
13bf0 6f 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 ource table */.
13c00 20 20 20 69 6e 74 20 69 53 6f 72 74 65 72 43 6f int iSorterCo
13c10 6c 75 6d 6e 3b 20 20 20 20 20 20 20 2f 2a 20 43 lumn; /* C
13c20 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e 20 olumn number in
13c30 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 the sorting inde
13c40 78 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4d 65 x */. int iMe
13c50 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 m;
13c60 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 /* Memory loca
13c70 74 69 6f 6e 20 74 68 61 74 20 61 63 74 73 20 61 tion that acts a
13c80 73 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 2a 2f s accumulator */
13c90 0a 20 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 . Expr *pExpr
13ca0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
13cb0 20 54 68 65 20 6f 72 69 67 69 6e 61 6c 20 65 78 The original ex
13cc0 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 7d 20 pression */. }
13cd0 2a 61 43 6f 6c 3b 0a 20 20 69 6e 74 20 6e 43 6f *aCol;. int nCo
13ce0 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 20 lumn;
13cf0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 75 73 /* Number of us
13d00 65 64 20 65 6e 74 72 69 65 73 20 69 6e 20 61 43 ed entries in aC
13d10 6f 6c 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 ol[] */. int nA
13d20 63 63 75 6d 75 6c 61 74 6f 72 3b 20 20 20 20 20 ccumulator;
13d30 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
13d40 6f 6c 75 6d 6e 73 20 74 68 61 74 20 73 68 6f 77 olumns that show
13d50 20 74 68 72 6f 75 67 68 20 74 6f 20 74 68 65 20 through to the
13d60 6f 75 74 70 75 74 2e 0a 20 20 20 20 20 20 20 20 output..
13d70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13d80 20 20 2a 2a 20 41 64 64 69 74 69 6f 6e 61 6c 20 ** Additional
13d90 63 6f 6c 75 6d 6e 73 20 61 72 65 20 75 73 65 64 columns are used
13da0 20 6f 6e 6c 79 20 61 73 20 70 61 72 61 6d 65 74 only as paramet
13db0 65 72 73 20 74 6f 0a 20 20 20 20 20 20 20 20 20 ers to.
13dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13dd0 20 2a 2a 20 61 67 67 72 65 67 61 74 65 20 66 75 ** aggregate fu
13de0 6e 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 nctions */. str
13df0 75 63 74 20 41 67 67 49 6e 66 6f 5f 66 75 6e 63 uct AggInfo_func
13e00 20 7b 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 { /* For each
13e10 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 aggregate funct
13e20 69 6f 6e 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 ion */. Expr
13e30 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 *pExpr;
13e40 20 20 20 20 2f 2a 20 45 78 70 72 65 73 73 69 6f /* Expressio
13e50 6e 20 65 6e 63 6f 64 69 6e 67 20 74 68 65 20 66 n encoding the f
13e60 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 46 unction */. F
13e70 75 6e 63 44 65 66 20 2a 70 46 75 6e 63 3b 20 20 uncDef *pFunc;
13e80 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 61 /* The a
13e90 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
13ea0 6e 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e n implementation
13eb0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4d 65 6d */. int iMem
13ec0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
13ed0 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 /* Memory locat
13ee0 69 6f 6e 20 74 68 61 74 20 61 63 74 73 20 61 73 ion that acts as
13ef0 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a accumulator */.
13f00 20 20 20 20 69 6e 74 20 69 44 69 73 74 69 6e 63 int iDistinc
13f10 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
13f20 45 70 68 65 6d 65 72 61 6c 20 74 61 62 6c 65 20 Ephemeral table
13f30 75 73 65 64 20 74 6f 20 65 6e 66 6f 72 63 65 20 used to enforce
13f40 44 49 53 54 49 4e 43 54 20 2a 2f 0a 20 20 7d 20 DISTINCT */. }
13f50 2a 61 46 75 6e 63 3b 0a 20 20 69 6e 74 20 6e 46 *aFunc;. int nF
13f60 75 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 unc;
13f70 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
13f80 6e 74 72 69 65 73 20 69 6e 20 61 46 75 6e 63 5b ntries in aFunc[
13f90 5d 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 ] */.};../*.** T
13fa0 68 65 20 64 61 74 61 74 79 70 65 20 79 6e 56 61 he datatype ynVa
13fb0 72 20 69 73 20 61 20 73 69 67 6e 65 64 20 69 6e r is a signed in
13fc0 74 65 67 65 72 2c 20 65 69 74 68 65 72 20 31 36 teger, either 16
13fd0 2d 62 69 74 20 6f 72 20 33 32 2d 62 69 74 2e 0a -bit or 32-bit..
13fe0 2a 2a 20 55 73 75 61 6c 6c 79 20 69 74 20 69 73 ** Usually it is
13ff0 20 31 36 2d 62 69 74 73 2e 20 20 42 75 74 20 69 16-bits. But i
14000 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52 f SQLITE_MAX_VAR
14010 49 41 42 4c 45 5f 4e 55 4d 42 45 52 20 69 73 20 IABLE_NUMBER is
14020 67 72 65 61 74 65 72 0a 2a 2a 20 74 68 61 6e 20 greater.** than
14030 33 32 37 36 37 20 77 65 20 68 61 76 65 20 74 6f 32767 we have to
14040 20 6d 61 6b 65 20 69 74 20 33 32 2d 62 69 74 2e make it 32-bit.
14050 20 20 31 36 2d 62 69 74 20 69 73 20 70 72 65 66 16-bit is pref
14060 65 72 72 65 64 20 62 65 63 61 75 73 65 0a 2a 2a erred because.**
14070 20 69 74 20 75 73 65 73 20 6c 65 73 73 20 6d 65 it uses less me
14080 6d 6f 72 79 20 69 6e 20 74 68 65 20 45 78 70 72 mory in the Expr
14090 20 6f 62 6a 65 63 74 2c 20 77 68 69 63 68 20 69 object, which i
140a0 73 20 61 20 62 69 67 20 6d 65 6d 6f 72 79 20 75 s a big memory u
140b0 73 65 72 0a 2a 2a 20 69 6e 20 73 79 73 74 65 6d ser.** in system
140c0 73 20 77 69 74 68 20 6c 6f 74 73 20 6f 66 20 70 s with lots of p
140d0 72 65 70 61 72 65 64 20 73 74 61 74 65 6d 65 6e repared statemen
140e0 74 73 2e 20 20 41 6e 64 20 66 65 77 20 61 70 70 ts. And few app
140f0 6c 69 63 61 74 69 6f 6e 73 0a 2a 2a 20 6e 65 65 lications.** nee
14100 64 20 6d 6f 72 65 20 74 68 61 6e 20 61 62 6f 75 d more than abou
14110 74 20 31 30 20 6f 72 20 32 30 20 76 61 72 69 61 t 10 or 20 varia
14120 62 6c 65 73 2e 20 20 42 75 74 20 73 6f 6d 65 20 bles. But some
14130 65 78 74 72 65 6d 65 20 75 73 65 72 73 20 77 61 extreme users wa
14140 6e 74 0a 2a 2a 20 74 6f 20 68 61 76 65 20 70 72 nt.** to have pr
14150 65 70 61 72 65 64 20 73 74 61 74 65 6d 65 6e 74 epared statement
14160 73 20 77 69 74 68 20 6f 76 65 72 20 33 32 37 36 s with over 3276
14170 37 20 76 61 72 69 61 62 6c 65 73 2c 20 61 6e 64 7 variables, and
14180 20 66 6f 72 20 74 68 65 6d 0a 2a 2a 20 74 68 65 for them.** the
14190 20 6f 70 74 69 6f 6e 20 69 73 20 61 76 61 69 6c option is avail
141a0 61 62 6c 65 20 28 61 74 20 63 6f 6d 70 69 6c 65 able (at compile
141b0 2d 74 69 6d 65 29 2e 0a 2a 2f 0a 23 69 66 20 53 -time)..*/.#if S
141c0 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 QLITE_MAX_VARIAB
141d0 4c 45 5f 4e 55 4d 42 45 52 3c 3d 33 32 37 36 37 LE_NUMBER<=32767
141e0 0a 74 79 70 65 64 65 66 20 69 31 36 20 79 6e 56 .typedef i16 ynV
141f0 61 72 3b 0a 23 65 6c 73 65 0a 74 79 70 65 64 65 ar;.#else.typede
14200 66 20 69 6e 74 20 79 6e 56 61 72 3b 0a 23 65 6e f int ynVar;.#en
14210 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 dif../*.** Each
14220 6e 6f 64 65 20 6f 66 20 61 6e 20 65 78 70 72 65 node of an expre
14230 73 73 69 6f 6e 20 69 6e 20 74 68 65 20 70 61 72 ssion in the par
14240 73 65 20 74 72 65 65 20 69 73 20 61 6e 20 69 6e se tree is an in
14250 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 69 stance.** of thi
14260 73 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a s structure..**.
14270 2a 2a 20 45 78 70 72 2e 6f 70 20 69 73 20 74 68 ** Expr.op is th
14280 65 20 6f 70 63 6f 64 65 2e 20 54 68 65 20 69 6e e opcode. The in
14290 74 65 67 65 72 20 70 61 72 73 65 72 20 74 6f 6b teger parser tok
142a0 65 6e 20 63 6f 64 65 73 20 61 72 65 20 72 65 75 en codes are reu
142b0 73 65 64 0a 2a 2a 20 61 73 20 6f 70 63 6f 64 65 sed.** as opcode
142c0 73 20 68 65 72 65 2e 20 46 6f 72 20 65 78 61 6d s here. For exam
142d0 70 6c 65 2c 20 74 68 65 20 70 61 72 73 65 72 20 ple, the parser
142e0 64 65 66 69 6e 65 73 20 54 4b 5f 47 45 20 74 6f defines TK_GE to
142f0 20 62 65 20 61 6e 20 69 6e 74 65 67 65 72 0a 2a be an integer.*
14300 2a 20 63 6f 64 65 20 72 65 70 72 65 73 65 6e 74 * code represent
14310 69 6e 67 20 74 68 65 20 22 3e 3d 22 20 6f 70 65 ing the ">=" ope
14320 72 61 74 6f 72 2e 20 54 68 69 73 20 73 61 6d 65 rator. This same
14330 20 69 6e 74 65 67 65 72 20 63 6f 64 65 20 69 73 integer code is
14340 20 72 65 75 73 65 64 0a 2a 2a 20 74 6f 20 72 65 reused.** to re
14350 70 72 65 73 65 6e 74 20 74 68 65 20 67 72 65 61 present the grea
14360 74 65 72 2d 74 68 61 6e 2d 6f 72 2d 65 71 75 61 ter-than-or-equa
14370 6c 2d 74 6f 20 6f 70 65 72 61 74 6f 72 20 69 6e l-to operator in
14380 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 0a the expression.
14390 2a 2a 20 74 72 65 65 2e 0a 2a 2a 0a 2a 2a 20 49 ** tree..**.** I
143a0 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e f the expression
143b0 20 69 73 20 61 6e 20 53 51 4c 20 6c 69 74 65 72 is an SQL liter
143c0 61 6c 20 28 54 4b 5f 49 4e 54 45 47 45 52 2c 20 al (TK_INTEGER,
143d0 54 4b 5f 46 4c 4f 41 54 2c 20 54 4b 5f 42 4c 4f TK_FLOAT, TK_BLO
143e0 42 2c 20 0a 2a 2a 20 6f 72 20 54 4b 5f 53 54 52 B, .** or TK_STR
143f0 49 4e 47 29 2c 20 74 68 65 6e 20 45 78 70 72 2e ING), then Expr.
14400 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 token contains t
14410 68 65 20 74 65 78 74 20 6f 66 20 74 68 65 20 53 he text of the S
14420 51 4c 20 6c 69 74 65 72 61 6c 2e 20 49 66 0a 2a QL literal. If.*
14430 2a 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e * the expression
14440 20 69 73 20 61 20 76 61 72 69 61 62 6c 65 20 28 is a variable (
14450 54 4b 5f 56 41 52 49 41 42 4c 45 29 2c 20 74 68 TK_VARIABLE), th
14460 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f en Expr.token co
14470 6e 74 61 69 6e 73 20 74 68 65 20 0a 2a 2a 20 76 ntains the .** v
14480 61 72 69 61 62 6c 65 20 6e 61 6d 65 2e 20 46 69 ariable name. Fi
14490 6e 61 6c 6c 79 2c 20 69 66 20 74 68 65 20 65 78 nally, if the ex
144a0 70 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 pression is an S
144b0 51 4c 20 66 75 6e 63 74 69 6f 6e 20 28 54 4b 5f QL function (TK_
144c0 46 55 4e 43 54 49 4f 4e 29 2c 0a 2a 2a 20 74 68 FUNCTION),.** th
144d0 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f en Expr.token co
144e0 6e 74 61 69 6e 73 20 74 68 65 20 6e 61 6d 65 20 ntains the name
144f0 6f 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 2e of the function.
14500 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 70 52 69 67 .**.** Expr.pRig
14510 68 74 20 61 6e 64 20 45 78 70 72 2e 70 4c 65 66 ht and Expr.pLef
14520 74 20 61 72 65 20 74 68 65 20 6c 65 66 74 20 61 t are the left a
14530 6e 64 20 72 69 67 68 74 20 73 75 62 65 78 70 72 nd right subexpr
14540 65 73 73 69 6f 6e 73 20 6f 66 20 61 0a 2a 2a 20 essions of a.**
14550 62 69 6e 61 72 79 20 6f 70 65 72 61 74 6f 72 2e binary operator.
14560 20 45 69 74 68 65 72 20 6f 72 20 62 6f 74 68 20 Either or both
14570 6d 61 79 20 62 65 20 4e 55 4c 4c 2e 0a 2a 2a 0a may be NULL..**.
14580 2a 2a 20 45 78 70 72 2e 78 2e 70 4c 69 73 74 20 ** Expr.x.pList
14590 69 73 20 61 20 6c 69 73 74 20 6f 66 20 61 72 67 is a list of arg
145a0 75 6d 65 6e 74 73 20 69 66 20 74 68 65 20 65 78 uments if the ex
145b0 70 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 pression is an S
145c0 51 4c 20 66 75 6e 63 74 69 6f 6e 2c 0a 2a 2a 20 QL function,.**
145d0 61 20 43 41 53 45 20 65 78 70 72 65 73 73 69 6f a CASE expressio
145e0 6e 20 6f 72 20 61 6e 20 49 4e 20 65 78 70 72 65 n or an IN expre
145f0 73 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 6f 72 ssion of the for
14600 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 3c 79 3e m "<lhs> IN (<y>
14610 2c 20 3c 7a 3e 2e 2e 2e 29 22 2e 0a 2a 2a 20 45 , <z>...)"..** E
14620 78 70 72 2e 78 2e 70 53 65 6c 65 63 74 20 69 73 xpr.x.pSelect is
14630 20 75 73 65 64 20 69 66 20 74 68 65 20 65 78 70 used if the exp
14640 72 65 73 73 69 6f 6e 20 69 73 20 61 20 73 75 62 ression is a sub
14650 2d 73 65 6c 65 63 74 20 6f 72 20 61 6e 20 65 78 -select or an ex
14660 70 72 65 73 73 69 6f 6e 20 6f 66 0a 2a 2a 20 74 pression of.** t
14670 68 65 20 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 49 he form "<lhs> I
14680 4e 20 28 53 45 4c 45 43 54 20 2e 2e 2e 29 22 2e N (SELECT ...)".
14690 20 49 66 20 74 68 65 20 45 50 5f 78 49 73 53 65 If the EP_xIsSe
146a0 6c 65 63 74 20 62 69 74 20 69 73 20 73 65 74 20 lect bit is set
146b0 69 6e 20 74 68 65 0a 2a 2a 20 45 78 70 72 2e 66 in the.** Expr.f
146c0 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 6e 20 lags mask, then
146d0 45 78 70 72 2e 78 2e 70 53 65 6c 65 63 74 20 69 Expr.x.pSelect i
146e0 73 20 76 61 6c 69 64 2e 20 4f 74 68 65 72 77 69 s valid. Otherwi
146f0 73 65 2c 20 45 78 70 72 2e 78 2e 70 4c 69 73 74 se, Expr.x.pList
14700 20 69 73 20 0a 2a 2a 20 76 61 6c 69 64 2e 0a 2a is .** valid..*
14710 2a 0a 2a 2a 20 41 6e 20 65 78 70 72 65 73 73 69 *.** An expressi
14720 6f 6e 20 6f 66 20 74 68 65 20 66 6f 72 6d 20 49 on of the form I
14730 44 20 6f 72 20 49 44 2e 49 44 20 72 65 66 65 72 D or ID.ID refer
14740 73 20 74 6f 20 61 20 63 6f 6c 75 6d 6e 20 69 6e s to a column in
14750 20 61 20 74 61 62 6c 65 2e 0a 2a 2a 20 46 6f 72 a table..** For
14760 20 73 75 63 68 20 65 78 70 72 65 73 73 69 6f 6e such expression
14770 73 2c 20 45 78 70 72 2e 6f 70 20 69 73 20 73 65 s, Expr.op is se
14780 74 20 74 6f 20 54 4b 5f 43 4f 4c 55 4d 4e 20 61 t to TK_COLUMN a
14790 6e 64 20 45 78 70 72 2e 69 54 61 62 6c 65 20 69 nd Expr.iTable i
147a0 73 0a 2a 2a 20 74 68 65 20 69 6e 74 65 67 65 72 s.** the integer
147b0 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f cursor number o
147c0 66 20 61 20 56 44 42 45 20 63 75 72 73 6f 72 20 f a VDBE cursor
147d0 70 6f 69 6e 74 69 6e 67 20 74 6f 20 74 68 61 74 pointing to that
147e0 20 74 61 62 6c 65 20 61 6e 64 0a 2a 2a 20 45 78 table and.** Ex
147f0 70 72 2e 69 43 6f 6c 75 6d 6e 20 69 73 20 74 68 pr.iColumn is th
14800 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 e column number
14810 66 6f 72 20 74 68 65 20 73 70 65 63 69 66 69 63 for the specific
14820 20 63 6f 6c 75 6d 6e 2e 20 20 49 66 20 74 68 65 column. If the
14830 0a 2a 2a 20 65 78 70 72 65 73 73 69 6f 6e 20 69 .** expression i
14840 73 20 75 73 65 64 20 61 73 20 61 20 72 65 73 75 s used as a resu
14850 6c 74 20 69 6e 20 61 6e 20 61 67 67 72 65 67 61 lt in an aggrega
14860 74 65 20 53 45 4c 45 43 54 2c 20 74 68 65 6e 20 te SELECT, then
14870 74 68 65 0a 2a 2a 20 76 61 6c 75 65 20 69 73 20 the.** value is
14880 61 6c 73 6f 20 73 74 6f 72 65 64 20 69 6e 20 74 also stored in t
14890 68 65 20 45 78 70 72 2e 69 41 67 67 20 63 6f 6c he Expr.iAgg col
148a0 75 6d 6e 20 69 6e 20 74 68 65 20 61 67 67 72 65 umn in the aggre
148b0 67 61 74 65 20 73 6f 20 74 68 61 74 0a 2a 2a 20 gate so that.**
148c0 69 74 20 63 61 6e 20 62 65 20 61 63 63 65 73 73 it can be access
148d0 65 64 20 61 66 74 65 72 20 61 6c 6c 20 61 67 67 ed after all agg
148e0 72 65 67 61 74 65 73 20 61 72 65 20 63 6f 6d 70 regates are comp
148f0 75 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 uted..**.** If t
14900 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 he expression is
14910 20 61 6e 20 75 6e 62 6f 75 6e 64 20 76 61 72 69 an unbound vari
14920 61 62 6c 65 20 6d 61 72 6b 65 72 20 28 61 20 71 able marker (a q
14930 75 65 73 74 69 6f 6e 20 6d 61 72 6b 20 0a 2a 2a uestion mark .**
14940 20 63 68 61 72 61 63 74 65 72 20 27 3f 27 20 69 character '?' i
14950 6e 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 53 n the original S
14960 51 4c 29 20 74 68 65 6e 20 74 68 65 20 45 78 70 QL) then the Exp
14970 72 2e 69 54 61 62 6c 65 20 68 6f 6c 64 73 20 74 r.iTable holds t
14980 68 65 20 69 6e 64 65 78 20 0a 2a 2a 20 6e 75 6d he index .** num
14990 62 65 72 20 66 6f 72 20 74 68 61 74 20 76 61 72 ber for that var
149a0 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 iable..**.** If
149b0 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 the expression i
149c0 73 20 61 20 73 75 62 71 75 65 72 79 20 74 68 65 s a subquery the
149d0 6e 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 68 n Expr.iColumn h
149e0 6f 6c 64 73 20 61 6e 20 69 6e 74 65 67 65 72 0a olds an integer.
149f0 2a 2a 20 72 65 67 69 73 74 65 72 20 6e 75 6d 62 ** register numb
14a00 65 72 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 er containing th
14a10 65 20 72 65 73 75 6c 74 20 6f 66 20 74 68 65 20 e result of the
14a20 73 75 62 71 75 65 72 79 2e 20 20 49 66 20 74 68 subquery. If th
14a30 65 0a 2a 2a 20 73 75 62 71 75 65 72 79 20 67 69 e.** subquery gi
14a40 76 65 73 20 61 20 63 6f 6e 73 74 61 6e 74 20 72 ves a constant r
14a50 65 73 75 6c 74 2c 20 74 68 65 6e 20 69 54 61 62 esult, then iTab
14a60 6c 65 20 69 73 20 2d 31 2e 20 20 49 66 20 74 68 le is -1. If th
14a70 65 20 73 75 62 71 75 65 72 79 0a 2a 2a 20 67 69 e subquery.** gi
14a80 76 65 73 20 61 20 64 69 66 66 65 72 65 6e 74 20 ves a different
14a90 61 6e 73 77 65 72 20 61 74 20 64 69 66 66 65 72 answer at differ
14aa0 65 6e 74 20 74 69 6d 65 73 20 64 75 72 69 6e 67 ent times during
14ab0 20 73 74 61 74 65 6d 65 6e 74 20 70 72 6f 63 65 statement proce
14ac0 73 73 69 6e 67 0a 2a 2a 20 74 68 65 6e 20 69 54 ssing.** then iT
14ad0 61 62 6c 65 20 69 73 20 74 68 65 20 61 64 64 72 able is the addr
14ae0 65 73 73 20 6f 66 20 61 20 73 75 62 72 6f 75 74 ess of a subrout
14af0 69 6e 65 20 74 68 61 74 20 63 6f 6d 70 75 74 65 ine that compute
14b00 73 20 74 68 65 20 73 75 62 71 75 65 72 79 2e 0a s the subquery..
14b10 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 45 78 70 **.** If the Exp
14b20 72 20 69 73 20 6f 66 20 74 79 70 65 20 4f 50 5f r is of type OP_
14b30 43 6f 6c 75 6d 6e 2c 20 61 6e 64 20 74 68 65 20 Column, and the
14b40 74 61 62 6c 65 20 69 74 20 69 73 20 73 65 6c 65 table it is sele
14b50 63 74 69 6e 67 20 66 72 6f 6d 0a 2a 2a 20 69 73 cting from.** is
14b60 20 61 20 64 69 73 6b 20 74 61 62 6c 65 20 6f 72 a disk table or
14b70 20 74 68 65 20 22 6f 6c 64 2e 2a 22 20 70 73 65 the "old.*" pse
14b80 75 64 6f 2d 74 61 62 6c 65 2c 20 74 68 65 6e 20 udo-table, then
14b90 70 54 61 62 20 70 6f 69 6e 74 73 20 74 6f 20 74 pTab points to t
14ba0 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e 64 he.** correspond
14bb0 69 6e 67 20 74 61 62 6c 65 20 64 65 66 69 6e 69 ing table defini
14bc0 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 41 4c 4c 4f tion..**.** ALLO
14bd0 43 41 54 49 4f 4e 20 4e 4f 54 45 53 3a 0a 2a 2a CATION NOTES:.**
14be0 0a 2a 2a 20 45 78 70 72 20 6f 62 6a 65 63 74 73 .** Expr objects
14bf0 20 63 61 6e 20 75 73 65 20 61 20 6c 6f 74 20 6f can use a lot o
14c00 66 20 6d 65 6d 6f 72 79 20 73 70 61 63 65 20 69 f memory space i
14c10 6e 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d n database schem
14c20 61 2e 20 20 54 6f 0a 2a 2a 20 68 65 6c 70 20 72 a. To.** help r
14c30 65 64 75 63 65 20 6d 65 6d 6f 72 79 20 72 65 71 educe memory req
14c40 75 69 72 65 6d 65 6e 74 73 2c 20 73 6f 6d 65 74 uirements, somet
14c50 69 6d 65 73 20 61 6e 20 45 78 70 72 20 6f 62 6a imes an Expr obj
14c60 65 63 74 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 74 ect will be.** t
14c70 72 75 6e 63 61 74 65 64 2e 20 20 41 6e 64 20 74 runcated. And t
14c80 6f 20 72 65 64 75 63 65 20 74 68 65 20 6e 75 6d o reduce the num
14c90 62 65 72 20 6f 66 20 6d 65 6d 6f 72 79 20 61 6c ber of memory al
14ca0 6c 6f 63 61 74 69 6f 6e 73 2c 20 73 6f 6d 65 74 locations, somet
14cb0 69 6d 65 73 0a 2a 2a 20 74 77 6f 20 6f 72 20 6d imes.** two or m
14cc0 6f 72 65 20 45 78 70 72 20 6f 62 6a 65 63 74 73 ore Expr objects
14cd0 20 77 69 6c 6c 20 62 65 20 73 74 6f 72 65 64 20 will be stored
14ce0 69 6e 20 61 20 73 69 6e 67 6c 65 20 6d 65 6d 6f in a single memo
14cf0 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 2c 0a 2a ry allocation,.*
14d00 2a 20 74 6f 67 65 74 68 65 72 20 77 69 74 68 20 * together with
14d10 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 73 74 72 69 Expr.zToken stri
14d20 6e 67 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 ngs..**.** If th
14d30 65 20 45 50 5f 52 65 64 75 63 65 64 20 61 6e 64 e EP_Reduced and
14d40 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c EP_TokenOnly fl
14d50 61 67 73 20 61 72 65 20 73 65 74 20 77 68 65 6e ags are set when
14d60 0a 2a 2a 20 61 6e 20 45 78 70 72 20 6f 62 6a 65 .** an Expr obje
14d70 63 74 20 69 73 20 74 72 75 6e 63 61 74 65 64 2e ct is truncated.
14d80 20 20 57 68 65 6e 20 45 50 5f 52 65 64 75 63 65 When EP_Reduce
14d90 64 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 61 d is set, then a
14da0 6c 6c 0a 2a 2a 20 74 68 65 20 63 68 69 6c 64 20 ll.** the child
14db0 45 78 70 72 20 6f 62 6a 65 63 74 73 20 69 6e 20 Expr objects in
14dc0 74 68 65 20 45 78 70 72 2e 70 4c 65 66 74 20 61 the Expr.pLeft a
14dd0 6e 64 20 45 78 70 72 2e 70 52 69 67 68 74 20 73 nd Expr.pRight s
14de0 75 62 74 72 65 65 73 0a 2a 2a 20 61 72 65 20 63 ubtrees.** are c
14df0 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 69 6e 20 ontained within
14e00 74 68 65 20 73 61 6d 65 20 6d 65 6d 6f 72 79 20 the same memory
14e10 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 4e 6f 74 allocation. Not
14e20 65 2c 20 68 6f 77 65 76 65 72 2c 20 74 68 61 74 e, however, that
14e30 0a 2a 2a 20 74 68 65 20 73 75 62 74 72 65 65 73 .** the subtrees
14e40 20 69 6e 20 45 78 70 72 2e 78 2e 70 4c 69 73 74 in Expr.x.pList
14e50 20 6f 72 20 45 78 70 72 2e 78 2e 70 53 65 6c 65 or Expr.x.pSele
14e60 63 74 20 61 72 65 20 61 6c 77 61 79 73 20 73 65 ct are always se
14e70 70 61 72 61 74 65 6c 79 0a 2a 2a 20 61 6c 6c 6f parately.** allo
14e80 63 61 74 65 64 2c 20 72 65 67 61 72 64 6c 65 73 cated, regardles
14e90 73 20 6f 66 20 77 68 65 74 68 65 72 20 6f 72 20 s of whether or
14ea0 6e 6f 74 20 45 50 5f 52 65 64 75 63 65 64 20 69 not EP_Reduced i
14eb0 73 20 73 65 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 s set..*/.struct
14ec0 20 45 78 70 72 20 7b 0a 20 20 75 38 20 6f 70 3b Expr {. u8 op;
14ed0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14ee0 20 2f 2a 20 4f 70 65 72 61 74 69 6f 6e 20 70 65 /* Operation pe
14ef0 72 66 6f 72 6d 65 64 20 62 79 20 74 68 69 73 20 rformed by this
14f00 6e 6f 64 65 20 2a 2f 0a 20 20 63 68 61 72 20 61 node */. char a
14f10 66 66 69 6e 69 74 79 3b 20 20 20 20 20 20 20 20 ffinity;
14f20 20 2f 2a 20 54 68 65 20 61 66 66 69 6e 69 74 79 /* The affinity
14f30 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6f of the column o
14f40 72 20 30 20 69 66 20 6e 6f 74 20 61 20 63 6f 6c r 0 if not a col
14f50 75 6d 6e 20 2a 2f 0a 20 20 75 33 32 20 66 6c 61 umn */. u32 fla
14f60 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 gs;
14f70 2f 2a 20 56 61 72 69 6f 75 73 20 66 6c 61 67 73 /* Various flags
14f80 2e 20 20 45 50 5f 2a 20 53 65 65 20 62 65 6c 6f . EP_* See belo
14f90 77 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 w */. union {.
14fa0 20 20 20 63 68 61 72 20 2a 7a 54 6f 6b 65 6e 3b char *zToken;
14fb0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b /* Tok
14fc0 65 6e 20 76 61 6c 75 65 2e 20 5a 65 72 6f 20 74 en value. Zero t
14fd0 65 72 6d 69 6e 61 74 65 64 20 61 6e 64 20 64 65 erminated and de
14fe0 71 75 6f 74 65 64 20 2a 2f 0a 20 20 20 20 69 6e quoted */. in
14ff0 74 20 69 56 61 6c 75 65 3b 20 20 20 20 20 20 20 t iValue;
15000 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6e 65 67 61 /* Non-nega
15010 74 69 76 65 20 69 6e 74 65 67 65 72 20 76 61 6c tive integer val
15020 75 65 20 69 66 20 45 50 5f 49 6e 74 56 61 6c 75 ue if EP_IntValu
15030 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a 0a 20 20 2f e */. } u;.. /
15040 2a 20 49 66 20 74 68 65 20 45 50 5f 54 6f 6b 65 * If the EP_Toke
15050 6e 4f 6e 6c 79 20 66 6c 61 67 20 69 73 20 73 65 nOnly flag is se
15060 74 20 69 6e 20 74 68 65 20 45 78 70 72 2e 66 6c t in the Expr.fl
15070 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 6e 20 6e ags mask, then n
15080 6f 0a 20 20 2a 2a 20 73 70 61 63 65 20 69 73 20 o. ** space is
15090 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 74 68 allocated for th
150a0 65 20 66 69 65 6c 64 73 20 62 65 6c 6f 77 20 74 e fields below t
150b0 68 69 73 20 70 6f 69 6e 74 2e 20 41 6e 20 61 74 his point. An at
150c0 74 65 6d 70 74 20 74 6f 0a 20 20 2a 2a 20 61 63 tempt to. ** ac
150d0 63 65 73 73 20 74 68 65 6d 20 77 69 6c 6c 20 72 cess them will r
150e0 65 73 75 6c 74 20 69 6e 20 61 20 73 65 67 66 61 esult in a segfa
150f0 75 6c 74 20 6f 72 20 6d 61 6c 66 75 6e 63 74 69 ult or malfuncti
15100 6f 6e 2e 20 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a on. . *********
15110 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15120 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15130 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15140 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 ************/..
15150 20 45 78 70 72 20 2a 70 4c 65 66 74 3b 20 20 20 Expr *pLeft;
15160 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 66 74 20 /* Left
15170 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 45 78 70 subnode */. Exp
15180 72 20 2a 70 52 69 67 68 74 3b 20 20 20 20 20 20 r *pRight;
15190 20 20 20 20 2f 2a 20 52 69 67 68 74 20 73 75 62 /* Right sub
151a0 6e 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 node */. union
151b0 7b 0a 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a {. ExprList *
151c0 70 4c 69 73 74 3b 20 20 20 20 20 2f 2a 20 6f 70 pList; /* op
151d0 20 3d 20 49 4e 2c 20 45 58 49 53 54 53 2c 20 53 = IN, EXISTS, S
151e0 45 4c 45 43 54 2c 20 43 41 53 45 2c 20 46 55 4e ELECT, CASE, FUN
151f0 43 54 49 4f 4e 2c 20 42 45 54 57 45 45 4e 20 2a CTION, BETWEEN *
15200 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 /. Select *pS
15210 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 45 50 elect; /* EP
15220 5f 78 49 73 53 65 6c 65 63 74 20 61 6e 64 20 6f _xIsSelect and o
15230 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 53 2c 20 p = IN, EXISTS,
15240 53 45 4c 45 43 54 20 2a 2f 0a 20 20 7d 20 78 3b SELECT */. } x;
15250 0a 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 45 50 .. /* If the EP
15260 5f 52 65 64 75 63 65 64 20 66 6c 61 67 20 69 73 _Reduced flag is
15270 20 73 65 74 20 69 6e 20 74 68 65 20 45 78 70 72 set in the Expr
15280 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 .flags mask, the
15290 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 65 20 n no. ** space
152a0 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 is allocated for
152b0 20 74 68 65 20 66 69 65 6c 64 73 20 62 65 6c 6f the fields belo
152c0 77 20 74 68 69 73 20 70 6f 69 6e 74 2e 20 41 6e w this point. An
152d0 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 20 2a 2a attempt to. **
152e0 20 61 63 63 65 73 73 20 74 68 65 6d 20 77 69 6c access them wil
152f0 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 20 73 65 l result in a se
15300 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c 66 75 6e gfault or malfun
15310 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a ction.. *******
15320 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15330 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15340 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
15350 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a **************/.
15360 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f .#if SQLITE_MAX_
15370 45 58 50 52 5f 44 45 50 54 48 3e 30 0a 20 20 69 EXPR_DEPTH>0. i
15380 6e 74 20 6e 48 65 69 67 68 74 3b 20 20 20 20 20 nt nHeight;
15390 20 20 20 20 20 20 2f 2a 20 48 65 69 67 68 74 20 /* Height
153a0 6f 66 20 74 68 65 20 74 72 65 65 20 68 65 61 64 of the tree head
153b0 65 64 20 62 79 20 74 68 69 73 20 6e 6f 64 65 20 ed by this node
153c0 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 */.#endif. int
153d0 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 iTable;
153e0 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a /* TK_COLUMN:
153f0 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f cursor number o
15400 66 20 74 61 62 6c 65 20 68 6f 6c 64 69 6e 67 20 f table holding
15410 63 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 column.
15420 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15430 2a 2a 20 54 4b 5f 52 45 47 49 53 54 45 52 3a 20 ** TK_REGISTER:
15440 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 0a register number.
15450 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15460 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 54 ** TK_T
15470 52 49 47 47 45 52 3a 20 31 20 2d 3e 20 6e 65 77 RIGGER: 1 -> new
15480 2c 20 30 20 2d 3e 20 6f 6c 64 0a 20 20 20 20 20 , 0 -> old.
15490 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
154a0 20 20 20 20 2a 2a 20 45 50 5f 55 6e 6c 69 6b 65 ** EP_Unlike
154b0 6c 79 3a 20 20 31 33 34 32 31 37 37 32 38 20 74 ly: 134217728 t
154c0 69 6d 65 73 20 6c 69 6b 65 6c 69 68 6f 6f 64 20 imes likelihood
154d0 2a 2f 0a 20 20 79 6e 56 61 72 20 69 43 6f 6c 75 */. ynVar iColu
154e0 6d 6e 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 mn; /* T
154f0 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d 6e K_COLUMN: column
15500 20 69 6e 64 65 78 2e 20 20 2d 31 20 66 6f 72 20 index. -1 for
15510 72 6f 77 69 64 2e 0a 20 20 20 20 20 20 20 20 20 rowid..
15520 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15530 2a 2a 20 54 4b 5f 56 41 52 49 41 42 4c 45 3a 20 ** TK_VARIABLE:
15540 76 61 72 69 61 62 6c 65 20 6e 75 6d 62 65 72 20 variable number
15550 28 61 6c 77 61 79 73 20 3e 3d 20 31 29 2e 20 2a (always >= 1). *
15560 2f 0a 20 20 69 31 36 20 69 41 67 67 3b 20 20 20 /. i16 iAgg;
15570 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 /* Wh
15580 69 63 68 20 65 6e 74 72 79 20 69 6e 20 70 41 67 ich entry in pAg
15590 67 49 6e 66 6f 2d 3e 61 43 6f 6c 5b 5d 20 6f 72 gInfo->aCol[] or
155a0 20 2d 3e 61 46 75 6e 63 5b 5d 20 2a 2f 0a 20 20 ->aFunc[] */.
155b0 69 31 36 20 69 52 69 67 68 74 4a 6f 69 6e 54 61 i16 iRightJoinTa
155c0 62 6c 65 3b 20 20 20 2f 2a 20 49 66 20 45 50 5f ble; /* If EP_
155d0 46 72 6f 6d 4a 6f 69 6e 2c 20 74 68 65 20 72 69 FromJoin, the ri
155e0 67 68 74 20 74 61 62 6c 65 20 6f 66 20 74 68 65 ght table of the
155f0 20 6a 6f 69 6e 20 2a 2f 0a 20 20 75 38 20 6f 70 join */. u8 op
15600 32 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2;
15610 20 20 2f 2a 20 54 4b 5f 52 45 47 49 53 54 45 52 /* TK_REGISTER
15620 3a 20 6f 72 69 67 69 6e 61 6c 20 76 61 6c 75 65 : original value
15630 20 6f 66 20 45 78 70 72 2e 6f 70 0a 20 20 20 20 of Expr.op.
15640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15650 20 20 20 20 20 2a 2a 20 54 4b 5f 43 4f 4c 55 4d ** TK_COLUM
15660 4e 3a 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 N: the value of
15670 70 35 20 66 6f 72 20 4f 50 5f 43 6f 6c 75 6d 6e p5 for OP_Column
15680 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
15690 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f ** TK_
156a0 41 47 47 5f 46 55 4e 43 54 49 4f 4e 3a 20 6e 65 AGG_FUNCTION: ne
156b0 73 74 69 6e 67 20 64 65 70 74 68 20 2a 2f 0a 20 sting depth */.
156c0 20 41 67 67 49 6e 66 6f 20 2a 70 41 67 67 49 6e AggInfo *pAggIn
156d0 66 6f 3b 20 20 20 20 20 2f 2a 20 55 73 65 64 20 fo; /* Used
156e0 62 79 20 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d 4e by TK_AGG_COLUMN
156f0 20 61 6e 64 20 54 4b 5f 41 47 47 5f 46 55 4e 43 and TK_AGG_FUNC
15700 54 49 4f 4e 20 2a 2f 0a 20 20 54 61 62 6c 65 20 TION */. Table
15710 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 *pTab;
15720 20 2f 2a 20 54 61 62 6c 65 20 66 6f 72 20 54 4b /* Table for TK
15730 5f 43 4f 4c 55 4d 4e 20 65 78 70 72 65 73 73 69 _COLUMN expressi
15740 6f 6e 73 2e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a ons. */.};../*.*
15750 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
15760 61 72 65 20 74 68 65 20 6d 65 61 6e 69 6e 67 73 are the meanings
15770 20 6f 66 20 62 69 74 73 20 69 6e 20 74 68 65 20 of bits in the
15780 45 78 70 72 2e 66 6c 61 67 73 20 66 69 65 6c 64 Expr.flags field
15790 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f ..*/.#define EP_
157a0 46 72 6f 6d 4a 6f 69 6e 20 20 30 78 30 30 30 30 FromJoin 0x0000
157b0 30 31 20 2f 2a 20 4f 72 69 67 69 6e 61 74 65 73 01 /* Originates
157c0 20 69 6e 20 4f 4e 2f 55 53 49 4e 47 20 63 6c 61 in ON/USING cla
157d0 75 73 65 20 6f 66 20 6f 75 74 65 72 20 6a 6f 69 use of outer joi
157e0 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f n */.#define EP_
157f0 41 67 67 20 20 20 20 20 20 20 30 78 30 30 30 30 Agg 0x0000
15800 30 32 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 6f 02 /* Contains o
15810 6e 65 20 6f 72 20 6d 6f 72 65 20 61 67 67 72 65 ne or more aggre
15820 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a gate functions *
15830 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 52 65 73 /.#define EP_Res
15840 6f 6c 76 65 64 20 20 30 78 30 30 30 30 30 34 20 olved 0x000004
15850 2f 2a 20 49 44 73 20 68 61 76 65 20 62 65 65 6e /* IDs have been
15860 20 72 65 73 6f 6c 76 65 64 20 74 6f 20 43 4f 4c resolved to COL
15870 55 4d 4e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 UMNs */.#define
15880 45 50 5f 45 72 72 6f 72 20 20 20 20 20 30 78 30 EP_Error 0x0
15890 30 30 30 30 38 20 2f 2a 20 45 78 70 72 65 73 73 00008 /* Express
158a0 69 6f 6e 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 ion contains one
158b0 20 6f 72 20 6d 6f 72 65 20 65 72 72 6f 72 73 20 or more errors
158c0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 44 69 */.#define EP_Di
158d0 73 74 69 6e 63 74 20 20 30 78 30 30 30 30 31 30 stinct 0x000010
158e0 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 66 75 /* Aggregate fu
158f0 6e 63 74 69 6f 6e 20 77 69 74 68 20 44 49 53 54 nction with DIST
15900 49 4e 43 54 20 6b 65 79 77 6f 72 64 20 2a 2f 0a INCT keyword */.
15910 23 64 65 66 69 6e 65 20 45 50 5f 56 61 72 53 65 #define EP_VarSe
15920 6c 65 63 74 20 30 78 30 30 30 30 32 30 20 2f 2a lect 0x000020 /*
15930 20 70 53 65 6c 65 63 74 20 69 73 20 63 6f 72 72 pSelect is corr
15940 65 6c 61 74 65 64 2c 20 6e 6f 74 20 63 6f 6e 73 elated, not cons
15950 74 61 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tant */.#define
15960 45 50 5f 44 62 6c 51 75 6f 74 65 64 20 30 78 30 EP_DblQuoted 0x0
15970 30 30 30 34 30 20 2f 2a 20 74 6f 6b 65 6e 2e 7a 00040 /* token.z
15980 20 77 61 73 20 6f 72 69 67 69 6e 61 6c 6c 79 20 was originally
15990 69 6e 20 22 2e 2e 2e 22 20 2a 2f 0a 23 64 65 66 in "..." */.#def
159a0 69 6e 65 20 45 50 5f 49 6e 66 69 78 46 75 6e 63 ine EP_InfixFunc
159b0 20 30 78 30 30 30 30 38 30 20 2f 2a 20 54 72 75 0x000080 /* Tru
159c0 65 20 66 6f 72 20 61 6e 20 69 6e 66 69 78 20 66 e for an infix f
159d0 75 6e 63 74 69 6f 6e 3a 20 4c 49 4b 45 2c 20 47 unction: LIKE, G
159e0 4c 4f 42 2c 20 65 74 63 20 2a 2f 0a 23 64 65 66 LOB, etc */.#def
159f0 69 6e 65 20 45 50 5f 43 6f 6c 6c 61 74 65 20 20 ine EP_Collate
15a00 20 30 78 30 30 30 31 30 30 20 2f 2a 20 54 72 65 0x000100 /* Tre
15a10 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 54 4b 5f e contains a TK_
15a20 43 4f 4c 4c 41 54 45 20 6f 70 65 72 61 74 6f 72 COLLATE operator
15a30 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 47 */.#define EP_G
15a40 65 6e 65 72 69 63 20 20 20 30 78 30 30 30 32 30 eneric 0x00020
15a50 30 20 2f 2a 20 49 67 6e 6f 72 65 20 43 4f 4c 4c 0 /* Ignore COLL
15a60 41 54 45 20 6f 72 20 61 66 66 69 6e 69 74 79 20 ATE or affinity
15a70 6f 6e 20 74 68 69 73 20 74 72 65 65 20 2a 2f 0a on this tree */.
15a80 23 64 65 66 69 6e 65 20 45 50 5f 49 6e 74 56 61 #define EP_IntVa
15a90 6c 75 65 20 20 30 78 30 30 30 34 30 30 20 2f 2a lue 0x000400 /*
15aa0 20 49 6e 74 65 67 65 72 20 76 61 6c 75 65 20 63 Integer value c
15ab0 6f 6e 74 61 69 6e 65 64 20 69 6e 20 75 2e 69 56 ontained in u.iV
15ac0 61 6c 75 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 alue */.#define
15ad0 45 50 5f 78 49 73 53 65 6c 65 63 74 20 30 78 30 EP_xIsSelect 0x0
15ae0 30 30 38 30 30 20 2f 2a 20 78 2e 70 53 65 6c 65 00800 /* x.pSele
15af0 63 74 20 69 73 20 76 61 6c 69 64 20 28 6f 74 68 ct is valid (oth
15b00 65 72 77 69 73 65 20 78 2e 70 4c 69 73 74 20 69 erwise x.pList i
15b10 73 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 s) */.#define EP
15b20 5f 53 6b 69 70 20 20 20 20 20 20 30 78 30 30 31 _Skip 0x001
15b30 30 30 30 20 2f 2a 20 43 4f 4c 4c 41 54 45 2c 20 000 /* COLLATE,
15b40 41 53 2c 20 6f 72 20 55 4e 4c 49 4b 45 4c 59 20 AS, or UNLIKELY
15b50 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 52 65 */.#define EP_Re
15b60 64 75 63 65 64 20 20 20 30 78 30 30 32 30 30 30 duced 0x002000
15b70 20 2f 2a 20 45 78 70 72 20 73 74 72 75 63 74 20 /* Expr struct
15b80 45 58 50 52 5f 52 45 44 55 43 45 44 53 49 5a 45 EXPR_REDUCEDSIZE
15b90 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a 2f 0a 23 bytes only */.#
15ba0 64 65 66 69 6e 65 20 45 50 5f 54 6f 6b 65 6e 4f define EP_TokenO
15bb0 6e 6c 79 20 30 78 30 30 34 30 30 30 20 2f 2a 20 nly 0x004000 /*
15bc0 45 78 70 72 20 73 74 72 75 63 74 20 45 58 50 52 Expr struct EXPR
15bd0 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 5a 45 20 62 _TOKENONLYSIZE b
15be0 79 74 65 73 20 6f 6e 6c 79 20 2a 2f 0a 23 64 65 ytes only */.#de
15bf0 66 69 6e 65 20 45 50 5f 53 74 61 74 69 63 20 20 fine EP_Static
15c00 20 20 30 78 30 30 38 30 30 30 20 2f 2a 20 48 65 0x008000 /* He
15c10 6c 64 20 69 6e 20 6d 65 6d 6f 72 79 20 6e 6f 74 ld in memory not
15c20 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 6d obtained from m
15c30 61 6c 6c 6f 63 28 29 20 2a 2f 0a 23 64 65 66 69 alloc() */.#defi
15c40 6e 65 20 45 50 5f 4d 65 6d 54 6f 6b 65 6e 20 20 ne EP_MemToken
15c50 30 78 30 31 30 30 30 30 20 2f 2a 20 4e 65 65 64 0x010000 /* Need
15c60 20 74 6f 20 73 71 6c 69 74 65 33 44 62 46 72 65 to sqlite3DbFre
15c70 65 28 29 20 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 e() Expr.zToken
15c80 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4e 6f */.#define EP_No
15c90 52 65 64 75 63 65 20 20 30 78 30 32 30 30 30 30 Reduce 0x020000
15ca0 20 2f 2a 20 43 61 6e 6e 6f 74 20 45 58 50 52 44 /* Cannot EXPRD
15cb0 55 50 5f 52 45 44 55 43 45 20 74 68 69 73 20 45 UP_REDUCE this E
15cc0 78 70 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 xpr */.#define E
15cd0 50 5f 55 6e 6c 69 6b 65 6c 79 20 20 30 78 30 34 P_Unlikely 0x04
15ce0 30 30 30 30 20 2f 2a 20 75 6e 6c 69 6b 65 6c 79 0000 /* unlikely
15cf0 28 29 20 6f 72 20 6c 69 6b 65 6c 69 68 6f 6f 64 () or likelihood
15d00 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 () function */.#
15d10 64 65 66 69 6e 65 20 45 50 5f 43 6f 6e 73 74 46 define EP_ConstF
15d20 75 6e 63 20 30 78 30 38 30 30 30 30 20 2f 2a 20 unc 0x080000 /*
15d30 41 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f A SQLITE_FUNC_CO
15d40 4e 53 54 41 4e 54 20 6f 72 20 5f 53 4c 4f 43 48 NSTANT or _SLOCH
15d50 4e 47 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 NG function */.#
15d60 64 65 66 69 6e 65 20 45 50 5f 43 61 6e 42 65 4e define EP_CanBeN
15d70 75 6c 6c 20 30 78 31 30 30 30 30 30 20 2f 2a 20 ull 0x100000 /*
15d80 43 61 6e 20 62 65 20 6e 75 6c 6c 20 64 65 73 70 Can be null desp
15d90 69 74 65 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e ite NOT NULL con
15da0 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 straint */.#defi
15db0 6e 65 20 45 50 5f 53 75 62 71 75 65 72 79 20 20 ne EP_Subquery
15dc0 30 78 32 30 30 30 30 30 20 2f 2a 20 54 72 65 65 0x200000 /* Tree
15dd0 20 63 6f 6e 74 61 69 6e 73 20 61 20 54 4b 5f 53 contains a TK_S
15de0 45 4c 45 43 54 20 6f 70 65 72 61 74 6f 72 20 2a ELECT operator *
15df0 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 41 6c 69 /.#define EP_Ali
15e00 61 73 20 20 20 20 20 30 78 34 30 30 30 30 30 20 as 0x400000
15e10 2f 2a 20 49 73 20 61 6e 20 61 6c 69 61 73 20 66 /* Is an alias f
15e20 6f 72 20 61 20 72 65 73 75 6c 74 20 73 65 74 20 or a result set
15e30 63 6f 6c 75 6d 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a column */../*.**
15e40 20 43 6f 6d 62 69 6e 61 74 69 6f 6e 73 20 6f 66 Combinations of
15e50 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 45 50 5f two or more EP_
15e60 2a 20 66 6c 61 67 73 0a 2a 2f 0a 23 64 65 66 69 * flags.*/.#defi
15e70 6e 65 20 45 50 5f 50 72 6f 70 61 67 61 74 65 20 ne EP_Propagate
15e80 28 45 50 5f 43 6f 6c 6c 61 74 65 7c 45 50 5f 53 (EP_Collate|EP_S
15e90 75 62 71 75 65 72 79 29 20 2f 2a 20 50 72 6f 70 ubquery) /* Prop
15ea0 61 67 61 74 65 20 74 68 65 73 65 20 62 69 74 73 agate these bits
15eb0 20 75 70 20 74 72 65 65 20 2a 2f 0a 0a 2f 2a 0a up tree */../*.
15ec0 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 ** These macros
15ed0 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 can be used to t
15ee0 65 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 est, set, or cle
15ef0 61 72 20 62 69 74 73 20 69 6e 20 74 68 65 20 0a ar bits in the .
15f00 2a 2a 20 45 78 70 72 2e 66 6c 61 67 73 20 66 69 ** Expr.flags fi
15f10 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 eld..*/.#define
15f20 45 78 70 72 48 61 73 50 72 6f 70 65 72 74 79 28 ExprHasProperty(
15f30 45 2c 50 29 20 20 20 20 20 28 28 28 45 29 2d 3e E,P) (((E)->
15f40 66 6c 61 67 73 26 28 50 29 29 21 3d 30 29 0a 23 flags&(P))!=0).#
15f50 64 65 66 69 6e 65 20 45 78 70 72 48 61 73 41 6c define ExprHasAl
15f60 6c 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 lProperty(E,P)
15f70 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 50 29 (((E)->flags&(P)
15f80 29 3d 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 20 )==(P)).#define
15f90 45 78 70 72 53 65 74 50 72 6f 70 65 72 74 79 28 ExprSetProperty(
15fa0 45 2c 50 29 20 20 20 20 20 28 45 29 2d 3e 66 6c E,P) (E)->fl
15fb0 61 67 73 7c 3d 28 50 29 0a 23 64 65 66 69 6e 65 ags|=(P).#define
15fc0 20 45 78 70 72 43 6c 65 61 72 50 72 6f 70 65 72 ExprClearProper
15fd0 74 79 28 45 2c 50 29 20 20 20 28 45 29 2d 3e 66 ty(E,P) (E)->f
15fe0 6c 61 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 20 54 lags&=~(P)../* T
15ff0 68 65 20 45 78 70 72 53 65 74 56 56 41 50 72 6f he ExprSetVVAPro
16000 70 65 72 74 79 28 29 20 6d 61 63 72 6f 20 69 73 perty() macro is
16010 20 75 73 65 64 20 66 6f 72 20 56 65 72 69 66 69 used for Verifi
16020 63 61 74 69 6f 6e 2c 20 56 61 6c 69 64 61 74 69 cation, Validati
16030 6f 6e 2c 0a 2a 2a 20 61 6e 64 20 41 63 63 72 65 on,.** and Accre
16040 64 69 74 61 74 69 6f 6e 20 6f 6e 6c 79 2e 20 20 ditation only.
16050 49 74 20 77 6f 72 6b 73 20 6c 69 6b 65 20 45 78 It works like Ex
16060 70 72 53 65 74 50 72 6f 70 65 72 74 79 28 29 20 prSetProperty()
16070 64 75 72 69 6e 67 20 56 56 41 0a 2a 2a 20 70 72 during VVA.** pr
16080 6f 63 65 73 73 65 73 20 62 75 74 20 69 73 20 61 ocesses but is a
16090 20 6e 6f 2d 6f 70 20 66 6f 72 20 64 65 6c 69 76 no-op for deliv
160a0 65 72 79 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 ery..*/.#ifdef S
160b0 51 4c 49 54 45 5f 44 45 42 55 47 0a 23 20 64 65 QLITE_DEBUG.# de
160c0 66 69 6e 65 20 45 78 70 72 53 65 74 56 56 41 50 fine ExprSetVVAP
160d0 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 28 45 roperty(E,P) (E
160e0 29 2d 3e 66 6c 61 67 73 7c 3d 28 50 29 0a 23 65 )->flags|=(P).#e
160f0 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 45 78 70 lse.# define Exp
16100 72 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 rSetVVAProperty(
16110 45 2c 50 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a E,P).#endif../*.
16120 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 74 ** Macros to det
16130 65 72 6d 69 6e 65 20 74 68 65 20 6e 75 6d 62 65 ermine the numbe
16140 72 20 6f 66 20 62 79 74 65 73 20 72 65 71 75 69 r of bytes requi
16150 72 65 64 20 62 79 20 61 20 6e 6f 72 6d 61 6c 20 red by a normal
16160 45 78 70 72 20 0a 2a 2a 20 73 74 72 75 63 74 2c Expr .** struct,
16170 20 61 6e 20 45 78 70 72 20 73 74 72 75 63 74 20 an Expr struct
16180 77 69 74 68 20 74 68 65 20 45 50 5f 52 65 64 75 with the EP_Redu
16190 63 65 64 20 66 6c 61 67 20 73 65 74 20 69 6e 20 ced flag set in
161a0 45 78 70 72 2e 66 6c 61 67 73 20 0a 2a 2a 20 61 Expr.flags .** a
161b0 6e 64 20 61 6e 20 45 78 70 72 20 73 74 72 75 63 nd an Expr struc
161c0 74 20 77 69 74 68 20 74 68 65 20 45 50 5f 54 6f t with the EP_To
161d0 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 73 65 74 kenOnly flag set
161e0 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 ..*/.#define EXP
161f0 52 5f 46 55 4c 4c 53 49 5a 45 20 20 20 20 20 20 R_FULLSIZE
16200 20 20 20 20 20 73 69 7a 65 6f 66 28 45 78 70 72 sizeof(Expr
16210 29 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 ) /* F
16220 75 6c 6c 20 73 69 7a 65 20 2a 2f 0a 23 64 65 66 ull size */.#def
16230 69 6e 65 20 45 58 50 52 5f 52 45 44 55 43 45 44 ine EXPR_REDUCED
16240 53 49 5a 45 20 20 20 20 20 20 20 20 6f 66 66 73 SIZE offs
16250 65 74 6f 66 28 45 78 70 72 2c 69 54 61 62 6c 65 etof(Expr,iTable
16260 29 20 20 2f 2a 20 43 6f 6d 6d 6f 6e 20 66 65 61 ) /* Common fea
16270 74 75 72 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 tures */.#define
16280 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 EXPR_TOKENONLYS
16290 49 5a 45 20 20 20 20 20 20 6f 66 66 73 65 74 6f IZE offseto
162a0 66 28 45 78 70 72 2c 70 4c 65 66 74 29 20 20 20 f(Expr,pLeft)
162b0 2f 2a 20 46 65 77 65 72 20 66 65 61 74 75 72 65 /* Fewer feature
162c0 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 s */../*.** Flag
162d0 73 20 70 61 73 73 65 64 20 74 6f 20 74 68 65 20 s passed to the
162e0 73 71 6c 69 74 65 33 45 78 70 72 44 75 70 28 29 sqlite3ExprDup()
162f0 20 66 75 6e 63 74 69 6f 6e 2e 20 53 65 65 20 74 function. See t
16300 68 65 20 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e he header commen
16310 74 20 0a 2a 2a 20 61 62 6f 76 65 20 73 71 6c 69 t .** above sqli
16320 74 65 33 45 78 70 72 44 75 70 28 29 20 66 6f 72 te3ExprDup() for
16330 20 64 65 74 61 69 6c 73 2e 0a 2a 2f 0a 23 64 65 details..*/.#de
16340 66 69 6e 65 20 45 58 50 52 44 55 50 5f 52 45 44 fine EXPRDUP_RED
16350 55 43 45 20 20 20 20 20 20 20 20 20 30 78 30 30 UCE 0x00
16360 30 31 20 20 2f 2a 20 55 73 65 64 20 72 65 64 75 01 /* Used redu
16370 63 65 64 2d 73 69 7a 65 20 45 78 70 72 20 6e 6f ced-size Expr no
16380 64 65 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 des */../*.** A
16390 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 list of expressi
163a0 6f 6e 73 2e 20 20 45 61 63 68 20 65 78 70 72 65 ons. Each expre
163b0 73 73 69 6f 6e 20 6d 61 79 20 6f 70 74 69 6f 6e ssion may option
163c0 61 6c 6c 79 20 68 61 76 65 20 61 0a 2a 2a 20 6e ally have a.** n
163d0 61 6d 65 2e 20 20 41 6e 20 65 78 70 72 2f 6e 61 ame. An expr/na
163e0 6d 65 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 63 me combination c
163f0 61 6e 20 62 65 20 75 73 65 64 20 69 6e 20 73 65 an be used in se
16400 76 65 72 61 6c 20 77 61 79 73 2c 20 73 75 63 68 veral ways, such
16410 0a 2a 2a 20 61 73 20 74 68 65 20 6c 69 73 74 20 .** as the list
16420 6f 66 20 22 65 78 70 72 20 41 53 20 49 44 22 20 of "expr AS ID"
16430 66 69 65 6c 64 73 20 66 6f 6c 6c 6f 77 69 6e 67 fields following
16440 20 61 20 22 53 45 4c 45 43 54 22 20 6f 72 20 69 a "SELECT" or i
16450 6e 20 74 68 65 0a 2a 2a 20 6c 69 73 74 20 6f 66 n the.** list of
16460 20 22 49 44 20 3d 20 65 78 70 72 22 20 69 74 65 "ID = expr" ite
16470 6d 73 20 69 6e 20 61 6e 20 55 50 44 41 54 45 2e ms in an UPDATE.
16480 20 20 41 20 6c 69 73 74 20 6f 66 20 65 78 70 72 A list of expr
16490 65 73 73 69 6f 6e 73 20 63 61 6e 0a 2a 2a 20 61 essions can.** a
164a0 6c 73 6f 20 62 65 20 75 73 65 64 20 61 73 20 74 lso be used as t
164b0 68 65 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 61 he argument to a
164c0 20 66 75 6e 63 74 69 6f 6e 2c 20 69 6e 20 77 68 function, in wh
164d0 69 63 68 20 63 61 73 65 20 74 68 65 20 61 2e 7a ich case the a.z
164e0 4e 61 6d 65 0a 2a 2a 20 66 69 65 6c 64 20 69 73 Name.** field is
164f0 20 6e 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a not used..**.**
16500 20 42 79 20 64 65 66 61 75 6c 74 20 74 68 65 20 By default the
16510 45 78 70 72 2e 7a 53 70 61 6e 20 66 69 65 6c 64 Expr.zSpan field
16520 20 68 6f 6c 64 73 20 61 20 68 75 6d 61 6e 2d 72 holds a human-r
16530 65 61 64 61 62 6c 65 20 64 65 73 63 72 69 70 74 eadable descript
16540 69 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 65 78 ion of.** the ex
16550 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 pression that is
16560 20 75 73 65 64 20 69 6e 20 74 68 65 20 67 65 6e used in the gen
16570 65 72 61 74 69 6f 6e 20 6f 66 20 65 72 72 6f 72 eration of error
16580 20 6d 65 73 73 61 67 65 73 20 61 6e 64 0a 2a 2a messages and.**
16590 20 63 6f 6c 75 6d 6e 20 6c 61 62 65 6c 73 2e 20 column labels.
165a0 20 49 6e 20 74 68 69 73 20 63 61 73 65 2c 20 45 In this case, E
165b0 78 70 72 2e 7a 53 70 61 6e 20 69 73 20 74 79 70 xpr.zSpan is typ
165c0 69 63 61 6c 6c 79 20 74 68 65 20 74 65 78 74 20 ically the text
165d0 6f 66 20 61 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 65 of a.** column e
165e0 78 70 72 65 73 73 69 6f 6e 20 61 73 20 69 74 20 xpression as it
165f0 65 78 69 73 74 73 20 69 6e 20 61 20 53 45 4c 45 exists in a SELE
16600 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 48 CT statement. H
16610 6f 77 65 76 65 72 2c 20 69 66 0a 2a 2a 20 74 68 owever, if.** th
16620 65 20 62 53 70 61 6e 49 73 54 61 62 20 66 6c 61 e bSpanIsTab fla
16630 67 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 7a g is set, then z
16640 53 70 61 6e 20 69 73 20 6f 76 65 72 6c 6f 61 64 Span is overload
16650 65 64 20 74 6f 20 6d 65 61 6e 20 74 68 65 20 6e ed to mean the n
16660 61 6d 65 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 ame.** of the re
16670 73 75 6c 74 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 sult column in t
16680 68 65 20 66 6f 72 6d 3a 20 44 41 54 41 42 41 53 he form: DATABAS
16690 45 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 2e 20 E.TABLE.COLUMN.
166a0 20 54 68 69 73 20 6c 61 74 65 72 0a 2a 2a 20 66 This later.** f
166b0 6f 72 6d 20 69 73 20 75 73 65 64 20 66 6f 72 20 orm is used for
166c0 6e 61 6d 65 20 72 65 73 6f 6c 75 74 69 6f 6e 20 name resolution
166d0 77 69 74 68 20 6e 65 73 74 65 64 20 46 52 4f 4d with nested FROM
166e0 20 63 6c 61 75 73 65 73 2e 0a 2a 2f 0a 73 74 72 clauses..*/.str
166f0 75 63 74 20 45 78 70 72 4c 69 73 74 20 7b 0a 20 uct ExprList {.
16700 20 69 6e 74 20 6e 45 78 70 72 3b 20 20 20 20 20 int nExpr;
16710 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
16720 72 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 r of expressions
16730 20 6f 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a on the list */.
16740 20 20 73 74 72 75 63 74 20 45 78 70 72 4c 69 73 struct ExprLis
16750 74 5f 69 74 65 6d 20 7b 20 2f 2a 20 46 6f 72 20 t_item { /* For
16760 65 61 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 each expression
16770 69 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 20 in the list */.
16780 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 Expr *pExpr;
16790 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
167a0 65 20 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 e list of expres
167b0 73 69 6f 6e 73 20 2a 2f 0a 20 20 20 20 63 68 61 sions */. cha
167c0 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 r *zName;
167d0 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 61 73 /* Token as
167e0 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 sociated with th
167f0 69 73 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f is expression */
16800 0a 20 20 20 20 63 68 61 72 20 2a 7a 53 70 61 6e . char *zSpan
16810 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
16820 4f 72 69 67 69 6e 61 6c 20 74 65 78 74 20 6f 66 Original text of
16830 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 the expression
16840 2a 2f 0a 20 20 20 20 75 38 20 73 6f 72 74 4f 72 */. u8 sortOr
16850 64 65 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f der; /
16860 2a 20 31 20 66 6f 72 20 44 45 53 43 20 6f 72 20 * 1 for DESC or
16870 30 20 66 6f 72 20 41 53 43 20 2a 2f 0a 20 20 20 0 for ASC */.
16880 20 75 6e 73 69 67 6e 65 64 20 64 6f 6e 65 20 3a unsigned done :
16890 31 3b 20 20 20 20 20 20 20 2f 2a 20 41 20 66 6c 1; /* A fl
168a0 61 67 20 74 6f 20 69 6e 64 69 63 61 74 65 20 77 ag to indicate w
168b0 68 65 6e 20 70 72 6f 63 65 73 73 69 6e 67 20 69 hen processing i
168c0 73 20 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 20 s finished */.
168d0 20 20 75 6e 73 69 67 6e 65 64 20 62 53 70 61 6e unsigned bSpan
168e0 49 73 54 61 62 20 3a 31 3b 20 2f 2a 20 7a 53 70 IsTab :1; /* zSp
168f0 61 6e 20 68 6f 6c 64 73 20 44 42 2e 54 41 42 4c an holds DB.TABL
16900 45 2e 43 4f 4c 55 4d 4e 20 2a 2f 0a 20 20 20 20 E.COLUMN */.
16910 75 6e 73 69 67 6e 65 64 20 72 65 75 73 61 62 6c unsigned reusabl
16920 65 20 3a 31 3b 20 20 20 2f 2a 20 43 6f 6e 73 74 e :1; /* Const
16930 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 20 69 ant expression i
16940 73 20 72 65 75 73 61 62 6c 65 20 2a 2f 0a 20 20 s reusable */.
16950 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 20 20 union {.
16960 73 74 72 75 63 74 20 7b 0a 20 20 20 20 20 20 20 struct {.
16970 20 75 31 36 20 69 4f 72 64 65 72 42 79 43 6f 6c u16 iOrderByCol
16980 3b 20 20 20 20 20 20 2f 2a 20 46 6f 72 20 4f 52 ; /* For OR
16990 44 45 52 20 42 59 2c 20 63 6f 6c 75 6d 6e 20 6e DER BY, column n
169a0 75 6d 62 65 72 20 69 6e 20 72 65 73 75 6c 74 20 umber in result
169b0 73 65 74 20 2a 2f 0a 20 20 20 20 20 20 20 20 75 set */. u
169c0 31 36 20 69 41 6c 69 61 73 3b 20 20 20 20 20 20 16 iAlias;
169d0 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e /* Index in
169e0 74 6f 20 50 61 72 73 65 2e 61 41 6c 69 61 73 5b to Parse.aAlias[
169f0 5d 20 66 6f 72 20 7a 4e 61 6d 65 20 2a 2f 0a 20 ] for zName */.
16a00 20 20 20 20 20 7d 20 78 3b 0a 20 20 20 20 20 20 } x;.
16a10 69 6e 74 20 69 43 6f 6e 73 74 45 78 70 72 52 65 int iConstExprRe
16a20 67 3b 20 20 20 20 20 20 2f 2a 20 52 65 67 69 73 g; /* Regis
16a30 74 65 72 20 69 6e 20 77 68 69 63 68 20 45 78 70 ter in which Exp
16a40 72 20 76 61 6c 75 65 20 69 73 20 63 61 63 68 65 r value is cache
16a50 64 20 2a 2f 0a 20 20 20 20 7d 20 75 3b 0a 20 20 d */. } u;.
16a60 7d 20 2a 61 3b 20 20 20 20 20 20 20 20 20 20 20 } *a;
16a70 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 20 /* Alloc
16a80 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f 20 67 a power of two g
16a90 72 65 61 74 65 72 20 6f 72 20 65 71 75 61 6c 20 reater or equal
16aa0 74 6f 20 6e 45 78 70 72 20 2a 2f 0a 7d 3b 0a 0a to nExpr */.};..
16ab0 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
16ac0 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 e of this struct
16ad0 75 72 65 20 69 73 20 75 73 65 64 20 62 79 20 74 ure is used by t
16ae0 68 65 20 70 61 72 73 65 72 20 74 6f 20 72 65 63 he parser to rec
16af0 6f 72 64 20 62 6f 74 68 0a 2a 2a 20 74 68 65 20 ord both.** the
16b00 70 61 72 73 65 20 74 72 65 65 20 66 6f 72 20 61 parse tree for a
16b10 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 61 6e 64 n expression and
16b20 20 74 68 65 20 73 70 61 6e 20 6f 66 20 69 6e 70 the span of inp
16b30 75 74 20 74 65 78 74 20 66 6f 72 20 61 6e 0a 2a ut text for an.*
16b40 2a 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a 2f * expression..*/
16b50 0a 73 74 72 75 63 74 20 45 78 70 72 53 70 61 6e .struct ExprSpan
16b60 20 7b 0a 20 20 45 78 70 72 20 2a 70 45 78 70 72 {. Expr *pExpr
16b70 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ; /* Th
16b80 65 20 65 78 70 72 65 73 73 69 6f 6e 20 70 61 72 e expression par
16b90 73 65 20 74 72 65 65 20 2a 2f 0a 20 20 63 6f 6e se tree */. con
16ba0 73 74 20 63 68 61 72 20 2a 7a 53 74 61 72 74 3b st char *zStart;
16bb0 20 20 20 2f 2a 20 46 69 72 73 74 20 63 68 61 72 /* First char
16bc0 61 63 74 65 72 20 6f 66 20 69 6e 70 75 74 20 74 acter of input t
16bd0 65 78 74 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 ext */. const c
16be0 68 61 72 20 2a 7a 45 6e 64 3b 20 20 20 20 20 2f har *zEnd; /
16bf0 2a 20 4f 6e 65 20 63 68 61 72 61 63 74 65 72 20 * One character
16c00 70 61 73 74 20 74 68 65 20 65 6e 64 20 6f 66 20 past the end of
16c10 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 7d 3b input text */.};
16c20 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 ../*.** An insta
16c30 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 nce of this stru
16c40 63 74 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 61 cture can hold a
16c50 20 73 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 20 simple list of
16c60 69 64 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a 20 identifiers,.**
16c70 73 75 63 68 20 61 73 20 74 68 65 20 6c 69 73 74 such as the list
16c80 20 22 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 20 "a,b,c" in the
16c90 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 6d following statem
16ca0 65 6e 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ents:.**.**
16cb0 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 INSERT INTO t(a
16cc0 2c 62 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e 2e ,b,c) VALUES ...
16cd0 3b 0a 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 ;.** CREATE
16ce0 20 49 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 28 INDEX idx ON t(
16cf0 61 2c 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 20 a,b,c);.**
16d00 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20 74 CREATE TRIGGER t
16d10 72 69 67 20 42 45 46 4f 52 45 20 55 50 44 41 54 rig BEFORE UPDAT
16d20 45 20 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e 2e E ON t(a,b,c) ..
16d30 2e 3b 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 4c .;.**.** The IdL
16d40 69 73 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 20 ist.a.idx field
16d50 69 73 20 75 73 65 64 20 77 68 65 6e 20 74 68 65 is used when the
16d60 20 49 64 4c 69 73 74 20 72 65 70 72 65 73 65 6e IdList represen
16d70 74 73 20 74 68 65 20 6c 69 73 74 20 6f 66 0a 2a ts the list of.*
16d80 2a 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 * column names a
16d90 66 74 65 72 20 61 20 74 61 62 6c 65 20 6e 61 6d fter a table nam
16da0 65 20 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 73 e in an INSERT s
16db0 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 68 tatement. In th
16dc0 65 20 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a 2a e statement.**.*
16dd0 2a 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 * INSERT INT
16de0 4f 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a 2a O t(a,b,c) ....*
16df0 2a 0a 2a 2a 20 49 66 20 22 61 22 20 69 73 20 74 *.** If "a" is t
16e00 68 65 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 6f he k-th column o
16e10 66 20 74 61 62 6c 65 20 22 74 22 2c 20 74 68 65 f table "t", the
16e20 6e 20 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 64 n IdList.a[0].id
16e30 78 3d 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 x==k..*/.struct
16e40 49 64 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 63 IdList {. struc
16e50 74 20 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b 0a t IdList_item {.
16e60 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b char *zName;
16e70 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 /* Name of
16e80 20 74 68 65 20 69 64 65 6e 74 69 66 69 65 72 20 the identifier
16e90 2a 2f 0a 20 20 20 20 69 6e 74 20 69 64 78 3b 20 */. int idx;
16ea0 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 /* Inde
16eb0 78 20 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 2e x in some Table.
16ec0 61 43 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c 75 aCol[] of a colu
16ed0 6d 6e 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 2a mn named zName *
16ee0 2f 0a 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 20 /. } *a;. int
16ef0 6e 49 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 nId; /*
16f00 4e 75 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 69 Number of identi
16f10 66 69 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 73 fiers on the lis
16f20 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 t */.};../*.** T
16f30 68 65 20 62 69 74 6d 61 73 6b 20 64 61 74 61 74 he bitmask datat
16f40 79 70 65 20 64 65 66 69 6e 65 64 20 62 65 6c 6f ype defined belo
16f50 77 20 69 73 20 75 73 65 64 20 66 6f 72 20 76 61 w is used for va
16f60 72 69 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 69 rious optimizati
16f70 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e 67 ons..**.** Chang
16f80 69 6e 67 20 74 68 69 73 20 66 72 6f 6d 20 61 20 ing this from a
16f90 36 34 2d 62 69 74 20 74 6f 20 61 20 33 32 2d 62 64-bit to a 32-b
16fa0 69 74 20 74 79 70 65 20 6c 69 6d 69 74 73 20 74 it type limits t
16fb0 68 65 20 6e 75 6d 62 65 72 20 6f 66 0a 2a 2a 20 he number of.**
16fc0 74 61 62 6c 65 73 20 69 6e 20 61 20 6a 6f 69 6e tables in a join
16fd0 20 74 6f 20 33 32 20 69 6e 73 74 65 61 64 20 6f to 32 instead o
16fe0 66 20 36 34 2e 20 20 42 75 74 20 69 74 20 61 6c f 64. But it al
16ff0 73 6f 20 72 65 64 75 63 65 73 20 74 68 65 20 73 so reduces the s
17000 69 7a 65 0a 2a 2a 20 6f 66 20 74 68 65 20 6c 69 ize.** of the li
17010 62 72 61 72 79 20 62 79 20 37 33 38 20 62 79 74 brary by 738 byt
17020 65 73 20 6f 6e 20 69 78 38 36 2e 0a 2a 2f 0a 74 es on ix86..*/.t
17030 79 70 65 64 65 66 20 75 36 34 20 42 69 74 6d 61 ypedef u64 Bitma
17040 73 6b 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e sk;../*.** The n
17050 75 6d 62 65 72 20 6f 66 20 62 69 74 73 20 69 6e umber of bits in
17060 20 61 20 42 69 74 6d 61 73 6b 2e 20 20 22 42 4d a Bitmask. "BM
17070 53 22 20 6d 65 61 6e 73 20 22 42 69 74 4d 61 73 S" means "BitMas
17080 6b 20 53 69 7a 65 22 2e 0a 2a 2f 0a 23 64 65 66 k Size"..*/.#def
17090 69 6e 65 20 42 4d 53 20 20 28 28 69 6e 74 29 28 ine BMS ((int)(
170a0 73 69 7a 65 6f 66 28 42 69 74 6d 61 73 6b 29 2a sizeof(Bitmask)*
170b0 38 29 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 62 69 74 8))../*.** A bit
170c0 20 69 6e 20 61 20 42 69 74 6d 61 73 6b 0a 2a 2f in a Bitmask.*/
170d0 0a 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 54 .#define MASKBIT
170e0 28 6e 29 20 20 20 28 28 28 42 69 74 6d 61 73 6b (n) (((Bitmask
170f0 29 31 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e )1)<<(n)).#defin
17100 65 20 4d 41 53 4b 42 49 54 33 32 28 6e 29 20 28 e MASKBIT32(n) (
17110 28 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 31 ((unsigned int)1
17120 29 3c 3c 28 6e 29 29 0a 0a 2f 2a 0a 2a 2a 20 54 )<<(n))../*.** T
17130 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
17140 75 63 74 75 72 65 20 64 65 73 63 72 69 62 65 73 ucture describes
17150 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 the FROM clause
17160 20 6f 66 20 61 20 53 45 4c 45 43 54 20 73 74 61 of a SELECT sta
17170 74 65 6d 65 6e 74 2e 0a 2a 2a 20 45 61 63 68 20 tement..** Each
17180 74 61 62 6c 65 20 6f 72 20 73 75 62 71 75 65 72 table or subquer
17190 79 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c y in the FROM cl
171a0 61 75 73 65 20 69 73 20 61 20 73 65 70 61 72 61 ause is a separa
171b0 74 65 20 65 6c 65 6d 65 6e 74 20 6f 66 0a 2a 2a te element of.**
171c0 20 74 68 65 20 53 72 63 4c 69 73 74 2e 61 5b 5d the SrcList.a[]
171d0 20 61 72 72 61 79 2e 0a 2a 2a 0a 2a 2a 20 57 69 array..**.** Wi
171e0 74 68 20 74 68 65 20 61 64 64 69 74 69 6f 6e 20 th the addition
171f0 6f 66 20 6d 75 6c 74 69 70 6c 65 20 64 61 74 61 of multiple data
17200 62 61 73 65 20 73 75 70 70 6f 72 74 2c 20 74 68 base support, th
17210 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
17220 63 74 75 72 65 0a 2a 2a 20 63 61 6e 20 61 6c 73 cture.** can als
17230 6f 20 62 65 20 75 73 65 64 20 74 6f 20 64 65 73 o be used to des
17240 63 72 69 62 65 20 61 20 70 61 72 74 69 63 75 6c cribe a particul
17250 61 72 20 74 61 62 6c 65 20 73 75 63 68 20 61 73 ar table such as
17260 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 0a the table that.
17270 2a 2a 20 69 73 20 6d 6f 64 69 66 69 65 64 20 62 ** is modified b
17280 79 20 61 6e 20 49 4e 53 45 52 54 2c 20 44 45 4c y an INSERT, DEL
17290 45 54 45 2c 20 6f 72 20 55 50 44 41 54 45 20 73 ETE, or UPDATE s
172a0 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 73 74 tatement. In st
172b0 61 6e 64 61 72 64 20 53 51 4c 2c 0a 2a 2a 20 73 andard SQL,.** s
172c0 75 63 68 20 61 20 74 61 62 6c 65 20 6d 75 73 74 uch a table must
172d0 20 62 65 20 61 20 73 69 6d 70 6c 65 20 6e 61 6d be a simple nam
172e0 65 3a 20 49 44 2e 20 20 42 75 74 20 69 6e 20 53 e: ID. But in S
172f0 51 4c 69 74 65 2c 20 74 68 65 20 74 61 62 6c 65 QLite, the table
17300 20 63 61 6e 0a 2a 2a 20 6e 6f 77 20 62 65 20 69 can.** now be i
17310 64 65 6e 74 69 66 69 65 64 20 62 79 20 61 20 64 dentified by a d
17320 61 74 61 62 61 73 65 20 6e 61 6d 65 2c 20 61 20 atabase name, a
17330 64 6f 74 2c 20 74 68 65 6e 20 74 68 65 20 74 61 dot, then the ta
17340 62 6c 65 20 6e 61 6d 65 3a 20 49 44 2e 49 44 2e ble name: ID.ID.
17350 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6a 6f 69 6e 74 .**.** The joint
17360 79 70 65 20 73 74 61 72 74 73 20 6f 75 74 20 73 ype starts out s
17370 68 6f 77 69 6e 67 20 74 68 65 20 6a 6f 69 6e 20 howing the join
17380 74 79 70 65 20 62 65 74 77 65 65 6e 20 74 68 65 type between the
17390 20 63 75 72 72 65 6e 74 20 74 61 62 6c 65 0a 2a current table.*
173a0 2a 20 61 6e 64 20 74 68 65 20 6e 65 78 74 20 74 * and the next t
173b0 61 62 6c 65 20 6f 6e 20 74 68 65 20 6c 69 73 74 able on the list
173c0 2e 20 20 54 68 65 20 70 61 72 73 65 72 20 62 75 . The parser bu
173d0 69 6c 64 73 20 74 68 65 20 6c 69 73 74 20 74 68 ilds the list th
173e0 69 73 20 77 61 79 2e 0a 2a 2a 20 42 75 74 20 73 is way..** But s
173f0 71 6c 69 74 65 33 53 72 63 4c 69 73 74 53 68 69 qlite3SrcListShi
17400 66 74 4a 6f 69 6e 54 79 70 65 28 29 20 6c 61 74 ftJoinType() lat
17410 65 72 20 73 68 69 66 74 73 20 74 68 65 20 6a 6f er shifts the jo
17420 69 6e 74 79 70 65 73 20 73 6f 20 74 68 61 74 20 intypes so that
17430 65 61 63 68 0a 2a 2a 20 6a 6f 69 6e 74 79 70 65 each.** jointype
17440 20 65 78 70 72 65 73 73 65 73 20 74 68 65 20 6a expresses the j
17450 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 65 20 oin between the
17460 74 61 62 6c 65 20 61 6e 64 20 74 68 65 20 70 72 table and the pr
17470 65 76 69 6f 75 73 20 74 61 62 6c 65 2e 0a 2a 2a evious table..**
17480 0a 2a 2a 20 49 6e 20 74 68 65 20 63 6f 6c 55 73 .** In the colUs
17490 65 64 20 66 69 65 6c 64 2c 20 74 68 65 20 68 69 ed field, the hi
174a0 67 68 2d 6f 72 64 65 72 20 62 69 74 20 28 62 69 gh-order bit (bi
174b0 74 20 36 33 29 20 69 73 20 73 65 74 20 69 66 20 t 63) is set if
174c0 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 63 6f 6e the table.** con
174d0 74 61 69 6e 73 20 6d 6f 72 65 20 74 68 61 6e 20 tains more than
174e0 36 33 20 63 6f 6c 75 6d 6e 73 20 61 6e 64 20 74 63 columns and t
174f0 68 65 20 36 34 2d 74 68 20 6f 72 20 6c 61 74 65 he 64-th or late
17500 72 20 63 6f 6c 75 6d 6e 20 69 73 20 75 73 65 64 r column is used
17510 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 72 63 4c ..*/.struct SrcL
17520 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 53 72 63 ist {. int nSrc
17530 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 ; /* Numb
17540 65 72 20 6f 66 20 74 61 62 6c 65 73 20 6f 72 20 er of tables or
17550 73 75 62 71 75 65 72 69 65 73 20 69 6e 20 74 68 subqueries in th
17560 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f e FROM clause */
17570 0a 20 20 75 33 32 20 6e 41 6c 6c 6f 63 3b 20 20 . u32 nAlloc;
17580 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
17590 20 65 6e 74 72 69 65 73 20 61 6c 6c 6f 63 61 74 entries allocat
175a0 65 64 20 69 6e 20 61 5b 5d 20 62 65 6c 6f 77 20 ed in a[] below
175b0 2a 2f 0a 20 20 73 74 72 75 63 74 20 53 72 63 4c */. struct SrcL
175c0 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 20 20 53 ist_item {. S
175d0 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 chema *pSchema;
175e0 20 2f 2a 20 53 63 68 65 6d 61 20 74 6f 20 77 68 /* Schema to wh
175f0 69 63 68 20 74 68 69 73 20 69 74 65 6d 20 69 73 ich this item is
17600 20 66 69 78 65 64 20 2a 2f 0a 20 20 20 20 63 68 fixed */. ch
17610 61 72 20 2a 7a 44 61 74 61 62 61 73 65 3b 20 20 ar *zDatabase;
17620 2f 2a 20 4e 61 6d 65 20 6f 66 20 64 61 74 61 62 /* Name of datab
17630 61 73 65 20 68 6f 6c 64 69 6e 67 20 74 68 69 73 ase holding this
17640 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 table */. ch
17650 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
17660 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 /* Name of the t
17670 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 able */. char
17680 20 2a 7a 41 6c 69 61 73 3b 20 20 20 20 20 2f 2a *zAlias; /*
17690 20 54 68 65 20 22 42 22 20 70 61 72 74 20 6f 66 The "B" part of
176a0 20 61 20 22 41 20 41 53 20 42 22 20 70 68 72 61 a "A AS B" phra
176b0 73 65 2e 20 20 7a 4e 61 6d 65 20 69 73 20 74 68 se. zName is th
176c0 65 20 22 41 22 20 2a 2f 0a 20 20 20 20 54 61 62 e "A" */. Tab
176d0 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 2f le *pTab; /
176e0 2a 20 41 6e 20 53 51 4c 20 74 61 62 6c 65 20 63 * An SQL table c
176f0 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 orresponding to
17700 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 20 53 65 6c zName */. Sel
17710 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 2f ect *pSelect; /
17720 2a 20 41 20 53 45 4c 45 43 54 20 73 74 61 74 65 * A SELECT state
17730 6d 65 6e 74 20 75 73 65 64 20 69 6e 20 70 6c 61 ment used in pla
17740 63 65 20 6f 66 20 61 20 74 61 62 6c 65 20 6e 61 ce of a table na
17750 6d 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 61 64 me */. int ad
17760 64 72 46 69 6c 6c 53 75 62 3b 20 20 2f 2a 20 41 drFillSub; /* A
17770 64 64 72 65 73 73 20 6f 66 20 73 75 62 72 6f 75 ddress of subrou
17780 74 69 6e 65 20 74 6f 20 6d 61 6e 69 66 65 73 74 tine to manifest
17790 20 61 20 73 75 62 71 75 65 72 79 20 2a 2f 0a 20 a subquery */.
177a0 20 20 20 69 6e 74 20 72 65 67 52 65 74 75 72 6e int regReturn
177b0 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 ; /* Register
177c0 20 68 6f 6c 64 69 6e 67 20 72 65 74 75 72 6e 20 holding return
177d0 61 64 64 72 65 73 73 20 6f 66 20 61 64 64 72 46 address of addrF
177e0 69 6c 6c 53 75 62 20 2a 2f 0a 20 20 20 20 69 6e illSub */. in
177f0 74 20 72 65 67 52 65 73 75 6c 74 3b 20 20 20 20 t regResult;
17800 2f 2a 20 52 65 67 69 73 74 65 72 73 20 68 6f 6c /* Registers hol
17810 64 69 6e 67 20 72 65 73 75 6c 74 73 20 6f 66 20 ding results of
17820 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a a co-routine */.
17830 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 20 20 struct {.
17840 20 20 20 75 38 20 6a 6f 69 6e 74 79 70 65 3b 20 u8 jointype;
17850 20 20 20 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 /* Type of
17860 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 69 join between thi
17870 73 20 61 62 6c 65 20 61 6e 64 20 74 68 65 20 70 s able and the p
17880 72 65 76 69 6f 75 73 20 2a 2f 0a 20 20 20 20 20 revious */.
17890 20 75 6e 73 69 67 6e 65 64 20 6e 6f 74 49 6e 64 unsigned notInd
178a0 65 78 65 64 20 3a 31 3b 20 20 20 20 2f 2a 20 54 exed :1; /* T
178b0 72 75 65 20 69 66 20 74 68 65 72 65 20 69 73 20 rue if there is
178c0 61 20 4e 4f 54 20 49 4e 44 45 58 45 44 20 63 6c a NOT INDEXED cl
178d0 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 75 6e ause */. un
178e0 73 69 67 6e 65 64 20 69 73 49 6e 64 65 78 65 64 signed isIndexed
178f0 42 79 20 3a 31 3b 20 20 20 2f 2a 20 54 72 75 65 By :1; /* True
17900 20 69 66 20 74 68 65 72 65 20 69 73 20 61 6e 20 if there is an
17910 49 4e 44 45 58 45 44 20 42 59 20 63 6c 61 75 73 INDEXED BY claus
17920 65 20 2a 2f 0a 20 20 20 20 20 20 75 6e 73 69 67 e */. unsig
17930 6e 65 64 20 69 73 54 61 62 46 75 6e 63 20 3a 31 ned isTabFunc :1
17940 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 ; /* True if
17950 20 74 61 62 6c 65 2d 76 61 6c 75 65 64 2d 66 75 table-valued-fu
17960 6e 63 74 69 6f 6e 20 73 79 6e 74 61 78 20 2a 2f nction syntax */
17970 0a 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 . unsigned
17980 69 73 43 6f 72 72 65 6c 61 74 65 64 20 3a 31 3b isCorrelated :1;
17990 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 75 62 /* True if sub
179a0 2d 71 75 65 72 79 20 69 73 20 63 6f 72 72 65 6c -query is correl
179b0 61 74 65 64 20 2a 2f 0a 20 20 20 20 20 20 75 6e ated */. un
179c0 73 69 67 6e 65 64 20 76 69 61 43 6f 72 6f 75 74 signed viaCorout
179d0 69 6e 65 20 3a 31 3b 20 20 2f 2a 20 49 6d 70 6c ine :1; /* Impl
179e0 65 6d 65 6e 74 65 64 20 61 73 20 61 20 63 6f 2d emented as a co-
179f0 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 20 20 20 routine */.
17a00 20 75 6e 73 69 67 6e 65 64 20 69 73 52 65 63 75 unsigned isRecu
17a10 72 73 69 76 65 20 3a 31 3b 20 20 20 2f 2a 20 54 rsive :1; /* T
17a20 72 75 65 20 66 6f 72 20 72 65 63 75 72 73 69 76 rue for recursiv
17a30 65 20 72 65 66 65 72 65 6e 63 65 20 69 6e 20 57 e reference in W
17a40 49 54 48 20 2a 2f 0a 20 20 20 20 7d 20 66 67 3b ITH */. } fg;
17a50 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
17a60 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 20 20 20 OMIT_EXPLAIN.
17a70 20 75 38 20 69 53 65 6c 65 63 74 49 64 3b 20 20 u8 iSelectId;
17a80 20 20 20 2f 2a 20 49 66 20 70 53 65 6c 65 63 74 /* If pSelect
17a90 21 3d 30 2c 20 74 68 65 20 69 64 20 6f 66 20 74 !=0, the id of t
17aa0 68 65 20 73 75 62 2d 73 65 6c 65 63 74 20 69 6e he sub-select in
17ab0 20 45 51 50 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 EQP */.#endif.
17ac0 20 20 20 69 6e 74 20 69 43 75 72 73 6f 72 3b 20 int iCursor;
17ad0 20 20 20 20 20 2f 2a 20 54 68 65 20 56 44 42 45 /* The VDBE
17ae0 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 75 cursor number u
17af0 73 65 64 20 74 6f 20 61 63 63 65 73 73 20 74 68 sed to access th
17b00 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 is table */.
17b10 45 78 70 72 20 2a 70 4f 6e 3b 20 20 20 20 20 20 Expr *pOn;
17b20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 63 6c 61 75 /* The ON clau
17b30 73 65 20 6f 66 20 61 20 6a 6f 69 6e 20 2a 2f 0a se of a join */.
17b40 20 20 20 20 49 64 4c 69 73 74 20 2a 70 55 73 69 IdList *pUsi
17b50 6e 67 3b 20 20 20 2f 2a 20 54 68 65 20 55 53 49 ng; /* The USI
17b60 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 61 20 6a NG clause of a j
17b70 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 69 74 6d 61 oin */. Bitma
17b80 73 6b 20 63 6f 6c 55 73 65 64 3b 20 20 2f 2a 20 sk colUsed; /*
17b90 42 69 74 20 4e 20 28 31 3c 3c 4e 29 20 73 65 74 Bit N (1<<N) set
17ba0 20 69 66 20 63 6f 6c 75 6d 6e 20 4e 20 6f 66 20 if column N of
17bb0 70 54 61 62 20 69 73 20 75 73 65 64 20 2a 2f 0a pTab is used */.
17bc0 20 20 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 union {.
17bd0 20 20 63 68 61 72 20 2a 7a 49 6e 64 65 78 65 64 char *zIndexed
17be0 42 79 3b 20 20 20 20 2f 2a 20 49 64 65 6e 74 69 By; /* Identi
17bf0 66 69 65 72 20 66 72 6f 6d 20 22 49 4e 44 45 58 fier from "INDEX
17c00 45 44 20 42 59 20 3c 7a 49 6e 64 65 78 3e 22 20 ED BY <zIndex>"
17c10 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 clause */.
17c20 45 78 70 72 4c 69 73 74 20 2a 70 46 75 6e 63 41 ExprList *pFuncA
17c30 72 67 3b 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 rg; /* Argument
17c40 73 20 74 6f 20 74 61 62 6c 65 2d 76 61 6c 75 65 s to table-value
17c50 64 2d 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 d-function */.
17c60 20 20 7d 20 75 31 3b 0a 20 20 20 20 49 6e 64 65 } u1;. Inde
17c70 78 20 2a 70 49 42 49 6e 64 65 78 3b 20 20 2f 2a x *pIBIndex; /*
17c80 20 49 6e 64 65 78 20 73 74 72 75 63 74 75 72 65 Index structure
17c90 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 corresponding t
17ca0 6f 20 75 31 2e 7a 49 6e 64 65 78 65 64 42 79 20 o u1.zIndexedBy
17cb0 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 20 20 20 */. } a[1];
17cc0 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 /* One
17cd0 65 6e 74 72 79 20 66 6f 72 20 65 61 63 68 20 69 entry for each i
17ce0 64 65 6e 74 69 66 69 65 72 20 6f 6e 20 74 68 65 dentifier on the
17cf0 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a list */.};../*.
17d00 2a 2a 20 50 65 72 6d 69 74 74 65 64 20 76 61 6c ** Permitted val
17d10 75 65 73 20 6f 66 20 74 68 65 20 53 72 63 4c 69 ues of the SrcLi
17d20 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 20 66 69 st.a.jointype fi
17d30 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4a eld.*/.#define J
17d40 54 5f 49 4e 4e 45 52 20 20 20 20 20 30 78 30 30 T_INNER 0x00
17d50 30 31 20 20 20 20 2f 2a 20 41 6e 79 20 6b 69 6e 01 /* Any kin
17d60 64 20 6f 66 20 69 6e 6e 65 72 20 6f 72 20 63 72 d of inner or cr
17d70 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 oss join */.#def
17d80 69 6e 65 20 4a 54 5f 43 52 4f 53 53 20 20 20 20 ine JT_CROSS
17d90 20 30 78 30 30 30 32 20 20 20 20 2f 2a 20 45 78 0x0002 /* Ex
17da0 70 6c 69 63 69 74 20 75 73 65 20 6f 66 20 74 68 plicit use of th
17db0 65 20 43 52 4f 53 53 20 6b 65 79 77 6f 72 64 20 e CROSS keyword
17dc0 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4e 41 */.#define JT_NA
17dd0 54 55 52 41 4c 20 20 20 30 78 30 30 30 34 20 20 TURAL 0x0004
17de0 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 20 /* True for a
17df0 22 6e 61 74 75 72 61 6c 22 20 6a 6f 69 6e 20 2a "natural" join *
17e00 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4c 45 46 /.#define JT_LEF
17e10 54 20 20 20 20 20 20 30 78 30 30 30 38 20 20 20 T 0x0008
17e20 20 2f 2a 20 4c 65 66 74 20 6f 75 74 65 72 20 6a /* Left outer j
17e30 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a oin */.#define J
17e40 54 5f 52 49 47 48 54 20 20 20 20 20 30 78 30 30 T_RIGHT 0x00
17e50 31 30 20 20 20 20 2f 2a 20 52 69 67 68 74 20 6f 10 /* Right o
17e60 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 uter join */.#de
17e70 66 69 6e 65 20 4a 54 5f 4f 55 54 45 52 20 20 20 fine JT_OUTER
17e80 20 20 30 78 30 30 32 30 20 20 20 20 2f 2a 20 54 0x0020 /* T
17e90 68 65 20 22 4f 55 54 45 52 22 20 6b 65 79 77 6f he "OUTER" keywo
17ea0 72 64 20 69 73 20 70 72 65 73 65 6e 74 20 2a 2f rd is present */
17eb0 0a 23 64 65 66 69 6e 65 20 4a 54 5f 45 52 52 4f .#define JT_ERRO
17ec0 52 20 20 20 20 20 30 78 30 30 34 30 20 20 20 20 R 0x0040
17ed0 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 20 75 6e /* unknown or un
17ee0 73 75 70 70 6f 72 74 65 64 20 6a 6f 69 6e 20 74 supported join t
17ef0 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 46 ype */.../*.** F
17f00 6c 61 67 73 20 61 70 70 72 6f 70 72 69 61 74 65 lags appropriate
17f10 20 66 6f 72 20 74 68 65 20 77 63 74 72 6c 46 6c for the wctrlFl
17f20 61 67 73 20 70 61 72 61 6d 65 74 65 72 20 6f 66 ags parameter of
17f30 20 73 71 6c 69 74 65 33 57 68 65 72 65 42 65 67 sqlite3WhereBeg
17f40 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 68 65 20 in().** and the
17f50 57 68 65 72 65 49 6e 66 6f 2e 77 63 74 72 6c 46 WhereInfo.wctrlF
17f60 6c 61 67 73 20 6d 65 6d 62 65 72 2e 0a 2a 2f 0a lags member..*/.
17f70 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 #define WHERE_OR
17f80 44 45 52 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 DERBY_NORMAL 0
17f90 78 30 30 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a x0000 /* No-op *
17fa0 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
17fb0 4f 52 44 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 ORDERBY_MIN
17fc0 20 30 78 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 0x0001 /* ORDER
17fd0 20 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 BY processing f
17fe0 6f 72 20 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f or min() func */
17ff0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
18000 52 44 45 52 42 59 5f 4d 41 58 20 20 20 20 20 20 RDERBY_MAX
18010 30 78 30 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 0x0002 /* ORDER
18020 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f BY processing fo
18030 72 20 6d 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a r max() func */.
18040 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e #define WHERE_ON
18050 45 50 41 53 53 5f 44 45 53 49 52 45 44 20 20 30 EPASS_DESIRED 0
18060 78 30 30 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f x0004 /* Want to
18070 20 64 6f 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 do one-pass UPD
18080 41 54 45 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 ATE/DELETE */.#d
18090 65 66 69 6e 65 20 57 48 45 52 45 5f 44 55 50 4c efine WHERE_DUPL
180a0 49 43 41 54 45 53 5f 4f 4b 20 20 20 20 30 78 30 ICATES_OK 0x0
180b0 30 30 38 20 2f 2a 20 4f 6b 20 74 6f 20 72 65 74 008 /* Ok to ret
180c0 75 72 6e 20 61 20 72 6f 77 20 6d 6f 72 65 20 74 urn a row more t
180d0 68 61 6e 20 6f 6e 63 65 20 2a 2f 0a 23 64 65 66 han once */.#def
180e0 69 6e 65 20 57 48 45 52 45 5f 4f 4d 49 54 5f 4f ine WHERE_OMIT_O
180f0 50 45 4e 5f 43 4c 4f 53 45 20 20 30 78 30 30 31 PEN_CLOSE 0x001
18100 30 20 2f 2a 20 54 61 62 6c 65 20 63 75 72 73 6f 0 /* Table curso
18110 72 73 20 61 72 65 20 61 6c 72 65 61 64 79 20 6f rs are already o
18120 70 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 pen */.#define W
18130 48 45 52 45 5f 46 4f 52 43 45 5f 54 41 42 4c 45 HERE_FORCE_TABLE
18140 20 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 0x0020 /*
18150 44 6f 20 6e 6f 74 20 75 73 65 20 61 6e 20 69 6e Do not use an in
18160 64 65 78 2d 6f 6e 6c 79 20 73 65 61 72 63 68 20 dex-only search
18170 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
18180 5f 4f 4e 45 54 41 42 4c 45 5f 4f 4e 4c 59 20 20 _ONETABLE_ONLY
18190 20 20 30 78 30 30 34 30 20 2f 2a 20 4f 6e 6c 79 0x0040 /* Only
181a0 20 63 6f 64 65 20 74 68 65 20 31 73 74 20 74 61 code the 1st ta
181b0 62 6c 65 20 69 6e 20 70 54 61 62 4c 69 73 74 20 ble in pTabList
181c0 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
181d0 5f 4e 4f 5f 41 55 54 4f 49 4e 44 45 58 20 20 20 _NO_AUTOINDEX
181e0 20 20 30 78 30 30 38 30 20 2f 2a 20 44 69 73 61 0x0080 /* Disa
181f0 6c 6c 6f 77 20 61 75 74 6f 6d 61 74 69 63 20 69 llow automatic i
18200 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e ndexes */.#defin
18210 65 20 57 48 45 52 45 5f 47 52 4f 55 50 42 59 20 e WHERE_GROUPBY
18220 20 20 20 20 20 20 20 20 20 30 78 30 31 30 30 20 0x0100
18230 2f 2a 20 70 4f 72 64 65 72 42 79 20 69 73 20 72 /* pOrderBy is r
18240 65 61 6c 6c 79 20 61 20 47 52 4f 55 50 20 42 59 eally a GROUP BY
18250 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
18260 45 5f 44 49 53 54 49 4e 43 54 42 59 20 20 20 20 E_DISTINCTBY
18270 20 20 20 30 78 30 32 30 30 20 2f 2a 20 70 4f 72 0x0200 /* pOr
18280 64 65 72 62 79 20 69 73 20 72 65 61 6c 6c 79 20 derby is really
18290 61 20 44 49 53 54 49 4e 43 54 20 63 6c 61 75 73 a DISTINCT claus
182a0 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 e */.#define WHE
182b0 52 45 5f 57 41 4e 54 5f 44 49 53 54 49 4e 43 54 RE_WANT_DISTINCT
182c0 20 20 20 20 30 78 30 34 30 30 20 2f 2a 20 41 6c 0x0400 /* Al
182d0 6c 20 6f 75 74 70 75 74 20 6e 65 65 64 73 20 74 l output needs t
182e0 6f 20 62 65 20 64 69 73 74 69 6e 63 74 20 2a 2f o be distinct */
182f0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 53 .#define WHERE_S
18300 4f 52 54 42 59 47 52 4f 55 50 20 20 20 20 20 20 ORTBYGROUP
18310 30 78 30 38 30 30 20 2f 2a 20 53 75 70 70 6f 72 0x0800 /* Suppor
18320 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 t sqlite3WhereIs
18330 53 6f 72 74 65 64 28 29 20 2a 2f 0a 23 64 65 66 Sorted() */.#def
18340 69 6e 65 20 57 48 45 52 45 5f 52 45 4f 50 45 4e ine WHERE_REOPEN
18350 5f 49 44 58 20 20 20 20 20 20 20 30 78 31 30 30 _IDX 0x100
18360 30 20 2f 2a 20 54 72 79 20 74 6f 20 75 73 65 20 0 /* Try to use
18370 4f 50 5f 52 65 6f 70 65 6e 49 64 78 20 2a 2f 0a OP_ReopenIdx */.
18380 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e #define WHERE_ON
18390 45 50 41 53 53 5f 4d 55 4c 54 49 52 4f 57 20 30 EPASS_MULTIROW 0
183a0 78 32 30 30 30 20 2f 2a 20 4f 4e 45 50 41 53 53 x2000 /* ONEPASS
183b0 20 69 73 20 6f 6b 20 77 69 74 68 20 6d 75 6c 74 is ok with mult
183c0 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 0a 2f 2a iple rows */../*
183d0 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 72 6e 20 Allowed return
183e0 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 71 6c 69 values from sqli
183f0 74 65 33 57 68 65 72 65 49 73 44 69 73 74 69 6e te3WhereIsDistin
18400 63 74 28 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ct().*/.#define
18410 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 4e WHERE_DISTINCT_N
18420 4f 4f 50 20 20 20 20 20 20 30 20 20 2f 2a 20 44 OOP 0 /* D
18430 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 64 20 ISTINCT keyword
18440 6e 6f 74 20 75 73 65 64 20 2a 2f 0a 23 64 65 66 not used */.#def
18450 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e ine WHERE_DISTIN
18460 43 54 5f 55 4e 49 51 55 45 20 20 20 20 31 20 20 CT_UNIQUE 1
18470 2f 2a 20 4e 6f 20 64 75 70 6c 69 63 61 74 65 73 /* No duplicates
18480 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
18490 45 5f 44 49 53 54 49 4e 43 54 5f 4f 52 44 45 52 E_DISTINCT_ORDER
184a0 45 44 20 20 20 32 20 20 2f 2a 20 41 6c 6c 20 64 ED 2 /* All d
184b0 75 70 6c 69 63 61 74 65 73 20 61 72 65 20 61 64 uplicates are ad
184c0 6a 61 63 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e jacent */.#defin
184d0 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 e WHERE_DISTINCT
184e0 5f 55 4e 4f 52 44 45 52 45 44 20 33 20 20 2f 2a _UNORDERED 3 /*
184f0 20 44 75 70 6c 69 63 61 74 65 73 20 61 72 65 20 Duplicates are
18500 73 63 61 74 74 65 72 65 64 20 2a 2f 0a 0a 2f 2a scattered */../*
18510 0a 2a 2a 20 41 20 4e 61 6d 65 43 6f 6e 74 65 78 .** A NameContex
18520 74 20 64 65 66 69 6e 65 73 20 61 20 63 6f 6e 74 t defines a cont
18530 65 78 74 20 69 6e 20 77 68 69 63 68 20 74 6f 20 ext in which to
18540 72 65 73 6f 6c 76 65 20 74 61 62 6c 65 20 61 6e resolve table an
18550 64 20 63 6f 6c 75 6d 6e 0a 2a 2a 20 6e 61 6d 65 d column.** name
18560 73 2e 20 20 54 68 65 20 63 6f 6e 74 65 78 74 20 s. The context
18570 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 20 6c 69 consists of a li
18580 73 74 20 6f 66 20 74 61 62 6c 65 73 20 28 74 68 st of tables (th
18590 65 20 70 53 72 63 4c 69 73 74 29 20 66 69 65 6c e pSrcList) fiel
185a0 64 20 61 6e 64 0a 2a 2a 20 61 20 6c 69 73 74 20 d and.** a list
185b0 6f 66 20 6e 61 6d 65 64 20 65 78 70 72 65 73 73 of named express
185c0 69 6f 6e 20 28 70 45 4c 69 73 74 29 2e 20 20 54 ion (pEList). T
185d0 68 65 20 6e 61 6d 65 64 20 65 78 70 72 65 73 73 he named express
185e0 69 6f 6e 20 6c 69 73 74 20 6d 61 79 0a 2a 2a 20 ion list may.**
185f0 62 65 20 4e 55 4c 4c 2e 20 20 54 68 65 20 70 53 be NULL. The pS
18600 72 63 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 rc corresponds t
18610 6f 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 o the FROM claus
18620 65 20 6f 66 20 61 20 53 45 4c 45 43 54 20 6f 72 e of a SELECT or
18630 0a 2a 2a 20 74 6f 20 74 68 65 20 74 61 62 6c 65 .** to the table
18640 20 62 65 69 6e 67 20 6f 70 65 72 61 74 65 64 20 being operated
18650 6f 6e 20 62 79 20 49 4e 53 45 52 54 2c 20 55 50 on by INSERT, UP
18660 44 41 54 45 2c 20 6f 72 20 44 45 4c 45 54 45 2e DATE, or DELETE.
18670 20 20 54 68 65 0a 2a 2a 20 70 45 4c 69 73 74 20 The.** pEList
18680 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 corresponds to t
18690 68 65 20 72 65 73 75 6c 74 20 73 65 74 20 6f 66 he result set of
186a0 20 61 20 53 45 4c 45 43 54 20 61 6e 64 20 69 73 a SELECT and is
186b0 20 4e 55 4c 4c 20 66 6f 72 0a 2a 2a 20 6f 74 68 NULL for.** oth
186c0 65 72 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 2a er statements..*
186d0 2a 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 *.** NameContext
186e0 73 20 63 61 6e 20 62 65 20 6e 65 73 74 65 64 2e s can be nested.
186f0 20 20 57 68 65 6e 20 72 65 73 6f 6c 76 69 6e 67 When resolving
18700 20 6e 61 6d 65 73 2c 20 74 68 65 20 69 6e 6e 65 names, the inne
18710 72 2d 6d 6f 73 74 20 0a 2a 2a 20 63 6f 6e 74 65 r-most .** conte
18720 78 74 20 69 73 20 73 65 61 72 63 68 65 64 20 66 xt is searched f
18730 69 72 73 74 2e 20 20 49 66 20 6e 6f 20 6d 61 74 irst. If no mat
18740 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 68 65 ch is found, the
18750 20 6e 65 78 74 20 6f 75 74 65 72 0a 2a 2a 20 63 next outer.** c
18760 6f 6e 74 65 78 74 20 69 73 20 63 68 65 63 6b 65 ontext is checke
18770 64 2e 20 20 49 66 20 74 68 65 72 65 20 69 73 20 d. If there is
18780 73 74 69 6c 6c 20 6e 6f 20 6d 61 74 63 68 2c 20 still no match,
18790 74 68 65 20 6e 65 78 74 20 63 6f 6e 74 65 78 74 the next context
187a0 0a 2a 2a 20 69 73 20 63 68 65 63 6b 65 64 2e 20 .** is checked.
187b0 20 54 68 69 73 20 70 72 6f 63 65 73 73 20 63 6f This process co
187c0 6e 74 69 6e 75 65 73 20 75 6e 74 69 6c 20 65 69 ntinues until ei
187d0 74 68 65 72 20 61 20 6d 61 74 63 68 20 69 73 20 ther a match is
187e0 66 6f 75 6e 64 0a 2a 2a 20 6f 72 20 61 6c 6c 20 found.** or all
187f0 63 6f 6e 74 65 78 74 73 20 61 72 65 20 63 68 65 contexts are che
18800 63 6b 2e 20 20 57 68 65 6e 20 61 20 6d 61 74 63 ck. When a matc
18810 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 68 65 20 h is found, the
18820 6e 52 65 66 20 6d 65 6d 62 65 72 20 6f 66 0a 2a nRef member of.*
18830 2a 20 74 68 65 20 63 6f 6e 74 65 78 74 20 63 6f * the context co
18840 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 6d 61 74 ntaining the mat
18850 63 68 20 69 73 20 69 6e 63 72 65 6d 65 6e 74 65 ch is incremente
18860 64 2e 20 0a 2a 2a 0a 2a 2a 20 45 61 63 68 20 73 d. .**.** Each s
18870 75 62 71 75 65 72 79 20 67 65 74 73 20 61 20 6e ubquery gets a n
18880 65 77 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2e 20 ew NameContext.
18890 20 54 68 65 20 70 4e 65 78 74 20 66 69 65 6c 64 The pNext field
188a0 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 0a 2a points to the.*
188b0 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 69 6e * NameContext in
188c0 20 74 68 65 20 70 61 72 65 6e 74 20 71 75 65 72 the parent quer
188d0 79 2e 20 20 54 68 75 73 20 74 68 65 20 70 72 6f y. Thus the pro
188e0 63 65 73 73 20 6f 66 20 73 63 61 6e 6e 69 6e 67 cess of scanning
188f0 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 the.** NameCont
18900 65 78 74 20 6c 69 73 74 20 63 6f 72 72 65 73 70 ext list corresp
18910 6f 6e 64 73 20 74 6f 20 73 65 61 72 63 68 69 6e onds to searchin
18920 67 20 74 68 72 6f 75 67 68 20 73 75 63 63 65 73 g through succes
18930 73 69 76 65 6c 79 20 6f 75 74 65 72 0a 2a 2a 20 sively outer.**
18940 73 75 62 71 75 65 72 69 65 73 20 6c 6f 6f 6b 69 subqueries looki
18950 6e 67 20 66 6f 72 20 61 20 6d 61 74 63 68 2e 0a ng for a match..
18960 2a 2f 0a 73 74 72 75 63 74 20 4e 61 6d 65 43 6f */.struct NameCo
18970 6e 74 65 78 74 20 7b 0a 20 20 50 61 72 73 65 20 ntext {. Parse
18980 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 2f *pParse; /
18990 2a 20 54 68 65 20 70 61 72 73 65 72 20 2a 2f 0a * The parser */.
189a0 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 4c SrcList *pSrcL
189b0 69 73 74 3b 20 20 20 2f 2a 20 4f 6e 65 20 6f 72 ist; /* One or
189c0 20 6d 6f 72 65 20 74 61 62 6c 65 73 20 75 73 65 more tables use
189d0 64 20 74 6f 20 72 65 73 6f 6c 76 65 20 6e 61 6d d to resolve nam
189e0 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 es */. ExprList
189f0 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 2f 2a 20 *pEList; /*
18a00 4f 70 74 69 6f 6e 61 6c 20 6c 69 73 74 20 6f 66 Optional list of
18a10 20 72 65 73 75 6c 74 2d 73 65 74 20 63 6f 6c 75 result-set colu
18a20 6d 6e 73 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f mns */. AggInfo
18a30 20 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 2f 2a *pAggInfo; /*
18a40 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f Information abo
18a50 75 74 20 61 67 67 72 65 67 61 74 65 73 20 61 74 ut aggregates at
18a60 20 74 68 69 73 20 6c 65 76 65 6c 20 2a 2f 0a 20 this level */.
18a70 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 2a 70 4e NameContext *pN
18a80 65 78 74 3b 20 20 2f 2a 20 4e 65 78 74 20 6f 75 ext; /* Next ou
18a90 74 65 72 20 6e 61 6d 65 20 63 6f 6e 74 65 78 74 ter name context
18aa0 2e 20 20 4e 55 4c 4c 20 66 6f 72 20 6f 75 74 65 . NULL for oute
18ab0 72 6d 6f 73 74 20 2a 2f 0a 20 20 69 6e 74 20 6e rmost */. int n
18ac0 52 65 66 3b 20 20 20 20 20 20 20 20 20 20 20 20 Ref;
18ad0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 61 6d /* Number of nam
18ae0 65 73 20 72 65 73 6f 6c 76 65 64 20 62 79 20 74 es resolved by t
18af0 68 69 73 20 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 his context */.
18b00 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 20 20 20 int nErr;
18b10 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
18b20 6f 66 20 65 72 72 6f 72 73 20 65 6e 63 6f 75 6e of errors encoun
18b30 74 65 72 65 64 20 77 68 69 6c 65 20 72 65 73 6f tered while reso
18b40 6c 76 69 6e 67 20 6e 61 6d 65 73 20 2a 2f 0a 20 lving names */.
18b50 20 75 31 36 20 6e 63 46 6c 61 67 73 3b 20 20 20 u16 ncFlags;
18b60 20 20 20 20 20 20 2f 2a 20 5a 65 72 6f 20 6f 72 /* Zero or
18b70 20 6d 6f 72 65 20 4e 43 5f 2a 20 66 6c 61 67 73 more NC_* flags
18b80 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 20 2a defined below *
18b90 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f /.};../*.** Allo
18ba0 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 74 wed values for t
18bb0 68 65 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2c 20 he NameContext,
18bc0 6e 63 46 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a ncFlags field..*
18bd0 2a 0a 2a 2a 20 4e 6f 74 65 3a 20 20 4e 43 5f 4d *.** Note: NC_M
18be0 69 6e 4d 61 78 41 67 67 20 6d 75 73 74 20 68 61 inMaxAgg must ha
18bf0 76 65 20 74 68 65 20 73 61 6d 65 20 76 61 6c 75 ve the same valu
18c00 65 20 61 73 20 53 46 5f 4d 69 6e 4d 61 78 41 67 e as SF_MinMaxAg
18c10 67 20 61 6e 64 0a 2a 2a 20 53 51 4c 49 54 45 5f g and.** SQLITE_
18c20 46 55 4e 43 5f 4d 49 4e 4d 41 58 2e 0a 2a 2a 20 FUNC_MINMAX..**
18c30 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 41 .*/.#define NC_A
18c40 6c 6c 6f 77 41 67 67 20 20 30 78 30 30 30 31 20 llowAgg 0x0001
18c50 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 66 75 /* Aggregate fu
18c60 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 6c 6c 6f nctions are allo
18c70 77 65 64 20 68 65 72 65 20 2a 2f 0a 23 64 65 66 wed here */.#def
18c80 69 6e 65 20 4e 43 5f 48 61 73 41 67 67 20 20 20 ine NC_HasAgg
18c90 20 30 78 30 30 30 32 20 20 2f 2a 20 4f 6e 65 20 0x0002 /* One
18ca0 6f 72 20 6d 6f 72 65 20 61 67 67 72 65 67 61 74 or more aggregat
18cb0 65 20 66 75 6e 63 74 69 6f 6e 73 20 73 65 65 6e e functions seen
18cc0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 49 */.#define NC_I
18cd0 73 43 68 65 63 6b 20 20 20 30 78 30 30 30 34 20 sCheck 0x0004
18ce0 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 6f /* True if reso
18cf0 6c 76 69 6e 67 20 6e 61 6d 65 73 20 69 6e 20 61 lving names in a
18d00 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 61 69 6e CHECK constrain
18d10 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f t */.#define NC_
18d20 49 6e 41 67 67 46 75 6e 63 20 30 78 30 30 30 38 InAggFunc 0x0008
18d30 20 20 2f 2a 20 54 72 75 65 20 69 66 20 61 6e 61 /* True if ana
18d40 6c 79 7a 69 6e 67 20 61 72 67 75 6d 65 6e 74 73 lyzing arguments
18d50 20 74 6f 20 61 6e 20 61 67 67 20 66 75 6e 63 20 to an agg func
18d60 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 50 61 */.#define NC_Pa
18d70 72 74 49 64 78 20 20 20 30 78 30 30 31 30 20 20 rtIdx 0x0010
18d80 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 6f 6c /* True if resol
18d90 76 69 6e 67 20 61 20 70 61 72 74 69 61 6c 20 69 ving a partial i
18da0 6e 64 65 78 20 57 48 45 52 45 20 2a 2f 0a 23 64 ndex WHERE */.#d
18db0 65 66 69 6e 65 20 4e 43 5f 49 64 78 45 78 70 72 efine NC_IdxExpr
18dc0 20 20 20 30 78 30 30 32 30 20 20 2f 2a 20 54 72 0x0020 /* Tr
18dd0 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 ue if resolving
18de0 63 6f 6c 75 6d 6e 73 20 6f 66 20 43 52 45 41 54 columns of CREAT
18df0 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 69 E INDEX */.#defi
18e00 6e 65 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 ne NC_MinMaxAgg
18e10 30 78 31 30 30 30 20 20 2f 2a 20 6d 69 6e 2f 6d 0x1000 /* min/m
18e20 61 78 20 61 67 67 72 65 67 61 74 65 73 20 73 65 ax aggregates se
18e30 65 6e 2e 20 20 53 65 65 20 6e 6f 74 65 20 61 62 en. See note ab
18e40 6f 76 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e ove */../*.** An
18e50 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
18e60 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
18e70 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 61 6c ture contains al
18e80 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a l information.**
18e90 20 6e 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 needed to gener
18ea0 61 74 65 20 63 6f 64 65 20 66 6f 72 20 61 20 73 ate code for a s
18eb0 69 6e 67 6c 65 20 53 45 4c 45 43 54 20 73 74 61 ingle SELECT sta
18ec0 74 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 6e 4c tement..**.** nL
18ed0 69 6d 69 74 20 69 73 20 73 65 74 20 74 6f 20 2d imit is set to -
18ee0 31 20 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 1 if there is no
18ef0 20 4c 49 4d 49 54 20 63 6c 61 75 73 65 2e 20 20 LIMIT clause.
18f00 6e 4f 66 66 73 65 74 20 69 73 20 73 65 74 20 74 nOffset is set t
18f10 6f 20 30 2e 0a 2a 2a 20 49 66 20 74 68 65 72 65 o 0..** If there
18f20 20 69 73 20 61 20 4c 49 4d 49 54 20 63 6c 61 75 is a LIMIT clau
18f30 73 65 2c 20 74 68 65 20 70 61 72 73 65 72 20 73 se, the parser s
18f40 65 74 73 20 6e 4c 69 6d 69 74 20 74 6f 20 74 68 ets nLimit to th
18f50 65 20 76 61 6c 75 65 20 6f 66 20 74 68 65 0a 2a e value of the.*
18f60 2a 20 6c 69 6d 69 74 20 61 6e 64 20 6e 4f 66 66 * limit and nOff
18f70 73 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 set to the value
18f80 20 6f 66 20 74 68 65 20 6f 66 66 73 65 74 20 28 of the offset (
18f90 6f 72 20 30 20 69 66 20 74 68 65 72 65 20 69 73 or 0 if there is
18fa0 20 6e 6f 74 0a 2a 2a 20 6f 66 66 73 65 74 29 2e not.** offset).
18fb0 20 20 42 75 74 20 6c 61 74 65 72 20 6f 6e 2c 20 But later on,
18fc0 6e 4c 69 6d 69 74 20 61 6e 64 20 6e 4f 66 66 73 nLimit and nOffs
18fd0 65 74 20 62 65 63 6f 6d 65 20 74 68 65 20 6d 65 et become the me
18fe0 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 73 0a 2a mory locations.*
18ff0 2a 20 69 6e 20 74 68 65 20 56 44 42 45 20 74 68 * in the VDBE th
19000 61 74 20 72 65 63 6f 72 64 20 74 68 65 20 6c 69 at record the li
19010 6d 69 74 20 61 6e 64 20 6f 66 66 73 65 74 20 63 mit and offset c
19020 6f 75 6e 74 65 72 73 2e 0a 2a 2a 0a 2a 2a 20 61 ounters..**.** a
19030 64 64 72 4f 70 65 6e 45 70 68 6d 5b 5d 20 65 6e ddrOpenEphm[] en
19040 74 72 69 65 73 20 63 6f 6e 74 61 69 6e 20 74 68 tries contain th
19050 65 20 61 64 64 72 65 73 73 20 6f 66 20 4f 50 5f e address of OP_
19060 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f 70 OpenEphemeral op
19070 63 6f 64 65 73 2e 0a 2a 2a 20 54 68 65 73 65 20 codes..** These
19080 61 64 64 72 65 73 73 65 73 20 6d 75 73 74 20 62 addresses must b
19090 65 20 73 74 6f 72 65 64 20 73 6f 20 74 68 61 74 e stored so that
190a0 20 77 65 20 63 61 6e 20 67 6f 20 62 61 63 6b 20 we can go back
190b0 61 6e 64 20 66 69 6c 6c 20 69 6e 0a 2a 2a 20 74 and fill in.** t
190c0 68 65 20 50 34 5f 4b 45 59 49 4e 46 4f 20 61 6e he P4_KEYINFO an
190d0 64 20 50 32 20 70 61 72 61 6d 65 74 65 72 73 20 d P2 parameters
190e0 6c 61 74 65 72 2e 20 20 4e 65 69 74 68 65 72 20 later. Neither
190f0 74 68 65 20 4b 65 79 49 6e 66 6f 20 6e 6f 72 0a the KeyInfo nor.
19100 2a 2a 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ** the number of
19110 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 50 32 20 63 columns in P2 c
19120 61 6e 20 62 65 20 63 6f 6d 70 75 74 65 64 20 61 an be computed a
19130 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 0a t the same time.
19140 2a 2a 20 61 73 20 74 68 65 20 4f 50 5f 4f 70 65 ** as the OP_Ope
19150 6e 45 70 68 6d 20 69 6e 73 74 72 75 63 74 69 6f nEphm instructio
19160 6e 20 69 73 20 63 6f 64 65 64 20 62 65 63 61 75 n is coded becau
19170 73 65 20 6e 6f 74 0a 2a 2a 20 65 6e 6f 75 67 68 se not.** enough
19180 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f information abo
19190 75 74 20 74 68 65 20 63 6f 6d 70 6f 75 6e 64 20 ut the compound
191a0 71 75 65 72 79 20 69 73 20 6b 6e 6f 77 6e 20 61 query is known a
191b0 74 20 74 68 61 74 20 70 6f 69 6e 74 2e 0a 2a 2a t that point..**
191c0 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 6f 72 The KeyInfo for
191d0 20 61 64 64 72 4f 70 65 6e 54 72 61 6e 5b 30 5d addrOpenTran[0]
191e0 20 61 6e 64 20 5b 31 5d 20 63 6f 6e 74 61 69 6e and [1] contain
191f0 73 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 s collating sequ
19200 65 6e 63 65 73 0a 2a 2a 20 66 6f 72 20 74 68 65 ences.** for the
19210 20 72 65 73 75 6c 74 20 73 65 74 2e 20 20 54 68 result set. Th
19220 65 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 61 64 e KeyInfo for ad
19230 64 72 4f 70 65 6e 45 70 68 6d 5b 32 5d 20 63 6f drOpenEphm[2] co
19240 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 ntains collating
19250 0a 2a 2a 20 73 65 71 75 65 6e 63 65 73 20 66 6f .** sequences fo
19260 72 20 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 r the ORDER BY c
19270 6c 61 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 lause..*/.struct
19280 20 53 65 6c 65 63 74 20 7b 0a 20 20 45 78 70 72 Select {. Expr
19290 4c 69 73 74 20 2a 70 45 4c 69 73 74 3b 20 20 20 List *pEList;
192a0 20 20 20 2f 2a 20 54 68 65 20 66 69 65 6c 64 73 /* The fields
192b0 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 2a of the result *
192c0 2f 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 /. u8 op;
192d0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e /* On
192e0 65 20 6f 66 3a 20 54 4b 5f 55 4e 49 4f 4e 20 54 e of: TK_UNION T
192f0 4b 5f 41 4c 4c 20 54 4b 5f 49 4e 54 45 52 53 45 K_ALL TK_INTERSE
19300 43 54 20 54 4b 5f 45 58 43 45 50 54 20 2a 2f 0a CT TK_EXCEPT */.
19310 20 20 75 31 36 20 73 65 6c 46 6c 61 67 73 3b 20 u16 selFlags;
19320 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 72 69 /* Vari
19330 6f 75 73 20 53 46 5f 2a 20 76 61 6c 75 65 73 20 ous SF_* values
19340 2a 2f 0a 20 20 69 6e 74 20 69 4c 69 6d 69 74 2c */. int iLimit,
19350 20 69 4f 66 66 73 65 74 3b 20 20 20 2f 2a 20 4d iOffset; /* M
19360 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 73 20 emory registers
19370 68 6f 6c 64 69 6e 67 20 4c 49 4d 49 54 20 26 20 holding LIMIT &
19380 4f 46 46 53 45 54 20 63 6f 75 6e 74 65 72 73 20 OFFSET counters
19390 2a 2f 0a 23 69 66 20 53 45 4c 45 43 54 54 52 41 */.#if SELECTTRA
193a0 43 45 5f 45 4e 41 42 4c 45 44 0a 20 20 63 68 61 CE_ENABLED. cha
193b0 72 20 7a 53 65 6c 4e 61 6d 65 5b 31 32 5d 3b 20 r zSelName[12];
193c0 20 20 20 20 2f 2a 20 53 79 6d 62 6f 6c 69 63 20 /* Symbolic
193d0 6e 61 6d 65 20 6f 66 20 74 68 69 73 20 53 45 4c name of this SEL
193e0 45 43 54 20 75 73 65 20 66 6f 72 20 64 65 62 75 ECT use for debu
193f0 67 67 69 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 0a gging */.#endif.
19400 20 20 69 6e 74 20 61 64 64 72 4f 70 65 6e 45 70 int addrOpenEp
19410 68 6d 5b 32 5d 3b 20 20 20 2f 2a 20 4f 50 5f 4f hm[2]; /* OP_O
19420 70 65 6e 45 70 68 65 6d 20 6f 70 63 6f 64 65 73 penEphem opcodes
19430 20 72 65 6c 61 74 65 64 20 74 6f 20 74 68 69 73 related to this
19440 20 73 65 6c 65 63 74 20 2a 2f 0a 20 20 75 36 34 select */. u64
19450 20 6e 53 65 6c 65 63 74 52 6f 77 3b 20 20 20 20 nSelectRow;
19460 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 /* Estimated
19470 20 6e 75 6d 62 65 72 20 6f 66 20 72 65 73 75 6c number of resul
19480 74 20 72 6f 77 73 20 2a 2f 0a 20 20 53 72 63 4c t rows */. SrcL
19490 69 73 74 20 2a 70 53 72 63 3b 20 20 20 20 20 20 ist *pSrc;
194a0 20 20 20 2f 2a 20 54 68 65 20 46 52 4f 4d 20 63 /* The FROM c
194b0 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 20 lause */. Expr
194c0 2a 70 57 68 65 72 65 3b 20 20 20 20 20 20 20 20 *pWhere;
194d0 20 20 2f 2a 20 54 68 65 20 57 48 45 52 45 20 63 /* The WHERE c
194e0 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 4c lause */. ExprL
194f0 69 73 74 20 2a 70 47 72 6f 75 70 42 79 3b 20 20 ist *pGroupBy;
19500 20 20 2f 2a 20 54 68 65 20 47 52 4f 55 50 20 42 /* The GROUP B
19510 59 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 Y clause */. Ex
19520 70 72 20 2a 70 48 61 76 69 6e 67 3b 20 20 20 20 pr *pHaving;
19530 20 20 20 20 20 2f 2a 20 54 68 65 20 48 41 56 49 /* The HAVI
19540 4e 47 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 NG clause */. E
19550 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 42 xprList *pOrderB
19560 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 4f 52 44 y; /* The ORD
19570 45 52 20 42 59 20 63 6c 61 75 73 65 20 2a 2f 0a ER BY clause */.
19580 20 20 53 65 6c 65 63 74 20 2a 70 50 72 69 6f 72 Select *pPrior
19590 3b 20 20 20 20 20 20 20 20 2f 2a 20 50 72 69 6f ; /* Prio
195a0 72 20 73 65 6c 65 63 74 20 69 6e 20 61 20 63 6f r select in a co
195b0 6d 70 6f 75 6e 64 20 73 65 6c 65 63 74 20 73 74 mpound select st
195c0 61 74 65 6d 65 6e 74 20 2a 2f 0a 20 20 53 65 6c atement */. Sel
195d0 65 63 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 ect *pNext;
195e0 20 20 20 20 2f 2a 20 4e 65 78 74 20 73 65 6c 65 /* Next sele
195f0 63 74 20 74 6f 20 74 68 65 20 6c 65 66 74 20 69 ct to the left i
19600 6e 20 61 20 63 6f 6d 70 6f 75 6e 64 20 2a 2f 0a n a compound */.
19610 20 20 45 78 70 72 20 2a 70 4c 69 6d 69 74 3b 20 Expr *pLimit;
19620 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 49 4d 49 /* LIMI
19630 54 20 65 78 70 72 65 73 73 69 6f 6e 2e 20 4e 55 T expression. NU
19640 4c 4c 20 6d 65 61 6e 73 20 6e 6f 74 20 75 73 65 LL means not use
19650 64 2e 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4f d. */. Expr *pO
19660 66 66 73 65 74 3b 20 20 20 20 20 20 20 20 20 2f ffset; /
19670 2a 20 4f 46 46 53 45 54 20 65 78 70 72 65 73 73 * OFFSET express
19680 69 6f 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 ion. NULL means
19690 6e 6f 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 57 not used. */. W
196a0 69 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 20 ith *pWith;
196b0 20 20 20 20 20 20 2f 2a 20 57 49 54 48 20 63 6c /* WITH cl
196c0 61 75 73 65 20 61 74 74 61 63 68 65 64 20 74 6f ause attached to
196d0 20 74 68 69 73 20 73 65 6c 65 63 74 2e 20 4f 72 this select. Or
196e0 20 4e 55 4c 4c 2e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a NULL. */.};../*
196f0 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 .** Allowed valu
19700 65 73 20 66 6f 72 20 53 65 6c 65 63 74 2e 73 65 es for Select.se
19710 6c 46 6c 61 67 73 2e 20 20 54 68 65 20 22 53 46 lFlags. The "SF
19720 22 20 70 72 65 66 69 78 20 73 74 61 6e 64 73 20 " prefix stands
19730 66 6f 72 0a 2a 2a 20 22 53 65 6c 65 63 74 20 46 for.** "Select F
19740 6c 61 67 22 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 lag"..*/.#define
19750 20 53 46 5f 44 69 73 74 69 6e 63 74 20 20 20 20 SF_Distinct
19760 20 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 4f 0x0001 /* O
19770 75 74 70 75 74 20 73 68 6f 75 6c 64 20 62 65 20 utput should be
19780 44 49 53 54 49 4e 43 54 20 2a 2f 0a 23 64 65 66 DISTINCT */.#def
19790 69 6e 65 20 53 46 5f 41 6c 6c 20 20 20 20 20 20 ine SF_All
197a0 20 20 20 20 20 20 20 30 78 30 30 30 32 20 20 2f 0x0002 /
197b0 2a 20 49 6e 63 6c 75 64 65 73 20 74 68 65 20 41 * Includes the A
197c0 4c 4c 20 6b 65 79 77 6f 72 64 20 2a 2f 0a 23 64 LL keyword */.#d
197d0 65 66 69 6e 65 20 53 46 5f 52 65 73 6f 6c 76 65 efine SF_Resolve
197e0 64 20 20 20 20 20 20 20 20 30 78 30 30 30 34 20 d 0x0004
197f0 20 2f 2a 20 49 64 65 6e 74 69 66 69 65 72 73 20 /* Identifiers
19800 68 61 76 65 20 62 65 65 6e 20 72 65 73 6f 6c 76 have been resolv
19810 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 ed */.#define SF
19820 5f 41 67 67 72 65 67 61 74 65 20 20 20 20 20 20 _Aggregate
19830 20 30 78 30 30 30 38 20 20 2f 2a 20 43 6f 6e 74 0x0008 /* Cont
19840 61 69 6e 73 20 61 67 67 72 65 67 61 74 65 20 66 ains aggregate f
19850 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 unctions */.#def
19860 69 6e 65 20 53 46 5f 55 73 65 73 45 70 68 65 6d ine SF_UsesEphem
19870 65 72 61 6c 20 20 20 30 78 30 30 31 30 20 20 2f eral 0x0010 /
19880 2a 20 55 73 65 73 20 74 68 65 20 4f 70 65 6e 45 * Uses the OpenE
19890 70 68 65 6d 65 72 61 6c 20 6f 70 63 6f 64 65 20 phemeral opcode
198a0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 45 78 */.#define SF_Ex
198b0 70 61 6e 64 65 64 20 20 20 20 20 20 20 20 30 78 panded 0x
198c0 30 30 32 30 20 20 2f 2a 20 73 71 6c 69 74 65 33 0020 /* sqlite3
198d0 53 65 6c 65 63 74 45 78 70 61 6e 64 28 29 20 63 SelectExpand() c
198e0 61 6c 6c 65 64 20 6f 6e 20 74 68 69 73 20 2a 2f alled on this */
198f0 0a 23 64 65 66 69 6e 65 20 53 46 5f 48 61 73 54 .#define SF_HasT
19900 79 70 65 49 6e 66 6f 20 20 20 20 20 30 78 30 30 ypeInfo 0x00
19910 34 30 20 20 2f 2a 20 46 52 4f 4d 20 73 75 62 71 40 /* FROM subq
19920 75 65 72 69 65 73 20 68 61 76 65 20 54 61 62 6c ueries have Tabl
19930 65 20 6d 65 74 61 64 61 74 61 20 2a 2f 0a 23 64 e metadata */.#d
19940 65 66 69 6e 65 20 53 46 5f 43 6f 6d 70 6f 75 6e efine SF_Compoun
19950 64 20 20 20 20 20 20 20 20 30 78 30 30 38 30 20 d 0x0080
19960 20 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 63 6f /* Part of a co
19970 6d 70 6f 75 6e 64 20 71 75 65 72 79 20 2a 2f 0a mpound query */.
19980 23 64 65 66 69 6e 65 20 53 46 5f 56 61 6c 75 65 #define SF_Value
19990 73 20 20 20 20 20 20 20 20 20 20 30 78 30 31 30 s 0x010
199a0 30 20 20 2f 2a 20 53 79 6e 74 68 65 73 69 7a 65 0 /* Synthesize
199b0 64 20 66 72 6f 6d 20 56 41 4c 55 45 53 20 63 6c d from VALUES cl
199c0 61 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ause */.#define
199d0 53 46 5f 4d 75 6c 74 69 56 61 6c 75 65 20 20 20 SF_MultiValue
199e0 20 20 20 30 78 30 32 30 30 20 20 2f 2a 20 53 69 0x0200 /* Si
199f0 6e 67 6c 65 20 56 41 4c 55 45 53 20 74 65 72 6d ngle VALUES term
19a00 20 77 69 74 68 20 6d 75 6c 74 69 70 6c 65 20 72 with multiple r
19a10 6f 77 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ows */.#define S
19a20 46 5f 4e 65 73 74 65 64 46 72 6f 6d 20 20 20 20 F_NestedFrom
19a30 20 20 30 78 30 34 30 30 20 20 2f 2a 20 50 61 72 0x0400 /* Par
19a40 74 20 6f 66 20 61 20 70 61 72 65 6e 74 68 65 73 t of a parenthes
19a50 69 7a 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 ized FROM clause
19a60 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d */.#define SF_M
19a70 61 79 62 65 43 6f 6e 76 65 72 74 20 20 20 20 30 aybeConvert 0
19a80 78 30 38 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 x0800 /* Need c
19a90 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 onvertCompoundSe
19aa0 6c 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 lectToSubquery()
19ab0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d */.#define SF_M
19ac0 69 6e 4d 61 78 41 67 67 20 20 20 20 20 20 20 30 inMaxAgg 0
19ad0 78 31 30 30 30 20 20 2f 2a 20 41 67 67 72 65 67 x1000 /* Aggreg
19ae0 61 74 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 6d ate containing m
19af0 69 6e 28 29 20 6f 72 20 6d 61 78 28 29 20 2a 2f in() or max() */
19b00 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 65 63 75 .#define SF_Recu
19b10 72 73 69 76 65 20 20 20 20 20 20 20 30 78 32 30 rsive 0x20
19b20 30 30 20 20 2f 2a 20 54 68 65 20 72 65 63 75 72 00 /* The recur
19b30 73 69 76 65 20 70 61 72 74 20 6f 66 20 61 20 72 sive part of a r
19b40 65 63 75 72 73 69 76 65 20 43 54 45 20 2a 2f 0a ecursive CTE */.
19b50 23 64 65 66 69 6e 65 20 53 46 5f 43 6f 6e 76 65 #define SF_Conve
19b60 72 74 65 64 20 20 20 20 20 20 20 30 78 34 30 30 rted 0x400
19b70 30 20 20 2f 2a 20 42 79 20 63 6f 6e 76 65 72 74 0 /* By convert
19b80 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 74 54 6f CompoundSelectTo
19b90 53 75 62 71 75 65 72 79 28 29 20 2a 2f 0a 0a 0a Subquery() */...
19ba0 2f 2a 0a 2a 2a 20 54 68 65 20 72 65 73 75 6c 74 /*.** The result
19bb0 73 20 6f 66 20 61 20 53 45 4c 45 43 54 20 63 61 s of a SELECT ca
19bc0 6e 20 62 65 20 64 69 73 74 72 69 62 75 74 65 64 n be distributed
19bd0 20 69 6e 20 73 65 76 65 72 61 6c 20 77 61 79 73 in several ways
19be0 2c 20 61 73 20 64 65 66 69 6e 65 64 0a 2a 2a 20 , as defined.**
19bf0 62 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 6f by one of the fo
19c00 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 2e 20 llowing macros.
19c10 20 54 68 65 20 22 53 52 54 22 20 70 72 65 66 69 The "SRT" prefi
19c20 78 20 6d 65 61 6e 73 20 22 53 45 4c 45 43 54 20 x means "SELECT
19c30 52 65 73 75 6c 74 0a 2a 2a 20 54 79 70 65 22 2e Result.** Type".
19c40 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 55 .**.** SRT_U
19c50 6e 69 6f 6e 20 20 20 20 20 20 20 53 74 6f 72 65 nion Store
19c60 20 72 65 73 75 6c 74 73 20 61 73 20 61 20 6b 65 results as a ke
19c70 79 20 69 6e 20 61 20 74 65 6d 70 6f 72 61 72 79 y in a temporary
19c80 20 69 6e 64 65 78 20 0a 2a 2a 20 20 20 20 20 20 index .**
19c90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
19ca0 64 65 6e 74 69 66 69 65 64 20 62 79 20 70 44 65 dentified by pDe
19cb0 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a st->iSDParm..**.
19cc0 2a 2a 20 20 20 20 20 53 52 54 5f 45 78 63 65 70 ** SRT_Excep
19cd0 74 20 20 20 20 20 20 52 65 6d 6f 76 65 20 72 65 t Remove re
19ce0 73 75 6c 74 73 20 66 72 6f 6d 20 74 68 65 20 74 sults from the t
19cf0 65 6d 70 6f 72 61 72 79 20 69 6e 64 65 78 20 70 emporary index p
19d00 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a Dest->iSDParm..*
19d10 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 45 78 69 *.** SRT_Exi
19d20 73 74 73 20 20 20 20 20 20 53 74 6f 72 65 20 61 sts Store a
19d30 20 31 20 69 6e 20 6d 65 6d 6f 72 79 20 63 65 6c 1 in memory cel
19d40 6c 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d l pDest->iSDParm
19d50 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 0a 2a if the result.*
19d60 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
19d70 20 20 20 20 20 20 73 65 74 20 69 73 20 6e 6f 74 set is not
19d80 20 65 6d 70 74 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 empty..**.**
19d90 20 20 53 52 54 5f 44 69 73 63 61 72 64 20 20 20 SRT_Discard
19da0 20 20 54 68 72 6f 77 20 74 68 65 20 72 65 73 75 Throw the resu
19db0 6c 74 73 20 61 77 61 79 2e 20 20 54 68 69 73 20 lts away. This
19dc0 69 73 20 75 73 65 64 20 62 79 20 53 45 4c 45 43 is used by SELEC
19dd0 54 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 T.**
19de0 20 20 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 stateme
19df0 6e 74 73 20 77 69 74 68 69 6e 20 74 72 69 67 67 nts within trigg
19e00 65 72 73 20 77 68 6f 73 65 20 6f 6e 6c 79 20 70 ers whose only p
19e10 75 72 70 6f 73 65 20 69 73 0a 2a 2a 20 20 20 20 urpose is.**
19e20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19e30 20 74 68 65 20 73 69 64 65 2d 65 66 66 65 63 74 the side-effect
19e40 73 20 6f 66 20 66 75 6e 63 74 69 6f 6e 73 2e 0a s of functions..
19e50 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 65 **.** All of the
19e60 20 61 62 6f 76 65 20 61 72 65 20 66 72 65 65 20 above are free
19e70 74 6f 20 69 67 6e 6f 72 65 20 74 68 65 69 72 20 to ignore their
19e80 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e ORDER BY clause.
19e90 20 54 68 6f 73 65 20 74 68 61 74 0a 2a 2a 20 66 Those that.** f
19ea0 6f 6c 6c 6f 77 20 6d 75 73 74 20 68 6f 6e 6f 72 ollow must honor
19eb0 20 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c the ORDER BY cl
19ec0 61 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ause..**.**
19ed0 53 52 54 5f 4f 75 74 70 75 74 20 20 20 20 20 20 SRT_Output
19ee0 47 65 6e 65 72 61 74 65 20 61 20 72 6f 77 20 6f Generate a row o
19ef0 66 20 6f 75 74 70 75 74 20 28 75 73 69 6e 67 20 f output (using
19f00 74 68 65 20 4f 50 5f 52 65 73 75 6c 74 52 6f 77 the OP_ResultRow
19f10 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
19f20 20 20 20 20 20 20 20 20 6f 70 63 6f 64 65 29 20 opcode)
19f30 66 6f 72 20 65 61 63 68 20 72 6f 77 20 69 6e 20 for each row in
19f40 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 2e 0a the result set..
19f50 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4d 65 **.** SRT_Me
19f60 6d 20 20 20 20 20 20 20 20 20 4f 6e 6c 79 20 76 m Only v
19f70 61 6c 69 64 20 69 66 20 74 68 65 20 72 65 73 75 alid if the resu
19f80 6c 74 20 69 73 20 61 20 73 69 6e 67 6c 65 20 63 lt is a single c
19f90 6f 6c 75 6d 6e 2e 0a 2a 2a 20 20 20 20 20 20 20 olumn..**
19fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 74 St
19fb0 6f 72 65 20 74 68 65 20 66 69 72 73 74 20 63 6f ore the first co
19fc0 6c 75 6d 6e 20 6f 66 20 74 68 65 20 66 69 72 73 lumn of the firs
19fd0 74 20 72 65 73 75 6c 74 20 72 6f 77 0a 2a 2a 20 t result row.**
19fe0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19ff0 20 20 20 20 69 6e 20 72 65 67 69 73 74 65 72 20 in register
1a000 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 74 pDest->iSDParm t
1a010 68 65 6e 20 61 62 61 6e 64 6f 6e 20 74 68 65 20 hen abandon the
1a020 72 65 73 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 rest.**
1a030 20 20 20 20 20 20 20 20 20 20 20 20 6f 66 20 74 of t
1a040 68 65 20 71 75 65 72 79 2e 20 20 54 68 69 73 20 he query. This
1a050 64 65 73 74 69 6e 61 74 69 6f 6e 20 69 6d 70 6c destination impl
1a060 69 65 73 20 22 4c 49 4d 49 54 20 31 22 2e 0a 2a ies "LIMIT 1"..*
1a070 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 53 65 74 *.** SRT_Set
1a080 20 20 20 20 20 20 20 20 20 54 68 65 20 72 65 73 The res
1a090 75 6c 74 20 6d 75 73 74 20 62 65 20 61 20 73 69 ult must be a si
1a0a0 6e 67 6c 65 20 63 6f 6c 75 6d 6e 2e 20 20 53 74 ngle column. St
1a0b0 6f 72 65 20 65 61 63 68 0a 2a 2a 20 20 20 20 20 ore each.**
1a0c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a0d0 72 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 61 73 row of result as
1a0e0 20 74 68 65 20 6b 65 79 20 69 6e 20 74 61 62 6c the key in tabl
1a0f0 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
1a100 2e 20 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 . .**
1a110 20 20 20 20 20 20 20 20 20 20 41 70 70 6c 79 20 Apply
1a120 74 68 65 20 61 66 66 69 6e 69 74 79 20 70 44 65 the affinity pDe
1a130 73 74 2d 3e 61 66 66 53 64 73 74 20 62 65 66 6f st->affSdst befo
1a140 72 65 20 73 74 6f 72 69 6e 67 0a 2a 2a 20 20 20 re storing.**
1a150 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a160 20 20 72 65 73 75 6c 74 73 2e 20 20 55 73 65 64 results. Used
1a170 20 74 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 22 49 to implement "I
1a180 4e 20 28 53 45 4c 45 43 54 20 2e 2e 2e 29 22 2e N (SELECT ...)".
1a190 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 45 .**.** SRT_E
1a1a0 70 68 65 6d 54 61 62 20 20 20 20 43 72 65 61 74 phemTab Creat
1a1b0 65 20 61 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 e an temporary t
1a1c0 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 able pDest->iSDP
1a1d0 61 72 6d 20 61 6e 64 20 73 74 6f 72 65 0a 2a 2a arm and store.**
1a1e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a1f0 20 20 20 20 20 74 68 65 20 72 65 73 75 6c 74 20 the result
1a200 74 68 65 72 65 2e 20 54 68 65 20 63 75 72 73 6f there. The curso
1a210 72 20 69 73 20 6c 65 66 74 20 6f 70 65 6e 20 61 r is left open a
1a220 66 74 65 72 0a 2a 2a 20 20 20 20 20 20 20 20 20 fter.**
1a230 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
1a240 72 6e 69 6e 67 2e 20 20 54 68 69 73 20 69 73 20 rning. This is
1a250 6c 69 6b 65 20 53 52 54 5f 54 61 62 6c 65 20 65 like SRT_Table e
1a260 78 63 65 70 74 20 74 68 61 74 0a 2a 2a 20 20 20 xcept that.**
1a270 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a280 20 20 74 68 69 73 20 64 65 73 74 69 6e 61 74 69 this destinati
1a290 6f 6e 20 75 73 65 73 20 4f 50 5f 4f 70 65 6e 45 on uses OP_OpenE
1a2a0 70 68 65 6d 65 72 61 6c 20 74 6f 20 63 72 65 61 phemeral to crea
1a2b0 74 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 te.**
1a2c0 20 20 20 20 20 20 20 20 20 20 74 68 65 20 74 61 the ta
1a2d0 62 6c 65 20 66 69 72 73 74 2e 0a 2a 2a 0a 2a 2a ble first..**.**
1a2e0 20 20 20 20 20 53 52 54 5f 43 6f 72 6f 75 74 69 SRT_Corouti
1a2f0 6e 65 20 20 20 47 65 6e 65 72 61 74 65 20 61 20 ne Generate a
1a300 63 6f 2d 72 6f 75 74 69 6e 65 20 74 68 61 74 20 co-routine that
1a310 72 65 74 75 72 6e 73 20 61 20 6e 65 77 20 72 6f returns a new ro
1a320 77 20 6f 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 w of.**
1a330 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 resu
1a340 6c 74 73 20 65 61 63 68 20 74 69 6d 65 20 69 74 lts each time it
1a350 20 69 73 20 69 6e 76 6f 6b 65 64 2e 20 20 54 68 is invoked. Th
1a360 65 20 65 6e 74 72 79 20 70 6f 69 6e 74 0a 2a 2a e entry point.**
1a370 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a380 20 20 20 20 20 6f 66 20 74 68 65 20 63 6f 2d 72 of the co-r
1a390 6f 75 74 69 6e 65 20 69 73 20 73 74 6f 72 65 64 outine is stored
1a3a0 20 69 6e 20 72 65 67 69 73 74 65 72 20 70 44 65 in register pDe
1a3b0 73 74 2d 3e 69 53 44 50 61 72 6d 0a 2a 2a 20 20 st->iSDParm.**
1a3c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a3d0 20 20 20 61 6e 64 20 74 68 65 20 72 65 73 75 6c and the resul
1a3e0 74 20 72 6f 77 20 69 73 20 73 74 6f 72 65 64 20 t row is stored
1a3f0 69 6e 20 70 44 65 73 74 2d 3e 6e 44 65 73 74 20 in pDest->nDest
1a400 72 65 67 69 73 74 65 72 73 0a 2a 2a 20 20 20 20 registers.**
1a410 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a420 20 73 74 61 72 74 69 6e 67 20 77 69 74 68 20 70 starting with p
1a430 44 65 73 74 2d 3e 69 53 64 73 74 2e 0a 2a 2a 0a Dest->iSdst..**.
1a440 2a 2a 20 20 20 20 20 53 52 54 5f 54 61 62 6c 65 ** SRT_Table
1a450 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 73 Store res
1a460 75 6c 74 73 20 69 6e 20 74 65 6d 70 6f 72 61 72 ults in temporar
1a470 79 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 y table pDest->i
1a480 53 44 50 61 72 6d 2e 0a 2a 2a 20 20 20 20 20 53 SDParm..** S
1a490 52 54 5f 46 69 66 6f 20 20 20 20 20 20 20 20 54 RT_Fifo T
1a4a0 68 69 73 20 69 73 20 6c 69 6b 65 20 53 52 54 5f his is like SRT_
1a4b0 45 70 68 65 6d 54 61 62 20 65 78 63 65 70 74 20 EphemTab except
1a4c0 74 68 61 74 20 74 68 65 20 74 61 62 6c 65 0a 2a that the table.*
1a4d0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1a4e0 20 20 20 20 20 20 69 73 20 61 73 73 75 6d 65 64 is assumed
1a4f0 20 74 6f 20 61 6c 72 65 61 64 79 20 62 65 20 6f to already be o
1a500 70 65 6e 2e 20 20 53 52 54 5f 46 69 66 6f 20 68 pen. SRT_Fifo h
1a510 61 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 as.**
1a520 20 20 20 20 20 20 20 20 20 20 74 68 65 20 61 64 the ad
1a530 64 69 74 69 6f 6e 61 6c 20 70 72 6f 70 65 72 74 ditional propert
1a540 79 20 6f 66 20 62 65 69 6e 67 20 61 62 6c 65 20 y of being able
1a550 74 6f 20 69 67 6e 6f 72 65 0a 2a 2a 20 20 20 20 to ignore.**
1a560 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a570 20 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c the ORDER BY cl
1a580 61 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ause..**.**
1a590 53 52 54 5f 44 69 73 74 46 69 66 6f 20 20 20 20 SRT_DistFifo
1a5a0 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e Store results in
1a5b0 20 61 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 a temporary tab
1a5c0 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 le pDest->iSDPar
1a5d0 6d 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 m..**
1a5e0 20 20 20 20 20 20 20 20 20 20 42 75 74 20 61 6c But al
1a5f0 73 6f 20 75 73 65 20 74 65 6d 70 6f 72 61 72 79 so use temporary
1a600 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 table pDest->iS
1a610 44 50 61 72 6d 2b 31 20 61 73 0a 2a 2a 20 20 20 DParm+1 as.**
1a620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a630 20 20 61 20 72 65 63 6f 72 64 20 6f 66 20 61 6c a record of al
1a640 6c 20 70 72 69 6f 72 20 72 65 73 75 6c 74 73 20 l prior results
1a650 61 6e 64 20 69 67 6e 6f 72 65 20 61 6e 79 20 64 and ignore any d
1a660 75 70 6c 69 63 61 74 65 0a 2a 2a 20 20 20 20 20 uplicate.**
1a670 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a680 72 6f 77 73 2e 20 20 4e 61 6d 65 20 6d 65 61 6e rows. Name mean
1a690 73 3a 20 20 22 44 69 73 74 69 6e 63 74 20 46 69 s: "Distinct Fi
1a6a0 66 6f 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 fo"..**.** S
1a6b0 52 54 5f 51 75 65 75 65 20 20 20 20 20 20 20 53 RT_Queue S
1a6c0 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 tore results in
1a6d0 70 72 69 6f 72 69 74 79 20 71 75 65 75 65 20 70 priority queue p
1a6e0 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 28 72 Dest->iSDParm (r
1a6f0 65 61 6c 6c 79 0a 2a 2a 20 20 20 20 20 20 20 20 eally.**
1a700 20 20 20 20 20 20 20 20 20 20 20 20 20 61 6e 20 an
1a710 69 6e 64 65 78 29 2e 20 20 41 70 70 65 6e 64 20 index). Append
1a720 61 20 73 65 71 75 65 6e 63 65 20 6e 75 6d 62 65 a sequence numbe
1a730 72 20 73 6f 20 74 68 61 74 20 61 6c 6c 20 65 6e r so that all en
1a740 74 72 69 65 73 0a 2a 2a 20 20 20 20 20 20 20 20 tries.**
1a750 20 20 20 20 20 20 20 20 20 20 20 20 20 61 72 65 are
1a760 20 64 69 73 74 69 6e 63 74 2e 0a 2a 2a 0a 2a 2a distinct..**.**
1a770 20 20 20 20 20 53 52 54 5f 44 69 73 74 51 75 65 SRT_DistQue
1a780 75 65 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c ue Store resul
1a790 74 73 20 69 6e 20 70 72 69 6f 72 69 74 79 20 71 ts in priority q
1a7a0 75 65 75 65 20 70 44 65 73 74 2d 3e 69 53 44 50 ueue pDest->iSDP
1a7b0 61 72 6d 20 6f 6e 6c 79 20 69 66 0a 2a 2a 20 20 arm only if.**
1a7c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a7d0 20 20 20 74 68 65 20 73 61 6d 65 20 72 65 63 6f the same reco
1a7e0 72 64 20 68 61 73 20 6e 65 76 65 72 20 62 65 65 rd has never bee
1a7f0 6e 20 73 74 6f 72 65 64 20 62 65 66 6f 72 65 2e n stored before.
1a800 20 20 54 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 The.**
1a810 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 64 ind
1a820 65 78 20 61 74 20 70 44 65 73 74 2d 3e 69 53 44 ex at pDest->iSD
1a830 50 61 72 6d 2b 31 20 68 6f 6c 64 20 61 6c 6c 20 Parm+1 hold all
1a840 70 72 69 6f 72 20 73 74 6f 72 65 73 2e 0a 2a 2f prior stores..*/
1a850 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 55 6e 69 .#define SRT_Uni
1a860 6f 6e 20 20 20 20 20 20 20 20 31 20 20 2f 2a 20 on 1 /*
1a870 53 74 6f 72 65 20 72 65 73 75 6c 74 20 61 73 20 Store result as
1a880 6b 65 79 73 20 69 6e 20 61 6e 20 69 6e 64 65 78 keys in an index
1a890 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f */.#define SRT_
1a8a0 45 78 63 65 70 74 20 20 20 20 20 20 20 32 20 20 Except 2
1a8b0 2f 2a 20 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 /* Remove result
1a8c0 20 66 72 6f 6d 20 61 20 55 4e 49 4f 4e 20 69 6e from a UNION in
1a8d0 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 dex */.#define S
1a8e0 52 54 5f 45 78 69 73 74 73 20 20 20 20 20 20 20 RT_Exists
1a8f0 33 20 20 2f 2a 20 53 74 6f 72 65 20 31 20 69 66 3 /* Store 1 if
1a900 20 74 68 65 20 72 65 73 75 6c 74 20 69 73 20 6e the result is n
1a910 6f 74 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 ot empty */.#def
1a920 69 6e 65 20 53 52 54 5f 44 69 73 63 61 72 64 20 ine SRT_Discard
1a930 20 20 20 20 20 34 20 20 2f 2a 20 44 6f 20 6e 6f 4 /* Do no
1a940 74 20 73 61 76 65 20 74 68 65 20 72 65 73 75 6c t save the resul
1a950 74 73 20 61 6e 79 77 68 65 72 65 20 2a 2f 0a 23 ts anywhere */.#
1a960 64 65 66 69 6e 65 20 53 52 54 5f 46 69 66 6f 20 define SRT_Fifo
1a970 20 20 20 20 20 20 20 20 35 20 20 2f 2a 20 53 74 5 /* St
1a980 6f 72 65 20 72 65 73 75 6c 74 20 61 73 20 64 61 ore result as da
1a990 74 61 20 77 69 74 68 20 61 6e 20 61 75 74 6f 6d ta with an autom
1a9a0 61 74 69 63 20 72 6f 77 69 64 20 2a 2f 0a 23 64 atic rowid */.#d
1a9b0 65 66 69 6e 65 20 53 52 54 5f 44 69 73 74 46 69 efine SRT_DistFi
1a9c0 66 6f 20 20 20 20 20 36 20 20 2f 2a 20 4c 69 6b fo 6 /* Lik
1a9d0 65 20 53 52 54 5f 46 69 66 6f 2c 20 62 75 74 20 e SRT_Fifo, but
1a9e0 75 6e 69 71 75 65 20 72 65 73 75 6c 74 73 20 6f unique results o
1a9f0 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 nly */.#define S
1aa00 52 54 5f 51 75 65 75 65 20 20 20 20 20 20 20 20 RT_Queue
1aa10 37 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 7 /* Store resu
1aa20 6c 74 20 69 6e 20 61 6e 20 71 75 65 75 65 20 2a lt in an queue *
1aa30 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 44 69 /.#define SRT_Di
1aa40 73 74 51 75 65 75 65 20 20 20 20 38 20 20 2f 2a stQueue 8 /*
1aa50 20 4c 69 6b 65 20 53 52 54 5f 51 75 65 75 65 2c Like SRT_Queue,
1aa60 20 62 75 74 20 75 6e 69 71 75 65 20 72 65 73 75 but unique resu
1aa70 6c 74 73 20 6f 6e 6c 79 20 2a 2f 0a 0a 2f 2a 20 lts only */../*
1aa80 54 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 The ORDER BY cla
1aa90 75 73 65 20 69 73 20 69 67 6e 6f 72 65 64 20 66 use is ignored f
1aaa0 6f 72 20 61 6c 6c 20 6f 66 20 74 68 65 20 61 62 or all of the ab
1aab0 6f 76 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 ove */.#define I
1aac0 67 6e 6f 72 61 62 6c 65 4f 72 64 65 72 62 79 28 gnorableOrderby(
1aad0 58 29 20 28 28 58 2d 3e 65 44 65 73 74 29 3c 3d X) ((X->eDest)<=
1aae0 53 52 54 5f 44 69 73 74 51 75 65 75 65 29 0a 0a SRT_DistQueue)..
1aaf0 23 64 65 66 69 6e 65 20 53 52 54 5f 4f 75 74 70 #define SRT_Outp
1ab00 75 74 20 20 20 20 20 20 20 39 20 20 2f 2a 20 4f ut 9 /* O
1ab10 75 74 70 75 74 20 65 61 63 68 20 72 6f 77 20 6f utput each row o
1ab20 66 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 f result */.#def
1ab30 69 6e 65 20 53 52 54 5f 4d 65 6d 20 20 20 20 20 ine SRT_Mem
1ab40 20 20 20 20 31 30 20 20 2f 2a 20 53 74 6f 72 65 10 /* Store
1ab50 20 72 65 73 75 6c 74 20 69 6e 20 61 20 6d 65 6d result in a mem
1ab60 6f 72 79 20 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 ory cell */.#def
1ab70 69 6e 65 20 53 52 54 5f 53 65 74 20 20 20 20 20 ine SRT_Set
1ab80 20 20 20 20 31 31 20 20 2f 2a 20 53 74 6f 72 65 11 /* Store
1ab90 20 72 65 73 75 6c 74 73 20 61 73 20 6b 65 79 73 results as keys
1aba0 20 69 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a in an index */.
1abb0 23 64 65 66 69 6e 65 20 53 52 54 5f 45 70 68 65 #define SRT_Ephe
1abc0 6d 54 61 62 20 20 20 20 31 32 20 20 2f 2a 20 43 mTab 12 /* C
1abd0 72 65 61 74 65 20 74 72 61 6e 73 69 65 6e 74 20 reate transient
1abe0 74 61 62 20 61 6e 64 20 73 74 6f 72 65 20 6c 69 tab and store li
1abf0 6b 65 20 53 52 54 5f 54 61 62 6c 65 20 2a 2f 0a ke SRT_Table */.
1ac00 23 64 65 66 69 6e 65 20 53 52 54 5f 43 6f 72 6f #define SRT_Coro
1ac10 75 74 69 6e 65 20 20 20 31 33 20 20 2f 2a 20 47 utine 13 /* G
1ac20 65 6e 65 72 61 74 65 20 61 20 73 69 6e 67 6c 65 enerate a single
1ac30 20 72 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 2a row of result *
1ac40 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 54 61 /.#define SRT_Ta
1ac50 62 6c 65 20 20 20 20 20 20 20 31 34 20 20 2f 2a ble 14 /*
1ac60 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 61 73 Store result as
1ac70 20 64 61 74 61 20 77 69 74 68 20 61 6e 20 61 75 data with an au
1ac80 74 6f 6d 61 74 69 63 20 72 6f 77 69 64 20 2a 2f tomatic rowid */
1ac90 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 ../*.** An insta
1aca0 6e 63 65 20 6f 66 20 74 68 69 73 20 6f 62 6a 65 nce of this obje
1acb0 63 74 20 64 65 73 63 72 69 62 65 73 20 77 68 65 ct describes whe
1acc0 72 65 20 74 6f 20 70 75 74 20 6f 66 20 74 68 65 re to put of the
1acd0 20 72 65 73 75 6c 74 73 20 6f 66 0a 2a 2a 20 61 results of.** a
1ace0 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e SELECT statemen
1acf0 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c t..*/.struct Sel
1ad00 65 63 74 44 65 73 74 20 7b 0a 20 20 75 38 20 65 ectDest {. u8 e
1ad10 44 65 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 Dest;
1ad20 20 2f 2a 20 48 6f 77 20 74 6f 20 64 69 73 70 6f /* How to dispo
1ad30 73 65 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 se of the result
1ad40 73 2e 20 20 4f 6e 20 6f 66 20 53 52 54 5f 2a 20 s. On of SRT_*
1ad50 61 62 6f 76 65 2e 20 2a 2f 0a 20 20 63 68 61 72 above. */. char
1ad60 20 61 66 66 53 64 73 74 3b 20 20 20 20 20 20 20 affSdst;
1ad70 20 2f 2a 20 41 66 66 69 6e 69 74 79 20 75 73 65 /* Affinity use
1ad80 64 20 77 68 65 6e 20 65 44 65 73 74 3d 3d 53 52 d when eDest==SR
1ad90 54 5f 53 65 74 20 2a 2f 0a 20 20 69 6e 74 20 69 T_Set */. int i
1ada0 53 44 50 61 72 6d 3b 20 20 20 20 20 20 20 20 20 SDParm;
1adb0 2f 2a 20 41 20 70 61 72 61 6d 65 74 65 72 20 75 /* A parameter u
1adc0 73 65 64 20 62 79 20 74 68 65 20 65 44 65 73 74 sed by the eDest
1add0 20 64 69 73 70 6f 73 61 6c 20 6d 65 74 68 6f 64 disposal method
1ade0 20 2a 2f 0a 20 20 69 6e 74 20 69 53 64 73 74 3b */. int iSdst;
1adf0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 61 /* Ba
1ae00 73 65 20 72 65 67 69 73 74 65 72 20 77 68 65 72 se register wher
1ae10 65 20 72 65 73 75 6c 74 73 20 61 72 65 20 77 72 e results are wr
1ae20 69 74 74 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e itten */. int n
1ae30 53 64 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 Sdst;
1ae40 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 72 65 67 /* Number of reg
1ae50 69 73 74 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 isters allocated
1ae60 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1ae70 70 4f 72 64 65 72 42 79 3b 20 20 2f 2a 20 4b 65 pOrderBy; /* Ke
1ae80 79 20 63 6f 6c 75 6d 6e 73 20 66 6f 72 20 53 52 y columns for SR
1ae90 54 5f 51 75 65 75 65 20 61 6e 64 20 53 52 54 5f T_Queue and SRT_
1aea0 44 69 73 74 51 75 65 75 65 20 2a 2f 0a 7d 3b 0a DistQueue */.};.
1aeb0 0a 2f 2a 0a 2a 2a 20 44 75 72 69 6e 67 20 63 6f ./*.** During co
1aec0 64 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f 66 de generation of
1aed0 20 73 74 61 74 65 6d 65 6e 74 73 20 74 68 61 74 statements that
1aee0 20 64 6f 20 69 6e 73 65 72 74 73 20 69 6e 74 6f do inserts into
1aef0 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 0a AUTOINCREMENT .
1af00 2a 2a 20 74 61 62 6c 65 73 2c 20 74 68 65 20 66 ** tables, the f
1af10 6f 6c 6c 6f 77 69 6e 67 20 69 6e 66 6f 72 6d 61 ollowing informa
1af20 74 69 6f 6e 20 69 73 20 61 74 74 61 63 68 65 64 tion is attached
1af30 20 74 6f 20 74 68 65 20 54 61 62 6c 65 2e 75 2e to the Table.u.
1af40 61 75 74 6f 49 6e 63 2e 70 0a 2a 2a 20 70 6f 69 autoInc.p.** poi
1af50 6e 74 65 72 20 6f 66 20 65 61 63 68 20 61 75 74 nter of each aut
1af60 6f 69 6e 63 72 65 6d 65 6e 74 20 74 61 62 6c 65 oincrement table
1af70 20 74 6f 20 72 65 63 6f 72 64 20 73 6f 6d 65 20 to record some
1af80 73 69 64 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e side information
1af90 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 63 6f 64 that.** the cod
1afa0 65 20 67 65 6e 65 72 61 74 6f 72 20 6e 65 65 64 e generator need
1afb0 73 2e 20 20 57 65 20 68 61 76 65 20 74 6f 20 6b s. We have to k
1afc0 65 65 70 20 70 65 72 2d 74 61 62 6c 65 20 61 75 eep per-table au
1afd0 74 6f 69 6e 63 72 65 6d 65 6e 74 0a 2a 2a 20 69 toincrement.** i
1afe0 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 6e 20 63 61 nformation in ca
1aff0 73 65 20 69 6e 73 65 72 74 73 20 61 72 65 20 64 se inserts are d
1b000 6f 77 6e 20 77 69 74 68 69 6e 20 74 72 69 67 67 own within trigg
1b010 65 72 73 2e 20 20 54 72 69 67 67 65 72 73 20 64 ers. Triggers d
1b020 6f 20 6e 6f 74 0a 2a 2a 20 6e 6f 72 6d 61 6c 6c o not.** normall
1b030 79 20 63 6f 6f 72 64 69 6e 61 74 65 20 74 68 65 y coordinate the
1b040 69 72 20 61 63 74 69 76 69 74 69 65 73 2c 20 62 ir activities, b
1b050 75 74 20 77 65 20 64 6f 20 6e 65 65 64 20 74 6f ut we do need to
1b060 20 63 6f 6f 72 64 69 6e 61 74 65 20 74 68 65 0a coordinate the.
1b070 2a 2a 20 6c 6f 61 64 69 6e 67 20 61 6e 64 20 73 ** loading and s
1b080 61 76 69 6e 67 20 6f 66 20 61 75 74 6f 69 6e 63 aving of autoinc
1b090 72 65 6d 65 6e 74 20 69 6e 66 6f 72 6d 61 74 69 rement informati
1b0a0 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 75 on..*/.struct Au
1b0b0 74 6f 69 6e 63 49 6e 66 6f 20 7b 0a 20 20 41 75 toincInfo {. Au
1b0c0 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 4e 65 78 74 toincInfo *pNext
1b0d0 3b 20 20 20 2f 2a 20 4e 65 78 74 20 69 6e 66 6f ; /* Next info
1b0e0 20 62 6c 6f 63 6b 20 69 6e 20 61 20 6c 69 73 74 block in a list
1b0f0 20 6f 66 20 74 68 65 6d 20 61 6c 6c 20 2a 2f 0a of them all */.
1b100 20 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 Table *pTab;
1b110 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
1b120 20 74 68 69 73 20 69 6e 66 6f 20 62 6c 6f 63 6b this info block
1b130 20 72 65 66 65 72 73 20 74 6f 20 2a 2f 0a 20 20 refers to */.
1b140 69 6e 74 20 69 44 62 3b 20 20 20 20 20 20 20 20 int iDb;
1b150 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 /* Index i
1b160 6e 20 73 71 6c 69 74 65 33 2e 61 44 62 5b 5d 20 n sqlite3.aDb[]
1b170 6f 66 20 64 61 74 61 62 61 73 65 20 68 6f 6c 64 of database hold
1b180 69 6e 67 20 70 54 61 62 20 2a 2f 0a 20 20 69 6e ing pTab */. in
1b190 74 20 72 65 67 43 74 72 3b 20 20 20 20 20 20 20 t regCtr;
1b1a0 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 72 65 /* Memory re
1b1b0 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 74 gister holding t
1b1c0 68 65 20 72 6f 77 69 64 20 63 6f 75 6e 74 65 72 he rowid counter
1b1d0 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 69 */.};../*.** Si
1b1e0 7a 65 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e ze of the column
1b1f0 20 63 61 63 68 65 0a 2a 2f 0a 23 69 66 6e 64 65 cache.*/.#ifnde
1b200 66 20 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 f SQLITE_N_COLCA
1b210 43 48 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c CHE.# define SQL
1b220 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 20 31 ITE_N_COLCACHE 1
1b230 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
1b240 41 74 20 6c 65 61 73 74 20 6f 6e 65 20 69 6e 73 At least one ins
1b250 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
1b260 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
1b270 20 69 73 20 63 72 65 61 74 65 64 20 66 6f 72 20 is created for
1b280 65 61 63 68 20 0a 2a 2a 20 74 72 69 67 67 65 72 each .** trigger
1b290 20 74 68 61 74 20 6d 61 79 20 62 65 20 66 69 72 that may be fir
1b2a0 65 64 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 ed while parsing
1b2b0 20 61 6e 20 49 4e 53 45 52 54 2c 20 55 50 44 41 an INSERT, UPDA
1b2c0 54 45 20 6f 72 20 44 45 4c 45 54 45 0a 2a 2a 20 TE or DELETE.**
1b2d0 73 74 61 74 65 6d 65 6e 74 2e 20 41 6c 6c 20 73 statement. All s
1b2e0 75 63 68 20 6f 62 6a 65 63 74 73 20 61 72 65 20 uch objects are
1b2f0 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 6c 69 stored in the li
1b300 6e 6b 65 64 20 6c 69 73 74 20 68 65 61 64 65 64 nked list headed
1b310 20 61 74 0a 2a 2a 20 50 61 72 73 65 2e 70 54 72 at.** Parse.pTr
1b320 69 67 67 65 72 50 72 67 20 61 6e 64 20 64 65 6c iggerPrg and del
1b330 65 74 65 64 20 6f 6e 63 65 20 73 74 61 74 65 6d eted once statem
1b340 65 6e 74 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 ent compilation
1b350 68 61 73 20 62 65 65 6e 0a 2a 2a 20 63 6f 6d 70 has been.** comp
1b360 6c 65 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 41 20 56 leted..**.** A V
1b370 64 62 65 20 73 75 62 2d 70 72 6f 67 72 61 6d 20 dbe sub-program
1b380 74 68 61 74 20 69 6d 70 6c 65 6d 65 6e 74 73 20 that implements
1b390 74 68 65 20 62 6f 64 79 20 61 6e 64 20 57 48 45 the body and WHE
1b3a0 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 72 69 67 N clause of trig
1b3b0 67 65 72 0a 2a 2a 20 54 72 69 67 67 65 72 50 72 ger.** TriggerPr
1b3c0 67 2e 70 54 72 69 67 67 65 72 2c 20 61 73 73 75 g.pTrigger, assu
1b3d0 6d 69 6e 67 20 61 20 64 65 66 61 75 6c 74 20 4f ming a default O
1b3e0 4e 20 43 4f 4e 46 4c 49 43 54 20 63 6c 61 75 73 N CONFLICT claus
1b3f0 65 20 6f 66 0a 2a 2a 20 54 72 69 67 67 65 72 50 e of.** TriggerP
1b400 72 67 2e 6f 72 63 6f 6e 66 2c 20 69 73 20 73 74 rg.orconf, is st
1b410 6f 72 65 64 20 69 6e 20 74 68 65 20 54 72 69 67 ored in the Trig
1b420 67 65 72 50 72 67 2e 70 50 72 6f 67 72 61 6d 20 gerPrg.pProgram
1b430 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 20 54 68 65 variable..** The
1b440 20 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 Parse.pTriggerP
1b450 72 67 20 6c 69 73 74 20 6e 65 76 65 72 20 63 6f rg list never co
1b460 6e 74 61 69 6e 73 20 74 77 6f 20 65 6e 74 72 69 ntains two entri
1b470 65 73 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 es with the same
1b480 0a 2a 2a 20 76 61 6c 75 65 73 20 66 6f 72 20 62 .** values for b
1b490 6f 74 68 20 70 54 72 69 67 67 65 72 20 61 6e 64 oth pTrigger and
1b4a0 20 6f 72 63 6f 6e 66 2e 0a 2a 2a 0a 2a 2a 20 54 orconf..**.** T
1b4b0 68 65 20 54 72 69 67 67 65 72 50 72 67 2e 61 43 he TriggerPrg.aC
1b4c0 6f 6c 6d 61 73 6b 5b 30 5d 20 76 61 72 69 61 62 olmask[0] variab
1b4d0 6c 65 20 69 73 20 73 65 74 20 74 6f 20 61 20 6d le is set to a m
1b4e0 61 73 6b 20 6f 66 20 6f 6c 64 2e 2a 20 63 6f 6c ask of old.* col
1b4f0 75 6d 6e 73 0a 2a 2a 20 61 63 63 65 73 73 65 64 umns.** accessed
1b500 20 28 6f 72 20 73 65 74 20 74 6f 20 30 20 66 6f (or set to 0 fo
1b510 72 20 74 72 69 67 67 65 72 73 20 66 69 72 65 64 r triggers fired
1b520 20 61 73 20 61 20 72 65 73 75 6c 74 20 6f 66 20 as a result of
1b530 49 4e 53 45 52 54 20 0a 2a 2a 20 73 74 61 74 65 INSERT .** state
1b540 6d 65 6e 74 73 29 2e 20 53 69 6d 69 6c 61 72 6c ments). Similarl
1b550 79 2c 20 74 68 65 20 54 72 69 67 67 65 72 50 72 y, the TriggerPr
1b560 67 2e 61 43 6f 6c 6d 61 73 6b 5b 31 5d 20 76 61 g.aColmask[1] va
1b570 72 69 61 62 6c 65 20 69 73 20 73 65 74 20 74 6f riable is set to
1b580 0a 2a 2a 20 61 20 6d 61 73 6b 20 6f 66 20 6e 65 .** a mask of ne
1b590 77 2e 2a 20 63 6f 6c 75 6d 6e 73 20 75 73 65 64 w.* columns used
1b5a0 20 62 79 20 74 68 65 20 70 72 6f 67 72 61 6d 2e by the program.
1b5b0 0a 2a 2f 0a 73 74 72 75 63 74 20 54 72 69 67 67 .*/.struct Trigg
1b5c0 65 72 50 72 67 20 7b 0a 20 20 54 72 69 67 67 65 erPrg {. Trigge
1b5d0 72 20 2a 70 54 72 69 67 67 65 72 3b 20 20 20 20 r *pTrigger;
1b5e0 20 20 2f 2a 20 54 72 69 67 67 65 72 20 74 68 69 /* Trigger thi
1b5f0 73 20 70 72 6f 67 72 61 6d 20 77 61 73 20 63 6f s program was co
1b600 64 65 64 20 66 72 6f 6d 20 2a 2f 0a 20 20 54 72 ded from */. Tr
1b610 69 67 67 65 72 50 72 67 20 2a 70 4e 65 78 74 3b iggerPrg *pNext;
1b620 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 65 6e /* Next en
1b630 74 72 79 20 69 6e 20 50 61 72 73 65 2e 70 54 72 try in Parse.pTr
1b640 69 67 67 65 72 50 72 67 20 6c 69 73 74 20 2a 2f iggerPrg list */
1b650 0a 20 20 53 75 62 50 72 6f 67 72 61 6d 20 2a 70 . SubProgram *p
1b660 50 72 6f 67 72 61 6d 3b 20 20 20 2f 2a 20 50 72 Program; /* Pr
1b670 6f 67 72 61 6d 20 69 6d 70 6c 65 6d 65 6e 74 69 ogram implementi
1b680 6e 67 20 70 54 72 69 67 67 65 72 2f 6f 72 63 6f ng pTrigger/orco
1b690 6e 66 20 2a 2f 0a 20 20 69 6e 74 20 6f 72 63 6f nf */. int orco
1b6a0 6e 66 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nf;
1b6b0 2f 2a 20 44 65 66 61 75 6c 74 20 4f 4e 20 43 4f /* Default ON CO
1b6c0 4e 46 4c 49 43 54 20 70 6f 6c 69 63 79 20 2a 2f NFLICT policy */
1b6d0 0a 20 20 75 33 32 20 61 43 6f 6c 6d 61 73 6b 5b . u32 aColmask[
1b6e0 32 5d 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 2]; /* Ma
1b6f0 73 6b 73 20 6f 66 20 6f 6c 64 2e 2a 2c 20 6e 65 sks of old.*, ne
1b700 77 2e 2a 20 63 6f 6c 75 6d 6e 73 20 61 63 63 65 w.* columns acce
1b710 73 73 65 64 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a ssed */.};../*.*
1b720 2a 20 54 68 65 20 79 44 62 4d 61 73 6b 20 64 61 * The yDbMask da
1b730 74 61 74 79 70 65 20 66 6f 72 20 74 68 65 20 62 tatype for the b
1b740 69 74 6d 61 73 6b 20 6f 66 20 61 6c 6c 20 61 74 itmask of all at
1b750 74 61 63 68 65 64 20 64 61 74 61 62 61 73 65 73 tached databases
1b760 2e 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f ..*/.#if SQLITE_
1b770 4d 41 58 5f 41 54 54 41 43 48 45 44 3e 33 30 0a MAX_ATTACHED>30.
1b780 20 20 74 79 70 65 64 65 66 20 75 6e 73 69 67 6e typedef unsign
1b790 65 64 20 63 68 61 72 20 79 44 62 4d 61 73 6b 5b ed char yDbMask[
1b7a0 28 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 (SQLITE_MAX_ATTA
1b7b0 43 48 45 44 2b 39 29 2f 38 5d 3b 0a 23 20 64 65 CHED+9)/8];.# de
1b7c0 66 69 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 fine DbMaskTest(
1b7d0 4d 2c 49 29 20 20 20 20 28 28 28 4d 29 5b 28 49 M,I) (((M)[(I
1b7e0 29 2f 38 5d 26 28 31 3c 3c 28 28 49 29 26 37 29 )/8]&(1<<((I)&7)
1b7f0 29 29 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 ))!=0).# define
1b800 44 62 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 DbMaskZero(M)
1b810 20 20 20 6d 65 6d 73 65 74 28 28 4d 29 2c 30 2c memset((M),0,
1b820 73 69 7a 65 6f 66 28 4d 29 29 0a 23 20 64 65 66 sizeof(M)).# def
1b830 69 6e 65 20 44 62 4d 61 73 6b 53 65 74 28 4d 2c ine DbMaskSet(M,
1b840 49 29 20 20 20 20 20 28 4d 29 5b 28 49 29 2f 38 I) (M)[(I)/8
1b850 5d 7c 3d 28 31 3c 3c 28 28 49 29 26 37 29 29 0a ]|=(1<<((I)&7)).
1b860 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 41 # define DbMaskA
1b870 6c 6c 5a 65 72 6f 28 4d 29 20 20 20 73 71 6c 69 llZero(M) sqli
1b880 74 65 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f te3DbMaskAllZero
1b890 28 4d 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d (M).# define DbM
1b8a0 61 73 6b 4e 6f 6e 5a 65 72 6f 28 4d 29 20 20 20 askNonZero(M)
1b8b0 28 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c (sqlite3DbMaskAl
1b8c0 6c 5a 65 72 6f 28 4d 29 3d 3d 30 29 0a 23 65 6c lZero(M)==0).#el
1b8d0 73 65 0a 20 20 74 79 70 65 64 65 66 20 75 6e 73 se. typedef uns
1b8e0 69 67 6e 65 64 20 69 6e 74 20 79 44 62 4d 61 73 igned int yDbMas
1b8f0 6b 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 k;.# define DbMa
1b900 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 skTest(M,I) (
1b910 28 28 4d 29 26 28 28 28 79 44 62 4d 61 73 6b 29 ((M)&(((yDbMask)
1b920 31 29 3c 3c 28 49 29 29 29 21 3d 30 29 0a 23 20 1)<<(I)))!=0).#
1b930 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 define DbMaskZer
1b940 6f 28 4d 29 20 20 20 20 20 20 28 4d 29 3d 30 0a o(M) (M)=0.
1b950 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 53 # define DbMaskS
1b960 65 74 28 4d 2c 49 29 20 20 20 20 20 28 4d 29 7c et(M,I) (M)|
1b970 3d 28 28 28 79 44 62 4d 61 73 6b 29 31 29 3c 3c =(((yDbMask)1)<<
1b980 28 49 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 (I)).# define Db
1b990 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 20 20 MaskAllZero(M)
1b9a0 20 28 4d 29 3d 3d 30 0a 23 20 64 65 66 69 6e 65 (M)==0.# define
1b9b0 20 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 6f 28 4d DbMaskNonZero(M
1b9c0 29 20 20 20 28 4d 29 21 3d 30 0a 23 65 6e 64 69 ) (M)!=0.#endi
1b9d0 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 53 51 4c 20 f../*.** An SQL
1b9e0 70 61 72 73 65 72 20 63 6f 6e 74 65 78 74 2e 20 parser context.
1b9f0 20 41 20 63 6f 70 79 20 6f 66 20 74 68 69 73 20 A copy of this
1ba00 73 74 72 75 63 74 75 72 65 20 69 73 20 70 61 73 structure is pas
1ba10 73 65 64 20 74 68 72 6f 75 67 68 0a 2a 2a 20 74 sed through.** t
1ba20 68 65 20 70 61 72 73 65 72 20 61 6e 64 20 64 6f he parser and do
1ba30 77 6e 20 69 6e 74 6f 20 61 6c 6c 20 74 68 65 20 wn into all the
1ba40 70 61 72 73 65 72 20 61 63 74 69 6f 6e 20 72 6f parser action ro
1ba50 75 74 69 6e 65 20 69 6e 20 6f 72 64 65 72 20 74 utine in order t
1ba60 6f 0a 2a 2a 20 63 61 72 72 79 20 61 72 6f 75 6e o.** carry aroun
1ba70 64 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 d information th
1ba80 61 74 20 69 73 20 67 6c 6f 62 61 6c 20 74 6f 20 at is global to
1ba90 74 68 65 20 65 6e 74 69 72 65 20 70 61 72 73 65 the entire parse
1baa0 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 74 72 75 ..**.** The stru
1bab0 63 74 75 72 65 20 69 73 20 64 69 76 69 64 65 64 cture is divided
1bac0 20 69 6e 74 6f 20 74 77 6f 20 70 61 72 74 73 2e into two parts.
1bad0 20 20 57 68 65 6e 20 74 68 65 20 70 61 72 73 65 When the parse
1bae0 72 20 61 6e 64 20 63 6f 64 65 0a 2a 2a 20 67 65 r and code.** ge
1baf0 6e 65 72 61 74 65 20 63 61 6c 6c 20 74 68 65 6d nerate call them
1bb00 73 65 6c 76 65 73 20 72 65 63 75 72 73 69 76 65 selves recursive
1bb10 6c 79 2c 20 74 68 65 20 66 69 72 73 74 20 70 61 ly, the first pa
1bb20 72 74 20 6f 66 20 74 68 65 20 73 74 72 75 63 74 rt of the struct
1bb30 75 72 65 0a 2a 2a 20 69 73 20 63 6f 6e 73 74 61 ure.** is consta
1bb40 6e 74 20 62 75 74 20 74 68 65 20 73 65 63 6f 6e nt but the secon
1bb50 64 20 70 61 72 74 20 69 73 20 72 65 73 65 74 20 d part is reset
1bb60 61 74 20 74 68 65 20 62 65 67 69 6e 6e 69 6e 67 at the beginning
1bb70 20 61 6e 64 20 65 6e 64 20 6f 66 0a 2a 2a 20 65 and end of.** e
1bb80 61 63 68 20 72 65 63 75 72 73 69 6f 6e 2e 0a 2a ach recursion..*
1bb90 2a 0a 2a 2a 20 54 68 65 20 6e 54 61 62 6c 65 4c *.** The nTableL
1bba0 6f 63 6b 20 61 6e 64 20 61 54 61 62 6c 65 4c 6f ock and aTableLo
1bbb0 63 6b 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 ck variables are
1bbc0 20 6f 6e 6c 79 20 75 73 65 64 20 69 66 20 74 68 only used if th
1bbd0 65 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 0a e shared-cache .
1bbe0 2a 2a 20 66 65 61 74 75 72 65 20 69 73 20 65 6e ** feature is en
1bbf0 61 62 6c 65 64 20 28 69 66 20 73 71 6c 69 74 65 abled (if sqlite
1bc00 33 54 73 64 28 29 2d 3e 75 73 65 53 68 61 72 65 3Tsd()->useShare
1bc10 64 44 61 74 61 20 69 73 20 74 72 75 65 29 2e 20 dData is true).
1bc20 54 68 65 79 20 61 72 65 0a 2a 2a 20 75 73 65 64 They are.** used
1bc30 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 73 65 to store the se
1bc40 74 20 6f 66 20 74 61 62 6c 65 2d 6c 6f 63 6b 73 t of table-locks
1bc50 20 72 65 71 75 69 72 65 64 20 62 79 20 74 68 65 required by the
1bc60 20 73 74 61 74 65 6d 65 6e 74 20 62 65 69 6e 67 statement being
1bc70 0a 2a 2a 20 63 6f 6d 70 69 6c 65 64 2e 20 46 75 .** compiled. Fu
1bc80 6e 63 74 69 6f 6e 20 73 71 6c 69 74 65 33 54 61 nction sqlite3Ta
1bc90 62 6c 65 4c 6f 63 6b 28 29 20 69 73 20 75 73 65 bleLock() is use
1bca0 64 20 74 6f 20 61 64 64 20 65 6e 74 72 69 65 73 d to add entries
1bcb0 20 74 6f 20 74 68 65 0a 2a 2a 20 6c 69 73 74 2e to the.** list.
1bcc0 0a 2a 2f 0a 73 74 72 75 63 74 20 50 61 72 73 65 .*/.struct Parse
1bcd0 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 {. sqlite3 *db
1bce0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 ; /* The
1bcf0 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 73 main database s
1bd00 74 72 75 63 74 75 72 65 20 2a 2f 0a 20 20 63 68 tructure */. ch
1bd10 61 72 20 2a 7a 45 72 72 4d 73 67 3b 20 20 20 20 ar *zErrMsg;
1bd20 20 20 20 2f 2a 20 41 6e 20 65 72 72 6f 72 20 6d /* An error m
1bd30 65 73 73 61 67 65 20 2a 2f 0a 20 20 56 64 62 65 essage */. Vdbe
1bd40 20 2a 70 56 64 62 65 3b 20 20 20 20 20 20 20 20 *pVdbe;
1bd50 20 2f 2a 20 41 6e 20 65 6e 67 69 6e 65 20 66 6f /* An engine fo
1bd60 72 20 65 78 65 63 75 74 69 6e 67 20 64 61 74 61 r executing data
1bd70 62 61 73 65 20 62 79 74 65 63 6f 64 65 20 2a 2f base bytecode */
1bd80 0a 20 20 69 6e 74 20 72 63 3b 20 20 20 20 20 20 . int rc;
1bd90 20 20 20 20 20 20 20 20 2f 2a 20 52 65 74 75 72 /* Retur
1bda0 6e 20 63 6f 64 65 20 66 72 6f 6d 20 65 78 65 63 n code from exec
1bdb0 75 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 63 6f ution */. u8 co
1bdc0 6c 4e 61 6d 65 73 53 65 74 3b 20 20 20 20 20 20 lNamesSet;
1bdd0 2f 2a 20 54 52 55 45 20 61 66 74 65 72 20 4f 50 /* TRUE after OP
1bde0 5f 43 6f 6c 75 6d 6e 4e 61 6d 65 20 68 61 73 20 _ColumnName has
1bdf0 62 65 65 6e 20 69 73 73 75 65 64 20 74 6f 20 70 been issued to p
1be00 56 64 62 65 20 2a 2f 0a 20 20 75 38 20 63 68 65 Vdbe */. u8 che
1be10 63 6b 53 63 68 65 6d 61 3b 20 20 20 20 20 20 2f ckSchema; /
1be20 2a 20 43 61 75 73 65 73 20 73 63 68 65 6d 61 20 * Causes schema
1be30 63 6f 6f 6b 69 65 20 63 68 65 63 6b 20 61 66 74 cookie check aft
1be40 65 72 20 61 6e 20 65 72 72 6f 72 20 2a 2f 0a 20 er an error */.
1be50 20 75 38 20 6e 65 73 74 65 64 3b 20 20 20 20 20 u8 nested;
1be60 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1be70 6f 66 20 6e 65 73 74 65 64 20 63 61 6c 6c 73 20 of nested calls
1be80 74 6f 20 74 68 65 20 70 61 72 73 65 72 2f 63 6f to the parser/co
1be90 64 65 20 67 65 6e 65 72 61 74 6f 72 20 2a 2f 0a de generator */.
1bea0 20 20 75 38 20 6e 54 65 6d 70 52 65 67 3b 20 20 u8 nTempReg;
1beb0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1bec0 20 6f 66 20 74 65 6d 70 6f 72 61 72 79 20 72 65 of temporary re
1bed0 67 69 73 74 65 72 73 20 69 6e 20 61 54 65 6d 70 gisters in aTemp
1bee0 52 65 67 5b 5d 20 2a 2f 0a 20 20 75 38 20 69 73 Reg[] */. u8 is
1bef0 4d 75 6c 74 69 57 72 69 74 65 3b 20 20 20 20 20 MultiWrite;
1bf00 2f 2a 20 54 72 75 65 20 69 66 20 73 74 61 74 65 /* True if state
1bf10 6d 65 6e 74 20 6d 61 79 20 6d 6f 64 69 66 79 2f ment may modify/
1bf20 69 6e 73 65 72 74 20 6d 75 6c 74 69 70 6c 65 20 insert multiple
1bf30 72 6f 77 73 20 2a 2f 0a 20 20 75 38 20 6d 61 79 rows */. u8 may
1bf40 41 62 6f 72 74 3b 20 20 20 20 20 20 20 20 20 2f Abort; /
1bf50 2a 20 54 72 75 65 20 69 66 20 73 74 61 74 65 6d * True if statem
1bf60 65 6e 74 20 6d 61 79 20 74 68 72 6f 77 20 61 6e ent may throw an
1bf70 20 41 42 4f 52 54 20 65 78 63 65 70 74 69 6f 6e ABORT exception
1bf80 20 2a 2f 0a 20 20 75 38 20 68 61 73 43 6f 6d 70 */. u8 hasComp
1bf90 6f 75 6e 64 3b 20 20 20 20 20 20 2f 2a 20 4e 65 ound; /* Ne
1bfa0 65 64 20 74 6f 20 69 6e 76 6f 6b 65 20 63 6f 6e ed to invoke con
1bfb0 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 vertCompoundSele
1bfc0 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a ctToSubquery() *
1bfd0 2f 0a 20 20 75 38 20 6f 6b 43 6f 6e 73 74 46 61 /. u8 okConstFa
1bfe0 63 74 6f 72 3b 20 20 20 20 2f 2a 20 4f 4b 20 74 ctor; /* OK t
1bff0 6f 20 66 61 63 74 6f 72 20 6f 75 74 20 63 6f 6e o factor out con
1c000 73 74 61 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 stants */. int
1c010 61 54 65 6d 70 52 65 67 5b 38 5d 3b 20 20 20 20 aTempReg[8];
1c020 20 2f 2a 20 48 6f 6c 64 69 6e 67 20 61 72 65 61 /* Holding area
1c030 20 66 6f 72 20 74 65 6d 70 6f 72 61 72 79 20 72 for temporary r
1c040 65 67 69 73 74 65 72 73 20 2a 2f 0a 20 20 69 6e egisters */. in
1c050 74 20 6e 52 61 6e 67 65 52 65 67 3b 20 20 20 20 t nRangeReg;
1c060 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 74 68 /* Size of th
1c070 65 20 74 65 6d 70 6f 72 61 72 79 20 72 65 67 69 e temporary regi
1c080 73 74 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 ster block */.
1c090 69 6e 74 20 69 52 61 6e 67 65 52 65 67 3b 20 20 int iRangeReg;
1c0a0 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 72 65 /* First re
1c0b0 67 69 73 74 65 72 20 69 6e 20 74 65 6d 70 6f 72 gister in tempor
1c0c0 61 72 79 20 72 65 67 69 73 74 65 72 20 62 6c 6f ary register blo
1c0d0 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 ck */. int nErr
1c0e0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1c0f0 4e 75 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 Number of errors
1c100 20 73 65 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e seen */. int n
1c110 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tab;
1c120 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 72 65 /* Number of pre
1c130 76 69 6f 75 73 6c 79 20 61 6c 6c 6f 63 61 74 65 viously allocate
1c140 64 20 56 44 42 45 20 63 75 72 73 6f 72 73 20 2a d VDBE cursors *
1c150 2f 0a 20 20 69 6e 74 20 6e 4d 65 6d 3b 20 20 20 /. int nMem;
1c160 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1c170 65 72 20 6f 66 20 6d 65 6d 6f 72 79 20 63 65 6c er of memory cel
1c180 6c 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a ls used so far *
1c190 2f 0a 20 20 69 6e 74 20 6e 53 65 74 3b 20 20 20 /. int nSet;
1c1a0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1c1b0 65 72 20 6f 66 20 73 65 74 73 20 75 73 65 64 20 er of sets used
1c1c0 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 20 so far */. int
1c1d0 6e 4f 6e 63 65 3b 20 20 20 20 20 20 20 20 20 20 nOnce;
1c1e0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 4f 50 /* Number of OP
1c1f0 5f 4f 6e 63 65 20 69 6e 73 74 72 75 63 74 69 6f _Once instructio
1c200 6e 73 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 ns so far */. i
1c210 6e 74 20 6e 4f 70 41 6c 6c 6f 63 3b 20 20 20 20 nt nOpAlloc;
1c220 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1c230 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 74 65 64 slots allocated
1c240 20 66 6f 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 for Vdbe.aOp[]
1c250 2a 2f 0a 20 20 69 6e 74 20 69 46 69 78 65 64 4f */. int iFixedO
1c260 70 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 76 p; /* Nev
1c270 65 72 20 62 61 63 6b 20 6f 75 74 20 6f 70 63 6f er back out opco
1c280 64 65 73 20 69 46 69 78 65 64 4f 70 2d 31 20 6f des iFixedOp-1 o
1c290 72 20 65 61 72 6c 69 65 72 20 2a 2f 0a 20 20 69 r earlier */. i
1c2a0 6e 74 20 63 6b 42 61 73 65 3b 20 20 20 20 20 20 nt ckBase;
1c2b0 20 20 20 20 2f 2a 20 42 61 73 65 20 72 65 67 69 /* Base regi
1c2c0 73 74 65 72 20 6f 66 20 64 61 74 61 20 64 75 72 ster of data dur
1c2d0 69 6e 67 20 63 68 65 63 6b 20 63 6f 6e 73 74 72 ing check constr
1c2e0 61 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 69 aints */. int i
1c2f0 53 65 6c 66 54 61 62 3b 20 20 20 20 20 20 20 20 SelfTab;
1c300 2f 2a 20 54 61 62 6c 65 20 6f 66 20 61 6e 20 69 /* Table of an i
1c310 6e 64 65 78 20 77 68 6f 73 65 20 65 78 70 72 73 ndex whose exprs
1c320 20 61 72 65 20 62 65 69 6e 67 20 63 6f 64 65 64 are being coded
1c330 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 65 */. int iCache
1c340 4c 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 43 6f Level; /* Co
1c350 6c 43 61 63 68 65 20 76 61 6c 69 64 20 77 68 65 lCache valid whe
1c360 6e 20 61 43 6f 6c 43 61 63 68 65 5b 5d 2e 69 4c n aColCache[].iL
1c370 65 76 65 6c 3c 3d 69 43 61 63 68 65 4c 65 76 65 evel<=iCacheLeve
1c380 6c 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 l */. int iCach
1c390 65 43 6e 74 3b 20 20 20 20 20 20 20 2f 2a 20 43 eCnt; /* C
1c3a0 6f 75 6e 74 65 72 20 75 73 65 64 20 74 6f 20 67 ounter used to g
1c3b0 65 6e 65 72 61 74 65 20 61 43 6f 6c 43 61 63 68 enerate aColCach
1c3c0 65 5b 5d 2e 6c 72 75 20 76 61 6c 75 65 73 20 2a e[].lru values *
1c3d0 2f 0a 20 20 69 6e 74 20 6e 4c 61 62 65 6c 3b 20 /. int nLabel;
1c3e0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1c3f0 65 72 20 6f 66 20 6c 61 62 65 6c 73 20 75 73 65 er of labels use
1c400 64 20 2a 2f 0a 20 20 69 6e 74 20 2a 61 4c 61 62 d */. int *aLab
1c410 65 6c 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 53 el; /* S
1c420 70 61 63 65 20 74 6f 20 68 6f 6c 64 20 74 68 65 pace to hold the
1c430 20 6c 61 62 65 6c 73 20 2a 2f 0a 20 20 73 74 72 labels */. str
1c440 75 63 74 20 79 43 6f 6c 43 61 63 68 65 20 7b 0a uct yColCache {.
1c450 20 20 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 int iTable;
1c460 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 /* Tab
1c470 6c 65 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 le cursor number
1c480 20 2a 2f 0a 20 20 20 20 69 31 36 20 69 43 6f 6c */. i16 iCol
1c490 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a umn; /*
1c4a0 20 54 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 6e 75 Table column nu
1c4b0 6d 62 65 72 20 2a 2f 0a 20 20 20 20 75 38 20 74 mber */. u8 t
1c4c0 65 6d 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 empReg;
1c4d0 20 20 2f 2a 20 69 52 65 67 20 69 73 20 61 20 74 /* iReg is a t
1c4e0 65 6d 70 20 72 65 67 69 73 74 65 72 20 74 68 61 emp register tha
1c4f0 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 66 72 t needs to be fr
1c500 65 65 64 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 eed */. int i
1c510 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 Level;
1c520 20 2f 2a 20 4e 65 73 74 69 6e 67 20 6c 65 76 65 /* Nesting leve
1c530 6c 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 52 65 l */. int iRe
1c540 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f g; /
1c550 2a 20 52 65 67 20 77 69 74 68 20 76 61 6c 75 65 * Reg with value
1c560 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e of this column.
1c570 20 30 20 6d 65 61 6e 73 20 6e 6f 6e 65 2e 20 2a 0 means none. *
1c580 2f 0a 20 20 20 20 69 6e 74 20 6c 72 75 3b 20 20 /. int lru;
1c590 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c /* L
1c5a0 65 61 73 74 20 72 65 63 65 6e 74 6c 79 20 75 73 east recently us
1c5b0 65 64 20 65 6e 74 72 79 20 68 61 73 20 74 68 65 ed entry has the
1c5c0 20 73 6d 61 6c 6c 65 73 74 20 76 61 6c 75 65 20 smallest value
1c5d0 2a 2f 0a 20 20 7d 20 61 43 6f 6c 43 61 63 68 65 */. } aColCache
1c5e0 5b 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 [SQLITE_N_COLCAC
1c5f0 48 45 5d 3b 20 20 2f 2a 20 4f 6e 65 20 66 6f 72 HE]; /* One for
1c600 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 63 61 63 each column cac
1c610 68 65 20 65 6e 74 72 79 20 2a 2f 0a 20 20 45 78 he entry */. Ex
1c620 70 72 4c 69 73 74 20 2a 70 43 6f 6e 73 74 45 78 prList *pConstEx
1c630 70 72 3b 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 pr;/* Constant e
1c640 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 xpressions */.
1c650 54 6f 6b 65 6e 20 63 6f 6e 73 74 72 61 69 6e 74 Token constraint
1c660 4e 61 6d 65 3b 2f 2a 20 4e 61 6d 65 20 6f 66 20 Name;/* Name of
1c670 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 the constraint c
1c680 75 72 72 65 6e 74 6c 79 20 62 65 69 6e 67 20 70 urrently being p
1c690 61 72 73 65 64 20 2a 2f 0a 20 20 79 44 62 4d 61 arsed */. yDbMa
1c6a0 73 6b 20 77 72 69 74 65 4d 61 73 6b 3b 20 20 20 sk writeMask;
1c6b0 2f 2a 20 53 74 61 72 74 20 61 20 77 72 69 74 65 /* Start a write
1c6c0 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 6f 6e 20 transaction on
1c6d0 74 68 65 73 65 20 64 61 74 61 62 61 73 65 73 20 these databases
1c6e0 2a 2f 0a 20 20 79 44 62 4d 61 73 6b 20 63 6f 6f */. yDbMask coo
1c6f0 6b 69 65 4d 61 73 6b 3b 20 20 2f 2a 20 42 69 74 kieMask; /* Bit
1c700 6d 61 73 6b 20 6f 66 20 73 63 68 65 6d 61 20 76 mask of schema v
1c710 65 72 69 66 69 65 64 20 64 61 74 61 62 61 73 65 erified database
1c720 73 20 2a 2f 0a 20 20 69 6e 74 20 63 6f 6f 6b 69 s */. int cooki
1c730 65 56 61 6c 75 65 5b 53 51 4c 49 54 45 5f 4d 41 eValue[SQLITE_MA
1c740 58 5f 41 54 54 41 43 48 45 44 2b 32 5d 3b 20 20 X_ATTACHED+2];
1c750 2f 2a 20 56 61 6c 75 65 73 20 6f 66 20 63 6f 6f /* Values of coo
1c760 6b 69 65 73 20 74 6f 20 76 65 72 69 66 79 20 2a kies to verify *
1c770 2f 0a 20 20 69 6e 74 20 72 65 67 52 6f 77 69 64 /. int regRowid
1c780 3b 20 20 20 20 20 20 20 20 2f 2a 20 52 65 67 69 ; /* Regi
1c790 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 6f 77 ster holding row
1c7a0 69 64 20 6f 66 20 43 52 45 41 54 45 20 54 41 42 id of CREATE TAB
1c7b0 4c 45 20 65 6e 74 72 79 20 2a 2f 0a 20 20 69 6e LE entry */. in
1c7c0 74 20 72 65 67 52 6f 6f 74 3b 20 20 20 20 20 20 t regRoot;
1c7d0 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 /* Register h
1c7e0 6f 6c 64 69 6e 67 20 72 6f 6f 74 20 70 61 67 65 olding root page
1c7f0 20 6e 75 6d 62 65 72 20 66 6f 72 20 6e 65 77 20 number for new
1c800 6f 62 6a 65 63 74 73 20 2a 2f 0a 20 20 69 6e 74 objects */. int
1c810 20 6e 4d 61 78 41 72 67 3b 20 20 20 20 20 20 20 nMaxArg;
1c820 20 20 2f 2a 20 4d 61 78 20 61 72 67 73 20 70 61 /* Max args pa
1c830 73 73 65 64 20 74 6f 20 75 73 65 72 20 66 75 6e ssed to user fun
1c840 63 74 69 6f 6e 20 62 79 20 73 75 62 2d 70 72 6f ction by sub-pro
1c850 67 72 61 6d 20 2a 2f 0a 23 69 66 20 53 45 4c 45 gram */.#if SELE
1c860 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 0a CTTRACE_ENABLED.
1c870 20 20 69 6e 74 20 6e 53 65 6c 65 63 74 3b 20 20 int nSelect;
1c880 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1c890 20 6f 66 20 53 45 4c 45 43 54 20 73 74 61 74 65 of SELECT state
1c8a0 6d 65 6e 74 73 20 73 65 65 6e 20 2a 2f 0a 20 20 ments seen */.
1c8b0 69 6e 74 20 6e 53 65 6c 65 63 74 49 6e 64 65 6e int nSelectInden
1c8c0 74 3b 20 20 20 2f 2a 20 48 6f 77 20 66 61 72 20 t; /* How far
1c8d0 74 6f 20 69 6e 64 65 6e 74 20 53 45 4c 45 43 54 to indent SELECT
1c8e0 54 52 41 43 45 28 29 20 6f 75 74 70 75 74 20 2a TRACE() output *
1c8f0 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 /.#endif.#ifndef
1c900 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 48 41 SQLITE_OMIT_SHA
1c910 52 45 44 5f 43 41 43 48 45 0a 20 20 69 6e 74 20 RED_CACHE. int
1c920 6e 54 61 62 6c 65 4c 6f 63 6b 3b 20 20 20 20 20 nTableLock;
1c930 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1c940 6c 6f 63 6b 73 20 69 6e 20 61 54 61 62 6c 65 4c locks in aTableL
1c950 6f 63 6b 20 2a 2f 0a 20 20 54 61 62 6c 65 4c 6f ock */. TableLo
1c960 63 6b 20 2a 61 54 61 62 6c 65 4c 6f 63 6b 3b 20 ck *aTableLock;
1c970 2f 2a 20 52 65 71 75 69 72 65 64 20 74 61 62 6c /* Required tabl
1c980 65 20 6c 6f 63 6b 73 20 66 6f 72 20 73 68 61 72 e locks for shar
1c990 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 2a 2f ed-cache mode */
1c9a0 0a 23 65 6e 64 69 66 0a 20 20 41 75 74 6f 69 6e .#endif. Autoin
1c9b0 63 49 6e 66 6f 20 2a 70 41 69 6e 63 3b 20 20 2f cInfo *pAinc; /
1c9c0 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 * Information ab
1c9d0 6f 75 74 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e out AUTOINCREMEN
1c9e0 54 20 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 0a 20 T counters */..
1c9f0 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 /* Information
1ca00 75 73 65 64 20 77 68 69 6c 65 20 63 6f 64 69 6e used while codin
1ca10 67 20 74 72 69 67 67 65 72 20 70 72 6f 67 72 61 g trigger progra
1ca20 6d 73 2e 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a ms. */. Parse *
1ca30 70 54 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a pToplevel; /*
1ca40 20 50 61 72 73 65 20 73 74 72 75 63 74 75 72 65 Parse structure
1ca50 20 66 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 for main progra
1ca60 6d 20 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 m (or NULL) */.
1ca70 20 54 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 Table *pTrigger
1ca80 54 61 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 Tab; /* Table t
1ca90 72 69 67 67 65 72 73 20 61 72 65 20 62 65 69 6e riggers are bein
1caa0 67 20 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 g coded for */.
1cab0 20 69 6e 74 20 61 64 64 72 43 72 54 61 62 3b 20 int addrCrTab;
1cac0 20 20 20 20 20 20 2f 2a 20 41 64 64 72 65 73 73 /* Address
1cad0 20 6f 66 20 4f 50 5f 43 72 65 61 74 65 54 61 62 of OP_CreateTab
1cae0 6c 65 20 6f 70 63 6f 64 65 20 6f 6e 20 43 52 45 le opcode on CRE
1caf0 41 54 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 75 ATE TABLE */. u
1cb00 33 32 20 6e 51 75 65 72 79 4c 6f 6f 70 3b 20 20 32 nQueryLoop;
1cb10 20 20 20 20 2f 2a 20 45 73 74 20 6e 75 6d 62 65 /* Est numbe
1cb20 72 20 6f 66 20 69 74 65 72 61 74 69 6f 6e 73 20 r of iterations
1cb30 6f 66 20 61 20 71 75 65 72 79 20 28 31 30 2a 6c of a query (10*l
1cb40 6f 67 32 28 4e 29 29 20 2a 2f 0a 20 20 75 33 32 og2(N)) */. u32
1cb50 20 6f 6c 64 6d 61 73 6b 3b 20 20 20 20 20 20 20 oldmask;
1cb60 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f 6c 64 /* Mask of old
1cb70 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 .* columns refer
1cb80 65 6e 63 65 64 20 2a 2f 0a 20 20 75 33 32 20 6e enced */. u32 n
1cb90 65 77 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 ewmask;
1cba0 2f 2a 20 4d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a /* Mask of new.*
1cbb0 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e columns referen
1cbc0 63 65 64 20 2a 2f 0a 20 20 75 38 20 65 54 72 69 ced */. u8 eTri
1cbd0 67 67 65 72 4f 70 3b 20 20 20 20 20 20 20 2f 2a ggerOp; /*
1cbe0 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 TK_UPDATE, TK_I
1cbf0 4e 53 45 52 54 20 6f 72 20 54 4b 5f 44 45 4c 45 NSERT or TK_DELE
1cc00 54 45 20 2a 2f 0a 20 20 75 38 20 65 4f 72 63 6f TE */. u8 eOrco
1cc10 6e 66 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 nf; /*
1cc20 44 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c Default ON CONFL
1cc30 49 43 54 20 70 6f 6c 69 63 79 20 66 6f 72 20 74 ICT policy for t
1cc40 72 69 67 67 65 72 20 73 74 65 70 73 20 2a 2f 0a rigger steps */.
1cc50 20 20 75 38 20 64 69 73 61 62 6c 65 54 72 69 67 u8 disableTrig
1cc60 67 65 72 73 3b 20 20 2f 2a 20 54 72 75 65 20 74 gers; /* True t
1cc70 6f 20 64 69 73 61 62 6c 65 20 74 72 69 67 67 65 o disable trigge
1cc80 72 73 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a rs */.. /******
1cc90 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1cca0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ccb0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ccc0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ccd0 2a 2a 0a 20 20 2a 2a 20 41 62 6f 76 65 20 69 73 **. ** Above is
1cce0 20 63 6f 6e 73 74 61 6e 74 20 62 65 74 77 65 65 constant betwee
1ccf0 6e 20 72 65 63 75 72 73 69 6f 6e 73 2e 20 20 42 n recursions. B
1cd00 65 6c 6f 77 20 69 73 20 72 65 73 65 74 20 62 65 elow is reset be
1cd10 66 6f 72 65 20 61 6e 64 20 61 66 74 65 72 0a 20 fore and after.
1cd20 20 2a 2a 20 65 61 63 68 20 72 65 63 75 72 73 69 ** each recursi
1cd30 6f 6e 2e 20 20 54 68 65 20 62 6f 75 6e 64 61 72 on. The boundar
1cd40 79 20 62 65 74 77 65 65 6e 20 74 68 65 73 65 20 y between these
1cd50 74 77 6f 20 72 65 67 69 6f 6e 73 20 69 73 20 64 two regions is d
1cd60 65 74 65 72 6d 69 6e 65 64 0a 20 20 2a 2a 20 75 etermined. ** u
1cd70 73 69 6e 67 20 6f 66 66 73 65 74 6f 66 28 50 61 sing offsetof(Pa
1cd80 72 73 65 2c 6e 56 61 72 29 20 73 6f 20 74 68 65 rse,nVar) so the
1cd90 20 6e 56 61 72 20 66 69 65 6c 64 20 6d 75 73 74 nVar field must
1cda0 20 62 65 20 74 68 65 20 66 69 72 73 74 20 66 69 be the first fi
1cdb0 65 6c 64 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20 eld. ** in the
1cdc0 72 65 63 75 72 73 69 76 65 20 72 65 67 69 6f 6e recursive region
1cdd0 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .. ************
1cde0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1cdf0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ce00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ce10 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 ************/..
1ce20 20 69 6e 74 20 6e 56 61 72 3b 20 20 20 20 20 20 int nVar;
1ce30 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1ce40 6d 62 65 72 20 6f 66 20 27 3f 27 20 76 61 72 69 mber of '?' vari
1ce50 61 62 6c 65 73 20 73 65 65 6e 20 69 6e 20 74 68 ables seen in th
1ce60 65 20 53 51 4c 20 73 6f 20 66 61 72 20 2a 2f 0a e SQL so far */.
1ce70 20 20 69 6e 74 20 6e 7a 56 61 72 3b 20 20 20 20 int nzVar;
1ce80 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
1ce90 75 6d 62 65 72 20 6f 66 20 61 76 61 69 6c 61 62 umber of availab
1cea0 6c 65 20 73 6c 6f 74 73 20 69 6e 20 61 7a 56 61 le slots in azVa
1ceb0 72 5b 5d 20 2a 2f 0a 20 20 75 38 20 69 50 6b 53 r[] */. u8 iPkS
1cec0 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 ortOrder;
1ced0 20 20 20 2f 2a 20 41 53 43 20 6f 72 20 44 45 53 /* ASC or DES
1cee0 43 20 66 6f 72 20 49 4e 54 45 47 45 52 20 50 52 C for INTEGER PR
1cef0 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 75 IMARY KEY */. u
1cf00 38 20 62 46 72 65 65 57 69 74 68 3b 20 20 20 20 8 bFreeWith;
1cf10 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
1cf20 20 69 66 20 70 57 69 74 68 20 73 68 6f 75 6c 64 if pWith should
1cf30 20 62 65 20 66 72 65 65 64 20 77 69 74 68 20 70 be freed with p
1cf40 61 72 73 65 72 20 2a 2f 0a 20 20 75 38 20 65 78 arser */. u8 ex
1cf50 70 6c 61 69 6e 3b 20 20 20 20 20 20 20 20 20 20 plain;
1cf60 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1cf70 74 68 65 20 45 58 50 4c 41 49 4e 20 66 6c 61 67 the EXPLAIN flag
1cf80 20 69 73 20 66 6f 75 6e 64 20 6f 6e 20 74 68 65 is found on the
1cf90 20 71 75 65 72 79 20 2a 2f 0a 23 69 66 6e 64 65 query */.#ifnde
1cfa0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 f SQLITE_OMIT_VI
1cfb0 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 75 38 20 RTUALTABLE. u8
1cfc0 64 65 63 6c 61 72 65 56 74 61 62 3b 20 20 20 20 declareVtab;
1cfd0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
1cfe0 66 20 69 6e 73 69 64 65 20 73 71 6c 69 74 65 33 f inside sqlite3
1cff0 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 28 29 20 _declare_vtab()
1d000 2a 2f 0a 20 20 69 6e 74 20 6e 56 74 61 62 4c 6f */. int nVtabLo
1d010 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ck; /
1d020 2a 20 4e 75 6d 62 65 72 20 6f 66 20 76 69 72 74 * Number of virt
1d030 75 61 6c 20 74 61 62 6c 65 73 20 74 6f 20 6c 6f ual tables to lo
1d040 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 ck */.#endif. i
1d050 6e 74 20 6e 41 6c 69 61 73 3b 20 20 20 20 20 20 nt nAlias;
1d060 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1d070 65 72 20 6f 66 20 61 6c 69 61 73 65 64 20 72 65 er of aliased re
1d080 73 75 6c 74 20 73 65 74 20 63 6f 6c 75 6d 6e 73 sult set columns
1d090 20 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 */. int nHeigh
1d0a0 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
1d0b0 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 74 72 /* Expression tr
1d0c0 65 65 20 68 65 69 67 68 74 20 6f 66 20 63 75 72 ee height of cur
1d0d0 72 65 6e 74 20 73 75 62 2d 73 65 6c 65 63 74 20 rent sub-select
1d0e0 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
1d0f0 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 20 E_OMIT_EXPLAIN.
1d100 20 69 6e 74 20 69 53 65 6c 65 63 74 49 64 3b 20 int iSelectId;
1d110 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 44 /* ID
1d120 20 6f 66 20 63 75 72 72 65 6e 74 20 73 65 6c 65 of current sele
1d130 63 74 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f ct for EXPLAIN o
1d140 75 74 70 75 74 20 2a 2f 0a 20 20 69 6e 74 20 69 utput */. int i
1d150 4e 65 78 74 53 65 6c 65 63 74 49 64 3b 20 20 20 NextSelectId;
1d160 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 61 76 61 /* Next ava
1d170 69 6c 61 62 6c 65 20 73 65 6c 65 63 74 20 49 44 ilable select ID
1d180 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 for EXPLAIN out
1d190 70 75 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 put */.#endif.
1d1a0 63 68 61 72 20 2a 2a 61 7a 56 61 72 3b 20 20 20 char **azVar;
1d1b0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 /* Poi
1d1c0 6e 74 65 72 73 20 74 6f 20 6e 61 6d 65 73 20 6f nters to names o
1d1d0 66 20 70 61 72 61 6d 65 74 65 72 73 20 2a 2f 0a f parameters */.
1d1e0 20 20 56 64 62 65 20 2a 70 52 65 70 72 65 70 61 Vdbe *pReprepa
1d1f0 72 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 56 re; /* V
1d200 4d 20 62 65 69 6e 67 20 72 65 70 72 65 70 61 72 M being reprepar
1d210 65 64 20 28 73 71 6c 69 74 65 33 52 65 70 72 65 ed (sqlite3Repre
1d220 70 61 72 65 28 29 29 20 2a 2f 0a 20 20 63 6f 6e pare()) */. con
1d230 73 74 20 63 68 61 72 20 2a 7a 54 61 69 6c 3b 20 st char *zTail;
1d240 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 53 51 /* All SQ
1d250 4c 20 74 65 78 74 20 70 61 73 74 20 74 68 65 20 L text past the
1d260 6c 61 73 74 20 73 65 6d 69 63 6f 6c 6f 6e 20 70 last semicolon p
1d270 61 72 73 65 64 20 2a 2f 0a 20 20 54 61 62 6c 65 arsed */. Table
1d280 20 2a 70 4e 65 77 54 61 62 6c 65 3b 20 20 20 20 *pNewTable;
1d290 20 20 20 20 20 2f 2a 20 41 20 74 61 62 6c 65 20 /* A table
1d2a0 62 65 69 6e 67 20 63 6f 6e 73 74 72 75 63 74 65 being constructe
1d2b0 64 20 62 79 20 43 52 45 41 54 45 20 54 41 42 4c d by CREATE TABL
1d2c0 45 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a E */. Trigger *
1d2d0 70 4e 65 77 54 72 69 67 67 65 72 3b 20 20 20 20 pNewTrigger;
1d2e0 20 2f 2a 20 54 72 69 67 67 65 72 20 75 6e 64 65 /* Trigger unde
1d2f0 72 20 63 6f 6e 73 74 72 75 63 74 20 62 79 20 61 r construct by a
1d300 20 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20 CREATE TRIGGER
1d310 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
1d320 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 2f *zAuthContext; /
1d330 2a 20 54 68 65 20 36 74 68 20 70 61 72 61 6d 65 * The 6th parame
1d340 74 65 72 20 74 6f 20 64 62 2d 3e 78 41 75 74 68 ter to db->xAuth
1d350 20 63 61 6c 6c 62 61 63 6b 73 20 2a 2f 0a 20 20 callbacks */.
1d360 54 6f 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 6e Token sNameToken
1d370 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b ; /* Tok
1d380 65 6e 20 77 69 74 68 20 75 6e 71 75 61 6c 69 66 en with unqualif
1d390 69 65 64 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 ied schema objec
1d3a0 74 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 6f 6b 65 t name */. Toke
1d3b0 6e 20 73 4c 61 73 74 54 6f 6b 65 6e 3b 20 20 20 n sLastToken;
1d3c0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6c 61 73 /* The las
1d3d0 74 20 74 6f 6b 65 6e 20 70 61 72 73 65 64 20 2a t token parsed *
1d3e0 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
1d3f0 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
1d400 4c 45 0a 20 20 54 6f 6b 65 6e 20 73 41 72 67 3b LE. Token sArg;
1d410 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1d420 2a 20 43 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 * Complete text
1d430 6f 66 20 61 20 6d 6f 64 75 6c 65 20 61 72 67 75 of a module argu
1d440 6d 65 6e 74 20 2a 2f 0a 20 20 54 61 62 6c 65 20 ment */. Table
1d450 2a 2a 61 70 56 74 61 62 4c 6f 63 6b 3b 20 20 20 **apVtabLock;
1d460 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 /* Pointer t
1d470 6f 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 o virtual tables
1d480 20 6e 65 65 64 69 6e 67 20 6c 6f 63 6b 69 6e 67 needing locking
1d490 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 54 61 62 */.#endif. Tab
1d4a0 6c 65 20 2a 70 5a 6f 6d 62 69 65 54 61 62 3b 20 le *pZombieTab;
1d4b0 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f /* List o
1d4c0 66 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 f Table objects
1d4d0 74 6f 20 64 65 6c 65 74 65 20 61 66 74 65 72 20 to delete after
1d4e0 63 6f 64 65 20 67 65 6e 20 2a 2f 0a 20 20 54 72 code gen */. Tr
1d4f0 69 67 67 65 72 50 72 67 20 2a 70 54 72 69 67 67 iggerPrg *pTrigg
1d500 65 72 50 72 67 3b 20 20 2f 2a 20 4c 69 6e 6b 65 erPrg; /* Linke
1d510 64 20 6c 69 73 74 20 6f 66 20 63 6f 64 65 64 20 d list of coded
1d520 74 72 69 67 67 65 72 73 20 2a 2f 0a 20 20 57 69 triggers */. Wi
1d530 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 20 20 th *pWith;
1d540 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 /* Curre
1d550 6e 74 20 57 49 54 48 20 63 6c 61 75 73 65 2c 20 nt WITH clause,
1d560 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 7d 3b 0a 0a 2f or NULL */.};../
1d570 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 *.** Return true
1d580 20 69 66 20 63 75 72 72 65 6e 74 6c 79 20 69 6e if currently in
1d590 73 69 64 65 20 61 6e 20 73 71 6c 69 74 65 33 5f side an sqlite3_
1d5a0 64 65 63 6c 61 72 65 5f 76 74 61 62 28 29 20 63 declare_vtab() c
1d5b0 61 6c 6c 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 all..*/.#ifdef S
1d5c0 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 QLITE_OMIT_VIRTU
1d5d0 41 4c 54 41 42 4c 45 0a 20 20 23 64 65 66 69 6e ALTABLE. #defin
1d5e0 65 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 e IN_DECLARE_VTA
1d5f0 42 20 30 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 B 0.#else. #def
1d600 69 6e 65 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 ine IN_DECLARE_V
1d610 54 41 42 20 28 70 50 61 72 73 65 2d 3e 64 65 63 TAB (pParse->dec
1d620 6c 61 72 65 56 74 61 62 29 0a 23 65 6e 64 69 66 lareVtab).#endif
1d630 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 ../*.** An insta
1d640 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
1d650 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 wing structure c
1d660 61 6e 20 62 65 20 64 65 63 6c 61 72 65 64 20 6f an be declared o
1d670 6e 20 61 20 73 74 61 63 6b 20 61 6e 64 20 75 73 n a stack and us
1d680 65 64 0a 2a 2a 20 74 6f 20 73 61 76 65 20 74 68 ed.** to save th
1d690 65 20 50 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e e Parse.zAuthCon
1d6a0 74 65 78 74 20 76 61 6c 75 65 20 73 6f 20 74 68 text value so th
1d6b0 61 74 20 69 74 20 63 61 6e 20 62 65 20 72 65 73 at it can be res
1d6c0 74 6f 72 65 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a tored later..*/.
1d6d0 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e 74 65 struct AuthConte
1d6e0 78 74 20 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 xt {. const cha
1d6f0 72 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b r *zAuthContext;
1d700 20 20 20 2f 2a 20 50 75 74 20 73 61 76 65 64 20 /* Put saved
1d710 50 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 Parse.zAuthConte
1d720 78 74 20 68 65 72 65 20 2a 2f 0a 20 20 50 61 72 xt here */. Par
1d730 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 se *pParse;
1d740 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
1d750 50 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 Parse structure
1d760 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 */.};../*.** Bit
1d770 66 69 65 6c 64 20 66 6c 61 67 73 20 66 6f 72 20 field flags for
1d780 50 35 20 76 61 6c 75 65 20 69 6e 20 76 61 72 69 P5 value in vari
1d790 6f 75 73 20 6f 70 63 6f 64 65 73 2e 0a 2a 2f 0a ous opcodes..*/.
1d7a0 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e #define OPFLAG_N
1d7b0 43 48 41 4e 47 45 20 20 20 20 20 20 20 30 78 30 CHANGE 0x0
1d7c0 31 20 20 20 20 2f 2a 20 53 65 74 20 74 6f 20 75 1 /* Set to u
1d7d0 70 64 61 74 65 20 64 62 2d 3e 6e 43 68 61 6e 67 pdate db->nChang
1d7e0 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 e */.#define OPF
1d7f0 4c 41 47 5f 45 50 48 45 4d 20 20 20 20 20 20 20 LAG_EPHEM
1d800 20 20 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 0x01 /* OP_
1d810 43 6f 6c 75 6d 6e 3a 20 45 70 68 65 6d 65 72 61 Column: Ephemera
1d820 6c 20 6f 75 74 70 75 74 20 69 73 20 6f 6b 20 2a l output is ok *
1d830 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
1d840 5f 4c 41 53 54 52 4f 57 49 44 20 20 20 20 20 30 _LASTROWID 0
1d850 78 30 32 20 20 20 20 2f 2a 20 53 65 74 20 74 6f x02 /* Set to
1d860 20 75 70 64 61 74 65 20 64 62 2d 3e 6c 61 73 74 update db->last
1d870 52 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 Rowid */.#define
1d880 20 4f 50 46 4c 41 47 5f 49 53 55 50 44 41 54 45 OPFLAG_ISUPDATE
1d890 20 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a 0x04 /*
1d8a0 20 54 68 69 73 20 4f 50 5f 49 6e 73 65 72 74 20 This OP_Insert
1d8b0 69 73 20 61 6e 20 73 71 6c 20 55 50 44 41 54 45 is an sql UPDATE
1d8c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1d8d0 41 47 5f 41 50 50 45 4e 44 20 20 20 20 20 20 20 AG_APPEND
1d8e0 20 30 78 30 38 20 20 20 20 2f 2a 20 54 68 69 73 0x08 /* This
1d8f0 20 69 73 20 6c 69 6b 65 6c 79 20 74 6f 20 62 65 is likely to be
1d900 20 61 6e 20 61 70 70 65 6e 64 20 2a 2f 0a 23 64 an append */.#d
1d910 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 55 53 45 efine OPFLAG_USE
1d920 53 45 45 4b 52 45 53 55 4c 54 20 30 78 31 30 20 SEEKRESULT 0x10
1d930 20 20 20 2f 2a 20 54 72 79 20 74 6f 20 61 76 6f /* Try to avo
1d940 69 64 20 61 20 73 65 65 6b 20 69 6e 20 42 74 72 id a seek in Btr
1d950 65 65 49 6e 73 65 72 74 28 29 20 2a 2f 0a 23 64 eeInsert() */.#d
1d960 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4c 45 4e efine OPFLAG_LEN
1d970 47 54 48 41 52 47 20 20 20 20 20 30 78 34 30 20 GTHARG 0x40
1d980 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 /* OP_Column
1d990 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 6c 65 only used for le
1d9a0 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 66 69 6e ngth() */.#defin
1d9b0 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 e OPFLAG_TYPEOFA
1d9c0 52 47 20 20 20 20 20 30 78 38 30 20 20 20 20 2f RG 0x80 /
1d9d0 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 6e 6c 79 * OP_Column only
1d9e0 20 75 73 65 64 20 66 6f 72 20 74 79 70 65 6f 66 used for typeof
1d9f0 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 () */.#define OP
1da00 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 20 20 FLAG_BULKCSR
1da10 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 0x01 /* OP
1da20 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 74 6f 20 _Open** used to
1da30 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 73 6f 72 open bulk cursor
1da40 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1da50 41 47 5f 53 45 45 4b 45 51 20 20 20 20 20 20 20 AG_SEEKEQ
1da60 20 30 78 30 32 20 20 20 20 2f 2a 20 4f 50 5f 4f 0x02 /* OP_O
1da70 70 65 6e 2a 2a 20 63 75 72 73 6f 72 20 75 73 65 pen** cursor use
1da80 73 20 45 51 20 73 65 65 6b 20 6f 6e 6c 79 20 2a s EQ seek only *
1da90 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
1daa0 5f 50 32 49 53 52 45 47 20 20 20 20 20 20 20 30 _P2ISREG 0
1dab0 78 30 34 20 20 20 20 2f 2a 20 50 32 20 74 6f 20 x04 /* P2 to
1dac0 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 61 20 72 OP_Open** is a r
1dad0 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 20 2a egister number *
1dae0 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
1daf0 5f 50 45 52 4d 55 54 45 20 20 20 20 20 20 20 30 _PERMUTE 0
1db00 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6d x01 /* OP_Com
1db10 70 61 72 65 3a 20 75 73 65 20 74 68 65 20 70 65 pare: use the pe
1db20 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a 0a 2f 2a rmutation */../*
1db30 0a 20 2a 20 45 61 63 68 20 74 72 69 67 67 65 72 . * Each trigger
1db40 20 70 72 65 73 65 6e 74 20 69 6e 20 74 68 65 20 present in the
1db50 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 database schema
1db60 69 73 20 73 74 6f 72 65 64 20 61 73 20 61 6e 20 is stored as an
1db70 69 6e 73 74 61 6e 63 65 20 6f 66 0a 20 2a 20 73 instance of. * s
1db80 74 72 75 63 74 20 54 72 69 67 67 65 72 2e 20 0a truct Trigger. .
1db90 20 2a 0a 20 2a 20 50 6f 69 6e 74 65 72 73 20 74 *. * Pointers t
1dba0 6f 20 69 6e 73 74 61 6e 63 65 73 20 6f 66 20 73 o instances of s
1dbb0 74 72 75 63 74 20 54 72 69 67 67 65 72 20 61 72 truct Trigger ar
1dbc0 65 20 73 74 6f 72 65 64 20 69 6e 20 74 77 6f 20 e stored in two
1dbd0 77 61 79 73 2e 0a 20 2a 20 31 2e 20 49 6e 20 74 ways.. * 1. In t
1dbe0 68 65 20 22 74 72 69 67 48 61 73 68 22 20 68 61 he "trigHash" ha
1dbf0 73 68 20 74 61 62 6c 65 20 28 70 61 72 74 20 6f sh table (part o
1dc00 66 20 74 68 65 20 73 71 6c 69 74 65 33 2a 20 74 f the sqlite3* t
1dc10 68 61 74 20 72 65 70 72 65 73 65 6e 74 73 20 74 hat represents t
1dc20 68 65 20 0a 20 2a 20 20 20 20 64 61 74 61 62 61 he . * databa
1dc30 73 65 29 2e 20 54 68 69 73 20 61 6c 6c 6f 77 73 se). This allows
1dc40 20 54 72 69 67 67 65 72 20 73 74 72 75 63 74 75 Trigger structu
1dc50 72 65 73 20 74 6f 20 62 65 20 72 65 74 72 69 65 res to be retrie
1dc60 76 65 64 20 62 79 20 6e 61 6d 65 2e 0a 20 2a 20 ved by name.. *
1dc70 32 2e 20 41 6c 6c 20 74 72 69 67 67 65 72 73 20 2. All triggers
1dc80 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
1dc90 61 20 73 69 6e 67 6c 65 20 74 61 62 6c 65 20 66 a single table f
1dca0 6f 72 6d 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 orm a linked lis
1dcb0 74 2c 20 75 73 69 6e 67 20 74 68 65 0a 20 2a 20 t, using the. *
1dcc0 20 20 20 70 4e 65 78 74 20 6d 65 6d 62 65 72 20 pNext member
1dcd0 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 67 65 of struct Trigge
1dce0 72 2e 20 41 20 70 6f 69 6e 74 65 72 20 74 6f 20 r. A pointer to
1dcf0 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e the first elemen
1dd00 74 20 6f 66 20 74 68 65 0a 20 2a 20 20 20 20 6c t of the. * l
1dd10 69 6e 6b 65 64 20 6c 69 73 74 20 69 73 20 73 74 inked list is st
1dd20 6f 72 65 64 20 61 73 20 74 68 65 20 22 70 54 72 ored as the "pTr
1dd30 69 67 67 65 72 22 20 6d 65 6d 62 65 72 20 6f 66 igger" member of
1dd40 20 74 68 65 20 61 73 73 6f 63 69 61 74 65 64 0a the associated.
1dd50 20 2a 20 20 20 20 73 74 72 75 63 74 20 54 61 62 * struct Tab
1dd60 6c 65 2e 0a 20 2a 0a 20 2a 20 54 68 65 20 22 73 le.. *. * The "s
1dd70 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 tep_list" member
1dd80 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 20 66 points to the f
1dd90 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f 66 20 irst element of
1dda0 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 0a 20 2a a linked list. *
1ddb0 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 containing the
1ddc0 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 20 73 SQL statements s
1ddd0 70 65 63 69 66 69 65 64 20 61 73 20 74 68 65 20 pecified as the
1dde0 74 72 69 67 67 65 72 20 70 72 6f 67 72 61 6d 2e trigger program.
1ddf0 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 72 69 67 . */.struct Trig
1de00 67 65 72 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e ger {. char *zN
1de10 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
1de20 2f 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 74 /* The name of t
1de30 68 65 20 74 72 69 67 67 65 72 20 20 20 20 20 20 he trigger
1de40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1de50 20 20 2a 2f 0a 20 20 63 68 61 72 20 2a 74 61 62 */. char *tab
1de60 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f le; /
1de70 2a 20 54 68 65 20 74 61 62 6c 65 20 6f 72 20 76 * The table or v
1de80 69 65 77 20 74 6f 20 77 68 69 63 68 20 74 68 65 iew to which the
1de90 20 74 72 69 67 67 65 72 20 61 70 70 6c 69 65 73 trigger applies
1dea0 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 */. u8 op;
1deb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1dec0 20 4f 6e 65 20 6f 66 20 54 4b 5f 44 45 4c 45 54 One of TK_DELET
1ded0 45 2c 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b E, TK_UPDATE, TK
1dee0 5f 49 4e 53 45 52 54 20 20 20 20 20 20 20 20 20 _INSERT
1def0 2a 2f 0a 20 20 75 38 20 74 72 5f 74 6d 3b 20 20 */. u8 tr_tm;
1df00 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1df10 4f 6e 65 20 6f 66 20 54 52 49 47 47 45 52 5f 42 One of TRIGGER_B
1df20 45 46 4f 52 45 2c 20 54 52 49 47 47 45 52 5f 41 EFORE, TRIGGER_A
1df30 46 54 45 52 20 2a 2f 0a 20 20 45 78 70 72 20 2a FTER */. Expr *
1df40 70 57 68 65 6e 3b 20 20 20 20 20 20 20 20 20 20 pWhen;
1df50 20 20 2f 2a 20 54 68 65 20 57 48 45 4e 20 63 6c /* The WHEN cl
1df60 61 75 73 65 20 6f 66 20 74 68 65 20 65 78 70 72 ause of the expr
1df70 65 73 73 69 6f 6e 20 28 6d 61 79 20 62 65 20 4e ession (may be N
1df80 55 4c 4c 29 20 2a 2f 0a 20 20 49 64 4c 69 73 74 ULL) */. IdList
1df90 20 2a 70 43 6f 6c 75 6d 6e 73 3b 20 20 20 20 20 *pColumns;
1dfa0 20 20 2f 2a 20 49 66 20 74 68 69 73 20 69 73 20 /* If this is
1dfb0 61 6e 20 55 50 44 41 54 45 20 4f 46 20 3c 63 6f an UPDATE OF <co
1dfc0 6c 75 6d 6e 2d 6c 69 73 74 3e 20 74 72 69 67 67 lumn-list> trigg
1dfd0 65 72 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 er,.
1dfe0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1dff0 20 74 68 65 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 the <column-lis
1e000 74 3e 20 69 73 20 73 74 6f 72 65 64 20 68 65 72 t> is stored her
1e010 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 e */. Schema *p
1e020 53 63 68 65 6d 61 3b 20 20 20 20 20 20 20 20 2f Schema; /
1e030 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e * Schema contain
1e040 69 6e 67 20 74 68 65 20 74 72 69 67 67 65 72 20 ing the trigger
1e050 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 54 61 */. Schema *pTa
1e060 62 53 63 68 65 6d 61 3b 20 20 20 20 20 2f 2a 20 bSchema; /*
1e070 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 6e Schema containin
1e080 67 20 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 20 g the table */.
1e090 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 74 TriggerStep *st
1e0a0 65 70 5f 6c 69 73 74 3b 20 2f 2a 20 4c 69 6e 6b ep_list; /* Link
1e0b0 20 6c 69 73 74 20 6f 66 20 74 72 69 67 67 65 72 list of trigger
1e0c0 20 70 72 6f 67 72 61 6d 20 73 74 65 70 73 20 20 program steps
1e0d0 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 */.
1e0e0 54 72 69 67 67 65 72 20 2a 70 4e 65 78 74 3b 20 Trigger *pNext;
1e0f0 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 /* Next
1e100 74 72 69 67 67 65 72 20 61 73 73 6f 63 69 61 74 trigger associat
1e110 65 64 20 77 69 74 68 20 74 68 65 20 74 61 62 6c ed with the tabl
1e120 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 e */.};../*.** A
1e130 20 74 72 69 67 67 65 72 20 69 73 20 65 69 74 68 trigger is eith
1e140 65 72 20 61 20 42 45 46 4f 52 45 20 6f 72 20 61 er a BEFORE or a
1e150 6e 20 41 46 54 45 52 20 74 72 69 67 67 65 72 2e n AFTER trigger.
1e160 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 The following
1e170 63 6f 6e 73 74 61 6e 74 73 0a 2a 2a 20 64 65 74 constants.** det
1e180 65 72 6d 69 6e 65 20 77 68 69 63 68 2e 20 0a 2a ermine which. .*
1e190 2a 0a 2a 2a 20 49 66 20 74 68 65 72 65 20 61 72 *.** If there ar
1e1a0 65 20 6d 75 6c 74 69 70 6c 65 20 74 72 69 67 67 e multiple trigg
1e1b0 65 72 73 2c 20 79 6f 75 20 6d 69 67 68 74 20 6f ers, you might o
1e1c0 66 20 73 6f 6d 65 20 42 45 46 4f 52 45 20 61 6e f some BEFORE an
1e1d0 64 20 73 6f 6d 65 20 41 46 54 45 52 2e 0a 2a 2a d some AFTER..**
1e1e0 20 49 6e 20 74 68 61 74 20 63 61 73 65 73 2c 20 In that cases,
1e1f0 74 68 65 20 63 6f 6e 73 74 61 6e 74 73 20 62 65 the constants be
1e200 6c 6f 77 20 63 61 6e 20 62 65 20 4f 52 65 64 20 low can be ORed
1e210 74 6f 67 65 74 68 65 72 2e 0a 2a 2f 0a 23 64 65 together..*/.#de
1e220 66 69 6e 65 20 54 52 49 47 47 45 52 5f 42 45 46 fine TRIGGER_BEF
1e230 4f 52 45 20 20 31 0a 23 64 65 66 69 6e 65 20 54 ORE 1.#define T
1e240 52 49 47 47 45 52 5f 41 46 54 45 52 20 20 20 32 RIGGER_AFTER 2
1e250 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 6e 73 74 61 ../*. * An insta
1e260 6e 63 65 20 6f 66 20 73 74 72 75 63 74 20 54 72 nce of struct Tr
1e270 69 67 67 65 72 53 74 65 70 20 69 73 20 75 73 65 iggerStep is use
1e280 64 20 74 6f 20 73 74 6f 72 65 20 61 20 73 69 6e d to store a sin
1e290 67 6c 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e gle SQL statemen
1e2a0 74 0a 20 2a 20 74 68 61 74 20 69 73 20 61 20 70 t. * that is a p
1e2b0 61 72 74 20 6f 66 20 61 20 74 72 69 67 67 65 72 art of a trigger
1e2c0 2d 70 72 6f 67 72 61 6d 2e 20 0a 20 2a 0a 20 2a -program. . *. *
1e2d0 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 20 73 74 Instances of st
1e2e0 72 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 ruct TriggerStep
1e2f0 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 61 are stored in a
1e300 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 64 20 6c singly linked l
1e310 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 2a 20 75 ist (linked. * u
1e320 73 69 6e 67 20 74 68 65 20 22 70 4e 65 78 74 22 sing the "pNext"
1e330 20 6d 65 6d 62 65 72 29 20 72 65 66 65 72 65 6e member) referen
1e340 63 65 64 20 62 79 20 74 68 65 20 22 73 74 65 70 ced by the "step
1e350 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 20 6f 66 _list" member of
1e360 20 74 68 65 20 0a 20 2a 20 61 73 73 6f 63 69 61 the . * associa
1e370 74 65 64 20 73 74 72 75 63 74 20 54 72 69 67 67 ted struct Trigg
1e380 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 54 68 65 er instance. The
1e390 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f first element o
1e3a0 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 73 f the linked lis
1e3b0 74 20 69 73 0a 20 2a 20 74 68 65 20 66 69 72 73 t is. * the firs
1e3c0 74 20 73 74 65 70 20 6f 66 20 74 68 65 20 74 72 t step of the tr
1e3d0 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 0a 20 igger-program..
1e3e0 2a 20 0a 20 2a 20 54 68 65 20 22 6f 70 22 20 6d * . * The "op" m
1e3f0 65 6d 62 65 72 20 69 6e 64 69 63 61 74 65 73 20 ember indicates
1e400 77 68 65 74 68 65 72 20 74 68 69 73 20 69 73 20 whether this is
1e410 61 20 22 44 45 4c 45 54 45 22 2c 20 22 49 4e 53 a "DELETE", "INS
1e420 45 52 54 22 2c 20 22 55 50 44 41 54 45 22 20 6f ERT", "UPDATE" o
1e430 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 20 73 74 r. * "SELECT" st
1e440 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 6d 65 61 atement. The mea
1e450 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 6f 74 68 nings of the oth
1e460 65 72 20 6d 65 6d 62 65 72 73 20 69 73 20 64 65 er members is de
1e470 74 65 72 6d 69 6e 65 64 20 62 79 20 74 68 65 20 termined by the
1e480 0a 20 2a 20 76 61 6c 75 65 20 6f 66 20 22 6f 70 . * value of "op
1e490 22 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 20 2a " as follows:. *
1e4a0 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 49 4e . * (op == TK_IN
1e4b0 53 45 52 54 29 0a 20 2a 20 6f 72 63 6f 6e 66 20 SERT). * orconf
1e4c0 20 20 20 2d 3e 20 73 74 6f 72 65 73 20 74 68 65 -> stores the
1e4d0 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 61 6c 67 ON CONFLICT alg
1e4e0 6f 72 69 74 68 6d 0a 20 2a 20 70 53 65 6c 65 63 orithm. * pSelec
1e4f0 74 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 t -> If this i
1e500 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f s an INSERT INTO
1e510 20 2e 2e 2e 20 53 45 4c 45 43 54 20 2e 2e 2e 20 ... SELECT ...
1e520 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 0a statement, then.
1e530 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1e540 74 68 69 73 20 73 74 6f 72 65 73 20 61 20 70 6f this stores a po
1e550 69 6e 74 65 72 20 74 6f 20 74 68 65 20 53 45 4c inter to the SEL
1e560 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 4f ECT statement. O
1e570 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
1e580 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 * zTarget -> D
1e590 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 equoted name of
1e5a0 74 68 65 20 74 61 62 6c 65 20 74 6f 20 69 6e 73 the table to ins
1e5b0 65 72 74 20 69 6e 74 6f 2e 0a 20 2a 20 70 45 78 ert into.. * pEx
1e5c0 70 72 4c 69 73 74 20 2d 3e 20 49 66 20 74 68 69 prList -> If thi
1e5d0 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 s is an INSERT I
1e5e0 4e 54 4f 20 2e 2e 2e 20 56 41 4c 55 45 53 20 2e NTO ... VALUES .
1e5f0 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 .. statement, th
1e600 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 en. *
1e610 20 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 76 this stores v
1e620 61 6c 75 65 73 20 74 6f 20 62 65 20 69 6e 73 65 alues to be inse
1e630 72 74 65 64 2e 20 4f 74 68 65 72 77 69 73 65 20 rted. Otherwise
1e640 4e 55 4c 4c 2e 0a 20 2a 20 70 49 64 4c 69 73 74 NULL.. * pIdList
1e650 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 73 -> If this is
1e660 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 an INSERT INTO
1e670 2e 2e 2e 20 28 3c 63 6f 6c 75 6d 6e 2d 6e 61 6d ... (<column-nam
1e680 65 73 3e 29 20 56 41 4c 55 45 53 20 2e 2e 2e 20 es>) VALUES ...
1e690 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 . *
1e6a0 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e statement, then
1e6b0 20 74 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 this stores the
1e6c0 20 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 74 6f column-names to
1e6d0 20 62 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 be. *
1e6e0 20 20 20 20 69 6e 73 65 72 74 65 64 20 69 6e 74 inserted int
1e6f0 6f 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 o.. *. * (op ==
1e700 54 4b 5f 44 45 4c 45 54 45 29 0a 20 2a 20 7a 54 TK_DELETE). * zT
1e710 61 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f arget -> Dequo
1e720 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 ted name of the
1e730 74 61 62 6c 65 20 74 6f 20 64 65 6c 65 74 65 20 table to delete
1e740 66 72 6f 6d 2e 0a 20 2a 20 70 57 68 65 72 65 20 from.. * pWhere
1e750 20 20 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 -> The WHERE
1e760 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 44 45 clause of the DE
1e770 4c 45 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 LETE statement i
1e780 66 20 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 f one is specifi
1e790 65 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 ed.. *
1e7a0 20 20 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 Otherwise NU
1e7b0 4c 4c 2e 0a 20 2a 20 0a 20 2a 20 28 6f 70 20 3d LL.. * . * (op =
1e7c0 3d 20 54 4b 5f 55 50 44 41 54 45 29 0a 20 2a 20 = TK_UPDATE). *
1e7d0 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 65 71 zTarget -> Deq
1e7e0 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 uoted name of th
1e7f0 65 20 74 61 62 6c 65 20 74 6f 20 75 70 64 61 74 e table to updat
1e800 65 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 20 20 e.. * pWhere
1e810 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 -> The WHERE cla
1e820 75 73 65 20 6f 66 20 74 68 65 20 55 50 44 41 54 use of the UPDAT
1e830 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 20 6f E statement if o
1e840 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 64 2e ne is specified.
1e850 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 . *
1e860 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e Otherwise NULL.
1e870 0a 20 2a 20 70 45 78 70 72 4c 69 73 74 20 2d 3e . * pExprList ->
1e880 20 41 20 6c 69 73 74 20 6f 66 20 74 68 65 20 63 A list of the c
1e890 6f 6c 75 6d 6e 73 20 74 6f 20 75 70 64 61 74 65 olumns to update
1e8a0 20 61 6e 64 20 74 68 65 20 65 78 70 72 65 73 73 and the express
1e8b0 69 6f 6e 73 20 74 6f 20 75 70 64 61 74 65 0a 20 ions to update.
1e8c0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 * t
1e8d0 68 65 6d 20 74 6f 2e 20 53 65 65 20 73 71 6c 69 hem to. See sqli
1e8e0 74 65 33 55 70 64 61 74 65 28 29 20 64 6f 63 75 te3Update() docu
1e8f0 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 22 70 43 mentation of "pC
1e900 68 61 6e 67 65 73 22 0a 20 2a 20 20 20 20 20 20 hanges". *
1e910 20 20 20 20 20 20 20 20 61 72 67 75 6d 65 6e 74 argument
1e920 2e 0a 20 2a 20 0a 20 2a 2f 0a 73 74 72 75 63 74 .. * . */.struct
1e930 20 54 72 69 67 67 65 72 53 74 65 70 20 7b 0a 20 TriggerStep {.
1e940 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 u8 op;
1e950 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 /* One of
1e960 54 4b 5f 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 TK_DELETE, TK_UP
1e970 44 41 54 45 2c 20 54 4b 5f 49 4e 53 45 52 54 2c DATE, TK_INSERT,
1e980 20 54 4b 5f 53 45 4c 45 43 54 20 2a 2f 0a 20 20 TK_SELECT */.
1e990 75 38 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 u8 orconf;
1e9a0 20 20 20 20 20 2f 2a 20 4f 45 5f 52 6f 6c 6c 62 /* OE_Rollb
1e9b0 61 63 6b 20 65 74 63 2e 20 2a 2f 0a 20 20 54 72 ack etc. */. Tr
1e9c0 69 67 67 65 72 20 2a 70 54 72 69 67 3b 20 20 20 igger *pTrig;
1e9d0 20 20 20 2f 2a 20 54 68 65 20 74 72 69 67 67 65 /* The trigge
1e9e0 72 20 74 68 61 74 20 74 68 69 73 20 73 74 65 70 r that this step
1e9f0 20 69 73 20 61 20 70 61 72 74 20 6f 66 20 2a 2f is a part of */
1ea00 0a 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 . Select *pSele
1ea10 63 74 3b 20 20 20 20 20 2f 2a 20 53 45 4c 45 43 ct; /* SELEC
1ea20 54 20 73 74 61 74 65 6d 65 6e 74 20 6f 72 20 52 T statement or R
1ea30 48 53 20 6f 66 20 49 4e 53 45 52 54 20 49 4e 54 HS of INSERT INT
1ea40 4f 20 53 45 4c 45 43 54 20 2e 2e 2e 20 2a 2f 0a O SELECT ... */.
1ea50 20 20 63 68 61 72 20 2a 7a 54 61 72 67 65 74 3b char *zTarget;
1ea60 20 20 20 20 20 20 20 2f 2a 20 54 61 72 67 65 74 /* Target
1ea70 20 74 61 62 6c 65 20 66 6f 72 20 44 45 4c 45 54 table for DELET
1ea80 45 2c 20 55 50 44 41 54 45 2c 20 49 4e 53 45 52 E, UPDATE, INSER
1ea90 54 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 57 68 T */. Expr *pWh
1eaa0 65 72 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 ere; /* T
1eab0 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 he WHERE clause
1eac0 66 6f 72 20 44 45 4c 45 54 45 20 6f 72 20 55 50 for DELETE or UP
1ead0 44 41 54 45 20 73 74 65 70 73 20 2a 2f 0a 20 20 DATE steps */.
1eae0 45 78 70 72 4c 69 73 74 20 2a 70 45 78 70 72 4c ExprList *pExprL
1eaf0 69 73 74 3b 20 2f 2a 20 53 45 54 20 63 6c 61 75 ist; /* SET clau
1eb00 73 65 20 66 6f 72 20 55 50 44 41 54 45 2e 20 2a se for UPDATE. *
1eb10 2f 0a 20 20 49 64 4c 69 73 74 20 2a 70 49 64 4c /. IdList *pIdL
1eb20 69 73 74 3b 20 20 20 20 20 2f 2a 20 43 6f 6c 75 ist; /* Colu
1eb30 6d 6e 20 6e 61 6d 65 73 20 66 6f 72 20 49 4e 53 mn names for INS
1eb40 45 52 54 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 ERT */. Trigger
1eb50 53 74 65 70 20 2a 70 4e 65 78 74 3b 20 20 2f 2a Step *pNext; /*
1eb60 20 4e 65 78 74 20 69 6e 20 74 68 65 20 6c 69 6e Next in the lin
1eb70 6b 2d 6c 69 73 74 20 2a 2f 0a 20 20 54 72 69 67 k-list */. Trig
1eb80 67 65 72 53 74 65 70 20 2a 70 4c 61 73 74 3b 20 gerStep *pLast;
1eb90 20 2f 2a 20 4c 61 73 74 20 65 6c 65 6d 65 6e 74 /* Last element
1eba0 20 69 6e 20 6c 69 6e 6b 2d 6c 69 73 74 2e 20 56 in link-list. V
1ebb0 61 6c 69 64 20 66 6f 72 20 31 73 74 20 65 6c 65 alid for 1st ele
1ebc0 6d 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a m only */.};../*
1ebd0 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
1ebe0 67 20 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 g structure cont
1ebf0 61 69 6e 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e ains information
1ec00 20 75 73 65 64 20 62 79 20 74 68 65 20 73 71 6c used by the sql
1ec10 69 74 65 46 69 78 2e 2e 2e 0a 2a 2a 20 72 6f 75 iteFix....** rou
1ec20 74 69 6e 65 73 20 61 73 20 74 68 65 79 20 77 61 tines as they wa
1ec30 6c 6b 20 74 68 65 20 70 61 72 73 65 20 74 72 65 lk the parse tre
1ec40 65 20 74 6f 20 6d 61 6b 65 20 64 61 74 61 62 61 e to make databa
1ec50 73 65 20 72 65 66 65 72 65 6e 63 65 73 0a 2a 2a se references.**
1ec60 20 65 78 70 6c 69 63 69 74 2e 20 20 0a 2a 2f 0a explicit. .*/.
1ec70 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 44 typedef struct D
1ec80 62 46 69 78 65 72 20 44 62 46 69 78 65 72 3b 0a bFixer DbFixer;.
1ec90 73 74 72 75 63 74 20 44 62 46 69 78 65 72 20 7b struct DbFixer {
1eca0 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 73 65 . Parse *pParse
1ecb0 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 70 61 ; /* The pa
1ecc0 72 73 69 6e 67 20 63 6f 6e 74 65 78 74 2e 20 20 rsing context.
1ecd0 45 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 77 Error messages w
1ece0 72 69 74 74 65 6e 20 68 65 72 65 20 2a 2f 0a 20 ritten here */.
1ecf0 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 Schema *pSchema
1ed00 3b 20 20 20 20 2f 2a 20 46 69 78 20 69 74 65 6d ; /* Fix item
1ed10 73 20 74 6f 20 74 68 69 73 20 73 63 68 65 6d 61 s to this schema
1ed20 20 2a 2f 0a 20 20 69 6e 74 20 62 56 61 72 4f 6e */. int bVarOn
1ed30 6c 79 3b 20 20 20 20 20 20 20 2f 2a 20 43 68 65 ly; /* Che
1ed40 63 6b 20 66 6f 72 20 76 61 72 69 61 62 6c 65 20 ck for variable
1ed50 72 65 66 65 72 65 6e 63 65 73 20 6f 6e 6c 79 20 references only
1ed60 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
1ed70 2a 7a 44 62 3b 20 20 20 20 2f 2a 20 4d 61 6b 65 *zDb; /* Make
1ed80 20 73 75 72 65 20 61 6c 6c 20 6f 62 6a 65 63 74 sure all object
1ed90 73 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 s are contained
1eda0 69 6e 20 74 68 69 73 20 64 61 74 61 62 61 73 65 in this database
1edb0 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 */. const char
1edc0 20 2a 7a 54 79 70 65 3b 20 20 2f 2a 20 54 79 70 *zType; /* Typ
1edd0 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 69 6e e of the contain
1ede0 65 72 20 2d 20 75 73 65 64 20 66 6f 72 20 65 72 er - used for er
1edf0 72 6f 72 20 6d 65 73 73 61 67 65 73 20 2a 2f 0a ror messages */.
1ee00 20 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 20 2a 70 const Token *p
1ee10 4e 61 6d 65 3b 20 2f 2a 20 4e 61 6d 65 20 6f 66 Name; /* Name of
1ee20 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 20 2d the container -
1ee30 20 75 73 65 64 20 66 6f 72 20 65 72 72 6f 72 20 used for error
1ee40 6d 65 73 73 61 67 65 73 20 2a 2f 0a 7d 3b 0a 0a messages */.};..
1ee50 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 63 74 65 /*.** An objecte
1ee60 64 20 75 73 65 64 20 74 6f 20 61 63 63 75 6d 75 d used to accumu
1ee70 6c 61 74 65 20 74 68 65 20 74 65 78 74 20 6f 66 late the text of
1ee80 20 61 20 73 74 72 69 6e 67 20 77 68 65 72 65 20 a string where
1ee90 77 65 0a 2a 2a 20 64 6f 20 6e 6f 74 20 6e 65 63 we.** do not nec
1eea0 65 73 73 61 72 69 6c 79 20 6b 6e 6f 77 20 68 6f essarily know ho
1eeb0 77 20 62 69 67 20 74 68 65 20 73 74 72 69 6e 67 w big the string
1eec0 20 77 69 6c 6c 20 62 65 20 69 6e 20 74 68 65 20 will be in the
1eed0 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 end..*/.struct S
1eee0 74 72 41 63 63 75 6d 20 7b 0a 20 20 73 71 6c 69 trAccum {. sqli
1eef0 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 te3 *db;
1ef00 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 64 61 74 /* Optional dat
1ef10 61 62 61 73 65 20 66 6f 72 20 6c 6f 6f 6b 61 73 abase for lookas
1ef20 69 64 65 2e 20 20 43 61 6e 20 62 65 20 4e 55 4c ide. Can be NUL
1ef30 4c 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 42 61 L */. char *zBa
1ef40 73 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 se; /* A
1ef50 20 62 61 73 65 20 61 6c 6c 6f 63 61 74 69 6f 6e base allocation
1ef60 2e 20 20 4e 6f 74 20 66 72 6f 6d 20 6d 61 6c 6c . Not from mall
1ef70 6f 63 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a oc. */. char *z
1ef80 54 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a Text; /*
1ef90 20 54 68 65 20 73 74 72 69 6e 67 20 63 6f 6c 6c The string coll
1efa0 65 63 74 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a ected so far */.
1efb0 20 20 69 6e 74 20 20 6e 43 68 61 72 3b 20 20 20 int nChar;
1efc0 20 20 20 20 20 20 20 2f 2a 20 4c 65 6e 67 74 68 /* Length
1efd0 20 6f 66 20 74 68 65 20 73 74 72 69 6e 67 20 73 of the string s
1efe0 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 20 20 o far */. int
1eff0 6e 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 20 nAlloc;
1f000 2f 2a 20 41 6d 6f 75 6e 74 20 6f 66 20 73 70 61 /* Amount of spa
1f010 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 69 6e 20 ce allocated in
1f020 7a 54 65 78 74 20 2a 2f 0a 20 20 69 6e 74 20 20 zText */. int
1f030 6d 78 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 mxAlloc;
1f040 2f 2a 20 4d 61 78 69 6d 75 6d 20 61 6c 6c 6f 77 /* Maximum allow
1f050 65 64 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 ed allocation.
1f060 30 20 66 6f 72 20 6e 6f 20 6d 61 6c 6c 6f 63 20 0 for no malloc
1f070 75 73 61 67 65 20 2a 2f 0a 20 20 75 38 20 20 20 usage */. u8
1f080 61 63 63 45 72 72 6f 72 3b 20 20 20 20 20 20 20 accError;
1f090 2f 2a 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 /* STRACCUM_NOME
1f0a0 4d 20 6f 72 20 53 54 52 41 43 43 55 4d 5f 54 4f M or STRACCUM_TO
1f0b0 4f 42 49 47 20 2a 2f 0a 7d 3b 0a 23 64 65 66 69 OBIG */.};.#defi
1f0c0 6e 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 ne STRACCUM_NOME
1f0d0 4d 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 54 M 1.#define ST
1f0e0 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 20 32 RACCUM_TOOBIG 2
1f0f0 0a 0a 2f 2a 0a 2a 2a 20 41 20 70 6f 69 6e 74 65 ../*.** A pointe
1f100 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 r to this struct
1f110 75 72 65 20 69 73 20 75 73 65 64 20 74 6f 20 63 ure is used to c
1f120 6f 6d 6d 75 6e 69 63 61 74 65 20 69 6e 66 6f 72 ommunicate infor
1f130 6d 61 74 69 6f 6e 0a 2a 2a 20 66 72 6f 6d 20 73 mation.** from s
1f140 71 6c 69 74 65 33 49 6e 69 74 20 61 6e 64 20 4f qlite3Init and O
1f150 50 5f 50 61 72 73 65 53 63 68 65 6d 61 20 69 6e P_ParseSchema in
1f160 74 6f 20 74 68 65 20 73 71 6c 69 74 65 33 49 6e to the sqlite3In
1f170 69 74 43 61 6c 6c 62 61 63 6b 2e 0a 2a 2f 0a 74 itCallback..*/.t
1f180 79 70 65 64 65 66 20 73 74 72 75 63 74 20 7b 0a ypedef struct {.
1f190 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 sqlite3 *db;
1f1a0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 61 74 /* The dat
1f1b0 61 62 61 73 65 20 62 65 69 6e 67 20 69 6e 69 74 abase being init
1f1c0 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 63 68 61 ialized */. cha
1f1d0 72 20 2a 2a 70 7a 45 72 72 4d 73 67 3b 20 20 20 r **pzErrMsg;
1f1e0 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 67 /* Error messag
1f1f0 65 20 73 74 6f 72 65 64 20 68 65 72 65 20 2a 2f e stored here */
1f200 0a 20 20 69 6e 74 20 69 44 62 3b 20 20 20 20 20 . int iDb;
1f210 20 20 20 20 20 20 20 2f 2a 20 30 20 66 6f 72 20 /* 0 for
1f220 6d 61 69 6e 20 64 61 74 61 62 61 73 65 2e 20 20 main database.
1f230 31 20 66 6f 72 20 54 45 4d 50 2c 20 32 2e 2e 20 1 for TEMP, 2..
1f240 66 6f 72 20 41 54 54 41 43 48 65 64 20 2a 2f 0a for ATTACHed */.
1f250 20 20 69 6e 74 20 72 63 3b 20 20 20 20 20 20 20 int rc;
1f260 20 20 20 20 20 20 2f 2a 20 52 65 73 75 6c 74 20 /* Result
1f270 63 6f 64 65 20 73 74 6f 72 65 64 20 68 65 72 65 code stored here
1f280 20 2a 2f 0a 7d 20 49 6e 69 74 44 61 74 61 3b 0a */.} InitData;.
1f290 0a 2f 2a 0a 2a 2a 20 53 74 72 75 63 74 75 72 65 ./*.** Structure
1f2a0 20 63 6f 6e 74 61 69 6e 69 6e 67 20 67 6c 6f 62 containing glob
1f2b0 61 6c 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e al configuration
1f2c0 20 64 61 74 61 20 66 6f 72 20 74 68 65 20 53 51 data for the SQ
1f2d0 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 0a 2a 2a Lite library..**
1f2e0 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 .** This structu
1f2f0 72 65 20 61 6c 73 6f 20 63 6f 6e 74 61 69 6e 73 re also contains
1f300 20 73 6f 6d 65 20 73 74 61 74 65 20 69 6e 66 6f some state info
1f310 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 rmation..*/.stru
1f320 63 74 20 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 ct Sqlite3Config
1f330 20 7b 0a 20 20 69 6e 74 20 62 4d 65 6d 73 74 61 {. int bMemsta
1f340 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
1f350 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 /* True t
1f360 6f 20 65 6e 61 62 6c 65 20 6d 65 6d 6f 72 79 20 o enable memory
1f370 73 74 61 74 75 73 20 2a 2f 0a 20 20 69 6e 74 20 status */. int
1f380 62 43 6f 72 65 4d 75 74 65 78 3b 20 20 20 20 20 bCoreMutex;
1f390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1f3a0 20 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 True to enable
1f3b0 63 6f 72 65 20 6d 75 74 65 78 69 6e 67 20 2a 2f core mutexing */
1f3c0 0a 20 20 69 6e 74 20 62 46 75 6c 6c 4d 75 74 65 . int bFullMute
1f3d0 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 x;
1f3e0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 /* True to
1f3f0 65 6e 61 62 6c 65 20 66 75 6c 6c 20 6d 75 74 65 enable full mute
1f400 78 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 62 4f xing */. int bO
1f410 70 65 6e 55 72 69 3b 20 20 20 20 20 20 20 20 20 penUri;
1f420 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
1f430 72 75 65 20 74 6f 20 69 6e 74 65 72 70 72 65 74 rue to interpret
1f440 20 66 69 6c 65 6e 61 6d 65 73 20 61 73 20 55 52 filenames as UR
1f450 49 73 20 2a 2f 0a 20 20 69 6e 74 20 62 55 73 65 Is */. int bUse
1f460 43 69 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 Cis;
1f470 20 20 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 /* Use
1f480 20 63 6f 76 65 72 69 6e 67 20 69 6e 64 69 63 65 covering indice
1f490 73 20 66 6f 72 20 66 75 6c 6c 2d 73 63 61 6e 73 s for full-scans
1f4a0 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 53 74 72 6c */. int mxStrl
1f4b0 65 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 en;
1f4c0 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d /* Maxim
1f4d0 75 6d 20 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 um string length
1f4e0 20 2a 2f 0a 20 20 69 6e 74 20 6e 65 76 65 72 43 */. int neverC
1f4f0 6f 72 72 75 70 74 3b 20 20 20 20 20 20 20 20 20 orrupt;
1f500 20 20 20 20 20 20 20 20 2f 2a 20 44 61 74 61 62 /* Datab
1f510 61 73 65 20 69 73 20 61 6c 77 61 79 73 20 77 65 ase is always we
1f520 6c 6c 2d 66 6f 72 6d 65 64 20 2a 2f 0a 20 20 69 ll-formed */. i
1f530 6e 74 20 73 7a 4c 6f 6f 6b 61 73 69 64 65 3b 20 nt szLookaside;
1f540 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f550 20 2f 2a 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b /* Default look
1f560 61 73 69 64 65 20 62 75 66 66 65 72 20 73 69 7a aside buffer siz
1f570 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 6f 6f 6b e */. int nLook
1f580 61 73 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 aside;
1f590 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 /* Defa
1f5a0 75 6c 74 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 ult lookaside bu
1f5b0 66 66 65 72 20 63 6f 75 6e 74 20 2a 2f 0a 20 20 ffer count */.
1f5c0 73 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 sqlite3_mem_meth
1f5d0 6f 64 73 20 6d 3b 20 20 20 20 20 20 20 20 20 20 ods m;
1f5e0 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d /* Low-level m
1f5f0 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e emory allocation
1f600 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 interface */.
1f610 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 sqlite3_mutex_me
1f620 74 68 6f 64 73 20 2a 70 4d 75 74 65 78 3b 20 20 thods *pMutex;
1f630 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f 66 20 /* Address of
1f640 6d 75 74 65 78 20 6d 65 6d 62 65 72 20 6f 72 20 mutex member or
1f650 7a 65 72 6f 2e 20 2a 2f 0a 20 20 73 71 6c 69 74 zero. */. sqlit
1f660 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 e3_mutex_methods
1f670 20 6d 75 74 65 78 3b 20 20 20 20 20 20 2f 2a 20 mutex; /*
1f680 4c 6f 77 2d 6c 65 76 65 6c 20 6d 75 74 65 78 20 Low-level mutex
1f690 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 interface */. s
1f6a0 71 6c 69 74 65 33 5f 70 63 61 63 68 65 5f 6d 65 qlite3_pcache_me
1f6b0 74 68 6f 64 73 32 20 70 63 61 63 68 65 32 3b 20 thods2 pcache2;
1f6c0 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 70 61 /* Low-level pa
1f6d0 67 65 2d 63 61 63 68 65 20 69 6e 74 65 72 66 61 ge-cache interfa
1f6e0 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 48 ce */. void *pH
1f6f0 65 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 eap;
1f700 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 65 61 /* Hea
1f710 70 20 73 74 6f 72 61 67 65 20 73 70 61 63 65 20 p storage space
1f720 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 61 70 3b 20 */. int nHeap;
1f730 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f740 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f /* Size o
1f750 66 20 70 48 65 61 70 5b 5d 20 2a 2f 0a 20 20 69 f pHeap[] */. i
1f760 6e 74 20 6d 6e 52 65 71 2c 20 6d 78 52 65 71 3b nt mnReq, mxReq;
1f770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f780 20 2f 2a 20 4d 69 6e 20 61 6e 64 20 6d 61 78 20 /* Min and max
1f790 68 65 61 70 20 72 65 71 75 65 73 74 73 20 73 69 heap requests si
1f7a0 7a 65 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 zes */. sqlite3
1f7b0 5f 69 6e 74 36 34 20 73 7a 4d 6d 61 70 3b 20 20 _int64 szMmap;
1f7c0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6d 6d /* mm
1f7d0 61 70 28 29 20 73 70 61 63 65 20 70 65 72 20 6f ap() space per o
1f7e0 70 65 6e 20 66 69 6c 65 20 2a 2f 0a 20 20 73 71 pen file */. sq
1f7f0 6c 69 74 65 33 5f 69 6e 74 36 34 20 6d 78 4d 6d lite3_int64 mxMm
1f800 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ap;
1f810 2f 2a 20 4d 61 78 69 6d 75 6d 20 76 61 6c 75 65 /* Maximum value
1f820 20 66 6f 72 20 73 7a 4d 6d 61 70 20 2a 2f 0a 20 for szMmap */.
1f830 20 76 6f 69 64 20 2a 70 53 63 72 61 74 63 68 3b void *pScratch;
1f840 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f850 20 20 20 2f 2a 20 53 63 72 61 74 63 68 20 6d 65 /* Scratch me
1f860 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e 74 20 73 7a mory */. int sz
1f870 53 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 20 Scratch;
1f880 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
1f890 69 7a 65 20 6f 66 20 65 61 63 68 20 73 63 72 61 ize of each scra
1f8a0 74 63 68 20 62 75 66 66 65 72 20 2a 2f 0a 20 20 tch buffer */.
1f8b0 69 6e 74 20 6e 53 63 72 61 74 63 68 3b 20 20 20 int nScratch;
1f8c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f8d0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 /* Number of s
1f8e0 63 72 61 74 63 68 20 62 75 66 66 65 72 73 20 2a cratch buffers *
1f8f0 2f 0a 20 20 76 6f 69 64 20 2a 70 50 61 67 65 3b /. void *pPage;
1f900 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f910 20 20 20 20 20 20 2f 2a 20 50 61 67 65 20 63 61 /* Page ca
1f920 63 68 65 20 6d 65 6d 6f 72 79 20 2a 2f 0a 20 20 che memory */.
1f930 69 6e 74 20 73 7a 50 61 67 65 3b 20 20 20 20 20 int szPage;
1f940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f950 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 /* Size of eac
1f960 68 20 70 61 67 65 20 69 6e 20 70 50 61 67 65 5b h page in pPage[
1f970 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 50 61 67 65 ] */. int nPage
1f980 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1f990 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1f9a0 65 72 20 6f 66 20 70 61 67 65 73 20 69 6e 20 70 er of pages in p
1f9b0 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 Page[] */. int
1f9c0 6d 78 50 61 72 73 65 72 53 74 61 63 6b 3b 20 20 mxParserStack;
1f9d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1f9e0 20 6d 61 78 69 6d 75 6d 20 64 65 70 74 68 20 6f maximum depth o
1f9f0 66 20 74 68 65 20 70 61 72 73 65 72 20 73 74 61 f the parser sta
1fa00 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 73 68 61 72 ck */. int shar
1fa10 65 64 43 61 63 68 65 45 6e 61 62 6c 65 64 3b 20 edCacheEnabled;
1fa20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 74 72 75 /* tru
1fa30 65 20 69 66 20 73 68 61 72 65 64 2d 63 61 63 68 e if shared-cach
1fa40 65 20 6d 6f 64 65 20 65 6e 61 62 6c 65 64 20 2a e mode enabled *
1fa50 2f 0a 20 20 75 33 32 20 73 7a 50 6d 61 3b 20 20 /. u32 szPma;
1fa60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fa70 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d /* Maximum
1fa80 20 53 6f 72 74 65 72 20 50 4d 41 20 73 69 7a 65 Sorter PMA size
1fa90 20 2a 2f 0a 20 20 2f 2a 20 54 68 65 20 61 62 6f */. /* The abo
1faa0 76 65 20 6d 69 67 68 74 20 62 65 20 69 6e 69 74 ve might be init
1fab0 69 61 6c 69 7a 65 64 20 74 6f 20 6e 6f 6e 2d 7a ialized to non-z
1fac0 65 72 6f 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 ero. The follow
1fad0 69 6e 67 20 6e 65 65 64 20 74 6f 20 61 6c 77 61 ing need to alwa
1fae0 79 73 0a 20 20 2a 2a 20 69 6e 69 74 69 61 6c 6c ys. ** initiall
1faf0 79 20 62 65 20 7a 65 72 6f 2c 20 68 6f 77 65 76 y be zero, howev
1fb00 65 72 2e 20 2a 2f 0a 20 20 69 6e 74 20 69 73 49 er. */. int isI
1fb10 6e 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 nit;
1fb20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1fb30 75 65 20 61 66 74 65 72 20 69 6e 69 74 69 61 6c ue after initial
1fb40 69 7a 61 74 69 6f 6e 20 68 61 73 20 66 69 6e 69 ization has fini
1fb50 73 68 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 6e shed */. int in
1fb60 50 72 6f 67 72 65 73 73 3b 20 20 20 20 20 20 20 Progress;
1fb70 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
1fb80 72 75 65 20 77 68 69 6c 65 20 69 6e 69 74 69 61 rue while initia
1fb90 6c 69 7a 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 lization in prog
1fba0 72 65 73 73 20 2a 2f 0a 20 20 69 6e 74 20 69 73 ress */. int is
1fbb0 4d 75 74 65 78 49 6e 69 74 3b 20 20 20 20 20 20 MutexInit;
1fbc0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
1fbd0 72 75 65 20 61 66 74 65 72 20 6d 75 74 65 78 65 rue after mutexe
1fbe0 73 20 61 72 65 20 69 6e 69 74 69 61 6c 69 7a 65 s are initialize
1fbf0 64 20 2a 2f 0a 20 20 69 6e 74 20 69 73 4d 61 6c d */. int isMal
1fc00 6c 6f 63 49 6e 69 74 3b 20 20 20 20 20 20 20 20 locInit;
1fc10 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
1fc20 20 61 66 74 65 72 20 6d 61 6c 6c 6f 63 20 69 73 after malloc is
1fc30 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
1fc40 20 20 69 6e 74 20 69 73 50 43 61 63 68 65 49 6e int isPCacheIn
1fc50 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 it;
1fc60 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 /* True afte
1fc70 72 20 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 r malloc is init
1fc80 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 ialized */. int
1fc90 20 6e 52 65 66 49 6e 69 74 4d 75 74 65 78 3b 20 nRefInitMutex;
1fca0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1fcb0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 72 * Number of user
1fcc0 73 20 6f 66 20 70 49 6e 69 74 4d 75 74 65 78 20 s of pInitMutex
1fcd0 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 */. sqlite3_mut
1fce0 65 78 20 2a 70 49 6e 69 74 4d 75 74 65 78 3b 20 ex *pInitMutex;
1fcf0 20 20 20 20 20 20 20 2f 2a 20 4d 75 74 65 78 20 /* Mutex
1fd00 75 73 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f used by sqlite3_
1fd10 69 6e 69 74 69 61 6c 69 7a 65 28 29 20 2a 2f 0a initialize() */.
1fd20 20 20 76 6f 69 64 20 28 2a 78 4c 6f 67 29 28 76 void (*xLog)(v
1fd30 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 oid*,int,const c
1fd40 68 61 72 2a 29 3b 20 2f 2a 20 46 75 6e 63 74 69 har*); /* Functi
1fd50 6f 6e 20 66 6f 72 20 6c 6f 67 67 69 6e 67 20 2a on for logging *
1fd60 2f 0a 20 20 76 6f 69 64 20 2a 70 4c 6f 67 41 72 /. void *pLogAr
1fd70 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
1fd80 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
1fd90 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 4c t argument to xL
1fda0 6f 67 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 og() */.#ifdef S
1fdb0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 51 4c QLITE_ENABLE_SQL
1fdc0 4c 4f 47 0a 20 20 76 6f 69 64 28 2a 78 53 71 6c LOG. void(*xSql
1fdd0 6c 6f 67 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 log)(void*,sqlit
1fde0 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c e3*,const char*,
1fdf0 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 int);. void *p
1fe00 53 71 6c 6c 6f 67 41 72 67 3b 0a 23 65 6e 64 69 SqllogArg;.#endi
1fe10 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f f.#ifdef SQLITE_
1fe20 56 44 42 45 5f 43 4f 56 45 52 41 47 45 0a 20 20 VDBE_COVERAGE.
1fe30 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 /* The following
1fe40 20 63 61 6c 6c 62 61 63 6b 20 28 69 66 20 6e 6f callback (if no
1fe50 74 20 4e 55 4c 4c 29 20 69 73 20 69 6e 76 6f 6b t NULL) is invok
1fe60 65 64 20 6f 6e 20 65 76 65 72 79 20 56 44 42 45 ed on every VDBE
1fe70 20 62 72 61 6e 63 68 0a 20 20 2a 2a 20 6f 70 65 branch. ** ope
1fe80 72 61 74 69 6f 6e 2e 20 20 53 65 74 20 74 68 65 ration. Set the
1fe90 20 63 61 6c 6c 62 61 63 6b 20 75 73 69 6e 67 20 callback using
1fea0 53 51 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f SQLITE_TESTCTRL_
1feb0 56 44 42 45 5f 43 4f 56 45 52 41 47 45 2e 0a 20 VDBE_COVERAGE..
1fec0 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 56 64 */. void (*xVd
1fed0 62 65 42 72 61 6e 63 68 29 28 76 6f 69 64 2a 2c beBranch)(void*,
1fee0 69 6e 74 20 69 53 72 63 4c 69 6e 65 2c 75 38 20 int iSrcLine,u8
1fef0 65 54 68 69 73 2c 75 38 20 65 4d 78 29 3b 20 20 eThis,u8 eMx);
1ff00 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 /* Callback */.
1ff10 20 76 6f 69 64 20 2a 70 56 64 62 65 42 72 61 6e void *pVdbeBran
1ff20 63 68 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 chArg;
1ff30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ff40 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 73 /* 1s
1ff50 74 20 61 72 67 75 6d 65 6e 74 20 2a 2f 0a 23 65 t argument */.#e
1ff60 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
1ff70 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e ITE_OMIT_BUILTIN
1ff80 5f 54 45 53 54 0a 20 20 69 6e 74 20 28 2a 78 54 _TEST. int (*xT
1ff90 65 73 74 43 61 6c 6c 62 61 63 6b 29 28 69 6e 74 estCallback)(int
1ffa0 29 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 76 ); /* Inv
1ffb0 6f 6b 65 64 20 62 79 20 73 71 6c 69 74 65 33 46 oked by sqlite3F
1ffc0 61 75 6c 74 53 69 6d 28 29 20 2a 2f 0a 23 65 6e aultSim() */.#en
1ffd0 64 69 66 0a 20 20 69 6e 74 20 62 4c 6f 63 61 6c dif. int bLocal
1ffe0 74 69 6d 65 46 61 75 6c 74 3b 20 20 20 20 20 20 timeFault;
1fff0 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
20000 74 6f 20 66 61 69 6c 20 6c 6f 63 61 6c 74 69 6d to fail localtim
20010 65 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 7d 3b 0a e() calls */.};.
20020 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 6d 61 63 72 ./*.** This macr
20030 6f 20 69 73 20 75 73 65 64 20 69 6e 73 69 64 65 o is used inside
20040 20 6f 66 20 61 73 73 65 72 74 28 29 20 73 74 61 of assert() sta
20050 74 65 6d 65 6e 74 73 20 74 6f 20 69 6e 64 69 63 tements to indic
20060 61 74 65 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 ate that.** the
20070 61 73 73 65 72 74 20 69 73 20 6f 6e 6c 79 20 76 assert is only v
20080 61 6c 69 64 20 6f 6e 20 61 20 77 65 6c 6c 2d 66 alid on a well-f
20090 6f 72 6d 65 64 20 64 61 74 61 62 61 73 65 2e 20 ormed database.
200a0 20 49 6e 73 74 65 61 64 20 6f 66 3a 0a 2a 2a 0a Instead of:.**.
200b0 2a 2a 20 20 20 20 20 61 73 73 65 72 74 28 20 58 ** assert( X
200c0 20 29 3b 0a 2a 2a 0a 2a 2a 20 4f 6e 65 20 77 72 );.**.** One wr
200d0 69 74 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ites:.**.**
200e0 61 73 73 65 72 74 28 20 58 20 7c 7c 20 43 4f 52 assert( X || COR
200f0 52 55 50 54 5f 44 42 20 29 3b 0a 2a 2a 0a 2a 2a RUPT_DB );.**.**
20100 20 43 4f 52 52 55 50 54 5f 44 42 20 69 73 20 74 CORRUPT_DB is t
20110 72 75 65 20 64 75 72 69 6e 67 20 6e 6f 72 6d 61 rue during norma
20120 6c 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 43 4f l operation. CO
20130 52 52 55 50 54 5f 44 42 20 64 6f 65 73 20 6e 6f RRUPT_DB does no
20140 74 20 69 6e 64 69 63 61 74 65 0a 2a 2a 20 74 68 t indicate.** th
20150 61 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 at the database
20160 69 73 20 64 65 66 69 6e 69 74 65 6c 79 20 63 6f is definitely co
20170 72 72 75 70 74 2c 20 6f 6e 6c 79 20 74 68 61 74 rrupt, only that
20180 20 69 74 20 6d 69 67 68 74 20 62 65 20 63 6f 72 it might be cor
20190 72 75 70 74 2e 0a 2a 2a 20 46 6f 72 20 6d 6f 73 rupt..** For mos
201a0 74 20 74 65 73 74 20 63 61 73 65 73 2c 20 43 4f t test cases, CO
201b0 52 52 55 50 54 5f 44 42 20 69 73 20 73 65 74 20 RRUPT_DB is set
201c0 74 6f 20 66 61 6c 73 65 20 75 73 69 6e 67 20 61 to false using a
201d0 20 73 70 65 63 69 61 6c 0a 2a 2a 20 73 71 6c 69 special.** sqli
201e0 74 65 33 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c te3_test_control
201f0 28 29 2e 20 20 54 68 69 73 20 65 6e 61 62 6c 65 (). This enable
20200 73 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 s assert() state
20210 6d 65 6e 74 73 20 74 6f 20 70 72 6f 76 65 0a 2a ments to prove.*
20220 2a 20 74 68 69 6e 67 73 20 74 68 61 74 20 61 72 * things that ar
20230 65 20 61 6c 77 61 79 73 20 74 72 75 65 20 66 6f e always true fo
20240 72 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 r well-formed da
20250 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 64 65 66 tabases..*/.#def
20260 69 6e 65 20 43 4f 52 52 55 50 54 5f 44 42 20 20 ine CORRUPT_DB
20270 28 73 71 6c 69 74 65 33 43 6f 6e 66 69 67 2e 6e (sqlite3Config.n
20280 65 76 65 72 43 6f 72 72 75 70 74 3d 3d 30 29 0a everCorrupt==0).
20290 0a 2f 2a 0a 2a 2a 20 43 6f 6e 74 65 78 74 20 70 ./*.** Context p
202a0 6f 69 6e 74 65 72 20 70 61 73 73 65 64 20 64 6f ointer passed do
202b0 77 6e 20 74 68 72 6f 75 67 68 20 74 68 65 20 74 wn through the t
202c0 72 65 65 2d 77 61 6c 6b 2e 0a 2a 2f 0a 73 74 72 ree-walk..*/.str
202d0 75 63 74 20 57 61 6c 6b 65 72 20 7b 0a 20 20 69 uct Walker {. i
202e0 6e 74 20 28 2a 78 45 78 70 72 43 61 6c 6c 62 61 nt (*xExprCallba
202f0 63 6b 29 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 ck)(Walker*, Exp
20300 72 2a 29 3b 20 20 20 20 20 2f 2a 20 43 61 6c 6c r*); /* Call
20310 62 61 63 6b 20 66 6f 72 20 65 78 70 72 65 73 73 back for express
20320 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 28 2a ions */. int (*
20330 78 53 65 6c 65 63 74 43 61 6c 6c 62 61 63 6b 29 xSelectCallback)
20340 28 57 61 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a (Walker*,Select*
20350 29 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 ); /* Callback
20360 66 6f 72 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 for SELECTs */.
20370 20 76 6f 69 64 20 28 2a 78 53 65 6c 65 63 74 43 void (*xSelectC
20380 61 6c 6c 62 61 63 6b 32 29 28 57 61 6c 6b 65 72 allback2)(Walker
20390 2a 2c 53 65 6c 65 63 74 2a 29 3b 2f 2a 20 53 65 *,Select*);/* Se
203a0 63 6f 6e 64 20 63 61 6c 6c 62 61 63 6b 20 66 6f cond callback fo
203b0 72 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 50 r SELECTs */. P
203c0 61 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 arse *pParse;
203d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
203e0 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 73 /* Pars
203f0 65 72 20 63 6f 6e 74 65 78 74 2e 20 20 2a 2f 0a er context. */.
20400 20 20 69 6e 74 20 77 61 6c 6b 65 72 44 65 70 74 int walkerDept
20410 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 h;
20420 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
20430 75 6d 62 65 72 20 6f 66 20 73 75 62 71 75 65 72 umber of subquer
20440 69 65 73 20 2a 2f 0a 20 20 75 38 20 65 43 6f 64 ies */. u8 eCod
20450 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
20460 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20470 20 20 20 2f 2a 20 41 20 73 6d 61 6c 6c 20 70 72 /* A small pr
20480 6f 63 65 73 73 69 6e 67 20 63 6f 64 65 20 2a 2f ocessing code */
20490 0a 20 20 75 6e 69 6f 6e 20 7b 20 20 20 20 20 20 . union {
204a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
204b0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
204c0 45 78 74 72 61 20 64 61 74 61 20 66 6f 72 20 63 Extra data for c
204d0 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 20 20 4e allback */. N
204e0 61 6d 65 43 6f 6e 74 65 78 74 20 2a 70 4e 43 3b ameContext *pNC;
204f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20500 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d /* Nam
20510 69 6e 67 20 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 ing context */.
20520 20 20 20 69 6e 74 20 6e 3b 20 20 20 20 20 20 20 int n;
20530 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20540 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
20550 20 41 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 20 20 A counter */.
20560 20 20 69 6e 74 20 69 43 75 72 3b 20 20 20 20 20 int iCur;
20570 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20580 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
20590 41 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 A cursor number
205a0 2a 2f 0a 20 20 20 20 53 72 63 4c 69 73 74 20 2a */. SrcList *
205b0 70 53 72 63 4c 69 73 74 3b 20 20 20 20 20 20 20 pSrcList;
205c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
205d0 20 20 2f 2a 20 46 52 4f 4d 20 63 6c 61 75 73 65 /* FROM clause
205e0 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 74 20 53 */. struct S
205f0 72 63 43 6f 75 6e 74 20 2a 70 53 72 63 43 6f 75 rcCount *pSrcCou
20600 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nt;
20610 20 20 20 2f 2a 20 43 6f 75 6e 74 69 6e 67 20 63 /* Counting c
20620 6f 6c 75 6d 6e 20 72 65 66 65 72 65 6e 63 65 73 olumn references
20630 20 2a 2f 0a 20 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f */. } u;.};../
20640 2a 20 46 6f 72 77 61 72 64 20 64 65 63 6c 61 72 * Forward declar
20650 61 74 69 6f 6e 73 20 2a 2f 0a 69 6e 74 20 73 71 ations */.int sq
20660 6c 69 74 65 33 57 61 6c 6b 45 78 70 72 28 57 61 lite3WalkExpr(Wa
20670 6c 6b 65 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 lker*, Expr*);.i
20680 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 nt sqlite3WalkEx
20690 70 72 4c 69 73 74 28 57 61 6c 6b 65 72 2a 2c 20 prList(Walker*,
206a0 45 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 ExprList*);.int
206b0 73 71 6c 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 sqlite3WalkSelec
206c0 74 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 t(Walker*, Selec
206d0 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
206e0 57 61 6c 6b 53 65 6c 65 63 74 45 78 70 72 28 57 WalkSelectExpr(W
206f0 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 alker*, Select*)
20700 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c ;.int sqlite3Wal
20710 6b 53 65 6c 65 63 74 46 72 6f 6d 28 57 61 6c 6b kSelectFrom(Walk
20720 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 0a er*, Select*);..
20730 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 63 6f 64 /*.** Return cod
20740 65 20 66 72 6f 6d 20 74 68 65 20 70 61 72 73 65 e from the parse
20750 2d 74 72 65 65 20 77 61 6c 6b 69 6e 67 20 70 72 -tree walking pr
20760 69 6d 69 74 69 76 65 73 20 61 6e 64 20 74 68 65 imitives and the
20770 69 72 0a 2a 2a 20 63 61 6c 6c 62 61 63 6b 73 2e ir.** callbacks.
20780 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 57 52 43 5f .*/.#define WRC_
20790 43 6f 6e 74 69 6e 75 65 20 20 20 20 30 20 20 20 Continue 0
207a0 2f 2a 20 43 6f 6e 74 69 6e 75 65 20 64 6f 77 6e /* Continue down
207b0 20 69 6e 74 6f 20 63 68 69 6c 64 72 65 6e 20 2a into children *
207c0 2f 0a 23 64 65 66 69 6e 65 20 57 52 43 5f 50 72 /.#define WRC_Pr
207d0 75 6e 65 20 20 20 20 20 20 20 31 20 20 20 2f 2a une 1 /*
207e0 20 4f 6d 69 74 20 63 68 69 6c 64 72 65 6e 20 62 Omit children b
207f0 75 74 20 63 6f 6e 74 69 6e 75 65 20 77 61 6c 6b ut continue walk
20800 69 6e 67 20 73 69 62 6c 69 6e 67 73 20 2a 2f 0a ing siblings */.
20810 23 64 65 66 69 6e 65 20 57 52 43 5f 41 62 6f 72 #define WRC_Abor
20820 74 20 20 20 20 20 20 20 32 20 20 20 2f 2a 20 41 t 2 /* A
20830 62 61 6e 64 6f 6e 20 74 68 65 20 74 72 65 65 20 bandon the tree
20840 77 61 6c 6b 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 walk */../*.** A
20850 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
20860 69 73 20 73 74 72 75 63 74 75 72 65 20 72 65 70 is structure rep
20870 72 65 73 65 6e 74 73 20 61 20 73 65 74 20 6f 66 resents a set of
20880 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 43 54 45 one or more CTE
20890 73 0a 2a 2a 20 28 63 6f 6d 6d 6f 6e 20 74 61 62 s.** (common tab
208a0 6c 65 20 65 78 70 72 65 73 73 69 6f 6e 73 29 20 le expressions)
208b0 63 72 65 61 74 65 64 20 62 79 20 61 20 73 69 6e created by a sin
208c0 67 6c 65 20 57 49 54 48 20 63 6c 61 75 73 65 2e gle WITH clause.
208d0 0a 2a 2f 0a 73 74 72 75 63 74 20 57 69 74 68 20 .*/.struct With
208e0 7b 0a 20 20 69 6e 74 20 6e 43 74 65 3b 20 20 20 {. int nCte;
208f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20900 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
20910 20 43 54 45 73 20 69 6e 20 74 68 65 20 57 49 54 CTEs in the WIT
20920 48 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 57 69 H clause */. Wi
20930 74 68 20 2a 70 4f 75 74 65 72 3b 20 20 20 20 20 th *pOuter;
20940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
20950 20 43 6f 6e 74 61 69 6e 69 6e 67 20 57 49 54 48 Containing WITH
20960 20 63 6c 61 75 73 65 2c 20 6f 72 20 4e 55 4c 4c clause, or NULL
20970 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 43 74 65 */. struct Cte
20980 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
20990 20 20 20 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 /* For eac
209a0 68 20 43 54 45 20 69 6e 20 74 68 65 20 57 49 54 h CTE in the WIT
209b0 48 20 63 6c 61 75 73 65 2e 2e 2e 2e 20 2a 2f 0a H clause.... */.
209c0 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b char *zName;
209d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
209e0 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 /* Name of t
209f0 68 69 73 20 43 54 45 20 2a 2f 0a 20 20 20 20 45 his CTE */. E
20a00 78 70 72 4c 69 73 74 20 2a 70 43 6f 6c 73 3b 20 xprList *pCols;
20a10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
20a20 2a 20 4c 69 73 74 20 6f 66 20 65 78 70 6c 69 63 * List of explic
20a30 69 74 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 2c it column names,
20a40 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 20 20 20 20 or NULL */.
20a50 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b Select *pSelect;
20a60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20a70 2f 2a 20 54 68 65 20 64 65 66 69 6e 69 74 69 6f /* The definitio
20a80 6e 20 6f 66 20 74 68 69 73 20 43 54 45 20 2a 2f n of this CTE */
20a90 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
20aa0 2a 7a 43 74 65 45 72 72 3b 20 20 20 20 20 20 20 *zCteErr;
20ab0 20 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 /* Error me
20ac0 73 73 61 67 65 20 66 6f 72 20 63 69 72 63 75 6c ssage for circul
20ad0 61 72 20 72 65 66 65 72 65 6e 63 65 73 20 2a 2f ar references */
20ae0 0a 20 20 7d 20 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 . } a[1];.};..#
20af0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
20b00 55 47 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 UG./*.** An inst
20b10 61 6e 63 65 20 6f 66 20 74 68 65 20 54 72 65 65 ance of the Tree
20b20 56 69 65 77 20 6f 62 6a 65 63 74 20 69 73 20 75 View object is u
20b30 73 65 64 20 66 6f 72 20 70 72 69 6e 74 69 6e 67 sed for printing
20b40 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 0a the content of.
20b50 2a 2a 20 64 61 74 61 20 73 74 72 75 63 74 75 72 ** data structur
20b60 65 73 20 6f 6e 20 73 71 6c 69 74 65 33 44 65 62 es on sqlite3Deb
20b70 75 67 50 72 69 6e 74 66 28 29 20 75 73 69 6e 67 ugPrintf() using
20b80 20 61 20 74 72 65 65 2d 6c 69 6b 65 20 76 69 65 a tree-like vie
20b90 77 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 72 65 w..*/.struct Tre
20ba0 65 56 69 65 77 20 7b 0a 20 20 69 6e 74 20 69 4c eView {. int iL
20bb0 65 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 evel;
20bc0 20 20 2f 2a 20 57 68 69 63 68 20 6c 65 76 65 6c /* Which level
20bd0 20 6f 66 20 74 68 65 20 74 72 65 65 20 77 65 20 of the tree we
20be0 61 72 65 20 6f 6e 20 2a 2f 0a 20 20 75 38 20 20 are on */. u8
20bf0 62 4c 69 6e 65 5b 31 30 30 5d 3b 20 20 20 20 20 bLine[100];
20c00 20 20 20 20 2f 2a 20 44 72 61 77 20 76 65 72 74 /* Draw vert
20c10 69 63 61 6c 20 69 6e 20 63 6f 6c 75 6d 6e 20 69 ical in column i
20c20 20 69 66 20 62 4c 69 6e 65 5b 69 5d 20 69 73 20 if bLine[i] is
20c30 74 72 75 65 20 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 true */.};.#endi
20c40 66 20 2f 2a 20 53 51 4c 49 54 45 5f 44 45 42 55 f /* SQLITE_DEBU
20c50 47 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 75 G */../*.** Assu
20c60 6d 69 6e 67 20 7a 49 6e 20 70 6f 69 6e 74 73 20 ming zIn points
20c70 74 6f 20 74 68 65 20 66 69 72 73 74 20 62 79 74 to the first byt
20c80 65 20 6f 66 20 61 20 55 54 46 2d 38 20 63 68 61 e of a UTF-8 cha
20c90 72 61 63 74 65 72 2c 0a 2a 2a 20 61 64 76 61 6e racter,.** advan
20ca0 63 65 20 7a 49 6e 20 74 6f 20 70 6f 69 6e 74 20 ce zIn to point
20cb0 74 6f 20 74 68 65 20 66 69 72 73 74 20 62 79 74 to the first byt
20cc0 65 20 6f 66 20 74 68 65 20 6e 65 78 74 20 55 54 e of the next UT
20cd0 46 2d 38 20 63 68 61 72 61 63 74 65 72 2e 0a 2a F-8 character..*
20ce0 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
20cf0 5f 53 4b 49 50 5f 55 54 46 38 28 7a 49 6e 29 20 _SKIP_UTF8(zIn)
20d00 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
20d10 20 20 20 20 20 20 20 20 20 5c 0a 20 20 69 66 28 \. if(
20d20 20 28 2a 28 7a 49 6e 2b 2b 29 29 3e 3d 30 78 63 (*(zIn++))>=0xc
20d30 30 20 29 7b 20 20 20 20 20 20 20 20 20 20 20 20 0 ){
20d40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20d50 20 20 5c 0a 20 20 20 20 77 68 69 6c 65 28 20 28 \. while( (
20d60 2a 7a 49 6e 20 26 20 30 78 63 30 29 3d 3d 30 78 *zIn & 0xc0)==0x
20d70 38 30 20 29 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 20 80 ){ zIn++; }
20d80 20 20 20 20 20 20 20 20 20 20 20 5c 0a 20 20 7d \. }
20d90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20da0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20db0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20dc0 20 20 20 20 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 \.}../*.** T
20dd0 68 65 20 53 51 4c 49 54 45 5f 2a 5f 42 4b 50 54 he SQLITE_*_BKPT
20de0 20 6d 61 63 72 6f 73 20 61 72 65 20 73 75 62 73 macros are subs
20df0 74 69 74 75 74 65 73 20 66 6f 72 20 74 68 65 20 titutes for the
20e00 65 72 72 6f 72 20 63 6f 64 65 73 20 77 69 74 68 error codes with
20e10 0a 2a 2a 20 74 68 65 20 73 61 6d 65 20 6e 61 6d .** the same nam
20e20 65 20 62 75 74 20 77 69 74 68 6f 75 74 20 74 68 e but without th
20e30 65 20 5f 42 4b 50 54 20 73 75 66 66 69 78 2e 20 e _BKPT suffix.
20e40 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 69 6e These macros in
20e50 76 6f 6b 65 0a 2a 2a 20 72 6f 75 74 69 6e 65 73 voke.** routines
20e60 20 74 68 61 74 20 72 65 70 6f 72 74 20 74 68 65 that report the
20e70 20 6c 69 6e 65 2d 6e 75 6d 62 65 72 20 6f 6e 20 line-number on
20e80 77 68 69 63 68 20 74 68 65 20 65 72 72 6f 72 20 which the error
20e90 6f 72 69 67 69 6e 61 74 65 64 0a 2a 2a 20 75 73 originated.** us
20ea0 69 6e 67 20 73 71 6c 69 74 65 33 5f 6c 6f 67 28 ing sqlite3_log(
20eb0 29 2e 20 20 54 68 65 20 72 6f 75 74 69 6e 65 73 ). The routines
20ec0 20 61 6c 73 6f 20 70 72 6f 76 69 64 65 20 61 20 also provide a
20ed0 63 6f 6e 76 65 6e 69 65 6e 74 20 70 6c 61 63 65 convenient place
20ee0 0a 2a 2a 20 74 6f 20 73 65 74 20 61 20 64 65 62 .** to set a deb
20ef0 75 67 67 65 72 20 62 72 65 61 6b 70 6f 69 6e 74 ugger breakpoint
20f00 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 ..*/.int sqlite3
20f10 43 6f 72 72 75 70 74 45 72 72 6f 72 28 69 6e 74 CorruptError(int
20f20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 69 );.int sqlite3Mi
20f30 73 75 73 65 45 72 72 6f 72 28 69 6e 74 29 3b 0a suseError(int);.
20f40 69 6e 74 20 73 71 6c 69 74 65 33 43 61 6e 74 6f int sqlite3Canto
20f50 70 65 6e 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 penError(int);.#
20f60 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f define SQLITE_CO
20f70 52 52 55 50 54 5f 42 4b 50 54 20 73 71 6c 69 74 RRUPT_BKPT sqlit
20f80 65 33 43 6f 72 72 75 70 74 45 72 72 6f 72 28 5f e3CorruptError(_
20f90 5f 4c 49 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 _LINE__).#define
20fa0 20 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 5f 42 SQLITE_MISUSE_B
20fb0 4b 50 54 20 73 71 6c 69 74 65 33 4d 69 73 75 73 KPT sqlite3Misus
20fc0 65 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 eError(__LINE__)
20fd0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
20fe0 43 41 4e 54 4f 50 45 4e 5f 42 4b 50 54 20 73 71 CANTOPEN_BKPT sq
20ff0 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 lite3CantopenErr
21000 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 0a 0a 2f or(__LINE__).../
21010 2a 0a 2a 2a 20 46 54 53 34 20 69 73 20 72 65 61 *.** FTS4 is rea
21020 6c 6c 79 20 61 6e 20 65 78 74 65 6e 73 69 6f 6e lly an extension
21030 20 66 6f 72 20 46 54 53 33 2e 20 20 49 74 20 69 for FTS3. It i
21040 73 20 65 6e 61 62 6c 65 64 20 75 73 69 6e 67 20 s enabled using
21050 74 68 65 0a 2a 2a 20 53 51 4c 49 54 45 5f 45 4e the.** SQLITE_EN
21060 41 42 4c 45 5f 46 54 53 33 20 6d 61 63 72 6f 2e ABLE_FTS3 macro.
21070 20 20 42 75 74 20 74 6f 20 61 76 6f 69 64 20 63 But to avoid c
21080 6f 6e 66 75 73 69 6f 6e 20 77 65 20 61 6c 73 6f onfusion we also
21090 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 53 51 4c call.** the SQL
210a0 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 34 20 ITE_ENABLE_FTS4
210b0 6d 61 63 72 6f 20 74 6f 20 73 65 72 76 65 20 61 macro to serve a
210c0 73 20 61 6e 20 61 6c 69 61 73 20 66 6f 72 20 53 s an alias for S
210d0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
210e0 33 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 3..*/.#if define
210f0 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
21100 46 54 53 34 29 20 26 26 20 21 64 65 66 69 6e 65 FTS4) && !define
21110 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
21120 46 54 53 33 29 0a 23 20 64 65 66 69 6e 65 20 53 FTS3).# define S
21130 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
21140 33 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 3 1.#endif../*.*
21150 2a 20 54 68 65 20 63 74 79 70 65 2e 68 20 68 65 * The ctype.h he
21160 61 64 65 72 20 69 73 20 6e 65 65 64 65 64 20 66 ader is needed f
21170 6f 72 20 6e 6f 6e 2d 41 53 43 49 49 20 73 79 73 or non-ASCII sys
21180 74 65 6d 73 2e 20 20 49 74 20 69 73 20 61 6c 73 tems. It is als
21190 6f 0a 2a 2a 20 6e 65 65 64 65 64 20 62 79 20 46 o.** needed by F
211a0 54 53 33 20 77 68 65 6e 20 46 54 53 33 20 69 73 TS3 when FTS3 is
211b0 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 74 68 65 included in the
211c0 20 61 6d 61 6c 67 61 6d 61 74 69 6f 6e 2e 0a 2a amalgamation..*
211d0 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 /.#if !defined(S
211e0 51 4c 49 54 45 5f 41 53 43 49 49 29 20 7c 7c 20 QLITE_ASCII) ||
211f0 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 64 28 53 \. (defined(S
21200 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
21210 33 29 20 26 26 20 64 65 66 69 6e 65 64 28 53 51 3) && defined(SQ
21220 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 49 4f LITE_AMALGAMATIO
21230 4e 29 29 0a 23 20 69 6e 63 6c 75 64 65 20 3c 63 N)).# include <c
21240 74 79 70 65 2e 68 3e 0a 23 65 6e 64 69 66 0a 0a type.h>.#endif..
21250 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
21260 69 6e 67 20 6d 61 63 72 6f 73 20 6d 69 6d 69 63 ing macros mimic
21270 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 6c 69 the standard li
21280 62 72 61 72 79 20 66 75 6e 63 74 69 6f 6e 73 20 brary functions
21290 74 6f 75 70 70 65 72 28 29 2c 0a 2a 2a 20 69 73 toupper(),.** is
212a0 73 70 61 63 65 28 29 2c 20 69 73 61 6c 6e 75 6d space(), isalnum
212b0 28 29 2c 20 69 73 64 69 67 69 74 28 29 20 61 6e (), isdigit() an
212c0 64 20 69 73 78 64 69 67 69 74 28 29 2c 20 72 65 d isxdigit(), re
212d0 73 70 65 63 74 69 76 65 6c 79 2e 20 54 68 65 0a spectively. The.
212e0 2a 2a 20 73 71 6c 69 74 65 20 76 65 72 73 69 6f ** sqlite versio
212f0 6e 73 20 6f 6e 6c 79 20 77 6f 72 6b 20 66 6f 72 ns only work for
21300 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65 72 ASCII character
21310 73 2c 20 72 65 67 61 72 64 6c 65 73 73 20 6f 66 s, regardless of
21320 20 6c 6f 63 61 6c 65 2e 0a 2a 2f 0a 23 69 66 64 locale..*/.#ifd
21330 65 66 20 53 51 4c 49 54 45 5f 41 53 43 49 49 0a ef SQLITE_ASCII.
21340 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
21350 54 6f 75 70 70 65 72 28 78 29 20 20 28 28 78 29 Toupper(x) ((x)
21360 26 7e 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d &~(sqlite3CtypeM
21370 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 ap[(unsigned cha
21380 72 29 28 78 29 5d 26 30 78 32 30 29 29 0a 23 20 r)(x)]&0x20)).#
21390 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
213a0 73 70 61 63 65 28 78 29 20 20 20 28 73 71 6c 69 space(x) (sqli
213b0 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 te3CtypeMap[(uns
213c0 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 igned char)(x)]&
213d0 30 78 30 31 29 0a 23 20 64 65 66 69 6e 65 20 73 0x01).# define s
213e0 71 6c 69 74 65 33 49 73 61 6c 6e 75 6d 28 78 29 qlite3Isalnum(x)
213f0 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 (sqlite3Ctype
21400 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 Map[(unsigned ch
21410 61 72 29 28 78 29 5d 26 30 78 30 36 29 0a 23 20 ar)(x)]&0x06).#
21420 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
21430 61 6c 70 68 61 28 78 29 20 20 20 28 73 71 6c 69 alpha(x) (sqli
21440 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 te3CtypeMap[(uns
21450 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 igned char)(x)]&
21460 30 78 30 32 29 0a 23 20 64 65 66 69 6e 65 20 73 0x02).# define s
21470 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 78 29 qlite3Isdigit(x)
21480 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 (sqlite3Ctype
21490 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 Map[(unsigned ch
214a0 61 72 29 28 78 29 5d 26 30 78 30 34 29 0a 23 20 ar)(x)]&0x04).#
214b0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
214c0 78 64 69 67 69 74 28 78 29 20 20 28 73 71 6c 69 xdigit(x) (sqli
214d0 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 te3CtypeMap[(uns
214e0 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 igned char)(x)]&
214f0 30 78 30 38 29 0a 23 20 64 65 66 69 6e 65 20 73 0x08).# define s
21500 71 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 qlite3Tolower(x)
21510 20 20 20 28 73 71 6c 69 74 65 33 55 70 70 65 72 (sqlite3Upper
21520 54 6f 4c 6f 77 65 72 5b 28 75 6e 73 69 67 6e 65 ToLower[(unsigne
21530 64 20 63 68 61 72 29 28 78 29 5d 29 0a 23 65 6c d char)(x)]).#el
21540 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
21550 74 65 33 54 6f 75 70 70 65 72 28 78 29 20 20 20 te3Toupper(x)
21560 74 6f 75 70 70 65 72 28 28 75 6e 73 69 67 6e 65 toupper((unsigne
21570 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 d char)(x)).# de
21580 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 73 70 fine sqlite3Issp
21590 61 63 65 28 78 29 20 20 20 69 73 73 70 61 63 65 ace(x) isspace
215a0 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
215b0 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
215c0 6c 69 74 65 33 49 73 61 6c 6e 75 6d 28 78 29 20 lite3Isalnum(x)
215d0 20 20 69 73 61 6c 6e 75 6d 28 28 75 6e 73 69 67 isalnum((unsig
215e0 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 ned char)(x)).#
215f0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
21600 61 6c 70 68 61 28 78 29 20 20 20 69 73 61 6c 70 alpha(x) isalp
21610 68 61 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 ha((unsigned cha
21620 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
21630 73 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 78 sqlite3Isdigit(x
21640 29 20 20 20 69 73 64 69 67 69 74 28 28 75 6e 73 ) isdigit((uns
21650 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
21660 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
21670 49 73 78 64 69 67 69 74 28 78 29 20 20 69 73 78 Isxdigit(x) isx
21680 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 20 digit((unsigned
21690 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 char)(x)).# defi
216a0 6e 65 20 73 71 6c 69 74 65 33 54 6f 6c 6f 77 65 ne sqlite3Tolowe
216b0 72 28 78 29 20 20 20 74 6f 6c 6f 77 65 72 28 28 r(x) tolower((
216c0 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
216d0 29 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 )).#endif.#ifnde
216e0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 4f f SQLITE_OMIT_CO
216f0 4d 50 49 4c 45 4f 50 54 49 4f 4e 5f 44 49 41 47 MPILEOPTION_DIAG
21700 53 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 73 49 S.int sqlite3IsI
21710 64 43 68 61 72 28 75 38 29 3b 0a 23 65 6e 64 69 dChar(u8);.#endi
21720 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 72 6e 61 f../*.** Interna
21730 6c 20 66 75 6e 63 74 69 6f 6e 20 70 72 6f 74 6f l function proto
21740 74 79 70 65 73 0a 2a 2f 0a 23 64 65 66 69 6e 65 types.*/.#define
21750 20 73 71 6c 69 74 65 33 53 74 72 49 43 6d 70 20 sqlite3StrICmp
21760 73 71 6c 69 74 65 33 5f 73 74 72 69 63 6d 70 0a sqlite3_stricmp.
21770 69 6e 74 20 73 71 6c 69 74 65 33 53 74 72 6c 65 int sqlite3Strle
21780 6e 33 30 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 n30(const char*)
21790 3b 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 ;.#define sqlite
217a0 33 53 74 72 4e 49 43 6d 70 20 73 71 6c 69 74 65 3StrNICmp sqlite
217b0 33 5f 73 74 72 6e 69 63 6d 70 0a 0a 69 6e 74 20 3_strnicmp..int
217c0 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 49 6e 69 sqlite3MallocIni
217d0 74 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 t(void);.void sq
217e0 6c 69 74 65 33 4d 61 6c 6c 6f 63 45 6e 64 28 76 lite3MallocEnd(v
217f0 6f 69 64 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 oid);.void *sqli
21800 74 65 33 4d 61 6c 6c 6f 63 28 75 36 34 29 3b 0a te3Malloc(u64);.
21810 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 4d 61 6c void *sqlite3Mal
21820 6c 6f 63 5a 65 72 6f 28 75 36 34 29 3b 0a 76 6f locZero(u64);.vo
21830 69 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c id *sqlite3DbMal
21840 6c 6f 63 5a 65 72 6f 28 73 71 6c 69 74 65 33 2a locZero(sqlite3*
21850 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 , u64);.void *sq
21860 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 lite3DbMallocRaw
21870 28 73 71 6c 69 74 65 33 2a 2c 20 75 36 34 29 3b (sqlite3*, u64);
21880 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 44 62 .char *sqlite3Db
21890 53 74 72 44 75 70 28 73 71 6c 69 74 65 33 2a 2c StrDup(sqlite3*,
218a0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 63 68 const char*);.ch
218b0 61 72 20 2a 73 71 6c 69 74 65 33 44 62 53 74 72 ar *sqlite3DbStr
218c0 4e 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 63 6f NDup(sqlite3*,co
218d0 6e 73 74 20 63 68 61 72 2a 2c 20 75 36 34 29 3b nst char*, u64);
218e0 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 52 65 .void *sqlite3Re
218f0 61 6c 6c 6f 63 28 76 6f 69 64 2a 2c 20 75 36 34 alloc(void*, u64
21900 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
21910 44 62 52 65 61 6c 6c 6f 63 4f 72 46 72 65 65 28 DbReallocOrFree(
21920 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f 69 64 20 sqlite3 *, void
21930 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 *, u64);.void *s
21940 71 6c 69 74 65 33 44 62 52 65 61 6c 6c 6f 63 28 qlite3DbRealloc(
21950 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f 69 64 20 sqlite3 *, void
21960 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 73 71 *, u64);.void sq
21970 6c 69 74 65 33 44 62 46 72 65 65 28 73 71 6c 69 lite3DbFree(sqli
21980 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 69 6e te3*, void*);.in
21990 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 53 t sqlite3MallocS
219a0 69 7a 65 28 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 ize(void*);.int
219b0 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 53 sqlite3DbMallocS
219c0 69 7a 65 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f ize(sqlite3*, vo
219d0 69 64 2a 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 id*);.void *sqli
219e0 74 65 33 53 63 72 61 74 63 68 4d 61 6c 6c 6f 63 te3ScratchMalloc
219f0 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 (int);.void sqli
21a00 74 65 33 53 63 72 61 74 63 68 46 72 65 65 28 76 te3ScratchFree(v
21a10 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 2a 73 71 6c oid*);.void *sql
21a20 69 74 65 33 50 61 67 65 4d 61 6c 6c 6f 63 28 69 ite3PageMalloc(i
21a30 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
21a40 33 50 61 67 65 46 72 65 65 28 76 6f 69 64 2a 29 3PageFree(void*)
21a50 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 ;.void sqlite3Me
21a60 6d 53 65 74 44 65 66 61 75 6c 74 28 76 6f 69 64 mSetDefault(void
21a70 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
21a80 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 E_OMIT_BUILTIN_T
21a90 45 53 54 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 EST.void sqlite3
21aa0 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 48 6f 6f 6b BenignMallocHook
21ab0 73 28 76 6f 69 64 20 28 2a 29 28 76 6f 69 64 29 s(void (*)(void)
21ac0 2c 20 76 6f 69 64 20 28 2a 29 28 76 6f 69 64 29 , void (*)(void)
21ad0 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 );.#endif.int sq
21ae0 6c 69 74 65 33 48 65 61 70 4e 65 61 72 6c 79 46 lite3HeapNearlyF
21af0 75 6c 6c 28 76 6f 69 64 29 3b 0a 0a 2f 2a 0a 2a ull(void);../*.*
21b00 2a 20 4f 6e 20 73 79 73 74 65 6d 73 20 77 69 74 * On systems wit
21b10 68 20 61 6d 70 6c 65 20 73 74 61 63 6b 20 73 70 h ample stack sp
21b20 61 63 65 20 61 6e 64 20 74 68 61 74 20 73 75 70 ace and that sup
21b30 70 6f 72 74 20 61 6c 6c 6f 63 61 28 29 2c 20 6d port alloca(), m
21b40 61 6b 65 0a 2a 2a 20 75 73 65 20 6f 66 20 61 6c ake.** use of al
21b50 6c 6f 63 61 28 29 20 74 6f 20 6f 62 74 61 69 6e loca() to obtain
21b60 20 73 70 61 63 65 20 66 6f 72 20 6c 61 72 67 65 space for large
21b70 20 61 75 74 6f 6d 61 74 69 63 20 6f 62 6a 65 63 automatic objec
21b80 74 73 2e 20 20 42 79 20 64 65 66 61 75 6c 74 2c ts. By default,
21b90 0a 2a 2a 20 6f 62 74 61 69 6e 20 73 70 61 63 65 .** obtain space
21ba0 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 2e 0a from malloc()..
21bb0 2a 2a 0a 2a 2a 20 54 68 65 20 61 6c 6c 6f 63 61 **.** The alloca
21bc0 28 29 20 72 6f 75 74 69 6e 65 20 6e 65 76 65 72 () routine never
21bd0 20 72 65 74 75 72 6e 73 20 4e 55 4c 4c 2e 20 20 returns NULL.
21be0 54 68 69 73 20 77 69 6c 6c 20 63 61 75 73 65 20 This will cause
21bf0 63 6f 64 65 20 70 61 74 68 73 0a 2a 2a 20 74 68 code paths.** th
21c00 61 74 20 64 65 61 6c 20 77 69 74 68 20 73 71 6c at deal with sql
21c10 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 28 29 ite3StackAlloc()
21c20 20 66 61 69 6c 75 72 65 73 20 74 6f 20 62 65 20 failures to be
21c30 75 6e 72 65 61 63 68 61 62 6c 65 2e 0a 2a 2f 0a unreachable..*/.
21c40 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 #ifdef SQLITE_US
21c50 45 5f 41 4c 4c 4f 43 41 0a 23 20 64 65 66 69 6e E_ALLOCA.# defin
21c60 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c e sqlite3StackAl
21c70 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 20 61 6c locRaw(D,N) al
21c80 6c 6f 63 61 28 4e 29 0a 23 20 64 65 66 69 6e 65 loca(N).# define
21c90 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c sqlite3StackAll
21ca0 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 6d 65 6d ocZero(D,N) mem
21cb0 73 65 74 28 61 6c 6c 6f 63 61 28 4e 29 2c 20 30 set(alloca(N), 0
21cc0 2c 20 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 , N).# define sq
21cd0 6c 69 74 65 33 53 74 61 63 6b 46 72 65 65 28 44 lite3StackFree(D
21ce0 2c 50 29 20 20 20 20 20 20 20 0a 23 65 6c 73 65 ,P) .#else
21cf0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
21d00 33 53 74 61 63 6b 41 6c 6c 6f 63 52 61 77 28 44 3StackAllocRaw(D
21d10 2c 4e 29 20 20 20 73 71 6c 69 74 65 33 44 62 4d ,N) sqlite3DbM
21d20 61 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 0a 23 20 allocRaw(D,N).#
21d30 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 define sqlite3St
21d40 61 63 6b 41 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e ackAllocZero(D,N
21d50 29 20 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c ) sqlite3DbMall
21d60 6f 63 5a 65 72 6f 28 44 2c 4e 29 0a 23 20 64 65 ocZero(D,N).# de
21d70 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
21d80 6b 46 72 65 65 28 44 2c 50 29 20 20 20 20 20 20 kFree(D,P)
21d90 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 44 sqlite3DbFree(D
21da0 2c 50 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 ,P).#endif..#ifd
21db0 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
21dc0 5f 4d 45 4d 53 59 53 33 0a 63 6f 6e 73 74 20 73 _MEMSYS3.const s
21dd0 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f qlite3_mem_metho
21de0 64 73 20 2a 73 71 6c 69 74 65 33 4d 65 6d 47 65 ds *sqlite3MemGe
21df0 74 4d 65 6d 73 79 73 33 28 76 6f 69 64 29 3b 0a tMemsys3(void);.
21e00 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 #endif.#ifdef SQ
21e10 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 LITE_ENABLE_MEMS
21e20 59 53 35 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 YS5.const sqlite
21e30 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 3_mem_methods *s
21e40 71 6c 69 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 qlite3MemGetMems
21e50 79 73 35 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 ys5(void);.#endi
21e60 66 0a 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 f...#ifndef SQLI
21e70 54 45 5f 4d 55 54 45 58 5f 4f 4d 49 54 0a 20 20 TE_MUTEX_OMIT.
21e80 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 sqlite3_mutex_me
21e90 74 68 6f 64 73 20 63 6f 6e 73 74 20 2a 73 71 6c thods const *sql
21ea0 69 74 65 33 44 65 66 61 75 6c 74 4d 75 74 65 78 ite3DefaultMutex
21eb0 28 76 6f 69 64 29 3b 0a 20 20 73 71 6c 69 74 65 (void);. sqlite
21ec0 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 3_mutex_methods
21ed0 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 33 4e 6f const *sqlite3No
21ee0 6f 70 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 opMutex(void);.
21ef0 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 4e 6f void *sqlite3No
21f00 6f 70 43 6f 6d 70 61 72 65 41 6e 64 53 77 61 70 opCompareAndSwap
21f10 28 76 6f 69 64 20 2a 20 76 6f 6c 61 74 69 6c 65 (void * volatile
21f20 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 76 6f 69 64 *, void *, void
21f30 20 2a 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d *);. sqlite3_m
21f40 75 74 65 78 20 2a 73 71 6c 69 74 65 33 4d 75 74 utex *sqlite3Mut
21f50 65 78 41 6c 6c 6f 63 28 69 6e 74 29 3b 0a 20 20 exAlloc(int);.
21f60 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 74 65 78 int sqlite3Mutex
21f70 49 6e 69 74 28 76 6f 69 64 29 3b 0a 20 20 69 6e Init(void);. in
21f80 74 20 73 71 6c 69 74 65 33 4d 75 74 65 78 45 6e t sqlite3MutexEn
21f90 64 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a d(void);.#endif.
21fa0 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
21fb0 49 54 45 5f 4d 55 54 45 58 5f 4f 4d 49 54 29 20 ITE_MUTEX_OMIT)
21fc0 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
21fd0 54 45 5f 4d 55 54 45 58 5f 4e 4f 4f 50 29 0a 20 TE_MUTEX_NOOP).
21fe0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d void sqlite3Mem
21ff0 6f 72 79 42 61 72 72 69 65 72 28 76 6f 69 64 29 oryBarrier(void)
22000 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
22010 20 73 71 6c 69 74 65 33 4d 65 6d 6f 72 79 42 61 sqlite3MemoryBa
22020 72 72 69 65 72 28 29 0a 23 65 6e 64 69 66 0a 23 rrier().#endif.#
22030 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
22040 54 45 5f 4d 55 54 45 58 5f 4f 4d 49 54 29 0a 23 TE_MUTEX_OMIT).#
22050 20 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c if !defined(SQL
22060 49 54 45 5f 4d 55 54 45 58 5f 4e 4f 4f 50 29 0a ITE_MUTEX_NOOP).
22070 20 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 void *sqlite3
22080 43 6f 6d 70 61 72 65 41 6e 64 53 77 61 70 28 76 CompareAndSwap(v
22090 6f 69 64 20 2a 20 76 6f 6c 61 74 69 6c 65 20 2a oid * volatile *
220a0 2c 20 76 6f 69 64 20 2a 2c 20 76 6f 69 64 20 2a , void *, void *
220b0 29 3b 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 );.# else.# def
220c0 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6d 70 61 ine sqlite3Compa
220d0 72 65 41 6e 64 53 77 61 70 20 73 71 6c 69 74 65 reAndSwap sqlite
220e0 33 4e 6f 6f 70 43 6f 6d 70 61 72 65 41 6e 64 53 3NoopCompareAndS
220f0 77 61 70 0a 23 20 65 6e 64 69 66 0a 23 65 6c 73 wap.# endif.#els
22100 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
22110 65 33 43 6f 6d 70 61 72 65 41 6e 64 53 77 61 70 e3CompareAndSwap
22120 28 78 2c 79 2c 7a 29 0a 23 65 6e 64 69 66 0a 0a (x,y,z).#endif..
22130 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 73 71 sqlite3_int64 sq
22140 6c 69 74 65 33 53 74 61 74 75 73 56 61 6c 75 65 lite3StatusValue
22150 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 (int);.void sqli
22160 74 65 33 53 74 61 74 75 73 55 70 28 69 6e 74 2c te3StatusUp(int,
22170 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
22180 74 65 33 53 74 61 74 75 73 44 6f 77 6e 28 69 6e te3StatusDown(in
22190 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
221a0 6c 69 74 65 33 53 74 61 74 75 73 53 65 74 28 69 lite3StatusSet(i
221b0 6e 74 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 41 63 nt, int);../* Ac
221c0 63 65 73 73 20 74 6f 20 6d 75 74 65 78 65 73 20 cess to mutexes
221d0 75 73 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f used by sqlite3_
221e0 73 74 61 74 75 73 28 29 20 2a 2f 0a 73 71 6c 69 status() */.sqli
221f0 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 te3_mutex *sqlit
22200 65 33 50 63 61 63 68 65 31 4d 75 74 65 78 28 76 e3Pcache1Mutex(v
22210 6f 69 64 29 3b 0a 73 71 6c 69 74 65 33 5f 6d 75 oid);.sqlite3_mu
22220 74 65 78 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c tex *sqlite3Mall
22230 6f 63 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 0a ocMutex(void);..
22240 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
22250 4d 49 54 5f 46 4c 4f 41 54 49 4e 47 5f 50 4f 49 MIT_FLOATING_POI
22260 4e 54 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 NT. int sqlite3
22270 49 73 4e 61 4e 28 64 6f 75 62 6c 65 29 3b 0a 23 IsNaN(double);.#
22280 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
22290 6c 69 74 65 33 49 73 4e 61 4e 28 58 29 20 20 30 lite3IsNaN(X) 0
222a0 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 .#endif../*.** A
222b0 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
222c0 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
222d0 63 74 75 72 65 20 68 6f 6c 64 73 20 69 6e 66 6f cture holds info
222e0 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 53 51 rmation about SQ
222f0 4c 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 20 61 L.** functions a
22300 72 67 75 6d 65 6e 74 73 20 74 68 61 74 20 61 72 rguments that ar
22310 65 20 74 68 65 20 70 61 72 61 6d 65 74 65 72 73 e the parameters
22320 20 74 6f 20 74 68 65 20 70 72 69 6e 74 66 28 29 to the printf()
22330 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 function..*/.st
22340 72 75 63 74 20 50 72 69 6e 74 66 41 72 67 75 6d ruct PrintfArgum
22350 65 6e 74 73 20 7b 0a 20 20 69 6e 74 20 6e 41 72 ents {. int nAr
22360 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
22370 20 20 2f 2a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 /* Total numbe
22380 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 2a r of arguments *
22390 2f 0a 20 20 69 6e 74 20 6e 55 73 65 64 3b 20 20 /. int nUsed;
223a0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
223b0 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 Number of argume
223c0 6e 74 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 nts used so far
223d0 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 6c */. sqlite3_val
223e0 75 65 20 2a 2a 61 70 41 72 67 3b 20 20 20 2f 2a ue **apArg; /*
223f0 20 54 68 65 20 61 72 67 75 6d 65 6e 74 20 76 61 The argument va
22400 6c 75 65 73 20 2a 2f 0a 7d 3b 0a 0a 23 64 65 66 lues */.};..#def
22410 69 6e 65 20 53 51 4c 49 54 45 5f 50 52 49 4e 54 ine SQLITE_PRINT
22420 46 5f 49 4e 54 45 52 4e 41 4c 20 30 78 30 31 0a F_INTERNAL 0x01.
22430 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 #define SQLITE_P
22440 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 20 20 30 RINTF_SQLFUNC 0
22450 78 30 32 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 x02.void sqlite3
22460 56 58 50 72 69 6e 74 66 28 53 74 72 41 63 63 75 VXPrintf(StrAccu
22470 6d 2a 2c 20 75 33 32 2c 20 63 6f 6e 73 74 20 63 m*, u32, const c
22480 68 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b 0a har*, va_list);.
22490 76 6f 69 64 20 73 71 6c 69 74 65 33 58 50 72 69 void sqlite3XPri
224a0 6e 74 66 28 53 74 72 41 63 63 75 6d 2a 2c 20 75 ntf(StrAccum*, u
224b0 33 32 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 32, const char*,
224c0 20 2e 2e 2e 29 3b 0a 63 68 61 72 20 2a 73 71 6c ...);.char *sql
224d0 69 74 65 33 4d 50 72 69 6e 74 66 28 73 71 6c 69 ite3MPrintf(sqli
224e0 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
224f0 2c 20 2e 2e 2e 29 3b 0a 63 68 61 72 20 2a 73 71 , ...);.char *sq
22500 6c 69 74 65 33 56 4d 50 72 69 6e 74 66 28 73 71 lite3VMPrintf(sq
22510 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
22520 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b 0a 23 69 r*, va_list);.#i
22530 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 f defined(SQLITE
22540 5f 44 45 42 55 47 29 20 7c 7c 20 64 65 66 69 6e _DEBUG) || defin
22550 65 64 28 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f ed(SQLITE_HAVE_O
22560 53 5f 54 52 41 43 45 29 0a 20 20 76 6f 69 64 20 S_TRACE). void
22570 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 69 6e sqlite3DebugPrin
22580 74 66 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 tf(const char*,
22590 2e 2e 2e 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 ...);.#endif.#if
225a0 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
225b0 54 45 53 54 29 0a 20 20 76 6f 69 64 20 2a 73 71 TEST). void *sq
225c0 6c 69 74 65 33 54 65 73 74 54 65 78 74 54 6f 50 lite3TestTextToP
225d0 74 72 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b tr(const char*);
225e0 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 64 65 66 .#endif..#if def
225f0 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 ined(SQLITE_DEBU
22600 47 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 G). void sqlite
22610 33 54 72 65 65 56 69 65 77 45 78 70 72 28 54 72 3TreeViewExpr(Tr
22620 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 45 eeView*, const E
22630 78 70 72 2a 2c 20 75 38 29 3b 0a 20 20 76 6f 69 xpr*, u8);. voi
22640 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 65 d sqlite3TreeVie
22650 77 45 78 70 72 4c 69 73 74 28 54 72 65 65 56 69 wExprList(TreeVi
22660 65 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 4c ew*, const ExprL
22670 69 73 74 2a 2c 20 75 38 2c 20 63 6f 6e 73 74 20 ist*, u8, const
22680 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 char*);. void s
22690 71 6c 69 74 65 33 54 72 65 65 56 69 65 77 53 65 qlite3TreeViewSe
226a0 6c 65 63 74 28 54 72 65 65 56 69 65 77 2a 2c 20 lect(TreeView*,
226b0 63 6f 6e 73 74 20 53 65 6c 65 63 74 2a 2c 20 75 const Select*, u
226c0 38 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 76 6f 69 8);.#endif...voi
226d0 64 20 73 71 6c 69 74 65 33 53 65 74 53 74 72 69 d sqlite3SetStri
226e0 6e 67 28 63 68 61 72 20 2a 2a 2c 20 73 71 6c 69 ng(char **, sqli
226f0 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 te3*, const char
22700 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
22710 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c ErrorMsg(Parse*,
22720 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e const char*, ..
22730 2e 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 .);.int sqlite3D
22740 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 0a 69 equote(char*);.i
22750 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 77 6f 72 nt sqlite3Keywor
22760 64 43 6f 64 65 28 63 6f 6e 73 74 20 75 6e 73 69 dCode(const unsi
22770 67 6e 65 64 20 63 68 61 72 2a 2c 20 69 6e 74 29 gned char*, int)
22780 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 75 6e ;.int sqlite3Run
22790 50 61 72 73 65 72 28 50 61 72 73 65 2a 2c 20 63 Parser(Parse*, c
227a0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 68 61 72 onst char*, char
227b0 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 **);.void sqlit
227c0 65 33 46 69 6e 69 73 68 43 6f 64 69 6e 67 28 50 e3FinishCoding(P
227d0 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 arse*);.int sqli
227e0 74 65 33 47 65 74 54 65 6d 70 52 65 67 28 50 61 te3GetTempReg(Pa
227f0 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 rse*);.void sqli
22800 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 52 65 te3ReleaseTempRe
22810 67 28 50 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 69 g(Parse*,int);.i
22820 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d nt sqlite3GetTem
22830 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e pRange(Parse*,in
22840 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
22850 52 65 6c 65 61 73 65 54 65 6d 70 52 61 6e 67 65 ReleaseTempRange
22860 28 50 61 72 73 65 2a 2c 69 6e 74 2c 69 6e 74 29 (Parse*,int,int)
22870 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c ;.void sqlite3Cl
22880 65 61 72 54 65 6d 70 52 65 67 43 61 63 68 65 28 earTempRegCache(
22890 50 61 72 73 65 2a 29 3b 0a 45 78 70 72 20 2a 73 Parse*);.Expr *s
228a0 71 6c 69 74 65 33 45 78 70 72 41 6c 6c 6f 63 28 qlite3ExprAlloc(
228b0 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e sqlite3*,int,con
228c0 73 74 20 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a st Token*,int);.
228d0 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 Expr *sqlite3Exp
228e0 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 r(sqlite3*,int,c
228f0 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 onst char*);.voi
22900 64 20 73 71 6c 69 74 65 33 45 78 70 72 41 74 74 d sqlite3ExprAtt
22910 61 63 68 53 75 62 74 72 65 65 73 28 73 71 6c 69 achSubtrees(sqli
22920 74 65 33 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a te3*,Expr*,Expr*
22930 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 ,Expr*);.Expr *s
22940 71 6c 69 74 65 33 50 45 78 70 72 28 50 61 72 73 qlite3PExpr(Pars
22950 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 2a 2c 20 e*, int, Expr*,
22960 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b Expr*, const Tok
22970 65 6e 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 en*);.Expr *sqli
22980 74 65 33 45 78 70 72 41 6e 64 28 73 71 6c 69 74 te3ExprAnd(sqlit
22990 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 2a e3*,Expr*, Expr*
229a0 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
229b0 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 50 61 72 ExprFunction(Par
229c0 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 20 54 se*,ExprList*, T
229d0 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
229e0 69 74 65 33 45 78 70 72 41 73 73 69 67 6e 56 61 ite3ExprAssignVa
229f0 72 4e 75 6d 62 65 72 28 50 61 72 73 65 2a 2c 20 rNumber(Parse*,
22a00 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
22a10 69 74 65 33 45 78 70 72 44 65 6c 65 74 65 28 73 ite3ExprDelete(s
22a20 71 6c 69 74 65 33 2a 2c 20 45 78 70 72 2a 29 3b qlite3*, Expr*);
22a30 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 .ExprList *sqlit
22a40 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e 64 e3ExprListAppend
22a50 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 (Parse*,ExprList
22a60 2a 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 *,Expr*);.void s
22a70 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 qlite3ExprListSe
22a80 74 53 6f 72 74 4f 72 64 65 72 28 45 78 70 72 4c tSortOrder(ExprL
22a90 69 73 74 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 ist*,int);.void
22aa0 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 sqlite3ExprListS
22ab0 65 74 4e 61 6d 65 28 50 61 72 73 65 2a 2c 45 78 etName(Parse*,Ex
22ac0 70 72 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 prList*,Token*,i
22ad0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22ae0 33 45 78 70 72 4c 69 73 74 53 65 74 53 70 61 6e 3ExprListSetSpan
22af0 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 (Parse*,ExprList
22b00 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f *,ExprSpan*);.vo
22b10 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 id sqlite3ExprLi
22b20 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
22b30 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 75 *, ExprList*);.u
22b40 33 32 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 32 sqlite3ExprLi
22b50 73 74 46 6c 61 67 73 28 63 6f 6e 73 74 20 45 78 stFlags(const Ex
22b60 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 prList*);.int sq
22b70 6c 69 74 65 33 49 6e 69 74 28 73 71 6c 69 74 65 lite3Init(sqlite
22b80 33 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a 69 6e 74 3*, char**);.int
22b90 20 73 71 6c 69 74 65 33 49 6e 69 74 43 61 6c 6c sqlite3InitCall
22ba0 62 61 63 6b 28 76 6f 69 64 2a 2c 20 69 6e 74 2c back(void*, int,
22bb0 20 63 68 61 72 2a 2a 2c 20 63 68 61 72 2a 2a 29 char**, char**)
22bc0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 ;.void sqlite3Pr
22bd0 61 67 6d 61 28 50 61 72 73 65 2a 2c 54 6f 6b 65 agma(Parse*,Toke
22be0 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a n*,Token*,Token*
22bf0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
22c00 74 65 33 52 65 73 65 74 41 6c 6c 53 63 68 65 6d te3ResetAllSchem
22c10 61 73 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e 28 73 asOfConnection(s
22c20 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 qlite3*);.void s
22c30 71 6c 69 74 65 33 52 65 73 65 74 4f 6e 65 53 63 qlite3ResetOneSc
22c40 68 65 6d 61 28 73 71 6c 69 74 65 33 2a 2c 69 6e hema(sqlite3*,in
22c50 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
22c60 43 6f 6c 6c 61 70 73 65 44 61 74 61 62 61 73 65 CollapseDatabase
22c70 41 72 72 61 79 28 73 71 6c 69 74 65 33 2a 29 3b Array(sqlite3*);
22c80 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 .void sqlite3Beg
22c90 69 6e 50 61 72 73 65 28 50 61 72 73 65 2a 2c 69 inParse(Parse*,i
22ca0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22cb0 33 43 6f 6d 6d 69 74 49 6e 74 65 72 6e 61 6c 43 3CommitInternalC
22cc0 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 2a 29 hanges(sqlite3*)
22cd0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 ;.void sqlite3De
22ce0 6c 65 74 65 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 leteColumnNames(
22cf0 73 71 6c 69 74 65 33 2a 2c 54 61 62 6c 65 2a 29 sqlite3*,Table*)
22d00 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 6c ;.int sqlite3Col
22d10 75 6d 6e 73 46 72 6f 6d 45 78 70 72 4c 69 73 74 umnsFromExprList
22d20 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 (Parse*,ExprList
22d30 2a 2c 69 31 36 2a 2c 43 6f 6c 75 6d 6e 2a 2a 29 *,i16*,Column**)
22d40 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 ;.Table *sqlite3
22d50 52 65 73 75 6c 74 53 65 74 4f 66 53 65 6c 65 63 ResultSetOfSelec
22d60 74 28 50 61 72 73 65 2a 2c 53 65 6c 65 63 74 2a t(Parse*,Select*
22d70 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f );.void sqlite3O
22d80 70 65 6e 4d 61 73 74 65 72 54 61 62 6c 65 28 50 penMasterTable(P
22d90 61 72 73 65 20 2a 2c 20 69 6e 74 29 3b 0a 49 6e arse *, int);.In
22da0 64 65 78 20 2a 73 71 6c 69 74 65 33 50 72 69 6d dex *sqlite3Prim
22db0 61 72 79 4b 65 79 49 6e 64 65 78 28 54 61 62 6c aryKeyIndex(Tabl
22dc0 65 2a 29 3b 0a 69 31 36 20 73 71 6c 69 74 65 33 e*);.i16 sqlite3
22dd0 43 6f 6c 75 6d 6e 4f 66 49 6e 64 65 78 28 49 6e ColumnOfIndex(In
22de0 64 65 78 2a 2c 20 69 31 36 29 3b 0a 76 6f 69 64 dex*, i16);.void
22df0 20 73 71 6c 69 74 65 33 53 74 61 72 74 54 61 62 sqlite3StartTab
22e00 6c 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a le(Parse*,Token*
22e10 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c ,Token*,int,int,
22e20 69 6e 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 int,int);.void s
22e30 71 6c 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e 28 qlite3AddColumn(
22e40 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a Parse*,Token*);.
22e50 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 4e void sqlite3AddN
22e60 6f 74 4e 75 6c 6c 28 50 61 72 73 65 2a 2c 20 69 otNull(Parse*, i
22e70 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22e80 33 41 64 64 50 72 69 6d 61 72 79 4b 65 79 28 50 3AddPrimaryKey(P
22e90 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a arse*, ExprList*
22ea0 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
22eb0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 ;.void sqlite3Ad
22ec0 64 43 68 65 63 6b 43 6f 6e 73 74 72 61 69 6e 74 dCheckConstraint
22ed0 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b (Parse*, Expr*);
22ee0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
22ef0 43 6f 6c 75 6d 6e 54 79 70 65 28 50 61 72 73 65 ColumnType(Parse
22f00 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 *,Token*);.void
22f10 73 71 6c 69 74 65 33 41 64 64 44 65 66 61 75 6c sqlite3AddDefaul
22f20 74 56 61 6c 75 65 28 50 61 72 73 65 2a 2c 45 78 tValue(Parse*,Ex
22f30 70 72 53 70 61 6e 2a 29 3b 0a 76 6f 69 64 20 73 prSpan*);.void s
22f40 71 6c 69 74 65 33 41 64 64 43 6f 6c 6c 61 74 65 qlite3AddCollate
22f50 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b Type(Parse*, Tok
22f60 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
22f70 65 33 45 6e 64 54 61 62 6c 65 28 50 61 72 73 65 e3EndTable(Parse
22f80 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c *,Token*,Token*,
22f90 75 38 2c 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 u8,Select*);.int
22fa0 20 73 71 6c 69 74 65 33 50 61 72 73 65 55 72 69 sqlite3ParseUri
22fb0 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e (const char*,con
22fc0 73 74 20 63 68 61 72 2a 2c 75 6e 73 69 67 6e 65 st char*,unsigne
22fd0 64 20 69 6e 74 2a 2c 0a 20 20 20 20 20 20 20 20 d int*,.
22fe0 20 20 20 20 20 20 20 20 20 20 20 20 73 71 6c 69 sqli
22ff0 74 65 33 5f 76 66 73 2a 2a 2c 63 68 61 72 2a 2a te3_vfs**,char**
23000 2c 63 68 61 72 20 2a 2a 29 3b 0a 42 74 72 65 65 ,char **);.Btree
23010 20 2a 73 71 6c 69 74 65 33 44 62 4e 61 6d 65 54 *sqlite3DbNameT
23020 6f 42 74 72 65 65 28 73 71 6c 69 74 65 33 2a 2c oBtree(sqlite3*,
23030 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e const char*);.in
23040 74 20 73 71 6c 69 74 65 33 43 6f 64 65 4f 6e 63 t sqlite3CodeOnc
23050 65 28 50 61 72 73 65 20 2a 29 3b 0a 0a 23 69 66 e(Parse *);..#if
23060 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
23070 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 23 20 64 BUILTIN_TEST.# d
23080 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 61 75 efine sqlite3Fau
23090 6c 74 53 69 6d 28 58 29 20 53 51 4c 49 54 45 5f ltSim(X) SQLITE_
230a0 4f 4b 0a 23 65 6c 73 65 0a 20 20 69 6e 74 20 73 OK.#else. int s
230b0 71 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 69 qlite3FaultSim(i
230c0 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 42 69 74 nt);.#endif..Bit
230d0 76 65 63 20 2a 73 71 6c 69 74 65 33 42 69 74 76 vec *sqlite3Bitv
230e0 65 63 43 72 65 61 74 65 28 75 33 32 29 3b 0a 69 ecCreate(u32);.i
230f0 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
23100 54 65 73 74 28 42 69 74 76 65 63 2a 2c 20 75 33 Test(Bitvec*, u3
23110 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 2);.int sqlite3B
23120 69 74 76 65 63 54 65 73 74 4e 6f 74 4e 75 6c 6c itvecTestNotNull
23130 28 42 69 74 76 65 63 2a 2c 20 75 33 32 29 3b 0a (Bitvec*, u32);.
23140 69 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 int sqlite3Bitve
23150 63 53 65 74 28 42 69 74 76 65 63 2a 2c 20 75 33 cSet(Bitvec*, u3
23160 32 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 2);.void sqlite3
23170 42 69 74 76 65 63 43 6c 65 61 72 28 42 69 74 76 BitvecClear(Bitv
23180 65 63 2a 2c 20 75 33 32 2c 20 76 6f 69 64 2a 29 ec*, u32, void*)
23190 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 69 ;.void sqlite3Bi
231a0 74 76 65 63 44 65 73 74 72 6f 79 28 42 69 74 76 tvecDestroy(Bitv
231b0 65 63 2a 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 ec*);.u32 sqlite
231c0 33 42 69 74 76 65 63 53 69 7a 65 28 42 69 74 76 3BitvecSize(Bitv
231d0 65 63 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 ec*);.#ifndef SQ
231e0 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 LITE_OMIT_BUILTI
231f0 4e 5f 54 45 53 54 0a 69 6e 74 20 73 71 6c 69 74 N_TEST.int sqlit
23200 65 33 42 69 74 76 65 63 42 75 69 6c 74 69 6e 54 e3BitvecBuiltinT
23210 65 73 74 28 69 6e 74 2c 69 6e 74 2a 29 3b 0a 23 est(int,int*);.#
23220 65 6e 64 69 66 0a 0a 52 6f 77 53 65 74 20 2a 73 endif..RowSet *s
23230 71 6c 69 74 65 33 52 6f 77 53 65 74 49 6e 69 74 qlite3RowSetInit
23240 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a (sqlite3*, void*
23250 2c 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 3b , unsigned int);
23260 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 6f 77 .void sqlite3Row
23270 53 65 74 43 6c 65 61 72 28 52 6f 77 53 65 74 2a SetClear(RowSet*
23280 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
23290 6f 77 53 65 74 49 6e 73 65 72 74 28 52 6f 77 53 owSetInsert(RowS
232a0 65 74 2a 2c 20 69 36 34 29 3b 0a 69 6e 74 20 73 et*, i64);.int s
232b0 71 6c 69 74 65 33 52 6f 77 53 65 74 54 65 73 74 qlite3RowSetTest
232c0 28 52 6f 77 53 65 74 2a 2c 20 69 6e 74 20 69 42 (RowSet*, int iB
232d0 61 74 63 68 2c 20 69 36 34 29 3b 0a 69 6e 74 20 atch, i64);.int
232e0 73 71 6c 69 74 65 33 52 6f 77 53 65 74 4e 65 78 sqlite3RowSetNex
232f0 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 2a 29 t(RowSet*, i64*)
23300 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 ;..void sqlite3C
23310 72 65 61 74 65 56 69 65 77 28 50 61 72 73 65 2a reateView(Parse*
23320 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 ,Token*,Token*,T
23330 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
23340 53 65 6c 65 63 74 2a 2c 69 6e 74 2c 69 6e 74 29 Select*,int,int)
23350 3b 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 ;..#if !defined(
23360 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 57 SQLITE_OMIT_VIEW
23370 29 20 7c 7c 20 21 64 65 66 69 6e 65 64 28 53 51 ) || !defined(SQ
23380 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
23390 4c 54 41 42 4c 45 29 0a 20 20 69 6e 74 20 73 71 LTABLE). int sq
233a0 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f 6c 75 lite3ViewGetColu
233b0 6d 6e 4e 61 6d 65 73 28 50 61 72 73 65 2a 2c 54 mnNames(Parse*,T
233c0 61 62 6c 65 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 able*);.#else.#
233d0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 69 define sqlite3Vi
233e0 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 ewGetColumnNames
233f0 28 41 2c 42 29 20 30 0a 23 65 6e 64 69 66 0a 0a (A,B) 0.#endif..
23400 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 41 #if SQLITE_MAX_A
23410 54 54 41 43 48 45 44 3e 33 30 0a 20 20 69 6e 74 TTACHED>30. int
23420 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c sqlite3DbMaskAl
23430 6c 5a 65 72 6f 28 79 44 62 4d 61 73 6b 29 3b 0a lZero(yDbMask);.
23440 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
23450 74 65 33 44 72 6f 70 54 61 62 6c 65 28 50 61 72 te3DropTable(Par
23460 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 se*, SrcList*, i
23470 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
23480 71 6c 69 74 65 33 43 6f 64 65 44 72 6f 70 54 61 qlite3CodeDropTa
23490 62 6c 65 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ble(Parse*, Tabl
234a0 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 e*, int, int);.v
234b0 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 oid sqlite3Delet
234c0 65 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c eTable(sqlite3*,
234d0 20 54 61 62 6c 65 2a 29 3b 0a 23 69 66 6e 64 65 Table*);.#ifnde
234e0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
234f0 54 4f 49 4e 43 52 45 4d 45 4e 54 0a 20 20 76 6f TOINCREMENT. vo
23500 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e id sqlite3Autoin
23510 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 50 61 72 crementBegin(Par
23520 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 20 20 76 se *pParse);. v
23530 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 oid sqlite3Autoi
23540 6e 63 72 65 6d 65 6e 74 45 6e 64 28 50 61 72 73 ncrementEnd(Pars
23550 65 20 2a 70 50 61 72 73 65 29 3b 0a 23 65 6c 73 e *pParse);.#els
23560 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
23570 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 42 e3AutoincrementB
23580 65 67 69 6e 28 58 29 0a 23 20 64 65 66 69 6e 65 egin(X).# define
23590 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 sqlite3Autoincr
235a0 65 6d 65 6e 74 45 6e 64 28 58 29 0a 23 65 6e 64 ementEnd(X).#end
235b0 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 if.void sqlite3I
235c0 6e 73 65 72 74 28 50 61 72 73 65 2a 2c 20 53 72 nsert(Parse*, Sr
235d0 63 4c 69 73 74 2a 2c 20 53 65 6c 65 63 74 2a 2c cList*, Select*,
235e0 20 49 64 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a IdList*, int);.
235f0 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 41 72 72 void *sqlite3Arr
23600 61 79 41 6c 6c 6f 63 61 74 65 28 73 71 6c 69 74 ayAllocate(sqlit
23610 65 33 2a 2c 76 6f 69 64 2a 2c 69 6e 74 2c 69 6e e3*,void*,int,in
23620 74 2a 2c 69 6e 74 2a 29 3b 0a 49 64 4c 69 73 74 t*,int*);.IdList
23630 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 74 41 *sqlite3IdListA
23640 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 ppend(sqlite3*,
23650 49 64 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 IdList*, Token*)
23660 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 64 4c ;.int sqlite3IdL
23670 69 73 74 49 6e 64 65 78 28 49 64 4c 69 73 74 2a istIndex(IdList*
23680 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 53 ,const char*);.S
23690 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 rcList *sqlite3S
236a0 72 63 4c 69 73 74 45 6e 6c 61 72 67 65 28 73 71 rcListEnlarge(sq
236b0 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a lite3*, SrcList*
236c0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 53 72 63 , int, int);.Src
236d0 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 List *sqlite3Src
236e0 4c 69 73 74 41 70 70 65 6e 64 28 73 71 6c 69 74 ListAppend(sqlit
236f0 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 54 e3*, SrcList*, T
23700 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a oken*, Token*);.
23710 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 SrcList *sqlite3
23720 53 72 63 4c 69 73 74 41 70 70 65 6e 64 46 72 6f SrcListAppendFro
23730 6d 54 65 72 6d 28 50 61 72 73 65 2a 2c 20 53 72 mTerm(Parse*, Sr
23740 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 cList*, Token*,
23750 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 Token*,.
23760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 6f To
23780 6b 65 6e 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 45 ken*, Select*, E
23790 78 70 72 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a xpr*, IdList*);.
237a0 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c void sqlite3SrcL
237b0 69 73 74 49 6e 64 65 78 65 64 42 79 28 50 61 72 istIndexedBy(Par
237c0 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c se *, SrcList *,
237d0 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 Token *);.void
237e0 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 46 75 sqlite3SrcListFu
237f0 6e 63 41 72 67 73 28 50 61 72 73 65 2a 2c 20 53 ncArgs(Parse*, S
23800 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 73 rcList*, ExprLis
23810 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
23820 49 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 28 IndexedByLookup(
23830 50 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 20 Parse *, struct
23840 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 3b SrcList_item *);
23850 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 .void sqlite3Src
23860 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 70 ListShiftJoinTyp
23870 65 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 e(SrcList*);.voi
23880 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 d sqlite3SrcList
23890 41 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 61 AssignCursors(Pa
238a0 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b rse*, SrcList*);
238b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 4c .void sqlite3IdL
238c0 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 istDelete(sqlite
238d0 33 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 3*, IdList*);.vo
238e0 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 id sqlite3SrcLis
238f0 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a tDelete(sqlite3*
23900 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e 64 , SrcList*);.Ind
23910 65 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f 63 ex *sqlite3Alloc
23920 61 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 73 ateIndexObject(s
23930 71 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 2c qlite3*,i16,int,
23940 63 68 61 72 2a 2a 29 3b 0a 49 6e 64 65 78 20 2a char**);.Index *
23950 73 71 6c 69 74 65 33 43 72 65 61 74 65 49 6e 64 sqlite3CreateInd
23960 65 78 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a ex(Parse*,Token*
23970 2c 54 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 2a ,Token*,SrcList*
23980 2c 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 54 ,ExprList*,int,T
23990 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 20 oken*,.
239a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
239b0 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 Expr*, int, int
239c0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
239d0 72 6f 70 49 6e 64 65 78 28 50 61 72 73 65 2a 2c ropIndex(Parse*,
239e0 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 3b SrcList*, int);
239f0 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 .int sqlite3Sele
23a00 63 74 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 ct(Parse*, Selec
23a10 74 2a 2c 20 53 65 6c 65 63 74 44 65 73 74 2a 29 t*, SelectDest*)
23a20 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 74 65 ;.Select *sqlite
23a30 33 53 65 6c 65 63 74 4e 65 77 28 50 61 72 73 65 3SelectNew(Parse
23a40 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 72 63 4c *,ExprList*,SrcL
23a50 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c ist*,Expr*,ExprL
23a60 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 ist*,.
23a70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 45 E
23a80 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 75 xpr*,ExprList*,u
23a90 31 36 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 3b 16,Expr*,Expr*);
23aa0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c .void sqlite3Sel
23ab0 65 63 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 ectDelete(sqlite
23ac0 33 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 54 61 3*, Select*);.Ta
23ad0 62 6c 65 20 2a 73 71 6c 69 74 65 33 53 72 63 4c ble *sqlite3SrcL
23ae0 69 73 74 4c 6f 6f 6b 75 70 28 50 61 72 73 65 2a istLookup(Parse*
23af0 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 , SrcList*);.int
23b00 20 73 71 6c 69 74 65 33 49 73 52 65 61 64 4f 6e sqlite3IsReadOn
23b10 6c 79 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 ly(Parse*, Table
23b20 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
23b30 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 28 50 lite3OpenTable(P
23b40 61 72 73 65 2a 2c 20 69 6e 74 20 69 43 75 72 2c arse*, int iCur,
23b50 20 69 6e 74 20 69 44 62 2c 20 54 61 62 6c 65 2a int iDb, Table*
23b60 2c 20 69 6e 74 29 3b 0a 23 69 66 20 64 65 66 69 , int);.#if defi
23b70 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c ned(SQLITE_ENABL
23b80 45 5f 55 50 44 41 54 45 5f 44 45 4c 45 54 45 5f E_UPDATE_DELETE_
23b90 4c 49 4d 49 54 29 20 26 26 20 21 64 65 66 69 6e LIMIT) && !defin
23ba0 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 ed(SQLITE_OMIT_S
23bb0 55 42 51 55 45 52 59 29 0a 45 78 70 72 20 2a 73 UBQUERY).Expr *s
23bc0 71 6c 69 74 65 33 4c 69 6d 69 74 57 68 65 72 65 qlite3LimitWhere
23bd0 28 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a (Parse*,SrcList*
23be0 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a ,Expr*,ExprList*
23bf0 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 63 68 61 ,Expr*,Expr*,cha
23c00 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 r*);.#endif.void
23c10 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 46 72 sqlite3DeleteFr
23c20 6f 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 om(Parse*, SrcLi
23c30 73 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 st*, Expr*);.voi
23c40 64 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 28 d sqlite3Update(
23c50 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a Parse*, SrcList*
23c60 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 , ExprList*, Exp
23c70 72 2a 2c 20 69 6e 74 29 3b 0a 57 68 65 72 65 49 r*, int);.WhereI
23c80 6e 66 6f 20 2a 73 71 6c 69 74 65 33 57 68 65 72 nfo *sqlite3Wher
23c90 65 42 65 67 69 6e 28 50 61 72 73 65 2a 2c 53 72 eBegin(Parse*,Sr
23ca0 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 cList*,Expr*,Exp
23cb0 72 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 2a rList*,ExprList*
23cc0 2c 75 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 ,u16,int);.void
23cd0 73 71 6c 69 74 65 33 57 68 65 72 65 45 6e 64 28 sqlite3WhereEnd(
23ce0 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 75 36 34 WhereInfo*);.u64
23cf0 20 73 71 6c 69 74 65 33 57 68 65 72 65 4f 75 74 sqlite3WhereOut
23d00 70 75 74 52 6f 77 43 6f 75 6e 74 28 57 68 65 72 putRowCount(Wher
23d10 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23d20 69 74 65 33 57 68 65 72 65 49 73 44 69 73 74 69 ite3WhereIsDisti
23d30 6e 63 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b nct(WhereInfo*);
23d40 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
23d50 65 49 73 4f 72 64 65 72 65 64 28 57 68 65 72 65 eIsOrdered(Where
23d60 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 Info*);.int sqli
23d70 74 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 te3WhereIsSorted
23d80 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e (WhereInfo*);.in
23d90 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 43 6f t sqlite3WhereCo
23da0 6e 74 69 6e 75 65 4c 61 62 65 6c 28 57 68 65 72 ntinueLabel(Wher
23db0 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23dc0 69 74 65 33 57 68 65 72 65 42 72 65 61 6b 4c 61 ite3WhereBreakLa
23dd0 62 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b bel(WhereInfo*);
23de0 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
23df0 65 4f 6b 4f 6e 65 50 61 73 73 28 57 68 65 72 65 eOkOnePass(Where
23e00 49 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b 0a 23 64 Info*, int*);.#d
23e10 65 66 69 6e 65 20 4f 4e 45 50 41 53 53 5f 4f 46 efine ONEPASS_OF
23e20 46 20 20 20 20 20 20 30 20 20 20 20 20 20 20 20 F 0
23e30 2f 2a 20 55 73 65 20 6f 66 20 4f 4e 45 50 41 53 /* Use of ONEPAS
23e40 53 20 6e 6f 74 20 61 6c 6c 6f 77 65 64 20 2a 2f S not allowed */
23e50 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 53 .#define ONEPASS
23e60 5f 53 49 4e 47 4c 45 20 20 20 31 20 20 20 20 20 _SINGLE 1
23e70 20 20 20 2f 2a 20 4f 4e 45 50 41 53 53 20 76 61 /* ONEPASS va
23e80 6c 69 64 20 66 6f 72 20 61 20 73 69 6e 67 6c 65 lid for a single
23e90 20 72 6f 77 20 75 70 64 61 74 65 20 2a 2f 0a 23 row update */.#
23ea0 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 53 5f 4d define ONEPASS_M
23eb0 55 4c 54 49 20 20 20 20 32 20 20 20 20 20 20 20 ULTI 2
23ec0 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 73 20 76 /* ONEPASS is v
23ed0 61 6c 69 64 20 66 6f 72 20 6d 75 6c 74 69 70 6c alid for multipl
23ee0 65 20 72 6f 77 73 20 2a 2f 0a 76 6f 69 64 20 73 e rows */.void s
23ef0 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 4c 6f qlite3ExprCodeLo
23f00 61 64 49 6e 64 65 78 43 6f 6c 75 6d 6e 28 50 61 adIndexColumn(Pa
23f10 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c 20 69 6e rse*, Index*, in
23f20 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 69 6e t, int, int);.in
23f30 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 t sqlite3ExprCod
23f40 65 47 65 74 43 6f 6c 75 6d 6e 28 50 61 72 73 65 eGetColumn(Parse
23f50 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 *, Table*, int,
23f60 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 76 int, int, u8);.v
23f70 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
23f80 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 4f 66 54 61 odeGetColumnOfTa
23f90 62 6c 65 28 56 64 62 65 2a 2c 20 54 61 62 6c 65 ble(Vdbe*, Table
23fa0 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
23fb0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
23fc0 78 70 72 43 6f 64 65 4d 6f 76 65 28 50 61 72 73 xprCodeMove(Pars
23fd0 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e e*, int, int, in
23fe0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
23ff0 45 78 70 72 43 61 63 68 65 53 74 6f 72 65 28 50 ExprCacheStore(P
24000 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c arse*, int, int,
24010 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
24020 74 65 33 45 78 70 72 43 61 63 68 65 50 75 73 68 te3ExprCachePush
24030 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 (Parse*);.void s
24040 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 50 qlite3ExprCacheP
24050 6f 70 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 op(Parse*);.void
24060 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 sqlite3ExprCach
24070 65 52 65 6d 6f 76 65 28 50 61 72 73 65 2a 2c 20 eRemove(Parse*,
24080 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
24090 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 sqlite3ExprCache
240a0 43 6c 65 61 72 28 50 61 72 73 65 2a 29 3b 0a 76 Clear(Parse*);.v
240b0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
240c0 61 63 68 65 41 66 66 69 6e 69 74 79 43 68 61 6e acheAffinityChan
240d0 67 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 ge(Parse*, int,
240e0 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
240f0 65 33 45 78 70 72 43 6f 64 65 28 50 61 72 73 65 e3ExprCode(Parse
24100 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
24110 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
24120 43 6f 64 65 46 61 63 74 6f 72 61 62 6c 65 28 50 CodeFactorable(P
24130 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
24140 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
24150 45 78 70 72 43 6f 64 65 41 74 49 6e 69 74 28 50 ExprCodeAtInit(P
24160 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
24170 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 t, u8);.int sqli
24180 74 65 33 45 78 70 72 43 6f 64 65 54 65 6d 70 28 te3ExprCodeTemp(
24190 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
241a0 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
241b0 33 45 78 70 72 43 6f 64 65 54 61 72 67 65 74 28 3ExprCodeTarget(
241c0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
241d0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
241e0 33 45 78 70 72 43 6f 64 65 41 6e 64 43 61 63 68 3ExprCodeAndCach
241f0 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c e(Parse*, Expr*,
24200 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
24210 65 33 45 78 70 72 43 6f 64 65 45 78 70 72 4c 69 e3ExprCodeExprLi
24220 73 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 4c st(Parse*, ExprL
24230 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 ist*, int, int,
24240 75 38 29 3b 0a 23 64 65 66 69 6e 65 20 53 51 4c u8);.#define SQL
24250 49 54 45 5f 45 43 45 4c 5f 44 55 50 20 20 20 20 ITE_ECEL_DUP
24260 20 20 30 78 30 31 20 20 2f 2a 20 44 65 65 70 2c 0x01 /* Deep,
24270 20 6e 6f 74 20 73 68 61 6c 6c 6f 77 20 63 6f 70 not shallow cop
24280 69 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ies */.#define S
24290 51 4c 49 54 45 5f 45 43 45 4c 5f 46 41 43 54 4f QLITE_ECEL_FACTO
242a0 52 20 20 20 30 78 30 32 20 20 2f 2a 20 46 61 63 R 0x02 /* Fac
242b0 74 6f 72 20 6f 75 74 20 63 6f 6e 73 74 61 6e 74 tor out constant
242c0 20 74 65 72 6d 73 20 2a 2f 0a 23 64 65 66 69 6e terms */.#defin
242d0 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 52 45 e SQLITE_ECEL_RE
242e0 46 20 20 20 20 20 20 30 78 30 34 20 20 2f 2a 20 F 0x04 /*
242f0 55 73 65 20 45 78 70 72 4c 69 73 74 2e 75 2e 78 Use ExprList.u.x
24300 2e 69 4f 72 64 65 72 42 79 43 6f 6c 20 2a 2f 0a .iOrderByCol */.
24310 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
24320 49 66 54 72 75 65 28 50 61 72 73 65 2a 2c 20 45 IfTrue(Parse*, E
24330 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b xpr*, int, int);
24340 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
24350 72 49 66 46 61 6c 73 65 28 50 61 72 73 65 2a 2c rIfFalse(Parse*,
24360 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 Expr*, int, int
24370 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
24380 78 70 72 49 66 46 61 6c 73 65 44 75 70 28 50 61 xprIfFalseDup(Pa
24390 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 rse*, Expr*, int
243a0 2c 20 69 6e 74 29 3b 0a 54 61 62 6c 65 20 2a 73 , int);.Table *s
243b0 71 6c 69 74 65 33 46 69 6e 64 54 61 62 6c 65 28 qlite3FindTable(
243c0 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
243d0 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 har*, const char
243e0 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 *);.Table *sqlit
243f0 65 33 4c 6f 63 61 74 65 54 61 62 6c 65 28 50 61 e3LocateTable(Pa
24400 72 73 65 2a 2c 69 6e 74 20 69 73 56 69 65 77 2c rse*,int isView,
24410 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
24420 73 74 20 63 68 61 72 2a 29 3b 0a 54 61 62 6c 65 st char*);.Table
24430 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 *sqlite3LocateT
24440 61 62 6c 65 49 74 65 6d 28 50 61 72 73 65 2a 2c ableItem(Parse*,
24450 69 6e 74 20 69 73 56 69 65 77 2c 73 74 72 75 63 int isView,struc
24460 74 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a t SrcList_item *
24470 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 74 65 );.Index *sqlite
24480 33 46 69 6e 64 49 6e 64 65 78 28 73 71 6c 69 74 3FindIndex(sqlit
24490 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c e3*,const char*,
244a0 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 const char*);.v
244b0 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e oid sqlite3Unlin
244c0 6b 41 6e 64 44 65 6c 65 74 65 54 61 62 6c 65 28 kAndDeleteTable(
244d0 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e sqlite3*,int,con
244e0 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
244f0 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 sqlite3UnlinkAnd
24500 44 65 6c 65 74 65 49 6e 64 65 78 28 73 71 6c 69 DeleteIndex(sqli
24510 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 te3*,int,const c
24520 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
24530 74 65 33 56 61 63 75 75 6d 28 50 61 72 73 65 2a te3Vacuum(Parse*
24540 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 75 );.int sqlite3Ru
24550 6e 56 61 63 75 75 6d 28 63 68 61 72 2a 2a 2c 20 nVacuum(char**,
24560 73 71 6c 69 74 65 33 2a 29 3b 0a 63 68 61 72 20 sqlite3*);.char
24570 2a 73 71 6c 69 74 65 33 4e 61 6d 65 46 72 6f 6d *sqlite3NameFrom
24580 54 6f 6b 65 6e 28 73 71 6c 69 74 65 33 2a 2c 20 Token(sqlite3*,
24590 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
245a0 69 74 65 33 45 78 70 72 43 6f 6d 70 61 72 65 28 ite3ExprCompare(
245b0 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e Expr*, Expr*, in
245c0 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 t);.int sqlite3E
245d0 78 70 72 4c 69 73 74 43 6f 6d 70 61 72 65 28 45 xprListCompare(E
245e0 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 xprList*, ExprLi
245f0 73 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 st*, int);.int s
24600 71 6c 69 74 65 33 45 78 70 72 49 6d 70 6c 69 65 qlite3ExprImplie
24610 73 45 78 70 72 28 45 78 70 72 2a 2c 20 45 78 70 sExpr(Expr*, Exp
24620 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 r*, int);.void s
24630 71 6c 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a qlite3ExprAnalyz
24640 65 41 67 67 72 65 67 61 74 65 73 28 4e 61 6d 65 eAggregates(Name
24650 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a 29 Context*, Expr*)
24660 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
24670 70 72 41 6e 61 6c 79 7a 65 41 67 67 4c 69 73 74 prAnalyzeAggList
24680 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 45 78 (NameContext*,Ex
24690 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 prList*);.int sq
246a0 6c 69 74 65 33 46 75 6e 63 74 69 6f 6e 55 73 65 lite3FunctionUse
246b0 73 54 68 69 73 53 72 63 28 45 78 70 72 2a 2c 20 sThisSrc(Expr*,
246c0 53 72 63 4c 69 73 74 2a 29 3b 0a 56 64 62 65 20 SrcList*);.Vdbe
246d0 2a 73 71 6c 69 74 65 33 47 65 74 56 64 62 65 28 *sqlite3GetVdbe(
246e0 50 61 72 73 65 2a 29 3b 0a 23 69 66 6e 64 65 66 Parse*);.#ifndef
246f0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 SQLITE_OMIT_BUI
24700 4c 54 49 4e 5f 54 45 53 54 0a 76 6f 69 64 20 73 LTIN_TEST.void s
24710 71 6c 69 74 65 33 50 72 6e 67 53 61 76 65 53 74 qlite3PrngSaveSt
24720 61 74 65 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 ate(void);.void
24730 73 71 6c 69 74 65 33 50 72 6e 67 52 65 73 74 6f sqlite3PrngResto
24740 72 65 53 74 61 74 65 28 76 6f 69 64 29 3b 0a 23 reState(void);.#
24750 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
24760 65 33 52 6f 6c 6c 62 61 63 6b 41 6c 6c 28 73 71 e3RollbackAll(sq
24770 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 lite3*,int);.voi
24780 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 72 d sqlite3CodeVer
24790 69 66 79 53 63 68 65 6d 61 28 50 61 72 73 65 2a ifySchema(Parse*
247a0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
247b0 69 74 65 33 43 6f 64 65 56 65 72 69 66 79 4e 61 ite3CodeVerifyNa
247c0 6d 65 64 53 63 68 65 6d 61 28 50 61 72 73 65 2a medSchema(Parse*
247d0 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 , const char *zD
247e0 62 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 b);.void sqlite3
247f0 42 65 67 69 6e 54 72 61 6e 73 61 63 74 69 6f 6e BeginTransaction
24800 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 (Parse*, int);.v
24810 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 6d 69 oid sqlite3Commi
24820 74 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 tTransaction(Par
24830 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 se*);.void sqlit
24840 65 33 52 6f 6c 6c 62 61 63 6b 54 72 61 6e 73 61 e3RollbackTransa
24850 63 74 69 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 ction(Parse*);.v
24860 6f 69 64 20 73 71 6c 69 74 65 33 53 61 76 65 70 oid sqlite3Savep
24870 6f 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 oint(Parse*, int
24880 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
24890 73 71 6c 69 74 65 33 43 6c 6f 73 65 53 61 76 65 sqlite3CloseSave
248a0 70 6f 69 6e 74 73 28 73 71 6c 69 74 65 33 20 2a points(sqlite3 *
248b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4c );.void sqlite3L
248c0 65 61 76 65 4d 75 74 65 78 41 6e 64 43 6c 6f 73 eaveMutexAndClos
248d0 65 5a 6f 6d 62 69 65 28 73 71 6c 69 74 65 33 2a eZombie(sqlite3*
248e0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
248f0 70 72 49 73 43 6f 6e 73 74 61 6e 74 28 45 78 70 prIsConstant(Exp
24900 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
24910 45 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4e 6f ExprIsConstantNo
24920 74 4a 6f 69 6e 28 45 78 70 72 2a 29 3b 0a 69 6e tJoin(Expr*);.in
24930 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 43 t sqlite3ExprIsC
24940 6f 6e 73 74 61 6e 74 4f 72 46 75 6e 63 74 69 6f onstantOrFunctio
24950 6e 28 45 78 70 72 2a 2c 20 75 38 29 3b 0a 69 6e n(Expr*, u8);.in
24960 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 54 t sqlite3ExprIsT
24970 61 62 6c 65 43 6f 6e 73 74 61 6e 74 28 45 78 70 ableConstant(Exp
24980 72 2a 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c r*,int);.int sql
24990 69 74 65 33 45 78 70 72 49 73 49 6e 74 65 67 65 ite3ExprIsIntege
249a0 72 28 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a r(Expr*, int*);.
249b0 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
249c0 61 6e 42 65 4e 75 6c 6c 28 63 6f 6e 73 74 20 45 anBeNull(const E
249d0 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 xpr*);.int sqlit
249e0 65 33 45 78 70 72 4e 65 65 64 73 4e 6f 41 66 66 e3ExprNeedsNoAff
249f0 69 6e 69 74 79 43 68 61 6e 67 65 28 63 6f 6e 73 inityChange(cons
24a00 74 20 45 78 70 72 2a 2c 20 63 68 61 72 29 3b 0a t Expr*, char);.
24a10 69 6e 74 20 73 71 6c 69 74 65 33 49 73 52 6f 77 int sqlite3IsRow
24a20 69 64 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b id(const char*);
24a30 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
24a40 65 72 61 74 65 52 6f 77 44 65 6c 65 74 65 28 0a erateRowDelete(.
24a50 20 20 20 20 50 61 72 73 65 2a 2c 54 61 62 6c 65 Parse*,Table
24a60 2a 2c 54 72 69 67 67 65 72 2a 2c 69 6e 74 2c 69 *,Trigger*,int,i
24a70 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 38 2c 75 38 nt,int,i16,u8,u8
24a80 2c 75 38 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 ,u8,int);.void s
24a90 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f qlite3GenerateRo
24aa0 77 49 6e 64 65 78 44 65 6c 65 74 65 28 50 61 72 wIndexDelete(Par
24ab0 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
24ac0 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 , int, int*, int
24ad0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 );.int sqlite3Ge
24ae0 6e 65 72 61 74 65 49 6e 64 65 78 4b 65 79 28 50 nerateIndexKey(P
24af0 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c 20 69 arse*, Index*, i
24b00 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e nt, int, int, in
24b10 74 2a 2c 49 6e 64 65 78 2a 2c 69 6e 74 29 3b 0a t*,Index*,int);.
24b20 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 6f void sqlite3Reso
24b30 6c 76 65 50 61 72 74 49 64 78 4c 61 62 65 6c 28 lvePartIdxLabel(
24b40 50 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 Parse*,int);.voi
24b50 64 20 73 71 6c 69 74 65 33 47 65 6e 65 72 61 74 d sqlite3Generat
24b60 65 43 6f 6e 73 74 72 61 69 6e 74 43 68 65 63 6b eConstraintCheck
24b70 73 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c s(Parse*,Table*,
24b80 69 6e 74 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 int*,int,int,int
24b90 2c 69 6e 74 2c 0a 20 20 20 20 20 20 20 20 20 20 ,int,.
24ba0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24bb0 20 20 20 20 20 20 20 20 20 20 20 75 38 2c 75 38 u8,u8
24bc0 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a 76 6f 69 64 ,int,int*);.void
24bd0 20 73 71 6c 69 74 65 33 43 6f 6d 70 6c 65 74 65 sqlite3Complete
24be0 49 6e 73 65 72 74 69 6f 6e 28 50 61 72 73 65 2a Insertion(Parse*
24bf0 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 69 6e 74 2c ,Table*,int,int,
24c00 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2c 69 6e 74 int,int*,int,int
24c10 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ,int);.int sqlit
24c20 65 33 4f 70 65 6e 54 61 62 6c 65 41 6e 64 49 6e e3OpenTableAndIn
24c30 64 69 63 65 73 28 50 61 72 73 65 2a 2c 20 54 61 dices(Parse*, Ta
24c40 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 ble*, int, int,
24c50 75 38 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 u8*, int*, int*)
24c60 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 ;.void sqlite3Be
24c70 67 69 6e 57 72 69 74 65 4f 70 65 72 61 74 69 6f ginWriteOperatio
24c80 6e 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 n(Parse*, int, i
24c90 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
24ca0 33 4d 75 6c 74 69 57 72 69 74 65 28 50 61 72 73 3MultiWrite(Pars
24cb0 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
24cc0 33 4d 61 79 41 62 6f 72 74 28 50 61 72 73 65 2a 3MayAbort(Parse*
24cd0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 48 );.void sqlite3H
24ce0 61 6c 74 43 6f 6e 73 74 72 61 69 6e 74 28 50 61 altConstraint(Pa
24cf0 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 rse*, int, int,
24d00 63 68 61 72 2a 2c 20 69 38 2c 20 75 38 29 3b 0a char*, i8, u8);.
24d10 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 69 71 void sqlite3Uniq
24d20 75 65 43 6f 6e 73 74 72 61 69 6e 74 28 50 61 72 ueConstraint(Par
24d30 73 65 2a 2c 20 69 6e 74 2c 20 49 6e 64 65 78 2a se*, int, Index*
24d40 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
24d50 6f 77 69 64 43 6f 6e 73 74 72 61 69 6e 74 28 50 owidConstraint(P
24d60 61 72 73 65 2a 2c 20 69 6e 74 2c 20 54 61 62 6c arse*, int, Tabl
24d70 65 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 e*);.Expr *sqlit
24d80 65 33 45 78 70 72 44 75 70 28 73 71 6c 69 74 65 e3ExprDup(sqlite
24d90 33 2a 2c 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 45 3*,Expr*,int);.E
24da0 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 xprList *sqlite3
24db0 45 78 70 72 4c 69 73 74 44 75 70 28 73 71 6c 69 ExprListDup(sqli
24dc0 74 65 33 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 te3*,ExprList*,i
24dd0 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 2a 73 71 nt);.SrcList *sq
24de0 6c 69 74 65 33 53 72 63 4c 69 73 74 44 75 70 28 lite3SrcListDup(
24df0 73 71 6c 69 74 65 33 2a 2c 53 72 63 4c 69 73 74 sqlite3*,SrcList
24e00 2a 2c 69 6e 74 29 3b 0a 49 64 4c 69 73 74 20 2a *,int);.IdList *
24e10 73 71 6c 69 74 65 33 49 64 4c 69 73 74 44 75 70 sqlite3IdListDup
24e20 28 73 71 6c 69 74 65 33 2a 2c 49 64 4c 69 73 74 (sqlite3*,IdList
24e30 2a 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 *);.Select *sqli
24e40 74 65 33 53 65 6c 65 63 74 44 75 70 28 73 71 6c te3SelectDup(sql
24e50 69 74 65 33 2a 2c 53 65 6c 65 63 74 2a 2c 69 6e ite3*,Select*,in
24e60 74 29 3b 0a 23 69 66 20 53 45 4c 45 43 54 54 52 t);.#if SELECTTR
24e70 41 43 45 5f 45 4e 41 42 4c 45 44 0a 76 6f 69 64 ACE_ENABLED.void
24e80 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 53 65 sqlite3SelectSe
24e90 74 4e 61 6d 65 28 53 65 6c 65 63 74 2a 2c 63 6f tName(Select*,co
24ea0 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 nst char*);.#els
24eb0 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
24ec0 65 33 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 28 e3SelectSetName(
24ed0 41 2c 42 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 A,B).#endif.void
24ee0 20 73 71 6c 69 74 65 33 46 75 6e 63 44 65 66 49 sqlite3FuncDefI
24ef0 6e 73 65 72 74 28 46 75 6e 63 44 65 66 48 61 73 nsert(FuncDefHas
24f00 68 2a 2c 20 46 75 6e 63 44 65 66 2a 29 3b 0a 46 h*, FuncDef*);.F
24f10 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 65 33 46 uncDef *sqlite3F
24f20 69 6e 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 indFunction(sqli
24f30 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
24f40 2c 69 6e 74 2c 69 6e 74 2c 75 38 2c 75 38 29 3b ,int,int,u8,u8);
24f50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 .void sqlite3Reg
24f60 69 73 74 65 72 42 75 69 6c 74 69 6e 46 75 6e 63 isterBuiltinFunc
24f70 74 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b tions(sqlite3*);
24f80 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 .void sqlite3Reg
24f90 69 73 74 65 72 44 61 74 65 54 69 6d 65 46 75 6e isterDateTimeFun
24fa0 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 76 6f ctions(void);.vo
24fb0 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 73 74 id sqlite3Regist
24fc0 65 72 47 6c 6f 62 61 6c 46 75 6e 63 74 69 6f 6e erGlobalFunction
24fd0 73 28 76 6f 69 64 29 3b 0a 69 6e 74 20 73 71 6c s(void);.int sql
24fe0 69 74 65 33 53 61 66 65 74 79 43 68 65 63 6b 4f ite3SafetyCheckO
24ff0 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 k(sqlite3*);.int
25000 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 43 68 sqlite3SafetyCh
25010 65 63 6b 53 69 63 6b 4f 72 4f 6b 28 73 71 6c 69 eckSickOrOk(sqli
25020 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 te3*);.void sqli
25030 74 65 33 43 68 61 6e 67 65 43 6f 6f 6b 69 65 28 te3ChangeCookie(
25040 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 0a 23 Parse*, int);..#
25050 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
25060 54 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 26 26 TE_OMIT_VIEW) &&
25070 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
25080 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 0a 76 _OMIT_TRIGGER).v
25090 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 74 65 72 oid sqlite3Mater
250a0 69 61 6c 69 7a 65 56 69 65 77 28 50 61 72 73 65 ializeView(Parse
250b0 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a *, Table*, Expr*
250c0 2c 20 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a , int);.#endif..
250d0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
250e0 4d 49 54 5f 54 52 49 47 47 45 52 0a 20 20 76 6f MIT_TRIGGER. vo
250f0 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 6e 54 id sqlite3BeginT
25100 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 54 rigger(Parse*, T
25110 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 oken*,Token*,int
25120 2c 69 6e 74 2c 49 64 4c 69 73 74 2a 2c 53 72 63 ,int,IdList*,Src
25130 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 List*,.
25140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25150 20 20 45 78 70 72 2a 2c 69 6e 74 2c 20 69 6e 74 Expr*,int, int
25160 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
25170 33 46 69 6e 69 73 68 54 72 69 67 67 65 72 28 50 3FinishTrigger(P
25180 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 53 74 arse*, TriggerSt
25190 65 70 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 20 20 ep*, Token*);.
251a0 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 void sqlite3Drop
251b0 54 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 Trigger(Parse*,
251c0 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a SrcList*, int);.
251d0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 void sqlite3Dr
251e0 6f 70 54 72 69 67 67 65 72 50 74 72 28 50 61 72 opTriggerPtr(Par
251f0 73 65 2a 2c 20 54 72 69 67 67 65 72 2a 29 3b 0a se*, Trigger*);.
25200 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 Trigger *sqlit
25210 65 33 54 72 69 67 67 65 72 73 45 78 69 73 74 28 e3TriggersExist(
25220 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 2a 2c Parse *, Table*,
25230 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c int, ExprList*,
25240 20 69 6e 74 20 2a 70 4d 61 73 6b 29 3b 0a 20 20 int *pMask);.
25250 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 65 33 Trigger *sqlite3
25260 54 72 69 67 67 65 72 4c 69 73 74 28 50 61 72 73 TriggerList(Pars
25270 65 20 2a 2c 20 54 61 62 6c 65 20 2a 29 3b 0a 20 e *, Table *);.
25280 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 void sqlite3Cod
25290 65 52 6f 77 54 72 69 67 67 65 72 28 50 61 72 73 eRowTrigger(Pars
252a0 65 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c 20 69 e*, Trigger *, i
252b0 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 nt, ExprList*, i
252c0 6e 74 2c 20 54 61 62 6c 65 20 2a 2c 0a 20 20 20 nt, Table *,.
252d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
252e0 20 20 20 20 20 20 20 20 20 69 6e 74 2c 20 69 6e int, in
252f0 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 t, int);. void
25300 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 sqlite3CodeRowTr
25310 69 67 67 65 72 44 69 72 65 63 74 28 50 61 72 73 iggerDirect(Pars
25320 65 20 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c 20 e *, Trigger *,
25330 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c 20 69 6e Table *, int, in
25340 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 t, int);. void
25350 73 71 6c 69 74 65 56 69 65 77 54 72 69 67 67 65 sqliteViewTrigge
25360 72 73 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 rs(Parse*, Table
25370 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 45 *, Expr*, int, E
25380 78 70 72 4c 69 73 74 2a 29 3b 0a 20 20 76 6f 69 xprList*);. voi
25390 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 54 d sqlite3DeleteT
253a0 72 69 67 67 65 72 53 74 65 70 28 73 71 6c 69 74 riggerStep(sqlit
253b0 65 33 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 e3*, TriggerStep
253c0 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 *);. TriggerSte
253d0 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 p *sqlite3Trigge
253e0 72 53 65 6c 65 63 74 53 74 65 70 28 73 71 6c 69 rSelectStep(sqli
253f0 74 65 33 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a 20 te3*,Select*);.
25400 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 71 TriggerStep *sq
25410 6c 69 74 65 33 54 72 69 67 67 65 72 49 6e 73 65 lite3TriggerInse
25420 72 74 53 74 65 70 28 73 71 6c 69 74 65 33 2a 2c rtStep(sqlite3*,
25430 54 6f 6b 65 6e 2a 2c 20 49 64 4c 69 73 74 2a 2c Token*, IdList*,
25440 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
25450 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25460 20 20 20 20 20 20 20 20 20 53 65 6c 65 63 74 2a Select*
25470 2c 75 38 29 3b 0a 20 20 54 72 69 67 67 65 72 53 ,u8);. TriggerS
25480 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 tep *sqlite3Trig
25490 67 65 72 55 70 64 61 74 65 53 74 65 70 28 73 71 gerUpdateStep(sq
254a0 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 lite3*,Token*,Ex
254b0 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 2a 2c 20 prList*, Expr*,
254c0 75 38 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 u8);. TriggerSt
254d0 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 ep *sqlite3Trigg
254e0 65 72 44 65 6c 65 74 65 53 74 65 70 28 73 71 6c erDeleteStep(sql
254f0 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 45 78 ite3*,Token*, Ex
25500 70 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c pr*);. void sql
25510 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 67 65 ite3DeleteTrigge
25520 72 28 73 71 6c 69 74 65 33 2a 2c 20 54 72 69 67 r(sqlite3*, Trig
25530 67 65 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 ger*);. void sq
25540 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 lite3UnlinkAndDe
25550 6c 65 74 65 54 72 69 67 67 65 72 28 73 71 6c 69 leteTrigger(sqli
25560 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 te3*,int,const c
25570 68 61 72 2a 29 3b 0a 20 20 75 33 32 20 73 71 6c har*);. u32 sql
25580 69 74 65 33 54 72 69 67 67 65 72 43 6f 6c 6d 61 ite3TriggerColma
25590 73 6b 28 50 61 72 73 65 2a 2c 54 72 69 67 67 65 sk(Parse*,Trigge
255a0 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 r*,ExprList*,int
255b0 2c 69 6e 74 2c 54 61 62 6c 65 2a 2c 69 6e 74 29 ,int,Table*,int)
255c0 3b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ;.# define sqlit
255d0 65 33 50 61 72 73 65 54 6f 70 6c 65 76 65 6c 28 e3ParseToplevel(
255e0 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 6c 65 76 p) ((p)->pToplev
255f0 65 6c 20 3f 20 28 70 29 2d 3e 70 54 6f 70 6c 65 el ? (p)->pTople
25600 76 65 6c 20 3a 20 28 70 29 29 0a 23 65 6c 73 65 vel : (p)).#else
25610 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
25620 33 54 72 69 67 67 65 72 73 45 78 69 73 74 28 42 3TriggersExist(B
25630 2c 43 2c 44 2c 45 2c 46 29 20 30 0a 23 20 64 65 ,C,D,E,F) 0.# de
25640 66 69 6e 65 20 73 71 6c 69 74 65 33 44 65 6c 65 fine sqlite3Dele
25650 74 65 54 72 69 67 67 65 72 28 41 2c 42 29 0a 23 teTrigger(A,B).#
25660 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 44 define sqlite3D
25670 72 6f 70 54 72 69 67 67 65 72 50 74 72 28 41 2c ropTriggerPtr(A,
25680 42 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 B).# define sqli
25690 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 te3UnlinkAndDele
256a0 74 65 54 72 69 67 67 65 72 28 41 2c 42 2c 43 29 teTrigger(A,B,C)
256b0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
256c0 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 28 3CodeRowTrigger(
256d0 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 2c 48 2c A,B,C,D,E,F,G,H,
256e0 49 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 I).# define sqli
256f0 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 te3CodeRowTrigge
25700 72 44 69 72 65 63 74 28 41 2c 42 2c 43 2c 44 2c rDirect(A,B,C,D,
25710 45 2c 46 29 0a 23 20 64 65 66 69 6e 65 20 73 71 E,F).# define sq
25720 6c 69 74 65 33 54 72 69 67 67 65 72 4c 69 73 74 lite3TriggerList
25730 28 58 2c 20 59 29 20 30 0a 23 20 64 65 66 69 6e (X, Y) 0.# defin
25740 65 20 73 71 6c 69 74 65 33 50 61 72 73 65 54 6f e sqlite3ParseTo
25750 70 6c 65 76 65 6c 28 70 29 20 70 0a 23 20 64 65 plevel(p) p.# de
25760 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 69 67 fine sqlite3Trig
25770 67 65 72 43 6f 6c 6d 61 73 6b 28 41 2c 42 2c 43 gerColmask(A,B,C
25780 2c 44 2c 45 2c 46 2c 47 29 20 30 0a 23 65 6e 64 ,D,E,F,G) 0.#end
25790 69 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a if..int sqlite3J
257a0 6f 69 6e 54 79 70 65 28 50 61 72 73 65 2a 2c 20 oinType(Parse*,
257b0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Token*, Token*,
257c0 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 Token*);.void sq
257d0 6c 69 74 65 33 43 72 65 61 74 65 46 6f 72 65 69 lite3CreateForei
257e0 67 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 gnKey(Parse*, Ex
257f0 70 72 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c prList*, Token*,
25800 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 ExprList*, int)
25810 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 ;.void sqlite3De
25820 66 65 72 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 ferForeignKey(Pa
25830 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 6e rse*, int);.#ifn
25840 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
25850 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 AUTHORIZATION.
25860 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 68 void sqlite3Auth
25870 52 65 61 64 28 50 61 72 73 65 2a 2c 45 78 70 72 Read(Parse*,Expr
25880 2a 2c 53 63 68 65 6d 61 2a 2c 53 72 63 4c 69 73 *,Schema*,SrcLis
25890 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 t*);. int sqlit
258a0 65 33 41 75 74 68 43 68 65 63 6b 28 50 61 72 73 e3AuthCheck(Pars
258b0 65 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 e*,int, const ch
258c0 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
258d0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
258e0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 void sqlite3Au
258f0 74 68 43 6f 6e 74 65 78 74 50 75 73 68 28 50 61 thContextPush(Pa
25900 72 73 65 2a 2c 20 41 75 74 68 43 6f 6e 74 65 78 rse*, AuthContex
25910 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 t*, const char*)
25920 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
25930 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 41 AuthContextPop(A
25940 75 74 68 43 6f 6e 74 65 78 74 2a 29 3b 0a 20 20 uthContext*);.
25950 69 6e 74 20 73 71 6c 69 74 65 33 41 75 74 68 52 int sqlite3AuthR
25960 65 61 64 43 6f 6c 28 50 61 72 73 65 2a 2c 20 63 eadCol(Parse*, c
25970 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 6f 6e onst char *, con
25980 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b st char *, int);
25990 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
259a0 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 64 28 sqlite3AuthRead(
259b0 61 2c 62 2c 63 2c 64 29 0a 23 20 64 65 66 69 6e a,b,c,d).# defin
259c0 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 68 65 e sqlite3AuthChe
259d0 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 29 20 20 20 ck(a,b,c,d,e)
259e0 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 64 65 66 SQLITE_OK.# def
259f0 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 ine sqlite3AuthC
25a00 6f 6e 74 65 78 74 50 75 73 68 28 61 2c 62 2c 63 ontextPush(a,b,c
25a10 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
25a20 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 e3AuthContextPop
25a30 28 61 29 20 20 28 28 76 6f 69 64 29 28 61 29 29 (a) ((void)(a))
25a40 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c .#endif.void sql
25a50 69 74 65 33 41 74 74 61 63 68 28 50 61 72 73 65 ite3Attach(Parse
25a60 2a 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c *, Expr*, Expr*,
25a70 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 Expr*);.void sq
25a80 6c 69 74 65 33 44 65 74 61 63 68 28 50 61 72 73 lite3Detach(Pars
25a90 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 e*, Expr*);.void
25aa0 20 73 71 6c 69 74 65 33 46 69 78 49 6e 69 74 28 sqlite3FixInit(
25ab0 44 62 46 69 78 65 72 2a 2c 20 50 61 72 73 65 2a DbFixer*, Parse*
25ac0 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 , int, const cha
25ad0 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a r*, const Token*
25ae0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 );.int sqlite3Fi
25af0 78 53 72 63 4c 69 73 74 28 44 62 46 69 78 65 72 xSrcList(DbFixer
25b00 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e *, SrcList*);.in
25b10 74 20 73 71 6c 69 74 65 33 46 69 78 53 65 6c 65 t sqlite3FixSele
25b20 63 74 28 44 62 46 69 78 65 72 2a 2c 20 53 65 6c ct(DbFixer*, Sel
25b30 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ect*);.int sqlit
25b40 65 33 46 69 78 45 78 70 72 28 44 62 46 69 78 65 e3FixExpr(DbFixe
25b50 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 r*, Expr*);.int
25b60 73 71 6c 69 74 65 33 46 69 78 45 78 70 72 4c 69 sqlite3FixExprLi
25b70 73 74 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 st(DbFixer*, Exp
25b80 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c rList*);.int sql
25b90 69 74 65 33 46 69 78 54 72 69 67 67 65 72 53 74 ite3FixTriggerSt
25ba0 65 70 28 44 62 46 69 78 65 72 2a 2c 20 54 72 69 ep(DbFixer*, Tri
25bb0 67 67 65 72 53 74 65 70 2a 29 3b 0a 69 6e 74 20 ggerStep*);.int
25bc0 73 71 6c 69 74 65 33 41 74 6f 46 28 63 6f 6e 73 sqlite3AtoF(cons
25bd0 74 20 63 68 61 72 20 2a 7a 2c 20 64 6f 75 62 6c t char *z, doubl
25be0 65 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e e*, int, u8);.in
25bf0 74 20 73 71 6c 69 74 65 33 47 65 74 49 6e 74 33 t sqlite3GetInt3
25c00 32 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 2(const char *,
25c10 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int*);.int sqlit
25c20 65 33 41 74 6f 69 28 63 6f 6e 73 74 20 63 68 61 e3Atoi(const cha
25c30 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
25c40 55 74 66 31 36 42 79 74 65 4c 65 6e 28 63 6f 6e Utf16ByteLen(con
25c50 73 74 20 76 6f 69 64 20 2a 70 44 61 74 61 2c 20 st void *pData,
25c60 69 6e 74 20 6e 43 68 61 72 29 3b 0a 69 6e 74 20 int nChar);.int
25c70 73 71 6c 69 74 65 33 55 74 66 38 43 68 61 72 4c sqlite3Utf8CharL
25c80 65 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 en(const char *p
25c90 44 61 74 61 2c 20 69 6e 74 20 6e 42 79 74 65 29 Data, int nByte)
25ca0 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 55 74 66 ;.u32 sqlite3Utf
25cb0 38 52 65 61 64 28 63 6f 6e 73 74 20 75 38 2a 2a 8Read(const u8**
25cc0 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 );.LogEst sqlite
25cd0 33 4c 6f 67 45 73 74 28 75 36 34 29 3b 0a 4c 6f 3LogEst(u64);.Lo
25ce0 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 gEst sqlite3LogE
25cf0 73 74 41 64 64 28 4c 6f 67 45 73 74 2c 4c 6f 67 stAdd(LogEst,Log
25d00 45 73 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 Est);.#ifndef SQ
25d10 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
25d20 4c 54 41 42 4c 45 0a 4c 6f 67 45 73 74 20 73 71 LTABLE.LogEst sq
25d30 6c 69 74 65 33 4c 6f 67 45 73 74 46 72 6f 6d 44 lite3LogEstFromD
25d40 6f 75 62 6c 65 28 64 6f 75 62 6c 65 29 3b 0a 23 ouble(double);.#
25d50 65 6e 64 69 66 0a 75 36 34 20 73 71 6c 69 74 65 endif.u64 sqlite
25d60 33 4c 6f 67 45 73 74 54 6f 49 6e 74 28 4c 6f 67 3LogEstToInt(Log
25d70 45 73 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 Est);../*.** Rou
25d80 74 69 6e 65 73 20 74 6f 20 72 65 61 64 20 61 6e tines to read an
25d90 64 20 77 72 69 74 65 20 76 61 72 69 61 62 6c 65 d write variable
25da0 2d 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 72 73 -length integers
25db0 2e 20 20 54 68 65 73 65 20 75 73 65 64 20 74 6f . These used to
25dc0 0a 2a 2a 20 62 65 20 64 65 66 69 6e 65 64 20 6c .** be defined l
25dd0 6f 63 61 6c 6c 79 2c 20 62 75 74 20 6e 6f 77 20 ocally, but now
25de0 77 65 20 75 73 65 20 74 68 65 20 76 61 72 69 6e we use the varin
25df0 74 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 74 68 t routines in th
25e00 65 20 75 74 69 6c 2e 63 0a 2a 2a 20 66 69 6c 65 e util.c.** file
25e10 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 ..*/.int sqlite3
25e20 50 75 74 56 61 72 69 6e 74 28 75 6e 73 69 67 6e PutVarint(unsign
25e30 65 64 20 63 68 61 72 2a 2c 20 75 36 34 29 3b 0a ed char*, u64);.
25e40 75 38 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 u8 sqlite3GetVar
25e50 69 6e 74 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e int(const unsign
25e60 65 64 20 63 68 61 72 20 2a 2c 20 75 36 34 20 2a ed char *, u64 *
25e70 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 );.u8 sqlite3Get
25e80 56 61 72 69 6e 74 33 32 28 63 6f 6e 73 74 20 75 Varint32(const u
25e90 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 nsigned char *,
25ea0 75 33 32 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 u32 *);.int sqli
25eb0 74 65 33 56 61 72 69 6e 74 4c 65 6e 28 75 36 34 te3VarintLen(u64
25ec0 20 76 29 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 v);../*.** The
25ed0 63 6f 6d 6d 6f 6e 20 63 61 73 65 20 69 73 20 66 common case is f
25ee0 6f 72 20 61 20 76 61 72 69 6e 74 20 74 6f 20 62 or a varint to b
25ef0 65 20 61 20 73 69 6e 67 6c 65 20 62 79 74 65 2e e a single byte.
25f00 20 20 54 68 65 79 20 66 6f 6c 6c 6f 77 69 6e 67 They following
25f10 0a 2a 2a 20 6d 61 63 72 6f 73 20 68 61 6e 64 6c .** macros handl
25f20 65 20 74 68 65 20 63 6f 6d 6d 6f 6e 20 63 61 73 e the common cas
25f30 65 20 77 69 74 68 6f 75 74 20 61 20 70 72 6f 63 e without a proc
25f40 65 64 75 72 65 20 63 61 6c 6c 2c 20 62 75 74 20 edure call, but
25f50 74 68 65 6e 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 then call.** the
25f60 20 70 72 6f 63 65 64 75 72 65 20 66 6f 72 20 6c procedure for l
25f70 61 72 67 65 72 20 76 61 72 69 6e 74 73 2e 0a 2a arger varints..*
25f80 2f 0a 23 64 65 66 69 6e 65 20 67 65 74 56 61 72 /.#define getVar
25f90 69 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a 20 20 int32(A,B) \.
25fa0 28 75 38 29 28 28 2a 28 41 29 3c 28 75 38 29 30 (u8)((*(A)<(u8)0
25fb0 78 38 30 29 3f 28 28 42 29 3d 28 75 33 32 29 2a x80)?((B)=(u32)*
25fc0 28 41 29 29 2c 31 3a 73 71 6c 69 74 65 33 47 65 (A)),1:sqlite3Ge
25fd0 74 56 61 72 69 6e 74 33 32 28 28 41 29 2c 28 75 tVarint32((A),(u
25fe0 33 32 20 2a 29 26 28 42 29 29 29 0a 23 64 65 66 32 *)&(B))).#def
25ff0 69 6e 65 20 70 75 74 56 61 72 69 6e 74 33 32 28 ine putVarint32(
26000 41 2c 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 A,B) \. (u8)((
26010 28 75 33 32 29 28 42 29 3c 28 75 33 32 29 30 78 (u32)(B)<(u32)0x
26020 38 30 29 3f 28 2a 28 41 29 3d 28 75 6e 73 69 67 80)?(*(A)=(unsig
26030 6e 65 64 20 63 68 61 72 29 28 42 29 29 2c 31 3a ned char)(B)),1:
26040 5c 0a 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 \. sqlite3PutVa
26050 72 69 6e 74 28 28 41 29 2c 28 42 29 29 29 0a 23 rint((A),(B))).#
26060 64 65 66 69 6e 65 20 67 65 74 56 61 72 69 6e 74 define getVarint
26070 20 20 20 20 73 71 6c 69 74 65 33 47 65 74 56 61 sqlite3GetVa
26080 72 69 6e 74 0a 23 64 65 66 69 6e 65 20 70 75 74 rint.#define put
26090 56 61 72 69 6e 74 20 20 20 20 73 71 6c 69 74 65 Varint sqlite
260a0 33 50 75 74 56 61 72 69 6e 74 0a 0a 0a 63 6f 6e 3PutVarint...con
260b0 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 st char *sqlite3
260c0 49 6e 64 65 78 41 66 66 69 6e 69 74 79 53 74 72 IndexAffinityStr
260d0 28 73 71 6c 69 74 65 33 2a 2c 20 49 6e 64 65 78 (sqlite3*, Index
260e0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
260f0 54 61 62 6c 65 41 66 66 69 6e 69 74 79 28 56 64 TableAffinity(Vd
26100 62 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 be*, Table*, int
26110 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 43 );.char sqlite3C
26120 6f 6d 70 61 72 65 41 66 66 69 6e 69 74 79 28 45 ompareAffinity(E
26130 78 70 72 20 2a 70 45 78 70 72 2c 20 63 68 61 72 xpr *pExpr, char
26140 20 61 66 66 32 29 3b 0a 69 6e 74 20 73 71 6c 69 aff2);.int sqli
26150 74 65 33 49 6e 64 65 78 41 66 66 69 6e 69 74 79 te3IndexAffinity
26160 4f 6b 28 45 78 70 72 20 2a 70 45 78 70 72 2c 20 Ok(Expr *pExpr,
26170 63 68 61 72 20 69 64 78 5f 61 66 66 69 6e 69 74 char idx_affinit
26180 79 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 y);.char sqlite3
26190 45 78 70 72 41 66 66 69 6e 69 74 79 28 45 78 70 ExprAffinity(Exp
261a0 72 20 2a 70 45 78 70 72 29 3b 0a 69 6e 74 20 73 r *pExpr);.int s
261b0 71 6c 69 74 65 33 41 74 6f 69 36 34 28 63 6f 6e qlite3Atoi64(con
261c0 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a 2c 20 st char*, i64*,
261d0 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 int, u8);.int sq
261e0 6c 69 74 65 33 44 65 63 4f 72 48 65 78 54 6f 49 lite3DecOrHexToI
261f0 36 34 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 64(const char*,
26200 69 36 34 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 i64*);.void sqli
26210 74 65 33 45 72 72 6f 72 57 69 74 68 4d 73 67 28 te3ErrorWithMsg(
26220 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 sqlite3*, int, c
26230 6f 6e 73 74 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b onst char*,...);
26240 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 72 72 .void sqlite3Err
26250 6f 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 29 or(sqlite3*,int)
26260 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 48 ;.void *sqlite3H
26270 65 78 54 6f 42 6c 6f 62 28 73 71 6c 69 74 65 33 exToBlob(sqlite3
26280 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a *, const char *z
26290 2c 20 69 6e 74 20 6e 29 3b 0a 75 38 20 73 71 6c , int n);.u8 sql
262a0 69 74 65 33 48 65 78 54 6f 49 6e 74 28 69 6e 74 ite3HexToInt(int
262b0 20 68 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 h);.int sqlite3
262c0 54 77 6f 50 61 72 74 4e 61 6d 65 28 50 61 72 73 TwoPartName(Pars
262d0 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f e *, Token *, To
262e0 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2a 29 ken *, Token **)
262f0 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 ;..#if defined(S
26300 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 52 5f 4e QLITE_NEED_ERR_N
26310 41 4d 45 29 0a 63 6f 6e 73 74 20 63 68 61 72 20 AME).const char
26320 2a 73 71 6c 69 74 65 33 45 72 72 4e 61 6d 65 28 *sqlite3ErrName(
26330 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 63 6f int);.#endif..co
26340 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 nst char *sqlite
26350 33 45 72 72 53 74 72 28 69 6e 74 29 3b 0a 69 6e 3ErrStr(int);.in
26360 74 20 73 71 6c 69 74 65 33 52 65 61 64 53 63 68 t sqlite3ReadSch
26370 65 6d 61 28 50 61 72 73 65 20 2a 70 50 61 72 73 ema(Parse *pPars
26380 65 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c e);.CollSeq *sql
26390 69 74 65 33 46 69 6e 64 43 6f 6c 6c 53 65 71 28 ite3FindCollSeq(
263a0 73 71 6c 69 74 65 33 2a 2c 75 38 20 65 6e 63 2c sqlite3*,u8 enc,
263b0 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 const char*,int
263c0 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 );.CollSeq *sqli
263d0 74 65 33 4c 6f 63 61 74 65 43 6f 6c 6c 53 65 71 te3LocateCollSeq
263e0 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 (Parse *pParse,
263f0 63 6f 6e 73 74 20 63 68 61 72 2a 7a 4e 61 6d 65 const char*zName
26400 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 );.CollSeq *sqli
26410 74 65 33 45 78 70 72 43 6f 6c 6c 53 65 71 28 50 te3ExprCollSeq(P
26420 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 45 78 arse *pParse, Ex
26430 70 72 20 2a 70 45 78 70 72 29 3b 0a 45 78 70 72 pr *pExpr);.Expr
26440 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 64 64 *sqlite3ExprAdd
26450 43 6f 6c 6c 61 74 65 54 6f 6b 65 6e 28 50 61 72 CollateToken(Par
26460 73 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 se *pParse, Expr
26470 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c *, const Token*,
26480 20 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 71 6c int);.Expr *sql
26490 69 74 65 33 45 78 70 72 41 64 64 43 6f 6c 6c 61 ite3ExprAddColla
264a0 74 65 53 74 72 69 6e 67 28 50 61 72 73 65 2a 2c teString(Parse*,
264b0 45 78 70 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 Expr*,const char
264c0 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 *);.Expr *sqlite
264d0 33 45 78 70 72 53 6b 69 70 43 6f 6c 6c 61 74 65 3ExprSkipCollate
264e0 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c (Expr*);.int sql
264f0 69 74 65 33 43 68 65 63 6b 43 6f 6c 6c 53 65 71 ite3CheckCollSeq
26500 28 50 61 72 73 65 20 2a 2c 20 43 6f 6c 6c 53 65 (Parse *, CollSe
26510 71 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 q *);.int sqlite
26520 33 43 68 65 63 6b 4f 62 6a 65 63 74 4e 61 6d 65 3CheckObjectName
26530 28 50 61 72 73 65 20 2a 2c 20 63 6f 6e 73 74 20 (Parse *, const
26540 63 68 61 72 20 2a 29 3b 0a 76 6f 69 64 20 73 71 char *);.void sq
26550 6c 69 74 65 33 56 64 62 65 53 65 74 43 68 61 6e lite3VdbeSetChan
26560 67 65 73 28 73 71 6c 69 74 65 33 20 2a 2c 20 69 ges(sqlite3 *, i
26570 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
26580 41 64 64 49 6e 74 36 34 28 69 36 34 2a 2c 69 36 AddInt64(i64*,i6
26590 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 4);.int sqlite3S
265a0 75 62 49 6e 74 36 34 28 69 36 34 2a 2c 69 36 34 ubInt64(i64*,i64
265b0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 );.int sqlite3Mu
265c0 6c 49 6e 74 36 34 28 69 36 34 2a 2c 69 36 34 29 lInt64(i64*,i64)
265d0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 62 73 ;.int sqlite3Abs
265e0 49 6e 74 33 32 28 69 6e 74 29 3b 0a 23 69 66 64 Int32(int);.#ifd
265f0 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
26600 5f 38 5f 33 5f 4e 41 4d 45 53 0a 76 6f 69 64 20 _8_3_NAMES.void
26610 73 71 6c 69 74 65 33 46 69 6c 65 53 75 66 66 69 sqlite3FileSuffi
26620 78 33 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 x3(const char*,
26630 63 68 61 72 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 char*);.#else.#
26640 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 69 define sqlite3Fi
26650 6c 65 53 75 66 66 69 78 33 28 58 2c 59 29 0a 23 leSuffix3(X,Y).#
26660 65 6e 64 69 66 0a 75 38 20 73 71 6c 69 74 65 33 endif.u8 sqlite3
26670 47 65 74 42 6f 6f 6c 65 61 6e 28 63 6f 6e 73 74 GetBoolean(const
26680 20 63 68 61 72 20 2a 7a 2c 75 38 29 3b 0a 0a 63 char *z,u8);..c
26690 6f 6e 73 74 20 76 6f 69 64 20 2a 73 71 6c 69 74 onst void *sqlit
266a0 65 33 56 61 6c 75 65 54 65 78 74 28 73 71 6c 69 e3ValueText(sqli
266b0 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 38 29 3b te3_value*, u8);
266c0 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 61 6c 75 .int sqlite3Valu
266d0 65 42 79 74 65 73 28 73 71 6c 69 74 65 33 5f 76 eBytes(sqlite3_v
266e0 61 6c 75 65 2a 2c 20 75 38 29 3b 0a 76 6f 69 64 alue*, u8);.void
266f0 20 73 71 6c 69 74 65 33 56 61 6c 75 65 53 65 74 sqlite3ValueSet
26700 53 74 72 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 Str(sqlite3_valu
26710 65 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 76 e*, int, const v
26720 6f 69 64 20 2a 2c 75 38 2c 20 0a 20 20 20 20 20 oid *,u8, .
26730 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26740 20 20 20 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a void(*)(void*
26750 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 ));.void sqlite3
26760 56 61 6c 75 65 53 65 74 4e 75 6c 6c 28 73 71 6c ValueSetNull(sql
26770 69 74 65 33 5f 76 61 6c 75 65 2a 29 3b 0a 76 6f ite3_value*);.vo
26780 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 65 46 id sqlite3ValueF
26790 72 65 65 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ree(sqlite3_valu
267a0 65 2a 29 3b 0a 73 71 6c 69 74 65 33 5f 76 61 6c e*);.sqlite3_val
267b0 75 65 20 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 ue *sqlite3Value
267c0 4e 65 77 28 73 71 6c 69 74 65 33 20 2a 29 3b 0a New(sqlite3 *);.
267d0 63 68 61 72 20 2a 73 71 6c 69 74 65 33 55 74 66 char *sqlite3Utf
267e0 31 36 74 6f 38 28 73 71 6c 69 74 65 33 20 2a 2c 16to8(sqlite3 *,
267f0 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e const void*, in
26800 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 t, u8);.int sqli
26810 74 65 33 56 61 6c 75 65 46 72 6f 6d 45 78 70 72 te3ValueFromExpr
26820 28 73 71 6c 69 74 65 33 20 2a 2c 20 45 78 70 72 (sqlite3 *, Expr
26830 20 2a 2c 20 75 38 2c 20 75 38 2c 20 73 71 6c 69 *, u8, u8, sqli
26840 74 65 33 5f 76 61 6c 75 65 20 2a 2a 29 3b 0a 76 te3_value **);.v
26850 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 65 oid sqlite3Value
26860 41 70 70 6c 79 41 66 66 69 6e 69 74 79 28 73 71 ApplyAffinity(sq
26870 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 2c 20 75 lite3_value *, u
26880 38 2c 20 75 38 29 3b 0a 23 69 66 6e 64 65 66 20 8, u8);.#ifndef
26890 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 SQLITE_AMALGAMAT
268a0 49 4f 4e 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 ION.extern const
268b0 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 unsigned char s
268c0 71 6c 69 74 65 33 4f 70 63 6f 64 65 50 72 6f 70 qlite3OpcodeProp
268d0 65 72 74 79 5b 5d 3b 0a 65 78 74 65 72 6e 20 63 erty[];.extern c
268e0 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 onst unsigned ch
268f0 61 72 20 73 71 6c 69 74 65 33 55 70 70 65 72 54 ar sqlite3UpperT
26900 6f 4c 6f 77 65 72 5b 5d 3b 0a 65 78 74 65 72 6e oLower[];.extern
26910 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 const unsigned
26920 63 68 61 72 20 73 71 6c 69 74 65 33 43 74 79 70 char sqlite3Ctyp
26930 65 4d 61 70 5b 5d 3b 0a 65 78 74 65 72 6e 20 63 eMap[];.extern c
26940 6f 6e 73 74 20 54 6f 6b 65 6e 20 73 71 6c 69 74 onst Token sqlit
26950 65 33 49 6e 74 54 6f 6b 65 6e 73 5b 5d 3b 0a 65 e3IntTokens[];.e
26960 78 74 65 72 6e 20 53 51 4c 49 54 45 5f 57 53 44 xtern SQLITE_WSD
26970 20 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 43 struct Sqlite3C
26980 6f 6e 66 69 67 20 73 71 6c 69 74 65 33 43 6f 6e onfig sqlite3Con
26990 66 69 67 3b 0a 65 78 74 65 72 6e 20 53 51 4c 49 fig;.extern SQLI
269a0 54 45 5f 57 53 44 20 46 75 6e 63 44 65 66 48 61 TE_WSD FuncDefHa
269b0 73 68 20 73 71 6c 69 74 65 33 47 6c 6f 62 61 6c sh sqlite3Global
269c0 46 75 6e 63 74 69 6f 6e 73 3b 0a 23 69 66 6e 64 Functions;.#ifnd
269d0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 ef SQLITE_OMIT_W
269e0 53 44 0a 65 78 74 65 72 6e 20 69 6e 74 20 73 71 SD.extern int sq
269f0 6c 69 74 65 33 50 65 6e 64 69 6e 67 42 79 74 65 lite3PendingByte
26a00 3b 0a 23 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a ;.#endif.#endif.
26a10 76 6f 69 64 20 73 71 6c 69 74 65 33 52 6f 6f 74 void sqlite3Root
26a20 50 61 67 65 4d 6f 76 65 64 28 73 71 6c 69 74 65 PageMoved(sqlite
26a30 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 3*, int, int, in
26a40 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
26a50 52 65 69 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 Reindex(Parse*,
26a60 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b Token*, Token*);
26a70 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 .void sqlite3Alt
26a80 65 72 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 erFunctions(void
26a90 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
26aa0 6c 74 65 72 52 65 6e 61 6d 65 54 61 62 6c 65 28 lterRenameTable(
26ab0 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a Parse*, SrcList*
26ac0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 , Token*);.int s
26ad0 71 6c 69 74 65 33 47 65 74 54 6f 6b 65 6e 28 63 qlite3GetToken(c
26ae0 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 onst unsigned ch
26af0 61 72 20 2a 2c 20 69 6e 74 20 2a 29 3b 0a 76 6f ar *, int *);.vo
26b00 69 64 20 73 71 6c 69 74 65 33 4e 65 73 74 65 64 id sqlite3Nested
26b10 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 63 6f Parse(Parse*, co
26b20 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b nst char*, ...);
26b30 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
26b40 69 72 65 50 72 65 70 61 72 65 64 53 74 61 74 65 irePreparedState
26b50 6d 65 6e 74 73 28 73 71 6c 69 74 65 33 2a 29 3b ments(sqlite3*);
26b60 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 64 65 .int sqlite3Code
26b70 53 75 62 73 65 6c 65 63 74 28 50 61 72 73 65 20 Subselect(Parse
26b80 2a 2c 20 45 78 70 72 20 2a 2c 20 69 6e 74 2c 20 *, Expr *, int,
26b90 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
26ba0 65 33 53 65 6c 65 63 74 50 72 65 70 28 50 61 72 e3SelectPrep(Par
26bb0 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 4e 61 se*, Select*, Na
26bc0 6d 65 43 6f 6e 74 65 78 74 2a 29 3b 0a 76 6f 69 meContext*);.voi
26bd0 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 57 d sqlite3SelectW
26be0 72 6f 6e 67 4e 75 6d 54 65 72 6d 73 45 72 72 6f rongNumTermsErro
26bf0 72 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c r(Parse *pParse,
26c00 20 53 65 6c 65 63 74 20 2a 70 29 3b 0a 69 6e 74 Select *p);.int
26c10 20 73 71 6c 69 74 65 33 4d 61 74 63 68 53 70 61 sqlite3MatchSpa
26c20 6e 4e 61 6d 65 28 63 6f 6e 73 74 20 63 68 61 72 nName(const char
26c30 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 *, const char*,
26c40 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
26c50 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 20 73 st char*);.int s
26c60 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 45 78 70 qlite3ResolveExp
26c70 72 4e 61 6d 65 73 28 4e 61 6d 65 43 6f 6e 74 65 rNames(NameConte
26c80 78 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 xt*, Expr*);.int
26c90 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 45 sqlite3ResolveE
26ca0 78 70 72 4c 69 73 74 4e 61 6d 65 73 28 4e 61 6d xprListNames(Nam
26cb0 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 4c eContext*, ExprL
26cc0 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ist*);.void sqli
26cd0 74 65 33 52 65 73 6f 6c 76 65 53 65 6c 65 63 74 te3ResolveSelect
26ce0 4e 61 6d 65 73 28 50 61 72 73 65 2a 2c 20 53 65 Names(Parse*, Se
26cf0 6c 65 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 lect*, NameConte
26d00 78 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 xt*);.void sqlit
26d10 65 33 52 65 73 6f 6c 76 65 53 65 6c 66 52 65 66 e3ResolveSelfRef
26d20 65 72 65 6e 63 65 28 50 61 72 73 65 2a 2c 54 61 erence(Parse*,Ta
26d30 62 6c 65 2a 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 ble*,int,Expr*,E
26d40 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 xprList*);.int s
26d50 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 4f 72 64 qlite3ResolveOrd
26d60 65 72 47 72 6f 75 70 42 79 28 50 61 72 73 65 2a erGroupBy(Parse*
26d70 2c 20 53 65 6c 65 63 74 2a 2c 20 45 78 70 72 4c , Select*, ExprL
26d80 69 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 ist*, const char
26d90 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
26da0 43 6f 6c 75 6d 6e 44 65 66 61 75 6c 74 28 56 64 ColumnDefault(Vd
26db0 62 65 20 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 be *, Table *, i
26dc0 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
26dd0 71 6c 69 74 65 33 41 6c 74 65 72 46 69 6e 69 73 qlite3AlterFinis
26de0 68 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 hAddColumn(Parse
26df0 20 2a 2c 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f *, Token *);.vo
26e00 69 64 20 73 71 6c 69 74 65 33 41 6c 74 65 72 42 id sqlite3AlterB
26e10 65 67 69 6e 41 64 64 43 6f 6c 75 6d 6e 28 50 61 eginAddColumn(Pa
26e20 72 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a rse *, SrcList *
26e30 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 );.CollSeq *sqli
26e40 74 65 33 47 65 74 43 6f 6c 6c 53 65 71 28 50 61 te3GetCollSeq(Pa
26e50 72 73 65 2a 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 rse*, u8, CollSe
26e60 71 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a q *, const char*
26e70 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 41 );.char sqlite3A
26e80 66 66 69 6e 69 74 79 54 79 70 65 28 63 6f 6e 73 ffinityType(cons
26e90 74 20 63 68 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 t char*, u8*);.v
26ea0 6f 69 64 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 oid sqlite3Analy
26eb0 7a 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e ze(Parse*, Token
26ec0 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 *, Token*);.int
26ed0 73 71 6c 69 74 65 33 49 6e 76 6f 6b 65 42 75 73 sqlite3InvokeBus
26ee0 79 48 61 6e 64 6c 65 72 28 42 75 73 79 48 61 6e yHandler(BusyHan
26ef0 64 6c 65 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 dler*);.int sqli
26f00 74 65 33 46 69 6e 64 44 62 28 73 71 6c 69 74 65 te3FindDb(sqlite
26f10 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 3*, Token*);.int
26f20 20 73 71 6c 69 74 65 33 46 69 6e 64 44 62 4e 61 sqlite3FindDbNa
26f30 6d 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f me(sqlite3 *, co
26f40 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 nst char *);.int
26f50 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 73 69 73 sqlite3Analysis
26f60 4c 6f 61 64 28 73 71 6c 69 74 65 33 2a 2c 69 6e Load(sqlite3*,in
26f70 74 20 69 44 42 29 3b 0a 76 6f 69 64 20 73 71 6c t iDB);.void sql
26f80 69 74 65 33 44 65 6c 65 74 65 49 6e 64 65 78 53 ite3DeleteIndexS
26f90 61 6d 70 6c 65 73 28 73 71 6c 69 74 65 33 2a 2c amples(sqlite3*,
26fa0 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 Index*);.void sq
26fb0 6c 69 74 65 33 44 65 66 61 75 6c 74 52 6f 77 45 lite3DefaultRowE
26fc0 73 74 28 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 st(Index*);.void
26fd0 20 73 71 6c 69 74 65 33 52 65 67 69 73 74 65 72 sqlite3Register
26fe0 4c 69 6b 65 46 75 6e 63 74 69 6f 6e 73 28 73 71 LikeFunctions(sq
26ff0 6c 69 74 65 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e lite3*, int);.in
27000 74 20 73 71 6c 69 74 65 33 49 73 4c 69 6b 65 46 t sqlite3IsLikeF
27010 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a unction(sqlite3*
27020 2c 45 78 70 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 ,Expr*,int*,char
27030 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
27040 4d 69 6e 69 6d 75 6d 46 69 6c 65 46 6f 72 6d 61 MinimumFileForma
27050 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 t(Parse*, int, i
27060 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27070 33 53 63 68 65 6d 61 43 6c 65 61 72 28 76 6f 69 3SchemaClear(voi
27080 64 20 2a 29 3b 0a 53 63 68 65 6d 61 20 2a 73 71 d *);.Schema *sq
27090 6c 69 74 65 33 53 63 68 65 6d 61 47 65 74 28 73 lite3SchemaGet(s
270a0 71 6c 69 74 65 33 20 2a 2c 20 42 74 72 65 65 20 qlite3 *, Btree
270b0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 *);.int sqlite3S
270c0 63 68 65 6d 61 54 6f 49 6e 64 65 78 28 73 71 6c chemaToIndex(sql
270d0 69 74 65 33 20 2a 64 62 2c 20 53 63 68 65 6d 61 ite3 *db, Schema
270e0 20 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 *);.KeyInfo *sq
270f0 6c 69 74 65 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f lite3KeyInfoAllo
27100 63 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 c(sqlite3*,int,i
27110 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27120 33 4b 65 79 49 6e 66 6f 55 6e 72 65 66 28 4b 65 3KeyInfoUnref(Ke
27130 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f yInfo*);.KeyInfo
27140 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f *sqlite3KeyInfo
27150 52 65 66 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b Ref(KeyInfo*);.K
27160 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b eyInfo *sqlite3K
27170 65 79 49 6e 66 6f 4f 66 49 6e 64 65 78 28 50 61 eyInfoOfIndex(Pa
27180 72 73 65 2a 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 rse*, Index*);.#
27190 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
271a0 55 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 UG.int sqlite3Ke
271b0 79 49 6e 66 6f 49 73 57 72 69 74 65 61 62 6c 65 yInfoIsWriteable
271c0 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 (KeyInfo*);.#end
271d0 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 72 if.int sqlite3Cr
271e0 65 61 74 65 46 75 6e 63 28 73 71 6c 69 74 65 33 eateFunc(sqlite3
271f0 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a *, const char *
27200 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 76 6f 69 64 , int, int, void
27210 20 2a 2c 20 0a 20 20 76 6f 69 64 20 28 2a 29 28 *, . void (*)(
27220 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
27230 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c ,int,sqlite3_val
27240 75 65 20 2a 2a 29 2c 0a 20 20 76 6f 69 64 20 28 ue **),. void (
27250 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 *)(sqlite3_conte
27260 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f xt*,int,sqlite3_
27270 76 61 6c 75 65 20 2a 2a 29 2c 20 76 6f 69 64 20 value **), void
27280 28 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 (*)(sqlite3_cont
27290 65 78 74 2a 29 2c 0a 20 20 46 75 6e 63 44 65 73 ext*),. FuncDes
272a0 74 72 75 63 74 6f 72 20 2a 70 44 65 73 74 72 75 tructor *pDestru
272b0 63 74 6f 72 0a 29 3b 0a 69 6e 74 20 73 71 6c 69 ctor.);.int sqli
272c0 74 65 33 41 70 69 45 78 69 74 28 73 71 6c 69 74 te3ApiExit(sqlit
272d0 65 33 20 2a 64 62 2c 20 69 6e 74 29 3b 0a 69 6e e3 *db, int);.in
272e0 74 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 65 6d t sqlite3OpenTem
272f0 70 44 61 74 61 62 61 73 65 28 50 61 72 73 65 20 pDatabase(Parse
27300 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);..void sqlite
27310 33 53 74 72 41 63 63 75 6d 49 6e 69 74 28 53 74 3StrAccumInit(St
27320 72 41 63 63 75 6d 2a 2c 20 73 71 6c 69 74 65 33 rAccum*, sqlite3
27330 2a 2c 20 63 68 61 72 2a 2c 20 69 6e 74 2c 20 69 *, char*, int, i
27340 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27350 33 53 74 72 41 63 63 75 6d 41 70 70 65 6e 64 28 3StrAccumAppend(
27360 53 74 72 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 StrAccum*,const
27370 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 char*,int);.void
27380 20 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d sqlite3StrAccum
27390 41 70 70 65 6e 64 41 6c 6c 28 53 74 72 41 63 63 AppendAll(StrAcc
273a0 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 um*,const char*)
273b0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 70 ;.void sqlite3Ap
273c0 70 65 6e 64 43 68 61 72 28 53 74 72 41 63 63 75 pendChar(StrAccu
273d0 6d 2a 2c 69 6e 74 2c 63 68 61 72 29 3b 0a 63 68 m*,int,char);.ch
273e0 61 72 20 2a 73 71 6c 69 74 65 33 53 74 72 41 63 ar *sqlite3StrAc
273f0 63 75 6d 46 69 6e 69 73 68 28 53 74 72 41 63 63 cumFinish(StrAcc
27400 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 um*);.void sqlit
27410 65 33 53 74 72 41 63 63 75 6d 52 65 73 65 74 28 e3StrAccumReset(
27420 53 74 72 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 StrAccum*);.void
27430 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 44 65 sqlite3SelectDe
27440 73 74 49 6e 69 74 28 53 65 6c 65 63 74 44 65 73 stInit(SelectDes
27450 74 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 45 78 70 t*,int,int);.Exp
27460 72 20 2a 73 71 6c 69 74 65 33 43 72 65 61 74 65 r *sqlite3Create
27470 43 6f 6c 75 6d 6e 45 78 70 72 28 73 71 6c 69 74 ColumnExpr(sqlit
27480 65 33 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c e3 *, SrcList *,
27490 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 0a 76 6f 69 int, int);..voi
274a0 64 20 73 71 6c 69 74 65 33 42 61 63 6b 75 70 52 d sqlite3BackupR
274b0 65 73 74 61 72 74 28 73 71 6c 69 74 65 33 5f 62 estart(sqlite3_b
274c0 61 63 6b 75 70 20 2a 29 3b 0a 76 6f 69 64 20 73 ackup *);.void s
274d0 71 6c 69 74 65 33 42 61 63 6b 75 70 55 70 64 61 qlite3BackupUpda
274e0 74 65 28 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 te(sqlite3_backu
274f0 70 20 2a 2c 20 50 67 6e 6f 2c 20 63 6f 6e 73 74 p *, Pgno, const
27500 20 75 38 20 2a 29 3b 0a 0a 23 69 66 64 65 66 20 u8 *);..#ifdef
27510 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
27520 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 76 6f 69 AT3_OR_STAT4.voi
27530 64 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 d sqlite3Analyze
27540 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
27550 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 .int sqlite3Stat
27560 34 50 72 6f 62 65 53 65 74 56 61 6c 75 65 28 50 4ProbeSetValue(P
27570 61 72 73 65 2a 2c 49 6e 64 65 78 2a 2c 55 6e 70 arse*,Index*,Unp
27580 61 63 6b 65 64 52 65 63 6f 72 64 2a 2a 2c 45 78 ackedRecord**,Ex
27590 70 72 2a 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a 29 pr*,u8,int,int*)
275a0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 ;.int sqlite3Sta
275b0 74 34 56 61 6c 75 65 46 72 6f 6d 45 78 70 72 28 t4ValueFromExpr(
275c0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 75 Parse*, Expr*, u
275d0 38 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 8, sqlite3_value
275e0 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 **);.void sqlite
275f0 33 53 74 61 74 34 50 72 6f 62 65 46 72 65 65 28 3Stat4ProbeFree(
27600 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 2a 29 UnpackedRecord*)
27610 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 ;.int sqlite3Sta
27620 74 34 43 6f 6c 75 6d 6e 28 73 71 6c 69 74 65 33 t4Column(sqlite3
27630 2a 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 *, const void*,
27640 69 6e 74 2c 20 69 6e 74 2c 20 73 71 6c 69 74 65 int, int, sqlite
27650 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 23 65 6e 64 3_value**);.#end
27660 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e if../*.** The in
27670 74 65 72 66 61 63 65 20 74 6f 20 74 68 65 20 4c terface to the L
27680 45 4d 4f 4e 2d 67 65 6e 65 72 61 74 65 64 20 70 EMON-generated p
27690 61 72 73 65 72 0a 2a 2f 0a 76 6f 69 64 20 2a 73 arser.*/.void *s
276a0 71 6c 69 74 65 33 50 61 72 73 65 72 41 6c 6c 6f qlite3ParserAllo
276b0 63 28 76 6f 69 64 2a 28 2a 29 28 75 36 34 29 29 c(void*(*)(u64))
276c0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 ;.void sqlite3Pa
276d0 72 73 65 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 rserFree(void*,
276e0 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b void(*)(void*));
276f0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 .void sqlite3Par
27700 73 65 72 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 ser(void*, int,
27710 54 6f 6b 65 6e 2c 20 50 61 72 73 65 2a 29 3b 0a Token, Parse*);.
27720 23 69 66 64 65 66 20 59 59 54 52 41 43 4b 4d 41 #ifdef YYTRACKMA
27730 58 53 54 41 43 4b 44 45 50 54 48 0a 20 20 69 6e XSTACKDEPTH. in
27740 74 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 53 t sqlite3ParserS
27750 74 61 63 6b 50 65 61 6b 28 76 6f 69 64 2a 29 3b tackPeak(void*);
27760 0a 23 65 6e 64 69 66 0a 0a 76 6f 69 64 20 73 71 .#endif..void sq
27770 6c 69 74 65 33 41 75 74 6f 4c 6f 61 64 45 78 74 lite3AutoLoadExt
27780 65 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a ensions(sqlite3*
27790 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
277a0 45 5f 4f 4d 49 54 5f 4c 4f 41 44 5f 45 58 54 45 E_OMIT_LOAD_EXTE
277b0 4e 53 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c NSION. void sql
277c0 69 74 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 ite3CloseExtensi
277d0 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 ons(sqlite3*);.#
277e0 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
277f0 6c 69 74 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 lite3CloseExtens
27800 69 6f 6e 73 28 58 29 0a 23 65 6e 64 69 66 0a 0a ions(X).#endif..
27810 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
27820 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 45 MIT_SHARED_CACHE
27830 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 . void sqlite3T
27840 61 62 6c 65 4c 6f 63 6b 28 50 61 72 73 65 20 2a ableLock(Parse *
27850 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 2c 20 , int, int, u8,
27860 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 23 const char *);.#
27870 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 else. #define s
27880 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 qlite3TableLock(
27890 76 2c 77 2c 78 2c 79 2c 7a 29 0a 23 65 6e 64 69 v,w,x,y,z).#endi
278a0 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 f..#ifdef SQLITE
278b0 5f 54 45 53 54 0a 20 20 69 6e 74 20 73 71 6c 69 _TEST. int sqli
278c0 74 65 33 55 74 66 38 54 6f 38 28 75 6e 73 69 67 te3Utf8To8(unsig
278d0 6e 65 64 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 ned char*);.#end
278e0 69 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 if..#ifdef SQLIT
278f0 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 E_OMIT_VIRTUALTA
27900 42 4c 45 0a 23 20 20 64 65 66 69 6e 65 20 73 71 BLE.# define sq
27910 6c 69 74 65 33 56 74 61 62 43 6c 65 61 72 28 59 lite3VtabClear(Y
27920 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 ).# define sqli
27930 74 65 33 56 74 61 62 53 79 6e 63 28 58 2c 59 29 te3VtabSync(X,Y)
27940 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 65 SQLITE_OK.# de
27950 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
27960 52 6f 6c 6c 62 61 63 6b 28 58 29 0a 23 20 20 64 Rollback(X).# d
27970 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
27980 62 43 6f 6d 6d 69 74 28 58 29 0a 23 20 20 64 65 bCommit(X).# de
27990 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
279a0 49 6e 53 79 6e 63 28 64 62 29 20 30 0a 23 20 20 InSync(db) 0.#
279b0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 define sqlite3Vt
279c0 61 62 4c 6f 63 6b 28 58 29 20 0a 23 20 20 64 65 abLock(X) .# de
279d0 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
279e0 55 6e 6c 6f 63 6b 28 58 29 0a 23 20 20 64 65 66 Unlock(X).# def
279f0 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 ine sqlite3VtabU
27a00 6e 6c 6f 63 6b 4c 69 73 74 28 58 29 0a 23 20 20 nlockList(X).#
27a10 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 define sqlite3Vt
27a20 61 62 53 61 76 65 70 6f 69 6e 74 28 58 2c 20 59 abSavepoint(X, Y
27a30 2c 20 5a 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 , Z) SQLITE_OK.#
27a40 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
27a50 47 65 74 56 54 61 62 6c 65 28 58 2c 59 29 20 20 GetVTable(X,Y)
27a60 28 28 56 54 61 62 6c 65 2a 29 30 29 0a 23 65 6c ((VTable*)0).#el
27a70 73 65 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 se. void sqlit
27a80 65 33 56 74 61 62 43 6c 65 61 72 28 73 71 6c 69 e3VtabClear(sqli
27a90 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 2a 29 te3 *db, Table*)
27aa0 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 ;. void sqlite
27ab0 33 56 74 61 62 44 69 73 63 6f 6e 6e 65 63 74 28 3VtabDisconnect(
27ac0 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 62 sqlite3 *db, Tab
27ad0 6c 65 20 2a 70 29 3b 0a 20 20 20 69 6e 74 20 73 le *p);. int s
27ae0 71 6c 69 74 65 33 56 74 61 62 53 79 6e 63 28 73 qlite3VtabSync(s
27af0 71 6c 69 74 65 33 20 2a 64 62 2c 20 56 64 62 65 qlite3 *db, Vdbe
27b00 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 *);. int sqlit
27b10 65 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 73 e3VtabRollback(s
27b20 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 20 qlite3 *db);.
27b30 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 int sqlite3VtabC
27b40 6f 6d 6d 69 74 28 73 71 6c 69 74 65 33 20 2a 64 ommit(sqlite3 *d
27b50 62 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 b);. void sqli
27b60 74 65 33 56 74 61 62 4c 6f 63 6b 28 56 54 61 62 te3VtabLock(VTab
27b70 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 le *);. void s
27b80 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b qlite3VtabUnlock
27b90 28 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 (VTable *);. v
27ba0 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 55 oid sqlite3VtabU
27bb0 6e 6c 6f 63 6b 4c 69 73 74 28 73 71 6c 69 74 65 nlockList(sqlite
27bc0 33 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 3*);. int sqli
27bd0 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 6e 74 te3VtabSavepoint
27be0 28 73 71 6c 69 74 65 33 20 2a 2c 20 69 6e 74 2c (sqlite3 *, int,
27bf0 20 69 6e 74 29 3b 0a 20 20 20 76 6f 69 64 20 73 int);. void s
27c00 71 6c 69 74 65 33 56 74 61 62 49 6d 70 6f 72 74 qlite3VtabImport
27c10 45 72 72 6d 73 67 28 56 64 62 65 2a 2c 20 73 71 Errmsg(Vdbe*, sq
27c20 6c 69 74 65 33 5f 76 74 61 62 2a 29 3b 0a 20 20 lite3_vtab*);.
27c30 20 56 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 VTable *sqlite3
27c40 47 65 74 56 54 61 62 6c 65 28 73 71 6c 69 74 65 GetVTable(sqlite
27c50 33 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 23 20 20 3*, Table*);.#
27c60 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 define sqlite3Vt
27c70 61 62 49 6e 53 79 6e 63 28 64 62 29 20 28 28 64 abInSync(db) ((d
27c80 62 29 2d 3e 6e 56 54 72 61 6e 73 3e 30 20 26 26 b)->nVTrans>0 &&
27c90 20 28 64 62 29 2d 3e 61 56 54 72 61 6e 73 3d 3d (db)->aVTrans==
27ca0 30 29 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 0).#endif.int sq
27cb0 6c 69 74 65 33 56 74 61 62 45 70 6f 6e 79 6d 6f lite3VtabEponymo
27cc0 75 73 54 61 62 6c 65 49 6e 69 74 28 50 61 72 73 usTableInit(Pars
27cd0 65 2a 2c 4d 6f 64 75 6c 65 2a 29 3b 0a 76 6f 69 e*,Module*);.voi
27ce0 64 20 73 71 6c 69 74 65 33 56 74 61 62 45 70 6f d sqlite3VtabEpo
27cf0 6e 79 6d 6f 75 73 54 61 62 6c 65 43 6c 65 61 72 nymousTableClear
27d00 28 73 71 6c 69 74 65 33 2a 2c 4d 6f 64 75 6c 65 (sqlite3*,Module
27d10 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
27d20 56 74 61 62 4d 61 6b 65 57 72 69 74 61 62 6c 65 VtabMakeWritable
27d30 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b (Parse*,Table*);
27d40 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 .void sqlite3Vta
27d50 62 42 65 67 69 6e 50 61 72 73 65 28 50 61 72 73 bBeginParse(Pars
27d60 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 e*, Token*, Toke
27d70 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 n*, Token*, int)
27d80 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 ;.void sqlite3Vt
27d90 61 62 46 69 6e 69 73 68 50 61 72 73 65 28 50 61 abFinishParse(Pa
27da0 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 rse*, Token*);.v
27db0 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 41 oid sqlite3VtabA
27dc0 72 67 49 6e 69 74 28 50 61 72 73 65 2a 29 3b 0a rgInit(Parse*);.
27dd0 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 void sqlite3Vtab
27de0 41 72 67 45 78 74 65 6e 64 28 50 61 72 73 65 2a ArgExtend(Parse*
27df0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 , Token*);.int s
27e00 71 6c 69 74 65 33 56 74 61 62 43 61 6c 6c 43 72 qlite3VtabCallCr
27e10 65 61 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 69 eate(sqlite3*, i
27e20 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a nt, const char *
27e30 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 69 6e 74 20 , char **);.int
27e40 73 71 6c 69 74 65 33 56 74 61 62 43 61 6c 6c 43 sqlite3VtabCallC
27e50 6f 6e 6e 65 63 74 28 50 61 72 73 65 2a 2c 20 54 onnect(Parse*, T
27e60 61 62 6c 65 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 able*);.int sqli
27e70 74 65 33 56 74 61 62 43 61 6c 6c 44 65 73 74 72 te3VtabCallDestr
27e80 6f 79 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 oy(sqlite3*, int
27e90 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b , const char *);
27ea0 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 .int sqlite3Vtab
27eb0 42 65 67 69 6e 28 73 71 6c 69 74 65 33 20 2a 2c Begin(sqlite3 *,
27ec0 20 56 54 61 62 6c 65 20 2a 29 3b 0a 46 75 6e 63 VTable *);.Func
27ed0 44 65 66 20 2a 73 71 6c 69 74 65 33 56 74 61 62 Def *sqlite3Vtab
27ee0 4f 76 65 72 6c 6f 61 64 46 75 6e 63 74 69 6f 6e OverloadFunction
27ef0 28 73 71 6c 69 74 65 33 20 2a 2c 46 75 6e 63 44 (sqlite3 *,FuncD
27f00 65 66 2a 2c 20 69 6e 74 20 6e 41 72 67 2c 20 45 ef*, int nArg, E
27f10 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
27f20 74 65 33 49 6e 76 61 6c 69 64 46 75 6e 63 74 69 te3InvalidFuncti
27f30 6f 6e 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 on(sqlite3_conte
27f40 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f xt*,int,sqlite3_
27f50 76 61 6c 75 65 2a 2a 29 3b 0a 73 71 6c 69 74 65 value**);.sqlite
27f60 33 5f 69 6e 74 36 34 20 73 71 6c 69 74 65 33 53 3_int64 sqlite3S
27f70 74 6d 74 43 75 72 72 65 6e 74 54 69 6d 65 28 73 tmtCurrentTime(s
27f80 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 qlite3_context*)
27f90 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 64 62 ;.int sqlite3Vdb
27fa0 65 50 61 72 61 6d 65 74 65 72 49 6e 64 65 78 28 eParameterIndex(
27fb0 56 64 62 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 Vdbe*, const cha
27fc0 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 r*, int);.int sq
27fd0 6c 69 74 65 33 54 72 61 6e 73 66 65 72 42 69 6e lite3TransferBin
27fe0 64 69 6e 67 73 28 73 71 6c 69 74 65 33 5f 73 74 dings(sqlite3_st
27ff0 6d 74 20 2a 2c 20 73 71 6c 69 74 65 33 5f 73 74 mt *, sqlite3_st
28000 6d 74 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 mt *);.void sqli
28010 74 65 33 50 61 72 73 65 72 52 65 73 65 74 28 50 te3ParserReset(P
28020 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 arse*);.int sqli
28030 74 65 33 52 65 70 72 65 70 61 72 65 28 56 64 62 te3Reprepare(Vdb
28040 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
28050 33 45 78 70 72 4c 69 73 74 43 68 65 63 6b 4c 65 3ExprListCheckLe
28060 6e 67 74 68 28 50 61 72 73 65 2a 2c 20 45 78 70 ngth(Parse*, Exp
28070 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 rList*, const ch
28080 61 72 2a 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 ar*);.CollSeq *s
28090 71 6c 69 74 65 33 42 69 6e 61 72 79 43 6f 6d 70 qlite3BinaryComp
280a0 61 72 65 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 areCollSeq(Parse
280b0 20 2a 2c 20 45 78 70 72 20 2a 2c 20 45 78 70 72 *, Expr *, Expr
280c0 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 *);.int sqlite3
280d0 54 65 6d 70 49 6e 4d 65 6d 6f 72 79 28 63 6f 6e TempInMemory(con
280e0 73 74 20 73 71 6c 69 74 65 33 2a 29 3b 0a 63 6f st sqlite3*);.co
280f0 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 nst char *sqlite
28100 33 4a 6f 75 72 6e 61 6c 4d 6f 64 65 6e 61 6d 65 3JournalModename
28110 28 69 6e 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 (int);.#ifndef S
28120 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 QLITE_OMIT_WAL.
28130 20 69 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 int sqlite3Chec
28140 6b 70 6f 69 6e 74 28 73 71 6c 69 74 65 33 2a 2c kpoint(sqlite3*,
28150 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c int, int, int*,
28160 20 69 6e 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 int*);. int sq
28170 6c 69 74 65 33 57 61 6c 44 65 66 61 75 6c 74 48 lite3WalDefaultH
28180 6f 6f 6b 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 ook(void*,sqlite
28190 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 3*,const char*,i
281a0 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 6e nt);.#endif.#ifn
281b0 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
281c0 43 54 45 0a 20 20 57 69 74 68 20 2a 73 71 6c 69 CTE. With *sqli
281d0 74 65 33 57 69 74 68 41 64 64 28 50 61 72 73 65 te3WithAdd(Parse
281e0 2a 2c 57 69 74 68 2a 2c 54 6f 6b 65 6e 2a 2c 45 *,With*,Token*,E
281f0 78 70 72 4c 69 73 74 2a 2c 53 65 6c 65 63 74 2a xprList*,Select*
28200 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
28210 33 57 69 74 68 44 65 6c 65 74 65 28 73 71 6c 69 3WithDelete(sqli
28220 74 65 33 2a 2c 57 69 74 68 2a 29 3b 0a 20 20 76 te3*,With*);. v
28230 6f 69 64 20 73 71 6c 69 74 65 33 57 69 74 68 50 oid sqlite3WithP
28240 75 73 68 28 50 61 72 73 65 2a 2c 20 57 69 74 68 ush(Parse*, With
28250 2a 2c 20 75 38 29 3b 0a 23 65 6c 73 65 0a 23 64 *, u8);.#else.#d
28260 65 66 69 6e 65 20 73 71 6c 69 74 65 33 57 69 74 efine sqlite3Wit
28270 68 50 75 73 68 28 78 2c 79 2c 7a 29 0a 23 64 65 hPush(x,y,z).#de
28280 66 69 6e 65 20 73 71 6c 69 74 65 33 57 69 74 68 fine sqlite3With
28290 44 65 6c 65 74 65 28 78 2c 79 29 0a 23 65 6e 64 Delete(x,y).#end
282a0 69 66 0a 0a 2f 2a 20 44 65 63 6c 61 72 61 74 69 if../* Declarati
282b0 6f 6e 73 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e ons for function
282c0 73 20 69 6e 20 66 6b 65 79 2e 63 2e 20 41 6c 6c s in fkey.c. All
282d0 20 6f 66 20 74 68 65 73 65 20 61 72 65 20 72 65 of these are re
282e0 70 6c 61 63 65 64 20 62 79 0a 2a 2a 20 6e 6f 2d placed by.** no-
282f0 6f 70 20 6d 61 63 72 6f 73 20 69 66 20 4f 4d 49 op macros if OMI
28300 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 20 69 73 T_FOREIGN_KEY is
28310 20 64 65 66 69 6e 65 64 2e 20 49 6e 20 74 68 69 defined. In thi
28320 73 20 63 61 73 65 20 6e 6f 20 66 6f 72 65 69 67 s case no foreig
28330 6e 0a 2a 2a 20 6b 65 79 20 66 75 6e 63 74 69 6f n.** key functio
28340 6e 61 6c 69 74 79 20 69 73 20 61 76 61 69 6c 61 nality is availa
28350 62 6c 65 2e 20 49 66 20 4f 4d 49 54 5f 54 52 49 ble. If OMIT_TRI
28360 47 47 45 52 20 69 73 20 64 65 66 69 6e 65 64 20 GGER is defined
28370 62 75 74 0a 2a 2a 20 4f 4d 49 54 5f 46 4f 52 45 but.** OMIT_FORE
28380 49 47 4e 5f 4b 45 59 20 69 73 20 6e 6f 74 2c 20 IGN_KEY is not,
28390 6f 6e 6c 79 20 73 6f 6d 65 20 6f 66 20 74 68 65 only some of the
283a0 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e functions are n
283b0 6f 2d 6f 70 65 64 2e 20 49 6e 0a 2a 2a 20 74 68 o-oped. In.** th
283c0 69 73 20 63 61 73 65 20 66 6f 72 65 69 67 6e 20 is case foreign
283d0 6b 65 79 73 20 61 72 65 20 70 61 72 73 65 64 2c keys are parsed,
283e0 20 62 75 74 20 6e 6f 20 6f 74 68 65 72 20 66 75 but no other fu
283f0 6e 63 74 69 6f 6e 61 6c 69 74 79 20 69 73 20 0a nctionality is .
28400 2a 2a 20 70 72 6f 76 69 64 65 64 20 28 65 6e 66 ** provided (enf
28410 6f 72 63 65 6d 65 6e 74 20 6f 66 20 46 4b 20 63 orcement of FK c
28420 6f 6e 73 74 72 61 69 6e 74 73 20 72 65 71 75 69 onstraints requi
28430 72 65 73 20 74 68 65 20 74 72 69 67 67 65 72 73 res the triggers
28440 20 73 75 62 2d 73 79 73 74 65 6d 29 2e 0a 2a 2f sub-system)..*/
28450 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 .#if !defined(SQ
28460 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 LITE_OMIT_FOREIG
28470 4e 5f 4b 45 59 29 20 26 26 20 21 64 65 66 69 6e N_KEY) && !defin
28480 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 ed(SQLITE_OMIT_T
28490 52 49 47 47 45 52 29 0a 20 20 76 6f 69 64 20 73 RIGGER). void s
284a0 71 6c 69 74 65 33 46 6b 43 68 65 63 6b 28 50 61 qlite3FkCheck(Pa
284b0 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e rse*, Table*, in
284c0 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e t, int, int*, in
284d0 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 t);. void sqlit
284e0 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 28 50 61 e3FkDropTable(Pa
284f0 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c rse*, SrcList *,
28500 20 54 61 62 6c 65 2a 29 3b 0a 20 20 76 6f 69 64 Table*);. void
28510 20 73 71 6c 69 74 65 33 46 6b 41 63 74 69 6f 6e sqlite3FkAction
28520 73 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a s(Parse*, Table*
28530 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 , ExprList*, int
28540 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 , int*, int);.
28550 69 6e 74 20 73 71 6c 69 74 65 33 46 6b 52 65 71 int sqlite3FkReq
28560 75 69 72 65 64 28 50 61 72 73 65 2a 2c 20 54 61 uired(Parse*, Ta
28570 62 6c 65 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 ble*, int*, int)
28580 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 65 33 46 ;. u32 sqlite3F
28590 6b 4f 6c 64 6d 61 73 6b 28 50 61 72 73 65 2a 2c kOldmask(Parse*,
285a0 20 54 61 62 6c 65 2a 29 3b 0a 20 20 46 4b 65 79 Table*);. FKey
285b0 20 2a 73 71 6c 69 74 65 33 46 6b 52 65 66 65 72 *sqlite3FkRefer
285c0 65 6e 63 65 73 28 54 61 62 6c 65 20 2a 29 3b 0a ences(Table *);.
285d0 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
285e0 73 71 6c 69 74 65 33 46 6b 41 63 74 69 6f 6e 73 sqlite3FkActions
285f0 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 20 (a,b,c,d,e,f).
28600 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 #define sqlite3F
28610 6b 43 68 65 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 kCheck(a,b,c,d,e
28620 2c 66 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 ,f). #define sq
28630 6c 69 74 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 lite3FkDropTable
28640 28 61 2c 62 2c 63 29 0a 20 20 23 64 65 66 69 6e (a,b,c). #defin
28650 65 20 73 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 61 e sqlite3FkOldma
28660 73 6b 28 61 2c 62 29 20 20 20 20 20 20 20 20 20 sk(a,b)
28670 30 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 0. #define sqli
28680 74 65 33 46 6b 52 65 71 75 69 72 65 64 28 61 2c te3FkRequired(a,
28690 62 2c 63 2c 64 29 20 20 20 20 30 0a 23 65 6e 64 b,c,d) 0.#end
286a0 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
286b0 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b E_OMIT_FOREIGN_K
286c0 45 59 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 EY. void sqlite
286d0 33 46 6b 44 65 6c 65 74 65 28 73 71 6c 69 74 65 3FkDelete(sqlite
286e0 33 20 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 3 *, Table*);.
286f0 69 6e 74 20 73 71 6c 69 74 65 33 46 6b 4c 6f 63 int sqlite3FkLoc
28700 61 74 65 49 6e 64 65 78 28 50 61 72 73 65 2a 2c ateIndex(Parse*,
28710 54 61 62 6c 65 2a 2c 46 4b 65 79 2a 2c 49 6e 64 Table*,FKey*,Ind
28720 65 78 2a 2a 2c 69 6e 74 2a 2a 29 3b 0a 23 65 6c ex**,int**);.#el
28730 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c se. #define sql
28740 69 74 65 33 46 6b 44 65 6c 65 74 65 28 61 2c 62 ite3FkDelete(a,b
28750 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 ). #define sqli
28760 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e 64 65 78 te3FkLocateIndex
28770 28 61 2c 62 2c 63 2c 64 2c 65 29 0a 23 65 6e 64 (a,b,c,d,e).#end
28780 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 41 76 61 69 6c if.../*.** Avail
28790 61 62 6c 65 20 66 61 75 6c 74 20 69 6e 6a 65 63 able fault injec
287a0 74 6f 72 73 2e 20 20 53 68 6f 75 6c 64 20 62 65 tors. Should be
287b0 20 6e 75 6d 62 65 72 65 64 20 62 65 67 69 6e 6e numbered beginn
287c0 69 6e 67 20 77 69 74 68 20 30 2e 0a 2a 2f 0a 23 ing with 0..*/.#
287d0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 41 define SQLITE_FA
287e0 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 4d 41 4c 4c ULTINJECTOR_MALL
287f0 4f 43 20 20 20 20 20 30 0a 23 64 65 66 69 6e 65 OC 0.#define
28800 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 49 4e 4a SQLITE_FAULTINJ
28810 45 43 54 4f 52 5f 43 4f 55 4e 54 20 20 20 20 20 ECTOR_COUNT
28820 20 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 1../*.** The in
28830 74 65 72 66 61 63 65 20 74 6f 20 74 68 65 20 63 terface to the c
28840 6f 64 65 20 69 6e 20 66 61 75 6c 74 2e 63 20 75 ode in fault.c u
28850 73 65 64 20 66 6f 72 20 69 64 65 6e 74 69 66 79 sed for identify
28860 69 6e 67 20 22 62 65 6e 69 67 6e 22 0a 2a 2a 20 ing "benign".**
28870 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 65 73 2e malloc failures.
28880 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 20 70 72 This is only pr
28890 65 73 65 6e 74 20 69 66 20 53 51 4c 49 54 45 5f esent if SQLITE_
288a0 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 OMIT_BUILTIN_TES
288b0 54 0a 2a 2a 20 69 73 20 6e 6f 74 20 64 65 66 69 T.** is not defi
288c0 6e 65 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 ned..*/.#ifndef
288d0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c SQLITE_OMIT_BUIL
288e0 54 49 4e 5f 54 45 53 54 0a 20 20 76 6f 69 64 20 TIN_TEST. void
288f0 73 71 6c 69 74 65 33 42 65 67 69 6e 42 65 6e 69 sqlite3BeginBeni
28900 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a gnMalloc(void);.
28910 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 45 6e void sqlite3En
28920 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f dBenignMalloc(vo
28930 69 64 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 id);.#else. #de
28940 66 69 6e 65 20 73 71 6c 69 74 65 33 42 65 67 69 fine sqlite3Begi
28950 6e 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a nBenignMalloc().
28960 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
28970 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3EndBenignMalloc
28980 28 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a ().#endif../*.**
28990 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 72 6e 20 Allowed return
289a0 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 71 6c 69 values from sqli
289b0 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 te3FindInIndex()
289c0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 .*/.#define IN_I
289d0 4e 44 45 58 5f 52 4f 57 49 44 20 20 20 20 20 20 NDEX_ROWID
289e0 20 20 31 20 20 20 2f 2a 20 53 65 61 72 63 68 20 1 /* Search
289f0 74 68 65 20 72 6f 77 69 64 20 6f 66 20 74 68 65 the rowid of the
28a00 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e table */.#defin
28a10 65 20 49 4e 5f 49 4e 44 45 58 5f 45 50 48 20 20 e IN_INDEX_EPH
28a20 20 20 20 20 20 20 20 20 32 20 20 20 2f 2a 20 53 2 /* S
28a30 65 61 72 63 68 20 61 6e 20 65 70 68 65 6d 65 72 earch an ephemer
28a40 61 6c 20 62 2d 74 72 65 65 20 2a 2f 0a 23 64 65 al b-tree */.#de
28a50 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 49 4e fine IN_INDEX_IN
28a60 44 45 58 5f 41 53 43 20 20 20 20 33 20 20 20 2f DEX_ASC 3 /
28a70 2a 20 45 78 69 73 74 69 6e 67 20 69 6e 64 65 78 * Existing index
28a80 20 41 53 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 ASCENDING */.#d
28a90 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 49 efine IN_INDEX_I
28aa0 4e 44 45 58 5f 44 45 53 43 20 20 20 34 20 20 20 NDEX_DESC 4
28ab0 2f 2a 20 45 78 69 73 74 69 6e 67 20 69 6e 64 65 /* Existing inde
28ac0 78 20 44 45 53 43 45 4e 44 49 4e 47 20 2a 2f 0a x DESCENDING */.
28ad0 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 #define IN_INDEX
28ae0 5f 4e 4f 4f 50 20 20 20 20 20 20 20 20 20 35 20 _NOOP 5
28af0 20 20 2f 2a 20 4e 6f 20 74 61 62 6c 65 20 61 76 /* No table av
28b00 61 69 6c 61 62 6c 65 2e 20 55 73 65 20 63 6f 6d ailable. Use com
28b10 70 61 72 69 73 6f 6e 73 20 2a 2f 0a 2f 2a 0a 2a parisons */./*.*
28b20 2a 20 41 6c 6c 6f 77 65 64 20 66 6c 61 67 73 20 * Allowed flags
28b30 66 6f 72 20 74 68 65 20 33 72 64 20 70 61 72 61 for the 3rd para
28b40 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 74 65 33 meter to sqlite3
28b50 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 2e 0a 2a FindInIndex()..*
28b60 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 /.#define IN_IND
28b70 45 58 5f 4e 4f 4f 50 5f 4f 4b 20 20 20 20 20 30 EX_NOOP_OK 0
28b80 78 30 30 30 31 20 20 2f 2a 20 4f 4b 20 74 6f 20 x0001 /* OK to
28b90 72 65 74 75 72 6e 20 49 4e 5f 49 4e 44 45 58 5f return IN_INDEX_
28ba0 4e 4f 4f 50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 NOOP */.#define
28bb0 49 4e 5f 49 4e 44 45 58 5f 4d 45 4d 42 45 52 53 IN_INDEX_MEMBERS
28bc0 48 49 50 20 20 30 78 30 30 30 32 20 20 2f 2a 20 HIP 0x0002 /*
28bd0 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 73 65 64 IN operator used
28be0 20 66 6f 72 20 6d 65 6d 62 65 72 73 68 69 70 20 for membership
28bf0 74 65 73 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 test */.#define
28c00 49 4e 5f 49 4e 44 45 58 5f 4c 4f 4f 50 20 20 20 IN_INDEX_LOOP
28c10 20 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 0x0004 /*
28c20 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 73 65 64 IN operator used
28c30 20 61 73 20 61 20 6c 6f 6f 70 20 2a 2f 0a 69 6e as a loop */.in
28c40 74 20 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 t sqlite3FindInI
28c50 6e 64 65 78 28 50 61 72 73 65 20 2a 2c 20 45 78 ndex(Parse *, Ex
28c60 70 72 20 2a 2c 20 75 33 32 2c 20 69 6e 74 2a 29 pr *, u32, int*)
28c70 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
28c80 5f 45 4e 41 42 4c 45 5f 41 54 4f 4d 49 43 5f 57 _ENABLE_ATOMIC_W
28c90 52 49 54 45 0a 20 20 69 6e 74 20 73 71 6c 69 74 RITE. int sqlit
28ca0 65 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 e3JournalOpen(sq
28cb0 6c 69 74 65 33 5f 76 66 73 20 2a 2c 20 63 6f 6e lite3_vfs *, con
28cc0 73 74 20 63 68 61 72 20 2a 2c 20 73 71 6c 69 74 st char *, sqlit
28cd0 65 33 5f 66 69 6c 65 20 2a 2c 20 69 6e 74 2c 20 e3_file *, int,
28ce0 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 int);. int sqli
28cf0 74 65 33 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 73 te3JournalSize(s
28d00 71 6c 69 74 65 33 5f 76 66 73 20 2a 29 3b 0a 20 qlite3_vfs *);.
28d10 20 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 int sqlite3Jour
28d20 6e 61 6c 43 72 65 61 74 65 28 73 71 6c 69 74 65 nalCreate(sqlite
28d30 33 5f 66 69 6c 65 20 2a 29 3b 0a 20 20 69 6e 74 3_file *);. int
28d40 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 45 sqlite3JournalE
28d50 78 69 73 74 73 28 73 71 6c 69 74 65 33 5f 66 69 xists(sqlite3_fi
28d60 6c 65 20 2a 70 29 3b 0a 23 65 6c 73 65 0a 20 20 le *p);.#else.
28d70 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4a #define sqlite3J
28d80 6f 75 72 6e 61 6c 53 69 7a 65 28 70 56 66 73 29 ournalSize(pVfs)
28d90 20 28 28 70 56 66 73 29 2d 3e 73 7a 4f 73 46 69 ((pVfs)->szOsFi
28da0 6c 65 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 le). #define sq
28db0 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 45 78 69 73 lite3JournalExis
28dc0 74 73 28 70 29 20 31 0a 23 65 6e 64 69 66 0a 0a ts(p) 1.#endif..
28dd0 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d 4a void sqlite3MemJ
28de0 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 6c 69 74 ournalOpen(sqlit
28df0 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 69 6e 74 20 e3_file *);.int
28e00 73 71 6c 69 74 65 33 4d 65 6d 4a 6f 75 72 6e 61 sqlite3MemJourna
28e10 6c 53 69 7a 65 28 76 6f 69 64 29 3b 0a 69 6e 74 lSize(void);.int
28e20 20 73 71 6c 69 74 65 33 49 73 4d 65 6d 4a 6f 75 sqlite3IsMemJou
28e30 72 6e 61 6c 28 73 71 6c 69 74 65 33 5f 66 69 6c rnal(sqlite3_fil
28e40 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 e *);..void sqli
28e50 74 65 33 45 78 70 72 53 65 74 48 65 69 67 68 74 te3ExprSetHeight
28e60 41 6e 64 46 6c 61 67 73 28 50 61 72 73 65 20 2a AndFlags(Parse *
28e70 70 50 61 72 73 65 2c 20 45 78 70 72 20 2a 70 29 pParse, Expr *p)
28e80 3b 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 ;.#if SQLITE_MAX
28e90 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 0a 20 20 _EXPR_DEPTH>0.
28ea0 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 63 int sqlite3Selec
28eb0 74 45 78 70 72 48 65 69 67 68 74 28 53 65 6c 65 tExprHeight(Sele
28ec0 63 74 20 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c ct *);. int sql
28ed0 69 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 69 ite3ExprCheckHei
28ee0 67 68 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 ght(Parse*, int)
28ef0 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e ;.#else. #defin
28f00 65 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 45 e sqlite3SelectE
28f10 78 70 72 48 65 69 67 68 74 28 78 29 20 30 0a 20 xprHeight(x) 0.
28f20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
28f30 45 78 70 72 43 68 65 63 6b 48 65 69 67 68 74 28 ExprCheckHeight(
28f40 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a 75 33 32 x,y).#endif..u32
28f50 20 73 71 6c 69 74 65 33 47 65 74 34 62 79 74 65 sqlite3Get4byte
28f60 28 63 6f 6e 73 74 20 75 38 2a 29 3b 0a 76 6f 69 (const u8*);.voi
28f70 64 20 73 71 6c 69 74 65 33 50 75 74 34 62 79 74 d sqlite3Put4byt
28f80 65 28 75 38 2a 2c 20 75 33 32 29 3b 0a 0a 23 69 e(u8*, u32);..#i
28f90 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
28fa0 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 59 LE_UNLOCK_NOTIFY
28fb0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
28fc0 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 64 onnectionBlocked
28fd0 28 73 71 6c 69 74 65 33 20 2a 2c 20 73 71 6c 69 (sqlite3 *, sqli
28fe0 74 65 33 20 2a 29 3b 0a 20 20 76 6f 69 64 20 73 te3 *);. void s
28ff0 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
29000 55 6e 6c 6f 63 6b 65 64 28 73 71 6c 69 74 65 33 Unlocked(sqlite3
29010 20 2a 64 62 29 3b 0a 20 20 76 6f 69 64 20 73 71 *db);. void sq
29020 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 43 lite3ConnectionC
29030 6c 6f 73 65 64 28 73 71 6c 69 74 65 33 20 2a 64 losed(sqlite3 *d
29040 62 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 b);.#else. #def
29050 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 ine sqlite3Conne
29060 63 74 69 6f 6e 42 6c 6f 63 6b 65 64 28 78 2c 79 ctionBlocked(x,y
29070 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 ). #define sqli
29080 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 55 6e 6c te3ConnectionUnl
29090 6f 63 6b 65 64 28 78 29 0a 20 20 23 64 65 66 69 ocked(x). #defi
290a0 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 ne sqlite3Connec
290b0 74 69 6f 6e 43 6c 6f 73 65 64 28 78 29 0a 23 65 tionClosed(x).#e
290c0 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 4c ndif..#ifdef SQL
290d0 49 54 45 5f 44 45 42 55 47 0a 20 20 76 6f 69 64 ITE_DEBUG. void
290e0 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 54 72 sqlite3ParserTr
290f0 61 63 65 28 46 49 4c 45 2a 2c 20 63 68 61 72 20 ace(FILE*, char
29100 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a *);.#endif../*.*
29110 2a 20 49 66 20 74 68 65 20 53 51 4c 49 54 45 5f * If the SQLITE_
29120 45 4e 41 42 4c 45 20 49 4f 54 52 41 43 45 20 65 ENABLE IOTRACE e
29130 78 69 73 74 73 20 74 68 65 6e 20 74 68 65 20 67 xists then the g
29140 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 0a 2a lobal variable.*
29150 2a 20 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 * sqlite3IoTrace
29160 20 69 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f is a pointer to
29170 20 61 20 70 72 69 6e 74 66 2d 6c 69 6b 65 20 72 a printf-like r
29180 6f 75 74 69 6e 65 20 75 73 65 64 20 74 6f 0a 2a outine used to.*
29190 2a 20 70 72 69 6e 74 20 49 2f 4f 20 74 72 61 63 * print I/O trac
291a0 69 6e 67 20 6d 65 73 73 61 67 65 73 2e 20 0a 2a ing messages. .*
291b0 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
291c0 45 4e 41 42 4c 45 5f 49 4f 54 52 41 43 45 0a 23 ENABLE_IOTRACE.#
291d0 20 64 65 66 69 6e 65 20 49 4f 54 52 41 43 45 28 define IOTRACE(
291e0 41 29 20 20 69 66 28 20 73 71 6c 69 74 65 33 49 A) if( sqlite3I
291f0 6f 54 72 61 63 65 20 29 7b 20 73 71 6c 69 74 65 oTrace ){ sqlite
29200 33 49 6f 54 72 61 63 65 20 41 3b 20 7d 0a 20 20 3IoTrace A; }.
29210 76 6f 69 64 20 73 71 6c 69 74 65 33 56 64 62 65 void sqlite3Vdbe
29220 49 4f 54 72 61 63 65 53 71 6c 28 56 64 62 65 2a IOTraceSql(Vdbe*
29230 29 3b 0a 53 51 4c 49 54 45 5f 41 50 49 20 53 51 );.SQLITE_API SQ
29240 4c 49 54 45 5f 45 58 54 45 52 4e 20 76 6f 69 64 LITE_EXTERN void
29250 20 28 53 51 4c 49 54 45 5f 43 44 45 43 4c 20 2a (SQLITE_CDECL *
29260 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 29 28 sqlite3IoTrace)(
29270 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e 2e 2e 29 const char*,...)
29280 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
29290 20 49 4f 54 52 41 43 45 28 41 29 0a 23 20 64 65 IOTRACE(A).# de
292a0 66 69 6e 65 20 73 71 6c 69 74 65 33 56 64 62 65 fine sqlite3Vdbe
292b0 49 4f 54 72 61 63 65 53 71 6c 28 58 29 0a 23 65 IOTraceSql(X).#e
292c0 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 ndif../*.** Thes
292d0 65 20 72 6f 75 74 69 6e 65 73 20 61 72 65 20 61 e routines are a
292e0 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 74 68 65 vailable for the
292f0 20 6d 65 6d 32 2e 63 20 64 65 62 75 67 67 69 6e mem2.c debuggin
29300 67 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 g memory allocat
29310 6f 72 0a 2a 2a 20 6f 6e 6c 79 2e 20 20 54 68 65 or.** only. The
29320 79 20 61 72 65 20 75 73 65 64 20 74 6f 20 76 65 y are used to ve
29330 72 69 66 79 20 74 68 61 74 20 64 69 66 66 65 72 rify that differ
29340 65 6e 74 20 22 74 79 70 65 73 22 20 6f 66 20 6d ent "types" of m
29350 65 6d 6f 72 79 0a 2a 2a 20 61 6c 6c 6f 63 61 74 emory.** allocat
29360 69 6f 6e 73 20 61 72 65 20 70 72 6f 70 65 72 6c ions are properl
29370 79 20 74 72 61 63 6b 65 64 20 62 79 20 74 68 65 y tracked by the
29380 20 73 79 73 74 65 6d 2e 0a 2a 2a 0a 2a 2a 20 73 system..**.** s
29390 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 qlite3MemdebugSe
293a0 74 54 79 70 65 28 29 20 73 65 74 73 20 74 68 65 tType() sets the
293b0 20 22 74 79 70 65 22 20 6f 66 20 61 6e 20 61 6c "type" of an al
293c0 6c 6f 63 61 74 69 6f 6e 20 74 6f 20 6f 6e 65 20 location to one
293d0 6f 66 0a 2a 2a 20 74 68 65 20 4d 45 4d 54 59 50 of.** the MEMTYP
293e0 45 5f 2a 20 6d 61 63 72 6f 73 20 64 65 66 69 6e E_* macros defin
293f0 65 64 20 62 65 6c 6f 77 2e 20 20 54 68 65 20 74 ed below. The t
29400 79 70 65 20 6d 75 73 74 20 62 65 20 61 20 62 69 ype must be a bi
29410 74 6d 61 73 6b 20 77 69 74 68 0a 2a 2a 20 61 20 tmask with.** a
29420 73 69 6e 67 6c 65 20 62 69 74 20 73 65 74 2e 0a single bit set..
29430 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d **.** sqlite3Mem
29440 64 65 62 75 67 48 61 73 54 79 70 65 28 29 20 72 debugHasType() r
29450 65 74 75 72 6e 73 20 74 72 75 65 20 69 66 20 61 eturns true if a
29460 6e 79 20 6f 66 20 74 68 65 20 62 69 74 73 20 69 ny of the bits i
29470 6e 20 69 74 73 20 73 65 63 6f 6e 64 0a 2a 2a 20 n its second.**
29480 61 72 67 75 6d 65 6e 74 20 6d 61 74 63 68 20 74 argument match t
29490 68 65 20 74 79 70 65 20 73 65 74 20 62 79 20 74 he type set by t
294a0 68 65 20 70 72 65 76 69 6f 75 73 20 73 71 6c 69 he previous sqli
294b0 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 te3MemdebugSetTy
294c0 70 65 28 29 2e 0a 2a 2a 20 73 71 6c 69 74 65 33 pe()..** sqlite3
294d0 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 MemdebugHasType(
294e0 29 20 69 73 20 69 6e 74 65 6e 64 65 64 20 66 6f ) is intended fo
294f0 72 20 75 73 65 20 69 6e 73 69 64 65 20 61 73 73 r use inside ass
29500 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
29510 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d ..**.** sqlite3M
29520 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 28 29 20 emdebugNoType()
29530 72 65 74 75 72 6e 73 20 74 72 75 65 20 69 66 20 returns true if
29540 6e 6f 6e 65 20 6f 66 20 74 68 65 20 62 69 74 73 none of the bits
29550 20 69 6e 20 69 74 73 20 73 65 63 6f 6e 64 0a 2a in its second.*
29560 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 74 63 68 * argument match
29570 20 74 68 65 20 74 79 70 65 20 73 65 74 20 62 79 the type set by
29580 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 73 71 the previous sq
29590 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 lite3MemdebugSet
295a0 54 79 70 65 28 29 2e 0a 2a 2a 0a 2a 2a 20 50 65 Type()..**.** Pe
295b0 72 68 61 70 73 20 74 68 65 20 6d 6f 73 74 20 69 rhaps the most i
295c0 6d 70 6f 72 74 61 6e 74 20 70 6f 69 6e 74 20 69 mportant point i
295d0 73 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65 s the difference
295e0 20 62 65 74 77 65 65 6e 20 4d 45 4d 54 59 50 45 between MEMTYPE
295f0 5f 48 45 41 50 0a 2a 2a 20 61 6e 64 20 4d 45 4d _HEAP.** and MEM
29600 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 2e 20 TYPE_LOOKASIDE.
29610 20 49 66 20 61 6e 20 61 6c 6c 6f 63 61 74 69 6f If an allocatio
29620 6e 20 69 73 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f n is MEMTYPE_LOO
29630 4b 41 53 49 44 45 2c 20 74 68 61 74 20 6d 65 61 KASIDE, that mea
29640 6e 73 0a 2a 2a 20 69 74 20 6d 69 67 68 74 20 68 ns.** it might h
29650 61 76 65 20 62 65 65 6e 20 61 6c 6c 6f 63 61 74 ave been allocat
29660 65 64 20 62 79 20 6c 6f 6f 6b 61 73 69 64 65 2c ed by lookaside,
29670 20 65 78 63 65 70 74 20 74 68 65 20 61 6c 6c 6f except the allo
29680 63 61 74 69 6f 6e 20 77 61 73 0a 2a 2a 20 74 6f cation was.** to
29690 6f 20 6c 61 72 67 65 20 6f 72 20 6c 6f 6f 6b 61 o large or looka
296a0 73 69 64 65 20 77 61 73 20 61 6c 72 65 61 64 79 side was already
296b0 20 66 75 6c 6c 2e 20 20 49 74 20 69 73 20 69 6d full. It is im
296c0 70 6f 72 74 61 6e 74 20 74 6f 20 76 65 72 69 66 portant to verif
296d0 79 0a 2a 2a 20 74 68 61 74 20 61 6c 6c 6f 63 61 y.** that alloca
296e0 74 69 6f 6e 73 20 74 68 61 74 20 6d 69 67 68 74 tions that might
296f0 20 68 61 76 65 20 62 65 65 6e 20 73 61 74 69 73 have been satis
29700 66 69 65 64 20 62 79 20 6c 6f 6f 6b 61 73 69 64 fied by lookasid
29710 65 20 61 72 65 20 6e 6f 74 0a 2a 2a 20 70 61 73 e are not.** pas
29720 73 65 64 20 62 61 63 6b 20 74 6f 20 6e 6f 6e 2d sed back to non-
29730 6c 6f 6f 6b 61 73 69 64 65 20 66 72 65 65 28 29 lookaside free()
29740 20 72 6f 75 74 69 6e 65 73 2e 20 20 41 73 73 65 routines. Asse
29750 72 74 73 20 73 75 63 68 20 61 73 20 74 68 65 0a rts such as the.
29760 2a 2a 20 65 78 61 6d 70 6c 65 20 61 62 6f 76 65 ** example above
29770 20 61 72 65 20 70 6c 61 63 65 64 20 6f 6e 20 74 are placed on t
29780 68 65 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 he non-lookaside
29790 20 66 72 65 65 28 29 20 72 6f 75 74 69 6e 65 73 free() routines
297a0 20 74 6f 20 76 65 72 69 66 79 0a 2a 2a 20 74 68 to verify.** th
297b0 69 73 20 63 6f 6e 73 74 72 61 69 6e 74 2e 20 0a is constraint. .
297c0 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 69 **.** All of thi
297d0 73 20 69 73 20 6e 6f 2d 6f 70 20 66 6f 72 20 61 s is no-op for a
297e0 20 70 72 6f 64 75 63 74 69 6f 6e 20 62 75 69 6c production buil
297f0 64 2e 20 20 49 74 20 6f 6e 6c 79 20 63 6f 6d 65 d. It only come
29800 73 20 69 6e 74 6f 0a 2a 2a 20 70 6c 61 79 20 77 s into.** play w
29810 68 65 6e 20 74 68 65 20 53 51 4c 49 54 45 5f 4d hen the SQLITE_M
29820 45 4d 44 45 42 55 47 20 63 6f 6d 70 69 6c 65 2d EMDEBUG compile-
29830 74 69 6d 65 20 6f 70 74 69 6f 6e 20 69 73 20 75 time option is u
29840 73 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 sed..*/.#ifdef S
29850 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 0a 20 QLITE_MEMDEBUG.
29860 20 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d void sqlite3Mem
29870 64 65 62 75 67 53 65 74 54 79 70 65 28 76 6f 69 debugSetType(voi
29880 64 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 20 73 71 d*,u8);. int sq
29890 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 lite3MemdebugHas
298a0 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a Type(void*,u8);.
298b0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d int sqlite3Mem
298c0 64 65 62 75 67 4e 6f 54 79 70 65 28 76 6f 69 64 debugNoType(void
298d0 2a 2c 75 38 29 3b 0a 23 65 6c 73 65 0a 23 20 64 *,u8);.#else.# d
298e0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d efine sqlite3Mem
298f0 64 65 62 75 67 53 65 74 54 79 70 65 28 58 2c 59 debugSetType(X,Y
29900 29 20 20 2f 2a 20 6e 6f 2d 6f 70 20 2a 2f 0a 23 ) /* no-op */.#
29910 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d define sqlite3M
29920 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 58 emdebugHasType(X
29930 2c 59 29 20 20 31 0a 23 20 64 65 66 69 6e 65 20 ,Y) 1.# define
29940 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 4e sqlite3MemdebugN
29950 6f 54 79 70 65 28 58 2c 59 29 20 20 20 31 0a 23 oType(X,Y) 1.#
29960 65 6e 64 69 66 0a 23 64 65 66 69 6e 65 20 4d 45 endif.#define ME
29970 4d 54 59 50 45 5f 48 45 41 50 20 20 20 20 20 20 MTYPE_HEAP
29980 20 30 78 30 31 20 20 2f 2a 20 47 65 6e 65 72 61 0x01 /* Genera
29990 6c 20 68 65 61 70 20 61 6c 6c 6f 63 61 74 69 6f l heap allocatio
299a0 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 ns */.#define ME
299b0 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 20 MTYPE_LOOKASIDE
299c0 20 30 78 30 32 20 20 2f 2a 20 48 65 61 70 20 74 0x02 /* Heap t
299d0 68 61 74 20 6d 69 67 68 74 20 68 61 76 65 20 62 hat might have b
299e0 65 65 6e 20 6c 6f 6f 6b 61 73 69 64 65 20 2a 2f een lookaside */
299f0 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 .#define MEMTYPE
29a00 5f 53 43 52 41 54 43 48 20 20 20 20 30 78 30 34 _SCRATCH 0x04
29a10 20 20 2f 2a 20 53 63 72 61 74 63 68 20 61 6c 6c /* Scratch all
29a20 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 ocations */.#def
29a30 69 6e 65 20 4d 45 4d 54 59 50 45 5f 50 43 41 43 ine MEMTYPE_PCAC
29a40 48 45 20 20 20 20 20 30 78 30 38 20 20 2f 2a 20 HE 0x08 /*
29a50 50 61 67 65 20 63 61 63 68 65 20 61 6c 6c 6f 63 Page cache alloc
29a60 61 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a ations */../*.**
29a70 20 54 68 72 65 61 64 69 6e 67 20 69 6e 74 65 72 Threading inter
29a80 66 61 63 65 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 face.*/.#if SQLI
29a90 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 TE_MAX_WORKER_TH
29aa0 52 45 41 44 53 3e 30 0a 69 6e 74 20 73 71 6c 69 READS>0.int sqli
29ab0 74 65 33 54 68 72 65 61 64 43 72 65 61 74 65 28 te3ThreadCreate(
29ac0 53 51 4c 69 74 65 54 68 72 65 61 64 2a 2a 2c 76 SQLiteThread**,v
29ad0 6f 69 64 2a 28 2a 29 28 76 6f 69 64 2a 29 2c 76 oid*(*)(void*),v
29ae0 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 oid*);.int sqlit
29af0 65 33 54 68 72 65 61 64 4a 6f 69 6e 28 53 51 4c e3ThreadJoin(SQL
29b00 69 74 65 54 68 72 65 61 64 2a 2c 20 76 6f 69 64 iteThread*, void
29b10 2a 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 **);.#endif..#if
29b20 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
29b30 45 4e 41 42 4c 45 5f 44 42 53 54 41 54 5f 56 54 ENABLE_DBSTAT_VT
29b40 41 42 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 AB) || defined(S
29b50 51 4c 49 54 45 5f 54 45 53 54 29 0a 69 6e 74 20 QLITE_TEST).int
29b60 73 71 6c 69 74 65 33 44 62 73 74 61 74 52 65 67 sqlite3DbstatReg
29b70 69 73 74 65 72 28 73 71 6c 69 74 65 33 2a 29 3b ister(sqlite3*);
29b80 0a 23 65 6e 64 69 66 0a 0a 23 65 6e 64 69 66 20 .#endif..#endif
29b90 2f 2a 20 5f 53 51 4c 49 54 45 49 4e 54 5f 48 5f /* _SQLITEINT_H_
29ba0 20 2a 2f 0a */.