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 53 51 4c 49 54 45 49 4e 54 5f 48 0a 23 ef SQLITEINT_H.#
01c0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 49 4e 54 define SQLITEINT
01d0: 5f 48 0a 0a 2f 2a 20 53 70 65 63 69 61 6c 20 43 _H../* Special C
01e0: 6f 6d 6d 65 6e 74 73 3a 0a 2a 2a 0a 2a 2a 20 53 omments:.**.** S
01f0: 6f 6d 65 20 63 6f 6d 6d 65 6e 74 73 20 68 61 76 ome comments hav
0200: 65 20 73 70 65 63 69 61 6c 20 6d 65 61 6e 69 6e e special meanin
0210: 67 20 74 6f 20 74 68 65 20 74 6f 6f 6c 73 20 74 g to the tools t
0220: 68 61 74 20 6d 65 61 73 75 72 65 20 74 65 73 74 hat measure test
0230: 0a 2a 2a 20 63 6f 76 65 72 61 67 65 3a 0a 2a 2a .** coverage:.**
0240: 0a 2a 2a 20 20 20 20 4e 4f 5f 54 45 53 54 20 20 .** NO_TEST
0250: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0260: 20 20 20 2d 20 54 68 65 20 62 72 61 6e 63 68 65 - The branche
0270: 73 20 6f 6e 20 74 68 69 73 20 6c 69 6e 65 20 61 s on this line a
0280: 72 65 20 6e 6f 74 0a 2a 2a 20 20 20 20 20 20 20 re not.**
0290: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
02a0: 20 20 20 20 20 20 20 20 20 20 20 6d 65 61 73 75 measu
02b0: 72 65 64 20 62 79 20 62 72 61 6e 63 68 20 63 6f red by branch co
02c0: 76 65 72 61 67 65 2e 20 20 54 68 69 73 20 69 73 verage. This is
02d0: 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
02e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
02f0: 20 20 20 20 20 75 73 65 64 20 6f 6e 20 6c 69 6e used on lin
0300: 65 73 20 6f 66 20 63 6f 64 65 20 74 68 61 74 20 es of code that
0310: 61 63 74 75 61 6c 6c 79 0a 2a 2a 20 20 20 20 20 actually.**
0320: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0330: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6d 70 imp
0340: 6c 65 6d 65 6e 74 20 70 61 72 74 73 20 6f 66 20 lement parts of
0350: 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 6e 67 coverage testing
0360: 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 4f 50 54 49 4d ..**.** OPTIM
0370: 49 5a 41 54 49 4f 4e 2d 49 46 2d 54 52 55 45 20 IZATION-IF-TRUE
0380: 20 20 20 20 20 20 20 2d 20 54 68 69 73 20 62 72 - This br
0390: 61 6e 63 68 20 69 73 20 61 6c 6c 6f 77 65 64 20 anch is allowed
03a0: 74 6f 20 61 6c 77 61 79 20 62 65 20 66 61 6c 73 to alway be fals
03b0: 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 e.**
03c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
03d0: 20 20 20 20 20 20 61 6e 64 20 74 68 65 20 63 6f and the co
03e0: 72 72 65 63 74 20 61 6e 73 77 65 72 20 69 73 20 rrect answer is
03f0: 73 74 69 6c 6c 20 6f 62 74 61 69 6e 65 64 2c 0a still obtained,.
0400: 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
0410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0420: 20 20 20 20 74 68 6f 75 67 68 20 70 65 72 68 61 though perha
0430: 70 73 20 6d 6f 72 65 20 73 6c 6f 77 6c 79 2e 0a ps more slowly..
0440: 2a 2a 0a 2a 2a 20 20 20 20 4f 50 54 49 4d 49 5a **.** OPTIMIZ
0450: 41 54 49 4f 4e 2d 49 46 2d 46 41 4c 53 45 20 20 ATION-IF-FALSE
0460: 20 20 20 20 20 2d 20 54 68 69 73 20 62 72 61 6e - This bran
0470: 63 68 20 69 73 20 61 6c 6c 6f 77 65 64 20 74 6f ch is allowed to
0480: 20 61 6c 77 61 79 20 62 65 20 74 72 75 65 0a 2a alway be true.*
0490: 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
04a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
04b0: 20 20 20 61 6e 64 20 74 68 65 20 63 6f 72 72 65 and the corre
04c0: 63 74 20 61 6e 73 77 65 72 20 69 73 20 73 74 69 ct answer is sti
04d0: 6c 6c 20 6f 62 74 61 69 6e 65 64 2c 0a 2a 2a 20 ll obtained,.**
04e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
04f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0500: 20 74 68 6f 75 67 68 20 70 65 72 68 61 70 73 20 though perhaps
0510: 6d 6f 72 65 20 73 6c 6f 77 6c 79 2e 0a 2a 2a 0a more slowly..**.
0520: 2a 2a 20 20 20 20 50 52 45 56 45 4e 54 53 2d 48 ** PREVENTS-H
0530: 41 52 4d 4c 45 53 53 2d 4f 56 45 52 52 45 41 44 ARMLESS-OVERREAD
0540: 20 20 2d 20 54 68 69 73 20 62 72 61 6e 63 68 20 - This branch
0550: 70 72 65 76 65 6e 74 73 20 61 20 62 75 66 66 65 prevents a buffe
0560: 72 20 6f 76 65 72 72 65 61 64 0a 2a 2a 20 20 20 r overread.**
0570: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
0580: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
0590: 68 61 74 20 77 6f 75 6c 64 20 62 65 20 68 61 72 hat would be har
05a0: 6d 6c 65 73 73 20 61 6e 64 20 75 6e 64 65 74 65 mless and undete
05b0: 63 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 20 ctable.**
05c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
05d0: 20 20 20 20 20 20 20 20 20 20 20 69 66 20 69 74 if it
05e0: 20 64 69 64 20 6f 63 63 75 72 2e 20 20 0a 2a 2a did occur. .**
05f0: 0a 2a 2a 20 49 6e 20 61 6c 6c 20 63 61 73 65 73 .** In all cases
0600: 2c 20 74 68 65 20 73 70 65 63 69 61 6c 20 63 6f , the special co
0610: 6d 6d 65 6e 74 20 6d 75 73 74 20 62 65 20 65 6e mment must be en
0620: 63 6c 6f 73 65 64 20 69 6e 20 74 68 65 20 75 73 closed in the us
0630: 75 61 6c 0a 2a 2a 20 73 6c 61 73 68 2d 61 73 74 ual.** slash-ast
0640: 65 72 69 73 6b 2e 2e 2e 61 73 74 65 72 69 73 6b erisk...asterisk
0650: 2d 73 6c 61 73 68 20 63 6f 6d 6d 65 6e 74 20 6d -slash comment m
0660: 61 72 6b 73 2c 20 77 69 74 68 20 6e 6f 20 73 70 arks, with no sp
0670: 61 63 65 73 20 62 65 74 77 65 65 6e 20 74 68 65 aces between the
0680: 20 0a 2a 2a 20 61 73 74 65 72 69 73 6b 73 20 61 .** asterisks a
0690: 6e 64 20 74 68 65 20 63 6f 6d 6d 65 6e 74 20 74 nd the comment t
06a0: 65 78 74 2e 0a 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 4d ext..*/../*.** M
06b0: 61 6b 65 20 73 75 72 65 20 74 68 65 20 54 63 6c ake sure the Tcl
06c0: 20 63 61 6c 6c 69 6e 67 20 63 6f 6e 76 65 6e 74 calling convent
06d0: 69 6f 6e 20 6d 61 63 72 6f 20 69 73 20 64 65 66 ion macro is def
06e0: 69 6e 65 64 2e 20 20 54 68 69 73 20 6d 61 63 72 ined. This macr
06f0: 6f 20 69 73 0a 2a 2a 20 6f 6e 6c 79 20 75 73 65 o is.** only use
0700: 64 20 62 79 20 74 65 73 74 20 63 6f 64 65 20 61 d by test code a
0710: 6e 64 20 54 63 6c 20 69 6e 74 65 67 72 61 74 69 nd Tcl integrati
0720: 6f 6e 20 63 6f 64 65 2e 0a 2a 2f 0a 23 69 66 6e on code..*/.#ifn
0730: 64 65 66 20 53 51 4c 49 54 45 5f 54 43 4c 41 50 def SQLITE_TCLAP
0740: 49 0a 23 20 20 64 65 66 69 6e 65 20 53 51 4c 49 I.# define SQLI
0750: 54 45 5f 54 43 4c 41 50 49 0a 23 65 6e 64 69 66 TE_TCLAPI.#endif
0760: 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 ../*.** Include
0770: 74 68 65 20 68 65 61 64 65 72 20 66 69 6c 65 20 the header file
0780: 75 73 65 64 20 74 6f 20 63 75 73 74 6f 6d 69 7a used to customiz
0790: 65 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 6f e the compiler o
07a0: 70 74 69 6f 6e 73 20 66 6f 72 20 4d 53 56 43 2e ptions for MSVC.
07b0: 0a 2a 2a 20 54 68 69 73 20 73 68 6f 75 6c 64 20 .** This should
07c0: 62 65 20 64 6f 6e 65 20 66 69 72 73 74 20 73 6f be done first so
07d0: 20 74 68 61 74 20 69 74 20 63 61 6e 20 73 75 63 that it can suc
07e0: 63 65 73 73 66 75 6c 6c 79 20 70 72 65 76 65 6e cessfully preven
07f0: 74 20 73 70 75 72 69 6f 75 73 0a 2a 2a 20 63 6f t spurious.** co
0800: 6d 70 69 6c 65 72 20 77 61 72 6e 69 6e 67 73 20 mpiler warnings
0810: 64 75 65 20 74 6f 20 73 75 62 73 65 71 75 65 6e due to subsequen
0820: 74 20 63 6f 6e 74 65 6e 74 20 69 6e 20 74 68 69 t content in thi
0830: 73 20 66 69 6c 65 20 61 6e 64 20 6f 74 68 65 72 s file and other
0840: 20 66 69 6c 65 73 0a 2a 2a 20 74 68 61 74 20 61 files.** that a
0850: 72 65 20 69 6e 63 6c 75 64 65 64 20 62 79 20 74 re included by t
0860: 68 69 73 20 66 69 6c 65 2e 0a 2a 2f 0a 23 69 6e his file..*/.#in
0870: 63 6c 75 64 65 20 22 6d 73 76 63 2e 68 22 0a 0a clude "msvc.h"..
0880: 2f 2a 0a 2a 2a 20 53 70 65 63 69 61 6c 20 73 65 /*.** Special se
0890: 74 75 70 20 66 6f 72 20 56 78 57 6f 72 6b 73 0a tup for VxWorks.
08a0: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 76 78 77 */.#include "vxw
08b0: 6f 72 6b 73 2e 68 22 0a 0a 2f 2a 0a 2a 2a 20 54 orks.h"../*.** T
08c0: 68 65 73 65 20 23 64 65 66 69 6e 65 73 20 73 68 hese #defines sh
08d0: 6f 75 6c 64 20 65 6e 61 62 6c 65 20 3e 32 47 42 ould enable >2GB
08e0: 20 66 69 6c 65 20 73 75 70 70 6f 72 74 20 6f 6e file support on
08f0: 20 50 4f 53 49 58 20 69 66 20 74 68 65 0a 2a 2a POSIX if the.**
0900: 20 75 6e 64 65 72 6c 79 69 6e 67 20 6f 70 65 72 underlying oper
0910: 61 74 69 6e 67 20 73 79 73 74 65 6d 20 73 75 70 ating system sup
0920: 70 6f 72 74 73 20 69 74 2e 20 20 49 66 20 74 68 ports it. If th
0930: 65 20 4f 53 20 6c 61 63 6b 73 0a 2a 2a 20 6c 61 e OS lacks.** la
0940: 72 67 65 20 66 69 6c 65 20 73 75 70 70 6f 72 74 rge file support
0950: 2c 20 6f 72 20 69 66 20 74 68 65 20 4f 53 20 69 , or if the OS i
0960: 73 20 77 69 6e 64 6f 77 73 2c 20 74 68 65 73 65 s windows, these
0970: 20 73 68 6f 75 6c 64 20 62 65 20 6e 6f 2d 6f 70 should be no-op
0980: 73 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 20 s..**.** Ticket
0990: 23 32 37 33 39 3a 20 20 54 68 65 20 5f 4c 41 52 #2739: The _LAR
09a0: 47 45 46 49 4c 45 5f 53 4f 55 52 43 45 20 6d 61 GEFILE_SOURCE ma
09b0: 63 72 6f 20 6d 75 73 74 20 61 70 70 65 61 72 20 cro must appear
09c0: 62 65 66 6f 72 65 20 61 6e 79 0a 2a 2a 20 73 79 before any.** sy
09d0: 73 74 65 6d 20 23 69 6e 63 6c 75 64 65 73 2e 20 stem #includes.
09e0: 20 48 65 6e 63 65 2c 20 74 68 69 73 20 62 6c 6f Hence, this blo
09f0: 63 6b 20 6f 66 20 63 6f 64 65 20 6d 75 73 74 20 ck of code must
0a00: 62 65 20 74 68 65 20 76 65 72 79 20 66 69 72 73 be the very firs
0a10: 74 0a 2a 2a 20 63 6f 64 65 20 69 6e 20 61 6c 6c t.** code in all
0a20: 20 73 6f 75 72 63 65 20 66 69 6c 65 73 2e 0a 2a source files..*
0a30: 2a 0a 2a 2a 20 4c 61 72 67 65 20 66 69 6c 65 20 *.** Large file
0a40: 73 75 70 70 6f 72 74 20 63 61 6e 20 62 65 20 64 support can be d
0a50: 69 73 61 62 6c 65 64 20 75 73 69 6e 67 20 74 68 isabled using th
0a60: 65 20 2d 44 53 51 4c 49 54 45 5f 44 49 53 41 42 e -DSQLITE_DISAB
0a70: 4c 45 5f 4c 46 53 20 73 77 69 74 63 68 0a 2a 2a LE_LFS switch.**
0a80: 20 6f 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 on the compiler
0a90: 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 20 command line.
0aa0: 54 68 69 73 20 69 73 20 6e 65 63 65 73 73 61 72 This is necessar
0ab0: 79 20 69 66 20 79 6f 75 20 61 72 65 20 63 6f 6d y if you are com
0ac0: 70 69 6c 69 6e 67 0a 2a 2a 20 6f 6e 20 61 20 72 piling.** on a r
0ad0: 65 63 65 6e 74 20 6d 61 63 68 69 6e 65 20 28 65 ecent machine (e
0ae0: 78 3a 20 52 65 64 20 48 61 74 20 37 2e 32 29 20 x: Red Hat 7.2)
0af0: 62 75 74 20 79 6f 75 20 77 61 6e 74 20 79 6f 75 but you want you
0b00: 72 20 63 6f 64 65 20 74 6f 20 77 6f 72 6b 0a 2a r code to work.*
0b10: 2a 20 6f 6e 20 61 6e 20 6f 6c 64 65 72 20 6d 61 * on an older ma
0b20: 63 68 69 6e 65 20 28 65 78 3a 20 52 65 64 20 48 chine (ex: Red H
0b30: 61 74 20 36 2e 30 29 2e 20 20 49 66 20 79 6f 75 at 6.0). If you
0b40: 20 63 6f 6d 70 69 6c 65 20 6f 6e 20 52 65 64 20 compile on Red
0b50: 48 61 74 20 37 2e 32 0a 2a 2a 20 77 69 74 68 6f Hat 7.2.** witho
0b60: 75 74 20 74 68 69 73 20 6f 70 74 69 6f 6e 2c 20 ut this option,
0b70: 4c 46 53 20 69 73 20 65 6e 61 62 6c 65 2e 20 20 LFS is enable.
0b80: 42 75 74 20 4c 46 53 20 64 6f 65 73 20 6e 6f 74 But LFS does not
0b90: 20 65 78 69 73 74 20 69 6e 20 74 68 65 20 6b 65 exist in the ke
0ba0: 72 6e 65 6c 0a 2a 2a 20 69 6e 20 52 65 64 20 48 rnel.** in Red H
0bb0: 61 74 20 36 2e 30 2c 20 73 6f 20 74 68 65 20 63 at 6.0, so the c
0bc0: 6f 64 65 20 77 6f 6e 27 74 20 77 6f 72 6b 2e 20 ode won't work.
0bd0: 20 48 65 6e 63 65 2c 20 66 6f 72 20 6d 61 78 69 Hence, for maxi
0be0: 6d 75 6d 20 62 69 6e 61 72 79 0a 2a 2a 20 70 6f mum binary.** po
0bf0: 72 74 61 62 69 6c 69 74 79 20 79 6f 75 20 73 68 rtability you sh
0c00: 6f 75 6c 64 20 6f 6d 69 74 20 4c 46 53 2e 0a 2a ould omit LFS..*
0c10: 2a 0a 2a 2a 20 54 68 65 20 70 72 65 76 69 6f 75 *.** The previou
0c20: 73 20 70 61 72 61 67 72 61 70 68 20 77 61 73 20 s paragraph was
0c30: 77 72 69 74 74 65 6e 20 69 6e 20 32 30 30 35 2e written in 2005.
0c40: 20 20 28 54 68 69 73 20 70 61 72 61 67 72 61 70 (This paragrap
0c50: 68 20 69 73 20 77 72 69 74 74 65 6e 0a 2a 2a 20 h is written.**
0c60: 6f 6e 20 32 30 30 38 2d 31 31 2d 32 38 2e 29 20 on 2008-11-28.)
0c70: 54 68 65 73 65 20 64 61 79 73 2c 20 61 6c 6c 20 These days, all
0c80: 4c 69 6e 75 78 20 6b 65 72 6e 65 6c 73 20 73 75 Linux kernels su
0c90: 70 70 6f 72 74 20 6c 61 72 67 65 20 66 69 6c 65 pport large file
0ca0: 73 2c 20 73 6f 0a 2a 2a 20 79 6f 75 20 73 68 6f s, so.** you sho
0cb0: 75 6c 64 20 70 72 6f 62 61 62 6c 79 20 6c 65 61 uld probably lea
0cc0: 76 65 20 4c 46 53 20 65 6e 61 62 6c 65 64 2e 20 ve LFS enabled.
0cd0: 20 42 75 74 20 73 6f 6d 65 20 65 6d 62 65 64 64 But some embedd
0ce0: 65 64 20 70 6c 61 74 66 6f 72 6d 73 20 6d 69 67 ed platforms mig
0cf0: 68 74 0a 2a 2a 20 6c 61 63 6b 20 4c 46 53 20 69 ht.** lack LFS i
0d00: 6e 20 77 68 69 63 68 20 63 61 73 65 20 74 68 65 n which case the
0d10: 20 53 51 4c 49 54 45 5f 44 49 53 41 42 4c 45 5f SQLITE_DISABLE_
0d20: 4c 46 53 20 6d 61 63 72 6f 20 6d 69 67 68 74 20 LFS macro might
0d30: 73 74 69 6c 6c 20 62 65 20 75 73 65 66 75 6c 2e still be useful.
0d40: 0a 2a 2a 0a 2a 2a 20 53 69 6d 69 6c 61 72 20 69 .**.** Similar i
0d50: 73 20 74 72 75 65 20 66 6f 72 20 4d 61 63 20 4f s true for Mac O
0d60: 53 20 58 2e 20 20 4c 46 53 20 69 73 20 6f 6e 6c S X. LFS is onl
0d70: 79 20 73 75 70 70 6f 72 74 65 64 20 6f 6e 20 4d y supported on M
0d80: 61 63 20 4f 53 20 58 20 39 20 61 6e 64 20 6c 61 ac OS X 9 and la
0d90: 74 65 72 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 ter..*/.#ifndef
0da0: 53 51 4c 49 54 45 5f 44 49 53 41 42 4c 45 5f 4c SQLITE_DISABLE_L
0db0: 46 53 0a 23 20 64 65 66 69 6e 65 20 5f 4c 41 52 FS.# define _LAR
0dc0: 47 45 5f 46 49 4c 45 20 20 20 20 20 20 20 31 0a GE_FILE 1.
0dd0: 23 20 69 66 6e 64 65 66 20 5f 46 49 4c 45 5f 4f # ifndef _FILE_O
0de0: 46 46 53 45 54 5f 42 49 54 53 0a 23 20 20 20 64 FFSET_BITS.# d
0df0: 65 66 69 6e 65 20 5f 46 49 4c 45 5f 4f 46 46 53 efine _FILE_OFFS
0e00: 45 54 5f 42 49 54 53 20 36 34 0a 23 20 65 6e 64 ET_BITS 64.# end
0e10: 69 66 0a 23 20 64 65 66 69 6e 65 20 5f 4c 41 52 if.# define _LAR
0e20: 47 45 46 49 4c 45 5f 53 4f 55 52 43 45 20 31 0a GEFILE_SOURCE 1.
0e30: 23 65 6e 64 69 66 0a 0a 2f 2a 20 54 68 65 20 47 #endif../* The G
0e40: 43 43 5f 56 45 52 53 49 4f 4e 20 61 6e 64 20 4d CC_VERSION and M
0e50: 53 56 43 5f 56 45 52 53 49 4f 4e 20 6d 61 63 72 SVC_VERSION macr
0e60: 6f 73 20 61 72 65 20 75 73 65 64 20 74 6f 0a 2a os are used to.*
0e70: 2a 20 63 6f 6e 64 69 74 69 6f 6e 61 6c 6c 79 20 * conditionally
0e80: 69 6e 63 6c 75 64 65 20 6f 70 74 69 6d 69 7a 61 include optimiza
0e90: 74 69 6f 6e 73 20 66 6f 72 20 65 61 63 68 20 6f tions for each o
0ea0: 66 20 74 68 65 73 65 20 63 6f 6d 70 69 6c 65 72 f these compiler
0eb0: 73 2e 20 20 41 0a 2a 2a 20 76 61 6c 75 65 20 6f s. A.** value o
0ec0: 66 20 30 20 6d 65 61 6e 73 20 74 68 61 74 20 63 f 0 means that c
0ed0: 6f 6d 70 69 6c 65 72 20 69 73 20 6e 6f 74 20 62 ompiler is not b
0ee0: 65 69 6e 67 20 75 73 65 64 2e 20 20 54 68 65 0a eing used. The.
0ef0: 2a 2a 20 53 51 4c 49 54 45 5f 44 49 53 41 42 4c ** SQLITE_DISABL
0f00: 45 5f 49 4e 54 52 49 4e 53 49 43 20 6d 61 63 72 E_INTRINSIC macr
0f10: 6f 20 6d 65 61 6e 73 20 64 6f 20 6e 6f 74 20 75 o means do not u
0f20: 73 65 20 61 6e 79 20 63 6f 6d 70 69 6c 65 72 2d se any compiler-
0f30: 73 70 65 63 69 66 69 63 0a 2a 2a 20 6f 70 74 69 specific.** opti
0f40: 6d 69 7a 61 74 69 6f 6e 73 2c 20 61 6e 64 20 68 mizations, and h
0f50: 65 6e 63 65 20 73 65 74 20 61 6c 6c 20 63 6f 6d ence set all com
0f60: 70 69 6c 65 72 20 6d 61 63 72 6f 73 20 74 6f 20 piler macros to
0f70: 30 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 20 77 61 0.**.** There wa
0f80: 73 20 6f 6e 63 65 20 61 6c 73 6f 20 61 20 43 4c s once also a CL
0f90: 41 4e 47 5f 56 45 52 53 49 4f 4e 20 6d 61 63 72 ANG_VERSION macr
0fa0: 6f 2e 20 20 48 6f 77 65 76 65 72 2c 20 77 65 20 o. However, we
0fb0: 6c 65 61 72 6e 20 74 68 61 74 20 74 68 65 0a 2a learn that the.*
0fc0: 2a 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 * version number
0fd0: 73 20 69 6e 20 63 6c 61 6e 67 20 61 72 65 20 66 s in clang are f
0fe0: 6f 72 20 22 6d 61 72 6b 65 74 69 6e 67 22 20 6f or "marketing" o
0ff0: 6e 6c 79 20 61 6e 64 20 61 72 65 20 69 6e 63 6f nly and are inco
1000: 6e 73 69 73 74 65 6e 74 0a 2a 2a 20 61 6e 64 20 nsistent.** and
1010: 75 6e 72 65 6c 69 61 62 6c 65 2e 20 20 46 6f 72 unreliable. For
1020: 74 75 6e 61 74 65 6c 79 2c 20 61 6c 6c 20 76 65 tunately, all ve
1030: 72 73 69 6f 6e 73 20 6f 66 20 63 6c 61 6e 67 20 rsions of clang
1040: 61 6c 73 6f 20 72 65 63 6f 67 6e 69 7a 65 20 74 also recognize t
1050: 68 65 0a 2a 2a 20 67 63 63 20 76 65 72 73 69 6f he.** gcc versio
1060: 6e 20 6e 75 6d 62 65 72 73 20 61 6e 64 20 68 61 n numbers and ha
1070: 76 65 20 72 65 61 73 6f 6e 61 62 6c 65 20 73 65 ve reasonable se
1080: 74 74 69 6e 67 73 20 66 6f 72 20 67 63 63 20 76 ttings for gcc v
1090: 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 73 2c 0a ersion numbers,.
10a0: 2a 2a 20 73 6f 20 74 68 65 20 47 43 43 5f 56 45 ** so the GCC_VE
10b0: 52 53 49 4f 4e 20 6d 61 63 72 6f 20 77 69 6c 6c RSION macro will
10c0: 20 62 65 20 73 65 74 20 74 6f 20 61 20 63 6f 72 be set to a cor
10d0: 72 65 63 74 20 6e 6f 6e 2d 7a 65 72 6f 20 76 61 rect non-zero va
10e0: 6c 75 65 20 65 76 65 6e 0a 2a 2a 20 77 68 65 6e lue even.** when
10f0: 20 63 6f 6d 70 69 6c 69 6e 67 20 77 69 74 68 20 compiling with
1100: 63 6c 61 6e 67 2e 0a 2a 2f 0a 23 69 66 20 64 65 clang..*/.#if de
1110: 66 69 6e 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 20 fined(__GNUC__)
1120: 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
1130: 54 45 5f 44 49 53 41 42 4c 45 5f 49 4e 54 52 49 TE_DISABLE_INTRI
1140: 4e 53 49 43 29 0a 23 20 64 65 66 69 6e 65 20 47 NSIC).# define G
1150: 43 43 5f 56 45 52 53 49 4f 4e 20 28 5f 5f 47 4e CC_VERSION (__GN
1160: 55 43 5f 5f 2a 31 30 30 30 30 30 30 2b 5f 5f 47 UC__*1000000+__G
1170: 4e 55 43 5f 4d 49 4e 4f 52 5f 5f 2a 31 30 30 30 NUC_MINOR__*1000
1180: 2b 5f 5f 47 4e 55 43 5f 50 41 54 43 48 4c 45 56 +__GNUC_PATCHLEV
1190: 45 4c 5f 5f 29 0a 23 65 6c 73 65 0a 23 20 64 65 EL__).#else.# de
11a0: 66 69 6e 65 20 47 43 43 5f 56 45 52 53 49 4f 4e fine GCC_VERSION
11b0: 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 0.#endif.#if de
11c0: 66 69 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 fined(_MSC_VER)
11d0: 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
11e0: 54 45 5f 44 49 53 41 42 4c 45 5f 49 4e 54 52 49 TE_DISABLE_INTRI
11f0: 4e 53 49 43 29 0a 23 20 64 65 66 69 6e 65 20 4d NSIC).# define M
1200: 53 56 43 5f 56 45 52 53 49 4f 4e 20 5f 4d 53 43 SVC_VERSION _MSC
1210: 5f 56 45 52 0a 23 65 6c 73 65 0a 23 20 64 65 66 _VER.#else.# def
1220: 69 6e 65 20 4d 53 56 43 5f 56 45 52 53 49 4f 4e ine MSVC_VERSION
1230: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 4e 65 0.#endif../* Ne
1240: 65 64 65 64 20 66 6f 72 20 76 61 72 69 6f 75 73 eded for various
1250: 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e 2e 2e 20 definitions...
1260: 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f */.#if defined(_
1270: 5f 47 4e 55 43 5f 5f 29 20 26 26 20 21 64 65 66 _GNUC__) && !def
1280: 69 6e 65 64 28 5f 47 4e 55 5f 53 4f 55 52 43 45 ined(_GNU_SOURCE
1290: 29 0a 23 20 64 65 66 69 6e 65 20 5f 47 4e 55 5f ).# define _GNU_
12a0: 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a 23 SOURCE.#endif..#
12b0: 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 65 if defined(__Ope
12c0: 6e 42 53 44 5f 5f 29 20 26 26 20 21 64 65 66 69 nBSD__) && !defi
12d0: 6e 65 64 28 5f 42 53 44 5f 53 4f 55 52 43 45 29 ned(_BSD_SOURCE)
12e0: 0a 23 20 64 65 66 69 6e 65 20 5f 42 53 44 5f 53 .# define _BSD_S
12f0: 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a OURCE.#endif../*
1300: 0a 2a 2a 20 46 6f 72 20 4d 69 6e 47 57 2c 20 63 .** For MinGW, c
1310: 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 77 heck to see if w
1320: 65 20 63 61 6e 20 69 6e 63 6c 75 64 65 20 74 68 e can include th
1330: 65 20 68 65 61 64 65 72 20 66 69 6c 65 20 63 6f e header file co
1340: 6e 74 61 69 6e 69 6e 67 20 69 74 73 0a 2a 2a 20 ntaining its.**
1350: 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 version informat
1360: 69 6f 6e 2c 20 61 6d 6f 6e 67 20 6f 74 68 65 72 ion, among other
1370: 20 74 68 69 6e 67 73 2e 20 20 4e 6f 72 6d 61 6c things. Normal
1380: 6c 79 2c 20 74 68 69 73 20 69 6e 74 65 72 6e 61 ly, this interna
1390: 6c 20 4d 69 6e 47 57 0a 2a 2a 20 68 65 61 64 65 l MinGW.** heade
13a0: 72 20 66 69 6c 65 20 77 6f 75 6c 64 20 5b 6f 6e r file would [on
13b0: 6c 79 5d 20 62 65 20 69 6e 63 6c 75 64 65 64 20 ly] be included
13c0: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 62 79 automatically by
13d0: 20 6f 74 68 65 72 20 4d 69 6e 47 57 20 68 65 61 other MinGW hea
13e0: 64 65 72 0a 2a 2a 20 66 69 6c 65 73 3b 20 68 6f der.** files; ho
13f0: 77 65 76 65 72 2c 20 74 68 65 20 63 6f 6e 74 61 wever, the conta
1400: 69 6e 65 64 20 76 65 72 73 69 6f 6e 20 69 6e 66 ined version inf
1410: 6f 72 6d 61 74 69 6f 6e 20 69 73 20 6e 6f 77 20 ormation is now
1420: 72 65 71 75 69 72 65 64 20 62 79 20 74 68 69 73 required by this
1430: 0a 2a 2a 20 68 65 61 64 65 72 20 66 69 6c 65 20 .** header file
1440: 74 6f 20 77 6f 72 6b 20 61 72 6f 75 6e 64 20 62 to work around b
1450: 69 6e 61 72 79 20 63 6f 6d 70 61 74 69 62 69 6c inary compatibil
1460: 69 74 79 20 69 73 73 75 65 73 20 28 73 65 65 20 ity issues (see
1470: 62 65 6c 6f 77 29 20 61 6e 64 0a 2a 2a 20 74 68 below) and.** th
1480: 69 73 20 69 73 20 74 68 65 20 6f 6e 6c 79 20 6b is is the only k
1490: 6e 6f 77 6e 20 77 61 79 20 74 6f 20 72 65 6c 69 nown way to reli
14a0: 61 62 6c 79 20 6f 62 74 61 69 6e 20 69 74 2e 20 ably obtain it.
14b0: 20 54 68 69 73 20 65 6e 74 69 72 65 20 23 69 66 This entire #if
14c0: 20 62 6c 6f 63 6b 0a 2a 2a 20 77 6f 75 6c 64 20 block.** would
14d0: 62 65 20 63 6f 6d 70 6c 65 74 65 6c 79 20 75 6e be completely un
14e0: 6e 65 63 65 73 73 61 72 79 20 69 66 20 74 68 65 necessary if the
14f0: 72 65 20 77 61 73 20 61 6e 79 20 6f 74 68 65 72 re was any other
1500: 20 77 61 79 20 6f 66 20 64 65 74 65 63 74 69 6e way of detectin
1510: 67 0a 2a 2a 20 4d 69 6e 47 57 20 76 69 61 20 74 g.** MinGW via t
1520: 68 65 69 72 20 70 72 65 70 72 6f 63 65 73 73 6f heir preprocesso
1530: 72 20 28 65 2e 67 2e 20 69 66 20 74 68 65 79 20 r (e.g. if they
1540: 63 75 73 74 6f 6d 69 7a 65 64 20 74 68 65 69 72 customized their
1550: 20 47 43 43 20 74 6f 20 64 65 66 69 6e 65 0a 2a GCC to define.*
1560: 2a 20 73 6f 6d 65 20 4d 69 6e 47 57 2d 73 70 65 * some MinGW-spe
1570: 63 69 66 69 63 20 6d 61 63 72 6f 73 29 2e 20 20 cific macros).
1580: 57 68 65 6e 20 63 6f 6d 70 69 6c 69 6e 67 20 66 When compiling f
1590: 6f 72 20 4d 69 6e 47 57 2c 20 65 69 74 68 65 72 or MinGW, either
15a0: 20 74 68 65 0a 2a 2a 20 5f 48 41 56 45 5f 4d 49 the.** _HAVE_MI
15b0: 4e 47 57 5f 48 20 6f 72 20 5f 48 41 56 45 5f 5f NGW_H or _HAVE__
15c0: 4d 49 4e 47 57 5f 48 20 28 6e 6f 74 65 20 74 68 MINGW_H (note th
15d0: 65 20 65 78 74 72 61 20 75 6e 64 65 72 73 63 6f e extra undersco
15e0: 72 65 29 20 6d 61 63 72 6f 20 6d 75 73 74 20 62 re) macro must b
15f0: 65 0a 2a 2a 20 64 65 66 69 6e 65 64 3b 20 6f 74 e.** defined; ot
1600: 68 65 72 77 69 73 65 2c 20 64 65 74 65 63 74 69 herwise, detecti
1610: 6f 6e 20 6f 66 20 63 6f 6e 64 69 74 69 6f 6e 73 on of conditions
1620: 20 73 70 65 63 69 66 69 63 20 74 6f 20 4d 69 6e specific to Min
1630: 47 57 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 64 69 GW will be.** di
1640: 73 61 62 6c 65 64 2e 0a 2a 2f 0a 23 69 66 20 64 sabled..*/.#if d
1650: 65 66 69 6e 65 64 28 5f 48 41 56 45 5f 4d 49 4e efined(_HAVE_MIN
1660: 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 64 65 20 GW_H).# include
1670: 22 6d 69 6e 67 77 2e 68 22 0a 23 65 6c 69 66 20 "mingw.h".#elif
1680: 64 65 66 69 6e 65 64 28 5f 48 41 56 45 5f 5f 4d defined(_HAVE__M
1690: 49 4e 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 64 INGW_H).# includ
16a0: 65 20 22 5f 6d 69 6e 67 77 2e 68 22 0a 23 65 6e e "_mingw.h".#en
16b0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 20 4d dif../*.** For M
16c0: 69 6e 47 57 20 76 65 72 73 69 6f 6e 20 34 2e 78 inGW version 4.x
16d0: 20 28 61 6e 64 20 68 69 67 68 65 72 29 2c 20 63 (and higher), c
16e0: 68 65 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 heck to see if t
16f0: 68 65 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 he _USE_32BIT_TI
1700: 4d 45 5f 54 0a 2a 2a 20 64 65 66 69 6e 65 20 69 ME_T.** define i
1710: 73 20 72 65 71 75 69 72 65 64 20 74 6f 20 6d 61 s required to ma
1720: 69 6e 74 61 69 6e 20 62 69 6e 61 72 79 20 63 6f intain binary co
1730: 6d 70 61 74 69 62 69 6c 69 74 79 20 77 69 74 68 mpatibility with
1740: 20 74 68 65 20 4d 53 56 43 20 72 75 6e 74 69 6d the MSVC runtim
1750: 65 0a 2a 2a 20 6c 69 62 72 61 72 79 20 69 6e 20 e.** library in
1760: 75 73 65 20 28 65 2e 67 2e 20 66 6f 72 20 57 69 use (e.g. for Wi
1770: 6e 64 6f 77 73 20 58 50 29 2e 0a 2a 2f 0a 23 69 ndows XP)..*/.#i
1780: 66 20 21 64 65 66 69 6e 65 64 28 5f 55 53 45 5f f !defined(_USE_
1790: 33 32 42 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 32BIT_TIME_T) &&
17a0: 20 21 64 65 66 69 6e 65 64 28 5f 55 53 45 5f 36 !defined(_USE_6
17b0: 34 42 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 20 4BIT_TIME_T) &&
17c0: 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 5f 57 \. defined(_W
17d0: 49 4e 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 IN32) && !define
17e0: 64 28 5f 57 49 4e 36 34 29 20 26 26 20 5c 0a 20 d(_WIN64) && \.
17f0: 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 4d 49 4e defined(__MIN
1800: 47 57 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e GW_MAJOR_VERSION
1810: 29 20 26 26 20 5f 5f 4d 49 4e 47 57 5f 4d 41 4a ) && __MINGW_MAJ
1820: 4f 52 5f 56 45 52 53 49 4f 4e 20 3e 3d 20 34 20 OR_VERSION >= 4
1830: 26 26 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 && \. defined
1840: 28 5f 5f 4d 53 56 43 52 54 5f 5f 29 0a 23 20 64 (__MSVCRT__).# d
1850: 65 66 69 6e 65 20 5f 55 53 45 5f 33 32 42 49 54 efine _USE_32BIT
1860: 5f 54 49 4d 45 5f 54 0a 23 65 6e 64 69 66 0a 0a _TIME_T.#endif..
1870: 2f 2a 20 54 68 65 20 70 75 62 6c 69 63 20 53 51 /* The public SQ
1880: 4c 69 74 65 20 69 6e 74 65 72 66 61 63 65 2e 20 Lite interface.
1890: 20 54 68 65 20 5f 46 49 4c 45 5f 4f 46 46 53 45 The _FILE_OFFSE
18a0: 54 5f 42 49 54 53 20 6d 61 63 72 6f 20 6d 75 73 T_BITS macro mus
18b0: 74 20 61 70 70 65 61 72 0a 2a 2a 20 66 69 72 73 t appear.** firs
18c0: 74 20 69 6e 20 51 4e 58 2e 20 20 41 6c 73 6f 2c t in QNX. Also,
18d0: 20 74 68 65 20 5f 55 53 45 5f 33 32 42 49 54 5f the _USE_32BIT_
18e0: 54 49 4d 45 5f 54 20 6d 61 63 72 6f 20 6d 75 73 TIME_T macro mus
18f0: 74 20 61 70 70 65 61 72 20 66 69 72 73 74 20 66 t appear first f
1900: 6f 72 0a 2a 2a 20 4d 69 6e 47 57 2e 0a 2a 2f 0a or.** MinGW..*/.
1910: 23 69 6e 63 6c 75 64 65 20 22 73 71 6c 69 74 65 #include "sqlite
1920: 33 2e 68 22 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 3.h"../*.** Incl
1930: 75 64 65 20 74 68 65 20 63 6f 6e 66 69 67 75 72 ude the configur
1940: 61 74 69 6f 6e 20 68 65 61 64 65 72 20 6f 75 74 ation header out
1950: 70 75 74 20 62 79 20 27 63 6f 6e 66 69 67 75 72 put by 'configur
1960: 65 27 20 69 66 20 77 65 27 72 65 20 75 73 69 6e e' if we're usin
1970: 67 20 74 68 65 0a 2a 2a 20 61 75 74 6f 63 6f 6e g the.** autocon
1980: 66 2d 62 61 73 65 64 20 62 75 69 6c 64 0a 2a 2f f-based build.*/
1990: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 48 41 .#if defined(_HA
19a0: 56 45 5f 53 51 4c 49 54 45 5f 43 4f 4e 46 49 47 VE_SQLITE_CONFIG
19b0: 5f 48 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 _H) && !defined(
19c0: 53 51 4c 49 54 45 43 4f 4e 46 49 47 5f 48 29 0a SQLITECONFIG_H).
19d0: 23 69 6e 63 6c 75 64 65 20 22 63 6f 6e 66 69 67 #include "config
19e0: 2e 68 22 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .h".#define SQLI
19f0: 54 45 43 4f 4e 46 49 47 5f 48 20 31 0a 23 65 6e TECONFIG_H 1.#en
1a00: 64 69 66 0a 0a 23 69 6e 63 6c 75 64 65 20 22 73 dif..#include "s
1a10: 71 6c 69 74 65 4c 69 6d 69 74 2e 68 22 0a 0a 2f qliteLimit.h"../
1a20: 2a 20 44 69 73 61 62 6c 65 20 6e 75 69 73 61 6e * Disable nuisan
1a30: 63 65 20 77 61 72 6e 69 6e 67 73 20 6f 6e 20 42 ce warnings on B
1a40: 6f 72 6c 61 6e 64 20 63 6f 6d 70 69 6c 65 72 73 orland compilers
1a50: 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 */.#if defined(
1a60: 5f 5f 42 4f 52 4c 41 4e 44 43 5f 5f 29 0a 23 70 __BORLANDC__).#p
1a70: 72 61 67 6d 61 20 77 61 72 6e 20 2d 72 63 68 20 ragma warn -rch
1a80: 2f 2a 20 75 6e 72 65 61 63 68 61 62 6c 65 20 63 /* unreachable c
1a90: 6f 64 65 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 ode */.#pragma w
1aa0: 61 72 6e 20 2d 63 63 63 20 2f 2a 20 43 6f 6e 64 arn -ccc /* Cond
1ab0: 69 74 69 6f 6e 20 69 73 20 61 6c 77 61 79 73 20 ition is always
1ac0: 74 72 75 65 20 6f 72 20 66 61 6c 73 65 20 2a 2f true or false */
1ad0: 0a 23 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 61 .#pragma warn -a
1ae0: 75 73 20 2f 2a 20 41 73 73 69 67 6e 65 64 20 76 us /* Assigned v
1af0: 61 6c 75 65 20 69 73 20 6e 65 76 65 72 20 75 73 alue is never us
1b00: 65 64 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 ed */.#pragma wa
1b10: 72 6e 20 2d 63 73 75 20 2f 2a 20 43 6f 6d 70 61 rn -csu /* Compa
1b20: 72 69 6e 67 20 73 69 67 6e 65 64 20 61 6e 64 20 ring signed and
1b30: 75 6e 73 69 67 6e 65 64 20 2a 2f 0a 23 70 72 61 unsigned */.#pra
1b40: 67 6d 61 20 77 61 72 6e 20 2d 73 70 61 20 2f 2a gma warn -spa /*
1b50: 20 53 75 73 70 69 63 69 6f 75 73 20 70 6f 69 6e Suspicious poin
1b60: 74 65 72 20 61 72 69 74 68 6d 65 74 69 63 20 2a ter arithmetic *
1b70: 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 /.#endif../*.**
1b80: 49 6e 63 6c 75 64 65 20 73 74 61 6e 64 61 72 64 Include standard
1b90: 20 68 65 61 64 65 72 20 66 69 6c 65 73 20 61 73 header files as
1ba0: 20 6e 65 63 65 73 73 61 72 79 0a 2a 2f 0a 23 69 necessary.*/.#i
1bb0: 66 64 65 66 20 48 41 56 45 5f 53 54 44 49 4e 54 fdef HAVE_STDINT
1bc0: 5f 48 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 _H.#include <std
1bd0: 69 6e 74 2e 68 3e 0a 23 65 6e 64 69 66 0a 23 69 int.h>.#endif.#i
1be0: 66 64 65 66 20 48 41 56 45 5f 49 4e 54 54 59 50 fdef HAVE_INTTYP
1bf0: 45 53 5f 48 0a 23 69 6e 63 6c 75 64 65 20 3c 69 ES_H.#include <i
1c00: 6e 74 74 79 70 65 73 2e 68 3e 0a 23 65 6e 64 69 nttypes.h>.#endi
1c10: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c f../*.** The fol
1c20: 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 lowing macros ar
1c30: 65 20 75 73 65 64 20 74 6f 20 63 61 73 74 20 70 e used to cast p
1c40: 6f 69 6e 74 65 72 73 20 74 6f 20 69 6e 74 65 67 ointers to integ
1c50: 65 72 73 20 61 6e 64 0a 2a 2a 20 69 6e 74 65 67 ers and.** integ
1c60: 65 72 73 20 74 6f 20 70 6f 69 6e 74 65 72 73 2e ers to pointers.
1c70: 20 20 54 68 65 20 77 61 79 20 79 6f 75 20 64 6f The way you do
1c80: 20 74 68 69 73 20 76 61 72 69 65 73 20 66 72 6f this varies fro
1c90: 6d 20 6f 6e 65 20 63 6f 6d 70 69 6c 65 72 0a 2a m one compiler.*
1ca0: 2a 20 74 6f 20 74 68 65 20 6e 65 78 74 2c 20 73 * to the next, s
1cb0: 6f 20 77 65 20 68 61 76 65 20 64 65 76 65 6c 6f o we have develo
1cc0: 70 65 64 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e ped the followin
1cd0: 67 20 73 65 74 20 6f 66 20 23 69 66 20 73 74 61 g set of #if sta
1ce0: 74 65 6d 65 6e 74 73 0a 2a 2a 20 74 6f 20 67 65 tements.** to ge
1cf0: 6e 65 72 61 74 65 20 61 70 70 72 6f 70 72 69 61 nerate appropria
1d00: 74 65 20 6d 61 63 72 6f 73 20 66 6f 72 20 61 20 te macros for a
1d10: 77 69 64 65 20 72 61 6e 67 65 20 6f 66 20 63 6f wide range of co
1d20: 6d 70 69 6c 65 72 73 2e 0a 2a 2a 0a 2a 2a 20 54 mpilers..**.** T
1d30: 68 65 20 63 6f 72 72 65 63 74 20 22 41 4e 53 49 he correct "ANSI
1d40: 22 20 77 61 79 20 74 6f 20 64 6f 20 74 68 69 73 " way to do this
1d50: 20 69 73 20 74 6f 20 75 73 65 20 74 68 65 20 69 is to use the i
1d60: 6e 74 70 74 72 5f 74 20 74 79 70 65 2e 0a 2a 2a ntptr_t type..**
1d70: 20 55 6e 66 6f 72 74 75 6e 61 74 65 6c 79 2c 20 Unfortunately,
1d80: 74 68 61 74 20 74 79 70 65 64 65 66 20 69 73 20 that typedef is
1d90: 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 20 6f 6e not available on
1da0: 20 61 6c 6c 20 63 6f 6d 70 69 6c 65 72 73 2c 20 all compilers,
1db0: 6f 72 0a 2a 2a 20 69 66 20 69 74 20 69 73 20 61 or.** if it is a
1dc0: 76 61 69 6c 61 62 6c 65 2c 20 69 74 20 72 65 71 vailable, it req
1dd0: 75 69 72 65 73 20 61 6e 20 23 69 6e 63 6c 75 64 uires an #includ
1de0: 65 20 6f 66 20 73 70 65 63 69 66 69 63 20 68 65 e of specific he
1df0: 61 64 65 72 73 0a 2a 2a 20 74 68 61 74 20 76 61 aders.** that va
1e00: 72 79 20 66 72 6f 6d 20 6f 6e 65 20 6d 61 63 68 ry from one mach
1e10: 69 6e 65 20 74 6f 20 74 68 65 20 6e 65 78 74 2e ine to the next.
1e20: 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 20 23 33 .**.** Ticket #3
1e30: 38 36 30 3a 20 20 54 68 65 20 6c 6c 76 6d 2d 67 860: The llvm-g
1e40: 63 63 2d 34 2e 32 20 63 6f 6d 70 69 6c 65 72 20 cc-4.2 compiler
1e50: 66 72 6f 6d 20 41 70 70 6c 65 20 63 68 6f 6b 65 from Apple choke
1e60: 73 20 6f 6e 0a 2a 2a 20 74 68 65 20 28 28 76 6f s on.** the ((vo
1e70: 69 64 2a 29 26 28 28 63 68 61 72 2a 29 30 29 5b id*)&((char*)0)[
1e80: 58 5d 29 20 63 6f 6e 73 74 72 75 63 74 2e 20 20 X]) construct.
1e90: 42 75 74 20 4d 53 56 43 20 63 68 6f 6b 65 73 20 But MSVC chokes
1ea0: 6f 6e 20 28 28 76 6f 69 64 2a 29 28 58 29 29 2e on ((void*)(X)).
1eb0: 0a 2a 2a 20 53 6f 20 77 65 20 68 61 76 65 20 74 .** So we have t
1ec0: 6f 20 64 65 66 69 6e 65 20 74 68 65 20 6d 61 63 o define the mac
1ed0: 72 6f 73 20 69 6e 20 64 69 66 66 65 72 65 6e 74 ros in different
1ee0: 20 77 61 79 73 20 64 65 70 65 6e 64 69 6e 67 20 ways depending
1ef0: 6f 6e 20 74 68 65 0a 2a 2a 20 63 6f 6d 70 69 6c on the.** compil
1f00: 65 72 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e er..*/.#if defin
1f10: 65 64 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 ed(__PTRDIFF_TYP
1f20: 45 5f 5f 29 20 20 2f 2a 20 54 68 69 73 20 63 61 E__) /* This ca
1f30: 73 65 20 73 68 6f 75 6c 64 20 77 6f 72 6b 20 66 se should work f
1f40: 6f 72 20 47 43 43 20 2a 2f 0a 23 20 64 65 66 69 or GCC */.# defi
1f50: 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f ne SQLITE_INT_TO
1f60: 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 2a _PTR(X) ((void*
1f70: 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 45 )(__PTRDIFF_TYPE
1f80: 5f 5f 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 __)(X)).# define
1f90: 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 SQLITE_PTR_TO_I
1fa0: 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 5f 5f NT(X) ((int)(__
1fb0: 50 54 52 44 49 46 46 5f 54 59 50 45 5f 5f 29 28 PTRDIFF_TYPE__)(
1fc0: 58 29 29 0a 23 65 6c 69 66 20 21 64 65 66 69 6e X)).#elif !defin
1fd0: 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 20 20 20 20 ed(__GNUC__)
1fe0: 20 20 20 2f 2a 20 57 6f 72 6b 73 20 66 6f 72 20 /* Works for
1ff0: 63 6f 6d 70 69 6c 65 72 73 20 6f 74 68 65 72 20 compilers other
2000: 74 68 61 6e 20 4c 4c 56 4d 20 2a 2f 0a 23 20 64 than LLVM */.# d
2010: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 efine SQLITE_INT
2020: 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f _TO_PTR(X) ((vo
2030: 69 64 2a 29 26 28 28 63 68 61 72 2a 29 30 29 5b id*)&((char*)0)[
2040: 58 5d 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c X]).# define SQL
2050: 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 ITE_PTR_TO_INT(X
2060: 29 20 20 28 28 69 6e 74 29 28 28 28 63 68 61 72 ) ((int)(((char
2070: 2a 29 58 29 2d 28 63 68 61 72 2a 29 30 29 29 0a *)X)-(char*)0)).
2080: 23 65 6c 69 66 20 64 65 66 69 6e 65 64 28 48 41 #elif defined(HA
2090: 56 45 5f 53 54 44 49 4e 54 5f 48 29 20 20 20 2f VE_STDINT_H) /
20a0: 2a 20 55 73 65 20 74 68 69 73 20 63 61 73 65 20 * Use this case
20b0: 69 66 20 77 65 20 68 61 76 65 20 41 4e 53 49 20 if we have ANSI
20c0: 68 65 61 64 65 72 73 20 2a 2f 0a 23 20 64 65 66 headers */.# def
20d0: 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 ine SQLITE_INT_T
20e0: 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 O_PTR(X) ((void
20f0: 2a 29 28 69 6e 74 70 74 72 5f 74 29 28 58 29 29 *)(intptr_t)(X))
2100: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
2110: 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 _PTR_TO_INT(X)
2120: 28 28 69 6e 74 29 28 69 6e 74 70 74 72 5f 74 29 ((int)(intptr_t)
2130: 28 58 29 29 0a 23 65 6c 73 65 20 20 20 20 20 20 (X)).#else
2140: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2150: 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 74 65 73 /* Generates
2160: 20 61 20 77 61 72 6e 69 6e 67 20 2d 20 62 75 74 a warning - but
2170: 20 69 74 20 61 6c 77 61 79 73 20 77 6f 72 6b 73 it always works
2180: 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c */.# define SQL
2190: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 ITE_INT_TO_PTR(X
21a0: 29 20 20 28 28 76 6f 69 64 2a 29 28 58 29 29 0a ) ((void*)(X)).
21b0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
21c0: 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 PTR_TO_INT(X) (
21d0: 28 69 6e 74 29 28 58 29 29 0a 23 65 6e 64 69 66 (int)(X)).#endif
21e0: 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 72 6f 20 ../*.** A macro
21f0: 74 6f 20 68 69 6e 74 20 74 6f 20 74 68 65 20 63 to hint to the c
2200: 6f 6d 70 69 6c 65 72 20 74 68 61 74 20 61 20 66 ompiler that a f
2210: 75 6e 63 74 69 6f 6e 20 73 68 6f 75 6c 64 20 6e unction should n
2220: 6f 74 20 62 65 0a 2a 2a 20 69 6e 6c 69 6e 65 64 ot be.** inlined
2230: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
2240: 28 5f 5f 47 4e 55 43 5f 5f 29 0a 23 20 20 64 65 (__GNUC__).# de
2250: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 49 4e fine SQLITE_NOIN
2260: 4c 49 4e 45 20 20 5f 5f 61 74 74 72 69 62 75 74 LINE __attribut
2270: 65 5f 5f 28 28 6e 6f 69 6e 6c 69 6e 65 29 29 0a e__((noinline)).
2280: 23 65 6c 69 66 20 64 65 66 69 6e 65 64 28 5f 4d #elif defined(_M
2290: 53 43 5f 56 45 52 29 20 26 26 20 5f 4d 53 43 5f SC_VER) && _MSC_
22a0: 56 45 52 3e 3d 31 33 31 30 0a 23 20 20 64 65 66 VER>=1310.# def
22b0: 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 49 4e 4c ine SQLITE_NOINL
22c0: 49 4e 45 20 20 5f 5f 64 65 63 6c 73 70 65 63 28 INE __declspec(
22d0: 6e 6f 69 6e 6c 69 6e 65 29 0a 23 65 6c 73 65 0a noinline).#else.
22e0: 23 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 # define SQLITE
22f0: 5f 4e 4f 49 4e 4c 49 4e 45 0a 23 65 6e 64 69 66 _NOINLINE.#endif
2300: 0a 0a 2f 2a 0a 2a 2a 20 4d 61 6b 65 20 73 75 72 ../*.** Make sur
2310: 65 20 74 68 61 74 20 74 68 65 20 63 6f 6d 70 69 e that the compi
2320: 6c 65 72 20 69 6e 74 72 69 6e 73 69 63 73 20 77 ler intrinsics w
2330: 65 20 64 65 73 69 72 65 20 61 72 65 20 65 6e 61 e desire are ena
2340: 62 6c 65 64 20 77 68 65 6e 0a 2a 2a 20 63 6f 6d bled when.** com
2350: 70 69 6c 69 6e 67 20 77 69 74 68 20 61 6e 20 61 piling with an a
2360: 70 70 72 6f 70 72 69 61 74 65 20 76 65 72 73 69 ppropriate versi
2370: 6f 6e 20 6f 66 20 4d 53 56 43 20 75 6e 6c 65 73 on of MSVC unles
2380: 73 20 70 72 65 76 65 6e 74 65 64 20 62 79 0a 2a s prevented by.*
2390: 2a 20 74 68 65 20 53 51 4c 49 54 45 5f 44 49 53 * the SQLITE_DIS
23a0: 41 42 4c 45 5f 49 4e 54 52 49 4e 53 49 43 20 64 ABLE_INTRINSIC d
23b0: 65 66 69 6e 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 efine..*/.#if !d
23c0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 49 efined(SQLITE_DI
23d0: 53 41 42 4c 45 5f 49 4e 54 52 49 4e 53 49 43 29 SABLE_INTRINSIC)
23e0: 0a 23 20 20 69 66 20 64 65 66 69 6e 65 64 28 5f .# if defined(_
23f0: 4d 53 43 5f 56 45 52 29 20 26 26 20 5f 4d 53 43 MSC_VER) && _MSC
2400: 5f 56 45 52 3e 3d 31 34 30 30 0a 23 20 20 20 20 _VER>=1400.#
2410: 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e if !defined(_WIN
2420: 33 32 5f 57 43 45 29 0a 23 20 20 20 20 20 20 69 32_WCE).# i
2430: 6e 63 6c 75 64 65 20 3c 69 6e 74 72 69 6e 2e 68 nclude <intrin.h
2440: 3e 0a 23 20 20 20 20 20 20 70 72 61 67 6d 61 20 >.# pragma
2450: 69 6e 74 72 69 6e 73 69 63 28 5f 62 79 74 65 73 intrinsic(_bytes
2460: 77 61 70 5f 75 73 68 6f 72 74 29 0a 23 20 20 20 wap_ushort).#
2470: 20 20 20 70 72 61 67 6d 61 20 69 6e 74 72 69 6e pragma intrin
2480: 73 69 63 28 5f 62 79 74 65 73 77 61 70 5f 75 6c sic(_byteswap_ul
2490: 6f 6e 67 29 0a 23 20 20 20 20 20 20 70 72 61 67 ong).# prag
24a0: 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 5f 62 79 ma intrinsic(_by
24b0: 74 65 73 77 61 70 5f 75 69 6e 74 36 34 29 0a 23 teswap_uint64).#
24c0: 20 20 20 20 20 20 70 72 61 67 6d 61 20 69 6e 74 pragma int
24d0: 72 69 6e 73 69 63 28 5f 52 65 61 64 57 72 69 74 rinsic(_ReadWrit
24e0: 65 42 61 72 72 69 65 72 29 0a 23 20 20 20 20 65 eBarrier).# e
24f0: 6c 73 65 0a 23 20 20 20 20 20 20 69 6e 63 6c 75 lse.# inclu
2500: 64 65 20 3c 63 6d 6e 69 6e 74 72 69 6e 2e 68 3e de <cmnintrin.h>
2510: 0a 23 20 20 20 20 65 6e 64 69 66 0a 23 20 20 65 .# endif.# e
2520: 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a ndif.#endif../*.
2530: 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 54 48 ** The SQLITE_TH
2540: 52 45 41 44 53 41 46 45 20 6d 61 63 72 6f 20 6d READSAFE macro m
2550: 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 20 61 ust be defined a
2560: 73 20 30 2c 20 31 2c 20 6f 72 20 32 2e 0a 2a 2a s 0, 1, or 2..**
2570: 20 30 20 6d 65 61 6e 73 20 6d 75 74 65 78 65 73 0 means mutexes
2580: 20 61 72 65 20 70 65 72 6d 61 6e 65 6e 74 6c 79 are permanently
2590: 20 64 69 73 61 62 6c 65 20 61 6e 64 20 74 68 65 disable and the
25a0: 20 6c 69 62 72 61 72 79 20 69 73 20 6e 65 76 65 library is neve
25b0: 72 0a 2a 2a 20 74 68 72 65 61 64 73 61 66 65 2e r.** threadsafe.
25c0: 20 20 31 20 6d 65 61 6e 73 20 74 68 65 20 6c 69 1 means the li
25d0: 62 72 61 72 79 20 69 73 20 73 65 72 69 61 6c 69 brary is seriali
25e0: 7a 65 64 20 77 68 69 63 68 20 69 73 20 74 68 65 zed which is the
25f0: 20 68 69 67 68 65 73 74 0a 2a 2a 20 6c 65 76 65 highest.** leve
2600: 6c 20 6f 66 20 74 68 72 65 61 64 73 61 66 65 74 l of threadsafet
2610: 79 2e 20 20 32 20 6d 65 61 6e 73 20 74 68 65 20 y. 2 means the
2620: 6c 69 62 72 61 72 79 20 69 73 20 6d 75 6c 74 69 library is multi
2630: 74 68 72 65 61 64 65 64 20 2d 20 6d 75 6c 74 69 threaded - multi
2640: 70 6c 65 0a 2a 2a 20 74 68 72 65 61 64 73 20 63 ple.** threads c
2650: 61 6e 20 75 73 65 20 53 51 4c 69 74 65 20 61 73 an use SQLite as
2660: 20 6c 6f 6e 67 20 61 73 20 6e 6f 20 74 77 6f 20 long as no two
2670: 74 68 72 65 61 64 73 20 74 72 79 20 74 6f 20 75 threads try to u
2680: 73 65 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 64 se the same.** d
2690: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
26a0: 6f 6e 20 61 74 20 74 68 65 20 73 61 6d 65 20 74 on at the same t
26b0: 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 4f 6c 64 65 72 ime..**.** Older
26c0: 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 53 51 4c versions of SQL
26d0: 69 74 65 20 75 73 65 64 20 61 6e 20 6f 70 74 69 ite used an opti
26e0: 6f 6e 61 6c 20 54 48 52 45 41 44 53 41 46 45 20 onal THREADSAFE
26f0: 6d 61 63 72 6f 2e 0a 2a 2a 20 57 65 20 73 75 70 macro..** We sup
2700: 70 6f 72 74 20 74 68 61 74 20 66 6f 72 20 6c 65 port that for le
2710: 67 61 63 79 2e 0a 2a 2a 0a 2a 2a 20 54 6f 20 65 gacy..**.** To e
2720: 6e 73 75 72 65 20 74 68 61 74 20 74 68 65 20 63 nsure that the c
2730: 6f 72 72 65 63 74 20 76 61 6c 75 65 20 6f 66 20 orrect value of
2740: 22 54 48 52 45 41 44 53 41 46 45 22 20 69 73 20 "THREADSAFE" is
2750: 72 65 70 6f 72 74 65 64 20 77 68 65 6e 20 71 75 reported when qu
2760: 65 72 79 69 6e 67 0a 2a 2a 20 66 6f 72 20 63 6f erying.** for co
2770: 6d 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f mpile-time optio
2780: 6e 73 20 61 74 20 72 75 6e 74 69 6d 65 20 28 65 ns at runtime (e
2790: 2e 67 2e 20 22 50 52 41 47 4d 41 20 63 6f 6d 70 .g. "PRAGMA comp
27a0: 69 6c 65 5f 6f 70 74 69 6f 6e 73 22 29 2c 20 74 ile_options"), t
27b0: 68 69 73 0a 2a 2a 20 6c 6f 67 69 63 20 69 73 20 his.** logic is
27c0: 70 61 72 74 69 61 6c 6c 79 20 72 65 70 6c 69 63 partially replic
27d0: 61 74 65 64 20 69 6e 20 63 74 69 6d 65 2e 63 2e ated in ctime.c.
27e0: 20 49 66 20 69 74 20 69 73 20 75 70 64 61 74 65 If it is update
27f0: 64 20 68 65 72 65 2c 20 69 74 20 73 68 6f 75 6c d here, it shoul
2800: 64 0a 2a 2a 20 61 6c 73 6f 20 62 65 20 75 70 64 d.** also be upd
2810: 61 74 65 64 20 74 68 65 72 65 2e 0a 2a 2f 0a 23 ated there..*/.#
2820: 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
2830: 54 45 5f 54 48 52 45 41 44 53 41 46 45 29 0a 23 TE_THREADSAFE).#
2840: 20 69 66 20 64 65 66 69 6e 65 64 28 54 48 52 45 if defined(THRE
2850: 41 44 53 41 46 45 29 0a 23 20 20 20 64 65 66 69 ADSAFE).# defi
2860: 6e 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 ne SQLITE_THREAD
2870: 53 41 46 45 20 54 48 52 45 41 44 53 41 46 45 0a SAFE THREADSAFE.
2880: 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e # else.# defin
2890: 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 53 e SQLITE_THREADS
28a0: 41 46 45 20 31 20 2f 2a 20 49 4d 50 3a 20 52 2d AFE 1 /* IMP: R-
28b0: 30 37 32 37 32 2d 32 32 33 30 39 20 2a 2f 0a 23 07272-22309 */.#
28c0: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f endif.#endif../
28d0: 2a 0a 2a 2a 20 50 6f 77 65 72 73 61 66 65 20 6f *.** Powersafe o
28e0: 76 65 72 77 72 69 74 65 20 69 73 20 6f 6e 20 62 verwrite is on b
28f0: 79 20 64 65 66 61 75 6c 74 2e 20 20 42 75 74 20 y default. But
2900: 63 61 6e 20 62 65 20 74 75 72 6e 65 64 20 6f 66 can be turned of
2910: 66 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65 20 2d f using.** the -
2920: 44 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 DSQLITE_POWERSAF
2930: 45 5f 4f 56 45 52 57 52 49 54 45 3d 30 20 63 6f E_OVERWRITE=0 co
2940: 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f mmand-line optio
2950: 6e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 n..*/.#ifndef SQ
2960: 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 45 5f 4f LITE_POWERSAFE_O
2970: 56 45 52 57 52 49 54 45 0a 23 20 64 65 66 69 6e VERWRITE.# defin
2980: 65 20 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 e SQLITE_POWERSA
2990: 46 45 5f 4f 56 45 52 57 52 49 54 45 20 31 0a 23 FE_OVERWRITE 1.#
29a0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 56 49 endif../*.** EVI
29b0: 44 45 4e 43 45 2d 4f 46 3a 20 52 2d 32 35 37 31 DENCE-OF: R-2571
29c0: 35 2d 33 37 30 37 32 20 4d 65 6d 6f 72 79 20 61 5-37072 Memory a
29d0: 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 69 73 llocation statis
29e0: 74 69 63 73 20 61 72 65 20 65 6e 61 62 6c 65 64 tics are enabled
29f0: 20 62 79 0a 2a 2a 20 64 65 66 61 75 6c 74 20 75 by.** default u
2a00: 6e 6c 65 73 73 20 53 51 4c 69 74 65 20 69 73 20 nless SQLite is
2a10: 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 20 53 51 compiled with SQ
2a20: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d LITE_DEFAULT_MEM
2a30: 53 54 41 54 55 53 3d 30 20 69 6e 0a 2a 2a 20 77 STATUS=0 in.** w
2a40: 68 69 63 68 20 63 61 73 65 20 6d 65 6d 6f 72 79 hich case memory
2a50: 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 allocation stat
2a60: 69 73 74 69 63 73 20 61 72 65 20 64 69 73 61 62 istics are disab
2a70: 6c 65 64 20 62 79 20 64 65 66 61 75 6c 74 2e 0a led by default..
2a80: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
2a90: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
2aa0: 45 4d 53 54 41 54 55 53 29 0a 23 20 64 65 66 69 EMSTATUS).# defi
2ab0: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
2ac0: 54 5f 4d 45 4d 53 54 41 54 55 53 20 31 0a 23 65 T_MEMSTATUS 1.#e
2ad0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 78 61 63 ndif../*.** Exac
2ae0: 74 6c 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 tly one of the f
2af0: 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 ollowing macros
2b00: 6d 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 20 must be defined
2b10: 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 73 in order to.** s
2b20: 70 65 63 69 66 79 20 77 68 69 63 68 20 6d 65 6d pecify which mem
2b30: 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 ory allocation s
2b40: 75 62 73 79 73 74 65 6d 20 74 6f 20 75 73 65 2e ubsystem to use.
2b50: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 .**.** SQLIT
2b60: 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 E_SYSTEM_MALLOC
2b70: 20 20 20 20 20 20 20 20 20 2f 2f 20 55 73 65 20 // Use
2b80: 6e 6f 72 6d 61 6c 20 73 79 73 74 65 6d 20 6d 61 normal system ma
2b90: 6c 6c 6f 63 28 29 0a 2a 2a 20 20 20 20 20 53 51 lloc().** SQ
2ba0: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
2bb0: 43 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 55 C // U
2bc0: 73 65 20 57 69 6e 33 32 20 6e 61 74 69 76 65 20 se Win32 native
2bd0: 68 65 61 70 20 41 50 49 0a 2a 2a 20 20 20 20 20 heap API.**
2be0: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
2bf0: 4f 43 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f OC //
2c00: 20 55 73 65 20 61 20 73 74 75 62 20 61 6c 6c 6f Use a stub allo
2c10: 63 61 74 6f 72 20 74 68 61 74 20 61 6c 77 61 79 cator that alway
2c20: 73 20 66 61 69 6c 73 0a 2a 2a 20 20 20 20 20 53 s fails.** S
2c30: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 20 QLITE_MEMDEBUG
2c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
2c50: 44 65 62 75 67 67 69 6e 67 20 76 65 72 73 69 6f Debugging versio
2c60: 6e 20 6f 66 20 73 79 73 74 65 6d 20 6d 61 6c 6c n of system mall
2c70: 6f 63 28 29 0a 2a 2a 0a 2a 2a 20 4f 6e 20 57 69 oc().**.** On Wi
2c80: 6e 64 6f 77 73 2c 20 69 66 20 74 68 65 20 53 51 ndows, if the SQ
2c90: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
2ca0: 43 5f 56 41 4c 49 44 41 54 45 20 6d 61 63 72 6f C_VALIDATE macro
2cb0: 20 69 73 20 64 65 66 69 6e 65 64 20 61 6e 64 20 is defined and
2cc0: 74 68 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 the.** assert()
2cd0: 6d 61 63 72 6f 20 69 73 20 65 6e 61 62 6c 65 64 macro is enabled
2ce0: 2c 20 65 61 63 68 20 63 61 6c 6c 20 69 6e 74 6f , each call into
2cf0: 20 74 68 65 20 57 69 6e 33 32 20 6e 61 74 69 76 the Win32 nativ
2d00: 65 20 68 65 61 70 20 73 75 62 73 79 73 74 65 6d e heap subsystem
2d10: 0a 2a 2a 20 77 69 6c 6c 20 63 61 75 73 65 20 48 .** will cause H
2d20: 65 61 70 56 61 6c 69 64 61 74 65 20 74 6f 20 62 eapValidate to b
2d30: 65 20 63 61 6c 6c 65 64 2e 20 20 49 66 20 68 65 e called. If he
2d40: 61 70 20 76 61 6c 69 64 61 74 69 6f 6e 20 73 68 ap validation sh
2d50: 6f 75 6c 64 20 66 61 69 6c 2c 20 61 6e 0a 2a 2a ould fail, an.**
2d60: 20 61 73 73 65 72 74 69 6f 6e 20 77 69 6c 6c 20 assertion will
2d70: 62 65 20 74 72 69 67 67 65 72 65 64 2e 0a 2a 2a be triggered..**
2d80: 0a 2a 2a 20 49 66 20 6e 6f 6e 65 20 6f 66 20 74 .** If none of t
2d90: 68 65 20 61 62 6f 76 65 20 61 72 65 20 64 65 66 he above are def
2da0: 69 6e 65 64 2c 20 74 68 65 6e 20 73 65 74 20 53 ined, then set S
2db0: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
2dc0: 4c 4f 43 20 61 73 0a 2a 2a 20 74 68 65 20 64 65 LOC as.** the de
2dd0: 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 66 20 64 65 fault..*/.#if de
2de0: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 53 fined(SQLITE_SYS
2df0: 54 45 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 TEM_MALLOC) \.
2e00: 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 + defined(SQLITE
2e10: 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 5c _WIN32_MALLOC) \
2e20: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
2e30: 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 29 ITE_ZERO_MALLOC)
2e40: 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 \. + defined(S
2e50: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 3e QLITE_MEMDEBUG)>
2e60: 31 0a 23 20 65 72 72 6f 72 20 22 54 77 6f 20 6f 1.# error "Two o
2e70: 72 20 6d 6f 72 65 20 6f 66 20 74 68 65 20 66 6f r more of the fo
2e80: 6c 6c 6f 77 69 6e 67 20 63 6f 6d 70 69 6c 65 2d llowing compile-
2e90: 74 69 6d 65 20 63 6f 6e 66 69 67 75 72 61 74 69 time configurati
2ea0: 6f 6e 20 6f 70 74 69 6f 6e 73 5c 0a 20 61 72 65 on options\. are
2eb0: 20 64 65 66 69 6e 65 64 20 62 75 74 20 61 74 20 defined but at
2ec0: 6d 6f 73 74 20 6f 6e 65 20 69 73 20 61 6c 6c 6f most one is allo
2ed0: 77 65 64 3a 5c 0a 20 53 51 4c 49 54 45 5f 53 59 wed:\. SQLITE_SY
2ee0: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c STEM_MALLOC, SQL
2ef0: 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 ITE_WIN32_MALLOC
2f00: 2c 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 , SQLITE_MEMDEBU
2f10: 47 2c 5c 0a 20 53 51 4c 49 54 45 5f 5a 45 52 4f G,\. SQLITE_ZERO
2f20: 5f 4d 41 4c 4c 4f 43 22 0a 23 65 6e 64 69 66 0a _MALLOC".#endif.
2f30: 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
2f40: 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 TE_SYSTEM_MALLOC
2f50: 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 ) \. + defined(
2f60: 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c SQLITE_WIN32_MAL
2f70: 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e LOC) \. + defin
2f80: 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d ed(SQLITE_ZERO_M
2f90: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
2fa0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 45 4d 44 ined(SQLITE_MEMD
2fb0: 45 42 55 47 29 3d 3d 30 0a 23 20 64 65 66 69 6e EBUG)==0.# defin
2fc0: 65 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f e SQLITE_SYSTEM_
2fd0: 4d 41 4c 4c 4f 43 20 31 0a 23 65 6e 64 69 66 0a MALLOC 1.#endif.
2fe0: 0a 2f 2a 0a 2a 2a 20 49 66 20 53 51 4c 49 54 45 ./*.** If SQLITE
2ff0: 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d _MALLOC_SOFT_LIM
3000: 49 54 20 69 73 20 6e 6f 74 20 7a 65 72 6f 2c 20 IT is not zero,
3010: 74 68 65 6e 20 74 72 79 20 74 6f 20 6b 65 65 70 then try to keep
3020: 20 74 68 65 0a 2a 2a 20 73 69 7a 65 73 20 6f 66 the.** sizes of
3030: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
3040: 6f 6e 73 20 62 65 6c 6f 77 20 74 68 69 73 20 76 ons below this v
3050: 61 6c 75 65 20 77 68 65 72 65 20 70 6f 73 73 69 alue where possi
3060: 62 6c 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 ble..*/.#if !def
3070: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 41 4c 4c ined(SQLITE_MALL
3080: 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 29 0a 23 OC_SOFT_LIMIT).#
3090: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
30a0: 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 ALLOC_SOFT_LIMIT
30b0: 20 31 30 32 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 1024.#endif../*
30c0: 0a 2a 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 64 .** We need to d
30d0: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
30e0: 52 43 45 20 61 73 20 66 6f 6c 6c 6f 77 73 20 69 RCE as follows i
30f0: 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c n order to enabl
3100: 65 0a 2a 2a 20 72 65 63 75 72 73 69 76 65 20 6d e.** recursive m
3110: 75 74 65 78 65 73 20 6f 6e 20 6d 6f 73 74 20 55 utexes on most U
3120: 6e 69 78 20 73 79 73 74 65 6d 73 20 61 6e 64 20 nix systems and
3130: 66 63 68 6d 6f 64 28 29 20 6f 6e 20 4f 70 65 6e fchmod() on Open
3140: 42 53 44 2e 0a 2a 2a 20 42 75 74 20 5f 58 4f 50 BSD..** But _XOP
3150: 45 4e 5f 53 4f 55 52 43 45 20 64 65 66 69 6e 65 EN_SOURCE define
3160: 20 63 61 75 73 65 73 20 70 72 6f 62 6c 65 6d 73 causes problems
3170: 20 66 6f 72 20 4d 61 63 20 4f 53 20 58 2c 20 73 for Mac OS X, s
3180: 6f 20 6f 6d 69 74 0a 2a 2a 20 69 74 2e 0a 2a 2f o omit.** it..*/
3190: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 58 .#if !defined(_X
31a0: 4f 50 45 4e 5f 53 4f 55 52 43 45 29 20 26 26 20 OPEN_SOURCE) &&
31b0: 21 64 65 66 69 6e 65 64 28 5f 5f 44 41 52 57 49 !defined(__DARWI
31c0: 4e 5f 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 N__) && !defined
31d0: 28 5f 5f 41 50 50 4c 45 5f 5f 29 0a 23 20 20 64 (__APPLE__).# d
31e0: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
31f0: 52 43 45 20 36 30 30 0a 23 65 6e 64 69 66 0a 0a RCE 600.#endif..
3200: 2f 2a 0a 2a 2a 20 4e 44 45 42 55 47 20 61 6e 64 /*.** NDEBUG and
3210: 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 61 72 SQLITE_DEBUG ar
3220: 65 20 6f 70 70 6f 73 69 74 65 73 2e 20 20 49 74 e opposites. It
3230: 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 62 should always b
3240: 65 20 74 72 75 65 20 74 68 61 74 0a 2a 2a 20 64 e true that.** d
3250: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 3d 3d efined(NDEBUG)==
3260: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
3270: 44 45 42 55 47 29 2e 20 20 49 66 20 74 68 69 73 DEBUG). If this
3280: 20 69 73 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c is not currentl
3290: 79 20 74 72 75 65 2c 0a 2a 2a 20 6d 61 6b 65 20 y true,.** make
32a0: 69 74 20 74 72 75 65 20 62 79 20 64 65 66 69 6e it true by defin
32b0: 69 6e 67 20 6f 72 20 75 6e 64 65 66 69 6e 69 6e ing or undefinin
32c0: 67 20 4e 44 45 42 55 47 2e 0a 2a 2a 0a 2a 2a 20 g NDEBUG..**.**
32d0: 53 65 74 74 69 6e 67 20 4e 44 45 42 55 47 20 6d Setting NDEBUG m
32e0: 61 6b 65 73 20 74 68 65 20 63 6f 64 65 20 73 6d akes the code sm
32f0: 61 6c 6c 65 72 20 61 6e 64 20 66 61 73 74 65 72 aller and faster
3300: 20 62 79 20 64 69 73 61 62 6c 69 6e 67 20 74 68 by disabling th
3310: 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 73 74 e.** assert() st
3320: 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 atements in the
3330: 63 6f 64 65 2e 20 20 53 6f 20 77 65 20 77 61 6e code. So we wan
3340: 74 20 74 68 65 20 64 65 66 61 75 6c 74 20 61 63 t the default ac
3350: 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 66 6f tion.** to be fo
3360: 72 20 4e 44 45 42 55 47 20 74 6f 20 62 65 20 73 r NDEBUG to be s
3370: 65 74 20 61 6e 64 20 4e 44 45 42 55 47 20 74 6f et and NDEBUG to
3380: 20 62 65 20 75 6e 64 65 66 69 6e 65 64 20 6f 6e be undefined on
3390: 6c 79 20 69 66 20 53 51 4c 49 54 45 5f 44 45 42 ly if SQLITE_DEB
33a0: 55 47 0a 2a 2a 20 69 73 20 73 65 74 2e 20 20 54 UG.** is set. T
33b0: 68 75 73 20 4e 44 45 42 55 47 20 62 65 63 6f 6d hus NDEBUG becom
33c0: 65 73 20 61 6e 20 6f 70 74 2d 69 6e 20 72 61 74 es an opt-in rat
33d0: 68 65 72 20 74 68 61 6e 20 61 6e 20 6f 70 74 2d her than an opt-
33e0: 6f 75 74 0a 2a 2a 20 66 65 61 74 75 72 65 2e 0a out.** feature..
33f0: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
3400: 4e 44 45 42 55 47 29 20 26 26 20 21 64 65 66 69 NDEBUG) && !defi
3410: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
3420: 29 0a 23 20 64 65 66 69 6e 65 20 4e 44 45 42 55 ).# define NDEBU
3430: 47 20 31 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 G 1.#endif.#if d
3440: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 26 efined(NDEBUG) &
3450: 26 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 & defined(SQLITE
3460: 5f 44 45 42 55 47 29 0a 23 20 75 6e 64 65 66 20 _DEBUG).# undef
3470: 4e 44 45 42 55 47 0a 23 65 6e 64 69 66 0a 0a 2f NDEBUG.#endif../
3480: 2a 0a 2a 2a 20 45 6e 61 62 6c 65 20 53 51 4c 49 *.** Enable SQLI
3490: 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 TE_ENABLE_EXPLAI
34a0: 4e 5f 43 4f 4d 4d 45 4e 54 53 20 69 66 20 53 51 N_COMMENTS if SQ
34b0: 4c 49 54 45 5f 44 45 42 55 47 20 69 73 20 74 75 LITE_DEBUG is tu
34c0: 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 69 66 20 rned on..*/.#if
34d0: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
34e0: 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 ENABLE_EXPLAIN_C
34f0: 4f 4d 4d 45 4e 54 53 29 20 26 26 20 64 65 66 69 OMMENTS) && defi
3500: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
3510: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
3520: 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e E_ENABLE_EXPLAIN
3530: 5f 43 4f 4d 4d 45 4e 54 53 20 31 0a 23 65 6e 64 _COMMENTS 1.#end
3540: 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 74 65 if../*.** The te
3550: 73 74 63 61 73 65 28 29 20 6d 61 63 72 6f 20 69 stcase() macro i
3560: 73 20 75 73 65 64 20 74 6f 20 61 69 64 20 69 6e s used to aid in
3570: 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 6e coverage testin
3580: 67 2e 20 20 57 68 65 6e 0a 2a 2a 20 64 6f 69 6e g. When.** doin
3590: 67 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 g coverage testi
35a0: 6e 67 2c 20 74 68 65 20 63 6f 6e 64 69 74 69 6f ng, the conditio
35b0: 6e 20 69 6e 73 69 64 65 20 74 68 65 20 61 72 67 n inside the arg
35c0: 75 6d 65 6e 74 20 74 6f 0a 2a 2a 20 74 65 73 74 ument to.** test
35d0: 63 61 73 65 28 29 20 6d 75 73 74 20 62 65 20 65 case() must be e
35e0: 76 61 6c 75 61 74 65 64 20 62 6f 74 68 20 74 72 valuated both tr
35f0: 75 65 20 61 6e 64 20 66 61 6c 73 65 20 69 6e 20 ue and false in
3600: 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 65 74 20 order to.** get
3610: 66 75 6c 6c 20 62 72 61 6e 63 68 20 63 6f 76 65 full branch cove
3620: 72 61 67 65 2e 20 20 54 68 65 20 74 65 73 74 63 rage. The testc
3630: 61 73 65 28 29 20 6d 61 63 72 6f 20 69 73 20 69 ase() macro is i
3640: 6e 73 65 72 74 65 64 0a 2a 2a 20 74 6f 20 68 65 nserted.** to he
3650: 6c 70 20 65 6e 73 75 72 65 20 61 64 65 71 75 61 lp ensure adequa
3660: 74 65 20 74 65 73 74 20 63 6f 76 65 72 61 67 65 te test coverage
3670: 20 69 6e 20 70 6c 61 63 65 73 20 77 68 65 72 65 in places where
3680: 20 73 69 6d 70 6c 65 0a 2a 2a 20 63 6f 6e 64 69 simple.** condi
3690: 74 69 6f 6e 2f 64 65 63 69 73 69 6f 6e 20 63 6f tion/decision co
36a0: 76 65 72 61 67 65 20 69 73 20 69 6e 61 64 65 71 verage is inadeq
36b0: 75 61 74 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 uate. For examp
36c0: 6c 65 2c 20 74 65 73 74 63 61 73 65 28 29 0a 2a le, testcase().*
36d0: 2a 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f * can be used to
36e0: 20 6d 61 6b 65 20 73 75 72 65 20 62 6f 75 6e 64 make sure bound
36f0: 61 72 79 20 76 61 6c 75 65 73 20 61 72 65 20 74 ary values are t
3700: 65 73 74 65 64 2e 20 20 46 6f 72 0a 2a 2a 20 62 ested. For.** b
3710: 69 74 6d 61 73 6b 20 74 65 73 74 73 2c 20 74 65 itmask tests, te
3720: 73 74 63 61 73 65 28 29 20 63 61 6e 20 62 65 20 stcase() can be
3730: 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 73 75 72 used to make sur
3740: 65 20 65 61 63 68 20 62 69 74 0a 2a 2a 20 69 73 e each bit.** is
3750: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 61 6e 64 significant and
3760: 20 75 73 65 64 20 61 74 20 6c 65 61 73 74 20 6f used at least o
3770: 6e 63 65 2e 20 20 4f 6e 20 73 77 69 74 63 68 20 nce. On switch
3780: 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a 20 77 68 statements.** wh
3790: 65 72 65 20 6d 75 6c 74 69 70 6c 65 20 63 61 73 ere multiple cas
37a0: 65 73 20 67 6f 20 74 6f 20 74 68 65 20 73 61 6d es go to the sam
37b0: 65 20 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 2c e block of code,
37c0: 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 testcase().** c
37d0: 61 6e 20 69 6e 73 75 72 65 20 74 68 61 74 20 61 an insure that a
37e0: 6c 6c 20 63 61 73 65 73 20 61 72 65 20 65 76 61 ll cases are eva
37f0: 6c 75 61 74 65 64 2e 0a 2a 2a 0a 2a 2f 0a 23 69 luated..**.*/.#i
3800: 66 64 65 66 20 53 51 4c 49 54 45 5f 43 4f 56 45 fdef SQLITE_COVE
3810: 52 41 47 45 5f 54 45 53 54 0a 20 20 76 6f 69 64 RAGE_TEST. void
3820: 20 73 71 6c 69 74 65 33 43 6f 76 65 72 61 67 65 sqlite3Coverage
3830: 28 69 6e 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 (int);.# define
3840: 74 65 73 74 63 61 73 65 28 58 29 20 20 69 66 28 testcase(X) if(
3850: 20 58 20 29 7b 20 73 71 6c 69 74 65 33 43 6f 76 X ){ sqlite3Cov
3860: 65 72 61 67 65 28 5f 5f 4c 49 4e 45 5f 5f 29 3b erage(__LINE__);
3870: 20 7d 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e }.#else.# defin
3880: 65 20 74 65 73 74 63 61 73 65 28 58 29 0a 23 65 e testcase(X).#e
3890: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
38a0: 54 45 53 54 4f 4e 4c 59 20 6d 61 63 72 6f 20 69 TESTONLY macro i
38b0: 73 20 75 73 65 64 20 74 6f 20 65 6e 63 6c 6f 73 s used to enclos
38c0: 65 20 76 61 72 69 61 62 6c 65 20 64 65 63 6c 61 e variable decla
38d0: 72 61 74 69 6f 6e 73 20 6f 72 0a 2a 2a 20 6f 74 rations or.** ot
38e0: 68 65 72 20 62 69 74 73 20 6f 66 20 63 6f 64 65 her bits of code
38f0: 20 74 68 61 74 20 61 72 65 20 6e 65 65 64 65 64 that are needed
3900: 20 74 6f 20 73 75 70 70 6f 72 74 20 74 68 65 20 to support the
3910: 61 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 77 69 74 arguments.** wit
3920: 68 69 6e 20 74 65 73 74 63 61 73 65 28 29 20 61 hin testcase() a
3930: 6e 64 20 61 73 73 65 72 74 28 29 20 6d 61 63 72 nd assert() macr
3940: 6f 73 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 os..*/.#if !defi
3950: 6e 65 64 28 4e 44 45 42 55 47 29 20 7c 7c 20 64 ned(NDEBUG) || d
3960: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 43 4f efined(SQLITE_CO
3970: 56 45 52 41 47 45 5f 54 45 53 54 29 0a 23 20 64 VERAGE_TEST).# d
3980: 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 efine TESTONLY(X
3990: 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 ) X.#else.# def
39a0: 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 29 0a ine TESTONLY(X).
39b0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f #endif../*.** So
39c0: 6d 65 74 69 6d 65 73 20 77 65 20 6e 65 65 64 20 metimes we need
39d0: 61 20 73 6d 61 6c 6c 20 61 6d 6f 75 6e 74 20 6f a small amount o
39e0: 66 20 63 6f 64 65 20 73 75 63 68 20 61 73 20 61 f code such as a
39f0: 20 76 61 72 69 61 62 6c 65 20 69 6e 69 74 69 61 variable initia
3a00: 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 74 6f 20 73 lization.** to s
3a10: 65 74 75 70 20 66 6f 72 20 61 20 6c 61 74 65 72 etup for a later
3a20: 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d assert() statem
3a30: 65 6e 74 2e 20 20 57 65 20 64 6f 20 6e 6f 74 20 ent. We do not
3a40: 77 61 6e 74 20 74 68 69 73 20 63 6f 64 65 20 74 want this code t
3a50: 6f 0a 2a 2a 20 61 70 70 65 61 72 20 77 68 65 6e o.** appear when
3a60: 20 61 73 73 65 72 74 28 29 20 69 73 20 64 69 73 assert() is dis
3a70: 61 62 6c 65 64 2e 20 20 54 68 65 20 66 6f 6c 6c abled. The foll
3a80: 6f 77 69 6e 67 20 6d 61 63 72 6f 20 69 73 20 74 owing macro is t
3a90: 68 65 72 65 66 6f 72 65 0a 2a 2a 20 75 73 65 64 herefore.** used
3aa0: 20 74 6f 20 63 6f 6e 74 61 69 6e 20 74 68 61 74 to contain that
3ab0: 20 73 65 74 75 70 20 63 6f 64 65 2e 20 20 54 68 setup code. Th
3ac0: 65 20 22 56 56 41 22 20 61 63 72 6f 6e 79 6d 20 e "VVA" acronym
3ad0: 73 74 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 56 stands for.** "V
3ae0: 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 56 61 6c erification, Val
3af0: 69 64 61 74 69 6f 6e 2c 20 61 6e 64 20 41 63 63 idation, and Acc
3b00: 72 65 64 69 74 61 74 69 6f 6e 22 2e 20 20 49 6e reditation". In
3b10: 20 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 74 68 other words, th
3b20: 65 0a 2a 2a 20 63 6f 64 65 20 77 69 74 68 69 6e e.** code within
3b30: 20 56 56 41 5f 4f 4e 4c 59 28 29 20 77 69 6c 6c VVA_ONLY() will
3b40: 20 6f 6e 6c 79 20 72 75 6e 20 64 75 72 69 6e 67 only run during
3b50: 20 76 65 72 69 66 69 63 61 74 69 6f 6e 20 70 72 verification pr
3b60: 6f 63 65 73 73 65 73 2e 0a 2a 2f 0a 23 69 66 6e ocesses..*/.#ifn
3b70: 64 65 66 20 4e 44 45 42 55 47 0a 23 20 64 65 66 def NDEBUG.# def
3b80: 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 20 ine VVA_ONLY(X)
3b90: 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e X.#else.# defin
3ba0: 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 0a 23 65 e VVA_ONLY(X).#e
3bb0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
3bc0: 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 45 52 ALWAYS and NEVER
3bd0: 20 6d 61 63 72 6f 73 20 73 75 72 72 6f 75 6e 64 macros surround
3be0: 20 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 boolean express
3bf0: 69 6f 6e 73 20 77 68 69 63 68 0a 2a 2a 20 61 72 ions which.** ar
3c00: 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 61 6c e intended to al
3c10: 77 61 79 73 20 62 65 20 74 72 75 65 20 6f 72 20 ways be true or
3c20: 66 61 6c 73 65 2c 20 72 65 73 70 65 63 74 69 76 false, respectiv
3c30: 65 6c 79 2e 20 20 53 75 63 68 0a 2a 2a 20 65 78 ely. Such.** ex
3c40: 70 72 65 73 73 69 6f 6e 73 20 63 6f 75 6c 64 20 pressions could
3c50: 62 65 20 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 be omitted from
3c60: 74 68 65 20 63 6f 64 65 20 63 6f 6d 70 6c 65 74 the code complet
3c70: 65 6c 79 2e 20 20 42 75 74 20 74 68 65 79 0a 2a ely. But they.*
3c80: 2a 20 61 72 65 20 69 6e 63 6c 75 64 65 64 20 69 * are included i
3c90: 6e 20 61 20 66 65 77 20 63 61 73 65 73 20 69 6e n a few cases in
3ca0: 20 6f 72 64 65 72 20 74 6f 20 65 6e 68 61 6e 63 order to enhanc
3cb0: 65 20 74 68 65 20 72 65 73 69 6c 69 65 6e 63 65 e the resilience
3cc0: 0a 2a 2a 20 6f 66 20 53 51 4c 69 74 65 20 74 6f .** of SQLite to
3cd0: 20 75 6e 65 78 70 65 63 74 65 64 20 62 65 68 61 unexpected beha
3ce0: 76 69 6f 72 20 2d 20 74 6f 20 6d 61 6b 65 20 74 vior - to make t
3cf0: 68 65 20 63 6f 64 65 20 22 73 65 6c 66 2d 68 65 he code "self-he
3d00: 61 6c 69 6e 67 22 0a 2a 2a 20 6f 72 20 22 64 75 aling".** or "du
3d10: 63 74 69 6c 65 22 20 72 61 74 68 65 72 20 74 68 ctile" rather th
3d20: 61 6e 20 62 65 69 6e 67 20 22 62 72 69 74 74 6c an being "brittl
3d30: 65 22 20 61 6e 64 20 63 72 61 73 68 69 6e 67 20 e" and crashing
3d40: 61 74 20 74 68 65 20 66 69 72 73 74 0a 2a 2a 20 at the first.**
3d50: 68 69 6e 74 20 6f 66 20 75 6e 70 6c 61 6e 6e 65 hint of unplanne
3d60: 64 20 62 65 68 61 76 69 6f 72 2e 0a 2a 2a 0a 2a d behavior..**.*
3d70: 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 * In other words
3d80: 2c 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 , ALWAYS and NEV
3d90: 45 52 20 61 72 65 20 61 64 64 65 64 20 66 6f 72 ER are added for
3da0: 20 64 65 66 65 6e 73 69 76 65 20 63 6f 64 65 2e defensive code.
3db0: 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 64 6f 69 6e .**.** When doin
3dc0: 67 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 g coverage testi
3dd0: 6e 67 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 ng ALWAYS and NE
3de0: 56 45 52 20 61 72 65 20 68 61 72 64 2d 63 6f 64 VER are hard-cod
3df0: 65 64 20 74 6f 0a 2a 2a 20 62 65 20 74 72 75 65 ed to.** be true
3e00: 20 61 6e 64 20 66 61 6c 73 65 20 73 6f 20 74 68 and false so th
3e10: 61 74 20 74 68 65 20 75 6e 72 65 61 63 68 61 62 at the unreachab
3e20: 6c 65 20 63 6f 64 65 20 74 68 65 79 20 73 70 65 le code they spe
3e30: 63 69 66 79 20 77 69 6c 6c 0a 2a 2a 20 6e 6f 74 cify will.** not
3e40: 20 62 65 20 63 6f 75 6e 74 65 64 20 61 73 20 75 be counted as u
3e50: 6e 74 65 73 74 65 64 20 63 6f 64 65 2e 0a 2a 2f ntested code..*/
3e60: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c .#if defined(SQL
3e70: 49 54 45 5f 43 4f 56 45 52 41 47 45 5f 54 45 53 ITE_COVERAGE_TES
3e80: 54 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 T) || defined(SQ
3e90: 4c 49 54 45 5f 4d 55 54 41 54 49 4f 4e 5f 54 45 LITE_MUTATION_TE
3ea0: 53 54 29 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 ST).# define ALW
3eb0: 41 59 53 28 58 29 20 20 20 20 20 20 28 31 29 0a AYS(X) (1).
3ec0: 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 58 # define NEVER(X
3ed0: 29 20 20 20 20 20 20 20 28 30 29 0a 23 65 6c 69 ) (0).#eli
3ee0: 66 20 21 64 65 66 69 6e 65 64 28 4e 44 45 42 55 f !defined(NDEBU
3ef0: 47 29 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 41 G).# define ALWA
3f00: 59 53 28 58 29 20 20 20 20 20 20 28 28 58 29 3f YS(X) ((X)?
3f10: 31 3a 28 61 73 73 65 72 74 28 30 29 2c 30 29 29 1:(assert(0),0))
3f20: 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 .# define NEVER(
3f30: 58 29 20 20 20 20 20 20 20 28 28 58 29 3f 28 61 X) ((X)?(a
3f40: 73 73 65 72 74 28 30 29 2c 31 29 3a 30 29 0a 23 ssert(0),1):0).#
3f50: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 41 4c else.# define AL
3f60: 57 41 59 53 28 58 29 20 20 20 20 20 20 28 58 29 WAYS(X) (X)
3f70: 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 .# define NEVER(
3f80: 58 29 20 20 20 20 20 20 20 28 58 29 0a 23 65 6e X) (X).#en
3f90: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f 6d 65 20 dif../*.** Some
3fa0: 63 6f 6e 64 69 74 69 6f 6e 61 6c 73 20 61 72 65 conditionals are
3fb0: 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 6f optimizations o
3fc0: 6e 6c 79 2e 20 20 49 6e 20 6f 74 68 65 72 20 77 nly. In other w
3fd0: 6f 72 64 73 2c 20 69 66 20 74 68 65 0a 2a 2a 20 ords, if the.**
3fe0: 63 6f 6e 64 69 74 69 6f 6e 61 6c 73 20 61 72 65 conditionals are
3ff0: 20 72 65 70 6c 61 63 65 64 20 77 69 74 68 20 61 replaced with a
4000: 20 63 6f 6e 73 74 61 6e 74 20 31 20 28 74 72 75 constant 1 (tru
4010: 65 29 20 6f 72 20 30 20 28 66 61 6c 73 65 29 20 e) or 0 (false)
4020: 74 68 65 6e 0a 2a 2a 20 74 68 65 20 63 6f 72 72 then.** the corr
4030: 65 63 74 20 61 6e 73 77 65 72 20 69 73 20 73 74 ect answer is st
4040: 69 6c 6c 20 6f 62 74 61 69 6e 65 64 2c 20 74 68 ill obtained, th
4050: 6f 75 67 68 20 70 65 72 68 61 70 73 20 6e 6f 74 ough perhaps not
4060: 20 61 73 20 71 75 69 63 6b 6c 79 2e 0a 2a 2a 0a as quickly..**.
4070: 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ** The following
4080: 20 6d 61 63 72 6f 73 20 6d 61 72 6b 20 74 68 65 macros mark the
4090: 73 65 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 se optimizations
40a0: 20 63 6f 6e 64 69 74 69 6f 6e 61 6c 73 2e 0a 2a conditionals..*
40b0: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 /.#if defined(SQ
40c0: 4c 49 54 45 5f 4d 55 54 41 54 49 4f 4e 5f 54 45 LITE_MUTATION_TE
40d0: 53 54 29 0a 23 20 64 65 66 69 6e 65 20 4f 4b 5f ST).# define OK_
40e0: 49 46 5f 41 4c 57 41 59 53 5f 54 52 55 45 28 58 IF_ALWAYS_TRUE(X
40f0: 29 20 20 28 31 29 0a 23 20 64 65 66 69 6e 65 20 ) (1).# define
4100: 4f 4b 5f 49 46 5f 41 4c 57 41 59 53 5f 46 41 4c OK_IF_ALWAYS_FAL
4110: 53 45 28 58 29 20 28 30 29 0a 23 65 6c 73 65 0a SE(X) (0).#else.
4120: 23 20 64 65 66 69 6e 65 20 4f 4b 5f 49 46 5f 41 # define OK_IF_A
4130: 4c 57 41 59 53 5f 54 52 55 45 28 58 29 20 20 28 LWAYS_TRUE(X) (
4140: 58 29 0a 23 20 64 65 66 69 6e 65 20 4f 4b 5f 49 X).# define OK_I
4150: 46 5f 41 4c 57 41 59 53 5f 46 41 4c 53 45 28 58 F_ALWAYS_FALSE(X
4160: 29 20 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a ) (X).#endif../*
4170: 0a 2a 2a 20 53 6f 6d 65 20 6d 61 6c 6c 6f 63 20 .** Some malloc
4180: 66 61 69 6c 75 72 65 73 20 61 72 65 20 6f 6e 6c failures are onl
4190: 79 20 70 6f 73 73 69 62 6c 65 20 69 66 20 53 51 y possible if SQ
41a0: 4c 49 54 45 5f 54 45 53 54 5f 52 45 41 4c 4c 4f LITE_TEST_REALLO
41b0: 43 5f 53 54 52 45 53 53 20 69 73 0a 2a 2a 20 64 C_STRESS is.** d
41c0: 65 66 69 6e 65 64 2e 20 20 57 65 20 6e 65 65 64 efined. We need
41d0: 20 74 6f 20 64 65 66 65 6e 64 20 61 67 61 69 6e to defend again
41e0: 73 74 20 74 68 6f 73 65 20 66 61 69 6c 75 72 65 st those failure
41f0: 73 20 77 68 65 6e 20 74 65 73 74 69 6e 67 20 77 s when testing w
4200: 69 74 68 0a 2a 2a 20 53 51 4c 49 54 45 5f 54 45 ith.** SQLITE_TE
4210: 53 54 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 53 ST_REALLOC_STRES
4220: 53 2c 20 62 75 74 20 77 65 20 64 6f 6e 27 74 20 S, but we don't
4230: 77 61 6e 74 20 74 68 65 20 75 6e 72 65 61 63 68 want the unreach
4240: 61 62 6c 65 20 62 72 61 6e 63 68 65 73 0a 2a 2a able branches.**
4250: 20 64 75 72 69 6e 67 20 61 20 6e 6f 72 6d 61 6c during a normal
4260: 20 62 75 69 6c 64 2e 20 20 54 68 65 20 66 6f 6c build. The fol
4270: 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 20 63 61 6e lowing macro can
4280: 20 62 65 20 75 73 65 64 20 74 6f 20 64 69 73 61 be used to disa
4290: 62 6c 65 20 74 65 73 74 73 0a 2a 2a 20 74 68 61 ble tests.** tha
42a0: 74 20 61 72 65 20 61 6c 77 61 79 73 20 66 61 6c t are always fal
42b0: 73 65 20 65 78 63 65 70 74 20 77 68 65 6e 20 53 se except when S
42c0: 51 4c 49 54 45 5f 54 45 53 54 5f 52 45 41 4c 4c QLITE_TEST_REALL
42d0: 4f 43 5f 53 54 52 45 53 53 20 69 73 20 73 65 74 OC_STRESS is set
42e0: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
42f0: 28 53 51 4c 49 54 45 5f 54 45 53 54 5f 52 45 41 (SQLITE_TEST_REA
4300: 4c 4c 4f 43 5f 53 54 52 45 53 53 29 0a 23 20 64 LLOC_STRESS).# d
4310: 65 66 69 6e 65 20 4f 4e 4c 59 5f 49 46 5f 52 45 efine ONLY_IF_RE
4320: 41 4c 4c 4f 43 5f 53 54 52 45 53 53 28 58 29 20 ALLOC_STRESS(X)
4330: 20 28 58 29 0a 23 65 6c 69 66 20 21 64 65 66 69 (X).#elif !defi
4340: 6e 65 64 28 4e 44 45 42 55 47 29 0a 23 20 64 65 ned(NDEBUG).# de
4350: 66 69 6e 65 20 4f 4e 4c 59 5f 49 46 5f 52 45 41 fine ONLY_IF_REA
4360: 4c 4c 4f 43 5f 53 54 52 45 53 53 28 58 29 20 20 LLOC_STRESS(X)
4370: 28 28 58 29 3f 28 61 73 73 65 72 74 28 30 29 2c ((X)?(assert(0),
4380: 31 29 3a 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 1):0).#else.# de
4390: 66 69 6e 65 20 4f 4e 4c 59 5f 49 46 5f 52 45 41 fine ONLY_IF_REA
43a0: 4c 4c 4f 43 5f 53 54 52 45 53 53 28 58 29 20 20 LLOC_STRESS(X)
43b0: 28 30 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a (0).#endif../*.*
43c0: 2a 20 44 65 63 6c 61 72 61 74 69 6f 6e 73 20 75 * Declarations u
43d0: 73 65 64 20 66 6f 72 20 74 72 61 63 69 6e 67 20 sed for tracing
43e0: 74 68 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 the operating sy
43f0: 73 74 65 6d 20 69 6e 74 65 72 66 61 63 65 73 2e stem interfaces.
4400: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
4410: 53 51 4c 49 54 45 5f 46 4f 52 43 45 5f 4f 53 5f SQLITE_FORCE_OS_
4420: 54 52 41 43 45 29 20 7c 7c 20 64 65 66 69 6e 65 TRACE) || define
4430: 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 20 7c d(SQLITE_TEST) |
4440: 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 64 | \. (defined
4450: 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 20 26 (SQLITE_DEBUG) &
4460: 26 20 53 51 4c 49 54 45 5f 4f 53 5f 57 49 4e 29 & SQLITE_OS_WIN)
4470: 0a 20 20 65 78 74 65 72 6e 20 69 6e 74 20 73 71 . extern int sq
4480: 6c 69 74 65 33 4f 53 54 72 61 63 65 3b 0a 23 20 lite3OSTrace;.#
4490: 64 65 66 69 6e 65 20 4f 53 54 52 41 43 45 28 58 define OSTRACE(X
44a0: 29 20 20 20 20 20 20 20 20 20 20 69 66 28 20 73 ) if( s
44b0: 71 6c 69 74 65 33 4f 53 54 72 61 63 65 20 29 20 qlite3OSTrace )
44c0: 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 69 6e sqlite3DebugPrin
44d0: 74 66 20 58 0a 23 20 64 65 66 69 6e 65 20 53 51 tf X.# define SQ
44e0: 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 LITE_HAVE_OS_TRA
44f0: 43 45 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e CE.#else.# defin
4500: 65 20 4f 53 54 52 41 43 45 28 58 29 0a 23 20 75 e OSTRACE(X).# u
4510: 6e 64 65 66 20 20 53 51 4c 49 54 45 5f 48 41 56 ndef SQLITE_HAV
4520: 45 5f 4f 53 5f 54 52 41 43 45 0a 23 65 6e 64 69 E_OS_TRACE.#endi
4530: 66 0a 0a 2f 2a 0a 2a 2a 20 49 73 20 74 68 65 20 f../*.** Is the
4540: 73 71 6c 69 74 65 33 45 72 72 4e 61 6d 65 28 29 sqlite3ErrName()
4550: 20 66 75 6e 63 74 69 6f 6e 20 6e 65 65 64 65 64 function needed
4560: 20 69 6e 20 74 68 65 20 62 75 69 6c 64 3f 20 20 in the build?
4570: 43 75 72 72 65 6e 74 6c 79 2c 0a 2a 2a 20 69 74 Currently,.** it
4580: 20 69 73 20 6e 65 65 64 65 64 20 62 79 20 22 6d is needed by "m
4590: 75 74 65 78 5f 77 33 32 2e 63 22 20 28 77 68 65 utex_w32.c" (whe
45a0: 6e 20 64 65 62 75 67 67 69 6e 67 29 2c 20 22 6f n debugging), "o
45b0: 73 5f 77 69 6e 2e 63 22 20 28 77 68 65 6e 0a 2a s_win.c" (when.*
45c0: 2a 20 4f 53 54 52 41 43 45 20 69 73 20 65 6e 61 * OSTRACE is ena
45d0: 62 6c 65 64 29 2c 20 61 6e 64 20 62 79 20 73 65 bled), and by se
45e0: 76 65 72 61 6c 20 22 74 65 73 74 2a 2e 63 22 20 veral "test*.c"
45f0: 66 69 6c 65 73 20 28 77 68 69 63 68 20 61 72 65 files (which are
4600: 0a 2a 2a 20 63 6f 6d 70 69 6c 65 64 20 75 73 69 .** compiled usi
4610: 6e 67 20 53 51 4c 49 54 45 5f 54 45 53 54 29 2e ng SQLITE_TEST).
4620: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
4630: 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 SQLITE_HAVE_OS_T
4640: 52 41 43 45 29 20 7c 7c 20 64 65 66 69 6e 65 64 RACE) || defined
4650: 28 53 51 4c 49 54 45 5f 54 45 53 54 29 20 7c 7c (SQLITE_TEST) ||
4660: 20 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 64 28 \. (defined(
4670: 53 51 4c 49 54 45 5f 44 45 42 55 47 29 20 26 26 SQLITE_DEBUG) &&
4680: 20 53 51 4c 49 54 45 5f 4f 53 5f 57 49 4e 29 0a SQLITE_OS_WIN).
4690: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
46a0: 4e 45 45 44 5f 45 52 52 5f 4e 41 4d 45 0a 23 65 NEED_ERR_NAME.#e
46b0: 6c 73 65 0a 23 20 75 6e 64 65 66 20 20 53 51 4c lse.# undef SQL
46c0: 49 54 45 5f 4e 45 45 44 5f 45 52 52 5f 4e 41 4d ITE_NEED_ERR_NAM
46d0: 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 E.#endif../*.**
46e0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 45 58 SQLITE_ENABLE_EX
46f0: 50 4c 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 20 69 PLAIN_COMMENTS i
4700: 73 20 69 6e 63 6f 6d 70 61 74 69 62 6c 65 20 77 s incompatible w
4710: 69 74 68 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ith SQLITE_OMIT_
4720: 45 58 50 4c 41 49 4e 0a 2a 2f 0a 23 69 66 64 65 EXPLAIN.*/.#ifde
4730: 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 45 58 f SQLITE_OMIT_EX
4740: 50 4c 41 49 4e 0a 23 20 75 6e 64 65 66 20 53 51 PLAIN.# undef SQ
4750: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c LITE_ENABLE_EXPL
4760: 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 0a 23 65 6e AIN_COMMENTS.#en
4770: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 dif../*.** Retur
4780: 6e 20 74 72 75 65 20 28 6e 6f 6e 2d 7a 65 72 6f n true (non-zero
4790: 29 20 69 66 20 74 68 65 20 69 6e 70 75 74 20 69 ) if the input i
47a0: 73 20 61 6e 20 69 6e 74 65 67 65 72 20 74 68 61 s an integer tha
47b0: 74 20 69 73 20 74 6f 6f 20 6c 61 72 67 65 0a 2a t is too large.*
47c0: 2a 20 74 6f 20 66 69 74 20 69 6e 20 33 32 2d 62 * to fit in 32-b
47d0: 69 74 73 2e 20 20 54 68 69 73 20 6d 61 63 72 6f its. This macro
47e0: 20 69 73 20 75 73 65 64 20 69 6e 73 69 64 65 20 is used inside
47f0: 6f 66 20 76 61 72 69 6f 75 73 20 74 65 73 74 63 of various testc
4800: 61 73 65 28 29 0a 2a 2a 20 6d 61 63 72 6f 73 20 ase().** macros
4810: 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 77 to verify that w
4820: 65 20 68 61 76 65 20 74 65 73 74 65 64 20 53 51 e have tested SQ
4830: 4c 69 74 65 20 66 6f 72 20 6c 61 72 67 65 2d 66 Lite for large-f
4840: 69 6c 65 20 73 75 70 70 6f 72 74 2e 0a 2a 2f 0a ile support..*/.
4850: 23 64 65 66 69 6e 65 20 49 53 5f 42 49 47 5f 49 #define IS_BIG_I
4860: 4e 54 28 58 29 20 20 28 28 28 58 29 26 7e 28 69 NT(X) (((X)&~(i
4870: 36 34 29 30 78 66 66 66 66 66 66 66 66 29 21 3d 64)0xffffffff)!=
4880: 30 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6d 61 0)../*.** The ma
4890: 63 72 6f 20 75 6e 6c 69 6b 65 6c 79 28 29 20 69 cro unlikely() i
48a0: 73 20 61 20 68 69 6e 74 20 74 68 61 74 20 73 75 s a hint that su
48b0: 72 72 6f 75 6e 64 73 20 61 20 62 6f 6f 6c 65 61 rrounds a boolea
48c0: 6e 0a 2a 2a 20 65 78 70 72 65 73 73 69 6f 6e 20 n.** expression
48d0: 74 68 61 74 20 69 73 20 75 73 75 61 6c 6c 79 20 that is usually
48e0: 66 61 6c 73 65 2e 20 20 4d 61 63 72 6f 20 6c 69 false. Macro li
48f0: 6b 65 6c 79 28 29 20 73 75 72 72 6f 75 6e 64 73 kely() surrounds
4900: 0a 2a 2a 20 61 20 62 6f 6f 6c 65 61 6e 20 65 78 .** a boolean ex
4910: 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 pression that is
4920: 20 75 73 75 61 6c 6c 79 20 74 72 75 65 2e 20 20 usually true.
4930: 54 68 65 73 65 20 68 69 6e 74 73 20 63 6f 75 6c These hints coul
4940: 64 2c 0a 2a 2a 20 69 6e 20 74 68 65 6f 72 79 2c d,.** in theory,
4950: 20 62 65 20 75 73 65 64 20 62 79 20 74 68 65 20 be used by the
4960: 63 6f 6d 70 69 6c 65 72 20 74 6f 20 67 65 6e 65 compiler to gene
4970: 72 61 74 65 20 62 65 74 74 65 72 20 63 6f 64 65 rate better code
4980: 2c 20 62 75 74 0a 2a 2a 20 63 75 72 72 65 6e 74 , but.** current
4990: 6c 79 20 74 68 65 79 20 61 72 65 20 6a 75 73 74 ly they are just
49a0: 20 63 6f 6d 6d 65 6e 74 73 20 66 6f 72 20 68 75 comments for hu
49b0: 6d 61 6e 20 72 65 61 64 65 72 73 2e 0a 2a 2f 0a man readers..*/.
49c0: 23 64 65 66 69 6e 65 20 6c 69 6b 65 6c 79 28 58 #define likely(X
49d0: 29 20 20 20 20 28 58 29 0a 23 64 65 66 69 6e 65 ) (X).#define
49e0: 20 75 6e 6c 69 6b 65 6c 79 28 58 29 20 20 28 58 unlikely(X) (X
49f0: 29 0a 0a 23 69 6e 63 6c 75 64 65 20 22 68 61 73 )..#include "has
4a00: 68 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 h.h".#include "p
4a10: 61 72 73 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 arse.h".#include
4a20: 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c <stdio.h>.#incl
4a30: 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 ude <stdlib.h>.#
4a40: 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67 2e include <string.
4a50: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 73 h>.#include <ass
4a60: 65 72 74 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 ert.h>.#include
4a70: 3c 73 74 64 64 65 66 2e 68 3e 0a 0a 2f 2a 0a 2a <stddef.h>../*.*
4a80: 2a 20 55 73 65 20 61 20 6d 61 63 72 6f 20 74 6f * Use a macro to
4a90: 20 72 65 70 6c 61 63 65 20 6d 65 6d 63 70 79 28 replace memcpy(
4aa0: 29 20 69 66 20 63 6f 6d 70 69 6c 65 64 20 77 69 ) if compiled wi
4ab0: 74 68 20 53 51 4c 49 54 45 5f 49 4e 4c 49 4e 45 th SQLITE_INLINE
4ac0: 5f 4d 45 4d 43 50 59 2e 0a 2a 2a 20 54 68 69 73 _MEMCPY..** This
4ad0: 20 61 6c 6c 6f 77 73 20 62 65 74 74 65 72 20 6d allows better m
4ae0: 65 61 73 75 72 65 6d 65 6e 74 73 20 6f 66 20 77 easurements of w
4af0: 68 65 72 65 20 6d 65 6d 63 70 79 28 29 20 69 73 here memcpy() is
4b00: 20 75 73 65 64 20 77 68 65 6e 20 72 75 6e 6e 69 used when runni
4b10: 6e 67 0a 2a 2a 20 63 61 63 68 65 67 72 69 6e 64 ng.** cachegrind
4b20: 2e 20 20 42 75 74 20 74 68 69 73 20 6d 61 63 72 . But this macr
4b30: 6f 20 76 65 72 73 69 6f 6e 20 6f 66 20 6d 65 6d o version of mem
4b40: 63 70 79 28 29 20 69 73 20 76 65 72 79 20 73 6c cpy() is very sl
4b50: 6f 77 20 73 6f 20 69 74 0a 2a 2a 20 73 68 6f 75 ow so it.** shou
4b60: 6c 64 20 6e 6f 74 20 62 65 20 75 73 65 64 20 69 ld not be used i
4b70: 6e 20 70 72 6f 64 75 63 74 69 6f 6e 2e 20 20 54 n production. T
4b80: 68 69 73 20 69 73 20 61 20 70 65 72 66 6f 72 6d his is a perform
4b90: 61 6e 63 65 20 6d 65 61 73 75 72 65 6d 65 6e 74 ance measurement
4ba0: 0a 2a 2a 20 68 61 63 6b 20 6f 6e 6c 79 2e 0a 2a .** hack only..*
4bb0: 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
4bc0: 49 4e 4c 49 4e 45 5f 4d 45 4d 43 50 59 0a 23 20 INLINE_MEMCPY.#
4bd0: 64 65 66 69 6e 65 20 6d 65 6d 63 70 79 28 44 2c define memcpy(D,
4be0: 53 2c 4e 29 20 7b 63 68 61 72 2a 78 78 64 3d 28 S,N) {char*xxd=(
4bf0: 63 68 61 72 2a 29 28 44 29 3b 63 6f 6e 73 74 20 char*)(D);const
4c00: 63 68 61 72 2a 78 78 73 3d 28 63 6f 6e 73 74 20 char*xxs=(const
4c10: 63 68 61 72 2a 29 28 53 29 3b 5c 0a 20 20 20 20 char*)(S);\.
4c20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4c30: 20 20 20 20 69 6e 74 20 78 78 6e 3d 28 4e 29 3b int xxn=(N);
4c40: 77 68 69 6c 65 28 78 78 6e 2d 2d 3e 30 29 2a 28 while(xxn-->0)*(
4c50: 78 78 64 2b 2b 29 3d 2a 28 78 78 73 2b 2b 29 3b xxd++)=*(xxs++);
4c60: 7d 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 }.#endif../*.**
4c70: 49 66 20 63 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 If compiling for
4c80: 20 61 20 70 72 6f 63 65 73 73 6f 72 20 74 68 61 a processor tha
4c90: 74 20 6c 61 63 6b 73 20 66 6c 6f 61 74 69 6e 67 t lacks floating
4ca0: 20 70 6f 69 6e 74 20 73 75 70 70 6f 72 74 2c 0a point support,.
4cb0: 2a 2a 20 73 75 62 73 74 69 74 75 74 65 20 69 6e ** substitute in
4cc0: 74 65 67 65 72 20 66 6f 72 20 66 6c 6f 61 74 69 teger for floati
4cd0: 6e 67 2d 70 6f 69 6e 74 0a 2a 2f 0a 23 69 66 64 ng-point.*/.#ifd
4ce0: 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 ef SQLITE_OMIT_F
4cf0: 4c 4f 41 54 49 4e 47 5f 50 4f 49 4e 54 0a 23 20 LOATING_POINT.#
4d00: 64 65 66 69 6e 65 20 64 6f 75 62 6c 65 20 73 71 define double sq
4d10: 6c 69 74 65 5f 69 6e 74 36 34 0a 23 20 64 65 66 lite_int64.# def
4d20: 69 6e 65 20 66 6c 6f 61 74 20 73 71 6c 69 74 65 ine float sqlite
4d30: 5f 69 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 20 _int64.# define
4d40: 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 LONGDOUBLE_TYPE
4d50: 73 71 6c 69 74 65 5f 69 6e 74 36 34 0a 23 20 69 sqlite_int64.# i
4d60: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 42 49 47 fndef SQLITE_BIG
4d70: 5f 44 42 4c 0a 23 20 20 20 64 65 66 69 6e 65 20 _DBL.# define
4d80: 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 20 28 SQLITE_BIG_DBL (
4d90: 28 28 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 29 ((sqlite3_int64)
4da0: 31 29 3c 3c 35 30 29 0a 23 20 65 6e 64 69 66 0a 1)<<50).# endif.
4db0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
4dc0: 4f 4d 49 54 5f 44 41 54 45 54 49 4d 45 5f 46 55 OMIT_DATETIME_FU
4dd0: 4e 43 53 20 31 0a 23 20 64 65 66 69 6e 65 20 53 NCS 1.# define S
4de0: 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 41 43 45 QLITE_OMIT_TRACE
4df0: 20 31 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 1.# undef SQLIT
4e00: 45 5f 4d 49 58 45 44 5f 45 4e 44 49 41 4e 5f 36 E_MIXED_ENDIAN_6
4e10: 34 42 49 54 5f 46 4c 4f 41 54 0a 23 20 75 6e 64 4BIT_FLOAT.# und
4e20: 65 66 20 53 51 4c 49 54 45 5f 48 41 56 45 5f 49 ef SQLITE_HAVE_I
4e30: 53 4e 41 4e 0a 23 65 6e 64 69 66 0a 23 69 66 6e SNAN.#endif.#ifn
4e40: 64 65 66 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 def SQLITE_BIG_D
4e50: 42 4c 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 BL.# define SQLI
4e60: 54 45 5f 42 49 47 5f 44 42 4c 20 28 31 65 39 39 TE_BIG_DBL (1e99
4e70: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
4e80: 4f 4d 49 54 5f 54 45 4d 50 44 42 20 69 73 20 73 OMIT_TEMPDB is s
4e90: 65 74 20 74 6f 20 31 20 69 66 20 53 51 4c 49 54 et to 1 if SQLIT
4ea0: 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 20 69 73 E_OMIT_TEMPDB is
4eb0: 20 64 65 66 69 6e 65 64 2c 20 6f 72 20 30 0a 2a defined, or 0.*
4ec0: 2a 20 61 66 74 65 72 77 61 72 64 2e 20 48 61 76 * afterward. Hav
4ed0: 69 6e 67 20 74 68 69 73 20 6d 61 63 72 6f 20 61 ing this macro a
4ee0: 6c 6c 6f 77 73 20 75 73 20 74 6f 20 63 61 75 73 llows us to caus
4ef0: 65 20 74 68 65 20 43 20 63 6f 6d 70 69 6c 65 72 e the C compiler
4f00: 0a 2a 2a 20 74 6f 20 6f 6d 69 74 20 63 6f 64 65 .** to omit code
4f10: 20 75 73 65 64 20 62 79 20 54 45 4d 50 20 74 61 used by TEMP ta
4f20: 62 6c 65 73 20 77 69 74 68 6f 75 74 20 6d 65 73 bles without mes
4f30: 73 79 20 23 69 66 6e 64 65 66 20 73 74 61 74 65 sy #ifndef state
4f40: 6d 65 6e 74 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 ments..*/.#ifdef
4f50: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 45 4d SQLITE_OMIT_TEM
4f60: 50 44 42 0a 23 64 65 66 69 6e 65 20 4f 4d 49 54 PDB.#define OMIT
4f70: 5f 54 45 4d 50 44 42 20 31 0a 23 65 6c 73 65 0a _TEMPDB 1.#else.
4f80: 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d #define OMIT_TEM
4f90: 50 44 42 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a PDB 0.#endif../*
4fa0: 0a 2a 2a 20 54 68 65 20 22 66 69 6c 65 20 66 6f .** The "file fo
4fb0: 72 6d 61 74 22 20 6e 75 6d 62 65 72 20 69 73 20 rmat" number is
4fc0: 61 6e 20 69 6e 74 65 67 65 72 20 74 68 61 74 20 an integer that
4fd0: 69 73 20 69 6e 63 72 65 6d 65 6e 74 65 64 20 77 is incremented w
4fe0: 68 65 6e 65 76 65 72 0a 2a 2a 20 74 68 65 20 56 henever.** the V
4ff0: 44 42 45 2d 6c 65 76 65 6c 20 66 69 6c 65 20 66 DBE-level file f
5000: 6f 72 6d 61 74 20 63 68 61 6e 67 65 73 2e 20 20 ormat changes.
5010: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 The following ma
5020: 63 72 6f 73 20 64 65 66 69 6e 65 20 74 68 65 0a cros define the.
5030: 2a 2a 20 74 68 65 20 64 65 66 61 75 6c 74 20 66 ** the default f
5040: 69 6c 65 20 66 6f 72 6d 61 74 20 66 6f 72 20 6e ile format for n
5050: 65 77 20 64 61 74 61 62 61 73 65 73 20 61 6e 64 ew databases and
5060: 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 66 69 6c the maximum fil
5070: 65 20 66 6f 72 6d 61 74 0a 2a 2a 20 74 68 61 74 e format.** that
5080: 20 74 68 65 20 6c 69 62 72 61 72 79 20 63 61 6e the library can
5090: 20 72 65 61 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e read..*/.#defin
50a0: 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 46 49 4c e SQLITE_MAX_FIL
50b0: 45 5f 46 4f 52 4d 41 54 20 34 0a 23 69 66 6e 64 E_FORMAT 4.#ifnd
50c0: 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ef SQLITE_DEFAUL
50d0: 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 0a 23 20 T_FILE_FORMAT.#
50e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 define SQLITE_DE
50f0: 46 41 55 4c 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 FAULT_FILE_FORMA
5100: 54 20 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a T 4.#endif../*.*
5110: 2a 20 44 65 74 65 72 6d 69 6e 65 20 77 68 65 74 * Determine whet
5120: 68 65 72 20 74 72 69 67 67 65 72 73 20 61 72 65 her triggers are
5130: 20 72 65 63 75 72 73 69 76 65 20 62 79 20 64 65 recursive by de
5140: 66 61 75 6c 74 2e 20 20 54 68 69 73 20 63 61 6e fault. This can
5150: 20 62 65 0a 2a 2a 20 63 68 61 6e 67 65 64 20 61 be.** changed a
5160: 74 20 72 75 6e 2d 74 69 6d 65 20 75 73 69 6e 67 t run-time using
5170: 20 61 20 70 72 61 67 6d 61 2e 0a 2a 2f 0a 23 69 a pragma..*/.#i
5180: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 fndef SQLITE_DEF
5190: 41 55 4c 54 5f 52 45 43 55 52 53 49 56 45 5f 54 AULT_RECURSIVE_T
51a0: 52 49 47 47 45 52 53 0a 23 20 64 65 66 69 6e 65 RIGGERS.# define
51b0: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
51c0: 52 45 43 55 52 53 49 56 45 5f 54 52 49 47 47 45 RECURSIVE_TRIGGE
51d0: 52 53 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a RS 0.#endif../*.
51e0: 2a 2a 20 50 72 6f 76 69 64 65 20 61 20 64 65 66 ** Provide a def
51f0: 61 75 6c 74 20 76 61 6c 75 65 20 66 6f 72 20 53 ault value for S
5200: 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 QLITE_TEMP_STORE
5210: 20 69 6e 20 63 61 73 65 20 69 74 20 69 73 20 6e in case it is n
5220: 6f 74 20 73 70 65 63 69 66 69 65 64 0a 2a 2a 20 ot specified.**
5230: 6f 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c on the command-l
5240: 69 6e 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ine.*/.#ifndef S
5250: 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 QLITE_TEMP_STORE
5260: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
5270: 5f 54 45 4d 50 5f 53 54 4f 52 45 20 31 0a 23 65 _TEMP_STORE 1.#e
5280: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 6e ndif../*.** If n
5290: 6f 20 76 61 6c 75 65 20 68 61 73 20 62 65 65 6e o value has been
52a0: 20 70 72 6f 76 69 64 65 64 20 66 6f 72 20 53 51 provided for SQ
52b0: 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f LITE_MAX_WORKER_
52c0: 54 48 52 45 41 44 53 2c 20 6f 72 20 69 66 0a 2a THREADS, or if.*
52d0: 2a 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 * SQLITE_TEMP_ST
52e0: 4f 52 45 20 69 73 20 73 65 74 20 74 6f 20 33 20 ORE is set to 3
52f0: 28 6e 65 76 65 72 20 75 73 65 20 74 65 6d 70 6f (never use tempo
5300: 72 61 72 79 20 66 69 6c 65 73 29 2c 20 73 65 74 rary files), set
5310: 20 69 74 0a 2a 2a 20 74 6f 20 7a 65 72 6f 2e 0a it.** to zero..
5320: 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 54 45 */.#if SQLITE_TE
5330: 4d 50 5f 53 54 4f 52 45 3d 3d 33 20 7c 7c 20 53 MP_STORE==3 || S
5340: 51 4c 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 QLITE_THREADSAFE
5350: 3d 3d 30 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 ==0.# undef SQLI
5360: 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 TE_MAX_WORKER_TH
5370: 52 45 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 READS.# define S
5380: 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
5390: 5f 54 48 52 45 41 44 53 20 30 0a 23 65 6e 64 69 _THREADS 0.#endi
53a0: 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 f.#ifndef SQLITE
53b0: 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 _MAX_WORKER_THRE
53c0: 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ADS.# define SQL
53d0: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
53e0: 48 52 45 41 44 53 20 38 0a 23 65 6e 64 69 66 0a HREADS 8.#endif.
53f0: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 #ifndef SQLITE_D
5400: 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 EFAULT_WORKER_TH
5410: 52 45 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 READS.# define S
5420: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f QLITE_DEFAULT_WO
5430: 52 4b 45 52 5f 54 48 52 45 41 44 53 20 30 0a 23 RKER_THREADS 0.#
5440: 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 45 endif.#if SQLITE
5450: 5f 44 45 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f _DEFAULT_WORKER_
5460: 54 48 52 45 41 44 53 3e 53 51 4c 49 54 45 5f 4d THREADS>SQLITE_M
5470: 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 AX_WORKER_THREAD
5480: 53 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 S.# undef SQLITE
5490: 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 _MAX_WORKER_THRE
54a0: 41 44 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ADS.# define SQL
54b0: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
54c0: 48 52 45 41 44 53 20 53 51 4c 49 54 45 5f 44 45 HREADS SQLITE_DE
54d0: 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 FAULT_WORKER_THR
54e0: 45 41 44 53 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a EADS.#endif../*.
54f0: 2a 2a 20 54 68 65 20 64 65 66 61 75 6c 74 20 69 ** The default i
5500: 6e 69 74 69 61 6c 20 61 6c 6c 6f 63 61 74 69 6f nitial allocatio
5510: 6e 20 66 6f 72 20 74 68 65 20 70 61 67 65 63 61 n for the pageca
5520: 63 68 65 20 77 68 65 6e 20 75 73 69 6e 67 20 73 che when using s
5530: 65 70 61 72 61 74 65 0a 2a 2a 20 70 61 67 65 63 eparate.** pagec
5540: 61 63 68 65 73 20 66 6f 72 20 65 61 63 68 20 64 aches for each d
5550: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
5560: 6f 6e 2e 20 20 41 20 70 6f 73 69 74 69 76 65 20 on. A positive
5570: 6e 75 6d 62 65 72 20 69 73 20 74 68 65 0a 2a 2a number is the.**
5580: 20 6e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 number of pages
5590: 2e 20 20 41 20 6e 65 67 61 74 69 76 65 20 6e 75 . A negative nu
55a0: 6d 62 65 72 20 4e 20 74 72 61 6e 73 6c 61 74 69 mber N translati
55b0: 6f 6e 73 20 6d 65 61 6e 73 20 74 68 61 74 20 61 ons means that a
55c0: 20 62 75 66 66 65 72 0a 2a 2a 20 6f 66 20 2d 31 buffer.** of -1
55d0: 30 32 34 2a 4e 20 62 79 74 65 73 20 69 73 20 61 024*N bytes is a
55e0: 6c 6c 6f 63 61 74 65 64 20 61 6e 64 20 75 73 65 llocated and use
55f0: 64 20 66 6f 72 20 61 73 20 6d 61 6e 79 20 70 61 d for as many pa
5600: 67 65 73 20 61 73 20 69 74 20 77 69 6c 6c 20 68 ges as it will h
5610: 6f 6c 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 64 old..**.** The d
5620: 65 66 61 75 6c 74 20 76 61 6c 75 65 20 6f 66 20 efault value of
5630: 22 32 30 22 20 77 61 73 20 63 68 6f 6f 73 65 6e "20" was choosen
5640: 20 74 6f 20 6d 69 6e 69 6d 69 7a 65 20 74 68 65 to minimize the
5650: 20 72 75 6e 2d 74 69 6d 65 20 6f 66 20 74 68 65 run-time of the
5660: 0a 2a 2a 20 73 70 65 65 64 74 65 73 74 31 20 74 .** speedtest1 t
5670: 65 73 74 20 70 72 6f 67 72 61 6d 20 77 69 74 68 est program with
5680: 20 6f 70 74 69 6f 6e 73 3a 20 2d 2d 73 68 72 69 options: --shri
5690: 6e 6b 2d 6d 65 6d 6f 72 79 20 2d 2d 72 65 70 72 nk-memory --repr
56a0: 65 70 61 72 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 epare.*/.#ifndef
56b0: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
56c0: 50 43 41 43 48 45 5f 49 4e 49 54 53 5a 0a 23 20 PCACHE_INITSZ.#
56d0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 define SQLITE_DE
56e0: 46 41 55 4c 54 5f 50 43 41 43 48 45 5f 49 4e 49 FAULT_PCACHE_INI
56f0: 54 53 5a 20 32 30 0a 23 65 6e 64 69 66 0a 0a 2f TSZ 20.#endif../
5700: 2a 0a 2a 2a 20 54 68 65 20 63 6f 6d 70 69 6c 65 *.** The compile
5710: 2d 74 69 6d 65 20 6f 70 74 69 6f 6e 73 20 53 51 -time options SQ
5720: 4c 49 54 45 5f 4d 4d 41 50 5f 52 45 41 44 57 52 LITE_MMAP_READWR
5730: 49 54 45 20 61 6e 64 20 0a 2a 2a 20 53 51 4c 49 ITE and .** SQLI
5740: 54 45 5f 45 4e 41 42 4c 45 5f 42 41 54 43 48 5f TE_ENABLE_BATCH_
5750: 41 54 4f 4d 49 43 5f 57 52 49 54 45 20 61 72 65 ATOMIC_WRITE are
5760: 20 6e 6f 74 20 63 6f 6d 70 61 74 69 62 6c 65 20 not compatible
5770: 77 69 74 68 20 6f 6e 65 20 61 6e 6f 74 68 65 72 with one another
5780: 2e 0a 2a 2a 20 59 6f 75 20 6d 75 73 74 20 63 68 ..** You must ch
5790: 6f 6f 73 65 20 6f 6e 65 20 6f 72 20 74 68 65 20 oose one or the
57a0: 6f 74 68 65 72 20 28 6f 72 20 6e 65 69 74 68 65 other (or neithe
57b0: 72 29 20 62 75 74 20 6e 6f 74 20 62 6f 74 68 2e r) but not both.
57c0: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
57d0: 53 51 4c 49 54 45 5f 4d 4d 41 50 5f 52 45 41 44 SQLITE_MMAP_READ
57e0: 57 52 49 54 45 29 20 26 26 20 64 65 66 69 6e 65 WRITE) && define
57f0: 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
5800: 42 41 54 43 48 5f 41 54 4f 4d 49 43 5f 57 52 49 BATCH_ATOMIC_WRI
5810: 54 45 29 0a 23 65 72 72 6f 72 20 43 61 6e 6e 6f TE).#error Canno
5820: 74 20 75 73 65 20 62 6f 74 68 20 53 51 4c 49 54 t use both SQLIT
5830: 45 5f 4d 4d 41 50 5f 52 45 41 44 57 52 49 54 45 E_MMAP_READWRITE
5840: 20 61 6e 64 20 53 51 4c 49 54 45 5f 45 4e 41 42 and SQLITE_ENAB
5850: 4c 45 5f 42 41 54 43 48 5f 41 54 4f 4d 49 43 5f LE_BATCH_ATOMIC_
5860: 57 52 49 54 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a WRITE.#endif../*
5870: 0a 2a 2a 20 47 43 43 20 64 6f 65 73 20 6e 6f 74 .** GCC does not
5880: 20 64 65 66 69 6e 65 20 74 68 65 20 6f 66 66 73 define the offs
5890: 65 74 6f 66 28 29 20 6d 61 63 72 6f 20 73 6f 20 etof() macro so
58a0: 77 65 27 6c 6c 20 68 61 76 65 20 74 6f 20 64 6f we'll have to do
58b0: 20 69 74 0a 2a 2a 20 6f 75 72 73 65 6c 76 65 73 it.** ourselves
58c0: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 6f 66 66 ..*/.#ifndef off
58d0: 73 65 74 6f 66 0a 23 64 65 66 69 6e 65 20 6f 66 setof.#define of
58e0: 66 73 65 74 6f 66 28 53 54 52 55 43 54 55 52 45 fsetof(STRUCTURE
58f0: 2c 46 49 45 4c 44 29 20 28 28 69 6e 74 29 28 28 ,FIELD) ((int)((
5900: 63 68 61 72 2a 29 26 28 28 53 54 52 55 43 54 55 char*)&((STRUCTU
5910: 52 45 2a 29 30 29 2d 3e 46 49 45 4c 44 29 29 0a RE*)0)->FIELD)).
5920: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 #endif../*.** Ma
5930: 63 72 6f 73 20 74 6f 20 63 6f 6d 70 75 74 65 20 cros to compute
5940: 6d 69 6e 69 6d 75 6d 20 61 6e 64 20 6d 61 78 69 minimum and maxi
5950: 6d 75 6d 20 6f 66 20 74 77 6f 20 6e 75 6d 62 65 mum of two numbe
5960: 72 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 4d rs..*/.#ifndef M
5970: 49 4e 0a 23 20 64 65 66 69 6e 65 20 4d 49 4e 28 IN.# define MIN(
5980: 41 2c 42 29 20 28 28 41 29 3c 28 42 29 3f 28 41 A,B) ((A)<(B)?(A
5990: 29 3a 28 42 29 29 0a 23 65 6e 64 69 66 0a 23 69 ):(B)).#endif.#i
59a0: 66 6e 64 65 66 20 4d 41 58 0a 23 20 64 65 66 69 fndef MAX.# defi
59b0: 6e 65 20 4d 41 58 28 41 2c 42 29 20 28 28 41 29 ne MAX(A,B) ((A)
59c0: 3e 28 42 29 3f 28 41 29 3a 28 42 29 29 0a 23 65 >(B)?(A):(B)).#e
59d0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 77 61 70 ndif../*.** Swap
59e0: 20 74 77 6f 20 6f 62 6a 65 63 74 73 20 6f 66 20 two objects of
59f0: 74 79 70 65 20 54 59 50 45 2e 0a 2a 2f 0a 23 64 type TYPE..*/.#d
5a00: 65 66 69 6e 65 20 53 57 41 50 28 54 59 50 45 2c efine SWAP(TYPE,
5a10: 41 2c 42 29 20 7b 54 59 50 45 20 74 3d 41 3b 20 A,B) {TYPE t=A;
5a20: 41 3d 42 3b 20 42 3d 74 3b 7d 0a 0a 2f 2a 0a 2a A=B; B=t;}../*.*
5a30: 2a 20 43 68 65 63 6b 20 74 6f 20 73 65 65 20 69 * Check to see i
5a40: 66 20 74 68 69 73 20 6d 61 63 68 69 6e 65 20 75 f this machine u
5a50: 73 65 73 20 45 42 43 44 49 43 2e 20 20 28 59 65 ses EBCDIC. (Ye
5a60: 73 2c 20 62 65 6c 69 65 76 65 20 69 74 20 6f 72 s, believe it or
5a70: 0a 2a 2a 20 6e 6f 74 2c 20 74 68 65 72 65 20 61 .** not, there a
5a80: 72 65 20 73 74 69 6c 6c 20 6d 61 63 68 69 6e 65 re still machine
5a90: 73 20 6f 75 74 20 74 68 65 72 65 20 74 68 61 74 s out there that
5aa0: 20 75 73 65 20 45 42 43 44 49 43 2e 29 0a 2a 2f use EBCDIC.).*/
5ab0: 0a 23 69 66 20 27 41 27 20 3d 3d 20 27 5c 33 30 .#if 'A' == '\30
5ac0: 31 27 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1'.# define SQLI
5ad0: 54 45 5f 45 42 43 44 49 43 20 31 0a 23 65 6c 73 TE_EBCDIC 1.#els
5ae0: 65 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 e.# define SQLIT
5af0: 45 5f 41 53 43 49 49 20 31 0a 23 65 6e 64 69 66 E_ASCII 1.#endif
5b00: 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 67 65 72 73 ../*.** Integers
5b10: 20 6f 66 20 6b 6e 6f 77 6e 20 73 69 7a 65 73 2e of known sizes.
5b20: 20 20 54 68 65 73 65 20 74 79 70 65 64 65 66 73 These typedefs
5b30: 20 6d 69 67 68 74 20 63 68 61 6e 67 65 20 66 6f might change fo
5b40: 72 20 61 72 63 68 69 74 65 63 74 75 72 65 73 0a r architectures.
5b50: 2a 2a 20 77 68 65 72 65 20 74 68 65 20 73 69 7a ** where the siz
5b60: 65 73 20 76 65 72 79 2e 20 20 50 72 65 70 72 6f es very. Prepro
5b70: 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 20 61 72 cessor macros ar
5b80: 65 20 61 76 61 69 6c 61 62 6c 65 20 73 6f 20 74 e available so t
5b90: 68 61 74 20 74 68 65 0a 2a 2a 20 74 79 70 65 73 hat the.** types
5ba0: 20 63 61 6e 20 62 65 20 63 6f 6e 76 65 6e 69 65 can be convenie
5bb0: 6e 74 6c 79 20 72 65 64 65 66 69 6e 65 64 20 61 ntly redefined a
5bc0: 74 20 63 6f 6d 70 69 6c 65 2d 74 79 70 65 2e 20 t compile-type.
5bd0: 20 4c 69 6b 65 20 74 68 69 73 3a 0a 2a 2a 0a 2a Like this:.**.*
5be0: 2a 20 20 20 20 20 20 20 20 20 63 63 20 27 2d 44 * cc '-D
5bf0: 55 49 4e 54 50 54 52 5f 54 59 50 45 3d 6c 6f 6e UINTPTR_TYPE=lon
5c00: 67 20 6c 6f 6e 67 20 69 6e 74 27 20 2e 2e 2e 0a g long int' ....
5c10: 2a 2f 0a 23 69 66 6e 64 65 66 20 55 49 4e 54 33 */.#ifndef UINT3
5c20: 32 5f 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 2_TYPE.# ifdef H
5c30: 41 56 45 5f 55 49 4e 54 33 32 5f 54 0a 23 20 20 AVE_UINT32_T.#
5c40: 64 65 66 69 6e 65 20 55 49 4e 54 33 32 5f 54 59 define UINT32_TY
5c50: 50 45 20 75 69 6e 74 33 32 5f 74 0a 23 20 65 6c PE uint32_t.# el
5c60: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e se.# define UIN
5c70: 54 33 32 5f 54 59 50 45 20 75 6e 73 69 67 6e 65 T32_TYPE unsigne
5c80: 64 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a 23 65 d int.# endif.#e
5c90: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 49 4e ndif.#ifndef UIN
5ca0: 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 65 66 T16_TYPE.# ifdef
5cb0: 20 48 41 56 45 5f 55 49 4e 54 31 36 5f 54 0a 23 HAVE_UINT16_T.#
5cc0: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 31 36 5f define UINT16_
5cd0: 54 59 50 45 20 75 69 6e 74 31 36 5f 74 0a 23 20 TYPE uint16_t.#
5ce0: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
5cf0: 49 4e 54 31 36 5f 54 59 50 45 20 75 6e 73 69 67 INT16_TYPE unsig
5d00: 6e 65 64 20 73 68 6f 72 74 20 69 6e 74 0a 23 20 ned short int.#
5d10: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 endif.#endif.#if
5d20: 6e 64 65 66 20 49 4e 54 31 36 5f 54 59 50 45 0a ndef INT16_TYPE.
5d30: 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 4e 54 # ifdef HAVE_INT
5d40: 31 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 49 16_T.# define I
5d50: 4e 54 31 36 5f 54 59 50 45 20 69 6e 74 31 36 5f NT16_TYPE int16_
5d60: 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 t.# else.# defi
5d70: 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 73 68 ne INT16_TYPE sh
5d80: 6f 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a ort int.# endif.
5d90: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 #endif.#ifndef U
5da0: 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 64 65 INT8_TYPE.# ifde
5db0: 66 20 48 41 56 45 5f 55 49 4e 54 38 5f 54 0a 23 f HAVE_UINT8_T.#
5dc0: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 38 5f 54 define UINT8_T
5dd0: 59 50 45 20 75 69 6e 74 38 5f 74 0a 23 20 65 6c YPE uint8_t.# el
5de0: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e se.# define UIN
5df0: 54 38 5f 54 59 50 45 20 75 6e 73 69 67 6e 65 64 T8_TYPE unsigned
5e00: 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a 23 65 char.# endif.#e
5e10: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 4e 54 ndif.#ifndef INT
5e20: 38 5f 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 8_TYPE.# ifdef H
5e30: 41 56 45 5f 49 4e 54 38 5f 54 0a 23 20 20 64 65 AVE_INT8_T.# de
5e40: 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 20 69 fine INT8_TYPE i
5e50: 6e 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 nt8_t.# else.#
5e60: 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 define INT8_TYPE
5e70: 20 73 69 67 6e 65 64 20 63 68 61 72 0a 23 20 65 signed char.# e
5e80: 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e ndif.#endif.#ifn
5e90: 64 65 66 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 def LONGDOUBLE_T
5ea0: 59 50 45 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e YPE.# define LON
5eb0: 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 6c 6f 6e GDOUBLE_TYPE lon
5ec0: 67 20 64 6f 75 62 6c 65 0a 23 65 6e 64 69 66 0a g double.#endif.
5ed0: 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f 69 typedef sqlite_i
5ee0: 6e 74 36 34 20 69 36 34 3b 20 20 20 20 20 20 20 nt64 i64;
5ef0: 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 73 69 67 /* 8-byte sig
5f00: 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f 0a 74 ned integer */.t
5f10: 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f 75 69 ypedef sqlite_ui
5f20: 6e 74 36 34 20 75 36 34 3b 20 20 20 20 20 20 20 nt64 u64;
5f30: 20 20 2f 2a 20 38 2d 62 79 74 65 20 75 6e 73 69 /* 8-byte unsi
5f40: 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f 0a gned integer */.
5f50: 74 79 70 65 64 65 66 20 55 49 4e 54 33 32 5f 54 typedef UINT32_T
5f60: 59 50 45 20 75 33 32 3b 20 20 20 20 20 20 20 20 YPE u32;
5f70: 20 20 20 2f 2a 20 34 2d 62 79 74 65 20 75 6e 73 /* 4-byte uns
5f80: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
5f90: 0a 74 79 70 65 64 65 66 20 55 49 4e 54 31 36 5f .typedef UINT16_
5fa0: 54 59 50 45 20 75 31 36 3b 20 20 20 20 20 20 20 TYPE u16;
5fb0: 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 75 6e /* 2-byte un
5fc0: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
5fd0: 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 36 5f /.typedef INT16_
5fe0: 54 59 50 45 20 69 31 36 3b 20 20 20 20 20 20 20 TYPE i16;
5ff0: 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 73 /* 2-byte s
6000: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
6010: 0a 74 79 70 65 64 65 66 20 55 49 4e 54 38 5f 54 .typedef UINT8_T
6020: 59 50 45 20 75 38 3b 20 20 20 20 20 20 20 20 20 YPE u8;
6030: 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 75 6e /* 1-byte un
6040: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
6050: 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 38 5f 54 /.typedef INT8_T
6060: 59 50 45 20 69 38 3b 20 20 20 20 20 20 20 20 20 YPE i8;
6070: 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 73 /* 1-byte s
6080: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
6090: 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 5f 4d ../*.** SQLITE_M
60a0: 41 58 5f 55 33 32 20 69 73 20 61 20 75 36 34 20 AX_U32 is a u64
60b0: 63 6f 6e 73 74 61 6e 74 20 74 68 61 74 20 69 73 constant that is
60c0: 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 75 36 34 the maximum u64
60d0: 20 76 61 6c 75 65 0a 2a 2a 20 74 68 61 74 20 63 value.** that c
60e0: 61 6e 20 62 65 20 73 74 6f 72 65 64 20 69 6e 20 an be stored in
60f0: 61 20 75 33 32 20 77 69 74 68 6f 75 74 20 6c 6f a u32 without lo
6100: 73 73 20 6f 66 20 64 61 74 61 2e 20 20 54 68 65 ss of data. The
6110: 20 76 61 6c 75 65 0a 2a 2a 20 69 73 20 30 78 30 value.** is 0x0
6120: 30 30 30 30 30 30 30 66 66 66 66 66 66 66 66 2e 0000000ffffffff.
6130: 20 20 42 75 74 20 62 65 63 61 75 73 65 20 6f 66 But because of
6140: 20 71 75 69 72 6b 73 20 6f 66 20 73 6f 6d 65 20 quirks of some
6150: 63 6f 6d 70 69 6c 65 72 73 2c 20 77 65 0a 2a 2a compilers, we.**
6160: 20 68 61 76 65 20 74 6f 20 73 70 65 63 69 66 79 have to specify
6170: 20 74 68 65 20 76 61 6c 75 65 20 69 6e 20 74 68 the value in th
6180: 65 20 6c 65 73 73 20 69 6e 74 75 69 74 69 76 65 e less intuitive
6190: 20 6d 61 6e 6e 65 72 20 73 68 6f 77 6e 3a 0a 2a manner shown:.*
61a0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
61b0: 5f 4d 41 58 5f 55 33 32 20 20 28 28 28 28 75 36 _MAX_U32 ((((u6
61c0: 34 29 31 29 3c 3c 33 32 29 2d 31 29 0a 0a 2f 2a 4)1)<<32)-1)../*
61d0: 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 79 70 65 .** The datatype
61e0: 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 65 used to store e
61f0: 73 74 69 6d 61 74 65 73 20 6f 66 20 74 68 65 20 stimates of the
6200: 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 number of rows i
6210: 6e 20 61 0a 2a 2a 20 74 61 62 6c 65 20 6f 72 20 n a.** table or
6220: 69 6e 64 65 78 2e 20 20 54 68 69 73 20 69 73 20 index. This is
6230: 61 6e 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 an unsigned inte
6240: 67 65 72 20 74 79 70 65 2e 20 20 46 6f 72 20 39 ger type. For 9
6250: 39 2e 39 25 20 6f 66 0a 2a 2a 20 74 68 65 20 77 9.9% of.** the w
6260: 6f 72 6c 64 2c 20 61 20 33 32 2d 62 69 74 20 69 orld, a 32-bit i
6270: 6e 74 65 67 65 72 20 69 73 20 73 75 66 66 69 63 nteger is suffic
6280: 69 65 6e 74 2e 20 20 42 75 74 20 61 20 36 34 2d ient. But a 64-
6290: 62 69 74 20 69 6e 74 65 67 65 72 0a 2a 2a 20 63 bit integer.** c
62a0: 61 6e 20 62 65 20 75 73 65 64 20 61 74 20 63 6f an be used at co
62b0: 6d 70 69 6c 65 2d 74 69 6d 65 20 69 66 20 64 65 mpile-time if de
62c0: 73 69 72 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 sired..*/.#ifdef
62d0: 20 53 51 4c 49 54 45 5f 36 34 42 49 54 5f 53 54 SQLITE_64BIT_ST
62e0: 41 54 53 0a 20 74 79 70 65 64 65 66 20 75 36 34 ATS. typedef u64
62f0: 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 tRowcnt; /*
6300: 36 34 2d 62 69 74 20 6f 6e 6c 79 20 69 66 20 72 64-bit only if r
6310: 65 71 75 65 73 74 65 64 20 61 74 20 63 6f 6d 70 equested at comp
6320: 69 6c 65 2d 74 69 6d 65 20 2a 2f 0a 23 65 6c 73 ile-time */.#els
6330: 65 0a 20 74 79 70 65 64 65 66 20 75 33 32 20 74 e. typedef u32 t
6340: 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 33 32 Rowcnt; /* 32
6350: 2d 62 69 74 20 69 73 20 74 68 65 20 64 65 66 61 -bit is the defa
6360: 75 6c 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f ult */.#endif../
6370: 2a 0a 2a 2a 20 45 73 74 69 6d 61 74 65 64 20 71 *.** Estimated q
6380: 75 61 6e 74 69 74 69 65 73 20 75 73 65 64 20 66 uantities used f
6390: 6f 72 20 71 75 65 72 79 20 70 6c 61 6e 6e 69 6e or query plannin
63a0: 67 20 61 72 65 20 73 74 6f 72 65 64 20 61 73 20 g are stored as
63b0: 31 36 2d 62 69 74 0a 2a 2a 20 6c 6f 67 61 72 69 16-bit.** logari
63c0: 74 68 6d 73 2e 20 20 46 6f 72 20 71 75 61 6e 74 thms. For quant
63d0: 69 74 79 20 58 2c 20 74 68 65 20 76 61 6c 75 65 ity X, the value
63e0: 20 73 74 6f 72 65 64 20 69 73 20 31 30 2a 6c 6f stored is 10*lo
63f0: 67 32 28 58 29 2e 20 20 54 68 69 73 0a 2a 2a 20 g2(X). This.**
6400: 67 69 76 65 73 20 61 20 70 6f 73 73 69 62 6c 65 gives a possible
6410: 20 72 61 6e 67 65 20 6f 66 20 76 61 6c 75 65 73 range of values
6420: 20 6f 66 20 61 70 70 72 6f 78 69 6d 61 74 65 6c of approximatel
6430: 79 20 31 2e 30 65 39 38 36 20 74 6f 20 31 65 2d y 1.0e986 to 1e-
6440: 39 38 36 2e 0a 2a 2a 20 42 75 74 20 74 68 65 20 986..** But the
6450: 61 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 61 allowed values a
6460: 72 65 20 22 67 72 61 69 6e 79 22 2e 20 20 4e 6f re "grainy". No
6470: 74 20 65 76 65 72 79 20 76 61 6c 75 65 20 69 73 t every value is
6480: 20 72 65 70 72 65 73 65 6e 74 61 62 6c 65 2e 0a representable..
6490: 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 ** For example,
64a0: 71 75 61 6e 74 69 74 69 65 73 20 31 36 20 61 6e quantities 16 an
64b0: 64 20 31 37 20 61 72 65 20 62 6f 74 68 20 72 65 d 17 are both re
64c0: 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 20 4c presented by a L
64d0: 6f 67 45 73 74 0a 2a 2a 20 6f 66 20 34 30 2e 20 ogEst.** of 40.
64e0: 20 48 6f 77 65 76 65 72 2c 20 73 69 6e 63 65 20 However, since
64f0: 4c 6f 67 45 73 74 20 71 75 61 6e 74 69 74 69 65 LogEst quantitie
6500: 73 20 61 72 65 20 73 75 70 70 6f 73 65 20 74 6f s are suppose to
6510: 20 62 65 20 65 73 74 69 6d 61 74 65 73 2c 0a 2a be estimates,.*
6520: 2a 20 6e 6f 74 20 65 78 61 63 74 20 76 61 6c 75 * not exact valu
6530: 65 73 2c 20 74 68 69 73 20 69 6d 70 72 65 63 69 es, this impreci
6540: 73 69 6f 6e 20 69 73 20 6e 6f 74 20 61 20 70 72 sion is not a pr
6550: 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a 2a 20 22 4c 6f oblem..**.** "Lo
6560: 67 45 73 74 22 20 69 73 20 73 68 6f 72 74 20 66 gEst" is short f
6570: 6f 72 20 22 4c 6f 67 61 72 69 74 68 6d 69 63 20 or "Logarithmic
6580: 45 73 74 69 6d 61 74 65 22 2e 0a 2a 2a 0a 2a 2a Estimate"..**.**
6590: 20 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 20 20 20 Examples:.**
65a0: 20 20 20 31 20 2d 3e 20 30 20 20 20 20 20 20 20 1 -> 0
65b0: 20 20 20 20 20 20 20 32 30 20 2d 3e 20 34 33 20 20 -> 43
65c0: 20 20 20 20 20 20 20 20 20 31 30 30 30 30 20 2d 10000 -
65d0: 3e 20 31 33 32 0a 2a 2a 20 20 20 20 20 20 32 20 > 132.** 2
65e0: 2d 3e 20 31 30 20 20 20 20 20 20 20 20 20 20 20 -> 10
65f0: 20 20 32 35 20 2d 3e 20 34 36 20 20 20 20 20 20 25 -> 46
6600: 20 20 20 20 32 35 30 30 30 20 2d 3e 20 31 34 36 25000 -> 146
6610: 0a 2a 2a 20 20 20 20 20 20 33 20 2d 3e 20 31 36 .** 3 -> 16
6620: 20 20 20 20 20 20 20 20 20 20 20 20 31 30 30 20 100
6630: 2d 3e 20 36 36 20 20 20 20 20 20 20 20 31 30 30 -> 66 100
6640: 30 30 30 30 20 2d 3e 20 31 39 39 0a 2a 2a 20 20 0000 -> 199.**
6650: 20 20 20 20 34 20 2d 3e 20 32 30 20 20 20 20 20 4 -> 20
6660: 20 20 20 20 20 20 31 30 30 30 20 2d 3e 20 39 39 1000 -> 99
6670: 20 20 20 20 20 20 20 20 31 30 34 38 35 37 36 20 1048576
6680: 2d 3e 20 32 30 30 0a 2a 2a 20 20 20 20 20 31 30 -> 200.** 10
6690: 20 2d 3e 20 33 33 20 20 20 20 20 20 20 20 20 20 -> 33
66a0: 20 31 30 32 34 20 2d 3e 20 31 30 30 20 20 20 20 1024 -> 100
66b0: 34 32 39 34 39 36 37 32 39 36 20 2d 3e 20 33 32 4294967296 -> 32
66c0: 30 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 67 45 0.**.** The LogE
66d0: 73 74 20 63 61 6e 20 62 65 20 6e 65 67 61 74 69 st can be negati
66e0: 76 65 20 74 6f 20 69 6e 64 69 63 61 74 65 20 66 ve to indicate f
66f0: 72 61 63 74 69 6f 6e 61 6c 20 76 61 6c 75 65 73 ractional values
6700: 2e 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a 2a ..** Examples:.*
6710: 2a 0a 2a 2a 20 20 20 20 30 2e 35 20 2d 3e 20 2d *.** 0.5 -> -
6720: 31 30 20 20 20 20 20 20 20 20 20 20 20 30 2e 31 10 0.1
6730: 20 2d 3e 20 2d 33 33 20 20 20 20 20 20 20 20 30 -> -33 0
6740: 2e 30 36 32 35 20 2d 3e 20 2d 34 30 0a 2a 2f 0a .0625 -> -40.*/.
6750: 74 79 70 65 64 65 66 20 49 4e 54 31 36 5f 54 59 typedef INT16_TY
6760: 50 45 20 4c 6f 67 45 73 74 3b 0a 0a 2f 2a 0a 2a PE LogEst;../*.*
6770: 2a 20 53 65 74 20 74 68 65 20 53 51 4c 49 54 45 * Set the SQLITE
6780: 5f 50 54 52 53 49 5a 45 20 6d 61 63 72 6f 20 74 _PTRSIZE macro t
6790: 6f 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 o the number of
67a0: 62 79 74 65 73 20 69 6e 20 61 20 70 6f 69 6e 74 bytes in a point
67b0: 65 72 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 er.*/.#ifndef SQ
67c0: 4c 49 54 45 5f 50 54 52 53 49 5a 45 0a 23 20 69 LITE_PTRSIZE.# i
67d0: 66 20 64 65 66 69 6e 65 64 28 5f 5f 53 49 5a 45 f defined(__SIZE
67e0: 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f 29 0a 23 20 OF_POINTER__).#
67f0: 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f define SQLITE_
6800: 50 54 52 53 49 5a 45 20 5f 5f 53 49 5a 45 4f 46 PTRSIZE __SIZEOF
6810: 5f 50 4f 49 4e 54 45 52 5f 5f 0a 23 20 65 6c 69 _POINTER__.# eli
6820: 66 20 64 65 66 69 6e 65 64 28 69 33 38 36 29 20 f defined(i386)
6830: 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f || defined(_
6840: 5f 69 33 38 36 5f 5f 29 20 20 20 7c 7c 20 64 65 _i386__) || de
6850: 66 69 6e 65 64 28 5f 4d 5f 49 58 38 36 29 20 7c fined(_M_IX86) |
6860: 7c 20 20 20 20 5c 0a 20 20 20 20 20 20 20 64 65 | \. de
6870: 66 69 6e 65 64 28 5f 4d 5f 41 52 4d 29 20 20 20 fined(_M_ARM)
6880: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 61 72 6d || defined(__arm
6890: 5f 5f 29 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 __) || define
68a0: 64 28 5f 5f 78 38 36 29 0a 23 20 20 20 64 65 66 d(__x86).# def
68b0: 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 53 49 ine SQLITE_PTRSI
68c0: 5a 45 20 34 0a 23 20 65 6c 73 65 0a 23 20 20 20 ZE 4.# else.#
68d0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 define SQLITE_PT
68e0: 52 53 49 5a 45 20 38 0a 23 20 65 6e 64 69 66 0a RSIZE 8.# endif.
68f0: 23 65 6e 64 69 66 0a 0a 2f 2a 20 54 68 65 20 75 #endif../* The u
6900: 70 74 72 20 74 79 70 65 20 69 73 20 61 6e 20 75 ptr type is an u
6910: 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 nsigned integer
6920: 6c 61 72 67 65 20 65 6e 6f 75 67 68 20 74 6f 20 large enough to
6930: 68 6f 6c 64 20 61 20 70 6f 69 6e 74 65 72 0a 2a hold a pointer.*
6940: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 48 41 /.#if defined(HA
6950: 56 45 5f 53 54 44 49 4e 54 5f 48 29 0a 20 20 74 VE_STDINT_H). t
6960: 79 70 65 64 65 66 20 75 69 6e 74 70 74 72 5f 74 ypedef uintptr_t
6970: 20 75 70 74 72 3b 0a 23 65 6c 69 66 20 53 51 4c uptr;.#elif SQL
6980: 49 54 45 5f 50 54 52 53 49 5a 45 3d 3d 34 0a 20 ITE_PTRSIZE==4.
6990: 20 74 79 70 65 64 65 66 20 75 33 32 20 75 70 74 typedef u32 upt
69a0: 72 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 64 r;.#else. typed
69b0: 65 66 20 75 36 34 20 75 70 74 72 3b 0a 23 65 6e ef u64 uptr;.#en
69c0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 dif../*.** The S
69d0: 51 4c 49 54 45 5f 57 49 54 48 49 4e 28 50 2c 53 QLITE_WITHIN(P,S
69e0: 2c 45 29 20 6d 61 63 72 6f 20 63 68 65 63 6b 73 ,E) macro checks
69f0: 20 74 6f 20 73 65 65 20 69 66 20 70 6f 69 6e 74 to see if point
6a00: 65 72 20 50 20 70 6f 69 6e 74 73 20 74 6f 0a 2a er P points to.*
6a10: 2a 20 73 6f 6d 65 74 68 69 6e 67 20 62 65 74 77 * something betw
6a20: 65 65 6e 20 53 20 28 69 6e 63 6c 75 73 69 76 65 een S (inclusive
6a30: 29 20 61 6e 64 20 45 20 28 65 78 63 6c 75 73 69 ) and E (exclusi
6a40: 76 65 29 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 6f 74 ve)..**.** In ot
6a50: 68 65 72 20 77 6f 72 64 73 2c 20 53 20 69 73 20 her words, S is
6a60: 61 20 62 75 66 66 65 72 20 61 6e 64 20 45 20 69 a buffer and E i
6a70: 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 s a pointer to t
6a80: 68 65 20 66 69 72 73 74 20 62 79 74 65 20 61 66 he first byte af
6a90: 74 65 72 0a 2a 2a 20 74 68 65 20 65 6e 64 20 6f ter.** the end o
6aa0: 66 20 62 75 66 66 65 72 20 53 2e 20 20 54 68 69 f buffer S. Thi
6ab0: 73 20 6d 61 63 72 6f 20 72 65 74 75 72 6e 73 20 s macro returns
6ac0: 74 72 75 65 20 69 66 20 50 20 70 6f 69 6e 74 73 true if P points
6ad0: 20 74 6f 20 73 6f 6d 65 74 68 69 6e 67 0a 2a 2a to something.**
6ae0: 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 69 contained withi
6af0: 6e 20 74 68 65 20 62 75 66 66 65 72 20 53 2e 0a n the buffer S..
6b00: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
6b10: 45 5f 57 49 54 48 49 4e 28 50 2c 53 2c 45 29 20 E_WITHIN(P,S,E)
6b20: 28 28 28 75 70 74 72 29 28 50 29 3e 3d 28 75 70 (((uptr)(P)>=(up
6b30: 74 72 29 28 53 29 29 26 26 28 28 75 70 74 72 29 tr)(S))&&((uptr)
6b40: 28 50 29 3c 28 75 70 74 72 29 28 45 29 29 29 0a (P)<(uptr)(E))).
6b50: 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 ../*.** Macros t
6b60: 6f 20 64 65 74 65 72 6d 69 6e 65 20 77 68 65 74 o determine whet
6b70: 68 65 72 20 74 68 65 20 6d 61 63 68 69 6e 65 20 her the machine
6b80: 69 73 20 62 69 67 20 6f 72 20 6c 69 74 74 6c 65 is big or little
6b90: 20 65 6e 64 69 61 6e 2c 0a 2a 2a 20 61 6e 64 20 endian,.** and
6ba0: 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 whether or not t
6bb0: 68 61 74 20 64 65 74 65 72 6d 69 6e 61 74 69 6f hat determinatio
6bc0: 6e 20 69 73 20 72 75 6e 2d 74 69 6d 65 20 6f 72 n is run-time or
6bd0: 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 2e 0a 2a compile-time..*
6be0: 2a 0a 2a 2a 20 46 6f 72 20 62 65 73 74 20 70 65 *.** For best pe
6bf0: 72 66 6f 72 6d 61 6e 63 65 2c 20 61 6e 20 61 74 rformance, an at
6c00: 74 65 6d 70 74 20 69 73 20 6d 61 64 65 20 74 6f tempt is made to
6c10: 20 67 75 65 73 73 20 61 74 20 74 68 65 20 62 79 guess at the by
6c20: 74 65 2d 6f 72 64 65 72 0a 2a 2a 20 75 73 69 6e te-order.** usin
6c30: 67 20 43 2d 70 72 65 70 72 6f 63 65 73 73 6f 72 g C-preprocessor
6c40: 20 6d 61 63 72 6f 73 2e 20 20 49 66 20 74 68 61 macros. If tha
6c50: 74 20 69 73 20 75 6e 73 75 63 63 65 73 73 66 75 t is unsuccessfu
6c60: 6c 2c 20 6f 72 20 69 66 0a 2a 2a 20 2d 44 53 51 l, or if.** -DSQ
6c70: 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 3d 30 LITE_BYTEORDER=0
6c80: 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 62 79 is set, then by
6c90: 74 65 2d 6f 72 64 65 72 20 69 73 20 64 65 74 65 te-order is dete
6ca0: 72 6d 69 6e 65 64 0a 2a 2a 20 61 74 20 72 75 6e rmined.** at run
6cb0: 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 69 66 6e 64 65 -time..*/.#ifnde
6cc0: 66 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 f SQLITE_BYTEORD
6cd0: 45 52 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 ER.# if defined(
6ce0: 69 33 38 36 29 20 20 20 20 20 7c 7c 20 64 65 66 i386) || def
6cf0: 69 6e 65 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 ined(__i386__)
6d00: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 || defined(_M_I
6d10: 58 38 36 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 X86) || \.
6d20: 20 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 5f defined(__x86_
6d30: 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 64) || defined(_
6d40: 5f 78 38 36 5f 36 34 5f 5f 29 20 7c 7c 20 64 65 _x86_64__) || de
6d50: 66 69 6e 65 64 28 5f 4d 5f 58 36 34 29 20 20 7c fined(_M_X64) |
6d60: 7c 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 | \. defi
6d70: 6e 65 64 28 5f 4d 5f 41 4d 44 36 34 29 20 7c 7c ned(_M_AMD64) ||
6d80: 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 52 4d 29 defined(_M_ARM)
6d90: 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 || defined(
6da0: 5f 5f 78 38 36 29 20 20 20 7c 7c 20 20 20 20 5c __x86) || \
6db0: 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f . defined(__
6dc0: 61 72 6d 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e arm__).# defin
6dd0: 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 e SQLITE_BYTEORD
6de0: 45 52 20 20 20 20 31 32 33 34 0a 23 20 65 6c 69 ER 1234.# eli
6df0: 66 20 64 65 66 69 6e 65 64 28 73 70 61 72 63 29 f defined(sparc)
6e00: 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f || defined(_
6e10: 5f 70 70 63 5f 5f 29 0a 23 20 20 20 64 65 66 69 _ppc__).# defi
6e20: 6e 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 ne SQLITE_BYTEOR
6e30: 44 45 52 20 20 20 20 34 33 32 31 0a 23 20 65 6c DER 4321.# el
6e40: 73 65 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 se.# define SQ
6e50: 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 30 LITE_BYTEORDER 0
6e60: 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a .# endif.#endif.
6e70: 23 69 66 20 53 51 4c 49 54 45 5f 42 59 54 45 4f #if SQLITE_BYTEO
6e80: 52 44 45 52 3d 3d 34 33 32 31 0a 23 20 64 65 66 RDER==4321.# def
6e90: 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 4e ine SQLITE_BIGEN
6ea0: 44 49 41 4e 20 20 20 20 31 0a 23 20 64 65 66 69 DIAN 1.# defi
6eb0: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
6ec0: 45 4e 44 49 41 4e 20 30 0a 23 20 64 65 66 69 6e ENDIAN 0.# defin
6ed0: 65 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 e SQLITE_UTF16NA
6ee0: 54 49 56 45 20 20 53 51 4c 49 54 45 5f 55 54 46 TIVE SQLITE_UTF
6ef0: 31 36 42 45 0a 23 65 6c 69 66 20 53 51 4c 49 54 16BE.#elif SQLIT
6f00: 45 5f 42 59 54 45 4f 52 44 45 52 3d 3d 31 32 33 E_BYTEORDER==123
6f10: 34 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 4.# define SQLIT
6f20: 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 30 E_BIGENDIAN 0
6f30: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
6f40: 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 31 0a _LITTLEENDIAN 1.
6f50: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
6f60: 55 54 46 31 36 4e 41 54 49 56 45 20 20 53 51 4c UTF16NATIVE SQL
6f70: 49 54 45 5f 55 54 46 31 36 4c 45 0a 23 65 6c 73 ITE_UTF16LE.#els
6f80: 65 0a 23 20 69 66 64 65 66 20 53 51 4c 49 54 45 e.# ifdef SQLITE
6f90: 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a 20 20 _AMALGAMATION.
6fa0: 63 6f 6e 73 74 20 69 6e 74 20 73 71 6c 69 74 65 const int sqlite
6fb0: 33 6f 6e 65 20 3d 20 31 3b 0a 23 20 65 6c 73 65 3one = 1;.# else
6fc0: 0a 20 20 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 . extern const
6fd0: 69 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 3b 0a int sqlite3one;.
6fe0: 23 20 65 6e 64 69 66 0a 23 20 64 65 66 69 6e 65 # endif.# define
6ff0: 20 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 SQLITE_BIGENDIA
7000: 4e 20 20 20 20 28 2a 28 63 68 61 72 20 2a 29 28 N (*(char *)(
7010: 26 73 71 6c 69 74 65 33 6f 6e 65 29 3d 3d 30 29 &sqlite3one)==0)
7020: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
7030: 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 28 2a _LITTLEENDIAN (*
7040: 28 63 68 61 72 20 2a 29 28 26 73 71 6c 69 74 65 (char *)(&sqlite
7050: 33 6f 6e 65 29 3d 3d 31 29 0a 23 20 64 65 66 69 3one)==1).# defi
7060: 6e 65 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e ne SQLITE_UTF16N
7070: 41 54 49 56 45 20 20 28 53 51 4c 49 54 45 5f 42 ATIVE (SQLITE_B
7080: 49 47 45 4e 44 49 41 4e 3f 53 51 4c 49 54 45 5f IGENDIAN?SQLITE_
7090: 55 54 46 31 36 42 45 3a 53 51 4c 49 54 45 5f 55 UTF16BE:SQLITE_U
70a0: 54 46 31 36 4c 45 29 0a 23 65 6e 64 69 66 0a 0a TF16LE).#endif..
70b0: 2f 2a 0a 2a 2a 20 43 6f 6e 73 74 61 6e 74 73 20 /*.** Constants
70c0: 66 6f 72 20 74 68 65 20 6c 61 72 67 65 73 74 20 for the largest
70d0: 61 6e 64 20 73 6d 61 6c 6c 65 73 74 20 70 6f 73 and smallest pos
70e0: 73 69 62 6c 65 20 36 34 2d 62 69 74 20 73 69 67 sible 64-bit sig
70f0: 6e 65 64 20 69 6e 74 65 67 65 72 73 2e 0a 2a 2a ned integers..**
7100: 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 61 72 These macros ar
7110: 65 20 64 65 73 69 67 6e 65 64 20 74 6f 20 77 6f e designed to wo
7120: 72 6b 20 63 6f 72 72 65 63 74 6c 79 20 6f 6e 20 rk correctly on
7130: 62 6f 74 68 20 33 32 2d 62 69 74 20 61 6e 64 20 both 32-bit and
7140: 36 34 2d 62 69 74 0a 2a 2a 20 63 6f 6d 70 69 6c 64-bit.** compil
7150: 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ers..*/.#define
7160: 4c 41 52 47 45 53 54 5f 49 4e 54 36 34 20 20 28 LARGEST_INT64 (
7170: 30 78 66 66 66 66 66 66 66 66 7c 28 28 28 69 36 0xffffffff|(((i6
7180: 34 29 30 78 37 66 66 66 66 66 66 66 29 3c 3c 33 4)0x7fffffff)<<3
7190: 32 29 29 0a 23 64 65 66 69 6e 65 20 53 4d 41 4c 2)).#define SMAL
71a0: 4c 45 53 54 5f 49 4e 54 36 34 20 28 28 28 69 36 LEST_INT64 (((i6
71b0: 34 29 2d 31 29 20 2d 20 4c 41 52 47 45 53 54 5f 4)-1) - LARGEST_
71c0: 49 4e 54 36 34 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f INT64)../*.** Ro
71d0: 75 6e 64 20 75 70 20 61 20 6e 75 6d 62 65 72 20 und up a number
71e0: 74 6f 20 74 68 65 20 6e 65 78 74 20 6c 61 72 67 to the next larg
71f0: 65 72 20 6d 75 6c 74 69 70 6c 65 20 6f 66 20 38 er multiple of 8
7200: 2e 20 20 54 68 69 73 20 69 73 20 75 73 65 64 0a . This is used.
7210: 2a 2a 20 74 6f 20 66 6f 72 63 65 20 38 2d 62 79 ** to force 8-by
7220: 74 65 20 61 6c 69 67 6e 6d 65 6e 74 20 6f 6e 20 te alignment on
7230: 36 34 2d 62 69 74 20 61 72 63 68 69 74 65 63 74 64-bit architect
7240: 75 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ures..*/.#define
7250: 20 52 4f 55 4e 44 38 28 78 29 20 20 20 20 20 28 ROUND8(x) (
7260: 28 28 78 29 2b 37 29 26 7e 37 29 0a 0a 2f 2a 0a ((x)+7)&~7)../*.
7270: 2a 2a 20 52 6f 75 6e 64 20 64 6f 77 6e 20 74 6f ** Round down to
7280: 20 74 68 65 20 6e 65 61 72 65 73 74 20 6d 75 6c the nearest mul
7290: 74 69 70 6c 65 20 6f 66 20 38 0a 2a 2f 0a 23 64 tiple of 8.*/.#d
72a0: 65 66 69 6e 65 20 52 4f 55 4e 44 44 4f 57 4e 38 efine ROUNDDOWN8
72b0: 28 78 29 20 28 28 78 29 26 7e 37 29 0a 0a 2f 2a (x) ((x)&~7)../*
72c0: 0a 2a 2a 20 41 73 73 65 72 74 20 74 68 61 74 20 .** Assert that
72d0: 74 68 65 20 70 6f 69 6e 74 65 72 20 58 20 69 73 the pointer X is
72e0: 20 61 6c 69 67 6e 65 64 20 74 6f 20 61 6e 20 38 aligned to an 8
72f0: 2d 62 79 74 65 20 62 6f 75 6e 64 61 72 79 2e 20 -byte boundary.
7300: 20 54 68 69 73 0a 2a 2a 20 6d 61 63 72 6f 20 69 This.** macro i
7310: 73 20 75 73 65 64 20 6f 6e 6c 79 20 77 69 74 68 s used only with
7320: 69 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 76 in assert() to v
7330: 65 72 69 66 79 20 74 68 61 74 20 74 68 65 20 63 erify that the c
7340: 6f 64 65 20 67 65 74 73 0a 2a 2a 20 61 6c 6c 20 ode gets.** all
7350: 61 6c 69 67 6e 6d 65 6e 74 20 72 65 73 74 72 69 alignment restri
7360: 63 74 69 6f 6e 73 20 63 6f 72 72 65 63 74 2e 0a ctions correct..
7370: 2a 2a 0a 2a 2a 20 45 78 63 65 70 74 2c 20 69 66 **.** Except, if
7380: 20 53 51 4c 49 54 45 5f 34 5f 42 59 54 45 5f 41 SQLITE_4_BYTE_A
7390: 4c 49 47 4e 45 44 5f 4d 41 4c 4c 4f 43 20 69 73 LIGNED_MALLOC is
73a0: 20 64 65 66 69 6e 65 64 2c 20 74 68 65 6e 20 74 defined, then t
73b0: 68 65 0a 2a 2a 20 75 6e 64 65 72 6c 79 69 6e 67 he.** underlying
73c0: 20 6d 61 6c 6c 6f 63 28 29 20 69 6d 70 6c 65 6d malloc() implem
73d0: 65 6e 74 61 74 69 6f 6e 20 6d 69 67 68 74 20 72 entation might r
73e0: 65 74 75 72 6e 20 75 73 20 34 2d 62 79 74 65 20 eturn us 4-byte
73f0: 61 6c 69 67 6e 65 64 0a 2a 2a 20 70 6f 69 6e 74 aligned.** point
7400: 65 72 73 2e 20 20 49 6e 20 74 68 61 74 20 63 61 ers. In that ca
7410: 73 65 2c 20 6f 6e 6c 79 20 76 65 72 69 66 79 20 se, only verify
7420: 34 2d 62 79 74 65 20 61 6c 69 67 6e 6d 65 6e 74 4-byte alignment
7430: 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
7440: 54 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 TE_4_BYTE_ALIGNE
7450: 44 5f 4d 41 4c 4c 4f 43 0a 23 20 64 65 66 69 6e D_MALLOC.# defin
7460: 65 20 45 49 47 48 54 5f 42 59 54 45 5f 41 4c 49 e EIGHT_BYTE_ALI
7470: 47 4e 4d 45 4e 54 28 58 29 20 20 20 28 28 28 28 GNMENT(X) ((((
7480: 63 68 61 72 2a 29 28 58 29 20 2d 20 28 63 68 61 char*)(X) - (cha
7490: 72 2a 29 30 29 26 33 29 3d 3d 30 29 0a 23 65 6c r*)0)&3)==0).#el
74a0: 73 65 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 se.# define EIGH
74b0: 54 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 T_BYTE_ALIGNMENT
74c0: 28 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 (X) ((((char*)
74d0: 28 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 (X) - (char*)0)&
74e0: 37 29 3d 3d 30 29 0a 23 65 6e 64 69 66 0a 0a 2f 7)==0).#endif../
74f0: 2a 0a 2a 2a 20 44 69 73 61 62 6c 65 20 4d 4d 41 *.** Disable MMA
7500: 50 20 6f 6e 20 70 6c 61 74 66 6f 72 6d 73 20 77 P on platforms w
7510: 68 65 72 65 20 69 74 20 69 73 20 6b 6e 6f 77 6e here it is known
7520: 20 74 6f 20 6e 6f 74 20 77 6f 72 6b 0a 2a 2f 0a to not work.*/.
7530: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 #if defined(__Op
7540: 65 6e 42 53 44 5f 5f 29 20 7c 7c 20 64 65 66 69 enBSD__) || defi
7550: 6e 65 64 28 5f 5f 51 4e 58 4e 54 4f 5f 5f 29 0a ned(__QNXNTO__).
7560: 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d # undef SQLITE_M
7570: 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 AX_MMAP_SIZE.# d
7580: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 efine SQLITE_MAX
7590: 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 65 6e _MMAP_SIZE 0.#en
75a0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 61 75 dif../*.** Defau
75b0: 6c 74 20 6d 61 78 69 6d 75 6d 20 73 69 7a 65 20 lt maximum size
75c0: 6f 66 20 6d 65 6d 6f 72 79 20 75 73 65 64 20 62 of memory used b
75d0: 79 20 6d 65 6d 6f 72 79 2d 6d 61 70 70 65 64 20 y memory-mapped
75e0: 49 2f 4f 20 69 6e 20 74 68 65 20 56 46 53 0a 2a I/O in the VFS.*
75f0: 2f 0a 23 69 66 64 65 66 20 5f 5f 41 50 50 4c 45 /.#ifdef __APPLE
7600: 5f 5f 0a 23 20 69 6e 63 6c 75 64 65 20 3c 54 61 __.# include <Ta
7610: 72 67 65 74 43 6f 6e 64 69 74 69 6f 6e 61 6c 73 rgetConditionals
7620: 2e 68 3e 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 .h>.#endif.#ifnd
7630: 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ef SQLITE_MAX_MM
7640: 41 50 5f 53 49 5a 45 0a 23 20 69 66 20 64 65 66 AP_SIZE.# if def
7650: 69 6e 65 64 28 5f 5f 6c 69 6e 75 78 5f 5f 29 20 ined(__linux__)
7660: 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f \. || defined(_
7670: 57 49 4e 33 32 29 20 5c 0a 20 20 7c 7c 20 28 64 WIN32) \. || (d
7680: 65 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f efined(__APPLE__
7690: 29 20 26 26 20 64 65 66 69 6e 65 64 28 5f 5f 4d ) && defined(__M
76a0: 41 43 48 5f 5f 29 29 20 5c 0a 20 20 7c 7c 20 64 ACH__)) \. || d
76b0: 65 66 69 6e 65 64 28 5f 5f 73 75 6e 29 20 5c 0a efined(__sun) \.
76c0: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 46 || defined(__F
76d0: 72 65 65 42 53 44 5f 5f 29 20 5c 0a 20 20 7c 7c reeBSD__) \. ||
76e0: 20 64 65 66 69 6e 65 64 28 5f 5f 44 72 61 67 6f defined(__Drago
76f0: 6e 46 6c 79 5f 5f 29 0a 23 20 20 20 64 65 66 69 nFly__).# defi
7700: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ne SQLITE_MAX_MM
7710: 41 50 5f 53 49 5a 45 20 30 78 37 66 66 66 30 30 AP_SIZE 0x7fff00
7720: 30 30 20 20 2f 2a 20 32 31 34 37 34 31 38 31 31 00 /* 214741811
7730: 32 20 2a 2f 0a 23 20 65 6c 73 65 0a 23 20 20 20 2 */.# else.#
7740: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
7750: 58 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 X_MMAP_SIZE 0.#
7760: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a endif.#endif../*
7770: 0a 2a 2a 20 54 68 65 20 64 65 66 61 75 6c 74 20 .** The default
7780: 4d 4d 41 50 5f 53 49 5a 45 20 69 73 20 7a 65 72 MMAP_SIZE is zer
7790: 6f 20 6f 6e 20 61 6c 6c 20 70 6c 61 74 66 6f 72 o on all platfor
77a0: 6d 73 2e 20 20 4f 72 2c 20 65 76 65 6e 20 69 66 ms. Or, even if
77b0: 20 61 20 6c 61 72 67 65 72 0a 2a 2a 20 64 65 66 a larger.** def
77c0: 61 75 6c 74 20 4d 4d 41 50 5f 53 49 5a 45 20 69 ault MMAP_SIZE i
77d0: 73 20 73 70 65 63 69 66 69 65 64 20 61 74 20 63 s specified at c
77e0: 6f 6d 70 69 6c 65 2d 74 69 6d 65 2c 20 6d 61 6b ompile-time, mak
77f0: 65 20 73 75 72 65 20 74 68 61 74 20 69 74 20 64 e sure that it d
7800: 6f 65 73 0a 2a 2a 20 6e 6f 74 20 65 78 63 65 65 oes.** not excee
7810: 64 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 6d 6d d the maximum mm
7820: 61 70 20 73 69 7a 65 2e 0a 2a 2f 0a 23 69 66 6e ap size..*/.#ifn
7830: 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 def SQLITE_DEFAU
7840: 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 LT_MMAP_SIZE.# d
7850: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 efine SQLITE_DEF
7860: 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 AULT_MMAP_SIZE 0
7870: 0a 23 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 .#endif.#if SQLI
7880: 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f TE_DEFAULT_MMAP_
7890: 53 49 5a 45 3e 53 51 4c 49 54 45 5f 4d 41 58 5f SIZE>SQLITE_MAX_
78a0: 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 75 6e 64 65 MMAP_SIZE.# unde
78b0: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
78c0: 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 _MMAP_SIZE.# def
78d0: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
78e0: 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 20 53 51 4c LT_MMAP_SIZE SQL
78f0: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
7900: 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 E.#endif../*.**
7910: 4f 6e 6c 79 20 6f 6e 65 20 6f 66 20 53 51 4c 49 Only one of SQLI
7920: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 20 TE_ENABLE_STAT3
7930: 6f 72 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 or SQLITE_ENABLE
7940: 5f 53 54 41 54 34 20 63 61 6e 20 62 65 20 64 65 _STAT4 can be de
7950: 66 69 6e 65 64 2e 0a 2a 2a 20 50 72 69 6f 72 69 fined..** Priori
7960: 74 79 20 69 73 20 67 69 76 65 6e 20 74 6f 20 53 ty is given to S
7970: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 QLITE_ENABLE_STA
7980: 54 34 2e 20 20 49 66 20 65 69 74 68 65 72 20 61 T4. If either a
7990: 72 65 20 64 65 66 69 6e 65 64 2c 20 61 6c 73 6f re defined, also
79a0: 0a 2a 2a 20 64 65 66 69 6e 65 20 53 51 4c 49 54 .** define SQLIT
79b0: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f E_ENABLE_STAT3_O
79c0: 52 5f 53 54 41 54 34 0a 2a 2f 0a 23 69 66 64 65 R_STAT4.*/.#ifde
79d0: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
79e0: 53 54 41 54 34 0a 23 20 75 6e 64 65 66 20 53 51 STAT4.# undef SQ
79f0: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
7a00: 33 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 3.# define SQLIT
7a10: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f E_ENABLE_STAT3_O
7a20: 52 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 R_STAT4 1.#elif
7a30: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
7a40: 41 54 33 0a 23 20 64 65 66 69 6e 65 20 53 51 4c AT3.# define SQL
7a50: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
7a60: 5f 4f 52 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 _OR_STAT4 1.#eli
7a70: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
7a80: 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 STAT3_OR_STAT4.#
7a90: 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e undef SQLITE_EN
7aa0: 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 ABLE_STAT3_OR_ST
7ab0: 41 54 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a AT4.#endif../*.*
7ac0: 2a 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e * SELECTTRACE_EN
7ad0: 41 42 4c 45 44 20 77 69 6c 6c 20 62 65 20 65 69 ABLED will be ei
7ae0: 74 68 65 72 20 31 20 6f 72 20 30 20 64 65 70 65 ther 1 or 0 depe
7af0: 6e 64 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 nding on whether
7b00: 20 6f 72 20 6e 6f 74 0a 2a 2a 20 74 68 65 20 53 or not.** the S
7b10: 65 6c 65 63 74 20 71 75 65 72 79 20 67 65 6e 65 elect query gene
7b20: 72 61 74 6f 72 20 74 72 61 63 69 6e 67 20 6c 6f rator tracing lo
7b30: 67 69 63 20 69 73 20 74 75 72 6e 65 64 20 6f 6e gic is turned on
7b40: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
7b50: 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 (SQLITE_ENABLE_S
7b60: 45 4c 45 43 54 54 52 41 43 45 29 0a 23 20 64 65 ELECTTRACE).# de
7b70: 66 69 6e 65 20 53 45 4c 45 43 54 54 52 41 43 45 fine SELECTTRACE
7b80: 5f 45 4e 41 42 4c 45 44 20 31 0a 23 65 6c 73 65 _ENABLED 1.#else
7b90: 0a 23 20 64 65 66 69 6e 65 20 53 45 4c 45 43 54 .# define SELECT
7ba0: 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 30 0a TRACE_ENABLED 0.
7bb0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e #endif../*.** An
7bc0: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
7bd0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
7be0: 74 75 72 65 20 69 73 20 75 73 65 64 20 74 6f 20 ture is used to
7bf0: 73 74 6f 72 65 20 74 68 65 20 62 75 73 79 2d 68 store the busy-h
7c00: 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c 6c 62 61 andler.** callba
7c10: 63 6b 20 66 6f 72 20 61 20 67 69 76 65 6e 20 73 ck for a given s
7c20: 71 6c 69 74 65 20 68 61 6e 64 6c 65 2e 0a 2a 2a qlite handle..**
7c30: 0a 2a 2a 20 54 68 65 20 73 71 6c 69 74 65 2e 62 .** The sqlite.b
7c40: 75 73 79 48 61 6e 64 6c 65 72 20 6d 65 6d 62 65 usyHandler membe
7c50: 72 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 20 r of the sqlite
7c60: 73 74 72 75 63 74 20 63 6f 6e 74 61 69 6e 73 20 struct contains
7c70: 74 68 65 20 62 75 73 79 0a 2a 2a 20 63 61 6c 6c the busy.** call
7c80: 62 61 63 6b 20 66 6f 72 20 74 68 65 20 64 61 74 back for the dat
7c90: 61 62 61 73 65 20 68 61 6e 64 6c 65 2e 20 45 61 abase handle. Ea
7ca0: 63 68 20 70 61 67 65 72 20 6f 70 65 6e 65 64 20 ch pager opened
7cb0: 76 69 61 20 74 68 65 20 73 71 6c 69 74 65 0a 2a via the sqlite.*
7cc0: 2a 20 68 61 6e 64 6c 65 20 69 73 20 70 61 73 73 * handle is pass
7cd0: 65 64 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 ed a pointer to
7ce0: 73 71 6c 69 74 65 2e 62 75 73 79 48 61 6e 64 6c sqlite.busyHandl
7cf0: 65 72 2e 20 54 68 65 20 62 75 73 79 2d 68 61 6e er. The busy-han
7d00: 64 6c 65 72 0a 2a 2a 20 63 61 6c 6c 62 61 63 6b dler.** callback
7d10: 20 69 73 20 63 75 72 72 65 6e 74 6c 79 20 69 6e is currently in
7d20: 76 6f 6b 65 64 20 6f 6e 6c 79 20 66 72 6f 6d 20 voked only from
7d30: 77 69 74 68 69 6e 20 70 61 67 65 72 2e 63 2e 0a within pager.c..
7d40: 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
7d50: 74 20 42 75 73 79 48 61 6e 64 6c 65 72 20 42 75 t BusyHandler Bu
7d60: 73 79 48 61 6e 64 6c 65 72 3b 0a 73 74 72 75 63 syHandler;.struc
7d70: 74 20 42 75 73 79 48 61 6e 64 6c 65 72 20 7b 0a t BusyHandler {.
7d80: 20 20 69 6e 74 20 28 2a 78 42 75 73 79 48 61 6e int (*xBusyHan
7d90: 64 6c 65 72 29 28 76 6f 69 64 20 2a 2c 69 6e 74 dler)(void *,int
7da0: 29 3b 20 20 2f 2a 20 54 68 65 20 62 75 73 79 20 ); /* The busy
7db0: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f callback */. vo
7dc0: 69 64 20 2a 70 42 75 73 79 41 72 67 3b 20 20 20 id *pBusyArg;
7dd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7de0: 2f 2a 20 46 69 72 73 74 20 61 72 67 20 74 6f 20 /* First arg to
7df0: 62 75 73 79 20 63 61 6c 6c 62 61 63 6b 20 2a 2f busy callback */
7e00: 0a 20 20 69 6e 74 20 6e 42 75 73 79 3b 20 20 20 . int nBusy;
7e10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
7e20: 20 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d 65 6e /* Incremen
7e30: 74 65 64 20 77 69 74 68 20 65 61 63 68 20 62 75 ted with each bu
7e40: 73 79 20 63 61 6c 6c 20 2a 2f 0a 20 20 75 38 20 sy call */. u8
7e50: 62 45 78 74 72 61 46 69 6c 65 41 72 67 3b 20 20 bExtraFileArg;
7e60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
7e70: 2a 20 49 6e 63 6c 75 64 65 20 73 71 6c 69 74 65 * Include sqlite
7e80: 33 5f 66 69 6c 65 20 61 73 20 63 61 6c 6c 62 61 3_file as callba
7e90: 63 6b 20 61 72 67 20 2a 2f 0a 7d 3b 0a 0a 2f 2a ck arg */.};../*
7ea0: 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 .** Name of the
7eb0: 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 master database
7ec0: 74 61 62 6c 65 2e 20 20 54 68 65 20 6d 61 73 74 table. The mast
7ed0: 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 6c er database tabl
7ee0: 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 63 69 61 e.** is a specia
7ef0: 6c 20 74 61 62 6c 65 20 74 68 61 74 20 68 6f 6c l table that hol
7f00: 64 73 20 74 68 65 20 6e 61 6d 65 73 20 61 6e 64 ds the names and
7f10: 20 61 74 74 72 69 62 75 74 65 73 20 6f 66 20 61 attributes of a
7f20: 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 62 6c 65 ll.** user table
7f30: 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 0a 2a s and indices..*
7f40: 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 /.#define MASTER
7f50: 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 73 71 6c _NAME "sql
7f60: 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 64 65 66 ite_master".#def
7f70: 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 45 52 5f ine TEMP_MASTER_
7f80: 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 5f 74 65 NAME "sqlite_te
7f90: 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f 2a 0a 2a mp_master"../*.*
7fa0: 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 67 65 20 * The root-page
7fb0: 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 of the master da
7fc0: 74 61 62 61 73 65 20 74 61 62 6c 65 2e 0a 2a 2f tabase table..*/
7fd0: 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 5f .#define MASTER_
7fe0: 52 4f 4f 54 20 20 20 20 20 20 20 31 0a 0a 2f 2a ROOT 1../*
7ff0: 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 .** The name of
8000: 74 68 65 20 73 63 68 65 6d 61 20 74 61 62 6c 65 the schema table
8010: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 ..*/.#define SCH
8020: 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 20 28 28 EMA_TABLE(x) ((
8030: 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 26 26 28 !OMIT_TEMPDB)&&(
8040: 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 53 54 45 x==1)?TEMP_MASTE
8050: 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 5f 4e 41 R_NAME:MASTER_NA
8060: 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 63 6f 6e ME)../*.** A con
8070: 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 6f 20 74 venience macro t
8080: 68 61 74 20 72 65 74 75 72 6e 73 20 74 68 65 20 hat returns the
8090: 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e number of elemen
80a0: 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 72 72 61 ts in.** an arra
80b0: 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 41 72 y..*/.#define Ar
80c0: 72 61 79 53 69 7a 65 28 58 29 20 20 20 20 28 28 raySize(X) ((
80d0: 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 29 2f 73 int)(sizeof(X)/s
80e0: 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 0a 0a 2f izeof(X[0])))../
80f0: 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 *.** Determine i
8100: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 69 f the argument i
8110: 73 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f s a power of two
8120: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 6f .*/.#define IsPo
8130: 77 65 72 4f 66 54 77 6f 28 58 29 20 28 28 28 58 werOfTwo(X) (((X
8140: 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 29 0a 0a )&((X)-1))==0)..
8150: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
8160: 69 6e 67 20 76 61 6c 75 65 20 61 73 20 61 20 64 ing value as a d
8170: 65 73 74 72 75 63 74 6f 72 20 6d 65 61 6e 73 20 estructor means
8180: 74 6f 20 75 73 65 20 73 71 6c 69 74 65 33 44 62 to use sqlite3Db
8190: 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 65 20 73 Free()..** The s
81a0: 71 6c 69 74 65 33 44 62 46 72 65 65 28 29 20 72 qlite3DbFree() r
81b0: 6f 75 74 69 6e 65 20 72 65 71 75 69 72 65 73 20 outine requires
81c0: 74 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 69 two parameters i
81d0: 6e 73 74 65 61 64 20 6f 66 20 74 68 65 0a 2a 2a nstead of the.**
81e0: 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 72 20 74 one parameter t
81f0: 68 61 74 20 64 65 73 74 72 75 63 74 6f 72 73 20 hat destructors
8200: 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 2e 20 20 normally want.
8210: 53 6f 20 77 65 20 68 61 76 65 20 74 6f 20 69 6e So we have to in
8220: 74 72 6f 64 75 63 65 0a 2a 2a 20 74 68 69 73 20 troduce.** this
8230: 6d 61 67 69 63 20 76 61 6c 75 65 20 74 68 61 74 magic value that
8240: 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f 77 73 20 the code knows
8250: 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 66 65 72 to handle differ
8260: 65 6e 74 6c 79 2e 20 20 41 6e 79 0a 2a 2a 20 70 ently. Any.** p
8270: 6f 69 6e 74 65 72 20 77 69 6c 6c 20 77 6f 72 6b ointer will work
8280: 20 68 65 72 65 20 61 73 20 6c 6f 6e 67 20 61 73 here as long as
8290: 20 69 74 20 69 73 20 64 69 73 74 69 6e 63 74 20 it is distinct
82a0: 66 72 6f 6d 20 53 51 4c 49 54 45 5f 53 54 41 54 from SQLITE_STAT
82b0: 49 43 0a 2a 2a 20 61 6e 64 20 53 51 4c 49 54 45 IC.** and SQLITE
82c0: 5f 54 52 41 4e 53 49 45 4e 54 2e 0a 2a 2f 0a 23 _TRANSIENT..*/.#
82d0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 59 define SQLITE_DY
82e0: 4e 41 4d 49 43 20 20 20 28 28 73 71 6c 69 74 65 NAMIC ((sqlite
82f0: 33 5f 64 65 73 74 72 75 63 74 6f 72 5f 74 79 70 3_destructor_typ
8300: 65 29 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 53 e)sqlite3MallocS
8310: 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 57 68 65 6e ize)../*.** When
8320: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 SQLITE_OMIT_WSD
8330: 20 69 73 20 64 65 66 69 6e 65 64 2c 20 69 74 20 is defined, it
8340: 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 74 means that the t
8350: 61 72 67 65 74 20 70 6c 61 74 66 6f 72 6d 20 64 arget platform d
8360: 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 75 70 70 6f oes.** not suppo
8370: 72 74 20 57 72 69 74 61 62 6c 65 20 53 74 61 74 rt Writable Stat
8380: 69 63 20 44 61 74 61 20 28 57 53 44 29 20 73 75 ic Data (WSD) su
8390: 63 68 20 61 73 20 67 6c 6f 62 61 6c 20 61 6e 64 ch as global and
83a0: 20 73 74 61 74 69 63 20 76 61 72 69 61 62 6c 65 static variable
83b0: 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 72 69 61 62 s..** All variab
83c0: 6c 65 73 20 6d 75 73 74 20 65 69 74 68 65 72 20 les must either
83d0: 62 65 20 6f 6e 20 74 68 65 20 73 74 61 63 6b 20 be on the stack
83e0: 6f 72 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 61 or dynamically a
83f0: 6c 6c 6f 63 61 74 65 64 20 66 72 6f 6d 0a 2a 2a llocated from.**
8400: 20 74 68 65 20 68 65 61 70 2e 20 20 57 68 65 6e the heap. When
8410: 20 57 53 44 20 69 73 20 75 6e 73 75 70 70 6f 72 WSD is unsuppor
8420: 74 65 64 2c 20 74 68 65 20 76 61 72 69 61 62 6c ted, the variabl
8430: 65 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 20 73 e declarations s
8440: 63 61 74 74 65 72 65 64 0a 2a 2a 20 74 68 72 6f cattered.** thro
8450: 75 67 68 6f 75 74 20 74 68 65 20 53 51 4c 69 74 ughout the SQLit
8460: 65 20 63 6f 64 65 20 6d 75 73 74 20 62 65 63 6f e code must beco
8470: 6d 65 20 63 6f 6e 73 74 61 6e 74 73 20 69 6e 73 me constants ins
8480: 74 65 61 64 2e 20 20 54 68 65 20 53 51 4c 49 54 tead. The SQLIT
8490: 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 72 6f 20 69 E_WSD.** macro i
84a0: 73 20 75 73 65 64 20 66 6f 72 20 74 68 69 73 20 s used for this
84b0: 70 75 72 70 6f 73 65 2e 20 20 41 6e 64 20 69 6e purpose. And in
84c0: 73 74 65 61 64 20 6f 66 20 72 65 66 65 72 65 6e stead of referen
84d0: 63 69 6e 67 20 74 68 65 20 76 61 72 69 61 62 6c cing the variabl
84e0: 65 0a 2a 2a 20 64 69 72 65 63 74 6c 79 2c 20 77 e.** directly, w
84f0: 65 20 75 73 65 20 69 74 73 20 63 6f 6e 73 74 61 e use its consta
8500: 6e 74 20 61 73 20 61 20 6b 65 79 20 74 6f 20 6c nt as a key to l
8510: 6f 6f 6b 75 70 20 74 68 65 20 72 75 6e 2d 74 69 ookup the run-ti
8520: 6d 65 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 me allocated.**
8530: 62 75 66 66 65 72 20 74 68 61 74 20 68 6f 6c 64 buffer that hold
8540: 73 20 72 65 61 6c 20 76 61 72 69 61 62 6c 65 2e s real variable.
8550: 20 20 54 68 65 20 63 6f 6e 73 74 61 6e 74 20 69 The constant i
8560: 73 20 61 6c 73 6f 20 74 68 65 20 69 6e 69 74 69 s also the initi
8570: 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f 72 20 74 68 alizer.** for th
8580: 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 e run-time alloc
8590: 61 74 65 64 20 62 75 66 66 65 72 2e 0a 2a 2a 0a ated buffer..**.
85a0: 2a 2a 20 49 6e 20 74 68 65 20 75 73 75 61 6c 20 ** In the usual
85b0: 63 61 73 65 20 77 68 65 72 65 20 57 53 44 20 69 case where WSD i
85c0: 73 20 73 75 70 70 6f 72 74 65 64 2c 20 74 68 65 s supported, the
85d0: 20 53 51 4c 49 54 45 5f 57 53 44 20 61 6e 64 20 SQLITE_WSD and
85e0: 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 63 72 6f 73 GLOBAL.** macros
85f0: 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f 70 73 20 61 become no-ops a
8600: 6e 64 20 68 61 76 65 20 7a 65 72 6f 20 70 65 72 nd have zero per
8610: 66 6f 72 6d 61 6e 63 65 20 69 6d 70 61 63 74 2e formance impact.
8620: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
8630: 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 20 23 64 65 E_OMIT_WSD. #de
8640: 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 53 44 20 fine SQLITE_WSD
8650: 63 6f 6e 73 74 0a 20 20 23 64 65 66 69 6e 65 20 const. #define
8660: 47 4c 4f 42 41 4c 28 74 2c 76 29 20 28 2a 28 74 GLOBAL(t,v) (*(t
8670: 2a 29 73 71 6c 69 74 65 33 5f 77 73 64 5f 66 69 *)sqlite3_wsd_fi
8680: 6e 64 28 28 76 6f 69 64 2a 29 26 28 76 29 2c 20 nd((void*)&(v),
8690: 73 69 7a 65 6f 66 28 76 29 29 29 0a 20 20 23 64 sizeof(v))). #d
86a0: 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 6c 6f efine sqlite3Glo
86b0: 62 61 6c 43 6f 6e 66 69 67 20 47 4c 4f 42 41 4c balConfig GLOBAL
86c0: 28 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 43 (struct Sqlite3C
86d0: 6f 6e 66 69 67 2c 20 73 71 6c 69 74 65 33 43 6f onfig, sqlite3Co
86e0: 6e 66 69 67 29 0a 20 20 69 6e 74 20 73 71 6c 69 nfig). int sqli
86f0: 74 65 33 5f 77 73 64 5f 69 6e 69 74 28 69 6e 74 te3_wsd_init(int
8700: 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a 20 20 76 6f N, int J);. vo
8710: 69 64 20 2a 73 71 6c 69 74 65 33 5f 77 73 64 5f id *sqlite3_wsd_
8720: 66 69 6e 64 28 76 6f 69 64 20 2a 4b 2c 20 69 6e find(void *K, in
8730: 74 20 4c 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 t L);.#else. #d
8740: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 53 44 efine SQLITE_WSD
8750: 0a 20 20 23 64 65 66 69 6e 65 20 47 4c 4f 42 41 . #define GLOBA
8760: 4c 28 74 2c 76 29 20 76 0a 20 20 23 64 65 66 69 L(t,v) v. #defi
8770: 6e 65 20 73 71 6c 69 74 65 33 47 6c 6f 62 61 6c ne sqlite3Global
8780: 43 6f 6e 66 69 67 20 73 71 6c 69 74 65 33 43 6f Config sqlite3Co
8790: 6e 66 69 67 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a nfig.#endif../*.
87a0: 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ** The following
87b0: 20 6d 61 63 72 6f 73 20 61 72 65 20 75 73 65 64 macros are used
87c0: 20 74 6f 20 73 75 70 70 72 65 73 73 20 63 6f 6d to suppress com
87d0: 70 69 6c 65 72 20 77 61 72 6e 69 6e 67 73 20 61 piler warnings a
87e0: 6e 64 20 74 6f 0a 2a 2a 20 6d 61 6b 65 20 69 74 nd to.** make it
87f0: 20 63 6c 65 61 72 20 74 6f 20 68 75 6d 61 6e 20 clear to human
8800: 72 65 61 64 65 72 73 20 77 68 65 6e 20 61 20 66 readers when a f
8810: 75 6e 63 74 69 6f 6e 20 70 61 72 61 6d 65 74 65 unction paramete
8820: 72 20 69 73 20 64 65 6c 69 62 65 72 61 74 65 6c r is deliberatel
8830: 79 0a 2a 2a 20 6c 65 66 74 20 75 6e 75 73 65 64 y.** left unused
8840: 20 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 within the body
8850: 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2e 20 of a function.
8860: 54 68 69 73 20 75 73 75 61 6c 6c 79 20 68 61 70 This usually hap
8870: 70 65 6e 73 20 77 68 65 6e 0a 2a 2a 20 61 20 66 pens when.** a f
8880: 75 6e 63 74 69 6f 6e 20 69 73 20 63 61 6c 6c 65 unction is calle
8890: 64 20 76 69 61 20 61 20 66 75 6e 63 74 69 6f 6e d via a function
88a0: 20 70 6f 69 6e 74 65 72 2e 20 46 6f 72 20 65 78 pointer. For ex
88b0: 61 6d 70 6c 65 20 74 68 65 0a 2a 2a 20 69 6d 70 ample the.** imp
88c0: 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61 lementation of a
88d0: 6e 20 53 51 4c 20 61 67 67 72 65 67 61 74 65 20 n SQL aggregate
88e0: 73 74 65 70 20 63 61 6c 6c 62 61 63 6b 20 6d 61 step callback ma
88f0: 79 20 6e 6f 74 20 75 73 65 20 74 68 65 0a 2a 2a y not use the.**
8900: 20 70 61 72 61 6d 65 74 65 72 20 69 6e 64 69 63 parameter indic
8910: 61 74 69 6e 67 20 74 68 65 20 6e 75 6d 62 65 72 ating the number
8920: 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 70 61 of arguments pa
8930: 73 73 65 64 20 74 6f 20 74 68 65 20 61 67 67 72 ssed to the aggr
8940: 65 67 61 74 65 2c 0a 2a 2a 20 69 66 20 69 74 20 egate,.** if it
8950: 6b 6e 6f 77 73 20 74 68 61 74 20 74 68 69 73 20 knows that this
8960: 69 73 20 65 6e 66 6f 72 63 65 64 20 65 6c 73 65 is enforced else
8970: 77 68 65 72 65 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 where..**.** Whe
8980: 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 n a function par
8990: 61 6d 65 74 65 72 20 69 73 20 6e 6f 74 20 75 73 ameter is not us
89a0: 65 64 20 61 74 20 61 6c 6c 20 77 69 74 68 69 6e ed at all within
89b0: 20 74 68 65 20 62 6f 64 79 20 6f 66 20 61 20 66 the body of a f
89c0: 75 6e 63 74 69 6f 6e 2c 0a 2a 2a 20 69 74 20 69 unction,.** it i
89d0: 73 20 67 65 6e 65 72 61 6c 6c 79 20 6e 61 6d 65 s generally name
89e0: 64 20 22 4e 6f 74 55 73 65 64 22 20 6f 72 20 22 d "NotUsed" or "
89f0: 4e 6f 74 55 73 65 64 32 22 20 74 6f 20 6d 61 6b NotUsed2" to mak
8a00: 65 20 74 68 69 6e 67 73 20 65 76 65 6e 20 63 6c e things even cl
8a10: 65 61 72 65 72 2e 0a 2a 2a 20 48 6f 77 65 76 65 earer..** Howeve
8a20: 72 2c 20 74 68 65 73 65 20 6d 61 63 72 6f 73 20 r, these macros
8a30: 6d 61 79 20 61 6c 73 6f 20 62 65 20 75 73 65 64 may also be used
8a40: 20 74 6f 20 73 75 70 70 72 65 73 73 20 77 61 72 to suppress war
8a50: 6e 69 6e 67 73 20 72 65 6c 61 74 65 64 20 74 6f nings related to
8a60: 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 73 20 74 .** parameters t
8a70: 68 61 74 20 6d 61 79 20 6f 72 20 6d 61 79 20 6e hat may or may n
8a80: 6f 74 20 62 65 20 75 73 65 64 20 64 65 70 65 6e ot be used depen
8a90: 64 69 6e 67 20 6f 6e 20 63 6f 6d 70 69 6c 61 74 ding on compilat
8aa0: 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a 2a 2a 20 ion options..**
8ab0: 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 6f 73 For example thos
8ac0: 65 20 70 61 72 61 6d 65 74 65 72 73 20 6f 6e 6c e parameters onl
8ad0: 79 20 75 73 65 64 20 69 6e 20 61 73 73 65 72 74 y used in assert
8ae0: 28 29 20 73 74 61 74 65 6d 65 6e 74 73 2e 20 49 () statements. I
8af0: 6e 20 74 68 65 73 65 0a 2a 2a 20 63 61 73 65 73 n these.** cases
8b00: 20 74 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 the parameters
8b10: 61 72 65 20 6e 61 6d 65 64 20 61 73 20 70 65 72 are named as per
8b20: 20 74 68 65 20 75 73 75 61 6c 20 63 6f 6e 76 65 the usual conve
8b30: 6e 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 66 69 ntions..*/.#defi
8b40: 6e 65 20 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 ne UNUSED_PARAME
8b50: 54 45 52 28 78 29 20 28 76 6f 69 64 29 28 78 29 TER(x) (void)(x)
8b60: 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 5f .#define UNUSED_
8b70: 50 41 52 41 4d 45 54 45 52 32 28 78 2c 79 29 20 PARAMETER2(x,y)
8b80: 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 UNUSED_PARAMETER
8b90: 28 78 29 2c 55 4e 55 53 45 44 5f 50 41 52 41 4d (x),UNUSED_PARAM
8ba0: 45 54 45 52 28 79 29 0a 0a 2f 2a 0a 2a 2a 20 46 ETER(y)../*.** F
8bb0: 6f 72 77 61 72 64 20 72 65 66 65 72 65 6e 63 65 orward reference
8bc0: 73 20 74 6f 20 73 74 72 75 63 74 75 72 65 73 0a s to structures.
8bd0: 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
8be0: 74 20 41 67 67 49 6e 66 6f 20 41 67 67 49 6e 66 t AggInfo AggInf
8bf0: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
8c00: 74 20 41 75 74 68 43 6f 6e 74 65 78 74 20 41 75 t AuthContext Au
8c10: 74 68 43 6f 6e 74 65 78 74 3b 0a 74 79 70 65 64 thContext;.typed
8c20: 65 66 20 73 74 72 75 63 74 20 41 75 74 6f 69 6e ef struct Autoin
8c30: 63 49 6e 66 6f 20 41 75 74 6f 69 6e 63 49 6e 66 cInfo AutoincInf
8c40: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
8c50: 74 20 42 69 74 76 65 63 20 42 69 74 76 65 63 3b t Bitvec Bitvec;
8c60: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8c70: 43 6f 6c 6c 53 65 71 20 43 6f 6c 6c 53 65 71 3b CollSeq CollSeq;
8c80: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8c90: 43 6f 6c 75 6d 6e 20 43 6f 6c 75 6d 6e 3b 0a 74 Column Column;.t
8ca0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 44 62 ypedef struct Db
8cb0: 20 44 62 3b 0a 74 79 70 65 64 65 66 20 73 74 72 Db;.typedef str
8cc0: 75 63 74 20 53 63 68 65 6d 61 20 53 63 68 65 6d uct Schema Schem
8cd0: 61 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 a;.typedef struc
8ce0: 74 20 45 78 70 72 20 45 78 70 72 3b 0a 74 79 70 t Expr Expr;.typ
8cf0: 65 64 65 66 20 73 74 72 75 63 74 20 45 78 70 72 edef struct Expr
8d00: 4c 69 73 74 20 45 78 70 72 4c 69 73 74 3b 0a 74 List ExprList;.t
8d10: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 4b ypedef struct FK
8d20: 65 79 20 46 4b 65 79 3b 0a 74 79 70 65 64 65 66 ey FKey;.typedef
8d30: 20 73 74 72 75 63 74 20 46 75 6e 63 44 65 73 74 struct FuncDest
8d40: 72 75 63 74 6f 72 20 46 75 6e 63 44 65 73 74 72 ructor FuncDestr
8d50: 75 63 74 6f 72 3b 0a 74 79 70 65 64 65 66 20 73 uctor;.typedef s
8d60: 74 72 75 63 74 20 46 75 6e 63 44 65 66 20 46 75 truct FuncDef Fu
8d70: 6e 63 44 65 66 3b 0a 74 79 70 65 64 65 66 20 73 ncDef;.typedef s
8d80: 74 72 75 63 74 20 46 75 6e 63 44 65 66 48 61 73 truct FuncDefHas
8d90: 68 20 46 75 6e 63 44 65 66 48 61 73 68 3b 0a 74 h FuncDefHash;.t
8da0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 49 64 ypedef struct Id
8db0: 4c 69 73 74 20 49 64 4c 69 73 74 3b 0a 74 79 70 List IdList;.typ
8dc0: 65 64 65 66 20 73 74 72 75 63 74 20 49 6e 64 65 edef struct Inde
8dd0: 78 20 49 6e 64 65 78 3b 0a 74 79 70 65 64 65 66 x Index;.typedef
8de0: 20 73 74 72 75 63 74 20 49 6e 64 65 78 53 61 6d struct IndexSam
8df0: 70 6c 65 20 49 6e 64 65 78 53 61 6d 70 6c 65 3b ple IndexSample;
8e00: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8e10: 4b 65 79 43 6c 61 73 73 20 4b 65 79 43 6c 61 73 KeyClass KeyClas
8e20: 73 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 s;.typedef struc
8e30: 74 20 4b 65 79 49 6e 66 6f 20 4b 65 79 49 6e 66 t KeyInfo KeyInf
8e40: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
8e50: 74 20 4c 6f 6f 6b 61 73 69 64 65 20 4c 6f 6f 6b t Lookaside Look
8e60: 61 73 69 64 65 3b 0a 74 79 70 65 64 65 66 20 73 aside;.typedef s
8e70: 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 53 truct LookasideS
8e80: 6c 6f 74 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f lot LookasideSlo
8e90: 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 t;.typedef struc
8ea0: 74 20 4d 6f 64 75 6c 65 20 4d 6f 64 75 6c 65 3b t Module Module;
8eb0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8ec0: 4e 61 6d 65 43 6f 6e 74 65 78 74 20 4e 61 6d 65 NameContext Name
8ed0: 43 6f 6e 74 65 78 74 3b 0a 74 79 70 65 64 65 66 Context;.typedef
8ee0: 20 73 74 72 75 63 74 20 50 61 72 73 65 20 50 61 struct Parse Pa
8ef0: 72 73 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 rse;.typedef str
8f00: 75 63 74 20 50 72 65 55 70 64 61 74 65 20 50 72 uct PreUpdate Pr
8f10: 65 55 70 64 61 74 65 3b 0a 74 79 70 65 64 65 66 eUpdate;.typedef
8f20: 20 73 74 72 75 63 74 20 50 72 69 6e 74 66 41 72 struct PrintfAr
8f30: 67 75 6d 65 6e 74 73 20 50 72 69 6e 74 66 41 72 guments PrintfAr
8f40: 67 75 6d 65 6e 74 73 3b 0a 74 79 70 65 64 65 66 guments;.typedef
8f50: 20 73 74 72 75 63 74 20 52 6f 77 53 65 74 20 52 struct RowSet R
8f60: 6f 77 53 65 74 3b 0a 74 79 70 65 64 65 66 20 73 owSet;.typedef s
8f70: 74 72 75 63 74 20 53 61 76 65 70 6f 69 6e 74 20 truct Savepoint
8f80: 53 61 76 65 70 6f 69 6e 74 3b 0a 74 79 70 65 64 Savepoint;.typed
8f90: 65 66 20 73 74 72 75 63 74 20 53 65 6c 65 63 74 ef struct Select
8fa0: 20 53 65 6c 65 63 74 3b 0a 74 79 70 65 64 65 66 Select;.typedef
8fb0: 20 73 74 72 75 63 74 20 53 51 4c 69 74 65 54 68 struct SQLiteTh
8fc0: 72 65 61 64 20 53 51 4c 69 74 65 54 68 72 65 61 read SQLiteThrea
8fd0: 64 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 d;.typedef struc
8fe0: 74 20 53 65 6c 65 63 74 44 65 73 74 20 53 65 6c t SelectDest Sel
8ff0: 65 63 74 44 65 73 74 3b 0a 74 79 70 65 64 65 66 ectDest;.typedef
9000: 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 20 struct SrcList
9010: 53 72 63 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 SrcList;.typedef
9020: 20 73 74 72 75 63 74 20 53 74 72 41 63 63 75 6d struct StrAccum
9030: 20 53 74 72 41 63 63 75 6d 3b 0a 74 79 70 65 64 StrAccum;.typed
9040: 65 66 20 73 74 72 75 63 74 20 54 61 62 6c 65 20 ef struct Table
9050: 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 Table;.typedef s
9060: 74 72 75 63 74 20 54 61 62 6c 65 4c 6f 63 6b 20 truct TableLock
9070: 54 61 62 6c 65 4c 6f 63 6b 3b 0a 74 79 70 65 64 TableLock;.typed
9080: 65 66 20 73 74 72 75 63 74 20 54 6f 6b 65 6e 20 ef struct Token
9090: 54 6f 6b 65 6e 3b 0a 74 79 70 65 64 65 66 20 73 Token;.typedef s
90a0: 74 72 75 63 74 20 54 72 65 65 56 69 65 77 20 54 truct TreeView T
90b0: 72 65 65 56 69 65 77 3b 0a 74 79 70 65 64 65 66 reeView;.typedef
90c0: 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 20 struct Trigger
90d0: 54 72 69 67 67 65 72 3b 0a 74 79 70 65 64 65 66 Trigger;.typedef
90e0: 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 50 struct TriggerP
90f0: 72 67 20 54 72 69 67 67 65 72 50 72 67 3b 0a 74 rg TriggerPrg;.t
9100: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 72 ypedef struct Tr
9110: 69 67 67 65 72 53 74 65 70 20 54 72 69 67 67 65 iggerStep Trigge
9120: 72 53 74 65 70 3b 0a 74 79 70 65 64 65 66 20 73 rStep;.typedef s
9130: 74 72 75 63 74 20 55 6e 70 61 63 6b 65 64 52 65 truct UnpackedRe
9140: 63 6f 72 64 20 55 6e 70 61 63 6b 65 64 52 65 63 cord UnpackedRec
9150: 6f 72 64 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ord;.typedef str
9160: 75 63 74 20 55 70 73 65 72 74 20 55 70 73 65 72 uct Upsert Upser
9170: 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 t;.typedef struc
9180: 74 20 56 54 61 62 6c 65 20 56 54 61 62 6c 65 3b t VTable VTable;
9190: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
91a0: 56 74 61 62 43 74 78 20 56 74 61 62 43 74 78 3b VtabCtx VtabCtx;
91b0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
91c0: 57 61 6c 6b 65 72 20 57 61 6c 6b 65 72 3b 0a 74 Walker Walker;.t
91d0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 57 68 ypedef struct Wh
91e0: 65 72 65 49 6e 66 6f 20 57 68 65 72 65 49 6e 66 ereInfo WhereInf
91f0: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
9200: 74 20 57 69 74 68 20 57 69 74 68 3b 0a 0a 2f 2a t With With;../*
9210: 20 41 20 56 4c 69 73 74 20 6f 62 6a 65 63 74 20 A VList object
9220: 72 65 63 6f 72 64 73 20 61 20 6d 61 70 70 69 6e records a mappin
9230: 67 20 62 65 74 77 65 65 6e 20 70 61 72 61 6d 65 g between parame
9240: 74 65 72 73 2f 76 61 72 69 61 62 6c 65 73 2f 77 ters/variables/w
9250: 69 6c 64 63 61 72 64 73 0a 2a 2a 20 69 6e 20 74 ildcards.** in t
9260: 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 he SQL statement
9270: 20 28 73 75 63 68 20 61 73 20 24 61 62 63 2c 20 (such as $abc,
9280: 40 70 71 72 2c 20 6f 72 20 3a 78 79 7a 29 20 61 @pqr, or :xyz) a
9290: 6e 64 20 74 68 65 20 69 6e 74 65 67 65 72 0a 2a nd the integer.*
92a0: 2a 20 76 61 72 69 61 62 6c 65 20 6e 75 6d 62 65 * variable numbe
92b0: 72 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 r associated wit
92c0: 68 20 74 68 61 74 20 70 61 72 61 6d 65 74 65 72 h that parameter
92d0: 2e 20 20 53 65 65 20 74 68 65 20 66 6f 72 6d 61 . See the forma
92e0: 74 20 64 65 73 63 72 69 70 74 69 6f 6e 0a 2a 2a t description.**
92f0: 20 6f 6e 20 74 68 65 20 73 71 6c 69 74 65 33 56 on the sqlite3V
9300: 4c 69 73 74 41 64 64 28 29 20 72 6f 75 74 69 6e ListAdd() routin
9310: 65 20 66 6f 72 20 6d 6f 72 65 20 69 6e 66 6f 72 e for more infor
9320: 6d 61 74 69 6f 6e 2e 20 20 41 20 56 4c 69 73 74 mation. A VList
9330: 20 69 73 20 72 65 61 6c 6c 79 0a 2a 2a 20 6a 75 is really.** ju
9340: 73 74 20 61 6e 20 61 72 72 61 79 20 6f 66 20 69 st an array of i
9350: 6e 74 65 67 65 72 73 2e 0a 2a 2f 0a 74 79 70 65 ntegers..*/.type
9360: 64 65 66 20 69 6e 74 20 56 4c 69 73 74 3b 0a 0a def int VList;..
9370: 2f 2a 0a 2a 2a 20 44 65 66 65 72 20 73 6f 75 72 /*.** Defer sour
9380: 63 69 6e 67 20 76 64 62 65 2e 68 20 61 6e 64 20 cing vdbe.h and
9390: 62 74 72 65 65 2e 68 20 75 6e 74 69 6c 20 61 66 btree.h until af
93a0: 74 65 72 20 74 68 65 20 22 75 38 22 20 61 6e 64 ter the "u8" and
93b0: 0a 2a 2a 20 22 42 75 73 79 48 61 6e 64 6c 65 72 .** "BusyHandler
93c0: 22 20 74 79 70 65 64 65 66 73 2e 20 76 64 62 65 " typedefs. vdbe
93d0: 2e 68 20 61 6c 73 6f 20 72 65 71 75 69 72 65 73 .h also requires
93e0: 20 61 20 66 65 77 20 6f 66 20 74 68 65 20 6f 70 a few of the op
93f0: 61 71 75 65 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 aque.** pointer
9400: 74 79 70 65 73 20 28 69 2e 65 2e 20 46 75 6e 63 types (i.e. Func
9410: 44 65 66 29 20 64 65 66 69 6e 65 64 20 61 62 6f Def) defined abo
9420: 76 65 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 ve..*/.#include
9430: 22 62 74 72 65 65 2e 68 22 0a 23 69 6e 63 6c 75 "btree.h".#inclu
9440: 64 65 20 22 76 64 62 65 2e 68 22 0a 23 69 6e 63 de "vdbe.h".#inc
9450: 6c 75 64 65 20 22 70 61 67 65 72 2e 68 22 0a 23 lude "pager.h".#
9460: 69 6e 63 6c 75 64 65 20 22 70 63 61 63 68 65 2e include "pcache.
9470: 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 6f 73 2e h".#include "os.
9480: 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 6d 75 74 h".#include "mut
9490: 65 78 2e 68 22 0a 0a 2f 2a 20 54 68 65 20 53 51 ex.h"../* The SQ
94a0: 4c 49 54 45 5f 45 58 54 52 41 5f 44 55 52 41 42 LITE_EXTRA_DURAB
94b0: 4c 45 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 LE compile-time
94c0: 6f 70 74 69 6f 6e 20 75 73 65 64 20 74 6f 20 73 option used to s
94d0: 65 74 20 74 68 65 20 64 65 66 61 75 6c 74 0a 2a et the default.*
94e0: 2a 20 73 79 6e 63 68 72 6f 6e 6f 75 73 20 73 65 * synchronous se
94f0: 74 74 69 6e 67 20 74 6f 20 45 58 54 52 41 2e 20 tting to EXTRA.
9500: 20 49 74 20 69 73 20 6e 6f 20 6c 6f 6e 67 65 72 It is no longer
9510: 20 73 75 70 70 6f 72 74 65 64 2e 0a 2a 2f 0a 23 supported..*/.#
9520: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 58 54 ifdef SQLITE_EXT
9530: 52 41 5f 44 55 52 41 42 4c 45 0a 23 20 77 61 72 RA_DURABLE.# war
9540: 6e 69 6e 67 20 55 73 65 20 53 51 4c 49 54 45 5f ning Use SQLITE_
9550: 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e DEFAULT_SYNCHRON
9560: 4f 55 53 3d 33 20 69 6e 73 74 65 61 64 20 6f 66 OUS=3 instead of
9570: 20 53 51 4c 49 54 45 5f 45 58 54 52 41 5f 44 55 SQLITE_EXTRA_DU
9580: 52 41 42 4c 45 0a 23 20 64 65 66 69 6e 65 20 53 RABLE.# define S
9590: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 QLITE_DEFAULT_SY
95a0: 4e 43 48 52 4f 4e 4f 55 53 20 33 0a 23 65 6e 64 NCHRONOUS 3.#end
95b0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 61 75 6c if../*.** Defaul
95c0: 74 20 73 79 6e 63 68 72 6f 6e 6f 75 73 20 6c 65 t synchronous le
95d0: 76 65 6c 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 vels..**.** Note
95e0: 20 74 68 61 74 20 28 66 6f 72 20 68 69 73 74 6f that (for histo
95f0: 72 63 61 6c 20 72 65 61 73 6f 6e 73 29 20 74 68 rcal reasons) th
9600: 65 20 50 41 47 45 52 5f 53 59 4e 43 48 52 4f 4e e PAGER_SYNCHRON
9610: 4f 55 53 5f 2a 20 6d 61 63 72 6f 73 20 64 69 66 OUS_* macros dif
9620: 66 65 72 0a 2a 2a 20 66 72 6f 6d 20 74 68 65 20 fer.** from the
9630: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 SQLITE_DEFAULT_S
9640: 59 4e 43 48 52 4f 4e 4f 55 53 20 76 61 6c 75 65 YNCHRONOUS value
9650: 20 62 79 20 31 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 by 1..**.**
9660: 20 20 20 20 20 20 20 50 41 47 45 52 5f 53 59 4e PAGER_SYN
9670: 43 48 52 4f 4e 4f 55 53 20 20 20 20 20 20 20 44 CHRONOUS D
9680: 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f EFAULT_SYNCHRONO
9690: 55 53 0a 2a 2a 20 20 20 4f 46 46 20 20 20 20 20 US.** OFF
96a0: 20 20 20 20 20 20 31 20 20 20 20 20 20 20 20 20 1
96b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
96c0: 30 0a 2a 2a 20 20 20 4e 4f 52 4d 41 4c 20 20 20 0.** NORMAL
96d0: 20 20 20 20 20 32 20 20 20 20 20 20 20 20 20 20 2
96e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 31 1
96f0: 0a 2a 2a 20 20 20 46 55 4c 4c 20 20 20 20 20 20 .** FULL
9700: 20 20 20 20 33 20 20 20 20 20 20 20 20 20 20 20 3
9710: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 32 0a 2.
9720: 2a 2a 20 20 20 45 58 54 52 41 20 20 20 20 20 20 ** EXTRA
9730: 20 20 20 34 20 20 20 20 20 20 20 20 20 20 20 20 4
9740: 20 20 20 20 20 20 20 20 20 20 20 20 20 33 0a 2a 3.*
9750: 2a 0a 2a 2a 20 54 68 65 20 22 50 52 41 47 4d 41 *.** The "PRAGMA
9760: 20 73 79 6e 63 68 72 6f 6e 6f 75 73 22 20 73 74 synchronous" st
9770: 61 74 65 6d 65 6e 74 20 61 6c 73 6f 20 75 73 65 atement also use
9780: 73 20 74 68 65 20 7a 65 72 6f 2d 62 61 73 65 64 s the zero-based
9790: 20 6e 75 6d 62 65 72 73 2e 0a 2a 2a 20 49 6e 20 numbers..** In
97a0: 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 74 68 65 other words, the
97b0: 20 7a 65 72 6f 2d 62 61 73 65 64 20 6e 75 6d 62 zero-based numb
97c0: 65 72 73 20 61 72 65 20 75 73 65 64 20 66 6f 72 ers are used for
97d0: 20 61 6c 6c 20 65 78 74 65 72 6e 61 6c 20 69 6e all external in
97e0: 74 65 72 66 61 63 65 73 0a 2a 2a 20 61 6e 64 20 terfaces.** and
97f0: 74 68 65 20 6f 6e 65 2d 62 61 73 65 64 20 76 61 the one-based va
9800: 6c 75 65 73 20 61 72 65 20 75 73 65 64 20 69 6e lues are used in
9810: 74 65 72 6e 61 6c 6c 79 2e 0a 2a 2f 0a 23 69 66 ternally..*/.#if
9820: 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 ndef SQLITE_DEFA
9830: 55 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 0a ULT_SYNCHRONOUS.
9840: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
9850: 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e DEFAULT_SYNCHRON
9860: 4f 55 53 20 32 0a 23 65 6e 64 69 66 0a 23 69 66 OUS 2.#endif.#if
9870: 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 ndef SQLITE_DEFA
9880: 55 4c 54 5f 57 41 4c 5f 53 59 4e 43 48 52 4f 4e ULT_WAL_SYNCHRON
9890: 4f 55 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c OUS.# define SQL
98a0: 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 41 4c 5f ITE_DEFAULT_WAL_
98b0: 53 59 4e 43 48 52 4f 4e 4f 55 53 20 53 51 4c 49 SYNCHRONOUS SQLI
98c0: 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 TE_DEFAULT_SYNCH
98d0: 52 4f 4e 4f 55 53 0a 23 65 6e 64 69 66 0a 0a 2f RONOUS.#endif../
98e0: 2a 0a 2a 2a 20 45 61 63 68 20 64 61 74 61 62 61 *.** Each databa
98f0: 73 65 20 66 69 6c 65 20 74 6f 20 62 65 20 61 63 se file to be ac
9900: 63 65 73 73 65 64 20 62 79 20 74 68 65 20 73 79 cessed by the sy
9910: 73 74 65 6d 20 69 73 20 61 6e 20 69 6e 73 74 61 stem is an insta
9920: 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 65 20 66 6f nce.** of the fo
9930: 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
9940: 65 2e 20 20 54 68 65 72 65 20 61 72 65 20 6e 6f e. There are no
9950: 72 6d 61 6c 6c 79 20 74 77 6f 20 6f 66 20 74 68 rmally two of th
9960: 65 73 65 20 73 74 72 75 63 74 75 72 65 73 0a 2a ese structures.*
9970: 2a 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 2e * in the sqlite.
9980: 61 44 62 5b 5d 20 61 72 72 61 79 2e 20 20 61 44 aDb[] array. aD
9990: 62 5b 30 5d 20 69 73 20 74 68 65 20 6d 61 69 6e b[0] is the main
99a0: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 61 database file a
99b0: 6e 64 0a 2a 2a 20 61 44 62 5b 31 5d 20 69 73 20 nd.** aDb[1] is
99c0: 74 68 65 20 64 61 74 61 62 61 73 65 20 66 69 6c the database fil
99d0: 65 20 75 73 65 64 20 74 6f 20 68 6f 6c 64 20 74 e used to hold t
99e0: 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 73 2e emporary tables.
99f0: 20 20 41 64 64 69 74 69 6f 6e 61 6c 0a 2a 2a 20 Additional.**
9a00: 64 61 74 61 62 61 73 65 73 20 6d 61 79 20 62 65 databases may be
9a10: 20 61 74 74 61 63 68 65 64 2e 0a 2a 2f 0a 73 74 attached..*/.st
9a20: 72 75 63 74 20 44 62 20 7b 0a 20 20 63 68 61 72 ruct Db {. char
9a30: 20 2a 7a 44 62 53 4e 61 6d 65 3b 20 20 20 20 20 *zDbSName;
9a40: 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 /* Name of this
9a50: 20 64 61 74 61 62 61 73 65 2e 20 28 73 63 68 65 database. (sche
9a60: 6d 61 20 6e 61 6d 65 2c 20 6e 6f 74 20 66 69 6c ma name, not fil
9a70: 65 6e 61 6d 65 29 20 2a 2f 0a 20 20 42 74 72 65 ename) */. Btre
9a80: 65 20 2a 70 42 74 3b 20 20 20 20 20 20 20 20 20 e *pBt;
9a90: 20 2f 2a 20 54 68 65 20 42 2a 54 72 65 65 20 73 /* The B*Tree s
9aa0: 74 72 75 63 74 75 72 65 20 66 6f 72 20 74 68 69 tructure for thi
9ab0: 73 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 s database file
9ac0: 2a 2f 0a 20 20 75 38 20 73 61 66 65 74 79 5f 6c */. u8 safety_l
9ad0: 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 48 6f 77 evel; /* How
9ae0: 20 61 67 67 72 65 73 73 69 76 65 20 61 74 20 73 aggressive at s
9af0: 79 6e 63 69 6e 67 20 64 61 74 61 20 74 6f 20 64 yncing data to d
9b00: 69 73 6b 20 2a 2f 0a 20 20 75 38 20 62 53 79 6e isk */. u8 bSyn
9b10: 63 53 65 74 3b 20 20 20 20 20 20 20 20 20 2f 2a cSet; /*
9b20: 20 54 72 75 65 20 69 66 20 22 50 52 41 47 4d 41 True if "PRAGMA
9b30: 20 73 79 6e 63 68 72 6f 6e 6f 75 73 3d 4e 22 20 synchronous=N"
9b40: 68 61 73 20 62 65 65 6e 20 72 75 6e 20 2a 2f 0a has been run */.
9b50: 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d Schema *pSchem
9b60: 61 3b 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 a; /* Pointe
9b70: 72 20 74 6f 20 64 61 74 61 62 61 73 65 20 73 63 r to database sc
9b80: 68 65 6d 61 20 28 70 6f 73 73 69 62 6c 79 20 73 hema (possibly s
9b90: 68 61 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a hared) */.};../*
9ba0: 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
9bb0: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
9bc0: 20 73 74 72 75 63 74 75 72 65 20 73 74 6f 72 65 structure store
9bd0: 73 20 61 20 64 61 74 61 62 61 73 65 20 73 63 68 s a database sch
9be0: 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 ema..**.** Most
9bf0: 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 20 61 Schema objects a
9c00: 72 65 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 re associated wi
9c10: 74 68 20 61 20 42 74 72 65 65 2e 20 20 54 68 65 th a Btree. The
9c20: 20 65 78 63 65 70 74 69 6f 6e 20 69 73 0a 2a 2a exception is.**
9c30: 20 74 68 65 20 53 63 68 65 6d 61 20 66 6f 72 20 the Schema for
9c40: 74 68 65 20 54 45 4d 50 20 64 61 74 61 62 61 65 the TEMP databae
9c50: 73 20 28 73 71 6c 69 74 65 33 2e 61 44 62 5b 31 s (sqlite3.aDb[1
9c60: 5d 29 20 77 68 69 63 68 20 69 73 20 66 72 65 65 ]) which is free
9c70: 2d 73 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 6e -standing..** In
9c80: 20 73 68 61 72 65 64 20 63 61 63 68 65 20 6d 6f shared cache mo
9c90: 64 65 2c 20 61 20 73 69 6e 67 6c 65 20 53 63 68 de, a single Sch
9ca0: 65 6d 61 20 6f 62 6a 65 63 74 20 63 61 6e 20 62 ema object can b
9cb0: 65 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 e shared by mult
9cc0: 69 70 6c 65 0a 2a 2a 20 42 74 72 65 65 73 20 74 iple.** Btrees t
9cd0: 68 61 74 20 72 65 66 65 72 20 74 6f 20 74 68 65 hat refer to the
9ce0: 20 73 61 6d 65 20 75 6e 64 65 72 6c 79 69 6e 67 same underlying
9cf0: 20 42 74 53 68 61 72 65 64 20 6f 62 6a 65 63 74 BtShared object
9d00: 2e 0a 2a 2a 0a 2a 2a 20 53 63 68 65 6d 61 20 6f ..**.** Schema o
9d10: 62 6a 65 63 74 73 20 61 72 65 20 61 75 74 6f 6d bjects are autom
9d20: 61 74 69 63 61 6c 6c 79 20 64 65 61 6c 6c 6f 63 atically dealloc
9d30: 61 74 65 64 20 77 68 65 6e 20 74 68 65 20 6c 61 ated when the la
9d40: 73 74 20 42 74 72 65 65 20 74 68 61 74 0a 2a 2a st Btree that.**
9d50: 20 72 65 66 65 72 65 6e 63 65 73 20 74 68 65 6d references them
9d60: 20 69 73 20 64 65 73 74 72 6f 79 65 64 2e 20 20 is destroyed.
9d70: 20 54 68 65 20 54 45 4d 50 20 53 63 68 65 6d 61 The TEMP Schema
9d80: 20 69 73 20 6d 61 6e 75 61 6c 6c 79 20 66 72 65 is manually fre
9d90: 65 64 20 62 79 0a 2a 2a 20 73 71 6c 69 74 65 33 ed by.** sqlite3
9da0: 5f 63 6c 6f 73 65 28 29 2e 0a 2a 0a 2a 2a 20 41 _close()..*.** A
9db0: 20 74 68 72 65 61 64 20 6d 75 73 74 20 62 65 20 thread must be
9dc0: 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 holding a mutex
9dd0: 6f 6e 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e on the correspon
9de0: 64 69 6e 67 20 42 74 72 65 65 20 69 6e 20 6f 72 ding Btree in or
9df0: 64 65 72 0a 2a 2a 20 74 6f 20 61 63 63 65 73 73 der.** to access
9e00: 20 53 63 68 65 6d 61 20 63 6f 6e 74 65 6e 74 2e Schema content.
9e10: 20 20 54 68 69 73 20 69 6d 70 6c 69 65 73 20 74 This implies t
9e20: 68 61 74 20 74 68 65 20 74 68 72 65 61 64 20 6d hat the thread m
9e30: 75 73 74 20 61 6c 73 6f 20 62 65 0a 2a 2a 20 68 ust also be.** h
9e40: 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f olding a mutex o
9e50: 6e 20 74 68 65 20 73 71 6c 69 74 65 33 20 63 6f n the sqlite3 co
9e60: 6e 6e 65 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 nnection pointer
9e70: 20 74 68 61 74 20 6f 77 6e 73 20 74 68 65 20 42 that owns the B
9e80: 74 72 65 65 2e 0a 2a 2a 20 46 6f 72 20 61 20 54 tree..** For a T
9e90: 45 4d 50 20 53 63 68 65 6d 61 2c 20 6f 6e 6c 79 EMP Schema, only
9ea0: 20 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 the connection
9eb0: 6d 75 74 65 78 20 69 73 20 72 65 71 75 69 72 65 mutex is require
9ec0: 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 63 68 d..*/.struct Sch
9ed0: 65 6d 61 20 7b 0a 20 20 69 6e 74 20 73 63 68 65 ema {. int sche
9ee0: 6d 61 5f 63 6f 6f 6b 69 65 3b 20 20 20 2f 2a 20 ma_cookie; /*
9ef0: 44 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 Database schema
9f00: 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 66 version number f
9f10: 6f 72 20 74 68 69 73 20 66 69 6c 65 20 2a 2f 0a or this file */.
9f20: 20 20 69 6e 74 20 69 47 65 6e 65 72 61 74 69 6f int iGeneratio
9f30: 6e 3b 20 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 n; /* Genera
9f40: 74 69 6f 6e 20 63 6f 75 6e 74 65 72 2e 20 20 49 tion counter. I
9f50: 6e 63 72 65 6d 65 6e 74 65 64 20 77 69 74 68 20 ncremented with
9f60: 65 61 63 68 20 63 68 61 6e 67 65 20 2a 2f 0a 20 each change */.
9f70: 20 48 61 73 68 20 74 62 6c 48 61 73 68 3b 20 20 Hash tblHash;
9f80: 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 74 61 62 /* All tab
9f90: 6c 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e les indexed by n
9fa0: 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 69 64 ame */. Hash id
9fb0: 78 48 61 73 68 3b 20 20 20 20 20 20 20 20 2f 2a xHash; /*
9fc0: 20 41 6c 6c 20 28 6e 61 6d 65 64 29 20 69 6e 64 All (named) ind
9fd0: 69 63 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 ices indexed by
9fe0: 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 74 name */. Hash t
9ff0: 72 69 67 48 61 73 68 3b 20 20 20 20 20 20 20 2f rigHash; /
a000: 2a 20 41 6c 6c 20 74 72 69 67 67 65 72 73 20 69 * All triggers i
a010: 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a ndexed by name *
a020: 2f 0a 20 20 48 61 73 68 20 66 6b 65 79 48 61 73 /. Hash fkeyHas
a030: 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 h; /* All
a040: 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 62 79 20 foreign keys by
a050: 72 65 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 referenced table
a060: 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 61 62 6c 65 name */. Table
a070: 20 2a 70 53 65 71 54 61 62 3b 20 20 20 20 20 20 *pSeqTab;
a080: 2f 2a 20 54 68 65 20 73 71 6c 69 74 65 5f 73 65 /* The sqlite_se
a090: 71 75 65 6e 63 65 20 74 61 62 6c 65 20 75 73 65 quence table use
a0a0: 64 20 62 79 20 41 55 54 4f 49 4e 43 52 45 4d 45 d by AUTOINCREME
a0b0: 4e 54 20 2a 2f 0a 20 20 75 38 20 66 69 6c 65 5f NT */. u8 file_
a0c0: 66 6f 72 6d 61 74 3b 20 20 20 20 20 20 2f 2a 20 format; /*
a0d0: 53 63 68 65 6d 61 20 66 6f 72 6d 61 74 20 76 65 Schema format ve
a0e0: 72 73 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 66 rsion for this f
a0f0: 69 6c 65 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b ile */. u8 enc;
a100: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
a110: 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 75 Text encoding u
a120: 73 65 64 20 62 79 20 74 68 69 73 20 64 61 74 61 sed by this data
a130: 62 61 73 65 20 2a 2f 0a 20 20 75 31 36 20 73 63 base */. u16 sc
a140: 68 65 6d 61 46 6c 61 67 73 3b 20 20 20 20 20 2f hemaFlags; /
a150: 2a 20 46 6c 61 67 73 20 61 73 73 6f 63 69 61 74 * Flags associat
a160: 65 64 20 77 69 74 68 20 74 68 69 73 20 73 63 68 ed with this sch
a170: 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 63 61 63 ema */. int cac
a180: 68 65 5f 73 69 7a 65 3b 20 20 20 20 20 20 2f 2a he_size; /*
a190: 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 Number of pages
a1a0: 20 74 6f 20 75 73 65 20 69 6e 20 74 68 65 20 63 to use in the c
a1b0: 61 63 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a ache */.};../*.*
a1c0: 2a 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 63 * These macros c
a1d0: 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 65 an be used to te
a1e0: 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 st, set, or clea
a1f0: 72 20 62 69 74 73 20 69 6e 20 74 68 65 0a 2a 2a r bits in the.**
a200: 20 44 62 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 Db.pSchema->fla
a210: 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 gs field..*/.#de
a220: 66 69 6e 65 20 44 62 48 61 73 50 72 6f 70 65 72 fine DbHasProper
a230: 74 79 28 44 2c 49 2c 50 29 20 20 20 20 20 28 28 ty(D,I,P) ((
a240: 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 (D)->aDb[I].pSch
a250: 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 ema->schemaFlags
a260: 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 &(P))==(P)).#def
a270: 69 6e 65 20 44 62 48 61 73 41 6e 79 50 72 6f 70 ine DbHasAnyProp
a280: 65 72 74 79 28 44 2c 49 2c 50 29 20 20 28 28 28 erty(D,I,P) (((
a290: 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 D)->aDb[I].pSche
a2a0: 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 ma->schemaFlags&
a2b0: 28 50 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 (P))!=0).#define
a2c0: 20 44 62 53 65 74 50 72 6f 70 65 72 74 79 28 44 DbSetProperty(D
a2d0: 2c 49 2c 50 29 20 20 20 20 20 28 44 29 2d 3e 61 ,I,P) (D)->a
a2e0: 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 Db[I].pSchema->s
a2f0: 63 68 65 6d 61 46 6c 61 67 73 7c 3d 28 50 29 0a chemaFlags|=(P).
a300: 23 64 65 66 69 6e 65 20 44 62 43 6c 65 61 72 50 #define DbClearP
a310: 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 roperty(D,I,P)
a320: 20 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 (D)->aDb[I].pSc
a330: 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 hema->schemaFlag
a340: 73 26 3d 7e 28 50 29 0a 0a 2f 2a 0a 2a 2a 20 41 s&=~(P)../*.** A
a350: 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f llowed values fo
a360: 72 20 74 68 65 20 44 42 2e 70 53 63 68 65 6d 61 r the DB.pSchema
a370: 2d 3e 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a ->flags field..*
a380: 2a 0a 2a 2a 20 54 68 65 20 44 42 5f 53 63 68 65 *.** The DB_Sche
a390: 6d 61 4c 6f 61 64 65 64 20 66 6c 61 67 20 69 73 maLoaded flag is
a3a0: 20 73 65 74 20 61 66 74 65 72 20 74 68 65 20 64 set after the d
a3b0: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 68 atabase schema h
a3c0: 61 73 20 62 65 65 6e 0a 2a 2a 20 72 65 61 64 20 as been.** read
a3d0: 69 6e 74 6f 20 69 6e 74 65 72 6e 61 6c 20 68 61 into internal ha
a3e0: 73 68 20 74 61 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a sh tables..**.**
a3f0: 20 44 42 5f 55 6e 72 65 73 65 74 56 69 65 77 73 DB_UnresetViews
a400: 20 6d 65 61 6e 73 20 74 68 61 74 20 6f 6e 65 20 means that one
a410: 6f 72 20 6d 6f 72 65 20 76 69 65 77 73 20 68 61 or more views ha
a420: 76 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 ve column names
a430: 74 68 61 74 0a 2a 2a 20 68 61 76 65 20 62 65 65 that.** have bee
a440: 6e 20 66 69 6c 6c 65 64 20 6f 75 74 2e 20 20 49 n filled out. I
a450: 66 20 74 68 65 20 73 63 68 65 6d 61 20 63 68 61 f the schema cha
a460: 6e 67 65 73 2c 20 74 68 65 73 65 20 63 6f 6c 75 nges, these colu
a470: 6d 6e 20 6e 61 6d 65 73 20 6d 69 67 68 74 0a 2a mn names might.*
a480: 2a 20 63 68 61 6e 67 65 73 20 61 6e 64 20 73 6f * changes and so
a490: 20 74 68 65 20 76 69 65 77 20 77 69 6c 6c 20 6e the view will n
a4a0: 65 65 64 20 74 6f 20 62 65 20 72 65 73 65 74 2e eed to be reset.
a4b0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 53 .*/.#define DB_S
a4c0: 63 68 65 6d 61 4c 6f 61 64 65 64 20 20 20 20 30 chemaLoaded 0
a4d0: 78 30 30 30 31 20 20 2f 2a 20 54 68 65 20 73 63 x0001 /* The sc
a4e0: 68 65 6d 61 20 68 61 73 20 62 65 65 6e 20 6c 6f hema has been lo
a4f0: 61 64 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aded */.#define
a500: 44 42 5f 55 6e 72 65 73 65 74 56 69 65 77 73 20 DB_UnresetViews
a510: 20 20 20 30 78 30 30 30 32 20 20 2f 2a 20 53 6f 0x0002 /* So
a520: 6d 65 20 76 69 65 77 73 20 68 61 76 65 20 64 65 me views have de
a530: 66 69 6e 65 64 20 63 6f 6c 75 6d 6e 20 6e 61 6d fined column nam
a540: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 es */.#define DB
a550: 5f 45 6d 70 74 79 20 20 20 20 20 20 20 20 20 20 _Empty
a560: 20 30 78 30 30 30 34 20 20 2f 2a 20 54 68 65 20 0x0004 /* The
a570: 66 69 6c 65 20 69 73 20 65 6d 70 74 79 20 28 6c file is empty (l
a580: 65 6e 67 74 68 20 30 20 62 79 74 65 73 29 20 2a ength 0 bytes) *
a590: 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 52 65 73 /.#define DB_Res
a5a0: 65 74 57 61 6e 74 65 64 20 20 20 20 20 30 78 30 etWanted 0x0
a5b0: 30 30 38 20 20 2f 2a 20 52 65 73 65 74 20 74 68 008 /* Reset th
a5c0: 65 20 73 63 68 65 6d 61 20 77 68 65 6e 20 6e 53 e schema when nS
a5d0: 63 68 65 6d 61 4c 6f 63 6b 3d 3d 30 20 2a 2f 0a chemaLock==0 */.
a5e0: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 ./*.** The numbe
a5f0: 72 20 6f 66 20 64 69 66 66 65 72 65 6e 74 20 6b r of different k
a600: 69 6e 64 73 20 6f 66 20 74 68 69 6e 67 73 20 74 inds of things t
a610: 68 61 74 20 63 61 6e 20 62 65 20 6c 69 6d 69 74 hat can be limit
a620: 65 64 0a 2a 2a 20 75 73 69 6e 67 20 74 68 65 20 ed.** using the
a630: 73 71 6c 69 74 65 33 5f 6c 69 6d 69 74 28 29 20 sqlite3_limit()
a640: 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a 23 64 interface..*/.#d
a650: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 4c efine SQLITE_N_L
a660: 49 4d 49 54 20 28 53 51 4c 49 54 45 5f 4c 49 4d IMIT (SQLITE_LIM
a670: 49 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 IT_WORKER_THREAD
a680: 53 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b S+1)../*.** Look
a690: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 69 73 20 aside malloc is
a6a0: 61 20 73 65 74 20 6f 66 20 66 69 78 65 64 2d 73 a set of fixed-s
a6b0: 69 7a 65 20 62 75 66 66 65 72 73 20 74 68 61 74 ize buffers that
a6c0: 20 63 61 6e 20 62 65 20 75 73 65 64 0a 2a 2a 20 can be used.**
a6d0: 74 6f 20 73 61 74 69 73 66 79 20 73 6d 61 6c 6c to satisfy small
a6e0: 20 74 72 61 6e 73 69 65 6e 74 20 6d 65 6d 6f 72 transient memor
a6f0: 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 72 65 71 y allocation req
a700: 75 65 73 74 73 20 66 6f 72 20 6f 62 6a 65 63 74 uests for object
a710: 73 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65 64 20 s.** associated
a720: 77 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 with a particula
a730: 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 r database conne
a740: 63 74 69 6f 6e 2e 20 20 54 68 65 20 75 73 65 20 ction. The use
a750: 6f 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 of.** lookaside
a760: 6d 61 6c 6c 6f 63 20 70 72 6f 76 69 64 65 73 20 malloc provides
a770: 61 20 73 69 67 6e 69 66 69 63 61 6e 74 20 70 65 a significant pe
a780: 72 66 6f 72 6d 61 6e 63 65 20 65 6e 68 61 6e 63 rformance enhanc
a790: 65 6d 65 6e 74 0a 2a 2a 20 28 61 70 70 72 6f 78 ement.** (approx
a7a0: 20 31 30 25 29 20 62 79 20 61 76 6f 69 64 69 6e 10%) by avoidin
a7b0: 67 20 6e 75 6d 65 72 6f 75 73 20 6d 61 6c 6c 6f g numerous mallo
a7c0: 63 2f 66 72 65 65 20 72 65 71 75 65 73 74 73 20 c/free requests
a7d0: 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a 2a 2a while parsing.**
a7e0: 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 2e SQL statements.
a7f0: 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 6f 6b 61 .**.** The Looka
a800: 73 69 64 65 20 73 74 72 75 63 74 75 72 65 20 68 side structure h
a810: 6f 6c 64 73 20 63 6f 6e 66 69 67 75 72 61 74 69 olds configurati
a820: 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 on information a
a830: 62 6f 75 74 20 74 68 65 0a 2a 2a 20 6c 6f 6f 6b bout the.** look
a840: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 73 75 62 aside malloc sub
a850: 73 79 73 74 65 6d 2e 20 20 45 61 63 68 20 61 76 system. Each av
a860: 61 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 61 ailable memory a
a870: 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e 0a 2a 2a 20 llocation in.**
a880: 74 68 65 20 6c 6f 6f 6b 61 73 69 64 65 20 73 75 the lookaside su
a890: 62 73 79 73 74 65 6d 20 69 73 20 73 74 6f 72 65 bsystem is store
a8a0: 64 20 6f 6e 20 61 20 6c 69 6e 6b 65 64 20 6c 69 d on a linked li
a8b0: 73 74 20 6f 66 20 4c 6f 6f 6b 61 73 69 64 65 53 st of LookasideS
a8c0: 6c 6f 74 0a 2a 2a 20 6f 62 6a 65 63 74 73 2e 0a lot.** objects..
a8d0: 2a 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 **.** Lookaside
a8e0: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 allocations are
a8f0: 6f 6e 6c 79 20 61 6c 6c 6f 77 65 64 20 66 6f 72 only allowed for
a900: 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 61 72 objects that ar
a910: 65 20 61 73 73 6f 63 69 61 74 65 64 0a 2a 2a 20 e associated.**
a920: 77 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 with a particula
a930: 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 r database conne
a940: 63 74 69 6f 6e 2e 20 20 48 65 6e 63 65 2c 20 73 ction. Hence, s
a950: 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f chema informatio
a960: 6e 20 63 61 6e 6e 6f 74 0a 2a 2a 20 62 65 20 73 n cannot.** be s
a970: 74 6f 72 65 64 20 69 6e 20 6c 6f 6f 6b 61 73 69 tored in lookasi
a980: 64 65 20 62 65 63 61 75 73 65 20 69 6e 20 73 68 de because in sh
a990: 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 20 ared cache mode
a9a0: 74 68 65 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 the schema infor
a9b0: 6d 61 74 69 6f 6e 0a 2a 2a 20 69 73 20 73 68 61 mation.** is sha
a9c0: 72 65 64 20 62 79 20 6d 75 6c 74 69 70 6c 65 20 red by multiple
a9d0: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
a9e0: 69 6f 6e 73 2e 20 20 54 68 65 72 65 66 6f 72 65 ions. Therefore
a9f0: 2c 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a , while parsing.
aa00: 2a 2a 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d ** schema inform
aa10: 61 74 69 6f 6e 2c 20 74 68 65 20 4c 6f 6f 6b 61 ation, the Looka
aa20: 73 69 64 65 2e 62 45 6e 61 62 6c 65 64 20 66 6c side.bEnabled fl
aa30: 61 67 20 69 73 20 63 6c 65 61 72 65 64 20 73 6f ag is cleared so
aa40: 20 74 68 61 74 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 that.** lookasi
aa50: 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 de allocations a
aa60: 72 65 20 6e 6f 74 20 75 73 65 64 20 74 6f 20 63 re not used to c
aa70: 6f 6e 73 74 72 75 63 74 20 74 68 65 20 73 63 68 onstruct the sch
aa80: 65 6d 61 20 6f 62 6a 65 63 74 73 2e 0a 2a 2f 0a ema objects..*/.
aa90: 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 struct Lookaside
aaa0: 20 7b 0a 20 20 75 33 32 20 62 44 69 73 61 62 6c {. u32 bDisabl
aab0: 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 e; /*
aac0: 4f 6e 6c 79 20 6f 70 65 72 61 74 65 20 74 68 65 Only operate the
aad0: 20 6c 6f 6f 6b 61 73 69 64 65 20 77 68 65 6e 20 lookaside when
aae0: 7a 65 72 6f 20 2a 2f 0a 20 20 75 31 36 20 73 7a zero */. u16 sz
aaf0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
ab00: 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 /* Size of eac
ab10: 68 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 65 h buffer in byte
ab20: 73 20 2a 2f 0a 20 20 75 38 20 62 4d 61 6c 6c 6f s */. u8 bMallo
ab30: 63 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f ced; /
ab40: 2a 20 54 72 75 65 20 69 66 20 70 53 74 61 72 74 * True if pStart
ab50: 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 73 obtained from s
ab60: 71 6c 69 74 65 33 5f 6d 61 6c 6c 6f 63 28 29 20 qlite3_malloc()
ab70: 2a 2f 0a 20 20 75 33 32 20 6e 53 6c 6f 74 3b 20 */. u32 nSlot;
ab80: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
ab90: 4e 75 6d 62 65 72 20 6f 66 20 6c 6f 6f 6b 61 73 Number of lookas
aba0: 69 64 65 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 ide slots alloca
abb0: 74 65 64 20 2a 2f 0a 20 20 75 33 32 20 61 6e 53 ted */. u32 anS
abc0: 74 61 74 5b 33 5d 3b 20 20 20 20 20 20 20 20 20 tat[3];
abd0: 20 2f 2a 20 30 3a 20 68 69 74 73 2e 20 20 31 3a /* 0: hits. 1:
abe0: 20 73 69 7a 65 20 6d 69 73 73 65 73 2e 20 20 32 size misses. 2
abf0: 3a 20 66 75 6c 6c 20 6d 69 73 73 65 73 20 2a 2f : full misses */
ac00: 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 . LookasideSlot
ac10: 20 2a 70 49 6e 69 74 3b 20 20 20 2f 2a 20 4c 69 *pInit; /* Li
ac20: 73 74 20 6f 66 20 62 75 66 66 65 72 73 20 6e 6f st of buffers no
ac30: 74 20 70 72 65 76 69 6f 75 73 6c 79 20 75 73 65 t previously use
ac40: 64 20 2a 2f 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 d */. Lookaside
ac50: 53 6c 6f 74 20 2a 70 46 72 65 65 3b 20 20 20 2f Slot *pFree; /
ac60: 2a 20 4c 69 73 74 20 6f 66 20 61 76 61 69 6c 61 * List of availa
ac70: 62 6c 65 20 62 75 66 66 65 72 73 20 2a 2f 0a 20 ble buffers */.
ac80: 20 76 6f 69 64 20 2a 70 53 74 61 72 74 3b 20 20 void *pStart;
ac90: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
aca0: 74 20 62 79 74 65 20 6f 66 20 61 76 61 69 6c 61 t byte of availa
acb0: 62 6c 65 20 6d 65 6d 6f 72 79 20 73 70 61 63 65 ble memory space
acc0: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 45 6e 64 */. void *pEnd
acd0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
ace0: 20 46 69 72 73 74 20 62 79 74 65 20 70 61 73 74 First byte past
acf0: 20 65 6e 64 20 6f 66 20 61 76 61 69 6c 61 62 6c end of availabl
ad00: 65 20 73 70 61 63 65 20 2a 2f 0a 7d 3b 0a 73 74 e space */.};.st
ad10: 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 53 6c ruct LookasideSl
ad20: 6f 74 20 7b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 ot {. Lookaside
ad30: 53 6c 6f 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 Slot *pNext;
ad40: 2f 2a 20 4e 65 78 74 20 62 75 66 66 65 72 20 69 /* Next buffer i
ad50: 6e 20 74 68 65 20 6c 69 73 74 20 6f 66 20 66 72 n the list of fr
ad60: 65 65 20 62 75 66 66 65 72 73 20 2a 2f 0a 7d 3b ee buffers */.};
ad70: 0a 0a 2f 2a 0a 2a 2a 20 41 20 68 61 73 68 20 74 ../*.** A hash t
ad80: 61 62 6c 65 20 66 6f 72 20 62 75 69 6c 74 2d 69 able for built-i
ad90: 6e 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e n function defin
ada0: 69 74 69 6f 6e 73 2e 20 20 28 41 70 70 6c 69 63 itions. (Applic
adb0: 61 74 69 6f 6e 2d 64 65 66 69 6e 65 64 0a 2a 2a ation-defined.**
adc0: 20 66 75 6e 63 74 69 6f 6e 73 20 75 73 65 20 61 functions use a
add0: 20 72 65 67 75 6c 61 72 20 74 61 62 6c 65 20 74 regular table t
ade0: 61 62 6c 65 20 66 72 6f 6d 20 68 61 73 68 2e 68 able from hash.h
adf0: 2e 29 0a 2a 2a 0a 2a 2a 20 48 61 73 68 20 65 61 .).**.** Hash ea
ae00: 63 68 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 ch FuncDef struc
ae10: 74 75 72 65 20 69 6e 74 6f 20 6f 6e 65 20 6f 66 ture into one of
ae20: 20 74 68 65 20 46 75 6e 63 44 65 66 48 61 73 68 the FuncDefHash
ae30: 2e 61 5b 5d 20 73 6c 6f 74 73 2e 0a 2a 2a 20 43 .a[] slots..** C
ae40: 6f 6c 6c 69 73 69 6f 6e 73 20 61 72 65 20 6f 6e ollisions are on
ae50: 20 74 68 65 20 46 75 6e 63 44 65 66 2e 75 2e 70 the FuncDef.u.p
ae60: 48 61 73 68 20 63 68 61 69 6e 2e 0a 2a 2f 0a 23 Hash chain..*/.#
ae70: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
ae80: 4e 43 5f 48 41 53 48 5f 53 5a 20 32 33 0a 73 74 NC_HASH_SZ 23.st
ae90: 72 75 63 74 20 46 75 6e 63 44 65 66 48 61 73 68 ruct FuncDefHash
aea0: 20 7b 0a 20 20 46 75 6e 63 44 65 66 20 2a 61 5b {. FuncDef *a[
aeb0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 SQLITE_FUNC_HASH
aec0: 5f 53 5a 5d 3b 20 20 20 20 20 20 20 2f 2a 20 48 _SZ]; /* H
aed0: 61 73 68 20 74 61 62 6c 65 20 66 6f 72 20 66 75 ash table for fu
aee0: 6e 63 74 69 6f 6e 73 20 2a 2f 0a 7d 3b 0a 0a 23 nctions */.};..#
aef0: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 ifdef SQLITE_USE
af00: 52 5f 41 55 54 48 45 4e 54 49 43 41 54 49 4f 4e R_AUTHENTICATION
af10: 0a 2f 2a 0a 2a 2a 20 49 6e 66 6f 72 6d 61 74 69 ./*.** Informati
af20: 6f 6e 20 68 65 6c 64 20 69 6e 20 74 68 65 20 22 on held in the "
af30: 73 71 6c 69 74 65 33 22 20 64 61 74 61 62 61 73 sqlite3" databas
af40: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 6f 62 6a e connection obj
af50: 65 63 74 20 61 6e 64 20 75 73 65 64 0a 2a 2a 20 ect and used.**
af60: 74 6f 20 6d 61 6e 61 67 65 20 75 73 65 72 20 61 to manage user a
af70: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 2e 0a 2a uthentication..*
af80: 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
af90: 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 sqlite3_useraut
afa0: 68 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 h sqlite3_userau
afb0: 74 68 3b 0a 73 74 72 75 63 74 20 73 71 6c 69 74 th;.struct sqlit
afc0: 65 33 5f 75 73 65 72 61 75 74 68 20 7b 0a 20 20 e3_userauth {.
afd0: 75 38 20 61 75 74 68 4c 65 76 65 6c 3b 20 20 20 u8 authLevel;
afe0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
aff0: 20 43 75 72 72 65 6e 74 20 61 75 74 68 65 6e 74 Current authent
b000: 69 63 61 74 69 6f 6e 20 6c 65 76 65 6c 20 2a 2f ication level */
b010: 0a 20 20 69 6e 74 20 6e 41 75 74 68 50 57 3b 20 . int nAuthPW;
b020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b030: 20 2f 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 20 /* Size of the
b040: 7a 41 75 74 68 50 57 20 69 6e 20 62 79 74 65 73 zAuthPW in bytes
b050: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 41 75 74 */. char *zAut
b060: 68 50 57 3b 20 20 20 20 20 20 20 20 20 20 20 20 hPW;
b070: 20 20 20 20 2f 2a 20 50 61 73 73 77 6f 72 64 20 /* Password
b080: 75 73 65 64 20 74 6f 20 61 75 74 68 65 6e 74 69 used to authenti
b090: 63 61 74 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a cate */. char *
b0a0: 7a 41 75 74 68 55 73 65 72 3b 20 20 20 20 20 20 zAuthUser;
b0b0: 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 72 20 /* User
b0c0: 6e 61 6d 65 20 75 73 65 64 20 74 6f 20 61 75 74 name used to aut
b0d0: 68 65 6e 74 69 63 61 74 65 20 2a 2f 0a 7d 3b 0a henticate */.};.
b0e0: 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 ./* Allowed valu
b0f0: 65 73 20 66 6f 72 20 73 71 6c 69 74 65 33 5f 75 es for sqlite3_u
b100: 73 65 72 61 75 74 68 2e 61 75 74 68 4c 65 76 65 serauth.authLeve
b110: 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 l */.#define UAU
b120: 54 48 5f 55 6e 6b 6e 6f 77 6e 20 20 20 20 20 30 TH_Unknown 0
b130: 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 /* Authenti
b140: 63 61 74 69 6f 6e 20 6e 6f 74 20 79 65 74 20 63 cation not yet c
b150: 68 65 63 6b 65 64 20 2a 2f 0a 23 64 65 66 69 6e hecked */.#defin
b160: 65 20 55 41 55 54 48 5f 46 61 69 6c 20 20 20 20 e UAUTH_Fail
b170: 20 20 20 20 31 20 20 20 20 20 2f 2a 20 55 73 65 1 /* Use
b180: 72 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e r authentication
b190: 20 66 61 69 6c 65 64 20 2a 2f 0a 23 64 65 66 69 failed */.#defi
b1a0: 6e 65 20 55 41 55 54 48 5f 55 73 65 72 20 20 20 ne UAUTH_User
b1b0: 20 20 20 20 20 32 20 20 20 20 20 2f 2a 20 41 75 2 /* Au
b1c0: 74 68 65 6e 74 69 63 61 74 65 64 20 61 73 20 61 thenticated as a
b1d0: 20 6e 6f 72 6d 61 6c 20 75 73 65 72 20 2a 2f 0a normal user */.
b1e0: 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 41 64 #define UAUTH_Ad
b1f0: 6d 69 6e 20 20 20 20 20 20 20 33 20 20 20 20 20 min 3
b200: 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 74 65 64 /* Authenticated
b210: 20 61 73 20 61 6e 20 61 64 6d 69 6e 69 73 74 72 as an administr
b220: 61 74 6f 72 20 2a 2f 0a 0a 2f 2a 20 46 75 6e 63 ator */../* Func
b230: 74 69 6f 6e 73 20 75 73 65 64 20 6f 6e 6c 79 20 tions used only
b240: 62 79 20 75 73 65 72 20 61 75 74 68 6f 72 69 7a by user authoriz
b250: 61 74 69 6f 6e 20 6c 6f 67 69 63 20 2a 2f 0a 69 ation logic */.i
b260: 6e 74 20 73 71 6c 69 74 65 33 55 73 65 72 41 75 nt sqlite3UserAu
b270: 74 68 54 61 62 6c 65 28 63 6f 6e 73 74 20 63 68 thTable(const ch
b280: 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ar*);.int sqlite
b290: 33 55 73 65 72 41 75 74 68 43 68 65 63 6b 4c 6f 3UserAuthCheckLo
b2a0: 67 69 6e 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e gin(sqlite3*,con
b2b0: 73 74 20 63 68 61 72 2a 2c 75 38 2a 29 3b 0a 76 st char*,u8*);.v
b2c0: 6f 69 64 20 73 71 6c 69 74 65 33 55 73 65 72 41 oid sqlite3UserA
b2d0: 75 74 68 49 6e 69 74 28 73 71 6c 69 74 65 33 2a uthInit(sqlite3*
b2e0: 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
b2f0: 72 79 70 74 46 75 6e 63 28 73 71 6c 69 74 65 33 ryptFunc(sqlite3
b300: 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 _context*,int,sq
b310: 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a lite3_value**);.
b320: 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 54 .#endif /* SQLIT
b330: 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 E_USER_AUTHENTIC
b340: 41 54 49 4f 4e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 ATION */../*.**
b350: 74 79 70 65 64 65 66 20 66 6f 72 20 74 68 65 20 typedef for the
b360: 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 63 61 authorization ca
b370: 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f 6e 2e llback function.
b380: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
b390: 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 E_USER_AUTHENTIC
b3a0: 41 54 49 4f 4e 0a 20 20 74 79 70 65 64 65 66 20 ATION. typedef
b3b0: 69 6e 74 20 28 2a 73 71 6c 69 74 65 33 5f 78 61 int (*sqlite3_xa
b3c0: 75 74 68 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 uth)(void*,int,c
b3d0: 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 onst char*,const
b3e0: 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 char*,const cha
b3f0: 72 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 r*,.
b400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b410: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 const char*,
b420: 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 const char*);.#e
b430: 6c 73 65 0a 20 20 74 79 70 65 64 65 66 20 69 6e lse. typedef in
b440: 74 20 28 2a 73 71 6c 69 74 65 33 5f 78 61 75 74 t (*sqlite3_xaut
b450: 68 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 6f 6e h)(void*,int,con
b460: 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 st char*,const c
b470: 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
b480: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
b490: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b4a0: 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 const char*);.#
b4b0: 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 endif..#ifndef S
b4c0: 51 4c 49 54 45 5f 4f 4d 49 54 5f 44 45 50 52 45 QLITE_OMIT_DEPRE
b4d0: 43 41 54 45 44 0a 2f 2a 20 54 68 69 73 20 69 73 CATED./* This is
b4e0: 20 61 6e 20 65 78 74 72 61 20 53 51 4c 49 54 45 an extra SQLITE
b4f0: 5f 54 52 41 43 45 20 6d 61 63 72 6f 20 74 68 61 _TRACE macro tha
b500: 74 20 69 6e 64 69 63 61 74 65 73 20 22 6c 65 67 t indicates "leg
b510: 61 63 79 22 20 74 72 61 63 69 6e 67 0a 2a 2a 20 acy" tracing.**
b520: 69 6e 20 74 68 65 20 73 74 79 6c 65 20 6f 66 20 in the style of
b530: 73 71 6c 69 74 65 33 5f 74 72 61 63 65 28 29 0a sqlite3_trace().
b540: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b550: 45 5f 54 52 41 43 45 5f 4c 45 47 41 43 59 20 20 E_TRACE_LEGACY
b560: 30 78 38 30 0a 23 65 6c 73 65 0a 23 64 65 66 69 0x80.#else.#defi
b570: 6e 65 20 53 51 4c 49 54 45 5f 54 52 41 43 45 5f ne SQLITE_TRACE_
b580: 4c 45 47 41 43 59 20 20 30 0a 23 65 6e 64 69 66 LEGACY 0.#endif
b590: 20 2f 2a 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f /* SQLITE_OMIT_
b5a0: 44 45 50 52 45 43 41 54 45 44 20 2a 2f 0a 0a 0a DEPRECATED */...
b5b0: 2f 2a 0a 2a 2a 20 45 61 63 68 20 64 61 74 61 62 /*.** Each datab
b5c0: 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 69 ase connection i
b5d0: 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 s an instance of
b5e0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
b5f0: 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 tructure..*/.str
b600: 75 63 74 20 73 71 6c 69 74 65 33 20 7b 0a 20 20 uct sqlite3 {.
b610: 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 70 56 66 sqlite3_vfs *pVf
b620: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a s; /*
b630: 20 4f 53 20 49 6e 74 65 72 66 61 63 65 20 2a 2f OS Interface */
b640: 0a 20 20 73 74 72 75 63 74 20 56 64 62 65 20 2a . struct Vdbe *
b650: 70 56 64 62 65 3b 20 20 20 20 20 20 20 20 20 20 pVdbe;
b660: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 63 74 69 /* List of acti
b670: 76 65 20 76 69 72 74 75 61 6c 20 6d 61 63 68 69 ve virtual machi
b680: 6e 65 73 20 2a 2f 0a 20 20 43 6f 6c 6c 53 65 71 nes */. CollSeq
b690: 20 2a 70 44 66 6c 74 43 6f 6c 6c 3b 20 20 20 20 *pDfltColl;
b6a0: 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 65 /* The de
b6b0: 66 61 75 6c 74 20 63 6f 6c 6c 61 74 69 6e 67 20 fault collating
b6c0: 73 65 71 75 65 6e 63 65 20 28 42 49 4e 41 52 59 sequence (BINARY
b6d0: 29 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d ) */. sqlite3_m
b6e0: 75 74 65 78 20 2a 6d 75 74 65 78 3b 20 20 20 20 utex *mutex;
b6f0: 20 20 20 20 20 2f 2a 20 43 6f 6e 6e 65 63 74 69 /* Connecti
b700: 6f 6e 20 6d 75 74 65 78 20 2a 2f 0a 20 20 44 62 on mutex */. Db
b710: 20 2a 61 44 62 3b 20 20 20 20 20 20 20 20 20 20 *aDb;
b720: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 /* A
b730: 6c 6c 20 62 61 63 6b 65 6e 64 73 20 2a 2f 0a 20 ll backends */.
b740: 20 69 6e 74 20 6e 44 62 3b 20 20 20 20 20 20 20 int nDb;
b750: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
b760: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 62 61 63 6b * Number of back
b770: 65 6e 64 73 20 63 75 72 72 65 6e 74 6c 79 20 69 ends currently i
b780: 6e 20 75 73 65 20 2a 2f 0a 20 20 75 33 32 20 6d n use */. u32 m
b790: 44 62 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 DbFlags;
b7a0: 20 20 20 20 20 20 20 20 20 2f 2a 20 66 6c 61 67 /* flag
b7b0: 73 20 72 65 63 6f 72 64 69 6e 67 20 69 6e 74 65 s recording inte
b7c0: 72 6e 61 6c 20 73 74 61 74 65 20 2a 2f 0a 20 20 rnal state */.
b7d0: 75 33 32 20 66 6c 61 67 73 3b 20 20 20 20 20 20 u32 flags;
b7e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
b7f0: 20 66 6c 61 67 73 20 73 65 74 74 61 62 6c 65 20 flags settable
b800: 62 79 20 70 72 61 67 6d 61 73 2e 20 53 65 65 20 by pragmas. See
b810: 62 65 6c 6f 77 20 2a 2f 0a 20 20 69 36 34 20 6c below */. i64 l
b820: 61 73 74 52 6f 77 69 64 3b 20 20 20 20 20 20 20 astRowid;
b830: 20 20 20 20 20 20 20 20 20 2f 2a 20 52 4f 57 49 /* ROWI
b840: 44 20 6f 66 20 6d 6f 73 74 20 72 65 63 65 6e 74 D of most recent
b850: 20 69 6e 73 65 72 74 20 28 73 65 65 20 61 62 6f insert (see abo
b860: 76 65 29 20 2a 2f 0a 20 20 69 36 34 20 73 7a 4d ve) */. i64 szM
b870: 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 map;
b880: 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
b890: 74 20 6d 6d 61 70 5f 73 69 7a 65 20 73 65 74 74 t mmap_size sett
b8a0: 69 6e 67 20 2a 2f 0a 20 20 75 33 32 20 6e 53 63 ing */. u32 nSc
b8b0: 68 65 6d 61 4c 6f 63 6b 3b 20 20 20 20 20 20 20 hemaLock;
b8c0: 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 /* Do not
b8d0: 20 72 65 73 65 74 20 74 68 65 20 73 63 68 65 6d reset the schem
b8e0: 61 20 77 68 65 6e 20 6e 6f 6e 2d 7a 65 72 6f 20 a when non-zero
b8f0: 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e */. unsigned in
b900: 74 20 6f 70 65 6e 46 6c 61 67 73 3b 20 20 20 20 t openFlags;
b910: 20 20 20 2f 2a 20 46 6c 61 67 73 20 70 61 73 73 /* Flags pass
b920: 65 64 20 74 6f 20 73 71 6c 69 74 65 33 5f 76 66 ed to sqlite3_vf
b930: 73 2e 78 4f 70 65 6e 28 29 20 2a 2f 0a 20 20 69 s.xOpen() */. i
b940: 6e 74 20 65 72 72 43 6f 64 65 3b 20 20 20 20 20 nt errCode;
b950: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
b960: 4d 6f 73 74 20 72 65 63 65 6e 74 20 65 72 72 6f Most recent erro
b970: 72 20 63 6f 64 65 20 28 53 51 4c 49 54 45 5f 2a r code (SQLITE_*
b980: 29 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 4d 61 ) */. int errMa
b990: 73 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 sk;
b9a0: 20 20 20 20 20 2f 2a 20 26 20 72 65 73 75 6c 74 /* & result
b9b0: 20 63 6f 64 65 73 20 77 69 74 68 20 74 68 69 73 codes with this
b9c0: 20 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 6e before returnin
b9d0: 67 20 2a 2f 0a 20 20 69 6e 74 20 69 53 79 73 45 g */. int iSysE
b9e0: 72 72 6e 6f 3b 20 20 20 20 20 20 20 20 20 20 20 rrno;
b9f0: 20 20 20 20 20 2f 2a 20 45 72 72 6e 6f 20 76 61 /* Errno va
ba00: 6c 75 65 20 66 72 6f 6d 20 6c 61 73 74 20 73 79 lue from last sy
ba10: 73 74 65 6d 20 65 72 72 6f 72 20 2a 2f 0a 20 20 stem error */.
ba20: 75 31 36 20 64 62 4f 70 74 46 6c 61 67 73 3b 20 u16 dbOptFlags;
ba30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
ba40: 20 46 6c 61 67 73 20 74 6f 20 65 6e 61 62 6c 65 Flags to enable
ba50: 2f 64 69 73 61 62 6c 65 20 6f 70 74 69 6d 69 7a /disable optimiz
ba60: 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 75 38 20 65 ations */. u8 e
ba70: 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
ba80: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
ba90: 74 20 65 6e 63 6f 64 69 6e 67 20 2a 2f 0a 20 20 t encoding */.
baa0: 75 38 20 61 75 74 6f 43 6f 6d 6d 69 74 3b 20 20 u8 autoCommit;
bab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
bac0: 20 54 68 65 20 61 75 74 6f 2d 63 6f 6d 6d 69 74 The auto-commit
bad0: 20 66 6c 61 67 2e 20 2a 2f 0a 20 20 75 38 20 74 flag. */. u8 t
bae0: 65 6d 70 5f 73 74 6f 72 65 3b 20 20 20 20 20 20 emp_store;
baf0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 3a 20 /* 1:
bb00: 66 69 6c 65 20 32 3a 20 6d 65 6d 6f 72 79 20 30 file 2: memory 0
bb10: 3a 20 64 65 66 61 75 6c 74 20 2a 2f 0a 20 20 75 : default */. u
bb20: 38 20 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 3b 20 8 mallocFailed;
bb30: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
bb40: 54 72 75 65 20 69 66 20 77 65 20 68 61 76 65 20 True if we have
bb50: 73 65 65 6e 20 61 20 6d 61 6c 6c 6f 63 20 66 61 seen a malloc fa
bb60: 69 6c 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 42 ilure */. u8 bB
bb70: 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3b 20 20 20 20 enignMalloc;
bb80: 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e /* Do n
bb90: 6f 74 20 72 65 71 75 69 72 65 20 4f 4f 4d 73 20 ot require OOMs
bba0: 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 20 if true */. u8
bbb0: 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 3b 20 20 20 dfltLockMode;
bbc0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 /* De
bbd0: 66 61 75 6c 74 20 6c 6f 63 6b 69 6e 67 2d 6d 6f fault locking-mo
bbe0: 64 65 20 66 6f 72 20 61 74 74 61 63 68 65 64 20 de for attached
bbf0: 64 62 73 20 2a 2f 0a 20 20 73 69 67 6e 65 64 20 dbs */. signed
bc00: 63 68 61 72 20 6e 65 78 74 41 75 74 6f 76 61 63 char nextAutovac
bc10: 3b 20 20 20 20 20 20 2f 2a 20 41 75 74 6f 76 61 ; /* Autova
bc20: 63 20 73 65 74 74 69 6e 67 20 61 66 74 65 72 20 c setting after
bc30: 56 41 43 55 55 4d 20 69 66 20 3e 3d 30 20 2a 2f VACUUM if >=0 */
bc40: 0a 20 20 75 38 20 73 75 70 70 72 65 73 73 45 72 . u8 suppressEr
bc50: 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
bc60: 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 73 73 75 65 /* Do not issue
bc70: 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 error messages
bc80: 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 20 if true */. u8
bc90: 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 63 74 3b 20 vtabOnConflict;
bca0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 /* Va
bcb0: 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 66 6f lue to return fo
bcc0: 72 20 73 33 5f 76 74 61 62 5f 6f 6e 5f 63 6f 6e r s3_vtab_on_con
bcd0: 66 6c 69 63 74 28 29 20 2a 2f 0a 20 20 75 38 20 flict() */. u8
bce0: 69 73 54 72 61 6e 73 61 63 74 69 6f 6e 53 61 76 isTransactionSav
bcf0: 65 70 6f 69 6e 74 3b 20 20 20 20 2f 2a 20 54 72 epoint; /* Tr
bd00: 75 65 20 69 66 20 74 68 65 20 6f 75 74 65 72 6d ue if the outerm
bd10: 6f 73 74 20 73 61 76 65 70 6f 69 6e 74 20 69 73 ost savepoint is
bd20: 20 61 20 54 53 20 2a 2f 0a 20 20 75 38 20 6d 54 a TS */. u8 mT
bd30: 72 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 20 race;
bd40: 20 20 20 20 20 20 20 20 20 2f 2a 20 7a 65 72 6f /* zero
bd50: 20 6f 72 20 6d 6f 72 65 20 53 51 4c 49 54 45 5f or more SQLITE_
bd60: 54 52 41 43 45 20 66 6c 61 67 73 20 2a 2f 0a 20 TRACE flags */.
bd70: 20 75 38 20 73 6b 69 70 42 74 72 65 65 4d 75 74 u8 skipBtreeMut
bd80: 65 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ex; /
bd90: 2a 20 54 72 75 65 20 69 66 20 6e 6f 20 73 68 61 * True if no sha
bda0: 72 65 64 2d 63 61 63 68 65 20 62 61 63 6b 65 6e red-cache backen
bdb0: 64 73 20 2a 2f 0a 20 20 75 38 20 6e 53 71 6c 45 ds */. u8 nSqlE
bdc0: 78 65 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 xec;
bdd0: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
bde0: 6f 66 20 70 65 6e 64 69 6e 67 20 4f 50 5f 53 71 of pending OP_Sq
bdf0: 6c 45 78 65 63 20 6f 70 63 6f 64 65 73 20 2a 2f lExec opcodes */
be00: 0a 20 20 69 6e 74 20 6e 65 78 74 50 61 67 65 73 . int nextPages
be10: 69 7a 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ize;
be20: 20 2f 2a 20 50 61 67 65 73 69 7a 65 20 61 66 74 /* Pagesize aft
be30: 65 72 20 56 41 43 55 55 4d 20 69 66 20 3e 30 20 er VACUUM if >0
be40: 2a 2f 0a 20 20 75 33 32 20 6d 61 67 69 63 3b 20 */. u32 magic;
be50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
be60: 20 20 20 2f 2a 20 4d 61 67 69 63 20 6e 75 6d 62 /* Magic numb
be70: 65 72 20 66 6f 72 20 64 65 74 65 63 74 20 6c 69 er for detect li
be80: 62 72 61 72 79 20 6d 69 73 75 73 65 20 2a 2f 0a brary misuse */.
be90: 20 20 69 6e 74 20 6e 43 68 61 6e 67 65 3b 20 20 int nChange;
bea0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
beb0: 2f 2a 20 56 61 6c 75 65 20 72 65 74 75 72 6e 65 /* Value returne
bec0: 64 20 62 79 20 73 71 6c 69 74 65 33 5f 63 68 61 d by sqlite3_cha
bed0: 6e 67 65 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 nges() */. int
bee0: 6e 54 6f 74 61 6c 43 68 61 6e 67 65 3b 20 20 20 nTotalChange;
bef0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c /* Val
bf00: 75 65 20 72 65 74 75 72 6e 65 64 20 62 79 20 73 ue returned by s
bf10: 71 6c 69 74 65 33 5f 74 6f 74 61 6c 5f 63 68 61 qlite3_total_cha
bf20: 6e 67 65 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 nges() */. int
bf30: 61 4c 69 6d 69 74 5b 53 51 4c 49 54 45 5f 4e 5f aLimit[SQLITE_N_
bf40: 4c 49 4d 49 54 5d 3b 20 20 20 2f 2a 20 4c 69 6d LIMIT]; /* Lim
bf50: 69 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 its */. int nMa
bf60: 78 53 6f 72 74 65 72 4d 6d 61 70 3b 20 20 20 20 xSorterMmap;
bf70: 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 /* Maximu
bf80: 6d 20 73 69 7a 65 20 6f 66 20 72 65 67 69 6f 6e m size of region
bf90: 73 20 6d 61 70 70 65 64 20 62 79 20 73 6f 72 74 s mapped by sort
bfa0: 65 72 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 73 er */. struct s
bfb0: 71 6c 69 74 65 33 49 6e 69 74 49 6e 66 6f 20 7b qlite3InitInfo {
bfc0: 20 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 /* Informa
bfd0: 74 69 6f 6e 20 75 73 65 64 20 64 75 72 69 6e 67 tion used during
bfe0: 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
bff0: 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 65 77 54 6e */. int newTn
c000: 75 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 um;
c010: 20 20 20 2f 2a 20 52 6f 6f 74 70 61 67 65 20 6f /* Rootpage o
c020: 66 20 74 61 62 6c 65 20 62 65 69 6e 67 20 69 6e f table being in
c030: 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 itialized */.
c040: 20 75 38 20 69 44 62 3b 20 20 20 20 20 20 20 20 u8 iDb;
c050: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c060: 57 68 69 63 68 20 64 62 20 66 69 6c 65 20 69 73 Which db file is
c070: 20 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a being initializ
c080: 65 64 20 2a 2f 0a 20 20 20 20 75 38 20 62 75 73 ed */. u8 bus
c090: 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 y;
c0a0: 20 20 20 20 20 20 2f 2a 20 54 52 55 45 20 69 66 /* TRUE if
c0b0: 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 69 74 69 currently initi
c0c0: 61 6c 69 7a 69 6e 67 20 2a 2f 0a 20 20 20 20 75 alizing */. u
c0d0: 6e 73 69 67 6e 65 64 20 6f 72 70 68 61 6e 54 72 nsigned orphanTr
c0e0: 69 67 67 65 72 20 3a 20 31 3b 20 2f 2a 20 4c 61 igger : 1; /* La
c0f0: 73 74 20 73 74 61 74 65 6d 65 6e 74 20 69 73 20 st statement is
c100: 6f 72 70 68 61 6e 65 64 20 54 45 4d 50 20 74 72 orphaned TEMP tr
c110: 69 67 67 65 72 20 2a 2f 0a 20 20 20 20 75 6e 73 igger */. uns
c120: 69 67 6e 65 64 20 69 6d 70 6f 73 74 65 72 54 61 igned imposterTa
c130: 62 6c 65 20 3a 20 31 3b 20 2f 2a 20 42 75 69 6c ble : 1; /* Buil
c140: 64 69 6e 67 20 61 6e 20 69 6d 70 6f 73 74 65 72 ding an imposter
c150: 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 75 6e table */. un
c160: 73 69 67 6e 65 64 20 72 65 6f 70 65 6e 4d 65 6d signed reopenMem
c170: 64 62 20 3a 20 31 3b 20 20 20 2f 2a 20 41 54 54 db : 1; /* ATT
c180: 41 43 48 20 69 73 20 72 65 61 6c 6c 79 20 61 20 ACH is really a
c190: 72 65 6f 70 65 6e 20 75 73 69 6e 67 20 4d 65 6d reopen using Mem
c1a0: 44 42 20 2a 2f 0a 20 20 7d 20 69 6e 69 74 3b 0a DB */. } init;.
c1b0: 20 20 69 6e 74 20 6e 56 64 62 65 41 63 74 69 76 int nVdbeActiv
c1c0: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
c1d0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 56 44 42 /* Number of VDB
c1e0: 45 73 20 63 75 72 72 65 6e 74 6c 79 20 72 75 6e Es currently run
c1f0: 6e 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 ning */. int nV
c200: 64 62 65 52 65 61 64 3b 20 20 20 20 20 20 20 20 dbeRead;
c210: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
c220: 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 r of active VDBE
c230: 73 20 74 68 61 74 20 72 65 61 64 20 6f 72 20 77 s that read or w
c240: 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 rite */. int nV
c250: 64 62 65 57 72 69 74 65 3b 20 20 20 20 20 20 20 dbeWrite;
c260: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
c270: 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 45 r of active VDBE
c280: 73 20 74 68 61 74 20 72 65 61 64 20 61 6e 64 20 s that read and
c290: 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e write */. int n
c2a0: 56 64 62 65 45 78 65 63 3b 20 20 20 20 20 20 20 VdbeExec;
c2b0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
c2c0: 65 72 20 6f 66 20 6e 65 73 74 65 64 20 63 61 6c er of nested cal
c2d0: 6c 73 20 74 6f 20 56 64 62 65 45 78 65 63 28 29 ls to VdbeExec()
c2e0: 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 44 65 73 74 */. int nVDest
c2f0: 72 6f 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 roy;
c300: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
c310: 20 61 63 74 69 76 65 20 4f 50 5f 56 44 65 73 74 active OP_VDest
c320: 72 6f 79 20 6f 70 65 72 61 74 69 6f 6e 73 20 2a roy operations *
c330: 2f 0a 20 20 69 6e 74 20 6e 45 78 74 65 6e 73 69 /. int nExtensi
c340: 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 on;
c350: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c /* Number of l
c360: 6f 61 64 65 64 20 65 78 74 65 6e 73 69 6f 6e 73 oaded extensions
c370: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 2a 61 45 78 */. void **aEx
c380: 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 20 20 20 tension;
c390: 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 /* Array of
c3a0: 73 68 61 72 65 64 20 6c 69 62 72 61 72 79 20 68 shared library h
c3b0: 61 6e 64 6c 65 73 20 2a 2f 0a 20 20 69 6e 74 20 andles */. int
c3c0: 28 2a 78 54 72 61 63 65 29 28 75 33 32 2c 76 6f (*xTrace)(u32,vo
c3d0: 69 64 2a 2c 76 6f 69 64 2a 2c 76 6f 69 64 2a 29 id*,void*,void*)
c3e0: 3b 20 20 20 20 20 2f 2a 20 54 72 61 63 65 20 66 ; /* Trace f
c3f0: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 unction */. voi
c400: 64 20 2a 70 54 72 61 63 65 41 72 67 3b 20 20 20 d *pTraceArg;
c410: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c420: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
c430: 6e 74 20 74 6f 20 74 68 65 20 74 72 61 63 65 20 nt to the trace
c440: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f function */. vo
c450: 69 64 20 28 2a 78 50 72 6f 66 69 6c 65 29 28 76 id (*xProfile)(v
c460: 6f 69 64 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a oid*,const char*
c470: 2c 75 36 34 29 3b 20 20 2f 2a 20 50 72 6f 66 69 ,u64); /* Profi
c480: 6c 69 6e 67 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ling function */
c490: 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f 66 69 6c . void *pProfil
c4a0: 65 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 eArg;
c4b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c4c0: 41 72 67 75 6d 65 6e 74 20 74 6f 20 70 72 6f 66 Argument to prof
c4d0: 69 6c 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a ile function */.
c4e0: 20 20 76 6f 69 64 20 2a 70 43 6f 6d 6d 69 74 41 void *pCommitA
c4f0: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
c500: 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 /* Argument
c510: 74 6f 20 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 to xCommitCallba
c520: 63 6b 28 29 20 2a 2f 0a 20 20 69 6e 74 20 28 2a ck() */. int (*
c530: 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b 29 xCommitCallback)
c540: 28 76 6f 69 64 2a 29 3b 20 20 20 20 2f 2a 20 49 (void*); /* I
c550: 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 20 nvoked at every
c560: 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 commit. */. voi
c570: 64 20 2a 70 52 6f 6c 6c 62 61 63 6b 41 72 67 3b d *pRollbackArg;
c580: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c590: 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 52 * Argument to xR
c5a0: 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 6b 28 ollbackCallback(
c5b0: 29 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 52 ) */. void (*xR
c5c0: 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 63 6b 29 ollbackCallback)
c5d0: 28 76 6f 69 64 2a 29 3b 20 2f 2a 20 49 6e 76 6f (void*); /* Invo
c5e0: 6b 65 64 20 61 74 20 65 76 65 72 79 20 63 6f 6d ked at every com
c5f0: 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a mit. */. void *
c600: 70 55 70 64 61 74 65 41 72 67 3b 0a 20 20 76 6f pUpdateArg;. vo
c610: 69 64 20 28 2a 78 55 70 64 61 74 65 43 61 6c 6c id (*xUpdateCall
c620: 62 61 63 6b 29 28 76 6f 69 64 2a 2c 69 6e 74 2c back)(void*,int,
c630: 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e const char*,con
c640: 73 74 20 63 68 61 72 2a 2c 73 71 6c 69 74 65 5f st char*,sqlite_
c650: 69 6e 74 36 34 29 3b 0a 23 69 66 64 65 66 20 53 int64);.#ifdef S
c660: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 45 QLITE_ENABLE_PRE
c670: 55 50 44 41 54 45 5f 48 4f 4f 4b 0a 20 20 76 6f UPDATE_HOOK. vo
c680: 69 64 20 2a 70 50 72 65 55 70 64 61 74 65 41 72 id *pPreUpdateAr
c690: 67 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 g; /* F
c6a0: 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f irst argument to
c6b0: 20 78 50 72 65 55 70 64 61 74 65 43 61 6c 6c 62 xPreUpdateCallb
c6c0: 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a ack */. void (*
c6d0: 78 50 72 65 55 70 64 61 74 65 43 61 6c 6c 62 61 xPreUpdateCallba
c6e0: 63 6b 29 28 20 20 20 2f 2a 20 52 65 67 69 73 74 ck)( /* Regist
c6f0: 65 72 65 64 20 75 73 69 6e 67 20 73 71 6c 69 74 ered using sqlit
c700: 65 33 5f 70 72 65 75 70 64 61 74 65 5f 68 6f 6f e3_preupdate_hoo
c710: 6b 28 29 20 2a 2f 0a 20 20 20 20 76 6f 69 64 2a k() */. void*
c720: 2c 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 68 ,sqlite3*,int,ch
c730: 61 72 20 63 6f 6e 73 74 2a 2c 63 68 61 72 20 63 ar const*,char c
c740: 6f 6e 73 74 2a 2c 73 71 6c 69 74 65 33 5f 69 6e onst*,sqlite3_in
c750: 74 36 34 2c 73 71 6c 69 74 65 33 5f 69 6e 74 36 t64,sqlite3_int6
c760: 34 0a 20 20 29 3b 0a 20 20 50 72 65 55 70 64 61 4. );. PreUpda
c770: 74 65 20 2a 70 50 72 65 55 70 64 61 74 65 3b 20 te *pPreUpdate;
c780: 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 74 65 78 /* Contex
c790: 74 20 66 6f 72 20 61 63 74 69 76 65 20 70 72 65 t for active pre
c7a0: 2d 75 70 64 61 74 65 20 63 61 6c 6c 62 61 63 6b -update callback
c7b0: 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 */.#endif /* SQ
c7c0: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 45 55 LITE_ENABLE_PREU
c7d0: 50 44 41 54 45 5f 48 4f 4f 4b 20 2a 2f 0a 23 69 PDATE_HOOK */.#i
c7e0: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
c7f0: 54 5f 57 41 4c 0a 20 20 69 6e 74 20 28 2a 78 57 T_WAL. int (*xW
c800: 61 6c 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 alCallback)(void
c810: 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a 2c 20 63 *, sqlite3 *, c
c820: 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 onst char *, int
c830: 29 3b 0a 20 20 76 6f 69 64 20 2a 70 57 61 6c 41 );. void *pWalA
c840: 72 67 3b 0a 23 65 6e 64 69 66 0a 20 20 76 6f 69 rg;.#endif. voi
c850: 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 29 28 d(*xCollNeeded)(
c860: 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 void*,sqlite3*,i
c870: 6e 74 20 65 54 65 78 74 52 65 70 2c 63 6f 6e 73 nt eTextRep,cons
c880: 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 t char*);. void
c890: 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 31 36 29 (*xCollNeeded16)
c8a0: 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c (void*,sqlite3*,
c8b0: 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 6f 6e int eTextRep,con
c8c0: 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 st void*);. voi
c8d0: 64 20 2a 70 43 6f 6c 6c 4e 65 65 64 65 64 41 72 d *pCollNeededAr
c8e0: 67 3b 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 6c g;. sqlite3_val
c8f0: 75 65 20 2a 70 45 72 72 3b 20 20 20 20 20 20 20 ue *pErr;
c900: 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 63 65 6e /* Most recen
c910: 74 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 t error message
c920: 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 */. union {.
c930: 20 76 6f 6c 61 74 69 6c 65 20 69 6e 74 20 69 73 volatile int is
c940: 49 6e 74 65 72 72 75 70 74 65 64 3b 20 2f 2a 20 Interrupted; /*
c950: 54 72 75 65 20 69 66 20 73 71 6c 69 74 65 33 5f True if sqlite3_
c960: 69 6e 74 65 72 72 75 70 74 20 68 61 73 20 62 65 interrupt has be
c970: 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 20 en called */.
c980: 20 64 6f 75 62 6c 65 20 6e 6f 74 55 73 65 64 31 double notUsed1
c990: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
c9a0: 53 70 61 63 65 72 20 2a 2f 0a 20 20 7d 20 75 31 Spacer */. } u1
c9b0: 3b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 20 6c 6f ;. Lookaside lo
c9c0: 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 20 20 20 okaside;
c9d0: 20 20 2f 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 6d /* Lookaside m
c9e0: 61 6c 6c 6f 63 20 63 6f 6e 66 69 67 75 72 61 74 alloc configurat
c9f0: 69 6f 6e 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ion */.#ifndef S
ca00: 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 54 48 4f QLITE_OMIT_AUTHO
ca10: 52 49 5a 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 RIZATION. sqlit
ca20: 65 33 5f 78 61 75 74 68 20 78 41 75 74 68 3b 20 e3_xauth xAuth;
ca30: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 63 63 65 /* Acce
ca40: 73 73 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e ss authorization
ca50: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 function */. v
ca60: 6f 69 64 20 2a 70 41 75 74 68 41 72 67 3b 20 20 oid *pAuthArg;
ca70: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
ca80: 31 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 1st argument to
ca90: 74 68 65 20 61 63 63 65 73 73 20 61 75 74 68 20 the access auth
caa0: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 function */.#end
cab0: 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
cac0: 45 5f 4f 4d 49 54 5f 50 52 4f 47 52 45 53 53 5f E_OMIT_PROGRESS_
cad0: 43 41 4c 4c 42 41 43 4b 0a 20 20 69 6e 74 20 28 CALLBACK. int (
cae0: 2a 78 50 72 6f 67 72 65 73 73 29 28 76 6f 69 64 *xProgress)(void
caf0: 20 2a 29 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 *); /* The
cb00: 70 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 progress callbac
cb10: 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 72 k */. void *pPr
cb20: 6f 67 72 65 73 73 41 72 67 3b 20 20 20 20 20 20 ogressArg;
cb30: 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 /* Argument
cb40: 20 74 6f 20 74 68 65 20 70 72 6f 67 72 65 73 73 to the progress
cb50: 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 75 callback */. u
cb60: 6e 73 69 67 6e 65 64 20 6e 50 72 6f 67 72 65 73 nsigned nProgres
cb70: 73 4f 70 73 3b 20 20 20 20 20 20 20 20 2f 2a 20 sOps; /*
cb80: 4e 75 6d 62 65 72 20 6f 66 20 6f 70 63 6f 64 65 Number of opcode
cb90: 73 20 66 6f 72 20 70 72 6f 67 72 65 73 73 20 63 s for progress c
cba0: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e 64 69 allback */.#endi
cbb0: 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 f.#ifndef SQLITE
cbc0: 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
cbd0: 4c 45 0a 20 20 69 6e 74 20 6e 56 54 72 61 6e 73 LE. int nVTrans
cbe0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
cbf0: 20 20 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 64 20 /* Allocated
cc00: 73 69 7a 65 20 6f 66 20 61 56 54 72 61 6e 73 20 size of aVTrans
cc10: 2a 2f 0a 20 20 48 61 73 68 20 61 4d 6f 64 75 6c */. Hash aModul
cc20: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
cc30: 20 20 20 2f 2a 20 70 6f 70 75 6c 61 74 65 64 20 /* populated
cc40: 62 79 20 73 71 6c 69 74 65 33 5f 63 72 65 61 74 by sqlite3_creat
cc50: 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 e_module() */.
cc60: 56 74 61 62 43 74 78 20 2a 70 56 74 61 62 43 74 VtabCtx *pVtabCt
cc70: 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a x; /*
cc80: 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 61 63 74 Context for act
cc90: 69 76 65 20 76 74 61 62 20 63 6f 6e 6e 65 63 74 ive vtab connect
cca0: 2f 63 72 65 61 74 65 20 2a 2f 0a 20 20 56 54 61 /create */. VTa
ccb0: 62 6c 65 20 2a 2a 61 56 54 72 61 6e 73 3b 20 20 ble **aVTrans;
ccc0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 69 /* Vi
ccd0: 72 74 75 61 6c 20 74 61 62 6c 65 73 20 77 69 74 rtual tables wit
cce0: 68 20 6f 70 65 6e 20 74 72 61 6e 73 61 63 74 69 h open transacti
ccf0: 6f 6e 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 ons */. VTable
cd00: 2a 70 44 69 73 63 6f 6e 6e 65 63 74 3b 20 20 20 *pDisconnect;
cd10: 20 20 20 20 20 20 20 2f 2a 20 44 69 73 63 6f 6e /* Discon
cd20: 6e 65 63 74 20 74 68 65 73 65 20 69 6e 20 6e 65 nect these in ne
cd30: 78 74 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 xt sqlite3_prepa
cd40: 72 65 28 29 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 re() */.#endif.
cd50: 20 48 61 73 68 20 61 46 75 6e 63 3b 20 20 20 20 Hash aFunc;
cd60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
cd70: 2a 20 48 61 73 68 20 74 61 62 6c 65 20 6f 66 20 * Hash table of
cd80: 63 6f 6e 6e 65 63 74 69 6f 6e 20 66 75 6e 63 74 connection funct
cd90: 69 6f 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 61 ions */. Hash a
cda0: 43 6f 6c 6c 53 65 71 3b 20 20 20 20 20 20 20 20 CollSeq;
cdb0: 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 63 /* All c
cdc0: 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
cdd0: 65 73 20 2a 2f 0a 20 20 42 75 73 79 48 61 6e 64 es */. BusyHand
cde0: 6c 65 72 20 62 75 73 79 48 61 6e 64 6c 65 72 3b ler busyHandler;
cdf0: 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 63 61 /* Busy ca
ce00: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 44 62 20 61 llback */. Db a
ce10: 44 62 53 74 61 74 69 63 5b 32 5d 3b 20 20 20 20 DbStatic[2];
ce20: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 61 /* Sta
ce30: 74 69 63 20 73 70 61 63 65 20 66 6f 72 20 74 68 tic space for th
ce40: 65 20 32 20 64 65 66 61 75 6c 74 20 62 61 63 6b e 2 default back
ce50: 65 6e 64 73 20 2a 2f 0a 20 20 53 61 76 65 70 6f ends */. Savepo
ce60: 69 6e 74 20 2a 70 53 61 76 65 70 6f 69 6e 74 3b int *pSavepoint;
ce70: 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 /* List
ce80: 6f 66 20 61 63 74 69 76 65 20 73 61 76 65 70 6f of active savepo
ce90: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 62 75 ints */. int bu
cea0: 73 79 54 69 6d 65 6f 75 74 3b 20 20 20 20 20 20 syTimeout;
ceb0: 20 20 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 /* Busy
cec0: 68 61 6e 64 6c 65 72 20 74 69 6d 65 6f 75 74 2c handler timeout,
ced0: 20 69 6e 20 6d 73 65 63 20 2a 2f 0a 20 20 69 6e in msec */. in
cee0: 74 20 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 t nSavepoint;
cef0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
cf00: 75 6d 62 65 72 20 6f 66 20 6e 6f 6e 2d 74 72 61 umber of non-tra
cf10: 6e 73 61 63 74 69 6f 6e 20 73 61 76 65 70 6f 69 nsaction savepoi
cf20: 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 nts */. int nSt
cf30: 61 74 65 6d 65 6e 74 3b 20 20 20 20 20 20 20 20 atement;
cf40: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
cf50: 20 6f 66 20 6e 65 73 74 65 64 20 73 74 61 74 65 of nested state
cf60: 6d 65 6e 74 2d 74 72 61 6e 73 61 63 74 69 6f 6e ment-transaction
cf70: 73 20 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 s */. i64 nDef
cf80: 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 erredCons;
cf90: 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 66 /* Net def
cfa0: 65 72 72 65 64 20 63 6f 6e 73 74 72 61 69 6e 74 erred constraint
cfb0: 73 20 74 68 69 73 20 74 72 61 6e 73 61 63 74 69 s this transacti
cfc0: 6f 6e 2e 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 on. */. i64 nDe
cfd0: 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 ferredImmCons;
cfe0: 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 /* Net de
cff0: 66 65 72 72 65 64 20 69 6d 6d 65 64 69 61 74 65 ferred immediate
d000: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
d010: 20 20 69 6e 74 20 2a 70 6e 42 79 74 65 73 46 72 int *pnBytesFr
d020: 65 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 eed;
d030: 2f 2a 20 49 66 20 6e 6f 74 20 4e 55 4c 4c 2c 20 /* If not NULL,
d040: 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 73 20 69 increment this i
d050: 6e 20 44 62 46 72 65 65 28 29 20 2a 2f 0a 23 69 n DbFree() */.#i
d060: 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
d070: 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 59 LE_UNLOCK_NOTIFY
d080: 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 . /* The follow
d090: 69 6e 67 20 76 61 72 69 61 62 6c 65 73 20 61 72 ing variables ar
d0a0: 65 20 61 6c 6c 20 70 72 6f 74 65 63 74 65 64 20 e all protected
d0b0: 62 79 20 74 68 65 20 53 54 41 54 49 43 5f 4d 41 by the STATIC_MA
d0c0: 53 54 45 52 0a 20 20 2a 2a 20 6d 75 74 65 78 2c STER. ** mutex,
d0d0: 20 6e 6f 74 20 62 79 20 73 71 6c 69 74 65 33 2e not by sqlite3.
d0e0: 6d 75 74 65 78 2e 20 54 68 65 79 20 61 72 65 20 mutex. They are
d0f0: 75 73 65 64 20 62 79 20 63 6f 64 65 20 69 6e 20 used by code in
d100: 6e 6f 74 69 66 79 2e 63 2e 0a 20 20 2a 2a 0a 20 notify.c.. **.
d110: 20 2a 2a 20 57 68 65 6e 20 58 2e 70 55 6e 6c 6f ** When X.pUnlo
d120: 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c ckConnection==Y,
d130: 20 74 68 61 74 20 6d 65 61 6e 73 20 74 68 61 74 that means that
d140: 20 58 20 69 73 20 77 61 69 74 69 6e 67 20 66 6f X is waiting fo
d150: 72 20 59 20 74 6f 0a 20 20 2a 2a 20 75 6e 6c 6f r Y to. ** unlo
d160: 63 6b 20 73 6f 20 74 68 61 74 20 69 74 20 63 61 ck so that it ca
d170: 6e 20 70 72 6f 63 65 65 64 2e 0a 20 20 2a 2a 0a n proceed.. **.
d180: 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 42 6c 6f ** When X.pBlo
d190: 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 6f 6e 3d ckingConnection=
d1a0: 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 =Y, that means t
d1b0: 68 61 74 20 73 6f 6d 65 74 68 69 6e 67 20 74 68 hat something th
d1c0: 61 74 20 58 20 74 72 69 65 64 0a 20 20 2a 2a 20 at X tried. **
d1d0: 74 72 69 65 64 20 74 6f 20 64 6f 20 72 65 63 65 tried to do rece
d1e0: 6e 74 6c 79 20 66 61 69 6c 65 64 20 77 69 74 68 ntly failed with
d1f0: 20 61 6e 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 an SQLITE_LOCKE
d200: 44 20 65 72 72 6f 72 20 64 75 65 20 74 6f 20 6c D error due to l
d210: 6f 63 6b 73 0a 20 20 2a 2a 20 68 65 6c 64 20 62 ocks. ** held b
d220: 79 20 59 2e 0a 20 20 2a 2f 0a 20 20 73 71 6c 69 y Y.. */. sqli
d230: 74 65 33 20 2a 70 42 6c 6f 63 6b 69 6e 67 43 6f te3 *pBlockingCo
d240: 6e 6e 65 63 74 69 6f 6e 3b 20 2f 2a 20 43 6f 6e nnection; /* Con
d250: 6e 65 63 74 69 6f 6e 20 74 68 61 74 20 63 61 75 nection that cau
d260: 73 65 64 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 sed SQLITE_LOCKE
d270: 44 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a D */. sqlite3 *
d280: 70 55 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f pUnlockConnectio
d290: 6e 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 n; /*
d2a0: 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 77 61 Connection to wa
d2b0: 74 63 68 20 66 6f 72 20 75 6e 6c 6f 63 6b 20 2a tch for unlock *
d2c0: 2f 0a 20 20 76 6f 69 64 20 2a 70 55 6e 6c 6f 63 /. void *pUnloc
d2d0: 6b 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 kArg;
d2e0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 /* Arg
d2f0: 75 6d 65 6e 74 20 74 6f 20 78 55 6e 6c 6f 63 6b ument to xUnlock
d300: 4e 6f 74 69 66 79 20 2a 2f 0a 20 20 76 6f 69 64 Notify */. void
d310: 20 28 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 79 (*xUnlockNotify
d320: 29 28 76 6f 69 64 20 2a 2a 2c 20 69 6e 74 29 3b )(void **, int);
d330: 20 20 2f 2a 20 55 6e 6c 6f 63 6b 20 6e 6f 74 69 /* Unlock noti
d340: 66 79 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 fy callback */.
d350: 20 73 71 6c 69 74 65 33 20 2a 70 4e 65 78 74 42 sqlite3 *pNextB
d360: 6c 6f 63 6b 65 64 3b 20 20 20 20 20 20 20 20 2f locked; /
d370: 2a 20 4e 65 78 74 20 69 6e 20 6c 69 73 74 20 6f * Next in list o
d380: 66 20 61 6c 6c 20 62 6c 6f 63 6b 65 64 20 63 6f f all blocked co
d390: 6e 6e 65 63 74 69 6f 6e 73 20 2a 2f 0a 23 65 6e nnections */.#en
d3a0: 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 dif.#ifdef SQLIT
d3b0: 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 43 E_USER_AUTHENTIC
d3c0: 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 65 33 5f ATION. sqlite3_
d3d0: 75 73 65 72 61 75 74 68 20 61 75 74 68 3b 20 20 userauth auth;
d3e0: 20 20 20 20 20 20 2f 2a 20 55 73 65 72 20 61 75 /* User au
d3f0: 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 69 6e 66 thentication inf
d400: 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 ormation */.#end
d410: 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d if.};../*.** A m
d420: 61 63 72 6f 20 74 6f 20 64 69 73 63 6f 76 65 72 acro to discover
d430: 20 74 68 65 20 65 6e 63 6f 64 69 6e 67 20 6f 66 the encoding of
d440: 20 61 20 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a a database..*/.
d450: 23 64 65 66 69 6e 65 20 53 43 48 45 4d 41 5f 45 #define SCHEMA_E
d460: 4e 43 28 64 62 29 20 28 28 64 62 29 2d 3e 61 44 NC(db) ((db)->aD
d470: 62 5b 30 5d 2e 70 53 63 68 65 6d 61 2d 3e 65 6e b[0].pSchema->en
d480: 63 29 0a 23 64 65 66 69 6e 65 20 45 4e 43 28 64 c).#define ENC(d
d490: 62 29 20 20 20 20 20 20 20 20 28 28 64 62 29 2d b) ((db)-
d4a0: 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 >enc)../*.** Pos
d4b0: 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 sible values for
d4c0: 20 74 68 65 20 73 71 6c 69 74 65 33 2e 66 6c 61 the sqlite3.fla
d4d0: 67 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 gs..**.** Value
d4e0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 65 6e 66 constraints (enf
d4f0: 6f 72 63 65 64 20 76 69 61 20 61 73 73 65 72 74 orced via assert
d500: 28 29 29 3a 0a 2a 2a 20 20 20 20 20 20 53 51 4c ()):.** SQL
d510: 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 20 20 20 ITE_FullFSync
d520: 20 20 3d 3d 20 50 41 47 45 52 5f 46 55 4c 4c 46 == PAGER_FULLF
d530: 53 59 4e 43 0a 2a 2a 20 20 20 20 20 20 53 51 4c SYNC.** SQL
d540: 49 54 45 5f 43 6b 70 74 46 75 6c 6c 46 53 79 6e ITE_CkptFullFSyn
d550: 63 20 3d 3d 20 50 41 47 45 52 5f 43 4b 50 54 5f c == PAGER_CKPT_
d560: 46 55 4c 4c 46 53 59 4e 43 0a 2a 2a 20 20 20 20 FULLFSYNC.**
d570: 20 20 53 51 4c 49 54 45 5f 43 61 63 68 65 53 70 SQLITE_CacheSp
d580: 69 6c 6c 20 20 20 20 3d 3d 20 50 41 47 45 52 5f ill == PAGER_
d590: 43 41 43 48 45 5f 53 50 49 4c 4c 0a 2a 2f 0a 23 CACHE_SPILL.*/.#
d5a0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 72 define SQLITE_Wr
d5b0: 69 74 65 53 63 68 65 6d 61 20 20 20 20 30 78 30 iteSchema 0x0
d5c0: 30 30 30 30 30 30 31 20 20 2f 2a 20 4f 4b 20 74 0000001 /* OK t
d5d0: 6f 20 75 70 64 61 74 65 20 53 51 4c 49 54 45 5f o update SQLITE_
d5e0: 4d 41 53 54 45 52 20 2a 2f 0a 23 64 65 66 69 6e MASTER */.#defin
d5f0: 65 20 53 51 4c 49 54 45 5f 4c 65 67 61 63 79 46 e SQLITE_LegacyF
d600: 69 6c 65 46 6d 74 20 20 30 78 30 30 30 30 30 30 ileFmt 0x000000
d610: 30 32 20 20 2f 2a 20 43 72 65 61 74 65 20 6e 65 02 /* Create ne
d620: 77 20 64 61 74 61 62 61 73 65 73 20 69 6e 20 66 w databases in f
d630: 6f 72 6d 61 74 20 31 20 2a 2f 0a 23 64 65 66 69 ormat 1 */.#defi
d640: 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c 43 6f ne SQLITE_FullCo
d650: 6c 4e 61 6d 65 73 20 20 20 30 78 30 30 30 30 30 lNames 0x00000
d660: 30 30 34 20 20 2f 2a 20 53 68 6f 77 20 66 75 6c 004 /* Show ful
d670: 6c 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6f l column names o
d680: 6e 20 53 45 4c 45 43 54 20 2a 2f 0a 23 64 65 66 n SELECT */.#def
d690: 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c 46 ine SQLITE_FullF
d6a0: 53 79 6e 63 20 20 20 20 20 20 30 78 30 30 30 30 Sync 0x0000
d6b0: 30 30 30 38 20 20 2f 2a 20 55 73 65 20 66 75 6c 0008 /* Use ful
d6c0: 6c 20 66 73 79 6e 63 20 6f 6e 20 74 68 65 20 62 l fsync on the b
d6d0: 61 63 6b 65 6e 64 20 2a 2f 0a 23 64 65 66 69 6e ackend */.#defin
d6e0: 65 20 53 51 4c 49 54 45 5f 43 6b 70 74 46 75 6c e SQLITE_CkptFul
d6f0: 6c 46 53 79 6e 63 20 20 30 78 30 30 30 30 30 30 lFSync 0x000000
d700: 31 30 20 20 2f 2a 20 55 73 65 20 66 75 6c 6c 20 10 /* Use full
d710: 66 73 79 6e 63 20 66 6f 72 20 63 68 65 63 6b 70 fsync for checkp
d720: 6f 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 oint */.#define
d730: 53 51 4c 49 54 45 5f 43 61 63 68 65 53 70 69 6c SQLITE_CacheSpil
d740: 6c 20 20 20 20 20 30 78 30 30 30 30 30 30 32 30 l 0x00000020
d750: 20 20 2f 2a 20 4f 4b 20 74 6f 20 73 70 69 6c 6c /* OK to spill
d760: 20 70 61 67 65 72 20 63 61 63 68 65 20 2a 2f 0a pager cache */.
d770: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
d780: 68 6f 72 74 43 6f 6c 4e 61 6d 65 73 20 20 30 78 hortColNames 0x
d790: 30 30 30 30 30 30 34 30 20 20 2f 2a 20 53 68 6f 00000040 /* Sho
d7a0: 77 20 73 68 6f 72 74 20 63 6f 6c 75 6d 6e 73 20 w short columns
d7b0: 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 names */.#define
d7c0: 20 53 51 4c 49 54 45 5f 43 6f 75 6e 74 52 6f 77 SQLITE_CountRow
d7d0: 73 20 20 20 20 20 20 30 78 30 30 30 30 30 30 38 s 0x0000008
d7e0: 30 20 20 2f 2a 20 43 6f 75 6e 74 20 72 6f 77 73 0 /* Count rows
d7f0: 20 63 68 61 6e 67 65 64 20 62 79 20 49 4e 53 45 changed by INSE
d800: 52 54 2c 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 RT, */.
d810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d820: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d830: 20 2f 2a 20 20 20 44 45 4c 45 54 45 2c 20 6f 72 /* DELETE, or
d840: 20 55 50 44 41 54 45 20 61 6e 64 20 72 65 74 75 UPDATE and retu
d850: 72 6e 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 rn */.
d860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d870: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d880: 2f 2a 20 20 20 74 68 65 20 63 6f 75 6e 74 20 75 /* the count u
d890: 73 69 6e 67 20 61 20 63 61 6c 6c 62 61 63 6b 2e sing a callback.
d8a0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
d8b0: 54 45 5f 4e 75 6c 6c 43 61 6c 6c 62 61 63 6b 20 TE_NullCallback
d8c0: 20 20 30 78 30 30 30 30 30 31 30 30 20 20 2f 2a 0x00000100 /*
d8d0: 20 49 6e 76 6f 6b 65 20 74 68 65 20 63 61 6c 6c Invoke the call
d8e0: 62 61 63 6b 20 6f 6e 63 65 20 69 66 20 74 68 65 back once if the
d8f0: 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 */.
d900: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
d920: 20 20 20 72 65 73 75 6c 74 20 73 65 74 20 69 73 result set is
d930: 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 69 6e empty */.#defin
d940: 65 20 53 51 4c 49 54 45 5f 49 67 6e 6f 72 65 43 e SQLITE_IgnoreC
d950: 68 65 63 6b 73 20 20 20 30 78 30 30 30 30 30 32 hecks 0x000002
d960: 30 30 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 6e 00 /* Do not en
d970: 66 6f 72 63 65 20 63 68 65 63 6b 20 63 6f 6e 73 force check cons
d980: 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 66 69 traints */.#defi
d990: 6e 65 20 53 51 4c 49 54 45 5f 52 65 61 64 55 6e ne SQLITE_ReadUn
d9a0: 63 6f 6d 6d 69 74 20 20 20 30 78 30 30 30 30 30 commit 0x00000
d9b0: 34 30 30 20 20 2f 2a 20 52 45 41 44 20 55 4e 43 400 /* READ UNC
d9c0: 4f 4d 4d 49 54 54 45 44 20 69 6e 20 73 68 61 72 OMMITTED in shar
d9d0: 65 64 2d 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 ed-cache */.#def
d9e0: 69 6e 65 20 53 51 4c 49 54 45 5f 4e 6f 43 6b 70 ine SQLITE_NoCkp
d9f0: 74 4f 6e 43 6c 6f 73 65 20 20 30 78 30 30 30 30 tOnClose 0x0000
da00: 30 38 30 30 20 20 2f 2a 20 4e 6f 20 63 68 65 63 0800 /* No chec
da10: 6b 70 6f 69 6e 74 20 6f 6e 20 63 6c 6f 73 65 28 kpoint on close(
da20: 29 2f 44 45 54 41 43 48 20 2a 2f 0a 23 64 65 66 )/DETACH */.#def
da30: 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 76 65 72 ine SQLITE_Rever
da40: 73 65 4f 72 64 65 72 20 20 20 30 78 30 30 30 30 seOrder 0x0000
da50: 31 30 30 30 20 20 2f 2a 20 52 65 76 65 72 73 65 1000 /* Reverse
da60: 20 75 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 43 unordered SELEC
da70: 54 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 Ts */.#define SQ
da80: 4c 49 54 45 5f 52 65 63 54 72 69 67 67 65 72 73 LITE_RecTriggers
da90: 20 20 20 20 30 78 30 30 30 30 32 30 30 30 20 20 0x00002000
daa0: 2f 2a 20 45 6e 61 62 6c 65 20 72 65 63 75 72 73 /* Enable recurs
dab0: 69 76 65 20 74 72 69 67 67 65 72 73 20 2a 2f 0a ive triggers */.
dac0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
dad0: 6f 72 65 69 67 6e 4b 65 79 73 20 20 20 20 30 78 oreignKeys 0x
dae0: 30 30 30 30 34 30 30 30 20 20 2f 2a 20 45 6e 66 00004000 /* Enf
daf0: 6f 72 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 orce foreign key
db00: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a 2f constraints */
db10: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
db20: 41 75 74 6f 49 6e 64 65 78 20 20 20 20 20 20 30 AutoIndex 0
db30: 78 30 30 30 30 38 30 30 30 20 20 2f 2a 20 45 6e x00008000 /* En
db40: 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 69 able automatic i
db50: 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e ndexes */.#defin
db60: 65 20 53 51 4c 49 54 45 5f 4c 6f 61 64 45 78 74 e SQLITE_LoadExt
db70: 65 6e 73 69 6f 6e 20 20 30 78 30 30 30 31 30 30 ension 0x000100
db80: 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 6c 6f 00 /* Enable lo
db90: 61 64 5f 65 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a ad_extension */.
dba0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c #define SQLITE_L
dbb0: 6f 61 64 45 78 74 46 75 6e 63 20 20 20 20 30 78 oadExtFunc 0x
dbc0: 30 30 30 32 30 30 30 30 20 20 2f 2a 20 45 6e 61 00020000 /* Ena
dbd0: 62 6c 65 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 ble load_extensi
dbe0: 6f 6e 28 29 20 53 51 4c 20 66 75 6e 63 20 2a 2f on() SQL func */
dbf0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
dc00: 45 6e 61 62 6c 65 54 72 69 67 67 65 72 20 20 30 EnableTrigger 0
dc10: 78 30 30 30 34 30 30 30 30 20 20 2f 2a 20 54 72 x00040000 /* Tr
dc20: 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 74 72 69 ue to enable tri
dc30: 67 67 65 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 ggers */.#define
dc40: 20 53 51 4c 49 54 45 5f 44 65 66 65 72 46 4b 73 SQLITE_DeferFKs
dc50: 20 20 20 20 20 20 20 30 78 30 30 30 38 30 30 30 0x0008000
dc60: 30 20 20 2f 2a 20 44 65 66 65 72 20 61 6c 6c 20 0 /* Defer all
dc70: 46 4b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a FK constraints *
dc80: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
dc90: 5f 51 75 65 72 79 4f 6e 6c 79 20 20 20 20 20 20 _QueryOnly
dca0: 30 78 30 30 31 30 30 30 30 30 20 20 2f 2a 20 44 0x00100000 /* D
dcb0: 69 73 61 62 6c 65 20 64 61 74 61 62 61 73 65 20 isable database
dcc0: 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 changes */.#defi
dcd0: 6e 65 20 53 51 4c 49 54 45 5f 43 65 6c 6c 53 69 ne SQLITE_CellSi
dce0: 7a 65 43 6b 20 20 20 20 20 30 78 30 30 32 30 30 zeCk 0x00200
dcf0: 30 30 30 20 20 2f 2a 20 43 68 65 63 6b 20 62 74 000 /* Check bt
dd00: 72 65 65 20 63 65 6c 6c 20 73 69 7a 65 73 20 6f ree cell sizes o
dd10: 6e 20 6c 6f 61 64 20 2a 2f 0a 23 64 65 66 69 6e n load */.#defin
dd20: 65 20 53 51 4c 49 54 45 5f 46 74 73 33 54 6f 6b e SQLITE_Fts3Tok
dd30: 65 6e 69 7a 65 72 20 20 30 78 30 30 34 30 30 30 enizer 0x004000
dd40: 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 66 74 00 /* Enable ft
dd50: 73 33 5f 74 6f 6b 65 6e 69 7a 65 72 28 32 29 20 s3_tokenizer(2)
dd60: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
dd70: 45 5f 45 6e 61 62 6c 65 51 50 53 47 20 20 20 20 E_EnableQPSG
dd80: 20 30 78 30 30 38 30 30 30 30 30 20 20 2f 2a 20 0x00800000 /*
dd90: 51 75 65 72 79 20 50 6c 61 6e 6e 65 72 20 53 74 Query Planner St
dda0: 61 62 69 6c 69 74 79 20 47 75 61 72 61 6e 74 65 ability Guarante
ddb0: 65 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 e*/.#define SQLI
ddc0: 54 45 5f 54 72 69 67 67 65 72 45 51 50 20 20 20 TE_TriggerEQP
ddd0: 20 20 30 78 30 31 30 30 30 30 30 30 20 20 2f 2a 0x01000000 /*
dde0: 20 53 68 6f 77 20 74 72 69 67 67 65 72 20 45 58 Show trigger EX
ddf0: 50 4c 41 49 4e 20 51 55 45 52 59 20 50 4c 41 4e PLAIN QUERY PLAN
de00: 20 2a 2f 0a 0a 2f 2a 20 46 6c 61 67 73 20 75 73 */../* Flags us
de10: 65 64 20 6f 6e 6c 79 20 69 66 20 64 65 62 75 67 ed only if debug
de20: 67 69 6e 67 20 2a 2f 0a 23 69 66 64 65 66 20 53 ging */.#ifdef S
de30: 51 4c 49 54 45 5f 44 45 42 55 47 0a 23 64 65 66 QLITE_DEBUG.#def
de40: 69 6e 65 20 53 51 4c 49 54 45 5f 53 71 6c 54 72 ine SQLITE_SqlTr
de50: 61 63 65 20 20 20 20 20 20 20 30 78 30 38 30 30 ace 0x0800
de60: 30 30 30 30 20 20 2f 2a 20 44 65 62 75 67 20 70 0000 /* Debug p
de70: 72 69 6e 74 20 53 51 4c 20 61 73 20 69 74 20 65 rint SQL as it e
de80: 78 65 63 75 74 65 73 20 2a 2f 0a 23 64 65 66 69 xecutes */.#defi
de90: 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 4c 69 ne SQLITE_VdbeLi
dea0: 73 74 69 6e 67 20 20 20 20 30 78 31 30 30 30 30 sting 0x10000
deb0: 30 30 30 20 20 2f 2a 20 44 65 62 75 67 20 6c 69 000 /* Debug li
dec0: 73 74 69 6e 67 73 20 6f 66 20 56 44 42 45 20 70 stings of VDBE p
ded0: 72 6f 67 72 61 6d 73 20 2a 2f 0a 23 64 65 66 69 rograms */.#defi
dee0: 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 54 72 ne SQLITE_VdbeTr
def0: 61 63 65 20 20 20 20 20 20 30 78 32 30 30 30 30 ace 0x20000
df00: 30 30 30 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 000 /* True to
df10: 74 72 61 63 65 20 56 44 42 45 20 65 78 65 63 75 trace VDBE execu
df20: 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
df30: 53 51 4c 49 54 45 5f 56 64 62 65 41 64 64 6f 70 SQLITE_VdbeAddop
df40: 54 72 61 63 65 20 30 78 34 30 30 30 30 30 30 30 Trace 0x40000000
df50: 20 20 2f 2a 20 54 72 61 63 65 20 73 71 6c 69 74 /* Trace sqlit
df60: 65 33 56 64 62 65 41 64 64 4f 70 28 29 20 63 61 e3VdbeAddOp() ca
df70: 6c 6c 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 lls */.#define S
df80: 51 4c 49 54 45 5f 56 64 62 65 45 51 50 20 20 20 QLITE_VdbeEQP
df90: 20 20 20 20 20 30 78 38 30 30 30 30 30 30 30 20 0x80000000
dfa0: 20 2f 2a 20 44 65 62 75 67 20 45 58 50 4c 41 49 /* Debug EXPLAI
dfb0: 4e 20 51 55 45 52 59 20 50 4c 41 4e 20 2a 2f 0a N QUERY PLAN */.
dfc0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6c #endif../*.** Al
dfd0: 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 lowed values for
dfe0: 20 73 71 6c 69 74 65 33 2e 6d 44 62 46 6c 61 67 sqlite3.mDbFlag
dff0: 73 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 46 s.*/.#define DBF
e000: 4c 41 47 5f 53 63 68 65 6d 61 43 68 61 6e 67 65 LAG_SchemaChange
e010: 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 55 6e 0x0001 /* Un
e020: 63 6f 6d 6d 69 74 74 65 64 20 48 61 73 68 20 74 committed Hash t
e030: 61 62 6c 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a able changes */.
e040: 23 64 65 66 69 6e 65 20 44 42 46 4c 41 47 5f 50 #define DBFLAG_P
e050: 72 65 66 65 72 42 75 69 6c 74 69 6e 20 20 30 78 referBuiltin 0x
e060: 30 30 30 32 20 20 2f 2a 20 50 72 65 66 65 72 65 0002 /* Prefere
e070: 6e 63 65 20 74 6f 20 62 75 69 6c 74 2d 69 6e 20 nce to built-in
e080: 66 75 6e 63 73 20 2a 2f 0a 23 64 65 66 69 6e 65 funcs */.#define
e090: 20 44 42 46 4c 41 47 5f 56 61 63 75 75 6d 20 20 DBFLAG_Vacuum
e0a0: 20 20 20 20 20 20 20 30 78 30 30 30 34 20 20 2f 0x0004 /
e0b0: 2a 20 43 75 72 72 65 6e 74 6c 79 20 69 6e 20 61 * Currently in a
e0c0: 20 56 41 43 55 55 4d 20 2a 2f 0a 0a 2f 2a 0a 2a VACUUM */../*.*
e0d0: 2a 20 42 69 74 73 20 6f 66 20 74 68 65 20 73 71 * Bits of the sq
e0e0: 6c 69 74 65 33 2e 64 62 4f 70 74 46 6c 61 67 73 lite3.dbOptFlags
e0f0: 20 66 69 65 6c 64 20 74 68 61 74 20 61 72 65 20 field that are
e100: 75 73 65 64 20 62 79 20 74 68 65 0a 2a 2a 20 73 used by the.** s
e110: 71 6c 69 74 65 33 5f 74 65 73 74 5f 63 6f 6e 74 qlite3_test_cont
e120: 72 6f 6c 28 53 51 4c 49 54 45 5f 54 45 53 54 43 rol(SQLITE_TESTC
e130: 54 52 4c 5f 4f 50 54 49 4d 49 5a 41 54 49 4f 4e TRL_OPTIMIZATION
e140: 53 2c 2e 2e 2e 29 20 69 6e 74 65 72 66 61 63 65 S,...) interface
e150: 20 74 6f 0a 2a 2a 20 73 65 6c 65 63 74 69 76 65 to.** selective
e160: 6c 79 20 64 69 73 61 62 6c 65 20 76 61 72 69 6f ly disable vario
e170: 75 73 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 us optimizations
e180: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
e190: 49 54 45 5f 51 75 65 72 79 46 6c 61 74 74 65 6e ITE_QueryFlatten
e1a0: 65 72 20 30 78 30 30 30 31 20 20 20 2f 2a 20 51 er 0x0001 /* Q
e1b0: 75 65 72 79 20 66 6c 61 74 74 65 6e 69 6e 67 20 uery flattening
e1c0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e1d0: 45 5f 43 6f 6c 75 6d 6e 43 61 63 68 65 20 20 20 E_ColumnCache
e1e0: 20 30 78 30 30 30 32 20 20 20 2f 2a 20 43 6f 6c 0x0002 /* Col
e1f0: 75 6d 6e 20 63 61 63 68 65 20 2a 2f 0a 23 64 65 umn cache */.#de
e200: 66 69 6e 65 20 53 51 4c 49 54 45 5f 47 72 6f 75 fine SQLITE_Grou
e210: 70 42 79 4f 72 64 65 72 20 20 20 30 78 30 30 30 pByOrder 0x000
e220: 34 20 20 20 2f 2a 20 47 52 4f 55 50 42 59 20 63 4 /* GROUPBY c
e230: 6f 76 65 72 20 6f 66 20 4f 52 44 45 52 42 59 20 over of ORDERBY
e240: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e250: 45 5f 46 61 63 74 6f 72 4f 75 74 43 6f 6e 73 74 E_FactorOutConst
e260: 20 30 78 30 30 30 38 20 20 20 2f 2a 20 43 6f 6e 0x0008 /* Con
e270: 73 74 61 6e 74 20 66 61 63 74 6f 72 69 6e 67 20 stant factoring
e280: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e290: 45 5f 44 69 73 74 69 6e 63 74 4f 70 74 20 20 20 E_DistinctOpt
e2a0: 20 30 78 30 30 31 30 20 20 20 2f 2a 20 44 49 53 0x0010 /* DIS
e2b0: 54 49 4e 43 54 20 75 73 69 6e 67 20 69 6e 64 65 TINCT using inde
e2c0: 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 xes */.#define S
e2d0: 51 4c 49 54 45 5f 43 6f 76 65 72 49 64 78 53 63 QLITE_CoverIdxSc
e2e0: 61 6e 20 20 20 30 78 30 30 32 30 20 20 20 2f 2a an 0x0020 /*
e2f0: 20 43 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 Covering index
e300: 73 63 61 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 scans */.#define
e310: 20 53 51 4c 49 54 45 5f 4f 72 64 65 72 42 79 49 SQLITE_OrderByI
e320: 64 78 4a 6f 69 6e 20 30 78 30 30 34 30 20 20 20 dxJoin 0x0040
e330: 2f 2a 20 4f 52 44 45 52 20 42 59 20 6f 66 20 6a /* ORDER BY of j
e340: 6f 69 6e 73 20 76 69 61 20 69 6e 64 65 78 20 2a oins via index *
e350: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e360: 5f 54 72 61 6e 73 69 74 69 76 65 20 20 20 20 20 _Transitive
e370: 30 78 30 30 38 30 20 20 20 2f 2a 20 54 72 61 6e 0x0080 /* Tran
e380: 73 69 74 69 76 65 20 63 6f 6e 73 74 72 61 69 6e sitive constrain
e390: 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ts */.#define SQ
e3a0: 4c 49 54 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f 69 LITE_OmitNoopJoi
e3b0: 6e 20 20 20 30 78 30 31 30 30 20 20 20 2f 2a 20 n 0x0100 /*
e3c0: 4f 6d 69 74 20 75 6e 75 73 65 64 20 74 61 62 6c Omit unused tabl
e3d0: 65 73 20 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a 23 es in joins */.#
e3e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f define SQLITE_Co
e3f0: 75 6e 74 4f 66 56 69 65 77 20 20 20 20 30 78 30 untOfView 0x0
e400: 32 30 30 20 20 20 2f 2a 20 54 68 65 20 63 6f 75 200 /* The cou
e410: 6e 74 2d 6f 66 2d 76 69 65 77 20 6f 70 74 69 6d nt-of-view optim
e420: 69 7a 61 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 ization */.#defi
e430: 6e 65 20 53 51 4c 49 54 45 5f 43 75 72 73 6f 72 ne SQLITE_Cursor
e440: 48 69 6e 74 73 20 20 20 20 30 78 30 34 30 30 20 Hints 0x0400
e450: 20 20 2f 2a 20 41 64 64 20 4f 50 5f 43 75 72 73 /* Add OP_Curs
e460: 6f 72 48 69 6e 74 20 6f 70 63 6f 64 65 73 20 2a orHint opcodes *
e470: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e480: 5f 53 74 61 74 33 34 20 20 20 20 20 20 20 20 20 _Stat34
e490: 30 78 30 38 30 30 20 20 20 2f 2a 20 55 73 65 20 0x0800 /* Use
e4a0: 53 54 41 54 33 20 6f 72 20 53 54 41 54 34 20 64 STAT3 or STAT4 d
e4b0: 61 74 61 20 2a 2f 0a 20 20 20 2f 2a 20 54 48 33 ata */. /* TH3
e4c0: 20 65 78 70 65 63 74 73 20 74 68 65 20 53 74 61 expects the Sta
e4d0: 74 33 34 20 20 5e 5e 5e 5e 5e 5e 20 76 61 6c 75 t34 ^^^^^^ valu
e4e0: 65 20 74 6f 20 62 65 20 30 78 30 38 30 30 2e 20 e to be 0x0800.
e4f0: 20 44 6f 6e 27 74 20 63 68 61 6e 67 65 20 69 74 Don't change it
e500: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
e510: 54 45 5f 50 75 73 68 44 6f 77 6e 20 20 20 20 20 TE_PushDown
e520: 20 20 30 78 31 30 30 30 20 20 20 2f 2a 20 54 68 0x1000 /* Th
e530: 65 20 70 75 73 68 2d 64 6f 77 6e 20 6f 70 74 69 e push-down opti
e540: 6d 69 7a 61 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 mization */.#def
e550: 69 6e 65 20 53 51 4c 49 54 45 5f 53 69 6d 70 6c ine SQLITE_Simpl
e560: 69 66 79 4a 6f 69 6e 20 20 20 30 78 32 30 30 30 ifyJoin 0x2000
e570: 20 20 20 2f 2a 20 43 6f 6e 76 65 72 74 20 4c 45 /* Convert LE
e580: 46 54 20 4a 4f 49 4e 20 74 6f 20 4a 4f 49 4e 20 FT JOIN to JOIN
e590: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e5a0: 45 5f 41 6c 6c 4f 70 74 73 20 20 20 20 20 20 20 E_AllOpts
e5b0: 20 30 78 66 66 66 66 20 20 20 2f 2a 20 41 6c 6c 0xffff /* All
e5c0: 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 2a optimizations *
e5d0: 2f 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 /../*.** Macros
e5e0: 66 6f 72 20 74 65 73 74 69 6e 67 20 77 68 65 74 for testing whet
e5f0: 68 65 72 20 6f 72 20 6e 6f 74 20 6f 70 74 69 6d her or not optim
e600: 69 7a 61 74 69 6f 6e 73 20 61 72 65 20 65 6e 61 izations are ena
e610: 62 6c 65 64 20 6f 72 20 64 69 73 61 62 6c 65 64 bled or disabled
e620: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 70 74 ..*/.#define Opt
e630: 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 62 6c 65 imizationDisable
e640: 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 28 28 28 d(db, mask) (((
e650: 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 67 73 26 db)->dbOptFlags&
e660: 28 6d 61 73 6b 29 29 21 3d 30 29 0a 23 64 65 66 (mask))!=0).#def
e670: 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e ine Optimization
e680: 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b Enabled(db, mask
e690: 29 20 20 20 28 28 28 64 62 29 2d 3e 64 62 4f 70 ) (((db)->dbOp
e6a0: 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 3d 3d tFlags&(mask))==
e6b0: 30 29 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 0)../*.** Return
e6c0: 20 74 72 75 65 20 69 66 20 69 74 20 4f 4b 20 74 true if it OK t
e6d0: 6f 20 66 61 63 74 6f 72 20 63 6f 6e 73 74 61 6e o factor constan
e6e0: 74 20 65 78 70 72 65 73 73 69 6f 6e 73 20 69 6e t expressions in
e6f0: 74 6f 20 74 68 65 20 69 6e 69 74 69 61 6c 69 7a to the initializ
e700: 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 65 2e 20 54 ation.** code. T
e710: 68 65 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61 he argument is a
e720: 20 50 61 72 73 65 20 6f 62 6a 65 63 74 20 66 6f Parse object fo
e730: 72 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 r the code gener
e740: 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ator..*/.#define
e750: 20 43 6f 6e 73 74 46 61 63 74 6f 72 4f 6b 28 50 ConstFactorOk(P
e760: 29 20 28 28 50 29 2d 3e 6f 6b 43 6f 6e 73 74 46 ) ((P)->okConstF
e770: 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f actor)../*.** Po
e780: 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f ssible values fo
e790: 72 20 74 68 65 20 73 71 6c 69 74 65 2e 6d 61 67 r the sqlite.mag
e7a0: 69 63 20 66 69 65 6c 64 2e 0a 2a 2a 20 54 68 65 ic field..** The
e7b0: 20 6e 75 6d 62 65 72 73 20 61 72 65 20 6f 62 74 numbers are obt
e7c0: 61 69 6e 65 64 20 61 74 20 72 61 6e 64 6f 6d 20 ained at random
e7d0: 61 6e 64 20 68 61 76 65 20 6e 6f 20 73 70 65 63 and have no spec
e7e0: 69 61 6c 20 6d 65 61 6e 69 6e 67 2c 20 6f 74 68 ial meaning, oth
e7f0: 65 72 0a 2a 2a 20 74 68 61 6e 20 62 65 69 6e 67 er.** than being
e800: 20 64 69 73 74 69 6e 63 74 20 66 72 6f 6d 20 6f distinct from o
e810: 6e 65 20 61 6e 6f 74 68 65 72 2e 0a 2a 2f 0a 23 ne another..*/.#
e820: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
e830: 47 49 43 5f 4f 50 45 4e 20 20 20 20 20 30 78 61 GIC_OPEN 0xa
e840: 30 32 39 61 36 39 37 20 20 2f 2a 20 44 61 74 61 029a697 /* Data
e850: 62 61 73 65 20 69 73 20 6f 70 65 6e 20 2a 2f 0a base is open */.
e860: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
e870: 41 47 49 43 5f 43 4c 4f 53 45 44 20 20 20 30 78 AGIC_CLOSED 0x
e880: 39 66 33 63 32 64 33 33 20 20 2f 2a 20 44 61 74 9f3c2d33 /* Dat
e890: 61 62 61 73 65 20 69 73 20 63 6c 6f 73 65 64 20 abase is closed
e8a0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e8b0: 45 5f 4d 41 47 49 43 5f 53 49 43 4b 20 20 20 20 E_MAGIC_SICK
e8c0: 20 30 78 34 62 37 37 31 32 39 30 20 20 2f 2a 20 0x4b771290 /*
e8d0: 45 72 72 6f 72 20 61 6e 64 20 61 77 61 69 74 69 Error and awaiti
e8e0: 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a 23 64 65 66 ng close */.#def
e8f0: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
e900: 5f 42 55 53 59 20 20 20 20 20 30 78 66 30 33 62 _BUSY 0xf03b
e910: 37 39 30 36 20 20 2f 2a 20 44 61 74 61 62 61 73 7906 /* Databas
e920: 65 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 e currently in u
e930: 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 se */.#define SQ
e940: 4c 49 54 45 5f 4d 41 47 49 43 5f 45 52 52 4f 52 LITE_MAGIC_ERROR
e950: 20 20 20 20 30 78 62 35 33 35 37 39 33 30 20 20 0xb5357930
e960: 2f 2a 20 41 6e 20 53 51 4c 49 54 45 5f 4d 49 53 /* An SQLITE_MIS
e970: 55 53 45 20 65 72 72 6f 72 20 6f 63 63 75 72 72 USE error occurr
e980: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ed */.#define SQ
e990: 4c 49 54 45 5f 4d 41 47 49 43 5f 5a 4f 4d 42 49 LITE_MAGIC_ZOMBI
e9a0: 45 20 20 20 30 78 36 34 63 66 66 63 37 66 20 20 E 0x64cffc7f
e9b0: 2f 2a 20 43 6c 6f 73 65 20 77 69 74 68 20 6c 61 /* Close with la
e9c0: 73 74 20 73 74 61 74 65 6d 65 6e 74 20 63 6c 6f st statement clo
e9d0: 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 se */../*.** Eac
e9e0: 68 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 h SQL function i
e9f0: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 20 s defined by an
ea00: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
ea10: 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 following.** str
ea20: 75 63 74 75 72 65 2e 20 20 46 6f 72 20 67 6c 6f ucture. For glo
ea30: 62 61 6c 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e bal built-in fun
ea40: 63 74 69 6f 6e 73 20 28 65 78 3a 20 73 75 62 73 ctions (ex: subs
ea50: 74 72 28 29 2c 20 6d 61 78 28 29 2c 20 63 6f 75 tr(), max(), cou
ea60: 6e 74 28 29 29 0a 2a 2a 20 61 20 70 6f 69 6e 74 nt()).** a point
ea70: 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 er to this struc
ea80: 74 75 72 65 20 69 73 20 68 65 6c 64 20 69 6e 20 ture is held in
ea90: 74 68 65 20 73 71 6c 69 74 65 33 42 75 69 6c 74 the sqlite3Built
eaa0: 69 6e 46 75 6e 63 74 69 6f 6e 73 20 6f 62 6a 65 inFunctions obje
eab0: 63 74 2e 0a 2a 2a 20 46 6f 72 20 70 65 72 2d 63 ct..** For per-c
eac0: 6f 6e 6e 65 63 74 69 6f 6e 20 61 70 70 6c 69 63 onnection applic
ead0: 61 74 69 6f 6e 2d 64 65 66 69 6e 65 64 20 66 75 ation-defined fu
eae0: 6e 63 74 69 6f 6e 73 2c 20 61 20 70 6f 69 6e 74 nctions, a point
eaf0: 65 72 20 74 6f 20 74 68 69 73 0a 2a 2a 20 73 74 er to this.** st
eb00: 72 75 63 74 75 72 65 20 69 73 20 68 65 6c 64 20 ructure is held
eb10: 69 6e 20 74 68 65 20 64 62 2d 3e 61 48 61 73 68 in the db->aHash
eb20: 20 68 61 73 68 20 74 61 62 6c 65 2e 0a 2a 2a 0a hash table..**.
eb30: 2a 2a 20 54 68 65 20 75 2e 70 48 61 73 68 20 66 ** The u.pHash f
eb40: 69 65 6c 64 20 69 73 20 75 73 65 64 20 62 79 20 ield is used by
eb50: 74 68 65 20 67 6c 6f 62 61 6c 20 62 75 69 6c 74 the global built
eb60: 2d 69 6e 73 2e 20 20 54 68 65 20 75 2e 70 44 65 -ins. The u.pDe
eb70: 73 74 72 75 63 74 6f 72 0a 2a 2a 20 66 69 65 6c structor.** fiel
eb80: 64 20 69 73 20 75 73 65 64 20 62 79 20 70 65 72 d is used by per
eb90: 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 70 70 2d -connection app-
eba0: 64 65 66 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a def functions..*
ebb0: 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 65 66 /.struct FuncDef
ebc0: 20 7b 0a 20 20 69 38 20 6e 41 72 67 3b 20 20 20 {. i8 nArg;
ebd0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
ebe0: 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
ebf0: 2e 20 20 2d 31 20 6d 65 61 6e 73 20 75 6e 6c 69 . -1 means unli
ec00: 6d 69 74 65 64 20 2a 2f 0a 20 20 75 31 36 20 66 mited */. u16 f
ec10: 75 6e 63 46 6c 61 67 73 3b 20 20 20 20 20 20 20 uncFlags;
ec20: 2f 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 6e 61 74 /* Some combinat
ec30: 69 6f 6e 20 6f 66 20 53 51 4c 49 54 45 5f 46 55 ion of SQLITE_FU
ec40: 4e 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 64 20 2a NC_* */. void *
ec50: 70 55 73 65 72 44 61 74 61 3b 20 20 20 20 20 2f pUserData; /
ec60: 2a 20 55 73 65 72 20 64 61 74 61 20 70 61 72 61 * User data para
ec70: 6d 65 74 65 72 20 2a 2f 0a 20 20 46 75 6e 63 44 meter */. FuncD
ec80: 65 66 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 ef *pNext;
ec90: 2f 2a 20 4e 65 78 74 20 66 75 6e 63 74 69 6f 6e /* Next function
eca0: 20 77 69 74 68 20 73 61 6d 65 20 6e 61 6d 65 20 with same name
ecb0: 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 53 46 75 */. void (*xSFu
ecc0: 6e 63 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 nc)(sqlite3_cont
ecd0: 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 ext*,int,sqlite3
ece0: 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 66 75 _value**); /* fu
ecf0: 6e 63 20 6f 72 20 61 67 67 2d 73 74 65 70 20 2a nc or agg-step *
ed00: 2f 0a 20 20 76 6f 69 64 20 28 2a 78 46 69 6e 61 /. void (*xFina
ed10: 6c 69 7a 65 29 28 73 71 6c 69 74 65 33 5f 63 6f lize)(sqlite3_co
ed20: 6e 74 65 78 74 2a 29 3b 20 20 20 20 20 20 20 20 ntext*);
ed30: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 67 67 /* Agg
ed40: 20 66 69 6e 61 6c 69 7a 65 72 20 2a 2f 0a 20 20 finalizer */.
ed50: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d const char *zNam
ed60: 65 3b 20 20 20 2f 2a 20 53 51 4c 20 6e 61 6d 65 e; /* SQL name
ed70: 20 6f 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e of the function
ed80: 2e 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 . */. union {.
ed90: 20 20 20 46 75 6e 63 44 65 66 20 2a 70 48 61 73 FuncDef *pHas
eda0: 68 3b 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 h; /* Next
edb0: 77 69 74 68 20 61 20 64 69 66 66 65 72 65 6e 74 with a different
edc0: 20 6e 61 6d 65 20 62 75 74 20 74 68 65 20 73 61 name but the sa
edd0: 6d 65 20 68 61 73 68 20 2a 2f 0a 20 20 20 20 46 me hash */. F
ede0: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 2a 70 uncDestructor *p
edf0: 44 65 73 74 72 75 63 74 6f 72 3b 20 20 20 2f 2a Destructor; /*
ee00: 20 52 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 Reference count
ee10: 65 64 20 64 65 73 74 72 75 63 74 6f 72 20 66 75 ed destructor fu
ee20: 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 7d 20 75 3b nction */. } u;
ee30: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 .};../*.** This
ee40: 73 74 72 75 63 74 75 72 65 20 65 6e 63 61 70 73 structure encaps
ee50: 75 6c 61 74 65 73 20 61 20 75 73 65 72 2d 66 75 ulates a user-fu
ee60: 6e 63 74 69 6f 6e 20 64 65 73 74 72 75 63 74 6f nction destructo
ee70: 72 20 63 61 6c 6c 62 61 63 6b 20 28 61 73 0a 2a r callback (as.*
ee80: 2a 20 63 6f 6e 66 69 67 75 72 65 64 20 75 73 69 * configured usi
ee90: 6e 67 20 63 72 65 61 74 65 5f 66 75 6e 63 74 69 ng create_functi
eea0: 6f 6e 5f 76 32 28 29 29 20 61 6e 64 20 61 20 72 on_v2()) and a r
eeb0: 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 65 72 eference counter
eec0: 2e 20 57 68 65 6e 0a 2a 2a 20 63 72 65 61 74 65 . When.** create
eed0: 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 29 20 69 _function_v2() i
eee0: 73 20 63 61 6c 6c 65 64 20 74 6f 20 63 72 65 61 s called to crea
eef0: 74 65 20 61 20 66 75 6e 63 74 69 6f 6e 20 77 69 te a function wi
ef00: 74 68 20 61 20 64 65 73 74 72 75 63 74 6f 72 2c th a destructor,
ef10: 0a 2a 2a 20 61 20 73 69 6e 67 6c 65 20 6f 62 6a .** a single obj
ef20: 65 63 74 20 6f 66 20 74 68 69 73 20 74 79 70 65 ect of this type
ef30: 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 2e 20 46 is allocated. F
ef40: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 2e 6e 52 uncDestructor.nR
ef50: 65 66 20 69 73 20 73 65 74 20 74 6f 0a 2a 2a 20 ef is set to.**
ef60: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 46 75 the number of Fu
ef70: 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 20 63 72 ncDef objects cr
ef80: 65 61 74 65 64 20 28 65 69 74 68 65 72 20 31 20 eated (either 1
ef90: 6f 72 20 33 2c 20 64 65 70 65 6e 64 69 6e 67 20 or 3, depending
efa0: 6f 6e 20 77 68 65 74 68 65 72 0a 2a 2a 20 6f 72 on whether.** or
efb0: 20 6e 6f 74 20 74 68 65 20 73 70 65 63 69 66 69 not the specifi
efc0: 65 64 20 65 6e 63 6f 64 69 6e 67 20 69 73 20 53 ed encoding is S
efd0: 51 4c 49 54 45 5f 41 4e 59 29 2e 20 54 68 65 20 QLITE_ANY). The
efe0: 46 75 6e 63 44 65 66 2e 70 44 65 73 74 72 75 63 FuncDef.pDestruc
eff0: 74 6f 72 0a 2a 2a 20 6d 65 6d 62 65 72 20 6f 66 tor.** member of
f000: 20 65 61 63 68 20 6f 66 20 74 68 65 20 6e 65 77 each of the new
f010: 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 FuncDef objects
f020: 20 69 73 20 73 65 74 20 74 6f 20 70 6f 69 6e 74 is set to point
f030: 20 74 6f 20 74 68 65 20 61 6c 6c 6f 63 61 74 65 to the allocate
f040: 64 0a 2a 2a 20 46 75 6e 63 44 65 73 74 72 75 63 d.** FuncDestruc
f050: 74 6f 72 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 72 65 tor..**.** There
f060: 61 66 74 65 72 2c 20 77 68 65 6e 20 6f 6e 65 20 after, when one
f070: 6f 66 20 74 68 65 20 46 75 6e 63 44 65 66 20 6f of the FuncDef o
f080: 62 6a 65 63 74 73 20 69 73 20 64 65 6c 65 74 65 bjects is delete
f090: 64 2c 20 74 68 65 20 72 65 66 65 72 65 6e 63 65 d, the reference
f0a0: 0a 2a 2a 20 63 6f 75 6e 74 20 6f 6e 20 74 68 69 .** count on thi
f0b0: 73 20 6f 62 6a 65 63 74 20 69 73 20 64 65 63 72 s object is decr
f0c0: 65 6d 65 6e 74 65 64 2e 20 57 68 65 6e 20 69 74 emented. When it
f0d0: 20 72 65 61 63 68 65 73 20 30 2c 20 74 68 65 20 reaches 0, the
f0e0: 64 65 73 74 72 75 63 74 6f 72 0a 2a 2a 20 69 73 destructor.** is
f0f0: 20 69 6e 76 6f 6b 65 64 20 61 6e 64 20 74 68 65 invoked and the
f100: 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 FuncDestructor
f110: 73 74 72 75 63 74 75 72 65 20 66 72 65 65 64 2e structure freed.
f120: 0a 2a 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 44 .*/.struct FuncD
f130: 65 73 74 72 75 63 74 6f 72 20 7b 0a 20 20 69 6e estructor {. in
f140: 74 20 6e 52 65 66 3b 0a 20 20 76 6f 69 64 20 28 t nRef;. void (
f150: 2a 78 44 65 73 74 72 6f 79 29 28 76 6f 69 64 20 *xDestroy)(void
f160: 2a 29 3b 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 *);. void *pUse
f170: 72 44 61 74 61 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a rData;.};../*.**
f180: 20 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 Possible values
f190: 20 66 6f 72 20 46 75 6e 63 44 65 66 2e 66 6c 61 for FuncDef.fla
f1a0: 67 73 2e 20 20 4e 6f 74 65 20 74 68 61 74 20 74 gs. Note that t
f1b0: 68 65 20 5f 4c 45 4e 47 54 48 20 61 6e 64 20 5f he _LENGTH and _
f1c0: 54 59 50 45 4f 46 0a 2a 2a 20 76 61 6c 75 65 73 TYPEOF.** values
f1d0: 20 6d 75 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 must correspond
f1e0: 20 74 6f 20 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 to OPFLAG_LENGT
f1f0: 48 41 52 47 20 61 6e 64 20 4f 50 46 4c 41 47 5f HARG and OPFLAG_
f200: 54 59 50 45 4f 46 41 52 47 2e 20 20 41 6e 64 0a TYPEOFARG. And.
f210: 2a 2a 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 ** SQLITE_FUNC_C
f220: 4f 4e 53 54 41 4e 54 20 6d 75 73 74 20 62 65 20 ONSTANT must be
f230: 74 68 65 20 73 61 6d 65 20 61 73 20 53 51 4c 49 the same as SQLI
f240: 54 45 5f 44 45 54 45 52 4d 49 4e 49 53 54 49 43 TE_DETERMINISTIC
f250: 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 . There.** are
f260: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
f270: 6e 74 73 20 69 6e 20 74 68 65 20 63 6f 64 65 20 nts in the code
f280: 74 6f 20 76 65 72 69 66 79 20 74 68 69 73 2e 0a to verify this..
f290: 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e 73 **.** Value cons
f2a0: 74 72 61 69 6e 74 73 20 28 65 6e 66 6f 72 63 65 traints (enforce
f2b0: 64 20 76 69 61 20 61 73 73 65 72 74 28 29 29 3a d via assert()):
f2c0: 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 46 .** SQLITE_F
f2d0: 55 4e 43 5f 4d 49 4e 4d 41 58 20 20 20 20 3d 3d UNC_MINMAX ==
f2e0: 20 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 20 NC_MinMaxAgg
f2f0: 20 20 20 20 3d 3d 20 53 46 5f 4d 69 6e 4d 61 78 == SF_MinMax
f300: 41 67 67 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 Agg.** SQLIT
f310: 45 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 20 20 20 E_FUNC_LENGTH
f320: 20 3d 3d 20 20 4f 50 46 4c 41 47 5f 4c 45 4e 47 == OPFLAG_LENG
f330: 54 48 41 52 47 0a 2a 2a 20 20 20 20 20 53 51 4c THARG.** SQL
f340: 49 54 45 5f 46 55 4e 43 5f 54 59 50 45 4f 46 20 ITE_FUNC_TYPEOF
f350: 20 20 20 3d 3d 20 20 4f 50 46 4c 41 47 5f 54 59 == OPFLAG_TY
f360: 50 45 4f 46 41 52 47 0a 2a 2a 20 20 20 20 20 53 PEOFARG.** S
f370: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 QLITE_FUNC_CONST
f380: 41 4e 54 20 20 3d 3d 20 20 53 51 4c 49 54 45 5f ANT == SQLITE_
f390: 44 45 54 45 52 4d 49 4e 49 53 54 49 43 20 66 72 DETERMINISTIC fr
f3a0: 6f 6d 20 74 68 65 20 41 50 49 0a 2a 2a 20 20 20 om the API.**
f3b0: 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 4e SQLITE_FUNC_EN
f3c0: 43 4d 41 53 4b 20 20 20 64 65 70 65 6e 64 73 20 CMASK depends
f3d0: 6f 6e 20 53 51 4c 49 54 45 5f 55 54 46 2a 20 6d on SQLITE_UTF* m
f3e0: 61 63 72 6f 73 20 69 6e 20 74 68 65 20 41 50 49 acros in the API
f3f0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
f400: 54 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 53 4b 20 TE_FUNC_ENCMASK
f410: 20 30 78 30 30 30 33 20 2f 2a 20 53 51 4c 49 54 0x0003 /* SQLIT
f420: 45 5f 55 54 46 38 2c 20 53 51 4c 49 54 45 5f 55 E_UTF8, SQLITE_U
f430: 54 46 31 36 42 45 20 6f 72 20 55 54 46 31 36 4c TF16BE or UTF16L
f440: 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c E */.#define SQL
f450: 49 54 45 5f 46 55 4e 43 5f 4c 49 4b 45 20 20 20 ITE_FUNC_LIKE
f460: 20 20 30 78 30 30 30 34 20 2f 2a 20 43 61 6e 64 0x0004 /* Cand
f470: 69 64 61 74 65 20 66 6f 72 20 74 68 65 20 4c 49 idate for the LI
f480: 4b 45 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 KE optimization
f490: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
f4a0: 45 5f 46 55 4e 43 5f 43 41 53 45 20 20 20 20 20 E_FUNC_CASE
f4b0: 30 78 30 30 30 38 20 2f 2a 20 43 61 73 65 2d 73 0x0008 /* Case-s
f4c0: 65 6e 73 69 74 69 76 65 20 4c 49 4b 45 2d 74 79 ensitive LIKE-ty
f4d0: 70 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 pe function */.#
f4e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
f4f0: 4e 43 5f 45 50 48 45 4d 20 20 20 20 30 78 30 30 NC_EPHEM 0x00
f500: 31 30 20 2f 2a 20 45 70 68 65 6d 65 72 61 6c 2e 10 /* Ephemeral.
f510: 20 20 44 65 6c 65 74 65 20 77 69 74 68 20 56 44 Delete with VD
f520: 42 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 BE */.#define SQ
f530: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
f540: 4c 4c 20 30 78 30 30 32 30 20 2f 2a 20 73 71 6c LL 0x0020 /* sql
f550: 69 74 65 33 47 65 74 46 75 6e 63 43 6f 6c 6c 53 ite3GetFuncCollS
f560: 65 71 28 29 20 6d 69 67 68 74 20 62 65 20 63 61 eq() might be ca
f570: 6c 6c 65 64 2a 2f 0a 23 64 65 66 69 6e 65 20 53 lled*/.#define S
f580: 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 4e 47 54 QLITE_FUNC_LENGT
f590: 48 20 20 20 30 78 30 30 34 30 20 2f 2a 20 42 75 H 0x0040 /* Bu
f5a0: 69 6c 74 2d 69 6e 20 6c 65 6e 67 74 68 28 29 20 ilt-in length()
f5b0: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 function */.#def
f5c0: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
f5d0: 54 59 50 45 4f 46 20 20 20 30 78 30 30 38 30 20 TYPEOF 0x0080
f5e0: 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 74 79 70 65 /* Built-in type
f5f0: 6f 66 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f of() function */
f600: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
f610: 46 55 4e 43 5f 43 4f 55 4e 54 20 20 20 20 30 78 FUNC_COUNT 0x
f620: 30 31 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 0100 /* Built-in
f630: 20 63 6f 75 6e 74 28 2a 29 20 61 67 67 72 65 67 count(*) aggreg
f640: 61 74 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ate */.#define S
f650: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 41 4c 45 QLITE_FUNC_COALE
f660: 53 43 45 20 30 78 30 32 30 30 20 2f 2a 20 42 75 SCE 0x0200 /* Bu
f670: 69 6c 74 2d 69 6e 20 63 6f 61 6c 65 73 63 65 28 ilt-in coalesce(
f680: 29 20 6f 72 20 69 66 6e 75 6c 6c 28 29 20 2a 2f ) or ifnull() */
f690: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
f6a0: 46 55 4e 43 5f 55 4e 4c 49 4b 45 4c 59 20 30 78 FUNC_UNLIKELY 0x
f6b0: 30 34 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 0400 /* Built-in
f6c0: 20 75 6e 6c 69 6b 65 6c 79 28 29 20 66 75 6e 63 unlikely() func
f6d0: 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
f6e0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 SQLITE_FUNC_CONS
f6f0: 54 41 4e 54 20 30 78 30 38 30 30 20 2f 2a 20 43 TANT 0x0800 /* C
f700: 6f 6e 73 74 61 6e 74 20 69 6e 70 75 74 73 20 67 onstant inputs g
f710: 69 76 65 20 61 20 63 6f 6e 73 74 61 6e 74 20 6f ive a constant o
f720: 75 74 70 75 74 20 2a 2f 0a 23 64 65 66 69 6e 65 utput */.#define
f730: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 4e SQLITE_FUNC_MIN
f740: 4d 41 58 20 20 20 30 78 31 30 30 30 20 2f 2a 20 MAX 0x1000 /*
f750: 54 72 75 65 20 66 6f 72 20 6d 69 6e 28 29 20 61 True for min() a
f760: 6e 64 20 6d 61 78 28 29 20 61 67 67 72 65 67 61 nd max() aggrega
f770: 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 tes */.#define S
f780: 51 4c 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 48 QLITE_FUNC_SLOCH
f790: 4e 47 20 20 30 78 32 30 30 30 20 2f 2a 20 22 53 NG 0x2000 /* "S
f7a0: 6c 6f 77 20 43 68 61 6e 67 65 22 2e 20 56 61 6c low Change". Val
f7b0: 75 65 20 63 6f 6e 73 74 61 6e 74 20 64 75 72 69 ue constant duri
f7c0: 6e 67 20 61 0a 20 20 20 20 20 20 20 20 20 20 20 ng a.
f7d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f7e0: 20 20 20 20 20 20 20 20 20 2a 2a 20 73 69 6e 67 ** sing
f7f0: 6c 65 20 71 75 65 72 79 20 2d 20 6d 69 67 68 74 le query - might
f800: 20 63 68 61 6e 67 65 20 6f 76 65 72 20 74 69 6d change over tim
f810: 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c e */.#define SQL
f820: 49 54 45 5f 46 55 4e 43 5f 41 46 46 49 4e 49 54 ITE_FUNC_AFFINIT
f830: 59 20 30 78 34 30 30 30 20 2f 2a 20 42 75 69 6c Y 0x4000 /* Buil
f840: 74 2d 69 6e 20 61 66 66 69 6e 69 74 79 28 29 20 t-in affinity()
f850: 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 function */.#def
f860: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
f870: 4f 46 46 53 45 54 20 20 20 30 78 38 30 30 30 20 OFFSET 0x8000
f880: 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 73 71 6c 69 /* Built-in sqli
f890: 74 65 5f 6f 66 66 73 65 74 28 29 20 66 75 6e 63 te_offset() func
f8a0: 74 69 6f 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 tion */../*.** T
f8b0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 72 he following thr
f8c0: 65 65 20 6d 61 63 72 6f 73 2c 20 46 55 4e 43 54 ee macros, FUNCT
f8d0: 49 4f 4e 28 29 2c 20 4c 49 4b 45 46 55 4e 43 28 ION(), LIKEFUNC(
f8e0: 29 20 61 6e 64 20 41 47 47 52 45 47 41 54 45 28 ) and AGGREGATE(
f8f0: 29 20 61 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f ) are.** used to
f900: 20 63 72 65 61 74 65 20 74 68 65 20 69 6e 69 74 create the init
f910: 69 61 6c 69 7a 65 72 73 20 66 6f 72 20 74 68 65 ializers for the
f920: 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 74 75 FuncDef structu
f930: 72 65 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 46 55 4e res..**.** FUN
f940: 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 CTION(zName, nAr
f950: 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 g, iArg, bNC, xF
f960: 75 6e 63 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 unc).** Used
f970: 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 61 to create a sca
f980: 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 lar function def
f990: 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e inition of a fun
f9a0: 63 74 69 6f 6e 20 7a 4e 61 6d 65 0a 2a 2a 20 20 ction zName.**
f9b0: 20 20 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 implemented b
f9c0: 79 20 43 20 66 75 6e 63 74 69 6f 6e 20 78 46 75 y C function xFu
f9d0: 6e 63 20 74 68 61 74 20 61 63 63 65 70 74 73 20 nc that accepts
f9e0: 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 2e 20 nArg arguments.
f9f0: 54 68 65 0a 2a 2a 20 20 20 20 20 76 61 6c 75 65 The.** value
fa00: 20 70 61 73 73 65 64 20 61 73 20 69 41 72 67 20 passed as iArg
fa10: 69 73 20 63 61 73 74 20 74 6f 20 61 20 28 76 6f is cast to a (vo
fa20: 69 64 2a 29 20 61 6e 64 20 6d 61 64 65 20 61 76 id*) and made av
fa30: 61 69 6c 61 62 6c 65 0a 2a 2a 20 20 20 20 20 61 ailable.** a
fa40: 73 20 74 68 65 20 75 73 65 72 2d 64 61 74 61 20 s the user-data
fa50: 28 73 71 6c 69 74 65 33 5f 75 73 65 72 5f 64 61 (sqlite3_user_da
fa60: 74 61 28 29 29 20 66 6f 72 20 74 68 65 20 66 75 ta()) for the fu
fa70: 6e 63 74 69 6f 6e 2e 20 49 66 0a 2a 2a 20 20 20 nction. If.**
fa80: 20 20 61 72 67 75 6d 65 6e 74 20 62 4e 43 20 69 argument bNC i
fa90: 73 20 74 72 75 65 2c 20 74 68 65 6e 20 74 68 65 s true, then the
faa0: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 SQLITE_FUNC_NEE
fab0: 44 43 4f 4c 4c 20 66 6c 61 67 20 69 73 20 73 65 DCOLL flag is se
fac0: 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 56 46 55 4e 43 t..**.** VFUNC
fad0: 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 TION(zName, nArg
fae0: 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 , iArg, bNC, xFu
faf0: 6e 63 29 0a 2a 2a 20 20 20 20 20 4c 69 6b 65 20 nc).** Like
fb00: 46 55 4e 43 54 49 4f 4e 20 65 78 63 65 70 74 20 FUNCTION except
fb10: 69 74 20 6f 6d 69 74 73 20 74 68 65 20 53 51 4c it omits the SQL
fb20: 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e ITE_FUNC_CONSTAN
fb30: 54 20 66 6c 61 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 T flag..**.**
fb40: 44 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c DFUNCTION(zName,
fb50: 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 nArg, iArg, bNC
fb60: 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 , xFunc).**
fb70: 4c 69 6b 65 20 46 55 4e 43 54 49 4f 4e 20 65 78 Like FUNCTION ex
fb80: 63 65 70 74 20 69 74 20 6f 6d 69 74 73 20 74 68 cept it omits th
fb90: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
fba0: 4e 53 54 41 4e 54 20 66 6c 61 67 20 61 6e 64 0a NSTANT flag and.
fbb0: 2a 2a 20 20 20 20 20 61 64 64 73 20 74 68 65 20 ** adds the
fbc0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 SQLITE_FUNC_SLOC
fbd0: 48 4e 47 20 66 6c 61 67 2e 20 20 55 73 65 64 20 HNG flag. Used
fbe0: 66 6f 72 20 64 61 74 65 20 26 20 74 69 6d 65 20 for date & time
fbf0: 66 75 6e 63 74 69 6f 6e 73 0a 2a 2a 20 20 20 20 functions.**
fc00: 20 61 6e 64 20 66 75 6e 63 74 69 6f 6e 73 20 6c and functions l
fc10: 69 6b 65 20 73 71 6c 69 74 65 5f 76 65 72 73 69 ike sqlite_versi
fc20: 6f 6e 28 29 20 74 68 61 74 20 63 61 6e 20 63 68 on() that can ch
fc30: 61 6e 67 65 2c 20 62 75 74 20 6e 6f 74 20 64 75 ange, but not du
fc40: 72 69 6e 67 0a 2a 2a 20 20 20 20 20 61 20 73 69 ring.** a si
fc50: 6e 67 6c 65 20 71 75 65 72 79 2e 20 20 54 68 65 ngle query. The
fc60: 20 69 41 72 67 20 69 73 20 69 67 6e 6f 72 65 64 iArg is ignored
fc70: 2e 20 20 54 68 65 20 75 73 65 72 2d 64 61 74 61 . The user-data
fc80: 20 69 73 20 61 6c 77 61 79 73 20 73 65 74 0a 2a is always set.*
fc90: 2a 20 20 20 20 20 74 6f 20 61 20 4e 55 4c 4c 20 * to a NULL
fca0: 70 6f 69 6e 74 65 72 2e 20 20 54 68 65 20 62 4e pointer. The bN
fcb0: 43 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 6e C parameter is n
fcc0: 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 20 ot used..**.**
fcd0: 20 50 55 52 45 5f 44 41 54 45 28 7a 4e 61 6d 65 PURE_DATE(zName
fce0: 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e , nArg, iArg, bN
fcf0: 43 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 C, xFunc).**
fd00: 20 55 73 65 64 20 66 6f 72 20 22 70 75 72 65 22 Used for "pure"
fd10: 20 64 61 74 65 2f 74 69 6d 65 20 66 75 6e 63 74 date/time funct
fd20: 69 6f 6e 73 2c 20 74 68 69 73 20 6d 61 63 72 6f ions, this macro
fd30: 20 69 73 20 6c 69 6b 65 20 44 46 55 4e 43 54 49 is like DFUNCTI
fd40: 4f 4e 0a 2a 2a 20 20 20 20 20 65 78 63 65 70 74 ON.** except
fd50: 20 74 68 61 74 20 69 74 20 64 6f 65 73 20 73 65 that it does se
fd60: 74 20 74 68 65 20 53 51 4c 49 54 45 5f 46 55 4e t the SQLITE_FUN
fd70: 43 5f 43 4f 4e 53 54 41 4e 54 20 66 6c 61 67 73 C_CONSTANT flags
fd80: 2e 20 20 69 41 72 67 20 69 73 0a 2a 2a 20 20 20 . iArg is.**
fd90: 20 20 69 67 6e 6f 72 65 64 20 61 6e 64 20 74 68 ignored and th
fda0: 65 20 75 73 65 72 2d 64 61 74 61 20 66 6f 72 20 e user-data for
fdb0: 74 68 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 these functions
fdc0: 69 73 20 73 65 74 20 74 6f 20 61 6e 20 0a 2a 2a is set to an .**
fdd0: 20 20 20 20 20 61 72 62 69 74 72 61 72 79 20 6e arbitrary n
fde0: 6f 6e 2d 4e 55 4c 4c 20 70 6f 69 6e 74 65 72 2e on-NULL pointer.
fdf0: 20 20 54 68 65 20 62 4e 43 20 70 61 72 61 6d 65 The bNC parame
fe00: 74 65 72 20 69 73 20 6e 6f 74 20 75 73 65 64 2e ter is not used.
fe10: 0a 2a 2a 0a 2a 2a 20 20 20 41 47 47 52 45 47 41 .**.** AGGREGA
fe20: 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 TE(zName, nArg,
fe30: 69 41 72 67 2c 20 62 4e 43 2c 20 78 53 74 65 70 iArg, bNC, xStep
fe40: 2c 20 78 46 69 6e 61 6c 29 0a 2a 2a 20 20 20 20 , xFinal).**
fe50: 20 55 73 65 64 20 74 6f 20 63 72 65 61 74 65 20 Used to create
fe60: 61 6e 20 61 67 67 72 65 67 61 74 65 20 66 75 6e an aggregate fun
fe70: 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e ction definition
fe80: 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 0a implemented by.
fe90: 2a 2a 20 20 20 20 20 74 68 65 20 43 20 66 75 6e ** the C fun
fea0: 63 74 69 6f 6e 73 20 78 53 74 65 70 20 61 6e 64 ctions xStep and
feb0: 20 78 46 69 6e 61 6c 2e 20 54 68 65 20 66 69 72 xFinal. The fir
fec0: 73 74 20 66 6f 75 72 20 70 61 72 61 6d 65 74 65 st four paramete
fed0: 72 73 0a 2a 2a 20 20 20 20 20 61 72 65 20 69 6e rs.** are in
fee0: 74 65 72 70 72 65 74 65 64 20 69 6e 20 74 68 65 terpreted in the
fef0: 20 73 61 6d 65 20 77 61 79 20 61 73 20 74 68 65 same way as the
ff00: 20 66 69 72 73 74 20 34 20 70 61 72 61 6d 65 74 first 4 paramet
ff10: 65 72 73 20 74 6f 0a 2a 2a 20 20 20 20 20 46 55 ers to.** FU
ff20: 4e 43 54 49 4f 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 NCTION()..**.**
ff30: 20 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 LIKEFUNC(zName
ff40: 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 66 6c , nArg, pArg, fl
ff50: 61 67 73 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 ags).** Used
ff60: 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 61 to create a sca
ff70: 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 lar function def
ff80: 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e inition of a fun
ff90: 63 74 69 6f 6e 20 7a 4e 61 6d 65 0a 2a 2a 20 20 ction zName.**
ffa0: 20 20 20 74 68 61 74 20 61 63 63 65 70 74 73 20 that accepts
ffb0: 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 20 61 nArg arguments a
ffc0: 6e 64 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 nd is implemente
ffd0: 64 20 62 79 20 61 20 63 61 6c 6c 20 74 6f 20 43 d by a call to C
ffe0: 0a 2a 2a 20 20 20 20 20 66 75 6e 63 74 69 6f 6e .** function
fff0: 20 6c 69 6b 65 46 75 6e 63 2e 20 41 72 67 75 6d likeFunc. Argum
10000 65 6e 74 20 70 41 72 67 20 69 73 20 63 61 73 74 ent pArg is cast
10010 20 74 6f 20 61 20 28 76 6f 69 64 20 2a 29 20 61 to a (void *) a
10020 6e 64 20 6d 61 64 65 0a 2a 2a 20 20 20 20 20 61 nd made.** a
10030 76 61 69 6c 61 62 6c 65 20 61 73 20 74 68 65 20 vailable as the
10040 66 75 6e 63 74 69 6f 6e 20 75 73 65 72 2d 64 61 function user-da
10050 74 61 20 28 73 71 6c 69 74 65 33 5f 75 73 65 72 ta (sqlite3_user
10060 5f 64 61 74 61 28 29 29 2e 20 54 68 65 0a 2a 2a _data()). The.**
10070 20 20 20 20 20 46 75 6e 63 44 65 66 2e 66 6c 61 FuncDef.fla
10080 67 73 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 gs variable is s
10090 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 et to the value
100a0 70 61 73 73 65 64 20 61 73 20 74 68 65 20 66 6c passed as the fl
100b0 61 67 73 0a 2a 2a 20 20 20 20 20 70 61 72 61 6d ags.** param
100c0 65 74 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 eter..*/.#define
100d0 20 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c FUNCTION(zName,
100e0 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 nArg, iArg, bNC
100f0 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 , xFunc) \. {nA
10100 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f rg, SQLITE_FUNC_
10110 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 5f CONSTANT|SQLITE_
10120 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 UTF8|(bNC*SQLITE
10130 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c _FUNC_NEEDCOLL),
10140 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 \. SQLITE_INT
10150 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 _TO_PTR(iArg), 0
10160 2c 20 78 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 , xFunc, 0, #zNa
10170 6d 65 2c 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e me, {0} }.#defin
10180 65 20 56 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d e VFUNCTION(zNam
10190 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 e, nArg, iArg, b
101a0 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b NC, xFunc) \. {
101b0 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 nArg, SQLITE_UTF
101c0 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 55 8|(bNC*SQLITE_FU
101d0 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a NC_NEEDCOLL), \.
101e0 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f SQLITE_INT_TO
101f0 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 78 _PTR(iArg), 0, x
10200 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c Func, 0, #zName,
10210 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 44 {0} }.#define D
10220 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 FUNCTION(zName,
10230 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c nArg, iArg, bNC,
10240 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 xFunc) \. {nAr
10250 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 g, SQLITE_FUNC_S
10260 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 5f 55 54 LOCHNG|SQLITE_UT
10270 46 38 2c 20 5c 0a 20 20 20 30 2c 20 30 2c 20 78 F8, \. 0, 0, x
10280 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c Func, 0, #zName,
10290 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 50 {0} }.#define P
102a0 55 52 45 5f 44 41 54 45 28 7a 4e 61 6d 65 2c 20 URE_DATE(zName,
102b0 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c nArg, iArg, bNC,
102c0 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 xFunc) \. {nAr
102d0 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 g, SQLITE_FUNC_S
102e0 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 5f 55 54 LOCHNG|SQLITE_UT
102f0 46 38 7c 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 F8|SQLITE_FUNC_C
10300 4f 4e 53 54 41 4e 54 2c 20 5c 0a 20 20 20 28 76 ONSTANT, \. (v
10310 6f 69 64 2a 29 26 73 71 6c 69 74 65 33 43 6f 6e oid*)&sqlite3Con
10320 66 69 67 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 fig, 0, xFunc, 0
10330 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0a , #zName, {0} }.
10340 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f 4e #define FUNCTION
10350 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 2(zName, nArg, i
10360 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 2c Arg, bNC, xFunc,
10370 20 65 78 74 72 61 46 6c 61 67 73 29 20 5c 0a 20 extraFlags) \.
10380 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f 46 55 {nArg,SQLITE_FU
10390 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 NC_CONSTANT|SQLI
103a0 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c TE_UTF8|(bNC*SQL
103b0 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c ITE_FUNC_NEEDCOL
103c0 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 5c 0a L)|extraFlags,\.
103d0 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f SQLITE_INT_TO
103e0 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 78 _PTR(iArg), 0, x
103f0 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c Func, 0, #zName,
10400 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 53 {0} }.#define S
10410 54 52 5f 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d TR_FUNCTION(zNam
10420 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 62 e, nArg, pArg, b
10430 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b NC, xFunc) \. {
10440 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e nArg, SQLITE_FUN
10450 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 C_SLOCHNG|SQLITE
10460 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 _UTF8|(bNC*SQLIT
10470 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 E_FUNC_NEEDCOLL)
10480 2c 20 5c 0a 20 20 20 70 41 72 67 2c 20 30 2c 20 , \. pArg, 0,
10490 78 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 xFunc, 0, #zName
104a0 2c 20 7d 0a 23 64 65 66 69 6e 65 20 4c 49 4b 45 , }.#define LIKE
104b0 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 FUNC(zName, nArg
104c0 2c 20 61 72 67 2c 20 66 6c 61 67 73 29 20 5c 0a , arg, flags) \.
104d0 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
104e0 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 FUNC_CONSTANT|SQ
104f0 4c 49 54 45 5f 55 54 46 38 7c 66 6c 61 67 73 2c LITE_UTF8|flags,
10500 20 5c 0a 20 20 20 28 76 6f 69 64 20 2a 29 61 72 \. (void *)ar
10510 67 2c 20 30 2c 20 6c 69 6b 65 46 75 6e 63 2c 20 g, 0, likeFunc,
10520 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0, #zName, {0} }
10530 0a 23 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 .#define AGGREGA
10540 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 TE(zName, nArg,
10550 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 arg, nc, xStep,
10560 78 46 69 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 xFinal) \. {nAr
10570 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
10580 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
10590 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 EEDCOLL), \. S
105a0 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 QLITE_INT_TO_PTR
105b0 28 61 72 67 29 2c 20 30 2c 20 78 53 74 65 70 2c (arg), 0, xStep,
105c0 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 20 7b xFinal,#zName, {
105d0 30 7d 7d 0a 23 64 65 66 69 6e 65 20 41 47 47 52 0}}.#define AGGR
105e0 45 47 41 54 45 32 28 7a 4e 61 6d 65 2c 20 6e 41 EGATE2(zName, nA
105f0 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 rg, arg, nc, xSt
10600 65 70 2c 20 78 46 69 6e 61 6c 2c 20 65 78 74 72 ep, xFinal, extr
10610 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 aFlags) \. {nAr
10620 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
10630 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
10640 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 61 46 6c EEDCOLL)|extraFl
10650 61 67 73 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 ags, \. SQLITE
10660 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 _INT_TO_PTR(arg)
10670 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 69 6e 61 , 0, xStep,xFina
10680 6c 2c 23 7a 4e 61 6d 65 2c 20 7b 30 7d 7d 0a 0a l,#zName, {0}}..
10690 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 72 72 65 6e /*.** All curren
106a0 74 20 73 61 76 65 70 6f 69 6e 74 73 20 61 72 65 t savepoints are
106b0 20 73 74 6f 72 65 64 20 69 6e 20 61 20 6c 69 6e stored in a lin
106c0 6b 65 64 20 6c 69 73 74 20 73 74 61 72 74 69 6e ked list startin
106d0 67 20 61 74 0a 2a 2a 20 73 71 6c 69 74 65 33 2e g at.** sqlite3.
106e0 70 53 61 76 65 70 6f 69 6e 74 2e 20 54 68 65 20 pSavepoint. The
106f0 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e first element in
10700 20 74 68 65 20 6c 69 73 74 20 69 73 20 74 68 65 the list is the
10710 20 6d 6f 73 74 20 72 65 63 65 6e 74 6c 79 0a 2a most recently.*
10720 2a 20 6f 70 65 6e 65 64 20 73 61 76 65 70 6f 69 * opened savepoi
10730 6e 74 2e 20 53 61 76 65 70 6f 69 6e 74 73 20 61 nt. Savepoints a
10740 72 65 20 61 64 64 65 64 20 74 6f 20 74 68 65 20 re added to the
10750 6c 69 73 74 20 62 79 20 74 68 65 20 76 64 62 65 list by the vdbe
10760 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 6f 69 6e 74 .** OP_Savepoint
10770 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 2a 2f instruction..*/
10780 0a 73 74 72 75 63 74 20 53 61 76 65 70 6f 69 6e .struct Savepoin
10790 74 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d t {. char *zNam
107a0 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
107b0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 61 76 /* Sav
107c0 65 70 6f 69 6e 74 20 6e 61 6d 65 20 28 6e 75 6c epoint name (nul
107d0 2d 74 65 72 6d 69 6e 61 74 65 64 29 20 2a 2f 0a -terminated) */.
107e0 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 43 i64 nDeferredC
107f0 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ons;
10800 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
10810 6f 66 20 64 65 66 65 72 72 65 64 20 66 6b 20 76 of deferred fk v
10820 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 iolations */. i
10830 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d 6d 43 64 nDeferredImmC
10840 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ons;
10850 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
10860 64 65 66 65 72 72 65 64 20 69 6d 6d 20 66 6b 2e deferred imm fk.
10870 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e 74 20 */. Savepoint
10880 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 *pNext;
10890 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 /* Par
108a0 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 20 28 69 ent savepoint (i
108b0 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a f any) */.};../*
108c0 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
108d0 67 20 61 72 65 20 75 73 65 64 20 61 73 20 74 68 g are used as th
108e0 65 20 73 65 63 6f 6e 64 20 70 61 72 61 6d 65 74 e second paramet
108f0 65 72 20 74 6f 20 73 71 6c 69 74 65 33 53 61 76 er to sqlite3Sav
10900 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 20 61 6e 64 epoint(),.** and
10910 20 61 73 20 74 68 65 20 50 31 20 61 72 67 75 6d as the P1 argum
10920 65 6e 74 20 74 6f 20 74 68 65 20 4f 50 5f 53 61 ent to the OP_Sa
10930 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 75 63 74 vepoint instruct
10940 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ion..*/.#define
10950 53 41 56 45 50 4f 49 4e 54 5f 42 45 47 49 4e 20 SAVEPOINT_BEGIN
10960 20 20 20 20 20 30 0a 23 64 65 66 69 6e 65 20 53 0.#define S
10970 41 56 45 50 4f 49 4e 54 5f 52 45 4c 45 41 53 45 AVEPOINT_RELEASE
10980 20 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 41 1.#define SA
10990 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c 42 41 43 4b VEPOINT_ROLLBACK
109a0 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 2.../*.** Eac
109b0 68 20 53 51 4c 69 74 65 20 6d 6f 64 75 6c 65 20 h SQLite module
109c0 28 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 64 (virtual table d
109d0 65 66 69 6e 69 74 69 6f 6e 29 20 69 73 20 64 65 efinition) is de
109e0 66 69 6e 65 64 20 62 79 20 61 6e 0a 2a 2a 20 69 fined by an.** i
109f0 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
10a00 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
10a10 72 65 2c 20 73 74 6f 72 65 64 20 69 6e 20 74 68 re, stored in th
10a20 65 20 73 71 6c 69 74 65 33 2e 61 4d 6f 64 75 6c e sqlite3.aModul
10a30 65 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c 65 2e e.** hash table.
10a40 0a 2a 2f 0a 73 74 72 75 63 74 20 4d 6f 64 75 6c .*/.struct Modul
10a50 65 20 7b 0a 20 20 63 6f 6e 73 74 20 73 71 6c 69 e {. const sqli
10a60 74 65 33 5f 6d 6f 64 75 6c 65 20 2a 70 4d 6f 64 te3_module *pMod
10a70 75 6c 65 3b 20 20 20 20 20 20 20 2f 2a 20 43 61 ule; /* Ca
10a80 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 65 72 73 20 llback pointers
10a90 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
10aa0 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
10ab0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d /* Nam
10ac0 65 20 70 61 73 73 65 64 20 74 6f 20 63 72 65 61 e passed to crea
10ad0 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 te_module() */.
10ae0 20 76 6f 69 64 20 2a 70 41 75 78 3b 20 20 20 20 void *pAux;
10af0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10b00 20 20 20 20 20 20 2f 2a 20 70 41 75 78 20 70 61 /* pAux pa
10b10 73 73 65 64 20 74 6f 20 63 72 65 61 74 65 5f 6d ssed to create_m
10b20 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 76 6f 69 odule() */. voi
10b30 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 76 6f d (*xDestroy)(vo
10b40 69 64 20 2a 29 3b 20 20 20 20 20 20 20 20 20 20 id *);
10b50 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 64 65 73 74 /* Module dest
10b60 72 75 63 74 6f 72 20 66 75 6e 63 74 69 6f 6e 20 ructor function
10b70 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 45 70 6f */. Table *pEpo
10b80 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tab;
10b90 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 70 6f /* Epo
10ba0 6e 79 6d 6f 75 73 20 74 61 62 6c 65 20 66 6f 72 nymous table for
10bb0 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 2a 2f 0a this module */.
10bc0 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e 66 6f 72 6d };../*.** inform
10bd0 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 ation about each
10be0 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 6e 20 53 51 column of an SQ
10bf0 4c 20 74 61 62 6c 65 20 69 73 20 68 65 6c 64 20 L table is held
10c00 69 6e 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a in an instance.*
10c10 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 * of this struct
10c20 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 43 ure..*/.struct C
10c30 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 61 72 20 2a olumn {. char *
10c40 7a 4e 61 6d 65 3b 20 20 20 20 20 2f 2a 20 4e 61 zName; /* Na
10c50 6d 65 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d me of this colum
10c60 6e 2c 20 5c 30 30 30 2c 20 74 68 65 6e 20 74 68 n, \000, then th
10c70 65 20 74 79 70 65 20 2a 2f 0a 20 20 45 78 70 72 e type */. Expr
10c80 20 2a 70 44 66 6c 74 3b 20 20 20 20 20 2f 2a 20 *pDflt; /*
10c90 44 65 66 61 75 6c 74 20 76 61 6c 75 65 20 6f 66 Default value of
10ca0 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a this column */.
10cb0 20 20 63 68 61 72 20 2a 7a 43 6f 6c 6c 3b 20 20 char *zColl;
10cc0 20 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 /* Collating
10cd0 73 65 71 75 65 6e 63 65 2e 20 20 49 66 20 4e 55 sequence. If NU
10ce0 4c 4c 2c 20 75 73 65 20 74 68 65 20 64 65 66 61 LL, use the defa
10cf0 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6e 6f 74 4e ult */. u8 notN
10d00 75 6c 6c 3b 20 20 20 20 20 20 2f 2a 20 41 6e 20 ull; /* An
10d10 4f 45 5f 20 63 6f 64 65 20 66 6f 72 20 68 61 6e OE_ code for han
10d20 64 6c 69 6e 67 20 61 20 4e 4f 54 20 4e 55 4c 4c dling a NOT NULL
10d30 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 20 constraint */.
10d40 20 63 68 61 72 20 61 66 66 69 6e 69 74 79 3b 20 char affinity;
10d50 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 74 68 65 20 /* One of the
10d60 53 51 4c 49 54 45 5f 41 46 46 5f 2e 2e 2e 20 76 SQLITE_AFF_... v
10d70 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 73 7a alues */. u8 sz
10d80 45 73 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 Est; /* E
10d90 73 74 69 6d 61 74 65 64 20 73 69 7a 65 20 6f 66 stimated size of
10da0 20 76 61 6c 75 65 20 69 6e 20 74 68 69 73 20 63 value in this c
10db0 6f 6c 75 6d 6e 2e 20 73 69 7a 65 6f 66 28 49 4e olumn. sizeof(IN
10dc0 54 29 3d 3d 31 20 2a 2f 0a 20 20 75 38 20 63 6f T)==1 */. u8 co
10dd0 6c 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 42 lFlags; /* B
10de0 6f 6f 6c 65 61 6e 20 70 72 6f 70 65 72 74 69 65 oolean propertie
10df0 73 2e 20 20 53 65 65 20 43 4f 4c 46 4c 41 47 5f s. See COLFLAG_
10e00 20 64 65 66 69 6e 65 73 20 62 65 6c 6f 77 20 2a defines below *
10e10 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 /.};../* Allowed
10e20 20 76 61 6c 75 65 73 20 66 6f 72 20 43 6f 6c 75 values for Colu
10e30 6d 6e 2e 63 6f 6c 46 6c 61 67 73 3a 0a 2a 2f 0a mn.colFlags:.*/.
10e40 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f #define COLFLAG_
10e50 50 52 49 4d 4b 45 59 20 20 30 78 30 30 30 31 20 PRIMKEY 0x0001
10e60 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 69 73 20 /* Column is
10e70 70 61 72 74 20 6f 66 20 74 68 65 20 70 72 69 6d part of the prim
10e80 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 ary key */.#defi
10e90 6e 65 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 45 ne COLFLAG_HIDDE
10ea0 4e 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a N 0x0002 /*
10eb0 20 41 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e A hidden column
10ec0 20 69 6e 20 61 20 76 69 72 74 75 61 6c 20 74 61 in a virtual ta
10ed0 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 ble */.#define C
10ee0 4f 4c 46 4c 41 47 5f 48 41 53 54 59 50 45 20 20 OLFLAG_HASTYPE
10ef0 30 78 30 30 30 34 20 20 20 20 2f 2a 20 54 79 70 0x0004 /* Typ
10f00 65 20 6e 61 6d 65 20 66 6f 6c 6c 6f 77 73 20 63 e name follows c
10f10 6f 6c 75 6d 6e 20 6e 61 6d 65 20 2a 2f 0a 23 64 olumn name */.#d
10f20 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 55 4e efine COLFLAG_UN
10f30 49 51 55 45 20 20 20 30 78 30 30 30 38 20 20 20 IQUE 0x0008
10f40 20 2f 2a 20 43 6f 6c 75 6d 6e 20 64 65 66 20 63 /* Column def c
10f50 6f 6e 74 61 69 6e 73 20 22 55 4e 49 51 55 45 22 ontains "UNIQUE"
10f60 20 6f 72 20 22 50 4b 22 20 2a 2f 0a 0a 2f 2a 0a or "PK" */../*.
10f70 2a 2a 20 41 20 22 43 6f 6c 6c 61 74 69 6e 67 20 ** A "Collating
10f80 53 65 71 75 65 6e 63 65 22 20 69 73 20 64 65 66 Sequence" is def
10f90 69 6e 65 64 20 62 79 20 61 6e 20 69 6e 73 74 61 ined by an insta
10fa0 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
10fb0 77 69 6e 67 0a 2a 2a 20 73 74 72 75 63 74 75 72 wing.** structur
10fc0 65 2e 20 43 6f 6e 63 65 70 74 75 61 6c 6c 79 2c e. Conceptually,
10fd0 20 61 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 a collating seq
10fe0 75 65 6e 63 65 20 63 6f 6e 73 69 73 74 73 20 6f uence consists o
10ff0 66 20 61 20 6e 61 6d 65 20 61 6e 64 0a 2a 2a 20 f a name and.**
11000 61 20 63 6f 6d 70 61 72 69 73 6f 6e 20 72 6f 75 a comparison rou
11010 74 69 6e 65 20 74 68 61 74 20 64 65 66 69 6e 65 tine that define
11020 73 20 74 68 65 20 6f 72 64 65 72 20 6f 66 20 74 s the order of t
11030 68 61 74 20 73 65 71 75 65 6e 63 65 2e 0a 2a 2a hat sequence..**
11040 0a 2a 2a 20 49 66 20 43 6f 6c 6c 53 65 71 2e 78 .** If CollSeq.x
11050 43 6d 70 20 69 73 20 4e 55 4c 4c 2c 20 69 74 20 Cmp is NULL, it
11060 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 0a 2a means that the.*
11070 2a 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 * collating sequ
11080 65 6e 63 65 20 69 73 20 75 6e 64 65 66 69 6e 65 ence is undefine
11090 64 2e 20 20 49 6e 64 69 63 65 73 20 62 75 69 6c d. Indices buil
110a0 74 20 6f 6e 20 61 6e 20 75 6e 64 65 66 69 6e 65 t on an undefine
110b0 64 0a 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 20 73 d.** collating s
110c0 65 71 75 65 6e 63 65 20 6d 61 79 20 6e 6f 74 20 equence may not
110d0 62 65 20 72 65 61 64 20 6f 72 20 77 72 69 74 74 be read or writt
110e0 65 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 43 6f en..*/.struct Co
110f0 6c 6c 53 65 71 20 7b 0a 20 20 63 68 61 72 20 2a llSeq {. char *
11100 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 zName;
11110 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 63 /* Name of the c
11120 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
11130 65 2c 20 55 54 46 2d 38 20 65 6e 63 6f 64 65 64 e, UTF-8 encoded
11140 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 */. u8 enc;
11150 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
11160 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 68 61 6e ext encoding han
11170 64 6c 65 64 20 62 79 20 78 43 6d 70 28 29 20 2a dled by xCmp() *
11180 2f 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 72 3b /. void *pUser;
11190 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 /* Fir
111a0 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 st argument to x
111b0 43 6d 70 28 29 20 2a 2f 0a 20 20 69 6e 74 20 28 Cmp() */. int (
111c0 2a 78 43 6d 70 29 28 76 6f 69 64 2a 2c 69 6e 74 *xCmp)(void*,int
111d0 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 , const void*, i
111e0 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 29 nt, const void*)
111f0 3b 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 6c 29 ;. void (*xDel)
11200 28 76 6f 69 64 2a 29 3b 20 20 2f 2a 20 44 65 73 (void*); /* Des
11210 74 72 75 63 74 6f 72 20 66 6f 72 20 70 55 73 65 tructor for pUse
11220 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 r */.};../*.** A
11230 20 73 6f 72 74 20 6f 72 64 65 72 20 63 61 6e 20 sort order can
11240 62 65 20 65 69 74 68 65 72 20 41 53 43 20 6f 72 be either ASC or
11250 20 44 45 53 43 2e 0a 2a 2f 0a 23 64 65 66 69 6e DESC..*/.#defin
11260 65 20 53 51 4c 49 54 45 5f 53 4f 5f 41 53 43 20 e SQLITE_SO_ASC
11270 20 20 20 20 20 20 30 20 20 2f 2a 20 53 6f 72 74 0 /* Sort
11280 20 69 6e 20 61 73 63 65 6e 64 69 6e 67 20 6f 72 in ascending or
11290 64 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 der */.#define S
112a0 51 4c 49 54 45 5f 53 4f 5f 44 45 53 43 20 20 20 QLITE_SO_DESC
112b0 20 20 20 31 20 20 2f 2a 20 53 6f 72 74 20 69 6e 1 /* Sort in
112c0 20 61 73 63 65 6e 64 69 6e 67 20 6f 72 64 65 72 ascending order
112d0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
112e0 54 45 5f 53 4f 5f 55 4e 44 45 46 49 4e 45 44 20 TE_SO_UNDEFINED
112f0 2d 31 20 2f 2a 20 4e 6f 20 73 6f 72 74 20 6f 72 -1 /* No sort or
11300 64 65 72 20 73 70 65 63 69 66 69 65 64 20 2a 2f der specified */
11310 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6c 75 6d 6e 20 61 ../*.** Column a
11320 66 66 69 6e 69 74 79 20 74 79 70 65 73 2e 0a 2a ffinity types..*
11330 2a 0a 2a 2a 20 54 68 65 73 65 20 75 73 65 64 20 *.** These used
11340 74 6f 20 68 61 76 65 20 6d 6e 65 6d 6f 6e 69 63 to have mnemonic
11350 20 6e 61 6d 65 20 6c 69 6b 65 20 27 69 27 20 66 name like 'i' f
11360 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 4e or SQLITE_AFF_IN
11370 54 45 47 45 52 20 61 6e 64 0a 2a 2a 20 27 74 27 TEGER and.** 't'
11380 20 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 5f for SQLITE_AFF_
11390 54 45 58 54 2e 20 20 42 75 74 20 77 65 20 63 61 TEXT. But we ca
113a0 6e 20 73 61 76 65 20 61 20 6c 69 74 74 6c 65 20 n save a little
113b0 73 70 61 63 65 20 61 6e 64 20 69 6d 70 72 6f 76 space and improv
113c0 65 0a 2a 2a 20 74 68 65 20 73 70 65 65 64 20 61 e.** the speed a
113d0 20 6c 69 74 74 6c 65 20 62 79 20 6e 75 6d 62 65 little by numbe
113e0 72 69 6e 67 20 74 68 65 20 76 61 6c 75 65 73 20 ring the values
113f0 63 6f 6e 73 65 63 75 74 69 76 65 6c 79 2e 0a 2a consecutively..*
11400 2a 0a 2a 2a 20 42 75 74 20 72 61 74 68 65 72 20 *.** But rather
11410 74 68 61 6e 20 73 74 61 72 74 20 77 69 74 68 20 than start with
11420 30 20 6f 72 20 31 2c 20 77 65 20 62 65 67 69 6e 0 or 1, we begin
11430 20 77 69 74 68 20 27 41 27 2e 20 20 54 68 61 74 with 'A'. That
11440 20 77 61 79 2c 0a 2a 2a 20 77 68 65 6e 20 6d 75 way,.** when mu
11450 6c 74 69 70 6c 65 20 61 66 66 69 6e 69 74 79 20 ltiple affinity
11460 74 79 70 65 73 20 61 72 65 20 63 6f 6e 63 61 74 types are concat
11470 65 6e 61 74 65 64 20 69 6e 74 6f 20 61 20 73 74 enated into a st
11480 72 69 6e 67 20 61 6e 64 0a 2a 2a 20 75 73 65 64 ring and.** used
11490 20 61 73 20 74 68 65 20 50 34 20 6f 70 65 72 61 as the P4 opera
114a0 6e 64 2c 20 74 68 65 79 20 77 69 6c 6c 20 62 65 nd, they will be
114b0 20 6d 6f 72 65 20 72 65 61 64 61 62 6c 65 2e 0a more readable..
114c0 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 61 6c 73 6f 20 **.** Note also
114d0 74 68 61 74 20 74 68 65 20 6e 75 6d 65 72 69 63 that the numeric
114e0 20 74 79 70 65 73 20 61 72 65 20 67 72 6f 75 70 types are group
114f0 65 64 20 74 6f 67 65 74 68 65 72 20 73 6f 20 74 ed together so t
11500 68 61 74 20 74 65 73 74 69 6e 67 0a 2a 2a 20 66 hat testing.** f
11510 6f 72 20 61 20 6e 75 6d 65 72 69 63 20 74 79 70 or a numeric typ
11520 65 20 69 73 20 61 20 73 69 6e 67 6c 65 20 63 6f e is a single co
11530 6d 70 61 72 69 73 6f 6e 2e 20 20 41 6e 64 20 74 mparison. And t
11540 68 65 20 42 4c 4f 42 20 74 79 70 65 20 69 73 20 he BLOB type is
11550 66 69 72 73 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e first..*/.#defin
11560 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 42 4c 4f e SQLITE_AFF_BLO
11570 42 20 20 20 20 20 27 41 27 0a 23 64 65 66 69 6e B 'A'.#defin
11580 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 45 58 e SQLITE_AFF_TEX
11590 54 20 20 20 20 20 27 42 27 0a 23 64 65 66 69 6e T 'B'.#defin
115a0 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4e 55 4d e SQLITE_AFF_NUM
115b0 45 52 49 43 20 20 27 43 27 0a 23 64 65 66 69 6e ERIC 'C'.#defin
115c0 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 4e 54 e SQLITE_AFF_INT
115d0 45 47 45 52 20 20 27 44 27 0a 23 64 65 66 69 6e EGER 'D'.#defin
115e0 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 52 45 41 e SQLITE_AFF_REA
115f0 4c 20 20 20 20 20 27 45 27 0a 0a 23 64 65 66 69 L 'E'..#defi
11600 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 75 6d 65 ne sqlite3IsNume
11610 72 69 63 41 66 66 69 6e 69 74 79 28 58 29 20 20 ricAffinity(X)
11620 28 28 58 29 3e 3d 53 51 4c 49 54 45 5f 41 46 46 ((X)>=SQLITE_AFF
11630 5f 4e 55 4d 45 52 49 43 29 0a 0a 2f 2a 0a 2a 2a _NUMERIC)../*.**
11640 20 54 68 65 20 53 51 4c 49 54 45 5f 41 46 46 5f The SQLITE_AFF_
11650 4d 41 53 4b 20 76 61 6c 75 65 73 20 6d 61 73 6b MASK values mask
11660 73 20 6f 66 66 20 74 68 65 20 73 69 67 6e 69 66 s off the signif
11670 69 63 61 6e 74 20 62 69 74 73 20 6f 66 20 61 6e icant bits of an
11680 0a 2a 2a 20 61 66 66 69 6e 69 74 79 20 76 61 6c .** affinity val
11690 75 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ue..*/.#define S
116a0 51 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b 20 20 QLITE_AFF_MASK
116b0 20 20 20 30 78 34 37 0a 0a 2f 2a 0a 2a 2a 20 41 0x47../*.** A
116c0 64 64 69 74 69 6f 6e 61 6c 20 62 69 74 20 76 61 dditional bit va
116d0 6c 75 65 73 20 74 68 61 74 20 63 61 6e 20 62 65 lues that can be
116e0 20 4f 52 65 64 20 77 69 74 68 20 61 6e 20 61 66 ORed with an af
116f0 66 69 6e 69 74 79 20 77 69 74 68 6f 75 74 0a 2a finity without.*
11700 2a 20 63 68 61 6e 67 69 6e 67 20 74 68 65 20 61 * changing the a
11710 66 66 69 6e 69 74 79 2e 0a 2a 2a 0a 2a 2a 20 54 ffinity..**.** T
11720 68 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c he SQLITE_NOTNUL
11730 4c 20 66 6c 61 67 20 69 73 20 61 20 63 6f 6d 62 L flag is a comb
11740 69 6e 61 74 69 6f 6e 20 6f 66 20 4e 55 4c 4c 45 ination of NULLE
11750 51 20 61 6e 64 20 4a 55 4d 50 49 46 4e 55 4c 4c Q and JUMPIFNULL
11760 2e 0a 2a 2a 20 49 74 20 63 61 75 73 65 73 20 61 ..** It causes a
11770 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 66 69 n assert() to fi
11780 72 65 20 69 66 20 65 69 74 68 65 72 20 6f 70 65 re if either ope
11790 72 61 6e 64 20 74 6f 20 61 20 63 6f 6d 70 61 72 rand to a compar
117a0 69 73 6f 6e 0a 2a 2a 20 6f 70 65 72 61 74 6f 72 ison.** operator
117b0 20 69 73 20 4e 55 4c 4c 2e 20 20 49 74 20 69 73 is NULL. It is
117c0 20 61 64 64 65 64 20 74 6f 20 63 65 72 74 61 69 added to certai
117d0 6e 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 70 65 n comparison ope
117e0 72 61 74 6f 72 73 20 74 6f 0a 2a 2a 20 70 72 6f rators to.** pro
117f0 76 65 20 74 68 61 74 20 74 68 65 20 6f 70 65 72 ve that the oper
11800 61 6e 64 73 20 61 72 65 20 61 6c 77 61 79 73 20 ands are always
11810 4e 4f 54 20 4e 55 4c 4c 2e 0a 2a 2f 0a 23 64 65 NOT NULL..*/.#de
11820 66 69 6e 65 20 53 51 4c 49 54 45 5f 4b 45 45 50 fine SQLITE_KEEP
11830 4e 55 4c 4c 20 20 20 20 20 30 78 30 38 20 20 2f NULL 0x08 /
11840 2a 20 55 73 65 64 20 62 79 20 76 65 63 74 6f 72 * Used by vector
11850 20 3d 3d 20 6f 72 20 3c 3e 20 2a 2f 0a 23 64 65 == or <> */.#de
11860 66 69 6e 65 20 53 51 4c 49 54 45 5f 4a 55 4d 50 fine SQLITE_JUMP
11870 49 46 4e 55 4c 4c 20 20 20 30 78 31 30 20 20 2f IFNULL 0x10 /
11880 2a 20 6a 75 6d 70 73 20 69 66 20 65 69 74 68 65 * jumps if eithe
11890 72 20 6f 70 65 72 61 6e 64 20 69 73 20 4e 55 4c r operand is NUL
118a0 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c L */.#define SQL
118b0 49 54 45 5f 53 54 4f 52 45 50 32 20 20 20 20 20 ITE_STOREP2
118c0 20 30 78 32 30 20 20 2f 2a 20 53 74 6f 72 65 20 0x20 /* Store
118d0 72 65 73 75 6c 74 20 69 6e 20 72 65 67 5b 50 32 result in reg[P2
118e0 5d 20 72 61 74 68 65 72 20 74 68 61 6e 20 6a 75 ] rather than ju
118f0 6d 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 mp */.#define SQ
11900 4c 49 54 45 5f 4e 55 4c 4c 45 51 20 20 20 20 20 LITE_NULLEQ
11910 20 20 30 78 38 30 20 20 2f 2a 20 4e 55 4c 4c 3d 0x80 /* NULL=
11920 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 NULL */.#define
11930 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c 20 20 SQLITE_NOTNULL
11940 20 20 20 20 30 78 39 30 20 20 2f 2a 20 41 73 73 0x90 /* Ass
11950 65 72 74 20 74 68 61 74 20 6f 70 65 72 61 6e 64 ert that operand
11960 73 20 61 72 65 20 6e 65 76 65 72 20 4e 55 4c 4c s are never NULL
11970 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 */../*.** An ob
11980 6a 65 63 74 20 6f 66 20 74 68 69 73 20 74 79 70 ject of this typ
11990 65 20 69 73 20 63 72 65 61 74 65 64 20 66 6f 72 e is created for
119a0 20 65 61 63 68 20 76 69 72 74 75 61 6c 20 74 61 each virtual ta
119b0 62 6c 65 20 70 72 65 73 65 6e 74 20 69 6e 0a 2a ble present in.*
119c0 2a 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 * the database s
119d0 63 68 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 chema..**.** If
119e0 74 68 65 20 64 61 74 61 62 61 73 65 20 73 63 68 the database sch
119f0 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c 20 74 ema is shared, t
11a00 68 65 6e 20 74 68 65 72 65 20 69 73 20 6f 6e 65 hen there is one
11a10 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 instance of thi
11a20 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 20 66 s.** structure f
11a30 6f 72 20 65 61 63 68 20 64 61 74 61 62 61 73 65 or each database
11a40 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 28 73 71 6c connection (sql
11a50 69 74 65 33 2a 29 20 74 68 61 74 20 75 73 65 73 ite3*) that uses
11a60 20 74 68 65 20 73 68 61 72 65 64 0a 2a 2a 20 73 the shared.** s
11a70 63 68 65 6d 61 2e 20 54 68 69 73 20 69 73 20 62 chema. This is b
11a80 65 63 61 75 73 65 20 65 61 63 68 20 64 61 74 61 ecause each data
11a90 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 base connection
11aa0 72 65 71 75 69 72 65 73 20 69 74 73 20 6f 77 6e requires its own
11ab0 20 75 6e 69 71 75 65 0a 2a 2a 20 69 6e 73 74 61 unique.** insta
11ac0 6e 63 65 20 6f 66 20 74 68 65 20 73 71 6c 69 74 nce of the sqlit
11ad0 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 20 e3_vtab* handle
11ae0 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 20 74 used to access t
11af0 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 he virtual table
11b00 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 .** implementati
11b10 6f 6e 2e 20 73 71 6c 69 74 65 33 5f 76 74 61 62 on. sqlite3_vtab
11b20 2a 20 68 61 6e 64 6c 65 73 20 63 61 6e 20 6e 6f * handles can no
11b30 74 20 62 65 20 73 68 61 72 65 64 20 62 65 74 77 t be shared betw
11b40 65 65 6e 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 een.** database
11b50 63 6f 6e 6e 65 63 74 69 6f 6e 73 2c 20 65 76 65 connections, eve
11b60 6e 20 77 68 65 6e 20 74 68 65 20 72 65 73 74 20 n when the rest
11b70 6f 66 20 74 68 65 20 69 6e 2d 6d 65 6d 6f 72 79 of the in-memory
11b80 20 64 61 74 61 62 61 73 65 0a 2a 2a 20 73 63 68 database.** sch
11b90 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c 20 61 ema is shared, a
11ba0 73 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 s the implementa
11bb0 74 69 6f 6e 20 6f 66 74 65 6e 20 73 74 6f 72 65 tion often store
11bc0 73 20 74 68 65 20 64 61 74 61 62 61 73 65 0a 2a s the database.*
11bd0 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e * connection han
11be0 64 6c 65 20 70 61 73 73 65 64 20 74 6f 20 69 74 dle passed to it
11bf0 20 76 69 61 20 74 68 65 20 78 43 6f 6e 6e 65 63 via the xConnec
11c00 74 28 29 20 6f 72 20 78 43 72 65 61 74 65 28 29 t() or xCreate()
11c10 20 6d 65 74 68 6f 64 0a 2a 2a 20 64 75 72 69 6e method.** durin
11c20 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e g initialization
11c30 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 20 54 68 69 internally. Thi
11c40 73 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 s database conne
11c50 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 6d 61 79 ction handle may
11c60 0a 2a 2a 20 74 68 65 6e 20 62 65 20 75 73 65 64 .** then be used
11c70 20 62 79 20 74 68 65 20 76 69 72 74 75 61 6c 20 by the virtual
11c80 74 61 62 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 table implementa
11c90 74 69 6f 6e 20 74 6f 20 61 63 63 65 73 73 20 72 tion to access r
11ca0 65 61 6c 20 74 61 62 6c 65 73 0a 2a 2a 20 77 69 eal tables.** wi
11cb0 74 68 69 6e 20 74 68 65 20 64 61 74 61 62 61 73 thin the databas
11cc0 65 2e 20 53 6f 20 74 68 61 74 20 74 68 65 79 20 e. So that they
11cd0 61 70 70 65 61 72 20 61 73 20 70 61 72 74 20 6f appear as part o
11ce0 66 20 74 68 65 20 63 61 6c 6c 65 72 73 0a 2a 2a f the callers.**
11cf0 20 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 74 68 transaction, th
11d00 65 73 65 20 61 63 63 65 73 73 65 73 20 6e 65 65 ese accesses nee
11d10 64 20 74 6f 20 62 65 20 6d 61 64 65 20 76 69 61 d to be made via
11d20 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 62 61 the same databa
11d30 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e se.** connection
11d40 20 61 73 20 74 68 61 74 20 75 73 65 64 20 74 6f as that used to
11d50 20 65 78 65 63 75 74 65 20 53 51 4c 20 6f 70 65 execute SQL ope
11d60 72 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 20 76 rations on the v
11d70 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0a 2a 2a irtual table..**
11d80 0a 2a 2a 20 41 6c 6c 20 56 54 61 62 6c 65 20 6f .** All VTable o
11d90 62 6a 65 63 74 73 20 74 68 61 74 20 63 6f 72 72 bjects that corr
11da0 65 73 70 6f 6e 64 20 74 6f 20 61 20 73 69 6e 67 espond to a sing
11db0 6c 65 20 74 61 62 6c 65 20 69 6e 20 61 20 73 68 le table in a sh
11dc0 61 72 65 64 0a 2a 2a 20 64 61 74 61 62 61 73 65 ared.** database
11dd0 20 73 63 68 65 6d 61 20 61 72 65 20 69 6e 69 74 schema are init
11de0 69 61 6c 6c 79 20 73 74 6f 72 65 64 20 69 6e 20 ially stored in
11df0 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 70 6f a linked-list po
11e00 69 6e 74 65 64 20 74 6f 20 62 79 0a 2a 2a 20 74 inted to by.** t
11e10 68 65 20 54 61 62 6c 65 2e 70 56 54 61 62 6c 65 he Table.pVTable
11e20 20 6d 65 6d 62 65 72 20 76 61 72 69 61 62 6c 65 member variable
11e30 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 70 6f of the correspo
11e40 6e 64 69 6e 67 20 54 61 62 6c 65 20 6f 62 6a 65 nding Table obje
11e50 63 74 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e 20 73 ct..** When an s
11e60 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 28 29 qlite3_prepare()
11e70 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 72 65 operation is re
11e80 71 75 69 72 65 64 20 74 6f 20 61 63 63 65 73 73 quired to access
11e90 20 74 68 65 20 76 69 72 74 75 61 6c 0a 2a 2a 20 the virtual.**
11ea0 74 61 62 6c 65 2c 20 69 74 20 73 65 61 72 63 68 table, it search
11eb0 65 73 20 74 68 65 20 6c 69 73 74 20 66 6f 72 20 es the list for
11ec0 74 68 65 20 56 54 61 62 6c 65 20 74 68 61 74 20 the VTable that
11ed0 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 corresponds to t
11ee0 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 he.** database c
11ef0 6f 6e 6e 65 63 74 69 6f 6e 20 64 6f 69 6e 67 20 onnection doing
11f00 74 68 65 20 70 72 65 70 61 72 69 6e 67 20 73 6f the preparing so
11f10 20 61 73 20 74 6f 20 75 73 65 20 74 68 65 20 63 as to use the c
11f20 6f 72 72 65 63 74 0a 2a 2a 20 73 71 6c 69 74 65 orrect.** sqlite
11f30 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 20 69 3_vtab* handle i
11f40 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 64 20 71 n the compiled q
11f50 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 6e uery..**.** When
11f60 20 61 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 54 61 an in-memory Ta
11f70 62 6c 65 20 6f 62 6a 65 63 74 20 69 73 20 64 65 ble object is de
11f80 6c 65 74 65 64 20 28 66 6f 72 20 65 78 61 6d 70 leted (for examp
11f90 6c 65 20 77 68 65 6e 20 74 68 65 0a 2a 2a 20 73 le when the.** s
11fa0 63 68 65 6d 61 20 69 73 20 62 65 69 6e 67 20 72 chema is being r
11fb0 65 6c 6f 61 64 65 64 20 66 6f 72 20 73 6f 6d 65 eloaded for some
11fc0 20 72 65 61 73 6f 6e 29 2c 20 74 68 65 20 56 54 reason), the VT
11fd0 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 61 72 65 able objects are
11fe0 20 6e 6f 74 0a 2a 2a 20 64 65 6c 65 74 65 64 20 not.** deleted
11ff0 61 6e 64 20 74 68 65 20 73 71 6c 69 74 65 33 5f and the sqlite3_
12000 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 61 72 vtab* handles ar
12010 65 20 6e 6f 74 20 78 44 69 73 63 6f 6e 6e 65 63 e not xDisconnec
12020 74 28 29 65 64 0a 2a 2a 20 69 6d 6d 65 64 69 61 t()ed.** immedia
12030 74 65 6c 79 2e 20 49 6e 73 74 65 61 64 2c 20 74 tely. Instead, t
12040 68 65 79 20 61 72 65 20 6d 6f 76 65 64 20 66 72 hey are moved fr
12050 6f 6d 20 74 68 65 20 54 61 62 6c 65 2e 70 56 54 om the Table.pVT
12060 61 62 6c 65 20 6c 69 73 74 20 74 6f 0a 2a 2a 20 able list to.**
12070 61 6e 6f 74 68 65 72 20 6c 69 6e 6b 65 64 20 6c another linked l
12080 69 73 74 20 68 65 61 64 65 64 20 62 79 20 74 68 ist headed by th
12090 65 20 73 71 6c 69 74 65 33 2e 70 44 69 73 63 6f e sqlite3.pDisco
120a0 6e 6e 65 63 74 20 6d 65 6d 62 65 72 20 6f 66 20 nnect member of
120b0 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e the.** correspon
120c0 64 69 6e 67 20 73 71 6c 69 74 65 33 20 73 74 72 ding sqlite3 str
120d0 75 63 74 75 72 65 2e 20 54 68 65 79 20 61 72 65 ucture. They are
120e0 20 74 68 65 6e 20 64 65 6c 65 74 65 64 2f 78 44 then deleted/xD
120f0 69 73 63 6f 6e 6e 65 63 74 65 64 0a 2a 2a 20 6e isconnected.** n
12100 65 78 74 20 74 69 6d 65 20 61 20 73 74 61 74 65 ext time a state
12110 6d 65 6e 74 20 69 73 20 70 72 65 70 61 72 65 64 ment is prepared
12120 20 75 73 69 6e 67 20 73 61 69 64 20 73 71 6c 69 using said sqli
12130 74 65 33 2a 2e 20 54 68 69 73 20 69 73 20 64 6f te3*. This is do
12140 6e 65 0a 2a 2a 20 74 6f 20 61 76 6f 69 64 20 64 ne.** to avoid d
12150 65 61 64 6c 6f 63 6b 20 69 73 73 75 65 73 20 69 eadlock issues i
12160 6e 76 6f 6c 76 69 6e 67 20 6d 75 6c 74 69 70 6c nvolving multipl
12170 65 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 78 20 e sqlite3.mutex
12180 6d 75 74 65 78 65 73 2e 0a 2a 2a 20 52 65 66 65 mutexes..** Refe
12190 72 20 74 6f 20 63 6f 6d 6d 65 6e 74 73 20 61 62 r to comments ab
121a0 6f 76 65 20 66 75 6e 63 74 69 6f 6e 20 73 71 6c ove function sql
121b0 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 ite3VtabUnlockLi
121c0 73 74 28 29 20 66 6f 72 20 61 6e 0a 2a 2a 20 65 st() for an.** e
121d0 78 70 6c 61 6e 61 74 69 6f 6e 20 61 73 20 74 6f xplanation as to
121e0 20 77 68 79 20 69 74 20 69 73 20 73 61 66 65 20 why it is safe
121f0 74 6f 20 61 64 64 20 61 6e 20 65 6e 74 72 79 20 to add an entry
12200 74 6f 20 61 6e 20 73 71 6c 69 74 65 33 2e 70 44 to an sqlite3.pD
12210 69 73 63 6f 6e 6e 65 63 74 0a 2a 2a 20 6c 69 73 isconnect.** lis
12220 74 20 77 69 74 68 6f 75 74 20 68 6f 6c 64 69 6e t without holdin
12230 67 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 g the correspond
12240 69 6e 67 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 ing sqlite3.mute
12250 78 20 6d 75 74 65 78 2e 0a 2a 2a 0a 2a 2a 20 54 x mutex..**.** T
12260 68 65 20 6d 65 6d 6f 72 79 20 66 6f 72 20 6f 62 he memory for ob
12270 6a 65 63 74 73 20 6f 66 20 74 68 69 73 20 74 79 jects of this ty
12280 70 65 20 69 73 20 61 6c 77 61 79 73 20 61 6c 6c pe is always all
12290 6f 63 61 74 65 64 20 62 79 0a 2a 2a 20 73 71 6c ocated by.** sql
122a0 69 74 65 33 44 62 4d 61 6c 6c 6f 63 28 29 2c 20 ite3DbMalloc(),
122b0 75 73 69 6e 67 20 74 68 65 20 63 6f 6e 6e 65 63 using the connec
122c0 74 69 6f 6e 20 68 61 6e 64 6c 65 20 73 74 6f 72 tion handle stor
122d0 65 64 20 69 6e 20 56 54 61 62 6c 65 2e 64 62 20 ed in VTable.db
122e0 61 73 0a 2a 2a 20 74 68 65 20 66 69 72 73 74 20 as.** the first
122f0 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 72 argument..*/.str
12300 75 63 74 20 56 54 61 62 6c 65 20 7b 0a 20 20 73 uct VTable {. s
12310 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 qlite3 *db;
12320 20 20 20 20 20 20 20 20 20 2f 2a 20 44 61 74 61 /* Data
12330 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 base connection
12340 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
12350 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 this table */.
12360 4d 6f 64 75 6c 65 20 2a 70 4d 6f 64 3b 20 20 20 Module *pMod;
12370 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 /* Poi
12380 6e 74 65 72 20 74 6f 20 6d 6f 64 75 6c 65 20 69 nter to module i
12390 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f mplementation */
123a0 0a 20 20 73 71 6c 69 74 65 33 5f 76 74 61 62 20 . sqlite3_vtab
123b0 2a 70 56 74 61 62 3b 20 20 20 20 20 20 2f 2a 20 *pVtab; /*
123c0 50 6f 69 6e 74 65 72 20 74 6f 20 76 74 61 62 20 Pointer to vtab
123d0 69 6e 73 74 61 6e 63 65 20 2a 2f 0a 20 20 69 6e instance */. in
123e0 74 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 t nRef;
123f0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
12400 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f r of pointers to
12410 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 this structure
12420 2a 2f 0a 20 20 75 38 20 62 43 6f 6e 73 74 72 61 */. u8 bConstra
12430 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f int; /
12440 2a 20 54 72 75 65 20 69 66 20 63 6f 6e 73 74 72 * True if constr
12450 61 69 6e 74 73 20 61 72 65 20 73 75 70 70 6f 72 aints are suppor
12460 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 53 61 ted */. int iSa
12470 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 vepoint;
12480 20 20 20 2f 2a 20 44 65 70 74 68 20 6f 66 20 74 /* Depth of t
12490 68 65 20 53 41 56 45 50 4f 49 4e 54 20 73 74 61 he SAVEPOINT sta
124a0 63 6b 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a ck */. VTable *
124b0 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 20 pNext;
124c0 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 6e /* Next in lin
124d0 6b 65 64 20 6c 69 73 74 20 28 73 65 65 20 61 62 ked list (see ab
124e0 6f 76 65 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a ove) */.};../*.*
124f0 2a 20 54 68 65 20 73 63 68 65 6d 61 20 66 6f 72 * The schema for
12500 20 65 61 63 68 20 53 51 4c 20 74 61 62 6c 65 20 each SQL table
12510 61 6e 64 20 76 69 65 77 20 69 73 20 72 65 70 72 and view is repr
12520 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 6d 6f 72 esented in memor
12530 79 0a 2a 2a 20 62 79 20 61 6e 20 69 6e 73 74 61 y.** by an insta
12540 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
12550 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e 0a wing structure..
12560 2a 2f 0a 73 74 72 75 63 74 20 54 61 62 6c 65 20 */.struct Table
12570 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b {. char *zName;
12580 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 /* Name
12590 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 6f 72 of the table or
125a0 20 76 69 65 77 20 2a 2f 0a 20 20 43 6f 6c 75 6d view */. Colum
125b0 6e 20 2a 61 43 6f 6c 3b 20 20 20 20 20 20 20 20 n *aCol;
125c0 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 /* Information a
125d0 62 6f 75 74 20 65 61 63 68 20 63 6f 6c 75 6d 6e bout each column
125e0 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 49 6e */. Index *pIn
125f0 64 65 78 3b 20 20 20 20 20 20 20 2f 2a 20 4c 69 dex; /* Li
12600 73 74 20 6f 66 20 53 51 4c 20 69 6e 64 65 78 65 st of SQL indexe
12610 73 20 6f 6e 20 74 68 69 73 20 74 61 62 6c 65 2e s on this table.
12620 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 53 */. Select *pS
12630 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 4e 55 elect; /* NU
12640 4c 4c 20 66 6f 72 20 74 61 62 6c 65 73 2e 20 20 LL for tables.
12650 50 6f 69 6e 74 73 20 74 6f 20 64 65 66 69 6e 69 Points to defini
12660 74 69 6f 6e 20 69 66 20 61 20 76 69 65 77 2e 20 tion if a view.
12670 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 46 4b 65 79 */. FKey *pFKey
12680 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 6e ; /* Lin
12690 6b 65 64 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 ked list of all
126a0 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 69 6e 20 foreign keys in
126b0 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 this table */.
126c0 63 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b 20 20 char *zColAff;
126d0 20 20 20 20 20 2f 2a 20 53 74 72 69 6e 67 20 64 /* String d
126e0 65 66 69 6e 69 6e 67 20 74 68 65 20 61 66 66 69 efining the affi
126f0 6e 69 74 79 20 6f 66 20 65 61 63 68 20 63 6f 6c nity of each col
12700 75 6d 6e 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 umn */. ExprLis
12710 74 20 2a 70 43 68 65 63 6b 3b 20 20 20 20 2f 2a t *pCheck; /*
12720 20 41 6c 6c 20 43 48 45 43 4b 20 63 6f 6e 73 74 All CHECK const
12730 72 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 20 20 raints */.
12740 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
12750 20 2f 2a 20 20 20 2e 2e 2e 20 61 6c 73 6f 20 75 /* ... also u
12760 73 65 64 20 61 73 20 63 6f 6c 75 6d 6e 20 6e 61 sed as column na
12770 6d 65 20 6c 69 73 74 20 69 6e 20 61 20 56 49 45 me list in a VIE
12780 57 20 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 6d 3b W */. int tnum;
12790 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 /* R
127a0 6f 6f 74 20 42 54 72 65 65 20 70 61 67 65 20 66 oot BTree page f
127b0 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f or this table */
127c0 0a 20 20 75 33 32 20 6e 54 61 62 52 65 66 3b 20 . u32 nTabRef;
127d0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
127e0 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f r of pointers to
127f0 20 74 68 69 73 20 54 61 62 6c 65 20 2a 2f 0a 20 this Table */.
12800 20 75 33 32 20 74 61 62 46 6c 61 67 73 3b 20 20 u32 tabFlags;
12810 20 20 20 20 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 /* Mask of
12820 20 54 46 5f 2a 20 76 61 6c 75 65 73 20 2a 2f 0a TF_* values */.
12830 20 20 69 31 36 20 69 50 4b 65 79 3b 20 20 20 20 i16 iPKey;
12840 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f 74 /* If not
12850 20 6e 65 67 61 74 69 76 65 2c 20 75 73 65 20 61 negative, use a
12860 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 73 20 74 68 Col[iPKey] as th
12870 65 20 72 6f 77 69 64 20 2a 2f 0a 20 20 69 31 36 e rowid */. i16
12880 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 nCol;
12890 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
128a0 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 74 olumns in this t
128b0 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 able */. LogEst
128c0 20 6e 52 6f 77 4c 6f 67 45 73 74 3b 20 20 20 2f nRowLogEst; /
128d0 2a 20 45 73 74 69 6d 61 74 65 64 20 72 6f 77 73 * Estimated rows
128e0 20 69 6e 20 74 61 62 6c 65 20 2d 20 66 72 6f 6d in table - from
128f0 20 73 71 6c 69 74 65 5f 73 74 61 74 31 20 74 61 sqlite_stat1 ta
12900 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 ble */. LogEst
12910 73 7a 54 61 62 52 6f 77 3b 20 20 20 20 20 2f 2a szTabRow; /*
12920 20 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 20 Estimated size
12930 6f 66 20 65 61 63 68 20 74 61 62 6c 65 20 72 6f of each table ro
12940 77 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 23 69 w in bytes */.#i
12950 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
12960 4c 45 5f 43 4f 53 54 4d 55 4c 54 0a 20 20 4c 6f LE_COSTMULT. Lo
12970 67 45 73 74 20 63 6f 73 74 4d 75 6c 74 3b 20 20 gEst costMult;
12980 20 20 20 2f 2a 20 43 6f 73 74 20 6d 75 6c 74 69 /* Cost multi
12990 70 6c 69 65 72 20 66 6f 72 20 75 73 69 6e 67 20 plier for using
129a0 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 23 65 this table */.#e
129b0 6e 64 69 66 0a 20 20 75 38 20 6b 65 79 43 6f 6e ndif. u8 keyCon
129c0 66 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 f; /* W
129d0 68 61 74 20 74 6f 20 64 6f 20 69 6e 20 63 61 73 hat to do in cas
129e0 65 20 6f 66 20 75 6e 69 71 75 65 6e 65 73 73 20 e of uniqueness
129f0 63 6f 6e 66 6c 69 63 74 20 6f 6e 20 69 50 4b 65 conflict on iPKe
12a00 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c y */.#ifndef SQL
12a10 49 54 45 5f 4f 4d 49 54 5f 41 4c 54 45 52 54 41 ITE_OMIT_ALTERTA
12a20 42 4c 45 0a 20 20 69 6e 74 20 61 64 64 43 6f 6c BLE. int addCol
12a30 4f 66 66 73 65 74 3b 20 20 20 20 2f 2a 20 4f 66 Offset; /* Of
12a40 66 73 65 74 20 69 6e 20 43 52 45 41 54 45 20 54 fset in CREATE T
12a50 41 42 4c 45 20 73 74 6d 74 20 74 6f 20 61 64 64 ABLE stmt to add
12a60 20 61 20 6e 65 77 20 63 6f 6c 75 6d 6e 20 2a 2f a new column */
12a70 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
12a80 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
12a90 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 20 6e UALTABLE. int n
12aa0 4d 6f 64 75 6c 65 41 72 67 3b 20 20 20 20 20 20 ModuleArg;
12ab0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 /* Number of arg
12ac0 75 6d 65 6e 74 73 20 74 6f 20 74 68 65 20 6d 6f uments to the mo
12ad0 64 75 6c 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a dule */. char *
12ae0 2a 61 7a 4d 6f 64 75 6c 65 41 72 67 3b 20 20 2f *azModuleArg; /
12af0 2a 20 30 3a 20 6d 6f 64 75 6c 65 20 31 3a 20 73 * 0: module 1: s
12b00 63 68 65 6d 61 20 32 3a 20 76 74 61 62 20 6e 61 chema 2: vtab na
12b10 6d 65 20 33 2e 2e 2e 3a 20 61 72 67 73 20 2a 2f me 3...: args */
12b20 0a 20 20 56 54 61 62 6c 65 20 2a 70 56 54 61 62 . VTable *pVTab
12b30 6c 65 3b 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 le; /* List
12b40 6f 66 20 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 of VTable object
12b50 73 2e 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 54 s. */.#endif. T
12b60 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 65 72 rigger *pTrigger
12b70 3b 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 74 ; /* List of t
12b80 72 69 67 67 65 72 73 20 73 74 6f 72 65 64 20 69 riggers stored i
12b90 6e 20 70 53 63 68 65 6d 61 20 2a 2f 0a 20 20 53 n pSchema */. S
12ba0 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 chema *pSchema;
12bb0 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 74 68 /* Schema th
12bc0 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 69 73 at contains this
12bd0 20 74 61 62 6c 65 20 2a 2f 0a 20 20 54 61 62 6c table */. Tabl
12be0 65 20 2a 70 4e 65 78 74 5a 6f 6d 62 69 65 3b 20 e *pNextZombie;
12bf0 20 2f 2a 20 4e 65 78 74 20 6f 6e 20 74 68 65 20 /* Next on the
12c00 50 61 72 73 65 2e 70 5a 6f 6d 62 69 65 54 61 62 Parse.pZombieTab
12c10 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a list */.};../*.
12c20 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 ** Allowed value
12c30 73 20 66 6f 72 20 54 61 62 6c 65 2e 74 61 62 46 s for Table.tabF
12c40 6c 61 67 73 2e 0a 2a 2a 0a 2a 2a 20 54 46 5f 4f lags..**.** TF_O
12c50 4f 4f 48 69 64 64 65 6e 20 61 70 70 6c 69 65 73 OOHidden applies
12c60 20 74 6f 20 74 61 62 6c 65 73 20 6f 72 20 76 69 to tables or vi
12c70 65 77 20 74 68 61 74 20 68 61 76 65 20 68 69 64 ew that have hid
12c80 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 74 68 61 74 den columns that
12c90 20 61 72 65 0a 2a 2a 20 66 6f 6c 6c 6f 77 65 64 are.** followed
12ca0 20 62 79 20 6e 6f 6e 2d 68 69 64 64 65 6e 20 63 by non-hidden c
12cb0 6f 6c 75 6d 6e 73 2e 20 20 45 78 61 6d 70 6c 65 olumns. Example
12cc0 3a 20 20 22 43 52 45 41 54 45 20 56 49 52 54 55 : "CREATE VIRTU
12cd0 41 4c 20 54 41 42 4c 45 20 78 20 55 53 49 4e 47 AL TABLE x USING
12ce0 0a 2a 2a 20 76 74 61 62 31 28 61 20 48 49 44 44 .** vtab1(a HIDD
12cf0 45 4e 2c 20 62 29 3b 22 2e 20 20 53 69 6e 63 65 EN, b);". Since
12d00 20 22 62 22 20 69 73 20 61 20 6e 6f 6e 2d 68 69 "b" is a non-hi
12d10 64 64 65 6e 20 63 6f 6c 75 6d 6e 20 62 75 74 20 dden column but
12d20 22 61 22 20 69 73 20 68 69 64 64 65 6e 2c 0a 2a "a" is hidden,.*
12d30 2a 20 74 68 65 20 54 46 5f 4f 4f 4f 48 69 64 64 * the TF_OOOHidd
12d40 65 6e 20 61 74 74 72 69 62 75 74 65 20 77 6f 75 en attribute wou
12d50 6c 64 20 61 70 70 6c 79 20 69 6e 20 74 68 69 73 ld apply in this
12d60 20 63 61 73 65 2e 20 20 53 75 63 68 20 74 61 62 case. Such tab
12d70 6c 65 73 20 72 65 71 75 69 72 65 0a 2a 2a 20 73 les require.** s
12d80 70 65 63 69 61 6c 20 68 61 6e 64 6c 69 6e 67 20 pecial handling
12d90 64 75 72 69 6e 67 20 49 4e 53 45 52 54 20 70 72 during INSERT pr
12da0 6f 63 65 73 73 69 6e 67 2e 0a 2a 2f 0a 23 64 65 ocessing..*/.#de
12db0 66 69 6e 65 20 54 46 5f 52 65 61 64 6f 6e 6c 79 fine TF_Readonly
12dc0 20 20 20 20 20 20 20 20 30 78 30 30 30 31 20 20 0x0001
12dd0 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 79 20 73 /* Read-only s
12de0 79 73 74 65 6d 20 74 61 62 6c 65 20 2a 2f 0a 23 ystem table */.#
12df0 64 65 66 69 6e 65 20 54 46 5f 45 70 68 65 6d 65 define TF_Epheme
12e00 72 61 6c 20 20 20 20 20 20 20 30 78 30 30 30 32 ral 0x0002
12e10 20 20 20 20 2f 2a 20 41 6e 20 65 70 68 65 6d 65 /* An epheme
12e20 72 61 6c 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 ral table */.#de
12e30 66 69 6e 65 20 54 46 5f 48 61 73 50 72 69 6d 61 fine TF_HasPrima
12e40 72 79 4b 65 79 20 20 20 30 78 30 30 30 34 20 20 ryKey 0x0004
12e50 20 20 2f 2a 20 54 61 62 6c 65 20 68 61 73 20 61 /* Table has a
12e60 20 70 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a primary key */.
12e70 23 64 65 66 69 6e 65 20 54 46 5f 41 75 74 6f 69 #define TF_Autoi
12e80 6e 63 72 65 6d 65 6e 74 20 20 20 30 78 30 30 30 ncrement 0x000
12e90 38 20 20 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 8 /* Integer
12ea0 70 72 69 6d 61 72 79 20 6b 65 79 20 69 73 20 61 primary key is a
12eb0 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 2a 2f 0a utoincrement */.
12ec0 23 64 65 66 69 6e 65 20 54 46 5f 48 61 73 53 74 #define TF_HasSt
12ed0 61 74 31 20 20 20 20 20 20 20 20 30 78 30 30 31 at1 0x001
12ee0 30 20 20 20 20 2f 2a 20 6e 52 6f 77 4c 6f 67 45 0 /* nRowLogE
12ef0 73 74 20 73 65 74 20 66 72 6f 6d 20 73 71 6c 69 st set from sqli
12f00 74 65 5f 73 74 61 74 31 20 2a 2f 0a 23 64 65 66 te_stat1 */.#def
12f10 69 6e 65 20 54 46 5f 57 69 74 68 6f 75 74 52 6f ine TF_WithoutRo
12f20 77 69 64 20 20 20 20 30 78 30 30 32 30 20 20 20 wid 0x0020
12f30 20 2f 2a 20 4e 6f 20 72 6f 77 69 64 2e 20 20 50 /* No rowid. P
12f40 52 49 4d 41 52 59 20 4b 45 59 20 69 73 20 74 68 RIMARY KEY is th
12f50 65 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 6e 65 e key */.#define
12f60 20 54 46 5f 4e 6f 56 69 73 69 62 6c 65 52 6f 77 TF_NoVisibleRow
12f70 69 64 20 20 30 78 30 30 34 30 20 20 20 20 2f 2a id 0x0040 /*
12f80 20 4e 6f 20 75 73 65 72 2d 76 69 73 69 62 6c 65 No user-visible
12f90 20 22 72 6f 77 69 64 22 20 63 6f 6c 75 6d 6e 20 "rowid" column
12fa0 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 4f 4f */.#define TF_OO
12fb0 4f 48 69 64 64 65 6e 20 20 20 20 20 20 20 30 78 OHidden 0x
12fc0 30 30 38 30 20 20 20 20 2f 2a 20 4f 75 74 2d 6f 0080 /* Out-o
12fd0 66 2d 4f 72 64 65 72 20 68 69 64 64 65 6e 20 63 f-Order hidden c
12fe0 6f 6c 75 6d 6e 73 20 2a 2f 0a 23 64 65 66 69 6e olumns */.#defin
12ff0 65 20 54 46 5f 53 74 61 74 73 55 73 65 64 20 20 e TF_StatsUsed
13000 20 20 20 20 20 30 78 30 31 30 30 20 20 20 20 2f 0x0100 /
13010 2a 20 51 75 65 72 79 20 70 6c 61 6e 6e 65 72 20 * Query planner
13020 64 65 63 69 73 69 6f 6e 73 20 61 66 66 65 63 74 decisions affect
13030 65 64 20 62 79 0a 20 20 20 20 20 20 20 20 20 20 ed by.
13040 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13050 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 49 6e ** In
13060 64 65 78 2e 61 69 52 6f 77 4c 6f 67 45 73 74 5b dex.aiRowLogEst[
13070 5d 20 76 61 6c 75 65 73 20 2a 2f 0a 23 64 65 66 ] values */.#def
13080 69 6e 65 20 54 46 5f 48 61 73 4e 6f 74 4e 75 6c ine TF_HasNotNul
13090 6c 20 20 20 20 20 20 30 78 30 32 30 30 20 20 20 l 0x0200
130a0 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 4e 4f 54 /* Contains NOT
130b0 20 4e 55 4c 4c 20 63 6f 6e 73 74 72 61 69 6e 74 NULL constraint
130c0 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 65 73 74 s */../*.** Test
130d0 20 74 6f 20 73 65 65 20 77 68 65 74 68 65 72 20 to see whether
130e0 6f 72 20 6e 6f 74 20 61 20 74 61 62 6c 65 20 69 or not a table i
130f0 73 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 6c s a virtual tabl
13100 65 2e 20 20 54 68 69 73 20 69 73 0a 2a 2a 20 64 e. This is.** d
13110 6f 6e 65 20 61 73 20 61 20 6d 61 63 72 6f 20 73 one as a macro s
13120 6f 20 74 68 61 74 20 69 74 20 77 69 6c 6c 20 62 o that it will b
13130 65 20 6f 70 74 69 6d 69 7a 65 64 20 6f 75 74 20 e optimized out
13140 77 68 65 6e 20 76 69 72 74 75 61 6c 0a 2a 2a 20 when virtual.**
13150 74 61 62 6c 65 20 73 75 70 70 6f 72 74 20 69 73 table support is
13160 20 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 74 68 omitted from th
13170 65 20 62 75 69 6c 64 2e 0a 2a 2f 0a 23 69 66 6e e build..*/.#ifn
13180 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
13190 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 23 20 20 VIRTUALTABLE.#
131a0 64 65 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c define IsVirtual
131b0 28 58 29 20 20 20 20 20 20 28 28 58 29 2d 3e 6e (X) ((X)->n
131c0 4d 6f 64 75 6c 65 41 72 67 29 0a 23 65 6c 73 65 ModuleArg).#else
131d0 0a 23 20 20 64 65 66 69 6e 65 20 49 73 56 69 72 .# define IsVir
131e0 74 75 61 6c 28 58 29 20 20 20 20 20 20 30 0a 23 tual(X) 0.#
131f0 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 endif../*.** Mac
13200 72 6f 73 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 ros to determine
13210 20 69 66 20 61 20 63 6f 6c 75 6d 6e 20 69 73 20 if a column is
13220 68 69 64 64 65 6e 2e 20 20 49 73 4f 72 64 69 6e hidden. IsOrdin
13230 61 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 aryHiddenColumn(
13240 29 0a 2a 2a 20 6f 6e 6c 79 20 77 6f 72 6b 73 20 ).** only works
13250 66 6f 72 20 6e 6f 6e 2d 76 69 72 74 75 61 6c 20 for non-virtual
13260 74 61 62 6c 65 73 20 28 6f 72 64 69 6e 61 72 79 tables (ordinary
13270 20 74 61 62 6c 65 73 20 61 6e 64 20 76 69 65 77 tables and view
13280 73 29 20 61 6e 64 20 69 73 0a 2a 2a 20 61 6c 77 s) and is.** alw
13290 61 79 73 20 66 61 6c 73 65 20 75 6e 6c 65 73 73 ays false unless
132a0 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 48 SQLITE_ENABLE_H
132b0 49 44 44 45 4e 5f 43 4f 4c 55 4d 4e 53 20 69 73 IDDEN_COLUMNS is
132c0 20 64 65 66 69 6e 65 64 2e 20 20 54 68 65 0a 2a defined. The.*
132d0 2a 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e * IsHiddenColumn
132e0 28 29 20 6d 61 63 72 6f 20 69 73 20 67 65 6e 65 () macro is gene
132f0 72 61 6c 20 70 75 72 70 6f 73 65 2e 0a 2a 2f 0a ral purpose..*/.
13300 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
13310 54 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 45 4e TE_ENABLE_HIDDEN
13320 5f 43 4f 4c 55 4d 4e 53 29 0a 23 20 20 64 65 66 _COLUMNS).# def
13330 69 6e 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 ine IsHiddenColu
13340 6d 6e 28 58 29 20 20 20 20 20 20 20 20 20 28 28 mn(X) ((
13350 28 58 29 2d 3e 63 6f 6c 46 6c 61 67 73 20 26 20 (X)->colFlags &
13360 43 4f 4c 46 4c 41 47 5f 48 49 44 44 45 4e 29 21 COLFLAG_HIDDEN)!
13370 3d 30 29 0a 23 20 20 64 65 66 69 6e 65 20 49 73 =0).# define Is
13380 4f 72 64 69 6e 61 72 79 48 69 64 64 65 6e 43 6f OrdinaryHiddenCo
13390 6c 75 6d 6e 28 58 29 20 28 28 28 58 29 2d 3e 63 lumn(X) (((X)->c
133a0 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 olFlags & COLFLA
133b0 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 65 G_HIDDEN)!=0).#e
133c0 6c 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c lif !defined(SQL
133d0 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
133e0 54 41 42 4c 45 29 0a 23 20 20 64 65 66 69 6e 65 TABLE).# define
133f0 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 IsHiddenColumn(
13400 58 29 20 20 20 20 20 20 20 20 20 28 28 28 58 29 X) (((X)
13410 2d 3e 63 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c ->colFlags & COL
13420 46 4c 41 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 FLAG_HIDDEN)!=0)
13430 0a 23 20 20 64 65 66 69 6e 65 20 49 73 4f 72 64 .# define IsOrd
13440 69 6e 61 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d inaryHiddenColum
13450 6e 28 58 29 20 30 0a 23 65 6c 73 65 0a 23 20 20 n(X) 0.#else.#
13460 64 65 66 69 6e 65 20 49 73 48 69 64 64 65 6e 43 define IsHiddenC
13470 6f 6c 75 6d 6e 28 58 29 20 20 20 20 20 20 20 20 olumn(X)
13480 20 30 0a 23 20 20 64 65 66 69 6e 65 20 49 73 4f 0.# define IsO
13490 72 64 69 6e 61 72 79 48 69 64 64 65 6e 43 6f 6c rdinaryHiddenCol
134a0 75 6d 6e 28 58 29 20 30 0a 23 65 6e 64 69 66 0a umn(X) 0.#endif.
134b0 0a 0a 2f 2a 20 44 6f 65 73 20 74 68 65 20 74 61 ../* Does the ta
134c0 62 6c 65 20 68 61 76 65 20 61 20 72 6f 77 69 64 ble have a rowid
134d0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 48 61 73 52 */.#define HasR
134e0 6f 77 69 64 28 58 29 20 20 20 20 20 28 28 28 58 owid(X) (((X
134f0 29 2d 3e 74 61 62 46 6c 61 67 73 20 26 20 54 46 )->tabFlags & TF
13500 5f 57 69 74 68 6f 75 74 52 6f 77 69 64 29 3d 3d _WithoutRowid)==
13510 30 29 0a 23 64 65 66 69 6e 65 20 56 69 73 69 62 0).#define Visib
13520 6c 65 52 6f 77 69 64 28 58 29 20 28 28 28 58 29 leRowid(X) (((X)
13530 2d 3e 74 61 62 46 6c 61 67 73 20 26 20 54 46 5f ->tabFlags & TF_
13540 4e 6f 56 69 73 69 62 6c 65 52 6f 77 69 64 29 3d NoVisibleRowid)=
13550 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 =0)../*.** Each
13560 66 6f 72 65 69 67 6e 20 6b 65 79 20 63 6f 6e 73 foreign key cons
13570 74 72 61 69 6e 74 20 69 73 20 61 6e 20 69 6e 73 traint is an ins
13580 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
13590 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
135a0 2e 0a 2a 2a 0a 2a 2a 20 41 20 66 6f 72 65 69 67 ..**.** A foreig
135b0 6e 20 6b 65 79 20 69 73 20 61 73 73 6f 63 69 61 n key is associa
135c0 74 65 64 20 77 69 74 68 20 74 77 6f 20 74 61 62 ted with two tab
135d0 6c 65 73 2e 20 20 54 68 65 20 22 66 72 6f 6d 22 les. The "from"
135e0 20 74 61 62 6c 65 20 69 73 0a 2a 2a 20 74 68 65 table is.** the
135f0 20 74 61 62 6c 65 20 74 68 61 74 20 63 6f 6e 74 table that cont
13600 61 69 6e 73 20 74 68 65 20 52 45 46 45 52 45 4e ains the REFEREN
13610 43 45 53 20 63 6c 61 75 73 65 20 74 68 61 74 20 CES clause that
13620 63 72 65 61 74 65 73 20 74 68 65 20 66 6f 72 65 creates the fore
13630 69 67 6e 0a 2a 2a 20 6b 65 79 2e 20 20 54 68 65 ign.** key. The
13640 20 22 74 6f 22 20 74 61 62 6c 65 20 69 73 20 74 "to" table is t
13650 68 65 20 74 61 62 6c 65 20 74 68 61 74 20 69 73 he table that is
13660 20 6e 61 6d 65 64 20 69 6e 20 74 68 65 20 52 45 named in the RE
13670 46 45 52 45 4e 43 45 53 20 63 6c 61 75 73 65 2e FERENCES clause.
13680 0a 2a 2a 20 43 6f 6e 73 69 64 65 72 20 74 68 69 .** Consider thi
13690 73 20 65 78 61 6d 70 6c 65 3a 0a 2a 2a 0a 2a 2a s example:.**.**
136a0 20 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c CREATE TABL
136b0 45 20 65 78 31 28 0a 2a 2a 20 20 20 20 20 20 20 E ex1(.**
136c0 61 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 a INTEGER PRIMAR
136d0 59 20 4b 45 59 2c 0a 2a 2a 20 20 20 20 20 20 20 Y KEY,.**
136e0 62 20 49 4e 54 45 47 45 52 20 43 4f 4e 53 54 52 b INTEGER CONSTR
136f0 41 49 4e 54 20 66 6b 31 20 52 45 46 45 52 45 4e AINT fk1 REFEREN
13700 43 45 53 20 65 78 32 28 78 29 0a 2a 2a 20 20 20 CES ex2(x).**
13710 20 20 29 3b 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 66 );.**.** For f
13720 6f 72 65 69 67 6e 20 6b 65 79 20 22 66 6b 31 22 oreign key "fk1"
13730 2c 20 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 , the from-table
13740 20 69 73 20 22 65 78 31 22 20 61 6e 64 20 74 68 is "ex1" and th
13750 65 20 74 6f 2d 74 61 62 6c 65 20 69 73 20 22 65 e to-table is "e
13760 78 32 22 2e 0a 2a 2a 20 45 71 75 69 76 61 6c 65 x2"..** Equivale
13770 6e 74 20 6e 61 6d 65 73 3a 0a 2a 2a 0a 2a 2a 20 nt names:.**.**
13780 20 20 20 20 66 72 6f 6d 2d 74 61 62 6c 65 20 3d from-table =
13790 3d 20 63 68 69 6c 64 2d 74 61 62 6c 65 0a 2a 2a = child-table.**
137a0 20 20 20 20 20 20 20 74 6f 2d 74 61 62 6c 65 20 to-table
137b0 3d 3d 20 70 61 72 65 6e 74 2d 74 61 62 6c 65 0a == parent-table.
137c0 2a 2a 0a 2a 2a 20 45 61 63 68 20 52 45 46 45 52 **.** Each REFER
137d0 45 4e 43 45 53 20 63 6c 61 75 73 65 20 67 65 6e ENCES clause gen
137e0 65 72 61 74 65 73 20 61 6e 20 69 6e 73 74 61 6e erates an instan
137f0 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ce of the follow
13800 69 6e 67 20 73 74 72 75 63 74 75 72 65 0a 2a 2a ing structure.**
13810 20 77 68 69 63 68 20 69 73 20 61 74 74 61 63 68 which is attach
13820 65 64 20 74 6f 20 74 68 65 20 66 72 6f 6d 2d 74 ed to the from-t
13830 61 62 6c 65 2e 20 20 54 68 65 20 74 6f 2d 74 61 able. The to-ta
13840 62 6c 65 20 6e 65 65 64 20 6e 6f 74 20 65 78 69 ble need not exi
13850 73 74 20 77 68 65 6e 0a 2a 2a 20 74 68 65 20 66 st when.** the f
13860 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 63 72 65 rom-table is cre
13870 61 74 65 64 2e 20 20 54 68 65 20 65 78 69 73 74 ated. The exist
13880 65 6e 63 65 20 6f 66 20 74 68 65 20 74 6f 2d 74 ence of the to-t
13890 61 62 6c 65 20 69 73 20 6e 6f 74 20 63 68 65 63 able is not chec
138a0 6b 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6c ked..**.** The l
138b0 69 73 74 20 6f 66 20 61 6c 6c 20 70 61 72 65 6e ist of all paren
138c0 74 73 20 66 6f 72 20 63 68 69 6c 64 20 54 61 62 ts for child Tab
138d0 6c 65 20 58 20 69 73 20 68 65 6c 64 20 61 74 20 le X is held at
138e0 58 2e 70 46 4b 65 79 2e 0a 2a 2a 0a 2a 2a 20 41 X.pFKey..**.** A
138f0 20 6c 69 73 74 20 6f 66 20 61 6c 6c 20 63 68 69 list of all chi
13900 6c 64 72 65 6e 20 66 6f 72 20 61 20 74 61 62 6c ldren for a tabl
13910 65 20 6e 61 6d 65 64 20 5a 20 28 77 68 69 63 68 e named Z (which
13920 20 6d 69 67 68 74 20 6e 6f 74 20 65 76 65 6e 20 might not even
13930 65 78 69 73 74 29 0a 2a 2a 20 69 73 20 68 65 6c exist).** is hel
13940 64 20 69 6e 20 53 63 68 65 6d 61 2e 66 6b 65 79 d in Schema.fkey
13950 48 61 73 68 20 77 69 74 68 20 61 20 68 61 73 68 Hash with a hash
13960 20 6b 65 79 20 6f 66 20 5a 2e 0a 2a 2f 0a 73 74 key of Z..*/.st
13970 72 75 63 74 20 46 4b 65 79 20 7b 0a 20 20 54 61 ruct FKey {. Ta
13980 62 6c 65 20 2a 70 46 72 6f 6d 3b 20 20 20 20 20 ble *pFrom;
13990 2f 2a 20 54 61 62 6c 65 20 63 6f 6e 74 61 69 6e /* Table contain
139a0 69 6e 67 20 74 68 65 20 52 45 46 45 52 45 4e 43 ing the REFERENC
139b0 45 53 20 63 6c 61 75 73 65 20 28 61 6b 61 3a 20 ES clause (aka:
139c0 43 68 69 6c 64 29 20 2a 2f 0a 20 20 46 4b 65 79 Child) */. FKey
139d0 20 2a 70 4e 65 78 74 46 72 6f 6d 3b 20 20 2f 2a *pNextFrom; /*
139e0 20 4e 65 78 74 20 46 4b 65 79 20 77 69 74 68 20 Next FKey with
139f0 74 68 65 20 73 61 6d 65 20 69 6e 20 70 46 72 6f the same in pFro
13a00 6d 2e 20 4e 65 78 74 20 70 61 72 65 6e 74 20 6f m. Next parent o
13a10 66 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 63 68 61 f pFrom */. cha
13a20 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20 20 20 2f r *zTo; /
13a30 2a 20 4e 61 6d 65 20 6f 66 20 74 61 62 6c 65 20 * Name of table
13a40 74 68 61 74 20 74 68 65 20 6b 65 79 20 70 6f 69 that the key poi
13a50 6e 74 73 20 74 6f 20 28 61 6b 61 3a 20 50 61 72 nts to (aka: Par
13a60 65 6e 74 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a ent) */. FKey *
13a70 70 4e 65 78 74 54 6f 3b 20 20 20 20 2f 2a 20 4e pNextTo; /* N
13a80 65 78 74 20 77 69 74 68 20 74 68 65 20 73 61 6d ext with the sam
13a90 65 20 7a 54 6f 2e 20 4e 65 78 74 20 63 68 69 6c e zTo. Next chil
13aa0 64 20 6f 66 20 7a 54 6f 2e 20 2a 2f 0a 20 20 46 d of zTo. */. F
13ab0 4b 65 79 20 2a 70 50 72 65 76 54 6f 3b 20 20 20 Key *pPrevTo;
13ac0 20 2f 2a 20 50 72 65 76 69 6f 75 73 20 77 69 74 /* Previous wit
13ad0 68 20 74 68 65 20 73 61 6d 65 20 7a 54 6f 20 2a h the same zTo *
13ae0 2f 0a 20 20 69 6e 74 20 6e 43 6f 6c 3b 20 20 20 /. int nCol;
13af0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
13b00 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
13b10 69 73 20 6b 65 79 20 2a 2f 0a 20 20 2f 2a 20 45 is key */. /* E
13b20 56 3a 20 52 2d 33 30 33 32 33 2d 32 31 39 31 37 V: R-30323-21917
13b30 20 2a 2f 0a 20 20 75 38 20 69 73 44 65 66 65 72 */. u8 isDefer
13b40 72 65 64 3b 20 20 20 20 20 20 20 2f 2a 20 54 72 red; /* Tr
13b50 75 65 20 69 66 20 63 6f 6e 73 74 72 61 69 6e 74 ue if constraint
13b60 20 63 68 65 63 6b 69 6e 67 20 69 73 20 64 65 66 checking is def
13b70 65 72 72 65 64 20 74 69 6c 6c 20 43 4f 4d 4d 49 erred till COMMI
13b80 54 20 2a 2f 0a 20 20 75 38 20 61 41 63 74 69 6f T */. u8 aActio
13b90 6e 5b 32 5d 3b 20 20 20 20 20 20 20 20 2f 2a 20 n[2]; /*
13ba0 4f 4e 20 44 45 4c 45 54 45 20 61 6e 64 20 4f 4e ON DELETE and ON
13bb0 20 55 50 44 41 54 45 20 61 63 74 69 6f 6e 73 2c UPDATE actions,
13bc0 20 72 65 73 70 65 63 74 69 76 65 6c 79 20 2a 2f respectively */
13bd0 0a 20 20 54 72 69 67 67 65 72 20 2a 61 70 54 72 . Trigger *apTr
13be0 69 67 67 65 72 5b 32 5d 3b 2f 2a 20 54 72 69 67 igger[2];/* Trig
13bf0 67 65 72 73 20 66 6f 72 20 61 41 63 74 69 6f 6e gers for aAction
13c00 5b 5d 20 61 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 [] actions */.
13c10 73 74 72 75 63 74 20 73 43 6f 6c 4d 61 70 20 7b struct sColMap {
13c20 20 20 20 20 20 20 2f 2a 20 4d 61 70 70 69 6e 67 /* Mapping
13c30 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 70 of columns in p
13c40 46 72 6f 6d 20 74 6f 20 63 6f 6c 75 6d 6e 73 20 From to columns
13c50 69 6e 20 7a 54 6f 20 2a 2f 0a 20 20 20 20 69 6e in zTo */. in
13c60 74 20 69 46 72 6f 6d 3b 20 20 20 20 20 20 20 20 t iFrom;
13c70 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 6f 66 20 /* Index of
13c80 63 6f 6c 75 6d 6e 20 69 6e 20 70 46 72 6f 6d 20 column in pFrom
13c90 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 43 6f */. char *zCo
13ca0 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 l; /*
13cb0 4e 61 6d 65 20 6f 66 20 63 6f 6c 75 6d 6e 20 69 Name of column i
13cc0 6e 20 7a 54 6f 2e 20 20 49 66 20 4e 55 4c 4c 20 n zTo. If NULL
13cd0 75 73 65 20 50 52 49 4d 41 52 59 20 4b 45 59 20 use PRIMARY KEY
13ce0 2a 2f 0a 20 20 7d 20 61 43 6f 6c 5b 31 5d 3b 20 */. } aCol[1];
13cf0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e /* On
13d00 65 20 65 6e 74 72 79 20 66 6f 72 20 65 61 63 68 e entry for each
13d10 20 6f 66 20 6e 43 6f 6c 20 63 6f 6c 75 6d 6e 73 of nCol columns
13d20 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 51 */.};../*.** SQ
13d30 4c 69 74 65 20 73 75 70 70 6f 72 74 73 20 6d 61 Lite supports ma
13d40 6e 79 20 64 69 66 66 65 72 65 6e 74 20 77 61 79 ny different way
13d50 73 20 74 6f 20 72 65 73 6f 6c 76 65 20 61 20 63 s to resolve a c
13d60 6f 6e 73 74 72 61 69 6e 74 0a 2a 2a 20 65 72 72 onstraint.** err
13d70 6f 72 2e 20 20 52 4f 4c 4c 42 41 43 4b 20 70 72 or. ROLLBACK pr
13d80 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 ocessing means t
13d90 68 61 74 20 61 20 63 6f 6e 73 74 72 61 69 6e 74 hat a constraint
13da0 20 76 69 6f 6c 61 74 69 6f 6e 0a 2a 2a 20 63 61 violation.** ca
13db0 75 73 65 73 20 74 68 65 20 6f 70 65 72 61 74 69 uses the operati
13dc0 6f 6e 20 69 6e 20 70 72 6f 63 65 73 73 20 74 6f on in process to
13dd0 20 66 61 69 6c 20 61 6e 64 20 66 6f 72 20 74 68 fail and for th
13de0 65 20 63 75 72 72 65 6e 74 20 74 72 61 6e 73 61 e current transa
13df0 63 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 72 ction.** to be r
13e00 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 41 42 4f olled back. ABO
13e10 52 54 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 RT processing me
13e20 61 6e 73 20 74 68 65 20 6f 70 65 72 61 74 69 6f ans the operatio
13e30 6e 20 69 6e 20 70 72 6f 63 65 73 73 0a 2a 2a 20 n in process.**
13e40 66 61 69 6c 73 20 61 6e 64 20 61 6e 79 20 70 72 fails and any pr
13e50 69 6f 72 20 63 68 61 6e 67 65 73 20 66 72 6f 6d ior changes from
13e60 20 74 68 61 74 20 6f 6e 65 20 6f 70 65 72 61 74 that one operat
13e70 69 6f 6e 20 61 72 65 20 62 61 63 6b 65 64 20 6f ion are backed o
13e80 75 74 2c 0a 2a 2a 20 62 75 74 20 74 68 65 20 74 ut,.** but the t
13e90 72 61 6e 73 61 63 74 69 6f 6e 20 69 73 20 6e 6f ransaction is no
13ea0 74 20 72 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 t rolled back.
13eb0 46 41 49 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 FAIL processing
13ec0 6d 65 61 6e 73 20 74 68 61 74 0a 2a 2a 20 74 68 means that.** th
13ed0 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 e operation in p
13ee0 72 6f 67 72 65 73 73 20 73 74 6f 70 73 20 61 6e rogress stops an
13ef0 64 20 72 65 74 75 72 6e 73 20 61 6e 20 65 72 72 d returns an err
13f00 6f 72 20 63 6f 64 65 2e 20 20 42 75 74 20 70 72 or code. But pr
13f10 69 6f 72 0a 2a 2a 20 63 68 61 6e 67 65 73 20 64 ior.** changes d
13f20 75 65 20 74 6f 20 74 68 65 20 73 61 6d 65 20 6f ue to the same o
13f30 70 65 72 61 74 69 6f 6e 20 61 72 65 20 6e 6f 74 peration are not
13f40 20 62 61 63 6b 65 64 20 6f 75 74 20 61 6e 64 20 backed out and
13f50 6e 6f 20 72 6f 6c 6c 62 61 63 6b 0a 2a 2a 20 6f no rollback.** o
13f60 63 63 75 72 73 2e 20 20 49 47 4e 4f 52 45 20 6d ccurs. IGNORE m
13f70 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 70 61 eans that the pa
13f80 72 74 69 63 75 6c 61 72 20 72 6f 77 20 74 68 61 rticular row tha
13f90 74 20 63 61 75 73 65 64 20 74 68 65 20 63 6f 6e t caused the con
13fa0 73 74 72 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 straint.** error
13fb0 20 69 73 20 6e 6f 74 20 69 6e 73 65 72 74 65 64 is not inserted
13fc0 20 6f 72 20 75 70 64 61 74 65 64 2e 20 20 50 72 or updated. Pr
13fd0 6f 63 65 73 73 69 6e 67 20 63 6f 6e 74 69 6e 75 ocessing continu
13fe0 65 73 20 61 6e 64 20 6e 6f 20 65 72 72 6f 72 0a es and no error.
13ff0 2a 2a 20 69 73 20 72 65 74 75 72 6e 65 64 2e 20 ** is returned.
14000 20 52 45 50 4c 41 43 45 20 6d 65 61 6e 73 20 74 REPLACE means t
14010 68 61 74 20 70 72 65 65 78 69 73 74 69 6e 67 20 hat preexisting
14020 64 61 74 61 62 61 73 65 20 72 6f 77 73 20 74 68 database rows th
14030 61 74 20 63 61 75 73 65 64 0a 2a 2a 20 61 20 55 at caused.** a U
14040 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 NIQUE constraint
14050 20 76 69 6f 6c 61 74 69 6f 6e 20 61 72 65 20 72 violation are r
14060 65 6d 6f 76 65 64 20 73 6f 20 74 68 61 74 20 74 emoved so that t
14070 68 65 20 6e 65 77 20 69 6e 73 65 72 74 20 6f 72 he new insert or
14080 0a 2a 2a 20 75 70 64 61 74 65 20 63 61 6e 20 70 .** update can p
14090 72 6f 63 65 65 64 2e 20 20 50 72 6f 63 65 73 73 roceed. Process
140a0 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e ing continues an
140b0 64 20 6e 6f 20 65 72 72 6f 72 20 69 73 20 72 65 d no error is re
140c0 70 6f 72 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 52 45 ported..**.** RE
140d0 53 54 52 49 43 54 2c 20 53 45 54 4e 55 4c 4c 2c STRICT, SETNULL,
140e0 20 61 6e 64 20 43 41 53 43 41 44 45 20 61 63 74 and CASCADE act
140f0 69 6f 6e 73 20 61 70 70 6c 79 20 6f 6e 6c 79 20 ions apply only
14100 74 6f 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 2e to foreign keys.
14110 0a 2a 2a 20 52 45 53 54 52 49 43 54 20 69 73 20 .** RESTRICT is
14120 74 68 65 20 73 61 6d 65 20 61 73 20 41 42 4f 52 the same as ABOR
14130 54 20 66 6f 72 20 49 4d 4d 45 44 49 41 54 45 20 T for IMMEDIATE
14140 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 61 6e 64 foreign keys and
14150 20 74 68 65 0a 2a 2a 20 73 61 6d 65 20 61 73 20 the.** same as
14160 52 4f 4c 4c 42 41 43 4b 20 66 6f 72 20 44 45 46 ROLLBACK for DEF
14170 45 52 52 45 44 20 6b 65 79 73 2e 20 20 53 45 54 ERRED keys. SET
14180 4e 55 4c 4c 20 6d 65 61 6e 73 20 74 68 61 74 20 NULL means that
14190 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b the foreign.** k
141a0 65 79 20 69 73 20 73 65 74 20 74 6f 20 4e 55 4c ey is set to NUL
141b0 4c 2e 20 20 43 41 53 43 41 44 45 20 6d 65 61 6e L. CASCADE mean
141c0 73 20 74 68 61 74 20 61 20 44 45 4c 45 54 45 20 s that a DELETE
141d0 6f 72 20 55 50 44 41 54 45 20 6f 66 20 74 68 65 or UPDATE of the
141e0 0a 2a 2a 20 72 65 66 65 72 65 6e 63 65 64 20 74 .** referenced t
141f0 61 62 6c 65 20 72 6f 77 20 69 73 20 70 72 6f 70 able row is prop
14200 61 67 61 74 65 64 20 69 6e 74 6f 20 74 68 65 20 agated into the
14210 72 6f 77 20 74 68 61 74 20 68 6f 6c 64 73 20 74 row that holds t
14220 68 65 0a 2a 2a 20 66 6f 72 65 69 67 6e 20 6b 65 he.** foreign ke
14230 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c y..**.** The fol
14240 6c 6f 77 69 6e 67 20 73 79 6d 62 6f 6c 69 63 20 lowing symbolic
14250 76 61 6c 75 65 73 20 61 72 65 20 75 73 65 64 20 values are used
14260 74 6f 20 72 65 63 6f 72 64 20 77 68 69 63 68 20 to record which
14270 74 79 70 65 0a 2a 2a 20 6f 66 20 61 63 74 69 6f type.** of actio
14280 6e 20 74 6f 20 74 61 6b 65 2e 0a 2a 2f 0a 23 64 n to take..*/.#d
14290 65 66 69 6e 65 20 4f 45 5f 4e 6f 6e 65 20 20 20 efine OE_None
142a0 20 20 30 20 20 20 2f 2a 20 54 68 65 72 65 20 69 0 /* There i
142b0 73 20 6e 6f 20 63 6f 6e 73 74 72 61 69 6e 74 20 s no constraint
142c0 74 6f 20 63 68 65 63 6b 20 2a 2f 0a 23 64 65 66 to check */.#def
142d0 69 6e 65 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 ine OE_Rollback
142e0 31 20 20 20 2f 2a 20 46 61 69 6c 20 74 68 65 20 1 /* Fail the
142f0 6f 70 65 72 61 74 69 6f 6e 20 61 6e 64 20 72 6f operation and ro
14300 6c 6c 62 61 63 6b 20 74 68 65 20 74 72 61 6e 73 llback the trans
14310 61 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e action */.#defin
14320 65 20 4f 45 5f 41 62 6f 72 74 20 20 20 20 32 20 e OE_Abort 2
14330 20 20 2f 2a 20 42 61 63 6b 20 6f 75 74 20 63 68 /* Back out ch
14340 61 6e 67 65 73 20 62 75 74 20 64 6f 20 6e 6f 20 anges but do no
14350 72 6f 6c 6c 62 61 63 6b 20 74 72 61 6e 73 61 63 rollback transac
14360 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
14370 4f 45 5f 46 61 69 6c 20 20 20 20 20 33 20 20 20 OE_Fail 3
14380 2f 2a 20 53 74 6f 70 20 74 68 65 20 6f 70 65 72 /* Stop the oper
14390 61 74 69 6f 6e 20 62 75 74 20 6c 65 61 76 65 20 ation but leave
143a0 61 6c 6c 20 70 72 69 6f 72 20 63 68 61 6e 67 65 all prior change
143b0 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f s */.#define OE_
143c0 49 67 6e 6f 72 65 20 20 20 34 20 20 20 2f 2a 20 Ignore 4 /*
143d0 49 67 6e 6f 72 65 20 74 68 65 20 65 72 72 6f 72 Ignore the error
143e0 2e 20 44 6f 20 6e 6f 74 20 64 6f 20 74 68 65 20 . Do not do the
143f0 49 4e 53 45 52 54 20 6f 72 20 55 50 44 41 54 45 INSERT or UPDATE
14400 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 */.#define OE_R
14410 65 70 6c 61 63 65 20 20 35 20 20 20 2f 2a 20 44 eplace 5 /* D
14420 65 6c 65 74 65 20 65 78 69 73 74 69 6e 67 20 72 elete existing r
14430 65 63 6f 72 64 2c 20 74 68 65 6e 20 64 6f 20 49 ecord, then do I
14440 4e 53 45 52 54 20 6f 72 20 55 50 44 41 54 45 20 NSERT or UPDATE
14450 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 */..#define OE_R
14460 65 73 74 72 69 63 74 20 36 20 20 20 2f 2a 20 4f estrict 6 /* O
14470 45 5f 41 62 6f 72 74 20 66 6f 72 20 49 4d 4d 45 E_Abort for IMME
14480 44 49 41 54 45 2c 20 4f 45 5f 52 6f 6c 6c 62 61 DIATE, OE_Rollba
14490 63 6b 20 66 6f 72 20 44 45 46 45 52 52 45 44 20 ck for DEFERRED
144a0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 */.#define OE_Se
144b0 74 4e 75 6c 6c 20 20 37 20 20 20 2f 2a 20 53 65 tNull 7 /* Se
144c0 74 20 74 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 t the foreign ke
144d0 79 20 76 61 6c 75 65 20 74 6f 20 4e 55 4c 4c 20 y value to NULL
144e0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 */.#define OE_Se
144f0 74 44 66 6c 74 20 20 38 20 20 20 2f 2a 20 53 65 tDflt 8 /* Se
14500 74 20 74 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 t the foreign ke
14510 79 20 76 61 6c 75 65 20 74 6f 20 69 74 73 20 64 y value to its d
14520 65 66 61 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e efault */.#defin
14530 65 20 4f 45 5f 43 61 73 63 61 64 65 20 20 39 20 e OE_Cascade 9
14540 20 20 2f 2a 20 43 61 73 63 61 64 65 20 74 68 65 /* Cascade the
14550 20 63 68 61 6e 67 65 73 20 2a 2f 0a 0a 23 64 65 changes */..#de
14560 66 69 6e 65 20 4f 45 5f 44 65 66 61 75 6c 74 20 fine OE_Default
14570 20 31 30 20 20 2f 2a 20 44 6f 20 77 68 61 74 65 10 /* Do whate
14580 76 65 72 20 74 68 65 20 64 65 66 61 75 6c 74 20 ver the default
14590 61 63 74 69 6f 6e 20 69 73 20 2a 2f 0a 0a 0a 2f action is */.../
145a0 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
145b0 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
145c0 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 70 g structure is p
145d0 61 73 73 65 64 20 61 73 20 74 68 65 20 66 69 72 assed as the fir
145e0 73 74 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 74 st.** argument t
145f0 6f 20 73 71 6c 69 74 65 33 56 64 62 65 4b 65 79 o sqlite3VdbeKey
14600 43 6f 6d 70 61 72 65 20 61 6e 64 20 69 73 20 75 Compare and is u
14610 73 65 64 20 74 6f 20 63 6f 6e 74 72 6f 6c 20 74 sed to control t
14620 68 65 0a 2a 2a 20 63 6f 6d 70 61 72 69 73 6f 6e he.** comparison
14630 20 6f 66 20 74 68 65 20 74 77 6f 20 69 6e 64 65 of the two inde
14640 78 20 6b 65 79 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f x keys..**.** No
14650 74 65 20 74 68 61 74 20 61 53 6f 72 74 4f 72 64 te that aSortOrd
14660 65 72 5b 5d 20 61 6e 64 20 61 43 6f 6c 6c 5b 5d er[] and aColl[]
14670 20 68 61 76 65 20 6e 46 69 65 6c 64 2b 31 20 73 have nField+1 s
14680 6c 6f 74 73 2e 20 20 54 68 65 72 65 0a 2a 2a 20 lots. There.**
14690 61 72 65 20 6e 46 69 65 6c 64 20 73 6c 6f 74 73 are nField slots
146a0 20 66 6f 72 20 74 68 65 20 63 6f 6c 75 6d 6e 73 for the columns
146b0 20 6f 66 20 61 6e 20 69 6e 64 65 78 20 74 68 65 of an index the
146c0 6e 20 6f 6e 65 20 65 78 74 72 61 20 73 6c 6f 74 n one extra slot
146d0 0a 2a 2a 20 66 6f 72 20 74 68 65 20 72 6f 77 69 .** for the rowi
146e0 64 20 61 74 20 74 68 65 20 65 6e 64 2e 0a 2a 2f d at the end..*/
146f0 0a 73 74 72 75 63 74 20 4b 65 79 49 6e 66 6f 20 .struct KeyInfo
14700 7b 0a 20 20 75 33 32 20 6e 52 65 66 3b 20 20 20 {. u32 nRef;
14710 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
14720 72 20 6f 66 20 72 65 66 65 72 65 6e 63 65 73 20 r of references
14730 74 6f 20 74 68 69 73 20 4b 65 79 49 6e 66 6f 20 to this KeyInfo
14740 6f 62 6a 65 63 74 20 2a 2f 0a 20 20 75 38 20 65 object */. u8 e
14750 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
14760 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 /* Text encoding
14770 20 2d 20 6f 6e 65 20 6f 66 20 74 68 65 20 53 51 - one of the SQ
14780 4c 49 54 45 5f 55 54 46 2a 20 76 61 6c 75 65 73 LITE_UTF* values
14790 20 2a 2f 0a 20 20 75 31 36 20 6e 4b 65 79 46 69 */. u16 nKeyFi
147a0 65 6c 64 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d eld; /* Num
147b0 62 65 72 20 6f 66 20 6b 65 79 20 63 6f 6c 75 6d ber of key colum
147c0 6e 73 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 ns in the index
147d0 2a 2f 0a 20 20 75 31 36 20 6e 41 6c 6c 46 69 65 */. u16 nAllFie
147e0 6c 64 3b 20 20 20 20 20 20 2f 2a 20 54 6f 74 61 ld; /* Tota
147f0 6c 20 63 6f 6c 75 6d 6e 73 2c 20 69 6e 63 6c 75 l columns, inclu
14800 64 69 6e 67 20 6b 65 79 20 70 6c 75 73 20 6f 74 ding key plus ot
14810 68 65 72 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 hers */. sqlite
14820 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 3 *db; /*
14830 20 54 68 65 20 64 61 74 61 62 61 73 65 20 63 6f The database co
14840 6e 6e 65 63 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 nnection */. u8
14850 20 2a 61 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 *aSortOrder;
14860 20 20 2f 2a 20 53 6f 72 74 20 6f 72 64 65 72 20 /* Sort order
14870 66 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 2e for each column.
14880 20 2a 2f 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 61 */. CollSeq *a
14890 43 6f 6c 6c 5b 31 5d 3b 20 20 2f 2a 20 43 6f 6c Coll[1]; /* Col
148a0 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 lating sequence
148b0 66 6f 72 20 65 61 63 68 20 74 65 72 6d 20 6f 66 for each term of
148c0 20 74 68 65 20 6b 65 79 20 2a 2f 0a 7d 3b 0a 0a the key */.};..
148d0 2f 2a 0a 2a 2a 20 54 68 69 73 20 6f 62 6a 65 63 /*.** This objec
148e0 74 20 68 6f 6c 64 73 20 61 20 72 65 63 6f 72 64 t holds a record
148f0 20 77 68 69 63 68 20 68 61 73 20 62 65 65 6e 20 which has been
14900 70 61 72 73 65 64 20 6f 75 74 20 69 6e 74 6f 20 parsed out into
14910 69 6e 64 69 76 69 64 75 61 6c 0a 2a 2a 20 66 69 individual.** fi
14920 65 6c 64 73 2c 20 66 6f 72 20 74 68 65 20 70 75 elds, for the pu
14930 72 70 6f 73 65 73 20 6f 66 20 64 6f 69 6e 67 20 rposes of doing
14940 61 20 63 6f 6d 70 61 72 69 73 6f 6e 2e 0a 2a 2a a comparison..**
14950 0a 2a 2a 20 41 20 72 65 63 6f 72 64 20 69 73 20 .** A record is
14960 61 6e 20 6f 62 6a 65 63 74 20 74 68 61 74 20 63 an object that c
14970 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d ontains one or m
14980 6f 72 65 20 66 69 65 6c 64 73 20 6f 66 20 64 61 ore fields of da
14990 74 61 2e 0a 2a 2a 20 52 65 63 6f 72 64 73 20 61 ta..** Records a
149a0 72 65 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 re used to store
149b0 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 the content of
149c0 61 20 74 61 62 6c 65 20 72 6f 77 20 61 6e 64 20 a table row and
149d0 74 6f 20 73 74 6f 72 65 0a 2a 2a 20 74 68 65 20 to store.** the
149e0 6b 65 79 20 6f 66 20 61 6e 20 69 6e 64 65 78 2e key of an index.
149f0 20 20 41 20 62 6c 6f 62 20 65 6e 63 6f 64 69 6e A blob encodin
14a00 67 20 6f 66 20 61 20 72 65 63 6f 72 64 20 69 73 g of a record is
14a10 20 63 72 65 61 74 65 64 20 62 79 0a 2a 2a 20 74 created by.** t
14a20 68 65 20 4f 50 5f 4d 61 6b 65 52 65 63 6f 72 64 he OP_MakeRecord
14a30 20 6f 70 63 6f 64 65 20 6f 66 20 74 68 65 20 56 opcode of the V
14a40 44 42 45 20 61 6e 64 20 69 73 20 64 69 73 61 73 DBE and is disas
14a50 73 65 6d 62 6c 65 64 20 62 79 20 74 68 65 0a 2a sembled by the.*
14a60 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 70 63 6f * OP_Column opco
14a70 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 69 6e 73 de..**.** An ins
14a80 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 6f 62 tance of this ob
14a90 6a 65 63 74 20 73 65 72 76 65 73 20 61 73 20 61 ject serves as a
14aa0 20 22 6b 65 79 22 20 66 6f 72 20 64 6f 69 6e 67 "key" for doing
14ab0 20 61 20 73 65 61 72 63 68 20 6f 6e 0a 2a 2a 20 a search on.**
14ac0 61 6e 20 69 6e 64 65 78 20 62 2b 74 72 65 65 2e an index b+tree.
14ad0 20 54 68 65 20 67 6f 61 6c 20 6f 66 20 74 68 65 The goal of the
14ae0 20 73 65 61 72 63 68 20 69 73 20 74 6f 20 66 69 search is to fi
14af0 6e 64 20 74 68 65 20 65 6e 74 72 79 20 74 68 61 nd the entry tha
14b00 74 0a 2a 2a 20 69 73 20 63 6c 6f 73 65 64 20 74 t.** is closed t
14b10 6f 20 74 68 65 20 6b 65 79 20 64 65 73 63 72 69 o the key descri
14b20 62 65 64 20 62 79 20 74 68 69 73 20 6f 62 6a 65 bed by this obje
14b30 63 74 2e 20 20 54 68 69 73 20 6f 62 6a 65 63 74 ct. This object
14b40 20 6d 69 67 68 74 20 68 6f 6c 64 0a 2a 2a 20 6a might hold.** j
14b50 75 73 74 20 61 20 70 72 65 66 69 78 20 6f 66 20 ust a prefix of
14b60 74 68 65 20 6b 65 79 2e 20 20 54 68 65 20 6e 75 the key. The nu
14b70 6d 62 65 72 20 6f 66 20 66 69 65 6c 64 73 20 69 mber of fields i
14b80 73 20 67 69 76 65 6e 20 62 79 0a 2a 2a 20 70 4b s given by.** pK
14b90 65 79 49 6e 66 6f 2d 3e 6e 46 69 65 6c 64 2e 0a eyInfo->nField..
14ba0 2a 2a 0a 2a 2a 20 54 68 65 20 72 31 20 61 6e 64 **.** The r1 and
14bb0 20 72 32 20 66 69 65 6c 64 73 20 61 72 65 20 74 r2 fields are t
14bc0 68 65 20 76 61 6c 75 65 73 20 74 6f 20 72 65 74 he values to ret
14bd0 75 72 6e 20 69 66 20 74 68 69 73 20 6b 65 79 20 urn if this key
14be0 69 73 20 6c 65 73 73 20 74 68 61 6e 0a 2a 2a 20 is less than.**
14bf0 6f 72 20 67 72 65 61 74 65 72 20 74 68 61 6e 20 or greater than
14c00 61 20 6b 65 79 20 69 6e 20 74 68 65 20 62 74 72 a key in the btr
14c10 65 65 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 ee, respectively
14c20 2e 20 20 54 68 65 73 65 20 61 72 65 20 6e 6f 72 . These are nor
14c30 6d 61 6c 6c 79 0a 2a 2a 20 2d 31 20 61 6e 64 20 mally.** -1 and
14c40 2b 31 20 72 65 73 70 65 63 74 69 76 65 6c 79 2c +1 respectively,
14c50 20 62 75 74 20 6d 69 67 68 74 20 62 65 20 69 6e but might be in
14c60 76 65 72 74 65 64 20 74 6f 20 2b 31 20 61 6e 64 verted to +1 and
14c70 20 2d 31 20 69 66 20 74 68 65 20 62 2d 74 72 65 -1 if the b-tre
14c80 65 0a 2a 2a 20 69 73 20 69 6e 20 44 45 53 43 20 e.** is in DESC
14c90 6f 72 64 65 72 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 order..**.** The
14ca0 20 6b 65 79 20 63 6f 6d 70 61 72 69 73 6f 6e 20 key comparison
14cb0 66 75 6e 63 74 69 6f 6e 73 20 61 63 74 75 61 6c functions actual
14cc0 6c 79 20 72 65 74 75 72 6e 20 64 65 66 61 75 6c ly return defaul
14cd0 74 5f 72 63 20 77 68 65 6e 20 74 68 65 79 20 66 t_rc when they f
14ce0 69 6e 64 0a 2a 2a 20 61 6e 20 65 71 75 61 6c 73 ind.** an equals
14cf0 20 63 6f 6d 70 61 72 69 73 6f 6e 2e 20 20 64 65 comparison. de
14d00 66 61 75 6c 74 5f 72 63 20 63 61 6e 20 62 65 20 fault_rc can be
14d10 2d 31 2c 20 30 2c 20 6f 72 20 2b 31 2e 20 20 49 -1, 0, or +1. I
14d20 66 20 74 68 65 72 65 20 61 72 65 0a 2a 2a 20 6d f there are.** m
14d30 75 6c 74 69 70 6c 65 20 65 6e 74 72 69 65 73 20 ultiple entries
14d40 69 6e 20 74 68 65 20 62 2d 74 72 65 65 20 77 69 in the b-tree wi
14d50 74 68 20 74 68 65 20 73 61 6d 65 20 6b 65 79 20 th the same key
14d60 28 77 68 65 6e 20 6f 6e 6c 79 20 6c 6f 6f 6b 69 (when only looki
14d70 6e 67 0a 2a 2a 20 61 74 20 74 68 65 20 66 69 72 ng.** at the fir
14d80 73 74 20 70 4b 65 79 49 6e 66 6f 2d 3e 6e 46 69 st pKeyInfo->nFi
14d90 65 6c 64 73 2c 29 20 74 68 65 6e 20 64 65 66 61 elds,) then defa
14da0 75 6c 74 5f 72 63 20 63 61 6e 20 62 65 20 73 65 ult_rc can be se
14db0 74 20 74 6f 20 2d 31 20 74 6f 0a 2a 2a 20 63 61 t to -1 to.** ca
14dc0 75 73 65 20 74 68 65 20 73 65 61 72 63 68 20 74 use the search t
14dd0 6f 20 66 69 6e 64 20 74 68 65 20 6c 61 73 74 20 o find the last
14de0 6d 61 74 63 68 2c 20 6f 72 20 2b 31 20 74 6f 20 match, or +1 to
14df0 63 61 75 73 65 20 74 68 65 20 73 65 61 72 63 68 cause the search
14e00 20 74 6f 0a 2a 2a 20 66 69 6e 64 20 74 68 65 20 to.** find the
14e10 66 69 72 73 74 20 6d 61 74 63 68 2e 0a 2a 2a 0a first match..**.
14e20 2a 2a 20 54 68 65 20 6b 65 79 20 63 6f 6d 70 61 ** The key compa
14e30 72 69 73 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 rison functions
14e40 77 69 6c 6c 20 73 65 74 20 65 71 53 65 65 6e 20 will set eqSeen
14e50 74 6f 20 74 72 75 65 20 69 66 20 74 68 65 79 20 to true if they
14e60 65 76 65 72 0a 2a 2a 20 67 65 74 20 61 6e 64 20 ever.** get and
14e70 65 71 75 61 6c 20 72 65 73 75 6c 74 73 20 77 68 equal results wh
14e80 65 6e 20 63 6f 6d 70 61 72 69 6e 67 20 74 68 69 en comparing thi
14e90 73 20 73 74 72 75 63 74 75 72 65 20 74 6f 20 61 s structure to a
14ea0 20 62 2d 74 72 65 65 20 72 65 63 6f 72 64 2e 0a b-tree record..
14eb0 2a 2a 20 57 68 65 6e 20 64 65 66 61 75 6c 74 5f ** When default_
14ec0 72 63 21 3d 30 2c 20 74 68 65 20 73 65 61 72 63 rc!=0, the searc
14ed0 68 20 6d 69 67 68 74 20 65 6e 64 20 75 70 20 6f h might end up o
14ee0 6e 20 74 68 65 20 72 65 63 6f 72 64 20 69 6d 6d n the record imm
14ef0 65 64 69 61 74 65 6c 79 0a 2a 2a 20 62 65 66 6f ediately.** befo
14f00 72 65 20 74 68 65 20 66 69 72 73 74 20 6d 61 74 re the first mat
14f10 63 68 20 6f 72 20 69 6d 6d 65 64 69 61 74 65 6c ch or immediatel
14f20 79 20 61 66 74 65 72 20 74 68 65 20 6c 61 73 74 y after the last
14f30 20 6d 61 74 63 68 2e 20 20 54 68 65 0a 2a 2a 20 match. The.**
14f40 65 71 53 65 65 6e 20 66 69 65 6c 64 20 77 69 6c eqSeen field wil
14f50 6c 20 69 6e 64 69 63 61 74 65 20 77 68 65 74 68 l indicate wheth
14f60 65 72 20 6f 72 20 6e 6f 74 20 61 6e 20 65 78 61 er or not an exa
14f70 63 74 20 6d 61 74 63 68 20 65 78 69 73 74 73 20 ct match exists
14f80 69 6e 20 74 68 65 0a 2a 2a 20 62 2d 74 72 65 65 in the.** b-tree
14f90 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 55 6e 70 61 ..*/.struct Unpa
14fa0 63 6b 65 64 52 65 63 6f 72 64 20 7b 0a 20 20 4b ckedRecord {. K
14fb0 65 79 49 6e 66 6f 20 2a 70 4b 65 79 49 6e 66 6f eyInfo *pKeyInfo
14fc0 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6f 6e 20 ; /* Collation
14fd0 61 6e 64 20 73 6f 72 74 2d 6f 72 64 65 72 20 69 and sort-order i
14fe0 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 20 20 nformation */.
14ff0 4d 65 6d 20 2a 61 4d 65 6d 3b 20 20 20 20 20 20 Mem *aMem;
15000 20 20 20 20 2f 2a 20 56 61 6c 75 65 73 20 2a 2f /* Values */
15010 0a 20 20 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 . u16 nField;
15020 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
15030 20 6f 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 of entries in a
15040 70 4d 65 6d 5b 5d 20 2a 2f 0a 20 20 69 38 20 64 pMem[] */. i8 d
15050 65 66 61 75 6c 74 5f 72 63 3b 20 20 20 20 20 20 efault_rc;
15060 2f 2a 20 43 6f 6d 70 61 72 69 73 6f 6e 20 72 65 /* Comparison re
15070 73 75 6c 74 20 69 66 20 6b 65 79 73 20 61 72 65 sult if keys are
15080 20 65 71 75 61 6c 20 2a 2f 0a 20 20 75 38 20 65 equal */. u8 e
15090 72 72 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 rrCode;
150a0 2f 2a 20 45 72 72 6f 72 20 64 65 74 65 63 74 65 /* Error detecte
150b0 64 20 62 79 20 78 52 65 63 6f 72 64 43 6f 6d 70 d by xRecordComp
150c0 61 72 65 20 28 43 4f 52 52 55 50 54 20 6f 72 20 are (CORRUPT or
150d0 4e 4f 4d 45 4d 29 20 2a 2f 0a 20 20 69 38 20 72 NOMEM) */. i8 r
150e0 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1;
150f0 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 /* Value to retu
15100 72 6e 20 69 66 20 28 6c 68 73 20 3c 20 72 68 73 rn if (lhs < rhs
15110 29 20 2a 2f 0a 20 20 69 38 20 72 32 3b 20 20 20 ) */. i8 r2;
15120 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 /* Va
15130 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 69 66 lue to return if
15140 20 28 6c 68 73 20 3e 20 72 68 73 29 20 2a 2f 0a (lhs > rhs) */.
15150 20 20 75 38 20 65 71 53 65 65 6e 3b 20 20 20 20 u8 eqSeen;
15160 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
15170 20 61 6e 20 65 71 75 61 6c 69 74 79 20 63 6f 6d an equality com
15180 70 61 72 69 73 6f 6e 20 68 61 73 20 62 65 65 6e parison has been
15190 20 73 65 65 6e 20 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a seen */.};.../*
151a0 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 69 6e 64 .** Each SQL ind
151b0 65 78 20 69 73 20 72 65 70 72 65 73 65 6e 74 65 ex is represente
151c0 64 20 69 6e 20 6d 65 6d 6f 72 79 20 62 79 20 61 d in memory by a
151d0 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 n.** instance of
151e0 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
151f0 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 tructure..**.**
15200 54 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 74 The columns of t
15210 68 65 20 74 61 62 6c 65 20 74 68 61 74 20 61 72 he table that ar
15220 65 20 74 6f 20 62 65 20 69 6e 64 65 78 65 64 20 e to be indexed
15230 61 72 65 20 64 65 73 63 72 69 62 65 64 0a 2a 2a are described.**
15240 20 62 79 20 74 68 65 20 61 69 43 6f 6c 75 6d 6e by the aiColumn
15250 5b 5d 20 66 69 65 6c 64 20 6f 66 20 74 68 69 73 [] field of this
15260 20 73 74 72 75 63 74 75 72 65 2e 20 20 46 6f 72 structure. For
15270 20 65 78 61 6d 70 6c 65 2c 20 73 75 70 70 6f 73 example, suppos
15280 65 0a 2a 2a 20 77 65 20 68 61 76 65 20 74 68 65 e.** we have the
15290 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 61 62 6c 65 following table
152a0 20 61 6e 64 20 69 6e 64 65 78 3a 0a 2a 2a 0a 2a and index:.**.*
152b0 2a 20 20 20 20 20 43 52 45 41 54 45 20 54 41 42 * CREATE TAB
152c0 4c 45 20 45 78 31 28 63 31 20 69 6e 74 2c 20 63 LE Ex1(c1 int, c
152d0 32 20 69 6e 74 2c 20 63 33 20 74 65 78 74 29 3b 2 int, c3 text);
152e0 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 49 .** CREATE I
152f0 4e 44 45 58 20 45 78 32 20 4f 4e 20 45 78 31 28 NDEX Ex2 ON Ex1(
15300 63 33 2c 63 31 29 3b 0a 2a 2a 0a 2a 2a 20 49 6e c3,c1);.**.** In
15310 20 74 68 65 20 54 61 62 6c 65 20 73 74 72 75 63 the Table struc
15320 74 75 72 65 20 64 65 73 63 72 69 62 69 6e 67 20 ture describing
15330 45 78 31 2c 20 6e 43 6f 6c 3d 3d 33 20 62 65 63 Ex1, nCol==3 bec
15340 61 75 73 65 20 74 68 65 72 65 20 61 72 65 0a 2a ause there are.*
15350 2a 20 74 68 72 65 65 20 63 6f 6c 75 6d 6e 73 20 * three columns
15360 69 6e 20 74 68 65 20 74 61 62 6c 65 2e 20 20 49 in the table. I
15370 6e 20 74 68 65 20 49 6e 64 65 78 20 73 74 72 75 n the Index stru
15380 63 74 75 72 65 20 64 65 73 63 72 69 62 69 6e 67 cture describing
15390 0a 2a 2a 20 45 78 32 2c 20 6e 43 6f 6c 75 6d 6e .** Ex2, nColumn
153a0 3d 3d 32 20 73 69 6e 63 65 20 32 20 6f 66 20 74 ==2 since 2 of t
153b0 68 65 20 33 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 he 3 columns of
153c0 45 78 31 20 61 72 65 20 69 6e 64 65 78 65 64 2e Ex1 are indexed.
153d0 0a 2a 2a 20 54 68 65 20 76 61 6c 75 65 20 6f 66 .** The value of
153e0 20 61 69 43 6f 6c 75 6d 6e 20 69 73 20 7b 32 2c aiColumn is {2,
153f0 20 30 7d 2e 20 20 61 69 43 6f 6c 75 6d 6e 5b 30 0}. aiColumn[0
15400 5d 3d 3d 32 20 62 65 63 61 75 73 65 20 74 68 65 ]==2 because the
15410 0a 2a 2a 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e .** first column
15420 20 74 6f 20 62 65 20 69 6e 64 65 78 65 64 20 28 to be indexed (
15430 63 33 29 20 68 61 73 20 61 6e 20 69 6e 64 65 78 c3) has an index
15440 20 6f 66 20 32 20 69 6e 20 45 78 31 2e 61 43 6f of 2 in Ex1.aCo
15450 6c 5b 5d 2e 0a 2a 2a 20 54 68 65 20 73 65 63 6f l[]..** The seco
15460 6e 64 20 63 6f 6c 75 6d 6e 20 74 6f 20 62 65 20 nd column to be
15470 69 6e 64 65 78 65 64 20 28 63 31 29 20 68 61 73 indexed (c1) has
15480 20 61 6e 20 69 6e 64 65 78 20 6f 66 20 30 20 69 an index of 0 i
15490 6e 0a 2a 2a 20 45 78 31 2e 61 43 6f 6c 5b 5d 2c n.** Ex1.aCol[],
154a0 20 68 65 6e 63 65 20 45 78 32 2e 61 69 43 6f 6c hence Ex2.aiCol
154b0 75 6d 6e 5b 31 5d 3d 3d 30 2e 0a 2a 2a 0a 2a 2a umn[1]==0..**.**
154c0 20 54 68 65 20 49 6e 64 65 78 2e 6f 6e 45 72 72 The Index.onErr
154d0 6f 72 20 66 69 65 6c 64 20 64 65 74 65 72 6d 69 or field determi
154e0 6e 65 73 20 77 68 65 74 68 65 72 20 6f 72 20 6e nes whether or n
154f0 6f 74 20 74 68 65 20 69 6e 64 65 78 65 64 20 63 ot the indexed c
15500 6f 6c 75 6d 6e 73 0a 2a 2a 20 6d 75 73 74 20 62 olumns.** must b
15510 65 20 75 6e 69 71 75 65 20 61 6e 64 20 77 68 61 e unique and wha
15520 74 20 74 6f 20 64 6f 20 69 66 20 74 68 65 79 20 t to do if they
15530 61 72 65 20 6e 6f 74 2e 20 20 57 68 65 6e 20 49 are not. When I
15540 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 3d 4f 45 5f ndex.onError=OE_
15550 4e 6f 6e 65 2c 0a 2a 2a 20 69 74 20 6d 65 61 6e None,.** it mean
15560 73 20 74 68 69 73 20 69 73 20 6e 6f 74 20 61 20 s this is not a
15570 75 6e 69 71 75 65 20 69 6e 64 65 78 2e 20 20 4f unique index. O
15580 74 68 65 72 77 69 73 65 20 69 74 20 69 73 20 61 therwise it is a
15590 20 75 6e 69 71 75 65 20 69 6e 64 65 78 0a 2a 2a unique index.**
155a0 20 61 6e 64 20 74 68 65 20 76 61 6c 75 65 20 6f and the value o
155b0 66 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 f Index.onError
155c0 69 6e 64 69 63 61 74 65 20 74 68 65 20 77 68 69 indicate the whi
155d0 63 68 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f ch conflict reso
155e0 6c 75 74 69 6f 6e 0a 2a 2a 20 61 6c 67 6f 72 69 lution.** algori
155f0 74 68 6d 20 74 6f 20 65 6d 70 6c 6f 79 20 77 68 thm to employ wh
15600 65 6e 65 76 65 72 20 61 6e 20 61 74 74 65 6d 70 enever an attemp
15610 74 20 69 73 20 6d 61 64 65 20 74 6f 20 69 6e 73 t is made to ins
15620 65 72 74 20 61 20 6e 6f 6e 2d 75 6e 69 71 75 65 ert a non-unique
15630 0a 2a 2a 20 65 6c 65 6d 65 6e 74 2e 0a 2a 2a 0a .** element..**.
15640 2a 2a 20 57 68 69 6c 65 20 70 61 72 73 69 6e 67 ** While parsing
15650 20 61 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 a CREATE TABLE
15660 6f 72 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 or CREATE INDEX
15670 73 74 61 74 65 6d 65 6e 74 20 69 6e 20 6f 72 64 statement in ord
15680 65 72 20 74 6f 0a 2a 2a 20 67 65 6e 65 72 61 74 er to.** generat
15690 65 20 56 44 42 45 20 63 6f 64 65 20 28 61 73 20 e VDBE code (as
156a0 6f 70 70 6f 73 65 64 20 74 6f 20 70 61 72 73 69 opposed to parsi
156b0 6e 67 20 6f 6e 65 20 72 65 61 64 20 66 72 6f 6d ng one read from
156c0 20 61 6e 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 an sqlite_maste
156d0 72 0a 2a 2a 20 74 61 62 6c 65 20 61 73 20 70 61 r.** table as pa
156e0 72 74 20 6f 66 20 70 61 72 73 69 6e 67 20 61 6e rt of parsing an
156f0 20 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 existing databa
15700 73 65 20 73 63 68 65 6d 61 29 2c 20 74 72 61 6e se schema), tran
15710 73 69 65 6e 74 20 69 6e 73 74 61 6e 63 65 73 0a sient instances.
15720 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ** of this struc
15730 74 75 72 65 20 6d 61 79 20 62 65 20 63 72 65 61 ture may be crea
15740 74 65 64 2e 20 49 6e 20 74 68 69 73 20 63 61 73 ted. In this cas
15750 65 20 74 68 65 20 49 6e 64 65 78 2e 74 6e 75 6d e the Index.tnum
15760 20 76 61 72 69 61 62 6c 65 20 69 73 0a 2a 2a 20 variable is.**
15770 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 used to store th
15780 65 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 56 e address of a V
15790 44 42 45 20 69 6e 73 74 72 75 63 74 69 6f 6e 2c DBE instruction,
157a0 20 6e 6f 74 20 61 20 64 61 74 61 62 61 73 65 20 not a database
157b0 70 61 67 65 0a 2a 2a 20 6e 75 6d 62 65 72 20 28 page.** number (
157c0 69 74 20 63 61 6e 6e 6f 74 20 2d 20 74 68 65 20 it cannot - the
157d0 64 61 74 61 62 61 73 65 20 70 61 67 65 20 69 73 database page is
157e0 20 6e 6f 74 20 61 6c 6c 6f 63 61 74 65 64 20 75 not allocated u
157f0 6e 74 69 6c 20 74 68 65 20 56 44 42 45 0a 2a 2a ntil the VDBE.**
15800 20 70 72 6f 67 72 61 6d 20 69 73 20 65 78 65 63 program is exec
15810 75 74 65 64 29 2e 20 53 65 65 20 63 6f 6e 76 65 uted). See conve
15820 72 74 54 6f 57 69 74 68 6f 75 74 52 6f 77 69 64 rtToWithoutRowid
15830 54 61 62 6c 65 28 29 20 66 6f 72 20 64 65 74 61 Table() for deta
15840 69 6c 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 ils..*/.struct I
15850 6e 64 65 78 20 7b 0a 20 20 63 68 61 72 20 2a 7a ndex {. char *z
15860 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 Name;
15870 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 /* Name of thi
15880 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 31 36 s index */. i16
15890 20 2a 61 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 *aiColumn;
158a0 20 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 63 /* Which c
158b0 6f 6c 75 6d 6e 73 20 61 72 65 20 75 73 65 64 20 olumns are used
158c0 62 79 20 74 68 69 73 20 69 6e 64 65 78 2e 20 20 by this index.
158d0 31 73 74 20 69 73 20 30 20 2a 2f 0a 20 20 4c 6f 1st is 0 */. Lo
158e0 67 45 73 74 20 2a 61 69 52 6f 77 4c 6f 67 45 73 gEst *aiRowLogEs
158f0 74 3b 20 20 20 20 20 2f 2a 20 46 72 6f 6d 20 41 t; /* From A
15900 4e 41 4c 59 5a 45 3a 20 45 73 74 2e 20 72 6f 77 NALYZE: Est. row
15910 73 20 73 65 6c 65 63 74 65 64 20 62 79 20 65 61 s selected by ea
15920 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 54 ch column */. T
15930 61 62 6c 65 20 2a 70 54 61 62 6c 65 3b 20 20 20 able *pTable;
15940 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 53 /* The S
15950 51 4c 20 74 61 62 6c 65 20 62 65 69 6e 67 20 69 QL table being i
15960 6e 64 65 78 65 64 20 2a 2f 0a 20 20 63 68 61 72 ndexed */. char
15970 20 2a 7a 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 *zColAff;
15980 20 20 20 20 20 2f 2a 20 53 74 72 69 6e 67 20 64 /* String d
15990 65 66 69 6e 69 6e 67 20 74 68 65 20 61 66 66 69 efining the affi
159a0 6e 69 74 79 20 6f 66 20 65 61 63 68 20 63 6f 6c nity of each col
159b0 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a umn */. Index *
159c0 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 20 pNext;
159d0 20 20 2f 2a 20 54 68 65 20 6e 65 78 74 20 69 6e /* The next in
159e0 64 65 78 20 61 73 73 6f 63 69 61 74 65 64 20 77 dex associated w
159f0 69 74 68 20 74 68 65 20 73 61 6d 65 20 74 61 62 ith the same tab
15a00 6c 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a le */. Schema *
15a10 70 53 63 68 65 6d 61 3b 20 20 20 20 20 20 20 20 pSchema;
15a20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 /* Schema conta
15a30 69 6e 69 6e 67 20 74 68 69 73 20 69 6e 64 65 78 ining this index
15a40 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f */. u8 *aSortO
15a50 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f rder; /
15a60 2a 20 66 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d * for each colum
15a70 6e 3a 20 54 72 75 65 3d 3d 44 45 53 43 2c 20 46 n: True==DESC, F
15a80 61 6c 73 65 3d 3d 41 53 43 20 2a 2f 0a 20 20 63 alse==ASC */. c
15a90 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61 7a 43 6f onst char **azCo
15aa0 6c 6c 3b 20 20 20 20 20 2f 2a 20 41 72 72 61 79 ll; /* Array
15ab0 20 6f 66 20 63 6f 6c 6c 61 74 69 6f 6e 20 73 65 of collation se
15ac0 71 75 65 6e 63 65 20 6e 61 6d 65 73 20 66 6f 72 quence names for
15ad0 20 69 6e 64 65 78 20 2a 2f 0a 20 20 45 78 70 72 index */. Expr
15ae0 20 2a 70 50 61 72 74 49 64 78 57 68 65 72 65 3b *pPartIdxWhere;
15af0 20 20 20 20 20 2f 2a 20 57 48 45 52 45 20 63 6c /* WHERE cl
15b00 61 75 73 65 20 66 6f 72 20 70 61 72 74 69 61 6c ause for partial
15b10 20 69 6e 64 69 63 65 73 20 2a 2f 0a 20 20 45 78 indices */. Ex
15b20 70 72 4c 69 73 74 20 2a 61 43 6f 6c 45 78 70 72 prList *aColExpr
15b30 3b 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e ; /* Column
15b40 20 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a expressions */.
15b50 20 20 69 6e 74 20 74 6e 75 6d 3b 20 20 20 20 20 int tnum;
15b60 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 42 /* DB
15b70 20 50 61 67 65 20 63 6f 6e 74 61 69 6e 69 6e 67 Page containing
15b80 20 72 6f 6f 74 20 6f 66 20 74 68 69 73 20 69 6e root of this in
15b90 64 65 78 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 dex */. LogEst
15ba0 73 7a 49 64 78 52 6f 77 3b 20 20 20 20 20 20 20 szIdxRow;
15bb0 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 61 /* Estimated a
15bc0 76 65 72 61 67 65 20 72 6f 77 20 73 69 7a 65 20 verage row size
15bd0 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 75 31 in bytes */. u1
15be0 36 20 6e 4b 65 79 43 6f 6c 3b 20 20 20 20 20 20 6 nKeyCol;
15bf0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
15c00 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 66 6f 72 6d of columns form
15c10 69 6e 67 20 74 68 65 20 6b 65 79 20 2a 2f 0a 20 ing the key */.
15c20 20 75 31 36 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 u16 nColumn;
15c30 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
15c40 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 73 ber of columns s
15c50 74 6f 72 65 64 20 69 6e 20 74 68 65 20 69 6e 64 tored in the ind
15c60 65 78 20 2a 2f 0a 20 20 75 38 20 6f 6e 45 72 72 ex */. u8 onErr
15c70 6f 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 or;
15c80 20 2f 2a 20 4f 45 5f 41 62 6f 72 74 2c 20 4f 45 /* OE_Abort, OE
15c90 5f 49 67 6e 6f 72 65 2c 20 4f 45 5f 52 65 70 6c _Ignore, OE_Repl
15ca0 61 63 65 2c 20 6f 72 20 4f 45 5f 4e 6f 6e 65 20 ace, or OE_None
15cb0 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 64 */. unsigned id
15cc0 78 54 79 70 65 3a 32 3b 20 20 20 20 20 20 2f 2a xType:2; /*
15cd0 20 31 3d 3d 55 4e 49 51 55 45 2c 20 32 3d 3d 50 1==UNIQUE, 2==P
15ce0 52 49 4d 41 52 59 20 4b 45 59 2c 20 30 3d 3d 43 RIMARY KEY, 0==C
15cf0 52 45 41 54 45 20 49 4e 44 45 58 20 2a 2f 0a 20 REATE INDEX */.
15d00 20 75 6e 73 69 67 6e 65 64 20 62 55 6e 6f 72 64 unsigned bUnord
15d10 65 72 65 64 3a 31 3b 20 20 20 2f 2a 20 55 73 65 ered:1; /* Use
15d20 20 74 68 69 73 20 69 6e 64 65 78 20 66 6f 72 20 this index for
15d30 3d 3d 20 6f 72 20 49 4e 20 71 75 65 72 69 65 73 == or IN queries
15d40 20 6f 6e 6c 79 20 2a 2f 0a 20 20 75 6e 73 69 67 only */. unsig
15d50 6e 65 64 20 75 6e 69 71 4e 6f 74 4e 75 6c 6c 3a ned uniqNotNull:
15d60 31 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 20 55 1; /* True if U
15d70 4e 49 51 55 45 20 61 6e 64 20 4e 4f 54 20 4e 55 NIQUE and NOT NU
15d80 4c 4c 20 66 6f 72 20 61 6c 6c 20 63 6f 6c 75 6d LL for all colum
15d90 6e 73 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 ns */. unsigned
15da0 20 69 73 52 65 73 69 7a 65 64 3a 31 3b 20 20 20 isResized:1;
15db0 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 69 /* True if resi
15dc0 7a 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 29 20 zeIndexObject()
15dd0 68 61 73 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 has been called
15de0 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 73 */. unsigned is
15df0 43 6f 76 65 72 69 6e 67 3a 31 3b 20 20 20 2f 2a Covering:1; /*
15e00 20 54 72 75 65 20 69 66 20 74 68 69 73 20 69 73 True if this is
15e10 20 61 20 63 6f 76 65 72 69 6e 67 20 69 6e 64 65 a covering inde
15e20 78 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 x */. unsigned
15e30 6e 6f 53 6b 69 70 53 63 61 6e 3a 31 3b 20 20 20 noSkipScan:1;
15e40 2f 2a 20 44 6f 20 6e 6f 74 20 74 72 79 20 74 6f /* Do not try to
15e50 20 75 73 65 20 73 6b 69 70 2d 73 63 61 6e 20 69 use skip-scan i
15e60 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 6e 73 69 f true */. unsi
15e70 67 6e 65 64 20 68 61 73 53 74 61 74 31 3a 31 3b gned hasStat1:1;
15e80 20 20 20 20 20 2f 2a 20 61 69 52 6f 77 4c 6f 67 /* aiRowLog
15e90 45 73 74 20 76 61 6c 75 65 73 20 63 6f 6d 65 20 Est values come
15ea0 66 72 6f 6d 20 73 71 6c 69 74 65 5f 73 74 61 74 from sqlite_stat
15eb0 31 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 1 */. unsigned
15ec0 62 4e 6f 51 75 65 72 79 3a 31 3b 20 20 20 20 20 bNoQuery:1;
15ed0 2f 2a 20 44 6f 20 6e 6f 74 20 75 73 65 20 74 68 /* Do not use th
15ee0 69 73 20 69 6e 64 65 78 20 74 6f 20 6f 70 74 69 is index to opti
15ef0 6d 69 7a 65 20 71 75 65 72 69 65 73 20 2a 2f 0a mize queries */.
15f00 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e #ifdef SQLITE_EN
15f10 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 ABLE_STAT3_OR_ST
15f20 41 54 34 0a 20 20 69 6e 74 20 6e 53 61 6d 70 6c AT4. int nSampl
15f30 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f e; /
15f40 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d * Number of elem
15f50 65 6e 74 73 20 69 6e 20 61 53 61 6d 70 6c 65 5b ents in aSample[
15f60 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 6d 70 ] */. int nSamp
15f70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 leCol;
15f80 2f 2a 20 53 69 7a 65 20 6f 66 20 49 6e 64 65 78 /* Size of Index
15f90 53 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d 20 61 6e Sample.anEq[] an
15fa0 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 74 52 6f d so on */. tRo
15fb0 77 63 6e 74 20 2a 61 41 76 67 45 71 3b 20 20 20 wcnt *aAvgEq;
15fc0 20 20 20 20 20 20 2f 2a 20 41 76 65 72 61 67 65 /* Average
15fd0 20 6e 45 71 20 76 61 6c 75 65 73 20 66 6f 72 20 nEq values for
15fe0 6b 65 79 73 20 6e 6f 74 20 69 6e 20 61 53 61 6d keys not in aSam
15ff0 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 78 53 61 ple */. IndexSa
16000 6d 70 6c 65 20 2a 61 53 61 6d 70 6c 65 3b 20 20 mple *aSample;
16010 20 20 2f 2a 20 53 61 6d 70 6c 65 73 20 6f 66 20 /* Samples of
16020 74 68 65 20 6c 65 66 74 2d 6d 6f 73 74 20 6b 65 the left-most ke
16030 79 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a y */. tRowcnt *
16040 61 69 52 6f 77 45 73 74 3b 20 20 20 20 20 20 20 aiRowEst;
16050 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d /* Non-logarithm
16060 69 63 20 73 74 61 74 31 20 64 61 74 61 20 66 6f ic stat1 data fo
16070 72 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a r this index */.
16080 20 20 74 52 6f 77 63 6e 74 20 6e 52 6f 77 45 73 tRowcnt nRowEs
16090 74 30 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f t0; /* No
160a0 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 63 20 6e 75 n-logarithmic nu
160b0 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 6e 20 mber of rows in
160c0 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 23 65 6e the index */.#en
160d0 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c dif.};../*.** Al
160e0 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 lowed values for
160f0 20 49 6e 64 65 78 2e 69 64 78 54 79 70 65 0a 2a Index.idxType.*
16100 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
16110 5f 49 44 58 54 59 50 45 5f 41 50 50 44 45 46 20 _IDXTYPE_APPDEF
16120 20 20 20 20 20 30 20 20 20 2f 2a 20 43 72 65 61 0 /* Crea
16130 74 65 64 20 75 73 69 6e 67 20 43 52 45 41 54 45 ted using CREATE
16140 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 69 6e INDEX */.#defin
16150 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 e SQLITE_IDXTYPE
16160 5f 55 4e 49 51 55 45 20 20 20 20 20 20 31 20 20 _UNIQUE 1
16170 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 73 20 61 /* Implements a
16180 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 69 UNIQUE constrai
16190 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 nt */.#define SQ
161a0 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 50 52 49 LITE_IDXTYPE_PRI
161b0 4d 41 52 59 4b 45 59 20 20 32 20 20 20 2f 2a 20 MARYKEY 2 /*
161c0 49 73 20 74 68 65 20 50 52 49 4d 41 52 59 20 4b Is the PRIMARY K
161d0 45 59 20 66 6f 72 20 74 68 65 20 74 61 62 6c 65 EY for the table
161e0 20 2a 2f 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 74 */../* Return t
161f0 72 75 65 20 69 66 20 69 6e 64 65 78 20 58 20 69 rue if index X i
16200 73 20 61 20 50 52 49 4d 41 52 59 20 4b 45 59 20 s a PRIMARY KEY
16210 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 index */.#define
16220 20 49 73 50 72 69 6d 61 72 79 4b 65 79 49 6e 64 IsPrimaryKeyInd
16230 65 78 28 58 29 20 20 28 28 58 29 2d 3e 69 64 78 ex(X) ((X)->idx
16240 54 79 70 65 3d 3d 53 51 4c 49 54 45 5f 49 44 58 Type==SQLITE_IDX
16250 54 59 50 45 5f 50 52 49 4d 41 52 59 4b 45 59 29 TYPE_PRIMARYKEY)
16260 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 74 72 75 65 ../* Return true
16270 20 69 66 20 69 6e 64 65 78 20 58 20 69 73 20 61 if index X is a
16280 20 55 4e 49 51 55 45 20 69 6e 64 65 78 20 2a 2f UNIQUE index */
16290 0a 23 64 65 66 69 6e 65 20 49 73 55 6e 69 71 75 .#define IsUniqu
162a0 65 49 6e 64 65 78 28 58 29 20 20 20 20 20 20 28 eIndex(X) (
162b0 28 58 29 2d 3e 6f 6e 45 72 72 6f 72 21 3d 4f 45 (X)->onError!=OE
162c0 5f 4e 6f 6e 65 29 0a 0a 2f 2a 20 54 68 65 20 49 _None)../* The I
162d0 6e 64 65 78 2e 61 69 43 6f 6c 75 6d 6e 5b 5d 20 ndex.aiColumn[]
162e0 76 61 6c 75 65 73 20 61 72 65 20 6e 6f 72 6d 61 values are norma
162f0 6c 6c 79 20 70 6f 73 69 74 69 76 65 20 69 6e 74 lly positive int
16300 65 67 65 72 2e 20 20 42 75 74 0a 2a 2a 20 74 68 eger. But.** th
16310 65 72 65 20 61 72 65 20 73 6f 6d 65 20 6e 65 67 ere are some neg
16320 61 74 69 76 65 20 76 61 6c 75 65 73 20 74 68 61 ative values tha
16330 74 20 68 61 76 65 20 73 70 65 63 69 61 6c 20 6d t have special m
16340 65 61 6e 69 6e 67 3a 0a 2a 2f 0a 23 64 65 66 69 eaning:.*/.#defi
16350 6e 65 20 58 4e 5f 52 4f 57 49 44 20 20 20 20 20 ne XN_ROWID
16360 28 2d 31 29 20 20 20 20 20 2f 2a 20 49 6e 64 65 (-1) /* Inde
16370 78 65 64 20 63 6f 6c 75 6d 6e 20 69 73 20 74 68 xed column is th
16380 65 20 72 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 e rowid */.#defi
16390 6e 65 20 58 4e 5f 45 58 50 52 20 20 20 20 20 20 ne XN_EXPR
163a0 28 2d 32 29 20 20 20 20 20 2f 2a 20 49 6e 64 65 (-2) /* Inde
163b0 78 65 64 20 63 6f 6c 75 6d 6e 20 69 73 20 61 6e xed column is an
163c0 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 0a expression */..
163d0 2f 2a 0a 2a 2a 20 45 61 63 68 20 73 61 6d 70 6c /*.** Each sampl
163e0 65 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 e stored in the
163f0 73 71 6c 69 74 65 5f 73 74 61 74 33 20 74 61 62 sqlite_stat3 tab
16400 6c 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 65 le is represente
16410 64 20 69 6e 20 6d 65 6d 6f 72 79 0a 2a 2a 20 75 d in memory.** u
16420 73 69 6e 67 20 61 20 73 74 72 75 63 74 75 72 65 sing a structure
16430 20 6f 66 20 74 68 69 73 20 74 79 70 65 2e 20 20 of this type.
16440 53 65 65 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f See documentatio
16450 6e 20 61 74 20 74 68 65 20 74 6f 70 20 6f 66 20 n at the top of
16460 74 68 65 0a 2a 2a 20 61 6e 61 6c 79 7a 65 2e 63 the.** analyze.c
16470 20 73 6f 75 72 63 65 20 66 69 6c 65 20 66 6f 72 source file for
16480 20 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e 66 6f additional info
16490 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 rmation..*/.stru
164a0 63 74 20 49 6e 64 65 78 53 61 6d 70 6c 65 20 7b ct IndexSample {
164b0 0a 20 20 76 6f 69 64 20 2a 70 3b 20 20 20 20 20 . void *p;
164c0 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 /* Pointer
164d0 74 6f 20 73 61 6d 70 6c 65 64 20 72 65 63 6f 72 to sampled recor
164e0 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 3b 20 20 20 d */. int n;
164f0 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 /* Size
16500 20 6f 66 20 72 65 63 6f 72 64 20 69 6e 20 62 79 of record in by
16510 74 65 73 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 tes */. tRowcnt
16520 20 2a 61 6e 45 71 3b 20 20 20 20 2f 2a 20 45 73 *anEq; /* Es
16530 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 t. number of row
16540 73 20 77 68 65 72 65 20 74 68 65 20 6b 65 79 20 s where the key
16550 65 71 75 61 6c 73 20 74 68 69 73 20 73 61 6d 70 equals this samp
16560 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 le */. tRowcnt
16570 2a 61 6e 4c 74 3b 20 20 20 20 2f 2a 20 45 73 74 *anLt; /* Est
16580 2e 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 . number of rows
16590 20 77 68 65 72 65 20 6b 65 79 20 69 73 20 6c 65 where key is le
165a0 73 73 20 74 68 61 6e 20 74 68 69 73 20 73 61 6d ss than this sam
165b0 70 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 ple */. tRowcnt
165c0 20 2a 61 6e 44 4c 74 3b 20 20 20 2f 2a 20 45 73 *anDLt; /* Es
165d0 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 64 69 73 t. number of dis
165e0 74 69 6e 63 74 20 6b 65 79 73 20 6c 65 73 73 20 tinct keys less
165f0 74 68 61 6e 20 74 68 69 73 20 73 61 6d 70 6c 65 than this sample
16600 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 45 61 */.};../*.** Ea
16610 63 68 20 74 6f 6b 65 6e 20 63 6f 6d 69 6e 67 20 ch token coming
16620 6f 75 74 20 6f 66 20 74 68 65 20 6c 65 78 65 72 out of the lexer
16630 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 is an instance
16640 6f 66 0a 2a 2a 20 74 68 69 73 20 73 74 72 75 63 of.** this struc
16650 74 75 72 65 2e 20 20 54 6f 6b 65 6e 73 20 61 72 ture. Tokens ar
16660 65 20 61 6c 73 6f 20 75 73 65 64 20 61 73 20 70 e also used as p
16670 61 72 74 20 6f 66 20 61 6e 20 65 78 70 72 65 73 art of an expres
16680 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 sion..**.** Note
16690 20 69 66 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 20 74 if Token.z==0 t
166a0 68 65 6e 20 54 6f 6b 65 6e 2e 64 79 6e 20 61 6e hen Token.dyn an
166b0 64 20 54 6f 6b 65 6e 2e 6e 20 61 72 65 20 75 6e d Token.n are un
166c0 64 65 66 69 6e 65 64 20 61 6e 64 0a 2a 2a 20 6d defined and.** m
166d0 61 79 20 63 6f 6e 74 61 69 6e 20 72 61 6e 64 6f ay contain rando
166e0 6d 20 76 61 6c 75 65 73 2e 20 20 44 6f 20 6e 6f m values. Do no
166f0 74 20 6d 61 6b 65 20 61 6e 79 20 61 73 73 75 6d t make any assum
16700 70 74 69 6f 6e 73 20 61 62 6f 75 74 20 54 6f 6b ptions about Tok
16710 65 6e 2e 64 79 6e 0a 2a 2a 20 61 6e 64 20 54 6f en.dyn.** and To
16720 6b 65 6e 2e 6e 20 77 68 65 6e 20 54 6f 6b 65 6e ken.n when Token
16730 2e 7a 3d 3d 30 2e 0a 2a 2f 0a 73 74 72 75 63 74 .z==0..*/.struct
16740 20 54 6f 6b 65 6e 20 7b 0a 20 20 63 6f 6e 73 74 Token {. const
16750 20 63 68 61 72 20 2a 7a 3b 20 20 20 20 20 2f 2a char *z; /*
16760 20 54 65 78 74 20 6f 66 20 74 68 65 20 74 6f 6b Text of the tok
16770 65 6e 2e 20 20 4e 6f 74 20 4e 55 4c 4c 2d 74 65 en. Not NULL-te
16780 72 6d 69 6e 61 74 65 64 21 20 2a 2f 0a 20 20 75 rminated! */. u
16790 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b 20 20 nsigned int n;
167a0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
167b0 68 61 72 61 63 74 65 72 73 20 69 6e 20 74 68 69 haracters in thi
167c0 73 20 74 6f 6b 65 6e 20 2a 2f 0a 7d 3b 0a 0a 2f s token */.};../
167d0 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
167e0 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 of this structu
167f0 72 65 20 63 6f 6e 74 61 69 6e 73 20 69 6e 66 6f re contains info
16800 72 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 20 74 rmation needed t
16810 6f 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 63 6f o generate.** co
16820 64 65 20 66 6f 72 20 61 20 53 45 4c 45 43 54 20 de for a SELECT
16830 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 61 67 that contains ag
16840 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
16850 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 45 78 70 72 s..**.** If Expr
16860 2e 6f 70 3d 3d 54 4b 5f 41 47 47 5f 43 4f 4c 55 .op==TK_AGG_COLU
16870 4d 4e 20 6f 72 20 54 4b 5f 41 47 47 5f 46 55 4e MN or TK_AGG_FUN
16880 43 54 49 4f 4e 20 74 68 65 6e 20 45 78 70 72 2e CTION then Expr.
16890 70 41 67 67 49 6e 66 6f 20 69 73 20 61 0a 2a 2a pAggInfo is a.**
168a0 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 pointer to this
168b0 20 73 74 72 75 63 74 75 72 65 2e 20 20 54 68 65 structure. The
168c0 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 66 69 Expr.iColumn fi
168d0 65 6c 64 20 69 73 20 74 68 65 20 69 6e 64 65 78 eld is the index
168e0 20 69 6e 0a 2a 2a 20 41 67 67 49 6e 66 6f 2e 61 in.** AggInfo.a
168f0 43 6f 6c 5b 5d 20 6f 72 20 41 67 67 49 6e 66 6f Col[] or AggInfo
16900 2e 61 46 75 6e 63 5b 5d 20 6f 66 20 69 6e 66 6f .aFunc[] of info
16910 72 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 20 74 rmation needed t
16920 6f 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 63 6f o generate.** co
16930 64 65 20 66 6f 72 20 74 68 61 74 20 6e 6f 64 65 de for that node
16940 2e 0a 2a 2a 0a 2a 2a 20 41 67 67 49 6e 66 6f 2e ..**.** AggInfo.
16950 70 47 72 6f 75 70 42 79 20 61 6e 64 20 41 67 67 pGroupBy and Agg
16960 49 6e 66 6f 2e 61 46 75 6e 63 2e 70 45 78 70 72 Info.aFunc.pExpr
16970 20 70 6f 69 6e 74 20 74 6f 20 66 69 65 6c 64 73 point to fields
16980 20 77 69 74 68 69 6e 20 74 68 65 0a 2a 2a 20 6f within the.** o
16990 72 69 67 69 6e 61 6c 20 53 65 6c 65 63 74 20 73 riginal Select s
169a0 74 72 75 63 74 75 72 65 20 74 68 61 74 20 64 65 tructure that de
169b0 73 63 72 69 62 65 73 20 74 68 65 20 53 45 4c 45 scribes the SELE
169c0 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 54 CT statement. T
169d0 68 65 73 65 0a 2a 2a 20 66 69 65 6c 64 73 20 64 hese.** fields d
169e0 6f 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 62 65 o not need to be
169f0 20 66 72 65 65 64 20 77 68 65 6e 20 64 65 61 6c freed when deal
16a00 6c 6f 63 61 74 69 6e 67 20 74 68 65 20 41 67 67 locating the Agg
16a10 49 6e 66 6f 20 73 74 72 75 63 74 75 72 65 2e 0a Info structure..
16a20 2a 2f 0a 73 74 72 75 63 74 20 41 67 67 49 6e 66 */.struct AggInf
16a30 6f 20 7b 0a 20 20 75 38 20 64 69 72 65 63 74 4d o {. u8 directM
16a40 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ode; /*
16a50 20 44 69 72 65 63 74 20 72 65 6e 64 65 72 69 6e Direct renderin
16a60 67 20 6d 6f 64 65 20 6d 65 61 6e 73 20 74 61 6b g mode means tak
16a70 65 20 64 61 74 61 20 64 69 72 65 63 74 6c 79 0a e data directly.
16a80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
16a90 20 20 20 20 20 20 20 20 20 20 2a 2a 20 66 72 6f ** fro
16aa0 6d 20 73 6f 75 72 63 65 20 74 61 62 6c 65 73 20 m source tables
16ab0 72 61 74 68 65 72 20 74 68 61 6e 20 66 72 6f 6d rather than from
16ac0 20 61 63 63 75 6d 75 6c 61 74 6f 72 73 20 2a 2f accumulators */
16ad0 0a 20 20 75 38 20 75 73 65 53 6f 72 74 69 6e 67 . u8 useSorting
16ae0 49 64 78 3b 20 20 20 20 20 20 20 2f 2a 20 49 6e Idx; /* In
16af0 20 64 69 72 65 63 74 20 6d 6f 64 65 2c 20 72 65 direct mode, re
16b00 66 65 72 65 6e 63 65 20 74 68 65 20 73 6f 72 74 ference the sort
16b10 69 6e 67 20 69 6e 64 65 78 20 72 61 74 68 65 72 ing index rather
16b20 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
16b30 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 74 68 ** th
16b40 61 6e 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 an the source ta
16b50 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 73 6f 72 ble */. int sor
16b60 74 69 6e 67 49 64 78 3b 20 20 20 20 20 20 20 20 tingIdx;
16b70 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d 62 65 /* Cursor numbe
16b80 72 20 6f 66 20 74 68 65 20 73 6f 72 74 69 6e 67 r of the sorting
16b90 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e 74 20 index */. int
16ba0 73 6f 72 74 69 6e 67 49 64 78 50 54 61 62 3b 20 sortingIdxPTab;
16bb0 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 /* Cursor nu
16bc0 6d 62 65 72 20 6f 66 20 70 73 65 75 64 6f 2d 74 mber of pseudo-t
16bd0 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 able */. int nS
16be0 6f 72 74 69 6e 67 43 6f 6c 75 6d 6e 3b 20 20 20 ortingColumn;
16bf0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 /* Number of c
16c00 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 73 6f olumns in the so
16c10 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 rting index */.
16c20 20 69 6e 74 20 6d 6e 52 65 67 2c 20 6d 78 52 65 int mnReg, mxRe
16c30 67 3b 20 20 20 20 20 20 20 2f 2a 20 52 61 6e 67 g; /* Rang
16c40 65 20 6f 66 20 72 65 67 69 73 74 65 72 73 20 61 e of registers a
16c50 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 61 43 6f llocated for aCo
16c60 6c 20 61 6e 64 20 61 46 75 6e 63 20 2a 2f 0a 20 l and aFunc */.
16c70 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 ExprList *pGrou
16c80 70 42 79 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 pBy; /* The
16c90 67 72 6f 75 70 20 62 79 20 63 6c 61 75 73 65 20 group by clause
16ca0 2a 2f 0a 20 20 73 74 72 75 63 74 20 41 67 67 49 */. struct AggI
16cb0 6e 66 6f 5f 63 6f 6c 20 7b 20 20 20 20 2f 2a 20 nfo_col { /*
16cc0 46 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 For each column
16cd0 75 73 65 64 20 69 6e 20 73 6f 75 72 63 65 20 74 used in source t
16ce0 61 62 6c 65 73 20 2a 2f 0a 20 20 20 20 54 61 62 ables */. Tab
16cf0 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 le *pTab;
16d00 20 20 20 20 20 20 2f 2a 20 53 6f 75 72 63 65 20 /* Source
16d10 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 table */. int
16d20 20 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 iTable;
16d30 20 20 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 /* Cursor
16d40 6e 75 6d 62 65 72 20 6f 66 20 74 68 65 20 73 6f number of the so
16d50 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 urce table */.
16d60 20 20 69 6e 74 20 69 43 6f 6c 75 6d 6e 3b 20 20 int iColumn;
16d70 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f /* Co
16d80 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 77 69 74 68 lumn number with
16d90 69 6e 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 in the source ta
16da0 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 ble */. int i
16db0 53 6f 72 74 65 72 43 6f 6c 75 6d 6e 3b 20 20 20 SorterColumn;
16dc0 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e 75 /* Column nu
16dd0 6d 62 65 72 20 69 6e 20 74 68 65 20 73 6f 72 74 mber in the sort
16de0 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 20 ing index */.
16df0 20 69 6e 74 20 69 4d 65 6d 3b 20 20 20 20 20 20 int iMem;
16e00 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 6d /* Mem
16e10 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 74 68 61 ory location tha
16e20 74 20 61 63 74 73 20 61 73 20 61 63 63 75 6d 75 t acts as accumu
16e30 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 20 45 78 70 lator */. Exp
16e40 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 r *pExpr;
16e50 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6f 72 69 /* The ori
16e60 67 69 6e 61 6c 20 65 78 70 72 65 73 73 69 6f 6e ginal expression
16e70 20 2a 2f 0a 20 20 7d 20 2a 61 43 6f 6c 3b 0a 20 */. } *aCol;.
16e80 20 69 6e 74 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 int nColumn;
16e90 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
16ea0 65 72 20 6f 66 20 75 73 65 64 20 65 6e 74 72 69 er of used entri
16eb0 65 73 20 69 6e 20 61 43 6f 6c 5b 5d 20 2a 2f 0a es in aCol[] */.
16ec0 20 20 69 6e 74 20 6e 41 63 63 75 6d 75 6c 61 74 int nAccumulat
16ed0 6f 72 3b 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d or; /* Num
16ee0 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 74 ber of columns t
16ef0 68 61 74 20 73 68 6f 77 20 74 68 72 6f 75 67 68 hat show through
16f00 20 74 6f 20 74 68 65 20 6f 75 74 70 75 74 2e 0a to the output..
16f10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
16f20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 41 64 64 ** Add
16f30 69 74 69 6f 6e 61 6c 20 63 6f 6c 75 6d 6e 73 20 itional columns
16f40 61 72 65 20 75 73 65 64 20 6f 6e 6c 79 20 61 73 are used only as
16f50 20 70 61 72 61 6d 65 74 65 72 73 20 74 6f 0a 20 parameters to.
16f60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
16f70 20 20 20 20 20 20 20 20 20 2a 2a 20 61 67 67 72 ** aggr
16f80 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 egate functions
16f90 2a 2f 0a 20 20 73 74 72 75 63 74 20 41 67 67 49 */. struct AggI
16fa0 6e 66 6f 5f 66 75 6e 63 20 7b 20 20 20 2f 2a 20 nfo_func { /*
16fb0 46 6f 72 20 65 61 63 68 20 61 67 67 72 65 67 61 For each aggrega
16fc0 74 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 te function */.
16fd0 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 Expr *pExpr;
16fe0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 /* E
16ff0 78 70 72 65 73 73 69 6f 6e 20 65 6e 63 6f 64 69 xpression encodi
17000 6e 67 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 ng the function
17010 2a 2f 0a 20 20 20 20 46 75 6e 63 44 65 66 20 2a */. FuncDef *
17020 70 46 75 6e 63 3b 20 20 20 20 20 20 20 20 20 20 pFunc;
17030 2f 2a 20 54 68 65 20 61 67 67 72 65 67 61 74 65 /* The aggregate
17040 20 66 75 6e 63 74 69 6f 6e 20 69 6d 70 6c 65 6d function implem
17050 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 entation */.
17060 69 6e 74 20 69 4d 65 6d 3b 20 20 20 20 20 20 20 int iMem;
17070 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 6d 6f /* Memo
17080 72 79 20 6c 6f 63 61 74 69 6f 6e 20 74 68 61 74 ry location that
17090 20 61 63 74 73 20 61 73 20 61 63 63 75 6d 75 6c acts as accumul
170a0 61 74 6f 72 20 2a 2f 0a 20 20 20 20 69 6e 74 20 ator */. int
170b0 69 44 69 73 74 69 6e 63 74 3b 20 20 20 20 20 20 iDistinct;
170c0 20 20 20 20 20 2f 2a 20 45 70 68 65 6d 65 72 61 /* Ephemera
170d0 6c 20 74 61 62 6c 65 20 75 73 65 64 20 74 6f 20 l table used to
170e0 65 6e 66 6f 72 63 65 20 44 49 53 54 49 4e 43 54 enforce DISTINCT
170f0 20 2a 2f 0a 20 20 7d 20 2a 61 46 75 6e 63 3b 0a */. } *aFunc;.
17100 20 20 69 6e 74 20 6e 46 75 6e 63 3b 20 20 20 20 int nFunc;
17110 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
17120 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 69 ber of entries i
17130 6e 20 61 46 75 6e 63 5b 5d 20 2a 2f 0a 7d 3b 0a n aFunc[] */.};.
17140 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 ./*.** The datat
17150 79 70 65 20 79 6e 56 61 72 20 69 73 20 61 20 73 ype ynVar is a s
17160 69 67 6e 65 64 20 69 6e 74 65 67 65 72 2c 20 65 igned integer, e
17170 69 74 68 65 72 20 31 36 2d 62 69 74 20 6f 72 20 ither 16-bit or
17180 33 32 2d 62 69 74 2e 0a 2a 2a 20 55 73 75 61 6c 32-bit..** Usual
17190 6c 79 20 69 74 20 69 73 20 31 36 2d 62 69 74 73 ly it is 16-bits
171a0 2e 20 20 42 75 74 20 69 66 20 53 51 4c 49 54 45 . But if SQLITE
171b0 5f 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f 4e 55 _MAX_VARIABLE_NU
171c0 4d 42 45 52 20 69 73 20 67 72 65 61 74 65 72 0a MBER is greater.
171d0 2a 2a 20 74 68 61 6e 20 33 32 37 36 37 20 77 65 ** than 32767 we
171e0 20 68 61 76 65 20 74 6f 20 6d 61 6b 65 20 69 74 have to make it
171f0 20 33 32 2d 62 69 74 2e 20 20 31 36 2d 62 69 74 32-bit. 16-bit
17200 20 69 73 20 70 72 65 66 65 72 72 65 64 20 62 65 is preferred be
17210 63 61 75 73 65 0a 2a 2a 20 69 74 20 75 73 65 73 cause.** it uses
17220 20 6c 65 73 73 20 6d 65 6d 6f 72 79 20 69 6e 20 less memory in
17230 74 68 65 20 45 78 70 72 20 6f 62 6a 65 63 74 2c the Expr object,
17240 20 77 68 69 63 68 20 69 73 20 61 20 62 69 67 20 which is a big
17250 6d 65 6d 6f 72 79 20 75 73 65 72 0a 2a 2a 20 69 memory user.** i
17260 6e 20 73 79 73 74 65 6d 73 20 77 69 74 68 20 6c n systems with l
17270 6f 74 73 20 6f 66 20 70 72 65 70 61 72 65 64 20 ots of prepared
17280 73 74 61 74 65 6d 65 6e 74 73 2e 20 20 41 6e 64 statements. And
17290 20 66 65 77 20 61 70 70 6c 69 63 61 74 69 6f 6e few application
172a0 73 0a 2a 2a 20 6e 65 65 64 20 6d 6f 72 65 20 74 s.** need more t
172b0 68 61 6e 20 61 62 6f 75 74 20 31 30 20 6f 72 20 han about 10 or
172c0 32 30 20 76 61 72 69 61 62 6c 65 73 2e 20 20 42 20 variables. B
172d0 75 74 20 73 6f 6d 65 20 65 78 74 72 65 6d 65 20 ut some extreme
172e0 75 73 65 72 73 20 77 61 6e 74 0a 2a 2a 20 74 6f users want.** to
172f0 20 68 61 76 65 20 70 72 65 70 61 72 65 64 20 73 have prepared s
17300 74 61 74 65 6d 65 6e 74 73 20 77 69 74 68 20 6f tatements with o
17310 76 65 72 20 33 32 37 36 37 20 76 61 72 69 61 62 ver 32767 variab
17320 6c 65 73 2c 20 61 6e 64 20 66 6f 72 20 74 68 65 les, and for the
17330 6d 0a 2a 2a 20 74 68 65 20 6f 70 74 69 6f 6e 20 m.** the option
17340 69 73 20 61 76 61 69 6c 61 62 6c 65 20 28 61 74 is available (at
17350 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 29 2e 0a compile-time)..
17360 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 */.#if SQLITE_MA
17370 58 5f 56 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 X_VARIABLE_NUMBE
17380 52 3c 3d 33 32 37 36 37 0a 74 79 70 65 64 65 66 R<=32767.typedef
17390 20 69 31 36 20 79 6e 56 61 72 3b 0a 23 65 6c 73 i16 ynVar;.#els
173a0 65 0a 74 79 70 65 64 65 66 20 69 6e 74 20 79 6e e.typedef int yn
173b0 56 61 72 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a Var;.#endif../*.
173c0 2a 2a 20 45 61 63 68 20 6e 6f 64 65 20 6f 66 20 ** Each node of
173d0 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e an expression in
173e0 20 74 68 65 20 70 61 72 73 65 20 74 72 65 65 20 the parse tree
173f0 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a is an instance.*
17400 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 * of this struct
17410 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e ure..**.** Expr.
17420 6f 70 20 69 73 20 74 68 65 20 6f 70 63 6f 64 65 op is the opcode
17430 2e 20 54 68 65 20 69 6e 74 65 67 65 72 20 70 61 . The integer pa
17440 72 73 65 72 20 74 6f 6b 65 6e 20 63 6f 64 65 73 rser token codes
17450 20 61 72 65 20 72 65 75 73 65 64 0a 2a 2a 20 61 are reused.** a
17460 73 20 6f 70 63 6f 64 65 73 20 68 65 72 65 2e 20 s opcodes here.
17470 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 68 65 For example, the
17480 20 70 61 72 73 65 72 20 64 65 66 69 6e 65 73 20 parser defines
17490 54 4b 5f 47 45 20 74 6f 20 62 65 20 61 6e 20 69 TK_GE to be an i
174a0 6e 74 65 67 65 72 0a 2a 2a 20 63 6f 64 65 20 72 nteger.** code r
174b0 65 70 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20 epresenting the
174c0 22 3e 3d 22 20 6f 70 65 72 61 74 6f 72 2e 20 54 ">=" operator. T
174d0 68 69 73 20 73 61 6d 65 20 69 6e 74 65 67 65 72 his same integer
174e0 20 63 6f 64 65 20 69 73 20 72 65 75 73 65 64 0a code is reused.
174f0 2a 2a 20 74 6f 20 72 65 70 72 65 73 65 6e 74 20 ** to represent
17500 74 68 65 20 67 72 65 61 74 65 72 2d 74 68 61 6e the greater-than
17510 2d 6f 72 2d 65 71 75 61 6c 2d 74 6f 20 6f 70 65 -or-equal-to ope
17520 72 61 74 6f 72 20 69 6e 20 74 68 65 20 65 78 70 rator in the exp
17530 72 65 73 73 69 6f 6e 0a 2a 2a 20 74 72 65 65 2e ression.** tree.
17540 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 .**.** If the ex
17550 70 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 pression is an S
17560 51 4c 20 6c 69 74 65 72 61 6c 20 28 54 4b 5f 49 QL literal (TK_I
17570 4e 54 45 47 45 52 2c 20 54 4b 5f 46 4c 4f 41 54 NTEGER, TK_FLOAT
17580 2c 20 54 4b 5f 42 4c 4f 42 2c 0a 2a 2a 20 6f 72 , TK_BLOB,.** or
17590 20 54 4b 5f 53 54 52 49 4e 47 29 2c 20 74 68 65 TK_STRING), the
175a0 6e 20 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e n Expr.token con
175b0 74 61 69 6e 73 20 74 68 65 20 74 65 78 74 20 6f tains the text o
175c0 66 20 74 68 65 20 53 51 4c 20 6c 69 74 65 72 61 f the SQL litera
175d0 6c 2e 20 49 66 0a 2a 2a 20 74 68 65 20 65 78 70 l. If.** the exp
175e0 72 65 73 73 69 6f 6e 20 69 73 20 61 20 76 61 72 ression is a var
175f0 69 61 62 6c 65 20 28 54 4b 5f 56 41 52 49 41 42 iable (TK_VARIAB
17600 4c 45 29 2c 20 74 68 65 6e 20 45 78 70 72 2e 74 LE), then Expr.t
17610 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 oken contains th
17620 65 0a 2a 2a 20 76 61 72 69 61 62 6c 65 20 6e 61 e.** variable na
17630 6d 65 2e 20 46 69 6e 61 6c 6c 79 2c 20 69 66 20 me. Finally, if
17640 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 the expression i
17650 73 20 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f s an SQL functio
17660 6e 20 28 54 4b 5f 46 55 4e 43 54 49 4f 4e 29 2c n (TK_FUNCTION),
17670 0a 2a 2a 20 74 68 65 6e 20 45 78 70 72 2e 74 6f .** then Expr.to
17680 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 ken contains the
17690 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 66 75 6e name of the fun
176a0 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 ction..**.** Exp
176b0 72 2e 70 52 69 67 68 74 20 61 6e 64 20 45 78 70 r.pRight and Exp
176c0 72 2e 70 4c 65 66 74 20 61 72 65 20 74 68 65 20 r.pLeft are the
176d0 6c 65 66 74 20 61 6e 64 20 72 69 67 68 74 20 73 left and right s
176e0 75 62 65 78 70 72 65 73 73 69 6f 6e 73 20 6f 66 ubexpressions of
176f0 20 61 0a 2a 2a 20 62 69 6e 61 72 79 20 6f 70 65 a.** binary ope
17700 72 61 74 6f 72 2e 20 45 69 74 68 65 72 20 6f 72 rator. Either or
17710 20 62 6f 74 68 20 6d 61 79 20 62 65 20 4e 55 4c both may be NUL
17720 4c 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 72 2e 78 2e L..**.** Expr.x.
17730 70 4c 69 73 74 20 69 73 20 61 20 6c 69 73 74 20 pList is a list
17740 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 69 66 20 of arguments if
17750 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 the expression i
17760 73 20 61 6e 20 53 51 4c 20 66 75 6e 63 74 69 6f s an SQL functio
17770 6e 2c 0a 2a 2a 20 61 20 43 41 53 45 20 65 78 70 n,.** a CASE exp
17780 72 65 73 73 69 6f 6e 20 6f 72 20 61 6e 20 49 4e ression or an IN
17790 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 expression of t
177a0 68 65 20 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 49 he form "<lhs> I
177b0 4e 20 28 3c 79 3e 2c 20 3c 7a 3e 2e 2e 2e 29 22 N (<y>, <z>...)"
177c0 2e 0a 2a 2a 20 45 78 70 72 2e 78 2e 70 53 65 6c ..** Expr.x.pSel
177d0 65 63 74 20 69 73 20 75 73 65 64 20 69 66 20 74 ect is used if t
177e0 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 he expression is
177f0 20 61 20 73 75 62 2d 73 65 6c 65 63 74 20 6f 72 a sub-select or
17800 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 6f an expression o
17810 66 0a 2a 2a 20 74 68 65 20 66 6f 72 6d 20 22 3c f.** the form "<
17820 6c 68 73 3e 20 49 4e 20 28 53 45 4c 45 43 54 20 lhs> IN (SELECT
17830 2e 2e 2e 29 22 2e 20 49 66 20 74 68 65 20 45 50 ...)". If the EP
17840 5f 78 49 73 53 65 6c 65 63 74 20 62 69 74 20 69 _xIsSelect bit i
17850 73 20 73 65 74 20 69 6e 20 74 68 65 0a 2a 2a 20 s set in the.**
17860 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c Expr.flags mask,
17870 20 74 68 65 6e 20 45 78 70 72 2e 78 2e 70 53 65 then Expr.x.pSe
17880 6c 65 63 74 20 69 73 20 76 61 6c 69 64 2e 20 4f lect is valid. O
17890 74 68 65 72 77 69 73 65 2c 20 45 78 70 72 2e 78 therwise, Expr.x
178a0 2e 70 4c 69 73 74 20 69 73 0a 2a 2a 20 76 61 6c .pList is.** val
178b0 69 64 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 65 78 70 id..**.** An exp
178c0 72 65 73 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 ression of the f
178d0 6f 72 6d 20 49 44 20 6f 72 20 49 44 2e 49 44 20 orm ID or ID.ID
178e0 72 65 66 65 72 73 20 74 6f 20 61 20 63 6f 6c 75 refers to a colu
178f0 6d 6e 20 69 6e 20 61 20 74 61 62 6c 65 2e 0a 2a mn in a table..*
17900 2a 20 46 6f 72 20 73 75 63 68 20 65 78 70 72 65 * For such expre
17910 73 73 69 6f 6e 73 2c 20 45 78 70 72 2e 6f 70 20 ssions, Expr.op
17920 69 73 20 73 65 74 20 74 6f 20 54 4b 5f 43 4f 4c is set to TK_COL
17930 55 4d 4e 20 61 6e 64 20 45 78 70 72 2e 69 54 61 UMN and Expr.iTa
17940 62 6c 65 20 69 73 0a 2a 2a 20 74 68 65 20 69 6e ble is.** the in
17950 74 65 67 65 72 20 63 75 72 73 6f 72 20 6e 75 6d teger cursor num
17960 62 65 72 20 6f 66 20 61 20 56 44 42 45 20 63 75 ber of a VDBE cu
17970 72 73 6f 72 20 70 6f 69 6e 74 69 6e 67 20 74 6f rsor pointing to
17980 20 74 68 61 74 20 74 61 62 6c 65 20 61 6e 64 0a that table and.
17990 2a 2a 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 ** Expr.iColumn
179a0 69 73 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6e 75 is the column nu
179b0 6d 62 65 72 20 66 6f 72 20 74 68 65 20 73 70 65 mber for the spe
179c0 63 69 66 69 63 20 63 6f 6c 75 6d 6e 2e 20 20 49 cific column. I
179d0 66 20 74 68 65 0a 2a 2a 20 65 78 70 72 65 73 73 f the.** express
179e0 69 6f 6e 20 69 73 20 75 73 65 64 20 61 73 20 61 ion is used as a
179f0 20 72 65 73 75 6c 74 20 69 6e 20 61 6e 20 61 67 result in an ag
17a00 67 72 65 67 61 74 65 20 53 45 4c 45 43 54 2c 20 gregate SELECT,
17a10 74 68 65 6e 20 74 68 65 0a 2a 2a 20 76 61 6c 75 then the.** valu
17a20 65 20 69 73 20 61 6c 73 6f 20 73 74 6f 72 65 64 e is also stored
17a30 20 69 6e 20 74 68 65 20 45 78 70 72 2e 69 41 67 in the Expr.iAg
17a40 67 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 20 g column in the
17a50 61 67 67 72 65 67 61 74 65 20 73 6f 20 74 68 61 aggregate so tha
17a60 74 0a 2a 2a 20 69 74 20 63 61 6e 20 62 65 20 61 t.** it can be a
17a70 63 63 65 73 73 65 64 20 61 66 74 65 72 20 61 6c ccessed after al
17a80 6c 20 61 67 67 72 65 67 61 74 65 73 20 61 72 65 l aggregates are
17a90 20 63 6f 6d 70 75 74 65 64 2e 0a 2a 2a 0a 2a 2a computed..**.**
17aa0 20 49 66 20 74 68 65 20 65 78 70 72 65 73 73 69 If the expressi
17ab0 6f 6e 20 69 73 20 61 6e 20 75 6e 62 6f 75 6e 64 on is an unbound
17ac0 20 76 61 72 69 61 62 6c 65 20 6d 61 72 6b 65 72 variable marker
17ad0 20 28 61 20 71 75 65 73 74 69 6f 6e 20 6d 61 72 (a question mar
17ae0 6b 0a 2a 2a 20 63 68 61 72 61 63 74 65 72 20 27 k.** character '
17af0 3f 27 20 69 6e 20 74 68 65 20 6f 72 69 67 69 6e ?' in the origin
17b00 61 6c 20 53 51 4c 29 20 74 68 65 6e 20 74 68 65 al SQL) then the
17b10 20 45 78 70 72 2e 69 54 61 62 6c 65 20 68 6f 6c Expr.iTable hol
17b20 64 73 20 74 68 65 20 69 6e 64 65 78 0a 2a 2a 20 ds the index.**
17b30 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 61 74 20 number for that
17b40 76 61 72 69 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 variable..**.**
17b50 49 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f If the expressio
17b60 6e 20 69 73 20 61 20 73 75 62 71 75 65 72 79 20 n is a subquery
17b70 74 68 65 6e 20 45 78 70 72 2e 69 43 6f 6c 75 6d then Expr.iColum
17b80 6e 20 68 6f 6c 64 73 20 61 6e 20 69 6e 74 65 67 n holds an integ
17b90 65 72 0a 2a 2a 20 72 65 67 69 73 74 65 72 20 6e er.** register n
17ba0 75 6d 62 65 72 20 63 6f 6e 74 61 69 6e 69 6e 67 umber containing
17bb0 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 74 the result of t
17bc0 68 65 20 73 75 62 71 75 65 72 79 2e 20 20 49 66 he subquery. If
17bd0 20 74 68 65 0a 2a 2a 20 73 75 62 71 75 65 72 79 the.** subquery
17be0 20 67 69 76 65 73 20 61 20 63 6f 6e 73 74 61 6e gives a constan
17bf0 74 20 72 65 73 75 6c 74 2c 20 74 68 65 6e 20 69 t result, then i
17c00 54 61 62 6c 65 20 69 73 20 2d 31 2e 20 20 49 66 Table is -1. If
17c10 20 74 68 65 20 73 75 62 71 75 65 72 79 0a 2a 2a the subquery.**
17c20 20 67 69 76 65 73 20 61 20 64 69 66 66 65 72 65 gives a differe
17c30 6e 74 20 61 6e 73 77 65 72 20 61 74 20 64 69 66 nt answer at dif
17c40 66 65 72 65 6e 74 20 74 69 6d 65 73 20 64 75 72 ferent times dur
17c50 69 6e 67 20 73 74 61 74 65 6d 65 6e 74 20 70 72 ing statement pr
17c60 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 74 68 65 6e ocessing.** then
17c70 20 69 54 61 62 6c 65 20 69 73 20 74 68 65 20 61 iTable is the a
17c80 64 64 72 65 73 73 20 6f 66 20 61 20 73 75 62 72 ddress of a subr
17c90 6f 75 74 69 6e 65 20 74 68 61 74 20 63 6f 6d 70 outine that comp
17ca0 75 74 65 73 20 74 68 65 20 73 75 62 71 75 65 72 utes the subquer
17cb0 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 y..**.** If the
17cc0 45 78 70 72 20 69 73 20 6f 66 20 74 79 70 65 20 Expr is of type
17cd0 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 6e 64 20 74 OP_Column, and t
17ce0 68 65 20 74 61 62 6c 65 20 69 74 20 69 73 20 73 he table it is s
17cf0 65 6c 65 63 74 69 6e 67 20 66 72 6f 6d 0a 2a 2a electing from.**
17d00 20 69 73 20 61 20 64 69 73 6b 20 74 61 62 6c 65 is a disk table
17d10 20 6f 72 20 74 68 65 20 22 6f 6c 64 2e 2a 22 20 or the "old.*"
17d20 70 73 65 75 64 6f 2d 74 61 62 6c 65 2c 20 74 68 pseudo-table, th
17d30 65 6e 20 70 54 61 62 20 70 6f 69 6e 74 73 20 74 en pTab points t
17d40 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 o the.** corresp
17d50 6f 6e 64 69 6e 67 20 74 61 62 6c 65 20 64 65 66 onding table def
17d60 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 41 inition..**.** A
17d70 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f 54 45 53 3a LLOCATION NOTES:
17d80 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 6f 62 6a 65 .**.** Expr obje
17d90 63 74 73 20 63 61 6e 20 75 73 65 20 61 20 6c 6f cts can use a lo
17da0 74 20 6f 66 20 6d 65 6d 6f 72 79 20 73 70 61 63 t of memory spac
17db0 65 20 69 6e 20 64 61 74 61 62 61 73 65 20 73 63 e in database sc
17dc0 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a 20 68 65 6c hema. To.** hel
17dd0 70 20 72 65 64 75 63 65 20 6d 65 6d 6f 72 79 20 p reduce memory
17de0 72 65 71 75 69 72 65 6d 65 6e 74 73 2c 20 73 6f requirements, so
17df0 6d 65 74 69 6d 65 73 20 61 6e 20 45 78 70 72 20 metimes an Expr
17e00 6f 62 6a 65 63 74 20 77 69 6c 6c 20 62 65 0a 2a object will be.*
17e10 2a 20 74 72 75 6e 63 61 74 65 64 2e 20 20 41 6e * truncated. An
17e20 64 20 74 6f 20 72 65 64 75 63 65 20 74 68 65 20 d to reduce the
17e30 6e 75 6d 62 65 72 20 6f 66 20 6d 65 6d 6f 72 79 number of memory
17e40 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 2c 20 73 6f allocations, so
17e50 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 77 6f 20 6f metimes.** two o
17e60 72 20 6d 6f 72 65 20 45 78 70 72 20 6f 62 6a 65 r more Expr obje
17e70 63 74 73 20 77 69 6c 6c 20 62 65 20 73 74 6f 72 cts will be stor
17e80 65 64 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 6d ed in a single m
17e90 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e emory allocation
17ea0 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 72 20 77 69 ,.** together wi
17eb0 74 68 20 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 73 th Expr.zToken s
17ec0 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 trings..**.** If
17ed0 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 the EP_Reduced
17ee0 61 6e 64 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 and EP_TokenOnly
17ef0 20 66 6c 61 67 73 20 61 72 65 20 73 65 74 20 77 flags are set w
17f00 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 70 72 20 6f hen.** an Expr o
17f10 62 6a 65 63 74 20 69 73 20 74 72 75 6e 63 61 74 bject is truncat
17f20 65 64 2e 20 20 57 68 65 6e 20 45 50 5f 52 65 64 ed. When EP_Red
17f30 75 63 65 64 20 69 73 20 73 65 74 2c 20 74 68 65 uced is set, the
17f40 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 20 63 68 69 n all.** the chi
17f50 6c 64 20 45 78 70 72 20 6f 62 6a 65 63 74 73 20 ld Expr objects
17f60 69 6e 20 74 68 65 20 45 78 70 72 2e 70 4c 65 66 in the Expr.pLef
17f70 74 20 61 6e 64 20 45 78 70 72 2e 70 52 69 67 68 t and Expr.pRigh
17f80 74 20 73 75 62 74 72 65 65 73 0a 2a 2a 20 61 72 t subtrees.** ar
17f90 65 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 68 e contained with
17fa0 69 6e 20 74 68 65 20 73 61 6d 65 20 6d 65 6d 6f in the same memo
17fb0 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 ry allocation.
17fc0 4e 6f 74 65 2c 20 68 6f 77 65 76 65 72 2c 20 74 Note, however, t
17fd0 68 61 74 0a 2a 2a 20 74 68 65 20 73 75 62 74 72 hat.** the subtr
17fe0 65 65 73 20 69 6e 20 45 78 70 72 2e 78 2e 70 4c ees in Expr.x.pL
17ff0 69 73 74 20 6f 72 20 45 78 70 72 2e 78 2e 70 53 ist or Expr.x.pS
18000 65 6c 65 63 74 20 61 72 65 20 61 6c 77 61 79 73 elect are always
18010 20 73 65 70 61 72 61 74 65 6c 79 0a 2a 2a 20 61 separately.** a
18020 6c 6c 6f 63 61 74 65 64 2c 20 72 65 67 61 72 64 llocated, regard
18030 6c 65 73 73 20 6f 66 20 77 68 65 74 68 65 72 20 less of whether
18040 6f 72 20 6e 6f 74 20 45 50 5f 52 65 64 75 63 65 or not EP_Reduce
18050 64 20 69 73 20 73 65 74 2e 0a 2a 2f 0a 73 74 72 d is set..*/.str
18060 75 63 74 20 45 78 70 72 20 7b 0a 20 20 75 38 20 uct Expr {. u8
18070 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 op;
18080 20 20 20 20 2f 2a 20 4f 70 65 72 61 74 69 6f 6e /* Operation
18090 20 70 65 72 66 6f 72 6d 65 64 20 62 79 20 74 68 performed by th
180a0 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 20 63 68 61 is node */. cha
180b0 72 20 61 66 66 69 6e 69 74 79 3b 20 20 20 20 20 r affinity;
180c0 20 20 20 20 2f 2a 20 54 68 65 20 61 66 66 69 6e /* The affin
180d0 69 74 79 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d ity of the colum
180e0 6e 20 6f 72 20 30 20 69 66 20 6e 6f 74 20 61 20 n or 0 if not a
180f0 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 75 33 32 20 column */. u32
18100 66 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 flags;
18110 20 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 66 6c /* Various fl
18120 61 67 73 2e 20 20 45 50 5f 2a 20 53 65 65 20 62 ags. EP_* See b
18130 65 6c 6f 77 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 elow */. union
18140 7b 0a 20 20 20 20 63 68 61 72 20 2a 7a 54 6f 6b {. char *zTok
18150 65 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 en; /*
18160 54 6f 6b 65 6e 20 76 61 6c 75 65 2e 20 5a 65 72 Token value. Zer
18170 6f 20 74 65 72 6d 69 6e 61 74 65 64 20 61 6e 64 o terminated and
18180 20 64 65 71 75 6f 74 65 64 20 2a 2f 0a 20 20 20 dequoted */.
18190 20 69 6e 74 20 69 56 61 6c 75 65 3b 20 20 20 20 int iValue;
181a0 20 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6e /* Non-n
181b0 65 67 61 74 69 76 65 20 69 6e 74 65 67 65 72 20 egative integer
181c0 76 61 6c 75 65 20 69 66 20 45 50 5f 49 6e 74 56 value if EP_IntV
181d0 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a 0a alue */. } u;..
181e0 20 20 2f 2a 20 49 66 20 74 68 65 20 45 50 5f 54 /* If the EP_T
181f0 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 69 73 okenOnly flag is
18200 20 73 65 74 20 69 6e 20 74 68 65 20 45 78 70 72 set in the Expr
18210 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 .flags mask, the
18220 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 65 20 n no. ** space
18230 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 is allocated for
18240 20 74 68 65 20 66 69 65 6c 64 73 20 62 65 6c 6f the fields belo
18250 77 20 74 68 69 73 20 70 6f 69 6e 74 2e 20 41 6e w this point. An
18260 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 20 2a 2a attempt to. **
18270 20 61 63 63 65 73 73 20 74 68 65 6d 20 77 69 6c access them wil
18280 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 20 73 65 l result in a se
18290 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c 66 75 6e gfault or malfun
182a0 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a ction.. *******
182b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
182c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
182d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
182e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a **************/.
182f0 0a 20 20 45 78 70 72 20 2a 70 4c 65 66 74 3b 20 . Expr *pLeft;
18300 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 66 /* Lef
18310 74 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 45 t subnode */. E
18320 78 70 72 20 2a 70 52 69 67 68 74 3b 20 20 20 20 xpr *pRight;
18330 20 20 20 20 20 20 2f 2a 20 52 69 67 68 74 20 73 /* Right s
18340 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 6f ubnode */. unio
18350 6e 20 7b 0a 20 20 20 20 45 78 70 72 4c 69 73 74 n {. ExprList
18360 20 2a 70 4c 69 73 74 3b 20 20 20 20 20 2f 2a 20 *pList; /*
18370 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 53 2c op = IN, EXISTS,
18380 20 53 45 4c 45 43 54 2c 20 43 41 53 45 2c 20 46 SELECT, CASE, F
18390 55 4e 43 54 49 4f 4e 2c 20 42 45 54 57 45 45 4e UNCTION, BETWEEN
183a0 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a */. Select *
183b0 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 pSelect; /*
183c0 45 50 5f 78 49 73 53 65 6c 65 63 74 20 61 6e 64 EP_xIsSelect and
183d0 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 53 54 53 op = IN, EXISTS
183e0 2c 20 53 45 4c 45 43 54 20 2a 2f 0a 20 20 7d 20 , SELECT */. }
183f0 78 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 x;.. /* If the
18400 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 67 20 EP_Reduced flag
18410 69 73 20 73 65 74 20 69 6e 20 74 68 65 20 45 78 is set in the Ex
18420 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c 20 74 pr.flags mask, t
18430 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 hen no. ** spac
18440 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 e is allocated f
18450 6f 72 20 74 68 65 20 66 69 65 6c 64 73 20 62 65 or the fields be
18460 6c 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 2e 20 low this point.
18470 41 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a 20 20 An attempt to.
18480 2a 2a 20 61 63 63 65 73 73 20 74 68 65 6d 20 77 ** access them w
18490 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 61 20 ill result in a
184a0 73 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 6c 66 segfault or malf
184b0 75 6e 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a unction.. *****
184c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
184d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
184e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
184f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
18500 2f 0a 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 /..#if SQLITE_MA
18510 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 0a 20 X_EXPR_DEPTH>0.
18520 20 69 6e 74 20 6e 48 65 69 67 68 74 3b 20 20 20 int nHeight;
18530 20 20 20 20 20 20 20 20 2f 2a 20 48 65 69 67 68 /* Heigh
18540 74 20 6f 66 20 74 68 65 20 74 72 65 65 20 68 65 t of the tree he
18550 61 64 65 64 20 62 79 20 74 68 69 73 20 6e 6f 64 aded by this nod
18560 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e e */.#endif. in
18570 74 20 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 t iTable;
18580 20 20 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d /* TK_COLUM
18590 4e 3a 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 N: cursor number
185a0 20 6f 66 20 74 61 62 6c 65 20 68 6f 6c 64 69 6e of table holdin
185b0 67 20 63 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 g column.
185c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
185d0 20 20 2a 2a 20 54 4b 5f 52 45 47 49 53 54 45 52 ** TK_REGISTER
185e0 3a 20 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 : register numbe
185f0 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r.
18600 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b ** TK
18610 5f 54 52 49 47 47 45 52 3a 20 31 20 2d 3e 20 6e _TRIGGER: 1 -> n
18620 65 77 2c 20 30 20 2d 3e 20 6f 6c 64 0a 20 20 20 ew, 0 -> old.
18630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18640 20 20 20 20 20 20 2a 2a 20 45 50 5f 55 6e 6c 69 ** EP_Unli
18650 6b 65 6c 79 3a 20 20 31 33 34 32 31 37 37 32 38 kely: 134217728
18660 20 74 69 6d 65 73 20 6c 69 6b 65 6c 69 68 6f 6f times likelihoo
18670 64 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 d.
18680 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b ** TK
18690 5f 53 45 4c 45 43 54 3a 20 31 73 74 20 72 65 67 _SELECT: 1st reg
186a0 69 73 74 65 72 20 6f 66 20 72 65 73 75 6c 74 20 ister of result
186b0 76 65 63 74 6f 72 20 2a 2f 0a 20 20 79 6e 56 61 vector */. ynVa
186c0 72 20 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 r iColumn;
186d0 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a /* TK_COLUMN:
186e0 20 63 6f 6c 75 6d 6e 20 69 6e 64 65 78 2e 20 20 column index.
186f0 2d 31 20 66 6f 72 20 72 6f 77 69 64 2e 0a 20 20 -1 for rowid..
18700 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18710 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 56 41 52 ** TK_VAR
18720 49 41 42 4c 45 3a 20 76 61 72 69 61 62 6c 65 20 IABLE: variable
18730 6e 75 6d 62 65 72 20 28 61 6c 77 61 79 73 20 3e number (always >
18740 3d 20 31 29 2e 0a 20 20 20 20 20 20 20 20 20 20 = 1)..
18750 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
18760 2a 20 54 4b 5f 53 45 4c 45 43 54 5f 43 4f 4c 55 * TK_SELECT_COLU
18770 4d 4e 3a 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 68 MN: column of th
18780 65 20 72 65 73 75 6c 74 20 76 65 63 74 6f 72 20 e result vector
18790 2a 2f 0a 20 20 69 31 36 20 69 41 67 67 3b 20 20 */. i16 iAgg;
187a0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 /* W
187b0 68 69 63 68 20 65 6e 74 72 79 20 69 6e 20 70 41 hich entry in pA
187c0 67 67 49 6e 66 6f 2d 3e 61 43 6f 6c 5b 5d 20 6f ggInfo->aCol[] o
187d0 72 20 2d 3e 61 46 75 6e 63 5b 5d 20 2a 2f 0a 20 r ->aFunc[] */.
187e0 20 69 31 36 20 69 52 69 67 68 74 4a 6f 69 6e 54 i16 iRightJoinT
187f0 61 62 6c 65 3b 20 20 20 2f 2a 20 49 66 20 45 50 able; /* If EP
18800 5f 46 72 6f 6d 4a 6f 69 6e 2c 20 74 68 65 20 72 _FromJoin, the r
18810 69 67 68 74 20 74 61 62 6c 65 20 6f 66 20 74 68 ight table of th
18820 65 20 6a 6f 69 6e 20 2a 2f 0a 20 20 75 38 20 6f e join */. u8 o
18830 70 32 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 p2;
18840 20 20 20 2f 2a 20 54 4b 5f 52 45 47 49 53 54 45 /* TK_REGISTE
18850 52 3a 20 6f 72 69 67 69 6e 61 6c 20 76 61 6c 75 R: original valu
18860 65 20 6f 66 20 45 78 70 72 2e 6f 70 0a 20 20 20 e of Expr.op.
18870 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18880 20 20 20 20 20 20 2a 2a 20 54 4b 5f 43 4f 4c 55 ** TK_COLU
18890 4d 4e 3a 20 74 68 65 20 76 61 6c 75 65 20 6f 66 MN: the value of
188a0 20 70 35 20 66 6f 72 20 4f 50 5f 43 6f 6c 75 6d p5 for OP_Colum
188b0 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n.
188c0 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b ** TK
188d0 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e 3a 20 6e _AGG_FUNCTION: n
188e0 65 73 74 69 6e 67 20 64 65 70 74 68 20 2a 2f 0a esting depth */.
188f0 20 20 41 67 67 49 6e 66 6f 20 2a 70 41 67 67 49 AggInfo *pAggI
18900 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 55 73 65 64 nfo; /* Used
18910 20 62 79 20 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d by TK_AGG_COLUM
18920 4e 20 61 6e 64 20 54 4b 5f 41 47 47 5f 46 55 4e N and TK_AGG_FUN
18930 43 54 49 4f 4e 20 2a 2f 0a 20 20 54 61 62 6c 65 CTION */. Table
18940 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 *pTab;
18950 20 20 2f 2a 20 54 61 62 6c 65 20 66 6f 72 20 54 /* Table for T
18960 4b 5f 43 4f 4c 55 4d 4e 20 65 78 70 72 65 73 73 K_COLUMN express
18970 69 6f 6e 73 2e 20 20 43 61 6e 20 62 65 20 4e 55 ions. Can be NU
18980 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 LL.
18990 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 66 ** f
189a0 6f 72 20 61 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 or a column of a
189b0 6e 20 69 6e 64 65 78 20 6f 6e 20 61 6e 20 65 78 n index on an ex
189c0 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a pression */.};..
189d0 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
189e0 69 6e 67 20 61 72 65 20 74 68 65 20 6d 65 61 6e ing are the mean
189f0 69 6e 67 73 20 6f 66 20 62 69 74 73 20 69 6e 20 ings of bits in
18a00 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 66 the Expr.flags f
18a10 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ield..*/.#define
18a20 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 20 30 78 EP_FromJoin 0x
18a30 30 30 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 6e 000001 /* Origin
18a40 61 74 65 73 20 69 6e 20 4f 4e 2f 55 53 49 4e 47 ates in ON/USING
18a50 20 63 6c 61 75 73 65 20 6f 66 20 6f 75 74 65 72 clause of outer
18a60 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 join */.#define
18a70 20 45 50 5f 41 67 67 20 20 20 20 20 20 20 30 78 EP_Agg 0x
18a80 30 30 30 30 30 32 20 2f 2a 20 43 6f 6e 74 61 69 000002 /* Contai
18a90 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 61 ns one or more a
18aa0 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
18ab0 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 ns */.#define EP
18ac0 5f 48 61 73 46 75 6e 63 20 20 20 30 78 30 30 30 _HasFunc 0x000
18ad0 30 30 34 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 004 /* Contains
18ae0 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 66 75 6e 63 one or more func
18af0 74 69 6f 6e 73 20 6f 66 20 61 6e 79 20 6b 69 6e tions of any kin
18b00 64 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 d */.
18b10 20 20 20 20 20 20 20 2f 2a 20 30 78 30 30 30 30 /* 0x0000
18b20 30 38 20 2f 2f 20 61 76 61 69 6c 61 62 6c 65 20 08 // available
18b30 66 6f 72 20 75 73 65 20 2a 2f 0a 23 64 65 66 69 for use */.#defi
18b40 6e 65 20 45 50 5f 44 69 73 74 69 6e 63 74 20 20 ne EP_Distinct
18b50 30 78 30 30 30 30 31 30 20 2f 2a 20 41 67 67 72 0x000010 /* Aggr
18b60 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 egate function w
18b70 69 74 68 20 44 49 53 54 49 4e 43 54 20 6b 65 79 ith DISTINCT key
18b80 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 word */.#define
18b90 45 50 5f 56 61 72 53 65 6c 65 63 74 20 30 78 30 EP_VarSelect 0x0
18ba0 30 30 30 32 30 20 2f 2a 20 70 53 65 6c 65 63 74 00020 /* pSelect
18bb0 20 69 73 20 63 6f 72 72 65 6c 61 74 65 64 2c 20 is correlated,
18bc0 6e 6f 74 20 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a not constant */.
18bd0 23 64 65 66 69 6e 65 20 45 50 5f 44 62 6c 51 75 #define EP_DblQu
18be0 6f 74 65 64 20 30 78 30 30 30 30 34 30 20 2f 2a oted 0x000040 /*
18bf0 20 74 6f 6b 65 6e 2e 7a 20 77 61 73 20 6f 72 69 token.z was ori
18c00 67 69 6e 61 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 ginally in "..."
18c10 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 */.#define EP_I
18c20 6e 66 69 78 46 75 6e 63 20 30 78 30 30 30 30 38 nfixFunc 0x00008
18c30 30 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 6e 0 /* True for an
18c40 20 69 6e 66 69 78 20 66 75 6e 63 74 69 6f 6e 3a infix function:
18c50 20 4c 49 4b 45 2c 20 47 4c 4f 42 2c 20 65 74 63 LIKE, GLOB, etc
18c60 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 */.#define EP_C
18c70 6f 6c 6c 61 74 65 20 20 20 30 78 30 30 30 31 30 ollate 0x00010
18c80 30 20 2f 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 0 /* Tree contai
18c90 6e 73 20 61 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 ns a TK_COLLATE
18ca0 6f 70 65 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 operator */.#def
18cb0 69 6e 65 20 45 50 5f 47 65 6e 65 72 69 63 20 20 ine EP_Generic
18cc0 20 30 78 30 30 30 32 30 30 20 2f 2a 20 49 67 6e 0x000200 /* Ign
18cd0 6f 72 65 20 43 4f 4c 4c 41 54 45 20 6f 72 20 61 ore COLLATE or a
18ce0 66 66 69 6e 69 74 79 20 6f 6e 20 74 68 69 73 20 ffinity on this
18cf0 74 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tree */.#define
18d00 45 50 5f 49 6e 74 56 61 6c 75 65 20 20 30 78 30 EP_IntValue 0x0
18d10 30 30 34 30 30 20 2f 2a 20 49 6e 74 65 67 65 72 00400 /* Integer
18d20 20 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 value contained
18d30 20 69 6e 20 75 2e 69 56 61 6c 75 65 20 2a 2f 0a in u.iValue */.
18d40 23 64 65 66 69 6e 65 20 45 50 5f 78 49 73 53 65 #define EP_xIsSe
18d50 6c 65 63 74 20 30 78 30 30 30 38 30 30 20 2f 2a lect 0x000800 /*
18d60 20 78 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 x.pSelect is va
18d70 6c 69 64 20 28 6f 74 68 65 72 77 69 73 65 20 78 lid (otherwise x
18d80 2e 70 4c 69 73 74 20 69 73 29 20 2a 2f 0a 23 64 .pList is) */.#d
18d90 65 66 69 6e 65 20 45 50 5f 53 6b 69 70 20 20 20 efine EP_Skip
18da0 20 20 20 30 78 30 30 31 30 30 30 20 2f 2a 20 43 0x001000 /* C
18db0 4f 4c 4c 41 54 45 2c 20 41 53 2c 20 6f 72 20 55 OLLATE, AS, or U
18dc0 4e 4c 49 4b 45 4c 59 20 2a 2f 0a 23 64 65 66 69 NLIKELY */.#defi
18dd0 6e 65 20 45 50 5f 52 65 64 75 63 65 64 20 20 20 ne EP_Reduced
18de0 30 78 30 30 32 30 30 30 20 2f 2a 20 45 78 70 72 0x002000 /* Expr
18df0 20 73 74 72 75 63 74 20 45 58 50 52 5f 52 45 44 struct EXPR_RED
18e00 55 43 45 44 53 49 5a 45 20 62 79 74 65 73 20 6f UCEDSIZE bytes o
18e10 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 nly */.#define E
18e20 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 P_TokenOnly 0x00
18e30 34 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 4000 /* Expr str
18e40 75 63 74 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e uct EXPR_TOKENON
18e50 4c 59 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c LYSIZE bytes onl
18e60 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f y */.#define EP_
18e70 53 74 61 74 69 63 20 20 20 20 30 78 30 30 38 30 Static 0x0080
18e80 30 30 20 2f 2a 20 48 65 6c 64 20 69 6e 20 6d 65 00 /* Held in me
18e90 6d 6f 72 79 20 6e 6f 74 20 6f 62 74 61 69 6e 65 mory not obtaine
18ea0 64 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 d from malloc()
18eb0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4d 65 */.#define EP_Me
18ec0 6d 54 6f 6b 65 6e 20 20 30 78 30 31 30 30 30 30 mToken 0x010000
18ed0 20 2f 2a 20 4e 65 65 64 20 74 6f 20 73 71 6c 69 /* Need to sqli
18ee0 74 65 33 44 62 46 72 65 65 28 29 20 45 78 70 72 te3DbFree() Expr
18ef0 2e 7a 54 6f 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 .zToken */.#defi
18f00 6e 65 20 45 50 5f 4e 6f 52 65 64 75 63 65 20 20 ne EP_NoReduce
18f10 30 78 30 32 30 30 30 30 20 2f 2a 20 43 61 6e 6e 0x020000 /* Cann
18f20 6f 74 20 45 58 50 52 44 55 50 5f 52 45 44 55 43 ot EXPRDUP_REDUC
18f30 45 20 74 68 69 73 20 45 78 70 72 20 2a 2f 0a 23 E this Expr */.#
18f40 64 65 66 69 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 define EP_Unlike
18f50 6c 79 20 20 30 78 30 34 30 30 30 30 20 2f 2a 20 ly 0x040000 /*
18f60 75 6e 6c 69 6b 65 6c 79 28 29 20 6f 72 20 6c 69 unlikely() or li
18f70 6b 65 6c 69 68 6f 6f 64 28 29 20 66 75 6e 63 74 kelihood() funct
18f80 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ion */.#define E
18f90 50 5f 43 6f 6e 73 74 46 75 6e 63 20 30 78 30 38 P_ConstFunc 0x08
18fa0 30 30 30 30 20 2f 2a 20 41 20 53 51 4c 49 54 45 0000 /* A SQLITE
18fb0 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 6f _FUNC_CONSTANT o
18fc0 72 20 5f 53 4c 4f 43 48 4e 47 20 66 75 6e 63 74 r _SLOCHNG funct
18fd0 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ion */.#define E
18fe0 50 5f 43 61 6e 42 65 4e 75 6c 6c 20 30 78 31 30 P_CanBeNull 0x10
18ff0 30 30 30 30 20 2f 2a 20 43 61 6e 20 62 65 20 6e 0000 /* Can be n
19000 75 6c 6c 20 64 65 73 70 69 74 65 20 4e 4f 54 20 ull despite NOT
19010 4e 55 4c 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 NULL constraint
19020 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 75 */.#define EP_Su
19030 62 71 75 65 72 79 20 20 30 78 32 30 30 30 30 30 bquery 0x200000
19040 20 2f 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 6e /* Tree contain
19050 73 20 61 20 54 4b 5f 53 45 4c 45 43 54 20 6f 70 s a TK_SELECT op
19060 65 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e erator */.#defin
19070 65 20 45 50 5f 41 6c 69 61 73 20 20 20 20 20 30 e EP_Alias 0
19080 78 34 30 30 30 30 30 20 2f 2a 20 49 73 20 61 6e x400000 /* Is an
19090 20 61 6c 69 61 73 20 66 6f 72 20 61 20 72 65 73 alias for a res
190a0 75 6c 74 20 73 65 74 20 63 6f 6c 75 6d 6e 20 2a ult set column *
190b0 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4c 65 61 /.#define EP_Lea
190c0 66 20 20 20 20 20 20 30 78 38 30 30 30 30 30 20 f 0x800000
190d0 2f 2a 20 45 78 70 72 2e 70 4c 65 66 74 2c 20 2e /* Expr.pLeft, .
190e0 70 52 69 67 68 74 2c 20 2e 75 2e 70 53 65 6c 65 pRight, .u.pSele
190f0 63 74 20 61 6c 6c 20 4e 55 4c 4c 20 2a 2f 0a 0a ct all NULL */..
19100 2f 2a 0a 2a 2a 20 54 68 65 20 45 50 5f 50 72 6f /*.** The EP_Pro
19110 70 61 67 61 74 65 20 6d 61 73 6b 20 69 73 20 61 pagate mask is a
19120 20 73 65 74 20 6f 66 20 70 72 6f 70 65 72 74 69 set of properti
19130 65 73 20 74 68 61 74 20 61 75 74 6f 6d 61 74 69 es that automati
19140 63 61 6c 6c 79 20 70 72 6f 70 61 67 61 74 65 0a cally propagate.
19150 2a 2a 20 75 70 77 61 72 64 73 20 69 6e 74 6f 20 ** upwards into
19160 70 61 72 65 6e 74 20 6e 6f 64 65 73 2e 0a 2a 2f parent nodes..*/
19170 0a 23 64 65 66 69 6e 65 20 45 50 5f 50 72 6f 70 .#define EP_Prop
19180 61 67 61 74 65 20 28 45 50 5f 43 6f 6c 6c 61 74 agate (EP_Collat
19190 65 7c 45 50 5f 53 75 62 71 75 65 72 79 7c 45 50 e|EP_Subquery|EP
191a0 5f 48 61 73 46 75 6e 63 29 0a 0a 2f 2a 0a 2a 2a _HasFunc)../*.**
191b0 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 63 61 These macros ca
191c0 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 65 73 n be used to tes
191d0 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 t, set, or clear
191e0 20 62 69 74 73 20 69 6e 20 74 68 65 0a 2a 2a 20 bits in the.**
191f0 45 78 70 72 2e 66 6c 61 67 73 20 66 69 65 6c 64 Expr.flags field
19200 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 78 70 ..*/.#define Exp
19210 72 48 61 73 50 72 6f 70 65 72 74 79 28 45 2c 50 rHasProperty(E,P
19220 29 20 20 20 20 20 28 28 28 45 29 2d 3e 66 6c 61 ) (((E)->fla
19230 67 73 26 28 50 29 29 21 3d 30 29 0a 23 64 65 66 gs&(P))!=0).#def
19240 69 6e 65 20 45 78 70 72 48 61 73 41 6c 6c 50 72 ine ExprHasAllPr
19250 6f 70 65 72 74 79 28 45 2c 50 29 20 20 28 28 28 operty(E,P) (((
19260 45 29 2d 3e 66 6c 61 67 73 26 28 50 29 29 3d 3d E)->flags&(P))==
19270 28 50 29 29 0a 23 64 65 66 69 6e 65 20 45 78 70 (P)).#define Exp
19280 72 53 65 74 50 72 6f 70 65 72 74 79 28 45 2c 50 rSetProperty(E,P
19290 29 20 20 20 20 20 28 45 29 2d 3e 66 6c 61 67 73 ) (E)->flags
192a0 7c 3d 28 50 29 0a 23 64 65 66 69 6e 65 20 45 78 |=(P).#define Ex
192b0 70 72 43 6c 65 61 72 50 72 6f 70 65 72 74 79 28 prClearProperty(
192c0 45 2c 50 29 20 20 20 28 45 29 2d 3e 66 6c 61 67 E,P) (E)->flag
192d0 73 26 3d 7e 28 50 29 0a 0a 2f 2a 20 54 68 65 20 s&=~(P)../* The
192e0 45 78 70 72 53 65 74 56 56 41 50 72 6f 70 65 72 ExprSetVVAProper
192f0 74 79 28 29 20 6d 61 63 72 6f 20 69 73 20 75 73 ty() macro is us
19300 65 64 20 66 6f 72 20 56 65 72 69 66 69 63 61 74 ed for Verificat
19310 69 6f 6e 2c 20 56 61 6c 69 64 61 74 69 6f 6e 2c ion, Validation,
19320 0a 2a 2a 20 61 6e 64 20 41 63 63 72 65 64 69 74 .** and Accredit
19330 61 74 69 6f 6e 20 6f 6e 6c 79 2e 20 20 49 74 20 ation only. It
19340 77 6f 72 6b 73 20 6c 69 6b 65 20 45 78 70 72 53 works like ExprS
19350 65 74 50 72 6f 70 65 72 74 79 28 29 20 64 75 72 etProperty() dur
19360 69 6e 67 20 56 56 41 0a 2a 2a 20 70 72 6f 63 65 ing VVA.** proce
19370 73 73 65 73 20 62 75 74 20 69 73 20 61 20 6e 6f sses but is a no
19380 2d 6f 70 20 66 6f 72 20 64 65 6c 69 76 65 72 79 -op for delivery
19390 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
193a0 54 45 5f 44 45 42 55 47 0a 23 20 64 65 66 69 6e TE_DEBUG.# defin
193b0 65 20 45 78 70 72 53 65 74 56 56 41 50 72 6f 70 e ExprSetVVAProp
193c0 65 72 74 79 28 45 2c 50 29 20 20 28 45 29 2d 3e erty(E,P) (E)->
193d0 66 6c 61 67 73 7c 3d 28 50 29 0a 23 65 6c 73 65 flags|=(P).#else
193e0 0a 23 20 64 65 66 69 6e 65 20 45 78 70 72 53 65 .# define ExprSe
193f0 74 56 56 41 50 72 6f 70 65 72 74 79 28 45 2c 50 tVVAProperty(E,P
19400 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
19410 4d 61 63 72 6f 73 20 74 6f 20 64 65 74 65 72 6d Macros to determ
19420 69 6e 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f ine the number o
19430 66 20 62 79 74 65 73 20 72 65 71 75 69 72 65 64 f bytes required
19440 20 62 79 20 61 20 6e 6f 72 6d 61 6c 20 45 78 70 by a normal Exp
19450 72 0a 2a 2a 20 73 74 72 75 63 74 2c 20 61 6e 20 r.** struct, an
19460 45 78 70 72 20 73 74 72 75 63 74 20 77 69 74 68 Expr struct with
19470 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 the EP_Reduced
19480 66 6c 61 67 20 73 65 74 20 69 6e 20 45 78 70 72 flag set in Expr
19490 2e 66 6c 61 67 73 0a 2a 2a 20 61 6e 64 20 61 6e .flags.** and an
194a0 20 45 78 70 72 20 73 74 72 75 63 74 20 77 69 74 Expr struct wit
194b0 68 20 74 68 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e h the EP_TokenOn
194c0 6c 79 20 66 6c 61 67 20 73 65 74 2e 0a 2a 2f 0a ly flag set..*/.
194d0 23 64 65 66 69 6e 65 20 45 58 50 52 5f 46 55 4c #define EXPR_FUL
194e0 4c 53 49 5a 45 20 20 20 20 20 20 20 20 20 20 20 LSIZE
194f0 73 69 7a 65 6f 66 28 45 78 70 72 29 20 20 20 20 sizeof(Expr)
19500 20 20 20 20 20 20 20 2f 2a 20 46 75 6c 6c 20 73 /* Full s
19510 69 7a 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ize */.#define E
19520 58 50 52 5f 52 45 44 55 43 45 44 53 49 5a 45 20 XPR_REDUCEDSIZE
19530 20 20 20 20 20 20 20 6f 66 66 73 65 74 6f 66 28 offsetof(
19540 45 78 70 72 2c 69 54 61 62 6c 65 29 20 20 2f 2a Expr,iTable) /*
19550 20 43 6f 6d 6d 6f 6e 20 66 65 61 74 75 72 65 73 Common features
19560 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 */.#define EXPR
19570 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 5a 45 20 20 _TOKENONLYSIZE
19580 20 20 20 20 6f 66 66 73 65 74 6f 66 28 45 78 70 offsetof(Exp
19590 72 2c 70 4c 65 66 74 29 20 20 20 2f 2a 20 46 65 r,pLeft) /* Fe
195a0 77 65 72 20 66 65 61 74 75 72 65 73 20 2a 2f 0a wer features */.
195b0 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 73 20 70 61 73 ./*.** Flags pas
195c0 73 65 64 20 74 6f 20 74 68 65 20 73 71 6c 69 74 sed to the sqlit
195d0 65 33 45 78 70 72 44 75 70 28 29 20 66 75 6e 63 e3ExprDup() func
195e0 74 69 6f 6e 2e 20 53 65 65 20 74 68 65 20 68 65 tion. See the he
195f0 61 64 65 72 20 63 6f 6d 6d 65 6e 74 0a 2a 2a 20 ader comment.**
19600 61 62 6f 76 65 20 73 71 6c 69 74 65 33 45 78 70 above sqlite3Exp
19610 72 44 75 70 28 29 20 66 6f 72 20 64 65 74 61 69 rDup() for detai
19620 6c 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ls..*/.#define E
19630 58 50 52 44 55 50 5f 52 45 44 55 43 45 20 20 20 XPRDUP_REDUCE
19640 20 20 20 20 20 20 30 78 30 30 30 31 20 20 2f 2a 0x0001 /*
19650 20 55 73 65 64 20 72 65 64 75 63 65 64 2d 73 69 Used reduced-si
19660 7a 65 20 45 78 70 72 20 6e 6f 64 65 73 20 2a 2f ze Expr nodes */
19670 0a 0a 2f 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 6f ../*.** A list o
19680 66 20 65 78 70 72 65 73 73 69 6f 6e 73 2e 20 20 f expressions.
19690 45 61 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 Each expression
196a0 6d 61 79 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 68 may optionally h
196b0 61 76 65 20 61 0a 2a 2a 20 6e 61 6d 65 2e 20 20 ave a.** name.
196c0 41 6e 20 65 78 70 72 2f 6e 61 6d 65 20 63 6f 6d An expr/name com
196d0 62 69 6e 61 74 69 6f 6e 20 63 61 6e 20 62 65 20 bination can be
196e0 75 73 65 64 20 69 6e 20 73 65 76 65 72 61 6c 20 used in several
196f0 77 61 79 73 2c 20 73 75 63 68 0a 2a 2a 20 61 73 ways, such.** as
19700 20 74 68 65 20 6c 69 73 74 20 6f 66 20 22 65 78 the list of "ex
19710 70 72 20 41 53 20 49 44 22 20 66 69 65 6c 64 73 pr AS ID" fields
19720 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 20 22 53 45 following a "SE
19730 4c 45 43 54 22 20 6f 72 20 69 6e 20 74 68 65 0a LECT" or in the.
19740 2a 2a 20 6c 69 73 74 20 6f 66 20 22 49 44 20 3d ** list of "ID =
19750 20 65 78 70 72 22 20 69 74 65 6d 73 20 69 6e 20 expr" items in
19760 61 6e 20 55 50 44 41 54 45 2e 20 20 41 20 6c 69 an UPDATE. A li
19770 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e st of expression
19780 73 20 63 61 6e 0a 2a 2a 20 61 6c 73 6f 20 62 65 s can.** also be
19790 20 75 73 65 64 20 61 73 20 74 68 65 20 61 72 67 used as the arg
197a0 75 6d 65 6e 74 20 74 6f 20 61 20 66 75 6e 63 74 ument to a funct
197b0 69 6f 6e 2c 20 69 6e 20 77 68 69 63 68 20 63 61 ion, in which ca
197c0 73 65 20 74 68 65 20 61 2e 7a 4e 61 6d 65 0a 2a se the a.zName.*
197d0 2a 20 66 69 65 6c 64 20 69 73 20 6e 6f 74 20 75 * field is not u
197e0 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 65 sed..**.** By de
197f0 66 61 75 6c 74 20 74 68 65 20 45 78 70 72 2e 7a fault the Expr.z
19800 53 70 61 6e 20 66 69 65 6c 64 20 68 6f 6c 64 73 Span field holds
19810 20 61 20 68 75 6d 61 6e 2d 72 65 61 64 61 62 6c a human-readabl
19820 65 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 e description of
19830 0a 2a 2a 20 74 68 65 20 65 78 70 72 65 73 73 69 .** the expressi
19840 6f 6e 20 74 68 61 74 20 69 73 20 75 73 65 64 20 on that is used
19850 69 6e 20 74 68 65 20 67 65 6e 65 72 61 74 69 6f in the generatio
19860 6e 20 6f 66 20 65 72 72 6f 72 20 6d 65 73 73 61 n of error messa
19870 67 65 73 20 61 6e 64 0a 2a 2a 20 63 6f 6c 75 6d ges and.** colum
19880 6e 20 6c 61 62 65 6c 73 2e 20 20 49 6e 20 74 68 n labels. In th
19890 69 73 20 63 61 73 65 2c 20 45 78 70 72 2e 7a 53 is case, Expr.zS
198a0 70 61 6e 20 69 73 20 74 79 70 69 63 61 6c 6c 79 pan is typically
198b0 20 74 68 65 20 74 65 78 74 20 6f 66 20 61 0a 2a the text of a.*
198c0 2a 20 63 6f 6c 75 6d 6e 20 65 78 70 72 65 73 73 * column express
198d0 69 6f 6e 20 61 73 20 69 74 20 65 78 69 73 74 73 ion as it exists
198e0 20 69 6e 20 61 20 53 45 4c 45 43 54 20 73 74 61 in a SELECT sta
198f0 74 65 6d 65 6e 74 2e 20 20 48 6f 77 65 76 65 72 tement. However
19900 2c 20 69 66 0a 2a 2a 20 74 68 65 20 62 53 70 61 , if.** the bSpa
19910 6e 49 73 54 61 62 20 66 6c 61 67 20 69 73 20 73 nIsTab flag is s
19920 65 74 2c 20 74 68 65 6e 20 7a 53 70 61 6e 20 69 et, then zSpan i
19930 73 20 6f 76 65 72 6c 6f 61 64 65 64 20 74 6f 20 s overloaded to
19940 6d 65 61 6e 20 74 68 65 20 6e 61 6d 65 0a 2a 2a mean the name.**
19950 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 63 of the result c
19960 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 20 66 6f 72 olumn in the for
19970 6d 3a 20 44 41 54 41 42 41 53 45 2e 54 41 42 4c m: DATABASE.TABL
19980 45 2e 43 4f 4c 55 4d 4e 2e 20 20 54 68 69 73 20 E.COLUMN. This
19990 6c 61 74 65 72 0a 2a 2a 20 66 6f 72 6d 20 69 73 later.** form is
199a0 20 75 73 65 64 20 66 6f 72 20 6e 61 6d 65 20 72 used for name r
199b0 65 73 6f 6c 75 74 69 6f 6e 20 77 69 74 68 20 6e esolution with n
199c0 65 73 74 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 ested FROM claus
199d0 65 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 es..*/.struct Ex
199e0 70 72 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e prList {. int n
199f0 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 Expr;
19a00 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
19a10 78 70 72 65 73 73 69 6f 6e 73 20 6f 6e 20 74 68 xpressions on th
19a20 65 20 6c 69 73 74 20 2a 2f 0a 20 20 73 74 72 75 e list */. stru
19a30 63 74 20 45 78 70 72 4c 69 73 74 5f 69 74 65 6d ct ExprList_item
19a40 20 7b 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 65 { /* For each e
19a50 78 70 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 xpression in the
19a60 20 6c 69 73 74 20 2a 2f 0a 20 20 20 20 45 78 70 list */. Exp
19a70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 r *pExpr;
19a80 20 20 20 20 20 2f 2a 20 54 68 65 20 70 61 72 73 /* The pars
19a90 65 20 74 72 65 65 20 66 6f 72 20 74 68 69 73 20 e tree for this
19aa0 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 expression */.
19ab0 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
19ac0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b /* Tok
19ad0 65 6e 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 en associated wi
19ae0 74 68 20 74 68 69 73 20 65 78 70 72 65 73 73 69 th this expressi
19af0 6f 6e 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a on */. char *
19b00 7a 53 70 61 6e 3b 20 20 20 20 20 20 20 20 20 20 zSpan;
19b10 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 74 65 /* Original te
19b20 78 74 20 6f 66 20 74 68 65 20 65 78 70 72 65 73 xt of the expres
19b30 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 75 38 20 73 sion */. u8 s
19b40 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 ortOrder;
19b50 20 20 20 20 2f 2a 20 31 20 66 6f 72 20 44 45 53 /* 1 for DES
19b60 43 20 6f 72 20 30 20 66 6f 72 20 41 53 43 20 2a C or 0 for ASC *
19b70 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 64 /. unsigned d
19b80 6f 6e 65 20 3a 31 3b 20 20 20 20 20 20 20 2f 2a one :1; /*
19b90 20 41 20 66 6c 61 67 20 74 6f 20 69 6e 64 69 63 A flag to indic
19ba0 61 74 65 20 77 68 65 6e 20 70 72 6f 63 65 73 73 ate when process
19bb0 69 6e 67 20 69 73 20 66 69 6e 69 73 68 65 64 20 ing is finished
19bc0 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 */. unsigned
19bd0 62 53 70 61 6e 49 73 54 61 62 20 3a 31 3b 20 2f bSpanIsTab :1; /
19be0 2a 20 7a 53 70 61 6e 20 68 6f 6c 64 73 20 44 42 * zSpan holds DB
19bf0 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 20 2a 2f .TABLE.COLUMN */
19c00 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 72 65 . unsigned re
19c10 75 73 61 62 6c 65 20 3a 31 3b 20 20 20 2f 2a 20 usable :1; /*
19c20 43 6f 6e 73 74 61 6e 74 20 65 78 70 72 65 73 73 Constant express
19c30 69 6f 6e 20 69 73 20 72 65 75 73 61 62 6c 65 20 ion is reusable
19c40 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b 0a 20 */. union {.
19c50 20 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 20 struct {.
19c60 20 20 20 20 20 20 75 31 36 20 69 4f 72 64 65 72 u16 iOrder
19c70 42 79 43 6f 6c 3b 20 20 20 20 20 20 2f 2a 20 46 ByCol; /* F
19c80 6f 72 20 4f 52 44 45 52 20 42 59 2c 20 63 6f 6c or ORDER BY, col
19c90 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e 20 72 65 umn number in re
19ca0 73 75 6c 74 20 73 65 74 20 2a 2f 0a 20 20 20 20 sult set */.
19cb0 20 20 20 20 75 31 36 20 69 41 6c 69 61 73 3b 20 u16 iAlias;
19cc0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 /* Ind
19cd0 65 78 20 69 6e 74 6f 20 50 61 72 73 65 2e 61 41 ex into Parse.aA
19ce0 6c 69 61 73 5b 5d 20 66 6f 72 20 7a 4e 61 6d 65 lias[] for zName
19cf0 20 2a 2f 0a 20 20 20 20 20 20 7d 20 78 3b 0a 20 */. } x;.
19d00 20 20 20 20 20 69 6e 74 20 69 43 6f 6e 73 74 45 int iConstE
19d10 78 70 72 52 65 67 3b 20 20 20 20 20 20 2f 2a 20 xprReg; /*
19d20 52 65 67 69 73 74 65 72 20 69 6e 20 77 68 69 63 Register in whic
19d30 68 20 45 78 70 72 20 76 61 6c 75 65 20 69 73 20 h Expr value is
19d40 63 61 63 68 65 64 20 2a 2f 0a 20 20 20 20 7d 20 cached */. }
19d50 75 3b 0a 20 20 7d 20 61 5b 31 5d 3b 20 20 20 20 u;. } a[1];
19d60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
19d70 20 4f 6e 65 20 73 6c 6f 74 20 66 6f 72 20 65 61 One slot for ea
19d80 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e ch expression in
19d90 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a the list */.};.
19da0 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
19db0 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ce of this struc
19dc0 74 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 61 20 ture can hold a
19dd0 73 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 20 69 simple list of i
19de0 64 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a 20 73 dentifiers,.** s
19df0 75 63 68 20 61 73 20 74 68 65 20 6c 69 73 74 20 uch as the list
19e00 22 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 20 66 "a,b,c" in the f
19e10 6f 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 6d 65 ollowing stateme
19e20 6e 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 nts:.**.**
19e30 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 2c INSERT INTO t(a,
19e40 62 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e 2e 3b b,c) VALUES ...;
19e50 0a 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 20 .** CREATE
19e60 49 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 28 61 INDEX idx ON t(a
19e70 2c 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 20 43 ,b,c);.** C
19e80 52 45 41 54 45 20 54 52 49 47 47 45 52 20 74 72 REATE TRIGGER tr
19e90 69 67 20 42 45 46 4f 52 45 20 55 50 44 41 54 45 ig BEFORE UPDATE
19ea0 20 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e ON t(a,b,c) ...
19eb0 3b 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 4c 69 ;.**.** The IdLi
19ec0 73 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 20 69 st.a.idx field i
19ed0 73 20 75 73 65 64 20 77 68 65 6e 20 74 68 65 20 s used when the
19ee0 49 64 4c 69 73 74 20 72 65 70 72 65 73 65 6e 74 IdList represent
19ef0 73 20 74 68 65 20 6c 69 73 74 20 6f 66 0a 2a 2a s the list of.**
19f00 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 66 column names af
19f10 74 65 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 ter a table name
19f20 20 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 73 74 in an INSERT st
19f30 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 68 65 atement. In the
19f40 20 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a 2a 2a statement.**.**
19f50 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f INSERT INTO
19f60 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a 2a 2a t(a,b,c) ....**
19f70 0a 2a 2a 20 49 66 20 22 61 22 20 69 73 20 74 68 .** If "a" is th
19f80 65 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 6f 66 e k-th column of
19f90 20 74 61 62 6c 65 20 22 74 22 2c 20 74 68 65 6e table "t", then
19fa0 20 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 64 78 IdList.a[0].idx
19fb0 3d 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 ==k..*/.struct I
19fc0 64 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 63 74 dList {. struct
19fd0 20 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b 0a 20 IdList_item {.
19fe0 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 char *zName;
19ff0 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
1a000 74 68 65 20 69 64 65 6e 74 69 66 69 65 72 20 2a the identifier *
1a010 2f 0a 20 20 20 20 69 6e 74 20 69 64 78 3b 20 20 /. int idx;
1a020 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 /* Index
1a030 20 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 2e 61 in some Table.a
1a040 43 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c 75 6d Col[] of a colum
1a050 6e 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 2a 2f n named zName */
1a060 0a 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 20 6e . } *a;. int n
1a070 49 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e Id; /* N
1a080 75 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 69 66 umber of identif
1a090 69 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 73 74 iers on the list
1a0a0 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 */.};../*.** Th
1a0b0 65 20 62 69 74 6d 61 73 6b 20 64 61 74 61 74 79 e bitmask dataty
1a0c0 70 65 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 pe defined below
1a0d0 20 69 73 20 75 73 65 64 20 66 6f 72 20 76 61 72 is used for var
1a0e0 69 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 69 6f ious optimizatio
1a0f0 6e 73 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e 67 69 ns..**.** Changi
1a100 6e 67 20 74 68 69 73 20 66 72 6f 6d 20 61 20 36 ng this from a 6
1a110 34 2d 62 69 74 20 74 6f 20 61 20 33 32 2d 62 69 4-bit to a 32-bi
1a120 74 20 74 79 70 65 20 6c 69 6d 69 74 73 20 74 68 t type limits th
1a130 65 20 6e 75 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 e number of.** t
1a140 61 62 6c 65 73 20 69 6e 20 61 20 6a 6f 69 6e 20 ables in a join
1a150 74 6f 20 33 32 20 69 6e 73 74 65 61 64 20 6f 66 to 32 instead of
1a160 20 36 34 2e 20 20 42 75 74 20 69 74 20 61 6c 73 64. But it als
1a170 6f 20 72 65 64 75 63 65 73 20 74 68 65 20 73 69 o reduces the si
1a180 7a 65 0a 2a 2a 20 6f 66 20 74 68 65 20 6c 69 62 ze.** of the lib
1a190 72 61 72 79 20 62 79 20 37 33 38 20 62 79 74 65 rary by 738 byte
1a1a0 73 20 6f 6e 20 69 78 38 36 2e 0a 2a 2f 0a 23 69 s on ix86..*/.#i
1a1b0 66 64 65 66 20 53 51 4c 49 54 45 5f 42 49 54 4d fdef SQLITE_BITM
1a1c0 41 53 4b 5f 54 59 50 45 0a 20 20 74 79 70 65 64 ASK_TYPE. typed
1a1d0 65 66 20 53 51 4c 49 54 45 5f 42 49 54 4d 41 53 ef SQLITE_BITMAS
1a1e0 4b 5f 54 59 50 45 20 42 69 74 6d 61 73 6b 3b 0a K_TYPE Bitmask;.
1a1f0 23 65 6c 73 65 0a 20 20 74 79 70 65 64 65 66 20 #else. typedef
1a200 75 36 34 20 42 69 74 6d 61 73 6b 3b 0a 23 65 6e u64 Bitmask;.#en
1a210 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e dif../*.** The n
1a220 75 6d 62 65 72 20 6f 66 20 62 69 74 73 20 69 6e umber of bits in
1a230 20 61 20 42 69 74 6d 61 73 6b 2e 20 20 22 42 4d a Bitmask. "BM
1a240 53 22 20 6d 65 61 6e 73 20 22 42 69 74 4d 61 73 S" means "BitMas
1a250 6b 20 53 69 7a 65 22 2e 0a 2a 2f 0a 23 64 65 66 k Size"..*/.#def
1a260 69 6e 65 20 42 4d 53 20 20 28 28 69 6e 74 29 28 ine BMS ((int)(
1a270 73 69 7a 65 6f 66 28 42 69 74 6d 61 73 6b 29 2a sizeof(Bitmask)*
1a280 38 29 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 62 69 74 8))../*.** A bit
1a290 20 69 6e 20 61 20 42 69 74 6d 61 73 6b 0a 2a 2f in a Bitmask.*/
1a2a0 0a 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 54 .#define MASKBIT
1a2b0 28 6e 29 20 20 20 28 28 28 42 69 74 6d 61 73 6b (n) (((Bitmask
1a2c0 29 31 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e )1)<<(n)).#defin
1a2d0 65 20 4d 41 53 4b 42 49 54 33 32 28 6e 29 20 28 e MASKBIT32(n) (
1a2e0 28 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 31 ((unsigned int)1
1a2f0 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e 65 20 )<<(n)).#define
1a300 41 4c 4c 42 49 54 53 20 20 20 20 20 20 28 28 42 ALLBITS ((B
1a310 69 74 6d 61 73 6b 29 2d 31 29 0a 0a 2f 2a 0a 2a itmask)-1)../*.*
1a320 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
1a330 73 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 structure descri
1a340 62 65 73 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 bes the FROM cla
1a350 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 54 20 use of a SELECT
1a360 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 20 45 61 statement..** Ea
1a370 63 68 20 74 61 62 6c 65 20 6f 72 20 73 75 62 71 ch table or subq
1a380 75 65 72 79 20 69 6e 20 74 68 65 20 46 52 4f 4d uery in the FROM
1a390 20 63 6c 61 75 73 65 20 69 73 20 61 20 73 65 70 clause is a sep
1a3a0 61 72 61 74 65 20 65 6c 65 6d 65 6e 74 20 6f 66 arate element of
1a3b0 0a 2a 2a 20 74 68 65 20 53 72 63 4c 69 73 74 2e .** the SrcList.
1a3c0 61 5b 5d 20 61 72 72 61 79 2e 0a 2a 2a 0a 2a 2a a[] array..**.**
1a3d0 20 57 69 74 68 20 74 68 65 20 61 64 64 69 74 69 With the additi
1a3e0 6f 6e 20 6f 66 20 6d 75 6c 74 69 70 6c 65 20 64 on of multiple d
1a3f0 61 74 61 62 61 73 65 20 73 75 70 70 6f 72 74 2c atabase support,
1a400 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
1a410 74 72 75 63 74 75 72 65 0a 2a 2a 20 63 61 6e 20 tructure.** can
1a420 61 6c 73 6f 20 62 65 20 75 73 65 64 20 74 6f 20 also be used to
1a430 64 65 73 63 72 69 62 65 20 61 20 70 61 72 74 69 describe a parti
1a440 63 75 6c 61 72 20 74 61 62 6c 65 20 73 75 63 68 cular table such
1a450 20 61 73 20 74 68 65 20 74 61 62 6c 65 20 74 68 as the table th
1a460 61 74 0a 2a 2a 20 69 73 20 6d 6f 64 69 66 69 65 at.** is modifie
1a470 64 20 62 79 20 61 6e 20 49 4e 53 45 52 54 2c 20 d by an INSERT,
1a480 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 41 54 DELETE, or UPDAT
1a490 45 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e E statement. In
1a4a0 20 73 74 61 6e 64 61 72 64 20 53 51 4c 2c 0a 2a standard SQL,.*
1a4b0 2a 20 73 75 63 68 20 61 20 74 61 62 6c 65 20 6d * such a table m
1a4c0 75 73 74 20 62 65 20 61 20 73 69 6d 70 6c 65 20 ust be a simple
1a4d0 6e 61 6d 65 3a 20 49 44 2e 20 20 42 75 74 20 69 name: ID. But i
1a4e0 6e 20 53 51 4c 69 74 65 2c 20 74 68 65 20 74 61 n SQLite, the ta
1a4f0 62 6c 65 20 63 61 6e 0a 2a 2a 20 6e 6f 77 20 62 ble can.** now b
1a500 65 20 69 64 65 6e 74 69 66 69 65 64 20 62 79 20 e identified by
1a510 61 20 64 61 74 61 62 61 73 65 20 6e 61 6d 65 2c a database name,
1a520 20 61 20 64 6f 74 2c 20 74 68 65 6e 20 74 68 65 a dot, then the
1a530 20 74 61 62 6c 65 20 6e 61 6d 65 3a 20 49 44 2e table name: ID.
1a540 49 44 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6a 6f ID..**.** The jo
1a550 69 6e 74 79 70 65 20 73 74 61 72 74 73 20 6f 75 intype starts ou
1a560 74 20 73 68 6f 77 69 6e 67 20 74 68 65 20 6a 6f t showing the jo
1a570 69 6e 20 74 79 70 65 20 62 65 74 77 65 65 6e 20 in type between
1a580 74 68 65 20 63 75 72 72 65 6e 74 20 74 61 62 6c the current tabl
1a590 65 0a 2a 2a 20 61 6e 64 20 74 68 65 20 6e 65 78 e.** and the nex
1a5a0 74 20 74 61 62 6c 65 20 6f 6e 20 74 68 65 20 6c t table on the l
1a5b0 69 73 74 2e 20 20 54 68 65 20 70 61 72 73 65 72 ist. The parser
1a5c0 20 62 75 69 6c 64 73 20 74 68 65 20 6c 69 73 74 builds the list
1a5d0 20 74 68 69 73 20 77 61 79 2e 0a 2a 2a 20 42 75 this way..** Bu
1a5e0 74 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 t sqlite3SrcList
1a5f0 53 68 69 66 74 4a 6f 69 6e 54 79 70 65 28 29 20 ShiftJoinType()
1a600 6c 61 74 65 72 20 73 68 69 66 74 73 20 74 68 65 later shifts the
1a610 20 6a 6f 69 6e 74 79 70 65 73 20 73 6f 20 74 68 jointypes so th
1a620 61 74 20 65 61 63 68 0a 2a 2a 20 6a 6f 69 6e 74 at each.** joint
1a630 79 70 65 20 65 78 70 72 65 73 73 65 73 20 74 68 ype expresses th
1a640 65 20 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 e join between t
1a650 68 65 20 74 61 62 6c 65 20 61 6e 64 20 74 68 65 he table and the
1a660 20 70 72 65 76 69 6f 75 73 20 74 61 62 6c 65 2e previous table.
1a670 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 63 6f .**.** In the co
1a680 6c 55 73 65 64 20 66 69 65 6c 64 2c 20 74 68 65 lUsed field, the
1a690 20 68 69 67 68 2d 6f 72 64 65 72 20 62 69 74 20 high-order bit
1a6a0 28 62 69 74 20 36 33 29 20 69 73 20 73 65 74 20 (bit 63) is set
1a6b0 69 66 20 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 if the table.**
1a6c0 63 6f 6e 74 61 69 6e 73 20 6d 6f 72 65 20 74 68 contains more th
1a6d0 61 6e 20 36 33 20 63 6f 6c 75 6d 6e 73 20 61 6e an 63 columns an
1a6e0 64 20 74 68 65 20 36 34 2d 74 68 20 6f 72 20 6c d the 64-th or l
1a6f0 61 74 65 72 20 63 6f 6c 75 6d 6e 20 69 73 20 75 ater column is u
1a700 73 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 sed..*/.struct S
1a710 72 63 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e rcList {. int n
1a720 53 72 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e Src; /* N
1a730 75 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 73 20 umber of tables
1a740 6f 72 20 73 75 62 71 75 65 72 69 65 73 20 69 6e or subqueries in
1a750 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 the FROM clause
1a760 20 2a 2f 0a 20 20 75 33 32 20 6e 41 6c 6c 6f 63 */. u32 nAlloc
1a770 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 ; /* Number
1a780 20 6f 66 20 65 6e 74 72 69 65 73 20 61 6c 6c 6f of entries allo
1a790 63 61 74 65 64 20 69 6e 20 61 5b 5d 20 62 65 6c cated in a[] bel
1a7a0 6f 77 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 53 ow */. struct S
1a7b0 72 63 4c 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 rcList_item {.
1a7c0 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d Schema *pSchem
1a7d0 61 3b 20 20 2f 2a 20 53 63 68 65 6d 61 20 74 6f a; /* Schema to
1a7e0 20 77 68 69 63 68 20 74 68 69 73 20 69 74 65 6d which this item
1a7f0 20 69 73 20 66 69 78 65 64 20 2a 2f 0a 20 20 20 is fixed */.
1a800 20 63 68 61 72 20 2a 7a 44 61 74 61 62 61 73 65 char *zDatabase
1a810 3b 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 64 61 ; /* Name of da
1a820 74 61 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 74 tabase holding t
1a830 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 his table */.
1a840 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 char *zName;
1a850 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 /* Name of th
1a860 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 e table */. c
1a870 68 61 72 20 2a 7a 41 6c 69 61 73 3b 20 20 20 20 har *zAlias;
1a880 20 2f 2a 20 54 68 65 20 22 42 22 20 70 61 72 74 /* The "B" part
1a890 20 6f 66 20 61 20 22 41 20 41 53 20 42 22 20 70 of a "A AS B" p
1a8a0 68 72 61 73 65 2e 20 20 7a 4e 61 6d 65 20 69 73 hrase. zName is
1a8b0 20 74 68 65 20 22 41 22 20 2a 2f 0a 20 20 20 20 the "A" */.
1a8c0 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 Table *pTab;
1a8d0 20 20 2f 2a 20 41 6e 20 53 51 4c 20 74 61 62 6c /* An SQL tabl
1a8e0 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 e corresponding
1a8f0 74 6f 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 20 to zName */.
1a900 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b Select *pSelect;
1a910 20 20 2f 2a 20 41 20 53 45 4c 45 43 54 20 73 74 /* A SELECT st
1a920 61 74 65 6d 65 6e 74 20 75 73 65 64 20 69 6e 20 atement used in
1a930 70 6c 61 63 65 20 6f 66 20 61 20 74 61 62 6c 65 place of a table
1a940 20 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 69 6e 74 name */. int
1a950 20 61 64 64 72 46 69 6c 6c 53 75 62 3b 20 20 2f addrFillSub; /
1a960 2a 20 41 64 64 72 65 73 73 20 6f 66 20 73 75 62 * Address of sub
1a970 72 6f 75 74 69 6e 65 20 74 6f 20 6d 61 6e 69 66 routine to manif
1a980 65 73 74 20 61 20 73 75 62 71 75 65 72 79 20 2a est a subquery *
1a990 2f 0a 20 20 20 20 69 6e 74 20 72 65 67 52 65 74 /. int regRet
1a9a0 75 72 6e 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 urn; /* Regis
1a9b0 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 65 74 75 ter holding retu
1a9c0 72 6e 20 61 64 64 72 65 73 73 20 6f 66 20 61 64 rn address of ad
1a9d0 64 72 46 69 6c 6c 53 75 62 20 2a 2f 0a 20 20 20 drFillSub */.
1a9e0 20 69 6e 74 20 72 65 67 52 65 73 75 6c 74 3b 20 int regResult;
1a9f0 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 73 20 /* Registers
1aa00 68 6f 6c 64 69 6e 67 20 72 65 73 75 6c 74 73 20 holding results
1aa10 6f 66 20 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 of a co-routine
1aa20 2a 2f 0a 20 20 20 20 73 74 72 75 63 74 20 7b 0a */. struct {.
1aa30 20 20 20 20 20 20 75 38 20 6a 6f 69 6e 74 79 70 u8 jointyp
1aa40 65 3b 20 20 20 20 20 20 2f 2a 20 54 79 70 65 20 e; /* Type
1aa50 6f 66 20 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 of join between
1aa60 74 68 69 73 20 74 61 62 6c 65 20 61 6e 64 20 74 this table and t
1aa70 68 65 20 70 72 65 76 69 6f 75 73 20 2a 2f 0a 20 he previous */.
1aa80 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 6e 6f unsigned no
1aa90 74 49 6e 64 65 78 65 64 20 3a 31 3b 20 20 20 20 tIndexed :1;
1aaa0 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 72 65 /* True if there
1aab0 20 69 73 20 61 20 4e 4f 54 20 49 4e 44 45 58 45 is a NOT INDEXE
1aac0 44 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 D clause */.
1aad0 20 20 75 6e 73 69 67 6e 65 64 20 69 73 49 6e 64 unsigned isInd
1aae0 65 78 65 64 42 79 20 3a 31 3b 20 20 20 2f 2a 20 exedBy :1; /*
1aaf0 54 72 75 65 20 69 66 20 74 68 65 72 65 20 69 73 True if there is
1ab00 20 61 6e 20 49 4e 44 45 58 45 44 20 42 59 20 63 an INDEXED BY c
1ab10 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 75 lause */. u
1ab20 6e 73 69 67 6e 65 64 20 69 73 54 61 62 46 75 6e nsigned isTabFun
1ab30 63 20 3a 31 3b 20 20 20 20 20 2f 2a 20 54 72 75 c :1; /* Tru
1ab40 65 20 69 66 20 74 61 62 6c 65 2d 76 61 6c 75 65 e if table-value
1ab50 64 2d 66 75 6e 63 74 69 6f 6e 20 73 79 6e 74 61 d-function synta
1ab60 78 20 2a 2f 0a 20 20 20 20 20 20 75 6e 73 69 67 x */. unsig
1ab70 6e 65 64 20 69 73 43 6f 72 72 65 6c 61 74 65 64 ned isCorrelated
1ab80 20 3a 31 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 :1; /* True if
1ab90 20 73 75 62 2d 71 75 65 72 79 20 69 73 20 63 6f sub-query is co
1aba0 72 72 65 6c 61 74 65 64 20 2a 2f 0a 20 20 20 20 rrelated */.
1abb0 20 20 75 6e 73 69 67 6e 65 64 20 76 69 61 43 6f unsigned viaCo
1abc0 72 6f 75 74 69 6e 65 20 3a 31 3b 20 20 2f 2a 20 routine :1; /*
1abd0 49 6d 70 6c 65 6d 65 6e 74 65 64 20 61 73 20 61 Implemented as a
1abe0 20 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 co-routine */.
1abf0 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 73 unsigned is
1ac00 52 65 63 75 72 73 69 76 65 20 3a 31 3b 20 20 20 Recursive :1;
1ac10 2f 2a 20 54 72 75 65 20 66 6f 72 20 72 65 63 75 /* True for recu
1ac20 72 73 69 76 65 20 72 65 66 65 72 65 6e 63 65 20 rsive reference
1ac30 69 6e 20 57 49 54 48 20 2a 2f 0a 20 20 20 20 7d in WITH */. }
1ac40 20 66 67 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c fg;.#ifndef SQL
1ac50 49 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e ITE_OMIT_EXPLAIN
1ac60 0a 20 20 20 20 75 38 20 69 53 65 6c 65 63 74 49 . u8 iSelectI
1ac70 64 3b 20 20 20 20 20 2f 2a 20 49 66 20 70 53 65 d; /* If pSe
1ac80 6c 65 63 74 21 3d 30 2c 20 74 68 65 20 69 64 20 lect!=0, the id
1ac90 6f 66 20 74 68 65 20 73 75 62 2d 73 65 6c 65 63 of the sub-selec
1aca0 74 20 69 6e 20 45 51 50 20 2a 2f 0a 23 65 6e 64 t in EQP */.#end
1acb0 69 66 0a 20 20 20 20 69 6e 74 20 69 43 75 72 73 if. int iCurs
1acc0 6f 72 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 or; /* The
1acd0 56 44 42 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 VDBE cursor numb
1ace0 65 72 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 er used to acces
1acf0 73 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a s this table */.
1ad00 20 20 20 20 45 78 70 72 20 2a 70 4f 6e 3b 20 20 Expr *pOn;
1ad10 20 20 20 20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 /* The ON
1ad20 63 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e clause of a join
1ad30 20 2a 2f 0a 20 20 20 20 49 64 4c 69 73 74 20 2a */. IdList *
1ad40 70 55 73 69 6e 67 3b 20 20 20 2f 2a 20 54 68 65 pUsing; /* The
1ad50 20 55 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 USING clause of
1ad60 20 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 a join */. B
1ad70 69 74 6d 61 73 6b 20 63 6f 6c 55 73 65 64 3b 20 itmask colUsed;
1ad80 20 2f 2a 20 42 69 74 20 4e 20 28 31 3c 3c 4e 29 /* Bit N (1<<N)
1ad90 20 73 65 74 20 69 66 20 63 6f 6c 75 6d 6e 20 4e set if column N
1ada0 20 6f 66 20 70 54 61 62 20 69 73 20 75 73 65 64 of pTab is used
1adb0 20 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b 0a */. union {.
1adc0 20 20 20 20 20 20 63 68 61 72 20 2a 7a 49 6e 64 char *zInd
1add0 65 78 65 64 42 79 3b 20 20 20 20 2f 2a 20 49 64 exedBy; /* Id
1ade0 65 6e 74 69 66 69 65 72 20 66 72 6f 6d 20 22 49 entifier from "I
1adf0 4e 44 45 58 45 44 20 42 59 20 3c 7a 49 6e 64 65 NDEXED BY <zInde
1ae00 78 3e 22 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 x>" clause */.
1ae10 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 46 ExprList *pF
1ae20 75 6e 63 41 72 67 3b 20 20 2f 2a 20 41 72 67 75 uncArg; /* Argu
1ae30 6d 65 6e 74 73 20 74 6f 20 74 61 62 6c 65 2d 76 ments to table-v
1ae40 61 6c 75 65 64 2d 66 75 6e 63 74 69 6f 6e 20 2a alued-function *
1ae50 2f 0a 20 20 20 20 7d 20 75 31 3b 0a 20 20 20 20 /. } u1;.
1ae60 49 6e 64 65 78 20 2a 70 49 42 49 6e 64 65 78 3b Index *pIBIndex;
1ae70 20 20 2f 2a 20 49 6e 64 65 78 20 73 74 72 75 63 /* Index struc
1ae80 74 75 72 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 ture correspondi
1ae90 6e 67 20 74 6f 20 75 31 2e 7a 49 6e 64 65 78 65 ng to u1.zIndexe
1aea0 64 42 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b dBy */. } a[1];
1aeb0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1aec0 4f 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 61 One entry for ea
1aed0 63 68 20 69 64 65 6e 74 69 66 69 65 72 20 6f 6e ch identifier on
1aee0 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a the list */.};.
1aef0 0a 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 65 64 ./*.** Permitted
1af00 20 76 61 6c 75 65 73 20 6f 66 20 74 68 65 20 53 values of the S
1af10 72 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 rcList.a.jointyp
1af20 65 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 e field.*/.#defi
1af30 6e 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 20 20 ne JT_INNER
1af40 30 78 30 30 30 31 20 20 20 20 2f 2a 20 41 6e 79 0x0001 /* Any
1af50 20 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 20 6f kind of inner o
1af60 72 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a r cross join */.
1af70 23 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f 53 53 #define JT_CROSS
1af80 20 20 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 0x0002 /
1af90 2a 20 45 78 70 6c 69 63 69 74 20 75 73 65 20 6f * Explicit use o
1afa0 66 20 74 68 65 20 43 52 4f 53 53 20 6b 65 79 77 f the CROSS keyw
1afb0 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a ord */.#define J
1afc0 54 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 30 30 T_NATURAL 0x00
1afd0 30 34 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 04 /* True fo
1afe0 72 20 61 20 22 6e 61 74 75 72 61 6c 22 20 6a 6f r a "natural" jo
1aff0 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 in */.#define JT
1b000 5f 4c 45 46 54 20 20 20 20 20 20 30 78 30 30 30 _LEFT 0x000
1b010 38 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 75 74 8 /* Left out
1b020 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 er join */.#defi
1b030 6e 65 20 4a 54 5f 52 49 47 48 54 20 20 20 20 20 ne JT_RIGHT
1b040 30 78 30 30 31 30 20 20 20 20 2f 2a 20 52 69 67 0x0010 /* Rig
1b050 68 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 2a 2f ht outer join */
1b060 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 54 45 .#define JT_OUTE
1b070 52 20 20 20 20 20 30 78 30 30 32 30 20 20 20 20 R 0x0020
1b080 2f 2a 20 54 68 65 20 22 4f 55 54 45 52 22 20 6b /* The "OUTER" k
1b090 65 79 77 6f 72 64 20 69 73 20 70 72 65 73 65 6e eyword is presen
1b0a0 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f t */.#define JT_
1b0b0 45 52 52 4f 52 20 20 20 20 20 30 78 30 30 34 30 ERROR 0x0040
1b0c0 20 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f /* unknown o
1b0d0 72 20 75 6e 73 75 70 70 6f 72 74 65 64 20 6a 6f r unsupported jo
1b0e0 69 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a in type */.../*.
1b0f0 2a 2a 20 46 6c 61 67 73 20 61 70 70 72 6f 70 72 ** Flags appropr
1b100 69 61 74 65 20 66 6f 72 20 74 68 65 20 77 63 74 iate for the wct
1b110 72 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 74 65 rlFlags paramete
1b120 72 20 6f 66 20 73 71 6c 69 74 65 33 57 68 65 72 r of sqlite3Wher
1b130 65 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 eBegin().** and
1b140 74 68 65 20 57 68 65 72 65 49 6e 66 6f 2e 77 63 the WhereInfo.wc
1b150 74 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 72 2e trlFlags member.
1b160 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e .**.** Value con
1b170 73 74 72 61 69 6e 74 73 20 28 65 6e 66 6f 72 63 straints (enforc
1b180 65 64 20 76 69 61 20 61 73 73 65 72 74 28 29 29 ed via assert())
1b190 3a 0a 2a 2a 20 20 20 20 20 57 48 45 52 45 5f 55 :.** WHERE_U
1b1a0 53 45 5f 4c 49 4d 49 54 20 20 3d 3d 20 53 46 5f SE_LIMIT == SF_
1b1b0 46 69 78 65 64 4c 69 6d 69 74 0a 2a 2f 0a 23 64 FixedLimit.*/.#d
1b1c0 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 45 efine WHERE_ORDE
1b1d0 52 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 78 30 RBY_NORMAL 0x0
1b1e0 30 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a 2f 0a 000 /* No-op */.
1b1f0 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 #define WHERE_OR
1b200 44 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 20 30 DERBY_MIN 0
1b210 78 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 20 42 x0001 /* ORDER B
1b220 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 Y processing for
1b230 20 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f 0a 23 min() func */.#
1b240 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 define WHERE_ORD
1b250 45 52 42 59 5f 4d 41 58 20 20 20 20 20 20 30 78 ERBY_MAX 0x
1b260 30 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 42 59 0002 /* ORDER BY
1b270 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 20 processing for
1b280 6d 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a 23 64 max() func */.#d
1b290 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 efine WHERE_ONEP
1b2a0 41 53 53 5f 44 45 53 49 52 45 44 20 20 30 78 30 ASS_DESIRED 0x0
1b2b0 30 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f 20 64 004 /* Want to d
1b2c0 6f 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 41 54 o one-pass UPDAT
1b2d0 45 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 65 66 E/DELETE */.#def
1b2e0 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 41 53 ine WHERE_ONEPAS
1b2f0 53 5f 4d 55 4c 54 49 52 4f 57 20 30 78 30 30 30 S_MULTIROW 0x000
1b300 38 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 73 20 8 /* ONEPASS is
1b310 6f 6b 20 77 69 74 68 20 6d 75 6c 74 69 70 6c 65 ok with multiple
1b320 20 72 6f 77 73 20 2a 2f 0a 23 64 65 66 69 6e 65 rows */.#define
1b330 20 57 48 45 52 45 5f 44 55 50 4c 49 43 41 54 45 WHERE_DUPLICATE
1b340 53 5f 4f 4b 20 20 20 20 30 78 30 30 31 30 20 2f S_OK 0x0010 /
1b350 2a 20 4f 6b 20 74 6f 20 72 65 74 75 72 6e 20 61 * Ok to return a
1b360 20 72 6f 77 20 6d 6f 72 65 20 74 68 61 6e 20 6f row more than o
1b370 6e 63 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 nce */.#define W
1b380 48 45 52 45 5f 4f 52 5f 53 55 42 43 4c 41 55 53 HERE_OR_SUBCLAUS
1b390 45 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 E 0x0020 /*
1b3a0 50 72 6f 63 65 73 73 69 6e 67 20 61 20 73 75 62 Processing a sub
1b3b0 2d 57 48 45 52 45 20 61 73 20 70 61 72 74 20 6f -WHERE as part o
1b3c0 66 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 f.
1b3d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1b3e0 20 20 20 20 20 20 20 20 2a 2a 20 74 68 65 20 4f ** the O
1b3f0 52 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 20 R optimization
1b400 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
1b410 5f 47 52 4f 55 50 42 59 20 20 20 20 20 20 20 20 _GROUPBY
1b420 20 20 30 78 30 30 34 30 20 2f 2a 20 70 4f 72 64 0x0040 /* pOrd
1b430 65 72 42 79 20 69 73 20 72 65 61 6c 6c 79 20 61 erBy is really a
1b440 20 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 65 GROUP BY */.#de
1b450 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 fine WHERE_DISTI
1b460 4e 43 54 42 59 20 20 20 20 20 20 20 30 78 30 30 NCTBY 0x00
1b470 38 30 20 2f 2a 20 70 4f 72 64 65 72 62 79 20 69 80 /* pOrderby i
1b480 73 20 72 65 61 6c 6c 79 20 61 20 44 49 53 54 49 s really a DISTI
1b490 4e 43 54 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 NCT clause */.#d
1b4a0 65 66 69 6e 65 20 57 48 45 52 45 5f 57 41 4e 54 efine WHERE_WANT
1b4b0 5f 44 49 53 54 49 4e 43 54 20 20 20 20 30 78 30 _DISTINCT 0x0
1b4c0 31 30 30 20 2f 2a 20 41 6c 6c 20 6f 75 74 70 75 100 /* All outpu
1b4d0 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 64 69 t needs to be di
1b4e0 73 74 69 6e 63 74 20 2a 2f 0a 23 64 65 66 69 6e stinct */.#defin
1b4f0 65 20 57 48 45 52 45 5f 53 4f 52 54 42 59 47 52 e WHERE_SORTBYGR
1b500 4f 55 50 20 20 20 20 20 20 30 78 30 32 30 30 20 OUP 0x0200
1b510 2f 2a 20 53 75 70 70 6f 72 74 20 73 71 6c 69 74 /* Support sqlit
1b520 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 28 e3WhereIsSorted(
1b530 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 ) */.#define WHE
1b540 52 45 5f 53 45 45 4b 5f 54 41 42 4c 45 20 20 20 RE_SEEK_TABLE
1b550 20 20 20 20 30 78 30 34 30 30 20 2f 2a 20 44 6f 0x0400 /* Do
1b560 20 6e 6f 74 20 64 65 66 65 72 20 73 65 65 6b 73 not defer seeks
1b570 20 6f 6e 20 6d 61 69 6e 20 74 61 62 6c 65 20 2a on main table *
1b580 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
1b590 4f 52 44 45 52 42 59 5f 4c 49 4d 49 54 20 20 20 ORDERBY_LIMIT
1b5a0 20 30 78 30 38 30 30 20 2f 2a 20 4f 52 44 45 52 0x0800 /* ORDER
1b5b0 42 59 2b 4c 49 4d 49 54 20 6f 6e 20 74 68 65 20 BY+LIMIT on the
1b5c0 69 6e 6e 65 72 20 6c 6f 6f 70 20 2a 2f 0a 23 64 inner loop */.#d
1b5d0 65 66 69 6e 65 20 57 48 45 52 45 5f 53 45 45 4b efine WHERE_SEEK
1b5e0 5f 55 4e 49 51 5f 54 41 42 4c 45 20 20 30 78 31 _UNIQ_TABLE 0x1
1b5f0 30 30 30 20 2f 2a 20 44 6f 20 6e 6f 74 20 64 65 000 /* Do not de
1b600 66 65 72 20 73 65 65 6b 73 20 69 66 20 75 6e 69 fer seeks if uni
1b610 71 75 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 que */.
1b620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1b630 2a 20 20 20 20 20 30 78 32 30 30 30 20 20 20 20 * 0x2000
1b640 6e 6f 74 20 63 75 72 72 65 6e 74 6c 79 20 75 73 not currently us
1b650 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 ed */.#define WH
1b660 45 52 45 5f 55 53 45 5f 4c 49 4d 49 54 20 20 20 ERE_USE_LIMIT
1b670 20 20 20 20 20 30 78 34 30 30 30 20 2f 2a 20 55 0x4000 /* U
1b680 73 65 20 74 68 65 20 4c 49 4d 49 54 20 69 6e 20 se the LIMIT in
1b690 63 6f 73 74 20 65 73 74 69 6d 61 74 65 73 20 2a cost estimates *
1b6a0 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 /.
1b6b0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 20 /*
1b6c0 20 30 78 38 30 30 30 20 20 20 20 6e 6f 74 20 63 0x8000 not c
1b6d0 75 72 72 65 6e 74 6c 79 20 75 73 65 64 20 2a 2f urrently used */
1b6e0 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 ../* Allowed ret
1b6f0 75 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 urn values from
1b700 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 sqlite3WhereIsDi
1b710 73 74 69 6e 63 74 28 29 0a 2a 2f 0a 23 64 65 66 stinct().*/.#def
1b720 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e ine WHERE_DISTIN
1b730 43 54 5f 4e 4f 4f 50 20 20 20 20 20 20 30 20 20 CT_NOOP 0
1b740 2f 2a 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 /* DISTINCT keyw
1b750 6f 72 64 20 6e 6f 74 20 75 73 65 64 20 2a 2f 0a ord not used */.
1b760 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 #define WHERE_DI
1b770 53 54 49 4e 43 54 5f 55 4e 49 51 55 45 20 20 20 STINCT_UNIQUE
1b780 20 31 20 20 2f 2a 20 4e 6f 20 64 75 70 6c 69 63 1 /* No duplic
1b790 61 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ates */.#define
1b7a0 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 4f WHERE_DISTINCT_O
1b7b0 52 44 45 52 45 44 20 20 20 32 20 20 2f 2a 20 41 RDERED 2 /* A
1b7c0 6c 6c 20 64 75 70 6c 69 63 61 74 65 73 20 61 72 ll duplicates ar
1b7d0 65 20 61 64 6a 61 63 65 6e 74 20 2a 2f 0a 23 64 e adjacent */.#d
1b7e0 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 efine WHERE_DIST
1b7f0 49 4e 43 54 5f 55 4e 4f 52 44 45 52 45 44 20 33 INCT_UNORDERED 3
1b800 20 20 2f 2a 20 44 75 70 6c 69 63 61 74 65 73 20 /* Duplicates
1b810 61 72 65 20 73 63 61 74 74 65 72 65 64 20 2a 2f are scattered */
1b820 0a 0a 2f 2a 0a 2a 2a 20 41 20 4e 61 6d 65 43 6f ../*.** A NameCo
1b830 6e 74 65 78 74 20 64 65 66 69 6e 65 73 20 61 20 ntext defines a
1b840 63 6f 6e 74 65 78 74 20 69 6e 20 77 68 69 63 68 context in which
1b850 20 74 6f 20 72 65 73 6f 6c 76 65 20 74 61 62 6c to resolve tabl
1b860 65 20 61 6e 64 20 63 6f 6c 75 6d 6e 0a 2a 2a 20 e and column.**
1b870 6e 61 6d 65 73 2e 20 20 54 68 65 20 63 6f 6e 74 names. The cont
1b880 65 78 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 ext consists of
1b890 61 20 6c 69 73 74 20 6f 66 20 74 61 62 6c 65 73 a list of tables
1b8a0 20 28 74 68 65 20 70 53 72 63 4c 69 73 74 29 20 (the pSrcList)
1b8b0 66 69 65 6c 64 20 61 6e 64 0a 2a 2a 20 61 20 6c field and.** a l
1b8c0 69 73 74 20 6f 66 20 6e 61 6d 65 64 20 65 78 70 ist of named exp
1b8d0 72 65 73 73 69 6f 6e 20 28 70 45 4c 69 73 74 29 ression (pEList)
1b8e0 2e 20 20 54 68 65 20 6e 61 6d 65 64 20 65 78 70 . The named exp
1b8f0 72 65 73 73 69 6f 6e 20 6c 69 73 74 20 6d 61 79 ression list may
1b900 0a 2a 2a 20 62 65 20 4e 55 4c 4c 2e 20 20 54 68 .** be NULL. Th
1b910 65 20 70 53 72 63 20 63 6f 72 72 65 73 70 6f 6e e pSrc correspon
1b920 64 73 20 74 6f 20 74 68 65 20 46 52 4f 4d 20 63 ds to the FROM c
1b930 6c 61 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 lause of a SELEC
1b940 54 20 6f 72 0a 2a 2a 20 74 6f 20 74 68 65 20 74 T or.** to the t
1b950 61 62 6c 65 20 62 65 69 6e 67 20 6f 70 65 72 61 able being opera
1b960 74 65 64 20 6f 6e 20 62 79 20 49 4e 53 45 52 54 ted on by INSERT
1b970 2c 20 55 50 44 41 54 45 2c 20 6f 72 20 44 45 4c , UPDATE, or DEL
1b980 45 54 45 2e 20 20 54 68 65 0a 2a 2a 20 70 45 4c ETE. The.** pEL
1b990 69 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 ist corresponds
1b9a0 74 6f 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 to the result se
1b9b0 74 20 6f 66 20 61 20 53 45 4c 45 43 54 20 61 6e t of a SELECT an
1b9c0 64 20 69 73 20 4e 55 4c 4c 20 66 6f 72 0a 2a 2a d is NULL for.**
1b9d0 20 6f 74 68 65 72 20 73 74 61 74 65 6d 65 6e 74 other statement
1b9e0 73 2e 0a 2a 2a 0a 2a 2a 20 4e 61 6d 65 43 6f 6e s..**.** NameCon
1b9f0 74 65 78 74 73 20 63 61 6e 20 62 65 20 6e 65 73 texts can be nes
1ba00 74 65 64 2e 20 20 57 68 65 6e 20 72 65 73 6f 6c ted. When resol
1ba10 76 69 6e 67 20 6e 61 6d 65 73 2c 20 74 68 65 20 ving names, the
1ba20 69 6e 6e 65 72 2d 6d 6f 73 74 0a 2a 2a 20 63 6f inner-most.** co
1ba30 6e 74 65 78 74 20 69 73 20 73 65 61 72 63 68 65 ntext is searche
1ba40 64 20 66 69 72 73 74 2e 20 20 49 66 20 6e 6f 20 d first. If no
1ba50 6d 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 match is found,
1ba60 74 68 65 20 6e 65 78 74 20 6f 75 74 65 72 0a 2a the next outer.*
1ba70 2a 20 63 6f 6e 74 65 78 74 20 69 73 20 63 68 65 * context is che
1ba80 63 6b 65 64 2e 20 20 49 66 20 74 68 65 72 65 20 cked. If there
1ba90 69 73 20 73 74 69 6c 6c 20 6e 6f 20 6d 61 74 63 is still no matc
1baa0 68 2c 20 74 68 65 20 6e 65 78 74 20 63 6f 6e 74 h, the next cont
1bab0 65 78 74 0a 2a 2a 20 69 73 20 63 68 65 63 6b 65 ext.** is checke
1bac0 64 2e 20 20 54 68 69 73 20 70 72 6f 63 65 73 73 d. This process
1bad0 20 63 6f 6e 74 69 6e 75 65 73 20 75 6e 74 69 6c continues until
1bae0 20 65 69 74 68 65 72 20 61 20 6d 61 74 63 68 20 either a match
1baf0 69 73 20 66 6f 75 6e 64 0a 2a 2a 20 6f 72 20 61 is found.** or a
1bb00 6c 6c 20 63 6f 6e 74 65 78 74 73 20 61 72 65 20 ll contexts are
1bb10 63 68 65 63 6b 2e 20 20 57 68 65 6e 20 61 20 6d check. When a m
1bb20 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 atch is found, t
1bb30 68 65 20 6e 52 65 66 20 6d 65 6d 62 65 72 20 6f he nRef member o
1bb40 66 0a 2a 2a 20 74 68 65 20 63 6f 6e 74 65 78 74 f.** the context
1bb50 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 containing the
1bb60 6d 61 74 63 68 20 69 73 20 69 6e 63 72 65 6d 65 match is increme
1bb70 6e 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 45 61 63 68 nted..**.** Each
1bb80 20 73 75 62 71 75 65 72 79 20 67 65 74 73 20 61 subquery gets a
1bb90 20 6e 65 77 20 4e 61 6d 65 43 6f 6e 74 65 78 74 new NameContext
1bba0 2e 20 20 54 68 65 20 70 4e 65 78 74 20 66 69 65 . The pNext fie
1bbb0 6c 64 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 ld points to the
1bbc0 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 .** NameContext
1bbd0 69 6e 20 74 68 65 20 70 61 72 65 6e 74 20 71 75 in the parent qu
1bbe0 65 72 79 2e 20 20 54 68 75 73 20 74 68 65 20 70 ery. Thus the p
1bbf0 72 6f 63 65 73 73 20 6f 66 20 73 63 61 6e 6e 69 rocess of scanni
1bc00 6e 67 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f ng the.** NameCo
1bc10 6e 74 65 78 74 20 6c 69 73 74 20 63 6f 72 72 65 ntext list corre
1bc20 73 70 6f 6e 64 73 20 74 6f 20 73 65 61 72 63 68 sponds to search
1bc30 69 6e 67 20 74 68 72 6f 75 67 68 20 73 75 63 63 ing through succ
1bc40 65 73 73 69 76 65 6c 79 20 6f 75 74 65 72 0a 2a essively outer.*
1bc50 2a 20 73 75 62 71 75 65 72 69 65 73 20 6c 6f 6f * subqueries loo
1bc60 6b 69 6e 67 20 66 6f 72 20 61 20 6d 61 74 63 68 king for a match
1bc70 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4e 61 6d 65 ..*/.struct Name
1bc80 43 6f 6e 74 65 78 74 20 7b 0a 20 20 50 61 72 73 Context {. Pars
1bc90 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 e *pParse;
1bca0 20 2f 2a 20 54 68 65 20 70 61 72 73 65 72 20 2a /* The parser *
1bcb0 2f 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 /. SrcList *pSr
1bcc0 63 4c 69 73 74 3b 20 20 20 2f 2a 20 4f 6e 65 20 cList; /* One
1bcd0 6f 72 20 6d 6f 72 65 20 74 61 62 6c 65 73 20 75 or more tables u
1bce0 73 65 64 20 74 6f 20 72 65 73 6f 6c 76 65 20 6e sed to resolve n
1bcf0 61 6d 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c 69 ames */. ExprLi
1bd00 73 74 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 2f st *pEList; /
1bd10 2a 20 4f 70 74 69 6f 6e 61 6c 20 6c 69 73 74 20 * Optional list
1bd20 6f 66 20 72 65 73 75 6c 74 2d 73 65 74 20 63 6f of result-set co
1bd30 6c 75 6d 6e 73 20 2a 2f 0a 20 20 41 67 67 49 6e lumns */. AggIn
1bd40 66 6f 20 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 fo *pAggInfo;
1bd50 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 /* Information a
1bd60 62 6f 75 74 20 61 67 67 72 65 67 61 74 65 73 20 bout aggregates
1bd70 61 74 20 74 68 69 73 20 6c 65 76 65 6c 20 2a 2f at this level */
1bd80 0a 20 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 2a . NameContext *
1bd90 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 78 74 20 pNext; /* Next
1bda0 6f 75 74 65 72 20 6e 61 6d 65 20 63 6f 6e 74 65 outer name conte
1bdb0 78 74 2e 20 20 4e 55 4c 4c 20 66 6f 72 20 6f 75 xt. NULL for ou
1bdc0 74 65 72 6d 6f 73 74 20 2a 2f 0a 20 20 69 6e 74 termost */. int
1bdd0 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 20 nRef;
1bde0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e /* Number of n
1bdf0 61 6d 65 73 20 72 65 73 6f 6c 76 65 64 20 62 79 ames resolved by
1be00 20 74 68 69 73 20 63 6f 6e 74 65 78 74 20 2a 2f this context */
1be10 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 20 . int nErr;
1be20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1be30 72 20 6f 66 20 65 72 72 6f 72 73 20 65 6e 63 6f r of errors enco
1be40 75 6e 74 65 72 65 64 20 77 68 69 6c 65 20 72 65 untered while re
1be50 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 2a 2f solving names */
1be60 0a 20 20 75 31 36 20 6e 63 46 6c 61 67 73 3b 20 . u16 ncFlags;
1be70 20 20 20 20 20 20 20 20 2f 2a 20 5a 65 72 6f 20 /* Zero
1be80 6f 72 20 6d 6f 72 65 20 4e 43 5f 2a 20 66 6c 61 or more NC_* fla
1be90 67 73 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 gs defined below
1bea0 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c */.};../*.** Al
1beb0 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 lowed values for
1bec0 20 74 68 65 20 4e 61 6d 65 43 6f 6e 74 65 78 74 the NameContext
1bed0 2c 20 6e 63 46 6c 61 67 73 20 66 69 65 6c 64 2e , ncFlags field.
1bee0 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e .**.** Value con
1bef0 73 74 72 61 69 6e 74 73 20 28 61 6c 6c 20 63 68 straints (all ch
1bf00 65 63 6b 65 64 20 76 69 61 20 61 73 73 65 72 74 ecked via assert
1bf10 28 29 29 3a 0a 2a 2a 20 20 20 20 4e 43 5f 48 61 ()):.** NC_Ha
1bf20 73 41 67 67 20 20 20 20 3d 3d 20 53 46 5f 48 61 sAgg == SF_Ha
1bf30 73 41 67 67 0a 2a 2a 20 20 20 20 4e 43 5f 4d 69 sAgg.** NC_Mi
1bf40 6e 4d 61 78 41 67 67 20 3d 3d 20 53 46 5f 4d 69 nMaxAgg == SF_Mi
1bf50 6e 4d 61 78 41 67 67 20 3d 3d 20 53 51 4c 49 54 nMaxAgg == SQLIT
1bf60 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 0a 2a 2a E_FUNC_MINMAX.**
1bf70 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 41 .*/.#define NC_A
1bf80 6c 6c 6f 77 41 67 67 20 20 30 78 30 30 30 31 20 llowAgg 0x0001
1bf90 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 66 75 /* Aggregate fu
1bfa0 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 6c 6c 6f nctions are allo
1bfb0 77 65 64 20 68 65 72 65 20 2a 2f 0a 23 64 65 66 wed here */.#def
1bfc0 69 6e 65 20 4e 43 5f 50 61 72 74 49 64 78 20 20 ine NC_PartIdx
1bfd0 20 30 78 30 30 30 32 20 20 2f 2a 20 54 72 75 65 0x0002 /* True
1bfe0 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 61 20 if resolving a
1bff0 70 61 72 74 69 61 6c 20 69 6e 64 65 78 20 57 48 partial index WH
1c000 45 52 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e ERE */.#define N
1c010 43 5f 49 73 43 68 65 63 6b 20 20 20 30 78 30 30 C_IsCheck 0x00
1c020 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 04 /* True if r
1c030 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 20 69 esolving names i
1c040 6e 20 61 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 n a CHECK constr
1c050 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aint */.#define
1c060 4e 43 5f 49 6e 41 67 67 46 75 6e 63 20 30 78 30 NC_InAggFunc 0x0
1c070 30 30 38 20 20 2f 2a 20 54 72 75 65 20 69 66 20 008 /* True if
1c080 61 6e 61 6c 79 7a 69 6e 67 20 61 72 67 75 6d 65 analyzing argume
1c090 6e 74 73 20 74 6f 20 61 6e 20 61 67 67 20 66 75 nts to an agg fu
1c0a0 6e 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 nc */.#define NC
1c0b0 5f 48 61 73 41 67 67 20 20 20 20 30 78 30 30 31 _HasAgg 0x001
1c0c0 30 20 20 2f 2a 20 4f 6e 65 20 6f 72 20 6d 6f 72 0 /* One or mor
1c0d0 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 e aggregate func
1c0e0 74 69 6f 6e 73 20 73 65 65 6e 20 2a 2f 0a 23 64 tions seen */.#d
1c0f0 65 66 69 6e 65 20 4e 43 5f 49 64 78 45 78 70 72 efine NC_IdxExpr
1c100 20 20 20 30 78 30 30 32 30 20 20 2f 2a 20 54 72 0x0020 /* Tr
1c110 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 ue if resolving
1c120 63 6f 6c 75 6d 6e 73 20 6f 66 20 43 52 45 41 54 columns of CREAT
1c130 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 69 E INDEX */.#defi
1c140 6e 65 20 4e 43 5f 56 61 72 53 65 6c 65 63 74 20 ne NC_VarSelect
1c150 30 78 30 30 34 30 20 20 2f 2a 20 41 20 63 6f 72 0x0040 /* A cor
1c160 72 65 6c 61 74 65 64 20 73 75 62 71 75 65 72 79 related subquery
1c170 20 68 61 73 20 62 65 65 6e 20 73 65 65 6e 20 2a has been seen *
1c180 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 4d 69 6e /.#define NC_Min
1c190 4d 61 78 41 67 67 20 30 78 31 30 30 30 20 20 2f MaxAgg 0x1000 /
1c1a0 2a 20 6d 69 6e 2f 6d 61 78 20 61 67 67 72 65 67 * min/max aggreg
1c1b0 61 74 65 73 20 73 65 65 6e 2e 20 20 53 65 65 20 ates seen. See
1c1c0 6e 6f 74 65 20 61 62 6f 76 65 20 2a 2f 0a 23 64 note above */.#d
1c1d0 65 66 69 6e 65 20 4e 43 5f 43 6f 6d 70 6c 65 78 efine NC_Complex
1c1e0 20 20 20 30 78 32 30 30 30 20 20 2f 2a 20 54 72 0x2000 /* Tr
1c1f0 75 65 20 69 66 20 61 20 66 75 6e 63 74 69 6f 6e ue if a function
1c200 20 6f 72 20 73 75 62 71 75 65 72 79 20 73 65 65 or subquery see
1c210 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 n */../*.** An i
1c220 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
1c230 6f 6c 6c 6f 77 69 6e 67 20 6f 62 6a 65 63 74 20 ollowing object
1c240 64 65 73 63 72 69 62 65 73 20 61 20 73 69 6e 67 describes a sing
1c250 6c 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 0a 2a le ON CONFLICT.*
1c260 2a 20 63 6c 61 75 73 65 20 69 6e 20 61 6e 20 75 * clause in an u
1c270 70 73 65 72 74 2e 20 20 41 20 6c 69 73 74 20 6f psert. A list o
1c280 66 20 74 68 65 73 65 20 6f 62 6a 65 63 74 73 20 f these objects
1c290 6d 61 79 20 62 65 20 61 74 74 61 63 68 65 64 20 may be attached
1c2a0 74 6f 0a 2a 2a 20 61 6e 20 49 4e 53 45 52 54 20 to.** an INSERT
1c2b0 73 74 61 74 65 6d 65 6e 74 20 69 6e 20 6f 72 64 statement in ord
1c2c0 65 72 20 74 6f 20 66 6f 72 6d 20 61 6e 20 75 70 er to form an up
1c2d0 73 65 72 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 sert..*/.struct
1c2e0 55 70 73 65 72 74 20 7b 0a 20 20 45 78 70 72 4c Upsert {. ExprL
1c2f0 69 73 74 20 2a 70 55 70 73 65 72 74 54 61 72 67 ist *pUpsertTarg
1c300 65 74 3b 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c et; /* Optional
1c310 20 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 20 description of
1c320 63 6f 6e 66 6c 69 63 74 69 6e 67 20 69 6e 64 65 conflicting inde
1c330 78 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 x */. ExprList
1c340 2a 70 55 70 73 65 72 74 53 65 74 3b 20 20 20 20 *pUpsertSet;
1c350 20 2f 2a 20 54 68 65 20 53 45 54 20 63 6c 61 75 /* The SET clau
1c360 73 65 20 66 72 6f 6d 20 61 6e 20 4f 4e 20 43 4f se from an ON CO
1c370 4e 46 4c 49 43 54 20 55 50 44 41 54 45 20 2a 2f NFLICT UPDATE */
1c380 0a 20 20 55 70 73 65 72 74 20 2a 70 55 70 73 65 . Upsert *pUpse
1c390 72 74 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 rtNext; /*
1c3a0 4e 65 78 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 Next ON CONFLICT
1c3b0 20 63 6c 61 75 73 65 20 69 6e 20 74 68 65 20 6c clause in the l
1c3c0 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ist */.};../*.**
1c3d0 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
1c3e0 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
1c3f0 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 ructure contains
1c400 20 61 6c 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e all information
1c410 0a 2a 2a 20 6e 65 65 64 65 64 20 74 6f 20 67 65 .** needed to ge
1c420 6e 65 72 61 74 65 20 63 6f 64 65 20 66 6f 72 20 nerate code for
1c430 61 20 73 69 6e 67 6c 65 20 53 45 4c 45 43 54 20 a single SELECT
1c440 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a statement..**.**
1c450 20 6e 4c 69 6d 69 74 20 69 73 20 73 65 74 20 74 nLimit is set t
1c460 6f 20 2d 31 20 69 66 20 74 68 65 72 65 20 69 73 o -1 if there is
1c470 20 6e 6f 20 4c 49 4d 49 54 20 63 6c 61 75 73 65 no LIMIT clause
1c480 2e 20 20 6e 4f 66 66 73 65 74 20 69 73 20 73 65 . nOffset is se
1c490 74 20 74 6f 20 30 2e 0a 2a 2a 20 49 66 20 74 68 t to 0..** If th
1c4a0 65 72 65 20 69 73 20 61 20 4c 49 4d 49 54 20 63 ere is a LIMIT c
1c4b0 6c 61 75 73 65 2c 20 74 68 65 20 70 61 72 73 65 lause, the parse
1c4c0 72 20 73 65 74 73 20 6e 4c 69 6d 69 74 20 74 6f r sets nLimit to
1c4d0 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 74 68 the value of th
1c4e0 65 0a 2a 2a 20 6c 69 6d 69 74 20 61 6e 64 20 6e e.** limit and n
1c4f0 4f 66 66 73 65 74 20 74 6f 20 74 68 65 20 76 61 Offset to the va
1c500 6c 75 65 20 6f 66 20 74 68 65 20 6f 66 66 73 65 lue of the offse
1c510 74 20 28 6f 72 20 30 20 69 66 20 74 68 65 72 65 t (or 0 if there
1c520 20 69 73 20 6e 6f 74 0a 2a 2a 20 6f 66 66 73 65 is not.** offse
1c530 74 29 2e 20 20 42 75 74 20 6c 61 74 65 72 20 6f t). But later o
1c540 6e 2c 20 6e 4c 69 6d 69 74 20 61 6e 64 20 6e 4f n, nLimit and nO
1c550 66 66 73 65 74 20 62 65 63 6f 6d 65 20 74 68 65 ffset become the
1c560 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e memory location
1c570 73 0a 2a 2a 20 69 6e 20 74 68 65 20 56 44 42 45 s.** in the VDBE
1c580 20 74 68 61 74 20 72 65 63 6f 72 64 20 74 68 65 that record the
1c590 20 6c 69 6d 69 74 20 61 6e 64 20 6f 66 66 73 65 limit and offse
1c5a0 74 20 63 6f 75 6e 74 65 72 73 2e 0a 2a 2a 0a 2a t counters..**.*
1c5b0 2a 20 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b 5d * addrOpenEphm[]
1c5c0 20 65 6e 74 72 69 65 73 20 63 6f 6e 74 61 69 6e entries contain
1c5d0 20 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 the address of
1c5e0 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c OP_OpenEphemeral
1c5f0 20 6f 70 63 6f 64 65 73 2e 0a 2a 2a 20 54 68 65 opcodes..** The
1c600 73 65 20 61 64 64 72 65 73 73 65 73 20 6d 75 73 se addresses mus
1c610 74 20 62 65 20 73 74 6f 72 65 64 20 73 6f 20 74 t be stored so t
1c620 68 61 74 20 77 65 20 63 61 6e 20 67 6f 20 62 61 hat we can go ba
1c630 63 6b 20 61 6e 64 20 66 69 6c 6c 20 69 6e 0a 2a ck and fill in.*
1c640 2a 20 74 68 65 20 50 34 5f 4b 45 59 49 4e 46 4f * the P4_KEYINFO
1c650 20 61 6e 64 20 50 32 20 70 61 72 61 6d 65 74 65 and P2 paramete
1c660 72 73 20 6c 61 74 65 72 2e 20 20 4e 65 69 74 68 rs later. Neith
1c670 65 72 20 74 68 65 20 4b 65 79 49 6e 66 6f 20 6e er the KeyInfo n
1c680 6f 72 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 65 72 or.** the number
1c690 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 50 of columns in P
1c6a0 32 20 63 61 6e 20 62 65 20 63 6f 6d 70 75 74 65 2 can be compute
1c6b0 64 20 61 74 20 74 68 65 20 73 61 6d 65 20 74 69 d at the same ti
1c6c0 6d 65 0a 2a 2a 20 61 73 20 74 68 65 20 4f 50 5f me.** as the OP_
1c6d0 4f 70 65 6e 45 70 68 6d 20 69 6e 73 74 72 75 63 OpenEphm instruc
1c6e0 74 69 6f 6e 20 69 73 20 63 6f 64 65 64 20 62 65 tion is coded be
1c6f0 63 61 75 73 65 20 6e 6f 74 0a 2a 2a 20 65 6e 6f cause not.** eno
1c700 75 67 68 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 ugh information
1c710 61 62 6f 75 74 20 74 68 65 20 63 6f 6d 70 6f 75 about the compou
1c720 6e 64 20 71 75 65 72 79 20 69 73 20 6b 6e 6f 77 nd query is know
1c730 6e 20 61 74 20 74 68 61 74 20 70 6f 69 6e 74 2e n at that point.
1c740 0a 2a 2a 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 .** The KeyInfo
1c750 66 6f 72 20 61 64 64 72 4f 70 65 6e 54 72 61 6e for addrOpenTran
1c760 5b 30 5d 20 61 6e 64 20 5b 31 5d 20 63 6f 6e 74 [0] and [1] cont
1c770 61 69 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 20 73 ains collating s
1c780 65 71 75 65 6e 63 65 73 0a 2a 2a 20 66 6f 72 20 equences.** for
1c790 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 2e 20 the result set.
1c7a0 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 6f 72 The KeyInfo for
1c7b0 20 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b 32 5d addrOpenEphm[2]
1c7c0 20 63 6f 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 74 contains collat
1c7d0 69 6e 67 0a 2a 2a 20 73 65 71 75 65 6e 63 65 73 ing.** sequences
1c7e0 20 66 6f 72 20 74 68 65 20 4f 52 44 45 52 20 42 for the ORDER B
1c7f0 59 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a 73 74 72 Y clause..*/.str
1c800 75 63 74 20 53 65 6c 65 63 74 20 7b 0a 20 20 45 uct Select {. E
1c810 78 70 72 4c 69 73 74 20 2a 70 45 4c 69 73 74 3b xprList *pEList;
1c820 20 20 20 20 20 20 2f 2a 20 54 68 65 20 66 69 65 /* The fie
1c830 6c 64 73 20 6f 66 20 74 68 65 20 72 65 73 75 6c lds of the resul
1c840 74 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 20 20 t */. u8 op;
1c850 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1c860 20 4f 6e 65 20 6f 66 3a 20 54 4b 5f 55 4e 49 4f One of: TK_UNIO
1c870 4e 20 54 4b 5f 41 4c 4c 20 54 4b 5f 49 4e 54 45 N TK_ALL TK_INTE
1c880 52 53 45 43 54 20 54 4b 5f 45 58 43 45 50 54 20 RSECT TK_EXCEPT
1c890 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 6e 53 65 6c */. LogEst nSel
1c8a0 65 63 74 52 6f 77 3b 20 20 20 20 20 2f 2a 20 45 ectRow; /* E
1c8b0 73 74 69 6d 61 74 65 64 20 6e 75 6d 62 65 72 20 stimated number
1c8c0 6f 66 20 72 65 73 75 6c 74 20 72 6f 77 73 20 2a of result rows *
1c8d0 2f 0a 20 20 75 33 32 20 73 65 6c 46 6c 61 67 73 /. u32 selFlags
1c8e0 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 ; /* Va
1c8f0 72 69 6f 75 73 20 53 46 5f 2a 20 76 61 6c 75 65 rious SF_* value
1c900 73 20 2a 2f 0a 20 20 69 6e 74 20 69 4c 69 6d 69 s */. int iLimi
1c910 74 2c 20 69 4f 66 66 73 65 74 3b 20 20 20 2f 2a t, iOffset; /*
1c920 20 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 Memory register
1c930 73 20 68 6f 6c 64 69 6e 67 20 4c 49 4d 49 54 20 s holding LIMIT
1c940 26 20 4f 46 46 53 45 54 20 63 6f 75 6e 74 65 72 & OFFSET counter
1c950 73 20 2a 2f 0a 23 69 66 20 53 45 4c 45 43 54 54 s */.#if SELECTT
1c960 52 41 43 45 5f 45 4e 41 42 4c 45 44 0a 20 20 63 RACE_ENABLED. c
1c970 68 61 72 20 7a 53 65 6c 4e 61 6d 65 5b 31 32 5d har zSelName[12]
1c980 3b 20 20 20 20 20 2f 2a 20 53 79 6d 62 6f 6c 69 ; /* Symboli
1c990 63 20 6e 61 6d 65 20 6f 66 20 74 68 69 73 20 53 c name of this S
1c9a0 45 4c 45 43 54 20 75 73 65 20 66 6f 72 20 64 65 ELECT use for de
1c9b0 62 75 67 67 69 6e 67 20 2a 2f 0a 23 65 6e 64 69 bugging */.#endi
1c9c0 66 0a 20 20 69 6e 74 20 61 64 64 72 4f 70 65 6e f. int addrOpen
1c9d0 45 70 68 6d 5b 32 5d 3b 20 20 20 2f 2a 20 4f 50 Ephm[2]; /* OP
1c9e0 5f 4f 70 65 6e 45 70 68 65 6d 20 6f 70 63 6f 64 _OpenEphem opcod
1c9f0 65 73 20 72 65 6c 61 74 65 64 20 74 6f 20 74 68 es related to th
1ca00 69 73 20 73 65 6c 65 63 74 20 2a 2f 0a 20 20 53 is select */. S
1ca10 72 63 4c 69 73 74 20 2a 70 53 72 63 3b 20 20 20 rcList *pSrc;
1ca20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 46 52 4f /* The FRO
1ca30 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 M clause */. Ex
1ca40 70 72 20 2a 70 57 68 65 72 65 3b 20 20 20 20 20 pr *pWhere;
1ca50 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 45 52 /* The WHER
1ca60 45 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 E clause */. Ex
1ca70 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 70 42 79 prList *pGroupBy
1ca80 3b 20 20 20 20 2f 2a 20 54 68 65 20 47 52 4f 55 ; /* The GROU
1ca90 50 20 42 59 20 63 6c 61 75 73 65 20 2a 2f 0a 20 P BY clause */.
1caa0 20 45 78 70 72 20 2a 70 48 61 76 69 6e 67 3b 20 Expr *pHaving;
1cab0 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 48 /* The H
1cac0 41 56 49 4e 47 20 63 6c 61 75 73 65 20 2a 2f 0a AVING clause */.
1cad0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 ExprList *pOrd
1cae0 65 72 42 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 erBy; /* The
1caf0 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 20 ORDER BY clause
1cb00 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 50 72 */. Select *pPr
1cb10 69 6f 72 3b 20 20 20 20 20 20 20 20 2f 2a 20 50 ior; /* P
1cb20 72 69 6f 72 20 73 65 6c 65 63 74 20 69 6e 20 61 rior select in a
1cb30 20 63 6f 6d 70 6f 75 6e 64 20 73 65 6c 65 63 74 compound select
1cb40 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f 0a 20 20 statement */.
1cb50 53 65 6c 65 63 74 20 2a 70 4e 65 78 74 3b 20 20 Select *pNext;
1cb60 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 73 /* Next s
1cb70 65 6c 65 63 74 20 74 6f 20 74 68 65 20 6c 65 66 elect to the lef
1cb80 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 6e 64 20 t in a compound
1cb90 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4c 69 6d 69 */. Expr *pLimi
1cba0 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c t; /* L
1cbb0 49 4d 49 54 20 65 78 70 72 65 73 73 69 6f 6e 2e IMIT expression.
1cbc0 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e 6f 74 20 NULL means not
1cbd0 75 73 65 64 2e 20 2a 2f 0a 20 20 57 69 74 68 20 used. */. With
1cbe0 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 20 *pWith;
1cbf0 20 20 2f 2a 20 57 49 54 48 20 63 6c 61 75 73 65 /* WITH clause
1cc00 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 69 attached to thi
1cc10 73 20 73 65 6c 65 63 74 2e 20 4f 72 20 4e 55 4c s select. Or NUL
1cc20 4c 2e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 L. */.};../*.**
1cc30 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
1cc40 6f 72 20 53 65 6c 65 63 74 2e 73 65 6c 46 6c 61 or Select.selFla
1cc50 67 73 2e 20 20 54 68 65 20 22 53 46 22 20 70 72 gs. The "SF" pr
1cc60 65 66 69 78 20 73 74 61 6e 64 73 20 66 6f 72 0a efix stands for.
1cc70 2a 2a 20 22 53 65 6c 65 63 74 20 46 6c 61 67 22 ** "Select Flag"
1cc80 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f ..**.** Value co
1cc90 6e 73 74 72 61 69 6e 74 73 20 28 61 6c 6c 20 63 nstraints (all c
1cca0 68 65 63 6b 65 64 20 76 69 61 20 61 73 73 65 72 hecked via asser
1ccb0 74 28 29 29 0a 2a 2a 20 20 20 20 20 53 46 5f 48 t()).** SF_H
1ccc0 61 73 41 67 67 20 20 20 20 20 3d 3d 20 4e 43 5f asAgg == NC_
1ccd0 48 61 73 41 67 67 0a 2a 2a 20 20 20 20 20 53 46 HasAgg.** SF
1cce0 5f 4d 69 6e 4d 61 78 41 67 67 20 20 3d 3d 20 4e _MinMaxAgg == N
1ccf0 43 5f 4d 69 6e 4d 61 78 41 67 67 20 20 20 20 20 C_MinMaxAgg
1cd00 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d == SQLITE_FUNC_M
1cd10 49 4e 4d 41 58 0a 2a 2a 20 20 20 20 20 53 46 5f INMAX.** SF_
1cd20 46 69 78 65 64 4c 69 6d 69 74 20 3d 3d 20 57 48 FixedLimit == WH
1cd30 45 52 45 5f 55 53 45 5f 4c 49 4d 49 54 0a 2a 2f ERE_USE_LIMIT.*/
1cd40 0a 23 64 65 66 69 6e 65 20 53 46 5f 44 69 73 74 .#define SF_Dist
1cd50 69 6e 63 74 20 20 20 20 20 20 20 30 78 30 30 30 inct 0x000
1cd60 30 31 20 20 2f 2a 20 4f 75 74 70 75 74 20 73 68 01 /* Output sh
1cd70 6f 75 6c 64 20 62 65 20 44 49 53 54 49 4e 43 54 ould be DISTINCT
1cd80 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 41 */.#define SF_A
1cd90 6c 6c 20 20 20 20 20 20 20 20 20 20 20 20 30 78 ll 0x
1cda0 30 30 30 30 32 20 20 2f 2a 20 49 6e 63 6c 75 64 00002 /* Includ
1cdb0 65 73 20 74 68 65 20 41 4c 4c 20 6b 65 79 77 6f es the ALL keywo
1cdc0 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 rd */.#define SF
1cdd0 5f 52 65 73 6f 6c 76 65 64 20 20 20 20 20 20 20 _Resolved
1cde0 30 78 30 30 30 30 34 20 20 2f 2a 20 49 64 65 6e 0x00004 /* Iden
1cdf0 74 69 66 69 65 72 73 20 68 61 76 65 20 62 65 65 tifiers have bee
1ce00 6e 20 72 65 73 6f 6c 76 65 64 20 2a 2f 0a 23 64 n resolved */.#d
1ce10 65 66 69 6e 65 20 53 46 5f 41 67 67 72 65 67 61 efine SF_Aggrega
1ce20 74 65 20 20 20 20 20 20 30 78 30 30 30 30 38 20 te 0x00008
1ce30 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 /* Contains agg
1ce40 20 66 75 6e 63 74 69 6f 6e 73 20 6f 72 20 61 20 functions or a
1ce50 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 65 66 GROUP BY */.#def
1ce60 69 6e 65 20 53 46 5f 48 61 73 41 67 67 20 20 20 ine SF_HasAgg
1ce70 20 20 20 20 20 20 30 78 30 30 30 31 30 20 20 2f 0x00010 /
1ce80 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 * Contains aggre
1ce90 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a gate functions *
1cea0 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 55 73 65 /.#define SF_Use
1ceb0 73 45 70 68 65 6d 65 72 61 6c 20 20 30 78 30 30 sEphemeral 0x00
1cec0 30 32 30 20 20 2f 2a 20 55 73 65 73 20 74 68 65 020 /* Uses the
1ced0 20 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f OpenEphemeral o
1cee0 70 63 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 pcode */.#define
1cef0 20 53 46 5f 45 78 70 61 6e 64 65 64 20 20 20 20 SF_Expanded
1cf00 20 20 20 30 78 30 30 30 34 30 20 20 2f 2a 20 73 0x00040 /* s
1cf10 71 6c 69 74 65 33 53 65 6c 65 63 74 45 78 70 61 qlite3SelectExpa
1cf20 6e 64 28 29 20 63 61 6c 6c 65 64 20 6f 6e 20 74 nd() called on t
1cf30 68 69 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 his */.#define S
1cf40 46 5f 48 61 73 54 79 70 65 49 6e 66 6f 20 20 20 F_HasTypeInfo
1cf50 20 30 78 30 30 30 38 30 20 20 2f 2a 20 46 52 4f 0x00080 /* FRO
1cf60 4d 20 73 75 62 71 75 65 72 69 65 73 20 68 61 76 M subqueries hav
1cf70 65 20 54 61 62 6c 65 20 6d 65 74 61 64 61 74 61 e Table metadata
1cf80 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 */.#define SF_C
1cf90 6f 6d 70 6f 75 6e 64 20 20 20 20 20 20 20 30 78 ompound 0x
1cfa0 30 30 31 30 30 20 20 2f 2a 20 50 61 72 74 20 6f 00100 /* Part o
1cfb0 66 20 61 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 f a compound que
1cfc0 72 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 ry */.#define SF
1cfd0 5f 56 61 6c 75 65 73 20 20 20 20 20 20 20 20 20 _Values
1cfe0 30 78 30 30 32 30 30 20 20 2f 2a 20 53 79 6e 74 0x00200 /* Synt
1cff0 68 65 73 69 7a 65 64 20 66 72 6f 6d 20 56 41 4c hesized from VAL
1d000 55 45 53 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 UES clause */.#d
1d010 65 66 69 6e 65 20 53 46 5f 4d 75 6c 74 69 56 61 efine SF_MultiVa
1d020 6c 75 65 20 20 20 20 20 30 78 30 30 34 30 30 20 lue 0x00400
1d030 20 2f 2a 20 53 69 6e 67 6c 65 20 56 41 4c 55 45 /* Single VALUE
1d040 53 20 74 65 72 6d 20 77 69 74 68 20 6d 75 6c 74 S term with mult
1d050 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 23 64 65 iple rows */.#de
1d060 66 69 6e 65 20 53 46 5f 4e 65 73 74 65 64 46 72 fine SF_NestedFr
1d070 6f 6d 20 20 20 20 20 30 78 30 30 38 30 30 20 20 om 0x00800
1d080 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 70 61 72 /* Part of a par
1d090 65 6e 74 68 65 73 69 7a 65 64 20 46 52 4f 4d 20 enthesized FROM
1d0a0 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e clause */.#defin
1d0b0 65 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 20 e SF_MinMaxAgg
1d0c0 20 20 20 20 30 78 30 31 30 30 30 20 20 2f 2a 20 0x01000 /*
1d0d0 41 67 67 72 65 67 61 74 65 20 63 6f 6e 74 61 69 Aggregate contai
1d0e0 6e 69 6e 67 20 6d 69 6e 28 29 20 6f 72 20 6d 61 ning min() or ma
1d0f0 78 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 x() */.#define S
1d100 46 5f 52 65 63 75 72 73 69 76 65 20 20 20 20 20 F_Recursive
1d110 20 30 78 30 32 30 30 30 20 20 2f 2a 20 54 68 65 0x02000 /* The
1d120 20 72 65 63 75 72 73 69 76 65 20 70 61 72 74 20 recursive part
1d130 6f 66 20 61 20 72 65 63 75 72 73 69 76 65 20 43 of a recursive C
1d140 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 TE */.#define SF
1d150 5f 46 69 78 65 64 4c 69 6d 69 74 20 20 20 20 20 _FixedLimit
1d160 30 78 30 34 30 30 30 20 20 2f 2a 20 6e 53 65 6c 0x04000 /* nSel
1d170 65 63 74 52 6f 77 20 73 65 74 20 62 79 20 61 20 ectRow set by a
1d180 63 6f 6e 73 74 61 6e 74 20 4c 49 4d 49 54 20 2a constant LIMIT *
1d190 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 61 79 /.#define SF_May
1d1a0 62 65 43 6f 6e 76 65 72 74 20 20 20 30 78 30 38 beConvert 0x08
1d1b0 30 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 6f 6e 000 /* Need con
1d1c0 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 vertCompoundSele
1d1d0 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a ctToSubquery() *
1d1e0 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 6f 6e /.#define SF_Con
1d1f0 76 65 72 74 65 64 20 20 20 20 20 20 30 78 31 30 verted 0x10
1d200 30 30 30 20 20 2f 2a 20 42 79 20 63 6f 6e 76 65 000 /* By conve
1d210 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 74 rtCompoundSelect
1d220 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a 2f 0a ToSubquery() */.
1d230 23 64 65 66 69 6e 65 20 53 46 5f 49 6e 63 6c 75 #define SF_Inclu
1d240 64 65 48 69 64 64 65 6e 20 20 30 78 32 30 30 30 deHidden 0x2000
1d250 30 20 20 2f 2a 20 49 6e 63 6c 75 64 65 20 68 69 0 /* Include hi
1d260 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 dden columns in
1d270 6f 75 74 70 75 74 20 2a 2f 0a 23 64 65 66 69 6e output */.#defin
1d280 65 20 53 46 5f 43 6f 6d 70 6c 65 78 52 65 73 75 e SF_ComplexResu
1d290 6c 74 20 20 30 78 34 30 30 30 30 20 20 2f 2a 20 lt 0x40000 /*
1d2a0 52 65 73 75 6c 74 20 73 65 74 20 63 6f 6e 74 61 Result set conta
1d2b0 69 6e 73 20 73 75 62 71 75 65 72 79 20 6f 72 20 ins subquery or
1d2c0 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 0a 0a 2f 2a function */.../*
1d2d0 0a 2a 2a 20 54 68 65 20 72 65 73 75 6c 74 73 20 .** The results
1d2e0 6f 66 20 61 20 53 45 4c 45 43 54 20 63 61 6e 20 of a SELECT can
1d2f0 62 65 20 64 69 73 74 72 69 62 75 74 65 64 20 69 be distributed i
1d300 6e 20 73 65 76 65 72 61 6c 20 77 61 79 73 2c 20 n several ways,
1d310 61 73 20 64 65 66 69 6e 65 64 0a 2a 2a 20 62 79 as defined.** by
1d320 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c one of the foll
1d330 6f 77 69 6e 67 20 6d 61 63 72 6f 73 2e 20 20 54 owing macros. T
1d340 68 65 20 22 53 52 54 22 20 70 72 65 66 69 78 20 he "SRT" prefix
1d350 6d 65 61 6e 73 20 22 53 45 4c 45 43 54 20 52 65 means "SELECT Re
1d360 73 75 6c 74 0a 2a 2a 20 54 79 70 65 22 2e 0a 2a sult.** Type"..*
1d370 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 55 6e 69 *.** SRT_Uni
1d380 6f 6e 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 on Store r
1d390 65 73 75 6c 74 73 20 61 73 20 61 20 6b 65 79 20 esults as a key
1d3a0 69 6e 20 61 20 74 65 6d 70 6f 72 61 72 79 20 69 in a temporary i
1d3b0 6e 64 65 78 0a 2a 2a 20 20 20 20 20 20 20 20 20 ndex.**
1d3c0 20 20 20 20 20 20 20 20 20 20 20 20 69 64 65 6e iden
1d3d0 74 69 66 69 65 64 20 62 79 20 70 44 65 73 74 2d tified by pDest-
1d3e0 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 >iSDParm..**.**
1d3f0 20 20 20 20 53 52 54 5f 45 78 63 65 70 74 20 20 SRT_Except
1d400 20 20 20 20 52 65 6d 6f 76 65 20 72 65 73 75 6c Remove resul
1d410 74 73 20 66 72 6f 6d 20 74 68 65 20 74 65 6d 70 ts from the temp
1d420 6f 72 61 72 79 20 69 6e 64 65 78 20 70 44 65 73 orary index pDes
1d430 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a t->iSDParm..**.*
1d440 2a 20 20 20 20 20 53 52 54 5f 45 78 69 73 74 73 * SRT_Exists
1d450 20 20 20 20 20 20 53 74 6f 72 65 20 61 20 31 20 Store a 1
1d460 69 6e 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 70 in memory cell p
1d470 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 69 66 Dest->iSDParm if
1d480 20 74 68 65 20 72 65 73 75 6c 74 0a 2a 2a 20 20 the result.**
1d490 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d4a0 20 20 20 73 65 74 20 69 73 20 6e 6f 74 20 65 6d set is not em
1d4b0 70 74 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 pty..**.** S
1d4c0 52 54 5f 44 69 73 63 61 72 64 20 20 20 20 20 54 RT_Discard T
1d4d0 68 72 6f 77 20 74 68 65 20 72 65 73 75 6c 74 73 hrow the results
1d4e0 20 61 77 61 79 2e 20 20 54 68 69 73 20 69 73 20 away. This is
1d4f0 75 73 65 64 20 62 79 20 53 45 4c 45 43 54 0a 2a used by SELECT.*
1d500 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1d510 20 20 20 20 20 20 73 74 61 74 65 6d 65 6e 74 73 statements
1d520 20 77 69 74 68 69 6e 20 74 72 69 67 67 65 72 73 within triggers
1d530 20 77 68 6f 73 65 20 6f 6e 6c 79 20 70 75 72 70 whose only purp
1d540 6f 73 65 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 ose is.**
1d550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 th
1d560 65 20 73 69 64 65 2d 65 66 66 65 63 74 73 20 6f e side-effects o
1d570 66 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a f functions..**.
1d580 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 65 20 61 62 ** All of the ab
1d590 6f 76 65 20 61 72 65 20 66 72 65 65 20 74 6f 20 ove are free to
1d5a0 69 67 6e 6f 72 65 20 74 68 65 69 72 20 4f 52 44 ignore their ORD
1d5b0 45 52 20 42 59 20 63 6c 61 75 73 65 2e 20 54 68 ER BY clause. Th
1d5c0 6f 73 65 20 74 68 61 74 0a 2a 2a 20 66 6f 6c 6c ose that.** foll
1d5d0 6f 77 20 6d 75 73 74 20 68 6f 6e 6f 72 20 74 68 ow must honor th
1d5e0 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
1d5f0 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 e..**.** SRT
1d600 5f 4f 75 74 70 75 74 20 20 20 20 20 20 47 65 6e _Output Gen
1d610 65 72 61 74 65 20 61 20 72 6f 77 20 6f 66 20 6f erate a row of o
1d620 75 74 70 75 74 20 28 75 73 69 6e 67 20 74 68 65 utput (using the
1d630 20 4f 50 5f 52 65 73 75 6c 74 52 6f 77 0a 2a 2a OP_ResultRow.**
1d640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d650 20 20 20 20 20 6f 70 63 6f 64 65 29 20 66 6f 72 opcode) for
1d660 20 65 61 63 68 20 72 6f 77 20 69 6e 20 74 68 65 each row in the
1d670 20 72 65 73 75 6c 74 20 73 65 74 2e 0a 2a 2a 0a result set..**.
1d680 2a 2a 20 20 20 20 20 53 52 54 5f 4d 65 6d 20 20 ** SRT_Mem
1d690 20 20 20 20 20 20 20 4f 6e 6c 79 20 76 61 6c 69 Only vali
1d6a0 64 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 20 d if the result
1d6b0 69 73 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c 75 is a single colu
1d6c0 6d 6e 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 mn..**
1d6d0 20 20 20 20 20 20 20 20 20 20 20 53 74 6f 72 65 Store
1d6e0 20 74 68 65 20 66 69 72 73 74 20 63 6f 6c 75 6d the first colum
1d6f0 6e 20 6f 66 20 74 68 65 20 66 69 72 73 74 20 72 n of the first r
1d700 65 73 75 6c 74 20 72 6f 77 0a 2a 2a 20 20 20 20 esult row.**
1d710 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d720 20 69 6e 20 72 65 67 69 73 74 65 72 20 70 44 65 in register pDe
1d730 73 74 2d 3e 69 53 44 50 61 72 6d 20 74 68 65 6e st->iSDParm then
1d740 20 61 62 61 6e 64 6f 6e 20 74 68 65 20 72 65 73 abandon the res
1d750 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 t.**
1d760 20 20 20 20 20 20 20 20 20 6f 66 20 74 68 65 20 of the
1d770 71 75 65 72 79 2e 20 20 54 68 69 73 20 64 65 73 query. This des
1d780 74 69 6e 61 74 69 6f 6e 20 69 6d 70 6c 69 65 73 tination implies
1d790 20 22 4c 49 4d 49 54 20 31 22 2e 0a 2a 2a 0a 2a "LIMIT 1"..**.*
1d7a0 2a 20 20 20 20 20 53 52 54 5f 53 65 74 20 20 20 * SRT_Set
1d7b0 20 20 20 20 20 20 54 68 65 20 72 65 73 75 6c 74 The result
1d7c0 20 6d 75 73 74 20 62 65 20 61 20 73 69 6e 67 6c must be a singl
1d7d0 65 20 63 6f 6c 75 6d 6e 2e 20 20 53 74 6f 72 65 e column. Store
1d7e0 20 65 61 63 68 0a 2a 2a 20 20 20 20 20 20 20 20 each.**
1d7f0 20 20 20 20 20 20 20 20 20 20 20 20 20 72 6f 77 row
1d800 20 6f 66 20 72 65 73 75 6c 74 20 61 73 20 74 68 of result as th
1d810 65 20 6b 65 79 20 69 6e 20 74 61 62 6c 65 20 70 e key in table p
1d820 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a Dest->iSDParm..*
1d830 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1d840 20 20 20 20 20 20 41 70 70 6c 79 20 74 68 65 20 Apply the
1d850 61 66 66 69 6e 69 74 79 20 70 44 65 73 74 2d 3e affinity pDest->
1d860 61 66 66 53 64 73 74 20 62 65 66 6f 72 65 20 73 affSdst before s
1d870 74 6f 72 69 6e 67 0a 2a 2a 20 20 20 20 20 20 20 toring.**
1d880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 65 re
1d890 73 75 6c 74 73 2e 20 20 55 73 65 64 20 74 6f 20 sults. Used to
1d8a0 69 6d 70 6c 65 6d 65 6e 74 20 22 49 4e 20 28 53 implement "IN (S
1d8b0 45 4c 45 43 54 20 2e 2e 2e 29 22 2e 0a 2a 2a 0a ELECT ...)"..**.
1d8c0 2a 2a 20 20 20 20 20 53 52 54 5f 45 70 68 65 6d ** SRT_Ephem
1d8d0 54 61 62 20 20 20 20 43 72 65 61 74 65 20 61 6e Tab Create an
1d8e0 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 temporary table
1d8f0 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 pDest->iSDParm
1d900 61 6e 64 20 73 74 6f 72 65 0a 2a 2a 20 20 20 20 and store.**
1d910 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d920 20 74 68 65 20 72 65 73 75 6c 74 20 74 68 65 72 the result ther
1d930 65 2e 20 54 68 65 20 63 75 72 73 6f 72 20 69 73 e. The cursor is
1d940 20 6c 65 66 74 20 6f 70 65 6e 20 61 66 74 65 72 left open after
1d950 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
1d960 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 69 6e returnin
1d970 67 2e 20 20 54 68 69 73 20 69 73 20 6c 69 6b 65 g. This is like
1d980 20 53 52 54 5f 54 61 62 6c 65 20 65 78 63 65 70 SRT_Table excep
1d990 74 20 74 68 61 74 0a 2a 2a 20 20 20 20 20 20 20 t that.**
1d9a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 th
1d9b0 69 73 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 75 is destination u
1d9c0 73 65 73 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d ses OP_OpenEphem
1d9d0 65 72 61 6c 20 74 6f 20 63 72 65 61 74 65 0a 2a eral to create.*
1d9e0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1d9f0 20 20 20 20 20 20 74 68 65 20 74 61 62 6c 65 20 the table
1da00 66 69 72 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 first..**.**
1da10 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 SRT_Coroutine
1da20 20 47 65 6e 65 72 61 74 65 20 61 20 63 6f 2d 72 Generate a co-r
1da30 6f 75 74 69 6e 65 20 74 68 61 74 20 72 65 74 75 outine that retu
1da40 72 6e 73 20 61 20 6e 65 77 20 72 6f 77 20 6f 66 rns a new row of
1da50 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
1da60 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 73 20 results
1da70 65 61 63 68 20 74 69 6d 65 20 69 74 20 69 73 20 each time it is
1da80 69 6e 76 6f 6b 65 64 2e 20 20 54 68 65 20 65 6e invoked. The en
1da90 74 72 79 20 70 6f 69 6e 74 0a 2a 2a 20 20 20 20 try point.**
1daa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1dab0 20 6f 66 20 74 68 65 20 63 6f 2d 72 6f 75 74 69 of the co-routi
1dac0 6e 65 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 ne is stored in
1dad0 72 65 67 69 73 74 65 72 20 70 44 65 73 74 2d 3e register pDest->
1dae0 69 53 44 50 61 72 6d 0a 2a 2a 20 20 20 20 20 20 iSDParm.**
1daf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 a
1db00 6e 64 20 74 68 65 20 72 65 73 75 6c 74 20 72 6f nd the result ro
1db10 77 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 70 w is stored in p
1db20 44 65 73 74 2d 3e 6e 44 65 73 74 20 72 65 67 69 Dest->nDest regi
1db30 73 74 65 72 73 0a 2a 2a 20 20 20 20 20 20 20 20 sters.**
1db40 20 20 20 20 20 20 20 20 20 20 20 20 20 73 74 61 sta
1db50 72 74 69 6e 67 20 77 69 74 68 20 70 44 65 73 74 rting with pDest
1db60 2d 3e 69 53 64 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 ->iSdst..**.**
1db70 20 20 20 53 52 54 5f 54 61 62 6c 65 20 20 20 20 SRT_Table
1db80 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 Store results
1db90 20 69 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 61 in temporary ta
1dba0 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 ble pDest->iSDPa
1dbb0 72 6d 2e 0a 2a 2a 20 20 20 20 20 53 52 54 5f 46 rm..** SRT_F
1dbc0 69 66 6f 20 20 20 20 20 20 20 20 54 68 69 73 20 ifo This
1dbd0 69 73 20 6c 69 6b 65 20 53 52 54 5f 45 70 68 65 is like SRT_Ephe
1dbe0 6d 54 61 62 20 65 78 63 65 70 74 20 74 68 61 74 mTab except that
1dbf0 20 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 20 20 the table.**
1dc00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1dc10 20 20 69 73 20 61 73 73 75 6d 65 64 20 74 6f 20 is assumed to
1dc20 61 6c 72 65 61 64 79 20 62 65 20 6f 70 65 6e 2e already be open.
1dc30 20 20 53 52 54 5f 46 69 66 6f 20 68 61 73 0a 2a SRT_Fifo has.*
1dc40 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1dc50 20 20 20 20 20 20 74 68 65 20 61 64 64 69 74 69 the additi
1dc60 6f 6e 61 6c 20 70 72 6f 70 65 72 74 79 20 6f 66 onal property of
1dc70 20 62 65 69 6e 67 20 61 62 6c 65 20 74 6f 20 69 being able to i
1dc80 67 6e 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 gnore.**
1dc90 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 the
1dca0 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 ORDER BY clause
1dcb0 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
1dcc0 44 69 73 74 46 69 66 6f 20 20 20 20 53 74 6f 72 DistFifo Stor
1dcd0 65 20 72 65 73 75 6c 74 73 20 69 6e 20 61 20 74 e results in a t
1dce0 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 emporary table p
1dcf0 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a Dest->iSDParm..*
1dd00 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1dd10 20 20 20 20 20 20 42 75 74 20 61 6c 73 6f 20 75 But also u
1dd20 73 65 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 se temporary tab
1dd30 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 le pDest->iSDPar
1dd40 6d 2b 31 20 61 73 0a 2a 2a 20 20 20 20 20 20 20 m+1 as.**
1dd50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 20 a
1dd60 72 65 63 6f 72 64 20 6f 66 20 61 6c 6c 20 70 72 record of all pr
1dd70 69 6f 72 20 72 65 73 75 6c 74 73 20 61 6e 64 20 ior results and
1dd80 69 67 6e 6f 72 65 20 61 6e 79 20 64 75 70 6c 69 ignore any dupli
1dd90 63 61 74 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 cate.**
1dda0 20 20 20 20 20 20 20 20 20 20 20 20 72 6f 77 73 rows
1ddb0 2e 20 20 4e 61 6d 65 20 6d 65 61 6e 73 3a 20 20 . Name means:
1ddc0 22 44 69 73 74 69 6e 63 74 20 46 69 66 6f 22 2e "Distinct Fifo".
1ddd0 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 51 .**.** SRT_Q
1dde0 75 65 75 65 20 20 20 20 20 20 20 53 74 6f 72 65 ueue Store
1ddf0 20 72 65 73 75 6c 74 73 20 69 6e 20 70 72 69 6f results in prio
1de00 72 69 74 79 20 71 75 65 75 65 20 70 44 65 73 74 rity queue pDest
1de10 2d 3e 69 53 44 50 61 72 6d 20 28 72 65 61 6c 6c ->iSDParm (reall
1de20 79 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 y.**
1de30 20 20 20 20 20 20 20 20 20 61 6e 20 69 6e 64 65 an inde
1de40 78 29 2e 20 20 41 70 70 65 6e 64 20 61 20 73 65 x). Append a se
1de50 71 75 65 6e 63 65 20 6e 75 6d 62 65 72 20 73 6f quence number so
1de60 20 74 68 61 74 20 61 6c 6c 20 65 6e 74 72 69 65 that all entrie
1de70 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 s.**
1de80 20 20 20 20 20 20 20 20 20 61 72 65 20 64 69 73 are dis
1de90 74 69 6e 63 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 tinct..**.**
1dea0 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 20 20 SRT_DistQueue
1deb0 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 Store results i
1dec0 6e 20 70 72 69 6f 72 69 74 79 20 71 75 65 75 65 n priority queue
1ded0 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 pDest->iSDParm
1dee0 6f 6e 6c 79 20 69 66 0a 2a 2a 20 20 20 20 20 20 only if.**
1def0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
1df00 68 65 20 73 61 6d 65 20 72 65 63 6f 72 64 20 68 he same record h
1df10 61 73 20 6e 65 76 65 72 20 62 65 65 6e 20 73 74 as never been st
1df20 6f 72 65 64 20 62 65 66 6f 72 65 2e 20 20 54 68 ored before. Th
1df30 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 e.**
1df40 20 20 20 20 20 20 20 20 20 69 6e 64 65 78 20 61 index a
1df50 74 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d t pDest->iSDParm
1df60 2b 31 20 68 6f 6c 64 20 61 6c 6c 20 70 72 69 6f +1 hold all prio
1df70 72 20 73 74 6f 72 65 73 2e 0a 2a 2f 0a 23 64 65 r stores..*/.#de
1df80 66 69 6e 65 20 53 52 54 5f 55 6e 69 6f 6e 20 20 fine SRT_Union
1df90 20 20 20 20 20 20 31 20 20 2f 2a 20 53 74 6f 72 1 /* Stor
1dfa0 65 20 72 65 73 75 6c 74 20 61 73 20 6b 65 79 73 e result as keys
1dfb0 20 69 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a in an index */.
1dfc0 23 64 65 66 69 6e 65 20 53 52 54 5f 45 78 63 65 #define SRT_Exce
1dfd0 70 74 20 20 20 20 20 20 20 32 20 20 2f 2a 20 52 pt 2 /* R
1dfe0 65 6d 6f 76 65 20 72 65 73 75 6c 74 20 66 72 6f emove result fro
1dff0 6d 20 61 20 55 4e 49 4f 4e 20 69 6e 64 65 78 20 m a UNION index
1e000 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 45 */.#define SRT_E
1e010 78 69 73 74 73 20 20 20 20 20 20 20 33 20 20 2f xists 3 /
1e020 2a 20 53 74 6f 72 65 20 31 20 69 66 20 74 68 65 * Store 1 if the
1e030 20 72 65 73 75 6c 74 20 69 73 20 6e 6f 74 20 65 result is not e
1e040 6d 70 74 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 mpty */.#define
1e050 53 52 54 5f 44 69 73 63 61 72 64 20 20 20 20 20 SRT_Discard
1e060 20 34 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 73 61 4 /* Do not sa
1e070 76 65 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 ve the results a
1e080 6e 79 77 68 65 72 65 20 2a 2f 0a 23 64 65 66 69 nywhere */.#defi
1e090 6e 65 20 53 52 54 5f 46 69 66 6f 20 20 20 20 20 ne SRT_Fifo
1e0a0 20 20 20 20 35 20 20 2f 2a 20 53 74 6f 72 65 20 5 /* Store
1e0b0 72 65 73 75 6c 74 20 61 73 20 64 61 74 61 20 77 result as data w
1e0c0 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 ith an automatic
1e0d0 20 72 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e rowid */.#defin
1e0e0 65 20 53 52 54 5f 44 69 73 74 46 69 66 6f 20 20 e SRT_DistFifo
1e0f0 20 20 20 36 20 20 2f 2a 20 4c 69 6b 65 20 53 52 6 /* Like SR
1e100 54 5f 46 69 66 6f 2c 20 62 75 74 20 75 6e 69 71 T_Fifo, but uniq
1e110 75 65 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 ue results only
1e120 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 51 */.#define SRT_Q
1e130 75 65 75 65 20 20 20 20 20 20 20 20 37 20 20 2f ueue 7 /
1e140 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 * Store result i
1e150 6e 20 61 6e 20 71 75 65 75 65 20 2a 2f 0a 23 64 n an queue */.#d
1e160 65 66 69 6e 65 20 53 52 54 5f 44 69 73 74 51 75 efine SRT_DistQu
1e170 65 75 65 20 20 20 20 38 20 20 2f 2a 20 4c 69 6b eue 8 /* Lik
1e180 65 20 53 52 54 5f 51 75 65 75 65 2c 20 62 75 74 e SRT_Queue, but
1e190 20 75 6e 69 71 75 65 20 72 65 73 75 6c 74 73 20 unique results
1e1a0 6f 6e 6c 79 20 2a 2f 0a 0a 2f 2a 20 54 68 65 20 only */../* The
1e1b0 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 20 ORDER BY clause
1e1c0 69 73 20 69 67 6e 6f 72 65 64 20 66 6f 72 20 61 is ignored for a
1e1d0 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 ll of the above
1e1e0 2a 2f 0a 23 64 65 66 69 6e 65 20 49 67 6e 6f 72 */.#define Ignor
1e1f0 61 62 6c 65 4f 72 64 65 72 62 79 28 58 29 20 28 ableOrderby(X) (
1e200 28 58 2d 3e 65 44 65 73 74 29 3c 3d 53 52 54 5f (X->eDest)<=SRT_
1e210 44 69 73 74 51 75 65 75 65 29 0a 0a 23 64 65 66 DistQueue)..#def
1e220 69 6e 65 20 53 52 54 5f 4f 75 74 70 75 74 20 20 ine SRT_Output
1e230 20 20 20 20 20 39 20 20 2f 2a 20 4f 75 74 70 75 9 /* Outpu
1e240 74 20 65 61 63 68 20 72 6f 77 20 6f 66 20 72 65 t each row of re
1e250 73 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 sult */.#define
1e260 53 52 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 20 SRT_Mem
1e270 31 30 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 10 /* Store res
1e280 75 6c 74 20 69 6e 20 61 20 6d 65 6d 6f 72 79 20 ult in a memory
1e290 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 cell */.#define
1e2a0 53 52 54 5f 53 65 74 20 20 20 20 20 20 20 20 20 SRT_Set
1e2b0 31 31 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 11 /* Store res
1e2c0 75 6c 74 73 20 61 73 20 6b 65 79 73 20 69 6e 20 ults as keys in
1e2d0 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 an index */.#def
1e2e0 69 6e 65 20 53 52 54 5f 45 70 68 65 6d 54 61 62 ine SRT_EphemTab
1e2f0 20 20 20 20 31 32 20 20 2f 2a 20 43 72 65 61 74 12 /* Creat
1e300 65 20 74 72 61 6e 73 69 65 6e 74 20 74 61 62 20 e transient tab
1e310 61 6e 64 20 73 74 6f 72 65 20 6c 69 6b 65 20 53 and store like S
1e320 52 54 5f 54 61 62 6c 65 20 2a 2f 0a 23 64 65 66 RT_Table */.#def
1e330 69 6e 65 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e ine SRT_Coroutin
1e340 65 20 20 20 31 33 20 20 2f 2a 20 47 65 6e 65 72 e 13 /* Gener
1e350 61 74 65 20 61 20 73 69 6e 67 6c 65 20 72 6f 77 ate a single row
1e360 20 6f 66 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 of result */.#d
1e370 65 66 69 6e 65 20 53 52 54 5f 54 61 62 6c 65 20 efine SRT_Table
1e380 20 20 20 20 20 20 31 34 20 20 2f 2a 20 53 74 6f 14 /* Sto
1e390 72 65 20 72 65 73 75 6c 74 20 61 73 20 64 61 74 re result as dat
1e3a0 61 20 77 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 a with an automa
1e3b0 74 69 63 20 72 6f 77 69 64 20 2a 2f 0a 0a 2f 2a tic rowid */../*
1e3c0 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
1e3d0 6f 66 20 74 68 69 73 20 6f 62 6a 65 63 74 20 64 of this object d
1e3e0 65 73 63 72 69 62 65 73 20 77 68 65 72 65 20 74 escribes where t
1e3f0 6f 20 70 75 74 20 6f 66 20 74 68 65 20 72 65 73 o put of the res
1e400 75 6c 74 73 20 6f 66 0a 2a 2a 20 61 20 53 45 4c ults of.** a SEL
1e410 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a ECT statement..*
1e420 2f 0a 73 74 72 75 63 74 20 53 65 6c 65 63 74 44 /.struct SelectD
1e430 65 73 74 20 7b 0a 20 20 75 38 20 65 44 65 73 74 est {. u8 eDest
1e440 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1e450 48 6f 77 20 74 6f 20 64 69 73 70 6f 73 65 20 6f How to dispose o
1e460 66 20 74 68 65 20 72 65 73 75 6c 74 73 2e 20 20 f the results.
1e470 4f 6e 20 6f 66 20 53 52 54 5f 2a 20 61 62 6f 76 On of SRT_* abov
1e480 65 2e 20 2a 2f 0a 20 20 69 6e 74 20 69 53 44 50 e. */. int iSDP
1e490 61 72 6d 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 arm; /*
1e4a0 41 20 70 61 72 61 6d 65 74 65 72 20 75 73 65 64 A parameter used
1e4b0 20 62 79 20 74 68 65 20 65 44 65 73 74 20 64 69 by the eDest di
1e4c0 73 70 6f 73 61 6c 20 6d 65 74 68 6f 64 20 2a 2f sposal method */
1e4d0 0a 20 20 69 6e 74 20 69 53 64 73 74 3b 20 20 20 . int iSdst;
1e4e0 20 20 20 20 20 20 20 20 2f 2a 20 42 61 73 65 20 /* Base
1e4f0 72 65 67 69 73 74 65 72 20 77 68 65 72 65 20 72 register where r
1e500 65 73 75 6c 74 73 20 61 72 65 20 77 72 69 74 74 esults are writt
1e510 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 64 73 en */. int nSds
1e520 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
1e530 4e 75 6d 62 65 72 20 6f 66 20 72 65 67 69 73 74 Number of regist
1e540 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 2a 2f ers allocated */
1e550 0a 20 20 63 68 61 72 20 2a 7a 41 66 66 53 64 73 . char *zAffSds
1e560 74 3b 20 20 20 20 20 20 2f 2a 20 41 66 66 69 6e t; /* Affin
1e570 69 74 79 20 75 73 65 64 20 77 68 65 6e 20 65 44 ity used when eD
1e580 65 73 74 3d 3d 53 52 54 5f 53 65 74 20 2a 2f 0a est==SRT_Set */.
1e590 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 ExprList *pOrd
1e5a0 65 72 42 79 3b 20 20 2f 2a 20 4b 65 79 20 63 6f erBy; /* Key co
1e5b0 6c 75 6d 6e 73 20 66 6f 72 20 53 52 54 5f 51 75 lumns for SRT_Qu
1e5c0 65 75 65 20 61 6e 64 20 53 52 54 5f 44 69 73 74 eue and SRT_Dist
1e5d0 51 75 65 75 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a Queue */.};../*.
1e5e0 2a 2a 20 44 75 72 69 6e 67 20 63 6f 64 65 20 67 ** During code g
1e5f0 65 6e 65 72 61 74 69 6f 6e 20 6f 66 20 73 74 61 eneration of sta
1e600 74 65 6d 65 6e 74 73 20 74 68 61 74 20 64 6f 20 tements that do
1e610 69 6e 73 65 72 74 73 20 69 6e 74 6f 20 41 55 54 inserts into AUT
1e620 4f 49 4e 43 52 45 4d 45 4e 54 0a 2a 2a 20 74 61 OINCREMENT.** ta
1e630 62 6c 65 73 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 bles, the follow
1e640 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 ing information
1e650 69 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 is attached to t
1e660 68 65 20 54 61 62 6c 65 2e 75 2e 61 75 74 6f 49 he Table.u.autoI
1e670 6e 63 2e 70 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 nc.p.** pointer
1e680 6f 66 20 65 61 63 68 20 61 75 74 6f 69 6e 63 72 of each autoincr
1e690 65 6d 65 6e 74 20 74 61 62 6c 65 20 74 6f 20 72 ement table to r
1e6a0 65 63 6f 72 64 20 73 6f 6d 65 20 73 69 64 65 20 ecord some side
1e6b0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 74 information that
1e6c0 0a 2a 2a 20 74 68 65 20 63 6f 64 65 20 67 65 6e .** the code gen
1e6d0 65 72 61 74 6f 72 20 6e 65 65 64 73 2e 20 20 57 erator needs. W
1e6e0 65 20 68 61 76 65 20 74 6f 20 6b 65 65 70 20 70 e have to keep p
1e6f0 65 72 2d 74 61 62 6c 65 20 61 75 74 6f 69 6e 63 er-table autoinc
1e700 72 65 6d 65 6e 74 0a 2a 2a 20 69 6e 66 6f 72 6d rement.** inform
1e710 61 74 69 6f 6e 20 69 6e 20 63 61 73 65 20 69 6e ation in case in
1e720 73 65 72 74 73 20 61 72 65 20 64 6f 6e 65 20 77 serts are done w
1e730 69 74 68 69 6e 20 74 72 69 67 67 65 72 73 2e 20 ithin triggers.
1e740 20 54 72 69 67 67 65 72 73 20 64 6f 20 6e 6f 74 Triggers do not
1e750 0a 2a 2a 20 6e 6f 72 6d 61 6c 6c 79 20 63 6f 6f .** normally coo
1e760 72 64 69 6e 61 74 65 20 74 68 65 69 72 20 61 63 rdinate their ac
1e770 74 69 76 69 74 69 65 73 2c 20 62 75 74 20 77 65 tivities, but we
1e780 20 64 6f 20 6e 65 65 64 20 74 6f 20 63 6f 6f 72 do need to coor
1e790 64 69 6e 61 74 65 20 74 68 65 0a 2a 2a 20 6c 6f dinate the.** lo
1e7a0 61 64 69 6e 67 20 61 6e 64 20 73 61 76 69 6e 67 ading and saving
1e7b0 20 6f 66 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e of autoincremen
1e7c0 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a t information..*
1e7d0 2f 0a 73 74 72 75 63 74 20 41 75 74 6f 69 6e 63 /.struct Autoinc
1e7e0 49 6e 66 6f 20 7b 0a 20 20 41 75 74 6f 69 6e 63 Info {. Autoinc
1e7f0 49 6e 66 6f 20 2a 70 4e 65 78 74 3b 20 20 20 2f Info *pNext; /
1e800 2a 20 4e 65 78 74 20 69 6e 66 6f 20 62 6c 6f 63 * Next info bloc
1e810 6b 20 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 74 k in a list of t
1e820 68 65 6d 20 61 6c 6c 20 2a 2f 0a 20 20 54 61 62 hem all */. Tab
1e830 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 le *pTab;
1e840 20 20 20 2f 2a 20 54 61 62 6c 65 20 74 68 69 73 /* Table this
1e850 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 72 65 66 65 info block refe
1e860 72 73 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 69 rs to */. int i
1e870 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 Db;
1e880 20 2f 2a 20 49 6e 64 65 78 20 69 6e 20 73 71 6c /* Index in sql
1e890 69 74 65 33 2e 61 44 62 5b 5d 20 6f 66 20 64 61 ite3.aDb[] of da
1e8a0 74 61 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 70 tabase holding p
1e8b0 54 61 62 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 Tab */. int reg
1e8c0 43 74 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f Ctr; /
1e8d0 2a 20 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 * Memory registe
1e8e0 72 20 68 6f 6c 64 69 6e 67 20 74 68 65 20 72 6f r holding the ro
1e8f0 77 69 64 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 7d wid counter */.}
1e900 3b 0a 0a 2f 2a 0a 2a 2a 20 53 69 7a 65 20 6f 66 ;../*.** Size of
1e910 20 74 68 65 20 63 6f 6c 75 6d 6e 20 63 61 63 68 the column cach
1e920 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c e.*/.#ifndef SQL
1e930 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 0a 23 ITE_N_COLCACHE.#
1e940 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e define SQLITE_N
1e950 5f 43 4f 4c 43 41 43 48 45 20 31 30 0a 23 65 6e _COLCACHE 10.#en
1e960 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 74 20 6c 65 dif../*.** At le
1e970 61 73 74 20 6f 6e 65 20 69 6e 73 74 61 6e 63 65 ast one instance
1e980 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
1e990 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 63 g structure is c
1e9a0 72 65 61 74 65 64 20 66 6f 72 20 65 61 63 68 0a reated for each.
1e9b0 2a 2a 20 74 72 69 67 67 65 72 20 74 68 61 74 20 ** trigger that
1e9c0 6d 61 79 20 62 65 20 66 69 72 65 64 20 77 68 69 may be fired whi
1e9d0 6c 65 20 70 61 72 73 69 6e 67 20 61 6e 20 49 4e le parsing an IN
1e9e0 53 45 52 54 2c 20 55 50 44 41 54 45 20 6f 72 20 SERT, UPDATE or
1e9f0 44 45 4c 45 54 45 0a 2a 2a 20 73 74 61 74 65 6d DELETE.** statem
1ea00 65 6e 74 2e 20 41 6c 6c 20 73 75 63 68 20 6f 62 ent. All such ob
1ea10 6a 65 63 74 73 20 61 72 65 20 73 74 6f 72 65 64 jects are stored
1ea20 20 69 6e 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c in the linked l
1ea30 69 73 74 20 68 65 61 64 65 64 20 61 74 0a 2a 2a ist headed at.**
1ea40 20 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 Parse.pTriggerP
1ea50 72 67 20 61 6e 64 20 64 65 6c 65 74 65 64 20 6f rg and deleted o
1ea60 6e 63 65 20 73 74 61 74 65 6d 65 6e 74 20 63 6f nce statement co
1ea70 6d 70 69 6c 61 74 69 6f 6e 20 68 61 73 20 62 65 mpilation has be
1ea80 65 6e 0a 2a 2a 20 63 6f 6d 70 6c 65 74 65 64 2e en.** completed.
1ea90 0a 2a 2a 0a 2a 2a 20 41 20 56 64 62 65 20 73 75 .**.** A Vdbe su
1eaa0 62 2d 70 72 6f 67 72 61 6d 20 74 68 61 74 20 69 b-program that i
1eab0 6d 70 6c 65 6d 65 6e 74 73 20 74 68 65 20 62 6f mplements the bo
1eac0 64 79 20 61 6e 64 20 57 48 45 4e 20 63 6c 61 75 dy and WHEN clau
1ead0 73 65 20 6f 66 20 74 72 69 67 67 65 72 0a 2a 2a se of trigger.**
1eae0 20 54 72 69 67 67 65 72 50 72 67 2e 70 54 72 69 TriggerPrg.pTri
1eaf0 67 67 65 72 2c 20 61 73 73 75 6d 69 6e 67 20 61 gger, assuming a
1eb00 20 64 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 default ON CONF
1eb10 4c 49 43 54 20 63 6c 61 75 73 65 20 6f 66 0a 2a LICT clause of.*
1eb20 2a 20 54 72 69 67 67 65 72 50 72 67 2e 6f 72 63 * TriggerPrg.orc
1eb30 6f 6e 66 2c 20 69 73 20 73 74 6f 72 65 64 20 69 onf, is stored i
1eb40 6e 20 74 68 65 20 54 72 69 67 67 65 72 50 72 67 n the TriggerPrg
1eb50 2e 70 50 72 6f 67 72 61 6d 20 76 61 72 69 61 62 .pProgram variab
1eb60 6c 65 2e 0a 2a 2a 20 54 68 65 20 50 61 72 73 65 le..** The Parse
1eb70 2e 70 54 72 69 67 67 65 72 50 72 67 20 6c 69 73 .pTriggerPrg lis
1eb80 74 20 6e 65 76 65 72 20 63 6f 6e 74 61 69 6e 73 t never contains
1eb90 20 74 77 6f 20 65 6e 74 72 69 65 73 20 77 69 74 two entries wit
1eba0 68 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 76 61 h the same.** va
1ebb0 6c 75 65 73 20 66 6f 72 20 62 6f 74 68 20 70 54 lues for both pT
1ebc0 72 69 67 67 65 72 20 61 6e 64 20 6f 72 63 6f 6e rigger and orcon
1ebd0 66 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 54 72 69 f..**.** The Tri
1ebe0 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b ggerPrg.aColmask
1ebf0 5b 30 5d 20 76 61 72 69 61 62 6c 65 20 69 73 20 [0] variable is
1ec00 73 65 74 20 74 6f 20 61 20 6d 61 73 6b 20 6f 66 set to a mask of
1ec10 20 6f 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 0a 2a old.* columns.*
1ec20 2a 20 61 63 63 65 73 73 65 64 20 28 6f 72 20 73 * accessed (or s
1ec30 65 74 20 74 6f 20 30 20 66 6f 72 20 74 72 69 67 et to 0 for trig
1ec40 67 65 72 73 20 66 69 72 65 64 20 61 73 20 61 20 gers fired as a
1ec50 72 65 73 75 6c 74 20 6f 66 20 49 4e 53 45 52 54 result of INSERT
1ec60 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 73 29 2e .** statements).
1ec70 20 53 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65 20 Similarly, the
1ec80 54 72 69 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d TriggerPrg.aColm
1ec90 61 73 6b 5b 31 5d 20 76 61 72 69 61 62 6c 65 20 ask[1] variable
1eca0 69 73 20 73 65 74 20 74 6f 0a 2a 2a 20 61 20 6d is set to.** a m
1ecb0 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c ask of new.* col
1ecc0 75 6d 6e 73 20 75 73 65 64 20 62 79 20 74 68 65 umns used by the
1ecd0 20 70 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 program..*/.str
1ece0 75 63 74 20 54 72 69 67 67 65 72 50 72 67 20 7b uct TriggerPrg {
1ecf0 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 . Trigger *pTri
1ed00 67 67 65 72 3b 20 20 20 20 20 20 2f 2a 20 54 72 gger; /* Tr
1ed10 69 67 67 65 72 20 74 68 69 73 20 70 72 6f 67 72 igger this progr
1ed20 61 6d 20 77 61 73 20 63 6f 64 65 64 20 66 72 6f am was coded fro
1ed30 6d 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 72 m */. TriggerPr
1ed40 67 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 2f g *pNext; /
1ed50 2a 20 4e 65 78 74 20 65 6e 74 72 79 20 69 6e 20 * Next entry in
1ed60 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 Parse.pTriggerPr
1ed70 67 20 6c 69 73 74 20 2a 2f 0a 20 20 53 75 62 50 g list */. SubP
1ed80 72 6f 67 72 61 6d 20 2a 70 50 72 6f 67 72 61 6d rogram *pProgram
1ed90 3b 20 20 20 2f 2a 20 50 72 6f 67 72 61 6d 20 69 ; /* Program i
1eda0 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 70 54 72 69 mplementing pTri
1edb0 67 67 65 72 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 gger/orconf */.
1edc0 20 69 6e 74 20 6f 72 63 6f 6e 66 3b 20 20 20 20 int orconf;
1edd0 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 /* Defa
1ede0 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 ult ON CONFLICT
1edf0 70 6f 6c 69 63 79 20 2a 2f 0a 20 20 75 33 32 20 policy */. u32
1ee00 61 43 6f 6c 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 aColmask[2];
1ee10 20 20 20 20 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 /* Masks of
1ee20 6f 6c 64 2e 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c old.*, new.* col
1ee30 75 6d 6e 73 20 61 63 63 65 73 73 65 64 20 2a 2f umns accessed */
1ee40 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 .};../*.** The y
1ee50 44 62 4d 61 73 6b 20 64 61 74 61 74 79 70 65 20 DbMask datatype
1ee60 66 6f 72 20 74 68 65 20 62 69 74 6d 61 73 6b 20 for the bitmask
1ee70 6f 66 20 61 6c 6c 20 61 74 74 61 63 68 65 64 20 of all attached
1ee80 64 61 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 databases..*/.#i
1ee90 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 f SQLITE_MAX_ATT
1eea0 41 43 48 45 44 3e 33 30 0a 20 20 74 79 70 65 64 ACHED>30. typed
1eeb0 65 66 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 ef unsigned char
1eec0 20 79 44 62 4d 61 73 6b 5b 28 53 51 4c 49 54 45 yDbMask[(SQLITE
1eed0 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 2b 39 29 _MAX_ATTACHED+9)
1eee0 2f 38 5d 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 /8];.# define Db
1eef0 4d 61 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 MaskTest(M,I)
1ef00 20 28 28 28 4d 29 5b 28 49 29 2f 38 5d 26 28 31 (((M)[(I)/8]&(1
1ef10 3c 3c 28 28 49 29 26 37 29 29 29 21 3d 30 29 0a <<((I)&7)))!=0).
1ef20 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a # define DbMaskZ
1ef30 65 72 6f 28 4d 29 20 20 20 20 20 20 6d 65 6d 73 ero(M) mems
1ef40 65 74 28 28 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 et((M),0,sizeof(
1ef50 4d 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d M)).# define DbM
1ef60 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 20 askSet(M,I)
1ef70 28 4d 29 5b 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c (M)[(I)/8]|=(1<<
1ef80 28 28 49 29 26 37 29 29 0a 23 20 64 65 66 69 6e ((I)&7)).# defin
1ef90 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 e DbMaskAllZero(
1efa0 4d 29 20 20 20 73 71 6c 69 74 65 33 44 62 4d 61 M) sqlite3DbMa
1efb0 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 skAllZero(M).# d
1efc0 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a efine DbMaskNonZ
1efd0 65 72 6f 28 4d 29 20 20 20 28 73 71 6c 69 74 65 ero(M) (sqlite
1efe0 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 3DbMaskAllZero(M
1eff0 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 20 20 74 79 )==0).#else. ty
1f000 70 65 64 65 66 20 75 6e 73 69 67 6e 65 64 20 69 pedef unsigned i
1f010 6e 74 20 79 44 62 4d 61 73 6b 3b 0a 23 20 64 65 nt yDbMask;.# de
1f020 66 69 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 fine DbMaskTest(
1f030 4d 2c 49 29 20 20 20 20 28 28 28 4d 29 26 28 28 M,I) (((M)&((
1f040 28 79 44 62 4d 61 73 6b 29 31 29 3c 3c 28 49 29 (yDbMask)1)<<(I)
1f050 29 29 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 ))!=0).# define
1f060 44 62 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 DbMaskZero(M)
1f070 20 20 20 28 4d 29 3d 30 0a 23 20 64 65 66 69 6e (M)=0.# defin
1f080 65 20 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 29 e DbMaskSet(M,I)
1f090 20 20 20 20 20 28 4d 29 7c 3d 28 28 28 79 44 62 (M)|=(((yDb
1f0a0 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 0a 23 20 Mask)1)<<(I)).#
1f0b0 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c 6c define DbMaskAll
1f0c0 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 3d 3d 30 Zero(M) (M)==0
1f0d0 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b .# define DbMask
1f0e0 4e 6f 6e 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 NonZero(M) (M)
1f0f0 21 3d 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a !=0.#endif../*.*
1f100 2a 20 41 6e 20 53 51 4c 20 70 61 72 73 65 72 20 * An SQL parser
1f110 63 6f 6e 74 65 78 74 2e 20 20 41 20 63 6f 70 79 context. A copy
1f120 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 of this structu
1f130 72 65 20 69 73 20 70 61 73 73 65 64 20 74 68 72 re is passed thr
1f140 6f 75 67 68 0a 2a 2a 20 74 68 65 20 70 61 72 73 ough.** the pars
1f150 65 72 20 61 6e 64 20 64 6f 77 6e 20 69 6e 74 6f er and down into
1f160 20 61 6c 6c 20 74 68 65 20 70 61 72 73 65 72 20 all the parser
1f170 61 63 74 69 6f 6e 20 72 6f 75 74 69 6e 65 20 69 action routine i
1f180 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 63 61 n order to.** ca
1f190 72 72 79 20 61 72 6f 75 6e 64 20 69 6e 66 6f 72 rry around infor
1f1a0 6d 61 74 69 6f 6e 20 74 68 61 74 20 69 73 20 67 mation that is g
1f1b0 6c 6f 62 61 6c 20 74 6f 20 74 68 65 20 65 6e 74 lobal to the ent
1f1c0 69 72 65 20 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a ire parse..**.**
1f1d0 20 54 68 65 20 73 74 72 75 63 74 75 72 65 20 69 The structure i
1f1e0 73 20 64 69 76 69 64 65 64 20 69 6e 74 6f 20 74 s divided into t
1f1f0 77 6f 20 70 61 72 74 73 2e 20 20 57 68 65 6e 20 wo parts. When
1f200 74 68 65 20 70 61 72 73 65 72 20 61 6e 64 20 63 the parser and c
1f210 6f 64 65 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 ode.** generate
1f220 63 61 6c 6c 20 74 68 65 6d 73 65 6c 76 65 73 20 call themselves
1f230 72 65 63 75 72 73 69 76 65 6c 79 2c 20 74 68 65 recursively, the
1f240 20 66 69 72 73 74 20 70 61 72 74 20 6f 66 20 74 first part of t
1f250 68 65 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 he structure.**
1f260 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 75 74 20 is constant but
1f270 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 74 20 the second part
1f280 69 73 20 72 65 73 65 74 20 61 74 20 74 68 65 20 is reset at the
1f290 62 65 67 69 6e 6e 69 6e 67 20 61 6e 64 20 65 6e beginning and en
1f2a0 64 20 6f 66 0a 2a 2a 20 65 61 63 68 20 72 65 63 d of.** each rec
1f2b0 75 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 ursion..**.** Th
1f2c0 65 20 6e 54 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 e nTableLock and
1f2d0 20 61 54 61 62 6c 65 4c 6f 63 6b 20 76 61 72 69 aTableLock vari
1f2e0 61 62 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 75 ables are only u
1f2f0 73 65 64 20 69 66 20 74 68 65 20 73 68 61 72 65 sed if the share
1f300 64 2d 63 61 63 68 65 0a 2a 2a 20 66 65 61 74 75 d-cache.** featu
1f310 72 65 20 69 73 20 65 6e 61 62 6c 65 64 20 28 69 re is enabled (i
1f320 66 20 73 71 6c 69 74 65 33 54 73 64 28 29 2d 3e f sqlite3Tsd()->
1f330 75 73 65 53 68 61 72 65 64 44 61 74 61 20 69 73 useSharedData is
1f340 20 74 72 75 65 29 2e 20 54 68 65 79 20 61 72 65 true). They are
1f350 0a 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f 72 .** used to stor
1f360 65 20 74 68 65 20 73 65 74 20 6f 66 20 74 61 62 e the set of tab
1f370 6c 65 2d 6c 6f 63 6b 73 20 72 65 71 75 69 72 65 le-locks require
1f380 64 20 62 79 20 74 68 65 20 73 74 61 74 65 6d 65 d by the stateme
1f390 6e 74 20 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d 70 nt being.** comp
1f3a0 69 6c 65 64 2e 20 46 75 6e 63 74 69 6f 6e 20 73 iled. Function s
1f3b0 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 qlite3TableLock(
1f3c0 29 20 69 73 20 75 73 65 64 20 74 6f 20 61 64 64 ) is used to add
1f3d0 20 65 6e 74 72 69 65 73 20 74 6f 20 74 68 65 0a entries to the.
1f3e0 2a 2a 20 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 75 ** list..*/.stru
1f3f0 63 74 20 50 61 72 73 65 20 7b 0a 20 20 73 71 6c ct Parse {. sql
1f400 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 20 ite3 *db;
1f410 20 20 2f 2a 20 54 68 65 20 6d 61 69 6e 20 64 61 /* The main da
1f420 74 61 62 61 73 65 20 73 74 72 75 63 74 75 72 65 tabase structure
1f430 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 */. char *zErr
1f440 4d 73 67 3b 20 20 20 20 20 20 20 2f 2a 20 41 6e Msg; /* An
1f450 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a error message *
1f460 2f 0a 20 20 56 64 62 65 20 2a 70 56 64 62 65 3b /. Vdbe *pVdbe;
1f470 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 /* An e
1f480 6e 67 69 6e 65 20 66 6f 72 20 65 78 65 63 75 74 ngine for execut
1f490 69 6e 67 20 64 61 74 61 62 61 73 65 20 62 79 74 ing database byt
1f4a0 65 63 6f 64 65 20 2a 2f 0a 20 20 69 6e 74 20 72 ecode */. int r
1f4b0 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
1f4c0 2f 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 /* Return code f
1f4d0 72 6f 6d 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f rom execution */
1f4e0 0a 20 20 75 38 20 63 6f 6c 4e 61 6d 65 73 53 65 . u8 colNamesSe
1f4f0 74 3b 20 20 20 20 20 20 2f 2a 20 54 52 55 45 20 t; /* TRUE
1f500 61 66 74 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e 4e after OP_ColumnN
1f510 61 6d 65 20 68 61 73 20 62 65 65 6e 20 69 73 73 ame has been iss
1f520 75 65 64 20 74 6f 20 70 56 64 62 65 20 2a 2f 0a ued to pVdbe */.
1f530 20 20 75 38 20 63 68 65 63 6b 53 63 68 65 6d 61 u8 checkSchema
1f540 3b 20 20 20 20 20 20 2f 2a 20 43 61 75 73 65 73 ; /* Causes
1f550 20 73 63 68 65 6d 61 20 63 6f 6f 6b 69 65 20 63 schema cookie c
1f560 68 65 63 6b 20 61 66 74 65 72 20 61 6e 20 65 72 heck after an er
1f570 72 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 65 73 74 ror */. u8 nest
1f580 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ed; /*
1f590 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 65 Number of neste
1f5a0 64 20 63 61 6c 6c 73 20 74 6f 20 74 68 65 20 70 d calls to the p
1f5b0 61 72 73 65 72 2f 63 6f 64 65 20 67 65 6e 65 72 arser/code gener
1f5c0 61 74 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 54 65 ator */. u8 nTe
1f5d0 6d 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 2f mpReg; /
1f5e0 2a 20 4e 75 6d 62 65 72 20 6f 66 20 74 65 6d 70 * Number of temp
1f5f0 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 73 20 orary registers
1f600 69 6e 20 61 54 65 6d 70 52 65 67 5b 5d 20 2a 2f in aTempReg[] */
1f610 0a 20 20 75 38 20 69 73 4d 75 6c 74 69 57 72 69 . u8 isMultiWri
1f620 74 65 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 te; /* True
1f630 69 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 if statement may
1f640 20 6d 6f 64 69 66 79 2f 69 6e 73 65 72 74 20 6d modify/insert m
1f650 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a ultiple rows */.
1f660 20 20 75 38 20 6d 61 79 41 62 6f 72 74 3b 20 20 u8 mayAbort;
1f670 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
1f680 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 f statement may
1f690 74 68 72 6f 77 20 61 6e 20 41 42 4f 52 54 20 65 throw an ABORT e
1f6a0 78 63 65 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 xception */. u8
1f6b0 20 68 61 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 20 hasCompound;
1f6c0 20 20 20 2f 2a 20 4e 65 65 64 20 74 6f 20 69 6e /* Need to in
1f6d0 76 6f 6b 65 20 63 6f 6e 76 65 72 74 43 6f 6d 70 voke convertComp
1f6e0 6f 75 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 71 oundSelectToSubq
1f6f0 75 65 72 79 28 29 20 2a 2f 0a 20 20 75 38 20 6f uery() */. u8 o
1f700 6b 43 6f 6e 73 74 46 61 63 74 6f 72 3b 20 20 20 kConstFactor;
1f710 20 2f 2a 20 4f 4b 20 74 6f 20 66 61 63 74 6f 72 /* OK to factor
1f720 20 6f 75 74 20 63 6f 6e 73 74 61 6e 74 73 20 2a out constants *
1f730 2f 0a 20 20 75 38 20 64 69 73 61 62 6c 65 4c 6f /. u8 disableLo
1f740 6f 6b 61 73 69 64 65 3b 20 2f 2a 20 4e 75 6d 62 okaside; /* Numb
1f750 65 72 20 6f 66 20 74 69 6d 65 73 20 6c 6f 6f 6b er of times look
1f760 61 73 69 64 65 20 68 61 73 20 62 65 65 6e 20 64 aside has been d
1f770 69 73 61 62 6c 65 64 20 2a 2f 0a 20 20 75 38 20 isabled */. u8
1f780 6e 43 6f 6c 43 61 63 68 65 3b 20 20 20 20 20 20 nColCache;
1f790 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
1f7a0 6e 74 72 69 65 73 20 69 6e 20 61 43 6f 6c 43 61 ntries in aColCa
1f7b0 63 68 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e che[] */. int n
1f7c0 52 61 6e 67 65 52 65 67 3b 20 20 20 20 20 20 20 RangeReg;
1f7d0 2f 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 20 74 /* Size of the t
1f7e0 65 6d 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 emporary registe
1f7f0 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 6e 74 r block */. int
1f800 20 69 52 61 6e 67 65 52 65 67 3b 20 20 20 20 20 iRangeReg;
1f810 20 20 2f 2a 20 46 69 72 73 74 20 72 65 67 69 73 /* First regis
1f820 74 65 72 20 69 6e 20 74 65 6d 70 6f 72 61 72 79 ter in temporary
1f830 20 72 65 67 69 73 74 65 72 20 62 6c 6f 63 6b 20 register block
1f840 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 20 */. int nErr;
1f850 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1f860 62 65 72 20 6f 66 20 65 72 72 6f 72 73 20 73 65 ber of errors se
1f870 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 61 62 en */. int nTab
1f880 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1f890 4e 75 6d 62 65 72 20 6f 66 20 70 72 65 76 69 6f Number of previo
1f8a0 75 73 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 56 usly allocated V
1f8b0 44 42 45 20 63 75 72 73 6f 72 73 20 2a 2f 0a 20 DBE cursors */.
1f8c0 20 69 6e 74 20 6e 4d 65 6d 3b 20 20 20 20 20 20 int nMem;
1f8d0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1f8e0 6f 66 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 73 20 of memory cells
1f8f0 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a 20 used so far */.
1f900 20 69 6e 74 20 6e 4f 70 41 6c 6c 6f 63 3b 20 20 int nOpAlloc;
1f910 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1f920 6f 66 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 74 of slots allocat
1f930 65 64 20 66 6f 72 20 56 64 62 65 2e 61 4f 70 5b ed for Vdbe.aOp[
1f940 5d 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 4f 70 41 ] */. int szOpA
1f950 6c 6c 6f 63 3b 20 20 20 20 20 20 20 2f 2a 20 42 lloc; /* B
1f960 79 74 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 73 ytes of memory s
1f970 70 61 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 66 pace allocated f
1f980 6f 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 2a 2f or Vdbe.aOp[] */
1f990 0a 20 20 69 6e 74 20 69 53 65 6c 66 54 61 62 3b . int iSelfTab;
1f9a0 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
1f9b0 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
1f9c0 20 61 6e 20 69 6e 64 65 78 20 6f 6e 20 65 78 70 an index on exp
1f9d0 72 2c 20 6f 72 20 6e 65 67 61 74 69 76 65 0a 20 r, or negative.
1f9e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f9f0 20 20 20 20 20 20 2a 2a 20 6f 66 20 74 68 65 20 ** of the
1fa00 62 61 73 65 20 72 65 67 69 73 74 65 72 20 64 75 base register du
1fa10 72 69 6e 67 20 63 68 65 63 6b 2d 63 6f 6e 73 74 ring check-const
1fa20 72 61 69 6e 74 20 65 76 61 6c 20 2a 2f 0a 20 20 raint eval */.
1fa30 69 6e 74 20 69 43 61 63 68 65 4c 65 76 65 6c 3b int iCacheLevel;
1fa40 20 20 20 20 20 2f 2a 20 43 6f 6c 43 61 63 68 65 /* ColCache
1fa50 20 76 61 6c 69 64 20 77 68 65 6e 20 61 43 6f 6c valid when aCol
1fa60 43 61 63 68 65 5b 5d 2e 69 4c 65 76 65 6c 3c 3d Cache[].iLevel<=
1fa70 69 43 61 63 68 65 4c 65 76 65 6c 20 2a 2f 0a 20 iCacheLevel */.
1fa80 20 69 6e 74 20 69 43 61 63 68 65 43 6e 74 3b 20 int iCacheCnt;
1fa90 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 65 72 /* Counter
1faa0 20 75 73 65 64 20 74 6f 20 67 65 6e 65 72 61 74 used to generat
1fab0 65 20 61 43 6f 6c 43 61 63 68 65 5b 5d 2e 6c 72 e aColCache[].lr
1fac0 75 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 69 6e u values */. in
1fad0 74 20 6e 4c 61 62 65 6c 3b 20 20 20 20 20 20 20 t nLabel;
1fae0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1faf0 6c 61 62 65 6c 73 20 75 73 65 64 20 2a 2f 0a 20 labels used */.
1fb00 20 69 6e 74 20 2a 61 4c 61 62 65 6c 3b 20 20 20 int *aLabel;
1fb10 20 20 20 20 20 20 2f 2a 20 53 70 61 63 65 20 74 /* Space t
1fb20 6f 20 68 6f 6c 64 20 74 68 65 20 6c 61 62 65 6c o hold the label
1fb30 73 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 s */. ExprList
1fb40 2a 70 43 6f 6e 73 74 45 78 70 72 3b 2f 2a 20 43 *pConstExpr;/* C
1fb50 6f 6e 73 74 61 6e 74 20 65 78 70 72 65 73 73 69 onstant expressi
1fb60 6f 6e 73 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 63 ons */. Token c
1fb70 6f 6e 73 74 72 61 69 6e 74 4e 61 6d 65 3b 2f 2a onstraintName;/*
1fb80 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6e Name of the con
1fb90 73 74 72 61 69 6e 74 20 63 75 72 72 65 6e 74 6c straint currentl
1fba0 79 20 62 65 69 6e 67 20 70 61 72 73 65 64 20 2a y being parsed *
1fbb0 2f 0a 20 20 79 44 62 4d 61 73 6b 20 77 72 69 74 /. yDbMask writ
1fbc0 65 4d 61 73 6b 3b 20 20 20 2f 2a 20 53 74 61 72 eMask; /* Star
1fbd0 74 20 61 20 77 72 69 74 65 20 74 72 61 6e 73 61 t a write transa
1fbe0 63 74 69 6f 6e 20 6f 6e 20 74 68 65 73 65 20 64 ction on these d
1fbf0 61 74 61 62 61 73 65 73 20 2a 2f 0a 20 20 79 44 atabases */. yD
1fc00 62 4d 61 73 6b 20 63 6f 6f 6b 69 65 4d 61 73 6b bMask cookieMask
1fc10 3b 20 20 2f 2a 20 42 69 74 6d 61 73 6b 20 6f 66 ; /* Bitmask of
1fc20 20 73 63 68 65 6d 61 20 76 65 72 69 66 69 65 64 schema verified
1fc30 20 64 61 74 61 62 61 73 65 73 20 2a 2f 0a 20 20 databases */.
1fc40 69 6e 74 20 72 65 67 52 6f 77 69 64 3b 20 20 20 int regRowid;
1fc50 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 /* Register
1fc60 20 68 6f 6c 64 69 6e 67 20 72 6f 77 69 64 20 6f holding rowid o
1fc70 66 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 f CREATE TABLE e
1fc80 6e 74 72 79 20 2a 2f 0a 20 20 69 6e 74 20 72 65 ntry */. int re
1fc90 67 52 6f 6f 74 3b 20 20 20 20 20 20 20 20 20 2f gRoot; /
1fca0 2a 20 52 65 67 69 73 74 65 72 20 68 6f 6c 64 69 * Register holdi
1fcb0 6e 67 20 72 6f 6f 74 20 70 61 67 65 20 6e 75 6d ng root page num
1fcc0 62 65 72 20 66 6f 72 20 6e 65 77 20 6f 62 6a 65 ber for new obje
1fcd0 63 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 cts */. int nMa
1fce0 78 41 72 67 3b 20 20 20 20 20 20 20 20 20 2f 2a xArg; /*
1fcf0 20 4d 61 78 20 61 72 67 73 20 70 61 73 73 65 64 Max args passed
1fd00 20 74 6f 20 75 73 65 72 20 66 75 6e 63 74 69 6f to user functio
1fd10 6e 20 62 79 20 73 75 62 2d 70 72 6f 67 72 61 6d n by sub-program
1fd20 20 2a 2f 0a 23 69 66 20 53 45 4c 45 43 54 54 52 */.#if SELECTTR
1fd30 41 43 45 5f 45 4e 41 42 4c 45 44 0a 20 20 69 6e ACE_ENABLED. in
1fd40 74 20 6e 53 65 6c 65 63 74 3b 20 20 20 20 20 20 t nSelect;
1fd50 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1fd60 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
1fd70 73 20 73 65 65 6e 20 2a 2f 0a 23 65 6e 64 69 66 s seen */.#endif
1fd80 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
1fd90 4f 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 OMIT_SHARED_CACH
1fda0 45 0a 20 20 69 6e 74 20 6e 54 61 62 6c 65 4c 6f E. int nTableLo
1fdb0 63 6b 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ck; /* Nu
1fdc0 6d 62 65 72 20 6f 66 20 6c 6f 63 6b 73 20 69 6e mber of locks in
1fdd0 20 61 54 61 62 6c 65 4c 6f 63 6b 20 2a 2f 0a 20 aTableLock */.
1fde0 20 54 61 62 6c 65 4c 6f 63 6b 20 2a 61 54 61 62 TableLock *aTab
1fdf0 6c 65 4c 6f 63 6b 3b 20 2f 2a 20 52 65 71 75 69 leLock; /* Requi
1fe00 72 65 64 20 74 61 62 6c 65 20 6c 6f 63 6b 73 20 red table locks
1fe10 66 6f 72 20 73 68 61 72 65 64 2d 63 61 63 68 65 for shared-cache
1fe20 20 6d 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a mode */.#endif.
1fe30 20 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 AutoincInfo *p
1fe40 41 69 6e 63 3b 20 20 2f 2a 20 49 6e 66 6f 72 6d Ainc; /* Inform
1fe50 61 74 69 6f 6e 20 61 62 6f 75 74 20 41 55 54 4f ation about AUTO
1fe60 49 4e 43 52 45 4d 45 4e 54 20 63 6f 75 6e 74 65 INCREMENT counte
1fe70 72 73 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 rs */. Parse *p
1fe80 54 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a 20 Toplevel; /*
1fe90 50 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 Parse structure
1fea0 66 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 6d for main program
1feb0 20 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 (or NULL) */.
1fec0 54 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 54 Table *pTriggerT
1fed0 61 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 72 ab; /* Table tr
1fee0 69 67 67 65 72 73 20 61 72 65 20 62 65 69 6e 67 iggers are being
1fef0 20 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 20 coded for */.
1ff00 69 6e 74 20 61 64 64 72 43 72 54 61 62 3b 20 20 int addrCrTab;
1ff10 20 20 20 20 20 2f 2a 20 41 64 64 72 65 73 73 20 /* Address
1ff20 6f 66 20 4f 50 5f 43 72 65 61 74 65 42 74 72 65 of OP_CreateBtre
1ff30 65 20 6f 70 63 6f 64 65 20 6f 6e 20 43 52 45 41 e opcode on CREA
1ff40 54 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 75 33 TE TABLE */. u3
1ff50 32 20 6e 51 75 65 72 79 4c 6f 6f 70 3b 20 20 20 2 nQueryLoop;
1ff60 20 20 20 2f 2a 20 45 73 74 20 6e 75 6d 62 65 72 /* Est number
1ff70 20 6f 66 20 69 74 65 72 61 74 69 6f 6e 73 20 6f of iterations o
1ff80 66 20 61 20 71 75 65 72 79 20 28 31 30 2a 6c 6f f a query (10*lo
1ff90 67 32 28 4e 29 29 20 2a 2f 0a 20 20 75 33 32 20 g2(N)) */. u32
1ffa0 6f 6c 64 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 oldmask;
1ffb0 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f 6c 64 2e /* Mask of old.
1ffc0 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 * columns refere
1ffd0 6e 63 65 64 20 2a 2f 0a 20 20 75 33 32 20 6e 65 nced */. u32 ne
1ffe0 77 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f wmask; /
1fff0 2a 20 4d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 * Mask of new.*
20000 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 columns referenc
20010 65 64 20 2a 2f 0a 20 20 75 38 20 65 54 72 69 67 ed */. u8 eTrig
20020 67 65 72 4f 70 3b 20 20 20 20 20 20 20 2f 2a 20 gerOp; /*
20030 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e TK_UPDATE, TK_IN
20040 53 45 52 54 20 6f 72 20 54 4b 5f 44 45 4c 45 54 SERT or TK_DELET
20050 45 20 2a 2f 0a 20 20 75 38 20 65 4f 72 63 6f 6e E */. u8 eOrcon
20060 66 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 f; /* D
20070 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 efault ON CONFLI
20080 43 54 20 70 6f 6c 69 63 79 20 66 6f 72 20 74 72 CT policy for tr
20090 69 67 67 65 72 20 73 74 65 70 73 20 2a 2f 0a 20 igger steps */.
200a0 20 75 38 20 64 69 73 61 62 6c 65 54 72 69 67 67 u8 disableTrigg
200b0 65 72 73 3b 20 20 2f 2a 20 54 72 75 65 20 74 6f ers; /* True to
200c0 20 64 69 73 61 62 6c 65 20 74 72 69 67 67 65 72 disable trigger
200d0 73 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a 2a s */.. /*******
200e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
200f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20100 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20110 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20120 2a 2a 2a 0a 20 20 2a 2a 20 46 69 65 6c 64 73 20 ***. ** Fields
20130 61 62 6f 76 65 20 6d 75 73 74 20 62 65 20 69 6e above must be in
20140 69 74 69 61 6c 69 7a 65 64 20 74 6f 20 7a 65 72 itialized to zer
20150 6f 2e 20 20 54 68 65 20 66 69 65 6c 64 73 20 74 o. The fields t
20160 68 61 74 20 66 6f 6c 6c 6f 77 2c 0a 20 20 2a 2a hat follow,. **
20170 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 62 65 67 down to the beg
20180 69 6e 6e 69 6e 67 20 6f 66 20 74 68 65 20 72 65 inning of the re
20190 63 75 72 73 69 76 65 20 73 65 63 74 69 6f 6e 2c cursive section,
201a0 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 do not need to
201b0 62 65 0a 20 20 2a 2a 20 69 6e 69 74 69 61 6c 69 be. ** initiali
201c0 7a 65 64 20 61 73 20 74 68 65 79 20 77 69 6c 6c zed as they will
201d0 20 62 65 20 73 65 74 20 62 65 66 6f 72 65 20 62 be set before b
201e0 65 69 6e 67 20 75 73 65 64 2e 20 20 54 68 65 20 eing used. The
201f0 62 6f 75 6e 64 61 72 79 20 69 73 0a 20 20 2a 2a boundary is. **
20200 20 64 65 74 65 72 6d 69 6e 65 64 20 62 79 20 6f determined by o
20210 66 66 73 65 74 6f 66 28 50 61 72 73 65 2c 61 43 ffsetof(Parse,aC
20220 6f 6c 43 61 63 68 65 29 2e 0a 20 20 2a 2a 2a 2a olCache).. ****
20230 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20240 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20250 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20260 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20270 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 73 74 72 75 63 ******/.. struc
20280 74 20 79 43 6f 6c 43 61 63 68 65 20 7b 0a 20 20 t yColCache {.
20290 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 int iTable;
202a0 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
202b0 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 2a cursor number *
202c0 2f 0a 20 20 20 20 69 31 36 20 69 43 6f 6c 75 6d /. i16 iColum
202d0 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 n; /* T
202e0 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 able column numb
202f0 65 72 20 2a 2f 0a 20 20 20 20 75 38 20 74 65 6d er */. u8 tem
20300 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 20 20 pReg;
20310 2f 2a 20 69 52 65 67 20 69 73 20 61 20 74 65 6d /* iReg is a tem
20320 70 20 72 65 67 69 73 74 65 72 20 74 68 61 74 20 p register that
20330 6e 65 65 64 73 20 74 6f 20 62 65 20 66 72 65 65 needs to be free
20340 64 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4c 65 d */. int iLe
20350 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f vel; /
20360 2a 20 4e 65 73 74 69 6e 67 20 6c 65 76 65 6c 20 * Nesting level
20370 2a 2f 0a 20 20 20 20 69 6e 74 20 69 52 65 67 3b */. int iReg;
20380 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
20390 52 65 67 20 77 69 74 68 20 76 61 6c 75 65 20 6f Reg with value o
203a0 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 30 f this column. 0
203b0 20 6d 65 61 6e 73 20 6e 6f 6e 65 2e 20 2a 2f 0a means none. */.
203c0 20 20 20 20 69 6e 74 20 6c 72 75 3b 20 20 20 20 int lru;
203d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 61 /* Lea
203e0 73 74 20 72 65 63 65 6e 74 6c 79 20 75 73 65 64 st recently used
203f0 20 65 6e 74 72 79 20 68 61 73 20 74 68 65 20 73 entry has the s
20400 6d 61 6c 6c 65 73 74 20 76 61 6c 75 65 20 2a 2f mallest value */
20410 0a 20 20 7d 20 61 43 6f 6c 43 61 63 68 65 5b 53 . } aColCache[S
20420 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 QLITE_N_COLCACHE
20430 5d 3b 20 20 2f 2a 20 4f 6e 65 20 66 6f 72 20 65 ]; /* One for e
20440 61 63 68 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 ach column cache
20450 20 65 6e 74 72 79 20 2a 2f 0a 20 20 69 6e 74 20 entry */. int
20460 61 54 65 6d 70 52 65 67 5b 38 5d 3b 20 20 20 20 aTempReg[8];
20470 20 20 20 20 2f 2a 20 48 6f 6c 64 69 6e 67 20 61 /* Holding a
20480 72 65 61 20 66 6f 72 20 74 65 6d 70 6f 72 61 72 rea for temporar
20490 79 20 72 65 67 69 73 74 65 72 73 20 2a 2f 0a 20 y registers */.
204a0 20 54 6f 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 Token sNameToke
204b0 6e 3b 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 n; /* Toke
204c0 6e 20 77 69 74 68 20 75 6e 71 75 61 6c 69 66 69 n with unqualifi
204d0 65 64 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 ed schema object
204e0 20 6e 61 6d 65 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a name */.. /***
204f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20500 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20510 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20520 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20530 2a 2a 2a 2a 2a 0a 20 20 2a 2a 20 41 62 6f 76 65 *****. ** Above
20540 20 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 65 74 is constant bet
20550 77 65 65 6e 20 72 65 63 75 72 73 69 6f 6e 73 2e ween recursions.
20560 20 20 42 65 6c 6f 77 20 69 73 20 72 65 73 65 74 Below is reset
20570 20 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 before and afte
20580 72 0a 20 20 2a 2a 20 65 61 63 68 20 72 65 63 75 r. ** each recu
20590 72 73 69 6f 6e 2e 20 20 54 68 65 20 62 6f 75 6e rsion. The boun
205a0 64 61 72 79 20 62 65 74 77 65 65 6e 20 74 68 65 dary between the
205b0 73 65 20 74 77 6f 20 72 65 67 69 6f 6e 73 20 69 se two regions i
205c0 73 20 64 65 74 65 72 6d 69 6e 65 64 0a 20 20 2a s determined. *
205d0 2a 20 75 73 69 6e 67 20 6f 66 66 73 65 74 6f 66 * using offsetof
205e0 28 50 61 72 73 65 2c 73 4c 61 73 74 54 6f 6b 65 (Parse,sLastToke
205f0 6e 29 20 73 6f 20 74 68 65 20 73 4c 61 73 74 54 n) so the sLastT
20600 6f 6b 65 6e 20 66 69 65 6c 64 20 6d 75 73 74 20 oken field must
20610 62 65 20 74 68 65 0a 20 20 2a 2a 20 66 69 72 73 be the. ** firs
20620 74 20 66 69 65 6c 64 20 69 6e 20 74 68 65 20 72 t field in the r
20630 65 63 75 72 73 69 76 65 20 72 65 67 69 6f 6e 2e ecursive region.
20640 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a . *************
20650 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20660 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20670 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
20680 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 ***********/..
20690 54 6f 6b 65 6e 20 73 4c 61 73 74 54 6f 6b 65 6e Token sLastToken
206a0 3b 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6c ; /* The l
206b0 61 73 74 20 74 6f 6b 65 6e 20 70 61 72 73 65 64 ast token parsed
206c0 20 2a 2f 0a 20 20 79 6e 56 61 72 20 6e 56 61 72 */. ynVar nVar
206d0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
206e0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 27 3f 27 /* Number of '?'
206f0 20 76 61 72 69 61 62 6c 65 73 20 73 65 65 6e 20 variables seen
20700 69 6e 20 74 68 65 20 53 51 4c 20 73 6f 20 66 61 in the SQL so fa
20710 72 20 2a 2f 0a 20 20 75 38 20 69 50 6b 53 6f 72 r */. u8 iPkSor
20720 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 tOrder;
20730 20 2f 2a 20 41 53 43 20 6f 72 20 44 45 53 43 20 /* ASC or DESC
20740 66 6f 72 20 49 4e 54 45 47 45 52 20 50 52 49 4d for INTEGER PRIM
20750 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 75 38 20 ARY KEY */. u8
20760 65 78 70 6c 61 69 6e 3b 20 20 20 20 20 20 20 20 explain;
20770 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
20780 66 20 74 68 65 20 45 58 50 4c 41 49 4e 20 66 6c f the EXPLAIN fl
20790 61 67 20 69 73 20 66 6f 75 6e 64 20 6f 6e 20 74 ag is found on t
207a0 68 65 20 71 75 65 72 79 20 2a 2f 0a 23 69 66 6e he query */.#ifn
207b0 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
207c0 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 75 VIRTUALTABLE. u
207d0 38 20 64 65 63 6c 61 72 65 56 74 61 62 3b 20 20 8 declareVtab;
207e0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
207f0 20 69 66 20 69 6e 73 69 64 65 20 73 71 6c 69 74 if inside sqlit
20800 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 28 e3_declare_vtab(
20810 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 74 61 62 ) */. int nVtab
20820 4c 6f 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 Lock;
20830 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 76 69 /* Number of vi
20840 72 74 75 61 6c 20 74 61 62 6c 65 73 20 74 6f 20 rtual tables to
20850 6c 6f 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 lock */.#endif.
20860 20 69 6e 74 20 6e 48 65 69 67 68 74 3b 20 20 20 int nHeight;
20870 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 78 /* Ex
20880 70 72 65 73 73 69 6f 6e 20 74 72 65 65 20 68 65 pression tree he
20890 69 67 68 74 20 6f 66 20 63 75 72 72 65 6e 74 20 ight of current
208a0 73 75 62 2d 73 65 6c 65 63 74 20 2a 2f 0a 23 69 sub-select */.#i
208b0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
208c0 54 5f 45 58 50 4c 41 49 4e 0a 20 20 69 6e 74 20 T_EXPLAIN. int
208d0 69 53 65 6c 65 63 74 49 64 3b 20 20 20 20 20 20 iSelectId;
208e0 20 20 20 20 20 20 2f 2a 20 49 44 20 6f 66 20 63 /* ID of c
208f0 75 72 72 65 6e 74 20 73 65 6c 65 63 74 20 66 6f urrent select fo
20900 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 70 75 74 r EXPLAIN output
20910 20 2a 2f 0a 20 20 69 6e 74 20 69 4e 65 78 74 53 */. int iNextS
20920 65 6c 65 63 74 49 64 3b 20 20 20 20 20 20 20 20 electId;
20930 2f 2a 20 4e 65 78 74 20 61 76 61 69 6c 61 62 6c /* Next availabl
20940 65 20 73 65 6c 65 63 74 20 49 44 20 66 6f 72 20 e select ID for
20950 45 58 50 4c 41 49 4e 20 6f 75 74 70 75 74 20 2a EXPLAIN output *
20960 2f 0a 23 65 6e 64 69 66 0a 20 20 56 4c 69 73 74 /.#endif. VList
20970 20 2a 70 56 4c 69 73 74 3b 20 20 20 20 20 20 20 *pVList;
20980 20 20 20 20 20 2f 2a 20 4d 61 70 70 69 6e 67 20 /* Mapping
20990 62 65 74 77 65 65 6e 20 76 61 72 69 61 62 6c 65 between variable
209a0 20 6e 61 6d 65 73 20 61 6e 64 20 6e 75 6d 62 65 names and numbe
209b0 72 73 20 2a 2f 0a 20 20 56 64 62 65 20 2a 70 52 rs */. Vdbe *pR
209c0 65 70 72 65 70 61 72 65 3b 20 20 20 20 20 20 20 eprepare;
209d0 20 20 2f 2a 20 56 4d 20 62 65 69 6e 67 20 72 65 /* VM being re
209e0 70 72 65 70 61 72 65 64 20 28 73 71 6c 69 74 65 prepared (sqlite
209f0 33 52 65 70 72 65 70 61 72 65 28 29 29 20 2a 2f 3Reprepare()) */
20a00 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
20a10 54 61 69 6c 3b 20 20 20 20 20 20 20 20 2f 2a 20 Tail; /*
20a20 41 6c 6c 20 53 51 4c 20 74 65 78 74 20 70 61 73 All SQL text pas
20a30 74 20 74 68 65 20 6c 61 73 74 20 73 65 6d 69 63 t the last semic
20a40 6f 6c 6f 6e 20 70 61 72 73 65 64 20 2a 2f 0a 20 olon parsed */.
20a50 20 54 61 62 6c 65 20 2a 70 4e 65 77 54 61 62 6c Table *pNewTabl
20a60 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 e; /* A
20a70 74 61 62 6c 65 20 62 65 69 6e 67 20 63 6f 6e 73 table being cons
20a80 74 72 75 63 74 65 64 20 62 79 20 43 52 45 41 54 tructed by CREAT
20a90 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 54 72 69 E TABLE */. Tri
20aa0 67 67 65 72 20 2a 70 4e 65 77 54 72 69 67 67 65 gger *pNewTrigge
20ab0 72 3b 20 20 20 20 20 2f 2a 20 54 72 69 67 67 65 r; /* Trigge
20ac0 72 20 75 6e 64 65 72 20 63 6f 6e 73 74 72 75 63 r under construc
20ad0 74 20 62 79 20 61 20 43 52 45 41 54 45 20 54 52 t by a CREATE TR
20ae0 49 47 47 45 52 20 2a 2f 0a 20 20 63 6f 6e 73 74 IGGER */. const
20af0 20 63 68 61 72 20 2a 7a 41 75 74 68 43 6f 6e 74 char *zAuthCont
20b00 65 78 74 3b 20 2f 2a 20 54 68 65 20 36 74 68 20 ext; /* The 6th
20b10 70 61 72 61 6d 65 74 65 72 20 74 6f 20 64 62 2d parameter to db-
20b20 3e 78 41 75 74 68 20 63 61 6c 6c 62 61 63 6b 73 >xAuth callbacks
20b30 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
20b40 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
20b50 41 42 4c 45 0a 20 20 54 6f 6b 65 6e 20 73 41 72 ABLE. Token sAr
20b60 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
20b70 20 2f 2a 20 43 6f 6d 70 6c 65 74 65 20 74 65 78 /* Complete tex
20b80 74 20 6f 66 20 61 20 6d 6f 64 75 6c 65 20 61 72 t of a module ar
20b90 67 75 6d 65 6e 74 20 2a 2f 0a 20 20 54 61 62 6c gument */. Tabl
20ba0 65 20 2a 2a 61 70 56 74 61 62 4c 6f 63 6b 3b 20 e **apVtabLock;
20bb0 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 /* Pointer
20bc0 20 74 6f 20 76 69 72 74 75 61 6c 20 74 61 62 6c to virtual tabl
20bd0 65 73 20 6e 65 65 64 69 6e 67 20 6c 6f 63 6b 69 es needing locki
20be0 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 54 ng */.#endif. T
20bf0 61 62 6c 65 20 2a 70 5a 6f 6d 62 69 65 54 61 62 able *pZombieTab
20c00 3b 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 ; /* List
20c10 20 6f 66 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 of Table object
20c20 73 20 74 6f 20 64 65 6c 65 74 65 20 61 66 74 65 s to delete afte
20c30 72 20 63 6f 64 65 20 67 65 6e 20 2a 2f 0a 20 20 r code gen */.
20c40 54 72 69 67 67 65 72 50 72 67 20 2a 70 54 72 69 TriggerPrg *pTri
20c50 67 67 65 72 50 72 67 3b 20 20 2f 2a 20 4c 69 6e ggerPrg; /* Lin
20c60 6b 65 64 20 6c 69 73 74 20 6f 66 20 63 6f 64 65 ked list of code
20c70 64 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 20 20 d triggers */.
20c80 57 69 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 With *pWith;
20c90 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 /* Cur
20ca0 72 65 6e 74 20 57 49 54 48 20 63 6c 61 75 73 65 rent WITH clause
20cb0 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a 20 20 57 , or NULL */. W
20cc0 69 74 68 20 2a 70 57 69 74 68 54 6f 46 72 65 65 ith *pWithToFree
20cd0 3b 20 20 20 20 20 20 20 20 2f 2a 20 46 72 65 65 ; /* Free
20ce0 20 74 68 69 73 20 57 49 54 48 20 6f 62 6a 65 63 this WITH objec
20cf0 74 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20 t at the end of
20d00 74 68 65 20 70 61 72 73 65 20 2a 2f 0a 7d 3b 0a the parse */.};.
20d10 0a 2f 2a 0a 2a 2a 20 53 69 7a 65 73 20 61 6e 64 ./*.** Sizes and
20d20 20 70 6f 69 6e 74 65 72 73 20 6f 66 20 76 61 72 pointers of var
20d30 69 6f 75 73 20 70 61 72 74 73 20 6f 66 20 74 68 ious parts of th
20d40 65 20 50 61 72 73 65 20 6f 62 6a 65 63 74 2e 0a e Parse object..
20d50 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 52 53 45 */.#define PARSE
20d60 5f 48 44 52 5f 53 5a 20 6f 66 66 73 65 74 6f 66 _HDR_SZ offsetof
20d70 28 50 61 72 73 65 2c 61 43 6f 6c 43 61 63 68 65 (Parse,aColCache
20d80 29 20 2f 2a 20 52 65 63 75 72 73 69 76 65 20 70 ) /* Recursive p
20d90 61 72 74 20 77 2f 6f 20 61 43 6f 6c 43 61 63 68 art w/o aColCach
20da0 65 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 52 53 e*/.#define PARS
20db0 45 5f 52 45 43 55 52 53 45 5f 53 5a 20 6f 66 66 E_RECURSE_SZ off
20dc0 73 65 74 6f 66 28 50 61 72 73 65 2c 73 4c 61 73 setof(Parse,sLas
20dd0 74 54 6f 6b 65 6e 29 20 20 20 20 2f 2a 20 52 65 tToken) /* Re
20de0 63 75 72 73 69 76 65 20 70 61 72 74 20 2a 2f 0a cursive part */.
20df0 23 64 65 66 69 6e 65 20 50 41 52 53 45 5f 54 41 #define PARSE_TA
20e00 49 4c 5f 53 5a 20 28 73 69 7a 65 6f 66 28 50 61 IL_SZ (sizeof(Pa
20e10 72 73 65 29 2d 50 41 52 53 45 5f 52 45 43 55 52 rse)-PARSE_RECUR
20e20 53 45 5f 53 5a 29 20 2f 2a 20 4e 6f 6e 2d 72 65 SE_SZ) /* Non-re
20e30 63 75 72 73 69 76 65 20 70 61 72 74 20 2a 2f 0a cursive part */.
20e40 23 64 65 66 69 6e 65 20 50 41 52 53 45 5f 54 41 #define PARSE_TA
20e50 49 4c 28 58 29 20 28 28 28 63 68 61 72 2a 29 28 IL(X) (((char*)(
20e60 58 29 29 2b 50 41 52 53 45 5f 52 45 43 55 52 53 X))+PARSE_RECURS
20e70 45 5f 53 5a 29 20 20 2f 2a 20 50 6f 69 6e 74 65 E_SZ) /* Pointe
20e80 72 20 74 6f 20 74 61 69 6c 20 2a 2f 0a 0a 2f 2a r to tail */../*
20e90 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 .** Return true
20ea0 69 66 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 73 if currently ins
20eb0 69 64 65 20 61 6e 20 73 71 6c 69 74 65 33 5f 64 ide an sqlite3_d
20ec0 65 63 6c 61 72 65 5f 76 74 61 62 28 29 20 63 61 eclare_vtab() ca
20ed0 6c 6c 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 ll..*/.#ifdef SQ
20ee0 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
20ef0 4c 54 41 42 4c 45 0a 20 20 23 64 65 66 69 6e 65 LTABLE. #define
20f00 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 IN_DECLARE_VTAB
20f10 20 30 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 0.#else. #defi
20f20 6e 65 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 ne IN_DECLARE_VT
20f30 41 42 20 28 70 50 61 72 73 65 2d 3e 64 65 63 6c AB (pParse->decl
20f40 61 72 65 56 74 61 62 29 0a 23 65 6e 64 69 66 0a areVtab).#endif.
20f50 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
20f60 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ce of the follow
20f70 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 61 ing structure ca
20f80 6e 20 62 65 20 64 65 63 6c 61 72 65 64 20 6f 6e n be declared on
20f90 20 61 20 73 74 61 63 6b 20 61 6e 64 20 75 73 65 a stack and use
20fa0 64 0a 2a 2a 20 74 6f 20 73 61 76 65 20 74 68 65 d.** to save the
20fb0 20 50 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 Parse.zAuthCont
20fc0 65 78 74 20 76 61 6c 75 65 20 73 6f 20 74 68 61 ext value so tha
20fd0 74 20 69 74 20 63 61 6e 20 62 65 20 72 65 73 74 t it can be rest
20fe0 6f 72 65 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 73 ored later..*/.s
20ff0 74 72 75 63 74 20 41 75 74 68 43 6f 6e 74 65 78 truct AuthContex
21000 74 20 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 t {. const char
21010 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 *zAuthContext;
21020 20 20 2f 2a 20 50 75 74 20 73 61 76 65 64 20 50 /* Put saved P
21030 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 arse.zAuthContex
21040 74 20 68 65 72 65 20 2a 2f 0a 20 20 50 61 72 73 t here */. Pars
21050 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 e *pParse;
21060 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 50 /* The P
21070 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 2a arse structure *
21080 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 66 /.};../*.** Bitf
21090 69 65 6c 64 20 66 6c 61 67 73 20 66 6f 72 20 50 ield flags for P
210a0 35 20 76 61 6c 75 65 20 69 6e 20 76 61 72 69 6f 5 value in vario
210b0 75 73 20 6f 70 63 6f 64 65 73 2e 0a 2a 2a 0a 2a us opcodes..**.*
210c0 2a 20 56 61 6c 75 65 20 63 6f 6e 73 74 72 61 69 * Value constrai
210d0 6e 74 73 20 28 65 6e 66 6f 72 63 65 64 20 76 69 nts (enforced vi
210e0 61 20 61 73 73 65 72 74 28 29 29 3a 0a 2a 2a 20 a assert()):.**
210f0 20 20 20 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 48 OPFLAG_LENGTH
21100 41 52 47 20 20 20 20 3d 3d 20 53 51 4c 49 54 45 ARG == SQLITE
21110 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 0a 2a 2a 20 _FUNC_LENGTH.**
21120 20 20 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 OPFLAG_TYPEOF
21130 41 52 47 20 20 20 20 3d 3d 20 53 51 4c 49 54 45 ARG == SQLITE
21140 5f 46 55 4e 43 5f 54 59 50 45 4f 46 0a 2a 2a 20 _FUNC_TYPEOF.**
21150 20 20 20 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 OPFLAG_BULKCS
21160 52 20 20 20 20 20 20 3d 3d 20 42 54 52 45 45 5f R == BTREE_
21170 42 55 4c 4b 4c 4f 41 44 0a 2a 2a 20 20 20 20 4f BULKLOAD.** O
21180 50 46 4c 41 47 5f 53 45 45 4b 45 51 20 20 20 20 PFLAG_SEEKEQ
21190 20 20 20 3d 3d 20 42 54 52 45 45 5f 53 45 45 4b == BTREE_SEEK
211a0 5f 45 51 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 47 _EQ.** OPFLAG
211b0 5f 46 4f 52 44 45 4c 45 54 45 20 20 20 20 3d 3d _FORDELETE ==
211c0 20 42 54 52 45 45 5f 46 4f 52 44 45 4c 45 54 45 BTREE_FORDELETE
211d0 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 47 5f 53 41 .** OPFLAG_SA
211e0 56 45 50 4f 53 49 54 49 4f 4e 20 3d 3d 20 42 54 VEPOSITION == BT
211f0 52 45 45 5f 53 41 56 45 50 4f 53 49 54 49 4f 4e REE_SAVEPOSITION
21200 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 47 5f 41 55 .** OPFLAG_AU
21210 58 44 45 4c 45 54 45 20 20 20 20 3d 3d 20 42 54 XDELETE == BT
21220 52 45 45 5f 41 55 58 44 45 4c 45 54 45 0a 2a 2f REE_AUXDELETE.*/
21230 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
21240 4e 43 48 41 4e 47 45 20 20 20 20 20 20 20 30 78 NCHANGE 0x
21250 30 31 20 20 20 20 2f 2a 20 4f 50 5f 49 6e 73 65 01 /* OP_Inse
21260 72 74 3a 20 53 65 74 20 74 6f 20 75 70 64 61 74 rt: Set to updat
21270 65 20 64 62 2d 3e 6e 43 68 61 6e 67 65 20 2a 2f e db->nChange */
21280 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
21290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
212a0 20 20 20 20 20 20 2f 2a 20 41 6c 73 6f 20 75 73 /* Also us
212b0 65 64 20 69 6e 20 50 32 20 28 6e 6f 74 20 50 35 ed in P2 (not P5
212c0 29 20 6f 66 20 4f 50 5f 44 65 6c 65 74 65 20 2a ) of OP_Delete *
212d0 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
212e0 5f 45 50 48 45 4d 20 20 20 20 20 20 20 20 20 30 _EPHEM 0
212f0 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c x01 /* OP_Col
21300 75 6d 6e 3a 20 45 70 68 65 6d 65 72 61 6c 20 6f umn: Ephemeral o
21310 75 74 70 75 74 20 69 73 20 6f 6b 20 2a 2f 0a 23 utput is ok */.#
21320 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4c 41 define OPFLAG_LA
21330 53 54 52 4f 57 49 44 20 20 20 20 20 30 78 32 30 STROWID 0x20
21340 20 20 20 20 2f 2a 20 53 65 74 20 74 6f 20 75 70 /* Set to up
21350 64 61 74 65 20 64 62 2d 3e 6c 61 73 74 52 6f 77 date db->lastRow
21360 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 id */.#define OP
21370 46 4c 41 47 5f 49 53 55 50 44 41 54 45 20 20 20 FLAG_ISUPDATE
21380 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 54 68 0x04 /* Th
21390 69 73 20 4f 50 5f 49 6e 73 65 72 74 20 69 73 20 is OP_Insert is
213a0 61 6e 20 73 71 6c 20 55 50 44 41 54 45 20 2a 2f an sql UPDATE */
213b0 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
213c0 41 50 50 45 4e 44 20 20 20 20 20 20 20 20 30 78 APPEND 0x
213d0 30 38 20 20 20 20 2f 2a 20 54 68 69 73 20 69 73 08 /* This is
213e0 20 6c 69 6b 65 6c 79 20 74 6f 20 62 65 20 61 6e likely to be an
213f0 20 61 70 70 65 6e 64 20 2a 2f 0a 23 64 65 66 69 append */.#defi
21400 6e 65 20 4f 50 46 4c 41 47 5f 55 53 45 53 45 45 ne OPFLAG_USESEE
21410 4b 52 45 53 55 4c 54 20 30 78 31 30 20 20 20 20 KRESULT 0x10
21420 2f 2a 20 54 72 79 20 74 6f 20 61 76 6f 69 64 20 /* Try to avoid
21430 61 20 73 65 65 6b 20 69 6e 20 42 74 72 65 65 49 a seek in BtreeI
21440 6e 73 65 72 74 28 29 20 2a 2f 0a 23 64 65 66 69 nsert() */.#defi
21450 6e 65 20 4f 50 46 4c 41 47 5f 49 53 4e 4f 4f 50 ne OPFLAG_ISNOOP
21460 20 20 20 20 20 20 20 20 30 78 34 30 20 20 20 20 0x40
21470 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 20 64 6f 65 /* OP_Delete doe
21480 73 20 70 72 65 2d 75 70 64 61 74 65 2d 68 6f 6f s pre-update-hoo
21490 6b 20 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e k only */.#defin
214a0 65 20 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 e OPFLAG_LENGTHA
214b0 52 47 20 20 20 20 20 30 78 34 30 20 20 20 20 2f RG 0x40 /
214c0 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 6e 6c 79 * OP_Column only
214d0 20 75 73 65 64 20 66 6f 72 20 6c 65 6e 67 74 68 used for length
214e0 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 () */.#define OP
214f0 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 20 20 FLAG_TYPEOFARG
21500 20 20 20 30 78 38 30 20 20 20 20 2f 2a 20 4f 50 0x80 /* OP
21510 5f 43 6f 6c 75 6d 6e 20 6f 6e 6c 79 20 75 73 65 _Column only use
21520 64 20 66 6f 72 20 74 79 70 65 6f 66 28 29 20 2a d for typeof() *
21530 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
21540 5f 42 55 4c 4b 43 53 52 20 20 20 20 20 20 20 30 _BULKCSR 0
21550 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 4f 70 65 x01 /* OP_Ope
21560 6e 2a 2a 20 75 73 65 64 20 74 6f 20 6f 70 65 6e n** used to open
21570 20 62 75 6c 6b 20 63 75 72 73 6f 72 20 2a 2f 0a bulk cursor */.
21580 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 53 #define OPFLAG_S
21590 45 45 4b 45 51 20 20 20 20 20 20 20 20 30 78 30 EEKEQ 0x0
215a0 32 20 20 20 20 2f 2a 20 4f 50 5f 4f 70 65 6e 2a 2 /* OP_Open*
215b0 2a 20 63 75 72 73 6f 72 20 75 73 65 73 20 45 51 * cursor uses EQ
215c0 20 73 65 65 6b 20 6f 6e 6c 79 20 2a 2f 0a 23 64 seek only */.#d
215d0 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 46 4f 52 efine OPFLAG_FOR
215e0 44 45 4c 45 54 45 20 20 20 20 20 30 78 30 38 20 DELETE 0x08
215f0 20 20 20 2f 2a 20 4f 50 5f 4f 70 65 6e 20 73 68 /* OP_Open sh
21600 6f 75 6c 64 20 75 73 65 20 42 54 52 45 45 5f 46 ould use BTREE_F
21610 4f 52 44 45 4c 45 54 45 20 2a 2f 0a 23 64 65 66 ORDELETE */.#def
21620 69 6e 65 20 4f 50 46 4c 41 47 5f 50 32 49 53 52 ine OPFLAG_P2ISR
21630 45 47 20 20 20 20 20 20 20 30 78 31 30 20 20 20 EG 0x10
21640 20 2f 2a 20 50 32 20 74 6f 20 4f 50 5f 4f 70 65 /* P2 to OP_Ope
21650 6e 2a 2a 20 69 73 20 61 20 72 65 67 69 73 74 65 n** is a registe
21660 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 23 64 65 66 r number */.#def
21670 69 6e 65 20 4f 50 46 4c 41 47 5f 50 45 52 4d 55 ine OPFLAG_PERMU
21680 54 45 20 20 20 20 20 20 20 30 78 30 31 20 20 20 TE 0x01
21690 20 2f 2a 20 4f 50 5f 43 6f 6d 70 61 72 65 3a 20 /* OP_Compare:
216a0 75 73 65 20 74 68 65 20 70 65 72 6d 75 74 61 74 use the permutat
216b0 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ion */.#define O
216c0 50 46 4c 41 47 5f 53 41 56 45 50 4f 53 49 54 49 PFLAG_SAVEPOSITI
216d0 4f 4e 20 20 30 78 30 32 20 20 20 20 2f 2a 20 4f ON 0x02 /* O
216e0 50 5f 44 65 6c 65 74 65 2f 49 6e 73 65 72 74 3a P_Delete/Insert:
216f0 20 73 61 76 65 20 63 75 72 73 6f 72 20 70 6f 73 save cursor pos
21700 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
21710 41 47 5f 41 55 58 44 45 4c 45 54 45 20 20 20 20 AG_AUXDELETE
21720 20 30 78 30 34 20 20 20 20 2f 2a 20 4f 50 5f 44 0x04 /* OP_D
21730 65 6c 65 74 65 3a 20 69 6e 64 65 78 20 69 6e 20 elete: index in
21740 61 20 44 45 4c 45 54 45 20 6f 70 20 2a 2f 0a 23 a DELETE op */.#
21750 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 4f define OPFLAG_NO
21760 43 48 4e 47 5f 4d 41 47 49 43 20 20 30 78 36 64 CHNG_MAGIC 0x6d
21770 20 20 20 20 2f 2a 20 4f 50 5f 4d 61 6b 65 52 65 /* OP_MakeRe
21780 63 6f 72 64 3a 20 73 65 72 69 61 6c 74 79 70 65 cord: serialtype
21790 20 31 30 20 69 73 20 6f 6b 20 2a 2f 0a 0a 2f 2a 10 is ok */../*
217a0 0a 20 2a 20 45 61 63 68 20 74 72 69 67 67 65 72 . * Each trigger
217b0 20 70 72 65 73 65 6e 74 20 69 6e 20 74 68 65 20 present in the
217c0 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 database schema
217d0 69 73 20 73 74 6f 72 65 64 20 61 73 20 61 6e 20 is stored as an
217e0 69 6e 73 74 61 6e 63 65 20 6f 66 0a 20 2a 20 73 instance of. * s
217f0 74 72 75 63 74 20 54 72 69 67 67 65 72 2e 0a 20 truct Trigger..
21800 2a 0a 20 2a 20 50 6f 69 6e 74 65 72 73 20 74 6f *. * Pointers to
21810 20 69 6e 73 74 61 6e 63 65 73 20 6f 66 20 73 74 instances of st
21820 72 75 63 74 20 54 72 69 67 67 65 72 20 61 72 65 ruct Trigger are
21830 20 73 74 6f 72 65 64 20 69 6e 20 74 77 6f 20 77 stored in two w
21840 61 79 73 2e 0a 20 2a 20 31 2e 20 49 6e 20 74 68 ays.. * 1. In th
21850 65 20 22 74 72 69 67 48 61 73 68 22 20 68 61 73 e "trigHash" has
21860 68 20 74 61 62 6c 65 20 28 70 61 72 74 20 6f 66 h table (part of
21870 20 74 68 65 20 73 71 6c 69 74 65 33 2a 20 74 68 the sqlite3* th
21880 61 74 20 72 65 70 72 65 73 65 6e 74 73 20 74 68 at represents th
21890 65 0a 20 2a 20 20 20 20 64 61 74 61 62 61 73 65 e. * database
218a0 29 2e 20 54 68 69 73 20 61 6c 6c 6f 77 73 20 54 ). This allows T
218b0 72 69 67 67 65 72 20 73 74 72 75 63 74 75 72 65 rigger structure
218c0 73 20 74 6f 20 62 65 20 72 65 74 72 69 65 76 65 s to be retrieve
218d0 64 20 62 79 20 6e 61 6d 65 2e 0a 20 2a 20 32 2e d by name.. * 2.
218e0 20 41 6c 6c 20 74 72 69 67 67 65 72 73 20 61 73 All triggers as
218f0 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 61 20 sociated with a
21900 73 69 6e 67 6c 65 20 74 61 62 6c 65 20 66 6f 72 single table for
21910 6d 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 2c m a linked list,
21920 20 75 73 69 6e 67 20 74 68 65 0a 20 2a 20 20 20 using the. *
21930 20 70 4e 65 78 74 20 6d 65 6d 62 65 72 20 6f 66 pNext member of
21940 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 2e struct Trigger.
21950 20 41 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 A pointer to th
21960 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 e first element
21970 6f 66 20 74 68 65 0a 20 2a 20 20 20 20 6c 69 6e of the. * lin
21980 6b 65 64 20 6c 69 73 74 20 69 73 20 73 74 6f 72 ked list is stor
21990 65 64 20 61 73 20 74 68 65 20 22 70 54 72 69 67 ed as the "pTrig
219a0 67 65 72 22 20 6d 65 6d 62 65 72 20 6f 66 20 74 ger" member of t
219b0 68 65 20 61 73 73 6f 63 69 61 74 65 64 0a 20 2a he associated. *
219c0 20 20 20 20 73 74 72 75 63 74 20 54 61 62 6c 65 struct Table
219d0 2e 0a 20 2a 0a 20 2a 20 54 68 65 20 22 73 74 65 .. *. * The "ste
219e0 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 20 70 p_list" member p
219f0 6f 69 6e 74 73 20 74 6f 20 74 68 65 20 66 69 72 oints to the fir
21a00 73 74 20 65 6c 65 6d 65 6e 74 20 6f 66 20 61 20 st element of a
21a10 6c 69 6e 6b 65 64 20 6c 69 73 74 0a 20 2a 20 63 linked list. * c
21a20 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 53 51 ontaining the SQ
21a30 4c 20 73 74 61 74 65 6d 65 6e 74 73 20 73 70 65 L statements spe
21a40 63 69 66 69 65 64 20 61 73 20 74 68 65 20 74 72 cified as the tr
21a50 69 67 67 65 72 20 70 72 6f 67 72 61 6d 2e 0a 20 igger program..
21a60 2a 2f 0a 73 74 72 75 63 74 20 54 72 69 67 67 65 */.struct Trigge
21a70 72 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d r {. char *zNam
21a80 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a e; /*
21a90 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 The name of the
21aa0 20 74 72 69 67 67 65 72 20 20 20 20 20 20 20 20 trigger
21ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21ac0 2a 2f 0a 20 20 63 68 61 72 20 2a 74 61 62 6c 65 */. char *table
21ad0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
21ae0 54 68 65 20 74 61 62 6c 65 20 6f 72 20 76 69 65 The table or vie
21af0 77 20 74 6f 20 77 68 69 63 68 20 74 68 65 20 74 w to which the t
21b00 72 69 67 67 65 72 20 61 70 70 6c 69 65 73 20 2a rigger applies *
21b10 2f 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 /. u8 op;
21b20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
21b30 6e 65 20 6f 66 20 54 4b 5f 44 45 4c 45 54 45 2c ne of TK_DELETE,
21b40 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 TK_UPDATE, TK_I
21b50 4e 53 45 52 54 20 20 20 20 20 20 20 20 20 2a 2f NSERT */
21b60 0a 20 20 75 38 20 74 72 5f 74 6d 3b 20 20 20 20 . u8 tr_tm;
21b70 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e /* On
21b80 65 20 6f 66 20 54 52 49 47 47 45 52 5f 42 45 46 e of TRIGGER_BEF
21b90 4f 52 45 2c 20 54 52 49 47 47 45 52 5f 41 46 54 ORE, TRIGGER_AFT
21ba0 45 52 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 57 ER */. Expr *pW
21bb0 68 65 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 hen;
21bc0 2f 2a 20 54 68 65 20 57 48 45 4e 20 63 6c 61 75 /* The WHEN clau
21bd0 73 65 20 6f 66 20 74 68 65 20 65 78 70 72 65 73 se of the expres
21be0 73 69 6f 6e 20 28 6d 61 79 20 62 65 20 4e 55 4c sion (may be NUL
21bf0 4c 29 20 2a 2f 0a 20 20 49 64 4c 69 73 74 20 2a L) */. IdList *
21c00 70 43 6f 6c 75 6d 6e 73 3b 20 20 20 20 20 20 20 pColumns;
21c10 2f 2a 20 49 66 20 74 68 69 73 20 69 73 20 61 6e /* If this is an
21c20 20 55 50 44 41 54 45 20 4f 46 20 3c 63 6f 6c 75 UPDATE OF <colu
21c30 6d 6e 2d 6c 69 73 74 3e 20 74 72 69 67 67 65 72 mn-list> trigger
21c40 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
21c50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
21c60 68 65 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e he <column-list>
21c70 20 69 73 20 73 74 6f 72 65 64 20 68 65 72 65 20 is stored here
21c80 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 */. Schema *pSc
21c90 68 65 6d 61 3b 20 20 20 20 20 20 20 20 2f 2a 20 hema; /*
21ca0 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 6e Schema containin
21cb0 67 20 74 68 65 20 74 72 69 67 67 65 72 20 2a 2f g the trigger */
21cc0 0a 20 20 53 63 68 65 6d 61 20 2a 70 54 61 62 53 . Schema *pTabS
21cd0 63 68 65 6d 61 3b 20 20 20 20 20 2f 2a 20 53 63 chema; /* Sc
21ce0 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 6e 67 20 hema containing
21cf0 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 54 the table */. T
21d00 72 69 67 67 65 72 53 74 65 70 20 2a 73 74 65 70 riggerStep *step
21d10 5f 6c 69 73 74 3b 20 2f 2a 20 4c 69 6e 6b 20 6c _list; /* Link l
21d20 69 73 74 20 6f 66 20 74 72 69 67 67 65 72 20 70 ist of trigger p
21d30 72 6f 67 72 61 6d 20 73 74 65 70 73 20 20 20 20 rogram steps
21d40 20 20 20 20 20 20 20 20 20 2a 2f 0a 20 20 54 72 */. Tr
21d50 69 67 67 65 72 20 2a 70 4e 65 78 74 3b 20 20 20 igger *pNext;
21d60 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 74 72 /* Next tr
21d70 69 67 67 65 72 20 61 73 73 6f 63 69 61 74 65 64 igger associated
21d80 20 77 69 74 68 20 74 68 65 20 74 61 62 6c 65 20 with the table
21d90 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 74 */.};../*.** A t
21da0 72 69 67 67 65 72 20 69 73 20 65 69 74 68 65 72 rigger is either
21db0 20 61 20 42 45 46 4f 52 45 20 6f 72 20 61 6e 20 a BEFORE or an
21dc0 41 46 54 45 52 20 74 72 69 67 67 65 72 2e 20 20 AFTER trigger.
21dd0 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f The following co
21de0 6e 73 74 61 6e 74 73 0a 2a 2a 20 64 65 74 65 72 nstants.** deter
21df0 6d 69 6e 65 20 77 68 69 63 68 2e 0a 2a 2a 0a 2a mine which..**.*
21e00 2a 20 49 66 20 74 68 65 72 65 20 61 72 65 20 6d * If there are m
21e10 75 6c 74 69 70 6c 65 20 74 72 69 67 67 65 72 73 ultiple triggers
21e20 2c 20 79 6f 75 20 6d 69 67 68 74 20 6f 66 20 73 , you might of s
21e30 6f 6d 65 20 42 45 46 4f 52 45 20 61 6e 64 20 73 ome BEFORE and s
21e40 6f 6d 65 20 41 46 54 45 52 2e 0a 2a 2a 20 49 6e ome AFTER..** In
21e50 20 74 68 61 74 20 63 61 73 65 73 2c 20 74 68 65 that cases, the
21e60 20 63 6f 6e 73 74 61 6e 74 73 20 62 65 6c 6f 77 constants below
21e70 20 63 61 6e 20 62 65 20 4f 52 65 64 20 74 6f 67 can be ORed tog
21e80 65 74 68 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e ether..*/.#defin
21e90 65 20 54 52 49 47 47 45 52 5f 42 45 46 4f 52 45 e TRIGGER_BEFORE
21ea0 20 20 31 0a 23 64 65 66 69 6e 65 20 54 52 49 47 1.#define TRIG
21eb0 47 45 52 5f 41 46 54 45 52 20 20 20 32 0a 0a 2f GER_AFTER 2../
21ec0 2a 0a 20 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *. * An instance
21ed0 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 67 of struct Trigg
21ee0 65 72 53 74 65 70 20 69 73 20 75 73 65 64 20 74 erStep is used t
21ef0 6f 20 73 74 6f 72 65 20 61 20 73 69 6e 67 6c 65 o store a single
21f00 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 0a 20 SQL statement.
21f10 2a 20 74 68 61 74 20 69 73 20 61 20 70 61 72 74 * that is a part
21f20 20 6f 66 20 61 20 74 72 69 67 67 65 72 2d 70 72 of a trigger-pr
21f30 6f 67 72 61 6d 2e 0a 20 2a 0a 20 2a 20 49 6e 73 ogram.. *. * Ins
21f40 74 61 6e 63 65 73 20 6f 66 20 73 74 72 75 63 74 tances of struct
21f50 20 54 72 69 67 67 65 72 53 74 65 70 20 61 72 65 TriggerStep are
21f60 20 73 74 6f 72 65 64 20 69 6e 20 61 20 73 69 6e stored in a sin
21f70 67 6c 79 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 gly linked list
21f80 28 6c 69 6e 6b 65 64 0a 20 2a 20 75 73 69 6e 67 (linked. * using
21f90 20 74 68 65 20 22 70 4e 65 78 74 22 20 6d 65 6d the "pNext" mem
21fa0 62 65 72 29 20 72 65 66 65 72 65 6e 63 65 64 20 ber) referenced
21fb0 62 79 20 74 68 65 20 22 73 74 65 70 5f 6c 69 73 by the "step_lis
21fc0 74 22 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 t" member of the
21fd0 0a 20 2a 20 61 73 73 6f 63 69 61 74 65 64 20 73 . * associated s
21fe0 74 72 75 63 74 20 54 72 69 67 67 65 72 20 69 6e truct Trigger in
21ff0 73 74 61 6e 63 65 2e 20 54 68 65 20 66 69 72 73 stance. The firs
22000 74 20 65 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 t element of the
22010 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 69 73 0a linked list is.
22020 20 2a 20 74 68 65 20 66 69 72 73 74 20 73 74 65 * the first ste
22030 70 20 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 p of the trigger
22040 2d 70 72 6f 67 72 61 6d 2e 0a 20 2a 0a 20 2a 20 -program.. *. *
22050 54 68 65 20 22 6f 70 22 20 6d 65 6d 62 65 72 20 The "op" member
22060 69 6e 64 69 63 61 74 65 73 20 77 68 65 74 68 65 indicates whethe
22070 72 20 74 68 69 73 20 69 73 20 61 20 22 44 45 4c r this is a "DEL
22080 45 54 45 22 2c 20 22 49 4e 53 45 52 54 22 2c 20 ETE", "INSERT",
22090 22 55 50 44 41 54 45 22 20 6f 72 0a 20 2a 20 22 "UPDATE" or. * "
220a0 53 45 4c 45 43 54 22 20 73 74 61 74 65 6d 65 6e SELECT" statemen
220b0 74 2e 20 54 68 65 20 6d 65 61 6e 69 6e 67 73 20 t. The meanings
220c0 6f 66 20 74 68 65 20 6f 74 68 65 72 20 6d 65 6d of the other mem
220d0 62 65 72 73 20 69 73 20 64 65 74 65 72 6d 69 6e bers is determin
220e0 65 64 20 62 79 20 74 68 65 0a 20 2a 20 76 61 6c ed by the. * val
220f0 75 65 20 6f 66 20 22 6f 70 22 20 61 73 20 66 6f ue of "op" as fo
22100 6c 6c 6f 77 73 3a 0a 20 2a 0a 20 2a 20 28 6f 70 llows:. *. * (op
22110 20 3d 3d 20 54 4b 5f 49 4e 53 45 52 54 29 0a 20 == TK_INSERT).
22120 2a 20 6f 72 63 6f 6e 66 20 20 20 20 2d 3e 20 73 * orconf -> s
22130 74 6f 72 65 73 20 74 68 65 20 4f 4e 20 43 4f 4e tores the ON CON
22140 46 4c 49 43 54 20 61 6c 67 6f 72 69 74 68 6d 0a FLICT algorithm.
22150 20 2a 20 70 53 65 6c 65 63 74 20 20 20 2d 3e 20 * pSelect ->
22160 49 66 20 74 68 69 73 20 69 73 20 61 6e 20 49 4e If this is an IN
22170 53 45 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 53 45 SERT INTO ... SE
22180 4c 45 43 54 20 2e 2e 2e 20 73 74 61 74 65 6d 65 LECT ... stateme
22190 6e 74 2c 20 74 68 65 6e 0a 20 2a 20 20 20 20 20 nt, then. *
221a0 20 20 20 20 20 20 20 20 20 74 68 69 73 20 73 74 this st
221b0 6f 72 65 73 20 61 20 70 6f 69 6e 74 65 72 20 74 ores a pointer t
221c0 6f 20 74 68 65 20 53 45 4c 45 43 54 20 73 74 61 o the SELECT sta
221d0 74 65 6d 65 6e 74 2e 20 4f 74 68 65 72 77 69 73 tement. Otherwis
221e0 65 20 4e 55 4c 4c 2e 0a 20 2a 20 7a 54 61 72 67 e NULL.. * zTarg
221f0 65 74 20 20 20 2d 3e 20 44 65 71 75 6f 74 65 64 et -> Dequoted
22200 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 name of the tab
22210 6c 65 20 74 6f 20 69 6e 73 65 72 74 20 69 6e 74 le to insert int
22220 6f 2e 0a 20 2a 20 70 45 78 70 72 4c 69 73 74 20 o.. * pExprList
22230 2d 3e 20 49 66 20 74 68 69 73 20 69 73 20 61 6e -> If this is an
22240 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 2e 2e 2e INSERT INTO ...
22250 20 56 41 4c 55 45 53 20 2e 2e 2e 20 73 74 61 74 VALUES ... stat
22260 65 6d 65 6e 74 2c 20 74 68 65 6e 0a 20 2a 20 20 ement, then. *
22270 20 20 20 20 20 20 20 20 20 20 20 20 74 68 69 73 this
22280 20 73 74 6f 72 65 73 20 76 61 6c 75 65 73 20 74 stores values t
22290 6f 20 62 65 20 69 6e 73 65 72 74 65 64 2e 20 4f o be inserted. O
222a0 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
222b0 2a 20 70 49 64 4c 69 73 74 20 20 20 2d 3e 20 49 * pIdList -> I
222c0 66 20 74 68 69 73 20 69 73 20 61 6e 20 49 4e 53 f this is an INS
222d0 45 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 28 3c 63 ERT INTO ... (<c
222e0 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 3e 29 20 56 41 olumn-names>) VA
222f0 4c 55 45 53 20 2e 2e 2e 0a 20 2a 20 20 20 20 20 LUES .... *
22300 20 20 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 stateme
22310 6e 74 2c 20 74 68 65 6e 20 74 68 69 73 20 73 74 nt, then this st
22320 6f 72 65 73 20 74 68 65 20 63 6f 6c 75 6d 6e 2d ores the column-
22330 6e 61 6d 65 73 20 74 6f 20 62 65 0a 20 2a 20 20 names to be. *
22340 20 20 20 20 20 20 20 20 20 20 20 20 69 6e 73 65 inse
22350 72 74 65 64 20 69 6e 74 6f 2e 0a 20 2a 0a 20 2a rted into.. *. *
22360 20 28 6f 70 20 3d 3d 20 54 4b 5f 44 45 4c 45 54 (op == TK_DELET
22370 45 29 0a 20 2a 20 7a 54 61 72 67 65 74 20 20 20 E). * zTarget
22380 2d 3e 20 44 65 71 75 6f 74 65 64 20 6e 61 6d 65 -> Dequoted name
22390 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 74 6f of the table to
223a0 20 64 65 6c 65 74 65 20 66 72 6f 6d 2e 0a 20 2a delete from.. *
223b0 20 70 57 68 65 72 65 20 20 20 20 2d 3e 20 54 68 pWhere -> Th
223c0 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 6f e WHERE clause o
223d0 66 20 74 68 65 20 44 45 4c 45 54 45 20 73 74 61 f the DELETE sta
223e0 74 65 6d 65 6e 74 20 69 66 20 6f 6e 65 20 69 73 tement if one is
223f0 20 73 70 65 63 69 66 69 65 64 2e 0a 20 2a 20 20 specified.. *
22400 20 20 20 20 20 20 20 20 20 20 20 20 4f 74 68 65 Othe
22410 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a 0a 20 rwise NULL.. *.
22420 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 55 50 44 41 * (op == TK_UPDA
22430 54 45 29 0a 20 2a 20 7a 54 61 72 67 65 74 20 20 TE). * zTarget
22440 20 2d 3e 20 44 65 71 75 6f 74 65 64 20 6e 61 6d -> Dequoted nam
22450 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 74 e of the table t
22460 6f 20 75 70 64 61 74 65 2e 0a 20 2a 20 70 57 68 o update.. * pWh
22470 65 72 65 20 20 20 20 2d 3e 20 54 68 65 20 57 48 ere -> The WH
22480 45 52 45 20 63 6c 61 75 73 65 20 6f 66 20 74 68 ERE clause of th
22490 65 20 55 50 44 41 54 45 20 73 74 61 74 65 6d 65 e UPDATE stateme
224a0 6e 74 20 69 66 20 6f 6e 65 20 69 73 20 73 70 65 nt if one is spe
224b0 63 69 66 69 65 64 2e 0a 20 2a 20 20 20 20 20 20 cified.. *
224c0 20 20 20 20 20 20 20 20 4f 74 68 65 72 77 69 73 Otherwis
224d0 65 20 4e 55 4c 4c 2e 0a 20 2a 20 70 45 78 70 72 e NULL.. * pExpr
224e0 4c 69 73 74 20 2d 3e 20 41 20 6c 69 73 74 20 6f List -> A list o
224f0 66 20 74 68 65 20 63 6f 6c 75 6d 6e 73 20 74 6f f the columns to
22500 20 75 70 64 61 74 65 20 61 6e 64 20 74 68 65 20 update and the
22510 65 78 70 72 65 73 73 69 6f 6e 73 20 74 6f 20 75 expressions to u
22520 70 64 61 74 65 0a 20 2a 20 20 20 20 20 20 20 20 pdate. *
22530 20 20 20 20 20 20 74 68 65 6d 20 74 6f 2e 20 53 them to. S
22540 65 65 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 ee sqlite3Update
22550 28 29 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e () documentation
22560 20 6f 66 20 22 70 43 68 61 6e 67 65 73 22 0a 20 of "pChanges".
22570 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 * a
22580 72 67 75 6d 65 6e 74 2e 0a 20 2a 0a 20 2a 2f 0a rgument.. *. */.
22590 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 struct TriggerSt
225a0 65 70 20 7b 0a 20 20 75 38 20 6f 70 3b 20 20 20 ep {. u8 op;
225b0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
225c0 6e 65 20 6f 66 20 54 4b 5f 44 45 4c 45 54 45 2c ne of TK_DELETE,
225d0 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 TK_UPDATE, TK_I
225e0 4e 53 45 52 54 2c 20 54 4b 5f 53 45 4c 45 43 54 NSERT, TK_SELECT
225f0 20 2a 2f 0a 20 20 75 38 20 6f 72 63 6f 6e 66 3b */. u8 orconf;
22600 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 /* OE
22610 5f 52 6f 6c 6c 62 61 63 6b 20 65 74 63 2e 20 2a _Rollback etc. *
22620 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 /. Trigger *pTr
22630 69 67 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ig; /* The
22640 74 72 69 67 67 65 72 20 74 68 61 74 20 74 68 69 trigger that thi
22650 73 20 73 74 65 70 20 69 73 20 61 20 70 61 72 74 s step is a part
22660 20 6f 66 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 of */. Select
22670 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a *pSelect; /*
22680 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e SELECT statemen
22690 74 20 6f 72 20 52 48 53 20 6f 66 20 49 4e 53 45 t or RHS of INSE
226a0 52 54 20 49 4e 54 4f 20 53 45 4c 45 43 54 20 2e RT INTO SELECT .
226b0 2e 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 .. */. char *zT
226c0 61 72 67 65 74 3b 20 20 20 20 20 20 20 2f 2a 20 arget; /*
226d0 54 61 72 67 65 74 20 74 61 62 6c 65 20 66 6f 72 Target table for
226e0 20 44 45 4c 45 54 45 2c 20 55 50 44 41 54 45 2c DELETE, UPDATE,
226f0 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 45 78 70 INSERT */. Exp
22700 72 20 2a 70 57 68 65 72 65 3b 20 20 20 20 20 20 r *pWhere;
22710 20 20 2f 2a 20 54 68 65 20 57 48 45 52 45 20 63 /* The WHERE c
22720 6c 61 75 73 65 20 66 6f 72 20 44 45 4c 45 54 45 lause for DELETE
22730 20 6f 72 20 55 50 44 41 54 45 20 73 74 65 70 73 or UPDATE steps
22740 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
22750 70 45 78 70 72 4c 69 73 74 3b 20 2f 2a 20 53 45 pExprList; /* SE
22760 54 20 63 6c 61 75 73 65 20 66 6f 72 20 55 50 44 T clause for UPD
22770 41 54 45 20 2a 2f 0a 20 20 49 64 4c 69 73 74 20 ATE */. IdList
22780 2a 70 49 64 4c 69 73 74 3b 20 20 20 20 20 2f 2a *pIdList; /*
22790 20 43 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 66 6f Column names fo
227a0 72 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 55 70 r INSERT */. Up
227b0 73 65 72 74 20 2a 70 55 70 73 65 72 74 3b 20 20 sert *pUpsert;
227c0 20 20 20 2f 2a 20 55 70 73 65 72 74 20 63 6c 61 /* Upsert cla
227d0 75 73 65 73 20 6f 6e 20 61 6e 20 49 4e 53 45 52 uses on an INSER
227e0 54 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 53 70 T */. char *zSp
227f0 61 6e 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4f an; /* O
22800 72 69 67 69 6e 61 6c 20 53 51 4c 20 74 65 78 74 riginal SQL text
22810 20 6f 66 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 of this command
22820 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 */. TriggerSte
22830 70 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 p *pNext; /* Ne
22840 78 74 20 69 6e 20 74 68 65 20 6c 69 6e 6b 2d 6c xt in the link-l
22850 69 73 74 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 ist */. Trigger
22860 53 74 65 70 20 2a 70 4c 61 73 74 3b 20 20 2f 2a Step *pLast; /*
22870 20 4c 61 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e Last element in
22880 20 6c 69 6e 6b 2d 6c 69 73 74 2e 20 56 61 6c 69 link-list. Vali
22890 64 20 66 6f 72 20 31 73 74 20 65 6c 65 6d 20 6f d for 1st elem o
228a0 6e 6c 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a nly */.};../*.**
228b0 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 The following s
228c0 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e tructure contain
228d0 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 73 s information us
228e0 65 64 20 62 79 20 74 68 65 20 73 71 6c 69 74 65 ed by the sqlite
228f0 46 69 78 2e 2e 2e 0a 2a 2a 20 72 6f 75 74 69 6e Fix....** routin
22900 65 73 20 61 73 20 74 68 65 79 20 77 61 6c 6b 20 es as they walk
22910 74 68 65 20 70 61 72 73 65 20 74 72 65 65 20 74 the parse tree t
22920 6f 20 6d 61 6b 65 20 64 61 74 61 62 61 73 65 20 o make database
22930 72 65 66 65 72 65 6e 63 65 73 0a 2a 2a 20 65 78 references.** ex
22940 70 6c 69 63 69 74 2e 0a 2a 2f 0a 74 79 70 65 64 plicit..*/.typed
22950 65 66 20 73 74 72 75 63 74 20 44 62 46 69 78 65 ef struct DbFixe
22960 72 20 44 62 46 69 78 65 72 3b 0a 73 74 72 75 63 r DbFixer;.struc
22970 74 20 44 62 46 69 78 65 72 20 7b 0a 20 20 50 61 t DbFixer {. Pa
22980 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 rse *pParse;
22990 20 20 2f 2a 20 54 68 65 20 70 61 72 73 69 6e 67 /* The parsing
229a0 20 63 6f 6e 74 65 78 74 2e 20 20 45 72 72 6f 72 context. Error
229b0 20 6d 65 73 73 61 67 65 73 20 77 72 69 74 74 65 messages writte
229c0 6e 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 n here */. Sche
229d0 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
229e0 2f 2a 20 46 69 78 20 69 74 65 6d 73 20 74 6f 20 /* Fix items to
229f0 74 68 69 73 20 73 63 68 65 6d 61 20 2a 2f 0a 20 this schema */.
22a00 20 69 6e 74 20 62 56 61 72 4f 6e 6c 79 3b 20 20 int bVarOnly;
22a10 20 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 66 6f /* Check fo
22a20 72 20 76 61 72 69 61 62 6c 65 20 72 65 66 65 72 r variable refer
22a30 65 6e 63 65 73 20 6f 6e 6c 79 20 2a 2f 0a 20 20 ences only */.
22a40 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 3b const char *zDb;
22a50 20 20 20 20 2f 2a 20 4d 61 6b 65 20 73 75 72 65 /* Make sure
22a60 20 61 6c 6c 20 6f 62 6a 65 63 74 73 20 61 72 65 all objects are
22a70 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 74 68 contained in th
22a80 69 73 20 64 61 74 61 62 61 73 65 20 2a 2f 0a 20 is database */.
22a90 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 79 const char *zTy
22aa0 70 65 3b 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 pe; /* Type of
22ab0 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 20 2d 20 the container -
22ac0 75 73 65 64 20 66 6f 72 20 65 72 72 6f 72 20 6d used for error m
22ad0 65 73 73 61 67 65 73 20 2a 2f 0a 20 20 63 6f 6e essages */. con
22ae0 73 74 20 54 6f 6b 65 6e 20 2a 70 4e 61 6d 65 3b st Token *pName;
22af0 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 /* Name of the
22b00 63 6f 6e 74 61 69 6e 65 72 20 2d 20 75 73 65 64 container - used
22b10 20 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 for error messa
22b20 67 65 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ges */.};../*.**
22b30 20 41 6e 20 6f 62 6a 65 63 74 65 64 20 75 73 65 An objected use
22b40 64 20 74 6f 20 61 63 63 75 6d 75 6c 61 74 65 20 d to accumulate
22b50 74 68 65 20 74 65 78 74 20 6f 66 20 61 20 73 74 the text of a st
22b60 72 69 6e 67 20 77 68 65 72 65 20 77 65 0a 2a 2a ring where we.**
22b70 20 64 6f 20 6e 6f 74 20 6e 65 63 65 73 73 61 72 do not necessar
22b80 69 6c 79 20 6b 6e 6f 77 20 68 6f 77 20 62 69 67 ily know how big
22b90 20 74 68 65 20 73 74 72 69 6e 67 20 77 69 6c 6c the string will
22ba0 20 62 65 20 69 6e 20 74 68 65 20 65 6e 64 2e 0a be in the end..
22bb0 2a 2f 0a 73 74 72 75 63 74 20 53 74 72 41 63 63 */.struct StrAcc
22bc0 75 6d 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a um {. sqlite3 *
22bd0 64 62 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4f db; /* O
22be0 70 74 69 6f 6e 61 6c 20 64 61 74 61 62 61 73 65 ptional database
22bf0 20 66 6f 72 20 6c 6f 6f 6b 61 73 69 64 65 2e 20 for lookaside.
22c00 20 43 61 6e 20 62 65 20 4e 55 4c 4c 20 2a 2f 0a Can be NULL */.
22c10 20 20 63 68 61 72 20 2a 7a 54 65 78 74 3b 20 20 char *zText;
22c20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 73 74 /* The st
22c30 72 69 6e 67 20 63 6f 6c 6c 65 63 74 65 64 20 73 ring collected s
22c40 6f 20 66 61 72 20 2a 2f 0a 20 20 75 33 32 20 20 o far */. u32
22c50 6e 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 20 nAlloc;
22c60 2f 2a 20 41 6d 6f 75 6e 74 20 6f 66 20 73 70 61 /* Amount of spa
22c70 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 69 6e 20 ce allocated in
22c80 7a 54 65 78 74 20 2a 2f 0a 20 20 75 33 32 20 20 zText */. u32
22c90 6d 78 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 mxAlloc;
22ca0 2f 2a 20 4d 61 78 69 6d 75 6d 20 61 6c 6c 6f 77 /* Maximum allow
22cb0 65 64 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 ed allocation.
22cc0 30 20 66 6f 72 20 6e 6f 20 6d 61 6c 6c 6f 63 20 0 for no malloc
22cd0 75 73 61 67 65 20 2a 2f 0a 20 20 75 33 32 20 20 usage */. u32
22ce0 6e 43 68 61 72 3b 20 20 20 20 20 20 20 20 20 20 nChar;
22cf0 2f 2a 20 4c 65 6e 67 74 68 20 6f 66 20 74 68 65 /* Length of the
22d00 20 73 74 72 69 6e 67 20 73 6f 20 66 61 72 20 2a string so far *
22d10 2f 0a 20 20 75 38 20 20 20 61 63 63 45 72 72 6f /. u8 accErro
22d20 72 3b 20 20 20 20 20 20 20 2f 2a 20 53 54 52 41 r; /* STRA
22d30 43 43 55 4d 5f 4e 4f 4d 45 4d 20 6f 72 20 53 54 CCUM_NOMEM or ST
22d40 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 2a 2f RACCUM_TOOBIG */
22d50 0a 20 20 75 38 20 20 20 70 72 69 6e 74 66 46 6c . u8 printfFl
22d60 61 67 73 3b 20 20 20 20 2f 2a 20 53 51 4c 49 54 ags; /* SQLIT
22d70 45 5f 50 52 49 4e 54 46 20 66 6c 61 67 73 20 62 E_PRINTF flags b
22d80 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 23 64 65 66 69 elow */.};.#defi
22d90 6e 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 ne STRACCUM_NOME
22da0 4d 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 54 M 1.#define ST
22db0 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 20 32 RACCUM_TOOBIG 2
22dc0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
22dd0 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 4c 20 PRINTF_INTERNAL
22de0 30 78 30 31 20 20 2f 2a 20 49 6e 74 65 72 6e 61 0x01 /* Interna
22df0 6c 2d 75 73 65 2d 6f 6e 6c 79 20 63 6f 6e 76 65 l-use-only conve
22e00 72 74 65 72 73 20 61 6c 6c 6f 77 65 64 20 2a 2f rters allowed */
22e10 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
22e20 50 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 20 20 PRINTF_SQLFUNC
22e30 30 78 30 32 20 20 2f 2a 20 53 51 4c 20 66 75 6e 0x02 /* SQL fun
22e40 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 73 20 ction arguments
22e50 74 6f 20 56 58 50 72 69 6e 74 66 20 2a 2f 0a 23 to VXPrintf */.#
22e60 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 52 define SQLITE_PR
22e70 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 20 30 78 INTF_MALLOCED 0x
22e80 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 78 04 /* True if x
22e90 54 65 78 74 20 69 73 20 61 6c 6c 6f 63 61 74 65 Text is allocate
22ea0 64 20 73 70 61 63 65 20 2a 2f 0a 0a 23 64 65 66 d space */..#def
22eb0 69 6e 65 20 69 73 4d 61 6c 6c 6f 63 65 64 28 58 ine isMalloced(X
22ec0 29 20 20 28 28 28 58 29 2d 3e 70 72 69 6e 74 66 ) (((X)->printf
22ed0 46 6c 61 67 73 20 26 20 53 51 4c 49 54 45 5f 50 Flags & SQLITE_P
22ee0 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 29 21 RINTF_MALLOCED)!
22ef0 3d 30 29 0a 0a 0a 2f 2a 0a 2a 2a 20 41 20 70 6f =0).../*.** A po
22f00 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 inter to this st
22f10 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 20 ructure is used
22f20 74 6f 20 63 6f 6d 6d 75 6e 69 63 61 74 65 20 69 to communicate i
22f30 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 66 72 nformation.** fr
22f40 6f 6d 20 73 71 6c 69 74 65 33 49 6e 69 74 20 61 om sqlite3Init a
22f50 6e 64 20 4f 50 5f 50 61 72 73 65 53 63 68 65 6d nd OP_ParseSchem
22f60 61 20 69 6e 74 6f 20 74 68 65 20 73 71 6c 69 74 a into the sqlit
22f70 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b 2e 0a e3InitCallback..
22f80 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
22f90 74 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 t {. sqlite3 *d
22fa0 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 b; /* The
22fb0 20 64 61 74 61 62 61 73 65 20 62 65 69 6e 67 20 database being
22fc0 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 initialized */.
22fd0 20 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 67 char **pzErrMsg
22fe0 3b 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 ; /* Error me
22ff0 73 73 61 67 65 20 73 74 6f 72 65 64 20 68 65 72 ssage stored her
23000 65 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b 20 e */. int iDb;
23010 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 30 20 /* 0
23020 66 6f 72 20 6d 61 69 6e 20 64 61 74 61 62 61 73 for main databas
23030 65 2e 20 20 31 20 66 6f 72 20 54 45 4d 50 2c 20 e. 1 for TEMP,
23040 32 2e 2e 20 66 6f 72 20 41 54 54 41 43 48 65 64 2.. for ATTACHed
23050 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 20 20 */. int rc;
23060 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 73 /* Res
23070 75 6c 74 20 63 6f 64 65 20 73 74 6f 72 65 64 20 ult code stored
23080 68 65 72 65 20 2a 2f 0a 7d 20 49 6e 69 74 44 61 here */.} InitDa
23090 74 61 3b 0a 0a 2f 2a 0a 2a 2a 20 53 74 72 75 63 ta;../*.** Struc
230a0 74 75 72 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 ture containing
230b0 67 6c 6f 62 61 6c 20 63 6f 6e 66 69 67 75 72 61 global configura
230c0 74 69 6f 6e 20 64 61 74 61 20 66 6f 72 20 74 68 tion data for th
230d0 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 e SQLite library
230e0 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 74 72 ..**.** This str
230f0 75 63 74 75 72 65 20 61 6c 73 6f 20 63 6f 6e 74 ucture also cont
23100 61 69 6e 73 20 73 6f 6d 65 20 73 74 61 74 65 20 ains some state
23110 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a information..*/.
23120 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 43 6f struct Sqlite3Co
23130 6e 66 69 67 20 7b 0a 20 20 69 6e 74 20 62 4d 65 nfig {. int bMe
23140 6d 73 74 61 74 3b 20 20 20 20 20 20 20 20 20 20 mstat;
23150 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
23160 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 6d 65 6d ue to enable mem
23170 6f 72 79 20 73 74 61 74 75 73 20 2a 2f 0a 20 20 ory status */.
23180 69 6e 74 20 62 43 6f 72 65 4d 75 74 65 78 3b 20 int bCoreMutex;
23190 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
231a0 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 /* True to ena
231b0 62 6c 65 20 63 6f 72 65 20 6d 75 74 65 78 69 6e ble core mutexin
231c0 67 20 2a 2f 0a 20 20 69 6e 74 20 62 46 75 6c 6c g */. int bFull
231d0 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 20 Mutex;
231e0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
231f0 20 74 6f 20 65 6e 61 62 6c 65 20 66 75 6c 6c 20 to enable full
23200 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 20 69 6e mutexing */. in
23210 74 20 62 4f 70 65 6e 55 72 69 3b 20 20 20 20 20 t bOpenUri;
23220 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23230 2f 2a 20 54 72 75 65 20 74 6f 20 69 6e 74 65 72 /* True to inter
23240 70 72 65 74 20 66 69 6c 65 6e 61 6d 65 73 20 61 pret filenames a
23250 73 20 55 52 49 73 20 2a 2f 0a 20 20 69 6e 74 20 s URIs */. int
23260 62 55 73 65 43 69 73 3b 20 20 20 20 20 20 20 20 bUseCis;
23270 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
23280 20 55 73 65 20 63 6f 76 65 72 69 6e 67 20 69 6e Use covering in
23290 64 69 63 65 73 20 66 6f 72 20 66 75 6c 6c 2d 73 dices for full-s
232a0 63 61 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 62 53 cans */. int bS
232b0 6d 61 6c 6c 4d 61 6c 6c 6f 63 3b 20 20 20 20 20 mallMalloc;
232c0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 /* A
232d0 76 6f 69 64 20 6c 61 72 67 65 20 6d 65 6d 6f 72 void large memor
232e0 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 69 66 y allocations if
232f0 20 74 72 75 65 20 2a 2f 0a 20 20 69 6e 74 20 6d true */. int m
23300 78 53 74 72 6c 65 6e 3b 20 20 20 20 20 20 20 20 xStrlen;
23310 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
23320 4d 61 78 69 6d 75 6d 20 73 74 72 69 6e 67 20 6c Maximum string l
23330 65 6e 67 74 68 20 2a 2f 0a 20 20 69 6e 74 20 6e ength */. int n
23340 65 76 65 72 43 6f 72 72 75 70 74 3b 20 20 20 20 everCorrupt;
23350 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
23360 44 61 74 61 62 61 73 65 20 69 73 20 61 6c 77 61 Database is alwa
23370 79 73 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 2a ys well-formed *
23380 2f 0a 20 20 69 6e 74 20 73 7a 4c 6f 6f 6b 61 73 /. int szLookas
23390 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ide;
233a0 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 /* Default
233b0 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 65 lookaside buffe
233c0 72 20 73 69 7a 65 20 2a 2f 0a 20 20 69 6e 74 20 r size */. int
233d0 6e 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 nLookaside;
233e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
233f0 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 69 Default lookasi
23400 64 65 20 62 75 66 66 65 72 20 63 6f 75 6e 74 20 de buffer count
23410 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 6d 74 53 70 */. int nStmtSp
23420 69 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 ill;
23430 20 20 20 20 20 20 20 2f 2a 20 53 74 6d 74 2d 6a /* Stmt-j
23440 6f 75 72 6e 61 6c 20 73 70 69 6c 6c 2d 74 6f 2d ournal spill-to-
23450 64 69 73 6b 20 74 68 72 65 73 68 6f 6c 64 20 2a disk threshold *
23460 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 65 6d 5f /. sqlite3_mem_
23470 6d 65 74 68 6f 64 73 20 6d 3b 20 20 20 20 20 20 methods m;
23480 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 /* Low-lev
23490 65 6c 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 el memory alloca
234a0 74 69 6f 6e 20 69 6e 74 65 72 66 61 63 65 20 2a tion interface *
234b0 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 /. sqlite3_mute
234c0 78 5f 6d 65 74 68 6f 64 73 20 6d 75 74 65 78 3b x_methods mutex;
234d0 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 /* Low-lev
234e0 65 6c 20 6d 75 74 65 78 20 69 6e 74 65 72 66 61 el mutex interfa
234f0 63 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f ce */. sqlite3_
23500 70 63 61 63 68 65 5f 6d 65 74 68 6f 64 73 32 20 pcache_methods2
23510 70 63 61 63 68 65 32 3b 20 20 2f 2a 20 4c 6f 77 pcache2; /* Low
23520 2d 6c 65 76 65 6c 20 70 61 67 65 2d 63 61 63 68 -level page-cach
23530 65 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 e interface */.
23540 20 76 6f 69 64 20 2a 70 48 65 61 70 3b 20 20 20 void *pHeap;
23550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23560 20 20 20 2f 2a 20 48 65 61 70 20 73 74 6f 72 61 /* Heap stora
23570 67 65 20 73 70 61 63 65 20 2a 2f 0a 20 20 69 6e ge space */. in
23580 74 20 6e 48 65 61 70 3b 20 20 20 20 20 20 20 20 t nHeap;
23590 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
235a0 2f 2a 20 53 69 7a 65 20 6f 66 20 70 48 65 61 70 /* Size of pHeap
235b0 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 [] */. int mnRe
235c0 71 2c 20 6d 78 52 65 71 3b 20 20 20 20 20 20 20 q, mxReq;
235d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 69 6e /* Min
235e0 20 61 6e 64 20 6d 61 78 20 68 65 61 70 20 72 65 and max heap re
235f0 71 75 65 73 74 73 20 73 69 7a 65 73 20 2a 2f 0a quests sizes */.
23600 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 sqlite3_int64
23610 73 7a 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 szMmap;
23620 20 20 20 20 2f 2a 20 6d 6d 61 70 28 29 20 73 70 /* mmap() sp
23630 61 63 65 20 70 65 72 20 6f 70 65 6e 20 66 69 6c ace per open fil
23640 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 69 e */. sqlite3_i
23650 6e 74 36 34 20 6d 78 4d 6d 61 70 3b 20 20 20 20 nt64 mxMmap;
23660 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 /* Maxi
23670 6d 75 6d 20 76 61 6c 75 65 20 66 6f 72 20 73 7a mum value for sz
23680 4d 6d 61 70 20 2a 2f 0a 20 20 76 6f 69 64 20 2a Mmap */. void *
23690 70 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 pPage;
236a0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
236b0 61 67 65 20 63 61 63 68 65 20 6d 65 6d 6f 72 79 age cache memory
236c0 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 50 61 67 65 */. int szPage
236d0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
236e0 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
236f0 6f 66 20 65 61 63 68 20 70 61 67 65 20 69 6e 20 of each page in
23700 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 pPage[] */. int
23710 20 6e 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 nPage;
23720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
23730 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 65 * Number of page
23740 73 20 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f 0a s in pPage[] */.
23750 20 20 69 6e 74 20 6d 78 50 61 72 73 65 72 53 74 int mxParserSt
23760 61 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 ack;
23770 20 20 20 20 2f 2a 20 6d 61 78 69 6d 75 6d 20 64 /* maximum d
23780 65 70 74 68 20 6f 66 20 74 68 65 20 70 61 72 73 epth of the pars
23790 65 72 20 73 74 61 63 6b 20 2a 2f 0a 20 20 69 6e er stack */. in
237a0 74 20 73 68 61 72 65 64 43 61 63 68 65 45 6e 61 t sharedCacheEna
237b0 62 6c 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 bled;
237c0 2f 2a 20 74 72 75 65 20 69 66 20 73 68 61 72 65 /* true if share
237d0 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 65 6e 61 d-cache mode ena
237e0 62 6c 65 64 20 2a 2f 0a 20 20 75 33 32 20 73 7a bled */. u32 sz
237f0 50 6d 61 3b 20 20 20 20 20 20 20 20 20 20 20 20 Pma;
23800 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d /* M
23810 61 78 69 6d 75 6d 20 53 6f 72 74 65 72 20 50 4d aximum Sorter PM
23820 41 20 73 69 7a 65 20 2a 2f 0a 20 20 2f 2a 20 54 A size */. /* T
23830 68 65 20 61 62 6f 76 65 20 6d 69 67 68 74 20 62 he above might b
23840 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 74 6f e initialized to
23850 20 6e 6f 6e 2d 7a 65 72 6f 2e 20 20 54 68 65 20 non-zero. The
23860 66 6f 6c 6c 6f 77 69 6e 67 20 6e 65 65 64 20 74 following need t
23870 6f 20 61 6c 77 61 79 73 0a 20 20 2a 2a 20 69 6e o always. ** in
23880 69 74 69 61 6c 6c 79 20 62 65 20 7a 65 72 6f 2c itially be zero,
23890 20 68 6f 77 65 76 65 72 2e 20 2a 2f 0a 20 20 69 however. */. i
238a0 6e 74 20 69 73 49 6e 69 74 3b 20 20 20 20 20 20 nt isInit;
238b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
238c0 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 69 /* True after i
238d0 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 68 61 nitialization ha
238e0 73 20 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 20 s finished */.
238f0 69 6e 74 20 69 6e 50 72 6f 67 72 65 73 73 3b 20 int inProgress;
23900 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23910 20 20 2f 2a 20 54 72 75 65 20 77 68 69 6c 65 20 /* True while
23920 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 69 initialization i
23930 6e 20 70 72 6f 67 72 65 73 73 20 2a 2f 0a 20 20 n progress */.
23940 69 6e 74 20 69 73 4d 75 74 65 78 49 6e 69 74 3b int isMutexInit;
23950 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23960 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 /* True after
23970 6d 75 74 65 78 65 73 20 61 72 65 20 69 6e 69 74 mutexes are init
23980 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 ialized */. int
23990 20 69 73 4d 61 6c 6c 6f 63 49 6e 69 74 3b 20 20 isMallocInit;
239a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
239b0 2a 20 54 72 75 65 20 61 66 74 65 72 20 6d 61 6c * True after mal
239c0 6c 6f 63 20 69 73 20 69 6e 69 74 69 61 6c 69 7a loc is initializ
239d0 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 73 50 43 ed */. int isPC
239e0 61 63 68 65 49 6e 69 74 3b 20 20 20 20 20 20 20 acheInit;
239f0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
23a00 65 20 61 66 74 65 72 20 6d 61 6c 6c 6f 63 20 69 e after malloc i
23a10 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f s initialized */
23a20 0a 20 20 69 6e 74 20 6e 52 65 66 49 6e 69 74 4d . int nRefInitM
23a30 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 20 20 utex;
23a40 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
23a50 66 20 75 73 65 72 73 20 6f 66 20 70 49 6e 69 74 f users of pInit
23a60 4d 75 74 65 78 20 2a 2f 0a 20 20 73 71 6c 69 74 Mutex */. sqlit
23a70 65 33 5f 6d 75 74 65 78 20 2a 70 49 6e 69 74 4d e3_mutex *pInitM
23a80 75 74 65 78 3b 20 20 20 20 20 20 20 20 2f 2a 20 utex; /*
23a90 4d 75 74 65 78 20 75 73 65 64 20 62 79 20 73 71 Mutex used by sq
23aa0 6c 69 74 65 33 5f 69 6e 69 74 69 61 6c 69 7a 65 lite3_initialize
23ab0 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 () */. void (*x
23ac0 4c 6f 67 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 63 Log)(void*,int,c
23ad0 6f 6e 73 74 20 63 68 61 72 2a 29 3b 20 2f 2a 20 onst char*); /*
23ae0 46 75 6e 63 74 69 6f 6e 20 66 6f 72 20 6c 6f 67 Function for log
23af0 67 69 6e 67 20 2a 2f 0a 20 20 76 6f 69 64 20 2a ging */. void *
23b00 70 4c 6f 67 41 72 67 3b 20 20 20 20 20 20 20 20 pLogArg;
23b10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
23b20 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 * First argument
23b30 20 74 6f 20 78 4c 6f 67 28 29 20 2a 2f 0a 23 69 to xLog() */.#i
23b40 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
23b50 4c 45 5f 53 51 4c 4c 4f 47 0a 20 20 76 6f 69 64 LE_SQLLOG. void
23b60 28 2a 78 53 71 6c 6c 6f 67 29 28 76 6f 69 64 2a (*xSqllog)(void*
23b70 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 ,sqlite3*,const
23b80 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 char*, int);. v
23b90 6f 69 64 20 2a 70 53 71 6c 6c 6f 67 41 72 67 3b oid *pSqllogArg;
23ba0 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 .#endif.#ifdef S
23bb0 51 4c 49 54 45 5f 56 44 42 45 5f 43 4f 56 45 52 QLITE_VDBE_COVER
23bc0 41 47 45 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c AGE. /* The fol
23bd0 6c 6f 77 69 6e 67 20 63 61 6c 6c 62 61 63 6b 20 lowing callback
23be0 28 69 66 20 6e 6f 74 20 4e 55 4c 4c 29 20 69 73 (if not NULL) is
23bf0 20 69 6e 76 6f 6b 65 64 20 6f 6e 20 65 76 65 72 invoked on ever
23c00 79 20 56 44 42 45 20 62 72 61 6e 63 68 0a 20 20 y VDBE branch.
23c10 2a 2a 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 53 ** operation. S
23c20 65 74 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 et the callback
23c30 75 73 69 6e 67 20 53 51 4c 49 54 45 5f 54 45 53 using SQLITE_TES
23c40 54 43 54 52 4c 5f 56 44 42 45 5f 43 4f 56 45 52 TCTRL_VDBE_COVER
23c50 41 47 45 2e 0a 20 20 2a 2f 0a 20 20 76 6f 69 64 AGE.. */. void
23c60 20 28 2a 78 56 64 62 65 42 72 61 6e 63 68 29 28 (*xVdbeBranch)(
23c70 76 6f 69 64 2a 2c 69 6e 74 20 69 53 72 63 4c 69 void*,int iSrcLi
23c80 6e 65 2c 75 38 20 65 54 68 69 73 2c 75 38 20 65 ne,u8 eThis,u8 e
23c90 4d 78 29 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 Mx); /* Callbac
23ca0 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 56 64 k */. void *pVd
23cb0 62 65 42 72 61 6e 63 68 41 72 67 3b 20 20 20 20 beBranchArg;
23cc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23ce0 20 2f 2a 20 31 73 74 20 61 72 67 75 6d 65 6e 74 /* 1st argument
23cf0 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 */.#endif.#ifnd
23d00 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 ef SQLITE_UNTEST
23d10 41 42 4c 45 0a 20 20 69 6e 74 20 28 2a 78 54 65 ABLE. int (*xTe
23d20 73 74 43 61 6c 6c 62 61 63 6b 29 28 69 6e 74 29 stCallback)(int)
23d30 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 76 6f ; /* Invo
23d40 6b 65 64 20 62 79 20 73 71 6c 69 74 65 33 46 61 ked by sqlite3Fa
23d50 75 6c 74 53 69 6d 28 29 20 2a 2f 0a 23 65 6e 64 ultSim() */.#end
23d60 69 66 0a 20 20 69 6e 74 20 62 4c 6f 63 61 6c 74 if. int bLocalt
23d70 69 6d 65 46 61 75 6c 74 3b 20 20 20 20 20 20 20 imeFault;
23d80 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 /* True t
23d90 6f 20 66 61 69 6c 20 6c 6f 63 61 6c 74 69 6d 65 o fail localtime
23da0 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 20 20 69 6e () calls */. in
23db0 74 20 69 4f 6e 63 65 52 65 73 65 74 54 68 72 65 t iOnceResetThre
23dc0 73 68 6f 6c 64 3b 20 20 20 20 20 20 20 20 20 20 shold;
23dd0 2f 2a 20 57 68 65 6e 20 74 6f 20 72 65 73 65 74 /* When to reset
23de0 20 4f 50 5f 4f 6e 63 65 20 63 6f 75 6e 74 65 72 OP_Once counter
23df0 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 s */.};../*.** T
23e00 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 his macro is use
23e10 64 20 69 6e 73 69 64 65 20 6f 66 20 61 73 73 65 d inside of asse
23e20 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 20 rt() statements
23e30 74 6f 20 69 6e 64 69 63 61 74 65 20 74 68 61 74 to indicate that
23e40 0a 2a 2a 20 74 68 65 20 61 73 73 65 72 74 20 69 .** the assert i
23e50 73 20 6f 6e 6c 79 20 76 61 6c 69 64 20 6f 6e 20 s only valid on
23e60 61 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 a well-formed da
23e70 74 61 62 61 73 65 2e 20 20 49 6e 73 74 65 61 64 tabase. Instead
23e80 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 of:.**.** a
23e90 73 73 65 72 74 28 20 58 20 29 3b 0a 2a 2a 0a 2a ssert( X );.**.*
23ea0 2a 20 4f 6e 65 20 77 72 69 74 65 73 3a 0a 2a 2a * One writes:.**
23eb0 0a 2a 2a 20 20 20 20 20 61 73 73 65 72 74 28 20 .** assert(
23ec0 58 20 7c 7c 20 43 4f 52 52 55 50 54 5f 44 42 20 X || CORRUPT_DB
23ed0 29 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 52 55 50 54 );.**.** CORRUPT
23ee0 5f 44 42 20 69 73 20 74 72 75 65 20 64 75 72 69 _DB is true duri
23ef0 6e 67 20 6e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 ng normal operat
23f00 69 6f 6e 2e 20 20 43 4f 52 52 55 50 54 5f 44 42 ion. CORRUPT_DB
23f10 20 64 6f 65 73 20 6e 6f 74 20 69 6e 64 69 63 61 does not indica
23f20 74 65 0a 2a 2a 20 74 68 61 74 20 74 68 65 20 64 te.** that the d
23f30 61 74 61 62 61 73 65 20 69 73 20 64 65 66 69 6e atabase is defin
23f40 69 74 65 6c 79 20 63 6f 72 72 75 70 74 2c 20 6f itely corrupt, o
23f50 6e 6c 79 20 74 68 61 74 20 69 74 20 6d 69 67 68 nly that it migh
23f60 74 20 62 65 20 63 6f 72 72 75 70 74 2e 0a 2a 2a t be corrupt..**
23f70 20 46 6f 72 20 6d 6f 73 74 20 74 65 73 74 20 63 For most test c
23f80 61 73 65 73 2c 20 43 4f 52 52 55 50 54 5f 44 42 ases, CORRUPT_DB
23f90 20 69 73 20 73 65 74 20 74 6f 20 66 61 6c 73 65 is set to false
23fa0 20 75 73 69 6e 67 20 61 20 73 70 65 63 69 61 6c using a special
23fb0 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 74 .** sqlite3_test
23fc0 5f 63 6f 6e 74 72 6f 6c 28 29 2e 20 20 54 68 69 _control(). Thi
23fd0 73 20 65 6e 61 62 6c 65 73 20 61 73 73 65 72 74 s enables assert
23fe0 28 29 20 73 74 61 74 65 6d 65 6e 74 73 20 74 6f () statements to
23ff0 20 70 72 6f 76 65 0a 2a 2a 20 74 68 69 6e 67 73 prove.** things
24000 20 74 68 61 74 20 61 72 65 20 61 6c 77 61 79 73 that are always
24010 20 74 72 75 65 20 66 6f 72 20 77 65 6c 6c 2d 66 true for well-f
24020 6f 72 6d 65 64 20 64 61 74 61 62 61 73 65 73 2e ormed databases.
24030 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 52 52 .*/.#define CORR
24040 55 50 54 5f 44 42 20 20 28 73 71 6c 69 74 65 33 UPT_DB (sqlite3
24050 43 6f 6e 66 69 67 2e 6e 65 76 65 72 43 6f 72 72 Config.neverCorr
24060 75 70 74 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 43 upt==0)../*.** C
24070 6f 6e 74 65 78 74 20 70 6f 69 6e 74 65 72 20 70 ontext pointer p
24080 61 73 73 65 64 20 64 6f 77 6e 20 74 68 72 6f 75 assed down throu
24090 67 68 20 74 68 65 20 74 72 65 65 2d 77 61 6c 6b gh the tree-walk
240a0 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 61 6c 6b ..*/.struct Walk
240b0 65 72 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 er {. Parse *pP
240c0 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 20 arse;
240d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
240e0 20 2f 2a 20 50 61 72 73 65 72 20 63 6f 6e 74 65 /* Parser conte
240f0 78 74 2e 20 20 2a 2f 0a 20 20 69 6e 74 20 28 2a xt. */. int (*
24100 78 45 78 70 72 43 61 6c 6c 62 61 63 6b 29 28 57 xExprCallback)(W
24110 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a 29 3b 20 alker*, Expr*);
24120 20 20 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 /* Callback
24130 66 6f 72 20 65 78 70 72 65 73 73 69 6f 6e 73 20 for expressions
24140 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 53 65 6c 65 */. int (*xSele
24150 63 74 43 61 6c 6c 62 61 63 6b 29 28 57 61 6c 6b ctCallback)(Walk
24160 65 72 2a 2c 53 65 6c 65 63 74 2a 29 3b 20 20 2f er*,Select*); /
24170 2a 20 43 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 * Callback for S
24180 45 4c 45 43 54 73 20 2a 2f 0a 20 20 76 6f 69 64 ELECTs */. void
24190 20 28 2a 78 53 65 6c 65 63 74 43 61 6c 6c 62 61 (*xSelectCallba
241a0 63 6b 32 29 28 57 61 6c 6b 65 72 2a 2c 53 65 6c ck2)(Walker*,Sel
241b0 65 63 74 2a 29 3b 2f 2a 20 53 65 63 6f 6e 64 20 ect*);/* Second
241c0 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 45 4c callback for SEL
241d0 45 43 54 73 20 2a 2f 0a 20 20 69 6e 74 20 77 61 ECTs */. int wa
241e0 6c 6b 65 72 44 65 70 74 68 3b 20 20 20 20 20 20 lkerDepth;
241f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24200 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
24210 20 73 75 62 71 75 65 72 69 65 73 20 2a 2f 0a 20 subqueries */.
24220 20 75 38 20 65 43 6f 64 65 3b 20 20 20 20 20 20 u8 eCode;
24230 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24240 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 /* A
24250 73 6d 61 6c 6c 20 70 72 6f 63 65 73 73 69 6e 67 small processing
24260 20 63 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e code */. union
24270 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
24280 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24290 20 20 20 20 20 2f 2a 20 45 78 74 72 61 20 64 61 /* Extra da
242a0 74 61 20 66 6f 72 20 63 61 6c 6c 62 61 63 6b 20 ta for callback
242b0 2a 2f 0a 20 20 20 20 4e 61 6d 65 43 6f 6e 74 65 */. NameConte
242c0 78 74 20 2a 70 4e 43 3b 20 20 20 20 20 20 20 20 xt *pNC;
242d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
242e0 20 2f 2a 20 4e 61 6d 69 6e 67 20 63 6f 6e 74 65 /* Naming conte
242f0 78 74 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 3b xt */. int n;
24300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24310 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24320 20 20 20 20 2f 2a 20 41 20 63 6f 75 6e 74 65 72 /* A counter
24330 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 43 75 72 */. int iCur
24340 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
24350 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24360 20 20 2f 2a 20 41 20 63 75 72 73 6f 72 20 6e 75 /* A cursor nu
24370 6d 62 65 72 20 2a 2f 0a 20 20 20 20 53 72 63 4c mber */. SrcL
24380 69 73 74 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 ist *pSrcList;
24390 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
243a0 20 20 20 20 20 20 2f 2a 20 46 52 4f 4d 20 63 6c /* FROM cl
243b0 61 75 73 65 20 2a 2f 0a 20 20 20 20 73 74 72 75 ause */. stru
243c0 63 74 20 53 72 63 43 6f 75 6e 74 20 2a 70 53 72 ct SrcCount *pSr
243d0 63 43 6f 75 6e 74 3b 20 20 20 20 20 20 20 20 20 cCount;
243e0 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 69 6e /* Countin
243f0 67 20 63 6f 6c 75 6d 6e 20 72 65 66 65 72 65 6e g column referen
24400 63 65 73 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 ces */. struc
24410 74 20 43 43 75 72 48 69 6e 74 20 2a 70 43 43 75 t CCurHint *pCCu
24420 72 48 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 rHint;
24430 20 20 20 20 20 2f 2a 20 55 73 65 64 20 62 79 20 /* Used by
24440 63 6f 64 65 43 75 72 73 6f 72 48 69 6e 74 28 29 codeCursorHint()
24450 20 2a 2f 0a 20 20 20 20 69 6e 74 20 2a 61 69 43 */. int *aiC
24460 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ol;
24470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24480 20 20 2f 2a 20 61 72 72 61 79 20 6f 66 20 63 6f /* array of co
24490 6c 75 6d 6e 20 69 6e 64 65 78 65 73 20 2a 2f 0a lumn indexes */.
244a0 20 20 20 20 73 74 72 75 63 74 20 49 64 78 43 6f struct IdxCo
244b0 76 65 72 20 2a 70 49 64 78 43 6f 76 65 72 3b 20 ver *pIdxCover;
244c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
244d0 20 43 68 65 63 6b 20 66 6f 72 20 69 6e 64 65 78 Check for index
244e0 20 63 6f 76 65 72 61 67 65 20 2a 2f 0a 20 20 20 coverage */.
244f0 20 73 74 72 75 63 74 20 49 64 78 45 78 70 72 54 struct IdxExprT
24500 72 61 6e 73 20 2a 70 49 64 78 54 72 61 6e 73 3b rans *pIdxTrans;
24510 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f /* Co
24520 6e 76 65 72 74 20 69 64 78 65 64 20 65 78 70 72 nvert idxed expr
24530 20 74 6f 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 to column */.
24540 20 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f ExprList *pGro
24550 75 70 42 79 3b 20 20 20 20 20 20 20 20 20 20 20 upBy;
24560 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 47 /* G
24570 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 2a ROUP BY clause *
24580 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 /. Select *pS
24590 65 6c 65 63 74 3b 20 20 20 20 20 20 20 20 20 20 elect;
245a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
245b0 2f 2a 20 48 41 56 49 4e 47 20 74 6f 20 57 48 45 /* HAVING to WHE
245c0 52 45 20 63 6c 61 75 73 65 20 63 74 78 20 2a 2f RE clause ctx */
245d0 0a 20 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f 2a 20 46 . } u;.};../* F
245e0 6f 72 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 orward declarati
245f0 6f 6e 73 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 ons */.int sqlit
24600 65 33 57 61 6c 6b 45 78 70 72 28 57 61 6c 6b 65 e3WalkExpr(Walke
24610 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 r*, Expr*);.int
24620 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 70 72 4c sqlite3WalkExprL
24630 69 73 74 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 ist(Walker*, Exp
24640 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c rList*);.int sql
24650 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 28 57 ite3WalkSelect(W
24660 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 alker*, Select*)
24670 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c ;.int sqlite3Wal
24680 6b 53 65 6c 65 63 74 45 78 70 72 28 57 61 6c 6b kSelectExpr(Walk
24690 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 er*, Select*);.i
246a0 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 65 nt sqlite3WalkSe
246b0 6c 65 63 74 46 72 6f 6d 28 57 61 6c 6b 65 72 2a lectFrom(Walker*
246c0 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 , Select*);.int
246d0 73 71 6c 69 74 65 33 45 78 70 72 57 61 6c 6b 4e sqlite3ExprWalkN
246e0 6f 6f 70 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 oop(Walker*, Exp
246f0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
24700 53 65 6c 65 63 74 57 61 6c 6b 4e 6f 6f 70 28 57 SelectWalkNoop(W
24710 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 alker*, Select*)
24720 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c ;.int sqlite3Sel
24730 65 63 74 57 61 6c 6b 46 61 69 6c 28 57 61 6c 6b ectWalkFail(Walk
24740 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 23 er*, Select*);.#
24750 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
24760 55 47 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 UG.void sqlite3S
24770 65 6c 65 63 74 57 61 6c 6b 41 73 73 65 72 74 32 electWalkAssert2
24780 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 (Walker*, Select
24790 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a *);.#endif../*.*
247a0 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 * Return code fr
247b0 6f 6d 20 74 68 65 20 70 61 72 73 65 2d 74 72 65 om the parse-tre
247c0 65 20 77 61 6c 6b 69 6e 67 20 70 72 69 6d 69 74 e walking primit
247d0 69 76 65 73 20 61 6e 64 20 74 68 65 69 72 0a 2a ives and their.*
247e0 2a 20 63 61 6c 6c 62 61 63 6b 73 2e 0a 2a 2f 0a * callbacks..*/.
247f0 23 64 65 66 69 6e 65 20 57 52 43 5f 43 6f 6e 74 #define WRC_Cont
24800 69 6e 75 65 20 20 20 20 30 20 20 20 2f 2a 20 43 inue 0 /* C
24810 6f 6e 74 69 6e 75 65 20 64 6f 77 6e 20 69 6e 74 ontinue down int
24820 6f 20 63 68 69 6c 64 72 65 6e 20 2a 2f 0a 23 64 o children */.#d
24830 65 66 69 6e 65 20 57 52 43 5f 50 72 75 6e 65 20 efine WRC_Prune
24840 20 20 20 20 20 20 31 20 20 20 2f 2a 20 4f 6d 69 1 /* Omi
24850 74 20 63 68 69 6c 64 72 65 6e 20 62 75 74 20 63 t children but c
24860 6f 6e 74 69 6e 75 65 20 77 61 6c 6b 69 6e 67 20 ontinue walking
24870 73 69 62 6c 69 6e 67 73 20 2a 2f 0a 23 64 65 66 siblings */.#def
24880 69 6e 65 20 57 52 43 5f 41 62 6f 72 74 20 20 20 ine WRC_Abort
24890 20 20 20 20 32 20 20 20 2f 2a 20 41 62 61 6e 64 2 /* Aband
248a0 6f 6e 20 74 68 65 20 74 72 65 65 20 77 61 6c 6b on the tree walk
248b0 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e */../*.** An in
248c0 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 stance of this s
248d0 74 72 75 63 74 75 72 65 20 72 65 70 72 65 73 65 tructure represe
248e0 6e 74 73 20 61 20 73 65 74 20 6f 66 20 6f 6e 65 nts a set of one
248f0 20 6f 72 20 6d 6f 72 65 20 43 54 45 73 0a 2a 2a or more CTEs.**
24900 20 28 63 6f 6d 6d 6f 6e 20 74 61 62 6c 65 20 65 (common table e
24910 78 70 72 65 73 73 69 6f 6e 73 29 20 63 72 65 61 xpressions) crea
24920 74 65 64 20 62 79 20 61 20 73 69 6e 67 6c 65 20 ted by a single
24930 57 49 54 48 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a WITH clause..*/.
24940 73 74 72 75 63 74 20 57 69 74 68 20 7b 0a 20 20 struct With {.
24950 69 6e 74 20 6e 43 74 65 3b 20 20 20 20 20 20 20 int nCte;
24960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24970 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 43 54 45 /* Number of CTE
24980 73 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c s in the WITH cl
24990 61 75 73 65 20 2a 2f 0a 20 20 57 69 74 68 20 2a ause */. With *
249a0 70 4f 75 74 65 72 3b 20 20 20 20 20 20 20 20 20 pOuter;
249b0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e /* Con
249c0 74 61 69 6e 69 6e 67 20 57 49 54 48 20 63 6c 61 taining WITH cla
249d0 75 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a use, or NULL */.
249e0 20 20 73 74 72 75 63 74 20 43 74 65 20 7b 20 20 struct Cte {
249f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24a00 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 43 54 /* For each CT
24a10 45 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c E in the WITH cl
24a20 61 75 73 65 2e 2e 2e 2e 20 2a 2f 0a 20 20 20 20 ause.... */.
24a30 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
24a40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24a50 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 /* Name of this
24a60 43 54 45 20 2a 2f 0a 20 20 20 20 45 78 70 72 4c CTE */. ExprL
24a70 69 73 74 20 2a 70 43 6f 6c 73 3b 20 20 20 20 20 ist *pCols;
24a80 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 /* Li
24a90 73 74 20 6f 66 20 65 78 70 6c 69 63 69 74 20 63 st of explicit c
24aa0 6f 6c 75 6d 6e 20 6e 61 6d 65 73 2c 20 6f 72 20 olumn names, or
24ab0 4e 55 4c 4c 20 2a 2f 0a 20 20 20 20 53 65 6c 65 NULL */. Sele
24ac0 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 ct *pSelect;
24ad0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
24ae0 68 65 20 64 65 66 69 6e 69 74 69 6f 6e 20 6f 66 he definition of
24af0 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 20 20 this CTE */.
24b00 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 74 const char *zCt
24b10 65 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 eErr;
24b20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 67 /* Error messag
24b30 65 20 66 6f 72 20 63 69 72 63 75 6c 61 72 20 72 e for circular r
24b40 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 20 7d eferences */. }
24b50 20 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 69 66 64 65 a[1];.};..#ifde
24b60 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 2f f SQLITE_DEBUG./
24b70 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
24b80 20 6f 66 20 74 68 65 20 54 72 65 65 56 69 65 77 of the TreeView
24b90 20 6f 62 6a 65 63 74 20 69 73 20 75 73 65 64 20 object is used
24ba0 66 6f 72 20 70 72 69 6e 74 69 6e 67 20 74 68 65 for printing the
24bb0 20 63 6f 6e 74 65 6e 74 20 6f 66 0a 2a 2a 20 64 content of.** d
24bc0 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20 6f ata structures o
24bd0 6e 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 n sqlite3DebugPr
24be0 69 6e 74 66 28 29 20 75 73 69 6e 67 20 61 20 74 intf() using a t
24bf0 72 65 65 2d 6c 69 6b 65 20 76 69 65 77 2e 0a 2a ree-like view..*
24c00 2f 0a 73 74 72 75 63 74 20 54 72 65 65 56 69 65 /.struct TreeVie
24c10 77 20 7b 0a 20 20 69 6e 74 20 69 4c 65 76 65 6c w {. int iLevel
24c20 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
24c30 20 57 68 69 63 68 20 6c 65 76 65 6c 20 6f 66 20 Which level of
24c40 74 68 65 20 74 72 65 65 20 77 65 20 61 72 65 20 the tree we are
24c50 6f 6e 20 2a 2f 0a 20 20 75 38 20 20 62 4c 69 6e on */. u8 bLin
24c60 65 5b 31 30 30 5d 3b 20 20 20 20 20 20 20 20 20 e[100];
24c70 2f 2a 20 44 72 61 77 20 76 65 72 74 69 63 61 6c /* Draw vertical
24c80 20 69 6e 20 63 6f 6c 75 6d 6e 20 69 20 69 66 20 in column i if
24c90 62 4c 69 6e 65 5b 69 5d 20 69 73 20 74 72 75 65 bLine[i] is true
24ca0 20 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 66 20 2f 2a */.};.#endif /*
24cb0 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 2a 2f SQLITE_DEBUG */
24cc0 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 75 6d 69 6e 67 ../*.** Assuming
24cd0 20 7a 49 6e 20 70 6f 69 6e 74 73 20 74 6f 20 74 zIn points to t
24ce0 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f 66 he first byte of
24cf0 20 61 20 55 54 46 2d 38 20 63 68 61 72 61 63 74 a UTF-8 charact
24d00 65 72 2c 0a 2a 2a 20 61 64 76 61 6e 63 65 20 7a er,.** advance z
24d10 49 6e 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 74 In to point to t
24d20 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f 66 he first byte of
24d30 20 74 68 65 20 6e 65 78 74 20 55 54 46 2d 38 20 the next UTF-8
24d40 63 68 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 23 64 character..*/.#d
24d50 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4b 49 efine SQLITE_SKI
24d60 50 5f 55 54 46 38 28 7a 49 6e 29 20 7b 20 20 20 P_UTF8(zIn) {
24d70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24d80 20 20 20 20 20 5c 0a 20 20 69 66 28 20 28 2a 28 \. if( (*(
24d90 7a 49 6e 2b 2b 29 29 3e 3d 30 78 63 30 20 29 7b zIn++))>=0xc0 ){
24da0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24db0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5c 0a \.
24dc0 20 20 20 20 77 68 69 6c 65 28 20 28 2a 7a 49 6e while( (*zIn
24dd0 20 26 20 30 78 63 30 29 3d 3d 30 78 38 30 20 29 & 0xc0)==0x80 )
24de0 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 20 20 20 20 20 { zIn++; }
24df0 20 20 20 20 20 20 20 5c 0a 20 20 7d 20 20 20 20 \. }
24e00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24e10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24e20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24e30 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 \.}../*.** The S
24e40 51 4c 49 54 45 5f 2a 5f 42 4b 50 54 20 6d 61 63 QLITE_*_BKPT mac
24e50 72 6f 73 20 61 72 65 20 73 75 62 73 74 69 74 75 ros are substitu
24e60 74 65 73 20 66 6f 72 20 74 68 65 20 65 72 72 6f tes for the erro
24e70 72 20 63 6f 64 65 73 20 77 69 74 68 0a 2a 2a 20 r codes with.**
24e80 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 20 62 75 the same name bu
24e90 74 20 77 69 74 68 6f 75 74 20 74 68 65 20 5f 42 t without the _B
24ea0 4b 50 54 20 73 75 66 66 69 78 2e 20 20 54 68 65 KPT suffix. The
24eb0 73 65 20 6d 61 63 72 6f 73 20 69 6e 76 6f 6b 65 se macros invoke
24ec0 0a 2a 2a 20 72 6f 75 74 69 6e 65 73 20 74 68 61 .** routines tha
24ed0 74 20 72 65 70 6f 72 74 20 74 68 65 20 6c 69 6e t report the lin
24ee0 65 2d 6e 75 6d 62 65 72 20 6f 6e 20 77 68 69 63 e-number on whic
24ef0 68 20 74 68 65 20 65 72 72 6f 72 20 6f 72 69 67 h the error orig
24f00 69 6e 61 74 65 64 0a 2a 2a 20 75 73 69 6e 67 20 inated.** using
24f10 73 71 6c 69 74 65 33 5f 6c 6f 67 28 29 2e 20 20 sqlite3_log().
24f20 54 68 65 20 72 6f 75 74 69 6e 65 73 20 61 6c 73 The routines als
24f30 6f 20 70 72 6f 76 69 64 65 20 61 20 63 6f 6e 76 o provide a conv
24f40 65 6e 69 65 6e 74 20 70 6c 61 63 65 0a 2a 2a 20 enient place.**
24f50 74 6f 20 73 65 74 20 61 20 64 65 62 75 67 67 65 to set a debugge
24f60 72 20 62 72 65 61 6b 70 6f 69 6e 74 2e 0a 2a 2f r breakpoint..*/
24f70 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 70 6f .int sqlite3Repo
24f80 72 74 45 72 72 6f 72 28 69 6e 74 20 69 45 72 72 rtError(int iErr
24f90 2c 20 69 6e 74 20 6c 69 6e 65 6e 6f 2c 20 63 6f , int lineno, co
24fa0 6e 73 74 20 63 68 61 72 20 2a 7a 54 79 70 65 29 nst char *zType)
24fb0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 72 ;.int sqlite3Cor
24fc0 72 75 70 74 45 72 72 6f 72 28 69 6e 74 29 3b 0a ruptError(int);.
24fd0 69 6e 74 20 73 71 6c 69 74 65 33 4d 69 73 75 73 int sqlite3Misus
24fe0 65 45 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e 74 eError(int);.int
24ff0 20 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e sqlite3Cantopen
25000 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 64 65 66 Error(int);.#def
25010 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 ine SQLITE_CORRU
25020 50 54 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 43 PT_BKPT sqlite3C
25030 6f 72 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c 49 orruptError(__LI
25040 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 NE__).#define SQ
25050 4c 49 54 45 5f 4d 49 53 55 53 45 5f 42 4b 50 54 LITE_MISUSE_BKPT
25060 20 73 71 6c 69 74 65 33 4d 69 73 75 73 65 45 72 sqlite3MisuseEr
25070 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 ror(__LINE__).#d
25080 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 41 4e efine SQLITE_CAN
25090 54 4f 50 45 4e 5f 42 4b 50 54 20 73 71 6c 69 74 TOPEN_BKPT sqlit
250a0 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 e3CantopenError(
250b0 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 69 66 64 65 66 __LINE__).#ifdef
250c0 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 20 SQLITE_DEBUG.
250d0 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f 6d 65 6d int sqlite3Nomem
250e0 45 72 72 6f 72 28 69 6e 74 29 3b 0a 20 20 69 6e Error(int);. in
250f0 74 20 73 71 6c 69 74 65 33 49 6f 65 72 72 6e 6f t sqlite3Ioerrno
25100 6d 65 6d 45 72 72 6f 72 28 69 6e 74 29 3b 0a 20 memError(int);.
25110 20 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 72 72 int sqlite3Corr
25120 75 70 74 50 67 6e 6f 45 72 72 6f 72 28 69 6e 74 uptPgnoError(int
25130 2c 50 67 6e 6f 29 3b 0a 23 20 64 65 66 69 6e 65 ,Pgno);.# define
25140 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 5f 42 4b SQLITE_NOMEM_BK
25150 50 54 20 73 71 6c 69 74 65 33 4e 6f 6d 65 6d 45 PT sqlite3NomemE
25160 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 rror(__LINE__).#
25170 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 define SQLITE_I
25180 4f 45 52 52 5f 4e 4f 4d 45 4d 5f 42 4b 50 54 20 OERR_NOMEM_BKPT
25190 73 71 6c 69 74 65 33 49 6f 65 72 72 6e 6f 6d 65 sqlite3Ioerrnome
251a0 6d 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 mError(__LINE__)
251b0 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
251c0 5f 43 4f 52 52 55 50 54 5f 50 47 4e 4f 28 50 29 _CORRUPT_PGNO(P)
251d0 20 73 71 6c 69 74 65 33 43 6f 72 72 75 70 74 50 sqlite3CorruptP
251e0 67 6e 6f 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f gnoError(__LINE_
251f0 5f 2c 28 50 29 29 0a 23 65 6c 73 65 0a 23 20 64 _,(P)).#else.# d
25200 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 4d efine SQLITE_NOM
25210 45 4d 5f 42 4b 50 54 20 53 51 4c 49 54 45 5f 4e EM_BKPT SQLITE_N
25220 4f 4d 45 4d 0a 23 20 64 65 66 69 6e 65 20 53 51 OMEM.# define SQ
25230 4c 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d 45 4d LITE_IOERR_NOMEM
25240 5f 42 4b 50 54 20 53 51 4c 49 54 45 5f 49 4f 45 _BKPT SQLITE_IOE
25250 52 52 5f 4e 4f 4d 45 4d 0a 23 20 64 65 66 69 6e RR_NOMEM.# defin
25260 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 50 54 e SQLITE_CORRUPT
25270 5f 50 47 4e 4f 28 50 29 20 73 71 6c 69 74 65 33 _PGNO(P) sqlite3
25280 43 6f 72 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c CorruptError(__L
25290 49 4e 45 5f 5f 29 0a 23 65 6e 64 69 66 0a 0a 2f INE__).#endif../
252a0 2a 0a 2a 2a 20 46 54 53 33 20 61 6e 64 20 46 54 *.** FTS3 and FT
252b0 53 34 20 62 6f 74 68 20 72 65 71 75 69 72 65 20 S4 both require
252c0 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 73 75 virtual table su
252d0 70 70 6f 72 74 0a 2a 2f 0a 23 69 66 20 64 65 66 pport.*/.#if def
252e0 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 ined(SQLITE_OMIT
252f0 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 0a 23 _VIRTUALTABLE).#
25300 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e undef SQLITE_EN
25310 41 42 4c 45 5f 46 54 53 33 0a 23 20 75 6e 64 65 ABLE_FTS3.# unde
25320 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
25330 46 54 53 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a FTS4.#endif../*.
25340 2a 2a 20 46 54 53 34 20 69 73 20 72 65 61 6c 6c ** FTS4 is reall
25350 79 20 61 6e 20 65 78 74 65 6e 73 69 6f 6e 20 66 y an extension f
25360 6f 72 20 46 54 53 33 2e 20 20 49 74 20 69 73 20 or FTS3. It is
25370 65 6e 61 62 6c 65 64 20 75 73 69 6e 67 20 74 68 enabled using th
25380 65 0a 2a 2a 20 53 51 4c 49 54 45 5f 45 4e 41 42 e.** SQLITE_ENAB
25390 4c 45 5f 46 54 53 33 20 6d 61 63 72 6f 2e 20 20 LE_FTS3 macro.
253a0 42 75 74 20 74 6f 20 61 76 6f 69 64 20 63 6f 6e But to avoid con
253b0 66 75 73 69 6f 6e 20 77 65 20 61 6c 73 6f 20 63 fusion we also c
253c0 61 6c 6c 0a 2a 2a 20 74 68 65 20 53 51 4c 49 54 all.** the SQLIT
253d0 45 5f 45 4e 41 42 4c 45 5f 46 54 53 34 20 6d 61 E_ENABLE_FTS4 ma
253e0 63 72 6f 20 74 6f 20 73 65 72 76 65 20 61 73 20 cro to serve as
253f0 61 6e 20 61 6c 69 61 73 20 66 6f 72 20 53 51 4c an alias for SQL
25400 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 2e ITE_ENABLE_FTS3.
25410 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
25420 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
25430 53 34 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 S4) && !defined(
25440 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
25450 53 33 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c S3).# define SQL
25460 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 ITE_ENABLE_FTS3
25470 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 1.#endif../*.**
25480 54 68 65 20 63 74 79 70 65 2e 68 20 68 65 61 64 The ctype.h head
25490 65 72 20 69 73 20 6e 65 65 64 65 64 20 66 6f 72 er is needed for
254a0 20 6e 6f 6e 2d 41 53 43 49 49 20 73 79 73 74 65 non-ASCII syste
254b0 6d 73 2e 20 20 49 74 20 69 73 20 61 6c 73 6f 0a ms. It is also.
254c0 2a 2a 20 6e 65 65 64 65 64 20 62 79 20 46 54 53 ** needed by FTS
254d0 33 20 77 68 65 6e 20 46 54 53 33 20 69 73 20 69 3 when FTS3 is i
254e0 6e 63 6c 75 64 65 64 20 69 6e 20 74 68 65 20 61 ncluded in the a
254f0 6d 61 6c 67 61 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a malgamation..*/.
25500 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
25510 49 54 45 5f 41 53 43 49 49 29 20 7c 7c 20 5c 0a ITE_ASCII) || \.
25520 20 20 20 20 28 64 65 66 69 6e 65 64 28 53 51 4c (defined(SQL
25530 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 29 ITE_ENABLE_FTS3)
25540 20 26 26 20 64 65 66 69 6e 65 64 28 53 51 4c 49 && defined(SQLI
25550 54 45 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 29 TE_AMALGAMATION)
25560 29 0a 23 20 69 6e 63 6c 75 64 65 20 3c 63 74 79 ).# include <cty
25570 70 65 2e 68 3e 0a 23 65 6e 64 69 66 0a 0a 2f 2a pe.h>.#endif../*
25580 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
25590 67 20 6d 61 63 72 6f 73 20 6d 69 6d 69 63 20 74 g macros mimic t
255a0 68 65 20 73 74 61 6e 64 61 72 64 20 6c 69 62 72 he standard libr
255b0 61 72 79 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f ary functions to
255c0 75 70 70 65 72 28 29 2c 0a 2a 2a 20 69 73 73 70 upper(),.** issp
255d0 61 63 65 28 29 2c 20 69 73 61 6c 6e 75 6d 28 29 ace(), isalnum()
255e0 2c 20 69 73 64 69 67 69 74 28 29 20 61 6e 64 20 , isdigit() and
255f0 69 73 78 64 69 67 69 74 28 29 2c 20 72 65 73 70 isxdigit(), resp
25600 65 63 74 69 76 65 6c 79 2e 20 54 68 65 0a 2a 2a ectively. The.**
25610 20 73 71 6c 69 74 65 20 76 65 72 73 69 6f 6e 73 sqlite versions
25620 20 6f 6e 6c 79 20 77 6f 72 6b 20 66 6f 72 20 41 only work for A
25630 53 43 49 49 20 63 68 61 72 61 63 74 65 72 73 2c SCII characters,
25640 20 72 65 67 61 72 64 6c 65 73 73 20 6f 66 20 6c regardless of l
25650 6f 63 61 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 ocale..*/.#ifdef
25660 20 53 51 4c 49 54 45 5f 41 53 43 49 49 0a 23 20 SQLITE_ASCII.#
25670 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f define sqlite3To
25680 75 70 70 65 72 28 78 29 20 20 28 28 78 29 26 7e upper(x) ((x)&~
25690 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 (sqlite3CtypeMap
256a0 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 [(unsigned char)
256b0 28 78 29 5d 26 30 78 32 30 29 29 0a 23 20 64 65 (x)]&0x20)).# de
256c0 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 73 70 fine sqlite3Issp
256d0 61 63 65 28 78 29 20 20 20 28 73 71 6c 69 74 65 ace(x) (sqlite
256e0 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 3CtypeMap[(unsig
256f0 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 ned char)(x)]&0x
25700 30 31 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 01).# define sql
25710 69 74 65 33 49 73 61 6c 6e 75 6d 28 78 29 20 20 ite3Isalnum(x)
25720 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 (sqlite3CtypeMa
25730 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 p[(unsigned char
25740 29 28 78 29 5d 26 30 78 30 36 29 0a 23 20 64 65 )(x)]&0x06).# de
25750 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 61 6c fine sqlite3Isal
25760 70 68 61 28 78 29 20 20 20 28 73 71 6c 69 74 65 pha(x) (sqlite
25770 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 3CtypeMap[(unsig
25780 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 ned char)(x)]&0x
25790 30 32 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 02).# define sql
257a0 69 74 65 33 49 73 64 69 67 69 74 28 78 29 20 20 ite3Isdigit(x)
257b0 20 28 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 (sqlite3CtypeMa
257c0 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 p[(unsigned char
257d0 29 28 78 29 5d 26 30 78 30 34 29 0a 23 20 64 65 )(x)]&0x04).# de
257e0 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 78 64 fine sqlite3Isxd
257f0 69 67 69 74 28 78 29 20 20 28 73 71 6c 69 74 65 igit(x) (sqlite
25800 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 3CtypeMap[(unsig
25810 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 ned char)(x)]&0x
25820 30 38 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 08).# define sql
25830 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 ite3Tolower(x)
25840 20 28 73 71 6c 69 74 65 33 55 70 70 65 72 54 6f (sqlite3UpperTo
25850 4c 6f 77 65 72 5b 28 75 6e 73 69 67 6e 65 64 20 Lower[(unsigned
25860 63 68 61 72 29 28 78 29 5d 29 0a 23 20 64 65 66 char)(x)]).# def
25870 69 6e 65 20 73 71 6c 69 74 65 33 49 73 71 75 6f ine sqlite3Isquo
25880 74 65 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 te(x) (sqlite3
25890 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e CtypeMap[(unsign
258a0 65 64 20 63 68 61 72 29 28 78 29 5d 26 30 78 38 ed char)(x)]&0x8
258b0 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 0).#else.# defin
258c0 65 20 73 71 6c 69 74 65 33 54 6f 75 70 70 65 72 e sqlite3Toupper
258d0 28 78 29 20 20 20 74 6f 75 70 70 65 72 28 28 75 (x) toupper((u
258e0 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
258f0 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
25900 65 33 49 73 73 70 61 63 65 28 78 29 20 20 20 69 e3Isspace(x) i
25910 73 73 70 61 63 65 28 28 75 6e 73 69 67 6e 65 64 sspace((unsigned
25920 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 char)(x)).# def
25930 69 6e 65 20 73 71 6c 69 74 65 33 49 73 61 6c 6e ine sqlite3Isaln
25940 75 6d 28 78 29 20 20 20 69 73 61 6c 6e 75 6d 28 um(x) isalnum(
25950 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
25960 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c x)).# define sql
25970 69 74 65 33 49 73 61 6c 70 68 61 28 78 29 20 20 ite3Isalpha(x)
25980 20 69 73 61 6c 70 68 61 28 28 75 6e 73 69 67 6e isalpha((unsign
25990 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 ed char)(x)).# d
259a0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 64 efine sqlite3Isd
259b0 69 67 69 74 28 78 29 20 20 20 69 73 64 69 67 69 igit(x) isdigi
259c0 74 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 t((unsigned char
259d0 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 )(x)).# define s
259e0 71 6c 69 74 65 33 49 73 78 64 69 67 69 74 28 78 qlite3Isxdigit(x
259f0 29 20 20 69 73 78 64 69 67 69 74 28 28 75 6e 73 ) isxdigit((uns
25a00 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
25a10 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
25a20 54 6f 6c 6f 77 65 72 28 78 29 20 20 20 74 6f 6c Tolower(x) tol
25a30 6f 77 65 72 28 28 75 6e 73 69 67 6e 65 64 20 63 ower((unsigned c
25a40 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
25a50 65 20 73 71 6c 69 74 65 33 49 73 71 75 6f 74 65 e sqlite3Isquote
25a60 28 78 29 20 20 20 28 28 78 29 3d 3d 27 22 27 7c (x) ((x)=='"'|
25a70 7c 28 78 29 3d 3d 27 5c 27 27 7c 7c 28 78 29 3d |(x)=='\''||(x)=
25a80 3d 27 5b 27 7c 7c 28 78 29 3d 3d 27 60 27 29 0a ='['||(x)=='`').
25a90 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
25aa0 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 4f 4d 50 49 QLITE_OMIT_COMPI
25ab0 4c 45 4f 50 54 49 4f 4e 5f 44 49 41 47 53 0a 69 LEOPTION_DIAGS.i
25ac0 6e 74 20 73 71 6c 69 74 65 33 49 73 49 64 43 68 nt sqlite3IsIdCh
25ad0 61 72 28 75 38 29 3b 0a 23 65 6e 64 69 66 0a 0a ar(u8);.#endif..
25ae0 2f 2a 0a 2a 2a 20 49 6e 74 65 72 6e 61 6c 20 66 /*.** Internal f
25af0 75 6e 63 74 69 6f 6e 20 70 72 6f 74 6f 74 79 70 unction prototyp
25b00 65 73 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 es.*/.int sqlite
25b10 33 53 74 72 49 43 6d 70 28 63 6f 6e 73 74 20 63 3StrICmp(const c
25b20 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
25b30 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 );.int sqlite3St
25b40 72 6c 65 6e 33 30 28 63 6f 6e 73 74 20 63 68 61 rlen30(const cha
25b50 72 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 r*);.char *sqlit
25b60 65 33 43 6f 6c 75 6d 6e 54 79 70 65 28 43 6f 6c e3ColumnType(Col
25b70 75 6d 6e 2a 2c 63 68 61 72 2a 29 3b 0a 23 64 65 umn*,char*);.#de
25b80 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 72 4e fine sqlite3StrN
25b90 49 43 6d 70 20 73 71 6c 69 74 65 33 5f 73 74 72 ICmp sqlite3_str
25ba0 6e 69 63 6d 70 0a 0a 69 6e 74 20 73 71 6c 69 74 nicmp..int sqlit
25bb0 65 33 4d 61 6c 6c 6f 63 49 6e 69 74 28 76 6f 69 e3MallocInit(voi
25bc0 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 d);.void sqlite3
25bd0 4d 61 6c 6c 6f 63 45 6e 64 28 76 6f 69 64 29 3b MallocEnd(void);
25be0 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 4d 61 .void *sqlite3Ma
25bf0 6c 6c 6f 63 28 75 36 34 29 3b 0a 76 6f 69 64 20 lloc(u64);.void
25c00 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 5a 65 *sqlite3MallocZe
25c10 72 6f 28 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 ro(u64);.void *s
25c20 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 qlite3DbMallocZe
25c30 72 6f 28 73 71 6c 69 74 65 33 2a 2c 20 75 36 34 ro(sqlite3*, u64
25c40 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
25c50 44 62 4d 61 6c 6c 6f 63 52 61 77 28 73 71 6c 69 DbMallocRaw(sqli
25c60 74 65 33 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 te3*, u64);.void
25c70 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f *sqlite3DbMallo
25c80 63 52 61 77 4e 4e 28 73 71 6c 69 74 65 33 2a 2c cRawNN(sqlite3*,
25c90 20 75 36 34 29 3b 0a 63 68 61 72 20 2a 73 71 6c u64);.char *sql
25ca0 69 74 65 33 44 62 53 74 72 44 75 70 28 73 71 6c ite3DbStrDup(sql
25cb0 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 ite3*,const char
25cc0 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 *);.char *sqlite
25cd0 33 44 62 53 74 72 4e 44 75 70 28 73 71 6c 69 74 3DbStrNDup(sqlit
25ce0 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c e3*,const char*,
25cf0 20 75 36 34 29 3b 0a 63 68 61 72 20 2a 73 71 6c u64);.char *sql
25d00 69 74 65 33 44 62 53 70 61 6e 44 75 70 28 73 71 ite3DbSpanDup(sq
25d10 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
25d20 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b r*,const char*);
25d30 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 52 65 .void *sqlite3Re
25d40 61 6c 6c 6f 63 28 76 6f 69 64 2a 2c 20 75 36 34 alloc(void*, u64
25d50 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
25d60 44 62 52 65 61 6c 6c 6f 63 4f 72 46 72 65 65 28 DbReallocOrFree(
25d70 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f 69 64 20 sqlite3 *, void
25d80 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 *, u64);.void *s
25d90 71 6c 69 74 65 33 44 62 52 65 61 6c 6c 6f 63 28 qlite3DbRealloc(
25da0 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f 69 64 20 sqlite3 *, void
25db0 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 73 71 *, u64);.void sq
25dc0 6c 69 74 65 33 44 62 46 72 65 65 28 73 71 6c 69 lite3DbFree(sqli
25dd0 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 76 6f te3*, void*);.vo
25de0 69 64 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 id sqlite3DbFree
25df0 4e 4e 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f 69 NN(sqlite3*, voi
25e00 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 d*);.int sqlite3
25e10 4d 61 6c 6c 6f 63 53 69 7a 65 28 76 6f 69 64 2a MallocSize(void*
25e20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 );.int sqlite3Db
25e30 4d 61 6c 6c 6f 63 53 69 7a 65 28 73 71 6c 69 74 MallocSize(sqlit
25e40 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 e3*, void*);.voi
25e50 64 20 2a 73 71 6c 69 74 65 33 50 61 67 65 4d 61 d *sqlite3PageMa
25e60 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f 69 64 20 lloc(int);.void
25e70 73 71 6c 69 74 65 33 50 61 67 65 46 72 65 65 28 sqlite3PageFree(
25e80 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c void*);.void sql
25e90 69 74 65 33 4d 65 6d 53 65 74 44 65 66 61 75 6c ite3MemSetDefaul
25ea0 74 28 76 6f 69 64 29 3b 0a 23 69 66 6e 64 65 66 t(void);.#ifndef
25eb0 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 42 SQLITE_UNTESTAB
25ec0 4c 45 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 LE.void sqlite3B
25ed0 65 6e 69 67 6e 4d 61 6c 6c 6f 63 48 6f 6f 6b 73 enignMallocHooks
25ee0 28 76 6f 69 64 20 28 2a 29 28 76 6f 69 64 29 2c (void (*)(void),
25ef0 20 76 6f 69 64 20 28 2a 29 28 76 6f 69 64 29 29 void (*)(void))
25f00 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c ;.#endif.int sql
25f10 69 74 65 33 48 65 61 70 4e 65 61 72 6c 79 46 75 ite3HeapNearlyFu
25f20 6c 6c 28 76 6f 69 64 29 3b 0a 0a 2f 2a 0a 2a 2a ll(void);../*.**
25f30 20 4f 6e 20 73 79 73 74 65 6d 73 20 77 69 74 68 On systems with
25f40 20 61 6d 70 6c 65 20 73 74 61 63 6b 20 73 70 61 ample stack spa
25f50 63 65 20 61 6e 64 20 74 68 61 74 20 73 75 70 70 ce and that supp
25f60 6f 72 74 20 61 6c 6c 6f 63 61 28 29 2c 20 6d 61 ort alloca(), ma
25f70 6b 65 0a 2a 2a 20 75 73 65 20 6f 66 20 61 6c 6c ke.** use of all
25f80 6f 63 61 28 29 20 74 6f 20 6f 62 74 61 69 6e 20 oca() to obtain
25f90 73 70 61 63 65 20 66 6f 72 20 6c 61 72 67 65 20 space for large
25fa0 61 75 74 6f 6d 61 74 69 63 20 6f 62 6a 65 63 74 automatic object
25fb0 73 2e 20 20 42 79 20 64 65 66 61 75 6c 74 2c 0a s. By default,.
25fc0 2a 2a 20 6f 62 74 61 69 6e 20 73 70 61 63 65 20 ** obtain space
25fd0 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 2e 0a 2a from malloc()..*
25fe0 2a 0a 2a 2a 20 54 68 65 20 61 6c 6c 6f 63 61 28 *.** The alloca(
25ff0 29 20 72 6f 75 74 69 6e 65 20 6e 65 76 65 72 20 ) routine never
26000 72 65 74 75 72 6e 73 20 4e 55 4c 4c 2e 20 20 54 returns NULL. T
26010 68 69 73 20 77 69 6c 6c 20 63 61 75 73 65 20 63 his will cause c
26020 6f 64 65 20 70 61 74 68 73 0a 2a 2a 20 74 68 61 ode paths.** tha
26030 74 20 64 65 61 6c 20 77 69 74 68 20 73 71 6c 69 t deal with sqli
26040 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 28 29 20 te3StackAlloc()
26050 66 61 69 6c 75 72 65 73 20 74 6f 20 62 65 20 75 failures to be u
26060 6e 72 65 61 63 68 61 62 6c 65 2e 0a 2a 2f 0a 23 nreachable..*/.#
26070 69 66 64 65 66 20 53 51 4c 49 54 45 5f 55 53 45 ifdef SQLITE_USE
26080 5f 41 4c 4c 4f 43 41 0a 23 20 64 65 66 69 6e 65 _ALLOCA.# define
26090 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c sqlite3StackAll
260a0 6f 63 52 61 77 28 44 2c 4e 29 20 20 20 61 6c 6c ocRaw(D,N) all
260b0 6f 63 61 28 4e 29 0a 23 20 64 65 66 69 6e 65 20 oca(N).# define
260c0 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f sqlite3StackAllo
260d0 63 5a 65 72 6f 28 44 2c 4e 29 20 20 6d 65 6d 73 cZero(D,N) mems
260e0 65 74 28 61 6c 6c 6f 63 61 28 4e 29 2c 20 30 2c et(alloca(N), 0,
260f0 20 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c N).# define sql
26100 69 74 65 33 53 74 61 63 6b 46 72 65 65 28 44 2c ite3StackFree(D,
26110 50 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e P).#else.# defin
26120 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c e sqlite3StackAl
26130 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 20 73 71 locRaw(D,N) sq
26140 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 lite3DbMallocRaw
26150 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 (D,N).# define s
26160 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 qlite3StackAlloc
26170 5a 65 72 6f 28 44 2c 4e 29 20 20 73 71 6c 69 74 Zero(D,N) sqlit
26180 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 6f 28 44 e3DbMallocZero(D
26190 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ,N).# define sql
261a0 69 74 65 33 53 74 61 63 6b 46 72 65 65 28 44 2c ite3StackFree(D,
261b0 50 29 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 P) sqlite3
261c0 44 62 46 72 65 65 28 44 2c 50 29 0a 23 65 6e 64 DbFree(D,P).#end
261d0 69 66 0a 0a 2f 2a 20 44 6f 20 6e 6f 74 20 61 6c if../* Do not al
261e0 6c 6f 77 20 62 6f 74 68 20 4d 45 4d 53 59 53 35 low both MEMSYS5
261f0 20 61 6e 64 20 4d 45 4d 53 59 53 33 20 74 6f 20 and MEMSYS3 to
26200 62 65 20 64 65 66 69 6e 65 64 20 74 6f 67 65 74 be defined toget
26210 68 65 72 2e 20 20 49 66 20 74 68 65 79 0a 2a 2a her. If they.**
26220 20 61 72 65 2c 20 64 69 73 61 62 6c 65 20 4d 45 are, disable ME
26230 4d 53 59 53 33 0a 2a 2f 0a 23 69 66 64 65 66 20 MSYS3.*/.#ifdef
26240 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 SQLITE_ENABLE_ME
26250 4d 53 59 53 35 0a 63 6f 6e 73 74 20 73 71 6c 69 MSYS5.const sqli
26260 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 te3_mem_methods
26270 2a 73 71 6c 69 74 65 33 4d 65 6d 47 65 74 4d 65 *sqlite3MemGetMe
26280 6d 73 79 73 35 28 76 6f 69 64 29 3b 0a 23 75 6e msys5(void);.#un
26290 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c def SQLITE_ENABL
262a0 45 5f 4d 45 4d 53 59 53 33 0a 23 65 6e 64 69 66 E_MEMSYS3.#endif
262b0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
262c0 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 33 0a 63 6f NABLE_MEMSYS3.co
262d0 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 65 6d 5f nst sqlite3_mem_
262e0 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 74 65 33 methods *sqlite3
262f0 4d 65 6d 47 65 74 4d 65 6d 73 79 73 33 28 76 6f MemGetMemsys3(vo
26300 69 64 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 23 69 id);.#endif...#i
26310 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 55 54 fndef SQLITE_MUT
26320 45 58 5f 4f 4d 49 54 0a 20 20 73 71 6c 69 74 65 EX_OMIT. sqlite
26330 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 3_mutex_methods
26340 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 33 44 65 const *sqlite3De
26350 66 61 75 6c 74 4d 75 74 65 78 28 76 6f 69 64 29 faultMutex(void)
26360 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 ;. sqlite3_mute
26370 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e 73 74 20 x_methods const
26380 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 4d 75 74 65 *sqlite3NoopMute
26390 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 6c 69 74 x(void);. sqlit
263a0 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 e3_mutex *sqlite
263b0 33 4d 75 74 65 78 41 6c 6c 6f 63 28 69 6e 74 29 3MutexAlloc(int)
263c0 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d ;. int sqlite3M
263d0 75 74 65 78 49 6e 69 74 28 76 6f 69 64 29 3b 0a utexInit(void);.
263e0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 74 int sqlite3Mut
263f0 65 78 45 6e 64 28 76 6f 69 64 29 3b 0a 23 65 6e exEnd(void);.#en
26400 64 69 66 0a 23 69 66 20 21 64 65 66 69 6e 65 64 dif.#if !defined
26410 28 53 51 4c 49 54 45 5f 4d 55 54 45 58 5f 4f 4d (SQLITE_MUTEX_OM
26420 49 54 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 IT) && !defined(
26430 53 51 4c 49 54 45 5f 4d 55 54 45 58 5f 4e 4f 4f SQLITE_MUTEX_NOO
26440 50 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 P). void sqlite
26450 33 4d 65 6d 6f 72 79 42 61 72 72 69 65 72 28 76 3MemoryBarrier(v
26460 6f 69 64 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 oid);.#else.# de
26470 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 6f fine sqlite3Memo
26480 72 79 42 61 72 72 69 65 72 28 29 0a 23 65 6e 64 ryBarrier().#end
26490 69 66 0a 0a 73 71 6c 69 74 65 33 5f 69 6e 74 36 if..sqlite3_int6
264a0 34 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 56 4 sqlite3StatusV
264b0 61 6c 75 65 28 69 6e 74 29 3b 0a 76 6f 69 64 20 alue(int);.void
264c0 73 71 6c 69 74 65 33 53 74 61 74 75 73 55 70 28 sqlite3StatusUp(
264d0 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
264e0 73 71 6c 69 74 65 33 53 74 61 74 75 73 44 6f 77 sqlite3StatusDow
264f0 6e 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 n(int, int);.voi
26500 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 48 d sqlite3StatusH
26510 69 67 68 77 61 74 65 72 28 69 6e 74 2c 20 69 6e ighwater(int, in
26520 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4c t);.int sqlite3L
26530 6f 6f 6b 61 73 69 64 65 55 73 65 64 28 73 71 6c ookasideUsed(sql
26540 69 74 65 33 2a 2c 69 6e 74 2a 29 3b 0a 0a 2f 2a ite3*,int*);../*
26550 20 41 63 63 65 73 73 20 74 6f 20 6d 75 74 65 78 Access to mutex
26560 65 73 20 75 73 65 64 20 62 79 20 73 71 6c 69 74 es used by sqlit
26570 65 33 5f 73 74 61 74 75 73 28 29 20 2a 2f 0a 73 e3_status() */.s
26580 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 qlite3_mutex *sq
26590 6c 69 74 65 33 50 63 61 63 68 65 31 4d 75 74 65 lite3Pcache1Mute
265a0 78 28 76 6f 69 64 29 3b 0a 73 71 6c 69 74 65 33 x(void);.sqlite3
265b0 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 4d _mutex *sqlite3M
265c0 61 6c 6c 6f 63 4d 75 74 65 78 28 76 6f 69 64 29 allocMutex(void)
265d0 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 ;..#if defined(S
265e0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 55 4c QLITE_ENABLE_MUL
265f0 54 49 54 48 52 45 41 44 45 44 5f 43 48 45 43 4b TITHREADED_CHECK
26600 53 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 S) && !defined(S
26610 51 4c 49 54 45 5f 4d 55 54 45 58 5f 4f 4d 49 54 QLITE_MUTEX_OMIT
26620 29 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 75 ).void sqlite3Mu
26630 74 65 78 57 61 72 6e 4f 6e 43 6f 6e 74 65 6e 74 texWarnOnContent
26640 69 6f 6e 28 73 71 6c 69 74 65 33 5f 6d 75 74 65 ion(sqlite3_mute
26650 78 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 x*);.#else.# def
26660 69 6e 65 20 73 71 6c 69 74 65 33 4d 75 74 65 78 ine sqlite3Mutex
26670 57 61 72 6e 4f 6e 43 6f 6e 74 65 6e 74 69 6f 6e WarnOnContention
26680 28 78 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 6e (x).#endif..#ifn
26690 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
266a0 46 4c 4f 41 54 49 4e 47 5f 50 4f 49 4e 54 0a 20 FLOATING_POINT.
266b0 20 69 6e 74 20 73 71 6c 69 74 65 33 49 73 4e 61 int sqlite3IsNa
266c0 4e 28 64 6f 75 62 6c 65 29 3b 0a 23 65 6c 73 65 N(double);.#else
266d0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
266e0 33 49 73 4e 61 4e 28 58 29 20 20 30 0a 23 65 6e 3IsNaN(X) 0.#en
266f0 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e dif../*.** An in
26700 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f stance of the fo
26710 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 llowing structur
26720 65 20 68 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 74 e holds informat
26730 69 6f 6e 20 61 62 6f 75 74 20 53 51 4c 0a 2a 2a ion about SQL.**
26740 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 67 75 6d functions argum
26750 65 6e 74 73 20 74 68 61 74 20 61 72 65 20 74 68 ents that are th
26760 65 20 70 61 72 61 6d 65 74 65 72 73 20 74 6f 20 e parameters to
26770 74 68 65 20 70 72 69 6e 74 66 28 29 20 66 75 6e the printf() fun
26780 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 ction..*/.struct
26790 20 50 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 PrintfArguments
267a0 20 7b 0a 20 20 69 6e 74 20 6e 41 72 67 3b 20 20 {. int nArg;
267b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
267c0 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 Total number of
267d0 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a 20 20 arguments */.
267e0 69 6e 74 20 6e 55 73 65 64 3b 20 20 20 20 20 20 int nUsed;
267f0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
26800 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 er of arguments
26810 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a 20 used so far */.
26820 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a sqlite3_value *
26830 2a 61 70 41 72 67 3b 20 20 20 2f 2a 20 54 68 65 *apArg; /* The
26840 20 61 72 67 75 6d 65 6e 74 20 76 61 6c 75 65 73 argument values
26850 20 2a 2f 0a 7d 3b 0a 0a 76 6f 69 64 20 73 71 6c */.};..void sql
26860 69 74 65 33 56 58 50 72 69 6e 74 66 28 53 74 72 ite3VXPrintf(Str
26870 41 63 63 75 6d 2a 2c 20 63 6f 6e 73 74 20 63 68 Accum*, const ch
26880 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b 0a 76 ar*, va_list);.v
26890 6f 69 64 20 73 71 6c 69 74 65 33 58 50 72 69 6e oid sqlite3XPrin
268a0 74 66 28 53 74 72 41 63 63 75 6d 2a 2c 20 63 6f tf(StrAccum*, co
268b0 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b nst char*, ...);
268c0 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4d 50 .char *sqlite3MP
268d0 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 rintf(sqlite3*,c
268e0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 onst char*, ...)
268f0 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 56 ;.char *sqlite3V
26900 4d 50 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a MPrintf(sqlite3*
26910 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 ,const char*, va
26920 5f 6c 69 73 74 29 3b 0a 23 69 66 20 64 65 66 69 _list);.#if defi
26930 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
26940 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c ) || defined(SQL
26950 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 ITE_HAVE_OS_TRAC
26960 45 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 E). void sqlite
26970 33 44 65 62 75 67 50 72 69 6e 74 66 28 63 6f 6e 3DebugPrintf(con
26980 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a st char*, ...);.
26990 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e #endif.#if defin
269a0 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a ed(SQLITE_TEST).
269b0 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 54 void *sqlite3T
269c0 65 73 74 54 65 78 74 54 6f 50 74 72 28 63 6f 6e estTextToPtr(con
269d0 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 st char*);.#endi
269e0 66 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 f..#if defined(S
269f0 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 20 76 QLITE_DEBUG). v
26a00 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 oid sqlite3TreeV
26a10 69 65 77 45 78 70 72 28 54 72 65 65 56 69 65 77 iewExpr(TreeView
26a20 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 *, const Expr*,
26a30 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 u8);. void sqli
26a40 74 65 33 54 72 65 65 56 69 65 77 42 61 72 65 45 te3TreeViewBareE
26a50 78 70 72 4c 69 73 74 28 54 72 65 65 56 69 65 77 xprList(TreeView
26a60 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 4c 69 73 *, const ExprLis
26a70 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 t*, const char*)
26a80 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
26a90 54 72 65 65 56 69 65 77 45 78 70 72 4c 69 73 74 TreeViewExprList
26aa0 28 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 (TreeView*, cons
26ab0 74 20 45 78 70 72 4c 69 73 74 2a 2c 20 75 38 2c t ExprList*, u8,
26ac0 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 const char*);.
26ad0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 void sqlite3Tre
26ae0 65 56 69 65 77 53 65 6c 65 63 74 28 54 72 65 65 eViewSelect(Tree
26af0 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 53 65 6c View*, const Sel
26b00 65 63 74 2a 2c 20 75 38 29 3b 0a 20 20 76 6f 69 ect*, u8);. voi
26b10 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 65 d sqlite3TreeVie
26b20 77 57 69 74 68 28 54 72 65 65 56 69 65 77 2a 2c wWith(TreeView*,
26b30 20 63 6f 6e 73 74 20 57 69 74 68 2a 2c 20 75 38 const With*, u8
26b40 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 76 6f 69 64 );.#endif...void
26b50 20 73 71 6c 69 74 65 33 53 65 74 53 74 72 69 6e sqlite3SetStrin
26b60 67 28 63 68 61 72 20 2a 2a 2c 20 73 71 6c 69 74 g(char **, sqlit
26b70 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a e3*, const char*
26b80 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
26b90 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c 20 rrorMsg(Parse*,
26ba0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e const char*, ...
26bb0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
26bc0 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 0a 76 equote(char*);.v
26bd0 6f 69 64 20 73 71 6c 69 74 65 33 54 6f 6b 65 6e oid sqlite3Token
26be0 49 6e 69 74 28 54 6f 6b 65 6e 2a 2c 63 68 61 72 Init(Token*,char
26bf0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b *);.int sqlite3K
26c00 65 79 77 6f 72 64 43 6f 64 65 28 63 6f 6e 73 74 eywordCode(const
26c10 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 2c unsigned char*,
26c20 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
26c30 65 33 52 75 6e 50 61 72 73 65 72 28 50 61 72 73 e3RunParser(Pars
26c40 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c e*, const char*,
26c50 20 63 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 20 char **);.void
26c60 73 71 6c 69 74 65 33 46 69 6e 69 73 68 43 6f 64 sqlite3FinishCod
26c70 69 6e 67 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 ing(Parse*);.int
26c80 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d 70 52 sqlite3GetTempR
26c90 65 67 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 eg(Parse*);.void
26ca0 20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 sqlite3ReleaseT
26cb0 65 6d 70 52 65 67 28 50 61 72 73 65 2a 2c 69 6e empReg(Parse*,in
26cc0 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 t);.int sqlite3G
26cd0 65 74 54 65 6d 70 52 61 6e 67 65 28 50 61 72 73 etTempRange(Pars
26ce0 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 e*,int);.void sq
26cf0 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 lite3ReleaseTemp
26d00 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e 74 Range(Parse*,int
26d10 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
26d20 74 65 33 43 6c 65 61 72 54 65 6d 70 52 65 67 43 te3ClearTempRegC
26d30 61 63 68 65 28 50 61 72 73 65 2a 29 3b 0a 23 69 ache(Parse*);.#i
26d40 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 fdef SQLITE_DEBU
26d50 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f 54 G.int sqlite3NoT
26d60 65 6d 70 73 49 6e 52 61 6e 67 65 28 50 61 72 73 empsInRange(Pars
26d70 65 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 23 65 6e e*,int,int);.#en
26d80 64 69 66 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 dif.Expr *sqlite
26d90 33 45 78 70 72 41 6c 6c 6f 63 28 73 71 6c 69 74 3ExprAlloc(sqlit
26da0 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 54 6f e3*,int,const To
26db0 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 45 78 70 72 20 ken*,int);.Expr
26dc0 2a 73 71 6c 69 74 65 33 45 78 70 72 28 73 71 6c *sqlite3Expr(sql
26dd0 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 ite3*,int,const
26de0 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c char*);.void sql
26df0 69 74 65 33 45 78 70 72 41 74 74 61 63 68 53 75 ite3ExprAttachSu
26e00 62 74 72 65 65 73 28 73 71 6c 69 74 65 33 2a 2c btrees(sqlite3*,
26e10 45 78 70 72 2a 2c 45 78 70 72 2a 2c 45 78 70 72 Expr*,Expr*,Expr
26e20 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 *);.Expr *sqlite
26e30 33 50 45 78 70 72 28 50 61 72 73 65 2a 2c 20 69 3PExpr(Parse*, i
26e40 6e 74 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a nt, Expr*, Expr*
26e50 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
26e60 45 78 70 72 41 64 64 53 65 6c 65 63 74 28 50 61 ExprAddSelect(Pa
26e70 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 53 65 6c rse*, Expr*, Sel
26e80 65 63 74 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c ect*);.Expr *sql
26e90 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 6c 69 ite3ExprAnd(sqli
26ea0 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 te3*,Expr*, Expr
26eb0 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 *);.Expr *sqlite
26ec0 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 50 61 3ExprFunction(Pa
26ed0 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 20 rse*,ExprList*,
26ee0 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 Token*);.void sq
26ef0 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 6e 56 lite3ExprAssignV
26f00 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 2a 2c arNumber(Parse*,
26f10 20 45 78 70 72 2a 2c 20 75 33 32 29 3b 0a 76 6f Expr*, u32);.vo
26f20 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 44 65 id sqlite3ExprDe
26f30 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 45 lete(sqlite3*, E
26f40 78 70 72 2a 29 3b 0a 45 78 70 72 4c 69 73 74 20 xpr*);.ExprList
26f50 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 *sqlite3ExprList
26f60 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c 45 78 Append(Parse*,Ex
26f70 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 29 3b 0a prList*,Expr*);.
26f80 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 65 ExprList *sqlite
26f90 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e 64 56 3ExprListAppendV
26fa0 65 63 74 6f 72 28 50 61 72 73 65 2a 2c 45 78 70 ector(Parse*,Exp
26fb0 72 4c 69 73 74 2a 2c 49 64 4c 69 73 74 2a 2c 45 rList*,IdList*,E
26fc0 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
26fd0 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 53 6f te3ExprListSetSo
26fe0 72 74 4f 72 64 65 72 28 45 78 70 72 4c 69 73 74 rtOrder(ExprList
26ff0 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c *,int);.void sql
27000 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 4e ite3ExprListSetN
27010 61 6d 65 28 50 61 72 73 65 2a 2c 45 78 70 72 4c ame(Parse*,ExprL
27020 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 29 ist*,Token*,int)
27030 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
27040 70 72 4c 69 73 74 53 65 74 53 70 61 6e 28 50 61 prListSetSpan(Pa
27050 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 63 rse*,ExprList*,c
27060 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 onst char*,const
27070 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 char*);.void sq
27080 6c 69 74 65 33 45 78 70 72 4c 69 73 74 44 65 6c lite3ExprListDel
27090 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 45 78 ete(sqlite3*, Ex
270a0 70 72 4c 69 73 74 2a 29 3b 0a 75 33 32 20 73 71 prList*);.u32 sq
270b0 6c 69 74 65 33 45 78 70 72 4c 69 73 74 46 6c 61 lite3ExprListFla
270c0 67 73 28 63 6f 6e 73 74 20 45 78 70 72 4c 69 73 gs(const ExprLis
270d0 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
270e0 49 6e 69 74 28 73 71 6c 69 74 65 33 2a 2c 20 63 Init(sqlite3*, c
270f0 68 61 72 2a 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 har**);.int sqli
27100 74 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b 28 te3InitCallback(
27110 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 63 68 61 72 void*, int, char
27120 2a 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a 76 6f 69 **, char**);.voi
27130 64 20 73 71 6c 69 74 65 33 50 72 61 67 6d 61 28 d sqlite3Pragma(
27140 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f Parse*,Token*,To
27150 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 29 ken*,Token*,int)
27160 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
27170 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
27180 4c 45 0a 4d 6f 64 75 6c 65 20 2a 73 71 6c 69 74 LE.Module *sqlit
27190 65 33 50 72 61 67 6d 61 56 74 61 62 52 65 67 69 e3PragmaVtabRegi
271a0 73 74 65 72 28 73 71 6c 69 74 65 33 2a 2c 63 6f ster(sqlite3*,co
271b0 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 29 nst char *zName)
271c0 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 ;.#endif.void sq
271d0 6c 69 74 65 33 52 65 73 65 74 41 6c 6c 53 63 68 lite3ResetAllSch
271e0 65 6d 61 73 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e emasOfConnection
271f0 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
27200 20 73 71 6c 69 74 65 33 52 65 73 65 74 4f 6e 65 sqlite3ResetOne
27210 53 63 68 65 6d 61 28 73 71 6c 69 74 65 33 2a 2c Schema(sqlite3*,
27220 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
27230 65 33 43 6f 6c 6c 61 70 73 65 44 61 74 61 62 61 e3CollapseDataba
27240 73 65 41 72 72 61 79 28 73 71 6c 69 74 65 33 2a seArray(sqlite3*
27250 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
27260 6f 6d 6d 69 74 49 6e 74 65 72 6e 61 6c 43 68 61 ommitInternalCha
27270 6e 67 65 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a nges(sqlite3*);.
27280 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 void sqlite3Dele
27290 74 65 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 73 71 teColumnNames(sq
272a0 6c 69 74 65 33 2a 2c 54 61 62 6c 65 2a 29 3b 0a lite3*,Table*);.
272b0 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d int sqlite3Colum
272c0 6e 73 46 72 6f 6d 45 78 70 72 4c 69 73 74 28 50 nsFromExprList(P
272d0 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c arse*,ExprList*,
272e0 69 31 36 2a 2c 43 6f 6c 75 6d 6e 2a 2a 29 3b 0a i16*,Column**);.
272f0 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 void sqlite3Sele
27300 63 74 41 64 64 43 6f 6c 75 6d 6e 54 79 70 65 41 ctAddColumnTypeA
27310 6e 64 43 6f 6c 6c 61 74 69 6f 6e 28 50 61 72 73 ndCollation(Pars
27320 65 2a 2c 54 61 62 6c 65 2a 2c 53 65 6c 65 63 74 e*,Table*,Select
27330 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 *);.Table *sqlit
27340 65 33 52 65 73 75 6c 74 53 65 74 4f 66 53 65 6c e3ResultSetOfSel
27350 65 63 74 28 50 61 72 73 65 2a 2c 53 65 6c 65 63 ect(Parse*,Selec
27360 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 t*);.void sqlite
27370 33 4f 70 65 6e 4d 61 73 74 65 72 54 61 62 6c 65 3OpenMasterTable
27380 28 50 61 72 73 65 20 2a 2c 20 69 6e 74 29 3b 0a (Parse *, int);.
27390 49 6e 64 65 78 20 2a 73 71 6c 69 74 65 33 50 72 Index *sqlite3Pr
273a0 69 6d 61 72 79 4b 65 79 49 6e 64 65 78 28 54 61 imaryKeyIndex(Ta
273b0 62 6c 65 2a 29 3b 0a 69 31 36 20 73 71 6c 69 74 ble*);.i16 sqlit
273c0 65 33 43 6f 6c 75 6d 6e 4f 66 49 6e 64 65 78 28 e3ColumnOfIndex(
273d0 49 6e 64 65 78 2a 2c 20 69 31 36 29 3b 0a 76 6f Index*, i16);.vo
273e0 69 64 20 73 71 6c 69 74 65 33 53 74 61 72 74 54 id sqlite3StartT
273f0 61 62 6c 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 able(Parse*,Toke
27400 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e n*,Token*,int,in
27410 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a 23 69 66 20 t,int,int);.#if
27420 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 48 49 SQLITE_ENABLE_HI
27430 44 44 45 4e 5f 43 4f 4c 55 4d 4e 53 0a 20 20 76 DDEN_COLUMNS. v
27440 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d oid sqlite3Colum
27450 6e 50 72 6f 70 65 72 74 69 65 73 46 72 6f 6d 4e nPropertiesFromN
27460 61 6d 65 28 54 61 62 6c 65 2a 2c 20 43 6f 6c 75 ame(Table*, Colu
27470 6d 6e 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 mn*);.#else.# de
27480 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6c 75 fine sqlite3Colu
27490 6d 6e 50 72 6f 70 65 72 74 69 65 73 46 72 6f 6d mnPropertiesFrom
274a0 4e 61 6d 65 28 54 2c 43 29 20 2f 2a 20 6e 6f 2d Name(T,C) /* no-
274b0 6f 70 20 2a 2f 0a 23 65 6e 64 69 66 0a 76 6f 69 op */.#endif.voi
274c0 64 20 73 71 6c 69 74 65 33 41 64 64 43 6f 6c 75 d sqlite3AddColu
274d0 6d 6e 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a mn(Parse*,Token*
274e0 2c 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 ,Token*);.void s
274f0 71 6c 69 74 65 33 41 64 64 4e 6f 74 4e 75 6c 6c qlite3AddNotNull
27500 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 (Parse*, int);.v
27510 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 50 72 oid sqlite3AddPr
27520 69 6d 61 72 79 4b 65 79 28 50 61 72 73 65 2a 2c imaryKey(Parse*,
27530 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c ExprList*, int,
27540 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
27550 20 73 71 6c 69 74 65 33 41 64 64 43 68 65 63 6b sqlite3AddCheck
27560 43 6f 6e 73 74 72 61 69 6e 74 28 50 61 72 73 65 Constraint(Parse
27570 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 *, Expr*);.void
27580 73 71 6c 69 74 65 33 41 64 64 44 65 66 61 75 6c sqlite3AddDefaul
27590 74 56 61 6c 75 65 28 50 61 72 73 65 2a 2c 45 78 tValue(Parse*,Ex
275a0 70 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c pr*,const char*,
275b0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f const char*);.vo
275c0 69 64 20 73 71 6c 69 74 65 33 41 64 64 43 6f 6c id sqlite3AddCol
275d0 6c 61 74 65 54 79 70 65 28 50 61 72 73 65 2a 2c lateType(Parse*,
275e0 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
275f0 71 6c 69 74 65 33 45 6e 64 54 61 62 6c 65 28 50 qlite3EndTable(P
27600 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b arse*,Token*,Tok
27610 65 6e 2a 2c 75 38 2c 53 65 6c 65 63 74 2a 29 3b en*,u8,Select*);
27620 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 72 73 .int sqlite3Pars
27630 65 55 72 69 28 63 6f 6e 73 74 20 63 68 61 72 2a eUri(const char*
27640 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 6e 73 ,const char*,uns
27650 69 67 6e 65 64 20 69 6e 74 2a 2c 0a 20 20 20 20 igned int*,.
27660 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
27670 73 71 6c 69 74 65 33 5f 76 66 73 2a 2a 2c 63 68 sqlite3_vfs**,ch
27680 61 72 2a 2a 2c 63 68 61 72 20 2a 2a 29 3b 0a 42 ar**,char **);.B
27690 74 72 65 65 20 2a 73 71 6c 69 74 65 33 44 62 4e tree *sqlite3DbN
276a0 61 6d 65 54 6f 42 74 72 65 65 28 73 71 6c 69 74 ameToBtree(sqlit
276b0 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 e3*,const char*)
276c0 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
276d0 5f 55 4e 54 45 53 54 41 42 4c 45 0a 23 20 64 65 _UNTESTABLE.# de
276e0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 61 75 6c fine sqlite3Faul
276f0 74 53 69 6d 28 58 29 20 53 51 4c 49 54 45 5f 4f tSim(X) SQLITE_O
27700 4b 0a 23 65 6c 73 65 0a 20 20 69 6e 74 20 73 71 K.#else. int sq
27710 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 69 6e lite3FaultSim(in
27720 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 42 69 74 76 t);.#endif..Bitv
27730 65 63 20 2a 73 71 6c 69 74 65 33 42 69 74 76 65 ec *sqlite3Bitve
27740 63 43 72 65 61 74 65 28 75 33 32 29 3b 0a 69 6e cCreate(u32);.in
27750 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 54 t sqlite3BitvecT
27760 65 73 74 28 42 69 74 76 65 63 2a 2c 20 75 33 32 est(Bitvec*, u32
27770 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 69 );.int sqlite3Bi
27780 74 76 65 63 54 65 73 74 4e 6f 74 4e 75 6c 6c 28 tvecTestNotNull(
27790 42 69 74 76 65 63 2a 2c 20 75 33 32 29 3b 0a 69 Bitvec*, u32);.i
277a0 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
277b0 53 65 74 28 42 69 74 76 65 63 2a 2c 20 75 33 32 Set(Bitvec*, u32
277c0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 );.void sqlite3B
277d0 69 74 76 65 63 43 6c 65 61 72 28 42 69 74 76 65 itvecClear(Bitve
277e0 63 2a 2c 20 75 33 32 2c 20 76 6f 69 64 2a 29 3b c*, u32, void*);
277f0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 69 74 .void sqlite3Bit
27800 76 65 63 44 65 73 74 72 6f 79 28 42 69 74 76 65 vecDestroy(Bitve
27810 63 2a 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 c*);.u32 sqlite3
27820 42 69 74 76 65 63 53 69 7a 65 28 42 69 74 76 65 BitvecSize(Bitve
27830 63 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c c*);.#ifndef SQL
27840 49 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a 69 ITE_UNTESTABLE.i
27850 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
27860 42 75 69 6c 74 69 6e 54 65 73 74 28 69 6e 74 2c BuiltinTest(int,
27870 69 6e 74 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 52 int*);.#endif..R
27880 6f 77 53 65 74 20 2a 73 71 6c 69 74 65 33 52 6f owSet *sqlite3Ro
27890 77 53 65 74 49 6e 69 74 28 73 71 6c 69 74 65 33 wSetInit(sqlite3
278a0 2a 2c 20 76 6f 69 64 2a 2c 20 75 6e 73 69 67 6e *, void*, unsign
278b0 65 64 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 ed int);.void sq
278c0 6c 69 74 65 33 52 6f 77 53 65 74 43 6c 65 61 72 lite3RowSetClear
278d0 28 52 6f 77 53 65 74 2a 29 3b 0a 76 6f 69 64 20 (RowSet*);.void
278e0 73 71 6c 69 74 65 33 52 6f 77 53 65 74 49 6e 73 sqlite3RowSetIns
278f0 65 72 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 ert(RowSet*, i64
27900 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f );.int sqlite3Ro
27910 77 53 65 74 54 65 73 74 28 52 6f 77 53 65 74 2a wSetTest(RowSet*
27920 2c 20 69 6e 74 20 69 42 61 74 63 68 2c 20 69 36 , int iBatch, i6
27930 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 4);.int sqlite3R
27940 6f 77 53 65 74 4e 65 78 74 28 52 6f 77 53 65 74 owSetNext(RowSet
27950 2a 2c 20 69 36 34 2a 29 3b 0a 0a 76 6f 69 64 20 *, i64*);..void
27960 73 71 6c 69 74 65 33 43 72 65 61 74 65 56 69 65 sqlite3CreateVie
27970 77 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c w(Parse*,Token*,
27980 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 Token*,Token*,Ex
27990 70 72 4c 69 73 74 2a 2c 53 65 6c 65 63 74 2a 2c prList*,Select*,
279a0 69 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 66 20 21 int,int);..#if !
279b0 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f defined(SQLITE_O
279c0 4d 49 54 5f 56 49 45 57 29 20 7c 7c 20 21 64 65 MIT_VIEW) || !de
279d0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 fined(SQLITE_OMI
279e0 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 0a T_VIRTUALTABLE).
279f0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 69 65 int sqlite3Vie
27a00 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 wGetColumnNames(
27a10 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a Parse*,Table*);.
27a20 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
27a30 71 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f 6c qlite3ViewGetCol
27a40 75 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 20 30 0a umnNames(A,B) 0.
27a50 23 65 6e 64 69 66 0a 0a 23 69 66 20 53 51 4c 49 #endif..#if SQLI
27a60 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 3e TE_MAX_ATTACHED>
27a70 33 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 30. int sqlite3
27a80 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 79 44 DbMaskAllZero(yD
27a90 62 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 66 0a 76 bMask);.#endif.v
27aa0 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 54 oid sqlite3DropT
27ab0 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 63 able(Parse*, Src
27ac0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 List*, int, int)
27ad0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f ;.void sqlite3Co
27ae0 64 65 44 72 6f 70 54 61 62 6c 65 28 50 61 72 73 deDropTable(Pars
27af0 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
27b00 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
27b10 74 65 33 44 65 6c 65 74 65 54 61 62 6c 65 28 73 te3DeleteTable(s
27b20 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 qlite3*, Table*)
27b30 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
27b40 5f 4f 4d 49 54 5f 41 55 54 4f 49 4e 43 52 45 4d _OMIT_AUTOINCREM
27b50 45 4e 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 ENT. void sqlit
27b60 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 42 e3AutoincrementB
27b70 65 67 69 6e 28 50 61 72 73 65 20 2a 70 50 61 72 egin(Parse *pPar
27b80 73 65 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 se);. void sqli
27b90 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 te3Autoincrement
27ba0 45 6e 64 28 50 61 72 73 65 20 2a 70 50 61 72 73 End(Parse *pPars
27bb0 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 e);.#else.# defi
27bc0 6e 65 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e ne sqlite3Autoin
27bd0 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 58 29 0a crementBegin(X).
27be0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
27bf0 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 45 6e 64 AutoincrementEnd
27c00 28 58 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 (X).#endif.void
27c10 73 71 6c 69 74 65 33 49 6e 73 65 72 74 28 50 61 sqlite3Insert(Pa
27c20 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 rse*, SrcList*,
27c30 53 65 6c 65 63 74 2a 2c 20 49 64 4c 69 73 74 2a Select*, IdList*
27c40 2c 20 69 6e 74 2c 20 55 70 73 65 72 74 2a 29 3b , int, Upsert*);
27c50 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 41 72 .void *sqlite3Ar
27c60 72 61 79 41 6c 6c 6f 63 61 74 65 28 73 71 6c 69 rayAllocate(sqli
27c70 74 65 33 2a 2c 76 6f 69 64 2a 2c 69 6e 74 2c 69 te3*,void*,int,i
27c80 6e 74 2a 2c 69 6e 74 2a 29 3b 0a 49 64 4c 69 73 nt*,int*);.IdLis
27c90 74 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 74 t *sqlite3IdList
27ca0 41 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c Append(sqlite3*,
27cb0 20 49 64 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a IdList*, Token*
27cc0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 64 );.int sqlite3Id
27cd0 4c 69 73 74 49 6e 64 65 78 28 49 64 4c 69 73 74 ListIndex(IdList
27ce0 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a *,const char*);.
27cf0 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 SrcList *sqlite3
27d00 53 72 63 4c 69 73 74 45 6e 6c 61 72 67 65 28 73 SrcListEnlarge(s
27d10 71 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 74 qlite3*, SrcList
27d20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 53 72 *, int, int);.Sr
27d30 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 cList *sqlite3Sr
27d40 63 4c 69 73 74 41 70 70 65 6e 64 28 73 71 6c 69 cListAppend(sqli
27d50 74 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 te3*, SrcList*,
27d60 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b Token*, Token*);
27d70 0a 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 .SrcList *sqlite
27d80 33 53 72 63 4c 69 73 74 41 70 70 65 6e 64 46 72 3SrcListAppendFr
27d90 6f 6d 54 65 72 6d 28 50 61 72 73 65 2a 2c 20 53 omTerm(Parse*, S
27da0 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c rcList*, Token*,
27db0 20 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 Token*,.
27dc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
27dd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 T
27de0 6f 6b 65 6e 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 oken*, Select*,
27df0 45 78 70 72 2a 2c 20 49 64 4c 69 73 74 2a 29 3b Expr*, IdList*);
27e00 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 .void sqlite3Src
27e10 4c 69 73 74 49 6e 64 65 78 65 64 42 79 28 50 61 ListIndexedBy(Pa
27e20 72 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a rse *, SrcList *
27e30 2c 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 , Token *);.void
27e40 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 46 sqlite3SrcListF
27e50 75 6e 63 41 72 67 73 28 50 61 72 73 65 2a 2c 20 uncArgs(Parse*,
27e60 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 SrcList*, ExprLi
27e70 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 st*);.int sqlite
27e80 33 49 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 3IndexedByLookup
27e90 28 50 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 (Parse *, struct
27ea0 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 SrcList_item *)
27eb0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 ;.void sqlite3Sr
27ec0 63 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 cListShiftJoinTy
27ed0 70 65 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f pe(SrcList*);.vo
27ee0 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 id sqlite3SrcLis
27ef0 74 41 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 tAssignCursors(P
27f00 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 arse*, SrcList*)
27f10 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 ;.void sqlite3Id
27f20 4c 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 ListDelete(sqlit
27f30 65 33 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 e3*, IdList*);.v
27f40 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 oid sqlite3SrcLi
27f50 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
27f60 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e *, SrcList*);.In
27f70 64 65 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f dex *sqlite3Allo
27f80 63 61 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 cateIndexObject(
27f90 73 71 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 sqlite3*,i16,int
27fa0 2c 63 68 61 72 2a 2a 29 3b 0a 76 6f 69 64 20 73 ,char**);.void s
27fb0 71 6c 69 74 65 33 43 72 65 61 74 65 49 6e 64 65 qlite3CreateInde
27fc0 78 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c x(Parse*,Token*,
27fd0 54 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 2a 2c Token*,SrcList*,
27fe0 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 54 6f ExprList*,int,To
27ff0 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 ken*,.
28000 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28010 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c Expr*, int, int,
28020 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 u8);.void sqlit
28030 65 33 44 72 6f 70 49 6e 64 65 78 28 50 61 72 73 e3DropIndex(Pars
28040 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e e*, SrcList*, in
28050 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 t);.int sqlite3S
28060 65 6c 65 63 74 28 50 61 72 73 65 2a 2c 20 53 65 elect(Parse*, Se
28070 6c 65 63 74 2a 2c 20 53 65 6c 65 63 74 44 65 73 lect*, SelectDes
28080 74 2a 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c t*);.Select *sql
28090 69 74 65 33 53 65 6c 65 63 74 4e 65 77 28 50 61 ite3SelectNew(Pa
280a0 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 rse*,ExprList*,S
280b0 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 rcList*,Expr*,Ex
280c0 70 72 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 prList*,.
280d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
280e0 20 20 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 Expr*,ExprList
280f0 2a 2c 75 33 32 2c 45 78 70 72 2a 29 3b 0a 76 6f *,u32,Expr*);.vo
28100 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 id sqlite3Select
28110 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c Delete(sqlite3*,
28120 20 53 65 6c 65 63 74 2a 29 3b 0a 54 61 62 6c 65 Select*);.Table
28130 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 *sqlite3SrcList
28140 4c 6f 6f 6b 75 70 28 50 61 72 73 65 2a 2c 20 53 Lookup(Parse*, S
28150 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 rcList*);.int sq
28160 6c 69 74 65 33 49 73 52 65 61 64 4f 6e 6c 79 28 lite3IsReadOnly(
28170 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 Parse*, Table*,
28180 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
28190 65 33 4f 70 65 6e 54 61 62 6c 65 28 50 61 72 73 e3OpenTable(Pars
281a0 65 2a 2c 20 69 6e 74 20 69 43 75 72 2c 20 69 6e e*, int iCur, in
281b0 74 20 69 44 62 2c 20 54 61 62 6c 65 2a 2c 20 69 t iDb, Table*, i
281c0 6e 74 29 3b 0a 23 69 66 20 64 65 66 69 6e 65 64 nt);.#if defined
281d0 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 (SQLITE_ENABLE_U
281e0 50 44 41 54 45 5f 44 45 4c 45 54 45 5f 4c 49 4d PDATE_DELETE_LIM
281f0 49 54 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 IT) && !defined(
28200 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 55 42 51 SQLITE_OMIT_SUBQ
28210 55 45 52 59 29 0a 45 78 70 72 20 2a 73 71 6c 69 UERY).Expr *sqli
28220 74 65 33 4c 69 6d 69 74 57 68 65 72 65 28 50 61 te3LimitWhere(Pa
28230 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 78 rse*,SrcList*,Ex
28240 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 45 78 pr*,ExprList*,Ex
28250 70 72 2a 2c 63 68 61 72 2a 29 3b 0a 23 65 6e 64 pr*,char*);.#end
28260 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 if.void sqlite3D
28270 65 6c 65 74 65 46 72 6f 6d 28 50 61 72 73 65 2a eleteFrom(Parse*
28280 2c 20 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 , SrcList*, Expr
28290 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 *, ExprList*, Ex
282a0 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 pr*);.void sqlit
282b0 65 33 55 70 64 61 74 65 28 50 61 72 73 65 2a 2c e3Update(Parse*,
282c0 20 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 4c SrcList*, ExprL
282d0 69 73 74 2a 2c 45 78 70 72 2a 2c 69 6e 74 2c 45 ist*,Expr*,int,E
282e0 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 29 3b xprList*,Expr*);
282f0 0a 57 68 65 72 65 49 6e 66 6f 20 2a 73 71 6c 69 .WhereInfo *sqli
28300 74 65 33 57 68 65 72 65 42 65 67 69 6e 28 50 61 te3WhereBegin(Pa
28310 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 78 rse*,SrcList*,Ex
28320 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 45 78 pr*,ExprList*,Ex
28330 70 72 4c 69 73 74 2a 2c 75 31 36 2c 69 6e 74 29 prList*,u16,int)
28340 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 57 68 ;.void sqlite3Wh
28350 65 72 65 45 6e 64 28 57 68 65 72 65 49 6e 66 6f ereEnd(WhereInfo
28360 2a 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 74 *);.LogEst sqlit
28370 65 33 57 68 65 72 65 4f 75 74 70 75 74 52 6f 77 e3WhereOutputRow
28380 43 6f 75 6e 74 28 57 68 65 72 65 49 6e 66 6f 2a Count(WhereInfo*
28390 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 );.int sqlite3Wh
283a0 65 72 65 49 73 44 69 73 74 69 6e 63 74 28 57 68 ereIsDistinct(Wh
283b0 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 ereInfo*);.int s
283c0 71 6c 69 74 65 33 57 68 65 72 65 49 73 4f 72 64 qlite3WhereIsOrd
283d0 65 72 65 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 ered(WhereInfo*)
283e0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
283f0 72 65 4f 72 64 65 72 65 64 49 6e 6e 65 72 4c 6f reOrderedInnerLo
28400 6f 70 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a op(WhereInfo*);.
28410 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 int sqlite3Where
28420 49 73 53 6f 72 74 65 64 28 57 68 65 72 65 49 6e IsSorted(WhereIn
28430 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 fo*);.int sqlite
28440 33 57 68 65 72 65 43 6f 6e 74 69 6e 75 65 4c 61 3WhereContinueLa
28450 62 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b bel(WhereInfo*);
28460 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
28470 65 42 72 65 61 6b 4c 61 62 65 6c 28 57 68 65 72 eBreakLabel(Wher
28480 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
28490 69 74 65 33 57 68 65 72 65 4f 6b 4f 6e 65 50 61 ite3WhereOkOnePa
284a0 73 73 28 57 68 65 72 65 49 6e 66 6f 2a 2c 20 69 ss(WhereInfo*, i
284b0 6e 74 2a 29 3b 0a 23 64 65 66 69 6e 65 20 4f 4e nt*);.#define ON
284c0 45 50 41 53 53 5f 4f 46 46 20 20 20 20 20 20 30 EPASS_OFF 0
284d0 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 20 6f /* Use o
284e0 66 20 4f 4e 45 50 41 53 53 20 6e 6f 74 20 61 6c f ONEPASS not al
284f0 6c 6f 77 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 lowed */.#define
28500 20 4f 4e 45 50 41 53 53 5f 53 49 4e 47 4c 45 20 ONEPASS_SINGLE
28510 20 20 31 20 20 20 20 20 20 20 20 2f 2a 20 4f 4e 1 /* ON
28520 45 50 41 53 53 20 76 61 6c 69 64 20 66 6f 72 20 EPASS valid for
28530 61 20 73 69 6e 67 6c 65 20 72 6f 77 20 75 70 64 a single row upd
28540 61 74 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ate */.#define O
28550 4e 45 50 41 53 53 5f 4d 55 4c 54 49 20 20 20 20 NEPASS_MULTI
28560 32 20 20 20 20 20 20 20 20 2f 2a 20 4f 4e 45 50 2 /* ONEP
28570 41 53 53 20 69 73 20 76 61 6c 69 64 20 66 6f 72 ASS is valid for
28580 20 6d 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a multiple rows *
28590 2f 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 /.void sqlite3Ex
285a0 70 72 43 6f 64 65 4c 6f 61 64 49 6e 64 65 78 43 prCodeLoadIndexC
285b0 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c 20 49 6e olumn(Parse*, In
285c0 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 dex*, int, int,
285d0 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
285e0 33 45 78 70 72 43 6f 64 65 47 65 74 43 6f 6c 75 3ExprCodeGetColu
285f0 6d 6e 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 mn(Parse*, Table
28600 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
28610 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 , u8);.void sqli
28620 74 65 33 45 78 70 72 43 6f 64 65 47 65 74 43 6f te3ExprCodeGetCo
28630 6c 75 6d 6e 54 6f 52 65 67 28 50 61 72 73 65 2a lumnToReg(Parse*
28640 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 , Table*, int, i
28650 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
28660 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 47 65 qlite3ExprCodeGe
28670 74 43 6f 6c 75 6d 6e 4f 66 54 61 62 6c 65 28 56 tColumnOfTable(V
28680 64 62 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e dbe*, Table*, in
28690 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f t, int, int);.vo
286a0 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f id sqlite3ExprCo
286b0 64 65 4d 6f 76 65 28 50 61 72 73 65 2a 2c 20 69 deMove(Parse*, i
286c0 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 nt, int, int);.v
286d0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
286e0 61 63 68 65 53 74 6f 72 65 28 50 61 72 73 65 2a acheStore(Parse*
286f0 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
28700 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
28710 70 72 43 61 63 68 65 50 75 73 68 28 50 61 72 73 prCachePush(Pars
28720 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
28730 33 45 78 70 72 43 61 63 68 65 50 6f 70 28 50 61 3ExprCachePop(Pa
28740 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 rse*);.void sqli
28750 74 65 33 45 78 70 72 43 61 63 68 65 52 65 6d 6f te3ExprCacheRemo
28760 76 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 ve(Parse*, int,
28770 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
28780 65 33 45 78 70 72 43 61 63 68 65 43 6c 65 61 72 e3ExprCacheClear
28790 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 (Parse*);.void s
287a0 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 41 qlite3ExprCacheA
287b0 66 66 69 6e 69 74 79 43 68 61 6e 67 65 28 50 61 ffinityChange(Pa
287c0 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b rse*, int, int);
287d0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
287e0 72 43 6f 64 65 28 50 61 72 73 65 2a 2c 20 45 78 rCode(Parse*, Ex
287f0 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 pr*, int);.void
28800 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 43 sqlite3ExprCodeC
28810 6f 70 79 28 50 61 72 73 65 2a 2c 20 45 78 70 72 opy(Parse*, Expr
28820 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
28830 6c 69 74 65 33 45 78 70 72 43 6f 64 65 46 61 63 lite3ExprCodeFac
28840 74 6f 72 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 torable(Parse*,
28850 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 Expr*, int);.int
28860 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 sqlite3ExprCode
28870 41 74 49 6e 69 74 28 50 61 72 73 65 2a 2c 20 45 AtInit(Parse*, E
28880 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 xpr*, int);.int
28890 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 54 sqlite3ExprCodeT
288a0 65 6d 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 emp(Parse*, Expr
288b0 2a 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 *, int*);.int sq
288c0 6c 69 74 65 33 45 78 70 72 43 6f 64 65 54 61 72 lite3ExprCodeTar
288d0 67 65 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 get(Parse*, Expr
288e0 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
288f0 6c 69 74 65 33 45 78 70 72 43 6f 64 65 41 6e 64 lite3ExprCodeAnd
28900 43 61 63 68 65 28 50 61 72 73 65 2a 2c 20 45 78 Cache(Parse*, Ex
28910 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 pr*, int);.int s
28920 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 45 78 qlite3ExprCodeEx
28930 70 72 4c 69 73 74 28 50 61 72 73 65 2a 2c 20 45 prList(Parse*, E
28940 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 xprList*, int, i
28950 6e 74 2c 20 75 38 29 3b 0a 23 64 65 66 69 6e 65 nt, u8);.#define
28960 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 44 55 50 SQLITE_ECEL_DUP
28970 20 20 20 20 20 20 30 78 30 31 20 20 2f 2a 20 44 0x01 /* D
28980 65 65 70 2c 20 6e 6f 74 20 73 68 61 6c 6c 6f 77 eep, not shallow
28990 20 63 6f 70 69 65 73 20 2a 2f 0a 23 64 65 66 69 copies */.#defi
289a0 6e 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 46 ne SQLITE_ECEL_F
289b0 41 43 54 4f 52 20 20 20 30 78 30 32 20 20 2f 2a ACTOR 0x02 /*
289c0 20 46 61 63 74 6f 72 20 6f 75 74 20 63 6f 6e 73 Factor out cons
289d0 74 61 6e 74 20 74 65 72 6d 73 20 2a 2f 0a 23 64 tant terms */.#d
289e0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 43 45 efine SQLITE_ECE
289f0 4c 5f 52 45 46 20 20 20 20 20 20 30 78 30 34 20 L_REF 0x04
28a00 20 2f 2a 20 55 73 65 20 45 78 70 72 4c 69 73 74 /* Use ExprList
28a10 2e 75 2e 78 2e 69 4f 72 64 65 72 42 79 43 6f 6c .u.x.iOrderByCol
28a20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
28a30 54 45 5f 45 43 45 4c 5f 4f 4d 49 54 52 45 46 20 TE_ECEL_OMITREF
28a40 20 30 78 30 38 20 20 2f 2a 20 4f 6d 69 74 20 69 0x08 /* Omit i
28a50 66 20 45 78 70 72 4c 69 73 74 2e 75 2e 78 2e 69 f ExprList.u.x.i
28a60 4f 72 64 65 72 42 79 43 6f 6c 20 2a 2f 0a 76 6f OrderByCol */.vo
28a70 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 66 id sqlite3ExprIf
28a80 54 72 75 65 28 50 61 72 73 65 2a 2c 20 45 78 70 True(Parse*, Exp
28a90 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 r*, int, int);.v
28aa0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 oid sqlite3ExprI
28ab0 66 46 61 6c 73 65 28 50 61 72 73 65 2a 2c 20 45 fFalse(Parse*, E
28ac0 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b xpr*, int, int);
28ad0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
28ae0 72 49 66 46 61 6c 73 65 44 75 70 28 50 61 72 73 rIfFalseDup(Pars
28af0 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 e*, Expr*, int,
28b00 69 6e 74 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c int);.Table *sql
28b10 69 74 65 33 46 69 6e 64 54 61 62 6c 65 28 73 71 ite3FindTable(sq
28b20 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
28b30 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
28b40 3b 0a 23 64 65 66 69 6e 65 20 4c 4f 43 41 54 45 ;.#define LOCATE
28b50 5f 56 49 45 57 20 20 20 20 30 78 30 31 0a 23 64 _VIEW 0x01.#d
28b60 65 66 69 6e 65 20 4c 4f 43 41 54 45 5f 4e 4f 45 efine LOCATE_NOE
28b70 52 52 20 20 20 30 78 30 32 0a 54 61 62 6c 65 20 RR 0x02.Table
28b80 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 *sqlite3LocateTa
28b90 62 6c 65 28 50 61 72 73 65 2a 2c 75 33 32 20 66 ble(Parse*,u32 f
28ba0 6c 61 67 73 2c 63 6f 6e 73 74 20 63 68 61 72 2a lags,const char*
28bb0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
28bc0 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 4c 6f Table *sqlite3Lo
28bd0 63 61 74 65 54 61 62 6c 65 49 74 65 6d 28 50 61 cateTableItem(Pa
28be0 72 73 65 2a 2c 75 33 32 20 66 6c 61 67 73 2c 73 rse*,u32 flags,s
28bf0 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f 69 74 truct SrcList_it
28c00 65 6d 20 2a 29 3b 0a 49 6e 64 65 78 20 2a 73 71 em *);.Index *sq
28c10 6c 69 74 65 33 46 69 6e 64 49 6e 64 65 78 28 73 lite3FindIndex(s
28c20 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
28c30 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
28c40 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 );.void sqlite3U
28c50 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 61 nlinkAndDeleteTa
28c60 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ble(sqlite3*,int
28c70 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
28c80 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e oid sqlite3Unlin
28c90 6b 41 6e 64 44 65 6c 65 74 65 49 6e 64 65 78 28 kAndDeleteIndex(
28ca0 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e sqlite3*,int,con
28cb0 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
28cc0 73 71 6c 69 74 65 33 56 61 63 75 75 6d 28 50 61 sqlite3Vacuum(Pa
28cd0 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 69 6e rse*,Token*);.in
28ce0 74 20 73 71 6c 69 74 65 33 52 75 6e 56 61 63 75 t sqlite3RunVacu
28cf0 75 6d 28 63 68 61 72 2a 2a 2c 20 73 71 6c 69 74 um(char**, sqlit
28d00 65 33 2a 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 e3*, int);.char
28d10 2a 73 71 6c 69 74 65 33 4e 61 6d 65 46 72 6f 6d *sqlite3NameFrom
28d20 54 6f 6b 65 6e 28 73 71 6c 69 74 65 33 2a 2c 20 Token(sqlite3*,
28d30 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
28d40 69 74 65 33 45 78 70 72 43 6f 6d 70 61 72 65 28 ite3ExprCompare(
28d50 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 20 45 78 Parse*,Expr*, Ex
28d60 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 pr*, int);.int s
28d70 71 6c 69 74 65 33 45 78 70 72 43 6f 6d 70 61 72 qlite3ExprCompar
28d80 65 53 6b 69 70 28 45 78 70 72 2a 2c 20 45 78 70 eSkip(Expr*, Exp
28d90 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 r*, int);.int sq
28da0 6c 69 74 65 33 45 78 70 72 4c 69 73 74 43 6f 6d lite3ExprListCom
28db0 70 61 72 65 28 45 78 70 72 4c 69 73 74 2a 2c 20 pare(ExprList*,
28dc0 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b ExprList*, int);
28dd0 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
28de0 49 6d 70 6c 69 65 73 45 78 70 72 28 50 61 72 73 ImpliesExpr(Pars
28df0 65 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c e*,Expr*, Expr*,
28e00 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
28e10 65 33 45 78 70 72 49 6d 70 6c 69 65 73 4e 6f 6e e3ExprImpliesNon
28e20 4e 75 6c 6c 52 6f 77 28 45 78 70 72 2a 2c 69 6e NullRow(Expr*,in
28e30 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
28e40 45 78 70 72 41 6e 61 6c 79 7a 65 41 67 67 72 65 ExprAnalyzeAggre
28e50 67 61 74 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 gates(NameContex
28e60 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 t*, Expr*);.void
28e70 20 73 71 6c 69 74 65 33 45 78 70 72 41 6e 61 6c sqlite3ExprAnal
28e80 79 7a 65 41 67 67 4c 69 73 74 28 4e 61 6d 65 43 yzeAggList(NameC
28e90 6f 6e 74 65 78 74 2a 2c 45 78 70 72 4c 69 73 74 ontext*,ExprList
28ea0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
28eb0 78 70 72 43 6f 76 65 72 65 64 42 79 49 6e 64 65 xprCoveredByInde
28ec0 78 28 45 78 70 72 2a 2c 20 69 6e 74 20 69 43 75 x(Expr*, int iCu
28ed0 72 2c 20 49 6e 64 65 78 20 2a 70 49 64 78 29 3b r, Index *pIdx);
28ee0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 75 6e 63 .int sqlite3Func
28ef0 74 69 6f 6e 55 73 65 73 54 68 69 73 53 72 63 28 tionUsesThisSrc(
28f00 45 78 70 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 Expr*, SrcList*)
28f10 3b 0a 56 64 62 65 20 2a 73 71 6c 69 74 65 33 47 ;.Vdbe *sqlite3G
28f20 65 74 56 64 62 65 28 50 61 72 73 65 2a 29 3b 0a etVdbe(Parse*);.
28f30 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 #ifndef SQLITE_U
28f40 4e 54 45 53 54 41 42 4c 45 0a 76 6f 69 64 20 73 NTESTABLE.void s
28f50 71 6c 69 74 65 33 50 72 6e 67 53 61 76 65 53 74 qlite3PrngSaveSt
28f60 61 74 65 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 ate(void);.void
28f70 73 71 6c 69 74 65 33 50 72 6e 67 52 65 73 74 6f sqlite3PrngResto
28f80 72 65 53 74 61 74 65 28 76 6f 69 64 29 3b 0a 23 reState(void);.#
28f90 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
28fa0 65 33 52 6f 6c 6c 62 61 63 6b 41 6c 6c 28 73 71 e3RollbackAll(sq
28fb0 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 lite3*,int);.voi
28fc0 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 72 d sqlite3CodeVer
28fd0 69 66 79 53 63 68 65 6d 61 28 50 61 72 73 65 2a ifySchema(Parse*
28fe0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
28ff0 69 74 65 33 43 6f 64 65 56 65 72 69 66 79 4e 61 ite3CodeVerifyNa
29000 6d 65 64 53 63 68 65 6d 61 28 50 61 72 73 65 2a medSchema(Parse*
29010 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 , const char *zD
29020 62 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 b);.void sqlite3
29030 42 65 67 69 6e 54 72 61 6e 73 61 63 74 69 6f 6e BeginTransaction
29040 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 (Parse*, int);.v
29050 6f 69 64 20 73 71 6c 69 74 65 33 45 6e 64 54 72 oid sqlite3EndTr
29060 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 73 65 2a ansaction(Parse*
29070 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
29080 74 65 33 53 61 76 65 70 6f 69 6e 74 28 50 61 72 te3Savepoint(Par
29090 73 65 2a 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a se*, int, Token*
290a0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
290b0 6c 6f 73 65 53 61 76 65 70 6f 69 6e 74 73 28 73 loseSavepoints(s
290c0 71 6c 69 74 65 33 20 2a 29 3b 0a 76 6f 69 64 20 qlite3 *);.void
290d0 73 71 6c 69 74 65 33 4c 65 61 76 65 4d 75 74 65 sqlite3LeaveMute
290e0 78 41 6e 64 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 xAndCloseZombie(
290f0 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 sqlite3*);.int s
29100 71 6c 69 74 65 33 45 78 70 72 49 64 54 6f 54 72 qlite3ExprIdToTr
29110 75 65 46 61 6c 73 65 28 45 78 70 72 2a 29 3b 0a ueFalse(Expr*);.
29120 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 54 int sqlite3ExprT
29130 72 75 74 68 56 61 6c 75 65 28 63 6f 6e 73 74 20 ruthValue(const
29140 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 Expr*);.int sqli
29150 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 61 6e te3ExprIsConstan
29160 74 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 t(Expr*);.int sq
29170 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 lite3ExprIsConst
29180 61 6e 74 4e 6f 74 4a 6f 69 6e 28 45 78 70 72 2a antNotJoin(Expr*
29190 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
291a0 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 46 75 prIsConstantOrFu
291b0 6e 63 74 69 6f 6e 28 45 78 70 72 2a 2c 20 75 38 nction(Expr*, u8
291c0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
291d0 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 47 72 prIsConstantOrGr
291e0 6f 75 70 42 79 28 50 61 72 73 65 2a 2c 20 45 78 oupBy(Parse*, Ex
291f0 70 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b pr*, ExprList*);
29200 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
29210 49 73 54 61 62 6c 65 43 6f 6e 73 74 61 6e 74 28 IsTableConstant(
29220 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 23 69 66 64 Expr*,int);.#ifd
29230 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
29240 5f 43 55 52 53 4f 52 5f 48 49 4e 54 53 0a 69 6e _CURSOR_HINTS.in
29250 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 6e t sqlite3ExprCon
29260 74 61 69 6e 73 53 75 62 71 75 65 72 79 28 45 78 tainsSubquery(Ex
29270 70 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 pr*);.#endif.int
29280 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 49 6e sqlite3ExprIsIn
29290 74 65 67 65 72 28 45 78 70 72 2a 2c 20 69 6e 74 teger(Expr*, int
292a0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
292b0 78 70 72 43 61 6e 42 65 4e 75 6c 6c 28 63 6f 6e xprCanBeNull(con
292c0 73 74 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 st Expr*);.int s
292d0 71 6c 69 74 65 33 45 78 70 72 4e 65 65 64 73 4e qlite3ExprNeedsN
292e0 6f 41 66 66 69 6e 69 74 79 43 68 61 6e 67 65 28 oAffinityChange(
292f0 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 63 68 61 const Expr*, cha
29300 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 r);.int sqlite3I
29310 73 52 6f 77 69 64 28 63 6f 6e 73 74 20 63 68 61 sRowid(const cha
29320 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
29330 33 47 65 6e 65 72 61 74 65 52 6f 77 44 65 6c 65 3GenerateRowDele
29340 74 65 28 0a 20 20 20 20 50 61 72 73 65 2a 2c 54 te(. Parse*,T
29350 61 62 6c 65 2a 2c 54 72 69 67 67 65 72 2a 2c 69 able*,Trigger*,i
29360 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 nt,int,int,i16,u
29370 38 2c 75 38 2c 75 38 2c 69 6e 74 29 3b 0a 76 6f 8,u8,u8,int);.vo
29380 69 64 20 73 71 6c 69 74 65 33 47 65 6e 65 72 61 id sqlite3Genera
29390 74 65 52 6f 77 49 6e 64 65 78 44 65 6c 65 74 65 teRowIndexDelete
293a0 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
293b0 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c int, int, int*,
293c0 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
293d0 65 33 47 65 6e 65 72 61 74 65 49 6e 64 65 78 4b e3GenerateIndexK
293e0 65 79 28 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 ey(Parse*, Index
293f0 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
29400 2c 20 69 6e 74 2a 2c 49 6e 64 65 78 2a 2c 69 6e , int*,Index*,in
29410 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
29420 52 65 73 6f 6c 76 65 50 61 72 74 49 64 78 4c 61 ResolvePartIdxLa
29430 62 65 6c 28 50 61 72 73 65 2a 2c 69 6e 74 29 3b bel(Parse*,int);
29440 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
29450 65 72 61 74 65 43 6f 6e 73 74 72 61 69 6e 74 43 erateConstraintC
29460 68 65 63 6b 73 28 50 61 72 73 65 2a 2c 54 61 62 hecks(Parse*,Tab
29470 6c 65 2a 2c 69 6e 74 2a 2c 69 6e 74 2c 69 6e 74 le*,int*,int,int
29480 2c 69 6e 74 2c 69 6e 74 2c 0a 20 20 20 20 20 20 ,int,int,.
29490 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
294a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 75 u
294b0 38 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 8,u8,int,int*,in
294c0 74 2a 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 t*);.#ifdef SQLI
294d0 54 45 5f 45 4e 41 42 4c 45 5f 4e 55 4c 4c 5f 54 TE_ENABLE_NULL_T
294e0 52 49 4d 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 RIM. void sqlit
294f0 65 33 53 65 74 4d 61 6b 65 52 65 63 6f 72 64 50 e3SetMakeRecordP
29500 35 28 56 64 62 65 2a 2c 54 61 62 6c 65 2a 29 3b 5(Vdbe*,Table*);
29510 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
29520 73 71 6c 69 74 65 33 53 65 74 4d 61 6b 65 52 65 sqlite3SetMakeRe
29530 63 6f 72 64 50 35 28 41 2c 42 29 0a 23 65 6e 64 cordP5(A,B).#end
29540 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 if.void sqlite3C
29550 6f 6d 70 6c 65 74 65 49 6e 73 65 72 74 69 6f 6e ompleteInsertion
29560 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 (Parse*,Table*,i
29570 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2a 2c nt,int,int,int*,
29580 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a 69 6e int,int,int);.in
29590 74 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 61 62 t sqlite3OpenTab
295a0 6c 65 41 6e 64 49 6e 64 69 63 65 73 28 50 61 72 leAndIndices(Par
295b0 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
295c0 2c 20 75 38 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 , u8, int, u8*,
295d0 69 6e 74 2a 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 int*, int*);.voi
295e0 64 20 73 71 6c 69 74 65 33 42 65 67 69 6e 57 72 d sqlite3BeginWr
295f0 69 74 65 4f 70 65 72 61 74 69 6f 6e 28 50 61 72 iteOperation(Par
29600 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a se*, int, int);.
29610 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 75 6c 74 void sqlite3Mult
29620 69 57 72 69 74 65 28 50 61 72 73 65 2a 29 3b 0a iWrite(Parse*);.
29630 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 79 41 void sqlite3MayA
29640 62 6f 72 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f bort(Parse*);.vo
29650 69 64 20 73 71 6c 69 74 65 33 48 61 6c 74 43 6f id sqlite3HaltCo
29660 6e 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c nstraint(Parse*,
29670 20 69 6e 74 2c 20 69 6e 74 2c 20 63 68 61 72 2a int, int, char*
29680 2c 20 69 38 2c 20 75 38 29 3b 0a 76 6f 69 64 20 , i8, u8);.void
29690 73 71 6c 69 74 65 33 55 6e 69 71 75 65 43 6f 6e sqlite3UniqueCon
296a0 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 straint(Parse*,
296b0 69 6e 74 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f int, Index*);.vo
296c0 69 64 20 73 71 6c 69 74 65 33 52 6f 77 69 64 43 id sqlite3RowidC
296d0 6f 6e 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a onstraint(Parse*
296e0 2c 20 69 6e 74 2c 20 54 61 62 6c 65 2a 29 3b 0a , int, Table*);.
296f0 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 Expr *sqlite3Exp
29700 72 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 rDup(sqlite3*,Ex
29710 70 72 2a 2c 69 6e 74 29 3b 0a 45 78 70 72 4c 69 pr*,int);.ExprLi
29720 73 74 20 2a 73 71 6c 69 74 65 33 45 78 70 72 4c st *sqlite3ExprL
29730 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c istDup(sqlite3*,
29740 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a ExprList*,int);.
29750 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 SrcList *sqlite3
29760 53 72 63 4c 69 73 74 44 75 70 28 73 71 6c 69 74 SrcListDup(sqlit
29770 65 33 2a 2c 53 72 63 4c 69 73 74 2a 2c 69 6e 74 e3*,SrcList*,int
29780 29 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 );.IdList *sqlit
29790 65 33 49 64 4c 69 73 74 44 75 70 28 73 71 6c 69 e3IdListDup(sqli
297a0 74 65 33 2a 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 te3*,IdList*);.S
297b0 65 6c 65 63 74 20 2a 73 71 6c 69 74 65 33 53 65 elect *sqlite3Se
297c0 6c 65 63 74 44 75 70 28 73 71 6c 69 74 65 33 2a lectDup(sqlite3*
297d0 2c 53 65 6c 65 63 74 2a 2c 69 6e 74 29 3b 0a 23 ,Select*,int);.#
297e0 69 66 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 if SELECTTRACE_E
297f0 4e 41 42 4c 45 44 0a 76 6f 69 64 20 73 71 6c 69 NABLED.void sqli
29800 74 65 33 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 te3SelectSetName
29810 28 53 65 6c 65 63 74 2a 2c 63 6f 6e 73 74 20 63 (Select*,const c
29820 68 61 72 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 har*);.#else.# d
29830 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 65 6c efine sqlite3Sel
29840 65 63 74 53 65 74 4e 61 6d 65 28 41 2c 42 29 0a ectSetName(A,B).
29850 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
29860 74 65 33 49 6e 73 65 72 74 42 75 69 6c 74 69 6e te3InsertBuiltin
29870 46 75 6e 63 73 28 46 75 6e 63 44 65 66 2a 2c 69 Funcs(FuncDef*,i
29880 6e 74 29 3b 0a 46 75 6e 63 44 65 66 20 2a 73 71 nt);.FuncDef *sq
29890 6c 69 74 65 33 46 69 6e 64 46 75 6e 63 74 69 6f lite3FindFunctio
298a0 6e 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 n(sqlite3*,const
298b0 20 63 68 61 72 2a 2c 69 6e 74 2c 75 38 2c 75 38 char*,int,u8,u8
298c0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
298d0 65 67 69 73 74 65 72 42 75 69 6c 74 69 6e 46 75 egisterBuiltinFu
298e0 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 76 nctions(void);.v
298f0 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 73 oid sqlite3Regis
29900 74 65 72 44 61 74 65 54 69 6d 65 46 75 6e 63 74 terDateTimeFunct
29910 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 ions(void);.void
29920 20 73 71 6c 69 74 65 33 52 65 67 69 73 74 65 72 sqlite3Register
29930 50 65 72 43 6f 6e 6e 65 63 74 69 6f 6e 42 75 69 PerConnectionBui
29940 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 73 28 73 71 ltinFunctions(sq
29950 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c lite3*);.int sql
29960 69 74 65 33 53 61 66 65 74 79 43 68 65 63 6b 4f ite3SafetyCheckO
29970 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 k(sqlite3*);.int
29980 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 43 68 sqlite3SafetyCh
29990 65 63 6b 53 69 63 6b 4f 72 4f 6b 28 73 71 6c 69 eckSickOrOk(sqli
299a0 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 te3*);.void sqli
299b0 74 65 33 43 68 61 6e 67 65 43 6f 6f 6b 69 65 28 te3ChangeCookie(
299c0 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 0a 23 Parse*, int);..#
299d0 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
299e0 54 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 26 26 TE_OMIT_VIEW) &&
299f0 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
29a00 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 0a 76 _OMIT_TRIGGER).v
29a10 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 74 65 72 oid sqlite3Mater
29a20 69 61 6c 69 7a 65 56 69 65 77 28 50 61 72 73 65 ializeView(Parse
29a30 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a *, Table*, Expr*
29a40 2c 20 45 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 , ExprList*,Expr
29a50 2a 2c 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a *,int);.#endif..
29a60 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
29a70 4d 49 54 5f 54 52 49 47 47 45 52 0a 20 20 76 6f MIT_TRIGGER. vo
29a80 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 6e 54 id sqlite3BeginT
29a90 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 54 rigger(Parse*, T
29aa0 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 oken*,Token*,int
29ab0 2c 69 6e 74 2c 49 64 4c 69 73 74 2a 2c 53 72 63 ,int,IdList*,Src
29ac0 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 List*,.
29ad0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29ae0 20 20 45 78 70 72 2a 2c 69 6e 74 2c 20 69 6e 74 Expr*,int, int
29af0 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
29b00 33 46 69 6e 69 73 68 54 72 69 67 67 65 72 28 50 3FinishTrigger(P
29b10 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 53 74 arse*, TriggerSt
29b20 65 70 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 20 20 ep*, Token*);.
29b30 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 void sqlite3Drop
29b40 54 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c 20 Trigger(Parse*,
29b50 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a SrcList*, int);.
29b60 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 void sqlite3Dr
29b70 6f 70 54 72 69 67 67 65 72 50 74 72 28 50 61 72 opTriggerPtr(Par
29b80 73 65 2a 2c 20 54 72 69 67 67 65 72 2a 29 3b 0a se*, Trigger*);.
29b90 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 Trigger *sqlit
29ba0 65 33 54 72 69 67 67 65 72 73 45 78 69 73 74 28 e3TriggersExist(
29bb0 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 2a 2c Parse *, Table*,
29bc0 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c int, ExprList*,
29bd0 20 69 6e 74 20 2a 70 4d 61 73 6b 29 3b 0a 20 20 int *pMask);.
29be0 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 65 33 Trigger *sqlite3
29bf0 54 72 69 67 67 65 72 4c 69 73 74 28 50 61 72 73 TriggerList(Pars
29c00 65 20 2a 2c 20 54 61 62 6c 65 20 2a 29 3b 0a 20 e *, Table *);.
29c10 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 void sqlite3Cod
29c20 65 52 6f 77 54 72 69 67 67 65 72 28 50 61 72 73 eRowTrigger(Pars
29c30 65 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c 20 69 e*, Trigger *, i
29c40 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 nt, ExprList*, i
29c50 6e 74 2c 20 54 61 62 6c 65 20 2a 2c 0a 20 20 20 nt, Table *,.
29c60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29c70 20 20 20 20 20 20 20 20 20 69 6e 74 2c 20 69 6e int, in
29c80 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 t, int);. void
29c90 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 sqlite3CodeRowTr
29ca0 69 67 67 65 72 44 69 72 65 63 74 28 50 61 72 73 iggerDirect(Pars
29cb0 65 20 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c 20 e *, Trigger *,
29cc0 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c 20 69 6e Table *, int, in
29cd0 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 t, int);. void
29ce0 73 71 6c 69 74 65 56 69 65 77 54 72 69 67 67 65 sqliteViewTrigge
29cf0 72 73 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 rs(Parse*, Table
29d00 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 45 *, Expr*, int, E
29d10 78 70 72 4c 69 73 74 2a 29 3b 0a 20 20 76 6f 69 xprList*);. voi
29d20 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 54 d sqlite3DeleteT
29d30 72 69 67 67 65 72 53 74 65 70 28 73 71 6c 69 74 riggerStep(sqlit
29d40 65 33 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 e3*, TriggerStep
29d50 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 *);. TriggerSte
29d60 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 p *sqlite3Trigge
29d70 72 53 65 6c 65 63 74 53 74 65 70 28 73 71 6c 69 rSelectStep(sqli
29d80 74 65 33 2a 2c 53 65 6c 65 63 74 2a 2c 0a 20 20 te3*,Select*,.
29d90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29da0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29db0 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
29dc0 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a *,const char*);.
29dd0 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 TriggerStep *s
29de0 71 6c 69 74 65 33 54 72 69 67 67 65 72 49 6e 73 qlite3TriggerIns
29df0 65 72 74 53 74 65 70 28 73 71 6c 69 74 65 33 2a ertStep(sqlite3*
29e00 2c 54 6f 6b 65 6e 2a 2c 20 49 64 4c 69 73 74 2a ,Token*, IdList*
29e10 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
29e20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29e30 20 20 20 20 20 20 20 20 20 20 53 65 6c 65 63 74 Select
29e40 2a 2c 75 38 2c 55 70 73 65 72 74 2a 2c 0a 20 20 *,u8,Upsert*,.
29e50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29e60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29e70 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
29e80 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a *,const char*);.
29e90 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 TriggerStep *s
29ea0 71 6c 69 74 65 33 54 72 69 67 67 65 72 55 70 64 qlite3TriggerUpd
29eb0 61 74 65 53 74 65 70 28 73 71 6c 69 74 65 33 2a ateStep(sqlite3*
29ec0 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 ,Token*,ExprList
29ed0 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c 0a 20 20 *, Expr*, u8,.
29ee0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29ef0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29f00 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 const char
29f10 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a *,const char*);.
29f20 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a 73 TriggerStep *s
29f30 71 6c 69 74 65 33 54 72 69 67 67 65 72 44 65 6c qlite3TriggerDel
29f40 65 74 65 53 74 65 70 28 73 71 6c 69 74 65 33 2a eteStep(sqlite3*
29f50 2c 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 2a 2c 0a ,Token*, Expr*,.
29f60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29f70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29f80 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 const ch
29f90 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 ar*,const char*)
29fa0 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
29fb0 44 65 6c 65 74 65 54 72 69 67 67 65 72 28 73 71 DeleteTrigger(sq
29fc0 6c 69 74 65 33 2a 2c 20 54 72 69 67 67 65 72 2a lite3*, Trigger*
29fd0 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
29fe0 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 3UnlinkAndDelete
29ff0 54 72 69 67 67 65 72 28 73 71 6c 69 74 65 33 2a Trigger(sqlite3*
2a000 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
2a010 29 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 65 33 );. u32 sqlite3
2a020 54 72 69 67 67 65 72 43 6f 6c 6d 61 73 6b 28 50 TriggerColmask(P
2a030 61 72 73 65 2a 2c 54 72 69 67 67 65 72 2a 2c 45 arse*,Trigger*,E
2a040 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 69 6e 74 xprList*,int,int
2a050 2c 54 61 62 6c 65 2a 2c 69 6e 74 29 3b 0a 23 20 ,Table*,int);.#
2a060 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 50 61 define sqlite3Pa
2a070 72 73 65 54 6f 70 6c 65 76 65 6c 28 70 29 20 28 rseToplevel(p) (
2a080 28 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 3f (p)->pToplevel ?
2a090 20 28 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 (p)->pToplevel
2a0a0 3a 20 28 70 29 29 0a 23 20 64 65 66 69 6e 65 20 : (p)).# define
2a0b0 73 71 6c 69 74 65 33 49 73 54 6f 70 6c 65 76 65 sqlite3IsTopleve
2a0c0 6c 28 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 6c l(p) ((p)->pTopl
2a0d0 65 76 65 6c 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 evel==0).#else.#
2a0e0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 define sqlite3T
2a0f0 72 69 67 67 65 72 73 45 78 69 73 74 28 42 2c 43 riggersExist(B,C
2a100 2c 44 2c 45 2c 46 29 20 30 0a 23 20 64 65 66 69 ,D,E,F) 0.# defi
2a110 6e 65 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 ne sqlite3Delete
2a120 54 72 69 67 67 65 72 28 41 2c 42 29 0a 23 20 64 Trigger(A,B).# d
2a130 65 66 69 6e 65 20 73 71 6c 69 74 65 33 44 72 6f efine sqlite3Dro
2a140 70 54 72 69 67 67 65 72 50 74 72 28 41 2c 42 29 pTriggerPtr(A,B)
2a150 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
2a160 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 3UnlinkAndDelete
2a170 54 72 69 67 67 65 72 28 41 2c 42 2c 43 29 0a 23 Trigger(A,B,C).#
2a180 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 define sqlite3C
2a190 6f 64 65 52 6f 77 54 72 69 67 67 65 72 28 41 2c odeRowTrigger(A,
2a1a0 42 2c 43 2c 44 2c 45 2c 46 2c 47 2c 48 2c 49 29 B,C,D,E,F,G,H,I)
2a1b0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
2a1c0 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 44 3CodeRowTriggerD
2a1d0 69 72 65 63 74 28 41 2c 42 2c 43 2c 44 2c 45 2c irect(A,B,C,D,E,
2a1e0 46 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 F).# define sqli
2a1f0 74 65 33 54 72 69 67 67 65 72 4c 69 73 74 28 58 te3TriggerList(X
2a200 2c 20 59 29 20 30 0a 23 20 64 65 66 69 6e 65 20 , Y) 0.# define
2a210 73 71 6c 69 74 65 33 50 61 72 73 65 54 6f 70 6c sqlite3ParseTopl
2a220 65 76 65 6c 28 70 29 20 70 0a 23 20 64 65 66 69 evel(p) p.# defi
2a230 6e 65 20 73 71 6c 69 74 65 33 49 73 54 6f 70 6c ne sqlite3IsTopl
2a240 65 76 65 6c 28 70 29 20 31 0a 23 20 64 65 66 69 evel(p) 1.# defi
2a250 6e 65 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 ne sqlite3Trigge
2a260 72 43 6f 6c 6d 61 73 6b 28 41 2c 42 2c 43 2c 44 rColmask(A,B,C,D
2a270 2c 45 2c 46 2c 47 29 20 30 0a 23 65 6e 64 69 66 ,E,F,G) 0.#endif
2a280 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 69 ..int sqlite3Joi
2a290 6e 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 6f nType(Parse*, To
2a2a0 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f ken*, Token*, To
2a2b0 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
2a2c0 74 65 33 43 72 65 61 74 65 46 6f 72 65 69 67 6e te3CreateForeign
2a2d0 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Key(Parse*, Expr
2a2e0 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 45 List*, Token*, E
2a2f0 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a xprList*, int);.
2a300 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 66 65 void sqlite3Defe
2a310 72 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 72 73 rForeignKey(Pars
2a320 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 6e 64 65 e*, int);.#ifnde
2a330 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
2a340 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 76 6f THORIZATION. vo
2a350 69 64 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 id sqlite3AuthRe
2a360 61 64 28 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c ad(Parse*,Expr*,
2a370 53 63 68 65 6d 61 2a 2c 53 72 63 4c 69 73 74 2a Schema*,SrcList*
2a380 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
2a390 41 75 74 68 43 68 65 63 6b 28 50 61 72 73 65 2a AuthCheck(Parse*
2a3a0 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 ,int, const char
2a3b0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 *, const char*,
2a3c0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 const char*);.
2a3d0 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 68 void sqlite3Auth
2a3e0 43 6f 6e 74 65 78 74 50 75 73 68 28 50 61 72 73 ContextPush(Pars
2a3f0 65 2a 2c 20 41 75 74 68 43 6f 6e 74 65 78 74 2a e*, AuthContext*
2a400 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
2a410 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 void sqlite3Au
2a420 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 41 75 74 thContextPop(Aut
2a430 68 43 6f 6e 74 65 78 74 2a 29 3b 0a 20 20 69 6e hContext*);. in
2a440 74 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 t sqlite3AuthRea
2a450 64 43 6f 6c 28 50 61 72 73 65 2a 2c 20 63 6f 6e dCol(Parse*, con
2a460 73 74 20 63 68 61 72 20 2a 2c 20 63 6f 6e 73 74 st char *, const
2a470 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 23 char *, int);.#
2a480 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
2a490 6c 69 74 65 33 41 75 74 68 52 65 61 64 28 61 2c lite3AuthRead(a,
2a4a0 62 2c 63 2c 64 29 0a 23 20 64 65 66 69 6e 65 20 b,c,d).# define
2a4b0 73 71 6c 69 74 65 33 41 75 74 68 43 68 65 63 6b sqlite3AuthCheck
2a4c0 28 61 2c 62 2c 63 2c 64 2c 65 29 20 20 20 20 53 (a,b,c,d,e) S
2a4d0 51 4c 49 54 45 5f 4f 4b 0a 23 20 64 65 66 69 6e QLITE_OK.# defin
2a4e0 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e e sqlite3AuthCon
2a4f0 74 65 78 74 50 75 73 68 28 61 2c 62 2c 63 29 0a textPush(a,b,c).
2a500 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
2a510 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 61 AuthContextPop(a
2a520 29 20 20 28 28 76 6f 69 64 29 28 61 29 29 0a 23 ) ((void)(a)).#
2a530 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
2a540 65 33 41 74 74 61 63 68 28 50 61 72 73 65 2a 2c e3Attach(Parse*,
2a550 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 45 Expr*, Expr*, E
2a560 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
2a570 74 65 33 44 65 74 61 63 68 28 50 61 72 73 65 2a te3Detach(Parse*
2a580 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
2a590 71 6c 69 74 65 33 46 69 78 49 6e 69 74 28 44 62 qlite3FixInit(Db
2a5a0 46 69 78 65 72 2a 2c 20 50 61 72 73 65 2a 2c 20 Fixer*, Parse*,
2a5b0 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a int, const char*
2a5c0 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 29 3b , const Token*);
2a5d0 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 53 .int sqlite3FixS
2a5e0 72 63 4c 69 73 74 28 44 62 46 69 78 65 72 2a 2c rcList(DbFixer*,
2a5f0 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 SrcList*);.int
2a600 73 71 6c 69 74 65 33 46 69 78 53 65 6c 65 63 74 sqlite3FixSelect
2a610 28 44 62 46 69 78 65 72 2a 2c 20 53 65 6c 65 63 (DbFixer*, Selec
2a620 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
2a630 46 69 78 45 78 70 72 28 44 62 46 69 78 65 72 2a FixExpr(DbFixer*
2a640 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 , Expr*);.int sq
2a650 6c 69 74 65 33 46 69 78 45 78 70 72 4c 69 73 74 lite3FixExprList
2a660 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 4c (DbFixer*, ExprL
2a670 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ist*);.int sqlit
2a680 65 33 46 69 78 54 72 69 67 67 65 72 53 74 65 70 e3FixTriggerStep
2a690 28 44 62 46 69 78 65 72 2a 2c 20 54 72 69 67 67 (DbFixer*, Trigg
2a6a0 65 72 53 74 65 70 2a 29 3b 0a 69 6e 74 20 73 71 erStep*);.int sq
2a6b0 6c 69 74 65 33 41 74 6f 46 28 63 6f 6e 73 74 20 lite3AtoF(const
2a6c0 63 68 61 72 20 2a 7a 2c 20 64 6f 75 62 6c 65 2a char *z, double*
2a6d0 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 , int, u8);.int
2a6e0 73 71 6c 69 74 65 33 47 65 74 49 6e 74 33 32 28 sqlite3GetInt32(
2a6f0 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e const char *, in
2a700 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
2a710 41 74 6f 69 28 63 6f 6e 73 74 20 63 68 61 72 2a Atoi(const char*
2a720 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
2a730 45 5f 4f 4d 49 54 5f 55 54 46 31 36 0a 69 6e 74 E_OMIT_UTF16.int
2a740 20 73 71 6c 69 74 65 33 55 74 66 31 36 42 79 74 sqlite3Utf16Byt
2a750 65 4c 65 6e 28 63 6f 6e 73 74 20 76 6f 69 64 20 eLen(const void
2a760 2a 70 44 61 74 61 2c 20 69 6e 74 20 6e 43 68 61 *pData, int nCha
2a770 72 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 r);.#endif.int s
2a780 71 6c 69 74 65 33 55 74 66 38 43 68 61 72 4c 65 qlite3Utf8CharLe
2a790 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 44 n(const char *pD
2a7a0 61 74 61 2c 20 69 6e 74 20 6e 42 79 74 65 29 3b ata, int nByte);
2a7b0 0a 75 33 32 20 73 71 6c 69 74 65 33 55 74 66 38 .u32 sqlite3Utf8
2a7c0 52 65 61 64 28 63 6f 6e 73 74 20 75 38 2a 2a 29 Read(const u8**)
2a7d0 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 33 ;.LogEst sqlite3
2a7e0 4c 6f 67 45 73 74 28 75 36 34 29 3b 0a 4c 6f 67 LogEst(u64);.Log
2a7f0 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 Est sqlite3LogEs
2a800 74 41 64 64 28 4c 6f 67 45 73 74 2c 4c 6f 67 45 tAdd(LogEst,LogE
2a810 73 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c st);.#ifndef SQL
2a820 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
2a830 54 41 42 4c 45 0a 4c 6f 67 45 73 74 20 73 71 6c TABLE.LogEst sql
2a840 69 74 65 33 4c 6f 67 45 73 74 46 72 6f 6d 44 6f ite3LogEstFromDo
2a850 75 62 6c 65 28 64 6f 75 62 6c 65 29 3b 0a 23 65 uble(double);.#e
2a860 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
2a870 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 (SQLITE_ENABLE_S
2a880 54 4d 54 5f 53 43 41 4e 53 54 41 54 55 53 29 20 TMT_SCANSTATUS)
2a890 7c 7c 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 || \. defined
2a8a0 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 (SQLITE_ENABLE_S
2a8b0 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 29 20 7c TAT3_OR_STAT4) |
2a8c0 7c 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 | \. defined(
2a8d0 53 51 4c 49 54 45 5f 45 58 50 4c 41 49 4e 5f 45 SQLITE_EXPLAIN_E
2a8e0 53 54 49 4d 41 54 45 44 5f 52 4f 57 53 29 0a 75 STIMATED_ROWS).u
2a8f0 36 34 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 64 sqlite3LogEst
2a900 54 6f 49 6e 74 28 4c 6f 67 45 73 74 29 3b 0a 23 ToInt(LogEst);.#
2a910 65 6e 64 69 66 0a 56 4c 69 73 74 20 2a 73 71 6c endif.VList *sql
2a920 69 74 65 33 56 4c 69 73 74 41 64 64 28 73 71 6c ite3VListAdd(sql
2a930 69 74 65 33 2a 2c 56 4c 69 73 74 2a 2c 63 6f 6e ite3*,VList*,con
2a940 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c 69 6e 74 st char*,int,int
2a950 29 3b 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 );.const char *s
2a960 71 6c 69 74 65 33 56 4c 69 73 74 4e 75 6d 54 6f qlite3VListNumTo
2a970 4e 61 6d 65 28 56 4c 69 73 74 2a 2c 69 6e 74 29 Name(VList*,int)
2a980 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 4c 69 ;.int sqlite3VLi
2a990 73 74 4e 61 6d 65 54 6f 4e 75 6d 28 56 4c 69 73 stNameToNum(VLis
2a9a0 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 t*,const char*,i
2a9b0 6e 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 74 nt);../*.** Rout
2a9c0 69 6e 65 73 20 74 6f 20 72 65 61 64 20 61 6e 64 ines to read and
2a9d0 20 77 72 69 74 65 20 76 61 72 69 61 62 6c 65 2d write variable-
2a9e0 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 72 73 2e length integers.
2a9f0 20 20 54 68 65 73 65 20 75 73 65 64 20 74 6f 0a These used to.
2aa00 2a 2a 20 62 65 20 64 65 66 69 6e 65 64 20 6c 6f ** be defined lo
2aa10 63 61 6c 6c 79 2c 20 62 75 74 20 6e 6f 77 20 77 cally, but now w
2aa20 65 20 75 73 65 20 74 68 65 20 76 61 72 69 6e 74 e use the varint
2aa30 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 74 68 65 routines in the
2aa40 20 75 74 69 6c 2e 63 0a 2a 2a 20 66 69 6c 65 2e util.c.** file.
2aa50 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 .*/.int sqlite3P
2aa60 75 74 56 61 72 69 6e 74 28 75 6e 73 69 67 6e 65 utVarint(unsigne
2aa70 64 20 63 68 61 72 2a 2c 20 75 36 34 29 3b 0a 75 d char*, u64);.u
2aa80 38 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 69 8 sqlite3GetVari
2aa90 6e 74 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 nt(const unsigne
2aaa0 64 20 63 68 61 72 20 2a 2c 20 75 36 34 20 2a 29 d char *, u64 *)
2aab0 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 56 ;.u8 sqlite3GetV
2aac0 61 72 69 6e 74 33 32 28 63 6f 6e 73 74 20 75 6e arint32(const un
2aad0 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 75 signed char *, u
2aae0 33 32 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 32 *);.int sqlit
2aaf0 65 33 56 61 72 69 6e 74 4c 65 6e 28 75 36 34 20 e3VarintLen(u64
2ab00 76 29 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 v);../*.** The c
2ab10 6f 6d 6d 6f 6e 20 63 61 73 65 20 69 73 20 66 6f ommon case is fo
2ab20 72 20 61 20 76 61 72 69 6e 74 20 74 6f 20 62 65 r a varint to be
2ab30 20 61 20 73 69 6e 67 6c 65 20 62 79 74 65 2e 20 a single byte.
2ab40 20 54 68 65 79 20 66 6f 6c 6c 6f 77 69 6e 67 0a They following.
2ab50 2a 2a 20 6d 61 63 72 6f 73 20 68 61 6e 64 6c 65 ** macros handle
2ab60 20 74 68 65 20 63 6f 6d 6d 6f 6e 20 63 61 73 65 the common case
2ab70 20 77 69 74 68 6f 75 74 20 61 20 70 72 6f 63 65 without a proce
2ab80 64 75 72 65 20 63 61 6c 6c 2c 20 62 75 74 20 74 dure call, but t
2ab90 68 65 6e 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 hen call.** the
2aba0 70 72 6f 63 65 64 75 72 65 20 66 6f 72 20 6c 61 procedure for la
2abb0 72 67 65 72 20 76 61 72 69 6e 74 73 2e 0a 2a 2f rger varints..*/
2abc0 0a 23 64 65 66 69 6e 65 20 67 65 74 56 61 72 69 .#define getVari
2abd0 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a 20 20 28 nt32(A,B) \. (
2abe0 75 38 29 28 28 2a 28 41 29 3c 28 75 38 29 30 78 u8)((*(A)<(u8)0x
2abf0 38 30 29 3f 28 28 42 29 3d 28 75 33 32 29 2a 28 80)?((B)=(u32)*(
2ac00 41 29 29 2c 31 3a 73 71 6c 69 74 65 33 47 65 74 A)),1:sqlite3Get
2ac10 56 61 72 69 6e 74 33 32 28 28 41 29 2c 28 75 33 Varint32((A),(u3
2ac20 32 20 2a 29 26 28 42 29 29 29 0a 23 64 65 66 69 2 *)&(B))).#defi
2ac30 6e 65 20 70 75 74 56 61 72 69 6e 74 33 32 28 41 ne putVarint32(A
2ac40 2c 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 28 ,B) \. (u8)(((
2ac50 75 33 32 29 28 42 29 3c 28 75 33 32 29 30 78 38 u32)(B)<(u32)0x8
2ac60 30 29 3f 28 2a 28 41 29 3d 28 75 6e 73 69 67 6e 0)?(*(A)=(unsign
2ac70 65 64 20 63 68 61 72 29 28 42 29 29 2c 31 3a 5c ed char)(B)),1:\
2ac80 0a 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 . sqlite3PutVar
2ac90 69 6e 74 28 28 41 29 2c 28 42 29 29 29 0a 23 64 int((A),(B))).#d
2aca0 65 66 69 6e 65 20 67 65 74 56 61 72 69 6e 74 20 efine getVarint
2acb0 20 20 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 sqlite3GetVar
2acc0 69 6e 74 0a 23 64 65 66 69 6e 65 20 70 75 74 56 int.#define putV
2acd0 61 72 69 6e 74 20 20 20 20 73 71 6c 69 74 65 33 arint sqlite3
2ace0 50 75 74 56 61 72 69 6e 74 0a 0a 0a 63 6f 6e 73 PutVarint...cons
2acf0 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 49 t char *sqlite3I
2ad00 6e 64 65 78 41 66 66 69 6e 69 74 79 53 74 72 28 ndexAffinityStr(
2ad10 73 71 6c 69 74 65 33 2a 2c 20 49 6e 64 65 78 2a sqlite3*, Index*
2ad20 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 54 );.void sqlite3T
2ad30 61 62 6c 65 41 66 66 69 6e 69 74 79 28 56 64 62 ableAffinity(Vdb
2ad40 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 e*, Table*, int)
2ad50 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 43 6f ;.char sqlite3Co
2ad60 6d 70 61 72 65 41 66 66 69 6e 69 74 79 28 45 78 mpareAffinity(Ex
2ad70 70 72 20 2a 70 45 78 70 72 2c 20 63 68 61 72 20 pr *pExpr, char
2ad80 61 66 66 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 aff2);.int sqlit
2ad90 65 33 49 6e 64 65 78 41 66 66 69 6e 69 74 79 4f e3IndexAffinityO
2ada0 6b 28 45 78 70 72 20 2a 70 45 78 70 72 2c 20 63 k(Expr *pExpr, c
2adb0 68 61 72 20 69 64 78 5f 61 66 66 69 6e 69 74 79 har idx_affinity
2adc0 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 54 );.char sqlite3T
2add0 61 62 6c 65 43 6f 6c 75 6d 6e 41 66 66 69 6e 69 ableColumnAffini
2ade0 74 79 28 54 61 62 6c 65 2a 2c 69 6e 74 29 3b 0a ty(Table*,int);.
2adf0 63 68 61 72 20 73 71 6c 69 74 65 33 45 78 70 72 char sqlite3Expr
2ae00 41 66 66 69 6e 69 74 79 28 45 78 70 72 20 2a 70 Affinity(Expr *p
2ae10 45 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 Expr);.int sqlit
2ae20 65 33 41 74 6f 69 36 34 28 63 6f 6e 73 74 20 63 e3Atoi64(const c
2ae30 68 61 72 2a 2c 20 69 36 34 2a 2c 20 69 6e 74 2c har*, i64*, int,
2ae40 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u8);.int sqlite
2ae50 33 44 65 63 4f 72 48 65 78 54 6f 49 36 34 28 63 3DecOrHexToI64(c
2ae60 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a onst char*, i64*
2ae70 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
2ae80 72 72 6f 72 57 69 74 68 4d 73 67 28 73 71 6c 69 rrorWithMsg(sqli
2ae90 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 te3*, int, const
2aea0 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 76 6f 69 char*,...);.voi
2aeb0 64 20 73 71 6c 69 74 65 33 45 72 72 6f 72 28 73 d sqlite3Error(s
2aec0 71 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f qlite3*,int);.vo
2aed0 69 64 20 73 71 6c 69 74 65 33 53 79 73 74 65 6d id sqlite3System
2aee0 45 72 72 6f 72 28 73 71 6c 69 74 65 33 2a 2c 69 Error(sqlite3*,i
2aef0 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 nt);.void *sqlit
2af00 65 33 48 65 78 54 6f 42 6c 6f 62 28 73 71 6c 69 e3HexToBlob(sqli
2af10 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 te3*, const char
2af20 20 2a 7a 2c 20 69 6e 74 20 6e 29 3b 0a 75 38 20 *z, int n);.u8
2af30 73 71 6c 69 74 65 33 48 65 78 54 6f 49 6e 74 28 sqlite3HexToInt(
2af40 69 6e 74 20 68 29 3b 0a 69 6e 74 20 73 71 6c 69 int h);.int sqli
2af50 74 65 33 54 77 6f 50 61 72 74 4e 61 6d 65 28 50 te3TwoPartName(P
2af60 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c arse *, Token *,
2af70 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 Token *, Token
2af80 2a 2a 29 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 **);..#if define
2af90 64 28 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 d(SQLITE_NEED_ER
2afa0 52 5f 4e 41 4d 45 29 0a 63 6f 6e 73 74 20 63 68 R_NAME).const ch
2afb0 61 72 20 2a 73 71 6c 69 74 65 33 45 72 72 4e 61 ar *sqlite3ErrNa
2afc0 6d 65 28 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a me(int);.#endif.
2afd0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
2afe0 4e 41 42 4c 45 5f 44 45 53 45 52 49 41 4c 49 5a NABLE_DESERIALIZ
2aff0 45 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d E.int sqlite3Mem
2b000 64 62 49 6e 69 74 28 76 6f 69 64 29 3b 0a 23 65 dbInit(void);.#e
2b010 6e 64 69 66 0a 0a 63 6f 6e 73 74 20 63 68 61 72 ndif..const char
2b020 20 2a 73 71 6c 69 74 65 33 45 72 72 53 74 72 28 *sqlite3ErrStr(
2b030 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
2b040 33 52 65 61 64 53 63 68 65 6d 61 28 50 61 72 73 3ReadSchema(Pars
2b050 65 20 2a 70 50 61 72 73 65 29 3b 0a 43 6f 6c 6c e *pParse);.Coll
2b060 53 65 71 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 Seq *sqlite3Find
2b070 43 6f 6c 6c 53 65 71 28 73 71 6c 69 74 65 33 2a CollSeq(sqlite3*
2b080 2c 75 38 20 65 6e 63 2c 20 63 6f 6e 73 74 20 63 ,u8 enc, const c
2b090 68 61 72 2a 2c 69 6e 74 29 3b 0a 43 6f 6c 6c 53 har*,int);.CollS
2b0a0 65 71 20 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 eq *sqlite3Locat
2b0b0 65 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a eCollSeq(Parse *
2b0c0 70 50 61 72 73 65 2c 20 63 6f 6e 73 74 20 63 68 pParse, const ch
2b0d0 61 72 2a 7a 4e 61 6d 65 29 3b 0a 43 6f 6c 6c 53 ar*zName);.CollS
2b0e0 65 71 20 2a 73 71 6c 69 74 65 33 45 78 70 72 43 eq *sqlite3ExprC
2b0f0 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 70 50 ollSeq(Parse *pP
2b100 61 72 73 65 2c 20 45 78 70 72 20 2a 70 45 78 70 arse, Expr *pExp
2b110 72 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c r);.CollSeq *sql
2b120 69 74 65 33 45 78 70 72 4e 4e 43 6f 6c 6c 53 65 ite3ExprNNCollSe
2b130 71 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c q(Parse *pParse,
2b140 20 45 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 69 Expr *pExpr);.i
2b150 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f nt sqlite3ExprCo
2b160 6c 6c 53 65 71 4d 61 74 63 68 28 50 61 72 73 65 llSeqMatch(Parse
2b170 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 3b 0a *,Expr*,Expr*);.
2b180 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 Expr *sqlite3Exp
2b190 72 41 64 64 43 6f 6c 6c 61 74 65 54 6f 6b 65 6e rAddCollateToken
2b1a0 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 (Parse *pParse,
2b1b0 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b Expr*, const Tok
2b1c0 65 6e 2a 2c 20 69 6e 74 29 3b 0a 45 78 70 72 20 en*, int);.Expr
2b1d0 2a 73 71 6c 69 74 65 33 45 78 70 72 41 64 64 43 *sqlite3ExprAddC
2b1e0 6f 6c 6c 61 74 65 53 74 72 69 6e 67 28 50 61 72 ollateString(Par
2b1f0 73 65 2a 2c 45 78 70 72 2a 2c 63 6f 6e 73 74 20 se*,Expr*,const
2b200 63 68 61 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 char*);.Expr *sq
2b210 6c 69 74 65 33 45 78 70 72 53 6b 69 70 43 6f 6c lite3ExprSkipCol
2b220 6c 61 74 65 28 45 78 70 72 2a 29 3b 0a 69 6e 74 late(Expr*);.int
2b230 20 73 71 6c 69 74 65 33 43 68 65 63 6b 43 6f 6c sqlite3CheckCol
2b240 6c 53 65 71 28 50 61 72 73 65 20 2a 2c 20 43 6f lSeq(Parse *, Co
2b250 6c 6c 53 65 71 20 2a 29 3b 0a 69 6e 74 20 73 71 llSeq *);.int sq
2b260 6c 69 74 65 33 43 68 65 63 6b 4f 62 6a 65 63 74 lite3CheckObject
2b270 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c 20 63 6f Name(Parse *, co
2b280 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 76 6f 69 nst char *);.voi
2b290 64 20 73 71 6c 69 74 65 33 56 64 62 65 53 65 74 d sqlite3VdbeSet
2b2a0 43 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 20 Changes(sqlite3
2b2b0 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c *, int);.int sql
2b2c0 69 74 65 33 41 64 64 49 6e 74 36 34 28 69 36 34 ite3AddInt64(i64
2b2d0 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 *,i64);.int sqli
2b2e0 74 65 33 53 75 62 49 6e 74 36 34 28 69 36 34 2a te3SubInt64(i64*
2b2f0 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ,i64);.int sqlit
2b300 65 33 4d 75 6c 49 6e 74 36 34 28 69 36 34 2a 2c e3MulInt64(i64*,
2b310 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 i64);.int sqlite
2b320 33 41 62 73 49 6e 74 33 32 28 69 6e 74 29 3b 0a 3AbsInt32(int);.
2b330 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e #ifdef SQLITE_EN
2b340 41 42 4c 45 5f 38 5f 33 5f 4e 41 4d 45 53 0a 76 ABLE_8_3_NAMES.v
2b350 6f 69 64 20 73 71 6c 69 74 65 33 46 69 6c 65 53 oid sqlite3FileS
2b360 75 66 66 69 78 33 28 63 6f 6e 73 74 20 63 68 61 uffix3(const cha
2b370 72 2a 2c 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 r*, char*);.#els
2b380 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
2b390 65 33 46 69 6c 65 53 75 66 66 69 78 33 28 58 2c e3FileSuffix3(X,
2b3a0 59 29 0a 23 65 6e 64 69 66 0a 75 38 20 73 71 6c Y).#endif.u8 sql
2b3b0 69 74 65 33 47 65 74 42 6f 6f 6c 65 61 6e 28 63 ite3GetBoolean(c
2b3c0 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c 75 38 29 onst char *z,u8)
2b3d0 3b 0a 0a 63 6f 6e 73 74 20 76 6f 69 64 20 2a 73 ;..const void *s
2b3e0 71 6c 69 74 65 33 56 61 6c 75 65 54 65 78 74 28 qlite3ValueText(
2b3f0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 sqlite3_value*,
2b400 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 u8);.int sqlite3
2b410 56 61 6c 75 65 42 79 74 65 73 28 73 71 6c 69 74 ValueBytes(sqlit
2b420 65 33 5f 76 61 6c 75 65 2a 2c 20 75 38 29 3b 0a e3_value*, u8);.
2b430 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 void sqlite3Valu
2b440 65 53 65 74 53 74 72 28 73 71 6c 69 74 65 33 5f eSetStr(sqlite3_
2b450 76 61 6c 75 65 2a 2c 20 69 6e 74 2c 20 63 6f 6e value*, int, con
2b460 73 74 20 76 6f 69 64 20 2a 2c 75 38 2c 0a 20 20 st void *,u8,.
2b470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2b480 20 20 20 20 20 20 76 6f 69 64 28 2a 29 28 76 6f void(*)(vo
2b490 69 64 2a 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 id*));.void sqli
2b4a0 74 65 33 56 61 6c 75 65 53 65 74 4e 75 6c 6c 28 te3ValueSetNull(
2b4b0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 29 3b sqlite3_value*);
2b4c0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c .void sqlite3Val
2b4d0 75 65 46 72 65 65 28 73 71 6c 69 74 65 33 5f 76 ueFree(sqlite3_v
2b4e0 61 6c 75 65 2a 29 3b 0a 73 71 6c 69 74 65 33 5f alue*);.sqlite3_
2b4f0 76 61 6c 75 65 20 2a 73 71 6c 69 74 65 33 56 61 value *sqlite3Va
2b500 6c 75 65 4e 65 77 28 73 71 6c 69 74 65 33 20 2a lueNew(sqlite3 *
2b510 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
2b520 45 5f 4f 4d 49 54 5f 55 54 46 31 36 0a 63 68 61 E_OMIT_UTF16.cha
2b530 72 20 2a 73 71 6c 69 74 65 33 55 74 66 31 36 74 r *sqlite3Utf16t
2b540 6f 38 28 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f o8(sqlite3 *, co
2b550 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 nst void*, int,
2b560 75 38 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 u8);.#endif.int
2b570 73 71 6c 69 74 65 33 56 61 6c 75 65 46 72 6f 6d sqlite3ValueFrom
2b580 45 78 70 72 28 73 71 6c 69 74 65 33 20 2a 2c 20 Expr(sqlite3 *,
2b590 45 78 70 72 20 2a 2c 20 75 38 2c 20 75 38 2c 20 Expr *, u8, u8,
2b5a0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 2a sqlite3_value **
2b5b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
2b5c0 61 6c 75 65 41 70 70 6c 79 41 66 66 69 6e 69 74 alueApplyAffinit
2b5d0 79 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 y(sqlite3_value
2b5e0 2a 2c 20 75 38 2c 20 75 38 29 3b 0a 23 69 66 6e *, u8, u8);.#ifn
2b5f0 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c 47 def SQLITE_AMALG
2b600 41 4d 41 54 49 4f 4e 0a 65 78 74 65 72 6e 20 63 AMATION.extern c
2b610 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 onst unsigned ch
2b620 61 72 20 73 71 6c 69 74 65 33 4f 70 63 6f 64 65 ar sqlite3Opcode
2b630 50 72 6f 70 65 72 74 79 5b 5d 3b 0a 65 78 74 65 Property[];.exte
2b640 72 6e 20 63 6f 6e 73 74 20 63 68 61 72 20 73 71 rn const char sq
2b650 6c 69 74 65 33 53 74 72 42 49 4e 41 52 59 5b 5d lite3StrBINARY[]
2b660 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 ;.extern const u
2b670 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c nsigned char sql
2b680 69 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 ite3UpperToLower
2b690 5b 5d 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 [];.extern const
2b6a0 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 unsigned char s
2b6b0 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 5d qlite3CtypeMap[]
2b6c0 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 54 ;.extern const T
2b6d0 6f 6b 65 6e 20 73 71 6c 69 74 65 33 49 6e 74 54 oken sqlite3IntT
2b6e0 6f 6b 65 6e 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 okens[];.extern
2b6f0 53 51 4c 49 54 45 5f 57 53 44 20 73 74 72 75 63 SQLITE_WSD struc
2b700 74 20 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 t Sqlite3Config
2b710 73 71 6c 69 74 65 33 43 6f 6e 66 69 67 3b 0a 65 sqlite3Config;.e
2b720 78 74 65 72 6e 20 46 75 6e 63 44 65 66 48 61 73 xtern FuncDefHas
2b730 68 20 73 71 6c 69 74 65 33 42 75 69 6c 74 69 6e h sqlite3Builtin
2b740 46 75 6e 63 74 69 6f 6e 73 3b 0a 23 69 66 6e 64 Functions;.#ifnd
2b750 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 ef SQLITE_OMIT_W
2b760 53 44 0a 65 78 74 65 72 6e 20 69 6e 74 20 73 71 SD.extern int sq
2b770 6c 69 74 65 33 50 65 6e 64 69 6e 67 42 79 74 65 lite3PendingByte
2b780 3b 0a 23 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a ;.#endif.#endif.
2b790 23 69 66 64 65 66 20 56 44 42 45 5f 50 52 4f 46 #ifdef VDBE_PROF
2b7a0 49 4c 45 0a 65 78 74 65 72 6e 20 73 71 6c 69 74 ILE.extern sqlit
2b7b0 65 33 5f 75 69 6e 74 36 34 20 73 71 6c 69 74 65 e3_uint64 sqlite
2b7c0 33 4e 50 72 6f 66 69 6c 65 43 6e 74 3b 0a 23 65 3NProfileCnt;.#e
2b7d0 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 ndif.void sqlite
2b7e0 33 52 6f 6f 74 50 61 67 65 4d 6f 76 65 64 28 73 3RootPageMoved(s
2b7f0 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 69 6e qlite3*, int, in
2b800 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
2b810 6c 69 74 65 33 52 65 69 6e 64 65 78 28 50 61 72 lite3Reindex(Par
2b820 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b se*, Token*, Tok
2b830 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
2b840 65 33 41 6c 74 65 72 46 75 6e 63 74 69 6f 6e 73 e3AlterFunctions
2b850 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c (void);.void sql
2b860 69 74 65 33 41 6c 74 65 72 52 65 6e 61 6d 65 54 ite3AlterRenameT
2b870 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 63 able(Parse*, Src
2b880 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a List*, Token*);.
2b890 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 6f int sqlite3GetTo
2b8a0 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e ken(const unsign
2b8b0 65 64 20 63 68 61 72 20 2a 2c 20 69 6e 74 20 2a ed char *, int *
2b8c0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4e );.void sqlite3N
2b8d0 65 73 74 65 64 50 61 72 73 65 28 50 61 72 73 65 estedParse(Parse
2b8e0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 *, const char*,
2b8f0 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ...);.void sqlit
2b900 65 33 45 78 70 69 72 65 50 72 65 70 61 72 65 64 e3ExpirePrepared
2b910 53 74 61 74 65 6d 65 6e 74 73 28 73 71 6c 69 74 Statements(sqlit
2b920 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 e3*);.int sqlite
2b930 33 43 6f 64 65 53 75 62 73 65 6c 65 63 74 28 50 3CodeSubselect(P
2b940 61 72 73 65 2a 2c 20 45 78 70 72 20 2a 2c 20 69 arse*, Expr *, i
2b950 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
2b960 71 6c 69 74 65 33 53 65 6c 65 63 74 50 72 65 70 qlite3SelectPrep
2b970 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a (Parse*, Select*
2b980 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 29 3b , NameContext*);
2b990 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c .void sqlite3Sel
2b9a0 65 63 74 57 72 6f 6e 67 4e 75 6d 54 65 72 6d 73 ectWrongNumTerms
2b9b0 45 72 72 6f 72 28 50 61 72 73 65 20 2a 70 50 61 Error(Parse *pPa
2b9c0 72 73 65 2c 20 53 65 6c 65 63 74 20 2a 70 29 3b rse, Select *p);
2b9d0 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 74 63 .int sqlite3Matc
2b9e0 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e 73 74 20 hSpanName(const
2b9f0 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
2ba00 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c r*, const char*,
2ba10 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 const char*);.i
2ba20 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 nt sqlite3Resolv
2ba30 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 6d 65 43 eExprNames(NameC
2ba40 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a 29 3b ontext*, Expr*);
2ba50 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f .int sqlite3Reso
2ba60 6c 76 65 45 78 70 72 4c 69 73 74 4e 61 6d 65 73 lveExprListNames
2ba70 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 45 (NameContext*, E
2ba80 78 70 72 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 xprList*);.void
2ba90 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 53 65 sqlite3ResolveSe
2baa0 6c 65 63 74 4e 61 6d 65 73 28 50 61 72 73 65 2a lectNames(Parse*
2bab0 2c 20 53 65 6c 65 63 74 2a 2c 20 4e 61 6d 65 43 , Select*, NameC
2bac0 6f 6e 74 65 78 74 2a 29 3b 0a 76 6f 69 64 20 73 ontext*);.void s
2bad0 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 53 65 6c qlite3ResolveSel
2bae0 66 52 65 66 65 72 65 6e 63 65 28 50 61 72 73 65 fReference(Parse
2baf0 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 45 78 70 *,Table*,int,Exp
2bb00 72 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b 0a 69 r*,ExprList*);.i
2bb10 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 nt sqlite3Resolv
2bb20 65 4f 72 64 65 72 47 72 6f 75 70 42 79 28 50 61 eOrderGroupBy(Pa
2bb30 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 45 rse*, Select*, E
2bb40 78 70 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 74 20 xprList*, const
2bb50 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c char*);.void sql
2bb60 69 74 65 33 43 6f 6c 75 6d 6e 44 65 66 61 75 6c ite3ColumnDefaul
2bb70 74 28 56 64 62 65 20 2a 2c 20 54 61 62 6c 65 20 t(Vdbe *, Table
2bb80 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f *, int, int);.vo
2bb90 69 64 20 73 71 6c 69 74 65 33 41 6c 74 65 72 46 id sqlite3AlterF
2bba0 69 6e 69 73 68 41 64 64 43 6f 6c 75 6d 6e 28 50 inishAddColumn(P
2bbb0 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 29 arse *, Token *)
2bbc0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c ;.void sqlite3Al
2bbd0 74 65 72 42 65 67 69 6e 41 64 64 43 6f 6c 75 6d terBeginAddColum
2bbe0 6e 28 50 61 72 73 65 20 2a 2c 20 53 72 63 4c 69 n(Parse *, SrcLi
2bbf0 73 74 20 2a 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a st *);.CollSeq *
2bc00 73 71 6c 69 74 65 33 47 65 74 43 6f 6c 6c 53 65 sqlite3GetCollSe
2bc10 71 28 50 61 72 73 65 2a 2c 20 75 38 2c 20 43 6f q(Parse*, u8, Co
2bc20 6c 6c 53 65 71 20 2a 2c 20 63 6f 6e 73 74 20 63 llSeq *, const c
2bc30 68 61 72 2a 29 3b 0a 63 68 61 72 20 73 71 6c 69 har*);.char sqli
2bc40 74 65 33 41 66 66 69 6e 69 74 79 54 79 70 65 28 te3AffinityType(
2bc50 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 75 38 2a const char*, u8*
2bc60 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
2bc70 6e 61 6c 79 7a 65 28 50 61 72 73 65 2a 2c 20 54 nalyze(Parse*, T
2bc80 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a oken*, Token*);.
2bc90 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 76 6f 6b int sqlite3Invok
2bca0 65 42 75 73 79 48 61 6e 64 6c 65 72 28 42 75 73 eBusyHandler(Bus
2bcb0 79 48 61 6e 64 6c 65 72 2a 2c 20 73 71 6c 69 74 yHandler*, sqlit
2bcc0 65 33 5f 66 69 6c 65 2a 29 3b 0a 69 6e 74 20 73 e3_file*);.int s
2bcd0 71 6c 69 74 65 33 46 69 6e 64 44 62 28 73 71 6c qlite3FindDb(sql
2bce0 69 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a ite3*, Token*);.
2bcf0 69 6e 74 20 73 71 6c 69 74 65 33 46 69 6e 64 44 int sqlite3FindD
2bd00 62 4e 61 6d 65 28 73 71 6c 69 74 65 33 20 2a 2c bName(sqlite3 *,
2bd10 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a const char *);.
2bd20 69 6e 74 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 int sqlite3Analy
2bd30 73 69 73 4c 6f 61 64 28 73 71 6c 69 74 65 33 2a sisLoad(sqlite3*
2bd40 2c 69 6e 74 20 69 44 42 29 3b 0a 76 6f 69 64 20 ,int iDB);.void
2bd50 73 71 6c 69 74 65 33 44 65 6c 65 74 65 49 6e 64 sqlite3DeleteInd
2bd60 65 78 53 61 6d 70 6c 65 73 28 73 71 6c 69 74 65 exSamples(sqlite
2bd70 33 2a 2c 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 3*,Index*);.void
2bd80 20 73 71 6c 69 74 65 33 44 65 66 61 75 6c 74 52 sqlite3DefaultR
2bd90 6f 77 45 73 74 28 49 6e 64 65 78 2a 29 3b 0a 76 owEst(Index*);.v
2bda0 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 73 oid sqlite3Regis
2bdb0 74 65 72 4c 69 6b 65 46 75 6e 63 74 69 6f 6e 73 terLikeFunctions
2bdc0 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 29 3b (sqlite3*, int);
2bdd0 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 73 4c 69 .int sqlite3IsLi
2bde0 6b 65 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 keFunction(sqlit
2bdf0 65 33 2a 2c 45 78 70 72 2a 2c 69 6e 74 2a 2c 63 e3*,Expr*,int*,c
2be00 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
2be10 74 65 33 53 63 68 65 6d 61 43 6c 65 61 72 28 76 te3SchemaClear(v
2be20 6f 69 64 20 2a 29 3b 0a 53 63 68 65 6d 61 20 2a oid *);.Schema *
2be30 73 71 6c 69 74 65 33 53 63 68 65 6d 61 47 65 74 sqlite3SchemaGet
2be40 28 73 71 6c 69 74 65 33 20 2a 2c 20 42 74 72 65 (sqlite3 *, Btre
2be50 65 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 e *);.int sqlite
2be60 33 53 63 68 65 6d 61 54 6f 49 6e 64 65 78 28 73 3SchemaToIndex(s
2be70 71 6c 69 74 65 33 20 2a 64 62 2c 20 53 63 68 65 qlite3 *db, Sche
2be80 6d 61 20 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a ma *);.KeyInfo *
2be90 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f 41 6c sqlite3KeyInfoAl
2bea0 6c 6f 63 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 loc(sqlite3*,int
2beb0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
2bec0 74 65 33 4b 65 79 49 6e 66 6f 55 6e 72 65 66 28 te3KeyInfoUnref(
2bed0 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e KeyInfo*);.KeyIn
2bee0 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e fo *sqlite3KeyIn
2bef0 66 6f 52 65 66 28 4b 65 79 49 6e 66 6f 2a 29 3b foRef(KeyInfo*);
2bf00 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 .KeyInfo *sqlite
2bf10 33 4b 65 79 49 6e 66 6f 4f 66 49 6e 64 65 78 28 3KeyInfoOfIndex(
2bf20 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 29 3b Parse*, Index*);
2bf30 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 .#ifdef SQLITE_D
2bf40 45 42 55 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 EBUG.int sqlite3
2bf50 4b 65 79 49 6e 66 6f 49 73 57 72 69 74 65 61 62 KeyInfoIsWriteab
2bf60 6c 65 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 23 65 le(KeyInfo*);.#e
2bf70 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 ndif.int sqlite3
2bf80 43 72 65 61 74 65 46 75 6e 63 28 73 71 6c 69 74 CreateFunc(sqlit
2bf90 65 33 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 e3 *, const char
2bfa0 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 76 6f *, int, int, vo
2bfb0 69 64 20 2a 2c 0a 20 20 76 6f 69 64 20 28 2a 29 id *,. void (*)
2bfc0 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
2bfd0 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 *,int,sqlite3_va
2bfe0 6c 75 65 20 2a 2a 29 2c 0a 20 20 76 6f 69 64 20 lue **),. void
2bff0 28 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 (*)(sqlite3_cont
2c000 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 ext*,int,sqlite3
2c010 5f 76 61 6c 75 65 20 2a 2a 29 2c 20 76 6f 69 64 _value **), void
2c020 20 28 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e (*)(sqlite3_con
2c030 74 65 78 74 2a 29 2c 0a 20 20 46 75 6e 63 44 65 text*),. FuncDe
2c040 73 74 72 75 63 74 6f 72 20 2a 70 44 65 73 74 72 structor *pDestr
2c050 75 63 74 6f 72 0a 29 3b 0a 76 6f 69 64 20 73 71 uctor.);.void sq
2c060 6c 69 74 65 33 4f 6f 6d 46 61 75 6c 74 28 73 71 lite3OomFault(sq
2c070 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
2c080 6c 69 74 65 33 4f 6f 6d 43 6c 65 61 72 28 73 71 lite3OomClear(sq
2c090 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c lite3*);.int sql
2c0a0 69 74 65 33 41 70 69 45 78 69 74 28 73 71 6c 69 ite3ApiExit(sqli
2c0b0 74 65 33 20 2a 64 62 2c 20 69 6e 74 29 3b 0a 69 te3 *db, int);.i
2c0c0 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 6e 54 65 nt sqlite3OpenTe
2c0d0 6d 70 44 61 74 61 62 61 73 65 28 50 61 72 73 65 mpDatabase(Parse
2c0e0 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 *);..void sqlit
2c0f0 65 33 53 74 72 41 63 63 75 6d 49 6e 69 74 28 53 e3StrAccumInit(S
2c100 74 72 41 63 63 75 6d 2a 2c 20 73 71 6c 69 74 65 trAccum*, sqlite
2c110 33 2a 2c 20 63 68 61 72 2a 2c 20 69 6e 74 2c 20 3*, char*, int,
2c120 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
2c130 65 33 53 74 72 41 63 63 75 6d 41 70 70 65 6e 64 e3StrAccumAppend
2c140 28 53 74 72 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 (StrAccum*,const
2c150 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 char*,int);.voi
2c160 64 20 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 d sqlite3StrAccu
2c170 6d 41 70 70 65 6e 64 41 6c 6c 28 53 74 72 41 63 mAppendAll(StrAc
2c180 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a cum*,const char*
2c190 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
2c1a0 70 70 65 6e 64 43 68 61 72 28 53 74 72 41 63 63 ppendChar(StrAcc
2c1b0 75 6d 2a 2c 69 6e 74 2c 63 68 61 72 29 3b 0a 63 um*,int,char);.c
2c1c0 68 61 72 20 2a 73 71 6c 69 74 65 33 53 74 72 41 har *sqlite3StrA
2c1d0 63 63 75 6d 46 69 6e 69 73 68 28 53 74 72 41 63 ccumFinish(StrAc
2c1e0 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 cum*);.void sqli
2c1f0 74 65 33 53 74 72 41 63 63 75 6d 52 65 73 65 74 te3StrAccumReset
2c200 28 53 74 72 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 (StrAccum*);.voi
2c210 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 44 d sqlite3SelectD
2c220 65 73 74 49 6e 69 74 28 53 65 6c 65 63 74 44 65 estInit(SelectDe
2c230 73 74 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 45 78 st*,int,int);.Ex
2c240 70 72 20 2a 73 71 6c 69 74 65 33 43 72 65 61 74 pr *sqlite3Creat
2c250 65 43 6f 6c 75 6d 6e 45 78 70 72 28 73 71 6c 69 eColumnExpr(sqli
2c260 74 65 33 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a te3 *, SrcList *
2c270 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 0a 76 6f , int, int);..vo
2c280 69 64 20 73 71 6c 69 74 65 33 42 61 63 6b 75 70 id sqlite3Backup
2c290 52 65 73 74 61 72 74 28 73 71 6c 69 74 65 33 5f Restart(sqlite3_
2c2a0 62 61 63 6b 75 70 20 2a 29 3b 0a 76 6f 69 64 20 backup *);.void
2c2b0 73 71 6c 69 74 65 33 42 61 63 6b 75 70 55 70 64 sqlite3BackupUpd
2c2c0 61 74 65 28 73 71 6c 69 74 65 33 5f 62 61 63 6b ate(sqlite3_back
2c2d0 75 70 20 2a 2c 20 50 67 6e 6f 2c 20 63 6f 6e 73 up *, Pgno, cons
2c2e0 74 20 75 38 20 2a 29 3b 0a 0a 23 69 66 6e 64 65 t u8 *);..#ifnde
2c2f0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 55 f SQLITE_OMIT_SU
2c300 42 51 55 45 52 59 0a 69 6e 74 20 73 71 6c 69 74 BQUERY.int sqlit
2c310 65 33 45 78 70 72 43 68 65 63 6b 49 4e 28 50 61 e3ExprCheckIN(Pa
2c320 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 23 65 rse*, Expr*);.#e
2c330 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
2c340 69 74 65 33 45 78 70 72 43 68 65 63 6b 49 4e 28 ite3ExprCheckIN(
2c350 78 2c 79 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 x,y) SQLITE_OK.#
2c360 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
2c370 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
2c380 33 5f 4f 52 5f 53 54 41 54 34 0a 76 6f 69 64 20 3_OR_STAT4.void
2c390 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 46 75 sqlite3AnalyzeFu
2c3a0 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 nctions(void);.i
2c3b0 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 50 nt sqlite3Stat4P
2c3c0 72 6f 62 65 53 65 74 56 61 6c 75 65 28 0a 20 20 robeSetValue(.
2c3d0 20 20 50 61 72 73 65 2a 2c 49 6e 64 65 78 2a 2c Parse*,Index*,
2c3e0 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 2a 2a UnpackedRecord**
2c3f0 2c 45 78 70 72 2a 2c 69 6e 74 2c 69 6e 74 2c 69 ,Expr*,int,int,i
2c400 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
2c410 33 53 74 61 74 34 56 61 6c 75 65 46 72 6f 6d 45 3Stat4ValueFromE
2c420 78 70 72 28 50 61 72 73 65 2a 2c 20 45 78 70 72 xpr(Parse*, Expr
2c430 2a 2c 20 75 38 2c 20 73 71 6c 69 74 65 33 5f 76 *, u8, sqlite3_v
2c440 61 6c 75 65 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 alue**);.void sq
2c450 6c 69 74 65 33 53 74 61 74 34 50 72 6f 62 65 46 lite3Stat4ProbeF
2c460 72 65 65 28 55 6e 70 61 63 6b 65 64 52 65 63 6f ree(UnpackedReco
2c470 72 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 rd*);.int sqlite
2c480 33 53 74 61 74 34 43 6f 6c 75 6d 6e 28 73 71 6c 3Stat4Column(sql
2c490 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 76 6f 69 ite3*, const voi
2c4a0 64 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 73 71 d*, int, int, sq
2c4b0 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a lite3_value**);.
2c4c0 63 68 61 72 20 73 71 6c 69 74 65 33 49 6e 64 65 char sqlite3Inde
2c4d0 78 43 6f 6c 75 6d 6e 41 66 66 69 6e 69 74 79 28 xColumnAffinity(
2c4e0 73 71 6c 69 74 65 33 2a 2c 20 49 6e 64 65 78 2a sqlite3*, Index*
2c4f0 2c 20 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a , int);.#endif..
2c500 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 66 /*.** The interf
2c510 61 63 65 20 74 6f 20 74 68 65 20 4c 45 4d 4f 4e ace to the LEMON
2c520 2d 67 65 6e 65 72 61 74 65 64 20 70 61 72 73 65 -generated parse
2c530 72 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c r.*/.#ifndef SQL
2c540 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e ITE_AMALGAMATION
2c550 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 . void *sqlite3
2c560 50 61 72 73 65 72 41 6c 6c 6f 63 28 76 6f 69 64 ParserAlloc(void
2c570 2a 28 2a 29 28 75 36 34 29 29 3b 0a 20 20 76 6f *(*)(u64));. vo
2c580 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 id sqlite3Parser
2c590 46 72 65 65 28 76 6f 69 64 2a 2c 20 76 6f 69 64 Free(void*, void
2c5a0 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 23 65 6e (*)(void*));.#en
2c5b0 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
2c5c0 50 61 72 73 65 72 28 76 6f 69 64 2a 2c 20 69 6e Parser(void*, in
2c5d0 74 2c 20 54 6f 6b 65 6e 2c 20 50 61 72 73 65 2a t, Token, Parse*
2c5e0 29 3b 0a 23 69 66 64 65 66 20 59 59 54 52 41 43 );.#ifdef YYTRAC
2c5f0 4b 4d 41 58 53 54 41 43 4b 44 45 50 54 48 0a 20 KMAXSTACKDEPTH.
2c600 20 69 6e 74 20 73 71 6c 69 74 65 33 50 61 72 73 int sqlite3Pars
2c610 65 72 53 74 61 63 6b 50 65 61 6b 28 76 6f 69 64 erStackPeak(void
2c620 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 76 6f 69 64 *);.#endif..void
2c630 20 73 71 6c 69 74 65 33 41 75 74 6f 4c 6f 61 64 sqlite3AutoLoad
2c640 45 78 74 65 6e 73 69 6f 6e 73 28 73 71 6c 69 74 Extensions(sqlit
2c650 65 33 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 e3*);.#ifndef SQ
2c660 4c 49 54 45 5f 4f 4d 49 54 5f 4c 4f 41 44 5f 45 LITE_OMIT_LOAD_E
2c670 58 54 45 4e 53 49 4f 4e 0a 20 20 76 6f 69 64 20 XTENSION. void
2c680 73 71 6c 69 74 65 33 43 6c 6f 73 65 45 78 74 65 sqlite3CloseExte
2c690 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 nsions(sqlite3*)
2c6a0 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
2c6b0 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 45 78 74 sqlite3CloseExt
2c6c0 65 6e 73 69 6f 6e 73 28 58 29 0a 23 65 6e 64 69 ensions(X).#endi
2c6d0 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 f..#ifndef SQLIT
2c6e0 45 5f 4f 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 E_OMIT_SHARED_CA
2c6f0 43 48 45 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 CHE. void sqlit
2c700 65 33 54 61 62 6c 65 4c 6f 63 6b 28 50 61 72 73 e3TableLock(Pars
2c710 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 e *, int, int, u
2c720 38 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 8, const char *)
2c730 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e ;.#else. #defin
2c740 65 20 73 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f e sqlite3TableLo
2c750 63 6b 28 76 2c 77 2c 78 2c 79 2c 7a 29 0a 23 65 ck(v,w,x,y,z).#e
2c760 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 4c ndif..#ifdef SQL
2c770 49 54 45 5f 54 45 53 54 0a 20 20 69 6e 74 20 73 ITE_TEST. int s
2c780 71 6c 69 74 65 33 55 74 66 38 54 6f 38 28 75 6e qlite3Utf8To8(un
2c790 73 69 67 6e 65 64 20 63 68 61 72 2a 29 3b 0a 23 signed char*);.#
2c7a0 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
2c7b0 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
2c7c0 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 69 6e 65 LTABLE.# define
2c7d0 20 73 71 6c 69 74 65 33 56 74 61 62 43 6c 65 61 sqlite3VtabClea
2c7e0 72 28 59 29 0a 23 20 20 64 65 66 69 6e 65 20 73 r(Y).# define s
2c7f0 71 6c 69 74 65 33 56 74 61 62 53 79 6e 63 28 58 qlite3VtabSync(X
2c800 2c 59 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 ,Y) SQLITE_OK.#
2c810 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
2c820 74 61 62 52 6f 6c 6c 62 61 63 6b 28 58 29 0a 23 tabRollback(X).#
2c830 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
2c840 56 74 61 62 43 6f 6d 6d 69 74 28 58 29 0a 23 20 VtabCommit(X).#
2c850 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
2c860 74 61 62 49 6e 53 79 6e 63 28 64 62 29 20 30 0a tabInSync(db) 0.
2c870 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
2c880 33 56 74 61 62 4c 6f 63 6b 28 58 29 0a 23 20 20 3VtabLock(X).#
2c890 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 define sqlite3Vt
2c8a0 61 62 55 6e 6c 6f 63 6b 28 58 29 0a 23 20 20 64 abUnlock(X).# d
2c8b0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
2c8c0 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 58 29 0a 23 bUnlockList(X).#
2c8d0 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
2c8e0 56 74 61 62 53 61 76 65 70 6f 69 6e 74 28 58 2c VtabSavepoint(X,
2c8f0 20 59 2c 20 5a 29 20 53 51 4c 49 54 45 5f 4f 4b Y, Z) SQLITE_OK
2c900 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
2c910 65 33 47 65 74 56 54 61 62 6c 65 28 58 2c 59 29 e3GetVTable(X,Y)
2c920 20 20 28 28 56 54 61 62 6c 65 2a 29 30 29 0a 23 ((VTable*)0).#
2c930 65 6c 73 65 0a 20 20 20 76 6f 69 64 20 73 71 6c else. void sql
2c940 69 74 65 33 56 74 61 62 43 6c 65 61 72 28 73 71 ite3VtabClear(sq
2c950 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 lite3 *db, Table
2c960 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 *);. void sqli
2c970 74 65 33 56 74 61 62 44 69 73 63 6f 6e 6e 65 63 te3VtabDisconnec
2c980 74 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 t(sqlite3 *db, T
2c990 61 62 6c 65 20 2a 70 29 3b 0a 20 20 20 69 6e 74 able *p);. int
2c9a0 20 73 71 6c 69 74 65 33 56 74 61 62 53 79 6e 63 sqlite3VtabSync
2c9b0 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 56 64 (sqlite3 *db, Vd
2c9c0 62 65 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c be*);. int sql
2c9d0 69 74 65 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b ite3VtabRollback
2c9e0 28 73 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 (sqlite3 *db);.
2c9f0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 int sqlite3Vta
2ca00 62 43 6f 6d 6d 69 74 28 73 71 6c 69 74 65 33 20 bCommit(sqlite3
2ca10 2a 64 62 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 *db);. void sq
2ca20 6c 69 74 65 33 56 74 61 62 4c 6f 63 6b 28 56 54 lite3VtabLock(VT
2ca30 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 able *);. void
2ca40 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f sqlite3VtabUnlo
2ca50 63 6b 28 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 ck(VTable *);.
2ca60 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 void sqlite3Vta
2ca70 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 73 71 6c 69 bUnlockList(sqli
2ca80 74 65 33 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 te3*);. int sq
2ca90 6c 69 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 lite3VtabSavepoi
2caa0 6e 74 28 73 71 6c 69 74 65 33 20 2a 2c 20 69 6e nt(sqlite3 *, in
2cab0 74 2c 20 69 6e 74 29 3b 0a 20 20 20 76 6f 69 64 t, int);. void
2cac0 20 73 71 6c 69 74 65 33 56 74 61 62 49 6d 70 6f sqlite3VtabImpo
2cad0 72 74 45 72 72 6d 73 67 28 56 64 62 65 2a 2c 20 rtErrmsg(Vdbe*,
2cae0 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 29 3b 0a sqlite3_vtab*);.
2caf0 20 20 20 56 54 61 62 6c 65 20 2a 73 71 6c 69 74 VTable *sqlit
2cb00 65 33 47 65 74 56 54 61 62 6c 65 28 73 71 6c 69 e3GetVTable(sqli
2cb10 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 te3*, Table*);.
2cb20 20 20 4d 6f 64 75 6c 65 20 2a 73 71 6c 69 74 65 Module *sqlite
2cb30 33 56 74 61 62 43 72 65 61 74 65 4d 6f 64 75 6c 3VtabCreateModul
2cb40 65 28 0a 20 20 20 20 20 73 71 6c 69 74 65 33 2a e(. sqlite3*
2cb50 2c 0a 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 ,. const cha
2cb60 72 2a 2c 0a 20 20 20 20 20 63 6f 6e 73 74 20 73 r*,. const s
2cb70 71 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 2a 2c 0a qlite3_module*,.
2cb80 20 20 20 20 20 76 6f 69 64 2a 2c 0a 20 20 20 20 void*,.
2cb90 20 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 0a void(*)(void*).
2cba0 20 20 20 29 3b 0a 23 20 20 64 65 66 69 6e 65 20 );.# define
2cbb0 73 71 6c 69 74 65 33 56 74 61 62 49 6e 53 79 6e sqlite3VtabInSyn
2cbc0 63 28 64 62 29 20 28 28 64 62 29 2d 3e 6e 56 54 c(db) ((db)->nVT
2cbd0 72 61 6e 73 3e 30 20 26 26 20 28 64 62 29 2d 3e rans>0 && (db)->
2cbe0 61 56 54 72 61 6e 73 3d 3d 30 29 0a 23 65 6e 64 aVTrans==0).#end
2cbf0 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 if.int sqlite3Vt
2cc00 61 62 45 70 6f 6e 79 6d 6f 75 73 54 61 62 6c 65 abEponymousTable
2cc10 49 6e 69 74 28 50 61 72 73 65 2a 2c 4d 6f 64 75 Init(Parse*,Modu
2cc20 6c 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 le*);.void sqlit
2cc30 65 33 56 74 61 62 45 70 6f 6e 79 6d 6f 75 73 54 e3VtabEponymousT
2cc40 61 62 6c 65 43 6c 65 61 72 28 73 71 6c 69 74 65 ableClear(sqlite
2cc50 33 2a 2c 4d 6f 64 75 6c 65 2a 29 3b 0a 76 6f 69 3*,Module*);.voi
2cc60 64 20 73 71 6c 69 74 65 33 56 74 61 62 4d 61 6b d sqlite3VtabMak
2cc70 65 57 72 69 74 61 62 6c 65 28 50 61 72 73 65 2a eWritable(Parse*
2cc80 2c 54 61 62 6c 65 2a 29 3b 0a 76 6f 69 64 20 73 ,Table*);.void s
2cc90 71 6c 69 74 65 33 56 74 61 62 42 65 67 69 6e 50 qlite3VtabBeginP
2cca0 61 72 73 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b arse(Parse*, Tok
2ccb0 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b en*, Token*, Tok
2ccc0 65 6e 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 en*, int);.void
2ccd0 73 71 6c 69 74 65 33 56 74 61 62 46 69 6e 69 73 sqlite3VtabFinis
2cce0 68 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 54 hParse(Parse*, T
2ccf0 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
2cd00 69 74 65 33 56 74 61 62 41 72 67 49 6e 69 74 28 ite3VtabArgInit(
2cd10 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 Parse*);.void sq
2cd20 6c 69 74 65 33 56 74 61 62 41 72 67 45 78 74 65 lite3VtabArgExte
2cd30 6e 64 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e nd(Parse*, Token
2cd40 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 *);.int sqlite3V
2cd50 74 61 62 43 61 6c 6c 43 72 65 61 74 65 28 73 71 tabCallCreate(sq
2cd60 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e lite3*, int, con
2cd70 73 74 20 63 68 61 72 20 2a 2c 20 63 68 61 72 20 st char *, char
2cd80 2a 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 **);.int sqlite3
2cd90 56 74 61 62 43 61 6c 6c 43 6f 6e 6e 65 63 74 28 VtabCallConnect(
2cda0 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 29 3b Parse*, Table*);
2cdb0 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 .int sqlite3Vtab
2cdc0 43 61 6c 6c 44 65 73 74 72 6f 79 28 73 71 6c 69 CallDestroy(sqli
2cdd0 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 te3*, int, const
2cde0 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 char *);.int sq
2cdf0 6c 69 74 65 33 56 74 61 62 42 65 67 69 6e 28 73 lite3VtabBegin(s
2ce00 71 6c 69 74 65 33 20 2a 2c 20 56 54 61 62 6c 65 qlite3 *, VTable
2ce10 20 2a 29 3b 0a 46 75 6e 63 44 65 66 20 2a 73 71 *);.FuncDef *sq
2ce20 6c 69 74 65 33 56 74 61 62 4f 76 65 72 6c 6f 61 lite3VtabOverloa
2ce30 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 dFunction(sqlite
2ce40 33 20 2a 2c 46 75 6e 63 44 65 66 2a 2c 20 69 6e 3 *,FuncDef*, in
2ce50 74 20 6e 41 72 67 2c 20 45 78 70 72 2a 29 3b 0a t nArg, Expr*);.
2ce60 76 6f 69 64 20 73 71 6c 69 74 65 33 49 6e 76 61 void sqlite3Inva
2ce70 6c 69 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 lidFunction(sqli
2ce80 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 te3_context*,int
2ce90 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a ,sqlite3_value**
2cea0 29 3b 0a 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 );.sqlite3_int64
2ceb0 20 73 71 6c 69 74 65 33 53 74 6d 74 43 75 72 72 sqlite3StmtCurr
2cec0 65 6e 74 54 69 6d 65 28 73 71 6c 69 74 65 33 5f entTime(sqlite3_
2ced0 63 6f 6e 74 65 78 74 2a 29 3b 0a 69 6e 74 20 73 context*);.int s
2cee0 71 6c 69 74 65 33 56 64 62 65 50 61 72 61 6d 65 qlite3VdbeParame
2cef0 74 65 72 49 6e 64 65 78 28 56 64 62 65 2a 2c 20 terIndex(Vdbe*,
2cf00 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 const char*, int
2cf10 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 72 );.int sqlite3Tr
2cf20 61 6e 73 66 65 72 42 69 6e 64 69 6e 67 73 28 73 ansferBindings(s
2cf30 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a 2c 20 73 qlite3_stmt *, s
2cf40 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a 29 3b 0a qlite3_stmt *);.
2cf50 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 void sqlite3Pars
2cf60 65 72 52 65 73 65 74 28 50 61 72 73 65 2a 29 3b erReset(Parse*);
2cf70 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 70 72 .int sqlite3Repr
2cf80 65 70 61 72 65 28 56 64 62 65 2a 29 3b 0a 76 6f epare(Vdbe*);.vo
2cf90 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 id sqlite3ExprLi
2cfa0 73 74 43 68 65 63 6b 4c 65 6e 67 74 68 28 50 61 stCheckLength(Pa
2cfb0 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c rse*, ExprList*,
2cfc0 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 43 const char*);.C
2cfd0 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 42 ollSeq *sqlite3B
2cfe0 69 6e 61 72 79 43 6f 6d 70 61 72 65 43 6f 6c 6c inaryCompareColl
2cff0 53 65 71 28 50 61 72 73 65 20 2a 2c 20 45 78 70 Seq(Parse *, Exp
2d000 72 20 2a 2c 20 45 78 70 72 20 2a 29 3b 0a 69 6e r *, Expr *);.in
2d010 74 20 73 71 6c 69 74 65 33 54 65 6d 70 49 6e 4d t sqlite3TempInM
2d020 65 6d 6f 72 79 28 63 6f 6e 73 74 20 73 71 6c 69 emory(const sqli
2d030 74 65 33 2a 29 3b 0a 63 6f 6e 73 74 20 63 68 61 te3*);.const cha
2d040 72 20 2a 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 r *sqlite3Journa
2d050 6c 4d 6f 64 65 6e 61 6d 65 28 69 6e 74 29 3b 0a lModename(int);.
2d060 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
2d070 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 73 71 MIT_WAL. int sq
2d080 6c 69 74 65 33 43 68 65 63 6b 70 6f 69 6e 74 28 lite3Checkpoint(
2d090 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 69 sqlite3*, int, i
2d0a0 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 3b nt, int*, int*);
2d0b0 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 57 61 . int sqlite3Wa
2d0c0 6c 44 65 66 61 75 6c 74 48 6f 6f 6b 28 76 6f 69 lDefaultHook(voi
2d0d0 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 d*,sqlite3*,cons
2d0e0 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 23 65 t char*,int);.#e
2d0f0 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
2d100 49 54 45 5f 4f 4d 49 54 5f 43 54 45 0a 20 20 57 ITE_OMIT_CTE. W
2d110 69 74 68 20 2a 73 71 6c 69 74 65 33 57 69 74 68 ith *sqlite3With
2d120 41 64 64 28 50 61 72 73 65 2a 2c 57 69 74 68 2a Add(Parse*,With*
2d130 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 ,Token*,ExprList
2d140 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a 20 20 76 6f *,Select*);. vo
2d150 69 64 20 73 71 6c 69 74 65 33 57 69 74 68 44 65 id sqlite3WithDe
2d160 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 57 69 lete(sqlite3*,Wi
2d170 74 68 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c th*);. void sql
2d180 69 74 65 33 57 69 74 68 50 75 73 68 28 50 61 72 ite3WithPush(Par
2d190 73 65 2a 2c 20 57 69 74 68 2a 2c 20 75 38 29 3b se*, With*, u8);
2d1a0 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 73 .#else.#define s
2d1b0 71 6c 69 74 65 33 57 69 74 68 50 75 73 68 28 78 qlite3WithPush(x
2d1c0 2c 79 2c 7a 29 0a 23 64 65 66 69 6e 65 20 73 71 ,y,z).#define sq
2d1d0 6c 69 74 65 33 57 69 74 68 44 65 6c 65 74 65 28 lite3WithDelete(
2d1e0 78 2c 79 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e x,y).#endif.#ifn
2d1f0 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
2d200 55 50 53 45 52 54 0a 20 20 76 6f 69 64 20 73 71 UPSERT. void sq
2d210 6c 69 74 65 33 55 70 73 65 72 74 44 65 6c 65 74 lite3UpsertDelet
2d220 65 28 73 71 6c 69 74 65 33 2a 2c 55 70 73 65 72 e(sqlite3*,Upser
2d230 74 2a 29 3b 0a 20 20 55 70 73 65 72 74 20 2a 73 t*);. Upsert *s
2d240 71 6c 69 74 65 33 55 70 73 65 72 74 44 75 70 28 qlite3UpsertDup(
2d250 73 71 6c 69 74 65 33 2a 2c 55 70 73 65 72 74 2a sqlite3*,Upsert*
2d260 29 3b 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 );.#else.#define
2d270 20 73 71 6c 69 74 65 33 55 70 73 65 72 74 44 65 sqlite3UpsertDe
2d280 6c 65 74 65 28 78 2c 79 29 0a 23 64 65 66 69 6e lete(x,y).#defin
2d290 65 20 73 71 6c 69 74 65 33 55 70 73 65 72 74 44 e sqlite3UpsertD
2d2a0 75 70 28 78 2c 79 29 20 28 28 55 70 73 65 72 74 up(x,y) ((Upsert
2d2b0 2a 29 30 29 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a *)0).#endif.../*
2d2c0 20 44 65 63 6c 61 72 61 74 69 6f 6e 73 20 66 6f Declarations fo
2d2d0 72 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e 20 66 r functions in f
2d2e0 6b 65 79 2e 63 2e 20 41 6c 6c 20 6f 66 20 74 68 key.c. All of th
2d2f0 65 73 65 20 61 72 65 20 72 65 70 6c 61 63 65 64 ese are replaced
2d300 20 62 79 0a 2a 2a 20 6e 6f 2d 6f 70 20 6d 61 63 by.** no-op mac
2d310 72 6f 73 20 69 66 20 4f 4d 49 54 5f 46 4f 52 45 ros if OMIT_FORE
2d320 49 47 4e 5f 4b 45 59 20 69 73 20 64 65 66 69 6e IGN_KEY is defin
2d330 65 64 2e 20 49 6e 20 74 68 69 73 20 63 61 73 65 ed. In this case
2d340 20 6e 6f 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b no foreign.** k
2d350 65 79 20 66 75 6e 63 74 69 6f 6e 61 6c 69 74 79 ey functionality
2d360 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2e 20 49 is available. I
2d370 66 20 4f 4d 49 54 5f 54 52 49 47 47 45 52 20 69 f OMIT_TRIGGER i
2d380 73 20 64 65 66 69 6e 65 64 20 62 75 74 0a 2a 2a s defined but.**
2d390 20 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 OMIT_FOREIGN_KE
2d3a0 59 20 69 73 20 6e 6f 74 2c 20 6f 6e 6c 79 20 73 Y is not, only s
2d3b0 6f 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 74 ome of the funct
2d3c0 69 6f 6e 73 20 61 72 65 20 6e 6f 2d 6f 70 65 64 ions are no-oped
2d3d0 2e 20 49 6e 0a 2a 2a 20 74 68 69 73 20 63 61 73 . In.** this cas
2d3e0 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 61 e foreign keys a
2d3f0 72 65 20 70 61 72 73 65 64 2c 20 62 75 74 20 6e re parsed, but n
2d400 6f 20 6f 74 68 65 72 20 66 75 6e 63 74 69 6f 6e o other function
2d410 61 6c 69 74 79 20 69 73 0a 2a 2a 20 70 72 6f 76 ality is.** prov
2d420 69 64 65 64 20 28 65 6e 66 6f 72 63 65 6d 65 6e ided (enforcemen
2d430 74 20 6f 66 20 46 4b 20 63 6f 6e 73 74 72 61 69 t of FK constrai
2d440 6e 74 73 20 72 65 71 75 69 72 65 73 20 74 68 65 nts requires the
2d450 20 74 72 69 67 67 65 72 73 20 73 75 62 2d 73 79 triggers sub-sy
2d460 73 74 65 6d 29 2e 0a 2a 2f 0a 23 69 66 20 21 64 stem)..*/.#if !d
2d470 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d efined(SQLITE_OM
2d480 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 29 20 IT_FOREIGN_KEY)
2d490 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
2d4a0 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 TE_OMIT_TRIGGER)
2d4b0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 . void sqlite3F
2d4c0 6b 43 68 65 63 6b 28 50 61 72 73 65 2a 2c 20 54 kCheck(Parse*, T
2d4d0 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c able*, int, int,
2d4e0 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 int*, int);. v
2d4f0 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 44 72 6f oid sqlite3FkDro
2d500 70 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 pTable(Parse*, S
2d510 72 63 4c 69 73 74 20 2a 2c 20 54 61 62 6c 65 2a rcList *, Table*
2d520 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
2d530 33 46 6b 41 63 74 69 6f 6e 73 28 50 61 72 73 65 3FkActions(Parse
2d540 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 4c *, Table*, ExprL
2d550 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c ist*, int, int*,
2d560 20 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c int);. int sql
2d570 69 74 65 33 46 6b 52 65 71 75 69 72 65 64 28 50 ite3FkRequired(P
2d580 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 arse*, Table*, i
2d590 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 75 33 32 nt*, int);. u32
2d5a0 20 73 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 61 73 sqlite3FkOldmas
2d5b0 6b 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a k(Parse*, Table*
2d5c0 29 3b 0a 20 20 46 4b 65 79 20 2a 73 71 6c 69 74 );. FKey *sqlit
2d5d0 65 33 46 6b 52 65 66 65 72 65 6e 63 65 73 28 54 e3FkReferences(T
2d5e0 61 62 6c 65 20 2a 29 3b 0a 23 65 6c 73 65 0a 20 able *);.#else.
2d5f0 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2d600 46 6b 41 63 74 69 6f 6e 73 28 61 2c 62 2c 63 2c FkActions(a,b,c,
2d610 64 2c 65 2c 66 29 0a 20 20 23 64 65 66 69 6e 65 d,e,f). #define
2d620 20 73 71 6c 69 74 65 33 46 6b 43 68 65 63 6b 28 sqlite3FkCheck(
2d630 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 20 23 a,b,c,d,e,f). #
2d640 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
2d650 44 72 6f 70 54 61 62 6c 65 28 61 2c 62 2c 63 29 DropTable(a,b,c)
2d660 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
2d670 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 61 2c 62 29 e3FkOldmask(a,b)
2d680 20 20 20 20 20 20 20 20 20 30 0a 20 20 23 64 65 0. #de
2d690 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 52 65 fine sqlite3FkRe
2d6a0 71 75 69 72 65 64 28 61 2c 62 2c 63 2c 64 29 20 quired(a,b,c,d)
2d6b0 20 20 20 30 0a 20 20 23 64 65 66 69 6e 65 20 73 0. #define s
2d6c0 71 6c 69 74 65 33 46 6b 52 65 66 65 72 65 6e 63 qlite3FkReferenc
2d6d0 65 73 28 61 29 20 20 20 20 20 20 20 20 30 0a 23 es(a) 0.#
2d6e0 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 endif.#ifndef SQ
2d6f0 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 LITE_OMIT_FOREIG
2d700 4e 5f 4b 45 59 0a 20 20 76 6f 69 64 20 73 71 6c N_KEY. void sql
2d710 69 74 65 33 46 6b 44 65 6c 65 74 65 28 73 71 6c ite3FkDelete(sql
2d720 69 74 65 33 20 2a 2c 20 54 61 62 6c 65 2a 29 3b ite3 *, Table*);
2d730 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 6b . int sqlite3Fk
2d740 4c 6f 63 61 74 65 49 6e 64 65 78 28 50 61 72 73 LocateIndex(Pars
2d750 65 2a 2c 54 61 62 6c 65 2a 2c 46 4b 65 79 2a 2c e*,Table*,FKey*,
2d760 49 6e 64 65 78 2a 2a 2c 69 6e 74 2a 2a 29 3b 0a Index**,int**);.
2d770 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
2d780 73 71 6c 69 74 65 33 46 6b 44 65 6c 65 74 65 28 sqlite3FkDelete(
2d790 61 2c 62 29 0a 20 20 23 64 65 66 69 6e 65 20 73 a,b). #define s
2d7a0 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e qlite3FkLocateIn
2d7b0 64 65 78 28 61 2c 62 2c 63 2c 64 2c 65 29 0a 23 dex(a,b,c,d,e).#
2d7c0 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a 2a 20 41 76 endif.../*.** Av
2d7d0 61 69 6c 61 62 6c 65 20 66 61 75 6c 74 20 69 6e ailable fault in
2d7e0 6a 65 63 74 6f 72 73 2e 20 20 53 68 6f 75 6c 64 jectors. Should
2d7f0 20 62 65 20 6e 75 6d 62 65 72 65 64 20 62 65 67 be numbered beg
2d800 69 6e 6e 69 6e 67 20 77 69 74 68 20 30 2e 0a 2a inning with 0..*
2d810 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
2d820 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 4d _FAULTINJECTOR_M
2d830 41 4c 4c 4f 43 20 20 20 20 20 30 0a 23 64 65 66 ALLOC 0.#def
2d840 69 6e 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 ine SQLITE_FAULT
2d850 49 4e 4a 45 43 54 4f 52 5f 43 4f 55 4e 54 20 20 INJECTOR_COUNT
2d860 20 20 20 20 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 1../*.** The
2d870 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 74 68 interface to th
2d880 65 20 63 6f 64 65 20 69 6e 20 66 61 75 6c 74 2e e code in fault.
2d890 63 20 75 73 65 64 20 66 6f 72 20 69 64 65 6e 74 c used for ident
2d8a0 69 66 79 69 6e 67 20 22 62 65 6e 69 67 6e 22 0a ifying "benign".
2d8b0 2a 2a 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 ** malloc failur
2d8c0 65 73 2e 20 54 68 69 73 20 69 73 20 6f 6e 6c 79 es. This is only
2d8d0 20 70 72 65 73 65 6e 74 20 69 66 20 53 51 4c 49 present if SQLI
2d8e0 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a 2a 2a TE_UNTESTABLE.**
2d8f0 20 69 73 20 6e 6f 74 20 64 65 66 69 6e 65 64 2e is not defined.
2d900 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 .*/.#ifndef SQLI
2d910 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a 20 20 TE_UNTESTABLE.
2d920 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 void sqlite3Begi
2d930 6e 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f nBenignMalloc(vo
2d940 69 64 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 id);. void sqli
2d950 74 65 33 45 6e 64 42 65 6e 69 67 6e 4d 61 6c 6c te3EndBenignMall
2d960 6f 63 28 76 6f 69 64 29 3b 0a 23 65 6c 73 65 0a oc(void);.#else.
2d970 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
2d980 33 42 65 67 69 6e 42 65 6e 69 67 6e 4d 61 6c 6c 3BeginBenignMall
2d990 6f 63 28 29 0a 20 20 23 64 65 66 69 6e 65 20 73 oc(). #define s
2d9a0 71 6c 69 74 65 33 45 6e 64 42 65 6e 69 67 6e 4d qlite3EndBenignM
2d9b0 61 6c 6c 6f 63 28 29 0a 23 65 6e 64 69 66 0a 0a alloc().#endif..
2d9c0 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 72 65 /*.** Allowed re
2d9d0 74 75 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d turn values from
2d9e0 20 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e sqlite3FindInIn
2d9f0 64 65 78 28 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 dex().*/.#define
2da00 20 49 4e 5f 49 4e 44 45 58 5f 52 4f 57 49 44 20 IN_INDEX_ROWID
2da10 20 20 20 20 20 20 20 31 20 20 20 2f 2a 20 53 65 1 /* Se
2da20 61 72 63 68 20 74 68 65 20 72 6f 77 69 64 20 6f arch the rowid o
2da30 66 20 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 23 f the table */.#
2da40 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
2da50 45 50 48 20 20 20 20 20 20 20 20 20 20 32 20 20 EPH 2
2da60 20 2f 2a 20 53 65 61 72 63 68 20 61 6e 20 65 70 /* Search an ep
2da70 68 65 6d 65 72 61 6c 20 62 2d 74 72 65 65 20 2a hemeral b-tree *
2da80 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 /.#define IN_IND
2da90 45 58 5f 49 4e 44 45 58 5f 41 53 43 20 20 20 20 EX_INDEX_ASC
2daa0 33 20 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 20 3 /* Existing
2dab0 69 6e 64 65 78 20 41 53 43 45 4e 44 49 4e 47 20 index ASCENDING
2dac0 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
2dad0 44 45 58 5f 49 4e 44 45 58 5f 44 45 53 43 20 20 DEX_INDEX_DESC
2dae0 20 34 20 20 20 2f 2a 20 45 78 69 73 74 69 6e 67 4 /* Existing
2daf0 20 69 6e 64 65 78 20 44 45 53 43 45 4e 44 49 4e index DESCENDIN
2db00 47 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f G */.#define IN_
2db10 49 4e 44 45 58 5f 4e 4f 4f 50 20 20 20 20 20 20 INDEX_NOOP
2db20 20 20 20 35 20 20 20 2f 2a 20 4e 6f 20 74 61 62 5 /* No tab
2db30 6c 65 20 61 76 61 69 6c 61 62 6c 65 2e 20 55 73 le available. Us
2db40 65 20 63 6f 6d 70 61 72 69 73 6f 6e 73 20 2a 2f e comparisons */
2db50 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 66 ./*.** Allowed f
2db60 6c 61 67 73 20 66 6f 72 20 74 68 65 20 33 72 64 lags for the 3rd
2db70 20 70 61 72 61 6d 65 74 65 72 20 74 6f 20 73 71 parameter to sq
2db80 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 lite3FindInIndex
2db90 28 29 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 ()..*/.#define I
2dba0 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 5f 4f 4b 20 N_INDEX_NOOP_OK
2dbb0 20 20 20 20 30 78 30 30 30 31 20 20 2f 2a 20 4f 0x0001 /* O
2dbc0 4b 20 74 6f 20 72 65 74 75 72 6e 20 49 4e 5f 49 K to return IN_I
2dbd0 4e 44 45 58 5f 4e 4f 4f 50 20 2a 2f 0a 23 64 65 NDEX_NOOP */.#de
2dbe0 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4d 45 fine IN_INDEX_ME
2dbf0 4d 42 45 52 53 48 49 50 20 20 30 78 30 30 30 32 MBERSHIP 0x0002
2dc00 20 20 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 /* IN operator
2dc10 20 75 73 65 64 20 66 6f 72 20 6d 65 6d 62 65 72 used for member
2dc20 73 68 69 70 20 74 65 73 74 20 2a 2f 0a 23 64 65 ship test */.#de
2dc30 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4c 4f fine IN_INDEX_LO
2dc40 4f 50 20 20 20 20 20 20 20 20 30 78 30 30 30 34 OP 0x0004
2dc50 20 20 2f 2a 20 49 4e 20 6f 70 65 72 61 74 6f 72 /* IN operator
2dc60 20 75 73 65 64 20 61 73 20 61 20 6c 6f 6f 70 20 used as a loop
2dc70 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 */.int sqlite3Fi
2dc80 6e 64 49 6e 49 6e 64 65 78 28 50 61 72 73 65 20 ndInIndex(Parse
2dc90 2a 2c 20 45 78 70 72 20 2a 2c 20 75 33 32 2c 20 *, Expr *, u32,
2dca0 69 6e 74 2a 2c 20 69 6e 74 2a 29 3b 0a 0a 69 6e int*, int*);..in
2dcb0 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c t sqlite3Journal
2dcc0 4f 70 65 6e 28 73 71 6c 69 74 65 33 5f 76 66 73 Open(sqlite3_vfs
2dcd0 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a *, const char *
2dce0 2c 20 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a , sqlite3_file *
2dcf0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 69 6e 74 , int, int);.int
2dd00 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 53 sqlite3JournalS
2dd10 69 7a 65 28 73 71 6c 69 74 65 33 5f 76 66 73 20 ize(sqlite3_vfs
2dd20 2a 29 3b 0a 23 69 66 20 64 65 66 69 6e 65 64 28 *);.#if defined(
2dd30 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 41 54 SQLITE_ENABLE_AT
2dd40 4f 4d 49 43 5f 57 52 49 54 45 29 20 5c 0a 20 7c OMIC_WRITE) \. |
2dd50 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 | defined(SQLITE
2dd60 5f 45 4e 41 42 4c 45 5f 42 41 54 43 48 5f 41 54 _ENABLE_BATCH_AT
2dd70 4f 4d 49 43 5f 57 52 49 54 45 29 0a 20 20 69 6e OMIC_WRITE). in
2dd80 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c t sqlite3Journal
2dd90 43 72 65 61 74 65 28 73 71 6c 69 74 65 33 5f 66 Create(sqlite3_f
2dda0 69 6c 65 20 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a ile *);.#endif..
2ddb0 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e int sqlite3Journ
2ddc0 61 6c 49 73 49 6e 4d 65 6d 6f 72 79 28 73 71 6c alIsInMemory(sql
2ddd0 69 74 65 33 5f 66 69 6c 65 20 2a 70 29 3b 0a 76 ite3_file *p);.v
2dde0 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d 4a 6f oid sqlite3MemJo
2ddf0 75 72 6e 61 6c 4f 70 65 6e 28 73 71 6c 69 74 65 urnalOpen(sqlite
2de00 33 5f 66 69 6c 65 20 2a 29 3b 0a 0a 76 6f 69 64 3_file *);..void
2de10 20 73 71 6c 69 74 65 33 45 78 70 72 53 65 74 48 sqlite3ExprSetH
2de20 65 69 67 68 74 41 6e 64 46 6c 61 67 73 28 50 61 eightAndFlags(Pa
2de30 72 73 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 rse *pParse, Exp
2de40 72 20 2a 70 29 3b 0a 23 69 66 20 53 51 4c 49 54 r *p);.#if SQLIT
2de50 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 E_MAX_EXPR_DEPTH
2de60 3e 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 >0. int sqlite3
2de70 53 65 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 SelectExprHeight
2de80 28 53 65 6c 65 63 74 20 2a 29 3b 0a 20 20 69 6e (Select *);. in
2de90 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 t sqlite3ExprChe
2dea0 63 6b 48 65 69 67 68 74 28 50 61 72 73 65 2a 2c ckHeight(Parse*,
2deb0 20 69 6e 74 29 3b 0a 23 65 6c 73 65 0a 20 20 23 int);.#else. #
2dec0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 65 define sqlite3Se
2ded0 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 28 78 lectExprHeight(x
2dee0 29 20 30 0a 20 20 23 64 65 66 69 6e 65 20 73 71 ) 0. #define sq
2def0 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 lite3ExprCheckHe
2df00 69 67 68 74 28 78 2c 79 29 0a 23 65 6e 64 69 66 ight(x,y).#endif
2df10 0a 0a 75 33 32 20 73 71 6c 69 74 65 33 47 65 74 ..u32 sqlite3Get
2df20 34 62 79 74 65 28 63 6f 6e 73 74 20 75 38 2a 29 4byte(const u8*)
2df30 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 75 ;.void sqlite3Pu
2df40 74 34 62 79 74 65 28 75 38 2a 2c 20 75 33 32 29 t4byte(u8*, u32)
2df50 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
2df60 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e _ENABLE_UNLOCK_N
2df70 4f 54 49 46 59 0a 20 20 76 6f 69 64 20 73 71 6c OTIFY. void sql
2df80 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c ite3ConnectionBl
2df90 6f 63 6b 65 64 28 73 71 6c 69 74 65 33 20 2a 2c ocked(sqlite3 *,
2dfa0 20 73 71 6c 69 74 65 33 20 2a 29 3b 0a 20 20 76 sqlite3 *);. v
2dfb0 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 oid sqlite3Conne
2dfc0 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 73 71 ctionUnlocked(sq
2dfd0 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 76 6f lite3 *db);. vo
2dfe0 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 id sqlite3Connec
2dff0 74 69 6f 6e 43 6c 6f 73 65 64 28 73 71 6c 69 74 tionClosed(sqlit
2e000 65 33 20 2a 64 62 29 3b 0a 23 65 6c 73 65 0a 20 e3 *db);.#else.
2e010 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2e020 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 ConnectionBlocke
2e030 64 28 78 2c 79 29 0a 20 20 23 64 65 66 69 6e 65 d(x,y). #define
2e040 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 sqlite3Connecti
2e050 6f 6e 55 6e 6c 6f 63 6b 65 64 28 78 29 0a 20 20 onUnlocked(x).
2e060 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 #define sqlite3C
2e070 6f 6e 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 onnectionClosed(
2e080 78 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 x).#endif..#ifde
2e090 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 f SQLITE_DEBUG.
2e0a0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 void sqlite3Par
2e0b0 73 65 72 54 72 61 63 65 28 46 49 4c 45 2a 2c 20 serTrace(FILE*,
2e0c0 63 68 61 72 20 2a 29 3b 0a 23 65 6e 64 69 66 0a char *);.#endif.
2e0d0 23 69 66 20 64 65 66 69 6e 65 64 28 59 59 43 4f #if defined(YYCO
2e0e0 56 45 52 41 47 45 29 0a 20 20 69 6e 74 20 73 71 VERAGE). int sq
2e0f0 6c 69 74 65 33 50 61 72 73 65 72 43 6f 76 65 72 lite3ParserCover
2e100 61 67 65 28 46 49 4c 45 2a 29 3b 0a 23 65 6e 64 age(FILE*);.#end
2e110 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 74 68 65 if../*.** If the
2e120 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 20 49 SQLITE_ENABLE I
2e130 4f 54 52 41 43 45 20 65 78 69 73 74 73 20 74 68 OTRACE exists th
2e140 65 6e 20 74 68 65 20 67 6c 6f 62 61 6c 20 76 61 en the global va
2e150 72 69 61 62 6c 65 0a 2a 2a 20 73 71 6c 69 74 65 riable.** sqlite
2e160 33 49 6f 54 72 61 63 65 20 69 73 20 61 20 70 6f 3IoTrace is a po
2e170 69 6e 74 65 72 20 74 6f 20 61 20 70 72 69 6e 74 inter to a print
2e180 66 2d 6c 69 6b 65 20 72 6f 75 74 69 6e 65 20 75 f-like routine u
2e190 73 65 64 20 74 6f 0a 2a 2a 20 70 72 69 6e 74 20 sed to.** print
2e1a0 49 2f 4f 20 74 72 61 63 69 6e 67 20 6d 65 73 73 I/O tracing mess
2e1b0 61 67 65 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 ages..*/.#ifdef
2e1c0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 49 4f SQLITE_ENABLE_IO
2e1d0 54 52 41 43 45 0a 23 20 64 65 66 69 6e 65 20 49 TRACE.# define I
2e1e0 4f 54 52 41 43 45 28 41 29 20 20 69 66 28 20 73 OTRACE(A) if( s
2e1f0 71 6c 69 74 65 33 49 6f 54 72 61 63 65 20 29 7b qlite3IoTrace ){
2e200 20 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 20 sqlite3IoTrace
2e210 41 3b 20 7d 0a 20 20 76 6f 69 64 20 73 71 6c 69 A; }. void sqli
2e220 74 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 71 te3VdbeIOTraceSq
2e230 6c 28 56 64 62 65 2a 29 3b 0a 53 51 4c 49 54 45 l(Vdbe*);.SQLITE
2e240 5f 41 50 49 20 53 51 4c 49 54 45 5f 45 58 54 45 _API SQLITE_EXTE
2e250 52 4e 20 76 6f 69 64 20 28 53 51 4c 49 54 45 5f RN void (SQLITE_
2e260 43 44 45 43 4c 20 2a 73 71 6c 69 74 65 33 49 6f CDECL *sqlite3Io
2e270 54 72 61 63 65 29 28 63 6f 6e 73 74 20 63 68 61 Trace)(const cha
2e280 72 2a 2c 2e 2e 2e 29 3b 0a 23 65 6c 73 65 0a 23 r*,...);.#else.#
2e290 20 64 65 66 69 6e 65 20 49 4f 54 52 41 43 45 28 define IOTRACE(
2e2a0 41 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 A).# define sqli
2e2b0 74 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 71 te3VdbeIOTraceSq
2e2c0 6c 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a l(X).#endif../*.
2e2d0 2a 2a 20 54 68 65 73 65 20 72 6f 75 74 69 6e 65 ** These routine
2e2e0 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 20 s are available
2e2f0 66 6f 72 20 74 68 65 20 6d 65 6d 32 2e 63 20 64 for the mem2.c d
2e300 65 62 75 67 67 69 6e 67 20 6d 65 6d 6f 72 79 20 ebugging memory
2e310 61 6c 6c 6f 63 61 74 6f 72 0a 2a 2a 20 6f 6e 6c allocator.** onl
2e320 79 2e 20 20 54 68 65 79 20 61 72 65 20 75 73 65 y. They are use
2e330 64 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 d to verify that
2e340 20 64 69 66 66 65 72 65 6e 74 20 22 74 79 70 65 different "type
2e350 73 22 20 6f 66 20 6d 65 6d 6f 72 79 0a 2a 2a 20 s" of memory.**
2e360 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 allocations are
2e370 70 72 6f 70 65 72 6c 79 20 74 72 61 63 6b 65 64 properly tracked
2e380 20 62 79 20 74 68 65 20 73 79 73 74 65 6d 2e 0a by the system..
2e390 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d **.** sqlite3Mem
2e3a0 64 65 62 75 67 53 65 74 54 79 70 65 28 29 20 73 debugSetType() s
2e3b0 65 74 73 20 74 68 65 20 22 74 79 70 65 22 20 6f ets the "type" o
2e3c0 66 20 61 6e 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 f an allocation
2e3d0 74 6f 20 6f 6e 65 20 6f 66 0a 2a 2a 20 74 68 65 to one of.** the
2e3e0 20 4d 45 4d 54 59 50 45 5f 2a 20 6d 61 63 72 6f MEMTYPE_* macro
2e3f0 73 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 2e s defined below.
2e400 20 20 54 68 65 20 74 79 70 65 20 6d 75 73 74 20 The type must
2e410 62 65 20 61 20 62 69 74 6d 61 73 6b 20 77 69 74 be a bitmask wit
2e420 68 0a 2a 2a 20 61 20 73 69 6e 67 6c 65 20 62 69 h.** a single bi
2e430 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c t set..**.** sql
2e440 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 ite3MemdebugHasT
2e450 79 70 65 28 29 20 72 65 74 75 72 6e 73 20 74 72 ype() returns tr
2e460 75 65 20 69 66 20 61 6e 79 20 6f 66 20 74 68 65 ue if any of the
2e470 20 62 69 74 73 20 69 6e 20 69 74 73 20 73 65 63 bits in its sec
2e480 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 ond.** argument
2e490 6d 61 74 63 68 20 74 68 65 20 74 79 70 65 20 73 match the type s
2e4a0 65 74 20 62 79 20 74 68 65 20 70 72 65 76 69 6f et by the previo
2e4b0 75 73 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 us sqlite3Memdeb
2e4c0 75 67 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a 20 ugSetType()..**
2e4d0 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 sqlite3MemdebugH
2e4e0 61 73 54 79 70 65 28 29 20 69 73 20 69 6e 74 65 asType() is inte
2e4f0 6e 64 65 64 20 66 6f 72 20 75 73 65 20 69 6e 73 nded for use ins
2e500 69 64 65 20 61 73 73 65 72 74 28 29 20 73 74 61 ide assert() sta
2e510 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 73 tements..**.** s
2e520 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 4e 6f qlite3MemdebugNo
2e530 54 79 70 65 28 29 20 72 65 74 75 72 6e 73 20 74 Type() returns t
2e540 72 75 65 20 69 66 20 6e 6f 6e 65 20 6f 66 20 74 rue if none of t
2e550 68 65 20 62 69 74 73 20 69 6e 20 69 74 73 20 73 he bits in its s
2e560 65 63 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 6e econd.** argumen
2e570 74 20 6d 61 74 63 68 20 74 68 65 20 74 79 70 65 t match the type
2e580 20 73 65 74 20 62 79 20 74 68 65 20 70 72 65 76 set by the prev
2e590 69 6f 75 73 20 73 71 6c 69 74 65 33 4d 65 6d 64 ious sqlite3Memd
2e5a0 65 62 75 67 53 65 74 54 79 70 65 28 29 2e 0a 2a ebugSetType()..*
2e5b0 2a 0a 2a 2a 20 50 65 72 68 61 70 73 20 74 68 65 *.** Perhaps the
2e5c0 20 6d 6f 73 74 20 69 6d 70 6f 72 74 61 6e 74 20 most important
2e5d0 70 6f 69 6e 74 20 69 73 20 74 68 65 20 64 69 66 point is the dif
2e5e0 66 65 72 65 6e 63 65 20 62 65 74 77 65 65 6e 20 ference between
2e5f0 4d 45 4d 54 59 50 45 5f 48 45 41 50 0a 2a 2a 20 MEMTYPE_HEAP.**
2e600 61 6e 64 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b and MEMTYPE_LOOK
2e610 41 53 49 44 45 2e 20 20 49 66 20 61 6e 20 61 6c ASIDE. If an al
2e620 6c 6f 63 61 74 69 6f 6e 20 69 73 20 4d 45 4d 54 location is MEMT
2e630 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 2c 20 74 YPE_LOOKASIDE, t
2e640 68 61 74 20 6d 65 61 6e 73 0a 2a 2a 20 69 74 20 hat means.** it
2e650 6d 69 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 might have been
2e660 61 6c 6c 6f 63 61 74 65 64 20 62 79 20 6c 6f 6f allocated by loo
2e670 6b 61 73 69 64 65 2c 20 65 78 63 65 70 74 20 74 kaside, except t
2e680 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 77 61 he allocation wa
2e690 73 0a 2a 2a 20 74 6f 6f 20 6c 61 72 67 65 20 6f s.** too large o
2e6a0 72 20 6c 6f 6f 6b 61 73 69 64 65 20 77 61 73 20 r lookaside was
2e6b0 61 6c 72 65 61 64 79 20 66 75 6c 6c 2e 20 20 49 already full. I
2e6c0 74 20 69 73 20 69 6d 70 6f 72 74 61 6e 74 20 74 t is important t
2e6d0 6f 20 76 65 72 69 66 79 0a 2a 2a 20 74 68 61 74 o verify.** that
2e6e0 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 74 68 61 allocations tha
2e6f0 74 20 6d 69 67 68 74 20 68 61 76 65 20 62 65 65 t might have bee
2e700 6e 20 73 61 74 69 73 66 69 65 64 20 62 79 20 6c n satisfied by l
2e710 6f 6f 6b 61 73 69 64 65 20 61 72 65 20 6e 6f 74 ookaside are not
2e720 0a 2a 2a 20 70 61 73 73 65 64 20 62 61 63 6b 20 .** passed back
2e730 74 6f 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 to non-lookaside
2e740 20 66 72 65 65 28 29 20 72 6f 75 74 69 6e 65 73 free() routines
2e750 2e 20 20 41 73 73 65 72 74 73 20 73 75 63 68 20 . Asserts such
2e760 61 73 20 74 68 65 0a 2a 2a 20 65 78 61 6d 70 6c as the.** exampl
2e770 65 20 61 62 6f 76 65 20 61 72 65 20 70 6c 61 63 e above are plac
2e780 65 64 20 6f 6e 20 74 68 65 20 6e 6f 6e 2d 6c 6f ed on the non-lo
2e790 6f 6b 61 73 69 64 65 20 66 72 65 65 28 29 20 72 okaside free() r
2e7a0 6f 75 74 69 6e 65 73 20 74 6f 20 76 65 72 69 66 outines to verif
2e7b0 79 0a 2a 2a 20 74 68 69 73 20 63 6f 6e 73 74 72 y.** this constr
2e7c0 61 69 6e 74 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 aint..**.** All
2e7d0 6f 66 20 74 68 69 73 20 69 73 20 6e 6f 2d 6f 70 of this is no-op
2e7e0 20 66 6f 72 20 61 20 70 72 6f 64 75 63 74 69 6f for a productio
2e7f0 6e 20 62 75 69 6c 64 2e 20 20 49 74 20 6f 6e 6c n build. It onl
2e800 79 20 63 6f 6d 65 73 20 69 6e 74 6f 0a 2a 2a 20 y comes into.**
2e810 70 6c 61 79 20 77 68 65 6e 20 74 68 65 20 53 51 play when the SQ
2e820 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 63 6f LITE_MEMDEBUG co
2e830 6d 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f mpile-time optio
2e840 6e 20 69 73 20 75 73 65 64 2e 0a 2a 2f 0a 23 69 n is used..*/.#i
2e850 66 64 65 66 20 53 51 4c 49 54 45 5f 4d 45 4d 44 fdef SQLITE_MEMD
2e860 45 42 55 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 EBUG. void sqli
2e870 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 te3MemdebugSetTy
2e880 70 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 pe(void*,u8);.
2e890 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 int sqlite3Memde
2e8a0 62 75 67 48 61 73 54 79 70 65 28 76 6f 69 64 2a bugHasType(void*
2e8b0 2c 75 38 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 ,u8);. int sqli
2e8c0 74 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 te3MemdebugNoTyp
2e8d0 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 23 65 6c e(void*,u8);.#el
2e8e0 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
2e8f0 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 te3MemdebugSetTy
2e900 70 65 28 58 2c 59 29 20 20 2f 2a 20 6e 6f 2d 6f pe(X,Y) /* no-o
2e910 70 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 73 71 p */.# define sq
2e920 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 lite3MemdebugHas
2e930 54 79 70 65 28 58 2c 59 29 20 20 31 0a 23 20 64 Type(X,Y) 1.# d
2e940 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d efine sqlite3Mem
2e950 64 65 62 75 67 4e 6f 54 79 70 65 28 58 2c 59 29 debugNoType(X,Y)
2e960 20 20 20 31 0a 23 65 6e 64 69 66 0a 23 64 65 66 1.#endif.#def
2e970 69 6e 65 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 ine MEMTYPE_HEAP
2e980 20 20 20 20 20 20 20 30 78 30 31 20 20 2f 2a 20 0x01 /*
2e990 47 65 6e 65 72 61 6c 20 68 65 61 70 20 61 6c 6c General heap all
2e9a0 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 ocations */.#def
2e9b0 69 6e 65 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b ine MEMTYPE_LOOK
2e9c0 41 53 49 44 45 20 20 30 78 30 32 20 20 2f 2a 20 ASIDE 0x02 /*
2e9d0 48 65 61 70 20 74 68 61 74 20 6d 69 67 68 74 20 Heap that might
2e9e0 68 61 76 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 have been lookas
2e9f0 69 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d ide */.#define M
2ea00 45 4d 54 59 50 45 5f 50 43 41 43 48 45 20 20 20 EMTYPE_PCACHE
2ea10 20 20 30 78 30 34 20 20 2f 2a 20 50 61 67 65 20 0x04 /* Page
2ea20 63 61 63 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e cache allocation
2ea30 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 72 65 s */../*.** Thre
2ea40 61 64 69 6e 67 20 69 6e 74 65 72 66 61 63 65 0a ading interface.
2ea50 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 */.#if SQLITE_MA
2ea60 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
2ea70 3e 30 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 68 >0.int sqlite3Th
2ea80 72 65 61 64 43 72 65 61 74 65 28 53 51 4c 69 74 readCreate(SQLit
2ea90 65 54 68 72 65 61 64 2a 2a 2c 76 6f 69 64 2a 28 eThread**,void*(
2eaa0 2a 29 28 76 6f 69 64 2a 29 2c 76 6f 69 64 2a 29 *)(void*),void*)
2eab0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 68 72 ;.int sqlite3Thr
2eac0 65 61 64 4a 6f 69 6e 28 53 51 4c 69 74 65 54 68 eadJoin(SQLiteTh
2ead0 72 65 61 64 2a 2c 20 76 6f 69 64 2a 2a 29 3b 0a read*, void**);.
2eae0 23 65 6e 64 69 66 0a 0a 23 69 66 20 64 65 66 69 #endif..#if defi
2eaf0 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c ned(SQLITE_ENABL
2eb00 45 5f 44 42 50 41 47 45 5f 56 54 41 42 29 20 7c E_DBPAGE_VTAB) |
2eb10 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 | defined(SQLITE
2eb20 5f 54 45 53 54 29 0a 69 6e 74 20 73 71 6c 69 74 _TEST).int sqlit
2eb30 65 33 44 62 70 61 67 65 52 65 67 69 73 74 65 72 e3DbpageRegister
2eb40 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 65 6e 64 (sqlite3*);.#end
2eb50 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 if.#if defined(S
2eb60 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 42 53 QLITE_ENABLE_DBS
2eb70 54 41 54 5f 56 54 41 42 29 20 7c 7c 20 64 65 66 TAT_VTAB) || def
2eb80 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 ined(SQLITE_TEST
2eb90 29 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 73 ).int sqlite3Dbs
2eba0 74 61 74 52 65 67 69 73 74 65 72 28 73 71 6c 69 tatRegister(sqli
2ebb0 74 65 33 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 69 te3*);.#endif..i
2ebc0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 56 65 nt sqlite3ExprVe
2ebd0 63 74 6f 72 53 69 7a 65 28 45 78 70 72 20 2a 70 ctorSize(Expr *p
2ebe0 45 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 Expr);.int sqlit
2ebf0 65 33 45 78 70 72 49 73 56 65 63 74 6f 72 28 45 e3ExprIsVector(E
2ec00 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 45 78 70 xpr *pExpr);.Exp
2ec10 72 20 2a 73 71 6c 69 74 65 33 56 65 63 74 6f 72 r *sqlite3Vector
2ec20 46 69 65 6c 64 53 75 62 65 78 70 72 28 45 78 70 FieldSubexpr(Exp
2ec30 72 2a 2c 20 69 6e 74 29 3b 0a 45 78 70 72 20 2a r*, int);.Expr *
2ec40 73 71 6c 69 74 65 33 45 78 70 72 46 6f 72 56 65 sqlite3ExprForVe
2ec50 63 74 6f 72 46 69 65 6c 64 28 50 61 72 73 65 2a ctorField(Parse*
2ec60 2c 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 ,Expr*,int);.voi
2ec70 64 20 73 71 6c 69 74 65 33 56 65 63 74 6f 72 45 d sqlite3VectorE
2ec80 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c 20 rrorMsg(Parse*,
2ec90 45 78 70 72 2a 29 3b 0a 0a 23 69 66 6e 64 65 66 Expr*);..#ifndef
2eca0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 4f 4d SQLITE_OMIT_COM
2ecb0 50 49 4c 45 4f 50 54 49 4f 4e 5f 44 49 41 47 53 PILEOPTION_DIAGS
2ecc0 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a 73 71 .const char **sq
2ecd0 6c 69 74 65 33 43 6f 6d 70 69 6c 65 4f 70 74 69 lite3CompileOpti
2ece0 6f 6e 73 28 69 6e 74 20 2a 70 6e 4f 70 74 29 3b ons(int *pnOpt);
2ecf0 0a 23 65 6e 64 69 66 0a 0a 23 65 6e 64 69 66 20 .#endif..#endif
2ed00 2f 2a 20 53 51 4c 49 54 45 49 4e 54 5f 48 20 2a /* SQLITEINT_H *
2ed10 2f 0a /.