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 4e 65 65 64 65 64 20 66 6f 72 20 76 61 72 69 Needed for vari
08c0: 6f 75 73 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e ous definitions.
08d0: 2e 2e 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 .. */.#if define
08e0: 64 28 5f 5f 47 4e 55 43 5f 5f 29 20 26 26 20 21 d(__GNUC__) && !
08f0: 64 65 66 69 6e 65 64 28 5f 47 4e 55 5f 53 4f 55 defined(_GNU_SOU
0900: 52 43 45 29 0a 23 20 64 65 66 69 6e 65 20 5f 47 RCE).# define _G
0910: 4e 55 5f 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 NU_SOURCE.#endif
0920: 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f ..#if defined(__
0930: 4f 70 65 6e 42 53 44 5f 5f 29 20 26 26 20 21 64 OpenBSD__) && !d
0940: 65 66 69 6e 65 64 28 5f 42 53 44 5f 53 4f 55 52 efined(_BSD_SOUR
0950: 43 45 29 0a 23 20 64 65 66 69 6e 65 20 5f 42 53 CE).# define _BS
0960: 44 5f 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a D_SOURCE.#endif.
0970: 0a 2f 2a 0a 2a 2a 20 46 6f 72 20 4d 69 6e 47 57 ./*.** For MinGW
0980: 2c 20 63 68 65 63 6b 20 74 6f 20 73 65 65 20 69 , check to see i
0990: 66 20 77 65 20 63 61 6e 20 69 6e 63 6c 75 64 65 f we can include
09a0: 20 74 68 65 20 68 65 61 64 65 72 20 66 69 6c 65 the header file
09b0: 20 63 6f 6e 74 61 69 6e 69 6e 67 20 69 74 73 0a containing its.
09c0: 2a 2a 20 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 ** version infor
09d0: 6d 61 74 69 6f 6e 2c 20 61 6d 6f 6e 67 20 6f 74 mation, among ot
09e0: 68 65 72 20 74 68 69 6e 67 73 2e 20 20 4e 6f 72 her things. Nor
09f0: 6d 61 6c 6c 79 2c 20 74 68 69 73 20 69 6e 74 65 mally, this inte
0a00: 72 6e 61 6c 20 4d 69 6e 47 57 0a 2a 2a 20 68 65 rnal MinGW.** he
0a10: 61 64 65 72 20 66 69 6c 65 20 77 6f 75 6c 64 20 ader file would
0a20: 5b 6f 6e 6c 79 5d 20 62 65 20 69 6e 63 6c 75 64 [only] be includ
0a30: 65 64 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 ed automatically
0a40: 20 62 79 20 6f 74 68 65 72 20 4d 69 6e 47 57 20 by other MinGW
0a50: 68 65 61 64 65 72 0a 2a 2a 20 66 69 6c 65 73 3b header.** files;
0a60: 20 68 6f 77 65 76 65 72 2c 20 74 68 65 20 63 6f however, the co
0a70: 6e 74 61 69 6e 65 64 20 76 65 72 73 69 6f 6e 20 ntained version
0a80: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 73 20 6e information is n
0a90: 6f 77 20 72 65 71 75 69 72 65 64 20 62 79 20 74 ow required by t
0aa0: 68 69 73 0a 2a 2a 20 68 65 61 64 65 72 20 66 69 his.** header fi
0ab0: 6c 65 20 74 6f 20 77 6f 72 6b 20 61 72 6f 75 6e le to work aroun
0ac0: 64 20 62 69 6e 61 72 79 20 63 6f 6d 70 61 74 69 d binary compati
0ad0: 62 69 6c 69 74 79 20 69 73 73 75 65 73 20 28 73 bility issues (s
0ae0: 65 65 20 62 65 6c 6f 77 29 20 61 6e 64 0a 2a 2a ee below) and.**
0af0: 20 74 68 69 73 20 69 73 20 74 68 65 20 6f 6e 6c this is the onl
0b00: 79 20 6b 6e 6f 77 6e 20 77 61 79 20 74 6f 20 72 y known way to r
0b10: 65 6c 69 61 62 6c 79 20 6f 62 74 61 69 6e 20 69 eliably obtain i
0b20: 74 2e 20 20 54 68 69 73 20 65 6e 74 69 72 65 20 t. This entire
0b30: 23 69 66 20 62 6c 6f 63 6b 0a 2a 2a 20 77 6f 75 #if block.** wou
0b40: 6c 64 20 62 65 20 63 6f 6d 70 6c 65 74 65 6c 79 ld be completely
0b50: 20 75 6e 6e 65 63 65 73 73 61 72 79 20 69 66 20 unnecessary if
0b60: 74 68 65 72 65 20 77 61 73 20 61 6e 79 20 6f 74 there was any ot
0b70: 68 65 72 20 77 61 79 20 6f 66 20 64 65 74 65 63 her way of detec
0b80: 74 69 6e 67 0a 2a 2a 20 4d 69 6e 47 57 20 76 69 ting.** MinGW vi
0b90: 61 20 74 68 65 69 72 20 70 72 65 70 72 6f 63 65 a their preproce
0ba0: 73 73 6f 72 20 28 65 2e 67 2e 20 69 66 20 74 68 ssor (e.g. if th
0bb0: 65 79 20 63 75 73 74 6f 6d 69 7a 65 64 20 74 68 ey customized th
0bc0: 65 69 72 20 47 43 43 20 74 6f 20 64 65 66 69 6e eir GCC to defin
0bd0: 65 0a 2a 2a 20 73 6f 6d 65 20 4d 69 6e 47 57 2d e.** some MinGW-
0be0: 73 70 65 63 69 66 69 63 20 6d 61 63 72 6f 73 29 specific macros)
0bf0: 2e 20 20 57 68 65 6e 20 63 6f 6d 70 69 6c 69 6e . When compilin
0c00: 67 20 66 6f 72 20 4d 69 6e 47 57 2c 20 65 69 74 g for MinGW, eit
0c10: 68 65 72 20 74 68 65 0a 2a 2a 20 5f 48 41 56 45 her the.** _HAVE
0c20: 5f 4d 49 4e 47 57 5f 48 20 6f 72 20 5f 48 41 56 _MINGW_H or _HAV
0c30: 45 5f 5f 4d 49 4e 47 57 5f 48 20 28 6e 6f 74 65 E__MINGW_H (note
0c40: 20 74 68 65 20 65 78 74 72 61 20 75 6e 64 65 72 the extra under
0c50: 73 63 6f 72 65 29 20 6d 61 63 72 6f 20 6d 75 73 score) macro mus
0c60: 74 20 62 65 0a 2a 2a 20 64 65 66 69 6e 65 64 3b t be.** defined;
0c70: 20 6f 74 68 65 72 77 69 73 65 2c 20 64 65 74 65 otherwise, dete
0c80: 63 74 69 6f 6e 20 6f 66 20 63 6f 6e 64 69 74 69 ction of conditi
0c90: 6f 6e 73 20 73 70 65 63 69 66 69 63 20 74 6f 20 ons specific to
0ca0: 4d 69 6e 47 57 20 77 69 6c 6c 20 62 65 0a 2a 2a MinGW will be.**
0cb0: 20 64 69 73 61 62 6c 65 64 2e 0a 2a 2f 0a 23 69 disabled..*/.#i
0cc0: 66 20 64 65 66 69 6e 65 64 28 5f 48 41 56 45 5f f defined(_HAVE_
0cd0: 4d 49 4e 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 MINGW_H).# inclu
0ce0: 64 65 20 22 6d 69 6e 67 77 2e 68 22 0a 23 65 6c de "mingw.h".#el
0cf0: 69 66 20 64 65 66 69 6e 65 64 28 5f 48 41 56 45 if defined(_HAVE
0d00: 5f 5f 4d 49 4e 47 57 5f 48 29 0a 23 20 69 6e 63 __MINGW_H).# inc
0d10: 6c 75 64 65 20 22 5f 6d 69 6e 67 77 2e 68 22 0a lude "_mingw.h".
0d20: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 6f #endif../*.** Fo
0d30: 72 20 4d 69 6e 47 57 20 76 65 72 73 69 6f 6e 20 r MinGW version
0d40: 34 2e 78 20 28 61 6e 64 20 68 69 67 68 65 72 29 4.x (and higher)
0d50: 2c 20 63 68 65 63 6b 20 74 6f 20 73 65 65 20 69 , check to see i
0d60: 66 20 74 68 65 20 5f 55 53 45 5f 33 32 42 49 54 f the _USE_32BIT
0d70: 5f 54 49 4d 45 5f 54 0a 2a 2a 20 64 65 66 69 6e _TIME_T.** defin
0d80: 65 20 69 73 20 72 65 71 75 69 72 65 64 20 74 6f e is required to
0d90: 20 6d 61 69 6e 74 61 69 6e 20 62 69 6e 61 72 79 maintain binary
0da0: 20 63 6f 6d 70 61 74 69 62 69 6c 69 74 79 20 77 compatibility w
0db0: 69 74 68 20 74 68 65 20 4d 53 56 43 20 72 75 6e ith the MSVC run
0dc0: 74 69 6d 65 0a 2a 2a 20 6c 69 62 72 61 72 79 20 time.** library
0dd0: 69 6e 20 75 73 65 20 28 65 2e 67 2e 20 66 6f 72 in use (e.g. for
0de0: 20 57 69 6e 64 6f 77 73 20 58 50 29 2e 0a 2a 2f Windows XP)..*/
0df0: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 55 .#if !defined(_U
0e00: 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 5f 54 29 SE_32BIT_TIME_T)
0e10: 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f 55 53 && !defined(_US
0e20: 45 5f 36 34 42 49 54 5f 54 49 4d 45 5f 54 29 20 E_64BIT_TIME_T)
0e30: 26 26 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 && \. defined
0e40: 28 5f 57 49 4e 33 32 29 20 26 26 20 21 64 65 66 (_WIN32) && !def
0e50: 69 6e 65 64 28 5f 57 49 4e 36 34 29 20 26 26 20 ined(_WIN64) &&
0e60: 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f \. defined(__
0e70: 4d 49 4e 47 57 5f 4d 41 4a 4f 52 5f 56 45 52 53 MINGW_MAJOR_VERS
0e80: 49 4f 4e 29 20 26 26 20 5f 5f 4d 49 4e 47 57 5f ION) && __MINGW_
0e90: 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e 20 3e 3d MAJOR_VERSION >=
0ea0: 20 34 20 26 26 20 5c 0a 20 20 20 20 64 65 66 69 4 && \. defi
0eb0: 6e 65 64 28 5f 5f 4d 53 56 43 52 54 5f 5f 29 0a ned(__MSVCRT__).
0ec0: 23 20 64 65 66 69 6e 65 20 5f 55 53 45 5f 33 32 # define _USE_32
0ed0: 42 49 54 5f 54 49 4d 45 5f 54 0a 23 65 6e 64 69 BIT_TIME_T.#endi
0ee0: 66 0a 0a 2f 2a 20 54 68 65 20 70 75 62 6c 69 63 f../* The public
0ef0: 20 53 51 4c 69 74 65 20 69 6e 74 65 72 66 61 63 SQLite interfac
0f00: 65 2e 20 20 54 68 65 20 5f 46 49 4c 45 5f 4f 46 e. The _FILE_OF
0f10: 46 53 45 54 5f 42 49 54 53 20 6d 61 63 72 6f 20 FSET_BITS macro
0f20: 6d 75 73 74 20 61 70 70 65 61 72 0a 2a 2a 20 66 must appear.** f
0f30: 69 72 73 74 20 69 6e 20 51 4e 58 2e 20 20 41 6c irst in QNX. Al
0f40: 73 6f 2c 20 74 68 65 20 5f 55 53 45 5f 33 32 42 so, the _USE_32B
0f50: 49 54 5f 54 49 4d 45 5f 54 20 6d 61 63 72 6f 20 IT_TIME_T macro
0f60: 6d 75 73 74 20 61 70 70 65 61 72 20 66 69 72 73 must appear firs
0f70: 74 20 66 6f 72 0a 2a 2a 20 4d 69 6e 47 57 2e 0a t for.** MinGW..
0f80: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 73 71 6c */.#include "sql
0f90: 69 74 65 33 2e 68 22 0a 0a 2f 2a 0a 2a 2a 20 49 ite3.h"../*.** I
0fa0: 6e 63 6c 75 64 65 20 74 68 65 20 63 6f 6e 66 69 nclude the confi
0fb0: 67 75 72 61 74 69 6f 6e 20 68 65 61 64 65 72 20 guration header
0fc0: 6f 75 74 70 75 74 20 62 79 20 27 63 6f 6e 66 69 output by 'confi
0fd0: 67 75 72 65 27 20 69 66 20 77 65 27 72 65 20 75 gure' if we're u
0fe0: 73 69 6e 67 20 74 68 65 0a 2a 2a 20 61 75 74 6f sing the.** auto
0ff0: 63 6f 6e 66 2d 62 61 73 65 64 20 62 75 69 6c 64 conf-based build
1000: 0a 2a 2f 0a 23 69 66 64 65 66 20 5f 48 41 56 45 .*/.#ifdef _HAVE
1010: 5f 53 51 4c 49 54 45 5f 43 4f 4e 46 49 47 5f 48 _SQLITE_CONFIG_H
1020: 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 .#include "confi
1030: 67 2e 68 22 0a 23 65 6e 64 69 66 0a 0a 23 69 6e g.h".#endif..#in
1040: 63 6c 75 64 65 20 22 73 71 6c 69 74 65 4c 69 6d clude "sqliteLim
1050: 69 74 2e 68 22 0a 0a 2f 2a 20 44 69 73 61 62 6c it.h"../* Disabl
1060: 65 20 6e 75 69 73 61 6e 63 65 20 77 61 72 6e 69 e nuisance warni
1070: 6e 67 73 20 6f 6e 20 42 6f 72 6c 61 6e 64 20 63 ngs on Borland c
1080: 6f 6d 70 69 6c 65 72 73 20 2a 2f 0a 23 69 66 20 ompilers */.#if
1090: 64 65 66 69 6e 65 64 28 5f 5f 42 4f 52 4c 41 4e defined(__BORLAN
10a0: 44 43 5f 5f 29 0a 23 70 72 61 67 6d 61 20 77 61 DC__).#pragma wa
10b0: 72 6e 20 2d 72 63 68 20 2f 2a 20 75 6e 72 65 61 rn -rch /* unrea
10c0: 63 68 61 62 6c 65 20 63 6f 64 65 20 2a 2f 0a 23 chable code */.#
10d0: 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 63 63 63 pragma warn -ccc
10e0: 20 2f 2a 20 43 6f 6e 64 69 74 69 6f 6e 20 69 73 /* Condition is
10f0: 20 61 6c 77 61 79 73 20 74 72 75 65 20 6f 72 20 always true or
1100: 66 61 6c 73 65 20 2a 2f 0a 23 70 72 61 67 6d 61 false */.#pragma
1110: 20 77 61 72 6e 20 2d 61 75 73 20 2f 2a 20 41 73 warn -aus /* As
1120: 73 69 67 6e 65 64 20 76 61 6c 75 65 20 69 73 20 signed value is
1130: 6e 65 76 65 72 20 75 73 65 64 20 2a 2f 0a 23 70 never used */.#p
1140: 72 61 67 6d 61 20 77 61 72 6e 20 2d 63 73 75 20 ragma warn -csu
1150: 2f 2a 20 43 6f 6d 70 61 72 69 6e 67 20 73 69 67 /* Comparing sig
1160: 6e 65 64 20 61 6e 64 20 75 6e 73 69 67 6e 65 64 ned and unsigned
1170: 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 72 6e */.#pragma warn
1180: 20 2d 73 70 61 20 2f 2a 20 53 75 73 70 69 63 69 -spa /* Suspici
1190: 6f 75 73 20 70 6f 69 6e 74 65 72 20 61 72 69 74 ous pointer arit
11a0: 68 6d 65 74 69 63 20 2a 2f 0a 23 65 6e 64 69 66 hmetic */.#endif
11b0: 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 ../*.** Include
11c0: 73 74 61 6e 64 61 72 64 20 68 65 61 64 65 72 20 standard header
11d0: 66 69 6c 65 73 20 61 73 20 6e 65 63 65 73 73 61 files as necessa
11e0: 72 79 0a 2a 2f 0a 23 69 66 64 65 66 20 48 41 56 ry.*/.#ifdef HAV
11f0: 45 5f 53 54 44 49 4e 54 5f 48 0a 23 69 6e 63 6c E_STDINT_H.#incl
1200: 75 64 65 20 3c 73 74 64 69 6e 74 2e 68 3e 0a 23 ude <stdint.h>.#
1210: 65 6e 64 69 66 0a 23 69 66 64 65 66 20 48 41 56 endif.#ifdef HAV
1220: 45 5f 49 4e 54 54 59 50 45 53 5f 48 0a 23 69 6e E_INTTYPES_H.#in
1230: 63 6c 75 64 65 20 3c 69 6e 74 74 79 70 65 73 2e clude <inttypes.
1240: 68 3e 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a h>.#endif../*.**
1250: 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d The following m
1260: 61 63 72 6f 73 20 61 72 65 20 75 73 65 64 20 74 acros are used t
1270: 6f 20 63 61 73 74 20 70 6f 69 6e 74 65 72 73 20 o cast pointers
1280: 74 6f 20 69 6e 74 65 67 65 72 73 20 61 6e 64 0a to integers and.
1290: 2a 2a 20 69 6e 74 65 67 65 72 73 20 74 6f 20 70 ** integers to p
12a0: 6f 69 6e 74 65 72 73 2e 20 20 54 68 65 20 77 61 ointers. The wa
12b0: 79 20 79 6f 75 20 64 6f 20 74 68 69 73 20 76 61 y you do this va
12c0: 72 69 65 73 20 66 72 6f 6d 20 6f 6e 65 20 63 6f ries from one co
12d0: 6d 70 69 6c 65 72 0a 2a 2a 20 74 6f 20 74 68 65 mpiler.** to the
12e0: 20 6e 65 78 74 2c 20 73 6f 20 77 65 20 68 61 76 next, so we hav
12f0: 65 20 64 65 76 65 6c 6f 70 65 64 20 74 68 65 20 e developed the
1300: 66 6f 6c 6c 6f 77 69 6e 67 20 73 65 74 20 6f 66 following set of
1310: 20 23 69 66 20 73 74 61 74 65 6d 65 6e 74 73 0a #if statements.
1320: 2a 2a 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61 ** to generate a
1330: 70 70 72 6f 70 72 69 61 74 65 20 6d 61 63 72 6f ppropriate macro
1340: 73 20 66 6f 72 20 61 20 77 69 64 65 20 72 61 6e s for a wide ran
1350: 67 65 20 6f 66 20 63 6f 6d 70 69 6c 65 72 73 2e ge of compilers.
1360: 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f 72 72 65 .**.** The corre
1370: 63 74 20 22 41 4e 53 49 22 20 77 61 79 20 74 6f ct "ANSI" way to
1380: 20 64 6f 20 74 68 69 73 20 69 73 20 74 6f 20 75 do this is to u
1390: 73 65 20 74 68 65 20 69 6e 74 70 74 72 5f 74 20 se the intptr_t
13a0: 74 79 70 65 2e 20 0a 2a 2a 20 55 6e 66 6f 72 74 type. .** Unfort
13b0: 75 6e 61 74 65 6c 79 2c 20 74 68 61 74 20 74 79 unately, that ty
13c0: 70 65 64 65 66 20 69 73 20 6e 6f 74 20 61 76 61 pedef is not ava
13d0: 69 6c 61 62 6c 65 20 6f 6e 20 61 6c 6c 20 63 6f ilable on all co
13e0: 6d 70 69 6c 65 72 73 2c 20 6f 72 0a 2a 2a 20 69 mpilers, or.** i
13f0: 66 20 69 74 20 69 73 20 61 76 61 69 6c 61 62 6c f it is availabl
1400: 65 2c 20 69 74 20 72 65 71 75 69 72 65 73 20 61 e, it requires a
1410: 6e 20 23 69 6e 63 6c 75 64 65 20 6f 66 20 73 70 n #include of sp
1420: 65 63 69 66 69 63 20 68 65 61 64 65 72 73 0a 2a ecific headers.*
1430: 2a 20 74 68 61 74 20 76 61 72 79 20 66 72 6f 6d * that vary from
1440: 20 6f 6e 65 20 6d 61 63 68 69 6e 65 20 74 6f 20 one machine to
1450: 74 68 65 20 6e 65 78 74 2e 0a 2a 2a 0a 2a 2a 20 the next..**.**
1460: 54 69 63 6b 65 74 20 23 33 38 36 30 3a 20 20 54 Ticket #3860: T
1470: 68 65 20 6c 6c 76 6d 2d 67 63 63 2d 34 2e 32 20 he llvm-gcc-4.2
1480: 63 6f 6d 70 69 6c 65 72 20 66 72 6f 6d 20 41 70 compiler from Ap
1490: 70 6c 65 20 63 68 6f 6b 65 73 20 6f 6e 0a 2a 2a ple chokes on.**
14a0: 20 74 68 65 20 28 28 76 6f 69 64 2a 29 26 28 28 the ((void*)&((
14b0: 63 68 61 72 2a 29 30 29 5b 58 5d 29 20 63 6f 6e char*)0)[X]) con
14c0: 73 74 72 75 63 74 2e 20 20 42 75 74 20 4d 53 56 struct. But MSV
14d0: 43 20 63 68 6f 6b 65 73 20 6f 6e 20 28 28 76 6f C chokes on ((vo
14e0: 69 64 2a 29 28 58 29 29 2e 0a 2a 2a 20 53 6f 20 id*)(X))..** So
14f0: 77 65 20 68 61 76 65 20 74 6f 20 64 65 66 69 6e we have to defin
1500: 65 20 74 68 65 20 6d 61 63 72 6f 73 20 69 6e 20 e the macros in
1510: 64 69 66 66 65 72 65 6e 74 20 77 61 79 73 20 64 different ways d
1520: 65 70 65 6e 64 69 6e 67 20 6f 6e 20 74 68 65 0a epending on the.
1530: 2a 2a 20 63 6f 6d 70 69 6c 65 72 2e 0a 2a 2f 0a ** compiler..*/.
1540: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 50 54 #if defined(__PT
1550: 52 44 49 46 46 5f 54 59 50 45 5f 5f 29 20 20 2f RDIFF_TYPE__) /
1560: 2a 20 54 68 69 73 20 63 61 73 65 20 73 68 6f 75 * This case shou
1570: 6c 64 20 77 6f 72 6b 20 66 6f 72 20 47 43 43 20 ld work for GCC
1580: 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 */.# define SQLI
1590: 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 TE_INT_TO_PTR(X)
15a0: 20 20 28 28 76 6f 69 64 2a 29 28 5f 5f 50 54 52 ((void*)(__PTR
15b0: 44 49 46 46 5f 54 59 50 45 5f 5f 29 28 58 29 29 DIFF_TYPE__)(X))
15c0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
15d0: 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 _PTR_TO_INT(X)
15e0: 28 28 69 6e 74 29 28 5f 5f 50 54 52 44 49 46 46 ((int)(__PTRDIFF
15f0: 5f 54 59 50 45 5f 5f 29 28 58 29 29 0a 23 65 6c _TYPE__)(X)).#el
1600: 69 66 20 21 64 65 66 69 6e 65 64 28 5f 5f 47 4e if !defined(__GN
1610: 55 43 5f 5f 29 20 20 20 20 20 20 20 2f 2a 20 57 UC__) /* W
1620: 6f 72 6b 73 20 66 6f 72 20 63 6f 6d 70 69 6c 65 orks for compile
1630: 72 73 20 6f 74 68 65 72 20 74 68 61 6e 20 4c 4c rs other than LL
1640: 56 4d 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 VM */.# define S
1650: 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 QLITE_INT_TO_PTR
1660: 28 58 29 20 20 28 28 76 6f 69 64 2a 29 26 28 28 (X) ((void*)&((
1670: 63 68 61 72 2a 29 30 29 5b 58 5d 29 0a 23 20 64 char*)0)[X]).# d
1680: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 efine SQLITE_PTR
1690: 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 28 69 6e _TO_INT(X) ((in
16a0: 74 29 28 28 28 63 68 61 72 2a 29 58 29 2d 28 63 t)(((char*)X)-(c
16b0: 68 61 72 2a 29 30 29 29 0a 23 65 6c 69 66 20 64 har*)0)).#elif d
16c0: 65 66 69 6e 65 64 28 48 41 56 45 5f 53 54 44 49 efined(HAVE_STDI
16d0: 4e 54 5f 48 29 20 20 20 2f 2a 20 55 73 65 20 74 NT_H) /* Use t
16e0: 68 69 73 20 63 61 73 65 20 69 66 20 77 65 20 68 his case if we h
16f0: 61 76 65 20 41 4e 53 49 20 68 65 61 64 65 72 73 ave ANSI headers
1700: 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c */.# define SQL
1710: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 ITE_INT_TO_PTR(X
1720: 29 20 20 28 28 76 6f 69 64 2a 29 28 69 6e 74 70 ) ((void*)(intp
1730: 74 72 5f 74 29 28 58 29 29 0a 23 20 64 65 66 69 tr_t)(X)).# defi
1740: 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f ne SQLITE_PTR_TO
1750: 5f 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 _INT(X) ((int)(
1760: 69 6e 74 70 74 72 5f 74 29 28 58 29 29 0a 23 65 intptr_t)(X)).#e
1770: 6c 73 65 20 20 20 20 20 20 20 20 20 20 20 20 20 lse
1780: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1790: 47 65 6e 65 72 61 74 65 73 20 61 20 77 61 72 6e Generates a warn
17a0: 69 6e 67 20 2d 20 62 75 74 20 69 74 20 61 6c 77 ing - but it alw
17b0: 61 79 73 20 77 6f 72 6b 73 20 2a 2f 0a 23 20 64 ays works */.# d
17c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 efine SQLITE_INT
17d0: 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f _TO_PTR(X) ((vo
17e0: 69 64 2a 29 28 58 29 29 0a 23 20 64 65 66 69 6e id*)(X)).# defin
17f0: 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f e SQLITE_PTR_TO_
1800: 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 58 INT(X) ((int)(X
1810: 29 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a )).#endif../*.**
1820: 20 41 20 6d 61 63 72 6f 20 74 6f 20 68 69 6e 74 A macro to hint
1830: 20 74 6f 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 to the compiler
1840: 20 74 68 61 74 20 61 20 66 75 6e 63 74 69 6f 6e that a function
1850: 20 73 68 6f 75 6c 64 20 6e 6f 74 20 62 65 0a 2a should not be.*
1860: 2a 20 69 6e 6c 69 6e 65 64 2e 0a 2a 2f 0a 23 69 * inlined..*/.#i
1870: 66 20 64 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 f defined(__GNUC
1880: 5f 5f 29 0a 23 20 20 64 65 66 69 6e 65 20 53 51 __).# define SQ
1890: 4c 49 54 45 5f 4e 4f 49 4e 4c 49 4e 45 20 20 5f LITE_NOINLINE _
18a0: 5f 61 74 74 72 69 62 75 74 65 5f 5f 28 28 6e 6f _attribute__((no
18b0: 69 6e 6c 69 6e 65 29 29 0a 23 65 6c 69 66 20 64 inline)).#elif d
18c0: 65 66 69 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 efined(_MSC_VER)
18d0: 20 26 26 20 5f 4d 53 43 5f 56 45 52 3e 3d 31 33 && _MSC_VER>=13
18e0: 31 30 0a 23 20 20 64 65 66 69 6e 65 20 53 51 4c 10.# define SQL
18f0: 49 54 45 5f 4e 4f 49 4e 4c 49 4e 45 20 20 5f 5f ITE_NOINLINE __
1900: 64 65 63 6c 73 70 65 63 28 6e 6f 69 6e 6c 69 6e declspec(noinlin
1910: 65 29 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 69 e).#else.# defi
1920: 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 49 4e 4c 49 ne SQLITE_NOINLI
1930: 4e 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a NE.#endif../*.**
1940: 20 54 68 65 20 53 51 4c 49 54 45 5f 54 48 52 45 The SQLITE_THRE
1950: 41 44 53 41 46 45 20 6d 61 63 72 6f 20 6d 75 73 ADSAFE macro mus
1960: 74 20 62 65 20 64 65 66 69 6e 65 64 20 61 73 20 t be defined as
1970: 30 2c 20 31 2c 20 6f 72 20 32 2e 0a 2a 2a 20 30 0, 1, or 2..** 0
1980: 20 6d 65 61 6e 73 20 6d 75 74 65 78 65 73 20 61 means mutexes a
1990: 72 65 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 64 re permanently d
19a0: 69 73 61 62 6c 65 20 61 6e 64 20 74 68 65 20 6c isable and the l
19b0: 69 62 72 61 72 79 20 69 73 20 6e 65 76 65 72 0a ibrary is never.
19c0: 2a 2a 20 74 68 72 65 61 64 73 61 66 65 2e 20 20 ** threadsafe.
19d0: 31 20 6d 65 61 6e 73 20 74 68 65 20 6c 69 62 72 1 means the libr
19e0: 61 72 79 20 69 73 20 73 65 72 69 61 6c 69 7a 65 ary is serialize
19f0: 64 20 77 68 69 63 68 20 69 73 20 74 68 65 20 68 d which is the h
1a00: 69 67 68 65 73 74 0a 2a 2a 20 6c 65 76 65 6c 20 ighest.** level
1a10: 6f 66 20 74 68 72 65 61 64 73 61 66 65 74 79 2e of threadsafety.
1a20: 20 20 32 20 6d 65 61 6e 73 20 74 68 65 20 6c 69 2 means the li
1a30: 62 72 61 72 79 20 69 73 20 6d 75 6c 74 69 74 68 brary is multith
1a40: 72 65 61 64 65 64 20 2d 20 6d 75 6c 74 69 70 6c readed - multipl
1a50: 65 0a 2a 2a 20 74 68 72 65 61 64 73 20 63 61 6e e.** threads can
1a60: 20 75 73 65 20 53 51 4c 69 74 65 20 61 73 20 6c use SQLite as l
1a70: 6f 6e 67 20 61 73 20 6e 6f 20 74 77 6f 20 74 68 ong as no two th
1a80: 72 65 61 64 73 20 74 72 79 20 74 6f 20 75 73 65 reads try to use
1a90: 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 64 61 74 the same.** dat
1aa0: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
1ab0: 20 61 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d at the same tim
1ac0: 65 2e 0a 2a 2a 0a 2a 2a 20 4f 6c 64 65 72 20 76 e..**.** Older v
1ad0: 65 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 ersions of SQLit
1ae0: 65 20 75 73 65 64 20 61 6e 20 6f 70 74 69 6f 6e e used an option
1af0: 61 6c 20 54 48 52 45 41 44 53 41 46 45 20 6d 61 al THREADSAFE ma
1b00: 63 72 6f 2e 0a 2a 2a 20 57 65 20 73 75 70 70 6f cro..** We suppo
1b10: 72 74 20 74 68 61 74 20 66 6f 72 20 6c 65 67 61 rt that for lega
1b20: 63 79 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 cy..*/.#if !defi
1b30: 6e 65 64 28 53 51 4c 49 54 45 5f 54 48 52 45 41 ned(SQLITE_THREA
1b40: 44 53 41 46 45 29 0a 23 20 69 66 20 64 65 66 69 DSAFE).# if defi
1b50: 6e 65 64 28 54 48 52 45 41 44 53 41 46 45 29 0a ned(THREADSAFE).
1b60: 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 # define SQLIT
1b70: 45 5f 54 48 52 45 41 44 53 41 46 45 20 54 48 52 E_THREADSAFE THR
1b80: 45 41 44 53 41 46 45 0a 23 20 65 6c 73 65 0a 23 EADSAFE.# else.#
1b90: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
1ba0: 5f 54 48 52 45 41 44 53 41 46 45 20 31 20 2f 2a _THREADSAFE 1 /*
1bb0: 20 49 4d 50 3a 20 52 2d 30 37 32 37 32 2d 32 32 IMP: R-07272-22
1bc0: 33 30 39 20 2a 2f 0a 23 20 65 6e 64 69 66 0a 23 309 */.# endif.#
1bd0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 6f 77 endif../*.** Pow
1be0: 65 72 73 61 66 65 20 6f 76 65 72 77 72 69 74 65 ersafe overwrite
1bf0: 20 69 73 20 6f 6e 20 62 79 20 64 65 66 61 75 6c is on by defaul
1c00: 74 2e 20 20 42 75 74 20 63 61 6e 20 62 65 20 74 t. But can be t
1c10: 75 72 6e 65 64 20 6f 66 66 20 75 73 69 6e 67 0a urned off using.
1c20: 2a 2a 20 74 68 65 20 2d 44 53 51 4c 49 54 45 5f ** the -DSQLITE_
1c30: 50 4f 57 45 52 53 41 46 45 5f 4f 56 45 52 57 52 POWERSAFE_OVERWR
1c40: 49 54 45 3d 30 20 63 6f 6d 6d 61 6e 64 2d 6c 69 ITE=0 command-li
1c50: 6e 65 20 6f 70 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 ne option..*/.#i
1c60: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 50 4f 57 fndef SQLITE_POW
1c70: 45 52 53 41 46 45 5f 4f 56 45 52 57 52 49 54 45 ERSAFE_OVERWRITE
1c80: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
1c90: 5f 50 4f 57 45 52 53 41 46 45 5f 4f 56 45 52 57 _POWERSAFE_OVERW
1ca0: 52 49 54 45 20 31 0a 23 65 6e 64 69 66 0a 0a 2f RITE 1.#endif../
1cb0: 2a 0a 2a 2a 20 45 56 49 44 45 4e 43 45 2d 4f 46 *.** EVIDENCE-OF
1cc0: 3a 20 52 2d 32 35 37 31 35 2d 33 37 30 37 32 20 : R-25715-37072
1cd0: 4d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f Memory allocatio
1ce0: 6e 20 73 74 61 74 69 73 74 69 63 73 20 61 72 65 n statistics are
1cf0: 20 65 6e 61 62 6c 65 64 20 62 79 0a 2a 2a 20 64 enabled by.** d
1d00: 65 66 61 75 6c 74 20 75 6e 6c 65 73 73 20 53 51 efault unless SQ
1d10: 4c 69 74 65 20 69 73 20 63 6f 6d 70 69 6c 65 64 Lite is compiled
1d20: 20 77 69 74 68 20 53 51 4c 49 54 45 5f 44 45 46 with SQLITE_DEF
1d30: 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 53 3d 30 AULT_MEMSTATUS=0
1d40: 20 69 6e 0a 2a 2a 20 77 68 69 63 68 20 63 61 73 in.** which cas
1d50: 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 e memory allocat
1d60: 69 6f 6e 20 73 74 61 74 69 73 74 69 63 73 20 61 ion statistics a
1d70: 72 65 20 64 69 73 61 62 6c 65 64 20 62 79 20 64 re disabled by d
1d80: 65 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 66 20 21 efault..*/.#if !
1d90: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 defined(SQLITE_D
1da0: 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 53 EFAULT_MEMSTATUS
1db0: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
1dc0: 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 E_DEFAULT_MEMSTA
1dd0: 54 55 53 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a TUS 1.#endif../*
1de0: 0a 2a 2a 20 45 78 61 63 74 6c 79 20 6f 6e 65 20 .** Exactly one
1df0: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
1e00: 20 6d 61 63 72 6f 73 20 6d 75 73 74 20 62 65 20 macros must be
1e10: 64 65 66 69 6e 65 64 20 69 6e 20 6f 72 64 65 72 defined in order
1e20: 20 74 6f 0a 2a 2a 20 73 70 65 63 69 66 79 20 77 to.** specify w
1e30: 68 69 63 68 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f hich memory allo
1e40: 63 61 74 69 6f 6e 20 73 75 62 73 79 73 74 65 6d cation subsystem
1e50: 20 74 6f 20 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 to use..**.**
1e60: 20 20 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d SQLITE_SYSTEM
1e70: 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 20 20 20 _MALLOC
1e80: 20 2f 2f 20 55 73 65 20 6e 6f 72 6d 61 6c 20 73 // Use normal s
1e90: 79 73 74 65 6d 20 6d 61 6c 6c 6f 63 28 29 0a 2a ystem malloc().*
1ea0: 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 57 49 4e * SQLITE_WIN
1eb0: 33 32 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 20 32_MALLOC
1ec0: 20 20 20 20 2f 2f 20 55 73 65 20 57 69 6e 33 32 // Use Win32
1ed0: 20 6e 61 74 69 76 65 20 68 65 61 70 20 41 50 49 native heap API
1ee0: 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 5a .** SQLITE_Z
1ef0: 45 52 4f 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 ERO_MALLOC
1f00: 20 20 20 20 20 20 2f 2f 20 55 73 65 20 61 20 73 // Use a s
1f10: 74 75 62 20 61 6c 6c 6f 63 61 74 6f 72 20 74 68 tub allocator th
1f20: 61 74 20 61 6c 77 61 79 73 20 66 61 69 6c 73 0a at always fails.
1f30: 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 4d 45 ** SQLITE_ME
1f40: 4d 44 45 42 55 47 20 20 20 20 20 20 20 20 20 20 MDEBUG
1f50: 20 20 20 20 20 2f 2f 20 44 65 62 75 67 67 69 6e // Debuggin
1f60: 67 20 76 65 72 73 69 6f 6e 20 6f 66 20 73 79 73 g version of sys
1f70: 74 65 6d 20 6d 61 6c 6c 6f 63 28 29 0a 2a 2a 0a tem malloc().**.
1f80: 2a 2a 20 4f 6e 20 57 69 6e 64 6f 77 73 2c 20 69 ** On Windows, i
1f90: 66 20 74 68 65 20 53 51 4c 49 54 45 5f 57 49 4e f the SQLITE_WIN
1fa0: 33 32 5f 4d 41 4c 4c 4f 43 5f 56 41 4c 49 44 41 32_MALLOC_VALIDA
1fb0: 54 45 20 6d 61 63 72 6f 20 69 73 20 64 65 66 69 TE macro is defi
1fc0: 6e 65 64 20 61 6e 64 20 74 68 65 0a 2a 2a 20 61 ned and the.** a
1fd0: 73 73 65 72 74 28 29 20 6d 61 63 72 6f 20 69 73 ssert() macro is
1fe0: 20 65 6e 61 62 6c 65 64 2c 20 65 61 63 68 20 63 enabled, each c
1ff0: 61 6c 6c 20 69 6e 74 6f 20 74 68 65 20 57 69 6e all into the Win
2000: 33 32 20 6e 61 74 69 76 65 20 68 65 61 70 20 73 32 native heap s
2010: 75 62 73 79 73 74 65 6d 0a 2a 2a 20 77 69 6c 6c ubsystem.** will
2020: 20 63 61 75 73 65 20 48 65 61 70 56 61 6c 69 64 cause HeapValid
2030: 61 74 65 20 74 6f 20 62 65 20 63 61 6c 6c 65 64 ate to be called
2040: 2e 20 20 49 66 20 68 65 61 70 20 76 61 6c 69 64 . If heap valid
2050: 61 74 69 6f 6e 20 73 68 6f 75 6c 64 20 66 61 69 ation should fai
2060: 6c 2c 20 61 6e 0a 2a 2a 20 61 73 73 65 72 74 69 l, an.** asserti
2070: 6f 6e 20 77 69 6c 6c 20 62 65 20 74 72 69 67 67 on will be trigg
2080: 65 72 65 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 6e ered..**.** If n
2090: 6f 6e 65 20 6f 66 20 74 68 65 20 61 62 6f 76 65 one of the above
20a0: 20 61 72 65 20 64 65 66 69 6e 65 64 2c 20 74 68 are defined, th
20b0: 65 6e 20 73 65 74 20 53 51 4c 49 54 45 5f 53 59 en set SQLITE_SY
20c0: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 61 73 0a 2a STEM_MALLOC as.*
20d0: 2a 20 74 68 65 20 64 65 66 61 75 6c 74 2e 0a 2a * the default..*
20e0: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 /.#if defined(SQ
20f0: 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c LITE_SYSTEM_MALL
2100: 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 OC) \. + define
2110: 64 28 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d d(SQLITE_WIN32_M
2120: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
2130: 69 6e 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 4f ined(SQLITE_ZERO
2140: 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 _MALLOC) \. + d
2150: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 45 efined(SQLITE_ME
2160: 4d 44 45 42 55 47 29 3e 31 0a 23 20 65 72 72 6f MDEBUG)>1.# erro
2170: 72 20 22 54 77 6f 20 6f 72 20 6d 6f 72 65 20 6f r "Two or more o
2180: 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
2190: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 63 6f 6e compile-time con
21a0: 66 69 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f figuration optio
21b0: 6e 73 5c 0a 20 61 72 65 20 64 65 66 69 6e 65 64 ns\. are defined
21c0: 20 62 75 74 20 61 74 20 6d 6f 73 74 20 6f 6e 65 but at most one
21d0: 20 69 73 20 61 6c 6c 6f 77 65 64 3a 5c 0a 20 53 is allowed:\. S
21e0: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
21f0: 4c 4f 43 2c 20 53 51 4c 49 54 45 5f 57 49 4e 33 LOC, SQLITE_WIN3
2200: 32 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c 49 54 45 2_MALLOC, SQLITE
2210: 5f 4d 45 4d 44 45 42 55 47 2c 5c 0a 20 53 51 4c _MEMDEBUG,\. SQL
2220: 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 22 ITE_ZERO_MALLOC"
2230: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
2240: 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 53 54 45 ned(SQLITE_SYSTE
2250: 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 M_MALLOC) \. +
2260: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 57 defined(SQLITE_W
2270: 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 IN32_MALLOC) \.
2280: 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 + defined(SQLIT
2290: 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 29 20 5c E_ZERO_MALLOC) \
22a0: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
22b0: 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 3d 3d 30 ITE_MEMDEBUG)==0
22c0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
22d0: 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 31 _SYSTEM_MALLOC 1
22e0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 .#endif../*.** I
22f0: 66 20 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 5f f SQLITE_MALLOC_
2300: 53 4f 46 54 5f 4c 49 4d 49 54 20 69 73 20 6e 6f SOFT_LIMIT is no
2310: 74 20 7a 65 72 6f 2c 20 74 68 65 6e 20 74 72 79 t zero, then try
2320: 20 74 6f 20 6b 65 65 70 20 74 68 65 0a 2a 2a 20 to keep the.**
2330: 73 69 7a 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 sizes of memory
2340: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 62 65 6c 6f allocations belo
2350: 77 20 74 68 69 73 20 76 61 6c 75 65 20 77 68 65 w this value whe
2360: 72 65 20 70 6f 73 73 69 62 6c 65 2e 0a 2a 2f 0a re possible..*/.
2370: 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
2380: 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f ITE_MALLOC_SOFT_
2390: 4c 49 4d 49 54 29 0a 23 20 64 65 66 69 6e 65 20 LIMIT).# define
23a0: 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f SQLITE_MALLOC_SO
23b0: 46 54 5f 4c 49 4d 49 54 20 31 30 32 34 0a 23 65 FT_LIMIT 1024.#e
23c0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 57 65 20 6e ndif../*.** We n
23d0: 65 65 64 20 74 6f 20 64 65 66 69 6e 65 20 5f 58 eed to define _X
23e0: 4f 50 45 4e 5f 53 4f 55 52 43 45 20 61 73 20 66 OPEN_SOURCE as f
23f0: 6f 6c 6c 6f 77 73 20 69 6e 20 6f 72 64 65 72 20 ollows in order
2400: 74 6f 20 65 6e 61 62 6c 65 0a 2a 2a 20 72 65 63 to enable.** rec
2410: 75 72 73 69 76 65 20 6d 75 74 65 78 65 73 20 6f ursive mutexes o
2420: 6e 20 6d 6f 73 74 20 55 6e 69 78 20 73 79 73 74 n most Unix syst
2430: 65 6d 73 20 61 6e 64 20 66 63 68 6d 6f 64 28 29 ems and fchmod()
2440: 20 6f 6e 20 4f 70 65 6e 42 53 44 2e 0a 2a 2a 20 on OpenBSD..**
2450: 42 75 74 20 5f 58 4f 50 45 4e 5f 53 4f 55 52 43 But _XOPEN_SOURC
2460: 45 20 64 65 66 69 6e 65 20 63 61 75 73 65 73 20 E define causes
2470: 70 72 6f 62 6c 65 6d 73 20 66 6f 72 20 4d 61 63 problems for Mac
2480: 20 4f 53 20 58 2c 20 73 6f 20 6f 6d 69 74 0a 2a OS X, so omit.*
2490: 2a 20 69 74 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 * it..*/.#if !de
24a0: 66 69 6e 65 64 28 5f 58 4f 50 45 4e 5f 53 4f 55 fined(_XOPEN_SOU
24b0: 52 43 45 29 20 26 26 20 21 64 65 66 69 6e 65 64 RCE) && !defined
24c0: 28 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 26 26 20 (__DARWIN__) &&
24d0: 21 64 65 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 !defined(__APPLE
24e0: 5f 5f 29 0a 23 20 20 64 65 66 69 6e 65 20 5f 58 __).# define _X
24f0: 4f 50 45 4e 5f 53 4f 55 52 43 45 20 36 30 30 0a OPEN_SOURCE 600.
2500: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4e 44 #endif../*.** ND
2510: 45 42 55 47 20 61 6e 64 20 53 51 4c 49 54 45 5f EBUG and SQLITE_
2520: 44 45 42 55 47 20 61 72 65 20 6f 70 70 6f 73 69 DEBUG are opposi
2530: 74 65 73 2e 20 20 49 74 20 73 68 6f 75 6c 64 20 tes. It should
2540: 61 6c 77 61 79 73 20 62 65 20 74 72 75 65 20 74 always be true t
2550: 68 61 74 0a 2a 2a 20 64 65 66 69 6e 65 64 28 4e hat.** defined(N
2560: 44 45 42 55 47 29 3d 3d 21 64 65 66 69 6e 65 64 DEBUG)==!defined
2570: 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 2e 20 (SQLITE_DEBUG).
2580: 20 49 66 20 74 68 69 73 20 69 73 20 6e 6f 74 20 If this is not
2590: 63 75 72 72 65 6e 74 6c 79 20 74 72 75 65 2c 0a currently true,.
25a0: 2a 2a 20 6d 61 6b 65 20 69 74 20 74 72 75 65 20 ** make it true
25b0: 62 79 20 64 65 66 69 6e 69 6e 67 20 6f 72 20 75 by defining or u
25c0: 6e 64 65 66 69 6e 69 6e 67 20 4e 44 45 42 55 47 ndefining NDEBUG
25d0: 2e 0a 2a 2a 0a 2a 2a 20 53 65 74 74 69 6e 67 20 ..**.** Setting
25e0: 4e 44 45 42 55 47 20 6d 61 6b 65 73 20 74 68 65 NDEBUG makes the
25f0: 20 63 6f 64 65 20 73 6d 61 6c 6c 65 72 20 61 6e code smaller an
2600: 64 20 66 61 73 74 65 72 20 62 79 20 64 69 73 61 d faster by disa
2610: 62 6c 69 6e 67 20 74 68 65 0a 2a 2a 20 61 73 73 bling the.** ass
2620: 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
2630: 20 69 6e 20 74 68 65 20 63 6f 64 65 2e 20 20 53 in the code. S
2640: 6f 20 77 65 20 77 61 6e 74 20 74 68 65 20 64 65 o we want the de
2650: 66 61 75 6c 74 20 61 63 74 69 6f 6e 0a 2a 2a 20 fault action.**
2660: 74 6f 20 62 65 20 66 6f 72 20 4e 44 45 42 55 47 to be for NDEBUG
2670: 20 74 6f 20 62 65 20 73 65 74 20 61 6e 64 20 4e to be set and N
2680: 44 45 42 55 47 20 74 6f 20 62 65 20 75 6e 64 65 DEBUG to be unde
2690: 66 69 6e 65 64 20 6f 6e 6c 79 20 69 66 20 53 51 fined only if SQ
26a0: 4c 49 54 45 5f 44 45 42 55 47 0a 2a 2a 20 69 73 LITE_DEBUG.** is
26b0: 20 73 65 74 2e 20 20 54 68 75 73 20 4e 44 45 42 set. Thus NDEB
26c0: 55 47 20 62 65 63 6f 6d 65 73 20 61 6e 20 6f 70 UG becomes an op
26d0: 74 2d 69 6e 20 72 61 74 68 65 72 20 74 68 61 6e t-in rather than
26e0: 20 61 6e 20 6f 70 74 2d 6f 75 74 0a 2a 2a 20 66 an opt-out.** f
26f0: 65 61 74 75 72 65 2e 0a 2a 2f 0a 23 69 66 20 21 eature..*/.#if !
2700: 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 defined(NDEBUG)
2710: 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
2720: 54 45 5f 44 45 42 55 47 29 20 0a 23 20 64 65 66 TE_DEBUG) .# def
2730: 69 6e 65 20 4e 44 45 42 55 47 20 31 0a 23 65 6e ine NDEBUG 1.#en
2740: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
2750: 4e 44 45 42 55 47 29 20 26 26 20 64 65 66 69 6e NDEBUG) && defin
2760: 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 ed(SQLITE_DEBUG)
2770: 0a 23 20 75 6e 64 65 66 20 4e 44 45 42 55 47 0a .# undef NDEBUG.
2780: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 6e #endif../*.** En
2790: 61 62 6c 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 able SQLITE_ENAB
27a0: 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 LE_EXPLAIN_COMME
27b0: 4e 54 53 20 69 66 20 53 51 4c 49 54 45 5f 44 45 NTS if SQLITE_DE
27c0: 42 55 47 20 69 73 20 74 75 72 6e 65 64 20 6f 6e BUG is turned on
27d0: 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 ..*/.#if !define
27e0: 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
27f0: 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 EXPLAIN_COMMENTS
2800: 29 20 26 26 20 64 65 66 69 6e 65 64 28 53 51 4c ) && defined(SQL
2810: 49 54 45 5f 44 45 42 55 47 29 0a 23 20 64 65 66 ITE_DEBUG).# def
2820: 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c ine SQLITE_ENABL
2830: 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 4e E_EXPLAIN_COMMEN
2840: 54 53 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a TS 1.#endif../*.
2850: 2a 2a 20 54 68 65 20 74 65 73 74 63 61 73 65 28 ** The testcase(
2860: 29 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 ) macro is used
2870: 74 6f 20 61 69 64 20 69 6e 20 63 6f 76 65 72 61 to aid in covera
2880: 67 65 20 74 65 73 74 69 6e 67 2e 20 20 57 68 65 ge testing. Whe
2890: 6e 20 0a 2a 2a 20 64 6f 69 6e 67 20 63 6f 76 65 n .** doing cove
28a0: 72 61 67 65 20 74 65 73 74 69 6e 67 2c 20 74 68 rage testing, th
28b0: 65 20 63 6f 6e 64 69 74 69 6f 6e 20 69 6e 73 69 e condition insi
28c0: 64 65 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 de the argument
28d0: 74 6f 0a 2a 2a 20 74 65 73 74 63 61 73 65 28 29 to.** testcase()
28e0: 20 6d 75 73 74 20 62 65 20 65 76 61 6c 75 61 74 must be evaluat
28f0: 65 64 20 62 6f 74 68 20 74 72 75 65 20 61 6e 64 ed both true and
2900: 20 66 61 6c 73 65 20 69 6e 20 6f 72 64 65 72 20 false in order
2910: 74 6f 0a 2a 2a 20 67 65 74 20 66 75 6c 6c 20 62 to.** get full b
2920: 72 61 6e 63 68 20 63 6f 76 65 72 61 67 65 2e 20 ranch coverage.
2930: 20 54 68 65 20 74 65 73 74 63 61 73 65 28 29 20 The testcase()
2940: 6d 61 63 72 6f 20 69 73 20 69 6e 73 65 72 74 65 macro is inserte
2950: 64 0a 2a 2a 20 74 6f 20 68 65 6c 70 20 65 6e 73 d.** to help ens
2960: 75 72 65 20 61 64 65 71 75 61 74 65 20 74 65 73 ure adequate tes
2970: 74 20 63 6f 76 65 72 61 67 65 20 69 6e 20 70 6c t coverage in pl
2980: 61 63 65 73 20 77 68 65 72 65 20 73 69 6d 70 6c aces where simpl
2990: 65 0a 2a 2a 20 63 6f 6e 64 69 74 69 6f 6e 2f 64 e.** condition/d
29a0: 65 63 69 73 69 6f 6e 20 63 6f 76 65 72 61 67 65 ecision coverage
29b0: 20 69 73 20 69 6e 61 64 65 71 75 61 74 65 2e 20 is inadequate.
29c0: 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 65 For example, te
29d0: 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 61 6e 20 stcase().** can
29e0: 62 65 20 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 be used to make
29f0: 73 75 72 65 20 62 6f 75 6e 64 61 72 79 20 76 61 sure boundary va
2a00: 6c 75 65 73 20 61 72 65 20 74 65 73 74 65 64 2e lues are tested.
2a10: 20 20 46 6f 72 0a 2a 2a 20 62 69 74 6d 61 73 6b For.** bitmask
2a20: 20 74 65 73 74 73 2c 20 74 65 73 74 63 61 73 65 tests, testcase
2a30: 28 29 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 () can be used t
2a40: 6f 20 6d 61 6b 65 20 73 75 72 65 20 65 61 63 68 o make sure each
2a50: 20 62 69 74 0a 2a 2a 20 69 73 20 73 69 67 6e 69 bit.** is signi
2a60: 66 69 63 61 6e 74 20 61 6e 64 20 75 73 65 64 20 ficant and used
2a70: 61 74 20 6c 65 61 73 74 20 6f 6e 63 65 2e 20 20 at least once.
2a80: 4f 6e 20 73 77 69 74 63 68 20 73 74 61 74 65 6d On switch statem
2a90: 65 6e 74 73 0a 2a 2a 20 77 68 65 72 65 20 6d 75 ents.** where mu
2aa0: 6c 74 69 70 6c 65 20 63 61 73 65 73 20 67 6f 20 ltiple cases go
2ab0: 74 6f 20 74 68 65 20 73 61 6d 65 20 62 6c 6f 63 to the same bloc
2ac0: 6b 20 6f 66 20 63 6f 64 65 2c 20 74 65 73 74 63 k of code, testc
2ad0: 61 73 65 28 29 0a 2a 2a 20 63 61 6e 20 69 6e 73 ase().** can ins
2ae0: 75 72 65 20 74 68 61 74 20 61 6c 6c 20 63 61 73 ure that all cas
2af0: 65 73 20 61 72 65 20 65 76 61 6c 75 61 74 65 64 es are evaluated
2b00: 2e 0a 2a 2a 0a 2a 2f 0a 23 69 66 64 65 66 20 53 ..**.*/.#ifdef S
2b10: 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 5f 54 QLITE_COVERAGE_T
2b20: 45 53 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 EST. void sqlit
2b30: 65 33 43 6f 76 65 72 61 67 65 28 69 6e 74 29 3b e3Coverage(int);
2b40: 0a 23 20 64 65 66 69 6e 65 20 74 65 73 74 63 61 .# define testca
2b50: 73 65 28 58 29 20 20 69 66 28 20 58 20 29 7b 20 se(X) if( X ){
2b60: 73 71 6c 69 74 65 33 43 6f 76 65 72 61 67 65 28 sqlite3Coverage(
2b70: 5f 5f 4c 49 4e 45 5f 5f 29 3b 20 7d 0a 23 65 6c __LINE__); }.#el
2b80: 73 65 0a 23 20 64 65 66 69 6e 65 20 74 65 73 74 se.# define test
2b90: 63 61 73 65 28 58 29 0a 23 65 6e 64 69 66 0a 0a case(X).#endif..
2ba0: 2f 2a 0a 2a 2a 20 54 68 65 20 54 45 53 54 4f 4e /*.** The TESTON
2bb0: 4c 59 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 LY macro is used
2bc0: 20 74 6f 20 65 6e 63 6c 6f 73 65 20 76 61 72 69 to enclose vari
2bd0: 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f 6e able declaration
2be0: 73 20 6f 72 0a 2a 2a 20 6f 74 68 65 72 20 62 69 s or.** other bi
2bf0: 74 73 20 6f 66 20 63 6f 64 65 20 74 68 61 74 20 ts of code that
2c00: 61 72 65 20 6e 65 65 64 65 64 20 74 6f 20 73 75 are needed to su
2c10: 70 70 6f 72 74 20 74 68 65 20 61 72 67 75 6d 65 pport the argume
2c20: 6e 74 73 0a 2a 2a 20 77 69 74 68 69 6e 20 74 65 nts.** within te
2c30: 73 74 63 61 73 65 28 29 20 61 6e 64 20 61 73 73 stcase() and ass
2c40: 65 72 74 28 29 20 6d 61 63 72 6f 73 2e 0a 2a 2f ert() macros..*/
2c50: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 4e 44 .#if !defined(ND
2c60: 45 42 55 47 29 20 7c 7c 20 64 65 66 69 6e 65 64 EBUG) || defined
2c70: 28 53 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 (SQLITE_COVERAGE
2c80: 5f 54 45 53 54 29 0a 23 20 64 65 66 69 6e 65 20 _TEST).# define
2c90: 54 45 53 54 4f 4e 4c 59 28 58 29 20 20 58 0a 23 TESTONLY(X) X.#
2ca0: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 54 45 else.# define TE
2cb0: 53 54 4f 4e 4c 59 28 58 29 0a 23 65 6e 64 69 66 STONLY(X).#endif
2cc0: 0a 0a 2f 2a 0a 2a 2a 20 53 6f 6d 65 74 69 6d 65 ../*.** Sometime
2cd0: 73 20 77 65 20 6e 65 65 64 20 61 20 73 6d 61 6c s we need a smal
2ce0: 6c 20 61 6d 6f 75 6e 74 20 6f 66 20 63 6f 64 65 l amount of code
2cf0: 20 73 75 63 68 20 61 73 20 61 20 76 61 72 69 61 such as a varia
2d00: 62 6c 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ble initializati
2d10: 6f 6e 0a 2a 2a 20 74 6f 20 73 65 74 75 70 20 66 on.** to setup f
2d20: 6f 72 20 61 20 6c 61 74 65 72 20 61 73 73 65 72 or a later asser
2d30: 74 28 29 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 t() statement.
2d40: 57 65 20 64 6f 20 6e 6f 74 20 77 61 6e 74 20 74 We do not want t
2d50: 68 69 73 20 63 6f 64 65 20 74 6f 0a 2a 2a 20 61 his code to.** a
2d60: 70 70 65 61 72 20 77 68 65 6e 20 61 73 73 65 72 ppear when asser
2d70: 74 28 29 20 69 73 20 64 69 73 61 62 6c 65 64 2e t() is disabled.
2d80: 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 The following
2d90: 6d 61 63 72 6f 20 69 73 20 74 68 65 72 65 66 6f macro is therefo
2da0: 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f 20 63 6f re.** used to co
2db0: 6e 74 61 69 6e 20 74 68 61 74 20 73 65 74 75 70 ntain that setup
2dc0: 20 63 6f 64 65 2e 20 20 54 68 65 20 22 56 56 41 code. The "VVA
2dd0: 22 20 61 63 72 6f 6e 79 6d 20 73 74 61 6e 64 73 " acronym stands
2de0: 20 66 6f 72 0a 2a 2a 20 22 56 65 72 69 66 69 63 for.** "Verific
2df0: 61 74 69 6f 6e 2c 20 56 61 6c 69 64 61 74 69 6f ation, Validatio
2e00: 6e 2c 20 61 6e 64 20 41 63 63 72 65 64 69 74 61 n, and Accredita
2e10: 74 69 6f 6e 22 2e 20 20 49 6e 20 6f 74 68 65 72 tion". In other
2e20: 20 77 6f 72 64 73 2c 20 74 68 65 0a 2a 2a 20 63 words, the.** c
2e30: 6f 64 65 20 77 69 74 68 69 6e 20 56 56 41 5f 4f ode within VVA_O
2e40: 4e 4c 59 28 29 20 77 69 6c 6c 20 6f 6e 6c 79 20 NLY() will only
2e50: 72 75 6e 20 64 75 72 69 6e 67 20 76 65 72 69 66 run during verif
2e60: 69 63 61 74 69 6f 6e 20 70 72 6f 63 65 73 73 65 ication processe
2e70: 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 4e 44 s..*/.#ifndef ND
2e80: 45 42 55 47 0a 23 20 64 65 66 69 6e 65 20 56 56 EBUG.# define VV
2e90: 41 5f 4f 4e 4c 59 28 58 29 20 20 58 0a 23 65 6c A_ONLY(X) X.#el
2ea0: 73 65 0a 23 20 64 65 66 69 6e 65 20 56 56 41 5f se.# define VVA_
2eb0: 4f 4e 4c 59 28 58 29 0a 23 65 6e 64 69 66 0a 0a ONLY(X).#endif..
2ec0: 2f 2a 0a 2a 2a 20 54 68 65 20 41 4c 57 41 59 53 /*.** The ALWAYS
2ed0: 20 61 6e 64 20 4e 45 56 45 52 20 6d 61 63 72 6f and NEVER macro
2ee0: 73 20 73 75 72 72 6f 75 6e 64 20 62 6f 6f 6c 65 s surround boole
2ef0: 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 73 20 77 an expressions w
2f00: 68 69 63 68 20 0a 2a 2a 20 61 72 65 20 69 6e 74 hich .** are int
2f10: 65 6e 64 65 64 20 74 6f 20 61 6c 77 61 79 73 20 ended to always
2f20: 62 65 20 74 72 75 65 20 6f 72 20 66 61 6c 73 65 be true or false
2f30: 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 , respectively.
2f40: 20 53 75 63 68 0a 2a 2a 20 65 78 70 72 65 73 73 Such.** express
2f50: 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 20 6f 6d ions could be om
2f60: 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 20 63 itted from the c
2f70: 6f 64 65 20 63 6f 6d 70 6c 65 74 65 6c 79 2e 20 ode completely.
2f80: 20 42 75 74 20 74 68 65 79 0a 2a 2a 20 61 72 65 But they.** are
2f90: 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 61 20 66 included in a f
2fa0: 65 77 20 63 61 73 65 73 20 69 6e 20 6f 72 64 65 ew cases in orde
2fb0: 72 20 74 6f 20 65 6e 68 61 6e 63 65 20 74 68 65 r to enhance the
2fc0: 20 72 65 73 69 6c 69 65 6e 63 65 0a 2a 2a 20 6f resilience.** o
2fd0: 66 20 53 51 4c 69 74 65 20 74 6f 20 75 6e 65 78 f SQLite to unex
2fe0: 70 65 63 74 65 64 20 62 65 68 61 76 69 6f 72 20 pected behavior
2ff0: 2d 20 74 6f 20 6d 61 6b 65 20 74 68 65 20 63 6f - to make the co
3000: 64 65 20 22 73 65 6c 66 2d 68 65 61 6c 69 6e 67 de "self-healing
3010: 22 0a 2a 2a 20 6f 72 20 22 64 75 63 74 69 6c 65 ".** or "ductile
3020: 22 20 72 61 74 68 65 72 20 74 68 61 6e 20 62 65 " rather than be
3030: 69 6e 67 20 22 62 72 69 74 74 6c 65 22 20 61 6e ing "brittle" an
3040: 64 20 63 72 61 73 68 69 6e 67 20 61 74 20 74 68 d crashing at th
3050: 65 20 66 69 72 73 74 0a 2a 2a 20 68 69 6e 74 20 e first.** hint
3060: 6f 66 20 75 6e 70 6c 61 6e 6e 65 64 20 62 65 68 of unplanned beh
3070: 61 76 69 6f 72 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 avior..**.** In
3080: 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 41 4c 57 other words, ALW
3090: 41 59 53 20 61 6e 64 20 4e 45 56 45 52 20 61 72 AYS and NEVER ar
30a0: 65 20 61 64 64 65 64 20 66 6f 72 20 64 65 66 65 e added for defe
30b0: 6e 73 69 76 65 20 63 6f 64 65 2e 0a 2a 2a 0a 2a nsive code..**.*
30c0: 2a 20 57 68 65 6e 20 64 6f 69 6e 67 20 63 6f 76 * When doing cov
30d0: 65 72 61 67 65 20 74 65 73 74 69 6e 67 20 41 4c erage testing AL
30e0: 57 41 59 53 20 61 6e 64 20 4e 45 56 45 52 20 61 WAYS and NEVER a
30f0: 72 65 20 68 61 72 64 2d 63 6f 64 65 64 20 74 6f re hard-coded to
3100: 0a 2a 2a 20 62 65 20 74 72 75 65 20 61 6e 64 20 .** be true and
3110: 66 61 6c 73 65 20 73 6f 20 74 68 61 74 20 74 68 false so that th
3120: 65 20 75 6e 72 65 61 63 68 61 62 6c 65 20 63 6f e unreachable co
3130: 64 65 20 74 68 65 79 20 73 70 65 63 69 66 79 20 de they specify
3140: 77 69 6c 6c 0a 2a 2a 20 6e 6f 74 20 62 65 20 63 will.** not be c
3150: 6f 75 6e 74 65 64 20 61 73 20 75 6e 74 65 73 74 ounted as untest
3160: 65 64 20 63 6f 64 65 2e 0a 2a 2f 0a 23 69 66 20 ed code..*/.#if
3170: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 43 defined(SQLITE_C
3180: 4f 56 45 52 41 47 45 5f 54 45 53 54 29 0a 23 20 OVERAGE_TEST).#
3190: 64 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 29 define ALWAYS(X)
31a0: 20 20 20 20 20 20 28 31 29 0a 23 20 64 65 66 69 (1).# defi
31b0: 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 20 ne NEVER(X)
31c0: 20 20 28 30 29 0a 23 65 6c 69 66 20 21 64 65 66 (0).#elif !def
31d0: 69 6e 65 64 28 4e 44 45 42 55 47 29 0a 23 20 64 ined(NDEBUG).# d
31e0: 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 29 20 efine ALWAYS(X)
31f0: 20 20 20 20 20 28 28 58 29 3f 31 3a 28 61 73 73 ((X)?1:(ass
3200: 65 72 74 28 30 29 2c 30 29 29 0a 23 20 64 65 66 ert(0),0)).# def
3210: 69 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 ine NEVER(X)
3220: 20 20 20 28 28 58 29 3f 28 61 73 73 65 72 74 28 ((X)?(assert(
3230: 30 29 2c 31 29 3a 30 29 0a 23 65 6c 73 65 0a 23 0),1):0).#else.#
3240: 20 64 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 define ALWAYS(X
3250: 29 20 20 20 20 20 20 28 58 29 0a 23 20 64 65 66 ) (X).# def
3260: 69 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 ine NEVER(X)
3270: 20 20 20 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f (X).#endif../
3280: 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 *.** Return true
3290: 20 28 6e 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 74 (non-zero) if t
32a0: 68 65 20 69 6e 70 75 74 20 69 73 20 61 6e 20 69 he input is an i
32b0: 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 74 nteger that is t
32c0: 6f 6f 20 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 66 oo large.** to f
32d0: 69 74 20 69 6e 20 33 32 2d 62 69 74 73 2e 20 20 it in 32-bits.
32e0: 54 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 This macro is us
32f0: 65 64 20 69 6e 73 69 64 65 20 6f 66 20 76 61 72 ed inside of var
3300: 69 6f 75 73 20 74 65 73 74 63 61 73 65 28 29 0a ious testcase().
3310: 2a 2a 20 6d 61 63 72 6f 73 20 74 6f 20 76 65 72 ** macros to ver
3320: 69 66 79 20 74 68 61 74 20 77 65 20 68 61 76 65 ify that we have
3330: 20 74 65 73 74 65 64 20 53 51 4c 69 74 65 20 66 tested SQLite f
3340: 6f 72 20 6c 61 72 67 65 2d 66 69 6c 65 20 73 75 or large-file su
3350: 70 70 6f 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e pport..*/.#defin
3360: 65 20 49 53 5f 42 49 47 5f 49 4e 54 28 58 29 20 e IS_BIG_INT(X)
3370: 20 28 28 28 58 29 26 7e 28 69 36 34 29 30 78 66 (((X)&~(i64)0xf
3380: 66 66 66 66 66 66 66 29 21 3d 30 29 0a 0a 2f 2a fffffff)!=0)../*
3390: 0a 2a 2a 20 54 68 65 20 6d 61 63 72 6f 20 75 6e .** The macro un
33a0: 6c 69 6b 65 6c 79 28 29 20 69 73 20 61 20 68 69 likely() is a hi
33b0: 6e 74 20 74 68 61 74 20 73 75 72 72 6f 75 6e 64 nt that surround
33c0: 73 20 61 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 65 s a boolean.** e
33d0: 78 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 xpression that i
33e0: 73 20 75 73 75 61 6c 6c 79 20 66 61 6c 73 65 2e s usually false.
33f0: 20 20 4d 61 63 72 6f 20 6c 69 6b 65 6c 79 28 29 Macro likely()
3400: 20 73 75 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 20 surrounds.** a
3410: 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 69 boolean expressi
3420: 6f 6e 20 74 68 61 74 20 69 73 20 75 73 75 61 6c on that is usual
3430: 6c 79 20 74 72 75 65 2e 20 20 54 68 65 73 65 20 ly true. These
3440: 68 69 6e 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a 20 hints could,.**
3450: 69 6e 20 74 68 65 6f 72 79 2c 20 62 65 20 75 73 in theory, be us
3460: 65 64 20 62 79 20 74 68 65 20 63 6f 6d 70 69 6c ed by the compil
3470: 65 72 20 74 6f 20 67 65 6e 65 72 61 74 65 20 62 er to generate b
3480: 65 74 74 65 72 20 63 6f 64 65 2c 20 62 75 74 0a etter code, but.
3490: 2a 2a 20 63 75 72 72 65 6e 74 6c 79 20 74 68 65 ** currently the
34a0: 79 20 61 72 65 20 6a 75 73 74 20 63 6f 6d 6d 65 y are just comme
34b0: 6e 74 73 20 66 6f 72 20 68 75 6d 61 6e 20 72 65 nts for human re
34c0: 61 64 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e aders..*/.#defin
34d0: 65 20 6c 69 6b 65 6c 79 28 58 29 20 20 20 20 28 e likely(X) (
34e0: 58 29 0a 23 64 65 66 69 6e 65 20 75 6e 6c 69 6b X).#define unlik
34f0: 65 6c 79 28 58 29 20 20 28 58 29 0a 0a 23 69 6e ely(X) (X)..#in
3500: 63 6c 75 64 65 20 22 68 61 73 68 2e 68 22 0a 23 clude "hash.h".#
3510: 69 6e 63 6c 75 64 65 20 22 70 61 72 73 65 2e 68 include "parse.h
3520: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 ".#include <stdi
3530: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 o.h>.#include <s
3540: 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 tdlib.h>.#includ
3550: 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e e <string.h>.#in
3560: 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e clude <assert.h>
3570: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 64 65 .#include <stdde
3580: 66 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 63 f.h>../*.** If c
3590: 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 20 61 20 70 ompiling for a p
35a0: 72 6f 63 65 73 73 6f 72 20 74 68 61 74 20 6c 61 rocessor that la
35b0: 63 6b 73 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 cks floating poi
35c0: 6e 74 20 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 73 nt support,.** s
35d0: 75 62 73 74 69 74 75 74 65 20 69 6e 74 65 67 65 ubstitute intege
35e0: 72 20 66 6f 72 20 66 6c 6f 61 74 69 6e 67 2d 70 r for floating-p
35f0: 6f 69 6e 74 0a 2a 2f 0a 23 69 66 64 65 66 20 53 oint.*/.#ifdef S
3600: 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 QLITE_OMIT_FLOAT
3610: 49 4e 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 ING_POINT.# defi
3620: 6e 65 20 64 6f 75 62 6c 65 20 73 71 6c 69 74 65 ne double sqlite
3630: 5f 69 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 20 _int64.# define
3640: 66 6c 6f 61 74 20 73 71 6c 69 74 65 5f 69 6e 74 float sqlite_int
3650: 36 34 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e 47 64.# define LONG
3660: 44 4f 55 42 4c 45 5f 54 59 50 45 20 73 71 6c 69 DOUBLE_TYPE sqli
3670: 74 65 5f 69 6e 74 36 34 0a 23 20 69 66 6e 64 65 te_int64.# ifnde
3680: 66 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c f SQLITE_BIG_DBL
3690: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
36a0: 54 45 5f 42 49 47 5f 44 42 4c 20 28 28 28 73 71 TE_BIG_DBL (((sq
36b0: 6c 69 74 65 33 5f 69 6e 74 36 34 29 31 29 3c 3c lite3_int64)1)<<
36c0: 35 30 29 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 50).# endif.# de
36d0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fine SQLITE_OMIT
36e0: 5f 44 41 54 45 54 49 4d 45 5f 46 55 4e 43 53 20 _DATETIME_FUNCS
36f0: 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 1.# define SQLIT
3700: 45 5f 4f 4d 49 54 5f 54 52 41 43 45 20 31 0a 23 E_OMIT_TRACE 1.#
3710: 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 49 undef SQLITE_MI
3720: 58 45 44 5f 45 4e 44 49 41 4e 5f 36 34 42 49 54 XED_ENDIAN_64BIT
3730: 5f 46 4c 4f 41 54 0a 23 20 75 6e 64 65 66 20 53 _FLOAT.# undef S
3740: 51 4c 49 54 45 5f 48 41 56 45 5f 49 53 4e 41 4e QLITE_HAVE_ISNAN
3750: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
3760: 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 SQLITE_BIG_DBL.#
3770: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 define SQLITE_B
3780: 49 47 5f 44 42 4c 20 28 31 65 39 39 29 0a 23 65 IG_DBL (1e99).#e
3790: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 54 ndif../*.** OMIT
37a0: 5f 54 45 4d 50 44 42 20 69 73 20 73 65 74 20 74 _TEMPDB is set t
37b0: 6f 20 31 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d o 1 if SQLITE_OM
37c0: 49 54 5f 54 45 4d 50 44 42 20 69 73 20 64 65 66 IT_TEMPDB is def
37d0: 69 6e 65 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 66 ined, or 0.** af
37e0: 74 65 72 77 61 72 64 2e 20 48 61 76 69 6e 67 20 terward. Having
37f0: 74 68 69 73 20 6d 61 63 72 6f 20 61 6c 6c 6f 77 this macro allow
3800: 73 20 75 73 20 74 6f 20 63 61 75 73 65 20 74 68 s us to cause th
3810: 65 20 43 20 63 6f 6d 70 69 6c 65 72 20 0a 2a 2a e C compiler .**
3820: 20 74 6f 20 6f 6d 69 74 20 63 6f 64 65 20 75 73 to omit code us
3830: 65 64 20 62 79 20 54 45 4d 50 20 74 61 62 6c 65 ed by TEMP table
3840: 73 20 77 69 74 68 6f 75 74 20 6d 65 73 73 79 20 s without messy
3850: 23 69 66 6e 64 65 66 20 73 74 61 74 65 6d 65 6e #ifndef statemen
3860: 74 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 ts..*/.#ifdef SQ
3870: 4c 49 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 LITE_OMIT_TEMPDB
3880: 0a 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 .#define OMIT_TE
3890: 4d 50 44 42 20 31 0a 23 65 6c 73 65 0a 23 64 65 MPDB 1.#else.#de
38a0: 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 42 fine OMIT_TEMPDB
38b0: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 0.#endif../*.**
38c0: 20 54 68 65 20 22 66 69 6c 65 20 66 6f 72 6d 61 The "file forma
38d0: 74 22 20 6e 75 6d 62 65 72 20 69 73 20 61 6e 20 t" number is an
38e0: 69 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 integer that is
38f0: 69 6e 63 72 65 6d 65 6e 74 65 64 20 77 68 65 6e incremented when
3900: 65 76 65 72 0a 2a 2a 20 74 68 65 20 56 44 42 45 ever.** the VDBE
3910: 2d 6c 65 76 65 6c 20 66 69 6c 65 20 66 6f 72 6d -level file form
3920: 61 74 20 63 68 61 6e 67 65 73 2e 20 20 54 68 65 at changes. The
3930: 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f following macro
3940: 73 20 64 65 66 69 6e 65 20 74 68 65 0a 2a 2a 20 s define the.**
3950: 74 68 65 20 64 65 66 61 75 6c 74 20 66 69 6c 65 the default file
3960: 20 66 6f 72 6d 61 74 20 66 6f 72 20 6e 65 77 20 format for new
3970: 64 61 74 61 62 61 73 65 73 20 61 6e 64 20 74 68 databases and th
3980: 65 20 6d 61 78 69 6d 75 6d 20 66 69 6c 65 20 66 e maximum file f
3990: 6f 72 6d 61 74 0a 2a 2a 20 74 68 61 74 20 74 68 ormat.** that th
39a0: 65 20 6c 69 62 72 61 72 79 20 63 61 6e 20 72 65 e library can re
39b0: 61 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ad..*/.#define S
39c0: 51 4c 49 54 45 5f 4d 41 58 5f 46 49 4c 45 5f 46 QLITE_MAX_FILE_F
39d0: 4f 52 4d 41 54 20 34 0a 23 69 66 6e 64 65 66 20 ORMAT 4.#ifndef
39e0: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 46 SQLITE_DEFAULT_F
39f0: 49 4c 45 5f 46 4f 52 4d 41 54 0a 23 20 64 65 66 ILE_FORMAT.# def
3a00: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
3a10: 4c 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 20 34 LT_FILE_FORMAT 4
3a20: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 .#endif../*.** D
3a30: 65 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 etermine whether
3a40: 20 74 72 69 67 67 65 72 73 20 61 72 65 20 72 65 triggers are re
3a50: 63 75 72 73 69 76 65 20 62 79 20 64 65 66 61 75 cursive by defau
3a60: 6c 74 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 lt. This can be
3a70: 0a 2a 2a 20 63 68 61 6e 67 65 64 20 61 74 20 72 .** changed at r
3a80: 75 6e 2d 74 69 6d 65 20 75 73 69 6e 67 20 61 20 un-time using a
3a90: 70 72 61 67 6d 61 2e 0a 2a 2f 0a 23 69 66 6e 64 pragma..*/.#ifnd
3aa0: 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ef SQLITE_DEFAUL
3ab0: 54 5f 52 45 43 55 52 53 49 56 45 5f 54 52 49 47 T_RECURSIVE_TRIG
3ac0: 47 45 52 53 0a 23 20 64 65 66 69 6e 65 20 53 51 GERS.# define SQ
3ad0: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 43 LITE_DEFAULT_REC
3ae0: 55 52 53 49 56 45 5f 54 52 49 47 47 45 52 53 20 URSIVE_TRIGGERS
3af0: 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
3b00: 50 72 6f 76 69 64 65 20 61 20 64 65 66 61 75 6c Provide a defaul
3b10: 74 20 76 61 6c 75 65 20 66 6f 72 20 53 51 4c 49 t value for SQLI
3b20: 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 6e TE_TEMP_STORE in
3b30: 20 63 61 73 65 20 69 74 20 69 73 20 6e 6f 74 20 case it is not
3b40: 73 70 65 63 69 66 69 65 64 0a 2a 2a 20 6f 6e 20 specified.** on
3b50: 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 the command-line
3b60: 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 .*/.#ifndef SQLI
3b70: 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 0a 23 20 TE_TEMP_STORE.#
3b80: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 define SQLITE_TE
3b90: 4d 50 5f 53 54 4f 52 45 20 31 0a 23 20 64 65 66 MP_STORE 1.# def
3ba0: 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f ine SQLITE_TEMP_
3bb0: 53 54 4f 52 45 5f 78 63 20 31 20 20 2f 2a 20 45 STORE_xc 1 /* E
3bc0: 78 63 6c 75 64 65 20 66 72 6f 6d 20 63 74 69 6d xclude from ctim
3bd0: 65 2e 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f e.c */.#endif../
3be0: 2a 0a 2a 2a 20 49 66 20 6e 6f 20 76 61 6c 75 65 *.** If no value
3bf0: 20 68 61 73 20 62 65 65 6e 20 70 72 6f 76 69 64 has been provid
3c00: 65 64 20 66 6f 72 20 53 51 4c 49 54 45 5f 4d 41 ed for SQLITE_MA
3c10: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
3c20: 2c 20 6f 72 20 69 66 0a 2a 2a 20 53 51 4c 49 54 , or if.** SQLIT
3c30: 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 73 20 E_TEMP_STORE is
3c40: 73 65 74 20 74 6f 20 33 20 28 6e 65 76 65 72 20 set to 3 (never
3c50: 75 73 65 20 74 65 6d 70 6f 72 61 72 79 20 66 69 use temporary fi
3c60: 6c 65 73 29 2c 20 73 65 74 20 69 74 20 0a 2a 2a les), set it .**
3c70: 20 74 6f 20 7a 65 72 6f 2e 0a 2a 2f 0a 23 69 66 to zero..*/.#if
3c80: 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f SQLITE_TEMP_STO
3c90: 52 45 3d 3d 33 20 7c 7c 20 53 51 4c 49 54 45 5f RE==3 || SQLITE_
3ca0: 54 48 52 45 41 44 53 41 46 45 3d 3d 30 0a 23 20 THREADSAFE==0.#
3cb0: 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 undef SQLITE_MAX
3cc0: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a _WORKER_THREADS.
3cd0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
3ce0: 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 MAX_WORKER_THREA
3cf0: 44 53 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 6e DS 0.#endif.#ifn
3d00: 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 def SQLITE_MAX_W
3d10: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
3d20: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
3d30: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
3d40: 20 38 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 8.#endif.#ifnde
3d50: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
3d60: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a _WORKER_THREADS.
3d70: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
3d80: 44 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 DEFAULT_WORKER_T
3d90: 48 52 45 41 44 53 20 30 0a 23 65 6e 64 69 66 0a HREADS 0.#endif.
3da0: 23 69 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 #if SQLITE_DEFAU
3db0: 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 LT_WORKER_THREAD
3dc0: 53 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 S>SQLITE_MAX_WOR
3dd0: 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 75 6e KER_THREADS.# un
3de0: 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 def SQLITE_MAX_W
3df0: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
3e00: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
3e10: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
3e20: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
3e30: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 WORKER_THREADS.#
3e40: 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 47 43 endif.../*.** GC
3e50: 43 20 64 6f 65 73 20 6e 6f 74 20 64 65 66 69 6e C does not defin
3e60: 65 20 74 68 65 20 6f 66 66 73 65 74 6f 66 28 29 e the offsetof()
3e70: 20 6d 61 63 72 6f 20 73 6f 20 77 65 27 6c 6c 20 macro so we'll
3e80: 68 61 76 65 20 74 6f 20 64 6f 20 69 74 0a 2a 2a have to do it.**
3e90: 20 6f 75 72 73 65 6c 76 65 73 2e 0a 2a 2f 0a 23 ourselves..*/.#
3ea0: 69 66 6e 64 65 66 20 6f 66 66 73 65 74 6f 66 0a ifndef offsetof.
3eb0: 23 64 65 66 69 6e 65 20 6f 66 66 73 65 74 6f 66 #define offsetof
3ec0: 28 53 54 52 55 43 54 55 52 45 2c 46 49 45 4c 44 (STRUCTURE,FIELD
3ed0: 29 20 28 28 69 6e 74 29 28 28 63 68 61 72 2a 29 ) ((int)((char*)
3ee0: 26 28 28 53 54 52 55 43 54 55 52 45 2a 29 30 29 &((STRUCTURE*)0)
3ef0: 2d 3e 46 49 45 4c 44 29 29 0a 23 65 6e 64 69 66 ->FIELD)).#endif
3f00: 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 ../*.** Macros t
3f10: 6f 20 63 6f 6d 70 75 74 65 20 6d 69 6e 69 6d 75 o compute minimu
3f20: 6d 20 61 6e 64 20 6d 61 78 69 6d 75 6d 20 6f 66 m and maximum of
3f30: 20 74 77 6f 20 6e 75 6d 62 65 72 73 2e 0a 2a 2f two numbers..*/
3f40: 0a 23 64 65 66 69 6e 65 20 4d 49 4e 28 41 2c 42 .#define MIN(A,B
3f50: 29 20 28 28 41 29 3c 28 42 29 3f 28 41 29 3a 28 ) ((A)<(B)?(A):(
3f60: 42 29 29 0a 23 64 65 66 69 6e 65 20 4d 41 58 28 B)).#define MAX(
3f70: 41 2c 42 29 20 28 28 41 29 3e 28 42 29 3f 28 41 A,B) ((A)>(B)?(A
3f80: 29 3a 28 42 29 29 0a 0a 2f 2a 0a 2a 2a 20 53 77 ):(B))../*.** Sw
3f90: 61 70 20 74 77 6f 20 6f 62 6a 65 63 74 73 20 6f ap two objects o
3fa0: 66 20 74 79 70 65 20 54 59 50 45 2e 0a 2a 2f 0a f type TYPE..*/.
3fb0: 23 64 65 66 69 6e 65 20 53 57 41 50 28 54 59 50 #define SWAP(TYP
3fc0: 45 2c 41 2c 42 29 20 7b 54 59 50 45 20 74 3d 41 E,A,B) {TYPE t=A
3fd0: 3b 20 41 3d 42 3b 20 42 3d 74 3b 7d 0a 0a 2f 2a ; A=B; B=t;}../*
3fe0: 0a 2a 2a 20 43 68 65 63 6b 20 74 6f 20 73 65 65 .** Check to see
3ff0: 20 69 66 20 74 68 69 73 20 6d 61 63 68 69 6e 65 if this machine
4000: 20 75 73 65 73 20 45 42 43 44 49 43 2e 20 20 28 uses EBCDIC. (
4010: 59 65 73 2c 20 62 65 6c 69 65 76 65 20 69 74 20 Yes, believe it
4020: 6f 72 0a 2a 2a 20 6e 6f 74 2c 20 74 68 65 72 65 or.** not, there
4030: 20 61 72 65 20 73 74 69 6c 6c 20 6d 61 63 68 69 are still machi
4040: 6e 65 73 20 6f 75 74 20 74 68 65 72 65 20 74 68 nes out there th
4050: 61 74 20 75 73 65 20 45 42 43 44 49 43 2e 29 0a at use EBCDIC.).
4060: 2a 2f 0a 23 69 66 20 27 41 27 20 3d 3d 20 27 5c */.#if 'A' == '\
4070: 33 30 31 27 0a 23 20 64 65 66 69 6e 65 20 53 51 301'.# define SQ
4080: 4c 49 54 45 5f 45 42 43 44 49 43 20 31 0a 23 65 LITE_EBCDIC 1.#e
4090: 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 51 4c lse.# define SQL
40a0: 49 54 45 5f 41 53 43 49 49 20 31 0a 23 65 6e 64 ITE_ASCII 1.#end
40b0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 67 65 if../*.** Intege
40c0: 72 73 20 6f 66 20 6b 6e 6f 77 6e 20 73 69 7a 65 rs of known size
40d0: 73 2e 20 20 54 68 65 73 65 20 74 79 70 65 64 65 s. These typede
40e0: 66 73 20 6d 69 67 68 74 20 63 68 61 6e 67 65 20 fs might change
40f0: 66 6f 72 20 61 72 63 68 69 74 65 63 74 75 72 65 for architecture
4100: 73 0a 2a 2a 20 77 68 65 72 65 20 74 68 65 20 73 s.** where the s
4110: 69 7a 65 73 20 76 65 72 79 2e 20 20 50 72 65 70 izes very. Prep
4120: 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 20 rocessor macros
4130: 61 72 65 20 61 76 61 69 6c 61 62 6c 65 20 73 6f are available so
4140: 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 74 79 70 that the.** typ
4150: 65 73 20 63 61 6e 20 62 65 20 63 6f 6e 76 65 6e es can be conven
4160: 69 65 6e 74 6c 79 20 72 65 64 65 66 69 6e 65 64 iently redefined
4170: 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 79 70 65 at compile-type
4180: 2e 20 20 4c 69 6b 65 20 74 68 69 73 3a 0a 2a 2a . Like this:.**
4190: 0a 2a 2a 20 20 20 20 20 20 20 20 20 63 63 20 27 .** cc '
41a0: 2d 44 55 49 4e 54 50 54 52 5f 54 59 50 45 3d 6c -DUINTPTR_TYPE=l
41b0: 6f 6e 67 20 6c 6f 6e 67 20 69 6e 74 27 20 2e 2e ong long int' ..
41c0: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 55 49 4e ..*/.#ifndef UIN
41d0: 54 33 32 5f 54 59 50 45 0a 23 20 69 66 64 65 66 T32_TYPE.# ifdef
41e0: 20 48 41 56 45 5f 55 49 4e 54 33 32 5f 54 0a 23 HAVE_UINT32_T.#
41f0: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 33 32 5f define UINT32_
4200: 54 59 50 45 20 75 69 6e 74 33 32 5f 74 0a 23 20 TYPE uint32_t.#
4210: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
4220: 49 4e 54 33 32 5f 54 59 50 45 20 75 6e 73 69 67 INT32_TYPE unsig
4230: 6e 65 64 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a ned int.# endif.
4240: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 #endif.#ifndef U
4250: 49 4e 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 INT16_TYPE.# ifd
4260: 65 66 20 48 41 56 45 5f 55 49 4e 54 31 36 5f 54 ef HAVE_UINT16_T
4270: 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 31 .# define UINT1
4280: 36 5f 54 59 50 45 20 75 69 6e 74 31 36 5f 74 0a 6_TYPE uint16_t.
4290: 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 # else.# define
42a0: 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 6e 73 UINT16_TYPE uns
42b0: 69 67 6e 65 64 20 73 68 6f 72 74 20 69 6e 74 0a igned short int.
42c0: 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 # endif.#endif.#
42d0: 69 66 6e 64 65 66 20 49 4e 54 31 36 5f 54 59 50 ifndef INT16_TYP
42e0: 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 E.# ifdef HAVE_I
42f0: 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 NT16_T.# define
4300: 20 49 4e 54 31 36 5f 54 59 50 45 20 69 6e 74 31 INT16_TYPE int1
4310: 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 6_t.# else.# de
4320: 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 fine INT16_TYPE
4330: 73 68 6f 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 short int.# endi
4340: 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 f.#endif.#ifndef
4350: 20 55 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 UINT8_TYPE.# if
4360: 64 65 66 20 48 41 56 45 5f 55 49 4e 54 38 5f 54 def HAVE_UINT8_T
4370: 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 38 .# define UINT8
4380: 5f 54 59 50 45 20 75 69 6e 74 38 5f 74 0a 23 20 _TYPE uint8_t.#
4390: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
43a0: 49 4e 54 38 5f 54 59 50 45 20 75 6e 73 69 67 6e INT8_TYPE unsign
43b0: 65 64 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a ed char.# endif.
43c0: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 #endif.#ifndef I
43d0: 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 64 65 66 NT8_TYPE.# ifdef
43e0: 20 48 41 56 45 5f 49 4e 54 38 5f 54 0a 23 20 20 HAVE_INT8_T.#
43f0: 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 define INT8_TYPE
4400: 20 69 6e 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 int8_t.# else.#
4410: 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 define INT8_TY
4420: 50 45 20 73 69 67 6e 65 64 20 63 68 61 72 0a 23 PE signed char.#
4430: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 endif.#endif.#i
4440: 66 6e 64 65 66 20 4c 4f 4e 47 44 4f 55 42 4c 45 fndef LONGDOUBLE
4450: 5f 54 59 50 45 0a 23 20 64 65 66 69 6e 65 20 4c _TYPE.# define L
4460: 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 6c ONGDOUBLE_TYPE l
4470: 6f 6e 67 20 64 6f 75 62 6c 65 0a 23 65 6e 64 69 ong double.#endi
4480: 66 0a 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 f.typedef sqlite
4490: 5f 69 6e 74 36 34 20 69 36 34 3b 20 20 20 20 20 _int64 i64;
44a0: 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 73 /* 8-byte s
44b0: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
44c0: 0a 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f .typedef sqlite_
44d0: 75 69 6e 74 36 34 20 75 36 34 3b 20 20 20 20 20 uint64 u64;
44e0: 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 75 6e /* 8-byte un
44f0: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
4500: 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 33 32 /.typedef UINT32
4510: 5f 54 59 50 45 20 75 33 32 3b 20 20 20 20 20 20 _TYPE u32;
4520: 20 20 20 20 20 2f 2a 20 34 2d 62 79 74 65 20 75 /* 4-byte u
4530: 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 nsigned integer
4540: 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 31 */.typedef UINT1
4550: 36 5f 54 59 50 45 20 75 31 36 3b 20 20 20 20 20 6_TYPE u16;
4560: 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 /* 2-byte
4570: 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 unsigned integer
4580: 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 */.typedef INT1
4590: 36 5f 54 59 50 45 20 69 31 36 3b 20 20 20 20 20 6_TYPE i16;
45a0: 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 /* 2-byte
45b0: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 signed integer
45c0: 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 38 */.typedef UINT8
45d0: 5f 54 59 50 45 20 75 38 3b 20 20 20 20 20 20 20 _TYPE u8;
45e0: 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 /* 1-byte
45f0: 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 unsigned integer
4600: 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 38 */.typedef INT8
4610: 5f 54 59 50 45 20 69 38 3b 20 20 20 20 20 20 20 _TYPE i8;
4620: 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 /* 1-byte
4630: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 signed integer
4640: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 */../*.** SQLITE
4650: 5f 4d 41 58 5f 55 33 32 20 69 73 20 61 20 75 36 _MAX_U32 is a u6
4660: 34 20 63 6f 6e 73 74 61 6e 74 20 74 68 61 74 20 4 constant that
4670: 69 73 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 75 is the maximum u
4680: 36 34 20 76 61 6c 75 65 0a 2a 2a 20 74 68 61 74 64 value.** that
4690: 20 63 61 6e 20 62 65 20 73 74 6f 72 65 64 20 69 can be stored i
46a0: 6e 20 61 20 75 33 32 20 77 69 74 68 6f 75 74 20 n a u32 without
46b0: 6c 6f 73 73 20 6f 66 20 64 61 74 61 2e 20 20 54 loss of data. T
46c0: 68 65 20 76 61 6c 75 65 0a 2a 2a 20 69 73 20 30 he value.** is 0
46d0: 78 30 30 30 30 30 30 30 30 66 66 66 66 66 66 66 x00000000fffffff
46e0: 66 2e 20 20 42 75 74 20 62 65 63 61 75 73 65 20 f. But because
46f0: 6f 66 20 71 75 69 72 6b 73 20 6f 66 20 73 6f 6d of quirks of som
4700: 65 20 63 6f 6d 70 69 6c 65 72 73 2c 20 77 65 0a e compilers, we.
4710: 2a 2a 20 68 61 76 65 20 74 6f 20 73 70 65 63 69 ** have to speci
4720: 66 79 20 74 68 65 20 76 61 6c 75 65 20 69 6e 20 fy the value in
4730: 74 68 65 20 6c 65 73 73 20 69 6e 74 75 69 74 69 the less intuiti
4740: 76 65 20 6d 61 6e 6e 65 72 20 73 68 6f 77 6e 3a ve manner shown:
4750: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
4760: 54 45 5f 4d 41 58 5f 55 33 32 20 20 28 28 28 28 TE_MAX_U32 ((((
4770: 75 36 34 29 31 29 3c 3c 33 32 29 2d 31 29 0a 0a u64)1)<<32)-1)..
4780: 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 79 /*.** The dataty
4790: 70 65 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 pe used to store
47a0: 20 65 73 74 69 6d 61 74 65 73 20 6f 66 20 74 68 estimates of th
47b0: 65 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 e number of rows
47c0: 20 69 6e 20 61 0a 2a 2a 20 74 61 62 6c 65 20 6f in a.** table o
47d0: 72 20 69 6e 64 65 78 2e 20 20 54 68 69 73 20 69 r index. This i
47e0: 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 20 69 6e s an unsigned in
47f0: 74 65 67 65 72 20 74 79 70 65 2e 20 20 46 6f 72 teger type. For
4800: 20 39 39 2e 39 25 20 6f 66 0a 2a 2a 20 74 68 65 99.9% of.** the
4810: 20 77 6f 72 6c 64 2c 20 61 20 33 32 2d 62 69 74 world, a 32-bit
4820: 20 69 6e 74 65 67 65 72 20 69 73 20 73 75 66 66 integer is suff
4830: 69 63 69 65 6e 74 2e 20 20 42 75 74 20 61 20 36 icient. But a 6
4840: 34 2d 62 69 74 20 69 6e 74 65 67 65 72 0a 2a 2a 4-bit integer.**
4850: 20 63 61 6e 20 62 65 20 75 73 65 64 20 61 74 20 can be used at
4860: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 69 66 20 compile-time if
4870: 64 65 73 69 72 65 64 2e 0a 2a 2f 0a 23 69 66 64 desired..*/.#ifd
4880: 65 66 20 53 51 4c 49 54 45 5f 36 34 42 49 54 5f ef SQLITE_64BIT_
4890: 53 54 41 54 53 0a 20 74 79 70 65 64 65 66 20 75 STATS. typedef u
48a0: 36 34 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 64 tRowcnt; /
48b0: 2a 20 36 34 2d 62 69 74 20 6f 6e 6c 79 20 69 66 * 64-bit only if
48c0: 20 72 65 71 75 65 73 74 65 64 20 61 74 20 63 6f requested at co
48d0: 6d 70 69 6c 65 2d 74 69 6d 65 20 2a 2f 0a 23 65 mpile-time */.#e
48e0: 6c 73 65 0a 20 74 79 70 65 64 65 66 20 75 33 32 lse. typedef u32
48f0: 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 tRowcnt; /*
4900: 33 32 2d 62 69 74 20 69 73 20 74 68 65 20 64 65 32-bit is the de
4910: 66 61 75 6c 74 20 2a 2f 0a 23 65 6e 64 69 66 0a fault */.#endif.
4920: 0a 2f 2a 0a 2a 2a 20 45 73 74 69 6d 61 74 65 64 ./*.** Estimated
4930: 20 71 75 61 6e 74 69 74 69 65 73 20 75 73 65 64 quantities used
4940: 20 66 6f 72 20 71 75 65 72 79 20 70 6c 61 6e 6e for query plann
4950: 69 6e 67 20 61 72 65 20 73 74 6f 72 65 64 20 61 ing are stored a
4960: 73 20 31 36 2d 62 69 74 0a 2a 2a 20 6c 6f 67 61 s 16-bit.** loga
4970: 72 69 74 68 6d 73 2e 20 20 46 6f 72 20 71 75 61 rithms. For qua
4980: 6e 74 69 74 79 20 58 2c 20 74 68 65 20 76 61 6c ntity X, the val
4990: 75 65 20 73 74 6f 72 65 64 20 69 73 20 31 30 2a ue stored is 10*
49a0: 6c 6f 67 32 28 58 29 2e 20 20 54 68 69 73 0a 2a log2(X). This.*
49b0: 2a 20 67 69 76 65 73 20 61 20 70 6f 73 73 69 62 * gives a possib
49c0: 6c 65 20 72 61 6e 67 65 20 6f 66 20 76 61 6c 75 le range of valu
49d0: 65 73 20 6f 66 20 61 70 70 72 6f 78 69 6d 61 74 es of approximat
49e0: 65 6c 79 20 31 2e 30 65 39 38 36 20 74 6f 20 31 ely 1.0e986 to 1
49f0: 65 2d 39 38 36 2e 0a 2a 2a 20 42 75 74 20 74 68 e-986..** But th
4a00: 65 20 61 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 e allowed values
4a10: 20 61 72 65 20 22 67 72 61 69 6e 79 22 2e 20 20 are "grainy".
4a20: 4e 6f 74 20 65 76 65 72 79 20 76 61 6c 75 65 20 Not every value
4a30: 69 73 20 72 65 70 72 65 73 65 6e 74 61 62 6c 65 is representable
4a40: 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c 65 ..** For example
4a50: 2c 20 71 75 61 6e 74 69 74 69 65 73 20 31 36 20 , quantities 16
4a60: 61 6e 64 20 31 37 20 61 72 65 20 62 6f 74 68 20 and 17 are both
4a70: 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 represented by a
4a80: 20 4c 6f 67 45 73 74 0a 2a 2a 20 6f 66 20 34 30 LogEst.** of 40
4a90: 2e 20 20 48 6f 77 65 76 65 72 2c 20 73 69 6e 63 . However, sinc
4aa0: 65 20 4c 6f 67 45 73 74 20 71 75 61 6e 74 69 74 e LogEst quantit
4ab0: 69 65 73 20 61 72 65 20 73 75 70 70 6f 73 65 20 ies are suppose
4ac0: 74 6f 20 62 65 20 65 73 74 69 6d 61 74 65 73 2c to be estimates,
4ad0: 0a 2a 2a 20 6e 6f 74 20 65 78 61 63 74 20 76 61 .** not exact va
4ae0: 6c 75 65 73 2c 20 74 68 69 73 20 69 6d 70 72 65 lues, this impre
4af0: 63 69 73 69 6f 6e 20 69 73 20 6e 6f 74 20 61 20 cision is not a
4b00: 70 72 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a 2a 20 22 problem..**.** "
4b10: 4c 6f 67 45 73 74 22 20 69 73 20 73 68 6f 72 74 LogEst" is short
4b20: 20 66 6f 72 20 22 4c 6f 67 61 72 69 74 68 6d 69 for "Logarithmi
4b30: 63 20 45 73 74 69 6d 61 74 65 22 2e 0a 2a 2a 0a c Estimate"..**.
4b40: 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 20 ** Examples:.**
4b50: 20 20 20 20 20 31 20 2d 3e 20 30 20 20 20 20 20 1 -> 0
4b60: 20 20 20 20 20 20 20 20 20 32 30 20 2d 3e 20 34 20 -> 4
4b70: 33 20 20 20 20 20 20 20 20 20 20 31 30 30 30 30 3 10000
4b80: 20 2d 3e 20 31 33 32 0a 2a 2a 20 20 20 20 20 20 -> 132.**
4b90: 32 20 2d 3e 20 31 30 20 20 20 20 20 20 20 20 20 2 -> 10
4ba0: 20 20 20 20 32 35 20 2d 3e 20 34 36 20 20 20 20 25 -> 46
4bb0: 20 20 20 20 20 20 32 35 30 30 30 20 2d 3e 20 31 25000 -> 1
4bc0: 34 36 0a 2a 2a 20 20 20 20 20 20 33 20 2d 3e 20 46.** 3 ->
4bd0: 31 36 20 20 20 20 20 20 20 20 20 20 20 20 31 30 16 10
4be0: 30 20 2d 3e 20 36 36 20 20 20 20 20 20 20 20 31 0 -> 66 1
4bf0: 30 30 30 30 30 30 20 2d 3e 20 31 39 39 0a 2a 2a 000000 -> 199.**
4c00: 20 20 20 20 20 20 34 20 2d 3e 20 32 30 20 20 20 4 -> 20
4c10: 20 20 20 20 20 20 20 20 31 30 30 30 20 2d 3e 20 1000 ->
4c20: 39 39 20 20 20 20 20 20 20 20 31 30 34 38 35 37 99 104857
4c30: 36 20 2d 3e 20 32 30 30 0a 2a 2a 20 20 20 20 20 6 -> 200.**
4c40: 31 30 20 2d 3e 20 33 33 20 20 20 20 20 20 20 20 10 -> 33
4c50: 20 20 20 31 30 32 34 20 2d 3e 20 31 30 30 20 20 1024 -> 100
4c60: 20 20 34 32 39 34 39 36 37 32 39 36 20 2d 3e 20 4294967296 ->
4c70: 33 32 30 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 320.**.** The Lo
4c80: 67 45 73 74 20 63 61 6e 20 62 65 20 6e 65 67 61 gEst can be nega
4c90: 74 69 76 65 20 74 6f 20 69 6e 64 69 63 61 74 65 tive to indicate
4ca0: 20 66 72 61 63 74 69 6f 6e 61 6c 20 76 61 6c 75 fractional valu
4cb0: 65 73 2e 20 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 es. .** Examples
4cc0: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 30 2e 35 20 2d :.**.** 0.5 -
4cd0: 3e 20 2d 31 30 20 20 20 20 20 20 20 20 20 20 20 > -10
4ce0: 30 2e 31 20 2d 3e 20 2d 33 33 20 20 20 20 20 20 0.1 -> -33
4cf0: 20 20 30 2e 30 36 32 35 20 2d 3e 20 2d 34 30 0a 0.0625 -> -40.
4d00: 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 36 */.typedef INT16
4d10: 5f 54 59 50 45 20 4c 6f 67 45 73 74 3b 0a 0a 2f _TYPE LogEst;../
4d20: 2a 0a 2a 2a 20 53 65 74 20 74 68 65 20 53 51 4c *.** Set the SQL
4d30: 49 54 45 5f 50 54 52 53 49 5a 45 20 6d 61 63 72 ITE_PTRSIZE macr
4d40: 6f 20 74 6f 20 74 68 65 20 6e 75 6d 62 65 72 20 o to the number
4d50: 6f 66 20 62 79 74 65 73 20 69 6e 20 61 20 70 6f of bytes in a po
4d60: 69 6e 74 65 72 0a 2a 2f 0a 23 69 66 6e 64 65 66 inter.*/.#ifndef
4d70: 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 0a SQLITE_PTRSIZE.
4d80: 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 53 # if defined(__S
4d90: 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f 29 IZEOF_POINTER__)
4da0: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
4db0: 54 45 5f 50 54 52 53 49 5a 45 20 5f 5f 53 49 5a TE_PTRSIZE __SIZ
4dc0: 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f 0a 23 20 EOF_POINTER__.#
4dd0: 65 6c 69 66 20 64 65 66 69 6e 65 64 28 69 33 38 elif defined(i38
4de0: 36 29 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 6) || define
4df0: 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 20 7c 7c d(__i386__) ||
4e00: 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 58 38 36 defined(_M_IX86
4e10: 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 20 ) || \.
4e20: 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 52 4d 29 defined(_M_ARM)
4e30: 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f || defined(__
4e40: 61 72 6d 5f 5f 29 20 20 20 20 7c 7c 20 64 65 66 arm__) || def
4e50: 69 6e 65 64 28 5f 5f 78 38 36 29 0a 23 20 20 20 ined(__x86).#
4e60: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 define SQLITE_PT
4e70: 52 53 49 5a 45 20 34 0a 23 20 65 6c 73 65 0a 23 RSIZE 4.# else.#
4e80: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
4e90: 5f 50 54 52 53 49 5a 45 20 38 0a 23 20 65 6e 64 _PTRSIZE 8.# end
4ea0: 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a if.#endif../*.**
4eb0: 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 74 65 72 Macros to deter
4ec0: 6d 69 6e 65 20 77 68 65 74 68 65 72 20 74 68 65 mine whether the
4ed0: 20 6d 61 63 68 69 6e 65 20 69 73 20 62 69 67 20 machine is big
4ee0: 6f 72 20 6c 69 74 74 6c 65 20 65 6e 64 69 61 6e or little endian
4ef0: 2c 0a 2a 2a 20 61 6e 64 20 77 68 65 74 68 65 72 ,.** and whether
4f00: 20 6f 72 20 6e 6f 74 20 74 68 61 74 20 64 65 74 or not that det
4f10: 65 72 6d 69 6e 61 74 69 6f 6e 20 69 73 20 72 75 ermination is ru
4f20: 6e 2d 74 69 6d 65 20 6f 72 20 63 6f 6d 70 69 6c n-time or compil
4f30: 65 2d 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 46 6f e-time..**.** Fo
4f40: 72 20 62 65 73 74 20 70 65 72 66 6f 72 6d 61 6e r best performan
4f50: 63 65 2c 20 61 6e 20 61 74 74 65 6d 70 74 20 69 ce, an attempt i
4f60: 73 20 6d 61 64 65 20 74 6f 20 67 75 65 73 73 20 s made to guess
4f70: 61 74 20 74 68 65 20 62 79 74 65 2d 6f 72 64 65 at the byte-orde
4f80: 72 0a 2a 2a 20 75 73 69 6e 67 20 43 2d 70 72 65 r.** using C-pre
4f90: 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 processor macros
4fa0: 2e 20 20 49 66 20 74 68 61 74 20 69 73 20 75 6e . If that is un
4fb0: 73 75 63 63 65 73 73 66 75 6c 2c 20 6f 72 20 69 successful, or i
4fc0: 66 0a 2a 2a 20 2d 44 53 51 4c 49 54 45 5f 52 55 f.** -DSQLITE_RU
4fd0: 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 3d NTIME_BYTEORDER=
4fe0: 31 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 62 1 is set, then b
4ff0: 79 74 65 2d 6f 72 64 65 72 20 69 73 20 64 65 74 yte-order is det
5000: 65 72 6d 69 6e 65 64 0a 2a 2a 20 61 74 20 72 75 ermined.** at ru
5010: 6e 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 69 66 64 65 n-time..*/.#ifde
5020: 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d f SQLITE_AMALGAM
5030: 41 54 49 4f 4e 0a 63 6f 6e 73 74 20 69 6e 74 20 ATION.const int
5040: 73 71 6c 69 74 65 33 6f 6e 65 20 3d 20 31 3b 0a sqlite3one = 1;.
5050: 23 65 6c 73 65 0a 65 78 74 65 72 6e 20 63 6f 6e #else.extern con
5060: 73 74 20 69 6e 74 20 73 71 6c 69 74 65 33 6f 6e st int sqlite3on
5070: 65 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 28 64 e;.#endif.#if (d
5080: 65 66 69 6e 65 64 28 69 33 38 36 29 20 20 20 20 efined(i386)
5090: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 69 33 || defined(__i3
50a0: 38 36 5f 5f 29 20 20 20 7c 7c 20 64 65 66 69 6e 86__) || defin
50b0: 65 64 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 20 ed(_M_IX86) ||
50c0: 20 20 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 64 \. defined
50d0: 28 5f 5f 78 38 36 5f 36 34 29 20 7c 7c 20 64 65 (__x86_64) || de
50e0: 66 69 6e 65 64 28 5f 5f 78 38 36 5f 36 34 5f 5f fined(__x86_64__
50f0: 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f ) || defined(_M_
5100: 58 36 34 29 20 20 7c 7c 20 20 20 20 5c 0a 20 20 X64) || \.
5110: 20 20 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 4d defined(_M_AM
5120: 44 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 D64) || defined(
5130: 5f 4d 5f 41 52 4d 29 20 20 20 20 20 7c 7c 20 64 _M_ARM) || d
5140: 65 66 69 6e 65 64 28 5f 5f 78 38 36 29 20 20 20 efined(__x86)
5150: 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 || \. def
5160: 69 6e 65 64 28 5f 5f 61 72 6d 5f 5f 29 29 20 26 ined(__arm__)) &
5170: 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 & !defined(SQLIT
5180: 45 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 E_RUNTIME_BYTEOR
5190: 44 45 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 DER).# define SQ
51a0: 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 LITE_BYTEORDER
51b0: 20 20 31 32 33 34 0a 23 20 64 65 66 69 6e 65 20 1234.# define
51c0: 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e SQLITE_BIGENDIAN
51d0: 20 20 20 20 30 0a 23 20 64 65 66 69 6e 65 20 53 0.# define S
51e0: 51 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 QLITE_LITTLEENDI
51f0: 41 4e 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 AN 1.# define SQ
5200: 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 LITE_UTF16NATIVE
5210: 20 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 SQLITE_UTF16LE
5220: 0a 23 65 6e 64 69 66 0a 23 69 66 20 28 64 65 66 .#endif.#if (def
5230: 69 6e 65 64 28 73 70 61 72 63 29 20 20 20 20 7c ined(sparc) |
5240: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 70 70 63 5f | defined(__ppc_
5250: 5f 29 29 20 20 5c 0a 20 20 20 20 26 26 20 21 64 _)) \. && !d
5260: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 52 55 efined(SQLITE_RU
5270: 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 29 NTIME_BYTEORDER)
5280: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
5290: 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 34 33 _BYTEORDER 43
52a0: 32 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 21.# define SQLI
52b0: 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 TE_BIGENDIAN
52c0: 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 1.# define SQLIT
52d0: 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 30 E_LITTLEENDIAN 0
52e0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
52f0: 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 53 51 _UTF16NATIVE SQ
5300: 4c 49 54 45 5f 55 54 46 31 36 42 45 0a 23 65 6e LITE_UTF16BE.#en
5310: 64 69 66 0a 23 69 66 20 21 64 65 66 69 6e 65 64 dif.#if !defined
5320: 28 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 (SQLITE_BYTEORDE
5330: 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 R).# define SQLI
5340: 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 TE_BYTEORDER
5350: 30 20 20 20 20 20 2f 2a 20 30 20 6d 65 61 6e 73 0 /* 0 means
5360: 20 22 75 6e 6b 6e 6f 77 6e 20 61 74 20 63 6f 6d "unknown at com
5370: 70 69 6c 65 2d 74 69 6d 65 22 20 2a 2f 0a 23 20 pile-time" */.#
5380: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 define SQLITE_BI
5390: 47 45 4e 44 49 41 4e 20 20 20 20 28 2a 28 63 68 GENDIAN (*(ch
53a0: 61 72 20 2a 29 28 26 73 71 6c 69 74 65 33 6f 6e ar *)(&sqlite3on
53b0: 65 29 3d 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 e)==0).# define
53c0: 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 SQLITE_LITTLEEND
53d0: 49 41 4e 20 28 2a 28 63 68 61 72 20 2a 29 28 26 IAN (*(char *)(&
53e0: 73 71 6c 69 74 65 33 6f 6e 65 29 3d 3d 31 29 0a sqlite3one)==1).
53f0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
5400: 55 54 46 31 36 4e 41 54 49 56 45 20 20 28 53 51 UTF16NATIVE (SQ
5410: 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 3f 53 LITE_BIGENDIAN?S
5420: 51 4c 49 54 45 5f 55 54 46 31 36 42 45 3a 53 51 QLITE_UTF16BE:SQ
5430: 4c 49 54 45 5f 55 54 46 31 36 4c 45 29 0a 23 65 LITE_UTF16LE).#e
5440: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6e 73 ndif../*.** Cons
5450: 74 61 6e 74 73 20 66 6f 72 20 74 68 65 20 6c 61 tants for the la
5460: 72 67 65 73 74 20 61 6e 64 20 73 6d 61 6c 6c 65 rgest and smalle
5470: 73 74 20 70 6f 73 73 69 62 6c 65 20 36 34 2d 62 st possible 64-b
5480: 69 74 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 it signed intege
5490: 72 73 2e 0a 2a 2a 20 54 68 65 73 65 20 6d 61 63 rs..** These mac
54a0: 72 6f 73 20 61 72 65 20 64 65 73 69 67 6e 65 64 ros are designed
54b0: 20 74 6f 20 77 6f 72 6b 20 63 6f 72 72 65 63 74 to work correct
54c0: 6c 79 20 6f 6e 20 62 6f 74 68 20 33 32 2d 62 69 ly on both 32-bi
54d0: 74 20 61 6e 64 20 36 34 2d 62 69 74 0a 2a 2a 20 t and 64-bit.**
54e0: 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a 2f 0a 23 64 compilers..*/.#d
54f0: 65 66 69 6e 65 20 4c 41 52 47 45 53 54 5f 49 4e efine LARGEST_IN
5500: 54 36 34 20 20 28 30 78 66 66 66 66 66 66 66 66 T64 (0xffffffff
5510: 7c 28 28 28 69 36 34 29 30 78 37 66 66 66 66 66 |(((i64)0x7fffff
5520: 66 66 29 3c 3c 33 32 29 29 0a 23 64 65 66 69 6e ff)<<32)).#defin
5530: 65 20 53 4d 41 4c 4c 45 53 54 5f 49 4e 54 36 34 e SMALLEST_INT64
5540: 20 28 28 28 69 36 34 29 2d 31 29 20 2d 20 4c 41 (((i64)-1) - LA
5550: 52 47 45 53 54 5f 49 4e 54 36 34 29 0a 0a 2f 2a RGEST_INT64)../*
5560: 20 0a 2a 2a 20 52 6f 75 6e 64 20 75 70 20 61 20 .** Round up a
5570: 6e 75 6d 62 65 72 20 74 6f 20 74 68 65 20 6e 65 number to the ne
5580: 78 74 20 6c 61 72 67 65 72 20 6d 75 6c 74 69 70 xt larger multip
5590: 6c 65 20 6f 66 20 38 2e 20 20 54 68 69 73 20 69 le of 8. This i
55a0: 73 20 75 73 65 64 0a 2a 2a 20 74 6f 20 66 6f 72 s used.** to for
55b0: 63 65 20 38 2d 62 79 74 65 20 61 6c 69 67 6e 6d ce 8-byte alignm
55c0: 65 6e 74 20 6f 6e 20 36 34 2d 62 69 74 20 61 72 ent on 64-bit ar
55d0: 63 68 69 74 65 63 74 75 72 65 73 2e 0a 2a 2f 0a chitectures..*/.
55e0: 23 64 65 66 69 6e 65 20 52 4f 55 4e 44 38 28 78 #define ROUND8(x
55f0: 29 20 20 20 20 20 28 28 28 78 29 2b 37 29 26 7e ) (((x)+7)&~
5600: 37 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e 64 20 7)../*.** Round
5610: 64 6f 77 6e 20 74 6f 20 74 68 65 20 6e 65 61 72 down to the near
5620: 65 73 74 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 est multiple of
5630: 38 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 8.*/.#define ROU
5640: 4e 44 44 4f 57 4e 38 28 78 29 20 28 28 78 29 26 NDDOWN8(x) ((x)&
5650: 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 65 72 ~7)../*.** Asser
5660: 74 20 74 68 61 74 20 74 68 65 20 70 6f 69 6e 74 t that the point
5670: 65 72 20 58 20 69 73 20 61 6c 69 67 6e 65 64 20 er X is aligned
5680: 74 6f 20 61 6e 20 38 2d 62 79 74 65 20 62 6f 75 to an 8-byte bou
5690: 6e 64 61 72 79 2e 20 20 54 68 69 73 0a 2a 2a 20 ndary. This.**
56a0: 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 6f 6e macro is used on
56b0: 6c 79 20 77 69 74 68 69 6e 20 61 73 73 65 72 74 ly within assert
56c0: 28 29 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 () to verify tha
56d0: 74 20 74 68 65 20 63 6f 64 65 20 67 65 74 73 0a t the code gets.
56e0: 2a 2a 20 61 6c 6c 20 61 6c 69 67 6e 6d 65 6e 74 ** all alignment
56f0: 20 72 65 73 74 72 69 63 74 69 6f 6e 73 20 63 6f restrictions co
5700: 72 72 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 45 78 63 rrect..**.** Exc
5710: 65 70 74 2c 20 69 66 20 53 51 4c 49 54 45 5f 34 ept, if SQLITE_4
5720: 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 _BYTE_ALIGNED_MA
5730: 4c 4c 4f 43 20 69 73 20 64 65 66 69 6e 65 64 2c LLOC is defined,
5740: 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 75 6e 64 then the.** und
5750: 65 72 6c 79 69 6e 67 20 6d 61 6c 6c 6f 63 28 29 erlying malloc()
5760: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
5770: 6d 69 67 68 74 20 72 65 74 75 72 6e 20 75 73 20 might return us
5780: 34 2d 62 79 74 65 20 61 6c 69 67 6e 65 64 0a 2a 4-byte aligned.*
5790: 2a 20 70 6f 69 6e 74 65 72 73 2e 20 20 49 6e 20 * pointers. In
57a0: 74 68 61 74 20 63 61 73 65 2c 20 6f 6e 6c 79 20 that case, only
57b0: 76 65 72 69 66 79 20 34 2d 62 79 74 65 20 61 6c verify 4-byte al
57c0: 69 67 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 69 66 64 ignment..*/.#ifd
57d0: 65 66 20 53 51 4c 49 54 45 5f 34 5f 42 59 54 45 ef SQLITE_4_BYTE
57e0: 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c 4f 43 0a _ALIGNED_MALLOC.
57f0: 23 20 64 65 66 69 6e 65 20 45 49 47 48 54 5f 42 # define EIGHT_B
5800: 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 58 29 YTE_ALIGNMENT(X)
5810: 20 20 20 28 28 28 28 63 68 61 72 2a 29 28 58 29 ((((char*)(X)
5820: 20 2d 20 28 63 68 61 72 2a 29 30 29 26 33 29 3d - (char*)0)&3)=
5830: 3d 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 =0).#else.# defi
5840: 6e 65 20 45 49 47 48 54 5f 42 59 54 45 5f 41 4c ne EIGHT_BYTE_AL
5850: 49 47 4e 4d 45 4e 54 28 58 29 20 20 20 28 28 28 IGNMENT(X) (((
5860: 28 63 68 61 72 2a 29 28 58 29 20 2d 20 28 63 68 (char*)(X) - (ch
5870: 61 72 2a 29 30 29 26 37 29 3d 3d 30 29 0a 23 65 ar*)0)&7)==0).#e
5880: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 69 73 61 ndif../*.** Disa
5890: 62 6c 65 20 4d 4d 41 50 20 6f 6e 20 70 6c 61 74 ble MMAP on plat
58a0: 66 6f 72 6d 73 20 77 68 65 72 65 20 69 74 20 69 forms where it i
58b0: 73 20 6b 6e 6f 77 6e 20 74 6f 20 6e 6f 74 20 77 s known to not w
58c0: 6f 72 6b 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e ork.*/.#if defin
58d0: 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f 5f 29 20 ed(__OpenBSD__)
58e0: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 51 4e 58 || defined(__QNX
58f0: 4e 54 4f 5f 5f 29 0a 23 20 75 6e 64 65 66 20 53 NTO__).# undef S
5900: 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 QLITE_MAX_MMAP_S
5910: 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c IZE.# define SQL
5920: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5930: 45 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a E 0.#endif../*.*
5940: 2a 20 44 65 66 61 75 6c 74 20 6d 61 78 69 6d 75 * Default maximu
5950: 6d 20 73 69 7a 65 20 6f 66 20 6d 65 6d 6f 72 79 m size of memory
5960: 20 75 73 65 64 20 62 79 20 6d 65 6d 6f 72 79 2d used by memory-
5970: 6d 61 70 70 65 64 20 49 2f 4f 20 69 6e 20 74 68 mapped I/O in th
5980: 65 20 56 46 53 0a 2a 2f 0a 23 69 66 64 65 66 20 e VFS.*/.#ifdef
5990: 5f 5f 41 50 50 4c 45 5f 5f 0a 23 20 69 6e 63 6c __APPLE__.# incl
59a0: 75 64 65 20 3c 54 61 72 67 65 74 43 6f 6e 64 69 ude <TargetCondi
59b0: 74 69 6f 6e 61 6c 73 2e 68 3e 0a 23 20 69 66 20 tionals.h>.# if
59c0: 54 41 52 47 45 54 5f 4f 53 5f 49 50 48 4f 4e 45 TARGET_OS_IPHONE
59d0: 0a 23 20 20 20 75 6e 64 65 66 20 53 51 4c 49 54 .# undef SQLIT
59e0: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a E_MAX_MMAP_SIZE.
59f0: 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 # define SQLIT
5a00: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 20 E_MAX_MMAP_SIZE
5a10: 30 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0.# endif.#endif
5a20: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
5a30: 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 MAX_MMAP_SIZE.#
5a40: 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 6c 69 6e if defined(__lin
5a50: 75 78 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 66 ux__) \. || def
5a60: 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 5c 0a 20 ined(_WIN32) \.
5a70: 20 7c 7c 20 28 64 65 66 69 6e 65 64 28 5f 5f 41 || (defined(__A
5a80: 50 50 4c 45 5f 5f 29 20 26 26 20 64 65 66 69 6e PPLE__) && defin
5a90: 65 64 28 5f 5f 4d 41 43 48 5f 5f 29 29 20 5c 0a ed(__MACH__)) \.
5aa0: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 73 || defined(__s
5ab0: 75 6e 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 un).# define S
5ac0: 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 QLITE_MAX_MMAP_S
5ad0: 49 5a 45 20 30 78 37 66 66 66 30 30 30 30 20 20 IZE 0x7fff0000
5ae0: 2f 2a 20 32 31 34 37 34 31 38 31 31 32 20 2a 2f /* 2147418112 */
5af0: 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 .# else.# defi
5b00: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ne SQLITE_MAX_MM
5b10: 41 50 5f 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 AP_SIZE 0.# endi
5b20: 66 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 f.# define SQLIT
5b30: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 5f E_MAX_MMAP_SIZE_
5b40: 78 63 20 31 20 2f 2a 20 65 78 63 6c 75 64 65 20 xc 1 /* exclude
5b50: 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a from ctime.c */.
5b60: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 #endif../*.** Th
5b70: 65 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 5f 53 e default MMAP_S
5b80: 49 5a 45 20 69 73 20 7a 65 72 6f 20 6f 6e 20 61 IZE is zero on a
5b90: 6c 6c 20 70 6c 61 74 66 6f 72 6d 73 2e 20 20 4f ll platforms. O
5ba0: 72 2c 20 65 76 65 6e 20 69 66 20 61 20 6c 61 72 r, even if a lar
5bb0: 67 65 72 0a 2a 2a 20 64 65 66 61 75 6c 74 20 4d ger.** default M
5bc0: 4d 41 50 5f 53 49 5a 45 20 69 73 20 73 70 65 63 MAP_SIZE is spec
5bd0: 69 66 69 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 ified at compile
5be0: 2d 74 69 6d 65 2c 20 6d 61 6b 65 20 73 75 72 65 -time, make sure
5bf0: 20 74 68 61 74 20 69 74 20 64 6f 65 73 0a 2a 2a that it does.**
5c00: 20 6e 6f 74 20 65 78 63 65 65 64 20 74 68 65 20 not exceed the
5c10: 6d 61 78 69 6d 75 6d 20 6d 6d 61 70 20 73 69 7a maximum mmap siz
5c20: 65 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 e..*/.#ifndef SQ
5c30: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 LITE_DEFAULT_MMA
5c40: 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 P_SIZE.# define
5c50: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
5c60: 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 64 65 66 MAP_SIZE 0.# def
5c70: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
5c80: 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 20 LT_MMAP_SIZE_xc
5c90: 31 20 20 2f 2a 20 45 78 63 6c 75 64 65 20 66 72 1 /* Exclude fr
5ca0: 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 om ctime.c */.#e
5cb0: 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 45 5f ndif.#if SQLITE_
5cc0: 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a DEFAULT_MMAP_SIZ
5cd0: 45 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 E>SQLITE_MAX_MMA
5ce0: 50 5f 53 49 5a 45 0a 23 20 75 6e 64 65 66 20 53 P_SIZE.# undef S
5cf0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d QLITE_DEFAULT_MM
5d00: 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 AP_SIZE.# define
5d10: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
5d20: 4d 4d 41 50 5f 53 49 5a 45 20 53 51 4c 49 54 45 MMAP_SIZE SQLITE
5d30: 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 _MAX_MMAP_SIZE.#
5d40: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 6c endif../*.** Onl
5d50: 79 20 6f 6e 65 20 6f 66 20 53 51 4c 49 54 45 5f y one of SQLITE_
5d60: 45 4e 41 42 4c 45 5f 53 54 41 54 33 20 6f 72 20 ENABLE_STAT3 or
5d70: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
5d80: 41 54 34 20 63 61 6e 20 62 65 20 64 65 66 69 6e AT4 can be defin
5d90: 65 64 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 79 20 ed..** Priority
5da0: 69 73 20 67 69 76 65 6e 20 74 6f 20 53 51 4c 49 is given to SQLI
5db0: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 2e TE_ENABLE_STAT4.
5dc0: 20 20 49 66 20 65 69 74 68 65 72 20 61 72 65 20 If either are
5dd0: 64 65 66 69 6e 65 64 2c 20 61 6c 73 6f 0a 2a 2a defined, also.**
5de0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 define SQLITE_E
5df0: 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
5e00: 54 41 54 34 0a 2a 2f 0a 23 69 66 64 65 66 20 53 TAT4.*/.#ifdef S
5e10: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 QLITE_ENABLE_STA
5e20: 54 34 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 T4.# undef SQLIT
5e30: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 E_ENABLE_STAT3.#
5e40: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 define SQLITE_E
5e50: 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
5e60: 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c TAT4 1.#elif SQL
5e70: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
5e80: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
5e90: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
5ea0: 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 _STAT4 1.#elif S
5eb0: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 QLITE_ENABLE_STA
5ec0: 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 20 75 6e T3_OR_STAT4.# un
5ed0: 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c def SQLITE_ENABL
5ee0: 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 E_STAT3_OR_STAT4
5ef0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 .#endif../*.** S
5f00: 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c ELECTTRACE_ENABL
5f10: 45 44 20 77 69 6c 6c 20 62 65 20 65 69 74 68 65 ED will be eithe
5f20: 72 20 31 20 6f 72 20 30 20 64 65 70 65 6e 64 69 r 1 or 0 dependi
5f30: 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 20 6f 72 ng on whether or
5f40: 20 6e 6f 74 0a 2a 2a 20 74 68 65 20 53 65 6c 65 not.** the Sele
5f50: 63 74 20 71 75 65 72 79 20 67 65 6e 65 72 61 74 ct query generat
5f60: 6f 72 20 74 72 61 63 69 6e 67 20 6c 6f 67 69 63 or tracing logic
5f70: 20 69 73 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a is turned on..*
5f80: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 /.#if defined(SQ
5f90: 4c 49 54 45 5f 44 45 42 55 47 29 20 7c 7c 20 64 LITE_DEBUG) || d
5fa0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e efined(SQLITE_EN
5fb0: 41 42 4c 45 5f 53 45 4c 45 43 54 54 52 41 43 45 ABLE_SELECTTRACE
5fc0: 29 0a 23 20 64 65 66 69 6e 65 20 53 45 4c 45 43 ).# define SELEC
5fd0: 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 31 TTRACE_ENABLED 1
5fe0: 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
5ff0: 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
6000: 4c 45 44 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a LED 0.#endif../*
6010: 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
6020: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
6030: 20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 73 structure is us
6040: 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 ed to store the
6050: 62 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 busy-handler.**
6060: 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 61 20 67 callback for a g
6070: 69 76 65 6e 20 73 71 6c 69 74 65 20 68 61 6e 64 iven sqlite hand
6080: 6c 65 2e 20 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 le. .**.** The s
6090: 71 6c 69 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 qlite.busyHandle
60a0: 72 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 20 r member of the
60b0: 73 71 6c 69 74 65 20 73 74 72 75 63 74 20 63 6f sqlite struct co
60c0: 6e 74 61 69 6e 73 20 74 68 65 20 62 75 73 79 0a ntains the busy.
60d0: 2a 2a 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 ** callback for
60e0: 74 68 65 20 64 61 74 61 62 61 73 65 20 68 61 6e the database han
60f0: 64 6c 65 2e 20 45 61 63 68 20 70 61 67 65 72 20 dle. Each pager
6100: 6f 70 65 6e 65 64 20 76 69 61 20 74 68 65 20 73 opened via the s
6110: 71 6c 69 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 qlite.** handle
6120: 69 73 20 70 61 73 73 65 64 20 61 20 70 6f 69 6e is passed a poin
6130: 74 65 72 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 ter to sqlite.bu
6140: 73 79 48 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 syHandler. The b
6150: 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 usy-handler.** c
6160: 61 6c 6c 62 61 63 6b 20 69 73 20 63 75 72 72 65 allback is curre
6170: 6e 74 6c 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c ntly invoked onl
6180: 79 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 y from within pa
6190: 67 65 72 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 ger.c..*/.typede
61a0: 66 20 73 74 72 75 63 74 20 42 75 73 79 48 61 6e f struct BusyHan
61b0: 64 6c 65 72 20 42 75 73 79 48 61 6e 64 6c 65 72 dler BusyHandler
61c0: 3b 0a 73 74 72 75 63 74 20 42 75 73 79 48 61 6e ;.struct BusyHan
61d0: 64 6c 65 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 dler {. int (*x
61e0: 46 75 6e 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 Func)(void *,int
61f0: 29 3b 20 20 2f 2a 20 54 68 65 20 62 75 73 79 20 ); /* The busy
6200: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f callback */. vo
6210: 69 64 20 2a 70 41 72 67 3b 20 20 20 20 20 20 20 id *pArg;
6220: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
6230: 74 20 61 72 67 20 74 6f 20 62 75 73 79 20 63 61 t arg to busy ca
6240: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 llback */. int
6250: 6e 42 75 73 79 3b 20 20 20 20 20 20 20 20 20 20 nBusy;
6260: 20 20 20 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d /* Increm
6270: 65 6e 74 65 64 20 77 69 74 68 20 65 61 63 68 20 ented with each
6280: 62 75 73 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a busy call */.};.
6290: 0a 2f 2a 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 ./*.** Name of t
62a0: 68 65 20 6d 61 73 74 65 72 20 64 61 74 61 62 61 he master databa
62b0: 73 65 20 74 61 62 6c 65 2e 20 20 54 68 65 20 6d se table. The m
62c0: 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 74 aster database t
62d0: 61 62 6c 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 able.** is a spe
62e0: 63 69 61 6c 20 74 61 62 6c 65 20 74 68 61 74 20 cial table that
62f0: 68 6f 6c 64 73 20 74 68 65 20 6e 61 6d 65 73 20 holds the names
6300: 61 6e 64 20 61 74 74 72 69 62 75 74 65 73 20 6f and attributes o
6310: 66 20 61 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 f all.** user ta
6320: 62 6c 65 73 20 61 6e 64 20 69 6e 64 69 63 65 73 bles and indices
6330: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 ..*/.#define MAS
6340: 54 45 52 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 TER_NAME "
6350: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 sqlite_master".#
6360: 64 65 66 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 define TEMP_MAST
6370: 45 52 5f 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 ER_NAME "sqlite
6380: 5f 74 65 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f _temp_master"../
6390: 2a 0a 2a 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 *.** The root-pa
63a0: 67 65 20 6f 66 20 74 68 65 20 6d 61 73 74 65 72 ge of the master
63b0: 20 64 61 74 61 62 61 73 65 20 74 61 62 6c 65 2e database table.
63c0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 .*/.#define MAST
63d0: 45 52 5f 52 4f 4f 54 20 20 20 20 20 20 20 31 0a ER_ROOT 1.
63e0: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 ./*.** The name
63f0: 6f 66 20 74 68 65 20 73 63 68 65 6d 61 20 74 61 of the schema ta
6400: 62 6c 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ble..*/.#define
6410: 53 43 48 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 SCHEMA_TABLE(x)
6420: 20 28 28 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 ((!OMIT_TEMPDB)
6430: 26 26 28 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 &&(x==1)?TEMP_MA
6440: 53 54 45 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 STER_NAME:MASTER
6450: 5f 4e 41 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 _NAME)../*.** A
6460: 63 6f 6e 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 convenience macr
6470: 6f 20 74 68 61 74 20 72 65 74 75 72 6e 73 20 74 o that returns t
6480: 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 he number of ele
6490: 6d 65 6e 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 ments in.** an a
64a0: 72 72 61 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 rray..*/.#define
64b0: 20 41 72 72 61 79 53 69 7a 65 28 58 29 20 20 20 ArraySize(X)
64c0: 20 28 28 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 ((int)(sizeof(X
64d0: 29 2f 73 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 )/sizeof(X[0])))
64e0: 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e ../*.** Determin
64f0: 65 20 69 66 20 74 68 65 20 61 72 67 75 6d 65 6e e if the argumen
6500: 74 20 69 73 20 61 20 70 6f 77 65 72 20 6f 66 20 t is a power of
6510: 74 77 6f 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 two.*/.#define I
6520: 73 50 6f 77 65 72 4f 66 54 77 6f 28 58 29 20 28 sPowerOfTwo(X) (
6530: 28 28 58 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 ((X)&((X)-1))==0
6540: 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c )../*.** The fol
6550: 6c 6f 77 69 6e 67 20 76 61 6c 75 65 20 61 73 20 lowing value as
6560: 61 20 64 65 73 74 72 75 63 74 6f 72 20 6d 65 61 a destructor mea
6570: 6e 73 20 74 6f 20 75 73 65 20 73 71 6c 69 74 65 ns to use sqlite
6580: 33 44 62 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 3DbFree()..** Th
6590: 65 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 e sqlite3DbFree(
65a0: 29 20 72 6f 75 74 69 6e 65 20 72 65 71 75 69 72 ) routine requir
65b0: 65 73 20 74 77 6f 20 70 61 72 61 6d 65 74 65 72 es two parameter
65c0: 73 20 69 6e 73 74 65 61 64 20 6f 66 20 74 68 65 s instead of the
65d0: 20 0a 2a 2a 20 6f 6e 65 20 70 61 72 61 6d 65 74 .** one paramet
65e0: 65 72 20 74 68 61 74 20 64 65 73 74 72 75 63 74 er that destruct
65f0: 6f 72 73 20 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e ors normally wan
6600: 74 2e 20 20 53 6f 20 77 65 20 68 61 76 65 20 74 t. So we have t
6610: 6f 20 69 6e 74 72 6f 64 75 63 65 20 0a 2a 2a 20 o introduce .**
6620: 74 68 69 73 20 6d 61 67 69 63 20 76 61 6c 75 65 this magic value
6630: 20 74 68 61 74 20 74 68 65 20 63 6f 64 65 20 6b that the code k
6640: 6e 6f 77 73 20 74 6f 20 68 61 6e 64 6c 65 20 64 nows to handle d
6650: 69 66 66 65 72 65 6e 74 6c 79 2e 20 20 41 6e 79 ifferently. Any
6660: 20 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 77 69 6c .** pointer wil
6670: 6c 20 77 6f 72 6b 20 68 65 72 65 20 61 73 20 6c l work here as l
6680: 6f 6e 67 20 61 73 20 69 74 20 69 73 20 64 69 73 ong as it is dis
6690: 74 69 6e 63 74 20 66 72 6f 6d 20 53 51 4c 49 54 tinct from SQLIT
66a0: 45 5f 53 54 41 54 49 43 0a 2a 2a 20 61 6e 64 20 E_STATIC.** and
66b0: 53 51 4c 49 54 45 5f 54 52 41 4e 53 49 45 4e 54 SQLITE_TRANSIENT
66c0: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
66d0: 49 54 45 5f 44 59 4e 41 4d 49 43 20 20 20 28 28 ITE_DYNAMIC ((
66e0: 73 71 6c 69 74 65 33 5f 64 65 73 74 72 75 63 74 sqlite3_destruct
66f0: 6f 72 5f 74 79 70 65 29 73 71 6c 69 74 65 33 4d or_type)sqlite3M
6700: 61 6c 6c 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a 2a allocSize)../*.*
6710: 2a 20 57 68 65 6e 20 53 51 4c 49 54 45 5f 4f 4d * When SQLITE_OM
6720: 49 54 5f 57 53 44 20 69 73 20 64 65 66 69 6e 65 IT_WSD is define
6730: 64 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 61 74 d, it means that
6740: 20 74 68 65 20 74 61 72 67 65 74 20 70 6c 61 74 the target plat
6750: 66 6f 72 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 form does.** not
6760: 20 73 75 70 70 6f 72 74 20 57 72 69 74 61 62 6c support Writabl
6770: 65 20 53 74 61 74 69 63 20 44 61 74 61 20 28 57 e Static Data (W
6780: 53 44 29 20 73 75 63 68 20 61 73 20 67 6c 6f 62 SD) such as glob
6790: 61 6c 20 61 6e 64 20 73 74 61 74 69 63 20 76 61 al and static va
67a0: 72 69 61 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c 20 riables..** All
67b0: 76 61 72 69 61 62 6c 65 73 20 6d 75 73 74 20 65 variables must e
67c0: 69 74 68 65 72 20 62 65 20 6f 6e 20 74 68 65 20 ither be on the
67d0: 73 74 61 63 6b 20 6f 72 20 64 79 6e 61 6d 69 63 stack or dynamic
67e0: 61 6c 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 66 ally allocated f
67f0: 72 6f 6d 0a 2a 2a 20 74 68 65 20 68 65 61 70 2e rom.** the heap.
6800: 20 20 57 68 65 6e 20 57 53 44 20 69 73 20 75 6e When WSD is un
6810: 73 75 70 70 6f 72 74 65 64 2c 20 74 68 65 20 76 supported, the v
6820: 61 72 69 61 62 6c 65 20 64 65 63 6c 61 72 61 74 ariable declarat
6830: 69 6f 6e 73 20 73 63 61 74 74 65 72 65 64 0a 2a ions scattered.*
6840: 2a 20 74 68 72 6f 75 67 68 6f 75 74 20 74 68 65 * throughout the
6850: 20 53 51 4c 69 74 65 20 63 6f 64 65 20 6d 75 73 SQLite code mus
6860: 74 20 62 65 63 6f 6d 65 20 63 6f 6e 73 74 61 6e t become constan
6870: 74 73 20 69 6e 73 74 65 61 64 2e 20 20 54 68 65 ts instead. The
6880: 20 53 51 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 6d SQLITE_WSD.** m
6890: 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 6f 72 acro is used for
68a0: 20 74 68 69 73 20 70 75 72 70 6f 73 65 2e 20 20 this purpose.
68b0: 41 6e 64 20 69 6e 73 74 65 61 64 20 6f 66 20 72 And instead of r
68c0: 65 66 65 72 65 6e 63 69 6e 67 20 74 68 65 20 76 eferencing the v
68d0: 61 72 69 61 62 6c 65 0a 2a 2a 20 64 69 72 65 63 ariable.** direc
68e0: 74 6c 79 2c 20 77 65 20 75 73 65 20 69 74 73 20 tly, we use its
68f0: 63 6f 6e 73 74 61 6e 74 20 61 73 20 61 20 6b 65 constant as a ke
6900: 79 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 y to lookup the
6910: 72 75 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 74 run-time allocat
6920: 65 64 0a 2a 2a 20 62 75 66 66 65 72 20 74 68 61 ed.** buffer tha
6930: 74 20 68 6f 6c 64 73 20 72 65 61 6c 20 76 61 72 t holds real var
6940: 69 61 62 6c 65 2e 20 20 54 68 65 20 63 6f 6e 73 iable. The cons
6950: 74 61 6e 74 20 69 73 20 61 6c 73 6f 20 74 68 65 tant is also the
6960: 20 69 6e 69 74 69 61 6c 69 7a 65 72 0a 2a 2a 20 initializer.**
6970: 66 6f 72 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 for the run-time
6980: 20 61 6c 6c 6f 63 61 74 65 64 20 62 75 66 66 65 allocated buffe
6990: 72 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 r..**.** In the
69a0: 75 73 75 61 6c 20 63 61 73 65 20 77 68 65 72 65 usual case where
69b0: 20 57 53 44 20 69 73 20 73 75 70 70 6f 72 74 65 WSD is supporte
69c0: 64 2c 20 74 68 65 20 53 51 4c 49 54 45 5f 57 53 d, the SQLITE_WS
69d0: 44 20 61 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a 20 D and GLOBAL.**
69e0: 6d 61 63 72 6f 73 20 62 65 63 6f 6d 65 20 6e 6f macros become no
69f0: 2d 6f 70 73 20 61 6e 64 20 68 61 76 65 20 7a 65 -ops and have ze
6a00: 72 6f 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 ro performance i
6a10: 6d 70 61 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 mpact..*/.#ifdef
6a20: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 SQLITE_OMIT_WSD
6a30: 0a 20 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 . #define SQLIT
6a40: 45 5f 57 53 44 20 63 6f 6e 73 74 0a 20 20 23 64 E_WSD const. #d
6a50: 65 66 69 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 efine GLOBAL(t,v
6a60: 29 20 28 2a 28 74 2a 29 73 71 6c 69 74 65 33 5f ) (*(t*)sqlite3_
6a70: 77 73 64 5f 66 69 6e 64 28 28 76 6f 69 64 2a 29 wsd_find((void*)
6a80: 26 28 76 29 2c 20 73 69 7a 65 6f 66 28 76 29 29 &(v), sizeof(v))
6a90: 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 ). #define sqli
6aa0: 74 65 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 te3GlobalConfig
6ab0: 47 4c 4f 42 41 4c 28 73 74 72 75 63 74 20 53 71 GLOBAL(struct Sq
6ac0: 6c 69 74 65 33 43 6f 6e 66 69 67 2c 20 73 71 6c lite3Config, sql
6ad0: 69 74 65 33 43 6f 6e 66 69 67 29 0a 20 20 69 6e ite3Config). in
6ae0: 74 20 73 71 6c 69 74 65 33 5f 77 73 64 5f 69 6e t sqlite3_wsd_in
6af0: 69 74 28 69 6e 74 20 4e 2c 20 69 6e 74 20 4a 29 it(int N, int J)
6b00: 3b 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 ;. void *sqlite
6b10: 33 5f 77 73 64 5f 66 69 6e 64 28 76 6f 69 64 20 3_wsd_find(void
6b20: 2a 4b 2c 20 69 6e 74 20 4c 29 3b 0a 23 65 6c 73 *K, int L);.#els
6b30: 65 0a 20 20 23 64 65 66 69 6e 65 20 53 51 4c 49 e. #define SQLI
6b40: 54 45 5f 57 53 44 20 0a 20 20 23 64 65 66 69 6e TE_WSD . #defin
6b50: 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 76 0a e GLOBAL(t,v) v.
6b60: 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
6b70: 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 73 71 3GlobalConfig sq
6b80: 6c 69 74 65 33 43 6f 6e 66 69 67 0a 23 65 6e 64 lite3Config.#end
6b90: 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f if../*.** The fo
6ba0: 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 llowing macros a
6bb0: 72 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 re used to suppr
6bc0: 65 73 73 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 ess compiler war
6bd0: 6e 69 6e 67 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 nings and to.**
6be0: 6d 61 6b 65 20 69 74 20 63 6c 65 61 72 20 74 6f make it clear to
6bf0: 20 68 75 6d 61 6e 20 72 65 61 64 65 72 73 20 77 human readers w
6c00: 68 65 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 hen a function p
6c10: 61 72 61 6d 65 74 65 72 20 69 73 20 64 65 6c 69 arameter is deli
6c20: 62 65 72 61 74 65 6c 79 20 0a 2a 2a 20 6c 65 66 berately .** lef
6c30: 74 20 75 6e 75 73 65 64 20 77 69 74 68 69 6e 20 t unused within
6c40: 74 68 65 20 62 6f 64 79 20 6f 66 20 61 20 66 75 the body of a fu
6c50: 6e 63 74 69 6f 6e 2e 20 54 68 69 73 20 75 73 75 nction. This usu
6c60: 61 6c 6c 79 20 68 61 70 70 65 6e 73 20 77 68 65 ally happens whe
6c70: 6e 0a 2a 2a 20 61 20 66 75 6e 63 74 69 6f 6e 20 n.** a function
6c80: 69 73 20 63 61 6c 6c 65 64 20 76 69 61 20 61 20 is called via a
6c90: 66 75 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 function pointer
6ca0: 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 . For example th
6cb0: 65 20 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 e .** implementa
6cc0: 74 69 6f 6e 20 6f 66 20 61 6e 20 53 51 4c 20 61 tion of an SQL a
6cd0: 67 67 72 65 67 61 74 65 20 73 74 65 70 20 63 61 ggregate step ca
6ce0: 6c 6c 62 61 63 6b 20 6d 61 79 20 6e 6f 74 20 75 llback may not u
6cf0: 73 65 20 74 68 65 0a 2a 2a 20 70 61 72 61 6d 65 se the.** parame
6d00: 74 65 72 20 69 6e 64 69 63 61 74 69 6e 67 20 74 ter indicating t
6d10: 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 he number of arg
6d20: 75 6d 65 6e 74 73 20 70 61 73 73 65 64 20 74 6f uments passed to
6d30: 20 74 68 65 20 61 67 67 72 65 67 61 74 65 2c 0a the aggregate,.
6d40: 2a 2a 20 69 66 20 69 74 20 6b 6e 6f 77 73 20 74 ** if it knows t
6d50: 68 61 74 20 74 68 69 73 20 69 73 20 65 6e 66 6f hat this is enfo
6d60: 72 63 65 64 20 65 6c 73 65 77 68 65 72 65 2e 0a rced elsewhere..
6d70: 2a 2a 0a 2a 2a 20 57 68 65 6e 20 61 20 66 75 6e **.** When a fun
6d80: 63 74 69 6f 6e 20 70 61 72 61 6d 65 74 65 72 20 ction parameter
6d90: 69 73 20 6e 6f 74 20 75 73 65 64 20 61 74 20 61 is not used at a
6da0: 6c 6c 20 77 69 74 68 69 6e 20 74 68 65 20 62 6f ll within the bo
6db0: 64 79 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e dy of a function
6dc0: 2c 0a 2a 2a 20 69 74 20 69 73 20 67 65 6e 65 72 ,.** it is gener
6dd0: 61 6c 6c 79 20 6e 61 6d 65 64 20 22 4e 6f 74 55 ally named "NotU
6de0: 73 65 64 22 20 6f 72 20 22 4e 6f 74 55 73 65 64 sed" or "NotUsed
6df0: 32 22 20 74 6f 20 6d 61 6b 65 20 74 68 69 6e 67 2" to make thing
6e00: 73 20 65 76 65 6e 20 63 6c 65 61 72 65 72 2e 0a s even clearer..
6e10: 2a 2a 20 48 6f 77 65 76 65 72 2c 20 74 68 65 73 ** However, thes
6e20: 65 20 6d 61 63 72 6f 73 20 6d 61 79 20 61 6c 73 e macros may als
6e30: 6f 20 62 65 20 75 73 65 64 20 74 6f 20 73 75 70 o be used to sup
6e40: 70 72 65 73 73 20 77 61 72 6e 69 6e 67 73 20 72 press warnings r
6e50: 65 6c 61 74 65 64 20 74 6f 0a 2a 2a 20 70 61 72 elated to.** par
6e60: 61 6d 65 74 65 72 73 20 74 68 61 74 20 6d 61 79 ameters that may
6e70: 20 6f 72 20 6d 61 79 20 6e 6f 74 20 62 65 20 75 or may not be u
6e80: 73 65 64 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e sed depending on
6e90: 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 6f 70 74 compilation opt
6ea0: 69 6f 6e 73 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 ions..** For exa
6eb0: 6d 70 6c 65 20 74 68 6f 73 65 20 70 61 72 61 6d mple those param
6ec0: 65 74 65 72 73 20 6f 6e 6c 79 20 75 73 65 64 20 eters only used
6ed0: 69 6e 20 61 73 73 65 72 74 28 29 20 73 74 61 74 in assert() stat
6ee0: 65 6d 65 6e 74 73 2e 20 49 6e 20 74 68 65 73 65 ements. In these
6ef0: 0a 2a 2a 20 63 61 73 65 73 20 74 68 65 20 70 61 .** cases the pa
6f00: 72 61 6d 65 74 65 72 73 20 61 72 65 20 6e 61 6d rameters are nam
6f10: 65 64 20 61 73 20 70 65 72 20 74 68 65 20 75 73 ed as per the us
6f20: 75 61 6c 20 63 6f 6e 76 65 6e 74 69 6f 6e 73 2e ual conventions.
6f30: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 .*/.#define UNUS
6f40: 45 44 5f 50 41 52 41 4d 45 54 45 52 28 78 29 20 ED_PARAMETER(x)
6f50: 28 76 6f 69 64 29 28 78 29 0a 23 64 65 66 69 6e (void)(x).#defin
6f60: 65 20 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 e UNUSED_PARAMET
6f70: 45 52 32 28 78 2c 79 29 20 55 4e 55 53 45 44 5f ER2(x,y) UNUSED_
6f80: 50 41 52 41 4d 45 54 45 52 28 78 29 2c 55 4e 55 PARAMETER(x),UNU
6f90: 53 45 44 5f 50 41 52 41 4d 45 54 45 52 28 79 29 SED_PARAMETER(y)
6fa0: 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 77 61 72 64 20 ../*.** Forward
6fb0: 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 73 74 references to st
6fc0: 72 75 63 74 75 72 65 73 0a 2a 2f 0a 74 79 70 65 ructures.*/.type
6fd0: 64 65 66 20 73 74 72 75 63 74 20 41 67 67 49 6e def struct AggIn
6fe0: 66 6f 20 41 67 67 49 6e 66 6f 3b 0a 74 79 70 65 fo AggInfo;.type
6ff0: 64 65 66 20 73 74 72 75 63 74 20 41 75 74 68 43 def struct AuthC
7000: 6f 6e 74 65 78 74 20 41 75 74 68 43 6f 6e 74 65 ontext AuthConte
7010: 78 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 xt;.typedef stru
7020: 63 74 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 41 ct AutoincInfo A
7030: 75 74 6f 69 6e 63 49 6e 66 6f 3b 0a 74 79 70 65 utoincInfo;.type
7040: 64 65 66 20 73 74 72 75 63 74 20 42 69 74 76 65 def struct Bitve
7050: 63 20 42 69 74 76 65 63 3b 0a 74 79 70 65 64 65 c Bitvec;.typede
7060: 66 20 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 f struct CollSeq
7070: 20 43 6f 6c 6c 53 65 71 3b 0a 74 79 70 65 64 65 CollSeq;.typede
7080: 66 20 73 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 f struct Column
7090: 43 6f 6c 75 6d 6e 3b 0a 74 79 70 65 64 65 66 20 Column;.typedef
70a0: 73 74 72 75 63 74 20 44 62 20 44 62 3b 0a 74 79 struct Db Db;.ty
70b0: 70 65 64 65 66 20 73 74 72 75 63 74 20 53 63 68 pedef struct Sch
70c0: 65 6d 61 20 53 63 68 65 6d 61 3b 0a 74 79 70 65 ema Schema;.type
70d0: 64 65 66 20 73 74 72 75 63 74 20 45 78 70 72 20 def struct Expr
70e0: 45 78 70 72 3b 0a 74 79 70 65 64 65 66 20 73 74 Expr;.typedef st
70f0: 72 75 63 74 20 45 78 70 72 4c 69 73 74 20 45 78 ruct ExprList Ex
7100: 70 72 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 prList;.typedef
7110: 73 74 72 75 63 74 20 45 78 70 72 53 70 61 6e 20 struct ExprSpan
7120: 45 78 70 72 53 70 61 6e 3b 0a 74 79 70 65 64 65 ExprSpan;.typede
7130: 66 20 73 74 72 75 63 74 20 46 4b 65 79 20 46 4b f struct FKey FK
7140: 65 79 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ey;.typedef stru
7150: 63 74 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f ct FuncDestructo
7160: 72 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 r FuncDestructor
7170: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7180: 20 46 75 6e 63 44 65 66 20 46 75 6e 63 44 65 66 FuncDef FuncDef
7190: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
71a0: 20 46 75 6e 63 44 65 66 48 61 73 68 20 46 75 6e FuncDefHash Fun
71b0: 63 44 65 66 48 61 73 68 3b 0a 74 79 70 65 64 65 cDefHash;.typede
71c0: 66 20 73 74 72 75 63 74 20 49 64 4c 69 73 74 20 f struct IdList
71d0: 49 64 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 IdList;.typedef
71e0: 73 74 72 75 63 74 20 49 6e 64 65 78 20 49 6e 64 struct Index Ind
71f0: 65 78 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ex;.typedef stru
7200: 63 74 20 49 6e 64 65 78 53 61 6d 70 6c 65 20 49 ct IndexSample I
7210: 6e 64 65 78 53 61 6d 70 6c 65 3b 0a 74 79 70 65 ndexSample;.type
7220: 64 65 66 20 73 74 72 75 63 74 20 4b 65 79 43 6c def struct KeyCl
7230: 61 73 73 20 4b 65 79 43 6c 61 73 73 3b 0a 74 79 ass KeyClass;.ty
7240: 70 65 64 65 66 20 73 74 72 75 63 74 20 4b 65 79 pedef struct Key
7250: 49 6e 66 6f 20 4b 65 79 49 6e 66 6f 3b 0a 74 79 Info KeyInfo;.ty
7260: 70 65 64 65 66 20 73 74 72 75 63 74 20 4c 6f 6f pedef struct Loo
7270: 6b 61 73 69 64 65 20 4c 6f 6f 6b 61 73 69 64 65 kaside Lookaside
7280: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7290: 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 4c LookasideSlot L
72a0: 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 3b 0a 74 79 ookasideSlot;.ty
72b0: 70 65 64 65 66 20 73 74 72 75 63 74 20 4d 6f 64 pedef struct Mod
72c0: 75 6c 65 20 4d 6f 64 75 6c 65 3b 0a 74 79 70 65 ule Module;.type
72d0: 64 65 66 20 73 74 72 75 63 74 20 4e 61 6d 65 43 def struct NameC
72e0: 6f 6e 74 65 78 74 20 4e 61 6d 65 43 6f 6e 74 65 ontext NameConte
72f0: 78 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 xt;.typedef stru
7300: 63 74 20 50 61 72 73 65 20 50 61 72 73 65 3b 0a ct Parse Parse;.
7310: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 50 typedef struct P
7320: 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 20 50 rintfArguments P
7330: 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 3b 0a rintfArguments;.
7340: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 52 typedef struct R
7350: 6f 77 53 65 74 20 52 6f 77 53 65 74 3b 0a 74 79 owSet RowSet;.ty
7360: 70 65 64 65 66 20 73 74 72 75 63 74 20 53 61 76 pedef struct Sav
7370: 65 70 6f 69 6e 74 20 53 61 76 65 70 6f 69 6e 74 epoint Savepoint
7380: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7390: 20 53 65 6c 65 63 74 20 53 65 6c 65 63 74 3b 0a Select Select;.
73a0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
73b0: 51 4c 69 74 65 54 68 72 65 61 64 20 53 51 4c 69 QLiteThread SQLi
73c0: 74 65 54 68 72 65 61 64 3b 0a 74 79 70 65 64 65 teThread;.typede
73d0: 66 20 73 74 72 75 63 74 20 53 65 6c 65 63 74 44 f struct SelectD
73e0: 65 73 74 20 53 65 6c 65 63 74 44 65 73 74 3b 0a est SelectDest;.
73f0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
7400: 72 63 4c 69 73 74 20 53 72 63 4c 69 73 74 3b 0a rcList SrcList;.
7410: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
7420: 74 72 41 63 63 75 6d 20 53 74 72 41 63 63 75 6d trAccum StrAccum
7430: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7440: 20 54 61 62 6c 65 20 54 61 62 6c 65 3b 0a 74 79 Table Table;.ty
7450: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 61 62 pedef struct Tab
7460: 6c 65 4c 6f 63 6b 20 54 61 62 6c 65 4c 6f 63 6b leLock TableLock
7470: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7480: 20 54 6f 6b 65 6e 20 54 6f 6b 65 6e 3b 0a 74 79 Token Token;.ty
7490: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 72 65 pedef struct Tre
74a0: 65 56 69 65 77 20 54 72 65 65 56 69 65 77 3b 0a eView TreeView;.
74b0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
74c0: 72 69 67 67 65 72 20 54 72 69 67 67 65 72 3b 0a rigger Trigger;.
74d0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
74e0: 72 69 67 67 65 72 50 72 67 20 54 72 69 67 67 65 riggerPrg Trigge
74f0: 72 50 72 67 3b 0a 74 79 70 65 64 65 66 20 73 74 rPrg;.typedef st
7500: 72 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 ruct TriggerStep
7510: 20 54 72 69 67 67 65 72 53 74 65 70 3b 0a 74 79 TriggerStep;.ty
7520: 70 65 64 65 66 20 73 74 72 75 63 74 20 55 6e 70 pedef struct Unp
7530: 61 63 6b 65 64 52 65 63 6f 72 64 20 55 6e 70 61 ackedRecord Unpa
7540: 63 6b 65 64 52 65 63 6f 72 64 3b 0a 74 79 70 65 ckedRecord;.type
7550: 64 65 66 20 73 74 72 75 63 74 20 56 54 61 62 6c def struct VTabl
7560: 65 20 56 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 e VTable;.typede
7570: 66 20 73 74 72 75 63 74 20 56 74 61 62 43 74 78 f struct VtabCtx
7580: 20 56 74 61 62 43 74 78 3b 0a 74 79 70 65 64 65 VtabCtx;.typede
7590: 66 20 73 74 72 75 63 74 20 57 61 6c 6b 65 72 20 f struct Walker
75a0: 57 61 6c 6b 65 72 3b 0a 74 79 70 65 64 65 66 20 Walker;.typedef
75b0: 73 74 72 75 63 74 20 57 68 65 72 65 49 6e 66 6f struct WhereInfo
75c0: 20 57 68 65 72 65 49 6e 66 6f 3b 0a 74 79 70 65 WhereInfo;.type
75d0: 64 65 66 20 73 74 72 75 63 74 20 57 69 74 68 20 def struct With
75e0: 57 69 74 68 3b 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 With;../*.** Def
75f0: 65 72 20 73 6f 75 72 63 69 6e 67 20 76 64 62 65 er sourcing vdbe
7600: 2e 68 20 61 6e 64 20 62 74 72 65 65 2e 68 20 75 .h and btree.h u
7610: 6e 74 69 6c 20 61 66 74 65 72 20 74 68 65 20 22 ntil after the "
7620: 75 38 22 20 61 6e 64 20 0a 2a 2a 20 22 42 75 73 u8" and .** "Bus
7630: 79 48 61 6e 64 6c 65 72 22 20 74 79 70 65 64 65 yHandler" typede
7640: 66 73 2e 20 76 64 62 65 2e 68 20 61 6c 73 6f 20 fs. vdbe.h also
7650: 72 65 71 75 69 72 65 73 20 61 20 66 65 77 20 6f requires a few o
7660: 66 20 74 68 65 20 6f 70 61 71 75 65 0a 2a 2a 20 f the opaque.**
7670: 70 6f 69 6e 74 65 72 20 74 79 70 65 73 20 28 69 pointer types (i
7680: 2e 65 2e 20 46 75 6e 63 44 65 66 29 20 64 65 66 .e. FuncDef) def
7690: 69 6e 65 64 20 61 62 6f 76 65 2e 0a 2a 2f 0a 23 ined above..*/.#
76a0: 69 6e 63 6c 75 64 65 20 22 62 74 72 65 65 2e 68 include "btree.h
76b0: 22 0a 23 69 6e 63 6c 75 64 65 20 22 76 64 62 65 ".#include "vdbe
76c0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 61 .h".#include "pa
76d0: 67 65 72 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 ger.h".#include
76e0: 22 70 63 61 63 68 65 2e 68 22 0a 0a 23 69 6e 63 "pcache.h"..#inc
76f0: 6c 75 64 65 20 22 6f 73 2e 68 22 0a 23 69 6e 63 lude "os.h".#inc
7700: 6c 75 64 65 20 22 6d 75 74 65 78 2e 68 22 0a 0a lude "mutex.h"..
7710: 2f 2a 20 57 68 65 6e 20 75 73 69 6e 67 20 61 20 /* When using a
7720: 64 65 66 61 75 6c 74 20 77 61 6c 20 73 61 66 65 default wal safe
7730: 74 79 20 6c 65 76 65 6c 2c 20 74 68 65 20 73 61 ty level, the sa
7740: 66 65 74 79 20 6c 65 76 65 6c 20 73 68 6f 75 6c fety level shoul
7750: 64 20 6f 6e 6c 79 20 0a 2a 2a 20 63 68 61 6e 67 d only .** chang
7760: 65 20 77 69 74 68 20 74 68 65 20 6a 6f 75 72 6e e with the journ
7770: 61 6c 20 6d 6f 64 65 20 69 66 20 74 68 65 20 75 al mode if the u
7780: 73 65 72 20 68 61 73 6e 27 74 20 6d 61 6e 75 61 ser hasn't manua
7790: 6c 6c 79 20 73 70 65 63 69 66 69 65 64 20 0a 2a lly specified .*
77a0: 2a 20 70 72 61 67 6d 61 20 73 79 6e 63 68 72 6f * pragma synchro
77b0: 6e 6f 75 73 2c 20 69 66 20 74 68 65 79 20 68 61 nous, if they ha
77c0: 76 65 20 74 68 65 20 64 65 66 61 75 6c 74 73 20 ve the defaults
77d0: 73 68 6f 75 6c 64 6e 27 74 20 62 65 20 61 70 70 shouldn't be app
77e0: 6c 69 65 64 2e 0a 2a 2a 20 54 68 65 20 53 51 4c lied..** The SQL
77f0: 49 54 45 5f 53 41 46 45 54 59 4c 45 56 45 4c 5f ITE_SAFETYLEVEL_
7800: 46 49 58 45 44 20 76 61 6c 75 65 20 69 73 20 4f FIXED value is O
7810: 52 65 64 20 69 6e 74 6f 20 74 68 65 20 44 62 2d Red into the Db-
7820: 3e 73 61 66 65 74 79 5f 6c 65 76 65 6c 0a 2a 2a >safety_level.**
7830: 20 66 69 65 6c 64 20 77 68 65 6e 20 74 68 65 20 field when the
7840: 75 73 65 72 20 68 61 73 20 73 70 65 63 69 66 69 user has specifi
7850: 65 64 20 61 20 73 79 6e 63 68 72 6f 6e 6f 75 73 ed a synchronous
7860: 20 73 65 74 74 69 6e 67 20 76 69 61 20 70 72 61 setting via pra
7870: 67 6d 61 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 gma..*/.#define
7880: 53 51 4c 49 54 45 5f 53 41 46 45 54 59 4c 45 56 SQLITE_SAFETYLEV
7890: 45 4c 5f 46 49 58 45 44 20 30 78 31 30 0a 23 64 EL_FIXED 0x10.#d
78a0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 41 46 efine SQLITE_SAF
78b0: 45 54 59 4c 45 56 45 4c 5f 56 41 4c 55 45 5f 4d ETYLEVEL_VALUE_M
78c0: 41 53 4b 20 30 78 30 33 0a 23 64 65 66 69 6e 65 ASK 0x03.#define
78d0: 20 53 51 4c 49 54 45 5f 44 62 53 61 66 65 74 79 SQLITE_DbSafety
78e0: 4c 65 76 65 6c 56 61 6c 75 65 28 6c 65 76 65 6c LevelValue(level
78f0: 29 20 28 6c 65 76 65 6c 26 53 51 4c 49 54 45 5f ) (level&SQLITE_
7900: 53 41 46 45 54 59 4c 45 56 45 4c 5f 56 41 4c 55 SAFETYLEVEL_VALU
7910: 45 5f 4d 41 53 4b 29 0a 23 64 65 66 69 6e 65 20 E_MASK).#define
7920: 53 51 4c 49 54 45 5f 44 62 53 61 66 65 74 79 4c SQLITE_DbSafetyL
7930: 65 76 65 6c 49 73 46 69 78 65 64 28 6c 65 76 65 evelIsFixed(leve
7940: 6c 29 20 28 6c 65 76 65 6c 26 53 51 4c 49 54 45 l) (level&SQLITE
7950: 5f 53 41 46 45 54 59 4c 45 56 45 4c 5f 46 49 58 _SAFETYLEVEL_FIX
7960: 45 44 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 ED)../*.** Each
7970: 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 74 6f database file to
7980: 20 62 65 20 61 63 63 65 73 73 65 64 20 62 79 20 be accessed by
7990: 74 68 65 20 73 79 73 74 65 6d 20 69 73 20 61 6e the system is an
79a0: 20 69 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 instance.** of
79b0: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
79c0: 72 75 63 74 75 72 65 2e 20 20 54 68 65 72 65 20 ructure. There
79d0: 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 20 74 77 6f are normally two
79e0: 20 6f 66 20 74 68 65 73 65 20 73 74 72 75 63 74 of these struct
79f0: 75 72 65 73 0a 2a 2a 20 69 6e 20 74 68 65 20 73 ures.** in the s
7a00: 71 6c 69 74 65 2e 61 44 62 5b 5d 20 61 72 72 61 qlite.aDb[] arra
7a10: 79 2e 20 20 61 44 62 5b 30 5d 20 69 73 20 74 68 y. aDb[0] is th
7a20: 65 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 e main database
7a30: 66 69 6c 65 20 61 6e 64 0a 2a 2a 20 61 44 62 5b file and.** aDb[
7a40: 31 5d 20 69 73 20 74 68 65 20 64 61 74 61 62 61 1] is the databa
7a50: 73 65 20 66 69 6c 65 20 75 73 65 64 20 74 6f 20 se file used to
7a60: 68 6f 6c 64 20 74 65 6d 70 6f 72 61 72 79 20 74 hold temporary t
7a70: 61 62 6c 65 73 2e 20 20 41 64 64 69 74 69 6f 6e ables. Addition
7a80: 61 6c 0a 2a 2a 20 64 61 74 61 62 61 73 65 73 20 al.** databases
7a90: 6d 61 79 20 62 65 20 61 74 74 61 63 68 65 64 2e may be attached.
7aa0: 0a 2a 2f 0a 73 74 72 75 63 74 20 44 62 20 7b 0a .*/.struct Db {.
7ab0: 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
7ac0: 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
7ad0: 66 20 74 68 69 73 20 64 61 74 61 62 61 73 65 20 f this database
7ae0: 2a 2f 0a 20 20 42 74 72 65 65 20 2a 70 42 74 3b */. Btree *pBt;
7af0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 /* The
7b00: 20 42 2a 54 72 65 65 20 73 74 72 75 63 74 75 72 B*Tree structur
7b10: 65 20 66 6f 72 20 74 68 69 73 20 64 61 74 61 62 e for this datab
7b20: 61 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 75 38 ase file */. u8
7b30: 20 73 61 66 65 74 79 5f 6c 65 76 65 6c 3b 20 20 safety_level;
7b40: 20 20 20 2f 2a 20 48 6f 77 20 61 67 67 72 65 73 /* How aggres
7b50: 73 69 76 65 20 61 74 20 73 79 6e 63 69 6e 67 20 sive at syncing
7b60: 64 61 74 61 20 74 6f 20 64 69 73 6b 20 2a 2f 0a data to disk */.
7b70: 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d Schema *pSchem
7b80: 61 3b 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 a; /* Pointe
7b90: 72 20 74 6f 20 64 61 74 61 62 61 73 65 20 73 63 r to database sc
7ba0: 68 65 6d 61 20 28 70 6f 73 73 69 62 6c 79 20 73 hema (possibly s
7bb0: 68 61 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a hared) */.};../*
7bc0: 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
7bd0: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
7be0: 20 73 74 72 75 63 74 75 72 65 20 73 74 6f 72 65 structure store
7bf0: 73 20 61 20 64 61 74 61 62 61 73 65 20 73 63 68 s a database sch
7c00: 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 ema..**.** Most
7c10: 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 20 61 Schema objects a
7c20: 72 65 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 re associated wi
7c30: 74 68 20 61 20 42 74 72 65 65 2e 20 20 54 68 65 th a Btree. The
7c40: 20 65 78 63 65 70 74 69 6f 6e 20 69 73 0a 2a 2a exception is.**
7c50: 20 74 68 65 20 53 63 68 65 6d 61 20 66 6f 72 20 the Schema for
7c60: 74 68 65 20 54 45 4d 50 20 64 61 74 61 62 61 65 the TEMP databae
7c70: 73 20 28 73 71 6c 69 74 65 33 2e 61 44 62 5b 31 s (sqlite3.aDb[1
7c80: 5d 29 20 77 68 69 63 68 20 69 73 20 66 72 65 65 ]) which is free
7c90: 2d 73 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 6e -standing..** In
7ca0: 20 73 68 61 72 65 64 20 63 61 63 68 65 20 6d 6f shared cache mo
7cb0: 64 65 2c 20 61 20 73 69 6e 67 6c 65 20 53 63 68 de, a single Sch
7cc0: 65 6d 61 20 6f 62 6a 65 63 74 20 63 61 6e 20 62 ema object can b
7cd0: 65 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 e shared by mult
7ce0: 69 70 6c 65 0a 2a 2a 20 42 74 72 65 65 73 20 74 iple.** Btrees t
7cf0: 68 61 74 20 72 65 66 65 72 20 74 6f 20 74 68 65 hat refer to the
7d00: 20 73 61 6d 65 20 75 6e 64 65 72 6c 79 69 6e 67 same underlying
7d10: 20 42 74 53 68 61 72 65 64 20 6f 62 6a 65 63 74 BtShared object
7d20: 2e 0a 2a 2a 20 0a 2a 2a 20 53 63 68 65 6d 61 20 ..** .** Schema
7d30: 6f 62 6a 65 63 74 73 20 61 72 65 20 61 75 74 6f objects are auto
7d40: 6d 61 74 69 63 61 6c 6c 79 20 64 65 61 6c 6c 6f matically deallo
7d50: 63 61 74 65 64 20 77 68 65 6e 20 74 68 65 20 6c cated when the l
7d60: 61 73 74 20 42 74 72 65 65 20 74 68 61 74 0a 2a ast Btree that.*
7d70: 2a 20 72 65 66 65 72 65 6e 63 65 73 20 74 68 65 * references the
7d80: 6d 20 69 73 20 64 65 73 74 72 6f 79 65 64 2e 20 m is destroyed.
7d90: 20 20 54 68 65 20 54 45 4d 50 20 53 63 68 65 6d The TEMP Schem
7da0: 61 20 69 73 20 6d 61 6e 75 61 6c 6c 79 20 66 72 a is manually fr
7db0: 65 65 64 20 62 79 0a 2a 2a 20 73 71 6c 69 74 65 eed by.** sqlite
7dc0: 33 5f 63 6c 6f 73 65 28 29 2e 0a 2a 0a 2a 2a 20 3_close()..*.**
7dd0: 41 20 74 68 72 65 61 64 20 6d 75 73 74 20 62 65 A thread must be
7de0: 20 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 holding a mutex
7df0: 20 6f 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f on the correspo
7e00: 6e 64 69 6e 67 20 42 74 72 65 65 20 69 6e 20 6f nding Btree in o
7e10: 72 64 65 72 0a 2a 2a 20 74 6f 20 61 63 63 65 73 rder.** to acces
7e20: 73 20 53 63 68 65 6d 61 20 63 6f 6e 74 65 6e 74 s Schema content
7e30: 2e 20 20 54 68 69 73 20 69 6d 70 6c 69 65 73 20 . This implies
7e40: 74 68 61 74 20 74 68 65 20 74 68 72 65 61 64 20 that the thread
7e50: 6d 75 73 74 20 61 6c 73 6f 20 62 65 0a 2a 2a 20 must also be.**
7e60: 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 holding a mutex
7e70: 6f 6e 20 74 68 65 20 73 71 6c 69 74 65 33 20 63 on the sqlite3 c
7e80: 6f 6e 6e 65 63 74 69 6f 6e 20 70 6f 69 6e 74 65 onnection pointe
7e90: 72 20 74 68 61 74 20 6f 77 6e 73 20 74 68 65 20 r that owns the
7ea0: 42 74 72 65 65 2e 0a 2a 2a 20 46 6f 72 20 61 20 Btree..** For a
7eb0: 54 45 4d 50 20 53 63 68 65 6d 61 2c 20 6f 6e 6c TEMP Schema, onl
7ec0: 79 20 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e y the connection
7ed0: 20 6d 75 74 65 78 20 69 73 20 72 65 71 75 69 72 mutex is requir
7ee0: 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 63 ed..*/.struct Sc
7ef0: 68 65 6d 61 20 7b 0a 20 20 69 6e 74 20 73 63 68 hema {. int sch
7f00: 65 6d 61 5f 63 6f 6f 6b 69 65 3b 20 20 20 2f 2a ema_cookie; /*
7f10: 20 44 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 Database schema
7f20: 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 version number
7f30: 66 6f 72 20 74 68 69 73 20 66 69 6c 65 20 2a 2f for this file */
7f40: 0a 20 20 69 6e 74 20 69 47 65 6e 65 72 61 74 69 . int iGenerati
7f50: 6f 6e 3b 20 20 20 20 20 2f 2a 20 47 65 6e 65 72 on; /* Gener
7f60: 61 74 69 6f 6e 20 63 6f 75 6e 74 65 72 2e 20 20 ation counter.
7f70: 49 6e 63 72 65 6d 65 6e 74 65 64 20 77 69 74 68 Incremented with
7f80: 20 65 61 63 68 20 63 68 61 6e 67 65 20 2a 2f 0a each change */.
7f90: 20 20 48 61 73 68 20 74 62 6c 48 61 73 68 3b 20 Hash tblHash;
7fa0: 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 74 61 /* All ta
7fb0: 62 6c 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 bles indexed by
7fc0: 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 69 name */. Hash i
7fd0: 64 78 48 61 73 68 3b 20 20 20 20 20 20 20 20 2f dxHash; /
7fe0: 2a 20 41 6c 6c 20 28 6e 61 6d 65 64 29 20 69 6e * All (named) in
7ff0: 64 69 63 65 73 20 69 6e 64 65 78 65 64 20 62 79 dices indexed by
8000: 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 name */. Hash
8010: 74 72 69 67 48 61 73 68 3b 20 20 20 20 20 20 20 trigHash;
8020: 2f 2a 20 41 6c 6c 20 74 72 69 67 67 65 72 73 20 /* All triggers
8030: 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 indexed by name
8040: 2a 2f 0a 20 20 48 61 73 68 20 66 6b 65 79 48 61 */. Hash fkeyHa
8050: 73 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c sh; /* All
8060: 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 62 79 foreign keys by
8070: 20 72 65 66 65 72 65 6e 63 65 64 20 74 61 62 6c referenced tabl
8080: 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 61 62 6c e name */. Tabl
8090: 65 20 2a 70 53 65 71 54 61 62 3b 20 20 20 20 20 e *pSeqTab;
80a0: 20 2f 2a 20 54 68 65 20 73 71 6c 69 74 65 5f 73 /* The sqlite_s
80b0: 65 71 75 65 6e 63 65 20 74 61 62 6c 65 20 75 73 equence table us
80c0: 65 64 20 62 79 20 41 55 54 4f 49 4e 43 52 45 4d ed by AUTOINCREM
80d0: 45 4e 54 20 2a 2f 0a 20 20 75 38 20 66 69 6c 65 ENT */. u8 file
80e0: 5f 66 6f 72 6d 61 74 3b 20 20 20 20 20 20 2f 2a _format; /*
80f0: 20 53 63 68 65 6d 61 20 66 6f 72 6d 61 74 20 76 Schema format v
8100: 65 72 73 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 ersion for this
8110: 66 69 6c 65 20 2a 2f 0a 20 20 75 38 20 65 6e 63 file */. u8 enc
8120: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
8130: 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 * Text encoding
8140: 75 73 65 64 20 62 79 20 74 68 69 73 20 64 61 74 used by this dat
8150: 61 62 61 73 65 20 2a 2f 0a 20 20 75 31 36 20 73 abase */. u16 s
8160: 63 68 65 6d 61 46 6c 61 67 73 3b 20 20 20 20 20 chemaFlags;
8170: 2f 2a 20 46 6c 61 67 73 20 61 73 73 6f 63 69 61 /* Flags associa
8180: 74 65 64 20 77 69 74 68 20 74 68 69 73 20 73 63 ted with this sc
8190: 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 63 61 hema */. int ca
81a0: 63 68 65 5f 73 69 7a 65 3b 20 20 20 20 20 20 2f che_size; /
81b0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 * Number of page
81c0: 73 20 74 6f 20 75 73 65 20 69 6e 20 74 68 65 20 s to use in the
81d0: 63 61 63 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a cache */.};../*.
81e0: 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 ** These macros
81f0: 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 can be used to t
8200: 65 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 est, set, or cle
8210: 61 72 20 62 69 74 73 20 69 6e 20 74 68 65 20 0a ar bits in the .
8220: 2a 2a 20 44 62 2e 70 53 63 68 65 6d 61 2d 3e 66 ** Db.pSchema->f
8230: 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 lags field..*/.#
8240: 64 65 66 69 6e 65 20 44 62 48 61 73 50 72 6f 70 define DbHasProp
8250: 65 72 74 79 28 44 2c 49 2c 50 29 20 20 20 20 20 erty(D,I,P)
8260: 28 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 (((D)->aDb[I].pS
8270: 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 chema->schemaFla
8280: 67 73 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 64 gs&(P))==(P)).#d
8290: 65 66 69 6e 65 20 44 62 48 61 73 41 6e 79 50 72 efine DbHasAnyPr
82a0: 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 28 operty(D,I,P) (
82b0: 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 ((D)->aDb[I].pSc
82c0: 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 hema->schemaFlag
82d0: 73 26 28 50 29 29 21 3d 30 29 0a 23 64 65 66 69 s&(P))!=0).#defi
82e0: 6e 65 20 44 62 53 65 74 50 72 6f 70 65 72 74 79 ne DbSetProperty
82f0: 28 44 2c 49 2c 50 29 20 20 20 20 20 28 44 29 2d (D,I,P) (D)-
8300: 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d >aDb[I].pSchema-
8310: 3e 73 63 68 65 6d 61 46 6c 61 67 73 7c 3d 28 50 >schemaFlags|=(P
8320: 29 0a 23 64 65 66 69 6e 65 20 44 62 43 6c 65 61 ).#define DbClea
8330: 72 50 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 rProperty(D,I,P)
8340: 20 20 20 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 (D)->aDb[I].p
8350: 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c Schema->schemaFl
8360: 61 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 0a 2a 2a ags&=~(P)../*.**
8370: 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 Allowed values
8380: 66 6f 72 20 74 68 65 20 44 42 2e 70 53 63 68 65 for the DB.pSche
8390: 6d 61 2d 3e 66 6c 61 67 73 20 66 69 65 6c 64 2e ma->flags field.
83a0: 0a 2a 2a 0a 2a 2a 20 54 68 65 20 44 42 5f 53 63 .**.** The DB_Sc
83b0: 68 65 6d 61 4c 6f 61 64 65 64 20 66 6c 61 67 20 hemaLoaded flag
83c0: 69 73 20 73 65 74 20 61 66 74 65 72 20 74 68 65 is set after the
83d0: 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 database schema
83e0: 20 68 61 73 20 62 65 65 6e 0a 2a 2a 20 72 65 61 has been.** rea
83f0: 64 20 69 6e 74 6f 20 69 6e 74 65 72 6e 61 6c 20 d into internal
8400: 68 61 73 68 20 74 61 62 6c 65 73 2e 0a 2a 2a 0a hash tables..**.
8410: 2a 2a 20 44 42 5f 55 6e 72 65 73 65 74 56 69 65 ** DB_UnresetVie
8420: 77 73 20 6d 65 61 6e 73 20 74 68 61 74 20 6f 6e ws means that on
8430: 65 20 6f 72 20 6d 6f 72 65 20 76 69 65 77 73 20 e or more views
8440: 68 61 76 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 have column name
8450: 73 20 74 68 61 74 0a 2a 2a 20 68 61 76 65 20 62 s that.** have b
8460: 65 65 6e 20 66 69 6c 6c 65 64 20 6f 75 74 2e 20 een filled out.
8470: 20 49 66 20 74 68 65 20 73 63 68 65 6d 61 20 63 If the schema c
8480: 68 61 6e 67 65 73 2c 20 74 68 65 73 65 20 63 6f hanges, these co
8490: 6c 75 6d 6e 20 6e 61 6d 65 73 20 6d 69 67 68 74 lumn names might
84a0: 0a 2a 2a 20 63 68 61 6e 67 65 73 20 61 6e 64 20 .** changes and
84b0: 73 6f 20 74 68 65 20 76 69 65 77 20 77 69 6c 6c so the view will
84c0: 20 6e 65 65 64 20 74 6f 20 62 65 20 72 65 73 65 need to be rese
84d0: 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 t..*/.#define DB
84e0: 5f 53 63 68 65 6d 61 4c 6f 61 64 65 64 20 20 20 _SchemaLoaded
84f0: 20 30 78 30 30 30 31 20 20 2f 2a 20 54 68 65 20 0x0001 /* The
8500: 73 63 68 65 6d 61 20 68 61 73 20 62 65 65 6e 20 schema has been
8510: 6c 6f 61 64 65 64 20 2a 2f 0a 23 64 65 66 69 6e loaded */.#defin
8520: 65 20 44 42 5f 55 6e 72 65 73 65 74 56 69 65 77 e DB_UnresetView
8530: 73 20 20 20 20 30 78 30 30 30 32 20 20 2f 2a 20 s 0x0002 /*
8540: 53 6f 6d 65 20 76 69 65 77 73 20 68 61 76 65 20 Some views have
8550: 64 65 66 69 6e 65 64 20 63 6f 6c 75 6d 6e 20 6e defined column n
8560: 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ames */.#define
8570: 44 42 5f 45 6d 70 74 79 20 20 20 20 20 20 20 20 DB_Empty
8580: 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 54 68 0x0004 /* Th
8590: 65 20 66 69 6c 65 20 69 73 20 65 6d 70 74 79 20 e file is empty
85a0: 28 6c 65 6e 67 74 68 20 30 20 62 79 74 65 73 29 (length 0 bytes)
85b0: 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e */../*.** The n
85c0: 75 6d 62 65 72 20 6f 66 20 64 69 66 66 65 72 65 umber of differe
85d0: 6e 74 20 6b 69 6e 64 73 20 6f 66 20 74 68 69 6e nt kinds of thin
85e0: 67 73 20 74 68 61 74 20 63 61 6e 20 62 65 20 6c gs that can be l
85f0: 69 6d 69 74 65 64 0a 2a 2a 20 75 73 69 6e 67 20 imited.** using
8600: 74 68 65 20 73 71 6c 69 74 65 33 5f 6c 69 6d 69 the sqlite3_limi
8610: 74 28 29 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a t() interface..*
8620: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
8630: 5f 4e 5f 4c 49 4d 49 54 20 28 53 51 4c 49 54 45 _N_LIMIT (SQLITE
8640: 5f 4c 49 4d 49 54 5f 57 4f 52 4b 45 52 5f 54 48 _LIMIT_WORKER_TH
8650: 52 45 41 44 53 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 READS+1)../*.**
8660: 4c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 Lookaside malloc
8670: 20 69 73 20 61 20 73 65 74 20 6f 66 20 66 69 78 is a set of fix
8680: 65 64 2d 73 69 7a 65 20 62 75 66 66 65 72 73 20 ed-size buffers
8690: 74 68 61 74 20 63 61 6e 20 62 65 20 75 73 65 64 that can be used
86a0: 0a 2a 2a 20 74 6f 20 73 61 74 69 73 66 79 20 73 .** to satisfy s
86b0: 6d 61 6c 6c 20 74 72 61 6e 73 69 65 6e 74 20 6d mall transient m
86c0: 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e emory allocation
86d0: 20 72 65 71 75 65 73 74 73 20 66 6f 72 20 6f 62 requests for ob
86e0: 6a 65 63 74 73 0a 2a 2a 20 61 73 73 6f 63 69 61 jects.** associa
86f0: 74 65 64 20 77 69 74 68 20 61 20 70 61 72 74 69 ted with a parti
8700: 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 cular database c
8710: 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 54 68 65 20 onnection. The
8720: 75 73 65 20 6f 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 use of.** lookas
8730: 69 64 65 20 6d 61 6c 6c 6f 63 20 70 72 6f 76 69 ide malloc provi
8740: 64 65 73 20 61 20 73 69 67 6e 69 66 69 63 61 6e des a significan
8750: 74 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 65 6e t performance en
8760: 68 61 6e 63 65 6d 65 6e 74 0a 2a 2a 20 28 61 70 hancement.** (ap
8770: 70 72 6f 78 20 31 30 25 29 20 62 79 20 61 76 6f prox 10%) by avo
8780: 69 64 69 6e 67 20 6e 75 6d 65 72 6f 75 73 20 6d iding numerous m
8790: 61 6c 6c 6f 63 2f 66 72 65 65 20 72 65 71 75 65 alloc/free reque
87a0: 73 74 73 20 77 68 69 6c 65 20 70 61 72 73 69 6e sts while parsin
87b0: 67 0a 2a 2a 20 53 51 4c 20 73 74 61 74 65 6d 65 g.** SQL stateme
87c0: 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c nts..**.** The L
87d0: 6f 6f 6b 61 73 69 64 65 20 73 74 72 75 63 74 75 ookaside structu
87e0: 72 65 20 68 6f 6c 64 73 20 63 6f 6e 66 69 67 75 re holds configu
87f0: 72 61 74 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 ration informati
8800: 6f 6e 20 61 62 6f 75 74 20 74 68 65 0a 2a 2a 20 on about the.**
8810: 6c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 lookaside malloc
8820: 20 73 75 62 73 79 73 74 65 6d 2e 20 20 45 61 63 subsystem. Eac
8830: 68 20 61 76 61 69 6c 61 62 6c 65 20 6d 65 6d 6f h available memo
8840: 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e ry allocation in
8850: 0a 2a 2a 20 74 68 65 20 6c 6f 6f 6b 61 73 69 64 .** the lookasid
8860: 65 20 73 75 62 73 79 73 74 65 6d 20 69 73 20 73 e subsystem is s
8870: 74 6f 72 65 64 20 6f 6e 20 61 20 6c 69 6e 6b 65 tored on a linke
8880: 64 20 6c 69 73 74 20 6f 66 20 4c 6f 6f 6b 61 73 d list of Lookas
8890: 69 64 65 53 6c 6f 74 0a 2a 2a 20 6f 62 6a 65 63 ideSlot.** objec
88a0: 74 73 2e 0a 2a 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 ts..**.** Lookas
88b0: 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 ide allocations
88c0: 61 72 65 20 6f 6e 6c 79 20 61 6c 6c 6f 77 65 64 are only allowed
88d0: 20 66 6f 72 20 6f 62 6a 65 63 74 73 20 74 68 61 for objects tha
88e0: 74 20 61 72 65 20 61 73 73 6f 63 69 61 74 65 64 t are associated
88f0: 0a 2a 2a 20 77 69 74 68 20 61 20 70 61 72 74 69 .** with a parti
8900: 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 cular database c
8910: 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 48 65 6e 63 onnection. Henc
8920: 65 2c 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d e, schema inform
8930: 61 74 69 6f 6e 20 63 61 6e 6e 6f 74 0a 2a 2a 20 ation cannot.**
8940: 62 65 20 73 74 6f 72 65 64 20 69 6e 20 6c 6f 6f be stored in loo
8950: 6b 61 73 69 64 65 20 62 65 63 61 75 73 65 20 69 kaside because i
8960: 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 20 6d n shared cache m
8970: 6f 64 65 20 74 68 65 20 73 63 68 65 6d 61 20 69 ode the schema i
8980: 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 69 73 nformation.** is
8990: 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 shared by multi
89a0: 70 6c 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e ple database con
89b0: 6e 65 63 74 69 6f 6e 73 2e 20 20 54 68 65 72 65 nections. There
89c0: 66 6f 72 65 2c 20 77 68 69 6c 65 20 70 61 72 73 fore, while pars
89d0: 69 6e 67 0a 2a 2a 20 73 63 68 65 6d 61 20 69 6e ing.** schema in
89e0: 66 6f 72 6d 61 74 69 6f 6e 2c 20 74 68 65 20 4c formation, the L
89f0: 6f 6f 6b 61 73 69 64 65 2e 62 45 6e 61 62 6c 65 ookaside.bEnable
8a00: 64 20 66 6c 61 67 20 69 73 20 63 6c 65 61 72 65 d flag is cleare
8a10: 64 20 73 6f 20 74 68 61 74 0a 2a 2a 20 6c 6f 6f d so that.** loo
8a20: 6b 61 73 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f kaside allocatio
8a30: 6e 73 20 61 72 65 20 6e 6f 74 20 75 73 65 64 20 ns are not used
8a40: 74 6f 20 63 6f 6e 73 74 72 75 63 74 20 74 68 65 to construct the
8a50: 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 2e schema objects.
8a60: 0a 2a 2f 0a 73 74 72 75 63 74 20 4c 6f 6f 6b 61 .*/.struct Looka
8a70: 73 69 64 65 20 7b 0a 20 20 75 31 36 20 73 7a 3b side {. u16 sz;
8a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8a90: 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 /* Size of each
8aa0: 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 65 73 buffer in bytes
8ab0: 20 2a 2f 0a 20 20 75 38 20 62 45 6e 61 62 6c 65 */. u8 bEnable
8ac0: 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a d; /*
8ad0: 20 46 61 6c 73 65 20 74 6f 20 64 69 73 61 62 6c False to disabl
8ae0: 65 20 6e 65 77 20 6c 6f 6f 6b 61 73 69 64 65 20 e new lookaside
8af0: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 20 allocations */.
8b00: 20 75 38 20 62 4d 61 6c 6c 6f 63 65 64 3b 20 20 u8 bMalloced;
8b10: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
8b20: 20 69 66 20 70 53 74 61 72 74 20 6f 62 74 61 69 if pStart obtai
8b30: 6e 65 64 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 ned from sqlite3
8b40: 5f 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 20 20 69 _malloc() */. i
8b50: 6e 74 20 6e 4f 75 74 3b 20 20 20 20 20 20 20 20 nt nOut;
8b60: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
8b70: 20 6f 66 20 62 75 66 66 65 72 73 20 63 75 72 72 of buffers curr
8b80: 65 6e 74 6c 79 20 63 68 65 63 6b 65 64 20 6f 75 ently checked ou
8b90: 74 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 4f 75 74 t */. int mxOut
8ba0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
8bb0: 2a 20 48 69 67 68 77 61 74 65 72 20 6d 61 72 6b * Highwater mark
8bc0: 20 66 6f 72 20 6e 4f 75 74 20 2a 2f 0a 20 20 69 for nOut */. i
8bd0: 6e 74 20 61 6e 53 74 61 74 5b 33 5d 3b 20 20 20 nt anStat[3];
8be0: 20 20 20 20 20 20 20 2f 2a 20 30 3a 20 68 69 74 /* 0: hit
8bf0: 73 2e 20 20 31 3a 20 73 69 7a 65 20 6d 69 73 73 s. 1: size miss
8c00: 65 73 2e 20 20 32 3a 20 66 75 6c 6c 20 6d 69 73 es. 2: full mis
8c10: 73 65 73 20 2a 2f 0a 20 20 4c 6f 6f 6b 61 73 69 ses */. Lookasi
8c20: 64 65 53 6c 6f 74 20 2a 70 46 72 65 65 3b 20 20 deSlot *pFree;
8c30: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 76 61 69 /* List of avai
8c40: 6c 61 62 6c 65 20 62 75 66 66 65 72 73 20 2a 2f lable buffers */
8c50: 0a 20 20 76 6f 69 64 20 2a 70 53 74 61 72 74 3b . void *pStart;
8c60: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 /* Fi
8c70: 72 73 74 20 62 79 74 65 20 6f 66 20 61 76 61 69 rst byte of avai
8c80: 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 70 61 lable memory spa
8c90: 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 45 ce */. void *pE
8ca0: 6e 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nd;
8cb0: 2f 2a 20 46 69 72 73 74 20 62 79 74 65 20 70 61 /* First byte pa
8cc0: 73 74 20 65 6e 64 20 6f 66 20 61 76 61 69 6c 61 st end of availa
8cd0: 62 6c 65 20 73 70 61 63 65 20 2a 2f 0a 7d 3b 0a ble space */.};.
8ce0: 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 struct Lookaside
8cf0: 53 6c 6f 74 20 7b 0a 20 20 4c 6f 6f 6b 61 73 69 Slot {. Lookasi
8d00: 64 65 53 6c 6f 74 20 2a 70 4e 65 78 74 3b 20 20 deSlot *pNext;
8d10: 20 20 2f 2a 20 4e 65 78 74 20 62 75 66 66 65 72 /* Next buffer
8d20: 20 69 6e 20 74 68 65 20 6c 69 73 74 20 6f 66 20 in the list of
8d30: 66 72 65 65 20 62 75 66 66 65 72 73 20 2a 2f 0a free buffers */.
8d40: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 68 61 73 68 };../*.** A hash
8d50: 20 74 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 table for funct
8d60: 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e ion definitions.
8d70: 0a 2a 2a 0a 2a 2a 20 48 61 73 68 20 65 61 63 68 .**.** Hash each
8d80: 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 74 75 FuncDef structu
8d90: 72 65 20 69 6e 74 6f 20 6f 6e 65 20 6f 66 20 74 re into one of t
8da0: 68 65 20 46 75 6e 63 44 65 66 48 61 73 68 2e 61 he FuncDefHash.a
8db0: 5b 5d 20 73 6c 6f 74 73 2e 0a 2a 2a 20 43 6f 6c [] slots..** Col
8dc0: 6c 69 73 69 6f 6e 73 20 61 72 65 20 6f 6e 20 74 lisions are on t
8dd0: 68 65 20 46 75 6e 63 44 65 66 2e 70 48 61 73 68 he FuncDef.pHash
8de0: 20 63 68 61 69 6e 2e 0a 2a 2f 0a 73 74 72 75 63 chain..*/.struc
8df0: 74 20 46 75 6e 63 44 65 66 48 61 73 68 20 7b 0a t FuncDefHash {.
8e00: 20 20 46 75 6e 63 44 65 66 20 2a 61 5b 32 33 5d FuncDef *a[23]
8e10: 3b 20 20 20 20 20 20 20 2f 2a 20 48 61 73 68 20 ; /* Hash
8e20: 74 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 69 table for functi
8e30: 6f 6e 73 20 2a 2f 0a 7d 3b 0a 0a 23 69 66 64 65 ons */.};..#ifde
8e40: 66 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 f SQLITE_USER_AU
8e50: 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a 2f 2a 0a THENTICATION./*.
8e60: 2a 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 68 ** Information h
8e70: 65 6c 64 20 69 6e 20 74 68 65 20 22 73 71 6c 69 eld in the "sqli
8e80: 74 65 33 22 20 64 61 74 61 62 61 73 65 20 63 6f te3" database co
8e90: 6e 6e 65 63 74 69 6f 6e 20 6f 62 6a 65 63 74 20 nnection object
8ea0: 61 6e 64 20 75 73 65 64 0a 2a 2a 20 74 6f 20 6d and used.** to m
8eb0: 61 6e 61 67 65 20 75 73 65 72 20 61 75 74 68 65 anage user authe
8ec0: 6e 74 69 63 61 74 69 6f 6e 2e 0a 2a 2f 0a 74 79 ntication..*/.ty
8ed0: 70 65 64 65 66 20 73 74 72 75 63 74 20 73 71 6c pedef struct sql
8ee0: 69 74 65 33 5f 75 73 65 72 61 75 74 68 20 73 71 ite3_userauth sq
8ef0: 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 3b 0a lite3_userauth;.
8f00: 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 5f 75 struct sqlite3_u
8f10: 73 65 72 61 75 74 68 20 7b 0a 20 20 75 38 20 61 serauth {. u8 a
8f20: 75 74 68 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 uthLevel;
8f30: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 /* Cur
8f40: 72 65 6e 74 20 61 75 74 68 65 6e 74 69 63 61 74 rent authenticat
8f50: 69 6f 6e 20 6c 65 76 65 6c 20 2a 2f 0a 20 20 69 ion level */. i
8f60: 6e 74 20 6e 41 75 74 68 50 57 3b 20 20 20 20 20 nt nAuthPW;
8f70: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
8f80: 53 69 7a 65 20 6f 66 20 74 68 65 20 7a 41 75 74 Size of the zAut
8f90: 68 50 57 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a hPW in bytes */.
8fa0: 20 20 63 68 61 72 20 2a 7a 41 75 74 68 50 57 3b char *zAuthPW;
8fb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8fc0: 2f 2a 20 50 61 73 73 77 6f 72 64 20 75 73 65 64 /* Password used
8fd0: 20 74 6f 20 61 75 74 68 65 6e 74 69 63 61 74 65 to authenticate
8fe0: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 41 75 74 */. char *zAut
8ff0: 68 55 73 65 72 3b 20 20 20 20 20 20 20 20 20 20 hUser;
9000: 20 20 20 20 2f 2a 20 55 73 65 72 20 6e 61 6d 65 /* User name
9010: 20 75 73 65 64 20 74 6f 20 61 75 74 68 65 6e 74 used to authent
9020: 69 63 61 74 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 icate */.};../*
9030: 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
9040: 6f 72 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 or sqlite3_usera
9050: 75 74 68 2e 61 75 74 68 4c 65 76 65 6c 20 2a 2f uth.authLevel */
9060: 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 55 .#define UAUTH_U
9070: 6e 6b 6e 6f 77 6e 20 20 20 20 20 30 20 20 20 20 nknown 0
9080: 20 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 74 69 /* Authenticati
9090: 6f 6e 20 6e 6f 74 20 79 65 74 20 63 68 65 63 6b on not yet check
90a0: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 ed */.#define UA
90b0: 55 54 48 5f 46 61 69 6c 20 20 20 20 20 20 20 20 UTH_Fail
90c0: 31 20 20 20 20 20 2f 2a 20 55 73 65 72 20 61 75 1 /* User au
90d0: 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 66 61 69 thentication fai
90e0: 6c 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 led */.#define U
90f0: 41 55 54 48 5f 55 73 65 72 20 20 20 20 20 20 20 AUTH_User
9100: 20 32 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 2 /* Authen
9110: 74 69 63 61 74 65 64 20 61 73 20 61 20 6e 6f 72 ticated as a nor
9120: 6d 61 6c 20 75 73 65 72 20 2a 2f 0a 23 64 65 66 mal user */.#def
9130: 69 6e 65 20 55 41 55 54 48 5f 41 64 6d 69 6e 20 ine UAUTH_Admin
9140: 20 20 20 20 20 20 33 20 20 20 20 20 2f 2a 20 41 3 /* A
9150: 75 74 68 65 6e 74 69 63 61 74 65 64 20 61 73 20 uthenticated as
9160: 61 6e 20 61 64 6d 69 6e 69 73 74 72 61 74 6f 72 an administrator
9170: 20 2a 2f 0a 0a 2f 2a 20 46 75 6e 63 74 69 6f 6e */../* Function
9180: 73 20 75 73 65 64 20 6f 6e 6c 79 20 62 79 20 75 s used only by u
9190: 73 65 72 20 61 75 74 68 6f 72 69 7a 61 74 69 6f ser authorizatio
91a0: 6e 20 6c 6f 67 69 63 20 2a 2f 0a 69 6e 74 20 73 n logic */.int s
91b0: 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 54 61 qlite3UserAuthTa
91c0: 62 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 ble(const char*)
91d0: 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 73 65 ;.int sqlite3Use
91e0: 72 41 75 74 68 43 68 65 63 6b 4c 6f 67 69 6e 28 rAuthCheckLogin(
91f0: 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
9200: 68 61 72 2a 2c 75 38 2a 29 3b 0a 76 6f 69 64 20 har*,u8*);.void
9210: 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 49 sqlite3UserAuthI
9220: 6e 69 74 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 nit(sqlite3*);.v
9230: 6f 69 64 20 73 71 6c 69 74 65 33 43 72 79 70 74 oid sqlite3Crypt
9240: 46 75 6e 63 28 73 71 6c 69 74 65 33 5f 63 6f 6e Func(sqlite3_con
9250: 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 text*,int,sqlite
9260: 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 0a 23 65 6e 3_value**);..#en
9270: 64 69 66 20 2f 2a 20 53 51 4c 49 54 45 5f 55 53 dif /* SQLITE_US
9280: 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f ER_AUTHENTICATIO
9290: 4e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 74 79 70 65 N */../*.** type
92a0: 64 65 66 20 66 6f 72 20 74 68 65 20 61 75 74 68 def for the auth
92b0: 6f 72 69 7a 61 74 69 6f 6e 20 63 61 6c 6c 62 61 orization callba
92c0: 63 6b 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a ck function..*/.
92d0: 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 #ifdef SQLITE_US
92e0: 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f ER_AUTHENTICATIO
92f0: 4e 0a 20 20 74 79 70 65 64 65 66 20 69 6e 74 20 N. typedef int
9300: 28 2a 73 71 6c 69 74 65 33 5f 78 61 75 74 68 29 (*sqlite3_xauth)
9310: 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 (void*,int,const
9320: 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 char*,const cha
9330: 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 0a r*,const char*,.
9340: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9350: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 63 c
9360: 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
9370: 74 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 65 0a t char*);.#else.
9380: 20 20 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a typedef int (*
9390: 73 71 6c 69 74 65 33 5f 78 61 75 74 68 29 28 76 sqlite3_xauth)(v
93a0: 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 oid*,int,const c
93b0: 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
93c0: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 0a 20 20 ,const char*,.
93d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
93e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e con
93f0: 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 st char*);.#endi
9400: 66 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 64 f.../*.** Each d
9410: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
9420: 6f 6e 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 on is an instanc
9430: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
9440: 6e 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f ng structure..*/
9450: 0a 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 20 .struct sqlite3
9460: 7b 0a 20 20 73 71 6c 69 74 65 33 5f 76 66 73 20 {. sqlite3_vfs
9470: 2a 70 56 66 73 3b 20 20 20 20 20 20 20 20 20 20 *pVfs;
9480: 20 20 2f 2a 20 4f 53 20 49 6e 74 65 72 66 61 63 /* OS Interfac
9490: 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 56 64 e */. struct Vd
94a0: 62 65 20 2a 70 56 64 62 65 3b 20 20 20 20 20 20 be *pVdbe;
94b0: 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 /* List of
94c0: 61 63 74 69 76 65 20 76 69 72 74 75 61 6c 20 6d active virtual m
94d0: 61 63 68 69 6e 65 73 20 2a 2f 0a 20 20 43 6f 6c achines */. Col
94e0: 6c 53 65 71 20 2a 70 44 66 6c 74 43 6f 6c 6c 3b lSeq *pDfltColl;
94f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
9500: 65 20 64 65 66 61 75 6c 74 20 63 6f 6c 6c 61 74 e default collat
9510: 69 6e 67 20 73 65 71 75 65 6e 63 65 20 28 42 49 ing sequence (BI
9520: 4e 41 52 59 29 20 2a 2f 0a 20 20 73 71 6c 69 74 NARY) */. sqlit
9530: 65 33 5f 6d 75 74 65 78 20 2a 6d 75 74 65 78 3b e3_mutex *mutex;
9540: 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 6e /* Conn
9550: 65 63 74 69 6f 6e 20 6d 75 74 65 78 20 2a 2f 0a ection mutex */.
9560: 20 20 44 62 20 2a 61 44 62 3b 20 20 20 20 20 20 Db *aDb;
9570: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9580: 2f 2a 20 41 6c 6c 20 62 61 63 6b 65 6e 64 73 20 /* All backends
9590: 2a 2f 0a 20 20 69 6e 74 20 6e 44 62 3b 20 20 20 */. int nDb;
95a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
95b0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
95c0: 62 61 63 6b 65 6e 64 73 20 63 75 72 72 65 6e 74 backends current
95d0: 6c 79 20 69 6e 20 75 73 65 20 2a 2f 0a 20 20 69 ly in use */. i
95e0: 6e 74 20 66 6c 61 67 73 3b 20 20 20 20 20 20 20 nt flags;
95f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9600: 4d 69 73 63 65 6c 6c 61 6e 65 6f 75 73 20 66 6c Miscellaneous fl
9610: 61 67 73 2e 20 53 65 65 20 62 65 6c 6f 77 20 2a ags. See below *
9620: 2f 0a 20 20 69 36 34 20 6c 61 73 74 52 6f 77 69 /. i64 lastRowi
9630: 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 d;
9640: 20 20 2f 2a 20 52 4f 57 49 44 20 6f 66 20 6d 6f /* ROWID of mo
9650: 73 74 20 72 65 63 65 6e 74 20 69 6e 73 65 72 74 st recent insert
9660: 20 28 73 65 65 20 61 62 6f 76 65 29 20 2a 2f 0a (see above) */.
9670: 20 20 69 36 34 20 73 7a 4d 6d 61 70 3b 20 20 20 i64 szMmap;
9680: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9690: 2f 2a 20 44 65 66 61 75 6c 74 20 6d 6d 61 70 5f /* Default mmap_
96a0: 73 69 7a 65 20 73 65 74 74 69 6e 67 20 2a 2f 0a size setting */.
96b0: 20 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6f unsigned int o
96c0: 70 65 6e 46 6c 61 67 73 3b 20 20 20 20 20 20 20 penFlags;
96d0: 2f 2a 20 46 6c 61 67 73 20 70 61 73 73 65 64 20 /* Flags passed
96e0: 74 6f 20 73 71 6c 69 74 65 33 5f 76 66 73 2e 78 to sqlite3_vfs.x
96f0: 4f 70 65 6e 28 29 20 2a 2f 0a 20 20 69 6e 74 20 Open() */. int
9700: 65 72 72 43 6f 64 65 3b 20 20 20 20 20 20 20 20 errCode;
9710: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f 73 /* Mos
9720: 74 20 72 65 63 65 6e 74 20 65 72 72 6f 72 20 63 t recent error c
9730: 6f 64 65 20 28 53 51 4c 49 54 45 5f 2a 29 20 2a ode (SQLITE_*) *
9740: 2f 0a 20 20 69 6e 74 20 65 72 72 4d 61 73 6b 3b /. int errMask;
9750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9760: 20 20 2f 2a 20 26 20 72 65 73 75 6c 74 20 63 6f /* & result co
9770: 64 65 73 20 77 69 74 68 20 74 68 69 73 20 62 65 des with this be
9780: 66 6f 72 65 20 72 65 74 75 72 6e 69 6e 67 20 2a fore returning *
9790: 2f 0a 20 20 75 31 36 20 64 62 4f 70 74 46 6c 61 /. u16 dbOptFla
97a0: 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 gs;
97b0: 20 20 2f 2a 20 46 6c 61 67 73 20 74 6f 20 65 6e /* Flags to en
97c0: 61 62 6c 65 2f 64 69 73 61 62 6c 65 20 6f 70 74 able/disable opt
97d0: 69 6d 69 7a 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 imizations */.
97e0: 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 20 20 u8 enc;
97f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9800: 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 2a Text encoding *
9810: 2f 0a 20 20 75 38 20 61 75 74 6f 43 6f 6d 6d 69 /. u8 autoCommi
9820: 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
9830: 20 20 2f 2a 20 54 68 65 20 61 75 74 6f 2d 63 6f /* The auto-co
9840: 6d 6d 69 74 20 66 6c 61 67 2e 20 2a 2f 0a 20 20 mmit flag. */.
9850: 75 38 20 74 65 6d 70 5f 73 74 6f 72 65 3b 20 20 u8 temp_store;
9860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9870: 20 31 3a 20 66 69 6c 65 20 32 3a 20 6d 65 6d 6f 1: file 2: memo
9880: 72 79 20 30 3a 20 64 65 66 61 75 6c 74 20 2a 2f ry 0: default */
9890: 0a 20 20 75 38 20 6d 61 6c 6c 6f 63 46 61 69 6c . u8 mallocFail
98a0: 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ed;
98b0: 20 2f 2a 20 54 72 75 65 20 69 66 20 77 65 20 68 /* True if we h
98c0: 61 76 65 20 73 65 65 6e 20 61 20 6d 61 6c 6c 6f ave seen a mallo
98d0: 63 20 66 61 69 6c 75 72 65 20 2a 2f 0a 20 20 75 c failure */. u
98e0: 38 20 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 3b 20 8 dfltLockMode;
98f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9900: 44 65 66 61 75 6c 74 20 6c 6f 63 6b 69 6e 67 2d Default locking-
9910: 6d 6f 64 65 20 66 6f 72 20 61 74 74 61 63 68 65 mode for attache
9920: 64 20 64 62 73 20 2a 2f 0a 20 20 73 69 67 6e 65 d dbs */. signe
9930: 64 20 63 68 61 72 20 6e 65 78 74 41 75 74 6f 76 d char nextAutov
9940: 61 63 3b 20 20 20 20 20 20 2f 2a 20 41 75 74 6f ac; /* Auto
9950: 76 61 63 20 73 65 74 74 69 6e 67 20 61 66 74 65 vac setting afte
9960: 72 20 56 41 43 55 55 4d 20 69 66 20 3e 3d 30 20 r VACUUM if >=0
9970: 2a 2f 0a 20 20 75 38 20 73 75 70 70 72 65 73 73 */. u8 suppress
9980: 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 Err;
9990: 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 73 73 /* Do not iss
99a0: 75 65 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 ue error message
99b0: 73 20 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 s if true */. u
99c0: 38 20 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 63 74 8 vtabOnConflict
99d0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
99e0: 56 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 Value to return
99f0: 66 6f 72 20 73 33 5f 76 74 61 62 5f 6f 6e 5f 63 for s3_vtab_on_c
9a00: 6f 6e 66 6c 69 63 74 28 29 20 2a 2f 0a 20 20 75 onflict() */. u
9a10: 38 20 69 73 54 72 61 6e 73 61 63 74 69 6f 6e 53 8 isTransactionS
9a20: 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 2f 2a 20 avepoint; /*
9a30: 54 72 75 65 20 69 66 20 74 68 65 20 6f 75 74 65 True if the oute
9a40: 72 6d 6f 73 74 20 73 61 76 65 70 6f 69 6e 74 20 rmost savepoint
9a50: 69 73 20 61 20 54 53 20 2a 2f 0a 20 20 69 6e 74 is a TS */. int
9a60: 20 6e 65 78 74 50 61 67 65 73 69 7a 65 3b 20 20 nextPagesize;
9a70: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 /* Pa
9a80: 67 65 73 69 7a 65 20 61 66 74 65 72 20 56 41 43 gesize after VAC
9a90: 55 55 4d 20 69 66 20 3e 30 20 2a 2f 0a 20 20 75 UUM if >0 */. u
9aa0: 33 32 20 6d 61 67 69 63 3b 20 20 20 20 20 20 20 32 magic;
9ab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9ac0: 4d 61 67 69 63 20 6e 75 6d 62 65 72 20 66 6f 72 Magic number for
9ad0: 20 64 65 74 65 63 74 20 6c 69 62 72 61 72 79 20 detect library
9ae0: 6d 69 73 75 73 65 20 2a 2f 0a 20 20 69 6e 74 20 misuse */. int
9af0: 6e 43 68 61 6e 67 65 3b 20 20 20 20 20 20 20 20 nChange;
9b00: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c /* Val
9b10: 75 65 20 72 65 74 75 72 6e 65 64 20 62 79 20 73 ue returned by s
9b20: 71 6c 69 74 65 33 5f 63 68 61 6e 67 65 73 28 29 qlite3_changes()
9b30: 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 6f 74 61 6c */. int nTotal
9b40: 43 68 61 6e 67 65 3b 20 20 20 20 20 20 20 20 20 Change;
9b50: 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 72 65 74 /* Value ret
9b60: 75 72 6e 65 64 20 62 79 20 73 71 6c 69 74 65 33 urned by sqlite3
9b70: 5f 74 6f 74 61 6c 5f 63 68 61 6e 67 65 73 28 29 _total_changes()
9b80: 20 2a 2f 0a 20 20 69 6e 74 20 61 4c 69 6d 69 74 */. int aLimit
9b90: 5b 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 54 5d [SQLITE_N_LIMIT]
9ba0: 3b 20 20 20 2f 2a 20 4c 69 6d 69 74 73 20 2a 2f ; /* Limits */
9bb0: 0a 20 20 69 6e 74 20 6e 4d 61 78 53 6f 72 74 65 . int nMaxSorte
9bc0: 72 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 rMmap;
9bd0: 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 73 69 7a 65 /* Maximum size
9be0: 20 6f 66 20 72 65 67 69 6f 6e 73 20 6d 61 70 70 of regions mapp
9bf0: 65 64 20 62 79 20 73 6f 72 74 65 72 20 2a 2f 0a ed by sorter */.
9c00: 20 20 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 struct sqlite3
9c10: 49 6e 69 74 49 6e 66 6f 20 7b 20 20 20 20 20 20 InitInfo {
9c20: 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 /* Information u
9c30: 73 65 64 20 64 75 72 69 6e 67 20 69 6e 69 74 69 sed during initi
9c40: 61 6c 69 7a 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 alization */.
9c50: 20 69 6e 74 20 6e 65 77 54 6e 75 6d 3b 20 20 20 int newTnum;
9c60: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
9c70: 52 6f 6f 74 70 61 67 65 20 6f 66 20 74 61 62 6c Rootpage of tabl
9c80: 65 20 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 e being initiali
9c90: 7a 65 64 20 2a 2f 0a 20 20 20 20 75 38 20 69 44 zed */. u8 iD
9ca0: 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 b;
9cb0: 20 20 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 /* Which
9cc0: 64 62 20 66 69 6c 65 20 69 73 20 62 65 69 6e 67 db file is being
9cd0: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
9ce0: 20 20 20 20 75 38 20 62 75 73 79 3b 20 20 20 20 u8 busy;
9cf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9d00: 2f 2a 20 54 52 55 45 20 69 66 20 63 75 72 72 65 /* TRUE if curre
9d10: 6e 74 6c 79 20 69 6e 69 74 69 61 6c 69 7a 69 6e ntly initializin
9d20: 67 20 2a 2f 0a 20 20 20 20 75 38 20 6f 72 70 68 g */. u8 orph
9d30: 61 6e 54 72 69 67 67 65 72 3b 20 20 20 20 20 20 anTrigger;
9d40: 20 20 20 20 20 2f 2a 20 4c 61 73 74 20 73 74 61 /* Last sta
9d50: 74 65 6d 65 6e 74 20 69 73 20 6f 72 70 68 61 6e tement is orphan
9d60: 65 64 20 54 45 4d 50 20 74 72 69 67 67 65 72 20 ed TEMP trigger
9d70: 2a 2f 0a 20 20 20 20 75 38 20 69 6d 70 6f 73 74 */. u8 impost
9d80: 65 72 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 erTable;
9d90: 20 20 20 2f 2a 20 42 75 69 6c 64 69 6e 67 20 61 /* Building a
9da0: 6e 20 69 6d 70 6f 73 74 65 72 20 74 61 62 6c 65 n imposter table
9db0: 20 2a 2f 0a 20 20 7d 20 69 6e 69 74 3b 0a 20 20 */. } init;.
9dc0: 69 6e 74 20 6e 56 64 62 65 41 63 74 69 76 65 3b int nVdbeActive;
9dd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9de0: 20 4e 75 6d 62 65 72 20 6f 66 20 56 44 42 45 73 Number of VDBEs
9df0: 20 63 75 72 72 65 6e 74 6c 79 20 72 75 6e 6e 69 currently runni
9e00: 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 62 ng */. int nVdb
9e10: 65 52 65 61 64 3b 20 20 20 20 20 20 20 20 20 20 eRead;
9e20: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
9e30: 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 73 20 of active VDBEs
9e40: 74 68 61 74 20 72 65 61 64 20 6f 72 20 77 72 69 that read or wri
9e50: 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 62 te */. int nVdb
9e60: 65 57 72 69 74 65 3b 20 20 20 20 20 20 20 20 20 eWrite;
9e70: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
9e80: 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 73 20 of active VDBEs
9e90: 74 68 61 74 20 72 65 61 64 20 61 6e 64 20 77 72 that read and wr
9ea0: 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 ite */. int nVd
9eb0: 62 65 45 78 65 63 3b 20 20 20 20 20 20 20 20 20 beExec;
9ec0: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
9ed0: 20 6f 66 20 6e 65 73 74 65 64 20 63 61 6c 6c 73 of nested calls
9ee0: 20 74 6f 20 56 64 62 65 45 78 65 63 28 29 20 2a to VdbeExec() *
9ef0: 2f 0a 20 20 69 6e 74 20 6e 56 44 65 73 74 72 6f /. int nVDestro
9f00: 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 y;
9f10: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 /* Number of a
9f20: 63 74 69 76 65 20 4f 50 5f 56 44 65 73 74 72 6f ctive OP_VDestro
9f30: 79 20 6f 70 65 72 61 74 69 6f 6e 73 20 2a 2f 0a y operations */.
9f40: 20 20 69 6e 74 20 6e 45 78 74 65 6e 73 69 6f 6e int nExtension
9f50: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
9f60: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c 6f 61 /* Number of loa
9f70: 64 65 64 20 65 78 74 65 6e 73 69 6f 6e 73 20 2a ded extensions *
9f80: 2f 0a 20 20 76 6f 69 64 20 2a 2a 61 45 78 74 65 /. void **aExte
9f90: 6e 73 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 nsion;
9fa0: 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 73 68 /* Array of sh
9fb0: 61 72 65 64 20 6c 69 62 72 61 72 79 20 68 61 6e ared library han
9fc0: 64 6c 65 73 20 2a 2f 0a 20 20 76 6f 69 64 20 28 dles */. void (
9fd0: 2a 78 54 72 61 63 65 29 28 76 6f 69 64 2a 2c 63 *xTrace)(void*,c
9fe0: 6f 6e 73 74 20 63 68 61 72 2a 29 3b 20 20 20 20 onst char*);
9ff0: 20 20 20 20 2f 2a 20 54 72 61 63 65 20 66 75 6e /* Trace fun
a000: 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 ction */. void
a010: 2a 70 54 72 61 63 65 41 72 67 3b 20 20 20 20 20 *pTraceArg;
a020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a030: 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 /* Argument
a040: 20 74 6f 20 74 68 65 20 74 72 61 63 65 20 66 75 to the trace fu
a050: 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 nction */. void
a060: 20 28 2a 78 50 72 6f 66 69 6c 65 29 28 76 6f 69 (*xProfile)(voi
a070: 64 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 d*,const char*,u
a080: 36 34 29 3b 20 20 2f 2a 20 50 72 6f 66 69 6c 69 64); /* Profili
a090: 6e 67 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 ng function */.
a0a0: 20 76 6f 69 64 20 2a 70 50 72 6f 66 69 6c 65 41 void *pProfileA
a0b0: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
a0c0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
a0d0: 67 75 6d 65 6e 74 20 74 6f 20 70 72 6f 66 69 6c gument to profil
a0e0: 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 e function */.
a0f0: 76 6f 69 64 20 2a 70 43 6f 6d 6d 69 74 41 72 67 void *pCommitArg
a100: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
a110: 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f /* Argument to
a120: 20 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b xCommitCallback
a130: 28 29 20 2a 2f 20 20 20 0a 20 20 69 6e 74 20 28 () */ . int (
a140: 2a 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b *xCommitCallback
a150: 29 28 76 6f 69 64 2a 29 3b 20 20 20 20 2f 2a 20 )(void*); /*
a160: 49 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 Invoked at every
a170: 20 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f commit. */. vo
a180: 69 64 20 2a 70 52 6f 6c 6c 62 61 63 6b 41 72 67 id *pRollbackArg
a190: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
a1a0: 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 /* Argument to x
a1b0: 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 6b RollbackCallback
a1c0: 28 29 20 2a 2f 20 20 20 0a 20 20 76 6f 69 64 20 () */ . void
a1d0: 28 2a 78 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 (*xRollbackCallb
a1e0: 61 63 6b 29 28 76 6f 69 64 2a 29 3b 20 2f 2a 20 ack)(void*); /*
a1f0: 49 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 Invoked at every
a200: 20 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f commit. */. vo
a210: 69 64 20 2a 70 55 70 64 61 74 65 41 72 67 3b 0a id *pUpdateArg;.
a220: 20 20 76 6f 69 64 20 28 2a 78 55 70 64 61 74 65 void (*xUpdate
a230: 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 2c Callback)(void*,
a240: 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a int, const char*
a250: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 73 71 6c ,const char*,sql
a260: 69 74 65 5f 69 6e 74 36 34 29 3b 0a 23 69 66 6e ite_int64);.#ifn
a270: 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
a280: 57 41 4c 0a 20 20 69 6e 74 20 28 2a 78 57 61 6c WAL. int (*xWal
a290: 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 20 2a Callback)(void *
a2a0: 2c 20 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e , sqlite3 *, con
a2b0: 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b st char *, int);
a2c0: 0a 20 20 76 6f 69 64 20 2a 70 57 61 6c 41 72 67 . void *pWalArg
a2d0: 3b 0a 23 65 6e 64 69 66 0a 20 20 76 6f 69 64 28 ;.#endif. void(
a2e0: 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 29 28 76 6f *xCollNeeded)(vo
a2f0: 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 6e 74 id*,sqlite3*,int
a300: 20 65 54 65 78 74 52 65 70 2c 63 6f 6e 73 74 20 eTextRep,const
a310: 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 28 2a char*);. void(*
a320: 78 43 6f 6c 6c 4e 65 65 64 65 64 31 36 29 28 76 xCollNeeded16)(v
a330: 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 6e oid*,sqlite3*,in
a340: 74 20 65 54 65 78 74 52 65 70 2c 63 6f 6e 73 74 t eTextRep,const
a350: 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 64 20 void*);. void
a360: 2a 70 43 6f 6c 6c 4e 65 65 64 65 64 41 72 67 3b *pCollNeededArg;
a370: 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 . sqlite3_value
a380: 20 2a 70 45 72 72 3b 20 20 20 20 20 20 20 20 20 *pErr;
a390: 20 2f 2a 20 4d 6f 73 74 20 72 65 63 65 6e 74 20 /* Most recent
a3a0: 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f error message */
a3b0: 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 76 . union {. v
a3c0: 6f 6c 61 74 69 6c 65 20 69 6e 74 20 69 73 49 6e olatile int isIn
a3d0: 74 65 72 72 75 70 74 65 64 3b 20 2f 2a 20 54 72 terrupted; /* Tr
a3e0: 75 65 20 69 66 20 73 71 6c 69 74 65 33 5f 69 6e ue if sqlite3_in
a3f0: 74 65 72 72 75 70 74 20 68 61 73 20 62 65 65 6e terrupt has been
a400: 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 20 20 64 called */. d
a410: 6f 75 62 6c 65 20 6e 6f 74 55 73 65 64 31 3b 20 ouble notUsed1;
a420: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 70 /* Sp
a430: 61 63 65 72 20 2a 2f 0a 20 20 7d 20 75 31 3b 0a acer */. } u1;.
a440: 20 20 4c 6f 6f 6b 61 73 69 64 65 20 6c 6f 6f 6b Lookaside look
a450: 61 73 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 aside;
a460: 2f 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c /* Lookaside mal
a470: 6c 6f 63 20 63 6f 6e 66 69 67 75 72 61 74 69 6f loc configuratio
a480: 6e 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c n */.#ifndef SQL
a490: 49 54 45 5f 4f 4d 49 54 5f 41 55 54 48 4f 52 49 ITE_OMIT_AUTHORI
a4a0: 5a 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 65 33 ZATION. sqlite3
a4b0: 5f 78 61 75 74 68 20 78 41 75 74 68 3b 20 20 20 _xauth xAuth;
a4c0: 20 20 20 20 20 20 20 2f 2a 20 41 63 63 65 73 73 /* Access
a4d0: 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 66 authorization f
a4e0: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 unction */. voi
a4f0: 64 20 2a 70 41 75 74 68 41 72 67 3b 20 20 20 20 d *pAuthArg;
a500: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 73 /* 1s
a510: 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 t argument to th
a520: 65 20 61 63 63 65 73 73 20 61 75 74 68 20 66 75 e access auth fu
a530: 6e 63 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 nction */.#endif
a540: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
a550: 4f 4d 49 54 5f 50 52 4f 47 52 45 53 53 5f 43 41 OMIT_PROGRESS_CA
a560: 4c 4c 42 41 43 4b 0a 20 20 69 6e 74 20 28 2a 78 LLBACK. int (*x
a570: 50 72 6f 67 72 65 73 73 29 28 76 6f 69 64 20 2a Progress)(void *
a580: 29 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 70 72 ); /* The pr
a590: 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 ogress callback
a5a0: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f 67 */. void *pProg
a5b0: 72 65 73 73 41 72 67 3b 20 20 20 20 20 20 20 20 ressArg;
a5c0: 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 /* Argument t
a5d0: 6f 20 74 68 65 20 70 72 6f 67 72 65 73 73 20 63 o the progress c
a5e0: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 75 6e 73 allback */. uns
a5f0: 69 67 6e 65 64 20 6e 50 72 6f 67 72 65 73 73 4f igned nProgressO
a600: 70 73 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ps; /* Nu
a610: 6d 62 65 72 20 6f 66 20 6f 70 63 6f 64 65 73 20 mber of opcodes
a620: 66 6f 72 20 70 72 6f 67 72 65 73 73 20 63 61 6c for progress cal
a630: 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 0a lback */.#endif.
a640: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
a650: 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
a660: 0a 20 20 69 6e 74 20 6e 56 54 72 61 6e 73 3b 20 . int nVTrans;
a670: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a680: 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 64 20 73 69 /* Allocated si
a690: 7a 65 20 6f 66 20 61 56 54 72 61 6e 73 20 2a 2f ze of aVTrans */
a6a0: 0a 20 20 48 61 73 68 20 61 4d 6f 64 75 6c 65 3b . Hash aModule;
a6b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a6c0: 20 2f 2a 20 70 6f 70 75 6c 61 74 65 64 20 62 79 /* populated by
a6d0: 20 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f sqlite3_create_
a6e0: 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 56 74 module() */. Vt
a6f0: 61 62 43 74 78 20 2a 70 56 74 61 62 43 74 78 3b abCtx *pVtabCtx;
a700: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
a710: 6f 6e 74 65 78 74 20 66 6f 72 20 61 63 74 69 76 ontext for activ
a720: 65 20 76 74 61 62 20 63 6f 6e 6e 65 63 74 2f 63 e vtab connect/c
a730: 72 65 61 74 65 20 2a 2f 0a 20 20 56 54 61 62 6c reate */. VTabl
a740: 65 20 2a 2a 61 56 54 72 61 6e 73 3b 20 20 20 20 e **aVTrans;
a750: 20 20 20 20 20 20 20 20 20 2f 2a 20 56 69 72 74 /* Virt
a760: 75 61 6c 20 74 61 62 6c 65 73 20 77 69 74 68 20 ual tables with
a770: 6f 70 65 6e 20 74 72 61 6e 73 61 63 74 69 6f 6e open transaction
a780: 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 s */. VTable *p
a790: 44 69 73 63 6f 6e 6e 65 63 74 3b 20 20 20 20 2f Disconnect; /
a7a0: 2a 20 44 69 73 63 6f 6e 6e 65 63 74 20 74 68 65 * Disconnect the
a7b0: 73 65 20 69 6e 20 6e 65 78 74 20 73 71 6c 69 74 se in next sqlit
a7c0: 65 33 5f 70 72 65 70 61 72 65 28 29 20 2a 2f 0a e3_prepare() */.
a7d0: 23 65 6e 64 69 66 0a 20 20 46 75 6e 63 44 65 66 #endif. FuncDef
a7e0: 48 61 73 68 20 61 46 75 6e 63 3b 20 20 20 20 20 Hash aFunc;
a7f0: 20 20 20 20 20 20 20 2f 2a 20 48 61 73 68 20 74 /* Hash t
a800: 61 62 6c 65 20 6f 66 20 63 6f 6e 6e 65 63 74 69 able of connecti
a810: 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a on functions */.
a820: 20 20 48 61 73 68 20 61 43 6f 6c 6c 53 65 71 3b Hash aCollSeq;
a830: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a840: 2f 2a 20 41 6c 6c 20 63 6f 6c 6c 61 74 69 6e 67 /* All collating
a850: 20 73 65 71 75 65 6e 63 65 73 20 2a 2f 0a 20 20 sequences */.
a860: 42 75 73 79 48 61 6e 64 6c 65 72 20 62 75 73 79 BusyHandler busy
a870: 48 61 6e 64 6c 65 72 3b 20 20 20 20 20 20 2f 2a Handler; /*
a880: 20 42 75 73 79 20 63 61 6c 6c 62 61 63 6b 20 2a Busy callback *
a890: 2f 0a 20 20 44 62 20 61 44 62 53 74 61 74 69 63 /. Db aDbStatic
a8a0: 5b 32 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 [2];
a8b0: 20 20 2f 2a 20 53 74 61 74 69 63 20 73 70 61 63 /* Static spac
a8c0: 65 20 66 6f 72 20 74 68 65 20 32 20 64 65 66 61 e for the 2 defa
a8d0: 75 6c 74 20 62 61 63 6b 65 6e 64 73 20 2a 2f 0a ult backends */.
a8e0: 20 20 53 61 76 65 70 6f 69 6e 74 20 2a 70 53 61 Savepoint *pSa
a8f0: 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 vepoint;
a900: 2f 2a 20 4c 69 73 74 20 6f 66 20 61 63 74 69 76 /* List of activ
a910: 65 20 73 61 76 65 70 6f 69 6e 74 73 20 2a 2f 0a e savepoints */.
a920: 20 20 69 6e 74 20 62 75 73 79 54 69 6d 65 6f 75 int busyTimeou
a930: 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
a940: 2f 2a 20 42 75 73 79 20 68 61 6e 64 6c 65 72 20 /* Busy handler
a950: 74 69 6d 65 6f 75 74 2c 20 69 6e 20 6d 73 65 63 timeout, in msec
a960: 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 76 65 70 */. int nSavep
a970: 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 oint;
a980: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
a990: 20 6e 6f 6e 2d 74 72 61 6e 73 61 63 74 69 6f 6e non-transaction
a9a0: 20 73 61 76 65 70 6f 69 6e 74 73 20 2a 2f 0a 20 savepoints */.
a9b0: 20 69 6e 74 20 6e 53 74 61 74 65 6d 65 6e 74 3b int nStatement;
a9c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
a9d0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 * Number of nest
a9e0: 65 64 20 73 74 61 74 65 6d 65 6e 74 2d 74 72 61 ed statement-tra
a9f0: 6e 73 61 63 74 69 6f 6e 73 20 20 2a 2f 0a 20 20 nsactions */.
aa00: 69 36 34 20 6e 44 65 66 65 72 72 65 64 43 6f 6e i64 nDeferredCon
aa10: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a s; /*
aa20: 20 4e 65 74 20 64 65 66 65 72 72 65 64 20 63 6f Net deferred co
aa30: 6e 73 74 72 61 69 6e 74 73 20 74 68 69 73 20 74 nstraints this t
aa40: 72 61 6e 73 61 63 74 69 6f 6e 2e 20 2a 2f 0a 20 ransaction. */.
aa50: 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d i64 nDeferredIm
aa60: 6d 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 2f mCons; /
aa70: 2a 20 4e 65 74 20 64 65 66 65 72 72 65 64 20 69 * Net deferred i
aa80: 6d 6d 65 64 69 61 74 65 20 63 6f 6e 73 74 72 61 mmediate constra
aa90: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 2a 70 ints */. int *p
aaa0: 6e 42 79 74 65 73 46 72 65 65 64 3b 20 20 20 20 nBytesFreed;
aab0: 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f /* If no
aac0: 74 20 4e 55 4c 4c 2c 20 69 6e 63 72 65 6d 65 6e t NULL, incremen
aad0: 74 20 74 68 69 73 20 69 6e 20 44 62 46 72 65 65 t this in DbFree
aae0: 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c () */.#ifdef SQL
aaf0: 49 54 45 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f 43 ITE_ENABLE_UNLOC
ab00: 4b 5f 4e 4f 54 49 46 59 0a 20 20 2f 2a 20 54 68 K_NOTIFY. /* Th
ab10: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 72 69 e following vari
ab20: 61 62 6c 65 73 20 61 72 65 20 61 6c 6c 20 70 72 ables are all pr
ab30: 6f 74 65 63 74 65 64 20 62 79 20 74 68 65 20 53 otected by the S
ab40: 54 41 54 49 43 5f 4d 41 53 54 45 52 20 0a 20 20 TATIC_MASTER .
ab50: 2a 2a 20 6d 75 74 65 78 2c 20 6e 6f 74 20 62 79 ** mutex, not by
ab60: 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 78 2e 20 sqlite3.mutex.
ab70: 54 68 65 79 20 61 72 65 20 75 73 65 64 20 62 79 They are used by
ab80: 20 63 6f 64 65 20 69 6e 20 6e 6f 74 69 66 79 2e code in notify.
ab90: 63 2e 20 0a 20 20 2a 2a 0a 20 20 2a 2a 20 57 68 c. . **. ** Wh
aba0: 65 6e 20 58 2e 70 55 6e 6c 6f 63 6b 43 6f 6e 6e en X.pUnlockConn
abb0: 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 68 61 74 20 ection==Y, that
abc0: 6d 65 61 6e 73 20 74 68 61 74 20 58 20 69 73 20 means that X is
abd0: 77 61 69 74 69 6e 67 20 66 6f 72 20 59 20 74 6f waiting for Y to
abe0: 0a 20 20 2a 2a 20 75 6e 6c 6f 63 6b 20 73 6f 20 . ** unlock so
abf0: 74 68 61 74 20 69 74 20 63 61 6e 20 70 72 6f 63 that it can proc
ac00: 65 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a 20 57 eed.. **. ** W
ac10: 68 65 6e 20 58 2e 70 42 6c 6f 63 6b 69 6e 67 43 hen X.pBlockingC
ac20: 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 68 onnection==Y, th
ac30: 61 74 20 6d 65 61 6e 73 20 74 68 61 74 20 73 6f at means that so
ac40: 6d 65 74 68 69 6e 67 20 74 68 61 74 20 58 20 74 mething that X t
ac50: 72 69 65 64 0a 20 20 2a 2a 20 74 72 69 65 64 20 ried. ** tried
ac60: 74 6f 20 64 6f 20 72 65 63 65 6e 74 6c 79 20 66 to do recently f
ac70: 61 69 6c 65 64 20 77 69 74 68 20 61 6e 20 53 51 ailed with an SQ
ac80: 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 65 72 72 6f LITE_LOCKED erro
ac90: 72 20 64 75 65 20 74 6f 20 6c 6f 63 6b 73 0a 20 r due to locks.
aca0: 20 2a 2a 20 68 65 6c 64 20 62 79 20 59 2e 0a 20 ** held by Y..
acb0: 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 */. sqlite3 *p
acc0: 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 BlockingConnecti
acd0: 6f 6e 3b 20 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f on; /* Connectio
ace0: 6e 20 74 68 61 74 20 63 61 75 73 65 64 20 53 51 n that caused SQ
acf0: 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 2a 2f 0a 20 LITE_LOCKED */.
ad00: 20 73 71 6c 69 74 65 33 20 2a 70 55 6e 6c 6f 63 sqlite3 *pUnloc
ad10: 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 20 20 20 kConnection;
ad20: 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 6e 65 63 /* Connec
ad30: 74 69 6f 6e 20 74 6f 20 77 61 74 63 68 20 66 6f tion to watch fo
ad40: 72 20 75 6e 6c 6f 63 6b 20 2a 2f 0a 20 20 76 6f r unlock */. vo
ad50: 69 64 20 2a 70 55 6e 6c 6f 63 6b 41 72 67 3b 20 id *pUnlockArg;
ad60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ad70: 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 /* Argument
ad80: 74 6f 20 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 79 to xUnlockNotify
ad90: 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 55 6e */. void (*xUn
ada0: 6c 6f 63 6b 4e 6f 74 69 66 79 29 28 76 6f 69 64 lockNotify)(void
adb0: 20 2a 2a 2c 20 69 6e 74 29 3b 20 20 2f 2a 20 55 **, int); /* U
adc0: 6e 6c 6f 63 6b 20 6e 6f 74 69 66 79 20 63 61 6c nlock notify cal
add0: 6c 62 61 63 6b 20 2a 2f 0a 20 20 73 71 6c 69 74 lback */. sqlit
ade0: 65 33 20 2a 70 4e 65 78 74 42 6c 6f 63 6b 65 64 e3 *pNextBlocked
adf0: 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 ; /* Next
ae00: 20 69 6e 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 in list of all
ae10: 62 6c 6f 63 6b 65 64 20 63 6f 6e 6e 65 63 74 69 blocked connecti
ae20: 6f 6e 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 ons */.#endif.#i
ae30: 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 52 fdef SQLITE_USER
ae40: 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a _AUTHENTICATION.
ae50: 20 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 sqlite3_userau
ae60: 74 68 20 61 75 74 68 3b 20 20 20 20 20 20 20 20 th auth;
ae70: 2f 2a 20 55 73 65 72 20 61 75 74 68 65 6e 74 69 /* User authenti
ae80: 63 61 74 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 cation informati
ae90: 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 7d 3b 0a on */.#endif.};.
aea0: 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 72 6f 20 74 ./*.** A macro t
aeb0: 6f 20 64 69 73 63 6f 76 65 72 20 74 68 65 20 65 o discover the e
aec0: 6e 63 6f 64 69 6e 67 20 6f 66 20 61 20 64 61 74 ncoding of a dat
aed0: 61 62 61 73 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e abase..*/.#defin
aee0: 65 20 53 43 48 45 4d 41 5f 45 4e 43 28 64 62 29 e SCHEMA_ENC(db)
aef0: 20 28 28 64 62 29 2d 3e 61 44 62 5b 30 5d 2e 70 ((db)->aDb[0].p
af00: 53 63 68 65 6d 61 2d 3e 65 6e 63 29 0a 23 64 65 Schema->enc).#de
af10: 66 69 6e 65 20 45 4e 43 28 64 62 29 20 20 20 20 fine ENC(db)
af20: 20 20 20 20 28 28 64 62 29 2d 3e 65 6e 63 29 0a ((db)->enc).
af30: 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 20 ./*.** Possible
af40: 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 73 values for the s
af50: 71 6c 69 74 65 33 2e 66 6c 61 67 73 2e 0a 2a 2f qlite3.flags..*/
af60: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
af70: 56 64 62 65 54 72 61 63 65 20 20 20 20 20 20 30 VdbeTrace 0
af80: 78 30 30 30 30 30 30 30 31 20 20 2f 2a 20 54 72 x00000001 /* Tr
af90: 75 65 20 74 6f 20 74 72 61 63 65 20 56 44 42 45 ue to trace VDBE
afa0: 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a 23 64 execution */.#d
afb0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 6e 74 efine SQLITE_Int
afc0: 65 72 6e 43 68 61 6e 67 65 73 20 20 30 78 30 30 ernChanges 0x00
afd0: 30 30 30 30 30 32 20 20 2f 2a 20 55 6e 63 6f 6d 000002 /* Uncom
afe0: 6d 69 74 74 65 64 20 48 61 73 68 20 74 61 62 6c mitted Hash tabl
aff0: 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 65 e changes */.#de
b000: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c fine SQLITE_Full
b010: 46 53 79 6e 63 20 20 20 20 20 20 30 78 30 30 30 FSync 0x000
b020: 30 30 30 30 34 20 20 2f 2a 20 55 73 65 20 66 75 00004 /* Use fu
b030: 6c 6c 20 66 73 79 6e 63 20 6f 6e 20 74 68 65 20 ll fsync on the
b040: 62 61 63 6b 65 6e 64 20 2a 2f 0a 23 64 65 66 69 backend */.#defi
b050: 6e 65 20 53 51 4c 49 54 45 5f 43 6b 70 74 46 75 ne SQLITE_CkptFu
b060: 6c 6c 46 53 79 6e 63 20 20 30 78 30 30 30 30 30 llFSync 0x00000
b070: 30 30 38 20 20 2f 2a 20 55 73 65 20 66 75 6c 6c 008 /* Use full
b080: 20 66 73 79 6e 63 20 66 6f 72 20 63 68 65 63 6b fsync for check
b090: 70 6f 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 point */.#define
b0a0: 20 53 51 4c 49 54 45 5f 43 61 63 68 65 53 70 69 SQLITE_CacheSpi
b0b0: 6c 6c 20 20 20 20 20 30 78 30 30 30 30 30 30 31 ll 0x0000001
b0c0: 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 73 70 69 6c 0 /* OK to spil
b0d0: 6c 20 70 61 67 65 72 20 63 61 63 68 65 20 2a 2f l pager cache */
b0e0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b0f0: 46 75 6c 6c 43 6f 6c 4e 61 6d 65 73 20 20 20 30 FullColNames 0
b100: 78 30 30 30 30 30 30 32 30 20 20 2f 2a 20 53 68 x00000020 /* Sh
b110: 6f 77 20 66 75 6c 6c 20 63 6f 6c 75 6d 6e 20 6e ow full column n
b120: 61 6d 65 73 20 6f 6e 20 53 45 4c 45 43 54 20 2a ames on SELECT *
b130: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
b140: 5f 53 68 6f 72 74 43 6f 6c 4e 61 6d 65 73 20 20 _ShortColNames
b150: 30 78 30 30 30 30 30 30 34 30 20 20 2f 2a 20 53 0x00000040 /* S
b160: 68 6f 77 20 73 68 6f 72 74 20 63 6f 6c 75 6d 6e how short column
b170: 73 20 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 s names */.#defi
b180: 6e 65 20 53 51 4c 49 54 45 5f 43 6f 75 6e 74 52 ne SQLITE_CountR
b190: 6f 77 73 20 20 20 20 20 20 30 78 30 30 30 30 30 ows 0x00000
b1a0: 30 38 30 20 20 2f 2a 20 43 6f 75 6e 74 20 72 6f 080 /* Count ro
b1b0: 77 73 20 63 68 61 6e 67 65 64 20 62 79 20 49 4e ws changed by IN
b1c0: 53 45 52 54 2c 20 2a 2f 0a 20 20 20 20 20 20 20 SERT, */.
b1d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b1e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b1f0: 20 20 20 2f 2a 20 20 20 44 45 4c 45 54 45 2c 20 /* DELETE,
b200: 6f 72 20 55 50 44 41 54 45 20 61 6e 64 20 72 65 or UPDATE and re
b210: 74 75 72 6e 20 2a 2f 0a 20 20 20 20 20 20 20 20 turn */.
b220: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b230: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b240: 20 20 2f 2a 20 20 20 74 68 65 20 63 6f 75 6e 74 /* the count
b250: 20 75 73 69 6e 67 20 61 20 63 61 6c 6c 62 61 63 using a callbac
b260: 6b 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 k. */.#define SQ
b270: 4c 49 54 45 5f 4e 75 6c 6c 43 61 6c 6c 62 61 63 LITE_NullCallbac
b280: 6b 20 20 20 30 78 30 30 30 30 30 31 30 30 20 20 k 0x00000100
b290: 2f 2a 20 49 6e 76 6f 6b 65 20 74 68 65 20 63 61 /* Invoke the ca
b2a0: 6c 6c 62 61 63 6b 20 6f 6e 63 65 20 69 66 20 74 llback once if t
b2b0: 68 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 he */.
b2c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b2d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b2e0: 2f 2a 20 20 20 72 65 73 75 6c 74 20 73 65 74 20 /* result set
b2f0: 69 73 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 is empty */.#def
b300: 69 6e 65 20 53 51 4c 49 54 45 5f 53 71 6c 54 72 ine SQLITE_SqlTr
b310: 61 63 65 20 20 20 20 20 20 20 30 78 30 30 30 30 ace 0x0000
b320: 30 32 30 30 20 20 2f 2a 20 44 65 62 75 67 20 70 0200 /* Debug p
b330: 72 69 6e 74 20 53 51 4c 20 61 73 20 69 74 20 65 rint SQL as it e
b340: 78 65 63 75 74 65 73 20 2a 2f 0a 23 64 65 66 69 xecutes */.#defi
b350: 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 4c 69 ne SQLITE_VdbeLi
b360: 73 74 69 6e 67 20 20 20 20 30 78 30 30 30 30 30 sting 0x00000
b370: 34 30 30 20 20 2f 2a 20 44 65 62 75 67 20 6c 69 400 /* Debug li
b380: 73 74 69 6e 67 73 20 6f 66 20 56 44 42 45 20 70 stings of VDBE p
b390: 72 6f 67 72 61 6d 73 20 2a 2f 0a 23 64 65 66 69 rograms */.#defi
b3a0: 6e 65 20 53 51 4c 49 54 45 5f 57 72 69 74 65 53 ne SQLITE_WriteS
b3b0: 63 68 65 6d 61 20 20 20 20 30 78 30 30 30 30 30 chema 0x00000
b3c0: 38 30 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 75 70 800 /* OK to up
b3d0: 64 61 74 65 20 53 51 4c 49 54 45 5f 4d 41 53 54 date SQLITE_MAST
b3e0: 45 52 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ER */.#define SQ
b3f0: 4c 49 54 45 5f 56 64 62 65 41 64 64 6f 70 54 72 LITE_VdbeAddopTr
b400: 61 63 65 20 30 78 30 30 30 30 31 30 30 30 20 20 ace 0x00001000
b410: 2f 2a 20 54 72 61 63 65 20 73 71 6c 69 74 65 33 /* Trace sqlite3
b420: 56 64 62 65 41 64 64 4f 70 28 29 20 63 61 6c 6c VdbeAddOp() call
b430: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
b440: 49 54 45 5f 49 67 6e 6f 72 65 43 68 65 63 6b 73 ITE_IgnoreChecks
b450: 20 20 20 30 78 30 30 30 30 32 30 30 30 20 20 2f 0x00002000 /
b460: 2a 20 44 6f 20 6e 6f 74 20 65 6e 66 6f 72 63 65 * Do not enforce
b470: 20 63 68 65 63 6b 20 63 6f 6e 73 74 72 61 69 6e check constrain
b480: 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ts */.#define SQ
b490: 4c 49 54 45 5f 52 65 61 64 55 6e 63 6f 6d 6d 69 LITE_ReadUncommi
b4a0: 74 74 65 64 20 30 78 30 30 30 34 30 30 30 20 20 tted 0x0004000
b4b0: 2f 2a 20 46 6f 72 20 73 68 61 72 65 64 2d 63 61 /* For shared-ca
b4c0: 63 68 65 20 6d 6f 64 65 20 2a 2f 0a 23 64 65 66 che mode */.#def
b4d0: 69 6e 65 20 53 51 4c 49 54 45 5f 4c 65 67 61 63 ine SQLITE_Legac
b4e0: 79 46 69 6c 65 46 6d 74 20 20 30 78 30 30 30 30 yFileFmt 0x0000
b4f0: 38 30 30 30 20 20 2f 2a 20 43 72 65 61 74 65 20 8000 /* Create
b500: 6e 65 77 20 64 61 74 61 62 61 73 65 73 20 69 6e new databases in
b510: 20 66 6f 72 6d 61 74 20 31 20 2a 2f 0a 23 64 65 format 1 */.#de
b520: 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 63 6f fine SQLITE_Reco
b530: 76 65 72 79 4d 6f 64 65 20 20 20 30 78 30 30 30 veryMode 0x000
b540: 31 30 30 30 30 20 20 2f 2a 20 49 67 6e 6f 72 65 10000 /* Ignore
b550: 20 73 63 68 65 6d 61 20 65 72 72 6f 72 73 20 2a schema errors *
b560: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
b570: 5f 52 65 76 65 72 73 65 4f 72 64 65 72 20 20 20 _ReverseOrder
b580: 30 78 30 30 30 32 30 30 30 30 20 20 2f 2a 20 52 0x00020000 /* R
b590: 65 76 65 72 73 65 20 75 6e 6f 72 64 65 72 65 64 everse unordered
b5a0: 20 53 45 4c 45 43 54 73 20 2a 2f 0a 23 64 65 66 SELECTs */.#def
b5b0: 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 63 54 72 ine SQLITE_RecTr
b5c0: 69 67 67 65 72 73 20 20 20 20 30 78 30 30 30 34 iggers 0x0004
b5d0: 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 0000 /* Enable
b5e0: 72 65 63 75 72 73 69 76 65 20 74 72 69 67 67 65 recursive trigge
b5f0: 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 rs */.#define SQ
b600: 4c 49 54 45 5f 46 6f 72 65 69 67 6e 4b 65 79 73 LITE_ForeignKeys
b610: 20 20 20 20 30 78 30 30 30 38 30 30 30 30 20 20 0x00080000
b620: 2f 2a 20 45 6e 66 6f 72 63 65 20 66 6f 72 65 69 /* Enforce forei
b630: 67 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 69 6e gn key constrain
b640: 74 73 20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ts */.#define S
b650: 51 4c 49 54 45 5f 41 75 74 6f 49 6e 64 65 78 20 QLITE_AutoIndex
b660: 20 20 20 20 20 30 78 30 30 31 30 30 30 30 30 20 0x00100000
b670: 20 2f 2a 20 45 6e 61 62 6c 65 20 61 75 74 6f 6d /* Enable autom
b680: 61 74 69 63 20 69 6e 64 65 78 65 73 20 2a 2f 0a atic indexes */.
b690: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 #define SQLITE_P
b6a0: 72 65 66 65 72 42 75 69 6c 74 69 6e 20 20 30 78 referBuiltin 0x
b6b0: 30 30 32 30 30 30 30 30 20 20 2f 2a 20 50 72 65 00200000 /* Pre
b6c0: 66 65 72 65 6e 63 65 20 74 6f 20 62 75 69 6c 74 ference to built
b6d0: 2d 69 6e 20 66 75 6e 63 73 20 2a 2f 0a 23 64 65 -in funcs */.#de
b6e0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 6f 61 64 fine SQLITE_Load
b6f0: 45 78 74 65 6e 73 69 6f 6e 20 20 30 78 30 30 34 Extension 0x004
b700: 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 00000 /* Enable
b710: 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 20 load_extension
b720: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b730: 45 5f 45 6e 61 62 6c 65 54 72 69 67 67 65 72 20 E_EnableTrigger
b740: 20 30 78 30 30 38 30 30 30 30 30 20 20 2f 2a 20 0x00800000 /*
b750: 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 74 True to enable t
b760: 72 69 67 67 65 72 73 20 2a 2f 0a 23 64 65 66 69 riggers */.#defi
b770: 6e 65 20 53 51 4c 49 54 45 5f 44 65 66 65 72 46 ne SQLITE_DeferF
b780: 4b 73 20 20 20 20 20 20 20 30 78 30 31 30 30 30 Ks 0x01000
b790: 30 30 30 20 20 2f 2a 20 44 65 66 65 72 20 61 6c 000 /* Defer al
b7a0: 6c 20 46 4b 20 63 6f 6e 73 74 72 61 69 6e 74 73 l FK constraints
b7b0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b7c0: 54 45 5f 51 75 65 72 79 4f 6e 6c 79 20 20 20 20 TE_QueryOnly
b7d0: 20 20 30 78 30 32 30 30 30 30 30 30 20 20 2f 2a 0x02000000 /*
b7e0: 20 44 69 73 61 62 6c 65 20 64 61 74 61 62 61 73 Disable databas
b7f0: 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 65 e changes */.#de
b800: 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 fine SQLITE_Vdbe
b810: 45 51 50 20 20 20 20 20 20 20 20 30 78 30 34 30 EQP 0x040
b820: 30 30 30 30 30 20 20 2f 2a 20 44 65 62 75 67 20 00000 /* Debug
b830: 45 58 50 4c 41 49 4e 20 51 55 45 52 59 20 50 4c EXPLAIN QUERY PL
b840: 41 4e 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 42 69 AN */.../*.** Bi
b850: 74 73 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 ts of the sqlite
b860: 33 2e 64 62 4f 70 74 46 6c 61 67 73 20 66 69 65 3.dbOptFlags fie
b870: 6c 64 20 74 68 61 74 20 61 72 65 20 75 73 65 64 ld that are used
b880: 20 62 79 20 74 68 65 0a 2a 2a 20 73 71 6c 69 74 by the.** sqlit
b890: 65 33 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 e3_test_control(
b8a0: 53 51 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f SQLITE_TESTCTRL_
b8b0: 4f 50 54 49 4d 49 5a 41 54 49 4f 4e 53 2c 2e 2e OPTIMIZATIONS,..
b8c0: 2e 29 20 69 6e 74 65 72 66 61 63 65 20 74 6f 0a .) interface to.
b8d0: 2a 2a 20 73 65 6c 65 63 74 69 76 65 6c 79 20 64 ** selectively d
b8e0: 69 73 61 62 6c 65 20 76 61 72 69 6f 75 73 20 6f isable various o
b8f0: 70 74 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2f ptimizations..*/
b900: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b910: 51 75 65 72 79 46 6c 61 74 74 65 6e 65 72 20 30 QueryFlattener 0
b920: 78 30 30 30 31 20 20 20 2f 2a 20 51 75 65 72 79 x0001 /* Query
b930: 20 66 6c 61 74 74 65 6e 69 6e 67 20 2a 2f 0a 23 flattening */.#
b940: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f define SQLITE_Co
b950: 6c 75 6d 6e 43 61 63 68 65 20 20 20 20 30 78 30 lumnCache 0x0
b960: 30 30 32 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 002 /* Column
b970: 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 cache */.#define
b980: 20 53 51 4c 49 54 45 5f 47 72 6f 75 70 42 79 4f SQLITE_GroupByO
b990: 72 64 65 72 20 20 20 30 78 30 30 30 34 20 20 20 rder 0x0004
b9a0: 2f 2a 20 47 52 4f 55 50 42 59 20 63 6f 76 65 72 /* GROUPBY cover
b9b0: 20 6f 66 20 4f 52 44 45 52 42 59 20 2a 2f 0a 23 of ORDERBY */.#
b9c0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 61 define SQLITE_Fa
b9d0: 63 74 6f 72 4f 75 74 43 6f 6e 73 74 20 30 78 30 ctorOutConst 0x0
b9e0: 30 30 38 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e 008 /* Constan
b9f0: 74 20 66 61 63 74 6f 72 69 6e 67 20 2a 2f 0a 2f t factoring */./
ba00: 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
ba10: 20 6e 6f 74 20 75 73 65 64 20 20 20 20 30 78 30 not used 0x0
ba20: 30 31 30 20 20 20 2f 2f 20 57 61 73 3a 20 53 51 010 // Was: SQ
ba30: 4c 49 54 45 5f 49 64 78 52 65 61 6c 41 73 49 6e LITE_IdxRealAsIn
ba40: 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c t */.#define SQL
ba50: 49 54 45 5f 44 69 73 74 69 6e 63 74 4f 70 74 20 ITE_DistinctOpt
ba60: 20 20 20 30 78 30 30 32 30 20 20 20 2f 2a 20 44 0x0020 /* D
ba70: 49 53 54 49 4e 43 54 20 75 73 69 6e 67 20 69 6e ISTINCT using in
ba80: 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 dexes */.#define
ba90: 20 53 51 4c 49 54 45 5f 43 6f 76 65 72 49 64 78 SQLITE_CoverIdx
baa0: 53 63 61 6e 20 20 20 30 78 30 30 34 30 20 20 20 Scan 0x0040
bab0: 2f 2a 20 43 6f 76 65 72 69 6e 67 20 69 6e 64 65 /* Covering inde
bac0: 78 20 73 63 61 6e 73 20 2a 2f 0a 23 64 65 66 69 x scans */.#defi
bad0: 6e 65 20 53 51 4c 49 54 45 5f 4f 72 64 65 72 42 ne SQLITE_OrderB
bae0: 79 49 64 78 4a 6f 69 6e 20 30 78 30 30 38 30 20 yIdxJoin 0x0080
baf0: 20 20 2f 2a 20 4f 52 44 45 52 20 42 59 20 6f 66 /* ORDER BY of
bb00: 20 6a 6f 69 6e 73 20 76 69 61 20 69 6e 64 65 78 joins via index
bb10: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bb20: 54 45 5f 53 75 62 71 43 6f 72 6f 75 74 69 6e 65 TE_SubqCoroutine
bb30: 20 20 30 78 30 31 30 30 20 20 20 2f 2a 20 45 76 0x0100 /* Ev
bb40: 61 6c 75 61 74 65 20 73 75 62 71 75 65 72 69 65 aluate subquerie
bb50: 73 20 61 73 20 63 6f 72 6f 75 74 69 6e 65 73 20 s as coroutines
bb60: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
bb70: 45 5f 54 72 61 6e 73 69 74 69 76 65 20 20 20 20 E_Transitive
bb80: 20 30 78 30 32 30 30 20 20 20 2f 2a 20 54 72 61 0x0200 /* Tra
bb90: 6e 73 69 74 69 76 65 20 63 6f 6e 73 74 72 61 69 nsitive constrai
bba0: 6e 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 nts */.#define S
bbb0: 51 4c 49 54 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f QLITE_OmitNoopJo
bbc0: 69 6e 20 20 20 30 78 30 34 30 30 20 20 20 2f 2a in 0x0400 /*
bbd0: 20 4f 6d 69 74 20 75 6e 75 73 65 64 20 74 61 62 Omit unused tab
bbe0: 6c 65 73 20 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a les in joins */.
bbf0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
bc00: 74 61 74 33 34 20 20 20 20 20 20 20 20 20 30 78 tat34 0x
bc10: 30 38 30 30 20 20 20 2f 2a 20 55 73 65 20 53 54 0800 /* Use ST
bc20: 41 54 33 20 6f 72 20 53 54 41 54 34 20 64 61 74 AT3 or STAT4 dat
bc30: 61 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c a */.#define SQL
bc40: 49 54 45 5f 41 6c 6c 4f 70 74 73 20 20 20 20 20 ITE_AllOpts
bc50: 20 20 20 30 78 66 66 66 66 20 20 20 2f 2a 20 41 0xffff /* A
bc60: 6c 6c 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 ll optimizations
bc70: 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f */../*.** Macro
bc80: 73 20 66 6f 72 20 74 65 73 74 69 6e 67 20 77 68 s for testing wh
bc90: 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 6f 70 74 ether or not opt
bca0: 69 6d 69 7a 61 74 69 6f 6e 73 20 61 72 65 20 65 imizations are e
bcb0: 6e 61 62 6c 65 64 20 6f 72 20 64 69 73 61 62 6c nabled or disabl
bcc0: 65 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ed..*/.#ifndef S
bcd0: 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 QLITE_OMIT_BUILT
bce0: 49 4e 5f 54 45 53 54 0a 23 64 65 66 69 6e 65 20 IN_TEST.#define
bcf0: 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 OptimizationDisa
bd00: 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 bled(db, mask)
bd10: 28 28 28 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 (((db)->dbOptFla
bd20: 67 73 26 28 6d 61 73 6b 29 29 21 3d 30 29 0a 23 gs&(mask))!=0).#
bd30: 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 define Optimizat
bd40: 69 6f 6e 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d ionEnabled(db, m
bd50: 61 73 6b 29 20 20 20 28 28 28 64 62 29 2d 3e 64 ask) (((db)->d
bd60: 62 4f 70 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 bOptFlags&(mask)
bd70: 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 64 65 66 )==0).#else.#def
bd80: 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e ine Optimization
bd90: 44 69 73 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 Disabled(db, mas
bda0: 6b 29 20 20 30 0a 23 64 65 66 69 6e 65 20 4f 70 k) 0.#define Op
bdb0: 74 69 6d 69 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 timizationEnable
bdc0: 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 20 31 0a d(db, mask) 1.
bdd0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 #endif../*.** Re
bde0: 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 74 20 turn true if it
bdf0: 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 63 6f 6e OK to factor con
be00: 73 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e stant expression
be10: 73 20 69 6e 74 6f 20 74 68 65 20 69 6e 69 74 69 s into the initi
be20: 61 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 alization.** cod
be30: 65 2e 20 54 68 65 20 61 72 67 75 6d 65 6e 74 20 e. The argument
be40: 69 73 20 61 20 50 61 72 73 65 20 6f 62 6a 65 63 is a Parse objec
be50: 74 20 66 6f 72 20 74 68 65 20 63 6f 64 65 20 67 t for the code g
be60: 65 6e 65 72 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 enerator..*/.#de
be70: 66 69 6e 65 20 43 6f 6e 73 74 46 61 63 74 6f 72 fine ConstFactor
be80: 4f 6b 28 50 29 20 28 28 50 29 2d 3e 6f 6b 43 6f Ok(P) ((P)->okCo
be90: 6e 73 74 46 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a nstFactor)../*.*
bea0: 2a 20 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 * Possible value
beb0: 73 20 66 6f 72 20 74 68 65 20 73 71 6c 69 74 65 s for the sqlite
bec0: 2e 6d 61 67 69 63 20 66 69 65 6c 64 2e 0a 2a 2a .magic field..**
bed0: 20 54 68 65 20 6e 75 6d 62 65 72 73 20 61 72 65 The numbers are
bee0: 20 6f 62 74 61 69 6e 65 64 20 61 74 20 72 61 6e obtained at ran
bef0: 64 6f 6d 20 61 6e 64 20 68 61 76 65 20 6e 6f 20 dom and have no
bf00: 73 70 65 63 69 61 6c 20 6d 65 61 6e 69 6e 67 2c special meaning,
bf10: 20 6f 74 68 65 72 0a 2a 2a 20 74 68 61 6e 20 62 other.** than b
bf20: 65 69 6e 67 20 64 69 73 74 69 6e 63 74 20 66 72 eing distinct fr
bf30: 6f 6d 20 6f 6e 65 20 61 6e 6f 74 68 65 72 2e 0a om one another..
bf40: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
bf50: 45 5f 4d 41 47 49 43 5f 4f 50 45 4e 20 20 20 20 E_MAGIC_OPEN
bf60: 20 30 78 61 30 32 39 61 36 39 37 20 20 2f 2a 20 0xa029a697 /*
bf70: 44 61 74 61 62 61 73 65 20 69 73 20 6f 70 65 6e Database is open
bf80: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bf90: 54 45 5f 4d 41 47 49 43 5f 43 4c 4f 53 45 44 20 TE_MAGIC_CLOSED
bfa0: 20 20 30 78 39 66 33 63 32 64 33 33 20 20 2f 2a 0x9f3c2d33 /*
bfb0: 20 44 61 74 61 62 61 73 65 20 69 73 20 63 6c 6f Database is clo
bfc0: 73 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 sed */.#define S
bfd0: 51 4c 49 54 45 5f 4d 41 47 49 43 5f 53 49 43 4b QLITE_MAGIC_SICK
bfe0: 20 20 20 20 20 30 78 34 62 37 37 31 32 39 30 20 0x4b771290
bff0: 20 2f 2a 20 45 72 72 6f 72 20 61 6e 64 20 61 77 /* Error and aw
c000: 61 69 74 69 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a aiting close */.
c010: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
c020: 41 47 49 43 5f 42 55 53 59 20 20 20 20 20 30 78 AGIC_BUSY 0x
c030: 66 30 33 62 37 39 30 36 20 20 2f 2a 20 44 61 74 f03b7906 /* Dat
c040: 61 62 61 73 65 20 63 75 72 72 65 6e 74 6c 79 20 abase currently
c050: 69 6e 20 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e in use */.#defin
c060: 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 45 e SQLITE_MAGIC_E
c070: 52 52 4f 52 20 20 20 20 30 78 62 35 33 35 37 39 RROR 0xb53579
c080: 33 30 20 20 2f 2a 20 41 6e 20 53 51 4c 49 54 45 30 /* An SQLITE
c090: 5f 4d 49 53 55 53 45 20 65 72 72 6f 72 20 6f 63 _MISUSE error oc
c0a0: 63 75 72 72 65 64 20 2a 2f 0a 23 64 65 66 69 6e curred */.#defin
c0b0: 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 5a e SQLITE_MAGIC_Z
c0c0: 4f 4d 42 49 45 20 20 20 30 78 36 34 63 66 66 63 OMBIE 0x64cffc
c0d0: 37 66 20 20 2f 2a 20 43 6c 6f 73 65 20 77 69 74 7f /* Close wit
c0e0: 68 20 6c 61 73 74 20 73 74 61 74 65 6d 65 6e 74 h last statement
c0f0: 20 63 6c 6f 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a close */../*.**
c100: 20 45 61 63 68 20 53 51 4c 20 66 75 6e 63 74 69 Each SQL functi
c110: 6f 6e 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 on is defined by
c120: 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 an instance of
c130: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a the following.**
c140: 20 73 74 72 75 63 74 75 72 65 2e 20 20 41 20 70 structure. A p
c150: 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 ointer to this s
c160: 74 72 75 63 74 75 72 65 20 69 73 20 73 74 6f 72 tructure is stor
c170: 65 64 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 ed in the sqlite
c180: 2e 61 46 75 6e 63 0a 2a 2a 20 68 61 73 68 20 74 .aFunc.** hash t
c190: 61 62 6c 65 2e 20 20 57 68 65 6e 20 6d 75 6c 74 able. When mult
c1a0: 69 70 6c 65 20 66 75 6e 63 74 69 6f 6e 73 20 68 iple functions h
c1b0: 61 76 65 20 74 68 65 20 73 61 6d 65 20 6e 61 6d ave the same nam
c1c0: 65 2c 20 74 68 65 20 68 61 73 68 20 74 61 62 6c e, the hash tabl
c1d0: 65 0a 2a 2a 20 70 6f 69 6e 74 73 20 74 6f 20 61 e.** points to a
c1e0: 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 linked list of
c1f0: 74 68 65 73 65 20 73 74 72 75 63 74 75 72 65 73 these structures
c200: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 ..*/.struct Func
c210: 44 65 66 20 7b 0a 20 20 69 31 36 20 6e 41 72 67 Def {. i16 nArg
c220: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
c230: 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 Number of argume
c240: 6e 74 73 2e 20 20 2d 31 20 6d 65 61 6e 73 20 75 nts. -1 means u
c250: 6e 6c 69 6d 69 74 65 64 20 2a 2f 0a 20 20 75 31 nlimited */. u1
c260: 36 20 66 75 6e 63 46 6c 61 67 73 3b 20 20 20 20 6 funcFlags;
c270: 20 20 20 2f 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 /* Some combi
c280: 6e 61 74 69 6f 6e 20 6f 66 20 53 51 4c 49 54 45 nation of SQLITE
c290: 5f 46 55 4e 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 _FUNC_* */. voi
c2a0: 64 20 2a 70 55 73 65 72 44 61 74 61 3b 20 20 20 d *pUserData;
c2b0: 20 20 2f 2a 20 55 73 65 72 20 64 61 74 61 20 70 /* User data p
c2c0: 61 72 61 6d 65 74 65 72 20 2a 2f 0a 20 20 46 75 arameter */. Fu
c2d0: 6e 63 44 65 66 20 2a 70 4e 65 78 74 3b 20 20 20 ncDef *pNext;
c2e0: 20 20 20 2f 2a 20 4e 65 78 74 20 66 75 6e 63 74 /* Next funct
c2f0: 69 6f 6e 20 77 69 74 68 20 73 61 6d 65 20 6e 61 ion with same na
c300: 6d 65 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 me */. void (*x
c310: 46 75 6e 63 29 28 73 71 6c 69 74 65 33 5f 63 6f Func)(sqlite3_co
c320: 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 ntext*,int,sqlit
c330: 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 e3_value**); /*
c340: 52 65 67 75 6c 61 72 20 66 75 6e 63 74 69 6f 6e Regular function
c350: 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 53 74 */. void (*xSt
c360: 65 70 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 ep)(sqlite3_cont
c370: 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 ext*,int,sqlite3
c380: 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 41 67 _value**); /* Ag
c390: 67 72 65 67 61 74 65 20 73 74 65 70 20 2a 2f 0a gregate step */.
c3a0: 20 20 76 6f 69 64 20 28 2a 78 46 69 6e 61 6c 69 void (*xFinali
c3b0: 7a 65 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 ze)(sqlite3_cont
c3c0: 65 78 74 2a 29 3b 20 20 20 20 20 20 20 20 20 20 ext*);
c3d0: 20 20 20 20 20 20 2f 2a 20 41 67 67 72 65 67 61 /* Aggrega
c3e0: 74 65 20 66 69 6e 61 6c 69 7a 65 72 20 2a 2f 0a te finalizer */.
c3f0: 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
c400: 20 20 20 20 20 20 20 2f 2a 20 53 51 4c 20 6e 61 /* SQL na
c410: 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 74 69 me of the functi
c420: 6f 6e 2e 20 2a 2f 0a 20 20 46 75 6e 63 44 65 66 on. */. FuncDef
c430: 20 2a 70 48 61 73 68 3b 20 20 20 20 20 20 2f 2a *pHash; /*
c440: 20 4e 65 78 74 20 77 69 74 68 20 61 20 64 69 66 Next with a dif
c450: 66 65 72 65 6e 74 20 6e 61 6d 65 20 62 75 74 20 ferent name but
c460: 74 68 65 20 73 61 6d 65 20 68 61 73 68 20 2a 2f the same hash */
c470: 0a 20 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f . FuncDestructo
c480: 72 20 2a 70 44 65 73 74 72 75 63 74 6f 72 3b 20 r *pDestructor;
c490: 20 20 2f 2a 20 52 65 66 65 72 65 6e 63 65 20 63 /* Reference c
c4a0: 6f 75 6e 74 65 64 20 64 65 73 74 72 75 63 74 6f ounted destructo
c4b0: 72 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 7d 3b r function */.};
c4c0: 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 ../*.** This str
c4d0: 75 63 74 75 72 65 20 65 6e 63 61 70 73 75 6c 61 ucture encapsula
c4e0: 74 65 73 20 61 20 75 73 65 72 2d 66 75 6e 63 74 tes a user-funct
c4f0: 69 6f 6e 20 64 65 73 74 72 75 63 74 6f 72 20 63 ion destructor c
c500: 61 6c 6c 62 61 63 6b 20 28 61 73 0a 2a 2a 20 63 allback (as.** c
c510: 6f 6e 66 69 67 75 72 65 64 20 75 73 69 6e 67 20 onfigured using
c520: 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f create_function_
c530: 76 32 28 29 29 20 61 6e 64 20 61 20 72 65 66 65 v2()) and a refe
c540: 72 65 6e 63 65 20 63 6f 75 6e 74 65 72 2e 20 57 rence counter. W
c550: 68 65 6e 0a 2a 2a 20 63 72 65 61 74 65 5f 66 75 hen.** create_fu
c560: 6e 63 74 69 6f 6e 5f 76 32 28 29 20 69 73 20 63 nction_v2() is c
c570: 61 6c 6c 65 64 20 74 6f 20 63 72 65 61 74 65 20 alled to create
c580: 61 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 a function with
c590: 61 20 64 65 73 74 72 75 63 74 6f 72 2c 0a 2a 2a a destructor,.**
c5a0: 20 61 20 73 69 6e 67 6c 65 20 6f 62 6a 65 63 74 a single object
c5b0: 20 6f 66 20 74 68 69 73 20 74 79 70 65 20 69 73 of this type is
c5c0: 20 61 6c 6c 6f 63 61 74 65 64 2e 20 46 75 6e 63 allocated. Func
c5d0: 44 65 73 74 72 75 63 74 6f 72 2e 6e 52 65 66 20 Destructor.nRef
c5e0: 69 73 20 73 65 74 20 74 6f 20 0a 2a 2a 20 74 68 is set to .** th
c5f0: 65 20 6e 75 6d 62 65 72 20 6f 66 20 46 75 6e 63 e number of Func
c600: 44 65 66 20 6f 62 6a 65 63 74 73 20 63 72 65 61 Def objects crea
c610: 74 65 64 20 28 65 69 74 68 65 72 20 31 20 6f 72 ted (either 1 or
c620: 20 33 2c 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 3, depending on
c630: 20 77 68 65 74 68 65 72 0a 2a 2a 20 6f 72 20 6e whether.** or n
c640: 6f 74 20 74 68 65 20 73 70 65 63 69 66 69 65 64 ot the specified
c650: 20 65 6e 63 6f 64 69 6e 67 20 69 73 20 53 51 4c encoding is SQL
c660: 49 54 45 5f 41 4e 59 29 2e 20 54 68 65 20 46 75 ITE_ANY). The Fu
c670: 6e 63 44 65 66 2e 70 44 65 73 74 72 75 63 74 6f ncDef.pDestructo
c680: 72 0a 2a 2a 20 6d 65 6d 62 65 72 20 6f 66 20 65 r.** member of e
c690: 61 63 68 20 6f 66 20 74 68 65 20 6e 65 77 20 46 ach of the new F
c6a0: 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 20 69 uncDef objects i
c6b0: 73 20 73 65 74 20 74 6f 20 70 6f 69 6e 74 20 74 s set to point t
c6c0: 6f 20 74 68 65 20 61 6c 6c 6f 63 61 74 65 64 0a o the allocated.
c6d0: 2a 2a 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f ** FuncDestructo
c6e0: 72 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 61 66 r..**.** Thereaf
c6f0: 74 65 72 2c 20 77 68 65 6e 20 6f 6e 65 20 6f 66 ter, when one of
c700: 20 74 68 65 20 46 75 6e 63 44 65 66 20 6f 62 6a the FuncDef obj
c710: 65 63 74 73 20 69 73 20 64 65 6c 65 74 65 64 2c ects is deleted,
c720: 20 74 68 65 20 72 65 66 65 72 65 6e 63 65 0a 2a the reference.*
c730: 2a 20 63 6f 75 6e 74 20 6f 6e 20 74 68 69 73 20 * count on this
c740: 6f 62 6a 65 63 74 20 69 73 20 64 65 63 72 65 6d object is decrem
c750: 65 6e 74 65 64 2e 20 57 68 65 6e 20 69 74 20 72 ented. When it r
c760: 65 61 63 68 65 73 20 30 2c 20 74 68 65 20 64 65 eaches 0, the de
c770: 73 74 72 75 63 74 6f 72 0a 2a 2a 20 69 73 20 69 structor.** is i
c780: 6e 76 6f 6b 65 64 20 61 6e 64 20 74 68 65 20 46 nvoked and the F
c790: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 73 74 uncDestructor st
c7a0: 72 75 63 74 75 72 65 20 66 72 65 65 64 2e 0a 2a ructure freed..*
c7b0: 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 65 73 /.struct FuncDes
c7c0: 74 72 75 63 74 6f 72 20 7b 0a 20 20 69 6e 74 20 tructor {. int
c7d0: 6e 52 65 66 3b 0a 20 20 76 6f 69 64 20 28 2a 78 nRef;. void (*x
c7e0: 44 65 73 74 72 6f 79 29 28 76 6f 69 64 20 2a 29 Destroy)(void *)
c7f0: 3b 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 72 44 ;. void *pUserD
c800: 61 74 61 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 50 ata;.};../*.** P
c810: 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 ossible values f
c820: 6f 72 20 46 75 6e 63 44 65 66 2e 66 6c 61 67 73 or FuncDef.flags
c830: 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 74 68 65 . Note that the
c840: 20 5f 4c 45 4e 47 54 48 20 61 6e 64 20 5f 54 59 _LENGTH and _TY
c850: 50 45 4f 46 0a 2a 2a 20 76 61 6c 75 65 73 20 6d PEOF.** values m
c860: 75 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 ust correspond t
c870: 6f 20 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 o OPFLAG_LENGTHA
c880: 52 47 20 61 6e 64 20 4f 50 46 4c 41 47 5f 54 59 RG and OPFLAG_TY
c890: 50 45 4f 46 41 52 47 2e 20 20 54 68 65 72 65 0a PEOFARG. There.
c8a0: 2a 2a 20 61 72 65 20 61 73 73 65 72 74 28 29 20 ** are assert()
c8b0: 73 74 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 statements in th
c8c0: 65 20 63 6f 64 65 20 74 6f 20 76 65 72 69 66 79 e code to verify
c8d0: 20 74 68 69 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e this..*/.#defin
c8e0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 4e e SQLITE_FUNC_EN
c8f0: 43 4d 41 53 4b 20 20 30 78 30 30 33 20 2f 2a 20 CMASK 0x003 /*
c900: 53 51 4c 49 54 45 5f 55 54 46 38 2c 20 53 51 4c SQLITE_UTF8, SQL
c910: 49 54 45 5f 55 54 46 31 36 42 45 20 6f 72 20 55 ITE_UTF16BE or U
c920: 54 46 31 36 4c 45 20 2a 2f 0a 23 64 65 66 69 6e TF16LE */.#defin
c930: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 49 e SQLITE_FUNC_LI
c940: 4b 45 20 20 20 20 20 30 78 30 30 34 20 2f 2a 20 KE 0x004 /*
c950: 43 61 6e 64 69 64 61 74 65 20 66 6f 72 20 74 68 Candidate for th
c960: 65 20 4c 49 4b 45 20 6f 70 74 69 6d 69 7a 61 74 e LIKE optimizat
c970: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ion */.#define S
c980: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 41 53 45 20 QLITE_FUNC_CASE
c990: 20 20 20 20 30 78 30 30 38 20 2f 2a 20 43 61 73 0x008 /* Cas
c9a0: 65 2d 73 65 6e 73 69 74 69 76 65 20 4c 49 4b 45 e-sensitive LIKE
c9b0: 2d 74 79 70 65 20 66 75 6e 63 74 69 6f 6e 20 2a -type function *
c9c0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
c9d0: 5f 46 55 4e 43 5f 45 50 48 45 4d 20 20 20 20 30 _FUNC_EPHEM 0
c9e0: 78 30 31 30 20 2f 2a 20 45 70 68 65 6d 65 72 61 x010 /* Ephemera
c9f0: 6c 2e 20 20 44 65 6c 65 74 65 20 77 69 74 68 20 l. Delete with
ca00: 56 44 42 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 VDBE */.#define
ca10: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 SQLITE_FUNC_NEED
ca20: 43 4f 4c 4c 20 30 78 30 32 30 20 2f 2a 20 73 71 COLL 0x020 /* sq
ca30: 6c 69 74 65 33 47 65 74 46 75 6e 63 43 6f 6c 6c lite3GetFuncColl
ca40: 53 65 71 28 29 20 6d 69 67 68 74 20 62 65 20 63 Seq() might be c
ca50: 61 6c 6c 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 alled */.#define
ca60: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 4e SQLITE_FUNC_LEN
ca70: 47 54 48 20 20 20 30 78 30 34 30 20 2f 2a 20 42 GTH 0x040 /* B
ca80: 75 69 6c 74 2d 69 6e 20 6c 65 6e 67 74 68 28 29 uilt-in length()
ca90: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 function */.#de
caa0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 fine SQLITE_FUNC
cab0: 5f 54 59 50 45 4f 46 20 20 20 30 78 30 38 30 20 _TYPEOF 0x080
cac0: 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 74 79 70 65 /* Built-in type
cad0: 6f 66 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f of() function */
cae0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
caf0: 46 55 4e 43 5f 43 4f 55 4e 54 20 20 20 20 30 78 FUNC_COUNT 0x
cb00: 31 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 100 /* Built-in
cb10: 63 6f 75 6e 74 28 2a 29 20 61 67 67 72 65 67 61 count(*) aggrega
cb20: 74 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 te */.#define SQ
cb30: 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 41 4c 45 53 LITE_FUNC_COALES
cb40: 43 45 20 30 78 32 30 30 20 2f 2a 20 42 75 69 6c CE 0x200 /* Buil
cb50: 74 2d 69 6e 20 63 6f 61 6c 65 73 63 65 28 29 20 t-in coalesce()
cb60: 6f 72 20 69 66 6e 75 6c 6c 28 29 20 2a 2f 0a 23 or ifnull() */.#
cb70: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
cb80: 4e 43 5f 55 4e 4c 49 4b 45 4c 59 20 30 78 34 30 NC_UNLIKELY 0x40
cb90: 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 75 6e 0 /* Built-in un
cba0: 6c 69 6b 65 6c 79 28 29 20 66 75 6e 63 74 69 6f likely() functio
cbb0: 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c n */.#define SQL
cbc0: 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e ITE_FUNC_CONSTAN
cbd0: 54 20 30 78 38 30 30 20 2f 2a 20 43 6f 6e 73 74 T 0x800 /* Const
cbe0: 61 6e 74 20 69 6e 70 75 74 73 20 67 69 76 65 20 ant inputs give
cbf0: 61 20 63 6f 6e 73 74 61 6e 74 20 6f 75 74 70 75 a constant outpu
cc00: 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c t */.#define SQL
cc10: 49 54 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 20 ITE_FUNC_MINMAX
cc20: 20 30 78 31 30 30 30 20 2f 2a 20 54 72 75 65 20 0x1000 /* True
cc30: 66 6f 72 20 6d 69 6e 28 29 20 61 6e 64 20 6d 61 for min() and ma
cc40: 78 28 29 20 61 67 67 72 65 67 61 74 65 73 20 2a x() aggregates *
cc50: 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c /../*.** The fol
cc60: 6c 6f 77 69 6e 67 20 74 68 72 65 65 20 6d 61 63 lowing three mac
cc70: 72 6f 73 2c 20 46 55 4e 43 54 49 4f 4e 28 29 2c ros, FUNCTION(),
cc80: 20 4c 49 4b 45 46 55 4e 43 28 29 20 61 6e 64 20 LIKEFUNC() and
cc90: 41 47 47 52 45 47 41 54 45 28 29 20 61 72 65 0a AGGREGATE() are.
cca0: 2a 2a 20 75 73 65 64 20 74 6f 20 63 72 65 61 74 ** used to creat
ccb0: 65 20 74 68 65 20 69 6e 69 74 69 61 6c 69 7a 65 e the initialize
ccc0: 72 73 20 66 6f 72 20 74 68 65 20 46 75 6e 63 44 rs for the FuncD
ccd0: 65 66 20 73 74 72 75 63 74 75 72 65 73 2e 0a 2a ef structures..*
cce0: 2a 0a 2a 2a 20 20 20 46 55 4e 43 54 49 4f 4e 28 *.** FUNCTION(
ccf0: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 zName, nArg, iAr
cd00: 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a g, bNC, xFunc).*
cd10: 2a 20 20 20 20 20 55 73 65 64 20 74 6f 20 63 72 * Used to cr
cd20: 65 61 74 65 20 61 20 73 63 61 6c 61 72 20 66 75 eate a scalar fu
cd30: 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f nction definitio
cd40: 6e 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 20 n of a function
cd50: 7a 4e 61 6d 65 20 0a 2a 2a 20 20 20 20 20 69 6d zName .** im
cd60: 70 6c 65 6d 65 6e 74 65 64 20 62 79 20 43 20 66 plemented by C f
cd70: 75 6e 63 74 69 6f 6e 20 78 46 75 6e 63 20 74 68 unction xFunc th
cd80: 61 74 20 61 63 63 65 70 74 73 20 6e 41 72 67 20 at accepts nArg
cd90: 61 72 67 75 6d 65 6e 74 73 2e 20 54 68 65 0a 2a arguments. The.*
cda0: 2a 20 20 20 20 20 76 61 6c 75 65 20 70 61 73 73 * value pass
cdb0: 65 64 20 61 73 20 69 41 72 67 20 69 73 20 63 61 ed as iArg is ca
cdc0: 73 74 20 74 6f 20 61 20 28 76 6f 69 64 2a 29 20 st to a (void*)
cdd0: 61 6e 64 20 6d 61 64 65 20 61 76 61 69 6c 61 62 and made availab
cde0: 6c 65 0a 2a 2a 20 20 20 20 20 61 73 20 74 68 65 le.** as the
cdf0: 20 75 73 65 72 2d 64 61 74 61 20 28 73 71 6c 69 user-data (sqli
ce00: 74 65 33 5f 75 73 65 72 5f 64 61 74 61 28 29 29 te3_user_data())
ce10: 20 66 6f 72 20 74 68 65 20 66 75 6e 63 74 69 6f for the functio
ce20: 6e 2e 20 49 66 20 0a 2a 2a 20 20 20 20 20 61 72 n. If .** ar
ce30: 67 75 6d 65 6e 74 20 62 4e 43 20 69 73 20 74 72 gument bNC is tr
ce40: 75 65 2c 20 74 68 65 6e 20 74 68 65 20 53 51 4c ue, then the SQL
ce50: 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c ITE_FUNC_NEEDCOL
ce60: 4c 20 66 6c 61 67 20 69 73 20 73 65 74 2e 0a 2a L flag is set..*
ce70: 2a 0a 2a 2a 20 20 20 56 46 55 4e 43 54 49 4f 4e *.** VFUNCTION
ce80: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
ce90: 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a rg, bNC, xFunc).
cea0: 2a 2a 20 20 20 20 20 4c 69 6b 65 20 46 55 4e 43 ** Like FUNC
ceb0: 54 49 4f 4e 20 65 78 63 65 70 74 20 69 74 20 6f TION except it o
cec0: 6d 69 74 73 20 74 68 65 20 53 51 4c 49 54 45 5f mits the SQLITE_
ced0: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 66 6c FUNC_CONSTANT fl
cee0: 61 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 41 47 47 52 ag..**.** AGGR
cef0: 45 47 41 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 EGATE(zName, nAr
cf00: 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 53 g, iArg, bNC, xS
cf10: 74 65 70 2c 20 78 46 69 6e 61 6c 29 0a 2a 2a 20 tep, xFinal).**
cf20: 20 20 20 20 55 73 65 64 20 74 6f 20 63 72 65 61 Used to crea
cf30: 74 65 20 61 6e 20 61 67 67 72 65 67 61 74 65 20 te an aggregate
cf40: 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 function definit
cf50: 69 6f 6e 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 ion implemented
cf60: 62 79 0a 2a 2a 20 20 20 20 20 74 68 65 20 43 20 by.** the C
cf70: 66 75 6e 63 74 69 6f 6e 73 20 78 53 74 65 70 20 functions xStep
cf80: 61 6e 64 20 78 46 69 6e 61 6c 2e 20 54 68 65 20 and xFinal. The
cf90: 66 69 72 73 74 20 66 6f 75 72 20 70 61 72 61 6d first four param
cfa0: 65 74 65 72 73 0a 2a 2a 20 20 20 20 20 61 72 65 eters.** are
cfb0: 20 69 6e 74 65 72 70 72 65 74 65 64 20 69 6e 20 interpreted in
cfc0: 74 68 65 20 73 61 6d 65 20 77 61 79 20 61 73 20 the same way as
cfd0: 74 68 65 20 66 69 72 73 74 20 34 20 70 61 72 61 the first 4 para
cfe0: 6d 65 74 65 72 73 20 74 6f 0a 2a 2a 20 20 20 20 meters to.**
cff0: 20 46 55 4e 43 54 49 4f 4e 28 29 2e 0a 2a 2a 0a FUNCTION()..**.
d000: 2a 2a 20 20 20 4c 49 4b 45 46 55 4e 43 28 7a 4e ** LIKEFUNC(zN
d010: 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c ame, nArg, pArg,
d020: 20 66 6c 61 67 73 29 0a 2a 2a 20 20 20 20 20 55 flags).** U
d030: 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 sed to create a
d040: 73 63 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 scalar function
d050: 64 65 66 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 definition of a
d060: 66 75 6e 63 74 69 6f 6e 20 7a 4e 61 6d 65 20 0a function zName .
d070: 2a 2a 20 20 20 20 20 74 68 61 74 20 61 63 63 65 ** that acce
d080: 70 74 73 20 6e 41 72 67 20 61 72 67 75 6d 65 6e pts nArg argumen
d090: 74 73 20 61 6e 64 20 69 73 20 69 6d 70 6c 65 6d ts and is implem
d0a0: 65 6e 74 65 64 20 62 79 20 61 20 63 61 6c 6c 20 ented by a call
d0b0: 74 6f 20 43 20 0a 2a 2a 20 20 20 20 20 66 75 6e to C .** fun
d0c0: 63 74 69 6f 6e 20 6c 69 6b 65 46 75 6e 63 2e 20 ction likeFunc.
d0d0: 41 72 67 75 6d 65 6e 74 20 70 41 72 67 20 69 73 Argument pArg is
d0e0: 20 63 61 73 74 20 74 6f 20 61 20 28 76 6f 69 64 cast to a (void
d0f0: 20 2a 29 20 61 6e 64 20 6d 61 64 65 0a 2a 2a 20 *) and made.**
d100: 20 20 20 20 61 76 61 69 6c 61 62 6c 65 20 61 73 available as
d110: 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 75 73 the function us
d120: 65 72 2d 64 61 74 61 20 28 73 71 6c 69 74 65 33 er-data (sqlite3
d130: 5f 75 73 65 72 5f 64 61 74 61 28 29 29 2e 20 54 _user_data()). T
d140: 68 65 0a 2a 2a 20 20 20 20 20 46 75 6e 63 44 65 he.** FuncDe
d150: 66 2e 66 6c 61 67 73 20 76 61 72 69 61 62 6c 65 f.flags variable
d160: 20 69 73 20 73 65 74 20 74 6f 20 74 68 65 20 76 is set to the v
d170: 61 6c 75 65 20 70 61 73 73 65 64 20 61 73 20 74 alue passed as t
d180: 68 65 20 66 6c 61 67 73 0a 2a 2a 20 20 20 20 20 he flags.**
d190: 70 61 72 61 6d 65 74 65 72 2e 0a 2a 2f 0a 23 64 parameter..*/.#d
d1a0: 65 66 69 6e 65 20 46 55 4e 43 54 49 4f 4e 28 7a efine FUNCTION(z
d1b0: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 Name, nArg, iArg
d1c0: 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a , bNC, xFunc) \.
d1d0: 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
d1e0: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 FUNC_CONSTANT|SQ
d1f0: 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 LITE_UTF8|(bNC*S
d200: 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
d210: 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 OLL), \. SQLIT
d220: 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 E_INT_TO_PTR(iAr
d230: 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c g), 0, xFunc, 0,
d240: 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 0, #zName, 0, 0
d250: 7d 0a 23 64 65 66 69 6e 65 20 56 46 55 4e 43 54 }.#define VFUNCT
d260: 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c ION(zName, nArg,
d270: 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e iArg, bNC, xFun
d280: 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 c) \. {nArg, SQ
d290: 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 LITE_UTF8|(bNC*S
d2a0: 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
d2b0: 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 OLL), \. SQLIT
d2c0: 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 E_INT_TO_PTR(iAr
d2d0: 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c g), 0, xFunc, 0,
d2e0: 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 0, #zName, 0, 0
d2f0: 7d 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 }.#define FUNCTI
d300: 4f 4e 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c ON2(zName, nArg,
d310: 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e iArg, bNC, xFun
d320: 63 2c 20 65 78 74 72 61 46 6c 61 67 73 29 20 5c c, extraFlags) \
d330: 0a 20 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f . {nArg,SQLITE_
d340: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 FUNC_CONSTANT|SQ
d350: 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 LITE_UTF8|(bNC*S
d360: 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
d370: 4f 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c OLL)|extraFlags,
d380: 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f \. SQLITE_INT_
d390: 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c TO_PTR(iArg), 0,
d3a0: 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a xFunc, 0, 0, #z
d3b0: 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 Name, 0, 0}.#def
d3c0: 69 6e 65 20 53 54 52 5f 46 55 4e 43 54 49 4f 4e ine STR_FUNCTION
d3d0: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 (zName, nArg, pA
d3e0: 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 rg, bNC, xFunc)
d3f0: 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 \. {nArg, SQLIT
d400: 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c E_FUNC_CONSTANT|
d410: 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 SQLITE_UTF8|(bNC
d420: 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 *SQLITE_FUNC_NEE
d430: 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 70 41 72 DCOLL), \. pAr
d440: 67 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 g, 0, xFunc, 0,
d450: 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0, #zName, 0, 0}
d460: 0a 23 64 65 66 69 6e 65 20 4c 49 4b 45 46 55 4e .#define LIKEFUN
d470: 43 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 C(zName, nArg, a
d480: 72 67 2c 20 66 6c 61 67 73 29 20 5c 0a 20 20 7b rg, flags) \. {
d490: 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e nArg, SQLITE_FUN
d4a0: 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 C_CONSTANT|SQLIT
d4b0: 45 5f 55 54 46 38 7c 66 6c 61 67 73 2c 20 5c 0a E_UTF8|flags, \.
d4c0: 20 20 20 28 76 6f 69 64 20 2a 29 61 72 67 2c 20 (void *)arg,
d4d0: 30 2c 20 6c 69 6b 65 46 75 6e 63 2c 20 30 2c 20 0, likeFunc, 0,
d4e0: 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0, #zName, 0, 0}
d4f0: 0a 23 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 .#define AGGREGA
d500: 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 TE(zName, nArg,
d510: 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 arg, nc, xStep,
d520: 78 46 69 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 xFinal) \. {nAr
d530: 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
d540: 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
d550: 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 EEDCOLL), \. S
d560: 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 QLITE_INT_TO_PTR
d570: 28 61 72 67 29 2c 20 30 2c 20 30 2c 20 78 53 74 (arg), 0, 0, xSt
d580: 65 70 2c 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 ep,xFinal,#zName
d590: 2c 30 2c 30 7d 0a 23 64 65 66 69 6e 65 20 41 47 ,0,0}.#define AG
d5a0: 47 52 45 47 41 54 45 32 28 7a 4e 61 6d 65 2c 20 GREGATE2(zName,
d5b0: 6e 41 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 nArg, arg, nc, x
d5c0: 53 74 65 70 2c 20 78 46 69 6e 61 6c 2c 20 65 78 Step, xFinal, ex
d5d0: 74 72 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e traFlags) \. {n
d5e0: 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 Arg, SQLITE_UTF8
d5f0: 7c 28 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 |(nc*SQLITE_FUNC
d600: 5f 4e 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 61 _NEEDCOLL)|extra
d610: 46 6c 61 67 73 2c 20 5c 0a 20 20 20 53 51 4c 49 Flags, \. SQLI
d620: 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 TE_INT_TO_PTR(ar
d630: 67 29 2c 20 30 2c 20 30 2c 20 78 53 74 65 70 2c g), 0, 0, xStep,
d640: 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 30 2c xFinal,#zName,0,
d650: 30 7d 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 0}../*.** All cu
d660: 72 72 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 73 rrent savepoints
d670: 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 61 are stored in a
d680: 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 73 74 61 linked list sta
d690: 72 74 69 6e 67 20 61 74 0a 2a 2a 20 73 71 6c 69 rting at.** sqli
d6a0: 74 65 33 2e 70 53 61 76 65 70 6f 69 6e 74 2e 20 te3.pSavepoint.
d6b0: 54 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e The first elemen
d6c0: 74 20 69 6e 20 74 68 65 20 6c 69 73 74 20 69 73 t in the list is
d6d0: 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 the most recent
d6e0: 6c 79 0a 2a 2a 20 6f 70 65 6e 65 64 20 73 61 76 ly.** opened sav
d6f0: 65 70 6f 69 6e 74 2e 20 53 61 76 65 70 6f 69 6e epoint. Savepoin
d700: 74 73 20 61 72 65 20 61 64 64 65 64 20 74 6f 20 ts are added to
d710: 74 68 65 20 6c 69 73 74 20 62 79 20 74 68 65 20 the list by the
d720: 76 64 62 65 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 vdbe.** OP_Savep
d730: 6f 69 6e 74 20 69 6e 73 74 72 75 63 74 69 6f 6e oint instruction
d740: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 61 76 65 ..*/.struct Save
d750: 70 6f 69 6e 74 20 7b 0a 20 20 63 68 61 72 20 2a point {. char *
d760: 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 zName;
d770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
d780: 20 53 61 76 65 70 6f 69 6e 74 20 6e 61 6d 65 20 Savepoint name
d790: 28 6e 75 6c 2d 74 65 72 6d 69 6e 61 74 65 64 29 (nul-terminated)
d7a0: 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 */. i64 nDefer
d7b0: 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 redCons;
d7c0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
d7d0: 62 65 72 20 6f 66 20 64 65 66 65 72 72 65 64 20 ber of deferred
d7e0: 66 6b 20 76 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f fk violations */
d7f0: 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 . i64 nDeferred
d800: 49 6d 6d 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 ImmCons;
d810: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
d820: 20 6f 66 20 64 65 66 65 72 72 65 64 20 69 6d 6d of deferred imm
d830: 20 66 6b 2e 20 2a 2f 0a 20 20 53 61 76 65 70 6f fk. */. Savepo
d840: 69 6e 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 int *pNext;
d850: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
d860: 20 50 61 72 65 6e 74 20 73 61 76 65 70 6f 69 6e Parent savepoin
d870: 74 20 28 69 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b t (if any) */.};
d880: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c ../*.** The foll
d890: 6f 77 69 6e 67 20 61 72 65 20 75 73 65 64 20 61 owing are used a
d8a0: 73 20 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 s the second par
d8b0: 61 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 74 65 ameter to sqlite
d8c0: 33 53 61 76 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 3Savepoint(),.**
d8d0: 20 61 6e 64 20 61 73 20 74 68 65 20 50 31 20 61 and as the P1 a
d8e0: 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 4f rgument to the O
d8f0: 50 5f 53 61 76 65 70 6f 69 6e 74 20 69 6e 73 74 P_Savepoint inst
d900: 72 75 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 ruction..*/.#def
d910: 69 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f 42 45 ine SAVEPOINT_BE
d920: 47 49 4e 20 20 20 20 20 20 30 0a 23 64 65 66 69 GIN 0.#defi
d930: 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f 52 45 4c ne SAVEPOINT_REL
d940: 45 41 53 45 20 20 20 20 31 0a 23 64 65 66 69 6e EASE 1.#defin
d950: 65 20 53 41 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c e SAVEPOINT_ROLL
d960: 42 41 43 4b 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a BACK 2.../*.**
d970: 20 45 61 63 68 20 53 51 4c 69 74 65 20 6d 6f 64 Each SQLite mod
d980: 75 6c 65 20 28 76 69 72 74 75 61 6c 20 74 61 62 ule (virtual tab
d990: 6c 65 20 64 65 66 69 6e 69 74 69 6f 6e 29 20 69 le definition) i
d9a0: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 0a s defined by an.
d9b0: 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 ** instance of t
d9c0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
d9d0: 75 63 74 75 72 65 2c 20 73 74 6f 72 65 64 20 69 ucture, stored i
d9e0: 6e 20 74 68 65 20 73 71 6c 69 74 65 33 2e 61 4d n the sqlite3.aM
d9f0: 6f 64 75 6c 65 0a 2a 2a 20 68 61 73 68 20 74 61 odule.** hash ta
da00: 62 6c 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4d ble..*/.struct M
da10: 6f 64 75 6c 65 20 7b 0a 20 20 63 6f 6e 73 74 20 odule {. const
da20: 73 71 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 20 2a sqlite3_module *
da30: 70 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 20 2f pModule; /
da40: 2a 20 43 61 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 * Callback point
da50: 65 72 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 ers */. const c
da60: 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
da70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
da80: 20 4e 61 6d 65 20 70 61 73 73 65 64 20 74 6f 20 Name passed to
da90: 63 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 create_module()
daa0: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 41 75 78 3b */. void *pAux;
dab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
dac0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 70 41 75 /* pAu
dad0: 78 20 70 61 73 73 65 64 20 74 6f 20 63 72 65 61 x passed to crea
dae0: 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 te_module() */.
daf0: 20 76 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 void (*xDestroy
db00: 29 28 76 6f 69 64 20 2a 29 3b 20 20 20 20 20 20 )(void *);
db10: 20 20 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 /* Module
db20: 64 65 73 74 72 75 63 74 6f 72 20 66 75 6e 63 74 destructor funct
db30: 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ion */.};../*.**
db40: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f information abo
db50: 75 74 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 6f ut each column o
db60: 66 20 61 6e 20 53 51 4c 20 74 61 62 6c 65 20 69 f an SQL table i
db70: 73 20 68 65 6c 64 20 69 6e 20 61 6e 20 69 6e 73 s held in an ins
db80: 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 69 73 tance.** of this
db90: 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 structure..*/.s
dba0: 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 7b 0a 20 truct Column {.
dbb0: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 char *zName;
dbc0: 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 /* Name of thi
dbd0: 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 78 s column */. Ex
dbe0: 70 72 20 2a 70 44 66 6c 74 3b 20 20 20 20 20 2f pr *pDflt; /
dbf0: 2a 20 44 65 66 61 75 6c 74 20 76 61 6c 75 65 20 * Default value
dc00: 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a of this column *
dc10: 2f 0a 20 20 63 68 61 72 20 2a 7a 44 66 6c 74 3b /. char *zDflt;
dc20: 20 20 20 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c /* Original
dc30: 20 74 65 78 74 20 6f 66 20 74 68 65 20 64 65 66 text of the def
dc40: 61 75 6c 74 20 76 61 6c 75 65 20 2a 2f 0a 20 20 ault value */.
dc50: 63 68 61 72 20 2a 7a 54 79 70 65 3b 20 20 20 20 char *zType;
dc60: 20 2f 2a 20 44 61 74 61 20 74 79 70 65 20 66 6f /* Data type fo
dc70: 72 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f r this column */
dc80: 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c 6c 3b 20 . char *zColl;
dc90: 20 20 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 /* Collating
dca0: 20 73 65 71 75 65 6e 63 65 2e 20 20 49 66 20 4e sequence. If N
dcb0: 55 4c 4c 2c 20 75 73 65 20 74 68 65 20 64 65 66 ULL, use the def
dcc0: 61 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6e 6f 74 ault */. u8 not
dcd0: 4e 75 6c 6c 3b 20 20 20 20 20 20 2f 2a 20 41 6e Null; /* An
dce0: 20 4f 45 5f 20 63 6f 64 65 20 66 6f 72 20 68 61 OE_ code for ha
dcf0: 6e 64 6c 69 6e 67 20 61 20 4e 4f 54 20 4e 55 4c ndling a NOT NUL
dd00: 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a L constraint */.
dd10: 20 20 63 68 61 72 20 61 66 66 69 6e 69 74 79 3b char affinity;
dd20: 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 74 68 65 /* One of the
dd30: 20 53 51 4c 49 54 45 5f 41 46 46 5f 2e 2e 2e 20 SQLITE_AFF_...
dd40: 76 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 73 values */. u8 s
dd50: 7a 45 73 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 zEst; /*
dd60: 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 20 6f Estimated size o
dd70: 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 20 f this column.
dd80: 49 4e 54 3d 3d 31 20 2a 2f 0a 20 20 75 38 20 63 INT==1 */. u8 c
dd90: 6f 6c 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 olFlags; /*
dda0: 42 6f 6f 6c 65 61 6e 20 70 72 6f 70 65 72 74 69 Boolean properti
ddb0: 65 73 2e 20 20 53 65 65 20 43 4f 4c 46 4c 41 47 es. See COLFLAG
ddc0: 5f 20 64 65 66 69 6e 65 73 20 62 65 6c 6f 77 20 _ defines below
ddd0: 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 */.};../* Allowe
dde0: 64 20 76 61 6c 75 65 73 20 66 6f 72 20 43 6f 6c d values for Col
ddf0: 75 6d 6e 2e 63 6f 6c 46 6c 61 67 73 3a 0a 2a 2f umn.colFlags:.*/
de00: 0a 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 .#define COLFLAG
de10: 5f 50 52 49 4d 4b 45 59 20 20 30 78 30 30 30 31 _PRIMKEY 0x0001
de20: 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 69 73 /* Column is
de30: 20 70 61 72 74 20 6f 66 20 74 68 65 20 70 72 69 part of the pri
de40: 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 mary key */.#def
de50: 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 ine COLFLAG_HIDD
de60: 45 4e 20 20 20 30 78 30 30 30 32 20 20 20 20 2f EN 0x0002 /
de70: 2a 20 41 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d * A hidden colum
de80: 6e 20 69 6e 20 61 20 76 69 72 74 75 61 6c 20 74 n in a virtual t
de90: 61 62 6c 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 able */../*.** A
dea0: 20 22 43 6f 6c 6c 61 74 69 6e 67 20 53 65 71 75 "Collating Sequ
deb0: 65 6e 63 65 22 20 69 73 20 64 65 66 69 6e 65 64 ence" is defined
dec0: 20 62 79 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 by an instance
ded0: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
dee0: 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 2e 20 43 .** structure. C
def0: 6f 6e 63 65 70 74 75 61 6c 6c 79 2c 20 61 20 63 onceptually, a c
df00: 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
df10: 65 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 20 e consists of a
df20: 6e 61 6d 65 20 61 6e 64 0a 2a 2a 20 61 20 63 6f name and.** a co
df30: 6d 70 61 72 69 73 6f 6e 20 72 6f 75 74 69 6e 65 mparison routine
df40: 20 74 68 61 74 20 64 65 66 69 6e 65 73 20 74 68 that defines th
df50: 65 20 6f 72 64 65 72 20 6f 66 20 74 68 61 74 20 e order of that
df60: 73 65 71 75 65 6e 63 65 2e 0a 2a 2a 0a 2a 2a 20 sequence..**.**
df70: 49 66 20 43 6f 6c 6c 53 65 71 2e 78 43 6d 70 20 If CollSeq.xCmp
df80: 69 73 20 4e 55 4c 4c 2c 20 69 74 20 6d 65 61 6e is NULL, it mean
df90: 73 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 63 6f s that the.** co
dfa0: 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 llating sequence
dfb0: 20 69 73 20 75 6e 64 65 66 69 6e 65 64 2e 20 20 is undefined.
dfc0: 49 6e 64 69 63 65 73 20 62 75 69 6c 74 20 6f 6e Indices built on
dfd0: 20 61 6e 20 75 6e 64 65 66 69 6e 65 64 0a 2a 2a an undefined.**
dfe0: 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 collating seque
dff0: 6e 63 65 20 6d 61 79 20 6e 6f 74 20 62 65 20 72 nce may not be r
e000: 65 61 64 20 6f 72 20 77 72 69 74 74 65 6e 2e 0a ead or written..
e010: 2a 2f 0a 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 */.struct CollSe
e020: 71 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d q {. char *zNam
e030: 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e e; /* N
e040: 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6c 6c 61 ame of the colla
e050: 74 69 6e 67 20 73 65 71 75 65 6e 63 65 2c 20 55 ting sequence, U
e060: 54 46 2d 38 20 65 6e 63 6f 64 65 64 20 2a 2f 0a TF-8 encoded */.
e070: 20 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 u8 enc;
e080: 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 /* Text
e090: 65 6e 63 6f 64 69 6e 67 20 68 61 6e 64 6c 65 64 encoding handled
e0a0: 20 62 79 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 by xCmp() */.
e0b0: 76 6f 69 64 20 2a 70 55 73 65 72 3b 20 20 20 20 void *pUser;
e0c0: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 /* First a
e0d0: 72 67 75 6d 65 6e 74 20 74 6f 20 78 43 6d 70 28 rgument to xCmp(
e0e0: 29 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 43 6d ) */. int (*xCm
e0f0: 70 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f p)(void*,int, co
e100: 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 nst void*, int,
e110: 63 6f 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 const void*);.
e120: 76 6f 69 64 20 28 2a 78 44 65 6c 29 28 76 6f 69 void (*xDel)(voi
e130: 64 2a 29 3b 20 20 2f 2a 20 44 65 73 74 72 75 63 d*); /* Destruc
e140: 74 6f 72 20 66 6f 72 20 70 55 73 65 72 20 2a 2f tor for pUser */
e150: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 73 6f 72 .};../*.** A sor
e160: 74 20 6f 72 64 65 72 20 63 61 6e 20 62 65 20 65 t order can be e
e170: 69 74 68 65 72 20 41 53 43 20 6f 72 20 44 45 53 ither ASC or DES
e180: 43 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 C..*/.#define SQ
e190: 4c 49 54 45 5f 53 4f 5f 41 53 43 20 20 20 20 20 LITE_SO_ASC
e1a0: 20 20 30 20 20 2f 2a 20 53 6f 72 74 20 69 6e 20 0 /* Sort in
e1b0: 61 73 63 65 6e 64 69 6e 67 20 6f 72 64 65 72 20 ascending order
e1c0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e1d0: 45 5f 53 4f 5f 44 45 53 43 20 20 20 20 20 20 31 E_SO_DESC 1
e1e0: 20 20 2f 2a 20 53 6f 72 74 20 69 6e 20 61 73 63 /* Sort in asc
e1f0: 65 6e 64 69 6e 67 20 6f 72 64 65 72 20 2a 2f 0a ending order */.
e200: 0a 2f 2a 0a 2a 2a 20 43 6f 6c 75 6d 6e 20 61 66 ./*.** Column af
e210: 66 69 6e 69 74 79 20 74 79 70 65 73 2e 0a 2a 2a finity types..**
e220: 0a 2a 2a 20 54 68 65 73 65 20 75 73 65 64 20 74 .** These used t
e230: 6f 20 68 61 76 65 20 6d 6e 65 6d 6f 6e 69 63 20 o have mnemonic
e240: 6e 61 6d 65 20 6c 69 6b 65 20 27 69 27 20 66 6f name like 'i' fo
e250: 72 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 4e 54 r SQLITE_AFF_INT
e260: 45 47 45 52 20 61 6e 64 0a 2a 2a 20 27 74 27 20 EGER and.** 't'
e270: 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 for SQLITE_AFF_T
e280: 45 58 54 2e 20 20 42 75 74 20 77 65 20 63 61 6e EXT. But we can
e290: 20 73 61 76 65 20 61 20 6c 69 74 74 6c 65 20 73 save a little s
e2a0: 70 61 63 65 20 61 6e 64 20 69 6d 70 72 6f 76 65 pace and improve
e2b0: 0a 2a 2a 20 74 68 65 20 73 70 65 65 64 20 61 20 .** the speed a
e2c0: 6c 69 74 74 6c 65 20 62 79 20 6e 75 6d 62 65 72 little by number
e2d0: 69 6e 67 20 74 68 65 20 76 61 6c 75 65 73 20 63 ing the values c
e2e0: 6f 6e 73 65 63 75 74 69 76 65 6c 79 2e 20 20 0a onsecutively. .
e2f0: 2a 2a 0a 2a 2a 20 42 75 74 20 72 61 74 68 65 72 **.** But rather
e300: 20 74 68 61 6e 20 73 74 61 72 74 20 77 69 74 68 than start with
e310: 20 30 20 6f 72 20 31 2c 20 77 65 20 62 65 67 69 0 or 1, we begi
e320: 6e 20 77 69 74 68 20 27 41 27 2e 20 20 54 68 61 n with 'A'. Tha
e330: 74 20 77 61 79 2c 0a 2a 2a 20 77 68 65 6e 20 6d t way,.** when m
e340: 75 6c 74 69 70 6c 65 20 61 66 66 69 6e 69 74 79 ultiple affinity
e350: 20 74 79 70 65 73 20 61 72 65 20 63 6f 6e 63 61 types are conca
e360: 74 65 6e 61 74 65 64 20 69 6e 74 6f 20 61 20 73 tenated into a s
e370: 74 72 69 6e 67 20 61 6e 64 0a 2a 2a 20 75 73 65 tring and.** use
e380: 64 20 61 73 20 74 68 65 20 50 34 20 6f 70 65 72 d as the P4 oper
e390: 61 6e 64 2c 20 74 68 65 79 20 77 69 6c 6c 20 62 and, they will b
e3a0: 65 20 6d 6f 72 65 20 72 65 61 64 61 62 6c 65 2e e more readable.
e3b0: 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 61 6c 73 6f .**.** Note also
e3c0: 20 74 68 61 74 20 74 68 65 20 6e 75 6d 65 72 69 that the numeri
e3d0: 63 20 74 79 70 65 73 20 61 72 65 20 67 72 6f 75 c types are grou
e3e0: 70 65 64 20 74 6f 67 65 74 68 65 72 20 73 6f 20 ped together so
e3f0: 74 68 61 74 20 74 65 73 74 69 6e 67 0a 2a 2a 20 that testing.**
e400: 66 6f 72 20 61 20 6e 75 6d 65 72 69 63 20 74 79 for a numeric ty
e410: 70 65 20 69 73 20 61 20 73 69 6e 67 6c 65 20 63 pe is a single c
e420: 6f 6d 70 61 72 69 73 6f 6e 2e 20 20 41 6e 64 20 omparison. And
e430: 74 68 65 20 4e 4f 4e 45 20 74 79 70 65 20 69 73 the NONE type is
e440: 20 66 69 72 73 74 2e 0a 2a 2f 0a 23 64 65 66 69 first..*/.#defi
e450: 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4e 4f ne SQLITE_AFF_NO
e460: 4e 45 20 20 20 20 20 27 41 27 0a 23 64 65 66 69 NE 'A'.#defi
e470: 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 45 ne SQLITE_AFF_TE
e480: 58 54 20 20 20 20 20 27 42 27 0a 23 64 65 66 69 XT 'B'.#defi
e490: 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4e 55 ne SQLITE_AFF_NU
e4a0: 4d 45 52 49 43 20 20 27 43 27 0a 23 64 65 66 69 MERIC 'C'.#defi
e4b0: 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 4e ne SQLITE_AFF_IN
e4c0: 54 45 47 45 52 20 20 27 44 27 0a 23 64 65 66 69 TEGER 'D'.#defi
e4d0: 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 52 45 ne SQLITE_AFF_RE
e4e0: 41 4c 20 20 20 20 20 27 45 27 0a 0a 23 64 65 66 AL 'E'..#def
e4f0: 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 75 6d ine sqlite3IsNum
e500: 65 72 69 63 41 66 66 69 6e 69 74 79 28 58 29 20 ericAffinity(X)
e510: 20 28 28 58 29 3e 3d 53 51 4c 49 54 45 5f 41 46 ((X)>=SQLITE_AF
e520: 46 5f 4e 55 4d 45 52 49 43 29 0a 0a 2f 2a 0a 2a F_NUMERIC)../*.*
e530: 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 41 46 46 * The SQLITE_AFF
e540: 5f 4d 41 53 4b 20 76 61 6c 75 65 73 20 6d 61 73 _MASK values mas
e550: 6b 73 20 6f 66 66 20 74 68 65 20 73 69 67 6e 69 ks off the signi
e560: 66 69 63 61 6e 74 20 62 69 74 73 20 6f 66 20 61 ficant bits of a
e570: 6e 0a 2a 2a 20 61 66 66 69 6e 69 74 79 20 76 61 n.** affinity va
e580: 6c 75 65 2e 20 0a 2a 2f 0a 23 64 65 66 69 6e 65 lue. .*/.#define
e590: 20 53 51 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b SQLITE_AFF_MASK
e5a0: 20 20 20 20 20 30 78 34 37 0a 0a 2f 2a 0a 2a 2a 0x47../*.**
e5b0: 20 41 64 64 69 74 69 6f 6e 61 6c 20 62 69 74 20 Additional bit
e5c0: 76 61 6c 75 65 73 20 74 68 61 74 20 63 61 6e 20 values that can
e5d0: 62 65 20 4f 52 65 64 20 77 69 74 68 20 61 6e 20 be ORed with an
e5e0: 61 66 66 69 6e 69 74 79 20 77 69 74 68 6f 75 74 affinity without
e5f0: 0a 2a 2a 20 63 68 61 6e 67 69 6e 67 20 74 68 65 .** changing the
e600: 20 61 66 66 69 6e 69 74 79 2e 0a 2a 2a 0a 2a 2a affinity..**.**
e610: 20 54 68 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e The SQLITE_NOTN
e620: 55 4c 4c 20 66 6c 61 67 20 69 73 20 61 20 63 6f ULL flag is a co
e630: 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 4e 55 4c mbination of NUL
e640: 4c 45 51 20 61 6e 64 20 4a 55 4d 50 49 46 4e 55 LEQ and JUMPIFNU
e650: 4c 4c 2e 0a 2a 2a 20 49 74 20 63 61 75 73 65 73 LL..** It causes
e660: 20 61 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 an assert() to
e670: 66 69 72 65 20 69 66 20 65 69 74 68 65 72 20 6f fire if either o
e680: 70 65 72 61 6e 64 20 74 6f 20 61 20 63 6f 6d 70 perand to a comp
e690: 61 72 69 73 6f 6e 0a 2a 2a 20 6f 70 65 72 61 74 arison.** operat
e6a0: 6f 72 20 69 73 20 4e 55 4c 4c 2e 20 20 49 74 20 or is NULL. It
e6b0: 69 73 20 61 64 64 65 64 20 74 6f 20 63 65 72 74 is added to cert
e6c0: 61 69 6e 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f ain comparison o
e6d0: 70 65 72 61 74 6f 72 73 20 74 6f 0a 2a 2a 20 70 perators to.** p
e6e0: 72 6f 76 65 20 74 68 61 74 20 74 68 65 20 6f 70 rove that the op
e6f0: 65 72 61 6e 64 73 20 61 72 65 20 61 6c 77 61 79 erands are alway
e700: 73 20 4e 4f 54 20 4e 55 4c 4c 2e 0a 2a 2f 0a 23 s NOT NULL..*/.#
e710: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4a 55 define SQLITE_JU
e720: 4d 50 49 46 4e 55 4c 4c 20 20 20 30 78 31 30 20 MPIFNULL 0x10
e730: 20 2f 2a 20 6a 75 6d 70 73 20 69 66 20 65 69 74 /* jumps if eit
e740: 68 65 72 20 6f 70 65 72 61 6e 64 20 69 73 20 4e her operand is N
e750: 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ULL */.#define S
e760: 51 4c 49 54 45 5f 53 54 4f 52 45 50 32 20 20 20 QLITE_STOREP2
e770: 20 20 20 30 78 32 30 20 20 2f 2a 20 53 74 6f 72 0x20 /* Stor
e780: 65 20 72 65 73 75 6c 74 20 69 6e 20 72 65 67 5b e result in reg[
e790: 50 32 5d 20 72 61 74 68 65 72 20 74 68 61 6e 20 P2] rather than
e7a0: 6a 75 6d 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 jump */.#define
e7b0: 53 51 4c 49 54 45 5f 4e 55 4c 4c 45 51 20 20 20 SQLITE_NULLEQ
e7c0: 20 20 20 20 30 78 38 30 20 20 2f 2a 20 4e 55 4c 0x80 /* NUL
e7d0: 4c 3d 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e L=NULL */.#defin
e7e0: 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c e SQLITE_NOTNULL
e7f0: 20 20 20 20 20 20 30 78 39 30 20 20 2f 2a 20 41 0x90 /* A
e800: 73 73 65 72 74 20 74 68 61 74 20 6f 70 65 72 61 ssert that opera
e810: 6e 64 73 20 61 72 65 20 6e 65 76 65 72 20 4e 55 nds are never NU
e820: 4c 4c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 LL */../*.** An
e830: 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 73 20 74 object of this t
e840: 79 70 65 20 69 73 20 63 72 65 61 74 65 64 20 66 ype is created f
e850: 6f 72 20 65 61 63 68 20 76 69 72 74 75 61 6c 20 or each virtual
e860: 74 61 62 6c 65 20 70 72 65 73 65 6e 74 20 69 6e table present in
e870: 0a 2a 2a 20 74 68 65 20 64 61 74 61 62 61 73 65 .** the database
e880: 20 73 63 68 65 6d 61 2e 20 0a 2a 2a 0a 2a 2a 20 schema. .**.**
e890: 49 66 20 74 68 65 20 64 61 74 61 62 61 73 65 20 If the database
e8a0: 73 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 schema is shared
e8b0: 2c 20 74 68 65 6e 20 74 68 65 72 65 20 69 73 20 , then there is
e8c0: 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 one instance of
e8d0: 74 68 69 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 this.** structur
e8e0: 65 20 66 6f 72 20 65 61 63 68 20 64 61 74 61 62 e for each datab
e8f0: 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 28 ase connection (
e900: 73 71 6c 69 74 65 33 2a 29 20 74 68 61 74 20 75 sqlite3*) that u
e910: 73 65 73 20 74 68 65 20 73 68 61 72 65 64 0a 2a ses the shared.*
e920: 2a 20 73 63 68 65 6d 61 2e 20 54 68 69 73 20 69 * schema. This i
e930: 73 20 62 65 63 61 75 73 65 20 65 61 63 68 20 64 s because each d
e940: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
e950: 6f 6e 20 72 65 71 75 69 72 65 73 20 69 74 73 20 on requires its
e960: 6f 77 6e 20 75 6e 69 71 75 65 0a 2a 2a 20 69 6e own unique.** in
e970: 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 73 71 stance of the sq
e980: 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 lite3_vtab* hand
e990: 6c 65 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 le used to acces
e9a0: 73 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 s the virtual ta
e9b0: 62 6c 65 20 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e ble .** implemen
e9c0: 74 61 74 69 6f 6e 2e 20 73 71 6c 69 74 65 33 5f tation. sqlite3_
e9d0: 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 63 61 vtab* handles ca
e9e0: 6e 20 6e 6f 74 20 62 65 20 73 68 61 72 65 64 20 n not be shared
e9f0: 62 65 74 77 65 65 6e 20 0a 2a 2a 20 64 61 74 61 between .** data
ea00: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 base connections
ea10: 2c 20 65 76 65 6e 20 77 68 65 6e 20 74 68 65 20 , even when the
ea20: 72 65 73 74 20 6f 66 20 74 68 65 20 69 6e 2d 6d rest of the in-m
ea30: 65 6d 6f 72 79 20 64 61 74 61 62 61 73 65 20 0a emory database .
ea40: 2a 2a 20 73 63 68 65 6d 61 20 69 73 20 73 68 61 ** schema is sha
ea50: 72 65 64 2c 20 61 73 20 74 68 65 20 69 6d 70 6c red, as the impl
ea60: 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 74 65 6e ementation often
ea70: 20 73 74 6f 72 65 73 20 74 68 65 20 64 61 74 61 stores the data
ea80: 62 61 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 base.** connecti
ea90: 6f 6e 20 68 61 6e 64 6c 65 20 70 61 73 73 65 64 on handle passed
eaa0: 20 74 6f 20 69 74 20 76 69 61 20 74 68 65 20 78 to it via the x
eab0: 43 6f 6e 6e 65 63 74 28 29 20 6f 72 20 78 43 72 Connect() or xCr
eac0: 65 61 74 65 28 29 20 6d 65 74 68 6f 64 0a 2a 2a eate() method.**
ead0: 20 64 75 72 69 6e 67 20 69 6e 69 74 69 61 6c 69 during initiali
eae0: 7a 61 74 69 6f 6e 20 69 6e 74 65 72 6e 61 6c 6c zation internall
eaf0: 79 2e 20 54 68 69 73 20 64 61 74 61 62 61 73 65 y. This database
eb00: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 connection hand
eb10: 6c 65 20 6d 61 79 0a 2a 2a 20 74 68 65 6e 20 62 le may.** then b
eb20: 65 20 75 73 65 64 20 62 79 20 74 68 65 20 76 69 e used by the vi
eb30: 72 74 75 61 6c 20 74 61 62 6c 65 20 69 6d 70 6c rtual table impl
eb40: 65 6d 65 6e 74 61 74 69 6f 6e 20 74 6f 20 61 63 ementation to ac
eb50: 63 65 73 73 20 72 65 61 6c 20 74 61 62 6c 65 73 cess real tables
eb60: 20 0a 2a 2a 20 77 69 74 68 69 6e 20 74 68 65 20 .** within the
eb70: 64 61 74 61 62 61 73 65 2e 20 53 6f 20 74 68 61 database. So tha
eb80: 74 20 74 68 65 79 20 61 70 70 65 61 72 20 61 73 t they appear as
eb90: 20 70 61 72 74 20 6f 66 20 74 68 65 20 63 61 6c part of the cal
eba0: 6c 65 72 73 20 0a 2a 2a 20 74 72 61 6e 73 61 63 lers .** transac
ebb0: 74 69 6f 6e 2c 20 74 68 65 73 65 20 61 63 63 65 tion, these acce
ebc0: 73 73 65 73 20 6e 65 65 64 20 74 6f 20 62 65 20 sses need to be
ebd0: 6d 61 64 65 20 76 69 61 20 74 68 65 20 73 61 6d made via the sam
ebe0: 65 20 64 61 74 61 62 61 73 65 20 0a 2a 2a 20 63 e database .** c
ebf0: 6f 6e 6e 65 63 74 69 6f 6e 20 61 73 20 74 68 61 onnection as tha
ec00: 74 20 75 73 65 64 20 74 6f 20 65 78 65 63 75 74 t used to execut
ec10: 65 20 53 51 4c 20 6f 70 65 72 61 74 69 6f 6e 73 e SQL operations
ec20: 20 6f 6e 20 74 68 65 20 76 69 72 74 75 61 6c 20 on the virtual
ec30: 74 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c table..**.** All
ec40: 20 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 VTable objects
ec50: 74 68 61 74 20 63 6f 72 72 65 73 70 6f 6e 64 20 that correspond
ec60: 74 6f 20 61 20 73 69 6e 67 6c 65 20 74 61 62 6c to a single tabl
ec70: 65 20 69 6e 20 61 20 73 68 61 72 65 64 0a 2a 2a e in a shared.**
ec80: 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 database schema
ec90: 20 61 72 65 20 69 6e 69 74 69 61 6c 6c 79 20 73 are initially s
eca0: 74 6f 72 65 64 20 69 6e 20 61 20 6c 69 6e 6b 65 tored in a linke
ecb0: 64 2d 6c 69 73 74 20 70 6f 69 6e 74 65 64 20 74 d-list pointed t
ecc0: 6f 20 62 79 0a 2a 2a 20 74 68 65 20 54 61 62 6c o by.** the Tabl
ecd0: 65 2e 70 56 54 61 62 6c 65 20 6d 65 6d 62 65 72 e.pVTable member
ece0: 20 76 61 72 69 61 62 6c 65 20 6f 66 20 74 68 65 variable of the
ecf0: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 54 corresponding T
ed00: 61 62 6c 65 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 able object..**
ed10: 57 68 65 6e 20 61 6e 20 73 71 6c 69 74 65 33 5f When an sqlite3_
ed20: 70 72 65 70 61 72 65 28 29 20 6f 70 65 72 61 74 prepare() operat
ed30: 69 6f 6e 20 69 73 20 72 65 71 75 69 72 65 64 20 ion is required
ed40: 74 6f 20 61 63 63 65 73 73 20 74 68 65 20 76 69 to access the vi
ed50: 72 74 75 61 6c 0a 2a 2a 20 74 61 62 6c 65 2c 20 rtual.** table,
ed60: 69 74 20 73 65 61 72 63 68 65 73 20 74 68 65 20 it searches the
ed70: 6c 69 73 74 20 66 6f 72 20 74 68 65 20 56 54 61 list for the VTa
ed80: 62 6c 65 20 74 68 61 74 20 63 6f 72 72 65 73 70 ble that corresp
ed90: 6f 6e 64 73 20 74 6f 20 74 68 65 0a 2a 2a 20 64 onds to the.** d
eda0: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
edb0: 6f 6e 20 64 6f 69 6e 67 20 74 68 65 20 70 72 65 on doing the pre
edc0: 70 61 72 69 6e 67 20 73 6f 20 61 73 20 74 6f 20 paring so as to
edd0: 75 73 65 20 74 68 65 20 63 6f 72 72 65 63 74 0a use the correct.
ede0: 2a 2a 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a ** sqlite3_vtab*
edf0: 20 68 61 6e 64 6c 65 20 69 6e 20 74 68 65 20 63 handle in the c
ee00: 6f 6d 70 69 6c 65 64 20 71 75 65 72 79 2e 0a 2a ompiled query..*
ee10: 2a 0a 2a 2a 20 57 68 65 6e 20 61 6e 20 69 6e 2d *.** When an in-
ee20: 6d 65 6d 6f 72 79 20 54 61 62 6c 65 20 6f 62 6a memory Table obj
ee30: 65 63 74 20 69 73 20 64 65 6c 65 74 65 64 20 28 ect is deleted (
ee40: 66 6f 72 20 65 78 61 6d 70 6c 65 20 77 68 65 6e for example when
ee50: 20 74 68 65 0a 2a 2a 20 73 63 68 65 6d 61 20 69 the.** schema i
ee60: 73 20 62 65 69 6e 67 20 72 65 6c 6f 61 64 65 64 s being reloaded
ee70: 20 66 6f 72 20 73 6f 6d 65 20 72 65 61 73 6f 6e for some reason
ee80: 29 2c 20 74 68 65 20 56 54 61 62 6c 65 20 6f 62 ), the VTable ob
ee90: 6a 65 63 74 73 20 61 72 65 20 6e 6f 74 20 0a 2a jects are not .*
eea0: 2a 20 64 65 6c 65 74 65 64 20 61 6e 64 20 74 68 * deleted and th
eeb0: 65 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 e sqlite3_vtab*
eec0: 68 61 6e 64 6c 65 73 20 61 72 65 20 6e 6f 74 20 handles are not
eed0: 78 44 69 73 63 6f 6e 6e 65 63 74 28 29 65 64 20 xDisconnect()ed
eee0: 0a 2a 2a 20 69 6d 6d 65 64 69 61 74 65 6c 79 2e .** immediately.
eef0: 20 49 6e 73 74 65 61 64 2c 20 74 68 65 79 20 61 Instead, they a
ef00: 72 65 20 6d 6f 76 65 64 20 66 72 6f 6d 20 74 68 re moved from th
ef10: 65 20 54 61 62 6c 65 2e 70 56 54 61 62 6c 65 20 e Table.pVTable
ef20: 6c 69 73 74 20 74 6f 0a 2a 2a 20 61 6e 6f 74 68 list to.** anoth
ef30: 65 72 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 68 er linked list h
ef40: 65 61 64 65 64 20 62 79 20 74 68 65 20 73 71 6c eaded by the sql
ef50: 69 74 65 33 2e 70 44 69 73 63 6f 6e 6e 65 63 74 ite3.pDisconnect
ef60: 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 0a 2a member of the.*
ef70: 2a 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 * corresponding
ef80: 73 71 6c 69 74 65 33 20 73 74 72 75 63 74 75 72 sqlite3 structur
ef90: 65 2e 20 54 68 65 79 20 61 72 65 20 74 68 65 6e e. They are then
efa0: 20 64 65 6c 65 74 65 64 2f 78 44 69 73 63 6f 6e deleted/xDiscon
efb0: 6e 65 63 74 65 64 20 0a 2a 2a 20 6e 65 78 74 20 nected .** next
efc0: 74 69 6d 65 20 61 20 73 74 61 74 65 6d 65 6e 74 time a statement
efd0: 20 69 73 20 70 72 65 70 61 72 65 64 20 75 73 69 is prepared usi
efe0: 6e 67 20 73 61 69 64 20 73 71 6c 69 74 65 33 2a ng said sqlite3*
eff0: 2e 20 54 68 69 73 20 69 73 20 64 6f 6e 65 0a 2a . This is done.*
f000: 2a 20 74 6f 20 61 76 6f 69 64 20 64 65 61 64 6c * to avoid deadl
f010: 6f 63 6b 20 69 73 73 75 65 73 20 69 6e 76 6f 6c ock issues invol
f020: 76 69 6e 67 20 6d 75 6c 74 69 70 6c 65 20 73 71 ving multiple sq
f030: 6c 69 74 65 33 2e 6d 75 74 65 78 20 6d 75 74 65 lite3.mutex mute
f040: 78 65 73 2e 0a 2a 2a 20 52 65 66 65 72 20 74 6f xes..** Refer to
f050: 20 63 6f 6d 6d 65 6e 74 73 20 61 62 6f 76 65 20 comments above
f060: 66 75 6e 63 74 69 6f 6e 20 73 71 6c 69 74 65 33 function sqlite3
f070: 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 29 VtabUnlockList()
f080: 20 66 6f 72 20 61 6e 0a 2a 2a 20 65 78 70 6c 61 for an.** expla
f090: 6e 61 74 69 6f 6e 20 61 73 20 74 6f 20 77 68 79 nation as to why
f0a0: 20 69 74 20 69 73 20 73 61 66 65 20 74 6f 20 61 it is safe to a
f0b0: 64 64 20 61 6e 20 65 6e 74 72 79 20 74 6f 20 61 dd an entry to a
f0c0: 6e 20 73 71 6c 69 74 65 33 2e 70 44 69 73 63 6f n sqlite3.pDisco
f0d0: 6e 6e 65 63 74 0a 2a 2a 20 6c 69 73 74 20 77 69 nnect.** list wi
f0e0: 74 68 6f 75 74 20 68 6f 6c 64 69 6e 67 20 74 68 thout holding th
f0f0: 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
f100: 73 71 6c 69 74 65 33 2e 6d 75 74 65 78 20 6d 75 sqlite3.mutex mu
f110: 74 65 78 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6d tex..**.** The m
f120: 65 6d 6f 72 79 20 66 6f 72 20 6f 62 6a 65 63 74 emory for object
f130: 73 20 6f 66 20 74 68 69 73 20 74 79 70 65 20 69 s of this type i
f140: 73 20 61 6c 77 61 79 73 20 61 6c 6c 6f 63 61 74 s always allocat
f150: 65 64 20 62 79 20 0a 2a 2a 20 73 71 6c 69 74 65 ed by .** sqlite
f160: 33 44 62 4d 61 6c 6c 6f 63 28 29 2c 20 75 73 69 3DbMalloc(), usi
f170: 6e 67 20 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f ng the connectio
f180: 6e 20 68 61 6e 64 6c 65 20 73 74 6f 72 65 64 20 n handle stored
f190: 69 6e 20 56 54 61 62 6c 65 2e 64 62 20 61 73 20 in VTable.db as
f1a0: 0a 2a 2a 20 74 68 65 20 66 69 72 73 74 20 61 72 .** the first ar
f1b0: 67 75 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 72 75 63 gument..*/.struc
f1c0: 74 20 56 54 61 62 6c 65 20 7b 0a 20 20 73 71 6c t VTable {. sql
f1d0: 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 20 ite3 *db;
f1e0: 20 20 20 20 20 20 20 2f 2a 20 44 61 74 61 62 61 /* Databa
f1f0: 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 73 se connection as
f200: 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 sociated with th
f210: 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 4d 6f is table */. Mo
f220: 64 75 6c 65 20 2a 70 4d 6f 64 3b 20 20 20 20 20 dule *pMod;
f230: 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 /* Point
f240: 65 72 20 74 6f 20 6d 6f 64 75 6c 65 20 69 6d 70 er to module imp
f250: 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 lementation */.
f260: 20 73 71 6c 69 74 65 33 5f 76 74 61 62 20 2a 70 sqlite3_vtab *p
f270: 56 74 61 62 3b 20 20 20 20 20 20 2f 2a 20 50 6f Vtab; /* Po
f280: 69 6e 74 65 72 20 74 6f 20 76 74 61 62 20 69 6e inter to vtab in
f290: 73 74 61 6e 63 65 20 2a 2f 0a 20 20 69 6e 74 20 stance */. int
f2a0: 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 20 20 nRef;
f2b0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
f2c0: 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 74 of pointers to t
f2d0: 68 69 73 20 73 74 72 75 63 74 75 72 65 20 2a 2f his structure */
f2e0: 0a 20 20 75 38 20 62 43 6f 6e 73 74 72 61 69 6e . u8 bConstrain
f2f0: 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
f300: 54 72 75 65 20 69 66 20 63 6f 6e 73 74 72 61 69 True if constrai
f310: 6e 74 73 20 61 72 65 20 73 75 70 70 6f 72 74 65 nts are supporte
f320: 64 20 2a 2f 0a 20 20 69 6e 74 20 69 53 61 76 65 d */. int iSave
f330: 70 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 point;
f340: 20 2f 2a 20 44 65 70 74 68 20 6f 66 20 74 68 65 /* Depth of the
f350: 20 53 41 56 45 50 4f 49 4e 54 20 73 74 61 63 6b SAVEPOINT stack
f360: 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 4e */. VTable *pN
f370: 65 78 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ext;
f380: 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 6e 6b 65 /* Next in linke
f390: 64 20 6c 69 73 74 20 28 73 65 65 20 61 62 6f 76 d list (see abov
f3a0: 65 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 e) */.};../*.**
f3b0: 45 61 63 68 20 53 51 4c 20 74 61 62 6c 65 20 69 Each SQL table i
f3c0: 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e s represented in
f3d0: 20 6d 65 6d 6f 72 79 20 62 79 20 61 6e 20 69 6e memory by an in
f3e0: 73 74 61 6e 63 65 20 6f 66 20 74 68 65 0a 2a 2a stance of the.**
f3f0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
f400: 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 61 62 6c ture..**.** Tabl
f410: 65 2e 7a 4e 61 6d 65 20 69 73 20 74 68 65 20 6e e.zName is the n
f420: 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 ame of the table
f430: 2e 20 20 54 68 65 20 63 61 73 65 20 6f 66 20 74 . The case of t
f440: 68 65 20 6f 72 69 67 69 6e 61 6c 0a 2a 2a 20 43 he original.** C
f450: 52 45 41 54 45 20 54 41 42 4c 45 20 73 74 61 74 REATE TABLE stat
f460: 65 6d 65 6e 74 20 69 73 20 73 74 6f 72 65 64 2c ement is stored,
f470: 20 62 75 74 20 63 61 73 65 20 69 73 20 6e 6f 74 but case is not
f480: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 66 6f 72 significant for
f490: 0a 2a 2a 20 63 6f 6d 70 61 72 69 73 6f 6e 73 2e .** comparisons.
f4a0: 0a 2a 2a 0a 2a 2a 20 54 61 62 6c 65 2e 6e 43 6f .**.** Table.nCo
f4b0: 6c 20 69 73 20 74 68 65 20 6e 75 6d 62 65 72 20 l is the number
f4c0: 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
f4d0: 69 73 20 74 61 62 6c 65 2e 20 20 54 61 62 6c 65 is table. Table
f4e0: 2e 61 43 6f 6c 20 69 73 20 61 0a 2a 2a 20 70 6f .aCol is a.** po
f4f0: 69 6e 74 65 72 20 74 6f 20 61 6e 20 61 72 72 61 inter to an arra
f500: 79 20 6f 66 20 43 6f 6c 75 6d 6e 20 73 74 72 75 y of Column stru
f510: 63 74 75 72 65 73 2c 20 6f 6e 65 20 66 6f 72 20 ctures, one for
f520: 65 61 63 68 20 63 6f 6c 75 6d 6e 2e 0a 2a 2a 0a each column..**.
f530: 2a 2a 20 49 66 20 74 68 65 20 74 61 62 6c 65 20 ** If the table
f540: 68 61 73 20 61 6e 20 49 4e 54 45 47 45 52 20 50 has an INTEGER P
f550: 52 49 4d 41 52 59 20 4b 45 59 2c 20 74 68 65 6e RIMARY KEY, then
f560: 20 54 61 62 6c 65 2e 69 50 4b 65 79 20 69 73 20 Table.iPKey is
f570: 74 68 65 20 69 6e 64 65 78 20 6f 66 0a 2a 2a 20 the index of.**
f580: 74 68 65 20 63 6f 6c 75 6d 6e 20 74 68 61 74 20 the column that
f590: 69 73 20 74 68 61 74 20 6b 65 79 2e 20 20 20 4f is that key. O
f5a0: 74 68 65 72 77 69 73 65 20 54 61 62 6c 65 2e 69 therwise Table.i
f5b0: 50 4b 65 79 20 69 73 20 6e 65 67 61 74 69 76 65 PKey is negative
f5c0: 2e 20 20 4e 6f 74 65 0a 2a 2a 20 74 68 61 74 20 . Note.** that
f5d0: 74 68 65 20 64 61 74 61 74 79 70 65 20 6f 66 20 the datatype of
f5e0: 74 68 65 20 50 52 49 4d 41 52 59 20 4b 45 59 20 the PRIMARY KEY
f5f0: 6d 75 73 74 20 62 65 20 49 4e 54 45 47 45 52 20 must be INTEGER
f600: 66 6f 72 20 74 68 69 73 20 66 69 65 6c 64 20 74 for this field t
f610: 6f 0a 2a 2a 20 62 65 20 73 65 74 2e 20 20 41 6e o.** be set. An
f620: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
f630: 20 4b 45 59 20 69 73 20 75 73 65 64 20 61 73 20 KEY is used as
f640: 74 68 65 20 72 6f 77 69 64 20 66 6f 72 20 65 61 the rowid for ea
f650: 63 68 20 72 6f 77 20 6f 66 0a 2a 2a 20 74 68 65 ch row of.** the
f660: 20 74 61 62 6c 65 2e 20 20 49 66 20 61 20 74 61 table. If a ta
f670: 62 6c 65 20 68 61 73 20 6e 6f 20 49 4e 54 45 47 ble has no INTEG
f680: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 ER PRIMARY KEY,
f690: 74 68 65 6e 20 61 20 72 61 6e 64 6f 6d 20 72 6f then a random ro
f6a0: 77 69 64 0a 2a 2a 20 69 73 20 67 65 6e 65 72 61 wid.** is genera
f6b0: 74 65 64 20 66 6f 72 20 65 61 63 68 20 72 6f 77 ted for each row
f6c0: 20 6f 66 20 74 68 65 20 74 61 62 6c 65 2e 20 20 of the table.
f6d0: 54 46 5f 48 61 73 50 72 69 6d 61 72 79 4b 65 79 TF_HasPrimaryKey
f6e0: 20 69 73 20 73 65 74 20 69 66 0a 2a 2a 20 74 68 is set if.** th
f6f0: 65 20 74 61 62 6c 65 20 68 61 73 20 61 6e 79 20 e table has any
f700: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 49 4e 54 PRIMARY KEY, INT
f710: 45 47 45 52 20 6f 72 20 6f 74 68 65 72 77 69 73 EGER or otherwis
f720: 65 2e 0a 2a 2a 0a 2a 2a 20 54 61 62 6c 65 2e 74 e..**.** Table.t
f730: 6e 75 6d 20 69 73 20 74 68 65 20 70 61 67 65 20 num is the page
f740: 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 65 20 72 number for the r
f750: 6f 6f 74 20 42 54 72 65 65 20 70 61 67 65 20 6f oot BTree page o
f760: 66 20 74 68 65 20 74 61 62 6c 65 20 69 6e 20 74 f the table in t
f770: 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 66 he.** database f
f780: 69 6c 65 2e 20 20 49 66 20 54 61 62 6c 65 2e 69 ile. If Table.i
f790: 44 62 20 69 73 20 74 68 65 20 69 6e 64 65 78 20 Db is the index
f7a0: 6f 66 20 74 68 65 20 64 61 74 61 62 61 73 65 20 of the database
f7b0: 74 61 62 6c 65 20 62 61 63 6b 65 6e 64 0a 2a 2a table backend.**
f7c0: 20 69 6e 20 73 71 6c 69 74 65 2e 61 44 62 5b 5d in sqlite.aDb[]
f7d0: 2e 20 20 30 20 69 73 20 66 6f 72 20 74 68 65 20 . 0 is for the
f7e0: 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 61 6e main database an
f7f0: 64 20 31 20 69 73 20 66 6f 72 20 74 68 65 20 66 d 1 is for the f
f800: 69 6c 65 20 74 68 61 74 0a 2a 2a 20 68 6f 6c 64 ile that.** hold
f810: 73 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c s temporary tabl
f820: 65 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 20 es and indices.
f830: 20 49 66 20 54 46 5f 45 70 68 65 6d 65 72 61 6c If TF_Ephemeral
f840: 20 69 73 20 73 65 74 0a 2a 2a 20 74 68 65 6e 20 is set.** then
f850: 74 68 65 20 74 61 62 6c 65 20 69 73 20 73 74 6f the table is sto
f860: 72 65 64 20 69 6e 20 61 20 66 69 6c 65 20 74 68 red in a file th
f870: 61 74 20 69 73 20 61 75 74 6f 6d 61 74 69 63 61 at is automatica
f880: 6c 6c 79 20 64 65 6c 65 74 65 64 0a 2a 2a 20 77 lly deleted.** w
f890: 68 65 6e 20 74 68 65 20 56 44 42 45 20 63 75 72 hen the VDBE cur
f8a0: 73 6f 72 20 74 6f 20 74 68 65 20 74 61 62 6c 65 sor to the table
f8b0: 20 69 73 20 63 6c 6f 73 65 64 2e 20 20 49 6e 20 is closed. In
f8c0: 74 68 69 73 20 63 61 73 65 20 54 61 62 6c 65 2e this case Table.
f8d0: 74 6e 75 6d 20 0a 2a 2a 20 72 65 66 65 72 73 20 tnum .** refers
f8e0: 56 44 42 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 VDBE cursor numb
f8f0: 65 72 20 74 68 61 74 20 68 6f 6c 64 73 20 74 68 er that holds th
f900: 65 20 74 61 62 6c 65 20 6f 70 65 6e 2c 20 6e 6f e table open, no
f910: 74 20 74 6f 20 74 68 65 20 72 6f 6f 74 0a 2a 2a t to the root.**
f920: 20 70 61 67 65 20 6e 75 6d 62 65 72 2e 20 20 54 page number. T
f930: 72 61 6e 73 69 65 6e 74 20 74 61 62 6c 65 73 20 ransient tables
f940: 61 72 65 20 75 73 65 64 20 74 6f 20 68 6f 6c 64 are used to hold
f950: 20 74 68 65 20 72 65 73 75 6c 74 73 20 6f 66 20 the results of
f960: 61 0a 2a 2a 20 73 75 62 2d 71 75 65 72 79 20 74 a.** sub-query t
f970: 68 61 74 20 61 70 70 65 61 72 73 20 69 6e 73 74 hat appears inst
f980: 65 61 64 20 6f 66 20 61 20 72 65 61 6c 20 74 61 ead of a real ta
f990: 62 6c 65 20 6e 61 6d 65 20 69 6e 20 74 68 65 20 ble name in the
f9a0: 46 52 4f 4d 20 63 6c 61 75 73 65 20 0a 2a 2a 20 FROM clause .**
f9b0: 6f 66 20 61 20 53 45 4c 45 43 54 20 73 74 61 74 of a SELECT stat
f9c0: 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 ement..*/.struct
f9d0: 20 54 61 62 6c 65 20 7b 0a 20 20 63 68 61 72 20 Table {. char
f9e0: 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
f9f0: 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 /* Name of the t
fa00: 61 62 6c 65 20 6f 72 20 76 69 65 77 20 2a 2f 0a able or view */.
fa10: 20 20 43 6f 6c 75 6d 6e 20 2a 61 43 6f 6c 3b 20 Column *aCol;
fa20: 20 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d /* Inform
fa30: 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 ation about each
fa40: 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 column */. Ind
fa50: 65 78 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 20 ex *pIndex;
fa60: 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 53 51 4c /* List of SQL
fa70: 20 69 6e 64 65 78 65 73 20 6f 6e 20 74 68 69 73 indexes on this
fa80: 20 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 53 65 6c table. */. Sel
fa90: 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 ect *pSelect;
faa0: 20 20 2f 2a 20 4e 55 4c 4c 20 66 6f 72 20 74 61 /* NULL for ta
fab0: 62 6c 65 73 2e 20 20 50 6f 69 6e 74 73 20 74 6f bles. Points to
fac0: 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 66 20 61 definition if a
fad0: 20 76 69 65 77 2e 20 2a 2f 0a 20 20 46 4b 65 79 view. */. FKey
fae0: 20 2a 70 46 4b 65 79 3b 20 20 20 20 20 20 20 20 *pFKey;
faf0: 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 /* Linked list
fb00: 6f 66 20 61 6c 6c 20 66 6f 72 65 69 67 6e 20 6b of all foreign k
fb10: 65 79 73 20 69 6e 20 74 68 69 73 20 74 61 62 6c eys in this tabl
fb20: 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f e */. char *zCo
fb30: 6c 41 66 66 3b 20 20 20 20 20 20 20 2f 2a 20 53 lAff; /* S
fb40: 74 72 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 tring defining t
fb50: 68 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 he affinity of e
fb60: 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 69 ach column */.#i
fb70: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
fb80: 54 5f 43 48 45 43 4b 0a 20 20 45 78 70 72 4c 69 T_CHECK. ExprLi
fb90: 73 74 20 2a 70 43 68 65 63 6b 3b 20 20 20 20 2f st *pCheck; /
fba0: 2a 20 41 6c 6c 20 43 48 45 43 4b 20 63 6f 6e 73 * All CHECK cons
fbb0: 74 72 61 69 6e 74 73 20 2a 2f 0a 23 65 6e 64 69 traints */.#endi
fbc0: 66 0a 20 20 4c 6f 67 45 73 74 20 6e 52 6f 77 4c f. LogEst nRowL
fbd0: 6f 67 45 73 74 3b 20 20 20 2f 2a 20 45 73 74 69 ogEst; /* Esti
fbe0: 6d 61 74 65 64 20 72 6f 77 73 20 69 6e 20 74 61 mated rows in ta
fbf0: 62 6c 65 20 2d 20 66 72 6f 6d 20 73 71 6c 69 74 ble - from sqlit
fc00: 65 5f 73 74 61 74 31 20 74 61 62 6c 65 20 2a 2f e_stat1 table */
fc10: 0a 20 20 69 6e 74 20 74 6e 75 6d 3b 20 20 20 20 . int tnum;
fc20: 20 20 20 20 20 20 20 20 2f 2a 20 52 6f 6f 74 20 /* Root
fc30: 42 54 72 65 65 20 6e 6f 64 65 20 66 6f 72 20 74 BTree node for t
fc40: 68 69 73 20 74 61 62 6c 65 20 28 73 65 65 20 6e his table (see n
fc50: 6f 74 65 20 61 62 6f 76 65 29 20 2a 2f 0a 20 20 ote above) */.
fc60: 69 31 36 20 69 50 4b 65 79 3b 20 20 20 20 20 20 i16 iPKey;
fc70: 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f 74 20 6e /* If not n
fc80: 65 67 61 74 69 76 65 2c 20 75 73 65 20 61 43 6f egative, use aCo
fc90: 6c 5b 69 50 4b 65 79 5d 20 61 73 20 74 68 65 20 l[iPKey] as the
fca0: 70 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 20 primary key */.
fcb0: 20 69 31 36 20 6e 43 6f 6c 3b 20 20 20 20 20 20 i16 nCol;
fcc0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
fcd0: 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
fce0: 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 75 31 is table */. u1
fcf0: 36 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 6 nRef;
fd00: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
fd10: 70 6f 69 6e 74 65 72 73 20 74 6f 20 74 68 69 73 pointers to this
fd20: 20 54 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 Table */. LogE
fd30: 73 74 20 73 7a 54 61 62 52 6f 77 3b 20 20 20 20 st szTabRow;
fd40: 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 73 69 /* Estimated si
fd50: 7a 65 20 6f 66 20 65 61 63 68 20 74 61 62 6c 65 ze of each table
fd60: 20 72 6f 77 20 69 6e 20 62 79 74 65 73 20 2a 2f row in bytes */
fd70: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
fd80: 4e 41 42 4c 45 5f 43 4f 53 54 4d 55 4c 54 0a 20 NABLE_COSTMULT.
fd90: 20 4c 6f 67 45 73 74 20 63 6f 73 74 4d 75 6c 74 LogEst costMult
fda0: 3b 20 20 20 20 20 2f 2a 20 43 6f 73 74 20 6d 75 ; /* Cost mu
fdb0: 6c 74 69 70 6c 69 65 72 20 66 6f 72 20 75 73 69 ltiplier for usi
fdc0: 6e 67 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f ng this table */
fdd0: 0a 23 65 6e 64 69 66 0a 20 20 75 38 20 74 61 62 .#endif. u8 tab
fde0: 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 2f Flags; /
fdf0: 2a 20 4d 61 73 6b 20 6f 66 20 54 46 5f 2a 20 76 * Mask of TF_* v
fe00: 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 6b 65 alues */. u8 ke
fe10: 79 43 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 20 yConf;
fe20: 2f 2a 20 57 68 61 74 20 74 6f 20 64 6f 20 69 6e /* What to do in
fe30: 20 63 61 73 65 20 6f 66 20 75 6e 69 71 75 65 6e case of uniquen
fe40: 65 73 73 20 63 6f 6e 66 6c 69 63 74 20 6f 6e 20 ess conflict on
fe50: 69 50 4b 65 79 20 2a 2f 0a 23 69 66 6e 64 65 66 iPKey */.#ifndef
fe60: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 4c 54 SQLITE_OMIT_ALT
fe70: 45 52 54 41 42 4c 45 0a 20 20 69 6e 74 20 61 64 ERTABLE. int ad
fe80: 64 43 6f 6c 4f 66 66 73 65 74 3b 20 20 20 20 2f dColOffset; /
fe90: 2a 20 4f 66 66 73 65 74 20 69 6e 20 43 52 45 41 * Offset in CREA
fea0: 54 45 20 54 41 42 4c 45 20 73 74 6d 74 20 74 6f TE TABLE stmt to
feb0: 20 61 64 64 20 61 20 6e 65 77 20 63 6f 6c 75 6d add a new colum
fec0: 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e n */.#endif.#ifn
fed0: 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
fee0: 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 VIRTUALTABLE. i
fef0: 6e 74 20 6e 4d 6f 64 75 6c 65 41 72 67 3b 20 20 nt nModuleArg;
ff00: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
ff10: 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 74 68 arguments to th
ff20: 65 20 6d 6f 64 75 6c 65 20 2a 2f 0a 20 20 63 68 e module */. ch
ff30: 61 72 20 2a 2a 61 7a 4d 6f 64 75 6c 65 41 72 67 ar **azModuleArg
ff40: 3b 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 61 6c ; /* Text of al
ff50: 6c 20 6d 6f 64 75 6c 65 20 61 72 67 73 2e 20 5b l module args. [
ff60: 30 5d 20 69 73 20 6d 6f 64 75 6c 65 20 6e 61 6d 0] is module nam
ff70: 65 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 e */. VTable *p
ff80: 56 54 61 62 6c 65 3b 20 20 20 20 20 2f 2a 20 4c VTable; /* L
ff90: 69 73 74 20 6f 66 20 56 54 61 62 6c 65 20 6f 62 ist of VTable ob
ffa0: 6a 65 63 74 73 2e 20 2a 2f 0a 23 65 6e 64 69 66 jects. */.#endif
ffb0: 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 . Trigger *pTri
ffc0: 67 67 65 72 3b 20 20 20 2f 2a 20 4c 69 73 74 20 gger; /* List
ffd0: 6f 66 20 74 72 69 67 67 65 72 73 20 73 74 6f 72 of triggers stor
ffe0: 65 64 20 69 6e 20 70 53 63 68 65 6d 61 20 2a 2f ed in pSchema */
fff0: 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 . Schema *pSche
10000 6d 61 3b 20 20 20 20 20 2f 2a 20 53 63 68 65 6d ma; /* Schem
10010 61 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 a that contains
10020 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 this table */.
10030 54 61 62 6c 65 20 2a 70 4e 65 78 74 5a 6f 6d 62 Table *pNextZomb
10040 69 65 3b 20 20 2f 2a 20 4e 65 78 74 20 6f 6e 20 ie; /* Next on
10050 74 68 65 20 50 61 72 73 65 2e 70 5a 6f 6d 62 69 the Parse.pZombi
10060 65 54 61 62 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a eTab list */.};.
10070 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 ./*.** Allowed v
10080 61 6c 75 65 73 20 66 6f 72 20 54 61 62 6c 65 2e alues for Table.
10090 74 61 62 46 6c 61 67 73 2e 0a 2a 2f 0a 23 64 65 tabFlags..*/.#de
100a0 66 69 6e 65 20 54 46 5f 52 65 61 64 6f 6e 6c 79 fine TF_Readonly
100b0 20 20 20 20 20 20 20 20 30 78 30 31 20 20 20 20 0x01
100c0 2f 2a 20 52 65 61 64 2d 6f 6e 6c 79 20 73 79 73 /* Read-only sys
100d0 74 65 6d 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 tem table */.#de
100e0 66 69 6e 65 20 54 46 5f 45 70 68 65 6d 65 72 61 fine TF_Ephemera
100f0 6c 20 20 20 20 20 20 20 30 78 30 32 20 20 20 20 l 0x02
10100 2f 2a 20 41 6e 20 65 70 68 65 6d 65 72 61 6c 20 /* An ephemeral
10110 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 table */.#define
10120 20 54 46 5f 48 61 73 50 72 69 6d 61 72 79 4b 65 TF_HasPrimaryKe
10130 79 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 54 y 0x04 /* T
10140 61 62 6c 65 20 68 61 73 20 61 20 70 72 69 6d 61 able has a prima
10150 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 6e ry key */.#defin
10160 65 20 54 46 5f 41 75 74 6f 69 6e 63 72 65 6d 65 e TF_Autoincreme
10170 6e 74 20 20 20 30 78 30 38 20 20 20 20 2f 2a 20 nt 0x08 /*
10180 49 6e 74 65 67 65 72 20 70 72 69 6d 61 72 79 20 Integer primary
10190 6b 65 79 20 69 73 20 61 75 74 6f 69 6e 63 72 65 key is autoincre
101a0 6d 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ment */.#define
101b0 54 46 5f 56 69 72 74 75 61 6c 20 20 20 20 20 20 TF_Virtual
101c0 20 20 20 30 78 31 30 20 20 20 20 2f 2a 20 49 73 0x10 /* Is
101d0 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 a virtual table
101e0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 57 */.#define TF_W
101f0 69 74 68 6f 75 74 52 6f 77 69 64 20 20 20 20 30 ithoutRowid 0
10200 78 32 30 20 20 20 20 2f 2a 20 4e 6f 20 72 6f 77 x20 /* No row
10210 69 64 20 75 73 65 64 2e 20 50 52 49 4d 41 52 59 id used. PRIMARY
10220 20 4b 45 59 20 69 73 20 74 68 65 20 6b 65 79 20 KEY is the key
10230 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 65 73 74 20 */.../*.** Test
10240 74 6f 20 73 65 65 20 77 68 65 74 68 65 72 20 6f to see whether o
10250 72 20 6e 6f 74 20 61 20 74 61 62 6c 65 20 69 73 r not a table is
10260 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 a virtual table
10270 2e 20 20 54 68 69 73 20 69 73 0a 2a 2a 20 64 6f . This is.** do
10280 6e 65 20 61 73 20 61 20 6d 61 63 72 6f 20 73 6f ne as a macro so
10290 20 74 68 61 74 20 69 74 20 77 69 6c 6c 20 62 65 that it will be
102a0 20 6f 70 74 69 6d 69 7a 65 64 20 6f 75 74 20 77 optimized out w
102b0 68 65 6e 20 76 69 72 74 75 61 6c 0a 2a 2a 20 74 hen virtual.** t
102c0 61 62 6c 65 20 73 75 70 70 6f 72 74 20 69 73 20 able support is
102d0 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 omitted from the
102e0 20 62 75 69 6c 64 2e 0a 2a 2f 0a 23 69 66 6e 64 build..*/.#ifnd
102f0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 ef SQLITE_OMIT_V
10300 49 52 54 55 41 4c 54 41 42 4c 45 0a 23 20 20 64 IRTUALTABLE.# d
10310 65 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 efine IsVirtual(
10320 58 29 20 20 20 20 20 20 28 28 28 58 29 2d 3e 74 X) (((X)->t
10330 61 62 46 6c 61 67 73 20 26 20 54 46 5f 56 69 72 abFlags & TF_Vir
10340 74 75 61 6c 29 21 3d 30 29 0a 23 20 20 64 65 66 tual)!=0).# def
10350 69 6e 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 ine IsHiddenColu
10360 6d 6e 28 58 29 20 28 28 28 58 29 2d 3e 63 6f 6c mn(X) (((X)->col
10370 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f Flags & COLFLAG_
10380 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 65 6c 73 HIDDEN)!=0).#els
10390 65 0a 23 20 20 64 65 66 69 6e 65 20 49 73 56 69 e.# define IsVi
103a0 72 74 75 61 6c 28 58 29 20 20 20 20 20 20 30 0a rtual(X) 0.
103b0 23 20 20 64 65 66 69 6e 65 20 49 73 48 69 64 64 # define IsHidd
103c0 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 30 0a 23 65 enColumn(X) 0.#e
103d0 6e 64 69 66 0a 0a 2f 2a 20 44 6f 65 73 20 74 68 ndif../* Does th
103e0 65 20 74 61 62 6c 65 20 68 61 76 65 20 61 20 72 e table have a r
103f0 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 owid */.#define
10400 48 61 73 52 6f 77 69 64 28 58 29 20 20 20 20 20 HasRowid(X)
10410 28 28 28 58 29 2d 3e 74 61 62 46 6c 61 67 73 20 (((X)->tabFlags
10420 26 20 54 46 5f 57 69 74 68 6f 75 74 52 6f 77 69 & TF_WithoutRowi
10430 64 29 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 d)==0)../*.** Ea
10440 63 68 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 63 ch foreign key c
10450 6f 6e 73 74 72 61 69 6e 74 20 69 73 20 61 6e 20 onstraint is an
10460 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
10470 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
10480 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 41 20 66 6f 72 ure..**.** A for
10490 65 69 67 6e 20 6b 65 79 20 69 73 20 61 73 73 6f eign key is asso
104a0 63 69 61 74 65 64 20 77 69 74 68 20 74 77 6f 20 ciated with two
104b0 74 61 62 6c 65 73 2e 20 20 54 68 65 20 22 66 72 tables. The "fr
104c0 6f 6d 22 20 74 61 62 6c 65 20 69 73 0a 2a 2a 20 om" table is.**
104d0 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 20 63 the table that c
104e0 6f 6e 74 61 69 6e 73 20 74 68 65 20 52 45 46 45 ontains the REFE
104f0 52 45 4e 43 45 53 20 63 6c 61 75 73 65 20 74 68 RENCES clause th
10500 61 74 20 63 72 65 61 74 65 73 20 74 68 65 20 66 at creates the f
10510 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 2e 20 20 oreign.** key.
10520 54 68 65 20 22 74 6f 22 20 74 61 62 6c 65 20 69 The "to" table i
10530 73 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 s the table that
10540 20 69 73 20 6e 61 6d 65 64 20 69 6e 20 74 68 65 is named in the
10550 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 75 REFERENCES clau
10560 73 65 2e 0a 2a 2a 20 43 6f 6e 73 69 64 65 72 20 se..** Consider
10570 74 68 69 73 20 65 78 61 6d 70 6c 65 3a 0a 2a 2a this example:.**
10580 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 54 .** CREATE T
10590 41 42 4c 45 20 65 78 31 28 0a 2a 2a 20 20 20 20 ABLE ex1(.**
105a0 20 20 20 61 20 49 4e 54 45 47 45 52 20 50 52 49 a INTEGER PRI
105b0 4d 41 52 59 20 4b 45 59 2c 0a 2a 2a 20 20 20 20 MARY KEY,.**
105c0 20 20 20 62 20 49 4e 54 45 47 45 52 20 43 4f 4e b INTEGER CON
105d0 53 54 52 41 49 4e 54 20 66 6b 31 20 52 45 46 45 STRAINT fk1 REFE
105e0 52 45 4e 43 45 53 20 65 78 32 28 78 29 0a 2a 2a RENCES ex2(x).**
105f0 20 20 20 20 20 29 3b 0a 2a 2a 0a 2a 2a 20 46 6f );.**.** Fo
10600 72 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 22 66 r foreign key "f
10610 6b 31 22 2c 20 74 68 65 20 66 72 6f 6d 2d 74 61 k1", the from-ta
10620 62 6c 65 20 69 73 20 22 65 78 31 22 20 61 6e 64 ble is "ex1" and
10630 20 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 69 73 the to-table is
10640 20 22 65 78 32 22 2e 0a 2a 2a 20 45 71 75 69 76 "ex2"..** Equiv
10650 61 6c 65 6e 74 20 6e 61 6d 65 73 3a 0a 2a 2a 0a alent names:.**.
10660 2a 2a 20 20 20 20 20 66 72 6f 6d 2d 74 61 62 6c ** from-tabl
10670 65 20 3d 3d 20 63 68 69 6c 64 2d 74 61 62 6c 65 e == child-table
10680 0a 2a 2a 20 20 20 20 20 20 20 74 6f 2d 74 61 62 .** to-tab
10690 6c 65 20 3d 3d 20 70 61 72 65 6e 74 2d 74 61 62 le == parent-tab
106a0 6c 65 0a 2a 2a 0a 2a 2a 20 45 61 63 68 20 52 45 le.**.** Each RE
106b0 46 45 52 45 4e 43 45 53 20 63 6c 61 75 73 65 20 FERENCES clause
106c0 67 65 6e 65 72 61 74 65 73 20 61 6e 20 69 6e 73 generates an ins
106d0 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
106e0 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
106f0 0a 2a 2a 20 77 68 69 63 68 20 69 73 20 61 74 74 .** which is att
10700 61 63 68 65 64 20 74 6f 20 74 68 65 20 66 72 6f ached to the fro
10710 6d 2d 74 61 62 6c 65 2e 20 20 54 68 65 20 74 6f m-table. The to
10720 2d 74 61 62 6c 65 20 6e 65 65 64 20 6e 6f 74 20 -table need not
10730 65 78 69 73 74 20 77 68 65 6e 0a 2a 2a 20 74 68 exist when.** th
10740 65 20 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 e from-table is
10750 63 72 65 61 74 65 64 2e 20 20 54 68 65 20 65 78 created. The ex
10760 69 73 74 65 6e 63 65 20 6f 66 20 74 68 65 20 74 istence of the t
10770 6f 2d 74 61 62 6c 65 20 69 73 20 6e 6f 74 20 63 o-table is not c
10780 68 65 63 6b 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 hecked..**.** Th
10790 65 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 70 61 e list of all pa
107a0 72 65 6e 74 73 20 66 6f 72 20 63 68 69 6c 64 20 rents for child
107b0 54 61 62 6c 65 20 58 20 69 73 20 68 65 6c 64 20 Table X is held
107c0 61 74 20 58 2e 70 46 4b 65 79 2e 0a 2a 2a 0a 2a at X.pFKey..**.*
107d0 2a 20 41 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 * A list of all
107e0 63 68 69 6c 64 72 65 6e 20 66 6f 72 20 61 20 74 children for a t
107f0 61 62 6c 65 20 6e 61 6d 65 64 20 5a 20 28 77 68 able named Z (wh
10800 69 63 68 20 6d 69 67 68 74 20 6e 6f 74 20 65 76 ich might not ev
10810 65 6e 20 65 78 69 73 74 29 0a 2a 2a 20 69 73 20 en exist).** is
10820 68 65 6c 64 20 69 6e 20 53 63 68 65 6d 61 2e 66 held in Schema.f
10830 6b 65 79 48 61 73 68 20 77 69 74 68 20 61 20 68 keyHash with a h
10840 61 73 68 20 6b 65 79 20 6f 66 20 5a 2e 0a 2a 2f ash key of Z..*/
10850 0a 73 74 72 75 63 74 20 46 4b 65 79 20 7b 0a 20 .struct FKey {.
10860 20 54 61 62 6c 65 20 2a 70 46 72 6f 6d 3b 20 20 Table *pFrom;
10870 20 20 20 2f 2a 20 54 61 62 6c 65 20 63 6f 6e 74 /* Table cont
10880 61 69 6e 69 6e 67 20 74 68 65 20 52 45 46 45 52 aining the REFER
10890 45 4e 43 45 53 20 63 6c 61 75 73 65 20 28 61 6b ENCES clause (ak
108a0 61 3a 20 43 68 69 6c 64 29 20 2a 2f 0a 20 20 46 a: Child) */. F
108b0 4b 65 79 20 2a 70 4e 65 78 74 46 72 6f 6d 3b 20 Key *pNextFrom;
108c0 20 2f 2a 20 4e 65 78 74 20 46 4b 65 79 20 77 69 /* Next FKey wi
108d0 74 68 20 74 68 65 20 73 61 6d 65 20 69 6e 20 70 th the same in p
108e0 46 72 6f 6d 2e 20 4e 65 78 74 20 70 61 72 65 6e From. Next paren
108f0 74 20 6f 66 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 t of pFrom */.
10900 63 68 61 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20 char *zTo;
10910 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 61 62 /* Name of tab
10920 6c 65 20 74 68 61 74 20 74 68 65 20 6b 65 79 20 le that the key
10930 70 6f 69 6e 74 73 20 74 6f 20 28 61 6b 61 3a 20 points to (aka:
10940 50 61 72 65 6e 74 29 20 2a 2f 0a 20 20 46 4b 65 Parent) */. FKe
10950 79 20 2a 70 4e 65 78 74 54 6f 3b 20 20 20 20 2f y *pNextTo; /
10960 2a 20 4e 65 78 74 20 77 69 74 68 20 74 68 65 20 * Next with the
10970 73 61 6d 65 20 7a 54 6f 2e 20 4e 65 78 74 20 63 same zTo. Next c
10980 68 69 6c 64 20 6f 66 20 7a 54 6f 2e 20 2a 2f 0a hild of zTo. */.
10990 20 20 46 4b 65 79 20 2a 70 50 72 65 76 54 6f 3b FKey *pPrevTo;
109a0 20 20 20 20 2f 2a 20 50 72 65 76 69 6f 75 73 20 /* Previous
109b0 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 7a 54 with the same zT
109c0 6f 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 6f 6c 3b o */. int nCol;
109d0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
109e0 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
109f0 20 74 68 69 73 20 6b 65 79 20 2a 2f 0a 20 20 2f this key */. /
10a00 2a 20 45 56 3a 20 52 2d 33 30 33 32 33 2d 32 31 * EV: R-30323-21
10a10 39 31 37 20 2a 2f 0a 20 20 75 38 20 69 73 44 65 917 */. u8 isDe
10a20 66 65 72 72 65 64 3b 20 20 20 20 20 20 20 2f 2a ferred; /*
10a30 20 54 72 75 65 20 69 66 20 63 6f 6e 73 74 72 61 True if constra
10a40 69 6e 74 20 63 68 65 63 6b 69 6e 67 20 69 73 20 int checking is
10a50 64 65 66 65 72 72 65 64 20 74 69 6c 6c 20 43 4f deferred till CO
10a60 4d 4d 49 54 20 2a 2f 0a 20 20 75 38 20 61 41 63 MMIT */. u8 aAc
10a70 74 69 6f 6e 5b 32 5d 3b 20 20 20 20 20 20 20 20 tion[2];
10a80 2f 2a 20 4f 4e 20 44 45 4c 45 54 45 20 61 6e 64 /* ON DELETE and
10a90 20 4f 4e 20 55 50 44 41 54 45 20 61 63 74 69 6f ON UPDATE actio
10aa0 6e 73 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 ns, respectively
10ab0 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 61 */. Trigger *a
10ac0 70 54 72 69 67 67 65 72 5b 32 5d 3b 2f 2a 20 54 pTrigger[2];/* T
10ad0 72 69 67 67 65 72 73 20 66 6f 72 20 61 41 63 74 riggers for aAct
10ae0 69 6f 6e 5b 5d 20 61 63 74 69 6f 6e 73 20 2a 2f ion[] actions */
10af0 0a 20 20 73 74 72 75 63 74 20 73 43 6f 6c 4d 61 . struct sColMa
10b00 70 20 7b 20 20 20 20 20 20 2f 2a 20 4d 61 70 70 p { /* Mapp
10b10 69 6e 67 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 ing of columns i
10b20 6e 20 70 46 72 6f 6d 20 74 6f 20 63 6f 6c 75 6d n pFrom to colum
10b30 6e 73 20 69 6e 20 7a 54 6f 20 2a 2f 0a 20 20 20 ns in zTo */.
10b40 20 69 6e 74 20 69 46 72 6f 6d 3b 20 20 20 20 20 int iFrom;
10b50 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 /* Index
10b60 6f 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 70 46 72 of column in pFr
10b70 6f 6d 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a om */. char *
10b80 7a 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 zCol;
10b90 2f 2a 20 4e 61 6d 65 20 6f 66 20 63 6f 6c 75 6d /* Name of colum
10ba0 6e 20 69 6e 20 7a 54 6f 2e 20 20 49 66 20 4e 55 n in zTo. If NU
10bb0 4c 4c 20 75 73 65 20 50 52 49 4d 41 52 59 20 4b LL use PRIMARY K
10bc0 45 59 20 2a 2f 0a 20 20 7d 20 61 43 6f 6c 5b 31 EY */. } aCol[1
10bd0 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ]; /*
10be0 20 4f 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 One entry for e
10bf0 61 63 68 20 6f 66 20 6e 43 6f 6c 20 63 6f 6c 75 ach of nCol colu
10c00 6d 6e 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a mns */.};../*.**
10c10 20 53 51 4c 69 74 65 20 73 75 70 70 6f 72 74 73 SQLite supports
10c20 20 6d 61 6e 79 20 64 69 66 66 65 72 65 6e 74 20 many different
10c30 77 61 79 73 20 74 6f 20 72 65 73 6f 6c 76 65 20 ways to resolve
10c40 61 20 63 6f 6e 73 74 72 61 69 6e 74 0a 2a 2a 20 a constraint.**
10c50 65 72 72 6f 72 2e 20 20 52 4f 4c 4c 42 41 43 4b error. ROLLBACK
10c60 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e processing mean
10c70 73 20 74 68 61 74 20 61 20 63 6f 6e 73 74 72 61 s that a constra
10c80 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 0a 2a 2a int violation.**
10c90 20 63 61 75 73 65 73 20 74 68 65 20 6f 70 65 72 causes the oper
10ca0 61 74 69 6f 6e 20 69 6e 20 70 72 6f 63 65 73 73 ation in process
10cb0 20 74 6f 20 66 61 69 6c 20 61 6e 64 20 66 6f 72 to fail and for
10cc0 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 72 61 the current tra
10cd0 6e 73 61 63 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 nsaction.** to b
10ce0 65 20 72 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 e rolled back.
10cf0 41 42 4f 52 54 20 70 72 6f 63 65 73 73 69 6e 67 ABORT processing
10d00 20 6d 65 61 6e 73 20 74 68 65 20 6f 70 65 72 61 means the opera
10d10 74 69 6f 6e 20 69 6e 20 70 72 6f 63 65 73 73 0a tion in process.
10d20 2a 2a 20 66 61 69 6c 73 20 61 6e 64 20 61 6e 79 ** fails and any
10d30 20 70 72 69 6f 72 20 63 68 61 6e 67 65 73 20 66 prior changes f
10d40 72 6f 6d 20 74 68 61 74 20 6f 6e 65 20 6f 70 65 rom that one ope
10d50 72 61 74 69 6f 6e 20 61 72 65 20 62 61 63 6b 65 ration are backe
10d60 64 20 6f 75 74 2c 0a 2a 2a 20 62 75 74 20 74 68 d out,.** but th
10d70 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 69 73 e transaction is
10d80 20 6e 6f 74 20 72 6f 6c 6c 65 64 20 62 61 63 6b not rolled back
10d90 2e 20 20 46 41 49 4c 20 70 72 6f 63 65 73 73 69 . FAIL processi
10da0 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 0a 2a 2a ng means that.**
10db0 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 the operation i
10dc0 6e 20 70 72 6f 67 72 65 73 73 20 73 74 6f 70 73 n progress stops
10dd0 20 61 6e 64 20 72 65 74 75 72 6e 73 20 61 6e 20 and returns an
10de0 65 72 72 6f 72 20 63 6f 64 65 2e 20 20 42 75 74 error code. But
10df0 20 70 72 69 6f 72 0a 2a 2a 20 63 68 61 6e 67 65 prior.** change
10e00 73 20 64 75 65 20 74 6f 20 74 68 65 20 73 61 6d s due to the sam
10e10 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 72 65 20 e operation are
10e20 6e 6f 74 20 62 61 63 6b 65 64 20 6f 75 74 20 61 not backed out a
10e30 6e 64 20 6e 6f 20 72 6f 6c 6c 62 61 63 6b 0a 2a nd no rollback.*
10e40 2a 20 6f 63 63 75 72 73 2e 20 20 49 47 4e 4f 52 * occurs. IGNOR
10e50 45 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 E means that the
10e60 20 70 61 72 74 69 63 75 6c 61 72 20 72 6f 77 20 particular row
10e70 74 68 61 74 20 63 61 75 73 65 64 20 74 68 65 20 that caused the
10e80 63 6f 6e 73 74 72 61 69 6e 74 0a 2a 2a 20 65 72 constraint.** er
10e90 72 6f 72 20 69 73 20 6e 6f 74 20 69 6e 73 65 72 ror is not inser
10ea0 74 65 64 20 6f 72 20 75 70 64 61 74 65 64 2e 20 ted or updated.
10eb0 20 50 72 6f 63 65 73 73 69 6e 67 20 63 6f 6e 74 Processing cont
10ec0 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 65 72 72 inues and no err
10ed0 6f 72 0a 2a 2a 20 69 73 20 72 65 74 75 72 6e 65 or.** is returne
10ee0 64 2e 20 20 52 45 50 4c 41 43 45 20 6d 65 61 6e d. REPLACE mean
10ef0 73 20 74 68 61 74 20 70 72 65 65 78 69 73 74 69 s that preexisti
10f00 6e 67 20 64 61 74 61 62 61 73 65 20 72 6f 77 73 ng database rows
10f10 20 74 68 61 74 20 63 61 75 73 65 64 0a 2a 2a 20 that caused.**
10f20 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 a UNIQUE constra
10f30 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 20 61 72 int violation ar
10f40 65 20 72 65 6d 6f 76 65 64 20 73 6f 20 74 68 61 e removed so tha
10f50 74 20 74 68 65 20 6e 65 77 20 69 6e 73 65 72 74 t the new insert
10f60 20 6f 72 0a 2a 2a 20 75 70 64 61 74 65 20 63 61 or.** update ca
10f70 6e 20 70 72 6f 63 65 65 64 2e 20 20 50 72 6f 63 n proceed. Proc
10f80 65 73 73 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 essing continues
10f90 20 61 6e 64 20 6e 6f 20 65 72 72 6f 72 20 69 73 and no error is
10fa0 20 72 65 70 6f 72 74 65 64 2e 0a 2a 2a 0a 2a 2a reported..**.**
10fb0 20 52 45 53 54 52 49 43 54 2c 20 53 45 54 4e 55 RESTRICT, SETNU
10fc0 4c 4c 2c 20 61 6e 64 20 43 41 53 43 41 44 45 20 LL, and CASCADE
10fd0 61 63 74 69 6f 6e 73 20 61 70 70 6c 79 20 6f 6e actions apply on
10fe0 6c 79 20 74 6f 20 66 6f 72 65 69 67 6e 20 6b 65 ly to foreign ke
10ff0 79 73 2e 0a 2a 2a 20 52 45 53 54 52 49 43 54 20 ys..** RESTRICT
11000 69 73 20 74 68 65 20 73 61 6d 65 20 61 73 20 41 is the same as A
11010 42 4f 52 54 20 66 6f 72 20 49 4d 4d 45 44 49 41 BORT for IMMEDIA
11020 54 45 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 TE foreign keys
11030 61 6e 64 20 74 68 65 0a 2a 2a 20 73 61 6d 65 20 and the.** same
11040 61 73 20 52 4f 4c 4c 42 41 43 4b 20 66 6f 72 20 as ROLLBACK for
11050 44 45 46 45 52 52 45 44 20 6b 65 79 73 2e 20 20 DEFERRED keys.
11060 53 45 54 4e 55 4c 4c 20 6d 65 61 6e 73 20 74 68 SETNULL means th
11070 61 74 20 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a at the foreign.*
11080 2a 20 6b 65 79 20 69 73 20 73 65 74 20 74 6f 20 * key is set to
11090 4e 55 4c 4c 2e 20 20 43 41 53 43 41 44 45 20 6d NULL. CASCADE m
110a0 65 61 6e 73 20 74 68 61 74 20 61 20 44 45 4c 45 eans that a DELE
110b0 54 45 20 6f 72 20 55 50 44 41 54 45 20 6f 66 20 TE or UPDATE of
110c0 74 68 65 0a 2a 2a 20 72 65 66 65 72 65 6e 63 65 the.** reference
110d0 64 20 74 61 62 6c 65 20 72 6f 77 20 69 73 20 70 d table row is p
110e0 72 6f 70 61 67 61 74 65 64 20 69 6e 74 6f 20 74 ropagated into t
110f0 68 65 20 72 6f 77 20 74 68 61 74 20 68 6f 6c 64 he row that hold
11100 73 20 74 68 65 0a 2a 2a 20 66 6f 72 65 69 67 6e s the.** foreign
11110 20 6b 65 79 2e 0a 2a 2a 20 0a 2a 2a 20 54 68 65 key..** .** The
11120 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 79 6d 62 6f following symbo
11130 6c 69 63 20 76 61 6c 75 65 73 20 61 72 65 20 75 lic values are u
11140 73 65 64 20 74 6f 20 72 65 63 6f 72 64 20 77 68 sed to record wh
11150 69 63 68 20 74 79 70 65 0a 2a 2a 20 6f 66 20 61 ich type.** of a
11160 63 74 69 6f 6e 20 74 6f 20 74 61 6b 65 2e 0a 2a ction to take..*
11170 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 4e 6f 6e /.#define OE_Non
11180 65 20 20 20 20 20 30 20 20 20 2f 2a 20 54 68 65 e 0 /* The
11190 72 65 20 69 73 20 6e 6f 20 63 6f 6e 73 74 72 61 re is no constra
111a0 69 6e 74 20 74 6f 20 63 68 65 63 6b 20 2a 2f 0a int to check */.
111b0 23 64 65 66 69 6e 65 20 4f 45 5f 52 6f 6c 6c 62 #define OE_Rollb
111c0 61 63 6b 20 31 20 20 20 2f 2a 20 46 61 69 6c 20 ack 1 /* Fail
111d0 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 6e the operation an
111e0 64 20 72 6f 6c 6c 62 61 63 6b 20 74 68 65 20 74 d rollback the t
111f0 72 61 6e 73 61 63 74 69 6f 6e 20 2a 2f 0a 23 64 ransaction */.#d
11200 65 66 69 6e 65 20 4f 45 5f 41 62 6f 72 74 20 20 efine OE_Abort
11210 20 20 32 20 20 20 2f 2a 20 42 61 63 6b 20 6f 75 2 /* Back ou
11220 74 20 63 68 61 6e 67 65 73 20 62 75 74 20 64 6f t changes but do
11230 20 6e 6f 20 72 6f 6c 6c 62 61 63 6b 20 74 72 61 no rollback tra
11240 6e 73 61 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 nsaction */.#def
11250 69 6e 65 20 4f 45 5f 46 61 69 6c 20 20 20 20 20 ine OE_Fail
11260 33 20 20 20 2f 2a 20 53 74 6f 70 20 74 68 65 20 3 /* Stop the
11270 6f 70 65 72 61 74 69 6f 6e 20 62 75 74 20 6c 65 operation but le
11280 61 76 65 20 61 6c 6c 20 70 72 69 6f 72 20 63 68 ave all prior ch
11290 61 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 anges */.#define
112a0 20 4f 45 5f 49 67 6e 6f 72 65 20 20 20 34 20 20 OE_Ignore 4
112b0 20 2f 2a 20 49 67 6e 6f 72 65 20 74 68 65 20 65 /* Ignore the e
112c0 72 72 6f 72 2e 20 44 6f 20 6e 6f 74 20 64 6f 20 rror. Do not do
112d0 74 68 65 20 49 4e 53 45 52 54 20 6f 72 20 55 50 the INSERT or UP
112e0 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 DATE */.#define
112f0 4f 45 5f 52 65 70 6c 61 63 65 20 20 35 20 20 20 OE_Replace 5
11300 2f 2a 20 44 65 6c 65 74 65 20 65 78 69 73 74 69 /* Delete existi
11310 6e 67 20 72 65 63 6f 72 64 2c 20 74 68 65 6e 20 ng record, then
11320 64 6f 20 49 4e 53 45 52 54 20 6f 72 20 55 50 44 do INSERT or UPD
11330 41 54 45 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 ATE */..#define
11340 4f 45 5f 52 65 73 74 72 69 63 74 20 36 20 20 20 OE_Restrict 6
11350 2f 2a 20 4f 45 5f 41 62 6f 72 74 20 66 6f 72 20 /* OE_Abort for
11360 49 4d 4d 45 44 49 41 54 45 2c 20 4f 45 5f 52 6f IMMEDIATE, OE_Ro
11370 6c 6c 62 61 63 6b 20 66 6f 72 20 44 45 46 45 52 llback for DEFER
11380 52 45 44 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f RED */.#define O
11390 45 5f 53 65 74 4e 75 6c 6c 20 20 37 20 20 20 2f E_SetNull 7 /
113a0 2a 20 53 65 74 20 74 68 65 20 66 6f 72 65 69 67 * Set the foreig
113b0 6e 20 6b 65 79 20 76 61 6c 75 65 20 74 6f 20 4e n key value to N
113c0 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ULL */.#define O
113d0 45 5f 53 65 74 44 66 6c 74 20 20 38 20 20 20 2f E_SetDflt 8 /
113e0 2a 20 53 65 74 20 74 68 65 20 66 6f 72 65 69 67 * Set the foreig
113f0 6e 20 6b 65 79 20 76 61 6c 75 65 20 74 6f 20 69 n key value to i
11400 74 73 20 64 65 66 61 75 6c 74 20 2a 2f 0a 23 64 ts default */.#d
11410 65 66 69 6e 65 20 4f 45 5f 43 61 73 63 61 64 65 efine OE_Cascade
11420 20 20 39 20 20 20 2f 2a 20 43 61 73 63 61 64 65 9 /* Cascade
11430 20 74 68 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a the changes */.
11440 0a 23 64 65 66 69 6e 65 20 4f 45 5f 44 65 66 61 .#define OE_Defa
11450 75 6c 74 20 20 31 30 20 20 2f 2a 20 44 6f 20 77 ult 10 /* Do w
11460 68 61 74 65 76 65 72 20 74 68 65 20 64 65 66 61 hatever the defa
11470 75 6c 74 20 61 63 74 69 6f 6e 20 69 73 20 2a 2f ult action is */
11480 0a 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 .../*.** An inst
11490 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c ance of the foll
114a0 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 owing structure
114b0 69 73 20 70 61 73 73 65 64 20 61 73 20 74 68 65 is passed as the
114c0 20 66 69 72 73 74 0a 2a 2a 20 61 72 67 75 6d 65 first.** argume
114d0 6e 74 20 74 6f 20 73 71 6c 69 74 65 33 56 64 62 nt to sqlite3Vdb
114e0 65 4b 65 79 43 6f 6d 70 61 72 65 20 61 6e 64 20 eKeyCompare and
114f0 69 73 20 75 73 65 64 20 74 6f 20 63 6f 6e 74 72 is used to contr
11500 6f 6c 20 74 68 65 20 0a 2a 2a 20 63 6f 6d 70 61 ol the .** compa
11510 72 69 73 6f 6e 20 6f 66 20 74 68 65 20 74 77 6f rison of the two
11520 20 69 6e 64 65 78 20 6b 65 79 73 2e 0a 2a 2a 0a index keys..**.
11530 2a 2a 20 4e 6f 74 65 20 74 68 61 74 20 61 53 6f ** Note that aSo
11540 72 74 4f 72 64 65 72 5b 5d 20 61 6e 64 20 61 43 rtOrder[] and aC
11550 6f 6c 6c 5b 5d 20 68 61 76 65 20 6e 46 69 65 6c oll[] have nFiel
11560 64 2b 31 20 73 6c 6f 74 73 2e 20 20 54 68 65 72 d+1 slots. Ther
11570 65 0a 2a 2a 20 61 72 65 20 6e 46 69 65 6c 64 20 e.** are nField
11580 73 6c 6f 74 73 20 66 6f 72 20 74 68 65 20 63 6f slots for the co
11590 6c 75 6d 6e 73 20 6f 66 20 61 6e 20 69 6e 64 65 lumns of an inde
115a0 78 20 74 68 65 6e 20 6f 6e 65 20 65 78 74 72 61 x then one extra
115b0 20 73 6c 6f 74 0a 2a 2a 20 66 6f 72 20 74 68 65 slot.** for the
115c0 20 72 6f 77 69 64 20 61 74 20 74 68 65 20 65 6e rowid at the en
115d0 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4b 65 79 d..*/.struct Key
115e0 49 6e 66 6f 20 7b 0a 20 20 75 33 32 20 6e 52 65 Info {. u32 nRe
115f0 66 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 f; /*
11600 4e 75 6d 62 65 72 20 6f 66 20 72 65 66 65 72 65 Number of refere
11610 6e 63 65 73 20 74 6f 20 74 68 69 73 20 4b 65 79 nces to this Key
11620 49 6e 66 6f 20 6f 62 6a 65 63 74 20 2a 2f 0a 20 Info object */.
11630 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 20 u8 enc;
11640 20 20 20 20 20 2f 2a 20 54 65 78 74 20 65 6e 63 /* Text enc
11650 6f 64 69 6e 67 20 2d 20 6f 6e 65 20 6f 66 20 74 oding - one of t
11660 68 65 20 53 51 4c 49 54 45 5f 55 54 46 2a 20 76 he SQLITE_UTF* v
11670 61 6c 75 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e alues */. u16 n
11680 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 20 2f Field; /
11690 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6b 65 79 20 * Number of key
116a0 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 69 columns in the i
116b0 6e 64 65 78 20 2a 2f 0a 20 20 75 31 36 20 6e 58 ndex */. u16 nX
116c0 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 2f 2a Field; /*
116d0 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
116e0 6e 73 20 62 65 79 6f 6e 64 20 74 68 65 20 6b 65 ns beyond the ke
116f0 79 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 73 y columns */. s
11700 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 qlite3 *db;
11710 20 20 20 2f 2a 20 54 68 65 20 64 61 74 61 62 61 /* The databa
11720 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 2a 2f se connection */
11730 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 . u8 *aSortOrde
11740 72 3b 20 20 20 20 20 2f 2a 20 53 6f 72 74 20 6f r; /* Sort o
11750 72 64 65 72 20 66 6f 72 20 65 61 63 68 20 63 6f rder for each co
11760 6c 75 6d 6e 2e 20 2a 2f 0a 20 20 43 6f 6c 6c 53 lumn. */. CollS
11770 65 71 20 2a 61 43 6f 6c 6c 5b 31 5d 3b 20 20 2f eq *aColl[1]; /
11780 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 * Collating sequ
11790 65 6e 63 65 20 66 6f 72 20 65 61 63 68 20 74 65 ence for each te
117a0 72 6d 20 6f 66 20 74 68 65 20 6b 65 79 20 2a 2f rm of the key */
117b0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e .};../*.** An in
117c0 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f stance of the fo
117d0 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
117e0 65 20 68 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 74 e holds informat
117f0 69 6f 6e 20 61 62 6f 75 74 20 61 0a 2a 2a 20 73 ion about a.** s
11800 69 6e 67 6c 65 20 69 6e 64 65 78 20 72 65 63 6f ingle index reco
11810 72 64 20 74 68 61 74 20 68 61 73 20 61 6c 72 65 rd that has alre
11820 61 64 79 20 62 65 65 6e 20 70 61 72 73 65 64 20 ady been parsed
11830 6f 75 74 20 69 6e 74 6f 20 69 6e 64 69 76 69 64 out into individ
11840 75 61 6c 0a 2a 2a 20 76 61 6c 75 65 73 2e 0a 2a ual.** values..*
11850 2a 0a 2a 2a 20 41 20 72 65 63 6f 72 64 20 69 73 *.** A record is
11860 20 61 6e 20 6f 62 6a 65 63 74 20 74 68 61 74 20 an object that
11870 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 contains one or
11880 6d 6f 72 65 20 66 69 65 6c 64 73 20 6f 66 20 64 more fields of d
11890 61 74 61 2e 0a 2a 2a 20 52 65 63 6f 72 64 73 20 ata..** Records
118a0 61 72 65 20 75 73 65 64 20 74 6f 20 73 74 6f 72 are used to stor
118b0 65 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 e the content of
118c0 20 61 20 74 61 62 6c 65 20 72 6f 77 20 61 6e 64 a table row and
118d0 20 74 6f 20 73 74 6f 72 65 0a 2a 2a 20 74 68 65 to store.** the
118e0 20 6b 65 79 20 6f 66 20 61 6e 20 69 6e 64 65 78 key of an index
118f0 2e 20 20 41 20 62 6c 6f 62 20 65 6e 63 6f 64 69 . A blob encodi
11900 6e 67 20 6f 66 20 61 20 72 65 63 6f 72 64 20 69 ng of a record i
11910 73 20 63 72 65 61 74 65 64 20 62 79 0a 2a 2a 20 s created by.**
11920 74 68 65 20 4f 50 5f 4d 61 6b 65 52 65 63 6f 72 the OP_MakeRecor
11930 64 20 6f 70 63 6f 64 65 20 6f 66 20 74 68 65 20 d opcode of the
11940 56 44 42 45 20 61 6e 64 20 69 73 20 64 69 73 61 VDBE and is disa
11950 73 73 65 6d 62 6c 65 64 20 62 79 20 74 68 65 0a ssembled by the.
11960 2a 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 70 63 ** OP_Column opc
11970 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 ode..**.** This
11980 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 structure holds
11990 61 20 72 65 63 6f 72 64 20 74 68 61 74 20 68 61 a record that ha
119a0 73 20 61 6c 72 65 61 64 79 20 62 65 65 6e 20 64 s already been d
119b0 69 73 61 73 73 65 6d 62 6c 65 64 0a 2a 2a 20 69 isassembled.** i
119c0 6e 74 6f 20 69 74 73 20 63 6f 6e 73 74 69 74 75 nto its constitu
119d0 65 6e 74 20 66 69 65 6c 64 73 2e 0a 2a 2a 0a 2a ent fields..**.*
119e0 2a 20 54 68 65 20 72 31 20 61 6e 64 20 72 32 20 * The r1 and r2
119f0 6d 65 6d 62 65 72 20 76 61 72 69 61 62 6c 65 73 member variables
11a00 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 64 20 62 are only used b
11a10 79 20 74 68 65 20 6f 70 74 69 6d 69 7a 65 64 20 y the optimized
11a20 63 6f 6d 70 61 72 69 73 6f 6e 0a 2a 2a 20 66 75 comparison.** fu
11a30 6e 63 74 69 6f 6e 73 20 76 64 62 65 52 65 63 6f nctions vdbeReco
11a40 72 64 43 6f 6d 70 61 72 65 49 6e 74 28 29 20 61 rdCompareInt() a
11a50 6e 64 20 76 64 62 65 52 65 63 6f 72 64 43 6f 6d nd vdbeRecordCom
11a60 70 61 72 65 53 74 72 69 6e 67 28 29 2e 0a 2a 2f pareString()..*/
11a70 0a 73 74 72 75 63 74 20 55 6e 70 61 63 6b 65 64 .struct Unpacked
11a80 52 65 63 6f 72 64 20 7b 0a 20 20 4b 65 79 49 6e Record {. KeyIn
11a90 66 6f 20 2a 70 4b 65 79 49 6e 66 6f 3b 20 20 2f fo *pKeyInfo; /
11aa0 2a 20 43 6f 6c 6c 61 74 69 6f 6e 20 61 6e 64 20 * Collation and
11ab0 73 6f 72 74 2d 6f 72 64 65 72 20 69 6e 66 6f 72 sort-order infor
11ac0 6d 61 74 69 6f 6e 20 2a 2f 0a 20 20 75 31 36 20 mation */. u16
11ad0 6e 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 20 nField;
11ae0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 /* Number of ent
11af0 72 69 65 73 20 69 6e 20 61 70 4d 65 6d 5b 5d 20 ries in apMem[]
11b00 2a 2f 0a 20 20 69 38 20 64 65 66 61 75 6c 74 5f */. i8 default_
11b10 72 63 3b 20 20 20 20 20 20 2f 2a 20 43 6f 6d 70 rc; /* Comp
11b20 61 72 69 73 6f 6e 20 72 65 73 75 6c 74 20 69 66 arison result if
11b30 20 6b 65 79 73 20 61 72 65 20 65 71 75 61 6c 20 keys are equal
11b40 2a 2f 0a 20 20 75 38 20 65 72 72 43 6f 64 65 3b */. u8 errCode;
11b50 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 72 6f /* Erro
11b60 72 20 64 65 74 65 63 74 65 64 20 62 79 20 78 52 r detected by xR
11b70 65 63 6f 72 64 43 6f 6d 70 61 72 65 20 28 43 4f ecordCompare (CO
11b80 52 52 55 50 54 20 6f 72 20 4e 4f 4d 45 4d 29 20 RRUPT or NOMEM)
11b90 2a 2f 0a 20 20 4d 65 6d 20 2a 61 4d 65 6d 3b 20 */. Mem *aMem;
11ba0 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 /* Valu
11bb0 65 73 20 2a 2f 0a 20 20 69 6e 74 20 72 31 3b 20 es */. int r1;
11bc0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 /* V
11bd0 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 69 alue to return i
11be0 66 20 28 6c 68 73 20 3e 20 72 68 73 29 20 2a 2f f (lhs > rhs) */
11bf0 0a 20 20 69 6e 74 20 72 32 3b 20 20 20 20 20 20 . int r2;
11c00 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 /* Value
11c10 74 6f 20 72 65 74 75 72 6e 20 69 66 20 28 72 68 to return if (rh
11c20 73 20 3c 20 6c 68 73 29 20 2a 2f 0a 7d 3b 0a 0a s < lhs) */.};..
11c30 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 ./*.** Each SQL
11c40 69 6e 64 65 78 20 69 73 20 72 65 70 72 65 73 65 index is represe
11c50 6e 74 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20 62 nted in memory b
11c60 79 20 61 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 y an.** instance
11c70 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
11c80 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a g structure..**.
11c90 2a 2a 20 54 68 65 20 63 6f 6c 75 6d 6e 73 20 6f ** The columns o
11ca0 66 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 f the table that
11cb0 20 61 72 65 20 74 6f 20 62 65 20 69 6e 64 65 78 are to be index
11cc0 65 64 20 61 72 65 20 64 65 73 63 72 69 62 65 64 ed are described
11cd0 0a 2a 2a 20 62 79 20 74 68 65 20 61 69 43 6f 6c .** by the aiCol
11ce0 75 6d 6e 5b 5d 20 66 69 65 6c 64 20 6f 66 20 74 umn[] field of t
11cf0 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 his structure.
11d00 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 73 75 70 For example, sup
11d10 70 6f 73 65 0a 2a 2a 20 77 65 20 68 61 76 65 20 pose.** we have
11d20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 61 the following ta
11d30 62 6c 65 20 61 6e 64 20 69 6e 64 65 78 3a 0a 2a ble and index:.*
11d40 2a 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 *.** CREATE
11d50 54 41 42 4c 45 20 45 78 31 28 63 31 20 69 6e 74 TABLE Ex1(c1 int
11d60 2c 20 63 32 20 69 6e 74 2c 20 63 33 20 74 65 78 , c2 int, c3 tex
11d70 74 29 3b 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 t);.** CREAT
11d80 45 20 49 4e 44 45 58 20 45 78 32 20 4f 4e 20 45 E INDEX Ex2 ON E
11d90 78 31 28 63 33 2c 63 31 29 3b 0a 2a 2a 0a 2a 2a x1(c3,c1);.**.**
11da0 20 49 6e 20 74 68 65 20 54 61 62 6c 65 20 73 74 In the Table st
11db0 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 69 ructure describi
11dc0 6e 67 20 45 78 31 2c 20 6e 43 6f 6c 3d 3d 33 20 ng Ex1, nCol==3
11dd0 62 65 63 61 75 73 65 20 74 68 65 72 65 20 61 72 because there ar
11de0 65 0a 2a 2a 20 74 68 72 65 65 20 63 6f 6c 75 6d e.** three colum
11df0 6e 73 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e ns in the table.
11e00 20 20 49 6e 20 74 68 65 20 49 6e 64 65 78 20 73 In the Index s
11e10 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 tructure describ
11e20 69 6e 67 0a 2a 2a 20 45 78 32 2c 20 6e 43 6f 6c ing.** Ex2, nCol
11e30 75 6d 6e 3d 3d 32 20 73 69 6e 63 65 20 32 20 6f umn==2 since 2 o
11e40 66 20 74 68 65 20 33 20 63 6f 6c 75 6d 6e 73 20 f the 3 columns
11e50 6f 66 20 45 78 31 20 61 72 65 20 69 6e 64 65 78 of Ex1 are index
11e60 65 64 2e 0a 2a 2a 20 54 68 65 20 76 61 6c 75 65 ed..** The value
11e70 20 6f 66 20 61 69 43 6f 6c 75 6d 6e 20 69 73 20 of aiColumn is
11e80 7b 32 2c 20 30 7d 2e 20 20 61 69 43 6f 6c 75 6d {2, 0}. aiColum
11e90 6e 5b 30 5d 3d 3d 32 20 62 65 63 61 75 73 65 20 n[0]==2 because
11ea0 74 68 65 20 0a 2a 2a 20 66 69 72 73 74 20 63 6f the .** first co
11eb0 6c 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 65 78 lumn to be index
11ec0 65 64 20 28 63 33 29 20 68 61 73 20 61 6e 20 69 ed (c3) has an i
11ed0 6e 64 65 78 20 6f 66 20 32 20 69 6e 20 45 78 31 ndex of 2 in Ex1
11ee0 2e 61 43 6f 6c 5b 5d 2e 0a 2a 2a 20 54 68 65 20 .aCol[]..** The
11ef0 73 65 63 6f 6e 64 20 63 6f 6c 75 6d 6e 20 74 6f second column to
11f00 20 62 65 20 69 6e 64 65 78 65 64 20 28 63 31 29 be indexed (c1)
11f10 20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 has an index of
11f20 20 30 20 69 6e 0a 2a 2a 20 45 78 31 2e 61 43 6f 0 in.** Ex1.aCo
11f30 6c 5b 5d 2c 20 68 65 6e 63 65 20 45 78 32 2e 61 l[], hence Ex2.a
11f40 69 43 6f 6c 75 6d 6e 5b 31 5d 3d 3d 30 2e 0a 2a iColumn[1]==0..*
11f50 2a 0a 2a 2a 20 54 68 65 20 49 6e 64 65 78 2e 6f *.** The Index.o
11f60 6e 45 72 72 6f 72 20 66 69 65 6c 64 20 64 65 74 nError field det
11f70 65 72 6d 69 6e 65 73 20 77 68 65 74 68 65 72 20 ermines whether
11f80 6f 72 20 6e 6f 74 20 74 68 65 20 69 6e 64 65 78 or not the index
11f90 65 64 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 6d 75 ed columns.** mu
11fa0 73 74 20 62 65 20 75 6e 69 71 75 65 20 61 6e 64 st be unique and
11fb0 20 77 68 61 74 20 74 6f 20 64 6f 20 69 66 20 74 what to do if t
11fc0 68 65 79 20 61 72 65 20 6e 6f 74 2e 20 20 57 68 hey are not. Wh
11fd0 65 6e 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 en Index.onError
11fe0 3d 4f 45 5f 4e 6f 6e 65 2c 0a 2a 2a 20 69 74 20 =OE_None,.** it
11ff0 6d 65 61 6e 73 20 74 68 69 73 20 69 73 20 6e 6f means this is no
12000 74 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 78 t a unique index
12010 2e 20 20 4f 74 68 65 72 77 69 73 65 20 69 74 20 . Otherwise it
12020 69 73 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 is a unique inde
12030 78 0a 2a 2a 20 61 6e 64 20 74 68 65 20 76 61 6c x.** and the val
12040 75 65 20 6f 66 20 49 6e 64 65 78 2e 6f 6e 45 72 ue of Index.onEr
12050 72 6f 72 20 69 6e 64 69 63 61 74 65 20 74 68 65 ror indicate the
12060 20 77 68 69 63 68 20 63 6f 6e 66 6c 69 63 74 20 which conflict
12070 72 65 73 6f 6c 75 74 69 6f 6e 20 0a 2a 2a 20 61 resolution .** a
12080 6c 67 6f 72 69 74 68 6d 20 74 6f 20 65 6d 70 6c lgorithm to empl
12090 6f 79 20 77 68 65 6e 65 76 65 72 20 61 6e 20 61 oy whenever an a
120a0 74 74 65 6d 70 74 20 69 73 20 6d 61 64 65 20 74 ttempt is made t
120b0 6f 20 69 6e 73 65 72 74 20 61 20 6e 6f 6e 2d 75 o insert a non-u
120c0 6e 69 71 75 65 0a 2a 2a 20 65 6c 65 6d 65 6e 74 nique.** element
120d0 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 ..*/.struct Inde
120e0 78 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d x {. char *zNam
120f0 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f e; /
12100 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 69 * Name of this i
12110 6e 64 65 78 20 2a 2f 0a 20 20 69 31 36 20 2a 61 ndex */. i16 *a
12120 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 iColumn;
12130 20 20 20 2f 2a 20 57 68 69 63 68 20 63 6f 6c 75 /* Which colu
12140 6d 6e 73 20 61 72 65 20 75 73 65 64 20 62 79 20 mns are used by
12150 74 68 69 73 20 69 6e 64 65 78 2e 20 20 31 73 74 this index. 1st
12160 20 69 73 20 30 20 2a 2f 0a 20 20 4c 6f 67 45 73 is 0 */. LogEs
12170 74 20 2a 61 69 52 6f 77 4c 6f 67 45 73 74 3b 20 t *aiRowLogEst;
12180 20 20 20 20 2f 2a 20 46 72 6f 6d 20 41 4e 41 4c /* From ANAL
12190 59 5a 45 3a 20 45 73 74 2e 20 72 6f 77 73 20 73 YZE: Est. rows s
121a0 65 6c 65 63 74 65 64 20 62 79 20 65 61 63 68 20 elected by each
121b0 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 54 61 62 6c column */. Tabl
121c0 65 20 2a 70 54 61 62 6c 65 3b 20 20 20 20 20 20 e *pTable;
121d0 20 20 20 20 20 2f 2a 20 54 68 65 20 53 51 4c 20 /* The SQL
121e0 74 61 62 6c 65 20 62 65 69 6e 67 20 69 6e 64 65 table being inde
121f0 78 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a xed */. char *z
12200 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 20 20 20 ColAff;
12210 20 20 2f 2a 20 53 74 72 69 6e 67 20 64 65 66 69 /* String defi
12220 6e 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 ning the affinit
12230 79 20 6f 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e y of each column
12240 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 4e 65 */. Index *pNe
12250 78 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f xt; /
12260 2a 20 54 68 65 20 6e 65 78 74 20 69 6e 64 65 78 * The next index
12270 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
12280 20 74 68 65 20 73 61 6d 65 20 74 61 62 6c 65 20 the same table
12290 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 */. Schema *pSc
122a0 68 65 6d 61 3b 20 20 20 20 20 20 20 20 20 2f 2a hema; /*
122b0 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 Schema containi
122c0 6e 67 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f ng this index */
122d0 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 . u8 *aSortOrde
122e0 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 66 r; /* f
122f0 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 3a 20 or each column:
12300 54 72 75 65 3d 3d 44 45 53 43 2c 20 46 61 6c 73 True==DESC, Fals
12310 65 3d 3d 41 53 43 20 2a 2f 0a 20 20 63 68 61 72 e==ASC */. char
12320 20 2a 2a 61 7a 43 6f 6c 6c 3b 20 20 20 20 20 20 **azColl;
12330 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 /* Array of
12340 20 63 6f 6c 6c 61 74 69 6f 6e 20 73 65 71 75 65 collation seque
12350 6e 63 65 20 6e 61 6d 65 73 20 66 6f 72 20 69 6e nce names for in
12360 64 65 78 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 dex */. Expr *p
12370 50 61 72 74 49 64 78 57 68 65 72 65 3b 20 20 20 PartIdxWhere;
12380 20 20 2f 2a 20 57 48 45 52 45 20 63 6c 61 75 73 /* WHERE claus
12390 65 20 66 6f 72 20 70 61 72 74 69 61 6c 20 69 6e e for partial in
123a0 64 69 63 65 73 20 2a 2f 0a 20 20 69 6e 74 20 74 dices */. int t
123b0 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 num;
123c0 20 20 20 20 2f 2a 20 44 42 20 50 61 67 65 20 63 /* DB Page c
123d0 6f 6e 74 61 69 6e 69 6e 67 20 72 6f 6f 74 20 6f ontaining root o
123e0 66 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a f this index */.
123f0 20 20 4c 6f 67 45 73 74 20 73 7a 49 64 78 52 6f LogEst szIdxRo
12400 77 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 45 73 w; /* Es
12410 74 69 6d 61 74 65 64 20 61 76 65 72 61 67 65 20 timated average
12420 72 6f 77 20 73 69 7a 65 20 69 6e 20 62 79 74 65 row size in byte
12430 73 20 2a 2f 0a 20 20 75 31 36 20 6e 4b 65 79 43 s */. u16 nKeyC
12440 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ol;
12450 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c /* Number of col
12460 75 6d 6e 73 20 66 6f 72 6d 69 6e 67 20 74 68 65 umns forming the
12470 20 6b 65 79 20 2a 2f 0a 20 20 75 31 36 20 6e 43 key */. u16 nC
12480 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 olumn;
12490 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
124a0 63 6f 6c 75 6d 6e 73 20 73 74 6f 72 65 64 20 69 columns stored i
124b0 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 n the index */.
124c0 20 75 38 20 6f 6e 45 72 72 6f 72 3b 20 20 20 20 u8 onError;
124d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 5f /* OE_
124e0 41 62 6f 72 74 2c 20 4f 45 5f 49 67 6e 6f 72 65 Abort, OE_Ignore
124f0 2c 20 4f 45 5f 52 65 70 6c 61 63 65 2c 20 6f 72 , OE_Replace, or
12500 20 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a 20 20 75 6e OE_None */. un
12510 73 69 67 6e 65 64 20 69 64 78 54 79 70 65 3a 32 signed idxType:2
12520 3b 20 20 20 20 20 20 2f 2a 20 31 3d 3d 55 4e 49 ; /* 1==UNI
12530 51 55 45 2c 20 32 3d 3d 50 52 49 4d 41 52 59 20 QUE, 2==PRIMARY
12540 4b 45 59 2c 20 30 3d 3d 43 52 45 41 54 45 20 49 KEY, 0==CREATE I
12550 4e 44 45 58 20 2a 2f 0a 20 20 75 6e 73 69 67 6e NDEX */. unsign
12560 65 64 20 62 55 6e 6f 72 64 65 72 65 64 3a 31 3b ed bUnordered:1;
12570 20 20 20 2f 2a 20 55 73 65 20 74 68 69 73 20 69 /* Use this i
12580 6e 64 65 78 20 66 6f 72 20 3d 3d 20 6f 72 20 49 ndex for == or I
12590 4e 20 71 75 65 72 69 65 73 20 6f 6e 6c 79 20 2a N queries only *
125a0 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 75 6e 69 /. unsigned uni
125b0 71 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 20 2f 2a 20 qNotNull:1; /*
125c0 54 72 75 65 20 69 66 20 55 4e 49 51 55 45 20 61 True if UNIQUE a
125d0 6e 64 20 4e 4f 54 20 4e 55 4c 4c 20 66 6f 72 20 nd NOT NULL for
125e0 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 all columns */.
125f0 20 75 6e 73 69 67 6e 65 64 20 69 73 52 65 73 69 unsigned isResi
12600 7a 65 64 3a 31 3b 20 20 20 20 2f 2a 20 54 72 75 zed:1; /* Tru
12610 65 20 69 66 20 72 65 73 69 7a 65 49 6e 64 65 78 e if resizeIndex
12620 4f 62 6a 65 63 74 28 29 20 68 61 73 20 62 65 65 Object() has bee
12630 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 75 6e n called */. un
12640 73 69 67 6e 65 64 20 69 73 43 6f 76 65 72 69 6e signed isCoverin
12650 67 3a 31 3b 20 20 20 2f 2a 20 54 72 75 65 20 69 g:1; /* True i
12660 66 20 74 68 69 73 20 69 73 20 61 20 63 6f 76 65 f this is a cove
12670 72 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 ring index */.
12680 75 6e 73 69 67 6e 65 64 20 6e 6f 53 6b 69 70 53 unsigned noSkipS
12690 63 61 6e 3a 31 3b 20 20 20 2f 2a 20 44 6f 20 6e can:1; /* Do n
126a0 6f 74 20 74 72 79 20 74 6f 20 75 73 65 20 73 6b ot try to use sk
126b0 69 70 2d 73 63 61 6e 20 69 66 20 74 72 75 65 20 ip-scan if true
126c0 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
126d0 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
126e0 5f 53 54 41 54 34 0a 20 20 69 6e 74 20 6e 53 61 _STAT4. int nSa
126f0 6d 70 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 mple;
12700 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
12710 6c 65 6d 65 6e 74 73 20 69 6e 20 61 53 61 6d 70 lements in aSamp
12720 6c 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 le[] */. int nS
12730 61 6d 70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 20 ampleCol;
12740 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 49 6e /* Size of In
12750 64 65 78 53 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d dexSample.anEq[]
12760 20 61 6e 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 and so on */.
12770 74 52 6f 77 63 6e 74 20 2a 61 41 76 67 45 71 3b tRowcnt *aAvgEq;
12780 20 20 20 20 20 20 20 20 20 2f 2a 20 41 76 65 72 /* Aver
12790 61 67 65 20 6e 45 71 20 76 61 6c 75 65 73 20 66 age nEq values f
127a0 6f 72 20 6b 65 79 73 20 6e 6f 74 20 69 6e 20 61 or keys not in a
127b0 53 61 6d 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 Sample */. Inde
127c0 78 53 61 6d 70 6c 65 20 2a 61 53 61 6d 70 6c 65 xSample *aSample
127d0 3b 20 20 20 20 2f 2a 20 53 61 6d 70 6c 65 73 20 ; /* Samples
127e0 6f 66 20 74 68 65 20 6c 65 66 74 2d 6d 6f 73 74 of the left-most
127f0 20 6b 65 79 20 2a 2f 0a 20 20 74 52 6f 77 63 6e key */. tRowcn
12800 74 20 2a 61 69 52 6f 77 45 73 74 3b 20 20 20 20 t *aiRowEst;
12810 20 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 /* Non-logari
12820 74 68 6d 69 63 20 73 74 61 74 31 20 64 61 74 61 thmic stat1 data
12830 20 66 6f 72 20 74 68 69 73 20 69 6e 64 65 78 20 for this index
12840 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 6e 52 6f */. tRowcnt nRo
12850 77 45 73 74 30 3b 20 20 20 20 20 20 20 20 2f 2a wEst0; /*
12860 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 63 Non-logarithmic
12870 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 number of rows
12880 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a in the index */.
12890 23 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a #endif.};../*.**
128a0 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 Allowed values
128b0 66 6f 72 20 49 6e 64 65 78 2e 69 64 78 54 79 70 for Index.idxTyp
128c0 65 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c e.*/.#define SQL
128d0 49 54 45 5f 49 44 58 54 59 50 45 5f 41 50 50 44 ITE_IDXTYPE_APPD
128e0 45 46 20 20 20 20 20 20 30 20 20 20 2f 2a 20 43 EF 0 /* C
128f0 72 65 61 74 65 64 20 75 73 69 6e 67 20 43 52 45 reated using CRE
12900 41 54 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 ATE INDEX */.#de
12910 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 fine SQLITE_IDXT
12920 59 50 45 5f 55 4e 49 51 55 45 20 20 20 20 20 20 YPE_UNIQUE
12930 31 20 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 1 /* Implement
12940 73 20 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 s a UNIQUE const
12950 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 raint */.#define
12960 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f SQLITE_IDXTYPE_
12970 50 52 49 4d 41 52 59 4b 45 59 20 20 32 20 20 20 PRIMARYKEY 2
12980 2f 2a 20 49 73 20 74 68 65 20 50 52 49 4d 41 52 /* Is the PRIMAR
12990 59 20 4b 45 59 20 66 6f 72 20 74 68 65 20 74 61 Y KEY for the ta
129a0 62 6c 65 20 2a 2f 0a 0a 2f 2a 20 52 65 74 75 72 ble */../* Retur
129b0 6e 20 74 72 75 65 20 69 66 20 69 6e 64 65 78 20 n true if index
129c0 58 20 69 73 20 61 20 50 52 49 4d 41 52 59 20 4b X is a PRIMARY K
129d0 45 59 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 EY index */.#def
129e0 69 6e 65 20 49 73 50 72 69 6d 61 72 79 4b 65 79 ine IsPrimaryKey
129f0 49 6e 64 65 78 28 58 29 20 20 28 28 58 29 2d 3e Index(X) ((X)->
12a00 69 64 78 54 79 70 65 3d 3d 53 51 4c 49 54 45 5f idxType==SQLITE_
12a10 49 44 58 54 59 50 45 5f 50 52 49 4d 41 52 59 4b IDXTYPE_PRIMARYK
12a20 45 59 29 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 74 EY)../* Return t
12a30 72 75 65 20 69 66 20 69 6e 64 65 78 20 58 20 69 rue if index X i
12a40 73 20 61 20 55 4e 49 51 55 45 20 69 6e 64 65 78 s a UNIQUE index
12a50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 55 6e */.#define IsUn
12a60 69 71 75 65 49 6e 64 65 78 28 58 29 20 20 20 20 iqueIndex(X)
12a70 20 20 28 28 58 29 2d 3e 6f 6e 45 72 72 6f 72 21 ((X)->onError!
12a80 3d 4f 45 5f 4e 6f 6e 65 29 0a 0a 2f 2a 0a 2a 2a =OE_None)../*.**
12a90 20 45 61 63 68 20 73 61 6d 70 6c 65 20 73 74 6f Each sample sto
12aa0 72 65 64 20 69 6e 20 74 68 65 20 73 71 6c 69 74 red in the sqlit
12ab0 65 5f 73 74 61 74 33 20 74 61 62 6c 65 20 69 73 e_stat3 table is
12ac0 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 represented in
12ad0 6d 65 6d 6f 72 79 20 0a 2a 2a 20 75 73 69 6e 67 memory .** using
12ae0 20 61 20 73 74 72 75 63 74 75 72 65 20 6f 66 20 a structure of
12af0 74 68 69 73 20 74 79 70 65 2e 20 20 53 65 65 20 this type. See
12b00 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 61 74 documentation at
12b10 20 74 68 65 20 74 6f 70 20 6f 66 20 74 68 65 0a the top of the.
12b20 2a 2a 20 61 6e 61 6c 79 7a 65 2e 63 20 73 6f 75 ** analyze.c sou
12b30 72 63 65 20 66 69 6c 65 20 66 6f 72 20 61 64 64 rce file for add
12b40 69 74 69 6f 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 itional informat
12b50 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 ion..*/.struct I
12b60 6e 64 65 78 53 61 6d 70 6c 65 20 7b 0a 20 20 76 ndexSample {. v
12b70 6f 69 64 20 2a 70 3b 20 20 20 20 20 20 20 20 20 oid *p;
12b80 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 73 /* Pointer to s
12b90 61 6d 70 6c 65 64 20 72 65 63 6f 72 64 20 2a 2f ampled record */
12ba0 0a 20 20 69 6e 74 20 6e 3b 20 20 20 20 20 20 20 . int n;
12bb0 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 /* Size of
12bc0 72 65 63 6f 72 64 20 69 6e 20 62 79 74 65 73 20 record in bytes
12bd0 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e */. tRowcnt *an
12be0 45 71 3b 20 20 20 20 2f 2a 20 45 73 74 2e 20 6e Eq; /* Est. n
12bf0 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 77 68 umber of rows wh
12c00 65 72 65 20 74 68 65 20 6b 65 79 20 65 71 75 61 ere the key equa
12c10 6c 73 20 74 68 69 73 20 73 61 6d 70 6c 65 20 2a ls this sample *
12c20 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 4c /. tRowcnt *anL
12c30 74 3b 20 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 t; /* Est. nu
12c40 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 77 68 65 mber of rows whe
12c50 72 65 20 6b 65 79 20 69 73 20 6c 65 73 73 20 74 re key is less t
12c60 68 61 6e 20 74 68 69 73 20 73 61 6d 70 6c 65 20 han this sample
12c70 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e */. tRowcnt *an
12c80 44 4c 74 3b 20 20 20 2f 2a 20 45 73 74 2e 20 6e DLt; /* Est. n
12c90 75 6d 62 65 72 20 6f 66 20 64 69 73 74 69 6e 63 umber of distinc
12ca0 74 20 6b 65 79 73 20 6c 65 73 73 20 74 68 61 6e t keys less than
12cb0 20 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a this sample */.
12cc0 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 74 };../*.** Each t
12cd0 6f 6b 65 6e 20 63 6f 6d 69 6e 67 20 6f 75 74 20 oken coming out
12ce0 6f 66 20 74 68 65 20 6c 65 78 65 72 20 69 73 20 of the lexer is
12cf0 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 0a 2a an instance of.*
12d00 2a 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 * this structure
12d10 2e 20 20 54 6f 6b 65 6e 73 20 61 72 65 20 61 6c . Tokens are al
12d20 73 6f 20 75 73 65 64 20 61 73 20 70 61 72 74 20 so used as part
12d30 6f 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e of an expression
12d40 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 69 66 20 ..**.** Note if
12d50 54 6f 6b 65 6e 2e 7a 3d 3d 30 20 74 68 65 6e 20 Token.z==0 then
12d60 54 6f 6b 65 6e 2e 64 79 6e 20 61 6e 64 20 54 6f Token.dyn and To
12d70 6b 65 6e 2e 6e 20 61 72 65 20 75 6e 64 65 66 69 ken.n are undefi
12d80 6e 65 64 20 61 6e 64 0a 2a 2a 20 6d 61 79 20 63 ned and.** may c
12d90 6f 6e 74 61 69 6e 20 72 61 6e 64 6f 6d 20 76 61 ontain random va
12da0 6c 75 65 73 2e 20 20 44 6f 20 6e 6f 74 20 6d 61 lues. Do not ma
12db0 6b 65 20 61 6e 79 20 61 73 73 75 6d 70 74 69 6f ke any assumptio
12dc0 6e 73 20 61 62 6f 75 74 20 54 6f 6b 65 6e 2e 64 ns about Token.d
12dd0 79 6e 0a 2a 2a 20 61 6e 64 20 54 6f 6b 65 6e 2e yn.** and Token.
12de0 6e 20 77 68 65 6e 20 54 6f 6b 65 6e 2e 7a 3d 3d n when Token.z==
12df0 30 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 6f 6b 0..*/.struct Tok
12e00 65 6e 20 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 en {. const cha
12e10 72 20 2a 7a 3b 20 20 20 20 20 2f 2a 20 54 65 78 r *z; /* Tex
12e20 74 20 6f 66 20 74 68 65 20 74 6f 6b 65 6e 2e 20 t of the token.
12e30 20 4e 6f 74 20 4e 55 4c 4c 2d 74 65 72 6d 69 6e Not NULL-termin
12e40 61 74 65 64 21 20 2a 2f 0a 20 20 75 6e 73 69 67 ated! */. unsig
12e50 6e 65 64 20 69 6e 74 20 6e 3b 20 20 20 20 2f 2a ned int n; /*
12e60 20 4e 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 Number of chara
12e70 63 74 65 72 73 20 69 6e 20 74 68 69 73 20 74 6f cters in this to
12e80 6b 65 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ken */.};../*.**
12e90 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
12ea0 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 63 this structure c
12eb0 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 6d 61 74 ontains informat
12ec0 69 6f 6e 20 6e 65 65 64 65 64 20 74 6f 20 67 65 ion needed to ge
12ed0 6e 65 72 61 74 65 0a 2a 2a 20 63 6f 64 65 20 66 nerate.** code f
12ee0 6f 72 20 61 20 53 45 4c 45 43 54 20 74 68 61 74 or a SELECT that
12ef0 20 63 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 contains aggreg
12f00 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a ate functions..*
12f10 2a 0a 2a 2a 20 49 66 20 45 78 70 72 2e 6f 70 3d *.** If Expr.op=
12f20 3d 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d 4e 20 6f =TK_AGG_COLUMN o
12f30 72 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f r TK_AGG_FUNCTIO
12f40 4e 20 74 68 65 6e 20 45 78 70 72 2e 70 41 67 67 N then Expr.pAgg
12f50 49 6e 66 6f 20 69 73 20 61 0a 2a 2a 20 70 6f 69 Info is a.** poi
12f60 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 nter to this str
12f70 75 63 74 75 72 65 2e 20 20 54 68 65 20 45 78 70 ucture. The Exp
12f80 72 2e 69 43 6f 6c 75 6d 6e 20 66 69 65 6c 64 20 r.iColumn field
12f90 69 73 20 74 68 65 20 69 6e 64 65 78 20 69 6e 0a is the index in.
12fa0 2a 2a 20 41 67 67 49 6e 66 6f 2e 61 43 6f 6c 5b ** AggInfo.aCol[
12fb0 5d 20 6f 72 20 41 67 67 49 6e 66 6f 2e 61 46 75 ] or AggInfo.aFu
12fc0 6e 63 5b 5d 20 6f 66 20 69 6e 66 6f 72 6d 61 74 nc[] of informat
12fd0 69 6f 6e 20 6e 65 65 64 65 64 20 74 6f 20 67 65 ion needed to ge
12fe0 6e 65 72 61 74 65 0a 2a 2a 20 63 6f 64 65 20 66 nerate.** code f
12ff0 6f 72 20 74 68 61 74 20 6e 6f 64 65 2e 0a 2a 2a or that node..**
13000 0a 2a 2a 20 41 67 67 49 6e 66 6f 2e 70 47 72 6f .** AggInfo.pGro
13010 75 70 42 79 20 61 6e 64 20 41 67 67 49 6e 66 6f upBy and AggInfo
13020 2e 61 46 75 6e 63 2e 70 45 78 70 72 20 70 6f 69 .aFunc.pExpr poi
13030 6e 74 20 74 6f 20 66 69 65 6c 64 73 20 77 69 74 nt to fields wit
13040 68 69 6e 20 74 68 65 0a 2a 2a 20 6f 72 69 67 69 hin the.** origi
13050 6e 61 6c 20 53 65 6c 65 63 74 20 73 74 72 75 63 nal Select struc
13060 74 75 72 65 20 74 68 61 74 20 64 65 73 63 72 69 ture that descri
13070 62 65 73 20 74 68 65 20 53 45 4c 45 43 54 20 73 bes the SELECT s
13080 74 61 74 65 6d 65 6e 74 2e 20 20 54 68 65 73 65 tatement. These
13090 0a 2a 2a 20 66 69 65 6c 64 73 20 64 6f 20 6e 6f .** fields do no
130a0 74 20 6e 65 65 64 20 74 6f 20 62 65 20 66 72 65 t need to be fre
130b0 65 64 20 77 68 65 6e 20 64 65 61 6c 6c 6f 63 61 ed when dealloca
130c0 74 69 6e 67 20 74 68 65 20 41 67 67 49 6e 66 6f ting the AggInfo
130d0 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 structure..*/.s
130e0 74 72 75 63 74 20 41 67 67 49 6e 66 6f 20 7b 0a truct AggInfo {.
130f0 20 20 75 38 20 64 69 72 65 63 74 4d 6f 64 65 3b u8 directMode;
13100 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 69 72 /* Dir
13110 65 63 74 20 72 65 6e 64 65 72 69 6e 67 20 6d 6f ect rendering mo
13120 64 65 20 6d 65 61 6e 73 20 74 61 6b 65 20 64 61 de means take da
13130 74 61 20 64 69 72 65 63 74 6c 79 0a 20 20 20 20 ta directly.
13140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13150 20 20 20 20 20 20 2a 2a 20 66 72 6f 6d 20 73 6f ** from so
13160 75 72 63 65 20 74 61 62 6c 65 73 20 72 61 74 68 urce tables rath
13170 65 72 20 74 68 61 6e 20 66 72 6f 6d 20 61 63 63 er than from acc
13180 75 6d 75 6c 61 74 6f 72 73 20 2a 2f 0a 20 20 75 umulators */. u
13190 38 20 75 73 65 53 6f 72 74 69 6e 67 49 64 78 3b 8 useSortingIdx;
131a0 20 20 20 20 20 20 20 2f 2a 20 49 6e 20 64 69 72 /* In dir
131b0 65 63 74 20 6d 6f 64 65 2c 20 72 65 66 65 72 65 ect mode, refere
131c0 6e 63 65 20 74 68 65 20 73 6f 72 74 69 6e 67 20 nce the sorting
131d0 69 6e 64 65 78 20 72 61 74 68 65 72 0a 20 20 20 index rather.
131e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
131f0 20 20 20 20 20 20 20 2a 2a 20 74 68 61 6e 20 74 ** than t
13200 68 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 he source table
13210 2a 2f 0a 20 20 69 6e 74 20 73 6f 72 74 69 6e 67 */. int sorting
13220 49 64 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 Idx; /*
13230 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 Cursor number of
13240 20 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 the sorting ind
13250 65 78 20 2a 2f 0a 20 20 69 6e 74 20 73 6f 72 74 ex */. int sort
13260 69 6e 67 49 64 78 50 54 61 62 3b 20 20 20 20 20 ingIdxPTab;
13270 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 /* Cursor number
13280 20 6f 66 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 of pseudo-table
13290 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 6f 72 74 69 */. int nSorti
132a0 6e 67 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 2f 2a ngColumn; /*
132b0 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
132c0 6e 73 20 69 6e 20 74 68 65 20 73 6f 72 74 69 6e ns in the sortin
132d0 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e 74 g index */. int
132e0 20 6d 6e 52 65 67 2c 20 6d 78 52 65 67 3b 20 20 mnReg, mxReg;
132f0 20 20 20 20 20 2f 2a 20 52 61 6e 67 65 20 6f 66 /* Range of
13300 20 72 65 67 69 73 74 65 72 73 20 61 6c 6c 6f 63 registers alloc
13310 61 74 65 64 20 66 6f 72 20 61 43 6f 6c 20 61 6e ated for aCol an
13320 64 20 61 46 75 6e 63 20 2a 2f 0a 20 20 45 78 70 d aFunc */. Exp
13330 72 4c 69 73 74 20 2a 70 47 72 6f 75 70 42 79 3b rList *pGroupBy;
13340 20 20 20 20 20 2f 2a 20 54 68 65 20 67 72 6f 75 /* The grou
13350 70 20 62 79 20 63 6c 61 75 73 65 20 2a 2f 0a 20 p by clause */.
13360 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 5f struct AggInfo_
13370 63 6f 6c 20 7b 20 20 20 20 2f 2a 20 46 6f 72 20 col { /* For
13380 65 61 63 68 20 63 6f 6c 75 6d 6e 20 75 73 65 64 each column used
13390 20 69 6e 20 73 6f 75 72 63 65 20 74 61 62 6c 65 in source table
133a0 73 20 2a 2f 0a 20 20 20 20 54 61 62 6c 65 20 2a s */. Table *
133b0 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 pTab;
133c0 20 20 2f 2a 20 53 6f 75 72 63 65 20 74 61 62 6c /* Source tabl
133d0 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 54 61 e */. int iTa
133e0 62 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ble;
133f0 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 /* Cursor numb
13400 65 72 20 6f 66 20 74 68 65 20 73 6f 75 72 63 65 er of the source
13410 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e table */. in
13420 74 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 t iColumn;
13430 20 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e /* Column
13440 20 6e 75 6d 62 65 72 20 77 69 74 68 69 6e 20 74 number within t
13450 68 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 he source table
13460 2a 2f 0a 20 20 20 20 69 6e 74 20 69 53 6f 72 74 */. int iSort
13470 65 72 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 erColumn;
13480 2f 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 /* Column number
13490 20 69 6e 20 74 68 65 20 73 6f 72 74 69 6e 67 20 in the sorting
134a0 69 6e 64 65 78 20 2a 2f 0a 20 20 20 20 69 6e 74 index */. int
134b0 20 69 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 iMem;
134c0 20 20 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 /* Memory
134d0 6c 6f 63 61 74 69 6f 6e 20 74 68 61 74 20 61 63 location that ac
134e0 74 73 20 61 73 20 61 63 63 75 6d 75 6c 61 74 6f ts as accumulato
134f0 72 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a 70 r */. Expr *p
13500 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 Expr;
13510 20 20 2f 2a 20 54 68 65 20 6f 72 69 67 69 6e 61 /* The origina
13520 6c 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a l expression */.
13530 20 20 7d 20 2a 61 43 6f 6c 3b 0a 20 20 69 6e 74 } *aCol;. int
13540 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 nColumn;
13550 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
13560 66 20 75 73 65 64 20 65 6e 74 72 69 65 73 20 69 f used entries i
13570 6e 20 61 43 6f 6c 5b 5d 20 2a 2f 0a 20 20 69 6e n aCol[] */. in
13580 74 20 6e 41 63 63 75 6d 75 6c 61 74 6f 72 3b 20 t nAccumulator;
13590 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
135a0 6f 66 20 63 6f 6c 75 6d 6e 73 20 74 68 61 74 20 of columns that
135b0 73 68 6f 77 20 74 68 72 6f 75 67 68 20 74 6f 20 show through to
135c0 74 68 65 20 6f 75 74 70 75 74 2e 0a 20 20 20 20 the output..
135d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
135e0 20 20 20 20 20 20 2a 2a 20 41 64 64 69 74 69 6f ** Additio
135f0 6e 61 6c 20 63 6f 6c 75 6d 6e 73 20 61 72 65 20 nal columns are
13600 75 73 65 64 20 6f 6e 6c 79 20 61 73 20 70 61 72 used only as par
13610 61 6d 65 74 65 72 73 20 74 6f 0a 20 20 20 20 20 ameters to.
13620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13630 20 20 20 20 20 2a 2a 20 61 67 67 72 65 67 61 74 ** aggregat
13640 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a 20 e functions */.
13650 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 5f struct AggInfo_
13660 66 75 6e 63 20 7b 20 20 20 2f 2a 20 46 6f 72 20 func { /* For
13670 65 61 63 68 20 61 67 67 72 65 67 61 74 65 20 66 each aggregate f
13680 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 45 unction */. E
13690 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 xpr *pExpr;
136a0 20 20 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 /* Expre
136b0 73 73 69 6f 6e 20 65 6e 63 6f 64 69 6e 67 20 74 ssion encoding t
136c0 68 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 he function */.
136d0 20 20 20 46 75 6e 63 44 65 66 20 2a 70 46 75 6e FuncDef *pFun
136e0 63 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 c; /* T
136f0 68 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e he aggregate fun
13700 63 74 69 6f 6e 20 69 6d 70 6c 65 6d 65 6e 74 61 ction implementa
13710 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 tion */. int
13720 69 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 20 iMem;
13730 20 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c /* Memory l
13740 6f 63 61 74 69 6f 6e 20 74 68 61 74 20 61 63 74 ocation that act
13750 73 20 61 73 20 61 63 63 75 6d 75 6c 61 74 6f 72 s as accumulator
13760 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 44 69 73 */. int iDis
13770 74 69 6e 63 74 3b 20 20 20 20 20 20 20 20 20 20 tinct;
13780 20 2f 2a 20 45 70 68 65 6d 65 72 61 6c 20 74 61 /* Ephemeral ta
13790 62 6c 65 20 75 73 65 64 20 74 6f 20 65 6e 66 6f ble used to enfo
137a0 72 63 65 20 44 49 53 54 49 4e 43 54 20 2a 2f 0a rce DISTINCT */.
137b0 20 20 7d 20 2a 61 46 75 6e 63 3b 0a 20 20 69 6e } *aFunc;. in
137c0 74 20 6e 46 75 6e 63 3b 20 20 20 20 20 20 20 20 t nFunc;
137d0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
137e0 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 46 of entries in aF
137f0 75 6e 63 5b 5d 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a unc[] */.};../*.
13800 2a 2a 20 54 68 65 20 64 61 74 61 74 79 70 65 20 ** The datatype
13810 79 6e 56 61 72 20 69 73 20 61 20 73 69 67 6e 65 ynVar is a signe
13820 64 20 69 6e 74 65 67 65 72 2c 20 65 69 74 68 65 d integer, eithe
13830 72 20 31 36 2d 62 69 74 20 6f 72 20 33 32 2d 62 r 16-bit or 32-b
13840 69 74 2e 0a 2a 2a 20 55 73 75 61 6c 6c 79 20 69 it..** Usually i
13850 74 20 69 73 20 31 36 2d 62 69 74 73 2e 20 20 42 t is 16-bits. B
13860 75 74 20 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 ut if SQLITE_MAX
13870 5f 56 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 _VARIABLE_NUMBER
13880 20 69 73 20 67 72 65 61 74 65 72 0a 2a 2a 20 74 is greater.** t
13890 68 61 6e 20 33 32 37 36 37 20 77 65 20 68 61 76 han 32767 we hav
138a0 65 20 74 6f 20 6d 61 6b 65 20 69 74 20 33 32 2d e to make it 32-
138b0 62 69 74 2e 20 20 31 36 2d 62 69 74 20 69 73 20 bit. 16-bit is
138c0 70 72 65 66 65 72 72 65 64 20 62 65 63 61 75 73 preferred becaus
138d0 65 0a 2a 2a 20 69 74 20 75 73 65 73 20 6c 65 73 e.** it uses les
138e0 73 20 6d 65 6d 6f 72 79 20 69 6e 20 74 68 65 20 s memory in the
138f0 45 78 70 72 20 6f 62 6a 65 63 74 2c 20 77 68 69 Expr object, whi
13900 63 68 20 69 73 20 61 20 62 69 67 20 6d 65 6d 6f ch is a big memo
13910 72 79 20 75 73 65 72 0a 2a 2a 20 69 6e 20 73 79 ry user.** in sy
13920 73 74 65 6d 73 20 77 69 74 68 20 6c 6f 74 73 20 stems with lots
13930 6f 66 20 70 72 65 70 61 72 65 64 20 73 74 61 74 of prepared stat
13940 65 6d 65 6e 74 73 2e 20 20 41 6e 64 20 66 65 77 ements. And few
13950 20 61 70 70 6c 69 63 61 74 69 6f 6e 73 0a 2a 2a applications.**
13960 20 6e 65 65 64 20 6d 6f 72 65 20 74 68 61 6e 20 need more than
13970 61 62 6f 75 74 20 31 30 20 6f 72 20 32 30 20 76 about 10 or 20 v
13980 61 72 69 61 62 6c 65 73 2e 20 20 42 75 74 20 73 ariables. But s
13990 6f 6d 65 20 65 78 74 72 65 6d 65 20 75 73 65 72 ome extreme user
139a0 73 20 77 61 6e 74 0a 2a 2a 20 74 6f 20 68 61 76 s want.** to hav
139b0 65 20 70 72 65 70 61 72 65 64 20 73 74 61 74 65 e prepared state
139c0 6d 65 6e 74 73 20 77 69 74 68 20 6f 76 65 72 20 ments with over
139d0 33 32 37 36 37 20 76 61 72 69 61 62 6c 65 73 2c 32767 variables,
139e0 20 61 6e 64 20 66 6f 72 20 74 68 65 6d 0a 2a 2a and for them.**
139f0 20 74 68 65 20 6f 70 74 69 6f 6e 20 69 73 20 61 the option is a
13a00 76 61 69 6c 61 62 6c 65 20 28 61 74 20 63 6f 6d vailable (at com
13a10 70 69 6c 65 2d 74 69 6d 65 29 2e 0a 2a 2f 0a 23 pile-time)..*/.#
13a20 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 if SQLITE_MAX_VA
13a30 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 3c 3d 33 RIABLE_NUMBER<=3
13a40 32 37 36 37 0a 74 79 70 65 64 65 66 20 69 31 36 2767.typedef i16
13a50 20 79 6e 56 61 72 3b 0a 23 65 6c 73 65 0a 74 79 ynVar;.#else.ty
13a60 70 65 64 65 66 20 69 6e 74 20 79 6e 56 61 72 3b pedef int ynVar;
13a70 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 .#endif../*.** E
13a80 61 63 68 20 6e 6f 64 65 20 6f 66 20 61 6e 20 65 ach node of an e
13a90 78 70 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 xpression in the
13aa0 20 70 61 72 73 65 20 74 72 65 65 20 69 73 20 61 parse tree is a
13ab0 6e 20 69 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 n instance.** of
13ac0 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 2e this structure.
13ad0 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 6f 70 20 69 .**.** Expr.op i
13ae0 73 20 74 68 65 20 6f 70 63 6f 64 65 2e 20 54 68 s the opcode. Th
13af0 65 20 69 6e 74 65 67 65 72 20 70 61 72 73 65 72 e integer parser
13b00 20 74 6f 6b 65 6e 20 63 6f 64 65 73 20 61 72 65 token codes are
13b10 20 72 65 75 73 65 64 0a 2a 2a 20 61 73 20 6f 70 reused.** as op
13b20 63 6f 64 65 73 20 68 65 72 65 2e 20 46 6f 72 20 codes here. For
13b30 65 78 61 6d 70 6c 65 2c 20 74 68 65 20 70 61 72 example, the par
13b40 73 65 72 20 64 65 66 69 6e 65 73 20 54 4b 5f 47 ser defines TK_G
13b50 45 20 74 6f 20 62 65 20 61 6e 20 69 6e 74 65 67 E to be an integ
13b60 65 72 0a 2a 2a 20 63 6f 64 65 20 72 65 70 72 65 er.** code repre
13b70 73 65 6e 74 69 6e 67 20 74 68 65 20 22 3e 3d 22 senting the ">="
13b80 20 6f 70 65 72 61 74 6f 72 2e 20 54 68 69 73 20 operator. This
13b90 73 61 6d 65 20 69 6e 74 65 67 65 72 20 63 6f 64 same integer cod
13ba0 65 20 69 73 20 72 65 75 73 65 64 0a 2a 2a 20 74 e is reused.** t
13bb0 6f 20 72 65 70 72 65 73 65 6e 74 20 74 68 65 20 o represent the
13bc0 67 72 65 61 74 65 72 2d 74 68 61 6e 2d 6f 72 2d greater-than-or-
13bd0 65 71 75 61 6c 2d 74 6f 20 6f 70 65 72 61 74 6f equal-to operato
13be0 72 20 69 6e 20 74 68 65 20 65 78 70 72 65 73 73 r in the express
13bf0 69 6f 6e 0a 2a 2a 20 74 72 65 65 2e 0a 2a 2a 0a ion.** tree..**.
13c00 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 73 ** If the expres
13c10 73 69 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 6c sion is an SQL l
13c20 69 74 65 72 61 6c 20 28 54 4b 5f 49 4e 54 45 47 iteral (TK_INTEG
13c30 45 52 2c 20 54 4b 5f 46 4c 4f 41 54 2c 20 54 4b ER, TK_FLOAT, TK
13c40 5f 42 4c 4f 42 2c 20 0a 2a 2a 20 6f 72 20 54 4b _BLOB, .** or TK
13c50 5f 53 54 52 49 4e 47 29 2c 20 74 68 65 6e 20 45 _STRING), then E
13c60 78 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 xpr.token contai
13c70 6e 73 20 74 68 65 20 74 65 78 74 20 6f 66 20 74 ns the text of t
13c80 68 65 20 53 51 4c 20 6c 69 74 65 72 61 6c 2e 20 he SQL literal.
13c90 49 66 0a 2a 2a 20 74 68 65 20 65 78 70 72 65 73 If.** the expres
13ca0 73 69 6f 6e 20 69 73 20 61 20 76 61 72 69 61 62 sion is a variab
13cb0 6c 65 20 28 54 4b 5f 56 41 52 49 41 42 4c 45 29 le (TK_VARIABLE)
13cc0 2c 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 , then Expr.toke
13cd0 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 0a n contains the .
13ce0 2a 2a 20 76 61 72 69 61 62 6c 65 20 6e 61 6d 65 ** variable name
13cf0 2e 20 46 69 6e 61 6c 6c 79 2c 20 69 66 20 74 68 . Finally, if th
13d00 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 e expression is
13d10 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 an SQL function
13d20 28 54 4b 5f 46 55 4e 43 54 49 4f 4e 29 2c 0a 2a (TK_FUNCTION),.*
13d30 2a 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 * then Expr.toke
13d40 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 6e n contains the n
13d50 61 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 74 ame of the funct
13d60 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e ion..**.** Expr.
13d70 70 52 69 67 68 74 20 61 6e 64 20 45 78 70 72 2e pRight and Expr.
13d80 70 4c 65 66 74 20 61 72 65 20 74 68 65 20 6c 65 pLeft are the le
13d90 66 74 20 61 6e 64 20 72 69 67 68 74 20 73 75 62 ft and right sub
13da0 65 78 70 72 65 73 73 69 6f 6e 73 20 6f 66 20 61 expressions of a
13db0 0a 2a 2a 20 62 69 6e 61 72 79 20 6f 70 65 72 61 .** binary opera
13dc0 74 6f 72 2e 20 45 69 74 68 65 72 20 6f 72 20 62 tor. Either or b
13dd0 6f 74 68 20 6d 61 79 20 62 65 20 4e 55 4c 4c 2e oth may be NULL.
13de0 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 78 2e 70 4c .**.** Expr.x.pL
13df0 69 73 74 20 69 73 20 61 20 6c 69 73 74 20 6f 66 ist is a list of
13e00 20 61 72 67 75 6d 65 6e 74 73 20 69 66 20 74 68 arguments if th
13e10 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 e expression is
13e20 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 2c an SQL function,
13e30 0a 2a 2a 20 61 20 43 41 53 45 20 65 78 70 72 65 .** a CASE expre
13e40 73 73 69 6f 6e 20 6f 72 20 61 6e 20 49 4e 20 65 ssion or an IN e
13e50 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 68 65 xpression of the
13e60 20 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 form "<lhs> IN
13e70 28 3c 79 3e 2c 20 3c 7a 3e 2e 2e 2e 29 22 2e 0a (<y>, <z>...)"..
13e80 2a 2a 20 45 78 70 72 2e 78 2e 70 53 65 6c 65 63 ** Expr.x.pSelec
13e90 74 20 69 73 20 75 73 65 64 20 69 66 20 74 68 65 t is used if the
13ea0 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 expression is a
13eb0 20 73 75 62 2d 73 65 6c 65 63 74 20 6f 72 20 61 sub-select or a
13ec0 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 0a n expression of.
13ed0 2a 2a 20 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 ** the form "<lh
13ee0 73 3e 20 49 4e 20 28 53 45 4c 45 43 54 20 2e 2e s> IN (SELECT ..
13ef0 2e 29 22 2e 20 49 66 20 74 68 65 20 45 50 5f 78 .)". If the EP_x
13f00 49 73 53 65 6c 65 63 74 20 62 69 74 20 69 73 20 IsSelect bit is
13f10 73 65 74 20 69 6e 20 74 68 65 0a 2a 2a 20 45 78 set in the.** Ex
13f20 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 pr.flags mask, t
13f30 68 65 6e 20 45 78 70 72 2e 78 2e 70 53 65 6c 65 hen Expr.x.pSele
13f40 63 74 20 69 73 20 76 61 6c 69 64 2e 20 4f 74 68 ct is valid. Oth
13f50 65 72 77 69 73 65 2c 20 45 78 70 72 2e 78 2e 70 erwise, Expr.x.p
13f60 4c 69 73 74 20 69 73 20 0a 2a 2a 20 76 61 6c 69 List is .** vali
13f70 64 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 65 78 70 72 d..**.** An expr
13f80 65 73 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 6f ession of the fo
13f90 72 6d 20 49 44 20 6f 72 20 49 44 2e 49 44 20 72 rm ID or ID.ID r
13fa0 65 66 65 72 73 20 74 6f 20 61 20 63 6f 6c 75 6d efers to a colum
13fb0 6e 20 69 6e 20 61 20 74 61 62 6c 65 2e 0a 2a 2a n in a table..**
13fc0 20 46 6f 72 20 73 75 63 68 20 65 78 70 72 65 73 For such expres
13fd0 73 69 6f 6e 73 2c 20 45 78 70 72 2e 6f 70 20 69 sions, Expr.op i
13fe0 73 20 73 65 74 20 74 6f 20 54 4b 5f 43 4f 4c 55 s set to TK_COLU
13ff0 4d 4e 20 61 6e 64 20 45 78 70 72 2e 69 54 61 62 MN and Expr.iTab
14000 6c 65 20 69 73 0a 2a 2a 20 74 68 65 20 69 6e 74 le is.** the int
14010 65 67 65 72 20 63 75 72 73 6f 72 20 6e 75 6d 62 eger cursor numb
14020 65 72 20 6f 66 20 61 20 56 44 42 45 20 63 75 72 er of a VDBE cur
14030 73 6f 72 20 70 6f 69 6e 74 69 6e 67 20 74 6f 20 sor pointing to
14040 74 68 61 74 20 74 61 62 6c 65 20 61 6e 64 0a 2a that table and.*
14050 2a 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 69 * Expr.iColumn i
14060 73 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d s the column num
14070 62 65 72 20 66 6f 72 20 74 68 65 20 73 70 65 63 ber for the spec
14080 69 66 69 63 20 63 6f 6c 75 6d 6e 2e 20 20 49 66 ific column. If
14090 20 74 68 65 0a 2a 2a 20 65 78 70 72 65 73 73 69 the.** expressi
140a0 6f 6e 20 69 73 20 75 73 65 64 20 61 73 20 61 20 on is used as a
140b0 72 65 73 75 6c 74 20 69 6e 20 61 6e 20 61 67 67 result in an agg
140c0 72 65 67 61 74 65 20 53 45 4c 45 43 54 2c 20 74 regate SELECT, t
140d0 68 65 6e 20 74 68 65 0a 2a 2a 20 76 61 6c 75 65 hen the.** value
140e0 20 69 73 20 61 6c 73 6f 20 73 74 6f 72 65 64 20 is also stored
140f0 69 6e 20 74 68 65 20 45 78 70 72 2e 69 41 67 67 in the Expr.iAgg
14100 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 20 61 column in the a
14110 67 67 72 65 67 61 74 65 20 73 6f 20 74 68 61 74 ggregate so that
14120 0a 2a 2a 20 69 74 20 63 61 6e 20 62 65 20 61 63 .** it can be ac
14130 63 65 73 73 65 64 20 61 66 74 65 72 20 61 6c 6c cessed after all
14140 20 61 67 67 72 65 67 61 74 65 73 20 61 72 65 20 aggregates are
14150 63 6f 6d 70 75 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 computed..**.**
14160 49 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f If the expressio
14170 6e 20 69 73 20 61 6e 20 75 6e 62 6f 75 6e 64 20 n is an unbound
14180 76 61 72 69 61 62 6c 65 20 6d 61 72 6b 65 72 20 variable marker
14190 28 61 20 71 75 65 73 74 69 6f 6e 20 6d 61 72 6b (a question mark
141a0 20 0a 2a 2a 20 63 68 61 72 61 63 74 65 72 20 27 .** character '
141b0 3f 27 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e ?' in the origin
141c0 61 6c 20 53 51 4c 29 20 74 68 65 6e 20 74 68 65 al SQL) then the
141d0 20 45 78 70 72 2e 69 54 61 62 6c 65 20 68 6f 6c Expr.iTable hol
141e0 64 73 20 74 68 65 20 69 6e 64 65 78 20 0a 2a 2a ds the index .**
141f0 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 61 74 number for that
14200 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a variable..**.**
14210 20 49 66 20 74 68 65 20 65 78 70 72 65 73 73 69 If the expressi
14220 6f 6e 20 69 73 20 61 20 73 75 62 71 75 65 72 79 on is a subquery
14230 20 74 68 65 6e 20 45 78 70 72 2e 69 43 6f 6c 75 then Expr.iColu
14240 6d 6e 20 68 6f 6c 64 73 20 61 6e 20 69 6e 74 65 mn holds an inte
14250 67 65 72 0a 2a 2a 20 72 65 67 69 73 74 65 72 20 ger.** register
14260 6e 75 6d 62 65 72 20 63 6f 6e 74 61 69 6e 69 6e number containin
14270 67 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 g the result of
14280 74 68 65 20 73 75 62 71 75 65 72 79 2e 20 20 49 the subquery. I
14290 66 20 74 68 65 0a 2a 2a 20 73 75 62 71 75 65 72 f the.** subquer
142a0 79 20 67 69 76 65 73 20 61 20 63 6f 6e 73 74 61 y gives a consta
142b0 6e 74 20 72 65 73 75 6c 74 2c 20 74 68 65 6e 20 nt result, then
142c0 69 54 61 62 6c 65 20 69 73 20 2d 31 2e 20 20 49 iTable is -1. I
142d0 66 20 74 68 65 20 73 75 62 71 75 65 72 79 0a 2a f the subquery.*
142e0 2a 20 67 69 76 65 73 20 61 20 64 69 66 66 65 72 * gives a differ
142f0 65 6e 74 20 61 6e 73 77 65 72 20 61 74 20 64 69 ent answer at di
14300 66 66 65 72 65 6e 74 20 74 69 6d 65 73 20 64 75 fferent times du
14310 72 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 20 70 ring statement p
14320 72 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 74 68 65 rocessing.** the
14330 6e 20 69 54 61 62 6c 65 20 69 73 20 74 68 65 20 n iTable is the
14340 61 64 64 72 65 73 73 20 6f 66 20 61 20 73 75 62 address of a sub
14350 72 6f 75 74 69 6e 65 20 74 68 61 74 20 63 6f 6d routine that com
14360 70 75 74 65 73 20 74 68 65 20 73 75 62 71 75 65 putes the subque
14370 72 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 ry..**.** If the
14380 20 45 78 70 72 20 69 73 20 6f 66 20 74 79 70 65 Expr is of type
14390 20 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 6e 64 20 OP_Column, and
143a0 74 68 65 20 74 61 62 6c 65 20 69 74 20 69 73 20 the table it is
143b0 73 65 6c 65 63 74 69 6e 67 20 66 72 6f 6d 0a 2a selecting from.*
143c0 2a 20 69 73 20 61 20 64 69 73 6b 20 74 61 62 6c * is a disk tabl
143d0 65 20 6f 72 20 74 68 65 20 22 6f 6c 64 2e 2a 22 e or the "old.*"
143e0 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 2c 20 74 pseudo-table, t
143f0 68 65 6e 20 70 54 61 62 20 70 6f 69 6e 74 73 20 hen pTab points
14400 74 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 to the.** corres
14410 70 6f 6e 64 69 6e 67 20 74 61 62 6c 65 20 64 65 ponding table de
14420 66 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 finition..**.**
14430 41 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f 54 45 53 ALLOCATION NOTES
14440 3a 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 6f 62 6a :.**.** Expr obj
14450 65 63 74 73 20 63 61 6e 20 75 73 65 20 61 20 6c ects can use a l
14460 6f 74 20 6f 66 20 6d 65 6d 6f 72 79 20 73 70 61 ot of memory spa
14470 63 65 20 69 6e 20 64 61 74 61 62 61 73 65 20 73 ce in database s
14480 63 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a 20 68 65 chema. To.** he
14490 6c 70 20 72 65 64 75 63 65 20 6d 65 6d 6f 72 79 lp reduce memory
144a0 20 72 65 71 75 69 72 65 6d 65 6e 74 73 2c 20 73 requirements, s
144b0 6f 6d 65 74 69 6d 65 73 20 61 6e 20 45 78 70 72 ometimes an Expr
144c0 20 6f 62 6a 65 63 74 20 77 69 6c 6c 20 62 65 0a object will be.
144d0 2a 2a 20 74 72 75 6e 63 61 74 65 64 2e 20 20 41 ** truncated. A
144e0 6e 64 20 74 6f 20 72 65 64 75 63 65 20 74 68 65 nd to reduce the
144f0 20 6e 75 6d 62 65 72 20 6f 66 20 6d 65 6d 6f 72 number of memor
14500 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 2c 20 73 y allocations, s
14510 6f 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 77 6f 20 ometimes.** two
14520 6f 72 20 6d 6f 72 65 20 45 78 70 72 20 6f 62 6a or more Expr obj
14530 65 63 74 73 20 77 69 6c 6c 20 62 65 20 73 74 6f ects will be sto
14540 72 65 64 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 red in a single
14550 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f memory allocatio
14560 6e 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 72 20 77 n,.** together w
14570 69 74 68 20 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 ith Expr.zToken
14580 73 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a 2a 20 49 strings..**.** I
14590 66 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 f the EP_Reduced
145a0 20 61 6e 64 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c and EP_TokenOnl
145b0 79 20 66 6c 61 67 73 20 61 72 65 20 73 65 74 20 y flags are set
145c0 77 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 70 72 20 when.** an Expr
145d0 6f 62 6a 65 63 74 20 69 73 20 74 72 75 6e 63 61 object is trunca
145e0 74 65 64 2e 20 20 57 68 65 6e 20 45 50 5f 52 65 ted. When EP_Re
145f0 64 75 63 65 64 20 69 73 20 73 65 74 2c 20 74 68 duced is set, th
14600 65 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 20 63 68 en all.** the ch
14610 69 6c 64 20 45 78 70 72 20 6f 62 6a 65 63 74 73 ild Expr objects
14620 20 69 6e 20 74 68 65 20 45 78 70 72 2e 70 4c 65 in the Expr.pLe
14630 66 74 20 61 6e 64 20 45 78 70 72 2e 70 52 69 67 ft and Expr.pRig
14640 68 74 20 73 75 62 74 72 65 65 73 0a 2a 2a 20 61 ht subtrees.** a
14650 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 re contained wit
14660 68 69 6e 20 74 68 65 20 73 61 6d 65 20 6d 65 6d hin the same mem
14670 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 ory allocation.
14680 20 4e 6f 74 65 2c 20 68 6f 77 65 76 65 72 2c 20 Note, however,
14690 74 68 61 74 0a 2a 2a 20 74 68 65 20 73 75 62 74 that.** the subt
146a0 72 65 65 73 20 69 6e 20 45 78 70 72 2e 78 2e 70 rees in Expr.x.p
146b0 4c 69 73 74 20 6f 72 20 45 78 70 72 2e 78 2e 70 List or Expr.x.p
146c0 53 65 6c 65 63 74 20 61 72 65 20 61 6c 77 61 79 Select are alway
146d0 73 20 73 65 70 61 72 61 74 65 6c 79 0a 2a 2a 20 s separately.**
146e0 61 6c 6c 6f 63 61 74 65 64 2c 20 72 65 67 61 72 allocated, regar
146f0 64 6c 65 73 73 20 6f 66 20 77 68 65 74 68 65 72 dless of whether
14700 20 6f 72 20 6e 6f 74 20 45 50 5f 52 65 64 75 63 or not EP_Reduc
14710 65 64 20 69 73 20 73 65 74 2e 0a 2a 2f 0a 73 74 ed is set..*/.st
14720 72 75 63 74 20 45 78 70 72 20 7b 0a 20 20 75 38 ruct Expr {. u8
14730 20 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 op;
14740 20 20 20 20 20 2f 2a 20 4f 70 65 72 61 74 69 6f /* Operatio
14750 6e 20 70 65 72 66 6f 72 6d 65 64 20 62 79 20 74 n performed by t
14760 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 20 63 68 his node */. ch
14770 61 72 20 61 66 66 69 6e 69 74 79 3b 20 20 20 20 ar affinity;
14780 20 20 20 20 20 2f 2a 20 54 68 65 20 61 66 66 69 /* The affi
14790 6e 69 74 79 20 6f 66 20 74 68 65 20 63 6f 6c 75 nity of the colu
147a0 6d 6e 20 6f 72 20 30 20 69 66 20 6e 6f 74 20 61 mn or 0 if not a
147b0 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 75 33 32 column */. u32
147c0 20 66 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 flags;
147d0 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 66 /* Various f
147e0 6c 61 67 73 2e 20 20 45 50 5f 2a 20 53 65 65 20 lags. EP_* See
147f0 62 65 6c 6f 77 20 2a 2f 0a 20 20 75 6e 69 6f 6e below */. union
14800 20 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a 54 6f {. char *zTo
14810 6b 65 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ken; /*
14820 20 54 6f 6b 65 6e 20 76 61 6c 75 65 2e 20 5a 65 Token value. Ze
14830 72 6f 20 74 65 72 6d 69 6e 61 74 65 64 20 61 6e ro terminated an
14840 64 20 64 65 71 75 6f 74 65 64 20 2a 2f 0a 20 20 d dequoted */.
14850 20 20 69 6e 74 20 69 56 61 6c 75 65 3b 20 20 20 int iValue;
14860 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d /* Non-
14870 6e 65 67 61 74 69 76 65 20 69 6e 74 65 67 65 72 negative integer
14880 20 76 61 6c 75 65 20 69 66 20 45 50 5f 49 6e 74 value if EP_Int
14890 56 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a Value */. } u;.
148a0 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 45 50 5f . /* If the EP_
148b0 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 69 TokenOnly flag i
148c0 73 20 73 65 74 20 69 6e 20 74 68 65 20 45 78 70 s set in the Exp
148d0 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 r.flags mask, th
148e0 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 65 en no. ** space
148f0 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f is allocated fo
14900 72 20 74 68 65 20 66 69 65 6c 64 73 20 62 65 6c r the fields bel
14910 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 2e 20 41 ow this point. A
14920 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 20 2a n attempt to. *
14930 2a 20 61 63 63 65 73 73 20 74 68 65 6d 20 77 69 * access them wi
14940 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 20 73 ll result in a s
14950 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c 66 75 egfault or malfu
14960 6e 63 74 69 6f 6e 2e 20 0a 20 20 2a 2a 2a 2a 2a nction. . *****
14970 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14980 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14990 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
149a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
149b0 2f 0a 0a 20 20 45 78 70 72 20 2a 70 4c 65 66 74 /.. Expr *pLeft
149c0 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c ; /* L
149d0 65 66 74 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 eft subnode */.
149e0 20 45 78 70 72 20 2a 70 52 69 67 68 74 3b 20 20 Expr *pRight;
149f0 20 20 20 20 20 20 20 20 2f 2a 20 52 69 67 68 74 /* Right
14a00 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 75 6e subnode */. un
14a10 69 6f 6e 20 7b 0a 20 20 20 20 45 78 70 72 4c 69 ion {. ExprLi
14a20 73 74 20 2a 70 4c 69 73 74 3b 20 20 20 20 20 2f st *pList; /
14a30 2a 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 * op = IN, EXIST
14a40 53 2c 20 53 45 4c 45 43 54 2c 20 43 41 53 45 2c S, SELECT, CASE,
14a50 20 46 55 4e 43 54 49 4f 4e 2c 20 42 45 54 57 45 FUNCTION, BETWE
14a60 45 4e 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 74 EN */. Select
14a70 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f *pSelect; /
14a80 2a 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 61 * EP_xIsSelect a
14a90 6e 64 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 nd op = IN, EXIS
14aa0 54 53 2c 20 53 45 4c 45 43 54 20 2a 2f 0a 20 20 TS, SELECT */.
14ab0 7d 20 78 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 68 } x;.. /* If th
14ac0 65 20 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 e EP_Reduced fla
14ad0 67 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 20 g is set in the
14ae0 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c Expr.flags mask,
14af0 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 then no. ** sp
14b00 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 ace is allocated
14b10 20 66 6f 72 20 74 68 65 20 66 69 65 6c 64 73 20 for the fields
14b20 62 65 6c 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 below this point
14b30 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a . An attempt to.
14b40 20 20 2a 2a 20 61 63 63 65 73 73 20 74 68 65 6d ** access them
14b50 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 will result in
14b60 61 20 73 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 a segfault or ma
14b70 6c 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a lfunction.. ***
14b80 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14b90 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14ba0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14bb0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14bc0 2a 2a 2f 0a 0a 23 69 66 20 53 51 4c 49 54 45 5f **/..#if SQLITE_
14bd0 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 MAX_EXPR_DEPTH>0
14be0 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 74 3b 20 . int nHeight;
14bf0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 65 69 /* Hei
14c00 67 68 74 20 6f 66 20 74 68 65 20 74 72 65 65 20 ght of the tree
14c10 68 65 61 64 65 64 20 62 79 20 74 68 69 73 20 6e headed by this n
14c20 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 ode */.#endif.
14c30 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 20 int iTable;
14c40 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c /* TK_COL
14c50 55 4d 4e 3a 20 63 75 72 73 6f 72 20 6e 75 6d 62 UMN: cursor numb
14c60 65 72 20 6f 66 20 74 61 62 6c 65 20 68 6f 6c 64 er of table hold
14c70 69 6e 67 20 63 6f 6c 75 6d 6e 0a 20 20 20 20 20 ing column.
14c80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14c90 20 20 20 20 2a 2a 20 54 4b 5f 52 45 47 49 53 54 ** TK_REGIST
14ca0 45 52 3a 20 72 65 67 69 73 74 65 72 20 6e 75 6d ER: register num
14cb0 62 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 ber.
14cc0 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
14cd0 54 4b 5f 54 52 49 47 47 45 52 3a 20 31 20 2d 3e TK_TRIGGER: 1 ->
14ce0 20 6e 65 77 2c 20 30 20 2d 3e 20 6f 6c 64 0a 20 new, 0 -> old.
14cf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14d00 20 20 20 20 20 20 20 20 2a 2a 20 45 50 5f 55 6e ** EP_Un
14d10 6c 69 6b 65 6c 79 3a 20 20 31 33 34 32 31 37 37 likely: 1342177
14d20 32 38 20 74 69 6d 65 73 20 6c 69 6b 65 6c 69 68 28 times likelih
14d30 6f 6f 64 20 2a 2f 0a 20 20 79 6e 56 61 72 20 69 ood */. ynVar i
14d40 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 Column;
14d50 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 6f /* TK_COLUMN: co
14d60 6c 75 6d 6e 20 69 6e 64 65 78 2e 20 20 2d 31 20 lumn index. -1
14d70 66 6f 72 20 72 6f 77 69 64 2e 0a 20 20 20 20 20 for rowid..
14d80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14d90 20 20 20 20 2a 2a 20 54 4b 5f 56 41 52 49 41 42 ** TK_VARIAB
14da0 4c 45 3a 20 76 61 72 69 61 62 6c 65 20 6e 75 6d LE: variable num
14db0 62 65 72 20 28 61 6c 77 61 79 73 20 3e 3d 20 31 ber (always >= 1
14dc0 29 2e 20 2a 2f 0a 20 20 69 31 36 20 69 41 67 67 ). */. i16 iAgg
14dd0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
14de0 2a 20 57 68 69 63 68 20 65 6e 74 72 79 20 69 6e * Which entry in
14df0 20 70 41 67 67 49 6e 66 6f 2d 3e 61 43 6f 6c 5b pAggInfo->aCol[
14e00 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 5b 5d 20 2a ] or ->aFunc[] *
14e10 2f 0a 20 20 69 31 36 20 69 52 69 67 68 74 4a 6f /. i16 iRightJo
14e20 69 6e 54 61 62 6c 65 3b 20 20 20 2f 2a 20 49 66 inTable; /* If
14e30 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 2c 20 74 68 EP_FromJoin, th
14e40 65 20 72 69 67 68 74 20 74 61 62 6c 65 20 6f 66 e right table of
14e50 20 74 68 65 20 6a 6f 69 6e 20 2a 2f 0a 20 20 75 the join */. u
14e60 38 20 6f 70 32 3b 20 20 20 20 20 20 20 20 20 20 8 op2;
14e70 20 20 20 20 20 20 2f 2a 20 54 4b 5f 52 45 47 49 /* TK_REGI
14e80 53 54 45 52 3a 20 6f 72 69 67 69 6e 61 6c 20 76 STER: original v
14e90 61 6c 75 65 20 6f 66 20 45 78 70 72 2e 6f 70 0a alue of Expr.op.
14ea0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14eb0 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 43 ** TK_C
14ec0 4f 4c 55 4d 4e 3a 20 74 68 65 20 76 61 6c 75 65 OLUMN: the value
14ed0 20 6f 66 20 70 35 20 66 6f 72 20 4f 50 5f 43 6f of p5 for OP_Co
14ee0 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 20 20 lumn.
14ef0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
14f00 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e TK_AGG_FUNCTION
14f10 3a 20 6e 65 73 74 69 6e 67 20 64 65 70 74 68 20 : nesting depth
14f20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 41 */. AggInfo *pA
14f30 67 67 49 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 55 ggInfo; /* U
14f40 73 65 64 20 62 79 20 54 4b 5f 41 47 47 5f 43 4f sed by TK_AGG_CO
14f50 4c 55 4d 4e 20 61 6e 64 20 54 4b 5f 41 47 47 5f LUMN and TK_AGG_
14f60 46 55 4e 43 54 49 4f 4e 20 2a 2f 0a 20 20 54 61 FUNCTION */. Ta
14f70 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 ble *pTab;
14f80 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 66 6f /* Table fo
14f90 72 20 54 4b 5f 43 4f 4c 55 4d 4e 20 65 78 70 72 r TK_COLUMN expr
14fa0 65 73 73 69 6f 6e 73 2e 20 2a 2f 0a 7d 3b 0a 0a essions. */.};..
14fb0 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
14fc0 69 6e 67 20 61 72 65 20 74 68 65 20 6d 65 61 6e ing are the mean
14fd0 69 6e 67 73 20 6f 66 20 62 69 74 73 20 69 6e 20 ings of bits in
14fe0 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 66 the Expr.flags f
14ff0 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ield..*/.#define
15000 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 20 30 78 EP_FromJoin 0x
15010 30 30 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 6e 000001 /* Origin
15020 61 74 65 73 20 69 6e 20 4f 4e 2f 55 53 49 4e 47 ates in ON/USING
15030 20 63 6c 61 75 73 65 20 6f 66 20 6f 75 74 65 72 clause of outer
15040 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 join */.#define
15050 20 45 50 5f 41 67 67 20 20 20 20 20 20 20 30 78 EP_Agg 0x
15060 30 30 30 30 30 32 20 2f 2a 20 43 6f 6e 74 61 69 000002 /* Contai
15070 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 61 ns one or more a
15080 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
15090 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 ns */.#define EP
150a0 5f 52 65 73 6f 6c 76 65 64 20 20 30 78 30 30 30 _Resolved 0x000
150b0 30 30 34 20 2f 2a 20 49 44 73 20 68 61 76 65 20 004 /* IDs have
150c0 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 74 6f been resolved to
150d0 20 43 4f 4c 55 4d 4e 73 20 2a 2f 0a 23 64 65 66 COLUMNs */.#def
150e0 69 6e 65 20 45 50 5f 45 72 72 6f 72 20 20 20 20 ine EP_Error
150f0 20 30 78 30 30 30 30 30 38 20 2f 2a 20 45 78 70 0x000008 /* Exp
15100 72 65 73 73 69 6f 6e 20 63 6f 6e 74 61 69 6e 73 ression contains
15110 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 65 72 72 one or more err
15120 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ors */.#define E
15130 50 5f 44 69 73 74 69 6e 63 74 20 20 30 78 30 30 P_Distinct 0x00
15140 30 30 31 30 20 2f 2a 20 41 67 67 72 65 67 61 74 0010 /* Aggregat
15150 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 e function with
15160 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 64 DISTINCT keyword
15170 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 56 */.#define EP_V
15180 61 72 53 65 6c 65 63 74 20 30 78 30 30 30 30 32 arSelect 0x00002
15190 30 20 2f 2a 20 70 53 65 6c 65 63 74 20 69 73 20 0 /* pSelect is
151a0 63 6f 72 72 65 6c 61 74 65 64 2c 20 6e 6f 74 20 correlated, not
151b0 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a 23 64 65 66 constant */.#def
151c0 69 6e 65 20 45 50 5f 44 62 6c 51 75 6f 74 65 64 ine EP_DblQuoted
151d0 20 30 78 30 30 30 30 34 30 20 2f 2a 20 74 6f 6b 0x000040 /* tok
151e0 65 6e 2e 7a 20 77 61 73 20 6f 72 69 67 69 6e 61 en.z was origina
151f0 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 20 2a 2f 0a lly in "..." */.
15200 23 64 65 66 69 6e 65 20 45 50 5f 49 6e 66 69 78 #define EP_Infix
15210 46 75 6e 63 20 30 78 30 30 30 30 38 30 20 2f 2a Func 0x000080 /*
15220 20 54 72 75 65 20 66 6f 72 20 61 6e 20 69 6e 66 True for an inf
15230 69 78 20 66 75 6e 63 74 69 6f 6e 3a 20 4c 49 4b ix function: LIK
15240 45 2c 20 47 4c 4f 42 2c 20 65 74 63 20 2a 2f 0a E, GLOB, etc */.
15250 23 64 65 66 69 6e 65 20 45 50 5f 43 6f 6c 6c 61 #define EP_Colla
15260 74 65 20 20 20 30 78 30 30 30 31 30 30 20 2f 2a te 0x000100 /*
15270 20 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 Tree contains a
15280 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 6f 70 65 72 TK_COLLATE oper
15290 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ator */.#define
152a0 45 50 5f 47 65 6e 65 72 69 63 20 20 20 30 78 30 EP_Generic 0x0
152b0 30 30 32 30 30 20 2f 2a 20 49 67 6e 6f 72 65 20 00200 /* Ignore
152c0 43 4f 4c 4c 41 54 45 20 6f 72 20 61 66 66 69 6e COLLATE or affin
152d0 69 74 79 20 6f 6e 20 74 68 69 73 20 74 72 65 65 ity on this tree
152e0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 */.#define EP_I
152f0 6e 74 56 61 6c 75 65 20 20 30 78 30 30 30 34 30 ntValue 0x00040
15300 30 20 2f 2a 20 49 6e 74 65 67 65 72 20 76 61 6c 0 /* Integer val
15310 75 65 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 ue contained in
15320 75 2e 69 56 61 6c 75 65 20 2a 2f 0a 23 64 65 66 u.iValue */.#def
15330 69 6e 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 ine EP_xIsSelect
15340 20 30 78 30 30 30 38 30 30 20 2f 2a 20 78 2e 70 0x000800 /* x.p
15350 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 64 20 Select is valid
15360 28 6f 74 68 65 72 77 69 73 65 20 78 2e 70 4c 69 (otherwise x.pLi
15370 73 74 20 69 73 29 20 2a 2f 0a 23 64 65 66 69 6e st is) */.#defin
15380 65 20 45 50 5f 53 6b 69 70 20 20 20 20 20 20 30 e EP_Skip 0
15390 78 30 30 31 30 30 30 20 2f 2a 20 43 4f 4c 4c 41 x001000 /* COLLA
153a0 54 45 2c 20 41 53 2c 20 6f 72 20 55 4e 4c 49 4b TE, AS, or UNLIK
153b0 45 4c 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ELY */.#define E
153c0 50 5f 52 65 64 75 63 65 64 20 20 20 30 78 30 30 P_Reduced 0x00
153d0 32 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 2000 /* Expr str
153e0 75 63 74 20 45 58 50 52 5f 52 45 44 55 43 45 44 uct EXPR_REDUCED
153f0 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 SIZE bytes only
15400 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 54 6f */.#define EP_To
15410 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 34 30 30 30 kenOnly 0x004000
15420 20 2f 2a 20 45 78 70 72 20 73 74 72 75 63 74 20 /* Expr struct
15430 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 EXPR_TOKENONLYSI
15440 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a 2f ZE bytes only */
15450 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 74 61 74 .#define EP_Stat
15460 69 63 20 20 20 20 30 78 30 30 38 30 30 30 20 2f ic 0x008000 /
15470 2a 20 48 65 6c 64 20 69 6e 20 6d 65 6d 6f 72 79 * Held in memory
15480 20 6e 6f 74 20 6f 62 74 61 69 6e 65 64 20 66 72 not obtained fr
15490 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 23 om malloc() */.#
154a0 64 65 66 69 6e 65 20 45 50 5f 4d 65 6d 54 6f 6b define EP_MemTok
154b0 65 6e 20 20 30 78 30 31 30 30 30 30 20 2f 2a 20 en 0x010000 /*
154c0 4e 65 65 64 20 74 6f 20 73 71 6c 69 74 65 33 44 Need to sqlite3D
154d0 62 46 72 65 65 28 29 20 45 78 70 72 2e 7a 54 6f bFree() Expr.zTo
154e0 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ken */.#define E
154f0 50 5f 4e 6f 52 65 64 75 63 65 20 20 30 78 30 32 P_NoReduce 0x02
15500 30 30 30 30 20 2f 2a 20 43 61 6e 6e 6f 74 20 45 0000 /* Cannot E
15510 58 50 52 44 55 50 5f 52 45 44 55 43 45 20 74 68 XPRDUP_REDUCE th
15520 69 73 20 45 78 70 72 20 2a 2f 0a 23 64 65 66 69 is Expr */.#defi
15530 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 20 20 ne EP_Unlikely
15540 30 78 30 34 30 30 30 30 20 2f 2a 20 75 6e 6c 69 0x040000 /* unli
15550 6b 65 6c 79 28 29 20 6f 72 20 6c 69 6b 65 6c 69 kely() or likeli
15560 68 6f 6f 64 28 29 20 66 75 6e 63 74 69 6f 6e 20 hood() function
15570 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f */.#define EP_Co
15580 6e 73 74 46 75 6e 63 20 30 78 30 38 30 30 30 30 nstFunc 0x080000
15590 20 2f 2a 20 4e 6f 64 65 20 69 73 20 61 20 53 51 /* Node is a SQ
155a0 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 LITE_FUNC_CONSTA
155b0 4e 54 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 NT function */.#
155c0 64 65 66 69 6e 65 20 45 50 5f 43 61 6e 42 65 4e define EP_CanBeN
155d0 75 6c 6c 20 30 78 31 30 30 30 30 30 20 2f 2a 20 ull 0x100000 /*
155e0 43 61 6e 20 62 65 20 6e 75 6c 6c 20 64 65 73 70 Can be null desp
155f0 69 74 65 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e ite NOT NULL con
15600 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 straint */.#defi
15610 6e 65 20 45 50 5f 53 75 62 71 75 65 72 79 20 20 ne EP_Subquery
15620 30 78 32 30 30 30 30 30 20 2f 2a 20 54 72 65 65 0x200000 /* Tree
15630 20 63 6f 6e 74 61 69 6e 73 20 61 20 54 4b 5f 53 contains a TK_S
15640 45 4c 45 43 54 20 6f 70 65 72 61 74 6f 72 20 2a ELECT operator *
15650 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6d 62 69 6e 61 /../*.** Combina
15660 74 69 6f 6e 73 20 6f 66 20 74 77 6f 20 6f 72 20 tions of two or
15670 6d 6f 72 65 20 45 50 5f 2a 20 66 6c 61 67 73 0a more EP_* flags.
15680 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 50 72 */.#define EP_Pr
15690 6f 70 61 67 61 74 65 20 28 45 50 5f 43 6f 6c 6c opagate (EP_Coll
156a0 61 74 65 7c 45 50 5f 53 75 62 71 75 65 72 79 29 ate|EP_Subquery)
156b0 20 2f 2a 20 50 72 6f 70 61 67 61 74 65 20 74 68 /* Propagate th
156c0 65 73 65 20 62 69 74 73 20 75 70 20 74 72 65 65 ese bits up tree
156d0 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 65 */../*.** These
156e0 20 6d 61 63 72 6f 73 20 63 61 6e 20 62 65 20 75 macros can be u
156f0 73 65 64 20 74 6f 20 74 65 73 74 2c 20 73 65 74 sed to test, set
15700 2c 20 6f 72 20 63 6c 65 61 72 20 62 69 74 73 20 , or clear bits
15710 69 6e 20 74 68 65 20 0a 2a 2a 20 45 78 70 72 2e in the .** Expr.
15720 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a flags field..*/.
15730 23 64 65 66 69 6e 65 20 45 78 70 72 48 61 73 50 #define ExprHasP
15740 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 20 20 roperty(E,P)
15750 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 50 (((E)->flags&(P
15760 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 45 ))!=0).#define E
15770 78 70 72 48 61 73 41 6c 6c 50 72 6f 70 65 72 74 xprHasAllPropert
15780 79 28 45 2c 50 29 20 20 28 28 28 45 29 2d 3e 66 y(E,P) (((E)->f
15790 6c 61 67 73 26 28 50 29 29 3d 3d 28 50 29 29 0a lags&(P))==(P)).
157a0 23 64 65 66 69 6e 65 20 45 78 70 72 53 65 74 50 #define ExprSetP
157b0 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 20 20 roperty(E,P)
157c0 20 28 45 29 2d 3e 66 6c 61 67 73 7c 3d 28 50 29 (E)->flags|=(P)
157d0 0a 23 64 65 66 69 6e 65 20 45 78 70 72 43 6c 65 .#define ExprCle
157e0 61 72 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 arProperty(E,P)
157f0 20 20 28 45 29 2d 3e 66 6c 61 67 73 26 3d 7e 28 (E)->flags&=~(
15800 50 29 0a 0a 2f 2a 20 54 68 65 20 45 78 70 72 53 P)../* The ExprS
15810 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 29 20 etVVAProperty()
15820 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 6f macro is used fo
15830 72 20 56 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 r Verification,
15840 56 61 6c 69 64 61 74 69 6f 6e 2c 0a 2a 2a 20 61 Validation,.** a
15850 6e 64 20 41 63 63 72 65 64 69 74 61 74 69 6f 6e nd Accreditation
15860 20 6f 6e 6c 79 2e 20 20 49 74 20 77 6f 72 6b 73 only. It works
15870 20 6c 69 6b 65 20 45 78 70 72 53 65 74 50 72 6f like ExprSetPro
15880 70 65 72 74 79 28 29 20 64 75 72 69 6e 67 20 56 perty() during V
15890 56 41 0a 2a 2a 20 70 72 6f 63 65 73 73 65 73 20 VA.** processes
158a0 62 75 74 20 69 73 20 61 20 6e 6f 2d 6f 70 20 66 but is a no-op f
158b0 6f 72 20 64 65 6c 69 76 65 72 79 2e 0a 2a 2f 0a or delivery..*/.
158c0 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 #ifdef SQLITE_DE
158d0 42 55 47 0a 23 20 64 65 66 69 6e 65 20 45 78 70 BUG.# define Exp
158e0 72 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 rSetVVAProperty(
158f0 45 2c 50 29 20 20 28 45 29 2d 3e 66 6c 61 67 73 E,P) (E)->flags
15900 7c 3d 28 50 29 0a 23 65 6c 73 65 0a 23 20 64 65 |=(P).#else.# de
15910 66 69 6e 65 20 45 78 70 72 53 65 74 56 56 41 50 fine ExprSetVVAP
15920 72 6f 70 65 72 74 79 28 45 2c 50 29 0a 23 65 6e roperty(E,P).#en
15930 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f dif../*.** Macro
15940 73 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 74 s to determine t
15950 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 62 79 74 he number of byt
15960 65 73 20 72 65 71 75 69 72 65 64 20 62 79 20 61 es required by a
15970 20 6e 6f 72 6d 61 6c 20 45 78 70 72 20 0a 2a 2a normal Expr .**
15980 20 73 74 72 75 63 74 2c 20 61 6e 20 45 78 70 72 struct, an Expr
15990 20 73 74 72 75 63 74 20 77 69 74 68 20 74 68 65 struct with the
159a0 20 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 67 EP_Reduced flag
159b0 20 73 65 74 20 69 6e 20 45 78 70 72 2e 66 6c 61 set in Expr.fla
159c0 67 73 20 0a 2a 2a 20 61 6e 64 20 61 6e 20 45 78 gs .** and an Ex
159d0 70 72 20 73 74 72 75 63 74 20 77 69 74 68 20 74 pr struct with t
159e0 68 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 he EP_TokenOnly
159f0 66 6c 61 67 20 73 65 74 2e 0a 2a 2f 0a 23 64 65 flag set..*/.#de
15a00 66 69 6e 65 20 45 58 50 52 5f 46 55 4c 4c 53 49 fine EXPR_FULLSI
15a10 5a 45 20 20 20 20 20 20 20 20 20 20 20 73 69 7a ZE siz
15a20 65 6f 66 28 45 78 70 72 29 20 20 20 20 20 20 20 eof(Expr)
15a30 20 20 20 20 2f 2a 20 46 75 6c 6c 20 73 69 7a 65 /* Full size
15a40 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 */.#define EXPR
15a50 5f 52 45 44 55 43 45 44 53 49 5a 45 20 20 20 20 _REDUCEDSIZE
15a60 20 20 20 20 6f 66 66 73 65 74 6f 66 28 45 78 70 offsetof(Exp
15a70 72 2c 69 54 61 62 6c 65 29 20 20 2f 2a 20 43 6f r,iTable) /* Co
15a80 6d 6d 6f 6e 20 66 65 61 74 75 72 65 73 20 2a 2f mmon features */
15a90 0a 23 64 65 66 69 6e 65 20 45 58 50 52 5f 54 4f .#define EXPR_TO
15aa0 4b 45 4e 4f 4e 4c 59 53 49 5a 45 20 20 20 20 20 KENONLYSIZE
15ab0 20 6f 66 66 73 65 74 6f 66 28 45 78 70 72 2c 70 offsetof(Expr,p
15ac0 4c 65 66 74 29 20 20 20 2f 2a 20 46 65 77 65 72 Left) /* Fewer
15ad0 20 66 65 61 74 75 72 65 73 20 2a 2f 0a 0a 2f 2a features */../*
15ae0 0a 2a 2a 20 46 6c 61 67 73 20 70 61 73 73 65 64 .** Flags passed
15af0 20 74 6f 20 74 68 65 20 73 71 6c 69 74 65 33 45 to the sqlite3E
15b00 78 70 72 44 75 70 28 29 20 66 75 6e 63 74 69 6f xprDup() functio
15b10 6e 2e 20 53 65 65 20 74 68 65 20 68 65 61 64 65 n. See the heade
15b20 72 20 63 6f 6d 6d 65 6e 74 20 0a 2a 2a 20 61 62 r comment .** ab
15b30 6f 76 65 20 73 71 6c 69 74 65 33 45 78 70 72 44 ove sqlite3ExprD
15b40 75 70 28 29 20 66 6f 72 20 64 65 74 61 69 6c 73 up() for details
15b50 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 ..*/.#define EXP
15b60 52 44 55 50 5f 52 45 44 55 43 45 20 20 20 20 20 RDUP_REDUCE
15b70 20 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 55 0x0001 /* U
15b80 73 65 64 20 72 65 64 75 63 65 64 2d 73 69 7a 65 sed reduced-size
15b90 20 45 78 70 72 20 6e 6f 64 65 73 20 2a 2f 0a 0a Expr nodes */..
15ba0 2f 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 6f 66 20 /*.** A list of
15bb0 65 78 70 72 65 73 73 69 6f 6e 73 2e 20 20 45 61 expressions. Ea
15bc0 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 6d 61 ch expression ma
15bd0 79 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 68 61 76 y optionally hav
15be0 65 20 61 0a 2a 2a 20 6e 61 6d 65 2e 20 20 41 6e e a.** name. An
15bf0 20 65 78 70 72 2f 6e 61 6d 65 20 63 6f 6d 62 69 expr/name combi
15c00 6e 61 74 69 6f 6e 20 63 61 6e 20 62 65 20 75 73 nation can be us
15c10 65 64 20 69 6e 20 73 65 76 65 72 61 6c 20 77 61 ed in several wa
15c20 79 73 2c 20 73 75 63 68 0a 2a 2a 20 61 73 20 74 ys, such.** as t
15c30 68 65 20 6c 69 73 74 20 6f 66 20 22 65 78 70 72 he list of "expr
15c40 20 41 53 20 49 44 22 20 66 69 65 6c 64 73 20 66 AS ID" fields f
15c50 6f 6c 6c 6f 77 69 6e 67 20 61 20 22 53 45 4c 45 ollowing a "SELE
15c60 43 54 22 20 6f 72 20 69 6e 20 74 68 65 0a 2a 2a CT" or in the.**
15c70 20 6c 69 73 74 20 6f 66 20 22 49 44 20 3d 20 65 list of "ID = e
15c80 78 70 72 22 20 69 74 65 6d 73 20 69 6e 20 61 6e xpr" items in an
15c90 20 55 50 44 41 54 45 2e 20 20 41 20 6c 69 73 74 UPDATE. A list
15ca0 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 of expressions
15cb0 63 61 6e 0a 2a 2a 20 61 6c 73 6f 20 62 65 20 75 can.** also be u
15cc0 73 65 64 20 61 73 20 74 68 65 20 61 72 67 75 6d sed as the argum
15cd0 65 6e 74 20 74 6f 20 61 20 66 75 6e 63 74 69 6f ent to a functio
15ce0 6e 2c 20 69 6e 20 77 68 69 63 68 20 63 61 73 65 n, in which case
15cf0 20 74 68 65 20 61 2e 7a 4e 61 6d 65 0a 2a 2a 20 the a.zName.**
15d00 66 69 65 6c 64 20 69 73 20 6e 6f 74 20 75 73 65 field is not use
15d10 64 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 65 66 61 d..**.** By defa
15d20 75 6c 74 20 74 68 65 20 45 78 70 72 2e 7a 53 70 ult the Expr.zSp
15d30 61 6e 20 66 69 65 6c 64 20 68 6f 6c 64 73 20 61 an field holds a
15d40 20 68 75 6d 61 6e 2d 72 65 61 64 61 62 6c 65 20 human-readable
15d50 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 0a 2a description of.*
15d60 2a 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e * the expression
15d70 20 74 68 61 74 20 69 73 20 75 73 65 64 20 69 6e that is used in
15d80 20 74 68 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 the generation
15d90 6f 66 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 of error message
15da0 73 20 61 6e 64 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 s and.** column
15db0 6c 61 62 65 6c 73 2e 20 20 49 6e 20 74 68 69 73 labels. In this
15dc0 20 63 61 73 65 2c 20 45 78 70 72 2e 7a 53 70 61 case, Expr.zSpa
15dd0 6e 20 69 73 20 74 79 70 69 63 61 6c 6c 79 20 74 n is typically t
15de0 68 65 20 74 65 78 74 20 6f 66 20 61 0a 2a 2a 20 he text of a.**
15df0 63 6f 6c 75 6d 6e 20 65 78 70 72 65 73 73 69 6f column expressio
15e00 6e 20 61 73 20 69 74 20 65 78 69 73 74 73 20 69 n as it exists i
15e10 6e 20 61 20 53 45 4c 45 43 54 20 73 74 61 74 65 n a SELECT state
15e20 6d 65 6e 74 2e 20 20 48 6f 77 65 76 65 72 2c 20 ment. However,
15e30 69 66 0a 2a 2a 20 74 68 65 20 62 53 70 61 6e 49 if.** the bSpanI
15e40 73 54 61 62 20 66 6c 61 67 20 69 73 20 73 65 74 sTab flag is set
15e50 2c 20 74 68 65 6e 20 7a 53 70 61 6e 20 69 73 20 , then zSpan is
15e60 6f 76 65 72 6c 6f 61 64 65 64 20 74 6f 20 6d 65 overloaded to me
15e70 61 6e 20 74 68 65 20 6e 61 6d 65 0a 2a 2a 20 6f an the name.** o
15e80 66 20 74 68 65 20 72 65 73 75 6c 74 20 63 6f 6c f the result col
15e90 75 6d 6e 20 69 6e 20 74 68 65 20 66 6f 72 6d 3a umn in the form:
15ea0 20 44 41 54 41 42 41 53 45 2e 54 41 42 4c 45 2e DATABASE.TABLE.
15eb0 43 4f 4c 55 4d 4e 2e 20 20 54 68 69 73 20 6c 61 COLUMN. This la
15ec0 74 65 72 0a 2a 2a 20 66 6f 72 6d 20 69 73 20 75 ter.** form is u
15ed0 73 65 64 20 66 6f 72 20 6e 61 6d 65 20 72 65 73 sed for name res
15ee0 6f 6c 75 74 69 6f 6e 20 77 69 74 68 20 6e 65 73 olution with nes
15ef0 74 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 73 ted FROM clauses
15f00 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 70 72 ..*/.struct Expr
15f10 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 45 78 List {. int nEx
15f20 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pr;
15f30 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 78 70 /* Number of exp
15f40 72 65 73 73 69 6f 6e 73 20 6f 6e 20 74 68 65 20 ressions on the
15f50 6c 69 73 74 20 2a 2f 0a 20 20 73 74 72 75 63 74 list */. struct
15f60 20 45 78 70 72 4c 69 73 74 5f 69 74 65 6d 20 7b ExprList_item {
15f70 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 65 78 70 /* For each exp
15f80 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 20 6c ression in the l
15f90 69 73 74 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 ist */. Expr
15fa0 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 *pExpr;
15fb0 20 20 20 2f 2a 20 54 68 65 20 6c 69 73 74 20 6f /* The list o
15fc0 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f f expressions */
15fd0 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 . char *zName
15fe0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
15ff0 54 6f 6b 65 6e 20 61 73 73 6f 63 69 61 74 65 64 Token associated
16000 20 77 69 74 68 20 74 68 69 73 20 65 78 70 72 65 with this expre
16010 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 63 68 61 ssion */. cha
16020 72 20 2a 7a 53 70 61 6e 3b 20 20 20 20 20 20 20 r *zSpan;
16030 20 20 20 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c /* Original
16040 20 74 65 78 74 20 6f 66 20 74 68 65 20 65 78 70 text of the exp
16050 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 75 ression */. u
16060 38 20 73 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 8 sortOrder;
16070 20 20 20 20 20 20 20 2f 2a 20 31 20 66 6f 72 20 /* 1 for
16080 44 45 53 43 20 6f 72 20 30 20 66 6f 72 20 41 53 DESC or 0 for AS
16090 43 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 C */. unsigne
160a0 64 20 64 6f 6e 65 20 3a 31 3b 20 20 20 20 20 20 d done :1;
160b0 20 2f 2a 20 41 20 66 6c 61 67 20 74 6f 20 69 6e /* A flag to in
160c0 64 69 63 61 74 65 20 77 68 65 6e 20 70 72 6f 63 dicate when proc
160d0 65 73 73 69 6e 67 20 69 73 20 66 69 6e 69 73 68 essing is finish
160e0 65 64 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e ed */. unsign
160f0 65 64 20 62 53 70 61 6e 49 73 54 61 62 20 3a 31 ed bSpanIsTab :1
16100 3b 20 2f 2a 20 7a 53 70 61 6e 20 68 6f 6c 64 73 ; /* zSpan holds
16110 20 44 42 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e DB.TABLE.COLUMN
16120 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
16130 20 72 65 75 73 61 62 6c 65 20 3a 31 3b 20 20 20 reusable :1;
16140 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 78 70 72 /* Constant expr
16150 65 73 73 69 6f 6e 20 69 73 20 72 65 75 73 61 62 ession is reusab
16160 6c 65 20 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 le */. union
16170 7b 0a 20 20 20 20 20 20 73 74 72 75 63 74 20 7b {. struct {
16180 0a 20 20 20 20 20 20 20 20 75 31 36 20 69 4f 72 . u16 iOr
16190 64 65 72 42 79 43 6f 6c 3b 20 20 20 20 20 20 2f derByCol; /
161a0 2a 20 46 6f 72 20 4f 52 44 45 52 20 42 59 2c 20 * For ORDER BY,
161b0 63 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e column number in
161c0 20 72 65 73 75 6c 74 20 73 65 74 20 2a 2f 0a 20 result set */.
161d0 20 20 20 20 20 20 20 75 31 36 20 69 41 6c 69 61 u16 iAlia
161e0 73 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 s; /*
161f0 49 6e 64 65 78 20 69 6e 74 6f 20 50 61 72 73 65 Index into Parse
16200 2e 61 41 6c 69 61 73 5b 5d 20 66 6f 72 20 7a 4e .aAlias[] for zN
16210 61 6d 65 20 2a 2f 0a 20 20 20 20 20 20 7d 20 78 ame */. } x
16220 3b 0a 20 20 20 20 20 20 69 6e 74 20 69 43 6f 6e ;. int iCon
16230 73 74 45 78 70 72 52 65 67 3b 20 20 20 20 20 20 stExprReg;
16240 2f 2a 20 52 65 67 69 73 74 65 72 20 69 6e 20 77 /* Register in w
16250 68 69 63 68 20 45 78 70 72 20 76 61 6c 75 65 20 hich Expr value
16260 69 73 20 63 61 63 68 65 64 20 2a 2f 0a 20 20 20 is cached */.
16270 20 7d 20 75 3b 0a 20 20 7d 20 2a 61 3b 20 20 20 } u;. } *a;
16280 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
16290 2a 20 41 6c 6c 6f 63 20 61 20 70 6f 77 65 72 20 * Alloc a power
162a0 6f 66 20 74 77 6f 20 67 72 65 61 74 65 72 20 6f of two greater o
162b0 72 20 65 71 75 61 6c 20 74 6f 20 6e 45 78 70 72 r equal to nExpr
162c0 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e */.};../*.** An
162d0 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 instance of thi
162e0 73 20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 s structure is u
162f0 73 65 64 20 62 79 20 74 68 65 20 70 61 72 73 65 sed by the parse
16300 72 20 74 6f 20 72 65 63 6f 72 64 20 62 6f 74 68 r to record both
16310 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 20 74 72 .** the parse tr
16320 65 65 20 66 6f 72 20 61 6e 20 65 78 70 72 65 73 ee for an expres
16330 73 69 6f 6e 20 61 6e 64 20 74 68 65 20 73 70 61 sion and the spa
16340 6e 20 6f 66 20 69 6e 70 75 74 20 74 65 78 74 20 n of input text
16350 66 6f 72 20 61 6e 0a 2a 2a 20 65 78 70 72 65 73 for an.** expres
16360 73 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 sion..*/.struct
16370 45 78 70 72 53 70 61 6e 20 7b 0a 20 20 45 78 70 ExprSpan {. Exp
16380 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 r *pExpr;
16390 20 20 20 2f 2a 20 54 68 65 20 65 78 70 72 65 73 /* The expres
163a0 73 69 6f 6e 20 70 61 72 73 65 20 74 72 65 65 20 sion parse tree
163b0 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
163c0 2a 7a 53 74 61 72 74 3b 20 20 20 2f 2a 20 46 69 *zStart; /* Fi
163d0 72 73 74 20 63 68 61 72 61 63 74 65 72 20 6f 66 rst character of
163e0 20 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 input text */.
163f0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 45 6e const char *zEn
16400 64 3b 20 20 20 20 20 2f 2a 20 4f 6e 65 20 63 68 d; /* One ch
16410 61 72 61 63 74 65 72 20 70 61 73 74 20 74 68 65 aracter past the
16420 20 65 6e 64 20 6f 66 20 69 6e 70 75 74 20 74 65 end of input te
16430 78 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 xt */.};../*.**
16440 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
16450 68 69 73 20 73 74 72 75 63 74 75 72 65 20 63 61 his structure ca
16460 6e 20 68 6f 6c 64 20 61 20 73 69 6d 70 6c 65 20 n hold a simple
16470 6c 69 73 74 20 6f 66 20 69 64 65 6e 74 69 66 69 list of identifi
16480 65 72 73 2c 0a 2a 2a 20 73 75 63 68 20 61 73 20 ers,.** such as
16490 74 68 65 20 6c 69 73 74 20 22 61 2c 62 2c 63 22 the list "a,b,c"
164a0 20 69 6e 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e in the followin
164b0 67 20 73 74 61 74 65 6d 65 6e 74 73 3a 0a 2a 2a g statements:.**
164c0 0a 2a 2a 20 20 20 20 20 20 49 4e 53 45 52 54 20 .** INSERT
164d0 49 4e 54 4f 20 74 28 61 2c 62 2c 63 29 20 56 41 INTO t(a,b,c) VA
164e0 4c 55 45 53 20 2e 2e 2e 3b 0a 2a 2a 20 20 20 20 LUES ...;.**
164f0 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 69 CREATE INDEX i
16500 64 78 20 4f 4e 20 74 28 61 2c 62 2c 63 29 3b 0a dx ON t(a,b,c);.
16510 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 20 54 ** CREATE T
16520 52 49 47 47 45 52 20 74 72 69 67 20 42 45 46 4f RIGGER trig BEFO
16530 52 45 20 55 50 44 41 54 45 20 4f 4e 20 74 28 61 RE UPDATE ON t(a
16540 2c 62 2c 63 29 20 2e 2e 2e 3b 0a 2a 2a 0a 2a 2a ,b,c) ...;.**.**
16550 20 54 68 65 20 49 64 4c 69 73 74 2e 61 2e 69 64 The IdList.a.id
16560 78 20 66 69 65 6c 64 20 69 73 20 75 73 65 64 20 x field is used
16570 77 68 65 6e 20 74 68 65 20 49 64 4c 69 73 74 20 when the IdList
16580 72 65 70 72 65 73 65 6e 74 73 20 74 68 65 20 6c represents the l
16590 69 73 74 20 6f 66 0a 2a 2a 20 63 6f 6c 75 6d 6e ist of.** column
165a0 20 6e 61 6d 65 73 20 61 66 74 65 72 20 61 20 74 names after a t
165b0 61 62 6c 65 20 6e 61 6d 65 20 69 6e 20 61 6e 20 able name in an
165c0 49 4e 53 45 52 54 20 73 74 61 74 65 6d 65 6e 74 INSERT statement
165d0 2e 20 20 49 6e 20 74 68 65 20 73 74 61 74 65 6d . In the statem
165e0 65 6e 74 0a 2a 2a 0a 2a 2a 20 20 20 20 20 49 4e ent.**.** IN
165f0 53 45 52 54 20 49 4e 54 4f 20 74 28 61 2c 62 2c SERT INTO t(a,b,
16600 63 29 20 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 c) ....**.** If
16610 22 61 22 20 69 73 20 74 68 65 20 6b 2d 74 68 20 "a" is the k-th
16620 63 6f 6c 75 6d 6e 20 6f 66 20 74 61 62 6c 65 20 column of table
16630 22 74 22 2c 20 74 68 65 6e 20 49 64 4c 69 73 74 "t", then IdList
16640 2e 61 5b 30 5d 2e 69 64 78 3d 3d 6b 2e 0a 2a 2f .a[0].idx==k..*/
16650 0a 73 74 72 75 63 74 20 49 64 4c 69 73 74 20 7b .struct IdList {
16660 0a 20 20 73 74 72 75 63 74 20 49 64 4c 69 73 74 . struct IdList
16670 5f 69 74 65 6d 20 7b 0a 20 20 20 20 63 68 61 72 _item {. char
16680 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a *zName; /*
16690 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 69 64 65 Name of the ide
166a0 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 69 ntifier */. i
166b0 6e 74 20 69 64 78 3b 20 20 20 20 20 20 20 20 20 nt idx;
166c0 20 2f 2a 20 49 6e 64 65 78 20 69 6e 20 73 6f 6d /* Index in som
166d0 65 20 54 61 62 6c 65 2e 61 43 6f 6c 5b 5d 20 6f e Table.aCol[] o
166e0 66 20 61 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 64 f a column named
166f0 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 7d 20 2a 61 zName */. } *a
16700 3b 0a 20 20 69 6e 74 20 6e 49 64 3b 20 20 20 20 ;. int nId;
16710 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
16720 66 20 69 64 65 6e 74 69 66 69 65 72 73 20 6f 6e f identifiers on
16730 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a the list */.};.
16740 0a 2f 2a 0a 2a 2a 20 54 68 65 20 62 69 74 6d 61 ./*.** The bitma
16750 73 6b 20 64 61 74 61 74 79 70 65 20 64 65 66 69 sk datatype defi
16760 6e 65 64 20 62 65 6c 6f 77 20 69 73 20 75 73 65 ned below is use
16770 64 20 66 6f 72 20 76 61 72 69 6f 75 73 20 6f 70 d for various op
16780 74 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2a 0a timizations..**.
16790 2a 2a 20 43 68 61 6e 67 69 6e 67 20 74 68 69 73 ** Changing this
167a0 20 66 72 6f 6d 20 61 20 36 34 2d 62 69 74 20 74 from a 64-bit t
167b0 6f 20 61 20 33 32 2d 62 69 74 20 74 79 70 65 20 o a 32-bit type
167c0 6c 69 6d 69 74 73 20 74 68 65 20 6e 75 6d 62 65 limits the numbe
167d0 72 20 6f 66 0a 2a 2a 20 74 61 62 6c 65 73 20 69 r of.** tables i
167e0 6e 20 61 20 6a 6f 69 6e 20 74 6f 20 33 32 20 69 n a join to 32 i
167f0 6e 73 74 65 61 64 20 6f 66 20 36 34 2e 20 20 42 nstead of 64. B
16800 75 74 20 69 74 20 61 6c 73 6f 20 72 65 64 75 63 ut it also reduc
16810 65 73 20 74 68 65 20 73 69 7a 65 0a 2a 2a 20 6f es the size.** o
16820 66 20 74 68 65 20 6c 69 62 72 61 72 79 20 62 79 f the library by
16830 20 37 33 38 20 62 79 74 65 73 20 6f 6e 20 69 78 738 bytes on ix
16840 38 36 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 75 86..*/.typedef u
16850 36 34 20 42 69 74 6d 61 73 6b 3b 0a 0a 2f 2a 0a 64 Bitmask;../*.
16860 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 20 6f 66 ** The number of
16870 20 62 69 74 73 20 69 6e 20 61 20 42 69 74 6d 61 bits in a Bitma
16880 73 6b 2e 20 20 22 42 4d 53 22 20 6d 65 61 6e 73 sk. "BMS" means
16890 20 22 42 69 74 4d 61 73 6b 20 53 69 7a 65 22 2e "BitMask Size".
168a0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 42 4d 53 20 .*/.#define BMS
168b0 20 28 28 69 6e 74 29 28 73 69 7a 65 6f 66 28 42 ((int)(sizeof(B
168c0 69 74 6d 61 73 6b 29 2a 38 29 29 0a 0a 2f 2a 0a itmask)*8))../*.
168d0 2a 2a 20 41 20 62 69 74 20 69 6e 20 61 20 42 69 ** A bit in a Bi
168e0 74 6d 61 73 6b 0a 2a 2f 0a 23 64 65 66 69 6e 65 tmask.*/.#define
168f0 20 4d 41 53 4b 42 49 54 28 6e 29 20 20 20 28 28 MASKBIT(n) ((
16900 28 42 69 74 6d 61 73 6b 29 31 29 3c 3c 28 6e 29 (Bitmask)1)<<(n)
16910 29 0a 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 ).#define MASKBI
16920 54 33 32 28 6e 29 20 28 28 28 75 6e 73 69 67 6e T32(n) (((unsign
16930 65 64 20 69 6e 74 29 31 29 3c 3c 28 6e 29 29 0a ed int)1)<<(n)).
16940 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
16950 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 64 wing structure d
16960 65 73 63 72 69 62 65 73 20 74 68 65 20 46 52 4f escribes the FRO
16970 4d 20 63 6c 61 75 73 65 20 6f 66 20 61 20 53 45 M clause of a SE
16980 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a LECT statement..
16990 2a 2a 20 45 61 63 68 20 74 61 62 6c 65 20 6f 72 ** Each table or
169a0 20 73 75 62 71 75 65 72 79 20 69 6e 20 74 68 65 subquery in the
169b0 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 69 73 20 FROM clause is
169c0 61 20 73 65 70 61 72 61 74 65 20 65 6c 65 6d 65 a separate eleme
169d0 6e 74 20 6f 66 0a 2a 2a 20 74 68 65 20 53 72 63 nt of.** the Src
169e0 4c 69 73 74 2e 61 5b 5d 20 61 72 72 61 79 2e 0a List.a[] array..
169f0 2a 2a 0a 2a 2a 20 57 69 74 68 20 74 68 65 20 61 **.** With the a
16a00 64 64 69 74 69 6f 6e 20 6f 66 20 6d 75 6c 74 69 ddition of multi
16a10 70 6c 65 20 64 61 74 61 62 61 73 65 20 73 75 70 ple database sup
16a20 70 6f 72 74 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 port, the follow
16a30 69 6e 67 20 73 74 72 75 63 74 75 72 65 0a 2a 2a ing structure.**
16a40 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 75 73 65 can also be use
16a50 64 20 74 6f 20 64 65 73 63 72 69 62 65 20 61 20 d to describe a
16a60 70 61 72 74 69 63 75 6c 61 72 20 74 61 62 6c 65 particular table
16a70 20 73 75 63 68 20 61 73 20 74 68 65 20 74 61 62 such as the tab
16a80 6c 65 20 74 68 61 74 0a 2a 2a 20 69 73 20 6d 6f le that.** is mo
16a90 64 69 66 69 65 64 20 62 79 20 61 6e 20 49 4e 53 dified by an INS
16aa0 45 52 54 2c 20 44 45 4c 45 54 45 2c 20 6f 72 20 ERT, DELETE, or
16ab0 55 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e 74 UPDATE statement
16ac0 2e 20 20 49 6e 20 73 74 61 6e 64 61 72 64 20 53 . In standard S
16ad0 51 4c 2c 0a 2a 2a 20 73 75 63 68 20 61 20 74 61 QL,.** such a ta
16ae0 62 6c 65 20 6d 75 73 74 20 62 65 20 61 20 73 69 ble must be a si
16af0 6d 70 6c 65 20 6e 61 6d 65 3a 20 49 44 2e 20 20 mple name: ID.
16b00 42 75 74 20 69 6e 20 53 51 4c 69 74 65 2c 20 74 But in SQLite, t
16b10 68 65 20 74 61 62 6c 65 20 63 61 6e 0a 2a 2a 20 he table can.**
16b20 6e 6f 77 20 62 65 20 69 64 65 6e 74 69 66 69 65 now be identifie
16b30 64 20 62 79 20 61 20 64 61 74 61 62 61 73 65 20 d by a database
16b40 6e 61 6d 65 2c 20 61 20 64 6f 74 2c 20 74 68 65 name, a dot, the
16b50 6e 20 74 68 65 20 74 61 62 6c 65 20 6e 61 6d 65 n the table name
16b60 3a 20 49 44 2e 49 44 2e 0a 2a 2a 0a 2a 2a 20 54 : ID.ID..**.** T
16b70 68 65 20 6a 6f 69 6e 74 79 70 65 20 73 74 61 72 he jointype star
16b80 74 73 20 6f 75 74 20 73 68 6f 77 69 6e 67 20 74 ts out showing t
16b90 68 65 20 6a 6f 69 6e 20 74 79 70 65 20 62 65 74 he join type bet
16ba0 77 65 65 6e 20 74 68 65 20 63 75 72 72 65 6e 74 ween the current
16bb0 20 74 61 62 6c 65 0a 2a 2a 20 61 6e 64 20 74 68 table.** and th
16bc0 65 20 6e 65 78 74 20 74 61 62 6c 65 20 6f 6e 20 e next table on
16bd0 74 68 65 20 6c 69 73 74 2e 20 20 54 68 65 20 70 the list. The p
16be0 61 72 73 65 72 20 62 75 69 6c 64 73 20 74 68 65 arser builds the
16bf0 20 6c 69 73 74 20 74 68 69 73 20 77 61 79 2e 0a list this way..
16c00 2a 2a 20 42 75 74 20 73 71 6c 69 74 65 33 53 72 ** But sqlite3Sr
16c10 63 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 cListShiftJoinTy
16c20 70 65 28 29 20 6c 61 74 65 72 20 73 68 69 66 74 pe() later shift
16c30 73 20 74 68 65 20 6a 6f 69 6e 74 79 70 65 73 20 s the jointypes
16c40 73 6f 20 74 68 61 74 20 65 61 63 68 0a 2a 2a 20 so that each.**
16c50 6a 6f 69 6e 74 79 70 65 20 65 78 70 72 65 73 73 jointype express
16c60 65 73 20 74 68 65 20 6a 6f 69 6e 20 62 65 74 77 es the join betw
16c70 65 65 6e 20 74 68 65 20 74 61 62 6c 65 20 61 6e een the table an
16c80 64 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 74 d the previous t
16c90 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 able..**.** In t
16ca0 68 65 20 63 6f 6c 55 73 65 64 20 66 69 65 6c 64 he colUsed field
16cb0 2c 20 74 68 65 20 68 69 67 68 2d 6f 72 64 65 72 , the high-order
16cc0 20 62 69 74 20 28 62 69 74 20 36 33 29 20 69 73 bit (bit 63) is
16cd0 20 73 65 74 20 69 66 20 74 68 65 20 74 61 62 6c set if the tabl
16ce0 65 0a 2a 2a 20 63 6f 6e 74 61 69 6e 73 20 6d 6f e.** contains mo
16cf0 72 65 20 74 68 61 6e 20 36 33 20 63 6f 6c 75 6d re than 63 colum
16d00 6e 73 20 61 6e 64 20 74 68 65 20 36 34 2d 74 68 ns and the 64-th
16d10 20 6f 72 20 6c 61 74 65 72 20 63 6f 6c 75 6d 6e or later column
16d20 20 69 73 20 75 73 65 64 2e 0a 2a 2f 0a 73 74 72 is used..*/.str
16d30 75 63 74 20 53 72 63 4c 69 73 74 20 7b 0a 20 20 uct SrcList {.
16d40 69 6e 74 20 6e 53 72 63 3b 20 20 20 20 20 20 20 int nSrc;
16d50 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 74 61 /* Number of ta
16d60 62 6c 65 73 20 6f 72 20 73 75 62 71 75 65 72 69 bles or subqueri
16d70 65 73 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 es in the FROM c
16d80 6c 61 75 73 65 20 2a 2f 0a 20 20 75 33 32 20 6e lause */. u32 n
16d90 41 6c 6c 6f 63 3b 20 20 20 20 20 20 2f 2a 20 4e Alloc; /* N
16da0 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 umber of entries
16db0 20 61 6c 6c 6f 63 61 74 65 64 20 69 6e 20 61 5b allocated in a[
16dc0 5d 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 73 74 72 ] below */. str
16dd0 75 63 74 20 53 72 63 4c 69 73 74 5f 69 74 65 6d uct SrcList_item
16de0 20 7b 0a 20 20 20 20 53 63 68 65 6d 61 20 2a 70 {. Schema *p
16df0 53 63 68 65 6d 61 3b 20 20 2f 2a 20 53 63 68 65 Schema; /* Sche
16e00 6d 61 20 74 6f 20 77 68 69 63 68 20 74 68 69 73 ma to which this
16e10 20 69 74 65 6d 20 69 73 20 66 69 78 65 64 20 2a item is fixed *
16e20 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 44 61 74 /. char *zDat
16e30 61 62 61 73 65 3b 20 20 2f 2a 20 4e 61 6d 65 20 abase; /* Name
16e40 6f 66 20 64 61 74 61 62 61 73 65 20 68 6f 6c 64 of database hold
16e50 69 6e 67 20 74 68 69 73 20 74 61 62 6c 65 20 2a ing this table *
16e60 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d /. char *zNam
16e70 65 3b 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 e; /* Name
16e80 6f 66 20 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a of the table */.
16e90 20 20 20 20 63 68 61 72 20 2a 7a 41 6c 69 61 73 char *zAlias
16ea0 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 22 42 22 ; /* The "B"
16eb0 20 70 61 72 74 20 6f 66 20 61 20 22 41 20 41 53 part of a "A AS
16ec0 20 42 22 20 70 68 72 61 73 65 2e 20 20 7a 4e 61 B" phrase. zNa
16ed0 6d 65 20 69 73 20 74 68 65 20 22 41 22 20 2a 2f me is the "A" */
16ee0 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 54 61 62 . Table *pTab
16ef0 3b 20 20 20 20 20 20 2f 2a 20 41 6e 20 53 51 4c ; /* An SQL
16f00 20 74 61 62 6c 65 20 63 6f 72 72 65 73 70 6f 6e table correspon
16f10 64 69 6e 67 20 74 6f 20 7a 4e 61 6d 65 20 2a 2f ding to zName */
16f20 0a 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 65 . Select *pSe
16f30 6c 65 63 74 3b 20 20 2f 2a 20 41 20 53 45 4c 45 lect; /* A SELE
16f40 43 54 20 73 74 61 74 65 6d 65 6e 74 20 75 73 65 CT statement use
16f50 64 20 69 6e 20 70 6c 61 63 65 20 6f 66 20 61 20 d in place of a
16f60 74 61 62 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 table name */.
16f70 20 20 69 6e 74 20 61 64 64 72 46 69 6c 6c 53 75 int addrFillSu
16f80 62 3b 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f b; /* Address o
16f90 66 20 73 75 62 72 6f 75 74 69 6e 65 20 74 6f 20 f subroutine to
16fa0 6d 61 6e 69 66 65 73 74 20 61 20 73 75 62 71 75 manifest a subqu
16fb0 65 72 79 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 ery */. int r
16fc0 65 67 52 65 74 75 72 6e 3b 20 20 20 20 2f 2a 20 egReturn; /*
16fd0 52 65 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 Register holding
16fe0 20 72 65 74 75 72 6e 20 61 64 64 72 65 73 73 20 return address
16ff0 6f 66 20 61 64 64 72 46 69 6c 6c 53 75 62 20 2a of addrFillSub *
17000 2f 0a 20 20 20 20 69 6e 74 20 72 65 67 52 65 73 /. int regRes
17010 75 6c 74 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 ult; /* Regis
17020 74 65 72 73 20 68 6f 6c 64 69 6e 67 20 72 65 73 ters holding res
17030 75 6c 74 73 20 6f 66 20 61 20 63 6f 2d 72 6f 75 ults of a co-rou
17040 74 69 6e 65 20 2a 2f 0a 20 20 20 20 75 38 20 6a tine */. u8 j
17050 6f 69 6e 74 79 70 65 3b 20 20 20 20 20 20 2f 2a ointype; /*
17060 20 54 79 70 65 20 6f 66 20 6a 6f 69 6e 20 62 65 Type of join be
17070 74 77 65 65 6e 20 74 68 69 73 20 61 62 6c 65 20 tween this able
17080 61 6e 64 20 74 68 65 20 70 72 65 76 69 6f 75 73 and the previous
17090 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
170a0 20 6e 6f 74 49 6e 64 65 78 65 64 20 3a 31 3b 20 notIndexed :1;
170b0 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 /* True if th
170c0 65 72 65 20 69 73 20 61 20 4e 4f 54 20 49 4e 44 ere is a NOT IND
170d0 45 58 45 44 20 63 6c 61 75 73 65 20 2a 2f 0a 20 EXED clause */.
170e0 20 20 20 75 6e 73 69 67 6e 65 64 20 69 73 43 6f unsigned isCo
170f0 72 72 65 6c 61 74 65 64 20 3a 31 3b 20 20 2f 2a rrelated :1; /*
17100 20 54 72 75 65 20 69 66 20 73 75 62 2d 71 75 65 True if sub-que
17110 72 79 20 69 73 20 63 6f 72 72 65 6c 61 74 65 64 ry is correlated
17120 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
17130 20 76 69 61 43 6f 72 6f 75 74 69 6e 65 20 3a 31 viaCoroutine :1
17140 3b 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 65 ; /* Implemente
17150 64 20 61 73 20 61 20 63 6f 2d 72 6f 75 74 69 6e d as a co-routin
17160 65 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 e */. unsigne
17170 64 20 69 73 52 65 63 75 72 73 69 76 65 20 3a 31 d isRecursive :1
17180 3b 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 ; /* True for
17190 72 65 63 75 72 73 69 76 65 20 72 65 66 65 72 65 recursive refere
171a0 6e 63 65 20 69 6e 20 57 49 54 48 20 2a 2f 0a 23 nce in WITH */.#
171b0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
171c0 49 54 5f 45 58 50 4c 41 49 4e 0a 20 20 20 20 75 IT_EXPLAIN. u
171d0 38 20 69 53 65 6c 65 63 74 49 64 3b 20 20 20 20 8 iSelectId;
171e0 20 2f 2a 20 49 66 20 70 53 65 6c 65 63 74 21 3d /* If pSelect!=
171f0 30 2c 20 74 68 65 20 69 64 20 6f 66 20 74 68 65 0, the id of the
17200 20 73 75 62 2d 73 65 6c 65 63 74 20 69 6e 20 45 sub-select in E
17210 51 50 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 20 QP */.#endif.
17220 20 69 6e 74 20 69 43 75 72 73 6f 72 3b 20 20 20 int iCursor;
17230 20 20 20 2f 2a 20 54 68 65 20 56 44 42 45 20 63 /* The VDBE c
17240 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 75 73 65 ursor number use
17250 64 20 74 6f 20 61 63 63 65 73 73 20 74 68 69 73 d to access this
17260 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 45 78 table */. Ex
17270 70 72 20 2a 70 4f 6e 3b 20 20 20 20 20 20 20 20 pr *pOn;
17280 2f 2a 20 54 68 65 20 4f 4e 20 63 6c 61 75 73 65 /* The ON clause
17290 20 6f 66 20 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 of a join */.
172a0 20 20 49 64 4c 69 73 74 20 2a 70 55 73 69 6e 67 IdList *pUsing
172b0 3b 20 20 20 2f 2a 20 54 68 65 20 55 53 49 4e 47 ; /* The USING
172c0 20 63 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 clause of a joi
172d0 6e 20 2a 2f 0a 20 20 20 20 42 69 74 6d 61 73 6b n */. Bitmask
172e0 20 63 6f 6c 55 73 65 64 3b 20 20 2f 2a 20 42 69 colUsed; /* Bi
172f0 74 20 4e 20 28 31 3c 3c 4e 29 20 73 65 74 20 69 t N (1<<N) set i
17300 66 20 63 6f 6c 75 6d 6e 20 4e 20 6f 66 20 70 54 f column N of pT
17310 61 62 20 69 73 20 75 73 65 64 20 2a 2f 0a 20 20 ab is used */.
17320 20 20 63 68 61 72 20 2a 7a 49 6e 64 65 78 3b 20 char *zIndex;
17330 20 20 20 20 2f 2a 20 49 64 65 6e 74 69 66 69 65 /* Identifie
17340 72 20 66 72 6f 6d 20 22 49 4e 44 45 58 45 44 20 r from "INDEXED
17350 42 59 20 3c 7a 49 6e 64 65 78 3e 22 20 63 6c 61 BY <zIndex>" cla
17360 75 73 65 20 2a 2f 0a 20 20 20 20 49 6e 64 65 78 use */. Index
17370 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 2f 2a 20 *pIndex; /*
17380 49 6e 64 65 78 20 73 74 72 75 63 74 75 72 65 20 Index structure
17390 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f corresponding to
173a0 20 7a 49 6e 64 65 78 2c 20 69 66 20 61 6e 79 20 zIndex, if any
173b0 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 20 20 20 */. } a[1];
173c0 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 /* One
173d0 65 6e 74 72 79 20 66 6f 72 20 65 61 63 68 20 69 entry for each i
173e0 64 65 6e 74 69 66 69 65 72 20 6f 6e 20 74 68 65 dentifier on the
173f0 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a list */.};../*.
17400 2a 2a 20 50 65 72 6d 69 74 74 65 64 20 76 61 6c ** Permitted val
17410 75 65 73 20 6f 66 20 74 68 65 20 53 72 63 4c 69 ues of the SrcLi
17420 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 20 66 69 st.a.jointype fi
17430 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4a eld.*/.#define J
17440 54 5f 49 4e 4e 45 52 20 20 20 20 20 30 78 30 30 T_INNER 0x00
17450 30 31 20 20 20 20 2f 2a 20 41 6e 79 20 6b 69 6e 01 /* Any kin
17460 64 20 6f 66 20 69 6e 6e 65 72 20 6f 72 20 63 72 d of inner or cr
17470 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 oss join */.#def
17480 69 6e 65 20 4a 54 5f 43 52 4f 53 53 20 20 20 20 ine JT_CROSS
17490 20 30 78 30 30 30 32 20 20 20 20 2f 2a 20 45 78 0x0002 /* Ex
174a0 70 6c 69 63 69 74 20 75 73 65 20 6f 66 20 74 68 plicit use of th
174b0 65 20 43 52 4f 53 53 20 6b 65 79 77 6f 72 64 20 e CROSS keyword
174c0 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4e 41 */.#define JT_NA
174d0 54 55 52 41 4c 20 20 20 30 78 30 30 30 34 20 20 TURAL 0x0004
174e0 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 20 /* True for a
174f0 22 6e 61 74 75 72 61 6c 22 20 6a 6f 69 6e 20 2a "natural" join *
17500 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4c 45 46 /.#define JT_LEF
17510 54 20 20 20 20 20 20 30 78 30 30 30 38 20 20 20 T 0x0008
17520 20 2f 2a 20 4c 65 66 74 20 6f 75 74 65 72 20 6a /* Left outer j
17530 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a oin */.#define J
17540 54 5f 52 49 47 48 54 20 20 20 20 20 30 78 30 30 T_RIGHT 0x00
17550 31 30 20 20 20 20 2f 2a 20 52 69 67 68 74 20 6f 10 /* Right o
17560 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 uter join */.#de
17570 66 69 6e 65 20 4a 54 5f 4f 55 54 45 52 20 20 20 fine JT_OUTER
17580 20 20 30 78 30 30 32 30 20 20 20 20 2f 2a 20 54 0x0020 /* T
17590 68 65 20 22 4f 55 54 45 52 22 20 6b 65 79 77 6f he "OUTER" keywo
175a0 72 64 20 69 73 20 70 72 65 73 65 6e 74 20 2a 2f rd is present */
175b0 0a 23 64 65 66 69 6e 65 20 4a 54 5f 45 52 52 4f .#define JT_ERRO
175c0 52 20 20 20 20 20 30 78 30 30 34 30 20 20 20 20 R 0x0040
175d0 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 20 75 6e /* unknown or un
175e0 73 75 70 70 6f 72 74 65 64 20 6a 6f 69 6e 20 74 supported join t
175f0 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 46 ype */.../*.** F
17600 6c 61 67 73 20 61 70 70 72 6f 70 72 69 61 74 65 lags appropriate
17610 20 66 6f 72 20 74 68 65 20 77 63 74 72 6c 46 6c for the wctrlFl
17620 61 67 73 20 70 61 72 61 6d 65 74 65 72 20 6f 66 ags parameter of
17630 20 73 71 6c 69 74 65 33 57 68 65 72 65 42 65 67 sqlite3WhereBeg
17640 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 68 65 20 in().** and the
17650 57 68 65 72 65 49 6e 66 6f 2e 77 63 74 72 6c 46 WhereInfo.wctrlF
17660 6c 61 67 73 20 6d 65 6d 62 65 72 2e 0a 2a 2f 0a lags member..*/.
17670 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 #define WHERE_OR
17680 44 45 52 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 DERBY_NORMAL 0
17690 78 30 30 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a x0000 /* No-op *
176a0 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
176b0 4f 52 44 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 ORDERBY_MIN
176c0 20 30 78 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 0x0001 /* ORDER
176d0 20 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 BY processing f
176e0 6f 72 20 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f or min() func */
176f0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
17700 52 44 45 52 42 59 5f 4d 41 58 20 20 20 20 20 20 RDERBY_MAX
17710 30 78 30 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 0x0002 /* ORDER
17720 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f BY processing fo
17730 72 20 6d 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a r max() func */.
17740 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e #define WHERE_ON
17750 45 50 41 53 53 5f 44 45 53 49 52 45 44 20 20 30 EPASS_DESIRED 0
17760 78 30 30 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f x0004 /* Want to
17770 20 64 6f 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 do one-pass UPD
17780 41 54 45 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 ATE/DELETE */.#d
17790 65 66 69 6e 65 20 57 48 45 52 45 5f 44 55 50 4c efine WHERE_DUPL
177a0 49 43 41 54 45 53 5f 4f 4b 20 20 20 20 30 78 30 ICATES_OK 0x0
177b0 30 30 38 20 2f 2a 20 4f 6b 20 74 6f 20 72 65 74 008 /* Ok to ret
177c0 75 72 6e 20 61 20 72 6f 77 20 6d 6f 72 65 20 74 urn a row more t
177d0 68 61 6e 20 6f 6e 63 65 20 2a 2f 0a 23 64 65 66 han once */.#def
177e0 69 6e 65 20 57 48 45 52 45 5f 4f 4d 49 54 5f 4f ine WHERE_OMIT_O
177f0 50 45 4e 5f 43 4c 4f 53 45 20 20 30 78 30 30 31 PEN_CLOSE 0x001
17800 30 20 2f 2a 20 54 61 62 6c 65 20 63 75 72 73 6f 0 /* Table curso
17810 72 73 20 61 72 65 20 61 6c 72 65 61 64 79 20 6f rs are already o
17820 70 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 pen */.#define W
17830 48 45 52 45 5f 46 4f 52 43 45 5f 54 41 42 4c 45 HERE_FORCE_TABLE
17840 20 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 0x0020 /*
17850 44 6f 20 6e 6f 74 20 75 73 65 20 61 6e 20 69 6e Do not use an in
17860 64 65 78 2d 6f 6e 6c 79 20 73 65 61 72 63 68 20 dex-only search
17870 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
17880 5f 4f 4e 45 54 41 42 4c 45 5f 4f 4e 4c 59 20 20 _ONETABLE_ONLY
17890 20 20 30 78 30 30 34 30 20 2f 2a 20 4f 6e 6c 79 0x0040 /* Only
178a0 20 63 6f 64 65 20 74 68 65 20 31 73 74 20 74 61 code the 1st ta
178b0 62 6c 65 20 69 6e 20 70 54 61 62 4c 69 73 74 20 ble in pTabList
178c0 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
178d0 5f 4e 4f 5f 41 55 54 4f 49 4e 44 45 58 20 20 20 _NO_AUTOINDEX
178e0 20 20 30 78 30 30 38 30 20 2f 2a 20 44 69 73 61 0x0080 /* Disa
178f0 6c 6c 6f 77 20 61 75 74 6f 6d 61 74 69 63 20 69 llow automatic i
17900 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e ndexes */.#defin
17910 65 20 57 48 45 52 45 5f 47 52 4f 55 50 42 59 20 e WHERE_GROUPBY
17920 20 20 20 20 20 20 20 20 20 30 78 30 31 30 30 20 0x0100
17930 2f 2a 20 70 4f 72 64 65 72 42 79 20 69 73 20 72 /* pOrderBy is r
17940 65 61 6c 6c 79 20 61 20 47 52 4f 55 50 20 42 59 eally a GROUP BY
17950 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
17960 45 5f 44 49 53 54 49 4e 43 54 42 59 20 20 20 20 E_DISTINCTBY
17970 20 20 20 30 78 30 32 30 30 20 2f 2a 20 70 4f 72 0x0200 /* pOr
17980 64 65 72 62 79 20 69 73 20 72 65 61 6c 6c 79 20 derby is really
17990 61 20 44 49 53 54 49 4e 43 54 20 63 6c 61 75 73 a DISTINCT claus
179a0 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 e */.#define WHE
179b0 52 45 5f 57 41 4e 54 5f 44 49 53 54 49 4e 43 54 RE_WANT_DISTINCT
179c0 20 20 20 20 30 78 30 34 30 30 20 2f 2a 20 41 6c 0x0400 /* Al
179d0 6c 20 6f 75 74 70 75 74 20 6e 65 65 64 73 20 74 l output needs t
179e0 6f 20 62 65 20 64 69 73 74 69 6e 63 74 20 2a 2f o be distinct */
179f0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 53 .#define WHERE_S
17a00 4f 52 54 42 59 47 52 4f 55 50 20 20 20 20 20 20 ORTBYGROUP
17a10 30 78 30 38 30 30 20 2f 2a 20 53 75 70 70 6f 72 0x0800 /* Suppor
17a20 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 t sqlite3WhereIs
17a30 53 6f 72 74 65 64 28 29 20 2a 2f 0a 23 64 65 66 Sorted() */.#def
17a40 69 6e 65 20 57 48 45 52 45 5f 52 45 4f 50 45 4e ine WHERE_REOPEN
17a50 5f 49 44 58 20 20 20 20 20 20 20 30 78 31 30 30 _IDX 0x100
17a60 30 20 2f 2a 20 54 72 79 20 74 6f 20 75 73 65 20 0 /* Try to use
17a70 4f 50 5f 52 65 6f 70 65 6e 49 64 78 20 2a 2f 0a OP_ReopenIdx */.
17a80 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 ./* Allowed retu
17a90 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 rn values from s
17aa0 71 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 qlite3WhereIsDis
17ab0 74 69 6e 63 74 28 29 0a 2a 2f 0a 23 64 65 66 69 tinct().*/.#defi
17ac0 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 ne WHERE_DISTINC
17ad0 54 5f 4e 4f 4f 50 20 20 20 20 20 20 30 20 20 2f T_NOOP 0 /
17ae0 2a 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f * DISTINCT keywo
17af0 72 64 20 6e 6f 74 20 75 73 65 64 20 2a 2f 0a 23 rd not used */.#
17b00 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 define WHERE_DIS
17b10 54 49 4e 43 54 5f 55 4e 49 51 55 45 20 20 20 20 TINCT_UNIQUE
17b20 31 20 20 2f 2a 20 4e 6f 20 64 75 70 6c 69 63 61 1 /* No duplica
17b30 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 tes */.#define W
17b40 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 4f 52 HERE_DISTINCT_OR
17b50 44 45 52 45 44 20 20 20 32 20 20 2f 2a 20 41 6c DERED 2 /* Al
17b60 6c 20 64 75 70 6c 69 63 61 74 65 73 20 61 72 65 l duplicates are
17b70 20 61 64 6a 61 63 65 6e 74 20 2a 2f 0a 23 64 65 adjacent */.#de
17b80 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 fine WHERE_DISTI
17b90 4e 43 54 5f 55 4e 4f 52 44 45 52 45 44 20 33 20 NCT_UNORDERED 3
17ba0 20 2f 2a 20 44 75 70 6c 69 63 61 74 65 73 20 61 /* Duplicates a
17bb0 72 65 20 73 63 61 74 74 65 72 65 64 20 2a 2f 0a re scattered */.
17bc0 0a 2f 2a 0a 2a 2a 20 41 20 4e 61 6d 65 43 6f 6e ./*.** A NameCon
17bd0 74 65 78 74 20 64 65 66 69 6e 65 73 20 61 20 63 text defines a c
17be0 6f 6e 74 65 78 74 20 69 6e 20 77 68 69 63 68 20 ontext in which
17bf0 74 6f 20 72 65 73 6f 6c 76 65 20 74 61 62 6c 65 to resolve table
17c00 20 61 6e 64 20 63 6f 6c 75 6d 6e 0a 2a 2a 20 6e and column.** n
17c10 61 6d 65 73 2e 20 20 54 68 65 20 63 6f 6e 74 65 ames. The conte
17c20 78 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 xt consists of a
17c30 20 6c 69 73 74 20 6f 66 20 74 61 62 6c 65 73 20 list of tables
17c40 28 74 68 65 20 70 53 72 63 4c 69 73 74 29 20 66 (the pSrcList) f
17c50 69 65 6c 64 20 61 6e 64 0a 2a 2a 20 61 20 6c 69 ield and.** a li
17c60 73 74 20 6f 66 20 6e 61 6d 65 64 20 65 78 70 72 st of named expr
17c70 65 73 73 69 6f 6e 20 28 70 45 4c 69 73 74 29 2e ession (pEList).
17c80 20 20 54 68 65 20 6e 61 6d 65 64 20 65 78 70 72 The named expr
17c90 65 73 73 69 6f 6e 20 6c 69 73 74 20 6d 61 79 0a ession list may.
17ca0 2a 2a 20 62 65 20 4e 55 4c 4c 2e 20 20 54 68 65 ** be NULL. The
17cb0 20 70 53 72 63 20 63 6f 72 72 65 73 70 6f 6e 64 pSrc correspond
17cc0 73 20 74 6f 20 74 68 65 20 46 52 4f 4d 20 63 6c s to the FROM cl
17cd0 61 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 54 ause of a SELECT
17ce0 20 6f 72 0a 2a 2a 20 74 6f 20 74 68 65 20 74 61 or.** to the ta
17cf0 62 6c 65 20 62 65 69 6e 67 20 6f 70 65 72 61 74 ble being operat
17d00 65 64 20 6f 6e 20 62 79 20 49 4e 53 45 52 54 2c ed on by INSERT,
17d10 20 55 50 44 41 54 45 2c 20 6f 72 20 44 45 4c 45 UPDATE, or DELE
17d20 54 45 2e 20 20 54 68 65 0a 2a 2a 20 70 45 4c 69 TE. The.** pELi
17d30 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 st corresponds t
17d40 6f 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 o the result set
17d50 20 6f 66 20 61 20 53 45 4c 45 43 54 20 61 6e 64 of a SELECT and
17d60 20 69 73 20 4e 55 4c 4c 20 66 6f 72 0a 2a 2a 20 is NULL for.**
17d70 6f 74 68 65 72 20 73 74 61 74 65 6d 65 6e 74 73 other statements
17d80 2e 0a 2a 2a 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 ..**.** NameCont
17d90 65 78 74 73 20 63 61 6e 20 62 65 20 6e 65 73 74 exts can be nest
17da0 65 64 2e 20 20 57 68 65 6e 20 72 65 73 6f 6c 76 ed. When resolv
17db0 69 6e 67 20 6e 61 6d 65 73 2c 20 74 68 65 20 69 ing names, the i
17dc0 6e 6e 65 72 2d 6d 6f 73 74 20 0a 2a 2a 20 63 6f nner-most .** co
17dd0 6e 74 65 78 74 20 69 73 20 73 65 61 72 63 68 65 ntext is searche
17de0 64 20 66 69 72 73 74 2e 20 20 49 66 20 6e 6f 20 d first. If no
17df0 6d 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 match is found,
17e00 74 68 65 20 6e 65 78 74 20 6f 75 74 65 72 0a 2a the next outer.*
17e10 2a 20 63 6f 6e 74 65 78 74 20 69 73 20 63 68 65 * context is che
17e20 63 6b 65 64 2e 20 20 49 66 20 74 68 65 72 65 20 cked. If there
17e30 69 73 20 73 74 69 6c 6c 20 6e 6f 20 6d 61 74 63 is still no matc
17e40 68 2c 20 74 68 65 20 6e 65 78 74 20 63 6f 6e 74 h, the next cont
17e50 65 78 74 0a 2a 2a 20 69 73 20 63 68 65 63 6b 65 ext.** is checke
17e60 64 2e 20 20 54 68 69 73 20 70 72 6f 63 65 73 73 d. This process
17e70 20 63 6f 6e 74 69 6e 75 65 73 20 75 6e 74 69 6c continues until
17e80 20 65 69 74 68 65 72 20 61 20 6d 61 74 63 68 20 either a match
17e90 69 73 20 66 6f 75 6e 64 0a 2a 2a 20 6f 72 20 61 is found.** or a
17ea0 6c 6c 20 63 6f 6e 74 65 78 74 73 20 61 72 65 20 ll contexts are
17eb0 63 68 65 63 6b 2e 20 20 57 68 65 6e 20 61 20 6d check. When a m
17ec0 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 atch is found, t
17ed0 68 65 20 6e 52 65 66 20 6d 65 6d 62 65 72 20 6f he nRef member o
17ee0 66 0a 2a 2a 20 74 68 65 20 63 6f 6e 74 65 78 74 f.** the context
17ef0 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 containing the
17f00 6d 61 74 63 68 20 69 73 20 69 6e 63 72 65 6d 65 match is increme
17f10 6e 74 65 64 2e 20 0a 2a 2a 0a 2a 2a 20 45 61 63 nted. .**.** Eac
17f20 68 20 73 75 62 71 75 65 72 79 20 67 65 74 73 20 h subquery gets
17f30 61 20 6e 65 77 20 4e 61 6d 65 43 6f 6e 74 65 78 a new NameContex
17f40 74 2e 20 20 54 68 65 20 70 4e 65 78 74 20 66 69 t. The pNext fi
17f50 65 6c 64 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 eld points to th
17f60 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 e.** NameContext
17f70 20 69 6e 20 74 68 65 20 70 61 72 65 6e 74 20 71 in the parent q
17f80 75 65 72 79 2e 20 20 54 68 75 73 20 74 68 65 20 uery. Thus the
17f90 70 72 6f 63 65 73 73 20 6f 66 20 73 63 61 6e 6e process of scann
17fa0 69 6e 67 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 ing the.** NameC
17fb0 6f 6e 74 65 78 74 20 6c 69 73 74 20 63 6f 72 72 ontext list corr
17fc0 65 73 70 6f 6e 64 73 20 74 6f 20 73 65 61 72 63 esponds to searc
17fd0 68 69 6e 67 20 74 68 72 6f 75 67 68 20 73 75 63 hing through suc
17fe0 63 65 73 73 69 76 65 6c 79 20 6f 75 74 65 72 0a cessively outer.
17ff0 2a 2a 20 73 75 62 71 75 65 72 69 65 73 20 6c 6f ** subqueries lo
18000 6f 6b 69 6e 67 20 66 6f 72 20 61 20 6d 61 74 63 oking for a matc
18010 68 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4e 61 6d h..*/.struct Nam
18020 65 43 6f 6e 74 65 78 74 20 7b 0a 20 20 50 61 72 eContext {. Par
18030 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 se *pParse;
18040 20 20 2f 2a 20 54 68 65 20 70 61 72 73 65 72 20 /* The parser
18050 2a 2f 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 */. SrcList *pS
18060 72 63 4c 69 73 74 3b 20 20 20 2f 2a 20 4f 6e 65 rcList; /* One
18070 20 6f 72 20 6d 6f 72 65 20 74 61 62 6c 65 73 20 or more tables
18080 75 73 65 64 20 74 6f 20 72 65 73 6f 6c 76 65 20 used to resolve
18090 6e 61 6d 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c names */. ExprL
180a0 69 73 74 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 ist *pEList;
180b0 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 6c 69 73 74 /* Optional list
180c0 20 6f 66 20 72 65 73 75 6c 74 2d 73 65 74 20 63 of result-set c
180d0 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 41 67 67 49 olumns */. AggI
180e0 6e 66 6f 20 2a 70 41 67 67 49 6e 66 6f 3b 20 20 nfo *pAggInfo;
180f0 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 /* Information
18100 61 62 6f 75 74 20 61 67 67 72 65 67 61 74 65 73 about aggregates
18110 20 61 74 20 74 68 69 73 20 6c 65 76 65 6c 20 2a at this level *
18120 2f 0a 20 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 /. NameContext
18130 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 78 74 *pNext; /* Next
18140 20 6f 75 74 65 72 20 6e 61 6d 65 20 63 6f 6e 74 outer name cont
18150 65 78 74 2e 20 20 4e 55 4c 4c 20 66 6f 72 20 6f ext. NULL for o
18160 75 74 65 72 6d 6f 73 74 20 2a 2f 0a 20 20 69 6e utermost */. in
18170 74 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 t nRef;
18180 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
18190 6e 61 6d 65 73 20 72 65 73 6f 6c 76 65 64 20 62 names resolved b
181a0 79 20 74 68 69 73 20 63 6f 6e 74 65 78 74 20 2a y this context *
181b0 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 /. int nErr;
181c0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
181d0 65 72 20 6f 66 20 65 72 72 6f 72 73 20 65 6e 63 er of errors enc
181e0 6f 75 6e 74 65 72 65 64 20 77 68 69 6c 65 20 72 ountered while r
181f0 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 2a esolving names *
18200 2f 0a 20 20 75 31 36 20 6e 63 46 6c 61 67 73 3b /. u16 ncFlags;
18210 20 20 20 20 20 20 20 20 20 2f 2a 20 5a 65 72 6f /* Zero
18220 20 6f 72 20 6d 6f 72 65 20 4e 43 5f 2a 20 66 6c or more NC_* fl
18230 61 67 73 20 64 65 66 69 6e 65 64 20 62 65 6c 6f ags defined belo
18240 77 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 w */.};../*.** A
18250 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f llowed values fo
18260 72 20 74 68 65 20 4e 61 6d 65 43 6f 6e 74 65 78 r the NameContex
18270 74 2c 20 6e 63 46 6c 61 67 73 20 66 69 65 6c 64 t, ncFlags field
18280 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 3a 20 20 4e ..**.** Note: N
18290 43 5f 4d 69 6e 4d 61 78 41 67 67 20 6d 75 73 74 C_MinMaxAgg must
182a0 20 68 61 76 65 20 74 68 65 20 73 61 6d 65 20 76 have the same v
182b0 61 6c 75 65 20 61 73 20 53 46 5f 4d 69 6e 4d 61 alue as SF_MinMa
182c0 78 41 67 67 20 61 6e 64 0a 2a 2a 20 53 51 4c 49 xAgg and.** SQLI
182d0 54 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 2e 0a TE_FUNC_MINMAX..
182e0 2a 2a 20 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4e ** .*/.#define N
182f0 43 5f 41 6c 6c 6f 77 41 67 67 20 20 30 78 30 30 C_AllowAgg 0x00
18300 30 31 20 20 2f 2a 20 41 67 67 72 65 67 61 74 65 01 /* Aggregate
18310 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 functions are a
18320 6c 6c 6f 77 65 64 20 68 65 72 65 20 2a 2f 0a 23 llowed here */.#
18330 64 65 66 69 6e 65 20 4e 43 5f 48 61 73 41 67 67 define NC_HasAgg
18340 20 20 20 20 30 78 30 30 30 32 20 20 2f 2a 20 4f 0x0002 /* O
18350 6e 65 20 6f 72 20 6d 6f 72 65 20 61 67 67 72 65 ne or more aggre
18360 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 73 gate functions s
18370 65 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e een */.#define N
18380 43 5f 49 73 43 68 65 63 6b 20 20 20 30 78 30 30 C_IsCheck 0x00
18390 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 04 /* True if r
183a0 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 69 esolving names i
183b0 6e 20 61 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 n a CHECK constr
183c0 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aint */.#define
183d0 4e 43 5f 49 6e 41 67 67 46 75 6e 63 20 30 78 30 NC_InAggFunc 0x0
183e0 30 30 38 20 20 2f 2a 20 54 72 75 65 20 69 66 20 008 /* True if
183f0 61 6e 61 6c 79 7a 69 6e 67 20 61 72 67 75 6d 65 analyzing argume
18400 6e 74 73 20 74 6f 20 61 6e 20 61 67 67 20 66 75 nts to an agg fu
18410 6e 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 nc */.#define NC
18420 5f 50 61 72 74 49 64 78 20 20 20 30 78 30 30 31 _PartIdx 0x001
18430 30 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 0 /* True if re
18440 73 6f 6c 76 69 6e 67 20 61 20 70 61 72 74 69 61 solving a partia
18450 6c 20 69 6e 64 65 78 20 57 48 45 52 45 20 2a 2f l index WHERE */
18460 0a 23 64 65 66 69 6e 65 20 4e 43 5f 4d 69 6e 4d .#define NC_MinM
18470 61 78 41 67 67 20 30 78 31 30 30 30 20 20 2f 2a axAgg 0x1000 /*
18480 20 6d 69 6e 2f 6d 61 78 20 61 67 67 72 65 67 61 min/max aggrega
18490 74 65 73 20 73 65 65 6e 2e 20 20 53 65 65 20 6e tes seen. See n
184a0 6f 74 65 20 61 62 6f 76 65 20 2a 2f 0a 0a 2f 2a ote above */../*
184b0 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
184c0 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
184d0 20 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 structure conta
184e0 69 6e 73 20 61 6c 6c 20 69 6e 66 6f 72 6d 61 74 ins all informat
184f0 69 6f 6e 0a 2a 2a 20 6e 65 65 64 65 64 20 74 6f ion.** needed to
18500 20 67 65 6e 65 72 61 74 65 20 63 6f 64 65 20 66 generate code f
18510 6f 72 20 61 20 73 69 6e 67 6c 65 20 53 45 4c 45 or a single SELE
18520 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a CT statement..**
18530 0a 2a 2a 20 6e 4c 69 6d 69 74 20 69 73 20 73 65 .** nLimit is se
18540 74 20 74 6f 20 2d 31 20 69 66 20 74 68 65 72 65 t to -1 if there
18550 20 69 73 20 6e 6f 20 4c 49 4d 49 54 20 63 6c 61 is no LIMIT cla
18560 75 73 65 2e 20 20 6e 4f 66 66 73 65 74 20 69 73 use. nOffset is
18570 20 73 65 74 20 74 6f 20 30 2e 0a 2a 2a 20 49 66 set to 0..** If
18580 20 74 68 65 72 65 20 69 73 20 61 20 4c 49 4d 49 there is a LIMI
18590 54 20 63 6c 61 75 73 65 2c 20 74 68 65 20 70 61 T clause, the pa
185a0 72 73 65 72 20 73 65 74 73 20 6e 4c 69 6d 69 74 rser sets nLimit
185b0 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 6f 66 to the value of
185c0 20 74 68 65 0a 2a 2a 20 6c 69 6d 69 74 20 61 6e the.** limit an
185d0 64 20 6e 4f 66 66 73 65 74 20 74 6f 20 74 68 65 d nOffset to the
185e0 20 76 61 6c 75 65 20 6f 66 20 74 68 65 20 6f 66 value of the of
185f0 66 73 65 74 20 28 6f 72 20 30 20 69 66 20 74 68 fset (or 0 if th
18600 65 72 65 20 69 73 20 6e 6f 74 0a 2a 2a 20 6f 66 ere is not.** of
18610 66 73 65 74 29 2e 20 20 42 75 74 20 6c 61 74 65 fset). But late
18620 72 20 6f 6e 2c 20 6e 4c 69 6d 69 74 20 61 6e 64 r on, nLimit and
18630 20 6e 4f 66 66 73 65 74 20 62 65 63 6f 6d 65 20 nOffset become
18640 74 68 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 the memory locat
18650 69 6f 6e 73 0a 2a 2a 20 69 6e 20 74 68 65 20 56 ions.** in the V
18660 44 42 45 20 74 68 61 74 20 72 65 63 6f 72 64 20 DBE that record
18670 74 68 65 20 6c 69 6d 69 74 20 61 6e 64 20 6f 66 the limit and of
18680 66 73 65 74 20 63 6f 75 6e 74 65 72 73 2e 0a 2a fset counters..*
18690 2a 0a 2a 2a 20 61 64 64 72 4f 70 65 6e 45 70 68 *.** addrOpenEph
186a0 6d 5b 5d 20 65 6e 74 72 69 65 73 20 63 6f 6e 74 m[] entries cont
186b0 61 69 6e 20 74 68 65 20 61 64 64 72 65 73 73 20 ain the address
186c0 6f 66 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 of OP_OpenEpheme
186d0 72 61 6c 20 6f 70 63 6f 64 65 73 2e 0a 2a 2a 20 ral opcodes..**
186e0 54 68 65 73 65 20 61 64 64 72 65 73 73 65 73 20 These addresses
186f0 6d 75 73 74 20 62 65 20 73 74 6f 72 65 64 20 73 must be stored s
18700 6f 20 74 68 61 74 20 77 65 20 63 61 6e 20 67 6f o that we can go
18710 20 62 61 63 6b 20 61 6e 64 20 66 69 6c 6c 20 69 back and fill i
18720 6e 0a 2a 2a 20 74 68 65 20 50 34 5f 4b 45 59 49 n.** the P4_KEYI
18730 4e 46 4f 20 61 6e 64 20 50 32 20 70 61 72 61 6d NFO and P2 param
18740 65 74 65 72 73 20 6c 61 74 65 72 2e 20 20 4e 65 eters later. Ne
18750 69 74 68 65 72 20 74 68 65 20 4b 65 79 49 6e 66 ither the KeyInf
18760 6f 20 6e 6f 72 0a 2a 2a 20 74 68 65 20 6e 75 6d o nor.** the num
18770 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 ber of columns i
18780 6e 20 50 32 20 63 61 6e 20 62 65 20 63 6f 6d 70 n P2 can be comp
18790 75 74 65 64 20 61 74 20 74 68 65 20 73 61 6d 65 uted at the same
187a0 20 74 69 6d 65 0a 2a 2a 20 61 73 20 74 68 65 20 time.** as the
187b0 4f 50 5f 4f 70 65 6e 45 70 68 6d 20 69 6e 73 74 OP_OpenEphm inst
187c0 72 75 63 74 69 6f 6e 20 69 73 20 63 6f 64 65 64 ruction is coded
187d0 20 62 65 63 61 75 73 65 20 6e 6f 74 0a 2a 2a 20 because not.**
187e0 65 6e 6f 75 67 68 20 69 6e 66 6f 72 6d 61 74 69 enough informati
187f0 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 63 6f 6d on about the com
18800 70 6f 75 6e 64 20 71 75 65 72 79 20 69 73 20 6b pound query is k
18810 6e 6f 77 6e 20 61 74 20 74 68 61 74 20 70 6f 69 nown at that poi
18820 6e 74 2e 0a 2a 2a 20 54 68 65 20 4b 65 79 49 6e nt..** The KeyIn
18830 66 6f 20 66 6f 72 20 61 64 64 72 4f 70 65 6e 54 fo for addrOpenT
18840 72 61 6e 5b 30 5d 20 61 6e 64 20 5b 31 5d 20 63 ran[0] and [1] c
18850 6f 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 74 69 6e ontains collatin
18860 67 20 73 65 71 75 65 6e 63 65 73 0a 2a 2a 20 66 g sequences.** f
18870 6f 72 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 or the result se
18880 74 2e 20 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 t. The KeyInfo
18890 66 6f 72 20 61 64 64 72 4f 70 65 6e 45 70 68 6d for addrOpenEphm
188a0 5b 32 5d 20 63 6f 6e 74 61 69 6e 73 20 63 6f 6c [2] contains col
188b0 6c 61 74 69 6e 67 0a 2a 2a 20 73 65 71 75 65 6e lating.** sequen
188c0 63 65 73 20 66 6f 72 20 74 68 65 20 4f 52 44 45 ces for the ORDE
188d0 52 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a R BY clause..*/.
188e0 73 74 72 75 63 74 20 53 65 6c 65 63 74 20 7b 0a struct Select {.
188f0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 45 4c 69 ExprList *pELi
18900 73 74 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 st; /* The
18910 66 69 65 6c 64 73 20 6f 66 20 74 68 65 20 72 65 fields of the re
18920 73 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6f 70 3b sult */. u8 op;
18930 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18940 20 2f 2a 20 4f 6e 65 20 6f 66 3a 20 54 4b 5f 55 /* One of: TK_U
18950 4e 49 4f 4e 20 54 4b 5f 41 4c 4c 20 54 4b 5f 49 NION TK_ALL TK_I
18960 4e 54 45 52 53 45 43 54 20 54 4b 5f 45 58 43 45 NTERSECT TK_EXCE
18970 50 54 20 2a 2f 0a 20 20 75 31 36 20 73 65 6c 46 PT */. u16 selF
18980 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 2f lags; /
18990 2a 20 56 61 72 69 6f 75 73 20 53 46 5f 2a 20 76 * Various SF_* v
189a0 61 6c 75 65 73 20 2a 2f 0a 20 20 69 6e 74 20 69 alues */. int i
189b0 4c 69 6d 69 74 2c 20 69 4f 66 66 73 65 74 3b 20 Limit, iOffset;
189c0 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 72 65 67 69 /* Memory regi
189d0 73 74 65 72 73 20 68 6f 6c 64 69 6e 67 20 4c 49 sters holding LI
189e0 4d 49 54 20 26 20 4f 46 46 53 45 54 20 63 6f 75 MIT & OFFSET cou
189f0 6e 74 65 72 73 20 2a 2f 0a 23 69 66 20 53 45 4c nters */.#if SEL
18a00 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 ECTTRACE_ENABLED
18a10 0a 20 20 63 68 61 72 20 7a 53 65 6c 4e 61 6d 65 . char zSelName
18a20 5b 31 32 5d 3b 20 20 20 20 20 2f 2a 20 53 79 6d [12]; /* Sym
18a30 62 6f 6c 69 63 20 6e 61 6d 65 20 6f 66 20 74 68 bolic name of th
18a40 69 73 20 53 45 4c 45 43 54 20 75 73 65 20 66 6f is SELECT use fo
18a50 72 20 64 65 62 75 67 67 69 6e 67 20 2a 2f 0a 23 r debugging */.#
18a60 65 6e 64 69 66 0a 20 20 69 6e 74 20 61 64 64 72 endif. int addr
18a70 4f 70 65 6e 45 70 68 6d 5b 32 5d 3b 20 20 20 2f OpenEphm[2]; /
18a80 2a 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 20 6f * OP_OpenEphem o
18a90 70 63 6f 64 65 73 20 72 65 6c 61 74 65 64 20 74 pcodes related t
18aa0 6f 20 74 68 69 73 20 73 65 6c 65 63 74 20 2a 2f o this select */
18ab0 0a 20 20 75 36 34 20 6e 53 65 6c 65 63 74 52 6f . u64 nSelectRo
18ac0 77 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 w; /* Est
18ad0 69 6d 61 74 65 64 20 6e 75 6d 62 65 72 20 6f 66 imated number of
18ae0 20 72 65 73 75 6c 74 20 72 6f 77 73 20 2a 2f 0a result rows */.
18af0 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 3b SrcList *pSrc;
18b00 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
18b10 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 FROM clause */.
18b20 20 45 78 70 72 20 2a 70 57 68 65 72 65 3b 20 20 Expr *pWhere;
18b30 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 /* The W
18b40 48 45 52 45 20 63 6c 61 75 73 65 20 2a 2f 0a 20 HERE clause */.
18b50 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 ExprList *pGrou
18b60 70 42 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 47 pBy; /* The G
18b70 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 2a ROUP BY clause *
18b80 2f 0a 20 20 45 78 70 72 20 2a 70 48 61 76 69 6e /. Expr *pHavin
18b90 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 g; /* Th
18ba0 65 20 48 41 56 49 4e 47 20 63 6c 61 75 73 65 20 e HAVING clause
18bb0 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
18bc0 4f 72 64 65 72 42 79 3b 20 20 20 20 2f 2a 20 54 OrderBy; /* T
18bd0 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 he ORDER BY clau
18be0 73 65 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a se */. Select *
18bf0 70 50 72 69 6f 72 3b 20 20 20 20 20 20 20 20 2f pPrior; /
18c00 2a 20 50 72 69 6f 72 20 73 65 6c 65 63 74 20 69 * Prior select i
18c10 6e 20 61 20 63 6f 6d 70 6f 75 6e 64 20 73 65 6c n a compound sel
18c20 65 63 74 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f ect statement */
18c30 0a 20 20 53 65 6c 65 63 74 20 2a 70 4e 65 78 74 . Select *pNext
18c40 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 ; /* Nex
18c50 74 20 73 65 6c 65 63 74 20 74 6f 20 74 68 65 20 t select to the
18c60 6c 65 66 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 left in a compou
18c70 6e 64 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4c nd */. Expr *pL
18c80 69 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 2f imit; /
18c90 2a 20 4c 49 4d 49 54 20 65 78 70 72 65 73 73 69 * LIMIT expressi
18ca0 6f 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e on. NULL means n
18cb0 6f 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 45 78 ot used. */. Ex
18cc0 70 72 20 2a 70 4f 66 66 73 65 74 3b 20 20 20 20 pr *pOffset;
18cd0 20 20 20 20 20 2f 2a 20 4f 46 46 53 45 54 20 65 /* OFFSET e
18ce0 78 70 72 65 73 73 69 6f 6e 2e 20 4e 55 4c 4c 20 xpression. NULL
18cf0 6d 65 61 6e 73 20 6e 6f 74 20 75 73 65 64 2e 20 means not used.
18d00 2a 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 74 68 */. With *pWith
18d10 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 ; /* W
18d20 49 54 48 20 63 6c 61 75 73 65 20 61 74 74 61 63 ITH clause attac
18d30 68 65 64 20 74 6f 20 74 68 69 73 20 73 65 6c 65 hed to this sele
18d40 63 74 2e 20 4f 72 20 4e 55 4c 4c 2e 20 2a 2f 0a ct. Or NULL. */.
18d50 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 };../*.** Allowe
18d60 64 20 76 61 6c 75 65 73 20 66 6f 72 20 53 65 6c d values for Sel
18d70 65 63 74 2e 73 65 6c 46 6c 61 67 73 2e 20 20 54 ect.selFlags. T
18d80 68 65 20 22 53 46 22 20 70 72 65 66 69 78 20 73 he "SF" prefix s
18d90 74 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 53 65 tands for.** "Se
18da0 6c 65 63 74 20 46 6c 61 67 22 2e 0a 2a 2f 0a 23 lect Flag"..*/.#
18db0 64 65 66 69 6e 65 20 53 46 5f 44 69 73 74 69 6e define SF_Distin
18dc0 63 74 20 20 20 20 20 20 20 20 30 78 30 30 30 31 ct 0x0001
18dd0 20 20 2f 2a 20 4f 75 74 70 75 74 20 73 68 6f 75 /* Output shou
18de0 6c 64 20 62 65 20 44 49 53 54 49 4e 43 54 20 2a ld be DISTINCT *
18df0 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 65 73 /.#define SF_Res
18e00 6f 6c 76 65 64 20 20 20 20 20 20 20 20 30 78 30 olved 0x0
18e10 30 30 32 20 20 2f 2a 20 49 64 65 6e 74 69 66 69 002 /* Identifi
18e20 65 72 73 20 68 61 76 65 20 62 65 65 6e 20 72 65 ers have been re
18e30 73 6f 6c 76 65 64 20 2a 2f 0a 23 64 65 66 69 6e solved */.#defin
18e40 65 20 53 46 5f 41 67 67 72 65 67 61 74 65 20 20 e SF_Aggregate
18e50 20 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 0x0004 /*
18e60 43 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 61 Contains aggrega
18e70 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a te functions */.
18e80 23 64 65 66 69 6e 65 20 53 46 5f 55 73 65 73 45 #define SF_UsesE
18e90 70 68 65 6d 65 72 61 6c 20 20 20 30 78 30 30 30 phemeral 0x000
18ea0 38 20 20 2f 2a 20 55 73 65 73 20 74 68 65 20 4f 8 /* Uses the O
18eb0 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f 70 63 penEphemeral opc
18ec0 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ode */.#define S
18ed0 46 5f 45 78 70 61 6e 64 65 64 20 20 20 20 20 20 F_Expanded
18ee0 20 20 30 78 30 30 31 30 20 20 2f 2a 20 73 71 6c 0x0010 /* sql
18ef0 69 74 65 33 53 65 6c 65 63 74 45 78 70 61 6e 64 ite3SelectExpand
18f00 28 29 20 63 61 6c 6c 65 64 20 6f 6e 20 74 68 69 () called on thi
18f10 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f s */.#define SF_
18f20 48 61 73 54 79 70 65 49 6e 66 6f 20 20 20 20 20 HasTypeInfo
18f30 30 78 30 30 32 30 20 20 2f 2a 20 46 52 4f 4d 20 0x0020 /* FROM
18f40 73 75 62 71 75 65 72 69 65 73 20 68 61 76 65 20 subqueries have
18f50 54 61 62 6c 65 20 6d 65 74 61 64 61 74 61 20 2a Table metadata *
18f60 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 6f 6d /.#define SF_Com
18f70 70 6f 75 6e 64 20 20 20 20 20 20 20 20 30 78 30 pound 0x0
18f80 30 34 30 20 20 2f 2a 20 50 61 72 74 20 6f 66 20 040 /* Part of
18f90 61 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 79 a compound query
18fa0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 56 */.#define SF_V
18fb0 61 6c 75 65 73 20 20 20 20 20 20 20 20 20 20 30 alues 0
18fc0 78 30 30 38 30 20 20 2f 2a 20 53 79 6e 74 68 65 x0080 /* Synthe
18fd0 73 69 7a 65 64 20 66 72 6f 6d 20 56 41 4c 55 45 sized from VALUE
18fe0 53 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 66 S clause */.#def
18ff0 69 6e 65 20 53 46 5f 41 6c 6c 56 61 6c 75 65 73 ine SF_AllValues
19000 20 20 20 20 20 20 20 30 78 30 31 30 30 20 20 2f 0x0100 /
19010 2a 20 41 6c 6c 20 74 65 72 6d 73 20 6f 66 20 63 * All terms of c
19020 6f 6d 70 6f 75 6e 64 20 61 72 65 20 56 41 4c 55 ompound are VALU
19030 45 53 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 ES */.#define SF
19040 5f 4e 65 73 74 65 64 46 72 6f 6d 20 20 20 20 20 _NestedFrom
19050 20 30 78 30 32 30 30 20 20 2f 2a 20 50 61 72 74 0x0200 /* Part
19060 20 6f 66 20 61 20 70 61 72 65 6e 74 68 65 73 69 of a parenthesi
19070 7a 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 zed FROM clause
19080 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 61 */.#define SF_Ma
19090 79 62 65 43 6f 6e 76 65 72 74 20 20 20 20 30 78 ybeConvert 0x
190a0 30 34 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 6f 0400 /* Need co
190b0 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c nvertCompoundSel
190c0 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 ectToSubquery()
190d0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 65 */.#define SF_Re
190e0 63 75 72 73 69 76 65 20 20 20 20 20 20 20 30 78 cursive 0x
190f0 30 38 30 30 20 20 2f 2a 20 54 68 65 20 72 65 63 0800 /* The rec
19100 75 72 73 69 76 65 20 70 61 72 74 20 6f 66 20 61 ursive part of a
19110 20 72 65 63 75 72 73 69 76 65 20 43 54 45 20 2a recursive CTE *
19120 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 69 6e /.#define SF_Min
19130 4d 61 78 41 67 67 20 20 20 20 20 20 20 30 78 31 MaxAgg 0x1
19140 30 30 30 20 20 2f 2a 20 41 67 67 72 65 67 61 74 000 /* Aggregat
19150 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 6d 69 6e e containing min
19160 28 29 20 6f 72 20 6d 61 78 28 29 20 2a 2f 0a 23 () or max() */.#
19170 64 65 66 69 6e 65 20 53 46 5f 43 6f 6e 76 65 72 define SF_Conver
19180 74 65 64 20 20 20 20 20 20 20 30 78 32 30 30 30 ted 0x2000
19190 20 20 2f 2a 20 42 79 20 63 6f 6e 76 65 72 74 43 /* By convertC
191a0 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 74 54 6f 53 ompoundSelectToS
191b0 75 62 71 75 65 72 79 28 29 20 2a 2f 0a 0a 0a 2f ubquery() */.../
191c0 2a 0a 2a 2a 20 54 68 65 20 72 65 73 75 6c 74 73 *.** The results
191d0 20 6f 66 20 61 20 53 45 4c 45 43 54 20 63 61 6e of a SELECT can
191e0 20 62 65 20 64 69 73 74 72 69 62 75 74 65 64 20 be distributed
191f0 69 6e 20 73 65 76 65 72 61 6c 20 77 61 79 73 2c in several ways,
19200 20 61 73 20 64 65 66 69 6e 65 64 0a 2a 2a 20 62 as defined.** b
19210 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c y one of the fol
19220 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 2e 20 20 lowing macros.
19230 54 68 65 20 22 53 52 54 22 20 70 72 65 66 69 78 The "SRT" prefix
19240 20 6d 65 61 6e 73 20 22 53 45 4c 45 43 54 20 52 means "SELECT R
19250 65 73 75 6c 74 0a 2a 2a 20 54 79 70 65 22 2e 0a esult.** Type"..
19260 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 55 6e **.** SRT_Un
19270 69 6f 6e 20 20 20 20 20 20 20 53 74 6f 72 65 20 ion Store
19280 72 65 73 75 6c 74 73 20 61 73 20 61 20 6b 65 79 results as a key
19290 20 69 6e 20 61 20 74 65 6d 70 6f 72 61 72 79 20 in a temporary
192a0 69 6e 64 65 78 20 0a 2a 2a 20 20 20 20 20 20 20 index .**
192b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 64 id
192c0 65 6e 74 69 66 69 65 64 20 62 79 20 70 44 65 73 entified by pDes
192d0 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a t->iSDParm..**.*
192e0 2a 20 20 20 20 20 53 52 54 5f 45 78 63 65 70 74 * SRT_Except
192f0 20 20 20 20 20 20 52 65 6d 6f 76 65 20 72 65 73 Remove res
19300 75 6c 74 73 20 66 72 6f 6d 20 74 68 65 20 74 65 ults from the te
19310 6d 70 6f 72 61 72 79 20 69 6e 64 65 78 20 70 44 mporary index pD
19320 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a est->iSDParm..**
19330 0a 2a 2a 20 20 20 20 20 53 52 54 5f 45 78 69 73 .** SRT_Exis
19340 74 73 20 20 20 20 20 20 53 74 6f 72 65 20 61 20 ts Store a
19350 31 20 69 6e 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 1 in memory cell
19360 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 pDest->iSDParm
19370 69 66 20 74 68 65 20 72 65 73 75 6c 74 0a 2a 2a if the result.**
19380 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19390 20 20 20 20 20 73 65 74 20 69 73 20 6e 6f 74 20 set is not
193a0 65 6d 70 74 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 empty..**.**
193b0 20 53 52 54 5f 44 69 73 63 61 72 64 20 20 20 20 SRT_Discard
193c0 20 54 68 72 6f 77 20 74 68 65 20 72 65 73 75 6c Throw the resul
193d0 74 73 20 61 77 61 79 2e 20 20 54 68 69 73 20 69 ts away. This i
193e0 73 20 75 73 65 64 20 62 79 20 53 45 4c 45 43 54 s used by SELECT
193f0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
19400 20 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 6e statemen
19410 74 73 20 77 69 74 68 69 6e 20 74 72 69 67 67 65 ts within trigge
19420 72 73 20 77 68 6f 73 65 20 6f 6e 6c 79 20 70 75 rs whose only pu
19430 72 70 6f 73 65 20 69 73 0a 2a 2a 20 20 20 20 20 rpose is.**
19440 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19450 74 68 65 20 73 69 64 65 2d 65 66 66 65 63 74 73 the side-effects
19460 20 6f 66 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a of functions..*
19470 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 65 20 *.** All of the
19480 61 62 6f 76 65 20 61 72 65 20 66 72 65 65 20 74 above are free t
19490 6f 20 69 67 6e 6f 72 65 20 74 68 65 69 72 20 4f o ignore their O
194a0 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 20 RDER BY clause.
194b0 54 68 6f 73 65 20 74 68 61 74 0a 2a 2a 20 66 6f Those that.** fo
194c0 6c 6c 6f 77 20 6d 75 73 74 20 68 6f 6e 6f 72 20 llow must honor
194d0 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 the ORDER BY cla
194e0 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 use..**.** S
194f0 52 54 5f 4f 75 74 70 75 74 20 20 20 20 20 20 47 RT_Output G
19500 65 6e 65 72 61 74 65 20 61 20 72 6f 77 20 6f 66 enerate a row of
19510 20 6f 75 74 70 75 74 20 28 75 73 69 6e 67 20 74 output (using t
19520 68 65 20 4f 50 5f 52 65 73 75 6c 74 52 6f 77 0a he OP_ResultRow.
19530 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
19540 20 20 20 20 20 20 20 6f 70 63 6f 64 65 29 20 66 opcode) f
19550 6f 72 20 65 61 63 68 20 72 6f 77 20 69 6e 20 74 or each row in t
19560 68 65 20 72 65 73 75 6c 74 20 73 65 74 2e 0a 2a he result set..*
19570 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4d 65 6d *.** SRT_Mem
19580 20 20 20 20 20 20 20 20 20 4f 6e 6c 79 20 76 61 Only va
19590 6c 69 64 20 69 66 20 74 68 65 20 72 65 73 75 6c lid if the resul
195a0 74 20 69 73 20 61 20 73 69 6e 67 6c 65 20 63 6f t is a single co
195b0 6c 75 6d 6e 2e 0a 2a 2a 20 20 20 20 20 20 20 20 lumn..**
195c0 20 20 20 20 20 20 20 20 20 20 20 20 20 53 74 6f Sto
195d0 72 65 20 74 68 65 20 66 69 72 73 74 20 63 6f 6c re the first col
195e0 75 6d 6e 20 6f 66 20 74 68 65 20 66 69 72 73 74 umn of the first
195f0 20 72 65 73 75 6c 74 20 72 6f 77 0a 2a 2a 20 20 result row.**
19600 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19610 20 20 20 69 6e 20 72 65 67 69 73 74 65 72 20 70 in register p
19620 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 74 68 Dest->iSDParm th
19630 65 6e 20 61 62 61 6e 64 6f 6e 20 74 68 65 20 72 en abandon the r
19640 65 73 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 est.**
19650 20 20 20 20 20 20 20 20 20 20 20 6f 66 20 74 68 of th
19660 65 20 71 75 65 72 79 2e 20 20 54 68 69 73 20 64 e query. This d
19670 65 73 74 69 6e 61 74 69 6f 6e 20 69 6d 70 6c 69 estination impli
19680 65 73 20 22 4c 49 4d 49 54 20 31 22 2e 0a 2a 2a es "LIMIT 1"..**
19690 0a 2a 2a 20 20 20 20 20 53 52 54 5f 53 65 74 20 .** SRT_Set
196a0 20 20 20 20 20 20 20 20 54 68 65 20 72 65 73 75 The resu
196b0 6c 74 20 6d 75 73 74 20 62 65 20 61 20 73 69 6e lt must be a sin
196c0 67 6c 65 20 63 6f 6c 75 6d 6e 2e 20 20 53 74 6f gle column. Sto
196d0 72 65 20 65 61 63 68 0a 2a 2a 20 20 20 20 20 20 re each.**
196e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
196f0 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 61 73 20 ow of result as
19700 74 68 65 20 6b 65 79 20 69 6e 20 74 61 62 6c 65 the key in table
19710 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e pDest->iSDParm.
19720 20 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 .**
19730 20 20 20 20 20 20 20 20 20 41 70 70 6c 79 20 74 Apply t
19740 68 65 20 61 66 66 69 6e 69 74 79 20 70 44 65 73 he affinity pDes
19750 74 2d 3e 61 66 66 53 64 73 74 20 62 65 66 6f 72 t->affSdst befor
19760 65 20 73 74 6f 72 69 6e 67 0a 2a 2a 20 20 20 20 e storing.**
19770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19780 20 72 65 73 75 6c 74 73 2e 20 20 55 73 65 64 20 results. Used
19790 74 6f 20 69 6d 70 6c 65 6d 65 6e 74 20 22 49 4e to implement "IN
197a0 20 28 53 45 4c 45 43 54 20 2e 2e 2e 29 22 2e 0a (SELECT ...)"..
197b0 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 45 70 **.** SRT_Ep
197c0 68 65 6d 54 61 62 20 20 20 20 43 72 65 61 74 65 hemTab Create
197d0 20 61 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 61 an temporary ta
197e0 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 ble pDest->iSDPa
197f0 72 6d 20 61 6e 64 20 73 74 6f 72 65 0a 2a 2a 20 rm and store.**
19800 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19810 20 20 20 20 74 68 65 20 72 65 73 75 6c 74 20 74 the result t
19820 68 65 72 65 2e 20 54 68 65 20 63 75 72 73 6f 72 here. The cursor
19830 20 69 73 20 6c 65 66 74 20 6f 70 65 6e 20 61 66 is left open af
19840 74 65 72 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ter.**
19850 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 retur
19860 6e 69 6e 67 2e 20 20 54 68 69 73 20 69 73 20 6c ning. This is l
19870 69 6b 65 20 53 52 54 5f 54 61 62 6c 65 20 65 78 ike SRT_Table ex
19880 63 65 70 74 20 74 68 61 74 0a 2a 2a 20 20 20 20 cept that.**
19890 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
198a0 20 74 68 69 73 20 64 65 73 74 69 6e 61 74 69 6f this destinatio
198b0 6e 20 75 73 65 73 20 4f 50 5f 4f 70 65 6e 45 70 n uses OP_OpenEp
198c0 68 65 6d 65 72 61 6c 20 74 6f 20 63 72 65 61 74 hemeral to creat
198d0 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 e.**
198e0 20 20 20 20 20 20 20 20 20 74 68 65 20 74 61 62 the tab
198f0 6c 65 20 66 69 72 73 74 2e 0a 2a 2a 0a 2a 2a 20 le first..**.**
19900 20 20 20 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e SRT_Coroutin
19910 65 20 20 20 47 65 6e 65 72 61 74 65 20 61 20 63 e Generate a c
19920 6f 2d 72 6f 75 74 69 6e 65 20 74 68 61 74 20 72 o-routine that r
19930 65 74 75 72 6e 73 20 61 20 6e 65 77 20 72 6f 77 eturns a new row
19940 20 6f 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 of.**
19950 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 6c resul
19960 74 73 20 65 61 63 68 20 74 69 6d 65 20 69 74 20 ts each time it
19970 69 73 20 69 6e 76 6f 6b 65 64 2e 20 20 54 68 65 is invoked. The
19980 20 65 6e 74 72 79 20 70 6f 69 6e 74 0a 2a 2a 20 entry point.**
19990 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
199a0 20 20 20 20 6f 66 20 74 68 65 20 63 6f 2d 72 6f of the co-ro
199b0 75 74 69 6e 65 20 69 73 20 73 74 6f 72 65 64 20 utine is stored
199c0 69 6e 20 72 65 67 69 73 74 65 72 20 70 44 65 73 in register pDes
199d0 74 2d 3e 69 53 44 50 61 72 6d 0a 2a 2a 20 20 20 t->iSDParm.**
199e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
199f0 20 20 61 6e 64 20 74 68 65 20 72 65 73 75 6c 74 and the result
19a00 20 72 6f 77 20 69 73 20 73 74 6f 72 65 64 20 69 row is stored i
19a10 6e 20 70 44 65 73 74 2d 3e 6e 44 65 73 74 20 72 n pDest->nDest r
19a20 65 67 69 73 74 65 72 73 0a 2a 2a 20 20 20 20 20 egisters.**
19a30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19a40 73 74 61 72 74 69 6e 67 20 77 69 74 68 20 70 44 starting with pD
19a50 65 73 74 2d 3e 69 53 64 73 74 2e 0a 2a 2a 0a 2a est->iSdst..**.*
19a60 2a 20 20 20 20 20 53 52 54 5f 54 61 62 6c 65 20 * SRT_Table
19a70 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 Store resu
19a80 6c 74 73 20 69 6e 20 74 65 6d 70 6f 72 61 72 79 lts in temporary
19a90 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 table pDest->iS
19aa0 44 50 61 72 6d 2e 0a 2a 2a 20 20 20 20 20 53 52 DParm..** SR
19ab0 54 5f 46 69 66 6f 20 20 20 20 20 20 20 20 54 68 T_Fifo Th
19ac0 69 73 20 69 73 20 6c 69 6b 65 20 53 52 54 5f 45 is is like SRT_E
19ad0 70 68 65 6d 54 61 62 20 65 78 63 65 70 74 20 74 phemTab except t
19ae0 68 61 74 20 74 68 65 20 74 61 62 6c 65 0a 2a 2a hat the table.**
19af0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19b00 20 20 20 20 20 69 73 20 61 73 73 75 6d 65 64 20 is assumed
19b10 74 6f 20 61 6c 72 65 61 64 79 20 62 65 20 6f 70 to already be op
19b20 65 6e 2e 20 20 53 52 54 5f 46 69 66 6f 20 68 61 en. SRT_Fifo ha
19b30 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 s.**
19b40 20 20 20 20 20 20 20 20 20 74 68 65 20 61 64 64 the add
19b50 69 74 69 6f 6e 61 6c 20 70 72 6f 70 65 72 74 79 itional property
19b60 20 6f 66 20 62 65 69 6e 67 20 61 62 6c 65 20 74 of being able t
19b70 6f 20 69 67 6e 6f 72 65 0a 2a 2a 20 20 20 20 20 o ignore.**
19b80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19b90 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 the ORDER BY cla
19ba0 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 use..**.** S
19bb0 52 54 5f 44 69 73 74 46 69 66 6f 20 20 20 20 53 RT_DistFifo S
19bc0 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 tore results in
19bd0 61 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c a temporary tabl
19be0 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
19bf0 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ..**
19c00 20 20 20 20 20 20 20 20 20 42 75 74 20 61 6c 73 But als
19c10 6f 20 75 73 65 20 74 65 6d 70 6f 72 61 72 79 20 o use temporary
19c20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 table pDest->iSD
19c30 50 61 72 6d 2b 31 20 61 73 0a 2a 2a 20 20 20 20 Parm+1 as.**
19c40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19c50 20 61 20 72 65 63 6f 72 64 20 6f 66 20 61 6c 6c a record of all
19c60 20 70 72 69 6f 72 20 72 65 73 75 6c 74 73 20 61 prior results a
19c70 6e 64 20 69 67 6e 6f 72 65 20 61 6e 79 20 64 75 nd ignore any du
19c80 70 6c 69 63 61 74 65 0a 2a 2a 20 20 20 20 20 20 plicate.**
19c90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
19ca0 6f 77 73 2e 20 20 4e 61 6d 65 20 6d 65 61 6e 73 ows. Name means
19cb0 3a 20 20 22 44 69 73 74 69 6e 63 74 20 46 69 66 : "Distinct Fif
19cc0 6f 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 o"..**.** SR
19cd0 54 5f 51 75 65 75 65 20 20 20 20 20 20 20 53 74 T_Queue St
19ce0 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 70 ore results in p
19cf0 72 69 6f 72 69 74 79 20 71 75 65 75 65 20 70 44 riority queue pD
19d00 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 28 72 65 est->iSDParm (re
19d10 61 6c 6c 79 0a 2a 2a 20 20 20 20 20 20 20 20 20 ally.**
19d20 20 20 20 20 20 20 20 20 20 20 20 20 61 6e 20 69 an i
19d30 6e 64 65 78 29 2e 20 20 41 70 70 65 6e 64 20 61 ndex). Append a
19d40 20 73 65 71 75 65 6e 63 65 20 6e 75 6d 62 65 72 sequence number
19d50 20 73 6f 20 74 68 61 74 20 61 6c 6c 20 65 6e 74 so that all ent
19d60 72 69 65 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 ries.**
19d70 20 20 20 20 20 20 20 20 20 20 20 20 61 72 65 20 are
19d80 64 69 73 74 69 6e 63 74 2e 0a 2a 2a 0a 2a 2a 20 distinct..**.**
19d90 20 20 20 20 53 52 54 5f 44 69 73 74 51 75 65 75 SRT_DistQueu
19da0 65 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 e Store result
19db0 73 20 69 6e 20 70 72 69 6f 72 69 74 79 20 71 75 s in priority qu
19dc0 65 75 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 eue pDest->iSDPa
19dd0 72 6d 20 6f 6e 6c 79 20 69 66 0a 2a 2a 20 20 20 rm only if.**
19de0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19df0 20 20 74 68 65 20 73 61 6d 65 20 72 65 63 6f 72 the same recor
19e00 64 20 68 61 73 20 6e 65 76 65 72 20 62 65 65 6e d has never been
19e10 20 73 74 6f 72 65 64 20 62 65 66 6f 72 65 2e 20 stored before.
19e20 20 54 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 The.**
19e30 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 64 65 inde
19e40 78 20 61 74 20 70 44 65 73 74 2d 3e 69 53 44 50 x at pDest->iSDP
19e50 61 72 6d 2b 31 20 68 6f 6c 64 20 61 6c 6c 20 70 arm+1 hold all p
19e60 72 69 6f 72 20 73 74 6f 72 65 73 2e 0a 2a 2f 0a rior stores..*/.
19e70 23 64 65 66 69 6e 65 20 53 52 54 5f 55 6e 69 6f #define SRT_Unio
19e80 6e 20 20 20 20 20 20 20 20 31 20 20 2f 2a 20 53 n 1 /* S
19e90 74 6f 72 65 20 72 65 73 75 6c 74 20 61 73 20 6b tore result as k
19ea0 65 79 73 20 69 6e 20 61 6e 20 69 6e 64 65 78 20 eys in an index
19eb0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 45 */.#define SRT_E
19ec0 78 63 65 70 74 20 20 20 20 20 20 20 32 20 20 2f xcept 2 /
19ed0 2a 20 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 20 * Remove result
19ee0 66 72 6f 6d 20 61 20 55 4e 49 4f 4e 20 69 6e 64 from a UNION ind
19ef0 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ex */.#define SR
19f00 54 5f 45 78 69 73 74 73 20 20 20 20 20 20 20 33 T_Exists 3
19f10 20 20 2f 2a 20 53 74 6f 72 65 20 31 20 69 66 20 /* Store 1 if
19f20 74 68 65 20 72 65 73 75 6c 74 20 69 73 20 6e 6f the result is no
19f30 74 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 69 t empty */.#defi
19f40 6e 65 20 53 52 54 5f 44 69 73 63 61 72 64 20 20 ne SRT_Discard
19f50 20 20 20 20 34 20 20 2f 2a 20 44 6f 20 6e 6f 74 4 /* Do not
19f60 20 73 61 76 65 20 74 68 65 20 72 65 73 75 6c 74 save the result
19f70 73 20 61 6e 79 77 68 65 72 65 20 2a 2f 0a 23 64 s anywhere */.#d
19f80 65 66 69 6e 65 20 53 52 54 5f 46 69 66 6f 20 20 efine SRT_Fifo
19f90 20 20 20 20 20 20 20 35 20 20 2f 2a 20 53 74 6f 5 /* Sto
19fa0 72 65 20 72 65 73 75 6c 74 20 61 73 20 64 61 74 re result as dat
19fb0 61 20 77 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 a with an automa
19fc0 74 69 63 20 72 6f 77 69 64 20 2a 2f 0a 23 64 65 tic rowid */.#de
19fd0 66 69 6e 65 20 53 52 54 5f 44 69 73 74 46 69 66 fine SRT_DistFif
19fe0 6f 20 20 20 20 20 36 20 20 2f 2a 20 4c 69 6b 65 o 6 /* Like
19ff0 20 53 52 54 5f 46 69 66 6f 2c 20 62 75 74 20 75 SRT_Fifo, but u
1a000 6e 69 71 75 65 20 72 65 73 75 6c 74 73 20 6f 6e nique results on
1a010 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ly */.#define SR
1a020 54 5f 51 75 65 75 65 20 20 20 20 20 20 20 20 37 T_Queue 7
1a030 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
1a040 74 20 69 6e 20 61 6e 20 71 75 65 75 65 20 2a 2f t in an queue */
1a050 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 44 69 73 .#define SRT_Dis
1a060 74 51 75 65 75 65 20 20 20 20 38 20 20 2f 2a 20 tQueue 8 /*
1a070 4c 69 6b 65 20 53 52 54 5f 51 75 65 75 65 2c 20 Like SRT_Queue,
1a080 62 75 74 20 75 6e 69 71 75 65 20 72 65 73 75 6c but unique resul
1a090 74 73 20 6f 6e 6c 79 20 2a 2f 0a 0a 2f 2a 20 54 ts only */../* T
1a0a0 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 he ORDER BY clau
1a0b0 73 65 20 69 73 20 69 67 6e 6f 72 65 64 20 66 6f se is ignored fo
1a0c0 72 20 61 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f r all of the abo
1a0d0 76 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 67 ve */.#define Ig
1a0e0 6e 6f 72 61 62 6c 65 4f 72 64 65 72 62 79 28 58 norableOrderby(X
1a0f0 29 20 28 28 58 2d 3e 65 44 65 73 74 29 3c 3d 53 ) ((X->eDest)<=S
1a100 52 54 5f 44 69 73 74 51 75 65 75 65 29 0a 0a 23 RT_DistQueue)..#
1a110 64 65 66 69 6e 65 20 53 52 54 5f 4f 75 74 70 75 define SRT_Outpu
1a120 74 20 20 20 20 20 20 20 39 20 20 2f 2a 20 4f 75 t 9 /* Ou
1a130 74 70 75 74 20 65 61 63 68 20 72 6f 77 20 6f 66 tput each row of
1a140 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 69 result */.#defi
1a150 6e 65 20 53 52 54 5f 4d 65 6d 20 20 20 20 20 20 ne SRT_Mem
1a160 20 20 20 31 30 20 20 2f 2a 20 53 74 6f 72 65 20 10 /* Store
1a170 72 65 73 75 6c 74 20 69 6e 20 61 20 6d 65 6d 6f result in a memo
1a180 72 79 20 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 69 ry cell */.#defi
1a190 6e 65 20 53 52 54 5f 53 65 74 20 20 20 20 20 20 ne SRT_Set
1a1a0 20 20 20 31 31 20 20 2f 2a 20 53 74 6f 72 65 20 11 /* Store
1a1b0 72 65 73 75 6c 74 73 20 61 73 20 6b 65 79 73 20 results as keys
1a1c0 69 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 in an index */.#
1a1d0 64 65 66 69 6e 65 20 53 52 54 5f 45 70 68 65 6d define SRT_Ephem
1a1e0 54 61 62 20 20 20 20 31 32 20 20 2f 2a 20 43 72 Tab 12 /* Cr
1a1f0 65 61 74 65 20 74 72 61 6e 73 69 65 6e 74 20 74 eate transient t
1a200 61 62 20 61 6e 64 20 73 74 6f 72 65 20 6c 69 6b ab and store lik
1a210 65 20 53 52 54 5f 54 61 62 6c 65 20 2a 2f 0a 23 e SRT_Table */.#
1a220 64 65 66 69 6e 65 20 53 52 54 5f 43 6f 72 6f 75 define SRT_Corou
1a230 74 69 6e 65 20 20 20 31 33 20 20 2f 2a 20 47 65 tine 13 /* Ge
1a240 6e 65 72 61 74 65 20 61 20 73 69 6e 67 6c 65 20 nerate a single
1a250 72 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 2a 2f row of result */
1a260 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 54 61 62 .#define SRT_Tab
1a270 6c 65 20 20 20 20 20 20 20 31 34 20 20 2f 2a 20 le 14 /*
1a280 53 74 6f 72 65 20 72 65 73 75 6c 74 20 61 73 20 Store result as
1a290 64 61 74 61 20 77 69 74 68 20 61 6e 20 61 75 74 data with an aut
1a2a0 6f 6d 61 74 69 63 20 72 6f 77 69 64 20 2a 2f 0a omatic rowid */.
1a2b0 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
1a2c0 63 65 20 6f 66 20 74 68 69 73 20 6f 62 6a 65 63 ce of this objec
1a2d0 74 20 64 65 73 63 72 69 62 65 73 20 77 68 65 72 t describes wher
1a2e0 65 20 74 6f 20 70 75 74 20 6f 66 20 74 68 65 20 e to put of the
1a2f0 72 65 73 75 6c 74 73 20 6f 66 0a 2a 2a 20 61 20 results of.** a
1a300 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
1a310 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c 65 ..*/.struct Sele
1a320 63 74 44 65 73 74 20 7b 0a 20 20 75 38 20 65 44 ctDest {. u8 eD
1a330 65 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 est;
1a340 2f 2a 20 48 6f 77 20 74 6f 20 64 69 73 70 6f 73 /* How to dispos
1a350 65 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 73 e of the results
1a360 2e 20 20 4f 6e 20 6f 66 20 53 52 54 5f 2a 20 61 . On of SRT_* a
1a370 62 6f 76 65 2e 20 2a 2f 0a 20 20 63 68 61 72 20 bove. */. char
1a380 61 66 66 53 64 73 74 3b 20 20 20 20 20 20 20 20 affSdst;
1a390 2f 2a 20 41 66 66 69 6e 69 74 79 20 75 73 65 64 /* Affinity used
1a3a0 20 77 68 65 6e 20 65 44 65 73 74 3d 3d 53 52 54 when eDest==SRT
1a3b0 5f 53 65 74 20 2a 2f 0a 20 20 69 6e 74 20 69 53 _Set */. int iS
1a3c0 44 50 61 72 6d 3b 20 20 20 20 20 20 20 20 20 2f DParm; /
1a3d0 2a 20 41 20 70 61 72 61 6d 65 74 65 72 20 75 73 * A parameter us
1a3e0 65 64 20 62 79 20 74 68 65 20 65 44 65 73 74 20 ed by the eDest
1a3f0 64 69 73 70 6f 73 61 6c 20 6d 65 74 68 6f 64 20 disposal method
1a400 2a 2f 0a 20 20 69 6e 74 20 69 53 64 73 74 3b 20 */. int iSdst;
1a410 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 61 73 /* Bas
1a420 65 20 72 65 67 69 73 74 65 72 20 77 68 65 72 65 e register where
1a430 20 72 65 73 75 6c 74 73 20 61 72 65 20 77 72 69 results are wri
1a440 74 74 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 tten */. int nS
1a450 64 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f dst; /
1a460 2a 20 4e 75 6d 62 65 72 20 6f 66 20 72 65 67 69 * Number of regi
1a470 73 74 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 sters allocated
1a480 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
1a490 4f 72 64 65 72 42 79 3b 20 20 2f 2a 20 4b 65 79 OrderBy; /* Key
1a4a0 20 63 6f 6c 75 6d 6e 73 20 66 6f 72 20 53 52 54 columns for SRT
1a4b0 5f 51 75 65 75 65 20 61 6e 64 20 53 52 54 5f 44 _Queue and SRT_D
1a4c0 69 73 74 51 75 65 75 65 20 2a 2f 0a 7d 3b 0a 0a istQueue */.};..
1a4d0 2f 2a 0a 2a 2a 20 44 75 72 69 6e 67 20 63 6f 64 /*.** During cod
1a4e0 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f 66 20 e generation of
1a4f0 73 74 61 74 65 6d 65 6e 74 73 20 74 68 61 74 20 statements that
1a500 64 6f 20 69 6e 73 65 72 74 73 20 69 6e 74 6f 20 do inserts into
1a510 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 0a 2a AUTOINCREMENT .*
1a520 2a 20 74 61 62 6c 65 73 2c 20 74 68 65 20 66 6f * tables, the fo
1a530 6c 6c 6f 77 69 6e 67 20 69 6e 66 6f 72 6d 61 74 llowing informat
1a540 69 6f 6e 20 69 73 20 61 74 74 61 63 68 65 64 20 ion is attached
1a550 74 6f 20 74 68 65 20 54 61 62 6c 65 2e 75 2e 61 to the Table.u.a
1a560 75 74 6f 49 6e 63 2e 70 0a 2a 2a 20 70 6f 69 6e utoInc.p.** poin
1a570 74 65 72 20 6f 66 20 65 61 63 68 20 61 75 74 6f ter of each auto
1a580 69 6e 63 72 65 6d 65 6e 74 20 74 61 62 6c 65 20 increment table
1a590 74 6f 20 72 65 63 6f 72 64 20 73 6f 6d 65 20 73 to record some s
1a5a0 69 64 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 ide information
1a5b0 74 68 61 74 0a 2a 2a 20 74 68 65 20 63 6f 64 65 that.** the code
1a5c0 20 67 65 6e 65 72 61 74 6f 72 20 6e 65 65 64 73 generator needs
1a5d0 2e 20 20 57 65 20 68 61 76 65 20 74 6f 20 6b 65 . We have to ke
1a5e0 65 70 20 70 65 72 2d 74 61 62 6c 65 20 61 75 74 ep per-table aut
1a5f0 6f 69 6e 63 72 65 6d 65 6e 74 0a 2a 2a 20 69 6e oincrement.** in
1a600 66 6f 72 6d 61 74 69 6f 6e 20 69 6e 20 63 61 73 formation in cas
1a610 65 20 69 6e 73 65 72 74 73 20 61 72 65 20 64 6f e inserts are do
1a620 77 6e 20 77 69 74 68 69 6e 20 74 72 69 67 67 65 wn within trigge
1a630 72 73 2e 20 20 54 72 69 67 67 65 72 73 20 64 6f rs. Triggers do
1a640 20 6e 6f 74 0a 2a 2a 20 6e 6f 72 6d 61 6c 6c 79 not.** normally
1a650 20 63 6f 6f 72 64 69 6e 61 74 65 20 74 68 65 69 coordinate thei
1a660 72 20 61 63 74 69 76 69 74 69 65 73 2c 20 62 75 r activities, bu
1a670 74 20 77 65 20 64 6f 20 6e 65 65 64 20 74 6f 20 t we do need to
1a680 63 6f 6f 72 64 69 6e 61 74 65 20 74 68 65 0a 2a coordinate the.*
1a690 2a 20 6c 6f 61 64 69 6e 67 20 61 6e 64 20 73 61 * loading and sa
1a6a0 76 69 6e 67 20 6f 66 20 61 75 74 6f 69 6e 63 72 ving of autoincr
1a6b0 65 6d 65 6e 74 20 69 6e 66 6f 72 6d 61 74 69 6f ement informatio
1a6c0 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 75 74 n..*/.struct Aut
1a6d0 6f 69 6e 63 49 6e 66 6f 20 7b 0a 20 20 41 75 74 oincInfo {. Aut
1a6e0 6f 69 6e 63 49 6e 66 6f 20 2a 70 4e 65 78 74 3b oincInfo *pNext;
1a6f0 20 20 20 2f 2a 20 4e 65 78 74 20 69 6e 66 6f 20 /* Next info
1a700 62 6c 6f 63 6b 20 69 6e 20 61 20 6c 69 73 74 20 block in a list
1a710 6f 66 20 74 68 65 6d 20 61 6c 6c 20 2a 2f 0a 20 of them all */.
1a720 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 Table *pTab;
1a730 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 /* Table
1a740 74 68 69 73 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 this info block
1a750 72 65 66 65 72 73 20 74 6f 20 2a 2f 0a 20 20 69 refers to */. i
1a760 6e 74 20 69 44 62 3b 20 20 20 20 20 20 20 20 20 nt iDb;
1a770 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e /* Index in
1a780 20 73 71 6c 69 74 65 33 2e 61 44 62 5b 5d 20 6f sqlite3.aDb[] o
1a790 66 20 64 61 74 61 62 61 73 65 20 68 6f 6c 64 69 f database holdi
1a7a0 6e 67 20 70 54 61 62 20 2a 2f 0a 20 20 69 6e 74 ng pTab */. int
1a7b0 20 72 65 67 43 74 72 3b 20 20 20 20 20 20 20 20 regCtr;
1a7c0 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 72 65 67 /* Memory reg
1a7d0 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 74 68 ister holding th
1a7e0 65 20 72 6f 77 69 64 20 63 6f 75 6e 74 65 72 20 e rowid counter
1a7f0 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 69 7a */.};../*.** Siz
1a800 65 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e 20 e of the column
1a810 63 61 63 68 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 cache.*/.#ifndef
1a820 20 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 SQLITE_N_COLCAC
1a830 48 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 HE.# define SQLI
1a840 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 20 31 30 TE_N_COLCACHE 10
1a850 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 .#endif../*.** A
1a860 74 20 6c 65 61 73 74 20 6f 6e 65 20 69 6e 73 74 t least one inst
1a870 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c ance of the foll
1a880 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 owing structure
1a890 69 73 20 63 72 65 61 74 65 64 20 66 6f 72 20 65 is created for e
1a8a0 61 63 68 20 0a 2a 2a 20 74 72 69 67 67 65 72 20 ach .** trigger
1a8b0 74 68 61 74 20 6d 61 79 20 62 65 20 66 69 72 65 that may be fire
1a8c0 64 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 20 d while parsing
1a8d0 61 6e 20 49 4e 53 45 52 54 2c 20 55 50 44 41 54 an INSERT, UPDAT
1a8e0 45 20 6f 72 20 44 45 4c 45 54 45 0a 2a 2a 20 73 E or DELETE.** s
1a8f0 74 61 74 65 6d 65 6e 74 2e 20 41 6c 6c 20 73 75 tatement. All su
1a900 63 68 20 6f 62 6a 65 63 74 73 20 61 72 65 20 73 ch objects are s
1a910 74 6f 72 65 64 20 69 6e 20 74 68 65 20 6c 69 6e tored in the lin
1a920 6b 65 64 20 6c 69 73 74 20 68 65 61 64 65 64 20 ked list headed
1a930 61 74 0a 2a 2a 20 50 61 72 73 65 2e 70 54 72 69 at.** Parse.pTri
1a940 67 67 65 72 50 72 67 20 61 6e 64 20 64 65 6c 65 ggerPrg and dele
1a950 74 65 64 20 6f 6e 63 65 20 73 74 61 74 65 6d 65 ted once stateme
1a960 6e 74 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 68 nt compilation h
1a970 61 73 20 62 65 65 6e 0a 2a 2a 20 63 6f 6d 70 6c as been.** compl
1a980 65 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 41 20 56 64 eted..**.** A Vd
1a990 62 65 20 73 75 62 2d 70 72 6f 67 72 61 6d 20 74 be sub-program t
1a9a0 68 61 74 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 hat implements t
1a9b0 68 65 20 62 6f 64 79 20 61 6e 64 20 57 48 45 4e he body and WHEN
1a9c0 20 63 6c 61 75 73 65 20 6f 66 20 74 72 69 67 67 clause of trigg
1a9d0 65 72 0a 2a 2a 20 54 72 69 67 67 65 72 50 72 67 er.** TriggerPrg
1a9e0 2e 70 54 72 69 67 67 65 72 2c 20 61 73 73 75 6d .pTrigger, assum
1a9f0 69 6e 67 20 61 20 64 65 66 61 75 6c 74 20 4f 4e ing a default ON
1aa00 20 43 4f 4e 46 4c 49 43 54 20 63 6c 61 75 73 65 CONFLICT clause
1aa10 20 6f 66 0a 2a 2a 20 54 72 69 67 67 65 72 50 72 of.** TriggerPr
1aa20 67 2e 6f 72 63 6f 6e 66 2c 20 69 73 20 73 74 6f g.orconf, is sto
1aa30 72 65 64 20 69 6e 20 74 68 65 20 54 72 69 67 67 red in the Trigg
1aa40 65 72 50 72 67 2e 70 50 72 6f 67 72 61 6d 20 76 erPrg.pProgram v
1aa50 61 72 69 61 62 6c 65 2e 0a 2a 2a 20 54 68 65 20 ariable..** The
1aa60 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 Parse.pTriggerPr
1aa70 67 20 6c 69 73 74 20 6e 65 76 65 72 20 63 6f 6e g list never con
1aa80 74 61 69 6e 73 20 74 77 6f 20 65 6e 74 72 69 65 tains two entrie
1aa90 73 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 0a s with the same.
1aaa0 2a 2a 20 76 61 6c 75 65 73 20 66 6f 72 20 62 6f ** values for bo
1aab0 74 68 20 70 54 72 69 67 67 65 72 20 61 6e 64 20 th pTrigger and
1aac0 6f 72 63 6f 6e 66 2e 0a 2a 2a 0a 2a 2a 20 54 68 orconf..**.** Th
1aad0 65 20 54 72 69 67 67 65 72 50 72 67 2e 61 43 6f e TriggerPrg.aCo
1aae0 6c 6d 61 73 6b 5b 30 5d 20 76 61 72 69 61 62 6c lmask[0] variabl
1aaf0 65 20 69 73 20 73 65 74 20 74 6f 20 61 20 6d 61 e is set to a ma
1ab00 73 6b 20 6f 66 20 6f 6c 64 2e 2a 20 63 6f 6c 75 sk of old.* colu
1ab10 6d 6e 73 0a 2a 2a 20 61 63 63 65 73 73 65 64 20 mns.** accessed
1ab20 28 6f 72 20 73 65 74 20 74 6f 20 30 20 66 6f 72 (or set to 0 for
1ab30 20 74 72 69 67 67 65 72 73 20 66 69 72 65 64 20 triggers fired
1ab40 61 73 20 61 20 72 65 73 75 6c 74 20 6f 66 20 49 as a result of I
1ab50 4e 53 45 52 54 20 0a 2a 2a 20 73 74 61 74 65 6d NSERT .** statem
1ab60 65 6e 74 73 29 2e 20 53 69 6d 69 6c 61 72 6c 79 ents). Similarly
1ab70 2c 20 74 68 65 20 54 72 69 67 67 65 72 50 72 67 , the TriggerPrg
1ab80 2e 61 43 6f 6c 6d 61 73 6b 5b 31 5d 20 76 61 72 .aColmask[1] var
1ab90 69 61 62 6c 65 20 69 73 20 73 65 74 20 74 6f 0a iable is set to.
1aba0 2a 2a 20 61 20 6d 61 73 6b 20 6f 66 20 6e 65 77 ** a mask of new
1abb0 2e 2a 20 63 6f 6c 75 6d 6e 73 20 75 73 65 64 20 .* columns used
1abc0 62 79 20 74 68 65 20 70 72 6f 67 72 61 6d 2e 0a by the program..
1abd0 2a 2f 0a 73 74 72 75 63 74 20 54 72 69 67 67 65 */.struct Trigge
1abe0 72 50 72 67 20 7b 0a 20 20 54 72 69 67 67 65 72 rPrg {. Trigger
1abf0 20 2a 70 54 72 69 67 67 65 72 3b 20 20 20 20 20 *pTrigger;
1ac00 20 2f 2a 20 54 72 69 67 67 65 72 20 74 68 69 73 /* Trigger this
1ac10 20 70 72 6f 67 72 61 6d 20 77 61 73 20 63 6f 64 program was cod
1ac20 65 64 20 66 72 6f 6d 20 2a 2f 0a 20 20 54 72 69 ed from */. Tri
1ac30 67 67 65 72 50 72 67 20 2a 70 4e 65 78 74 3b 20 ggerPrg *pNext;
1ac40 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 65 6e 74 /* Next ent
1ac50 72 79 20 69 6e 20 50 61 72 73 65 2e 70 54 72 69 ry in Parse.pTri
1ac60 67 67 65 72 50 72 67 20 6c 69 73 74 20 2a 2f 0a ggerPrg list */.
1ac70 20 20 53 75 62 50 72 6f 67 72 61 6d 20 2a 70 50 SubProgram *pP
1ac80 72 6f 67 72 61 6d 3b 20 20 20 2f 2a 20 50 72 6f rogram; /* Pro
1ac90 67 72 61 6d 20 69 6d 70 6c 65 6d 65 6e 74 69 6e gram implementin
1aca0 67 20 70 54 72 69 67 67 65 72 2f 6f 72 63 6f 6e g pTrigger/orcon
1acb0 66 20 2a 2f 0a 20 20 69 6e 74 20 6f 72 63 6f 6e f */. int orcon
1acc0 66 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f f; /
1acd0 2a 20 44 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e * Default ON CON
1ace0 46 4c 49 43 54 20 70 6f 6c 69 63 79 20 2a 2f 0a FLICT policy */.
1acf0 20 20 75 33 32 20 61 43 6f 6c 6d 61 73 6b 5b 32 u32 aColmask[2
1ad00 5d 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 73 ]; /* Mas
1ad10 6b 73 20 6f 66 20 6f 6c 64 2e 2a 2c 20 6e 65 77 ks of old.*, new
1ad20 2e 2a 20 63 6f 6c 75 6d 6e 73 20 61 63 63 65 73 .* columns acces
1ad30 73 65 64 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a sed */.};../*.**
1ad40 20 54 68 65 20 79 44 62 4d 61 73 6b 20 64 61 74 The yDbMask dat
1ad50 61 74 79 70 65 20 66 6f 72 20 74 68 65 20 62 69 atype for the bi
1ad60 74 6d 61 73 6b 20 6f 66 20 61 6c 6c 20 61 74 74 tmask of all att
1ad70 61 63 68 65 64 20 64 61 74 61 62 61 73 65 73 2e ached databases.
1ad80 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d .*/.#if SQLITE_M
1ad90 41 58 5f 41 54 54 41 43 48 45 44 3e 33 30 0a 20 AX_ATTACHED>30.
1ada0 20 74 79 70 65 64 65 66 20 75 6e 73 69 67 6e 65 typedef unsigne
1adb0 64 20 63 68 61 72 20 79 44 62 4d 61 73 6b 5b 28 d char yDbMask[(
1adc0 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 SQLITE_MAX_ATTAC
1add0 48 45 44 2b 39 29 2f 38 5d 3b 0a 23 20 64 65 66 HED+9)/8];.# def
1ade0 69 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 4d ine DbMaskTest(M
1adf0 2c 49 29 20 20 20 20 28 28 28 4d 29 5b 28 49 29 ,I) (((M)[(I)
1ae00 2f 38 5d 26 28 31 3c 3c 28 28 49 29 26 37 29 29 /8]&(1<<((I)&7))
1ae10 29 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 44 )!=0).# define D
1ae20 62 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 20 bMaskZero(M)
1ae30 20 20 6d 65 6d 73 65 74 28 28 4d 29 2c 30 2c 73 memset((M),0,s
1ae40 69 7a 65 6f 66 28 4d 29 29 0a 23 20 64 65 66 69 izeof(M)).# defi
1ae50 6e 65 20 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 ne DbMaskSet(M,I
1ae60 29 20 20 20 20 20 28 4d 29 5b 28 49 29 2f 38 5d ) (M)[(I)/8]
1ae70 7c 3d 28 31 3c 3c 28 28 49 29 26 37 29 29 0a 23 |=(1<<((I)&7)).#
1ae80 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c define DbMaskAl
1ae90 6c 5a 65 72 6f 28 4d 29 20 20 20 73 71 6c 69 74 lZero(M) sqlit
1aea0 65 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 e3DbMaskAllZero(
1aeb0 4d 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 M).# define DbMa
1aec0 73 6b 4e 6f 6e 5a 65 72 6f 28 4d 29 20 20 20 28 skNonZero(M) (
1aed0 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c 6c sqlite3DbMaskAll
1aee0 5a 65 72 6f 28 4d 29 3d 3d 30 29 0a 23 65 6c 73 Zero(M)==0).#els
1aef0 65 0a 20 20 74 79 70 65 64 65 66 20 75 6e 73 69 e. typedef unsi
1af00 67 6e 65 64 20 69 6e 74 20 79 44 62 4d 61 73 6b gned int yDbMask
1af10 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 ;.# define DbMas
1af20 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 28 kTest(M,I) ((
1af30 28 4d 29 26 28 28 28 79 44 62 4d 61 73 6b 29 31 (M)&(((yDbMask)1
1af40 29 3c 3c 28 49 29 29 29 21 3d 30 29 0a 23 20 64 )<<(I)))!=0).# d
1af50 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 6f efine DbMaskZero
1af60 28 4d 29 20 20 20 20 20 20 28 4d 29 3d 30 0a 23 (M) (M)=0.#
1af70 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 53 65 define DbMaskSe
1af80 74 28 4d 2c 49 29 20 20 20 20 20 28 4d 29 7c 3d t(M,I) (M)|=
1af90 28 28 28 79 44 62 4d 61 73 6b 29 31 29 3c 3c 28 (((yDbMask)1)<<(
1afa0 49 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d I)).# define DbM
1afb0 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 20 20 20 askAllZero(M)
1afc0 28 4d 29 3d 3d 30 0a 23 20 64 65 66 69 6e 65 20 (M)==0.# define
1afd0 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 6f 28 4d 29 DbMaskNonZero(M)
1afe0 20 20 20 28 4d 29 21 3d 30 0a 23 65 6e 64 69 66 (M)!=0.#endif
1aff0 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 53 51 4c 20 70 ../*.** An SQL p
1b000 61 72 73 65 72 20 63 6f 6e 74 65 78 74 2e 20 20 arser context.
1b010 41 20 63 6f 70 79 20 6f 66 20 74 68 69 73 20 73 A copy of this s
1b020 74 72 75 63 74 75 72 65 20 69 73 20 70 61 73 73 tructure is pass
1b030 65 64 20 74 68 72 6f 75 67 68 0a 2a 2a 20 74 68 ed through.** th
1b040 65 20 70 61 72 73 65 72 20 61 6e 64 20 64 6f 77 e parser and dow
1b050 6e 20 69 6e 74 6f 20 61 6c 6c 20 74 68 65 20 70 n into all the p
1b060 61 72 73 65 72 20 61 63 74 69 6f 6e 20 72 6f 75 arser action rou
1b070 74 69 6e 65 20 69 6e 20 6f 72 64 65 72 20 74 6f tine in order to
1b080 0a 2a 2a 20 63 61 72 72 79 20 61 72 6f 75 6e 64 .** carry around
1b090 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 information tha
1b0a0 74 20 69 73 20 67 6c 6f 62 61 6c 20 74 6f 20 74 t is global to t
1b0b0 68 65 20 65 6e 74 69 72 65 20 70 61 72 73 65 2e he entire parse.
1b0c0 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 74 72 75 63 .**.** The struc
1b0d0 74 75 72 65 20 69 73 20 64 69 76 69 64 65 64 20 ture is divided
1b0e0 69 6e 74 6f 20 74 77 6f 20 70 61 72 74 73 2e 20 into two parts.
1b0f0 20 57 68 65 6e 20 74 68 65 20 70 61 72 73 65 72 When the parser
1b100 20 61 6e 64 20 63 6f 64 65 0a 2a 2a 20 67 65 6e and code.** gen
1b110 65 72 61 74 65 20 63 61 6c 6c 20 74 68 65 6d 73 erate call thems
1b120 65 6c 76 65 73 20 72 65 63 75 72 73 69 76 65 6c elves recursivel
1b130 79 2c 20 74 68 65 20 66 69 72 73 74 20 70 61 72 y, the first par
1b140 74 20 6f 66 20 74 68 65 20 73 74 72 75 63 74 75 t of the structu
1b150 72 65 0a 2a 2a 20 69 73 20 63 6f 6e 73 74 61 6e re.** is constan
1b160 74 20 62 75 74 20 74 68 65 20 73 65 63 6f 6e 64 t but the second
1b170 20 70 61 72 74 20 69 73 20 72 65 73 65 74 20 61 part is reset a
1b180 74 20 74 68 65 20 62 65 67 69 6e 6e 69 6e 67 20 t the beginning
1b190 61 6e 64 20 65 6e 64 20 6f 66 0a 2a 2a 20 65 61 and end of.** ea
1b1a0 63 68 20 72 65 63 75 72 73 69 6f 6e 2e 0a 2a 2a ch recursion..**
1b1b0 0a 2a 2a 20 54 68 65 20 6e 54 61 62 6c 65 4c 6f .** The nTableLo
1b1c0 63 6b 20 61 6e 64 20 61 54 61 62 6c 65 4c 6f 63 ck and aTableLoc
1b1d0 6b 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 k variables are
1b1e0 6f 6e 6c 79 20 75 73 65 64 20 69 66 20 74 68 65 only used if the
1b1f0 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 0a 2a shared-cache .*
1b200 2a 20 66 65 61 74 75 72 65 20 69 73 20 65 6e 61 * feature is ena
1b210 62 6c 65 64 20 28 69 66 20 73 71 6c 69 74 65 33 bled (if sqlite3
1b220 54 73 64 28 29 2d 3e 75 73 65 53 68 61 72 65 64 Tsd()->useShared
1b230 44 61 74 61 20 69 73 20 74 72 75 65 29 2e 20 54 Data is true). T
1b240 68 65 79 20 61 72 65 0a 2a 2a 20 75 73 65 64 20 hey are.** used
1b250 74 6f 20 73 74 6f 72 65 20 74 68 65 20 73 65 74 to store the set
1b260 20 6f 66 20 74 61 62 6c 65 2d 6c 6f 63 6b 73 20 of table-locks
1b270 72 65 71 75 69 72 65 64 20 62 79 20 74 68 65 20 required by the
1b280 73 74 61 74 65 6d 65 6e 74 20 62 65 69 6e 67 0a statement being.
1b290 2a 2a 20 63 6f 6d 70 69 6c 65 64 2e 20 46 75 6e ** compiled. Fun
1b2a0 63 74 69 6f 6e 20 73 71 6c 69 74 65 33 54 61 62 ction sqlite3Tab
1b2b0 6c 65 4c 6f 63 6b 28 29 20 69 73 20 75 73 65 64 leLock() is used
1b2c0 20 74 6f 20 61 64 64 20 65 6e 74 72 69 65 73 20 to add entries
1b2d0 74 6f 20 74 68 65 0a 2a 2a 20 6c 69 73 74 2e 0a to the.** list..
1b2e0 2a 2f 0a 73 74 72 75 63 74 20 50 61 72 73 65 20 */.struct Parse
1b2f0 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b {. sqlite3 *db;
1b300 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
1b310 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 73 74 main database st
1b320 72 75 63 74 75 72 65 20 2a 2f 0a 20 20 63 68 61 ructure */. cha
1b330 72 20 2a 7a 45 72 72 4d 73 67 3b 20 20 20 20 20 r *zErrMsg;
1b340 20 20 2f 2a 20 41 6e 20 65 72 72 6f 72 20 6d 65 /* An error me
1b350 73 73 61 67 65 20 2a 2f 0a 20 20 56 64 62 65 20 ssage */. Vdbe
1b360 2a 70 56 64 62 65 3b 20 20 20 20 20 20 20 20 20 *pVdbe;
1b370 2f 2a 20 41 6e 20 65 6e 67 69 6e 65 20 66 6f 72 /* An engine for
1b380 20 65 78 65 63 75 74 69 6e 67 20 64 61 74 61 62 executing datab
1b390 61 73 65 20 62 79 74 65 63 6f 64 65 20 2a 2f 0a ase bytecode */.
1b3a0 20 20 69 6e 74 20 72 63 3b 20 20 20 20 20 20 20 int rc;
1b3b0 20 20 20 20 20 20 20 2f 2a 20 52 65 74 75 72 6e /* Return
1b3c0 20 63 6f 64 65 20 66 72 6f 6d 20 65 78 65 63 75 code from execu
1b3d0 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 63 6f 6c tion */. u8 col
1b3e0 4e 61 6d 65 73 53 65 74 3b 20 20 20 20 20 20 2f NamesSet; /
1b3f0 2a 20 54 52 55 45 20 61 66 74 65 72 20 4f 50 5f * TRUE after OP_
1b400 43 6f 6c 75 6d 6e 4e 61 6d 65 20 68 61 73 20 62 ColumnName has b
1b410 65 65 6e 20 69 73 73 75 65 64 20 74 6f 20 70 56 een issued to pV
1b420 64 62 65 20 2a 2f 0a 20 20 75 38 20 63 68 65 63 dbe */. u8 chec
1b430 6b 53 63 68 65 6d 61 3b 20 20 20 20 20 20 2f 2a kSchema; /*
1b440 20 43 61 75 73 65 73 20 73 63 68 65 6d 61 20 63 Causes schema c
1b450 6f 6f 6b 69 65 20 63 68 65 63 6b 20 61 66 74 65 ookie check afte
1b460 72 20 61 6e 20 65 72 72 6f 72 20 2a 2f 0a 20 20 r an error */.
1b470 75 38 20 6e 65 73 74 65 64 3b 20 20 20 20 20 20 u8 nested;
1b480 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1b490 66 20 6e 65 73 74 65 64 20 63 61 6c 6c 73 20 74 f nested calls t
1b4a0 6f 20 74 68 65 20 70 61 72 73 65 72 2f 63 6f 64 o the parser/cod
1b4b0 65 20 67 65 6e 65 72 61 74 6f 72 20 2a 2f 0a 20 e generator */.
1b4c0 20 75 38 20 6e 54 65 6d 70 52 65 67 3b 20 20 20 u8 nTempReg;
1b4d0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1b4e0 6f 66 20 74 65 6d 70 6f 72 61 72 79 20 72 65 67 of temporary reg
1b4f0 69 73 74 65 72 73 20 69 6e 20 61 54 65 6d 70 52 isters in aTempR
1b500 65 67 5b 5d 20 2a 2f 0a 20 20 75 38 20 69 73 4d eg[] */. u8 isM
1b510 75 6c 74 69 57 72 69 74 65 3b 20 20 20 20 20 2f ultiWrite; /
1b520 2a 20 54 72 75 65 20 69 66 20 73 74 61 74 65 6d * True if statem
1b530 65 6e 74 20 6d 61 79 20 6d 6f 64 69 66 79 2f 69 ent may modify/i
1b540 6e 73 65 72 74 20 6d 75 6c 74 69 70 6c 65 20 72 nsert multiple r
1b550 6f 77 73 20 2a 2f 0a 20 20 75 38 20 6d 61 79 41 ows */. u8 mayA
1b560 62 6f 72 74 3b 20 20 20 20 20 20 20 20 20 2f 2a bort; /*
1b570 20 54 72 75 65 20 69 66 20 73 74 61 74 65 6d 65 True if stateme
1b580 6e 74 20 6d 61 79 20 74 68 72 6f 77 20 61 6e 20 nt may throw an
1b590 41 42 4f 52 54 20 65 78 63 65 70 74 69 6f 6e 20 ABORT exception
1b5a0 2a 2f 0a 20 20 75 38 20 68 61 73 43 6f 6d 70 6f */. u8 hasCompo
1b5b0 75 6e 64 3b 20 20 20 20 20 20 2f 2a 20 4e 65 65 und; /* Nee
1b5c0 64 20 74 6f 20 69 6e 76 6f 6b 65 20 63 6f 6e 76 d to invoke conv
1b5d0 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 ertCompoundSelec
1b5e0 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a 2f tToSubquery() */
1b5f0 0a 20 20 75 38 20 6f 6b 43 6f 6e 73 74 46 61 63 . u8 okConstFac
1b600 74 6f 72 3b 20 20 20 20 2f 2a 20 4f 4b 20 74 6f tor; /* OK to
1b610 20 66 61 63 74 6f 72 20 6f 75 74 20 63 6f 6e 73 factor out cons
1b620 74 61 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 61 tants */. int a
1b630 54 65 6d 70 52 65 67 5b 38 5d 3b 20 20 20 20 20 TempReg[8];
1b640 2f 2a 20 48 6f 6c 64 69 6e 67 20 61 72 65 61 20 /* Holding area
1b650 66 6f 72 20 74 65 6d 70 6f 72 61 72 79 20 72 65 for temporary re
1b660 67 69 73 74 65 72 73 20 2a 2f 0a 20 20 69 6e 74 gisters */. int
1b670 20 6e 52 61 6e 67 65 52 65 67 3b 20 20 20 20 20 nRangeReg;
1b680 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 /* Size of the
1b690 20 74 65 6d 70 6f 72 61 72 79 20 72 65 67 69 73 temporary regis
1b6a0 74 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 ter block */. i
1b6b0 6e 74 20 69 52 61 6e 67 65 52 65 67 3b 20 20 20 nt iRangeReg;
1b6c0 20 20 20 20 2f 2a 20 46 69 72 73 74 20 72 65 67 /* First reg
1b6d0 69 73 74 65 72 20 69 6e 20 74 65 6d 70 6f 72 61 ister in tempora
1b6e0 72 79 20 72 65 67 69 73 74 65 72 20 62 6c 6f 63 ry register bloc
1b6f0 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b k */. int nErr;
1b700 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
1b710 75 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 20 umber of errors
1b720 73 65 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 seen */. int nT
1b730 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ab; /
1b740 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 72 65 76 * Number of prev
1b750 69 6f 75 73 6c 79 20 61 6c 6c 6f 63 61 74 65 64 iously allocated
1b760 20 56 44 42 45 20 63 75 72 73 6f 72 73 20 2a 2f VDBE cursors */
1b770 0a 20 20 69 6e 74 20 6e 4d 65 6d 3b 20 20 20 20 . int nMem;
1b780 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1b790 72 20 6f 66 20 6d 65 6d 6f 72 79 20 63 65 6c 6c r of memory cell
1b7a0 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f s used so far */
1b7b0 0a 20 20 69 6e 74 20 6e 53 65 74 3b 20 20 20 20 . int nSet;
1b7c0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1b7d0 72 20 6f 66 20 73 65 74 73 20 75 73 65 64 20 73 r of sets used s
1b7e0 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 20 6e o far */. int n
1b7f0 4f 6e 63 65 3b 20 20 20 20 20 20 20 20 20 20 20 Once;
1b800 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 4f 50 5f /* Number of OP_
1b810 4f 6e 63 65 20 69 6e 73 74 72 75 63 74 69 6f 6e Once instruction
1b820 73 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e s so far */. in
1b830 74 20 6e 4f 70 41 6c 6c 6f 63 3b 20 20 20 20 20 t nOpAlloc;
1b840 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1b850 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 74 65 64 20 slots allocated
1b860 66 6f 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 2a for Vdbe.aOp[] *
1b870 2f 0a 20 20 69 6e 74 20 69 46 69 78 65 64 4f 70 /. int iFixedOp
1b880 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 76 65 ; /* Neve
1b890 72 20 62 61 63 6b 20 6f 75 74 20 6f 70 63 6f 64 r back out opcod
1b8a0 65 73 20 69 46 69 78 65 64 4f 70 2d 31 20 6f 72 es iFixedOp-1 or
1b8b0 20 65 61 72 6c 69 65 72 20 2a 2f 0a 20 20 69 6e earlier */. in
1b8c0 74 20 63 6b 42 61 73 65 3b 20 20 20 20 20 20 20 t ckBase;
1b8d0 20 20 20 2f 2a 20 42 61 73 65 20 72 65 67 69 73 /* Base regis
1b8e0 74 65 72 20 6f 66 20 64 61 74 61 20 64 75 72 69 ter of data duri
1b8f0 6e 67 20 63 68 65 63 6b 20 63 6f 6e 73 74 72 61 ng check constra
1b900 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 69 50 ints */. int iP
1b910 61 72 74 49 64 78 54 61 62 3b 20 20 20 20 20 2f artIdxTab; /
1b920 2a 20 54 61 62 6c 65 20 63 6f 72 72 65 73 70 6f * Table correspo
1b930 6e 64 69 6e 67 20 74 6f 20 61 20 70 61 72 74 69 nding to a parti
1b940 61 6c 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e al index */. in
1b950 74 20 69 43 61 63 68 65 4c 65 76 65 6c 3b 20 20 t iCacheLevel;
1b960 20 20 20 2f 2a 20 43 6f 6c 43 61 63 68 65 20 76 /* ColCache v
1b970 61 6c 69 64 20 77 68 65 6e 20 61 43 6f 6c 43 61 alid when aColCa
1b980 63 68 65 5b 5d 2e 69 4c 65 76 65 6c 3c 3d 69 43 che[].iLevel<=iC
1b990 61 63 68 65 4c 65 76 65 6c 20 2a 2f 0a 20 20 69 acheLevel */. i
1b9a0 6e 74 20 69 43 61 63 68 65 43 6e 74 3b 20 20 20 nt iCacheCnt;
1b9b0 20 20 20 20 2f 2a 20 43 6f 75 6e 74 65 72 20 75 /* Counter u
1b9c0 73 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 sed to generate
1b9d0 61 43 6f 6c 43 61 63 68 65 5b 5d 2e 6c 72 75 20 aColCache[].lru
1b9e0 76 61 6c 75 65 73 20 2a 2f 0a 20 20 69 6e 74 20 values */. int
1b9f0 6e 4c 61 62 65 6c 3b 20 20 20 20 20 20 20 20 20 nLabel;
1ba00 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c 61 /* Number of la
1ba10 62 65 6c 73 20 75 73 65 64 20 2a 2f 0a 20 20 69 bels used */. i
1ba20 6e 74 20 2a 61 4c 61 62 65 6c 3b 20 20 20 20 20 nt *aLabel;
1ba30 20 20 20 20 2f 2a 20 53 70 61 63 65 20 74 6f 20 /* Space to
1ba40 68 6f 6c 64 20 74 68 65 20 6c 61 62 65 6c 73 20 hold the labels
1ba50 2a 2f 0a 20 20 73 74 72 75 63 74 20 79 43 6f 6c */. struct yCol
1ba60 43 61 63 68 65 20 7b 0a 20 20 20 20 69 6e 74 20 Cache {. int
1ba70 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 iTable;
1ba80 20 20 2f 2a 20 54 61 62 6c 65 20 63 75 72 73 6f /* Table curso
1ba90 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 20 20 r number */.
1baa0 69 31 36 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 i16 iColumn;
1bab0 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 63 /* Table c
1bac0 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 2a 2f 0a olumn number */.
1bad0 20 20 20 20 75 38 20 74 65 6d 70 52 65 67 3b 20 u8 tempReg;
1bae0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 52 65 /* iRe
1baf0 67 20 69 73 20 61 20 74 65 6d 70 20 72 65 67 69 g is a temp regi
1bb00 73 74 65 72 20 74 68 61 74 20 6e 65 65 64 73 20 ster that needs
1bb10 74 6f 20 62 65 20 66 72 65 65 64 20 2a 2f 0a 20 to be freed */.
1bb20 20 20 20 69 6e 74 20 69 4c 65 76 65 6c 3b 20 20 int iLevel;
1bb30 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 73 74 /* Nest
1bb40 69 6e 67 20 6c 65 76 65 6c 20 2a 2f 0a 20 20 20 ing level */.
1bb50 20 69 6e 74 20 69 52 65 67 3b 20 20 20 20 20 20 int iReg;
1bb60 20 20 20 20 20 20 20 2f 2a 20 52 65 67 20 77 69 /* Reg wi
1bb70 74 68 20 76 61 6c 75 65 20 6f 66 20 74 68 69 73 th value of this
1bb80 20 63 6f 6c 75 6d 6e 2e 20 30 20 6d 65 61 6e 73 column. 0 means
1bb90 20 6e 6f 6e 65 2e 20 2a 2f 0a 20 20 20 20 69 6e none. */. in
1bba0 74 20 6c 72 75 3b 20 20 20 20 20 20 20 20 20 20 t lru;
1bbb0 20 20 20 20 2f 2a 20 4c 65 61 73 74 20 72 65 63 /* Least rec
1bbc0 65 6e 74 6c 79 20 75 73 65 64 20 65 6e 74 72 79 ently used entry
1bbd0 20 68 61 73 20 74 68 65 20 73 6d 61 6c 6c 65 73 has the smalles
1bbe0 74 20 76 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 61 t value */. } a
1bbf0 43 6f 6c 43 61 63 68 65 5b 53 51 4c 49 54 45 5f ColCache[SQLITE_
1bc00 4e 5f 43 4f 4c 43 41 43 48 45 5d 3b 20 20 2f 2a N_COLCACHE]; /*
1bc10 20 4f 6e 65 20 66 6f 72 20 65 61 63 68 20 63 6f One for each co
1bc20 6c 75 6d 6e 20 63 61 63 68 65 20 65 6e 74 72 79 lumn cache entry
1bc30 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1bc40 70 43 6f 6e 73 74 45 78 70 72 3b 2f 2a 20 43 6f pConstExpr;/* Co
1bc50 6e 73 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f nstant expressio
1bc60 6e 73 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 63 6f ns */. Token co
1bc70 6e 73 74 72 61 69 6e 74 4e 61 6d 65 3b 2f 2a 20 nstraintName;/*
1bc80 4e 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6e 73 Name of the cons
1bc90 74 72 61 69 6e 74 20 63 75 72 72 65 6e 74 6c 79 traint currently
1bca0 20 62 65 69 6e 67 20 70 61 72 73 65 64 20 2a 2f being parsed */
1bcb0 0a 20 20 79 44 62 4d 61 73 6b 20 77 72 69 74 65 . yDbMask write
1bcc0 4d 61 73 6b 3b 20 20 20 2f 2a 20 53 74 61 72 74 Mask; /* Start
1bcd0 20 61 20 77 72 69 74 65 20 74 72 61 6e 73 61 63 a write transac
1bce0 74 69 6f 6e 20 6f 6e 20 74 68 65 73 65 20 64 61 tion on these da
1bcf0 74 61 62 61 73 65 73 20 2a 2f 0a 20 20 79 44 62 tabases */. yDb
1bd00 4d 61 73 6b 20 63 6f 6f 6b 69 65 4d 61 73 6b 3b Mask cookieMask;
1bd10 20 20 2f 2a 20 42 69 74 6d 61 73 6b 20 6f 66 20 /* Bitmask of
1bd20 73 63 68 65 6d 61 20 76 65 72 69 66 69 65 64 20 schema verified
1bd30 64 61 74 61 62 61 73 65 73 20 2a 2f 0a 20 20 69 databases */. i
1bd40 6e 74 20 63 6f 6f 6b 69 65 56 61 6c 75 65 5b 53 nt cookieValue[S
1bd50 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 QLITE_MAX_ATTACH
1bd60 45 44 2b 32 5d 3b 20 20 2f 2a 20 56 61 6c 75 65 ED+2]; /* Value
1bd70 73 20 6f 66 20 63 6f 6f 6b 69 65 73 20 74 6f 20 s of cookies to
1bd80 76 65 72 69 66 79 20 2a 2f 0a 20 20 69 6e 74 20 verify */. int
1bd90 72 65 67 52 6f 77 69 64 3b 20 20 20 20 20 20 20 regRowid;
1bda0 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 6f 6c /* Register hol
1bdb0 64 69 6e 67 20 72 6f 77 69 64 20 6f 66 20 43 52 ding rowid of CR
1bdc0 45 41 54 45 20 54 41 42 4c 45 20 65 6e 74 72 79 EATE TABLE entry
1bdd0 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 52 6f 6f */. int regRoo
1bde0 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 t; /* Re
1bdf0 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 gister holding r
1be00 6f 6f 74 20 70 61 67 65 20 6e 75 6d 62 65 72 20 oot page number
1be10 66 6f 72 20 6e 65 77 20 6f 62 6a 65 63 74 73 20 for new objects
1be20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 78 41 72 67 */. int nMaxArg
1be30 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 ; /* Max
1be40 20 61 72 67 73 20 70 61 73 73 65 64 20 74 6f 20 args passed to
1be50 75 73 65 72 20 66 75 6e 63 74 69 6f 6e 20 62 79 user function by
1be60 20 73 75 62 2d 70 72 6f 67 72 61 6d 20 2a 2f 0a sub-program */.
1be70 23 69 66 20 53 45 4c 45 43 54 54 52 41 43 45 5f #if SELECTTRACE_
1be80 45 4e 41 42 4c 45 44 0a 20 20 69 6e 74 20 6e 53 ENABLED. int nS
1be90 65 6c 65 63 74 3b 20 20 20 20 20 20 20 20 20 2f elect; /
1bea0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 53 45 4c 45 * Number of SELE
1beb0 43 54 20 73 74 61 74 65 6d 65 6e 74 73 20 73 65 CT statements se
1bec0 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 65 6c en */. int nSel
1bed0 65 63 74 49 6e 64 65 6e 74 3b 20 20 20 2f 2a 20 ectIndent; /*
1bee0 48 6f 77 20 66 61 72 20 74 6f 20 69 6e 64 65 6e How far to inden
1bef0 74 20 53 45 4c 45 43 54 54 52 41 43 45 28 29 20 t SELECTTRACE()
1bf00 6f 75 74 70 75 74 20 2a 2f 0a 23 65 6e 64 69 66 output */.#endif
1bf10 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
1bf20 4f 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 OMIT_SHARED_CACH
1bf30 45 0a 20 20 69 6e 74 20 6e 54 61 62 6c 65 4c 6f E. int nTableLo
1bf40 63 6b 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ck; /* Nu
1bf50 6d 62 65 72 20 6f 66 20 6c 6f 63 6b 73 20 69 6e mber of locks in
1bf60 20 61 54 61 62 6c 65 4c 6f 63 6b 20 2a 2f 0a 20 aTableLock */.
1bf70 20 54 61 62 6c 65 4c 6f 63 6b 20 2a 61 54 61 62 TableLock *aTab
1bf80 6c 65 4c 6f 63 6b 3b 20 2f 2a 20 52 65 71 75 69 leLock; /* Requi
1bf90 72 65 64 20 74 61 62 6c 65 20 6c 6f 63 6b 73 20 red table locks
1bfa0 66 6f 72 20 73 68 61 72 65 64 2d 63 61 63 68 65 for shared-cache
1bfb0 20 6d 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a mode */.#endif.
1bfc0 20 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 AutoincInfo *p
1bfd0 41 69 6e 63 3b 20 20 2f 2a 20 49 6e 66 6f 72 6d Ainc; /* Inform
1bfe0 61 74 69 6f 6e 20 61 62 6f 75 74 20 41 55 54 4f ation about AUTO
1bff0 49 4e 43 52 45 4d 45 4e 54 20 63 6f 75 6e 74 65 INCREMENT counte
1c000 72 73 20 2a 2f 0a 0a 20 20 2f 2a 20 49 6e 66 6f rs */.. /* Info
1c010 72 6d 61 74 69 6f 6e 20 75 73 65 64 20 77 68 69 rmation used whi
1c020 6c 65 20 63 6f 64 69 6e 67 20 74 72 69 67 67 65 le coding trigge
1c030 72 20 70 72 6f 67 72 61 6d 73 2e 20 2a 2f 0a 20 r programs. */.
1c040 20 50 61 72 73 65 20 2a 70 54 6f 70 6c 65 76 65 Parse *pTopleve
1c050 6c 3b 20 20 20 20 2f 2a 20 50 61 72 73 65 20 73 l; /* Parse s
1c060 74 72 75 63 74 75 72 65 20 66 6f 72 20 6d 61 69 tructure for mai
1c070 6e 20 70 72 6f 67 72 61 6d 20 28 6f 72 20 4e 55 n program (or NU
1c080 4c 4c 29 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a LL) */. Table *
1c090 70 54 72 69 67 67 65 72 54 61 62 3b 20 20 2f 2a pTriggerTab; /*
1c0a0 20 54 61 62 6c 65 20 74 72 69 67 67 65 72 73 20 Table triggers
1c0b0 61 72 65 20 62 65 69 6e 67 20 63 6f 64 65 64 20 are being coded
1c0c0 66 6f 72 20 2a 2f 0a 20 20 69 6e 74 20 61 64 64 for */. int add
1c0d0 72 43 72 54 61 62 3b 20 20 20 20 20 20 20 2f 2a rCrTab; /*
1c0e0 20 41 64 64 72 65 73 73 20 6f 66 20 4f 50 5f 43 Address of OP_C
1c0f0 72 65 61 74 65 54 61 62 6c 65 20 6f 70 63 6f 64 reateTable opcod
1c100 65 20 6f 6e 20 43 52 45 41 54 45 20 54 41 42 4c e on CREATE TABL
1c110 45 20 2a 2f 0a 20 20 69 6e 74 20 61 64 64 72 53 E */. int addrS
1c120 6b 69 70 50 4b 3b 20 20 20 20 20 20 2f 2a 20 41 kipPK; /* A
1c130 64 64 72 65 73 73 20 6f 66 20 69 6e 73 74 72 75 ddress of instru
1c140 63 74 69 6f 6e 20 74 6f 20 73 6b 69 70 20 50 52 ction to skip PR
1c150 49 4d 41 52 59 20 4b 45 59 20 69 6e 64 65 78 20 IMARY KEY index
1c160 2a 2f 0a 20 20 75 33 32 20 6e 51 75 65 72 79 4c */. u32 nQueryL
1c170 6f 6f 70 3b 20 20 20 20 20 20 2f 2a 20 45 73 74 oop; /* Est
1c180 20 6e 75 6d 62 65 72 20 6f 66 20 69 74 65 72 61 number of itera
1c190 74 69 6f 6e 73 20 6f 66 20 61 20 71 75 65 72 79 tions of a query
1c1a0 20 28 31 30 2a 6c 6f 67 32 28 4e 29 29 20 2a 2f (10*log2(N)) */
1c1b0 0a 20 20 75 33 32 20 6f 6c 64 6d 61 73 6b 3b 20 . u32 oldmask;
1c1c0 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 73 6b 20 /* Mask
1c1d0 6f 66 20 6f 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 of old.* columns
1c1e0 20 72 65 66 65 72 65 6e 63 65 64 20 2a 2f 0a 20 referenced */.
1c1f0 20 75 33 32 20 6e 65 77 6d 61 73 6b 3b 20 20 20 u32 newmask;
1c200 20 20 20 20 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 /* Mask of
1c210 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 new.* columns r
1c220 65 66 65 72 65 6e 63 65 64 20 2a 2f 0a 20 20 75 eferenced */. u
1c230 38 20 65 54 72 69 67 67 65 72 4f 70 3b 20 20 20 8 eTriggerOp;
1c240 20 20 20 20 2f 2a 20 54 4b 5f 55 50 44 41 54 45 /* TK_UPDATE
1c250 2c 20 54 4b 5f 49 4e 53 45 52 54 20 6f 72 20 54 , TK_INSERT or T
1c260 4b 5f 44 45 4c 45 54 45 20 2a 2f 0a 20 20 75 38 K_DELETE */. u8
1c270 20 65 4f 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 eOrconf;
1c280 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 4f 4e /* Default ON
1c290 20 43 4f 4e 46 4c 49 43 54 20 70 6f 6c 69 63 79 CONFLICT policy
1c2a0 20 66 6f 72 20 74 72 69 67 67 65 72 20 73 74 65 for trigger ste
1c2b0 70 73 20 2a 2f 0a 20 20 75 38 20 64 69 73 61 62 ps */. u8 disab
1c2c0 6c 65 54 72 69 67 67 65 72 73 3b 20 20 2f 2a 20 leTriggers; /*
1c2d0 54 72 75 65 20 74 6f 20 64 69 73 61 62 6c 65 20 True to disable
1c2e0 74 72 69 67 67 65 72 73 20 2a 2f 0a 0a 20 20 2f triggers */.. /
1c2f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c300 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c310 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c320 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c330 2a 2a 2a 2a 2a 2a 2a 2a 0a 20 20 2a 2a 20 41 62 ********. ** Ab
1c340 6f 76 65 20 69 73 20 63 6f 6e 73 74 61 6e 74 20 ove is constant
1c350 62 65 74 77 65 65 6e 20 72 65 63 75 72 73 69 6f between recursio
1c360 6e 73 2e 20 20 42 65 6c 6f 77 20 69 73 20 72 65 ns. Below is re
1c370 73 65 74 20 62 65 66 6f 72 65 20 61 6e 64 20 61 set before and a
1c380 66 74 65 72 0a 20 20 2a 2a 20 65 61 63 68 20 72 fter. ** each r
1c390 65 63 75 72 73 69 6f 6e 2e 20 20 54 68 65 20 62 ecursion. The b
1c3a0 6f 75 6e 64 61 72 79 20 62 65 74 77 65 65 6e 20 oundary between
1c3b0 74 68 65 73 65 20 74 77 6f 20 72 65 67 69 6f 6e these two region
1c3c0 73 20 69 73 20 64 65 74 65 72 6d 69 6e 65 64 0a s is determined.
1c3d0 20 20 2a 2a 20 75 73 69 6e 67 20 6f 66 66 73 65 ** using offse
1c3e0 74 6f 66 28 50 61 72 73 65 2c 6e 56 61 72 29 20 tof(Parse,nVar)
1c3f0 73 6f 20 74 68 65 20 6e 56 61 72 20 66 69 65 6c so the nVar fiel
1c400 64 20 6d 75 73 74 20 62 65 20 74 68 65 20 66 69 d must be the fi
1c410 72 73 74 20 66 69 65 6c 64 0a 20 20 2a 2a 20 69 rst field. ** i
1c420 6e 20 74 68 65 20 72 65 63 75 72 73 69 76 65 20 n the recursive
1c430 72 65 67 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a region.. ******
1c440 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c450 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c460 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c470 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c480 2a 2a 2f 0a 0a 20 20 69 6e 74 20 6e 56 61 72 3b **/.. int nVar;
1c490 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c4a0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 27 3f /* Number of '?
1c4b0 27 20 76 61 72 69 61 62 6c 65 73 20 73 65 65 6e ' variables seen
1c4c0 20 69 6e 20 74 68 65 20 53 51 4c 20 73 6f 20 66 in the SQL so f
1c4d0 61 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 7a 56 61 ar */. int nzVa
1c4e0 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
1c4f0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 /* Number of a
1c500 76 61 69 6c 61 62 6c 65 20 73 6c 6f 74 73 20 69 vailable slots i
1c510 6e 20 61 7a 56 61 72 5b 5d 20 2a 2f 0a 20 20 75 n azVar[] */. u
1c520 38 20 69 50 6b 53 6f 72 74 4f 72 64 65 72 3b 20 8 iPkSortOrder;
1c530 20 20 20 20 20 20 20 20 20 2f 2a 20 41 53 43 20 /* ASC
1c540 6f 72 20 44 45 53 43 20 66 6f 72 20 49 4e 54 45 or DESC for INTE
1c550 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 GER PRIMARY KEY
1c560 2a 2f 0a 20 20 75 38 20 62 46 72 65 65 57 69 74 */. u8 bFreeWit
1c570 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f h; /
1c580 2a 20 54 72 75 65 20 69 66 20 70 57 69 74 68 20 * True if pWith
1c590 73 68 6f 75 6c 64 20 62 65 20 66 72 65 65 64 20 should be freed
1c5a0 77 69 74 68 20 70 61 72 73 65 72 20 2a 2f 0a 20 with parser */.
1c5b0 20 75 38 20 65 78 70 6c 61 69 6e 3b 20 20 20 20 u8 explain;
1c5c0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1c5d0 75 65 20 69 66 20 74 68 65 20 45 58 50 4c 41 49 ue if the EXPLAI
1c5e0 4e 20 66 6c 61 67 20 69 73 20 66 6f 75 6e 64 20 N flag is found
1c5f0 6f 6e 20 74 68 65 20 71 75 65 72 79 20 2a 2f 0a on the query */.
1c600 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1c610 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
1c620 0a 20 20 75 38 20 64 65 63 6c 61 72 65 56 74 61 . u8 declareVta
1c630 62 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 b; /*
1c640 54 72 75 65 20 69 66 20 69 6e 73 69 64 65 20 73 True if inside s
1c650 71 6c 69 74 65 33 5f 64 65 63 6c 61 72 65 5f 76 qlite3_declare_v
1c660 74 61 62 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e tab() */. int n
1c670 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 20 20 VtabLock;
1c680 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1c690 66 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 f virtual tables
1c6a0 20 74 6f 20 6c 6f 63 6b 20 2a 2f 0a 23 65 6e 64 to lock */.#end
1c6b0 69 66 0a 20 20 69 6e 74 20 6e 41 6c 69 61 73 3b if. int nAlias;
1c6c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1c6d0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 6c 69 61 * Number of alia
1c6e0 73 65 64 20 72 65 73 75 6c 74 20 73 65 74 20 63 sed result set c
1c6f0 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 olumns */. int
1c700 6e 48 65 69 67 68 74 3b 20 20 20 20 20 20 20 20 nHeight;
1c710 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 73 /* Express
1c720 69 6f 6e 20 74 72 65 65 20 68 65 69 67 68 74 20 ion tree height
1c730 6f 66 20 63 75 72 72 65 6e 74 20 73 75 62 2d 73 of current sub-s
1c740 65 6c 65 63 74 20 2a 2f 0a 23 69 66 6e 64 65 66 elect */.#ifndef
1c750 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 45 58 50 SQLITE_OMIT_EXP
1c760 4c 41 49 4e 0a 20 20 69 6e 74 20 69 53 65 6c 65 LAIN. int iSele
1c770 63 74 49 64 3b 20 20 20 20 20 20 20 20 20 20 20 ctId;
1c780 20 2f 2a 20 49 44 20 6f 66 20 63 75 72 72 65 6e /* ID of curren
1c790 74 20 73 65 6c 65 63 74 20 66 6f 72 20 45 58 50 t select for EXP
1c7a0 4c 41 49 4e 20 6f 75 74 70 75 74 20 2a 2f 0a 20 LAIN output */.
1c7b0 20 69 6e 74 20 69 4e 65 78 74 53 65 6c 65 63 74 int iNextSelect
1c7c0 49 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 Id; /* Ne
1c7d0 78 74 20 61 76 61 69 6c 61 62 6c 65 20 73 65 6c xt available sel
1c7e0 65 63 74 20 49 44 20 66 6f 72 20 45 58 50 4c 41 ect ID for EXPLA
1c7f0 49 4e 20 6f 75 74 70 75 74 20 2a 2f 0a 23 65 6e IN output */.#en
1c800 64 69 66 0a 20 20 63 68 61 72 20 2a 2a 61 7a 56 dif. char **azV
1c810 61 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ar;
1c820 2f 2a 20 50 6f 69 6e 74 65 72 73 20 74 6f 20 6e /* Pointers to n
1c830 61 6d 65 73 20 6f 66 20 70 61 72 61 6d 65 74 65 ames of paramete
1c840 72 73 20 2a 2f 0a 20 20 56 64 62 65 20 2a 70 52 rs */. Vdbe *pR
1c850 65 70 72 65 70 61 72 65 3b 20 20 20 20 20 20 20 eprepare;
1c860 20 20 2f 2a 20 56 4d 20 62 65 69 6e 67 20 72 65 /* VM being re
1c870 70 72 65 70 61 72 65 64 20 28 73 71 6c 69 74 65 prepared (sqlite
1c880 33 52 65 70 72 65 70 61 72 65 28 29 29 20 2a 2f 3Reprepare()) */
1c890 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
1c8a0 54 61 69 6c 3b 20 20 20 20 20 20 20 20 2f 2a 20 Tail; /*
1c8b0 41 6c 6c 20 53 51 4c 20 74 65 78 74 20 70 61 73 All SQL text pas
1c8c0 74 20 74 68 65 20 6c 61 73 74 20 73 65 6d 69 63 t the last semic
1c8d0 6f 6c 6f 6e 20 70 61 72 73 65 64 20 2a 2f 0a 20 olon parsed */.
1c8e0 20 54 61 62 6c 65 20 2a 70 4e 65 77 54 61 62 6c Table *pNewTabl
1c8f0 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 e; /* A
1c900 74 61 62 6c 65 20 62 65 69 6e 67 20 63 6f 6e 73 table being cons
1c910 74 72 75 63 74 65 64 20 62 79 20 43 52 45 41 54 tructed by CREAT
1c920 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 54 72 69 E TABLE */. Tri
1c930 67 67 65 72 20 2a 70 4e 65 77 54 72 69 67 67 65 gger *pNewTrigge
1c940 72 3b 20 20 20 20 20 2f 2a 20 54 72 69 67 67 65 r; /* Trigge
1c950 72 20 75 6e 64 65 72 20 63 6f 6e 73 74 72 75 63 r under construc
1c960 74 20 62 79 20 61 20 43 52 45 41 54 45 20 54 52 t by a CREATE TR
1c970 49 47 47 45 52 20 2a 2f 0a 20 20 63 6f 6e 73 74 IGGER */. const
1c980 20 63 68 61 72 20 2a 7a 41 75 74 68 43 6f 6e 74 char *zAuthCont
1c990 65 78 74 3b 20 2f 2a 20 54 68 65 20 36 74 68 20 ext; /* The 6th
1c9a0 70 61 72 61 6d 65 74 65 72 20 74 6f 20 64 62 2d parameter to db-
1c9b0 3e 78 41 75 74 68 20 63 61 6c 6c 62 61 63 6b 73 >xAuth callbacks
1c9c0 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 73 4e 61 6d */. Token sNam
1c9d0 65 54 6f 6b 65 6e 3b 20 20 20 20 20 20 20 20 20 eToken;
1c9e0 2f 2a 20 54 6f 6b 65 6e 20 77 69 74 68 20 75 6e /* Token with un
1c9f0 71 75 61 6c 69 66 69 65 64 20 73 63 68 65 6d 61 qualified schema
1ca00 20 6f 62 6a 65 63 74 20 6e 61 6d 65 20 2a 2f 0a object name */.
1ca10 20 20 54 6f 6b 65 6e 20 73 4c 61 73 74 54 6f 6b Token sLastTok
1ca20 65 6e 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 en; /* T
1ca30 68 65 20 6c 61 73 74 20 74 6f 6b 65 6e 20 70 61 he last token pa
1ca40 72 73 65 64 20 2a 2f 0a 23 69 66 6e 64 65 66 20 rsed */.#ifndef
1ca50 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
1ca60 55 41 4c 54 41 42 4c 45 0a 20 20 54 6f 6b 65 6e UALTABLE. Token
1ca70 20 73 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 sArg;
1ca80 20 20 20 20 20 2f 2a 20 43 6f 6d 70 6c 65 74 65 /* Complete
1ca90 20 74 65 78 74 20 6f 66 20 61 20 6d 6f 64 75 6c text of a modul
1caa0 65 20 61 72 67 75 6d 65 6e 74 20 2a 2f 0a 20 20 e argument */.
1cab0 54 61 62 6c 65 20 2a 2a 61 70 56 74 61 62 4c 6f Table **apVtabLo
1cac0 63 6b 3b 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 ck; /* Poi
1cad0 6e 74 65 72 20 74 6f 20 76 69 72 74 75 61 6c 20 nter to virtual
1cae0 74 61 62 6c 65 73 20 6e 65 65 64 69 6e 67 20 6c tables needing l
1caf0 6f 63 6b 69 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 ocking */.#endif
1cb00 0a 20 20 54 61 62 6c 65 20 2a 70 5a 6f 6d 62 69 . Table *pZombi
1cb10 65 54 61 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 eTab; /*
1cb20 4c 69 73 74 20 6f 66 20 54 61 62 6c 65 20 6f 62 List of Table ob
1cb30 6a 65 63 74 73 20 74 6f 20 64 65 6c 65 74 65 20 jects to delete
1cb40 61 66 74 65 72 20 63 6f 64 65 20 67 65 6e 20 2a after code gen *
1cb50 2f 0a 20 20 54 72 69 67 67 65 72 50 72 67 20 2a /. TriggerPrg *
1cb60 70 54 72 69 67 67 65 72 50 72 67 3b 20 20 2f 2a pTriggerPrg; /*
1cb70 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 Linked list of
1cb80 63 6f 64 65 64 20 74 72 69 67 67 65 72 73 20 2a coded triggers *
1cb90 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 74 68 3b /. With *pWith;
1cba0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1cbb0 20 43 75 72 72 65 6e 74 20 57 49 54 48 20 63 6c Current WITH cl
1cbc0 61 75 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f ause, or NULL */
1cbd0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 .};../*.** Retur
1cbe0 6e 20 74 72 75 65 20 69 66 20 63 75 72 72 65 6e n true if curren
1cbf0 74 6c 79 20 69 6e 73 69 64 65 20 61 6e 20 73 71 tly inside an sq
1cc00 6c 69 74 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 lite3_declare_vt
1cc10 61 62 28 29 20 63 61 6c 6c 2e 0a 2a 2f 0a 23 69 ab() call..*/.#i
1cc20 66 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fdef SQLITE_OMIT
1cc30 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 _VIRTUALTABLE.
1cc40 23 64 65 66 69 6e 65 20 49 4e 5f 44 45 43 4c 41 #define IN_DECLA
1cc50 52 45 5f 56 54 41 42 20 30 0a 23 65 6c 73 65 0a RE_VTAB 0.#else.
1cc60 20 20 23 64 65 66 69 6e 65 20 49 4e 5f 44 45 43 #define IN_DEC
1cc70 4c 41 52 45 5f 56 54 41 42 20 28 70 50 61 72 73 LARE_VTAB (pPars
1cc80 65 2d 3e 64 65 63 6c 61 72 65 56 74 61 62 29 0a e->declareVtab).
1cc90 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e #endif../*.** An
1cca0 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
1ccb0 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
1ccc0 74 75 72 65 20 63 61 6e 20 62 65 20 64 65 63 6c ture can be decl
1ccd0 61 72 65 64 20 6f 6e 20 61 20 73 74 61 63 6b 20 ared on a stack
1cce0 61 6e 64 20 75 73 65 64 0a 2a 2a 20 74 6f 20 73 and used.** to s
1ccf0 61 76 65 20 74 68 65 20 50 61 72 73 65 2e 7a 41 ave the Parse.zA
1cd00 75 74 68 43 6f 6e 74 65 78 74 20 76 61 6c 75 65 uthContext value
1cd10 20 73 6f 20 74 68 61 74 20 69 74 20 63 61 6e 20 so that it can
1cd20 62 65 20 72 65 73 74 6f 72 65 64 20 6c 61 74 65 be restored late
1cd30 72 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 75 74 r..*/.struct Aut
1cd40 68 43 6f 6e 74 65 78 74 20 7b 0a 20 20 63 6f 6e hContext {. con
1cd50 73 74 20 63 68 61 72 20 2a 7a 41 75 74 68 43 6f st char *zAuthCo
1cd60 6e 74 65 78 74 3b 20 20 20 2f 2a 20 50 75 74 20 ntext; /* Put
1cd70 73 61 76 65 64 20 50 61 72 73 65 2e 7a 41 75 74 saved Parse.zAut
1cd80 68 43 6f 6e 74 65 78 74 20 68 65 72 65 20 2a 2f hContext here */
1cd90 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 73 65 . Parse *pParse
1cda0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
1cdb0 2a 20 54 68 65 20 50 61 72 73 65 20 73 74 72 75 * The Parse stru
1cdc0 63 74 75 72 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a cture */.};../*.
1cdd0 2a 2a 20 42 69 74 66 69 65 6c 64 20 66 6c 61 67 ** Bitfield flag
1cde0 73 20 66 6f 72 20 50 35 20 76 61 6c 75 65 20 69 s for P5 value i
1cdf0 6e 20 76 61 72 69 6f 75 73 20 6f 70 63 6f 64 65 n various opcode
1ce00 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 s..*/.#define OP
1ce10 46 4c 41 47 5f 4e 43 48 41 4e 47 45 20 20 20 20 FLAG_NCHANGE
1ce20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 53 65 0x01 /* Se
1ce30 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 2d 3e t to update db->
1ce40 6e 43 68 61 6e 67 65 20 2a 2f 0a 23 64 65 66 69 nChange */.#defi
1ce50 6e 65 20 4f 50 46 4c 41 47 5f 45 50 48 45 4d 20 ne OPFLAG_EPHEM
1ce60 20 20 20 20 20 20 20 20 30 78 30 31 20 20 20 20 0x01
1ce70 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 3a 20 45 70 /* OP_Column: Ep
1ce80 68 65 6d 65 72 61 6c 20 6f 75 74 70 75 74 20 69 hemeral output i
1ce90 73 20 6f 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 s ok */.#define
1cea0 4f 50 46 4c 41 47 5f 4c 41 53 54 52 4f 57 49 44 OPFLAG_LASTROWID
1ceb0 20 20 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 0x02 /*
1cec0 53 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 Set to update db
1ced0 2d 3e 6c 61 73 74 52 6f 77 69 64 20 2a 2f 0a 23 ->lastRowid */.#
1cee0 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 49 53 define OPFLAG_IS
1cef0 55 50 44 41 54 45 20 20 20 20 20 20 30 78 30 34 UPDATE 0x04
1cf00 20 20 20 20 2f 2a 20 54 68 69 73 20 4f 50 5f 49 /* This OP_I
1cf10 6e 73 65 72 74 20 69 73 20 61 6e 20 73 71 6c 20 nsert is an sql
1cf20 55 50 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e UPDATE */.#defin
1cf30 65 20 4f 50 46 4c 41 47 5f 41 50 50 45 4e 44 20 e OPFLAG_APPEND
1cf40 20 20 20 20 20 20 20 30 78 30 38 20 20 20 20 2f 0x08 /
1cf50 2a 20 54 68 69 73 20 69 73 20 6c 69 6b 65 6c 79 * This is likely
1cf60 20 74 6f 20 62 65 20 61 6e 20 61 70 70 65 6e 64 to be an append
1cf70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1cf80 41 47 5f 55 53 45 53 45 45 4b 52 45 53 55 4c 54 AG_USESEEKRESULT
1cf90 20 30 78 31 30 20 20 20 20 2f 2a 20 54 72 79 20 0x10 /* Try
1cfa0 74 6f 20 61 76 6f 69 64 20 61 20 73 65 65 6b 20 to avoid a seek
1cfb0 69 6e 20 42 74 72 65 65 49 6e 73 65 72 74 28 29 in BtreeInsert()
1cfc0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1cfd0 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 20 20 20 AG_LENGTHARG
1cfe0 20 30 78 34 30 20 20 20 20 2f 2a 20 4f 50 5f 43 0x40 /* OP_C
1cff0 6f 6c 75 6d 6e 20 6f 6e 6c 79 20 75 73 65 64 20 olumn only used
1d000 66 6f 72 20 6c 65 6e 67 74 68 28 29 20 2a 2f 0a for length() */.
1d010 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 54 #define OPFLAG_T
1d020 59 50 45 4f 46 41 52 47 20 20 20 20 20 30 78 38 YPEOFARG 0x8
1d030 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 0 /* OP_Colum
1d040 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 n only used for
1d050 74 79 70 65 6f 66 28 29 20 2a 2f 0a 23 64 65 66 typeof() */.#def
1d060 69 6e 65 20 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 ine OPFLAG_BULKC
1d070 53 52 20 20 20 20 20 20 20 30 78 30 31 20 20 20 SR 0x01
1d080 20 2f 2a 20 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 /* OP_Open** us
1d090 65 64 20 74 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 ed to open bulk
1d0a0 63 75 72 73 6f 72 20 2a 2f 0a 23 64 65 66 69 6e cursor */.#defin
1d0b0 65 20 4f 50 46 4c 41 47 5f 53 45 45 4b 45 51 20 e OPFLAG_SEEKEQ
1d0c0 20 20 20 20 20 20 20 30 78 30 32 20 20 20 20 2f 0x02 /
1d0d0 2a 20 4f 50 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 * OP_Open** curs
1d0e0 6f 72 20 75 73 65 73 20 45 51 20 73 65 65 6b 20 or uses EQ seek
1d0f0 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 only */.#define
1d100 4f 50 46 4c 41 47 5f 50 32 49 53 52 45 47 20 20 OPFLAG_P2ISREG
1d110 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 0x04 /*
1d120 50 32 20 74 6f 20 4f 50 5f 4f 70 65 6e 2a 2a 20 P2 to OP_Open**
1d130 69 73 20 61 20 72 65 67 69 73 74 65 72 20 6e 75 is a register nu
1d140 6d 62 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 mber */.#define
1d150 4f 50 46 4c 41 47 5f 50 45 52 4d 55 54 45 20 20 OPFLAG_PERMUTE
1d160 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
1d170 4f 50 5f 43 6f 6d 70 61 72 65 3a 20 75 73 65 20 OP_Compare: use
1d180 74 68 65 20 70 65 72 6d 75 74 61 74 69 6f 6e 20 the permutation
1d190 2a 2f 0a 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 74 */../*. * Each t
1d1a0 72 69 67 67 65 72 20 70 72 65 73 65 6e 74 20 69 rigger present i
1d1b0 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 n the database s
1d1c0 63 68 65 6d 61 20 69 73 20 73 74 6f 72 65 64 20 chema is stored
1d1d0 61 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f as an instance o
1d1e0 66 0a 20 2a 20 73 74 72 75 63 74 20 54 72 69 67 f. * struct Trig
1d1f0 67 65 72 2e 20 0a 20 2a 0a 20 2a 20 50 6f 69 6e ger. . *. * Poin
1d200 74 65 72 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 ters to instance
1d210 73 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 s of struct Trig
1d220 67 65 72 20 61 72 65 20 73 74 6f 72 65 64 20 69 ger are stored i
1d230 6e 20 74 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 n two ways.. * 1
1d240 2e 20 49 6e 20 74 68 65 20 22 74 72 69 67 48 61 . In the "trigHa
1d250 73 68 22 20 68 61 73 68 20 74 61 62 6c 65 20 28 sh" hash table (
1d260 70 61 72 74 20 6f 66 20 74 68 65 20 73 71 6c 69 part of the sqli
1d270 74 65 33 2a 20 74 68 61 74 20 72 65 70 72 65 73 te3* that repres
1d280 65 6e 74 73 20 74 68 65 20 0a 20 2a 20 20 20 20 ents the . *
1d290 64 61 74 61 62 61 73 65 29 2e 20 54 68 69 73 20 database). This
1d2a0 61 6c 6c 6f 77 73 20 54 72 69 67 67 65 72 20 73 allows Trigger s
1d2b0 74 72 75 63 74 75 72 65 73 20 74 6f 20 62 65 20 tructures to be
1d2c0 72 65 74 72 69 65 76 65 64 20 62 79 20 6e 61 6d retrieved by nam
1d2d0 65 2e 0a 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 e.. * 2. All tri
1d2e0 67 67 65 72 73 20 61 73 73 6f 63 69 61 74 65 64 ggers associated
1d2f0 20 77 69 74 68 20 61 20 73 69 6e 67 6c 65 20 74 with a single t
1d300 61 62 6c 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b able form a link
1d310 65 64 20 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 ed list, using t
1d320 68 65 0a 20 2a 20 20 20 20 70 4e 65 78 74 20 6d he. * pNext m
1d330 65 6d 62 65 72 20 6f 66 20 73 74 72 75 63 74 20 ember of struct
1d340 54 72 69 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 Trigger. A point
1d350 65 72 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 er to the first
1d360 65 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 element of the.
1d370 2a 20 20 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 * linked list
1d380 20 69 73 20 73 74 6f 72 65 64 20 61 73 20 74 68 is stored as th
1d390 65 20 22 70 54 72 69 67 67 65 72 22 20 6d 65 6d e "pTrigger" mem
1d3a0 62 65 72 20 6f 66 20 74 68 65 20 61 73 73 6f 63 ber of the assoc
1d3b0 69 61 74 65 64 0a 20 2a 20 20 20 20 73 74 72 75 iated. * stru
1d3c0 63 74 20 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 ct Table.. *. *
1d3d0 54 68 65 20 22 73 74 65 70 5f 6c 69 73 74 22 20 The "step_list"
1d3e0 6d 65 6d 62 65 72 20 70 6f 69 6e 74 73 20 74 6f member points to
1d3f0 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 the first eleme
1d400 6e 74 20 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c nt of a linked l
1d410 69 73 74 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e ist. * containin
1d420 67 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 6d g the SQL statem
1d430 65 6e 74 73 20 73 70 65 63 69 66 69 65 64 20 61 ents specified a
1d440 73 20 74 68 65 20 74 72 69 67 67 65 72 20 70 72 s the trigger pr
1d450 6f 67 72 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 ogram.. */.struc
1d460 74 20 54 72 69 67 67 65 72 20 7b 0a 20 20 63 68 t Trigger {. ch
1d470 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
1d480 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d /* The nam
1d490 65 20 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 e of the trigger
1d4a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d4b0 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 */. cha
1d4c0 72 20 2a 74 61 62 6c 65 3b 20 20 20 20 20 20 20 r *table;
1d4d0 20 20 20 20 20 2f 2a 20 54 68 65 20 74 61 62 6c /* The tabl
1d4e0 65 20 6f 72 20 76 69 65 77 20 74 6f 20 77 68 69 e or view to whi
1d4f0 63 68 20 74 68 65 20 74 72 69 67 67 65 72 20 61 ch the trigger a
1d500 70 70 6c 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f pplies */. u8 o
1d510 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 p;
1d520 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b /* One of TK
1d530 5f 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 _DELETE, TK_UPDA
1d540 54 45 2c 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 TE, TK_INSERT
1d550 20 20 20 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 */. u8 tr
1d560 5f 74 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 _tm;
1d570 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 /* One of TRI
1d580 47 47 45 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 GGER_BEFORE, TRI
1d590 47 47 45 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 GGER_AFTER */.
1d5a0 45 78 70 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 Expr *pWhen;
1d5b0 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 /* The W
1d5c0 48 45 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 68 HEN clause of th
1d5d0 65 20 65 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 e expression (ma
1d5e0 79 20 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 y be NULL) */.
1d5f0 49 64 4c 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 IdList *pColumns
1d600 3b 20 20 20 20 20 20 20 2f 2a 20 49 66 20 74 68 ; /* If th
1d610 69 73 20 69 73 20 61 6e 20 55 50 44 41 54 45 20 is is an UPDATE
1d620 4f 46 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e OF <column-list>
1d630 20 74 72 69 67 67 65 72 2c 0a 20 20 20 20 20 20 trigger,.
1d640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d650 20 20 20 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 the <colu
1d660 6d 6e 2d 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 mn-list> is stor
1d670 65 64 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 ed here */. Sch
1d680 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 ema *pSchema;
1d690 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 /* Schema c
1d6a0 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74 72 ontaining the tr
1d6b0 69 67 67 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d igger */. Schem
1d6c0 61 20 2a 70 54 61 62 53 63 68 65 6d 61 3b 20 20 a *pTabSchema;
1d6d0 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e /* Schema con
1d6e0 74 61 69 6e 69 6e 67 20 74 68 65 20 74 61 62 6c taining the tabl
1d6f0 65 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 e */. TriggerSt
1d700 65 70 20 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f ep *step_list; /
1d710 2a 20 4c 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 * Link list of t
1d720 72 69 67 67 65 72 20 70 72 6f 67 72 61 6d 20 73 rigger program s
1d730 74 65 70 73 20 20 20 20 20 20 20 20 20 20 20 20 teps
1d740 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 */. Trigger *p
1d750 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a Next; /*
1d760 20 4e 65 78 74 20 74 72 69 67 67 65 72 20 61 73 Next trigger as
1d770 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 sociated with th
1d780 65 20 74 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f e table */.};../
1d790 2a 0a 2a 2a 20 41 20 74 72 69 67 67 65 72 20 69 *.** A trigger i
1d7a0 73 20 65 69 74 68 65 72 20 61 20 42 45 46 4f 52 s either a BEFOR
1d7b0 45 20 6f 72 20 61 6e 20 41 46 54 45 52 20 74 72 E or an AFTER tr
1d7c0 69 67 67 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c igger. The foll
1d7d0 6f 77 69 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a owing constants.
1d7e0 2a 2a 20 64 65 74 65 72 6d 69 6e 65 20 77 68 69 ** determine whi
1d7f0 63 68 2e 20 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 ch. .**.** If th
1d800 65 72 65 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 ere are multiple
1d810 20 74 72 69 67 67 65 72 73 2c 20 79 6f 75 20 6d triggers, you m
1d820 69 67 68 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 ight of some BEF
1d830 4f 52 45 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 ORE and some AFT
1d840 45 52 2e 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 ER..** In that c
1d850 61 73 65 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 ases, the consta
1d860 6e 74 73 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 nts below can be
1d870 20 4f 52 65 64 20 74 6f 67 65 74 68 65 72 2e 0a ORed together..
1d880 2a 2f 0a 23 64 65 66 69 6e 65 20 54 52 49 47 47 */.#define TRIGG
1d890 45 52 5f 42 45 46 4f 52 45 20 20 31 0a 23 64 65 ER_BEFORE 1.#de
1d8a0 66 69 6e 65 20 54 52 49 47 47 45 52 5f 41 46 54 fine TRIGGER_AFT
1d8b0 45 52 20 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e ER 2../*. * An
1d8c0 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 73 74 72 instance of str
1d8d0 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 20 uct TriggerStep
1d8e0 69 73 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 is used to store
1d8f0 20 61 20 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 a single SQL st
1d900 61 74 65 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 atement. * that
1d910 69 73 20 61 20 70 61 72 74 20 6f 66 20 61 20 74 is a part of a t
1d920 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 20 rigger-program.
1d930 0a 20 2a 0a 20 2a 20 49 6e 73 74 61 6e 63 65 73 . *. * Instances
1d940 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 67 of struct Trigg
1d950 65 72 53 74 65 70 20 61 72 65 20 73 74 6f 72 65 erStep are store
1d960 64 20 69 6e 20 61 20 73 69 6e 67 6c 79 20 6c 69 d in a singly li
1d970 6e 6b 65 64 20 6c 69 73 74 20 28 6c 69 6e 6b 65 nked list (linke
1d980 64 0a 20 2a 20 75 73 69 6e 67 20 74 68 65 20 22 d. * using the "
1d990 70 4e 65 78 74 22 20 6d 65 6d 62 65 72 29 20 72 pNext" member) r
1d9a0 65 66 65 72 65 6e 63 65 64 20 62 79 20 74 68 65 eferenced by the
1d9b0 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d "step_list" mem
1d9c0 62 65 72 20 6f 66 20 74 68 65 20 0a 20 2a 20 61 ber of the . * a
1d9d0 73 73 6f 63 69 61 74 65 64 20 73 74 72 75 63 74 ssociated struct
1d9e0 20 54 72 69 67 67 65 72 20 69 6e 73 74 61 6e 63 Trigger instanc
1d9f0 65 2e 20 54 68 65 20 66 69 72 73 74 20 65 6c 65 e. The first ele
1da00 6d 65 6e 74 20 6f 66 20 74 68 65 20 6c 69 6e 6b ment of the link
1da10 65 64 20 6c 69 73 74 20 69 73 0a 20 2a 20 74 68 ed list is. * th
1da20 65 20 66 69 72 73 74 20 73 74 65 70 20 6f 66 20 e first step of
1da30 74 68 65 20 74 72 69 67 67 65 72 2d 70 72 6f 67 the trigger-prog
1da40 72 61 6d 2e 0a 20 2a 20 0a 20 2a 20 54 68 65 20 ram.. * . * The
1da50 22 6f 70 22 20 6d 65 6d 62 65 72 20 69 6e 64 69 "op" member indi
1da60 63 61 74 65 73 20 77 68 65 74 68 65 72 20 74 68 cates whether th
1da70 69 73 20 69 73 20 61 20 22 44 45 4c 45 54 45 22 is is a "DELETE"
1da80 2c 20 22 49 4e 53 45 52 54 22 2c 20 22 55 50 44 , "INSERT", "UPD
1da90 41 54 45 22 20 6f 72 0a 20 2a 20 22 53 45 4c 45 ATE" or. * "SELE
1daa0 43 54 22 20 73 74 61 74 65 6d 65 6e 74 2e 20 54 CT" statement. T
1dab0 68 65 20 6d 65 61 6e 69 6e 67 73 20 6f 66 20 74 he meanings of t
1dac0 68 65 20 6f 74 68 65 72 20 6d 65 6d 62 65 72 73 he other members
1dad0 20 69 73 20 64 65 74 65 72 6d 69 6e 65 64 20 62 is determined b
1dae0 79 20 74 68 65 20 0a 20 2a 20 76 61 6c 75 65 20 y the . * value
1daf0 6f 66 20 22 6f 70 22 20 61 73 20 66 6f 6c 6c 6f of "op" as follo
1db00 77 73 3a 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d ws:. *. * (op ==
1db10 20 54 4b 5f 49 4e 53 45 52 54 29 0a 20 2a 20 6f TK_INSERT). * o
1db20 72 63 6f 6e 66 20 20 20 20 2d 3e 20 73 74 6f 72 rconf -> stor
1db30 65 73 20 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 es the ON CONFLI
1db40 43 54 20 61 6c 67 6f 72 69 74 68 6d 0a 20 2a 20 CT algorithm. *
1db50 70 53 65 6c 65 63 74 20 20 20 2d 3e 20 49 66 20 pSelect -> If
1db60 74 68 69 73 20 69 73 20 61 6e 20 49 4e 53 45 52 this is an INSER
1db70 54 20 49 4e 54 4f 20 2e 2e 2e 20 53 45 4c 45 43 T INTO ... SELEC
1db80 54 20 2e 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c T ... statement,
1db90 20 74 68 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 then. *
1dba0 20 20 20 20 20 20 74 68 69 73 20 73 74 6f 72 65 this store
1dbb0 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 s a pointer to t
1dbc0 68 65 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d he SELECT statem
1dbd0 65 6e 74 2e 20 4f 74 68 65 72 77 69 73 65 20 4e ent. Otherwise N
1dbe0 55 4c 4c 2e 0a 20 2a 20 74 61 72 67 65 74 20 20 ULL.. * target
1dbf0 20 20 2d 3e 20 41 20 74 6f 6b 65 6e 20 68 6f 6c -> A token hol
1dc00 64 69 6e 67 20 74 68 65 20 71 75 6f 74 65 64 20 ding the quoted
1dc10 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c name of the tabl
1dc20 65 20 74 6f 20 69 6e 73 65 72 74 20 69 6e 74 6f e to insert into
1dc30 2e 0a 20 2a 20 70 45 78 70 72 4c 69 73 74 20 2d .. * pExprList -
1dc40 3e 20 49 66 20 74 68 69 73 20 69 73 20 61 6e 20 > If this is an
1dc50 49 4e 53 45 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 INSERT INTO ...
1dc60 56 41 4c 55 45 53 20 2e 2e 2e 20 73 74 61 74 65 VALUES ... state
1dc70 6d 65 6e 74 2c 20 74 68 65 6e 0a 20 2a 20 20 20 ment, then. *
1dc80 20 20 20 20 20 20 20 20 20 20 20 74 68 69 73 20 this
1dc90 73 74 6f 72 65 73 20 76 61 6c 75 65 73 20 74 6f stores values to
1dca0 20 62 65 20 69 6e 73 65 72 74 65 64 2e 20 4f 74 be inserted. Ot
1dcb0 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a herwise NULL.. *
1dcc0 20 70 49 64 4c 69 73 74 20 20 20 2d 3e 20 49 66 pIdList -> If
1dcd0 20 74 68 69 73 20 69 73 20 61 6e 20 49 4e 53 45 this is an INSE
1dce0 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 28 3c 63 6f RT INTO ... (<co
1dcf0 6c 75 6d 6e 2d 6e 61 6d 65 73 3e 29 20 56 41 4c lumn-names>) VAL
1dd00 55 45 53 20 2e 2e 2e 20 0a 20 2a 20 20 20 20 20 UES ... . *
1dd10 20 20 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 stateme
1dd20 6e 74 2c 20 74 68 65 6e 20 74 68 69 73 20 73 74 nt, then this st
1dd30 6f 72 65 73 20 74 68 65 20 63 6f 6c 75 6d 6e 2d ores the column-
1dd40 6e 61 6d 65 73 20 74 6f 20 62 65 0a 20 2a 20 20 names to be. *
1dd50 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 73 65 inse
1dd60 72 74 65 64 20 69 6e 74 6f 2e 0a 20 2a 0a 20 2a rted into.. *. *
1dd70 20 28 6f 70 20 3d 3d 20 54 4b 5f 44 45 4c 45 54 (op == TK_DELET
1dd80 45 29 0a 20 2a 20 74 61 72 67 65 74 20 20 20 20 E). * target
1dd90 2d 3e 20 41 20 74 6f 6b 65 6e 20 68 6f 6c 64 69 -> A token holdi
1dda0 6e 67 20 74 68 65 20 71 75 6f 74 65 64 20 6e 61 ng the quoted na
1ddb0 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 me of the table
1ddc0 74 6f 20 64 65 6c 65 74 65 20 66 72 6f 6d 2e 0a to delete from..
1ddd0 20 2a 20 70 57 68 65 72 65 20 20 20 20 2d 3e 20 * pWhere ->
1dde0 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 The WHERE clause
1ddf0 20 6f 66 20 74 68 65 20 44 45 4c 45 54 45 20 73 of the DELETE s
1de00 74 61 74 65 6d 65 6e 74 20 69 66 20 6f 6e 65 20 tatement if one
1de10 69 73 20 73 70 65 63 69 66 69 65 64 2e 0a 20 2a is specified.. *
1de20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4f 74 Ot
1de30 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a herwise NULL.. *
1de40 20 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 55 . * (op == TK_U
1de50 50 44 41 54 45 29 0a 20 2a 20 74 61 72 67 65 74 PDATE). * target
1de60 20 20 20 20 2d 3e 20 41 20 74 6f 6b 65 6e 20 68 -> A token h
1de70 6f 6c 64 69 6e 67 20 74 68 65 20 71 75 6f 74 65 olding the quote
1de80 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 d name of the ta
1de90 62 6c 65 20 74 6f 20 75 70 64 61 74 65 20 72 6f ble to update ro
1dea0 77 73 20 6f 66 2e 0a 20 2a 20 70 57 68 65 72 65 ws of.. * pWhere
1deb0 20 20 20 20 2d 3e 20 54 68 65 20 57 48 45 52 45 -> The WHERE
1dec0 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 55 clause of the U
1ded0 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e 74 20 PDATE statement
1dee0 69 66 20 6f 6e 65 20 69 73 20 73 70 65 63 69 66 if one is specif
1def0 69 65 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 ied.. *
1df00 20 20 20 20 20 4f 74 68 65 72 77 69 73 65 20 4e Otherwise N
1df10 55 4c 4c 2e 0a 20 2a 20 70 45 78 70 72 4c 69 73 ULL.. * pExprLis
1df20 74 20 2d 3e 20 41 20 6c 69 73 74 20 6f 66 20 74 t -> A list of t
1df30 68 65 20 63 6f 6c 75 6d 6e 73 20 74 6f 20 75 70 he columns to up
1df40 64 61 74 65 20 61 6e 64 20 74 68 65 20 65 78 70 date and the exp
1df50 72 65 73 73 69 6f 6e 73 20 74 6f 20 75 70 64 61 ressions to upda
1df60 74 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 te. *
1df70 20 20 20 74 68 65 6d 20 74 6f 2e 20 53 65 65 20 them to. See
1df80 73 71 6c 69 74 65 33 55 70 64 61 74 65 28 29 20 sqlite3Update()
1df90 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 documentation of
1dfa0 20 22 70 43 68 61 6e 67 65 73 22 0a 20 2a 20 20 "pChanges". *
1dfb0 20 20 20 20 20 20 20 20 20 20 20 20 61 72 67 75 argu
1dfc0 6d 65 6e 74 2e 0a 20 2a 20 0a 20 2a 2f 0a 73 74 ment.. * . */.st
1dfd0 72 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 ruct TriggerStep
1dfe0 20 7b 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 {. u8 op;
1dff0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 /* One
1e000 20 6f 66 20 54 4b 5f 44 45 4c 45 54 45 2c 20 54 of TK_DELETE, T
1e010 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 K_UPDATE, TK_INS
1e020 45 52 54 2c 20 54 4b 5f 53 45 4c 45 43 54 20 2a ERT, TK_SELECT *
1e030 2f 0a 20 20 75 38 20 6f 72 63 6f 6e 66 3b 20 20 /. u8 orconf;
1e040 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 5f 52 /* OE_R
1e050 6f 6c 6c 62 61 63 6b 20 65 74 63 2e 20 2a 2f 0a ollback etc. */.
1e060 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 Trigger *pTrig
1e070 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 74 72 ; /* The tr
1e080 69 67 67 65 72 20 74 68 61 74 20 74 68 69 73 20 igger that this
1e090 73 74 65 70 20 69 73 20 61 20 70 61 72 74 20 6f step is a part o
1e0a0 66 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 f */. Select *p
1e0b0 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 53 Select; /* S
1e0c0 45 4c 45 43 54 20 73 74 61 74 6d 65 6e 74 20 6f ELECT statment o
1e0d0 72 20 52 48 53 20 6f 66 20 49 4e 53 45 52 54 20 r RHS of INSERT
1e0e0 49 4e 54 4f 20 2e 2e 20 53 45 4c 45 43 54 20 2e INTO .. SELECT .
1e0f0 2e 2e 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 74 61 .. */. Token ta
1e100 72 67 65 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 rget; /*
1e110 54 61 72 67 65 74 20 74 61 62 6c 65 20 66 6f 72 Target table for
1e120 20 44 45 4c 45 54 45 2c 20 55 50 44 41 54 45 2c DELETE, UPDATE,
1e130 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 45 78 70 INSERT */. Exp
1e140 72 20 2a 70 57 68 65 72 65 3b 20 20 20 20 20 20 r *pWhere;
1e150 20 20 2f 2a 20 54 68 65 20 57 48 45 52 45 20 63 /* The WHERE c
1e160 6c 61 75 73 65 20 66 6f 72 20 44 45 4c 45 54 45 lause for DELETE
1e170 20 6f 72 20 55 50 44 41 54 45 20 73 74 65 70 73 or UPDATE steps
1e180 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1e190 70 45 78 70 72 4c 69 73 74 3b 20 2f 2a 20 53 45 pExprList; /* SE
1e1a0 54 20 63 6c 61 75 73 65 20 66 6f 72 20 55 50 44 T clause for UPD
1e1b0 41 54 45 2e 20 2a 2f 0a 20 20 49 64 4c 69 73 74 ATE. */. IdList
1e1c0 20 2a 70 49 64 4c 69 73 74 3b 20 20 20 20 20 2f *pIdList; /
1e1d0 2a 20 43 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 66 * Column names f
1e1e0 6f 72 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 54 or INSERT */. T
1e1f0 72 69 67 67 65 72 53 74 65 70 20 2a 70 4e 65 78 riggerStep *pNex
1e200 74 3b 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 74 t; /* Next in t
1e210 68 65 20 6c 69 6e 6b 2d 6c 69 73 74 20 2a 2f 0a he link-list */.
1e220 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 70 TriggerStep *p
1e230 4c 61 73 74 3b 20 20 2f 2a 20 4c 61 73 74 20 65 Last; /* Last e
1e240 6c 65 6d 65 6e 74 20 69 6e 20 6c 69 6e 6b 2d 6c lement in link-l
1e250 69 73 74 2e 20 56 61 6c 69 64 20 66 6f 72 20 31 ist. Valid for 1
1e260 73 74 20 65 6c 65 6d 20 6f 6e 6c 79 20 2a 2f 0a st elem only */.
1e270 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f };../*.** The fo
1e280 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
1e290 65 20 63 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 e contains infor
1e2a0 6d 61 74 69 6f 6e 20 75 73 65 64 20 62 79 20 74 mation used by t
1e2b0 68 65 20 73 71 6c 69 74 65 46 69 78 2e 2e 2e 0a he sqliteFix....
1e2c0 2a 2a 20 72 6f 75 74 69 6e 65 73 20 61 73 20 74 ** routines as t
1e2d0 68 65 79 20 77 61 6c 6b 20 74 68 65 20 70 61 72 hey walk the par
1e2e0 73 65 20 74 72 65 65 20 74 6f 20 6d 61 6b 65 20 se tree to make
1e2f0 64 61 74 61 62 61 73 65 20 72 65 66 65 72 65 6e database referen
1e300 63 65 73 0a 2a 2a 20 65 78 70 6c 69 63 69 74 2e ces.** explicit.
1e310 20 20 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 .*/.typedef st
1e320 72 75 63 74 20 44 62 46 69 78 65 72 20 44 62 46 ruct DbFixer DbF
1e330 69 78 65 72 3b 0a 73 74 72 75 63 74 20 44 62 46 ixer;.struct DbF
1e340 69 78 65 72 20 7b 0a 20 20 50 61 72 73 65 20 2a ixer {. Parse *
1e350 70 50 61 72 73 65 3b 20 20 20 20 20 20 2f 2a 20 pParse; /*
1e360 54 68 65 20 70 61 72 73 69 6e 67 20 63 6f 6e 74 The parsing cont
1e370 65 78 74 2e 20 20 45 72 72 6f 72 20 6d 65 73 73 ext. Error mess
1e380 61 67 65 73 20 77 72 69 74 74 65 6e 20 68 65 72 ages written her
1e390 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 e */. Schema *p
1e3a0 53 63 68 65 6d 61 3b 20 20 20 20 2f 2a 20 46 69 Schema; /* Fi
1e3b0 78 20 69 74 65 6d 73 20 74 6f 20 74 68 69 73 20 x items to this
1e3c0 73 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 schema */. int
1e3d0 62 56 61 72 4f 6e 6c 79 3b 20 20 20 20 20 20 20 bVarOnly;
1e3e0 2f 2a 20 43 68 65 63 6b 20 66 6f 72 20 76 61 72 /* Check for var
1e3f0 69 61 62 6c 65 20 72 65 66 65 72 65 6e 63 65 73 iable references
1e400 20 6f 6e 6c 79 20 2a 2f 0a 20 20 63 6f 6e 73 74 only */. const
1e410 20 63 68 61 72 20 2a 7a 44 62 3b 20 20 20 20 2f char *zDb; /
1e420 2a 20 4d 61 6b 65 20 73 75 72 65 20 61 6c 6c 20 * Make sure all
1e430 6f 62 6a 65 63 74 73 20 61 72 65 20 63 6f 6e 74 objects are cont
1e440 61 69 6e 65 64 20 69 6e 20 74 68 69 73 20 64 61 ained in this da
1e450 74 61 62 61 73 65 20 2a 2f 0a 20 20 63 6f 6e 73 tabase */. cons
1e460 74 20 63 68 61 72 20 2a 7a 54 79 70 65 3b 20 20 t char *zType;
1e470 2f 2a 20 54 79 70 65 20 6f 66 20 74 68 65 20 63 /* Type of the c
1e480 6f 6e 74 61 69 6e 65 72 20 2d 20 75 73 65 64 20 ontainer - used
1e490 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 67 for error messag
1e4a0 65 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 54 6f es */. const To
1e4b0 6b 65 6e 20 2a 70 4e 61 6d 65 3b 20 2f 2a 20 4e ken *pName; /* N
1e4c0 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 ame of the conta
1e4d0 69 6e 65 72 20 2d 20 75 73 65 64 20 66 6f 72 20 iner - used for
1e4e0 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 2a error messages *
1e4f0 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f /.};../*.** An o
1e500 62 6a 65 63 74 65 64 20 75 73 65 64 20 74 6f 20 bjected used to
1e510 61 63 63 75 6d 75 6c 61 74 65 20 74 68 65 20 74 accumulate the t
1e520 65 78 74 20 6f 66 20 61 20 73 74 72 69 6e 67 20 ext of a string
1e530 77 68 65 72 65 20 77 65 0a 2a 2a 20 64 6f 20 6e where we.** do n
1e540 6f 74 20 6e 65 63 65 73 73 61 72 69 6c 79 20 6b ot necessarily k
1e550 6e 6f 77 20 68 6f 77 20 62 69 67 20 74 68 65 20 now how big the
1e560 73 74 72 69 6e 67 20 77 69 6c 6c 20 62 65 20 69 string will be i
1e570 6e 20 74 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 n the end..*/.st
1e580 72 75 63 74 20 53 74 72 41 63 63 75 6d 20 7b 0a ruct StrAccum {.
1e590 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 sqlite3 *db;
1e5a0 20 20 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e /* Option
1e5b0 61 6c 20 64 61 74 61 62 61 73 65 20 66 6f 72 20 al database for
1e5c0 6c 6f 6f 6b 61 73 69 64 65 2e 20 20 43 61 6e 20 lookaside. Can
1e5d0 62 65 20 4e 55 4c 4c 20 2a 2f 0a 20 20 63 68 61 be NULL */. cha
1e5e0 72 20 2a 7a 42 61 73 65 3b 20 20 20 20 20 20 20 r *zBase;
1e5f0 20 20 2f 2a 20 41 20 62 61 73 65 20 61 6c 6c 6f /* A base allo
1e600 63 61 74 69 6f 6e 2e 20 20 4e 6f 74 20 66 72 6f cation. Not fro
1e610 6d 20 6d 61 6c 6c 6f 63 2e 20 2a 2f 0a 20 20 63 m malloc. */. c
1e620 68 61 72 20 2a 7a 54 65 78 74 3b 20 20 20 20 20 har *zText;
1e630 20 20 20 20 2f 2a 20 54 68 65 20 73 74 72 69 6e /* The strin
1e640 67 20 63 6f 6c 6c 65 63 74 65 64 20 73 6f 20 66 g collected so f
1e650 61 72 20 2a 2f 0a 20 20 69 6e 74 20 20 6e 43 68 ar */. int nCh
1e660 61 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ar; /*
1e670 4c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 73 74 Length of the st
1e680 72 69 6e 67 20 73 6f 20 66 61 72 20 2a 2f 0a 20 ring so far */.
1e690 20 69 6e 74 20 20 6e 41 6c 6c 6f 63 3b 20 20 20 int nAlloc;
1e6a0 20 20 20 20 20 20 2f 2a 20 41 6d 6f 75 6e 74 20 /* Amount
1e6b0 6f 66 20 73 70 61 63 65 20 61 6c 6c 6f 63 61 74 of space allocat
1e6c0 65 64 20 69 6e 20 7a 54 65 78 74 20 2a 2f 0a 20 ed in zText */.
1e6d0 20 69 6e 74 20 20 6d 78 41 6c 6c 6f 63 3b 20 20 int mxAlloc;
1e6e0 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d /* Maximum
1e6f0 20 61 6c 6c 6f 77 65 64 20 73 74 72 69 6e 67 20 allowed string
1e700 6c 65 6e 67 74 68 20 2a 2f 0a 20 20 75 38 20 20 length */. u8
1e710 20 75 73 65 4d 61 6c 6c 6f 63 3b 20 20 20 20 20 useMalloc;
1e720 20 2f 2a 20 30 3a 20 6e 6f 6e 65 2c 20 20 31 3a /* 0: none, 1:
1e730 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 sqlite3DbMalloc
1e740 2c 20 20 32 3a 20 73 71 6c 69 74 65 33 5f 6d 61 , 2: sqlite3_ma
1e750 6c 6c 6f 63 20 2a 2f 0a 20 20 75 38 20 20 20 61 lloc */. u8 a
1e760 63 63 45 72 72 6f 72 3b 20 20 20 20 20 20 20 2f ccError; /
1e770 2a 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 4d * STRACCUM_NOMEM
1e780 20 6f 72 20 53 54 52 41 43 43 55 4d 5f 54 4f 4f or STRACCUM_TOO
1e790 42 49 47 20 2a 2f 0a 7d 3b 0a 23 64 65 66 69 6e BIG */.};.#defin
1e7a0 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 4d e STRACCUM_NOMEM
1e7b0 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 54 52 1.#define STR
1e7c0 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 20 32 0a ACCUM_TOOBIG 2.
1e7d0 0a 2f 2a 0a 2a 2a 20 41 20 70 6f 69 6e 74 65 72 ./*.** A pointer
1e7e0 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 to this structu
1e7f0 72 65 20 69 73 20 75 73 65 64 20 74 6f 20 63 6f re is used to co
1e800 6d 6d 75 6e 69 63 61 74 65 20 69 6e 66 6f 72 6d mmunicate inform
1e810 61 74 69 6f 6e 0a 2a 2a 20 66 72 6f 6d 20 73 71 ation.** from sq
1e820 6c 69 74 65 33 49 6e 69 74 20 61 6e 64 20 4f 50 lite3Init and OP
1e830 5f 50 61 72 73 65 53 63 68 65 6d 61 20 69 6e 74 _ParseSchema int
1e840 6f 20 74 68 65 20 73 71 6c 69 74 65 33 49 6e 69 o the sqlite3Ini
1e850 74 43 61 6c 6c 62 61 63 6b 2e 0a 2a 2f 0a 74 79 tCallback..*/.ty
1e860 70 65 64 65 66 20 73 74 72 75 63 74 20 7b 0a 20 pedef struct {.
1e870 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 sqlite3 *db;
1e880 20 20 20 20 20 2f 2a 20 54 68 65 20 64 61 74 61 /* The data
1e890 62 61 73 65 20 62 65 69 6e 67 20 69 6e 69 74 69 base being initi
1e8a0 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 63 68 61 72 alized */. char
1e8b0 20 2a 2a 70 7a 45 72 72 4d 73 67 3b 20 20 20 20 **pzErrMsg;
1e8c0 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 67 65 /* Error message
1e8d0 20 73 74 6f 72 65 64 20 68 65 72 65 20 2a 2f 0a stored here */.
1e8e0 20 20 69 6e 74 20 69 44 62 3b 20 20 20 20 20 20 int iDb;
1e8f0 20 20 20 20 20 20 2f 2a 20 30 20 66 6f 72 20 6d /* 0 for m
1e900 61 69 6e 20 64 61 74 61 62 61 73 65 2e 20 20 31 ain database. 1
1e910 20 66 6f 72 20 54 45 4d 50 2c 20 32 2e 2e 20 66 for TEMP, 2.. f
1e920 6f 72 20 41 54 54 41 43 48 65 64 20 2a 2f 0a 20 or ATTACHed */.
1e930 20 69 6e 74 20 72 63 3b 20 20 20 20 20 20 20 20 int rc;
1e940 20 20 20 20 20 2f 2a 20 52 65 73 75 6c 74 20 63 /* Result c
1e950 6f 64 65 20 73 74 6f 72 65 64 20 68 65 72 65 20 ode stored here
1e960 2a 2f 0a 7d 20 49 6e 69 74 44 61 74 61 3b 0a 0a */.} InitData;..
1e970 2f 2a 0a 2a 2a 20 53 74 72 75 63 74 75 72 65 20 /*.** Structure
1e980 63 6f 6e 74 61 69 6e 69 6e 67 20 67 6c 6f 62 61 containing globa
1e990 6c 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 l configuration
1e9a0 64 61 74 61 20 66 6f 72 20 74 68 65 20 53 51 4c data for the SQL
1e9b0 69 74 65 20 6c 69 62 72 61 72 79 2e 0a 2a 2a 0a ite library..**.
1e9c0 2a 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 ** This structur
1e9d0 65 20 61 6c 73 6f 20 63 6f 6e 74 61 69 6e 73 20 e also contains
1e9e0 73 6f 6d 65 20 73 74 61 74 65 20 69 6e 66 6f 72 some state infor
1e9f0 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 mation..*/.struc
1ea00 74 20 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 t Sqlite3Config
1ea10 7b 0a 20 20 69 6e 74 20 62 4d 65 6d 73 74 61 74 {. int bMemstat
1ea20 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1ea30 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f /* True to
1ea40 20 65 6e 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 enable memory s
1ea50 74 61 74 75 73 20 2a 2f 0a 20 20 69 6e 74 20 62 tatus */. int b
1ea60 43 6f 72 65 4d 75 74 65 78 3b 20 20 20 20 20 20 CoreMutex;
1ea70 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1ea80 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 63 True to enable c
1ea90 6f 72 65 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a ore mutexing */.
1eaa0 20 20 69 6e 74 20 62 46 75 6c 6c 4d 75 74 65 78 int bFullMutex
1eab0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1eac0 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 /* True to e
1ead0 6e 61 62 6c 65 20 66 75 6c 6c 20 6d 75 74 65 78 nable full mutex
1eae0 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 62 4f 70 ing */. int bOp
1eaf0 65 6e 55 72 69 3b 20 20 20 20 20 20 20 20 20 20 enUri;
1eb00 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1eb10 75 65 20 74 6f 20 69 6e 74 65 72 70 72 65 74 20 ue to interpret
1eb20 66 69 6c 65 6e 61 6d 65 73 20 61 73 20 55 52 49 filenames as URI
1eb30 73 20 2a 2f 0a 20 20 69 6e 74 20 62 55 73 65 43 s */. int bUseC
1eb40 69 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 is;
1eb50 20 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 20 /* Use
1eb60 63 6f 76 65 72 69 6e 67 20 69 6e 64 69 63 65 73 covering indices
1eb70 20 66 6f 72 20 66 75 6c 6c 2d 73 63 61 6e 73 20 for full-scans
1eb80 2a 2f 0a 20 20 69 6e 74 20 6d 78 53 74 72 6c 65 */. int mxStrle
1eb90 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n;
1eba0 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 /* Maximu
1ebb0 6d 20 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 m string length
1ebc0 2a 2f 0a 20 20 69 6e 74 20 6e 65 76 65 72 43 6f */. int neverCo
1ebd0 72 72 75 70 74 3b 20 20 20 20 20 20 20 20 20 20 rrupt;
1ebe0 20 20 20 20 20 20 20 2f 2a 20 44 61 74 61 62 61 /* Databa
1ebf0 73 65 20 69 73 20 61 6c 77 61 79 73 20 77 65 6c se is always wel
1ec00 6c 2d 66 6f 72 6d 65 64 20 2a 2f 0a 20 20 69 6e l-formed */. in
1ec10 74 20 73 7a 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 t szLookaside;
1ec20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ec30 2f 2a 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 /* Default looka
1ec40 73 69 64 65 20 62 75 66 66 65 72 20 73 69 7a 65 side buffer size
1ec50 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 6f 6f 6b 61 */. int nLooka
1ec60 73 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 side;
1ec70 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 /* Defau
1ec80 6c 74 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 lt lookaside buf
1ec90 66 65 72 20 63 6f 75 6e 74 20 2a 2f 0a 20 20 73 fer count */. s
1eca0 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f qlite3_mem_metho
1ecb0 64 73 20 6d 3b 20 20 20 20 20 20 20 20 20 20 20 ds m;
1ecc0 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 65 /* Low-level me
1ecd0 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 mory allocation
1ece0 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 interface */. s
1ecf0 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 qlite3_mutex_met
1ed00 68 6f 64 73 20 6d 75 74 65 78 3b 20 20 20 20 20 hods mutex;
1ed10 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 75 /* Low-level mu
1ed20 74 65 78 20 69 6e 74 65 72 66 61 63 65 20 2a 2f tex interface */
1ed30 0a 20 20 73 71 6c 69 74 65 33 5f 70 63 61 63 68 . sqlite3_pcach
1ed40 65 5f 6d 65 74 68 6f 64 73 32 20 70 63 61 63 68 e_methods2 pcach
1ed50 65 32 3b 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 e2; /* Low-leve
1ed60 6c 20 70 61 67 65 2d 63 61 63 68 65 20 69 6e 74 l page-cache int
1ed70 65 72 66 61 63 65 20 2a 2f 0a 20 20 76 6f 69 64 erface */. void
1ed80 20 2a 70 48 65 61 70 3b 20 20 20 20 20 20 20 20 *pHeap;
1ed90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1eda0 20 48 65 61 70 20 73 74 6f 72 61 67 65 20 73 70 Heap storage sp
1edb0 61 63 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 ace */. int nHe
1edc0 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ap;
1edd0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 /* Si
1ede0 7a 65 20 6f 66 20 70 48 65 61 70 5b 5d 20 2a 2f ze of pHeap[] */
1edf0 0a 20 20 69 6e 74 20 6d 6e 52 65 71 2c 20 6d 78 . int mnReq, mx
1ee00 52 65 71 3b 20 20 20 20 20 20 20 20 20 20 20 20 Req;
1ee10 20 20 20 20 20 2f 2a 20 4d 69 6e 20 61 6e 64 20 /* Min and
1ee20 6d 61 78 20 68 65 61 70 20 72 65 71 75 65 73 74 max heap request
1ee30 73 20 73 69 7a 65 73 20 2a 2f 0a 20 20 73 71 6c s sizes */. sql
1ee40 69 74 65 33 5f 69 6e 74 36 34 20 73 7a 4d 6d 61 ite3_int64 szMma
1ee50 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f p; /
1ee60 2a 20 6d 6d 61 70 28 29 20 73 70 61 63 65 20 70 * mmap() space p
1ee70 65 72 20 6f 70 65 6e 20 66 69 6c 65 20 2a 2f 0a er open file */.
1ee80 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 sqlite3_int64
1ee90 6d 78 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 mxMmap;
1eea0 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 76 /* Maximum v
1eeb0 61 6c 75 65 20 66 6f 72 20 73 7a 4d 6d 61 70 20 alue for szMmap
1eec0 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 53 63 72 61 */. void *pScra
1eed0 74 63 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 tch;
1eee0 20 20 20 20 20 20 20 2f 2a 20 53 63 72 61 74 63 /* Scratc
1eef0 68 20 6d 65 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e h memory */. in
1ef00 74 20 73 7a 53 63 72 61 74 63 68 3b 20 20 20 20 t szScratch;
1ef10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ef20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 20 /* Size of each
1ef30 73 63 72 61 74 63 68 20 62 75 66 66 65 72 20 2a scratch buffer *
1ef40 2f 0a 20 20 69 6e 74 20 6e 53 63 72 61 74 63 68 /. int nScratch
1ef50 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1ef60 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1ef70 6f 66 20 73 63 72 61 74 63 68 20 62 75 66 66 65 of scratch buffe
1ef80 72 73 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 rs */. void *pP
1ef90 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 age;
1efa0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 67 /* Pag
1efb0 65 20 63 61 63 68 65 20 6d 65 6d 6f 72 79 20 2a e cache memory *
1efc0 2f 0a 20 20 69 6e 74 20 73 7a 50 61 67 65 3b 20 /. int szPage;
1efd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1efe0 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 /* Size of
1eff0 20 65 61 63 68 20 70 61 67 65 20 69 6e 20 70 50 each page in pP
1f000 61 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e age[] */. int n
1f010 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 Page;
1f020 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f030 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 20 Number of pages
1f040 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 in pPage[] */.
1f050 69 6e 74 20 6d 78 50 61 72 73 65 72 53 74 61 63 int mxParserStac
1f060 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 k;
1f070 20 20 2f 2a 20 6d 61 78 69 6d 75 6d 20 64 65 70 /* maximum dep
1f080 74 68 20 6f 66 20 74 68 65 20 70 61 72 73 65 72 th of the parser
1f090 20 73 74 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 stack */. int
1f0a0 73 68 61 72 65 64 43 61 63 68 65 45 6e 61 62 6c sharedCacheEnabl
1f0b0 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ed; /*
1f0c0 20 74 72 75 65 20 69 66 20 73 68 61 72 65 64 2d true if shared-
1f0d0 63 61 63 68 65 20 6d 6f 64 65 20 65 6e 61 62 6c cache mode enabl
1f0e0 65 64 20 2a 2f 0a 20 20 75 33 32 20 73 7a 50 6d ed */. u32 szPm
1f0f0 61 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 a;
1f100 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 /* Max
1f110 69 6d 75 6d 20 53 6f 72 74 65 72 20 50 4d 41 20 imum Sorter PMA
1f120 73 69 7a 65 20 2a 2f 0a 20 20 2f 2a 20 54 68 65 size */. /* The
1f130 20 61 62 6f 76 65 20 6d 69 67 68 74 20 62 65 20 above might be
1f140 69 6e 69 74 69 61 6c 69 7a 65 64 20 74 6f 20 6e initialized to n
1f150 6f 6e 2d 7a 65 72 6f 2e 20 20 54 68 65 20 66 6f on-zero. The fo
1f160 6c 6c 6f 77 69 6e 67 20 6e 65 65 64 20 74 6f 20 llowing need to
1f170 61 6c 77 61 79 73 0a 20 20 2a 2a 20 69 6e 69 74 always. ** init
1f180 69 61 6c 6c 79 20 62 65 20 7a 65 72 6f 2c 20 68 ially be zero, h
1f190 6f 77 65 76 65 72 2e 20 2a 2f 0a 20 20 69 6e 74 owever. */. int
1f1a0 20 69 73 49 6e 69 74 3b 20 20 20 20 20 20 20 20 isInit;
1f1b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1f1c0 2a 20 54 72 75 65 20 61 66 74 65 72 20 69 6e 69 * True after ini
1f1d0 74 69 61 6c 69 7a 61 74 69 6f 6e 20 68 61 73 20 tialization has
1f1e0 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 20 69 6e finished */. in
1f1f0 74 20 69 6e 50 72 6f 67 72 65 73 73 3b 20 20 20 t inProgress;
1f200 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f210 2f 2a 20 54 72 75 65 20 77 68 69 6c 65 20 69 6e /* True while in
1f220 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 69 6e 20 itialization in
1f230 70 72 6f 67 72 65 73 73 20 2a 2f 0a 20 20 69 6e progress */. in
1f240 74 20 69 73 4d 75 74 65 78 49 6e 69 74 3b 20 20 t isMutexInit;
1f250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f260 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 6d 75 /* True after mu
1f270 74 65 78 65 73 20 61 72 65 20 69 6e 69 74 69 61 texes are initia
1f280 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 lized */. int i
1f290 73 4d 61 6c 6c 6f 63 49 6e 69 74 3b 20 20 20 20 sMallocInit;
1f2a0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f2b0 54 72 75 65 20 61 66 74 65 72 20 6d 61 6c 6c 6f True after mallo
1f2c0 63 20 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 c is initialized
1f2d0 20 2a 2f 0a 20 20 69 6e 74 20 69 73 50 43 61 63 */. int isPCac
1f2e0 68 65 49 6e 69 74 3b 20 20 20 20 20 20 20 20 20 heInit;
1f2f0 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1f300 61 66 74 65 72 20 6d 61 6c 6c 6f 63 20 69 73 20 after malloc is
1f310 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 initialized */.
1f320 20 69 6e 74 20 6e 52 65 66 49 6e 69 74 4d 75 74 int nRefInitMut
1f330 65 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ex;
1f340 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1f350 75 73 65 72 73 20 6f 66 20 70 49 6e 69 74 4d 75 users of pInitMu
1f360 74 65 78 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 tex */. sqlite3
1f370 5f 6d 75 74 65 78 20 2a 70 49 6e 69 74 4d 75 74 _mutex *pInitMut
1f380 65 78 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 75 ex; /* Mu
1f390 74 65 78 20 75 73 65 64 20 62 79 20 73 71 6c 69 tex used by sqli
1f3a0 74 65 33 5f 69 6e 69 74 69 61 6c 69 7a 65 28 29 te3_initialize()
1f3b0 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 4c 6f */. void (*xLo
1f3c0 67 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e g)(void*,int,con
1f3d0 73 74 20 63 68 61 72 2a 29 3b 20 2f 2a 20 46 75 st char*); /* Fu
1f3e0 6e 63 74 69 6f 6e 20 66 6f 72 20 6c 6f 67 67 69 nction for loggi
1f3f0 6e 67 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 4c ng */. void *pL
1f400 6f 67 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 ogArg;
1f410 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f420 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 First argument t
1f430 6f 20 78 4c 6f 67 28 29 20 2a 2f 0a 23 69 66 64 o xLog() */.#ifd
1f440 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
1f450 5f 53 51 4c 4c 4f 47 0a 20 20 76 6f 69 64 28 2a _SQLLOG. void(*
1f460 78 53 71 6c 6c 6f 67 29 28 76 6f 69 64 2a 2c 73 xSqllog)(void*,s
1f470 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
1f480 61 72 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 ar*, int);. voi
1f490 64 20 2a 70 53 71 6c 6c 6f 67 41 72 67 3b 0a 23 d *pSqllogArg;.#
1f4a0 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c endif.#ifdef SQL
1f4b0 49 54 45 5f 56 44 42 45 5f 43 4f 56 45 52 41 47 ITE_VDBE_COVERAG
1f4c0 45 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f E. /* The follo
1f4d0 77 69 6e 67 20 63 61 6c 6c 62 61 63 6b 20 28 69 wing callback (i
1f4e0 66 20 6e 6f 74 20 4e 55 4c 4c 29 20 69 73 20 69 f not NULL) is i
1f4f0 6e 76 6f 6b 65 64 20 6f 6e 20 65 76 65 72 79 20 nvoked on every
1f500 56 44 42 45 20 62 72 61 6e 63 68 0a 20 20 2a 2a VDBE branch. **
1f510 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 53 65 74 operation. Set
1f520 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 75 73 the callback us
1f530 69 6e 67 20 53 51 4c 49 54 45 5f 54 45 53 54 43 ing SQLITE_TESTC
1f540 54 52 4c 5f 56 44 42 45 5f 43 4f 56 45 52 41 47 TRL_VDBE_COVERAG
1f550 45 2e 0a 20 20 2a 2f 0a 20 20 76 6f 69 64 20 28 E.. */. void (
1f560 2a 78 56 64 62 65 42 72 61 6e 63 68 29 28 76 6f *xVdbeBranch)(vo
1f570 69 64 2a 2c 69 6e 74 20 69 53 72 63 4c 69 6e 65 id*,int iSrcLine
1f580 2c 75 38 20 65 54 68 69 73 2c 75 38 20 65 4d 78 ,u8 eThis,u8 eMx
1f590 29 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 ); /* Callback
1f5a0 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 56 64 62 65 */. void *pVdbe
1f5b0 42 72 61 6e 63 68 41 72 67 3b 20 20 20 20 20 20 BranchArg;
1f5c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f5d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1f5e0 2a 20 31 73 74 20 61 72 67 75 6d 65 6e 74 20 2a * 1st argument *
1f5f0 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 /.#endif.#ifndef
1f600 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 SQLITE_OMIT_BUI
1f610 4c 54 49 4e 5f 54 45 53 54 0a 20 20 69 6e 74 20 LTIN_TEST. int
1f620 28 2a 78 54 65 73 74 43 61 6c 6c 62 61 63 6b 29 (*xTestCallback)
1f630 28 69 6e 74 29 3b 20 20 20 20 20 20 20 20 2f 2a (int); /*
1f640 20 49 6e 76 6f 6b 65 64 20 62 79 20 73 71 6c 69 Invoked by sqli
1f650 74 65 33 46 61 75 6c 74 53 69 6d 28 29 20 2a 2f te3FaultSim() */
1f660 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 62 4c .#endif. int bL
1f670 6f 63 61 6c 74 69 6d 65 46 61 75 6c 74 3b 20 20 ocaltimeFault;
1f680 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
1f690 72 75 65 20 74 6f 20 66 61 69 6c 20 6c 6f 63 61 rue to fail loca
1f6a0 6c 74 69 6d 65 28 29 20 63 61 6c 6c 73 20 2a 2f ltime() calls */
1f6b0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 .};../*.** This
1f6c0 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 69 6e macro is used in
1f6d0 73 69 64 65 20 6f 66 20 61 73 73 65 72 74 28 29 side of assert()
1f6e0 20 73 74 61 74 65 6d 65 6e 74 73 20 74 6f 20 69 statements to i
1f6f0 6e 64 69 63 61 74 65 20 74 68 61 74 0a 2a 2a 20 ndicate that.**
1f700 74 68 65 20 61 73 73 65 72 74 20 69 73 20 6f 6e the assert is on
1f710 6c 79 20 76 61 6c 69 64 20 6f 6e 20 61 20 77 65 ly valid on a we
1f720 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 74 61 62 61 ll-formed databa
1f730 73 65 2e 20 20 49 6e 73 74 65 61 64 20 6f 66 3a se. Instead of:
1f740 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 73 73 65 72 .**.** asser
1f750 74 28 20 58 20 29 3b 0a 2a 2a 0a 2a 2a 20 4f 6e t( X );.**.** On
1f760 65 20 77 72 69 74 65 73 3a 0a 2a 2a 0a 2a 2a 20 e writes:.**.**
1f770 20 20 20 20 61 73 73 65 72 74 28 20 58 20 7c 7c assert( X ||
1f780 20 43 4f 52 52 55 50 54 5f 44 42 20 29 3b 0a 2a CORRUPT_DB );.*
1f790 2a 0a 2a 2a 20 43 4f 52 52 55 50 54 5f 44 42 20 *.** CORRUPT_DB
1f7a0 69 73 20 74 72 75 65 20 64 75 72 69 6e 67 20 6e is true during n
1f7b0 6f 72 6d 61 6c 20 6f 70 65 72 61 74 69 6f 6e 2e ormal operation.
1f7c0 20 20 43 4f 52 52 55 50 54 5f 44 42 20 64 6f 65 CORRUPT_DB doe
1f7d0 73 20 6e 6f 74 20 69 6e 64 69 63 61 74 65 0a 2a s not indicate.*
1f7e0 2a 20 74 68 61 74 20 74 68 65 20 64 61 74 61 62 * that the datab
1f7f0 61 73 65 20 69 73 20 64 65 66 69 6e 69 74 65 6c ase is definitel
1f800 79 20 63 6f 72 72 75 70 74 2c 20 6f 6e 6c 79 20 y corrupt, only
1f810 74 68 61 74 20 69 74 20 6d 69 67 68 74 20 62 65 that it might be
1f820 20 63 6f 72 72 75 70 74 2e 0a 2a 2a 20 46 6f 72 corrupt..** For
1f830 20 6d 6f 73 74 20 74 65 73 74 20 63 61 73 65 73 most test cases
1f840 2c 20 43 4f 52 52 55 50 54 5f 44 42 20 69 73 20 , CORRUPT_DB is
1f850 73 65 74 20 74 6f 20 66 61 6c 73 65 20 75 73 69 set to false usi
1f860 6e 67 20 61 20 73 70 65 63 69 61 6c 0a 2a 2a 20 ng a special.**
1f870 73 71 6c 69 74 65 33 5f 74 65 73 74 5f 63 6f 6e sqlite3_test_con
1f880 74 72 6f 6c 28 29 2e 20 20 54 68 69 73 20 65 6e trol(). This en
1f890 61 62 6c 65 73 20 61 73 73 65 72 74 28 29 20 73 ables assert() s
1f8a0 74 61 74 65 6d 65 6e 74 73 20 74 6f 20 70 72 6f tatements to pro
1f8b0 76 65 0a 2a 2a 20 74 68 69 6e 67 73 20 74 68 61 ve.** things tha
1f8c0 74 20 61 72 65 20 61 6c 77 61 79 73 20 74 72 75 t are always tru
1f8d0 65 20 66 6f 72 20 77 65 6c 6c 2d 66 6f 72 6d 65 e for well-forme
1f8e0 64 20 64 61 74 61 62 61 73 65 73 2e 0a 2a 2f 0a d databases..*/.
1f8f0 23 64 65 66 69 6e 65 20 43 4f 52 52 55 50 54 5f #define CORRUPT_
1f900 44 42 20 20 28 73 71 6c 69 74 65 33 43 6f 6e 66 DB (sqlite3Conf
1f910 69 67 2e 6e 65 76 65 72 43 6f 72 72 75 70 74 3d ig.neverCorrupt=
1f920 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6e 74 65 =0)../*.** Conte
1f930 78 74 20 70 6f 69 6e 74 65 72 20 70 61 73 73 65 xt pointer passe
1f940 64 20 64 6f 77 6e 20 74 68 72 6f 75 67 68 20 74 d down through t
1f950 68 65 20 74 72 65 65 2d 77 61 6c 6b 2e 0a 2a 2f he tree-walk..*/
1f960 0a 73 74 72 75 63 74 20 57 61 6c 6b 65 72 20 7b .struct Walker {
1f970 0a 20 20 69 6e 74 20 28 2a 78 45 78 70 72 43 61 . int (*xExprCa
1f980 6c 6c 62 61 63 6b 29 28 57 61 6c 6b 65 72 2a 2c llback)(Walker*,
1f990 20 45 78 70 72 2a 29 3b 20 20 20 20 20 2f 2a 20 Expr*); /*
1f9a0 43 61 6c 6c 62 61 63 6b 20 66 6f 72 20 65 78 70 Callback for exp
1f9b0 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e ressions */. in
1f9c0 74 20 28 2a 78 53 65 6c 65 63 74 43 61 6c 6c 62 t (*xSelectCallb
1f9d0 61 63 6b 29 28 57 61 6c 6b 65 72 2a 2c 53 65 6c ack)(Walker*,Sel
1f9e0 65 63 74 2a 29 3b 20 20 2f 2a 20 43 61 6c 6c 62 ect*); /* Callb
1f9f0 61 63 6b 20 66 6f 72 20 53 45 4c 45 43 54 73 20 ack for SELECTs
1fa00 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 53 65 6c */. void (*xSel
1fa10 65 63 74 43 61 6c 6c 62 61 63 6b 32 29 28 57 61 ectCallback2)(Wa
1fa20 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a 29 3b 2f lker*,Select*);/
1fa30 2a 20 53 65 63 6f 6e 64 20 63 61 6c 6c 62 61 63 * Second callbac
1fa40 6b 20 66 6f 72 20 53 45 4c 45 43 54 73 20 2a 2f k for SELECTs */
1fa50 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 73 65 . Parse *pParse
1fa60 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1fa70 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1fa80 50 61 72 73 65 72 20 63 6f 6e 74 65 78 74 2e 20 Parser context.
1fa90 20 2a 2f 0a 20 20 69 6e 74 20 77 61 6c 6b 65 72 */. int walker
1faa0 44 65 70 74 68 3b 20 20 20 20 20 20 20 20 20 20 Depth;
1fab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fac0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 75 62 /* Number of sub
1fad0 71 75 65 72 69 65 73 20 2a 2f 0a 20 20 75 38 20 queries */. u8
1fae0 65 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 eCode;
1faf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fb00 20 20 20 20 20 20 20 2f 2a 20 41 20 73 6d 61 6c /* A smal
1fb10 6c 20 70 72 6f 63 65 73 73 69 6e 67 20 63 6f 64 l processing cod
1fb20 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 20 20 e */. union {
1fb30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fb40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fb50 20 2f 2a 20 45 78 74 72 61 20 64 61 74 61 20 66 /* Extra data f
1fb60 6f 72 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 or callback */.
1fb70 20 20 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 2a NameContext *
1fb80 70 4e 43 3b 20 20 20 20 20 20 20 20 20 20 20 20 pNC;
1fb90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1fba0 20 4e 61 6d 69 6e 67 20 63 6f 6e 74 65 78 74 20 Naming context
1fbb0 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 3b 20 20 20 */. int n;
1fbc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fbd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fbe0 20 20 2f 2a 20 41 20 63 6f 75 6e 74 65 72 20 2a /* A counter *
1fbf0 2f 0a 20 20 20 20 69 6e 74 20 69 43 75 72 3b 20 /. int iCur;
1fc00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fc10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fc20 20 2f 2a 20 41 20 63 75 72 73 6f 72 20 6e 75 6d /* A cursor num
1fc30 62 65 72 20 2a 2f 0a 20 20 20 20 53 72 63 4c 69 ber */. SrcLi
1fc40 73 74 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 20 st *pSrcList;
1fc50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fc60 20 20 20 20 20 20 2f 2a 20 46 52 4f 4d 20 63 6c /* FROM cl
1fc70 61 75 73 65 20 2a 2f 0a 20 20 20 20 73 74 72 75 ause */. stru
1fc80 63 74 20 53 72 63 43 6f 75 6e 74 20 2a 70 53 72 ct SrcCount *pSr
1fc90 63 43 6f 75 6e 74 3b 20 20 20 20 20 20 20 20 20 cCount;
1fca0 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 69 /* Counti
1fcb0 6e 67 20 63 6f 6c 75 6d 6e 20 72 65 66 65 72 65 ng column refere
1fcc0 6e 63 65 73 20 2a 2f 0a 20 20 7d 20 75 3b 0a 7d nces */. } u;.}
1fcd0 3b 0a 0a 2f 2a 20 46 6f 72 77 61 72 64 20 64 65 ;../* Forward de
1fce0 63 6c 61 72 61 74 69 6f 6e 73 20 2a 2f 0a 69 6e clarations */.in
1fcf0 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 70 t sqlite3WalkExp
1fd00 72 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a r(Walker*, Expr*
1fd10 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 );.int sqlite3Wa
1fd20 6c 6b 45 78 70 72 4c 69 73 74 28 57 61 6c 6b 65 lkExprList(Walke
1fd30 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a r*, ExprList*);.
1fd40 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 int sqlite3WalkS
1fd50 65 6c 65 63 74 28 57 61 6c 6b 65 72 2a 2c 20 53 elect(Walker*, S
1fd60 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
1fd70 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 45 78 ite3WalkSelectEx
1fd80 70 72 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 pr(Walker*, Sele
1fd90 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ct*);.int sqlite
1fda0 33 57 61 6c 6b 53 65 6c 65 63 74 46 72 6f 6d 28 3WalkSelectFrom(
1fdb0 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a Walker*, Select*
1fdc0 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e );../*.** Return
1fdd0 20 63 6f 64 65 20 66 72 6f 6d 20 74 68 65 20 70 code from the p
1fde0 61 72 73 65 2d 74 72 65 65 20 77 61 6c 6b 69 6e arse-tree walkin
1fdf0 67 20 70 72 69 6d 69 74 69 76 65 73 20 61 6e 64 g primitives and
1fe00 20 74 68 65 69 72 0a 2a 2a 20 63 61 6c 6c 62 61 their.** callba
1fe10 63 6b 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 cks..*/.#define
1fe20 57 52 43 5f 43 6f 6e 74 69 6e 75 65 20 20 20 20 WRC_Continue
1fe30 30 20 20 20 2f 2a 20 43 6f 6e 74 69 6e 75 65 20 0 /* Continue
1fe40 64 6f 77 6e 20 69 6e 74 6f 20 63 68 69 6c 64 72 down into childr
1fe50 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 52 en */.#define WR
1fe60 43 5f 50 72 75 6e 65 20 20 20 20 20 20 20 31 20 C_Prune 1
1fe70 20 20 2f 2a 20 4f 6d 69 74 20 63 68 69 6c 64 72 /* Omit childr
1fe80 65 6e 20 62 75 74 20 63 6f 6e 74 69 6e 75 65 20 en but continue
1fe90 77 61 6c 6b 69 6e 67 20 73 69 62 6c 69 6e 67 73 walking siblings
1fea0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 52 43 5f */.#define WRC_
1feb0 41 62 6f 72 74 20 20 20 20 20 20 20 32 20 20 20 Abort 2
1fec0 2f 2a 20 41 62 61 6e 64 6f 6e 20 74 68 65 20 74 /* Abandon the t
1fed0 72 65 65 20 77 61 6c 6b 20 2a 2f 0a 0a 2f 2a 0a ree walk */../*.
1fee0 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
1fef0 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
1ff00 20 72 65 70 72 65 73 65 6e 74 73 20 61 20 73 65 represents a se
1ff10 74 20 6f 66 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 t of one or more
1ff20 20 43 54 45 73 0a 2a 2a 20 28 63 6f 6d 6d 6f 6e CTEs.** (common
1ff30 20 74 61 62 6c 65 20 65 78 70 72 65 73 73 69 6f table expressio
1ff40 6e 73 29 20 63 72 65 61 74 65 64 20 62 79 20 61 ns) created by a
1ff50 20 73 69 6e 67 6c 65 20 57 49 54 48 20 63 6c 61 single WITH cla
1ff60 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 use..*/.struct W
1ff70 69 74 68 20 7b 0a 20 20 69 6e 74 20 6e 43 74 65 ith {. int nCte
1ff80 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1ff90 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1ffa0 72 20 6f 66 20 43 54 45 73 20 69 6e 20 74 68 65 r of CTEs in the
1ffb0 20 57 49 54 48 20 63 6c 61 75 73 65 20 2a 2f 0a WITH clause */.
1ffc0 20 20 57 69 74 68 20 2a 70 4f 75 74 65 72 3b 20 With *pOuter;
1ffd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ffe0 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 69 6e 67 20 /* Containing
1fff0 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 20 WITH clause, or
20000 4e 55 4c 4c 20 2a 2f 0a 20 20 73 74 72 75 63 74 NULL */. struct
20010 20 43 74 65 20 7b 20 20 20 20 20 20 20 20 20 20 Cte {
20020 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 6f 72 /* For
20030 20 65 61 63 68 20 43 54 45 20 69 6e 20 74 68 65 each CTE in the
20040 20 57 49 54 48 20 63 6c 61 75 73 65 2e 2e 2e 2e WITH clause....
20050 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e */. char *zN
20060 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
20070 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 /* Name
20080 6f 66 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 of this CTE */.
20090 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 43 6f ExprList *pCo
200a0 6c 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ls;
200b0 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 65 78 /* List of ex
200c0 70 6c 69 63 69 74 20 63 6f 6c 75 6d 6e 20 6e 61 plicit column na
200d0 6d 65 73 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a mes, or NULL */.
200e0 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c Select *pSel
200f0 65 63 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ect;
20100 20 20 20 20 2f 2a 20 54 68 65 20 64 65 66 69 6e /* The defin
20110 69 74 69 6f 6e 20 6f 66 20 74 68 69 73 20 43 54 ition of this CT
20120 45 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 20 63 E */. const c
20130 68 61 72 20 2a 7a 45 72 72 3b 20 20 20 20 20 20 har *zErr;
20140 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 72 6f /* Erro
20150 72 20 6d 65 73 73 61 67 65 20 66 6f 72 20 63 69 r message for ci
20160 72 63 75 6c 61 72 20 72 65 66 65 72 65 6e 63 65 rcular reference
20170 73 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 0a 7d s */. } a[1];.}
20180 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
20190 5f 44 45 42 55 47 0a 2f 2a 0a 2a 2a 20 41 6e 20 _DEBUG./*.** An
201a0 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
201b0 54 72 65 65 56 69 65 77 20 6f 62 6a 65 63 74 20 TreeView object
201c0 69 73 20 75 73 65 64 20 66 6f 72 20 70 72 69 6e is used for prin
201d0 74 69 6e 67 20 74 68 65 20 63 6f 6e 74 65 6e 74 ting the content
201e0 20 6f 66 0a 2a 2a 20 64 61 74 61 20 73 74 72 75 of.** data stru
201f0 63 74 75 72 65 73 20 6f 6e 20 73 71 6c 69 74 65 ctures on sqlite
20200 33 44 65 62 75 67 50 72 69 6e 74 66 28 29 20 75 3DebugPrintf() u
20210 73 69 6e 67 20 61 20 74 72 65 65 2d 6c 69 6b 65 sing a tree-like
20220 20 76 69 65 77 2e 0a 2a 2f 0a 73 74 72 75 63 74 view..*/.struct
20230 20 54 72 65 65 56 69 65 77 20 7b 0a 20 20 69 6e TreeView {. in
20240 74 20 69 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 t iLevel;
20250 20 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 6c /* Which l
20260 65 76 65 6c 20 6f 66 20 74 68 65 20 74 72 65 65 evel of the tree
20270 20 77 65 20 61 72 65 20 6f 6e 20 2a 2f 0a 20 20 we are on */.
20280 75 38 20 20 62 4c 69 6e 65 5b 31 30 30 5d 3b 20 u8 bLine[100];
20290 20 20 20 20 20 20 20 20 2f 2a 20 44 72 61 77 20 /* Draw
202a0 76 65 72 74 69 63 61 6c 20 69 6e 20 63 6f 6c 75 vertical in colu
202b0 6d 6e 20 69 20 69 66 20 62 4c 69 6e 65 5b 69 5d mn i if bLine[i]
202c0 20 69 73 20 74 72 75 65 20 2a 2f 0a 7d 3b 0a 23 is true */.};.#
202d0 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 54 45 5f endif /* SQLITE_
202e0 44 45 42 55 47 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 DEBUG */../*.**
202f0 41 73 73 75 6d 69 6e 67 20 7a 49 6e 20 70 6f 69 Assuming zIn poi
20300 6e 74 73 20 74 6f 20 74 68 65 20 66 69 72 73 74 nts to the first
20310 20 62 79 74 65 20 6f 66 20 61 20 55 54 46 2d 38 byte of a UTF-8
20320 20 63 68 61 72 61 63 74 65 72 2c 0a 2a 2a 20 61 character,.** a
20330 64 76 61 6e 63 65 20 7a 49 6e 20 74 6f 20 70 6f dvance zIn to po
20340 69 6e 74 20 74 6f 20 74 68 65 20 66 69 72 73 74 int to the first
20350 20 62 79 74 65 20 6f 66 20 74 68 65 20 6e 65 78 byte of the nex
20360 74 20 55 54 46 2d 38 20 63 68 61 72 61 63 74 65 t UTF-8 characte
20370 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 r..*/.#define SQ
20380 4c 49 54 45 5f 53 4b 49 50 5f 55 54 46 38 28 7a LITE_SKIP_UTF8(z
20390 49 6e 29 20 7b 20 20 20 20 20 20 20 20 20 20 20 In) {
203a0 20 20 20 20 20 20 20 20 20 20 20 20 20 5c 0a 20 \.
203b0 20 69 66 28 20 28 2a 28 7a 49 6e 2b 2b 29 29 3e if( (*(zIn++))>
203c0 3d 30 78 63 30 20 29 7b 20 20 20 20 20 20 20 20 =0xc0 ){
203d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
203e0 20 20 20 20 20 20 5c 0a 20 20 20 20 77 68 69 6c \. whil
203f0 65 28 20 28 2a 7a 49 6e 20 26 20 30 78 63 30 29 e( (*zIn & 0xc0)
20400 3d 3d 30 78 38 30 20 29 7b 20 7a 49 6e 2b 2b 3b ==0x80 ){ zIn++;
20410 20 7d 20 20 20 20 20 20 20 20 20 20 20 20 20 5c } \
20420 0a 20 20 7d 20 20 20 20 20 20 20 20 20 20 20 20 . }
20430 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20440 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20450 20 20 20 20 20 20 20 20 5c 0a 7d 0a 0a 2f 2a 0a \.}../*.
20460 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 2a 5f ** The SQLITE_*_
20470 42 4b 50 54 20 6d 61 63 72 6f 73 20 61 72 65 20 BKPT macros are
20480 73 75 62 73 74 69 74 75 74 65 73 20 66 6f 72 20 substitutes for
20490 74 68 65 20 65 72 72 6f 72 20 63 6f 64 65 73 20 the error codes
204a0 77 69 74 68 0a 2a 2a 20 74 68 65 20 73 61 6d 65 with.** the same
204b0 20 6e 61 6d 65 20 62 75 74 20 77 69 74 68 6f 75 name but withou
204c0 74 20 74 68 65 20 5f 42 4b 50 54 20 73 75 66 66 t the _BKPT suff
204d0 69 78 2e 20 20 54 68 65 73 65 20 6d 61 63 72 6f ix. These macro
204e0 73 20 69 6e 76 6f 6b 65 0a 2a 2a 20 72 6f 75 74 s invoke.** rout
204f0 69 6e 65 73 20 74 68 61 74 20 72 65 70 6f 72 74 ines that report
20500 20 74 68 65 20 6c 69 6e 65 2d 6e 75 6d 62 65 72 the line-number
20510 20 6f 6e 20 77 68 69 63 68 20 74 68 65 20 65 72 on which the er
20520 72 6f 72 20 6f 72 69 67 69 6e 61 74 65 64 0a 2a ror originated.*
20530 2a 20 75 73 69 6e 67 20 73 71 6c 69 74 65 33 5f * using sqlite3_
20540 6c 6f 67 28 29 2e 20 20 54 68 65 20 72 6f 75 74 log(). The rout
20550 69 6e 65 73 20 61 6c 73 6f 20 70 72 6f 76 69 64 ines also provid
20560 65 20 61 20 63 6f 6e 76 65 6e 69 65 6e 74 20 70 e a convenient p
20570 6c 61 63 65 0a 2a 2a 20 74 6f 20 73 65 74 20 61 lace.** to set a
20580 20 64 65 62 75 67 67 65 72 20 62 72 65 61 6b 70 debugger breakp
20590 6f 69 6e 74 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c oint..*/.int sql
205a0 69 74 65 33 43 6f 72 72 75 70 74 45 72 72 6f 72 ite3CorruptError
205b0 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 (int);.int sqlit
205c0 65 33 4d 69 73 75 73 65 45 72 72 6f 72 28 69 6e e3MisuseError(in
205d0 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 t);.int sqlite3C
205e0 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 69 6e 74 antopenError(int
205f0 29 3b 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 );.#define SQLIT
20600 45 5f 43 4f 52 52 55 50 54 5f 42 4b 50 54 20 73 E_CORRUPT_BKPT s
20610 71 6c 69 74 65 33 43 6f 72 72 75 70 74 45 72 72 qlite3CorruptErr
20620 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 65 or(__LINE__).#de
20630 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 49 53 55 fine SQLITE_MISU
20640 53 45 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 4d SE_BKPT sqlite3M
20650 69 73 75 73 65 45 72 72 6f 72 28 5f 5f 4c 49 4e isuseError(__LIN
20660 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 4c E__).#define SQL
20670 49 54 45 5f 43 41 4e 54 4f 50 45 4e 5f 42 4b 50 ITE_CANTOPEN_BKP
20680 54 20 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 T sqlite3Cantope
20690 6e 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 nError(__LINE__)
206a0 0a 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 34 20 69 73 .../*.** FTS4 is
206b0 20 72 65 61 6c 6c 79 20 61 6e 20 65 78 74 65 6e really an exten
206c0 73 69 6f 6e 20 66 6f 72 20 46 54 53 33 2e 20 20 sion for FTS3.
206d0 49 74 20 69 73 20 65 6e 61 62 6c 65 64 20 75 73 It is enabled us
206e0 69 6e 67 20 74 68 65 0a 2a 2a 20 53 51 4c 49 54 ing the.** SQLIT
206f0 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 6d 61 E_ENABLE_FTS3 ma
20700 63 72 6f 2e 20 20 42 75 74 20 74 6f 20 61 76 6f cro. But to avo
20710 69 64 20 63 6f 6e 66 75 73 69 6f 6e 20 77 65 20 id confusion we
20720 61 6c 73 6f 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 also call.** the
20730 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 SQLITE_ENABLE_F
20740 54 53 34 20 6d 61 63 72 6f 20 74 6f 20 73 65 72 TS4 macro to ser
20750 76 65 20 61 73 20 61 6e 20 61 6c 69 61 73 20 66 ve as an alias f
20760 6f 72 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 or SQLITE_ENABLE
20770 5f 46 54 53 33 2e 0a 2a 2f 0a 23 69 66 20 64 65 _FTS3..*/.#if de
20780 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
20790 42 4c 45 5f 46 54 53 34 29 20 26 26 20 21 64 65 BLE_FTS4) && !de
207a0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
207b0 42 4c 45 5f 46 54 53 33 29 0a 23 20 64 65 66 69 BLE_FTS3).# defi
207c0 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ne SQLITE_ENABLE
207d0 5f 46 54 53 33 20 31 0a 23 65 6e 64 69 66 0a 0a _FTS3 1.#endif..
207e0 2f 2a 0a 2a 2a 20 54 68 65 20 63 74 79 70 65 2e /*.** The ctype.
207f0 68 20 68 65 61 64 65 72 20 69 73 20 6e 65 65 64 h header is need
20800 65 64 20 66 6f 72 20 6e 6f 6e 2d 41 53 43 49 49 ed for non-ASCII
20810 20 73 79 73 74 65 6d 73 2e 20 20 49 74 20 69 73 systems. It is
20820 20 61 6c 73 6f 0a 2a 2a 20 6e 65 65 64 65 64 20 also.** needed
20830 62 79 20 46 54 53 33 20 77 68 65 6e 20 46 54 53 by FTS3 when FTS
20840 33 20 69 73 20 69 6e 63 6c 75 64 65 64 20 69 6e 3 is included in
20850 20 74 68 65 20 61 6d 61 6c 67 61 6d 61 74 69 6f the amalgamatio
20860 6e 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e n..*/.#if !defin
20870 65 64 28 53 51 4c 49 54 45 5f 41 53 43 49 49 29 ed(SQLITE_ASCII)
20880 20 7c 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 6e || \. (defin
20890 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ed(SQLITE_ENABLE
208a0 5f 46 54 53 33 29 20 26 26 20 64 65 66 69 6e 65 _FTS3) && define
208b0 64 28 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d d(SQLITE_AMALGAM
208c0 41 54 49 4f 4e 29 29 0a 23 20 69 6e 63 6c 75 64 ATION)).# includ
208d0 65 20 3c 63 74 79 70 65 2e 68 3e 0a 23 65 6e 64 e <ctype.h>.#end
208e0 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f if../*.** The fo
208f0 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 6d llowing macros m
20900 69 6d 69 63 20 74 68 65 20 73 74 61 6e 64 61 72 imic the standar
20910 64 20 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 d library functi
20920 6f 6e 73 20 74 6f 75 70 70 65 72 28 29 2c 0a 2a ons toupper(),.*
20930 2a 20 69 73 73 70 61 63 65 28 29 2c 20 69 73 61 * isspace(), isa
20940 6c 6e 75 6d 28 29 2c 20 69 73 64 69 67 69 74 28 lnum(), isdigit(
20950 29 20 61 6e 64 20 69 73 78 64 69 67 69 74 28 29 ) and isxdigit()
20960 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 , respectively.
20970 54 68 65 0a 2a 2a 20 73 71 6c 69 74 65 20 76 65 The.** sqlite ve
20980 72 73 69 6f 6e 73 20 6f 6e 6c 79 20 77 6f 72 6b rsions only work
20990 20 66 6f 72 20 41 53 43 49 49 20 63 68 61 72 61 for ASCII chara
209a0 63 74 65 72 73 2c 20 72 65 67 61 72 64 6c 65 73 cters, regardles
209b0 73 20 6f 66 20 6c 6f 63 61 6c 65 2e 0a 2a 2f 0a s of locale..*/.
209c0 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 41 53 #ifdef SQLITE_AS
209d0 43 49 49 0a 23 20 64 65 66 69 6e 65 20 73 71 6c CII.# define sql
209e0 69 74 65 33 54 6f 75 70 70 65 72 28 78 29 20 20 ite3Toupper(x)
209f0 28 28 78 29 26 7e 28 73 71 6c 69 74 65 33 43 74 ((x)&~(sqlite3Ct
20a00 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
20a10 20 63 68 61 72 29 28 78 29 5d 26 30 78 32 30 29 char)(x)]&0x20)
20a20 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
20a30 65 33 49 73 73 70 61 63 65 28 78 29 20 20 20 28 e3Isspace(x) (
20a40 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b sqlite3CtypeMap[
20a50 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
20a60 78 29 5d 26 30 78 30 31 29 0a 23 20 64 65 66 69 x)]&0x01).# defi
20a70 6e 65 20 73 71 6c 69 74 65 33 49 73 61 6c 6e 75 ne sqlite3Isalnu
20a80 6d 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 m(x) (sqlite3C
20a90 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 typeMap[(unsigne
20aa0 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 36 d char)(x)]&0x06
20ab0 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
20ac0 65 33 49 73 61 6c 70 68 61 28 78 29 20 20 20 28 e3Isalpha(x) (
20ad0 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b sqlite3CtypeMap[
20ae0 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
20af0 78 29 5d 26 30 78 30 32 29 0a 23 20 64 65 66 69 x)]&0x02).# defi
20b00 6e 65 20 73 71 6c 69 74 65 33 49 73 64 69 67 69 ne sqlite3Isdigi
20b10 74 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 t(x) (sqlite3C
20b20 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 typeMap[(unsigne
20b30 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 34 d char)(x)]&0x04
20b40 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
20b50 65 33 49 73 78 64 69 67 69 74 28 78 29 20 20 28 e3Isxdigit(x) (
20b60 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b sqlite3CtypeMap[
20b70 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
20b80 78 29 5d 26 30 78 30 38 29 0a 23 20 64 65 66 69 x)]&0x08).# defi
20b90 6e 65 20 73 71 6c 69 74 65 33 54 6f 6c 6f 77 65 ne sqlite3Tolowe
20ba0 72 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 55 r(x) (sqlite3U
20bb0 70 70 65 72 54 6f 4c 6f 77 65 72 5b 28 75 6e 73 pperToLower[(uns
20bc0 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 29 igned char)(x)])
20bd0 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
20be0 73 71 6c 69 74 65 33 54 6f 75 70 70 65 72 28 78 sqlite3Toupper(x
20bf0 29 20 20 20 74 6f 75 70 70 65 72 28 28 75 6e 73 ) toupper((uns
20c00 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
20c10 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
20c20 49 73 73 70 61 63 65 28 78 29 20 20 20 69 73 73 Isspace(x) iss
20c30 70 61 63 65 28 28 75 6e 73 69 67 6e 65 64 20 63 pace((unsigned c
20c40 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
20c50 65 20 73 71 6c 69 74 65 33 49 73 61 6c 6e 75 6d e sqlite3Isalnum
20c60 28 78 29 20 20 20 69 73 61 6c 6e 75 6d 28 28 75 (x) isalnum((u
20c70 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
20c80 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
20c90 65 33 49 73 61 6c 70 68 61 28 78 29 20 20 20 69 e3Isalpha(x) i
20ca0 73 61 6c 70 68 61 28 28 75 6e 73 69 67 6e 65 64 salpha((unsigned
20cb0 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 char)(x)).# def
20cc0 69 6e 65 20 73 71 6c 69 74 65 33 49 73 64 69 67 ine sqlite3Isdig
20cd0 69 74 28 78 29 20 20 20 69 73 64 69 67 69 74 28 it(x) isdigit(
20ce0 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
20cf0 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c x)).# define sql
20d00 69 74 65 33 49 73 78 64 69 67 69 74 28 78 29 20 ite3Isxdigit(x)
20d10 20 69 73 78 64 69 67 69 74 28 28 75 6e 73 69 67 isxdigit((unsig
20d20 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 ned char)(x)).#
20d30 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f define sqlite3To
20d40 6c 6f 77 65 72 28 78 29 20 20 20 74 6f 6c 6f 77 lower(x) tolow
20d50 65 72 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er((unsigned cha
20d60 72 29 28 78 29 29 0a 23 65 6e 64 69 66 0a 69 6e r)(x)).#endif.in
20d70 74 20 73 71 6c 69 74 65 33 49 73 49 64 43 68 61 t sqlite3IsIdCha
20d80 72 28 75 38 29 3b 0a 0a 2f 2a 0a 2a 2a 20 49 6e r(u8);../*.** In
20d90 74 65 72 6e 61 6c 20 66 75 6e 63 74 69 6f 6e 20 ternal function
20da0 70 72 6f 74 6f 74 79 70 65 73 0a 2a 2f 0a 23 64 prototypes.*/.#d
20db0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 72 efine sqlite3Str
20dc0 49 43 6d 70 20 73 71 6c 69 74 65 33 5f 73 74 72 ICmp sqlite3_str
20dd0 69 63 6d 70 0a 69 6e 74 20 73 71 6c 69 74 65 33 icmp.int sqlite3
20de0 53 74 72 6c 65 6e 33 30 28 63 6f 6e 73 74 20 63 Strlen30(const c
20df0 68 61 72 2a 29 3b 0a 23 64 65 66 69 6e 65 20 73 har*);.#define s
20e00 71 6c 69 74 65 33 53 74 72 4e 49 43 6d 70 20 73 qlite3StrNICmp s
20e10 71 6c 69 74 65 33 5f 73 74 72 6e 69 63 6d 70 0a qlite3_strnicmp.
20e20 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c .int sqlite3Mall
20e30 6f 63 49 6e 69 74 28 76 6f 69 64 29 3b 0a 76 6f ocInit(void);.vo
20e40 69 64 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 id sqlite3Malloc
20e50 45 6e 64 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 End(void);.void
20e60 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 28 75 *sqlite3Malloc(u
20e70 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 64);.void *sqlit
20e80 65 33 4d 61 6c 6c 6f 63 5a 65 72 6f 28 75 36 34 e3MallocZero(u64
20e90 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
20ea0 44 62 4d 61 6c 6c 6f 63 5a 65 72 6f 28 73 71 6c DbMallocZero(sql
20eb0 69 74 65 33 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 ite3*, u64);.voi
20ec0 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c d *sqlite3DbMall
20ed0 6f 63 52 61 77 28 73 71 6c 69 74 65 33 2a 2c 20 ocRaw(sqlite3*,
20ee0 75 36 34 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 u64);.char *sqli
20ef0 74 65 33 44 62 53 74 72 44 75 70 28 73 71 6c 69 te3DbStrDup(sqli
20f00 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
20f10 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
20f20 44 62 53 74 72 4e 44 75 70 28 73 71 6c 69 74 65 DbStrNDup(sqlite
20f30 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 3*,const char*,
20f40 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 u64);.void *sqli
20f50 74 65 33 52 65 61 6c 6c 6f 63 28 76 6f 69 64 2a te3Realloc(void*
20f60 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 , u64);.void *sq
20f70 6c 69 74 65 33 44 62 52 65 61 6c 6c 6f 63 4f 72 lite3DbReallocOr
20f80 46 72 65 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 Free(sqlite3 *,
20f90 76 6f 69 64 20 2a 2c 20 75 36 34 29 3b 0a 76 6f void *, u64);.vo
20fa0 69 64 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 id *sqlite3DbRea
20fb0 6c 6c 6f 63 28 73 71 6c 69 74 65 33 20 2a 2c 20 lloc(sqlite3 *,
20fc0 76 6f 69 64 20 2a 2c 20 75 36 34 29 3b 0a 76 6f void *, u64);.vo
20fd0 69 64 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 id sqlite3DbFree
20fe0 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a (sqlite3*, void*
20ff0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 );.int sqlite3Ma
21000 6c 6c 6f 63 53 69 7a 65 28 76 6f 69 64 2a 29 3b llocSize(void*);
21010 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 4d 61 .int sqlite3DbMa
21020 6c 6c 6f 63 53 69 7a 65 28 73 71 6c 69 74 65 33 llocSize(sqlite3
21030 2a 2c 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 *, void*);.void
21040 2a 73 71 6c 69 74 65 33 53 63 72 61 74 63 68 4d *sqlite3ScratchM
21050 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f 69 64 alloc(int);.void
21060 20 73 71 6c 69 74 65 33 53 63 72 61 74 63 68 46 sqlite3ScratchF
21070 72 65 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 ree(void*);.void
21080 20 2a 73 71 6c 69 74 65 33 50 61 67 65 4d 61 6c *sqlite3PageMal
21090 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 loc(int);.void s
210a0 71 6c 69 74 65 33 50 61 67 65 46 72 65 65 28 76 qlite3PageFree(v
210b0 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 oid*);.void sqli
210c0 74 65 33 4d 65 6d 53 65 74 44 65 66 61 75 6c 74 te3MemSetDefault
210d0 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c (void);.void sql
210e0 69 74 65 33 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 ite3BenignMalloc
210f0 48 6f 6f 6b 73 28 76 6f 69 64 20 28 2a 29 28 76 Hooks(void (*)(v
21100 6f 69 64 29 2c 20 76 6f 69 64 20 28 2a 29 28 76 oid), void (*)(v
21110 6f 69 64 29 29 3b 0a 69 6e 74 20 73 71 6c 69 74 oid));.int sqlit
21120 65 33 48 65 61 70 4e 65 61 72 6c 79 46 75 6c 6c e3HeapNearlyFull
21130 28 76 6f 69 64 29 3b 0a 0a 2f 2a 0a 2a 2a 20 4f (void);../*.** O
21140 6e 20 73 79 73 74 65 6d 73 20 77 69 74 68 20 61 n systems with a
21150 6d 70 6c 65 20 73 74 61 63 6b 20 73 70 61 63 65 mple stack space
21160 20 61 6e 64 20 74 68 61 74 20 73 75 70 70 6f 72 and that suppor
21170 74 20 61 6c 6c 6f 63 61 28 29 2c 20 6d 61 6b 65 t alloca(), make
21180 0a 2a 2a 20 75 73 65 20 6f 66 20 61 6c 6c 6f 63 .** use of alloc
21190 61 28 29 20 74 6f 20 6f 62 74 61 69 6e 20 73 70 a() to obtain sp
211a0 61 63 65 20 66 6f 72 20 6c 61 72 67 65 20 61 75 ace for large au
211b0 74 6f 6d 61 74 69 63 20 6f 62 6a 65 63 74 73 2e tomatic objects.
211c0 20 20 42 79 20 64 65 66 61 75 6c 74 2c 0a 2a 2a By default,.**
211d0 20 6f 62 74 61 69 6e 20 73 70 61 63 65 20 66 72 obtain space fr
211e0 6f 6d 20 6d 61 6c 6c 6f 63 28 29 2e 0a 2a 2a 0a om malloc()..**.
211f0 2a 2a 20 54 68 65 20 61 6c 6c 6f 63 61 28 29 20 ** The alloca()
21200 72 6f 75 74 69 6e 65 20 6e 65 76 65 72 20 72 65 routine never re
21210 74 75 72 6e 73 20 4e 55 4c 4c 2e 20 20 54 68 69 turns NULL. Thi
21220 73 20 77 69 6c 6c 20 63 61 75 73 65 20 63 6f 64 s will cause cod
21230 65 20 70 61 74 68 73 0a 2a 2a 20 74 68 61 74 20 e paths.** that
21240 64 65 61 6c 20 77 69 74 68 20 73 71 6c 69 74 65 deal with sqlite
21250 33 53 74 61 63 6b 41 6c 6c 6f 63 28 29 20 66 61 3StackAlloc() fa
21260 69 6c 75 72 65 73 20 74 6f 20 62 65 20 75 6e 72 ilures to be unr
21270 65 61 63 68 61 62 6c 65 2e 0a 2a 2f 0a 23 69 66 eachable..*/.#if
21280 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 5f 41 def SQLITE_USE_A
21290 4c 4c 4f 43 41 0a 23 20 64 65 66 69 6e 65 20 73 LLOCA.# define s
212a0 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 qlite3StackAlloc
212b0 52 61 77 28 44 2c 4e 29 20 20 20 61 6c 6c 6f 63 Raw(D,N) alloc
212c0 61 28 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 a(N).# define sq
212d0 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 5a lite3StackAllocZ
212e0 65 72 6f 28 44 2c 4e 29 20 20 6d 65 6d 73 65 74 ero(D,N) memset
212f0 28 61 6c 6c 6f 63 61 28 4e 29 2c 20 30 2c 20 4e (alloca(N), 0, N
21300 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
21310 65 33 53 74 61 63 6b 46 72 65 65 28 44 2c 50 29 e3StackFree(D,P)
21320 20 20 20 20 20 20 20 0a 23 65 6c 73 65 0a 23 20 .#else.#
21330 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 define sqlite3St
21340 61 63 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 ackAllocRaw(D,N)
21350 20 20 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c sqlite3DbMall
21360 6f 63 52 61 77 28 44 2c 4e 29 0a 23 20 64 65 66 ocRaw(D,N).# def
21370 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b ine sqlite3Stack
21380 41 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 AllocZero(D,N)
21390 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a sqlite3DbMallocZ
213a0 65 72 6f 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e ero(D,N).# defin
213b0 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 e sqlite3StackFr
213c0 65 65 28 44 2c 50 29 20 20 20 20 20 20 20 73 71 ee(D,P) sq
213d0 6c 69 74 65 33 44 62 46 72 65 65 28 44 2c 50 29 lite3DbFree(D,P)
213e0 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
213f0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 SQLITE_ENABLE_ME
21400 4d 53 59 53 33 0a 63 6f 6e 73 74 20 73 71 6c 69 MSYS3.const sqli
21410 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 te3_mem_methods
21420 2a 73 71 6c 69 74 65 33 4d 65 6d 47 65 74 4d 65 *sqlite3MemGetMe
21430 6d 73 79 73 33 28 76 6f 69 64 29 3b 0a 23 65 6e msys3(void);.#en
21440 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 dif.#ifdef SQLIT
21450 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 35 E_ENABLE_MEMSYS5
21460 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d .const sqlite3_m
21470 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 em_methods *sqli
21480 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 35 te3MemGetMemsys5
21490 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 0a (void);.#endif..
214a0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
214b0 4d 55 54 45 58 5f 4f 4d 49 54 0a 20 20 73 71 6c MUTEX_OMIT. sql
214c0 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f ite3_mutex_metho
214d0 64 73 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 ds const *sqlite
214e0 33 44 65 66 61 75 6c 74 4d 75 74 65 78 28 76 6f 3DefaultMutex(vo
214f0 69 64 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d id);. sqlite3_m
21500 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e utex_methods con
21510 73 74 20 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 4d st *sqlite3NoopM
21520 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 utex(void);. sq
21530 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c lite3_mutex *sql
21540 69 74 65 33 4d 75 74 65 78 41 6c 6c 6f 63 28 69 ite3MutexAlloc(i
21550 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 nt);. int sqlit
21560 65 33 4d 75 74 65 78 49 6e 69 74 28 76 6f 69 64 e3MutexInit(void
21570 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
21580 4d 75 74 65 78 45 6e 64 28 76 6f 69 64 29 3b 0a MutexEnd(void);.
21590 23 65 6e 64 69 66 0a 0a 73 71 6c 69 74 65 33 5f #endif..sqlite3_
215a0 69 6e 74 36 34 20 73 71 6c 69 74 65 33 53 74 61 int64 sqlite3Sta
215b0 74 75 73 56 61 6c 75 65 28 69 6e 74 29 3b 0a 76 tusValue(int);.v
215c0 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 oid sqlite3Statu
215d0 73 55 70 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 sUp(int, int);.v
215e0 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 oid sqlite3Statu
215f0 73 44 6f 77 6e 28 69 6e 74 2c 20 69 6e 74 29 3b sDown(int, int);
21600 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 .void sqlite3Sta
21610 74 75 73 53 65 74 28 69 6e 74 2c 20 69 6e 74 29 tusSet(int, int)
21620 3b 0a 0a 2f 2a 20 41 63 63 65 73 73 20 74 6f 20 ;../* Access to
21630 6d 75 74 65 78 65 73 20 75 73 65 64 20 62 79 20 mutexes used by
21640 73 71 6c 69 74 65 33 5f 73 74 61 74 75 73 28 29 sqlite3_status()
21650 20 2a 2f 0a 73 71 6c 69 74 65 33 5f 6d 75 74 65 */.sqlite3_mute
21660 78 20 2a 73 71 6c 69 74 65 33 50 63 61 63 68 65 x *sqlite3Pcache
21670 31 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 73 71 1Mutex(void);.sq
21680 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c lite3_mutex *sql
21690 69 74 65 33 4d 61 6c 6c 6f 63 4d 75 74 65 78 28 ite3MallocMutex(
216a0 76 6f 69 64 29 3b 0a 0a 23 69 66 6e 64 65 66 20 void);..#ifndef
216b0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 SQLITE_OMIT_FLOA
216c0 54 49 4e 47 5f 50 4f 49 4e 54 0a 20 20 69 6e 74 TING_POINT. int
216d0 20 73 71 6c 69 74 65 33 49 73 4e 61 4e 28 64 6f sqlite3IsNaN(do
216e0 75 62 6c 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 uble);.#else.# d
216f0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e efine sqlite3IsN
21700 61 4e 28 58 29 20 20 30 0a 23 65 6e 64 69 66 0a aN(X) 0.#endif.
21710 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
21720 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ce of the follow
21730 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 68 6f ing structure ho
21740 6c 64 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 lds information
21750 61 62 6f 75 74 20 53 51 4c 0a 2a 2a 20 66 75 6e about SQL.** fun
21760 63 74 69 6f 6e 73 20 61 72 67 75 6d 65 6e 74 73 ctions arguments
21770 20 74 68 61 74 20 61 72 65 20 74 68 65 20 70 61 that are the pa
21780 72 61 6d 65 74 65 72 73 20 74 6f 20 74 68 65 20 rameters to the
21790 70 72 69 6e 74 66 28 29 20 66 75 6e 63 74 69 6f printf() functio
217a0 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 50 72 69 n..*/.struct Pri
217b0 6e 74 66 41 72 67 75 6d 65 6e 74 73 20 7b 0a 20 ntfArguments {.
217c0 20 69 6e 74 20 6e 41 72 67 3b 20 20 20 20 20 20 int nArg;
217d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 74 /* Tot
217e0 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 al number of arg
217f0 75 6d 65 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 uments */. int
21800 6e 55 73 65 64 3b 20 20 20 20 20 20 20 20 20 20 nUsed;
21810 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
21820 66 20 61 72 67 75 6d 65 6e 74 73 20 75 73 65 64 f arguments used
21830 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 73 71 6c so far */. sql
21840 69 74 65 33 5f 76 61 6c 75 65 20 2a 2a 61 70 41 ite3_value **apA
21850 72 67 3b 20 20 20 2f 2a 20 54 68 65 20 61 72 67 rg; /* The arg
21860 75 6d 65 6e 74 20 76 61 6c 75 65 73 20 2a 2f 0a ument values */.
21870 7d 3b 0a 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 };..#define SQLI
21880 54 45 5f 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e TE_PRINTF_INTERN
21890 41 4c 20 30 78 30 31 0a 23 64 65 66 69 6e 65 20 AL 0x01.#define
218a0 53 51 4c 49 54 45 5f 50 52 49 4e 54 46 5f 53 51 SQLITE_PRINTF_SQ
218b0 4c 46 55 4e 43 20 20 30 78 30 32 0a 76 6f 69 64 LFUNC 0x02.void
218c0 20 73 71 6c 69 74 65 33 56 58 50 72 69 6e 74 66 sqlite3VXPrintf
218d0 28 53 74 72 41 63 63 75 6d 2a 2c 20 75 33 32 2c (StrAccum*, u32,
218e0 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 const char*, va
218f0 5f 6c 69 73 74 29 3b 0a 76 6f 69 64 20 73 71 6c _list);.void sql
21900 69 74 65 33 58 50 72 69 6e 74 66 28 53 74 72 41 ite3XPrintf(StrA
21910 63 63 75 6d 2a 2c 20 75 33 32 2c 20 63 6f 6e 73 ccum*, u32, cons
21920 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 t char*, ...);.c
21930 68 61 72 20 2a 73 71 6c 69 74 65 33 4d 50 72 69 har *sqlite3MPri
21940 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ntf(sqlite3*,con
21950 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a st char*, ...);.
21960 63 68 61 72 20 2a 73 71 6c 69 74 65 33 56 4d 50 char *sqlite3VMP
21970 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 rintf(sqlite3*,c
21980 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 5f 6c onst char*, va_l
21990 69 73 74 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 ist);.char *sqli
219a0 74 65 33 4d 41 70 70 65 6e 64 66 28 73 71 6c 69 te3MAppendf(sqli
219b0 74 65 33 2a 2c 63 68 61 72 2a 2c 63 6f 6e 73 74 te3*,char*,const
219c0 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 23 69 66 char*,...);.#if
219d0 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
219e0 54 45 53 54 29 20 7c 7c 20 64 65 66 69 6e 65 64 TEST) || defined
219f0 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 (SQLITE_DEBUG).
21a00 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 62 void sqlite3Deb
21a10 75 67 50 72 69 6e 74 66 28 63 6f 6e 73 74 20 63 ugPrintf(const c
21a20 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 23 65 6e 64 har*, ...);.#end
21a30 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 if.#if defined(S
21a40 51 4c 49 54 45 5f 54 45 53 54 29 0a 20 20 76 6f QLITE_TEST). vo
21a50 69 64 20 2a 73 71 6c 69 74 65 33 54 65 73 74 54 id *sqlite3TestT
21a60 65 78 74 54 6f 50 74 72 28 63 6f 6e 73 74 20 63 extToPtr(const c
21a70 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 har*);.#endif..#
21a80 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
21a90 45 5f 44 45 42 55 47 29 0a 20 20 54 72 65 65 56 E_DEBUG). TreeV
21aa0 69 65 77 20 2a 73 71 6c 69 74 65 33 54 72 65 65 iew *sqlite3Tree
21ab0 56 69 65 77 50 75 73 68 28 54 72 65 65 56 69 65 ViewPush(TreeVie
21ac0 77 2a 2c 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 w*,u8);. void s
21ad0 71 6c 69 74 65 33 54 72 65 65 56 69 65 77 50 6f qlite3TreeViewPo
21ae0 70 28 54 72 65 65 56 69 65 77 2a 29 3b 0a 20 20 p(TreeView*);.
21af0 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 void sqlite3Tree
21b00 56 69 65 77 4c 69 6e 65 28 54 72 65 65 56 69 65 ViewLine(TreeVie
21b10 77 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c w*, const char*,
21b20 20 2e 2e 2e 29 3b 0a 20 20 76 6f 69 64 20 73 71 ...);. void sq
21b30 6c 69 74 65 33 54 72 65 65 56 69 65 77 49 74 65 lite3TreeViewIte
21b40 6d 28 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e m(TreeView*, con
21b50 73 74 20 63 68 61 72 2a 2c 20 75 38 29 3b 0a 20 st char*, u8);.
21b60 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 void sqlite3Tre
21b70 65 56 69 65 77 45 78 70 72 28 54 72 65 65 56 69 eViewExpr(TreeVi
21b80 65 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 2a ew*, const Expr*
21b90 2c 20 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 , u8);. void sq
21ba0 6c 69 74 65 33 54 72 65 65 56 69 65 77 45 78 70 lite3TreeViewExp
21bb0 72 4c 69 73 74 28 54 72 65 65 56 69 65 77 2a 2c rList(TreeView*,
21bc0 20 63 6f 6e 73 74 20 45 78 70 72 4c 69 73 74 2a const ExprList*
21bd0 2c 20 75 38 2c 20 63 6f 6e 73 74 20 63 68 61 72 , u8, const char
21be0 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
21bf0 65 33 54 72 65 65 56 69 65 77 53 65 6c 65 63 74 e3TreeViewSelect
21c00 28 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 (TreeView*, cons
21c10 74 20 53 65 6c 65 63 74 2a 2c 20 75 38 29 3b 0a t Select*, u8);.
21c20 23 65 6e 64 69 66 0a 0a 0a 76 6f 69 64 20 73 71 #endif...void sq
21c30 6c 69 74 65 33 53 65 74 53 74 72 69 6e 67 28 63 lite3SetString(c
21c40 68 61 72 20 2a 2a 2c 20 73 71 6c 69 74 65 33 2a har **, sqlite3*
21c50 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e , const char*, .
21c60 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 ..);.void sqlite
21c70 33 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 3ErrorMsg(Parse*
21c80 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e , const char*, .
21c90 2e 2e 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 ..);.int sqlite3
21ca0 44 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 0a Dequote(char*);.
21cb0 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 77 6f int sqlite3Keywo
21cc0 72 64 43 6f 64 65 28 63 6f 6e 73 74 20 75 6e 73 rdCode(const uns
21cd0 69 67 6e 65 64 20 63 68 61 72 2a 2c 20 69 6e 74 igned char*, int
21ce0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 75 );.int sqlite3Ru
21cf0 6e 50 61 72 73 65 72 28 50 61 72 73 65 2a 2c 20 nParser(Parse*,
21d00 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 68 61 const char*, cha
21d10 72 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 r **);.void sqli
21d20 74 65 33 46 69 6e 69 73 68 43 6f 64 69 6e 67 28 te3FinishCoding(
21d30 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c Parse*);.int sql
21d40 69 74 65 33 47 65 74 54 65 6d 70 52 65 67 28 50 ite3GetTempReg(P
21d50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c arse*);.void sql
21d60 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 52 ite3ReleaseTempR
21d70 65 67 28 50 61 72 73 65 2a 2c 69 6e 74 29 3b 0a eg(Parse*,int);.
21d80 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 65 int sqlite3GetTe
21d90 6d 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 mpRange(Parse*,i
21da0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
21db0 33 52 65 6c 65 61 73 65 54 65 6d 70 52 61 6e 67 3ReleaseTempRang
21dc0 65 28 50 61 72 73 65 2a 2c 69 6e 74 2c 69 6e 74 e(Parse*,int,int
21dd0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
21de0 6c 65 61 72 54 65 6d 70 52 65 67 43 61 63 68 65 learTempRegCache
21df0 28 50 61 72 73 65 2a 29 3b 0a 45 78 70 72 20 2a (Parse*);.Expr *
21e00 73 71 6c 69 74 65 33 45 78 70 72 41 6c 6c 6f 63 sqlite3ExprAlloc
21e10 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f (sqlite3*,int,co
21e20 6e 73 74 20 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b nst Token*,int);
21e30 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 .Expr *sqlite3Ex
21e40 70 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c pr(sqlite3*,int,
21e50 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f const char*);.vo
21e60 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 41 74 id sqlite3ExprAt
21e70 74 61 63 68 53 75 62 74 72 65 65 73 28 73 71 6c tachSubtrees(sql
21e80 69 74 65 33 2a 2c 45 78 70 72 2a 2c 45 78 70 72 ite3*,Expr*,Expr
21e90 2a 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 2a *,Expr*);.Expr *
21ea0 73 71 6c 69 74 65 33 50 45 78 70 72 28 50 61 72 sqlite3PExpr(Par
21eb0 73 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 2a 2c se*, int, Expr*,
21ec0 20 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 54 6f Expr*, const To
21ed0 6b 65 6e 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c ken*);.Expr *sql
21ee0 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 6c 69 ite3ExprAnd(sqli
21ef0 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 te3*,Expr*, Expr
21f00 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 *);.Expr *sqlite
21f10 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 50 61 3ExprFunction(Pa
21f20 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 20 rse*,ExprList*,
21f30 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 Token*);.void sq
21f40 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 6e 56 lite3ExprAssignV
21f50 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 2a 2c arNumber(Parse*,
21f60 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 Expr*);.void sq
21f70 6c 69 74 65 33 45 78 70 72 44 65 6c 65 74 65 28 lite3ExprDelete(
21f80 73 71 6c 69 74 65 33 2a 2c 20 45 78 70 72 2a 29 sqlite3*, Expr*)
21f90 3b 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 ;.ExprList *sqli
21fa0 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e te3ExprListAppen
21fb0 64 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 d(Parse*,ExprLis
21fc0 74 2a 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 t*,Expr*);.void
21fd0 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 sqlite3ExprListS
21fe0 65 74 4e 61 6d 65 28 50 61 72 73 65 2a 2c 45 78 etName(Parse*,Ex
21ff0 70 72 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 prList*,Token*,i
22000 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22010 33 45 78 70 72 4c 69 73 74 53 65 74 53 70 61 6e 3ExprListSetSpan
22020 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 (Parse*,ExprList
22030 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f *,ExprSpan*);.vo
22040 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 id sqlite3ExprLi
22050 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
22060 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 75 *, ExprList*);.u
22070 33 32 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 32 sqlite3ExprLi
22080 73 74 46 6c 61 67 73 28 63 6f 6e 73 74 20 45 78 stFlags(const Ex
22090 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 prList*);.int sq
220a0 6c 69 74 65 33 49 6e 69 74 28 73 71 6c 69 74 65 lite3Init(sqlite
220b0 33 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a 69 6e 74 3*, char**);.int
220c0 20 73 71 6c 69 74 65 33 49 6e 69 74 43 61 6c 6c sqlite3InitCall
220d0 62 61 63 6b 28 76 6f 69 64 2a 2c 20 69 6e 74 2c back(void*, int,
220e0 20 63 68 61 72 2a 2a 2c 20 63 68 61 72 2a 2a 29 char**, char**)
220f0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 ;.void sqlite3Pr
22100 61 67 6d 61 28 50 61 72 73 65 2a 2c 54 6f 6b 65 agma(Parse*,Toke
22110 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a n*,Token*,Token*
22120 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
22130 74 65 33 52 65 73 65 74 41 6c 6c 53 63 68 65 6d te3ResetAllSchem
22140 61 73 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e 28 73 asOfConnection(s
22150 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 qlite3*);.void s
22160 71 6c 69 74 65 33 52 65 73 65 74 4f 6e 65 53 63 qlite3ResetOneSc
22170 68 65 6d 61 28 73 71 6c 69 74 65 33 2a 2c 69 6e hema(sqlite3*,in
22180 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
22190 43 6f 6c 6c 61 70 73 65 44 61 74 61 62 61 73 65 CollapseDatabase
221a0 41 72 72 61 79 28 73 71 6c 69 74 65 33 2a 29 3b Array(sqlite3*);
221b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 .void sqlite3Beg
221c0 69 6e 50 61 72 73 65 28 50 61 72 73 65 2a 2c 69 inParse(Parse*,i
221d0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
221e0 33 43 6f 6d 6d 69 74 49 6e 74 65 72 6e 61 6c 43 3CommitInternalC
221f0 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 2a 29 hanges(sqlite3*)
22200 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 ;.Table *sqlite3
22210 52 65 73 75 6c 74 53 65 74 4f 66 53 65 6c 65 63 ResultSetOfSelec
22220 74 28 50 61 72 73 65 2a 2c 53 65 6c 65 63 74 2a t(Parse*,Select*
22230 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f );.void sqlite3O
22240 70 65 6e 4d 61 73 74 65 72 54 61 62 6c 65 28 50 penMasterTable(P
22250 61 72 73 65 20 2a 2c 20 69 6e 74 29 3b 0a 49 6e arse *, int);.In
22260 64 65 78 20 2a 73 71 6c 69 74 65 33 50 72 69 6d dex *sqlite3Prim
22270 61 72 79 4b 65 79 49 6e 64 65 78 28 54 61 62 6c aryKeyIndex(Tabl
22280 65 2a 29 3b 0a 69 31 36 20 73 71 6c 69 74 65 33 e*);.i16 sqlite3
22290 43 6f 6c 75 6d 6e 4f 66 49 6e 64 65 78 28 49 6e ColumnOfIndex(In
222a0 64 65 78 2a 2c 20 69 31 36 29 3b 0a 76 6f 69 64 dex*, i16);.void
222b0 20 73 71 6c 69 74 65 33 53 74 61 72 74 54 61 62 sqlite3StartTab
222c0 6c 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a le(Parse*,Token*
222d0 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c ,Token*,int,int,
222e0 69 6e 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 int,int);.void s
222f0 71 6c 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e 28 qlite3AddColumn(
22300 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a Parse*,Token*);.
22310 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 4e void sqlite3AddN
22320 6f 74 4e 75 6c 6c 28 50 61 72 73 65 2a 2c 20 69 otNull(Parse*, i
22330 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22340 33 41 64 64 50 72 69 6d 61 72 79 4b 65 79 28 50 3AddPrimaryKey(P
22350 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a arse*, ExprList*
22360 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
22370 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 ;.void sqlite3Ad
22380 64 43 68 65 63 6b 43 6f 6e 73 74 72 61 69 6e 74 dCheckConstraint
22390 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b (Parse*, Expr*);
223a0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
223b0 43 6f 6c 75 6d 6e 54 79 70 65 28 50 61 72 73 65 ColumnType(Parse
223c0 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 *,Token*);.void
223d0 73 71 6c 69 74 65 33 41 64 64 44 65 66 61 75 6c sqlite3AddDefaul
223e0 74 56 61 6c 75 65 28 50 61 72 73 65 2a 2c 45 78 tValue(Parse*,Ex
223f0 70 72 53 70 61 6e 2a 29 3b 0a 76 6f 69 64 20 73 prSpan*);.void s
22400 71 6c 69 74 65 33 41 64 64 43 6f 6c 6c 61 74 65 qlite3AddCollate
22410 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b Type(Parse*, Tok
22420 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
22430 65 33 45 6e 64 54 61 62 6c 65 28 50 61 72 73 65 e3EndTable(Parse
22440 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c *,Token*,Token*,
22450 75 38 2c 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 u8,Select*);.int
22460 20 73 71 6c 69 74 65 33 50 61 72 73 65 55 72 69 sqlite3ParseUri
22470 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e (const char*,con
22480 73 74 20 63 68 61 72 2a 2c 75 6e 73 69 67 6e 65 st char*,unsigne
22490 64 20 69 6e 74 2a 2c 0a 20 20 20 20 20 20 20 20 d int*,.
224a0 20 20 20 20 20 20 20 20 20 20 20 20 73 71 6c 69 sqli
224b0 74 65 33 5f 76 66 73 2a 2a 2c 63 68 61 72 2a 2a te3_vfs**,char**
224c0 2c 63 68 61 72 20 2a 2a 29 3b 0a 42 74 72 65 65 ,char **);.Btree
224d0 20 2a 73 71 6c 69 74 65 33 44 62 4e 61 6d 65 54 *sqlite3DbNameT
224e0 6f 42 74 72 65 65 28 73 71 6c 69 74 65 33 2a 2c oBtree(sqlite3*,
224f0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e const char*);.in
22500 74 20 73 71 6c 69 74 65 33 43 6f 64 65 4f 6e 63 t sqlite3CodeOnc
22510 65 28 50 61 72 73 65 20 2a 29 3b 0a 0a 23 69 66 e(Parse *);..#if
22520 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
22530 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 23 20 64 BUILTIN_TEST.# d
22540 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 61 75 efine sqlite3Fau
22550 6c 74 53 69 6d 28 58 29 20 53 51 4c 49 54 45 5f ltSim(X) SQLITE_
22560 4f 4b 0a 23 65 6c 73 65 0a 20 20 69 6e 74 20 73 OK.#else. int s
22570 71 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 69 qlite3FaultSim(i
22580 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 42 69 74 nt);.#endif..Bit
22590 76 65 63 20 2a 73 71 6c 69 74 65 33 42 69 74 76 vec *sqlite3Bitv
225a0 65 63 43 72 65 61 74 65 28 75 33 32 29 3b 0a 69 ecCreate(u32);.i
225b0 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
225c0 54 65 73 74 28 42 69 74 76 65 63 2a 2c 20 75 33 Test(Bitvec*, u3
225d0 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 2);.int sqlite3B
225e0 69 74 76 65 63 53 65 74 28 42 69 74 76 65 63 2a itvecSet(Bitvec*
225f0 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 71 6c , u32);.void sql
22600 69 74 65 33 42 69 74 76 65 63 43 6c 65 61 72 28 ite3BitvecClear(
22610 42 69 74 76 65 63 2a 2c 20 75 33 32 2c 20 76 6f Bitvec*, u32, vo
22620 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 id*);.void sqlit
22630 65 33 42 69 74 76 65 63 44 65 73 74 72 6f 79 28 e3BitvecDestroy(
22640 42 69 74 76 65 63 2a 29 3b 0a 75 33 32 20 73 71 Bitvec*);.u32 sq
22650 6c 69 74 65 33 42 69 74 76 65 63 53 69 7a 65 28 lite3BitvecSize(
22660 42 69 74 76 65 63 2a 29 3b 0a 69 6e 74 20 73 71 Bitvec*);.int sq
22670 6c 69 74 65 33 42 69 74 76 65 63 42 75 69 6c 74 lite3BitvecBuilt
22680 69 6e 54 65 73 74 28 69 6e 74 2c 69 6e 74 2a 29 inTest(int,int*)
22690 3b 0a 0a 52 6f 77 53 65 74 20 2a 73 71 6c 69 74 ;..RowSet *sqlit
226a0 65 33 52 6f 77 53 65 74 49 6e 69 74 28 73 71 6c e3RowSetInit(sql
226b0 69 74 65 33 2a 2c 20 76 6f 69 64 2a 2c 20 75 6e ite3*, void*, un
226c0 73 69 67 6e 65 64 20 69 6e 74 29 3b 0a 76 6f 69 signed int);.voi
226d0 64 20 73 71 6c 69 74 65 33 52 6f 77 53 65 74 43 d sqlite3RowSetC
226e0 6c 65 61 72 28 52 6f 77 53 65 74 2a 29 3b 0a 76 lear(RowSet*);.v
226f0 6f 69 64 20 73 71 6c 69 74 65 33 52 6f 77 53 65 oid sqlite3RowSe
22700 74 49 6e 73 65 72 74 28 52 6f 77 53 65 74 2a 2c tInsert(RowSet*,
22710 20 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 i64);.int sqlit
22720 65 33 52 6f 77 53 65 74 54 65 73 74 28 52 6f 77 e3RowSetTest(Row
22730 53 65 74 2a 2c 20 69 6e 74 20 69 42 61 74 63 68 Set*, int iBatch
22740 2c 20 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 , i64);.int sqli
22750 74 65 33 52 6f 77 53 65 74 4e 65 78 74 28 52 6f te3RowSetNext(Ro
22760 77 53 65 74 2a 2c 20 69 36 34 2a 29 3b 0a 0a 76 wSet*, i64*);..v
22770 6f 69 64 20 73 71 6c 69 74 65 33 43 72 65 61 74 oid sqlite3Creat
22780 65 56 69 65 77 28 50 61 72 73 65 2a 2c 54 6f 6b eView(Parse*,Tok
22790 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e en*,Token*,Token
227a0 2a 2c 53 65 6c 65 63 74 2a 2c 69 6e 74 2c 69 6e *,Select*,int,in
227b0 74 29 3b 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 t);..#if !define
227c0 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 d(SQLITE_OMIT_VI
227d0 45 57 29 20 7c 7c 20 21 64 65 66 69 6e 65 64 28 EW) || !defined(
227e0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
227f0 55 41 4c 54 41 42 4c 45 29 0a 20 20 69 6e 74 20 UALTABLE). int
22800 73 71 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f sqlite3ViewGetCo
22810 6c 75 6d 6e 4e 61 6d 65 73 28 50 61 72 73 65 2a lumnNames(Parse*
22820 2c 54 61 62 6c 65 2a 29 3b 0a 23 65 6c 73 65 0a ,Table*);.#else.
22830 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
22840 56 69 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d ViewGetColumnNam
22850 65 73 28 41 2c 42 29 20 30 0a 23 65 6e 64 69 66 es(A,B) 0.#endif
22860 0a 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 ..#if SQLITE_MAX
22870 5f 41 54 54 41 43 48 45 44 3e 33 30 0a 20 20 69 _ATTACHED>30. i
22880 6e 74 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b nt sqlite3DbMask
22890 41 6c 6c 5a 65 72 6f 28 79 44 62 4d 61 73 6b 29 AllZero(yDbMask)
228a0 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 ;.#endif.void sq
228b0 6c 69 74 65 33 44 72 6f 70 54 61 62 6c 65 28 50 lite3DropTable(P
228c0 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c arse*, SrcList*,
228d0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
228e0 20 73 71 6c 69 74 65 33 43 6f 64 65 44 72 6f 70 sqlite3CodeDrop
228f0 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 54 61 Table(Parse*, Ta
22900 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b ble*, int, int);
22910 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c .void sqlite3Del
22920 65 74 65 54 61 62 6c 65 28 73 71 6c 69 74 65 33 eteTable(sqlite3
22930 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 23 69 66 6e *, Table*);.#ifn
22940 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
22950 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 0a 20 20 AUTOINCREMENT.
22960 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f void sqlite3Auto
22970 69 6e 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 50 incrementBegin(P
22980 61 72 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 20 arse *pParse);.
22990 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 void sqlite3Aut
229a0 6f 69 6e 63 72 65 6d 65 6e 74 45 6e 64 28 50 61 oincrementEnd(Pa
229b0 72 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 23 65 rse *pParse);.#e
229c0 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
229d0 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e ite3Autoincremen
229e0 74 42 65 67 69 6e 28 58 29 0a 23 20 64 65 66 69 tBegin(X).# defi
229f0 6e 65 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e ne sqlite3Autoin
22a00 63 72 65 6d 65 6e 74 45 6e 64 28 58 29 0a 23 65 crementEnd(X).#e
22a10 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 ndif.void sqlite
22a20 33 49 6e 73 65 72 74 28 50 61 72 73 65 2a 2c 20 3Insert(Parse*,
22a30 53 72 63 4c 69 73 74 2a 2c 20 53 65 6c 65 63 74 SrcList*, Select
22a40 2a 2c 20 49 64 4c 69 73 74 2a 2c 20 69 6e 74 29 *, IdList*, int)
22a50 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 41 ;.void *sqlite3A
22a60 72 72 61 79 41 6c 6c 6f 63 61 74 65 28 73 71 6c rrayAllocate(sql
22a70 69 74 65 33 2a 2c 76 6f 69 64 2a 2c 69 6e 74 2c ite3*,void*,int,
22a80 69 6e 74 2a 2c 69 6e 74 2a 29 3b 0a 49 64 4c 69 int*,int*);.IdLi
22a90 73 74 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 st *sqlite3IdLis
22aa0 74 41 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a tAppend(sqlite3*
22ab0 2c 20 49 64 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e , IdList*, Token
22ac0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 *);.int sqlite3I
22ad0 64 4c 69 73 74 49 6e 64 65 78 28 49 64 4c 69 73 dListIndex(IdLis
22ae0 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b t*,const char*);
22af0 0a 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 .SrcList *sqlite
22b00 33 53 72 63 4c 69 73 74 45 6e 6c 61 72 67 65 28 3SrcListEnlarge(
22b10 73 71 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 sqlite3*, SrcLis
22b20 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 53 t*, int, int);.S
22b30 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 rcList *sqlite3S
22b40 72 63 4c 69 73 74 41 70 70 65 6e 64 28 73 71 6c rcListAppend(sql
22b50 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a 2c ite3*, SrcList*,
22b60 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 Token*, Token*)
22b70 3b 0a 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 ;.SrcList *sqlit
22b80 65 33 53 72 63 4c 69 73 74 41 70 70 65 6e 64 46 e3SrcListAppendF
22b90 72 6f 6d 54 65 72 6d 28 50 61 72 73 65 2a 2c 20 romTerm(Parse*,
22ba0 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a SrcList*, Token*
22bb0 2c 20 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 , Token*,.
22bc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22bd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22be0 54 6f 6b 65 6e 2a 2c 20 53 65 6c 65 63 74 2a 2c Token*, Select*,
22bf0 20 45 78 70 72 2a 2c 20 49 64 4c 69 73 74 2a 29 Expr*, IdList*)
22c00 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 ;.void sqlite3Sr
22c10 63 4c 69 73 74 49 6e 64 65 78 65 64 42 79 28 50 cListIndexedBy(P
22c20 61 72 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 arse *, SrcList
22c30 2a 2c 20 54 6f 6b 65 6e 20 2a 29 3b 0a 69 6e 74 *, Token *);.int
22c40 20 73 71 6c 69 74 65 33 49 6e 64 65 78 65 64 42 sqlite3IndexedB
22c50 79 4c 6f 6f 6b 75 70 28 50 61 72 73 65 20 2a 2c yLookup(Parse *,
22c60 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f struct SrcList_
22c70 69 74 65 6d 20 2a 29 3b 0a 76 6f 69 64 20 73 71 item *);.void sq
22c80 6c 69 74 65 33 53 72 63 4c 69 73 74 53 68 69 66 lite3SrcListShif
22c90 74 4a 6f 69 6e 54 79 70 65 28 53 72 63 4c 69 73 tJoinType(SrcLis
22ca0 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 t*);.void sqlite
22cb0 33 53 72 63 4c 69 73 74 41 73 73 69 67 6e 43 75 3SrcListAssignCu
22cc0 72 73 6f 72 73 28 50 61 72 73 65 2a 2c 20 53 72 rsors(Parse*, Sr
22cd0 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 cList*);.void sq
22ce0 6c 69 74 65 33 49 64 4c 69 73 74 44 65 6c 65 74 lite3IdListDelet
22cf0 65 28 73 71 6c 69 74 65 33 2a 2c 20 49 64 4c 69 e(sqlite3*, IdLi
22d00 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 st*);.void sqlit
22d10 65 33 53 72 63 4c 69 73 74 44 65 6c 65 74 65 28 e3SrcListDelete(
22d20 73 71 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 sqlite3*, SrcLis
22d30 74 2a 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 t*);.Index *sqli
22d40 74 65 33 41 6c 6c 6f 63 61 74 65 49 6e 64 65 78 te3AllocateIndex
22d50 4f 62 6a 65 63 74 28 73 71 6c 69 74 65 33 2a 2c Object(sqlite3*,
22d60 69 31 36 2c 69 6e 74 2c 63 68 61 72 2a 2a 29 3b i16,int,char**);
22d70 0a 49 6e 64 65 78 20 2a 73 71 6c 69 74 65 33 43 .Index *sqlite3C
22d80 72 65 61 74 65 49 6e 64 65 78 28 50 61 72 73 65 reateIndex(Parse
22d90 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c *,Token*,Token*,
22da0 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 SrcList*,ExprLis
22db0 74 2a 2c 69 6e 74 2c 54 6f 6b 65 6e 2a 2c 0a 20 t*,int,Token*,.
22dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22dd0 20 20 20 20 20 20 20 20 20 45 78 70 72 2a 2c 20 Expr*,
22de0 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
22df0 73 71 6c 69 74 65 33 44 72 6f 70 49 6e 64 65 78 sqlite3DropIndex
22e00 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
22e10 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c *, int);.int sql
22e20 69 74 65 33 53 65 6c 65 63 74 28 50 61 72 73 65 ite3Select(Parse
22e30 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 53 65 6c 65 *, Select*, Sele
22e40 63 74 44 65 73 74 2a 29 3b 0a 53 65 6c 65 63 74 ctDest*);.Select
22e50 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 74 4e *sqlite3SelectN
22e60 65 77 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 ew(Parse*,ExprLi
22e70 73 74 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 78 70 st*,SrcList*,Exp
22e80 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 0a 20 20 r*,ExprList*,.
22e90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22ea0 20 20 20 20 20 20 20 45 78 70 72 2a 2c 45 78 70 Expr*,Exp
22eb0 72 4c 69 73 74 2a 2c 75 31 36 2c 45 78 70 72 2a rList*,u16,Expr*
22ec0 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 ,Expr*);.void sq
22ed0 6c 69 74 65 33 53 65 6c 65 63 74 44 65 6c 65 74 lite3SelectDelet
22ee0 65 28 73 71 6c 69 74 65 33 2a 2c 20 53 65 6c 65 e(sqlite3*, Sele
22ef0 63 74 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c ct*);.Table *sql
22f00 69 74 65 33 53 72 63 4c 69 73 74 4c 6f 6f 6b 75 ite3SrcListLooku
22f10 70 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 p(Parse*, SrcLis
22f20 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
22f30 49 73 52 65 61 64 4f 6e 6c 79 28 50 61 72 73 65 IsReadOnly(Parse
22f40 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 3b *, Table*, int);
22f50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f 70 65 .void sqlite3Ope
22f60 6e 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 69 nTable(Parse*, i
22f70 6e 74 20 69 43 75 72 2c 20 69 6e 74 20 69 44 62 nt iCur, int iDb
22f80 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 3b 0a , Table*, int);.
22f90 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
22fa0 54 45 5f 45 4e 41 42 4c 45 5f 55 50 44 41 54 45 TE_ENABLE_UPDATE
22fb0 5f 44 45 4c 45 54 45 5f 4c 49 4d 49 54 29 20 26 _DELETE_LIMIT) &
22fc0 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 & !defined(SQLIT
22fd0 45 5f 4f 4d 49 54 5f 53 55 42 51 55 45 52 59 29 E_OMIT_SUBQUERY)
22fe0 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 4c 69 .Expr *sqlite3Li
22ff0 6d 69 74 57 68 65 72 65 28 50 61 72 73 65 2a 2c mitWhere(Parse*,
23000 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 SrcList*,Expr*,E
23010 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 xprList*,Expr*,E
23020 78 70 72 2a 2c 63 68 61 72 2a 29 3b 0a 23 65 6e xpr*,char*);.#en
23030 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
23040 44 65 6c 65 74 65 46 72 6f 6d 28 50 61 72 73 65 DeleteFrom(Parse
23050 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 *, SrcList*, Exp
23060 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
23070 33 55 70 64 61 74 65 28 50 61 72 73 65 2a 2c 20 3Update(Parse*,
23080 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 SrcList*, ExprLi
23090 73 74 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 st*, Expr*, int)
230a0 3b 0a 57 68 65 72 65 49 6e 66 6f 20 2a 73 71 6c ;.WhereInfo *sql
230b0 69 74 65 33 57 68 65 72 65 42 65 67 69 6e 28 50 ite3WhereBegin(P
230c0 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 arse*,SrcList*,E
230d0 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 45 xpr*,ExprList*,E
230e0 78 70 72 4c 69 73 74 2a 2c 75 31 36 2c 69 6e 74 xprList*,u16,int
230f0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 57 );.void sqlite3W
23100 68 65 72 65 45 6e 64 28 57 68 65 72 65 49 6e 66 hereEnd(WhereInf
23110 6f 2a 29 3b 0a 75 36 34 20 73 71 6c 69 74 65 33 o*);.u64 sqlite3
23120 57 68 65 72 65 4f 75 74 70 75 74 52 6f 77 43 6f WhereOutputRowCo
23130 75 6e 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b unt(WhereInfo*);
23140 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
23150 65 49 73 44 69 73 74 69 6e 63 74 28 57 68 65 72 eIsDistinct(Wher
23160 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23170 69 74 65 33 57 68 65 72 65 49 73 4f 72 64 65 72 ite3WhereIsOrder
23180 65 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a ed(WhereInfo*);.
23190 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 int sqlite3Where
231a0 49 73 53 6f 72 74 65 64 28 57 68 65 72 65 49 6e IsSorted(WhereIn
231b0 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 fo*);.int sqlite
231c0 33 57 68 65 72 65 43 6f 6e 74 69 6e 75 65 4c 61 3WhereContinueLa
231d0 62 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b bel(WhereInfo*);
231e0 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
231f0 65 42 72 65 61 6b 4c 61 62 65 6c 28 57 68 65 72 eBreakLabel(Wher
23200 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23210 69 74 65 33 57 68 65 72 65 4f 6b 4f 6e 65 50 61 ite3WhereOkOnePa
23220 73 73 28 57 68 65 72 65 49 6e 66 6f 2a 2c 20 69 ss(WhereInfo*, i
23230 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
23240 33 45 78 70 72 43 6f 64 65 47 65 74 43 6f 6c 75 3ExprCodeGetColu
23250 6d 6e 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 mn(Parse*, Table
23260 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
23270 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 , u8);.void sqli
23280 74 65 33 45 78 70 72 43 6f 64 65 47 65 74 43 6f te3ExprCodeGetCo
23290 6c 75 6d 6e 4f 66 54 61 62 6c 65 28 56 64 62 65 lumnOfTable(Vdbe
232a0 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 *, Table*, int,
232b0 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
232c0 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 4d sqlite3ExprCodeM
232d0 6f 76 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c ove(Parse*, int,
232e0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
232f0 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 sqlite3ExprCach
23300 65 53 74 6f 72 65 28 50 61 72 73 65 2a 2c 20 69 eStore(Parse*, i
23310 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 nt, int, int);.v
23320 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
23330 61 63 68 65 50 75 73 68 28 50 61 72 73 65 2a 29 achePush(Parse*)
23340 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
23350 70 72 43 61 63 68 65 50 6f 70 28 50 61 72 73 65 prCachePop(Parse
23360 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
23370 45 78 70 72 43 61 63 68 65 52 65 6d 6f 76 65 28 ExprCacheRemove(
23380 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 Parse*, int, int
23390 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
233a0 78 70 72 43 61 63 68 65 43 6c 65 61 72 28 50 61 xprCacheClear(Pa
233b0 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 rse*);.void sqli
233c0 74 65 33 45 78 70 72 43 61 63 68 65 41 66 66 69 te3ExprCacheAffi
233d0 6e 69 74 79 43 68 61 6e 67 65 28 50 61 72 73 65 nityChange(Parse
233e0 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f *, int, int);.vo
233f0 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f id sqlite3ExprCo
23400 64 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a de(Parse*, Expr*
23410 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
23420 69 74 65 33 45 78 70 72 43 6f 64 65 46 61 63 74 ite3ExprCodeFact
23430 6f 72 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 45 orable(Parse*, E
23440 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 xpr*, int);.void
23450 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 sqlite3ExprCode
23460 41 74 49 6e 69 74 28 50 61 72 73 65 2a 2c 20 45 AtInit(Parse*, E
23470 78 70 72 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a xpr*, int, u8);.
23480 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
23490 6f 64 65 54 65 6d 70 28 50 61 72 73 65 2a 2c 20 odeTemp(Parse*,
234a0 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a 69 6e Expr*, int*);.in
234b0 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 t sqlite3ExprCod
234c0 65 54 61 72 67 65 74 28 50 61 72 73 65 2a 2c 20 eTarget(Parse*,
234d0 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 Expr*, int);.voi
234e0 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 d sqlite3ExprCod
234f0 65 41 6e 64 43 61 63 68 65 28 50 61 72 73 65 2a eAndCache(Parse*
23500 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 , Expr*, int);.i
23510 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
23520 64 65 45 78 70 72 4c 69 73 74 28 50 61 72 73 65 deExprList(Parse
23530 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e *, ExprList*, in
23540 74 2c 20 75 38 29 3b 0a 23 64 65 66 69 6e 65 20 t, u8);.#define
23550 53 51 4c 49 54 45 5f 45 43 45 4c 5f 44 55 50 20 SQLITE_ECEL_DUP
23560 20 20 20 20 20 30 78 30 31 20 20 2f 2a 20 44 65 0x01 /* De
23570 65 70 2c 20 6e 6f 74 20 73 68 61 6c 6c 6f 77 20 ep, not shallow
23580 63 6f 70 69 65 73 20 2a 2f 0a 23 64 65 66 69 6e copies */.#defin
23590 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 46 41 e SQLITE_ECEL_FA
235a0 43 54 4f 52 20 20 20 30 78 30 32 20 20 2f 2a 20 CTOR 0x02 /*
235b0 46 61 63 74 6f 72 20 6f 75 74 20 63 6f 6e 73 74 Factor out const
235c0 61 6e 74 20 74 65 72 6d 73 20 2a 2f 0a 76 6f 69 ant terms */.voi
235d0 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 66 54 d sqlite3ExprIfT
235e0 72 75 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 rue(Parse*, Expr
235f0 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f *, int, int);.vo
23600 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 66 id sqlite3ExprIf
23610 46 61 6c 73 65 28 50 61 72 73 65 2a 2c 20 45 78 False(Parse*, Ex
23620 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a pr*, int, int);.
23630 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 46 69 Table *sqlite3Fi
23640 6e 64 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a ndTable(sqlite3*
23650 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f ,const char*, co
23660 6e 73 74 20 63 68 61 72 2a 29 3b 0a 54 61 62 6c nst char*);.Tabl
23670 65 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 e *sqlite3Locate
23680 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 69 6e 74 Table(Parse*,int
23690 20 69 73 56 69 65 77 2c 63 6f 6e 73 74 20 63 68 isView,const ch
236a0 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
236b0 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 );.Table *sqlite
236c0 33 4c 6f 63 61 74 65 54 61 62 6c 65 49 74 65 6d 3LocateTableItem
236d0 28 50 61 72 73 65 2a 2c 69 6e 74 20 69 73 56 69 (Parse*,int isVi
236e0 65 77 2c 73 74 72 75 63 74 20 53 72 63 4c 69 73 ew,struct SrcLis
236f0 74 5f 69 74 65 6d 20 2a 29 3b 0a 49 6e 64 65 78 t_item *);.Index
23700 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 64 *sqlite3FindInd
23710 65 78 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 ex(sqlite3*,cons
23720 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 t char*, const c
23730 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
23740 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 te3UnlinkAndDele
23750 74 65 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a teTable(sqlite3*
23760 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
23770 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 );.void sqlite3U
23780 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 49 6e nlinkAndDeleteIn
23790 64 65 78 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 dex(sqlite3*,int
237a0 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
237b0 6f 69 64 20 73 71 6c 69 74 65 33 56 61 63 75 75 oid sqlite3Vacuu
237c0 6d 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 m(Parse*);.int s
237d0 71 6c 69 74 65 33 52 75 6e 56 61 63 75 75 6d 28 qlite3RunVacuum(
237e0 63 68 61 72 2a 2a 2c 20 73 71 6c 69 74 65 33 2a char**, sqlite3*
237f0 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
23800 4e 61 6d 65 46 72 6f 6d 54 6f 6b 65 6e 28 73 71 NameFromToken(sq
23810 6c 69 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b lite3*, Token*);
23820 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
23830 43 6f 6d 70 61 72 65 28 45 78 70 72 2a 2c 20 45 Compare(Expr*, E
23840 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 xpr*, int);.int
23850 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 43 sqlite3ExprListC
23860 6f 6d 70 61 72 65 28 45 78 70 72 4c 69 73 74 2a ompare(ExprList*
23870 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 , ExprList*, int
23880 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
23890 70 72 49 6d 70 6c 69 65 73 45 78 70 72 28 45 78 prImpliesExpr(Ex
238a0 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 pr*, Expr*, int)
238b0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
238c0 70 72 41 6e 61 6c 79 7a 65 41 67 67 72 65 67 61 prAnalyzeAggrega
238d0 74 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a tes(NameContext*
238e0 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
238f0 71 6c 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a qlite3ExprAnalyz
23900 65 41 67 67 4c 69 73 74 28 4e 61 6d 65 43 6f 6e eAggList(NameCon
23910 74 65 78 74 2a 2c 45 78 70 72 4c 69 73 74 2a 29 text*,ExprList*)
23920 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 75 6e ;.int sqlite3Fun
23930 63 74 69 6f 6e 55 73 65 73 54 68 69 73 53 72 63 ctionUsesThisSrc
23940 28 45 78 70 72 2a 2c 20 53 72 63 4c 69 73 74 2a (Expr*, SrcList*
23950 29 3b 0a 56 64 62 65 20 2a 73 71 6c 69 74 65 33 );.Vdbe *sqlite3
23960 47 65 74 56 64 62 65 28 50 61 72 73 65 2a 29 3b GetVdbe(Parse*);
23970 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e .void sqlite3Prn
23980 67 53 61 76 65 53 74 61 74 65 28 76 6f 69 64 29 gSaveState(void)
23990 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 ;.void sqlite3Pr
239a0 6e 67 52 65 73 74 6f 72 65 53 74 61 74 65 28 76 ngRestoreState(v
239b0 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 oid);.void sqlit
239c0 65 33 52 6f 6c 6c 62 61 63 6b 41 6c 6c 28 73 71 e3RollbackAll(sq
239d0 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 lite3*,int);.voi
239e0 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 72 d sqlite3CodeVer
239f0 69 66 79 53 63 68 65 6d 61 28 50 61 72 73 65 2a ifySchema(Parse*
23a00 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
23a10 69 74 65 33 43 6f 64 65 56 65 72 69 66 79 4e 61 ite3CodeVerifyNa
23a20 6d 65 64 53 63 68 65 6d 61 28 50 61 72 73 65 2a medSchema(Parse*
23a30 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 , const char *zD
23a40 62 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 b);.void sqlite3
23a50 42 65 67 69 6e 54 72 61 6e 73 61 63 74 69 6f 6e BeginTransaction
23a60 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 (Parse*, int);.v
23a70 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 6d 69 oid sqlite3Commi
23a80 74 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 tTransaction(Par
23a90 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 se*);.void sqlit
23aa0 65 33 52 6f 6c 6c 62 61 63 6b 54 72 61 6e 73 61 e3RollbackTransa
23ab0 63 74 69 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 ction(Parse*);.v
23ac0 6f 69 64 20 73 71 6c 69 74 65 33 53 61 76 65 70 oid sqlite3Savep
23ad0 6f 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 oint(Parse*, int
23ae0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
23af0 73 71 6c 69 74 65 33 43 6c 6f 73 65 53 61 76 65 sqlite3CloseSave
23b00 70 6f 69 6e 74 73 28 73 71 6c 69 74 65 33 20 2a points(sqlite3 *
23b10 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4c );.void sqlite3L
23b20 65 61 76 65 4d 75 74 65 78 41 6e 64 43 6c 6f 73 eaveMutexAndClos
23b30 65 5a 6f 6d 62 69 65 28 73 71 6c 69 74 65 33 2a eZombie(sqlite3*
23b40 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
23b50 70 72 49 73 43 6f 6e 73 74 61 6e 74 28 45 78 70 prIsConstant(Exp
23b60 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
23b70 45 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4e 6f ExprIsConstantNo
23b80 74 4a 6f 69 6e 28 45 78 70 72 2a 29 3b 0a 69 6e tJoin(Expr*);.in
23b90 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 43 t sqlite3ExprIsC
23ba0 6f 6e 73 74 61 6e 74 4f 72 46 75 6e 63 74 69 6f onstantOrFunctio
23bb0 6e 28 45 78 70 72 2a 2c 20 75 38 29 3b 0a 69 6e n(Expr*, u8);.in
23bc0 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 54 t sqlite3ExprIsT
23bd0 61 62 6c 65 43 6f 6e 73 74 61 6e 74 28 45 78 70 ableConstant(Exp
23be0 72 2a 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c r*,int);.int sql
23bf0 69 74 65 33 45 78 70 72 49 73 49 6e 74 65 67 65 ite3ExprIsIntege
23c00 72 28 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a r(Expr*, int*);.
23c10 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
23c20 61 6e 42 65 4e 75 6c 6c 28 63 6f 6e 73 74 20 45 anBeNull(const E
23c30 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 xpr*);.int sqlit
23c40 65 33 45 78 70 72 4e 65 65 64 73 4e 6f 41 66 66 e3ExprNeedsNoAff
23c50 69 6e 69 74 79 43 68 61 6e 67 65 28 63 6f 6e 73 inityChange(cons
23c60 74 20 45 78 70 72 2a 2c 20 63 68 61 72 29 3b 0a t Expr*, char);.
23c70 69 6e 74 20 73 71 6c 69 74 65 33 49 73 52 6f 77 int sqlite3IsRow
23c80 69 64 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b id(const char*);
23c90 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
23ca0 65 72 61 74 65 52 6f 77 44 65 6c 65 74 65 28 50 erateRowDelete(P
23cb0 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 54 72 69 arse*,Table*,Tri
23cc0 67 67 65 72 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e gger*,int,int,in
23cd0 74 2c 69 31 36 2c 75 38 2c 75 38 2c 75 38 29 3b t,i16,u8,u8,u8);
23ce0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
23cf0 65 72 61 74 65 52 6f 77 49 6e 64 65 78 44 65 6c erateRowIndexDel
23d00 65 74 65 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ete(Parse*, Tabl
23d10 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e e*, int, int, in
23d20 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
23d30 47 65 6e 65 72 61 74 65 49 6e 64 65 78 4b 65 79 GenerateIndexKey
23d40 28 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c (Parse*, Index*,
23d50 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 int, int, int,
23d60 69 6e 74 2a 2c 49 6e 64 65 78 2a 2c 69 6e 74 29 int*,Index*,int)
23d70 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 ;.void sqlite3Re
23d80 73 6f 6c 76 65 50 61 72 74 49 64 78 4c 61 62 65 solvePartIdxLabe
23d90 6c 28 50 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 76 l(Parse*,int);.v
23da0 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e 65 72 oid sqlite3Gener
23db0 61 74 65 43 6f 6e 73 74 72 61 69 6e 74 43 68 65 ateConstraintChe
23dc0 63 6b 73 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 cks(Parse*,Table
23dd0 2a 2c 69 6e 74 2a 2c 69 6e 74 2c 69 6e 74 2c 69 *,int*,int,int,i
23de0 6e 74 2c 69 6e 74 2c 0a 20 20 20 20 20 20 20 20 nt,int,.
23df0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23e00 20 20 20 20 20 20 20 20 20 20 20 20 20 75 38 2c u8,
23e10 75 38 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a 76 6f u8,int,int*);.vo
23e20 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 70 6c 65 id sqlite3Comple
23e30 74 65 49 6e 73 65 72 74 69 6f 6e 28 50 61 72 73 teInsertion(Pars
23e40 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 69 6e e*,Table*,int,in
23e50 74 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2c 69 t,int,int*,int,i
23e60 6e 74 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c nt,int);.int sql
23e70 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 41 6e 64 ite3OpenTableAnd
23e80 49 6e 64 69 63 65 73 28 50 61 72 73 65 2a 2c 20 Indices(Parse*,
23e90 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 Table*, int, int
23ea0 2c 20 75 38 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 , u8*, int*, int
23eb0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
23ec0 42 65 67 69 6e 57 72 69 74 65 4f 70 65 72 61 74 BeginWriteOperat
23ed0 69 6f 6e 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c ion(Parse*, int,
23ee0 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
23ef0 74 65 33 4d 75 6c 74 69 57 72 69 74 65 28 50 61 te3MultiWrite(Pa
23f00 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 rse*);.void sqli
23f10 74 65 33 4d 61 79 41 62 6f 72 74 28 50 61 72 73 te3MayAbort(Pars
23f20 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
23f30 33 48 61 6c 74 43 6f 6e 73 74 72 61 69 6e 74 28 3HaltConstraint(
23f40 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 Parse*, int, int
23f50 2c 20 63 68 61 72 2a 2c 20 69 38 2c 20 75 38 29 , char*, i8, u8)
23f60 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e ;.void sqlite3Un
23f70 69 71 75 65 43 6f 6e 73 74 72 61 69 6e 74 28 50 iqueConstraint(P
23f80 61 72 73 65 2a 2c 20 69 6e 74 2c 20 49 6e 64 65 arse*, int, Inde
23f90 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 x*);.void sqlite
23fa0 33 52 6f 77 69 64 43 6f 6e 73 74 72 61 69 6e 74 3RowidConstraint
23fb0 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 54 61 (Parse*, int, Ta
23fc0 62 6c 65 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c ble*);.Expr *sql
23fd0 69 74 65 33 45 78 70 72 44 75 70 28 73 71 6c 69 ite3ExprDup(sqli
23fe0 74 65 33 2a 2c 45 78 70 72 2a 2c 69 6e 74 29 3b te3*,Expr*,int);
23ff0 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 .ExprList *sqlit
24000 65 33 45 78 70 72 4c 69 73 74 44 75 70 28 73 71 e3ExprListDup(sq
24010 6c 69 74 65 33 2a 2c 45 78 70 72 4c 69 73 74 2a lite3*,ExprList*
24020 2c 69 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 2a ,int);.SrcList *
24030 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 44 75 sqlite3SrcListDu
24040 70 28 73 71 6c 69 74 65 33 2a 2c 53 72 63 4c 69 p(sqlite3*,SrcLi
24050 73 74 2a 2c 69 6e 74 29 3b 0a 49 64 4c 69 73 74 st*,int);.IdList
24060 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 74 44 *sqlite3IdListD
24070 75 70 28 73 71 6c 69 74 65 33 2a 2c 49 64 4c 69 up(sqlite3*,IdLi
24080 73 74 2a 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 st*);.Select *sq
24090 6c 69 74 65 33 53 65 6c 65 63 74 44 75 70 28 73 lite3SelectDup(s
240a0 71 6c 69 74 65 33 2a 2c 53 65 6c 65 63 74 2a 2c qlite3*,Select*,
240b0 69 6e 74 29 3b 0a 23 69 66 20 53 45 4c 45 43 54 int);.#if SELECT
240c0 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 0a 76 6f TRACE_ENABLED.vo
240d0 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 id sqlite3Select
240e0 53 65 74 4e 61 6d 65 28 53 65 6c 65 63 74 2a 2c SetName(Select*,
240f0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 const char*);.#e
24100 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
24110 69 74 65 33 53 65 6c 65 63 74 53 65 74 4e 61 6d ite3SelectSetNam
24120 65 28 41 2c 42 29 0a 23 65 6e 64 69 66 0a 76 6f e(A,B).#endif.vo
24130 69 64 20 73 71 6c 69 74 65 33 46 75 6e 63 44 65 id sqlite3FuncDe
24140 66 49 6e 73 65 72 74 28 46 75 6e 63 44 65 66 48 fInsert(FuncDefH
24150 61 73 68 2a 2c 20 46 75 6e 63 44 65 66 2a 29 3b ash*, FuncDef*);
24160 0a 46 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 65 .FuncDef *sqlite
24170 33 46 69 6e 64 46 75 6e 63 74 69 6f 6e 28 73 71 3FindFunction(sq
24180 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
24190 72 2a 2c 69 6e 74 2c 69 6e 74 2c 75 38 2c 75 38 r*,int,int,u8,u8
241a0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
241b0 65 67 69 73 74 65 72 42 75 69 6c 74 69 6e 46 75 egisterBuiltinFu
241c0 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a nctions(sqlite3*
241d0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
241e0 65 67 69 73 74 65 72 44 61 74 65 54 69 6d 65 46 egisterDateTimeF
241f0 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a unctions(void);.
24200 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 void sqlite3Regi
24210 73 74 65 72 47 6c 6f 62 61 6c 46 75 6e 63 74 69 sterGlobalFuncti
24220 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 6e 74 20 73 ons(void);.int s
24230 71 6c 69 74 65 33 53 61 66 65 74 79 43 68 65 63 qlite3SafetyChec
24240 6b 4f 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 kOk(sqlite3*);.i
24250 6e 74 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 nt sqlite3Safety
24260 43 68 65 63 6b 53 69 63 6b 4f 72 4f 6b 28 73 71 CheckSickOrOk(sq
24270 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
24280 6c 69 74 65 33 43 68 61 6e 67 65 43 6f 6f 6b 69 lite3ChangeCooki
24290 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a e(Parse*, int);.
242a0 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 .#if !defined(SQ
242b0 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 LITE_OMIT_VIEW)
242c0 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
242d0 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 TE_OMIT_TRIGGER)
242e0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 74 .void sqlite3Mat
242f0 65 72 69 61 6c 69 7a 65 56 69 65 77 28 50 61 72 erializeView(Par
24300 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 se*, Table*, Exp
24310 72 2a 2c 20 69 6e 74 29 3b 0a 23 65 6e 64 69 66 r*, int);.#endif
24320 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ..#ifndef SQLITE
24330 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 0a 20 20 _OMIT_TRIGGER.
24340 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 void sqlite3Begi
24350 6e 54 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c nTrigger(Parse*,
24360 20 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 Token*,Token*,i
24370 6e 74 2c 69 6e 74 2c 49 64 4c 69 73 74 2a 2c 53 nt,int,IdList*,S
24380 72 63 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 rcList*,.
24390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
243a0 20 20 20 20 45 78 70 72 2a 2c 69 6e 74 2c 20 69 Expr*,int, i
243b0 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 nt);. void sqli
243c0 74 65 33 46 69 6e 69 73 68 54 72 69 67 67 65 72 te3FinishTrigger
243d0 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 (Parse*, Trigger
243e0 53 74 65 70 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a Step*, Token*);.
243f0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 void sqlite3Dr
24400 6f 70 54 72 69 67 67 65 72 28 50 61 72 73 65 2a opTrigger(Parse*
24410 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 , SrcList*, int)
24420 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
24430 44 72 6f 70 54 72 69 67 67 65 72 50 74 72 28 50 DropTriggerPtr(P
24440 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 2a 29 arse*, Trigger*)
24450 3b 0a 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c ;. Trigger *sql
24460 69 74 65 33 54 72 69 67 67 65 72 73 45 78 69 73 ite3TriggersExis
24470 74 28 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 t(Parse *, Table
24480 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 *, int, ExprList
24490 2a 2c 20 69 6e 74 20 2a 70 4d 61 73 6b 29 3b 0a *, int *pMask);.
244a0 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 Trigger *sqlit
244b0 65 33 54 72 69 67 67 65 72 4c 69 73 74 28 50 61 e3TriggerList(Pa
244c0 72 73 65 20 2a 2c 20 54 61 62 6c 65 20 2a 29 3b rse *, Table *);
244d0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
244e0 6f 64 65 52 6f 77 54 72 69 67 67 65 72 28 50 61 odeRowTrigger(Pa
244f0 72 73 65 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c rse*, Trigger *,
24500 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c int, ExprList*,
24510 20 69 6e 74 2c 20 54 61 62 6c 65 20 2a 2c 0a 20 int, Table *,.
24520 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24530 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 2c 20 int,
24540 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
24550 64 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 d sqlite3CodeRow
24560 54 72 69 67 67 65 72 44 69 72 65 63 74 28 50 61 TriggerDirect(Pa
24570 72 73 65 20 2a 2c 20 54 72 69 67 67 65 72 20 2a rse *, Trigger *
24580 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c 20 , Table *, int,
24590 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
245a0 64 20 73 71 6c 69 74 65 56 69 65 77 54 72 69 67 d sqliteViewTrig
245b0 67 65 72 73 28 50 61 72 73 65 2a 2c 20 54 61 62 gers(Parse*, Tab
245c0 6c 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c le*, Expr*, int,
245d0 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 20 20 76 ExprList*);. v
245e0 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 oid sqlite3Delet
245f0 65 54 72 69 67 67 65 72 53 74 65 70 28 73 71 6c eTriggerStep(sql
24600 69 74 65 33 2a 2c 20 54 72 69 67 67 65 72 53 74 ite3*, TriggerSt
24610 65 70 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 ep*);. TriggerS
24620 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 tep *sqlite3Trig
24630 67 65 72 53 65 6c 65 63 74 53 74 65 70 28 73 71 gerSelectStep(sq
24640 6c 69 74 65 33 2a 2c 53 65 6c 65 63 74 2a 29 3b lite3*,Select*);
24650 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a . TriggerStep *
24660 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 49 6e sqlite3TriggerIn
24670 73 65 72 74 53 74 65 70 28 73 71 6c 69 74 65 33 sertStep(sqlite3
24680 2a 2c 54 6f 6b 65 6e 2a 2c 20 49 64 4c 69 73 74 *,Token*, IdList
24690 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 *,.
246a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
246b0 20 20 20 20 20 20 20 20 20 20 20 53 65 6c 65 63 Selec
246c0 74 2a 2c 75 38 29 3b 0a 20 20 54 72 69 67 67 65 t*,u8);. Trigge
246d0 72 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 rStep *sqlite3Tr
246e0 69 67 67 65 72 55 70 64 61 74 65 53 74 65 70 28 iggerUpdateStep(
246f0 73 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c sqlite3*,Token*,
24700 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 2a ExprList*, Expr*
24710 2c 20 75 38 29 3b 0a 20 20 54 72 69 67 67 65 72 , u8);. Trigger
24720 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 Step *sqlite3Tri
24730 67 67 65 72 44 65 6c 65 74 65 53 74 65 70 28 73 ggerDeleteStep(s
24740 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 qlite3*,Token*,
24750 45 78 70 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 Expr*);. void s
24760 71 6c 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 qlite3DeleteTrig
24770 67 65 72 28 73 71 6c 69 74 65 33 2a 2c 20 54 72 ger(sqlite3*, Tr
24780 69 67 67 65 72 2a 29 3b 0a 20 20 76 6f 69 64 20 igger*);. void
24790 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 sqlite3UnlinkAnd
247a0 44 65 6c 65 74 65 54 72 69 67 67 65 72 28 73 71 DeleteTrigger(sq
247b0 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 lite3*,int,const
247c0 20 63 68 61 72 2a 29 3b 0a 20 20 75 33 32 20 73 char*);. u32 s
247d0 71 6c 69 74 65 33 54 72 69 67 67 65 72 43 6f 6c qlite3TriggerCol
247e0 6d 61 73 6b 28 50 61 72 73 65 2a 2c 54 72 69 67 mask(Parse*,Trig
247f0 67 65 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 ger*,ExprList*,i
24800 6e 74 2c 69 6e 74 2c 54 61 62 6c 65 2a 2c 69 6e nt,int,Table*,in
24810 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c t);.# define sql
24820 69 74 65 33 50 61 72 73 65 54 6f 70 6c 65 76 65 ite3ParseTopleve
24830 6c 28 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 6c l(p) ((p)->pTopl
24840 65 76 65 6c 20 3f 20 28 70 29 2d 3e 70 54 6f 70 evel ? (p)->pTop
24850 6c 65 76 65 6c 20 3a 20 28 70 29 29 0a 23 65 6c level : (p)).#el
24860 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
24870 74 65 33 54 72 69 67 67 65 72 73 45 78 69 73 74 te3TriggersExist
24880 28 42 2c 43 2c 44 2c 45 2c 46 29 20 30 0a 23 20 (B,C,D,E,F) 0.#
24890 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 44 65 define sqlite3De
248a0 6c 65 74 65 54 72 69 67 67 65 72 28 41 2c 42 29 leteTrigger(A,B)
248b0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
248c0 33 44 72 6f 70 54 72 69 67 67 65 72 50 74 72 28 3DropTriggerPtr(
248d0 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 73 71 A,B).# define sq
248e0 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 lite3UnlinkAndDe
248f0 6c 65 74 65 54 72 69 67 67 65 72 28 41 2c 42 2c leteTrigger(A,B,
24900 43 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 C).# define sqli
24910 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 te3CodeRowTrigge
24920 72 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 2c r(A,B,C,D,E,F,G,
24930 48 2c 49 29 0a 23 20 64 65 66 69 6e 65 20 73 71 H,I).# define sq
24940 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 lite3CodeRowTrig
24950 67 65 72 44 69 72 65 63 74 28 41 2c 42 2c 43 2c gerDirect(A,B,C,
24960 44 2c 45 2c 46 29 0a 23 20 64 65 66 69 6e 65 20 D,E,F).# define
24970 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 4c 69 sqlite3TriggerLi
24980 73 74 28 58 2c 20 59 29 20 30 0a 23 20 64 65 66 st(X, Y) 0.# def
24990 69 6e 65 20 73 71 6c 69 74 65 33 50 61 72 73 65 ine sqlite3Parse
249a0 54 6f 70 6c 65 76 65 6c 28 70 29 20 70 0a 23 20 Toplevel(p) p.#
249b0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 define sqlite3Tr
249c0 69 67 67 65 72 43 6f 6c 6d 61 73 6b 28 41 2c 42 iggerColmask(A,B
249d0 2c 43 2c 44 2c 45 2c 46 2c 47 29 20 30 0a 23 65 ,C,D,E,F,G) 0.#e
249e0 6e 64 69 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 ndif..int sqlite
249f0 33 4a 6f 69 6e 54 79 70 65 28 50 61 72 73 65 2a 3JoinType(Parse*
24a00 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a , Token*, Token*
24a10 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
24a20 73 71 6c 69 74 65 33 43 72 65 61 74 65 46 6f 72 sqlite3CreateFor
24a30 65 69 67 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 eignKey(Parse*,
24a40 45 78 70 72 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e ExprList*, Token
24a50 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e *, ExprList*, in
24a60 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
24a70 44 65 66 65 72 46 6f 72 65 69 67 6e 4b 65 79 28 DeferForeignKey(
24a80 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 Parse*, int);.#i
24a90 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
24aa0 54 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a T_AUTHORIZATION.
24ab0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 void sqlite3Au
24ac0 74 68 52 65 61 64 28 50 61 72 73 65 2a 2c 45 78 thRead(Parse*,Ex
24ad0 70 72 2a 2c 53 63 68 65 6d 61 2a 2c 53 72 63 4c pr*,Schema*,SrcL
24ae0 69 73 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c ist*);. int sql
24af0 69 74 65 33 41 75 74 68 43 68 65 63 6b 28 50 61 ite3AuthCheck(Pa
24b00 72 73 65 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 rse*,int, const
24b10 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
24b20 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
24b30 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
24b40 41 75 74 68 43 6f 6e 74 65 78 74 50 75 73 68 28 AuthContextPush(
24b50 50 61 72 73 65 2a 2c 20 41 75 74 68 43 6f 6e 74 Parse*, AuthCont
24b60 65 78 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 ext*, const char
24b70 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
24b80 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 e3AuthContextPop
24b90 28 41 75 74 68 43 6f 6e 74 65 78 74 2a 29 3b 0a (AuthContext*);.
24ba0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 41 75 74 int sqlite3Aut
24bb0 68 52 65 61 64 43 6f 6c 28 50 61 72 73 65 2a 2c hReadCol(Parse*,
24bc0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 const char *, c
24bd0 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 onst char *, int
24be0 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e );.#else.# defin
24bf0 65 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 e sqlite3AuthRea
24c00 64 28 61 2c 62 2c 63 2c 64 29 0a 23 20 64 65 66 d(a,b,c,d).# def
24c10 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 ine sqlite3AuthC
24c20 68 65 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 29 20 heck(a,b,c,d,e)
24c30 20 20 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 64 SQLITE_OK.# d
24c40 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 efine sqlite3Aut
24c50 68 43 6f 6e 74 65 78 74 50 75 73 68 28 61 2c 62 hContextPush(a,b
24c60 2c 63 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ,c).# define sql
24c70 69 74 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 ite3AuthContextP
24c80 6f 70 28 61 29 20 20 28 28 76 6f 69 64 29 28 61 op(a) ((void)(a
24c90 29 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 )).#endif.void s
24ca0 71 6c 69 74 65 33 41 74 74 61 63 68 28 50 61 72 qlite3Attach(Par
24cb0 73 65 2a 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 se*, Expr*, Expr
24cc0 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 *, Expr*);.void
24cd0 73 71 6c 69 74 65 33 44 65 74 61 63 68 28 50 61 sqlite3Detach(Pa
24ce0 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f rse*, Expr*);.vo
24cf0 69 64 20 73 71 6c 69 74 65 33 46 69 78 49 6e 69 id sqlite3FixIni
24d00 74 28 44 62 46 69 78 65 72 2a 2c 20 50 61 72 73 t(DbFixer*, Pars
24d10 65 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 e*, int, const c
24d20 68 61 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 har*, const Toke
24d30 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 n*);.int sqlite3
24d40 46 69 78 53 72 63 4c 69 73 74 28 44 62 46 69 78 FixSrcList(DbFix
24d50 65 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a er*, SrcList*);.
24d60 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 53 65 int sqlite3FixSe
24d70 6c 65 63 74 28 44 62 46 69 78 65 72 2a 2c 20 53 lect(DbFixer*, S
24d80 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
24d90 69 74 65 33 46 69 78 45 78 70 72 28 44 62 46 69 ite3FixExpr(DbFi
24da0 78 65 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e xer*, Expr*);.in
24db0 74 20 73 71 6c 69 74 65 33 46 69 78 45 78 70 72 t sqlite3FixExpr
24dc0 4c 69 73 74 28 44 62 46 69 78 65 72 2a 2c 20 45 List(DbFixer*, E
24dd0 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 xprList*);.int s
24de0 71 6c 69 74 65 33 46 69 78 54 72 69 67 67 65 72 qlite3FixTrigger
24df0 53 74 65 70 28 44 62 46 69 78 65 72 2a 2c 20 54 Step(DbFixer*, T
24e00 72 69 67 67 65 72 53 74 65 70 2a 29 3b 0a 69 6e riggerStep*);.in
24e10 74 20 73 71 6c 69 74 65 33 41 74 6f 46 28 63 6f t sqlite3AtoF(co
24e20 6e 73 74 20 63 68 61 72 20 2a 7a 2c 20 64 6f 75 nst char *z, dou
24e30 62 6c 65 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a ble*, int, u8);.
24e40 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 49 6e int sqlite3GetIn
24e50 74 33 32 28 63 6f 6e 73 74 20 63 68 61 72 20 2a t32(const char *
24e60 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c , int*);.int sql
24e70 69 74 65 33 41 74 6f 69 28 63 6f 6e 73 74 20 63 ite3Atoi(const c
24e80 68 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 har*);.int sqlit
24e90 65 33 55 74 66 31 36 42 79 74 65 4c 65 6e 28 63 e3Utf16ByteLen(c
24ea0 6f 6e 73 74 20 76 6f 69 64 20 2a 70 44 61 74 61 onst void *pData
24eb0 2c 20 69 6e 74 20 6e 43 68 61 72 29 3b 0a 69 6e , int nChar);.in
24ec0 74 20 73 71 6c 69 74 65 33 55 74 66 38 43 68 61 t sqlite3Utf8Cha
24ed0 72 4c 65 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 rLen(const char
24ee0 2a 70 44 61 74 61 2c 20 69 6e 74 20 6e 42 79 74 *pData, int nByt
24ef0 65 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 55 e);.u32 sqlite3U
24f00 74 66 38 52 65 61 64 28 63 6f 6e 73 74 20 75 38 tf8Read(const u8
24f10 2a 2a 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 **);.LogEst sqli
24f20 74 65 33 4c 6f 67 45 73 74 28 75 36 34 29 3b 0a te3LogEst(u64);.
24f30 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f LogEst sqlite3Lo
24f40 67 45 73 74 41 64 64 28 4c 6f 67 45 73 74 2c 4c gEstAdd(LogEst,L
24f50 6f 67 45 73 74 29 3b 0a 23 69 66 6e 64 65 66 20 ogEst);.#ifndef
24f60 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
24f70 55 41 4c 54 41 42 4c 45 0a 4c 6f 67 45 73 74 20 UALTABLE.LogEst
24f80 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 46 72 6f sqlite3LogEstFro
24f90 6d 44 6f 75 62 6c 65 28 64 6f 75 62 6c 65 29 3b mDouble(double);
24fa0 0a 23 65 6e 64 69 66 0a 75 36 34 20 73 71 6c 69 .#endif.u64 sqli
24fb0 74 65 33 4c 6f 67 45 73 74 54 6f 49 6e 74 28 4c te3LogEstToInt(L
24fc0 6f 67 45 73 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 ogEst);../*.** R
24fd0 6f 75 74 69 6e 65 73 20 74 6f 20 72 65 61 64 20 outines to read
24fe0 61 6e 64 20 77 72 69 74 65 20 76 61 72 69 61 62 and write variab
24ff0 6c 65 2d 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 le-length intege
25000 72 73 2e 20 20 54 68 65 73 65 20 75 73 65 64 20 rs. These used
25010 74 6f 0a 2a 2a 20 62 65 20 64 65 66 69 6e 65 64 to.** be defined
25020 20 6c 6f 63 61 6c 6c 79 2c 20 62 75 74 20 6e 6f locally, but no
25030 77 20 77 65 20 75 73 65 20 74 68 65 20 76 61 72 w we use the var
25040 69 6e 74 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 int routines in
25050 74 68 65 20 75 74 69 6c 2e 63 0a 2a 2a 20 66 69 the util.c.** fi
25060 6c 65 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 le..*/.int sqlit
25070 65 33 50 75 74 56 61 72 69 6e 74 28 75 6e 73 69 e3PutVarint(unsi
25080 67 6e 65 64 20 63 68 61 72 2a 2c 20 75 36 34 29 gned char*, u64)
25090 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 56 ;.u8 sqlite3GetV
250a0 61 72 69 6e 74 28 63 6f 6e 73 74 20 75 6e 73 69 arint(const unsi
250b0 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 75 36 34 gned char *, u64
250c0 20 2a 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 *);.u8 sqlite3G
250d0 65 74 56 61 72 69 6e 74 33 32 28 63 6f 6e 73 74 etVarint32(const
250e0 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a unsigned char *
250f0 2c 20 75 33 32 20 2a 29 3b 0a 69 6e 74 20 73 71 , u32 *);.int sq
25100 6c 69 74 65 33 56 61 72 69 6e 74 4c 65 6e 28 75 lite3VarintLen(u
25110 36 34 20 76 29 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 64 v);../*.** Th
25120 65 20 63 6f 6d 6d 6f 6e 20 63 61 73 65 20 69 73 e common case is
25130 20 66 6f 72 20 61 20 76 61 72 69 6e 74 20 74 6f for a varint to
25140 20 62 65 20 61 20 73 69 6e 67 6c 65 20 62 79 74 be a single byt
25150 65 2e 20 20 54 68 65 79 20 66 6f 6c 6c 6f 77 69 e. They followi
25160 6e 67 0a 2a 2a 20 6d 61 63 72 6f 73 20 68 61 6e ng.** macros han
25170 64 6c 65 20 74 68 65 20 63 6f 6d 6d 6f 6e 20 63 dle the common c
25180 61 73 65 20 77 69 74 68 6f 75 74 20 61 20 70 72 ase without a pr
25190 6f 63 65 64 75 72 65 20 63 61 6c 6c 2c 20 62 75 ocedure call, bu
251a0 74 20 74 68 65 6e 20 63 61 6c 6c 0a 2a 2a 20 74 t then call.** t
251b0 68 65 20 70 72 6f 63 65 64 75 72 65 20 66 6f 72 he procedure for
251c0 20 6c 61 72 67 65 72 20 76 61 72 69 6e 74 73 2e larger varints.
251d0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 67 65 74 56 .*/.#define getV
251e0 61 72 69 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a arint32(A,B) \.
251f0 20 20 28 75 38 29 28 28 2a 28 41 29 3c 28 75 38 (u8)((*(A)<(u8
25200 29 30 78 38 30 29 3f 28 28 42 29 3d 28 75 33 32 )0x80)?((B)=(u32
25210 29 2a 28 41 29 29 2c 31 3a 73 71 6c 69 74 65 33 )*(A)),1:sqlite3
25220 47 65 74 56 61 72 69 6e 74 33 32 28 28 41 29 2c GetVarint32((A),
25230 28 75 33 32 20 2a 29 26 28 42 29 29 29 0a 23 64 (u32 *)&(B))).#d
25240 65 66 69 6e 65 20 70 75 74 56 61 72 69 6e 74 33 efine putVarint3
25250 32 28 41 2c 42 29 20 20 5c 0a 20 20 28 75 38 29 2(A,B) \. (u8)
25260 28 28 28 75 33 32 29 28 42 29 3c 28 75 33 32 29 (((u32)(B)<(u32)
25270 30 78 38 30 29 3f 28 2a 28 41 29 3d 28 75 6e 73 0x80)?(*(A)=(uns
25280 69 67 6e 65 64 20 63 68 61 72 29 28 42 29 29 2c igned char)(B)),
25290 31 3a 5c 0a 20 20 73 71 6c 69 74 65 33 50 75 74 1:\. sqlite3Put
252a0 56 61 72 69 6e 74 28 28 41 29 2c 28 42 29 29 29 Varint((A),(B)))
252b0 0a 23 64 65 66 69 6e 65 20 67 65 74 56 61 72 69 .#define getVari
252c0 6e 74 20 20 20 20 73 71 6c 69 74 65 33 47 65 74 nt sqlite3Get
252d0 56 61 72 69 6e 74 0a 23 64 65 66 69 6e 65 20 70 Varint.#define p
252e0 75 74 56 61 72 69 6e 74 20 20 20 20 73 71 6c 69 utVarint sqli
252f0 74 65 33 50 75 74 56 61 72 69 6e 74 0a 0a 0a 63 te3PutVarint...c
25300 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 onst char *sqlit
25310 65 33 49 6e 64 65 78 41 66 66 69 6e 69 74 79 53 e3IndexAffinityS
25320 74 72 28 56 64 62 65 20 2a 2c 20 49 6e 64 65 78 tr(Vdbe *, Index
25330 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
25340 33 54 61 62 6c 65 41 66 66 69 6e 69 74 79 28 56 3TableAffinity(V
25350 64 62 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e dbe*, Table*, in
25360 74 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 t);.char sqlite3
25370 43 6f 6d 70 61 72 65 41 66 66 69 6e 69 74 79 28 CompareAffinity(
25380 45 78 70 72 20 2a 70 45 78 70 72 2c 20 63 68 61 Expr *pExpr, cha
25390 72 20 61 66 66 32 29 3b 0a 69 6e 74 20 73 71 6c r aff2);.int sql
253a0 69 74 65 33 49 6e 64 65 78 41 66 66 69 6e 69 74 ite3IndexAffinit
253b0 79 4f 6b 28 45 78 70 72 20 2a 70 45 78 70 72 2c yOk(Expr *pExpr,
253c0 20 63 68 61 72 20 69 64 78 5f 61 66 66 69 6e 69 char idx_affini
253d0 74 79 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 ty);.char sqlite
253e0 33 45 78 70 72 41 66 66 69 6e 69 74 79 28 45 78 3ExprAffinity(Ex
253f0 70 72 20 2a 70 45 78 70 72 29 3b 0a 69 6e 74 20 pr *pExpr);.int
25400 73 71 6c 69 74 65 33 41 74 6f 69 36 34 28 63 6f sqlite3Atoi64(co
25410 6e 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a 2c nst char*, i64*,
25420 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 int, u8);.int s
25430 71 6c 69 74 65 33 44 65 63 4f 72 48 65 78 54 6f qlite3DecOrHexTo
25440 49 36 34 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c I64(const char*,
25450 20 69 36 34 2a 29 3b 0a 76 6f 69 64 20 73 71 6c i64*);.void sql
25460 69 74 65 33 45 72 72 6f 72 57 69 74 68 4d 73 67 ite3ErrorWithMsg
25470 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
25480 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e 2e 2e 29 const char*,...)
25490 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 72 ;.void sqlite3Er
254a0 72 6f 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ror(sqlite3*,int
254b0 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
254c0 48 65 78 54 6f 42 6c 6f 62 28 73 71 6c 69 74 65 HexToBlob(sqlite
254d0 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 3*, const char *
254e0 7a 2c 20 69 6e 74 20 6e 29 3b 0a 75 38 20 73 71 z, int n);.u8 sq
254f0 6c 69 74 65 33 48 65 78 54 6f 49 6e 74 28 69 6e lite3HexToInt(in
25500 74 20 68 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 t h);.int sqlite
25510 33 54 77 6f 50 61 72 74 4e 61 6d 65 28 50 61 72 3TwoPartName(Par
25520 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c 20 54 se *, Token *, T
25530 6f 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2a oken *, Token **
25540 29 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 );..#if defined(
25550 53 51 4c 49 54 45 5f 54 45 53 54 29 20 0a 63 6f SQLITE_TEST) .co
25560 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 nst char *sqlite
25570 33 45 72 72 4e 61 6d 65 28 69 6e 74 29 3b 0a 23 3ErrName(int);.#
25580 65 6e 64 69 66 0a 0a 63 6f 6e 73 74 20 63 68 61 endif..const cha
25590 72 20 2a 73 71 6c 69 74 65 33 45 72 72 53 74 72 r *sqlite3ErrStr
255a0 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 (int);.int sqlit
255b0 65 33 52 65 61 64 53 63 68 65 6d 61 28 50 61 72 e3ReadSchema(Par
255c0 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 43 6f 6c se *pParse);.Col
255d0 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 46 69 6e lSeq *sqlite3Fin
255e0 64 43 6f 6c 6c 53 65 71 28 73 71 6c 69 74 65 33 dCollSeq(sqlite3
255f0 2a 2c 75 38 20 65 6e 63 2c 20 63 6f 6e 73 74 20 *,u8 enc, const
25600 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 43 6f 6c 6c char*,int);.Coll
25610 53 65 71 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 Seq *sqlite3Loca
25620 74 65 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 teCollSeq(Parse
25630 2a 70 50 61 72 73 65 2c 20 63 6f 6e 73 74 20 63 *pParse, const c
25640 68 61 72 2a 7a 4e 61 6d 65 29 3b 0a 43 6f 6c 6c har*zName);.Coll
25650 53 65 71 20 2a 73 71 6c 69 74 65 33 45 78 70 72 Seq *sqlite3Expr
25660 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 CollSeq(Parse *p
25670 50 61 72 73 65 2c 20 45 78 70 72 20 2a 70 45 78 Parse, Expr *pEx
25680 70 72 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 pr);.Expr *sqlit
25690 65 33 45 78 70 72 41 64 64 43 6f 6c 6c 61 74 65 e3ExprAddCollate
256a0 54 6f 6b 65 6e 28 50 61 72 73 65 20 2a 70 50 61 Token(Parse *pPa
256b0 72 73 65 2c 20 45 78 70 72 2a 2c 20 63 6f 6e 73 rse, Expr*, cons
256c0 74 20 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a t Token*, int);.
256d0 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 Expr *sqlite3Exp
256e0 72 41 64 64 43 6f 6c 6c 61 74 65 53 74 72 69 6e rAddCollateStrin
256f0 67 28 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 63 g(Parse*,Expr*,c
25700 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 45 78 70 onst char*);.Exp
25710 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 53 6b r *sqlite3ExprSk
25720 69 70 43 6f 6c 6c 61 74 65 28 45 78 70 72 2a 29 ipCollate(Expr*)
25730 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 68 65 ;.int sqlite3Che
25740 63 6b 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 ckCollSeq(Parse
25750 2a 2c 20 43 6f 6c 6c 53 65 71 20 2a 29 3b 0a 69 *, CollSeq *);.i
25760 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 6b 4f nt sqlite3CheckO
25770 62 6a 65 63 74 4e 61 6d 65 28 50 61 72 73 65 20 bjectName(Parse
25780 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 *, const char *)
25790 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 64 ;.void sqlite3Vd
257a0 62 65 53 65 74 43 68 61 6e 67 65 73 28 73 71 6c beSetChanges(sql
257b0 69 74 65 33 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e ite3 *, int);.in
257c0 74 20 73 71 6c 69 74 65 33 41 64 64 49 6e 74 36 t sqlite3AddInt6
257d0 34 28 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 4(i64*,i64);.int
257e0 20 73 71 6c 69 74 65 33 53 75 62 49 6e 74 36 34 sqlite3SubInt64
257f0 28 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 (i64*,i64);.int
25800 73 71 6c 69 74 65 33 4d 75 6c 49 6e 74 36 34 28 sqlite3MulInt64(
25810 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 i64*,i64);.int s
25820 71 6c 69 74 65 33 41 62 73 49 6e 74 33 32 28 69 qlite3AbsInt32(i
25830 6e 74 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 nt);.#ifdef SQLI
25840 54 45 5f 45 4e 41 42 4c 45 5f 38 5f 33 5f 4e 41 TE_ENABLE_8_3_NA
25850 4d 45 53 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 MES.void sqlite3
25860 46 69 6c 65 53 75 66 66 69 78 33 28 63 6f 6e 73 FileSuffix3(cons
25870 74 20 63 68 61 72 2a 2c 20 63 68 61 72 2a 29 3b t char*, char*);
25880 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
25890 73 71 6c 69 74 65 33 46 69 6c 65 53 75 66 66 69 sqlite3FileSuffi
258a0 78 33 28 58 2c 59 29 0a 23 65 6e 64 69 66 0a 75 x3(X,Y).#endif.u
258b0 38 20 73 71 6c 69 74 65 33 47 65 74 42 6f 6f 6c 8 sqlite3GetBool
258c0 65 61 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ean(const char *
258d0 7a 2c 75 38 29 3b 0a 0a 63 6f 6e 73 74 20 76 6f z,u8);..const vo
258e0 69 64 20 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 id *sqlite3Value
258f0 54 65 78 74 28 73 71 6c 69 74 65 33 5f 76 61 6c Text(sqlite3_val
25900 75 65 2a 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 ue*, u8);.int sq
25910 6c 69 74 65 33 56 61 6c 75 65 42 79 74 65 73 28 lite3ValueBytes(
25920 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 sqlite3_value*,
25930 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 u8);.void sqlite
25940 33 56 61 6c 75 65 53 65 74 53 74 72 28 73 71 6c 3ValueSetStr(sql
25950 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 69 6e 74 ite3_value*, int
25960 2c 20 63 6f 6e 73 74 20 76 6f 69 64 20 2a 2c 75 , const void *,u
25970 38 2c 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 8, .
25980 20 20 20 20 20 20 20 20 20 20 20 20 76 6f 69 64 void
25990 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f 69 (*)(void*));.voi
259a0 64 20 73 71 6c 69 74 65 33 56 61 6c 75 65 53 65 d sqlite3ValueSe
259b0 74 4e 75 6c 6c 28 73 71 6c 69 74 65 33 5f 76 61 tNull(sqlite3_va
259c0 6c 75 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 lue*);.void sqli
259d0 74 65 33 56 61 6c 75 65 46 72 65 65 28 73 71 6c te3ValueFree(sql
259e0 69 74 65 33 5f 76 61 6c 75 65 2a 29 3b 0a 73 71 ite3_value*);.sq
259f0 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 73 71 6c lite3_value *sql
25a00 69 74 65 33 56 61 6c 75 65 4e 65 77 28 73 71 6c ite3ValueNew(sql
25a10 69 74 65 33 20 2a 29 3b 0a 63 68 61 72 20 2a 73 ite3 *);.char *s
25a20 71 6c 69 74 65 33 55 74 66 31 36 74 6f 38 28 73 qlite3Utf16to8(s
25a30 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 qlite3 *, const
25a40 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 75 38 29 3b void*, int, u8);
25a50 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 61 6c 75 .int sqlite3Valu
25a60 65 46 72 6f 6d 45 78 70 72 28 73 71 6c 69 74 65 eFromExpr(sqlite
25a70 33 20 2a 2c 20 45 78 70 72 20 2a 2c 20 75 38 2c 3 *, Expr *, u8,
25a80 20 75 38 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c u8, sqlite3_val
25a90 75 65 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ue **);.void sql
25aa0 69 74 65 33 56 61 6c 75 65 41 70 70 6c 79 41 66 ite3ValueApplyAf
25ab0 66 69 6e 69 74 79 28 73 71 6c 69 74 65 33 5f 76 finity(sqlite3_v
25ac0 61 6c 75 65 20 2a 2c 20 75 38 2c 20 75 38 29 3b alue *, u8, u8);
25ad0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
25ae0 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a 65 78 74 AMALGAMATION.ext
25af0 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e ern const unsign
25b00 65 64 20 63 68 61 72 20 73 71 6c 69 74 65 33 4f ed char sqlite3O
25b10 70 63 6f 64 65 50 72 6f 70 65 72 74 79 5b 5d 3b pcodeProperty[];
25b20 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e .extern const un
25b30 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 signed char sqli
25b40 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b te3UpperToLower[
25b50 5d 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 ];.extern const
25b60 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 unsigned char sq
25b70 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 5d 3b lite3CtypeMap[];
25b80 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 54 6f .extern const To
25b90 6b 65 6e 20 73 71 6c 69 74 65 33 49 6e 74 54 6f ken sqlite3IntTo
25ba0 6b 65 6e 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 kens[];.extern S
25bb0 51 4c 49 54 45 5f 57 53 44 20 73 74 72 75 63 74 QLITE_WSD struct
25bc0 20 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 73 Sqlite3Config s
25bd0 71 6c 69 74 65 33 43 6f 6e 66 69 67 3b 0a 65 78 qlite3Config;.ex
25be0 74 65 72 6e 20 53 51 4c 49 54 45 5f 57 53 44 20 tern SQLITE_WSD
25bf0 46 75 6e 63 44 65 66 48 61 73 68 20 73 71 6c 69 FuncDefHash sqli
25c00 74 65 33 47 6c 6f 62 61 6c 46 75 6e 63 74 69 6f te3GlobalFunctio
25c10 6e 73 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 ns;.#ifndef SQLI
25c20 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 65 78 74 65 TE_OMIT_WSD.exte
25c30 72 6e 20 69 6e 74 20 73 71 6c 69 74 65 33 50 65 rn int sqlite3Pe
25c40 6e 64 69 6e 67 42 79 74 65 3b 0a 23 65 6e 64 69 ndingByte;.#endi
25c50 66 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 f.#endif.void sq
25c60 6c 69 74 65 33 52 6f 6f 74 50 61 67 65 4d 6f 76 lite3RootPageMov
25c70 65 64 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 ed(sqlite3*, int
25c80 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
25c90 64 20 73 71 6c 69 74 65 33 52 65 69 6e 64 65 78 d sqlite3Reindex
25ca0 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c (Parse*, Token*,
25cb0 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
25cc0 71 6c 69 74 65 33 41 6c 74 65 72 46 75 6e 63 74 qlite3AlterFunct
25cd0 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 ions(void);.void
25ce0 20 73 71 6c 69 74 65 33 41 6c 74 65 72 52 65 6e sqlite3AlterRen
25cf0 61 6d 65 54 61 62 6c 65 28 50 61 72 73 65 2a 2c ameTable(Parse*,
25d00 20 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e SrcList*, Token
25d10 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 *);.int sqlite3G
25d20 65 74 54 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 6e etToken(const un
25d30 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 69 signed char *, i
25d40 6e 74 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 nt *);.void sqli
25d50 74 65 33 4e 65 73 74 65 64 50 61 72 73 65 28 50 te3NestedParse(P
25d60 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 arse*, const cha
25d70 72 2a 2c 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 r*, ...);.void s
25d80 71 6c 69 74 65 33 45 78 70 69 72 65 50 72 65 70 qlite3ExpirePrep
25d90 61 72 65 64 53 74 61 74 65 6d 65 6e 74 73 28 73 aredStatements(s
25da0 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 qlite3*);.int sq
25db0 6c 69 74 65 33 43 6f 64 65 53 75 62 73 65 6c 65 lite3CodeSubsele
25dc0 63 74 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 ct(Parse *, Expr
25dd0 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 *, int, int);.v
25de0 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 oid sqlite3Selec
25df0 74 50 72 65 70 28 50 61 72 73 65 2a 2c 20 53 65 tPrep(Parse*, Se
25e00 6c 65 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 lect*, NameConte
25e10 78 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 xt*);.int sqlite
25e20 33 4d 61 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 3MatchSpanName(c
25e30 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
25e40 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 t char*, const c
25e50 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 har*, const char
25e60 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 *);.int sqlite3R
25e70 65 73 6f 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 esolveExprNames(
25e80 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 NameContext*, Ex
25e90 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 pr*);.void sqlit
25ea0 65 33 52 65 73 6f 6c 76 65 53 65 6c 65 63 74 4e e3ResolveSelectN
25eb0 61 6d 65 73 28 50 61 72 73 65 2a 2c 20 53 65 6c ames(Parse*, Sel
25ec0 65 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 ect*, NameContex
25ed0 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 t*);.void sqlite
25ee0 33 52 65 73 6f 6c 76 65 53 65 6c 66 52 65 66 65 3ResolveSelfRefe
25ef0 72 65 6e 63 65 28 50 61 72 73 65 2a 2c 54 61 62 rence(Parse*,Tab
25f00 6c 65 2a 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 78 le*,int,Expr*,Ex
25f10 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 prList*);.int sq
25f20 6c 69 74 65 33 52 65 73 6f 6c 76 65 4f 72 64 65 lite3ResolveOrde
25f30 72 47 72 6f 75 70 42 79 28 50 61 72 73 65 2a 2c rGroupBy(Parse*,
25f40 20 53 65 6c 65 63 74 2a 2c 20 45 78 70 72 4c 69 Select*, ExprLi
25f50 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a st*, const char*
25f60 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
25f70 6f 6c 75 6d 6e 44 65 66 61 75 6c 74 28 56 64 62 olumnDefault(Vdb
25f80 65 20 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e e *, Table *, in
25f90 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
25fa0 6c 69 74 65 33 41 6c 74 65 72 46 69 6e 69 73 68 lite3AlterFinish
25fb0 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 AddColumn(Parse
25fc0 2a 2c 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 *, Token *);.voi
25fd0 64 20 73 71 6c 69 74 65 33 41 6c 74 65 72 42 65 d sqlite3AlterBe
25fe0 67 69 6e 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 ginAddColumn(Par
25ff0 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 29 se *, SrcList *)
26000 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 ;.CollSeq *sqlit
26010 65 33 47 65 74 43 6f 6c 6c 53 65 71 28 50 61 72 e3GetCollSeq(Par
26020 73 65 2a 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 71 se*, u8, CollSeq
26030 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 *, const char*)
26040 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 41 66 ;.char sqlite3Af
26050 66 69 6e 69 74 79 54 79 70 65 28 63 6f 6e 73 74 finityType(const
26060 20 63 68 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 6f char*, u8*);.vo
26070 69 64 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a id sqlite3Analyz
26080 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a e(Parse*, Token*
26090 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 , Token*);.int s
260a0 71 6c 69 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 qlite3InvokeBusy
260b0 48 61 6e 64 6c 65 72 28 42 75 73 79 48 61 6e 64 Handler(BusyHand
260c0 6c 65 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ler*);.int sqlit
260d0 65 33 46 69 6e 64 44 62 28 73 71 6c 69 74 65 33 e3FindDb(sqlite3
260e0 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 *, Token*);.int
260f0 73 71 6c 69 74 65 33 46 69 6e 64 44 62 4e 61 6d sqlite3FindDbNam
26100 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e e(sqlite3 *, con
26110 73 74 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 st char *);.int
26120 73 71 6c 69 74 65 33 41 6e 61 6c 79 73 69 73 4c sqlite3AnalysisL
26130 6f 61 64 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 oad(sqlite3*,int
26140 20 69 44 42 29 3b 0a 76 6f 69 64 20 73 71 6c 69 iDB);.void sqli
26150 74 65 33 44 65 6c 65 74 65 49 6e 64 65 78 53 61 te3DeleteIndexSa
26160 6d 70 6c 65 73 28 73 71 6c 69 74 65 33 2a 2c 49 mples(sqlite3*,I
26170 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ndex*);.void sql
26180 69 74 65 33 44 65 66 61 75 6c 74 52 6f 77 45 73 ite3DefaultRowEs
26190 74 28 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 t(Index*);.void
261a0 73 71 6c 69 74 65 33 52 65 67 69 73 74 65 72 4c sqlite3RegisterL
261b0 69 6b 65 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c ikeFunctions(sql
261c0 69 74 65 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 ite3*, int);.int
261d0 20 73 71 6c 69 74 65 33 49 73 4c 69 6b 65 46 75 sqlite3IsLikeFu
261e0 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c nction(sqlite3*,
261f0 45 78 70 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a Expr*,int*,char*
26200 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d );.void sqlite3M
26210 69 6e 69 6d 75 6d 46 69 6c 65 46 6f 72 6d 61 74 inimumFileFormat
26220 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e (Parse*, int, in
26230 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
26240 53 63 68 65 6d 61 43 6c 65 61 72 28 76 6f 69 64 SchemaClear(void
26250 20 2a 29 3b 0a 53 63 68 65 6d 61 20 2a 73 71 6c *);.Schema *sql
26260 69 74 65 33 53 63 68 65 6d 61 47 65 74 28 73 71 ite3SchemaGet(sq
26270 6c 69 74 65 33 20 2a 2c 20 42 74 72 65 65 20 2a lite3 *, Btree *
26280 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 63 );.int sqlite3Sc
26290 68 65 6d 61 54 6f 49 6e 64 65 78 28 73 71 6c 69 hemaToIndex(sqli
262a0 74 65 33 20 2a 64 62 2c 20 53 63 68 65 6d 61 20 te3 *db, Schema
262b0 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c *);.KeyInfo *sql
262c0 69 74 65 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f 63 ite3KeyInfoAlloc
262d0 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 6e (sqlite3*,int,in
262e0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
262f0 4b 65 79 49 6e 66 6f 55 6e 72 65 66 28 4b 65 79 KeyInfoUnref(Key
26300 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 Info*);.KeyInfo
26310 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f 52 *sqlite3KeyInfoR
26320 65 66 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 ef(KeyInfo*);.Ke
26330 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 yInfo *sqlite3Ke
26340 79 49 6e 66 6f 4f 66 49 6e 64 65 78 28 50 61 72 yInfoOfIndex(Par
26350 73 65 2a 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 69 se*, Index*);.#i
26360 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 fdef SQLITE_DEBU
26370 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 G.int sqlite3Key
26380 49 6e 66 6f 49 73 57 72 69 74 65 61 62 6c 65 28 InfoIsWriteable(
26390 4b 65 79 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 KeyInfo*);.#endi
263a0 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 72 65 f.int sqlite3Cre
263b0 61 74 65 46 75 6e 63 28 73 71 6c 69 74 65 33 20 ateFunc(sqlite3
263c0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c *, const char *,
263d0 20 69 6e 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 int, int, void
263e0 2a 2c 20 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 *, . void (*)(s
263f0 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
26400 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
26410 65 20 2a 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a e **),. void (*
26420 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 )(sqlite3_contex
26430 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 t*,int,sqlite3_v
26440 61 6c 75 65 20 2a 2a 29 2c 20 76 6f 69 64 20 28 alue **), void (
26450 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 *)(sqlite3_conte
26460 78 74 2a 29 2c 0a 20 20 46 75 6e 63 44 65 73 74 xt*),. FuncDest
26470 72 75 63 74 6f 72 20 2a 70 44 65 73 74 72 75 63 ructor *pDestruc
26480 74 6f 72 0a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 tor.);.int sqlit
26490 65 33 41 70 69 45 78 69 74 28 73 71 6c 69 74 65 e3ApiExit(sqlite
264a0 33 20 2a 64 62 2c 20 69 6e 74 29 3b 0a 69 6e 74 3 *db, int);.int
264b0 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 65 6d 70 sqlite3OpenTemp
264c0 44 61 74 61 62 61 73 65 28 50 61 72 73 65 20 2a Database(Parse *
264d0 29 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 );..void sqlite3
264e0 53 74 72 41 63 63 75 6d 49 6e 69 74 28 53 74 72 StrAccumInit(Str
264f0 41 63 63 75 6d 2a 2c 20 63 68 61 72 2a 2c 20 69 Accum*, char*, i
26500 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
26510 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d 41 70 qlite3StrAccumAp
26520 70 65 6e 64 28 53 74 72 41 63 63 75 6d 2a 2c 63 pend(StrAccum*,c
26530 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b onst char*,int);
26540 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 .void sqlite3Str
26550 41 63 63 75 6d 41 70 70 65 6e 64 41 6c 6c 28 53 AccumAppendAll(S
26560 74 72 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 trAccum*,const c
26570 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
26580 74 65 33 41 70 70 65 6e 64 43 68 61 72 28 53 74 te3AppendChar(St
26590 72 41 63 63 75 6d 2a 2c 69 6e 74 2c 63 68 61 72 rAccum*,int,char
265a0 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
265b0 53 74 72 41 63 63 75 6d 46 69 6e 69 73 68 28 53 StrAccumFinish(S
265c0 74 72 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 trAccum*);.void
265d0 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d 52 sqlite3StrAccumR
265e0 65 73 65 74 28 53 74 72 41 63 63 75 6d 2a 29 3b eset(StrAccum*);
265f0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c .void sqlite3Sel
26600 65 63 74 44 65 73 74 49 6e 69 74 28 53 65 6c 65 ectDestInit(Sele
26610 63 74 44 65 73 74 2a 2c 69 6e 74 2c 69 6e 74 29 ctDest*,int,int)
26620 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 43 ;.Expr *sqlite3C
26630 72 65 61 74 65 43 6f 6c 75 6d 6e 45 78 70 72 28 reateColumnExpr(
26640 73 71 6c 69 74 65 33 20 2a 2c 20 53 72 63 4c 69 sqlite3 *, SrcLi
26650 73 74 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b st *, int, int);
26660 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 61 ..void sqlite3Ba
26670 63 6b 75 70 52 65 73 74 61 72 74 28 73 71 6c 69 ckupRestart(sqli
26680 74 65 33 5f 62 61 63 6b 75 70 20 2a 29 3b 0a 76 te3_backup *);.v
26690 6f 69 64 20 73 71 6c 69 74 65 33 42 61 63 6b 75 oid sqlite3Backu
266a0 70 55 70 64 61 74 65 28 73 71 6c 69 74 65 33 5f pUpdate(sqlite3_
266b0 62 61 63 6b 75 70 20 2a 2c 20 50 67 6e 6f 2c 20 backup *, Pgno,
266c0 63 6f 6e 73 74 20 75 38 20 2a 29 3b 0a 0a 23 69 const u8 *);..#i
266d0 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
266e0 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 LE_STAT3_OR_STAT
266f0 34 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6e 4.void sqlite3An
26700 61 6c 79 7a 65 46 75 6e 63 74 69 6f 6e 73 28 76 alyzeFunctions(v
26710 6f 69 64 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 oid);.int sqlite
26720 33 53 74 61 74 34 50 72 6f 62 65 53 65 74 56 61 3Stat4ProbeSetVa
26730 6c 75 65 28 50 61 72 73 65 2a 2c 49 6e 64 65 78 lue(Parse*,Index
26740 2a 2c 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 *,UnpackedRecord
26750 2a 2a 2c 45 78 70 72 2a 2c 75 38 2c 69 6e 74 2c **,Expr*,u8,int,
26760 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int*);.int sqlit
26770 65 33 53 74 61 74 34 56 61 6c 75 65 46 72 6f 6d e3Stat4ValueFrom
26780 45 78 70 72 28 50 61 72 73 65 2a 2c 20 45 78 70 Expr(Parse*, Exp
26790 72 2a 2c 20 75 38 2c 20 73 71 6c 69 74 65 33 5f r*, u8, sqlite3_
267a0 76 61 6c 75 65 2a 2a 29 3b 0a 76 6f 69 64 20 73 value**);.void s
267b0 71 6c 69 74 65 33 53 74 61 74 34 50 72 6f 62 65 qlite3Stat4Probe
267c0 46 72 65 65 28 55 6e 70 61 63 6b 65 64 52 65 63 Free(UnpackedRec
267d0 6f 72 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ord*);.int sqlit
267e0 65 33 53 74 61 74 34 43 6f 6c 75 6d 6e 28 73 71 e3Stat4Column(sq
267f0 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 76 6f lite3*, const vo
26800 69 64 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 73 id*, int, int, s
26810 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b qlite3_value**);
26820 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
26830 68 65 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 he interface to
26840 74 68 65 20 4c 45 4d 4f 4e 2d 67 65 6e 65 72 61 the LEMON-genera
26850 74 65 64 20 70 61 72 73 65 72 0a 2a 2f 0a 76 6f ted parser.*/.vo
26860 69 64 20 2a 73 71 6c 69 74 65 33 50 61 72 73 65 id *sqlite3Parse
26870 72 41 6c 6c 6f 63 28 76 6f 69 64 2a 28 2a 29 28 rAlloc(void*(*)(
26880 75 36 34 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 u64));.void sqli
26890 74 65 33 50 61 72 73 65 72 46 72 65 65 28 76 6f te3ParserFree(vo
268a0 69 64 2a 2c 20 76 6f 69 64 28 2a 29 28 76 6f 69 id*, void(*)(voi
268b0 64 2a 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 d*));.void sqlit
268c0 65 33 50 61 72 73 65 72 28 76 6f 69 64 2a 2c 20 e3Parser(void*,
268d0 69 6e 74 2c 20 54 6f 6b 65 6e 2c 20 50 61 72 73 int, Token, Pars
268e0 65 2a 29 3b 0a 23 69 66 64 65 66 20 59 59 54 52 e*);.#ifdef YYTR
268f0 41 43 4b 4d 41 58 53 54 41 43 4b 44 45 50 54 48 ACKMAXSTACKDEPTH
26900 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 . int sqlite3Pa
26910 72 73 65 72 53 74 61 63 6b 50 65 61 6b 28 76 6f rserStackPeak(vo
26920 69 64 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 76 6f id*);.#endif..vo
26930 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 4c 6f id sqlite3AutoLo
26940 61 64 45 78 74 65 6e 73 69 6f 6e 73 28 73 71 6c adExtensions(sql
26950 69 74 65 33 2a 29 3b 0a 23 69 66 6e 64 65 66 20 ite3*);.#ifndef
26960 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 4c 4f 41 44 SQLITE_OMIT_LOAD
26970 5f 45 58 54 45 4e 53 49 4f 4e 0a 20 20 76 6f 69 _EXTENSION. voi
26980 64 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 45 78 d sqlite3CloseEx
26990 74 65 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 33 tensions(sqlite3
269a0 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
269b0 6e 65 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 45 ne sqlite3CloseE
269c0 78 74 65 6e 73 69 6f 6e 73 28 58 29 0a 23 65 6e xtensions(X).#en
269d0 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c dif..#ifndef SQL
269e0 49 54 45 5f 4f 4d 49 54 5f 53 48 41 52 45 44 5f ITE_OMIT_SHARED_
269f0 43 41 43 48 45 0a 20 20 76 6f 69 64 20 73 71 6c CACHE. void sql
26a00 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 50 61 ite3TableLock(Pa
26a10 72 73 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c rse *, int, int,
26a20 20 75 38 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 u8, const char
26a30 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 *);.#else. #def
26a40 69 6e 65 20 73 71 6c 69 74 65 33 54 61 62 6c 65 ine sqlite3Table
26a50 4c 6f 63 6b 28 76 2c 77 2c 78 2c 79 2c 7a 29 0a Lock(v,w,x,y,z).
26a60 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 #endif..#ifdef S
26a70 51 4c 49 54 45 5f 54 45 53 54 0a 20 20 69 6e 74 QLITE_TEST. int
26a80 20 73 71 6c 69 74 65 33 55 74 66 38 54 6f 38 28 sqlite3Utf8To8(
26a90 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 29 3b unsigned char*);
26aa0 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
26ab0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
26ac0 55 41 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 69 UALTABLE.# defi
26ad0 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 43 6c ne sqlite3VtabCl
26ae0 65 61 72 28 59 29 0a 23 20 20 64 65 66 69 6e 65 ear(Y).# define
26af0 20 73 71 6c 69 74 65 33 56 74 61 62 53 79 6e 63 sqlite3VtabSync
26b00 28 58 2c 59 29 20 53 51 4c 49 54 45 5f 4f 4b 0a (X,Y) SQLITE_OK.
26b10 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
26b20 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 58 29 3VtabRollback(X)
26b30 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
26b40 65 33 56 74 61 62 43 6f 6d 6d 69 74 28 58 29 0a e3VtabCommit(X).
26b50 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
26b60 33 56 74 61 62 49 6e 53 79 6e 63 28 64 62 29 20 3VtabInSync(db)
26b70 30 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 0.# define sqli
26b80 74 65 33 56 74 61 62 4c 6f 63 6b 28 58 29 20 0a te3VtabLock(X) .
26b90 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
26ba0 33 56 74 61 62 55 6e 6c 6f 63 6b 28 58 29 0a 23 3VtabUnlock(X).#
26bb0 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
26bc0 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 58 VtabUnlockList(X
26bd0 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 ).# define sqli
26be0 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 6e 74 te3VtabSavepoint
26bf0 28 58 2c 20 59 2c 20 5a 29 20 53 51 4c 49 54 45 (X, Y, Z) SQLITE
26c00 5f 4f 4b 0a 23 20 20 64 65 66 69 6e 65 20 73 71 _OK.# define sq
26c10 6c 69 74 65 33 47 65 74 56 54 61 62 6c 65 28 58 lite3GetVTable(X
26c20 2c 59 29 20 20 28 28 56 54 61 62 6c 65 2a 29 30 ,Y) ((VTable*)0
26c30 29 0a 23 65 6c 73 65 0a 20 20 20 76 6f 69 64 20 ).#else. void
26c40 73 71 6c 69 74 65 33 56 74 61 62 43 6c 65 61 72 sqlite3VtabClear
26c50 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 (sqlite3 *db, Ta
26c60 62 6c 65 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 ble*);. void s
26c70 71 6c 69 74 65 33 56 74 61 62 44 69 73 63 6f 6e qlite3VtabDiscon
26c80 6e 65 63 74 28 73 71 6c 69 74 65 33 20 2a 64 62 nect(sqlite3 *db
26c90 2c 20 54 61 62 6c 65 20 2a 70 29 3b 0a 20 20 20 , Table *p);.
26ca0 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 53 int sqlite3VtabS
26cb0 79 6e 63 28 73 71 6c 69 74 65 33 20 2a 64 62 2c ync(sqlite3 *db,
26cc0 20 56 64 62 65 2a 29 3b 0a 20 20 20 69 6e 74 20 Vdbe*);. int
26cd0 73 71 6c 69 74 65 33 56 74 61 62 52 6f 6c 6c 62 sqlite3VtabRollb
26ce0 61 63 6b 28 73 71 6c 69 74 65 33 20 2a 64 62 29 ack(sqlite3 *db)
26cf0 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ;. int sqlite3
26d00 56 74 61 62 43 6f 6d 6d 69 74 28 73 71 6c 69 74 VtabCommit(sqlit
26d10 65 33 20 2a 64 62 29 3b 0a 20 20 20 76 6f 69 64 e3 *db);. void
26d20 20 73 71 6c 69 74 65 33 56 74 61 62 4c 6f 63 6b sqlite3VtabLock
26d30 28 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 (VTable *);. v
26d40 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 55 oid sqlite3VtabU
26d50 6e 6c 6f 63 6b 28 56 54 61 62 6c 65 20 2a 29 3b nlock(VTable *);
26d60 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
26d70 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 73 VtabUnlockList(s
26d80 71 6c 69 74 65 33 2a 29 3b 0a 20 20 20 69 6e 74 qlite3*);. int
26d90 20 73 71 6c 69 74 65 33 56 74 61 62 53 61 76 65 sqlite3VtabSave
26da0 70 6f 69 6e 74 28 73 71 6c 69 74 65 33 20 2a 2c point(sqlite3 *,
26db0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 20 76 int, int);. v
26dc0 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 49 oid sqlite3VtabI
26dd0 6d 70 6f 72 74 45 72 72 6d 73 67 28 56 64 62 65 mportErrmsg(Vdbe
26de0 2a 2c 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a *, sqlite3_vtab*
26df0 29 3b 0a 20 20 20 56 54 61 62 6c 65 20 2a 73 71 );. VTable *sq
26e00 6c 69 74 65 33 47 65 74 56 54 61 62 6c 65 28 73 lite3GetVTable(s
26e10 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 qlite3*, Table*)
26e20 3b 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 ;.# define sqli
26e30 74 65 33 56 74 61 62 49 6e 53 79 6e 63 28 64 62 te3VtabInSync(db
26e40 29 20 28 28 64 62 29 2d 3e 6e 56 54 72 61 6e 73 ) ((db)->nVTrans
26e50 3e 30 20 26 26 20 28 64 62 29 2d 3e 61 56 54 72 >0 && (db)->aVTr
26e60 61 6e 73 3d 3d 30 29 0a 23 65 6e 64 69 66 0a 76 ans==0).#endif.v
26e70 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 4d oid sqlite3VtabM
26e80 61 6b 65 57 72 69 74 61 62 6c 65 28 50 61 72 73 akeWritable(Pars
26e90 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a 76 6f 69 64 e*,Table*);.void
26ea0 20 73 71 6c 69 74 65 33 56 74 61 62 42 65 67 69 sqlite3VtabBegi
26eb0 6e 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 54 nParse(Parse*, T
26ec0 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 oken*, Token*, T
26ed0 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 oken*, int);.voi
26ee0 64 20 73 71 6c 69 74 65 33 56 74 61 62 46 69 6e d sqlite3VtabFin
26ef0 69 73 68 50 61 72 73 65 28 50 61 72 73 65 2a 2c ishParse(Parse*,
26f00 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
26f10 71 6c 69 74 65 33 56 74 61 62 41 72 67 49 6e 69 qlite3VtabArgIni
26f20 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 t(Parse*);.void
26f30 73 71 6c 69 74 65 33 56 74 61 62 41 72 67 45 78 sqlite3VtabArgEx
26f40 74 65 6e 64 28 50 61 72 73 65 2a 2c 20 54 6f 6b tend(Parse*, Tok
26f50 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 en*);.int sqlite
26f60 33 56 74 61 62 43 61 6c 6c 43 72 65 61 74 65 28 3VtabCallCreate(
26f70 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 sqlite3*, int, c
26f80 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 68 61 onst char *, cha
26f90 72 20 2a 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 r **);.int sqlit
26fa0 65 33 56 74 61 62 43 61 6c 6c 43 6f 6e 6e 65 63 e3VtabCallConnec
26fb0 74 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a t(Parse*, Table*
26fc0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 );.int sqlite3Vt
26fd0 61 62 43 61 6c 6c 44 65 73 74 72 6f 79 28 73 71 abCallDestroy(sq
26fe0 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e lite3*, int, con
26ff0 73 74 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 st char *);.int
27000 73 71 6c 69 74 65 33 56 74 61 62 42 65 67 69 6e sqlite3VtabBegin
27010 28 73 71 6c 69 74 65 33 20 2a 2c 20 56 54 61 62 (sqlite3 *, VTab
27020 6c 65 20 2a 29 3b 0a 46 75 6e 63 44 65 66 20 2a le *);.FuncDef *
27030 73 71 6c 69 74 65 33 56 74 61 62 4f 76 65 72 6c sqlite3VtabOverl
27040 6f 61 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 oadFunction(sqli
27050 74 65 33 20 2a 2c 46 75 6e 63 44 65 66 2a 2c 20 te3 *,FuncDef*,
27060 69 6e 74 20 6e 41 72 67 2c 20 45 78 70 72 2a 29 int nArg, Expr*)
27070 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 6e ;.void sqlite3In
27080 76 61 6c 69 64 46 75 6e 63 74 69 6f 6e 28 73 71 validFunction(sq
27090 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 lite3_context*,i
270a0 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 nt,sqlite3_value
270b0 2a 2a 29 3b 0a 73 71 6c 69 74 65 33 5f 69 6e 74 **);.sqlite3_int
270c0 36 34 20 73 71 6c 69 74 65 33 53 74 6d 74 43 75 64 sqlite3StmtCu
270d0 72 72 65 6e 74 54 69 6d 65 28 73 71 6c 69 74 65 rrentTime(sqlite
270e0 33 5f 63 6f 6e 74 65 78 74 2a 29 3b 0a 69 6e 74 3_context*);.int
270f0 20 73 71 6c 69 74 65 33 56 64 62 65 50 61 72 61 sqlite3VdbePara
27100 6d 65 74 65 72 49 6e 64 65 78 28 56 64 62 65 2a meterIndex(Vdbe*
27110 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 , const char*, i
27120 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
27130 54 72 61 6e 73 66 65 72 42 69 6e 64 69 6e 67 73 TransferBindings
27140 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a 2c (sqlite3_stmt *,
27150 20 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a 29 sqlite3_stmt *)
27160 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 ;.void sqlite3Pa
27170 72 73 65 72 52 65 73 65 74 28 50 61 72 73 65 2a rserReset(Parse*
27180 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 );.int sqlite3Re
27190 70 72 65 70 61 72 65 28 56 64 62 65 2a 29 3b 0a prepare(Vdbe*);.
271a0 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
271b0 4c 69 73 74 43 68 65 63 6b 4c 65 6e 67 74 68 28 ListCheckLength(
271c0 50 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 Parse*, ExprList
271d0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
271e0 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 .CollSeq *sqlite
271f0 33 42 69 6e 61 72 79 43 6f 6d 70 61 72 65 43 6f 3BinaryCompareCo
27200 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 2c 20 45 llSeq(Parse *, E
27210 78 70 72 20 2a 2c 20 45 78 70 72 20 2a 29 3b 0a xpr *, Expr *);.
27220 69 6e 74 20 73 71 6c 69 74 65 33 54 65 6d 70 49 int sqlite3TempI
27230 6e 4d 65 6d 6f 72 79 28 63 6f 6e 73 74 20 73 71 nMemory(const sq
27240 6c 69 74 65 33 2a 29 3b 0a 63 6f 6e 73 74 20 63 lite3*);.const c
27250 68 61 72 20 2a 73 71 6c 69 74 65 33 4a 6f 75 72 har *sqlite3Jour
27260 6e 61 6c 4d 6f 64 65 6e 61 6d 65 28 69 6e 74 29 nalModename(int)
27270 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
27280 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 _OMIT_WAL. int
27290 73 71 6c 69 74 65 33 43 68 65 63 6b 70 6f 69 6e sqlite3Checkpoin
272a0 74 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c t(sqlite3*, int,
272b0 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a int, int*, int*
272c0 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
272d0 57 61 6c 44 65 66 61 75 6c 74 48 6f 6f 6b 28 76 WalDefaultHook(v
272e0 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 6f oid*,sqlite3*,co
272f0 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a nst char*,int);.
27300 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
27310 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 54 45 0a 20 QLITE_OMIT_CTE.
27320 20 57 69 74 68 20 2a 73 71 6c 69 74 65 33 57 69 With *sqlite3Wi
27330 74 68 41 64 64 28 50 61 72 73 65 2a 2c 57 69 74 thAdd(Parse*,Wit
27340 68 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 h*,Token*,ExprLi
27350 73 74 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a 20 20 st*,Select*);.
27360 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 74 68 void sqlite3With
27370 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c Delete(sqlite3*,
27380 57 69 74 68 2a 29 3b 0a 20 20 76 6f 69 64 20 73 With*);. void s
27390 71 6c 69 74 65 33 57 69 74 68 50 75 73 68 28 50 qlite3WithPush(P
273a0 61 72 73 65 2a 2c 20 57 69 74 68 2a 2c 20 75 38 arse*, With*, u8
273b0 29 3b 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 );.#else.#define
273c0 20 73 71 6c 69 74 65 33 57 69 74 68 50 75 73 68 sqlite3WithPush
273d0 28 78 2c 79 2c 7a 29 0a 23 64 65 66 69 6e 65 20 (x,y,z).#define
273e0 73 71 6c 69 74 65 33 57 69 74 68 44 65 6c 65 74 sqlite3WithDelet
273f0 65 28 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a 2f e(x,y).#endif../
27400 2a 20 44 65 63 6c 61 72 61 74 69 6f 6e 73 20 66 * Declarations f
27410 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e 20 or functions in
27420 66 6b 65 79 2e 63 2e 20 41 6c 6c 20 6f 66 20 74 fkey.c. All of t
27430 68 65 73 65 20 61 72 65 20 72 65 70 6c 61 63 65 hese are replace
27440 64 20 62 79 0a 2a 2a 20 6e 6f 2d 6f 70 20 6d 61 d by.** no-op ma
27450 63 72 6f 73 20 69 66 20 4f 4d 49 54 5f 46 4f 52 cros if OMIT_FOR
27460 45 49 47 4e 5f 4b 45 59 20 69 73 20 64 65 66 69 EIGN_KEY is defi
27470 6e 65 64 2e 20 49 6e 20 74 68 69 73 20 63 61 73 ned. In this cas
27480 65 20 6e 6f 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 e no foreign.**
27490 6b 65 79 20 66 75 6e 63 74 69 6f 6e 61 6c 69 74 key functionalit
274a0 79 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2e 20 y is available.
274b0 49 66 20 4f 4d 49 54 5f 54 52 49 47 47 45 52 20 If OMIT_TRIGGER
274c0 69 73 20 64 65 66 69 6e 65 64 20 62 75 74 0a 2a is defined but.*
274d0 2a 20 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b * OMIT_FOREIGN_K
274e0 45 59 20 69 73 20 6e 6f 74 2c 20 6f 6e 6c 79 20 EY is not, only
274f0 73 6f 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 some of the func
27500 74 69 6f 6e 73 20 61 72 65 20 6e 6f 2d 6f 70 65 tions are no-ope
27510 64 2e 20 49 6e 0a 2a 2a 20 74 68 69 73 20 63 61 d. In.** this ca
27520 73 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 se foreign keys
27530 61 72 65 20 70 61 72 73 65 64 2c 20 62 75 74 20 are parsed, but
27540 6e 6f 20 6f 74 68 65 72 20 66 75 6e 63 74 69 6f no other functio
27550 6e 61 6c 69 74 79 20 69 73 20 0a 2a 2a 20 70 72 nality is .** pr
27560 6f 76 69 64 65 64 20 28 65 6e 66 6f 72 63 65 6d ovided (enforcem
27570 65 6e 74 20 6f 66 20 46 4b 20 63 6f 6e 73 74 72 ent of FK constr
27580 61 69 6e 74 73 20 72 65 71 75 69 72 65 73 20 74 aints requires t
27590 68 65 20 74 72 69 67 67 65 72 73 20 73 75 62 2d he triggers sub-
275a0 73 79 73 74 65 6d 29 2e 0a 2a 2f 0a 23 69 66 20 system)..*/.#if
275b0 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
275c0 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 OMIT_FOREIGN_KEY
275d0 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 ) && !defined(SQ
275e0 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 LITE_OMIT_TRIGGE
275f0 52 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 R). void sqlite
27600 33 46 6b 43 68 65 63 6b 28 50 61 72 73 65 2a 2c 3FkCheck(Parse*,
27610 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e Table*, int, in
27620 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 t, int*, int);.
27630 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 44 void sqlite3FkD
27640 72 6f 70 54 61 62 6c 65 28 50 61 72 73 65 2a 2c ropTable(Parse*,
27650 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 61 62 6c SrcList *, Tabl
27660 65 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 e*);. void sqli
27670 74 65 33 46 6b 41 63 74 69 6f 6e 73 28 50 61 72 te3FkActions(Par
27680 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 se*, Table*, Exp
27690 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 rList*, int, int
276a0 2a 2c 20 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 *, int);. int s
276b0 71 6c 69 74 65 33 46 6b 52 65 71 75 69 72 65 64 qlite3FkRequired
276c0 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
276d0 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 75 int*, int);. u
276e0 33 32 20 73 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 32 sqlite3FkOldm
276f0 61 73 6b 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ask(Parse*, Tabl
27700 65 2a 29 3b 0a 20 20 46 4b 65 79 20 2a 73 71 6c e*);. FKey *sql
27710 69 74 65 33 46 6b 52 65 66 65 72 65 6e 63 65 73 ite3FkReferences
27720 28 54 61 62 6c 65 20 2a 29 3b 0a 23 65 6c 73 65 (Table *);.#else
27730 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
27740 65 33 46 6b 41 63 74 69 6f 6e 73 28 61 2c 62 2c e3FkActions(a,b,
27750 63 2c 64 2c 65 2c 66 29 0a 20 20 23 64 65 66 69 c,d,e,f). #defi
27760 6e 65 20 73 71 6c 69 74 65 33 46 6b 43 68 65 63 ne sqlite3FkChec
27770 6b 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 k(a,b,c,d,e,f).
27780 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
27790 46 6b 44 72 6f 70 54 61 62 6c 65 28 61 2c 62 2c FkDropTable(a,b,
277a0 63 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c c). #define sql
277b0 69 74 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 61 2c ite3FkOldmask(a,
277c0 62 29 20 20 20 20 20 20 20 20 20 30 0a 20 20 23 b) 0. #
277d0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
277e0 52 65 71 75 69 72 65 64 28 61 2c 62 2c 63 2c 64 Required(a,b,c,d
277f0 29 20 20 20 20 30 0a 23 65 6e 64 69 66 0a 23 69 ) 0.#endif.#i
27800 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
27810 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 0a 20 20 T_FOREIGN_KEY.
27820 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 44 65 void sqlite3FkDe
27830 6c 65 74 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 lete(sqlite3 *,
27840 54 61 62 6c 65 2a 29 3b 0a 20 20 69 6e 74 20 73 Table*);. int s
27850 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e qlite3FkLocateIn
27860 64 65 78 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 dex(Parse*,Table
27870 2a 2c 46 4b 65 79 2a 2c 49 6e 64 65 78 2a 2a 2c *,FKey*,Index**,
27880 69 6e 74 2a 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 int**);.#else.
27890 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 #define sqlite3F
278a0 6b 44 65 6c 65 74 65 28 61 2c 62 29 0a 20 20 23 kDelete(a,b). #
278b0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
278c0 4c 6f 63 61 74 65 49 6e 64 65 78 28 61 2c 62 2c LocateIndex(a,b,
278d0 63 2c 64 2c 65 29 0a 23 65 6e 64 69 66 0a 0a 0a c,d,e).#endif...
278e0 2f 2a 0a 2a 2a 20 41 76 61 69 6c 61 62 6c 65 20 /*.** Available
278f0 66 61 75 6c 74 20 69 6e 6a 65 63 74 6f 72 73 2e fault injectors.
27900 20 20 53 68 6f 75 6c 64 20 62 65 20 6e 75 6d 62 Should be numb
27910 65 72 65 64 20 62 65 67 69 6e 6e 69 6e 67 20 77 ered beginning w
27920 69 74 68 20 30 2e 0a 2a 2f 0a 23 64 65 66 69 6e ith 0..*/.#defin
27930 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 49 4e e SQLITE_FAULTIN
27940 4a 45 43 54 4f 52 5f 4d 41 4c 4c 4f 43 20 20 20 JECTOR_MALLOC
27950 20 20 30 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 0.#define SQLI
27960 54 45 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 TE_FAULTINJECTOR
27970 5f 43 4f 55 4e 54 20 20 20 20 20 20 31 0a 0a 2f _COUNT 1../
27980 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 66 61 *.** The interfa
27990 63 65 20 74 6f 20 74 68 65 20 63 6f 64 65 20 69 ce to the code i
279a0 6e 20 66 61 75 6c 74 2e 63 20 75 73 65 64 20 66 n fault.c used f
279b0 6f 72 20 69 64 65 6e 74 69 66 79 69 6e 67 20 22 or identifying "
279c0 62 65 6e 69 67 6e 22 0a 2a 2a 20 6d 61 6c 6c 6f benign".** mallo
279d0 63 20 66 61 69 6c 75 72 65 73 2e 20 54 68 69 73 c failures. This
279e0 20 69 73 20 6f 6e 6c 79 20 70 72 65 73 65 6e 74 is only present
279f0 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f if SQLITE_OMIT_
27a00 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 2a 2a 20 BUILTIN_TEST.**
27a10 69 73 20 6e 6f 74 20 64 65 66 69 6e 65 64 2e 0a is not defined..
27a20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
27a30 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 E_OMIT_BUILTIN_T
27a40 45 53 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 EST. void sqlit
27a50 65 33 42 65 67 69 6e 42 65 6e 69 67 6e 4d 61 6c e3BeginBenignMal
27a60 6c 6f 63 28 76 6f 69 64 29 3b 0a 20 20 76 6f 69 loc(void);. voi
27a70 64 20 73 71 6c 69 74 65 33 45 6e 64 42 65 6e 69 d sqlite3EndBeni
27a80 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a gnMalloc(void);.
27a90 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
27aa0 73 71 6c 69 74 65 33 42 65 67 69 6e 42 65 6e 69 sqlite3BeginBeni
27ab0 67 6e 4d 61 6c 6c 6f 63 28 29 0a 20 20 23 64 65 gnMalloc(). #de
27ac0 66 69 6e 65 20 73 71 6c 69 74 65 33 45 6e 64 42 fine sqlite3EndB
27ad0 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a 23 65 enignMalloc().#e
27ae0 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f ndif../*.** Allo
27af0 77 65 64 20 72 65 74 75 72 6e 20 76 61 6c 75 65 wed return value
27b00 73 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 46 69 s from sqlite3Fi
27b10 6e 64 49 6e 49 6e 64 65 78 28 29 0a 2a 2f 0a 23 ndInIndex().*/.#
27b20 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
27b30 52 4f 57 49 44 20 20 20 20 20 20 20 20 31 20 20 ROWID 1
27b40 20 2f 2a 20 53 65 61 72 63 68 20 74 68 65 20 72 /* Search the r
27b50 6f 77 69 64 20 6f 66 20 74 68 65 20 74 61 62 6c owid of the tabl
27b60 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f e */.#define IN_
27b70 49 4e 44 45 58 5f 45 50 48 20 20 20 20 20 20 20 INDEX_EPH
27b80 20 20 20 32 20 20 20 2f 2a 20 53 65 61 72 63 68 2 /* Search
27b90 20 61 6e 20 65 70 68 65 6d 65 72 61 6c 20 62 2d an ephemeral b-
27ba0 74 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tree */.#define
27bb0 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 58 5f 41 IN_INDEX_INDEX_A
27bc0 53 43 20 20 20 20 33 20 20 20 2f 2a 20 45 78 69 SC 3 /* Exi
27bd0 73 74 69 6e 67 20 69 6e 64 65 78 20 41 53 43 45 sting index ASCE
27be0 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 66 69 6e 65 NDING */.#define
27bf0 20 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 58 5f IN_INDEX_INDEX_
27c00 44 45 53 43 20 20 20 34 20 20 20 2f 2a 20 45 78 DESC 4 /* Ex
27c10 69 73 74 69 6e 67 20 69 6e 64 65 78 20 44 45 53 isting index DES
27c20 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 66 69 CENDING */.#defi
27c30 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 ne IN_INDEX_NOOP
27c40 20 20 20 20 20 20 20 20 20 35 20 20 20 2f 2a 20 5 /*
27c50 4e 6f 20 74 61 62 6c 65 20 61 76 61 69 6c 61 62 No table availab
27c60 6c 65 2e 20 55 73 65 20 63 6f 6d 70 61 72 69 73 le. Use comparis
27c70 6f 6e 73 20 2a 2f 0a 2f 2a 0a 2a 2a 20 41 6c 6c ons */./*.** All
27c80 6f 77 65 64 20 66 6c 61 67 73 20 66 6f 72 20 74 owed flags for t
27c90 68 65 20 33 72 64 20 70 61 72 61 6d 65 74 65 72 he 3rd parameter
27ca0 20 74 6f 20 73 71 6c 69 74 65 33 46 69 6e 64 49 to sqlite3FindI
27cb0 6e 49 6e 64 65 78 28 29 2e 0a 2a 2f 0a 23 64 65 nIndex()..*/.#de
27cc0 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f fine IN_INDEX_NO
27cd0 4f 50 5f 4f 4b 20 20 20 20 20 30 78 30 30 30 31 OP_OK 0x0001
27ce0 20 20 2f 2a 20 4f 4b 20 74 6f 20 72 65 74 75 72 /* OK to retur
27cf0 6e 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 20 n IN_INDEX_NOOP
27d00 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
27d10 44 45 58 5f 4d 45 4d 42 45 52 53 48 49 50 20 20 DEX_MEMBERSHIP
27d20 30 78 30 30 30 32 20 20 2f 2a 20 49 4e 20 6f 70 0x0002 /* IN op
27d30 65 72 61 74 6f 72 20 75 73 65 64 20 66 6f 72 20 erator used for
27d40 6d 65 6d 62 65 72 73 68 69 70 20 74 65 73 74 20 membership test
27d50 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
27d60 44 45 58 5f 4c 4f 4f 50 20 20 20 20 20 20 20 20 DEX_LOOP
27d70 30 78 30 30 30 34 20 20 2f 2a 20 49 4e 20 6f 70 0x0004 /* IN op
27d80 65 72 61 74 6f 72 20 75 73 65 64 20 61 73 20 61 erator used as a
27d90 20 6c 6f 6f 70 20 2a 2f 0a 69 6e 74 20 73 71 6c loop */.int sql
27da0 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 ite3FindInIndex(
27db0 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 2a 2c Parse *, Expr *,
27dc0 20 75 33 32 2c 20 69 6e 74 2a 29 3b 0a 0a 23 69 u32, int*);..#i
27dd0 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
27de0 4c 45 5f 41 54 4f 4d 49 43 5f 57 52 49 54 45 0a LE_ATOMIC_WRITE.
27df0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 int sqlite3Jou
27e00 72 6e 61 6c 4f 70 65 6e 28 73 71 6c 69 74 65 33 rnalOpen(sqlite3
27e10 5f 76 66 73 20 2a 2c 20 63 6f 6e 73 74 20 63 68 _vfs *, const ch
27e20 61 72 20 2a 2c 20 73 71 6c 69 74 65 33 5f 66 69 ar *, sqlite3_fi
27e30 6c 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b le *, int, int);
27e40 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f . int sqlite3Jo
27e50 75 72 6e 61 6c 53 69 7a 65 28 73 71 6c 69 74 65 urnalSize(sqlite
27e60 33 5f 76 66 73 20 2a 29 3b 0a 20 20 69 6e 74 20 3_vfs *);. int
27e70 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 43 72 sqlite3JournalCr
27e80 65 61 74 65 28 73 71 6c 69 74 65 33 5f 66 69 6c eate(sqlite3_fil
27e90 65 20 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 e *);. int sqli
27ea0 74 65 33 4a 6f 75 72 6e 61 6c 45 78 69 73 74 73 te3JournalExists
27eb0 28 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a 70 (sqlite3_file *p
27ec0 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 );.#else. #defi
27ed0 6e 65 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 ne sqlite3Journa
27ee0 6c 53 69 7a 65 28 70 56 66 73 29 20 28 28 70 56 lSize(pVfs) ((pV
27ef0 66 73 29 2d 3e 73 7a 4f 73 46 69 6c 65 29 0a 20 fs)->szOsFile).
27f00 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
27f10 4a 6f 75 72 6e 61 6c 45 78 69 73 74 73 28 70 29 JournalExists(p)
27f20 20 31 0a 23 65 6e 64 69 66 0a 0a 76 6f 69 64 20 1.#endif..void
27f30 73 71 6c 69 74 65 33 4d 65 6d 4a 6f 75 72 6e 61 sqlite3MemJourna
27f40 6c 4f 70 65 6e 28 73 71 6c 69 74 65 33 5f 66 69 lOpen(sqlite3_fi
27f50 6c 65 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 le *);.int sqlit
27f60 65 33 4d 65 6d 4a 6f 75 72 6e 61 6c 53 69 7a 65 e3MemJournalSize
27f70 28 76 6f 69 64 29 3b 0a 69 6e 74 20 73 71 6c 69 (void);.int sqli
27f80 74 65 33 49 73 4d 65 6d 4a 6f 75 72 6e 61 6c 28 te3IsMemJournal(
27f90 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b sqlite3_file *);
27fa0 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ..void sqlite3Ex
27fb0 70 72 53 65 74 48 65 69 67 68 74 41 6e 64 46 6c prSetHeightAndFl
27fc0 61 67 73 28 50 61 72 73 65 20 2a 70 50 61 72 73 ags(Parse *pPars
27fd0 65 2c 20 45 78 70 72 20 2a 70 29 3b 0a 23 69 66 e, Expr *p);.#if
27fe0 20 53 51 4c 49 54 45 5f 4d 41 58 5f 45 58 50 52 SQLITE_MAX_EXPR
27ff0 5f 44 45 50 54 48 3e 30 0a 20 20 69 6e 74 20 73 _DEPTH>0. int s
28000 71 6c 69 74 65 33 53 65 6c 65 63 74 45 78 70 72 qlite3SelectExpr
28010 48 65 69 67 68 74 28 53 65 6c 65 63 74 20 2a 29 Height(Select *)
28020 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 45 ;. int sqlite3E
28030 78 70 72 43 68 65 63 6b 48 65 69 67 68 74 28 50 xprCheckHeight(P
28040 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 65 6c arse*, int);.#el
28050 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c se. #define sql
28060 69 74 65 33 53 65 6c 65 63 74 45 78 70 72 48 65 ite3SelectExprHe
28070 69 67 68 74 28 78 29 20 30 0a 20 20 23 64 65 66 ight(x) 0. #def
28080 69 6e 65 20 73 71 6c 69 74 65 33 45 78 70 72 43 ine sqlite3ExprC
28090 68 65 63 6b 48 65 69 67 68 74 28 78 2c 79 29 0a heckHeight(x,y).
280a0 23 65 6e 64 69 66 0a 0a 75 33 32 20 73 71 6c 69 #endif..u32 sqli
280b0 74 65 33 47 65 74 34 62 79 74 65 28 63 6f 6e 73 te3Get4byte(cons
280c0 74 20 75 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c t u8*);.void sql
280d0 69 74 65 33 50 75 74 34 62 79 74 65 28 75 38 2a ite3Put4byte(u8*
280e0 2c 20 75 33 32 29 3b 0a 0a 23 69 66 64 65 66 20 , u32);..#ifdef
280f0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 4e SQLITE_ENABLE_UN
28100 4c 4f 43 4b 5f 4e 4f 54 49 46 59 0a 20 20 76 6f LOCK_NOTIFY. vo
28110 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 id sqlite3Connec
28120 74 69 6f 6e 42 6c 6f 63 6b 65 64 28 73 71 6c 69 tionBlocked(sqli
28130 74 65 33 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a te3 *, sqlite3 *
28140 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
28150 33 43 6f 6e 6e 65 63 74 69 6f 6e 55 6e 6c 6f 63 3ConnectionUnloc
28160 6b 65 64 28 73 71 6c 69 74 65 33 20 2a 64 62 29 ked(sqlite3 *db)
28170 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
28180 43 6f 6e 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 ConnectionClosed
28190 28 73 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 23 (sqlite3 *db);.#
281a0 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 else. #define s
281b0 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
281c0 42 6c 6f 63 6b 65 64 28 78 2c 79 29 0a 20 20 23 Blocked(x,y). #
281d0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f define sqlite3Co
281e0 6e 6e 65 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 nnectionUnlocked
281f0 28 78 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 (x). #define sq
28200 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 43 lite3ConnectionC
28210 6c 6f 73 65 64 28 78 29 0a 23 65 6e 64 69 66 0a losed(x).#endif.
28220 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 .#ifdef SQLITE_D
28230 45 42 55 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 EBUG. void sqli
28240 74 65 33 50 61 72 73 65 72 54 72 61 63 65 28 46 te3ParserTrace(F
28250 49 4c 45 2a 2c 20 63 68 61 72 20 2a 29 3b 0a 23 ILE*, char *);.#
28260 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 endif../*.** If
28270 74 68 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c the SQLITE_ENABL
28280 45 20 49 4f 54 52 41 43 45 20 65 78 69 73 74 73 E IOTRACE exists
28290 20 74 68 65 6e 20 74 68 65 20 67 6c 6f 62 61 6c then the global
282a0 20 76 61 72 69 61 62 6c 65 0a 2a 2a 20 73 71 6c variable.** sql
282b0 69 74 65 33 49 6f 54 72 61 63 65 20 69 73 20 61 ite3IoTrace is a
282c0 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 20 70 72 pointer to a pr
282d0 69 6e 74 66 2d 6c 69 6b 65 20 72 6f 75 74 69 6e intf-like routin
282e0 65 20 75 73 65 64 20 74 6f 0a 2a 2a 20 70 72 69 e used to.** pri
282f0 6e 74 20 49 2f 4f 20 74 72 61 63 69 6e 67 20 6d nt I/O tracing m
28300 65 73 73 61 67 65 73 2e 20 0a 2a 2f 0a 23 69 66 essages. .*/.#if
28310 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c def SQLITE_ENABL
28320 45 5f 49 4f 54 52 41 43 45 0a 23 20 64 65 66 69 E_IOTRACE.# defi
28330 6e 65 20 49 4f 54 52 41 43 45 28 41 29 20 20 69 ne IOTRACE(A) i
28340 66 28 20 73 71 6c 69 74 65 33 49 6f 54 72 61 63 f( sqlite3IoTrac
28350 65 20 29 7b 20 73 71 6c 69 74 65 33 49 6f 54 72 e ){ sqlite3IoTr
28360 61 63 65 20 41 3b 20 7d 0a 20 20 76 6f 69 64 20 ace A; }. void
28370 73 71 6c 69 74 65 33 56 64 62 65 49 4f 54 72 61 sqlite3VdbeIOTra
28380 63 65 53 71 6c 28 56 64 62 65 2a 29 3b 0a 53 51 ceSql(Vdbe*);.SQ
28390 4c 49 54 45 5f 41 50 49 20 53 51 4c 49 54 45 5f LITE_API SQLITE_
283a0 45 58 54 45 52 4e 20 76 6f 69 64 20 28 53 51 4c EXTERN void (SQL
283b0 49 54 45 5f 43 44 45 43 4c 20 2a 73 71 6c 69 74 ITE_CDECL *sqlit
283c0 65 33 49 6f 54 72 61 63 65 29 28 63 6f 6e 73 74 e3IoTrace)(const
283d0 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 23 65 6c char*,...);.#el
283e0 73 65 0a 23 20 64 65 66 69 6e 65 20 49 4f 54 52 se.# define IOTR
283f0 41 43 45 28 41 29 0a 23 20 64 65 66 69 6e 65 20 ACE(A).# define
28400 73 71 6c 69 74 65 33 56 64 62 65 49 4f 54 72 61 sqlite3VdbeIOTra
28410 63 65 53 71 6c 28 58 29 0a 23 65 6e 64 69 66 0a ceSql(X).#endif.
28420 0a 2f 2a 0a 2a 2a 20 54 68 65 73 65 20 72 6f 75 ./*.** These rou
28430 74 69 6e 65 73 20 61 72 65 20 61 76 61 69 6c 61 tines are availa
28440 62 6c 65 20 66 6f 72 20 74 68 65 20 6d 65 6d 32 ble for the mem2
28450 2e 63 20 64 65 62 75 67 67 69 6e 67 20 6d 65 6d .c debugging mem
28460 6f 72 79 20 61 6c 6c 6f 63 61 74 6f 72 0a 2a 2a ory allocator.**
28470 20 6f 6e 6c 79 2e 20 20 54 68 65 79 20 61 72 65 only. They are
28480 20 75 73 65 64 20 74 6f 20 76 65 72 69 66 79 20 used to verify
28490 74 68 61 74 20 64 69 66 66 65 72 65 6e 74 20 22 that different "
284a0 74 79 70 65 73 22 20 6f 66 20 6d 65 6d 6f 72 79 types" of memory
284b0 0a 2a 2a 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 .** allocations
284c0 61 72 65 20 70 72 6f 70 65 72 6c 79 20 74 72 61 are properly tra
284d0 63 6b 65 64 20 62 79 20 74 68 65 20 73 79 73 74 cked by the syst
284e0 65 6d 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 em..**.** sqlite
284f0 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 3MemdebugSetType
28500 28 29 20 73 65 74 73 20 74 68 65 20 22 74 79 70 () sets the "typ
28510 65 22 20 6f 66 20 61 6e 20 61 6c 6c 6f 63 61 74 e" of an allocat
28520 69 6f 6e 20 74 6f 20 6f 6e 65 20 6f 66 0a 2a 2a ion to one of.**
28530 20 74 68 65 20 4d 45 4d 54 59 50 45 5f 2a 20 6d the MEMTYPE_* m
28540 61 63 72 6f 73 20 64 65 66 69 6e 65 64 20 62 65 acros defined be
28550 6c 6f 77 2e 20 20 54 68 65 20 74 79 70 65 20 6d low. The type m
28560 75 73 74 20 62 65 20 61 20 62 69 74 6d 61 73 6b ust be a bitmask
28570 20 77 69 74 68 0a 2a 2a 20 61 20 73 69 6e 67 6c with.** a singl
28580 65 20 62 69 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a e bit set..**.**
28590 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
285a0 48 61 73 54 79 70 65 28 29 20 72 65 74 75 72 6e HasType() return
285b0 73 20 74 72 75 65 20 69 66 20 61 6e 79 20 6f 66 s true if any of
285c0 20 74 68 65 20 62 69 74 73 20 69 6e 20 69 74 73 the bits in its
285d0 20 73 65 63 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d second.** argum
285e0 65 6e 74 20 6d 61 74 63 68 20 74 68 65 20 74 79 ent match the ty
285f0 70 65 20 73 65 74 20 62 79 20 74 68 65 20 70 72 pe set by the pr
28600 65 76 69 6f 75 73 20 73 71 6c 69 74 65 33 4d 65 evious sqlite3Me
28610 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 29 2e mdebugSetType().
28620 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 .** sqlite3Memde
28630 62 75 67 48 61 73 54 79 70 65 28 29 20 69 73 20 bugHasType() is
28640 69 6e 74 65 6e 64 65 64 20 66 6f 72 20 75 73 65 intended for use
28650 20 69 6e 73 69 64 65 20 61 73 73 65 72 74 28 29 inside assert()
28660 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a statements..**.
28670 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ** sqlite3Memdeb
28680 75 67 4e 6f 54 79 70 65 28 29 20 72 65 74 75 72 ugNoType() retur
28690 6e 73 20 74 72 75 65 20 69 66 20 6e 6f 6e 65 20 ns true if none
286a0 6f 66 20 74 68 65 20 62 69 74 73 20 69 6e 20 69 of the bits in i
286b0 74 73 20 73 65 63 6f 6e 64 0a 2a 2a 20 61 72 67 ts second.** arg
286c0 75 6d 65 6e 74 20 6d 61 74 63 68 20 74 68 65 20 ument match the
286d0 74 79 70 65 20 73 65 74 20 62 79 20 74 68 65 20 type set by the
286e0 70 72 65 76 69 6f 75 73 20 73 71 6c 69 74 65 33 previous sqlite3
286f0 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
28700 29 2e 0a 2a 2a 0a 2a 2a 20 50 65 72 68 61 70 73 )..**.** Perhaps
28710 20 74 68 65 20 6d 6f 73 74 20 69 6d 70 6f 72 74 the most import
28720 61 6e 74 20 70 6f 69 6e 74 20 69 73 20 74 68 65 ant point is the
28730 20 64 69 66 66 65 72 65 6e 63 65 20 62 65 74 77 difference betw
28740 65 65 6e 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 een MEMTYPE_HEAP
28750 0a 2a 2a 20 61 6e 64 20 4d 45 4d 54 59 50 45 5f .** and MEMTYPE_
28760 4c 4f 4f 4b 41 53 49 44 45 2e 20 20 49 66 20 61 LOOKASIDE. If a
28770 6e 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 73 20 n allocation is
28780 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 MEMTYPE_LOOKASID
28790 45 2c 20 74 68 61 74 20 6d 65 61 6e 73 0a 2a 2a E, that means.**
287a0 20 69 74 20 6d 69 67 68 74 20 68 61 76 65 20 62 it might have b
287b0 65 65 6e 20 61 6c 6c 6f 63 61 74 65 64 20 62 79 een allocated by
287c0 20 6c 6f 6f 6b 61 73 69 64 65 2c 20 65 78 63 65 lookaside, exce
287d0 70 74 20 74 68 65 20 61 6c 6c 6f 63 61 74 69 6f pt the allocatio
287e0 6e 20 77 61 73 0a 2a 2a 20 74 6f 6f 20 6c 61 72 n was.** too lar
287f0 67 65 20 6f 72 20 6c 6f 6f 6b 61 73 69 64 65 20 ge or lookaside
28800 77 61 73 20 61 6c 72 65 61 64 79 20 66 75 6c 6c was already full
28810 2e 20 20 49 74 20 69 73 20 69 6d 70 6f 72 74 61 . It is importa
28820 6e 74 20 74 6f 20 76 65 72 69 66 79 0a 2a 2a 20 nt to verify.**
28830 74 68 61 74 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 that allocations
28840 20 74 68 61 74 20 6d 69 67 68 74 20 68 61 76 65 that might have
28850 20 62 65 65 6e 20 73 61 74 69 73 66 69 65 64 20 been satisfied
28860 62 79 20 6c 6f 6f 6b 61 73 69 64 65 20 61 72 65 by lookaside are
28870 20 6e 6f 74 0a 2a 2a 20 70 61 73 73 65 64 20 62 not.** passed b
28880 61 63 6b 20 74 6f 20 6e 6f 6e 2d 6c 6f 6f 6b 61 ack to non-looka
28890 73 69 64 65 20 66 72 65 65 28 29 20 72 6f 75 74 side free() rout
288a0 69 6e 65 73 2e 20 20 41 73 73 65 72 74 73 20 73 ines. Asserts s
288b0 75 63 68 20 61 73 20 74 68 65 0a 2a 2a 20 65 78 uch as the.** ex
288c0 61 6d 70 6c 65 20 61 62 6f 76 65 20 61 72 65 20 ample above are
288d0 70 6c 61 63 65 64 20 6f 6e 20 74 68 65 20 6e 6f placed on the no
288e0 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 66 72 65 65 n-lookaside free
288f0 28 29 20 72 6f 75 74 69 6e 65 73 20 74 6f 20 76 () routines to v
28900 65 72 69 66 79 0a 2a 2a 20 74 68 69 73 20 63 6f erify.** this co
28910 6e 73 74 72 61 69 6e 74 2e 20 0a 2a 2a 0a 2a 2a nstraint. .**.**
28920 20 41 6c 6c 20 6f 66 20 74 68 69 73 20 69 73 20 All of this is
28930 6e 6f 2d 6f 70 20 66 6f 72 20 61 20 70 72 6f 64 no-op for a prod
28940 75 63 74 69 6f 6e 20 62 75 69 6c 64 2e 20 20 49 uction build. I
28950 74 20 6f 6e 6c 79 20 63 6f 6d 65 73 20 69 6e 74 t only comes int
28960 6f 0a 2a 2a 20 70 6c 61 79 20 77 68 65 6e 20 74 o.** play when t
28970 68 65 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 he SQLITE_MEMDEB
28980 55 47 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 UG compile-time
28990 6f 70 74 69 6f 6e 20 69 73 20 75 73 65 64 2e 0a option is used..
289a0 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
289b0 5f 4d 45 4d 44 45 42 55 47 0a 20 20 76 6f 69 64 _MEMDEBUG. void
289c0 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
289d0 53 65 74 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 SetType(void*,u8
289e0 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
289f0 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 MemdebugHasType(
28a00 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 void*,u8);. int
28a10 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
28a20 4e 6f 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 29 NoType(void*,u8)
28a30 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
28a40 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
28a50 53 65 74 54 79 70 65 28 58 2c 59 29 20 20 2f 2a SetType(X,Y) /*
28a60 20 6e 6f 2d 6f 70 20 2a 2f 0a 23 20 64 65 66 69 no-op */.# defi
28a70 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ne sqlite3Memdeb
28a80 75 67 48 61 73 54 79 70 65 28 58 2c 59 29 20 20 ugHasType(X,Y)
28a90 31 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 1.# define sqlit
28aa0 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 e3MemdebugNoType
28ab0 28 58 2c 59 29 20 20 20 31 0a 23 65 6e 64 69 66 (X,Y) 1.#endif
28ac0 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 .#define MEMTYPE
28ad0 5f 48 45 41 50 20 20 20 20 20 20 20 30 78 30 31 _HEAP 0x01
28ae0 20 20 2f 2a 20 47 65 6e 65 72 61 6c 20 68 65 61 /* General hea
28af0 70 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f p allocations */
28b00 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 .#define MEMTYPE
28b10 5f 4c 4f 4f 4b 41 53 49 44 45 20 20 30 78 30 32 _LOOKASIDE 0x02
28b20 20 20 2f 2a 20 48 65 61 70 20 74 68 61 74 20 6d /* Heap that m
28b30 69 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 6c ight have been l
28b40 6f 6f 6b 61 73 69 64 65 20 2a 2f 0a 23 64 65 66 ookaside */.#def
28b50 69 6e 65 20 4d 45 4d 54 59 50 45 5f 53 43 52 41 ine MEMTYPE_SCRA
28b60 54 43 48 20 20 20 20 30 78 30 34 20 20 2f 2a 20 TCH 0x04 /*
28b70 53 63 72 61 74 63 68 20 61 6c 6c 6f 63 61 74 69 Scratch allocati
28b80 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d ons */.#define M
28b90 45 4d 54 59 50 45 5f 50 43 41 43 48 45 20 20 20 EMTYPE_PCACHE
28ba0 20 20 30 78 30 38 20 20 2f 2a 20 50 61 67 65 20 0x08 /* Page
28bb0 63 61 63 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e cache allocation
28bc0 73 20 2a 2f 0a 0a 23 69 66 20 28 53 51 4c 49 54 s */..#if (SQLIT
28bd0 45 5f 45 4e 41 42 4c 45 5f 41 50 50 4c 45 5f 53 E_ENABLE_APPLE_S
28be0 50 49 3e 30 29 20 26 26 20 64 65 66 69 6e 65 64 PI>0) && defined
28bf0 28 5f 5f 41 50 50 4c 45 5f 5f 29 0a 0a 2f 2a 0a (__APPLE__)../*.
28c00 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
28c10 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
28c20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 structure is use
28c30 64 20 74 6f 20 68 6f 6c 64 20 74 68 65 20 70 72 d to hold the pr
28c40 6f 63 65 73 73 20 49 44 0a 2a 2a 20 61 6e 64 20 ocess ID.** and
28c50 72 65 74 75 72 6e 2d 62 79 2d 72 65 66 65 72 65 return-by-refere
28c60 6e 63 65 20 6c 6f 63 6b 73 74 61 74 65 20 76 61 nce lockstate va
28c70 6c 75 65 2e 20 20 54 68 65 20 53 51 4c 49 54 45 lue. The SQLITE
28c80 5f 46 43 4e 54 4c 5f 4c 4f 43 4b 53 54 41 54 45 _FCNTL_LOCKSTATE
28c90 5f 50 49 44 0a 2a 2a 20 72 65 71 75 69 72 65 73 _PID.** requires
28ca0 20 74 68 65 20 34 74 68 20 61 72 67 75 6d 65 6e the 4th argumen
28cb0 74 20 74 6f 20 73 71 6c 69 74 65 33 5f 66 69 6c t to sqlite3_fil
28cc0 65 5f 63 6f 6e 74 72 6f 6c 20 74 6f 20 62 65 20 e_control to be
28cd0 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 6e 0a a pointer to an.
28ce0 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 4c ** instance of L
28cf0 6f 63 6b 73 74 61 74 65 50 49 44 20 69 6e 69 74 ockstatePID init
28d00 69 61 6c 69 7a 65 64 20 77 69 74 68 20 61 20 4c ialized with a L
28d10 6f 63 6b 73 74 61 74 65 50 49 44 2e 70 69 64 20 ockstatePID.pid
28d20 76 61 6c 75 65 20 65 71 75 61 6c 0a 2a 2a 20 74 value equal.** t
28d30 6f 20 61 20 70 72 6f 63 65 73 73 20 49 44 20 74 o a process ID t
28d40 6f 20 62 65 20 74 65 73 74 65 64 2c 20 6f 72 20 o be tested, or
28d50 74 68 65 20 73 70 65 63 69 61 6c 20 76 61 6c 75 the special valu
28d60 65 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 e SQLITE_LOCKSTA
28d70 54 45 5f 41 4e 59 50 49 44 0a 2a 2a 20 54 68 65 TE_ANYPID.** The
28d80 20 4c 6f 63 6b 73 74 61 74 65 2e 73 74 61 74 65 Lockstate.state
28d90 20 76 61 6c 75 65 20 69 73 20 61 6c 77 61 79 73 value is always
28da0 20 73 65 74 20 74 6f 20 6f 6e 65 20 6f 66 20 74 set to one of t
28db0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 6c he following val
28dc0 75 65 73 0a 2a 2a 20 77 68 65 6e 20 73 71 6c 69 ues.** when sqli
28dd0 74 65 33 5f 66 69 6c 65 5f 63 6f 6e 74 72 6f 6c te3_file_control
28de0 20 72 65 74 75 72 6e 73 3a 0a 2a 2a 20 0a 2a 2a returns:.** .**
28df0 20 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 SQLITE_LOCKST
28e00 41 54 45 5f 4f 46 46 20 20 20 20 6e 6f 20 61 63 ATE_OFF no ac
28e10 74 69 76 65 20 73 71 6c 69 74 65 20 66 69 6c 65 tive sqlite file
28e20 20 6c 6f 63 6b 73 20 6d 61 74 63 68 20 74 68 65 locks match the
28e30 20 73 70 65 63 69 66 69 65 64 20 70 69 64 0a 2a specified pid.*
28e40 2a 20 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 * SQLITE_LOCKS
28e50 54 41 54 45 5f 4f 4e 20 20 20 20 20 61 63 74 69 TATE_ON acti
28e60 76 65 20 73 71 6c 69 74 65 20 66 69 6c 65 20 6c ve sqlite file l
28e70 6f 63 6b 73 20 6d 61 74 63 68 20 74 68 65 20 73 ocks match the s
28e80 70 65 63 69 66 69 65 64 20 70 69 64 0a 2a 2a 20 pecified pid.**
28e90 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 SQLITE_LOCKSTA
28ea0 54 45 5f 4e 4f 54 41 44 42 20 70 61 74 68 20 70 TE_NOTADB path p
28eb0 6f 69 6e 74 73 20 74 6f 20 61 20 66 69 6c 65 20 oints to a file
28ec0 74 68 61 74 20 69 73 20 6e 6f 74 20 61 6e 20 73 that is not an s
28ed0 71 6c 69 74 65 20 64 62 20 66 69 6c 65 0a 2a 2a qlite db file.**
28ee0 20 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 SQLITE_LOCKST
28ef0 41 54 45 5f 45 52 52 4f 52 20 20 70 61 74 68 20 ATE_ERROR path
28f00 77 61 73 20 6e 6f 74 20 76 61 69 6c 64 20 6f 72 was not vaild or
28f10 20 77 61 73 20 75 6e 72 65 61 64 61 62 6c 65 0a was unreadable.
28f20 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
28f30 74 20 4c 6f 63 6b 73 74 61 74 65 50 49 44 20 4c t LockstatePID L
28f40 6f 63 6b 73 74 61 74 65 50 49 44 3b 0a 73 74 72 ockstatePID;.str
28f50 75 63 74 20 4c 6f 63 6b 73 74 61 74 65 50 49 44 uct LockstatePID
28f60 20 7b 0a 20 20 70 69 64 5f 74 20 70 69 64 3b 20 {. pid_t pid;
28f70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28f80 2f 2a 20 50 72 6f 63 65 73 73 20 49 44 20 74 6f /* Process ID to
28f90 20 74 65 73 74 20 2a 2f 0a 20 20 69 6e 74 20 73 test */. int s
28fa0 74 61 74 65 3b 20 20 20 20 20 20 20 20 20 20 20 tate;
28fb0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 73 74 61 /* The sta
28fc0 74 65 20 6f 66 20 74 68 65 20 6c 6f 63 6b 20 28 te of the lock (
28fd0 72 65 74 75 72 6e 20 76 61 6c 75 65 29 20 2a 2f return value) */
28fe0 0a 7d 3b 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 28 .};..#endif /* (
28ff0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 41 50 SQLITE_ENABLE_AP
29000 50 4c 45 5f 53 50 49 3e 30 29 20 26 26 20 64 65 PLE_SPI>0) && de
29010 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 fined(__APPLE__)
29020 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 72 65 61 */../*.** Threa
29030 64 69 6e 67 20 69 6e 74 65 72 66 61 63 65 0a 2a ding interface.*
29040 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 /.#if SQLITE_MAX
29050 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 3e _WORKER_THREADS>
29060 30 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 68 72 0.int sqlite3Thr
29070 65 61 64 43 72 65 61 74 65 28 53 51 4c 69 74 65 eadCreate(SQLite
29080 54 68 72 65 61 64 2a 2a 2c 76 6f 69 64 2a 28 2a Thread**,void*(*
29090 29 28 76 6f 69 64 2a 29 2c 76 6f 69 64 2a 29 3b )(void*),void*);
290a0 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 68 72 65 .int sqlite3Thre
290b0 61 64 4a 6f 69 6e 28 53 51 4c 69 74 65 54 68 72 adJoin(SQLiteThr
290c0 65 61 64 2a 2c 20 76 6f 69 64 2a 2a 29 3b 0a 23 ead*, void**);.#
290d0 65 6e 64 69 66 0a 0a 23 65 6e 64 69 66 20 2f 2a endif..#endif /*
290e0 20 5f 53 51 4c 49 54 45 49 4e 54 5f 48 5f 20 2a _SQLITEINT_H_ *
290f0 2f 0a /.