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 44 65 63 6c 61 72 61 74 69 6f 6e *.** Declaration
3290: 73 20 75 73 65 64 20 66 6f 72 20 74 72 61 63 69 s used for traci
32a0: 6e 67 20 74 68 65 20 6f 70 65 72 61 74 69 6e 67 ng the operating
32b0: 20 73 79 73 74 65 6d 20 69 6e 74 65 72 66 61 63 system interfac
32c0: 65 73 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e es..*/.#if defin
32d0: 65 64 28 53 51 4c 49 54 45 5f 46 4f 52 43 45 5f ed(SQLITE_FORCE_
32e0: 4f 53 5f 54 52 41 43 45 29 20 7c 7c 20 64 65 66 OS_TRACE) || def
32f0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 ined(SQLITE_TEST
3300: 29 20 7c 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 ) || \. (defi
3310: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
3320: 29 20 26 26 20 53 51 4c 49 54 45 5f 4f 53 5f 57 ) && SQLITE_OS_W
3330: 49 4e 29 0a 20 20 65 78 74 65 72 6e 20 69 6e 74 IN). extern int
3340: 20 73 71 6c 69 74 65 33 4f 53 54 72 61 63 65 3b sqlite3OSTrace;
3350: 0a 23 20 64 65 66 69 6e 65 20 4f 53 54 52 41 43 .# define OSTRAC
3360: 45 28 58 29 20 20 20 20 20 20 20 20 20 20 69 66 E(X) if
3370: 28 20 73 71 6c 69 74 65 33 4f 53 54 72 61 63 65 ( sqlite3OSTrace
3380: 20 29 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 ) sqlite3DebugP
3390: 72 69 6e 74 66 20 58 0a 23 20 64 65 66 69 6e 65 rintf X.# define
33a0: 20 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f SQLITE_HAVE_OS_
33b0: 54 52 41 43 45 0a 23 65 6c 73 65 0a 23 20 64 65 TRACE.#else.# de
33c0: 66 69 6e 65 20 4f 53 54 52 41 43 45 28 58 29 0a fine OSTRACE(X).
33d0: 23 20 75 6e 64 65 66 20 20 53 51 4c 49 54 45 5f # undef SQLITE_
33e0: 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 0a 23 65 HAVE_OS_TRACE.#e
33f0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 73 20 74 ndif../*.** Is t
3400: 68 65 20 73 71 6c 69 74 65 33 45 72 72 4e 61 6d he sqlite3ErrNam
3410: 65 28 29 20 66 75 6e 63 74 69 6f 6e 20 6e 65 65 e() function nee
3420: 64 65 64 20 69 6e 20 74 68 65 20 62 75 69 6c 64 ded in the build
3430: 3f 20 20 43 75 72 72 65 6e 74 6c 79 2c 0a 2a 2a ? Currently,.**
3440: 20 69 74 20 69 73 20 6e 65 65 64 65 64 20 62 79 it is needed by
3450: 20 22 6d 75 74 65 78 5f 77 33 32 2e 63 22 20 28 "mutex_w32.c" (
3460: 77 68 65 6e 20 64 65 62 75 67 67 69 6e 67 29 2c when debugging),
3470: 20 22 6f 73 5f 77 69 6e 2e 63 22 20 28 77 68 65 "os_win.c" (whe
3480: 6e 0a 2a 2a 20 4f 53 54 52 41 43 45 20 69 73 20 n.** OSTRACE is
3490: 65 6e 61 62 6c 65 64 29 2c 20 61 6e 64 20 62 79 enabled), and by
34a0: 20 73 65 76 65 72 61 6c 20 22 74 65 73 74 2a 2e several "test*.
34b0: 63 22 20 66 69 6c 65 73 20 28 77 68 69 63 68 20 c" files (which
34c0: 61 72 65 0a 2a 2a 20 63 6f 6d 70 69 6c 65 64 20 are.** compiled
34d0: 75 73 69 6e 67 20 53 51 4c 49 54 45 5f 54 45 53 using SQLITE_TES
34e0: 54 29 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e T)..*/.#if defin
34f0: 65 64 28 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f ed(SQLITE_HAVE_O
3500: 53 5f 54 52 41 43 45 29 20 7c 7c 20 64 65 66 69 S_TRACE) || defi
3510: 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 ned(SQLITE_TEST)
3520: 20 7c 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 6e || \. (defin
3530: 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 ed(SQLITE_DEBUG)
3540: 20 26 26 20 53 51 4c 49 54 45 5f 4f 53 5f 57 49 && SQLITE_OS_WI
3550: 4e 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 N).# define SQLI
3560: 54 45 5f 4e 45 45 44 5f 45 52 52 5f 4e 41 4d 45 TE_NEED_ERR_NAME
3570: 0a 23 65 6c 73 65 0a 23 20 75 6e 64 65 66 20 20 .#else.# undef
3580: 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 52 5f SQLITE_NEED_ERR_
3590: 4e 41 4d 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a NAME.#endif../*.
35a0: 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 28 ** Return true (
35b0: 6e 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 74 68 65 non-zero) if the
35c0: 20 69 6e 70 75 74 20 69 73 20 61 6e 20 69 6e 74 input is an int
35d0: 65 67 65 72 20 74 68 61 74 20 69 73 20 74 6f 6f eger that is too
35e0: 20 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 66 69 74 large.** to fit
35f0: 20 69 6e 20 33 32 2d 62 69 74 73 2e 20 20 54 68 in 32-bits. Th
3600: 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 is macro is used
3610: 20 69 6e 73 69 64 65 20 6f 66 20 76 61 72 69 6f inside of vario
3620: 75 73 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a us testcase().**
3630: 20 6d 61 63 72 6f 73 20 74 6f 20 76 65 72 69 66 macros to verif
3640: 79 20 74 68 61 74 20 77 65 20 68 61 76 65 20 74 y that we have t
3650: 65 73 74 65 64 20 53 51 4c 69 74 65 20 66 6f 72 ested SQLite for
3660: 20 6c 61 72 67 65 2d 66 69 6c 65 20 73 75 70 70 large-file supp
3670: 6f 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ort..*/.#define
3680: 49 53 5f 42 49 47 5f 49 4e 54 28 58 29 20 20 28 IS_BIG_INT(X) (
3690: 28 28 58 29 26 7e 28 69 36 34 29 30 78 66 66 66 ((X)&~(i64)0xfff
36a0: 66 66 66 66 66 29 21 3d 30 29 0a 0a 2f 2a 0a 2a fffff)!=0)../*.*
36b0: 2a 20 54 68 65 20 6d 61 63 72 6f 20 75 6e 6c 69 * The macro unli
36c0: 6b 65 6c 79 28 29 20 69 73 20 61 20 68 69 6e 74 kely() is a hint
36d0: 20 74 68 61 74 20 73 75 72 72 6f 75 6e 64 73 20 that surrounds
36e0: 61 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 65 78 70 a boolean.** exp
36f0: 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 20 ression that is
3700: 75 73 75 61 6c 6c 79 20 66 61 6c 73 65 2e 20 20 usually false.
3710: 4d 61 63 72 6f 20 6c 69 6b 65 6c 79 28 29 20 73 Macro likely() s
3720: 75 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 20 62 6f urrounds.** a bo
3730: 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 69 6f 6e olean expression
3740: 20 74 68 61 74 20 69 73 20 75 73 75 61 6c 6c 79 that is usually
3750: 20 74 72 75 65 2e 20 20 54 68 65 73 65 20 68 69 true. These hi
3760: 6e 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a 20 69 6e nts could,.** in
3770: 20 74 68 65 6f 72 79 2c 20 62 65 20 75 73 65 64 theory, be used
3780: 20 62 79 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 by the compiler
3790: 20 74 6f 20 67 65 6e 65 72 61 74 65 20 62 65 74 to generate bet
37a0: 74 65 72 20 63 6f 64 65 2c 20 62 75 74 0a 2a 2a ter code, but.**
37b0: 20 63 75 72 72 65 6e 74 6c 79 20 74 68 65 79 20 currently they
37c0: 61 72 65 20 6a 75 73 74 20 63 6f 6d 6d 65 6e 74 are just comment
37d0: 73 20 66 6f 72 20 68 75 6d 61 6e 20 72 65 61 64 s for human read
37e0: 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ers..*/.#define
37f0: 6c 69 6b 65 6c 79 28 58 29 20 20 20 20 28 58 29 likely(X) (X)
3800: 0a 23 64 65 66 69 6e 65 20 75 6e 6c 69 6b 65 6c .#define unlikel
3810: 79 28 58 29 20 20 28 58 29 0a 0a 23 69 6e 63 6c y(X) (X)..#incl
3820: 75 64 65 20 22 68 61 73 68 2e 68 22 0a 23 69 6e ude "hash.h".#in
3830: 63 6c 75 64 65 20 22 70 61 72 73 65 2e 68 22 0a clude "parse.h".
3840: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e #include <stdio.
3850: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 h>.#include <std
3860: 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 lib.h>.#include
3870: 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c <string.h>.#incl
3880: 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 23 ude <assert.h>.#
3890: 69 6e 63 6c 75 64 65 20 3c 73 74 64 64 65 66 2e include <stddef.
38a0: 68 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 63 6f 6d h>../*.** If com
38b0: 70 69 6c 69 6e 67 20 66 6f 72 20 61 20 70 72 6f piling for a pro
38c0: 63 65 73 73 6f 72 20 74 68 61 74 20 6c 61 63 6b cessor that lack
38d0: 73 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e 74 s floating point
38e0: 20 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 73 75 62 support,.** sub
38f0: 73 74 69 74 75 74 65 20 69 6e 74 65 67 65 72 20 stitute integer
3900: 66 6f 72 20 66 6c 6f 61 74 69 6e 67 2d 70 6f 69 for floating-poi
3910: 6e 74 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c nt.*/.#ifdef SQL
3920: 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 4e ITE_OMIT_FLOATIN
3930: 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 6e 65 G_POINT.# define
3940: 20 64 6f 75 62 6c 65 20 73 71 6c 69 74 65 5f 69 double sqlite_i
3950: 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 20 66 6c nt64.# define fl
3960: 6f 61 74 20 73 71 6c 69 74 65 5f 69 6e 74 36 34 oat sqlite_int64
3970: 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e 47 44 4f .# define LONGDO
3980: 55 42 4c 45 5f 54 59 50 45 20 73 71 6c 69 74 65 UBLE_TYPE sqlite
3990: 5f 69 6e 74 36 34 0a 23 20 69 66 6e 64 65 66 20 _int64.# ifndef
39a0: 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 SQLITE_BIG_DBL.#
39b0: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
39c0: 5f 42 49 47 5f 44 42 4c 20 28 28 28 73 71 6c 69 _BIG_DBL (((sqli
39d0: 74 65 33 5f 69 6e 74 36 34 29 31 29 3c 3c 35 30 te3_int64)1)<<50
39e0: 29 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 66 69 ).# endif.# defi
39f0: 6e 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 44 ne SQLITE_OMIT_D
3a00: 41 54 45 54 49 4d 45 5f 46 55 4e 43 53 20 31 0a ATETIME_FUNCS 1.
3a10: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
3a20: 4f 4d 49 54 5f 54 52 41 43 45 20 31 0a 23 20 75 OMIT_TRACE 1.# u
3a30: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 49 58 45 ndef SQLITE_MIXE
3a40: 44 5f 45 4e 44 49 41 4e 5f 36 34 42 49 54 5f 46 D_ENDIAN_64BIT_F
3a50: 4c 4f 41 54 0a 23 20 75 6e 64 65 66 20 53 51 4c LOAT.# undef SQL
3a60: 49 54 45 5f 48 41 56 45 5f 49 53 4e 41 4e 0a 23 ITE_HAVE_ISNAN.#
3a70: 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 endif.#ifndef SQ
3a80: 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 20 64 LITE_BIG_DBL.# d
3a90: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 efine SQLITE_BIG
3aa0: 5f 44 42 4c 20 28 31 65 39 39 29 0a 23 65 6e 64 _DBL (1e99).#end
3ab0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 54 5f 54 if../*.** OMIT_T
3ac0: 45 4d 50 44 42 20 69 73 20 73 65 74 20 74 6f 20 EMPDB is set to
3ad0: 31 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 1 if SQLITE_OMIT
3ae0: 5f 54 45 4d 50 44 42 20 69 73 20 64 65 66 69 6e _TEMPDB is defin
3af0: 65 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 66 74 65 ed, or 0.** afte
3b00: 72 77 61 72 64 2e 20 48 61 76 69 6e 67 20 74 68 rward. Having th
3b10: 69 73 20 6d 61 63 72 6f 20 61 6c 6c 6f 77 73 20 is macro allows
3b20: 75 73 20 74 6f 20 63 61 75 73 65 20 74 68 65 20 us to cause the
3b30: 43 20 63 6f 6d 70 69 6c 65 72 20 0a 2a 2a 20 74 C compiler .** t
3b40: 6f 20 6f 6d 69 74 20 63 6f 64 65 20 75 73 65 64 o omit code used
3b50: 20 62 79 20 54 45 4d 50 20 74 61 62 6c 65 73 20 by TEMP tables
3b60: 77 69 74 68 6f 75 74 20 6d 65 73 73 79 20 23 69 without messy #i
3b70: 66 6e 64 65 66 20 73 74 61 74 65 6d 65 6e 74 73 fndef statements
3b80: 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
3b90: 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 0a 23 TE_OMIT_TEMPDB.#
3ba0: 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 define OMIT_TEMP
3bb0: 44 42 20 31 0a 23 65 6c 73 65 0a 23 64 65 66 69 DB 1.#else.#defi
3bc0: 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 42 20 30 ne OMIT_TEMPDB 0
3bd0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
3be0: 68 65 20 22 66 69 6c 65 20 66 6f 72 6d 61 74 22 he "file format"
3bf0: 20 6e 75 6d 62 65 72 20 69 73 20 61 6e 20 69 6e number is an in
3c00: 74 65 67 65 72 20 74 68 61 74 20 69 73 20 69 6e teger that is in
3c10: 63 72 65 6d 65 6e 74 65 64 20 77 68 65 6e 65 76 cremented whenev
3c20: 65 72 0a 2a 2a 20 74 68 65 20 56 44 42 45 2d 6c er.** the VDBE-l
3c30: 65 76 65 6c 20 66 69 6c 65 20 66 6f 72 6d 61 74 evel file format
3c40: 20 63 68 61 6e 67 65 73 2e 20 20 54 68 65 20 66 changes. The f
3c50: 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 ollowing macros
3c60: 64 65 66 69 6e 65 20 74 68 65 0a 2a 2a 20 74 68 define the.** th
3c70: 65 20 64 65 66 61 75 6c 74 20 66 69 6c 65 20 66 e default file f
3c80: 6f 72 6d 61 74 20 66 6f 72 20 6e 65 77 20 64 61 ormat for new da
3c90: 74 61 62 61 73 65 73 20 61 6e 64 20 74 68 65 20 tabases and the
3ca0: 6d 61 78 69 6d 75 6d 20 66 69 6c 65 20 66 6f 72 maximum file for
3cb0: 6d 61 74 0a 2a 2a 20 74 68 61 74 20 74 68 65 20 mat.** that the
3cc0: 6c 69 62 72 61 72 79 20 63 61 6e 20 72 65 61 64 library can read
3cd0: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
3ce0: 49 54 45 5f 4d 41 58 5f 46 49 4c 45 5f 46 4f 52 ITE_MAX_FILE_FOR
3cf0: 4d 41 54 20 34 0a 23 69 66 6e 64 65 66 20 53 51 MAT 4.#ifndef SQ
3d00: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 46 49 4c LITE_DEFAULT_FIL
3d10: 45 5f 46 4f 52 4d 41 54 0a 23 20 64 65 66 69 6e E_FORMAT.# defin
3d20: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
3d30: 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 20 34 0a 23 _FILE_FORMAT 4.#
3d40: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 endif../*.** Det
3d50: 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 74 ermine whether t
3d60: 72 69 67 67 65 72 73 20 61 72 65 20 72 65 63 75 riggers are recu
3d70: 72 73 69 76 65 20 62 79 20 64 65 66 61 75 6c 74 rsive by default
3d80: 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 0a 2a . This can be.*
3d90: 2a 20 63 68 61 6e 67 65 64 20 61 74 20 72 75 6e * changed at run
3da0: 2d 74 69 6d 65 20 75 73 69 6e 67 20 61 20 70 72 -time using a pr
3db0: 61 67 6d 61 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 agma..*/.#ifndef
3dc0: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
3dd0: 52 45 43 55 52 53 49 56 45 5f 54 52 49 47 47 45 RECURSIVE_TRIGGE
3de0: 52 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 RS.# define SQLI
3df0: 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 43 55 52 TE_DEFAULT_RECUR
3e00: 53 49 56 45 5f 54 52 49 47 47 45 52 53 20 30 0a SIVE_TRIGGERS 0.
3e10: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 72 #endif../*.** Pr
3e20: 6f 76 69 64 65 20 61 20 64 65 66 61 75 6c 74 20 ovide a default
3e30: 76 61 6c 75 65 20 66 6f 72 20 53 51 4c 49 54 45 value for SQLITE
3e40: 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 6e 20 63 _TEMP_STORE in c
3e50: 61 73 65 20 69 74 20 69 73 20 6e 6f 74 20 73 70 ase it is not sp
3e60: 65 63 69 66 69 65 64 0a 2a 2a 20 6f 6e 20 74 68 ecified.** on th
3e70: 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 0a 2a e command-line.*
3e80: 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
3e90: 5f 54 45 4d 50 5f 53 54 4f 52 45 0a 23 20 64 65 _TEMP_STORE.# de
3ea0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 fine SQLITE_TEMP
3eb0: 5f 53 54 4f 52 45 20 31 0a 23 20 64 65 66 69 6e _STORE 1.# defin
3ec0: 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 e SQLITE_TEMP_ST
3ed0: 4f 52 45 5f 78 63 20 31 20 20 2f 2a 20 45 78 63 ORE_xc 1 /* Exc
3ee0: 6c 75 64 65 20 66 72 6f 6d 20 63 74 69 6d 65 2e lude from ctime.
3ef0: 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a c */.#endif../*.
3f00: 2a 2a 20 49 66 20 6e 6f 20 76 61 6c 75 65 20 68 ** If no value h
3f10: 61 73 20 62 65 65 6e 20 70 72 6f 76 69 64 65 64 as been provided
3f20: 20 66 6f 72 20 53 51 4c 49 54 45 5f 4d 41 58 5f for SQLITE_MAX_
3f30: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 2c 20 WORKER_THREADS,
3f40: 6f 72 20 69 66 0a 2a 2a 20 53 51 4c 49 54 45 5f or if.** SQLITE_
3f50: 54 45 4d 50 5f 53 54 4f 52 45 20 69 73 20 73 65 TEMP_STORE is se
3f60: 74 20 74 6f 20 33 20 28 6e 65 76 65 72 20 75 73 t to 3 (never us
3f70: 65 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 e temporary file
3f80: 73 29 2c 20 73 65 74 20 69 74 20 0a 2a 2a 20 74 s), set it .** t
3f90: 6f 20 7a 65 72 6f 2e 0a 2a 2f 0a 23 69 66 20 53 o zero..*/.#if S
3fa0: 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 QLITE_TEMP_STORE
3fb0: 3d 3d 33 20 7c 7c 20 53 51 4c 49 54 45 5f 54 48 ==3 || SQLITE_TH
3fc0: 52 45 41 44 53 41 46 45 3d 3d 30 0a 23 20 75 6e READSAFE==0.# un
3fd0: 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 def SQLITE_MAX_W
3fe0: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
3ff0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
4000: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
4010: 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 0.#endif.#ifnde
4020: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 f SQLITE_MAX_WOR
4030: 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 KER_THREADS.# de
4040: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
4050: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 20 38 WORKER_THREADS 8
4060: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
4070: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 SQLITE_DEFAULT_W
4080: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
4090: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 define SQLITE_DE
40a0: 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 FAULT_WORKER_THR
40b0: 45 41 44 53 20 30 0a 23 65 6e 64 69 66 0a 23 69 EADS 0.#endif.#i
40c0: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
40d0: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 3e _WORKER_THREADS>
40e0: 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 SQLITE_MAX_WORKE
40f0: 52 5f 54 48 52 45 41 44 53 0a 23 20 75 6e 64 65 R_THREADS.# unde
4100: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 f SQLITE_MAX_WOR
4110: 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 KER_THREADS.# de
4120: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
4130: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 20 53 WORKER_THREADS S
4140: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f QLITE_DEFAULT_WO
4150: 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 65 6e RKER_THREADS.#en
4160: 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 47 43 43 20 dif.../*.** GCC
4170: 64 6f 65 73 20 6e 6f 74 20 64 65 66 69 6e 65 20 does not define
4180: 74 68 65 20 6f 66 66 73 65 74 6f 66 28 29 20 6d the offsetof() m
4190: 61 63 72 6f 20 73 6f 20 77 65 27 6c 6c 20 68 61 acro so we'll ha
41a0: 76 65 20 74 6f 20 64 6f 20 69 74 0a 2a 2a 20 6f ve to do it.** o
41b0: 75 72 73 65 6c 76 65 73 2e 0a 2a 2f 0a 23 69 66 urselves..*/.#if
41c0: 6e 64 65 66 20 6f 66 66 73 65 74 6f 66 0a 23 64 ndef offsetof.#d
41d0: 65 66 69 6e 65 20 6f 66 66 73 65 74 6f 66 28 53 efine offsetof(S
41e0: 54 52 55 43 54 55 52 45 2c 46 49 45 4c 44 29 20 TRUCTURE,FIELD)
41f0: 28 28 69 6e 74 29 28 28 63 68 61 72 2a 29 26 28 ((int)((char*)&(
4200: 28 53 54 52 55 43 54 55 52 45 2a 29 30 29 2d 3e (STRUCTURE*)0)->
4210: 46 49 45 4c 44 29 29 0a 23 65 6e 64 69 66 0a 0a FIELD)).#endif..
4220: 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 /*.** Macros to
4230: 63 6f 6d 70 75 74 65 20 6d 69 6e 69 6d 75 6d 20 compute minimum
4240: 61 6e 64 20 6d 61 78 69 6d 75 6d 20 6f 66 20 74 and maximum of t
4250: 77 6f 20 6e 75 6d 62 65 72 73 2e 0a 2a 2f 0a 23 wo numbers..*/.#
4260: 64 65 66 69 6e 65 20 4d 49 4e 28 41 2c 42 29 20 define MIN(A,B)
4270: 28 28 41 29 3c 28 42 29 3f 28 41 29 3a 28 42 29 ((A)<(B)?(A):(B)
4280: 29 0a 23 64 65 66 69 6e 65 20 4d 41 58 28 41 2c ).#define MAX(A,
4290: 42 29 20 28 28 41 29 3e 28 42 29 3f 28 41 29 3a B) ((A)>(B)?(A):
42a0: 28 42 29 29 0a 0a 2f 2a 0a 2a 2a 20 53 77 61 70 (B))../*.** Swap
42b0: 20 74 77 6f 20 6f 62 6a 65 63 74 73 20 6f 66 20 two objects of
42c0: 74 79 70 65 20 54 59 50 45 2e 0a 2a 2f 0a 23 64 type TYPE..*/.#d
42d0: 65 66 69 6e 65 20 53 57 41 50 28 54 59 50 45 2c efine SWAP(TYPE,
42e0: 41 2c 42 29 20 7b 54 59 50 45 20 74 3d 41 3b 20 A,B) {TYPE t=A;
42f0: 41 3d 42 3b 20 42 3d 74 3b 7d 0a 0a 2f 2a 0a 2a A=B; B=t;}../*.*
4300: 2a 20 43 68 65 63 6b 20 74 6f 20 73 65 65 20 69 * Check to see i
4310: 66 20 74 68 69 73 20 6d 61 63 68 69 6e 65 20 75 f this machine u
4320: 73 65 73 20 45 42 43 44 49 43 2e 20 20 28 59 65 ses EBCDIC. (Ye
4330: 73 2c 20 62 65 6c 69 65 76 65 20 69 74 20 6f 72 s, believe it or
4340: 0a 2a 2a 20 6e 6f 74 2c 20 74 68 65 72 65 20 61 .** not, there a
4350: 72 65 20 73 74 69 6c 6c 20 6d 61 63 68 69 6e 65 re still machine
4360: 73 20 6f 75 74 20 74 68 65 72 65 20 74 68 61 74 s out there that
4370: 20 75 73 65 20 45 42 43 44 49 43 2e 29 0a 2a 2f use EBCDIC.).*/
4380: 0a 23 69 66 20 27 41 27 20 3d 3d 20 27 5c 33 30 .#if 'A' == '\30
4390: 31 27 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1'.# define SQLI
43a0: 54 45 5f 45 42 43 44 49 43 20 31 0a 23 65 6c 73 TE_EBCDIC 1.#els
43b0: 65 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 e.# define SQLIT
43c0: 45 5f 41 53 43 49 49 20 31 0a 23 65 6e 64 69 66 E_ASCII 1.#endif
43d0: 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 67 65 72 73 ../*.** Integers
43e0: 20 6f 66 20 6b 6e 6f 77 6e 20 73 69 7a 65 73 2e of known sizes.
43f0: 20 20 54 68 65 73 65 20 74 79 70 65 64 65 66 73 These typedefs
4400: 20 6d 69 67 68 74 20 63 68 61 6e 67 65 20 66 6f might change fo
4410: 72 20 61 72 63 68 69 74 65 63 74 75 72 65 73 0a r architectures.
4420: 2a 2a 20 77 68 65 72 65 20 74 68 65 20 73 69 7a ** where the siz
4430: 65 73 20 76 65 72 79 2e 20 20 50 72 65 70 72 6f es very. Prepro
4440: 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 20 61 72 cessor macros ar
4450: 65 20 61 76 61 69 6c 61 62 6c 65 20 73 6f 20 74 e available so t
4460: 68 61 74 20 74 68 65 0a 2a 2a 20 74 79 70 65 73 hat the.** types
4470: 20 63 61 6e 20 62 65 20 63 6f 6e 76 65 6e 69 65 can be convenie
4480: 6e 74 6c 79 20 72 65 64 65 66 69 6e 65 64 20 61 ntly redefined a
4490: 74 20 63 6f 6d 70 69 6c 65 2d 74 79 70 65 2e 20 t compile-type.
44a0: 20 4c 69 6b 65 20 74 68 69 73 3a 0a 2a 2a 0a 2a Like this:.**.*
44b0: 2a 20 20 20 20 20 20 20 20 20 63 63 20 27 2d 44 * cc '-D
44c0: 55 49 4e 54 50 54 52 5f 54 59 50 45 3d 6c 6f 6e UINTPTR_TYPE=lon
44d0: 67 20 6c 6f 6e 67 20 69 6e 74 27 20 2e 2e 2e 0a g long int' ....
44e0: 2a 2f 0a 23 69 66 6e 64 65 66 20 55 49 4e 54 33 */.#ifndef UINT3
44f0: 32 5f 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 2_TYPE.# ifdef H
4500: 41 56 45 5f 55 49 4e 54 33 32 5f 54 0a 23 20 20 AVE_UINT32_T.#
4510: 64 65 66 69 6e 65 20 55 49 4e 54 33 32 5f 54 59 define UINT32_TY
4520: 50 45 20 75 69 6e 74 33 32 5f 74 0a 23 20 65 6c PE uint32_t.# el
4530: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e se.# define UIN
4540: 54 33 32 5f 54 59 50 45 20 75 6e 73 69 67 6e 65 T32_TYPE unsigne
4550: 64 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a 23 65 d int.# endif.#e
4560: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 49 4e ndif.#ifndef UIN
4570: 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 65 66 T16_TYPE.# ifdef
4580: 20 48 41 56 45 5f 55 49 4e 54 31 36 5f 54 0a 23 HAVE_UINT16_T.#
4590: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 31 36 5f define UINT16_
45a0: 54 59 50 45 20 75 69 6e 74 31 36 5f 74 0a 23 20 TYPE uint16_t.#
45b0: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
45c0: 49 4e 54 31 36 5f 54 59 50 45 20 75 6e 73 69 67 INT16_TYPE unsig
45d0: 6e 65 64 20 73 68 6f 72 74 20 69 6e 74 0a 23 20 ned short int.#
45e0: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 endif.#endif.#if
45f0: 6e 64 65 66 20 49 4e 54 31 36 5f 54 59 50 45 0a ndef INT16_TYPE.
4600: 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 4e 54 # ifdef HAVE_INT
4610: 31 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 49 16_T.# define I
4620: 4e 54 31 36 5f 54 59 50 45 20 69 6e 74 31 36 5f NT16_TYPE int16_
4630: 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 t.# else.# defi
4640: 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 73 68 ne INT16_TYPE sh
4650: 6f 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a ort int.# endif.
4660: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 #endif.#ifndef U
4670: 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 64 65 INT8_TYPE.# ifde
4680: 66 20 48 41 56 45 5f 55 49 4e 54 38 5f 54 0a 23 f HAVE_UINT8_T.#
4690: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 38 5f 54 define UINT8_T
46a0: 59 50 45 20 75 69 6e 74 38 5f 74 0a 23 20 65 6c YPE uint8_t.# el
46b0: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e se.# define UIN
46c0: 54 38 5f 54 59 50 45 20 75 6e 73 69 67 6e 65 64 T8_TYPE unsigned
46d0: 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a 23 65 char.# endif.#e
46e0: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 4e 54 ndif.#ifndef INT
46f0: 38 5f 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 8_TYPE.# ifdef H
4700: 41 56 45 5f 49 4e 54 38 5f 54 0a 23 20 20 64 65 AVE_INT8_T.# de
4710: 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 20 69 fine INT8_TYPE i
4720: 6e 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 nt8_t.# else.#
4730: 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 define INT8_TYPE
4740: 20 73 69 67 6e 65 64 20 63 68 61 72 0a 23 20 65 signed char.# e
4750: 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e ndif.#endif.#ifn
4760: 64 65 66 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 def LONGDOUBLE_T
4770: 59 50 45 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e YPE.# define LON
4780: 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 6c 6f 6e GDOUBLE_TYPE lon
4790: 67 20 64 6f 75 62 6c 65 0a 23 65 6e 64 69 66 0a g double.#endif.
47a0: 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f 69 typedef sqlite_i
47b0: 6e 74 36 34 20 69 36 34 3b 20 20 20 20 20 20 20 nt64 i64;
47c0: 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 73 69 67 /* 8-byte sig
47d0: 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f 0a 74 ned integer */.t
47e0: 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f 75 69 ypedef sqlite_ui
47f0: 6e 74 36 34 20 75 36 34 3b 20 20 20 20 20 20 20 nt64 u64;
4800: 20 20 2f 2a 20 38 2d 62 79 74 65 20 75 6e 73 69 /* 8-byte unsi
4810: 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f 0a gned integer */.
4820: 74 79 70 65 64 65 66 20 55 49 4e 54 33 32 5f 54 typedef UINT32_T
4830: 59 50 45 20 75 33 32 3b 20 20 20 20 20 20 20 20 YPE u32;
4840: 20 20 20 2f 2a 20 34 2d 62 79 74 65 20 75 6e 73 /* 4-byte uns
4850: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
4860: 0a 74 79 70 65 64 65 66 20 55 49 4e 54 31 36 5f .typedef UINT16_
4870: 54 59 50 45 20 75 31 36 3b 20 20 20 20 20 20 20 TYPE u16;
4880: 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 75 6e /* 2-byte un
4890: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
48a0: 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 36 5f /.typedef INT16_
48b0: 54 59 50 45 20 69 31 36 3b 20 20 20 20 20 20 20 TYPE i16;
48c0: 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 73 /* 2-byte s
48d0: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
48e0: 0a 74 79 70 65 64 65 66 20 55 49 4e 54 38 5f 54 .typedef UINT8_T
48f0: 59 50 45 20 75 38 3b 20 20 20 20 20 20 20 20 20 YPE u8;
4900: 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 75 6e /* 1-byte un
4910: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
4920: 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 38 5f 54 /.typedef INT8_T
4930: 59 50 45 20 69 38 3b 20 20 20 20 20 20 20 20 20 YPE i8;
4940: 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 73 /* 1-byte s
4950: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
4960: 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 5f 4d ../*.** SQLITE_M
4970: 41 58 5f 55 33 32 20 69 73 20 61 20 75 36 34 20 AX_U32 is a u64
4980: 63 6f 6e 73 74 61 6e 74 20 74 68 61 74 20 69 73 constant that is
4990: 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 75 36 34 the maximum u64
49a0: 20 76 61 6c 75 65 0a 2a 2a 20 74 68 61 74 20 63 value.** that c
49b0: 61 6e 20 62 65 20 73 74 6f 72 65 64 20 69 6e 20 an be stored in
49c0: 61 20 75 33 32 20 77 69 74 68 6f 75 74 20 6c 6f a u32 without lo
49d0: 73 73 20 6f 66 20 64 61 74 61 2e 20 20 54 68 65 ss of data. The
49e0: 20 76 61 6c 75 65 0a 2a 2a 20 69 73 20 30 78 30 value.** is 0x0
49f0: 30 30 30 30 30 30 30 66 66 66 66 66 66 66 66 2e 0000000ffffffff.
4a00: 20 20 42 75 74 20 62 65 63 61 75 73 65 20 6f 66 But because of
4a10: 20 71 75 69 72 6b 73 20 6f 66 20 73 6f 6d 65 20 quirks of some
4a20: 63 6f 6d 70 69 6c 65 72 73 2c 20 77 65 0a 2a 2a compilers, we.**
4a30: 20 68 61 76 65 20 74 6f 20 73 70 65 63 69 66 79 have to specify
4a40: 20 74 68 65 20 76 61 6c 75 65 20 69 6e 20 74 68 the value in th
4a50: 65 20 6c 65 73 73 20 69 6e 74 75 69 74 69 76 65 e less intuitive
4a60: 20 6d 61 6e 6e 65 72 20 73 68 6f 77 6e 3a 0a 2a manner shown:.*
4a70: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
4a80: 5f 4d 41 58 5f 55 33 32 20 20 28 28 28 28 75 36 _MAX_U32 ((((u6
4a90: 34 29 31 29 3c 3c 33 32 29 2d 31 29 0a 0a 2f 2a 4)1)<<32)-1)../*
4aa0: 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 79 70 65 .** The datatype
4ab0: 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 65 used to store e
4ac0: 73 74 69 6d 61 74 65 73 20 6f 66 20 74 68 65 20 stimates of the
4ad0: 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 number of rows i
4ae0: 6e 20 61 0a 2a 2a 20 74 61 62 6c 65 20 6f 72 20 n a.** table or
4af0: 69 6e 64 65 78 2e 20 20 54 68 69 73 20 69 73 20 index. This is
4b00: 61 6e 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 an unsigned inte
4b10: 67 65 72 20 74 79 70 65 2e 20 20 46 6f 72 20 39 ger type. For 9
4b20: 39 2e 39 25 20 6f 66 0a 2a 2a 20 74 68 65 20 77 9.9% of.** the w
4b30: 6f 72 6c 64 2c 20 61 20 33 32 2d 62 69 74 20 69 orld, a 32-bit i
4b40: 6e 74 65 67 65 72 20 69 73 20 73 75 66 66 69 63 nteger is suffic
4b50: 69 65 6e 74 2e 20 20 42 75 74 20 61 20 36 34 2d ient. But a 64-
4b60: 62 69 74 20 69 6e 74 65 67 65 72 0a 2a 2a 20 63 bit integer.** c
4b70: 61 6e 20 62 65 20 75 73 65 64 20 61 74 20 63 6f an be used at co
4b80: 6d 70 69 6c 65 2d 74 69 6d 65 20 69 66 20 64 65 mpile-time if de
4b90: 73 69 72 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 sired..*/.#ifdef
4ba0: 20 53 51 4c 49 54 45 5f 36 34 42 49 54 5f 53 54 SQLITE_64BIT_ST
4bb0: 41 54 53 0a 20 74 79 70 65 64 65 66 20 75 36 34 ATS. typedef u64
4bc0: 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 tRowcnt; /*
4bd0: 36 34 2d 62 69 74 20 6f 6e 6c 79 20 69 66 20 72 64-bit only if r
4be0: 65 71 75 65 73 74 65 64 20 61 74 20 63 6f 6d 70 equested at comp
4bf0: 69 6c 65 2d 74 69 6d 65 20 2a 2f 0a 23 65 6c 73 ile-time */.#els
4c00: 65 0a 20 74 79 70 65 64 65 66 20 75 33 32 20 74 e. typedef u32 t
4c10: 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 33 32 Rowcnt; /* 32
4c20: 2d 62 69 74 20 69 73 20 74 68 65 20 64 65 66 61 -bit is the defa
4c30: 75 6c 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f ult */.#endif../
4c40: 2a 0a 2a 2a 20 45 73 74 69 6d 61 74 65 64 20 71 *.** Estimated q
4c50: 75 61 6e 74 69 74 69 65 73 20 75 73 65 64 20 66 uantities used f
4c60: 6f 72 20 71 75 65 72 79 20 70 6c 61 6e 6e 69 6e or query plannin
4c70: 67 20 61 72 65 20 73 74 6f 72 65 64 20 61 73 20 g are stored as
4c80: 31 36 2d 62 69 74 0a 2a 2a 20 6c 6f 67 61 72 69 16-bit.** logari
4c90: 74 68 6d 73 2e 20 20 46 6f 72 20 71 75 61 6e 74 thms. For quant
4ca0: 69 74 79 20 58 2c 20 74 68 65 20 76 61 6c 75 65 ity X, the value
4cb0: 20 73 74 6f 72 65 64 20 69 73 20 31 30 2a 6c 6f stored is 10*lo
4cc0: 67 32 28 58 29 2e 20 20 54 68 69 73 0a 2a 2a 20 g2(X). This.**
4cd0: 67 69 76 65 73 20 61 20 70 6f 73 73 69 62 6c 65 gives a possible
4ce0: 20 72 61 6e 67 65 20 6f 66 20 76 61 6c 75 65 73 range of values
4cf0: 20 6f 66 20 61 70 70 72 6f 78 69 6d 61 74 65 6c of approximatel
4d00: 79 20 31 2e 30 65 39 38 36 20 74 6f 20 31 65 2d y 1.0e986 to 1e-
4d10: 39 38 36 2e 0a 2a 2a 20 42 75 74 20 74 68 65 20 986..** But the
4d20: 61 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 61 allowed values a
4d30: 72 65 20 22 67 72 61 69 6e 79 22 2e 20 20 4e 6f re "grainy". No
4d40: 74 20 65 76 65 72 79 20 76 61 6c 75 65 20 69 73 t every value is
4d50: 20 72 65 70 72 65 73 65 6e 74 61 62 6c 65 2e 0a representable..
4d60: 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 ** For example,
4d70: 71 75 61 6e 74 69 74 69 65 73 20 31 36 20 61 6e quantities 16 an
4d80: 64 20 31 37 20 61 72 65 20 62 6f 74 68 20 72 65 d 17 are both re
4d90: 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 20 4c presented by a L
4da0: 6f 67 45 73 74 0a 2a 2a 20 6f 66 20 34 30 2e 20 ogEst.** of 40.
4db0: 20 48 6f 77 65 76 65 72 2c 20 73 69 6e 63 65 20 However, since
4dc0: 4c 6f 67 45 73 74 20 71 75 61 6e 74 69 74 69 65 LogEst quantitie
4dd0: 73 20 61 72 65 20 73 75 70 70 6f 73 65 20 74 6f s are suppose to
4de0: 20 62 65 20 65 73 74 69 6d 61 74 65 73 2c 0a 2a be estimates,.*
4df0: 2a 20 6e 6f 74 20 65 78 61 63 74 20 76 61 6c 75 * not exact valu
4e00: 65 73 2c 20 74 68 69 73 20 69 6d 70 72 65 63 69 es, this impreci
4e10: 73 69 6f 6e 20 69 73 20 6e 6f 74 20 61 20 70 72 sion is not a pr
4e20: 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a 2a 20 22 4c 6f oblem..**.** "Lo
4e30: 67 45 73 74 22 20 69 73 20 73 68 6f 72 74 20 66 gEst" is short f
4e40: 6f 72 20 22 4c 6f 67 61 72 69 74 68 6d 69 63 20 or "Logarithmic
4e50: 45 73 74 69 6d 61 74 65 22 2e 0a 2a 2a 0a 2a 2a Estimate"..**.**
4e60: 20 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 20 20 20 Examples:.**
4e70: 20 20 20 31 20 2d 3e 20 30 20 20 20 20 20 20 20 1 -> 0
4e80: 20 20 20 20 20 20 20 32 30 20 2d 3e 20 34 33 20 20 -> 43
4e90: 20 20 20 20 20 20 20 20 20 31 30 30 30 30 20 2d 10000 -
4ea0: 3e 20 31 33 32 0a 2a 2a 20 20 20 20 20 20 32 20 > 132.** 2
4eb0: 2d 3e 20 31 30 20 20 20 20 20 20 20 20 20 20 20 -> 10
4ec0: 20 20 32 35 20 2d 3e 20 34 36 20 20 20 20 20 20 25 -> 46
4ed0: 20 20 20 20 32 35 30 30 30 20 2d 3e 20 31 34 36 25000 -> 146
4ee0: 0a 2a 2a 20 20 20 20 20 20 33 20 2d 3e 20 31 36 .** 3 -> 16
4ef0: 20 20 20 20 20 20 20 20 20 20 20 20 31 30 30 20 100
4f00: 2d 3e 20 36 36 20 20 20 20 20 20 20 20 31 30 30 -> 66 100
4f10: 30 30 30 30 20 2d 3e 20 31 39 39 0a 2a 2a 20 20 0000 -> 199.**
4f20: 20 20 20 20 34 20 2d 3e 20 32 30 20 20 20 20 20 4 -> 20
4f30: 20 20 20 20 20 20 31 30 30 30 20 2d 3e 20 39 39 1000 -> 99
4f40: 20 20 20 20 20 20 20 20 31 30 34 38 35 37 36 20 1048576
4f50: 2d 3e 20 32 30 30 0a 2a 2a 20 20 20 20 20 31 30 -> 200.** 10
4f60: 20 2d 3e 20 33 33 20 20 20 20 20 20 20 20 20 20 -> 33
4f70: 20 31 30 32 34 20 2d 3e 20 31 30 30 20 20 20 20 1024 -> 100
4f80: 34 32 39 34 39 36 37 32 39 36 20 2d 3e 20 33 32 4294967296 -> 32
4f90: 30 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 67 45 0.**.** The LogE
4fa0: 73 74 20 63 61 6e 20 62 65 20 6e 65 67 61 74 69 st can be negati
4fb0: 76 65 20 74 6f 20 69 6e 64 69 63 61 74 65 20 66 ve to indicate f
4fc0: 72 61 63 74 69 6f 6e 61 6c 20 76 61 6c 75 65 73 ractional values
4fd0: 2e 20 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a . .** Examples:.
4fe0: 2a 2a 0a 2a 2a 20 20 20 20 30 2e 35 20 2d 3e 20 **.** 0.5 ->
4ff0: 2d 31 30 20 20 20 20 20 20 20 20 20 20 20 30 2e -10 0.
5000: 31 20 2d 3e 20 2d 33 33 20 20 20 20 20 20 20 20 1 -> -33
5010: 30 2e 30 36 32 35 20 2d 3e 20 2d 34 30 0a 2a 2f 0.0625 -> -40.*/
5020: 0a 74 79 70 65 64 65 66 20 49 4e 54 31 36 5f 54 .typedef INT16_T
5030: 59 50 45 20 4c 6f 67 45 73 74 3b 0a 0a 2f 2a 0a YPE LogEst;../*.
5040: 2a 2a 20 53 65 74 20 74 68 65 20 53 51 4c 49 54 ** Set the SQLIT
5050: 45 5f 50 54 52 53 49 5a 45 20 6d 61 63 72 6f 20 E_PTRSIZE macro
5060: 74 6f 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 to the number of
5070: 20 62 79 74 65 73 20 69 6e 20 61 20 70 6f 69 6e bytes in a poin
5080: 74 65 72 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ter.*/.#ifndef S
5090: 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 0a 23 20 QLITE_PTRSIZE.#
50a0: 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 53 49 5a if defined(__SIZ
50b0: 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f 29 0a 23 EOF_POINTER__).#
50c0: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
50d0: 5f 50 54 52 53 49 5a 45 20 5f 5f 53 49 5a 45 4f _PTRSIZE __SIZEO
50e0: 46 5f 50 4f 49 4e 54 45 52 5f 5f 0a 23 20 65 6c F_POINTER__.# el
50f0: 69 66 20 64 65 66 69 6e 65 64 28 69 33 38 36 29 if defined(i386)
5100: 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 || defined(
5110: 5f 5f 69 33 38 36 5f 5f 29 20 20 20 7c 7c 20 64 __i386__) || d
5120: 65 66 69 6e 65 64 28 5f 4d 5f 49 58 38 36 29 20 efined(_M_IX86)
5130: 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 20 20 64 || \. d
5140: 65 66 69 6e 65 64 28 5f 4d 5f 41 52 4d 29 20 20 efined(_M_ARM)
5150: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 61 72 || defined(__ar
5160: 6d 5f 5f 29 20 20 20 20 7c 7c 20 64 65 66 69 6e m__) || defin
5170: 65 64 28 5f 5f 78 38 36 29 0a 23 20 20 20 64 65 ed(__x86).# de
5180: 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 53 fine SQLITE_PTRS
5190: 49 5a 45 20 34 0a 23 20 65 6c 73 65 0a 23 20 20 IZE 4.# else.#
51a0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 define SQLITE_P
51b0: 54 52 53 49 5a 45 20 38 0a 23 20 65 6e 64 69 66 TRSIZE 8.# endif
51c0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d .#endif../*.** M
51d0: 61 63 72 6f 73 20 74 6f 20 64 65 74 65 72 6d 69 acros to determi
51e0: 6e 65 20 77 68 65 74 68 65 72 20 74 68 65 20 6d ne whether the m
51f0: 61 63 68 69 6e 65 20 69 73 20 62 69 67 20 6f 72 achine is big or
5200: 20 6c 69 74 74 6c 65 20 65 6e 64 69 61 6e 2c 0a little endian,.
5210: 2a 2a 20 61 6e 64 20 77 68 65 74 68 65 72 20 6f ** and whether o
5220: 72 20 6e 6f 74 20 74 68 61 74 20 64 65 74 65 72 r not that deter
5230: 6d 69 6e 61 74 69 6f 6e 20 69 73 20 72 75 6e 2d mination is run-
5240: 74 69 6d 65 20 6f 72 20 63 6f 6d 70 69 6c 65 2d time or compile-
5250: 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 time..**.** For
5260: 62 65 73 74 20 70 65 72 66 6f 72 6d 61 6e 63 65 best performance
5270: 2c 20 61 6e 20 61 74 74 65 6d 70 74 20 69 73 20 , an attempt is
5280: 6d 61 64 65 20 74 6f 20 67 75 65 73 73 20 61 74 made to guess at
5290: 20 74 68 65 20 62 79 74 65 2d 6f 72 64 65 72 0a the byte-order.
52a0: 2a 2a 20 75 73 69 6e 67 20 43 2d 70 72 65 70 72 ** using C-prepr
52b0: 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 2e 20 ocessor macros.
52c0: 20 49 66 20 74 68 61 74 20 69 73 20 75 6e 73 75 If that is unsu
52d0: 63 63 65 73 73 66 75 6c 2c 20 6f 72 20 69 66 0a ccessful, or if.
52e0: 2a 2a 20 2d 44 53 51 4c 49 54 45 5f 52 55 4e 54 ** -DSQLITE_RUNT
52f0: 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 3d 31 20 IME_BYTEORDER=1
5300: 69 73 20 73 65 74 2c 20 74 68 65 6e 20 62 79 74 is set, then byt
5310: 65 2d 6f 72 64 65 72 20 69 73 20 64 65 74 65 72 e-order is deter
5320: 6d 69 6e 65 64 0a 2a 2a 20 61 74 20 72 75 6e 2d mined.** at run-
5330: 74 69 6d 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 time..*/.#ifdef
5340: 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 SQLITE_AMALGAMAT
5350: 49 4f 4e 0a 63 6f 6e 73 74 20 69 6e 74 20 73 71 ION.const int sq
5360: 6c 69 74 65 33 6f 6e 65 20 3d 20 31 3b 0a 23 65 lite3one = 1;.#e
5370: 6c 73 65 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 lse.extern const
5380: 20 69 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 3b int sqlite3one;
5390: 0a 23 65 6e 64 69 66 0a 23 69 66 20 28 64 65 66 .#endif.#if (def
53a0: 69 6e 65 64 28 69 33 38 36 29 20 20 20 20 20 7c ined(i386) |
53b0: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 69 33 38 36 | defined(__i386
53c0: 5f 5f 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 __) || defined
53d0: 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 20 20 20 (_M_IX86) ||
53e0: 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f \. defined(_
53f0: 5f 78 38 36 5f 36 34 29 20 7c 7c 20 64 65 66 69 _x86_64) || defi
5400: 6e 65 64 28 5f 5f 78 38 36 5f 36 34 5f 5f 29 20 ned(__x86_64__)
5410: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 58 36 || defined(_M_X6
5420: 34 29 20 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 4) || \.
5430: 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 4d 44 36 defined(_M_AMD6
5440: 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 4) || defined(_M
5450: 5f 41 52 4d 29 20 20 20 20 20 7c 7c 20 64 65 66 _ARM) || def
5460: 69 6e 65 64 28 5f 5f 78 38 36 29 20 20 20 7c 7c ined(__x86) ||
5470: 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 6e \. defin
5480: 65 64 28 5f 5f 61 72 6d 5f 5f 29 29 20 26 26 20 ed(__arm__)) &&
5490: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
54a0: 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 RUNTIME_BYTEORDE
54b0: 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 R).# define SQLI
54c0: 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 TE_BYTEORDER
54d0: 31 32 33 34 0a 23 20 64 65 66 69 6e 65 20 53 51 1234.# define SQ
54e0: 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 LITE_BIGENDIAN
54f0: 20 20 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 0.# define SQL
5500: 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e ITE_LITTLEENDIAN
5510: 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1.# define SQLI
5520: 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 TE_UTF16NATIVE
5530: 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 0a 23 SQLITE_UTF16LE.#
5540: 65 6e 64 69 66 0a 23 69 66 20 28 64 65 66 69 6e endif.#if (defin
5550: 65 64 28 73 70 61 72 63 29 20 20 20 20 7c 7c 20 ed(sparc) ||
5560: 64 65 66 69 6e 65 64 28 5f 5f 70 70 63 5f 5f 29 defined(__ppc__)
5570: 29 20 20 5c 0a 20 20 20 20 26 26 20 21 64 65 66 ) \. && !def
5580: 69 6e 65 64 28 53 51 4c 49 54 45 5f 52 55 4e 54 ined(SQLITE_RUNT
5590: 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 29 0a 23 IME_BYTEORDER).#
55a0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 define SQLITE_B
55b0: 59 54 45 4f 52 44 45 52 20 20 20 20 34 33 32 31 YTEORDER 4321
55c0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
55d0: 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 31 0a _BIGENDIAN 1.
55e0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
55f0: 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 30 0a 23 LITTLEENDIAN 0.#
5600: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 55 define SQLITE_U
5610: 54 46 31 36 4e 41 54 49 56 45 20 20 53 51 4c 49 TF16NATIVE SQLI
5620: 54 45 5f 55 54 46 31 36 42 45 0a 23 65 6e 64 69 TE_UTF16BE.#endi
5630: 66 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 f.#if !defined(S
5640: 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 29 QLITE_BYTEORDER)
5650: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
5660: 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 30 20 _BYTEORDER 0
5670: 20 20 20 20 2f 2a 20 30 20 6d 65 61 6e 73 20 22 /* 0 means "
5680: 75 6e 6b 6e 6f 77 6e 20 61 74 20 63 6f 6d 70 69 unknown at compi
5690: 6c 65 2d 74 69 6d 65 22 20 2a 2f 0a 23 20 64 65 le-time" */.# de
56a0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 fine SQLITE_BIGE
56b0: 4e 44 49 41 4e 20 20 20 20 28 2a 28 63 68 61 72 NDIAN (*(char
56c0: 20 2a 29 28 26 73 71 6c 69 74 65 33 6f 6e 65 29 *)(&sqlite3one)
56d0: 3d 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 53 51 ==0).# define SQ
56e0: 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 LITE_LITTLEENDIA
56f0: 4e 20 28 2a 28 63 68 61 72 20 2a 29 28 26 73 71 N (*(char *)(&sq
5700: 6c 69 74 65 33 6f 6e 65 29 3d 3d 31 29 0a 23 20 lite3one)==1).#
5710: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 55 54 define SQLITE_UT
5720: 46 31 36 4e 41 54 49 56 45 20 20 28 53 51 4c 49 F16NATIVE (SQLI
5730: 54 45 5f 42 49 47 45 4e 44 49 41 4e 3f 53 51 4c TE_BIGENDIAN?SQL
5740: 49 54 45 5f 55 54 46 31 36 42 45 3a 53 51 4c 49 ITE_UTF16BE:SQLI
5750: 54 45 5f 55 54 46 31 36 4c 45 29 0a 23 65 6e 64 TE_UTF16LE).#end
5760: 69 66 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6e 73 74 61 if../*.** Consta
5770: 6e 74 73 20 66 6f 72 20 74 68 65 20 6c 61 72 67 nts for the larg
5780: 65 73 74 20 61 6e 64 20 73 6d 61 6c 6c 65 73 74 est and smallest
5790: 20 70 6f 73 73 69 62 6c 65 20 36 34 2d 62 69 74 possible 64-bit
57a0: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 73 signed integers
57b0: 2e 0a 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f ..** These macro
57c0: 73 20 61 72 65 20 64 65 73 69 67 6e 65 64 20 74 s are designed t
57d0: 6f 20 77 6f 72 6b 20 63 6f 72 72 65 63 74 6c 79 o work correctly
57e0: 20 6f 6e 20 62 6f 74 68 20 33 32 2d 62 69 74 20 on both 32-bit
57f0: 61 6e 64 20 36 34 2d 62 69 74 0a 2a 2a 20 63 6f and 64-bit.** co
5800: 6d 70 69 6c 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 mpilers..*/.#def
5810: 69 6e 65 20 4c 41 52 47 45 53 54 5f 49 4e 54 36 ine LARGEST_INT6
5820: 34 20 20 28 30 78 66 66 66 66 66 66 66 66 7c 28 4 (0xffffffff|(
5830: 28 28 69 36 34 29 30 78 37 66 66 66 66 66 66 66 ((i64)0x7fffffff
5840: 29 3c 3c 33 32 29 29 0a 23 64 65 66 69 6e 65 20 )<<32)).#define
5850: 53 4d 41 4c 4c 45 53 54 5f 49 4e 54 36 34 20 28 SMALLEST_INT64 (
5860: 28 28 69 36 34 29 2d 31 29 20 2d 20 4c 41 52 47 ((i64)-1) - LARG
5870: 45 53 54 5f 49 4e 54 36 34 29 0a 0a 2f 2a 20 0a EST_INT64)../* .
5880: 2a 2a 20 52 6f 75 6e 64 20 75 70 20 61 20 6e 75 ** Round up a nu
5890: 6d 62 65 72 20 74 6f 20 74 68 65 20 6e 65 78 74 mber to the next
58a0: 20 6c 61 72 67 65 72 20 6d 75 6c 74 69 70 6c 65 larger multiple
58b0: 20 6f 66 20 38 2e 20 20 54 68 69 73 20 69 73 20 of 8. This is
58c0: 75 73 65 64 0a 2a 2a 20 74 6f 20 66 6f 72 63 65 used.** to force
58d0: 20 38 2d 62 79 74 65 20 61 6c 69 67 6e 6d 65 6e 8-byte alignmen
58e0: 74 20 6f 6e 20 36 34 2d 62 69 74 20 61 72 63 68 t on 64-bit arch
58f0: 69 74 65 63 74 75 72 65 73 2e 0a 2a 2f 0a 23 64 itectures..*/.#d
5900: 65 66 69 6e 65 20 52 4f 55 4e 44 38 28 78 29 20 efine ROUND8(x)
5910: 20 20 20 20 28 28 28 78 29 2b 37 29 26 7e 37 29 (((x)+7)&~7)
5920: 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e 64 20 64 6f ../*.** Round do
5930: 77 6e 20 74 6f 20 74 68 65 20 6e 65 61 72 65 73 wn to the neares
5940: 74 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 38 0a t multiple of 8.
5950: 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e 44 */.#define ROUND
5960: 44 4f 57 4e 38 28 78 29 20 28 28 78 29 26 7e 37 DOWN8(x) ((x)&~7
5970: 29 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 65 72 74 20 )../*.** Assert
5980: 74 68 61 74 20 74 68 65 20 70 6f 69 6e 74 65 72 that the pointer
5990: 20 58 20 69 73 20 61 6c 69 67 6e 65 64 20 74 6f X is aligned to
59a0: 20 61 6e 20 38 2d 62 79 74 65 20 62 6f 75 6e 64 an 8-byte bound
59b0: 61 72 79 2e 20 20 54 68 69 73 0a 2a 2a 20 6d 61 ary. This.** ma
59c0: 63 72 6f 20 69 73 20 75 73 65 64 20 6f 6e 6c 79 cro is used only
59d0: 20 77 69 74 68 69 6e 20 61 73 73 65 72 74 28 29 within assert()
59e0: 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 to verify that
59f0: 74 68 65 20 63 6f 64 65 20 67 65 74 73 0a 2a 2a the code gets.**
5a00: 20 61 6c 6c 20 61 6c 69 67 6e 6d 65 6e 74 20 72 all alignment r
5a10: 65 73 74 72 69 63 74 69 6f 6e 73 20 63 6f 72 72 estrictions corr
5a20: 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 45 78 63 65 70 ect..**.** Excep
5a30: 74 2c 20 69 66 20 53 51 4c 49 54 45 5f 34 5f 42 t, if SQLITE_4_B
5a40: 59 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c YTE_ALIGNED_MALL
5a50: 4f 43 20 69 73 20 64 65 66 69 6e 65 64 2c 20 74 OC is defined, t
5a60: 68 65 6e 20 74 68 65 0a 2a 2a 20 75 6e 64 65 72 hen the.** under
5a70: 6c 79 69 6e 67 20 6d 61 6c 6c 6f 63 28 29 20 69 lying malloc() i
5a80: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6d 69 mplementation mi
5a90: 67 68 74 20 72 65 74 75 72 6e 20 75 73 20 34 2d ght return us 4-
5aa0: 62 79 74 65 20 61 6c 69 67 6e 65 64 0a 2a 2a 20 byte aligned.**
5ab0: 70 6f 69 6e 74 65 72 73 2e 20 20 49 6e 20 74 68 pointers. In th
5ac0: 61 74 20 63 61 73 65 2c 20 6f 6e 6c 79 20 76 65 at case, only ve
5ad0: 72 69 66 79 20 34 2d 62 79 74 65 20 61 6c 69 67 rify 4-byte alig
5ae0: 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 nment..*/.#ifdef
5af0: 20 53 51 4c 49 54 45 5f 34 5f 42 59 54 45 5f 41 SQLITE_4_BYTE_A
5b00: 4c 49 47 4e 45 44 5f 4d 41 4c 4c 4f 43 0a 23 20 LIGNED_MALLOC.#
5b10: 64 65 66 69 6e 65 20 45 49 47 48 54 5f 42 59 54 define EIGHT_BYT
5b20: 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 58 29 20 20 E_ALIGNMENT(X)
5b30: 20 28 28 28 28 63 68 61 72 2a 29 28 58 29 20 2d ((((char*)(X) -
5b40: 20 28 63 68 61 72 2a 29 30 29 26 33 29 3d 3d 30 (char*)0)&3)==0
5b50: 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ).#else.# define
5b60: 20 45 49 47 48 54 5f 42 59 54 45 5f 41 4c 49 47 EIGHT_BYTE_ALIG
5b70: 4e 4d 45 4e 54 28 58 29 20 20 20 28 28 28 28 63 NMENT(X) ((((c
5b80: 68 61 72 2a 29 28 58 29 20 2d 20 28 63 68 61 72 har*)(X) - (char
5b90: 2a 29 30 29 26 37 29 3d 3d 30 29 0a 23 65 6e 64 *)0)&7)==0).#end
5ba0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 69 73 61 62 6c if../*.** Disabl
5bb0: 65 20 4d 4d 41 50 20 6f 6e 20 70 6c 61 74 66 6f e MMAP on platfo
5bc0: 72 6d 73 20 77 68 65 72 65 20 69 74 20 69 73 20 rms where it is
5bd0: 6b 6e 6f 77 6e 20 74 6f 20 6e 6f 74 20 77 6f 72 known to not wor
5be0: 6b 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 k.*/.#if defined
5bf0: 28 5f 5f 4f 70 65 6e 42 53 44 5f 5f 29 20 7c 7c (__OpenBSD__) ||
5c00: 20 64 65 66 69 6e 65 64 28 5f 5f 51 4e 58 4e 54 defined(__QNXNT
5c10: 4f 5f 5f 29 0a 23 20 75 6e 64 65 66 20 53 51 4c O__).# undef SQL
5c20: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5c30: 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 E.# define SQLIT
5c40: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 20 E_MAX_MMAP_SIZE
5c50: 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
5c60: 44 65 66 61 75 6c 74 20 6d 61 78 69 6d 75 6d 20 Default maximum
5c70: 73 69 7a 65 20 6f 66 20 6d 65 6d 6f 72 79 20 75 size of memory u
5c80: 73 65 64 20 62 79 20 6d 65 6d 6f 72 79 2d 6d 61 sed by memory-ma
5c90: 70 70 65 64 20 49 2f 4f 20 69 6e 20 74 68 65 20 pped I/O in the
5ca0: 56 46 53 0a 2a 2f 0a 23 69 66 64 65 66 20 5f 5f VFS.*/.#ifdef __
5cb0: 41 50 50 4c 45 5f 5f 0a 23 20 69 6e 63 6c 75 64 APPLE__.# includ
5cc0: 65 20 3c 54 61 72 67 65 74 43 6f 6e 64 69 74 69 e <TargetConditi
5cd0: 6f 6e 61 6c 73 2e 68 3e 0a 23 20 69 66 20 54 41 onals.h>.# if TA
5ce0: 52 47 45 54 5f 4f 53 5f 49 50 48 4f 4e 45 0a 23 RGET_OS_IPHONE.#
5cf0: 20 20 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f undef SQLITE_
5d00: 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 MAX_MMAP_SIZE.#
5d10: 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f define SQLITE_
5d20: 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 0a MAX_MMAP_SIZE 0.
5d30: 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 # endif.#endif.#
5d40: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 ifndef SQLITE_MA
5d50: 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 69 66 X_MMAP_SIZE.# if
5d60: 20 64 65 66 69 6e 65 64 28 5f 5f 6c 69 6e 75 78 defined(__linux
5d70: 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e __) \. || defin
5d80: 65 64 28 5f 57 49 4e 33 32 29 20 5c 0a 20 20 7c ed(_WIN32) \. |
5d90: 7c 20 28 64 65 66 69 6e 65 64 28 5f 5f 41 50 50 | (defined(__APP
5da0: 4c 45 5f 5f 29 20 26 26 20 64 65 66 69 6e 65 64 LE__) && defined
5db0: 28 5f 5f 4d 41 43 48 5f 5f 29 29 20 5c 0a 20 20 (__MACH__)) \.
5dc0: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 73 75 6e || defined(__sun
5dd0: 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c ).# define SQL
5de0: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5df0: 45 20 30 78 37 66 66 66 30 30 30 30 20 20 2f 2a E 0x7fff0000 /*
5e00: 20 32 31 34 37 34 31 38 31 31 32 20 2a 2f 0a 23 2147418112 */.#
5e10: 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e 65 else.# define
5e20: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
5e30: 5f 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 66 0a _SIZE 0.# endif.
5e40: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
5e50: 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 MAX_MMAP_SIZE_xc
5e60: 20 31 20 2f 2a 20 65 78 63 6c 75 64 65 20 66 72 1 /* exclude fr
5e70: 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 om ctime.c */.#e
5e80: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
5e90: 64 65 66 61 75 6c 74 20 4d 4d 41 50 5f 53 49 5a default MMAP_SIZ
5ea0: 45 20 69 73 20 7a 65 72 6f 20 6f 6e 20 61 6c 6c E is zero on all
5eb0: 20 70 6c 61 74 66 6f 72 6d 73 2e 20 20 4f 72 2c platforms. Or,
5ec0: 20 65 76 65 6e 20 69 66 20 61 20 6c 61 72 67 65 even if a large
5ed0: 72 0a 2a 2a 20 64 65 66 61 75 6c 74 20 4d 4d 41 r.** default MMA
5ee0: 50 5f 53 49 5a 45 20 69 73 20 73 70 65 63 69 66 P_SIZE is specif
5ef0: 69 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 ied at compile-t
5f00: 69 6d 65 2c 20 6d 61 6b 65 20 73 75 72 65 20 74 ime, make sure t
5f10: 68 61 74 20 69 74 20 64 6f 65 73 0a 2a 2a 20 6e hat it does.** n
5f20: 6f 74 20 65 78 63 65 65 64 20 74 68 65 20 6d 61 ot exceed the ma
5f30: 78 69 6d 75 6d 20 6d 6d 61 70 20 73 69 7a 65 2e ximum mmap size.
5f40: 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 .*/.#ifndef SQLI
5f50: 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f TE_DEFAULT_MMAP_
5f60: 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 SIZE.# define SQ
5f70: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 LITE_DEFAULT_MMA
5f80: 50 5f 53 49 5a 45 20 30 0a 23 20 64 65 66 69 6e P_SIZE 0.# defin
5f90: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
5fa0: 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 20 31 20 _MMAP_SIZE_xc 1
5fb0: 20 2f 2a 20 45 78 63 6c 75 64 65 20 66 72 6f 6d /* Exclude from
5fc0: 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 6e 64 ctime.c */.#end
5fd0: 69 66 0a 23 69 66 20 53 51 4c 49 54 45 5f 44 45 if.#if SQLITE_DE
5fe0: 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 3e FAULT_MMAP_SIZE>
5ff0: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
6000: 53 49 5a 45 0a 23 20 75 6e 64 65 66 20 53 51 4c SIZE.# undef SQL
6010: 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 ITE_DEFAULT_MMAP
6020: 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 _SIZE.# define S
6030: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d QLITE_DEFAULT_MM
6040: 41 50 5f 53 49 5a 45 20 53 51 4c 49 54 45 5f 4d AP_SIZE SQLITE_M
6050: 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 65 6e AX_MMAP_SIZE.#en
6060: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 6c 79 20 dif../*.** Only
6070: 6f 6e 65 20 6f 66 20 53 51 4c 49 54 45 5f 45 4e one of SQLITE_EN
6080: 41 42 4c 45 5f 53 54 41 54 33 20 6f 72 20 53 51 ABLE_STAT3 or SQ
6090: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
60a0: 34 20 63 61 6e 20 62 65 20 64 65 66 69 6e 65 64 4 can be defined
60b0: 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 79 20 69 73 ..** Priority is
60c0: 20 67 69 76 65 6e 20 74 6f 20 53 51 4c 49 54 45 given to SQLITE
60d0: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 2e 20 20 _ENABLE_STAT4.
60e0: 49 66 20 65 69 74 68 65 72 20 61 72 65 20 64 65 If either are de
60f0: 66 69 6e 65 64 2c 20 61 6c 73 6f 0a 2a 2a 20 64 fined, also.** d
6100: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 efine SQLITE_ENA
6110: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
6120: 54 34 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c T4.*/.#ifdef SQL
6130: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 ITE_ENABLE_STAT4
6140: 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f .# undef SQLITE_
6150: 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 20 64 ENABLE_STAT3.# d
6160: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 efine SQLITE_ENA
6170: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
6180: 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c 49 54 T4 1.#elif SQLIT
6190: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 E_ENABLE_STAT3.#
61a0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 define SQLITE_E
61b0: 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
61c0: 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c TAT4 1.#elif SQL
61d0: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
61e0: 5f 4f 52 5f 53 54 41 54 34 0a 23 20 75 6e 64 65 _OR_STAT4.# unde
61f0: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
6200: 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 STAT3_OR_STAT4.#
6210: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 45 4c endif../*.** SEL
6220: 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 ECTTRACE_ENABLED
6230: 20 77 69 6c 6c 20 62 65 20 65 69 74 68 65 72 20 will be either
6240: 31 20 6f 72 20 30 20 64 65 70 65 6e 64 69 6e 67 1 or 0 depending
6250: 20 6f 6e 20 77 68 65 74 68 65 72 20 6f 72 20 6e on whether or n
6260: 6f 74 0a 2a 2a 20 74 68 65 20 53 65 6c 65 63 74 ot.** the Select
6270: 20 71 75 65 72 79 20 67 65 6e 65 72 61 74 6f 72 query generator
6280: 20 74 72 61 63 69 6e 67 20 6c 6f 67 69 63 20 69 tracing logic i
6290: 73 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a s turned on..*/.
62a0: 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
62b0: 54 45 5f 44 45 42 55 47 29 20 7c 7c 20 64 65 66 TE_DEBUG) || def
62c0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
62d0: 4c 45 5f 53 45 4c 45 43 54 54 52 41 43 45 29 0a LE_SELECTTRACE).
62e0: 23 20 64 65 66 69 6e 65 20 53 45 4c 45 43 54 54 # define SELECTT
62f0: 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 31 0a 23 RACE_ENABLED 1.#
6300: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 45 else.# define SE
6310: 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 LECTTRACE_ENABLE
6320: 44 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a D 0.#endif../*.*
6330: 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
6340: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
6350: 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 tructure is used
6360: 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 62 75 to store the bu
6370: 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 sy-handler.** ca
6380: 6c 6c 62 61 63 6b 20 66 6f 72 20 61 20 67 69 76 llback for a giv
6390: 65 6e 20 73 71 6c 69 74 65 20 68 61 6e 64 6c 65 en sqlite handle
63a0: 2e 20 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 71 6c . .**.** The sql
63b0: 69 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 72 20 ite.busyHandler
63c0: 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 20 73 71 member of the sq
63d0: 6c 69 74 65 20 73 74 72 75 63 74 20 63 6f 6e 74 lite struct cont
63e0: 61 69 6e 73 20 74 68 65 20 62 75 73 79 0a 2a 2a ains the busy.**
63f0: 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 74 68 callback for th
6400: 65 20 64 61 74 61 62 61 73 65 20 68 61 6e 64 6c e database handl
6410: 65 2e 20 45 61 63 68 20 70 61 67 65 72 20 6f 70 e. Each pager op
6420: 65 6e 65 64 20 76 69 61 20 74 68 65 20 73 71 6c ened via the sql
6430: 69 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 69 73 ite.** handle is
6440: 20 70 61 73 73 65 64 20 61 20 70 6f 69 6e 74 65 passed a pointe
6450: 72 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 73 79 r to sqlite.busy
6460: 48 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 75 73 Handler. The bus
6470: 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c y-handler.** cal
6480: 6c 62 61 63 6b 20 69 73 20 63 75 72 72 65 6e 74 lback is current
6490: 6c 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c 79 20 ly invoked only
64a0: 66 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 67 65 from within page
64b0: 72 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 r.c..*/.typedef
64c0: 73 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c struct BusyHandl
64d0: 65 72 20 42 75 73 79 48 61 6e 64 6c 65 72 3b 0a er BusyHandler;.
64e0: 73 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c struct BusyHandl
64f0: 65 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 46 75 er {. int (*xFu
6500: 6e 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 29 3b nc)(void *,int);
6510: 20 20 2f 2a 20 54 68 65 20 62 75 73 79 20 63 61 /* The busy ca
6520: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 llback */. void
6530: 20 2a 70 41 72 67 3b 20 20 20 20 20 20 20 20 20 *pArg;
6540: 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 /* First
6550: 61 72 67 20 74 6f 20 62 75 73 79 20 63 61 6c 6c arg to busy call
6560: 62 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 42 back */. int nB
6570: 75 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 usy;
6580: 20 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d 65 6e /* Incremen
6590: 74 65 64 20 77 69 74 68 20 65 61 63 68 20 62 75 ted with each bu
65a0: 73 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a 0a 2f sy call */.};../
65b0: 2a 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 *.** Name of the
65c0: 20 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 master database
65d0: 20 74 61 62 6c 65 2e 20 20 54 68 65 20 6d 61 73 table. The mas
65e0: 74 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 ter database tab
65f0: 6c 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 63 69 le.** is a speci
6600: 61 6c 20 74 61 62 6c 65 20 74 68 61 74 20 68 6f al table that ho
6610: 6c 64 73 20 74 68 65 20 6e 61 6d 65 73 20 61 6e lds the names an
6620: 64 20 61 74 74 72 69 62 75 74 65 73 20 6f 66 20 d attributes of
6630: 61 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 62 6c all.** user tabl
6640: 65 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 0a es and indices..
6650: 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 */.#define MASTE
6660: 52 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 73 71 R_NAME "sq
6670: 6c 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 64 65 lite_master".#de
6680: 66 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 45 52 fine TEMP_MASTER
6690: 5f 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 5f 74 _NAME "sqlite_t
66a0: 65 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f 2a 0a emp_master"../*.
66b0: 2a 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 67 65 ** The root-page
66c0: 20 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 of the master d
66d0: 61 74 61 62 61 73 65 20 74 61 62 6c 65 2e 0a 2a atabase table..*
66e0: 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 /.#define MASTER
66f0: 5f 52 4f 4f 54 20 20 20 20 20 20 20 31 0a 0a 2f _ROOT 1../
6700: 2a 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 *.** The name of
6710: 20 74 68 65 20 73 63 68 65 6d 61 20 74 61 62 6c the schema tabl
6720: 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 e..*/.#define SC
6730: 48 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 20 28 HEMA_TABLE(x) (
6740: 28 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 26 26 (!OMIT_TEMPDB)&&
6750: 28 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 53 54 (x==1)?TEMP_MAST
6760: 45 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 5f 4e ER_NAME:MASTER_N
6770: 41 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 63 6f AME)../*.** A co
6780: 6e 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 6f 20 nvenience macro
6790: 74 68 61 74 20 72 65 74 75 72 6e 73 20 74 68 65 that returns the
67a0: 20 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 number of eleme
67b0: 6e 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 72 72 nts in.** an arr
67c0: 61 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 41 ay..*/.#define A
67d0: 72 72 61 79 53 69 7a 65 28 58 29 20 20 20 20 28 rraySize(X) (
67e0: 28 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 29 2f (int)(sizeof(X)/
67f0: 73 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 0a 0a sizeof(X[0])))..
6800: 2f 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 /*.** Determine
6810: 69 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 if the argument
6820: 69 73 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 is a power of tw
6830: 6f 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 o.*/.#define IsP
6840: 6f 77 65 72 4f 66 54 77 6f 28 58 29 20 28 28 28 owerOfTwo(X) (((
6850: 58 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 29 0a X)&((X)-1))==0).
6860: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
6870: 77 69 6e 67 20 76 61 6c 75 65 20 61 73 20 61 20 wing value as a
6880: 64 65 73 74 72 75 63 74 6f 72 20 6d 65 61 6e 73 destructor means
6890: 20 74 6f 20 75 73 65 20 73 71 6c 69 74 65 33 44 to use sqlite3D
68a0: 62 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 65 20 bFree()..** The
68b0: 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 29 20 sqlite3DbFree()
68c0: 72 6f 75 74 69 6e 65 20 72 65 71 75 69 72 65 73 routine requires
68d0: 20 74 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 two parameters
68e0: 69 6e 73 74 65 61 64 20 6f 66 20 74 68 65 20 0a instead of the .
68f0: 2a 2a 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 72 ** one parameter
6900: 20 74 68 61 74 20 64 65 73 74 72 75 63 74 6f 72 that destructor
6910: 73 20 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 2e s normally want.
6920: 20 20 53 6f 20 77 65 20 68 61 76 65 20 74 6f 20 So we have to
6930: 69 6e 74 72 6f 64 75 63 65 20 0a 2a 2a 20 74 68 introduce .** th
6940: 69 73 20 6d 61 67 69 63 20 76 61 6c 75 65 20 74 is magic value t
6950: 68 61 74 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f hat the code kno
6960: 77 73 20 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 ws to handle dif
6970: 66 65 72 65 6e 74 6c 79 2e 20 20 41 6e 79 20 0a ferently. Any .
6980: 2a 2a 20 70 6f 69 6e 74 65 72 20 77 69 6c 6c 20 ** pointer will
6990: 77 6f 72 6b 20 68 65 72 65 20 61 73 20 6c 6f 6e work here as lon
69a0: 67 20 61 73 20 69 74 20 69 73 20 64 69 73 74 69 g as it is disti
69b0: 6e 63 74 20 66 72 6f 6d 20 53 51 4c 49 54 45 5f nct from SQLITE_
69c0: 53 54 41 54 49 43 0a 2a 2a 20 61 6e 64 20 53 51 STATIC.** and SQ
69d0: 4c 49 54 45 5f 54 52 41 4e 53 49 45 4e 54 2e 0a LITE_TRANSIENT..
69e0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
69f0: 45 5f 44 59 4e 41 4d 49 43 20 20 20 28 28 73 71 E_DYNAMIC ((sq
6a00: 6c 69 74 65 33 5f 64 65 73 74 72 75 63 74 6f 72 lite3_destructor
6a10: 5f 74 79 70 65 29 73 71 6c 69 74 65 33 4d 61 6c _type)sqlite3Mal
6a20: 6c 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 locSize)../*.**
6a30: 57 68 65 6e 20 53 51 4c 49 54 45 5f 4f 4d 49 54 When SQLITE_OMIT
6a40: 5f 57 53 44 20 69 73 20 64 65 66 69 6e 65 64 2c _WSD is defined,
6a50: 20 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 it means that t
6a60: 68 65 20 74 61 72 67 65 74 20 70 6c 61 74 66 6f he target platfo
6a70: 72 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 rm does.** not s
6a80: 75 70 70 6f 72 74 20 57 72 69 74 61 62 6c 65 20 upport Writable
6a90: 53 74 61 74 69 63 20 44 61 74 61 20 28 57 53 44 Static Data (WSD
6aa0: 29 20 73 75 63 68 20 61 73 20 67 6c 6f 62 61 6c ) such as global
6ab0: 20 61 6e 64 20 73 74 61 74 69 63 20 76 61 72 69 and static vari
6ac0: 61 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 ables..** All va
6ad0: 72 69 61 62 6c 65 73 20 6d 75 73 74 20 65 69 74 riables must eit
6ae0: 68 65 72 20 62 65 20 6f 6e 20 74 68 65 20 73 74 her be on the st
6af0: 61 63 6b 20 6f 72 20 64 79 6e 61 6d 69 63 61 6c ack or dynamical
6b00: 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 66 72 6f ly allocated fro
6b10: 6d 0a 2a 2a 20 74 68 65 20 68 65 61 70 2e 20 20 m.** the heap.
6b20: 57 68 65 6e 20 57 53 44 20 69 73 20 75 6e 73 75 When WSD is unsu
6b30: 70 70 6f 72 74 65 64 2c 20 74 68 65 20 76 61 72 pported, the var
6b40: 69 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f iable declaratio
6b50: 6e 73 20 73 63 61 74 74 65 72 65 64 0a 2a 2a 20 ns scattered.**
6b60: 74 68 72 6f 75 67 68 6f 75 74 20 74 68 65 20 53 throughout the S
6b70: 51 4c 69 74 65 20 63 6f 64 65 20 6d 75 73 74 20 QLite code must
6b80: 62 65 63 6f 6d 65 20 63 6f 6e 73 74 61 6e 74 73 become constants
6b90: 20 69 6e 73 74 65 61 64 2e 20 20 54 68 65 20 53 instead. The S
6ba0: 51 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 QLITE_WSD.** mac
6bb0: 72 6f 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 ro is used for t
6bc0: 68 69 73 20 70 75 72 70 6f 73 65 2e 20 20 41 6e his purpose. An
6bd0: 64 20 69 6e 73 74 65 61 64 20 6f 66 20 72 65 66 d instead of ref
6be0: 65 72 65 6e 63 69 6e 67 20 74 68 65 20 76 61 72 erencing the var
6bf0: 69 61 62 6c 65 0a 2a 2a 20 64 69 72 65 63 74 6c iable.** directl
6c00: 79 2c 20 77 65 20 75 73 65 20 69 74 73 20 63 6f y, we use its co
6c10: 6e 73 74 61 6e 74 20 61 73 20 61 20 6b 65 79 20 nstant as a key
6c20: 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 72 75 to lookup the ru
6c30: 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 74 65 64 n-time allocated
6c40: 0a 2a 2a 20 62 75 66 66 65 72 20 74 68 61 74 20 .** buffer that
6c50: 68 6f 6c 64 73 20 72 65 61 6c 20 76 61 72 69 61 holds real varia
6c60: 62 6c 65 2e 20 20 54 68 65 20 63 6f 6e 73 74 61 ble. The consta
6c70: 6e 74 20 69 73 20 61 6c 73 6f 20 74 68 65 20 69 nt is also the i
6c80: 6e 69 74 69 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f nitializer.** fo
6c90: 72 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 20 61 r the run-time a
6ca0: 6c 6c 6f 63 61 74 65 64 20 62 75 66 66 65 72 2e llocated buffer.
6cb0: 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 75 73 .**.** In the us
6cc0: 75 61 6c 20 63 61 73 65 20 77 68 65 72 65 20 57 ual case where W
6cd0: 53 44 20 69 73 20 73 75 70 70 6f 72 74 65 64 2c SD is supported,
6ce0: 20 74 68 65 20 53 51 4c 49 54 45 5f 57 53 44 20 the SQLITE_WSD
6cf0: 61 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 and GLOBAL.** ma
6d00: 63 72 6f 73 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f cros become no-o
6d10: 70 73 20 61 6e 64 20 68 61 76 65 20 7a 65 72 6f ps and have zero
6d20: 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 6d 70 performance imp
6d30: 61 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 act..*/.#ifdef S
6d40: 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 QLITE_OMIT_WSD.
6d50: 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f #define SQLITE_
6d60: 57 53 44 20 63 6f 6e 73 74 0a 20 20 23 64 65 66 WSD const. #def
6d70: 69 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 ine GLOBAL(t,v)
6d80: 28 2a 28 74 2a 29 73 71 6c 69 74 65 33 5f 77 73 (*(t*)sqlite3_ws
6d90: 64 5f 66 69 6e 64 28 28 76 6f 69 64 2a 29 26 28 d_find((void*)&(
6da0: 76 29 2c 20 73 69 7a 65 6f 66 28 76 29 29 29 0a v), sizeof(v))).
6db0: 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
6dc0: 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 47 4c 3GlobalConfig GL
6dd0: 4f 42 41 4c 28 73 74 72 75 63 74 20 53 71 6c 69 OBAL(struct Sqli
6de0: 74 65 33 43 6f 6e 66 69 67 2c 20 73 71 6c 69 74 te3Config, sqlit
6df0: 65 33 43 6f 6e 66 69 67 29 0a 20 20 69 6e 74 20 e3Config). int
6e00: 73 71 6c 69 74 65 33 5f 77 73 64 5f 69 6e 69 74 sqlite3_wsd_init
6e10: 28 69 6e 74 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a (int N, int J);.
6e20: 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 5f void *sqlite3_
6e30: 77 73 64 5f 66 69 6e 64 28 76 6f 69 64 20 2a 4b wsd_find(void *K
6e40: 2c 20 69 6e 74 20 4c 29 3b 0a 23 65 6c 73 65 0a , int L);.#else.
6e50: 20 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 #define SQLITE
6e60: 5f 57 53 44 20 0a 20 20 23 64 65 66 69 6e 65 20 _WSD . #define
6e70: 47 4c 4f 42 41 4c 28 74 2c 76 29 20 76 0a 20 20 GLOBAL(t,v) v.
6e80: 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 #define sqlite3G
6e90: 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 73 71 6c 69 lobalConfig sqli
6ea0: 74 65 33 43 6f 6e 66 69 67 0a 23 65 6e 64 69 66 te3Config.#endif
6eb0: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c ../*.** The foll
6ec0: 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 65 owing macros are
6ed0: 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 65 73 used to suppres
6ee0: 73 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e 69 s compiler warni
6ef0: 6e 67 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 6d 61 ngs and to.** ma
6f00: 6b 65 20 69 74 20 63 6c 65 61 72 20 74 6f 20 68 ke it clear to h
6f10: 75 6d 61 6e 20 72 65 61 64 65 72 73 20 77 68 65 uman readers whe
6f20: 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 n a function par
6f30: 61 6d 65 74 65 72 20 69 73 20 64 65 6c 69 62 65 ameter is delibe
6f40: 72 61 74 65 6c 79 20 0a 2a 2a 20 6c 65 66 74 20 rately .** left
6f50: 75 6e 75 73 65 64 20 77 69 74 68 69 6e 20 74 68 unused within th
6f60: 65 20 62 6f 64 79 20 6f 66 20 61 20 66 75 6e 63 e body of a func
6f70: 74 69 6f 6e 2e 20 54 68 69 73 20 75 73 75 61 6c tion. This usual
6f80: 6c 79 20 68 61 70 70 65 6e 73 20 77 68 65 6e 0a ly happens when.
6f90: 2a 2a 20 61 20 66 75 6e 63 74 69 6f 6e 20 69 73 ** a function is
6fa0: 20 63 61 6c 6c 65 64 20 76 69 61 20 61 20 66 75 called via a fu
6fb0: 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 2e 20 nction pointer.
6fc0: 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 65 20 For example the
6fd0: 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 .** implementati
6fe0: 6f 6e 20 6f 66 20 61 6e 20 53 51 4c 20 61 67 67 on of an SQL agg
6ff0: 72 65 67 61 74 65 20 73 74 65 70 20 63 61 6c 6c regate step call
7000: 62 61 63 6b 20 6d 61 79 20 6e 6f 74 20 75 73 65 back may not use
7010: 20 74 68 65 0a 2a 2a 20 70 61 72 61 6d 65 74 65 the.** paramete
7020: 72 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 65 r indicating the
7030: 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d number of argum
7040: 65 6e 74 73 20 70 61 73 73 65 64 20 74 6f 20 74 ents passed to t
7050: 68 65 20 61 67 67 72 65 67 61 74 65 2c 0a 2a 2a he aggregate,.**
7060: 20 69 66 20 69 74 20 6b 6e 6f 77 73 20 74 68 61 if it knows tha
7070: 74 20 74 68 69 73 20 69 73 20 65 6e 66 6f 72 63 t this is enforc
7080: 65 64 20 65 6c 73 65 77 68 65 72 65 2e 0a 2a 2a ed elsewhere..**
7090: 0a 2a 2a 20 57 68 65 6e 20 61 20 66 75 6e 63 74 .** When a funct
70a0: 69 6f 6e 20 70 61 72 61 6d 65 74 65 72 20 69 73 ion parameter is
70b0: 20 6e 6f 74 20 75 73 65 64 20 61 74 20 61 6c 6c not used at all
70c0: 20 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 within the body
70d0: 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2c 0a of a function,.
70e0: 2a 2a 20 69 74 20 69 73 20 67 65 6e 65 72 61 6c ** it is general
70f0: 6c 79 20 6e 61 6d 65 64 20 22 4e 6f 74 55 73 65 ly named "NotUse
7100: 64 22 20 6f 72 20 22 4e 6f 74 55 73 65 64 32 22 d" or "NotUsed2"
7110: 20 74 6f 20 6d 61 6b 65 20 74 68 69 6e 67 73 20 to make things
7120: 65 76 65 6e 20 63 6c 65 61 72 65 72 2e 0a 2a 2a even clearer..**
7130: 20 48 6f 77 65 76 65 72 2c 20 74 68 65 73 65 20 However, these
7140: 6d 61 63 72 6f 73 20 6d 61 79 20 61 6c 73 6f 20 macros may also
7150: 62 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 be used to suppr
7160: 65 73 73 20 77 61 72 6e 69 6e 67 73 20 72 65 6c ess warnings rel
7170: 61 74 65 64 20 74 6f 0a 2a 2a 20 70 61 72 61 6d ated to.** param
7180: 65 74 65 72 73 20 74 68 61 74 20 6d 61 79 20 6f eters that may o
7190: 72 20 6d 61 79 20 6e 6f 74 20 62 65 20 75 73 65 r may not be use
71a0: 64 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 63 d depending on c
71b0: 6f 6d 70 69 6c 61 74 69 6f 6e 20 6f 70 74 69 6f ompilation optio
71c0: 6e 73 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 ns..** For examp
71d0: 6c 65 20 74 68 6f 73 65 20 70 61 72 61 6d 65 74 le those paramet
71e0: 65 72 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e ers only used in
71f0: 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d assert() statem
7200: 65 6e 74 73 2e 20 49 6e 20 74 68 65 73 65 0a 2a ents. In these.*
7210: 2a 20 63 61 73 65 73 20 74 68 65 20 70 61 72 61 * cases the para
7220: 6d 65 74 65 72 73 20 61 72 65 20 6e 61 6d 65 64 meters are named
7230: 20 61 73 20 70 65 72 20 74 68 65 20 75 73 75 61 as per the usua
7240: 6c 20 63 6f 6e 76 65 6e 74 69 6f 6e 73 2e 0a 2a l conventions..*
7250: 2f 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 /.#define UNUSED
7260: 5f 50 41 52 41 4d 45 54 45 52 28 78 29 20 28 76 _PARAMETER(x) (v
7270: 6f 69 64 29 28 78 29 0a 23 64 65 66 69 6e 65 20 oid)(x).#define
7280: 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 UNUSED_PARAMETER
7290: 32 28 78 2c 79 29 20 55 4e 55 53 45 44 5f 50 41 2(x,y) UNUSED_PA
72a0: 52 41 4d 45 54 45 52 28 78 29 2c 55 4e 55 53 45 RAMETER(x),UNUSE
72b0: 44 5f 50 41 52 41 4d 45 54 45 52 28 79 29 0a 0a D_PARAMETER(y)..
72c0: 2f 2a 0a 2a 2a 20 46 6f 72 77 61 72 64 20 72 65 /*.** Forward re
72d0: 66 65 72 65 6e 63 65 73 20 74 6f 20 73 74 72 75 ferences to stru
72e0: 63 74 75 72 65 73 0a 2a 2f 0a 74 79 70 65 64 65 ctures.*/.typede
72f0: 66 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f f struct AggInfo
7300: 20 41 67 67 49 6e 66 6f 3b 0a 74 79 70 65 64 65 AggInfo;.typede
7310: 66 20 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e f struct AuthCon
7320: 74 65 78 74 20 41 75 74 68 43 6f 6e 74 65 78 74 text AuthContext
7330: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7340: 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 41 75 74 AutoincInfo Aut
7350: 6f 69 6e 63 49 6e 66 6f 3b 0a 74 79 70 65 64 65 oincInfo;.typede
7360: 66 20 73 74 72 75 63 74 20 42 69 74 76 65 63 20 f struct Bitvec
7370: 42 69 74 76 65 63 3b 0a 74 79 70 65 64 65 66 20 Bitvec;.typedef
7380: 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 43 struct CollSeq C
7390: 6f 6c 6c 53 65 71 3b 0a 74 79 70 65 64 65 66 20 ollSeq;.typedef
73a0: 73 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 43 6f struct Column Co
73b0: 6c 75 6d 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 lumn;.typedef st
73c0: 72 75 63 74 20 44 62 20 44 62 3b 0a 74 79 70 65 ruct Db Db;.type
73d0: 64 65 66 20 73 74 72 75 63 74 20 53 63 68 65 6d def struct Schem
73e0: 61 20 53 63 68 65 6d 61 3b 0a 74 79 70 65 64 65 a Schema;.typede
73f0: 66 20 73 74 72 75 63 74 20 45 78 70 72 20 45 78 f struct Expr Ex
7400: 70 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 pr;.typedef stru
7410: 63 74 20 45 78 70 72 4c 69 73 74 20 45 78 70 72 ct ExprList Expr
7420: 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 List;.typedef st
7430: 72 75 63 74 20 45 78 70 72 53 70 61 6e 20 45 78 ruct ExprSpan Ex
7440: 70 72 53 70 61 6e 3b 0a 74 79 70 65 64 65 66 20 prSpan;.typedef
7450: 73 74 72 75 63 74 20 46 4b 65 79 20 46 4b 65 79 struct FKey FKey
7460: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7470: 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 FuncDestructor
7480: 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 3b 0a FuncDestructor;.
7490: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 typedef struct F
74a0: 75 6e 63 44 65 66 20 46 75 6e 63 44 65 66 3b 0a uncDef FuncDef;.
74b0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 typedef struct F
74c0: 75 6e 63 44 65 66 48 61 73 68 20 46 75 6e 63 44 uncDefHash FuncD
74d0: 65 66 48 61 73 68 3b 0a 74 79 70 65 64 65 66 20 efHash;.typedef
74e0: 73 74 72 75 63 74 20 49 64 4c 69 73 74 20 49 64 struct IdList Id
74f0: 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 List;.typedef st
7500: 72 75 63 74 20 49 6e 64 65 78 20 49 6e 64 65 78 ruct Index Index
7510: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7520: 20 49 6e 64 65 78 53 61 6d 70 6c 65 20 49 6e 64 IndexSample Ind
7530: 65 78 53 61 6d 70 6c 65 3b 0a 74 79 70 65 64 65 exSample;.typede
7540: 66 20 73 74 72 75 63 74 20 4b 65 79 43 6c 61 73 f struct KeyClas
7550: 73 20 4b 65 79 43 6c 61 73 73 3b 0a 74 79 70 65 s KeyClass;.type
7560: 64 65 66 20 73 74 72 75 63 74 20 4b 65 79 49 6e def struct KeyIn
7570: 66 6f 20 4b 65 79 49 6e 66 6f 3b 0a 74 79 70 65 fo KeyInfo;.type
7580: 64 65 66 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 def struct Looka
7590: 73 69 64 65 20 4c 6f 6f 6b 61 73 69 64 65 3b 0a side Lookaside;.
75a0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4c typedef struct L
75b0: 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 4c 6f 6f ookasideSlot Loo
75c0: 6b 61 73 69 64 65 53 6c 6f 74 3b 0a 74 79 70 65 kasideSlot;.type
75d0: 64 65 66 20 73 74 72 75 63 74 20 4d 6f 64 75 6c def struct Modul
75e0: 65 20 4d 6f 64 75 6c 65 3b 0a 74 79 70 65 64 65 e Module;.typede
75f0: 66 20 73 74 72 75 63 74 20 4e 61 6d 65 43 6f 6e f struct NameCon
7600: 74 65 78 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 text NameContext
7610: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7620: 20 50 61 72 73 65 20 50 61 72 73 65 3b 0a 74 79 Parse Parse;.ty
7630: 70 65 64 65 66 20 73 74 72 75 63 74 20 50 72 65 pedef struct Pre
7640: 55 70 64 61 74 65 20 50 72 65 55 70 64 61 74 65 Update PreUpdate
7650: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7660: 20 50 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 PrintfArguments
7670: 20 50 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 PrintfArguments
7680: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7690: 20 52 6f 77 53 65 74 20 52 6f 77 53 65 74 3b 0a RowSet RowSet;.
76a0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
76b0: 61 76 65 70 6f 69 6e 74 20 53 61 76 65 70 6f 69 avepoint Savepoi
76c0: 6e 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 nt;.typedef stru
76d0: 63 74 20 53 65 6c 65 63 74 20 53 65 6c 65 63 74 ct Select Select
76e0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
76f0: 20 53 51 4c 69 74 65 54 68 72 65 61 64 20 53 51 SQLiteThread SQ
7700: 4c 69 74 65 54 68 72 65 61 64 3b 0a 74 79 70 65 LiteThread;.type
7710: 64 65 66 20 73 74 72 75 63 74 20 53 65 6c 65 63 def struct Selec
7720: 74 44 65 73 74 20 53 65 6c 65 63 74 44 65 73 74 tDest SelectDest
7730: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7740: 20 53 72 63 4c 69 73 74 20 53 72 63 4c 69 73 74 SrcList SrcList
7750: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7760: 20 53 74 72 41 63 63 75 6d 20 53 74 72 41 63 63 StrAccum StrAcc
7770: 75 6d 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 um;.typedef stru
7780: 63 74 20 54 61 62 6c 65 20 54 61 62 6c 65 3b 0a ct Table Table;.
7790: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
77a0: 61 62 6c 65 4c 6f 63 6b 20 54 61 62 6c 65 4c 6f ableLock TableLo
77b0: 63 6b 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ck;.typedef stru
77c0: 63 74 20 54 6f 6b 65 6e 20 54 6f 6b 65 6e 3b 0a ct Token Token;.
77d0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
77e0: 72 65 65 56 69 65 77 20 54 72 65 65 56 69 65 77 reeView TreeView
77f0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7800: 20 54 72 69 67 67 65 72 20 54 72 69 67 67 65 72 Trigger Trigger
7810: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
7820: 20 54 72 69 67 67 65 72 50 72 67 20 54 72 69 67 TriggerPrg Trig
7830: 67 65 72 50 72 67 3b 0a 74 79 70 65 64 65 66 20 gerPrg;.typedef
7840: 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 struct TriggerSt
7850: 65 70 20 54 72 69 67 67 65 72 53 74 65 70 3b 0a ep TriggerStep;.
7860: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 55 typedef struct U
7870: 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 20 55 6e npackedRecord Un
7880: 70 61 63 6b 65 64 52 65 63 6f 72 64 3b 0a 74 79 packedRecord;.ty
7890: 70 65 64 65 66 20 73 74 72 75 63 74 20 56 54 61 pedef struct VTa
78a0: 62 6c 65 20 56 54 61 62 6c 65 3b 0a 74 79 70 65 ble VTable;.type
78b0: 64 65 66 20 73 74 72 75 63 74 20 56 74 61 62 43 def struct VtabC
78c0: 74 78 20 56 74 61 62 43 74 78 3b 0a 74 79 70 65 tx VtabCtx;.type
78d0: 64 65 66 20 73 74 72 75 63 74 20 57 61 6c 6b 65 def struct Walke
78e0: 72 20 57 61 6c 6b 65 72 3b 0a 74 79 70 65 64 65 r Walker;.typede
78f0: 66 20 73 74 72 75 63 74 20 57 68 65 72 65 49 6e f struct WhereIn
7900: 66 6f 20 57 68 65 72 65 49 6e 66 6f 3b 0a 74 79 fo WhereInfo;.ty
7910: 70 65 64 65 66 20 73 74 72 75 63 74 20 57 69 74 pedef struct Wit
7920: 68 20 57 69 74 68 3b 0a 0a 2f 2a 0a 2a 2a 20 44 h With;../*.** D
7930: 65 66 65 72 20 73 6f 75 72 63 69 6e 67 20 76 64 efer sourcing vd
7940: 62 65 2e 68 20 61 6e 64 20 62 74 72 65 65 2e 68 be.h and btree.h
7950: 20 75 6e 74 69 6c 20 61 66 74 65 72 20 74 68 65 until after the
7960: 20 22 75 38 22 20 61 6e 64 20 0a 2a 2a 20 22 42 "u8" and .** "B
7970: 75 73 79 48 61 6e 64 6c 65 72 22 20 74 79 70 65 usyHandler" type
7980: 64 65 66 73 2e 20 76 64 62 65 2e 68 20 61 6c 73 defs. vdbe.h als
7990: 6f 20 72 65 71 75 69 72 65 73 20 61 20 66 65 77 o requires a few
79a0: 20 6f 66 20 74 68 65 20 6f 70 61 71 75 65 0a 2a of the opaque.*
79b0: 2a 20 70 6f 69 6e 74 65 72 20 74 79 70 65 73 20 * pointer types
79c0: 28 69 2e 65 2e 20 46 75 6e 63 44 65 66 29 20 64 (i.e. FuncDef) d
79d0: 65 66 69 6e 65 64 20 61 62 6f 76 65 2e 0a 2a 2f efined above..*/
79e0: 0a 23 69 6e 63 6c 75 64 65 20 22 62 74 72 65 65 .#include "btree
79f0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 76 64 .h".#include "vd
7a00: 62 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 be.h".#include "
7a10: 70 61 67 65 72 2e 68 22 0a 23 69 6e 63 6c 75 64 pager.h".#includ
7a20: 65 20 22 70 63 61 63 68 65 2e 68 22 0a 0a 23 69 e "pcache.h"..#i
7a30: 6e 63 6c 75 64 65 20 22 6f 73 2e 68 22 0a 23 69 nclude "os.h".#i
7a40: 6e 63 6c 75 64 65 20 22 6d 75 74 65 78 2e 68 22 nclude "mutex.h"
7a50: 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 64 61 .../*.** Each da
7a60: 74 61 62 61 73 65 20 66 69 6c 65 20 74 6f 20 62 tabase file to b
7a70: 65 20 61 63 63 65 73 73 65 64 20 62 79 20 74 68 e accessed by th
7a80: 65 20 73 79 73 74 65 6d 20 69 73 20 61 6e 20 69 e system is an i
7a90: 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 nstance.** of th
7aa0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
7ab0: 63 74 75 72 65 2e 20 20 54 68 65 72 65 20 61 72 cture. There ar
7ac0: 65 20 6e 6f 72 6d 61 6c 6c 79 20 74 77 6f 20 6f e normally two o
7ad0: 66 20 74 68 65 73 65 20 73 74 72 75 63 74 75 72 f these structur
7ae0: 65 73 0a 2a 2a 20 69 6e 20 74 68 65 20 73 71 6c es.** in the sql
7af0: 69 74 65 2e 61 44 62 5b 5d 20 61 72 72 61 79 2e ite.aDb[] array.
7b00: 20 20 61 44 62 5b 30 5d 20 69 73 20 74 68 65 20 aDb[0] is the
7b10: 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 66 69 main database fi
7b20: 6c 65 20 61 6e 64 0a 2a 2a 20 61 44 62 5b 31 5d le and.** aDb[1]
7b30: 20 69 73 20 74 68 65 20 64 61 74 61 62 61 73 65 is the database
7b40: 20 66 69 6c 65 20 75 73 65 64 20 74 6f 20 68 6f file used to ho
7b50: 6c 64 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 ld temporary tab
7b60: 6c 65 73 2e 20 20 41 64 64 69 74 69 6f 6e 61 6c les. Additional
7b70: 0a 2a 2a 20 64 61 74 61 62 61 73 65 73 20 6d 61 .** databases ma
7b80: 79 20 62 65 20 61 74 74 61 63 68 65 64 2e 0a 2a y be attached..*
7b90: 2f 0a 73 74 72 75 63 74 20 44 62 20 7b 0a 20 20 /.struct Db {.
7ba0: 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
7bb0: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
7bc0: 74 68 69 73 20 64 61 74 61 62 61 73 65 20 2a 2f this database */
7bd0: 0a 20 20 42 74 72 65 65 20 2a 70 42 74 3b 20 20 . Btree *pBt;
7be0: 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 42 /* The B
7bf0: 2a 54 72 65 65 20 73 74 72 75 63 74 75 72 65 20 *Tree structure
7c00: 66 6f 72 20 74 68 69 73 20 64 61 74 61 62 61 73 for this databas
7c10: 65 20 66 69 6c 65 20 2a 2f 0a 20 20 75 38 20 73 e file */. u8 s
7c20: 61 66 65 74 79 5f 6c 65 76 65 6c 3b 20 20 20 20 afety_level;
7c30: 20 2f 2a 20 48 6f 77 20 61 67 67 72 65 73 73 69 /* How aggressi
7c40: 76 65 20 61 74 20 73 79 6e 63 69 6e 67 20 64 61 ve at syncing da
7c50: 74 61 20 74 6f 20 64 69 73 6b 20 2a 2f 0a 20 20 ta to disk */.
7c60: 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b Schema *pSchema;
7c70: 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 /* Pointer
7c80: 74 6f 20 64 61 74 61 62 61 73 65 20 73 63 68 65 to database sche
7c90: 6d 61 20 28 70 6f 73 73 69 62 6c 79 20 73 68 61 ma (possibly sha
7ca0: 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a red) */.};../*.*
7cb0: 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
7cc0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
7cd0: 74 72 75 63 74 75 72 65 20 73 74 6f 72 65 73 20 tructure stores
7ce0: 61 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d a database schem
7cf0: 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 53 63 a..**.** Most Sc
7d00: 68 65 6d 61 20 6f 62 6a 65 63 74 73 20 61 72 65 hema objects are
7d10: 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
7d20: 20 61 20 42 74 72 65 65 2e 20 20 54 68 65 20 65 a Btree. The e
7d30: 78 63 65 70 74 69 6f 6e 20 69 73 0a 2a 2a 20 74 xception is.** t
7d40: 68 65 20 53 63 68 65 6d 61 20 66 6f 72 20 74 68 he Schema for th
7d50: 65 20 54 45 4d 50 20 64 61 74 61 62 61 65 73 20 e TEMP databaes
7d60: 28 73 71 6c 69 74 65 33 2e 61 44 62 5b 31 5d 29 (sqlite3.aDb[1])
7d70: 20 77 68 69 63 68 20 69 73 20 66 72 65 65 2d 73 which is free-s
7d80: 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 6e 20 73 tanding..** In s
7d90: 68 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 hared cache mode
7da0: 2c 20 61 20 73 69 6e 67 6c 65 20 53 63 68 65 6d , a single Schem
7db0: 61 20 6f 62 6a 65 63 74 20 63 61 6e 20 62 65 20 a object can be
7dc0: 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 70 shared by multip
7dd0: 6c 65 0a 2a 2a 20 42 74 72 65 65 73 20 74 68 61 le.** Btrees tha
7de0: 74 20 72 65 66 65 72 20 74 6f 20 74 68 65 20 73 t refer to the s
7df0: 61 6d 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 42 ame underlying B
7e00: 74 53 68 61 72 65 64 20 6f 62 6a 65 63 74 2e 0a tShared object..
7e10: 2a 2a 20 0a 2a 2a 20 53 63 68 65 6d 61 20 6f 62 ** .** Schema ob
7e20: 6a 65 63 74 73 20 61 72 65 20 61 75 74 6f 6d 61 jects are automa
7e30: 74 69 63 61 6c 6c 79 20 64 65 61 6c 6c 6f 63 61 tically dealloca
7e40: 74 65 64 20 77 68 65 6e 20 74 68 65 20 6c 61 73 ted when the las
7e50: 74 20 42 74 72 65 65 20 74 68 61 74 0a 2a 2a 20 t Btree that.**
7e60: 72 65 66 65 72 65 6e 63 65 73 20 74 68 65 6d 20 references them
7e70: 69 73 20 64 65 73 74 72 6f 79 65 64 2e 20 20 20 is destroyed.
7e80: 54 68 65 20 54 45 4d 50 20 53 63 68 65 6d 61 20 The TEMP Schema
7e90: 69 73 20 6d 61 6e 75 61 6c 6c 79 20 66 72 65 65 is manually free
7ea0: 64 20 62 79 0a 2a 2a 20 73 71 6c 69 74 65 33 5f d by.** sqlite3_
7eb0: 63 6c 6f 73 65 28 29 2e 0a 2a 0a 2a 2a 20 41 20 close()..*.** A
7ec0: 74 68 72 65 61 64 20 6d 75 73 74 20 62 65 20 68 thread must be h
7ed0: 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f olding a mutex o
7ee0: 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 n the correspond
7ef0: 69 6e 67 20 42 74 72 65 65 20 69 6e 20 6f 72 64 ing Btree in ord
7f00: 65 72 0a 2a 2a 20 74 6f 20 61 63 63 65 73 73 20 er.** to access
7f10: 53 63 68 65 6d 61 20 63 6f 6e 74 65 6e 74 2e 20 Schema content.
7f20: 20 54 68 69 73 20 69 6d 70 6c 69 65 73 20 74 68 This implies th
7f30: 61 74 20 74 68 65 20 74 68 72 65 61 64 20 6d 75 at the thread mu
7f40: 73 74 20 61 6c 73 6f 20 62 65 0a 2a 2a 20 68 6f st also be.** ho
7f50: 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f 6e lding a mutex on
7f60: 20 74 68 65 20 73 71 6c 69 74 65 33 20 63 6f 6e the sqlite3 con
7f70: 6e 65 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 20 nection pointer
7f80: 74 68 61 74 20 6f 77 6e 73 20 74 68 65 20 42 74 that owns the Bt
7f90: 72 65 65 2e 0a 2a 2a 20 46 6f 72 20 61 20 54 45 ree..** For a TE
7fa0: 4d 50 20 53 63 68 65 6d 61 2c 20 6f 6e 6c 79 20 MP Schema, only
7fb0: 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 6d the connection m
7fc0: 75 74 65 78 20 69 73 20 72 65 71 75 69 72 65 64 utex is required
7fd0: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 63 68 65 ..*/.struct Sche
7fe0: 6d 61 20 7b 0a 20 20 69 6e 74 20 73 63 68 65 6d ma {. int schem
7ff0: 61 5f 63 6f 6f 6b 69 65 3b 20 20 20 2f 2a 20 44 a_cookie; /* D
8000: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 76 atabase schema v
8010: 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 66 6f ersion number fo
8020: 72 20 74 68 69 73 20 66 69 6c 65 20 2a 2f 0a 20 r this file */.
8030: 20 69 6e 74 20 69 47 65 6e 65 72 61 74 69 6f 6e int iGeneration
8040: 3b 20 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 74 ; /* Generat
8050: 69 6f 6e 20 63 6f 75 6e 74 65 72 2e 20 20 49 6e ion counter. In
8060: 63 72 65 6d 65 6e 74 65 64 20 77 69 74 68 20 65 cremented with e
8070: 61 63 68 20 63 68 61 6e 67 65 20 2a 2f 0a 20 20 ach change */.
8080: 48 61 73 68 20 74 62 6c 48 61 73 68 3b 20 20 20 Hash tblHash;
8090: 20 20 20 20 20 2f 2a 20 41 6c 6c 20 74 61 62 6c /* All tabl
80a0: 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 es indexed by na
80b0: 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 69 64 78 me */. Hash idx
80c0: 48 61 73 68 3b 20 20 20 20 20 20 20 20 2f 2a 20 Hash; /*
80d0: 41 6c 6c 20 28 6e 61 6d 65 64 29 20 69 6e 64 69 All (named) indi
80e0: 63 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e ces indexed by n
80f0: 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 74 72 ame */. Hash tr
8100: 69 67 48 61 73 68 3b 20 20 20 20 20 20 20 2f 2a igHash; /*
8110: 20 41 6c 6c 20 74 72 69 67 67 65 72 73 20 69 6e All triggers in
8120: 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a 2f dexed by name */
8130: 0a 20 20 48 61 73 68 20 66 6b 65 79 48 61 73 68 . Hash fkeyHash
8140: 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 66 ; /* All f
8150: 6f 72 65 69 67 6e 20 6b 65 79 73 20 62 79 20 72 oreign keys by r
8160: 65 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 eferenced table
8170: 6e 61 6d 65 20 2a 2f 0a 20 20 54 61 62 6c 65 20 name */. Table
8180: 2a 70 53 65 71 54 61 62 3b 20 20 20 20 20 20 2f *pSeqTab; /
8190: 2a 20 54 68 65 20 73 71 6c 69 74 65 5f 73 65 71 * The sqlite_seq
81a0: 75 65 6e 63 65 20 74 61 62 6c 65 20 75 73 65 64 uence table used
81b0: 20 62 79 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e by AUTOINCREMEN
81c0: 54 20 2a 2f 0a 20 20 75 38 20 66 69 6c 65 5f 66 T */. u8 file_f
81d0: 6f 72 6d 61 74 3b 20 20 20 20 20 20 2f 2a 20 53 ormat; /* S
81e0: 63 68 65 6d 61 20 66 6f 72 6d 61 74 20 76 65 72 chema format ver
81f0: 73 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 66 69 sion for this fi
8200: 6c 65 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 le */. u8 enc;
8210: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
8220: 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 75 73 Text encoding us
8230: 65 64 20 62 79 20 74 68 69 73 20 64 61 74 61 62 ed by this datab
8240: 61 73 65 20 2a 2f 0a 20 20 75 31 36 20 73 63 68 ase */. u16 sch
8250: 65 6d 61 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a emaFlags; /*
8260: 20 46 6c 61 67 73 20 61 73 73 6f 63 69 61 74 65 Flags associate
8270: 64 20 77 69 74 68 20 74 68 69 73 20 73 63 68 65 d with this sche
8280: 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 63 61 63 68 ma */. int cach
8290: 65 5f 73 69 7a 65 3b 20 20 20 20 20 20 2f 2a 20 e_size; /*
82a0: 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 20 Number of pages
82b0: 74 6f 20 75 73 65 20 69 6e 20 74 68 65 20 63 61 to use in the ca
82c0: 63 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a che */.};../*.**
82d0: 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 63 61 These macros ca
82e0: 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 65 73 n be used to tes
82f0: 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 t, set, or clear
8300: 20 62 69 74 73 20 69 6e 20 74 68 65 20 0a 2a 2a bits in the .**
8310: 20 44 62 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 Db.pSchema->fla
8320: 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 gs field..*/.#de
8330: 66 69 6e 65 20 44 62 48 61 73 50 72 6f 70 65 72 fine DbHasProper
8340: 74 79 28 44 2c 49 2c 50 29 20 20 20 20 20 28 28 ty(D,I,P) ((
8350: 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 (D)->aDb[I].pSch
8360: 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 ema->schemaFlags
8370: 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 &(P))==(P)).#def
8380: 69 6e 65 20 44 62 48 61 73 41 6e 79 50 72 6f 70 ine DbHasAnyProp
8390: 65 72 74 79 28 44 2c 49 2c 50 29 20 20 28 28 28 erty(D,I,P) (((
83a0: 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 D)->aDb[I].pSche
83b0: 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 ma->schemaFlags&
83c0: 28 50 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 (P))!=0).#define
83d0: 20 44 62 53 65 74 50 72 6f 70 65 72 74 79 28 44 DbSetProperty(D
83e0: 2c 49 2c 50 29 20 20 20 20 20 28 44 29 2d 3e 61 ,I,P) (D)->a
83f0: 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 Db[I].pSchema->s
8400: 63 68 65 6d 61 46 6c 61 67 73 7c 3d 28 50 29 0a chemaFlags|=(P).
8410: 23 64 65 66 69 6e 65 20 44 62 43 6c 65 61 72 50 #define DbClearP
8420: 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 roperty(D,I,P)
8430: 20 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 (D)->aDb[I].pSc
8440: 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 hema->schemaFlag
8450: 73 26 3d 7e 28 50 29 0a 0a 2f 2a 0a 2a 2a 20 41 s&=~(P)../*.** A
8460: 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f llowed values fo
8470: 72 20 74 68 65 20 44 42 2e 70 53 63 68 65 6d 61 r the DB.pSchema
8480: 2d 3e 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a ->flags field..*
8490: 2a 0a 2a 2a 20 54 68 65 20 44 42 5f 53 63 68 65 *.** The DB_Sche
84a0: 6d 61 4c 6f 61 64 65 64 20 66 6c 61 67 20 69 73 maLoaded flag is
84b0: 20 73 65 74 20 61 66 74 65 72 20 74 68 65 20 64 set after the d
84c0: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 68 atabase schema h
84d0: 61 73 20 62 65 65 6e 0a 2a 2a 20 72 65 61 64 20 as been.** read
84e0: 69 6e 74 6f 20 69 6e 74 65 72 6e 61 6c 20 68 61 into internal ha
84f0: 73 68 20 74 61 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a sh tables..**.**
8500: 20 44 42 5f 55 6e 72 65 73 65 74 56 69 65 77 73 DB_UnresetViews
8510: 20 6d 65 61 6e 73 20 74 68 61 74 20 6f 6e 65 20 means that one
8520: 6f 72 20 6d 6f 72 65 20 76 69 65 77 73 20 68 61 or more views ha
8530: 76 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 ve column names
8540: 74 68 61 74 0a 2a 2a 20 68 61 76 65 20 62 65 65 that.** have bee
8550: 6e 20 66 69 6c 6c 65 64 20 6f 75 74 2e 20 20 49 n filled out. I
8560: 66 20 74 68 65 20 73 63 68 65 6d 61 20 63 68 61 f the schema cha
8570: 6e 67 65 73 2c 20 74 68 65 73 65 20 63 6f 6c 75 nges, these colu
8580: 6d 6e 20 6e 61 6d 65 73 20 6d 69 67 68 74 0a 2a mn names might.*
8590: 2a 20 63 68 61 6e 67 65 73 20 61 6e 64 20 73 6f * changes and so
85a0: 20 74 68 65 20 76 69 65 77 20 77 69 6c 6c 20 6e the view will n
85b0: 65 65 64 20 74 6f 20 62 65 20 72 65 73 65 74 2e eed to be reset.
85c0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 53 .*/.#define DB_S
85d0: 63 68 65 6d 61 4c 6f 61 64 65 64 20 20 20 20 30 chemaLoaded 0
85e0: 78 30 30 30 31 20 20 2f 2a 20 54 68 65 20 73 63 x0001 /* The sc
85f0: 68 65 6d 61 20 68 61 73 20 62 65 65 6e 20 6c 6f hema has been lo
8600: 61 64 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aded */.#define
8610: 44 42 5f 55 6e 72 65 73 65 74 56 69 65 77 73 20 DB_UnresetViews
8620: 20 20 20 30 78 30 30 30 32 20 20 2f 2a 20 53 6f 0x0002 /* So
8630: 6d 65 20 76 69 65 77 73 20 68 61 76 65 20 64 65 me views have de
8640: 66 69 6e 65 64 20 63 6f 6c 75 6d 6e 20 6e 61 6d fined column nam
8650: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 es */.#define DB
8660: 5f 45 6d 70 74 79 20 20 20 20 20 20 20 20 20 20 _Empty
8670: 20 30 78 30 30 30 34 20 20 2f 2a 20 54 68 65 20 0x0004 /* The
8680: 66 69 6c 65 20 69 73 20 65 6d 70 74 79 20 28 6c file is empty (l
8690: 65 6e 67 74 68 20 30 20 62 79 74 65 73 29 20 2a ength 0 bytes) *
86a0: 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d /../*.** The num
86b0: 62 65 72 20 6f 66 20 64 69 66 66 65 72 65 6e 74 ber of different
86c0: 20 6b 69 6e 64 73 20 6f 66 20 74 68 69 6e 67 73 kinds of things
86d0: 20 74 68 61 74 20 63 61 6e 20 62 65 20 6c 69 6d that can be lim
86e0: 69 74 65 64 0a 2a 2a 20 75 73 69 6e 67 20 74 68 ited.** using th
86f0: 65 20 73 71 6c 69 74 65 33 5f 6c 69 6d 69 74 28 e sqlite3_limit(
8700: 29 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a ) interface..*/.
8710: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e #define SQLITE_N
8720: 5f 4c 49 4d 49 54 20 28 53 51 4c 49 54 45 5f 4c _LIMIT (SQLITE_L
8730: 49 4d 49 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 IMIT_WORKER_THRE
8740: 41 44 53 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 4c 6f ADS+1)../*.** Lo
8750: 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 69 okaside malloc i
8760: 73 20 61 20 73 65 74 20 6f 66 20 66 69 78 65 64 s a set of fixed
8770: 2d 73 69 7a 65 20 62 75 66 66 65 72 73 20 74 68 -size buffers th
8780: 61 74 20 63 61 6e 20 62 65 20 75 73 65 64 0a 2a at can be used.*
8790: 2a 20 74 6f 20 73 61 74 69 73 66 79 20 73 6d 61 * to satisfy sma
87a0: 6c 6c 20 74 72 61 6e 73 69 65 6e 74 20 6d 65 6d ll transient mem
87b0: 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 72 ory allocation r
87c0: 65 71 75 65 73 74 73 20 66 6f 72 20 6f 62 6a 65 equests for obje
87d0: 63 74 73 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65 cts.** associate
87e0: 64 20 77 69 74 68 20 61 20 70 61 72 74 69 63 75 d with a particu
87f0: 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e lar database con
8800: 6e 65 63 74 69 6f 6e 2e 20 20 54 68 65 20 75 73 nection. The us
8810: 65 20 6f 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 e of.** lookasid
8820: 65 20 6d 61 6c 6c 6f 63 20 70 72 6f 76 69 64 65 e malloc provide
8830: 73 20 61 20 73 69 67 6e 69 66 69 63 61 6e 74 20 s a significant
8840: 70 65 72 66 6f 72 6d 61 6e 63 65 20 65 6e 68 61 performance enha
8850: 6e 63 65 6d 65 6e 74 0a 2a 2a 20 28 61 70 70 72 ncement.** (appr
8860: 6f 78 20 31 30 25 29 20 62 79 20 61 76 6f 69 64 ox 10%) by avoid
8870: 69 6e 67 20 6e 75 6d 65 72 6f 75 73 20 6d 61 6c ing numerous mal
8880: 6c 6f 63 2f 66 72 65 65 20 72 65 71 75 65 73 74 loc/free request
8890: 73 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a s while parsing.
88a0: 2a 2a 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 ** SQL statement
88b0: 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 6f s..**.** The Loo
88c0: 6b 61 73 69 64 65 20 73 74 72 75 63 74 75 72 65 kaside structure
88d0: 20 68 6f 6c 64 73 20 63 6f 6e 66 69 67 75 72 61 holds configura
88e0: 74 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e tion information
88f0: 20 61 62 6f 75 74 20 74 68 65 0a 2a 2a 20 6c 6f about the.** lo
8900: 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 73 okaside malloc s
8910: 75 62 73 79 73 74 65 6d 2e 20 20 45 61 63 68 20 ubsystem. Each
8920: 61 76 61 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 available memory
8930: 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e 0a 2a allocation in.*
8940: 2a 20 74 68 65 20 6c 6f 6f 6b 61 73 69 64 65 20 * the lookaside
8950: 73 75 62 73 79 73 74 65 6d 20 69 73 20 73 74 6f subsystem is sto
8960: 72 65 64 20 6f 6e 20 61 20 6c 69 6e 6b 65 64 20 red on a linked
8970: 6c 69 73 74 20 6f 66 20 4c 6f 6f 6b 61 73 69 64 list of Lookasid
8980: 65 53 6c 6f 74 0a 2a 2a 20 6f 62 6a 65 63 74 73 eSlot.** objects
8990: 2e 0a 2a 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 64 ..**.** Lookasid
89a0: 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 e allocations ar
89b0: 65 20 6f 6e 6c 79 20 61 6c 6c 6f 77 65 64 20 66 e only allowed f
89c0: 6f 72 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 or objects that
89d0: 61 72 65 20 61 73 73 6f 63 69 61 74 65 64 0a 2a are associated.*
89e0: 2a 20 77 69 74 68 20 61 20 70 61 72 74 69 63 75 * with a particu
89f0: 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e lar database con
8a00: 6e 65 63 74 69 6f 6e 2e 20 20 48 65 6e 63 65 2c nection. Hence,
8a10: 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 schema informat
8a20: 69 6f 6e 20 63 61 6e 6e 6f 74 0a 2a 2a 20 62 65 ion cannot.** be
8a30: 20 73 74 6f 72 65 64 20 69 6e 20 6c 6f 6f 6b 61 stored in looka
8a40: 73 69 64 65 20 62 65 63 61 75 73 65 20 69 6e 20 side because in
8a50: 73 68 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 shared cache mod
8a60: 65 20 74 68 65 20 73 63 68 65 6d 61 20 69 6e 66 e the schema inf
8a70: 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 69 73 20 73 ormation.** is s
8a80: 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 70 6c hared by multipl
8a90: 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 e database conne
8aa0: 63 74 69 6f 6e 73 2e 20 20 54 68 65 72 65 66 6f ctions. Therefo
8ab0: 72 65 2c 20 77 68 69 6c 65 20 70 61 72 73 69 6e re, while parsin
8ac0: 67 0a 2a 2a 20 73 63 68 65 6d 61 20 69 6e 66 6f g.** schema info
8ad0: 72 6d 61 74 69 6f 6e 2c 20 74 68 65 20 4c 6f 6f rmation, the Loo
8ae0: 6b 61 73 69 64 65 2e 62 45 6e 61 62 6c 65 64 20 kaside.bEnabled
8af0: 66 6c 61 67 20 69 73 20 63 6c 65 61 72 65 64 20 flag is cleared
8b00: 73 6f 20 74 68 61 74 0a 2a 2a 20 6c 6f 6f 6b 61 so that.** looka
8b10: 73 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 side allocations
8b20: 20 61 72 65 20 6e 6f 74 20 75 73 65 64 20 74 6f are not used to
8b30: 20 63 6f 6e 73 74 72 75 63 74 20 74 68 65 20 73 construct the s
8b40: 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 2e 0a 2a chema objects..*
8b50: 2f 0a 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 /.struct Lookasi
8b60: 64 65 20 7b 0a 20 20 75 31 36 20 73 7a 3b 20 20 de {. u16 sz;
8b70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
8b80: 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 20 62 * Size of each b
8b90: 75 66 66 65 72 20 69 6e 20 62 79 74 65 73 20 2a uffer in bytes *
8ba0: 2f 0a 20 20 75 38 20 62 45 6e 61 62 6c 65 64 3b /. u8 bEnabled;
8bb0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 /* F
8bc0: 61 6c 73 65 20 74 6f 20 64 69 73 61 62 6c 65 20 alse to disable
8bd0: 6e 65 77 20 6c 6f 6f 6b 61 73 69 64 65 20 61 6c new lookaside al
8be0: 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 75 locations */. u
8bf0: 38 20 62 4d 61 6c 6c 6f 63 65 64 3b 20 20 20 20 8 bMalloced;
8c00: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
8c10: 66 20 70 53 74 61 72 74 20 6f 62 74 61 69 6e 65 f pStart obtaine
8c20: 64 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 5f 6d d from sqlite3_m
8c30: 61 6c 6c 6f 63 28 29 20 2a 2f 0a 20 20 69 6e 74 alloc() */. int
8c40: 20 6e 4f 75 74 3b 20 20 20 20 20 20 20 20 20 20 nOut;
8c50: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
8c60: 66 20 62 75 66 66 65 72 73 20 63 75 72 72 65 6e f buffers curren
8c70: 74 6c 79 20 63 68 65 63 6b 65 64 20 6f 75 74 20 tly checked out
8c80: 2a 2f 0a 20 20 69 6e 74 20 6d 78 4f 75 74 3b 20 */. int mxOut;
8c90: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
8ca0: 48 69 67 68 77 61 74 65 72 20 6d 61 72 6b 20 66 Highwater mark f
8cb0: 6f 72 20 6e 4f 75 74 20 2a 2f 0a 20 20 69 6e 74 or nOut */. int
8cc0: 20 61 6e 53 74 61 74 5b 33 5d 3b 20 20 20 20 20 anStat[3];
8cd0: 20 20 20 20 20 2f 2a 20 30 3a 20 68 69 74 73 2e /* 0: hits.
8ce0: 20 20 31 3a 20 73 69 7a 65 20 6d 69 73 73 65 73 1: size misses
8cf0: 2e 20 20 32 3a 20 66 75 6c 6c 20 6d 69 73 73 65 . 2: full misse
8d00: 73 20 2a 2f 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 s */. Lookaside
8d10: 53 6c 6f 74 20 2a 70 46 72 65 65 3b 20 20 20 2f Slot *pFree; /
8d20: 2a 20 4c 69 73 74 20 6f 66 20 61 76 61 69 6c 61 * List of availa
8d30: 62 6c 65 20 62 75 66 66 65 72 73 20 2a 2f 0a 20 ble buffers */.
8d40: 20 76 6f 69 64 20 2a 70 53 74 61 72 74 3b 20 20 void *pStart;
8d50: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
8d60: 74 20 62 79 74 65 20 6f 66 20 61 76 61 69 6c 61 t byte of availa
8d70: 62 6c 65 20 6d 65 6d 6f 72 79 20 73 70 61 63 65 ble memory space
8d80: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 45 6e 64 */. void *pEnd
8d90: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
8da0: 20 46 69 72 73 74 20 62 79 74 65 20 70 61 73 74 First byte past
8db0: 20 65 6e 64 20 6f 66 20 61 76 61 69 6c 61 62 6c end of availabl
8dc0: 65 20 73 70 61 63 65 20 2a 2f 0a 7d 3b 0a 73 74 e space */.};.st
8dd0: 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 53 6c ruct LookasideSl
8de0: 6f 74 20 7b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 ot {. Lookaside
8df0: 53 6c 6f 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 Slot *pNext;
8e00: 2f 2a 20 4e 65 78 74 20 62 75 66 66 65 72 20 69 /* Next buffer i
8e10: 6e 20 74 68 65 20 6c 69 73 74 20 6f 66 20 66 72 n the list of fr
8e20: 65 65 20 62 75 66 66 65 72 73 20 2a 2f 0a 7d 3b ee buffers */.};
8e30: 0a 0a 2f 2a 0a 2a 2a 20 41 20 68 61 73 68 20 74 ../*.** A hash t
8e40: 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 69 6f able for functio
8e50: 6e 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e 0a 2a n definitions..*
8e60: 2a 0a 2a 2a 20 48 61 73 68 20 65 61 63 68 20 46 *.** Hash each F
8e70: 75 6e 63 44 65 66 20 73 74 72 75 63 74 75 72 65 uncDef structure
8e80: 20 69 6e 74 6f 20 6f 6e 65 20 6f 66 20 74 68 65 into one of the
8e90: 20 46 75 6e 63 44 65 66 48 61 73 68 2e 61 5b 5d FuncDefHash.a[]
8ea0: 20 73 6c 6f 74 73 2e 0a 2a 2a 20 43 6f 6c 6c 69 slots..** Colli
8eb0: 73 69 6f 6e 73 20 61 72 65 20 6f 6e 20 74 68 65 sions are on the
8ec0: 20 46 75 6e 63 44 65 66 2e 70 48 61 73 68 20 63 FuncDef.pHash c
8ed0: 68 61 69 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 hain..*/.struct
8ee0: 46 75 6e 63 44 65 66 48 61 73 68 20 7b 0a 20 20 FuncDefHash {.
8ef0: 46 75 6e 63 44 65 66 20 2a 61 5b 32 33 5d 3b 20 FuncDef *a[23];
8f00: 20 20 20 20 20 20 2f 2a 20 48 61 73 68 20 74 61 /* Hash ta
8f10: 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e ble for function
8f20: 73 20 2a 2f 0a 7d 3b 0a 0a 23 69 66 64 65 66 20 s */.};..#ifdef
8f30: 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 SQLITE_USER_AUTH
8f40: 45 4e 54 49 43 41 54 49 4f 4e 0a 2f 2a 0a 2a 2a ENTICATION./*.**
8f50: 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 68 65 6c Information hel
8f60: 64 20 69 6e 20 74 68 65 20 22 73 71 6c 69 74 65 d in the "sqlite
8f70: 33 22 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 3" database conn
8f80: 65 63 74 69 6f 6e 20 6f 62 6a 65 63 74 20 61 6e ection object an
8f90: 64 20 75 73 65 64 0a 2a 2a 20 74 6f 20 6d 61 6e d used.** to man
8fa0: 61 67 65 20 75 73 65 72 20 61 75 74 68 65 6e 74 age user authent
8fb0: 69 63 61 74 69 6f 6e 2e 0a 2a 2f 0a 74 79 70 65 ication..*/.type
8fc0: 64 65 66 20 73 74 72 75 63 74 20 73 71 6c 69 74 def struct sqlit
8fd0: 65 33 5f 75 73 65 72 61 75 74 68 20 73 71 6c 69 e3_userauth sqli
8fe0: 74 65 33 5f 75 73 65 72 61 75 74 68 3b 0a 73 74 te3_userauth;.st
8ff0: 72 75 63 74 20 73 71 6c 69 74 65 33 5f 75 73 65 ruct sqlite3_use
9000: 72 61 75 74 68 20 7b 0a 20 20 75 38 20 61 75 74 rauth {. u8 aut
9010: 68 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 20 20 hLevel;
9020: 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 /* Curre
9030: 6e 74 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f nt authenticatio
9040: 6e 20 6c 65 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 n level */. int
9050: 20 6e 41 75 74 68 50 57 3b 20 20 20 20 20 20 20 nAuthPW;
9060: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 /* Si
9070: 7a 65 20 6f 66 20 74 68 65 20 7a 41 75 74 68 50 ze of the zAuthP
9080: 57 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 W in bytes */.
9090: 63 68 61 72 20 2a 7a 41 75 74 68 50 57 3b 20 20 char *zAuthPW;
90a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
90b0: 20 50 61 73 73 77 6f 72 64 20 75 73 65 64 20 74 Password used t
90c0: 6f 20 61 75 74 68 65 6e 74 69 63 61 74 65 20 2a o authenticate *
90d0: 2f 0a 20 20 63 68 61 72 20 2a 7a 41 75 74 68 55 /. char *zAuthU
90e0: 73 65 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 ser;
90f0: 20 20 2f 2a 20 55 73 65 72 20 6e 61 6d 65 20 75 /* User name u
9100: 73 65 64 20 74 6f 20 61 75 74 68 65 6e 74 69 63 sed to authentic
9110: 61 74 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c ate */.};../* Al
9120: 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 lowed values for
9130: 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 sqlite3_useraut
9140: 68 2e 61 75 74 68 4c 65 76 65 6c 20 2a 2f 0a 23 h.authLevel */.#
9150: 64 65 66 69 6e 65 20 55 41 55 54 48 5f 55 6e 6b define UAUTH_Unk
9160: 6e 6f 77 6e 20 20 20 20 20 30 20 20 20 20 20 2f nown 0 /
9170: 2a 20 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e * Authentication
9180: 20 6e 6f 74 20 79 65 74 20 63 68 65 63 6b 65 64 not yet checked
9190: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 54 */.#define UAUT
91a0: 48 5f 46 61 69 6c 20 20 20 20 20 20 20 20 31 20 H_Fail 1
91b0: 20 20 20 20 2f 2a 20 55 73 65 72 20 61 75 74 68 /* User auth
91c0: 65 6e 74 69 63 61 74 69 6f 6e 20 66 61 69 6c 65 entication faile
91d0: 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 d */.#define UAU
91e0: 54 48 5f 55 73 65 72 20 20 20 20 20 20 20 20 32 TH_User 2
91f0: 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 /* Authenti
9200: 63 61 74 65 64 20 61 73 20 61 20 6e 6f 72 6d 61 cated as a norma
9210: 6c 20 75 73 65 72 20 2a 2f 0a 23 64 65 66 69 6e l user */.#defin
9220: 65 20 55 41 55 54 48 5f 41 64 6d 69 6e 20 20 20 e UAUTH_Admin
9230: 20 20 20 20 33 20 20 20 20 20 2f 2a 20 41 75 74 3 /* Aut
9240: 68 65 6e 74 69 63 61 74 65 64 20 61 73 20 61 6e henticated as an
9250: 20 61 64 6d 69 6e 69 73 74 72 61 74 6f 72 20 2a administrator *
9260: 2f 0a 0a 2f 2a 20 46 75 6e 63 74 69 6f 6e 73 20 /../* Functions
9270: 75 73 65 64 20 6f 6e 6c 79 20 62 79 20 75 73 65 used only by use
9280: 72 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 r authorization
9290: 6c 6f 67 69 63 20 2a 2f 0a 69 6e 74 20 73 71 6c logic */.int sql
92a0: 69 74 65 33 55 73 65 72 41 75 74 68 54 61 62 6c ite3UserAuthTabl
92b0: 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a e(const char*);.
92c0: 69 6e 74 20 73 71 6c 69 74 65 33 55 73 65 72 41 int sqlite3UserA
92d0: 75 74 68 43 68 65 63 6b 4c 6f 67 69 6e 28 73 71 uthCheckLogin(sq
92e0: 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
92f0: 72 2a 2c 75 38 2a 29 3b 0a 76 6f 69 64 20 73 71 r*,u8*);.void sq
9300: 6c 69 74 65 33 55 73 65 72 41 75 74 68 49 6e 69 lite3UserAuthIni
9310: 74 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 t(sqlite3*);.voi
9320: 64 20 73 71 6c 69 74 65 33 43 72 79 70 74 46 75 d sqlite3CryptFu
9330: 6e 63 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 nc(sqlite3_conte
9340: 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f xt*,int,sqlite3_
9350: 76 61 6c 75 65 2a 2a 29 3b 0a 0a 23 65 6e 64 69 value**);..#endi
9360: 66 20 2f 2a 20 53 51 4c 49 54 45 5f 55 53 45 52 f /* SQLITE_USER
9370: 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 20 _AUTHENTICATION
9380: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 74 79 70 65 64 65 */../*.** typede
9390: 66 20 66 6f 72 20 74 68 65 20 61 75 74 68 6f 72 f for the author
93a0: 69 7a 61 74 69 6f 6e 20 63 61 6c 6c 62 61 63 6b ization callback
93b0: 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 function..*/.#i
93c0: 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 52 fdef SQLITE_USER
93d0: 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a _AUTHENTICATION.
93e0: 20 20 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a typedef int (*
93f0: 73 71 6c 69 74 65 33 5f 78 61 75 74 68 29 28 76 sqlite3_xauth)(v
9400: 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 oid*,int,const c
9410: 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
9420: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 0a 20 20 ,const char*,.
9430: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9440: 20 20 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e con
9450: 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
9460: 63 68 61 72 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 char*);.#else.
9470: 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a 73 71 typedef int (*sq
9480: 6c 69 74 65 33 5f 78 61 75 74 68 29 28 76 6f 69 lite3_xauth)(voi
9490: 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 d*,int,const cha
94a0: 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 r*,const char*,c
94b0: 6f 6e 73 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 onst char*,.
94c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
94d0: 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 const
94e0: 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a char*);.#endif.
94f0: 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 64 61 74 ../*.** Each dat
9500: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
9510: 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 is an instance
9520: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
9530: 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 structure..*/.s
9540: 74 72 75 63 74 20 73 71 6c 69 74 65 33 20 7b 0a truct sqlite3 {.
9550: 20 20 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 70 sqlite3_vfs *p
9560: 56 66 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 Vfs;
9570: 2f 2a 20 4f 53 20 49 6e 74 65 72 66 61 63 65 20 /* OS Interface
9580: 2a 2f 0a 20 20 73 74 72 75 63 74 20 56 64 62 65 */. struct Vdbe
9590: 20 2a 70 56 64 62 65 3b 20 20 20 20 20 20 20 20 *pVdbe;
95a0: 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 63 /* List of ac
95b0: 74 69 76 65 20 76 69 72 74 75 61 6c 20 6d 61 63 tive virtual mac
95c0: 68 69 6e 65 73 20 2a 2f 0a 20 20 43 6f 6c 6c 53 hines */. CollS
95d0: 65 71 20 2a 70 44 66 6c 74 43 6f 6c 6c 3b 20 20 eq *pDfltColl;
95e0: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
95f0: 64 65 66 61 75 6c 74 20 63 6f 6c 6c 61 74 69 6e default collatin
9600: 67 20 73 65 71 75 65 6e 63 65 20 28 42 49 4e 41 g sequence (BINA
9610: 52 59 29 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 RY) */. sqlite3
9620: 5f 6d 75 74 65 78 20 2a 6d 75 74 65 78 3b 20 20 _mutex *mutex;
9630: 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 6e 65 63 /* Connec
9640: 74 69 6f 6e 20 6d 75 74 65 78 20 2a 2f 0a 20 20 tion mutex */.
9650: 44 62 20 2a 61 44 62 3b 20 20 20 20 20 20 20 20 Db *aDb;
9660: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9670: 20 41 6c 6c 20 62 61 63 6b 65 6e 64 73 20 2a 2f All backends */
9680: 0a 20 20 69 6e 74 20 6e 44 62 3b 20 20 20 20 20 . int nDb;
9690: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
96a0: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 62 61 /* Number of ba
96b0: 63 6b 65 6e 64 73 20 63 75 72 72 65 6e 74 6c 79 ckends currently
96c0: 20 69 6e 20 75 73 65 20 2a 2f 0a 20 20 69 6e 74 in use */. int
96d0: 20 66 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 flags;
96e0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 69 /* Mi
96f0: 73 63 65 6c 6c 61 6e 65 6f 75 73 20 66 6c 61 67 scellaneous flag
9700: 73 2e 20 53 65 65 20 62 65 6c 6f 77 20 2a 2f 0a s. See below */.
9710: 20 20 69 36 34 20 6c 61 73 74 52 6f 77 69 64 3b i64 lastRowid;
9720: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9730: 2f 2a 20 52 4f 57 49 44 20 6f 66 20 6d 6f 73 74 /* ROWID of most
9740: 20 72 65 63 65 6e 74 20 69 6e 73 65 72 74 20 28 recent insert (
9750: 73 65 65 20 61 62 6f 76 65 29 20 2a 2f 0a 20 20 see above) */.
9760: 69 36 34 20 73 7a 4d 6d 61 70 3b 20 20 20 20 20 i64 szMmap;
9770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9780: 20 44 65 66 61 75 6c 74 20 6d 6d 61 70 5f 73 69 Default mmap_si
9790: 7a 65 20 73 65 74 74 69 6e 67 20 2a 2f 0a 20 20 ze setting */.
97a0: 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6f 70 65 unsigned int ope
97b0: 6e 46 6c 61 67 73 3b 20 20 20 20 20 20 20 2f 2a nFlags; /*
97c0: 20 46 6c 61 67 73 20 70 61 73 73 65 64 20 74 6f Flags passed to
97d0: 20 73 71 6c 69 74 65 33 5f 76 66 73 2e 78 4f 70 sqlite3_vfs.xOp
97e0: 65 6e 28 29 20 2a 2f 0a 20 20 69 6e 74 20 65 72 en() */. int er
97f0: 72 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 rCode;
9800: 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f 73 74 20 /* Most
9810: 72 65 63 65 6e 74 20 65 72 72 6f 72 20 63 6f 64 recent error cod
9820: 65 20 28 53 51 4c 49 54 45 5f 2a 29 20 2a 2f 0a e (SQLITE_*) */.
9830: 20 20 69 6e 74 20 65 72 72 4d 61 73 6b 3b 20 20 int errMask;
9840: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9850: 2f 2a 20 26 20 72 65 73 75 6c 74 20 63 6f 64 65 /* & result code
9860: 73 20 77 69 74 68 20 74 68 69 73 20 62 65 66 6f s with this befo
9870: 72 65 20 72 65 74 75 72 6e 69 6e 67 20 2a 2f 0a re returning */.
9880: 20 20 75 31 36 20 64 62 4f 70 74 46 6c 61 67 73 u16 dbOptFlags
9890: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
98a0: 2f 2a 20 46 6c 61 67 73 20 74 6f 20 65 6e 61 62 /* Flags to enab
98b0: 6c 65 2f 64 69 73 61 62 6c 65 20 6f 70 74 69 6d le/disable optim
98c0: 69 7a 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 75 38 izations */. u8
98d0: 20 65 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 enc;
98e0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
98f0: 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 2a 2f 0a ext encoding */.
9900: 20 20 75 38 20 61 75 74 6f 43 6f 6d 6d 69 74 3b u8 autoCommit;
9910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9920: 2f 2a 20 54 68 65 20 61 75 74 6f 2d 63 6f 6d 6d /* The auto-comm
9930: 69 74 20 66 6c 61 67 2e 20 2a 2f 0a 20 20 75 38 it flag. */. u8
9940: 20 74 65 6d 70 5f 73 74 6f 72 65 3b 20 20 20 20 temp_store;
9950: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 /* 1
9960: 3a 20 66 69 6c 65 20 32 3a 20 6d 65 6d 6f 72 79 : file 2: memory
9970: 20 30 3a 20 64 65 66 61 75 6c 74 20 2a 2f 0a 20 0: default */.
9980: 20 75 38 20 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 u8 mallocFailed
9990: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
99a0: 2a 20 54 72 75 65 20 69 66 20 77 65 20 68 61 76 * True if we hav
99b0: 65 20 73 65 65 6e 20 61 20 6d 61 6c 6c 6f 63 20 e seen a malloc
99c0: 66 61 69 6c 75 72 65 20 2a 2f 0a 20 20 75 38 20 failure */. u8
99d0: 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 3b 20 20 20 dfltLockMode;
99e0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 /* De
99f0: 66 61 75 6c 74 20 6c 6f 63 6b 69 6e 67 2d 6d 6f fault locking-mo
9a00: 64 65 20 66 6f 72 20 61 74 74 61 63 68 65 64 20 de for attached
9a10: 64 62 73 20 2a 2f 0a 20 20 73 69 67 6e 65 64 20 dbs */. signed
9a20: 63 68 61 72 20 6e 65 78 74 41 75 74 6f 76 61 63 char nextAutovac
9a30: 3b 20 20 20 20 20 20 2f 2a 20 41 75 74 6f 76 61 ; /* Autova
9a40: 63 20 73 65 74 74 69 6e 67 20 61 66 74 65 72 20 c setting after
9a50: 56 41 43 55 55 4d 20 69 66 20 3e 3d 30 20 2a 2f VACUUM if >=0 */
9a60: 0a 20 20 75 38 20 73 75 70 70 72 65 73 73 45 72 . u8 suppressEr
9a70: 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
9a80: 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 73 73 75 65 /* Do not issue
9a90: 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 error messages
9aa0: 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 20 if true */. u8
9ab0: 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 63 74 3b 20 vtabOnConflict;
9ac0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 /* Va
9ad0: 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 66 6f lue to return fo
9ae0: 72 20 73 33 5f 76 74 61 62 5f 6f 6e 5f 63 6f 6e r s3_vtab_on_con
9af0: 66 6c 69 63 74 28 29 20 2a 2f 0a 20 20 75 38 20 flict() */. u8
9b00: 69 73 54 72 61 6e 73 61 63 74 69 6f 6e 53 61 76 isTransactionSav
9b10: 65 70 6f 69 6e 74 3b 20 20 20 20 2f 2a 20 54 72 epoint; /* Tr
9b20: 75 65 20 69 66 20 74 68 65 20 6f 75 74 65 72 6d ue if the outerm
9b30: 6f 73 74 20 73 61 76 65 70 6f 69 6e 74 20 69 73 ost savepoint is
9b40: 20 61 20 54 53 20 2a 2f 0a 20 20 69 6e 74 20 6e a TS */. int n
9b50: 65 78 74 50 61 67 65 73 69 7a 65 3b 20 20 20 20 extPagesize;
9b60: 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 67 65 /* Page
9b70: 73 69 7a 65 20 61 66 74 65 72 20 56 41 43 55 55 size after VACUU
9b80: 4d 20 69 66 20 3e 30 20 2a 2f 0a 20 20 75 33 32 M if >0 */. u32
9b90: 20 6d 61 67 69 63 3b 20 20 20 20 20 20 20 20 20 magic;
9ba0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 /* Ma
9bb0: 67 69 63 20 6e 75 6d 62 65 72 20 66 6f 72 20 64 gic number for d
9bc0: 65 74 65 63 74 20 6c 69 62 72 61 72 79 20 6d 69 etect library mi
9bd0: 73 75 73 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 suse */. int nC
9be0: 68 61 6e 67 65 3b 20 20 20 20 20 20 20 20 20 20 hange;
9bf0: 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 /* Value
9c00: 20 72 65 74 75 72 6e 65 64 20 62 79 20 73 71 6c returned by sql
9c10: 69 74 65 33 5f 63 68 61 6e 67 65 73 28 29 20 2a ite3_changes() *
9c20: 2f 0a 20 20 69 6e 74 20 6e 54 6f 74 61 6c 43 68 /. int nTotalCh
9c30: 61 6e 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 ange;
9c40: 20 20 2f 2a 20 56 61 6c 75 65 20 72 65 74 75 72 /* Value retur
9c50: 6e 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f 74 ned by sqlite3_t
9c60: 6f 74 61 6c 5f 63 68 61 6e 67 65 73 28 29 20 2a otal_changes() *
9c70: 2f 0a 20 20 69 6e 74 20 61 4c 69 6d 69 74 5b 53 /. int aLimit[S
9c80: 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 54 5d 3b 20 QLITE_N_LIMIT];
9c90: 20 20 2f 2a 20 4c 69 6d 69 74 73 20 2a 2f 0a 20 /* Limits */.
9ca0: 20 69 6e 74 20 6e 4d 61 78 53 6f 72 74 65 72 4d int nMaxSorterM
9cb0: 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 2f map; /
9cc0: 2a 20 4d 61 78 69 6d 75 6d 20 73 69 7a 65 20 6f * Maximum size o
9cd0: 66 20 72 65 67 69 6f 6e 73 20 6d 61 70 70 65 64 f regions mapped
9ce0: 20 62 79 20 73 6f 72 74 65 72 20 2a 2f 0a 20 20 by sorter */.
9cf0: 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 49 6e struct sqlite3In
9d00: 69 74 49 6e 66 6f 20 7b 20 20 20 20 20 20 2f 2a itInfo { /*
9d10: 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 73 65 Information use
9d20: 64 20 64 75 72 69 6e 67 20 69 6e 69 74 69 61 6c d during initial
9d30: 69 7a 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 ization */. i
9d40: 6e 74 20 6e 65 77 54 6e 75 6d 3b 20 20 20 20 20 nt newTnum;
9d50: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 6f /* Ro
9d60: 6f 74 70 61 67 65 20 6f 66 20 74 61 62 6c 65 20 otpage of table
9d70: 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 65 being initialize
9d80: 64 20 2a 2f 0a 20 20 20 20 75 38 20 69 44 62 3b d */. u8 iDb;
9d90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9da0: 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 64 62 /* Which db
9db0: 20 66 69 6c 65 20 69 73 20 62 65 69 6e 67 20 69 file is being i
9dc0: 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 nitialized */.
9dd0: 20 20 75 38 20 62 75 73 79 3b 20 20 20 20 20 20 u8 busy;
9de0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
9df0: 20 54 52 55 45 20 69 66 20 63 75 72 72 65 6e 74 TRUE if current
9e00: 6c 79 20 69 6e 69 74 69 61 6c 69 7a 69 6e 67 20 ly initializing
9e10: 2a 2f 0a 20 20 20 20 75 38 20 6f 72 70 68 61 6e */. u8 orphan
9e20: 54 72 69 67 67 65 72 3b 20 20 20 20 20 20 20 20 Trigger;
9e30: 20 20 20 2f 2a 20 4c 61 73 74 20 73 74 61 74 65 /* Last state
9e40: 6d 65 6e 74 20 69 73 20 6f 72 70 68 61 6e 65 64 ment is orphaned
9e50: 20 54 45 4d 50 20 74 72 69 67 67 65 72 20 2a 2f TEMP trigger */
9e60: 0a 20 20 20 20 75 38 20 69 6d 70 6f 73 74 65 72 . u8 imposter
9e70: 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 20 Table;
9e80: 20 2f 2a 20 42 75 69 6c 64 69 6e 67 20 61 6e 20 /* Building an
9e90: 69 6d 70 6f 73 74 65 72 20 74 61 62 6c 65 20 2a imposter table *
9ea0: 2f 0a 20 20 7d 20 69 6e 69 74 3b 0a 20 20 69 6e /. } init;. in
9eb0: 74 20 6e 56 64 62 65 41 63 74 69 76 65 3b 20 20 t nVdbeActive;
9ec0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
9ed0: 75 6d 62 65 72 20 6f 66 20 56 44 42 45 73 20 63 umber of VDBEs c
9ee0: 75 72 72 65 6e 74 6c 79 20 72 75 6e 6e 69 6e 67 urrently running
9ef0: 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 62 65 52 */. int nVdbeR
9f00: 65 61 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 ead;
9f10: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
9f20: 20 61 63 74 69 76 65 20 56 44 42 45 73 20 74 68 active VDBEs th
9f30: 61 74 20 72 65 61 64 20 6f 72 20 77 72 69 74 65 at read or write
9f40: 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 62 65 57 */. int nVdbeW
9f50: 72 69 74 65 3b 20 20 20 20 20 20 20 20 20 20 20 rite;
9f60: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
9f70: 20 61 63 74 69 76 65 20 56 44 42 45 73 20 74 68 active VDBEs th
9f80: 61 74 20 72 65 61 64 20 61 6e 64 20 77 72 69 74 at read and writ
9f90: 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 64 62 65 e */. int nVdbe
9fa0: 45 78 65 63 3b 20 20 20 20 20 20 20 20 20 20 20 Exec;
9fb0: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
9fc0: 66 20 6e 65 73 74 65 64 20 63 61 6c 6c 73 20 74 f nested calls t
9fd0: 6f 20 56 64 62 65 45 78 65 63 28 29 20 2a 2f 0a o VdbeExec() */.
9fe0: 20 20 69 6e 74 20 6e 56 44 65 73 74 72 6f 79 3b int nVDestroy;
9ff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a000: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 /* Number of act
a010: 69 76 65 20 4f 50 5f 56 44 65 73 74 72 6f 79 20 ive OP_VDestroy
a020: 6f 70 65 72 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 operations */.
a030: 69 6e 74 20 6e 45 78 74 65 6e 73 69 6f 6e 3b 20 int nExtension;
a040: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
a050: 20 4e 75 6d 62 65 72 20 6f 66 20 6c 6f 61 64 65 Number of loade
a060: 64 20 65 78 74 65 6e 73 69 6f 6e 73 20 2a 2f 0a d extensions */.
a070: 20 20 76 6f 69 64 20 2a 2a 61 45 78 74 65 6e 73 void **aExtens
a080: 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 ion;
a090: 2f 2a 20 41 72 72 61 79 20 6f 66 20 73 68 61 72 /* Array of shar
a0a0: 65 64 20 6c 69 62 72 61 72 79 20 68 61 6e 64 6c ed library handl
a0b0: 65 73 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 es */. void (*x
a0c0: 54 72 61 63 65 29 28 76 6f 69 64 2a 2c 63 6f 6e Trace)(void*,con
a0d0: 73 74 20 63 68 61 72 2a 29 3b 20 20 20 20 20 20 st char*);
a0e0: 20 20 2f 2a 20 54 72 61 63 65 20 66 75 6e 63 74 /* Trace funct
a0f0: 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ion */. void *p
a100: 54 72 61 63 65 41 72 67 3b 20 20 20 20 20 20 20 TraceArg;
a110: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a120: 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 /* Argument t
a130: 6f 20 74 68 65 20 74 72 61 63 65 20 66 75 6e 63 o the trace func
a140: 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 28 tion */. void (
a150: 2a 78 50 72 6f 66 69 6c 65 29 28 76 6f 69 64 2a *xProfile)(void*
a160: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 36 34 ,const char*,u64
a170: 29 3b 20 20 2f 2a 20 50 72 6f 66 69 6c 69 6e 67 ); /* Profiling
a180: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 function */. v
a190: 6f 69 64 20 2a 70 50 72 6f 66 69 6c 65 41 72 67 oid *pProfileArg
a1a0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
a1b0: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 /* Argu
a1c0: 6d 65 6e 74 20 74 6f 20 70 72 6f 66 69 6c 65 20 ment to profile
a1d0: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f function */. vo
a1e0: 69 64 20 2a 70 43 6f 6d 6d 69 74 41 72 67 3b 20 id *pCommitArg;
a1f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a200: 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 /* Argument to x
a210: 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b 28 29 CommitCallback()
a220: 20 2a 2f 20 20 20 0a 20 20 69 6e 74 20 28 2a 78 */ . int (*x
a230: 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b 29 28 CommitCallback)(
a240: 76 6f 69 64 2a 29 3b 20 20 20 20 2f 2a 20 49 6e void*); /* In
a250: 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 20 63 voked at every c
a260: 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 ommit. */. void
a270: 20 2a 70 52 6f 6c 6c 62 61 63 6b 41 72 67 3b 20 *pRollbackArg;
a280: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
a290: 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 52 6f Argument to xRo
a2a0: 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 6b 28 29 llbackCallback()
a2b0: 20 2a 2f 20 20 20 0a 20 20 76 6f 69 64 20 28 2a */ . void (*
a2c0: 78 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 xRollbackCallbac
a2d0: 6b 29 28 76 6f 69 64 2a 29 3b 20 2f 2a 20 49 6e k)(void*); /* In
a2e0: 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 20 63 voked at every c
a2f0: 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 ommit. */. void
a300: 20 2a 70 55 70 64 61 74 65 41 72 67 3b 0a 20 20 *pUpdateArg;.
a310: 76 6f 69 64 20 28 2a 78 55 70 64 61 74 65 43 61 void (*xUpdateCa
a320: 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 2c 69 6e llback)(void*,in
a330: 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 t, const char*,c
a340: 6f 6e 73 74 20 63 68 61 72 2a 2c 73 71 6c 69 74 onst char*,sqlit
a350: 65 5f 69 6e 74 36 34 29 3b 0a 23 69 66 64 65 66 e_int64);.#ifdef
a360: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 SQLITE_ENABLE_P
a370: 52 45 55 50 44 41 54 45 5f 48 4f 4f 4b 0a 20 20 REUPDATE_HOOK.
a380: 76 6f 69 64 20 2a 70 50 72 65 55 70 64 61 74 65 void *pPreUpdate
a390: 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 2f 2a Arg; /*
a3a0: 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 First argument
a3b0: 74 6f 20 78 50 72 65 55 70 64 61 74 65 43 61 6c to xPreUpdateCal
a3c0: 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 lback */. void
a3d0: 28 2a 78 50 72 65 55 70 64 61 74 65 43 61 6c 6c (*xPreUpdateCall
a3e0: 62 61 63 6b 29 28 20 20 20 2f 2a 20 52 65 67 69 back)( /* Regi
a3f0: 73 74 65 72 65 64 20 75 73 69 6e 67 20 73 71 6c stered using sql
a400: 69 74 65 33 5f 70 72 65 75 70 64 61 74 65 5f 68 ite3_preupdate_h
a410: 6f 6f 6b 28 29 20 2a 2f 0a 20 20 20 20 76 6f 69 ook() */. voi
a420: 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c d*,sqlite3*,int,
a430: 63 68 61 72 20 63 6f 6e 73 74 2a 2c 63 68 61 72 char const*,char
a440: 20 63 6f 6e 73 74 2a 2c 73 71 6c 69 74 65 33 5f const*,sqlite3_
a450: 69 6e 74 36 34 2c 73 71 6c 69 74 65 33 5f 69 6e int64,sqlite3_in
a460: 74 36 34 0a 20 20 29 3b 0a 20 20 50 72 65 55 70 t64. );. PreUp
a470: 64 61 74 65 20 2a 70 50 72 65 55 70 64 61 74 65 date *pPreUpdate
a480: 3b 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 74 ; /* Cont
a490: 65 78 74 20 66 6f 72 20 61 63 74 69 76 65 20 70 ext for active p
a4a0: 72 65 2d 75 70 64 61 74 65 20 63 61 6c 6c 62 61 re-update callba
a4b0: 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a 20 ck */.#endif /*
a4c0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 SQLITE_ENABLE_PR
a4d0: 45 55 50 44 41 54 45 5f 48 4f 4f 4b 20 2a 2f 0a EUPDATE_HOOK */.
a4e0: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
a4f0: 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 28 2a MIT_WAL. int (*
a500: 78 57 61 6c 43 61 6c 6c 62 61 63 6b 29 28 76 6f xWalCallback)(vo
a510: 69 64 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a 2c id *, sqlite3 *,
a520: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 const char *, i
a530: 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 57 61 nt);. void *pWa
a540: 6c 41 72 67 3b 0a 23 65 6e 64 69 66 0a 20 20 76 lArg;.#endif. v
a550: 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 oid(*xCollNeeded
a560: 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a )(void*,sqlite3*
a570: 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 6f ,int eTextRep,co
a580: 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f nst char*);. vo
a590: 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 31 id(*xCollNeeded1
a5a0: 36 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 6)(void*,sqlite3
a5b0: 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 *,int eTextRep,c
a5c0: 6f 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 76 onst void*);. v
a5d0: 6f 69 64 20 2a 70 43 6f 6c 6c 4e 65 65 64 65 64 oid *pCollNeeded
a5e0: 41 72 67 3b 0a 20 20 73 71 6c 69 74 65 33 5f 76 Arg;. sqlite3_v
a5f0: 61 6c 75 65 20 2a 70 45 72 72 3b 20 20 20 20 20 alue *pErr;
a600: 20 20 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 63 /* Most rec
a610: 65 6e 74 20 65 72 72 6f 72 20 6d 65 73 73 61 67 ent error messag
a620: 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 e */. union {.
a630: 20 20 20 76 6f 6c 61 74 69 6c 65 20 69 6e 74 20 volatile int
a640: 69 73 49 6e 74 65 72 72 75 70 74 65 64 3b 20 2f isInterrupted; /
a650: 2a 20 54 72 75 65 20 69 66 20 73 71 6c 69 74 65 * True if sqlite
a660: 33 5f 69 6e 74 65 72 72 75 70 74 20 68 61 73 20 3_interrupt has
a670: 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 been called */.
a680: 20 20 20 64 6f 75 62 6c 65 20 6e 6f 74 55 73 65 double notUse
a690: 64 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f d1; /
a6a0: 2a 20 53 70 61 63 65 72 20 2a 2f 0a 20 20 7d 20 * Spacer */. }
a6b0: 75 31 3b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 20 u1;. Lookaside
a6c0: 6c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 20 lookaside;
a6d0: 20 20 20 20 2f 2a 20 4c 6f 6f 6b 61 73 69 64 65 /* Lookaside
a6e0: 20 6d 61 6c 6c 6f 63 20 63 6f 6e 66 69 67 75 72 malloc configur
a6f0: 61 74 69 6f 6e 20 2a 2f 0a 23 69 66 6e 64 65 66 ation */.#ifndef
a700: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 54 SQLITE_OMIT_AUT
a710: 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 73 71 6c HORIZATION. sql
a720: 69 74 65 33 5f 78 61 75 74 68 20 78 41 75 74 68 ite3_xauth xAuth
a730: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 63 ; /* Ac
a740: 63 65 73 73 20 61 75 74 68 6f 72 69 7a 61 74 69 cess authorizati
a750: 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 on function */.
a760: 20 76 6f 69 64 20 2a 70 41 75 74 68 41 72 67 3b void *pAuthArg;
a770: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
a780: 2a 20 31 73 74 20 61 72 67 75 6d 65 6e 74 20 74 * 1st argument t
a790: 6f 20 74 68 65 20 61 63 63 65 73 73 20 61 75 74 o the access aut
a7a0: 68 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 65 h function */.#e
a7b0: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
a7c0: 49 54 45 5f 4f 4d 49 54 5f 50 52 4f 47 52 45 53 ITE_OMIT_PROGRES
a7d0: 53 5f 43 41 4c 4c 42 41 43 4b 0a 20 20 69 6e 74 S_CALLBACK. int
a7e0: 20 28 2a 78 50 72 6f 67 72 65 73 73 29 28 76 6f (*xProgress)(vo
a7f0: 69 64 20 2a 29 3b 20 20 20 20 20 2f 2a 20 54 68 id *); /* Th
a800: 65 20 70 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 e progress callb
a810: 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ack */. void *p
a820: 50 72 6f 67 72 65 73 73 41 72 67 3b 20 20 20 20 ProgressArg;
a830: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
a840: 6e 74 20 74 6f 20 74 68 65 20 70 72 6f 67 72 65 nt to the progre
a850: 73 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 ss callback */.
a860: 20 75 6e 73 69 67 6e 65 64 20 6e 50 72 6f 67 72 unsigned nProgr
a870: 65 73 73 4f 70 73 3b 20 20 20 20 20 20 20 20 2f essOps; /
a880: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6f 70 63 6f * Number of opco
a890: 64 65 73 20 66 6f 72 20 70 72 6f 67 72 65 73 73 des for progress
a8a0: 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e callback */.#en
a8b0: 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 dif.#ifndef SQLI
a8c0: 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
a8d0: 41 42 4c 45 0a 20 20 69 6e 74 20 6e 56 54 72 61 ABLE. int nVTra
a8e0: 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ns;
a8f0: 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 /* Allocate
a900: 64 20 73 69 7a 65 20 6f 66 20 61 56 54 72 61 6e d size of aVTran
a910: 73 20 2a 2f 0a 20 20 48 61 73 68 20 61 4d 6f 64 s */. Hash aMod
a920: 75 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ule;
a930: 20 20 20 20 20 2f 2a 20 70 6f 70 75 6c 61 74 65 /* populate
a940: 64 20 62 79 20 73 71 6c 69 74 65 33 5f 63 72 65 d by sqlite3_cre
a950: 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a ate_module() */.
a960: 20 20 56 74 61 62 43 74 78 20 2a 70 56 74 61 62 VtabCtx *pVtab
a970: 43 74 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 Ctx;
a980: 2f 2a 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 61 /* Context for a
a990: 63 74 69 76 65 20 76 74 61 62 20 63 6f 6e 6e 65 ctive vtab conne
a9a0: 63 74 2f 63 72 65 61 74 65 20 2a 2f 0a 20 20 56 ct/create */. V
a9b0: 54 61 62 6c 65 20 2a 2a 61 56 54 72 61 6e 73 3b Table **aVTrans;
a9c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
a9d0: 56 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 77 Virtual tables w
a9e0: 69 74 68 20 6f 70 65 6e 20 74 72 61 6e 73 61 63 ith open transac
a9f0: 74 69 6f 6e 73 20 2a 2f 0a 20 20 56 54 61 62 6c tions */. VTabl
aa00: 65 20 2a 70 44 69 73 63 6f 6e 6e 65 63 74 3b 20 e *pDisconnect;
aa10: 20 20 20 2f 2a 20 44 69 73 63 6f 6e 6e 65 63 74 /* Disconnect
aa20: 20 74 68 65 73 65 20 69 6e 20 6e 65 78 74 20 73 these in next s
aa30: 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 28 29 qlite3_prepare()
aa40: 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 46 75 6e */.#endif. Fun
aa50: 63 44 65 66 48 61 73 68 20 61 46 75 6e 63 3b 20 cDefHash aFunc;
aa60: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 61 /* Ha
aa70: 73 68 20 74 61 62 6c 65 20 6f 66 20 63 6f 6e 6e sh table of conn
aa80: 65 63 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 ection functions
aa90: 20 2a 2f 0a 20 20 48 61 73 68 20 61 43 6f 6c 6c */. Hash aColl
aaa0: 53 65 71 3b 20 20 20 20 20 20 20 20 20 20 20 20 Seq;
aab0: 20 20 20 20 2f 2a 20 41 6c 6c 20 63 6f 6c 6c 61 /* All colla
aac0: 74 69 6e 67 20 73 65 71 75 65 6e 63 65 73 20 2a ting sequences *
aad0: 2f 0a 20 20 42 75 73 79 48 61 6e 64 6c 65 72 20 /. BusyHandler
aae0: 62 75 73 79 48 61 6e 64 6c 65 72 3b 20 20 20 20 busyHandler;
aaf0: 20 20 2f 2a 20 42 75 73 79 20 63 61 6c 6c 62 61 /* Busy callba
ab00: 63 6b 20 2a 2f 0a 20 20 44 62 20 61 44 62 53 74 ck */. Db aDbSt
ab10: 61 74 69 63 5b 32 5d 3b 20 20 20 20 20 20 20 20 atic[2];
ab20: 20 20 20 20 20 20 2f 2a 20 53 74 61 74 69 63 20 /* Static
ab30: 73 70 61 63 65 20 66 6f 72 20 74 68 65 20 32 20 space for the 2
ab40: 64 65 66 61 75 6c 74 20 62 61 63 6b 65 6e 64 73 default backends
ab50: 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e 74 20 */. Savepoint
ab60: 2a 70 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 *pSavepoint;
ab70: 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 /* List of a
ab80: 63 74 69 76 65 20 73 61 76 65 70 6f 69 6e 74 73 ctive savepoints
ab90: 20 2a 2f 0a 20 20 69 6e 74 20 62 75 73 79 54 69 */. int busyTi
aba0: 6d 65 6f 75 74 3b 20 20 20 20 20 20 20 20 20 20 meout;
abb0: 20 20 20 20 2f 2a 20 42 75 73 79 20 68 61 6e 64 /* Busy hand
abc0: 6c 65 72 20 74 69 6d 65 6f 75 74 2c 20 69 6e 20 ler timeout, in
abd0: 6d 73 65 63 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 msec */. int nS
abe0: 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 20 avepoint;
abf0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
ac00: 72 20 6f 66 20 6e 6f 6e 2d 74 72 61 6e 73 61 63 r of non-transac
ac10: 74 69 6f 6e 20 73 61 76 65 70 6f 69 6e 74 73 20 tion savepoints
ac20: 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 61 74 65 6d */. int nStatem
ac30: 65 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ent;
ac40: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
ac50: 6e 65 73 74 65 64 20 73 74 61 74 65 6d 65 6e 74 nested statement
ac60: 2d 74 72 61 6e 73 61 63 74 69 6f 6e 73 20 20 2a -transactions *
ac70: 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 /. i64 nDeferre
ac80: 64 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 dCons;
ac90: 20 20 2f 2a 20 4e 65 74 20 64 65 66 65 72 72 65 /* Net deferre
aca0: 64 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 74 68 d constraints th
acb0: 69 73 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e 20 is transaction.
acc0: 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 */. i64 nDeferr
acd0: 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 20 20 20 20 edImmCons;
ace0: 20 20 20 2f 2a 20 4e 65 74 20 64 65 66 65 72 72 /* Net deferr
acf0: 65 64 20 69 6d 6d 65 64 69 61 74 65 20 63 6f 6e ed immediate con
ad00: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 69 6e straints */. in
ad10: 74 20 2a 70 6e 42 79 74 65 73 46 72 65 65 64 3b t *pnBytesFreed;
ad20: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 /* I
ad30: 66 20 6e 6f 74 20 4e 55 4c 4c 2c 20 69 6e 63 72 f not NULL, incr
ad40: 65 6d 65 6e 74 20 74 68 69 73 20 69 6e 20 44 62 ement this in Db
ad50: 46 72 65 65 28 29 20 2a 2f 0a 23 69 66 64 65 66 Free() */.#ifdef
ad60: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 SQLITE_ENABLE_U
ad70: 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 59 0a 20 20 2f NLOCK_NOTIFY. /
ad80: 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
ad90: 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 61 6c variables are al
ada0: 6c 20 70 72 6f 74 65 63 74 65 64 20 62 79 20 74 l protected by t
adb0: 68 65 20 53 54 41 54 49 43 5f 4d 41 53 54 45 52 he STATIC_MASTER
adc0: 20 0a 20 20 2a 2a 20 6d 75 74 65 78 2c 20 6e 6f . ** mutex, no
add0: 74 20 62 79 20 73 71 6c 69 74 65 33 2e 6d 75 74 t by sqlite3.mut
ade0: 65 78 2e 20 54 68 65 79 20 61 72 65 20 75 73 65 ex. They are use
adf0: 64 20 62 79 20 63 6f 64 65 20 69 6e 20 6e 6f 74 d by code in not
ae00: 69 66 79 2e 63 2e 20 0a 20 20 2a 2a 0a 20 20 2a ify.c. . **. *
ae10: 2a 20 57 68 65 6e 20 58 2e 70 55 6e 6c 6f 63 6b * When X.pUnlock
ae20: 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 Connection==Y, t
ae30: 68 61 74 20 6d 65 61 6e 73 20 74 68 61 74 20 58 hat means that X
ae40: 20 69 73 20 77 61 69 74 69 6e 67 20 66 6f 72 20 is waiting for
ae50: 59 20 74 6f 0a 20 20 2a 2a 20 75 6e 6c 6f 63 6b Y to. ** unlock
ae60: 20 73 6f 20 74 68 61 74 20 69 74 20 63 61 6e 20 so that it can
ae70: 70 72 6f 63 65 65 64 2e 0a 20 20 2a 2a 0a 20 20 proceed.. **.
ae80: 2a 2a 20 57 68 65 6e 20 58 2e 70 42 6c 6f 63 6b ** When X.pBlock
ae90: 69 6e 67 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 ingConnection==Y
aea0: 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 68 61 , that means tha
aeb0: 74 20 73 6f 6d 65 74 68 69 6e 67 20 74 68 61 74 t something that
aec0: 20 58 20 74 72 69 65 64 0a 20 20 2a 2a 20 74 72 X tried. ** tr
aed0: 69 65 64 20 74 6f 20 64 6f 20 72 65 63 65 6e 74 ied to do recent
aee0: 6c 79 20 66 61 69 6c 65 64 20 77 69 74 68 20 61 ly failed with a
aef0: 6e 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 n SQLITE_LOCKED
af00: 65 72 72 6f 72 20 64 75 65 20 74 6f 20 6c 6f 63 error due to loc
af10: 6b 73 0a 20 20 2a 2a 20 68 65 6c 64 20 62 79 20 ks. ** held by
af20: 59 2e 0a 20 20 2a 2f 0a 20 20 73 71 6c 69 74 65 Y.. */. sqlite
af30: 33 20 2a 70 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 3 *pBlockingConn
af40: 65 63 74 69 6f 6e 3b 20 2f 2a 20 43 6f 6e 6e 65 ection; /* Conne
af50: 63 74 69 6f 6e 20 74 68 61 74 20 63 61 75 73 65 ction that cause
af60: 64 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 d SQLITE_LOCKED
af70: 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 55 */. sqlite3 *pU
af80: 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3b nlockConnection;
af90: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f /* Co
afa0: 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 77 61 74 63 nnection to watc
afb0: 68 20 66 6f 72 20 75 6e 6c 6f 63 6b 20 2a 2f 0a h for unlock */.
afc0: 20 20 76 6f 69 64 20 2a 70 55 6e 6c 6f 63 6b 41 void *pUnlockA
afd0: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
afe0: 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d /* Argum
aff0: 65 6e 74 20 74 6f 20 78 55 6e 6c 6f 63 6b 4e 6f ent to xUnlockNo
b000: 74 69 66 79 20 2a 2f 0a 20 20 76 6f 69 64 20 28 tify */. void (
b010: 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 79 29 28 *xUnlockNotify)(
b020: 76 6f 69 64 20 2a 2a 2c 20 69 6e 74 29 3b 20 20 void **, int);
b030: 2f 2a 20 55 6e 6c 6f 63 6b 20 6e 6f 74 69 66 79 /* Unlock notify
b040: 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 73 callback */. s
b050: 71 6c 69 74 65 33 20 2a 70 4e 65 78 74 42 6c 6f qlite3 *pNextBlo
b060: 63 6b 65 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 cked; /*
b070: 4e 65 78 74 20 69 6e 20 6c 69 73 74 20 6f 66 20 Next in list of
b080: 61 6c 6c 20 62 6c 6f 63 6b 65 64 20 63 6f 6e 6e all blocked conn
b090: 65 63 74 69 6f 6e 73 20 2a 2f 0a 23 65 6e 64 69 ections */.#endi
b0a0: 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f f.#ifdef SQLITE_
b0b0: 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 USER_AUTHENTICAT
b0c0: 49 4f 4e 0a 20 20 73 71 6c 69 74 65 33 5f 75 73 ION. sqlite3_us
b0d0: 65 72 61 75 74 68 20 61 75 74 68 3b 20 20 20 20 erauth auth;
b0e0: 20 20 20 20 2f 2a 20 55 73 65 72 20 61 75 74 68 /* User auth
b0f0: 65 6e 74 69 63 61 74 69 6f 6e 20 69 6e 66 6f 72 entication infor
b100: 6d 61 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 mation */.#endif
b110: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 .};../*.** A mac
b120: 72 6f 20 74 6f 20 64 69 73 63 6f 76 65 72 20 74 ro to discover t
b130: 68 65 20 65 6e 63 6f 64 69 6e 67 20 6f 66 20 61 he encoding of a
b140: 20 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 23 64 database..*/.#d
b150: 65 66 69 6e 65 20 53 43 48 45 4d 41 5f 45 4e 43 efine SCHEMA_ENC
b160: 28 64 62 29 20 28 28 64 62 29 2d 3e 61 44 62 5b (db) ((db)->aDb[
b170: 30 5d 2e 70 53 63 68 65 6d 61 2d 3e 65 6e 63 29 0].pSchema->enc)
b180: 0a 23 64 65 66 69 6e 65 20 45 4e 43 28 64 62 29 .#define ENC(db)
b190: 20 20 20 20 20 20 20 20 28 28 64 62 29 2d 3e 65 ((db)->e
b1a0: 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 nc)../*.** Possi
b1b0: 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 74 ble values for t
b1c0: 68 65 20 73 71 6c 69 74 65 33 2e 66 6c 61 67 73 he sqlite3.flags
b1d0: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
b1e0: 49 54 45 5f 56 64 62 65 54 72 61 63 65 20 20 20 ITE_VdbeTrace
b1f0: 20 20 20 30 78 30 30 30 30 30 30 30 31 20 20 2f 0x00000001 /
b200: 2a 20 54 72 75 65 20 74 6f 20 74 72 61 63 65 20 * True to trace
b210: 56 44 42 45 20 65 78 65 63 75 74 69 6f 6e 20 2a VDBE execution *
b220: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
b230: 5f 49 6e 74 65 72 6e 43 68 61 6e 67 65 73 20 20 _InternChanges
b240: 30 78 30 30 30 30 30 30 30 32 20 20 2f 2a 20 55 0x00000002 /* U
b250: 6e 63 6f 6d 6d 69 74 74 65 64 20 48 61 73 68 20 ncommitted Hash
b260: 74 61 62 6c 65 20 63 68 61 6e 67 65 73 20 2a 2f table changes */
b270: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b280: 46 75 6c 6c 46 53 79 6e 63 20 20 20 20 20 20 30 FullFSync 0
b290: 78 30 30 30 30 30 30 30 34 20 20 2f 2a 20 55 73 x00000004 /* Us
b2a0: 65 20 66 75 6c 6c 20 66 73 79 6e 63 20 6f 6e 20 e full fsync on
b2b0: 74 68 65 20 62 61 63 6b 65 6e 64 20 2a 2f 0a 23 the backend */.#
b2c0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6b define SQLITE_Ck
b2d0: 70 74 46 75 6c 6c 46 53 79 6e 63 20 20 30 78 30 ptFullFSync 0x0
b2e0: 30 30 30 30 30 30 38 20 20 2f 2a 20 55 73 65 20 0000008 /* Use
b2f0: 66 75 6c 6c 20 66 73 79 6e 63 20 66 6f 72 20 63 full fsync for c
b300: 68 65 63 6b 70 6f 69 6e 74 20 2a 2f 0a 23 64 65 heckpoint */.#de
b310: 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 61 63 68 fine SQLITE_Cach
b320: 65 53 70 69 6c 6c 20 20 20 20 20 30 78 30 30 30 eSpill 0x000
b330: 30 30 30 31 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 00010 /* OK to
b340: 73 70 69 6c 6c 20 70 61 67 65 72 20 63 61 63 68 spill pager cach
b350: 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c e */.#define SQL
b360: 49 54 45 5f 46 75 6c 6c 43 6f 6c 4e 61 6d 65 73 ITE_FullColNames
b370: 20 20 20 30 78 30 30 30 30 30 30 32 30 20 20 2f 0x00000020 /
b380: 2a 20 53 68 6f 77 20 66 75 6c 6c 20 63 6f 6c 75 * Show full colu
b390: 6d 6e 20 6e 61 6d 65 73 20 6f 6e 20 53 45 4c 45 mn names on SELE
b3a0: 43 54 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 CT */.#define SQ
b3b0: 4c 49 54 45 5f 53 68 6f 72 74 43 6f 6c 4e 61 6d LITE_ShortColNam
b3c0: 65 73 20 20 30 78 30 30 30 30 30 30 34 30 20 20 es 0x00000040
b3d0: 2f 2a 20 53 68 6f 77 20 73 68 6f 72 74 20 63 6f /* Show short co
b3e0: 6c 75 6d 6e 73 20 6e 61 6d 65 73 20 2a 2f 0a 23 lumns names */.#
b3f0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f define SQLITE_Co
b400: 75 6e 74 52 6f 77 73 20 20 20 20 20 20 30 78 30 untRows 0x0
b410: 30 30 30 30 30 38 30 20 20 2f 2a 20 43 6f 75 6e 0000080 /* Coun
b420: 74 20 72 6f 77 73 20 63 68 61 6e 67 65 64 20 62 t rows changed b
b430: 79 20 49 4e 53 45 52 54 2c 20 2a 2f 0a 20 20 20 y INSERT, */.
b440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b450: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b460: 20 20 20 20 20 20 20 2f 2a 20 20 20 44 45 4c 45 /* DELE
b470: 54 45 2c 20 6f 72 20 55 50 44 41 54 45 20 61 6e TE, or UPDATE an
b480: 64 20 72 65 74 75 72 6e 20 2a 2f 0a 20 20 20 20 d return */.
b490: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b4a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b4b0: 20 20 20 20 20 20 2f 2a 20 20 20 74 68 65 20 63 /* the c
b4c0: 6f 75 6e 74 20 75 73 69 6e 67 20 61 20 63 61 6c ount using a cal
b4d0: 6c 62 61 63 6b 2e 20 2a 2f 0a 23 64 65 66 69 6e lback. */.#defin
b4e0: 65 20 53 51 4c 49 54 45 5f 4e 75 6c 6c 43 61 6c e SQLITE_NullCal
b4f0: 6c 62 61 63 6b 20 20 20 30 78 30 30 30 30 30 31 lback 0x000001
b500: 30 30 20 20 2f 2a 20 49 6e 76 6f 6b 65 20 74 68 00 /* Invoke th
b510: 65 20 63 61 6c 6c 62 61 63 6b 20 6f 6e 63 65 20 e callback once
b520: 69 66 20 74 68 65 20 2a 2f 0a 20 20 20 20 20 20 if the */.
b530: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b540: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b550: 20 20 20 20 2f 2a 20 20 20 72 65 73 75 6c 74 20 /* result
b560: 73 65 74 20 69 73 20 65 6d 70 74 79 20 2a 2f 0a set is empty */.
b570: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
b580: 71 6c 54 72 61 63 65 20 20 20 20 20 20 20 30 78 qlTrace 0x
b590: 30 30 30 30 30 32 30 30 20 20 2f 2a 20 44 65 62 00000200 /* Deb
b5a0: 75 67 20 70 72 69 6e 74 20 53 51 4c 20 61 73 20 ug print SQL as
b5b0: 69 74 20 65 78 65 63 75 74 65 73 20 2a 2f 0a 23 it executes */.#
b5c0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 define SQLITE_Vd
b5d0: 62 65 4c 69 73 74 69 6e 67 20 20 20 20 30 78 30 beListing 0x0
b5e0: 30 30 30 30 34 30 30 20 20 2f 2a 20 44 65 62 75 0000400 /* Debu
b5f0: 67 20 6c 69 73 74 69 6e 67 73 20 6f 66 20 56 44 g listings of VD
b600: 42 45 20 70 72 6f 67 72 61 6d 73 20 2a 2f 0a 23 BE programs */.#
b610: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 72 define SQLITE_Wr
b620: 69 74 65 53 63 68 65 6d 61 20 20 20 20 30 78 30 iteSchema 0x0
b630: 30 30 30 30 38 30 30 20 20 2f 2a 20 4f 4b 20 74 0000800 /* OK t
b640: 6f 20 75 70 64 61 74 65 20 53 51 4c 49 54 45 5f o update SQLITE_
b650: 4d 41 53 54 45 52 20 2a 2f 0a 23 64 65 66 69 6e MASTER */.#defin
b660: 65 20 53 51 4c 49 54 45 5f 56 64 62 65 41 64 64 e SQLITE_VdbeAdd
b670: 6f 70 54 72 61 63 65 20 30 78 30 30 30 30 31 30 opTrace 0x000010
b680: 30 30 20 20 2f 2a 20 54 72 61 63 65 20 73 71 6c 00 /* Trace sql
b690: 69 74 65 33 56 64 62 65 41 64 64 4f 70 28 29 20 ite3VdbeAddOp()
b6a0: 63 61 6c 6c 73 20 2a 2f 0a 23 64 65 66 69 6e 65 calls */.#define
b6b0: 20 53 51 4c 49 54 45 5f 49 67 6e 6f 72 65 43 68 SQLITE_IgnoreCh
b6c0: 65 63 6b 73 20 20 20 30 78 30 30 30 30 32 30 30 ecks 0x0000200
b6d0: 30 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 6e 66 0 /* Do not enf
b6e0: 6f 72 63 65 20 63 68 65 63 6b 20 63 6f 6e 73 74 orce check const
b6f0: 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 66 69 6e raints */.#defin
b700: 65 20 53 51 4c 49 54 45 5f 52 65 61 64 55 6e 63 e SQLITE_ReadUnc
b710: 6f 6d 6d 69 74 74 65 64 20 30 78 30 30 30 34 30 ommitted 0x00040
b720: 30 30 20 20 2f 2a 20 46 6f 72 20 73 68 61 72 65 00 /* For share
b730: 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 2a 2f 0a d-cache mode */.
b740: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c #define SQLITE_L
b750: 65 67 61 63 79 46 69 6c 65 46 6d 74 20 20 30 78 egacyFileFmt 0x
b760: 30 30 30 30 38 30 30 30 20 20 2f 2a 20 43 72 65 00008000 /* Cre
b770: 61 74 65 20 6e 65 77 20 64 61 74 61 62 61 73 65 ate new database
b780: 73 20 69 6e 20 66 6f 72 6d 61 74 20 31 20 2a 2f s in format 1 */
b790: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b7a0: 52 65 63 6f 76 65 72 79 4d 6f 64 65 20 20 20 30 RecoveryMode 0
b7b0: 78 30 30 30 31 30 30 30 30 20 20 2f 2a 20 49 67 x00010000 /* Ig
b7c0: 6e 6f 72 65 20 73 63 68 65 6d 61 20 65 72 72 6f nore schema erro
b7d0: 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 rs */.#define SQ
b7e0: 4c 49 54 45 5f 52 65 76 65 72 73 65 4f 72 64 65 LITE_ReverseOrde
b7f0: 72 20 20 20 30 78 30 30 30 32 30 30 30 30 20 20 r 0x00020000
b800: 2f 2a 20 52 65 76 65 72 73 65 20 75 6e 6f 72 64 /* Reverse unord
b810: 65 72 65 64 20 53 45 4c 45 43 54 73 20 2a 2f 0a ered SELECTs */.
b820: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 #define SQLITE_R
b830: 65 63 54 72 69 67 67 65 72 73 20 20 20 20 30 78 ecTriggers 0x
b840: 30 30 30 34 30 30 30 30 20 20 2f 2a 20 45 6e 61 00040000 /* Ena
b850: 62 6c 65 20 72 65 63 75 72 73 69 76 65 20 74 72 ble recursive tr
b860: 69 67 67 65 72 73 20 2a 2f 0a 23 64 65 66 69 6e iggers */.#defin
b870: 65 20 53 51 4c 49 54 45 5f 46 6f 72 65 69 67 6e e SQLITE_Foreign
b880: 4b 65 79 73 20 20 20 20 30 78 30 30 30 38 30 30 Keys 0x000800
b890: 30 30 20 20 2f 2a 20 45 6e 66 6f 72 63 65 20 66 00 /* Enforce f
b8a0: 6f 72 65 69 67 6e 20 6b 65 79 20 63 6f 6e 73 74 oreign key const
b8b0: 72 61 69 6e 74 73 20 20 2a 2f 0a 23 64 65 66 69 raints */.#defi
b8c0: 6e 65 20 53 51 4c 49 54 45 5f 41 75 74 6f 49 6e ne SQLITE_AutoIn
b8d0: 64 65 78 20 20 20 20 20 20 30 78 30 30 31 30 30 dex 0x00100
b8e0: 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 61 000 /* Enable a
b8f0: 75 74 6f 6d 61 74 69 63 20 69 6e 64 65 78 65 73 utomatic indexes
b900: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
b910: 54 45 5f 50 72 65 66 65 72 42 75 69 6c 74 69 6e TE_PreferBuiltin
b920: 20 20 30 78 30 30 32 30 30 30 30 30 20 20 2f 2a 0x00200000 /*
b930: 20 50 72 65 66 65 72 65 6e 63 65 20 74 6f 20 62 Preference to b
b940: 75 69 6c 74 2d 69 6e 20 66 75 6e 63 73 20 2a 2f uilt-in funcs */
b950: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
b960: 4c 6f 61 64 45 78 74 65 6e 73 69 6f 6e 20 20 30 LoadExtension 0
b970: 78 30 30 34 30 30 30 30 30 20 20 2f 2a 20 45 6e x00400000 /* En
b980: 61 62 6c 65 20 6c 6f 61 64 5f 65 78 74 65 6e 73 able load_extens
b990: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ion */.#define S
b9a0: 51 4c 49 54 45 5f 45 6e 61 62 6c 65 54 72 69 67 QLITE_EnableTrig
b9b0: 67 65 72 20 20 30 78 30 30 38 30 30 30 30 30 20 ger 0x00800000
b9c0: 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62 /* True to enab
b9d0: 6c 65 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 23 le triggers */.#
b9e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 65 define SQLITE_De
b9f0: 66 65 72 46 4b 73 20 20 20 20 20 20 20 30 78 30 ferFKs 0x0
ba00: 31 30 30 30 30 30 30 20 20 2f 2a 20 44 65 66 65 1000000 /* Defe
ba10: 72 20 61 6c 6c 20 46 4b 20 63 6f 6e 73 74 72 61 r all FK constra
ba20: 69 6e 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ints */.#define
ba30: 53 51 4c 49 54 45 5f 51 75 65 72 79 4f 6e 6c 79 SQLITE_QueryOnly
ba40: 20 20 20 20 20 20 30 78 30 32 30 30 30 30 30 30 0x02000000
ba50: 20 20 2f 2a 20 44 69 73 61 62 6c 65 20 64 61 74 /* Disable dat
ba60: 61 62 61 73 65 20 63 68 61 6e 67 65 73 20 2a 2f abase changes */
ba70: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ba80: 56 64 62 65 45 51 50 20 20 20 20 20 20 20 20 30 VdbeEQP 0
ba90: 78 30 34 30 30 30 30 30 30 20 20 2f 2a 20 44 65 x04000000 /* De
baa0: 62 75 67 20 45 58 50 4c 41 49 4e 20 51 55 45 52 bug EXPLAIN QUER
bab0: 59 20 50 4c 41 4e 20 2a 2f 0a 23 64 65 66 69 6e Y PLAN */.#defin
bac0: 65 20 53 51 4c 49 54 45 5f 56 61 63 75 75 6d 20 e SQLITE_Vacuum
bad0: 20 20 20 20 20 20 20 20 30 78 30 38 30 30 30 30 0x080000
bae0: 30 30 20 20 2f 2a 20 43 75 72 72 65 6e 74 6c 79 00 /* Currently
baf0: 20 69 6e 20 61 20 56 41 43 55 55 4d 20 2a 2f 0a in a VACUUM */.
bb00: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 #define SQLITE_C
bb10: 65 6c 6c 53 69 7a 65 43 6b 20 20 20 20 20 30 78 ellSizeCk 0x
bb20: 31 30 30 30 30 30 30 30 20 20 2f 2a 20 43 68 65 10000000 /* Che
bb30: 63 6b 20 62 74 72 65 65 20 63 65 6c 6c 20 73 69 ck btree cell si
bb40: 7a 65 73 20 6f 6e 20 6c 6f 61 64 20 2a 2f 0a 0a zes on load */..
bb50: 0a 2f 2a 0a 2a 2a 20 42 69 74 73 20 6f 66 20 74 ./*.** Bits of t
bb60: 68 65 20 73 71 6c 69 74 65 33 2e 64 62 4f 70 74 he sqlite3.dbOpt
bb70: 46 6c 61 67 73 20 66 69 65 6c 64 20 74 68 61 74 Flags field that
bb80: 20 61 72 65 20 75 73 65 64 20 62 79 20 74 68 65 are used by the
bb90: 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 74 .** sqlite3_test
bba0: 5f 63 6f 6e 74 72 6f 6c 28 53 51 4c 49 54 45 5f _control(SQLITE_
bbb0: 54 45 53 54 43 54 52 4c 5f 4f 50 54 49 4d 49 5a TESTCTRL_OPTIMIZ
bbc0: 41 54 49 4f 4e 53 2c 2e 2e 2e 29 20 69 6e 74 65 ATIONS,...) inte
bbd0: 72 66 61 63 65 20 74 6f 0a 2a 2a 20 73 65 6c 65 rface to.** sele
bbe0: 63 74 69 76 65 6c 79 20 64 69 73 61 62 6c 65 20 ctively disable
bbf0: 76 61 72 69 6f 75 73 20 6f 70 74 69 6d 69 7a 61 various optimiza
bc00: 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e tions..*/.#defin
bc10: 65 20 53 51 4c 49 54 45 5f 51 75 65 72 79 46 6c e SQLITE_QueryFl
bc20: 61 74 74 65 6e 65 72 20 30 78 30 30 30 31 20 20 attener 0x0001
bc30: 20 2f 2a 20 51 75 65 72 79 20 66 6c 61 74 74 65 /* Query flatte
bc40: 6e 69 6e 67 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ning */.#define
bc50: 53 51 4c 49 54 45 5f 43 6f 6c 75 6d 6e 43 61 63 SQLITE_ColumnCac
bc60: 68 65 20 20 20 20 30 78 30 30 30 32 20 20 20 2f he 0x0002 /
bc70: 2a 20 43 6f 6c 75 6d 6e 20 63 61 63 68 65 20 2a * Column cache *
bc80: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
bc90: 5f 47 72 6f 75 70 42 79 4f 72 64 65 72 20 20 20 _GroupByOrder
bca0: 30 78 30 30 30 34 20 20 20 2f 2a 20 47 52 4f 55 0x0004 /* GROU
bcb0: 50 42 59 20 63 6f 76 65 72 20 6f 66 20 4f 52 44 PBY cover of ORD
bcc0: 45 52 42 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ERBY */.#define
bcd0: 53 51 4c 49 54 45 5f 46 61 63 74 6f 72 4f 75 74 SQLITE_FactorOut
bce0: 43 6f 6e 73 74 20 30 78 30 30 30 38 20 20 20 2f Const 0x0008 /
bcf0: 2a 20 43 6f 6e 73 74 61 6e 74 20 66 61 63 74 6f * Constant facto
bd00: 72 69 6e 67 20 2a 2f 0a 2f 2a 20 20 20 20 20 20 ring */./*
bd10: 20 20 20 20 20 20 20 20 20 20 6e 6f 74 20 75 73 not us
bd20: 65 64 20 20 20 20 30 78 30 30 31 30 20 20 20 2f ed 0x0010 /
bd30: 2f 20 57 61 73 3a 20 53 51 4c 49 54 45 5f 49 64 / Was: SQLITE_Id
bd40: 78 52 65 61 6c 41 73 49 6e 74 20 2a 2f 0a 23 64 xRealAsInt */.#d
bd50: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 69 73 efine SQLITE_Dis
bd60: 74 69 6e 63 74 4f 70 74 20 20 20 20 30 78 30 30 tinctOpt 0x00
bd70: 32 30 20 20 20 2f 2a 20 44 49 53 54 49 4e 43 54 20 /* DISTINCT
bd80: 20 75 73 69 6e 67 20 69 6e 64 65 78 65 73 20 2a using indexes *
bd90: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
bda0: 5f 43 6f 76 65 72 49 64 78 53 63 61 6e 20 20 20 _CoverIdxScan
bdb0: 30 78 30 30 34 30 20 20 20 2f 2a 20 43 6f 76 65 0x0040 /* Cove
bdc0: 72 69 6e 67 20 69 6e 64 65 78 20 73 63 61 6e 73 ring index scans
bdd0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bde0: 54 45 5f 4f 72 64 65 72 42 79 49 64 78 4a 6f 69 TE_OrderByIdxJoi
bdf0: 6e 20 30 78 30 30 38 30 20 20 20 2f 2a 20 4f 52 n 0x0080 /* OR
be00: 44 45 52 20 42 59 20 6f 66 20 6a 6f 69 6e 73 20 DER BY of joins
be10: 76 69 61 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 via index */.#de
be20: 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 75 62 71 fine SQLITE_Subq
be30: 43 6f 72 6f 75 74 69 6e 65 20 20 30 78 30 31 30 Coroutine 0x010
be40: 30 20 20 20 2f 2a 20 45 76 61 6c 75 61 74 65 20 0 /* Evaluate
be50: 73 75 62 71 75 65 72 69 65 73 20 61 73 20 63 6f subqueries as co
be60: 72 6f 75 74 69 6e 65 73 20 2a 2f 0a 23 64 65 66 routines */.#def
be70: 69 6e 65 20 53 51 4c 49 54 45 5f 54 72 61 6e 73 ine SQLITE_Trans
be80: 69 74 69 76 65 20 20 20 20 20 30 78 30 32 30 30 itive 0x0200
be90: 20 20 20 2f 2a 20 54 72 61 6e 73 69 74 69 76 65 /* Transitive
bea0: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
beb0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f #define SQLITE_O
bec0: 6d 69 74 4e 6f 6f 70 4a 6f 69 6e 20 20 20 30 78 mitNoopJoin 0x
bed0: 30 34 30 30 20 20 20 2f 2a 20 4f 6d 69 74 20 75 0400 /* Omit u
bee0: 6e 75 73 65 64 20 74 61 62 6c 65 73 20 69 6e 20 nused tables in
bef0: 6a 6f 69 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 joins */.#define
bf00: 20 53 51 4c 49 54 45 5f 53 74 61 74 33 34 20 20 SQLITE_Stat34
bf10: 20 20 20 20 20 20 20 30 78 30 38 30 30 20 20 20 0x0800
bf20: 2f 2a 20 55 73 65 20 53 54 41 54 33 20 6f 72 20 /* Use STAT3 or
bf30: 53 54 41 54 34 20 64 61 74 61 20 2a 2f 0a 23 64 STAT4 data */.#d
bf40: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 6c 6c efine SQLITE_All
bf50: 4f 70 74 73 20 20 20 20 20 20 20 20 30 78 66 66 Opts 0xff
bf60: 66 66 20 20 20 2f 2a 20 41 6c 6c 20 6f 70 74 69 ff /* All opti
bf70: 6d 69 7a 61 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a mizations */../*
bf80: 0a 2a 2a 20 4d 61 63 72 6f 73 20 66 6f 72 20 74 .** Macros for t
bf90: 65 73 74 69 6e 67 20 77 68 65 74 68 65 72 20 6f esting whether o
bfa0: 72 20 6e 6f 74 20 6f 70 74 69 6d 69 7a 61 74 69 r not optimizati
bfb0: 6f 6e 73 20 61 72 65 20 65 6e 61 62 6c 65 64 20 ons are enabled
bfc0: 6f 72 20 64 69 73 61 62 6c 65 64 2e 0a 2a 2f 0a or disabled..*/.
bfd0: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
bfe0: 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 MIT_BUILTIN_TEST
bff0: 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 7a .#define Optimiz
c000: 61 74 69 6f 6e 44 69 73 61 62 6c 65 64 28 64 62 ationDisabled(db
c010: 2c 20 6d 61 73 6b 29 20 20 28 28 28 64 62 29 2d , mask) (((db)-
c020: 3e 64 62 4f 70 74 46 6c 61 67 73 26 28 6d 61 73 >dbOptFlags&(mas
c030: 6b 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 k))!=0).#define
c040: 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 45 6e 61 62 OptimizationEnab
c050: 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 20 led(db, mask)
c060: 28 28 28 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 (((db)->dbOptFla
c070: 67 73 26 28 6d 61 73 6b 29 29 3d 3d 30 29 0a 23 gs&(mask))==0).#
c080: 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 4f 70 74 else.#define Opt
c090: 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 62 6c 65 imizationDisable
c0a0: 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 30 0a 23 d(db, mask) 0.#
c0b0: 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 define Optimizat
c0c0: 69 6f 6e 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d ionEnabled(db, m
c0d0: 61 73 6b 29 20 20 20 31 0a 23 65 6e 64 69 66 0a ask) 1.#endif.
c0e0: 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 ./*.** Return tr
c0f0: 75 65 20 69 66 20 69 74 20 4f 4b 20 74 6f 20 66 ue if it OK to f
c100: 61 63 74 6f 72 20 63 6f 6e 73 74 61 6e 74 20 65 actor constant e
c110: 78 70 72 65 73 73 69 6f 6e 73 20 69 6e 74 6f 20 xpressions into
c120: 74 68 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 the initializati
c130: 6f 6e 0a 2a 2a 20 63 6f 64 65 2e 20 54 68 65 20 on.** code. The
c140: 61 72 67 75 6d 65 6e 74 20 69 73 20 61 20 50 61 argument is a Pa
c150: 72 73 65 20 6f 62 6a 65 63 74 20 66 6f 72 20 74 rse object for t
c160: 68 65 20 63 6f 64 65 20 67 65 6e 65 72 61 74 6f he code generato
c170: 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43 6f r..*/.#define Co
c180: 6e 73 74 46 61 63 74 6f 72 4f 6b 28 50 29 20 28 nstFactorOk(P) (
c190: 28 50 29 2d 3e 6f 6b 43 6f 6e 73 74 46 61 63 74 (P)->okConstFact
c1a0: 6f 72 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 or)../*.** Possi
c1b0: 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 74 ble values for t
c1c0: 68 65 20 73 71 6c 69 74 65 2e 6d 61 67 69 63 20 he sqlite.magic
c1d0: 66 69 65 6c 64 2e 0a 2a 2a 20 54 68 65 20 6e 75 field..** The nu
c1e0: 6d 62 65 72 73 20 61 72 65 20 6f 62 74 61 69 6e mbers are obtain
c1f0: 65 64 20 61 74 20 72 61 6e 64 6f 6d 20 61 6e 64 ed at random and
c200: 20 68 61 76 65 20 6e 6f 20 73 70 65 63 69 61 6c have no special
c210: 20 6d 65 61 6e 69 6e 67 2c 20 6f 74 68 65 72 0a meaning, other.
c220: 2a 2a 20 74 68 61 6e 20 62 65 69 6e 67 20 64 69 ** than being di
c230: 73 74 69 6e 63 74 20 66 72 6f 6d 20 6f 6e 65 20 stinct from one
c240: 61 6e 6f 74 68 65 72 2e 0a 2a 2f 0a 23 64 65 66 another..*/.#def
c250: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
c260: 5f 4f 50 45 4e 20 20 20 20 20 30 78 61 30 32 39 _OPEN 0xa029
c270: 61 36 39 37 20 20 2f 2a 20 44 61 74 61 62 61 73 a697 /* Databas
c280: 65 20 69 73 20 6f 70 65 6e 20 2a 2f 0a 23 64 65 e is open */.#de
c290: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 fine SQLITE_MAGI
c2a0: 43 5f 43 4c 4f 53 45 44 20 20 20 30 78 39 66 33 C_CLOSED 0x9f3
c2b0: 63 32 64 33 33 20 20 2f 2a 20 44 61 74 61 62 61 c2d33 /* Databa
c2c0: 73 65 20 69 73 20 63 6c 6f 73 65 64 20 2a 2f 0a se is closed */.
c2d0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
c2e0: 41 47 49 43 5f 53 49 43 4b 20 20 20 20 20 30 78 AGIC_SICK 0x
c2f0: 34 62 37 37 31 32 39 30 20 20 2f 2a 20 45 72 72 4b771290 /* Err
c300: 6f 72 20 61 6e 64 20 61 77 61 69 74 69 6e 67 20 or and awaiting
c310: 63 6c 6f 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 close */.#define
c320: 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 42 55 SQLITE_MAGIC_BU
c330: 53 59 20 20 20 20 20 30 78 66 30 33 62 37 39 30 SY 0xf03b790
c340: 36 20 20 2f 2a 20 44 61 74 61 62 61 73 65 20 63 6 /* Database c
c350: 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 73 65 20 urrently in use
c360: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
c370: 45 5f 4d 41 47 49 43 5f 45 52 52 4f 52 20 20 20 E_MAGIC_ERROR
c380: 20 30 78 62 35 33 35 37 39 33 30 20 20 2f 2a 20 0xb5357930 /*
c390: 41 6e 20 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 An SQLITE_MISUSE
c3a0: 20 65 72 72 6f 72 20 6f 63 63 75 72 72 65 64 20 error occurred
c3b0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
c3c0: 45 5f 4d 41 47 49 43 5f 5a 4f 4d 42 49 45 20 20 E_MAGIC_ZOMBIE
c3d0: 20 30 78 36 34 63 66 66 63 37 66 20 20 2f 2a 20 0x64cffc7f /*
c3e0: 43 6c 6f 73 65 20 77 69 74 68 20 6c 61 73 74 20 Close with last
c3f0: 73 74 61 74 65 6d 65 6e 74 20 63 6c 6f 73 65 20 statement close
c400: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 */../*.** Each S
c410: 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 64 QL function is d
c420: 65 66 69 6e 65 64 20 62 79 20 61 6e 20 69 6e 73 efined by an ins
c430: 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
c440: 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 75 63 74 lowing.** struct
c450: 75 72 65 2e 20 20 41 20 70 6f 69 6e 74 65 72 20 ure. A pointer
c460: 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 72 to this structur
c470: 65 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 e is stored in t
c480: 68 65 20 73 71 6c 69 74 65 2e 61 46 75 6e 63 0a he sqlite.aFunc.
c490: 2a 2a 20 68 61 73 68 20 74 61 62 6c 65 2e 20 20 ** hash table.
c4a0: 57 68 65 6e 20 6d 75 6c 74 69 70 6c 65 20 66 75 When multiple fu
c4b0: 6e 63 74 69 6f 6e 73 20 68 61 76 65 20 74 68 65 nctions have the
c4c0: 20 73 61 6d 65 20 6e 61 6d 65 2c 20 74 68 65 20 same name, the
c4d0: 68 61 73 68 20 74 61 62 6c 65 0a 2a 2a 20 70 6f hash table.** po
c4e0: 69 6e 74 73 20 74 6f 20 61 20 6c 69 6e 6b 65 64 ints to a linked
c4f0: 20 6c 69 73 74 20 6f 66 20 74 68 65 73 65 20 73 list of these s
c500: 74 72 75 63 74 75 72 65 73 2e 0a 2a 2f 0a 73 74 tructures..*/.st
c510: 72 75 63 74 20 46 75 6e 63 44 65 66 20 7b 0a 20 ruct FuncDef {.
c520: 20 69 31 36 20 6e 41 72 67 3b 20 20 20 20 20 20 i16 nArg;
c530: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
c540: 6f 66 20 61 72 67 75 6d 65 6e 74 73 2e 20 20 2d of arguments. -
c550: 31 20 6d 65 61 6e 73 20 75 6e 6c 69 6d 69 74 65 1 means unlimite
c560: 64 20 2a 2f 0a 20 20 75 31 36 20 66 75 6e 63 46 d */. u16 funcF
c570: 6c 61 67 73 3b 20 20 20 20 20 20 20 2f 2a 20 53 lags; /* S
c580: 6f 6d 65 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 ome combination
c590: 6f 66 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 2a of SQLITE_FUNC_*
c5a0: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 */. void *pUse
c5b0: 72 44 61 74 61 3b 20 20 20 20 20 2f 2a 20 55 73 rData; /* Us
c5c0: 65 72 20 64 61 74 61 20 70 61 72 61 6d 65 74 65 er data paramete
c5d0: 72 20 2a 2f 0a 20 20 46 75 6e 63 44 65 66 20 2a r */. FuncDef *
c5e0: 70 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 4e pNext; /* N
c5f0: 65 78 74 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 ext function wit
c600: 68 20 73 61 6d 65 20 6e 61 6d 65 20 2a 2f 0a 20 h same name */.
c610: 20 76 6f 69 64 20 28 2a 78 46 75 6e 63 29 28 73 void (*xFunc)(s
c620: 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
c630: 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
c640: 65 2a 2a 29 3b 20 2f 2a 20 52 65 67 75 6c 61 72 e**); /* Regular
c650: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 function */. v
c660: 6f 69 64 20 28 2a 78 53 74 65 70 29 28 73 71 6c oid (*xStep)(sql
c670: 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e ite3_context*,in
c680: 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a t,sqlite3_value*
c690: 2a 29 3b 20 2f 2a 20 41 67 67 72 65 67 61 74 65 *); /* Aggregate
c6a0: 20 73 74 65 70 20 2a 2f 0a 20 20 76 6f 69 64 20 step */. void
c6b0: 28 2a 78 46 69 6e 61 6c 69 7a 65 29 28 73 71 6c (*xFinalize)(sql
c6c0: 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 3b 20 ite3_context*);
c6d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c6e0: 2a 20 41 67 67 72 65 67 61 74 65 20 66 69 6e 61 * Aggregate fina
c6f0: 6c 69 7a 65 72 20 2a 2f 0a 20 20 63 68 61 72 20 lizer */. char
c700: 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
c710: 2f 2a 20 53 51 4c 20 6e 61 6d 65 20 6f 66 20 74 /* SQL name of t
c720: 68 65 20 66 75 6e 63 74 69 6f 6e 2e 20 2a 2f 0a he function. */.
c730: 20 20 46 75 6e 63 44 65 66 20 2a 70 48 61 73 68 FuncDef *pHash
c740: 3b 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 ; /* Next w
c750: 69 74 68 20 61 20 64 69 66 66 65 72 65 6e 74 20 ith a different
c760: 6e 61 6d 65 20 62 75 74 20 74 68 65 20 73 61 6d name but the sam
c770: 65 20 68 61 73 68 20 2a 2f 0a 20 20 46 75 6e 63 e hash */. Func
c780: 44 65 73 74 72 75 63 74 6f 72 20 2a 70 44 65 73 Destructor *pDes
c790: 74 72 75 63 74 6f 72 3b 20 20 20 2f 2a 20 52 65 tructor; /* Re
c7a0: 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 65 64 20 ference counted
c7b0: 64 65 73 74 72 75 63 74 6f 72 20 66 75 6e 63 74 destructor funct
c7c0: 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ion */.};../*.**
c7d0: 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 20 This structure
c7e0: 65 6e 63 61 70 73 75 6c 61 74 65 73 20 61 20 75 encapsulates a u
c7f0: 73 65 72 2d 66 75 6e 63 74 69 6f 6e 20 64 65 73 ser-function des
c800: 74 72 75 63 74 6f 72 20 63 61 6c 6c 62 61 63 6b tructor callback
c810: 20 28 61 73 0a 2a 2a 20 63 6f 6e 66 69 67 75 72 (as.** configur
c820: 65 64 20 75 73 69 6e 67 20 63 72 65 61 74 65 5f ed using create_
c830: 66 75 6e 63 74 69 6f 6e 5f 76 32 28 29 29 20 61 function_v2()) a
c840: 6e 64 20 61 20 72 65 66 65 72 65 6e 63 65 20 63 nd a reference c
c850: 6f 75 6e 74 65 72 2e 20 57 68 65 6e 0a 2a 2a 20 ounter. When.**
c860: 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f create_function_
c870: 76 32 28 29 20 69 73 20 63 61 6c 6c 65 64 20 74 v2() is called t
c880: 6f 20 63 72 65 61 74 65 20 61 20 66 75 6e 63 74 o create a funct
c890: 69 6f 6e 20 77 69 74 68 20 61 20 64 65 73 74 72 ion with a destr
c8a0: 75 63 74 6f 72 2c 0a 2a 2a 20 61 20 73 69 6e 67 uctor,.** a sing
c8b0: 6c 65 20 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 le object of thi
c8c0: 73 20 74 79 70 65 20 69 73 20 61 6c 6c 6f 63 61 s type is alloca
c8d0: 74 65 64 2e 20 46 75 6e 63 44 65 73 74 72 75 63 ted. FuncDestruc
c8e0: 74 6f 72 2e 6e 52 65 66 20 69 73 20 73 65 74 20 tor.nRef is set
c8f0: 74 6f 20 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 65 to .** the numbe
c900: 72 20 6f 66 20 46 75 6e 63 44 65 66 20 6f 62 6a r of FuncDef obj
c910: 65 63 74 73 20 63 72 65 61 74 65 64 20 28 65 69 ects created (ei
c920: 74 68 65 72 20 31 20 6f 72 20 33 2c 20 64 65 70 ther 1 or 3, dep
c930: 65 6e 64 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 ending on whethe
c940: 72 0a 2a 2a 20 6f 72 20 6e 6f 74 20 74 68 65 20 r.** or not the
c950: 73 70 65 63 69 66 69 65 64 20 65 6e 63 6f 64 69 specified encodi
c960: 6e 67 20 69 73 20 53 51 4c 49 54 45 5f 41 4e 59 ng is SQLITE_ANY
c970: 29 2e 20 54 68 65 20 46 75 6e 63 44 65 66 2e 70 ). The FuncDef.p
c980: 44 65 73 74 72 75 63 74 6f 72 0a 2a 2a 20 6d 65 Destructor.** me
c990: 6d 62 65 72 20 6f 66 20 65 61 63 68 20 6f 66 20 mber of each of
c9a0: 74 68 65 20 6e 65 77 20 46 75 6e 63 44 65 66 20 the new FuncDef
c9b0: 6f 62 6a 65 63 74 73 20 69 73 20 73 65 74 20 74 objects is set t
c9c0: 6f 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 20 61 o point to the a
c9d0: 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 46 75 6e 63 llocated.** Func
c9e0: 44 65 73 74 72 75 63 74 6f 72 2e 0a 2a 2a 0a 2a Destructor..**.*
c9f0: 2a 20 54 68 65 72 65 61 66 74 65 72 2c 20 77 68 * Thereafter, wh
ca00: 65 6e 20 6f 6e 65 20 6f 66 20 74 68 65 20 46 75 en one of the Fu
ca10: 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 20 69 73 ncDef objects is
ca20: 20 64 65 6c 65 74 65 64 2c 20 74 68 65 20 72 65 deleted, the re
ca30: 66 65 72 65 6e 63 65 0a 2a 2a 20 63 6f 75 6e 74 ference.** count
ca40: 20 6f 6e 20 74 68 69 73 20 6f 62 6a 65 63 74 20 on this object
ca50: 69 73 20 64 65 63 72 65 6d 65 6e 74 65 64 2e 20 is decremented.
ca60: 57 68 65 6e 20 69 74 20 72 65 61 63 68 65 73 20 When it reaches
ca70: 30 2c 20 74 68 65 20 64 65 73 74 72 75 63 74 6f 0, the destructo
ca80: 72 0a 2a 2a 20 69 73 20 69 6e 76 6f 6b 65 64 20 r.** is invoked
ca90: 61 6e 64 20 74 68 65 20 46 75 6e 63 44 65 73 74 and the FuncDest
caa0: 72 75 63 74 6f 72 20 73 74 72 75 63 74 75 72 65 ructor structure
cab0: 20 66 72 65 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 freed..*/.struc
cac0: 74 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 t FuncDestructor
cad0: 20 7b 0a 20 20 69 6e 74 20 6e 52 65 66 3b 0a 20 {. int nRef;.
cae0: 20 76 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 void (*xDestroy
caf0: 29 28 76 6f 69 64 20 2a 29 3b 0a 20 20 76 6f 69 )(void *);. voi
cb00: 64 20 2a 70 55 73 65 72 44 61 74 61 3b 0a 7d 3b d *pUserData;.};
cb10: 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 ../*.** Possible
cb20: 20 76 61 6c 75 65 73 20 66 6f 72 20 46 75 6e 63 values for Func
cb30: 44 65 66 2e 66 6c 61 67 73 2e 20 20 4e 6f 74 65 Def.flags. Note
cb40: 20 74 68 61 74 20 74 68 65 20 5f 4c 45 4e 47 54 that the _LENGT
cb50: 48 20 61 6e 64 20 5f 54 59 50 45 4f 46 0a 2a 2a H and _TYPEOF.**
cb60: 20 76 61 6c 75 65 73 20 6d 75 73 74 20 63 6f 72 values must cor
cb70: 72 65 73 70 6f 6e 64 20 74 6f 20 4f 50 46 4c 41 respond to OPFLA
cb80: 47 5f 4c 45 4e 47 54 48 41 52 47 20 61 6e 64 20 G_LENGTHARG and
cb90: 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 OPFLAG_TYPEOFARG
cba0: 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 . There.** are
cbb0: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
cbc0: 6e 74 73 20 69 6e 20 74 68 65 20 63 6f 64 65 20 nts in the code
cbd0: 74 6f 20 76 65 72 69 66 79 20 74 68 69 73 2e 0a to verify this..
cbe0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
cbf0: 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 53 4b 20 20 E_FUNC_ENCMASK
cc00: 30 78 30 30 33 20 2f 2a 20 53 51 4c 49 54 45 5f 0x003 /* SQLITE_
cc10: 55 54 46 38 2c 20 53 51 4c 49 54 45 5f 55 54 46 UTF8, SQLITE_UTF
cc20: 31 36 42 45 20 6f 72 20 55 54 46 31 36 4c 45 20 16BE or UTF16LE
cc30: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
cc40: 45 5f 46 55 4e 43 5f 4c 49 4b 45 20 20 20 20 20 E_FUNC_LIKE
cc50: 30 78 30 30 34 20 2f 2a 20 43 61 6e 64 69 64 61 0x004 /* Candida
cc60: 74 65 20 66 6f 72 20 74 68 65 20 4c 49 4b 45 20 te for the LIKE
cc70: 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 2a 2f 0a optimization */.
cc80: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
cc90: 55 4e 43 5f 43 41 53 45 20 20 20 20 20 30 78 30 UNC_CASE 0x0
cca0: 30 38 20 2f 2a 20 43 61 73 65 2d 73 65 6e 73 69 08 /* Case-sensi
ccb0: 74 69 76 65 20 4c 49 4b 45 2d 74 79 70 65 20 66 tive LIKE-type f
ccc0: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 unction */.#defi
ccd0: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 ne SQLITE_FUNC_E
cce0: 50 48 45 4d 20 20 20 20 30 78 30 31 30 20 2f 2a PHEM 0x010 /*
ccf0: 20 45 70 68 65 6d 65 72 61 6c 2e 20 20 44 65 6c Ephemeral. Del
cd00: 65 74 65 20 77 69 74 68 20 56 44 42 45 20 2a 2f ete with VDBE */
cd10: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
cd20: 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 20 30 78 FUNC_NEEDCOLL 0x
cd30: 30 32 30 20 2f 2a 20 73 71 6c 69 74 65 33 47 65 020 /* sqlite3Ge
cd40: 74 46 75 6e 63 43 6f 6c 6c 53 65 71 28 29 20 6d tFuncCollSeq() m
cd50: 69 67 68 74 20 62 65 20 63 61 6c 6c 65 64 20 2a ight be called *
cd60: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
cd70: 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 20 20 20 30 _FUNC_LENGTH 0
cd80: 78 30 34 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e x040 /* Built-in
cd90: 20 6c 65 6e 67 74 68 28 29 20 66 75 6e 63 74 69 length() functi
cda0: 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 on */.#define SQ
cdb0: 4c 49 54 45 5f 46 55 4e 43 5f 54 59 50 45 4f 46 LITE_FUNC_TYPEOF
cdc0: 20 20 20 30 78 30 38 30 20 2f 2a 20 42 75 69 6c 0x080 /* Buil
cdd0: 74 2d 69 6e 20 74 79 70 65 6f 66 28 29 20 66 75 t-in typeof() fu
cde0: 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e nction */.#defin
cdf0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
ce00: 55 4e 54 20 20 20 20 30 78 31 30 30 20 2f 2a 20 UNT 0x100 /*
ce10: 42 75 69 6c 74 2d 69 6e 20 63 6f 75 6e 74 28 2a Built-in count(*
ce20: 29 20 61 67 67 72 65 67 61 74 65 20 2a 2f 0a 23 ) aggregate */.#
ce30: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
ce40: 4e 43 5f 43 4f 41 4c 45 53 43 45 20 30 78 32 30 NC_COALESCE 0x20
ce50: 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 63 6f 0 /* Built-in co
ce60: 61 6c 65 73 63 65 28 29 20 6f 72 20 69 66 6e 75 alesce() or ifnu
ce70: 6c 6c 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ll() */.#define
ce80: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 55 4e 4c 49 SQLITE_FUNC_UNLI
ce90: 4b 45 4c 59 20 30 78 34 30 30 20 2f 2a 20 42 75 KELY 0x400 /* Bu
cea0: 69 6c 74 2d 69 6e 20 75 6e 6c 69 6b 65 6c 79 28 ilt-in unlikely(
ceb0: 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 ) function */.#d
cec0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
ced0: 43 5f 43 4f 4e 53 54 41 4e 54 20 30 78 38 30 30 C_CONSTANT 0x800
cee0: 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 69 6e 70 /* Constant inp
cef0: 75 74 73 20 67 69 76 65 20 61 20 63 6f 6e 73 74 uts give a const
cf00: 61 6e 74 20 6f 75 74 70 75 74 20 2a 2f 0a 23 64 ant output */.#d
cf10: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
cf20: 43 5f 4d 49 4e 4d 41 58 20 20 30 78 31 30 30 30 C_MINMAX 0x1000
cf30: 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 6d 69 6e /* True for min
cf40: 28 29 20 61 6e 64 20 6d 61 78 28 29 20 61 67 67 () and max() agg
cf50: 72 65 67 61 74 65 73 20 2a 2f 0a 0a 2f 2a 0a 2a regates */../*.*
cf60: 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
cf70: 74 68 72 65 65 20 6d 61 63 72 6f 73 2c 20 46 55 three macros, FU
cf80: 4e 43 54 49 4f 4e 28 29 2c 20 4c 49 4b 45 46 55 NCTION(), LIKEFU
cf90: 4e 43 28 29 20 61 6e 64 20 41 47 47 52 45 47 41 NC() and AGGREGA
cfa0: 54 45 28 29 20 61 72 65 0a 2a 2a 20 75 73 65 64 TE() are.** used
cfb0: 20 74 6f 20 63 72 65 61 74 65 20 74 68 65 20 69 to create the i
cfc0: 6e 69 74 69 61 6c 69 7a 65 72 73 20 66 6f 72 20 nitializers for
cfd0: 74 68 65 20 46 75 6e 63 44 65 66 20 73 74 72 75 the FuncDef stru
cfe0: 63 74 75 72 65 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 ctures..**.**
cff0: 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 FUNCTION(zName,
d000: 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c nArg, iArg, bNC,
d010: 20 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 55 xFunc).** U
d020: 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 sed to create a
d030: 73 63 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 scalar function
d040: 64 65 66 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 definition of a
d050: 66 75 6e 63 74 69 6f 6e 20 7a 4e 61 6d 65 20 0a function zName .
d060: 2a 2a 20 20 20 20 20 69 6d 70 6c 65 6d 65 6e 74 ** implement
d070: 65 64 20 62 79 20 43 20 66 75 6e 63 74 69 6f 6e ed by C function
d080: 20 78 46 75 6e 63 20 74 68 61 74 20 61 63 63 65 xFunc that acce
d090: 70 74 73 20 6e 41 72 67 20 61 72 67 75 6d 65 6e pts nArg argumen
d0a0: 74 73 2e 20 54 68 65 0a 2a 2a 20 20 20 20 20 76 ts. The.** v
d0b0: 61 6c 75 65 20 70 61 73 73 65 64 20 61 73 20 69 alue passed as i
d0c0: 41 72 67 20 69 73 20 63 61 73 74 20 74 6f 20 61 Arg is cast to a
d0d0: 20 28 76 6f 69 64 2a 29 20 61 6e 64 20 6d 61 64 (void*) and mad
d0e0: 65 20 61 76 61 69 6c 61 62 6c 65 0a 2a 2a 20 20 e available.**
d0f0: 20 20 20 61 73 20 74 68 65 20 75 73 65 72 2d 64 as the user-d
d100: 61 74 61 20 28 73 71 6c 69 74 65 33 5f 75 73 65 ata (sqlite3_use
d110: 72 5f 64 61 74 61 28 29 29 20 66 6f 72 20 74 68 r_data()) for th
d120: 65 20 66 75 6e 63 74 69 6f 6e 2e 20 49 66 20 0a e function. If .
d130: 2a 2a 20 20 20 20 20 61 72 67 75 6d 65 6e 74 20 ** argument
d140: 62 4e 43 20 69 73 20 74 72 75 65 2c 20 74 68 65 bNC is true, the
d150: 6e 20 74 68 65 20 53 51 4c 49 54 45 5f 46 55 4e n the SQLITE_FUN
d160: 43 5f 4e 45 45 44 43 4f 4c 4c 20 66 6c 61 67 20 C_NEEDCOLL flag
d170: 69 73 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 is set..**.**
d180: 56 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c VFUNCTION(zName,
d190: 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 nArg, iArg, bNC
d1a0: 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 , xFunc).**
d1b0: 4c 69 6b 65 20 46 55 4e 43 54 49 4f 4e 20 65 78 Like FUNCTION ex
d1c0: 63 65 70 74 20 69 74 20 6f 6d 69 74 73 20 74 68 cept it omits th
d1d0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
d1e0: 4e 53 54 41 4e 54 20 66 6c 61 67 2e 0a 2a 2a 0a NSTANT flag..**.
d1f0: 2a 2a 20 20 20 41 47 47 52 45 47 41 54 45 28 7a ** AGGREGATE(z
d200: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 Name, nArg, iArg
d210: 2c 20 62 4e 43 2c 20 78 53 74 65 70 2c 20 78 46 , bNC, xStep, xF
d220: 69 6e 61 6c 29 0a 2a 2a 20 20 20 20 20 55 73 65 inal).** Use
d230: 64 20 74 6f 20 63 72 65 61 74 65 20 61 6e 20 61 d to create an a
d240: 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
d250: 6e 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 6d 70 n definition imp
d260: 6c 65 6d 65 6e 74 65 64 20 62 79 0a 2a 2a 20 20 lemented by.**
d270: 20 20 20 74 68 65 20 43 20 66 75 6e 63 74 69 6f the C functio
d280: 6e 73 20 78 53 74 65 70 20 61 6e 64 20 78 46 69 ns xStep and xFi
d290: 6e 61 6c 2e 20 54 68 65 20 66 69 72 73 74 20 66 nal. The first f
d2a0: 6f 75 72 20 70 61 72 61 6d 65 74 65 72 73 0a 2a our parameters.*
d2b0: 2a 20 20 20 20 20 61 72 65 20 69 6e 74 65 72 70 * are interp
d2c0: 72 65 74 65 64 20 69 6e 20 74 68 65 20 73 61 6d reted in the sam
d2d0: 65 20 77 61 79 20 61 73 20 74 68 65 20 66 69 72 e way as the fir
d2e0: 73 74 20 34 20 70 61 72 61 6d 65 74 65 72 73 20 st 4 parameters
d2f0: 74 6f 0a 2a 2a 20 20 20 20 20 46 55 4e 43 54 49 to.** FUNCTI
d300: 4f 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 4c 49 ON()..**.** LI
d310: 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 6e 41 KEFUNC(zName, nA
d320: 72 67 2c 20 70 41 72 67 2c 20 66 6c 61 67 73 29 rg, pArg, flags)
d330: 0a 2a 2a 20 20 20 20 20 55 73 65 64 20 74 6f 20 .** Used to
d340: 63 72 65 61 74 65 20 61 20 73 63 61 6c 61 72 20 create a scalar
d350: 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 function definit
d360: 69 6f 6e 20 6f 66 20 61 20 66 75 6e 63 74 69 6f ion of a functio
d370: 6e 20 7a 4e 61 6d 65 20 0a 2a 2a 20 20 20 20 20 n zName .**
d380: 74 68 61 74 20 61 63 63 65 70 74 73 20 6e 41 72 that accepts nAr
d390: 67 20 61 72 67 75 6d 65 6e 74 73 20 61 6e 64 20 g arguments and
d3a0: 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 is implemented b
d3b0: 79 20 61 20 63 61 6c 6c 20 74 6f 20 43 20 0a 2a y a call to C .*
d3c0: 2a 20 20 20 20 20 66 75 6e 63 74 69 6f 6e 20 6c * function l
d3d0: 69 6b 65 46 75 6e 63 2e 20 41 72 67 75 6d 65 6e ikeFunc. Argumen
d3e0: 74 20 70 41 72 67 20 69 73 20 63 61 73 74 20 74 t pArg is cast t
d3f0: 6f 20 61 20 28 76 6f 69 64 20 2a 29 20 61 6e 64 o a (void *) and
d400: 20 6d 61 64 65 0a 2a 2a 20 20 20 20 20 61 76 61 made.** ava
d410: 69 6c 61 62 6c 65 20 61 73 20 74 68 65 20 66 75 ilable as the fu
d420: 6e 63 74 69 6f 6e 20 75 73 65 72 2d 64 61 74 61 nction user-data
d430: 20 28 73 71 6c 69 74 65 33 5f 75 73 65 72 5f 64 (sqlite3_user_d
d440: 61 74 61 28 29 29 2e 20 54 68 65 0a 2a 2a 20 20 ata()). The.**
d450: 20 20 20 46 75 6e 63 44 65 66 2e 66 6c 61 67 73 FuncDef.flags
d460: 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 65 74 variable is set
d470: 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 70 61 to the value pa
d480: 73 73 65 64 20 61 73 20 74 68 65 20 66 6c 61 67 ssed as the flag
d490: 73 0a 2a 2a 20 20 20 20 20 70 61 72 61 6d 65 74 s.** paramet
d4a0: 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 46 er..*/.#define F
d4b0: 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e UNCTION(zName, n
d4c0: 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 Arg, iArg, bNC,
d4d0: 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 67 xFunc) \. {nArg
d4e0: 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f , SQLITE_FUNC_CO
d4f0: 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f 55 54 NSTANT|SQLITE_UT
d500: 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 F8|(bNC*SQLITE_F
d510: 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c UNC_NEEDCOLL), \
d520: 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 . SQLITE_INT_T
d530: 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 O_PTR(iArg), 0,
d540: 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e xFunc, 0, 0, #zN
d550: 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 ame, 0, 0}.#defi
d560: 6e 65 20 56 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 ne VFUNCTION(zNa
d570: 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 me, nArg, iArg,
d580: 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 bNC, xFunc) \.
d590: 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 {nArg, SQLITE_UT
d5a0: 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 F8|(bNC*SQLITE_F
d5b0: 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c UNC_NEEDCOLL), \
d5c0: 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 . SQLITE_INT_T
d5d0: 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 O_PTR(iArg), 0,
d5e0: 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e xFunc, 0, 0, #zN
d5f0: 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 ame, 0, 0}.#defi
d600: 6e 65 20 46 55 4e 43 54 49 4f 4e 32 28 7a 4e 61 ne FUNCTION2(zNa
d610: 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 me, nArg, iArg,
d620: 62 4e 43 2c 20 78 46 75 6e 63 2c 20 65 78 74 72 bNC, xFunc, extr
d630: 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 aFlags) \. {nAr
d640: 67 2c 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f g,SQLITE_FUNC_CO
d650: 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f 55 54 NSTANT|SQLITE_UT
d660: 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 F8|(bNC*SQLITE_F
d670: 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 7c 65 78 UNC_NEEDCOLL)|ex
d680: 74 72 61 46 6c 61 67 73 2c 5c 0a 20 20 20 53 51 traFlags,\. SQ
d690: 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 LITE_INT_TO_PTR(
d6a0: 69 41 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c iArg), 0, xFunc,
d6b0: 20 30 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 0, 0, #zName, 0
d6c0: 2c 20 30 7d 0a 23 64 65 66 69 6e 65 20 53 54 52 , 0}.#define STR
d6d0: 5f 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c _FUNCTION(zName,
d6e0: 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 62 4e 43 nArg, pArg, bNC
d6f0: 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 , xFunc) \. {nA
d700: 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f rg, SQLITE_FUNC_
d710: 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f CONSTANT|SQLITE_
d720: 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 UTF8|(bNC*SQLITE
d730: 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c _FUNC_NEEDCOLL),
d740: 20 5c 0a 20 20 20 70 41 72 67 2c 20 30 2c 20 78 \. pArg, 0, x
d750: 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 Func, 0, 0, #zNa
d760: 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 6e me, 0, 0}.#defin
d770: 65 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 e LIKEFUNC(zName
d780: 2c 20 6e 41 72 67 2c 20 61 72 67 2c 20 66 6c 61 , nArg, arg, fla
d790: 67 73 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 gs) \. {nArg, S
d7a0: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 QLITE_FUNC_CONST
d7b0: 41 4e 54 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c ANT|SQLITE_UTF8|
d7c0: 66 6c 61 67 73 2c 20 5c 0a 20 20 20 28 76 6f 69 flags, \. (voi
d7d0: 64 20 2a 29 61 72 67 2c 20 30 2c 20 6c 69 6b 65 d *)arg, 0, like
d7e0: 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 Func, 0, 0, #zNa
d7f0: 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 6e me, 0, 0}.#defin
d800: 65 20 41 47 47 52 45 47 41 54 45 28 7a 4e 61 6d e AGGREGATE(zNam
d810: 65 2c 20 6e 41 72 67 2c 20 61 72 67 2c 20 6e 63 e, nArg, arg, nc
d820: 2c 20 78 53 74 65 70 2c 20 78 46 69 6e 61 6c 29 , xStep, xFinal)
d830: 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 \. {nArg, SQLI
d840: 54 45 5f 55 54 46 38 7c 28 6e 63 2a 53 51 4c 49 TE_UTF8|(nc*SQLI
d850: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
d860: 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 ), \. SQLITE_I
d870: 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 2c 20 NT_TO_PTR(arg),
d880: 30 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 69 6e 0, 0, xStep,xFin
d890: 61 6c 2c 23 7a 4e 61 6d 65 2c 30 2c 30 7d 0a 23 al,#zName,0,0}.#
d8a0: 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 54 45 define AGGREGATE
d8b0: 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 2(zName, nArg, a
d8c0: 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 78 rg, nc, xStep, x
d8d0: 46 69 6e 61 6c 2c 20 65 78 74 72 61 46 6c 61 67 Final, extraFlag
d8e0: 73 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 s) \. {nArg, SQ
d8f0: 4c 49 54 45 5f 55 54 46 38 7c 28 6e 63 2a 53 51 LITE_UTF8|(nc*SQ
d900: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
d910: 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 20 LL)|extraFlags,
d920: 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f \. SQLITE_INT_
d930: 54 4f 5f 50 54 52 28 61 72 67 29 2c 20 30 2c 20 TO_PTR(arg), 0,
d940: 30 2c 20 78 53 74 65 70 2c 78 46 69 6e 61 6c 2c 0, xStep,xFinal,
d950: 23 7a 4e 61 6d 65 2c 30 2c 30 7d 0a 0a 2f 2a 0a #zName,0,0}../*.
d960: 2a 2a 20 41 6c 6c 20 63 75 72 72 65 6e 74 20 73 ** All current s
d970: 61 76 65 70 6f 69 6e 74 73 20 61 72 65 20 73 74 avepoints are st
d980: 6f 72 65 64 20 69 6e 20 61 20 6c 69 6e 6b 65 64 ored in a linked
d990: 20 6c 69 73 74 20 73 74 61 72 74 69 6e 67 20 61 list starting a
d9a0: 74 0a 2a 2a 20 73 71 6c 69 74 65 33 2e 70 53 61 t.** sqlite3.pSa
d9b0: 76 65 70 6f 69 6e 74 2e 20 54 68 65 20 66 69 72 vepoint. The fir
d9c0: 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e 20 74 68 st element in th
d9d0: 65 20 6c 69 73 74 20 69 73 20 74 68 65 20 6d 6f e list is the mo
d9e0: 73 74 20 72 65 63 65 6e 74 6c 79 0a 2a 2a 20 6f st recently.** o
d9f0: 70 65 6e 65 64 20 73 61 76 65 70 6f 69 6e 74 2e pened savepoint.
da00: 20 53 61 76 65 70 6f 69 6e 74 73 20 61 72 65 20 Savepoints are
da10: 61 64 64 65 64 20 74 6f 20 74 68 65 20 6c 69 73 added to the lis
da20: 74 20 62 79 20 74 68 65 20 76 64 62 65 0a 2a 2a t by the vdbe.**
da30: 20 4f 50 5f 53 61 76 65 70 6f 69 6e 74 20 69 6e OP_Savepoint in
da40: 73 74 72 75 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 struction..*/.st
da50: 72 75 63 74 20 53 61 76 65 70 6f 69 6e 74 20 7b ruct Savepoint {
da60: 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
da70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
da80: 20 20 20 20 20 20 20 2f 2a 20 53 61 76 65 70 6f /* Savepo
da90: 69 6e 74 20 6e 61 6d 65 20 28 6e 75 6c 2d 74 65 int name (nul-te
daa0: 72 6d 69 6e 61 74 65 64 29 20 2a 2f 0a 20 20 69 rminated) */. i
dab0: 36 34 20 6e 44 65 66 65 72 72 65 64 43 6f 6e 73 64 nDeferredCons
dac0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
dad0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
dae0: 64 65 66 65 72 72 65 64 20 66 6b 20 76 69 6f 6c deferred fk viol
daf0: 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 36 34 20 ations */. i64
db00: 6e 44 65 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 nDeferredImmCons
db10: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
db20: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 64 65 66 /* Number of def
db30: 65 72 72 65 64 20 69 6d 6d 20 66 6b 2e 20 2a 2f erred imm fk. */
db40: 0a 20 20 53 61 76 65 70 6f 69 6e 74 20 2a 70 4e . Savepoint *pN
db50: 65 78 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ext;
db60: 20 20 20 20 20 20 20 2f 2a 20 50 61 72 65 6e 74 /* Parent
db70: 20 73 61 76 65 70 6f 69 6e 74 20 28 69 66 20 61 savepoint (if a
db80: 6e 79 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ny) */.};../*.**
db90: 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 The following a
dba0: 72 65 20 75 73 65 64 20 61 73 20 74 68 65 20 73 re used as the s
dbb0: 65 63 6f 6e 64 20 70 61 72 61 6d 65 74 65 72 20 econd parameter
dbc0: 74 6f 20 73 71 6c 69 74 65 33 53 61 76 65 70 6f to sqlite3Savepo
dbd0: 69 6e 74 28 29 2c 0a 2a 2a 20 61 6e 64 20 61 73 int(),.** and as
dbe0: 20 74 68 65 20 50 31 20 61 72 67 75 6d 65 6e 74 the P1 argument
dbf0: 20 74 6f 20 74 68 65 20 4f 50 5f 53 61 76 65 70 to the OP_Savep
dc00: 6f 69 6e 74 20 69 6e 73 74 72 75 63 74 69 6f 6e oint instruction
dc10: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 41 56 ..*/.#define SAV
dc20: 45 50 4f 49 4e 54 5f 42 45 47 49 4e 20 20 20 20 EPOINT_BEGIN
dc30: 20 20 30 0a 23 64 65 66 69 6e 65 20 53 41 56 45 0.#define SAVE
dc40: 50 4f 49 4e 54 5f 52 45 4c 45 41 53 45 20 20 20 POINT_RELEASE
dc50: 20 31 0a 23 64 65 66 69 6e 65 20 53 41 56 45 50 1.#define SAVEP
dc60: 4f 49 4e 54 5f 52 4f 4c 4c 42 41 43 4b 20 20 20 OINT_ROLLBACK
dc70: 32 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 2.../*.** Each S
dc80: 51 4c 69 74 65 20 6d 6f 64 75 6c 65 20 28 76 69 QLite module (vi
dc90: 72 74 75 61 6c 20 74 61 62 6c 65 20 64 65 66 69 rtual table defi
dca0: 6e 69 74 69 6f 6e 29 20 69 73 20 64 65 66 69 6e nition) is defin
dcb0: 65 64 20 62 79 20 61 6e 0a 2a 2a 20 69 6e 73 74 ed by an.** inst
dcc0: 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c ance of the foll
dcd0: 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2c owing structure,
dce0: 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 73 stored in the s
dcf0: 71 6c 69 74 65 33 2e 61 4d 6f 64 75 6c 65 0a 2a qlite3.aModule.*
dd00: 2a 20 68 61 73 68 20 74 61 62 6c 65 2e 0a 2a 2f * hash table..*/
dd10: 0a 73 74 72 75 63 74 20 4d 6f 64 75 6c 65 20 7b .struct Module {
dd20: 0a 20 20 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 . const sqlite3
dd30: 5f 6d 6f 64 75 6c 65 20 2a 70 4d 6f 64 75 6c 65 _module *pModule
dd40: 3b 20 20 20 20 20 20 20 2f 2a 20 43 61 6c 6c 62 ; /* Callb
dd50: 61 63 6b 20 70 6f 69 6e 74 65 72 73 20 2a 2f 0a ack pointers */.
dd60: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e const char *zN
dd70: 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
dd80: 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 70 /* Name p
dd90: 61 73 73 65 64 20 74 6f 20 63 72 65 61 74 65 5f assed to create_
dda0: 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 76 6f module() */. vo
ddb0: 69 64 20 2a 70 41 75 78 3b 20 20 20 20 20 20 20 id *pAux;
ddc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ddd0: 20 20 20 2f 2a 20 70 41 75 78 20 70 61 73 73 65 /* pAux passe
dde0: 64 20 74 6f 20 63 72 65 61 74 65 5f 6d 6f 64 75 d to create_modu
ddf0: 6c 65 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 28 le() */. void (
de00: 2a 78 44 65 73 74 72 6f 79 29 28 76 6f 69 64 20 *xDestroy)(void
de10: 2a 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f *); /
de20: 2a 20 4d 6f 64 75 6c 65 20 64 65 73 74 72 75 63 * Module destruc
de30: 74 6f 72 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a tor function */.
de40: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e 66 6f 72 6d };../*.** inform
de50: 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 ation about each
de60: 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 6e 20 53 51 column of an SQ
de70: 4c 20 74 61 62 6c 65 20 69 73 20 68 65 6c 64 20 L table is held
de80: 69 6e 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a in an instance.*
de90: 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 * of this struct
dea0: 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 43 ure..*/.struct C
deb0: 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 61 72 20 2a olumn {. char *
dec0: 7a 4e 61 6d 65 3b 20 20 20 20 20 2f 2a 20 4e 61 zName; /* Na
ded0: 6d 65 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d me of this colum
dee0: 6e 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 44 66 n */. Expr *pDf
def0: 6c 74 3b 20 20 20 20 20 2f 2a 20 44 65 66 61 75 lt; /* Defau
df00: 6c 74 20 76 61 6c 75 65 20 6f 66 20 74 68 69 73 lt value of this
df10: 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 63 68 61 column */. cha
df20: 72 20 2a 7a 44 66 6c 74 3b 20 20 20 20 20 2f 2a r *zDflt; /*
df30: 20 4f 72 69 67 69 6e 61 6c 20 74 65 78 74 20 6f Original text o
df40: 66 20 74 68 65 20 64 65 66 61 75 6c 74 20 76 61 f the default va
df50: 6c 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a lue */. char *z
df60: 54 79 70 65 3b 20 20 20 20 20 2f 2a 20 44 61 74 Type; /* Dat
df70: 61 20 74 79 70 65 20 66 6f 72 20 74 68 69 73 20 a type for this
df80: 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 63 68 61 72 column */. char
df90: 20 2a 7a 43 6f 6c 6c 3b 20 20 20 20 20 2f 2a 20 *zColl; /*
dfa0: 43 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e Collating sequen
dfb0: 63 65 2e 20 20 49 66 20 4e 55 4c 4c 2c 20 75 73 ce. If NULL, us
dfc0: 65 20 74 68 65 20 64 65 66 61 75 6c 74 20 2a 2f e the default */
dfd0: 0a 20 20 75 38 20 6e 6f 74 4e 75 6c 6c 3b 20 20 . u8 notNull;
dfe0: 20 20 20 20 2f 2a 20 41 6e 20 4f 45 5f 20 63 6f /* An OE_ co
dff0: 64 65 20 66 6f 72 20 68 61 6e 64 6c 69 6e 67 20 de for handling
e000: 61 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e 73 74 a NOT NULL const
e010: 72 61 69 6e 74 20 2a 2f 0a 20 20 63 68 61 72 20 raint */. char
e020: 61 66 66 69 6e 69 74 79 3b 20 20 20 2f 2a 20 4f affinity; /* O
e030: 6e 65 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 ne of the SQLITE
e040: 5f 41 46 46 5f 2e 2e 2e 20 76 61 6c 75 65 73 20 _AFF_... values
e050: 2a 2f 0a 20 20 75 38 20 73 7a 45 73 74 3b 20 20 */. u8 szEst;
e060: 20 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 /* Estimat
e070: 65 64 20 73 69 7a 65 20 6f 66 20 74 68 69 73 20 ed size of this
e080: 63 6f 6c 75 6d 6e 2e 20 20 49 4e 54 3d 3d 31 20 column. INT==1
e090: 2a 2f 0a 20 20 75 38 20 63 6f 6c 46 6c 61 67 73 */. u8 colFlags
e0a0: 3b 20 20 20 20 20 2f 2a 20 42 6f 6f 6c 65 61 6e ; /* Boolean
e0b0: 20 70 72 6f 70 65 72 74 69 65 73 2e 20 20 53 65 properties. Se
e0c0: 65 20 43 4f 4c 46 4c 41 47 5f 20 64 65 66 69 6e e COLFLAG_ defin
e0d0: 65 73 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 0a es below */.};..
e0e0: 2f 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 /* Allowed value
e0f0: 73 20 66 6f 72 20 43 6f 6c 75 6d 6e 2e 63 6f 6c s for Column.col
e100: 46 6c 61 67 73 3a 0a 2a 2f 0a 23 64 65 66 69 6e Flags:.*/.#defin
e110: 65 20 43 4f 4c 46 4c 41 47 5f 50 52 49 4d 4b 45 e COLFLAG_PRIMKE
e120: 59 20 20 30 78 30 30 30 31 20 20 20 20 2f 2a 20 Y 0x0001 /*
e130: 43 6f 6c 75 6d 6e 20 69 73 20 70 61 72 74 20 6f Column is part o
e140: 66 20 74 68 65 20 70 72 69 6d 61 72 79 20 6b 65 f the primary ke
e150: 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 4c y */.#define COL
e160: 46 4c 41 47 5f 48 49 44 44 45 4e 20 20 20 30 78 FLAG_HIDDEN 0x
e170: 30 30 30 32 20 20 20 20 2f 2a 20 41 20 68 69 64 0002 /* A hid
e180: 64 65 6e 20 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 den column in a
e190: 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 2a 2f virtual table */
e1a0: 0a 0a 2f 2a 0a 2a 2a 20 41 20 22 43 6f 6c 6c 61 ../*.** A "Colla
e1b0: 74 69 6e 67 20 53 65 71 75 65 6e 63 65 22 20 69 ting Sequence" i
e1c0: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 20 s defined by an
e1d0: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
e1e0: 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 following.** str
e1f0: 75 63 74 75 72 65 2e 20 43 6f 6e 63 65 70 74 75 ucture. Conceptu
e200: 61 6c 6c 79 2c 20 61 20 63 6f 6c 6c 61 74 69 6e ally, a collatin
e210: 67 20 73 65 71 75 65 6e 63 65 20 63 6f 6e 73 69 g sequence consi
e220: 73 74 73 20 6f 66 20 61 20 6e 61 6d 65 20 61 6e sts of a name an
e230: 64 0a 2a 2a 20 61 20 63 6f 6d 70 61 72 69 73 6f d.** a compariso
e240: 6e 20 72 6f 75 74 69 6e 65 20 74 68 61 74 20 64 n routine that d
e250: 65 66 69 6e 65 73 20 74 68 65 20 6f 72 64 65 72 efines the order
e260: 20 6f 66 20 74 68 61 74 20 73 65 71 75 65 6e 63 of that sequenc
e270: 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 43 6f 6c 6c e..**.** If Coll
e280: 53 65 71 2e 78 43 6d 70 20 69 73 20 4e 55 4c 4c Seq.xCmp is NULL
e290: 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 , it means that
e2a0: 74 68 65 0a 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 the.** collating
e2b0: 20 73 65 71 75 65 6e 63 65 20 69 73 20 75 6e 64 sequence is und
e2c0: 65 66 69 6e 65 64 2e 20 20 49 6e 64 69 63 65 73 efined. Indices
e2d0: 20 62 75 69 6c 74 20 6f 6e 20 61 6e 20 75 6e 64 built on an und
e2e0: 65 66 69 6e 65 64 0a 2a 2a 20 63 6f 6c 6c 61 74 efined.** collat
e2f0: 69 6e 67 20 73 65 71 75 65 6e 63 65 20 6d 61 79 ing sequence may
e300: 20 6e 6f 74 20 62 65 20 72 65 61 64 20 6f 72 20 not be read or
e310: 77 72 69 74 74 65 6e 2e 0a 2a 2f 0a 73 74 72 75 written..*/.stru
e320: 63 74 20 43 6f 6c 6c 53 65 71 20 7b 0a 20 20 63 ct CollSeq {. c
e330: 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
e340: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
e350: 74 68 65 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 the collating se
e360: 71 75 65 6e 63 65 2c 20 55 54 46 2d 38 20 65 6e quence, UTF-8 en
e370: 63 6f 64 65 64 20 2a 2f 0a 20 20 75 38 20 65 6e coded */. u8 en
e380: 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
e390: 20 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e /* Text encodin
e3a0: 67 20 68 61 6e 64 6c 65 64 20 62 79 20 78 43 6d g handled by xCm
e3b0: 70 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 p() */. void *p
e3c0: 55 73 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f User; /
e3d0: 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 * First argument
e3e0: 20 74 6f 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 to xCmp() */.
e3f0: 69 6e 74 20 28 2a 78 43 6d 70 29 28 76 6f 69 64 int (*xCmp)(void
e400: 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 *,int, const voi
e410: 64 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 76 d*, int, const v
e420: 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 64 20 28 2a oid*);. void (*
e430: 78 44 65 6c 29 28 76 6f 69 64 2a 29 3b 20 20 2f xDel)(void*); /
e440: 2a 20 44 65 73 74 72 75 63 74 6f 72 20 66 6f 72 * Destructor for
e450: 20 70 55 73 65 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a pUser */.};../*
e460: 0a 2a 2a 20 41 20 73 6f 72 74 20 6f 72 64 65 72 .** A sort order
e470: 20 63 61 6e 20 62 65 20 65 69 74 68 65 72 20 41 can be either A
e480: 53 43 20 6f 72 20 44 45 53 43 2e 0a 2a 2f 0a 23 SC or DESC..*/.#
e490: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f define SQLITE_SO
e4a0: 5f 41 53 43 20 20 20 20 20 20 20 30 20 20 2f 2a _ASC 0 /*
e4b0: 20 53 6f 72 74 20 69 6e 20 61 73 63 65 6e 64 69 Sort in ascendi
e4c0: 6e 67 20 6f 72 64 65 72 20 2a 2f 0a 23 64 65 66 ng order */.#def
e4d0: 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f 44 45 ine SQLITE_SO_DE
e4e0: 53 43 20 20 20 20 20 20 31 20 20 2f 2a 20 53 6f SC 1 /* So
e4f0: 72 74 20 69 6e 20 61 73 63 65 6e 64 69 6e 67 20 rt in ascending
e500: 6f 72 64 65 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 order */../*.**
e510: 43 6f 6c 75 6d 6e 20 61 66 66 69 6e 69 74 79 20 Column affinity
e520: 74 79 70 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 types..**.** The
e530: 73 65 20 75 73 65 64 20 74 6f 20 68 61 76 65 20 se used to have
e540: 6d 6e 65 6d 6f 6e 69 63 20 6e 61 6d 65 20 6c 69 mnemonic name li
e550: 6b 65 20 27 69 27 20 66 6f 72 20 53 51 4c 49 54 ke 'i' for SQLIT
e560: 45 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 61 6e E_AFF_INTEGER an
e570: 64 0a 2a 2a 20 27 74 27 20 66 6f 72 20 53 51 4c d.** 't' for SQL
e580: 49 54 45 5f 41 46 46 5f 54 45 58 54 2e 20 20 42 ITE_AFF_TEXT. B
e590: 75 74 20 77 65 20 63 61 6e 20 73 61 76 65 20 61 ut we can save a
e5a0: 20 6c 69 74 74 6c 65 20 73 70 61 63 65 20 61 6e little space an
e5b0: 64 20 69 6d 70 72 6f 76 65 0a 2a 2a 20 74 68 65 d improve.** the
e5c0: 20 73 70 65 65 64 20 61 20 6c 69 74 74 6c 65 20 speed a little
e5d0: 62 79 20 6e 75 6d 62 65 72 69 6e 67 20 74 68 65 by numbering the
e5e0: 20 76 61 6c 75 65 73 20 63 6f 6e 73 65 63 75 74 values consecut
e5f0: 69 76 65 6c 79 2e 20 20 0a 2a 2a 0a 2a 2a 20 42 ively. .**.** B
e600: 75 74 20 72 61 74 68 65 72 20 74 68 61 6e 20 73 ut rather than s
e610: 74 61 72 74 20 77 69 74 68 20 30 20 6f 72 20 31 tart with 0 or 1
e620: 2c 20 77 65 20 62 65 67 69 6e 20 77 69 74 68 20 , we begin with
e630: 27 41 27 2e 20 20 54 68 61 74 20 77 61 79 2c 0a 'A'. That way,.
e640: 2a 2a 20 77 68 65 6e 20 6d 75 6c 74 69 70 6c 65 ** when multiple
e650: 20 61 66 66 69 6e 69 74 79 20 74 79 70 65 73 20 affinity types
e660: 61 72 65 20 63 6f 6e 63 61 74 65 6e 61 74 65 64 are concatenated
e670: 20 69 6e 74 6f 20 61 20 73 74 72 69 6e 67 20 61 into a string a
e680: 6e 64 0a 2a 2a 20 75 73 65 64 20 61 73 20 74 68 nd.** used as th
e690: 65 20 50 34 20 6f 70 65 72 61 6e 64 2c 20 74 68 e P4 operand, th
e6a0: 65 79 20 77 69 6c 6c 20 62 65 20 6d 6f 72 65 20 ey will be more
e6b0: 72 65 61 64 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 readable..**.**
e6c0: 4e 6f 74 65 20 61 6c 73 6f 20 74 68 61 74 20 74 Note also that t
e6d0: 68 65 20 6e 75 6d 65 72 69 63 20 74 79 70 65 73 he numeric types
e6e0: 20 61 72 65 20 67 72 6f 75 70 65 64 20 74 6f 67 are grouped tog
e6f0: 65 74 68 65 72 20 73 6f 20 74 68 61 74 20 74 65 ether so that te
e700: 73 74 69 6e 67 0a 2a 2a 20 66 6f 72 20 61 20 6e sting.** for a n
e710: 75 6d 65 72 69 63 20 74 79 70 65 20 69 73 20 61 umeric type is a
e720: 20 73 69 6e 67 6c 65 20 63 6f 6d 70 61 72 69 73 single comparis
e730: 6f 6e 2e 20 20 41 6e 64 20 74 68 65 20 42 4c 4f on. And the BLO
e740: 42 20 74 79 70 65 20 69 73 20 66 69 72 73 74 2e B type is first.
e750: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
e760: 54 45 5f 41 46 46 5f 42 4c 4f 42 20 20 20 20 20 TE_AFF_BLOB
e770: 27 41 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 'A'.#define SQLI
e780: 54 45 5f 41 46 46 5f 54 45 58 54 20 20 20 20 20 TE_AFF_TEXT
e790: 27 42 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 'B'.#define SQLI
e7a0: 54 45 5f 41 46 46 5f 4e 55 4d 45 52 49 43 20 20 TE_AFF_NUMERIC
e7b0: 27 43 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 'C'.#define SQLI
e7c0: 54 45 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 20 TE_AFF_INTEGER
e7d0: 27 44 27 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 'D'.#define SQLI
e7e0: 54 45 5f 41 46 46 5f 52 45 41 4c 20 20 20 20 20 TE_AFF_REAL
e7f0: 27 45 27 0a 0a 23 64 65 66 69 6e 65 20 73 71 6c 'E'..#define sql
e800: 69 74 65 33 49 73 4e 75 6d 65 72 69 63 41 66 66 ite3IsNumericAff
e810: 69 6e 69 74 79 28 58 29 20 20 28 28 58 29 3e 3d inity(X) ((X)>=
e820: 53 51 4c 49 54 45 5f 41 46 46 5f 4e 55 4d 45 52 SQLITE_AFF_NUMER
e830: 49 43 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 IC)../*.** The S
e840: 51 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b 20 76 QLITE_AFF_MASK v
e850: 61 6c 75 65 73 20 6d 61 73 6b 73 20 6f 66 66 20 alues masks off
e860: 74 68 65 20 73 69 67 6e 69 66 69 63 61 6e 74 20 the significant
e870: 62 69 74 73 20 6f 66 20 61 6e 0a 2a 2a 20 61 66 bits of an.** af
e880: 66 69 6e 69 74 79 20 76 61 6c 75 65 2e 20 0a 2a finity value. .*
e890: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e8a0: 5f 41 46 46 5f 4d 41 53 4b 20 20 20 20 20 30 78 _AFF_MASK 0x
e8b0: 34 37 0a 0a 2f 2a 0a 2a 2a 20 41 64 64 69 74 69 47../*.** Additi
e8c0: 6f 6e 61 6c 20 62 69 74 20 76 61 6c 75 65 73 20 onal bit values
e8d0: 74 68 61 74 20 63 61 6e 20 62 65 20 4f 52 65 64 that can be ORed
e8e0: 20 77 69 74 68 20 61 6e 20 61 66 66 69 6e 69 74 with an affinit
e8f0: 79 20 77 69 74 68 6f 75 74 0a 2a 2a 20 63 68 61 y without.** cha
e900: 6e 67 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 nging the affini
e910: 74 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 53 51 ty..**.** The SQ
e920: 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c 20 66 6c 61 LITE_NOTNULL fla
e930: 67 20 69 73 20 61 20 63 6f 6d 62 69 6e 61 74 69 g is a combinati
e940: 6f 6e 20 6f 66 20 4e 55 4c 4c 45 51 20 61 6e 64 on of NULLEQ and
e950: 20 4a 55 4d 50 49 46 4e 55 4c 4c 2e 0a 2a 2a 20 JUMPIFNULL..**
e960: 49 74 20 63 61 75 73 65 73 20 61 6e 20 61 73 73 It causes an ass
e970: 65 72 74 28 29 20 74 6f 20 66 69 72 65 20 69 66 ert() to fire if
e980: 20 65 69 74 68 65 72 20 6f 70 65 72 61 6e 64 20 either operand
e990: 74 6f 20 61 20 63 6f 6d 70 61 72 69 73 6f 6e 0a to a comparison.
e9a0: 2a 2a 20 6f 70 65 72 61 74 6f 72 20 69 73 20 4e ** operator is N
e9b0: 55 4c 4c 2e 20 20 49 74 20 69 73 20 61 64 64 65 ULL. It is adde
e9c0: 64 20 74 6f 20 63 65 72 74 61 69 6e 20 63 6f 6d d to certain com
e9d0: 70 61 72 69 73 6f 6e 20 6f 70 65 72 61 74 6f 72 parison operator
e9e0: 73 20 74 6f 0a 2a 2a 20 70 72 6f 76 65 20 74 68 s to.** prove th
e9f0: 61 74 20 74 68 65 20 6f 70 65 72 61 6e 64 73 20 at the operands
ea00: 61 72 65 20 61 6c 77 61 79 73 20 4e 4f 54 20 4e are always NOT N
ea10: 55 4c 4c 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ULL..*/.#define
ea20: 53 51 4c 49 54 45 5f 4a 55 4d 50 49 46 4e 55 4c SQLITE_JUMPIFNUL
ea30: 4c 20 20 20 30 78 31 30 20 20 2f 2a 20 6a 75 6d L 0x10 /* jum
ea40: 70 73 20 69 66 20 65 69 74 68 65 72 20 6f 70 65 ps if either ope
ea50: 72 61 6e 64 20 69 73 20 4e 55 4c 4c 20 2a 2f 0a rand is NULL */.
ea60: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
ea70: 54 4f 52 45 50 32 20 20 20 20 20 20 30 78 32 30 TOREP2 0x20
ea80: 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
ea90: 74 20 69 6e 20 72 65 67 5b 50 32 5d 20 72 61 74 t in reg[P2] rat
eaa0: 68 65 72 20 74 68 61 6e 20 6a 75 6d 70 20 2a 2f her than jump */
eab0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
eac0: 4e 55 4c 4c 45 51 20 20 20 20 20 20 20 30 78 38 NULLEQ 0x8
ead0: 30 20 20 2f 2a 20 4e 55 4c 4c 3d 4e 55 4c 4c 20 0 /* NULL=NULL
eae0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
eaf0: 45 5f 4e 4f 54 4e 55 4c 4c 20 20 20 20 20 20 30 E_NOTNULL 0
eb00: 78 39 30 20 20 2f 2a 20 41 73 73 65 72 74 20 74 x90 /* Assert t
eb10: 68 61 74 20 6f 70 65 72 61 6e 64 73 20 61 72 65 hat operands are
eb20: 20 6e 65 76 65 72 20 4e 55 4c 4c 20 2a 2f 0a 0a never NULL */..
eb30: 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 63 74 20 /*.** An object
eb40: 6f 66 20 74 68 69 73 20 74 79 70 65 20 69 73 20 of this type is
eb50: 63 72 65 61 74 65 64 20 66 6f 72 20 65 61 63 68 created for each
eb60: 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 70 virtual table p
eb70: 72 65 73 65 6e 74 20 69 6e 0a 2a 2a 20 74 68 65 resent in.** the
eb80: 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 database schema
eb90: 2e 20 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 . .**.** If the
eba0: 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 database schema
ebb0: 69 73 20 73 68 61 72 65 64 2c 20 74 68 65 6e 20 is shared, then
ebc0: 74 68 65 72 65 20 69 73 20 6f 6e 65 20 69 6e 73 there is one ins
ebd0: 74 61 6e 63 65 20 6f 66 20 74 68 69 73 0a 2a 2a tance of this.**
ebe0: 20 73 74 72 75 63 74 75 72 65 20 66 6f 72 20 65 structure for e
ebf0: 61 63 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e ach database con
ec00: 6e 65 63 74 69 6f 6e 20 28 73 71 6c 69 74 65 33 nection (sqlite3
ec10: 2a 29 20 74 68 61 74 20 75 73 65 73 20 74 68 65 *) that uses the
ec20: 20 73 68 61 72 65 64 0a 2a 2a 20 73 63 68 65 6d shared.** schem
ec30: 61 2e 20 54 68 69 73 20 69 73 20 62 65 63 61 75 a. This is becau
ec40: 73 65 20 65 61 63 68 20 64 61 74 61 62 61 73 65 se each database
ec50: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 71 75 connection requ
ec60: 69 72 65 73 20 69 74 73 20 6f 77 6e 20 75 6e 69 ires its own uni
ec70: 71 75 65 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 20 que.** instance
ec80: 6f 66 20 74 68 65 20 73 71 6c 69 74 65 33 5f 76 of the sqlite3_v
ec90: 74 61 62 2a 20 68 61 6e 64 6c 65 20 75 73 65 64 tab* handle used
eca0: 20 74 6f 20 61 63 63 65 73 73 20 74 68 65 20 76 to access the v
ecb0: 69 72 74 75 61 6c 20 74 61 62 6c 65 20 0a 2a 2a irtual table .**
ecc0: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e implementation.
ecd0: 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 sqlite3_vtab* h
ece0: 61 6e 64 6c 65 73 20 63 61 6e 20 6e 6f 74 20 62 andles can not b
ecf0: 65 20 73 68 61 72 65 64 20 62 65 74 77 65 65 6e e shared between
ed00: 20 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 6f .** database co
ed10: 6e 6e 65 63 74 69 6f 6e 73 2c 20 65 76 65 6e 20 nnections, even
ed20: 77 68 65 6e 20 74 68 65 20 72 65 73 74 20 6f 66 when the rest of
ed30: 20 74 68 65 20 69 6e 2d 6d 65 6d 6f 72 79 20 64 the in-memory d
ed40: 61 74 61 62 61 73 65 20 0a 2a 2a 20 73 63 68 65 atabase .** sche
ed50: 6d 61 20 69 73 20 73 68 61 72 65 64 2c 20 61 73 ma is shared, as
ed60: 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 the implementat
ed70: 69 6f 6e 20 6f 66 74 65 6e 20 73 74 6f 72 65 73 ion often stores
ed80: 20 74 68 65 20 64 61 74 61 62 61 73 65 0a 2a 2a the database.**
ed90: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 connection hand
eda0: 6c 65 20 70 61 73 73 65 64 20 74 6f 20 69 74 20 le passed to it
edb0: 76 69 61 20 74 68 65 20 78 43 6f 6e 6e 65 63 74 via the xConnect
edc0: 28 29 20 6f 72 20 78 43 72 65 61 74 65 28 29 20 () or xCreate()
edd0: 6d 65 74 68 6f 64 0a 2a 2a 20 64 75 72 69 6e 67 method.** during
ede0: 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
edf0: 69 6e 74 65 72 6e 61 6c 6c 79 2e 20 54 68 69 73 internally. This
ee00: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
ee10: 74 69 6f 6e 20 68 61 6e 64 6c 65 20 6d 61 79 0a tion handle may.
ee20: 2a 2a 20 74 68 65 6e 20 62 65 20 75 73 65 64 20 ** then be used
ee30: 62 79 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 by the virtual t
ee40: 61 62 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 able implementat
ee50: 69 6f 6e 20 74 6f 20 61 63 63 65 73 73 20 72 65 ion to access re
ee60: 61 6c 20 74 61 62 6c 65 73 20 0a 2a 2a 20 77 69 al tables .** wi
ee70: 74 68 69 6e 20 74 68 65 20 64 61 74 61 62 61 73 thin the databas
ee80: 65 2e 20 53 6f 20 74 68 61 74 20 74 68 65 79 20 e. So that they
ee90: 61 70 70 65 61 72 20 61 73 20 70 61 72 74 20 6f appear as part o
eea0: 66 20 74 68 65 20 63 61 6c 6c 65 72 73 20 0a 2a f the callers .*
eeb0: 2a 20 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 74 * transaction, t
eec0: 68 65 73 65 20 61 63 63 65 73 73 65 73 20 6e 65 hese accesses ne
eed0: 65 64 20 74 6f 20 62 65 20 6d 61 64 65 20 76 69 ed to be made vi
eee0: 61 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 62 a the same datab
eef0: 61 73 65 20 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 ase .** connecti
ef00: 6f 6e 20 61 73 20 74 68 61 74 20 75 73 65 64 20 on as that used
ef10: 74 6f 20 65 78 65 63 75 74 65 20 53 51 4c 20 6f to execute SQL o
ef20: 70 65 72 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 perations on the
ef30: 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0a virtual table..
ef40: 2a 2a 0a 2a 2a 20 41 6c 6c 20 56 54 61 62 6c 65 **.** All VTable
ef50: 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 63 6f objects that co
ef60: 72 72 65 73 70 6f 6e 64 20 74 6f 20 61 20 73 69 rrespond to a si
ef70: 6e 67 6c 65 20 74 61 62 6c 65 20 69 6e 20 61 20 ngle table in a
ef80: 73 68 61 72 65 64 0a 2a 2a 20 64 61 74 61 62 61 shared.** databa
ef90: 73 65 20 73 63 68 65 6d 61 20 61 72 65 20 69 6e se schema are in
efa0: 69 74 69 61 6c 6c 79 20 73 74 6f 72 65 64 20 69 itially stored i
efb0: 6e 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 n a linked-list
efc0: 70 6f 69 6e 74 65 64 20 74 6f 20 62 79 0a 2a 2a pointed to by.**
efd0: 20 74 68 65 20 54 61 62 6c 65 2e 70 56 54 61 62 the Table.pVTab
efe0: 6c 65 20 6d 65 6d 62 65 72 20 76 61 72 69 61 62 le member variab
eff0: 6c 65 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 le of the corres
f000: 70 6f 6e 64 69 6e 67 20 54 61 62 6c 65 20 6f 62 ponding Table ob
f010: 6a 65 63 74 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e ject..** When an
f020: 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 sqlite3_prepare
f030: 28 29 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 () operation is
f040: 72 65 71 75 69 72 65 64 20 74 6f 20 61 63 63 65 required to acce
f050: 73 73 20 74 68 65 20 76 69 72 74 75 61 6c 0a 2a ss the virtual.*
f060: 2a 20 74 61 62 6c 65 2c 20 69 74 20 73 65 61 72 * table, it sear
f070: 63 68 65 73 20 74 68 65 20 6c 69 73 74 20 66 6f ches the list fo
f080: 72 20 74 68 65 20 56 54 61 62 6c 65 20 74 68 61 r the VTable tha
f090: 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f t corresponds to
f0a0: 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 the.** database
f0b0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 6f 69 6e connection doin
f0c0: 67 20 74 68 65 20 70 72 65 70 61 72 69 6e 67 20 g the preparing
f0d0: 73 6f 20 61 73 20 74 6f 20 75 73 65 20 74 68 65 so as to use the
f0e0: 20 63 6f 72 72 65 63 74 0a 2a 2a 20 73 71 6c 69 correct.** sqli
f0f0: 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 te3_vtab* handle
f100: 20 69 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 64 in the compiled
f110: 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 query..**.** Wh
f120: 65 6e 20 61 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 en an in-memory
f130: 54 61 62 6c 65 20 6f 62 6a 65 63 74 20 69 73 20 Table object is
f140: 64 65 6c 65 74 65 64 20 28 66 6f 72 20 65 78 61 deleted (for exa
f150: 6d 70 6c 65 20 77 68 65 6e 20 74 68 65 0a 2a 2a mple when the.**
f160: 20 73 63 68 65 6d 61 20 69 73 20 62 65 69 6e 67 schema is being
f170: 20 72 65 6c 6f 61 64 65 64 20 66 6f 72 20 73 6f reloaded for so
f180: 6d 65 20 72 65 61 73 6f 6e 29 2c 20 74 68 65 20 me reason), the
f190: 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 61 VTable objects a
f1a0: 72 65 20 6e 6f 74 20 0a 2a 2a 20 64 65 6c 65 74 re not .** delet
f1b0: 65 64 20 61 6e 64 20 74 68 65 20 73 71 6c 69 74 ed and the sqlit
f1c0: 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 e3_vtab* handles
f1d0: 20 61 72 65 20 6e 6f 74 20 78 44 69 73 63 6f 6e are not xDiscon
f1e0: 6e 65 63 74 28 29 65 64 20 0a 2a 2a 20 69 6d 6d nect()ed .** imm
f1f0: 65 64 69 61 74 65 6c 79 2e 20 49 6e 73 74 65 61 ediately. Instea
f200: 64 2c 20 74 68 65 79 20 61 72 65 20 6d 6f 76 65 d, they are move
f210: 64 20 66 72 6f 6d 20 74 68 65 20 54 61 62 6c 65 d from the Table
f220: 2e 70 56 54 61 62 6c 65 20 6c 69 73 74 20 74 6f .pVTable list to
f230: 0a 2a 2a 20 61 6e 6f 74 68 65 72 20 6c 69 6e 6b .** another link
f240: 65 64 20 6c 69 73 74 20 68 65 61 64 65 64 20 62 ed list headed b
f250: 79 20 74 68 65 20 73 71 6c 69 74 65 33 2e 70 44 y the sqlite3.pD
f260: 69 73 63 6f 6e 6e 65 63 74 20 6d 65 6d 62 65 72 isconnect member
f270: 20 6f 66 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 of the.** corre
f280: 73 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 sponding sqlite3
f290: 20 73 74 72 75 63 74 75 72 65 2e 20 54 68 65 79 structure. They
f2a0: 20 61 72 65 20 74 68 65 6e 20 64 65 6c 65 74 65 are then delete
f2b0: 64 2f 78 44 69 73 63 6f 6e 6e 65 63 74 65 64 20 d/xDisconnected
f2c0: 0a 2a 2a 20 6e 65 78 74 20 74 69 6d 65 20 61 20 .** next time a
f2d0: 73 74 61 74 65 6d 65 6e 74 20 69 73 20 70 72 65 statement is pre
f2e0: 70 61 72 65 64 20 75 73 69 6e 67 20 73 61 69 64 pared using said
f2f0: 20 73 71 6c 69 74 65 33 2a 2e 20 54 68 69 73 20 sqlite3*. This
f300: 69 73 20 64 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 is done.** to av
f310: 6f 69 64 20 64 65 61 64 6c 6f 63 6b 20 69 73 73 oid deadlock iss
f320: 75 65 73 20 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 ues involving mu
f330: 6c 74 69 70 6c 65 20 73 71 6c 69 74 65 33 2e 6d ltiple sqlite3.m
f340: 75 74 65 78 20 6d 75 74 65 78 65 73 2e 0a 2a 2a utex mutexes..**
f350: 20 52 65 66 65 72 20 74 6f 20 63 6f 6d 6d 65 6e Refer to commen
f360: 74 73 20 61 62 6f 76 65 20 66 75 6e 63 74 69 6f ts above functio
f370: 6e 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c n sqlite3VtabUnl
f380: 6f 63 6b 4c 69 73 74 28 29 20 66 6f 72 20 61 6e ockList() for an
f390: 0a 2a 2a 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 .** explanation
f3a0: 61 73 20 74 6f 20 77 68 79 20 69 74 20 69 73 20 as to why it is
f3b0: 73 61 66 65 20 74 6f 20 61 64 64 20 61 6e 20 65 safe to add an e
f3c0: 6e 74 72 79 20 74 6f 20 61 6e 20 73 71 6c 69 74 ntry to an sqlit
f3d0: 65 33 2e 70 44 69 73 63 6f 6e 6e 65 63 74 0a 2a e3.pDisconnect.*
f3e0: 2a 20 6c 69 73 74 20 77 69 74 68 6f 75 74 20 68 * list without h
f3f0: 6f 6c 64 69 6e 67 20 74 68 65 20 63 6f 72 72 65 olding the corre
f400: 73 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 sponding sqlite3
f410: 2e 6d 75 74 65 78 20 6d 75 74 65 78 2e 0a 2a 2a .mutex mutex..**
f420: 0a 2a 2a 20 54 68 65 20 6d 65 6d 6f 72 79 20 66 .** The memory f
f430: 6f 72 20 6f 62 6a 65 63 74 73 20 6f 66 20 74 68 or objects of th
f440: 69 73 20 74 79 70 65 20 69 73 20 61 6c 77 61 79 is type is alway
f450: 73 20 61 6c 6c 6f 63 61 74 65 64 20 62 79 20 0a s allocated by .
f460: 2a 2a 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c ** sqlite3DbMall
f470: 6f 63 28 29 2c 20 75 73 69 6e 67 20 74 68 65 20 oc(), using the
f480: 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c connection handl
f490: 65 20 73 74 6f 72 65 64 20 69 6e 20 56 54 61 62 e stored in VTab
f4a0: 6c 65 2e 64 62 20 61 73 20 0a 2a 2a 20 74 68 65 le.db as .** the
f4b0: 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 2e first argument.
f4c0: 0a 2a 2f 0a 73 74 72 75 63 74 20 56 54 61 62 6c .*/.struct VTabl
f4d0: 65 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 e {. sqlite3 *d
f4e0: 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 b;
f4f0: 2f 2a 20 44 61 74 61 62 61 73 65 20 63 6f 6e 6e /* Database conn
f500: 65 63 74 69 6f 6e 20 61 73 73 6f 63 69 61 74 65 ection associate
f510: 64 20 77 69 74 68 20 74 68 69 73 20 74 61 62 6c d with this tabl
f520: 65 20 2a 2f 0a 20 20 4d 6f 64 75 6c 65 20 2a 70 e */. Module *p
f530: 4d 6f 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 Mod;
f540: 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 6d /* Pointer to m
f550: 6f 64 75 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 odule implementa
f560: 74 69 6f 6e 20 2a 2f 0a 20 20 73 71 6c 69 74 65 tion */. sqlite
f570: 33 5f 76 74 61 62 20 2a 70 56 74 61 62 3b 20 20 3_vtab *pVtab;
f580: 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 /* Pointer t
f590: 6f 20 76 74 61 62 20 69 6e 73 74 61 6e 63 65 20 o vtab instance
f5a0: 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 3b 20 20 */. int nRef;
f5b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
f5c0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 6e * Number of poin
f5d0: 74 65 72 73 20 74 6f 20 74 68 69 73 20 73 74 72 ters to this str
f5e0: 75 63 74 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 ucture */. u8 b
f5f0: 43 6f 6e 73 74 72 61 69 6e 74 3b 20 20 20 20 20 Constraint;
f600: 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
f610: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 61 72 65 constraints are
f620: 20 73 75 70 70 6f 72 74 65 64 20 2a 2f 0a 20 20 supported */.
f630: 69 6e 74 20 69 53 61 76 65 70 6f 69 6e 74 3b 20 int iSavepoint;
f640: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 70 /* Dep
f650: 74 68 20 6f 66 20 74 68 65 20 53 41 56 45 50 4f th of the SAVEPO
f660: 49 4e 54 20 73 74 61 63 6b 20 2a 2f 0a 20 20 56 INT stack */. V
f670: 54 61 62 6c 65 20 2a 70 4e 65 78 74 3b 20 20 20 Table *pNext;
f680: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 /* Next
f690: 20 69 6e 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 in linked list
f6a0: 28 73 65 65 20 61 62 6f 76 65 29 20 2a 2f 0a 7d (see above) */.}
f6b0: 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 73 63 68 ;../*.** The sch
f6c0: 65 6d 61 20 66 6f 72 20 65 61 63 68 20 53 51 4c ema for each SQL
f6d0: 20 74 61 62 6c 65 20 61 6e 64 20 76 69 65 77 20 table and view
f6e0: 69 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 is represented i
f6f0: 6e 20 6d 65 6d 6f 72 79 0a 2a 2a 20 62 79 20 61 n memory.** by a
f700: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
f710: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
f720: 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 cture..*/.struct
f730: 20 54 61 62 6c 65 20 7b 0a 20 20 63 68 61 72 20 Table {. char
f740: 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
f750: 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 /* Name of the t
f760: 61 62 6c 65 20 6f 72 20 76 69 65 77 20 2a 2f 0a able or view */.
f770: 20 20 43 6f 6c 75 6d 6e 20 2a 61 43 6f 6c 3b 20 Column *aCol;
f780: 20 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d /* Inform
f790: 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 ation about each
f7a0: 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 column */. Ind
f7b0: 65 78 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 20 ex *pIndex;
f7c0: 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 53 51 4c /* List of SQL
f7d0: 20 69 6e 64 65 78 65 73 20 6f 6e 20 74 68 69 73 indexes on this
f7e0: 20 74 61 62 6c 65 2e 20 2a 2f 0a 20 20 53 65 6c table. */. Sel
f7f0: 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 ect *pSelect;
f800: 20 20 2f 2a 20 4e 55 4c 4c 20 66 6f 72 20 74 61 /* NULL for ta
f810: 62 6c 65 73 2e 20 20 50 6f 69 6e 74 73 20 74 6f bles. Points to
f820: 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 66 20 61 definition if a
f830: 20 76 69 65 77 2e 20 2a 2f 0a 20 20 46 4b 65 79 view. */. FKey
f840: 20 2a 70 46 4b 65 79 3b 20 20 20 20 20 20 20 20 *pFKey;
f850: 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 /* Linked list
f860: 6f 66 20 61 6c 6c 20 66 6f 72 65 69 67 6e 20 6b of all foreign k
f870: 65 79 73 20 69 6e 20 74 68 69 73 20 74 61 62 6c eys in this tabl
f880: 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f e */. char *zCo
f890: 6c 41 66 66 3b 20 20 20 20 20 20 20 2f 2a 20 53 lAff; /* S
f8a0: 74 72 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 tring defining t
f8b0: 68 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 he affinity of e
f8c0: 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 69 ach column */.#i
f8d0: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
f8e0: 54 5f 43 48 45 43 4b 0a 20 20 45 78 70 72 4c 69 T_CHECK. ExprLi
f8f0: 73 74 20 2a 70 43 68 65 63 6b 3b 20 20 20 20 2f st *pCheck; /
f900: 2a 20 41 6c 6c 20 43 48 45 43 4b 20 63 6f 6e 73 * All CHECK cons
f910: 74 72 61 69 6e 74 73 20 2a 2f 0a 23 65 6e 64 69 traints */.#endi
f920: 66 0a 20 20 69 6e 74 20 74 6e 75 6d 3b 20 20 20 f. int tnum;
f930: 20 20 20 20 20 20 20 20 20 2f 2a 20 52 6f 6f 74 /* Root
f940: 20 42 54 72 65 65 20 70 61 67 65 20 66 6f 72 20 BTree page for
f950: 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 this table */.
f960: 69 31 36 20 69 50 4b 65 79 3b 20 20 20 20 20 20 i16 iPKey;
f970: 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f 74 20 6e /* If not n
f980: 65 67 61 74 69 76 65 2c 20 75 73 65 20 61 43 6f egative, use aCo
f990: 6c 5b 69 50 4b 65 79 5d 20 61 73 20 74 68 65 20 l[iPKey] as the
f9a0: 72 6f 77 69 64 20 2a 2f 0a 20 20 69 31 36 20 6e rowid */. i16 n
f9b0: 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 Col;
f9c0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c /* Number of col
f9d0: 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 74 61 62 umns in this tab
f9e0: 6c 65 20 2a 2f 0a 20 20 75 31 36 20 6e 52 65 66 le */. u16 nRef
f9f0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
fa00: 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 Number of pointe
fa10: 72 73 20 74 6f 20 74 68 69 73 20 54 61 62 6c 65 rs to this Table
fa20: 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 6e 52 6f */. LogEst nRo
fa30: 77 4c 6f 67 45 73 74 3b 20 20 20 2f 2a 20 45 73 wLogEst; /* Es
fa40: 74 69 6d 61 74 65 64 20 72 6f 77 73 20 69 6e 20 timated rows in
fa50: 74 61 62 6c 65 20 2d 20 66 72 6f 6d 20 73 71 6c table - from sql
fa60: 69 74 65 5f 73 74 61 74 31 20 74 61 62 6c 65 20 ite_stat1 table
fa70: 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 73 7a 54 61 */. LogEst szTa
fa80: 62 52 6f 77 3b 20 20 20 20 20 2f 2a 20 45 73 74 bRow; /* Est
fa90: 69 6d 61 74 65 64 20 73 69 7a 65 20 6f 66 20 65 imated size of e
faa0: 61 63 68 20 74 61 62 6c 65 20 72 6f 77 20 69 6e ach table row in
fab0: 20 62 79 74 65 73 20 2a 2f 0a 23 69 66 64 65 66 bytes */.#ifdef
fac0: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 43 SQLITE_ENABLE_C
fad0: 4f 53 54 4d 55 4c 54 0a 20 20 4c 6f 67 45 73 74 OSTMULT. LogEst
fae0: 20 63 6f 73 74 4d 75 6c 74 3b 20 20 20 20 20 2f costMult; /
faf0: 2a 20 43 6f 73 74 20 6d 75 6c 74 69 70 6c 69 65 * Cost multiplie
fb00: 72 20 66 6f 72 20 75 73 69 6e 67 20 74 68 69 73 r for using this
fb10: 20 74 61 62 6c 65 20 2a 2f 0a 23 65 6e 64 69 66 table */.#endif
fb20: 0a 20 20 75 38 20 74 61 62 46 6c 61 67 73 3b 20 . u8 tabFlags;
fb30: 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 73 6b 20 /* Mask
fb40: 6f 66 20 54 46 5f 2a 20 76 61 6c 75 65 73 20 2a of TF_* values *
fb50: 2f 0a 20 20 75 38 20 6b 65 79 43 6f 6e 66 3b 20 /. u8 keyConf;
fb60: 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 61 74 /* What
fb70: 20 74 6f 20 64 6f 20 69 6e 20 63 61 73 65 20 6f to do in case o
fb80: 66 20 75 6e 69 71 75 65 6e 65 73 73 20 63 6f 6e f uniqueness con
fb90: 66 6c 69 63 74 20 6f 6e 20 69 50 4b 65 79 20 2a flict on iPKey *
fba0: 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
fbb0: 5f 4f 4d 49 54 5f 41 4c 54 45 52 54 41 42 4c 45 _OMIT_ALTERTABLE
fbc0: 0a 20 20 69 6e 74 20 61 64 64 43 6f 6c 4f 66 66 . int addColOff
fbd0: 73 65 74 3b 20 20 20 20 2f 2a 20 4f 66 66 73 65 set; /* Offse
fbe0: 74 20 69 6e 20 43 52 45 41 54 45 20 54 41 42 4c t in CREATE TABL
fbf0: 45 20 73 74 6d 74 20 74 6f 20 61 64 64 20 61 20 E stmt to add a
fc00: 6e 65 77 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 65 new column */.#e
fc10: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
fc20: 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
fc30: 54 41 42 4c 45 0a 20 20 69 6e 74 20 6e 4d 6f 64 TABLE. int nMod
fc40: 75 6c 65 41 72 67 3b 20 20 20 20 20 20 2f 2a 20 uleArg; /*
fc50: 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 Number of argume
fc60: 6e 74 73 20 74 6f 20 74 68 65 20 6d 6f 64 75 6c nts to the modul
fc70: 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 61 7a e */. char **az
fc80: 4d 6f 64 75 6c 65 41 72 67 3b 20 20 2f 2a 20 54 ModuleArg; /* T
fc90: 65 78 74 20 6f 66 20 61 6c 6c 20 6d 6f 64 75 6c ext of all modul
fca0: 65 20 61 72 67 73 2e 20 5b 30 5d 20 69 73 20 6d e args. [0] is m
fcb0: 6f 64 75 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 odule name */.
fcc0: 56 54 61 62 6c 65 20 2a 70 56 54 61 62 6c 65 3b VTable *pVTable;
fcd0: 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 /* List of
fce0: 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 2e 20 VTable objects.
fcf0: 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 54 72 69 67 */.#endif. Trig
fd00: 67 65 72 20 2a 70 54 72 69 67 67 65 72 3b 20 20 ger *pTrigger;
fd10: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 74 72 69 67 /* List of trig
fd20: 67 65 72 73 20 73 74 6f 72 65 64 20 69 6e 20 70 gers stored in p
fd30: 53 63 68 65 6d 61 20 2a 2f 0a 20 20 53 63 68 65 Schema */. Sche
fd40: 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
fd50: 20 2f 2a 20 53 63 68 65 6d 61 20 74 68 61 74 20 /* Schema that
fd60: 63 6f 6e 74 61 69 6e 73 20 74 68 69 73 20 74 61 contains this ta
fd70: 62 6c 65 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a ble */. Table *
fd80: 70 4e 65 78 74 5a 6f 6d 62 69 65 3b 20 20 2f 2a pNextZombie; /*
fd90: 20 4e 65 78 74 20 6f 6e 20 74 68 65 20 50 61 72 Next on the Par
fda0: 73 65 2e 70 5a 6f 6d 62 69 65 54 61 62 20 6c 69 se.pZombieTab li
fdb0: 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 st */.};../*.**
fdc0: 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
fdd0: 6f 72 20 54 61 62 6c 65 2e 74 61 62 46 6c 61 67 or Table.tabFlag
fde0: 73 2e 0a 2a 2a 0a 2a 2a 20 54 46 5f 4f 4f 4f 48 s..**.** TF_OOOH
fdf0: 69 64 64 65 6e 20 61 70 70 6c 69 65 73 20 74 6f idden applies to
fe00: 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 virtual tables
fe10: 74 68 61 74 20 68 61 76 65 20 68 69 64 64 65 6e that have hidden
fe20: 20 63 6f 6c 75 6d 6e 73 20 74 68 61 74 20 61 72 columns that ar
fe30: 65 0a 2a 2a 20 66 6f 6c 6c 6f 77 65 64 20 62 79 e.** followed by
fe40: 20 6e 6f 6e 2d 68 69 64 64 65 6e 20 63 6f 6c 75 non-hidden colu
fe50: 6d 6e 73 2e 20 20 45 78 61 6d 70 6c 65 3a 20 20 mns. Example:
fe60: 22 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 "CREATE VIRTUAL
fe70: 54 41 42 4c 45 20 78 20 55 53 49 4e 47 0a 2a 2a TABLE x USING.**
fe80: 20 76 74 61 62 31 28 61 20 48 49 44 44 45 4e 2c vtab1(a HIDDEN,
fe90: 20 62 29 3b 22 2e 20 20 53 69 6e 63 65 20 22 62 b);". Since "b
fea0: 22 20 69 73 20 61 20 6e 6f 6e 2d 68 69 64 64 65 " is a non-hidde
feb0: 6e 20 63 6f 6c 75 6d 6e 20 62 75 74 20 22 61 22 n column but "a"
fec0: 20 69 73 20 68 69 64 64 65 6e 2c 0a 2a 2a 20 74 is hidden,.** t
fed0: 68 65 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 he TF_OOOHidden
fee0: 61 74 74 72 69 62 75 74 65 20 77 6f 75 6c 64 20 attribute would
fef0: 61 70 70 6c 79 20 69 6e 20 74 68 69 73 20 63 61 apply in this ca
ff00: 73 65 2e 20 20 53 75 63 68 20 74 61 62 6c 65 73 se. Such tables
ff10: 20 72 65 71 75 69 72 65 0a 2a 2a 20 73 70 65 63 require.** spec
ff20: 69 61 6c 20 68 61 6e 64 6c 69 6e 67 20 64 75 72 ial handling dur
ff30: 69 6e 67 20 49 4e 53 45 52 54 20 70 72 6f 63 65 ing INSERT proce
ff40: 73 73 69 6e 67 2e 0a 2a 2f 0a 23 64 65 66 69 6e ssing..*/.#defin
ff50: 65 20 54 46 5f 52 65 61 64 6f 6e 6c 79 20 20 20 e TF_Readonly
ff60: 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
ff70: 52 65 61 64 2d 6f 6e 6c 79 20 73 79 73 74 65 6d Read-only system
ff80: 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e table */.#defin
ff90: 65 20 54 46 5f 45 70 68 65 6d 65 72 61 6c 20 20 e TF_Ephemeral
ffa0: 20 20 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 0x02 /*
ffb0: 41 6e 20 65 70 68 65 6d 65 72 61 6c 20 74 61 62 An ephemeral tab
ffc0: 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 le */.#define TF
ffd0: 5f 48 61 73 50 72 69 6d 61 72 79 4b 65 79 20 20 _HasPrimaryKey
ffe0: 20 30 78 30 34 20 20 20 20 2f 2a 20 54 61 62 6c 0x04 /* Tabl
fff0: 65 20 68 61 73 20 61 20 70 72 69 6d 61 72 79 20 e has a primary
10000 6b 65 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 key */.#define T
10010 46 5f 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 F_Autoincrement
10020 20 20 30 78 30 38 20 20 20 20 2f 2a 20 49 6e 74 0x08 /* Int
10030 65 67 65 72 20 70 72 69 6d 61 72 79 20 6b 65 79 eger primary key
10040 20 69 73 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e is autoincremen
10050 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f t */.#define TF_
10060 56 69 72 74 75 61 6c 20 20 20 20 20 20 20 20 20 Virtual
10070 30 78 31 30 20 20 20 20 2f 2a 20 49 73 20 61 20 0x10 /* Is a
10080 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 2a 2f virtual table */
10090 0a 23 64 65 66 69 6e 65 20 54 46 5f 57 69 74 68 .#define TF_With
100a0 6f 75 74 52 6f 77 69 64 20 20 20 20 30 78 32 30 outRowid 0x20
100b0 20 20 20 20 2f 2a 20 4e 6f 20 72 6f 77 69 64 2e /* No rowid.
100c0 20 20 50 52 49 4d 41 52 59 20 4b 45 59 20 69 73 PRIMARY KEY is
100d0 20 74 68 65 20 6b 65 79 20 2a 2f 0a 23 64 65 66 the key */.#def
100e0 69 6e 65 20 54 46 5f 4e 6f 56 69 73 69 62 6c 65 ine TF_NoVisible
100f0 52 6f 77 69 64 20 20 30 78 34 30 20 20 20 20 2f Rowid 0x40 /
10100 2a 20 4e 6f 20 75 73 65 72 2d 76 69 73 69 62 6c * No user-visibl
10110 65 20 22 72 6f 77 69 64 22 20 63 6f 6c 75 6d 6e e "rowid" column
10120 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 4f */.#define TF_O
10130 4f 4f 48 69 64 64 65 6e 20 20 20 20 20 20 20 30 OOHidden 0
10140 78 38 30 20 20 20 20 2f 2a 20 4f 75 74 2d 6f 66 x80 /* Out-of
10150 2d 4f 72 64 65 72 20 68 69 64 64 65 6e 20 63 6f -Order hidden co
10160 6c 75 6d 6e 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a lumns */.../*.**
10170 20 54 65 73 74 20 74 6f 20 73 65 65 20 77 68 65 Test to see whe
10180 74 68 65 72 20 6f 72 20 6e 6f 74 20 61 20 74 61 ther or not a ta
10190 62 6c 65 20 69 73 20 61 20 76 69 72 74 75 61 6c ble is a virtual
101a0 20 74 61 62 6c 65 2e 20 20 54 68 69 73 20 69 73 table. This is
101b0 0a 2a 2a 20 64 6f 6e 65 20 61 73 20 61 20 6d 61 .** done as a ma
101c0 63 72 6f 20 73 6f 20 74 68 61 74 20 69 74 20 77 cro so that it w
101d0 69 6c 6c 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 ill be optimized
101e0 20 6f 75 74 20 77 68 65 6e 20 76 69 72 74 75 61 out when virtua
101f0 6c 0a 2a 2a 20 74 61 62 6c 65 20 73 75 70 70 6f l.** table suppo
10200 72 74 20 69 73 20 6f 6d 69 74 74 65 64 20 66 72 rt is omitted fr
10210 6f 6d 20 74 68 65 20 62 75 69 6c 64 2e 0a 2a 2f om the build..*/
10220 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
10230 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
10240 45 0a 23 20 20 64 65 66 69 6e 65 20 49 73 56 69 E.# define IsVi
10250 72 74 75 61 6c 28 58 29 20 20 20 20 20 20 28 28 rtual(X) ((
10260 28 58 29 2d 3e 74 61 62 46 6c 61 67 73 20 26 20 (X)->tabFlags &
10270 54 46 5f 56 69 72 74 75 61 6c 29 21 3d 30 29 0a TF_Virtual)!=0).
10280 23 20 20 64 65 66 69 6e 65 20 49 73 48 69 64 64 # define IsHidd
10290 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 28 28 28 58 enColumn(X) (((X
102a0 29 2d 3e 63 6f 6c 46 6c 61 67 73 20 26 20 43 4f )->colFlags & CO
102b0 4c 46 4c 41 47 5f 48 49 44 44 45 4e 29 21 3d 30 LFLAG_HIDDEN)!=0
102c0 29 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 69 6e ).#else.# defin
102d0 65 20 49 73 56 69 72 74 75 61 6c 28 58 29 20 20 e IsVirtual(X)
102e0 20 20 20 20 30 0a 23 20 20 64 65 66 69 6e 65 20 0.# define
102f0 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 IsHiddenColumn(X
10300 29 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 44 ) 0.#endif../* D
10310 6f 65 73 20 74 68 65 20 74 61 62 6c 65 20 68 61 oes the table ha
10320 76 65 20 61 20 72 6f 77 69 64 20 2a 2f 0a 23 64 ve a rowid */.#d
10330 65 66 69 6e 65 20 48 61 73 52 6f 77 69 64 28 58 efine HasRowid(X
10340 29 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 62 ) (((X)->tab
10350 46 6c 61 67 73 20 26 20 54 46 5f 57 69 74 68 6f Flags & TF_Witho
10360 75 74 52 6f 77 69 64 29 3d 3d 30 29 0a 23 64 65 utRowid)==0).#de
10370 66 69 6e 65 20 56 69 73 69 62 6c 65 52 6f 77 69 fine VisibleRowi
10380 64 28 58 29 20 28 28 28 58 29 2d 3e 74 61 62 46 d(X) (((X)->tabF
10390 6c 61 67 73 20 26 20 54 46 5f 4e 6f 56 69 73 69 lags & TF_NoVisi
103a0 62 6c 65 52 6f 77 69 64 29 3d 3d 30 29 0a 0a 2f bleRowid)==0)../
103b0 2a 0a 2a 2a 20 45 61 63 68 20 66 6f 72 65 69 67 *.** Each foreig
103c0 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 69 6e 74 n key constraint
103d0 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 is an instance
103e0 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
103f0 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a structure..**.*
10400 2a 20 41 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 * A foreign key
10410 69 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 is associated wi
10420 74 68 20 74 77 6f 20 74 61 62 6c 65 73 2e 20 20 th two tables.
10430 54 68 65 20 22 66 72 6f 6d 22 20 74 61 62 6c 65 The "from" table
10440 20 69 73 0a 2a 2a 20 74 68 65 20 74 61 62 6c 65 is.** the table
10450 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 that contains t
10460 68 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c he REFERENCES cl
10470 61 75 73 65 20 74 68 61 74 20 63 72 65 61 74 65 ause that create
10480 73 20 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a 2a s the foreign.**
10490 20 6b 65 79 2e 20 20 54 68 65 20 22 74 6f 22 20 key. The "to"
104a0 74 61 62 6c 65 20 69 73 20 74 68 65 20 74 61 62 table is the tab
104b0 6c 65 20 74 68 61 74 20 69 73 20 6e 61 6d 65 64 le that is named
104c0 20 69 6e 20 74 68 65 20 52 45 46 45 52 45 4e 43 in the REFERENC
104d0 45 53 20 63 6c 61 75 73 65 2e 0a 2a 2a 20 43 6f ES clause..** Co
104e0 6e 73 69 64 65 72 20 74 68 69 73 20 65 78 61 6d nsider this exam
104f0 70 6c 65 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 43 ple:.**.** C
10500 52 45 41 54 45 20 54 41 42 4c 45 20 65 78 31 28 REATE TABLE ex1(
10510 0a 2a 2a 20 20 20 20 20 20 20 61 20 49 4e 54 45 .** a INTE
10520 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
10530 0a 2a 2a 20 20 20 20 20 20 20 62 20 49 4e 54 45 .** b INTE
10540 47 45 52 20 43 4f 4e 53 54 52 41 49 4e 54 20 66 GER CONSTRAINT f
10550 6b 31 20 52 45 46 45 52 45 4e 43 45 53 20 65 78 k1 REFERENCES ex
10560 32 28 78 29 0a 2a 2a 20 20 20 20 20 29 3b 0a 2a 2(x).** );.*
10570 2a 0a 2a 2a 20 46 6f 72 20 66 6f 72 65 69 67 6e *.** For foreign
10580 20 6b 65 79 20 22 66 6b 31 22 2c 20 74 68 65 20 key "fk1", the
10590 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 22 65 from-table is "e
105a0 78 31 22 20 61 6e 64 20 74 68 65 20 74 6f 2d 74 x1" and the to-t
105b0 61 62 6c 65 20 69 73 20 22 65 78 32 22 2e 0a 2a able is "ex2"..*
105c0 2a 20 45 71 75 69 76 61 6c 65 6e 74 20 6e 61 6d * Equivalent nam
105d0 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 66 72 es:.**.** fr
105e0 6f 6d 2d 74 61 62 6c 65 20 3d 3d 20 63 68 69 6c om-table == chil
105f0 64 2d 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 d-table.**
10600 20 74 6f 2d 74 61 62 6c 65 20 3d 3d 20 70 61 72 to-table == par
10610 65 6e 74 2d 74 61 62 6c 65 0a 2a 2a 0a 2a 2a 20 ent-table.**.**
10620 45 61 63 68 20 52 45 46 45 52 45 4e 43 45 53 20 Each REFERENCES
10630 63 6c 61 75 73 65 20 67 65 6e 65 72 61 74 65 73 clause generates
10640 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 an instance of
10650 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
10660 72 75 63 74 75 72 65 0a 2a 2a 20 77 68 69 63 68 ructure.** which
10670 20 69 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 is attached to
10680 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 2e 20 the from-table.
10690 20 54 68 65 20 74 6f 2d 74 61 62 6c 65 20 6e 65 The to-table ne
106a0 65 64 20 6e 6f 74 20 65 78 69 73 74 20 77 68 65 ed not exist whe
106b0 6e 0a 2a 2a 20 74 68 65 20 66 72 6f 6d 2d 74 61 n.** the from-ta
106c0 62 6c 65 20 69 73 20 63 72 65 61 74 65 64 2e 20 ble is created.
106d0 20 54 68 65 20 65 78 69 73 74 65 6e 63 65 20 6f The existence o
106e0 66 20 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 69 f the to-table i
106f0 73 20 6e 6f 74 20 63 68 65 63 6b 65 64 2e 0a 2a s not checked..*
10700 2a 0a 2a 2a 20 54 68 65 20 6c 69 73 74 20 6f 66 *.** The list of
10710 20 61 6c 6c 20 70 61 72 65 6e 74 73 20 66 6f 72 all parents for
10720 20 63 68 69 6c 64 20 54 61 62 6c 65 20 58 20 69 child Table X i
10730 73 20 68 65 6c 64 20 61 74 20 58 2e 70 46 4b 65 s held at X.pFKe
10740 79 2e 0a 2a 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 y..**.** A list
10750 6f 66 20 61 6c 6c 20 63 68 69 6c 64 72 65 6e 20 of all children
10760 66 6f 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 for a table name
10770 64 20 5a 20 28 77 68 69 63 68 20 6d 69 67 68 74 d Z (which might
10780 20 6e 6f 74 20 65 76 65 6e 20 65 78 69 73 74 29 not even exist)
10790 0a 2a 2a 20 69 73 20 68 65 6c 64 20 69 6e 20 53 .** is held in S
107a0 63 68 65 6d 61 2e 66 6b 65 79 48 61 73 68 20 77 chema.fkeyHash w
107b0 69 74 68 20 61 20 68 61 73 68 20 6b 65 79 20 6f ith a hash key o
107c0 66 20 5a 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 f Z..*/.struct F
107d0 4b 65 79 20 7b 0a 20 20 54 61 62 6c 65 20 2a 70 Key {. Table *p
107e0 46 72 6f 6d 3b 20 20 20 20 20 2f 2a 20 54 61 62 From; /* Tab
107f0 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 le containing th
10800 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 e REFERENCES cla
10810 75 73 65 20 28 61 6b 61 3a 20 43 68 69 6c 64 29 use (aka: Child)
10820 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 */. FKey *pNex
10830 74 46 72 6f 6d 3b 20 20 2f 2a 20 4e 65 78 74 20 tFrom; /* Next
10840 46 4b 65 79 20 77 69 74 68 20 74 68 65 20 73 61 FKey with the sa
10850 6d 65 20 69 6e 20 70 46 72 6f 6d 2e 20 4e 65 78 me in pFrom. Nex
10860 74 20 70 61 72 65 6e 74 20 6f 66 20 70 46 72 6f t parent of pFro
10870 6d 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 6f m */. char *zTo
10880 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 ; /* Name
10890 20 6f 66 20 74 61 62 6c 65 20 74 68 61 74 20 74 of table that t
108a0 68 65 20 6b 65 79 20 70 6f 69 6e 74 73 20 74 6f he key points to
108b0 20 28 61 6b 61 3a 20 50 61 72 65 6e 74 29 20 2a (aka: Parent) *
108c0 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 74 54 /. FKey *pNextT
108d0 6f 3b 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 69 o; /* Next wi
108e0 74 68 20 74 68 65 20 73 61 6d 65 20 7a 54 6f 2e th the same zTo.
108f0 20 4e 65 78 74 20 63 68 69 6c 64 20 6f 66 20 7a Next child of z
10900 54 6f 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 To. */. FKey *p
10910 50 72 65 76 54 6f 3b 20 20 20 20 2f 2a 20 50 72 PrevTo; /* Pr
10920 65 76 69 6f 75 73 20 77 69 74 68 20 74 68 65 20 evious with the
10930 73 61 6d 65 20 7a 54 6f 20 2a 2f 0a 20 20 69 6e same zTo */. in
10940 74 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 t nCol;
10950 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c /* Number of col
10960 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 6b 65 79 umns in this key
10970 20 2a 2f 0a 20 20 2f 2a 20 45 56 3a 20 52 2d 33 */. /* EV: R-3
10980 30 33 32 33 2d 32 31 39 31 37 20 2a 2f 0a 20 20 0323-21917 */.
10990 75 38 20 69 73 44 65 66 65 72 72 65 64 3b 20 20 u8 isDeferred;
109a0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
109b0 63 6f 6e 73 74 72 61 69 6e 74 20 63 68 65 63 6b constraint check
109c0 69 6e 67 20 69 73 20 64 65 66 65 72 72 65 64 20 ing is deferred
109d0 74 69 6c 6c 20 43 4f 4d 4d 49 54 20 2a 2f 0a 20 till COMMIT */.
109e0 20 75 38 20 61 41 63 74 69 6f 6e 5b 32 5d 3b 20 u8 aAction[2];
109f0 20 20 20 20 20 20 20 2f 2a 20 4f 4e 20 44 45 4c /* ON DEL
10a00 45 54 45 20 61 6e 64 20 4f 4e 20 55 50 44 41 54 ETE and ON UPDAT
10a10 45 20 61 63 74 69 6f 6e 73 2c 20 72 65 73 70 65 E actions, respe
10a20 63 74 69 76 65 6c 79 20 2a 2f 0a 20 20 54 72 69 ctively */. Tri
10a30 67 67 65 72 20 2a 61 70 54 72 69 67 67 65 72 5b gger *apTrigger[
10a40 32 5d 3b 2f 2a 20 54 72 69 67 67 65 72 73 20 66 2];/* Triggers f
10a50 6f 72 20 61 41 63 74 69 6f 6e 5b 5d 20 61 63 74 or aAction[] act
10a60 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 ions */. struct
10a70 20 73 43 6f 6c 4d 61 70 20 7b 20 20 20 20 20 20 sColMap {
10a80 2f 2a 20 4d 61 70 70 69 6e 67 20 6f 66 20 63 6f /* Mapping of co
10a90 6c 75 6d 6e 73 20 69 6e 20 70 46 72 6f 6d 20 74 lumns in pFrom t
10aa0 6f 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 7a 54 6f o columns in zTo
10ab0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 46 72 6f */. int iFro
10ac0 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
10ad0 20 49 6e 64 65 78 20 6f 66 20 63 6f 6c 75 6d 6e Index of column
10ae0 20 69 6e 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 20 in pFrom */.
10af0 20 63 68 61 72 20 2a 7a 43 6f 6c 3b 20 20 20 20 char *zCol;
10b00 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
10b10 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 7a 54 6f 2e f column in zTo.
10b20 20 20 49 66 20 4e 55 4c 4c 20 75 73 65 20 50 52 If NULL use PR
10b30 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 7d IMARY KEY */. }
10b40 20 61 43 6f 6c 5b 31 5d 3b 20 20 20 20 20 20 20 aCol[1];
10b50 20 20 20 20 20 2f 2a 20 4f 6e 65 20 65 6e 74 72 /* One entr
10b60 79 20 66 6f 72 20 65 61 63 68 20 6f 66 20 6e 43 y for each of nC
10b70 6f 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 7d 3b ol columns */.};
10b80 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 69 74 65 20 73 ../*.** SQLite s
10b90 75 70 70 6f 72 74 73 20 6d 61 6e 79 20 64 69 66 upports many dif
10ba0 66 65 72 65 6e 74 20 77 61 79 73 20 74 6f 20 72 ferent ways to r
10bb0 65 73 6f 6c 76 65 20 61 20 63 6f 6e 73 74 72 61 esolve a constra
10bc0 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 2e 20 20 52 int.** error. R
10bd0 4f 4c 4c 42 41 43 4b 20 70 72 6f 63 65 73 73 69 OLLBACK processi
10be0 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 20 61 20 ng means that a
10bf0 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 constraint viola
10c00 74 69 6f 6e 0a 2a 2a 20 63 61 75 73 65 73 20 74 tion.** causes t
10c10 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 he operation in
10c20 70 72 6f 63 65 73 73 20 74 6f 20 66 61 69 6c 20 process to fail
10c30 61 6e 64 20 66 6f 72 20 74 68 65 20 63 75 72 72 and for the curr
10c40 65 6e 74 20 74 72 61 6e 73 61 63 74 69 6f 6e 0a ent transaction.
10c50 2a 2a 20 74 6f 20 62 65 20 72 6f 6c 6c 65 64 20 ** to be rolled
10c60 62 61 63 6b 2e 20 20 41 42 4f 52 54 20 70 72 6f back. ABORT pro
10c70 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 cessing means th
10c80 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 e operation in p
10c90 72 6f 63 65 73 73 0a 2a 2a 20 66 61 69 6c 73 20 rocess.** fails
10ca0 61 6e 64 20 61 6e 79 20 70 72 69 6f 72 20 63 68 and any prior ch
10cb0 61 6e 67 65 73 20 66 72 6f 6d 20 74 68 61 74 20 anges from that
10cc0 6f 6e 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 72 one operation ar
10cd0 65 20 62 61 63 6b 65 64 20 6f 75 74 2c 0a 2a 2a e backed out,.**
10ce0 20 62 75 74 20 74 68 65 20 74 72 61 6e 73 61 63 but the transac
10cf0 74 69 6f 6e 20 69 73 20 6e 6f 74 20 72 6f 6c 6c tion is not roll
10d00 65 64 20 62 61 63 6b 2e 20 20 46 41 49 4c 20 70 ed back. FAIL p
10d10 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 rocessing means
10d20 74 68 61 74 0a 2a 2a 20 74 68 65 20 6f 70 65 72 that.** the oper
10d30 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 73 ation in progres
10d40 73 20 73 74 6f 70 73 20 61 6e 64 20 72 65 74 75 s stops and retu
10d50 72 6e 73 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 rns an error cod
10d60 65 2e 20 20 42 75 74 20 70 72 69 6f 72 0a 2a 2a e. But prior.**
10d70 20 63 68 61 6e 67 65 73 20 64 75 65 20 74 6f 20 changes due to
10d80 74 68 65 20 73 61 6d 65 20 6f 70 65 72 61 74 69 the same operati
10d90 6f 6e 20 61 72 65 20 6e 6f 74 20 62 61 63 6b 65 on are not backe
10da0 64 20 6f 75 74 20 61 6e 64 20 6e 6f 20 72 6f 6c d out and no rol
10db0 6c 62 61 63 6b 0a 2a 2a 20 6f 63 63 75 72 73 2e lback.** occurs.
10dc0 20 20 49 47 4e 4f 52 45 20 6d 65 61 6e 73 20 74 IGNORE means t
10dd0 68 61 74 20 74 68 65 20 70 61 72 74 69 63 75 6c hat the particul
10de0 61 72 20 72 6f 77 20 74 68 61 74 20 63 61 75 73 ar row that caus
10df0 65 64 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e ed the constrain
10e00 74 0a 2a 2a 20 65 72 72 6f 72 20 69 73 20 6e 6f t.** error is no
10e10 74 20 69 6e 73 65 72 74 65 64 20 6f 72 20 75 70 t inserted or up
10e20 64 61 74 65 64 2e 20 20 50 72 6f 63 65 73 73 69 dated. Processi
10e30 6e 67 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e 64 ng continues and
10e40 20 6e 6f 20 65 72 72 6f 72 0a 2a 2a 20 69 73 20 no error.** is
10e50 72 65 74 75 72 6e 65 64 2e 20 20 52 45 50 4c 41 returned. REPLA
10e60 43 45 20 6d 65 61 6e 73 20 74 68 61 74 20 70 72 CE means that pr
10e70 65 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 eexisting databa
10e80 73 65 20 72 6f 77 73 20 74 68 61 74 20 63 61 75 se rows that cau
10e90 73 65 64 0a 2a 2a 20 61 20 55 4e 49 51 55 45 20 sed.** a UNIQUE
10ea0 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 constraint viola
10eb0 74 69 6f 6e 20 61 72 65 20 72 65 6d 6f 76 65 64 tion are removed
10ec0 20 73 6f 20 74 68 61 74 20 74 68 65 20 6e 65 77 so that the new
10ed0 20 69 6e 73 65 72 74 20 6f 72 0a 2a 2a 20 75 70 insert or.** up
10ee0 64 61 74 65 20 63 61 6e 20 70 72 6f 63 65 65 64 date can proceed
10ef0 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 20 63 6f . Processing co
10f00 6e 74 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 65 ntinues and no e
10f10 72 72 6f 72 20 69 73 20 72 65 70 6f 72 74 65 64 rror is reported
10f20 2e 0a 2a 2a 0a 2a 2a 20 52 45 53 54 52 49 43 54 ..**.** RESTRICT
10f30 2c 20 53 45 54 4e 55 4c 4c 2c 20 61 6e 64 20 43 , SETNULL, and C
10f40 41 53 43 41 44 45 20 61 63 74 69 6f 6e 73 20 61 ASCADE actions a
10f50 70 70 6c 79 20 6f 6e 6c 79 20 74 6f 20 66 6f 72 pply only to for
10f60 65 69 67 6e 20 6b 65 79 73 2e 0a 2a 2a 20 52 45 eign keys..** RE
10f70 53 54 52 49 43 54 20 69 73 20 74 68 65 20 73 61 STRICT is the sa
10f80 6d 65 20 61 73 20 41 42 4f 52 54 20 66 6f 72 20 me as ABORT for
10f90 49 4d 4d 45 44 49 41 54 45 20 66 6f 72 65 69 67 IMMEDIATE foreig
10fa0 6e 20 6b 65 79 73 20 61 6e 64 20 74 68 65 0a 2a n keys and the.*
10fb0 2a 20 73 61 6d 65 20 61 73 20 52 4f 4c 4c 42 41 * same as ROLLBA
10fc0 43 4b 20 66 6f 72 20 44 45 46 45 52 52 45 44 20 CK for DEFERRED
10fd0 6b 65 79 73 2e 20 20 53 45 54 4e 55 4c 4c 20 6d keys. SETNULL m
10fe0 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 66 6f eans that the fo
10ff0 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 69 73 20 reign.** key is
11000 73 65 74 20 74 6f 20 4e 55 4c 4c 2e 20 20 43 41 set to NULL. CA
11010 53 43 41 44 45 20 6d 65 61 6e 73 20 74 68 61 74 SCADE means that
11020 20 61 20 44 45 4c 45 54 45 20 6f 72 20 55 50 44 a DELETE or UPD
11030 41 54 45 20 6f 66 20 74 68 65 0a 2a 2a 20 72 65 ATE of the.** re
11040 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 72 ferenced table r
11050 6f 77 20 69 73 20 70 72 6f 70 61 67 61 74 65 64 ow is propagated
11060 20 69 6e 74 6f 20 74 68 65 20 72 6f 77 20 74 68 into the row th
11070 61 74 20 68 6f 6c 64 73 20 74 68 65 0a 2a 2a 20 at holds the.**
11080 66 6f 72 65 69 67 6e 20 6b 65 79 2e 0a 2a 2a 20 foreign key..**
11090 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
110a0 67 20 73 79 6d 62 6f 6c 69 63 20 76 61 6c 75 65 g symbolic value
110b0 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 72 65 s are used to re
110c0 63 6f 72 64 20 77 68 69 63 68 20 74 79 70 65 0a cord which type.
110d0 2a 2a 20 6f 66 20 61 63 74 69 6f 6e 20 74 6f 20 ** of action to
110e0 74 61 6b 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 take..*/.#define
110f0 20 4f 45 5f 4e 6f 6e 65 20 20 20 20 20 30 20 20 OE_None 0
11100 20 2f 2a 20 54 68 65 72 65 20 69 73 20 6e 6f 20 /* There is no
11110 63 6f 6e 73 74 72 61 69 6e 74 20 74 6f 20 63 68 constraint to ch
11120 65 63 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f eck */.#define O
11130 45 5f 52 6f 6c 6c 62 61 63 6b 20 31 20 20 20 2f E_Rollback 1 /
11140 2a 20 46 61 69 6c 20 74 68 65 20 6f 70 65 72 61 * Fail the opera
11150 74 69 6f 6e 20 61 6e 64 20 72 6f 6c 6c 62 61 63 tion and rollbac
11160 6b 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f k the transactio
11170 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f n */.#define OE_
11180 41 62 6f 72 74 20 20 20 20 32 20 20 20 2f 2a 20 Abort 2 /*
11190 42 61 63 6b 20 6f 75 74 20 63 68 61 6e 67 65 73 Back out changes
111a0 20 62 75 74 20 64 6f 20 6e 6f 20 72 6f 6c 6c 62 but do no rollb
111b0 61 63 6b 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 ack transaction
111c0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 46 61 */.#define OE_Fa
111d0 69 6c 20 20 20 20 20 33 20 20 20 2f 2a 20 53 74 il 3 /* St
111e0 6f 70 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e op the operation
111f0 20 62 75 74 20 6c 65 61 76 65 20 61 6c 6c 20 70 but leave all p
11200 72 69 6f 72 20 63 68 61 6e 67 65 73 20 2a 2f 0a rior changes */.
11210 23 64 65 66 69 6e 65 20 4f 45 5f 49 67 6e 6f 72 #define OE_Ignor
11220 65 20 20 20 34 20 20 20 2f 2a 20 49 67 6e 6f 72 e 4 /* Ignor
11230 65 20 74 68 65 20 65 72 72 6f 72 2e 20 44 6f 20 e the error. Do
11240 6e 6f 74 20 64 6f 20 74 68 65 20 49 4e 53 45 52 not do the INSER
11250 54 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 23 T or UPDATE */.#
11260 64 65 66 69 6e 65 20 4f 45 5f 52 65 70 6c 61 63 define OE_Replac
11270 65 20 20 35 20 20 20 2f 2a 20 44 65 6c 65 74 65 e 5 /* Delete
11280 20 65 78 69 73 74 69 6e 67 20 72 65 63 6f 72 64 existing record
11290 2c 20 74 68 65 6e 20 64 6f 20 49 4e 53 45 52 54 , then do INSERT
112a0 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 0a 23 or UPDATE */..#
112b0 64 65 66 69 6e 65 20 4f 45 5f 52 65 73 74 72 69 define OE_Restri
112c0 63 74 20 36 20 20 20 2f 2a 20 4f 45 5f 41 62 6f ct 6 /* OE_Abo
112d0 72 74 20 66 6f 72 20 49 4d 4d 45 44 49 41 54 45 rt for IMMEDIATE
112e0 2c 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 66 6f , OE_Rollback fo
112f0 72 20 44 45 46 45 52 52 45 44 20 2a 2f 0a 23 64 r DEFERRED */.#d
11300 65 66 69 6e 65 20 4f 45 5f 53 65 74 4e 75 6c 6c efine OE_SetNull
11310 20 20 37 20 20 20 2f 2a 20 53 65 74 20 74 68 65 7 /* Set the
11320 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c foreign key val
11330 75 65 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a 23 64 ue to NULL */.#d
11340 65 66 69 6e 65 20 4f 45 5f 53 65 74 44 66 6c 74 efine OE_SetDflt
11350 20 20 38 20 20 20 2f 2a 20 53 65 74 20 74 68 65 8 /* Set the
11360 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c foreign key val
11370 75 65 20 74 6f 20 69 74 73 20 64 65 66 61 75 6c ue to its defaul
11380 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f t */.#define OE_
11390 43 61 73 63 61 64 65 20 20 39 20 20 20 2f 2a 20 Cascade 9 /*
113a0 43 61 73 63 61 64 65 20 74 68 65 20 63 68 61 6e Cascade the chan
113b0 67 65 73 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 ges */..#define
113c0 4f 45 5f 44 65 66 61 75 6c 74 20 20 31 30 20 20 OE_Default 10
113d0 2f 2a 20 44 6f 20 77 68 61 74 65 76 65 72 20 74 /* Do whatever t
113e0 68 65 20 64 65 66 61 75 6c 74 20 61 63 74 69 6f he default actio
113f0 6e 20 69 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 n is */.../*.**
11400 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
11410 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
11420 75 63 74 75 72 65 20 69 73 20 70 61 73 73 65 64 ucture is passed
11430 20 61 73 20 74 68 65 20 66 69 72 73 74 0a 2a 2a as the first.**
11440 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 73 71 6c argument to sql
11450 69 74 65 33 56 64 62 65 4b 65 79 43 6f 6d 70 61 ite3VdbeKeyCompa
11460 72 65 20 61 6e 64 20 69 73 20 75 73 65 64 20 74 re and is used t
11470 6f 20 63 6f 6e 74 72 6f 6c 20 74 68 65 20 0a 2a o control the .*
11480 2a 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 66 20 * comparison of
11490 74 68 65 20 74 77 6f 20 69 6e 64 65 78 20 6b 65 the two index ke
114a0 79 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 74 ys..**.** Note t
114b0 68 61 74 20 61 53 6f 72 74 4f 72 64 65 72 5b 5d hat aSortOrder[]
114c0 20 61 6e 64 20 61 43 6f 6c 6c 5b 5d 20 68 61 76 and aColl[] hav
114d0 65 20 6e 46 69 65 6c 64 2b 31 20 73 6c 6f 74 73 e nField+1 slots
114e0 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 . There.** are
114f0 6e 46 69 65 6c 64 20 73 6c 6f 74 73 20 66 6f 72 nField slots for
11500 20 74 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 the columns of
11510 61 6e 20 69 6e 64 65 78 20 74 68 65 6e 20 6f 6e an index then on
11520 65 20 65 78 74 72 61 20 73 6c 6f 74 0a 2a 2a 20 e extra slot.**
11530 66 6f 72 20 74 68 65 20 72 6f 77 69 64 20 61 74 for the rowid at
11540 20 74 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 the end..*/.str
11550 75 63 74 20 4b 65 79 49 6e 66 6f 20 7b 0a 20 20 uct KeyInfo {.
11560 75 33 32 20 6e 52 65 66 3b 20 20 20 20 20 20 20 u32 nRef;
11570 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
11580 20 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 references to t
11590 68 69 73 20 4b 65 79 49 6e 66 6f 20 6f 62 6a 65 his KeyInfo obje
115a0 63 74 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 ct */. u8 enc;
115b0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
115c0 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 2d 20 6f ext encoding - o
115d0 6e 65 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 ne of the SQLITE
115e0 5f 55 54 46 2a 20 76 61 6c 75 65 73 20 2a 2f 0a _UTF* values */.
115f0 20 20 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 20 u16 nField;
11600 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
11610 6f 66 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 69 of key columns i
11620 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 n the index */.
11630 20 75 31 36 20 6e 58 46 69 65 6c 64 3b 20 20 20 u16 nXField;
11640 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
11650 66 20 63 6f 6c 75 6d 6e 73 20 62 65 79 6f 6e 64 f columns beyond
11660 20 74 68 65 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 the key columns
11670 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 */. sqlite3 *d
11680 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 b; /* The
11690 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
116a0 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 2a 61 53 tion */. u8 *aS
116b0 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 2f 2a ortOrder; /*
116c0 20 53 6f 72 74 20 6f 72 64 65 72 20 66 6f 72 20 Sort order for
116d0 65 61 63 68 20 63 6f 6c 75 6d 6e 2e 20 2a 2f 0a each column. */.
116e0 20 20 43 6f 6c 6c 53 65 71 20 2a 61 43 6f 6c 6c CollSeq *aColl
116f0 5b 31 5d 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 [1]; /* Collati
11700 6e 67 20 73 65 71 75 65 6e 63 65 20 66 6f 72 20 ng sequence for
11710 65 61 63 68 20 74 65 72 6d 20 6f 66 20 74 68 65 each term of the
11720 20 6b 65 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a key */.};../*.*
11730 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
11740 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
11750 74 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 69 tructure holds i
11760 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 nformation about
11770 20 61 0a 2a 2a 20 73 69 6e 67 6c 65 20 69 6e 64 a.** single ind
11780 65 78 20 72 65 63 6f 72 64 20 74 68 61 74 20 68 ex record that h
11790 61 73 20 61 6c 72 65 61 64 79 20 62 65 65 6e 20 as already been
117a0 70 61 72 73 65 64 20 6f 75 74 20 69 6e 74 6f 20 parsed out into
117b0 69 6e 64 69 76 69 64 75 61 6c 0a 2a 2a 20 76 61 individual.** va
117c0 6c 75 65 73 2e 0a 2a 2a 0a 2a 2a 20 41 20 72 65 lues..**.** A re
117d0 63 6f 72 64 20 69 73 20 61 6e 20 6f 62 6a 65 63 cord is an objec
117e0 74 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 t that contains
117f0 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 66 69 65 6c one or more fiel
11800 64 73 20 6f 66 20 64 61 74 61 2e 0a 2a 2a 20 52 ds of data..** R
11810 65 63 6f 72 64 73 20 61 72 65 20 75 73 65 64 20 ecords are used
11820 74 6f 20 73 74 6f 72 65 20 74 68 65 20 63 6f 6e to store the con
11830 74 65 6e 74 20 6f 66 20 61 20 74 61 62 6c 65 20 tent of a table
11840 72 6f 77 20 61 6e 64 20 74 6f 20 73 74 6f 72 65 row and to store
11850 0a 2a 2a 20 74 68 65 20 6b 65 79 20 6f 66 20 61 .** the key of a
11860 6e 20 69 6e 64 65 78 2e 20 20 41 20 62 6c 6f 62 n index. A blob
11870 20 65 6e 63 6f 64 69 6e 67 20 6f 66 20 61 20 72 encoding of a r
11880 65 63 6f 72 64 20 69 73 20 63 72 65 61 74 65 64 ecord is created
11890 20 62 79 0a 2a 2a 20 74 68 65 20 4f 50 5f 4d 61 by.** the OP_Ma
118a0 6b 65 52 65 63 6f 72 64 20 6f 70 63 6f 64 65 20 keRecord opcode
118b0 6f 66 20 74 68 65 20 56 44 42 45 20 61 6e 64 20 of the VDBE and
118c0 69 73 20 64 69 73 61 73 73 65 6d 62 6c 65 64 20 is disassembled
118d0 62 79 20 74 68 65 0a 2a 2a 20 4f 50 5f 43 6f 6c by the.** OP_Col
118e0 75 6d 6e 20 6f 70 63 6f 64 65 2e 0a 2a 2a 0a 2a umn opcode..**.*
118f0 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 * This structure
11900 20 68 6f 6c 64 73 20 61 20 72 65 63 6f 72 64 20 holds a record
11910 74 68 61 74 20 68 61 73 20 61 6c 72 65 61 64 79 that has already
11920 20 62 65 65 6e 20 64 69 73 61 73 73 65 6d 62 6c been disassembl
11930 65 64 0a 2a 2a 20 69 6e 74 6f 20 69 74 73 20 63 ed.** into its c
11940 6f 6e 73 74 69 74 75 65 6e 74 20 66 69 65 6c 64 onstituent field
11950 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 72 31 20 s..**.** The r1
11960 61 6e 64 20 72 32 20 6d 65 6d 62 65 72 20 76 61 and r2 member va
11970 72 69 61 62 6c 65 73 20 61 72 65 20 6f 6e 6c 79 riables are only
11980 20 75 73 65 64 20 62 79 20 74 68 65 20 6f 70 74 used by the opt
11990 69 6d 69 7a 65 64 20 63 6f 6d 70 61 72 69 73 6f imized compariso
119a0 6e 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 20 76 n.** functions v
119b0 64 62 65 52 65 63 6f 72 64 43 6f 6d 70 61 72 65 dbeRecordCompare
119c0 49 6e 74 28 29 20 61 6e 64 20 76 64 62 65 52 65 Int() and vdbeRe
119d0 63 6f 72 64 43 6f 6d 70 61 72 65 53 74 72 69 6e cordCompareStrin
119e0 67 28 29 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 55 g()..*/.struct U
119f0 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 20 7b 0a npackedRecord {.
11a00 20 20 4b 65 79 49 6e 66 6f 20 2a 70 4b 65 79 49 KeyInfo *pKeyI
11a10 6e 66 6f 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 nfo; /* Collati
11a20 6f 6e 20 61 6e 64 20 73 6f 72 74 2d 6f 72 64 65 on and sort-orde
11a30 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f r information */
11a40 0a 20 20 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 . u16 nField;
11a50 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
11a60 20 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 of entries in a
11a70 70 4d 65 6d 5b 5d 20 2a 2f 0a 20 20 69 38 20 64 pMem[] */. i8 d
11a80 65 66 61 75 6c 74 5f 72 63 3b 20 20 20 20 20 20 efault_rc;
11a90 2f 2a 20 43 6f 6d 70 61 72 69 73 6f 6e 20 72 65 /* Comparison re
11aa0 73 75 6c 74 20 69 66 20 6b 65 79 73 20 61 72 65 sult if keys are
11ab0 20 65 71 75 61 6c 20 2a 2f 0a 20 20 75 38 20 65 equal */. u8 e
11ac0 72 72 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 rrCode;
11ad0 2f 2a 20 45 72 72 6f 72 20 64 65 74 65 63 74 65 /* Error detecte
11ae0 64 20 62 79 20 78 52 65 63 6f 72 64 43 6f 6d 70 d by xRecordComp
11af0 61 72 65 20 28 43 4f 52 52 55 50 54 20 6f 72 20 are (CORRUPT or
11b00 4e 4f 4d 45 4d 29 20 2a 2f 0a 20 20 4d 65 6d 20 NOMEM) */. Mem
11b10 2a 61 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 *aMem;
11b20 2f 2a 20 56 61 6c 75 65 73 20 2a 2f 0a 20 20 69 /* Values */. i
11b30 6e 74 20 72 31 3b 20 20 20 20 20 20 20 20 20 20 nt r1;
11b40 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 /* Value to r
11b50 65 74 75 72 6e 20 69 66 20 28 6c 68 73 20 3e 20 eturn if (lhs >
11b60 72 68 73 29 20 2a 2f 0a 20 20 69 6e 74 20 72 32 rhs) */. int r2
11b70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
11b80 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e Value to return
11b90 20 69 66 20 28 72 68 73 20 3c 20 6c 68 73 29 20 if (rhs < lhs)
11ba0 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 */.};.../*.** Ea
11bb0 63 68 20 53 51 4c 20 69 6e 64 65 78 20 69 73 20 ch SQL index is
11bc0 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d represented in m
11bd0 65 6d 6f 72 79 20 62 79 20 61 6e 0a 2a 2a 20 69 emory by an.** i
11be0 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
11bf0 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
11c00 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f re..**.** The co
11c10 6c 75 6d 6e 73 20 6f 66 20 74 68 65 20 74 61 62 lumns of the tab
11c20 6c 65 20 74 68 61 74 20 61 72 65 20 74 6f 20 62 le that are to b
11c30 65 20 69 6e 64 65 78 65 64 20 61 72 65 20 64 65 e indexed are de
11c40 73 63 72 69 62 65 64 0a 2a 2a 20 62 79 20 74 68 scribed.** by th
11c50 65 20 61 69 43 6f 6c 75 6d 6e 5b 5d 20 66 69 65 e aiColumn[] fie
11c60 6c 64 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ld of this struc
11c70 74 75 72 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 ture. For examp
11c80 6c 65 2c 20 73 75 70 70 6f 73 65 0a 2a 2a 20 77 le, suppose.** w
11c90 65 20 68 61 76 65 20 74 68 65 20 66 6f 6c 6c 6f e have the follo
11ca0 77 69 6e 67 20 74 61 62 6c 65 20 61 6e 64 20 69 wing table and i
11cb0 6e 64 65 78 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ndex:.**.**
11cc0 43 52 45 41 54 45 20 54 41 42 4c 45 20 45 78 31 CREATE TABLE Ex1
11cd0 28 63 31 20 69 6e 74 2c 20 63 32 20 69 6e 74 2c (c1 int, c2 int,
11ce0 20 63 33 20 74 65 78 74 29 3b 0a 2a 2a 20 20 20 c3 text);.**
11cf0 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 45 CREATE INDEX E
11d00 78 32 20 4f 4e 20 45 78 31 28 63 33 2c 63 31 29 x2 ON Ex1(c3,c1)
11d10 3b 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 54 ;.**.** In the T
11d20 61 62 6c 65 20 73 74 72 75 63 74 75 72 65 20 64 able structure d
11d30 65 73 63 72 69 62 69 6e 67 20 45 78 31 2c 20 6e escribing Ex1, n
11d40 43 6f 6c 3d 3d 33 20 62 65 63 61 75 73 65 20 74 Col==3 because t
11d50 68 65 72 65 20 61 72 65 0a 2a 2a 20 74 68 72 65 here are.** thre
11d60 65 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 e columns in the
11d70 20 74 61 62 6c 65 2e 20 20 49 6e 20 74 68 65 20 table. In the
11d80 49 6e 64 65 78 20 73 74 72 75 63 74 75 72 65 20 Index structure
11d90 64 65 73 63 72 69 62 69 6e 67 0a 2a 2a 20 45 78 describing.** Ex
11da0 32 2c 20 6e 43 6f 6c 75 6d 6e 3d 3d 32 20 73 69 2, nColumn==2 si
11db0 6e 63 65 20 32 20 6f 66 20 74 68 65 20 33 20 63 nce 2 of the 3 c
11dc0 6f 6c 75 6d 6e 73 20 6f 66 20 45 78 31 20 61 72 olumns of Ex1 ar
11dd0 65 20 69 6e 64 65 78 65 64 2e 0a 2a 2a 20 54 68 e indexed..** Th
11de0 65 20 76 61 6c 75 65 20 6f 66 20 61 69 43 6f 6c e value of aiCol
11df0 75 6d 6e 20 69 73 20 7b 32 2c 20 30 7d 2e 20 20 umn is {2, 0}.
11e00 61 69 43 6f 6c 75 6d 6e 5b 30 5d 3d 3d 32 20 62 aiColumn[0]==2 b
11e10 65 63 61 75 73 65 20 74 68 65 20 0a 2a 2a 20 66 ecause the .** f
11e20 69 72 73 74 20 63 6f 6c 75 6d 6e 20 74 6f 20 62 irst column to b
11e30 65 20 69 6e 64 65 78 65 64 20 28 63 33 29 20 68 e indexed (c3) h
11e40 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 20 32 as an index of 2
11e50 20 69 6e 20 45 78 31 2e 61 43 6f 6c 5b 5d 2e 0a in Ex1.aCol[]..
11e60 2a 2a 20 54 68 65 20 73 65 63 6f 6e 64 20 63 6f ** The second co
11e70 6c 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 65 78 lumn to be index
11e80 65 64 20 28 63 31 29 20 68 61 73 20 61 6e 20 69 ed (c1) has an i
11e90 6e 64 65 78 20 6f 66 20 30 20 69 6e 0a 2a 2a 20 ndex of 0 in.**
11ea0 45 78 31 2e 61 43 6f 6c 5b 5d 2c 20 68 65 6e 63 Ex1.aCol[], henc
11eb0 65 20 45 78 32 2e 61 69 43 6f 6c 75 6d 6e 5b 31 e Ex2.aiColumn[1
11ec0 5d 3d 3d 30 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 ]==0..**.** The
11ed0 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 66 69 Index.onError fi
11ee0 65 6c 64 20 64 65 74 65 72 6d 69 6e 65 73 20 77 eld determines w
11ef0 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 hether or not th
11f00 65 20 69 6e 64 65 78 65 64 20 63 6f 6c 75 6d 6e e indexed column
11f10 73 0a 2a 2a 20 6d 75 73 74 20 62 65 20 75 6e 69 s.** must be uni
11f20 71 75 65 20 61 6e 64 20 77 68 61 74 20 74 6f 20 que and what to
11f30 64 6f 20 69 66 20 74 68 65 79 20 61 72 65 20 6e do if they are n
11f40 6f 74 2e 20 20 57 68 65 6e 20 49 6e 64 65 78 2e ot. When Index.
11f50 6f 6e 45 72 72 6f 72 3d 4f 45 5f 4e 6f 6e 65 2c onError=OE_None,
11f60 0a 2a 2a 20 69 74 20 6d 65 61 6e 73 20 74 68 69 .** it means thi
11f70 73 20 69 73 20 6e 6f 74 20 61 20 75 6e 69 71 75 s is not a uniqu
11f80 65 20 69 6e 64 65 78 2e 20 20 4f 74 68 65 72 77 e index. Otherw
11f90 69 73 65 20 69 74 20 69 73 20 61 20 75 6e 69 71 ise it is a uniq
11fa0 75 65 20 69 6e 64 65 78 0a 2a 2a 20 61 6e 64 20 ue index.** and
11fb0 74 68 65 20 76 61 6c 75 65 20 6f 66 20 49 6e 64 the value of Ind
11fc0 65 78 2e 6f 6e 45 72 72 6f 72 20 69 6e 64 69 63 ex.onError indic
11fd0 61 74 65 20 74 68 65 20 77 68 69 63 68 20 63 6f ate the which co
11fe0 6e 66 6c 69 63 74 20 72 65 73 6f 6c 75 74 69 6f nflict resolutio
11ff0 6e 20 0a 2a 2a 20 61 6c 67 6f 72 69 74 68 6d 20 n .** algorithm
12000 74 6f 20 65 6d 70 6c 6f 79 20 77 68 65 6e 65 76 to employ whenev
12010 65 72 20 61 6e 20 61 74 74 65 6d 70 74 20 69 73 er an attempt is
12020 20 6d 61 64 65 20 74 6f 20 69 6e 73 65 72 74 20 made to insert
12030 61 20 6e 6f 6e 2d 75 6e 69 71 75 65 0a 2a 2a 20 a non-unique.**
12040 65 6c 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 57 element..**.** W
12050 68 69 6c 65 20 70 61 72 73 69 6e 67 20 61 20 43 hile parsing a C
12060 52 45 41 54 45 20 54 41 42 4c 45 20 6f 72 20 43 REATE TABLE or C
12070 52 45 41 54 45 20 49 4e 44 45 58 20 73 74 61 74 REATE INDEX stat
12080 65 6d 65 6e 74 20 69 6e 20 6f 72 64 65 72 20 74 ement in order t
12090 6f 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 56 44 o.** generate VD
120a0 42 45 20 63 6f 64 65 20 28 61 73 20 6f 70 70 6f BE code (as oppo
120b0 73 65 64 20 74 6f 20 70 61 72 73 69 6e 67 20 6f sed to parsing o
120c0 6e 65 20 72 65 61 64 20 66 72 6f 6d 20 61 6e 20 ne read from an
120d0 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 0a 2a 2a sqlite_master.**
120e0 20 74 61 62 6c 65 20 61 73 20 70 61 72 74 20 6f table as part o
120f0 66 20 70 61 72 73 69 6e 67 20 61 6e 20 65 78 69 f parsing an exi
12100 73 74 69 6e 67 20 64 61 74 61 62 61 73 65 20 73 sting database s
12110 63 68 65 6d 61 29 2c 20 74 72 61 6e 73 69 65 6e chema), transien
12120 74 20 69 6e 73 74 61 6e 63 65 73 0a 2a 2a 20 6f t instances.** o
12130 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
12140 20 6d 61 79 20 62 65 20 63 72 65 61 74 65 64 2e may be created.
12150 20 49 6e 20 74 68 69 73 20 63 61 73 65 20 74 68 In this case th
12160 65 20 49 6e 64 65 78 2e 74 6e 75 6d 20 76 61 72 e Index.tnum var
12170 69 61 62 6c 65 20 69 73 0a 2a 2a 20 75 73 65 64 iable is.** used
12180 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 61 64 to store the ad
12190 64 72 65 73 73 20 6f 66 20 61 20 56 44 42 45 20 dress of a VDBE
121a0 69 6e 73 74 72 75 63 74 69 6f 6e 2c 20 6e 6f 74 instruction, not
121b0 20 61 20 64 61 74 61 62 61 73 65 20 70 61 67 65 a database page
121c0 0a 2a 2a 20 6e 75 6d 62 65 72 20 28 69 74 20 63 .** number (it c
121d0 61 6e 6e 6f 74 20 2d 20 74 68 65 20 64 61 74 61 annot - the data
121e0 62 61 73 65 20 70 61 67 65 20 69 73 20 6e 6f 74 base page is not
121f0 20 61 6c 6c 6f 63 61 74 65 64 20 75 6e 74 69 6c allocated until
12200 20 74 68 65 20 56 44 42 45 0a 2a 2a 20 70 72 6f the VDBE.** pro
12210 67 72 61 6d 20 69 73 20 65 78 65 63 75 74 65 64 gram is executed
12220 29 2e 20 53 65 65 20 63 6f 6e 76 65 72 74 54 6f ). See convertTo
12230 57 69 74 68 6f 75 74 52 6f 77 69 64 54 61 62 6c WithoutRowidTabl
12240 65 28 29 20 66 6f 72 20 64 65 74 61 69 6c 73 2e e() for details.
12250 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 78 .*/.struct Index
12260 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 {. char *zName
12270 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
12280 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 69 6e Name of this in
12290 64 65 78 20 2a 2f 0a 20 20 69 31 36 20 2a 61 69 dex */. i16 *ai
122a0 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 Column;
122b0 20 20 2f 2a 20 57 68 69 63 68 20 63 6f 6c 75 6d /* Which colum
122c0 6e 73 20 61 72 65 20 75 73 65 64 20 62 79 20 74 ns are used by t
122d0 68 69 73 20 69 6e 64 65 78 2e 20 20 31 73 74 20 his index. 1st
122e0 69 73 20 30 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 is 0 */. LogEst
122f0 20 2a 61 69 52 6f 77 4c 6f 67 45 73 74 3b 20 20 *aiRowLogEst;
12300 20 20 20 2f 2a 20 46 72 6f 6d 20 41 4e 41 4c 59 /* From ANALY
12310 5a 45 3a 20 45 73 74 2e 20 72 6f 77 73 20 73 65 ZE: Est. rows se
12320 6c 65 63 74 65 64 20 62 79 20 65 61 63 68 20 63 lected by each c
12330 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 54 61 62 6c 65 olumn */. Table
12340 20 2a 70 54 61 62 6c 65 3b 20 20 20 20 20 20 20 *pTable;
12350 20 20 20 20 2f 2a 20 54 68 65 20 53 51 4c 20 74 /* The SQL t
12360 61 62 6c 65 20 62 65 69 6e 67 20 69 6e 64 65 78 able being index
12370 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 ed */. char *zC
12380 6f 6c 41 66 66 3b 20 20 20 20 20 20 20 20 20 20 olAff;
12390 20 2f 2a 20 53 74 72 69 6e 67 20 64 65 66 69 6e /* String defin
123a0 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 79 ing the affinity
123b0 20 6f 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 of each column
123c0 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 4e 65 78 */. Index *pNex
123d0 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a t; /*
123e0 20 54 68 65 20 6e 65 78 74 20 69 6e 64 65 78 20 The next index
123f0 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
12400 74 68 65 20 73 61 6d 65 20 74 61 62 6c 65 20 2a the same table *
12410 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 /. Schema *pSch
12420 65 6d 61 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ema; /*
12430 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 6e Schema containin
12440 67 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a g this index */.
12450 20 20 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 72 u8 *aSortOrder
12460 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 66 6f ; /* fo
12470 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 3a 20 54 r each column: T
12480 72 75 65 3d 3d 44 45 53 43 2c 20 46 61 6c 73 65 rue==DESC, False
12490 3d 3d 41 53 43 20 2a 2f 0a 20 20 63 68 61 72 20 ==ASC */. char
124a0 2a 2a 61 7a 43 6f 6c 6c 3b 20 20 20 20 20 20 20 **azColl;
124b0 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 /* Array of
124c0 63 6f 6c 6c 61 74 69 6f 6e 20 73 65 71 75 65 6e collation sequen
124d0 63 65 20 6e 61 6d 65 73 20 66 6f 72 20 69 6e 64 ce names for ind
124e0 65 78 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 50 ex */. Expr *pP
124f0 61 72 74 49 64 78 57 68 65 72 65 3b 20 20 20 20 artIdxWhere;
12500 20 2f 2a 20 57 48 45 52 45 20 63 6c 61 75 73 65 /* WHERE clause
12510 20 66 6f 72 20 70 61 72 74 69 61 6c 20 69 6e 64 for partial ind
12520 69 63 65 73 20 2a 2f 0a 20 20 69 6e 74 20 74 6e ices */. int tn
12530 75 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 um;
12540 20 20 20 2f 2a 20 44 42 20 50 61 67 65 20 63 6f /* DB Page co
12550 6e 74 61 69 6e 69 6e 67 20 72 6f 6f 74 20 6f 66 ntaining root of
12560 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 this index */.
12570 20 4c 6f 67 45 73 74 20 73 7a 49 64 78 52 6f 77 LogEst szIdxRow
12580 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 ; /* Est
12590 69 6d 61 74 65 64 20 61 76 65 72 61 67 65 20 72 imated average r
125a0 6f 77 20 73 69 7a 65 20 69 6e 20 62 79 74 65 73 ow size in bytes
125b0 20 2a 2f 0a 20 20 75 31 36 20 6e 4b 65 79 43 6f */. u16 nKeyCo
125c0 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f l; /
125d0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 * Number of colu
125e0 6d 6e 73 20 66 6f 72 6d 69 6e 67 20 74 68 65 20 mns forming the
125f0 6b 65 79 20 2a 2f 0a 20 20 75 31 36 20 6e 43 6f key */. u16 nCo
12600 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 20 lumn;
12610 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
12620 6f 6c 75 6d 6e 73 20 73 74 6f 72 65 64 20 69 6e olumns stored in
12630 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 20 the index */.
12640 75 38 20 6f 6e 45 72 72 6f 72 3b 20 20 20 20 20 u8 onError;
12650 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 5f 41 /* OE_A
12660 62 6f 72 74 2c 20 4f 45 5f 49 67 6e 6f 72 65 2c bort, OE_Ignore,
12670 20 4f 45 5f 52 65 70 6c 61 63 65 2c 20 6f 72 20 OE_Replace, or
12680 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a 20 20 75 6e 73 OE_None */. uns
12690 69 67 6e 65 64 20 69 64 78 54 79 70 65 3a 32 3b igned idxType:2;
126a0 20 20 20 20 20 20 2f 2a 20 31 3d 3d 55 4e 49 51 /* 1==UNIQ
126b0 55 45 2c 20 32 3d 3d 50 52 49 4d 41 52 59 20 4b UE, 2==PRIMARY K
126c0 45 59 2c 20 30 3d 3d 43 52 45 41 54 45 20 49 4e EY, 0==CREATE IN
126d0 44 45 58 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 DEX */. unsigne
126e0 64 20 62 55 6e 6f 72 64 65 72 65 64 3a 31 3b 20 d bUnordered:1;
126f0 20 20 2f 2a 20 55 73 65 20 74 68 69 73 20 69 6e /* Use this in
12700 64 65 78 20 66 6f 72 20 3d 3d 20 6f 72 20 49 4e dex for == or IN
12710 20 71 75 65 72 69 65 73 20 6f 6e 6c 79 20 2a 2f queries only */
12720 0a 20 20 75 6e 73 69 67 6e 65 64 20 75 6e 69 71 . unsigned uniq
12730 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 20 2f 2a 20 54 NotNull:1; /* T
12740 72 75 65 20 69 66 20 55 4e 49 51 55 45 20 61 6e rue if UNIQUE an
12750 64 20 4e 4f 54 20 4e 55 4c 4c 20 66 6f 72 20 61 d NOT NULL for a
12760 6c 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 ll columns */.
12770 75 6e 73 69 67 6e 65 64 20 69 73 52 65 73 69 7a unsigned isResiz
12780 65 64 3a 31 3b 20 20 20 20 2f 2a 20 54 72 75 65 ed:1; /* True
12790 20 69 66 20 72 65 73 69 7a 65 49 6e 64 65 78 4f if resizeIndexO
127a0 62 6a 65 63 74 28 29 20 68 61 73 20 62 65 65 6e bject() has been
127b0 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 75 6e 73 called */. uns
127c0 69 67 6e 65 64 20 69 73 43 6f 76 65 72 69 6e 67 igned isCovering
127d0 3a 31 3b 20 20 20 2f 2a 20 54 72 75 65 20 69 66 :1; /* True if
127e0 20 74 68 69 73 20 69 73 20 61 20 63 6f 76 65 72 this is a cover
127f0 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 ing index */. u
12800 6e 73 69 67 6e 65 64 20 6e 6f 53 6b 69 70 53 63 nsigned noSkipSc
12810 61 6e 3a 31 3b 20 20 20 2f 2a 20 44 6f 20 6e 6f an:1; /* Do no
12820 74 20 74 72 79 20 74 6f 20 75 73 65 20 73 6b 69 t try to use ski
12830 70 2d 73 63 61 6e 20 69 66 20 74 72 75 65 20 2a p-scan if true *
12840 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
12850 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f ENABLE_STAT3_OR_
12860 53 54 41 54 34 0a 20 20 69 6e 74 20 6e 53 61 6d STAT4. int nSam
12870 70 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ple;
12880 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6c /* Number of el
12890 65 6d 65 6e 74 73 20 69 6e 20 61 53 61 6d 70 6c ements in aSampl
128a0 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 e[] */. int nSa
128b0 6d 70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 20 20 mpleCol;
128c0 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 49 6e 64 /* Size of Ind
128d0 65 78 53 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d 20 exSample.anEq[]
128e0 61 6e 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 74 and so on */. t
128f0 52 6f 77 63 6e 74 20 2a 61 41 76 67 45 71 3b 20 Rowcnt *aAvgEq;
12900 20 20 20 20 20 20 20 20 2f 2a 20 41 76 65 72 61 /* Avera
12910 67 65 20 6e 45 71 20 76 61 6c 75 65 73 20 66 6f ge nEq values fo
12920 72 20 6b 65 79 73 20 6e 6f 74 20 69 6e 20 61 53 r keys not in aS
12930 61 6d 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 78 ample */. Index
12940 53 61 6d 70 6c 65 20 2a 61 53 61 6d 70 6c 65 3b Sample *aSample;
12950 20 20 20 20 2f 2a 20 53 61 6d 70 6c 65 73 20 6f /* Samples o
12960 66 20 74 68 65 20 6c 65 66 74 2d 6d 6f 73 74 20 f the left-most
12970 6b 65 79 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 key */. tRowcnt
12980 20 2a 61 69 52 6f 77 45 73 74 3b 20 20 20 20 20 *aiRowEst;
12990 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 /* Non-logarit
129a0 68 6d 69 63 20 73 74 61 74 31 20 64 61 74 61 20 hmic stat1 data
129b0 66 6f 72 20 74 68 69 73 20 69 6e 64 65 78 20 2a for this index *
129c0 2f 0a 20 20 74 52 6f 77 63 6e 74 20 6e 52 6f 77 /. tRowcnt nRow
129d0 45 73 74 30 3b 20 20 20 20 20 20 20 20 2f 2a 20 Est0; /*
129e0 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 63 20 Non-logarithmic
129f0 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 number of rows i
12a00 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 23 n the index */.#
12a10 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 endif.};../*.**
12a20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
12a30 6f 72 20 49 6e 64 65 78 2e 69 64 78 54 79 70 65 or Index.idxType
12a40 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
12a50 54 45 5f 49 44 58 54 59 50 45 5f 41 50 50 44 45 TE_IDXTYPE_APPDE
12a60 46 20 20 20 20 20 20 30 20 20 20 2f 2a 20 43 72 F 0 /* Cr
12a70 65 61 74 65 64 20 75 73 69 6e 67 20 43 52 45 41 eated using CREA
12a80 54 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 TE INDEX */.#def
12a90 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 ine SQLITE_IDXTY
12aa0 50 45 5f 55 4e 49 51 55 45 20 20 20 20 20 20 31 PE_UNIQUE 1
12ab0 20 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 73 /* Implements
12ac0 20 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 a UNIQUE constr
12ad0 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aint */.#define
12ae0 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 50 SQLITE_IDXTYPE_P
12af0 52 49 4d 41 52 59 4b 45 59 20 20 32 20 20 20 2f RIMARYKEY 2 /
12b00 2a 20 49 73 20 74 68 65 20 50 52 49 4d 41 52 59 * Is the PRIMARY
12b10 20 4b 45 59 20 66 6f 72 20 74 68 65 20 74 61 62 KEY for the tab
12b20 6c 65 20 2a 2f 0a 0a 2f 2a 20 52 65 74 75 72 6e le */../* Return
12b30 20 74 72 75 65 20 69 66 20 69 6e 64 65 78 20 58 true if index X
12b40 20 69 73 20 61 20 50 52 49 4d 41 52 59 20 4b 45 is a PRIMARY KE
12b50 59 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 Y index */.#defi
12b60 6e 65 20 49 73 50 72 69 6d 61 72 79 4b 65 79 49 ne IsPrimaryKeyI
12b70 6e 64 65 78 28 58 29 20 20 28 28 58 29 2d 3e 69 ndex(X) ((X)->i
12b80 64 78 54 79 70 65 3d 3d 53 51 4c 49 54 45 5f 49 dxType==SQLITE_I
12b90 44 58 54 59 50 45 5f 50 52 49 4d 41 52 59 4b 45 DXTYPE_PRIMARYKE
12ba0 59 29 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 74 72 Y)../* Return tr
12bb0 75 65 20 69 66 20 69 6e 64 65 78 20 58 20 69 73 ue if index X is
12bc0 20 61 20 55 4e 49 51 55 45 20 69 6e 64 65 78 20 a UNIQUE index
12bd0 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 55 6e 69 */.#define IsUni
12be0 71 75 65 49 6e 64 65 78 28 58 29 20 20 20 20 20 queIndex(X)
12bf0 20 28 28 58 29 2d 3e 6f 6e 45 72 72 6f 72 21 3d ((X)->onError!=
12c00 4f 45 5f 4e 6f 6e 65 29 0a 0a 2f 2a 0a 2a 2a 20 OE_None)../*.**
12c10 45 61 63 68 20 73 61 6d 70 6c 65 20 73 74 6f 72 Each sample stor
12c20 65 64 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 ed in the sqlite
12c30 5f 73 74 61 74 33 20 74 61 62 6c 65 20 69 73 20 _stat3 table is
12c40 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d represented in m
12c50 65 6d 6f 72 79 20 0a 2a 2a 20 75 73 69 6e 67 20 emory .** using
12c60 61 20 73 74 72 75 63 74 75 72 65 20 6f 66 20 74 a structure of t
12c70 68 69 73 20 74 79 70 65 2e 20 20 53 65 65 20 64 his type. See d
12c80 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 61 74 20 ocumentation at
12c90 74 68 65 20 74 6f 70 20 6f 66 20 74 68 65 0a 2a the top of the.*
12ca0 2a 20 61 6e 61 6c 79 7a 65 2e 63 20 73 6f 75 72 * analyze.c sour
12cb0 63 65 20 66 69 6c 65 20 66 6f 72 20 61 64 64 69 ce file for addi
12cc0 74 69 6f 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 69 tional informati
12cd0 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e on..*/.struct In
12ce0 64 65 78 53 61 6d 70 6c 65 20 7b 0a 20 20 76 6f dexSample {. vo
12cf0 69 64 20 2a 70 3b 20 20 20 20 20 20 20 20 20 20 id *p;
12d00 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 73 61 /* Pointer to sa
12d10 6d 70 6c 65 64 20 72 65 63 6f 72 64 20 2a 2f 0a mpled record */.
12d20 20 20 69 6e 74 20 6e 3b 20 20 20 20 20 20 20 20 int n;
12d30 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 72 /* Size of r
12d40 65 63 6f 72 64 20 69 6e 20 62 79 74 65 73 20 2a ecord in bytes *
12d50 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 45 /. tRowcnt *anE
12d60 71 3b 20 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 q; /* Est. nu
12d70 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 77 68 65 mber of rows whe
12d80 72 65 20 74 68 65 20 6b 65 79 20 65 71 75 61 6c re the key equal
12d90 73 20 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f s this sample */
12da0 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 4c 74 . tRowcnt *anLt
12db0 3b 20 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d ; /* Est. num
12dc0 62 65 72 20 6f 66 20 72 6f 77 73 20 77 68 65 72 ber of rows wher
12dd0 65 20 6b 65 79 20 69 73 20 6c 65 73 73 20 74 68 e key is less th
12de0 61 6e 20 74 68 69 73 20 73 61 6d 70 6c 65 20 2a an this sample *
12df0 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 44 /. tRowcnt *anD
12e00 4c 74 3b 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 Lt; /* Est. nu
12e10 6d 62 65 72 20 6f 66 20 64 69 73 74 69 6e 63 74 mber of distinct
12e20 20 6b 65 79 73 20 6c 65 73 73 20 74 68 61 6e 20 keys less than
12e30 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 7d this sample */.}
12e40 3b 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 74 6f ;../*.** Each to
12e50 6b 65 6e 20 63 6f 6d 69 6e 67 20 6f 75 74 20 6f ken coming out o
12e60 66 20 74 68 65 20 6c 65 78 65 72 20 69 73 20 61 f the lexer is a
12e70 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 0a 2a 2a n instance of.**
12e80 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 2e this structure.
12e90 20 20 54 6f 6b 65 6e 73 20 61 72 65 20 61 6c 73 Tokens are als
12ea0 6f 20 75 73 65 64 20 61 73 20 70 61 72 74 20 6f o used as part o
12eb0 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 2e f an expression.
12ec0 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 69 66 20 54 .**.** Note if T
12ed0 6f 6b 65 6e 2e 7a 3d 3d 30 20 74 68 65 6e 20 54 oken.z==0 then T
12ee0 6f 6b 65 6e 2e 64 79 6e 20 61 6e 64 20 54 6f 6b oken.dyn and Tok
12ef0 65 6e 2e 6e 20 61 72 65 20 75 6e 64 65 66 69 6e en.n are undefin
12f00 65 64 20 61 6e 64 0a 2a 2a 20 6d 61 79 20 63 6f ed and.** may co
12f10 6e 74 61 69 6e 20 72 61 6e 64 6f 6d 20 76 61 6c ntain random val
12f20 75 65 73 2e 20 20 44 6f 20 6e 6f 74 20 6d 61 6b ues. Do not mak
12f30 65 20 61 6e 79 20 61 73 73 75 6d 70 74 69 6f 6e e any assumption
12f40 73 20 61 62 6f 75 74 20 54 6f 6b 65 6e 2e 64 79 s about Token.dy
12f50 6e 0a 2a 2a 20 61 6e 64 20 54 6f 6b 65 6e 2e 6e n.** and Token.n
12f60 20 77 68 65 6e 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 when Token.z==0
12f70 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 6f 6b 65 ..*/.struct Toke
12f80 6e 20 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 n {. const char
12f90 20 2a 7a 3b 20 20 20 20 20 2f 2a 20 54 65 78 74 *z; /* Text
12fa0 20 6f 66 20 74 68 65 20 74 6f 6b 65 6e 2e 20 20 of the token.
12fb0 4e 6f 74 20 4e 55 4c 4c 2d 74 65 72 6d 69 6e 61 Not NULL-termina
12fc0 74 65 64 21 20 2a 2f 0a 20 20 75 6e 73 69 67 6e ted! */. unsign
12fd0 65 64 20 69 6e 74 20 6e 3b 20 20 20 20 2f 2a 20 ed int n; /*
12fe0 4e 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 63 Number of charac
12ff0 74 65 72 73 20 69 6e 20 74 68 69 73 20 74 6f 6b ters in this tok
13000 65 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 en */.};../*.**
13010 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
13020 68 69 73 20 73 74 72 75 63 74 75 72 65 20 63 6f his structure co
13030 6e 74 61 69 6e 73 20 69 6e 66 6f 72 6d 61 74 69 ntains informati
13040 6f 6e 20 6e 65 65 64 65 64 20 74 6f 20 67 65 6e on needed to gen
13050 65 72 61 74 65 0a 2a 2a 20 63 6f 64 65 20 66 6f erate.** code fo
13060 72 20 61 20 53 45 4c 45 43 54 20 74 68 61 74 20 r a SELECT that
13070 63 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 61 contains aggrega
13080 74 65 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a te functions..**
13090 0a 2a 2a 20 49 66 20 45 78 70 72 2e 6f 70 3d 3d .** If Expr.op==
130a0 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d 4e 20 6f 72 TK_AGG_COLUMN or
130b0 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e TK_AGG_FUNCTION
130c0 20 74 68 65 6e 20 45 78 70 72 2e 70 41 67 67 49 then Expr.pAggI
130d0 6e 66 6f 20 69 73 20 61 0a 2a 2a 20 70 6f 69 6e nfo is a.** poin
130e0 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 ter to this stru
130f0 63 74 75 72 65 2e 20 20 54 68 65 20 45 78 70 72 cture. The Expr
13100 2e 69 43 6f 6c 75 6d 6e 20 66 69 65 6c 64 20 69 .iColumn field i
13110 73 20 74 68 65 20 69 6e 64 65 78 20 69 6e 0a 2a s the index in.*
13120 2a 20 41 67 67 49 6e 66 6f 2e 61 43 6f 6c 5b 5d * AggInfo.aCol[]
13130 20 6f 72 20 41 67 67 49 6e 66 6f 2e 61 46 75 6e or AggInfo.aFun
13140 63 5b 5d 20 6f 66 20 69 6e 66 6f 72 6d 61 74 69 c[] of informati
13150 6f 6e 20 6e 65 65 64 65 64 20 74 6f 20 67 65 6e on needed to gen
13160 65 72 61 74 65 0a 2a 2a 20 63 6f 64 65 20 66 6f erate.** code fo
13170 72 20 74 68 61 74 20 6e 6f 64 65 2e 0a 2a 2a 0a r that node..**.
13180 2a 2a 20 41 67 67 49 6e 66 6f 2e 70 47 72 6f 75 ** AggInfo.pGrou
13190 70 42 79 20 61 6e 64 20 41 67 67 49 6e 66 6f 2e pBy and AggInfo.
131a0 61 46 75 6e 63 2e 70 45 78 70 72 20 70 6f 69 6e aFunc.pExpr poin
131b0 74 20 74 6f 20 66 69 65 6c 64 73 20 77 69 74 68 t to fields with
131c0 69 6e 20 74 68 65 0a 2a 2a 20 6f 72 69 67 69 6e in the.** origin
131d0 61 6c 20 53 65 6c 65 63 74 20 73 74 72 75 63 74 al Select struct
131e0 75 72 65 20 74 68 61 74 20 64 65 73 63 72 69 62 ure that describ
131f0 65 73 20 74 68 65 20 53 45 4c 45 43 54 20 73 74 es the SELECT st
13200 61 74 65 6d 65 6e 74 2e 20 20 54 68 65 73 65 0a atement. These.
13210 2a 2a 20 66 69 65 6c 64 73 20 64 6f 20 6e 6f 74 ** fields do not
13220 20 6e 65 65 64 20 74 6f 20 62 65 20 66 72 65 65 need to be free
13230 64 20 77 68 65 6e 20 64 65 61 6c 6c 6f 63 61 74 d when deallocat
13240 69 6e 67 20 74 68 65 20 41 67 67 49 6e 66 6f 20 ing the AggInfo
13250 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 structure..*/.st
13260 72 75 63 74 20 41 67 67 49 6e 66 6f 20 7b 0a 20 ruct AggInfo {.
13270 20 75 38 20 64 69 72 65 63 74 4d 6f 64 65 3b 20 u8 directMode;
13280 20 20 20 20 20 20 20 20 20 2f 2a 20 44 69 72 65 /* Dire
13290 63 74 20 72 65 6e 64 65 72 69 6e 67 20 6d 6f 64 ct rendering mod
132a0 65 20 6d 65 61 6e 73 20 74 61 6b 65 20 64 61 74 e means take dat
132b0 61 20 64 69 72 65 63 74 6c 79 0a 20 20 20 20 20 a directly.
132c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
132d0 20 20 20 20 20 2a 2a 20 66 72 6f 6d 20 73 6f 75 ** from sou
132e0 72 63 65 20 74 61 62 6c 65 73 20 72 61 74 68 65 rce tables rathe
132f0 72 20 74 68 61 6e 20 66 72 6f 6d 20 61 63 63 75 r than from accu
13300 6d 75 6c 61 74 6f 72 73 20 2a 2f 0a 20 20 75 38 mulators */. u8
13310 20 75 73 65 53 6f 72 74 69 6e 67 49 64 78 3b 20 useSortingIdx;
13320 20 20 20 20 20 20 2f 2a 20 49 6e 20 64 69 72 65 /* In dire
13330 63 74 20 6d 6f 64 65 2c 20 72 65 66 65 72 65 6e ct mode, referen
13340 63 65 20 74 68 65 20 73 6f 72 74 69 6e 67 20 69 ce the sorting i
13350 6e 64 65 78 20 72 61 74 68 65 72 0a 20 20 20 20 ndex rather.
13360 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13370 20 20 20 20 20 20 2a 2a 20 74 68 61 6e 20 74 68 ** than th
13380 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 2a e source table *
13390 2f 0a 20 20 69 6e 74 20 73 6f 72 74 69 6e 67 49 /. int sortingI
133a0 64 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 43 dx; /* C
133b0 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 ursor number of
133c0 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 the sorting inde
133d0 78 20 2a 2f 0a 20 20 69 6e 74 20 73 6f 72 74 69 x */. int sorti
133e0 6e 67 49 64 78 50 54 61 62 3b 20 20 20 20 20 2f ngIdxPTab; /
133f0 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 * Cursor number
13400 6f 66 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 20 of pseudo-table
13410 2a 2f 0a 20 20 69 6e 74 20 6e 53 6f 72 74 69 6e */. int nSortin
13420 67 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 2f 2a 20 gColumn; /*
13430 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e Number of column
13440 73 20 69 6e 20 74 68 65 20 73 6f 72 74 69 6e 67 s in the sorting
13450 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e 74 20 index */. int
13460 6d 6e 52 65 67 2c 20 6d 78 52 65 67 3b 20 20 20 mnReg, mxReg;
13470 20 20 20 20 2f 2a 20 52 61 6e 67 65 20 6f 66 20 /* Range of
13480 72 65 67 69 73 74 65 72 73 20 61 6c 6c 6f 63 61 registers alloca
13490 74 65 64 20 66 6f 72 20 61 43 6f 6c 20 61 6e 64 ted for aCol and
134a0 20 61 46 75 6e 63 20 2a 2f 0a 20 20 45 78 70 72 aFunc */. Expr
134b0 4c 69 73 74 20 2a 70 47 72 6f 75 70 42 79 3b 20 List *pGroupBy;
134c0 20 20 20 20 2f 2a 20 54 68 65 20 67 72 6f 75 70 /* The group
134d0 20 62 79 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 by clause */.
134e0 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 5f 63 struct AggInfo_c
134f0 6f 6c 20 7b 20 20 20 20 2f 2a 20 46 6f 72 20 65 ol { /* For e
13500 61 63 68 20 63 6f 6c 75 6d 6e 20 75 73 65 64 20 ach column used
13510 69 6e 20 73 6f 75 72 63 65 20 74 61 62 6c 65 73 in source tables
13520 20 2a 2f 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 */. Table *p
13530 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tab;
13540 20 2f 2a 20 53 6f 75 72 63 65 20 74 61 62 6c 65 /* Source table
13550 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 54 61 62 */. int iTab
13560 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 le;
13570 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 /* Cursor numbe
13580 72 20 6f 66 20 74 68 65 20 73 6f 75 72 63 65 20 r of the source
13590 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 table */. int
135a0 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 iColumn;
135b0 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 /* Column
135c0 6e 75 6d 62 65 72 20 77 69 74 68 69 6e 20 74 68 number within th
135d0 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 2a e source table *
135e0 2f 0a 20 20 20 20 69 6e 74 20 69 53 6f 72 74 65 /. int iSorte
135f0 72 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 2f rColumn; /
13600 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 * Column number
13610 69 6e 20 74 68 65 20 73 6f 72 74 69 6e 67 20 69 in the sorting i
13620 6e 64 65 78 20 2a 2f 0a 20 20 20 20 69 6e 74 20 ndex */. int
13630 69 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 20 iMem;
13640 20 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c /* Memory l
13650 6f 63 61 74 69 6f 6e 20 74 68 61 74 20 61 63 74 ocation that act
13660 73 20 61 73 20 61 63 63 75 6d 75 6c 61 74 6f 72 s as accumulator
13670 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a 70 45 */. Expr *pE
13680 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 xpr;
13690 20 2f 2a 20 54 68 65 20 6f 72 69 67 69 6e 61 6c /* The original
136a0 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 expression */.
136b0 20 7d 20 2a 61 43 6f 6c 3b 0a 20 20 69 6e 74 20 } *aCol;. int
136c0 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 nColumn;
136d0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
136e0 20 75 73 65 64 20 65 6e 74 72 69 65 73 20 69 6e used entries in
136f0 20 61 43 6f 6c 5b 5d 20 2a 2f 0a 20 20 69 6e 74 aCol[] */. int
13700 20 6e 41 63 63 75 6d 75 6c 61 74 6f 72 3b 20 20 nAccumulator;
13710 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
13720 66 20 63 6f 6c 75 6d 6e 73 20 74 68 61 74 20 73 f columns that s
13730 68 6f 77 20 74 68 72 6f 75 67 68 20 74 6f 20 74 how through to t
13740 68 65 20 6f 75 74 70 75 74 2e 0a 20 20 20 20 20 he output..
13750 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13760 20 20 20 20 20 2a 2a 20 41 64 64 69 74 69 6f 6e ** Addition
13770 61 6c 20 63 6f 6c 75 6d 6e 73 20 61 72 65 20 75 al columns are u
13780 73 65 64 20 6f 6e 6c 79 20 61 73 20 70 61 72 61 sed only as para
13790 6d 65 74 65 72 73 20 74 6f 0a 20 20 20 20 20 20 meters to.
137a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
137b0 20 20 20 20 2a 2a 20 61 67 67 72 65 67 61 74 65 ** aggregate
137c0 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 functions */.
137d0 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 5f 66 struct AggInfo_f
137e0 75 6e 63 20 7b 20 20 20 2f 2a 20 46 6f 72 20 65 unc { /* For e
137f0 61 63 68 20 61 67 67 72 65 67 61 74 65 20 66 75 ach aggregate fu
13800 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 45 78 nction */. Ex
13810 70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 pr *pExpr;
13820 20 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 /* Expres
13830 73 69 6f 6e 20 65 6e 63 6f 64 69 6e 67 20 74 68 sion encoding th
13840 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 e function */.
13850 20 20 46 75 6e 63 44 65 66 20 2a 70 46 75 6e 63 FuncDef *pFunc
13860 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ; /* Th
13870 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 e aggregate func
13880 74 69 6f 6e 20 69 6d 70 6c 65 6d 65 6e 74 61 74 tion implementat
13890 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 ion */. int i
138a0 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 Mem;
138b0 20 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c 6f /* Memory lo
138c0 63 61 74 69 6f 6e 20 74 68 61 74 20 61 63 74 73 cation that acts
138d0 20 61 73 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 as accumulator
138e0 2a 2f 0a 20 20 20 20 69 6e 74 20 69 44 69 73 74 */. int iDist
138f0 69 6e 63 74 3b 20 20 20 20 20 20 20 20 20 20 20 inct;
13900 2f 2a 20 45 70 68 65 6d 65 72 61 6c 20 74 61 62 /* Ephemeral tab
13910 6c 65 20 75 73 65 64 20 74 6f 20 65 6e 66 6f 72 le used to enfor
13920 63 65 20 44 49 53 54 49 4e 43 54 20 2a 2f 0a 20 ce DISTINCT */.
13930 20 7d 20 2a 61 46 75 6e 63 3b 0a 20 20 69 6e 74 } *aFunc;. int
13940 20 6e 46 75 6e 63 3b 20 20 20 20 20 20 20 20 20 nFunc;
13950 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
13960 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 46 75 f entries in aFu
13970 6e 63 5b 5d 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a nc[] */.};../*.*
13980 2a 20 54 68 65 20 64 61 74 61 74 79 70 65 20 79 * The datatype y
13990 6e 56 61 72 20 69 73 20 61 20 73 69 67 6e 65 64 nVar is a signed
139a0 20 69 6e 74 65 67 65 72 2c 20 65 69 74 68 65 72 integer, either
139b0 20 31 36 2d 62 69 74 20 6f 72 20 33 32 2d 62 69 16-bit or 32-bi
139c0 74 2e 0a 2a 2a 20 55 73 75 61 6c 6c 79 20 69 74 t..** Usually it
139d0 20 69 73 20 31 36 2d 62 69 74 73 2e 20 20 42 75 is 16-bits. Bu
139e0 74 20 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f t if SQLITE_MAX_
139f0 56 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 20 VARIABLE_NUMBER
13a00 69 73 20 67 72 65 61 74 65 72 0a 2a 2a 20 74 68 is greater.** th
13a10 61 6e 20 33 32 37 36 37 20 77 65 20 68 61 76 65 an 32767 we have
13a20 20 74 6f 20 6d 61 6b 65 20 69 74 20 33 32 2d 62 to make it 32-b
13a30 69 74 2e 20 20 31 36 2d 62 69 74 20 69 73 20 70 it. 16-bit is p
13a40 72 65 66 65 72 72 65 64 20 62 65 63 61 75 73 65 referred because
13a50 0a 2a 2a 20 69 74 20 75 73 65 73 20 6c 65 73 73 .** it uses less
13a60 20 6d 65 6d 6f 72 79 20 69 6e 20 74 68 65 20 45 memory in the E
13a70 78 70 72 20 6f 62 6a 65 63 74 2c 20 77 68 69 63 xpr object, whic
13a80 68 20 69 73 20 61 20 62 69 67 20 6d 65 6d 6f 72 h is a big memor
13a90 79 20 75 73 65 72 0a 2a 2a 20 69 6e 20 73 79 73 y user.** in sys
13aa0 74 65 6d 73 20 77 69 74 68 20 6c 6f 74 73 20 6f tems with lots o
13ab0 66 20 70 72 65 70 61 72 65 64 20 73 74 61 74 65 f prepared state
13ac0 6d 65 6e 74 73 2e 20 20 41 6e 64 20 66 65 77 20 ments. And few
13ad0 61 70 70 6c 69 63 61 74 69 6f 6e 73 0a 2a 2a 20 applications.**
13ae0 6e 65 65 64 20 6d 6f 72 65 20 74 68 61 6e 20 61 need more than a
13af0 62 6f 75 74 20 31 30 20 6f 72 20 32 30 20 76 61 bout 10 or 20 va
13b00 72 69 61 62 6c 65 73 2e 20 20 42 75 74 20 73 6f riables. But so
13b10 6d 65 20 65 78 74 72 65 6d 65 20 75 73 65 72 73 me extreme users
13b20 20 77 61 6e 74 0a 2a 2a 20 74 6f 20 68 61 76 65 want.** to have
13b30 20 70 72 65 70 61 72 65 64 20 73 74 61 74 65 6d prepared statem
13b40 65 6e 74 73 20 77 69 74 68 20 6f 76 65 72 20 33 ents with over 3
13b50 32 37 36 37 20 76 61 72 69 61 62 6c 65 73 2c 20 2767 variables,
13b60 61 6e 64 20 66 6f 72 20 74 68 65 6d 0a 2a 2a 20 and for them.**
13b70 74 68 65 20 6f 70 74 69 6f 6e 20 69 73 20 61 76 the option is av
13b80 61 69 6c 61 62 6c 65 20 28 61 74 20 63 6f 6d 70 ailable (at comp
13b90 69 6c 65 2d 74 69 6d 65 29 2e 0a 2a 2f 0a 23 69 ile-time)..*/.#i
13ba0 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52 f SQLITE_MAX_VAR
13bb0 49 41 42 4c 45 5f 4e 55 4d 42 45 52 3c 3d 33 32 IABLE_NUMBER<=32
13bc0 37 36 37 0a 74 79 70 65 64 65 66 20 69 31 36 20 767.typedef i16
13bd0 79 6e 56 61 72 3b 0a 23 65 6c 73 65 0a 74 79 70 ynVar;.#else.typ
13be0 65 64 65 66 20 69 6e 74 20 79 6e 56 61 72 3b 0a edef int ynVar;.
13bf0 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 61 #endif../*.** Ea
13c00 63 68 20 6e 6f 64 65 20 6f 66 20 61 6e 20 65 78 ch node of an ex
13c10 70 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 20 pression in the
13c20 70 61 72 73 65 20 74 72 65 65 20 69 73 20 61 6e parse tree is an
13c30 20 69 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 instance.** of
13c40 74 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 0a this structure..
13c50 2a 2a 0a 2a 2a 20 45 78 70 72 2e 6f 70 20 69 73 **.** Expr.op is
13c60 20 74 68 65 20 6f 70 63 6f 64 65 2e 20 54 68 65 the opcode. The
13c70 20 69 6e 74 65 67 65 72 20 70 61 72 73 65 72 20 integer parser
13c80 74 6f 6b 65 6e 20 63 6f 64 65 73 20 61 72 65 20 token codes are
13c90 72 65 75 73 65 64 0a 2a 2a 20 61 73 20 6f 70 63 reused.** as opc
13ca0 6f 64 65 73 20 68 65 72 65 2e 20 46 6f 72 20 65 odes here. For e
13cb0 78 61 6d 70 6c 65 2c 20 74 68 65 20 70 61 72 73 xample, the pars
13cc0 65 72 20 64 65 66 69 6e 65 73 20 54 4b 5f 47 45 er defines TK_GE
13cd0 20 74 6f 20 62 65 20 61 6e 20 69 6e 74 65 67 65 to be an intege
13ce0 72 0a 2a 2a 20 63 6f 64 65 20 72 65 70 72 65 73 r.** code repres
13cf0 65 6e 74 69 6e 67 20 74 68 65 20 22 3e 3d 22 20 enting the ">="
13d00 6f 70 65 72 61 74 6f 72 2e 20 54 68 69 73 20 73 operator. This s
13d10 61 6d 65 20 69 6e 74 65 67 65 72 20 63 6f 64 65 ame integer code
13d20 20 69 73 20 72 65 75 73 65 64 0a 2a 2a 20 74 6f is reused.** to
13d30 20 72 65 70 72 65 73 65 6e 74 20 74 68 65 20 67 represent the g
13d40 72 65 61 74 65 72 2d 74 68 61 6e 2d 6f 72 2d 65 reater-than-or-e
13d50 71 75 61 6c 2d 74 6f 20 6f 70 65 72 61 74 6f 72 qual-to operator
13d60 20 69 6e 20 74 68 65 20 65 78 70 72 65 73 73 69 in the expressi
13d70 6f 6e 0a 2a 2a 20 74 72 65 65 2e 0a 2a 2a 0a 2a on.** tree..**.*
13d80 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 73 73 * If the express
13d90 69 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 6c 69 ion is an SQL li
13da0 74 65 72 61 6c 20 28 54 4b 5f 49 4e 54 45 47 45 teral (TK_INTEGE
13db0 52 2c 20 54 4b 5f 46 4c 4f 41 54 2c 20 54 4b 5f R, TK_FLOAT, TK_
13dc0 42 4c 4f 42 2c 20 0a 2a 2a 20 6f 72 20 54 4b 5f BLOB, .** or TK_
13dd0 53 54 52 49 4e 47 29 2c 20 74 68 65 6e 20 45 78 STRING), then Ex
13de0 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e pr.token contain
13df0 73 20 74 68 65 20 74 65 78 74 20 6f 66 20 74 68 s the text of th
13e00 65 20 53 51 4c 20 6c 69 74 65 72 61 6c 2e 20 49 e SQL literal. I
13e10 66 0a 2a 2a 20 74 68 65 20 65 78 70 72 65 73 73 f.** the express
13e20 69 6f 6e 20 69 73 20 61 20 76 61 72 69 61 62 6c ion is a variabl
13e30 65 20 28 54 4b 5f 56 41 52 49 41 42 4c 45 29 2c e (TK_VARIABLE),
13e40 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e then Expr.token
13e50 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 0a 2a contains the .*
13e60 2a 20 76 61 72 69 61 62 6c 65 20 6e 61 6d 65 2e * variable name.
13e70 20 46 69 6e 61 6c 6c 79 2c 20 69 66 20 74 68 65 Finally, if the
13e80 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 expression is a
13e90 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 28 n SQL function (
13ea0 54 4b 5f 46 55 4e 43 54 49 4f 4e 29 2c 0a 2a 2a TK_FUNCTION),.**
13eb0 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e then Expr.token
13ec0 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 6e 61 contains the na
13ed0 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 74 69 me of the functi
13ee0 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 70 on..**.** Expr.p
13ef0 52 69 67 68 74 20 61 6e 64 20 45 78 70 72 2e 70 Right and Expr.p
13f00 4c 65 66 74 20 61 72 65 20 74 68 65 20 6c 65 66 Left are the lef
13f10 74 20 61 6e 64 20 72 69 67 68 74 20 73 75 62 65 t and right sube
13f20 78 70 72 65 73 73 69 6f 6e 73 20 6f 66 20 61 0a xpressions of a.
13f30 2a 2a 20 62 69 6e 61 72 79 20 6f 70 65 72 61 74 ** binary operat
13f40 6f 72 2e 20 45 69 74 68 65 72 20 6f 72 20 62 6f or. Either or bo
13f50 74 68 20 6d 61 79 20 62 65 20 4e 55 4c 4c 2e 0a th may be NULL..
13f60 2a 2a 0a 2a 2a 20 45 78 70 72 2e 78 2e 70 4c 69 **.** Expr.x.pLi
13f70 73 74 20 69 73 20 61 20 6c 69 73 74 20 6f 66 20 st is a list of
13f80 61 72 67 75 6d 65 6e 74 73 20 69 66 20 74 68 65 arguments if the
13f90 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 expression is a
13fa0 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 2c 0a n SQL function,.
13fb0 2a 2a 20 61 20 43 41 53 45 20 65 78 70 72 65 73 ** a CASE expres
13fc0 73 69 6f 6e 20 6f 72 20 61 6e 20 49 4e 20 65 78 sion or an IN ex
13fd0 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 68 65 20 pression of the
13fe0 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 form "<lhs> IN (
13ff0 3c 79 3e 2c 20 3c 7a 3e 2e 2e 2e 29 22 2e 0a 2a <y>, <z>...)"..*
14000 2a 20 45 78 70 72 2e 78 2e 70 53 65 6c 65 63 74 * Expr.x.pSelect
14010 20 69 73 20 75 73 65 64 20 69 66 20 74 68 65 20 is used if the
14020 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 20 expression is a
14030 73 75 62 2d 73 65 6c 65 63 74 20 6f 72 20 61 6e sub-select or an
14040 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 0a 2a expression of.*
14050 2a 20 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 73 * the form "<lhs
14060 3e 20 49 4e 20 28 53 45 4c 45 43 54 20 2e 2e 2e > IN (SELECT ...
14070 29 22 2e 20 49 66 20 74 68 65 20 45 50 5f 78 49 )". If the EP_xI
14080 73 53 65 6c 65 63 74 20 62 69 74 20 69 73 20 73 sSelect bit is s
14090 65 74 20 69 6e 20 74 68 65 0a 2a 2a 20 45 78 70 et in the.** Exp
140a0 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 r.flags mask, th
140b0 65 6e 20 45 78 70 72 2e 78 2e 70 53 65 6c 65 63 en Expr.x.pSelec
140c0 74 20 69 73 20 76 61 6c 69 64 2e 20 4f 74 68 65 t is valid. Othe
140d0 72 77 69 73 65 2c 20 45 78 70 72 2e 78 2e 70 4c rwise, Expr.x.pL
140e0 69 73 74 20 69 73 20 0a 2a 2a 20 76 61 6c 69 64 ist is .** valid
140f0 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 65 78 70 72 65 ..**.** An expre
14100 73 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 6f 72 ssion of the for
14110 6d 20 49 44 20 6f 72 20 49 44 2e 49 44 20 72 65 m ID or ID.ID re
14120 66 65 72 73 20 74 6f 20 61 20 63 6f 6c 75 6d 6e fers to a column
14130 20 69 6e 20 61 20 74 61 62 6c 65 2e 0a 2a 2a 20 in a table..**
14140 46 6f 72 20 73 75 63 68 20 65 78 70 72 65 73 73 For such express
14150 69 6f 6e 73 2c 20 45 78 70 72 2e 6f 70 20 69 73 ions, Expr.op is
14160 20 73 65 74 20 74 6f 20 54 4b 5f 43 4f 4c 55 4d set to TK_COLUM
14170 4e 20 61 6e 64 20 45 78 70 72 2e 69 54 61 62 6c N and Expr.iTabl
14180 65 20 69 73 0a 2a 2a 20 74 68 65 20 69 6e 74 65 e is.** the inte
14190 67 65 72 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 ger cursor numbe
141a0 72 20 6f 66 20 61 20 56 44 42 45 20 63 75 72 73 r of a VDBE curs
141b0 6f 72 20 70 6f 69 6e 74 69 6e 67 20 74 6f 20 74 or pointing to t
141c0 68 61 74 20 74 61 62 6c 65 20 61 6e 64 0a 2a 2a hat table and.**
141d0 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 69 73 Expr.iColumn is
141e0 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 the column numb
141f0 65 72 20 66 6f 72 20 74 68 65 20 73 70 65 63 69 er for the speci
14200 66 69 63 20 63 6f 6c 75 6d 6e 2e 20 20 49 66 20 fic column. If
14210 74 68 65 0a 2a 2a 20 65 78 70 72 65 73 73 69 6f the.** expressio
14220 6e 20 69 73 20 75 73 65 64 20 61 73 20 61 20 72 n is used as a r
14230 65 73 75 6c 74 20 69 6e 20 61 6e 20 61 67 67 72 esult in an aggr
14240 65 67 61 74 65 20 53 45 4c 45 43 54 2c 20 74 68 egate SELECT, th
14250 65 6e 20 74 68 65 0a 2a 2a 20 76 61 6c 75 65 20 en the.** value
14260 69 73 20 61 6c 73 6f 20 73 74 6f 72 65 64 20 69 is also stored i
14270 6e 20 74 68 65 20 45 78 70 72 2e 69 41 67 67 20 n the Expr.iAgg
14280 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 20 61 67 column in the ag
14290 67 72 65 67 61 74 65 20 73 6f 20 74 68 61 74 0a gregate so that.
142a0 2a 2a 20 69 74 20 63 61 6e 20 62 65 20 61 63 63 ** it can be acc
142b0 65 73 73 65 64 20 61 66 74 65 72 20 61 6c 6c 20 essed after all
142c0 61 67 67 72 65 67 61 74 65 73 20 61 72 65 20 63 aggregates are c
142d0 6f 6d 70 75 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 49 omputed..**.** I
142e0 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e f the expression
142f0 20 69 73 20 61 6e 20 75 6e 62 6f 75 6e 64 20 76 is an unbound v
14300 61 72 69 61 62 6c 65 20 6d 61 72 6b 65 72 20 28 ariable marker (
14310 61 20 71 75 65 73 74 69 6f 6e 20 6d 61 72 6b 20 a question mark
14320 0a 2a 2a 20 63 68 61 72 61 63 74 65 72 20 27 3f .** character '?
14330 27 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e 61 ' in the origina
14340 6c 20 53 51 4c 29 20 74 68 65 6e 20 74 68 65 20 l SQL) then the
14350 45 78 70 72 2e 69 54 61 62 6c 65 20 68 6f 6c 64 Expr.iTable hold
14360 73 20 74 68 65 20 69 6e 64 65 78 20 0a 2a 2a 20 s the index .**
14370 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 61 74 20 number for that
14380 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 variable..**.**
14390 49 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f If the expressio
143a0 6e 20 69 73 20 61 20 73 75 62 71 75 65 72 79 20 n is a subquery
143b0 74 68 65 6e 20 45 78 70 72 2e 69 43 6f 6c 75 6d then Expr.iColum
143c0 6e 20 68 6f 6c 64 73 20 61 6e 20 69 6e 74 65 67 n holds an integ
143d0 65 72 0a 2a 2a 20 72 65 67 69 73 74 65 72 20 6e er.** register n
143e0 75 6d 62 65 72 20 63 6f 6e 74 61 69 6e 69 6e 67 umber containing
143f0 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 74 the result of t
14400 68 65 20 73 75 62 71 75 65 72 79 2e 20 20 49 66 he subquery. If
14410 20 74 68 65 0a 2a 2a 20 73 75 62 71 75 65 72 79 the.** subquery
14420 20 67 69 76 65 73 20 61 20 63 6f 6e 73 74 61 6e gives a constan
14430 74 20 72 65 73 75 6c 74 2c 20 74 68 65 6e 20 69 t result, then i
14440 54 61 62 6c 65 20 69 73 20 2d 31 2e 20 20 49 66 Table is -1. If
14450 20 74 68 65 20 73 75 62 71 75 65 72 79 0a 2a 2a the subquery.**
14460 20 67 69 76 65 73 20 61 20 64 69 66 66 65 72 65 gives a differe
14470 6e 74 20 61 6e 73 77 65 72 20 61 74 20 64 69 66 nt answer at dif
14480 66 65 72 65 6e 74 20 74 69 6d 65 73 20 64 75 72 ferent times dur
14490 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 20 70 72 ing statement pr
144a0 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 74 68 65 6e ocessing.** then
144b0 20 69 54 61 62 6c 65 20 69 73 20 74 68 65 20 61 iTable is the a
144c0 64 64 72 65 73 73 20 6f 66 20 61 20 73 75 62 72 ddress of a subr
144d0 6f 75 74 69 6e 65 20 74 68 61 74 20 63 6f 6d 70 outine that comp
144e0 75 74 65 73 20 74 68 65 20 73 75 62 71 75 65 72 utes the subquer
144f0 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 y..**.** If the
14500 45 78 70 72 20 69 73 20 6f 66 20 74 79 70 65 20 Expr is of type
14510 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 6e 64 20 74 OP_Column, and t
14520 68 65 20 74 61 62 6c 65 20 69 74 20 69 73 20 73 he table it is s
14530 65 6c 65 63 74 69 6e 67 20 66 72 6f 6d 0a 2a 2a electing from.**
14540 20 69 73 20 61 20 64 69 73 6b 20 74 61 62 6c 65 is a disk table
14550 20 6f 72 20 74 68 65 20 22 6f 6c 64 2e 2a 22 20 or the "old.*"
14560 70 73 65 75 64 6f 2d 74 61 62 6c 65 2c 20 74 68 pseudo-table, th
14570 65 6e 20 70 54 61 62 20 70 6f 69 6e 74 73 20 74 en pTab points t
14580 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 o the.** corresp
14590 6f 6e 64 69 6e 67 20 74 61 62 6c 65 20 64 65 66 onding table def
145a0 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 41 inition..**.** A
145b0 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f 54 45 53 3a LLOCATION NOTES:
145c0 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 6f 62 6a 65 .**.** Expr obje
145d0 63 74 73 20 63 61 6e 20 75 73 65 20 61 20 6c 6f cts can use a lo
145e0 74 20 6f 66 20 6d 65 6d 6f 72 79 20 73 70 61 63 t of memory spac
145f0 65 20 69 6e 20 64 61 74 61 62 61 73 65 20 73 63 e in database sc
14600 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a 20 68 65 6c hema. To.** hel
14610 70 20 72 65 64 75 63 65 20 6d 65 6d 6f 72 79 20 p reduce memory
14620 72 65 71 75 69 72 65 6d 65 6e 74 73 2c 20 73 6f requirements, so
14630 6d 65 74 69 6d 65 73 20 61 6e 20 45 78 70 72 20 metimes an Expr
14640 6f 62 6a 65 63 74 20 77 69 6c 6c 20 62 65 0a 2a object will be.*
14650 2a 20 74 72 75 6e 63 61 74 65 64 2e 20 20 41 6e * truncated. An
14660 64 20 74 6f 20 72 65 64 75 63 65 20 74 68 65 20 d to reduce the
14670 6e 75 6d 62 65 72 20 6f 66 20 6d 65 6d 6f 72 79 number of memory
14680 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 2c 20 73 6f allocations, so
14690 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 77 6f 20 6f metimes.** two o
146a0 72 20 6d 6f 72 65 20 45 78 70 72 20 6f 62 6a 65 r more Expr obje
146b0 63 74 73 20 77 69 6c 6c 20 62 65 20 73 74 6f 72 cts will be stor
146c0 65 64 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 6d ed in a single m
146d0 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e emory allocation
146e0 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 72 20 77 69 ,.** together wi
146f0 74 68 20 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 73 th Expr.zToken s
14700 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 trings..**.** If
14710 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 the EP_Reduced
14720 61 6e 64 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 and EP_TokenOnly
14730 20 66 6c 61 67 73 20 61 72 65 20 73 65 74 20 77 flags are set w
14740 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 70 72 20 6f hen.** an Expr o
14750 62 6a 65 63 74 20 69 73 20 74 72 75 6e 63 61 74 bject is truncat
14760 65 64 2e 20 20 57 68 65 6e 20 45 50 5f 52 65 64 ed. When EP_Red
14770 75 63 65 64 20 69 73 20 73 65 74 2c 20 74 68 65 uced is set, the
14780 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 20 63 68 69 n all.** the chi
14790 6c 64 20 45 78 70 72 20 6f 62 6a 65 63 74 73 20 ld Expr objects
147a0 69 6e 20 74 68 65 20 45 78 70 72 2e 70 4c 65 66 in the Expr.pLef
147b0 74 20 61 6e 64 20 45 78 70 72 2e 70 52 69 67 68 t and Expr.pRigh
147c0 74 20 73 75 62 74 72 65 65 73 0a 2a 2a 20 61 72 t subtrees.** ar
147d0 65 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 e contained with
147e0 69 6e 20 74 68 65 20 73 61 6d 65 20 6d 65 6d 6f in the same memo
147f0 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 ry allocation.
14800 4e 6f 74 65 2c 20 68 6f 77 65 76 65 72 2c 20 74 Note, however, t
14810 68 61 74 0a 2a 2a 20 74 68 65 20 73 75 62 74 72 hat.** the subtr
14820 65 65 73 20 69 6e 20 45 78 70 72 2e 78 2e 70 4c ees in Expr.x.pL
14830 69 73 74 20 6f 72 20 45 78 70 72 2e 78 2e 70 53 ist or Expr.x.pS
14840 65 6c 65 63 74 20 61 72 65 20 61 6c 77 61 79 73 elect are always
14850 20 73 65 70 61 72 61 74 65 6c 79 0a 2a 2a 20 61 separately.** a
14860 6c 6c 6f 63 61 74 65 64 2c 20 72 65 67 61 72 64 llocated, regard
14870 6c 65 73 73 20 6f 66 20 77 68 65 74 68 65 72 20 less of whether
14880 6f 72 20 6e 6f 74 20 45 50 5f 52 65 64 75 63 65 or not EP_Reduce
14890 64 20 69 73 20 73 65 74 2e 0a 2a 2f 0a 73 74 72 d is set..*/.str
148a0 75 63 74 20 45 78 70 72 20 7b 0a 20 20 75 38 20 uct Expr {. u8
148b0 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 op;
148c0 20 20 20 20 2f 2a 20 4f 70 65 72 61 74 69 6f 6e /* Operation
148d0 20 70 65 72 66 6f 72 6d 65 64 20 62 79 20 74 68 performed by th
148e0 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 20 63 68 61 is node */. cha
148f0 72 20 61 66 66 69 6e 69 74 79 3b 20 20 20 20 20 r affinity;
14900 20 20 20 20 2f 2a 20 54 68 65 20 61 66 66 69 6e /* The affin
14910 69 74 79 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d ity of the colum
14920 6e 20 6f 72 20 30 20 69 66 20 6e 6f 74 20 61 20 n or 0 if not a
14930 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 75 33 32 20 column */. u32
14940 66 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 flags;
14950 20 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 66 6c /* Various fl
14960 61 67 73 2e 20 20 45 50 5f 2a 20 53 65 65 20 62 ags. EP_* See b
14970 65 6c 6f 77 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 elow */. union
14980 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a 54 6f 6b {. char *zTok
14990 65 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 en; /*
149a0 54 6f 6b 65 6e 20 76 61 6c 75 65 2e 20 5a 65 72 Token value. Zer
149b0 6f 20 74 65 72 6d 69 6e 61 74 65 64 20 61 6e 64 o terminated and
149c0 20 64 65 71 75 6f 74 65 64 20 2a 2f 0a 20 20 20 dequoted */.
149d0 20 69 6e 74 20 69 56 61 6c 75 65 3b 20 20 20 20 int iValue;
149e0 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6e /* Non-n
149f0 65 67 61 74 69 76 65 20 69 6e 74 65 67 65 72 20 egative integer
14a00 76 61 6c 75 65 20 69 66 20 45 50 5f 49 6e 74 56 value if EP_IntV
14a10 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a 0a alue */. } u;..
14a20 20 20 2f 2a 20 49 66 20 74 68 65 20 45 50 5f 54 /* If the EP_T
14a30 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 69 73 okenOnly flag is
14a40 20 73 65 74 20 69 6e 20 74 68 65 20 45 78 70 72 set in the Expr
14a50 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 .flags mask, the
14a60 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 65 20 n no. ** space
14a70 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 is allocated for
14a80 20 74 68 65 20 66 69 65 6c 64 73 20 62 65 6c 6f the fields belo
14a90 77 20 74 68 69 73 20 70 6f 69 6e 74 2e 20 41 6e w this point. An
14aa0 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 20 2a 2a attempt to. **
14ab0 20 61 63 63 65 73 73 20 74 68 65 6d 20 77 69 6c access them wil
14ac0 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 20 73 65 l result in a se
14ad0 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c 66 75 6e gfault or malfun
14ae0 63 74 69 6f 6e 2e 20 0a 20 20 2a 2a 2a 2a 2a 2a ction. . ******
14af0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14b00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14b10 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14b20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f ***************/
14b30 0a 0a 20 20 45 78 70 72 20 2a 70 4c 65 66 74 3b .. Expr *pLeft;
14b40 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 /* Le
14b50 66 74 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 ft subnode */.
14b60 45 78 70 72 20 2a 70 52 69 67 68 74 3b 20 20 20 Expr *pRight;
14b70 20 20 20 20 20 20 20 2f 2a 20 52 69 67 68 74 20 /* Right
14b80 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 subnode */. uni
14b90 6f 6e 20 7b 0a 20 20 20 20 45 78 70 72 4c 69 73 on {. ExprLis
14ba0 74 20 2a 70 4c 69 73 74 3b 20 20 20 20 20 2f 2a t *pList; /*
14bb0 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 53 op = IN, EXISTS
14bc0 2c 20 53 45 4c 45 43 54 2c 20 43 41 53 45 2c 20 , SELECT, CASE,
14bd0 46 55 4e 43 54 49 4f 4e 2c 20 42 45 54 57 45 45 FUNCTION, BETWEE
14be0 4e 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 N */. Select
14bf0 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a *pSelect; /*
14c00 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 61 6e EP_xIsSelect an
14c10 64 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 d op = IN, EXIST
14c20 53 2c 20 53 45 4c 45 43 54 20 2a 2f 0a 20 20 7d S, SELECT */. }
14c30 20 78 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 68 65 x;.. /* If the
14c40 20 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 67 EP_Reduced flag
14c50 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 20 45 is set in the E
14c60 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 xpr.flags mask,
14c70 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 then no. ** spa
14c80 63 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 ce is allocated
14c90 66 6f 72 20 74 68 65 20 66 69 65 6c 64 73 20 62 for the fields b
14ca0 65 6c 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 2e elow this point.
14cb0 20 41 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 An attempt to.
14cc0 20 2a 2a 20 61 63 63 65 73 73 20 74 68 65 6d 20 ** access them
14cd0 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 will result in a
14ce0 20 73 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c segfault or mal
14cf0 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a function.. ****
14d00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14d10 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14d20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14d30 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
14d40 2a 2f 0a 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d */..#if SQLITE_M
14d50 41 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 0a AX_EXPR_DEPTH>0.
14d60 20 20 69 6e 74 20 6e 48 65 69 67 68 74 3b 20 20 int nHeight;
14d70 20 20 20 20 20 20 20 20 20 2f 2a 20 48 65 69 67 /* Heig
14d80 68 74 20 6f 66 20 74 68 65 20 74 72 65 65 20 68 ht of the tree h
14d90 65 61 64 65 64 20 62 79 20 74 68 69 73 20 6e 6f eaded by this no
14da0 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 de */.#endif. i
14db0 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 20 20 nt iTable;
14dc0 20 20 20 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c 55 /* TK_COLU
14dd0 4d 4e 3a 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 MN: cursor numbe
14de0 72 20 6f 66 20 74 61 62 6c 65 20 68 6f 6c 64 69 r of table holdi
14df0 6e 67 20 63 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 ng column.
14e00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14e10 20 20 20 2a 2a 20 54 4b 5f 52 45 47 49 53 54 45 ** TK_REGISTE
14e20 52 3a 20 72 65 67 69 73 74 65 72 20 6e 75 6d 62 R: register numb
14e30 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 er.
14e40 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 ** T
14e50 4b 5f 54 52 49 47 47 45 52 3a 20 31 20 2d 3e 20 K_TRIGGER: 1 ->
14e60 6e 65 77 2c 20 30 20 2d 3e 20 6f 6c 64 0a 20 20 new, 0 -> old.
14e70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14e80 20 20 20 20 20 20 20 2a 2a 20 45 50 5f 55 6e 6c ** EP_Unl
14e90 69 6b 65 6c 79 3a 20 20 31 33 34 32 31 37 37 32 ikely: 13421772
14ea0 38 20 74 69 6d 65 73 20 6c 69 6b 65 6c 69 68 6f 8 times likeliho
14eb0 6f 64 20 2a 2f 0a 20 20 79 6e 56 61 72 20 69 43 od */. ynVar iC
14ec0 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 2f olumn; /
14ed0 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 6f 6c * TK_COLUMN: col
14ee0 75 6d 6e 20 69 6e 64 65 78 2e 20 20 2d 31 20 66 umn index. -1 f
14ef0 6f 72 20 72 6f 77 69 64 2e 0a 20 20 20 20 20 20 or rowid..
14f00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14f10 20 20 20 2a 2a 20 54 4b 5f 56 41 52 49 41 42 4c ** TK_VARIABL
14f20 45 3a 20 76 61 72 69 61 62 6c 65 20 6e 75 6d 62 E: variable numb
14f30 65 72 20 28 61 6c 77 61 79 73 20 3e 3d 20 31 29 er (always >= 1)
14f40 2e 20 2a 2f 0a 20 20 69 31 36 20 69 41 67 67 3b . */. i16 iAgg;
14f50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
14f60 20 57 68 69 63 68 20 65 6e 74 72 79 20 69 6e 20 Which entry in
14f70 70 41 67 67 49 6e 66 6f 2d 3e 61 43 6f 6c 5b 5d pAggInfo->aCol[]
14f80 20 6f 72 20 2d 3e 61 46 75 6e 63 5b 5d 20 2a 2f or ->aFunc[] */
14f90 0a 20 20 69 31 36 20 69 52 69 67 68 74 4a 6f 69 . i16 iRightJoi
14fa0 6e 54 61 62 6c 65 3b 20 20 20 2f 2a 20 49 66 20 nTable; /* If
14fb0 45 50 5f 46 72 6f 6d 4a 6f 69 6e 2c 20 74 68 65 EP_FromJoin, the
14fc0 20 72 69 67 68 74 20 74 61 62 6c 65 20 6f 66 20 right table of
14fd0 74 68 65 20 6a 6f 69 6e 20 2a 2f 0a 20 20 75 38 the join */. u8
14fe0 20 6f 70 32 3b 20 20 20 20 20 20 20 20 20 20 20 op2;
14ff0 20 20 20 20 20 2f 2a 20 54 4b 5f 52 45 47 49 53 /* TK_REGIS
15000 54 45 52 3a 20 6f 72 69 67 69 6e 61 6c 20 76 61 TER: original va
15010 6c 75 65 20 6f 66 20 45 78 70 72 2e 6f 70 0a 20 lue of Expr.op.
15020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15030 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 43 4f ** TK_CO
15040 4c 55 4d 4e 3a 20 74 68 65 20 76 61 6c 75 65 20 LUMN: the value
15050 6f 66 20 70 35 20 66 6f 72 20 4f 50 5f 43 6f 6c of p5 for OP_Col
15060 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 umn.
15070 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
15080 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e 3a TK_AGG_FUNCTION:
15090 20 6e 65 73 74 69 6e 67 20 64 65 70 74 68 20 2a nesting depth *
150a0 2f 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 41 67 /. AggInfo *pAg
150b0 67 49 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 55 73 gInfo; /* Us
150c0 65 64 20 62 79 20 54 4b 5f 41 47 47 5f 43 4f 4c ed by TK_AGG_COL
150d0 55 4d 4e 20 61 6e 64 20 54 4b 5f 41 47 47 5f 46 UMN and TK_AGG_F
150e0 55 4e 43 54 49 4f 4e 20 2a 2f 0a 20 20 54 61 62 UNCTION */. Tab
150f0 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 le *pTab;
15100 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 66 6f 72 /* Table for
15110 20 54 4b 5f 43 4f 4c 55 4d 4e 20 65 78 70 72 65 TK_COLUMN expre
15120 73 73 69 6f 6e 73 2e 20 2a 2f 0a 7d 3b 0a 0a 2f ssions. */.};../
15130 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 *.** The followi
15140 6e 67 20 61 72 65 20 74 68 65 20 6d 65 61 6e 69 ng are the meani
15150 6e 67 73 20 6f 66 20 62 69 74 73 20 69 6e 20 74 ngs of bits in t
15160 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 66 69 he Expr.flags fi
15170 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 eld..*/.#define
15180 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 20 30 78 30 EP_FromJoin 0x0
15190 30 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 6e 61 00001 /* Origina
151a0 74 65 73 20 69 6e 20 4f 4e 2f 55 53 49 4e 47 20 tes in ON/USING
151b0 63 6c 61 75 73 65 20 6f 66 20 6f 75 74 65 72 20 clause of outer
151c0 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 join */.#define
151d0 45 50 5f 41 67 67 20 20 20 20 20 20 20 30 78 30 EP_Agg 0x0
151e0 30 30 30 30 32 20 2f 2a 20 43 6f 6e 74 61 69 6e 00002 /* Contain
151f0 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 61 67 s one or more ag
15200 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
15210 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f s */.#define EP_
15220 52 65 73 6f 6c 76 65 64 20 20 30 78 30 30 30 30 Resolved 0x0000
15230 30 34 20 2f 2a 20 49 44 73 20 68 61 76 65 20 62 04 /* IDs have b
15240 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 74 6f 20 een resolved to
15250 43 4f 4c 55 4d 4e 73 20 2a 2f 0a 23 64 65 66 69 COLUMNs */.#defi
15260 6e 65 20 45 50 5f 45 72 72 6f 72 20 20 20 20 20 ne EP_Error
15270 30 78 30 30 30 30 30 38 20 2f 2a 20 45 78 70 72 0x000008 /* Expr
15280 65 73 73 69 6f 6e 20 63 6f 6e 74 61 69 6e 73 20 ession contains
15290 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 65 72 72 6f one or more erro
152a0 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 rs */.#define EP
152b0 5f 44 69 73 74 69 6e 63 74 20 20 30 78 30 30 30 _Distinct 0x000
152c0 30 31 30 20 2f 2a 20 41 67 67 72 65 67 61 74 65 010 /* Aggregate
152d0 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 44 function with D
152e0 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 64 20 ISTINCT keyword
152f0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 56 61 */.#define EP_Va
15300 72 53 65 6c 65 63 74 20 30 78 30 30 30 30 32 30 rSelect 0x000020
15310 20 2f 2a 20 70 53 65 6c 65 63 74 20 69 73 20 63 /* pSelect is c
15320 6f 72 72 65 6c 61 74 65 64 2c 20 6e 6f 74 20 63 orrelated, not c
15330 6f 6e 73 74 61 6e 74 20 2a 2f 0a 23 64 65 66 69 onstant */.#defi
15340 6e 65 20 45 50 5f 44 62 6c 51 75 6f 74 65 64 20 ne EP_DblQuoted
15350 30 78 30 30 30 30 34 30 20 2f 2a 20 74 6f 6b 65 0x000040 /* toke
15360 6e 2e 7a 20 77 61 73 20 6f 72 69 67 69 6e 61 6c n.z was original
15370 6c 79 20 69 6e 20 22 2e 2e 2e 22 20 2a 2f 0a 23 ly in "..." */.#
15380 64 65 66 69 6e 65 20 45 50 5f 49 6e 66 69 78 46 define EP_InfixF
15390 75 6e 63 20 30 78 30 30 30 30 38 30 20 2f 2a 20 unc 0x000080 /*
153a0 54 72 75 65 20 66 6f 72 20 61 6e 20 69 6e 66 69 True for an infi
153b0 78 20 66 75 6e 63 74 69 6f 6e 3a 20 4c 49 4b 45 x function: LIKE
153c0 2c 20 47 4c 4f 42 2c 20 65 74 63 20 2a 2f 0a 23 , GLOB, etc */.#
153d0 64 65 66 69 6e 65 20 45 50 5f 43 6f 6c 6c 61 74 define EP_Collat
153e0 65 20 20 20 30 78 30 30 30 31 30 30 20 2f 2a 20 e 0x000100 /*
153f0 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 20 Tree contains a
15400 54 4b 5f 43 4f 4c 4c 41 54 45 20 6f 70 65 72 61 TK_COLLATE opera
15410 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 tor */.#define E
15420 50 5f 47 65 6e 65 72 69 63 20 20 20 30 78 30 30 P_Generic 0x00
15430 30 32 30 30 20 2f 2a 20 49 67 6e 6f 72 65 20 43 0200 /* Ignore C
15440 4f 4c 4c 41 54 45 20 6f 72 20 61 66 66 69 6e 69 OLLATE or affini
15450 74 79 20 6f 6e 20 74 68 69 73 20 74 72 65 65 20 ty on this tree
15460 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 6e */.#define EP_In
15470 74 56 61 6c 75 65 20 20 30 78 30 30 30 34 30 30 tValue 0x000400
15480 20 2f 2a 20 49 6e 74 65 67 65 72 20 76 61 6c 75 /* Integer valu
15490 65 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 75 e contained in u
154a0 2e 69 56 61 6c 75 65 20 2a 2f 0a 23 64 65 66 69 .iValue */.#defi
154b0 6e 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 ne EP_xIsSelect
154c0 30 78 30 30 30 38 30 30 20 2f 2a 20 78 2e 70 53 0x000800 /* x.pS
154d0 65 6c 65 63 74 20 69 73 20 76 61 6c 69 64 20 28 elect is valid (
154e0 6f 74 68 65 72 77 69 73 65 20 78 2e 70 4c 69 73 otherwise x.pLis
154f0 74 20 69 73 29 20 2a 2f 0a 23 64 65 66 69 6e 65 t is) */.#define
15500 20 45 50 5f 53 6b 69 70 20 20 20 20 20 20 30 78 EP_Skip 0x
15510 30 30 31 30 30 30 20 2f 2a 20 43 4f 4c 4c 41 54 001000 /* COLLAT
15520 45 2c 20 41 53 2c 20 6f 72 20 55 4e 4c 49 4b 45 E, AS, or UNLIKE
15530 4c 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 LY */.#define EP
15540 5f 52 65 64 75 63 65 64 20 20 20 30 78 30 30 32 _Reduced 0x002
15550 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 75 000 /* Expr stru
15560 63 74 20 45 58 50 52 5f 52 45 44 55 43 45 44 53 ct EXPR_REDUCEDS
15570 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a IZE bytes only *
15580 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 54 6f 6b /.#define EP_Tok
15590 65 6e 4f 6e 6c 79 20 30 78 30 30 34 30 30 30 20 enOnly 0x004000
155a0 2f 2a 20 45 78 70 72 20 73 74 72 75 63 74 20 45 /* Expr struct E
155b0 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 5a XPR_TOKENONLYSIZ
155c0 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a 2f 0a E bytes only */.
155d0 23 64 65 66 69 6e 65 20 45 50 5f 53 74 61 74 69 #define EP_Stati
155e0 63 20 20 20 20 30 78 30 30 38 30 30 30 20 2f 2a c 0x008000 /*
155f0 20 48 65 6c 64 20 69 6e 20 6d 65 6d 6f 72 79 20 Held in memory
15600 6e 6f 74 20 6f 62 74 61 69 6e 65 64 20 66 72 6f not obtained fro
15610 6d 20 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 23 64 m malloc() */.#d
15620 65 66 69 6e 65 20 45 50 5f 4d 65 6d 54 6f 6b 65 efine EP_MemToke
15630 6e 20 20 30 78 30 31 30 30 30 30 20 2f 2a 20 4e n 0x010000 /* N
15640 65 65 64 20 74 6f 20 73 71 6c 69 74 65 33 44 62 eed to sqlite3Db
15650 46 72 65 65 28 29 20 45 78 70 72 2e 7a 54 6f 6b Free() Expr.zTok
15660 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 en */.#define EP
15670 5f 4e 6f 52 65 64 75 63 65 20 20 30 78 30 32 30 _NoReduce 0x020
15680 30 30 30 20 2f 2a 20 43 61 6e 6e 6f 74 20 45 58 000 /* Cannot EX
15690 50 52 44 55 50 5f 52 45 44 55 43 45 20 74 68 69 PRDUP_REDUCE thi
156a0 73 20 45 78 70 72 20 2a 2f 0a 23 64 65 66 69 6e s Expr */.#defin
156b0 65 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 20 20 30 e EP_Unlikely 0
156c0 78 30 34 30 30 30 30 20 2f 2a 20 75 6e 6c 69 6b x040000 /* unlik
156d0 65 6c 79 28 29 20 6f 72 20 6c 69 6b 65 6c 69 68 ely() or likelih
156e0 6f 6f 64 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a ood() function *
156f0 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f 6e /.#define EP_Con
15700 73 74 46 75 6e 63 20 30 78 30 38 30 30 30 30 20 stFunc 0x080000
15710 2f 2a 20 4e 6f 64 65 20 69 73 20 61 20 53 51 4c /* Node is a SQL
15720 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e ITE_FUNC_CONSTAN
15730 54 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 T function */.#d
15740 65 66 69 6e 65 20 45 50 5f 43 61 6e 42 65 4e 75 efine EP_CanBeNu
15750 6c 6c 20 30 78 31 30 30 30 30 30 20 2f 2a 20 43 ll 0x100000 /* C
15760 61 6e 20 62 65 20 6e 75 6c 6c 20 64 65 73 70 69 an be null despi
15770 74 65 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e 73 te NOT NULL cons
15780 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e traint */.#defin
15790 65 20 45 50 5f 53 75 62 71 75 65 72 79 20 20 30 e EP_Subquery 0
157a0 78 32 30 30 30 30 30 20 2f 2a 20 54 72 65 65 20 x200000 /* Tree
157b0 63 6f 6e 74 61 69 6e 73 20 61 20 54 4b 5f 53 45 contains a TK_SE
157c0 4c 45 43 54 20 6f 70 65 72 61 74 6f 72 20 2a 2f LECT operator */
157d0 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6d 62 69 6e 61 74 ../*.** Combinat
157e0 69 6f 6e 73 20 6f 66 20 74 77 6f 20 6f 72 20 6d ions of two or m
157f0 6f 72 65 20 45 50 5f 2a 20 66 6c 61 67 73 0a 2a ore EP_* flags.*
15800 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 50 72 6f /.#define EP_Pro
15810 70 61 67 61 74 65 20 28 45 50 5f 43 6f 6c 6c 61 pagate (EP_Colla
15820 74 65 7c 45 50 5f 53 75 62 71 75 65 72 79 29 20 te|EP_Subquery)
15830 2f 2a 20 50 72 6f 70 61 67 61 74 65 20 74 68 65 /* Propagate the
15840 73 65 20 62 69 74 73 20 75 70 20 74 72 65 65 20 se bits up tree
15850 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 65 20 */../*.** These
15860 6d 61 63 72 6f 73 20 63 61 6e 20 62 65 20 75 73 macros can be us
15870 65 64 20 74 6f 20 74 65 73 74 2c 20 73 65 74 2c ed to test, set,
15880 20 6f 72 20 63 6c 65 61 72 20 62 69 74 73 20 69 or clear bits i
15890 6e 20 74 68 65 20 0a 2a 2a 20 45 78 70 72 2e 66 n the .** Expr.f
158a0 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 lags field..*/.#
158b0 64 65 66 69 6e 65 20 45 78 70 72 48 61 73 50 72 define ExprHasPr
158c0 6f 70 65 72 74 79 28 45 2c 50 29 20 20 20 20 20 operty(E,P)
158d0 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 50 29 (((E)->flags&(P)
158e0 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 45 78 )!=0).#define Ex
158f0 70 72 48 61 73 41 6c 6c 50 72 6f 70 65 72 74 79 prHasAllProperty
15900 28 45 2c 50 29 20 20 28 28 28 45 29 2d 3e 66 6c (E,P) (((E)->fl
15910 61 67 73 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 ags&(P))==(P)).#
15920 64 65 66 69 6e 65 20 45 78 70 72 53 65 74 50 72 define ExprSetPr
15930 6f 70 65 72 74 79 28 45 2c 50 29 20 20 20 20 20 operty(E,P)
15940 28 45 29 2d 3e 66 6c 61 67 73 7c 3d 28 50 29 0a (E)->flags|=(P).
15950 23 64 65 66 69 6e 65 20 45 78 70 72 43 6c 65 61 #define ExprClea
15960 72 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 rProperty(E,P)
15970 20 28 45 29 2d 3e 66 6c 61 67 73 26 3d 7e 28 50 (E)->flags&=~(P
15980 29 0a 0a 2f 2a 20 54 68 65 20 45 78 70 72 53 65 )../* The ExprSe
15990 74 56 56 41 50 72 6f 70 65 72 74 79 28 29 20 6d tVVAProperty() m
159a0 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 6f 72 acro is used for
159b0 20 56 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 56 Verification, V
159c0 61 6c 69 64 61 74 69 6f 6e 2c 0a 2a 2a 20 61 6e alidation,.** an
159d0 64 20 41 63 63 72 65 64 69 74 61 74 69 6f 6e 20 d Accreditation
159e0 6f 6e 6c 79 2e 20 20 49 74 20 77 6f 72 6b 73 20 only. It works
159f0 6c 69 6b 65 20 45 78 70 72 53 65 74 50 72 6f 70 like ExprSetProp
15a00 65 72 74 79 28 29 20 64 75 72 69 6e 67 20 56 56 erty() during VV
15a10 41 0a 2a 2a 20 70 72 6f 63 65 73 73 65 73 20 62 A.** processes b
15a20 75 74 20 69 73 20 61 20 6e 6f 2d 6f 70 20 66 6f ut is a no-op fo
15a30 72 20 64 65 6c 69 76 65 72 79 2e 0a 2a 2f 0a 23 r delivery..*/.#
15a40 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
15a50 55 47 0a 23 20 64 65 66 69 6e 65 20 45 78 70 72 UG.# define Expr
15a60 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 45 SetVVAProperty(E
15a70 2c 50 29 20 20 28 45 29 2d 3e 66 6c 61 67 73 7c ,P) (E)->flags|
15a80 3d 28 50 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 =(P).#else.# def
15a90 69 6e 65 20 45 78 70 72 53 65 74 56 56 41 50 72 ine ExprSetVVAPr
15aa0 6f 70 65 72 74 79 28 45 2c 50 29 0a 23 65 6e 64 operty(E,P).#end
15ab0 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 if../*.** Macros
15ac0 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 74 68 to determine th
15ad0 65 20 6e 75 6d 62 65 72 20 6f 66 20 62 79 74 65 e number of byte
15ae0 73 20 72 65 71 75 69 72 65 64 20 62 79 20 61 20 s required by a
15af0 6e 6f 72 6d 61 6c 20 45 78 70 72 20 0a 2a 2a 20 normal Expr .**
15b00 73 74 72 75 63 74 2c 20 61 6e 20 45 78 70 72 20 struct, an Expr
15b10 73 74 72 75 63 74 20 77 69 74 68 20 74 68 65 20 struct with the
15b20 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 67 20 EP_Reduced flag
15b30 73 65 74 20 69 6e 20 45 78 70 72 2e 66 6c 61 67 set in Expr.flag
15b40 73 20 0a 2a 2a 20 61 6e 64 20 61 6e 20 45 78 70 s .** and an Exp
15b50 72 20 73 74 72 75 63 74 20 77 69 74 68 20 74 68 r struct with th
15b60 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 66 e EP_TokenOnly f
15b70 6c 61 67 20 73 65 74 2e 0a 2a 2f 0a 23 64 65 66 lag set..*/.#def
15b80 69 6e 65 20 45 58 50 52 5f 46 55 4c 4c 53 49 5a ine EXPR_FULLSIZ
15b90 45 20 20 20 20 20 20 20 20 20 20 20 73 69 7a 65 E size
15ba0 6f 66 28 45 78 70 72 29 20 20 20 20 20 20 20 20 of(Expr)
15bb0 20 20 20 2f 2a 20 46 75 6c 6c 20 73 69 7a 65 20 /* Full size
15bc0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 5f */.#define EXPR_
15bd0 52 45 44 55 43 45 44 53 49 5a 45 20 20 20 20 20 REDUCEDSIZE
15be0 20 20 20 6f 66 66 73 65 74 6f 66 28 45 78 70 72 offsetof(Expr
15bf0 2c 69 54 61 62 6c 65 29 20 20 2f 2a 20 43 6f 6d ,iTable) /* Com
15c00 6d 6f 6e 20 66 65 61 74 75 72 65 73 20 2a 2f 0a mon features */.
15c10 23 64 65 66 69 6e 65 20 45 58 50 52 5f 54 4f 4b #define EXPR_TOK
15c20 45 4e 4f 4e 4c 59 53 49 5a 45 20 20 20 20 20 20 ENONLYSIZE
15c30 6f 66 66 73 65 74 6f 66 28 45 78 70 72 2c 70 4c offsetof(Expr,pL
15c40 65 66 74 29 20 20 20 2f 2a 20 46 65 77 65 72 20 eft) /* Fewer
15c50 66 65 61 74 75 72 65 73 20 2a 2f 0a 0a 2f 2a 0a features */../*.
15c60 2a 2a 20 46 6c 61 67 73 20 70 61 73 73 65 64 20 ** Flags passed
15c70 74 6f 20 74 68 65 20 73 71 6c 69 74 65 33 45 78 to the sqlite3Ex
15c80 70 72 44 75 70 28 29 20 66 75 6e 63 74 69 6f 6e prDup() function
15c90 2e 20 53 65 65 20 74 68 65 20 68 65 61 64 65 72 . See the header
15ca0 20 63 6f 6d 6d 65 6e 74 20 0a 2a 2a 20 61 62 6f comment .** abo
15cb0 76 65 20 73 71 6c 69 74 65 33 45 78 70 72 44 75 ve sqlite3ExprDu
15cc0 70 28 29 20 66 6f 72 20 64 65 74 61 69 6c 73 2e p() for details.
15cd0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 .*/.#define EXPR
15ce0 44 55 50 5f 52 45 44 55 43 45 20 20 20 20 20 20 DUP_REDUCE
15cf0 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 55 73 0x0001 /* Us
15d00 65 64 20 72 65 64 75 63 65 64 2d 73 69 7a 65 20 ed reduced-size
15d10 45 78 70 72 20 6e 6f 64 65 73 20 2a 2f 0a 0a 2f Expr nodes */../
15d20 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 6f 66 20 65 *.** A list of e
15d30 78 70 72 65 73 73 69 6f 6e 73 2e 20 20 45 61 63 xpressions. Eac
15d40 68 20 65 78 70 72 65 73 73 69 6f 6e 20 6d 61 79 h expression may
15d50 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 68 61 76 65 optionally have
15d60 20 61 0a 2a 2a 20 6e 61 6d 65 2e 20 20 41 6e 20 a.** name. An
15d70 65 78 70 72 2f 6e 61 6d 65 20 63 6f 6d 62 69 6e expr/name combin
15d80 61 74 69 6f 6e 20 63 61 6e 20 62 65 20 75 73 65 ation can be use
15d90 64 20 69 6e 20 73 65 76 65 72 61 6c 20 77 61 79 d in several way
15da0 73 2c 20 73 75 63 68 0a 2a 2a 20 61 73 20 74 68 s, such.** as th
15db0 65 20 6c 69 73 74 20 6f 66 20 22 65 78 70 72 20 e list of "expr
15dc0 41 53 20 49 44 22 20 66 69 65 6c 64 73 20 66 6f AS ID" fields fo
15dd0 6c 6c 6f 77 69 6e 67 20 61 20 22 53 45 4c 45 43 llowing a "SELEC
15de0 54 22 20 6f 72 20 69 6e 20 74 68 65 0a 2a 2a 20 T" or in the.**
15df0 6c 69 73 74 20 6f 66 20 22 49 44 20 3d 20 65 78 list of "ID = ex
15e00 70 72 22 20 69 74 65 6d 73 20 69 6e 20 61 6e 20 pr" items in an
15e10 55 50 44 41 54 45 2e 20 20 41 20 6c 69 73 74 20 UPDATE. A list
15e20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 63 of expressions c
15e30 61 6e 0a 2a 2a 20 61 6c 73 6f 20 62 65 20 75 73 an.** also be us
15e40 65 64 20 61 73 20 74 68 65 20 61 72 67 75 6d 65 ed as the argume
15e50 6e 74 20 74 6f 20 61 20 66 75 6e 63 74 69 6f 6e nt to a function
15e60 2c 20 69 6e 20 77 68 69 63 68 20 63 61 73 65 20 , in which case
15e70 74 68 65 20 61 2e 7a 4e 61 6d 65 0a 2a 2a 20 66 the a.zName.** f
15e80 69 65 6c 64 20 69 73 20 6e 6f 74 20 75 73 65 64 ield is not used
15e90 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 65 66 61 75 ..**.** By defau
15ea0 6c 74 20 74 68 65 20 45 78 70 72 2e 7a 53 70 61 lt the Expr.zSpa
15eb0 6e 20 66 69 65 6c 64 20 68 6f 6c 64 73 20 61 20 n field holds a
15ec0 68 75 6d 61 6e 2d 72 65 61 64 61 62 6c 65 20 64 human-readable d
15ed0 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 0a 2a 2a escription of.**
15ee0 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 the expression
15ef0 74 68 61 74 20 69 73 20 75 73 65 64 20 69 6e 20 that is used in
15f00 74 68 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 6f the generation o
15f10 66 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 f error messages
15f20 20 61 6e 64 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 6c and.** column l
15f30 61 62 65 6c 73 2e 20 20 49 6e 20 74 68 69 73 20 abels. In this
15f40 63 61 73 65 2c 20 45 78 70 72 2e 7a 53 70 61 6e case, Expr.zSpan
15f50 20 69 73 20 74 79 70 69 63 61 6c 6c 79 20 74 68 is typically th
15f60 65 20 74 65 78 74 20 6f 66 20 61 0a 2a 2a 20 63 e text of a.** c
15f70 6f 6c 75 6d 6e 20 65 78 70 72 65 73 73 69 6f 6e olumn expression
15f80 20 61 73 20 69 74 20 65 78 69 73 74 73 20 69 6e as it exists in
15f90 20 61 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d a SELECT statem
15fa0 65 6e 74 2e 20 20 48 6f 77 65 76 65 72 2c 20 69 ent. However, i
15fb0 66 0a 2a 2a 20 74 68 65 20 62 53 70 61 6e 49 73 f.** the bSpanIs
15fc0 54 61 62 20 66 6c 61 67 20 69 73 20 73 65 74 2c Tab flag is set,
15fd0 20 74 68 65 6e 20 7a 53 70 61 6e 20 69 73 20 6f then zSpan is o
15fe0 76 65 72 6c 6f 61 64 65 64 20 74 6f 20 6d 65 61 verloaded to mea
15ff0 6e 20 74 68 65 20 6e 61 6d 65 0a 2a 2a 20 6f 66 n the name.** of
16000 20 74 68 65 20 72 65 73 75 6c 74 20 63 6f 6c 75 the result colu
16010 6d 6e 20 69 6e 20 74 68 65 20 66 6f 72 6d 3a 20 mn in the form:
16020 44 41 54 41 42 41 53 45 2e 54 41 42 4c 45 2e 43 DATABASE.TABLE.C
16030 4f 4c 55 4d 4e 2e 20 20 54 68 69 73 20 6c 61 74 OLUMN. This lat
16040 65 72 0a 2a 2a 20 66 6f 72 6d 20 69 73 20 75 73 er.** form is us
16050 65 64 20 66 6f 72 20 6e 61 6d 65 20 72 65 73 6f ed for name reso
16060 6c 75 74 69 6f 6e 20 77 69 74 68 20 6e 65 73 74 lution with nest
16070 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 73 2e ed FROM clauses.
16080 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 70 72 4c .*/.struct ExprL
16090 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 45 78 70 ist {. int nExp
160a0 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f r; /
160b0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 78 70 72 * Number of expr
160c0 65 73 73 69 6f 6e 73 20 6f 6e 20 74 68 65 20 6c essions on the l
160d0 69 73 74 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 ist */. struct
160e0 45 78 70 72 4c 69 73 74 5f 69 74 65 6d 20 7b 20 ExprList_item {
160f0 2f 2a 20 46 6f 72 20 65 61 63 68 20 65 78 70 72 /* For each expr
16100 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 20 6c 69 ession in the li
16110 73 74 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a st */. Expr *
16120 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 pExpr;
16130 20 20 2f 2a 20 54 68 65 20 6c 69 73 74 20 6f 66 /* The list of
16140 20 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a expressions */.
16150 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b char *zName;
16160 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
16170 6f 6b 65 6e 20 61 73 73 6f 63 69 61 74 65 64 20 oken associated
16180 77 69 74 68 20 74 68 69 73 20 65 78 70 72 65 73 with this expres
16190 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 63 68 61 72 sion */. char
161a0 20 2a 7a 53 70 61 6e 3b 20 20 20 20 20 20 20 20 *zSpan;
161b0 20 20 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 /* Original
161c0 74 65 78 74 20 6f 66 20 74 68 65 20 65 78 70 72 text of the expr
161d0 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 75 38 ession */. u8
161e0 20 73 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 sortOrder;
161f0 20 20 20 20 20 20 2f 2a 20 31 20 66 6f 72 20 44 /* 1 for D
16200 45 53 43 20 6f 72 20 30 20 66 6f 72 20 41 53 43 ESC or 0 for ASC
16210 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
16220 20 64 6f 6e 65 20 3a 31 3b 20 20 20 20 20 20 20 done :1;
16230 2f 2a 20 41 20 66 6c 61 67 20 74 6f 20 69 6e 64 /* A flag to ind
16240 69 63 61 74 65 20 77 68 65 6e 20 70 72 6f 63 65 icate when proce
16250 73 73 69 6e 67 20 69 73 20 66 69 6e 69 73 68 65 ssing is finishe
16260 64 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 d */. unsigne
16270 64 20 62 53 70 61 6e 49 73 54 61 62 20 3a 31 3b d bSpanIsTab :1;
16280 20 2f 2a 20 7a 53 70 61 6e 20 68 6f 6c 64 73 20 /* zSpan holds
16290 44 42 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 20 DB.TABLE.COLUMN
162a0 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 */. unsigned
162b0 72 65 75 73 61 62 6c 65 20 3a 31 3b 20 20 20 2f reusable :1; /
162c0 2a 20 43 6f 6e 73 74 61 6e 74 20 65 78 70 72 65 * Constant expre
162d0 73 73 69 6f 6e 20 69 73 20 72 65 75 73 61 62 6c ssion is reusabl
162e0 65 20 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b e */. union {
162f0 0a 20 20 20 20 20 20 73 74 72 75 63 74 20 7b 0a . struct {.
16300 20 20 20 20 20 20 20 20 75 31 36 20 69 4f 72 64 u16 iOrd
16310 65 72 42 79 43 6f 6c 3b 20 20 20 20 20 20 2f 2a erByCol; /*
16320 20 46 6f 72 20 4f 52 44 45 52 20 42 59 2c 20 63 For ORDER BY, c
16330 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e 20 olumn number in
16340 72 65 73 75 6c 74 20 73 65 74 20 2a 2f 0a 20 20 result set */.
16350 20 20 20 20 20 20 75 31 36 20 69 41 6c 69 61 73 u16 iAlias
16360 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 ; /* I
16370 6e 64 65 78 20 69 6e 74 6f 20 50 61 72 73 65 2e ndex into Parse.
16380 61 41 6c 69 61 73 5b 5d 20 66 6f 72 20 7a 4e 61 aAlias[] for zNa
16390 6d 65 20 2a 2f 0a 20 20 20 20 20 20 7d 20 78 3b me */. } x;
163a0 0a 20 20 20 20 20 20 69 6e 74 20 69 43 6f 6e 73 . int iCons
163b0 74 45 78 70 72 52 65 67 3b 20 20 20 20 20 20 2f tExprReg; /
163c0 2a 20 52 65 67 69 73 74 65 72 20 69 6e 20 77 68 * Register in wh
163d0 69 63 68 20 45 78 70 72 20 76 61 6c 75 65 20 69 ich Expr value i
163e0 73 20 63 61 63 68 65 64 20 2a 2f 0a 20 20 20 20 s cached */.
163f0 7d 20 75 3b 0a 20 20 7d 20 2a 61 3b 20 20 20 20 } u;. } *a;
16400 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
16410 20 41 6c 6c 6f 63 20 61 20 70 6f 77 65 72 20 6f Alloc a power o
16420 66 20 74 77 6f 20 67 72 65 61 74 65 72 20 6f 72 f two greater or
16430 20 65 71 75 61 6c 20 74 6f 20 6e 45 78 70 72 20 equal to nExpr
16440 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 */.};../*.** An
16450 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 instance of this
16460 20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 73 structure is us
16470 65 64 20 62 79 20 74 68 65 20 70 61 72 73 65 72 ed by the parser
16480 20 74 6f 20 72 65 63 6f 72 64 20 62 6f 74 68 0a to record both.
16490 2a 2a 20 74 68 65 20 70 61 72 73 65 20 74 72 65 ** the parse tre
164a0 65 20 66 6f 72 20 61 6e 20 65 78 70 72 65 73 73 e for an express
164b0 69 6f 6e 20 61 6e 64 20 74 68 65 20 73 70 61 6e ion and the span
164c0 20 6f 66 20 69 6e 70 75 74 20 74 65 78 74 20 66 of input text f
164d0 6f 72 20 61 6e 0a 2a 2a 20 65 78 70 72 65 73 73 or an.** express
164e0 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 45 ion..*/.struct E
164f0 78 70 72 53 70 61 6e 20 7b 0a 20 20 45 78 70 72 xprSpan {. Expr
16500 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 *pExpr;
16510 20 20 2f 2a 20 54 68 65 20 65 78 70 72 65 73 73 /* The express
16520 69 6f 6e 20 70 61 72 73 65 20 74 72 65 65 20 2a ion parse tree *
16530 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a /. const char *
16540 7a 53 74 61 72 74 3b 20 20 20 2f 2a 20 46 69 72 zStart; /* Fir
16550 73 74 20 63 68 61 72 61 63 74 65 72 20 6f 66 20 st character of
16560 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 20 input text */.
16570 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 45 6e 64 const char *zEnd
16580 3b 20 20 20 20 20 2f 2a 20 4f 6e 65 20 63 68 61 ; /* One cha
16590 72 61 63 74 65 72 20 70 61 73 74 20 74 68 65 20 racter past the
165a0 65 6e 64 20 6f 66 20 69 6e 70 75 74 20 74 65 78 end of input tex
165b0 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 t */.};../*.** A
165c0 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
165d0 69 73 20 73 74 72 75 63 74 75 72 65 20 63 61 6e is structure can
165e0 20 68 6f 6c 64 20 61 20 73 69 6d 70 6c 65 20 6c hold a simple l
165f0 69 73 74 20 6f 66 20 69 64 65 6e 74 69 66 69 65 ist of identifie
16600 72 73 2c 0a 2a 2a 20 73 75 63 68 20 61 73 20 74 rs,.** such as t
16610 68 65 20 6c 69 73 74 20 22 61 2c 62 2c 63 22 20 he list "a,b,c"
16620 69 6e 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 in the following
16630 20 73 74 61 74 65 6d 65 6e 74 73 3a 0a 2a 2a 0a statements:.**.
16640 2a 2a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 ** INSERT I
16650 4e 54 4f 20 74 28 61 2c 62 2c 63 29 20 56 41 4c NTO t(a,b,c) VAL
16660 55 45 53 20 2e 2e 2e 3b 0a 2a 2a 20 20 20 20 20 UES ...;.**
16670 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 69 64 CREATE INDEX id
16680 78 20 4f 4e 20 74 28 61 2c 62 2c 63 29 3b 0a 2a x ON t(a,b,c);.*
16690 2a 20 20 20 20 20 20 43 52 45 41 54 45 20 54 52 * CREATE TR
166a0 49 47 47 45 52 20 74 72 69 67 20 42 45 46 4f 52 IGGER trig BEFOR
166b0 45 20 55 50 44 41 54 45 20 4f 4e 20 74 28 61 2c E UPDATE ON t(a,
166c0 62 2c 63 29 20 2e 2e 2e 3b 0a 2a 2a 0a 2a 2a 20 b,c) ...;.**.**
166d0 54 68 65 20 49 64 4c 69 73 74 2e 61 2e 69 64 78 The IdList.a.idx
166e0 20 66 69 65 6c 64 20 69 73 20 75 73 65 64 20 77 field is used w
166f0 68 65 6e 20 74 68 65 20 49 64 4c 69 73 74 20 72 hen the IdList r
16700 65 70 72 65 73 65 6e 74 73 20 74 68 65 20 6c 69 epresents the li
16710 73 74 20 6f 66 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 st of.** column
16720 6e 61 6d 65 73 20 61 66 74 65 72 20 61 20 74 61 names after a ta
16730 62 6c 65 20 6e 61 6d 65 20 69 6e 20 61 6e 20 49 ble name in an I
16740 4e 53 45 52 54 20 73 74 61 74 65 6d 65 6e 74 2e NSERT statement.
16750 20 20 49 6e 20 74 68 65 20 73 74 61 74 65 6d 65 In the stateme
16760 6e 74 0a 2a 2a 0a 2a 2a 20 20 20 20 20 49 4e 53 nt.**.** INS
16770 45 52 54 20 49 4e 54 4f 20 74 28 61 2c 62 2c 63 ERT INTO t(a,b,c
16780 29 20 2e 2e 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 22 ) ....**.** If "
16790 61 22 20 69 73 20 74 68 65 20 6b 2d 74 68 20 63 a" is the k-th c
167a0 6f 6c 75 6d 6e 20 6f 66 20 74 61 62 6c 65 20 22 olumn of table "
167b0 74 22 2c 20 74 68 65 6e 20 49 64 4c 69 73 74 2e t", then IdList.
167c0 61 5b 30 5d 2e 69 64 78 3d 3d 6b 2e 0a 2a 2f 0a a[0].idx==k..*/.
167d0 73 74 72 75 63 74 20 49 64 4c 69 73 74 20 7b 0a struct IdList {.
167e0 20 20 73 74 72 75 63 74 20 49 64 4c 69 73 74 5f struct IdList_
167f0 69 74 65 6d 20 7b 0a 20 20 20 20 63 68 61 72 20 item {. char
16800 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a 20 *zName; /*
16810 4e 61 6d 65 20 6f 66 20 74 68 65 20 69 64 65 6e Name of the iden
16820 74 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 69 6e tifier */. in
16830 74 20 69 64 78 3b 20 20 20 20 20 20 20 20 20 20 t idx;
16840 2f 2a 20 49 6e 64 65 78 20 69 6e 20 73 6f 6d 65 /* Index in some
16850 20 54 61 62 6c 65 2e 61 43 6f 6c 5b 5d 20 6f 66 Table.aCol[] of
16860 20 61 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 64 20 a column named
16870 7a 4e 61 6d 65 20 2a 2f 0a 20 20 7d 20 2a 61 3b zName */. } *a;
16880 0a 20 20 69 6e 74 20 6e 49 64 3b 20 20 20 20 20 . int nId;
16890 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
168a0 20 69 64 65 6e 74 69 66 69 65 72 73 20 6f 6e 20 identifiers on
168b0 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a the list */.};..
168c0 2f 2a 0a 2a 2a 20 54 68 65 20 62 69 74 6d 61 73 /*.** The bitmas
168d0 6b 20 64 61 74 61 74 79 70 65 20 64 65 66 69 6e k datatype defin
168e0 65 64 20 62 65 6c 6f 77 20 69 73 20 75 73 65 64 ed below is used
168f0 20 66 6f 72 20 76 61 72 69 6f 75 73 20 6f 70 74 for various opt
16900 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a imizations..**.*
16910 2a 20 43 68 61 6e 67 69 6e 67 20 74 68 69 73 20 * Changing this
16920 66 72 6f 6d 20 61 20 36 34 2d 62 69 74 20 74 6f from a 64-bit to
16930 20 61 20 33 32 2d 62 69 74 20 74 79 70 65 20 6c a 32-bit type l
16940 69 6d 69 74 73 20 74 68 65 20 6e 75 6d 62 65 72 imits the number
16950 20 6f 66 0a 2a 2a 20 74 61 62 6c 65 73 20 69 6e of.** tables in
16960 20 61 20 6a 6f 69 6e 20 74 6f 20 33 32 20 69 6e a join to 32 in
16970 73 74 65 61 64 20 6f 66 20 36 34 2e 20 20 42 75 stead of 64. Bu
16980 74 20 69 74 20 61 6c 73 6f 20 72 65 64 75 63 65 t it also reduce
16990 73 20 74 68 65 20 73 69 7a 65 0a 2a 2a 20 6f 66 s the size.** of
169a0 20 74 68 65 20 6c 69 62 72 61 72 79 20 62 79 20 the library by
169b0 37 33 38 20 62 79 74 65 73 20 6f 6e 20 69 78 38 738 bytes on ix8
169c0 36 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 75 36 6..*/.typedef u6
169d0 34 20 42 69 74 6d 61 73 6b 3b 0a 0a 2f 2a 0a 2a 4 Bitmask;../*.*
169e0 2a 20 54 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 * The number of
169f0 62 69 74 73 20 69 6e 20 61 20 42 69 74 6d 61 73 bits in a Bitmas
16a00 6b 2e 20 20 22 42 4d 53 22 20 6d 65 61 6e 73 20 k. "BMS" means
16a10 22 42 69 74 4d 61 73 6b 20 53 69 7a 65 22 2e 0a "BitMask Size"..
16a20 2a 2f 0a 23 64 65 66 69 6e 65 20 42 4d 53 20 20 */.#define BMS
16a30 28 28 69 6e 74 29 28 73 69 7a 65 6f 66 28 42 69 ((int)(sizeof(Bi
16a40 74 6d 61 73 6b 29 2a 38 29 29 0a 0a 2f 2a 0a 2a tmask)*8))../*.*
16a50 2a 20 41 20 62 69 74 20 69 6e 20 61 20 42 69 74 * A bit in a Bit
16a60 6d 61 73 6b 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 mask.*/.#define
16a70 4d 41 53 4b 42 49 54 28 6e 29 20 20 20 28 28 28 MASKBIT(n) (((
16a80 42 69 74 6d 61 73 6b 29 31 29 3c 3c 28 6e 29 29 Bitmask)1)<<(n))
16a90 0a 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 54 .#define MASKBIT
16aa0 33 32 28 6e 29 20 28 28 28 75 6e 73 69 67 6e 65 32(n) (((unsigne
16ab0 64 20 69 6e 74 29 31 29 3c 3c 28 6e 29 29 0a 0a d int)1)<<(n))..
16ac0 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
16ad0 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 64 65 ing structure de
16ae0 73 63 72 69 62 65 73 20 74 68 65 20 46 52 4f 4d scribes the FROM
16af0 20 63 6c 61 75 73 65 20 6f 66 20 61 20 53 45 4c clause of a SEL
16b00 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a ECT statement..*
16b10 2a 20 45 61 63 68 20 74 61 62 6c 65 20 6f 72 20 * Each table or
16b20 73 75 62 71 75 65 72 79 20 69 6e 20 74 68 65 20 subquery in the
16b30 46 52 4f 4d 20 63 6c 61 75 73 65 20 69 73 20 61 FROM clause is a
16b40 20 73 65 70 61 72 61 74 65 20 65 6c 65 6d 65 6e separate elemen
16b50 74 20 6f 66 0a 2a 2a 20 74 68 65 20 53 72 63 4c t of.** the SrcL
16b60 69 73 74 2e 61 5b 5d 20 61 72 72 61 79 2e 0a 2a ist.a[] array..*
16b70 2a 0a 2a 2a 20 57 69 74 68 20 74 68 65 20 61 64 *.** With the ad
16b80 64 69 74 69 6f 6e 20 6f 66 20 6d 75 6c 74 69 70 dition of multip
16b90 6c 65 20 64 61 74 61 62 61 73 65 20 73 75 70 70 le database supp
16ba0 6f 72 74 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 ort, the followi
16bb0 6e 67 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 ng structure.**
16bc0 63 61 6e 20 61 6c 73 6f 20 62 65 20 75 73 65 64 can also be used
16bd0 20 74 6f 20 64 65 73 63 72 69 62 65 20 61 20 70 to describe a p
16be0 61 72 74 69 63 75 6c 61 72 20 74 61 62 6c 65 20 articular table
16bf0 73 75 63 68 20 61 73 20 74 68 65 20 74 61 62 6c such as the tabl
16c00 65 20 74 68 61 74 0a 2a 2a 20 69 73 20 6d 6f 64 e that.** is mod
16c10 69 66 69 65 64 20 62 79 20 61 6e 20 49 4e 53 45 ified by an INSE
16c20 52 54 2c 20 44 45 4c 45 54 45 2c 20 6f 72 20 55 RT, DELETE, or U
16c30 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e 74 2e PDATE statement.
16c40 20 20 49 6e 20 73 74 61 6e 64 61 72 64 20 53 51 In standard SQ
16c50 4c 2c 0a 2a 2a 20 73 75 63 68 20 61 20 74 61 62 L,.** such a tab
16c60 6c 65 20 6d 75 73 74 20 62 65 20 61 20 73 69 6d le must be a sim
16c70 70 6c 65 20 6e 61 6d 65 3a 20 49 44 2e 20 20 42 ple name: ID. B
16c80 75 74 20 69 6e 20 53 51 4c 69 74 65 2c 20 74 68 ut in SQLite, th
16c90 65 20 74 61 62 6c 65 20 63 61 6e 0a 2a 2a 20 6e e table can.** n
16ca0 6f 77 20 62 65 20 69 64 65 6e 74 69 66 69 65 64 ow be identified
16cb0 20 62 79 20 61 20 64 61 74 61 62 61 73 65 20 6e by a database n
16cc0 61 6d 65 2c 20 61 20 64 6f 74 2c 20 74 68 65 6e ame, a dot, then
16cd0 20 74 68 65 20 74 61 62 6c 65 20 6e 61 6d 65 3a the table name:
16ce0 20 49 44 2e 49 44 2e 0a 2a 2a 0a 2a 2a 20 54 68 ID.ID..**.** Th
16cf0 65 20 6a 6f 69 6e 74 79 70 65 20 73 74 61 72 74 e jointype start
16d00 73 20 6f 75 74 20 73 68 6f 77 69 6e 67 20 74 68 s out showing th
16d10 65 20 6a 6f 69 6e 20 74 79 70 65 20 62 65 74 77 e join type betw
16d20 65 65 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 een the current
16d30 74 61 62 6c 65 0a 2a 2a 20 61 6e 64 20 74 68 65 table.** and the
16d40 20 6e 65 78 74 20 74 61 62 6c 65 20 6f 6e 20 74 next table on t
16d50 68 65 20 6c 69 73 74 2e 20 20 54 68 65 20 70 61 he list. The pa
16d60 72 73 65 72 20 62 75 69 6c 64 73 20 74 68 65 20 rser builds the
16d70 6c 69 73 74 20 74 68 69 73 20 77 61 79 2e 0a 2a list this way..*
16d80 2a 20 42 75 74 20 73 71 6c 69 74 65 33 53 72 63 * But sqlite3Src
16d90 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 70 ListShiftJoinTyp
16da0 65 28 29 20 6c 61 74 65 72 20 73 68 69 66 74 73 e() later shifts
16db0 20 74 68 65 20 6a 6f 69 6e 74 79 70 65 73 20 73 the jointypes s
16dc0 6f 20 74 68 61 74 20 65 61 63 68 0a 2a 2a 20 6a o that each.** j
16dd0 6f 69 6e 74 79 70 65 20 65 78 70 72 65 73 73 65 ointype expresse
16de0 73 20 74 68 65 20 6a 6f 69 6e 20 62 65 74 77 65 s the join betwe
16df0 65 6e 20 74 68 65 20 74 61 62 6c 65 20 61 6e 64 en the table and
16e00 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 74 61 the previous ta
16e10 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 ble..**.** In th
16e20 65 20 63 6f 6c 55 73 65 64 20 66 69 65 6c 64 2c e colUsed field,
16e30 20 74 68 65 20 68 69 67 68 2d 6f 72 64 65 72 20 the high-order
16e40 62 69 74 20 28 62 69 74 20 36 33 29 20 69 73 20 bit (bit 63) is
16e50 73 65 74 20 69 66 20 74 68 65 20 74 61 62 6c 65 set if the table
16e60 0a 2a 2a 20 63 6f 6e 74 61 69 6e 73 20 6d 6f 72 .** contains mor
16e70 65 20 74 68 61 6e 20 36 33 20 63 6f 6c 75 6d 6e e than 63 column
16e80 73 20 61 6e 64 20 74 68 65 20 36 34 2d 74 68 20 s and the 64-th
16e90 6f 72 20 6c 61 74 65 72 20 63 6f 6c 75 6d 6e 20 or later column
16ea0 69 73 20 75 73 65 64 2e 0a 2a 2f 0a 73 74 72 75 is used..*/.stru
16eb0 63 74 20 53 72 63 4c 69 73 74 20 7b 0a 20 20 69 ct SrcList {. i
16ec0 6e 74 20 6e 53 72 63 3b 20 20 20 20 20 20 20 20 nt nSrc;
16ed0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 74 61 62 /* Number of tab
16ee0 6c 65 73 20 6f 72 20 73 75 62 71 75 65 72 69 65 les or subquerie
16ef0 73 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c s in the FROM cl
16f00 61 75 73 65 20 2a 2f 0a 20 20 75 33 32 20 6e 41 ause */. u32 nA
16f10 6c 6c 6f 63 3b 20 20 20 20 20 20 2f 2a 20 4e 75 lloc; /* Nu
16f20 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 mber of entries
16f30 61 6c 6c 6f 63 61 74 65 64 20 69 6e 20 61 5b 5d allocated in a[]
16f40 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 73 74 72 75 below */. stru
16f50 63 74 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 ct SrcList_item
16f60 7b 0a 20 20 20 20 53 63 68 65 6d 61 20 2a 70 53 {. Schema *pS
16f70 63 68 65 6d 61 3b 20 20 2f 2a 20 53 63 68 65 6d chema; /* Schem
16f80 61 20 74 6f 20 77 68 69 63 68 20 74 68 69 73 20 a to which this
16f90 69 74 65 6d 20 69 73 20 66 69 78 65 64 20 2a 2f item is fixed */
16fa0 0a 20 20 20 20 63 68 61 72 20 2a 7a 44 61 74 61 . char *zData
16fb0 62 61 73 65 3b 20 20 2f 2a 20 4e 61 6d 65 20 6f base; /* Name o
16fc0 66 20 64 61 74 61 62 61 73 65 20 68 6f 6c 64 69 f database holdi
16fd0 6e 67 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f ng this table */
16fe0 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 . char *zName
16ff0 3b 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f ; /* Name o
17000 66 20 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 20 f the table */.
17010 20 20 20 63 68 61 72 20 2a 7a 41 6c 69 61 73 3b char *zAlias;
17020 20 20 20 20 20 2f 2a 20 54 68 65 20 22 42 22 20 /* The "B"
17030 70 61 72 74 20 6f 66 20 61 20 22 41 20 41 53 20 part of a "A AS
17040 42 22 20 70 68 72 61 73 65 2e 20 20 7a 4e 61 6d B" phrase. zNam
17050 65 20 69 73 20 74 68 65 20 22 41 22 20 2a 2f 0a e is the "A" */.
17060 20 20 20 20 54 61 62 6c 65 20 2a 70 54 61 62 3b Table *pTab;
17070 20 20 20 20 20 20 2f 2a 20 41 6e 20 53 51 4c 20 /* An SQL
17080 74 61 62 6c 65 20 63 6f 72 72 65 73 70 6f 6e 64 table correspond
17090 69 6e 67 20 74 6f 20 7a 4e 61 6d 65 20 2a 2f 0a ing to zName */.
170a0 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c Select *pSel
170b0 65 63 74 3b 20 20 2f 2a 20 41 20 53 45 4c 45 43 ect; /* A SELEC
170c0 54 20 73 74 61 74 65 6d 65 6e 74 20 75 73 65 64 T statement used
170d0 20 69 6e 20 70 6c 61 63 65 20 6f 66 20 61 20 74 in place of a t
170e0 61 62 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 20 able name */.
170f0 20 69 6e 74 20 61 64 64 72 46 69 6c 6c 53 75 62 int addrFillSub
17100 3b 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f 66 ; /* Address of
17110 20 73 75 62 72 6f 75 74 69 6e 65 20 74 6f 20 6d subroutine to m
17120 61 6e 69 66 65 73 74 20 61 20 73 75 62 71 75 65 anifest a subque
17130 72 79 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 65 ry */. int re
17140 67 52 65 74 75 72 6e 3b 20 20 20 20 2f 2a 20 52 gReturn; /* R
17150 65 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 egister holding
17160 72 65 74 75 72 6e 20 61 64 64 72 65 73 73 20 6f return address o
17170 66 20 61 64 64 72 46 69 6c 6c 53 75 62 20 2a 2f f addrFillSub */
17180 0a 20 20 20 20 69 6e 74 20 72 65 67 52 65 73 75 . int regResu
17190 6c 74 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 74 lt; /* Regist
171a0 65 72 73 20 68 6f 6c 64 69 6e 67 20 72 65 73 75 ers holding resu
171b0 6c 74 73 20 6f 66 20 61 20 63 6f 2d 72 6f 75 74 lts of a co-rout
171c0 69 6e 65 20 2a 2f 0a 20 20 20 20 75 38 20 6a 6f ine */. u8 jo
171d0 69 6e 74 79 70 65 3b 20 20 20 20 20 20 2f 2a 20 intype; /*
171e0 54 79 70 65 20 6f 66 20 6a 6f 69 6e 20 62 65 74 Type of join bet
171f0 77 65 65 6e 20 74 68 69 73 20 61 62 6c 65 20 61 ween this able a
17200 6e 64 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 nd the previous
17210 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 */. unsigned
17220 6e 6f 74 49 6e 64 65 78 65 64 20 3a 31 3b 20 20 notIndexed :1;
17230 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 /* True if the
17240 72 65 20 69 73 20 61 20 4e 4f 54 20 49 4e 44 45 re is a NOT INDE
17250 58 45 44 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 XED clause */.
17260 20 20 75 6e 73 69 67 6e 65 64 20 69 73 43 6f 72 unsigned isCor
17270 72 65 6c 61 74 65 64 20 3a 31 3b 20 20 2f 2a 20 related :1; /*
17280 54 72 75 65 20 69 66 20 73 75 62 2d 71 75 65 72 True if sub-quer
17290 79 20 69 73 20 63 6f 72 72 65 6c 61 74 65 64 20 y is correlated
172a0 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 */. unsigned
172b0 76 69 61 43 6f 72 6f 75 74 69 6e 65 20 3a 31 3b viaCoroutine :1;
172c0 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 65 64 /* Implemented
172d0 20 61 73 20 61 20 63 6f 2d 72 6f 75 74 69 6e 65 as a co-routine
172e0 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
172f0 20 69 73 52 65 63 75 72 73 69 76 65 20 3a 31 3b isRecursive :1;
17300 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 72 /* True for r
17310 65 63 75 72 73 69 76 65 20 72 65 66 65 72 65 6e ecursive referen
17320 63 65 20 69 6e 20 57 49 54 48 20 2a 2f 0a 23 69 ce in WITH */.#i
17330 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
17340 54 5f 45 58 50 4c 41 49 4e 0a 20 20 20 20 75 38 T_EXPLAIN. u8
17350 20 69 53 65 6c 65 63 74 49 64 3b 20 20 20 20 20 iSelectId;
17360 2f 2a 20 49 66 20 70 53 65 6c 65 63 74 21 3d 30 /* If pSelect!=0
17370 2c 20 74 68 65 20 69 64 20 6f 66 20 74 68 65 20 , the id of the
17380 73 75 62 2d 73 65 6c 65 63 74 20 69 6e 20 45 51 sub-select in EQ
17390 50 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 20 20 P */.#endif.
173a0 69 6e 74 20 69 43 75 72 73 6f 72 3b 20 20 20 20 int iCursor;
173b0 20 20 2f 2a 20 54 68 65 20 56 44 42 45 20 63 75 /* The VDBE cu
173c0 72 73 6f 72 20 6e 75 6d 62 65 72 20 75 73 65 64 rsor number used
173d0 20 74 6f 20 61 63 63 65 73 73 20 74 68 69 73 20 to access this
173e0 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 45 78 70 table */. Exp
173f0 72 20 2a 70 4f 6e 3b 20 20 20 20 20 20 20 20 2f r *pOn; /
17400 2a 20 54 68 65 20 4f 4e 20 63 6c 61 75 73 65 20 * The ON clause
17410 6f 66 20 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 of a join */.
17420 20 49 64 4c 69 73 74 20 2a 70 55 73 69 6e 67 3b IdList *pUsing;
17430 20 20 20 2f 2a 20 54 68 65 20 55 53 49 4e 47 20 /* The USING
17440 63 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e clause of a join
17450 20 2a 2f 0a 20 20 20 20 42 69 74 6d 61 73 6b 20 */. Bitmask
17460 63 6f 6c 55 73 65 64 3b 20 20 2f 2a 20 42 69 74 colUsed; /* Bit
17470 20 4e 20 28 31 3c 3c 4e 29 20 73 65 74 20 69 66 N (1<<N) set if
17480 20 63 6f 6c 75 6d 6e 20 4e 20 6f 66 20 70 54 61 column N of pTa
17490 62 20 69 73 20 75 73 65 64 20 2a 2f 0a 20 20 20 b is used */.
174a0 20 63 68 61 72 20 2a 7a 49 6e 64 65 78 65 64 42 char *zIndexedB
174b0 79 3b 20 2f 2a 20 49 64 65 6e 74 69 66 69 65 72 y; /* Identifier
174c0 20 66 72 6f 6d 20 22 49 4e 44 45 58 45 44 20 42 from "INDEXED B
174d0 59 20 3c 7a 49 6e 64 65 78 3e 22 20 63 6c 61 75 Y <zIndex>" clau
174e0 73 65 20 2a 2f 0a 20 20 20 20 49 6e 64 65 78 20 se */. Index
174f0 2a 70 49 6e 64 65 78 3b 20 20 20 20 2f 2a 20 49 *pIndex; /* I
17500 6e 64 65 78 20 73 74 72 75 63 74 75 72 65 20 63 ndex structure c
17510 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 orresponding to
17520 7a 49 6e 64 65 78 2c 20 69 66 20 61 6e 79 20 2a zIndex, if any *
17530 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 20 20 20 20 /. } a[1];
17540 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 65 /* One e
17550 6e 74 72 79 20 66 6f 72 20 65 61 63 68 20 69 64 ntry for each id
17560 65 6e 74 69 66 69 65 72 20 6f 6e 20 74 68 65 20 entifier on the
17570 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a list */.};../*.*
17580 2a 20 50 65 72 6d 69 74 74 65 64 20 76 61 6c 75 * Permitted valu
17590 65 73 20 6f 66 20 74 68 65 20 53 72 63 4c 69 73 es of the SrcLis
175a0 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 20 66 69 65 t.a.jointype fie
175b0 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 ld.*/.#define JT
175c0 5f 49 4e 4e 45 52 20 20 20 20 20 30 78 30 30 30 _INNER 0x000
175d0 31 20 20 20 20 2f 2a 20 41 6e 79 20 6b 69 6e 64 1 /* Any kind
175e0 20 6f 66 20 69 6e 6e 65 72 20 6f 72 20 63 72 6f of inner or cro
175f0 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 ss join */.#defi
17600 6e 65 20 4a 54 5f 43 52 4f 53 53 20 20 20 20 20 ne JT_CROSS
17610 30 78 30 30 30 32 20 20 20 20 2f 2a 20 45 78 70 0x0002 /* Exp
17620 6c 69 63 69 74 20 75 73 65 20 6f 66 20 74 68 65 licit use of the
17630 20 43 52 4f 53 53 20 6b 65 79 77 6f 72 64 20 2a CROSS keyword *
17640 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4e 41 54 /.#define JT_NAT
17650 55 52 41 4c 20 20 20 30 78 30 30 30 34 20 20 20 URAL 0x0004
17660 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 20 22 /* True for a "
17670 6e 61 74 75 72 61 6c 22 20 6a 6f 69 6e 20 2a 2f natural" join */
17680 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4c 45 46 54 .#define JT_LEFT
17690 20 20 20 20 20 20 30 78 30 30 30 38 20 20 20 20 0x0008
176a0 2f 2a 20 4c 65 66 74 20 6f 75 74 65 72 20 6a 6f /* Left outer jo
176b0 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 in */.#define JT
176c0 5f 52 49 47 48 54 20 20 20 20 20 30 78 30 30 31 _RIGHT 0x001
176d0 30 20 20 20 20 2f 2a 20 52 69 67 68 74 20 6f 75 0 /* Right ou
176e0 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 ter join */.#def
176f0 69 6e 65 20 4a 54 5f 4f 55 54 45 52 20 20 20 20 ine JT_OUTER
17700 20 30 78 30 30 32 30 20 20 20 20 2f 2a 20 54 68 0x0020 /* Th
17710 65 20 22 4f 55 54 45 52 22 20 6b 65 79 77 6f 72 e "OUTER" keywor
17720 64 20 69 73 20 70 72 65 73 65 6e 74 20 2a 2f 0a d is present */.
17730 23 64 65 66 69 6e 65 20 4a 54 5f 45 52 52 4f 52 #define JT_ERROR
17740 20 20 20 20 20 30 78 30 30 34 30 20 20 20 20 2f 0x0040 /
17750 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 20 75 6e 73 * unknown or uns
17760 75 70 70 6f 72 74 65 64 20 6a 6f 69 6e 20 74 79 upported join ty
17770 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 46 6c pe */.../*.** Fl
17780 61 67 73 20 61 70 70 72 6f 70 72 69 61 74 65 20 ags appropriate
17790 66 6f 72 20 74 68 65 20 77 63 74 72 6c 46 6c 61 for the wctrlFla
177a0 67 73 20 70 61 72 61 6d 65 74 65 72 20 6f 66 20 gs parameter of
177b0 73 71 6c 69 74 65 33 57 68 65 72 65 42 65 67 69 sqlite3WhereBegi
177c0 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 68 65 20 57 n().** and the W
177d0 68 65 72 65 49 6e 66 6f 2e 77 63 74 72 6c 46 6c hereInfo.wctrlFl
177e0 61 67 73 20 6d 65 6d 62 65 72 2e 0a 2a 2f 0a 23 ags member..*/.#
177f0 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 define WHERE_ORD
17800 45 52 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 78 ERBY_NORMAL 0x
17810 30 30 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a 2f 0000 /* No-op */
17820 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
17830 52 44 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 20 RDERBY_MIN
17840 30 78 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 20 0x0001 /* ORDER
17850 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f BY processing fo
17860 72 20 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f 0a r min() func */.
17870 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 #define WHERE_OR
17880 44 45 52 42 59 5f 4d 41 58 20 20 20 20 20 20 30 DERBY_MAX 0
17890 78 30 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 42 x0002 /* ORDER B
178a0 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 Y processing for
178b0 20 6d 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a 23 max() func */.#
178c0 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 define WHERE_ONE
178d0 50 41 53 53 5f 44 45 53 49 52 45 44 20 20 30 78 PASS_DESIRED 0x
178e0 30 30 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f 20 0004 /* Want to
178f0 64 6f 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 41 do one-pass UPDA
17900 54 45 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 65 TE/DELETE */.#de
17910 66 69 6e 65 20 57 48 45 52 45 5f 44 55 50 4c 49 fine WHERE_DUPLI
17920 43 41 54 45 53 5f 4f 4b 20 20 20 20 30 78 30 30 CATES_OK 0x00
17930 30 38 20 2f 2a 20 4f 6b 20 74 6f 20 72 65 74 75 08 /* Ok to retu
17940 72 6e 20 61 20 72 6f 77 20 6d 6f 72 65 20 74 68 rn a row more th
17950 61 6e 20 6f 6e 63 65 20 2a 2f 0a 23 64 65 66 69 an once */.#defi
17960 6e 65 20 57 48 45 52 45 5f 4f 4d 49 54 5f 4f 50 ne WHERE_OMIT_OP
17970 45 4e 5f 43 4c 4f 53 45 20 20 30 78 30 30 31 30 EN_CLOSE 0x0010
17980 20 2f 2a 20 54 61 62 6c 65 20 63 75 72 73 6f 72 /* Table cursor
17990 73 20 61 72 65 20 61 6c 72 65 61 64 79 20 6f 70 s are already op
179a0 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 en */.#define WH
179b0 45 52 45 5f 46 4f 52 43 45 5f 54 41 42 4c 45 20 ERE_FORCE_TABLE
179c0 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 44 0x0020 /* D
179d0 6f 20 6e 6f 74 20 75 73 65 20 61 6e 20 69 6e 64 o not use an ind
179e0 65 78 2d 6f 6e 6c 79 20 73 65 61 72 63 68 20 2a ex-only search *
179f0 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
17a00 4f 4e 45 54 41 42 4c 45 5f 4f 4e 4c 59 20 20 20 ONETABLE_ONLY
17a10 20 30 78 30 30 34 30 20 2f 2a 20 4f 6e 6c 79 20 0x0040 /* Only
17a20 63 6f 64 65 20 74 68 65 20 31 73 74 20 74 61 62 code the 1st tab
17a30 6c 65 20 69 6e 20 70 54 61 62 4c 69 73 74 20 2a le in pTabList *
17a40 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
17a50 4e 4f 5f 41 55 54 4f 49 4e 44 45 58 20 20 20 20 NO_AUTOINDEX
17a60 20 30 78 30 30 38 30 20 2f 2a 20 44 69 73 61 6c 0x0080 /* Disal
17a70 6c 6f 77 20 61 75 74 6f 6d 61 74 69 63 20 69 6e low automatic in
17a80 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 dexes */.#define
17a90 20 57 48 45 52 45 5f 47 52 4f 55 50 42 59 20 20 WHERE_GROUPBY
17aa0 20 20 20 20 20 20 20 20 30 78 30 31 30 30 20 2f 0x0100 /
17ab0 2a 20 70 4f 72 64 65 72 42 79 20 69 73 20 72 65 * pOrderBy is re
17ac0 61 6c 6c 79 20 61 20 47 52 4f 55 50 20 42 59 20 ally a GROUP BY
17ad0 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
17ae0 5f 44 49 53 54 49 4e 43 54 42 59 20 20 20 20 20 _DISTINCTBY
17af0 20 20 30 78 30 32 30 30 20 2f 2a 20 70 4f 72 64 0x0200 /* pOrd
17b00 65 72 62 79 20 69 73 20 72 65 61 6c 6c 79 20 61 erby is really a
17b10 20 44 49 53 54 49 4e 43 54 20 63 6c 61 75 73 65 DISTINCT clause
17b20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
17b30 45 5f 57 41 4e 54 5f 44 49 53 54 49 4e 43 54 20 E_WANT_DISTINCT
17b40 20 20 20 30 78 30 34 30 30 20 2f 2a 20 41 6c 6c 0x0400 /* All
17b50 20 6f 75 74 70 75 74 20 6e 65 65 64 73 20 74 6f output needs to
17b60 20 62 65 20 64 69 73 74 69 6e 63 74 20 2a 2f 0a be distinct */.
17b70 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 53 4f #define WHERE_SO
17b80 52 54 42 59 47 52 4f 55 50 20 20 20 20 20 20 30 RTBYGROUP 0
17b90 78 30 38 30 30 20 2f 2a 20 53 75 70 70 6f 72 74 x0800 /* Support
17ba0 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 53 sqlite3WhereIsS
17bb0 6f 72 74 65 64 28 29 20 2a 2f 0a 23 64 65 66 69 orted() */.#defi
17bc0 6e 65 20 57 48 45 52 45 5f 52 45 4f 50 45 4e 5f ne WHERE_REOPEN_
17bd0 49 44 58 20 20 20 20 20 20 20 30 78 31 30 30 30 IDX 0x1000
17be0 20 2f 2a 20 54 72 79 20 74 6f 20 75 73 65 20 4f /* Try to use O
17bf0 50 5f 52 65 6f 70 65 6e 49 64 78 20 2a 2f 0a 0a P_ReopenIdx */..
17c00 2f 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 72 /* Allowed retur
17c10 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 71 n values from sq
17c20 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 74 lite3WhereIsDist
17c30 69 6e 63 74 28 29 0a 2a 2f 0a 23 64 65 66 69 6e inct().*/.#defin
17c40 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 e WHERE_DISTINCT
17c50 5f 4e 4f 4f 50 20 20 20 20 20 20 30 20 20 2f 2a _NOOP 0 /*
17c60 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 DISTINCT keywor
17c70 64 20 6e 6f 74 20 75 73 65 64 20 2a 2f 0a 23 64 d not used */.#d
17c80 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 efine WHERE_DIST
17c90 49 4e 43 54 5f 55 4e 49 51 55 45 20 20 20 20 31 INCT_UNIQUE 1
17ca0 20 20 2f 2a 20 4e 6f 20 64 75 70 6c 69 63 61 74 /* No duplicat
17cb0 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 es */.#define WH
17cc0 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 4f 52 44 ERE_DISTINCT_ORD
17cd0 45 52 45 44 20 20 20 32 20 20 2f 2a 20 41 6c 6c ERED 2 /* All
17ce0 20 64 75 70 6c 69 63 61 74 65 73 20 61 72 65 20 duplicates are
17cf0 61 64 6a 61 63 65 6e 74 20 2a 2f 0a 23 64 65 66 adjacent */.#def
17d00 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e ine WHERE_DISTIN
17d10 43 54 5f 55 4e 4f 52 44 45 52 45 44 20 33 20 20 CT_UNORDERED 3
17d20 2f 2a 20 44 75 70 6c 69 63 61 74 65 73 20 61 72 /* Duplicates ar
17d30 65 20 73 63 61 74 74 65 72 65 64 20 2a 2f 0a 0a e scattered */..
17d40 2f 2a 0a 2a 2a 20 41 20 4e 61 6d 65 43 6f 6e 74 /*.** A NameCont
17d50 65 78 74 20 64 65 66 69 6e 65 73 20 61 20 63 6f ext defines a co
17d60 6e 74 65 78 74 20 69 6e 20 77 68 69 63 68 20 74 ntext in which t
17d70 6f 20 72 65 73 6f 6c 76 65 20 74 61 62 6c 65 20 o resolve table
17d80 61 6e 64 20 63 6f 6c 75 6d 6e 0a 2a 2a 20 6e 61 and column.** na
17d90 6d 65 73 2e 20 20 54 68 65 20 63 6f 6e 74 65 78 mes. The contex
17da0 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 20 t consists of a
17db0 6c 69 73 74 20 6f 66 20 74 61 62 6c 65 73 20 28 list of tables (
17dc0 74 68 65 20 70 53 72 63 4c 69 73 74 29 20 66 69 the pSrcList) fi
17dd0 65 6c 64 20 61 6e 64 0a 2a 2a 20 61 20 6c 69 73 eld and.** a lis
17de0 74 20 6f 66 20 6e 61 6d 65 64 20 65 78 70 72 65 t of named expre
17df0 73 73 69 6f 6e 20 28 70 45 4c 69 73 74 29 2e 20 ssion (pEList).
17e00 20 54 68 65 20 6e 61 6d 65 64 20 65 78 70 72 65 The named expre
17e10 73 73 69 6f 6e 20 6c 69 73 74 20 6d 61 79 0a 2a ssion list may.*
17e20 2a 20 62 65 20 4e 55 4c 4c 2e 20 20 54 68 65 20 * be NULL. The
17e30 70 53 72 63 20 63 6f 72 72 65 73 70 6f 6e 64 73 pSrc corresponds
17e40 20 74 6f 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 to the FROM cla
17e50 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 54 20 use of a SELECT
17e60 6f 72 0a 2a 2a 20 74 6f 20 74 68 65 20 74 61 62 or.** to the tab
17e70 6c 65 20 62 65 69 6e 67 20 6f 70 65 72 61 74 65 le being operate
17e80 64 20 6f 6e 20 62 79 20 49 4e 53 45 52 54 2c 20 d on by INSERT,
17e90 55 50 44 41 54 45 2c 20 6f 72 20 44 45 4c 45 54 UPDATE, or DELET
17ea0 45 2e 20 20 54 68 65 0a 2a 2a 20 70 45 4c 69 73 E. The.** pELis
17eb0 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f t corresponds to
17ec0 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 20 the result set
17ed0 6f 66 20 61 20 53 45 4c 45 43 54 20 61 6e 64 20 of a SELECT and
17ee0 69 73 20 4e 55 4c 4c 20 66 6f 72 0a 2a 2a 20 6f is NULL for.** o
17ef0 74 68 65 72 20 73 74 61 74 65 6d 65 6e 74 73 2e ther statements.
17f00 0a 2a 2a 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 .**.** NameConte
17f10 78 74 73 20 63 61 6e 20 62 65 20 6e 65 73 74 65 xts can be neste
17f20 64 2e 20 20 57 68 65 6e 20 72 65 73 6f 6c 76 69 d. When resolvi
17f30 6e 67 20 6e 61 6d 65 73 2c 20 74 68 65 20 69 6e ng names, the in
17f40 6e 65 72 2d 6d 6f 73 74 20 0a 2a 2a 20 63 6f 6e ner-most .** con
17f50 74 65 78 74 20 69 73 20 73 65 61 72 63 68 65 64 text is searched
17f60 20 66 69 72 73 74 2e 20 20 49 66 20 6e 6f 20 6d first. If no m
17f70 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 atch is found, t
17f80 68 65 20 6e 65 78 74 20 6f 75 74 65 72 0a 2a 2a he next outer.**
17f90 20 63 6f 6e 74 65 78 74 20 69 73 20 63 68 65 63 context is chec
17fa0 6b 65 64 2e 20 20 49 66 20 74 68 65 72 65 20 69 ked. If there i
17fb0 73 20 73 74 69 6c 6c 20 6e 6f 20 6d 61 74 63 68 s still no match
17fc0 2c 20 74 68 65 20 6e 65 78 74 20 63 6f 6e 74 65 , the next conte
17fd0 78 74 0a 2a 2a 20 69 73 20 63 68 65 63 6b 65 64 xt.** is checked
17fe0 2e 20 20 54 68 69 73 20 70 72 6f 63 65 73 73 20 . This process
17ff0 63 6f 6e 74 69 6e 75 65 73 20 75 6e 74 69 6c 20 continues until
18000 65 69 74 68 65 72 20 61 20 6d 61 74 63 68 20 69 either a match i
18010 73 20 66 6f 75 6e 64 0a 2a 2a 20 6f 72 20 61 6c s found.** or al
18020 6c 20 63 6f 6e 74 65 78 74 73 20 61 72 65 20 63 l contexts are c
18030 68 65 63 6b 2e 20 20 57 68 65 6e 20 61 20 6d 61 heck. When a ma
18040 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 68 tch is found, th
18050 65 20 6e 52 65 66 20 6d 65 6d 62 65 72 20 6f 66 e nRef member of
18060 0a 2a 2a 20 74 68 65 20 63 6f 6e 74 65 78 74 20 .** the context
18070 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 6d containing the m
18080 61 74 63 68 20 69 73 20 69 6e 63 72 65 6d 65 6e atch is incremen
18090 74 65 64 2e 20 0a 2a 2a 0a 2a 2a 20 45 61 63 68 ted. .**.** Each
180a0 20 73 75 62 71 75 65 72 79 20 67 65 74 73 20 61 subquery gets a
180b0 20 6e 65 77 20 4e 61 6d 65 43 6f 6e 74 65 78 74 new NameContext
180c0 2e 20 20 54 68 65 20 70 4e 65 78 74 20 66 69 65 . The pNext fie
180d0 6c 64 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 ld points to the
180e0 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 .** NameContext
180f0 69 6e 20 74 68 65 20 70 61 72 65 6e 74 20 71 75 in the parent qu
18100 65 72 79 2e 20 20 54 68 75 73 20 74 68 65 20 70 ery. Thus the p
18110 72 6f 63 65 73 73 20 6f 66 20 73 63 61 6e 6e 69 rocess of scanni
18120 6e 67 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f ng the.** NameCo
18130 6e 74 65 78 74 20 6c 69 73 74 20 63 6f 72 72 65 ntext list corre
18140 73 70 6f 6e 64 73 20 74 6f 20 73 65 61 72 63 68 sponds to search
18150 69 6e 67 20 74 68 72 6f 75 67 68 20 73 75 63 63 ing through succ
18160 65 73 73 69 76 65 6c 79 20 6f 75 74 65 72 0a 2a essively outer.*
18170 2a 20 73 75 62 71 75 65 72 69 65 73 20 6c 6f 6f * subqueries loo
18180 6b 69 6e 67 20 66 6f 72 20 61 20 6d 61 74 63 68 king for a match
18190 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4e 61 6d 65 ..*/.struct Name
181a0 43 6f 6e 74 65 78 74 20 7b 0a 20 20 50 61 72 73 Context {. Pars
181b0 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 e *pParse;
181c0 20 2f 2a 20 54 68 65 20 70 61 72 73 65 72 20 2a /* The parser *
181d0 2f 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 /. SrcList *pSr
181e0 63 4c 69 73 74 3b 20 20 20 2f 2a 20 4f 6e 65 20 cList; /* One
181f0 6f 72 20 6d 6f 72 65 20 74 61 62 6c 65 73 20 75 or more tables u
18200 73 65 64 20 74 6f 20 72 65 73 6f 6c 76 65 20 6e sed to resolve n
18210 61 6d 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c 69 ames */. ExprLi
18220 73 74 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 2f st *pEList; /
18230 2a 20 4f 70 74 69 6f 6e 61 6c 20 6c 69 73 74 20 * Optional list
18240 6f 66 20 72 65 73 75 6c 74 2d 73 65 74 20 63 6f of result-set co
18250 6c 75 6d 6e 73 20 2a 2f 0a 20 20 41 67 67 49 6e lumns */. AggIn
18260 66 6f 20 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 fo *pAggInfo;
18270 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 /* Information a
18280 62 6f 75 74 20 61 67 67 72 65 67 61 74 65 73 20 bout aggregates
18290 61 74 20 74 68 69 73 20 6c 65 76 65 6c 20 2a 2f at this level */
182a0 0a 20 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 2a . NameContext *
182b0 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 78 74 20 pNext; /* Next
182c0 6f 75 74 65 72 20 6e 61 6d 65 20 63 6f 6e 74 65 outer name conte
182d0 78 74 2e 20 20 4e 55 4c 4c 20 66 6f 72 20 6f 75 xt. NULL for ou
182e0 74 65 72 6d 6f 73 74 20 2a 2f 0a 20 20 69 6e 74 termost */. int
182f0 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 20 nRef;
18300 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e /* Number of n
18310 61 6d 65 73 20 72 65 73 6f 6c 76 65 64 20 62 79 ames resolved by
18320 20 74 68 69 73 20 63 6f 6e 74 65 78 74 20 2a 2f this context */
18330 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 20 . int nErr;
18340 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
18350 72 20 6f 66 20 65 72 72 6f 72 73 20 65 6e 63 6f r of errors enco
18360 75 6e 74 65 72 65 64 20 77 68 69 6c 65 20 72 65 untered while re
18370 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 2a 2f solving names */
18380 0a 20 20 75 31 36 20 6e 63 46 6c 61 67 73 3b 20 . u16 ncFlags;
18390 20 20 20 20 20 20 20 20 2f 2a 20 5a 65 72 6f 20 /* Zero
183a0 6f 72 20 6d 6f 72 65 20 4e 43 5f 2a 20 66 6c 61 or more NC_* fla
183b0 67 73 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 gs defined below
183c0 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c */.};../*.** Al
183d0 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 lowed values for
183e0 20 74 68 65 20 4e 61 6d 65 43 6f 6e 74 65 78 74 the NameContext
183f0 2c 20 6e 63 46 6c 61 67 73 20 66 69 65 6c 64 2e , ncFlags field.
18400 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 3a 20 20 4e 43 .**.** Note: NC
18410 5f 4d 69 6e 4d 61 78 41 67 67 20 6d 75 73 74 20 _MinMaxAgg must
18420 68 61 76 65 20 74 68 65 20 73 61 6d 65 20 76 61 have the same va
18430 6c 75 65 20 61 73 20 53 46 5f 4d 69 6e 4d 61 78 lue as SF_MinMax
18440 41 67 67 20 61 6e 64 0a 2a 2a 20 53 51 4c 49 54 Agg and.** SQLIT
18450 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 2e 0a 2a E_FUNC_MINMAX..*
18460 2a 20 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 * .*/.#define NC
18470 5f 41 6c 6c 6f 77 41 67 67 20 20 30 78 30 30 30 _AllowAgg 0x000
18480 31 20 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 1 /* Aggregate
18490 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 6c functions are al
184a0 6c 6f 77 65 64 20 68 65 72 65 20 2a 2f 0a 23 64 lowed here */.#d
184b0 65 66 69 6e 65 20 4e 43 5f 48 61 73 41 67 67 20 efine NC_HasAgg
184c0 20 20 20 30 78 30 30 30 32 20 20 2f 2a 20 4f 6e 0x0002 /* On
184d0 65 20 6f 72 20 6d 6f 72 65 20 61 67 67 72 65 67 e or more aggreg
184e0 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 73 65 ate functions se
184f0 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 en */.#define NC
18500 5f 49 73 43 68 65 63 6b 20 20 20 30 78 30 30 30 _IsCheck 0x000
18510 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 4 /* True if re
18520 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 69 6e solving names in
18530 20 61 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 61 a CHECK constra
18540 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e int */.#define N
18550 43 5f 49 6e 41 67 67 46 75 6e 63 20 30 78 30 30 C_InAggFunc 0x00
18560 30 38 20 20 2f 2a 20 54 72 75 65 20 69 66 20 61 08 /* True if a
18570 6e 61 6c 79 7a 69 6e 67 20 61 72 67 75 6d 65 6e nalyzing argumen
18580 74 73 20 74 6f 20 61 6e 20 61 67 67 20 66 75 6e ts to an agg fun
18590 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f c */.#define NC_
185a0 50 61 72 74 49 64 78 20 20 20 30 78 30 30 31 30 PartIdx 0x0010
185b0 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 /* True if res
185c0 6f 6c 76 69 6e 67 20 61 20 70 61 72 74 69 61 6c olving a partial
185d0 20 69 6e 64 65 78 20 57 48 45 52 45 20 2a 2f 0a index WHERE */.
185e0 23 64 65 66 69 6e 65 20 4e 43 5f 4d 69 6e 4d 61 #define NC_MinMa
185f0 78 41 67 67 20 30 78 31 30 30 30 20 20 2f 2a 20 xAgg 0x1000 /*
18600 6d 69 6e 2f 6d 61 78 20 61 67 67 72 65 67 61 74 min/max aggregat
18610 65 73 20 73 65 65 6e 2e 20 20 53 65 65 20 6e 6f es seen. See no
18620 74 65 20 61 62 6f 76 65 20 2a 2f 0a 0a 2f 2a 0a te above */../*.
18630 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
18640 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
18650 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 structure contai
18660 6e 73 20 61 6c 6c 20 69 6e 66 6f 72 6d 61 74 69 ns all informati
18670 6f 6e 0a 2a 2a 20 6e 65 65 64 65 64 20 74 6f 20 on.** needed to
18680 67 65 6e 65 72 61 74 65 20 63 6f 64 65 20 66 6f generate code fo
18690 72 20 61 20 73 69 6e 67 6c 65 20 53 45 4c 45 43 r a single SELEC
186a0 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 0a T statement..**.
186b0 2a 2a 20 6e 4c 69 6d 69 74 20 69 73 20 73 65 74 ** nLimit is set
186c0 20 74 6f 20 2d 31 20 69 66 20 74 68 65 72 65 20 to -1 if there
186d0 69 73 20 6e 6f 20 4c 49 4d 49 54 20 63 6c 61 75 is no LIMIT clau
186e0 73 65 2e 20 20 6e 4f 66 66 73 65 74 20 69 73 20 se. nOffset is
186f0 73 65 74 20 74 6f 20 30 2e 0a 2a 2a 20 49 66 20 set to 0..** If
18700 74 68 65 72 65 20 69 73 20 61 20 4c 49 4d 49 54 there is a LIMIT
18710 20 63 6c 61 75 73 65 2c 20 74 68 65 20 70 61 72 clause, the par
18720 73 65 72 20 73 65 74 73 20 6e 4c 69 6d 69 74 20 ser sets nLimit
18730 74 6f 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 to the value of
18740 74 68 65 0a 2a 2a 20 6c 69 6d 69 74 20 61 6e 64 the.** limit and
18750 20 6e 4f 66 66 73 65 74 20 74 6f 20 74 68 65 20 nOffset to the
18760 76 61 6c 75 65 20 6f 66 20 74 68 65 20 6f 66 66 value of the off
18770 73 65 74 20 28 6f 72 20 30 20 69 66 20 74 68 65 set (or 0 if the
18780 72 65 20 69 73 20 6e 6f 74 0a 2a 2a 20 6f 66 66 re is not.** off
18790 73 65 74 29 2e 20 20 42 75 74 20 6c 61 74 65 72 set). But later
187a0 20 6f 6e 2c 20 6e 4c 69 6d 69 74 20 61 6e 64 20 on, nLimit and
187b0 6e 4f 66 66 73 65 74 20 62 65 63 6f 6d 65 20 74 nOffset become t
187c0 68 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 he memory locati
187d0 6f 6e 73 0a 2a 2a 20 69 6e 20 74 68 65 20 56 44 ons.** in the VD
187e0 42 45 20 74 68 61 74 20 72 65 63 6f 72 64 20 74 BE that record t
187f0 68 65 20 6c 69 6d 69 74 20 61 6e 64 20 6f 66 66 he limit and off
18800 73 65 74 20 63 6f 75 6e 74 65 72 73 2e 0a 2a 2a set counters..**
18810 0a 2a 2a 20 61 64 64 72 4f 70 65 6e 45 70 68 6d .** addrOpenEphm
18820 5b 5d 20 65 6e 74 72 69 65 73 20 63 6f 6e 74 61 [] entries conta
18830 69 6e 20 74 68 65 20 61 64 64 72 65 73 73 20 6f in the address o
18840 66 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 f OP_OpenEphemer
18850 61 6c 20 6f 70 63 6f 64 65 73 2e 0a 2a 2a 20 54 al opcodes..** T
18860 68 65 73 65 20 61 64 64 72 65 73 73 65 73 20 6d hese addresses m
18870 75 73 74 20 62 65 20 73 74 6f 72 65 64 20 73 6f ust be stored so
18880 20 74 68 61 74 20 77 65 20 63 61 6e 20 67 6f 20 that we can go
18890 62 61 63 6b 20 61 6e 64 20 66 69 6c 6c 20 69 6e back and fill in
188a0 0a 2a 2a 20 74 68 65 20 50 34 5f 4b 45 59 49 4e .** the P4_KEYIN
188b0 46 4f 20 61 6e 64 20 50 32 20 70 61 72 61 6d 65 FO and P2 parame
188c0 74 65 72 73 20 6c 61 74 65 72 2e 20 20 4e 65 69 ters later. Nei
188d0 74 68 65 72 20 74 68 65 20 4b 65 79 49 6e 66 6f ther the KeyInfo
188e0 20 6e 6f 72 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 nor.** the numb
188f0 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
18900 20 50 32 20 63 61 6e 20 62 65 20 63 6f 6d 70 75 P2 can be compu
18910 74 65 64 20 61 74 20 74 68 65 20 73 61 6d 65 20 ted at the same
18920 74 69 6d 65 0a 2a 2a 20 61 73 20 74 68 65 20 4f time.** as the O
18930 50 5f 4f 70 65 6e 45 70 68 6d 20 69 6e 73 74 72 P_OpenEphm instr
18940 75 63 74 69 6f 6e 20 69 73 20 63 6f 64 65 64 20 uction is coded
18950 62 65 63 61 75 73 65 20 6e 6f 74 0a 2a 2a 20 65 because not.** e
18960 6e 6f 75 67 68 20 69 6e 66 6f 72 6d 61 74 69 6f nough informatio
18970 6e 20 61 62 6f 75 74 20 74 68 65 20 63 6f 6d 70 n about the comp
18980 6f 75 6e 64 20 71 75 65 72 79 20 69 73 20 6b 6e ound query is kn
18990 6f 77 6e 20 61 74 20 74 68 61 74 20 70 6f 69 6e own at that poin
189a0 74 2e 0a 2a 2a 20 54 68 65 20 4b 65 79 49 6e 66 t..** The KeyInf
189b0 6f 20 66 6f 72 20 61 64 64 72 4f 70 65 6e 54 72 o for addrOpenTr
189c0 61 6e 5b 30 5d 20 61 6e 64 20 5b 31 5d 20 63 6f an[0] and [1] co
189d0 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 ntains collating
189e0 20 73 65 71 75 65 6e 63 65 73 0a 2a 2a 20 66 6f sequences.** fo
189f0 72 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 r the result set
18a00 2e 20 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 . The KeyInfo f
18a10 6f 72 20 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b or addrOpenEphm[
18a20 32 5d 20 63 6f 6e 74 61 69 6e 73 20 63 6f 6c 6c 2] contains coll
18a30 61 74 69 6e 67 0a 2a 2a 20 73 65 71 75 65 6e 63 ating.** sequenc
18a40 65 73 20 66 6f 72 20 74 68 65 20 4f 52 44 45 52 es for the ORDER
18a50 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a 73 BY clause..*/.s
18a60 74 72 75 63 74 20 53 65 6c 65 63 74 20 7b 0a 20 truct Select {.
18a70 20 45 78 70 72 4c 69 73 74 20 2a 70 45 4c 69 73 ExprList *pELis
18a80 74 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 66 t; /* The f
18a90 69 65 6c 64 73 20 6f 66 20 74 68 65 20 72 65 73 ields of the res
18aa0 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 ult */. u8 op;
18ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18ac0 2f 2a 20 4f 6e 65 20 6f 66 3a 20 54 4b 5f 55 4e /* One of: TK_UN
18ad0 49 4f 4e 20 54 4b 5f 41 4c 4c 20 54 4b 5f 49 4e ION TK_ALL TK_IN
18ae0 54 45 52 53 45 43 54 20 54 4b 5f 45 58 43 45 50 TERSECT TK_EXCEP
18af0 54 20 2a 2f 0a 20 20 75 31 36 20 73 65 6c 46 6c T */. u16 selFl
18b00 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ags; /*
18b10 20 56 61 72 69 6f 75 73 20 53 46 5f 2a 20 76 61 Various SF_* va
18b20 6c 75 65 73 20 2a 2f 0a 20 20 69 6e 74 20 69 4c lues */. int iL
18b30 69 6d 69 74 2c 20 69 4f 66 66 73 65 74 3b 20 20 imit, iOffset;
18b40 20 2f 2a 20 4d 65 6d 6f 72 79 20 72 65 67 69 73 /* Memory regis
18b50 74 65 72 73 20 68 6f 6c 64 69 6e 67 20 4c 49 4d ters holding LIM
18b60 49 54 20 26 20 4f 46 46 53 45 54 20 63 6f 75 6e IT & OFFSET coun
18b70 74 65 72 73 20 2a 2f 0a 23 69 66 20 53 45 4c 45 ters */.#if SELE
18b80 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 0a CTTRACE_ENABLED.
18b90 20 20 63 68 61 72 20 7a 53 65 6c 4e 61 6d 65 5b char zSelName[
18ba0 31 32 5d 3b 20 20 20 20 20 2f 2a 20 53 79 6d 62 12]; /* Symb
18bb0 6f 6c 69 63 20 6e 61 6d 65 20 6f 66 20 74 68 69 olic name of thi
18bc0 73 20 53 45 4c 45 43 54 20 75 73 65 20 66 6f 72 s SELECT use for
18bd0 20 64 65 62 75 67 67 69 6e 67 20 2a 2f 0a 23 65 debugging */.#e
18be0 6e 64 69 66 0a 20 20 69 6e 74 20 61 64 64 72 4f ndif. int addrO
18bf0 70 65 6e 45 70 68 6d 5b 32 5d 3b 20 20 20 2f 2a penEphm[2]; /*
18c00 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 20 6f 70 OP_OpenEphem op
18c10 63 6f 64 65 73 20 72 65 6c 61 74 65 64 20 74 6f codes related to
18c20 20 74 68 69 73 20 73 65 6c 65 63 74 20 2a 2f 0a this select */.
18c30 20 20 75 36 34 20 6e 53 65 6c 65 63 74 52 6f 77 u64 nSelectRow
18c40 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 69 ; /* Esti
18c50 6d 61 74 65 64 20 6e 75 6d 62 65 72 20 6f 66 20 mated number of
18c60 72 65 73 75 6c 74 20 72 6f 77 73 20 2a 2f 0a 20 result rows */.
18c70 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 3b 20 SrcList *pSrc;
18c80 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 46 /* The F
18c90 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 ROM clause */.
18ca0 45 78 70 72 20 2a 70 57 68 65 72 65 3b 20 20 20 Expr *pWhere;
18cb0 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 /* The WH
18cc0 45 52 45 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 ERE clause */.
18cd0 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 70 ExprList *pGroup
18ce0 42 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 47 52 By; /* The GR
18cf0 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 2a 2f OUP BY clause */
18d00 0a 20 20 45 78 70 72 20 2a 70 48 61 76 69 6e 67 . Expr *pHaving
18d10 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 ; /* The
18d20 20 48 41 56 49 4e 47 20 63 6c 61 75 73 65 20 2a HAVING clause *
18d30 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f /. ExprList *pO
18d40 72 64 65 72 42 79 3b 20 20 20 20 2f 2a 20 54 68 rderBy; /* Th
18d50 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
18d60 65 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 e */. Select *p
18d70 50 72 69 6f 72 3b 20 20 20 20 20 20 20 20 2f 2a Prior; /*
18d80 20 50 72 69 6f 72 20 73 65 6c 65 63 74 20 69 6e Prior select in
18d90 20 61 20 63 6f 6d 70 6f 75 6e 64 20 73 65 6c 65 a compound sele
18da0 63 74 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f 0a ct statement */.
18db0 20 20 53 65 6c 65 63 74 20 2a 70 4e 65 78 74 3b Select *pNext;
18dc0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 /* Next
18dd0 20 73 65 6c 65 63 74 20 74 6f 20 74 68 65 20 6c select to the l
18de0 65 66 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 6e eft in a compoun
18df0 64 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4c 69 d */. Expr *pLi
18e00 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a mit; /*
18e10 20 4c 49 4d 49 54 20 65 78 70 72 65 73 73 69 6f LIMIT expressio
18e20 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e 6f n. NULL means no
18e30 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 45 78 70 t used. */. Exp
18e40 72 20 2a 70 4f 66 66 73 65 74 3b 20 20 20 20 20 r *pOffset;
18e50 20 20 20 20 2f 2a 20 4f 46 46 53 45 54 20 65 78 /* OFFSET ex
18e60 70 72 65 73 73 69 6f 6e 2e 20 4e 55 4c 4c 20 6d pression. NULL m
18e70 65 61 6e 73 20 6e 6f 74 20 75 73 65 64 2e 20 2a eans not used. *
18e80 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 74 68 3b /. With *pWith;
18e90 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 49 /* WI
18ea0 54 48 20 63 6c 61 75 73 65 20 61 74 74 61 63 68 TH clause attach
18eb0 65 64 20 74 6f 20 74 68 69 73 20 73 65 6c 65 63 ed to this selec
18ec0 74 2e 20 4f 72 20 4e 55 4c 4c 2e 20 2a 2f 0a 7d t. Or NULL. */.}
18ed0 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 ;../*.** Allowed
18ee0 20 76 61 6c 75 65 73 20 66 6f 72 20 53 65 6c 65 values for Sele
18ef0 63 74 2e 73 65 6c 46 6c 61 67 73 2e 20 20 54 68 ct.selFlags. Th
18f00 65 20 22 53 46 22 20 70 72 65 66 69 78 20 73 74 e "SF" prefix st
18f10 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 53 65 6c ands for.** "Sel
18f20 65 63 74 20 46 6c 61 67 22 2e 0a 2a 2f 0a 23 64 ect Flag"..*/.#d
18f30 65 66 69 6e 65 20 53 46 5f 44 69 73 74 69 6e 63 efine SF_Distinc
18f40 74 20 20 20 20 20 20 20 20 30 78 30 30 30 31 20 t 0x0001
18f50 20 2f 2a 20 4f 75 74 70 75 74 20 73 68 6f 75 6c /* Output shoul
18f60 64 20 62 65 20 44 49 53 54 49 4e 43 54 20 2a 2f d be DISTINCT */
18f70 0a 23 64 65 66 69 6e 65 20 53 46 5f 41 6c 6c 20 .#define SF_All
18f80 20 20 20 20 20 20 20 20 20 20 20 20 30 78 30 30 0x00
18f90 30 32 20 20 2f 2a 20 49 6e 63 6c 75 64 65 73 20 02 /* Includes
18fa0 74 68 65 20 41 4c 4c 20 6b 65 79 77 6f 72 64 20 the ALL keyword
18fb0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 65 */.#define SF_Re
18fc0 73 6f 6c 76 65 64 20 20 20 20 20 20 20 20 30 78 solved 0x
18fd0 30 30 30 34 20 20 2f 2a 20 49 64 65 6e 74 69 66 0004 /* Identif
18fe0 69 65 72 73 20 68 61 76 65 20 62 65 65 6e 20 72 iers have been r
18ff0 65 73 6f 6c 76 65 64 20 2a 2f 0a 23 64 65 66 69 esolved */.#defi
19000 6e 65 20 53 46 5f 41 67 67 72 65 67 61 74 65 20 ne SF_Aggregate
19010 20 20 20 20 20 20 30 78 30 30 30 38 20 20 2f 2a 0x0008 /*
19020 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 Contains aggreg
19030 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f ate functions */
19040 0a 23 64 65 66 69 6e 65 20 53 46 5f 55 73 65 73 .#define SF_Uses
19050 45 70 68 65 6d 65 72 61 6c 20 20 20 30 78 30 30 Ephemeral 0x00
19060 31 30 20 20 2f 2a 20 55 73 65 73 20 74 68 65 20 10 /* Uses the
19070 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f 70 OpenEphemeral op
19080 63 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 code */.#define
19090 53 46 5f 45 78 70 61 6e 64 65 64 20 20 20 20 20 SF_Expanded
190a0 20 20 20 30 78 30 30 32 30 20 20 2f 2a 20 73 71 0x0020 /* sq
190b0 6c 69 74 65 33 53 65 6c 65 63 74 45 78 70 61 6e lite3SelectExpan
190c0 64 28 29 20 63 61 6c 6c 65 64 20 6f 6e 20 74 68 d() called on th
190d0 69 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 is */.#define SF
190e0 5f 48 61 73 54 79 70 65 49 6e 66 6f 20 20 20 20 _HasTypeInfo
190f0 20 30 78 30 30 34 30 20 20 2f 2a 20 46 52 4f 4d 0x0040 /* FROM
19100 20 73 75 62 71 75 65 72 69 65 73 20 68 61 76 65 subqueries have
19110 20 54 61 62 6c 65 20 6d 65 74 61 64 61 74 61 20 Table metadata
19120 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 6f */.#define SF_Co
19130 6d 70 6f 75 6e 64 20 20 20 20 20 20 20 20 30 78 mpound 0x
19140 30 30 38 30 20 20 2f 2a 20 50 61 72 74 20 6f 66 0080 /* Part of
19150 20 61 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 a compound quer
19160 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f y */.#define SF_
19170 56 61 6c 75 65 73 20 20 20 20 20 20 20 20 20 20 Values
19180 30 78 30 31 30 30 20 20 2f 2a 20 53 79 6e 74 68 0x0100 /* Synth
19190 65 73 69 7a 65 64 20 66 72 6f 6d 20 56 41 4c 55 esized from VALU
191a0 45 53 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 ES clause */.#de
191b0 66 69 6e 65 20 53 46 5f 4d 75 6c 74 69 56 61 6c fine SF_MultiVal
191c0 75 65 20 20 20 20 20 20 30 78 30 32 30 30 20 20 ue 0x0200
191d0 2f 2a 20 53 69 6e 67 6c 65 20 56 41 4c 55 45 53 /* Single VALUES
191e0 20 74 65 72 6d 20 77 69 74 68 20 6d 75 6c 74 69 term with multi
191f0 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 23 64 65 66 ple rows */.#def
19200 69 6e 65 20 53 46 5f 4e 65 73 74 65 64 46 72 6f ine SF_NestedFro
19210 6d 20 20 20 20 20 20 30 78 30 34 30 30 20 20 2f m 0x0400 /
19220 2a 20 50 61 72 74 20 6f 66 20 61 20 70 61 72 65 * Part of a pare
19230 6e 74 68 65 73 69 7a 65 64 20 46 52 4f 4d 20 63 nthesized FROM c
19240 6c 61 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 lause */.#define
19250 20 53 46 5f 4d 61 79 62 65 43 6f 6e 76 65 72 74 SF_MaybeConvert
19260 20 20 20 20 30 78 30 38 30 30 20 20 2f 2a 20 4e 0x0800 /* N
19270 65 65 64 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f eed convertCompo
19280 75 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 71 75 undSelectToSubqu
19290 65 72 79 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 ery() */.#define
192a0 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 20 20 SF_MinMaxAgg
192b0 20 20 20 20 30 78 31 30 30 30 20 20 2f 2a 20 41 0x1000 /* A
192c0 67 67 72 65 67 61 74 65 20 63 6f 6e 74 61 69 6e ggregate contain
192d0 69 6e 67 20 6d 69 6e 28 29 20 6f 72 20 6d 61 78 ing min() or max
192e0 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 () */.#define SF
192f0 5f 52 65 63 75 72 73 69 76 65 20 20 20 20 20 20 _Recursive
19300 20 30 78 32 30 30 30 20 20 2f 2a 20 54 68 65 20 0x2000 /* The
19310 72 65 63 75 72 73 69 76 65 20 70 61 72 74 20 6f recursive part o
19320 66 20 61 20 72 65 63 75 72 73 69 76 65 20 43 54 f a recursive CT
19330 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f E */.#define SF_
19340 43 6f 6e 76 65 72 74 65 64 20 20 20 20 20 20 20 Converted
19350 30 78 34 30 30 30 20 20 2f 2a 20 42 79 20 63 6f 0x4000 /* By co
19360 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c nvertCompoundSel
19370 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 ectToSubquery()
19380 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 72 */.../*.** The r
19390 65 73 75 6c 74 73 20 6f 66 20 61 20 53 45 4c 45 esults of a SELE
193a0 43 54 20 63 61 6e 20 62 65 20 64 69 73 74 72 69 CT can be distri
193b0 62 75 74 65 64 20 69 6e 20 73 65 76 65 72 61 6c buted in several
193c0 20 77 61 79 73 2c 20 61 73 20 64 65 66 69 6e 65 ways, as define
193d0 64 0a 2a 2a 20 62 79 20 6f 6e 65 20 6f 66 20 74 d.** by one of t
193e0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 he following mac
193f0 72 6f 73 2e 20 20 54 68 65 20 22 53 52 54 22 20 ros. The "SRT"
19400 70 72 65 66 69 78 20 6d 65 61 6e 73 20 22 53 45 prefix means "SE
19410 4c 45 43 54 20 52 65 73 75 6c 74 0a 2a 2a 20 54 LECT Result.** T
19420 79 70 65 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ype"..**.**
19430 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 20 20 20 SRT_Union
19440 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 61 73 Store results as
19450 20 61 20 6b 65 79 20 69 6e 20 61 20 74 65 6d 70 a key in a temp
19460 6f 72 61 72 79 20 69 6e 64 65 78 20 0a 2a 2a 20 orary index .**
19470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19480 20 20 20 20 69 64 65 6e 74 69 66 69 65 64 20 62 identified b
19490 79 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d y pDest->iSDParm
194a0 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
194b0 45 78 63 65 70 74 20 20 20 20 20 20 52 65 6d 6f Except Remo
194c0 76 65 20 72 65 73 75 6c 74 73 20 66 72 6f 6d 20 ve results from
194d0 74 68 65 20 74 65 6d 70 6f 72 61 72 79 20 69 6e the temporary in
194e0 64 65 78 20 70 44 65 73 74 2d 3e 69 53 44 50 61 dex pDest->iSDPa
194f0 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 rm..**.** SR
19500 54 5f 45 78 69 73 74 73 20 20 20 20 20 20 53 74 T_Exists St
19510 6f 72 65 20 61 20 31 20 69 6e 20 6d 65 6d 6f 72 ore a 1 in memor
19520 79 20 63 65 6c 6c 20 70 44 65 73 74 2d 3e 69 53 y cell pDest->iS
19530 44 50 61 72 6d 20 69 66 20 74 68 65 20 72 65 73 DParm if the res
19540 75 6c 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ult.**
19550 20 20 20 20 20 20 20 20 20 20 20 73 65 74 20 69 set i
19560 73 20 6e 6f 74 20 65 6d 70 74 79 2e 0a 2a 2a 0a s not empty..**.
19570 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 73 63 61 ** SRT_Disca
19580 72 64 20 20 20 20 20 54 68 72 6f 77 20 74 68 65 rd Throw the
19590 20 72 65 73 75 6c 74 73 20 61 77 61 79 2e 20 20 results away.
195a0 54 68 69 73 20 69 73 20 75 73 65 64 20 62 79 20 This is used by
195b0 53 45 4c 45 43 54 0a 2a 2a 20 20 20 20 20 20 20 SELECT.**
195c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 74 st
195d0 61 74 65 6d 65 6e 74 73 20 77 69 74 68 69 6e 20 atements within
195e0 74 72 69 67 67 65 72 73 20 77 68 6f 73 65 20 6f triggers whose o
195f0 6e 6c 79 20 70 75 72 70 6f 73 65 20 69 73 0a 2a nly purpose is.*
19600 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
19610 20 20 20 20 20 20 74 68 65 20 73 69 64 65 2d 65 the side-e
19620 66 66 65 63 74 73 20 6f 66 20 66 75 6e 63 74 69 ffects of functi
19630 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f ons..**.** All o
19640 66 20 74 68 65 20 61 62 6f 76 65 20 61 72 65 20 f the above are
19650 66 72 65 65 20 74 6f 20 69 67 6e 6f 72 65 20 74 free to ignore t
19660 68 65 69 72 20 4f 52 44 45 52 20 42 59 20 63 6c heir ORDER BY cl
19670 61 75 73 65 2e 20 54 68 6f 73 65 20 74 68 61 74 ause. Those that
19680 0a 2a 2a 20 66 6f 6c 6c 6f 77 20 6d 75 73 74 20 .** follow must
19690 68 6f 6e 6f 72 20 74 68 65 20 4f 52 44 45 52 20 honor the ORDER
196a0 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2a 0a 2a 2a BY clause..**.**
196b0 20 20 20 20 20 53 52 54 5f 4f 75 74 70 75 74 20 SRT_Output
196c0 20 20 20 20 20 47 65 6e 65 72 61 74 65 20 61 20 Generate a
196d0 72 6f 77 20 6f 66 20 6f 75 74 70 75 74 20 28 75 row of output (u
196e0 73 69 6e 67 20 74 68 65 20 4f 50 5f 52 65 73 75 sing the OP_Resu
196f0 6c 74 52 6f 77 0a 2a 2a 20 20 20 20 20 20 20 20 ltRow.**
19700 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 70 63 opc
19710 6f 64 65 29 20 66 6f 72 20 65 61 63 68 20 72 6f ode) for each ro
19720 77 20 69 6e 20 74 68 65 20 72 65 73 75 6c 74 20 w in the result
19730 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 set..**.** S
19740 52 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 20 4f RT_Mem O
19750 6e 6c 79 20 76 61 6c 69 64 20 69 66 20 74 68 65 nly valid if the
19760 20 72 65 73 75 6c 74 20 69 73 20 61 20 73 69 6e result is a sin
19770 67 6c 65 20 63 6f 6c 75 6d 6e 2e 0a 2a 2a 20 20 gle column..**
19780 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19790 20 20 20 53 74 6f 72 65 20 74 68 65 20 66 69 72 Store the fir
197a0 73 74 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 68 65 st column of the
197b0 20 66 69 72 73 74 20 72 65 73 75 6c 74 20 72 6f first result ro
197c0 77 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 w.**
197d0 20 20 20 20 20 20 20 20 20 69 6e 20 72 65 67 69 in regi
197e0 73 74 65 72 20 70 44 65 73 74 2d 3e 69 53 44 50 ster pDest->iSDP
197f0 61 72 6d 20 74 68 65 6e 20 61 62 61 6e 64 6f 6e arm then abandon
19800 20 74 68 65 20 72 65 73 74 0a 2a 2a 20 20 20 20 the rest.**
19810 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19820 20 6f 66 20 74 68 65 20 71 75 65 72 79 2e 20 20 of the query.
19830 54 68 69 73 20 64 65 73 74 69 6e 61 74 69 6f 6e This destination
19840 20 69 6d 70 6c 69 65 73 20 22 4c 49 4d 49 54 20 implies "LIMIT
19850 31 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 1"..**.** SR
19860 54 5f 53 65 74 20 20 20 20 20 20 20 20 20 54 68 T_Set Th
19870 65 20 72 65 73 75 6c 74 20 6d 75 73 74 20 62 65 e result must be
19880 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c 75 6d 6e a single column
19890 2e 20 20 53 74 6f 72 65 20 65 61 63 68 0a 2a 2a . Store each.**
198a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
198b0 20 20 20 20 20 72 6f 77 20 6f 66 20 72 65 73 75 row of resu
198c0 6c 74 20 61 73 20 74 68 65 20 6b 65 79 20 69 6e lt as the key in
198d0 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 table pDest->iS
198e0 44 50 61 72 6d 2e 20 0a 2a 2a 20 20 20 20 20 20 DParm. .**
198f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 41 A
19900 70 70 6c 79 20 74 68 65 20 61 66 66 69 6e 69 74 pply the affinit
19910 79 20 70 44 65 73 74 2d 3e 61 66 66 53 64 73 74 y pDest->affSdst
19920 20 62 65 66 6f 72 65 20 73 74 6f 72 69 6e 67 0a before storing.
19930 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
19940 20 20 20 20 20 20 20 72 65 73 75 6c 74 73 2e 20 results.
19950 20 55 73 65 64 20 74 6f 20 69 6d 70 6c 65 6d 65 Used to impleme
19960 6e 74 20 22 49 4e 20 28 53 45 4c 45 43 54 20 2e nt "IN (SELECT .
19970 2e 2e 29 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ..)"..**.**
19980 53 52 54 5f 45 70 68 65 6d 54 61 62 20 20 20 20 SRT_EphemTab
19990 43 72 65 61 74 65 20 61 6e 20 74 65 6d 70 6f 72 Create an tempor
199a0 61 72 79 20 74 61 62 6c 65 20 70 44 65 73 74 2d ary table pDest-
199b0 3e 69 53 44 50 61 72 6d 20 61 6e 64 20 73 74 6f >iSDParm and sto
199c0 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 re.**
199d0 20 20 20 20 20 20 20 20 20 20 74 68 65 20 72 65 the re
199e0 73 75 6c 74 20 74 68 65 72 65 2e 20 54 68 65 20 sult there. The
199f0 63 75 72 73 6f 72 20 69 73 20 6c 65 66 74 20 6f cursor is left o
19a00 70 65 6e 20 61 66 74 65 72 0a 2a 2a 20 20 20 20 pen after.**
19a10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19a20 20 72 65 74 75 72 6e 69 6e 67 2e 20 20 54 68 69 returning. Thi
19a30 73 20 69 73 20 6c 69 6b 65 20 53 52 54 5f 54 61 s is like SRT_Ta
19a40 62 6c 65 20 65 78 63 65 70 74 20 74 68 61 74 0a ble except that.
19a50 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
19a60 20 20 20 20 20 20 20 74 68 69 73 20 64 65 73 74 this dest
19a70 69 6e 61 74 69 6f 6e 20 75 73 65 73 20 4f 50 5f ination uses OP_
19a80 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 74 6f OpenEphemeral to
19a90 20 63 72 65 61 74 65 0a 2a 2a 20 20 20 20 20 20 create.**
19aa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
19ab0 68 65 20 74 61 62 6c 65 20 66 69 72 73 74 2e 0a he table first..
19ac0 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 43 6f **.** SRT_Co
19ad0 72 6f 75 74 69 6e 65 20 20 20 47 65 6e 65 72 61 routine Genera
19ae0 74 65 20 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 te a co-routine
19af0 74 68 61 74 20 72 65 74 75 72 6e 73 20 61 20 6e that returns a n
19b00 65 77 20 72 6f 77 20 6f 66 0a 2a 2a 20 20 20 20 ew row of.**
19b10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19b20 20 72 65 73 75 6c 74 73 20 65 61 63 68 20 74 69 results each ti
19b30 6d 65 20 69 74 20 69 73 20 69 6e 76 6f 6b 65 64 me it is invoked
19b40 2e 20 20 54 68 65 20 65 6e 74 72 79 20 70 6f 69 . The entry poi
19b50 6e 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 nt.**
19b60 20 20 20 20 20 20 20 20 20 20 6f 66 20 74 68 65 of the
19b70 20 63 6f 2d 72 6f 75 74 69 6e 65 20 69 73 20 73 co-routine is s
19b80 74 6f 72 65 64 20 69 6e 20 72 65 67 69 73 74 65 tored in registe
19b90 72 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d r pDest->iSDParm
19ba0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
19bb0 20 20 20 20 20 20 20 20 61 6e 64 20 74 68 65 20 and the
19bc0 72 65 73 75 6c 74 20 72 6f 77 20 69 73 20 73 74 result row is st
19bd0 6f 72 65 64 20 69 6e 20 70 44 65 73 74 2d 3e 6e ored in pDest->n
19be0 44 65 73 74 20 72 65 67 69 73 74 65 72 73 0a 2a Dest registers.*
19bf0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
19c00 20 20 20 20 20 20 73 74 61 72 74 69 6e 67 20 77 starting w
19c10 69 74 68 20 70 44 65 73 74 2d 3e 69 53 64 73 74 ith pDest->iSdst
19c20 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
19c30 54 61 62 6c 65 20 20 20 20 20 20 20 53 74 6f 72 Table Stor
19c40 65 20 72 65 73 75 6c 74 73 20 69 6e 20 74 65 6d e results in tem
19c50 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 porary table pDe
19c60 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 st->iSDParm..**
19c70 20 20 20 20 53 52 54 5f 46 69 66 6f 20 20 20 20 SRT_Fifo
19c80 20 20 20 20 54 68 69 73 20 69 73 20 6c 69 6b 65 This is like
19c90 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 65 78 SRT_EphemTab ex
19ca0 63 65 70 74 20 74 68 61 74 20 74 68 65 20 74 61 cept that the ta
19cb0 62 6c 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ble.**
19cc0 20 20 20 20 20 20 20 20 20 20 20 69 73 20 61 73 is as
19cd0 73 75 6d 65 64 20 74 6f 20 61 6c 72 65 61 64 79 sumed to already
19ce0 20 62 65 20 6f 70 65 6e 2e 20 20 53 52 54 5f 46 be open. SRT_F
19cf0 69 66 6f 20 68 61 73 0a 2a 2a 20 20 20 20 20 20 ifo has.**
19d00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
19d10 68 65 20 61 64 64 69 74 69 6f 6e 61 6c 20 70 72 he additional pr
19d20 6f 70 65 72 74 79 20 6f 66 20 62 65 69 6e 67 20 operty of being
19d30 61 62 6c 65 20 74 6f 20 69 67 6e 6f 72 65 0a 2a able to ignore.*
19d40 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
19d50 20 20 20 20 20 20 74 68 65 20 4f 52 44 45 52 20 the ORDER
19d60 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2a 0a 2a 2a BY clause..**.**
19d70 20 20 20 20 20 53 52 54 5f 44 69 73 74 46 69 66 SRT_DistFif
19d80 6f 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c o Store resul
19d90 74 73 20 69 6e 20 61 20 74 65 6d 70 6f 72 61 72 ts in a temporar
19da0 79 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 y table pDest->i
19db0 53 44 50 61 72 6d 2e 0a 2a 2a 20 20 20 20 20 20 SDParm..**
19dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 42 B
19dd0 75 74 20 61 6c 73 6f 20 75 73 65 20 74 65 6d 70 ut also use temp
19de0 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 73 orary table pDes
19df0 74 2d 3e 69 53 44 50 61 72 6d 2b 31 20 61 73 0a t->iSDParm+1 as.
19e00 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
19e10 20 20 20 20 20 20 20 61 20 72 65 63 6f 72 64 20 a record
19e20 6f 66 20 61 6c 6c 20 70 72 69 6f 72 20 72 65 73 of all prior res
19e30 75 6c 74 73 20 61 6e 64 20 69 67 6e 6f 72 65 20 ults and ignore
19e40 61 6e 79 20 64 75 70 6c 69 63 61 74 65 0a 2a 2a any duplicate.**
19e50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19e60 20 20 20 20 20 72 6f 77 73 2e 20 20 4e 61 6d 65 rows. Name
19e70 20 6d 65 61 6e 73 3a 20 20 22 44 69 73 74 69 6e means: "Distin
19e80 63 74 20 46 69 66 6f 22 2e 0a 2a 2a 0a 2a 2a 20 ct Fifo"..**.**
19e90 20 20 20 20 53 52 54 5f 51 75 65 75 65 20 20 20 SRT_Queue
19ea0 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 Store result
19eb0 73 20 69 6e 20 70 72 69 6f 72 69 74 79 20 71 75 s in priority qu
19ec0 65 75 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 eue pDest->iSDPa
19ed0 72 6d 20 28 72 65 61 6c 6c 79 0a 2a 2a 20 20 20 rm (really.**
19ee0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19ef0 20 20 61 6e 20 69 6e 64 65 78 29 2e 20 20 41 70 an index). Ap
19f00 70 65 6e 64 20 61 20 73 65 71 75 65 6e 63 65 20 pend a sequence
19f10 6e 75 6d 62 65 72 20 73 6f 20 74 68 61 74 20 61 number so that a
19f20 6c 6c 20 65 6e 74 72 69 65 73 0a 2a 2a 20 20 20 ll entries.**
19f30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19f40 20 20 61 72 65 20 64 69 73 74 69 6e 63 74 2e 0a are distinct..
19f50 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 **.** SRT_Di
19f60 73 74 51 75 65 75 65 20 20 20 53 74 6f 72 65 20 stQueue Store
19f70 72 65 73 75 6c 74 73 20 69 6e 20 70 72 69 6f 72 results in prior
19f80 69 74 79 20 71 75 65 75 65 20 70 44 65 73 74 2d ity queue pDest-
19f90 3e 69 53 44 50 61 72 6d 20 6f 6e 6c 79 20 69 66 >iSDParm only if
19fa0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
19fb0 20 20 20 20 20 20 20 20 74 68 65 20 73 61 6d 65 the same
19fc0 20 72 65 63 6f 72 64 20 68 61 73 20 6e 65 76 65 record has neve
19fd0 72 20 62 65 65 6e 20 73 74 6f 72 65 64 20 62 65 r been stored be
19fe0 66 6f 72 65 2e 20 20 54 68 65 0a 2a 2a 20 20 20 fore. The.**
19ff0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a000 20 20 69 6e 64 65 78 20 61 74 20 70 44 65 73 74 index at pDest
1a010 2d 3e 69 53 44 50 61 72 6d 2b 31 20 68 6f 6c 64 ->iSDParm+1 hold
1a020 20 61 6c 6c 20 70 72 69 6f 72 20 73 74 6f 72 65 all prior store
1a030 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 s..*/.#define SR
1a040 54 5f 55 6e 69 6f 6e 20 20 20 20 20 20 20 20 31 T_Union 1
1a050 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
1a060 74 20 61 73 20 6b 65 79 73 20 69 6e 20 61 6e 20 t as keys in an
1a070 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 index */.#define
1a080 20 53 52 54 5f 45 78 63 65 70 74 20 20 20 20 20 SRT_Except
1a090 20 20 32 20 20 2f 2a 20 52 65 6d 6f 76 65 20 72 2 /* Remove r
1a0a0 65 73 75 6c 74 20 66 72 6f 6d 20 61 20 55 4e 49 esult from a UNI
1a0b0 4f 4e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 ON index */.#def
1a0c0 69 6e 65 20 53 52 54 5f 45 78 69 73 74 73 20 20 ine SRT_Exists
1a0d0 20 20 20 20 20 33 20 20 2f 2a 20 53 74 6f 72 65 3 /* Store
1a0e0 20 31 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 1 if the result
1a0f0 20 69 73 20 6e 6f 74 20 65 6d 70 74 79 20 2a 2f is not empty */
1a100 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 44 69 73 .#define SRT_Dis
1a110 63 61 72 64 20 20 20 20 20 20 34 20 20 2f 2a 20 card 4 /*
1a120 44 6f 20 6e 6f 74 20 73 61 76 65 20 74 68 65 20 Do not save the
1a130 72 65 73 75 6c 74 73 20 61 6e 79 77 68 65 72 65 results anywhere
1a140 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f */.#define SRT_
1a150 46 69 66 6f 20 20 20 20 20 20 20 20 20 35 20 20 Fifo 5
1a160 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 /* Store result
1a170 61 73 20 64 61 74 61 20 77 69 74 68 20 61 6e 20 as data with an
1a180 61 75 74 6f 6d 61 74 69 63 20 72 6f 77 69 64 20 automatic rowid
1a190 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 44 */.#define SRT_D
1a1a0 69 73 74 46 69 66 6f 20 20 20 20 20 36 20 20 2f istFifo 6 /
1a1b0 2a 20 4c 69 6b 65 20 53 52 54 5f 46 69 66 6f 2c * Like SRT_Fifo,
1a1c0 20 62 75 74 20 75 6e 69 71 75 65 20 72 65 73 75 but unique resu
1a1d0 6c 74 73 20 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 lts only */.#def
1a1e0 69 6e 65 20 53 52 54 5f 51 75 65 75 65 20 20 20 ine SRT_Queue
1a1f0 20 20 20 20 20 37 20 20 2f 2a 20 53 74 6f 72 65 7 /* Store
1a200 20 72 65 73 75 6c 74 20 69 6e 20 61 6e 20 71 75 result in an qu
1a210 65 75 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 eue */.#define S
1a220 52 54 5f 44 69 73 74 51 75 65 75 65 20 20 20 20 RT_DistQueue
1a230 38 20 20 2f 2a 20 4c 69 6b 65 20 53 52 54 5f 51 8 /* Like SRT_Q
1a240 75 65 75 65 2c 20 62 75 74 20 75 6e 69 71 75 65 ueue, but unique
1a250 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 2a 2f results only */
1a260 0a 0a 2f 2a 20 54 68 65 20 4f 52 44 45 52 20 42 ../* The ORDER B
1a270 59 20 63 6c 61 75 73 65 20 69 73 20 69 67 6e 6f Y clause is igno
1a280 72 65 64 20 66 6f 72 20 61 6c 6c 20 6f 66 20 74 red for all of t
1a290 68 65 20 61 62 6f 76 65 20 2a 2f 0a 23 64 65 66 he above */.#def
1a2a0 69 6e 65 20 49 67 6e 6f 72 61 62 6c 65 4f 72 64 ine IgnorableOrd
1a2b0 65 72 62 79 28 58 29 20 28 28 58 2d 3e 65 44 65 erby(X) ((X->eDe
1a2c0 73 74 29 3c 3d 53 52 54 5f 44 69 73 74 51 75 65 st)<=SRT_DistQue
1a2d0 75 65 29 0a 0a 23 64 65 66 69 6e 65 20 53 52 54 ue)..#define SRT
1a2e0 5f 4f 75 74 70 75 74 20 20 20 20 20 20 20 39 20 _Output 9
1a2f0 20 2f 2a 20 4f 75 74 70 75 74 20 65 61 63 68 20 /* Output each
1a300 72 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 2a 2f row of result */
1a310 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 4d 65 6d .#define SRT_Mem
1a320 20 20 20 20 20 20 20 20 20 31 30 20 20 2f 2a 20 10 /*
1a330 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e 20 Store result in
1a340 61 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 2a 2f a memory cell */
1a350 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 53 65 74 .#define SRT_Set
1a360 20 20 20 20 20 20 20 20 20 31 31 20 20 2f 2a 20 11 /*
1a370 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 61 73 Store results as
1a380 20 6b 65 79 73 20 69 6e 20 61 6e 20 69 6e 64 65 keys in an inde
1a390 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 x */.#define SRT
1a3a0 5f 45 70 68 65 6d 54 61 62 20 20 20 20 31 32 20 _EphemTab 12
1a3b0 20 2f 2a 20 43 72 65 61 74 65 20 74 72 61 6e 73 /* Create trans
1a3c0 69 65 6e 74 20 74 61 62 20 61 6e 64 20 73 74 6f ient tab and sto
1a3d0 72 65 20 6c 69 6b 65 20 53 52 54 5f 54 61 62 6c re like SRT_Tabl
1a3e0 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 e */.#define SRT
1a3f0 5f 43 6f 72 6f 75 74 69 6e 65 20 20 20 31 33 20 _Coroutine 13
1a400 20 2f 2a 20 47 65 6e 65 72 61 74 65 20 61 20 73 /* Generate a s
1a410 69 6e 67 6c 65 20 72 6f 77 20 6f 66 20 72 65 73 ingle row of res
1a420 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ult */.#define S
1a430 52 54 5f 54 61 62 6c 65 20 20 20 20 20 20 20 31 RT_Table 1
1a440 34 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 4 /* Store resu
1a450 6c 74 20 61 73 20 64 61 74 61 20 77 69 74 68 20 lt as data with
1a460 61 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 6f 77 an automatic row
1a470 69 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 id */../*.** An
1a480 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 instance of this
1a490 20 6f 62 6a 65 63 74 20 64 65 73 63 72 69 62 65 object describe
1a4a0 73 20 77 68 65 72 65 20 74 6f 20 70 75 74 20 6f s where to put o
1a4b0 66 20 74 68 65 20 72 65 73 75 6c 74 73 20 6f 66 f the results of
1a4c0 0a 2a 2a 20 61 20 53 45 4c 45 43 54 20 73 74 61 .** a SELECT sta
1a4d0 74 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 72 75 63 tement..*/.struc
1a4e0 74 20 53 65 6c 65 63 74 44 65 73 74 20 7b 0a 20 t SelectDest {.
1a4f0 20 75 38 20 65 44 65 73 74 3b 20 20 20 20 20 20 u8 eDest;
1a500 20 20 20 20 20 20 2f 2a 20 48 6f 77 20 74 6f 20 /* How to
1a510 64 69 73 70 6f 73 65 20 6f 66 20 74 68 65 20 72 dispose of the r
1a520 65 73 75 6c 74 73 2e 20 20 4f 6e 20 6f 66 20 53 esults. On of S
1a530 52 54 5f 2a 20 61 62 6f 76 65 2e 20 2a 2f 0a 20 RT_* above. */.
1a540 20 63 68 61 72 20 61 66 66 53 64 73 74 3b 20 20 char affSdst;
1a550 20 20 20 20 20 20 2f 2a 20 41 66 66 69 6e 69 74 /* Affinit
1a560 79 20 75 73 65 64 20 77 68 65 6e 20 65 44 65 73 y used when eDes
1a570 74 3d 3d 53 52 54 5f 53 65 74 20 2a 2f 0a 20 20 t==SRT_Set */.
1a580 69 6e 74 20 69 53 44 50 61 72 6d 3b 20 20 20 20 int iSDParm;
1a590 20 20 20 20 20 2f 2a 20 41 20 70 61 72 61 6d 65 /* A parame
1a5a0 74 65 72 20 75 73 65 64 20 62 79 20 74 68 65 20 ter used by the
1a5b0 65 44 65 73 74 20 64 69 73 70 6f 73 61 6c 20 6d eDest disposal m
1a5c0 65 74 68 6f 64 20 2a 2f 0a 20 20 69 6e 74 20 69 ethod */. int i
1a5d0 53 64 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 Sdst;
1a5e0 2f 2a 20 42 61 73 65 20 72 65 67 69 73 74 65 72 /* Base register
1a5f0 20 77 68 65 72 65 20 72 65 73 75 6c 74 73 20 61 where results a
1a600 72 65 20 77 72 69 74 74 65 6e 20 2a 2f 0a 20 20 re written */.
1a610 69 6e 74 20 6e 53 64 73 74 3b 20 20 20 20 20 20 int nSdst;
1a620 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1a630 66 20 72 65 67 69 73 74 65 72 73 20 61 6c 6c 6f f registers allo
1a640 63 61 74 65 64 20 2a 2f 0a 20 20 45 78 70 72 4c cated */. ExprL
1a650 69 73 74 20 2a 70 4f 72 64 65 72 42 79 3b 20 20 ist *pOrderBy;
1a660 2f 2a 20 4b 65 79 20 63 6f 6c 75 6d 6e 73 20 66 /* Key columns f
1a670 6f 72 20 53 52 54 5f 51 75 65 75 65 20 61 6e 64 or SRT_Queue and
1a680 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 20 2a SRT_DistQueue *
1a690 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 44 75 72 69 /.};../*.** Duri
1a6a0 6e 67 20 63 6f 64 65 20 67 65 6e 65 72 61 74 69 ng code generati
1a6b0 6f 6e 20 6f 66 20 73 74 61 74 65 6d 65 6e 74 73 on of statements
1a6c0 20 74 68 61 74 20 64 6f 20 69 6e 73 65 72 74 73 that do inserts
1a6d0 20 69 6e 74 6f 20 41 55 54 4f 49 4e 43 52 45 4d into AUTOINCREM
1a6e0 45 4e 54 20 0a 2a 2a 20 74 61 62 6c 65 73 2c 20 ENT .** tables,
1a6f0 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 69 6e the following in
1a700 66 6f 72 6d 61 74 69 6f 6e 20 69 73 20 61 74 74 formation is att
1a710 61 63 68 65 64 20 74 6f 20 74 68 65 20 54 61 62 ached to the Tab
1a720 6c 65 2e 75 2e 61 75 74 6f 49 6e 63 2e 70 0a 2a le.u.autoInc.p.*
1a730 2a 20 70 6f 69 6e 74 65 72 20 6f 66 20 65 61 63 * pointer of eac
1a740 68 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 h autoincrement
1a750 74 61 62 6c 65 20 74 6f 20 72 65 63 6f 72 64 20 table to record
1a760 73 6f 6d 65 20 73 69 64 65 20 69 6e 66 6f 72 6d some side inform
1a770 61 74 69 6f 6e 20 74 68 61 74 0a 2a 2a 20 74 68 ation that.** th
1a780 65 20 63 6f 64 65 20 67 65 6e 65 72 61 74 6f 72 e code generator
1a790 20 6e 65 65 64 73 2e 20 20 57 65 20 68 61 76 65 needs. We have
1a7a0 20 74 6f 20 6b 65 65 70 20 70 65 72 2d 74 61 62 to keep per-tab
1a7b0 6c 65 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 le autoincrement
1a7c0 0a 2a 2a 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 .** information
1a7d0 69 6e 20 63 61 73 65 20 69 6e 73 65 72 74 73 20 in case inserts
1a7e0 61 72 65 20 64 6f 77 6e 20 77 69 74 68 69 6e 20 are down within
1a7f0 74 72 69 67 67 65 72 73 2e 20 20 54 72 69 67 67 triggers. Trigg
1a800 65 72 73 20 64 6f 20 6e 6f 74 0a 2a 2a 20 6e 6f ers do not.** no
1a810 72 6d 61 6c 6c 79 20 63 6f 6f 72 64 69 6e 61 74 rmally coordinat
1a820 65 20 74 68 65 69 72 20 61 63 74 69 76 69 74 69 e their activiti
1a830 65 73 2c 20 62 75 74 20 77 65 20 64 6f 20 6e 65 es, but we do ne
1a840 65 64 20 74 6f 20 63 6f 6f 72 64 69 6e 61 74 65 ed to coordinate
1a850 20 74 68 65 0a 2a 2a 20 6c 6f 61 64 69 6e 67 20 the.** loading
1a860 61 6e 64 20 73 61 76 69 6e 67 20 6f 66 20 61 75 and saving of au
1a870 74 6f 69 6e 63 72 65 6d 65 6e 74 20 69 6e 66 6f toincrement info
1a880 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 rmation..*/.stru
1a890 63 74 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 7b ct AutoincInfo {
1a8a0 0a 20 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 2a . AutoincInfo *
1a8b0 70 4e 65 78 74 3b 20 20 20 2f 2a 20 4e 65 78 74 pNext; /* Next
1a8c0 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 69 6e 20 61 info block in a
1a8d0 20 6c 69 73 74 20 6f 66 20 74 68 65 6d 20 61 6c list of them al
1a8e0 6c 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 54 l */. Table *pT
1a8f0 61 62 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ab; /*
1a900 54 61 62 6c 65 20 74 68 69 73 20 69 6e 66 6f 20 Table this info
1a910 62 6c 6f 63 6b 20 72 65 66 65 72 73 20 74 6f 20 block refers to
1a920 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b 20 20 20 */. int iDb;
1a930 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e /* In
1a940 64 65 78 20 69 6e 20 73 71 6c 69 74 65 33 2e 61 dex in sqlite3.a
1a950 44 62 5b 5d 20 6f 66 20 64 61 74 61 62 61 73 65 Db[] of database
1a960 20 68 6f 6c 64 69 6e 67 20 70 54 61 62 20 2a 2f holding pTab */
1a970 0a 20 20 69 6e 74 20 72 65 67 43 74 72 3b 20 20 . int regCtr;
1a980 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 6d 6f /* Memo
1a990 72 79 20 72 65 67 69 73 74 65 72 20 68 6f 6c 64 ry register hold
1a9a0 69 6e 67 20 74 68 65 20 72 6f 77 69 64 20 63 6f ing the rowid co
1a9b0 75 6e 74 65 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a unter */.};../*.
1a9c0 2a 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 20 63 ** Size of the c
1a9d0 6f 6c 75 6d 6e 20 63 61 63 68 65 0a 2a 2f 0a 23 olumn cache.*/.#
1a9e0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4e 5f ifndef SQLITE_N_
1a9f0 43 4f 4c 43 41 43 48 45 0a 23 20 64 65 66 69 6e COLCACHE.# defin
1aa00 65 20 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 e SQLITE_N_COLCA
1aa10 43 48 45 20 31 30 0a 23 65 6e 64 69 66 0a 0a 2f CHE 10.#endif../
1aa20 2a 0a 2a 2a 20 41 74 20 6c 65 61 73 74 20 6f 6e *.** At least on
1aa30 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 e instance of th
1aa40 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
1aa50 63 74 75 72 65 20 69 73 20 63 72 65 61 74 65 64 cture is created
1aa60 20 66 6f 72 20 65 61 63 68 20 0a 2a 2a 20 74 72 for each .** tr
1aa70 69 67 67 65 72 20 74 68 61 74 20 6d 61 79 20 62 igger that may b
1aa80 65 20 66 69 72 65 64 20 77 68 69 6c 65 20 70 61 e fired while pa
1aa90 72 73 69 6e 67 20 61 6e 20 49 4e 53 45 52 54 2c rsing an INSERT,
1aaa0 20 55 50 44 41 54 45 20 6f 72 20 44 45 4c 45 54 UPDATE or DELET
1aab0 45 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 2e 20 E.** statement.
1aac0 41 6c 6c 20 73 75 63 68 20 6f 62 6a 65 63 74 73 All such objects
1aad0 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 74 are stored in t
1aae0 68 65 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 68 he linked list h
1aaf0 65 61 64 65 64 20 61 74 0a 2a 2a 20 50 61 72 73 eaded at.** Pars
1ab00 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 61 6e e.pTriggerPrg an
1ab10 64 20 64 65 6c 65 74 65 64 20 6f 6e 63 65 20 73 d deleted once s
1ab20 74 61 74 65 6d 65 6e 74 20 63 6f 6d 70 69 6c 61 tatement compila
1ab30 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 0a 2a 2a tion has been.**
1ab40 20 63 6f 6d 70 6c 65 74 65 64 2e 0a 2a 2a 0a 2a completed..**.*
1ab50 2a 20 41 20 56 64 62 65 20 73 75 62 2d 70 72 6f * A Vdbe sub-pro
1ab60 67 72 61 6d 20 74 68 61 74 20 69 6d 70 6c 65 6d gram that implem
1ab70 65 6e 74 73 20 74 68 65 20 62 6f 64 79 20 61 6e ents the body an
1ab80 64 20 57 48 45 4e 20 63 6c 61 75 73 65 20 6f 66 d WHEN clause of
1ab90 20 74 72 69 67 67 65 72 0a 2a 2a 20 54 72 69 67 trigger.** Trig
1aba0 67 65 72 50 72 67 2e 70 54 72 69 67 67 65 72 2c gerPrg.pTrigger,
1abb0 20 61 73 73 75 6d 69 6e 67 20 61 20 64 65 66 61 assuming a defa
1abc0 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 ult ON CONFLICT
1abd0 63 6c 61 75 73 65 20 6f 66 0a 2a 2a 20 54 72 69 clause of.** Tri
1abe0 67 67 65 72 50 72 67 2e 6f 72 63 6f 6e 66 2c 20 ggerPrg.orconf,
1abf0 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 is stored in the
1ac00 20 54 72 69 67 67 65 72 50 72 67 2e 70 50 72 6f TriggerPrg.pPro
1ac10 67 72 61 6d 20 76 61 72 69 61 62 6c 65 2e 0a 2a gram variable..*
1ac20 2a 20 54 68 65 20 50 61 72 73 65 2e 70 54 72 69 * The Parse.pTri
1ac30 67 67 65 72 50 72 67 20 6c 69 73 74 20 6e 65 76 ggerPrg list nev
1ac40 65 72 20 63 6f 6e 74 61 69 6e 73 20 74 77 6f 20 er contains two
1ac50 65 6e 74 72 69 65 73 20 77 69 74 68 20 74 68 65 entries with the
1ac60 20 73 61 6d 65 0a 2a 2a 20 76 61 6c 75 65 73 20 same.** values
1ac70 66 6f 72 20 62 6f 74 68 20 70 54 72 69 67 67 65 for both pTrigge
1ac80 72 20 61 6e 64 20 6f 72 63 6f 6e 66 2e 0a 2a 2a r and orconf..**
1ac90 0a 2a 2a 20 54 68 65 20 54 72 69 67 67 65 72 50 .** The TriggerP
1aca0 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b 30 5d 20 76 rg.aColmask[0] v
1acb0 61 72 69 61 62 6c 65 20 69 73 20 73 65 74 20 74 ariable is set t
1acc0 6f 20 61 20 6d 61 73 6b 20 6f 66 20 6f 6c 64 2e o a mask of old.
1acd0 2a 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 61 63 63 * columns.** acc
1ace0 65 73 73 65 64 20 28 6f 72 20 73 65 74 20 74 6f essed (or set to
1acf0 20 30 20 66 6f 72 20 74 72 69 67 67 65 72 73 20 0 for triggers
1ad00 66 69 72 65 64 20 61 73 20 61 20 72 65 73 75 6c fired as a resul
1ad10 74 20 6f 66 20 49 4e 53 45 52 54 20 0a 2a 2a 20 t of INSERT .**
1ad20 73 74 61 74 65 6d 65 6e 74 73 29 2e 20 53 69 6d statements). Sim
1ad30 69 6c 61 72 6c 79 2c 20 74 68 65 20 54 72 69 67 ilarly, the Trig
1ad40 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b gerPrg.aColmask[
1ad50 31 5d 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 1] variable is s
1ad60 65 74 20 74 6f 0a 2a 2a 20 61 20 6d 61 73 6b 20 et to.** a mask
1ad70 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d 6e 73 of new.* columns
1ad80 20 75 73 65 64 20 62 79 20 74 68 65 20 70 72 6f used by the pro
1ad90 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 gram..*/.struct
1ada0 54 72 69 67 67 65 72 50 72 67 20 7b 0a 20 20 54 TriggerPrg {. T
1adb0 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 65 72 rigger *pTrigger
1adc0 3b 20 20 20 20 20 20 2f 2a 20 54 72 69 67 67 65 ; /* Trigge
1add0 72 20 74 68 69 73 20 70 72 6f 67 72 61 6d 20 77 r this program w
1ade0 61 73 20 63 6f 64 65 64 20 66 72 6f 6d 20 2a 2f as coded from */
1adf0 0a 20 20 54 72 69 67 67 65 72 50 72 67 20 2a 70 . TriggerPrg *p
1ae00 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 4e 65 Next; /* Ne
1ae10 78 74 20 65 6e 74 72 79 20 69 6e 20 50 61 72 73 xt entry in Pars
1ae20 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 6c 69 e.pTriggerPrg li
1ae30 73 74 20 2a 2f 0a 20 20 53 75 62 50 72 6f 67 72 st */. SubProgr
1ae40 61 6d 20 2a 70 50 72 6f 67 72 61 6d 3b 20 20 20 am *pProgram;
1ae50 2f 2a 20 50 72 6f 67 72 61 6d 20 69 6d 70 6c 65 /* Program imple
1ae60 6d 65 6e 74 69 6e 67 20 70 54 72 69 67 67 65 72 menting pTrigger
1ae70 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 20 69 6e 74 /orconf */. int
1ae80 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 orconf;
1ae90 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 /* Default
1aea0 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 70 6f 6c 69 ON CONFLICT poli
1aeb0 63 79 20 2a 2f 0a 20 20 75 33 32 20 61 43 6f 6c cy */. u32 aCol
1aec0 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 20 20 20 20 mask[2];
1aed0 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 6f 6c 64 2e /* Masks of old.
1aee0 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d 6e 73 *, new.* columns
1aef0 20 61 63 63 65 73 73 65 64 20 2a 2f 0a 7d 3b 0a accessed */.};.
1af00 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 44 62 4d 61 ./*.** The yDbMa
1af10 73 6b 20 64 61 74 61 74 79 70 65 20 66 6f 72 20 sk datatype for
1af20 74 68 65 20 62 69 74 6d 61 73 6b 20 6f 66 20 61 the bitmask of a
1af30 6c 6c 20 61 74 74 61 63 68 65 64 20 64 61 74 61 ll attached data
1af40 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 66 20 53 51 bases..*/.#if SQ
1af50 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 LITE_MAX_ATTACHE
1af60 44 3e 33 30 0a 20 20 74 79 70 65 64 65 66 20 75 D>30. typedef u
1af70 6e 73 69 67 6e 65 64 20 63 68 61 72 20 79 44 62 nsigned char yDb
1af80 4d 61 73 6b 5b 28 53 51 4c 49 54 45 5f 4d 41 58 Mask[(SQLITE_MAX
1af90 5f 41 54 54 41 43 48 45 44 2b 39 29 2f 38 5d 3b _ATTACHED+9)/8];
1afa0 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b .# define DbMask
1afb0 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 28 28 Test(M,I) (((
1afc0 4d 29 5b 28 49 29 2f 38 5d 26 28 31 3c 3c 28 28 M)[(I)/8]&(1<<((
1afd0 49 29 26 37 29 29 29 21 3d 30 29 0a 23 20 64 65 I)&7)))!=0).# de
1afe0 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 6f 28 fine DbMaskZero(
1aff0 4d 29 20 20 20 20 20 20 6d 65 6d 73 65 74 28 28 M) memset((
1b000 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 4d 29 29 0a M),0,sizeof(M)).
1b010 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 53 # define DbMaskS
1b020 65 74 28 4d 2c 49 29 20 20 20 20 20 28 4d 29 5b et(M,I) (M)[
1b030 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c 28 28 49 29 (I)/8]|=(1<<((I)
1b040 26 37 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 &7)).# define Db
1b050 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 20 20 MaskAllZero(M)
1b060 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c sqlite3DbMaskAl
1b070 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 65 66 69 6e lZero(M).# defin
1b080 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 6f 28 e DbMaskNonZero(
1b090 4d 29 20 20 20 28 73 71 6c 69 74 65 33 44 62 4d M) (sqlite3DbM
1b0a0 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 3d 3d 30 askAllZero(M)==0
1b0b0 29 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 64 65 ).#else. typede
1b0c0 66 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 79 f unsigned int y
1b0d0 44 62 4d 61 73 6b 3b 0a 23 20 64 65 66 69 6e 65 DbMask;.# define
1b0e0 20 44 62 4d 61 73 6b 54 65 73 74 28 4d 2c 49 29 DbMaskTest(M,I)
1b0f0 20 20 20 20 28 28 28 4d 29 26 28 28 28 79 44 62 (((M)&(((yDb
1b100 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 29 21 3d Mask)1)<<(I)))!=
1b110 30 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 0).# define DbMa
1b120 73 6b 5a 65 72 6f 28 4d 29 20 20 20 20 20 20 28 skZero(M) (
1b130 4d 29 3d 30 0a 23 20 64 65 66 69 6e 65 20 44 62 M)=0.# define Db
1b140 4d 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 MaskSet(M,I)
1b150 20 28 4d 29 7c 3d 28 28 28 79 44 62 4d 61 73 6b (M)|=(((yDbMask
1b160 29 31 29 3c 3c 28 49 29 29 0a 23 20 64 65 66 69 )1)<<(I)).# defi
1b170 6e 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f ne DbMaskAllZero
1b180 28 4d 29 20 20 20 28 4d 29 3d 3d 30 0a 23 20 64 (M) (M)==0.# d
1b190 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a efine DbMaskNonZ
1b1a0 65 72 6f 28 4d 29 20 20 20 28 4d 29 21 3d 30 0a ero(M) (M)!=0.
1b1b0 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e #endif../*.** An
1b1c0 20 53 51 4c 20 70 61 72 73 65 72 20 63 6f 6e 74 SQL parser cont
1b1d0 65 78 74 2e 20 20 41 20 63 6f 70 79 20 6f 66 20 ext. A copy of
1b1e0 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 69 this structure i
1b1f0 73 20 70 61 73 73 65 64 20 74 68 72 6f 75 67 68 s passed through
1b200 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 72 20 61 .** the parser a
1b210 6e 64 20 64 6f 77 6e 20 69 6e 74 6f 20 61 6c 6c nd down into all
1b220 20 74 68 65 20 70 61 72 73 65 72 20 61 63 74 69 the parser acti
1b230 6f 6e 20 72 6f 75 74 69 6e 65 20 69 6e 20 6f 72 on routine in or
1b240 64 65 72 20 74 6f 0a 2a 2a 20 63 61 72 72 79 20 der to.** carry
1b250 61 72 6f 75 6e 64 20 69 6e 66 6f 72 6d 61 74 69 around informati
1b260 6f 6e 20 74 68 61 74 20 69 73 20 67 6c 6f 62 61 on that is globa
1b270 6c 20 74 6f 20 74 68 65 20 65 6e 74 69 72 65 20 l to the entire
1b280 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 parse..**.** The
1b290 20 73 74 72 75 63 74 75 72 65 20 69 73 20 64 69 structure is di
1b2a0 76 69 64 65 64 20 69 6e 74 6f 20 74 77 6f 20 70 vided into two p
1b2b0 61 72 74 73 2e 20 20 57 68 65 6e 20 74 68 65 20 arts. When the
1b2c0 70 61 72 73 65 72 20 61 6e 64 20 63 6f 64 65 0a parser and code.
1b2d0 2a 2a 20 67 65 6e 65 72 61 74 65 20 63 61 6c 6c ** generate call
1b2e0 20 74 68 65 6d 73 65 6c 76 65 73 20 72 65 63 75 themselves recu
1b2f0 72 73 69 76 65 6c 79 2c 20 74 68 65 20 66 69 72 rsively, the fir
1b300 73 74 20 70 61 72 74 20 6f 66 20 74 68 65 20 73 st part of the s
1b310 74 72 75 63 74 75 72 65 0a 2a 2a 20 69 73 20 63 tructure.** is c
1b320 6f 6e 73 74 61 6e 74 20 62 75 74 20 74 68 65 20 onstant but the
1b330 73 65 63 6f 6e 64 20 70 61 72 74 20 69 73 20 72 second part is r
1b340 65 73 65 74 20 61 74 20 74 68 65 20 62 65 67 69 eset at the begi
1b350 6e 6e 69 6e 67 20 61 6e 64 20 65 6e 64 20 6f 66 nning and end of
1b360 0a 2a 2a 20 65 61 63 68 20 72 65 63 75 72 73 69 .** each recursi
1b370 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6e 54 on..**.** The nT
1b380 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 20 61 54 61 ableLock and aTa
1b390 62 6c 65 4c 6f 63 6b 20 76 61 72 69 61 62 6c 65 bleLock variable
1b3a0 73 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 64 20 s are only used
1b3b0 69 66 20 74 68 65 20 73 68 61 72 65 64 2d 63 61 if the shared-ca
1b3c0 63 68 65 20 0a 2a 2a 20 66 65 61 74 75 72 65 20 che .** feature
1b3d0 69 73 20 65 6e 61 62 6c 65 64 20 28 69 66 20 73 is enabled (if s
1b3e0 71 6c 69 74 65 33 54 73 64 28 29 2d 3e 75 73 65 qlite3Tsd()->use
1b3f0 53 68 61 72 65 64 44 61 74 61 20 69 73 20 74 72 SharedData is tr
1b400 75 65 29 2e 20 54 68 65 79 20 61 72 65 0a 2a 2a ue). They are.**
1b410 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 used to store t
1b420 68 65 20 73 65 74 20 6f 66 20 74 61 62 6c 65 2d he set of table-
1b430 6c 6f 63 6b 73 20 72 65 71 75 69 72 65 64 20 62 locks required b
1b440 79 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 20 y the statement
1b450 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d 70 69 6c 65 being.** compile
1b460 64 2e 20 46 75 6e 63 74 69 6f 6e 20 73 71 6c 69 d. Function sqli
1b470 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 29 20 69 te3TableLock() i
1b480 73 20 75 73 65 64 20 74 6f 20 61 64 64 20 65 6e s used to add en
1b490 74 72 69 65 73 20 74 6f 20 74 68 65 0a 2a 2a 20 tries to the.**
1b4a0 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 list..*/.struct
1b4b0 50 61 72 73 65 20 7b 0a 20 20 73 71 6c 69 74 65 Parse {. sqlite
1b4c0 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 20 2f 3 *db; /
1b4d0 2a 20 54 68 65 20 6d 61 69 6e 20 64 61 74 61 62 * The main datab
1b4e0 61 73 65 20 73 74 72 75 63 74 75 72 65 20 2a 2f ase structure */
1b4f0 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 4d 73 67 . char *zErrMsg
1b500 3b 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 72 ; /* An er
1b510 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f 0a 20 ror message */.
1b520 20 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 20 Vdbe *pVdbe;
1b530 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 6e 67 69 /* An engi
1b540 6e 65 20 66 6f 72 20 65 78 65 63 75 74 69 6e 67 ne for executing
1b550 20 64 61 74 61 62 61 73 65 20 62 79 74 65 63 6f database byteco
1b560 64 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 de */. int rc;
1b570 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1b580 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 6f 6d Return code from
1b590 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a 20 20 execution */.
1b5a0 75 38 20 63 6f 6c 4e 61 6d 65 73 53 65 74 3b 20 u8 colNamesSet;
1b5b0 20 20 20 20 20 2f 2a 20 54 52 55 45 20 61 66 74 /* TRUE aft
1b5c0 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e 4e 61 6d 65 er OP_ColumnName
1b5d0 20 68 61 73 20 62 65 65 6e 20 69 73 73 75 65 64 has been issued
1b5e0 20 74 6f 20 70 56 64 62 65 20 2a 2f 0a 20 20 75 to pVdbe */. u
1b5f0 38 20 63 68 65 63 6b 53 63 68 65 6d 61 3b 20 20 8 checkSchema;
1b600 20 20 20 20 2f 2a 20 43 61 75 73 65 73 20 73 63 /* Causes sc
1b610 68 65 6d 61 20 63 6f 6f 6b 69 65 20 63 68 65 63 hema cookie chec
1b620 6b 20 61 66 74 65 72 20 61 6e 20 65 72 72 6f 72 k after an error
1b630 20 2a 2f 0a 20 20 75 38 20 6e 65 73 74 65 64 3b */. u8 nested;
1b640 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1b650 6d 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 63 mber of nested c
1b660 61 6c 6c 73 20 74 6f 20 74 68 65 20 70 61 72 73 alls to the pars
1b670 65 72 2f 63 6f 64 65 20 67 65 6e 65 72 61 74 6f er/code generato
1b680 72 20 2a 2f 0a 20 20 75 38 20 6e 54 65 6d 70 52 r */. u8 nTempR
1b690 65 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e eg; /* N
1b6a0 75 6d 62 65 72 20 6f 66 20 74 65 6d 70 6f 72 61 umber of tempora
1b6b0 72 79 20 72 65 67 69 73 74 65 72 73 20 69 6e 20 ry registers in
1b6c0 61 54 65 6d 70 52 65 67 5b 5d 20 2a 2f 0a 20 20 aTempReg[] */.
1b6d0 75 38 20 69 73 4d 75 6c 74 69 57 72 69 74 65 3b u8 isMultiWrite;
1b6e0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1b6f0 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 6d 6f statement may mo
1b700 64 69 66 79 2f 69 6e 73 65 72 74 20 6d 75 6c 74 dify/insert mult
1b710 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 20 20 75 iple rows */. u
1b720 38 20 6d 61 79 41 62 6f 72 74 3b 20 20 20 20 20 8 mayAbort;
1b730 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 /* True if s
1b740 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 74 68 72 tatement may thr
1b750 6f 77 20 61 6e 20 41 42 4f 52 54 20 65 78 63 65 ow an ABORT exce
1b760 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 68 61 ption */. u8 ha
1b770 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 20 20 20 20 sCompound;
1b780 2f 2a 20 4e 65 65 64 20 74 6f 20 69 6e 76 6f 6b /* Need to invok
1b790 65 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e e convertCompoun
1b7a0 64 53 65 6c 65 63 74 54 6f 53 75 62 71 75 65 72 dSelectToSubquer
1b7b0 79 28 29 20 2a 2f 0a 20 20 75 38 20 6f 6b 43 6f y() */. u8 okCo
1b7c0 6e 73 74 46 61 63 74 6f 72 3b 20 20 20 20 2f 2a nstFactor; /*
1b7d0 20 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 6f 75 OK to factor ou
1b7e0 74 20 63 6f 6e 73 74 61 6e 74 73 20 2a 2f 0a 20 t constants */.
1b7f0 20 69 6e 74 20 61 54 65 6d 70 52 65 67 5b 38 5d int aTempReg[8]
1b800 3b 20 20 20 20 20 2f 2a 20 48 6f 6c 64 69 6e 67 ; /* Holding
1b810 20 61 72 65 61 20 66 6f 72 20 74 65 6d 70 6f 72 area for tempor
1b820 61 72 79 20 72 65 67 69 73 74 65 72 73 20 2a 2f ary registers */
1b830 0a 20 20 69 6e 74 20 6e 52 61 6e 67 65 52 65 67 . int nRangeReg
1b840 3b 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 ; /* Size
1b850 6f 66 20 74 68 65 20 74 65 6d 70 6f 72 61 72 79 of the temporary
1b860 20 72 65 67 69 73 74 65 72 20 62 6c 6f 63 6b 20 register block
1b870 2a 2f 0a 20 20 69 6e 74 20 69 52 61 6e 67 65 52 */. int iRangeR
1b880 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 46 69 72 eg; /* Fir
1b890 73 74 20 72 65 67 69 73 74 65 72 20 69 6e 20 74 st register in t
1b8a0 65 6d 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 emporary registe
1b8b0 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 6e 74 r block */. int
1b8c0 20 6e 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 nErr;
1b8d0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
1b8e0 72 72 6f 72 73 20 73 65 65 6e 20 2a 2f 0a 20 20 rrors seen */.
1b8f0 69 6e 74 20 6e 54 61 62 3b 20 20 20 20 20 20 20 int nTab;
1b900 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1b910 66 20 70 72 65 76 69 6f 75 73 6c 79 20 61 6c 6c f previously all
1b920 6f 63 61 74 65 64 20 56 44 42 45 20 63 75 72 73 ocated VDBE curs
1b930 6f 72 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 65 ors */. int nMe
1b940 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
1b950 20 4e 75 6d 62 65 72 20 6f 66 20 6d 65 6d 6f 72 Number of memor
1b960 79 20 63 65 6c 6c 73 20 75 73 65 64 20 73 6f 20 y cells used so
1b970 66 61 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 65 far */. int nSe
1b980 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a t; /*
1b990 20 4e 75 6d 62 65 72 20 6f 66 20 73 65 74 73 20 Number of sets
1b9a0 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a 20 used so far */.
1b9b0 20 69 6e 74 20 6e 4f 6e 63 65 3b 20 20 20 20 20 int nOnce;
1b9c0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1b9d0 6f 66 20 4f 50 5f 4f 6e 63 65 20 69 6e 73 74 72 of OP_Once instr
1b9e0 75 63 74 69 6f 6e 73 20 73 6f 20 66 61 72 20 2a uctions so far *
1b9f0 2f 0a 20 20 69 6e 74 20 6e 4f 70 41 6c 6c 6f 63 /. int nOpAlloc
1ba00 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 ; /* Numb
1ba10 65 72 20 6f 66 20 73 6c 6f 74 73 20 61 6c 6c 6f er of slots allo
1ba20 63 61 74 65 64 20 66 6f 72 20 56 64 62 65 2e 61 cated for Vdbe.a
1ba30 4f 70 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 69 46 Op[] */. int iF
1ba40 69 78 65 64 4f 70 3b 20 20 20 20 20 20 20 20 2f ixedOp; /
1ba50 2a 20 4e 65 76 65 72 20 62 61 63 6b 20 6f 75 74 * Never back out
1ba60 20 6f 70 63 6f 64 65 73 20 69 46 69 78 65 64 4f opcodes iFixedO
1ba70 70 2d 31 20 6f 72 20 65 61 72 6c 69 65 72 20 2a p-1 or earlier *
1ba80 2f 0a 20 20 69 6e 74 20 63 6b 42 61 73 65 3b 20 /. int ckBase;
1ba90 20 20 20 20 20 20 20 20 20 2f 2a 20 42 61 73 65 /* Base
1baa0 20 72 65 67 69 73 74 65 72 20 6f 66 20 64 61 74 register of dat
1bab0 61 20 64 75 72 69 6e 67 20 63 68 65 63 6b 20 63 a during check c
1bac0 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 onstraints */.
1bad0 69 6e 74 20 69 50 61 72 74 49 64 78 54 61 62 3b int iPartIdxTab;
1bae0 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 63 6f /* Table co
1baf0 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 61 rresponding to a
1bb00 20 70 61 72 74 69 61 6c 20 69 6e 64 65 78 20 2a partial index *
1bb10 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 65 4c 65 /. int iCacheLe
1bb20 76 65 6c 3b 20 20 20 20 20 2f 2a 20 43 6f 6c 43 vel; /* ColC
1bb30 61 63 68 65 20 76 61 6c 69 64 20 77 68 65 6e 20 ache valid when
1bb40 61 43 6f 6c 43 61 63 68 65 5b 5d 2e 69 4c 65 76 aColCache[].iLev
1bb50 65 6c 3c 3d 69 43 61 63 68 65 4c 65 76 65 6c 20 el<=iCacheLevel
1bb60 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 65 43 */. int iCacheC
1bb70 6e 74 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 nt; /* Cou
1bb80 6e 74 65 72 20 75 73 65 64 20 74 6f 20 67 65 6e nter used to gen
1bb90 65 72 61 74 65 20 61 43 6f 6c 43 61 63 68 65 5b erate aColCache[
1bba0 5d 2e 6c 72 75 20 76 61 6c 75 65 73 20 2a 2f 0a ].lru values */.
1bbb0 20 20 69 6e 74 20 6e 4c 61 62 65 6c 3b 20 20 20 int nLabel;
1bbc0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1bbd0 20 6f 66 20 6c 61 62 65 6c 73 20 75 73 65 64 20 of labels used
1bbe0 2a 2f 0a 20 20 69 6e 74 20 2a 61 4c 61 62 65 6c */. int *aLabel
1bbf0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 53 70 61 ; /* Spa
1bc00 63 65 20 74 6f 20 68 6f 6c 64 20 74 68 65 20 6c ce to hold the l
1bc10 61 62 65 6c 73 20 2a 2f 0a 20 20 73 74 72 75 63 abels */. struc
1bc20 74 20 79 43 6f 6c 43 61 63 68 65 20 7b 0a 20 20 t yColCache {.
1bc30 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 int iTable;
1bc40 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
1bc50 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 2a cursor number *
1bc60 2f 0a 20 20 20 20 69 31 36 20 69 43 6f 6c 75 6d /. i16 iColum
1bc70 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 n; /* T
1bc80 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 able column numb
1bc90 65 72 20 2a 2f 0a 20 20 20 20 75 38 20 74 65 6d er */. u8 tem
1bca0 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 20 20 pReg;
1bcb0 2f 2a 20 69 52 65 67 20 69 73 20 61 20 74 65 6d /* iReg is a tem
1bcc0 70 20 72 65 67 69 73 74 65 72 20 74 68 61 74 20 p register that
1bcd0 6e 65 65 64 73 20 74 6f 20 62 65 20 66 72 65 65 needs to be free
1bce0 64 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4c 65 d */. int iLe
1bcf0 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f vel; /
1bd00 2a 20 4e 65 73 74 69 6e 67 20 6c 65 76 65 6c 20 * Nesting level
1bd10 2a 2f 0a 20 20 20 20 69 6e 74 20 69 52 65 67 3b */. int iReg;
1bd20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1bd30 52 65 67 20 77 69 74 68 20 76 61 6c 75 65 20 6f Reg with value o
1bd40 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 30 f this column. 0
1bd50 20 6d 65 61 6e 73 20 6e 6f 6e 65 2e 20 2a 2f 0a means none. */.
1bd60 20 20 20 20 69 6e 74 20 6c 72 75 3b 20 20 20 20 int lru;
1bd70 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 61 /* Lea
1bd80 73 74 20 72 65 63 65 6e 74 6c 79 20 75 73 65 64 st recently used
1bd90 20 65 6e 74 72 79 20 68 61 73 20 74 68 65 20 73 entry has the s
1bda0 6d 61 6c 6c 65 73 74 20 76 61 6c 75 65 20 2a 2f mallest value */
1bdb0 0a 20 20 7d 20 61 43 6f 6c 43 61 63 68 65 5b 53 . } aColCache[S
1bdc0 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 QLITE_N_COLCACHE
1bdd0 5d 3b 20 20 2f 2a 20 4f 6e 65 20 66 6f 72 20 65 ]; /* One for e
1bde0 61 63 68 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 ach column cache
1bdf0 20 65 6e 74 72 79 20 2a 2f 0a 20 20 45 78 70 72 entry */. Expr
1be00 4c 69 73 74 20 2a 70 43 6f 6e 73 74 45 78 70 72 List *pConstExpr
1be10 3b 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 78 70 ;/* Constant exp
1be20 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 54 6f ressions */. To
1be30 6b 65 6e 20 63 6f 6e 73 74 72 61 69 6e 74 4e 61 ken constraintNa
1be40 6d 65 3b 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 me;/* Name of th
1be50 65 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 75 72 e constraint cur
1be60 72 65 6e 74 6c 79 20 62 65 69 6e 67 20 70 61 72 rently being par
1be70 73 65 64 20 2a 2f 0a 20 20 79 44 62 4d 61 73 6b sed */. yDbMask
1be80 20 77 72 69 74 65 4d 61 73 6b 3b 20 20 20 2f 2a writeMask; /*
1be90 20 53 74 61 72 74 20 61 20 77 72 69 74 65 20 74 Start a write t
1bea0 72 61 6e 73 61 63 74 69 6f 6e 20 6f 6e 20 74 68 ransaction on th
1beb0 65 73 65 20 64 61 74 61 62 61 73 65 73 20 2a 2f ese databases */
1bec0 0a 20 20 79 44 62 4d 61 73 6b 20 63 6f 6f 6b 69 . yDbMask cooki
1bed0 65 4d 61 73 6b 3b 20 20 2f 2a 20 42 69 74 6d 61 eMask; /* Bitma
1bee0 73 6b 20 6f 66 20 73 63 68 65 6d 61 20 76 65 72 sk of schema ver
1bef0 69 66 69 65 64 20 64 61 74 61 62 61 73 65 73 20 ified databases
1bf00 2a 2f 0a 20 20 69 6e 74 20 63 6f 6f 6b 69 65 56 */. int cookieV
1bf10 61 6c 75 65 5b 53 51 4c 49 54 45 5f 4d 41 58 5f alue[SQLITE_MAX_
1bf20 41 54 54 41 43 48 45 44 2b 32 5d 3b 20 20 2f 2a ATTACHED+2]; /*
1bf30 20 56 61 6c 75 65 73 20 6f 66 20 63 6f 6f 6b 69 Values of cooki
1bf40 65 73 20 74 6f 20 76 65 72 69 66 79 20 2a 2f 0a es to verify */.
1bf50 20 20 69 6e 74 20 72 65 67 52 6f 77 69 64 3b 20 int regRowid;
1bf60 20 20 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 /* Regist
1bf70 65 72 20 68 6f 6c 64 69 6e 67 20 72 6f 77 69 64 er holding rowid
1bf80 20 6f 66 20 43 52 45 41 54 45 20 54 41 42 4c 45 of CREATE TABLE
1bf90 20 65 6e 74 72 79 20 2a 2f 0a 20 20 69 6e 74 20 entry */. int
1bfa0 72 65 67 52 6f 6f 74 3b 20 20 20 20 20 20 20 20 regRoot;
1bfb0 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 6f 6c /* Register hol
1bfc0 64 69 6e 67 20 72 6f 6f 74 20 70 61 67 65 20 6e ding root page n
1bfd0 75 6d 62 65 72 20 66 6f 72 20 6e 65 77 20 6f 62 umber for new ob
1bfe0 6a 65 63 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e jects */. int n
1bff0 4d 61 78 41 72 67 3b 20 20 20 20 20 20 20 20 20 MaxArg;
1c000 2f 2a 20 4d 61 78 20 61 72 67 73 20 70 61 73 73 /* Max args pass
1c010 65 64 20 74 6f 20 75 73 65 72 20 66 75 6e 63 74 ed to user funct
1c020 69 6f 6e 20 62 79 20 73 75 62 2d 70 72 6f 67 72 ion by sub-progr
1c030 61 6d 20 2a 2f 0a 23 69 66 20 53 45 4c 45 43 54 am */.#if SELECT
1c040 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 0a 20 20 TRACE_ENABLED.
1c050 69 6e 74 20 6e 53 65 6c 65 63 74 3b 20 20 20 20 int nSelect;
1c060 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1c070 66 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 f SELECT stateme
1c080 6e 74 73 20 73 65 65 6e 20 2a 2f 0a 20 20 69 6e nts seen */. in
1c090 74 20 6e 53 65 6c 65 63 74 49 6e 64 65 6e 74 3b t nSelectIndent;
1c0a0 20 20 20 2f 2a 20 48 6f 77 20 66 61 72 20 74 6f /* How far to
1c0b0 20 69 6e 64 65 6e 74 20 53 45 4c 45 43 54 54 52 indent SELECTTR
1c0c0 41 43 45 28 29 20 6f 75 74 70 75 74 20 2a 2f 0a ACE() output */.
1c0d0 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
1c0e0 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 48 41 52 45 QLITE_OMIT_SHARE
1c0f0 44 5f 43 41 43 48 45 0a 20 20 69 6e 74 20 6e 54 D_CACHE. int nT
1c100 61 62 6c 65 4c 6f 63 6b 3b 20 20 20 20 20 20 20 ableLock;
1c110 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c 6f /* Number of lo
1c120 63 6b 73 20 69 6e 20 61 54 61 62 6c 65 4c 6f 63 cks in aTableLoc
1c130 6b 20 2a 2f 0a 20 20 54 61 62 6c 65 4c 6f 63 6b k */. TableLock
1c140 20 2a 61 54 61 62 6c 65 4c 6f 63 6b 3b 20 2f 2a *aTableLock; /*
1c150 20 52 65 71 75 69 72 65 64 20 74 61 62 6c 65 20 Required table
1c160 6c 6f 63 6b 73 20 66 6f 72 20 73 68 61 72 65 64 locks for shared
1c170 2d 63 61 63 68 65 20 6d 6f 64 65 20 2a 2f 0a 23 -cache mode */.#
1c180 65 6e 64 69 66 0a 20 20 41 75 74 6f 69 6e 63 49 endif. AutoincI
1c190 6e 66 6f 20 2a 70 41 69 6e 63 3b 20 20 2f 2a 20 nfo *pAinc; /*
1c1a0 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 Information abou
1c1b0 74 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 t AUTOINCREMENT
1c1c0 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 0a 20 20 2f counters */.. /
1c1d0 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 73 * Information us
1c1e0 65 64 20 77 68 69 6c 65 20 63 6f 64 69 6e 67 20 ed while coding
1c1f0 74 72 69 67 67 65 72 20 70 72 6f 67 72 61 6d 73 trigger programs
1c200 2e 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 54 . */. Parse *pT
1c210 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a 20 50 oplevel; /* P
1c220 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 66 arse structure f
1c230 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 6d 20 or main program
1c240 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 54 (or NULL) */. T
1c250 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 54 61 able *pTriggerTa
1c260 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 72 69 b; /* Table tri
1c270 67 67 65 72 73 20 61 72 65 20 62 65 69 6e 67 20 ggers are being
1c280 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 20 69 coded for */. i
1c290 6e 74 20 61 64 64 72 43 72 54 61 62 3b 20 20 20 nt addrCrTab;
1c2a0 20 20 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f /* Address o
1c2b0 66 20 4f 50 5f 43 72 65 61 74 65 54 61 62 6c 65 f OP_CreateTable
1c2c0 20 6f 70 63 6f 64 65 20 6f 6e 20 43 52 45 41 54 opcode on CREAT
1c2d0 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 75 33 32 E TABLE */. u32
1c2e0 20 6e 51 75 65 72 79 4c 6f 6f 70 3b 20 20 20 20 nQueryLoop;
1c2f0 20 20 2f 2a 20 45 73 74 20 6e 75 6d 62 65 72 20 /* Est number
1c300 6f 66 20 69 74 65 72 61 74 69 6f 6e 73 20 6f 66 of iterations of
1c310 20 61 20 71 75 65 72 79 20 28 31 30 2a 6c 6f 67 a query (10*log
1c320 32 28 4e 29 29 20 2a 2f 0a 20 20 75 33 32 20 6f 2(N)) */. u32 o
1c330 6c 64 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 ldmask;
1c340 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f 6c 64 2e 2a /* Mask of old.*
1c350 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e columns referen
1c360 63 65 64 20 2a 2f 0a 20 20 75 33 32 20 6e 65 77 ced */. u32 new
1c370 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f 2a mask; /*
1c380 20 4d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 Mask of new.* c
1c390 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 65 olumns reference
1c3a0 64 20 2a 2f 0a 20 20 75 38 20 65 54 72 69 67 67 d */. u8 eTrigg
1c3b0 65 72 4f 70 3b 20 20 20 20 20 20 20 2f 2a 20 54 erOp; /* T
1c3c0 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 K_UPDATE, TK_INS
1c3d0 45 52 54 20 6f 72 20 54 4b 5f 44 45 4c 45 54 45 ERT or TK_DELETE
1c3e0 20 2a 2f 0a 20 20 75 38 20 65 4f 72 63 6f 6e 66 */. u8 eOrconf
1c3f0 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 ; /* De
1c400 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 fault ON CONFLIC
1c410 54 20 70 6f 6c 69 63 79 20 66 6f 72 20 74 72 69 T policy for tri
1c420 67 67 65 72 20 73 74 65 70 73 20 2a 2f 0a 20 20 gger steps */.
1c430 75 38 20 64 69 73 61 62 6c 65 54 72 69 67 67 65 u8 disableTrigge
1c440 72 73 3b 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 rs; /* True to
1c450 64 69 73 61 62 6c 65 20 74 72 69 67 67 65 72 73 disable triggers
1c460 20 2a 2f 0a 0a 20 20 2f 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 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c490 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c4a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c4b0 0a 20 20 2a 2a 20 41 62 6f 76 65 20 69 73 20 63 . ** Above is c
1c4c0 6f 6e 73 74 61 6e 74 20 62 65 74 77 65 65 6e 20 onstant between
1c4d0 72 65 63 75 72 73 69 6f 6e 73 2e 20 20 42 65 6c recursions. Bel
1c4e0 6f 77 20 69 73 20 72 65 73 65 74 20 62 65 66 6f ow is reset befo
1c4f0 72 65 20 61 6e 64 20 61 66 74 65 72 0a 20 20 2a re and after. *
1c500 2a 20 65 61 63 68 20 72 65 63 75 72 73 69 6f 6e * each recursion
1c510 2e 20 20 54 68 65 20 62 6f 75 6e 64 61 72 79 20 . The boundary
1c520 62 65 74 77 65 65 6e 20 74 68 65 73 65 20 74 77 between these tw
1c530 6f 20 72 65 67 69 6f 6e 73 20 69 73 20 64 65 74 o regions is det
1c540 65 72 6d 69 6e 65 64 0a 20 20 2a 2a 20 75 73 69 ermined. ** usi
1c550 6e 67 20 6f 66 66 73 65 74 6f 66 28 50 61 72 73 ng offsetof(Pars
1c560 65 2c 6e 56 61 72 29 20 73 6f 20 74 68 65 20 6e e,nVar) so the n
1c570 56 61 72 20 66 69 65 6c 64 20 6d 75 73 74 20 62 Var field must b
1c580 65 20 74 68 65 20 66 69 72 73 74 20 66 69 65 6c e the first fiel
1c590 64 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20 72 65 d. ** in the re
1c5a0 63 75 72 73 69 76 65 20 72 65 67 69 6f 6e 2e 0a cursive region..
1c5b0 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a **************
1c5c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c5d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c5e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1c5f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 69 **********/.. i
1c600 6e 74 20 6e 56 61 72 3b 20 20 20 20 20 20 20 20 nt nVar;
1c610 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1c620 65 72 20 6f 66 20 27 3f 27 20 76 61 72 69 61 62 er of '?' variab
1c630 6c 65 73 20 73 65 65 6e 20 69 6e 20 74 68 65 20 les seen in the
1c640 53 51 4c 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 SQL so far */.
1c650 69 6e 74 20 6e 7a 56 61 72 3b 20 20 20 20 20 20 int nzVar;
1c660 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1c670 62 65 72 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 ber of available
1c680 20 73 6c 6f 74 73 20 69 6e 20 61 7a 56 61 72 5b slots in azVar[
1c690 5d 20 2a 2f 0a 20 20 75 38 20 69 50 6b 53 6f 72 ] */. u8 iPkSor
1c6a0 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 tOrder;
1c6b0 20 2f 2a 20 41 53 43 20 6f 72 20 44 45 53 43 20 /* ASC or DESC
1c6c0 66 6f 72 20 49 4e 54 45 47 45 52 20 50 52 49 4d for INTEGER PRIM
1c6d0 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 75 38 20 ARY KEY */. u8
1c6e0 62 46 72 65 65 57 69 74 68 3b 20 20 20 20 20 20 bFreeWith;
1c6f0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
1c700 66 20 70 57 69 74 68 20 73 68 6f 75 6c 64 20 62 f pWith should b
1c710 65 20 66 72 65 65 64 20 77 69 74 68 20 70 61 72 e freed with par
1c720 73 65 72 20 2a 2f 0a 20 20 75 38 20 65 78 70 6c ser */. u8 expl
1c730 61 69 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 ain;
1c740 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 /* True if th
1c750 65 20 45 58 50 4c 41 49 4e 20 66 6c 61 67 20 69 e EXPLAIN flag i
1c760 73 20 66 6f 75 6e 64 20 6f 6e 20 74 68 65 20 71 s found on the q
1c770 75 65 72 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 uery */.#ifndef
1c780 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
1c790 55 41 4c 54 41 42 4c 45 0a 20 20 75 38 20 64 65 UALTABLE. u8 de
1c7a0 63 6c 61 72 65 56 74 61 62 3b 20 20 20 20 20 20 clareVtab;
1c7b0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1c7c0 69 6e 73 69 64 65 20 73 71 6c 69 74 65 33 5f 64 inside sqlite3_d
1c7d0 65 63 6c 61 72 65 5f 76 74 61 62 28 29 20 2a 2f eclare_vtab() */
1c7e0 0a 20 20 69 6e 74 20 6e 56 74 61 62 4c 6f 63 6b . int nVtabLock
1c7f0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1c800 4e 75 6d 62 65 72 20 6f 66 20 76 69 72 74 75 61 Number of virtua
1c810 6c 20 74 61 62 6c 65 73 20 74 6f 20 6c 6f 63 6b l tables to lock
1c820 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 */.#endif. int
1c830 20 6e 41 6c 69 61 73 3b 20 20 20 20 20 20 20 20 nAlias;
1c840 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1c850 20 6f 66 20 61 6c 69 61 73 65 64 20 72 65 73 75 of aliased resu
1c860 6c 74 20 73 65 74 20 63 6f 6c 75 6d 6e 73 20 2a lt set columns *
1c870 2f 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 74 3b /. int nHeight;
1c880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1c890 20 45 78 70 72 65 73 73 69 6f 6e 20 74 72 65 65 Expression tree
1c8a0 20 68 65 69 67 68 74 20 6f 66 20 63 75 72 72 65 height of curre
1c8b0 6e 74 20 73 75 62 2d 73 65 6c 65 63 74 20 2a 2f nt sub-select */
1c8c0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
1c8d0 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 20 20 69 OMIT_EXPLAIN. i
1c8e0 6e 74 20 69 53 65 6c 65 63 74 49 64 3b 20 20 20 nt iSelectId;
1c8f0 20 20 20 20 20 20 20 20 20 2f 2a 20 49 44 20 6f /* ID o
1c900 66 20 63 75 72 72 65 6e 74 20 73 65 6c 65 63 74 f current select
1c910 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 for EXPLAIN out
1c920 70 75 74 20 2a 2f 0a 20 20 69 6e 74 20 69 4e 65 put */. int iNe
1c930 78 74 53 65 6c 65 63 74 49 64 3b 20 20 20 20 20 xtSelectId;
1c940 20 20 20 2f 2a 20 4e 65 78 74 20 61 76 61 69 6c /* Next avail
1c950 61 62 6c 65 20 73 65 6c 65 63 74 20 49 44 20 66 able select ID f
1c960 6f 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 70 75 or EXPLAIN outpu
1c970 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 63 68 t */.#endif. ch
1c980 61 72 20 2a 2a 61 7a 56 61 72 3b 20 20 20 20 20 ar **azVar;
1c990 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 /* Point
1c9a0 65 72 73 20 74 6f 20 6e 61 6d 65 73 20 6f 66 20 ers to names of
1c9b0 70 61 72 61 6d 65 74 65 72 73 20 2a 2f 0a 20 20 parameters */.
1c9c0 56 64 62 65 20 2a 70 52 65 70 72 65 70 61 72 65 Vdbe *pReprepare
1c9d0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 56 4d 20 ; /* VM
1c9e0 62 65 69 6e 67 20 72 65 70 72 65 70 61 72 65 64 being reprepared
1c9f0 20 28 73 71 6c 69 74 65 33 52 65 70 72 65 70 61 (sqlite3Reprepa
1ca00 72 65 28 29 29 20 2a 2f 0a 20 20 63 6f 6e 73 74 re()) */. const
1ca10 20 63 68 61 72 20 2a 7a 54 61 69 6c 3b 20 20 20 char *zTail;
1ca20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 53 51 4c 20 /* All SQL
1ca30 74 65 78 74 20 70 61 73 74 20 74 68 65 20 6c 61 text past the la
1ca40 73 74 20 73 65 6d 69 63 6f 6c 6f 6e 20 70 61 72 st semicolon par
1ca50 73 65 64 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a sed */. Table *
1ca60 70 4e 65 77 54 61 62 6c 65 3b 20 20 20 20 20 20 pNewTable;
1ca70 20 20 20 2f 2a 20 41 20 74 61 62 6c 65 20 62 65 /* A table be
1ca80 69 6e 67 20 63 6f 6e 73 74 72 75 63 74 65 64 20 ing constructed
1ca90 62 79 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 by CREATE TABLE
1caa0 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e */. Trigger *pN
1cab0 65 77 54 72 69 67 67 65 72 3b 20 20 20 20 20 2f ewTrigger; /
1cac0 2a 20 54 72 69 67 67 65 72 20 75 6e 64 65 72 20 * Trigger under
1cad0 63 6f 6e 73 74 72 75 63 74 20 62 79 20 61 20 43 construct by a C
1cae0 52 45 41 54 45 20 54 52 49 47 47 45 52 20 2a 2f REATE TRIGGER */
1caf0 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
1cb00 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 2f 2a 20 AuthContext; /*
1cb10 54 68 65 20 36 74 68 20 70 61 72 61 6d 65 74 65 The 6th paramete
1cb20 72 20 74 6f 20 64 62 2d 3e 78 41 75 74 68 20 63 r to db->xAuth c
1cb30 61 6c 6c 62 61 63 6b 73 20 2a 2f 0a 20 20 54 6f allbacks */. To
1cb40 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 6e 3b 20 ken sNameToken;
1cb50 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e /* Token
1cb60 20 77 69 74 68 20 75 6e 71 75 61 6c 69 66 69 65 with unqualifie
1cb70 64 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 20 d schema object
1cb80 6e 61 6d 65 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 name */. Token
1cb90 73 4c 61 73 74 54 6f 6b 65 6e 3b 20 20 20 20 20 sLastToken;
1cba0 20 20 20 20 2f 2a 20 54 68 65 20 6c 61 73 74 20 /* The last
1cbb0 74 6f 6b 65 6e 20 70 61 72 73 65 64 20 2a 2f 0a token parsed */.
1cbc0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1cbd0 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
1cbe0 0a 20 20 54 6f 6b 65 6e 20 73 41 72 67 3b 20 20 . Token sArg;
1cbf0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1cc00 43 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 6f 66 Complete text of
1cc10 20 61 20 6d 6f 64 75 6c 65 20 61 72 67 75 6d 65 a module argume
1cc20 6e 74 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 2a nt */. Table **
1cc30 61 70 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 apVtabLock;
1cc40 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
1cc50 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 6e virtual tables n
1cc60 65 65 64 69 6e 67 20 6c 6f 63 6b 69 6e 67 20 2a eeding locking *
1cc70 2f 0a 23 65 6e 64 69 66 0a 20 20 54 61 62 6c 65 /.#endif. Table
1cc80 20 2a 70 5a 6f 6d 62 69 65 54 61 62 3b 20 20 20 *pZombieTab;
1cc90 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 /* List of
1cca0 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 6f Table objects to
1ccb0 20 64 65 6c 65 74 65 20 61 66 74 65 72 20 63 6f delete after co
1ccc0 64 65 20 67 65 6e 20 2a 2f 0a 20 20 54 72 69 67 de gen */. Trig
1ccd0 67 65 72 50 72 67 20 2a 70 54 72 69 67 67 65 72 gerPrg *pTrigger
1cce0 50 72 67 3b 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 Prg; /* Linked
1ccf0 6c 69 73 74 20 6f 66 20 63 6f 64 65 64 20 74 72 list of coded tr
1cd00 69 67 67 65 72 73 20 2a 2f 0a 20 20 57 69 74 68 iggers */. With
1cd10 20 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 *pWith;
1cd20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 /* Current
1cd30 20 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 WITH clause, or
1cd40 20 4e 55 4c 4c 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a NULL */.};../*.
1cd50 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 ** Return true i
1cd60 66 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 73 69 f currently insi
1cd70 64 65 20 61 6e 20 73 71 6c 69 74 65 33 5f 64 65 de an sqlite3_de
1cd80 63 6c 61 72 65 5f 76 74 61 62 28 29 20 63 61 6c clare_vtab() cal
1cd90 6c 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c l..*/.#ifdef SQL
1cda0 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
1cdb0 54 41 42 4c 45 0a 20 20 23 64 65 66 69 6e 65 20 TABLE. #define
1cdc0 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 20 IN_DECLARE_VTAB
1cdd0 30 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 0.#else. #defin
1cde0 65 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 e IN_DECLARE_VTA
1cdf0 42 20 28 70 50 61 72 73 65 2d 3e 64 65 63 6c 61 B (pParse->decla
1ce00 72 65 56 74 61 62 29 0a 23 65 6e 64 69 66 0a 0a reVtab).#endif..
1ce10 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
1ce20 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
1ce30 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 61 6e ng structure can
1ce40 20 62 65 20 64 65 63 6c 61 72 65 64 20 6f 6e 20 be declared on
1ce50 61 20 73 74 61 63 6b 20 61 6e 64 20 75 73 65 64 a stack and used
1ce60 0a 2a 2a 20 74 6f 20 73 61 76 65 20 74 68 65 20 .** to save the
1ce70 50 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 Parse.zAuthConte
1ce80 78 74 20 76 61 6c 75 65 20 73 6f 20 74 68 61 74 xt value so that
1ce90 20 69 74 20 63 61 6e 20 62 65 20 72 65 73 74 6f it can be resto
1cea0 72 65 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 73 74 red later..*/.st
1ceb0 72 75 63 74 20 41 75 74 68 43 6f 6e 74 65 78 74 ruct AuthContext
1cec0 20 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 {. const char
1ced0 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 20 *zAuthContext;
1cee0 20 2f 2a 20 50 75 74 20 73 61 76 65 64 20 50 61 /* Put saved Pa
1cef0 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 rse.zAuthContext
1cf00 20 68 65 72 65 20 2a 2f 0a 20 20 50 61 72 73 65 here */. Parse
1cf10 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 *pParse;
1cf20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 50 61 /* The Pa
1cf30 72 73 65 20 73 74 72 75 63 74 75 72 65 20 2a 2f rse structure */
1cf40 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 66 69 .};../*.** Bitfi
1cf50 65 6c 64 20 66 6c 61 67 73 20 66 6f 72 20 50 35 eld flags for P5
1cf60 20 76 61 6c 75 65 20 69 6e 20 76 61 72 69 6f 75 value in variou
1cf70 73 20 6f 70 63 6f 64 65 73 2e 0a 2a 2a 0a 2a 2a s opcodes..**.**
1cf80 20 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20 76 Note that the v
1cf90 61 6c 75 65 73 20 66 6f 72 20 49 53 4e 4f 4f 50 alues for ISNOOP
1cfa0 20 61 6e 64 20 4c 45 4e 47 54 48 41 52 47 20 61 and LENGTHARG a
1cfb0 72 65 20 74 68 65 20 73 61 6d 65 2e 20 20 42 75 re the same. Bu
1cfc0 74 20 61 73 20 0a 2a 2a 20 74 68 6f 73 65 20 62 t as .** those b
1cfd0 69 74 73 20 61 72 65 20 6e 65 76 65 72 20 75 73 its are never us
1cfe0 65 64 20 6f 6e 20 74 68 65 20 73 61 6d 65 20 6f ed on the same o
1cff0 70 63 6f 64 65 2c 20 74 68 65 20 6f 76 65 72 6c pcode, the overl
1d000 61 70 20 69 73 20 68 61 72 6d 6c 65 73 73 2e 0a ap is harmless..
1d010 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 */.#define OPFLA
1d020 47 5f 4e 43 48 41 4e 47 45 20 20 20 20 20 20 20 G_NCHANGE
1d030 30 78 30 31 20 20 20 20 2f 2a 20 53 65 74 20 74 0x01 /* Set t
1d040 6f 20 75 70 64 61 74 65 20 64 62 2d 3e 6e 43 68 o update db->nCh
1d050 61 6e 67 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ange */.#define
1d060 4f 50 46 4c 41 47 5f 45 50 48 45 4d 20 20 20 20 OPFLAG_EPHEM
1d070 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
1d080 4f 50 5f 43 6f 6c 75 6d 6e 3a 20 45 70 68 65 6d OP_Column: Ephem
1d090 65 72 61 6c 20 6f 75 74 70 75 74 20 69 73 20 6f eral output is o
1d0a0 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 k */.#define OPF
1d0b0 4c 41 47 5f 4c 41 53 54 52 4f 57 49 44 20 20 20 LAG_LASTROWID
1d0c0 20 20 30 78 30 32 20 20 20 20 2f 2a 20 53 65 74 0x02 /* Set
1d0d0 20 74 6f 20 75 70 64 61 74 65 20 64 62 2d 3e 6c to update db->l
1d0e0 61 73 74 52 6f 77 69 64 20 2a 2f 0a 23 64 65 66 astRowid */.#def
1d0f0 69 6e 65 20 4f 50 46 4c 41 47 5f 49 53 55 50 44 ine OPFLAG_ISUPD
1d100 41 54 45 20 20 20 20 20 20 30 78 30 34 20 20 20 ATE 0x04
1d110 20 2f 2a 20 54 68 69 73 20 4f 50 5f 49 6e 73 65 /* This OP_Inse
1d120 72 74 20 69 73 20 61 6e 20 73 71 6c 20 55 50 44 rt is an sql UPD
1d130 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ATE */.#define O
1d140 50 46 4c 41 47 5f 41 50 50 45 4e 44 20 20 20 20 PFLAG_APPEND
1d150 20 20 20 20 30 78 30 38 20 20 20 20 2f 2a 20 54 0x08 /* T
1d160 68 69 73 20 69 73 20 6c 69 6b 65 6c 79 20 74 6f his is likely to
1d170 20 62 65 20 61 6e 20 61 70 70 65 6e 64 20 2a 2f be an append */
1d180 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
1d190 55 53 45 53 45 45 4b 52 45 53 55 4c 54 20 30 78 USESEEKRESULT 0x
1d1a0 31 30 20 20 20 20 2f 2a 20 54 72 79 20 74 6f 20 10 /* Try to
1d1b0 61 76 6f 69 64 20 61 20 73 65 65 6b 20 69 6e 20 avoid a seek in
1d1c0 42 74 72 65 65 49 6e 73 65 72 74 28 29 20 2a 2f BtreeInsert() */
1d1d0 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
1d1e0 49 53 4e 4f 4f 50 20 20 20 20 20 20 20 20 30 78 ISNOOP 0x
1d1f0 34 30 20 20 20 20 2f 2a 20 4f 50 5f 44 65 6c 65 40 /* OP_Dele
1d200 74 65 20 64 6f 65 73 20 70 72 65 2d 75 70 64 61 te does pre-upda
1d210 74 65 2d 68 6f 6f 6b 20 6f 6e 6c 79 20 2a 2f 0a te-hook only */.
1d220 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4c #define OPFLAG_L
1d230 45 4e 47 54 48 41 52 47 20 20 20 20 20 30 78 34 ENGTHARG 0x4
1d240 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 0 /* OP_Colum
1d250 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 n only used for
1d260 6c 65 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 66 length() */.#def
1d270 69 6e 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f ine OPFLAG_TYPEO
1d280 46 41 52 47 20 20 20 20 20 30 78 38 30 20 20 20 FARG 0x80
1d290 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 6e /* OP_Column on
1d2a0 6c 79 20 75 73 65 64 20 66 6f 72 20 74 79 70 65 ly used for type
1d2b0 6f 66 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 of() */.#define
1d2c0 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 OPFLAG_BULKCSR
1d2d0 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
1d2e0 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 74 OP_Open** used t
1d2f0 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 73 o open bulk curs
1d300 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 or */.#define OP
1d310 46 4c 41 47 5f 53 45 45 4b 45 51 20 20 20 20 20 FLAG_SEEKEQ
1d320 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 4f 50 0x02 /* OP
1d330 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 6f 72 20 75 _Open** cursor u
1d340 73 65 73 20 45 51 20 73 65 65 6b 20 6f 6e 6c 79 ses EQ seek only
1d350 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1d360 41 47 5f 50 32 49 53 52 45 47 20 20 20 20 20 20 AG_P2ISREG
1d370 20 30 78 30 34 20 20 20 20 2f 2a 20 50 32 20 74 0x04 /* P2 t
1d380 6f 20 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 61 o OP_Open** is a
1d390 20 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 register number
1d3a0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1d3b0 41 47 5f 50 45 52 4d 55 54 45 20 20 20 20 20 20 AG_PERMUTE
1d3c0 20 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 0x01 /* OP_C
1d3d0 6f 6d 70 61 72 65 3a 20 75 73 65 20 74 68 65 20 ompare: use the
1d3e0 70 65 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a 0a permutation */..
1d3f0 2f 2a 0a 20 2a 20 45 61 63 68 20 74 72 69 67 67 /*. * Each trigg
1d400 65 72 20 70 72 65 73 65 6e 74 20 69 6e 20 74 68 er present in th
1d410 65 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d e database schem
1d420 61 20 69 73 20 73 74 6f 72 65 64 20 61 73 20 61 a is stored as a
1d430 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 0a 20 2a n instance of. *
1d440 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 2e struct Trigger.
1d450 20 0a 20 2a 0a 20 2a 20 50 6f 69 6e 74 65 72 73 . *. * Pointers
1d460 20 74 6f 20 69 6e 73 74 61 6e 63 65 73 20 6f 66 to instances of
1d470 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 20 struct Trigger
1d480 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 74 77 are stored in tw
1d490 6f 20 77 61 79 73 2e 0a 20 2a 20 31 2e 20 49 6e o ways.. * 1. In
1d4a0 20 74 68 65 20 22 74 72 69 67 48 61 73 68 22 20 the "trigHash"
1d4b0 68 61 73 68 20 74 61 62 6c 65 20 28 70 61 72 74 hash table (part
1d4c0 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 33 2a of the sqlite3*
1d4d0 20 74 68 61 74 20 72 65 70 72 65 73 65 6e 74 73 that represents
1d4e0 20 74 68 65 20 0a 20 2a 20 20 20 20 64 61 74 61 the . * data
1d4f0 62 61 73 65 29 2e 20 54 68 69 73 20 61 6c 6c 6f base). This allo
1d500 77 73 20 54 72 69 67 67 65 72 20 73 74 72 75 63 ws Trigger struc
1d510 74 75 72 65 73 20 74 6f 20 62 65 20 72 65 74 72 tures to be retr
1d520 69 65 76 65 64 20 62 79 20 6e 61 6d 65 2e 0a 20 ieved by name..
1d530 2a 20 32 2e 20 41 6c 6c 20 74 72 69 67 67 65 72 * 2. All trigger
1d540 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 s associated wit
1d550 68 20 61 20 73 69 6e 67 6c 65 20 74 61 62 6c 65 h a single table
1d560 20 66 6f 72 6d 20 61 20 6c 69 6e 6b 65 64 20 6c form a linked l
1d570 69 73 74 2c 20 75 73 69 6e 67 20 74 68 65 0a 20 ist, using the.
1d580 2a 20 20 20 20 70 4e 65 78 74 20 6d 65 6d 62 65 * pNext membe
1d590 72 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 r of struct Trig
1d5a0 67 65 72 2e 20 41 20 70 6f 69 6e 74 65 72 20 74 ger. A pointer t
1d5b0 6f 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d o the first elem
1d5c0 65 6e 74 20 6f 66 20 74 68 65 0a 20 2a 20 20 20 ent of the. *
1d5d0 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 69 73 20 linked list is
1d5e0 73 74 6f 72 65 64 20 61 73 20 74 68 65 20 22 70 stored as the "p
1d5f0 54 72 69 67 67 65 72 22 20 6d 65 6d 62 65 72 20 Trigger" member
1d600 6f 66 20 74 68 65 20 61 73 73 6f 63 69 61 74 65 of the associate
1d610 64 0a 20 2a 20 20 20 20 73 74 72 75 63 74 20 54 d. * struct T
1d620 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 54 68 65 20 able.. *. * The
1d630 22 73 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 "step_list" memb
1d640 65 72 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 er points to the
1d650 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 6f first element o
1d660 66 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 0a f a linked list.
1d670 20 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 * containing th
1d680 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 e SQL statements
1d690 20 73 70 65 63 69 66 69 65 64 20 61 73 20 74 68 specified as th
1d6a0 65 20 74 72 69 67 67 65 72 20 70 72 6f 67 72 61 e trigger progra
1d6b0 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 72 m.. */.struct Tr
1d6c0 69 67 67 65 72 20 7b 0a 20 20 63 68 61 72 20 2a igger {. char *
1d6d0 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 zName;
1d6e0 20 20 2f 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 /* The name of
1d6f0 20 74 68 65 20 74 72 69 67 67 65 72 20 20 20 20 the trigger
1d700 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d710 20 20 20 20 2a 2f 0a 20 20 63 68 61 72 20 2a 74 */. char *t
1d720 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 able;
1d730 20 2f 2a 20 54 68 65 20 74 61 62 6c 65 20 6f 72 /* The table or
1d740 20 76 69 65 77 20 74 6f 20 77 68 69 63 68 20 74 view to which t
1d750 68 65 20 74 72 69 67 67 65 72 20 61 70 70 6c 69 he trigger appli
1d760 65 73 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 20 es */. u8 op;
1d770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d780 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f 44 45 4c /* One of TK_DEL
1d790 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 45 2c 20 ETE, TK_UPDATE,
1d7a0 54 4b 5f 49 4e 53 45 52 54 20 20 20 20 20 20 20 TK_INSERT
1d7b0 20 20 2a 2f 0a 20 20 75 38 20 74 72 5f 74 6d 3b */. u8 tr_tm;
1d7c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1d7d0 2a 20 4f 6e 65 20 6f 66 20 54 52 49 47 47 45 52 * One of TRIGGER
1d7e0 5f 42 45 46 4f 52 45 2c 20 54 52 49 47 47 45 52 _BEFORE, TRIGGER
1d7f0 5f 41 46 54 45 52 20 2a 2f 0a 20 20 45 78 70 72 _AFTER */. Expr
1d800 20 2a 70 57 68 65 6e 3b 20 20 20 20 20 20 20 20 *pWhen;
1d810 20 20 20 20 2f 2a 20 54 68 65 20 57 48 45 4e 20 /* The WHEN
1d820 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 65 78 clause of the ex
1d830 70 72 65 73 73 69 6f 6e 20 28 6d 61 79 20 62 65 pression (may be
1d840 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 49 64 4c 69 NULL) */. IdLi
1d850 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 3b 20 20 20 st *pColumns;
1d860 20 20 20 20 2f 2a 20 49 66 20 74 68 69 73 20 69 /* If this i
1d870 73 20 61 6e 20 55 50 44 41 54 45 20 4f 46 20 3c s an UPDATE OF <
1d880 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 74 72 69 column-list> tri
1d890 67 67 65 72 2c 0a 20 20 20 20 20 20 20 20 20 20 gger,.
1d8a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d8b0 20 20 20 74 68 65 20 3c 63 6f 6c 75 6d 6e 2d 6c the <column-l
1d8c0 69 73 74 3e 20 69 73 20 73 74 6f 72 65 64 20 68 ist> is stored h
1d8d0 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 ere */. Schema
1d8e0 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 20 20 20 *pSchema;
1d8f0 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 /* Schema conta
1d900 69 6e 69 6e 67 20 74 68 65 20 74 72 69 67 67 65 ining the trigge
1d910 72 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 r */. Schema *p
1d920 54 61 62 53 63 68 65 6d 61 3b 20 20 20 20 20 2f TabSchema; /
1d930 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e * Schema contain
1d940 69 6e 67 20 74 68 65 20 74 61 62 6c 65 20 2a 2f ing the table */
1d950 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a . TriggerStep *
1d960 73 74 65 70 5f 6c 69 73 74 3b 20 2f 2a 20 4c 69 step_list; /* Li
1d970 6e 6b 20 6c 69 73 74 20 6f 66 20 74 72 69 67 67 nk list of trigg
1d980 65 72 20 70 72 6f 67 72 61 6d 20 73 74 65 70 73 er program steps
1d990 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f 0a */.
1d9a0 20 20 54 72 69 67 67 65 72 20 2a 70 4e 65 78 74 Trigger *pNext
1d9b0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 ; /* Nex
1d9c0 74 20 74 72 69 67 67 65 72 20 61 73 73 6f 63 69 t trigger associ
1d9d0 61 74 65 64 20 77 69 74 68 20 74 68 65 20 74 61 ated with the ta
1d9e0 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ble */.};../*.**
1d9f0 20 41 20 74 72 69 67 67 65 72 20 69 73 20 65 69 A trigger is ei
1da00 74 68 65 72 20 61 20 42 45 46 4f 52 45 20 6f 72 ther a BEFORE or
1da10 20 61 6e 20 41 46 54 45 52 20 74 72 69 67 67 65 an AFTER trigge
1da20 72 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e r. The followin
1da30 67 20 63 6f 6e 73 74 61 6e 74 73 0a 2a 2a 20 64 g constants.** d
1da40 65 74 65 72 6d 69 6e 65 20 77 68 69 63 68 2e 20 etermine which.
1da50 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 65 20 .**.** If there
1da60 61 72 65 20 6d 75 6c 74 69 70 6c 65 20 74 72 69 are multiple tri
1da70 67 67 65 72 73 2c 20 79 6f 75 20 6d 69 67 68 74 ggers, you might
1da80 20 6f 66 20 73 6f 6d 65 20 42 45 46 4f 52 45 20 of some BEFORE
1da90 61 6e 64 20 73 6f 6d 65 20 41 46 54 45 52 2e 0a and some AFTER..
1daa0 2a 2a 20 49 6e 20 74 68 61 74 20 63 61 73 65 73 ** In that cases
1dab0 2c 20 74 68 65 20 63 6f 6e 73 74 61 6e 74 73 20 , the constants
1dac0 62 65 6c 6f 77 20 63 61 6e 20 62 65 20 4f 52 65 below can be ORe
1dad0 64 20 74 6f 67 65 74 68 65 72 2e 0a 2a 2f 0a 23 d together..*/.#
1dae0 64 65 66 69 6e 65 20 54 52 49 47 47 45 52 5f 42 define TRIGGER_B
1daf0 45 46 4f 52 45 20 20 31 0a 23 64 65 66 69 6e 65 EFORE 1.#define
1db00 20 54 52 49 47 47 45 52 5f 41 46 54 45 52 20 20 TRIGGER_AFTER
1db10 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 6e 73 2../*. * An ins
1db20 74 61 6e 63 65 20 6f 66 20 73 74 72 75 63 74 20 tance of struct
1db30 54 72 69 67 67 65 72 53 74 65 70 20 69 73 20 75 TriggerStep is u
1db40 73 65 64 20 74 6f 20 73 74 6f 72 65 20 61 20 73 sed to store a s
1db50 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 65 6d ingle SQL statem
1db60 65 6e 74 0a 20 2a 20 74 68 61 74 20 69 73 20 61 ent. * that is a
1db70 20 70 61 72 74 20 6f 66 20 61 20 74 72 69 67 67 part of a trigg
1db80 65 72 2d 70 72 6f 67 72 61 6d 2e 20 0a 20 2a 0a er-program. . *.
1db90 20 2a 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 20 * Instances of
1dba0 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 struct TriggerSt
1dbb0 65 70 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e ep are stored in
1dbc0 20 61 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 64 a singly linked
1dbd0 20 6c 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 2a list (linked. *
1dbe0 20 75 73 69 6e 67 20 74 68 65 20 22 70 4e 65 78 using the "pNex
1dbf0 74 22 20 6d 65 6d 62 65 72 29 20 72 65 66 65 72 t" member) refer
1dc00 65 6e 63 65 64 20 62 79 20 74 68 65 20 22 73 74 enced by the "st
1dc10 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 20 ep_list" member
1dc20 6f 66 20 74 68 65 20 0a 20 2a 20 61 73 73 6f 63 of the . * assoc
1dc30 69 61 74 65 64 20 73 74 72 75 63 74 20 54 72 69 iated struct Tri
1dc40 67 67 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 54 gger instance. T
1dc50 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 he first element
1dc60 20 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c of the linked l
1dc70 69 73 74 20 69 73 0a 20 2a 20 74 68 65 20 66 69 ist is. * the fi
1dc80 72 73 74 20 73 74 65 70 20 6f 66 20 74 68 65 20 rst step of the
1dc90 74 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e trigger-program.
1dca0 0a 20 2a 20 0a 20 2a 20 54 68 65 20 22 6f 70 22 . * . * The "op"
1dcb0 20 6d 65 6d 62 65 72 20 69 6e 64 69 63 61 74 65 member indicate
1dcc0 73 20 77 68 65 74 68 65 72 20 74 68 69 73 20 69 s whether this i
1dcd0 73 20 61 20 22 44 45 4c 45 54 45 22 2c 20 22 49 s a "DELETE", "I
1dce0 4e 53 45 52 54 22 2c 20 22 55 50 44 41 54 45 22 NSERT", "UPDATE"
1dcf0 20 6f 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 20 or. * "SELECT"
1dd00 73 74 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 6d statement. The m
1dd10 65 61 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 6f eanings of the o
1dd20 74 68 65 72 20 6d 65 6d 62 65 72 73 20 69 73 20 ther members is
1dd30 64 65 74 65 72 6d 69 6e 65 64 20 62 79 20 74 68 determined by th
1dd40 65 20 0a 20 2a 20 76 61 6c 75 65 20 6f 66 20 22 e . * value of "
1dd50 6f 70 22 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a op" as follows:.
1dd60 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f *. * (op == TK_
1dd70 49 4e 53 45 52 54 29 0a 20 2a 20 6f 72 63 6f 6e INSERT). * orcon
1dd80 66 20 20 20 20 2d 3e 20 73 74 6f 72 65 73 20 74 f -> stores t
1dd90 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 61 he ON CONFLICT a
1dda0 6c 67 6f 72 69 74 68 6d 0a 20 2a 20 70 53 65 6c lgorithm. * pSel
1ddb0 65 63 74 20 20 20 2d 3e 20 49 66 20 74 68 69 73 ect -> If this
1ddc0 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e is an INSERT IN
1ddd0 54 4f 20 2e 2e 2e 20 53 45 4c 45 43 54 20 2e 2e TO ... SELECT ..
1dde0 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 . statement, the
1ddf0 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 n. *
1de00 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 61 20 this stores a
1de10 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 20 53 pointer to the S
1de20 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e ELECT statement.
1de30 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e Otherwise NULL.
1de40 0a 20 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e . * zTarget ->
1de50 20 44 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f Dequoted name o
1de60 66 20 74 68 65 20 74 61 62 6c 65 20 74 6f 20 69 f the table to i
1de70 6e 73 65 72 74 20 69 6e 74 6f 2e 0a 20 2a 20 70 nsert into.. * p
1de80 45 78 70 72 4c 69 73 74 20 2d 3e 20 49 66 20 74 ExprList -> If t
1de90 68 69 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 his is an INSERT
1dea0 20 49 4e 54 4f 20 2e 2e 2e 20 56 41 4c 55 45 53 INTO ... VALUES
1deb0 20 2e 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 ... statement,
1dec0 74 68 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 then. *
1ded0 20 20 20 20 20 74 68 69 73 20 73 74 6f 72 65 73 this stores
1dee0 20 76 61 6c 75 65 73 20 74 6f 20 62 65 20 69 6e values to be in
1def0 73 65 72 74 65 64 2e 20 4f 74 68 65 72 77 69 73 serted. Otherwis
1df00 65 20 4e 55 4c 4c 2e 0a 20 2a 20 70 49 64 4c 69 e NULL.. * pIdLi
1df10 73 74 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 st -> If this
1df20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 is an INSERT INT
1df30 4f 20 2e 2e 2e 20 28 3c 63 6f 6c 75 6d 6e 2d 6e O ... (<column-n
1df40 61 6d 65 73 3e 29 20 56 41 4c 55 45 53 20 2e 2e ames>) VALUES ..
1df50 2e 20 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 . . *
1df60 20 20 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 statement, th
1df70 65 6e 20 74 68 69 73 20 73 74 6f 72 65 73 20 74 en this stores t
1df80 68 65 20 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 he column-names
1df90 74 6f 20 62 65 0a 20 2a 20 20 20 20 20 20 20 20 to be. *
1dfa0 20 20 20 20 20 20 69 6e 73 65 72 74 65 64 20 69 inserted i
1dfb0 6e 74 6f 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d nto.. *. * (op =
1dfc0 3d 20 54 4b 5f 44 45 4c 45 54 45 29 0a 20 2a 20 = TK_DELETE). *
1dfd0 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 65 71 zTarget -> Deq
1dfe0 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 uoted name of th
1dff0 65 20 74 61 62 6c 65 20 74 6f 20 64 65 6c 65 74 e table to delet
1e000 65 20 66 72 6f 6d 2e 0a 20 2a 20 70 57 68 65 72 e from.. * pWher
1e010 65 20 20 20 20 2d 3e 20 54 68 65 20 57 48 45 52 e -> The WHER
1e020 45 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 E clause of the
1e030 44 45 4c 45 54 45 20 73 74 61 74 65 6d 65 6e 74 DELETE statement
1e040 20 69 66 20 6f 6e 65 20 69 73 20 73 70 65 63 69 if one is speci
1e050 66 69 65 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 fied.. *
1e060 20 20 20 20 20 20 4f 74 68 65 72 77 69 73 65 20 Otherwise
1e070 4e 55 4c 4c 2e 0a 20 2a 20 0a 20 2a 20 28 6f 70 NULL.. * . * (op
1e080 20 3d 3d 20 54 4b 5f 55 50 44 41 54 45 29 0a 20 == TK_UPDATE).
1e090 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 * zTarget -> D
1e0a0 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 equoted name of
1e0b0 74 68 65 20 74 61 62 6c 65 20 74 6f 20 75 70 64 the table to upd
1e0c0 61 74 65 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 ate.. * pWhere
1e0d0 20 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 -> The WHERE c
1e0e0 6c 61 75 73 65 20 6f 66 20 74 68 65 20 55 50 44 lause of the UPD
1e0f0 41 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 ATE statement if
1e100 20 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 one is specifie
1e110 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 d.. *
1e120 20 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c Otherwise NUL
1e130 4c 2e 0a 20 2a 20 70 45 78 70 72 4c 69 73 74 20 L.. * pExprList
1e140 2d 3e 20 41 20 6c 69 73 74 20 6f 66 20 74 68 65 -> A list of the
1e150 20 63 6f 6c 75 6d 6e 73 20 74 6f 20 75 70 64 61 columns to upda
1e160 74 65 20 61 6e 64 20 74 68 65 20 65 78 70 72 65 te and the expre
1e170 73 73 69 6f 6e 73 20 74 6f 20 75 70 64 61 74 65 ssions to update
1e180 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 . *
1e190 20 74 68 65 6d 20 74 6f 2e 20 53 65 65 20 73 71 them to. See sq
1e1a0 6c 69 74 65 33 55 70 64 61 74 65 28 29 20 64 6f lite3Update() do
1e1b0 63 75 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 22 cumentation of "
1e1c0 70 43 68 61 6e 67 65 73 22 0a 20 2a 20 20 20 20 pChanges". *
1e1d0 20 20 20 20 20 20 20 20 20 20 61 72 67 75 6d 65 argume
1e1e0 6e 74 2e 0a 20 2a 20 0a 20 2a 2f 0a 73 74 72 75 nt.. * . */.stru
1e1f0 63 74 20 54 72 69 67 67 65 72 53 74 65 70 20 7b ct TriggerStep {
1e200 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 . u8 op;
1e210 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 6f /* One o
1e220 66 20 54 4b 5f 44 45 4c 45 54 45 2c 20 54 4b 5f f TK_DELETE, TK_
1e230 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 45 52 UPDATE, TK_INSER
1e240 54 2c 20 54 4b 5f 53 45 4c 45 43 54 20 2a 2f 0a T, TK_SELECT */.
1e250 20 20 75 38 20 6f 72 63 6f 6e 66 3b 20 20 20 20 u8 orconf;
1e260 20 20 20 20 20 20 20 2f 2a 20 4f 45 5f 52 6f 6c /* OE_Rol
1e270 6c 62 61 63 6b 20 65 74 63 2e 20 2a 2f 0a 20 20 lback etc. */.
1e280 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 3b 20 Trigger *pTrig;
1e290 20 20 20 20 20 2f 2a 20 54 68 65 20 74 72 69 67 /* The trig
1e2a0 67 65 72 20 74 68 61 74 20 74 68 69 73 20 73 74 ger that this st
1e2b0 65 70 20 69 73 20 61 20 70 61 72 74 20 6f 66 20 ep is a part of
1e2c0 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 53 65 */. Select *pSe
1e2d0 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 53 45 4c lect; /* SEL
1e2e0 45 43 54 20 73 74 61 74 65 6d 65 6e 74 20 6f 72 ECT statement or
1e2f0 20 52 48 53 20 6f 66 20 49 4e 53 45 52 54 20 49 RHS of INSERT I
1e300 4e 54 4f 20 53 45 4c 45 43 54 20 2e 2e 2e 20 2a NTO SELECT ... *
1e310 2f 0a 20 20 63 68 61 72 20 2a 7a 54 61 72 67 65 /. char *zTarge
1e320 74 3b 20 20 20 20 20 20 20 2f 2a 20 54 61 72 67 t; /* Targ
1e330 65 74 20 74 61 62 6c 65 20 66 6f 72 20 44 45 4c et table for DEL
1e340 45 54 45 2c 20 55 50 44 41 54 45 2c 20 49 4e 53 ETE, UPDATE, INS
1e350 45 52 54 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 ERT */. Expr *p
1e360 57 68 65 72 65 3b 20 20 20 20 20 20 20 20 2f 2a Where; /*
1e370 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 The WHERE claus
1e380 65 20 66 6f 72 20 44 45 4c 45 54 45 20 6f 72 20 e for DELETE or
1e390 55 50 44 41 54 45 20 73 74 65 70 73 20 2a 2f 0a UPDATE steps */.
1e3a0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 45 78 70 ExprList *pExp
1e3b0 72 4c 69 73 74 3b 20 2f 2a 20 53 45 54 20 63 6c rList; /* SET cl
1e3c0 61 75 73 65 20 66 6f 72 20 55 50 44 41 54 45 2e ause for UPDATE.
1e3d0 20 2a 2f 0a 20 20 49 64 4c 69 73 74 20 2a 70 49 */. IdList *pI
1e3e0 64 4c 69 73 74 3b 20 20 20 20 20 2f 2a 20 43 6f dList; /* Co
1e3f0 6c 75 6d 6e 20 6e 61 6d 65 73 20 66 6f 72 20 49 lumn names for I
1e400 4e 53 45 52 54 20 2a 2f 0a 20 20 54 72 69 67 67 NSERT */. Trigg
1e410 65 72 53 74 65 70 20 2a 70 4e 65 78 74 3b 20 20 erStep *pNext;
1e420 2f 2a 20 4e 65 78 74 20 69 6e 20 74 68 65 20 6c /* Next in the l
1e430 69 6e 6b 2d 6c 69 73 74 20 2a 2f 0a 20 20 54 72 ink-list */. Tr
1e440 69 67 67 65 72 53 74 65 70 20 2a 70 4c 61 73 74 iggerStep *pLast
1e450 3b 20 20 2f 2a 20 4c 61 73 74 20 65 6c 65 6d 65 ; /* Last eleme
1e460 6e 74 20 69 6e 20 6c 69 6e 6b 2d 6c 69 73 74 2e nt in link-list.
1e470 20 56 61 6c 69 64 20 66 6f 72 20 31 73 74 20 65 Valid for 1st e
1e480 6c 65 6d 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b 0a 0a lem only */.};..
1e490 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
1e4a0 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 6f ing structure co
1e4b0 6e 74 61 69 6e 73 20 69 6e 66 6f 72 6d 61 74 69 ntains informati
1e4c0 6f 6e 20 75 73 65 64 20 62 79 20 74 68 65 20 73 on used by the s
1e4d0 71 6c 69 74 65 46 69 78 2e 2e 2e 0a 2a 2a 20 72 qliteFix....** r
1e4e0 6f 75 74 69 6e 65 73 20 61 73 20 74 68 65 79 20 outines as they
1e4f0 77 61 6c 6b 20 74 68 65 20 70 61 72 73 65 20 74 walk the parse t
1e500 72 65 65 20 74 6f 20 6d 61 6b 65 20 64 61 74 61 ree to make data
1e510 62 61 73 65 20 72 65 66 65 72 65 6e 63 65 73 0a base references.
1e520 2a 2a 20 65 78 70 6c 69 63 69 74 2e 20 20 0a 2a ** explicit. .*
1e530 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
1e540 20 44 62 46 69 78 65 72 20 44 62 46 69 78 65 72 DbFixer DbFixer
1e550 3b 0a 73 74 72 75 63 74 20 44 62 46 69 78 65 72 ;.struct DbFixer
1e560 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 {. Parse *pPar
1e570 73 65 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 se; /* The
1e580 70 61 72 73 69 6e 67 20 63 6f 6e 74 65 78 74 2e parsing context.
1e590 20 20 45 72 72 6f 72 20 6d 65 73 73 61 67 65 73 Error messages
1e5a0 20 77 72 69 74 74 65 6e 20 68 65 72 65 20 2a 2f written here */
1e5b0 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 . Schema *pSche
1e5c0 6d 61 3b 20 20 20 20 2f 2a 20 46 69 78 20 69 74 ma; /* Fix it
1e5d0 65 6d 73 20 74 6f 20 74 68 69 73 20 73 63 68 65 ems to this sche
1e5e0 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 62 56 61 72 ma */. int bVar
1e5f0 4f 6e 6c 79 3b 20 20 20 20 20 20 20 2f 2a 20 43 Only; /* C
1e600 68 65 63 6b 20 66 6f 72 20 76 61 72 69 61 62 6c heck for variabl
1e610 65 20 72 65 66 65 72 65 6e 63 65 73 20 6f 6e 6c e references onl
1e620 79 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 y */. const cha
1e630 72 20 2a 7a 44 62 3b 20 20 20 20 2f 2a 20 4d 61 r *zDb; /* Ma
1e640 6b 65 20 73 75 72 65 20 61 6c 6c 20 6f 62 6a 65 ke sure all obje
1e650 63 74 73 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 cts are containe
1e660 64 20 69 6e 20 74 68 69 73 20 64 61 74 61 62 61 d in this databa
1e670 73 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 se */. const ch
1e680 61 72 20 2a 7a 54 79 70 65 3b 20 20 2f 2a 20 54 ar *zType; /* T
1e690 79 70 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 ype of the conta
1e6a0 69 6e 65 72 20 2d 20 75 73 65 64 20 66 6f 72 20 iner - used for
1e6b0 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 2a error messages *
1e6c0 2f 0a 20 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 20 /. const Token
1e6d0 2a 70 4e 61 6d 65 3b 20 2f 2a 20 4e 61 6d 65 20 *pName; /* Name
1e6e0 6f 66 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 of the container
1e6f0 20 2d 20 75 73 65 64 20 66 6f 72 20 65 72 72 6f - used for erro
1e700 72 20 6d 65 73 73 61 67 65 73 20 2a 2f 0a 7d 3b r messages */.};
1e710 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 63 ../*.** An objec
1e720 74 65 64 20 75 73 65 64 20 74 6f 20 61 63 63 75 ted used to accu
1e730 6d 75 6c 61 74 65 20 74 68 65 20 74 65 78 74 20 mulate the text
1e740 6f 66 20 61 20 73 74 72 69 6e 67 20 77 68 65 72 of a string wher
1e750 65 20 77 65 0a 2a 2a 20 64 6f 20 6e 6f 74 20 6e e we.** do not n
1e760 65 63 65 73 73 61 72 69 6c 79 20 6b 6e 6f 77 20 ecessarily know
1e770 68 6f 77 20 62 69 67 20 74 68 65 20 73 74 72 69 how big the stri
1e780 6e 67 20 77 69 6c 6c 20 62 65 20 69 6e 20 74 68 ng will be in th
1e790 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 e end..*/.struct
1e7a0 20 53 74 72 41 63 63 75 6d 20 7b 0a 20 20 73 71 StrAccum {. sq
1e7b0 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 lite3 *db;
1e7c0 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 64 /* Optional d
1e7d0 61 74 61 62 61 73 65 20 66 6f 72 20 6c 6f 6f 6b atabase for look
1e7e0 61 73 69 64 65 2e 20 20 43 61 6e 20 62 65 20 4e aside. Can be N
1e7f0 55 4c 4c 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a ULL */. char *z
1e800 42 61 73 65 3b 20 20 20 20 20 20 20 20 20 2f 2a Base; /*
1e810 20 41 20 62 61 73 65 20 61 6c 6c 6f 63 61 74 69 A base allocati
1e820 6f 6e 2e 20 20 4e 6f 74 20 66 72 6f 6d 20 6d 61 on. Not from ma
1e830 6c 6c 6f 63 2e 20 2a 2f 0a 20 20 63 68 61 72 20 lloc. */. char
1e840 2a 7a 54 65 78 74 3b 20 20 20 20 20 20 20 20 20 *zText;
1e850 2f 2a 20 54 68 65 20 73 74 72 69 6e 67 20 63 6f /* The string co
1e860 6c 6c 65 63 74 65 64 20 73 6f 20 66 61 72 20 2a llected so far *
1e870 2f 0a 20 20 69 6e 74 20 20 6e 43 68 61 72 3b 20 /. int nChar;
1e880 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 6e 67 /* Leng
1e890 74 68 20 6f 66 20 74 68 65 20 73 74 72 69 6e 67 th of the string
1e8a0 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 so far */. int
1e8b0 20 20 6e 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 nAlloc;
1e8c0 20 20 2f 2a 20 41 6d 6f 75 6e 74 20 6f 66 20 73 /* Amount of s
1e8d0 70 61 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 69 pace allocated i
1e8e0 6e 20 7a 54 65 78 74 20 2a 2f 0a 20 20 69 6e 74 n zText */. int
1e8f0 20 20 6d 78 41 6c 6c 6f 63 3b 20 20 20 20 20 20 mxAlloc;
1e900 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 61 6c 6c /* Maximum all
1e910 6f 77 65 64 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e owed allocation.
1e920 20 20 30 20 66 6f 72 20 6e 6f 20 6d 61 6c 6c 6f 0 for no mallo
1e930 63 20 75 73 61 67 65 20 2a 2f 0a 20 20 75 38 20 c usage */. u8
1e940 20 20 61 63 63 45 72 72 6f 72 3b 20 20 20 20 20 accError;
1e950 20 20 2f 2a 20 53 54 52 41 43 43 55 4d 5f 4e 4f /* STRACCUM_NO
1e960 4d 45 4d 20 6f 72 20 53 54 52 41 43 43 55 4d 5f MEM or STRACCUM_
1e970 54 4f 4f 42 49 47 20 2a 2f 0a 7d 3b 0a 23 64 65 TOOBIG */.};.#de
1e980 66 69 6e 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f fine STRACCUM_NO
1e990 4d 45 4d 20 20 20 31 0a 23 64 65 66 69 6e 65 20 MEM 1.#define
1e9a0 53 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 STRACCUM_TOOBIG
1e9b0 20 32 0a 0a 2f 2a 0a 2a 2a 20 41 20 70 6f 69 6e 2../*.** A poin
1e9c0 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 ter to this stru
1e9d0 63 74 75 72 65 20 69 73 20 75 73 65 64 20 74 6f cture is used to
1e9e0 20 63 6f 6d 6d 75 6e 69 63 61 74 65 20 69 6e 66 communicate inf
1e9f0 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 66 72 6f 6d ormation.** from
1ea00 20 73 71 6c 69 74 65 33 49 6e 69 74 20 61 6e 64 sqlite3Init and
1ea10 20 4f 50 5f 50 61 72 73 65 53 63 68 65 6d 61 20 OP_ParseSchema
1ea20 69 6e 74 6f 20 74 68 65 20 73 71 6c 69 74 65 33 into the sqlite3
1ea30 49 6e 69 74 43 61 6c 6c 62 61 63 6b 2e 0a 2a 2f InitCallback..*/
1ea40 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
1ea50 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b {. sqlite3 *db;
1ea60 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 /* The d
1ea70 61 74 61 62 61 73 65 20 62 65 69 6e 67 20 69 6e atabase being in
1ea80 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 63 itialized */. c
1ea90 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 67 3b 20 har **pzErrMsg;
1eaa0 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 /* Error mess
1eab0 61 67 65 20 73 74 6f 72 65 64 20 68 65 72 65 20 age stored here
1eac0 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b 20 20 20 */. int iDb;
1ead0 20 20 20 20 20 20 20 20 20 2f 2a 20 30 20 66 6f /* 0 fo
1eae0 72 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 2e r main database.
1eaf0 20 20 31 20 66 6f 72 20 54 45 4d 50 2c 20 32 2e 1 for TEMP, 2.
1eb00 2e 20 66 6f 72 20 41 54 54 41 43 48 65 64 20 2a . for ATTACHed *
1eb10 2f 0a 20 20 69 6e 74 20 72 63 3b 20 20 20 20 20 /. int rc;
1eb20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 73 75 6c /* Resul
1eb30 74 20 63 6f 64 65 20 73 74 6f 72 65 64 20 68 65 t code stored he
1eb40 72 65 20 2a 2f 0a 7d 20 49 6e 69 74 44 61 74 61 re */.} InitData
1eb50 3b 0a 0a 2f 2a 0a 2a 2a 20 53 74 72 75 63 74 75 ;../*.** Structu
1eb60 72 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 67 6c re containing gl
1eb70 6f 62 61 6c 20 63 6f 6e 66 69 67 75 72 61 74 69 obal configurati
1eb80 6f 6e 20 64 61 74 61 20 66 6f 72 20 74 68 65 20 on data for the
1eb90 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 0a SQLite library..
1eba0 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 **.** This struc
1ebb0 74 75 72 65 20 61 6c 73 6f 20 63 6f 6e 74 61 69 ture also contai
1ebc0 6e 73 20 73 6f 6d 65 20 73 74 61 74 65 20 69 6e ns some state in
1ebd0 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 formation..*/.st
1ebe0 72 75 63 74 20 53 71 6c 69 74 65 33 43 6f 6e 66 ruct Sqlite3Conf
1ebf0 69 67 20 7b 0a 20 20 69 6e 74 20 62 4d 65 6d 73 ig {. int bMems
1ec00 74 61 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 tat;
1ec10 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
1ec20 20 74 6f 20 65 6e 61 62 6c 65 20 6d 65 6d 6f 72 to enable memor
1ec30 79 20 73 74 61 74 75 73 20 2a 2f 0a 20 20 69 6e y status */. in
1ec40 74 20 62 43 6f 72 65 4d 75 74 65 78 3b 20 20 20 t bCoreMutex;
1ec50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ec60 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62 6c /* True to enabl
1ec70 65 20 63 6f 72 65 20 6d 75 74 65 78 69 6e 67 20 e core mutexing
1ec80 2a 2f 0a 20 20 69 6e 74 20 62 46 75 6c 6c 4d 75 */. int bFullMu
1ec90 74 65 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 tex;
1eca0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 /* True t
1ecb0 6f 20 65 6e 61 62 6c 65 20 66 75 6c 6c 20 6d 75 o enable full mu
1ecc0 74 65 78 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 texing */. int
1ecd0 62 4f 70 65 6e 55 72 69 3b 20 20 20 20 20 20 20 bOpenUri;
1ece0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1ecf0 20 54 72 75 65 20 74 6f 20 69 6e 74 65 72 70 72 True to interpr
1ed00 65 74 20 66 69 6c 65 6e 61 6d 65 73 20 61 73 20 et filenames as
1ed10 55 52 49 73 20 2a 2f 0a 20 20 69 6e 74 20 62 55 URIs */. int bU
1ed20 73 65 43 69 73 3b 20 20 20 20 20 20 20 20 20 20 seCis;
1ed30 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 55 /* U
1ed40 73 65 20 63 6f 76 65 72 69 6e 67 20 69 6e 64 69 se covering indi
1ed50 63 65 73 20 66 6f 72 20 66 75 6c 6c 2d 73 63 61 ces for full-sca
1ed60 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 53 74 ns */. int mxSt
1ed70 72 6c 65 6e 3b 20 20 20 20 20 20 20 20 20 20 20 rlen;
1ed80 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 /* Max
1ed90 69 6d 75 6d 20 73 74 72 69 6e 67 20 6c 65 6e 67 imum string leng
1eda0 74 68 20 2a 2f 0a 20 20 69 6e 74 20 6e 65 76 65 th */. int neve
1edb0 72 43 6f 72 72 75 70 74 3b 20 20 20 20 20 20 20 rCorrupt;
1edc0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 61 74 /* Dat
1edd0 61 62 61 73 65 20 69 73 20 61 6c 77 61 79 73 20 abase is always
1ede0 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 2a 2f 0a 20 well-formed */.
1edf0 20 69 6e 74 20 73 7a 4c 6f 6f 6b 61 73 69 64 65 int szLookaside
1ee00 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1ee10 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 6c 6f /* Default lo
1ee20 6f 6b 61 73 69 64 65 20 62 75 66 66 65 72 20 73 okaside buffer s
1ee30 69 7a 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 6f ize */. int nLo
1ee40 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 20 20 20 okaside;
1ee50 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 /* De
1ee60 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 69 64 65 20 fault lookaside
1ee70 62 75 66 66 65 72 20 63 6f 75 6e 74 20 2a 2f 0a buffer count */.
1ee80 20 20 73 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 sqlite3_mem_me
1ee90 74 68 6f 64 73 20 6d 3b 20 20 20 20 20 20 20 20 thods m;
1eea0 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c /* Low-level
1eeb0 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
1eec0 6f 6e 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a on interface */.
1eed0 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f sqlite3_mutex_
1eee0 6d 65 74 68 6f 64 73 20 6d 75 74 65 78 3b 20 20 methods mutex;
1eef0 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c /* Low-level
1ef00 20 6d 75 74 65 78 20 69 6e 74 65 72 66 61 63 65 mutex interface
1ef10 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 70 63 */. sqlite3_pc
1ef20 61 63 68 65 5f 6d 65 74 68 6f 64 73 32 20 70 63 ache_methods2 pc
1ef30 61 63 68 65 32 3b 20 20 2f 2a 20 4c 6f 77 2d 6c ache2; /* Low-l
1ef40 65 76 65 6c 20 70 61 67 65 2d 63 61 63 68 65 20 evel page-cache
1ef50 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 76 interface */. v
1ef60 6f 69 64 20 2a 70 48 65 61 70 3b 20 20 20 20 20 oid *pHeap;
1ef70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ef80 20 2f 2a 20 48 65 61 70 20 73 74 6f 72 61 67 65 /* Heap storage
1ef90 20 73 70 61 63 65 20 2a 2f 0a 20 20 69 6e 74 20 space */. int
1efa0 6e 48 65 61 70 3b 20 20 20 20 20 20 20 20 20 20 nHeap;
1efb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1efc0 20 53 69 7a 65 20 6f 66 20 70 48 65 61 70 5b 5d Size of pHeap[]
1efd0 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 71 2c */. int mnReq,
1efe0 20 6d 78 52 65 71 3b 20 20 20 20 20 20 20 20 20 mxReq;
1eff0 20 20 20 20 20 20 20 20 2f 2a 20 4d 69 6e 20 61 /* Min a
1f000 6e 64 20 6d 61 78 20 68 65 61 70 20 72 65 71 75 nd max heap requ
1f010 65 73 74 73 20 73 69 7a 65 73 20 2a 2f 0a 20 20 ests sizes */.
1f020 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 73 7a sqlite3_int64 sz
1f030 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 Mmap;
1f040 20 20 2f 2a 20 6d 6d 61 70 28 29 20 73 70 61 63 /* mmap() spac
1f050 65 20 70 65 72 20 6f 70 65 6e 20 66 69 6c 65 20 e per open file
1f060 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 */. sqlite3_int
1f070 36 34 20 6d 78 4d 6d 61 70 3b 20 20 20 20 20 20 64 mxMmap;
1f080 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 /* Maximu
1f090 6d 20 76 61 6c 75 65 20 66 6f 72 20 73 7a 4d 6d m value for szMm
1f0a0 61 70 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 53 ap */. void *pS
1f0b0 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 20 20 cratch;
1f0c0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 63 72 /* Scr
1f0d0 61 74 63 68 20 6d 65 6d 6f 72 79 20 2a 2f 0a 20 atch memory */.
1f0e0 20 69 6e 74 20 73 7a 53 63 72 61 74 63 68 3b 20 int szScratch;
1f0f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f100 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 /* Size of ea
1f110 63 68 20 73 63 72 61 74 63 68 20 62 75 66 66 65 ch scratch buffe
1f120 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 63 72 61 r */. int nScra
1f130 74 63 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 tch;
1f140 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1f150 65 72 20 6f 66 20 73 63 72 61 74 63 68 20 62 75 er of scratch bu
1f160 66 66 65 72 73 20 2a 2f 0a 20 20 76 6f 69 64 20 ffers */. void
1f170 2a 70 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 *pPage;
1f180 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f190 50 61 67 65 20 63 61 63 68 65 20 6d 65 6d 6f 72 Page cache memor
1f1a0 79 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 50 61 67 y */. int szPag
1f1b0 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
1f1c0 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 /* Size
1f1d0 20 6f 66 20 65 61 63 68 20 70 61 67 65 20 69 6e of each page in
1f1e0 20 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e pPage[] */. in
1f1f0 74 20 6e 50 61 67 65 3b 20 20 20 20 20 20 20 20 t nPage;
1f200 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f210 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 /* Number of pag
1f220 65 73 20 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f es in pPage[] */
1f230 0a 20 20 69 6e 74 20 6d 78 50 61 72 73 65 72 53 . int mxParserS
1f240 74 61 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 tack;
1f250 20 20 20 20 20 2f 2a 20 6d 61 78 69 6d 75 6d 20 /* maximum
1f260 64 65 70 74 68 20 6f 66 20 74 68 65 20 70 61 72 depth of the par
1f270 73 65 72 20 73 74 61 63 6b 20 2a 2f 0a 20 20 69 ser stack */. i
1f280 6e 74 20 73 68 61 72 65 64 43 61 63 68 65 45 6e nt sharedCacheEn
1f290 61 62 6c 65 64 3b 20 20 20 20 20 20 20 20 20 20 abled;
1f2a0 20 2f 2a 20 74 72 75 65 20 69 66 20 73 68 61 72 /* true if shar
1f2b0 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 65 6e ed-cache mode en
1f2c0 61 62 6c 65 64 20 2a 2f 0a 20 20 75 33 32 20 73 abled */. u32 s
1f2d0 7a 50 6d 61 3b 20 20 20 20 20 20 20 20 20 20 20 zPma;
1f2e0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f2f0 4d 61 78 69 6d 75 6d 20 53 6f 72 74 65 72 20 50 Maximum Sorter P
1f300 4d 41 20 73 69 7a 65 20 2a 2f 0a 20 20 2f 2a 20 MA size */. /*
1f310 54 68 65 20 61 62 6f 76 65 20 6d 69 67 68 74 20 The above might
1f320 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 74 be initialized t
1f330 6f 20 6e 6f 6e 2d 7a 65 72 6f 2e 20 20 54 68 65 o non-zero. The
1f340 20 66 6f 6c 6c 6f 77 69 6e 67 20 6e 65 65 64 20 following need
1f350 74 6f 20 61 6c 77 61 79 73 0a 20 20 2a 2a 20 69 to always. ** i
1f360 6e 69 74 69 61 6c 6c 79 20 62 65 20 7a 65 72 6f nitially be zero
1f370 2c 20 68 6f 77 65 76 65 72 2e 20 2a 2f 0a 20 20 , however. */.
1f380 69 6e 74 20 69 73 49 6e 69 74 3b 20 20 20 20 20 int isInit;
1f390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f3a0 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 /* True after
1f3b0 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 68 initialization h
1f3c0 61 73 20 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 as finished */.
1f3d0 20 69 6e 74 20 69 6e 50 72 6f 67 72 65 73 73 3b int inProgress;
1f3e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f3f0 20 20 20 2f 2a 20 54 72 75 65 20 77 68 69 6c 65 /* True while
1f400 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
1f410 69 6e 20 70 72 6f 67 72 65 73 73 20 2a 2f 0a 20 in progress */.
1f420 20 69 6e 74 20 69 73 4d 75 74 65 78 49 6e 69 74 int isMutexInit
1f430 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1f440 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 /* True after
1f450 20 6d 75 74 65 78 65 73 20 61 72 65 20 69 6e 69 mutexes are ini
1f460 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e tialized */. in
1f470 74 20 69 73 4d 61 6c 6c 6f 63 49 6e 69 74 3b 20 t isMallocInit;
1f480 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f490 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 6d 61 /* True after ma
1f4a0 6c 6c 6f 63 20 69 73 20 69 6e 69 74 69 61 6c 69 lloc is initiali
1f4b0 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 73 50 zed */. int isP
1f4c0 43 61 63 68 65 49 6e 69 74 3b 20 20 20 20 20 20 CacheInit;
1f4d0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1f4e0 75 65 20 61 66 74 65 72 20 6d 61 6c 6c 6f 63 20 ue after malloc
1f4f0 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a is initialized *
1f500 2f 0a 20 20 69 6e 74 20 6e 52 65 66 49 6e 69 74 /. int nRefInit
1f510 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 20 Mutex;
1f520 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1f530 6f 66 20 75 73 65 72 73 20 6f 66 20 70 49 6e 69 of users of pIni
1f540 74 4d 75 74 65 78 20 2a 2f 0a 20 20 73 71 6c 69 tMutex */. sqli
1f550 74 65 33 5f 6d 75 74 65 78 20 2a 70 49 6e 69 74 te3_mutex *pInit
1f560 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 2f 2a Mutex; /*
1f570 20 4d 75 74 65 78 20 75 73 65 64 20 62 79 20 73 Mutex used by s
1f580 71 6c 69 74 65 33 5f 69 6e 69 74 69 61 6c 69 7a qlite3_initializ
1f590 65 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a e() */. void (*
1f5a0 78 4c 6f 67 29 28 76 6f 69 64 2a 2c 69 6e 74 2c xLog)(void*,int,
1f5b0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 20 2f 2a const char*); /*
1f5c0 20 46 75 6e 63 74 69 6f 6e 20 66 6f 72 20 6c 6f Function for lo
1f5d0 67 67 69 6e 67 20 2a 2f 0a 20 20 76 6f 69 64 20 gging */. void
1f5e0 2a 70 4c 6f 67 41 72 67 3b 20 20 20 20 20 20 20 *pLogArg;
1f5f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f600 2f 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e /* First argumen
1f610 74 20 74 6f 20 78 4c 6f 67 28 29 20 2a 2f 0a 23 t to xLog() */.#
1f620 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
1f630 42 4c 45 5f 53 51 4c 4c 4f 47 0a 20 20 76 6f 69 BLE_SQLLOG. voi
1f640 64 28 2a 78 53 71 6c 6c 6f 67 29 28 76 6f 69 64 d(*xSqllog)(void
1f650 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 *,sqlite3*,const
1f660 20 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a 20 20 char*, int);.
1f670 76 6f 69 64 20 2a 70 53 71 6c 6c 6f 67 41 72 67 void *pSqllogArg
1f680 3b 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 ;.#endif.#ifdef
1f690 53 51 4c 49 54 45 5f 56 44 42 45 5f 43 4f 56 45 SQLITE_VDBE_COVE
1f6a0 52 41 47 45 0a 20 20 2f 2a 20 54 68 65 20 66 6f RAGE. /* The fo
1f6b0 6c 6c 6f 77 69 6e 67 20 63 61 6c 6c 62 61 63 6b llowing callback
1f6c0 20 28 69 66 20 6e 6f 74 20 4e 55 4c 4c 29 20 69 (if not NULL) i
1f6d0 73 20 69 6e 76 6f 6b 65 64 20 6f 6e 20 65 76 65 s invoked on eve
1f6e0 72 79 20 56 44 42 45 20 62 72 61 6e 63 68 0a 20 ry VDBE branch.
1f6f0 20 2a 2a 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 ** operation.
1f700 53 65 74 20 74 68 65 20 63 61 6c 6c 62 61 63 6b Set the callback
1f710 20 75 73 69 6e 67 20 53 51 4c 49 54 45 5f 54 45 using SQLITE_TE
1f720 53 54 43 54 52 4c 5f 56 44 42 45 5f 43 4f 56 45 STCTRL_VDBE_COVE
1f730 52 41 47 45 2e 0a 20 20 2a 2f 0a 20 20 76 6f 69 RAGE.. */. voi
1f740 64 20 28 2a 78 56 64 62 65 42 72 61 6e 63 68 29 d (*xVdbeBranch)
1f750 28 76 6f 69 64 2a 2c 69 6e 74 20 69 53 72 63 4c (void*,int iSrcL
1f760 69 6e 65 2c 75 38 20 65 54 68 69 73 2c 75 38 20 ine,u8 eThis,u8
1f770 65 4d 78 29 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 eMx); /* Callba
1f780 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 56 ck */. void *pV
1f790 64 62 65 42 72 61 6e 63 68 41 72 67 3b 20 20 20 dbeBranchArg;
1f7a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f7b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f7c0 20 20 2f 2a 20 31 73 74 20 61 72 67 75 6d 65 6e /* 1st argumen
1f7d0 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e t */.#endif.#ifn
1f7e0 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
1f7f0 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 20 20 69 BUILTIN_TEST. i
1f800 6e 74 20 28 2a 78 54 65 73 74 43 61 6c 6c 62 61 nt (*xTestCallba
1f810 63 6b 29 28 69 6e 74 29 3b 20 20 20 20 20 20 20 ck)(int);
1f820 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 62 79 20 73 /* Invoked by s
1f830 71 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 29 qlite3FaultSim()
1f840 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 */.#endif. int
1f850 20 62 4c 6f 63 61 6c 74 69 6d 65 46 61 75 6c 74 bLocaltimeFault
1f860 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
1f870 2a 20 54 72 75 65 20 74 6f 20 66 61 69 6c 20 6c * True to fail l
1f880 6f 63 61 6c 74 69 6d 65 28 29 20 63 61 6c 6c 73 ocaltime() calls
1f890 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 */.};../*.** Th
1f8a0 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 is macro is used
1f8b0 20 69 6e 73 69 64 65 20 6f 66 20 61 73 73 65 72 inside of asser
1f8c0 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 20 74 t() statements t
1f8d0 6f 20 69 6e 64 69 63 61 74 65 20 74 68 61 74 0a o indicate that.
1f8e0 2a 2a 20 74 68 65 20 61 73 73 65 72 74 20 69 73 ** the assert is
1f8f0 20 6f 6e 6c 79 20 76 61 6c 69 64 20 6f 6e 20 61 only valid on a
1f900 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 74 well-formed dat
1f910 61 62 61 73 65 2e 20 20 49 6e 73 74 65 61 64 20 abase. Instead
1f920 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 73 of:.**.** as
1f930 73 65 72 74 28 20 58 20 29 3b 0a 2a 2a 0a 2a 2a sert( X );.**.**
1f940 20 4f 6e 65 20 77 72 69 74 65 73 3a 0a 2a 2a 0a One writes:.**.
1f950 2a 2a 20 20 20 20 20 61 73 73 65 72 74 28 20 58 ** assert( X
1f960 20 7c 7c 20 43 4f 52 52 55 50 54 5f 44 42 20 29 || CORRUPT_DB )
1f970 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 52 55 50 54 5f ;.**.** CORRUPT_
1f980 44 42 20 69 73 20 74 72 75 65 20 64 75 72 69 6e DB is true durin
1f990 67 20 6e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 69 g normal operati
1f9a0 6f 6e 2e 20 20 43 4f 52 52 55 50 54 5f 44 42 20 on. CORRUPT_DB
1f9b0 64 6f 65 73 20 6e 6f 74 20 69 6e 64 69 63 61 74 does not indicat
1f9c0 65 0a 2a 2a 20 74 68 61 74 20 74 68 65 20 64 61 e.** that the da
1f9d0 74 61 62 61 73 65 20 69 73 20 64 65 66 69 6e 69 tabase is defini
1f9e0 74 65 6c 79 20 63 6f 72 72 75 70 74 2c 20 6f 6e tely corrupt, on
1f9f0 6c 79 20 74 68 61 74 20 69 74 20 6d 69 67 68 74 ly that it might
1fa00 20 62 65 20 63 6f 72 72 75 70 74 2e 0a 2a 2a 20 be corrupt..**
1fa10 46 6f 72 20 6d 6f 73 74 20 74 65 73 74 20 63 61 For most test ca
1fa20 73 65 73 2c 20 43 4f 52 52 55 50 54 5f 44 42 20 ses, CORRUPT_DB
1fa30 69 73 20 73 65 74 20 74 6f 20 66 61 6c 73 65 20 is set to false
1fa40 75 73 69 6e 67 20 61 20 73 70 65 63 69 61 6c 0a using a special.
1fa50 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 74 5f ** sqlite3_test_
1fa60 63 6f 6e 74 72 6f 6c 28 29 2e 20 20 54 68 69 73 control(). This
1fa70 20 65 6e 61 62 6c 65 73 20 61 73 73 65 72 74 28 enables assert(
1fa80 29 20 73 74 61 74 65 6d 65 6e 74 73 20 74 6f 20 ) statements to
1fa90 70 72 6f 76 65 0a 2a 2a 20 74 68 69 6e 67 73 20 prove.** things
1faa0 74 68 61 74 20 61 72 65 20 61 6c 77 61 79 73 20 that are always
1fab0 74 72 75 65 20 66 6f 72 20 77 65 6c 6c 2d 66 6f true for well-fo
1fac0 72 6d 65 64 20 64 61 74 61 62 61 73 65 73 2e 0a rmed databases..
1fad0 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 52 52 55 */.#define CORRU
1fae0 50 54 5f 44 42 20 20 28 73 71 6c 69 74 65 33 43 PT_DB (sqlite3C
1faf0 6f 6e 66 69 67 2e 6e 65 76 65 72 43 6f 72 72 75 onfig.neverCorru
1fb00 70 74 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 43 6f pt==0)../*.** Co
1fb10 6e 74 65 78 74 20 70 6f 69 6e 74 65 72 20 70 61 ntext pointer pa
1fb20 73 73 65 64 20 64 6f 77 6e 20 74 68 72 6f 75 67 ssed down throug
1fb30 68 20 74 68 65 20 74 72 65 65 2d 77 61 6c 6b 2e h the tree-walk.
1fb40 0a 2a 2f 0a 73 74 72 75 63 74 20 57 61 6c 6b 65 .*/.struct Walke
1fb50 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 45 78 70 r {. int (*xExp
1fb60 72 43 61 6c 6c 62 61 63 6b 29 28 57 61 6c 6b 65 rCallback)(Walke
1fb70 72 2a 2c 20 45 78 70 72 2a 29 3b 20 20 20 20 20 r*, Expr*);
1fb80 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 66 6f 72 20 /* Callback for
1fb90 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 expressions */.
1fba0 20 69 6e 74 20 28 2a 78 53 65 6c 65 63 74 43 61 int (*xSelectCa
1fbb0 6c 6c 62 61 63 6b 29 28 57 61 6c 6b 65 72 2a 2c llback)(Walker*,
1fbc0 53 65 6c 65 63 74 2a 29 3b 20 20 2f 2a 20 43 61 Select*); /* Ca
1fbd0 6c 6c 62 61 63 6b 20 66 6f 72 20 53 45 4c 45 43 llback for SELEC
1fbe0 54 73 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 Ts */. void (*x
1fbf0 53 65 6c 65 63 74 43 61 6c 6c 62 61 63 6b 32 29 SelectCallback2)
1fc00 28 57 61 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a (Walker*,Select*
1fc10 29 3b 2f 2a 20 53 65 63 6f 6e 64 20 63 61 6c 6c );/* Second call
1fc20 62 61 63 6b 20 66 6f 72 20 53 45 4c 45 43 54 73 back for SELECTs
1fc30 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 50 61 */. Parse *pPa
1fc40 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 rse;
1fc50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fc60 2f 2a 20 50 61 72 73 65 72 20 63 6f 6e 74 65 78 /* Parser contex
1fc70 74 2e 20 20 2a 2f 0a 20 20 69 6e 74 20 77 61 6c t. */. int wal
1fc80 6b 65 72 44 65 70 74 68 3b 20 20 20 20 20 20 20 kerDepth;
1fc90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fca0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1fcb0 73 75 62 71 75 65 72 69 65 73 20 2a 2f 0a 20 20 subqueries */.
1fcc0 75 38 20 65 43 6f 64 65 3b 20 20 20 20 20 20 20 u8 eCode;
1fcd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fce0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 73 /* A s
1fcf0 6d 61 6c 6c 20 70 72 6f 63 65 73 73 69 6e 67 20 mall processing
1fd00 63 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 code */. union
1fd10 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
1fd20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fd30 20 20 20 20 2f 2a 20 45 78 74 72 61 20 64 61 74 /* Extra dat
1fd40 61 20 66 6f 72 20 63 61 6c 6c 62 61 63 6b 20 2a a for callback *
1fd50 2f 0a 20 20 20 20 4e 61 6d 65 43 6f 6e 74 65 78 /. NameContex
1fd60 74 20 2a 70 4e 43 3b 20 20 20 20 20 20 20 20 20 t *pNC;
1fd70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fd80 20 2f 2a 20 4e 61 6d 69 6e 67 20 63 6f 6e 74 65 /* Naming conte
1fd90 78 74 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 3b xt */. int n;
1fda0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fdb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fdc0 20 20 20 20 20 2f 2a 20 41 20 63 6f 75 6e 74 65 /* A counte
1fdd0 72 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 43 75 r */. int iCu
1fde0 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
1fdf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fe00 20 20 20 20 2f 2a 20 41 20 63 75 72 73 6f 72 20 /* A cursor
1fe10 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 20 20 53 72 number */. Sr
1fe20 63 4c 69 73 74 20 2a 70 53 72 63 4c 69 73 74 3b cList *pSrcList;
1fe30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fe40 20 20 20 20 20 20 20 20 20 2f 2a 20 46 52 4f 4d /* FROM
1fe50 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 73 clause */. s
1fe60 74 72 75 63 74 20 53 72 63 43 6f 75 6e 74 20 2a truct SrcCount *
1fe70 70 53 72 63 43 6f 75 6e 74 3b 20 20 20 20 20 20 pSrcCount;
1fe80 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 /* Cou
1fe90 6e 74 69 6e 67 20 63 6f 6c 75 6d 6e 20 72 65 66 nting column ref
1fea0 65 72 65 6e 63 65 73 20 2a 2f 0a 20 20 7d 20 75 erences */. } u
1feb0 3b 0a 7d 3b 0a 0a 2f 2a 20 46 6f 72 77 61 72 64 ;.};../* Forward
1fec0 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 20 2a 2f declarations */
1fed0 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b .int sqlite3Walk
1fee0 45 78 70 72 28 57 61 6c 6b 65 72 2a 2c 20 45 78 Expr(Walker*, Ex
1fef0 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 pr*);.int sqlite
1ff00 33 57 61 6c 6b 45 78 70 72 4c 69 73 74 28 57 61 3WalkExprList(Wa
1ff10 6c 6b 65 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a lker*, ExprList*
1ff20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 );.int sqlite3Wa
1ff30 6c 6b 53 65 6c 65 63 74 28 57 61 6c 6b 65 72 2a lkSelect(Walker*
1ff40 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 , Select*);.int
1ff50 73 71 6c 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 sqlite3WalkSelec
1ff60 74 45 78 70 72 28 57 61 6c 6b 65 72 2a 2c 20 53 tExpr(Walker*, S
1ff70 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
1ff80 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 46 72 ite3WalkSelectFr
1ff90 6f 6d 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 om(Walker*, Sele
1ffa0 63 74 2a 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 ct*);../*.** Ret
1ffb0 75 72 6e 20 63 6f 64 65 20 66 72 6f 6d 20 74 68 urn code from th
1ffc0 65 20 70 61 72 73 65 2d 74 72 65 65 20 77 61 6c e parse-tree wal
1ffd0 6b 69 6e 67 20 70 72 69 6d 69 74 69 76 65 73 20 king primitives
1ffe0 61 6e 64 20 74 68 65 69 72 0a 2a 2a 20 63 61 6c and their.** cal
1fff0 6c 62 61 63 6b 73 2e 0a 2a 2f 0a 23 64 65 66 69 lbacks..*/.#defi
20000 6e 65 20 57 52 43 5f 43 6f 6e 74 69 6e 75 65 20 ne WRC_Continue
20010 20 20 20 30 20 20 20 2f 2a 20 43 6f 6e 74 69 6e 0 /* Contin
20020 75 65 20 64 6f 77 6e 20 69 6e 74 6f 20 63 68 69 ue down into chi
20030 6c 64 72 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 ldren */.#define
20040 20 57 52 43 5f 50 72 75 6e 65 20 20 20 20 20 20 WRC_Prune
20050 20 31 20 20 20 2f 2a 20 4f 6d 69 74 20 63 68 69 1 /* Omit chi
20060 6c 64 72 65 6e 20 62 75 74 20 63 6f 6e 74 69 6e ldren but contin
20070 75 65 20 77 61 6c 6b 69 6e 67 20 73 69 62 6c 69 ue walking sibli
20080 6e 67 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 ngs */.#define W
20090 52 43 5f 41 62 6f 72 74 20 20 20 20 20 20 20 32 RC_Abort 2
200a0 20 20 20 2f 2a 20 41 62 61 6e 64 6f 6e 20 74 68 /* Abandon th
200b0 65 20 74 72 65 65 20 77 61 6c 6b 20 2a 2f 0a 0a e tree walk */..
200c0 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
200d0 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 e of this struct
200e0 75 72 65 20 72 65 70 72 65 73 65 6e 74 73 20 61 ure represents a
200f0 20 73 65 74 20 6f 66 20 6f 6e 65 20 6f 72 20 6d set of one or m
20100 6f 72 65 20 43 54 45 73 0a 2a 2a 20 28 63 6f 6d ore CTEs.** (com
20110 6d 6f 6e 20 74 61 62 6c 65 20 65 78 70 72 65 73 mon table expres
20120 73 69 6f 6e 73 29 20 63 72 65 61 74 65 64 20 62 sions) created b
20130 79 20 61 20 73 69 6e 67 6c 65 20 57 49 54 48 20 y a single WITH
20140 63 6c 61 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 63 clause..*/.struc
20150 74 20 57 69 74 68 20 7b 0a 20 20 69 6e 74 20 6e t With {. int n
20160 43 74 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 Cte;
20170 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
20180 6d 62 65 72 20 6f 66 20 43 54 45 73 20 69 6e 20 mber of CTEs in
20190 74 68 65 20 57 49 54 48 20 63 6c 61 75 73 65 20 the WITH clause
201a0 2a 2f 0a 20 20 57 69 74 68 20 2a 70 4f 75 74 65 */. With *pOute
201b0 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
201c0 20 20 20 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 69 /* Containi
201d0 6e 67 20 57 49 54 48 20 63 6c 61 75 73 65 2c 20 ng WITH clause,
201e0 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 20 20 73 74 72 or NULL */. str
201f0 75 63 74 20 43 74 65 20 7b 20 20 20 20 20 20 20 uct Cte {
20200 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
20210 46 6f 72 20 65 61 63 68 20 43 54 45 20 69 6e 20 For each CTE in
20220 74 68 65 20 57 49 54 48 20 63 6c 61 75 73 65 2e the WITH clause.
20230 2e 2e 2e 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 ... */. char
20240 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
20250 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 /* Na
20260 6d 65 20 6f 66 20 74 68 69 73 20 43 54 45 20 2a me of this CTE *
20270 2f 0a 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a /. ExprList *
20280 70 43 6f 6c 73 3b 20 20 20 20 20 20 20 20 20 20 pCols;
20290 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 /* List of
202a0 20 65 78 70 6c 69 63 69 74 20 63 6f 6c 75 6d 6e explicit column
202b0 20 6e 61 6d 65 73 2c 20 6f 72 20 4e 55 4c 4c 20 names, or NULL
202c0 2a 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a 70 */. Select *p
202d0 53 65 6c 65 63 74 3b 20 20 20 20 20 20 20 20 20 Select;
202e0 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 65 /* The de
202f0 66 69 6e 69 74 69 6f 6e 20 6f 66 20 74 68 69 73 finition of this
20300 20 43 54 45 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 CTE */. cons
20310 74 20 63 68 61 72 20 2a 7a 45 72 72 3b 20 20 20 t char *zErr;
20320 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 /* E
20330 72 72 6f 72 20 6d 65 73 73 61 67 65 20 66 6f 72 rror message for
20340 20 63 69 72 63 75 6c 61 72 20 72 65 66 65 72 65 circular refere
20350 6e 63 65 73 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d nces */. } a[1]
20360 3b 0a 7d 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c ;.};..#ifdef SQL
20370 49 54 45 5f 44 45 42 55 47 0a 2f 2a 0a 2a 2a 20 ITE_DEBUG./*.**
20380 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
20390 68 65 20 54 72 65 65 56 69 65 77 20 6f 62 6a 65 he TreeView obje
203a0 63 74 20 69 73 20 75 73 65 64 20 66 6f 72 20 70 ct is used for p
203b0 72 69 6e 74 69 6e 67 20 74 68 65 20 63 6f 6e 74 rinting the cont
203c0 65 6e 74 20 6f 66 0a 2a 2a 20 64 61 74 61 20 73 ent of.** data s
203d0 74 72 75 63 74 75 72 65 73 20 6f 6e 20 73 71 6c tructures on sql
203e0 69 74 65 33 44 65 62 75 67 50 72 69 6e 74 66 28 ite3DebugPrintf(
203f0 29 20 75 73 69 6e 67 20 61 20 74 72 65 65 2d 6c ) using a tree-l
20400 69 6b 65 20 76 69 65 77 2e 0a 2a 2f 0a 73 74 72 ike view..*/.str
20410 75 63 74 20 54 72 65 65 56 69 65 77 20 7b 0a 20 uct TreeView {.
20420 20 69 6e 74 20 69 4c 65 76 65 6c 3b 20 20 20 20 int iLevel;
20430 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 69 63 /* Whic
20440 68 20 6c 65 76 65 6c 20 6f 66 20 74 68 65 20 74 h level of the t
20450 72 65 65 20 77 65 20 61 72 65 20 6f 6e 20 2a 2f ree we are on */
20460 0a 20 20 75 38 20 20 62 4c 69 6e 65 5b 31 30 30 . u8 bLine[100
20470 5d 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 44 72 ]; /* Dr
20480 61 77 20 76 65 72 74 69 63 61 6c 20 69 6e 20 63 aw vertical in c
20490 6f 6c 75 6d 6e 20 69 20 69 66 20 62 4c 69 6e 65 olumn i if bLine
204a0 5b 69 5d 20 69 73 20 74 72 75 65 20 2a 2f 0a 7d [i] is true */.}
204b0 3b 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 ;.#endif /* SQLI
204c0 54 45 5f 44 45 42 55 47 20 2a 2f 0a 0a 2f 2a 0a TE_DEBUG */../*.
204d0 2a 2a 20 41 73 73 75 6d 69 6e 67 20 7a 49 6e 20 ** Assuming zIn
204e0 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 20 66 69 points to the fi
204f0 72 73 74 20 62 79 74 65 20 6f 66 20 61 20 55 54 rst byte of a UT
20500 46 2d 38 20 63 68 61 72 61 63 74 65 72 2c 0a 2a F-8 character,.*
20510 2a 20 61 64 76 61 6e 63 65 20 7a 49 6e 20 74 6f * advance zIn to
20520 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 20 66 69 point to the fi
20530 72 73 74 20 62 79 74 65 20 6f 66 20 74 68 65 20 rst byte of the
20540 6e 65 78 74 20 55 54 46 2d 38 20 63 68 61 72 61 next UTF-8 chara
20550 63 74 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 cter..*/.#define
20560 20 53 51 4c 49 54 45 5f 53 4b 49 50 5f 55 54 46 SQLITE_SKIP_UTF
20570 38 28 7a 49 6e 29 20 7b 20 20 20 20 20 20 20 20 8(zIn) {
20580 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20590 5c 0a 20 20 69 66 28 20 28 2a 28 7a 49 6e 2b 2b \. if( (*(zIn++
205a0 29 29 3e 3d 30 78 63 30 20 29 7b 20 20 20 20 20 ))>=0xc0 ){
205b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
205c0 20 20 20 20 20 20 20 20 20 5c 0a 20 20 20 20 77 \. w
205d0 68 69 6c 65 28 20 28 2a 7a 49 6e 20 26 20 30 78 hile( (*zIn & 0x
205e0 63 30 29 3d 3d 30 78 38 30 20 29 7b 20 7a 49 6e c0)==0x80 ){ zIn
205f0 2b 2b 3b 20 7d 20 20 20 20 20 20 20 20 20 20 20 ++; }
20600 20 20 5c 0a 20 20 7d 20 20 20 20 20 20 20 20 20 \. }
20610 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20630 20 20 20 20 20 20 20 20 20 20 20 5c 0a 7d 0a 0a \.}..
20640 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 /*.** The SQLITE
20650 5f 2a 5f 42 4b 50 54 20 6d 61 63 72 6f 73 20 61 _*_BKPT macros a
20660 72 65 20 73 75 62 73 74 69 74 75 74 65 73 20 66 re substitutes f
20670 6f 72 20 74 68 65 20 65 72 72 6f 72 20 63 6f 64 or the error cod
20680 65 73 20 77 69 74 68 0a 2a 2a 20 74 68 65 20 73 es with.** the s
20690 61 6d 65 20 6e 61 6d 65 20 62 75 74 20 77 69 74 ame name but wit
206a0 68 6f 75 74 20 74 68 65 20 5f 42 4b 50 54 20 73 hout the _BKPT s
206b0 75 66 66 69 78 2e 20 20 54 68 65 73 65 20 6d 61 uffix. These ma
206c0 63 72 6f 73 20 69 6e 76 6f 6b 65 0a 2a 2a 20 72 cros invoke.** r
206d0 6f 75 74 69 6e 65 73 20 74 68 61 74 20 72 65 70 outines that rep
206e0 6f 72 74 20 74 68 65 20 6c 69 6e 65 2d 6e 75 6d ort the line-num
206f0 62 65 72 20 6f 6e 20 77 68 69 63 68 20 74 68 65 ber on which the
20700 20 65 72 72 6f 72 20 6f 72 69 67 69 6e 61 74 65 error originate
20710 64 0a 2a 2a 20 75 73 69 6e 67 20 73 71 6c 69 74 d.** using sqlit
20720 65 33 5f 6c 6f 67 28 29 2e 20 20 54 68 65 20 72 e3_log(). The r
20730 6f 75 74 69 6e 65 73 20 61 6c 73 6f 20 70 72 6f outines also pro
20740 76 69 64 65 20 61 20 63 6f 6e 76 65 6e 69 65 6e vide a convenien
20750 74 20 70 6c 61 63 65 0a 2a 2a 20 74 6f 20 73 65 t place.** to se
20760 74 20 61 20 64 65 62 75 67 67 65 72 20 62 72 65 t a debugger bre
20770 61 6b 70 6f 69 6e 74 2e 0a 2a 2f 0a 69 6e 74 20 akpoint..*/.int
20780 73 71 6c 69 74 65 33 43 6f 72 72 75 70 74 45 72 sqlite3CorruptEr
20790 72 6f 72 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 ror(int);.int sq
207a0 6c 69 74 65 33 4d 69 73 75 73 65 45 72 72 6f 72 lite3MisuseError
207b0 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 (int);.int sqlit
207c0 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 e3CantopenError(
207d0 69 6e 74 29 3b 0a 23 64 65 66 69 6e 65 20 53 51 int);.#define SQ
207e0 4c 49 54 45 5f 43 4f 52 52 55 50 54 5f 42 4b 50 LITE_CORRUPT_BKP
207f0 54 20 73 71 6c 69 74 65 33 43 6f 72 72 75 70 74 T sqlite3Corrupt
20800 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a Error(__LINE__).
20810 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
20820 49 53 55 53 45 5f 42 4b 50 54 20 73 71 6c 69 74 ISUSE_BKPT sqlit
20830 65 33 4d 69 73 75 73 65 45 72 72 6f 72 28 5f 5f e3MisuseError(__
20840 4c 49 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 LINE__).#define
20850 53 51 4c 49 54 45 5f 43 41 4e 54 4f 50 45 4e 5f SQLITE_CANTOPEN_
20860 42 4b 50 54 20 73 71 6c 69 74 65 33 43 61 6e 74 BKPT sqlite3Cant
20870 6f 70 65 6e 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 openError(__LINE
20880 5f 5f 29 0a 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 34 __).../*.** FTS4
20890 20 69 73 20 72 65 61 6c 6c 79 20 61 6e 20 65 78 is really an ex
208a0 74 65 6e 73 69 6f 6e 20 66 6f 72 20 46 54 53 33 tension for FTS3
208b0 2e 20 20 49 74 20 69 73 20 65 6e 61 62 6c 65 64 . It is enabled
208c0 20 75 73 69 6e 67 20 74 68 65 0a 2a 2a 20 53 51 using the.** SQ
208d0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 LITE_ENABLE_FTS3
208e0 20 6d 61 63 72 6f 2e 20 20 42 75 74 20 74 6f 20 macro. But to
208f0 61 76 6f 69 64 20 63 6f 6e 66 75 73 69 6f 6e 20 avoid confusion
20900 77 65 20 61 6c 73 6f 20 63 61 6c 6c 0a 2a 2a 20 we also call.**
20910 74 68 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c the SQLITE_ENABL
20920 45 5f 46 54 53 34 20 6d 61 63 72 6f 20 74 6f 20 E_FTS4 macro to
20930 73 65 72 76 65 20 61 73 20 61 6e 20 61 6c 69 61 serve as an alia
20940 73 20 66 6f 72 20 53 51 4c 49 54 45 5f 45 4e 41 s for SQLITE_ENA
20950 42 4c 45 5f 46 54 53 33 2e 0a 2a 2f 0a 23 69 66 BLE_FTS3..*/.#if
20960 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
20970 45 4e 41 42 4c 45 5f 46 54 53 34 29 20 26 26 20 ENABLE_FTS4) &&
20980 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
20990 45 4e 41 42 4c 45 5f 46 54 53 33 29 0a 23 20 64 ENABLE_FTS3).# d
209a0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 efine SQLITE_ENA
209b0 42 4c 45 5f 46 54 53 33 20 31 0a 23 65 6e 64 69 BLE_FTS3 1.#endi
209c0 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 74 79 f../*.** The cty
209d0 70 65 2e 68 20 68 65 61 64 65 72 20 69 73 20 6e pe.h header is n
209e0 65 65 64 65 64 20 66 6f 72 20 6e 6f 6e 2d 41 53 eeded for non-AS
209f0 43 49 49 20 73 79 73 74 65 6d 73 2e 20 20 49 74 CII systems. It
20a00 20 69 73 20 61 6c 73 6f 0a 2a 2a 20 6e 65 65 64 is also.** need
20a10 65 64 20 62 79 20 46 54 53 33 20 77 68 65 6e 20 ed by FTS3 when
20a20 46 54 53 33 20 69 73 20 69 6e 63 6c 75 64 65 64 FTS3 is included
20a30 20 69 6e 20 74 68 65 20 61 6d 61 6c 67 61 6d 61 in the amalgama
20a40 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 tion..*/.#if !de
20a50 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 41 53 43 fined(SQLITE_ASC
20a60 49 49 29 20 7c 7c 20 5c 0a 20 20 20 20 28 64 65 II) || \. (de
20a70 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
20a80 42 4c 45 5f 46 54 53 33 29 20 26 26 20 64 65 66 BLE_FTS3) && def
20a90 69 6e 65 64 28 53 51 4c 49 54 45 5f 41 4d 41 4c ined(SQLITE_AMAL
20aa0 47 41 4d 41 54 49 4f 4e 29 29 0a 23 20 69 6e 63 GAMATION)).# inc
20ab0 6c 75 64 65 20 3c 63 74 79 70 65 2e 68 3e 0a 23 lude <ctype.h>.#
20ac0 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
20ad0 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f following macro
20ae0 73 20 6d 69 6d 69 63 20 74 68 65 20 73 74 61 6e s mimic the stan
20af0 64 61 72 64 20 6c 69 62 72 61 72 79 20 66 75 6e dard library fun
20b00 63 74 69 6f 6e 73 20 74 6f 75 70 70 65 72 28 29 ctions toupper()
20b10 2c 0a 2a 2a 20 69 73 73 70 61 63 65 28 29 2c 20 ,.** isspace(),
20b20 69 73 61 6c 6e 75 6d 28 29 2c 20 69 73 64 69 67 isalnum(), isdig
20b30 69 74 28 29 20 61 6e 64 20 69 73 78 64 69 67 69 it() and isxdigi
20b40 74 28 29 2c 20 72 65 73 70 65 63 74 69 76 65 6c t(), respectivel
20b50 79 2e 20 54 68 65 0a 2a 2a 20 73 71 6c 69 74 65 y. The.** sqlite
20b60 20 76 65 72 73 69 6f 6e 73 20 6f 6e 6c 79 20 77 versions only w
20b70 6f 72 6b 20 66 6f 72 20 41 53 43 49 49 20 63 68 ork for ASCII ch
20b80 61 72 61 63 74 65 72 73 2c 20 72 65 67 61 72 64 aracters, regard
20b90 6c 65 73 73 20 6f 66 20 6c 6f 63 61 6c 65 2e 0a less of locale..
20ba0 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
20bb0 5f 41 53 43 49 49 0a 23 20 64 65 66 69 6e 65 20 _ASCII.# define
20bc0 73 71 6c 69 74 65 33 54 6f 75 70 70 65 72 28 78 sqlite3Toupper(x
20bd0 29 20 20 28 28 78 29 26 7e 28 73 71 6c 69 74 65 ) ((x)&~(sqlite
20be0 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 3CtypeMap[(unsig
20bf0 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 ned char)(x)]&0x
20c00 32 30 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 20)).# define sq
20c10 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 29 20 lite3Isspace(x)
20c20 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d (sqlite3CtypeM
20c30 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 ap[(unsigned cha
20c40 72 29 28 78 29 5d 26 30 78 30 31 29 0a 23 20 64 r)(x)]&0x01).# d
20c50 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 61 efine sqlite3Isa
20c60 6c 6e 75 6d 28 78 29 20 20 20 28 73 71 6c 69 74 lnum(x) (sqlit
20c70 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 e3CtypeMap[(unsi
20c80 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 gned char)(x)]&0
20c90 78 30 36 29 0a 23 20 64 65 66 69 6e 65 20 73 71 x06).# define sq
20ca0 6c 69 74 65 33 49 73 61 6c 70 68 61 28 78 29 20 lite3Isalpha(x)
20cb0 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d (sqlite3CtypeM
20cc0 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 ap[(unsigned cha
20cd0 72 29 28 78 29 5d 26 30 78 30 32 29 0a 23 20 64 r)(x)]&0x02).# d
20ce0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 64 efine sqlite3Isd
20cf0 69 67 69 74 28 78 29 20 20 20 28 73 71 6c 69 74 igit(x) (sqlit
20d00 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 e3CtypeMap[(unsi
20d10 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 gned char)(x)]&0
20d20 78 30 34 29 0a 23 20 64 65 66 69 6e 65 20 73 71 x04).# define sq
20d30 6c 69 74 65 33 49 73 78 64 69 67 69 74 28 78 29 lite3Isxdigit(x)
20d40 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d (sqlite3CtypeM
20d50 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 ap[(unsigned cha
20d60 72 29 28 78 29 5d 26 30 78 30 38 29 0a 23 20 64 r)(x)]&0x08).# d
20d70 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f 6c efine sqlite3Tol
20d80 6f 77 65 72 28 78 29 20 20 20 28 73 71 6c 69 74 ower(x) (sqlit
20d90 65 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b 28 e3UpperToLower[(
20da0 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
20db0 29 5d 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 )]).#else.# defi
20dc0 6e 65 20 73 71 6c 69 74 65 33 54 6f 75 70 70 65 ne sqlite3Touppe
20dd0 72 28 78 29 20 20 20 74 6f 75 70 70 65 72 28 28 r(x) toupper((
20de0 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
20df0 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 )).# define sqli
20e00 74 65 33 49 73 73 70 61 63 65 28 78 29 20 20 20 te3Isspace(x)
20e10 69 73 73 70 61 63 65 28 28 75 6e 73 69 67 6e 65 isspace((unsigne
20e20 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 d char)(x)).# de
20e30 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 61 6c fine sqlite3Isal
20e40 6e 75 6d 28 78 29 20 20 20 69 73 61 6c 6e 75 6d num(x) isalnum
20e50 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
20e60 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
20e70 6c 69 74 65 33 49 73 61 6c 70 68 61 28 78 29 20 lite3Isalpha(x)
20e80 20 20 69 73 61 6c 70 68 61 28 28 75 6e 73 69 67 isalpha((unsig
20e90 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 ned char)(x)).#
20ea0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
20eb0 64 69 67 69 74 28 78 29 20 20 20 69 73 64 69 67 digit(x) isdig
20ec0 69 74 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 it((unsigned cha
20ed0 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
20ee0 73 71 6c 69 74 65 33 49 73 78 64 69 67 69 74 28 sqlite3Isxdigit(
20ef0 78 29 20 20 69 73 78 64 69 67 69 74 28 28 75 6e x) isxdigit((un
20f00 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 signed char)(x))
20f10 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
20f20 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 20 74 6f 3Tolower(x) to
20f30 6c 6f 77 65 72 28 28 75 6e 73 69 67 6e 65 64 20 lower((unsigned
20f40 63 68 61 72 29 28 78 29 29 0a 23 65 6e 64 69 66 char)(x)).#endif
20f50 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
20f60 4f 4d 49 54 5f 43 4f 4d 50 49 4c 45 4f 50 54 49 OMIT_COMPILEOPTI
20f70 4f 4e 5f 44 49 41 47 53 0a 69 6e 74 20 73 71 6c ON_DIAGS.int sql
20f80 69 74 65 33 49 73 49 64 43 68 61 72 28 75 38 29 ite3IsIdChar(u8)
20f90 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ;.#endif../*.**
20fa0 49 6e 74 65 72 6e 61 6c 20 66 75 6e 63 74 69 6f Internal functio
20fb0 6e 20 70 72 6f 74 6f 74 79 70 65 73 0a 2a 2f 0a n prototypes.*/.
20fc0 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 #define sqlite3S
20fd0 74 72 49 43 6d 70 20 73 71 6c 69 74 65 33 5f 73 trICmp sqlite3_s
20fe0 74 72 69 63 6d 70 0a 69 6e 74 20 73 71 6c 69 74 tricmp.int sqlit
20ff0 65 33 53 74 72 6c 65 6e 33 30 28 63 6f 6e 73 74 e3Strlen30(const
21000 20 63 68 61 72 2a 29 3b 0a 23 64 65 66 69 6e 65 char*);.#define
21010 20 73 71 6c 69 74 65 33 53 74 72 4e 49 43 6d 70 sqlite3StrNICmp
21020 20 73 71 6c 69 74 65 33 5f 73 74 72 6e 69 63 6d sqlite3_strnicm
21030 70 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 p..int sqlite3Ma
21040 6c 6c 6f 63 49 6e 69 74 28 76 6f 69 64 29 3b 0a llocInit(void);.
21050 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 6c 6c void sqlite3Mall
21060 6f 63 45 6e 64 28 76 6f 69 64 29 3b 0a 76 6f 69 ocEnd(void);.voi
21070 64 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 d *sqlite3Malloc
21080 28 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c (u64);.void *sql
21090 69 74 65 33 4d 61 6c 6c 6f 63 5a 65 72 6f 28 75 ite3MallocZero(u
210a0 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 64);.void *sqlit
210b0 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 6f 28 73 e3DbMallocZero(s
210c0 71 6c 69 74 65 33 2a 2c 20 75 36 34 29 3b 0a 76 qlite3*, u64);.v
210d0 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 oid *sqlite3DbMa
210e0 6c 6c 6f 63 52 61 77 28 73 71 6c 69 74 65 33 2a llocRaw(sqlite3*
210f0 2c 20 75 36 34 29 3b 0a 63 68 61 72 20 2a 73 71 , u64);.char *sq
21100 6c 69 74 65 33 44 62 53 74 72 44 75 70 28 73 71 lite3DbStrDup(sq
21110 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
21120 72 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 r*);.char *sqlit
21130 65 33 44 62 53 74 72 4e 44 75 70 28 73 71 6c 69 e3DbStrNDup(sqli
21140 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
21150 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 , u64);.void *sq
21160 6c 69 74 65 33 52 65 61 6c 6c 6f 63 28 76 6f 69 lite3Realloc(voi
21170 64 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a d*, u64);.void *
21180 73 71 6c 69 74 65 33 44 62 52 65 61 6c 6c 6f 63 sqlite3DbRealloc
21190 4f 72 46 72 65 65 28 73 71 6c 69 74 65 33 20 2a OrFree(sqlite3 *
211a0 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 29 3b 0a , void *, u64);.
211b0 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 62 52 void *sqlite3DbR
211c0 65 61 6c 6c 6f 63 28 73 71 6c 69 74 65 33 20 2a ealloc(sqlite3 *
211d0 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 29 3b 0a , void *, u64);.
211e0 76 6f 69 64 20 73 71 6c 69 74 65 33 44 62 46 72 void sqlite3DbFr
211f0 65 65 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f 69 ee(sqlite3*, voi
21200 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 d*);.int sqlite3
21210 4d 61 6c 6c 6f 63 53 69 7a 65 28 76 6f 69 64 2a MallocSize(void*
21220 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 );.int sqlite3Db
21230 4d 61 6c 6c 6f 63 53 69 7a 65 28 73 71 6c 69 74 MallocSize(sqlit
21240 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 e3*, void*);.voi
21250 64 20 2a 73 71 6c 69 74 65 33 53 63 72 61 74 63 d *sqlite3Scratc
21260 68 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f hMalloc(int);.vo
21270 69 64 20 73 71 6c 69 74 65 33 53 63 72 61 74 63 id sqlite3Scratc
21280 68 46 72 65 65 28 76 6f 69 64 2a 29 3b 0a 76 6f hFree(void*);.vo
21290 69 64 20 2a 73 71 6c 69 74 65 33 50 61 67 65 4d id *sqlite3PageM
212a0 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f 69 64 alloc(int);.void
212b0 20 73 71 6c 69 74 65 33 50 61 67 65 46 72 65 65 sqlite3PageFree
212c0 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 (void*);.void sq
212d0 6c 69 74 65 33 4d 65 6d 53 65 74 44 65 66 61 75 lite3MemSetDefau
212e0 6c 74 28 76 6f 69 64 29 3b 0a 23 69 66 6e 64 65 lt(void);.#ifnde
212f0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 f SQLITE_OMIT_BU
21300 49 4c 54 49 4e 5f 54 45 53 54 0a 76 6f 69 64 20 ILTIN_TEST.void
21310 73 71 6c 69 74 65 33 42 65 6e 69 67 6e 4d 61 6c sqlite3BenignMal
21320 6c 6f 63 48 6f 6f 6b 73 28 76 6f 69 64 20 28 2a locHooks(void (*
21330 29 28 76 6f 69 64 29 2c 20 76 6f 69 64 20 28 2a )(void), void (*
21340 29 28 76 6f 69 64 29 29 3b 0a 23 65 6e 64 69 66 )(void));.#endif
21350 0a 69 6e 74 20 73 71 6c 69 74 65 33 48 65 61 70 .int sqlite3Heap
21360 4e 65 61 72 6c 79 46 75 6c 6c 28 76 6f 69 64 29 NearlyFull(void)
21370 3b 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 20 73 79 73 74 ;../*.** On syst
21380 65 6d 73 20 77 69 74 68 20 61 6d 70 6c 65 20 73 ems with ample s
21390 74 61 63 6b 20 73 70 61 63 65 20 61 6e 64 20 74 tack space and t
213a0 68 61 74 20 73 75 70 70 6f 72 74 20 61 6c 6c 6f hat support allo
213b0 63 61 28 29 2c 20 6d 61 6b 65 0a 2a 2a 20 75 73 ca(), make.** us
213c0 65 20 6f 66 20 61 6c 6c 6f 63 61 28 29 20 74 6f e of alloca() to
213d0 20 6f 62 74 61 69 6e 20 73 70 61 63 65 20 66 6f obtain space fo
213e0 72 20 6c 61 72 67 65 20 61 75 74 6f 6d 61 74 69 r large automati
213f0 63 20 6f 62 6a 65 63 74 73 2e 20 20 42 79 20 64 c objects. By d
21400 65 66 61 75 6c 74 2c 0a 2a 2a 20 6f 62 74 61 69 efault,.** obtai
21410 6e 20 73 70 61 63 65 20 66 72 6f 6d 20 6d 61 6c n space from mal
21420 6c 6f 63 28 29 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 loc()..**.** The
21430 20 61 6c 6c 6f 63 61 28 29 20 72 6f 75 74 69 6e alloca() routin
21440 65 20 6e 65 76 65 72 20 72 65 74 75 72 6e 73 20 e never returns
21450 4e 55 4c 4c 2e 20 20 54 68 69 73 20 77 69 6c 6c NULL. This will
21460 20 63 61 75 73 65 20 63 6f 64 65 20 70 61 74 68 cause code path
21470 73 0a 2a 2a 20 74 68 61 74 20 64 65 61 6c 20 77 s.** that deal w
21480 69 74 68 20 73 71 6c 69 74 65 33 53 74 61 63 6b ith sqlite3Stack
21490 41 6c 6c 6f 63 28 29 20 66 61 69 6c 75 72 65 73 Alloc() failures
214a0 20 74 6f 20 62 65 20 75 6e 72 65 61 63 68 61 62 to be unreachab
214b0 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 le..*/.#ifdef SQ
214c0 4c 49 54 45 5f 55 53 45 5f 41 4c 4c 4f 43 41 0a LITE_USE_ALLOCA.
214d0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
214e0 53 74 61 63 6b 41 6c 6c 6f 63 52 61 77 28 44 2c StackAllocRaw(D,
214f0 4e 29 20 20 20 61 6c 6c 6f 63 61 28 4e 29 0a 23 N) alloca(N).#
21500 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 define sqlite3S
21510 74 61 63 6b 41 6c 6c 6f 63 5a 65 72 6f 28 44 2c tackAllocZero(D,
21520 4e 29 20 20 6d 65 6d 73 65 74 28 61 6c 6c 6f 63 N) memset(alloc
21530 61 28 4e 29 2c 20 30 2c 20 4e 29 0a 23 20 64 65 a(N), 0, N).# de
21540 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
21550 6b 46 72 65 65 28 44 2c 50 29 20 20 20 20 20 20 kFree(D,P)
21560 20 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 .#else.# define
21570 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c sqlite3StackAll
21580 6f 63 52 61 77 28 44 2c 4e 29 20 20 20 73 71 6c ocRaw(D,N) sql
21590 69 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 28 ite3DbMallocRaw(
215a0 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 D,N).# define sq
215b0 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 5a lite3StackAllocZ
215c0 65 72 6f 28 44 2c 4e 29 20 20 73 71 6c 69 74 65 ero(D,N) sqlite
215d0 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 6f 28 44 2c 3DbMallocZero(D,
215e0 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 N).# define sqli
215f0 74 65 33 53 74 61 63 6b 46 72 65 65 28 44 2c 50 te3StackFree(D,P
21600 29 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 44 ) sqlite3D
21610 62 46 72 65 65 28 44 2c 50 29 0a 23 65 6e 64 69 bFree(D,P).#endi
21620 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 f..#ifdef SQLITE
21630 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 33 0a _ENABLE_MEMSYS3.
21640 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 65 const sqlite3_me
21650 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 74 m_methods *sqlit
21660 65 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 33 28 e3MemGetMemsys3(
21670 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 23 69 void);.#endif.#i
21680 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
21690 4c 45 5f 4d 45 4d 53 59 53 35 0a 63 6f 6e 73 74 LE_MEMSYS5.const
216a0 20 73 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 sqlite3_mem_met
216b0 68 6f 64 73 20 2a 73 71 6c 69 74 65 33 4d 65 6d hods *sqlite3Mem
216c0 47 65 74 4d 65 6d 73 79 73 35 28 76 6f 69 64 29 GetMemsys5(void)
216d0 3b 0a 23 65 6e 64 69 66 0a 0a 0a 23 69 66 6e 64 ;.#endif...#ifnd
216e0 65 66 20 53 51 4c 49 54 45 5f 4d 55 54 45 58 5f ef SQLITE_MUTEX_
216f0 4f 4d 49 54 0a 20 20 73 71 6c 69 74 65 33 5f 6d OMIT. sqlite3_m
21700 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e utex_methods con
21710 73 74 20 2a 73 71 6c 69 74 65 33 44 65 66 61 75 st *sqlite3Defau
21720 6c 74 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 ltMutex(void);.
21730 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d sqlite3_mutex_m
21740 65 74 68 6f 64 73 20 63 6f 6e 73 74 20 2a 73 71 ethods const *sq
21750 6c 69 74 65 33 4e 6f 6f 70 4d 75 74 65 78 28 76 lite3NoopMutex(v
21760 6f 69 64 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f oid);. sqlite3_
21770 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 4d 75 mutex *sqlite3Mu
21780 74 65 78 41 6c 6c 6f 63 28 69 6e 74 29 3b 0a 20 texAlloc(int);.
21790 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 74 65 int sqlite3Mute
217a0 78 49 6e 69 74 28 76 6f 69 64 29 3b 0a 20 20 69 xInit(void);. i
217b0 6e 74 20 73 71 6c 69 74 65 33 4d 75 74 65 78 45 nt sqlite3MutexE
217c0 6e 64 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 nd(void);.#endif
217d0 0a 0a 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 ..sqlite3_int64
217e0 73 71 6c 69 74 65 33 53 74 61 74 75 73 56 61 6c sqlite3StatusVal
217f0 75 65 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 ue(int);.void sq
21800 6c 69 74 65 33 53 74 61 74 75 73 55 70 28 69 6e lite3StatusUp(in
21810 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
21820 6c 69 74 65 33 53 74 61 74 75 73 44 6f 77 6e 28 lite3StatusDown(
21830 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
21840 73 71 6c 69 74 65 33 53 74 61 74 75 73 53 65 74 sqlite3StatusSet
21850 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 (int, int);../*
21860 41 63 63 65 73 73 20 74 6f 20 6d 75 74 65 78 65 Access to mutexe
21870 73 20 75 73 65 64 20 62 79 20 73 71 6c 69 74 65 s used by sqlite
21880 33 5f 73 74 61 74 75 73 28 29 20 2a 2f 0a 73 71 3_status() */.sq
21890 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c lite3_mutex *sql
218a0 69 74 65 33 50 63 61 63 68 65 31 4d 75 74 65 78 ite3Pcache1Mutex
218b0 28 76 6f 69 64 29 3b 0a 73 71 6c 69 74 65 33 5f (void);.sqlite3_
218c0 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 4d 61 mutex *sqlite3Ma
218d0 6c 6c 6f 63 4d 75 74 65 78 28 76 6f 69 64 29 3b llocMutex(void);
218e0 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ..#ifndef SQLITE
218f0 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 4e 47 5f 50 _OMIT_FLOATING_P
21900 4f 49 4e 54 0a 20 20 69 6e 74 20 73 71 6c 69 74 OINT. int sqlit
21910 65 33 49 73 4e 61 4e 28 64 6f 75 62 6c 65 29 3b e3IsNaN(double);
21920 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
21930 73 71 6c 69 74 65 33 49 73 4e 61 4e 28 58 29 20 sqlite3IsNaN(X)
21940 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 0.#endif../*.**
21950 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
21960 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
21970 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 69 6e ructure holds in
21980 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
21990 53 51 4c 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 SQL.** functions
219a0 20 61 72 67 75 6d 65 6e 74 73 20 74 68 61 74 20 arguments that
219b0 61 72 65 20 74 68 65 20 70 61 72 61 6d 65 74 65 are the paramete
219c0 72 73 20 74 6f 20 74 68 65 20 70 72 69 6e 74 66 rs to the printf
219d0 28 29 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a () function..*/.
219e0 73 74 72 75 63 74 20 50 72 69 6e 74 66 41 72 67 struct PrintfArg
219f0 75 6d 65 6e 74 73 20 7b 0a 20 20 69 6e 74 20 6e uments {. int n
21a00 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Arg;
21a10 20 20 20 20 2f 2a 20 54 6f 74 61 6c 20 6e 75 6d /* Total num
21a20 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
21a30 20 2a 2f 0a 20 20 69 6e 74 20 6e 55 73 65 64 3b */. int nUsed;
21a40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
21a50 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 * Number of argu
21a60 6d 65 6e 74 73 20 75 73 65 64 20 73 6f 20 66 61 ments used so fa
21a70 72 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 76 r */. sqlite3_v
21a80 61 6c 75 65 20 2a 2a 61 70 41 72 67 3b 20 20 20 alue **apArg;
21a90 2f 2a 20 54 68 65 20 61 72 67 75 6d 65 6e 74 20 /* The argument
21aa0 76 61 6c 75 65 73 20 2a 2f 0a 7d 3b 0a 0a 23 64 values */.};..#d
21ab0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 52 49 efine SQLITE_PRI
21ac0 4e 54 46 5f 49 4e 54 45 52 4e 41 4c 20 30 78 30 NTF_INTERNAL 0x0
21ad0 31 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 1.#define SQLITE
21ae0 5f 50 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 20 _PRINTF_SQLFUNC
21af0 20 30 78 30 32 0a 76 6f 69 64 20 73 71 6c 69 74 0x02.void sqlit
21b00 65 33 56 58 50 72 69 6e 74 66 28 53 74 72 41 63 e3VXPrintf(StrAc
21b10 63 75 6d 2a 2c 20 75 33 32 2c 20 63 6f 6e 73 74 cum*, u32, const
21b20 20 63 68 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 char*, va_list)
21b30 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 58 50 ;.void sqlite3XP
21b40 72 69 6e 74 66 28 53 74 72 41 63 63 75 6d 2a 2c rintf(StrAccum*,
21b50 20 75 33 32 2c 20 63 6f 6e 73 74 20 63 68 61 72 u32, const char
21b60 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 61 72 20 2a 73 *, ...);.char *s
21b70 71 6c 69 74 65 33 4d 50 72 69 6e 74 66 28 73 71 qlite3MPrintf(sq
21b80 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
21b90 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 61 72 20 2a r*, ...);.char *
21ba0 73 71 6c 69 74 65 33 56 4d 50 72 69 6e 74 66 28 sqlite3VMPrintf(
21bb0 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
21bc0 68 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b 0a har*, va_list);.
21bd0 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
21be0 54 45 5f 44 45 42 55 47 29 20 7c 7c 20 64 65 66 TE_DEBUG) || def
21bf0 69 6e 65 64 28 53 51 4c 49 54 45 5f 48 41 56 45 ined(SQLITE_HAVE
21c00 5f 4f 53 5f 54 52 41 43 45 29 0a 20 20 76 6f 69 _OS_TRACE). voi
21c10 64 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 d sqlite3DebugPr
21c20 69 6e 74 66 28 63 6f 6e 73 74 20 63 68 61 72 2a intf(const char*
21c30 2c 20 2e 2e 2e 29 3b 0a 23 65 6e 64 69 66 0a 23 , ...);.#endif.#
21c40 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
21c50 45 5f 54 45 53 54 29 0a 20 20 76 6f 69 64 20 2a E_TEST). void *
21c60 73 71 6c 69 74 65 33 54 65 73 74 54 65 78 74 54 sqlite3TestTextT
21c70 6f 50 74 72 28 63 6f 6e 73 74 20 63 68 61 72 2a oPtr(const char*
21c80 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 64 );.#endif..#if d
21c90 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 efined(SQLITE_DE
21ca0 42 55 47 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 BUG). void sqli
21cb0 74 65 33 54 72 65 65 56 69 65 77 45 78 70 72 28 te3TreeViewExpr(
21cc0 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 TreeView*, const
21cd0 20 45 78 70 72 2a 2c 20 75 38 29 3b 0a 20 20 76 Expr*, u8);. v
21ce0 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 oid sqlite3TreeV
21cf0 69 65 77 45 78 70 72 4c 69 73 74 28 54 72 65 65 iewExprList(Tree
21d00 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 View*, const Exp
21d10 72 4c 69 73 74 2a 2c 20 75 38 2c 20 63 6f 6e 73 rList*, u8, cons
21d20 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 t char*);. void
21d30 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 65 77 sqlite3TreeView
21d40 53 65 6c 65 63 74 28 54 72 65 65 56 69 65 77 2a Select(TreeView*
21d50 2c 20 63 6f 6e 73 74 20 53 65 6c 65 63 74 2a 2c , const Select*,
21d60 20 75 38 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 76 u8);.#endif...v
21d70 6f 69 64 20 73 71 6c 69 74 65 33 53 65 74 53 74 oid sqlite3SetSt
21d80 72 69 6e 67 28 63 68 61 72 20 2a 2a 2c 20 73 71 ring(char **, sq
21d90 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 lite3*, const ch
21da0 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ar*);.void sqlit
21db0 65 33 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 e3ErrorMsg(Parse
21dc0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 *, const char*,
21dd0 2e 2e 2e 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ...);.int sqlite
21de0 33 44 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 3Dequote(char*);
21df0 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 77 .int sqlite3Keyw
21e00 6f 72 64 43 6f 64 65 28 63 6f 6e 73 74 20 75 6e ordCode(const un
21e10 73 69 67 6e 65 64 20 63 68 61 72 2a 2c 20 69 6e signed char*, in
21e20 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 t);.int sqlite3R
21e30 75 6e 50 61 72 73 65 72 28 50 61 72 73 65 2a 2c unParser(Parse*,
21e40 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 68 const char*, ch
21e50 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ar **);.void sql
21e60 69 74 65 33 46 69 6e 69 73 68 43 6f 64 69 6e 67 ite3FinishCoding
21e70 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 (Parse*);.int sq
21e80 6c 69 74 65 33 47 65 74 54 65 6d 70 52 65 67 28 lite3GetTempReg(
21e90 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 Parse*);.void sq
21ea0 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 lite3ReleaseTemp
21eb0 52 65 67 28 50 61 72 73 65 2a 2c 69 6e 74 29 3b Reg(Parse*,int);
21ec0 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 .int sqlite3GetT
21ed0 65 6d 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c empRange(Parse*,
21ee0 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
21ef0 65 33 52 65 6c 65 61 73 65 54 65 6d 70 52 61 6e e3ReleaseTempRan
21f00 67 65 28 50 61 72 73 65 2a 2c 69 6e 74 2c 69 6e ge(Parse*,int,in
21f10 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
21f20 43 6c 65 61 72 54 65 6d 70 52 65 67 43 61 63 68 ClearTempRegCach
21f30 65 28 50 61 72 73 65 2a 29 3b 0a 45 78 70 72 20 e(Parse*);.Expr
21f40 2a 73 71 6c 69 74 65 33 45 78 70 72 41 6c 6c 6f *sqlite3ExprAllo
21f50 63 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 c(sqlite3*,int,c
21f60 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c 69 6e 74 29 onst Token*,int)
21f70 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 ;.Expr *sqlite3E
21f80 78 70 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 xpr(sqlite3*,int
21f90 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
21fa0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 41 oid sqlite3ExprA
21fb0 74 74 61 63 68 53 75 62 74 72 65 65 73 28 73 71 ttachSubtrees(sq
21fc0 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c 45 78 70 lite3*,Expr*,Exp
21fd0 72 2a 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 r*,Expr*);.Expr
21fe0 2a 73 71 6c 69 74 65 33 50 45 78 70 72 28 50 61 *sqlite3PExpr(Pa
21ff0 72 73 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 2a rse*, int, Expr*
22000 2c 20 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 54 , Expr*, const T
22010 6f 6b 65 6e 2a 29 3b 0a 45 78 70 72 20 2a 73 71 oken*);.Expr *sq
22020 6c 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 6c lite3ExprAnd(sql
22030 69 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 70 ite3*,Expr*, Exp
22040 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 r*);.Expr *sqlit
22050 65 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 50 e3ExprFunction(P
22060 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c arse*,ExprList*,
22070 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
22080 71 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 6e qlite3ExprAssign
22090 56 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 2a VarNumber(Parse*
220a0 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
220b0 71 6c 69 74 65 33 45 78 70 72 44 65 6c 65 74 65 qlite3ExprDelete
220c0 28 73 71 6c 69 74 65 33 2a 2c 20 45 78 70 72 2a (sqlite3*, Expr*
220d0 29 3b 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c );.ExprList *sql
220e0 69 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 ite3ExprListAppe
220f0 6e 64 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 nd(Parse*,ExprLi
22100 73 74 2a 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 st*,Expr*);.void
22110 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 sqlite3ExprList
22120 53 65 74 4e 61 6d 65 28 50 61 72 73 65 2a 2c 45 SetName(Parse*,E
22130 78 70 72 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c xprList*,Token*,
22140 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22150 65 33 45 78 70 72 4c 69 73 74 53 65 74 53 70 61 e3ExprListSetSpa
22160 6e 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 n(Parse*,ExprLis
22170 74 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 t*,ExprSpan*);.v
22180 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c oid sqlite3ExprL
22190 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 istDelete(sqlite
221a0 33 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 3*, ExprList*);.
221b0 75 33 32 20 73 71 6c 69 74 65 33 45 78 70 72 4c u32 sqlite3ExprL
221c0 69 73 74 46 6c 61 67 73 28 63 6f 6e 73 74 20 45 istFlags(const E
221d0 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 xprList*);.int s
221e0 71 6c 69 74 65 33 49 6e 69 74 28 73 71 6c 69 74 qlite3Init(sqlit
221f0 65 33 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a 69 6e e3*, char**);.in
22200 74 20 73 71 6c 69 74 65 33 49 6e 69 74 43 61 6c t sqlite3InitCal
22210 6c 62 61 63 6b 28 76 6f 69 64 2a 2c 20 69 6e 74 lback(void*, int
22220 2c 20 63 68 61 72 2a 2a 2c 20 63 68 61 72 2a 2a , char**, char**
22230 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
22240 72 61 67 6d 61 28 50 61 72 73 65 2a 2c 54 6f 6b ragma(Parse*,Tok
22250 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e en*,Token*,Token
22260 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c *,int);.void sql
22270 69 74 65 33 52 65 73 65 74 41 6c 6c 53 63 68 65 ite3ResetAllSche
22280 6d 61 73 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e 28 masOfConnection(
22290 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 sqlite3*);.void
222a0 73 71 6c 69 74 65 33 52 65 73 65 74 4f 6e 65 53 sqlite3ResetOneS
222b0 63 68 65 6d 61 28 73 71 6c 69 74 65 33 2a 2c 69 chema(sqlite3*,i
222c0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
222d0 33 43 6f 6c 6c 61 70 73 65 44 61 74 61 62 61 73 3CollapseDatabas
222e0 65 41 72 72 61 79 28 73 71 6c 69 74 65 33 2a 29 eArray(sqlite3*)
222f0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 ;.void sqlite3Be
22300 67 69 6e 50 61 72 73 65 28 50 61 72 73 65 2a 2c ginParse(Parse*,
22310 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22320 65 33 43 6f 6d 6d 69 74 49 6e 74 65 72 6e 61 6c e3CommitInternal
22330 43 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 2a Changes(sqlite3*
22340 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 );.Table *sqlite
22350 33 52 65 73 75 6c 74 53 65 74 4f 66 53 65 6c 65 3ResultSetOfSele
22360 63 74 28 50 61 72 73 65 2a 2c 53 65 6c 65 63 74 ct(Parse*,Select
22370 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
22380 4f 70 65 6e 4d 61 73 74 65 72 54 61 62 6c 65 28 OpenMasterTable(
22390 50 61 72 73 65 20 2a 2c 20 69 6e 74 29 3b 0a 49 Parse *, int);.I
223a0 6e 64 65 78 20 2a 73 71 6c 69 74 65 33 50 72 69 ndex *sqlite3Pri
223b0 6d 61 72 79 4b 65 79 49 6e 64 65 78 28 54 61 62 maryKeyIndex(Tab
223c0 6c 65 2a 29 3b 0a 69 31 36 20 73 71 6c 69 74 65 le*);.i16 sqlite
223d0 33 43 6f 6c 75 6d 6e 4f 66 49 6e 64 65 78 28 49 3ColumnOfIndex(I
223e0 6e 64 65 78 2a 2c 20 69 31 36 29 3b 0a 76 6f 69 ndex*, i16);.voi
223f0 64 20 73 71 6c 69 74 65 33 53 74 61 72 74 54 61 d sqlite3StartTa
22400 62 6c 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e ble(Parse*,Token
22410 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 *,Token*,int,int
22420 2c 69 6e 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 ,int,int);.void
22430 73 71 6c 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e sqlite3AddColumn
22440 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b (Parse*,Token*);
22450 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
22460 4e 6f 74 4e 75 6c 6c 28 50 61 72 73 65 2a 2c 20 NotNull(Parse*,
22470 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22480 65 33 41 64 64 50 72 69 6d 61 72 79 4b 65 79 28 e3AddPrimaryKey(
22490 50 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 Parse*, ExprList
224a0 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
224b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
224c0 64 64 43 68 65 63 6b 43 6f 6e 73 74 72 61 69 6e ddCheckConstrain
224d0 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 t(Parse*, Expr*)
224e0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 ;.void sqlite3Ad
224f0 64 43 6f 6c 75 6d 6e 54 79 70 65 28 50 61 72 73 dColumnType(Pars
22500 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 e*,Token*);.void
22510 20 73 71 6c 69 74 65 33 41 64 64 44 65 66 61 75 sqlite3AddDefau
22520 6c 74 56 61 6c 75 65 28 50 61 72 73 65 2a 2c 45 ltValue(Parse*,E
22530 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f 69 64 20 xprSpan*);.void
22540 73 71 6c 69 74 65 33 41 64 64 43 6f 6c 6c 61 74 sqlite3AddCollat
22550 65 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 6f eType(Parse*, To
22560 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
22570 74 65 33 45 6e 64 54 61 62 6c 65 28 50 61 72 73 te3EndTable(Pars
22580 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a e*,Token*,Token*
22590 2c 75 38 2c 53 65 6c 65 63 74 2a 29 3b 0a 69 6e ,u8,Select*);.in
225a0 74 20 73 71 6c 69 74 65 33 50 61 72 73 65 55 72 t sqlite3ParseUr
225b0 69 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f i(const char*,co
225c0 6e 73 74 20 63 68 61 72 2a 2c 75 6e 73 69 67 6e nst char*,unsign
225d0 65 64 20 69 6e 74 2a 2c 0a 20 20 20 20 20 20 20 ed int*,.
225e0 20 20 20 20 20 20 20 20 20 20 20 20 20 73 71 6c sql
225f0 69 74 65 33 5f 76 66 73 2a 2a 2c 63 68 61 72 2a ite3_vfs**,char*
22600 2a 2c 63 68 61 72 20 2a 2a 29 3b 0a 42 74 72 65 *,char **);.Btre
22610 65 20 2a 73 71 6c 69 74 65 33 44 62 4e 61 6d 65 e *sqlite3DbName
22620 54 6f 42 74 72 65 65 28 73 71 6c 69 74 65 33 2a ToBtree(sqlite3*
22630 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 ,const char*);.i
22640 6e 74 20 73 71 6c 69 74 65 33 43 6f 64 65 4f 6e nt sqlite3CodeOn
22650 63 65 28 50 61 72 73 65 20 2a 29 3b 0a 0a 23 69 ce(Parse *);..#i
22660 66 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fdef SQLITE_OMIT
22670 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a 23 20 _BUILTIN_TEST.#
22680 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 61 define sqlite3Fa
22690 75 6c 74 53 69 6d 28 58 29 20 53 51 4c 49 54 45 ultSim(X) SQLITE
226a0 5f 4f 4b 0a 23 65 6c 73 65 0a 20 20 69 6e 74 20 _OK.#else. int
226b0 73 71 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 sqlite3FaultSim(
226c0 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 42 69 int);.#endif..Bi
226d0 74 76 65 63 20 2a 73 71 6c 69 74 65 33 42 69 74 tvec *sqlite3Bit
226e0 76 65 63 43 72 65 61 74 65 28 75 33 32 29 3b 0a vecCreate(u32);.
226f0 69 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 int sqlite3Bitve
22700 63 54 65 73 74 28 42 69 74 76 65 63 2a 2c 20 75 cTest(Bitvec*, u
22710 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 32);.int sqlite3
22720 42 69 74 76 65 63 53 65 74 28 42 69 74 76 65 63 BitvecSet(Bitvec
22730 2a 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 71 *, u32);.void sq
22740 6c 69 74 65 33 42 69 74 76 65 63 43 6c 65 61 72 lite3BitvecClear
22750 28 42 69 74 76 65 63 2a 2c 20 75 33 32 2c 20 76 (Bitvec*, u32, v
22760 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 oid*);.void sqli
22770 74 65 33 42 69 74 76 65 63 44 65 73 74 72 6f 79 te3BitvecDestroy
22780 28 42 69 74 76 65 63 2a 29 3b 0a 75 33 32 20 73 (Bitvec*);.u32 s
22790 71 6c 69 74 65 33 42 69 74 76 65 63 53 69 7a 65 qlite3BitvecSize
227a0 28 42 69 74 76 65 63 2a 29 3b 0a 23 69 66 6e 64 (Bitvec*);.#ifnd
227b0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 ef SQLITE_OMIT_B
227c0 55 49 4c 54 49 4e 5f 54 45 53 54 0a 69 6e 74 20 UILTIN_TEST.int
227d0 73 71 6c 69 74 65 33 42 69 74 76 65 63 42 75 69 sqlite3BitvecBui
227e0 6c 74 69 6e 54 65 73 74 28 69 6e 74 2c 69 6e 74 ltinTest(int,int
227f0 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 52 6f 77 53 *);.#endif..RowS
22800 65 74 20 2a 73 71 6c 69 74 65 33 52 6f 77 53 65 et *sqlite3RowSe
22810 74 49 6e 69 74 28 73 71 6c 69 74 65 33 2a 2c 20 tInit(sqlite3*,
22820 76 6f 69 64 2a 2c 20 75 6e 73 69 67 6e 65 64 20 void*, unsigned
22830 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22840 65 33 52 6f 77 53 65 74 43 6c 65 61 72 28 52 6f e3RowSetClear(Ro
22850 77 53 65 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c wSet*);.void sql
22860 69 74 65 33 52 6f 77 53 65 74 49 6e 73 65 72 74 ite3RowSetInsert
22870 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 29 3b 0a (RowSet*, i64);.
22880 69 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 53 65 int sqlite3RowSe
22890 74 54 65 73 74 28 52 6f 77 53 65 74 2a 2c 20 69 tTest(RowSet*, i
228a0 6e 74 20 69 42 61 74 63 68 2c 20 69 36 34 29 3b nt iBatch, i64);
228b0 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 53 .int sqlite3RowS
228c0 65 74 4e 65 78 74 28 52 6f 77 53 65 74 2a 2c 20 etNext(RowSet*,
228d0 69 36 34 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c i64*);..void sql
228e0 69 74 65 33 43 72 65 61 74 65 56 69 65 77 28 50 ite3CreateView(P
228f0 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b arse*,Token*,Tok
22900 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 53 65 6c 65 63 en*,Token*,Selec
22910 74 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 t*,int,int);..#i
22920 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 f !defined(SQLIT
22930 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 7c 7c 20 E_OMIT_VIEW) ||
22940 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
22950 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
22960 45 29 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 E). int sqlite3
22970 56 69 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d ViewGetColumnNam
22980 65 73 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a es(Parse*,Table*
22990 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e );.#else.# defin
229a0 65 20 73 71 6c 69 74 65 33 56 69 65 77 47 65 74 e sqlite3ViewGet
229b0 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 ColumnNames(A,B)
229c0 20 30 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 53 0.#endif..#if S
229d0 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 QLITE_MAX_ATTACH
229e0 45 44 3e 33 30 0a 20 20 69 6e 74 20 73 71 6c 69 ED>30. int sqli
229f0 74 65 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f te3DbMaskAllZero
22a00 28 79 44 62 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 (yDbMask);.#endi
22a10 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 f.void sqlite3Dr
22a20 6f 70 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 opTable(Parse*,
22a30 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 SrcList*, int, i
22a40 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
22a50 33 43 6f 64 65 44 72 6f 70 54 61 62 6c 65 28 50 3CodeDropTable(P
22a60 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 arse*, Table*, i
22a70 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
22a80 71 6c 69 74 65 33 44 65 6c 65 74 65 54 61 62 6c qlite3DeleteTabl
22a90 65 28 73 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c e(sqlite3*, Tabl
22aa0 65 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c e*);.#ifndef SQL
22ab0 49 54 45 5f 4f 4d 49 54 5f 41 55 54 4f 49 4e 43 ITE_OMIT_AUTOINC
22ac0 52 45 4d 45 4e 54 0a 20 20 76 6f 69 64 20 73 71 REMENT. void sq
22ad0 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 lite3Autoincreme
22ae0 6e 74 42 65 67 69 6e 28 50 61 72 73 65 20 2a 70 ntBegin(Parse *p
22af0 50 61 72 73 65 29 3b 0a 20 20 76 6f 69 64 20 73 Parse);. void s
22b00 71 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d qlite3Autoincrem
22b10 65 6e 74 45 6e 64 28 50 61 72 73 65 20 2a 70 50 entEnd(Parse *pP
22b20 61 72 73 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 arse);.#else.# d
22b30 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 efine sqlite3Aut
22b40 6f 69 6e 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 oincrementBegin(
22b50 58 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 X).# define sqli
22b60 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 te3Autoincrement
22b70 45 6e 64 28 58 29 0a 23 65 6e 64 69 66 0a 76 6f End(X).#endif.vo
22b80 69 64 20 73 71 6c 69 74 65 33 49 6e 73 65 72 74 id sqlite3Insert
22b90 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
22ba0 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 49 64 4c 69 *, Select*, IdLi
22bb0 73 74 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 st*, int);.void
22bc0 2a 73 71 6c 69 74 65 33 41 72 72 61 79 41 6c 6c *sqlite3ArrayAll
22bd0 6f 63 61 74 65 28 73 71 6c 69 74 65 33 2a 2c 76 ocate(sqlite3*,v
22be0 6f 69 64 2a 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e oid*,int,int*,in
22bf0 74 2a 29 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c t*);.IdList *sql
22c00 69 74 65 33 49 64 4c 69 73 74 41 70 70 65 6e 64 ite3IdListAppend
22c10 28 73 71 6c 69 74 65 33 2a 2c 20 49 64 4c 69 73 (sqlite3*, IdLis
22c20 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 t*, Token*);.int
22c30 20 73 71 6c 69 74 65 33 49 64 4c 69 73 74 49 6e sqlite3IdListIn
22c40 64 65 78 28 49 64 4c 69 73 74 2a 2c 63 6f 6e 73 dex(IdList*,cons
22c50 74 20 63 68 61 72 2a 29 3b 0a 53 72 63 4c 69 73 t char*);.SrcLis
22c60 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 t *sqlite3SrcLis
22c70 74 45 6e 6c 61 72 67 65 28 73 71 6c 69 74 65 33 tEnlarge(sqlite3
22c80 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 *, SrcList*, int
22c90 2c 20 69 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 , int);.SrcList
22ca0 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 41 *sqlite3SrcListA
22cb0 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 ppend(sqlite3*,
22cc0 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a SrcList*, Token*
22cd0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 53 72 63 4c 69 , Token*);.SrcLi
22ce0 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 st *sqlite3SrcLi
22cf0 73 74 41 70 70 65 6e 64 46 72 6f 6d 54 65 72 6d stAppendFromTerm
22d00 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
22d10 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e *, Token*, Token
22d20 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 *,.
22d30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22d40 20 20 20 20 20 20 20 20 20 54 6f 6b 65 6e 2a 2c Token*,
22d50 20 53 65 6c 65 63 74 2a 2c 20 45 78 70 72 2a 2c Select*, Expr*,
22d60 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 IdList*);.void
22d70 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 49 6e sqlite3SrcListIn
22d80 64 65 78 65 64 42 79 28 50 61 72 73 65 20 2a 2c dexedBy(Parse *,
22d90 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 6f 6b 65 SrcList *, Toke
22da0 6e 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 n *);.int sqlite
22db0 33 49 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 3IndexedByLookup
22dc0 28 50 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 (Parse *, struct
22dd0 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 SrcList_item *)
22de0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 ;.void sqlite3Sr
22df0 63 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 cListShiftJoinTy
22e00 70 65 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f pe(SrcList*);.vo
22e10 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 id sqlite3SrcLis
22e20 74 41 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 tAssignCursors(P
22e30 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 arse*, SrcList*)
22e40 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 ;.void sqlite3Id
22e50 4c 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 ListDelete(sqlit
22e60 65 33 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 e3*, IdList*);.v
22e70 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 oid sqlite3SrcLi
22e80 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
22e90 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e *, SrcList*);.In
22ea0 64 65 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f dex *sqlite3Allo
22eb0 63 61 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 cateIndexObject(
22ec0 73 71 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 sqlite3*,i16,int
22ed0 2c 63 68 61 72 2a 2a 29 3b 0a 49 6e 64 65 78 20 ,char**);.Index
22ee0 2a 73 71 6c 69 74 65 33 43 72 65 61 74 65 49 6e *sqlite3CreateIn
22ef0 64 65 78 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e dex(Parse*,Token
22f00 2a 2c 54 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 *,Token*,SrcList
22f10 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c *,ExprList*,int,
22f20 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 Token*,.
22f30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22f40 20 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e Expr*, int, in
22f50 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
22f60 44 72 6f 70 49 6e 64 65 78 28 50 61 72 73 65 2a DropIndex(Parse*
22f70 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 , SrcList*, int)
22f80 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c ;.int sqlite3Sel
22f90 65 63 74 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 ect(Parse*, Sele
22fa0 63 74 2a 2c 20 53 65 6c 65 63 74 44 65 73 74 2a ct*, SelectDest*
22fb0 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 74 );.Select *sqlit
22fc0 65 33 53 65 6c 65 63 74 4e 65 77 28 50 61 72 73 e3SelectNew(Pars
22fd0 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 72 63 e*,ExprList*,Src
22fe0 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 List*,Expr*,Expr
22ff0 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 List*,.
23000 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23010 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c Expr*,ExprList*,
23020 75 31 36 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 u16,Expr*,Expr*)
23030 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 ;.void sqlite3Se
23040 6c 65 63 74 44 65 6c 65 74 65 28 73 71 6c 69 74 lectDelete(sqlit
23050 65 33 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 54 e3*, Select*);.T
23060 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 53 72 63 able *sqlite3Src
23070 4c 69 73 74 4c 6f 6f 6b 75 70 28 50 61 72 73 65 ListLookup(Parse
23080 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e *, SrcList*);.in
23090 74 20 73 71 6c 69 74 65 33 49 73 52 65 61 64 4f t sqlite3IsReadO
230a0 6e 6c 79 28 50 61 72 73 65 2a 2c 20 54 61 62 6c nly(Parse*, Tabl
230b0 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 e*, int);.void s
230c0 71 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 28 qlite3OpenTable(
230d0 50 61 72 73 65 2a 2c 20 69 6e 74 20 69 43 75 72 Parse*, int iCur
230e0 2c 20 69 6e 74 20 69 44 62 2c 20 54 61 62 6c 65 , int iDb, Table
230f0 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 20 64 65 66 *, int);.#if def
23100 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
23110 4c 45 5f 55 50 44 41 54 45 5f 44 45 4c 45 54 45 LE_UPDATE_DELETE
23120 5f 4c 49 4d 49 54 29 20 26 26 20 21 64 65 66 69 _LIMIT) && !defi
23130 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ned(SQLITE_OMIT_
23140 53 55 42 51 55 45 52 59 29 0a 45 78 70 72 20 2a SUBQUERY).Expr *
23150 73 71 6c 69 74 65 33 4c 69 6d 69 74 57 68 65 72 sqlite3LimitWher
23160 65 28 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 e(Parse*,SrcList
23170 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 *,Expr*,ExprList
23180 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 63 68 *,Expr*,Expr*,ch
23190 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 ar*);.#endif.voi
231a0 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 46 d sqlite3DeleteF
231b0 72 6f 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 4c rom(Parse*, SrcL
231c0 69 73 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f ist*, Expr*);.vo
231d0 69 64 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 id sqlite3Update
231e0 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
231f0 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 *, ExprList*, Ex
23200 70 72 2a 2c 20 69 6e 74 29 3b 0a 57 68 65 72 65 pr*, int);.Where
23210 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 57 68 65 Info *sqlite3Whe
23220 72 65 42 65 67 69 6e 28 50 61 72 73 65 2a 2c 53 reBegin(Parse*,S
23230 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 rcList*,Expr*,Ex
23240 70 72 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 prList*,ExprList
23250 2a 2c 75 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 64 *,u16,int);.void
23260 20 73 71 6c 69 74 65 33 57 68 65 72 65 45 6e 64 sqlite3WhereEnd
23270 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 75 36 (WhereInfo*);.u6
23280 34 20 73 71 6c 69 74 65 33 57 68 65 72 65 4f 75 4 sqlite3WhereOu
23290 74 70 75 74 52 6f 77 43 6f 75 6e 74 28 57 68 65 tputRowCount(Whe
232a0 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 reInfo*);.int sq
232b0 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 74 lite3WhereIsDist
232c0 69 6e 63 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 inct(WhereInfo*)
232d0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
232e0 72 65 49 73 4f 72 64 65 72 65 64 28 57 68 65 72 reIsOrdered(Wher
232f0 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
23300 69 74 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 ite3WhereIsSorte
23310 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 d(WhereInfo*);.i
23320 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 43 nt sqlite3WhereC
23330 6f 6e 74 69 6e 75 65 4c 61 62 65 6c 28 57 68 65 ontinueLabel(Whe
23340 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 reInfo*);.int sq
23350 6c 69 74 65 33 57 68 65 72 65 42 72 65 61 6b 4c lite3WhereBreakL
23360 61 62 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 abel(WhereInfo*)
23370 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
23380 72 65 4f 6b 4f 6e 65 50 61 73 73 28 57 68 65 72 reOkOnePass(Wher
23390 65 49 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b 0a 69 eInfo*, int*);.i
233a0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
233b0 64 65 47 65 74 43 6f 6c 75 6d 6e 28 50 61 72 73 deGetColumn(Pars
233c0 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
233d0 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a int, int, u8);.
233e0 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
233f0 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 4f 66 54 CodeGetColumnOfT
23400 61 62 6c 65 28 56 64 62 65 2a 2c 20 54 61 62 6c able(Vdbe*, Tabl
23410 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e e*, int, int, in
23420 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
23430 45 78 70 72 43 6f 64 65 4d 6f 76 65 28 50 61 72 ExprCodeMove(Par
23440 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 se*, int, int, i
23450 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
23460 33 45 78 70 72 43 61 63 68 65 53 74 6f 72 65 28 3ExprCacheStore(
23470 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 Parse*, int, int
23480 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
23490 69 74 65 33 45 78 70 72 43 61 63 68 65 50 75 73 ite3ExprCachePus
234a0 68 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 h(Parse*);.void
234b0 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 sqlite3ExprCache
234c0 50 6f 70 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 Pop(Parse*);.voi
234d0 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 d sqlite3ExprCac
234e0 68 65 52 65 6d 6f 76 65 28 50 61 72 73 65 2a 2c heRemove(Parse*,
234f0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
23500 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 sqlite3ExprCach
23510 65 43 6c 65 61 72 28 50 61 72 73 65 2a 29 3b 0a eClear(Parse*);.
23520 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
23530 43 61 63 68 65 41 66 66 69 6e 69 74 79 43 68 61 CacheAffinityCha
23540 6e 67 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c nge(Parse*, int,
23550 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
23560 74 65 33 45 78 70 72 43 6f 64 65 28 50 61 72 73 te3ExprCode(Pars
23570 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b e*, Expr*, int);
23580 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
23590 72 43 6f 64 65 46 61 63 74 6f 72 61 62 6c 65 28 rCodeFactorable(
235a0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
235b0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
235c0 33 45 78 70 72 43 6f 64 65 41 74 49 6e 69 74 28 3ExprCodeAtInit(
235d0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Parse*, Expr*, i
235e0 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c nt, u8);.int sql
235f0 69 74 65 33 45 78 70 72 43 6f 64 65 54 65 6d 70 ite3ExprCodeTemp
23600 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
23610 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int*);.int sqlit
23620 65 33 45 78 70 72 43 6f 64 65 54 61 72 67 65 74 e3ExprCodeTarget
23630 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
23640 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
23650 65 33 45 78 70 72 43 6f 64 65 41 6e 64 43 61 63 e3ExprCodeAndCac
23660 68 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a he(Parse*, Expr*
23670 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
23680 74 65 33 45 78 70 72 43 6f 64 65 45 78 70 72 4c te3ExprCodeExprL
23690 69 73 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 ist(Parse*, Expr
236a0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 75 38 29 3b List*, int, u8);
236b0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
236c0 45 43 45 4c 5f 44 55 50 20 20 20 20 20 20 30 78 ECEL_DUP 0x
236d0 30 31 20 20 2f 2a 20 44 65 65 70 2c 20 6e 6f 74 01 /* Deep, not
236e0 20 73 68 61 6c 6c 6f 77 20 63 6f 70 69 65 73 20 shallow copies
236f0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
23700 45 5f 45 43 45 4c 5f 46 41 43 54 4f 52 20 20 20 E_ECEL_FACTOR
23710 30 78 30 32 20 20 2f 2a 20 46 61 63 74 6f 72 20 0x02 /* Factor
23720 6f 75 74 20 63 6f 6e 73 74 61 6e 74 20 74 65 72 out constant ter
23730 6d 73 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 ms */.void sqlit
23740 65 33 45 78 70 72 49 66 54 72 75 65 28 50 61 72 e3ExprIfTrue(Par
23750 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c se*, Expr*, int,
23760 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
23770 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 28 50 te3ExprIfFalse(P
23780 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
23790 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
237a0 6c 69 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 lite3ExprIfFalse
237b0 44 75 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Dup(Parse*, Expr
237c0 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 54 61 *, int, int);.Ta
237d0 62 6c 65 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 ble *sqlite3Find
237e0 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 63 Table(sqlite3*,c
237f0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
23800 74 20 63 68 61 72 2a 29 3b 0a 54 61 62 6c 65 20 t char*);.Table
23810 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 *sqlite3LocateTa
23820 62 6c 65 28 50 61 72 73 65 2a 2c 69 6e 74 20 69 ble(Parse*,int i
23830 73 56 69 65 77 2c 63 6f 6e 73 74 20 63 68 61 72 sView,const char
23840 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
23850 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 4c .Table *sqlite3L
23860 6f 63 61 74 65 54 61 62 6c 65 49 74 65 6d 28 50 ocateTableItem(P
23870 61 72 73 65 2a 2c 69 6e 74 20 69 73 56 69 65 77 arse*,int isView
23880 2c 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f ,struct SrcList_
23890 69 74 65 6d 20 2a 29 3b 0a 49 6e 64 65 78 20 2a item *);.Index *
238a0 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 64 65 78 sqlite3FindIndex
238b0 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 (sqlite3*,const
238c0 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
238d0 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
238e0 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 3UnlinkAndDelete
238f0 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 69 Table(sqlite3*,i
23900 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b nt,const char*);
23910 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c .void sqlite3Unl
23920 69 6e 6b 41 6e 64 44 65 6c 65 74 65 49 6e 64 65 inkAndDeleteInde
23930 78 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 x(sqlite3*,int,c
23940 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 onst char*);.voi
23950 64 20 73 71 6c 69 74 65 33 56 61 63 75 75 6d 28 d sqlite3Vacuum(
23960 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c Parse*);.int sql
23970 69 74 65 33 52 75 6e 56 61 63 75 75 6d 28 63 68 ite3RunVacuum(ch
23980 61 72 2a 2a 2c 20 73 71 6c 69 74 65 33 2a 29 3b ar**, sqlite3*);
23990 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4e 61 .char *sqlite3Na
239a0 6d 65 46 72 6f 6d 54 6f 6b 65 6e 28 73 71 6c 69 meFromToken(sqli
239b0 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 te3*, Token*);.i
239c0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
239d0 6d 70 61 72 65 28 45 78 70 72 2a 2c 20 45 78 70 mpare(Expr*, Exp
239e0 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 r*, int);.int sq
239f0 6c 69 74 65 33 45 78 70 72 4c 69 73 74 43 6f 6d lite3ExprListCom
23a00 70 61 72 65 28 45 78 70 72 4c 69 73 74 2a 2c 20 pare(ExprList*,
23a10 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b ExprList*, int);
23a20 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
23a30 49 6d 70 6c 69 65 73 45 78 70 72 28 45 78 70 72 ImpliesExpr(Expr
23a40 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
23a50 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
23a60 41 6e 61 6c 79 7a 65 41 67 67 72 65 67 61 74 65 AnalyzeAggregate
23a70 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 s(NameContext*,
23a80 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
23a90 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a 65 41 ite3ExprAnalyzeA
23aa0 67 67 4c 69 73 74 28 4e 61 6d 65 43 6f 6e 74 65 ggList(NameConte
23ab0 78 74 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b 0a xt*,ExprList*);.
23ac0 69 6e 74 20 73 71 6c 69 74 65 33 46 75 6e 63 74 int sqlite3Funct
23ad0 69 6f 6e 55 73 65 73 54 68 69 73 53 72 63 28 45 ionUsesThisSrc(E
23ae0 78 70 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b xpr*, SrcList*);
23af0 0a 56 64 62 65 20 2a 73 71 6c 69 74 65 33 47 65 .Vdbe *sqlite3Ge
23b00 74 56 64 62 65 28 50 61 72 73 65 2a 29 3b 0a 23 tVdbe(Parse*);.#
23b10 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
23b20 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a IT_BUILTIN_TEST.
23b30 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e 67 void sqlite3Prng
23b40 53 61 76 65 53 74 61 74 65 28 76 6f 69 64 29 3b SaveState(void);
23b50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e .void sqlite3Prn
23b60 67 52 65 73 74 6f 72 65 53 74 61 74 65 28 76 6f gRestoreState(vo
23b70 69 64 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 id);.#endif.void
23b80 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
23b90 41 6c 6c 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 All(sqlite3*,int
23ba0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
23bb0 6f 64 65 56 65 72 69 66 79 53 63 68 65 6d 61 28 odeVerifySchema(
23bc0 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f Parse*, int);.vo
23bd0 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 id sqlite3CodeVe
23be0 72 69 66 79 4e 61 6d 65 64 53 63 68 65 6d 61 28 rifyNamedSchema(
23bf0 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 Parse*, const ch
23c00 61 72 20 2a 7a 44 62 29 3b 0a 76 6f 69 64 20 73 ar *zDb);.void s
23c10 71 6c 69 74 65 33 42 65 67 69 6e 54 72 61 6e 73 qlite3BeginTrans
23c20 61 63 74 69 6f 6e 28 50 61 72 73 65 2a 2c 20 69 action(Parse*, i
23c30 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
23c40 33 43 6f 6d 6d 69 74 54 72 61 6e 73 61 63 74 69 3CommitTransacti
23c50 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 on(Parse*);.void
23c60 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
23c70 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 73 Transaction(Pars
23c80 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
23c90 33 53 61 76 65 70 6f 69 6e 74 28 50 61 72 73 65 3Savepoint(Parse
23ca0 2a 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a 29 3b *, int, Token*);
23cb0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c 6f .void sqlite3Clo
23cc0 73 65 53 61 76 65 70 6f 69 6e 74 73 28 73 71 6c seSavepoints(sql
23cd0 69 74 65 33 20 2a 29 3b 0a 76 6f 69 64 20 73 71 ite3 *);.void sq
23ce0 6c 69 74 65 33 4c 65 61 76 65 4d 75 74 65 78 41 lite3LeaveMutexA
23cf0 6e 64 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 73 71 ndCloseZombie(sq
23d00 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c lite3*);.int sql
23d10 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 61 ite3ExprIsConsta
23d20 6e 74 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 nt(Expr*);.int s
23d30 71 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 qlite3ExprIsCons
23d40 74 61 6e 74 4e 6f 74 4a 6f 69 6e 28 45 78 70 72 tantNotJoin(Expr
23d50 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
23d60 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 46 xprIsConstantOrF
23d70 75 6e 63 74 69 6f 6e 28 45 78 70 72 2a 2c 20 75 unction(Expr*, u
23d80 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 8);.int sqlite3E
23d90 78 70 72 49 73 54 61 62 6c 65 43 6f 6e 73 74 61 xprIsTableConsta
23da0 6e 74 28 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 69 nt(Expr*,int);.i
23db0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 nt sqlite3ExprIs
23dc0 49 6e 74 65 67 65 72 28 45 78 70 72 2a 2c 20 69 Integer(Expr*, i
23dd0 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
23de0 33 45 78 70 72 43 61 6e 42 65 4e 75 6c 6c 28 63 3ExprCanBeNull(c
23df0 6f 6e 73 74 20 45 78 70 72 2a 29 3b 0a 69 6e 74 onst Expr*);.int
23e00 20 73 71 6c 69 74 65 33 45 78 70 72 4e 65 65 64 sqlite3ExprNeed
23e10 73 4e 6f 41 66 66 69 6e 69 74 79 43 68 61 6e 67 sNoAffinityChang
23e20 65 28 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 63 e(const Expr*, c
23e30 68 61 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 har);.int sqlite
23e40 33 49 73 52 6f 77 69 64 28 63 6f 6e 73 74 20 63 3IsRowid(const c
23e50 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
23e60 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 44 65 te3GenerateRowDe
23e70 6c 65 74 65 28 50 61 72 73 65 2a 2c 54 61 62 6c lete(Parse*,Tabl
23e80 65 2a 2c 54 72 69 67 67 65 72 2a 2c 69 6e 74 2c e*,Trigger*,int,
23e90 69 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 38 2c 75 int,int,i16,u8,u
23ea0 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 8,u8);.void sqli
23eb0 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 49 6e te3GenerateRowIn
23ec0 64 65 78 44 65 6c 65 74 65 28 50 61 72 73 65 2a dexDelete(Parse*
23ed0 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 , Table*, int, i
23ee0 6e 74 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 nt, int*);.int s
23ef0 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 49 6e qlite3GenerateIn
23f00 64 65 78 4b 65 79 28 50 61 72 73 65 2a 2c 20 49 dexKey(Parse*, I
23f10 6e 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c ndex*, int, int,
23f20 20 69 6e 74 2c 20 69 6e 74 2a 2c 49 6e 64 65 78 int, int*,Index
23f30 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c *,int);.void sql
23f40 69 74 65 33 52 65 73 6f 6c 76 65 50 61 72 74 49 ite3ResolvePartI
23f50 64 78 4c 61 62 65 6c 28 50 61 72 73 65 2a 2c 69 dxLabel(Parse*,i
23f60 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
23f70 33 47 65 6e 65 72 61 74 65 43 6f 6e 73 74 72 61 3GenerateConstra
23f80 69 6e 74 43 68 65 63 6b 73 28 50 61 72 73 65 2a intChecks(Parse*
23f90 2c 54 61 62 6c 65 2a 2c 69 6e 74 2a 2c 69 6e 74 ,Table*,int*,int
23fa0 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 0a 20 20 ,int,int,int,.
23fb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23fc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23fd0 20 20 20 75 38 2c 75 38 2c 69 6e 74 2c 69 6e 74 u8,u8,int,int
23fe0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
23ff0 43 6f 6d 70 6c 65 74 65 49 6e 73 65 72 74 69 6f CompleteInsertio
24000 6e 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c n(Parse*,Table*,
24010 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2a int,int,int,int*
24020 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a 69 ,int,int,int);.i
24030 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 61 nt sqlite3OpenTa
24040 62 6c 65 41 6e 64 49 6e 64 69 63 65 73 28 50 61 bleAndIndices(Pa
24050 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e rse*, Table*, in
24060 74 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 69 6e 74 t, int, u8*, int
24070 2a 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 *, int*);.void s
24080 71 6c 69 74 65 33 42 65 67 69 6e 57 72 69 74 65 qlite3BeginWrite
24090 4f 70 65 72 61 74 69 6f 6e 28 50 61 72 73 65 2a Operation(Parse*
240a0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
240b0 64 20 73 71 6c 69 74 65 33 4d 75 6c 74 69 57 72 d sqlite3MultiWr
240c0 69 74 65 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ite(Parse*);.voi
240d0 64 20 73 71 6c 69 74 65 33 4d 61 79 41 62 6f 72 d sqlite3MayAbor
240e0 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 t(Parse*);.void
240f0 73 71 6c 69 74 65 33 48 61 6c 74 43 6f 6e 73 74 sqlite3HaltConst
24100 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e raint(Parse*, in
24110 74 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2c 20 69 t, int, char*, i
24120 38 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 8, u8);.void sql
24130 69 74 65 33 55 6e 69 71 75 65 43 6f 6e 73 74 72 ite3UniqueConstr
24140 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 aint(Parse*, int
24150 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 , Index*);.void
24160 73 71 6c 69 74 65 33 52 6f 77 69 64 43 6f 6e 73 sqlite3RowidCons
24170 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 traint(Parse*, i
24180 6e 74 2c 20 54 61 62 6c 65 2a 29 3b 0a 45 78 70 nt, Table*);.Exp
24190 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 44 75 r *sqlite3ExprDu
241a0 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a p(sqlite3*,Expr*
241b0 2c 69 6e 74 29 3b 0a 45 78 70 72 4c 69 73 74 20 ,int);.ExprList
241c0 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 *sqlite3ExprList
241d0 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 Dup(sqlite3*,Exp
241e0 72 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 53 72 63 rList*,int);.Src
241f0 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 List *sqlite3Src
24200 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a ListDup(sqlite3*
24210 2c 53 72 63 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a ,SrcList*,int);.
24220 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 49 IdList *sqlite3I
24230 64 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 dListDup(sqlite3
24240 2a 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 65 6c 65 *,IdList*);.Sele
24250 63 74 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 ct *sqlite3Selec
24260 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 tDup(sqlite3*,Se
24270 6c 65 63 74 2a 2c 69 6e 74 29 3b 0a 23 69 66 20 lect*,int);.#if
24280 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
24290 4c 45 44 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 LED.void sqlite3
242a0 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 28 53 65 SelectSetName(Se
242b0 6c 65 63 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 lect*,const char
242c0 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
242d0 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 ne sqlite3Select
242e0 53 65 74 4e 61 6d 65 28 41 2c 42 29 0a 23 65 6e SetName(A,B).#en
242f0 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
24300 46 75 6e 63 44 65 66 49 6e 73 65 72 74 28 46 75 FuncDefInsert(Fu
24310 6e 63 44 65 66 48 61 73 68 2a 2c 20 46 75 6e 63 ncDefHash*, Func
24320 44 65 66 2a 29 3b 0a 46 75 6e 63 44 65 66 20 2a Def*);.FuncDef *
24330 73 71 6c 69 74 65 33 46 69 6e 64 46 75 6e 63 74 sqlite3FindFunct
24340 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ion(sqlite3*,con
24350 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c 69 6e 74 st char*,int,int
24360 2c 75 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 ,u8,u8);.void sq
24370 6c 69 74 65 33 52 65 67 69 73 74 65 72 42 75 69 lite3RegisterBui
24380 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 73 28 73 71 ltinFunctions(sq
24390 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
243a0 6c 69 74 65 33 52 65 67 69 73 74 65 72 44 61 74 lite3RegisterDat
243b0 65 54 69 6d 65 46 75 6e 63 74 69 6f 6e 73 28 76 eTimeFunctions(v
243c0 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 oid);.void sqlit
243d0 65 33 52 65 67 69 73 74 65 72 47 6c 6f 62 61 6c e3RegisterGlobal
243e0 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
243f0 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 61 66 65 .int sqlite3Safe
24400 74 79 43 68 65 63 6b 4f 6b 28 73 71 6c 69 74 65 tyCheckOk(sqlite
24410 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 3*);.int sqlite3
24420 53 61 66 65 74 79 43 68 65 63 6b 53 69 63 6b 4f SafetyCheckSickO
24430 72 4f 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 rOk(sqlite3*);.v
24440 6f 69 64 20 73 71 6c 69 74 65 33 43 68 61 6e 67 oid sqlite3Chang
24450 65 43 6f 6f 6b 69 65 28 50 61 72 73 65 2a 2c 20 eCookie(Parse*,
24460 69 6e 74 29 3b 0a 0a 23 69 66 20 21 64 65 66 69 int);..#if !defi
24470 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ned(SQLITE_OMIT_
24480 56 49 45 57 29 20 26 26 20 21 64 65 66 69 6e 65 VIEW) && !define
24490 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 d(SQLITE_OMIT_TR
244a0 49 47 47 45 52 29 0a 76 6f 69 64 20 73 71 6c 69 IGGER).void sqli
244b0 74 65 33 4d 61 74 65 72 69 61 6c 69 7a 65 56 69 te3MaterializeVi
244c0 65 77 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 ew(Parse*, Table
244d0 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
244e0 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 #endif..#ifndef
244f0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 SQLITE_OMIT_TRIG
24500 47 45 52 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 GER. void sqlit
24510 65 33 42 65 67 69 6e 54 72 69 67 67 65 72 28 50 e3BeginTrigger(P
24520 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 54 6f arse*, Token*,To
24530 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c 49 64 4c ken*,int,int,IdL
24540 69 73 74 2a 2c 53 72 63 4c 69 73 74 2a 2c 0a 20 ist*,SrcList*,.
24550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24560 20 20 20 20 20 20 20 20 20 20 45 78 70 72 2a 2c Expr*,
24570 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
24580 64 20 73 71 6c 69 74 65 33 46 69 6e 69 73 68 54 d sqlite3FinishT
24590 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 54 rigger(Parse*, T
245a0 72 69 67 67 65 72 53 74 65 70 2a 2c 20 54 6f 6b riggerStep*, Tok
245b0 65 6e 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c en*);. void sql
245c0 69 74 65 33 44 72 6f 70 54 72 69 67 67 65 72 28 ite3DropTrigger(
245d0 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a Parse*, SrcList*
245e0 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 , int);. void s
245f0 71 6c 69 74 65 33 44 72 6f 70 54 72 69 67 67 65 qlite3DropTrigge
24600 72 50 74 72 28 50 61 72 73 65 2a 2c 20 54 72 69 rPtr(Parse*, Tri
24610 67 67 65 72 2a 29 3b 0a 20 20 54 72 69 67 67 65 gger*);. Trigge
24620 72 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 r *sqlite3Trigge
24630 72 73 45 78 69 73 74 28 50 61 72 73 65 20 2a 2c rsExist(Parse *,
24640 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 45 78 Table*, int, Ex
24650 70 72 4c 69 73 74 2a 2c 20 69 6e 74 20 2a 70 4d prList*, int *pM
24660 61 73 6b 29 3b 0a 20 20 54 72 69 67 67 65 72 20 ask);. Trigger
24670 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 4c *sqlite3TriggerL
24680 69 73 74 28 50 61 72 73 65 20 2a 2c 20 54 61 62 ist(Parse *, Tab
24690 6c 65 20 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 le *);. void sq
246a0 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 lite3CodeRowTrig
246b0 67 65 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 ger(Parse*, Trig
246c0 67 65 72 20 2a 2c 20 69 6e 74 2c 20 45 78 70 72 ger *, int, Expr
246d0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 54 61 62 6c List*, int, Tabl
246e0 65 20 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 e *,.
246f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24700 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
24710 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
24720 6f 64 65 52 6f 77 54 72 69 67 67 65 72 44 69 72 odeRowTriggerDir
24730 65 63 74 28 50 61 72 73 65 20 2a 2c 20 54 72 69 ect(Parse *, Tri
24740 67 67 65 72 20 2a 2c 20 54 61 62 6c 65 20 2a 2c gger *, Table *,
24750 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
24760 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 56 69 . void sqliteVi
24770 65 77 54 72 69 67 67 65 72 73 28 50 61 72 73 65 ewTriggers(Parse
24780 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a *, Table*, Expr*
24790 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a , int, ExprList*
247a0 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
247b0 33 44 65 6c 65 74 65 54 72 69 67 67 65 72 53 74 3DeleteTriggerSt
247c0 65 70 28 73 71 6c 69 74 65 33 2a 2c 20 54 72 69 ep(sqlite3*, Tri
247d0 67 67 65 72 53 74 65 70 2a 29 3b 0a 20 20 54 72 ggerStep*);. Tr
247e0 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 74 iggerStep *sqlit
247f0 65 33 54 72 69 67 67 65 72 53 65 6c 65 63 74 53 e3TriggerSelectS
24800 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 6c tep(sqlite3*,Sel
24810 65 63 74 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 ect*);. Trigger
24820 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 Step *sqlite3Tri
24830 67 67 65 72 49 6e 73 65 72 74 53 74 65 70 28 73 ggerInsertStep(s
24840 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 qlite3*,Token*,
24850 49 64 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 IdList*,.
24860 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24870 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24880 20 53 65 6c 65 63 74 2a 2c 75 38 29 3b 0a 20 20 Select*,u8);.
24890 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c TriggerStep *sql
248a0 69 74 65 33 54 72 69 67 67 65 72 55 70 64 61 74 ite3TriggerUpdat
248b0 65 53 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 eStep(sqlite3*,T
248c0 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
248d0 20 45 78 70 72 2a 2c 20 75 38 29 3b 0a 20 20 54 Expr*, u8);. T
248e0 72 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 riggerStep *sqli
248f0 74 65 33 54 72 69 67 67 65 72 44 65 6c 65 74 65 te3TriggerDelete
24900 53 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 6f Step(sqlite3*,To
24910 6b 65 6e 2a 2c 20 45 78 70 72 2a 29 3b 0a 20 20 ken*, Expr*);.
24920 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 void sqlite3Dele
24930 74 65 54 72 69 67 67 65 72 28 73 71 6c 69 74 65 teTrigger(sqlite
24940 33 2a 2c 20 54 72 69 67 67 65 72 2a 29 3b 0a 20 3*, Trigger*);.
24950 20 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c void sqlite3Unl
24960 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 72 69 67 inkAndDeleteTrig
24970 67 65 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ger(sqlite3*,int
24980 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 ,const char*);.
24990 20 75 33 32 20 73 71 6c 69 74 65 33 54 72 69 67 u32 sqlite3Trig
249a0 67 65 72 43 6f 6c 6d 61 73 6b 28 50 61 72 73 65 gerColmask(Parse
249b0 2a 2c 54 72 69 67 67 65 72 2a 2c 45 78 70 72 4c *,Trigger*,ExprL
249c0 69 73 74 2a 2c 69 6e 74 2c 69 6e 74 2c 54 61 62 ist*,int,int,Tab
249d0 6c 65 2a 2c 69 6e 74 29 3b 0a 23 20 64 65 66 69 le*,int);.# defi
249e0 6e 65 20 73 71 6c 69 74 65 33 50 61 72 73 65 54 ne sqlite3ParseT
249f0 6f 70 6c 65 76 65 6c 28 70 29 20 28 28 70 29 2d oplevel(p) ((p)-
24a00 3e 70 54 6f 70 6c 65 76 65 6c 20 3f 20 28 70 29 >pToplevel ? (p)
24a10 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 3a 20 28 70 ->pToplevel : (p
24a20 29 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e )).#else.# defin
24a30 65 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 e sqlite3Trigger
24a40 73 45 78 69 73 74 28 42 2c 43 2c 44 2c 45 2c 46 sExist(B,C,D,E,F
24a50 29 20 30 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ) 0.# define sql
24a60 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 67 65 ite3DeleteTrigge
24a70 72 28 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 r(A,B).# define
24a80 73 71 6c 69 74 65 33 44 72 6f 70 54 72 69 67 67 sqlite3DropTrigg
24a90 65 72 50 74 72 28 41 2c 42 29 0a 23 20 64 65 66 erPtr(A,B).# def
24aa0 69 6e 65 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e ine sqlite3Unlin
24ab0 6b 41 6e 64 44 65 6c 65 74 65 54 72 69 67 67 65 kAndDeleteTrigge
24ac0 72 28 41 2c 42 2c 43 29 0a 23 20 64 65 66 69 6e r(A,B,C).# defin
24ad0 65 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 e sqlite3CodeRow
24ae0 54 72 69 67 67 65 72 28 41 2c 42 2c 43 2c 44 2c Trigger(A,B,C,D,
24af0 45 2c 46 2c 47 2c 48 2c 49 29 0a 23 20 64 65 66 E,F,G,H,I).# def
24b00 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 64 65 52 ine sqlite3CodeR
24b10 6f 77 54 72 69 67 67 65 72 44 69 72 65 63 74 28 owTriggerDirect(
24b20 41 2c 42 2c 43 2c 44 2c 45 2c 46 29 0a 23 20 64 A,B,C,D,E,F).# d
24b30 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 69 efine sqlite3Tri
24b40 67 67 65 72 4c 69 73 74 28 58 2c 20 59 29 20 30 ggerList(X, Y) 0
24b50 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
24b60 33 50 61 72 73 65 54 6f 70 6c 65 76 65 6c 28 70 3ParseToplevel(p
24b70 29 20 70 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ) p.# define sql
24b80 69 74 65 33 54 72 69 67 67 65 72 43 6f 6c 6d 61 ite3TriggerColma
24b90 73 6b 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 sk(A,B,C,D,E,F,G
24ba0 29 20 30 0a 23 65 6e 64 69 66 0a 0a 69 6e 74 20 ) 0.#endif..int
24bb0 73 71 6c 69 74 65 33 4a 6f 69 6e 54 79 70 65 28 sqlite3JoinType(
24bc0 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Parse*, Token*,
24bd0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b Token*, Token*);
24be0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 72 65 .void sqlite3Cre
24bf0 61 74 65 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 ateForeignKey(Pa
24c00 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c rse*, ExprList*,
24c10 20 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 4c 69 73 Token*, ExprLis
24c20 74 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 t*, int);.void s
24c30 71 6c 69 74 65 33 44 65 66 65 72 46 6f 72 65 69 qlite3DeferForei
24c40 67 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 69 6e gnKey(Parse*, in
24c50 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 t);.#ifndef SQLI
24c60 54 45 5f 4f 4d 49 54 5f 41 55 54 48 4f 52 49 5a TE_OMIT_AUTHORIZ
24c70 41 54 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c ATION. void sql
24c80 69 74 65 33 41 75 74 68 52 65 61 64 28 50 61 72 ite3AuthRead(Par
24c90 73 65 2a 2c 45 78 70 72 2a 2c 53 63 68 65 6d 61 se*,Expr*,Schema
24ca0 2a 2c 53 72 63 4c 69 73 74 2a 29 3b 0a 20 20 69 *,SrcList*);. i
24cb0 6e 74 20 73 71 6c 69 74 65 33 41 75 74 68 43 68 nt sqlite3AuthCh
24cc0 65 63 6b 28 50 61 72 73 65 2a 2c 69 6e 74 2c 20 eck(Parse*,int,
24cd0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
24ce0 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
24cf0 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 char*);. void s
24d00 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 65 78 qlite3AuthContex
24d10 74 50 75 73 68 28 50 61 72 73 65 2a 2c 20 41 75 tPush(Parse*, Au
24d20 74 68 43 6f 6e 74 65 78 74 2a 2c 20 63 6f 6e 73 thContext*, cons
24d30 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 t char*);. void
24d40 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 sqlite3AuthCont
24d50 65 78 74 50 6f 70 28 41 75 74 68 43 6f 6e 74 65 extPop(AuthConte
24d60 78 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 xt*);. int sqli
24d70 74 65 33 41 75 74 68 52 65 61 64 43 6f 6c 28 50 te3AuthReadCol(P
24d80 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 arse*, const cha
24d90 72 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 r *, const char
24da0 2a 2c 20 69 6e 74 29 3b 0a 23 65 6c 73 65 0a 23 *, int);.#else.#
24db0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 define sqlite3A
24dc0 75 74 68 52 65 61 64 28 61 2c 62 2c 63 2c 64 29 uthRead(a,b,c,d)
24dd0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
24de0 33 41 75 74 68 43 68 65 63 6b 28 61 2c 62 2c 63 3AuthCheck(a,b,c
24df0 2c 64 2c 65 29 20 20 20 20 53 51 4c 49 54 45 5f ,d,e) SQLITE_
24e00 4f 4b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 OK.# define sqli
24e10 74 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 75 te3AuthContextPu
24e20 73 68 28 61 2c 62 2c 63 29 0a 23 20 64 65 66 69 sh(a,b,c).# defi
24e30 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f ne sqlite3AuthCo
24e40 6e 74 65 78 74 50 6f 70 28 61 29 20 20 28 28 76 ntextPop(a) ((v
24e50 6f 69 64 29 28 61 29 29 0a 23 65 6e 64 69 66 0a oid)(a)).#endif.
24e60 76 6f 69 64 20 73 71 6c 69 74 65 33 41 74 74 61 void sqlite3Atta
24e70 63 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a ch(Parse*, Expr*
24e80 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 29 3b , Expr*, Expr*);
24e90 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 74 .void sqlite3Det
24ea0 61 63 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 ach(Parse*, Expr
24eb0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
24ec0 46 69 78 49 6e 69 74 28 44 62 46 69 78 65 72 2a FixInit(DbFixer*
24ed0 2c 20 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 63 , Parse*, int, c
24ee0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
24ef0 74 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 t Token*);.int s
24f00 71 6c 69 74 65 33 46 69 78 53 72 63 4c 69 73 74 qlite3FixSrcList
24f10 28 44 62 46 69 78 65 72 2a 2c 20 53 72 63 4c 69 (DbFixer*, SrcLi
24f20 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 st*);.int sqlite
24f30 33 46 69 78 53 65 6c 65 63 74 28 44 62 46 69 78 3FixSelect(DbFix
24f40 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 er*, Select*);.i
24f50 6e 74 20 73 71 6c 69 74 65 33 46 69 78 45 78 70 nt sqlite3FixExp
24f60 72 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 r(DbFixer*, Expr
24f70 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 *);.int sqlite3F
24f80 69 78 45 78 70 72 4c 69 73 74 28 44 62 46 69 78 ixExprList(DbFix
24f90 65 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b er*, ExprList*);
24fa0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 54 .int sqlite3FixT
24fb0 72 69 67 67 65 72 53 74 65 70 28 44 62 46 69 78 riggerStep(DbFix
24fc0 65 72 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 er*, TriggerStep
24fd0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 *);.int sqlite3A
24fe0 74 6f 46 28 63 6f 6e 73 74 20 63 68 61 72 20 2a toF(const char *
24ff0 7a 2c 20 64 6f 75 62 6c 65 2a 2c 20 69 6e 74 2c z, double*, int,
25000 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u8);.int sqlite
25010 33 47 65 74 49 6e 74 33 32 28 63 6f 6e 73 74 20 3GetInt32(const
25020 63 68 61 72 20 2a 2c 20 69 6e 74 2a 29 3b 0a 69 char *, int*);.i
25030 6e 74 20 73 71 6c 69 74 65 33 41 74 6f 69 28 63 nt sqlite3Atoi(c
25040 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 onst char*);.int
25050 20 73 71 6c 69 74 65 33 55 74 66 31 36 42 79 74 sqlite3Utf16Byt
25060 65 4c 65 6e 28 63 6f 6e 73 74 20 76 6f 69 64 20 eLen(const void
25070 2a 70 44 61 74 61 2c 20 69 6e 74 20 6e 43 68 61 *pData, int nCha
25080 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 r);.int sqlite3U
25090 74 66 38 43 68 61 72 4c 65 6e 28 63 6f 6e 73 74 tf8CharLen(const
250a0 20 63 68 61 72 20 2a 70 44 61 74 61 2c 20 69 6e char *pData, in
250b0 74 20 6e 42 79 74 65 29 3b 0a 75 33 32 20 73 71 t nByte);.u32 sq
250c0 6c 69 74 65 33 55 74 66 38 52 65 61 64 28 63 6f lite3Utf8Read(co
250d0 6e 73 74 20 75 38 2a 2a 29 3b 0a 4c 6f 67 45 73 nst u8**);.LogEs
250e0 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 28 t sqlite3LogEst(
250f0 75 36 34 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c u64);.LogEst sql
25100 69 74 65 33 4c 6f 67 45 73 74 41 64 64 28 4c 6f ite3LogEstAdd(Lo
25110 67 45 73 74 2c 4c 6f 67 45 73 74 29 3b 0a 23 69 gEst,LogEst);.#i
25120 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
25130 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 4c T_VIRTUALTABLE.L
25140 6f 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 ogEst sqlite3Log
25150 45 73 74 46 72 6f 6d 44 6f 75 62 6c 65 28 64 6f EstFromDouble(do
25160 75 62 6c 65 29 3b 0a 23 65 6e 64 69 66 0a 75 36 uble);.#endif.u6
25170 34 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 54 4 sqlite3LogEstT
25180 6f 49 6e 74 28 4c 6f 67 45 73 74 29 3b 0a 0a 2f oInt(LogEst);../
25190 2a 0a 2a 2a 20 52 6f 75 74 69 6e 65 73 20 74 6f *.** Routines to
251a0 20 72 65 61 64 20 61 6e 64 20 77 72 69 74 65 20 read and write
251b0 76 61 72 69 61 62 6c 65 2d 6c 65 6e 67 74 68 20 variable-length
251c0 69 6e 74 65 67 65 72 73 2e 20 20 54 68 65 73 65 integers. These
251d0 20 75 73 65 64 20 74 6f 0a 2a 2a 20 62 65 20 64 used to.** be d
251e0 65 66 69 6e 65 64 20 6c 6f 63 61 6c 6c 79 2c 20 efined locally,
251f0 62 75 74 20 6e 6f 77 20 77 65 20 75 73 65 20 74 but now we use t
25200 68 65 20 76 61 72 69 6e 74 20 72 6f 75 74 69 6e he varint routin
25210 65 73 20 69 6e 20 74 68 65 20 75 74 69 6c 2e 63 es in the util.c
25220 0a 2a 2a 20 66 69 6c 65 2e 0a 2a 2f 0a 69 6e 74 .** file..*/.int
25230 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 6e sqlite3PutVarin
25240 74 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a t(unsigned char*
25250 2c 20 75 36 34 29 3b 0a 75 38 20 73 71 6c 69 74 , u64);.u8 sqlit
25260 65 33 47 65 74 56 61 72 69 6e 74 28 63 6f 6e 73 e3GetVarint(cons
25270 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 t unsigned char
25280 2a 2c 20 75 36 34 20 2a 29 3b 0a 75 38 20 73 71 *, u64 *);.u8 sq
25290 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 32 lite3GetVarint32
252a0 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 (const unsigned
252b0 63 68 61 72 20 2a 2c 20 75 33 32 20 2a 29 3b 0a char *, u32 *);.
252c0 69 6e 74 20 73 71 6c 69 74 65 33 56 61 72 69 6e int sqlite3Varin
252d0 74 4c 65 6e 28 75 36 34 20 76 29 3b 0a 0a 2f 2a tLen(u64 v);../*
252e0 0a 2a 2a 20 54 68 65 20 63 6f 6d 6d 6f 6e 20 63 .** The common c
252f0 61 73 65 20 69 73 20 66 6f 72 20 61 20 76 61 72 ase is for a var
25300 69 6e 74 20 74 6f 20 62 65 20 61 20 73 69 6e 67 int to be a sing
25310 6c 65 20 62 79 74 65 2e 20 20 54 68 65 79 20 66 le byte. They f
25320 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 6d 61 63 72 ollowing.** macr
25330 6f 73 20 68 61 6e 64 6c 65 20 74 68 65 20 63 6f os handle the co
25340 6d 6d 6f 6e 20 63 61 73 65 20 77 69 74 68 6f 75 mmon case withou
25350 74 20 61 20 70 72 6f 63 65 64 75 72 65 20 63 61 t a procedure ca
25360 6c 6c 2c 20 62 75 74 20 74 68 65 6e 20 63 61 6c ll, but then cal
25370 6c 0a 2a 2a 20 74 68 65 20 70 72 6f 63 65 64 75 l.** the procedu
25380 72 65 20 66 6f 72 20 6c 61 72 67 65 72 20 76 61 re for larger va
25390 72 69 6e 74 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e rints..*/.#defin
253a0 65 20 67 65 74 56 61 72 69 6e 74 33 32 28 41 2c e getVarint32(A,
253b0 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 2a 28 B) \. (u8)((*(
253c0 41 29 3c 28 75 38 29 30 78 38 30 29 3f 28 28 42 A)<(u8)0x80)?((B
253d0 29 3d 28 75 33 32 29 2a 28 41 29 29 2c 31 3a 73 )=(u32)*(A)),1:s
253e0 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 qlite3GetVarint3
253f0 32 28 28 41 29 2c 28 75 33 32 20 2a 29 26 28 42 2((A),(u32 *)&(B
25400 29 29 29 0a 23 64 65 66 69 6e 65 20 70 75 74 56 ))).#define putV
25410 61 72 69 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a arint32(A,B) \.
25420 20 20 28 75 38 29 28 28 28 75 33 32 29 28 42 29 (u8)(((u32)(B)
25430 3c 28 75 33 32 29 30 78 38 30 29 3f 28 2a 28 41 <(u32)0x80)?(*(A
25440 29 3d 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 )=(unsigned char
25450 29 28 42 29 29 2c 31 3a 5c 0a 20 20 73 71 6c 69 )(B)),1:\. sqli
25460 74 65 33 50 75 74 56 61 72 69 6e 74 28 28 41 29 te3PutVarint((A)
25470 2c 28 42 29 29 29 0a 23 64 65 66 69 6e 65 20 67 ,(B))).#define g
25480 65 74 56 61 72 69 6e 74 20 20 20 20 73 71 6c 69 etVarint sqli
25490 74 65 33 47 65 74 56 61 72 69 6e 74 0a 23 64 65 te3GetVarint.#de
254a0 66 69 6e 65 20 70 75 74 56 61 72 69 6e 74 20 20 fine putVarint
254b0 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 sqlite3PutVari
254c0 6e 74 0a 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 nt...const char
254d0 2a 73 71 6c 69 74 65 33 49 6e 64 65 78 41 66 66 *sqlite3IndexAff
254e0 69 6e 69 74 79 53 74 72 28 56 64 62 65 20 2a 2c inityStr(Vdbe *,
254f0 20 49 6e 64 65 78 20 2a 29 3b 0a 76 6f 69 64 20 Index *);.void
25500 73 71 6c 69 74 65 33 54 61 62 6c 65 41 66 66 69 sqlite3TableAffi
25510 6e 69 74 79 28 56 64 62 65 2a 2c 20 54 61 62 6c nity(Vdbe*, Tabl
25520 65 2a 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 73 e*, int);.char s
25530 71 6c 69 74 65 33 43 6f 6d 70 61 72 65 41 66 66 qlite3CompareAff
25540 69 6e 69 74 79 28 45 78 70 72 20 2a 70 45 78 70 inity(Expr *pExp
25550 72 2c 20 63 68 61 72 20 61 66 66 32 29 3b 0a 69 r, char aff2);.i
25560 6e 74 20 73 71 6c 69 74 65 33 49 6e 64 65 78 41 nt sqlite3IndexA
25570 66 66 69 6e 69 74 79 4f 6b 28 45 78 70 72 20 2a ffinityOk(Expr *
25580 70 45 78 70 72 2c 20 63 68 61 72 20 69 64 78 5f pExpr, char idx_
25590 61 66 66 69 6e 69 74 79 29 3b 0a 63 68 61 72 20 affinity);.char
255a0 73 71 6c 69 74 65 33 45 78 70 72 41 66 66 69 6e sqlite3ExprAffin
255b0 69 74 79 28 45 78 70 72 20 2a 70 45 78 70 72 29 ity(Expr *pExpr)
255c0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 74 6f ;.int sqlite3Ato
255d0 69 36 34 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c i64(const char*,
255e0 20 69 36 34 2a 2c 20 69 6e 74 2c 20 75 38 29 3b i64*, int, u8);
255f0 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 65 63 4f .int sqlite3DecO
25600 72 48 65 78 54 6f 49 36 34 28 63 6f 6e 73 74 20 rHexToI64(const
25610 63 68 61 72 2a 2c 20 69 36 34 2a 29 3b 0a 76 6f char*, i64*);.vo
25620 69 64 20 73 71 6c 69 74 65 33 45 72 72 6f 72 57 id sqlite3ErrorW
25630 69 74 68 4d 73 67 28 73 71 6c 69 74 65 33 2a 2c ithMsg(sqlite3*,
25640 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 int, const char
25650 2a 2c 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c *,...);.void sql
25660 69 74 65 33 45 72 72 6f 72 28 73 71 6c 69 74 65 ite3Error(sqlite
25670 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 3*,int);.void *s
25680 71 6c 69 74 65 33 48 65 78 54 6f 42 6c 6f 62 28 qlite3HexToBlob(
25690 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 sqlite3*, const
256a0 63 68 61 72 20 2a 7a 2c 20 69 6e 74 20 6e 29 3b char *z, int n);
256b0 0a 75 38 20 73 71 6c 69 74 65 33 48 65 78 54 6f .u8 sqlite3HexTo
256c0 49 6e 74 28 69 6e 74 20 68 29 3b 0a 69 6e 74 20 Int(int h);.int
256d0 73 71 6c 69 74 65 33 54 77 6f 50 61 72 74 4e 61 sqlite3TwoPartNa
256e0 6d 65 28 50 61 72 73 65 20 2a 2c 20 54 6f 6b 65 me(Parse *, Toke
256f0 6e 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f n *, Token *, To
25700 6b 65 6e 20 2a 2a 29 3b 0a 0a 23 69 66 20 64 65 ken **);..#if de
25710 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4e 45 45 fined(SQLITE_NEE
25720 44 5f 45 52 52 5f 4e 41 4d 45 29 0a 63 6f 6e 73 D_ERR_NAME).cons
25730 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 45 t char *sqlite3E
25740 72 72 4e 61 6d 65 28 69 6e 74 29 3b 0a 23 65 6e rrName(int);.#en
25750 64 69 66 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 dif..const char
25760 2a 73 71 6c 69 74 65 33 45 72 72 53 74 72 28 69 *sqlite3ErrStr(i
25770 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
25780 52 65 61 64 53 63 68 65 6d 61 28 50 61 72 73 65 ReadSchema(Parse
25790 20 2a 70 50 61 72 73 65 29 3b 0a 43 6f 6c 6c 53 *pParse);.CollS
257a0 65 71 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 43 eq *sqlite3FindC
257b0 6f 6c 6c 53 65 71 28 73 71 6c 69 74 65 33 2a 2c ollSeq(sqlite3*,
257c0 75 38 20 65 6e 63 2c 20 63 6f 6e 73 74 20 63 68 u8 enc, const ch
257d0 61 72 2a 2c 69 6e 74 29 3b 0a 43 6f 6c 6c 53 65 ar*,int);.CollSe
257e0 71 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 q *sqlite3Locate
257f0 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 CollSeq(Parse *p
25800 50 61 72 73 65 2c 20 63 6f 6e 73 74 20 63 68 61 Parse, const cha
25810 72 2a 7a 4e 61 6d 65 29 3b 0a 43 6f 6c 6c 53 65 r*zName);.CollSe
25820 71 20 2a 73 71 6c 69 74 65 33 45 78 70 72 43 6f q *sqlite3ExprCo
25830 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 50 61 llSeq(Parse *pPa
25840 72 73 65 2c 20 45 78 70 72 20 2a 70 45 78 70 72 rse, Expr *pExpr
25850 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
25860 45 78 70 72 41 64 64 43 6f 6c 6c 61 74 65 54 6f ExprAddCollateTo
25870 6b 65 6e 28 50 61 72 73 65 20 2a 70 50 61 72 73 ken(Parse *pPars
25880 65 2c 20 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 e, Expr*, const
25890 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a 45 78 Token*, int);.Ex
258a0 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 pr *sqlite3ExprA
258b0 64 64 43 6f 6c 6c 61 74 65 53 74 72 69 6e 67 28 ddCollateString(
258c0 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 63 6f 6e Parse*,Expr*,con
258d0 73 74 20 63 68 61 72 2a 29 3b 0a 45 78 70 72 20 st char*);.Expr
258e0 2a 73 71 6c 69 74 65 33 45 78 70 72 53 6b 69 70 *sqlite3ExprSkip
258f0 43 6f 6c 6c 61 74 65 28 45 78 70 72 2a 29 3b 0a Collate(Expr*);.
25900 69 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 6b int sqlite3Check
25910 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 2c CollSeq(Parse *,
25920 20 43 6f 6c 6c 53 65 71 20 2a 29 3b 0a 69 6e 74 CollSeq *);.int
25930 20 73 71 6c 69 74 65 33 43 68 65 63 6b 4f 62 6a sqlite3CheckObj
25940 65 63 74 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c ectName(Parse *,
25950 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a const char *);.
25960 76 6f 69 64 20 73 71 6c 69 74 65 33 56 64 62 65 void sqlite3Vdbe
25970 53 65 74 43 68 61 6e 67 65 73 28 73 71 6c 69 74 SetChanges(sqlit
25980 65 33 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 e3 *, int);.int
25990 73 71 6c 69 74 65 33 41 64 64 49 6e 74 36 34 28 sqlite3AddInt64(
259a0 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 i64*,i64);.int s
259b0 71 6c 69 74 65 33 53 75 62 49 6e 74 36 34 28 69 qlite3SubInt64(i
259c0 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 64*,i64);.int sq
259d0 6c 69 74 65 33 4d 75 6c 49 6e 74 36 34 28 69 36 lite3MulInt64(i6
259e0 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 4*,i64);.int sql
259f0 69 74 65 33 41 62 73 49 6e 74 33 32 28 69 6e 74 ite3AbsInt32(int
25a00 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 );.#ifdef SQLITE
25a10 5f 45 4e 41 42 4c 45 5f 38 5f 33 5f 4e 41 4d 45 _ENABLE_8_3_NAME
25a20 53 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 69 S.void sqlite3Fi
25a30 6c 65 53 75 66 66 69 78 33 28 63 6f 6e 73 74 20 leSuffix3(const
25a40 63 68 61 72 2a 2c 20 63 68 61 72 2a 29 3b 0a 23 char*, char*);.#
25a50 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
25a60 6c 69 74 65 33 46 69 6c 65 53 75 66 66 69 78 33 lite3FileSuffix3
25a70 28 58 2c 59 29 0a 23 65 6e 64 69 66 0a 75 38 20 (X,Y).#endif.u8
25a80 73 71 6c 69 74 65 33 47 65 74 42 6f 6f 6c 65 61 sqlite3GetBoolea
25a90 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c n(const char *z,
25aa0 75 38 29 3b 0a 0a 63 6f 6e 73 74 20 76 6f 69 64 u8);..const void
25ab0 20 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 54 65 *sqlite3ValueTe
25ac0 78 74 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 xt(sqlite3_value
25ad0 2a 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 *, u8);.int sqli
25ae0 74 65 33 56 61 6c 75 65 42 79 74 65 73 28 73 71 te3ValueBytes(sq
25af0 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 38 lite3_value*, u8
25b00 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
25b10 61 6c 75 65 53 65 74 53 74 72 28 73 71 6c 69 74 alueSetStr(sqlit
25b20 65 33 5f 76 61 6c 75 65 2a 2c 20 69 6e 74 2c 20 e3_value*, int,
25b30 63 6f 6e 73 74 20 76 6f 69 64 20 2a 2c 75 38 2c const void *,u8,
25b40 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
25b50 20 20 20 20 20 20 20 20 20 20 76 6f 69 64 28 2a void(*
25b60 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f 69 64 20 )(void*));.void
25b70 73 71 6c 69 74 65 33 56 61 6c 75 65 53 65 74 4e sqlite3ValueSetN
25b80 75 6c 6c 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ull(sqlite3_valu
25b90 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
25ba0 33 56 61 6c 75 65 46 72 65 65 28 73 71 6c 69 74 3ValueFree(sqlit
25bb0 65 33 5f 76 61 6c 75 65 2a 29 3b 0a 73 71 6c 69 e3_value*);.sqli
25bc0 74 65 33 5f 76 61 6c 75 65 20 2a 73 71 6c 69 74 te3_value *sqlit
25bd0 65 33 56 61 6c 75 65 4e 65 77 28 73 71 6c 69 74 e3ValueNew(sqlit
25be0 65 33 20 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c e3 *);.char *sql
25bf0 69 74 65 33 55 74 66 31 36 74 6f 38 28 73 71 6c ite3Utf16to8(sql
25c00 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 76 6f ite3 *, const vo
25c10 69 64 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 id*, int, u8);.i
25c20 6e 74 20 73 71 6c 69 74 65 33 56 61 6c 75 65 46 nt sqlite3ValueF
25c30 72 6f 6d 45 78 70 72 28 73 71 6c 69 74 65 33 20 romExpr(sqlite3
25c40 2a 2c 20 45 78 70 72 20 2a 2c 20 75 38 2c 20 75 *, Expr *, u8, u
25c50 38 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 8, sqlite3_value
25c60 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 **);.void sqlit
25c70 65 33 56 61 6c 75 65 41 70 70 6c 79 41 66 66 69 e3ValueApplyAffi
25c80 6e 69 74 79 28 73 71 6c 69 74 65 33 5f 76 61 6c nity(sqlite3_val
25c90 75 65 20 2a 2c 20 75 38 2c 20 75 38 29 3b 0a 23 ue *, u8, u8);.#
25ca0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 41 4d ifndef SQLITE_AM
25cb0 41 4c 47 41 4d 41 54 49 4f 4e 0a 65 78 74 65 72 ALGAMATION.exter
25cc0 6e 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 n const unsigned
25cd0 20 63 68 61 72 20 73 71 6c 69 74 65 33 4f 70 63 char sqlite3Opc
25ce0 6f 64 65 50 72 6f 70 65 72 74 79 5b 5d 3b 0a 65 odeProperty[];.e
25cf0 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 69 xtern const unsi
25d00 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 65 gned char sqlite
25d10 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b 5d 3b 3UpperToLower[];
25d20 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e .extern const un
25d30 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 signed char sqli
25d40 74 65 33 43 74 79 70 65 4d 61 70 5b 5d 3b 0a 65 te3CtypeMap[];.e
25d50 78 74 65 72 6e 20 63 6f 6e 73 74 20 54 6f 6b 65 xtern const Toke
25d60 6e 20 73 71 6c 69 74 65 33 49 6e 74 54 6f 6b 65 n sqlite3IntToke
25d70 6e 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 51 4c ns[];.extern SQL
25d80 49 54 45 5f 57 53 44 20 73 74 72 75 63 74 20 53 ITE_WSD struct S
25d90 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 73 71 6c qlite3Config sql
25da0 69 74 65 33 43 6f 6e 66 69 67 3b 0a 65 78 74 65 ite3Config;.exte
25db0 72 6e 20 53 51 4c 49 54 45 5f 57 53 44 20 46 75 rn SQLITE_WSD Fu
25dc0 6e 63 44 65 66 48 61 73 68 20 73 71 6c 69 74 65 ncDefHash sqlite
25dd0 33 47 6c 6f 62 61 6c 46 75 6e 63 74 69 6f 6e 73 3GlobalFunctions
25de0 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
25df0 5f 4f 4d 49 54 5f 57 53 44 0a 65 78 74 65 72 6e _OMIT_WSD.extern
25e00 20 69 6e 74 20 73 71 6c 69 74 65 33 50 65 6e 64 int sqlite3Pend
25e10 69 6e 67 42 79 74 65 3b 0a 23 65 6e 64 69 66 0a ingByte;.#endif.
25e20 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
25e30 74 65 33 52 6f 6f 74 50 61 67 65 4d 6f 76 65 64 te3RootPageMoved
25e40 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
25e50 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
25e60 73 71 6c 69 74 65 33 52 65 69 6e 64 65 78 28 50 sqlite3Reindex(P
25e70 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
25e80 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
25e90 69 74 65 33 41 6c 74 65 72 46 75 6e 63 74 69 6f ite3AlterFunctio
25ea0 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 ns(void);.void s
25eb0 71 6c 69 74 65 33 41 6c 74 65 72 52 65 6e 61 6d qlite3AlterRenam
25ec0 65 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 eTable(Parse*, S
25ed0 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 rcList*, Token*)
25ee0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 ;.int sqlite3Get
25ef0 54 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 Token(const unsi
25f00 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 69 6e 74 gned char *, int
25f10 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
25f20 33 4e 65 73 74 65 64 50 61 72 73 65 28 50 61 72 3NestedParse(Par
25f30 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a se*, const char*
25f40 2c 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c , ...);.void sql
25f50 69 74 65 33 45 78 70 69 72 65 50 72 65 70 61 72 ite3ExpirePrepar
25f60 65 64 53 74 61 74 65 6d 65 6e 74 73 28 73 71 6c edStatements(sql
25f70 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ite3*);.int sqli
25f80 74 65 33 43 6f 64 65 53 75 62 73 65 6c 65 63 74 te3CodeSubselect
25f90 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 2a (Parse *, Expr *
25fa0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
25fb0 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 50 d sqlite3SelectP
25fc0 72 65 70 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 rep(Parse*, Sele
25fd0 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 ct*, NameContext
25fe0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
25ff0 53 65 6c 65 63 74 57 72 6f 6e 67 4e 75 6d 54 65 SelectWrongNumTe
26000 72 6d 73 45 72 72 6f 72 28 50 61 72 73 65 20 2a rmsError(Parse *
26010 70 50 61 72 73 65 2c 20 53 65 6c 65 63 74 20 2a pParse, Select *
26020 70 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d p);.int sqlite3M
26030 61 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e atchSpanName(con
26040 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
26050 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
26060 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
26070 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 ;.int sqlite3Res
26080 6f 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 olveExprNames(Na
26090 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 meContext*, Expr
260a0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
260b0 52 65 73 6f 6c 76 65 53 65 6c 65 63 74 4e 61 6d ResolveSelectNam
260c0 65 73 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 es(Parse*, Selec
260d0 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a t*, NameContext*
260e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
260f0 65 73 6f 6c 76 65 53 65 6c 66 52 65 66 65 72 65 esolveSelfRefere
26100 6e 63 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 nce(Parse*,Table
26110 2a 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 78 70 72 *,int,Expr*,Expr
26120 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 List*);.int sqli
26130 74 65 33 52 65 73 6f 6c 76 65 4f 72 64 65 72 47 te3ResolveOrderG
26140 72 6f 75 70 42 79 28 50 61 72 73 65 2a 2c 20 53 roupBy(Parse*, S
26150 65 6c 65 63 74 2a 2c 20 45 78 70 72 4c 69 73 74 elect*, ExprList
26160 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
26170 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6c .void sqlite3Col
26180 75 6d 6e 44 65 66 61 75 6c 74 28 56 64 62 65 20 umnDefault(Vdbe
26190 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c *, Table *, int,
261a0 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
261b0 74 65 33 41 6c 74 65 72 46 69 6e 69 73 68 41 64 te3AlterFinishAd
261c0 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 2a 2c dColumn(Parse *,
261d0 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 Token *);.void
261e0 73 71 6c 69 74 65 33 41 6c 74 65 72 42 65 67 69 sqlite3AlterBegi
261f0 6e 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 nAddColumn(Parse
26200 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 29 3b 0a *, SrcList *);.
26210 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 CollSeq *sqlite3
26220 47 65 74 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 GetCollSeq(Parse
26230 2a 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 71 20 2a *, u8, CollSeq *
26240 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
26250 63 68 61 72 20 73 71 6c 69 74 65 33 41 66 66 69 char sqlite3Affi
26260 6e 69 74 79 54 79 70 65 28 63 6f 6e 73 74 20 63 nityType(const c
26270 68 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 6f 69 64 har*, u8*);.void
26280 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 28 sqlite3Analyze(
26290 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Parse*, Token*,
262a0 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
262b0 69 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 48 61 ite3InvokeBusyHa
262c0 6e 64 6c 65 72 28 42 75 73 79 48 61 6e 64 6c 65 ndler(BusyHandle
262d0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
262e0 46 69 6e 64 44 62 28 73 71 6c 69 74 65 33 2a 2c FindDb(sqlite3*,
262f0 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 Token*);.int sq
26300 6c 69 74 65 33 46 69 6e 64 44 62 4e 61 6d 65 28 lite3FindDbName(
26310 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 sqlite3 *, const
26320 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 char *);.int sq
26330 6c 69 74 65 33 41 6e 61 6c 79 73 69 73 4c 6f 61 lite3AnalysisLoa
26340 64 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 69 d(sqlite3*,int i
26350 44 42 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 DB);.void sqlite
26360 33 44 65 6c 65 74 65 49 6e 64 65 78 53 61 6d 70 3DeleteIndexSamp
26370 6c 65 73 28 73 71 6c 69 74 65 33 2a 2c 49 6e 64 les(sqlite3*,Ind
26380 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ex*);.void sqlit
26390 65 33 44 65 66 61 75 6c 74 52 6f 77 45 73 74 28 e3DefaultRowEst(
263a0 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 Index*);.void sq
263b0 6c 69 74 65 33 52 65 67 69 73 74 65 72 4c 69 6b lite3RegisterLik
263c0 65 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 eFunctions(sqlit
263d0 65 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 e3*, int);.int s
263e0 71 6c 69 74 65 33 49 73 4c 69 6b 65 46 75 6e 63 qlite3IsLikeFunc
263f0 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 45 78 tion(sqlite3*,Ex
26400 70 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a 29 3b pr*,int*,char*);
26410 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 69 6e .void sqlite3Min
26420 69 6d 75 6d 46 69 6c 65 46 6f 72 6d 61 74 28 50 imumFileFormat(P
26430 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 arse*, int, int)
26440 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 ;.void sqlite3Sc
26450 68 65 6d 61 43 6c 65 61 72 28 76 6f 69 64 20 2a hemaClear(void *
26460 29 3b 0a 53 63 68 65 6d 61 20 2a 73 71 6c 69 74 );.Schema *sqlit
26470 65 33 53 63 68 65 6d 61 47 65 74 28 73 71 6c 69 e3SchemaGet(sqli
26480 74 65 33 20 2a 2c 20 42 74 72 65 65 20 2a 29 3b te3 *, Btree *);
26490 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 63 68 65 .int sqlite3Sche
264a0 6d 61 54 6f 49 6e 64 65 78 28 73 71 6c 69 74 65 maToIndex(sqlite
264b0 33 20 2a 64 62 2c 20 53 63 68 65 6d 61 20 2a 29 3 *db, Schema *)
264c0 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 ;.KeyInfo *sqlit
264d0 65 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f 63 28 73 e3KeyInfoAlloc(s
264e0 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 6e 74 29 qlite3*,int,int)
264f0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4b 65 ;.void sqlite3Ke
26500 79 49 6e 66 6f 55 6e 72 65 66 28 4b 65 79 49 6e yInfoUnref(KeyIn
26510 66 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 fo*);.KeyInfo *s
26520 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f 52 65 66 qlite3KeyInfoRef
26530 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 (KeyInfo*);.KeyI
26540 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 nfo *sqlite3KeyI
26550 6e 66 6f 4f 66 49 6e 64 65 78 28 50 61 72 73 65 nfoOfIndex(Parse
26560 2a 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 69 66 64 *, Index*);.#ifd
26570 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a ef SQLITE_DEBUG.
26580 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 49 6e int sqlite3KeyIn
26590 66 6f 49 73 57 72 69 74 65 61 62 6c 65 28 4b 65 foIsWriteable(Ke
265a0 79 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 66 0a yInfo*);.#endif.
265b0 69 6e 74 20 73 71 6c 69 74 65 33 43 72 65 61 74 int sqlite3Creat
265c0 65 46 75 6e 63 28 73 71 6c 69 74 65 33 20 2a 2c eFunc(sqlite3 *,
265d0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 const char *, i
265e0 6e 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 2a 2c nt, int, void *,
265f0 20 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 71 6c . void (*)(sql
26600 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e ite3_context*,in
26610 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 t,sqlite3_value
26620 2a 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 **),. void (*)(
26630 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
26640 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c ,int,sqlite3_val
26650 75 65 20 2a 2a 29 2c 20 76 6f 69 64 20 28 2a 29 ue **), void (*)
26660 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
26670 2a 29 2c 0a 20 20 46 75 6e 63 44 65 73 74 72 75 *),. FuncDestru
26680 63 74 6f 72 20 2a 70 44 65 73 74 72 75 63 74 6f ctor *pDestructo
26690 72 0a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r.);.int sqlite3
266a0 41 70 69 45 78 69 74 28 73 71 6c 69 74 65 33 20 ApiExit(sqlite3
266b0 2a 64 62 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 *db, int);.int s
266c0 71 6c 69 74 65 33 4f 70 65 6e 54 65 6d 70 44 61 qlite3OpenTempDa
266d0 74 61 62 61 73 65 28 50 61 72 73 65 20 2a 29 3b tabase(Parse *);
266e0 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ..void sqlite3St
266f0 72 41 63 63 75 6d 49 6e 69 74 28 53 74 72 41 63 rAccumInit(StrAc
26700 63 75 6d 2a 2c 20 73 71 6c 69 74 65 33 2a 2c 20 cum*, sqlite3*,
26710 63 68 61 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 char*, int, int)
26720 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ;.void sqlite3St
26730 72 41 63 63 75 6d 41 70 70 65 6e 64 28 53 74 72 rAccumAppend(Str
26740 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 Accum*,const cha
26750 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 r*,int);.void sq
26760 6c 69 74 65 33 53 74 72 41 63 63 75 6d 41 70 70 lite3StrAccumApp
26770 65 6e 64 41 6c 6c 28 53 74 72 41 63 63 75 6d 2a endAll(StrAccum*
26780 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
26790 6f 69 64 20 73 71 6c 69 74 65 33 41 70 70 65 6e oid sqlite3Appen
267a0 64 43 68 61 72 28 53 74 72 41 63 63 75 6d 2a 2c dChar(StrAccum*,
267b0 69 6e 74 2c 63 68 61 72 29 3b 0a 63 68 61 72 20 int,char);.char
267c0 2a 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d *sqlite3StrAccum
267d0 46 69 6e 69 73 68 28 53 74 72 41 63 63 75 6d 2a Finish(StrAccum*
267e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
267f0 74 72 41 63 63 75 6d 52 65 73 65 74 28 53 74 72 trAccumReset(Str
26800 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 Accum*);.void sq
26810 6c 69 74 65 33 53 65 6c 65 63 74 44 65 73 74 49 lite3SelectDestI
26820 6e 69 74 28 53 65 6c 65 63 74 44 65 73 74 2a 2c nit(SelectDest*,
26830 69 6e 74 2c 69 6e 74 29 3b 0a 45 78 70 72 20 2a int,int);.Expr *
26840 73 71 6c 69 74 65 33 43 72 65 61 74 65 43 6f 6c sqlite3CreateCol
26850 75 6d 6e 45 78 70 72 28 73 71 6c 69 74 65 33 20 umnExpr(sqlite3
26860 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 69 6e *, SrcList *, in
26870 74 2c 20 69 6e 74 29 3b 0a 0a 76 6f 69 64 20 73 t, int);..void s
26880 71 6c 69 74 65 33 42 61 63 6b 75 70 52 65 73 74 qlite3BackupRest
26890 61 72 74 28 73 71 6c 69 74 65 33 5f 62 61 63 6b art(sqlite3_back
268a0 75 70 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 up *);.void sqli
268b0 74 65 33 42 61 63 6b 75 70 55 70 64 61 74 65 28 te3BackupUpdate(
268c0 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 20 2a sqlite3_backup *
268d0 2c 20 50 67 6e 6f 2c 20 63 6f 6e 73 74 20 75 38 , Pgno, const u8
268e0 20 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c *);..#ifdef SQL
268f0 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
26900 5f 4f 52 5f 53 54 41 54 34 0a 76 6f 69 64 20 73 _OR_STAT4.void s
26910 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 46 75 6e qlite3AnalyzeFun
26920 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 6e ctions(void);.in
26930 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 50 72 t sqlite3Stat4Pr
26940 6f 62 65 53 65 74 56 61 6c 75 65 28 50 61 72 73 obeSetValue(Pars
26950 65 2a 2c 49 6e 64 65 78 2a 2c 55 6e 70 61 63 6b e*,Index*,Unpack
26960 65 64 52 65 63 6f 72 64 2a 2a 2c 45 78 70 72 2a edRecord**,Expr*
26970 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a 69 ,u8,int,int*);.i
26980 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 56 nt sqlite3Stat4V
26990 61 6c 75 65 46 72 6f 6d 45 78 70 72 28 50 61 72 alueFromExpr(Par
269a0 73 65 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c 20 se*, Expr*, u8,
269b0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 sqlite3_value**)
269c0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ;.void sqlite3St
269d0 61 74 34 50 72 6f 62 65 46 72 65 65 28 55 6e 70 at4ProbeFree(Unp
269e0 61 63 6b 65 64 52 65 63 6f 72 64 2a 29 3b 0a 69 ackedRecord*);.i
269f0 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 43 nt sqlite3Stat4C
26a00 6f 6c 75 6d 6e 28 73 71 6c 69 74 65 33 2a 2c 20 olumn(sqlite3*,
26a10 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 const void*, int
26a20 2c 20 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f 76 , int, sqlite3_v
26a30 61 6c 75 65 2a 2a 29 3b 0a 23 65 6e 64 69 66 0a alue**);.#endif.
26a40 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 ./*.** The inter
26a50 66 61 63 65 20 74 6f 20 74 68 65 20 4c 45 4d 4f face to the LEMO
26a60 4e 2d 67 65 6e 65 72 61 74 65 64 20 70 61 72 73 N-generated pars
26a70 65 72 0a 2a 2f 0a 76 6f 69 64 20 2a 73 71 6c 69 er.*/.void *sqli
26a80 74 65 33 50 61 72 73 65 72 41 6c 6c 6f 63 28 76 te3ParserAlloc(v
26a90 6f 69 64 2a 28 2a 29 28 75 36 34 29 29 3b 0a 76 oid*(*)(u64));.v
26aa0 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 oid sqlite3Parse
26ab0 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 76 6f 69 rFree(void*, voi
26ac0 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f d(*)(void*));.vo
26ad0 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 id sqlite3Parser
26ae0 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 54 6f 6b (void*, int, Tok
26af0 65 6e 2c 20 50 61 72 73 65 2a 29 3b 0a 23 69 66 en, Parse*);.#if
26b00 64 65 66 20 59 59 54 52 41 43 4b 4d 41 58 53 54 def YYTRACKMAXST
26b10 41 43 4b 44 45 50 54 48 0a 20 20 69 6e 74 20 73 ACKDEPTH. int s
26b20 71 6c 69 74 65 33 50 61 72 73 65 72 53 74 61 63 qlite3ParserStac
26b30 6b 50 65 61 6b 28 76 6f 69 64 2a 29 3b 0a 23 65 kPeak(void*);.#e
26b40 6e 64 69 66 0a 0a 76 6f 69 64 20 73 71 6c 69 74 ndif..void sqlit
26b50 65 33 41 75 74 6f 4c 6f 61 64 45 78 74 65 6e 73 e3AutoLoadExtens
26b60 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a ions(sqlite3*);.
26b70 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
26b80 4d 49 54 5f 4c 4f 41 44 5f 45 58 54 45 4e 53 49 MIT_LOAD_EXTENSI
26b90 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 ON. void sqlite
26ba0 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 6f 6e 73 3CloseExtensions
26bb0 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 65 6c 73 (sqlite3*);.#els
26bc0 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
26bd0 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 6f 6e e3CloseExtension
26be0 73 28 58 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 s(X).#endif..#if
26bf0 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
26c00 5f 53 48 41 52 45 44 5f 43 41 43 48 45 0a 20 20 _SHARED_CACHE.
26c10 76 6f 69 64 20 73 71 6c 69 74 65 33 54 61 62 6c void sqlite3Tabl
26c20 65 4c 6f 63 6b 28 50 61 72 73 65 20 2a 2c 20 69 eLock(Parse *, i
26c30 6e 74 2c 20 69 6e 74 2c 20 75 38 2c 20 63 6f 6e nt, int, u8, con
26c40 73 74 20 63 68 61 72 20 2a 29 3b 0a 23 65 6c 73 st char *);.#els
26c50 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 e. #define sqli
26c60 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 76 2c 77 te3TableLock(v,w
26c70 2c 78 2c 79 2c 7a 29 0a 23 65 6e 64 69 66 0a 0a ,x,y,z).#endif..
26c80 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 54 45 #ifdef SQLITE_TE
26c90 53 54 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ST. int sqlite3
26ca0 55 74 66 38 54 6f 38 28 75 6e 73 69 67 6e 65 64 Utf8To8(unsigned
26cb0 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a char*);.#endif.
26cc0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 4f .#ifdef SQLITE_O
26cd0 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
26ce0 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
26cf0 65 33 56 74 61 62 43 6c 65 61 72 28 59 29 0a 23 e3VtabClear(Y).#
26d00 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
26d10 56 74 61 62 53 79 6e 63 28 58 2c 59 29 20 53 51 VtabSync(X,Y) SQ
26d20 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 65 66 69 6e LITE_OK.# defin
26d30 65 20 73 71 6c 69 74 65 33 56 74 61 62 52 6f 6c e sqlite3VtabRol
26d40 6c 62 61 63 6b 28 58 29 0a 23 20 20 64 65 66 69 lback(X).# defi
26d50 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f ne sqlite3VtabCo
26d60 6d 6d 69 74 28 58 29 0a 23 20 20 64 65 66 69 6e mmit(X).# defin
26d70 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 6e 53 e sqlite3VtabInS
26d80 79 6e 63 28 64 62 29 20 30 0a 23 20 20 64 65 66 ync(db) 0.# def
26d90 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 4c ine sqlite3VtabL
26da0 6f 63 6b 28 58 29 20 0a 23 20 20 64 65 66 69 6e ock(X) .# defin
26db0 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c e sqlite3VtabUnl
26dc0 6f 63 6b 28 58 29 0a 23 20 20 64 65 66 69 6e 65 ock(X).# define
26dd0 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
26de0 63 6b 4c 69 73 74 28 58 29 0a 23 20 20 64 65 66 ckList(X).# def
26df0 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 53 ine sqlite3VtabS
26e00 61 76 65 70 6f 69 6e 74 28 58 2c 20 59 2c 20 5a avepoint(X, Y, Z
26e10 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 ) SQLITE_OK.# d
26e20 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 65 74 efine sqlite3Get
26e30 56 54 61 62 6c 65 28 58 2c 59 29 20 20 28 28 56 VTable(X,Y) ((V
26e40 54 61 62 6c 65 2a 29 30 29 0a 23 65 6c 73 65 0a Table*)0).#else.
26e50 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 void sqlite3V
26e60 74 61 62 43 6c 65 61 72 28 73 71 6c 69 74 65 33 tabClear(sqlite3
26e70 20 2a 64 62 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 *db, Table*);.
26e80 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 void sqlite3Vt
26e90 61 62 44 69 73 63 6f 6e 6e 65 63 74 28 73 71 6c abDisconnect(sql
26ea0 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 20 ite3 *db, Table
26eb0 2a 70 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 *p);. int sqli
26ec0 74 65 33 56 74 61 62 53 79 6e 63 28 73 71 6c 69 te3VtabSync(sqli
26ed0 74 65 33 20 2a 64 62 2c 20 56 64 62 65 2a 29 3b te3 *db, Vdbe*);
26ee0 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 . int sqlite3V
26ef0 74 61 62 52 6f 6c 6c 62 61 63 6b 28 73 71 6c 69 tabRollback(sqli
26f00 74 65 33 20 2a 64 62 29 3b 0a 20 20 20 69 6e 74 te3 *db);. int
26f10 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f 6d 6d sqlite3VtabComm
26f20 69 74 28 73 71 6c 69 74 65 33 20 2a 64 62 29 3b it(sqlite3 *db);
26f30 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
26f40 56 74 61 62 4c 6f 63 6b 28 56 54 61 62 6c 65 20 VtabLock(VTable
26f50 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 *);. void sqli
26f60 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 28 56 54 te3VtabUnlock(VT
26f70 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 able *);. void
26f80 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
26f90 63 6b 4c 69 73 74 28 73 71 6c 69 74 65 33 2a 29 ckList(sqlite3*)
26fa0 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ;. int sqlite3
26fb0 56 74 61 62 53 61 76 65 70 6f 69 6e 74 28 73 71 VtabSavepoint(sq
26fc0 6c 69 74 65 33 20 2a 2c 20 69 6e 74 2c 20 69 6e lite3 *, int, in
26fd0 74 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 t);. void sqli
26fe0 74 65 33 56 74 61 62 49 6d 70 6f 72 74 45 72 72 te3VtabImportErr
26ff0 6d 73 67 28 56 64 62 65 2a 2c 20 73 71 6c 69 74 msg(Vdbe*, sqlit
27000 65 33 5f 76 74 61 62 2a 29 3b 0a 20 20 20 56 54 e3_vtab*);. VT
27010 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 47 65 74 able *sqlite3Get
27020 56 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c VTable(sqlite3*,
27030 20 54 61 62 6c 65 2a 29 3b 0a 23 20 20 64 65 66 Table*);.# def
27040 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 ine sqlite3VtabI
27050 6e 53 79 6e 63 28 64 62 29 20 28 28 64 62 29 2d nSync(db) ((db)-
27060 3e 6e 56 54 72 61 6e 73 3e 30 20 26 26 20 28 64 >nVTrans>0 && (d
27070 62 29 2d 3e 61 56 54 72 61 6e 73 3d 3d 30 29 0a b)->aVTrans==0).
27080 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
27090 74 65 33 56 74 61 62 4d 61 6b 65 57 72 69 74 61 te3VtabMakeWrita
270a0 62 6c 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 ble(Parse*,Table
270b0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
270c0 56 74 61 62 42 65 67 69 6e 50 61 72 73 65 28 50 VtabBeginParse(P
270d0 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
270e0 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 69 oken*, Token*, i
270f0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27100 33 56 74 61 62 46 69 6e 69 73 68 50 61 72 73 65 3VtabFinishParse
27110 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 (Parse*, Token*)
27120 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 ;.void sqlite3Vt
27130 61 62 41 72 67 49 6e 69 74 28 50 61 72 73 65 2a abArgInit(Parse*
27140 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
27150 74 61 62 41 72 67 45 78 74 65 6e 64 28 50 61 72 tabArgExtend(Par
27160 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e se*, Token*);.in
27170 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 61 6c t sqlite3VtabCal
27180 6c 43 72 65 61 74 65 28 73 71 6c 69 74 65 33 2a lCreate(sqlite3*
27190 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 , int, const cha
271a0 72 20 2a 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 69 r *, char **);.i
271b0 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 61 nt sqlite3VtabCa
271c0 6c 6c 43 6f 6e 6e 65 63 74 28 50 61 72 73 65 2a llConnect(Parse*
271d0 2c 20 54 61 62 6c 65 2a 29 3b 0a 69 6e 74 20 73 , Table*);.int s
271e0 71 6c 69 74 65 33 56 74 61 62 43 61 6c 6c 44 65 qlite3VtabCallDe
271f0 73 74 72 6f 79 28 73 71 6c 69 74 65 33 2a 2c 20 stroy(sqlite3*,
27200 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 int, const char
27210 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 *);.int sqlite3V
27220 74 61 62 42 65 67 69 6e 28 73 71 6c 69 74 65 33 tabBegin(sqlite3
27230 20 2a 2c 20 56 54 61 62 6c 65 20 2a 29 3b 0a 46 *, VTable *);.F
27240 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 65 33 56 uncDef *sqlite3V
27250 74 61 62 4f 76 65 72 6c 6f 61 64 46 75 6e 63 74 tabOverloadFunct
27260 69 6f 6e 28 73 71 6c 69 74 65 33 20 2a 2c 46 75 ion(sqlite3 *,Fu
27270 6e 63 44 65 66 2a 2c 20 69 6e 74 20 6e 41 72 67 ncDef*, int nArg
27280 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
27290 71 6c 69 74 65 33 49 6e 76 61 6c 69 64 46 75 6e qlite3InvalidFun
272a0 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 5f 63 6f ction(sqlite3_co
272b0 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 ntext*,int,sqlit
272c0 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 73 71 6c e3_value**);.sql
272d0 69 74 65 33 5f 69 6e 74 36 34 20 73 71 6c 69 74 ite3_int64 sqlit
272e0 65 33 53 74 6d 74 43 75 72 72 65 6e 74 54 69 6d e3StmtCurrentTim
272f0 65 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 e(sqlite3_contex
27300 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
27310 56 64 62 65 50 61 72 61 6d 65 74 65 72 49 6e 64 VdbeParameterInd
27320 65 78 28 56 64 62 65 2a 2c 20 63 6f 6e 73 74 20 ex(Vdbe*, const
27330 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 char*, int);.int
27340 20 73 71 6c 69 74 65 33 54 72 61 6e 73 66 65 72 sqlite3Transfer
27350 42 69 6e 64 69 6e 67 73 28 73 71 6c 69 74 65 33 Bindings(sqlite3
27360 5f 73 74 6d 74 20 2a 2c 20 73 71 6c 69 74 65 33 _stmt *, sqlite3
27370 5f 73 74 6d 74 20 2a 29 3b 0a 76 6f 69 64 20 73 _stmt *);.void s
27380 71 6c 69 74 65 33 50 61 72 73 65 72 52 65 73 65 qlite3ParserRese
27390 74 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 t(Parse*);.int s
273a0 71 6c 69 74 65 33 52 65 70 72 65 70 61 72 65 28 qlite3Reprepare(
273b0 56 64 62 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Vdbe*);.void sql
273c0 69 74 65 33 45 78 70 72 4c 69 73 74 43 68 65 63 ite3ExprListChec
273d0 6b 4c 65 6e 67 74 68 28 50 61 72 73 65 2a 2c 20 kLength(Parse*,
273e0 45 78 70 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 74 ExprList*, const
273f0 20 63 68 61 72 2a 29 3b 0a 43 6f 6c 6c 53 65 71 char*);.CollSeq
27400 20 2a 73 71 6c 69 74 65 33 42 69 6e 61 72 79 43 *sqlite3BinaryC
27410 6f 6d 70 61 72 65 43 6f 6c 6c 53 65 71 28 50 61 ompareCollSeq(Pa
27420 72 73 65 20 2a 2c 20 45 78 70 72 20 2a 2c 20 45 rse *, Expr *, E
27430 78 70 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 xpr *);.int sqli
27440 74 65 33 54 65 6d 70 49 6e 4d 65 6d 6f 72 79 28 te3TempInMemory(
27450 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 2a 29 3b const sqlite3*);
27460 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c .const char *sql
27470 69 74 65 33 4a 6f 75 72 6e 61 6c 4d 6f 64 65 6e ite3JournalModen
27480 61 6d 65 28 69 6e 74 29 3b 0a 23 69 66 6e 64 65 ame(int);.#ifnde
27490 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 41 f SQLITE_OMIT_WA
274a0 4c 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 43 L. int sqlite3C
274b0 68 65 63 6b 70 6f 69 6e 74 28 73 71 6c 69 74 65 heckpoint(sqlite
274c0 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 3*, int, int, in
274d0 74 2a 2c 20 69 6e 74 2a 29 3b 0a 20 20 69 6e 74 t*, int*);. int
274e0 20 73 71 6c 69 74 65 33 57 61 6c 44 65 66 61 75 sqlite3WalDefau
274f0 6c 74 48 6f 6f 6b 28 76 6f 69 64 2a 2c 73 71 6c ltHook(void*,sql
27500 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 ite3*,const char
27510 2a 2c 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 23 *,int);.#endif.#
27520 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
27530 49 54 5f 43 54 45 0a 20 20 57 69 74 68 20 2a 73 IT_CTE. With *s
27540 71 6c 69 74 65 33 57 69 74 68 41 64 64 28 50 61 qlite3WithAdd(Pa
27550 72 73 65 2a 2c 57 69 74 68 2a 2c 54 6f 6b 65 6e rse*,With*,Token
27560 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 65 6c 65 *,ExprList*,Sele
27570 63 74 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c ct*);. void sql
27580 69 74 65 33 57 69 74 68 44 65 6c 65 74 65 28 73 ite3WithDelete(s
27590 71 6c 69 74 65 33 2a 2c 57 69 74 68 2a 29 3b 0a qlite3*,With*);.
275a0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 void sqlite3Wi
275b0 74 68 50 75 73 68 28 50 61 72 73 65 2a 2c 20 57 thPush(Parse*, W
275c0 69 74 68 2a 2c 20 75 38 29 3b 0a 23 65 6c 73 65 ith*, u8);.#else
275d0 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 .#define sqlite3
275e0 57 69 74 68 50 75 73 68 28 78 2c 79 2c 7a 29 0a WithPush(x,y,z).
275f0 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 57 #define sqlite3W
27600 69 74 68 44 65 6c 65 74 65 28 78 2c 79 29 0a 23 ithDelete(x,y).#
27610 65 6e 64 69 66 0a 0a 2f 2a 20 44 65 63 6c 61 72 endif../* Declar
27620 61 74 69 6f 6e 73 20 66 6f 72 20 66 75 6e 63 74 ations for funct
27630 69 6f 6e 73 20 69 6e 20 66 6b 65 79 2e 63 2e 20 ions in fkey.c.
27640 41 6c 6c 20 6f 66 20 74 68 65 73 65 20 61 72 65 All of these are
27650 20 72 65 70 6c 61 63 65 64 20 62 79 0a 2a 2a 20 replaced by.**
27660 6e 6f 2d 6f 70 20 6d 61 63 72 6f 73 20 69 66 20 no-op macros if
27670 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 OMIT_FOREIGN_KEY
27680 20 69 73 20 64 65 66 69 6e 65 64 2e 20 49 6e 20 is defined. In
27690 74 68 69 73 20 63 61 73 65 20 6e 6f 20 66 6f 72 this case no for
276a0 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 66 75 6e 63 eign.** key func
276b0 74 69 6f 6e 61 6c 69 74 79 20 69 73 20 61 76 61 tionality is ava
276c0 69 6c 61 62 6c 65 2e 20 49 66 20 4f 4d 49 54 5f ilable. If OMIT_
276d0 54 52 49 47 47 45 52 20 69 73 20 64 65 66 69 6e TRIGGER is defin
276e0 65 64 20 62 75 74 0a 2a 2a 20 4f 4d 49 54 5f 46 ed but.** OMIT_F
276f0 4f 52 45 49 47 4e 5f 4b 45 59 20 69 73 20 6e 6f OREIGN_KEY is no
27700 74 2c 20 6f 6e 6c 79 20 73 6f 6d 65 20 6f 66 20 t, only some of
27710 74 68 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 the functions ar
27720 65 20 6e 6f 2d 6f 70 65 64 2e 20 49 6e 0a 2a 2a e no-oped. In.**
27730 20 74 68 69 73 20 63 61 73 65 20 66 6f 72 65 69 this case forei
27740 67 6e 20 6b 65 79 73 20 61 72 65 20 70 61 72 73 gn keys are pars
27750 65 64 2c 20 62 75 74 20 6e 6f 20 6f 74 68 65 72 ed, but no other
27760 20 66 75 6e 63 74 69 6f 6e 61 6c 69 74 79 20 69 functionality i
27770 73 20 0a 2a 2a 20 70 72 6f 76 69 64 65 64 20 28 s .** provided (
27780 65 6e 66 6f 72 63 65 6d 65 6e 74 20 6f 66 20 46 enforcement of F
27790 4b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 72 65 K constraints re
277a0 71 75 69 72 65 73 20 74 68 65 20 74 72 69 67 67 quires the trigg
277b0 65 72 73 20 73 75 62 2d 73 79 73 74 65 6d 29 2e ers sub-system).
277c0 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 .*/.#if !defined
277d0 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 (SQLITE_OMIT_FOR
277e0 45 49 47 4e 5f 4b 45 59 29 20 26 26 20 21 64 65 EIGN_KEY) && !de
277f0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 fined(SQLITE_OMI
27800 54 5f 54 52 49 47 47 45 52 29 0a 20 20 76 6f 69 T_TRIGGER). voi
27810 64 20 73 71 6c 69 74 65 33 46 6b 43 68 65 63 6b d sqlite3FkCheck
27820 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
27830 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c int, int, int*,
27840 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 int);. void sq
27850 6c 69 74 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 lite3FkDropTable
27860 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 (Parse*, SrcList
27870 20 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 76 *, Table*);. v
27880 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 41 63 74 oid sqlite3FkAct
27890 69 6f 6e 73 28 50 61 72 73 65 2a 2c 20 54 61 62 ions(Parse*, Tab
278a0 6c 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 le*, ExprList*,
278b0 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b int, int*, int);
278c0 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 6b . int sqlite3Fk
278d0 52 65 71 75 69 72 65 64 28 50 61 72 73 65 2a 2c Required(Parse*,
278e0 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2a 2c 20 69 Table*, int*, i
278f0 6e 74 29 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 nt);. u32 sqlit
27900 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 50 61 72 73 e3FkOldmask(Pars
27910 65 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 46 e*, Table*);. F
27920 4b 65 79 20 2a 73 71 6c 69 74 65 33 46 6b 52 65 Key *sqlite3FkRe
27930 66 65 72 65 6e 63 65 73 28 54 61 62 6c 65 20 2a ferences(Table *
27940 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 );.#else. #defi
27950 6e 65 20 73 71 6c 69 74 65 33 46 6b 41 63 74 69 ne sqlite3FkActi
27960 6f 6e 73 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 ons(a,b,c,d,e,f)
27970 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
27980 65 33 46 6b 43 68 65 63 6b 28 61 2c 62 2c 63 2c e3FkCheck(a,b,c,
27990 64 2c 65 2c 66 29 0a 20 20 23 64 65 66 69 6e 65 d,e,f). #define
279a0 20 73 71 6c 69 74 65 33 46 6b 44 72 6f 70 54 61 sqlite3FkDropTa
279b0 62 6c 65 28 61 2c 62 2c 63 29 0a 20 20 23 64 65 ble(a,b,c). #de
279c0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 4f 6c fine sqlite3FkOl
279d0 64 6d 61 73 6b 28 61 2c 62 29 20 20 20 20 20 20 dmask(a,b)
279e0 20 20 20 30 0a 20 20 23 64 65 66 69 6e 65 20 73 0. #define s
279f0 71 6c 69 74 65 33 46 6b 52 65 71 75 69 72 65 64 qlite3FkRequired
27a00 28 61 2c 62 2c 63 2c 64 29 20 20 20 20 30 0a 23 (a,b,c,d) 0.#
27a10 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 endif.#ifndef SQ
27a20 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 LITE_OMIT_FOREIG
27a30 4e 5f 4b 45 59 0a 20 20 76 6f 69 64 20 73 71 6c N_KEY. void sql
27a40 69 74 65 33 46 6b 44 65 6c 65 74 65 28 73 71 6c ite3FkDelete(sql
27a50 69 74 65 33 20 2a 2c 20 54 61 62 6c 65 2a 29 3b ite3 *, Table*);
27a60 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 6b . int sqlite3Fk
27a70 4c 6f 63 61 74 65 49 6e 64 65 78 28 50 61 72 73 LocateIndex(Pars
27a80 65 2a 2c 54 61 62 6c 65 2a 2c 46 4b 65 79 2a 2c e*,Table*,FKey*,
27a90 49 6e 64 65 78 2a 2a 2c 69 6e 74 2a 2a 29 3b 0a Index**,int**);.
27aa0 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
27ab0 73 71 6c 69 74 65 33 46 6b 44 65 6c 65 74 65 28 sqlite3FkDelete(
27ac0 61 2c 62 29 0a 20 20 23 64 65 66 69 6e 65 20 73 a,b). #define s
27ad0 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e qlite3FkLocateIn
27ae0 64 65 78 28 61 2c 62 2c 63 2c 64 2c 65 29 0a 23 dex(a,b,c,d,e).#
27af0 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 41 76 endif.../*.** Av
27b00 61 69 6c 61 62 6c 65 20 66 61 75 6c 74 20 69 6e ailable fault in
27b10 6a 65 63 74 6f 72 73 2e 20 20 53 68 6f 75 6c 64 jectors. Should
27b20 20 62 65 20 6e 75 6d 62 65 72 65 64 20 62 65 67 be numbered beg
27b30 69 6e 6e 69 6e 67 20 77 69 74 68 20 30 2e 0a 2a inning with 0..*
27b40 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
27b50 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 4d _FAULTINJECTOR_M
27b60 41 4c 4c 4f 43 20 20 20 20 20 30 0a 23 64 65 66 ALLOC 0.#def
27b70 69 6e 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 ine SQLITE_FAULT
27b80 49 4e 4a 45 43 54 4f 52 5f 43 4f 55 4e 54 20 20 INJECTOR_COUNT
27b90 20 20 20 20 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 1../*.** The
27ba0 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 74 68 interface to th
27bb0 65 20 63 6f 64 65 20 69 6e 20 66 61 75 6c 74 2e e code in fault.
27bc0 63 20 75 73 65 64 20 66 6f 72 20 69 64 65 6e 74 c used for ident
27bd0 69 66 79 69 6e 67 20 22 62 65 6e 69 67 6e 22 0a ifying "benign".
27be0 2a 2a 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 ** malloc failur
27bf0 65 73 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 es. This is only
27c00 20 70 72 65 73 65 6e 74 20 69 66 20 53 51 4c 49 present if SQLI
27c10 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f TE_OMIT_BUILTIN_
27c20 54 45 53 54 0a 2a 2a 20 69 73 20 6e 6f 74 20 64 TEST.** is not d
27c30 65 66 69 6e 65 64 2e 0a 2a 2f 0a 23 69 66 6e 64 efined..*/.#ifnd
27c40 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 ef SQLITE_OMIT_B
27c50 55 49 4c 54 49 4e 5f 54 45 53 54 0a 20 20 76 6f UILTIN_TEST. vo
27c60 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 6e 42 id sqlite3BeginB
27c70 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 enignMalloc(void
27c80 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
27c90 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3EndBenignMalloc
27ca0 28 76 6f 69 64 29 3b 0a 23 65 6c 73 65 0a 20 20 (void);.#else.
27cb0 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 42 #define sqlite3B
27cc0 65 67 69 6e 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 eginBenignMalloc
27cd0 28 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c (). #define sql
27ce0 69 74 65 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c ite3EndBenignMal
27cf0 6c 6f 63 28 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a loc().#endif../*
27d00 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 .** Allowed retu
27d10 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 rn values from s
27d20 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 qlite3FindInInde
27d30 78 28 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 x().*/.#define I
27d40 4e 5f 49 4e 44 45 58 5f 52 4f 57 49 44 20 20 20 N_INDEX_ROWID
27d50 20 20 20 20 20 31 20 20 20 2f 2a 20 53 65 61 72 1 /* Sear
27d60 63 68 20 74 68 65 20 72 6f 77 69 64 20 6f 66 20 ch the rowid of
27d70 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 the table */.#de
27d80 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 45 50 fine IN_INDEX_EP
27d90 48 20 20 20 20 20 20 20 20 20 20 32 20 20 20 2f H 2 /
27da0 2a 20 53 65 61 72 63 68 20 61 6e 20 65 70 68 65 * Search an ephe
27db0 6d 65 72 61 6c 20 62 2d 74 72 65 65 20 2a 2f 0a meral b-tree */.
27dc0 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 #define IN_INDEX
27dd0 5f 49 4e 44 45 58 5f 41 53 43 20 20 20 20 33 20 _INDEX_ASC 3
27de0 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 20 69 6e /* Existing in
27df0 64 65 78 20 41 53 43 45 4e 44 49 4e 47 20 2a 2f dex ASCENDING */
27e00 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 .#define IN_INDE
27e10 58 5f 49 4e 44 45 58 5f 44 45 53 43 20 20 20 34 X_INDEX_DESC 4
27e20 20 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 20 69 /* Existing i
27e30 6e 64 65 78 20 44 45 53 43 45 4e 44 49 4e 47 20 ndex DESCENDING
27e40 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
27e50 44 45 58 5f 4e 4f 4f 50 20 20 20 20 20 20 20 20 DEX_NOOP
27e60 20 35 20 20 20 2f 2a 20 4e 6f 20 74 61 62 6c 65 5 /* No table
27e70 20 61 76 61 69 6c 61 62 6c 65 2e 20 55 73 65 20 available. Use
27e80 63 6f 6d 70 61 72 69 73 6f 6e 73 20 2a 2f 0a 2f comparisons */./
27e90 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 66 6c 61 *.** Allowed fla
27ea0 67 73 20 66 6f 72 20 74 68 65 20 33 72 64 20 70 gs for the 3rd p
27eb0 61 72 61 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 arameter to sqli
27ec0 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 te3FindInIndex()
27ed0 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f ..*/.#define IN_
27ee0 49 4e 44 45 58 5f 4e 4f 4f 50 5f 4f 4b 20 20 20 INDEX_NOOP_OK
27ef0 20 20 30 78 30 30 30 31 20 20 2f 2a 20 4f 4b 20 0x0001 /* OK
27f00 74 6f 20 72 65 74 75 72 6e 20 49 4e 5f 49 4e 44 to return IN_IND
27f10 45 58 5f 4e 4f 4f 50 20 2a 2f 0a 23 64 65 66 69 EX_NOOP */.#defi
27f20 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4d 45 4d 42 ne IN_INDEX_MEMB
27f30 45 52 53 48 49 50 20 20 30 78 30 30 30 32 20 20 ERSHIP 0x0002
27f40 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 /* IN operator u
27f50 73 65 64 20 66 6f 72 20 6d 65 6d 62 65 72 73 68 sed for membersh
27f60 69 70 20 74 65 73 74 20 2a 2f 0a 23 64 65 66 69 ip test */.#defi
27f70 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4c 4f 4f 50 ne IN_INDEX_LOOP
27f80 20 20 20 20 20 20 20 20 30 78 30 30 30 34 20 20 0x0004
27f90 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 20 75 /* IN operator u
27fa0 73 65 64 20 61 73 20 61 20 6c 6f 6f 70 20 2a 2f sed as a loop */
27fb0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 6e 64 .int sqlite3Find
27fc0 49 6e 49 6e 64 65 78 28 50 61 72 73 65 20 2a 2c InIndex(Parse *,
27fd0 20 45 78 70 72 20 2a 2c 20 75 33 32 2c 20 69 6e Expr *, u32, in
27fe0 74 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c t*);..#ifdef SQL
27ff0 49 54 45 5f 45 4e 41 42 4c 45 5f 41 54 4f 4d 49 ITE_ENABLE_ATOMI
28000 43 5f 57 52 49 54 45 0a 20 20 69 6e 74 20 73 71 C_WRITE. int sq
28010 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e lite3JournalOpen
28020 28 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 2c 20 (sqlite3_vfs *,
28030 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 73 71 const char *, sq
28040 6c 69 74 65 33 5f 66 69 6c 65 20 2a 2c 20 69 6e lite3_file *, in
28050 74 2c 20 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 t, int);. int s
28060 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 53 69 7a qlite3JournalSiz
28070 65 28 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 29 e(sqlite3_vfs *)
28080 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a ;. int sqlite3J
28090 6f 75 72 6e 61 6c 43 72 65 61 74 65 28 73 71 6c ournalCreate(sql
280a0 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 20 20 ite3_file *);.
280b0 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e int sqlite3Journ
280c0 61 6c 45 78 69 73 74 73 28 73 71 6c 69 74 65 33 alExists(sqlite3
280d0 5f 66 69 6c 65 20 2a 70 29 3b 0a 23 65 6c 73 65 _file *p);.#else
280e0 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
280f0 65 33 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 70 56 e3JournalSize(pV
28100 66 73 29 20 28 28 70 56 66 73 29 2d 3e 73 7a 4f fs) ((pVfs)->szO
28110 73 46 69 6c 65 29 0a 20 20 23 64 65 66 69 6e 65 sFile). #define
28120 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 45 sqlite3JournalE
28130 78 69 73 74 73 28 70 29 20 31 0a 23 65 6e 64 69 xists(p) 1.#endi
28140 66 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d f..void sqlite3M
28150 65 6d 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 emJournalOpen(sq
28160 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 69 lite3_file *);.i
28170 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 4a 6f 75 nt sqlite3MemJou
28180 72 6e 61 6c 53 69 7a 65 28 76 6f 69 64 29 3b 0a rnalSize(void);.
28190 69 6e 74 20 73 71 6c 69 74 65 33 49 73 4d 65 6d int sqlite3IsMem
281a0 4a 6f 75 72 6e 61 6c 28 73 71 6c 69 74 65 33 5f Journal(sqlite3_
281b0 66 69 6c 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 file *);..void s
281c0 71 6c 69 74 65 33 45 78 70 72 53 65 74 48 65 69 qlite3ExprSetHei
281d0 67 68 74 41 6e 64 46 6c 61 67 73 28 50 61 72 73 ghtAndFlags(Pars
281e0 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 20 e *pParse, Expr
281f0 2a 70 29 3b 0a 23 69 66 20 53 51 4c 49 54 45 5f *p);.#if SQLITE_
28200 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 MAX_EXPR_DEPTH>0
28210 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 53 65 . int sqlite3Se
28220 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 28 53 lectExprHeight(S
28230 65 6c 65 63 74 20 2a 29 3b 0a 20 20 69 6e 74 20 elect *);. int
28240 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b sqlite3ExprCheck
28250 48 65 69 67 68 74 28 50 61 72 73 65 2a 2c 20 69 Height(Parse*, i
28260 6e 74 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 nt);.#else. #de
28270 66 69 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 fine sqlite3Sele
28280 63 74 45 78 70 72 48 65 69 67 68 74 28 78 29 20 ctExprHeight(x)
28290 30 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 0. #define sqli
282a0 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 69 67 te3ExprCheckHeig
282b0 68 74 28 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a ht(x,y).#endif..
282c0 75 33 32 20 73 71 6c 69 74 65 33 47 65 74 34 62 u32 sqlite3Get4b
282d0 79 74 65 28 63 6f 6e 73 74 20 75 38 2a 29 3b 0a yte(const u8*);.
282e0 76 6f 69 64 20 73 71 6c 69 74 65 33 50 75 74 34 void sqlite3Put4
282f0 62 79 74 65 28 75 38 2a 2c 20 75 33 32 29 3b 0a byte(u8*, u32);.
28300 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
28310 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 NABLE_UNLOCK_NOT
28320 49 46 59 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 IFY. void sqlit
28330 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 e3ConnectionBloc
28340 6b 65 64 28 73 71 6c 69 74 65 33 20 2a 2c 20 73 ked(sqlite3 *, s
28350 71 6c 69 74 65 33 20 2a 29 3b 0a 20 20 76 6f 69 qlite3 *);. voi
28360 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 d sqlite3Connect
28370 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 73 71 6c 69 ionUnlocked(sqli
28380 74 65 33 20 2a 64 62 29 3b 0a 20 20 76 6f 69 64 te3 *db);. void
28390 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 sqlite3Connecti
283a0 6f 6e 43 6c 6f 73 65 64 28 73 71 6c 69 74 65 33 onClosed(sqlite3
283b0 20 2a 64 62 29 3b 0a 23 65 6c 73 65 0a 20 20 23 *db);.#else. #
283c0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f define sqlite3Co
283d0 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 64 28 nnectionBlocked(
283e0 78 2c 79 29 0a 20 20 23 64 65 66 69 6e 65 20 73 x,y). #define s
283f0 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
28400 55 6e 6c 6f 63 6b 65 64 28 78 29 0a 20 20 23 64 Unlocked(x). #d
28410 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e efine sqlite3Con
28420 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 78 29 nectionClosed(x)
28430 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
28440 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 20 76 SQLITE_DEBUG. v
28450 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 oid sqlite3Parse
28460 72 54 72 61 63 65 28 46 49 4c 45 2a 2c 20 63 68 rTrace(FILE*, ch
28470 61 72 20 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f ar *);.#endif../
28480 2a 0a 2a 2a 20 49 66 20 74 68 65 20 53 51 4c 49 *.** If the SQLI
28490 54 45 5f 45 4e 41 42 4c 45 20 49 4f 54 52 41 43 TE_ENABLE IOTRAC
284a0 45 20 65 78 69 73 74 73 20 74 68 65 6e 20 74 68 E exists then th
284b0 65 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c e global variabl
284c0 65 0a 2a 2a 20 73 71 6c 69 74 65 33 49 6f 54 72 e.** sqlite3IoTr
284d0 61 63 65 20 69 73 20 61 20 70 6f 69 6e 74 65 72 ace is a pointer
284e0 20 74 6f 20 61 20 70 72 69 6e 74 66 2d 6c 69 6b to a printf-lik
284f0 65 20 72 6f 75 74 69 6e 65 20 75 73 65 64 20 74 e routine used t
28500 6f 0a 2a 2a 20 70 72 69 6e 74 20 49 2f 4f 20 74 o.** print I/O t
28510 72 61 63 69 6e 67 20 6d 65 73 73 61 67 65 73 2e racing messages.
28520 20 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 .*/.#ifdef SQLI
28530 54 45 5f 45 4e 41 42 4c 45 5f 49 4f 54 52 41 43 TE_ENABLE_IOTRAC
28540 45 0a 23 20 64 65 66 69 6e 65 20 49 4f 54 52 41 E.# define IOTRA
28550 43 45 28 41 29 20 20 69 66 28 20 73 71 6c 69 74 CE(A) if( sqlit
28560 65 33 49 6f 54 72 61 63 65 20 29 7b 20 73 71 6c e3IoTrace ){ sql
28570 69 74 65 33 49 6f 54 72 61 63 65 20 41 3b 20 7d ite3IoTrace A; }
28580 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 . void sqlite3V
28590 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 56 64 dbeIOTraceSql(Vd
285a0 62 65 2a 29 3b 0a 53 51 4c 49 54 45 5f 41 50 49 be*);.SQLITE_API
285b0 20 53 51 4c 49 54 45 5f 45 58 54 45 52 4e 20 76 SQLITE_EXTERN v
285c0 6f 69 64 20 28 53 51 4c 49 54 45 5f 43 44 45 43 oid (SQLITE_CDEC
285d0 4c 20 2a 73 71 6c 69 74 65 33 49 6f 54 72 61 63 L *sqlite3IoTrac
285e0 65 29 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e e)(const char*,.
285f0 2e 2e 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 ..);.#else.# def
28600 69 6e 65 20 49 4f 54 52 41 43 45 28 41 29 0a 23 ine IOTRACE(A).#
28610 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
28620 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 58 29 dbeIOTraceSql(X)
28630 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
28640 68 65 73 65 20 72 6f 75 74 69 6e 65 73 20 61 72 hese routines ar
28650 65 20 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 e available for
28660 74 68 65 20 6d 65 6d 32 2e 63 20 64 65 62 75 67 the mem2.c debug
28670 67 69 6e 67 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f ging memory allo
28680 63 61 74 6f 72 0a 2a 2a 20 6f 6e 6c 79 2e 20 20 cator.** only.
28690 54 68 65 79 20 61 72 65 20 75 73 65 64 20 74 6f They are used to
286a0 20 76 65 72 69 66 79 20 74 68 61 74 20 64 69 66 verify that dif
286b0 66 65 72 65 6e 74 20 22 74 79 70 65 73 22 20 6f ferent "types" o
286c0 66 20 6d 65 6d 6f 72 79 0a 2a 2a 20 61 6c 6c 6f f memory.** allo
286d0 63 61 74 69 6f 6e 73 20 61 72 65 20 70 72 6f 70 cations are prop
286e0 65 72 6c 79 20 74 72 61 63 6b 65 64 20 62 79 20 erly tracked by
286f0 74 68 65 20 73 79 73 74 65 6d 2e 0a 2a 2a 0a 2a the system..**.*
28700 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 * sqlite3Memdebu
28710 67 53 65 74 54 79 70 65 28 29 20 73 65 74 73 20 gSetType() sets
28720 74 68 65 20 22 74 79 70 65 22 20 6f 66 20 61 6e the "type" of an
28730 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 74 6f 20 6f allocation to o
28740 6e 65 20 6f 66 0a 2a 2a 20 74 68 65 20 4d 45 4d ne of.** the MEM
28750 54 59 50 45 5f 2a 20 6d 61 63 72 6f 73 20 64 65 TYPE_* macros de
28760 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 20 54 68 fined below. Th
28770 65 20 74 79 70 65 20 6d 75 73 74 20 62 65 20 61 e type must be a
28780 20 62 69 74 6d 61 73 6b 20 77 69 74 68 0a 2a 2a bitmask with.**
28790 20 61 20 73 69 6e 67 6c 65 20 62 69 74 20 73 65 a single bit se
287a0 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 t..**.** sqlite3
287b0 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 MemdebugHasType(
287c0 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 69 ) returns true i
287d0 66 20 61 6e 79 20 6f 66 20 74 68 65 20 62 69 74 f any of the bit
287e0 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e 64 0a s in its second.
287f0 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 74 63 ** argument matc
28800 68 20 74 68 65 20 74 79 70 65 20 73 65 74 20 62 h the type set b
28810 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 73 y the previous s
28820 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 qlite3MemdebugSe
28830 74 54 79 70 65 28 29 2e 0a 2a 2a 20 73 71 6c 69 tType()..** sqli
28840 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 te3MemdebugHasTy
28850 70 65 28 29 20 69 73 20 69 6e 74 65 6e 64 65 64 pe() is intended
28860 20 66 6f 72 20 75 73 65 20 69 6e 73 69 64 65 20 for use inside
28870 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
28880 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 nts..**.** sqlit
28890 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 e3MemdebugNoType
288a0 28 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 () returns true
288b0 69 66 20 6e 6f 6e 65 20 6f 66 20 74 68 65 20 62 if none of the b
288c0 69 74 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e its in its secon
288d0 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 d.** argument ma
288e0 74 63 68 20 74 68 65 20 74 79 70 65 20 73 65 74 tch the type set
288f0 20 62 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 by the previous
28900 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
28910 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a 0a 2a 2a SetType()..**.**
28920 20 50 65 72 68 61 70 73 20 74 68 65 20 6d 6f 73 Perhaps the mos
28930 74 20 69 6d 70 6f 72 74 61 6e 74 20 70 6f 69 6e t important poin
28940 74 20 69 73 20 74 68 65 20 64 69 66 66 65 72 65 t is the differe
28950 6e 63 65 20 62 65 74 77 65 65 6e 20 4d 45 4d 54 nce between MEMT
28960 59 50 45 5f 48 45 41 50 0a 2a 2a 20 61 6e 64 20 YPE_HEAP.** and
28970 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 MEMTYPE_LOOKASID
28980 45 2e 20 20 49 66 20 61 6e 20 61 6c 6c 6f 63 61 E. If an alloca
28990 74 69 6f 6e 20 69 73 20 4d 45 4d 54 59 50 45 5f tion is MEMTYPE_
289a0 4c 4f 4f 4b 41 53 49 44 45 2c 20 74 68 61 74 20 LOOKASIDE, that
289b0 6d 65 61 6e 73 0a 2a 2a 20 69 74 20 6d 69 67 68 means.** it migh
289c0 74 20 68 61 76 65 20 62 65 65 6e 20 61 6c 6c 6f t have been allo
289d0 63 61 74 65 64 20 62 79 20 6c 6f 6f 6b 61 73 69 cated by lookasi
289e0 64 65 2c 20 65 78 63 65 70 74 20 74 68 65 20 61 de, except the a
289f0 6c 6c 6f 63 61 74 69 6f 6e 20 77 61 73 0a 2a 2a llocation was.**
28a00 20 74 6f 6f 20 6c 61 72 67 65 20 6f 72 20 6c 6f too large or lo
28a10 6f 6b 61 73 69 64 65 20 77 61 73 20 61 6c 72 65 okaside was alre
28a20 61 64 79 20 66 75 6c 6c 2e 20 20 49 74 20 69 73 ady full. It is
28a30 20 69 6d 70 6f 72 74 61 6e 74 20 74 6f 20 76 65 important to ve
28a40 72 69 66 79 0a 2a 2a 20 74 68 61 74 20 61 6c 6c rify.** that all
28a50 6f 63 61 74 69 6f 6e 73 20 74 68 61 74 20 6d 69 ocations that mi
28a60 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 73 61 ght have been sa
28a70 74 69 73 66 69 65 64 20 62 79 20 6c 6f 6f 6b 61 tisfied by looka
28a80 73 69 64 65 20 61 72 65 20 6e 6f 74 0a 2a 2a 20 side are not.**
28a90 70 61 73 73 65 64 20 62 61 63 6b 20 74 6f 20 6e passed back to n
28aa0 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 66 72 65 on-lookaside fre
28ab0 65 28 29 20 72 6f 75 74 69 6e 65 73 2e 20 20 41 e() routines. A
28ac0 73 73 65 72 74 73 20 73 75 63 68 20 61 73 20 74 sserts such as t
28ad0 68 65 0a 2a 2a 20 65 78 61 6d 70 6c 65 20 61 62 he.** example ab
28ae0 6f 76 65 20 61 72 65 20 70 6c 61 63 65 64 20 6f ove are placed o
28af0 6e 20 74 68 65 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 n the non-lookas
28b00 69 64 65 20 66 72 65 65 28 29 20 72 6f 75 74 69 ide free() routi
28b10 6e 65 73 20 74 6f 20 76 65 72 69 66 79 0a 2a 2a nes to verify.**
28b20 20 74 68 69 73 20 63 6f 6e 73 74 72 61 69 6e 74 this constraint
28b30 2e 20 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 . .**.** All of
28b40 74 68 69 73 20 69 73 20 6e 6f 2d 6f 70 20 66 6f this is no-op fo
28b50 72 20 61 20 70 72 6f 64 75 63 74 69 6f 6e 20 62 r a production b
28b60 75 69 6c 64 2e 20 20 49 74 20 6f 6e 6c 79 20 63 uild. It only c
28b70 6f 6d 65 73 20 69 6e 74 6f 0a 2a 2a 20 70 6c 61 omes into.** pla
28b80 79 20 77 68 65 6e 20 74 68 65 20 53 51 4c 49 54 y when the SQLIT
28b90 45 5f 4d 45 4d 44 45 42 55 47 20 63 6f 6d 70 69 E_MEMDEBUG compi
28ba0 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e 20 69 le-time option i
28bb0 73 20 75 73 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 s used..*/.#ifde
28bc0 66 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 f SQLITE_MEMDEBU
28bd0 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 G. void sqlite3
28be0 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
28bf0 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 void*,u8);. int
28c00 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
28c10 48 61 73 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 HasType(void*,u8
28c20 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
28c30 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 28 76 MemdebugNoType(v
28c40 6f 69 64 2a 2c 75 38 29 3b 0a 23 65 6c 73 65 0a oid*,u8);.#else.
28c50 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
28c60 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
28c70 58 2c 59 29 20 20 2f 2a 20 6e 6f 2d 6f 70 20 2a X,Y) /* no-op *
28c80 2f 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 /.# define sqlit
28c90 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 e3MemdebugHasTyp
28ca0 65 28 58 2c 59 29 20 20 31 0a 23 20 64 65 66 69 e(X,Y) 1.# defi
28cb0 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ne sqlite3Memdeb
28cc0 75 67 4e 6f 54 79 70 65 28 58 2c 59 29 20 20 20 ugNoType(X,Y)
28cd0 31 0a 23 65 6e 64 69 66 0a 23 64 65 66 69 6e 65 1.#endif.#define
28ce0 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 20 20 20 MEMTYPE_HEAP
28cf0 20 20 20 20 30 78 30 31 20 20 2f 2a 20 47 65 6e 0x01 /* Gen
28d00 65 72 61 6c 20 68 65 61 70 20 61 6c 6c 6f 63 61 eral heap alloca
28d10 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 tions */.#define
28d20 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 MEMTYPE_LOOKASI
28d30 44 45 20 20 30 78 30 32 20 20 2f 2a 20 48 65 61 DE 0x02 /* Hea
28d40 70 20 74 68 61 74 20 6d 69 67 68 74 20 68 61 76 p that might hav
28d50 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 69 64 65 e been lookaside
28d60 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 */.#define MEMT
28d70 59 50 45 5f 53 43 52 41 54 43 48 20 20 20 20 30 YPE_SCRATCH 0
28d80 78 30 34 20 20 2f 2a 20 53 63 72 61 74 63 68 20 x04 /* Scratch
28d90 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 allocations */.#
28da0 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 5f 50 define MEMTYPE_P
28db0 43 41 43 48 45 20 20 20 20 20 30 78 30 38 20 20 CACHE 0x08
28dc0 2f 2a 20 50 61 67 65 20 63 61 63 68 65 20 61 6c /* Page cache al
28dd0 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a locations */../*
28de0 0a 2a 2a 20 54 68 72 65 61 64 69 6e 67 20 69 6e .** Threading in
28df0 74 65 72 66 61 63 65 0a 2a 2f 0a 23 69 66 20 53 terface.*/.#if S
28e00 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
28e10 5f 54 48 52 45 41 44 53 3e 30 0a 69 6e 74 20 73 _THREADS>0.int s
28e20 71 6c 69 74 65 33 54 68 72 65 61 64 43 72 65 61 qlite3ThreadCrea
28e30 74 65 28 53 51 4c 69 74 65 54 68 72 65 61 64 2a te(SQLiteThread*
28e40 2a 2c 76 6f 69 64 2a 28 2a 29 28 76 6f 69 64 2a *,void*(*)(void*
28e50 29 2c 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 ),void*);.int sq
28e60 6c 69 74 65 33 54 68 72 65 61 64 4a 6f 69 6e 28 lite3ThreadJoin(
28e70 53 51 4c 69 74 65 54 68 72 65 61 64 2a 2c 20 76 SQLiteThread*, v
28e80 6f 69 64 2a 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a oid**);.#endif..
28e90 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
28ea0 54 45 5f 45 4e 41 42 4c 45 5f 44 42 53 54 41 54 TE_ENABLE_DBSTAT
28eb0 5f 56 54 41 42 29 20 7c 7c 20 64 65 66 69 6e 65 _VTAB) || define
28ec0 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a 69 d(SQLITE_TEST).i
28ed0 6e 74 20 73 71 6c 69 74 65 33 44 62 73 74 61 74 nt sqlite3Dbstat
28ee0 52 65 67 69 73 74 65 72 28 73 71 6c 69 74 65 33 Register(sqlite3
28ef0 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 65 6e 64 *);.#endif..#end
28f00 69 66 20 2f 2a 20 5f 53 51 4c 49 54 45 49 4e 54 if /* _SQLITEINT
28f10 5f 48 5f 20 2a 2f 0a _H_ */.