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 48 41 56 45 5f 53 54 44 49 4e 54 5f 48 ed(HAVE_STDINT_H
1f20: 29 20 20 20 2f 2a 20 55 73 65 20 74 68 69 73 20 ) /* Use this
1f30: 63 61 73 65 20 69 66 20 77 65 20 68 61 76 65 20 case if we have
1f40: 41 4e 53 49 20 68 65 61 64 65 72 73 20 2a 2f 0a ANSI headers */.
1f50: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
1f60: 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 INT_TO_PTR(X) (
1f70: 28 76 6f 69 64 2a 29 28 69 6e 74 70 74 72 5f 74 (void*)(intptr_t
1f80: 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 20 53 )(X)).# define S
1f90: 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 QLITE_PTR_TO_INT
1fa0: 28 58 29 20 20 28 28 69 6e 74 29 28 69 6e 74 70 (X) ((int)(intp
1fb0: 74 72 5f 74 29 28 58 29 29 0a 23 65 6c 69 66 20 tr_t)(X)).#elif
1fc0: 64 65 66 69 6e 65 64 28 5f 5f 50 54 52 44 49 46 defined(__PTRDIF
1fd0: 46 5f 54 59 50 45 5f 5f 29 20 20 2f 2a 20 54 68 F_TYPE__) /* Th
1fe0: 69 73 20 63 61 73 65 20 73 68 6f 75 6c 64 20 77 is case should w
1ff0: 6f 72 6b 20 66 6f 72 20 47 43 43 20 2a 2f 0a 23 ork for GCC */.#
2000: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 define SQLITE_I
2010: 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 NT_TO_PTR(X) ((
2020: 76 6f 69 64 2a 29 28 5f 5f 50 54 52 44 49 46 46 void*)(__PTRDIFF
2030: 5f 54 59 50 45 5f 5f 29 28 58 29 29 0a 23 20 64 _TYPE__)(X)).# d
2040: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 efine SQLITE_PTR
2050: 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 28 69 6e _TO_INT(X) ((in
2060: 74 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 t)(__PTRDIFF_TYP
2070: 45 5f 5f 29 28 58 29 29 0a 23 65 6c 69 66 20 21 E__)(X)).#elif !
2080: 64 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 5f 5f defined(__GNUC__
2090: 29 20 20 20 20 20 20 20 2f 2a 20 57 6f 72 6b 73 ) /* Works
20a0: 20 66 6f 72 20 63 6f 6d 70 69 6c 65 72 73 20 6f for compilers o
20b0: 74 68 65 72 20 74 68 61 6e 20 4c 4c 56 4d 20 2a ther than LLVM *
20c0: 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 /.# define SQLIT
20d0: 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 E_INT_TO_PTR(X)
20e0: 20 28 28 76 6f 69 64 2a 29 26 28 28 63 68 61 72 ((void*)&((char
20f0: 2a 29 30 29 5b 58 5d 29 0a 23 20 64 65 66 69 6e *)0)[X]).# defin
2100: 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f e SQLITE_PTR_TO_
2110: 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 28 INT(X) ((int)((
2120: 28 63 68 61 72 2a 29 58 29 2d 28 63 68 61 72 2a (char*)X)-(char*
2130: 29 30 29 29 0a 23 65 6c 73 65 20 20 20 20 20 20 )0)).#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 44 65 66 61 75 6c 74 20 76 61 6c *.** Default val
5710: 75 65 20 66 6f 72 20 74 68 65 20 53 51 4c 49 54 ue for the SQLIT
5720: 45 5f 43 4f 4e 46 49 47 5f 53 4f 52 54 45 52 52 E_CONFIG_SORTERR
5730: 45 46 5f 53 49 5a 45 20 6f 70 74 69 6f 6e 2e 0a EF_SIZE option..
5740: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
5750: 45 5f 44 45 46 41 55 4c 54 5f 53 4f 52 54 45 52 E_DEFAULT_SORTER
5760: 52 45 46 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e REF_SIZE.# defin
5770: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
5780: 5f 53 4f 52 54 45 52 52 45 46 5f 53 49 5a 45 20 _SORTERREF_SIZE
5790: 30 78 37 66 66 66 66 66 66 66 0a 23 65 6e 64 69 0x7fffffff.#endi
57a0: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 6f 6d f../*.** The com
57b0: 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e pile-time option
57c0: 73 20 53 51 4c 49 54 45 5f 4d 4d 41 50 5f 52 45 s SQLITE_MMAP_RE
57d0: 41 44 57 52 49 54 45 20 61 6e 64 20 0a 2a 2a 20 ADWRITE and .**
57e0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 42 41 SQLITE_ENABLE_BA
57f0: 54 43 48 5f 41 54 4f 4d 49 43 5f 57 52 49 54 45 TCH_ATOMIC_WRITE
5800: 20 61 72 65 20 6e 6f 74 20 63 6f 6d 70 61 74 69 are not compati
5810: 62 6c 65 20 77 69 74 68 20 6f 6e 65 20 61 6e 6f ble with one ano
5820: 74 68 65 72 2e 0a 2a 2a 20 59 6f 75 20 6d 75 73 ther..** You mus
5830: 74 20 63 68 6f 6f 73 65 20 6f 6e 65 20 6f 72 20 t choose one or
5840: 74 68 65 20 6f 74 68 65 72 20 28 6f 72 20 6e 65 the other (or ne
5850: 69 74 68 65 72 29 20 62 75 74 20 6e 6f 74 20 62 ither) but not b
5860: 6f 74 68 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 oth..*/.#if defi
5870: 6e 65 64 28 53 51 4c 49 54 45 5f 4d 4d 41 50 5f ned(SQLITE_MMAP_
5880: 52 45 41 44 57 52 49 54 45 29 20 26 26 20 64 65 READWRITE) && de
5890: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
58a0: 42 4c 45 5f 42 41 54 43 48 5f 41 54 4f 4d 49 43 BLE_BATCH_ATOMIC
58b0: 5f 57 52 49 54 45 29 0a 23 65 72 72 6f 72 20 43 _WRITE).#error C
58c0: 61 6e 6e 6f 74 20 75 73 65 20 62 6f 74 68 20 53 annot use both S
58d0: 51 4c 49 54 45 5f 4d 4d 41 50 5f 52 45 41 44 57 QLITE_MMAP_READW
58e0: 52 49 54 45 20 61 6e 64 20 53 51 4c 49 54 45 5f RITE and SQLITE_
58f0: 45 4e 41 42 4c 45 5f 42 41 54 43 48 5f 41 54 4f ENABLE_BATCH_ATO
5900: 4d 49 43 5f 57 52 49 54 45 0a 23 65 6e 64 69 66 MIC_WRITE.#endif
5910: 0a 0a 2f 2a 0a 2a 2a 20 47 43 43 20 64 6f 65 73 ../*.** GCC does
5920: 20 6e 6f 74 20 64 65 66 69 6e 65 20 74 68 65 20 not define the
5930: 6f 66 66 73 65 74 6f 66 28 29 20 6d 61 63 72 6f offsetof() macro
5940: 20 73 6f 20 77 65 27 6c 6c 20 68 61 76 65 20 74 so we'll have t
5950: 6f 20 64 6f 20 69 74 0a 2a 2a 20 6f 75 72 73 65 o do it.** ourse
5960: 6c 76 65 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 lves..*/.#ifndef
5970: 20 6f 66 66 73 65 74 6f 66 0a 23 64 65 66 69 6e offsetof.#defin
5980: 65 20 6f 66 66 73 65 74 6f 66 28 53 54 52 55 43 e offsetof(STRUC
5990: 54 55 52 45 2c 46 49 45 4c 44 29 20 28 28 69 6e TURE,FIELD) ((in
59a0: 74 29 28 28 63 68 61 72 2a 29 26 28 28 53 54 52 t)((char*)&((STR
59b0: 55 43 54 55 52 45 2a 29 30 29 2d 3e 46 49 45 4c UCTURE*)0)->FIEL
59c0: 44 29 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a D)).#endif../*.*
59d0: 2a 20 4d 61 63 72 6f 73 20 74 6f 20 63 6f 6d 70 * Macros to comp
59e0: 75 74 65 20 6d 69 6e 69 6d 75 6d 20 61 6e 64 20 ute minimum and
59f0: 6d 61 78 69 6d 75 6d 20 6f 66 20 74 77 6f 20 6e maximum of two n
5a00: 75 6d 62 65 72 73 2e 0a 2a 2f 0a 23 69 66 6e 64 umbers..*/.#ifnd
5a10: 65 66 20 4d 49 4e 0a 23 20 64 65 66 69 6e 65 20 ef MIN.# define
5a20: 4d 49 4e 28 41 2c 42 29 20 28 28 41 29 3c 28 42 MIN(A,B) ((A)<(B
5a30: 29 3f 28 41 29 3a 28 42 29 29 0a 23 65 6e 64 69 )?(A):(B)).#endi
5a40: 66 0a 23 69 66 6e 64 65 66 20 4d 41 58 0a 23 20 f.#ifndef MAX.#
5a50: 64 65 66 69 6e 65 20 4d 41 58 28 41 2c 42 29 20 define MAX(A,B)
5a60: 28 28 41 29 3e 28 42 29 3f 28 41 29 3a 28 42 29 ((A)>(B)?(A):(B)
5a70: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
5a80: 53 77 61 70 20 74 77 6f 20 6f 62 6a 65 63 74 73 Swap two objects
5a90: 20 6f 66 20 74 79 70 65 20 54 59 50 45 2e 0a 2a of type TYPE..*
5aa0: 2f 0a 23 64 65 66 69 6e 65 20 53 57 41 50 28 54 /.#define SWAP(T
5ab0: 59 50 45 2c 41 2c 42 29 20 7b 54 59 50 45 20 74 YPE,A,B) {TYPE t
5ac0: 3d 41 3b 20 41 3d 42 3b 20 42 3d 74 3b 7d 0a 0a =A; A=B; B=t;}..
5ad0: 2f 2a 0a 2a 2a 20 43 68 65 63 6b 20 74 6f 20 73 /*.** Check to s
5ae0: 65 65 20 69 66 20 74 68 69 73 20 6d 61 63 68 69 ee if this machi
5af0: 6e 65 20 75 73 65 73 20 45 42 43 44 49 43 2e 20 ne uses EBCDIC.
5b00: 20 28 59 65 73 2c 20 62 65 6c 69 65 76 65 20 69 (Yes, believe i
5b10: 74 20 6f 72 0a 2a 2a 20 6e 6f 74 2c 20 74 68 65 t or.** not, the
5b20: 72 65 20 61 72 65 20 73 74 69 6c 6c 20 6d 61 63 re are still mac
5b30: 68 69 6e 65 73 20 6f 75 74 20 74 68 65 72 65 20 hines out there
5b40: 74 68 61 74 20 75 73 65 20 45 42 43 44 49 43 2e that use EBCDIC.
5b50: 29 0a 2a 2f 0a 23 69 66 20 27 41 27 20 3d 3d 20 ).*/.#if 'A' ==
5b60: 27 5c 33 30 31 27 0a 23 20 64 65 66 69 6e 65 20 '\301'.# define
5b70: 53 51 4c 49 54 45 5f 45 42 43 44 49 43 20 31 0a SQLITE_EBCDIC 1.
5b80: 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 #else.# define S
5b90: 51 4c 49 54 45 5f 41 53 43 49 49 20 31 0a 23 65 QLITE_ASCII 1.#e
5ba0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 ndif../*.** Inte
5bb0: 67 65 72 73 20 6f 66 20 6b 6e 6f 77 6e 20 73 69 gers of known si
5bc0: 7a 65 73 2e 20 20 54 68 65 73 65 20 74 79 70 65 zes. These type
5bd0: 64 65 66 73 20 6d 69 67 68 74 20 63 68 61 6e 67 defs might chang
5be0: 65 20 66 6f 72 20 61 72 63 68 69 74 65 63 74 75 e for architectu
5bf0: 72 65 73 0a 2a 2a 20 77 68 65 72 65 20 74 68 65 res.** where the
5c00: 20 73 69 7a 65 73 20 76 65 72 79 2e 20 20 50 72 sizes very. Pr
5c10: 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f eprocessor macro
5c20: 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 20 s are available
5c30: 73 6f 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 74 so that the.** t
5c40: 79 70 65 73 20 63 61 6e 20 62 65 20 63 6f 6e 76 ypes can be conv
5c50: 65 6e 69 65 6e 74 6c 79 20 72 65 64 65 66 69 6e eniently redefin
5c60: 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 79 ed at compile-ty
5c70: 70 65 2e 20 20 4c 69 6b 65 20 74 68 69 73 3a 0a pe. Like this:.
5c80: 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 63 63 **.** cc
5c90: 20 27 2d 44 55 49 4e 54 50 54 52 5f 54 59 50 45 '-DUINTPTR_TYPE
5ca0: 3d 6c 6f 6e 67 20 6c 6f 6e 67 20 69 6e 74 27 20 =long long int'
5cb0: 2e 2e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 55 ....*/.#ifndef U
5cc0: 49 4e 54 33 32 5f 54 59 50 45 0a 23 20 69 66 64 INT32_TYPE.# ifd
5cd0: 65 66 20 48 41 56 45 5f 55 49 4e 54 33 32 5f 54 ef HAVE_UINT32_T
5ce0: 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 33 .# define UINT3
5cf0: 32 5f 54 59 50 45 20 75 69 6e 74 33 32 5f 74 0a 2_TYPE uint32_t.
5d00: 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 # else.# define
5d10: 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 6e 73 UINT32_TYPE uns
5d20: 69 67 6e 65 64 20 69 6e 74 0a 23 20 65 6e 64 69 igned int.# endi
5d30: 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 f.#endif.#ifndef
5d40: 20 55 49 4e 54 31 36 5f 54 59 50 45 0a 23 20 69 UINT16_TYPE.# i
5d50: 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 31 36 fdef HAVE_UINT16
5d60: 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e _T.# define UIN
5d70: 54 31 36 5f 54 59 50 45 20 75 69 6e 74 31 36 5f T16_TYPE uint16_
5d80: 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 t.# else.# defi
5d90: 6e 65 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 ne UINT16_TYPE u
5da0: 6e 73 69 67 6e 65 64 20 73 68 6f 72 74 20 69 6e nsigned short in
5db0: 74 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 t.# endif.#endif
5dc0: 0a 23 69 66 6e 64 65 66 20 49 4e 54 31 36 5f 54 .#ifndef INT16_T
5dd0: 59 50 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 YPE.# ifdef HAVE
5de0: 5f 49 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 69 _INT16_T.# defi
5df0: 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 69 6e ne INT16_TYPE in
5e00: 74 31 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 t16_t.# else.#
5e10: 64 65 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 50 define INT16_TYP
5e20: 45 20 73 68 6f 72 74 20 69 6e 74 0a 23 20 65 6e E short int.# en
5e30: 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 dif.#endif.#ifnd
5e40: 65 66 20 55 49 4e 54 38 5f 54 59 50 45 0a 23 20 ef UINT8_TYPE.#
5e50: 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 38 ifdef HAVE_UINT8
5e60: 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e _T.# define UIN
5e70: 54 38 5f 54 59 50 45 20 75 69 6e 74 38 5f 74 0a T8_TYPE uint8_t.
5e80: 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 # else.# define
5e90: 20 55 49 4e 54 38 5f 54 59 50 45 20 75 6e 73 69 UINT8_TYPE unsi
5ea0: 67 6e 65 64 20 63 68 61 72 0a 23 20 65 6e 64 69 gned char.# endi
5eb0: 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 f.#endif.#ifndef
5ec0: 20 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 64 INT8_TYPE.# ifd
5ed0: 65 66 20 48 41 56 45 5f 49 4e 54 38 5f 54 0a 23 ef HAVE_INT8_T.#
5ee0: 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 define INT8_TY
5ef0: 50 45 20 69 6e 74 38 5f 74 0a 23 20 65 6c 73 65 PE int8_t.# else
5f00: 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f .# define INT8_
5f10: 54 59 50 45 20 73 69 67 6e 65 64 20 63 68 61 72 TYPE signed char
5f20: 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a .# endif.#endif.
5f30: 23 69 66 6e 64 65 66 20 4c 4f 4e 47 44 4f 55 42 #ifndef LONGDOUB
5f40: 4c 45 5f 54 59 50 45 0a 23 20 64 65 66 69 6e 65 LE_TYPE.# define
5f50: 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 45 LONGDOUBLE_TYPE
5f60: 20 6c 6f 6e 67 20 64 6f 75 62 6c 65 0a 23 65 6e long double.#en
5f70: 64 69 66 0a 74 79 70 65 64 65 66 20 73 71 6c 69 dif.typedef sqli
5f80: 74 65 5f 69 6e 74 36 34 20 69 36 34 3b 20 20 20 te_int64 i64;
5f90: 20 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 /* 8-byte
5fa0: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 signed integer
5fb0: 2a 2f 0a 74 79 70 65 64 65 66 20 73 71 6c 69 74 */.typedef sqlit
5fc0: 65 5f 75 69 6e 74 36 34 20 75 36 34 3b 20 20 20 e_uint64 u64;
5fd0: 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 /* 8-byte
5fe0: 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 unsigned integer
5ff0: 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 */.typedef UINT
6000: 33 32 5f 54 59 50 45 20 75 33 32 3b 20 20 20 20 32_TYPE u32;
6010: 20 20 20 20 20 20 20 2f 2a 20 34 2d 62 79 74 65 /* 4-byte
6020: 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 unsigned intege
6030: 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e r */.typedef UIN
6040: 54 31 36 5f 54 59 50 45 20 75 31 36 3b 20 20 20 T16_TYPE u16;
6050: 20 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 /* 2-byt
6060: 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 e unsigned integ
6070: 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e er */.typedef IN
6080: 54 31 36 5f 54 59 50 45 20 69 31 36 3b 20 20 20 T16_TYPE i16;
6090: 20 20 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 /* 2-by
60a0: 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 te signed intege
60b0: 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e r */.typedef UIN
60c0: 54 38 5f 54 59 50 45 20 75 38 3b 20 20 20 20 20 T8_TYPE u8;
60d0: 20 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 /* 1-byt
60e0: 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 e unsigned integ
60f0: 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e er */.typedef IN
6100: 54 38 5f 54 59 50 45 20 69 38 3b 20 20 20 20 20 T8_TYPE i8;
6110: 20 20 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 /* 1-by
6120: 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 te signed intege
6130: 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 r */../*.** SQLI
6140: 54 45 5f 4d 41 58 5f 55 33 32 20 69 73 20 61 20 TE_MAX_U32 is a
6150: 75 36 34 20 63 6f 6e 73 74 61 6e 74 20 74 68 61 u64 constant tha
6160: 74 20 69 73 20 74 68 65 20 6d 61 78 69 6d 75 6d t is the maximum
6170: 20 75 36 34 20 76 61 6c 75 65 0a 2a 2a 20 74 68 u64 value.** th
6180: 61 74 20 63 61 6e 20 62 65 20 73 74 6f 72 65 64 at can be stored
6190: 20 69 6e 20 61 20 75 33 32 20 77 69 74 68 6f 75 in a u32 withou
61a0: 74 20 6c 6f 73 73 20 6f 66 20 64 61 74 61 2e 20 t loss of data.
61b0: 20 54 68 65 20 76 61 6c 75 65 0a 2a 2a 20 69 73 The value.** is
61c0: 20 30 78 30 30 30 30 30 30 30 30 66 66 66 66 66 0x00000000fffff
61d0: 66 66 66 2e 20 20 42 75 74 20 62 65 63 61 75 73 fff. But becaus
61e0: 65 20 6f 66 20 71 75 69 72 6b 73 20 6f 66 20 73 e of quirks of s
61f0: 6f 6d 65 20 63 6f 6d 70 69 6c 65 72 73 2c 20 77 ome compilers, w
6200: 65 0a 2a 2a 20 68 61 76 65 20 74 6f 20 73 70 65 e.** have to spe
6210: 63 69 66 79 20 74 68 65 20 76 61 6c 75 65 20 69 cify the value i
6220: 6e 20 74 68 65 20 6c 65 73 73 20 69 6e 74 75 69 n the less intui
6230: 74 69 76 65 20 6d 61 6e 6e 65 72 20 73 68 6f 77 tive manner show
6240: 6e 3a 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 n:.*/.#define SQ
6250: 4c 49 54 45 5f 4d 41 58 5f 55 33 32 20 20 28 28 LITE_MAX_U32 ((
6260: 28 28 75 36 34 29 31 29 3c 3c 33 32 29 2d 31 29 ((u64)1)<<32)-1)
6270: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 61 ../*.** The data
6280: 74 79 70 65 20 75 73 65 64 20 74 6f 20 73 74 6f type used to sto
6290: 72 65 20 65 73 74 69 6d 61 74 65 73 20 6f 66 20 re estimates of
62a0: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f the number of ro
62b0: 77 73 20 69 6e 20 61 0a 2a 2a 20 74 61 62 6c 65 ws in a.** table
62c0: 20 6f 72 20 69 6e 64 65 78 2e 20 20 54 68 69 73 or index. This
62d0: 20 69 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 20 is an unsigned
62e0: 69 6e 74 65 67 65 72 20 74 79 70 65 2e 20 20 46 integer type. F
62f0: 6f 72 20 39 39 2e 39 25 20 6f 66 0a 2a 2a 20 74 or 99.9% of.** t
6300: 68 65 20 77 6f 72 6c 64 2c 20 61 20 33 32 2d 62 he world, a 32-b
6310: 69 74 20 69 6e 74 65 67 65 72 20 69 73 20 73 75 it integer is su
6320: 66 66 69 63 69 65 6e 74 2e 20 20 42 75 74 20 61 fficient. But a
6330: 20 36 34 2d 62 69 74 20 69 6e 74 65 67 65 72 0a 64-bit integer.
6340: 2a 2a 20 63 61 6e 20 62 65 20 75 73 65 64 20 61 ** can be used a
6350: 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 69 t compile-time i
6360: 66 20 64 65 73 69 72 65 64 2e 0a 2a 2f 0a 23 69 f desired..*/.#i
6370: 66 64 65 66 20 53 51 4c 49 54 45 5f 36 34 42 49 fdef SQLITE_64BI
6380: 54 5f 53 54 41 54 53 0a 20 74 79 70 65 64 65 66 T_STATS. typedef
6390: 20 75 36 34 20 74 52 6f 77 63 6e 74 3b 20 20 20 u64 tRowcnt;
63a0: 20 2f 2a 20 36 34 2d 62 69 74 20 6f 6e 6c 79 20 /* 64-bit only
63b0: 69 66 20 72 65 71 75 65 73 74 65 64 20 61 74 20 if requested at
63c0: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 2a 2f 0a compile-time */.
63d0: 23 65 6c 73 65 0a 20 74 79 70 65 64 65 66 20 75 #else. typedef u
63e0: 33 32 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 32 tRowcnt; /
63f0: 2a 20 33 32 2d 62 69 74 20 69 73 20 74 68 65 20 * 32-bit is the
6400: 64 65 66 61 75 6c 74 20 2a 2f 0a 23 65 6e 64 69 default */.#endi
6410: 66 0a 0a 2f 2a 0a 2a 2a 20 45 73 74 69 6d 61 74 f../*.** Estimat
6420: 65 64 20 71 75 61 6e 74 69 74 69 65 73 20 75 73 ed quantities us
6430: 65 64 20 66 6f 72 20 71 75 65 72 79 20 70 6c 61 ed for query pla
6440: 6e 6e 69 6e 67 20 61 72 65 20 73 74 6f 72 65 64 nning are stored
6450: 20 61 73 20 31 36 2d 62 69 74 0a 2a 2a 20 6c 6f as 16-bit.** lo
6460: 67 61 72 69 74 68 6d 73 2e 20 20 46 6f 72 20 71 garithms. For q
6470: 75 61 6e 74 69 74 79 20 58 2c 20 74 68 65 20 76 uantity X, the v
6480: 61 6c 75 65 20 73 74 6f 72 65 64 20 69 73 20 31 alue stored is 1
6490: 30 2a 6c 6f 67 32 28 58 29 2e 20 20 54 68 69 73 0*log2(X). This
64a0: 0a 2a 2a 20 67 69 76 65 73 20 61 20 70 6f 73 73 .** gives a poss
64b0: 69 62 6c 65 20 72 61 6e 67 65 20 6f 66 20 76 61 ible range of va
64c0: 6c 75 65 73 20 6f 66 20 61 70 70 72 6f 78 69 6d lues of approxim
64d0: 61 74 65 6c 79 20 31 2e 30 65 39 38 36 20 74 6f ately 1.0e986 to
64e0: 20 31 65 2d 39 38 36 2e 0a 2a 2a 20 42 75 74 20 1e-986..** But
64f0: 74 68 65 20 61 6c 6c 6f 77 65 64 20 76 61 6c 75 the allowed valu
6500: 65 73 20 61 72 65 20 22 67 72 61 69 6e 79 22 2e es are "grainy".
6510: 20 20 4e 6f 74 20 65 76 65 72 79 20 76 61 6c 75 Not every valu
6520: 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 61 62 e is representab
6530: 6c 65 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 le..** For examp
6540: 6c 65 2c 20 71 75 61 6e 74 69 74 69 65 73 20 31 le, quantities 1
6550: 36 20 61 6e 64 20 31 37 20 61 72 65 20 62 6f 74 6 and 17 are bot
6560: 68 20 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 h represented by
6570: 20 61 20 4c 6f 67 45 73 74 0a 2a 2a 20 6f 66 20 a LogEst.** of
6580: 34 30 2e 20 20 48 6f 77 65 76 65 72 2c 20 73 69 40. However, si
6590: 6e 63 65 20 4c 6f 67 45 73 74 20 71 75 61 6e 74 nce LogEst quant
65a0: 69 74 69 65 73 20 61 72 65 20 73 75 70 70 6f 73 ities are suppos
65b0: 65 20 74 6f 20 62 65 20 65 73 74 69 6d 61 74 65 e to be estimate
65c0: 73 2c 0a 2a 2a 20 6e 6f 74 20 65 78 61 63 74 20 s,.** not exact
65d0: 76 61 6c 75 65 73 2c 20 74 68 69 73 20 69 6d 70 values, this imp
65e0: 72 65 63 69 73 69 6f 6e 20 69 73 20 6e 6f 74 20 recision is not
65f0: 61 20 70 72 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a 2a a problem..**.**
6600: 20 22 4c 6f 67 45 73 74 22 20 69 73 20 73 68 6f "LogEst" is sho
6610: 72 74 20 66 6f 72 20 22 4c 6f 67 61 72 69 74 68 rt for "Logarith
6620: 6d 69 63 20 45 73 74 69 6d 61 74 65 22 2e 0a 2a mic Estimate"..*
6630: 2a 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a 2a *.** Examples:.*
6640: 2a 20 20 20 20 20 20 31 20 2d 3e 20 30 20 20 20 * 1 -> 0
6650: 20 20 20 20 20 20 20 20 20 20 20 32 30 20 2d 3e 20 ->
6660: 20 34 33 20 20 20 20 20 20 20 20 20 20 31 30 30 43 100
6670: 30 30 20 2d 3e 20 31 33 32 0a 2a 2a 20 20 20 20 00 -> 132.**
6680: 20 20 32 20 2d 3e 20 31 30 20 20 20 20 20 20 20 2 -> 10
6690: 20 20 20 20 20 20 32 35 20 2d 3e 20 34 36 20 20 25 -> 46
66a0: 20 20 20 20 20 20 20 20 32 35 30 30 30 20 2d 3e 25000 ->
66b0: 20 31 34 36 0a 2a 2a 20 20 20 20 20 20 33 20 2d 146.** 3 -
66c0: 3e 20 31 36 20 20 20 20 20 20 20 20 20 20 20 20 > 16
66d0: 31 30 30 20 2d 3e 20 36 36 20 20 20 20 20 20 20 100 -> 66
66e0: 20 31 30 30 30 30 30 30 20 2d 3e 20 31 39 39 0a 1000000 -> 199.
66f0: 2a 2a 20 20 20 20 20 20 34 20 2d 3e 20 32 30 20 ** 4 -> 20
6700: 20 20 20 20 20 20 20 20 20 20 31 30 30 30 20 2d 1000 -
6710: 3e 20 39 39 20 20 20 20 20 20 20 20 31 30 34 38 > 99 1048
6720: 35 37 36 20 2d 3e 20 32 30 30 0a 2a 2a 20 20 20 576 -> 200.**
6730: 20 20 31 30 20 2d 3e 20 33 33 20 20 20 20 20 20 10 -> 33
6740: 20 20 20 20 20 31 30 32 34 20 2d 3e 20 31 30 30 1024 -> 100
6750: 20 20 20 20 34 32 39 34 39 36 37 32 39 36 20 2d 4294967296 -
6760: 3e 20 33 32 30 0a 2a 2a 0a 2a 2a 20 54 68 65 20 > 320.**.** The
6770: 4c 6f 67 45 73 74 20 63 61 6e 20 62 65 20 6e 65 LogEst can be ne
6780: 67 61 74 69 76 65 20 74 6f 20 69 6e 64 69 63 61 gative to indica
6790: 74 65 20 66 72 61 63 74 69 6f 6e 61 6c 20 76 61 te fractional va
67a0: 6c 75 65 73 2e 0a 2a 2a 20 45 78 61 6d 70 6c 65 lues..** Example
67b0: 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 30 2e 35 20 s:.**.** 0.5
67c0: 2d 3e 20 2d 31 30 20 20 20 20 20 20 20 20 20 20 -> -10
67d0: 20 30 2e 31 20 2d 3e 20 2d 33 33 20 20 20 20 20 0.1 -> -33
67e0: 20 20 20 30 2e 30 36 32 35 20 2d 3e 20 2d 34 30 0.0625 -> -40
67f0: 0a 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 .*/.typedef INT1
6800: 36 5f 54 59 50 45 20 4c 6f 67 45 73 74 3b 0a 0a 6_TYPE LogEst;..
6810: 2f 2a 0a 2a 2a 20 53 65 74 20 74 68 65 20 53 51 /*.** Set the SQ
6820: 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 6d 61 63 LITE_PTRSIZE mac
6830: 72 6f 20 74 6f 20 74 68 65 20 6e 75 6d 62 65 72 ro to the number
6840: 20 6f 66 20 62 79 74 65 73 20 69 6e 20 61 20 70 of bytes in a p
6850: 6f 69 6e 74 65 72 0a 2a 2f 0a 23 69 66 6e 64 65 ointer.*/.#ifnde
6860: 66 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 f SQLITE_PTRSIZE
6870: 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f 5f .# if defined(__
6880: 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f SIZEOF_POINTER__
6890: 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c ).# define SQL
68a0: 49 54 45 5f 50 54 52 53 49 5a 45 20 5f 5f 53 49 ITE_PTRSIZE __SI
68b0: 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f 0a 23 ZEOF_POINTER__.#
68c0: 20 65 6c 69 66 20 64 65 66 69 6e 65 64 28 69 33 elif defined(i3
68d0: 38 36 29 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 86) || defin
68e0: 65 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 20 7c ed(__i386__) |
68f0: 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 58 38 | defined(_M_IX8
6900: 36 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 6) || \.
6910: 20 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 52 4d defined(_M_ARM
6920: 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f ) || defined(_
6930: 5f 61 72 6d 5f 5f 29 20 20 20 20 7c 7c 20 64 65 _arm__) || de
6940: 66 69 6e 65 64 28 5f 5f 78 38 36 29 20 20 20 7c fined(__x86) |
6950: 7c 20 20 20 20 5c 0a 20 20 20 20 20 20 28 64 65 | \. (de
6960: 66 69 6e 65 64 28 5f 5f 54 4f 53 5f 41 49 58 5f fined(__TOS_AIX_
6970: 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f _) && !defined(_
6980: 5f 36 34 42 49 54 5f 5f 29 29 0a 23 20 20 20 64 _64BIT__)).# d
6990: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 efine SQLITE_PTR
69a0: 53 49 5a 45 20 34 0a 23 20 65 6c 73 65 0a 23 20 SIZE 4.# else.#
69b0: 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f define SQLITE_
69c0: 50 54 52 53 49 5a 45 20 38 0a 23 20 65 6e 64 69 PTRSIZE 8.# endi
69d0: 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 54 68 65 f.#endif../* The
69e0: 20 75 70 74 72 20 74 79 70 65 20 69 73 20 61 6e uptr type is an
69f0: 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 unsigned intege
6a00: 72 20 6c 61 72 67 65 20 65 6e 6f 75 67 68 20 74 r large enough t
6a10: 6f 20 68 6f 6c 64 20 61 20 70 6f 69 6e 74 65 72 o hold a pointer
6a20: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
6a30: 48 41 56 45 5f 53 54 44 49 4e 54 5f 48 29 0a 20 HAVE_STDINT_H).
6a40: 20 74 79 70 65 64 65 66 20 75 69 6e 74 70 74 72 typedef uintptr
6a50: 5f 74 20 75 70 74 72 3b 0a 23 65 6c 69 66 20 53 _t uptr;.#elif S
6a60: 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 3d 3d 34 QLITE_PTRSIZE==4
6a70: 0a 20 20 74 79 70 65 64 65 66 20 75 33 32 20 75 . typedef u32 u
6a80: 70 74 72 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 ptr;.#else. typ
6a90: 65 64 65 66 20 75 36 34 20 75 70 74 72 3b 0a 23 edef u64 uptr;.#
6aa0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
6ab0: 20 53 51 4c 49 54 45 5f 57 49 54 48 49 4e 28 50 SQLITE_WITHIN(P
6ac0: 2c 53 2c 45 29 20 6d 61 63 72 6f 20 63 68 65 63 ,S,E) macro chec
6ad0: 6b 73 20 74 6f 20 73 65 65 20 69 66 20 70 6f 69 ks to see if poi
6ae0: 6e 74 65 72 20 50 20 70 6f 69 6e 74 73 20 74 6f nter P points to
6af0: 0a 2a 2a 20 73 6f 6d 65 74 68 69 6e 67 20 62 65 .** something be
6b00: 74 77 65 65 6e 20 53 20 28 69 6e 63 6c 75 73 69 tween S (inclusi
6b10: 76 65 29 20 61 6e 64 20 45 20 28 65 78 63 6c 75 ve) and E (exclu
6b20: 73 69 76 65 29 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 sive)..**.** In
6b30: 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 53 20 69 other words, S i
6b40: 73 20 61 20 62 75 66 66 65 72 20 61 6e 64 20 45 s a buffer and E
6b50: 20 69 73 20 61 20 70 6f 69 6e 74 65 72 20 74 6f is a pointer to
6b60: 20 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 the first byte
6b70: 61 66 74 65 72 0a 2a 2a 20 74 68 65 20 65 6e 64 after.** the end
6b80: 20 6f 66 20 62 75 66 66 65 72 20 53 2e 20 20 54 of buffer S. T
6b90: 68 69 73 20 6d 61 63 72 6f 20 72 65 74 75 72 6e his macro return
6ba0: 73 20 74 72 75 65 20 69 66 20 50 20 70 6f 69 6e s true if P poin
6bb0: 74 73 20 74 6f 20 73 6f 6d 65 74 68 69 6e 67 0a ts to something.
6bc0: 2a 2a 20 63 6f 6e 74 61 69 6e 65 64 20 77 69 74 ** contained wit
6bd0: 68 69 6e 20 74 68 65 20 62 75 66 66 65 72 20 53 hin the buffer S
6be0: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
6bf0: 49 54 45 5f 57 49 54 48 49 4e 28 50 2c 53 2c 45 ITE_WITHIN(P,S,E
6c00: 29 20 28 28 28 75 70 74 72 29 28 50 29 3e 3d 28 ) (((uptr)(P)>=(
6c10: 75 70 74 72 29 28 53 29 29 26 26 28 28 75 70 74 uptr)(S))&&((upt
6c20: 72 29 28 50 29 3c 28 75 70 74 72 29 28 45 29 29 r)(P)<(uptr)(E))
6c30: 29 0a 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 ).../*.** Macros
6c40: 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 77 68 to determine wh
6c50: 65 74 68 65 72 20 74 68 65 20 6d 61 63 68 69 6e ether the machin
6c60: 65 20 69 73 20 62 69 67 20 6f 72 20 6c 69 74 74 e is big or litt
6c70: 6c 65 20 65 6e 64 69 61 6e 2c 0a 2a 2a 20 61 6e le endian,.** an
6c80: 64 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 d whether or not
6c90: 20 74 68 61 74 20 64 65 74 65 72 6d 69 6e 61 74 that determinat
6ca0: 69 6f 6e 20 69 73 20 72 75 6e 2d 74 69 6d 65 20 ion is run-time
6cb0: 6f 72 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 2e or compile-time.
6cc0: 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 62 65 73 74 20 .**.** For best
6cd0: 70 65 72 66 6f 72 6d 61 6e 63 65 2c 20 61 6e 20 performance, an
6ce0: 61 74 74 65 6d 70 74 20 69 73 20 6d 61 64 65 20 attempt is made
6cf0: 74 6f 20 67 75 65 73 73 20 61 74 20 74 68 65 20 to guess at the
6d00: 62 79 74 65 2d 6f 72 64 65 72 0a 2a 2a 20 75 73 byte-order.** us
6d10: 69 6e 67 20 43 2d 70 72 65 70 72 6f 63 65 73 73 ing C-preprocess
6d20: 6f 72 20 6d 61 63 72 6f 73 2e 20 20 49 66 20 74 or macros. If t
6d30: 68 61 74 20 69 73 20 75 6e 73 75 63 63 65 73 73 hat is unsuccess
6d40: 66 75 6c 2c 20 6f 72 20 69 66 0a 2a 2a 20 2d 44 ful, or if.** -D
6d50: 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 SQLITE_BYTEORDER
6d60: 3d 30 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 =0 is set, then
6d70: 62 79 74 65 2d 6f 72 64 65 72 20 69 73 20 64 65 byte-order is de
6d80: 74 65 72 6d 69 6e 65 64 0a 2a 2a 20 61 74 20 72 termined.** at r
6d90: 75 6e 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 69 66 6e un-time..*/.#ifn
6da0: 64 65 66 20 53 51 4c 49 54 45 5f 42 59 54 45 4f def SQLITE_BYTEO
6db0: 52 44 45 52 0a 23 20 69 66 20 64 65 66 69 6e 65 RDER.# if define
6dc0: 64 28 69 33 38 36 29 20 20 20 20 20 20 7c 7c 20 d(i386) ||
6dd0: 64 65 66 69 6e 65 64 28 5f 5f 69 33 38 36 5f 5f defined(__i386__
6de0: 29 20 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 ) || define
6df0: 64 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 20 20 d(_M_IX86) ||
6e00: 20 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 \. defined(
6e10: 5f 5f 78 38 36 5f 36 34 29 20 20 7c 7c 20 64 65 __x86_64) || de
6e20: 66 69 6e 65 64 28 5f 5f 78 38 36 5f 36 34 5f 5f fined(__x86_64__
6e30: 29 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 ) || defined(
6e40: 5f 4d 5f 58 36 34 29 20 20 7c 7c 20 20 20 20 5c _M_X64) || \
6e50: 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f 4d . defined(_M
6e60: 5f 41 4d 44 36 34 29 20 20 7c 7c 20 64 65 66 69 _AMD64) || defi
6e70: 6e 65 64 28 5f 4d 5f 41 52 4d 29 20 20 20 20 20 ned(_M_ARM)
6e80: 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f || defined(__
6e90: 78 38 36 29 20 20 20 7c 7c 20 20 20 20 5c 0a 20 x86) || \.
6ea0: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 41 52 defined(__AR
6eb0: 4d 45 4c 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 MEL__) || define
6ec0: 64 28 5f 5f 41 41 52 43 48 36 34 45 4c 5f 5f 29 d(__AARCH64EL__)
6ed0: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 || defined(_M_A
6ee0: 52 4d 36 34 29 0a 23 20 20 20 64 65 66 69 6e 65 RM64).# define
6ef0: 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 SQLITE_BYTEORDE
6f00: 52 20 20 20 20 31 32 33 34 0a 23 20 65 6c 69 66 R 1234.# elif
6f10: 20 64 65 66 69 6e 65 64 28 73 70 61 72 63 29 20 defined(sparc)
6f20: 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f || defined(_
6f30: 5f 70 70 63 5f 5f 29 20 7c 7c 20 5c 0a 20 20 20 _ppc__) || \.
6f40: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 41 52 defined(__AR
6f50: 4d 45 42 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 MEB__) || define
6f60: 64 28 5f 5f 41 41 52 43 48 36 34 45 42 5f 5f 29 d(__AARCH64EB__)
6f70: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
6f80: 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 TE_BYTEORDER
6f90: 34 33 32 31 0a 23 20 65 6c 73 65 0a 23 20 20 20 4321.# else.#
6fa0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 59 define SQLITE_BY
6fb0: 54 45 4f 52 44 45 52 20 30 0a 23 20 65 6e 64 69 TEORDER 0.# endi
6fc0: 66 0a 23 65 6e 64 69 66 0a 23 69 66 20 53 51 4c f.#endif.#if SQL
6fd0: 49 54 45 5f 42 59 54 45 4f 52 44 45 52 3d 3d 34 ITE_BYTEORDER==4
6fe0: 33 32 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 321.# define SQL
6ff0: 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 ITE_BIGENDIAN
7000: 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1.# define SQLI
7010: 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 TE_LITTLEENDIAN
7020: 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 0.# define SQLIT
7030: 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 53 E_UTF16NATIVE S
7040: 51 4c 49 54 45 5f 55 54 46 31 36 42 45 0a 23 65 QLITE_UTF16BE.#e
7050: 6c 69 66 20 53 51 4c 49 54 45 5f 42 59 54 45 4f lif SQLITE_BYTEO
7060: 52 44 45 52 3d 3d 31 32 33 34 0a 23 20 64 65 66 RDER==1234.# def
7070: 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 4e ine SQLITE_BIGEN
7080: 44 49 41 4e 20 20 20 20 30 0a 23 20 64 65 66 69 DIAN 0.# defi
7090: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
70a0: 45 4e 44 49 41 4e 20 31 0a 23 20 64 65 66 69 6e ENDIAN 1.# defin
70b0: 65 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 e SQLITE_UTF16NA
70c0: 54 49 56 45 20 20 53 51 4c 49 54 45 5f 55 54 46 TIVE SQLITE_UTF
70d0: 31 36 4c 45 0a 23 65 6c 73 65 0a 23 20 69 66 64 16LE.#else.# ifd
70e0: 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 ef SQLITE_AMALGA
70f0: 4d 41 54 49 4f 4e 0a 20 20 63 6f 6e 73 74 20 69 MATION. const i
7100: 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 20 3d 20 nt sqlite3one =
7110: 31 3b 0a 23 20 65 6c 73 65 0a 20 20 65 78 74 65 1;.# else. exte
7120: 72 6e 20 63 6f 6e 73 74 20 69 6e 74 20 73 71 6c rn const int sql
7130: 69 74 65 33 6f 6e 65 3b 0a 23 20 65 6e 64 69 66 ite3one;.# endif
7140: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
7150: 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 28 2a _BIGENDIAN (*
7160: 28 63 68 61 72 20 2a 29 28 26 73 71 6c 69 74 65 (char *)(&sqlite
7170: 33 6f 6e 65 29 3d 3d 30 29 0a 23 20 64 65 66 69 3one)==0).# defi
7180: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
7190: 45 4e 44 49 41 4e 20 28 2a 28 63 68 61 72 20 2a ENDIAN (*(char *
71a0: 29 28 26 73 71 6c 69 74 65 33 6f 6e 65 29 3d 3d )(&sqlite3one)==
71b0: 31 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1).# define SQLI
71c0: 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 TE_UTF16NATIVE
71d0: 28 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 (SQLITE_BIGENDIA
71e0: 4e 3f 53 51 4c 49 54 45 5f 55 54 46 31 36 42 45 N?SQLITE_UTF16BE
71f0: 3a 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 29 :SQLITE_UTF16LE)
7200: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 43 .#endif../*.** C
7210: 6f 6e 73 74 61 6e 74 73 20 66 6f 72 20 74 68 65 onstants for the
7220: 20 6c 61 72 67 65 73 74 20 61 6e 64 20 73 6d 61 largest and sma
7230: 6c 6c 65 73 74 20 70 6f 73 73 69 62 6c 65 20 36 llest possible 6
7240: 34 2d 62 69 74 20 73 69 67 6e 65 64 20 69 6e 74 4-bit signed int
7250: 65 67 65 72 73 2e 0a 2a 2a 20 54 68 65 73 65 20 egers..** These
7260: 6d 61 63 72 6f 73 20 61 72 65 20 64 65 73 69 67 macros are desig
7270: 6e 65 64 20 74 6f 20 77 6f 72 6b 20 63 6f 72 72 ned to work corr
7280: 65 63 74 6c 79 20 6f 6e 20 62 6f 74 68 20 33 32 ectly on both 32
7290: 2d 62 69 74 20 61 6e 64 20 36 34 2d 62 69 74 0a -bit and 64-bit.
72a0: 2a 2a 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a 2f ** compilers..*/
72b0: 0a 23 64 65 66 69 6e 65 20 4c 41 52 47 45 53 54 .#define LARGEST
72c0: 5f 49 4e 54 36 34 20 20 28 30 78 66 66 66 66 66 _INT64 (0xfffff
72d0: 66 66 66 7c 28 28 28 69 36 34 29 30 78 37 66 66 fff|(((i64)0x7ff
72e0: 66 66 66 66 66 29 3c 3c 33 32 29 29 0a 23 64 65 fffff)<<32)).#de
72f0: 66 69 6e 65 20 53 4d 41 4c 4c 45 53 54 5f 49 4e fine SMALLEST_IN
7300: 54 36 34 20 28 28 28 69 36 34 29 2d 31 29 20 2d T64 (((i64)-1) -
7310: 20 4c 41 52 47 45 53 54 5f 49 4e 54 36 34 29 0a LARGEST_INT64).
7320: 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e 64 20 75 70 20 ./*.** Round up
7330: 61 20 6e 75 6d 62 65 72 20 74 6f 20 74 68 65 20 a number to the
7340: 6e 65 78 74 20 6c 61 72 67 65 72 20 6d 75 6c 74 next larger mult
7350: 69 70 6c 65 20 6f 66 20 38 2e 20 20 54 68 69 73 iple of 8. This
7360: 20 69 73 20 75 73 65 64 0a 2a 2a 20 74 6f 20 66 is used.** to f
7370: 6f 72 63 65 20 38 2d 62 79 74 65 20 61 6c 69 67 orce 8-byte alig
7380: 6e 6d 65 6e 74 20 6f 6e 20 36 34 2d 62 69 74 20 nment on 64-bit
7390: 61 72 63 68 69 74 65 63 74 75 72 65 73 2e 0a 2a architectures..*
73a0: 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e 44 38 /.#define ROUND8
73b0: 28 78 29 20 20 20 20 20 28 28 28 78 29 2b 37 29 (x) (((x)+7)
73c0: 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e &~7)../*.** Roun
73d0: 64 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 6e 65 d down to the ne
73e0: 61 72 65 73 74 20 6d 75 6c 74 69 70 6c 65 20 6f arest multiple o
73f0: 66 20 38 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 52 f 8.*/.#define R
7400: 4f 55 4e 44 44 4f 57 4e 38 28 78 29 20 28 28 78 OUNDDOWN8(x) ((x
7410: 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 )&~7)../*.** Ass
7420: 65 72 74 20 74 68 61 74 20 74 68 65 20 70 6f 69 ert that the poi
7430: 6e 74 65 72 20 58 20 69 73 20 61 6c 69 67 6e 65 nter X is aligne
7440: 64 20 74 6f 20 61 6e 20 38 2d 62 79 74 65 20 62 d to an 8-byte b
7450: 6f 75 6e 64 61 72 79 2e 20 20 54 68 69 73 0a 2a oundary. This.*
7460: 2a 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 * macro is used
7470: 6f 6e 6c 79 20 77 69 74 68 69 6e 20 61 73 73 65 only within asse
7480: 72 74 28 29 20 74 6f 20 76 65 72 69 66 79 20 74 rt() to verify t
7490: 68 61 74 20 74 68 65 20 63 6f 64 65 20 67 65 74 hat the code get
74a0: 73 0a 2a 2a 20 61 6c 6c 20 61 6c 69 67 6e 6d 65 s.** all alignme
74b0: 6e 74 20 72 65 73 74 72 69 63 74 69 6f 6e 73 20 nt restrictions
74c0: 63 6f 72 72 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 45 correct..**.** E
74d0: 78 63 65 70 74 2c 20 69 66 20 53 51 4c 49 54 45 xcept, if SQLITE
74e0: 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 5f _4_BYTE_ALIGNED_
74f0: 4d 41 4c 4c 4f 43 20 69 73 20 64 65 66 69 6e 65 MALLOC is define
7500: 64 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 75 d, then the.** u
7510: 6e 64 65 72 6c 79 69 6e 67 20 6d 61 6c 6c 6f 63 nderlying malloc
7520: 28 29 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f () implementatio
7530: 6e 20 6d 69 67 68 74 20 72 65 74 75 72 6e 20 75 n might return u
7540: 73 20 34 2d 62 79 74 65 20 61 6c 69 67 6e 65 64 s 4-byte aligned
7550: 0a 2a 2a 20 70 6f 69 6e 74 65 72 73 2e 20 20 49 .** pointers. I
7560: 6e 20 74 68 61 74 20 63 61 73 65 2c 20 6f 6e 6c n that case, onl
7570: 79 20 76 65 72 69 66 79 20 34 2d 62 79 74 65 20 y verify 4-byte
7580: 61 6c 69 67 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 69 alignment..*/.#i
7590: 66 64 65 66 20 53 51 4c 49 54 45 5f 34 5f 42 59 fdef SQLITE_4_BY
75a0: 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c 4f TE_ALIGNED_MALLO
75b0: 43 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 54 C.# define EIGHT
75c0: 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 _BYTE_ALIGNMENT(
75d0: 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 28 X) ((((char*)(
75e0: 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 33 X) - (char*)0)&3
75f0: 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 )==0).#else.# de
7600: 66 69 6e 65 20 45 49 47 48 54 5f 42 59 54 45 5f fine EIGHT_BYTE_
7610: 41 4c 49 47 4e 4d 45 4e 54 28 58 29 20 20 20 28 ALIGNMENT(X) (
7620: 28 28 28 63 68 61 72 2a 29 28 58 29 20 2d 20 28 (((char*)(X) - (
7630: 63 68 61 72 2a 29 30 29 26 37 29 3d 3d 30 29 0a char*)0)&7)==0).
7640: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 69 #endif../*.** Di
7650: 73 61 62 6c 65 20 4d 4d 41 50 20 6f 6e 20 70 6c sable MMAP on pl
7660: 61 74 66 6f 72 6d 73 20 77 68 65 72 65 20 69 74 atforms where it
7670: 20 69 73 20 6b 6e 6f 77 6e 20 74 6f 20 6e 6f 74 is known to not
7680: 20 77 6f 72 6b 0a 2a 2f 0a 23 69 66 20 64 65 66 work.*/.#if def
7690: 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f 5f ined(__OpenBSD__
76a0: 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 51 ) || defined(__Q
76b0: 4e 58 4e 54 4f 5f 5f 29 0a 23 20 75 6e 64 65 66 NXNTO__).# undef
76c0: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
76d0: 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 _SIZE.# define S
76e0: 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 QLITE_MAX_MMAP_S
76f0: 49 5a 45 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a IZE 0.#endif../*
7700: 0a 2a 2a 20 44 65 66 61 75 6c 74 20 6d 61 78 69 .** Default maxi
7710: 6d 75 6d 20 73 69 7a 65 20 6f 66 20 6d 65 6d 6f mum size of memo
7720: 72 79 20 75 73 65 64 20 62 79 20 6d 65 6d 6f 72 ry used by memor
7730: 79 2d 6d 61 70 70 65 64 20 49 2f 4f 20 69 6e 20 y-mapped I/O in
7740: 74 68 65 20 56 46 53 0a 2a 2f 0a 23 69 66 64 65 the VFS.*/.#ifde
7750: 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a 23 20 69 6e f __APPLE__.# in
7760: 63 6c 75 64 65 20 3c 54 61 72 67 65 74 43 6f 6e clude <TargetCon
7770: 64 69 74 69 6f 6e 61 6c 73 2e 68 3e 0a 23 65 6e ditionals.h>.#en
7780: 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 dif.#ifndef SQLI
7790: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
77a0: 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f 5f .# if defined(__
77b0: 6c 69 6e 75 78 5f 5f 29 20 5c 0a 20 20 7c 7c 20 linux__) \. ||
77c0: 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 defined(_WIN32)
77d0: 5c 0a 20 20 7c 7c 20 28 64 65 66 69 6e 65 64 28 \. || (defined(
77e0: 5f 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 64 65 __APPLE__) && de
77f0: 66 69 6e 65 64 28 5f 5f 4d 41 43 48 5f 5f 29 29 fined(__MACH__))
7800: 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 \. || defined(
7810: 5f 5f 73 75 6e 29 20 5c 0a 20 20 7c 7c 20 64 65 __sun) \. || de
7820: 66 69 6e 65 64 28 5f 5f 46 72 65 65 42 53 44 5f fined(__FreeBSD_
7830: 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 _) \. || define
7840: 64 28 5f 5f 44 72 61 67 6f 6e 46 6c 79 5f 5f 29 d(__DragonFly__)
7850: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
7860: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
7870: 20 30 78 37 66 66 66 30 30 30 30 20 20 2f 2a 20 0x7fff0000 /*
7880: 32 31 34 37 34 31 38 31 31 32 20 2a 2f 0a 23 20 2147418112 */.#
7890: 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e 65 20 else.# define
78a0: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
78b0: 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 66 0a 23 SIZE 0.# endif.#
78c0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
78d0: 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 5f 53 49 default MMAP_SI
78e0: 5a 45 20 69 73 20 7a 65 72 6f 20 6f 6e 20 61 6c ZE is zero on al
78f0: 6c 20 70 6c 61 74 66 6f 72 6d 73 2e 20 20 4f 72 l platforms. Or
7900: 2c 20 65 76 65 6e 20 69 66 20 61 20 6c 61 72 67 , even if a larg
7910: 65 72 0a 2a 2a 20 64 65 66 61 75 6c 74 20 4d 4d er.** default MM
7920: 41 50 5f 53 49 5a 45 20 69 73 20 73 70 65 63 69 AP_SIZE is speci
7930: 66 69 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d fied at compile-
7940: 74 69 6d 65 2c 20 6d 61 6b 65 20 73 75 72 65 20 time, make sure
7950: 74 68 61 74 20 69 74 20 64 6f 65 73 0a 2a 2a 20 that it does.**
7960: 6e 6f 74 20 65 78 63 65 65 64 20 74 68 65 20 6d not exceed the m
7970: 61 78 69 6d 75 6d 20 6d 6d 61 70 20 73 69 7a 65 aximum mmap size
7980: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c ..*/.#ifndef SQL
7990: 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 ITE_DEFAULT_MMAP
79a0: 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 _SIZE.# define S
79b0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d QLITE_DEFAULT_MM
79c0: 41 50 5f 53 49 5a 45 20 30 0a 23 65 6e 64 69 66 AP_SIZE 0.#endif
79d0: 0a 23 69 66 20 53 51 4c 49 54 45 5f 44 45 46 41 .#if SQLITE_DEFA
79e0: 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 3e 53 51 ULT_MMAP_SIZE>SQ
79f0: 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 LITE_MAX_MMAP_SI
7a00: 5a 45 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 ZE.# undef SQLIT
7a10: 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 E_DEFAULT_MMAP_S
7a20: 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 4c IZE.# define SQL
7a30: 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 ITE_DEFAULT_MMAP
7a40: 5f 53 49 5a 45 20 53 51 4c 49 54 45 5f 4d 41 58 _SIZE SQLITE_MAX
7a50: 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 65 6e 64 69 _MMAP_SIZE.#endi
7a60: 66 0a 0a 2f 2a 0a 2a 2a 20 53 45 4c 45 43 54 54 f../*.** SELECTT
7a70: 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 77 69 6c RACE_ENABLED wil
7a80: 6c 20 62 65 20 65 69 74 68 65 72 20 31 20 6f 72 l be either 1 or
7a90: 20 30 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 0 depending on
7aa0: 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 0a 2a whether or not.*
7ab0: 2a 20 74 68 65 20 53 65 6c 65 63 74 20 71 75 65 * the Select que
7ac0: 72 79 20 67 65 6e 65 72 61 74 6f 72 20 74 72 61 ry generator tra
7ad0: 63 69 6e 67 20 6c 6f 67 69 63 20 69 73 20 74 75 cing logic is tu
7ae0: 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 69 66 20 rned on..*/.#if
7af0: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 defined(SQLITE_E
7b00: 4e 41 42 4c 45 5f 53 45 4c 45 43 54 54 52 41 43 NABLE_SELECTTRAC
7b10: 45 29 0a 23 20 64 65 66 69 6e 65 20 53 45 4c 45 E).# define SELE
7b20: 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 CTTRACE_ENABLED
7b30: 31 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 1.#else.# define
7b40: 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 SELECTTRACE_ENA
7b50: 42 4c 45 44 20 30 0a 23 65 6e 64 69 66 0a 0a 2f BLED 0.#endif../
7b60: 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
7b70: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
7b80: 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 g structure is u
7b90: 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 sed to store the
7ba0: 20 62 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a busy-handler.**
7bb0: 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 61 20 callback for a
7bc0: 67 69 76 65 6e 20 73 71 6c 69 74 65 20 68 61 6e given sqlite han
7bd0: 64 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 dle..**.** The s
7be0: 71 6c 69 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 qlite.busyHandle
7bf0: 72 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 20 r member of the
7c00: 73 71 6c 69 74 65 20 73 74 72 75 63 74 20 63 6f sqlite struct co
7c10: 6e 74 61 69 6e 73 20 74 68 65 20 62 75 73 79 0a ntains the busy.
7c20: 2a 2a 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 ** callback for
7c30: 74 68 65 20 64 61 74 61 62 61 73 65 20 68 61 6e the database han
7c40: 64 6c 65 2e 20 45 61 63 68 20 70 61 67 65 72 20 dle. Each pager
7c50: 6f 70 65 6e 65 64 20 76 69 61 20 74 68 65 20 73 opened via the s
7c60: 71 6c 69 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 qlite.** handle
7c70: 69 73 20 70 61 73 73 65 64 20 61 20 70 6f 69 6e is passed a poin
7c80: 74 65 72 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 ter to sqlite.bu
7c90: 73 79 48 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 syHandler. The b
7ca0: 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 usy-handler.** c
7cb0: 61 6c 6c 62 61 63 6b 20 69 73 20 63 75 72 72 65 allback is curre
7cc0: 6e 74 6c 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c ntly invoked onl
7cd0: 79 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 y from within pa
7ce0: 67 65 72 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 ger.c..*/.typede
7cf0: 66 20 73 74 72 75 63 74 20 42 75 73 79 48 61 6e f struct BusyHan
7d00: 64 6c 65 72 20 42 75 73 79 48 61 6e 64 6c 65 72 dler BusyHandler
7d10: 3b 0a 73 74 72 75 63 74 20 42 75 73 79 48 61 6e ;.struct BusyHan
7d20: 64 6c 65 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 dler {. int (*x
7d30: 42 75 73 79 48 61 6e 64 6c 65 72 29 28 76 6f 69 BusyHandler)(voi
7d40: 64 20 2a 2c 69 6e 74 29 3b 20 20 2f 2a 20 54 68 d *,int); /* Th
7d50: 65 20 62 75 73 79 20 63 61 6c 6c 62 61 63 6b 20 e busy callback
7d60: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 42 75 73 79 */. void *pBusy
7d70: 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Arg;
7d80: 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 /* First
7d90: 61 72 67 20 74 6f 20 62 75 73 79 20 63 61 6c 6c arg to busy call
7da0: 62 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 42 back */. int nB
7db0: 75 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 usy;
7dc0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 /* I
7dd0: 6e 63 72 65 6d 65 6e 74 65 64 20 77 69 74 68 20 ncremented with
7de0: 65 61 63 68 20 62 75 73 79 20 63 61 6c 6c 20 2a each busy call *
7df0: 2f 0a 20 20 75 38 20 62 45 78 74 72 61 46 69 6c /. u8 bExtraFil
7e00: 65 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 eArg;
7e10: 20 20 20 20 20 20 2f 2a 20 49 6e 63 6c 75 64 65 /* Include
7e20: 20 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 61 73 sqlite3_file as
7e30: 20 63 61 6c 6c 62 61 63 6b 20 61 72 67 20 2a 2f callback arg */
7e40: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 4e 61 6d 65 20 .};../*.** Name
7e50: 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 of the master da
7e60: 74 61 62 61 73 65 20 74 61 62 6c 65 2e 20 20 54 tabase table. T
7e70: 68 65 20 6d 61 73 74 65 72 20 64 61 74 61 62 61 he master databa
7e80: 73 65 20 74 61 62 6c 65 0a 2a 2a 20 69 73 20 61 se table.** is a
7e90: 20 73 70 65 63 69 61 6c 20 74 61 62 6c 65 20 74 special table t
7ea0: 68 61 74 20 68 6f 6c 64 73 20 74 68 65 20 6e 61 hat holds the na
7eb0: 6d 65 73 20 61 6e 64 20 61 74 74 72 69 62 75 74 mes and attribut
7ec0: 65 73 20 6f 66 20 61 6c 6c 0a 2a 2a 20 75 73 65 es of all.** use
7ed0: 72 20 74 61 62 6c 65 73 20 61 6e 64 20 69 6e 64 r tables and ind
7ee0: 69 63 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ices..*/.#define
7ef0: 20 4d 41 53 54 45 52 5f 4e 41 4d 45 20 20 20 20 MASTER_NAME
7f00: 20 20 20 22 73 71 6c 69 74 65 5f 6d 61 73 74 65 "sqlite_maste
7f10: 72 22 0a 23 64 65 66 69 6e 65 20 54 45 4d 50 5f r".#define TEMP_
7f20: 4d 41 53 54 45 52 5f 4e 41 4d 45 20 20 22 73 71 MASTER_NAME "sq
7f30: 6c 69 74 65 5f 74 65 6d 70 5f 6d 61 73 74 65 72 lite_temp_master
7f40: 22 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 72 6f 6f "../*.** The roo
7f50: 74 2d 70 61 67 65 20 6f 66 20 74 68 65 20 6d 61 t-page of the ma
7f60: 73 74 65 72 20 64 61 74 61 62 61 73 65 20 74 61 ster database ta
7f70: 62 6c 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ble..*/.#define
7f80: 4d 41 53 54 45 52 5f 52 4f 4f 54 20 20 20 20 20 MASTER_ROOT
7f90: 20 20 31 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 1../*.** The n
7fa0: 61 6d 65 20 6f 66 20 74 68 65 20 73 63 68 65 6d ame of the schem
7fb0: 61 20 74 61 62 6c 65 2e 0a 2a 2f 0a 23 64 65 66 a table..*/.#def
7fc0: 69 6e 65 20 53 43 48 45 4d 41 5f 54 41 42 4c 45 ine SCHEMA_TABLE
7fd0: 28 78 29 20 20 28 28 21 4f 4d 49 54 5f 54 45 4d (x) ((!OMIT_TEM
7fe0: 50 44 42 29 26 26 28 78 3d 3d 31 29 3f 54 45 4d PDB)&&(x==1)?TEM
7ff0: 50 5f 4d 41 53 54 45 52 5f 4e 41 4d 45 3a 4d 41 P_MASTER_NAME:MA
8000: 53 54 45 52 5f 4e 41 4d 45 29 0a 0a 2f 2a 0a 2a STER_NAME)../*.*
8010: 2a 20 41 20 63 6f 6e 76 65 6e 69 65 6e 63 65 20 * A convenience
8020: 6d 61 63 72 6f 20 74 68 61 74 20 72 65 74 75 72 macro that retur
8030: 6e 73 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ns the number of
8040: 20 65 6c 65 6d 65 6e 74 73 20 69 6e 0a 2a 2a 20 elements in.**
8050: 61 6e 20 61 72 72 61 79 2e 0a 2a 2f 0a 23 64 65 an array..*/.#de
8060: 66 69 6e 65 20 41 72 72 61 79 53 69 7a 65 28 58 fine ArraySize(X
8070: 29 20 20 20 20 28 28 69 6e 74 29 28 73 69 7a 65 ) ((int)(size
8080: 6f 66 28 58 29 2f 73 69 7a 65 6f 66 28 58 5b 30 of(X)/sizeof(X[0
8090: 5d 29 29 29 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 65 ])))../*.** Dete
80a0: 72 6d 69 6e 65 20 69 66 20 74 68 65 20 61 72 67 rmine if the arg
80b0: 75 6d 65 6e 74 20 69 73 20 61 20 70 6f 77 65 72 ument is a power
80c0: 20 6f 66 20 74 77 6f 0a 2a 2f 0a 23 64 65 66 69 of two.*/.#defi
80d0: 6e 65 20 49 73 50 6f 77 65 72 4f 66 54 77 6f 28 ne IsPowerOfTwo(
80e0: 58 29 20 28 28 28 58 29 26 28 28 58 29 2d 31 29 X) (((X)&((X)-1)
80f0: 29 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 )==0)../*.** The
8100: 20 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 6c 75 65 following value
8110: 20 61 73 20 61 20 64 65 73 74 72 75 63 74 6f 72 as a destructor
8120: 20 6d 65 61 6e 73 20 74 6f 20 75 73 65 20 73 71 means to use sq
8130: 6c 69 74 65 33 44 62 46 72 65 65 28 29 2e 0a 2a lite3DbFree()..*
8140: 2a 20 54 68 65 20 73 71 6c 69 74 65 33 44 62 46 * The sqlite3DbF
8150: 72 65 65 28 29 20 72 6f 75 74 69 6e 65 20 72 65 ree() routine re
8160: 71 75 69 72 65 73 20 74 77 6f 20 70 61 72 61 6d quires two param
8170: 65 74 65 72 73 20 69 6e 73 74 65 61 64 20 6f 66 eters instead of
8180: 20 74 68 65 0a 2a 2a 20 6f 6e 65 20 70 61 72 61 the.** one para
8190: 6d 65 74 65 72 20 74 68 61 74 20 64 65 73 74 72 meter that destr
81a0: 75 63 74 6f 72 73 20 6e 6f 72 6d 61 6c 6c 79 20 uctors normally
81b0: 77 61 6e 74 2e 20 20 53 6f 20 77 65 20 68 61 76 want. So we hav
81c0: 65 20 74 6f 20 69 6e 74 72 6f 64 75 63 65 0a 2a e to introduce.*
81d0: 2a 20 74 68 69 73 20 6d 61 67 69 63 20 76 61 6c * this magic val
81e0: 75 65 20 74 68 61 74 20 74 68 65 20 63 6f 64 65 ue that the code
81f0: 20 6b 6e 6f 77 73 20 74 6f 20 68 61 6e 64 6c 65 knows to handle
8200: 20 64 69 66 66 65 72 65 6e 74 6c 79 2e 20 20 41 differently. A
8210: 6e 79 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 77 69 ny.** pointer wi
8220: 6c 6c 20 77 6f 72 6b 20 68 65 72 65 20 61 73 20 ll work here as
8230: 6c 6f 6e 67 20 61 73 20 69 74 20 69 73 20 64 69 long as it is di
8240: 73 74 69 6e 63 74 20 66 72 6f 6d 20 53 51 4c 49 stinct from SQLI
8250: 54 45 5f 53 54 41 54 49 43 0a 2a 2a 20 61 6e 64 TE_STATIC.** and
8260: 20 53 51 4c 49 54 45 5f 54 52 41 4e 53 49 45 4e SQLITE_TRANSIEN
8270: 54 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 T..*/.#define SQ
8280: 4c 49 54 45 5f 44 59 4e 41 4d 49 43 20 20 20 28 LITE_DYNAMIC (
8290: 28 73 71 6c 69 74 65 33 5f 64 65 73 74 72 75 63 (sqlite3_destruc
82a0: 74 6f 72 5f 74 79 70 65 29 73 71 6c 69 74 65 33 tor_type)sqlite3
82b0: 4d 61 6c 6c 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a MallocSize)../*.
82c0: 2a 2a 20 57 68 65 6e 20 53 51 4c 49 54 45 5f 4f ** When SQLITE_O
82d0: 4d 49 54 5f 57 53 44 20 69 73 20 64 65 66 69 6e MIT_WSD is defin
82e0: 65 64 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 61 ed, it means tha
82f0: 74 20 74 68 65 20 74 61 72 67 65 74 20 70 6c 61 t the target pla
8300: 74 66 6f 72 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f tform does.** no
8310: 74 20 73 75 70 70 6f 72 74 20 57 72 69 74 61 62 t support Writab
8320: 6c 65 20 53 74 61 74 69 63 20 44 61 74 61 20 28 le Static Data (
8330: 57 53 44 29 20 73 75 63 68 20 61 73 20 67 6c 6f WSD) such as glo
8340: 62 61 6c 20 61 6e 64 20 73 74 61 74 69 63 20 76 bal and static v
8350: 61 72 69 61 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c ariables..** All
8360: 20 76 61 72 69 61 62 6c 65 73 20 6d 75 73 74 20 variables must
8370: 65 69 74 68 65 72 20 62 65 20 6f 6e 20 74 68 65 either be on the
8380: 20 73 74 61 63 6b 20 6f 72 20 64 79 6e 61 6d 69 stack or dynami
8390: 63 61 6c 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 cally allocated
83a0: 66 72 6f 6d 0a 2a 2a 20 74 68 65 20 68 65 61 70 from.** the heap
83b0: 2e 20 20 57 68 65 6e 20 57 53 44 20 69 73 20 75 . When WSD is u
83c0: 6e 73 75 70 70 6f 72 74 65 64 2c 20 74 68 65 20 nsupported, the
83d0: 76 61 72 69 61 62 6c 65 20 64 65 63 6c 61 72 61 variable declara
83e0: 74 69 6f 6e 73 20 73 63 61 74 74 65 72 65 64 0a tions scattered.
83f0: 2a 2a 20 74 68 72 6f 75 67 68 6f 75 74 20 74 68 ** throughout th
8400: 65 20 53 51 4c 69 74 65 20 63 6f 64 65 20 6d 75 e SQLite code mu
8410: 73 74 20 62 65 63 6f 6d 65 20 63 6f 6e 73 74 61 st become consta
8420: 6e 74 73 20 69 6e 73 74 65 61 64 2e 20 20 54 68 nts instead. Th
8430: 65 20 53 51 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 e SQLITE_WSD.**
8440: 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 6f macro is used fo
8450: 72 20 74 68 69 73 20 70 75 72 70 6f 73 65 2e 20 r this purpose.
8460: 20 41 6e 64 20 69 6e 73 74 65 61 64 20 6f 66 20 And instead of
8470: 72 65 66 65 72 65 6e 63 69 6e 67 20 74 68 65 20 referencing the
8480: 76 61 72 69 61 62 6c 65 0a 2a 2a 20 64 69 72 65 variable.** dire
8490: 63 74 6c 79 2c 20 77 65 20 75 73 65 20 69 74 73 ctly, we use its
84a0: 20 63 6f 6e 73 74 61 6e 74 20 61 73 20 61 20 6b constant as a k
84b0: 65 79 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 ey to lookup the
84c0: 20 72 75 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 run-time alloca
84d0: 74 65 64 0a 2a 2a 20 62 75 66 66 65 72 20 74 68 ted.** buffer th
84e0: 61 74 20 68 6f 6c 64 73 20 72 65 61 6c 20 76 61 at holds real va
84f0: 72 69 61 62 6c 65 2e 20 20 54 68 65 20 63 6f 6e riable. The con
8500: 73 74 61 6e 74 20 69 73 20 61 6c 73 6f 20 74 68 stant is also th
8510: 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 0a 2a 2a e initializer.**
8520: 20 66 6f 72 20 74 68 65 20 72 75 6e 2d 74 69 6d for the run-tim
8530: 65 20 61 6c 6c 6f 63 61 74 65 64 20 62 75 66 66 e allocated buff
8540: 65 72 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 er..**.** In the
8550: 20 75 73 75 61 6c 20 63 61 73 65 20 77 68 65 72 usual case wher
8560: 65 20 57 53 44 20 69 73 20 73 75 70 70 6f 72 74 e WSD is support
8570: 65 64 2c 20 74 68 65 20 53 51 4c 49 54 45 5f 57 ed, the SQLITE_W
8580: 53 44 20 61 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a SD and GLOBAL.**
8590: 20 6d 61 63 72 6f 73 20 62 65 63 6f 6d 65 20 6e macros become n
85a0: 6f 2d 6f 70 73 20 61 6e 64 20 68 61 76 65 20 7a o-ops and have z
85b0: 65 72 6f 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 ero performance
85c0: 69 6d 70 61 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 impact..*/.#ifde
85d0: 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 f SQLITE_OMIT_WS
85e0: 44 0a 20 20 23 64 65 66 69 6e 65 20 53 51 4c 49 D. #define SQLI
85f0: 54 45 5f 57 53 44 20 63 6f 6e 73 74 0a 20 20 23 TE_WSD const. #
8600: 64 65 66 69 6e 65 20 47 4c 4f 42 41 4c 28 74 2c define GLOBAL(t,
8610: 76 29 20 28 2a 28 74 2a 29 73 71 6c 69 74 65 33 v) (*(t*)sqlite3
8620: 5f 77 73 64 5f 66 69 6e 64 28 28 76 6f 69 64 2a _wsd_find((void*
8630: 29 26 28 76 29 2c 20 73 69 7a 65 6f 66 28 76 29 )&(v), sizeof(v)
8640: 29 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c )). #define sql
8650: 69 74 65 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 ite3GlobalConfig
8660: 20 47 4c 4f 42 41 4c 28 73 74 72 75 63 74 20 53 GLOBAL(struct S
8670: 71 6c 69 74 65 33 43 6f 6e 66 69 67 2c 20 73 71 qlite3Config, sq
8680: 6c 69 74 65 33 43 6f 6e 66 69 67 29 0a 20 20 69 lite3Config). i
8690: 6e 74 20 73 71 6c 69 74 65 33 5f 77 73 64 5f 69 nt sqlite3_wsd_i
86a0: 6e 69 74 28 69 6e 74 20 4e 2c 20 69 6e 74 20 4a nit(int N, int J
86b0: 29 3b 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 );. void *sqlit
86c0: 65 33 5f 77 73 64 5f 66 69 6e 64 28 76 6f 69 64 e3_wsd_find(void
86d0: 20 2a 4b 2c 20 69 6e 74 20 4c 29 3b 0a 23 65 6c *K, int L);.#el
86e0: 73 65 0a 20 20 23 64 65 66 69 6e 65 20 53 51 4c se. #define SQL
86f0: 49 54 45 5f 57 53 44 0a 20 20 23 64 65 66 69 6e ITE_WSD. #defin
8700: 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 76 0a e GLOBAL(t,v) v.
8710: 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
8720: 33 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 73 71 3GlobalConfig sq
8730: 6c 69 74 65 33 43 6f 6e 66 69 67 0a 23 65 6e 64 lite3Config.#end
8740: 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f if../*.** The fo
8750: 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 llowing macros a
8760: 72 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 re used to suppr
8770: 65 73 73 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 ess compiler war
8780: 6e 69 6e 67 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 nings and to.**
8790: 6d 61 6b 65 20 69 74 20 63 6c 65 61 72 20 74 6f make it clear to
87a0: 20 68 75 6d 61 6e 20 72 65 61 64 65 72 73 20 77 human readers w
87b0: 68 65 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 hen a function p
87c0: 61 72 61 6d 65 74 65 72 20 69 73 20 64 65 6c 69 arameter is deli
87d0: 62 65 72 61 74 65 6c 79 0a 2a 2a 20 6c 65 66 74 berately.** left
87e0: 20 75 6e 75 73 65 64 20 77 69 74 68 69 6e 20 74 unused within t
87f0: 68 65 20 62 6f 64 79 20 6f 66 20 61 20 66 75 6e he body of a fun
8800: 63 74 69 6f 6e 2e 20 54 68 69 73 20 75 73 75 61 ction. This usua
8810: 6c 6c 79 20 68 61 70 70 65 6e 73 20 77 68 65 6e lly happens when
8820: 0a 2a 2a 20 61 20 66 75 6e 63 74 69 6f 6e 20 69 .** a function i
8830: 73 20 63 61 6c 6c 65 64 20 76 69 61 20 61 20 66 s called via a f
8840: 75 6e 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 2e unction pointer.
8850: 20 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 65 For example the
8860: 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 .** implementati
8870: 6f 6e 20 6f 66 20 61 6e 20 53 51 4c 20 61 67 67 on of an SQL agg
8880: 72 65 67 61 74 65 20 73 74 65 70 20 63 61 6c 6c regate step call
8890: 62 61 63 6b 20 6d 61 79 20 6e 6f 74 20 75 73 65 back may not use
88a0: 20 74 68 65 0a 2a 2a 20 70 61 72 61 6d 65 74 65 the.** paramete
88b0: 72 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 65 r indicating the
88c0: 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d number of argum
88d0: 65 6e 74 73 20 70 61 73 73 65 64 20 74 6f 20 74 ents passed to t
88e0: 68 65 20 61 67 67 72 65 67 61 74 65 2c 0a 2a 2a he aggregate,.**
88f0: 20 69 66 20 69 74 20 6b 6e 6f 77 73 20 74 68 61 if it knows tha
8900: 74 20 74 68 69 73 20 69 73 20 65 6e 66 6f 72 63 t this is enforc
8910: 65 64 20 65 6c 73 65 77 68 65 72 65 2e 0a 2a 2a ed elsewhere..**
8920: 0a 2a 2a 20 57 68 65 6e 20 61 20 66 75 6e 63 74 .** When a funct
8930: 69 6f 6e 20 70 61 72 61 6d 65 74 65 72 20 69 73 ion parameter is
8940: 20 6e 6f 74 20 75 73 65 64 20 61 74 20 61 6c 6c not used at all
8950: 20 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 within the body
8960: 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2c 0a of a function,.
8970: 2a 2a 20 69 74 20 69 73 20 67 65 6e 65 72 61 6c ** it is general
8980: 6c 79 20 6e 61 6d 65 64 20 22 4e 6f 74 55 73 65 ly named "NotUse
8990: 64 22 20 6f 72 20 22 4e 6f 74 55 73 65 64 32 22 d" or "NotUsed2"
89a0: 20 74 6f 20 6d 61 6b 65 20 74 68 69 6e 67 73 20 to make things
89b0: 65 76 65 6e 20 63 6c 65 61 72 65 72 2e 0a 2a 2a even clearer..**
89c0: 20 48 6f 77 65 76 65 72 2c 20 74 68 65 73 65 20 However, these
89d0: 6d 61 63 72 6f 73 20 6d 61 79 20 61 6c 73 6f 20 macros may also
89e0: 62 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 be used to suppr
89f0: 65 73 73 20 77 61 72 6e 69 6e 67 73 20 72 65 6c ess warnings rel
8a00: 61 74 65 64 20 74 6f 0a 2a 2a 20 70 61 72 61 6d ated to.** param
8a10: 65 74 65 72 73 20 74 68 61 74 20 6d 61 79 20 6f eters that may o
8a20: 72 20 6d 61 79 20 6e 6f 74 20 62 65 20 75 73 65 r may not be use
8a30: 64 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 63 d depending on c
8a40: 6f 6d 70 69 6c 61 74 69 6f 6e 20 6f 70 74 69 6f ompilation optio
8a50: 6e 73 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 ns..** For examp
8a60: 6c 65 20 74 68 6f 73 65 20 70 61 72 61 6d 65 74 le those paramet
8a70: 65 72 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e ers only used in
8a80: 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d assert() statem
8a90: 65 6e 74 73 2e 20 49 6e 20 74 68 65 73 65 0a 2a ents. In these.*
8aa0: 2a 20 63 61 73 65 73 20 74 68 65 20 70 61 72 61 * cases the para
8ab0: 6d 65 74 65 72 73 20 61 72 65 20 6e 61 6d 65 64 meters are named
8ac0: 20 61 73 20 70 65 72 20 74 68 65 20 75 73 75 61 as per the usua
8ad0: 6c 20 63 6f 6e 76 65 6e 74 69 6f 6e 73 2e 0a 2a l conventions..*
8ae0: 2f 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 /.#define UNUSED
8af0: 5f 50 41 52 41 4d 45 54 45 52 28 78 29 20 28 76 _PARAMETER(x) (v
8b00: 6f 69 64 29 28 78 29 0a 23 64 65 66 69 6e 65 20 oid)(x).#define
8b10: 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 UNUSED_PARAMETER
8b20: 32 28 78 2c 79 29 20 55 4e 55 53 45 44 5f 50 41 2(x,y) UNUSED_PA
8b30: 52 41 4d 45 54 45 52 28 78 29 2c 55 4e 55 53 45 RAMETER(x),UNUSE
8b40: 44 5f 50 41 52 41 4d 45 54 45 52 28 79 29 0a 0a D_PARAMETER(y)..
8b50: 2f 2a 0a 2a 2a 20 46 6f 72 77 61 72 64 20 72 65 /*.** Forward re
8b60: 66 65 72 65 6e 63 65 73 20 74 6f 20 73 74 72 75 ferences to stru
8b70: 63 74 75 72 65 73 0a 2a 2f 0a 74 79 70 65 64 65 ctures.*/.typede
8b80: 66 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f f struct AggInfo
8b90: 20 41 67 67 49 6e 66 6f 3b 0a 74 79 70 65 64 65 AggInfo;.typede
8ba0: 66 20 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e f struct AuthCon
8bb0: 74 65 78 74 20 41 75 74 68 43 6f 6e 74 65 78 74 text AuthContext
8bc0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
8bd0: 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 41 75 74 AutoincInfo Aut
8be0: 6f 69 6e 63 49 6e 66 6f 3b 0a 74 79 70 65 64 65 oincInfo;.typede
8bf0: 66 20 73 74 72 75 63 74 20 42 69 74 76 65 63 20 f struct Bitvec
8c00: 42 69 74 76 65 63 3b 0a 74 79 70 65 64 65 66 20 Bitvec;.typedef
8c10: 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 43 struct CollSeq C
8c20: 6f 6c 6c 53 65 71 3b 0a 74 79 70 65 64 65 66 20 ollSeq;.typedef
8c30: 73 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 43 6f struct Column Co
8c40: 6c 75 6d 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 lumn;.typedef st
8c50: 72 75 63 74 20 44 62 20 44 62 3b 0a 74 79 70 65 ruct Db Db;.type
8c60: 64 65 66 20 73 74 72 75 63 74 20 53 63 68 65 6d def struct Schem
8c70: 61 20 53 63 68 65 6d 61 3b 0a 74 79 70 65 64 65 a Schema;.typede
8c80: 66 20 73 74 72 75 63 74 20 45 78 70 72 20 45 78 f struct Expr Ex
8c90: 70 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 pr;.typedef stru
8ca0: 63 74 20 45 78 70 72 4c 69 73 74 20 45 78 70 72 ct ExprList Expr
8cb0: 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 List;.typedef st
8cc0: 72 75 63 74 20 46 4b 65 79 20 46 4b 65 79 3b 0a ruct FKey FKey;.
8cd0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 typedef struct F
8ce0: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 46 75 uncDestructor Fu
8cf0: 6e 63 44 65 73 74 72 75 63 74 6f 72 3b 0a 74 79 ncDestructor;.ty
8d00: 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 6e pedef struct Fun
8d10: 63 44 65 66 20 46 75 6e 63 44 65 66 3b 0a 74 79 cDef FuncDef;.ty
8d20: 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 6e pedef struct Fun
8d30: 63 44 65 66 48 61 73 68 20 46 75 6e 63 44 65 66 cDefHash FuncDef
8d40: 48 61 73 68 3b 0a 74 79 70 65 64 65 66 20 73 74 Hash;.typedef st
8d50: 72 75 63 74 20 49 64 4c 69 73 74 20 49 64 4c 69 ruct IdList IdLi
8d60: 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 st;.typedef stru
8d70: 63 74 20 49 6e 64 65 78 20 49 6e 64 65 78 3b 0a ct Index Index;.
8d80: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 49 typedef struct I
8d90: 6e 64 65 78 53 61 6d 70 6c 65 20 49 6e 64 65 78 ndexSample Index
8da0: 53 61 6d 70 6c 65 3b 0a 74 79 70 65 64 65 66 20 Sample;.typedef
8db0: 73 74 72 75 63 74 20 4b 65 79 43 6c 61 73 73 20 struct KeyClass
8dc0: 4b 65 79 43 6c 61 73 73 3b 0a 74 79 70 65 64 65 KeyClass;.typede
8dd0: 66 20 73 74 72 75 63 74 20 4b 65 79 49 6e 66 6f f struct KeyInfo
8de0: 20 4b 65 79 49 6e 66 6f 3b 0a 74 79 70 65 64 65 KeyInfo;.typede
8df0: 66 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 f struct Lookasi
8e00: 64 65 20 4c 6f 6f 6b 61 73 69 64 65 3b 0a 74 79 de Lookaside;.ty
8e10: 70 65 64 65 66 20 73 74 72 75 63 74 20 4c 6f 6f pedef struct Loo
8e20: 6b 61 73 69 64 65 53 6c 6f 74 20 4c 6f 6f 6b 61 kasideSlot Looka
8e30: 73 69 64 65 53 6c 6f 74 3b 0a 74 79 70 65 64 65 sideSlot;.typede
8e40: 66 20 73 74 72 75 63 74 20 4d 6f 64 75 6c 65 20 f struct Module
8e50: 4d 6f 64 75 6c 65 3b 0a 74 79 70 65 64 65 66 20 Module;.typedef
8e60: 73 74 72 75 63 74 20 4e 61 6d 65 43 6f 6e 74 65 struct NameConte
8e70: 78 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 3b 0a xt NameContext;.
8e80: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 50 typedef struct P
8e90: 61 72 73 65 20 50 61 72 73 65 3b 0a 74 79 70 65 arse Parse;.type
8ea0: 64 65 66 20 73 74 72 75 63 74 20 50 72 65 55 70 def struct PreUp
8eb0: 64 61 74 65 20 50 72 65 55 70 64 61 74 65 3b 0a date PreUpdate;.
8ec0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 50 typedef struct P
8ed0: 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 20 50 rintfArguments P
8ee0: 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 73 3b 0a rintfArguments;.
8ef0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 52 typedef struct R
8f00: 65 6e 61 6d 65 54 6f 6b 65 6e 20 52 65 6e 61 6d enameToken Renam
8f10: 65 54 6f 6b 65 6e 3b 0a 74 79 70 65 64 65 66 20 eToken;.typedef
8f20: 73 74 72 75 63 74 20 52 6f 77 53 65 74 20 52 6f struct RowSet Ro
8f30: 77 53 65 74 3b 0a 74 79 70 65 64 65 66 20 73 74 wSet;.typedef st
8f40: 72 75 63 74 20 53 61 76 65 70 6f 69 6e 74 20 53 ruct Savepoint S
8f50: 61 76 65 70 6f 69 6e 74 3b 0a 74 79 70 65 64 65 avepoint;.typede
8f60: 66 20 73 74 72 75 63 74 20 53 65 6c 65 63 74 20 f struct Select
8f70: 53 65 6c 65 63 74 3b 0a 74 79 70 65 64 65 66 20 Select;.typedef
8f80: 73 74 72 75 63 74 20 53 51 4c 69 74 65 54 68 72 struct SQLiteThr
8f90: 65 61 64 20 53 51 4c 69 74 65 54 68 72 65 61 64 ead SQLiteThread
8fa0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
8fb0: 20 53 65 6c 65 63 74 44 65 73 74 20 53 65 6c 65 SelectDest Sele
8fc0: 63 74 44 65 73 74 3b 0a 74 79 70 65 64 65 66 20 ctDest;.typedef
8fd0: 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 20 53 struct SrcList S
8fe0: 72 63 4c 69 73 74 3b 0a 74 79 70 65 64 65 66 20 rcList;.typedef
8ff0: 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 5f 73 struct sqlite3_s
9000: 74 72 20 53 74 72 41 63 63 75 6d 3b 20 2f 2a 20 tr StrAccum; /*
9010: 49 6e 74 65 72 6e 61 6c 20 61 6c 69 61 73 20 66 Internal alias f
9020: 6f 72 20 73 71 6c 69 74 65 33 5f 73 74 72 20 2a or sqlite3_str *
9030: 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
9040: 20 54 61 62 6c 65 20 54 61 62 6c 65 3b 0a 74 79 Table Table;.ty
9050: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 61 62 pedef struct Tab
9060: 6c 65 4c 6f 63 6b 20 54 61 62 6c 65 4c 6f 63 6b leLock TableLock
9070: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
9080: 20 54 6f 6b 65 6e 20 54 6f 6b 65 6e 3b 0a 74 79 Token Token;.ty
9090: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 72 65 pedef struct Tre
90a0: 65 56 69 65 77 20 54 72 65 65 56 69 65 77 3b 0a eView TreeView;.
90b0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
90c0: 72 69 67 67 65 72 20 54 72 69 67 67 65 72 3b 0a rigger Trigger;.
90d0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
90e0: 72 69 67 67 65 72 50 72 67 20 54 72 69 67 67 65 riggerPrg Trigge
90f0: 72 50 72 67 3b 0a 74 79 70 65 64 65 66 20 73 74 rPrg;.typedef st
9100: 72 75 63 74 20 54 72 69 67 67 65 72 53 74 65 70 ruct TriggerStep
9110: 20 54 72 69 67 67 65 72 53 74 65 70 3b 0a 74 79 TriggerStep;.ty
9120: 70 65 64 65 66 20 73 74 72 75 63 74 20 55 6e 70 pedef struct Unp
9130: 61 63 6b 65 64 52 65 63 6f 72 64 20 55 6e 70 61 ackedRecord Unpa
9140: 63 6b 65 64 52 65 63 6f 72 64 3b 0a 74 79 70 65 ckedRecord;.type
9150: 64 65 66 20 73 74 72 75 63 74 20 55 70 73 65 72 def struct Upser
9160: 74 20 55 70 73 65 72 74 3b 0a 74 79 70 65 64 65 t Upsert;.typede
9170: 66 20 73 74 72 75 63 74 20 56 54 61 62 6c 65 20 f struct VTable
9180: 56 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 66 20 VTable;.typedef
9190: 73 74 72 75 63 74 20 56 74 61 62 43 74 78 20 56 struct VtabCtx V
91a0: 74 61 62 43 74 78 3b 0a 74 79 70 65 64 65 66 20 tabCtx;.typedef
91b0: 73 74 72 75 63 74 20 57 61 6c 6b 65 72 20 57 61 struct Walker Wa
91c0: 6c 6b 65 72 3b 0a 74 79 70 65 64 65 66 20 73 74 lker;.typedef st
91d0: 72 75 63 74 20 57 68 65 72 65 49 6e 66 6f 20 57 ruct WhereInfo W
91e0: 68 65 72 65 49 6e 66 6f 3b 0a 74 79 70 65 64 65 hereInfo;.typede
91f0: 66 20 73 74 72 75 63 74 20 57 69 6e 64 6f 77 20 f struct Window
9200: 57 69 6e 64 6f 77 3b 0a 74 79 70 65 64 65 66 20 Window;.typedef
9210: 73 74 72 75 63 74 20 57 69 74 68 20 57 69 74 68 struct With With
9220: 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 62 69 ;.../*.** The bi
9230: 74 6d 61 73 6b 20 64 61 74 61 74 79 70 65 20 64 tmask datatype d
9240: 65 66 69 6e 65 64 20 62 65 6c 6f 77 20 69 73 20 efined below is
9250: 75 73 65 64 20 66 6f 72 20 76 61 72 69 6f 75 73 used for various
9260: 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a optimizations..
9270: 2a 2a 0a 2a 2a 20 43 68 61 6e 67 69 6e 67 20 74 **.** Changing t
9280: 68 69 73 20 66 72 6f 6d 20 61 20 36 34 2d 62 69 his from a 64-bi
9290: 74 20 74 6f 20 61 20 33 32 2d 62 69 74 20 74 79 t to a 32-bit ty
92a0: 70 65 20 6c 69 6d 69 74 73 20 74 68 65 20 6e 75 pe limits the nu
92b0: 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 61 62 6c 65 mber of.** table
92c0: 73 20 69 6e 20 61 20 6a 6f 69 6e 20 74 6f 20 33 s in a join to 3
92d0: 32 20 69 6e 73 74 65 61 64 20 6f 66 20 36 34 2e 2 instead of 64.
92e0: 20 20 42 75 74 20 69 74 20 61 6c 73 6f 20 72 65 But it also re
92f0: 64 75 63 65 73 20 74 68 65 20 73 69 7a 65 0a 2a duces the size.*
9300: 2a 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72 79 * of the library
9310: 20 62 79 20 37 33 38 20 62 79 74 65 73 20 6f 6e by 738 bytes on
9320: 20 69 78 38 36 2e 0a 2a 2f 0a 23 69 66 64 65 66 ix86..*/.#ifdef
9330: 20 53 51 4c 49 54 45 5f 42 49 54 4d 41 53 4b 5f SQLITE_BITMASK_
9340: 54 59 50 45 0a 20 20 74 79 70 65 64 65 66 20 53 TYPE. typedef S
9350: 51 4c 49 54 45 5f 42 49 54 4d 41 53 4b 5f 54 59 QLITE_BITMASK_TY
9360: 50 45 20 42 69 74 6d 61 73 6b 3b 0a 23 65 6c 73 PE Bitmask;.#els
9370: 65 0a 20 20 74 79 70 65 64 65 66 20 75 36 34 20 e. typedef u64
9380: 42 69 74 6d 61 73 6b 3b 0a 23 65 6e 64 69 66 0a Bitmask;.#endif.
9390: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 ./*.** The numbe
93a0: 72 20 6f 66 20 62 69 74 73 20 69 6e 20 61 20 42 r of bits in a B
93b0: 69 74 6d 61 73 6b 2e 20 20 22 42 4d 53 22 20 6d itmask. "BMS" m
93c0: 65 61 6e 73 20 22 42 69 74 4d 61 73 6b 20 53 69 eans "BitMask Si
93d0: 7a 65 22 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ze"..*/.#define
93e0: 42 4d 53 20 20 28 28 69 6e 74 29 28 73 69 7a 65 BMS ((int)(size
93f0: 6f 66 28 42 69 74 6d 61 73 6b 29 2a 38 29 29 0a of(Bitmask)*8)).
9400: 0a 2f 2a 0a 2a 2a 20 41 20 62 69 74 20 69 6e 20 ./*.** A bit in
9410: 61 20 42 69 74 6d 61 73 6b 0a 2a 2f 0a 23 64 65 a Bitmask.*/.#de
9420: 66 69 6e 65 20 4d 41 53 4b 42 49 54 28 6e 29 20 fine MASKBIT(n)
9430: 20 20 28 28 28 42 69 74 6d 61 73 6b 29 31 29 3c (((Bitmask)1)<
9440: 3c 28 6e 29 29 0a 23 64 65 66 69 6e 65 20 4d 41 <(n)).#define MA
9450: 53 4b 42 49 54 33 32 28 6e 29 20 28 28 28 75 6e SKBIT32(n) (((un
9460: 73 69 67 6e 65 64 20 69 6e 74 29 31 29 3c 3c 28 signed int)1)<<(
9470: 6e 29 29 0a 23 64 65 66 69 6e 65 20 41 4c 4c 42 n)).#define ALLB
9480: 49 54 53 20 20 20 20 20 20 28 28 42 69 74 6d 61 ITS ((Bitma
9490: 73 6b 29 2d 31 29 0a 0a 2f 2a 20 41 20 56 4c 69 sk)-1)../* A VLi
94a0: 73 74 20 6f 62 6a 65 63 74 20 72 65 63 6f 72 64 st object record
94b0: 73 20 61 20 6d 61 70 70 69 6e 67 20 62 65 74 77 s a mapping betw
94c0: 65 65 6e 20 70 61 72 61 6d 65 74 65 72 73 2f 76 een parameters/v
94d0: 61 72 69 61 62 6c 65 73 2f 77 69 6c 64 63 61 72 ariables/wildcar
94e0: 64 73 0a 2a 2a 20 69 6e 20 74 68 65 20 53 51 4c ds.** in the SQL
94f0: 20 73 74 61 74 65 6d 65 6e 74 20 28 73 75 63 68 statement (such
9500: 20 61 73 20 24 61 62 63 2c 20 40 70 71 72 2c 20 as $abc, @pqr,
9510: 6f 72 20 3a 78 79 7a 29 20 61 6e 64 20 74 68 65 or :xyz) and the
9520: 20 69 6e 74 65 67 65 72 0a 2a 2a 20 76 61 72 69 integer.** vari
9530: 61 62 6c 65 20 6e 75 6d 62 65 72 20 61 73 73 6f able number asso
9540: 63 69 61 74 65 64 20 77 69 74 68 20 74 68 61 74 ciated with that
9550: 20 70 61 72 61 6d 65 74 65 72 2e 20 20 53 65 65 parameter. See
9560: 20 74 68 65 20 66 6f 72 6d 61 74 20 64 65 73 63 the format desc
9570: 72 69 70 74 69 6f 6e 0a 2a 2a 20 6f 6e 20 74 68 ription.** on th
9580: 65 20 73 71 6c 69 74 65 33 56 4c 69 73 74 41 64 e sqlite3VListAd
9590: 64 28 29 20 72 6f 75 74 69 6e 65 20 66 6f 72 20 d() routine for
95a0: 6d 6f 72 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e more information
95b0: 2e 20 20 41 20 56 4c 69 73 74 20 69 73 20 72 65 . A VList is re
95c0: 61 6c 6c 79 0a 2a 2a 20 6a 75 73 74 20 61 6e 20 ally.** just an
95d0: 61 72 72 61 79 20 6f 66 20 69 6e 74 65 67 65 72 array of integer
95e0: 73 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 69 6e s..*/.typedef in
95f0: 74 20 56 4c 69 73 74 3b 0a 0a 2f 2a 0a 2a 2a 20 t VList;../*.**
9600: 44 65 66 65 72 20 73 6f 75 72 63 69 6e 67 20 76 Defer sourcing v
9610: 64 62 65 2e 68 20 61 6e 64 20 62 74 72 65 65 2e dbe.h and btree.
9620: 68 20 75 6e 74 69 6c 20 61 66 74 65 72 20 74 68 h until after th
9630: 65 20 22 75 38 22 20 61 6e 64 0a 2a 2a 20 22 42 e "u8" and.** "B
9640: 75 73 79 48 61 6e 64 6c 65 72 22 20 74 79 70 65 usyHandler" type
9650: 64 65 66 73 2e 20 76 64 62 65 2e 68 20 61 6c 73 defs. vdbe.h als
9660: 6f 20 72 65 71 75 69 72 65 73 20 61 20 66 65 77 o requires a few
9670: 20 6f 66 20 74 68 65 20 6f 70 61 71 75 65 0a 2a of the opaque.*
9680: 2a 20 70 6f 69 6e 74 65 72 20 74 79 70 65 73 20 * pointer types
9690: 28 69 2e 65 2e 20 46 75 6e 63 44 65 66 29 20 64 (i.e. FuncDef) d
96a0: 65 66 69 6e 65 64 20 61 62 6f 76 65 2e 0a 2a 2f efined above..*/
96b0: 0a 23 69 6e 63 6c 75 64 65 20 22 62 74 72 65 65 .#include "btree
96c0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 76 64 .h".#include "vd
96d0: 62 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 be.h".#include "
96e0: 70 61 67 65 72 2e 68 22 0a 23 69 6e 63 6c 75 64 pager.h".#includ
96f0: 65 20 22 70 63 61 63 68 65 2e 68 22 0a 23 69 6e e "pcache.h".#in
9700: 63 6c 75 64 65 20 22 6f 73 2e 68 22 0a 23 69 6e clude "os.h".#in
9710: 63 6c 75 64 65 20 22 6d 75 74 65 78 2e 68 22 0a clude "mutex.h".
9720: 0a 2f 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 45 ./* The SQLITE_E
9730: 58 54 52 41 5f 44 55 52 41 42 4c 45 20 63 6f 6d XTRA_DURABLE com
9740: 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e pile-time option
9750: 20 75 73 65 64 20 74 6f 20 73 65 74 20 74 68 65 used to set the
9760: 20 64 65 66 61 75 6c 74 0a 2a 2a 20 73 79 6e 63 default.** sync
9770: 68 72 6f 6e 6f 75 73 20 73 65 74 74 69 6e 67 20 hronous setting
9780: 74 6f 20 45 58 54 52 41 2e 20 20 49 74 20 69 73 to EXTRA. It is
9790: 20 6e 6f 20 6c 6f 6e 67 65 72 20 73 75 70 70 6f no longer suppo
97a0: 72 74 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 rted..*/.#ifdef
97b0: 53 51 4c 49 54 45 5f 45 58 54 52 41 5f 44 55 52 SQLITE_EXTRA_DUR
97c0: 41 42 4c 45 0a 23 20 77 61 72 6e 69 6e 67 20 55 ABLE.# warning U
97d0: 73 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c se SQLITE_DEFAUL
97e0: 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 3d 33 20 T_SYNCHRONOUS=3
97f0: 69 6e 73 74 65 61 64 20 6f 66 20 53 51 4c 49 54 instead of SQLIT
9800: 45 5f 45 58 54 52 41 5f 44 55 52 41 42 4c 45 0a E_EXTRA_DURABLE.
9810: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
9820: 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e DEFAULT_SYNCHRON
9830: 4f 55 53 20 33 0a 23 65 6e 64 69 66 0a 0a 2f 2a OUS 3.#endif../*
9840: 0a 2a 2a 20 44 65 66 61 75 6c 74 20 73 79 6e 63 .** Default sync
9850: 68 72 6f 6e 6f 75 73 20 6c 65 76 65 6c 73 2e 0a hronous levels..
9860: 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 61 74 20 **.** Note that
9870: 28 66 6f 72 20 68 69 73 74 6f 72 63 61 6c 20 72 (for historcal r
9880: 65 61 73 6f 6e 73 29 20 74 68 65 20 50 41 47 45 easons) the PAGE
9890: 52 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 5f 2a 20 R_SYNCHRONOUS_*
98a0: 6d 61 63 72 6f 73 20 64 69 66 66 65 72 0a 2a 2a macros differ.**
98b0: 20 66 72 6f 6d 20 74 68 65 20 53 51 4c 49 54 45 from the SQLITE
98c0: 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f _DEFAULT_SYNCHRO
98d0: 4e 4f 55 53 20 76 61 6c 75 65 20 62 79 20 31 2e NOUS value by 1.
98e0: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 .**.**
98f0: 20 50 41 47 45 52 5f 53 59 4e 43 48 52 4f 4e 4f PAGER_SYNCHRONO
9900: 55 53 20 20 20 20 20 20 20 44 45 46 41 55 4c 54 US DEFAULT
9910: 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 0a 2a 2a 20 _SYNCHRONOUS.**
9920: 20 20 4f 46 46 20 20 20 20 20 20 20 20 20 20 20 OFF
9930: 31 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 1
9940: 20 20 20 20 20 20 20 20 20 20 30 0a 2a 2a 20 20 0.**
9950: 20 4e 4f 52 4d 41 4c 20 20 20 20 20 20 20 20 32 NORMAL 2
9960: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9970: 20 20 20 20 20 20 20 20 20 31 0a 2a 2a 20 20 20 1.**
9980: 46 55 4c 4c 20 20 20 20 20 20 20 20 20 20 33 20 FULL 3
9990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
99a0: 20 20 20 20 20 20 20 20 32 0a 2a 2a 20 20 20 45 2.** E
99b0: 58 54 52 41 20 20 20 20 20 20 20 20 20 34 20 20 XTRA 4
99c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
99d0: 20 20 20 20 20 20 20 33 0a 2a 2a 0a 2a 2a 20 54 3.**.** T
99e0: 68 65 20 22 50 52 41 47 4d 41 20 73 79 6e 63 68 he "PRAGMA synch
99f0: 72 6f 6e 6f 75 73 22 20 73 74 61 74 65 6d 65 6e ronous" statemen
9a00: 74 20 61 6c 73 6f 20 75 73 65 73 20 74 68 65 20 t also uses the
9a10: 7a 65 72 6f 2d 62 61 73 65 64 20 6e 75 6d 62 65 zero-based numbe
9a20: 72 73 2e 0a 2a 2a 20 49 6e 20 6f 74 68 65 72 20 rs..** In other
9a30: 77 6f 72 64 73 2c 20 74 68 65 20 7a 65 72 6f 2d words, the zero-
9a40: 62 61 73 65 64 20 6e 75 6d 62 65 72 73 20 61 72 based numbers ar
9a50: 65 20 75 73 65 64 20 66 6f 72 20 61 6c 6c 20 65 e used for all e
9a60: 78 74 65 72 6e 61 6c 20 69 6e 74 65 72 66 61 63 xternal interfac
9a70: 65 73 0a 2a 2a 20 61 6e 64 20 74 68 65 20 6f 6e es.** and the on
9a80: 65 2d 62 61 73 65 64 20 76 61 6c 75 65 73 20 61 e-based values a
9a90: 72 65 20 75 73 65 64 20 69 6e 74 65 72 6e 61 6c re used internal
9aa0: 6c 79 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ly..*/.#ifndef S
9ab0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 QLITE_DEFAULT_SY
9ac0: 4e 43 48 52 4f 4e 4f 55 53 0a 23 20 64 65 66 69 NCHRONOUS.# defi
9ad0: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
9ae0: 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 32 0a T_SYNCHRONOUS 2.
9af0: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
9b00: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 41 QLITE_DEFAULT_WA
9b10: 4c 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 0a 23 20 L_SYNCHRONOUS.#
9b20: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 define SQLITE_DE
9b30: 46 41 55 4c 54 5f 57 41 4c 5f 53 59 4e 43 48 52 FAULT_WAL_SYNCHR
9b40: 4f 4e 4f 55 53 20 53 51 4c 49 54 45 5f 44 45 46 ONOUS SQLITE_DEF
9b50: 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 AULT_SYNCHRONOUS
9b60: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 .#endif../*.** E
9b70: 61 63 68 20 64 61 74 61 62 61 73 65 20 66 69 6c ach database fil
9b80: 65 20 74 6f 20 62 65 20 61 63 63 65 73 73 65 64 e to be accessed
9b90: 20 62 79 20 74 68 65 20 73 79 73 74 65 6d 20 69 by the system i
9ba0: 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a 2a s an instance.**
9bb0: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
9bc0: 67 20 73 74 72 75 63 74 75 72 65 2e 20 20 54 68 g structure. Th
9bd0: 65 72 65 20 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 ere are normally
9be0: 20 74 77 6f 20 6f 66 20 74 68 65 73 65 20 73 74 two of these st
9bf0: 72 75 63 74 75 72 65 73 0a 2a 2a 20 69 6e 20 74 ructures.** in t
9c00: 68 65 20 73 71 6c 69 74 65 2e 61 44 62 5b 5d 20 he sqlite.aDb[]
9c10: 61 72 72 61 79 2e 20 20 61 44 62 5b 30 5d 20 69 array. aDb[0] i
9c20: 73 20 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 s the main datab
9c30: 61 73 65 20 66 69 6c 65 20 61 6e 64 0a 2a 2a 20 ase file and.**
9c40: 61 44 62 5b 31 5d 20 69 73 20 74 68 65 20 64 61 aDb[1] is the da
9c50: 74 61 62 61 73 65 20 66 69 6c 65 20 75 73 65 64 tabase file used
9c60: 20 74 6f 20 68 6f 6c 64 20 74 65 6d 70 6f 72 61 to hold tempora
9c70: 72 79 20 74 61 62 6c 65 73 2e 20 20 41 64 64 69 ry tables. Addi
9c80: 74 69 6f 6e 61 6c 0a 2a 2a 20 64 61 74 61 62 61 tional.** databa
9c90: 73 65 73 20 6d 61 79 20 62 65 20 61 74 74 61 63 ses may be attac
9ca0: 68 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 44 hed..*/.struct D
9cb0: 62 20 7b 0a 20 20 63 68 61 72 20 2a 7a 44 62 53 b {. char *zDbS
9cc0: 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a 20 4e 61 Name; /* Na
9cd0: 6d 65 20 6f 66 20 74 68 69 73 20 64 61 74 61 62 me of this datab
9ce0: 61 73 65 2e 20 28 73 63 68 65 6d 61 20 6e 61 6d ase. (schema nam
9cf0: 65 2c 20 6e 6f 74 20 66 69 6c 65 6e 61 6d 65 29 e, not filename)
9d00: 20 2a 2f 0a 20 20 42 74 72 65 65 20 2a 70 42 74 */. Btree *pBt
9d10: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ; /* Th
9d20: 65 20 42 2a 54 72 65 65 20 73 74 72 75 63 74 75 e B*Tree structu
9d30: 72 65 20 66 6f 72 20 74 68 69 73 20 64 61 74 61 re for this data
9d40: 62 61 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 75 base file */. u
9d50: 38 20 73 61 66 65 74 79 5f 6c 65 76 65 6c 3b 20 8 safety_level;
9d60: 20 20 20 20 2f 2a 20 48 6f 77 20 61 67 67 72 65 /* How aggre
9d70: 73 73 69 76 65 20 61 74 20 73 79 6e 63 69 6e 67 ssive at syncing
9d80: 20 64 61 74 61 20 74 6f 20 64 69 73 6b 20 2a 2f data to disk */
9d90: 0a 20 20 75 38 20 62 53 79 6e 63 53 65 74 3b 20 . u8 bSyncSet;
9da0: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
9db0: 69 66 20 22 50 52 41 47 4d 41 20 73 79 6e 63 68 if "PRAGMA synch
9dc0: 72 6f 6e 6f 75 73 3d 4e 22 20 68 61 73 20 62 65 ronous=N" has be
9dd0: 65 6e 20 72 75 6e 20 2a 2f 0a 20 20 53 63 68 65 en run */. Sche
9de0: 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
9df0: 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 64 /* Pointer to d
9e00: 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 28 atabase schema (
9e10: 70 6f 73 73 69 62 6c 79 20 73 68 61 72 65 64 29 possibly shared)
9e20: 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e */.};../*.** An
9e30: 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
9e40: 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
9e50: 74 75 72 65 20 73 74 6f 72 65 73 20 61 20 64 61 ture stores a da
9e60: 74 61 62 61 73 65 20 73 63 68 65 6d 61 2e 0a 2a tabase schema..*
9e70: 2a 0a 2a 2a 20 4d 6f 73 74 20 53 63 68 65 6d 61 *.** Most Schema
9e80: 20 6f 62 6a 65 63 74 73 20 61 72 65 20 61 73 73 objects are ass
9e90: 6f 63 69 61 74 65 64 20 77 69 74 68 20 61 20 42 ociated with a B
9ea0: 74 72 65 65 2e 20 20 54 68 65 20 65 78 63 65 70 tree. The excep
9eb0: 74 69 6f 6e 20 69 73 0a 2a 2a 20 74 68 65 20 53 tion is.** the S
9ec0: 63 68 65 6d 61 20 66 6f 72 20 74 68 65 20 54 45 chema for the TE
9ed0: 4d 50 20 64 61 74 61 62 61 65 73 20 28 73 71 6c MP databaes (sql
9ee0: 69 74 65 33 2e 61 44 62 5b 31 5d 29 20 77 68 69 ite3.aDb[1]) whi
9ef0: 63 68 20 69 73 20 66 72 65 65 2d 73 74 61 6e 64 ch is free-stand
9f00: 69 6e 67 2e 0a 2a 2a 20 49 6e 20 73 68 61 72 65 ing..** In share
9f10: 64 20 63 61 63 68 65 20 6d 6f 64 65 2c 20 61 20 d cache mode, a
9f20: 73 69 6e 67 6c 65 20 53 63 68 65 6d 61 20 6f 62 single Schema ob
9f30: 6a 65 63 74 20 63 61 6e 20 62 65 20 73 68 61 72 ject can be shar
9f40: 65 64 20 62 79 20 6d 75 6c 74 69 70 6c 65 0a 2a ed by multiple.*
9f50: 2a 20 42 74 72 65 65 73 20 74 68 61 74 20 72 65 * Btrees that re
9f60: 66 65 72 20 74 6f 20 74 68 65 20 73 61 6d 65 20 fer to the same
9f70: 75 6e 64 65 72 6c 79 69 6e 67 20 42 74 53 68 61 underlying BtSha
9f80: 72 65 64 20 6f 62 6a 65 63 74 2e 0a 2a 2a 0a 2a red object..**.*
9f90: 2a 20 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 * Schema objects
9fa0: 20 61 72 65 20 61 75 74 6f 6d 61 74 69 63 61 6c are automatical
9fb0: 6c 79 20 64 65 61 6c 6c 6f 63 61 74 65 64 20 77 ly deallocated w
9fc0: 68 65 6e 20 74 68 65 20 6c 61 73 74 20 42 74 72 hen the last Btr
9fd0: 65 65 20 74 68 61 74 0a 2a 2a 20 72 65 66 65 72 ee that.** refer
9fe0: 65 6e 63 65 73 20 74 68 65 6d 20 69 73 20 64 65 ences them is de
9ff0: 73 74 72 6f 79 65 64 2e 20 20 20 54 68 65 20 54 stroyed. The T
a000: 45 4d 50 20 53 63 68 65 6d 61 20 69 73 20 6d 61 EMP Schema is ma
a010: 6e 75 61 6c 6c 79 20 66 72 65 65 64 20 62 79 0a nually freed by.
a020: 2a 2a 20 73 71 6c 69 74 65 33 5f 63 6c 6f 73 65 ** sqlite3_close
a030: 28 29 2e 0a 2a 0a 2a 2a 20 41 20 74 68 72 65 61 ()..*.** A threa
a040: 64 20 6d 75 73 74 20 62 65 20 68 6f 6c 64 69 6e d must be holdin
a050: 67 20 61 20 6d 75 74 65 78 20 6f 6e 20 74 68 65 g a mutex on the
a060: 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 42 corresponding B
a070: 74 72 65 65 20 69 6e 20 6f 72 64 65 72 0a 2a 2a tree in order.**
a080: 20 74 6f 20 61 63 63 65 73 73 20 53 63 68 65 6d to access Schem
a090: 61 20 63 6f 6e 74 65 6e 74 2e 20 20 54 68 69 73 a content. This
a0a0: 20 69 6d 70 6c 69 65 73 20 74 68 61 74 20 74 68 implies that th
a0b0: 65 20 74 68 72 65 61 64 20 6d 75 73 74 20 61 6c e thread must al
a0c0: 73 6f 20 62 65 0a 2a 2a 20 68 6f 6c 64 69 6e 67 so be.** holding
a0d0: 20 61 20 6d 75 74 65 78 20 6f 6e 20 74 68 65 20 a mutex on the
a0e0: 73 71 6c 69 74 65 33 20 63 6f 6e 6e 65 63 74 69 sqlite3 connecti
a0f0: 6f 6e 20 70 6f 69 6e 74 65 72 20 74 68 61 74 20 on pointer that
a100: 6f 77 6e 73 20 74 68 65 20 42 74 72 65 65 2e 0a owns the Btree..
a110: 2a 2a 20 46 6f 72 20 61 20 54 45 4d 50 20 53 63 ** For a TEMP Sc
a120: 68 65 6d 61 2c 20 6f 6e 6c 79 20 74 68 65 20 63 hema, only the c
a130: 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 65 78 20 onnection mutex
a140: 69 73 20 72 65 71 75 69 72 65 64 2e 0a 2a 2f 0a is required..*/.
a150: 73 74 72 75 63 74 20 53 63 68 65 6d 61 20 7b 0a struct Schema {.
a160: 20 20 69 6e 74 20 73 63 68 65 6d 61 5f 63 6f 6f int schema_coo
a170: 6b 69 65 3b 20 20 20 2f 2a 20 44 61 74 61 62 61 kie; /* Databa
a180: 73 65 20 73 63 68 65 6d 61 20 76 65 72 73 69 6f se schema versio
a190: 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 69 n number for thi
a1a0: 73 20 66 69 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 s file */. int
a1b0: 69 47 65 6e 65 72 61 74 69 6f 6e 3b 20 20 20 20 iGeneration;
a1c0: 20 2f 2a 20 47 65 6e 65 72 61 74 69 6f 6e 20 63 /* Generation c
a1d0: 6f 75 6e 74 65 72 2e 20 20 49 6e 63 72 65 6d 65 ounter. Increme
a1e0: 6e 74 65 64 20 77 69 74 68 20 65 61 63 68 20 63 nted with each c
a1f0: 68 61 6e 67 65 20 2a 2f 0a 20 20 48 61 73 68 20 hange */. Hash
a200: 74 62 6c 48 61 73 68 3b 20 20 20 20 20 20 20 20 tblHash;
a210: 2f 2a 20 41 6c 6c 20 74 61 62 6c 65 73 20 69 6e /* All tables in
a220: 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a 2f dexed by name */
a230: 0a 20 20 48 61 73 68 20 69 64 78 48 61 73 68 3b . Hash idxHash;
a240: 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 28 /* All (
a250: 6e 61 6d 65 64 29 20 69 6e 64 69 63 65 73 20 69 named) indices i
a260: 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a ndexed by name *
a270: 2f 0a 20 20 48 61 73 68 20 74 72 69 67 48 61 73 /. Hash trigHas
a280: 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 h; /* All
a290: 74 72 69 67 67 65 72 73 20 69 6e 64 65 78 65 64 triggers indexed
a2a0: 20 62 79 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 by name */. Ha
a2b0: 73 68 20 66 6b 65 79 48 61 73 68 3b 20 20 20 20 sh fkeyHash;
a2c0: 20 20 20 2f 2a 20 41 6c 6c 20 66 6f 72 65 69 67 /* All foreig
a2d0: 6e 20 6b 65 79 73 20 62 79 20 72 65 66 65 72 65 n keys by refere
a2e0: 6e 63 65 64 20 74 61 62 6c 65 20 6e 61 6d 65 20 nced table name
a2f0: 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 53 65 71 */. Table *pSeq
a300: 54 61 62 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 Tab; /* The
a310: 20 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65 sqlite_sequence
a320: 20 74 61 62 6c 65 20 75 73 65 64 20 62 79 20 41 table used by A
a330: 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 2a 2f 0a UTOINCREMENT */.
a340: 20 20 75 38 20 66 69 6c 65 5f 66 6f 72 6d 61 74 u8 file_format
a350: 3b 20 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 ; /* Schema
a360: 20 66 6f 72 6d 61 74 20 76 65 72 73 69 6f 6e 20 format version
a370: 66 6f 72 20 74 68 69 73 20 66 69 6c 65 20 2a 2f for this file */
a380: 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 20 20 20 . u8 enc;
a390: 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 /* Text
a3a0: 65 6e 63 6f 64 69 6e 67 20 75 73 65 64 20 62 79 encoding used by
a3b0: 20 74 68 69 73 20 64 61 74 61 62 61 73 65 20 2a this database *
a3c0: 2f 0a 20 20 75 31 36 20 73 63 68 65 6d 61 46 6c /. u16 schemaFl
a3d0: 61 67 73 3b 20 20 20 20 20 2f 2a 20 46 6c 61 67 ags; /* Flag
a3e0: 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 s associated wit
a3f0: 68 20 74 68 69 73 20 73 63 68 65 6d 61 20 2a 2f h this schema */
a400: 0a 20 20 69 6e 74 20 63 61 63 68 65 5f 73 69 7a . int cache_siz
a410: 65 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 e; /* Numbe
a420: 72 20 6f 66 20 70 61 67 65 73 20 74 6f 20 75 73 r of pages to us
a430: 65 20 69 6e 20 74 68 65 20 63 61 63 68 65 20 2a e in the cache *
a440: 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 /.};../*.** Thes
a450: 65 20 6d 61 63 72 6f 73 20 63 61 6e 20 62 65 20 e macros can be
a460: 75 73 65 64 20 74 6f 20 74 65 73 74 2c 20 73 65 used to test, se
a470: 74 2c 20 6f 72 20 63 6c 65 61 72 20 62 69 74 73 t, or clear bits
a480: 20 69 6e 20 74 68 65 0a 2a 2a 20 44 62 2e 70 53 in the.** Db.pS
a490: 63 68 65 6d 61 2d 3e 66 6c 61 67 73 20 66 69 65 chema->flags fie
a4a0: 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 ld..*/.#define D
a4b0: 62 48 61 73 50 72 6f 70 65 72 74 79 28 44 2c 49 bHasProperty(D,I
a4c0: 2c 50 29 20 20 20 20 20 28 28 28 44 29 2d 3e 61 ,P) (((D)->a
a4d0: 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 Db[I].pSchema->s
a4e0: 63 68 65 6d 61 46 6c 61 67 73 26 28 50 29 29 3d chemaFlags&(P))=
a4f0: 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 20 44 62 =(P)).#define Db
a500: 48 61 73 41 6e 79 50 72 6f 70 65 72 74 79 28 44 HasAnyProperty(D
a510: 2c 49 2c 50 29 20 20 28 28 28 44 29 2d 3e 61 44 ,I,P) (((D)->aD
a520: 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 63 b[I].pSchema->sc
a530: 68 65 6d 61 46 6c 61 67 73 26 28 50 29 29 21 3d hemaFlags&(P))!=
a540: 30 29 0a 23 64 65 66 69 6e 65 20 44 62 53 65 74 0).#define DbSet
a550: 50 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 Property(D,I,P)
a560: 20 20 20 20 28 44 29 2d 3e 61 44 62 5b 49 5d 2e (D)->aDb[I].
a570: 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 pSchema->schemaF
a580: 6c 61 67 73 7c 3d 28 50 29 0a 23 64 65 66 69 6e lags|=(P).#defin
a590: 65 20 44 62 43 6c 65 61 72 50 72 6f 70 65 72 74 e DbClearPropert
a5a0: 79 28 44 2c 49 2c 50 29 20 20 20 28 44 29 2d 3e y(D,I,P) (D)->
a5b0: 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e aDb[I].pSchema->
a5c0: 73 63 68 65 6d 61 46 6c 61 67 73 26 3d 7e 28 50 schemaFlags&=~(P
a5d0: 29 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 )../*.** Allowed
a5e0: 20 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 values for the
a5f0: 44 42 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 67 DB.pSchema->flag
a600: 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 54 s field..**.** T
a610: 68 65 20 44 42 5f 53 63 68 65 6d 61 4c 6f 61 64 he DB_SchemaLoad
a620: 65 64 20 66 6c 61 67 20 69 73 20 73 65 74 20 61 ed flag is set a
a630: 66 74 65 72 20 74 68 65 20 64 61 74 61 62 61 73 fter the databas
a640: 65 20 73 63 68 65 6d 61 20 68 61 73 20 62 65 65 e schema has bee
a650: 6e 0a 2a 2a 20 72 65 61 64 20 69 6e 74 6f 20 69 n.** read into i
a660: 6e 74 65 72 6e 61 6c 20 68 61 73 68 20 74 61 62 nternal hash tab
a670: 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 44 42 5f 55 6e les..**.** DB_Un
a680: 72 65 73 65 74 56 69 65 77 73 20 6d 65 61 6e 73 resetViews means
a690: 20 74 68 61 74 20 6f 6e 65 20 6f 72 20 6d 6f 72 that one or mor
a6a0: 65 20 76 69 65 77 73 20 68 61 76 65 20 63 6f 6c e views have col
a6b0: 75 6d 6e 20 6e 61 6d 65 73 20 74 68 61 74 0a 2a umn names that.*
a6c0: 2a 20 68 61 76 65 20 62 65 65 6e 20 66 69 6c 6c * have been fill
a6d0: 65 64 20 6f 75 74 2e 20 20 49 66 20 74 68 65 20 ed out. If the
a6e0: 73 63 68 65 6d 61 20 63 68 61 6e 67 65 73 2c 20 schema changes,
a6f0: 74 68 65 73 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d these column nam
a700: 65 73 20 6d 69 67 68 74 0a 2a 2a 20 63 68 61 6e es might.** chan
a710: 67 65 73 20 61 6e 64 20 73 6f 20 74 68 65 20 76 ges and so the v
a720: 69 65 77 20 77 69 6c 6c 20 6e 65 65 64 20 74 6f iew will need to
a730: 20 62 65 20 72 65 73 65 74 2e 0a 2a 2f 0a 23 64 be reset..*/.#d
a740: 65 66 69 6e 65 20 44 42 5f 53 63 68 65 6d 61 4c efine DB_SchemaL
a750: 6f 61 64 65 64 20 20 20 20 30 78 30 30 30 31 20 oaded 0x0001
a760: 20 2f 2a 20 54 68 65 20 73 63 68 65 6d 61 20 68 /* The schema h
a770: 61 73 20 62 65 65 6e 20 6c 6f 61 64 65 64 20 2a as been loaded *
a780: 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 55 6e 72 /.#define DB_Unr
a790: 65 73 65 74 56 69 65 77 73 20 20 20 20 30 78 30 esetViews 0x0
a7a0: 30 30 32 20 20 2f 2a 20 53 6f 6d 65 20 76 69 65 002 /* Some vie
a7b0: 77 73 20 68 61 76 65 20 64 65 66 69 6e 65 64 20 ws have defined
a7c0: 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 2a 2f 0a column names */.
a7d0: 23 64 65 66 69 6e 65 20 44 42 5f 45 6d 70 74 79 #define DB_Empty
a7e0: 20 20 20 20 20 20 20 20 20 20 20 30 78 30 30 30 0x000
a7f0: 34 20 20 2f 2a 20 54 68 65 20 66 69 6c 65 20 69 4 /* The file i
a800: 73 20 65 6d 70 74 79 20 28 6c 65 6e 67 74 68 20 s empty (length
a810: 30 20 62 79 74 65 73 29 20 2a 2f 0a 23 64 65 66 0 bytes) */.#def
a820: 69 6e 65 20 44 42 5f 52 65 73 65 74 57 61 6e 74 ine DB_ResetWant
a830: 65 64 20 20 20 20 20 30 78 30 30 30 38 20 20 2f ed 0x0008 /
a840: 2a 20 52 65 73 65 74 20 74 68 65 20 73 63 68 65 * Reset the sche
a850: 6d 61 20 77 68 65 6e 20 6e 53 63 68 65 6d 61 4c ma when nSchemaL
a860: 6f 63 6b 3d 3d 30 20 2a 2f 0a 0a 2f 2a 0a 2a 2a ock==0 */../*.**
a870: 20 54 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 64 The number of d
a880: 69 66 66 65 72 65 6e 74 20 6b 69 6e 64 73 20 6f ifferent kinds o
a890: 66 20 74 68 69 6e 67 73 20 74 68 61 74 20 63 61 f things that ca
a8a0: 6e 20 62 65 20 6c 69 6d 69 74 65 64 0a 2a 2a 20 n be limited.**
a8b0: 75 73 69 6e 67 20 74 68 65 20 73 71 6c 69 74 65 using the sqlite
a8c0: 33 5f 6c 69 6d 69 74 28 29 20 69 6e 74 65 72 66 3_limit() interf
a8d0: 61 63 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ace..*/.#define
a8e0: 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 54 20 28 SQLITE_N_LIMIT (
a8f0: 53 51 4c 49 54 45 5f 4c 49 4d 49 54 5f 57 4f 52 SQLITE_LIMIT_WOR
a900: 4b 45 52 5f 54 48 52 45 41 44 53 2b 31 29 0a 0a KER_THREADS+1)..
a910: 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 /*.** Lookaside
a920: 6d 61 6c 6c 6f 63 20 69 73 20 61 20 73 65 74 20 malloc is a set
a930: 6f 66 20 66 69 78 65 64 2d 73 69 7a 65 20 62 75 of fixed-size bu
a940: 66 66 65 72 73 20 74 68 61 74 20 63 61 6e 20 62 ffers that can b
a950: 65 20 75 73 65 64 0a 2a 2a 20 74 6f 20 73 61 74 e used.** to sat
a960: 69 73 66 79 20 73 6d 61 6c 6c 20 74 72 61 6e 73 isfy small trans
a970: 69 65 6e 74 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f ient memory allo
a980: 63 61 74 69 6f 6e 20 72 65 71 75 65 73 74 73 20 cation requests
a990: 66 6f 72 20 6f 62 6a 65 63 74 73 0a 2a 2a 20 61 for objects.** a
a9a0: 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 61 ssociated with a
a9b0: 20 70 61 72 74 69 63 75 6c 61 72 20 64 61 74 61 particular data
a9c0: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e base connection.
a9d0: 20 20 54 68 65 20 75 73 65 20 6f 66 0a 2a 2a 20 The use of.**
a9e0: 6c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 lookaside malloc
a9f0: 20 70 72 6f 76 69 64 65 73 20 61 20 73 69 67 6e provides a sign
aa00: 69 66 69 63 61 6e 74 20 70 65 72 66 6f 72 6d 61 ificant performa
aa10: 6e 63 65 20 65 6e 68 61 6e 63 65 6d 65 6e 74 0a nce enhancement.
aa20: 2a 2a 20 28 61 70 70 72 6f 78 20 31 30 25 29 20 ** (approx 10%)
aa30: 62 79 20 61 76 6f 69 64 69 6e 67 20 6e 75 6d 65 by avoiding nume
aa40: 72 6f 75 73 20 6d 61 6c 6c 6f 63 2f 66 72 65 65 rous malloc/free
aa50: 20 72 65 71 75 65 73 74 73 20 77 68 69 6c 65 20 requests while
aa60: 70 61 72 73 69 6e 67 0a 2a 2a 20 53 51 4c 20 73 parsing.** SQL s
aa70: 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a tatements..**.**
aa80: 20 54 68 65 20 4c 6f 6f 6b 61 73 69 64 65 20 73 The Lookaside s
aa90: 74 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 63 tructure holds c
aaa0: 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 69 6e 66 onfiguration inf
aab0: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 ormation about t
aac0: 68 65 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 he.** lookaside
aad0: 6d 61 6c 6c 6f 63 20 73 75 62 73 79 73 74 65 6d malloc subsystem
aae0: 2e 20 20 45 61 63 68 20 61 76 61 69 6c 61 62 6c . Each availabl
aaf0: 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 e memory allocat
ab00: 69 6f 6e 20 69 6e 0a 2a 2a 20 74 68 65 20 6c 6f ion in.** the lo
ab10: 6f 6b 61 73 69 64 65 20 73 75 62 73 79 73 74 65 okaside subsyste
ab20: 6d 20 69 73 20 73 74 6f 72 65 64 20 6f 6e 20 61 m is stored on a
ab30: 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 linked list of
ab40: 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 0a 2a 2a LookasideSlot.**
ab50: 20 6f 62 6a 65 63 74 73 2e 0a 2a 2a 0a 2a 2a 20 objects..**.**
ab60: 4c 6f 6f 6b 61 73 69 64 65 20 61 6c 6c 6f 63 61 Lookaside alloca
ab70: 74 69 6f 6e 73 20 61 72 65 20 6f 6e 6c 79 20 61 tions are only a
ab80: 6c 6c 6f 77 65 64 20 66 6f 72 20 6f 62 6a 65 63 llowed for objec
ab90: 74 73 20 74 68 61 74 20 61 72 65 20 61 73 73 6f ts that are asso
aba0: 63 69 61 74 65 64 0a 2a 2a 20 77 69 74 68 20 61 ciated.** with a
abb0: 20 70 61 72 74 69 63 75 6c 61 72 20 64 61 74 61 particular data
abc0: 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 2e base connection.
abd0: 20 20 48 65 6e 63 65 2c 20 73 63 68 65 6d 61 20 Hence, schema
abe0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 61 6e 6e information cann
abf0: 6f 74 0a 2a 2a 20 62 65 20 73 74 6f 72 65 64 20 ot.** be stored
ac00: 69 6e 20 6c 6f 6f 6b 61 73 69 64 65 20 62 65 63 in lookaside bec
ac10: 61 75 73 65 20 69 6e 20 73 68 61 72 65 64 20 63 ause in shared c
ac20: 61 63 68 65 20 6d 6f 64 65 20 74 68 65 20 73 63 ache mode the sc
ac30: 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e hema information
ac40: 0a 2a 2a 20 69 73 20 73 68 61 72 65 64 20 62 79 .** is shared by
ac50: 20 6d 75 6c 74 69 70 6c 65 20 64 61 74 61 62 61 multiple databa
ac60: 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 2e 20 se connections.
ac70: 20 54 68 65 72 65 66 6f 72 65 2c 20 77 68 69 6c Therefore, whil
ac80: 65 20 70 61 72 73 69 6e 67 0a 2a 2a 20 73 63 68 e parsing.** sch
ac90: 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c ema information,
aca0: 20 74 68 65 20 4c 6f 6f 6b 61 73 69 64 65 2e 62 the Lookaside.b
acb0: 45 6e 61 62 6c 65 64 20 66 6c 61 67 20 69 73 20 Enabled flag is
acc0: 63 6c 65 61 72 65 64 20 73 6f 20 74 68 61 74 0a cleared so that.
acd0: 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 61 6c 6c ** lookaside all
ace0: 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 6e 6f 74 ocations are not
acf0: 20 75 73 65 64 20 74 6f 20 63 6f 6e 73 74 72 75 used to constru
ad00: 63 74 20 74 68 65 20 73 63 68 65 6d 61 20 6f 62 ct the schema ob
ad10: 6a 65 63 74 73 2e 0a 2a 2a 0a 2a 2a 20 4e 65 77 jects..**.** New
ad20: 20 6c 6f 6f 6b 61 73 69 64 65 20 61 6c 6c 6f 63 lookaside alloc
ad30: 61 74 69 6f 6e 73 20 61 72 65 20 6f 6e 6c 79 20 ations are only
ad40: 61 6c 6c 6f 77 65 64 20 69 66 20 62 44 69 73 61 allowed if bDisa
ad50: 62 6c 65 3d 3d 30 2e 20 20 57 68 65 6e 0a 2a 2a ble==0. When.**
ad60: 20 62 44 69 73 61 62 6c 65 20 69 73 20 67 72 65 bDisable is gre
ad70: 61 74 65 72 20 74 68 61 6e 20 7a 65 72 6f 2c 20 ater than zero,
ad80: 73 7a 20 69 73 20 73 65 74 20 74 6f 20 7a 65 72 sz is set to zer
ad90: 6f 20 77 68 69 63 68 20 65 66 66 65 63 74 69 76 o which effectiv
ada0: 65 6c 79 0a 2a 2a 20 64 69 73 61 62 6c 65 73 20 ely.** disables
adb0: 6c 6f 6f 6b 61 73 69 64 65 20 77 69 74 68 6f 75 lookaside withou
adc0: 74 20 61 64 64 69 6e 67 20 61 20 6e 65 77 20 74 t adding a new t
add0: 65 73 74 20 66 6f 72 20 74 68 65 20 62 44 69 73 est for the bDis
ade0: 61 62 6c 65 20 66 6c 61 67 0a 2a 2a 20 69 6e 20 able flag.** in
adf0: 61 20 70 65 72 66 6f 72 6d 61 6e 63 65 2d 63 72 a performance-cr
ae00: 69 74 69 63 61 6c 20 70 61 74 68 2e 20 20 73 7a itical path. sz
ae10: 20 73 68 6f 75 6c 64 20 62 65 20 73 65 74 20 62 should be set b
ae20: 79 20 74 6f 20 73 7a 54 72 75 65 20 77 68 65 6e y to szTrue when
ae30: 65 76 65 72 0a 2a 2a 20 62 44 69 73 61 62 6c 65 ever.** bDisable
ae40: 20 63 68 61 6e 67 65 73 20 62 61 63 6b 20 74 6f changes back to
ae50: 20 7a 65 72 6f 2e 0a 2a 2f 0a 73 74 72 75 63 74 zero..*/.struct
ae60: 20 4c 6f 6f 6b 61 73 69 64 65 20 7b 0a 20 20 75 Lookaside {. u
ae70: 33 32 20 62 44 69 73 61 62 6c 65 3b 20 20 20 20 32 bDisable;
ae80: 20 20 20 20 20 20 20 2f 2a 20 4f 6e 6c 79 20 6f /* Only o
ae90: 70 65 72 61 74 65 20 74 68 65 20 6c 6f 6f 6b 61 perate the looka
aea0: 73 69 64 65 20 77 68 65 6e 20 7a 65 72 6f 20 2a side when zero *
aeb0: 2f 0a 20 20 75 31 36 20 73 7a 3b 20 20 20 20 20 /. u16 sz;
aec0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
aed0: 69 7a 65 20 6f 66 20 65 61 63 68 20 62 75 66 66 ize of each buff
aee0: 65 72 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 er in bytes */.
aef0: 20 75 31 36 20 73 7a 54 72 75 65 3b 20 20 20 20 u16 szTrue;
af00: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
af10: 20 76 61 6c 75 65 20 6f 66 20 73 7a 2c 20 65 76 value of sz, ev
af20: 65 6e 20 69 66 20 64 69 73 61 62 6c 65 64 20 2a en if disabled *
af30: 2f 0a 20 20 75 38 20 62 4d 61 6c 6c 6f 63 65 64 /. u8 bMalloced
af40: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 ; /* T
af50: 72 75 65 20 69 66 20 70 53 74 61 72 74 20 6f 62 rue if pStart ob
af60: 74 61 69 6e 65 64 20 66 72 6f 6d 20 73 71 6c 69 tained from sqli
af70: 74 65 33 5f 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a te3_malloc() */.
af80: 20 20 75 33 32 20 6e 53 6c 6f 74 3b 20 20 20 20 u32 nSlot;
af90: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
afa0: 62 65 72 20 6f 66 20 6c 6f 6f 6b 61 73 69 64 65 ber of lookaside
afb0: 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 74 65 64 slots allocated
afc0: 20 2a 2f 0a 20 20 75 33 32 20 61 6e 53 74 61 74 */. u32 anStat
afd0: 5b 33 5d 3b 20 20 20 20 20 20 20 20 20 20 2f 2a [3]; /*
afe0: 20 30 3a 20 68 69 74 73 2e 20 20 31 3a 20 73 69 0: hits. 1: si
aff0: 7a 65 20 6d 69 73 73 65 73 2e 20 20 32 3a 20 66 ze misses. 2: f
b000: 75 6c 6c 20 6d 69 73 73 65 73 20 2a 2f 0a 20 20 ull misses */.
b010: 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 2a 70 LookasideSlot *p
b020: 49 6e 69 74 3b 20 20 20 2f 2a 20 4c 69 73 74 20 Init; /* List
b030: 6f 66 20 62 75 66 66 65 72 73 20 6e 6f 74 20 70 of buffers not p
b040: 72 65 76 69 6f 75 73 6c 79 20 75 73 65 64 20 2a reviously used *
b050: 2f 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f /. LookasideSlo
b060: 74 20 2a 70 46 72 65 65 3b 20 20 20 2f 2a 20 4c t *pFree; /* L
b070: 69 73 74 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 ist of available
b080: 20 62 75 66 66 65 72 73 20 2a 2f 0a 20 20 76 6f buffers */. vo
b090: 69 64 20 2a 70 53 74 61 72 74 3b 20 20 20 20 20 id *pStart;
b0a0: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 62 /* First b
b0b0: 79 74 65 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 yte of available
b0c0: 20 6d 65 6d 6f 72 79 20 73 70 61 63 65 20 2a 2f memory space */
b0d0: 0a 20 20 76 6f 69 64 20 2a 70 45 6e 64 3b 20 20 . void *pEnd;
b0e0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 /* Fi
b0f0: 72 73 74 20 62 79 74 65 20 70 61 73 74 20 65 6e rst byte past en
b100: 64 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 73 d of available s
b110: 70 61 63 65 20 2a 2f 0a 7d 3b 0a 73 74 72 75 63 pace */.};.struc
b120: 74 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 t LookasideSlot
b130: 7b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 53 6c 6f {. LookasideSlo
b140: 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 2f 2a 20 t *pNext; /*
b150: 4e 65 78 74 20 62 75 66 66 65 72 20 69 6e 20 74 Next buffer in t
b160: 68 65 20 6c 69 73 74 20 6f 66 20 66 72 65 65 20 he list of free
b170: 62 75 66 66 65 72 73 20 2a 2f 0a 7d 3b 0a 0a 23 buffers */.};..#
b180: 64 65 66 69 6e 65 20 44 69 73 61 62 6c 65 4c 6f define DisableLo
b190: 6f 6b 61 73 69 64 65 20 20 64 62 2d 3e 6c 6f 6f okaside db->loo
b1a0: 6b 61 73 69 64 65 2e 62 44 69 73 61 62 6c 65 2b kaside.bDisable+
b1b0: 2b 3b 64 62 2d 3e 6c 6f 6f 6b 61 73 69 64 65 2e +;db->lookaside.
b1c0: 73 7a 3d 30 0a 23 64 65 66 69 6e 65 20 45 6e 61 sz=0.#define Ena
b1d0: 62 6c 65 4c 6f 6f 6b 61 73 69 64 65 20 20 20 64 bleLookaside d
b1e0: 62 2d 3e 6c 6f 6f 6b 61 73 69 64 65 2e 62 44 69 b->lookaside.bDi
b1f0: 73 61 62 6c 65 2d 2d 3b 5c 0a 20 20 20 64 62 2d sable--;\. db-
b200: 3e 6c 6f 6f 6b 61 73 69 64 65 2e 73 7a 3d 64 62 >lookaside.sz=db
b210: 2d 3e 6c 6f 6f 6b 61 73 69 64 65 2e 62 44 69 73 ->lookaside.bDis
b220: 61 62 6c 65 3f 30 3a 64 62 2d 3e 6c 6f 6f 6b 61 able?0:db->looka
b230: 73 69 64 65 2e 73 7a 54 72 75 65 0a 0a 2f 2a 0a side.szTrue../*.
b240: 2a 2a 20 41 20 68 61 73 68 20 74 61 62 6c 65 20 ** A hash table
b250: 66 6f 72 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e for built-in fun
b260: 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e ction definition
b270: 73 2e 20 20 28 41 70 70 6c 69 63 61 74 69 6f 6e s. (Application
b280: 2d 64 65 66 69 6e 65 64 0a 2a 2a 20 66 75 6e 63 -defined.** func
b290: 74 69 6f 6e 73 20 75 73 65 20 61 20 72 65 67 75 tions use a regu
b2a0: 6c 61 72 20 74 61 62 6c 65 20 74 61 62 6c 65 20 lar table table
b2b0: 66 72 6f 6d 20 68 61 73 68 2e 68 2e 29 0a 2a 2a from hash.h.).**
b2c0: 0a 2a 2a 20 48 61 73 68 20 65 61 63 68 20 46 75 .** Hash each Fu
b2d0: 6e 63 44 65 66 20 73 74 72 75 63 74 75 72 65 20 ncDef structure
b2e0: 69 6e 74 6f 20 6f 6e 65 20 6f 66 20 74 68 65 20 into one of the
b2f0: 46 75 6e 63 44 65 66 48 61 73 68 2e 61 5b 5d 20 FuncDefHash.a[]
b300: 73 6c 6f 74 73 2e 0a 2a 2a 20 43 6f 6c 6c 69 73 slots..** Collis
b310: 69 6f 6e 73 20 61 72 65 20 6f 6e 20 74 68 65 20 ions are on the
b320: 46 75 6e 63 44 65 66 2e 75 2e 70 48 61 73 68 20 FuncDef.u.pHash
b330: 63 68 61 69 6e 2e 20 20 55 73 65 20 74 68 65 20 chain. Use the
b340: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 SQLITE_FUNC_HASH
b350: 28 29 0a 2a 2a 20 6d 61 63 72 6f 20 74 6f 20 63 ().** macro to c
b360: 6f 6d 70 75 74 65 20 61 20 68 61 73 68 20 6f 6e ompute a hash on
b370: 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 6e 61 the function na
b380: 6d 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 me..*/.#define S
b390: 51 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 5f QLITE_FUNC_HASH_
b3a0: 53 5a 20 32 33 0a 73 74 72 75 63 74 20 46 75 6e SZ 23.struct Fun
b3b0: 63 44 65 66 48 61 73 68 20 7b 0a 20 20 46 75 6e cDefHash {. Fun
b3c0: 63 44 65 66 20 2a 61 5b 53 51 4c 49 54 45 5f 46 cDef *a[SQLITE_F
b3d0: 55 4e 43 5f 48 41 53 48 5f 53 5a 5d 3b 20 20 20 UNC_HASH_SZ];
b3e0: 20 20 20 20 2f 2a 20 48 61 73 68 20 74 61 62 6c /* Hash tabl
b3f0: 65 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 e for functions
b400: 2a 2f 0a 7d 3b 0a 23 64 65 66 69 6e 65 20 53 51 */.};.#define SQ
b410: 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 28 43 LITE_FUNC_HASH(C
b420: 2c 4c 29 20 28 28 28 43 29 2b 28 4c 29 29 25 53 ,L) (((C)+(L))%S
b430: 51 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 5f QLITE_FUNC_HASH_
b440: 53 5a 29 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 SZ)..#ifdef SQLI
b450: 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 TE_USER_AUTHENTI
b460: 43 41 54 49 4f 4e 0a 2f 2a 0a 2a 2a 20 49 6e 66 CATION./*.** Inf
b470: 6f 72 6d 61 74 69 6f 6e 20 68 65 6c 64 20 69 6e ormation held in
b480: 20 74 68 65 20 22 73 71 6c 69 74 65 33 22 20 64 the "sqlite3" d
b490: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
b4a0: 6f 6e 20 6f 62 6a 65 63 74 20 61 6e 64 20 75 73 on object and us
b4b0: 65 64 0a 2a 2a 20 74 6f 20 6d 61 6e 61 67 65 20 ed.** to manage
b4c0: 75 73 65 72 20 61 75 74 68 65 6e 74 69 63 61 74 user authenticat
b4d0: 69 6f 6e 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 ion..*/.typedef
b4e0: 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 5f 75 struct sqlite3_u
b4f0: 73 65 72 61 75 74 68 20 73 71 6c 69 74 65 33 5f serauth sqlite3_
b500: 75 73 65 72 61 75 74 68 3b 0a 73 74 72 75 63 74 userauth;.struct
b510: 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 sqlite3_useraut
b520: 68 20 7b 0a 20 20 75 38 20 61 75 74 68 4c 65 76 h {. u8 authLev
b530: 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 el;
b540: 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 61 /* Current a
b550: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6c 65 uthentication le
b560: 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 75 vel */. int nAu
b570: 74 68 50 57 3b 20 20 20 20 20 20 20 20 20 20 20 thPW;
b580: 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f /* Size o
b590: 66 20 74 68 65 20 7a 41 75 74 68 50 57 20 69 6e f the zAuthPW in
b5a0: 20 62 79 74 65 73 20 2a 2f 0a 20 20 63 68 61 72 bytes */. char
b5b0: 20 2a 7a 41 75 74 68 50 57 3b 20 20 20 20 20 20 *zAuthPW;
b5c0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 73 /* Pas
b5d0: 73 77 6f 72 64 20 75 73 65 64 20 74 6f 20 61 75 sword used to au
b5e0: 74 68 65 6e 74 69 63 61 74 65 20 2a 2f 0a 20 20 thenticate */.
b5f0: 63 68 61 72 20 2a 7a 41 75 74 68 55 73 65 72 3b char *zAuthUser;
b600: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
b610: 20 55 73 65 72 20 6e 61 6d 65 20 75 73 65 64 20 User name used
b620: 74 6f 20 61 75 74 68 65 6e 74 69 63 61 74 65 20 to authenticate
b630: 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 */.};../* Allowe
b640: 64 20 76 61 6c 75 65 73 20 66 6f 72 20 73 71 6c d values for sql
b650: 69 74 65 33 5f 75 73 65 72 61 75 74 68 2e 61 75 ite3_userauth.au
b660: 74 68 4c 65 76 65 6c 20 2a 2f 0a 23 64 65 66 69 thLevel */.#defi
b670: 6e 65 20 55 41 55 54 48 5f 55 6e 6b 6e 6f 77 6e ne UAUTH_Unknown
b680: 20 20 20 20 20 30 20 20 20 20 20 2f 2a 20 41 75 0 /* Au
b690: 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6e 6f 74 thentication not
b6a0: 20 79 65 74 20 63 68 65 63 6b 65 64 20 2a 2f 0a yet checked */.
b6b0: 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 46 61 #define UAUTH_Fa
b6c0: 69 6c 20 20 20 20 20 20 20 20 31 20 20 20 20 20 il 1
b6d0: 2f 2a 20 55 73 65 72 20 61 75 74 68 65 6e 74 69 /* User authenti
b6e0: 63 61 74 69 6f 6e 20 66 61 69 6c 65 64 20 2a 2f cation failed */
b6f0: 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 55 .#define UAUTH_U
b700: 73 65 72 20 20 20 20 20 20 20 20 32 20 20 20 20 ser 2
b710: 20 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 74 65 /* Authenticate
b720: 64 20 61 73 20 61 20 6e 6f 72 6d 61 6c 20 75 73 d as a normal us
b730: 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 er */.#define UA
b740: 55 54 48 5f 41 64 6d 69 6e 20 20 20 20 20 20 20 UTH_Admin
b750: 33 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 3 /* Authent
b760: 69 63 61 74 65 64 20 61 73 20 61 6e 20 61 64 6d icated as an adm
b770: 69 6e 69 73 74 72 61 74 6f 72 20 2a 2f 0a 0a 2f inistrator */../
b780: 2a 20 46 75 6e 63 74 69 6f 6e 73 20 75 73 65 64 * Functions used
b790: 20 6f 6e 6c 79 20 62 79 20 75 73 65 72 20 61 75 only by user au
b7a0: 74 68 6f 72 69 7a 61 74 69 6f 6e 20 6c 6f 67 69 thorization logi
b7b0: 63 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 c */.int sqlite3
b7c0: 55 73 65 72 41 75 74 68 54 61 62 6c 65 28 63 6f UserAuthTable(co
b7d0: 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 20 nst char*);.int
b7e0: 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 43 sqlite3UserAuthC
b7f0: 68 65 63 6b 4c 6f 67 69 6e 28 73 71 6c 69 74 65 heckLogin(sqlite
b800: 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 3*,const char*,u
b810: 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 8*);.void sqlite
b820: 33 55 73 65 72 41 75 74 68 49 6e 69 74 28 73 71 3UserAuthInit(sq
b830: 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
b840: 6c 69 74 65 33 43 72 79 70 74 46 75 6e 63 28 73 lite3CryptFunc(s
b850: 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
b860: 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
b870: 65 2a 2a 29 3b 0a 0a 23 65 6e 64 69 66 20 2f 2a e**);..#endif /*
b880: 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 SQLITE_USER_AUT
b890: 48 45 4e 54 49 43 41 54 49 4f 4e 20 2a 2f 0a 0a HENTICATION */..
b8a0: 2f 2a 0a 2a 2a 20 74 79 70 65 64 65 66 20 66 6f /*.** typedef fo
b8b0: 72 20 74 68 65 20 61 75 74 68 6f 72 69 7a 61 74 r the authorizat
b8c0: 69 6f 6e 20 63 61 6c 6c 62 61 63 6b 20 66 75 6e ion callback fun
b8d0: 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 64 65 66 ction..*/.#ifdef
b8e0: 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 SQLITE_USER_AUT
b8f0: 48 45 4e 54 49 43 41 54 49 4f 4e 0a 20 20 74 79 HENTICATION. ty
b900: 70 65 64 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 pedef int (*sqli
b910: 74 65 33 5f 78 61 75 74 68 29 28 76 6f 69 64 2a te3_xauth)(void*
b920: 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
b930: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e ,const char*,con
b940: 73 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 st char*,.
b950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b960: 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 const c
b970: 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 har*, const char
b980: 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 *);.#else. type
b990: 64 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 74 65 def int (*sqlite
b9a0: 33 5f 78 61 75 74 68 29 28 76 6f 69 64 2a 2c 69 3_xauth)(void*,i
b9b0: 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 nt,const char*,c
b9c0: 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 onst char*,const
b9d0: 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 20 20 char*,.
b9e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b9f0: 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 const cha
ba00: 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 r*);.#endif..#if
ba10: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
ba20: 5f 44 45 50 52 45 43 41 54 45 44 0a 2f 2a 20 54 _DEPRECATED./* T
ba30: 68 69 73 20 69 73 20 61 6e 20 65 78 74 72 61 20 his is an extra
ba40: 53 51 4c 49 54 45 5f 54 52 41 43 45 20 6d 61 63 SQLITE_TRACE mac
ba50: 72 6f 20 74 68 61 74 20 69 6e 64 69 63 61 74 65 ro that indicate
ba60: 73 20 22 6c 65 67 61 63 79 22 20 74 72 61 63 69 s "legacy" traci
ba70: 6e 67 0a 2a 2a 20 69 6e 20 74 68 65 20 73 74 79 ng.** in the sty
ba80: 6c 65 20 6f 66 20 73 71 6c 69 74 65 33 5f 74 72 le of sqlite3_tr
ba90: 61 63 65 28 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 ace().*/.#define
baa0: 20 53 51 4c 49 54 45 5f 54 52 41 43 45 5f 4c 45 SQLITE_TRACE_LE
bab0: 47 41 43 59 20 20 20 20 20 20 20 20 20 20 30 78 GACY 0x
bac0: 34 30 20 20 20 20 20 2f 2a 20 55 73 65 20 74 68 40 /* Use th
bad0: 65 20 6c 65 67 61 63 79 20 78 54 72 61 63 65 20 e legacy xTrace
bae0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
baf0: 45 5f 54 52 41 43 45 5f 58 50 52 4f 46 49 4c 45 E_TRACE_XPROFILE
bb00: 20 20 20 20 20 20 20 20 30 78 38 30 20 20 20 20 0x80
bb10: 20 2f 2a 20 55 73 65 20 74 68 65 20 6c 65 67 61 /* Use the lega
bb20: 63 79 20 78 50 72 6f 66 69 6c 65 20 2a 2f 0a 23 cy xProfile */.#
bb30: 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 53 51 4c else.#define SQL
bb40: 49 54 45 5f 54 52 41 43 45 5f 4c 45 47 41 43 59 ITE_TRACE_LEGACY
bb50: 20 20 20 20 20 20 20 20 20 20 30 0a 23 64 65 66 0.#def
bb60: 69 6e 65 20 53 51 4c 49 54 45 5f 54 52 41 43 45 ine SQLITE_TRACE
bb70: 5f 58 50 52 4f 46 49 4c 45 20 20 20 20 20 20 20 _XPROFILE
bb80: 20 30 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 4c 0.#endif /* SQL
bb90: 49 54 45 5f 4f 4d 49 54 5f 44 45 50 52 45 43 41 ITE_OMIT_DEPRECA
bba0: 54 45 44 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 TED */.#define S
bbb0: 51 4c 49 54 45 5f 54 52 41 43 45 5f 4e 4f 4e 4c QLITE_TRACE_NONL
bbc0: 45 47 41 43 59 5f 4d 41 53 4b 20 20 30 78 30 66 EGACY_MASK 0x0f
bbd0: 20 20 20 20 20 2f 2a 20 4e 6f 72 6d 61 6c 20 66 /* Normal f
bbe0: 6c 61 67 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 lags */.../*.**
bbf0: 45 61 63 68 20 64 61 74 61 62 61 73 65 20 63 6f Each database co
bc00: 6e 6e 65 63 74 69 6f 6e 20 69 73 20 61 6e 20 69 nnection is an i
bc10: 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
bc20: 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
bc30: 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 73 71 re..*/.struct sq
bc40: 6c 69 74 65 33 20 7b 0a 20 20 73 71 6c 69 74 65 lite3 {. sqlite
bc50: 33 5f 76 66 73 20 2a 70 56 66 73 3b 20 20 20 20 3_vfs *pVfs;
bc60: 20 20 20 20 20 20 20 20 2f 2a 20 4f 53 20 49 6e /* OS In
bc70: 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 74 72 terface */. str
bc80: 75 63 74 20 56 64 62 65 20 2a 70 56 64 62 65 3b uct Vdbe *pVdbe;
bc90: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 /* Li
bca0: 73 74 20 6f 66 20 61 63 74 69 76 65 20 76 69 72 st of active vir
bcb0: 74 75 61 6c 20 6d 61 63 68 69 6e 65 73 20 2a 2f tual machines */
bcc0: 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 70 44 66 6c . CollSeq *pDfl
bcd0: 74 43 6f 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 tColl;
bce0: 20 2f 2a 20 54 68 65 20 64 65 66 61 75 6c 74 20 /* The default
bcf0: 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e collating sequen
bd00: 63 65 20 28 42 49 4e 41 52 59 29 20 2a 2f 0a 20 ce (BINARY) */.
bd10: 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a sqlite3_mutex *
bd20: 6d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 2f mutex; /
bd30: 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 * Connection mut
bd40: 65 78 20 2a 2f 0a 20 20 44 62 20 2a 61 44 62 3b ex */. Db *aDb;
bd50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
bd60: 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 62 61 63 /* All bac
bd70: 6b 65 6e 64 73 20 2a 2f 0a 20 20 69 6e 74 20 6e kends */. int n
bd80: 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 Db;
bd90: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
bda0: 65 72 20 6f 66 20 62 61 63 6b 65 6e 64 73 20 63 er of backends c
bdb0: 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 73 65 20 urrently in use
bdc0: 2a 2f 0a 20 20 75 33 32 20 6d 44 62 46 6c 61 67 */. u32 mDbFlag
bdd0: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 s;
bde0: 20 20 20 2f 2a 20 66 6c 61 67 73 20 72 65 63 6f /* flags reco
bdf0: 72 64 69 6e 67 20 69 6e 74 65 72 6e 61 6c 20 73 rding internal s
be00: 74 61 74 65 20 2a 2f 0a 20 20 75 36 34 20 66 6c tate */. u64 fl
be10: 61 67 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ags;
be20: 20 20 20 20 20 20 20 20 2f 2a 20 66 6c 61 67 73 /* flags
be30: 20 73 65 74 74 61 62 6c 65 20 62 79 20 70 72 61 settable by pra
be40: 67 6d 61 73 2e 20 53 65 65 20 62 65 6c 6f 77 20 gmas. See below
be50: 2a 2f 0a 20 20 69 36 34 20 6c 61 73 74 52 6f 77 */. i64 lastRow
be60: 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 id;
be70: 20 20 20 2f 2a 20 52 4f 57 49 44 20 6f 66 20 6d /* ROWID of m
be80: 6f 73 74 20 72 65 63 65 6e 74 20 69 6e 73 65 72 ost recent inser
be90: 74 20 28 73 65 65 20 61 62 6f 76 65 29 20 2a 2f t (see above) */
bea0: 0a 20 20 69 36 34 20 73 7a 4d 6d 61 70 3b 20 20 . i64 szMmap;
beb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
bec0: 20 2f 2a 20 44 65 66 61 75 6c 74 20 6d 6d 61 70 /* Default mmap
bed0: 5f 73 69 7a 65 20 73 65 74 74 69 6e 67 20 2a 2f _size setting */
bee0: 0a 20 20 75 33 32 20 6e 53 63 68 65 6d 61 4c 6f . u32 nSchemaLo
bef0: 63 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ck;
bf00: 20 2f 2a 20 44 6f 20 6e 6f 74 20 72 65 73 65 74 /* Do not reset
bf10: 20 74 68 65 20 73 63 68 65 6d 61 20 77 68 65 6e the schema when
bf20: 20 6e 6f 6e 2d 7a 65 72 6f 20 2a 2f 0a 20 20 75 non-zero */. u
bf30: 6e 73 69 67 6e 65 64 20 69 6e 74 20 6f 70 65 6e nsigned int open
bf40: 46 6c 61 67 73 3b 20 20 20 20 20 20 20 2f 2a 20 Flags; /*
bf50: 46 6c 61 67 73 20 70 61 73 73 65 64 20 74 6f 20 Flags passed to
bf60: 73 71 6c 69 74 65 33 5f 76 66 73 2e 78 4f 70 65 sqlite3_vfs.xOpe
bf70: 6e 28 29 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 n() */. int err
bf80: 43 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 Code;
bf90: 20 20 20 20 20 20 20 2f 2a 20 4d 6f 73 74 20 72 /* Most r
bfa0: 65 63 65 6e 74 20 65 72 72 6f 72 20 63 6f 64 65 ecent error code
bfb0: 20 28 53 51 4c 49 54 45 5f 2a 29 20 2a 2f 0a 20 (SQLITE_*) */.
bfc0: 20 69 6e 74 20 65 72 72 4d 61 73 6b 3b 20 20 20 int errMask;
bfd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
bfe0: 2a 20 26 20 72 65 73 75 6c 74 20 63 6f 64 65 73 * & result codes
bff0: 20 77 69 74 68 20 74 68 69 73 20 62 65 66 6f 72 with this befor
c000: 65 20 72 65 74 75 72 6e 69 6e 67 20 2a 2f 0a 20 e returning */.
c010: 20 69 6e 74 20 69 53 79 73 45 72 72 6e 6f 3b 20 int iSysErrno;
c020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c030: 2a 20 45 72 72 6e 6f 20 76 61 6c 75 65 20 66 72 * Errno value fr
c040: 6f 6d 20 6c 61 73 74 20 73 79 73 74 65 6d 20 65 om last system e
c050: 72 72 6f 72 20 2a 2f 0a 20 20 75 31 36 20 64 62 rror */. u16 db
c060: 4f 70 74 46 6c 61 67 73 3b 20 20 20 20 20 20 20 OptFlags;
c070: 20 20 20 20 20 20 20 20 2f 2a 20 46 6c 61 67 73 /* Flags
c080: 20 74 6f 20 65 6e 61 62 6c 65 2f 64 69 73 61 62 to enable/disab
c090: 6c 65 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 le optimizations
c0a0: 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 */. u8 enc;
c0b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c0c0: 20 20 20 20 2f 2a 20 54 65 78 74 20 65 6e 63 6f /* Text enco
c0d0: 64 69 6e 67 20 2a 2f 0a 20 20 75 38 20 61 75 74 ding */. u8 aut
c0e0: 6f 43 6f 6d 6d 69 74 3b 20 20 20 20 20 20 20 20 oCommit;
c0f0: 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 61 /* The a
c100: 75 74 6f 2d 63 6f 6d 6d 69 74 20 66 6c 61 67 2e uto-commit flag.
c110: 20 2a 2f 0a 20 20 75 38 20 74 65 6d 70 5f 73 74 */. u8 temp_st
c120: 6f 72 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ore;
c130: 20 20 20 20 2f 2a 20 31 3a 20 66 69 6c 65 20 32 /* 1: file 2
c140: 3a 20 6d 65 6d 6f 72 79 20 30 3a 20 64 65 66 61 : memory 0: defa
c150: 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6d 61 6c 6c ult */. u8 mall
c160: 6f 63 46 61 69 6c 65 64 3b 20 20 20 20 20 20 20 ocFailed;
c170: 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 /* True i
c180: 66 20 77 65 20 68 61 76 65 20 73 65 65 6e 20 61 f we have seen a
c190: 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 65 20 malloc failure
c1a0: 2a 2f 0a 20 20 75 38 20 62 42 65 6e 69 67 6e 4d */. u8 bBenignM
c1b0: 61 6c 6c 6f 63 3b 20 20 20 20 20 20 20 20 20 20 alloc;
c1c0: 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 72 65 71 /* Do not req
c1d0: 75 69 72 65 20 4f 4f 4d 73 20 69 66 20 74 72 75 uire OOMs if tru
c1e0: 65 20 2a 2f 0a 20 20 75 38 20 64 66 6c 74 4c 6f e */. u8 dfltLo
c1f0: 63 6b 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 20 ckMode;
c200: 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 /* Default
c210: 6c 6f 63 6b 69 6e 67 2d 6d 6f 64 65 20 66 6f 72 locking-mode for
c220: 20 61 74 74 61 63 68 65 64 20 64 62 73 20 2a 2f attached dbs */
c230: 0a 20 20 73 69 67 6e 65 64 20 63 68 61 72 20 6e . signed char n
c240: 65 78 74 41 75 74 6f 76 61 63 3b 20 20 20 20 20 extAutovac;
c250: 20 2f 2a 20 41 75 74 6f 76 61 63 20 73 65 74 74 /* Autovac sett
c260: 69 6e 67 20 61 66 74 65 72 20 56 41 43 55 55 4d ing after VACUUM
c270: 20 69 66 20 3e 3d 30 20 2a 2f 0a 20 20 75 38 20 if >=0 */. u8
c280: 73 75 70 70 72 65 73 73 45 72 72 3b 20 20 20 20 suppressErr;
c290: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f /* Do
c2a0: 20 6e 6f 74 20 69 73 73 75 65 20 65 72 72 6f 72 not issue error
c2b0: 20 6d 65 73 73 61 67 65 73 20 69 66 20 74 72 75 messages if tru
c2c0: 65 20 2a 2f 0a 20 20 75 38 20 76 74 61 62 4f 6e e */. u8 vtabOn
c2d0: 43 6f 6e 66 6c 69 63 74 3b 20 20 20 20 20 20 20 Conflict;
c2e0: 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f /* Value to
c2f0: 20 72 65 74 75 72 6e 20 66 6f 72 20 73 33 5f 76 return for s3_v
c300: 74 61 62 5f 6f 6e 5f 63 6f 6e 66 6c 69 63 74 28 tab_on_conflict(
c310: 29 20 2a 2f 0a 20 20 75 38 20 69 73 54 72 61 6e ) */. u8 isTran
c320: 73 61 63 74 69 6f 6e 53 61 76 65 70 6f 69 6e 74 sactionSavepoint
c330: 3b 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 ; /* True if
c340: 74 68 65 20 6f 75 74 65 72 6d 6f 73 74 20 73 61 the outermost sa
c350: 76 65 70 6f 69 6e 74 20 69 73 20 61 20 54 53 20 vepoint is a TS
c360: 2a 2f 0a 20 20 75 38 20 6d 54 72 61 63 65 3b 20 */. u8 mTrace;
c370: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c380: 20 20 20 2f 2a 20 7a 65 72 6f 20 6f 72 20 6d 6f /* zero or mo
c390: 72 65 20 53 51 4c 49 54 45 5f 54 52 41 43 45 20 re SQLITE_TRACE
c3a0: 66 6c 61 67 73 20 2a 2f 0a 20 20 75 38 20 6e 6f flags */. u8 no
c3b0: 53 68 61 72 65 64 43 61 63 68 65 3b 20 20 20 20 SharedCache;
c3c0: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
c3d0: 20 69 66 20 6e 6f 20 73 68 61 72 65 64 2d 63 61 if no shared-ca
c3e0: 63 68 65 20 62 61 63 6b 65 6e 64 73 20 2a 2f 0a che backends */.
c3f0: 20 20 75 38 20 6e 53 71 6c 45 78 65 63 3b 20 20 u8 nSqlExec;
c400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c410: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 65 6e /* Number of pen
c420: 64 69 6e 67 20 4f 50 5f 53 71 6c 45 78 65 63 20 ding OP_SqlExec
c430: 6f 70 63 6f 64 65 73 20 2a 2f 0a 20 20 69 6e 74 opcodes */. int
c440: 20 6e 65 78 74 50 61 67 65 73 69 7a 65 3b 20 20 nextPagesize;
c450: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 /* Pa
c460: 67 65 73 69 7a 65 20 61 66 74 65 72 20 56 41 43 gesize after VAC
c470: 55 55 4d 20 69 66 20 3e 30 20 2a 2f 0a 20 20 75 UUM if >0 */. u
c480: 33 32 20 6d 61 67 69 63 3b 20 20 20 20 20 20 20 32 magic;
c490: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c4a0: 4d 61 67 69 63 20 6e 75 6d 62 65 72 20 66 6f 72 Magic number for
c4b0: 20 64 65 74 65 63 74 20 6c 69 62 72 61 72 79 20 detect library
c4c0: 6d 69 73 75 73 65 20 2a 2f 0a 20 20 69 6e 74 20 misuse */. int
c4d0: 6e 43 68 61 6e 67 65 3b 20 20 20 20 20 20 20 20 nChange;
c4e0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c /* Val
c4f0: 75 65 20 72 65 74 75 72 6e 65 64 20 62 79 20 73 ue returned by s
c500: 71 6c 69 74 65 33 5f 63 68 61 6e 67 65 73 28 29 qlite3_changes()
c510: 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 6f 74 61 6c */. int nTotal
c520: 43 68 61 6e 67 65 3b 20 20 20 20 20 20 20 20 20 Change;
c530: 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 72 65 74 /* Value ret
c540: 75 72 6e 65 64 20 62 79 20 73 71 6c 69 74 65 33 urned by sqlite3
c550: 5f 74 6f 74 61 6c 5f 63 68 61 6e 67 65 73 28 29 _total_changes()
c560: 20 2a 2f 0a 20 20 69 6e 74 20 61 4c 69 6d 69 74 */. int aLimit
c570: 5b 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d 49 54 5d [SQLITE_N_LIMIT]
c580: 3b 20 20 20 2f 2a 20 4c 69 6d 69 74 73 20 2a 2f ; /* Limits */
c590: 0a 20 20 69 6e 74 20 6e 4d 61 78 53 6f 72 74 65 . int nMaxSorte
c5a0: 72 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 rMmap;
c5b0: 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 73 69 7a 65 /* Maximum size
c5c0: 20 6f 66 20 72 65 67 69 6f 6e 73 20 6d 61 70 70 of regions mapp
c5d0: 65 64 20 62 79 20 73 6f 72 74 65 72 20 2a 2f 0a ed by sorter */.
c5e0: 20 20 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 struct sqlite3
c5f0: 49 6e 69 74 49 6e 66 6f 20 7b 20 20 20 20 20 20 InitInfo {
c600: 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 /* Information u
c610: 73 65 64 20 64 75 72 69 6e 67 20 69 6e 69 74 69 sed during initi
c620: 61 6c 69 7a 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 alization */.
c630: 20 69 6e 74 20 6e 65 77 54 6e 75 6d 3b 20 20 20 int newTnum;
c640: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c650: 52 6f 6f 74 70 61 67 65 20 6f 66 20 74 61 62 6c Rootpage of tabl
c660: 65 20 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 e being initiali
c670: 7a 65 64 20 2a 2f 0a 20 20 20 20 75 38 20 69 44 zed */. u8 iD
c680: 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 b;
c690: 20 20 20 20 20 20 20 2f 2a 20 57 68 69 63 68 20 /* Which
c6a0: 64 62 20 66 69 6c 65 20 69 73 20 62 65 69 6e 67 db file is being
c6b0: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
c6c0: 20 20 20 20 75 38 20 62 75 73 79 3b 20 20 20 20 u8 busy;
c6d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c6e0: 2f 2a 20 54 52 55 45 20 69 66 20 63 75 72 72 65 /* TRUE if curre
c6f0: 6e 74 6c 79 20 69 6e 69 74 69 61 6c 69 7a 69 6e ntly initializin
c700: 67 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 g */. unsigne
c710: 64 20 6f 72 70 68 61 6e 54 72 69 67 67 65 72 20 d orphanTrigger
c720: 3a 20 31 3b 20 2f 2a 20 4c 61 73 74 20 73 74 61 : 1; /* Last sta
c730: 74 65 6d 65 6e 74 20 69 73 20 6f 72 70 68 61 6e tement is orphan
c740: 65 64 20 54 45 4d 50 20 74 72 69 67 67 65 72 20 ed TEMP trigger
c750: 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 */. unsigned
c760: 69 6d 70 6f 73 74 65 72 54 61 62 6c 65 20 3a 20 imposterTable :
c770: 31 3b 20 2f 2a 20 42 75 69 6c 64 69 6e 67 20 61 1; /* Building a
c780: 6e 20 69 6d 70 6f 73 74 65 72 20 74 61 62 6c 65 n imposter table
c790: 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 */. unsigned
c7a0: 20 72 65 6f 70 65 6e 4d 65 6d 64 62 20 3a 20 31 reopenMemdb : 1
c7b0: 3b 20 20 20 2f 2a 20 41 54 54 41 43 48 20 69 73 ; /* ATTACH is
c7c0: 20 72 65 61 6c 6c 79 20 61 20 72 65 6f 70 65 6e really a reopen
c7d0: 20 75 73 69 6e 67 20 4d 65 6d 44 42 20 2a 2f 0a using MemDB */.
c7e0: 20 20 20 20 63 68 61 72 20 2a 2a 61 7a 49 6e 69 char **azIni
c7f0: 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
c800: 2f 2a 20 22 74 79 70 65 22 2c 20 22 6e 61 6d 65 /* "type", "name
c810: 22 2c 20 61 6e 64 20 22 74 62 6c 5f 6e 61 6d 65 ", and "tbl_name
c820: 22 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 7d " columns */. }
c830: 20 69 6e 69 74 3b 0a 20 20 69 6e 74 20 6e 56 64 init;. int nVd
c840: 62 65 41 63 74 69 76 65 3b 20 20 20 20 20 20 20 beActive;
c850: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
c860: 20 6f 66 20 56 44 42 45 73 20 63 75 72 72 65 6e of VDBEs curren
c870: 74 6c 79 20 72 75 6e 6e 69 6e 67 20 2a 2f 0a 20 tly running */.
c880: 20 69 6e 74 20 6e 56 64 62 65 52 65 61 64 3b 20 int nVdbeRead;
c890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c8a0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 69 * Number of acti
c8b0: 76 65 20 56 44 42 45 73 20 74 68 61 74 20 72 65 ve VDBEs that re
c8c0: 61 64 20 6f 72 20 77 72 69 74 65 20 2a 2f 0a 20 ad or write */.
c8d0: 20 69 6e 74 20 6e 56 64 62 65 57 72 69 74 65 3b int nVdbeWrite;
c8e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c8f0: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 69 * Number of acti
c900: 76 65 20 56 44 42 45 73 20 74 68 61 74 20 72 65 ve VDBEs that re
c910: 61 64 20 61 6e 64 20 77 72 69 74 65 20 2a 2f 0a ad and write */.
c920: 20 20 69 6e 74 20 6e 56 64 62 65 45 78 65 63 3b int nVdbeExec;
c930: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c940: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 /* Number of nes
c950: 74 65 64 20 63 61 6c 6c 73 20 74 6f 20 56 64 62 ted calls to Vdb
c960: 65 45 78 65 63 28 29 20 2a 2f 0a 20 20 69 6e 74 eExec() */. int
c970: 20 6e 56 44 65 73 74 72 6f 79 3b 20 20 20 20 20 nVDestroy;
c980: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
c990: 6d 62 65 72 20 6f 66 20 61 63 74 69 76 65 20 4f mber of active O
c9a0: 50 5f 56 44 65 73 74 72 6f 79 20 6f 70 65 72 61 P_VDestroy opera
c9b0: 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 6e tions */. int n
c9c0: 45 78 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 20 Extension;
c9d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
c9e0: 65 72 20 6f 66 20 6c 6f 61 64 65 64 20 65 78 74 er of loaded ext
c9f0: 65 6e 73 69 6f 6e 73 20 2a 2f 0a 20 20 76 6f 69 ensions */. voi
ca00: 64 20 2a 2a 61 45 78 74 65 6e 73 69 6f 6e 3b 20 d **aExtension;
ca10: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
ca20: 72 61 79 20 6f 66 20 73 68 61 72 65 64 20 6c 69 ray of shared li
ca30: 62 72 61 72 79 20 68 61 6e 64 6c 65 73 20 2a 2f brary handles */
ca40: 0a 20 20 69 6e 74 20 28 2a 78 54 72 61 63 65 29 . int (*xTrace)
ca50: 28 75 33 32 2c 76 6f 69 64 2a 2c 76 6f 69 64 2a (u32,void*,void*
ca60: 2c 76 6f 69 64 2a 29 3b 20 20 20 20 20 2f 2a 20 ,void*); /*
ca70: 54 72 61 63 65 20 66 75 6e 63 74 69 6f 6e 20 2a Trace function *
ca80: 2f 0a 20 20 76 6f 69 64 20 2a 70 54 72 61 63 65 /. void *pTrace
ca90: 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 Arg;
caa0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
cab0: 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 Argument to the
cac0: 20 74 72 61 63 65 20 66 75 6e 63 74 69 6f 6e 20 trace function
cad0: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
cae0: 45 5f 4f 4d 49 54 5f 44 45 50 52 45 43 41 54 45 E_OMIT_DEPRECATE
caf0: 44 0a 20 20 76 6f 69 64 20 28 2a 78 50 72 6f 66 D. void (*xProf
cb00: 69 6c 65 29 28 76 6f 69 64 2a 2c 63 6f 6e 73 74 ile)(void*,const
cb10: 20 63 68 61 72 2a 2c 75 36 34 29 3b 20 20 2f 2a char*,u64); /*
cb20: 20 50 72 6f 66 69 6c 69 6e 67 20 66 75 6e 63 74 Profiling funct
cb30: 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ion */. void *p
cb40: 50 72 6f 66 69 6c 65 41 72 67 3b 20 20 20 20 20 ProfileArg;
cb50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cb60: 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 /* Argument t
cb70: 6f 20 70 72 6f 66 69 6c 65 20 66 75 6e 63 74 69 o profile functi
cb80: 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 76 on */.#endif. v
cb90: 6f 69 64 20 2a 70 43 6f 6d 6d 69 74 41 72 67 3b oid *pCommitArg;
cba0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cbb0: 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 /* Argument to
cbc0: 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 63 6b 28 xCommitCallback(
cbd0: 29 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 43 6f ) */. int (*xCo
cbe0: 6d 6d 69 74 43 61 6c 6c 62 61 63 6b 29 28 76 6f mmitCallback)(vo
cbf0: 69 64 2a 29 3b 20 20 20 20 2f 2a 20 49 6e 76 6f id*); /* Invo
cc00: 6b 65 64 20 61 74 20 65 76 65 72 79 20 63 6f 6d ked at every com
cc10: 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a mit. */. void *
cc20: 70 52 6f 6c 6c 62 61 63 6b 41 72 67 3b 20 20 20 pRollbackArg;
cc30: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 /* A
cc40: 72 67 75 6d 65 6e 74 20 74 6f 20 78 52 6f 6c 6c rgument to xRoll
cc50: 62 61 63 6b 43 61 6c 6c 62 61 63 6b 28 29 20 2a backCallback() *
cc60: 2f 0a 20 20 76 6f 69 64 20 28 2a 78 52 6f 6c 6c /. void (*xRoll
cc70: 62 61 63 6b 43 61 6c 6c 62 61 63 6b 29 28 76 6f backCallback)(vo
cc80: 69 64 2a 29 3b 20 2f 2a 20 49 6e 76 6f 6b 65 64 id*); /* Invoked
cc90: 20 61 74 20 65 76 65 72 79 20 63 6f 6d 6d 69 74 at every commit
cca0: 2e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 70 . */. void *pUp
ccb0: 64 61 74 65 41 72 67 3b 0a 20 20 76 6f 69 64 20 dateArg;. void
ccc0: 28 2a 78 55 70 64 61 74 65 43 61 6c 6c 62 61 63 (*xUpdateCallbac
ccd0: 6b 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f k)(void*,int, co
cce0: 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 nst char*,const
ccf0: 63 68 61 72 2a 2c 73 71 6c 69 74 65 5f 69 6e 74 char*,sqlite_int
cd00: 36 34 29 3b 0a 20 20 50 61 72 73 65 20 2a 70 50 64);. Parse *pP
cd10: 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 20 arse;
cd20: 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 /* Current
cd30: 70 61 72 73 65 20 2a 2f 0a 23 69 66 64 65 66 20 parse */.#ifdef
cd40: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 SQLITE_ENABLE_PR
cd50: 45 55 50 44 41 54 45 5f 48 4f 4f 4b 0a 20 20 76 EUPDATE_HOOK. v
cd60: 6f 69 64 20 2a 70 50 72 65 55 70 64 61 74 65 41 oid *pPreUpdateA
cd70: 72 67 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 rg; /*
cd80: 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 First argument t
cd90: 6f 20 78 50 72 65 55 70 64 61 74 65 43 61 6c 6c o xPreUpdateCall
cda0: 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 28 back */. void (
cdb0: 2a 78 50 72 65 55 70 64 61 74 65 43 61 6c 6c 62 *xPreUpdateCallb
cdc0: 61 63 6b 29 28 20 20 20 2f 2a 20 52 65 67 69 73 ack)( /* Regis
cdd0: 74 65 72 65 64 20 75 73 69 6e 67 20 73 71 6c 69 tered using sqli
cde0: 74 65 33 5f 70 72 65 75 70 64 61 74 65 5f 68 6f te3_preupdate_ho
cdf0: 6f 6b 28 29 20 2a 2f 0a 20 20 20 20 76 6f 69 64 ok() */. void
ce00: 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 *,sqlite3*,int,c
ce10: 68 61 72 20 63 6f 6e 73 74 2a 2c 63 68 61 72 20 har const*,char
ce20: 63 6f 6e 73 74 2a 2c 73 71 6c 69 74 65 33 5f 69 const*,sqlite3_i
ce30: 6e 74 36 34 2c 73 71 6c 69 74 65 33 5f 69 6e 74 nt64,sqlite3_int
ce40: 36 34 0a 20 20 29 3b 0a 20 20 50 72 65 55 70 64 64. );. PreUpd
ce50: 61 74 65 20 2a 70 50 72 65 55 70 64 61 74 65 3b ate *pPreUpdate;
ce60: 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 74 65 /* Conte
ce70: 78 74 20 66 6f 72 20 61 63 74 69 76 65 20 70 72 xt for active pr
ce80: 65 2d 75 70 64 61 74 65 20 63 61 6c 6c 62 61 63 e-update callbac
ce90: 6b 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a 20 53 k */.#endif /* S
cea0: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 45 QLITE_ENABLE_PRE
ceb0: 55 50 44 41 54 45 5f 48 4f 4f 4b 20 2a 2f 0a 23 UPDATE_HOOK */.#
cec0: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
ced0: 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 28 2a 78 IT_WAL. int (*x
cee0: 57 61 6c 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 WalCallback)(voi
cef0: 64 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a 2c 20 d *, sqlite3 *,
cf00: 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e const char *, in
cf10: 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 57 61 6c t);. void *pWal
cf20: 41 72 67 3b 0a 23 65 6e 64 69 66 0a 20 20 76 6f Arg;.#endif. vo
cf30: 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 29 id(*xCollNeeded)
cf40: 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c (void*,sqlite3*,
cf50: 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 6f 6e int eTextRep,con
cf60: 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 st char*);. voi
cf70: 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 31 36 d(*xCollNeeded16
cf80: 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a )(void*,sqlite3*
cf90: 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 6f ,int eTextRep,co
cfa0: 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f nst void*);. vo
cfb0: 69 64 20 2a 70 43 6f 6c 6c 4e 65 65 64 65 64 41 id *pCollNeededA
cfc0: 72 67 3b 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 rg;. sqlite3_va
cfd0: 6c 75 65 20 2a 70 45 72 72 3b 20 20 20 20 20 20 lue *pErr;
cfe0: 20 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 63 65 /* Most rece
cff0: 6e 74 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 nt error message
d000: 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 */. union {.
d010: 20 20 76 6f 6c 61 74 69 6c 65 20 69 6e 74 20 69 volatile int i
d020: 73 49 6e 74 65 72 72 75 70 74 65 64 3b 20 2f 2a sInterrupted; /*
d030: 20 54 72 75 65 20 69 66 20 73 71 6c 69 74 65 33 True if sqlite3
d040: 5f 69 6e 74 65 72 72 75 70 74 20 68 61 73 20 62 _interrupt has b
d050: 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 een called */.
d060: 20 20 64 6f 75 62 6c 65 20 6e 6f 74 55 73 65 64 double notUsed
d070: 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 1; /*
d080: 20 53 70 61 63 65 72 20 2a 2f 0a 20 20 7d 20 75 Spacer */. } u
d090: 31 3b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 20 6c 1;. Lookaside l
d0a0: 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 20 20 ookaside;
d0b0: 20 20 20 2f 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 /* Lookaside
d0c0: 6d 61 6c 6c 6f 63 20 63 6f 6e 66 69 67 75 72 61 malloc configura
d0d0: 74 69 6f 6e 20 2a 2f 0a 23 69 66 6e 64 65 66 20 tion */.#ifndef
d0e0: 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 54 48 SQLITE_OMIT_AUTH
d0f0: 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 73 71 6c 69 ORIZATION. sqli
d100: 74 65 33 5f 78 61 75 74 68 20 78 41 75 74 68 3b te3_xauth xAuth;
d110: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 63 63 /* Acc
d120: 65 73 73 20 61 75 74 68 6f 72 69 7a 61 74 69 6f ess authorizatio
d130: 6e 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 n function */.
d140: 76 6f 69 64 20 2a 70 41 75 74 68 41 72 67 3b 20 void *pAuthArg;
d150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
d160: 20 31 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 1st argument to
d170: 20 74 68 65 20 61 63 63 65 73 73 20 61 75 74 68 the access auth
d180: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 65 6e function */.#en
d190: 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 dif.#ifndef SQLI
d1a0: 54 45 5f 4f 4d 49 54 5f 50 52 4f 47 52 45 53 53 TE_OMIT_PROGRESS
d1b0: 5f 43 41 4c 4c 42 41 43 4b 0a 20 20 69 6e 74 20 _CALLBACK. int
d1c0: 28 2a 78 50 72 6f 67 72 65 73 73 29 28 76 6f 69 (*xProgress)(voi
d1d0: 64 20 2a 29 3b 20 20 20 20 20 2f 2a 20 54 68 65 d *); /* The
d1e0: 20 70 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 progress callba
d1f0: 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 ck */. void *pP
d200: 72 6f 67 72 65 73 73 41 72 67 3b 20 20 20 20 20 rogressArg;
d210: 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e /* Argumen
d220: 74 20 74 6f 20 74 68 65 20 70 72 6f 67 72 65 73 t to the progres
d230: 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 s callback */.
d240: 75 6e 73 69 67 6e 65 64 20 6e 50 72 6f 67 72 65 unsigned nProgre
d250: 73 73 4f 70 73 3b 20 20 20 20 20 20 20 20 2f 2a ssOps; /*
d260: 20 4e 75 6d 62 65 72 20 6f 66 20 6f 70 63 6f 64 Number of opcod
d270: 65 73 20 66 6f 72 20 70 72 6f 67 72 65 73 73 20 es for progress
d280: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e 64 callback */.#end
d290: 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
d2a0: 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 E_OMIT_VIRTUALTA
d2b0: 42 4c 45 0a 20 20 69 6e 74 20 6e 56 54 72 61 6e BLE. int nVTran
d2c0: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 s;
d2d0: 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 64 /* Allocated
d2e0: 20 73 69 7a 65 20 6f 66 20 61 56 54 72 61 6e 73 size of aVTrans
d2f0: 20 2a 2f 0a 20 20 48 61 73 68 20 61 4d 6f 64 75 */. Hash aModu
d300: 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 le;
d310: 20 20 20 20 2f 2a 20 70 6f 70 75 6c 61 74 65 64 /* populated
d320: 20 62 79 20 73 71 6c 69 74 65 33 5f 63 72 65 61 by sqlite3_crea
d330: 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 te_module() */.
d340: 20 56 74 61 62 43 74 78 20 2a 70 56 74 61 62 43 VtabCtx *pVtabC
d350: 74 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f tx; /
d360: 2a 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 61 63 * Context for ac
d370: 74 69 76 65 20 76 74 61 62 20 63 6f 6e 6e 65 63 tive vtab connec
d380: 74 2f 63 72 65 61 74 65 20 2a 2f 0a 20 20 56 54 t/create */. VT
d390: 61 62 6c 65 20 2a 2a 61 56 54 72 61 6e 73 3b 20 able **aVTrans;
d3a0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 /* V
d3b0: 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 77 69 irtual tables wi
d3c0: 74 68 20 6f 70 65 6e 20 74 72 61 6e 73 61 63 74 th open transact
d3d0: 69 6f 6e 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 ions */. VTable
d3e0: 20 2a 70 44 69 73 63 6f 6e 6e 65 63 74 3b 20 20 *pDisconnect;
d3f0: 20 20 20 20 20 20 20 20 2f 2a 20 44 69 73 63 6f /* Disco
d400: 6e 6e 65 63 74 20 74 68 65 73 65 20 69 6e 20 6e nnect these in n
d410: 65 78 74 20 73 71 6c 69 74 65 33 5f 70 72 65 70 ext sqlite3_prep
d420: 61 72 65 28 29 20 2a 2f 0a 23 65 6e 64 69 66 0a are() */.#endif.
d430: 20 20 48 61 73 68 20 61 46 75 6e 63 3b 20 20 20 Hash aFunc;
d440: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d450: 2f 2a 20 48 61 73 68 20 74 61 62 6c 65 20 6f 66 /* Hash table of
d460: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 66 75 6e 63 connection func
d470: 74 69 6f 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 tions */. Hash
d480: 61 43 6f 6c 6c 53 65 71 3b 20 20 20 20 20 20 20 aCollSeq;
d490: 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 /* All
d4a0: 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e collating sequen
d4b0: 63 65 73 20 2a 2f 0a 20 20 42 75 73 79 48 61 6e ces */. BusyHan
d4c0: 64 6c 65 72 20 62 75 73 79 48 61 6e 64 6c 65 72 dler busyHandler
d4d0: 3b 20 20 20 20 20 20 2f 2a 20 42 75 73 79 20 63 ; /* Busy c
d4e0: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 44 62 20 allback */. Db
d4f0: 61 44 62 53 74 61 74 69 63 5b 32 5d 3b 20 20 20 aDbStatic[2];
d500: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 /* St
d510: 61 74 69 63 20 73 70 61 63 65 20 66 6f 72 20 74 atic space for t
d520: 68 65 20 32 20 64 65 66 61 75 6c 74 20 62 61 63 he 2 default bac
d530: 6b 65 6e 64 73 20 2a 2f 0a 20 20 53 61 76 65 70 kends */. Savep
d540: 6f 69 6e 74 20 2a 70 53 61 76 65 70 6f 69 6e 74 oint *pSavepoint
d550: 3b 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 ; /* List
d560: 20 6f 66 20 61 63 74 69 76 65 20 73 61 76 65 70 of active savep
d570: 6f 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 62 oints */. int b
d580: 75 73 79 54 69 6d 65 6f 75 74 3b 20 20 20 20 20 usyTimeout;
d590: 20 20 20 20 20 20 20 20 20 2f 2a 20 42 75 73 79 /* Busy
d5a0: 20 68 61 6e 64 6c 65 72 20 74 69 6d 65 6f 75 74 handler timeout
d5b0: 2c 20 69 6e 20 6d 73 65 63 20 2a 2f 0a 20 20 69 , in msec */. i
d5c0: 6e 74 20 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 nt nSavepoint;
d5d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
d5e0: 4e 75 6d 62 65 72 20 6f 66 20 6e 6f 6e 2d 74 72 Number of non-tr
d5f0: 61 6e 73 61 63 74 69 6f 6e 20 73 61 76 65 70 6f ansaction savepo
d600: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 ints */. int nS
d610: 74 61 74 65 6d 65 6e 74 3b 20 20 20 20 20 20 20 tatement;
d620: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
d630: 72 20 6f 66 20 6e 65 73 74 65 64 20 73 74 61 74 r of nested stat
d640: 65 6d 65 6e 74 2d 74 72 61 6e 73 61 63 74 69 6f ement-transactio
d650: 6e 73 20 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 ns */. i64 nDe
d660: 66 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 ferredCons;
d670: 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 /* Net de
d680: 66 65 72 72 65 64 20 63 6f 6e 73 74 72 61 69 6e ferred constrain
d690: 74 73 20 74 68 69 73 20 74 72 61 6e 73 61 63 74 ts this transact
d6a0: 69 6f 6e 2e 20 2a 2f 0a 20 20 69 36 34 20 6e 44 ion. */. i64 nD
d6b0: 65 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 eferredImmCons;
d6c0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 64 /* Net d
d6d0: 65 66 65 72 72 65 64 20 69 6d 6d 65 64 69 61 74 eferred immediat
d6e0: 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f e constraints */
d6f0: 0a 20 20 69 6e 74 20 2a 70 6e 42 79 74 65 73 46 . int *pnBytesF
d700: 72 65 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 reed;
d710: 20 2f 2a 20 49 66 20 6e 6f 74 20 4e 55 4c 4c 2c /* If not NULL,
d720: 20 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 73 20 increment this
d730: 69 6e 20 44 62 46 72 65 65 28 29 20 2a 2f 0a 23 in DbFree() */.#
d740: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
d750: 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 BLE_UNLOCK_NOTIF
d760: 59 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f Y. /* The follo
d770: 77 69 6e 67 20 76 61 72 69 61 62 6c 65 73 20 61 wing variables a
d780: 72 65 20 61 6c 6c 20 70 72 6f 74 65 63 74 65 64 re all protected
d790: 20 62 79 20 74 68 65 20 53 54 41 54 49 43 5f 4d by the STATIC_M
d7a0: 41 53 54 45 52 0a 20 20 2a 2a 20 6d 75 74 65 78 ASTER. ** mutex
d7b0: 2c 20 6e 6f 74 20 62 79 20 73 71 6c 69 74 65 33 , not by sqlite3
d7c0: 2e 6d 75 74 65 78 2e 20 54 68 65 79 20 61 72 65 .mutex. They are
d7d0: 20 75 73 65 64 20 62 79 20 63 6f 64 65 20 69 6e used by code in
d7e0: 20 6e 6f 74 69 66 79 2e 63 2e 0a 20 20 2a 2a 0a notify.c.. **.
d7f0: 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 55 6e 6c ** When X.pUnl
d800: 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 ockConnection==Y
d810: 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 68 61 , that means tha
d820: 74 20 58 20 69 73 20 77 61 69 74 69 6e 67 20 66 t X is waiting f
d830: 6f 72 20 59 20 74 6f 0a 20 20 2a 2a 20 75 6e 6c or Y to. ** unl
d840: 6f 63 6b 20 73 6f 20 74 68 61 74 20 69 74 20 63 ock so that it c
d850: 61 6e 20 70 72 6f 63 65 65 64 2e 0a 20 20 2a 2a an proceed.. **
d860: 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 42 6c . ** When X.pBl
d870: 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 6f 6e ockingConnection
d880: 3d 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 ==Y, that means
d890: 74 68 61 74 20 73 6f 6d 65 74 68 69 6e 67 20 74 that something t
d8a0: 68 61 74 20 58 20 74 72 69 65 64 0a 20 20 2a 2a hat X tried. **
d8b0: 20 74 72 69 65 64 20 74 6f 20 64 6f 20 72 65 63 tried to do rec
d8c0: 65 6e 74 6c 79 20 66 61 69 6c 65 64 20 77 69 74 ently failed wit
d8d0: 68 20 61 6e 20 53 51 4c 49 54 45 5f 4c 4f 43 4b h an SQLITE_LOCK
d8e0: 45 44 20 65 72 72 6f 72 20 64 75 65 20 74 6f 20 ED error due to
d8f0: 6c 6f 63 6b 73 0a 20 20 2a 2a 20 68 65 6c 64 20 locks. ** held
d900: 62 79 20 59 2e 0a 20 20 2a 2f 0a 20 20 73 71 6c by Y.. */. sql
d910: 69 74 65 33 20 2a 70 42 6c 6f 63 6b 69 6e 67 43 ite3 *pBlockingC
d920: 6f 6e 6e 65 63 74 69 6f 6e 3b 20 2f 2a 20 43 6f onnection; /* Co
d930: 6e 6e 65 63 74 69 6f 6e 20 74 68 61 74 20 63 61 nnection that ca
d940: 75 73 65 64 20 53 51 4c 49 54 45 5f 4c 4f 43 4b used SQLITE_LOCK
d950: 45 44 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 ED */. sqlite3
d960: 2a 70 55 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 *pUnlockConnecti
d970: 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a on; /*
d980: 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f 20 77 Connection to w
d990: 61 74 63 68 20 66 6f 72 20 75 6e 6c 6f 63 6b 20 atch for unlock
d9a0: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 6e 6c 6f */. void *pUnlo
d9b0: 63 6b 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 ckArg;
d9c0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
d9d0: 67 75 6d 65 6e 74 20 74 6f 20 78 55 6e 6c 6f 63 gument to xUnloc
d9e0: 6b 4e 6f 74 69 66 79 20 2a 2f 0a 20 20 76 6f 69 kNotify */. voi
d9f0: 64 20 28 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 d (*xUnlockNotif
da00: 79 29 28 76 6f 69 64 20 2a 2a 2c 20 69 6e 74 29 y)(void **, int)
da10: 3b 20 20 2f 2a 20 55 6e 6c 6f 63 6b 20 6e 6f 74 ; /* Unlock not
da20: 69 66 79 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a ify callback */.
da30: 20 20 73 71 6c 69 74 65 33 20 2a 70 4e 65 78 74 sqlite3 *pNext
da40: 42 6c 6f 63 6b 65 64 3b 20 20 20 20 20 20 20 20 Blocked;
da50: 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 73 74 20 /* Next in list
da60: 6f 66 20 61 6c 6c 20 62 6c 6f 63 6b 65 64 20 63 of all blocked c
da70: 6f 6e 6e 65 63 74 69 6f 6e 73 20 2a 2f 0a 23 65 onnections */.#e
da80: 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c 49 ndif.#ifdef SQLI
da90: 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 49 TE_USER_AUTHENTI
daa0: 43 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 65 33 CATION. sqlite3
dab0: 5f 75 73 65 72 61 75 74 68 20 61 75 74 68 3b 20 _userauth auth;
dac0: 20 20 20 20 20 20 20 2f 2a 20 55 73 65 72 20 61 /* User a
dad0: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 69 6e uthentication in
dae0: 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 23 65 6e formation */.#en
daf0: 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 dif.};../*.** A
db00: 6d 61 63 72 6f 20 74 6f 20 64 69 73 63 6f 76 65 macro to discove
db10: 72 20 74 68 65 20 65 6e 63 6f 64 69 6e 67 20 6f r the encoding o
db20: 66 20 61 20 64 61 74 61 62 61 73 65 2e 0a 2a 2f f a database..*/
db30: 0a 23 64 65 66 69 6e 65 20 53 43 48 45 4d 41 5f .#define SCHEMA_
db40: 45 4e 43 28 64 62 29 20 28 28 64 62 29 2d 3e 61 ENC(db) ((db)->a
db50: 44 62 5b 30 5d 2e 70 53 63 68 65 6d 61 2d 3e 65 Db[0].pSchema->e
db60: 6e 63 29 0a 23 64 65 66 69 6e 65 20 45 4e 43 28 nc).#define ENC(
db70: 64 62 29 20 20 20 20 20 20 20 20 28 28 64 62 29 db) ((db)
db80: 2d 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f ->enc)../*.** Po
db90: 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f ssible values fo
dba0: 72 20 74 68 65 20 73 71 6c 69 74 65 33 2e 66 6c r the sqlite3.fl
dbb0: 61 67 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 ags..**.** Value
dbc0: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 65 6e constraints (en
dbd0: 66 6f 72 63 65 64 20 76 69 61 20 61 73 73 65 72 forced via asser
dbe0: 74 28 29 29 3a 0a 2a 2a 20 20 20 20 20 20 53 51 t()):.** SQ
dbf0: 4c 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 20 20 LITE_FullFSync
dc00: 20 20 20 3d 3d 20 50 41 47 45 52 5f 46 55 4c 4c == PAGER_FULL
dc10: 46 53 59 4e 43 0a 2a 2a 20 20 20 20 20 20 53 51 FSYNC.** SQ
dc20: 4c 49 54 45 5f 43 6b 70 74 46 75 6c 6c 46 53 79 LITE_CkptFullFSy
dc30: 6e 63 20 3d 3d 20 50 41 47 45 52 5f 43 4b 50 54 nc == PAGER_CKPT
dc40: 5f 46 55 4c 4c 46 53 59 4e 43 0a 2a 2a 20 20 20 _FULLFSYNC.**
dc50: 20 20 20 53 51 4c 49 54 45 5f 43 61 63 68 65 53 SQLITE_CacheS
dc60: 70 69 6c 6c 20 20 20 20 3d 3d 20 50 41 47 45 52 pill == PAGER
dc70: 5f 43 41 43 48 45 5f 53 50 49 4c 4c 0a 2a 2f 0a _CACHE_SPILL.*/.
dc80: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 #define SQLITE_W
dc90: 72 69 74 65 53 63 68 65 6d 61 20 20 20 20 30 78 riteSchema 0x
dca0: 30 30 30 30 30 30 30 31 20 20 2f 2a 20 4f 4b 20 00000001 /* OK
dcb0: 74 6f 20 75 70 64 61 74 65 20 53 51 4c 49 54 45 to update SQLITE
dcc0: 5f 4d 41 53 54 45 52 20 2a 2f 0a 23 64 65 66 69 _MASTER */.#defi
dcd0: 6e 65 20 53 51 4c 49 54 45 5f 4c 65 67 61 63 79 ne SQLITE_Legacy
dce0: 46 69 6c 65 46 6d 74 20 20 30 78 30 30 30 30 30 FileFmt 0x00000
dcf0: 30 30 32 20 20 2f 2a 20 43 72 65 61 74 65 20 6e 002 /* Create n
dd00: 65 77 20 64 61 74 61 62 61 73 65 73 20 69 6e 20 ew databases in
dd10: 66 6f 72 6d 61 74 20 31 20 2a 2f 0a 23 64 65 66 format 1 */.#def
dd20: 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c 43 ine SQLITE_FullC
dd30: 6f 6c 4e 61 6d 65 73 20 20 20 30 78 30 30 30 30 olNames 0x0000
dd40: 30 30 30 34 20 20 2f 2a 20 53 68 6f 77 20 66 75 0004 /* Show fu
dd50: 6c 6c 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 ll column names
dd60: 6f 6e 20 53 45 4c 45 43 54 20 2a 2f 0a 23 64 65 on SELECT */.#de
dd70: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c 6c fine SQLITE_Full
dd80: 46 53 79 6e 63 20 20 20 20 20 20 30 78 30 30 30 FSync 0x000
dd90: 30 30 30 30 38 20 20 2f 2a 20 55 73 65 20 66 75 00008 /* Use fu
dda0: 6c 6c 20 66 73 79 6e 63 20 6f 6e 20 74 68 65 20 ll fsync on the
ddb0: 62 61 63 6b 65 6e 64 20 2a 2f 0a 23 64 65 66 69 backend */.#defi
ddc0: 6e 65 20 53 51 4c 49 54 45 5f 43 6b 70 74 46 75 ne SQLITE_CkptFu
ddd0: 6c 6c 46 53 79 6e 63 20 20 30 78 30 30 30 30 30 llFSync 0x00000
dde0: 30 31 30 20 20 2f 2a 20 55 73 65 20 66 75 6c 6c 010 /* Use full
ddf0: 20 66 73 79 6e 63 20 66 6f 72 20 63 68 65 63 6b fsync for check
de00: 70 6f 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 point */.#define
de10: 20 53 51 4c 49 54 45 5f 43 61 63 68 65 53 70 69 SQLITE_CacheSpi
de20: 6c 6c 20 20 20 20 20 30 78 30 30 30 30 30 30 32 ll 0x0000002
de30: 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 73 70 69 6c 0 /* OK to spil
de40: 6c 20 70 61 67 65 72 20 63 61 63 68 65 20 2a 2f l pager cache */
de50: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
de60: 53 68 6f 72 74 43 6f 6c 4e 61 6d 65 73 20 20 30 ShortColNames 0
de70: 78 30 30 30 30 30 30 34 30 20 20 2f 2a 20 53 68 x00000040 /* Sh
de80: 6f 77 20 73 68 6f 72 74 20 63 6f 6c 75 6d 6e 73 ow short columns
de90: 20 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 6e names */.#defin
dea0: 65 20 53 51 4c 49 54 45 5f 43 6f 75 6e 74 52 6f e SQLITE_CountRo
deb0: 77 73 20 20 20 20 20 20 30 78 30 30 30 30 30 30 ws 0x000000
dec0: 38 30 20 20 2f 2a 20 43 6f 75 6e 74 20 72 6f 77 80 /* Count row
ded0: 73 20 63 68 61 6e 67 65 64 20 62 79 20 49 4e 53 s changed by INS
dee0: 45 52 54 2c 20 2a 2f 0a 20 20 20 20 20 20 20 20 ERT, */.
def0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
df00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
df10: 20 20 2f 2a 20 20 20 44 45 4c 45 54 45 2c 20 6f /* DELETE, o
df20: 72 20 55 50 44 41 54 45 20 61 6e 64 20 72 65 74 r UPDATE and ret
df30: 75 72 6e 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 urn */.
df40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
df50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
df60: 20 2f 2a 20 20 20 74 68 65 20 63 6f 75 6e 74 20 /* the count
df70: 75 73 69 6e 67 20 61 20 63 61 6c 6c 62 61 63 6b using a callback
df80: 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c . */.#define SQL
df90: 49 54 45 5f 4e 75 6c 6c 43 61 6c 6c 62 61 63 6b ITE_NullCallback
dfa0: 20 20 20 30 78 30 30 30 30 30 31 30 30 20 20 2f 0x00000100 /
dfb0: 2a 20 49 6e 76 6f 6b 65 20 74 68 65 20 63 61 6c * Invoke the cal
dfc0: 6c 62 61 63 6b 20 6f 6e 63 65 20 69 66 20 74 68 lback once if th
dfd0: 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 e */.
dfe0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
dff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
e000: 2a 20 20 20 72 65 73 75 6c 74 20 73 65 74 20 69 * result set i
e010: 73 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 69 s empty */.#defi
e020: 6e 65 20 53 51 4c 49 54 45 5f 49 67 6e 6f 72 65 ne SQLITE_Ignore
e030: 43 68 65 63 6b 73 20 20 20 30 78 30 30 30 30 30 Checks 0x00000
e040: 32 30 30 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 65 200 /* Do not e
e050: 6e 66 6f 72 63 65 20 63 68 65 63 6b 20 63 6f 6e nforce check con
e060: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 66 straints */.#def
e070: 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 61 64 55 ine SQLITE_ReadU
e080: 6e 63 6f 6d 6d 69 74 20 20 20 30 78 30 30 30 30 ncommit 0x0000
e090: 30 34 30 30 20 20 2f 2a 20 52 45 41 44 20 55 4e 0400 /* READ UN
e0a0: 43 4f 4d 4d 49 54 54 45 44 20 69 6e 20 73 68 61 COMMITTED in sha
e0b0: 72 65 64 2d 63 61 63 68 65 20 2a 2f 0a 23 64 65 red-cache */.#de
e0c0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 6f 43 6b fine SQLITE_NoCk
e0d0: 70 74 4f 6e 43 6c 6f 73 65 20 20 30 78 30 30 30 ptOnClose 0x000
e0e0: 30 30 38 30 30 20 20 2f 2a 20 4e 6f 20 63 68 65 00800 /* No che
e0f0: 63 6b 70 6f 69 6e 74 20 6f 6e 20 63 6c 6f 73 65 ckpoint on close
e100: 28 29 2f 44 45 54 41 43 48 20 2a 2f 0a 23 64 65 ()/DETACH */.#de
e110: 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 76 65 fine SQLITE_Reve
e120: 72 73 65 4f 72 64 65 72 20 20 20 30 78 30 30 30 rseOrder 0x000
e130: 30 31 30 30 30 20 20 2f 2a 20 52 65 76 65 72 73 01000 /* Revers
e140: 65 20 75 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 e unordered SELE
e150: 43 54 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 CTs */.#define S
e160: 51 4c 49 54 45 5f 52 65 63 54 72 69 67 67 65 72 QLITE_RecTrigger
e170: 73 20 20 20 20 30 78 30 30 30 30 32 30 30 30 20 s 0x00002000
e180: 20 2f 2a 20 45 6e 61 62 6c 65 20 72 65 63 75 72 /* Enable recur
e190: 73 69 76 65 20 74 72 69 67 67 65 72 73 20 2a 2f sive triggers */
e1a0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
e1b0: 46 6f 72 65 69 67 6e 4b 65 79 73 20 20 20 20 30 ForeignKeys 0
e1c0: 78 30 30 30 30 34 30 30 30 20 20 2f 2a 20 45 6e x00004000 /* En
e1d0: 66 6f 72 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 force foreign ke
e1e0: 79 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a y constraints *
e1f0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e200: 5f 41 75 74 6f 49 6e 64 65 78 20 20 20 20 20 20 _AutoIndex
e210: 30 78 30 30 30 30 38 30 30 30 20 20 2f 2a 20 45 0x00008000 /* E
e220: 6e 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 nable automatic
e230: 69 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 indexes */.#defi
e240: 6e 65 20 53 51 4c 49 54 45 5f 4c 6f 61 64 45 78 ne SQLITE_LoadEx
e250: 74 65 6e 73 69 6f 6e 20 20 30 78 30 30 30 31 30 tension 0x00010
e260: 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 6c 000 /* Enable l
e270: 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e 20 2a 2f oad_extension */
e280: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
e290: 4c 6f 61 64 45 78 74 46 75 6e 63 20 20 20 20 30 LoadExtFunc 0
e2a0: 78 30 30 30 32 30 30 30 30 20 20 2f 2a 20 45 6e x00020000 /* En
e2b0: 61 62 6c 65 20 6c 6f 61 64 5f 65 78 74 65 6e 73 able load_extens
e2c0: 69 6f 6e 28 29 20 53 51 4c 20 66 75 6e 63 20 2a ion() SQL func *
e2d0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e2e0: 5f 45 6e 61 62 6c 65 54 72 69 67 67 65 72 20 20 _EnableTrigger
e2f0: 30 78 30 30 30 34 30 30 30 30 20 20 2f 2a 20 54 0x00040000 /* T
e300: 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 74 72 rue to enable tr
e310: 69 67 67 65 72 73 20 2a 2f 0a 23 64 65 66 69 6e iggers */.#defin
e320: 65 20 53 51 4c 49 54 45 5f 44 65 66 65 72 46 4b e SQLITE_DeferFK
e330: 73 20 20 20 20 20 20 20 30 78 30 30 30 38 30 30 s 0x000800
e340: 30 30 20 20 2f 2a 20 44 65 66 65 72 20 61 6c 6c 00 /* Defer all
e350: 20 46 4b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 FK constraints
e360: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e370: 45 5f 51 75 65 72 79 4f 6e 6c 79 20 20 20 20 20 E_QueryOnly
e380: 20 30 78 30 30 31 30 30 30 30 30 20 20 2f 2a 20 0x00100000 /*
e390: 44 69 73 61 62 6c 65 20 64 61 74 61 62 61 73 65 Disable database
e3a0: 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 65 66 changes */.#def
e3b0: 69 6e 65 20 53 51 4c 49 54 45 5f 43 65 6c 6c 53 ine SQLITE_CellS
e3c0: 69 7a 65 43 6b 20 20 20 20 20 30 78 30 30 32 30 izeCk 0x0020
e3d0: 30 30 30 30 20 20 2f 2a 20 43 68 65 63 6b 20 62 0000 /* Check b
e3e0: 74 72 65 65 20 63 65 6c 6c 20 73 69 7a 65 73 20 tree cell sizes
e3f0: 6f 6e 20 6c 6f 61 64 20 2a 2f 0a 23 64 65 66 69 on load */.#defi
e400: 6e 65 20 53 51 4c 49 54 45 5f 46 74 73 33 54 6f ne SQLITE_Fts3To
e410: 6b 65 6e 69 7a 65 72 20 20 30 78 30 30 34 30 30 kenizer 0x00400
e420: 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 20 66 000 /* Enable f
e430: 74 73 33 5f 74 6f 6b 65 6e 69 7a 65 72 28 32 29 ts3_tokenizer(2)
e440: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
e450: 54 45 5f 45 6e 61 62 6c 65 51 50 53 47 20 20 20 TE_EnableQPSG
e460: 20 20 30 78 30 30 38 30 30 30 30 30 20 20 2f 2a 0x00800000 /*
e470: 20 51 75 65 72 79 20 50 6c 61 6e 6e 65 72 20 53 Query Planner S
e480: 74 61 62 69 6c 69 74 79 20 47 75 61 72 61 6e 74 tability Guarant
e490: 65 65 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ee*/.#define SQL
e4a0: 49 54 45 5f 54 72 69 67 67 65 72 45 51 50 20 20 ITE_TriggerEQP
e4b0: 20 20 20 30 78 30 31 30 30 30 30 30 30 20 20 2f 0x01000000 /
e4c0: 2a 20 53 68 6f 77 20 74 72 69 67 67 65 72 20 45 * Show trigger E
e4d0: 58 50 4c 41 49 4e 20 51 55 45 52 59 20 50 4c 41 XPLAIN QUERY PLA
e4e0: 4e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c N */.#define SQL
e4f0: 49 54 45 5f 52 65 73 65 74 44 61 74 61 62 61 73 ITE_ResetDatabas
e500: 65 20 20 30 78 30 32 30 30 30 30 30 30 20 20 2f e 0x02000000 /
e510: 2a 20 52 65 73 65 74 20 74 68 65 20 64 61 74 61 * Reset the data
e520: 62 61 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 base */.#define
e530: 53 51 4c 49 54 45 5f 4c 65 67 61 63 79 41 6c 74 SQLITE_LegacyAlt
e540: 65 72 20 20 20 20 30 78 30 34 30 30 30 30 30 30 er 0x04000000
e550: 20 20 2f 2a 20 4c 65 67 61 63 79 20 41 4c 54 45 /* Legacy ALTE
e560: 52 20 54 41 42 4c 45 20 62 65 68 61 76 69 6f 75 R TABLE behaviou
e570: 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c r */.#define SQL
e580: 49 54 45 5f 4e 6f 53 63 68 65 6d 61 45 72 72 6f ITE_NoSchemaErro
e590: 72 20 20 30 78 30 38 30 30 30 30 30 30 20 20 2f r 0x08000000 /
e5a0: 2a 20 44 6f 20 6e 6f 74 20 72 65 70 6f 72 74 20 * Do not report
e5b0: 73 63 68 65 6d 61 20 70 61 72 73 65 20 65 72 72 schema parse err
e5c0: 6f 72 73 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ors*/.#define SQ
e5d0: 4c 49 54 45 5f 44 65 66 65 6e 73 69 76 65 20 20 LITE_Defensive
e5e0: 20 20 20 20 30 78 31 30 30 30 30 30 30 30 20 20 0x10000000
e5f0: 2f 2a 20 49 6e 70 75 74 20 53 51 4c 20 69 73 20 /* Input SQL is
e600: 6c 69 6b 65 6c 79 20 68 6f 73 74 69 6c 65 20 2a likely hostile *
e610: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e620: 5f 44 71 73 44 44 4c 20 20 20 20 20 20 20 20 20 _DqsDDL
e630: 30 78 32 30 30 30 30 30 30 30 20 20 2f 2a 20 64 0x20000000 /* d
e640: 62 6c 2d 71 75 6f 74 65 64 20 73 74 72 69 6e 67 bl-quoted string
e650: 73 20 61 6c 6c 6f 77 65 64 20 69 6e 20 44 44 4c s allowed in DDL
e660: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e670: 45 5f 44 71 73 44 4d 4c 20 20 20 20 20 20 20 20 E_DqsDML
e680: 20 30 78 34 30 30 30 30 30 30 30 20 20 2f 2a 20 0x40000000 /*
e690: 64 62 6c 2d 71 75 6f 74 65 64 20 73 74 72 69 6e dbl-quoted strin
e6a0: 67 73 20 61 6c 6c 6f 77 65 64 20 69 6e 20 44 4d gs allowed in DM
e6b0: 4c 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 L*/.#define SQLI
e6c0: 54 45 5f 45 6e 61 62 6c 65 56 69 65 77 20 20 20 TE_EnableView
e6d0: 20 20 30 78 38 30 30 30 30 30 30 30 20 20 2f 2a 0x80000000 /*
e6e0: 20 45 6e 61 62 6c 65 20 74 68 65 20 75 73 65 20 Enable the use
e6f0: 6f 66 20 76 69 65 77 73 20 2a 2f 0a 0a 2f 2a 20 of views */../*
e700: 46 6c 61 67 73 20 75 73 65 64 20 6f 6e 6c 79 20 Flags used only
e710: 69 66 20 64 65 62 75 67 67 69 6e 67 20 2a 2f 0a if debugging */.
e720: 23 64 65 66 69 6e 65 20 48 49 28 58 29 20 20 28 #define HI(X) (
e730: 28 75 36 34 29 28 58 29 3c 3c 33 32 29 0a 23 69 (u64)(X)<<32).#i
e740: 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 fdef SQLITE_DEBU
e750: 47 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 G.#define SQLITE
e760: 5f 53 71 6c 54 72 61 63 65 20 20 20 20 20 20 20 _SqlTrace
e770: 48 49 28 30 78 30 31 30 30 30 30 30 29 20 2f 2a HI(0x0100000) /*
e780: 20 44 65 62 75 67 20 70 72 69 6e 74 20 53 51 4c Debug print SQL
e790: 20 61 73 20 69 74 20 65 78 65 63 75 74 65 73 20 as it executes
e7a0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
e7b0: 45 5f 56 64 62 65 4c 69 73 74 69 6e 67 20 20 20 E_VdbeListing
e7c0: 20 48 49 28 30 78 30 32 30 30 30 30 30 29 20 2f HI(0x0200000) /
e7d0: 2a 20 44 65 62 75 67 20 6c 69 73 74 69 6e 67 73 * Debug listings
e7e0: 20 6f 66 20 56 44 42 45 20 70 72 6f 67 73 20 2a of VDBE progs *
e7f0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e800: 5f 56 64 62 65 54 72 61 63 65 20 20 20 20 20 20 _VdbeTrace
e810: 48 49 28 30 78 30 34 30 30 30 30 30 29 20 2f 2a HI(0x0400000) /*
e820: 20 54 72 75 65 20 74 6f 20 74 72 61 63 65 20 56 True to trace V
e830: 44 42 45 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f DBE execution */
e840: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
e850: 56 64 62 65 41 64 64 6f 70 54 72 61 63 65 20 48 VdbeAddopTrace H
e860: 49 28 30 78 30 38 30 30 30 30 30 29 20 2f 2a 20 I(0x0800000) /*
e870: 54 72 61 63 65 20 73 71 6c 69 74 65 33 56 64 62 Trace sqlite3Vdb
e880: 65 41 64 64 4f 70 28 29 20 63 61 6c 6c 73 20 2a eAddOp() calls *
e890: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e8a0: 5f 56 64 62 65 45 51 50 20 20 20 20 20 20 20 20 _VdbeEQP
e8b0: 48 49 28 30 78 31 30 30 30 30 30 30 29 20 2f 2a HI(0x1000000) /*
e8c0: 20 44 65 62 75 67 20 45 58 50 4c 41 49 4e 20 51 Debug EXPLAIN Q
e8d0: 55 45 52 59 20 50 4c 41 4e 20 2a 2f 0a 23 64 65 UERY PLAN */.#de
e8e0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 61 72 73 fine SQLITE_Pars
e8f0: 65 72 54 72 61 63 65 20 20 20 20 48 49 28 30 78 erTrace HI(0x
e900: 32 30 30 30 30 30 30 29 20 2f 2a 20 50 52 41 47 2000000) /* PRAG
e910: 4d 41 20 70 61 72 73 65 72 5f 74 72 61 63 65 3d MA parser_trace=
e920: 4f 4e 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a ON */.#endif../*
e930: 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 .** Allowed valu
e940: 65 73 20 66 6f 72 20 73 71 6c 69 74 65 33 2e 6d es for sqlite3.m
e950: 44 62 46 6c 61 67 73 0a 2a 2f 0a 23 64 65 66 69 DbFlags.*/.#defi
e960: 6e 65 20 44 42 46 4c 41 47 5f 53 63 68 65 6d 61 ne DBFLAG_Schema
e970: 43 68 61 6e 67 65 20 20 20 30 78 30 30 30 31 20 Change 0x0001
e980: 20 2f 2a 20 55 6e 63 6f 6d 6d 69 74 74 65 64 20 /* Uncommitted
e990: 48 61 73 68 20 74 61 62 6c 65 20 63 68 61 6e 67 Hash table chang
e9a0: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 es */.#define DB
e9b0: 46 4c 41 47 5f 50 72 65 66 65 72 42 75 69 6c 74 FLAG_PreferBuilt
e9c0: 69 6e 20 20 30 78 30 30 30 32 20 20 2f 2a 20 50 in 0x0002 /* P
e9d0: 72 65 66 65 72 65 6e 63 65 20 74 6f 20 62 75 69 reference to bui
e9e0: 6c 74 2d 69 6e 20 66 75 6e 63 73 20 2a 2f 0a 23 lt-in funcs */.#
e9f0: 64 65 66 69 6e 65 20 44 42 46 4c 41 47 5f 56 61 define DBFLAG_Va
ea00: 63 75 75 6d 20 20 20 20 20 20 20 20 20 30 78 30 cuum 0x0
ea10: 30 30 34 20 20 2f 2a 20 43 75 72 72 65 6e 74 6c 004 /* Currentl
ea20: 79 20 69 6e 20 61 20 56 41 43 55 55 4d 20 2a 2f y in a VACUUM */
ea30: 0a 23 64 65 66 69 6e 65 20 44 42 46 4c 41 47 5f .#define DBFLAG_
ea40: 56 61 63 75 75 6d 49 6e 74 6f 20 20 20 20 20 30 VacuumInto 0
ea50: 78 30 30 30 38 20 20 2f 2a 20 43 75 72 72 65 6e x0008 /* Curren
ea60: 74 6c 79 20 72 75 6e 6e 69 6e 67 20 56 41 43 55 tly running VACU
ea70: 55 4d 20 49 4e 54 4f 20 2a 2f 0a 23 64 65 66 69 UM INTO */.#defi
ea80: 6e 65 20 44 42 46 4c 41 47 5f 53 63 68 65 6d 61 ne DBFLAG_Schema
ea90: 4b 6e 6f 77 6e 4f 6b 20 20 30 78 30 30 31 30 20 KnownOk 0x0010
eaa0: 20 2f 2a 20 53 63 68 65 6d 61 20 69 73 20 6b 6e /* Schema is kn
eab0: 6f 77 6e 20 74 6f 20 62 65 20 76 61 6c 69 64 20 own to be valid
eac0: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 73 20 6f */../*.** Bits o
ead0: 66 20 74 68 65 20 73 71 6c 69 74 65 33 2e 64 62 f the sqlite3.db
eae0: 4f 70 74 46 6c 61 67 73 20 66 69 65 6c 64 20 74 OptFlags field t
eaf0: 68 61 74 20 61 72 65 20 75 73 65 64 20 62 79 20 hat are used by
eb00: 74 68 65 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 the.** sqlite3_t
eb10: 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 53 51 4c 49 est_control(SQLI
eb20: 54 45 5f 54 45 53 54 43 54 52 4c 5f 4f 50 54 49 TE_TESTCTRL_OPTI
eb30: 4d 49 5a 41 54 49 4f 4e 53 2c 2e 2e 2e 29 20 69 MIZATIONS,...) i
eb40: 6e 74 65 72 66 61 63 65 20 74 6f 0a 2a 2a 20 73 nterface to.** s
eb50: 65 6c 65 63 74 69 76 65 6c 79 20 64 69 73 61 62 electively disab
eb60: 6c 65 20 76 61 72 69 6f 75 73 20 6f 70 74 69 6d le various optim
eb70: 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 izations..*/.#de
eb80: 66 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 72 fine SQLITE_Quer
eb90: 79 46 6c 61 74 74 65 6e 65 72 20 30 78 30 30 30 yFlattener 0x000
eba0: 31 20 20 20 2f 2a 20 51 75 65 72 79 20 66 6c 61 1 /* Query fla
ebb0: 74 74 65 6e 69 6e 67 20 2a 2f 0a 23 64 65 66 69 ttening */.#defi
ebc0: 6e 65 20 53 51 4c 49 54 45 5f 57 69 6e 64 6f 77 ne SQLITE_Window
ebd0: 46 75 6e 63 20 20 20 20 20 30 78 30 30 30 32 20 Func 0x0002
ebe0: 20 20 2f 2a 20 55 73 65 20 78 49 6e 76 65 72 73 /* Use xInvers
ebf0: 65 20 66 6f 72 20 77 69 6e 64 6f 77 20 66 75 6e e for window fun
ec00: 63 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e ctions */.#defin
ec10: 65 20 53 51 4c 49 54 45 5f 47 72 6f 75 70 42 79 e SQLITE_GroupBy
ec20: 4f 72 64 65 72 20 20 20 30 78 30 30 30 34 20 20 Order 0x0004
ec30: 20 2f 2a 20 47 52 4f 55 50 42 59 20 63 6f 76 65 /* GROUPBY cove
ec40: 72 20 6f 66 20 4f 52 44 45 52 42 59 20 2a 2f 0a r of ORDERBY */.
ec50: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
ec60: 61 63 74 6f 72 4f 75 74 43 6f 6e 73 74 20 30 78 actorOutConst 0x
ec70: 30 30 30 38 20 20 20 2f 2a 20 43 6f 6e 73 74 61 0008 /* Consta
ec80: 6e 74 20 66 61 63 74 6f 72 69 6e 67 20 2a 2f 0a nt factoring */.
ec90: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 #define SQLITE_D
eca0: 69 73 74 69 6e 63 74 4f 70 74 20 20 20 20 30 78 istinctOpt 0x
ecb0: 30 30 31 30 20 20 20 2f 2a 20 44 49 53 54 49 4e 0010 /* DISTIN
ecc0: 43 54 20 75 73 69 6e 67 20 69 6e 64 65 78 65 73 CT using indexes
ecd0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
ece0: 54 45 5f 43 6f 76 65 72 49 64 78 53 63 61 6e 20 TE_CoverIdxScan
ecf0: 20 20 30 78 30 30 32 30 20 20 20 2f 2a 20 43 6f 0x0020 /* Co
ed00: 76 65 72 69 6e 67 20 69 6e 64 65 78 20 73 63 61 vering index sca
ed10: 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ns */.#define SQ
ed20: 4c 49 54 45 5f 4f 72 64 65 72 42 79 49 64 78 4a LITE_OrderByIdxJ
ed30: 6f 69 6e 20 30 78 30 30 34 30 20 20 20 2f 2a 20 oin 0x0040 /*
ed40: 4f 52 44 45 52 20 42 59 20 6f 66 20 6a 6f 69 6e ORDER BY of join
ed50: 73 20 76 69 61 20 69 6e 64 65 78 20 2a 2f 0a 23 s via index */.#
ed60: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 72 define SQLITE_Tr
ed70: 61 6e 73 69 74 69 76 65 20 20 20 20 20 30 78 30 ansitive 0x0
ed80: 30 38 30 20 20 20 2f 2a 20 54 72 61 6e 73 69 74 080 /* Transit
ed90: 69 76 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 ive constraints
eda0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
edb0: 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f 69 6e 20 20 E_OmitNoopJoin
edc0: 20 30 78 30 31 30 30 20 20 20 2f 2a 20 4f 6d 69 0x0100 /* Omi
edd0: 74 20 75 6e 75 73 65 64 20 74 61 62 6c 65 73 20 t unused tables
ede0: 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a 23 64 65 66 in joins */.#def
edf0: 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f 75 6e 74 ine SQLITE_Count
ee00: 4f 66 56 69 65 77 20 20 20 20 30 78 30 32 30 30 OfView 0x0200
ee10: 20 20 20 2f 2a 20 54 68 65 20 63 6f 75 6e 74 2d /* The count-
ee20: 6f 66 2d 76 69 65 77 20 6f 70 74 69 6d 69 7a 61 of-view optimiza
ee30: 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
ee40: 53 51 4c 49 54 45 5f 43 75 72 73 6f 72 48 69 6e SQLITE_CursorHin
ee50: 74 73 20 20 20 20 30 78 30 34 30 30 20 20 20 2f ts 0x0400 /
ee60: 2a 20 41 64 64 20 4f 50 5f 43 75 72 73 6f 72 48 * Add OP_CursorH
ee70: 69 6e 74 20 6f 70 63 6f 64 65 73 20 2a 2f 0a 23 int opcodes */.#
ee80: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 74 define SQLITE_St
ee90: 61 74 34 20 20 20 20 20 20 20 20 20 20 30 78 30 at4 0x0
eea0: 38 30 30 20 20 20 2f 2a 20 55 73 65 20 53 54 41 800 /* Use STA
eeb0: 54 34 20 64 61 74 61 20 2a 2f 0a 20 20 20 2f 2a T4 data */. /*
eec0: 20 54 48 33 20 65 78 70 65 63 74 73 20 74 68 65 TH3 expects the
eed0: 20 53 74 61 74 34 20 20 20 5e 5e 5e 5e 5e 5e 20 Stat4 ^^^^^^
eee0: 76 61 6c 75 65 20 74 6f 20 62 65 20 30 78 30 38 value to be 0x08
eef0: 30 30 2e 20 20 44 6f 6e 27 74 20 63 68 61 6e 67 00. Don't chang
ef00: 65 20 69 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 e it */.#define
ef10: 53 51 4c 49 54 45 5f 50 75 73 68 44 6f 77 6e 20 SQLITE_PushDown
ef20: 20 20 20 20 20 20 30 78 31 30 30 30 20 20 20 2f 0x1000 /
ef30: 2a 20 54 68 65 20 70 75 73 68 2d 64 6f 77 6e 20 * The push-down
ef40: 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 2a 2f 0a optimization */.
ef50: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
ef60: 69 6d 70 6c 69 66 79 4a 6f 69 6e 20 20 20 30 78 implifyJoin 0x
ef70: 32 30 30 30 20 20 20 2f 2a 20 43 6f 6e 76 65 72 2000 /* Conver
ef80: 74 20 4c 45 46 54 20 4a 4f 49 4e 20 74 6f 20 4a t LEFT JOIN to J
ef90: 4f 49 4e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 OIN */.#define S
efa0: 51 4c 49 54 45 5f 53 6b 69 70 53 63 61 6e 20 20 QLITE_SkipScan
efb0: 20 20 20 20 20 30 78 34 30 30 30 20 20 20 2f 2a 0x4000 /*
efc0: 20 53 6b 69 70 2d 73 63 61 6e 73 20 2a 2f 0a 23 Skip-scans */.#
efd0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 72 define SQLITE_Pr
efe0: 6f 70 61 67 61 74 65 43 6f 6e 73 74 20 30 78 38 opagateConst 0x8
eff0: 30 30 30 20 20 20 2f 2a 20 54 68 65 20 63 6f 6e 000 /* The con
f000: 73 74 61 6e 74 20 70 72 6f 70 61 67 61 74 69 6f stant propagatio
f010: 6e 20 6f 70 74 20 2a 2f 0a 23 64 65 66 69 6e 65 n opt */.#define
f020: 20 53 51 4c 49 54 45 5f 41 6c 6c 4f 70 74 73 20 SQLITE_AllOpts
f030: 20 20 20 20 20 20 20 30 78 66 66 66 66 20 20 20 0xffff
f040: 2f 2a 20 41 6c 6c 20 6f 70 74 69 6d 69 7a 61 74 /* All optimizat
f050: 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 4d ions */../*.** M
f060: 61 63 72 6f 73 20 66 6f 72 20 74 65 73 74 69 6e acros for testin
f070: 67 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 g whether or not
f080: 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 61 optimizations a
f090: 72 65 20 65 6e 61 62 6c 65 64 20 6f 72 20 64 69 re enabled or di
f0a0: 73 61 62 6c 65 64 2e 0a 2a 2f 0a 23 64 65 66 69 sabled..*/.#defi
f0b0: 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 ne OptimizationD
f0c0: 69 73 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b isabled(db, mask
f0d0: 29 20 20 28 28 28 64 62 29 2d 3e 64 62 4f 70 74 ) (((db)->dbOpt
f0e0: 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 21 3d 30 Flags&(mask))!=0
f0f0: 29 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 ).#define Optimi
f100: 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 64 28 64 62 zationEnabled(db
f110: 2c 20 6d 61 73 6b 29 20 20 20 28 28 28 64 62 29 , mask) (((db)
f120: 2d 3e 64 62 4f 70 74 46 6c 61 67 73 26 28 6d 61 ->dbOptFlags&(ma
f130: 73 6b 29 29 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 sk))==0)../*.**
f140: 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 Return true if i
f150: 74 20 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 63 t OK to factor c
f160: 6f 6e 73 74 61 6e 74 20 65 78 70 72 65 73 73 69 onstant expressi
f170: 6f 6e 73 20 69 6e 74 6f 20 74 68 65 20 69 6e 69 ons into the ini
f180: 74 69 61 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 63 tialization.** c
f190: 6f 64 65 2e 20 54 68 65 20 61 72 67 75 6d 65 6e ode. The argumen
f1a0: 74 20 69 73 20 61 20 50 61 72 73 65 20 6f 62 6a t is a Parse obj
f1b0: 65 63 74 20 66 6f 72 20 74 68 65 20 63 6f 64 65 ect for the code
f1c0: 20 67 65 6e 65 72 61 74 6f 72 2e 0a 2a 2f 0a 23 generator..*/.#
f1d0: 64 65 66 69 6e 65 20 43 6f 6e 73 74 46 61 63 74 define ConstFact
f1e0: 6f 72 4f 6b 28 50 29 20 28 28 50 29 2d 3e 6f 6b orOk(P) ((P)->ok
f1f0: 43 6f 6e 73 74 46 61 63 74 6f 72 29 0a 0a 2f 2a ConstFactor)../*
f200: 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 20 76 61 6c .** Possible val
f210: 75 65 73 20 66 6f 72 20 74 68 65 20 73 71 6c 69 ues for the sqli
f220: 74 65 2e 6d 61 67 69 63 20 66 69 65 6c 64 2e 0a te.magic field..
f230: 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 73 20 61 ** The numbers a
f240: 72 65 20 6f 62 74 61 69 6e 65 64 20 61 74 20 72 re obtained at r
f250: 61 6e 64 6f 6d 20 61 6e 64 20 68 61 76 65 20 6e andom and have n
f260: 6f 20 73 70 65 63 69 61 6c 20 6d 65 61 6e 69 6e o special meanin
f270: 67 2c 20 6f 74 68 65 72 0a 2a 2a 20 74 68 61 6e g, other.** than
f280: 20 62 65 69 6e 67 20 64 69 73 74 69 6e 63 74 20 being distinct
f290: 66 72 6f 6d 20 6f 6e 65 20 61 6e 6f 74 68 65 72 from one another
f2a0: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c ..*/.#define SQL
f2b0: 49 54 45 5f 4d 41 47 49 43 5f 4f 50 45 4e 20 20 ITE_MAGIC_OPEN
f2c0: 20 20 20 30 78 61 30 32 39 61 36 39 37 20 20 2f 0xa029a697 /
f2d0: 2a 20 44 61 74 61 62 61 73 65 20 69 73 20 6f 70 * Database is op
f2e0: 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 en */.#define SQ
f2f0: 4c 49 54 45 5f 4d 41 47 49 43 5f 43 4c 4f 53 45 LITE_MAGIC_CLOSE
f300: 44 20 20 20 30 78 39 66 33 63 32 64 33 33 20 20 D 0x9f3c2d33
f310: 2f 2a 20 44 61 74 61 62 61 73 65 20 69 73 20 63 /* Database is c
f320: 6c 6f 73 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 losed */.#define
f330: 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 53 49 SQLITE_MAGIC_SI
f340: 43 4b 20 20 20 20 20 30 78 34 62 37 37 31 32 39 CK 0x4b77129
f350: 30 20 20 2f 2a 20 45 72 72 6f 72 20 61 6e 64 20 0 /* Error and
f360: 61 77 61 69 74 69 6e 67 20 63 6c 6f 73 65 20 2a awaiting close *
f370: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
f380: 5f 4d 41 47 49 43 5f 42 55 53 59 20 20 20 20 20 _MAGIC_BUSY
f390: 30 78 66 30 33 62 37 39 30 36 20 20 2f 2a 20 44 0xf03b7906 /* D
f3a0: 61 74 61 62 61 73 65 20 63 75 72 72 65 6e 74 6c atabase currentl
f3b0: 79 20 69 6e 20 75 73 65 20 2a 2f 0a 23 64 65 66 y in use */.#def
f3c0: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
f3d0: 5f 45 52 52 4f 52 20 20 20 20 30 78 62 35 33 35 _ERROR 0xb535
f3e0: 37 39 33 30 20 20 2f 2a 20 41 6e 20 53 51 4c 49 7930 /* An SQLI
f3f0: 54 45 5f 4d 49 53 55 53 45 20 65 72 72 6f 72 20 TE_MISUSE error
f400: 6f 63 63 75 72 72 65 64 20 2a 2f 0a 23 64 65 66 occurred */.#def
f410: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
f420: 5f 5a 4f 4d 42 49 45 20 20 20 30 78 36 34 63 66 _ZOMBIE 0x64cf
f430: 66 63 37 66 20 20 2f 2a 20 43 6c 6f 73 65 20 77 fc7f /* Close w
f440: 69 74 68 20 6c 61 73 74 20 73 74 61 74 65 6d 65 ith last stateme
f450: 6e 74 20 63 6c 6f 73 65 20 2a 2f 0a 0a 2f 2a 0a nt close */../*.
f460: 2a 2a 20 45 61 63 68 20 53 51 4c 20 66 75 6e 63 ** Each SQL func
f470: 74 69 6f 6e 20 69 73 20 64 65 66 69 6e 65 64 20 tion is defined
f480: 62 79 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f by an instance o
f490: 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a f the following.
f4a0: 2a 2a 20 73 74 72 75 63 74 75 72 65 2e 20 20 46 ** structure. F
f4b0: 6f 72 20 67 6c 6f 62 61 6c 20 62 75 69 6c 74 2d or global built-
f4c0: 69 6e 20 66 75 6e 63 74 69 6f 6e 73 20 28 65 78 in functions (ex
f4d0: 3a 20 73 75 62 73 74 72 28 29 2c 20 6d 61 78 28 : substr(), max(
f4e0: 29 2c 20 63 6f 75 6e 74 28 29 29 0a 2a 2a 20 61 ), count()).** a
f4f0: 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 pointer to this
f500: 20 73 74 72 75 63 74 75 72 65 20 69 73 20 68 65 structure is he
f510: 6c 64 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 ld in the sqlite
f520: 33 42 75 69 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 3BuiltinFunction
f530: 73 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 46 6f 72 s object..** For
f540: 20 70 65 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 per-connection
f550: 61 70 70 6c 69 63 61 74 69 6f 6e 2d 64 65 66 69 application-defi
f560: 6e 65 64 20 66 75 6e 63 74 69 6f 6e 73 2c 20 61 ned functions, a
f570: 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 pointer to this
f580: 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 20 69 73 .** structure is
f590: 20 68 65 6c 64 20 69 6e 20 74 68 65 20 64 62 2d held in the db-
f5a0: 3e 61 48 61 73 68 20 68 61 73 68 20 74 61 62 6c >aHash hash tabl
f5b0: 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 75 2e 70 e..**.** The u.p
f5c0: 48 61 73 68 20 66 69 65 6c 64 20 69 73 20 75 73 Hash field is us
f5d0: 65 64 20 62 79 20 74 68 65 20 67 6c 6f 62 61 6c ed by the global
f5e0: 20 62 75 69 6c 74 2d 69 6e 73 2e 20 20 54 68 65 built-ins. The
f5f0: 20 75 2e 70 44 65 73 74 72 75 63 74 6f 72 0a 2a u.pDestructor.*
f600: 2a 20 66 69 65 6c 64 20 69 73 20 75 73 65 64 20 * field is used
f610: 62 79 20 70 65 72 2d 63 6f 6e 6e 65 63 74 69 6f by per-connectio
f620: 6e 20 61 70 70 2d 64 65 66 20 66 75 6e 63 74 69 n app-def functi
f630: 6f 6e 73 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 ons..*/.struct F
f640: 75 6e 63 44 65 66 20 7b 0a 20 20 69 38 20 6e 41 uncDef {. i8 nA
f650: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
f660: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 /* Number of arg
f670: 75 6d 65 6e 74 73 2e 20 20 2d 31 20 6d 65 61 6e uments. -1 mean
f680: 73 20 75 6e 6c 69 6d 69 74 65 64 20 2a 2f 0a 20 s unlimited */.
f690: 20 75 33 32 20 66 75 6e 63 46 6c 61 67 73 3b 20 u32 funcFlags;
f6a0: 20 20 20 20 20 20 2f 2a 20 53 6f 6d 65 20 63 6f /* Some co
f6b0: 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 53 51 4c mbination of SQL
f6c0: 49 54 45 5f 46 55 4e 43 5f 2a 20 2a 2f 0a 20 20 ITE_FUNC_* */.
f6d0: 76 6f 69 64 20 2a 70 55 73 65 72 44 61 74 61 3b void *pUserData;
f6e0: 20 20 20 20 20 2f 2a 20 55 73 65 72 20 64 61 74 /* User dat
f6f0: 61 20 70 61 72 61 6d 65 74 65 72 20 2a 2f 0a 20 a parameter */.
f700: 20 46 75 6e 63 44 65 66 20 2a 70 4e 65 78 74 3b FuncDef *pNext;
f710: 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 66 75 /* Next fu
f720: 6e 63 74 69 6f 6e 20 77 69 74 68 20 73 61 6d 65 nction with same
f730: 20 6e 61 6d 65 20 2a 2f 0a 20 20 76 6f 69 64 20 name */. void
f740: 28 2a 78 53 46 75 6e 63 29 28 73 71 6c 69 74 65 (*xSFunc)(sqlite
f750: 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 3_context*,int,s
f760: 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b qlite3_value**);
f770: 20 2f 2a 20 66 75 6e 63 20 6f 72 20 61 67 67 2d /* func or agg-
f780: 73 74 65 70 20 2a 2f 0a 20 20 76 6f 69 64 20 28 step */. void (
f790: 2a 78 46 69 6e 61 6c 69 7a 65 29 28 73 71 6c 69 *xFinalize)(sqli
f7a0: 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 3b 20 20 te3_context*);
f7b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
f7c0: 2f 2a 20 41 67 67 20 66 69 6e 61 6c 69 7a 65 72 /* Agg finalizer
f7d0: 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 56 61 */. void (*xVa
f7e0: 6c 75 65 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e lue)(sqlite3_con
f7f0: 74 65 78 74 2a 29 3b 20 20 20 20 20 20 20 20 20 text*);
f800: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
f810: 75 72 72 65 6e 74 20 61 67 67 20 76 61 6c 75 65 urrent agg value
f820: 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 49 6e */. void (*xIn
f830: 76 65 72 73 65 29 28 73 71 6c 69 74 65 33 5f 63 verse)(sqlite3_c
f840: 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 ontext*,int,sqli
f850: 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a te3_value**); /*
f860: 20 69 6e 76 65 72 73 65 20 61 67 67 2d 73 74 65 inverse agg-ste
f870: 70 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 p */. const cha
f880: 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 2f 2a 20 53 r *zName; /* S
f890: 51 4c 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 66 QL name of the f
f8a0: 75 6e 63 74 69 6f 6e 2e 20 2a 2f 0a 20 20 75 6e unction. */. un
f8b0: 69 6f 6e 20 7b 0a 20 20 20 20 46 75 6e 63 44 65 ion {. FuncDe
f8c0: 66 20 2a 70 48 61 73 68 3b 20 20 20 20 20 20 2f f *pHash; /
f8d0: 2a 20 4e 65 78 74 20 77 69 74 68 20 61 20 64 69 * Next with a di
f8e0: 66 66 65 72 65 6e 74 20 6e 61 6d 65 20 62 75 74 fferent name but
f8f0: 20 74 68 65 20 73 61 6d 65 20 68 61 73 68 20 2a the same hash *
f900: 2f 0a 20 20 20 20 46 75 6e 63 44 65 73 74 72 75 /. FuncDestru
f910: 63 74 6f 72 20 2a 70 44 65 73 74 72 75 63 74 6f ctor *pDestructo
f920: 72 3b 20 20 20 2f 2a 20 52 65 66 65 72 65 6e 63 r; /* Referenc
f930: 65 20 63 6f 75 6e 74 65 64 20 64 65 73 74 72 75 e counted destru
f940: 63 74 6f 72 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ctor function */
f950: 0a 20 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a . } u;.};../*.*
f960: 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 * This structure
f970: 20 65 6e 63 61 70 73 75 6c 61 74 65 73 20 61 20 encapsulates a
f980: 75 73 65 72 2d 66 75 6e 63 74 69 6f 6e 20 64 65 user-function de
f990: 73 74 72 75 63 74 6f 72 20 63 61 6c 6c 62 61 63 structor callbac
f9a0: 6b 20 28 61 73 0a 2a 2a 20 63 6f 6e 66 69 67 75 k (as.** configu
f9b0: 72 65 64 20 75 73 69 6e 67 20 63 72 65 61 74 65 red using create
f9c0: 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 29 29 20 _function_v2())
f9d0: 61 6e 64 20 61 20 72 65 66 65 72 65 6e 63 65 20 and a reference
f9e0: 63 6f 75 6e 74 65 72 2e 20 57 68 65 6e 0a 2a 2a counter. When.**
f9f0: 20 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e create_function
fa00: 5f 76 32 28 29 20 69 73 20 63 61 6c 6c 65 64 20 _v2() is called
fa10: 74 6f 20 63 72 65 61 74 65 20 61 20 66 75 6e 63 to create a func
fa20: 74 69 6f 6e 20 77 69 74 68 20 61 20 64 65 73 74 tion with a dest
fa30: 72 75 63 74 6f 72 2c 0a 2a 2a 20 61 20 73 69 6e ructor,.** a sin
fa40: 67 6c 65 20 6f 62 6a 65 63 74 20 6f 66 20 74 68 gle object of th
fa50: 69 73 20 74 79 70 65 20 69 73 20 61 6c 6c 6f 63 is type is alloc
fa60: 61 74 65 64 2e 20 46 75 6e 63 44 65 73 74 72 75 ated. FuncDestru
fa70: 63 74 6f 72 2e 6e 52 65 66 20 69 73 20 73 65 74 ctor.nRef is set
fa80: 20 74 6f 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 65 to.** the numbe
fa90: 72 20 6f 66 20 46 75 6e 63 44 65 66 20 6f 62 6a r of FuncDef obj
faa0: 65 63 74 73 20 63 72 65 61 74 65 64 20 28 65 69 ects created (ei
fab0: 74 68 65 72 20 31 20 6f 72 20 33 2c 20 64 65 70 ther 1 or 3, dep
fac0: 65 6e 64 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 ending on whethe
fad0: 72 0a 2a 2a 20 6f 72 20 6e 6f 74 20 74 68 65 20 r.** or not the
fae0: 73 70 65 63 69 66 69 65 64 20 65 6e 63 6f 64 69 specified encodi
faf0: 6e 67 20 69 73 20 53 51 4c 49 54 45 5f 41 4e 59 ng is SQLITE_ANY
fb00: 29 2e 20 54 68 65 20 46 75 6e 63 44 65 66 2e 70 ). The FuncDef.p
fb10: 44 65 73 74 72 75 63 74 6f 72 0a 2a 2a 20 6d 65 Destructor.** me
fb20: 6d 62 65 72 20 6f 66 20 65 61 63 68 20 6f 66 20 mber of each of
fb30: 74 68 65 20 6e 65 77 20 46 75 6e 63 44 65 66 20 the new FuncDef
fb40: 6f 62 6a 65 63 74 73 20 69 73 20 73 65 74 20 74 objects is set t
fb50: 6f 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 20 61 o point to the a
fb60: 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 46 75 6e 63 llocated.** Func
fb70: 44 65 73 74 72 75 63 74 6f 72 2e 0a 2a 2a 0a 2a Destructor..**.*
fb80: 2a 20 54 68 65 72 65 61 66 74 65 72 2c 20 77 68 * Thereafter, wh
fb90: 65 6e 20 6f 6e 65 20 6f 66 20 74 68 65 20 46 75 en one of the Fu
fba0: 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 20 69 73 ncDef objects is
fbb0: 20 64 65 6c 65 74 65 64 2c 20 74 68 65 20 72 65 deleted, the re
fbc0: 66 65 72 65 6e 63 65 0a 2a 2a 20 63 6f 75 6e 74 ference.** count
fbd0: 20 6f 6e 20 74 68 69 73 20 6f 62 6a 65 63 74 20 on this object
fbe0: 69 73 20 64 65 63 72 65 6d 65 6e 74 65 64 2e 20 is decremented.
fbf0: 57 68 65 6e 20 69 74 20 72 65 61 63 68 65 73 20 When it reaches
fc00: 30 2c 20 74 68 65 20 64 65 73 74 72 75 63 74 6f 0, the destructo
fc10: 72 0a 2a 2a 20 69 73 20 69 6e 76 6f 6b 65 64 20 r.** is invoked
fc20: 61 6e 64 20 74 68 65 20 46 75 6e 63 44 65 73 74 and the FuncDest
fc30: 72 75 63 74 6f 72 20 73 74 72 75 63 74 75 72 65 ructor structure
fc40: 20 66 72 65 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 freed..*/.struc
fc50: 74 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 t FuncDestructor
fc60: 20 7b 0a 20 20 69 6e 74 20 6e 52 65 66 3b 0a 20 {. int nRef;.
fc70: 20 76 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 void (*xDestroy
fc80: 29 28 76 6f 69 64 20 2a 29 3b 0a 20 20 76 6f 69 )(void *);. voi
fc90: 64 20 2a 70 55 73 65 72 44 61 74 61 3b 0a 7d 3b d *pUserData;.};
fca0: 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 ../*.** Possible
fcb0: 20 76 61 6c 75 65 73 20 66 6f 72 20 46 75 6e 63 values for Func
fcc0: 44 65 66 2e 66 6c 61 67 73 2e 20 20 4e 6f 74 65 Def.flags. Note
fcd0: 20 74 68 61 74 20 74 68 65 20 5f 4c 45 4e 47 54 that the _LENGT
fce0: 48 20 61 6e 64 20 5f 54 59 50 45 4f 46 0a 2a 2a H and _TYPEOF.**
fcf0: 20 76 61 6c 75 65 73 20 6d 75 73 74 20 63 6f 72 values must cor
fd00: 72 65 73 70 6f 6e 64 20 74 6f 20 4f 50 46 4c 41 respond to OPFLA
fd10: 47 5f 4c 45 4e 47 54 48 41 52 47 20 61 6e 64 20 G_LENGTHARG and
fd20: 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 OPFLAG_TYPEOFARG
fd30: 2e 20 20 41 6e 64 0a 2a 2a 20 53 51 4c 49 54 45 . And.** SQLITE
fd40: 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 6d _FUNC_CONSTANT m
fd50: 75 73 74 20 62 65 20 74 68 65 20 73 61 6d 65 20 ust be the same
fd60: 61 73 20 53 51 4c 49 54 45 5f 44 45 54 45 52 4d as SQLITE_DETERM
fd70: 49 4e 49 53 54 49 43 2e 20 20 54 68 65 72 65 0a INISTIC. There.
fd80: 2a 2a 20 61 72 65 20 61 73 73 65 72 74 28 29 20 ** are assert()
fd90: 73 74 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 statements in th
fda0: 65 20 63 6f 64 65 20 74 6f 20 76 65 72 69 66 79 e code to verify
fdb0: 20 74 68 69 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c this..**.** Val
fdc0: 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 ue constraints (
fdd0: 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 73 73 enforced via ass
fde0: 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 20 53 ert()):.** S
fdf0: 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 QLITE_FUNC_MINMA
fe00: 58 20 20 20 20 3d 3d 20 20 4e 43 5f 4d 69 6e 4d X == NC_MinM
fe10: 61 78 41 67 67 20 20 20 20 20 20 3d 3d 20 53 46 axAgg == SF
fe20: 5f 4d 69 6e 4d 61 78 41 67 67 0a 2a 2a 20 20 20 _MinMaxAgg.**
fe30: 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 SQLITE_FUNC_LE
fe40: 4e 47 54 48 20 20 20 20 3d 3d 20 20 4f 50 46 4c NGTH == OPFL
fe50: 41 47 5f 4c 45 4e 47 54 48 41 52 47 0a 2a 2a 20 AG_LENGTHARG.**
fe60: 20 20 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f SQLITE_FUNC_
fe70: 54 59 50 45 4f 46 20 20 20 20 3d 3d 20 20 4f 50 TYPEOF == OP
fe80: 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 0a 2a FLAG_TYPEOFARG.*
fe90: 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 46 55 4e * SQLITE_FUN
fea0: 43 5f 43 4f 4e 53 54 41 4e 54 20 20 3d 3d 20 20 C_CONSTANT ==
feb0: 53 51 4c 49 54 45 5f 44 45 54 45 52 4d 49 4e 49 SQLITE_DETERMINI
fec0: 53 54 49 43 20 66 72 6f 6d 20 74 68 65 20 41 50 STIC from the AP
fed0: 49 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f I.** SQLITE_
fee0: 46 55 4e 43 5f 44 49 52 45 43 54 20 20 20 20 3d FUNC_DIRECT =
fef0: 3d 20 20 53 51 4c 49 54 45 5f 44 49 52 45 43 54 = SQLITE_DIRECT
ff00: 4f 4e 4c 59 20 66 72 6f 6d 20 74 68 65 20 41 50 ONLY from the AP
ff10: 49 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f I.** SQLITE_
ff20: 46 55 4e 43 5f 45 4e 43 4d 41 53 4b 20 20 20 64 FUNC_ENCMASK d
ff30: 65 70 65 6e 64 73 20 6f 6e 20 53 51 4c 49 54 45 epends on SQLITE
ff40: 5f 55 54 46 2a 20 6d 61 63 72 6f 73 20 69 6e 20 _UTF* macros in
ff50: 74 68 65 20 41 50 49 0a 2a 2f 0a 23 64 65 66 69 the API.*/.#defi
ff60: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 ne SQLITE_FUNC_E
ff70: 4e 43 4d 41 53 4b 20 20 30 78 30 30 30 33 20 2f NCMASK 0x0003 /
ff80: 2a 20 53 51 4c 49 54 45 5f 55 54 46 38 2c 20 53 * SQLITE_UTF8, S
ff90: 51 4c 49 54 45 5f 55 54 46 31 36 42 45 20 6f 72 QLITE_UTF16BE or
ffa0: 20 55 54 46 31 36 4c 45 20 2a 2f 0a 23 64 65 66 UTF16LE */.#def
ffb0: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
ffc0: 4c 49 4b 45 20 20 20 20 20 30 78 30 30 30 34 20 LIKE 0x0004
ffd0: 2f 2a 20 43 61 6e 64 69 64 61 74 65 20 66 6f 72 /* Candidate for
ffe0: 20 74 68 65 20 4c 49 4b 45 20 6f 70 74 69 6d 69 the LIKE optimi
fff0: 7a 61 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e zation */.#defin
10000 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 41 e SQLITE_FUNC_CA
10010 53 45 20 20 20 20 20 30 78 30 30 30 38 20 2f 2a SE 0x0008 /*
10020 20 43 61 73 65 2d 73 65 6e 73 69 74 69 76 65 20 Case-sensitive
10030 4c 49 4b 45 2d 74 79 70 65 20 66 75 6e 63 74 69 LIKE-type functi
10040 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 on */.#define SQ
10050 4c 49 54 45 5f 46 55 4e 43 5f 45 50 48 45 4d 20 LITE_FUNC_EPHEM
10060 20 20 20 30 78 30 30 31 30 20 2f 2a 20 45 70 68 0x0010 /* Eph
10070 65 6d 65 72 61 6c 2e 20 20 44 65 6c 65 74 65 20 emeral. Delete
10080 77 69 74 68 20 56 44 42 45 20 2a 2f 0a 23 64 65 with VDBE */.#de
10090 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 fine SQLITE_FUNC
100a0 5f 4e 45 45 44 43 4f 4c 4c 20 30 78 30 30 32 30 _NEEDCOLL 0x0020
100b0 20 2f 2a 20 73 71 6c 69 74 65 33 47 65 74 46 75 /* sqlite3GetFu
100c0 6e 63 43 6f 6c 6c 53 65 71 28 29 20 6d 69 67 68 ncCollSeq() migh
100d0 74 20 62 65 20 63 61 6c 6c 65 64 2a 2f 0a 23 64 t be called*/.#d
100e0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
100f0 43 5f 4c 45 4e 47 54 48 20 20 20 30 78 30 30 34 C_LENGTH 0x004
10100 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 6c 65 0 /* Built-in le
10110 6e 67 74 68 28 29 20 66 75 6e 63 74 69 6f 6e 20 ngth() function
10120 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
10130 45 5f 46 55 4e 43 5f 54 59 50 45 4f 46 20 20 20 E_FUNC_TYPEOF
10140 30 78 30 30 38 30 20 2f 2a 20 42 75 69 6c 74 2d 0x0080 /* Built-
10150 69 6e 20 74 79 70 65 6f 66 28 29 20 66 75 6e 63 in typeof() func
10160 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
10170 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 55 4e SQLITE_FUNC_COUN
10180 54 20 20 20 20 30 78 30 31 30 30 20 2f 2a 20 42 T 0x0100 /* B
10190 75 69 6c 74 2d 69 6e 20 63 6f 75 6e 74 28 2a 29 uilt-in count(*)
101a0 20 61 67 67 72 65 67 61 74 65 20 2a 2f 0a 23 64 aggregate */.#d
101b0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
101c0 43 5f 43 4f 41 4c 45 53 43 45 20 30 78 30 32 30 C_COALESCE 0x020
101d0 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 63 6f 0 /* Built-in co
101e0 61 6c 65 73 63 65 28 29 20 6f 72 20 69 66 6e 75 alesce() or ifnu
101f0 6c 6c 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ll() */.#define
10200 53 51 4c 49 54 45 5f 46 55 4e 43 5f 55 4e 4c 49 SQLITE_FUNC_UNLI
10210 4b 45 4c 59 20 30 78 30 34 30 30 20 2f 2a 20 42 KELY 0x0400 /* B
10220 75 69 6c 74 2d 69 6e 20 75 6e 6c 69 6b 65 6c 79 uilt-in unlikely
10230 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 () function */.#
10240 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
10250 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 30 78 30 38 NC_CONSTANT 0x08
10260 30 30 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 69 00 /* Constant i
10270 6e 70 75 74 73 20 67 69 76 65 20 61 20 63 6f 6e nputs give a con
10280 73 74 61 6e 74 20 6f 75 74 70 75 74 20 2a 2f 0a stant output */.
10290 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
102a0 55 4e 43 5f 4d 49 4e 4d 41 58 20 20 20 30 78 31 UNC_MINMAX 0x1
102b0 30 30 30 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 000 /* True for
102c0 6d 69 6e 28 29 20 61 6e 64 20 6d 61 78 28 29 20 min() and max()
102d0 61 67 67 72 65 67 61 74 65 73 20 2a 2f 0a 23 64 aggregates */.#d
102e0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
102f0 43 5f 53 4c 4f 43 48 4e 47 20 20 30 78 32 30 30 C_SLOCHNG 0x200
10300 30 20 2f 2a 20 22 53 6c 6f 77 20 43 68 61 6e 67 0 /* "Slow Chang
10310 65 22 2e 20 56 61 6c 75 65 20 63 6f 6e 73 74 61 e". Value consta
10320 6e 74 20 64 75 72 69 6e 67 20 61 0a 20 20 20 20 nt during a.
10330 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10340 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
10350 2a 2a 20 73 69 6e 67 6c 65 20 71 75 65 72 79 20 ** single query
10360 2d 20 6d 69 67 68 74 20 63 68 61 6e 67 65 20 6f - might change o
10370 76 65 72 20 74 69 6d 65 20 2a 2f 0a 23 64 65 66 ver time */.#def
10380 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
10390 41 46 46 49 4e 49 54 59 20 30 78 34 30 30 30 20 AFFINITY 0x4000
103a0 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 61 66 66 69 /* Built-in affi
103b0 6e 69 74 79 28 29 20 66 75 6e 63 74 69 6f 6e 20 nity() function
103c0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
103d0 45 5f 46 55 4e 43 5f 4f 46 46 53 45 54 20 20 20 E_FUNC_OFFSET
103e0 30 78 38 30 30 30 20 2f 2a 20 42 75 69 6c 74 2d 0x8000 /* Built-
103f0 69 6e 20 73 71 6c 69 74 65 5f 6f 66 66 73 65 74 in sqlite_offset
10400 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 () function */.#
10410 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
10420 4e 43 5f 57 49 4e 44 4f 57 20 20 20 30 78 30 30 NC_WINDOW 0x00
10430 30 31 30 30 30 30 20 2f 2a 20 42 75 69 6c 74 2d 010000 /* Built-
10440 69 6e 20 77 69 6e 64 6f 77 2d 6f 6e 6c 79 20 66 in window-only f
10450 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 unction */.#defi
10460 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 49 ne SQLITE_FUNC_I
10470 4e 54 45 52 4e 41 4c 20 30 78 30 30 30 34 30 30 NTERNAL 0x000400
10480 30 30 20 2f 2a 20 46 6f 72 20 75 73 65 20 62 79 00 /* For use by
10490 20 4e 65 73 74 65 64 50 61 72 73 65 28 29 20 6f NestedParse() o
104a0 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 nly */.#define S
104b0 51 4c 49 54 45 5f 46 55 4e 43 5f 44 49 52 45 43 QLITE_FUNC_DIREC
104c0 54 20 20 20 30 78 30 30 30 38 30 30 30 30 20 2f T 0x00080000 /
104d0 2a 20 4e 6f 74 20 66 6f 72 20 75 73 65 20 69 6e * Not for use in
104e0 20 54 52 49 47 47 45 52 73 20 6f 72 20 56 49 45 TRIGGERs or VIE
104f0 57 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 Ws */.#define SQ
10500 4c 49 54 45 5f 46 55 4e 43 5f 53 55 42 54 59 50 LITE_FUNC_SUBTYP
10510 45 20 20 30 78 30 30 31 30 30 30 30 30 20 2f 2a E 0x00100000 /*
10520 20 52 65 73 75 6c 74 20 6c 69 6b 65 6c 79 20 74 Result likely t
10530 6f 20 68 61 76 65 20 73 75 62 2d 74 79 70 65 20 o have sub-type
10540 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f */../*.** The fo
10550 6c 6c 6f 77 69 6e 67 20 74 68 72 65 65 20 6d 61 llowing three ma
10560 63 72 6f 73 2c 20 46 55 4e 43 54 49 4f 4e 28 29 cros, FUNCTION()
10570 2c 20 4c 49 4b 45 46 55 4e 43 28 29 20 61 6e 64 , LIKEFUNC() and
10580 20 41 47 47 52 45 47 41 54 45 28 29 20 61 72 65 AGGREGATE() are
10590 0a 2a 2a 20 75 73 65 64 20 74 6f 20 63 72 65 61 .** used to crea
105a0 74 65 20 74 68 65 20 69 6e 69 74 69 61 6c 69 7a te the initializ
105b0 65 72 73 20 66 6f 72 20 74 68 65 20 46 75 6e 63 ers for the Func
105c0 44 65 66 20 73 74 72 75 63 74 75 72 65 73 2e 0a Def structures..
105d0 2a 2a 0a 2a 2a 20 20 20 46 55 4e 43 54 49 4f 4e **.** FUNCTION
105e0 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
105f0 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a rg, bNC, xFunc).
10600 2a 2a 20 20 20 20 20 55 73 65 64 20 74 6f 20 63 ** Used to c
10610 72 65 61 74 65 20 61 20 73 63 61 6c 61 72 20 66 reate a scalar f
10620 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 unction definiti
10630 6f 6e 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e on of a function
10640 20 7a 4e 61 6d 65 0a 2a 2a 20 20 20 20 20 69 6d zName.** im
10650 70 6c 65 6d 65 6e 74 65 64 20 62 79 20 43 20 66 plemented by C f
10660 75 6e 63 74 69 6f 6e 20 78 46 75 6e 63 20 74 68 unction xFunc th
10670 61 74 20 61 63 63 65 70 74 73 20 6e 41 72 67 20 at accepts nArg
10680 61 72 67 75 6d 65 6e 74 73 2e 20 54 68 65 0a 2a arguments. The.*
10690 2a 20 20 20 20 20 76 61 6c 75 65 20 70 61 73 73 * value pass
106a0 65 64 20 61 73 20 69 41 72 67 20 69 73 20 63 61 ed as iArg is ca
106b0 73 74 20 74 6f 20 61 20 28 76 6f 69 64 2a 29 20 st to a (void*)
106c0 61 6e 64 20 6d 61 64 65 20 61 76 61 69 6c 61 62 and made availab
106d0 6c 65 0a 2a 2a 20 20 20 20 20 61 73 20 74 68 65 le.** as the
106e0 20 75 73 65 72 2d 64 61 74 61 20 28 73 71 6c 69 user-data (sqli
106f0 74 65 33 5f 75 73 65 72 5f 64 61 74 61 28 29 29 te3_user_data())
10700 20 66 6f 72 20 74 68 65 20 66 75 6e 63 74 69 6f for the functio
10710 6e 2e 20 49 66 0a 2a 2a 20 20 20 20 20 61 72 67 n. If.** arg
10720 75 6d 65 6e 74 20 62 4e 43 20 69 73 20 74 72 75 ument bNC is tru
10730 65 2c 20 74 68 65 6e 20 74 68 65 20 53 51 4c 49 e, then the SQLI
10740 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
10750 20 66 6c 61 67 20 69 73 20 73 65 74 2e 0a 2a 2a flag is set..**
10760 0a 2a 2a 20 20 20 56 46 55 4e 43 54 49 4f 4e 28 .** VFUNCTION(
10770 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 zName, nArg, iAr
10780 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a g, bNC, xFunc).*
10790 2a 20 20 20 20 20 4c 69 6b 65 20 46 55 4e 43 54 * Like FUNCT
107a0 49 4f 4e 20 65 78 63 65 70 74 20 69 74 20 6f 6d ION except it om
107b0 69 74 73 20 74 68 65 20 53 51 4c 49 54 45 5f 46 its the SQLITE_F
107c0 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 66 6c 61 UNC_CONSTANT fla
107d0 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 44 46 55 4e 43 g..**.** DFUNC
107e0 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 TION(zName, nArg
107f0 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 , iArg, bNC, xFu
10800 6e 63 29 0a 2a 2a 20 20 20 20 20 4c 69 6b 65 20 nc).** Like
10810 46 55 4e 43 54 49 4f 4e 20 65 78 63 65 70 74 20 FUNCTION except
10820 69 74 20 6f 6d 69 74 73 20 74 68 65 20 53 51 4c it omits the SQL
10830 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e ITE_FUNC_CONSTAN
10840 54 20 66 6c 61 67 20 61 6e 64 0a 2a 2a 20 20 20 T flag and.**
10850 20 20 61 64 64 73 20 74 68 65 20 53 51 4c 49 54 adds the SQLIT
10860 45 5f 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 20 66 E_FUNC_SLOCHNG f
10870 6c 61 67 2e 20 20 55 73 65 64 20 66 6f 72 20 64 lag. Used for d
10880 61 74 65 20 26 20 74 69 6d 65 20 66 75 6e 63 74 ate & time funct
10890 69 6f 6e 73 0a 2a 2a 20 20 20 20 20 61 6e 64 20 ions.** and
108a0 66 75 6e 63 74 69 6f 6e 73 20 6c 69 6b 65 20 73 functions like s
108b0 71 6c 69 74 65 5f 76 65 72 73 69 6f 6e 28 29 20 qlite_version()
108c0 74 68 61 74 20 63 61 6e 20 63 68 61 6e 67 65 2c that can change,
108d0 20 62 75 74 20 6e 6f 74 20 64 75 72 69 6e 67 0a but not during.
108e0 2a 2a 20 20 20 20 20 61 20 73 69 6e 67 6c 65 20 ** a single
108f0 71 75 65 72 79 2e 20 20 54 68 65 20 69 41 72 67 query. The iArg
10900 20 69 73 20 69 67 6e 6f 72 65 64 2e 20 20 54 68 is ignored. Th
10910 65 20 75 73 65 72 2d 64 61 74 61 20 69 73 20 61 e user-data is a
10920 6c 77 61 79 73 20 73 65 74 0a 2a 2a 20 20 20 20 lways set.**
10930 20 74 6f 20 61 20 4e 55 4c 4c 20 70 6f 69 6e 74 to a NULL point
10940 65 72 2e 20 20 54 68 65 20 62 4e 43 20 70 61 72 er. The bNC par
10950 61 6d 65 74 65 72 20 69 73 20 6e 6f 74 20 75 73 ameter is not us
10960 65 64 2e 0a 2a 2a 0a 2a 2a 20 20 20 50 55 52 45 ed..**.** PURE
10970 5f 44 41 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 _DATE(zName, nAr
10980 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 g, iArg, bNC, xF
10990 75 6e 63 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 unc).** Used
109a0 20 66 6f 72 20 22 70 75 72 65 22 20 64 61 74 65 for "pure" date
109b0 2f 74 69 6d 65 20 66 75 6e 63 74 69 6f 6e 73 2c /time functions,
109c0 20 74 68 69 73 20 6d 61 63 72 6f 20 69 73 20 6c this macro is l
109d0 69 6b 65 20 44 46 55 4e 43 54 49 4f 4e 0a 2a 2a ike DFUNCTION.**
109e0 20 20 20 20 20 65 78 63 65 70 74 20 74 68 61 74 except that
109f0 20 69 74 20 64 6f 65 73 20 73 65 74 20 74 68 65 it does set the
10a00 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e SQLITE_FUNC_CON
10a10 53 54 41 4e 54 20 66 6c 61 67 73 2e 20 20 69 41 STANT flags. iA
10a20 72 67 20 69 73 0a 2a 2a 20 20 20 20 20 69 67 6e rg is.** ign
10a30 6f 72 65 64 20 61 6e 64 20 74 68 65 20 75 73 65 ored and the use
10a40 72 2d 64 61 74 61 20 66 6f 72 20 74 68 65 73 65 r-data for these
10a50 20 66 75 6e 63 74 69 6f 6e 73 20 69 73 20 73 65 functions is se
10a60 74 20 74 6f 20 61 6e 20 0a 2a 2a 20 20 20 20 20 t to an .**
10a70 61 72 62 69 74 72 61 72 79 20 6e 6f 6e 2d 4e 55 arbitrary non-NU
10a80 4c 4c 20 70 6f 69 6e 74 65 72 2e 20 20 54 68 65 LL pointer. The
10a90 20 62 4e 43 20 70 61 72 61 6d 65 74 65 72 20 69 bNC parameter i
10aa0 73 20 6e 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a s not used..**.*
10ab0 2a 20 20 20 41 47 47 52 45 47 41 54 45 28 7a 4e * AGGREGATE(zN
10ac0 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c ame, nArg, iArg,
10ad0 20 62 4e 43 2c 20 78 53 74 65 70 2c 20 78 46 69 bNC, xStep, xFi
10ae0 6e 61 6c 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 nal).** Used
10af0 20 74 6f 20 63 72 65 61 74 65 20 61 6e 20 61 67 to create an ag
10b00 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
10b10 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 6d 70 6c definition impl
10b20 65 6d 65 6e 74 65 64 20 62 79 0a 2a 2a 20 20 20 emented by.**
10b30 20 20 74 68 65 20 43 20 66 75 6e 63 74 69 6f 6e the C function
10b40 73 20 78 53 74 65 70 20 61 6e 64 20 78 46 69 6e s xStep and xFin
10b50 61 6c 2e 20 54 68 65 20 66 69 72 73 74 20 66 6f al. The first fo
10b60 75 72 20 70 61 72 61 6d 65 74 65 72 73 0a 2a 2a ur parameters.**
10b70 20 20 20 20 20 61 72 65 20 69 6e 74 65 72 70 72 are interpr
10b80 65 74 65 64 20 69 6e 20 74 68 65 20 73 61 6d 65 eted in the same
10b90 20 77 61 79 20 61 73 20 74 68 65 20 66 69 72 73 way as the firs
10ba0 74 20 34 20 70 61 72 61 6d 65 74 65 72 73 20 74 t 4 parameters t
10bb0 6f 0a 2a 2a 20 20 20 20 20 46 55 4e 43 54 49 4f o.** FUNCTIO
10bc0 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 57 46 55 N()..**.** WFU
10bd0 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 NCTION(zName, nA
10be0 72 67 2c 20 69 41 72 67 2c 20 78 53 74 65 70 2c rg, iArg, xStep,
10bf0 20 78 46 69 6e 61 6c 2c 20 78 56 61 6c 75 65 2c xFinal, xValue,
10c00 20 78 49 6e 76 65 72 73 65 29 0a 2a 2a 20 20 20 xInverse).**
10c10 20 20 55 73 65 64 20 74 6f 20 63 72 65 61 74 65 Used to create
10c20 20 61 6e 20 61 67 67 72 65 67 61 74 65 20 66 75 an aggregate fu
10c30 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f nction definitio
10c40 6e 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 n implemented by
10c50 0a 2a 2a 20 20 20 20 20 74 68 65 20 43 20 66 75 .** the C fu
10c60 6e 63 74 69 6f 6e 73 20 78 53 74 65 70 20 61 6e nctions xStep an
10c70 64 20 78 46 69 6e 61 6c 2e 20 54 68 65 20 66 69 d xFinal. The fi
10c80 72 73 74 20 66 6f 75 72 20 70 61 72 61 6d 65 74 rst four paramet
10c90 65 72 73 0a 2a 2a 20 20 20 20 20 61 72 65 20 69 ers.** are i
10ca0 6e 74 65 72 70 72 65 74 65 64 20 69 6e 20 74 68 nterpreted in th
10cb0 65 20 73 61 6d 65 20 77 61 79 20 61 73 20 74 68 e same way as th
10cc0 65 20 66 69 72 73 74 20 34 20 70 61 72 61 6d 65 e first 4 parame
10cd0 74 65 72 73 20 74 6f 0a 2a 2a 20 20 20 20 20 46 ters to.** F
10ce0 55 4e 43 54 49 4f 4e 28 29 2e 0a 2a 2a 0a 2a 2a UNCTION()..**.**
10cf0 20 20 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d LIKEFUNC(zNam
10d00 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 66 e, nArg, pArg, f
10d10 6c 61 67 73 29 0a 2a 2a 20 20 20 20 20 55 73 65 lags).** Use
10d20 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 d to create a sc
10d30 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 alar function de
10d40 66 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 finition of a fu
10d50 6e 63 74 69 6f 6e 20 7a 4e 61 6d 65 0a 2a 2a 20 nction zName.**
10d60 20 20 20 20 74 68 61 74 20 61 63 63 65 70 74 73 that accepts
10d70 20 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 20 nArg arguments
10d80 61 6e 64 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 and is implement
10d90 65 64 20 62 79 20 61 20 63 61 6c 6c 20 74 6f 20 ed by a call to
10da0 43 0a 2a 2a 20 20 20 20 20 66 75 6e 63 74 69 6f C.** functio
10db0 6e 20 6c 69 6b 65 46 75 6e 63 2e 20 41 72 67 75 n likeFunc. Argu
10dc0 6d 65 6e 74 20 70 41 72 67 20 69 73 20 63 61 73 ment pArg is cas
10dd0 74 20 74 6f 20 61 20 28 76 6f 69 64 20 2a 29 20 t to a (void *)
10de0 61 6e 64 20 6d 61 64 65 0a 2a 2a 20 20 20 20 20 and made.**
10df0 61 76 61 69 6c 61 62 6c 65 20 61 73 20 74 68 65 available as the
10e00 20 66 75 6e 63 74 69 6f 6e 20 75 73 65 72 2d 64 function user-d
10e10 61 74 61 20 28 73 71 6c 69 74 65 33 5f 75 73 65 ata (sqlite3_use
10e20 72 5f 64 61 74 61 28 29 29 2e 20 54 68 65 0a 2a r_data()). The.*
10e30 2a 20 20 20 20 20 46 75 6e 63 44 65 66 2e 66 6c * FuncDef.fl
10e40 61 67 73 20 76 61 72 69 61 62 6c 65 20 69 73 20 ags variable is
10e50 73 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 set to the value
10e60 20 70 61 73 73 65 64 20 61 73 20 74 68 65 20 66 passed as the f
10e70 6c 61 67 73 0a 2a 2a 20 20 20 20 20 70 61 72 61 lags.** para
10e80 6d 65 74 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e meter..*/.#defin
10e90 65 20 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 e FUNCTION(zName
10ea0 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e , nArg, iArg, bN
10eb0 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e C, xFunc) \. {n
10ec0 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 Arg, SQLITE_FUNC
10ed0 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 _CONSTANT|SQLITE
10ee0 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 _UTF8|(bNC*SQLIT
10ef0 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 E_FUNC_NEEDCOLL)
10f00 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e , \. SQLITE_IN
10f10 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 T_TO_PTR(iArg),
10f20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 0, xFunc, 0, 0,
10f30 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0, #zName, {0} }
10f40 0a 23 64 65 66 69 6e 65 20 56 46 55 4e 43 54 49 .#define VFUNCTI
10f50 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 ON(zName, nArg,
10f60 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 iArg, bNC, xFunc
10f70 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c ) \. {nArg, SQL
10f80 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
10f90 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
10fa0 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 LL), \. SQLITE
10fb0 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 _INT_TO_PTR(iArg
10fc0 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 ), 0, xFunc, 0,
10fd0 30 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 0, 0, #zName, {0
10fe0 7d 20 7d 0a 23 64 65 66 69 6e 65 20 44 46 55 4e } }.#define DFUN
10ff0 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 CTION(zName, nAr
11000 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 g, iArg, bNC, xF
11010 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 unc) \. {nArg,
11020 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 SQLITE_FUNC_SLOC
11030 48 4e 47 7c 53 51 4c 49 54 45 5f 55 54 46 38 2c HNG|SQLITE_UTF8,
11040 20 5c 0a 20 20 20 30 2c 20 30 2c 20 78 46 75 6e \. 0, 0, xFun
11050 63 2c 20 30 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 c, 0, 0, 0, #zNa
11060 6d 65 2c 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e me, {0} }.#defin
11070 65 20 50 55 52 45 5f 44 41 54 45 28 7a 4e 61 6d e PURE_DATE(zNam
11080 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 e, nArg, iArg, b
11090 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b NC, xFunc) \. {
110a0 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e nArg, SQLITE_FUN
110b0 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 C_SLOCHNG|SQLITE
110c0 5f 55 54 46 38 7c 53 51 4c 49 54 45 5f 46 55 4e _UTF8|SQLITE_FUN
110d0 43 5f 43 4f 4e 53 54 41 4e 54 2c 20 5c 0a 20 20 C_CONSTANT, \.
110e0 20 28 76 6f 69 64 2a 29 26 73 71 6c 69 74 65 33 (void*)&sqlite3
110f0 43 6f 6e 66 69 67 2c 20 30 2c 20 78 46 75 6e 63 Config, 0, xFunc
11100 2c 20 30 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 6d , 0, 0, 0, #zNam
11110 65 2c 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 e, {0} }.#define
11120 20 46 55 4e 43 54 49 4f 4e 32 28 7a 4e 61 6d 65 FUNCTION2(zName
11130 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e , nArg, iArg, bN
11140 43 2c 20 78 46 75 6e 63 2c 20 65 78 74 72 61 46 C, xFunc, extraF
11150 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 67 2c lags) \. {nArg,
11160 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 SQLITE_FUNC_CONS
11170 54 41 4e 54 7c 53 51 4c 49 54 45 5f 55 54 46 38 TANT|SQLITE_UTF8
11180 7c 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 55 4e |(bNC*SQLITE_FUN
11190 43 5f 4e 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 C_NEEDCOLL)|extr
111a0 61 46 6c 61 67 73 2c 5c 0a 20 20 20 53 51 4c 49 aFlags,\. SQLI
111b0 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 TE_INT_TO_PTR(iA
111c0 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 rg), 0, xFunc, 0
111d0 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 , 0, 0, #zName,
111e0 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 53 54 {0} }.#define ST
111f0 52 5f 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 R_FUNCTION(zName
11200 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 62 4e , nArg, pArg, bN
11210 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b 6e C, xFunc) \. {n
11220 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 Arg, SQLITE_FUNC
11230 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 5f _SLOCHNG|SQLITE_
11240 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 45 UTF8|(bNC*SQLITE
11250 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c _FUNC_NEEDCOLL),
11260 20 5c 0a 20 20 20 70 41 72 67 2c 20 30 2c 20 78 \. pArg, 0, x
11270 46 75 6e 63 2c 20 30 2c 20 30 2c 20 30 2c 20 23 Func, 0, 0, 0, #
11280 7a 4e 61 6d 65 2c 20 7d 0a 23 64 65 66 69 6e 65 zName, }.#define
11290 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 2c LIKEFUNC(zName,
112a0 20 6e 41 72 67 2c 20 61 72 67 2c 20 66 6c 61 67 nArg, arg, flag
112b0 73 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 s) \. {nArg, SQ
112c0 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 LITE_FUNC_CONSTA
112d0 4e 54 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c 66 NT|SQLITE_UTF8|f
112e0 6c 61 67 73 2c 20 5c 0a 20 20 20 28 76 6f 69 64 lags, \. (void
112f0 20 2a 29 61 72 67 2c 20 30 2c 20 6c 69 6b 65 46 *)arg, 0, likeF
11300 75 6e 63 2c 20 30 2c 20 30 2c 20 30 2c 20 23 7a unc, 0, 0, 0, #z
11310 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0a 23 64 65 66 Name, {0} }.#def
11320 69 6e 65 20 41 47 47 52 45 47 41 54 45 28 7a 4e ine AGGREGATE(zN
11330 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 67 2c 20 ame, nArg, arg,
11340 6e 63 2c 20 78 53 74 65 70 2c 20 78 46 69 6e 61 nc, xStep, xFina
11350 6c 2c 20 78 56 61 6c 75 65 29 20 5c 0a 20 20 7b l, xValue) \. {
11360 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 nArg, SQLITE_UTF
11370 38 7c 28 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 8|(nc*SQLITE_FUN
11380 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 C_NEEDCOLL), \.
11390 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f SQLITE_INT_TO_
113a0 50 54 52 28 61 72 67 29 2c 20 30 2c 20 78 53 74 PTR(arg), 0, xSt
113b0 65 70 2c 78 46 69 6e 61 6c 2c 78 56 61 6c 75 65 ep,xFinal,xValue
113c0 2c 30 2c 23 7a 4e 61 6d 65 2c 20 7b 30 7d 7d 0a ,0,#zName, {0}}.
113d0 23 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 54 #define AGGREGAT
113e0 45 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 E2(zName, nArg,
113f0 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 arg, nc, xStep,
11400 78 46 69 6e 61 6c 2c 20 65 78 74 72 61 46 6c 61 xFinal, extraFla
11410 67 73 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 gs) \. {nArg, S
11420 51 4c 49 54 45 5f 55 54 46 38 7c 28 6e 63 2a 53 QLITE_UTF8|(nc*S
11430 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
11440 4f 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c OLL)|extraFlags,
11450 20 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 \. SQLITE_INT
11460 5f 54 4f 5f 50 54 52 28 61 72 67 29 2c 20 30 2c _TO_PTR(arg), 0,
11470 20 78 53 74 65 70 2c 78 46 69 6e 61 6c 2c 78 46 xStep,xFinal,xF
11480 69 6e 61 6c 2c 30 2c 23 7a 4e 61 6d 65 2c 20 7b inal,0,#zName, {
11490 30 7d 7d 0a 23 64 65 66 69 6e 65 20 57 41 47 47 0}}.#define WAGG
114a0 52 45 47 41 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 REGATE(zName, nA
114b0 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 rg, arg, nc, xSt
114c0 65 70 2c 20 78 46 69 6e 61 6c 2c 20 78 56 61 6c ep, xFinal, xVal
114d0 75 65 2c 20 78 49 6e 76 65 72 73 65 2c 20 66 29 ue, xInverse, f)
114e0 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 \. {nArg, SQLI
114f0 54 45 5f 55 54 46 38 7c 28 6e 63 2a 53 51 4c 49 TE_UTF8|(nc*SQLI
11500 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
11510 29 7c 66 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 )|f, \. SQLITE
11520 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 _INT_TO_PTR(arg)
11530 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 69 6e 61 , 0, xStep,xFina
11540 6c 2c 78 56 61 6c 75 65 2c 78 49 6e 76 65 72 73 l,xValue,xInvers
11550 65 2c 23 7a 4e 61 6d 65 2c 20 7b 30 7d 7d 0a 23 e,#zName, {0}}.#
11560 64 65 66 69 6e 65 20 49 4e 54 45 52 4e 41 4c 5f define INTERNAL_
11570 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 FUNCTION(zName,
11580 6e 41 72 67 2c 20 78 46 75 6e 63 29 20 5c 0a 20 nArg, xFunc) \.
11590 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 {nArg, SQLITE_F
115a0 55 4e 43 5f 49 4e 54 45 52 4e 41 4c 7c 53 51 4c UNC_INTERNAL|SQL
115b0 49 54 45 5f 55 54 46 38 7c 53 51 4c 49 54 45 5f ITE_UTF8|SQLITE_
115c0 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 2c 20 5c FUNC_CONSTANT, \
115d0 0a 20 20 20 30 2c 20 30 2c 20 78 46 75 6e 63 2c . 0, 0, xFunc,
115e0 20 30 2c 20 30 2c 20 30 2c 20 23 7a 4e 61 6d 65 0, 0, 0, #zName
115f0 2c 20 7b 30 7d 20 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 , {0} }.../*.**
11600 41 6c 6c 20 63 75 72 72 65 6e 74 20 73 61 76 65 All current save
11610 70 6f 69 6e 74 73 20 61 72 65 20 73 74 6f 72 65 points are store
11620 64 20 69 6e 20 61 20 6c 69 6e 6b 65 64 20 6c 69 d in a linked li
11630 73 74 20 73 74 61 72 74 69 6e 67 20 61 74 0a 2a st starting at.*
11640 2a 20 73 71 6c 69 74 65 33 2e 70 53 61 76 65 70 * sqlite3.pSavep
11650 6f 69 6e 74 2e 20 54 68 65 20 66 69 72 73 74 20 oint. The first
11660 65 6c 65 6d 65 6e 74 20 69 6e 20 74 68 65 20 6c element in the l
11670 69 73 74 20 69 73 20 74 68 65 20 6d 6f 73 74 20 ist is the most
11680 72 65 63 65 6e 74 6c 79 0a 2a 2a 20 6f 70 65 6e recently.** open
11690 65 64 20 73 61 76 65 70 6f 69 6e 74 2e 20 53 61 ed savepoint. Sa
116a0 76 65 70 6f 69 6e 74 73 20 61 72 65 20 61 64 64 vepoints are add
116b0 65 64 20 74 6f 20 74 68 65 20 6c 69 73 74 20 62 ed to the list b
116c0 79 20 74 68 65 20 76 64 62 65 0a 2a 2a 20 4f 50 y the vdbe.** OP
116d0 5f 53 61 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 _Savepoint instr
116e0 75 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 uction..*/.struc
116f0 74 20 53 61 76 65 70 6f 69 6e 74 20 7b 0a 20 20 t Savepoint {.
11700 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
11710 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11720 20 20 20 20 2f 2a 20 53 61 76 65 70 6f 69 6e 74 /* Savepoint
11730 20 6e 61 6d 65 20 28 6e 75 6c 2d 74 65 72 6d 69 name (nul-termi
11740 6e 61 74 65 64 29 20 2a 2f 0a 20 20 69 36 34 20 nated) */. i64
11750 6e 44 65 66 65 72 72 65 64 43 6f 6e 73 3b 20 20 nDeferredCons;
11760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11770 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 64 65 66 /* Number of def
11780 65 72 72 65 64 20 66 6b 20 76 69 6f 6c 61 74 69 erred fk violati
11790 6f 6e 73 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 ons */. i64 nDe
117a0 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 ferredImmCons;
117b0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
117c0 4e 75 6d 62 65 72 20 6f 66 20 64 65 66 65 72 72 Number of deferr
117d0 65 64 20 69 6d 6d 20 66 6b 2e 20 2a 2f 0a 20 20 ed imm fk. */.
117e0 53 61 76 65 70 6f 69 6e 74 20 2a 70 4e 65 78 74 Savepoint *pNext
117f0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
11800 20 20 20 20 2f 2a 20 50 61 72 65 6e 74 20 73 61 /* Parent sa
11810 76 65 70 6f 69 6e 74 20 28 69 66 20 61 6e 79 29 vepoint (if any)
11820 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 */.};../*.** Th
11830 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 72 65 20 e following are
11840 75 73 65 64 20 61 73 20 74 68 65 20 73 65 63 6f used as the seco
11850 6e 64 20 70 61 72 61 6d 65 74 65 72 20 74 6f 20 nd parameter to
11860 73 71 6c 69 74 65 33 53 61 76 65 70 6f 69 6e 74 sqlite3Savepoint
11870 28 29 2c 0a 2a 2a 20 61 6e 64 20 61 73 20 74 68 (),.** and as th
11880 65 20 50 31 20 61 72 67 75 6d 65 6e 74 20 74 6f e P1 argument to
11890 20 74 68 65 20 4f 50 5f 53 61 76 65 70 6f 69 6e the OP_Savepoin
118a0 74 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 2a t instruction..*
118b0 2f 0a 23 64 65 66 69 6e 65 20 53 41 56 45 50 4f /.#define SAVEPO
118c0 49 4e 54 5f 42 45 47 49 4e 20 20 20 20 20 20 30 INT_BEGIN 0
118d0 0a 23 64 65 66 69 6e 65 20 53 41 56 45 50 4f 49 .#define SAVEPOI
118e0 4e 54 5f 52 45 4c 45 41 53 45 20 20 20 20 31 0a NT_RELEASE 1.
118f0 23 64 65 66 69 6e 65 20 53 41 56 45 50 4f 49 4e #define SAVEPOIN
11900 54 5f 52 4f 4c 4c 42 41 43 4b 20 20 20 32 0a 0a T_ROLLBACK 2..
11910 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 69 ./*.** Each SQLi
11920 74 65 20 6d 6f 64 75 6c 65 20 28 76 69 72 74 75 te module (virtu
11930 61 6c 20 74 61 62 6c 65 20 64 65 66 69 6e 69 74 al table definit
11940 69 6f 6e 29 20 69 73 20 64 65 66 69 6e 65 64 20 ion) is defined
11950 62 79 20 61 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 by an.** instanc
11960 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
11970 6e 67 20 73 74 72 75 63 74 75 72 65 2c 20 73 74 ng structure, st
11980 6f 72 65 64 20 69 6e 20 74 68 65 20 73 71 6c 69 ored in the sqli
11990 74 65 33 2e 61 4d 6f 64 75 6c 65 0a 2a 2a 20 68 te3.aModule.** h
119a0 61 73 68 20 74 61 62 6c 65 2e 0a 2a 2f 0a 73 74 ash table..*/.st
119b0 72 75 63 74 20 4d 6f 64 75 6c 65 20 7b 0a 20 20 ruct Module {.
119c0 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 6f const sqlite3_mo
119d0 64 75 6c 65 20 2a 70 4d 6f 64 75 6c 65 3b 20 20 dule *pModule;
119e0 20 20 20 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b /* Callback
119f0 20 70 6f 69 6e 74 65 72 73 20 2a 2f 0a 20 20 63 pointers */. c
11a00 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d 65 onst char *zName
11a10 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
11a20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 70 61 73 73 /* Name pass
11a30 65 64 20 74 6f 20 63 72 65 61 74 65 5f 6d 6f 64 ed to create_mod
11a40 75 6c 65 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e ule() */. int n
11a50 52 65 66 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 RefModule;
11a60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11a70 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 /* Number of poi
11a80 6e 74 65 72 73 20 74 6f 20 74 68 69 73 20 6f 62 nters to this ob
11a90 6a 65 63 74 20 2a 2f 0a 20 20 76 6f 69 64 20 2a ject */. void *
11aa0 70 41 75 78 3b 20 20 20 20 20 20 20 20 20 20 20 pAux;
11ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
11ac0 2a 20 70 41 75 78 20 70 61 73 73 65 64 20 74 6f * pAux passed to
11ad0 20 63 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 create_module()
11ae0 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 */. void (*xDe
11af0 73 74 72 6f 79 29 28 76 6f 69 64 20 2a 29 3b 20 stroy)(void *);
11b00 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f /* Mo
11b10 64 75 6c 65 20 64 65 73 74 72 75 63 74 6f 72 20 dule destructor
11b20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 54 61 function */. Ta
11b30 62 6c 65 20 2a 70 45 70 6f 54 61 62 3b 20 20 20 ble *pEpoTab;
11b40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11b50 20 20 20 2f 2a 20 45 70 6f 6e 79 6d 6f 75 73 20 /* Eponymous
11b60 74 61 62 6c 65 20 66 6f 72 20 74 68 69 73 20 6d table for this m
11b70 6f 64 75 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a odule */.};../*.
11b80 2a 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 ** Information a
11b90 62 6f 75 74 20 65 61 63 68 20 63 6f 6c 75 6d 6e bout each column
11ba0 20 6f 66 20 61 6e 20 53 51 4c 20 74 61 62 6c 65 of an SQL table
11bb0 20 69 73 20 68 65 6c 64 20 69 6e 20 61 6e 20 69 is held in an i
11bc0 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 nstance.** of th
11bd0 65 20 43 6f 6c 75 6d 6e 20 73 74 72 75 63 74 75 e Column structu
11be0 72 65 2c 20 69 6e 20 74 68 65 20 54 61 62 6c 65 re, in the Table
11bf0 2e 61 43 6f 6c 5b 5d 20 61 72 72 61 79 2e 0a 2a .aCol[] array..*
11c00 2a 0a 2a 2a 20 44 65 66 69 6e 69 74 69 6f 6e 73 *.** Definitions
11c10 3a 0a 2a 2a 0a 2a 2a 20 20 20 22 74 61 62 6c 65 :.**.** "table
11c20 20 63 6f 6c 75 6d 6e 20 69 6e 64 65 78 22 20 20 column index"
11c30 20 20 20 54 68 69 73 20 69 73 20 74 68 65 20 69 This is the i
11c40 6e 64 65 78 20 6f 66 20 74 68 65 20 63 6f 6c 75 ndex of the colu
11c50 6d 6e 20 69 6e 20 74 68 65 0a 2a 2a 20 20 20 20 mn in the.**
11c60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11c70 20 20 20 20 20 20 20 20 54 61 62 6c 65 2e 61 43 Table.aC
11c80 6f 6c 5b 5d 20 61 72 72 61 79 2c 20 61 6e 64 20 ol[] array, and
11c90 61 6c 73 6f 20 74 68 65 20 69 6e 64 65 78 20 6f also the index o
11ca0 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 f.**
11cb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11cc0 74 68 65 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 the column in th
11cd0 65 20 6f 72 69 67 69 6e 61 6c 20 43 52 45 41 54 e original CREAT
11ce0 45 20 54 41 42 4c 45 20 73 74 6d 74 2e 0a 2a 2a E TABLE stmt..**
11cf0 0a 2a 2a 20 20 20 22 73 74 6f 72 61 67 65 20 63 .** "storage c
11d00 6f 6c 75 6d 6e 20 69 6e 64 65 78 22 20 20 20 54 olumn index" T
11d10 68 69 73 20 69 73 20 74 68 65 20 69 6e 64 65 78 his is the index
11d20 20 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e 20 69 of the column i
11d30 6e 20 74 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 n the.**
11d40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11d50 20 20 20 20 72 65 63 6f 72 64 20 42 4c 4f 42 20 record BLOB
11d60 67 65 6e 65 72 61 74 65 64 20 62 79 20 74 68 65 generated by the
11d70 20 4f 50 5f 4d 61 6b 65 52 65 63 6f 72 64 0a 2a OP_MakeRecord.*
11d80 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
11d90 20 20 20 20 20 20 20 20 20 20 20 20 20 6f 70 63 opc
11da0 6f 64 65 2e 20 20 54 68 65 20 73 74 6f 72 61 67 ode. The storag
11db0 65 20 63 6f 6c 75 6d 6e 20 69 6e 64 65 78 20 69 e column index i
11dc0 73 20 6c 65 73 73 20 74 68 61 6e 0a 2a 2a 20 20 s less than.**
11dd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11de0 20 20 20 20 20 20 20 20 20 20 6f 72 20 65 71 75 or equ
11df0 61 6c 20 74 6f 20 74 68 65 20 74 61 62 6c 65 20 al to the table
11e00 63 6f 6c 75 6d 6e 20 69 6e 64 65 78 2e 20 20 49 column index. I
11e10 74 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 t is.**
11e20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11e30 20 20 20 65 71 75 61 6c 20 69 66 20 61 6e 64 20 equal if and
11e40 6f 6e 6c 79 20 69 66 20 74 68 65 72 65 20 61 72 only if there ar
11e50 65 20 6e 6f 20 56 49 52 54 55 41 4c 0a 2a 2a 20 e no VIRTUAL.**
11e60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11e70 20 20 20 20 20 20 20 20 20 20 20 63 6f 6c 75 6d colum
11e80 6e 73 20 74 6f 20 74 68 65 20 6c 65 66 74 2e 0a ns to the left..
11e90 2a 2f 0a 73 74 72 75 63 74 20 43 6f 6c 75 6d 6e */.struct Column
11ea0 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 {. char *zName
11eb0 3b 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 ; /* Name of
11ec0 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2c 20 5c 30 this column, \0
11ed0 30 30 2c 20 74 68 65 6e 20 74 68 65 20 74 79 70 00, then the typ
11ee0 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 44 66 e */. Expr *pDf
11ef0 6c 74 3b 20 20 20 20 20 2f 2a 20 44 65 66 61 75 lt; /* Defau
11f00 6c 74 20 76 61 6c 75 65 20 6f 72 20 47 45 4e 45 lt value or GENE
11f10 52 41 54 45 44 20 41 4c 57 41 59 53 20 41 53 20 RATED ALWAYS AS
11f20 76 61 6c 75 65 20 2a 2f 0a 20 20 63 68 61 72 20 value */. char
11f30 2a 7a 43 6f 6c 6c 3b 20 20 20 20 20 2f 2a 20 43 *zColl; /* C
11f40 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
11f50 65 2e 20 20 49 66 20 4e 55 4c 4c 2c 20 75 73 65 e. If NULL, use
11f60 20 74 68 65 20 64 65 66 61 75 6c 74 20 2a 2f 0a the default */.
11f70 20 20 75 38 20 6e 6f 74 4e 75 6c 6c 3b 20 20 20 u8 notNull;
11f80 20 20 20 2f 2a 20 41 6e 20 4f 45 5f 20 63 6f 64 /* An OE_ cod
11f90 65 20 66 6f 72 20 68 61 6e 64 6c 69 6e 67 20 61 e for handling a
11fa0 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e 73 74 72 NOT NULL constr
11fb0 61 69 6e 74 20 2a 2f 0a 20 20 63 68 61 72 20 61 aint */. char a
11fc0 66 66 69 6e 69 74 79 3b 20 20 20 2f 2a 20 4f 6e ffinity; /* On
11fd0 65 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 5f e of the SQLITE_
11fe0 41 46 46 5f 2e 2e 2e 20 76 61 6c 75 65 73 20 2a AFF_... values *
11ff0 2f 0a 20 20 75 38 20 73 7a 45 73 74 3b 20 20 20 /. u8 szEst;
12000 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 /* Estimate
12010 64 20 73 69 7a 65 20 6f 66 20 76 61 6c 75 65 20 d size of value
12020 69 6e 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 in this column.
12030 73 69 7a 65 6f 66 28 49 4e 54 29 3d 3d 31 20 2a sizeof(INT)==1 *
12040 2f 0a 20 20 75 31 36 20 63 6f 6c 46 6c 61 67 73 /. u16 colFlags
12050 3b 20 20 20 20 2f 2a 20 42 6f 6f 6c 65 61 6e 20 ; /* Boolean
12060 70 72 6f 70 65 72 74 69 65 73 2e 20 20 53 65 65 properties. See
12070 20 43 4f 4c 46 4c 41 47 5f 20 64 65 66 69 6e 65 COLFLAG_ define
12080 73 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 0a 2f s below */.};../
12090 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
120a0 20 66 6f 72 20 43 6f 6c 75 6d 6e 2e 63 6f 6c 46 for Column.colF
120b0 6c 61 67 73 3a 0a 2a 2f 0a 23 64 65 66 69 6e 65 lags:.*/.#define
120c0 20 43 4f 4c 46 4c 41 47 5f 50 52 49 4d 4b 45 59 COLFLAG_PRIMKEY
120d0 20 20 20 30 78 30 30 30 31 20 20 20 2f 2a 20 43 0x0001 /* C
120e0 6f 6c 75 6d 6e 20 69 73 20 70 61 72 74 20 6f 66 olumn is part of
120f0 20 74 68 65 20 70 72 69 6d 61 72 79 20 6b 65 79 the primary key
12100 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 4c 46 */.#define COLF
12110 4c 41 47 5f 48 49 44 44 45 4e 20 20 20 20 30 78 LAG_HIDDEN 0x
12120 30 30 30 32 20 20 20 2f 2a 20 41 20 68 69 64 64 0002 /* A hidd
12130 65 6e 20 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 76 en column in a v
12140 69 72 74 75 61 6c 20 74 61 62 6c 65 20 2a 2f 0a irtual table */.
12150 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f #define COLFLAG_
12160 48 41 53 54 59 50 45 20 20 20 30 78 30 30 30 34 HASTYPE 0x0004
12170 20 20 20 2f 2a 20 54 79 70 65 20 6e 61 6d 65 20 /* Type name
12180 66 6f 6c 6c 6f 77 73 20 63 6f 6c 75 6d 6e 20 6e follows column n
12190 61 6d 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 ame */.#define C
121a0 4f 4c 46 4c 41 47 5f 55 4e 49 51 55 45 20 20 20 OLFLAG_UNIQUE
121b0 20 30 78 30 30 30 38 20 20 20 2f 2a 20 43 6f 6c 0x0008 /* Col
121c0 75 6d 6e 20 64 65 66 20 63 6f 6e 74 61 69 6e 73 umn def contains
121d0 20 22 55 4e 49 51 55 45 22 20 6f 72 20 22 50 4b "UNIQUE" or "PK
121e0 22 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 4c " */.#define COL
121f0 46 4c 41 47 5f 53 4f 52 54 45 52 52 45 46 20 30 FLAG_SORTERREF 0
12200 78 30 30 31 30 20 20 20 2f 2a 20 55 73 65 20 73 x0010 /* Use s
12210 6f 72 74 65 72 2d 72 65 66 73 20 77 69 74 68 20 orter-refs with
12220 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 this column */.#
12230 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 56 define COLFLAG_V
12240 49 52 54 55 41 4c 20 20 20 30 78 30 30 32 30 20 IRTUAL 0x0020
12250 20 20 2f 2a 20 47 45 4e 45 52 41 54 45 44 20 41 /* GENERATED A
12260 4c 57 41 59 53 20 41 53 20 2e 2e 2e 20 56 49 52 LWAYS AS ... VIR
12270 54 55 41 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 TUAL */.#define
12280 43 4f 4c 46 4c 41 47 5f 53 54 4f 52 45 44 20 20 COLFLAG_STORED
12290 20 20 30 78 30 30 34 30 20 20 20 2f 2a 20 47 45 0x0040 /* GE
122a0 4e 45 52 41 54 45 44 20 41 4c 57 41 59 53 20 41 NERATED ALWAYS A
122b0 53 20 2e 2e 2e 20 53 54 4f 52 45 44 20 2a 2f 0a S ... STORED */.
122c0 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f #define COLFLAG_
122d0 42 55 53 59 20 20 20 20 20 20 30 78 30 30 38 30 BUSY 0x0080
122e0 20 20 20 2f 2a 20 42 6c 6f 63 6b 73 20 72 65 63 /* Blocks rec
122f0 75 72 73 69 6f 6e 20 6f 6e 20 47 45 4e 45 52 41 ursion on GENERA
12300 54 45 44 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 23 TED columns */.#
12310 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 4e define COLFLAG_N
12320 4f 54 41 56 41 49 4c 20 20 30 78 30 31 30 30 20 OTAVAIL 0x0100
12330 20 20 2f 2a 20 53 54 4f 52 45 44 20 63 6f 6c 75 /* STORED colu
12340 6d 6e 20 6e 6f 74 20 79 65 74 20 63 61 6c 63 75 mn not yet calcu
12350 6c 61 74 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 lated */.#define
12360 20 43 4f 4c 46 4c 41 47 5f 47 45 4e 45 52 41 54 COLFLAG_GENERAT
12370 45 44 20 30 78 30 30 36 30 20 20 20 2f 2a 20 43 ED 0x0060 /* C
12380 6f 6d 62 6f 3a 20 5f 53 54 4f 52 45 44 2c 20 5f ombo: _STORED, _
12390 56 49 52 54 55 41 4c 20 2a 2f 0a 23 64 65 66 69 VIRTUAL */.#defi
123a0 6e 65 20 43 4f 4c 46 4c 41 47 5f 4e 4f 49 4e 53 ne COLFLAG_NOINS
123b0 45 52 54 20 20 30 78 30 30 36 32 20 20 20 2f 2a ERT 0x0062 /*
123c0 20 43 6f 6d 62 6f 3a 20 5f 48 49 44 44 45 4e 2c Combo: _HIDDEN,
123d0 20 5f 53 54 4f 52 45 44 2c 20 5f 56 49 52 54 55 _STORED, _VIRTU
123e0 41 4c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 22 AL */../*.** A "
123f0 43 6f 6c 6c 61 74 69 6e 67 20 53 65 71 75 65 6e Collating Sequen
12400 63 65 22 20 69 73 20 64 65 66 69 6e 65 64 20 62 ce" is defined b
12410 79 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 y an instance of
12420 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a the following.*
12430 2a 20 73 74 72 75 63 74 75 72 65 2e 20 43 6f 6e * structure. Con
12440 63 65 70 74 75 61 6c 6c 79 2c 20 61 20 63 6f 6c ceptually, a col
12450 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 lating sequence
12460 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 20 6e 61 consists of a na
12470 6d 65 20 61 6e 64 0a 2a 2a 20 61 20 63 6f 6d 70 me and.** a comp
12480 61 72 69 73 6f 6e 20 72 6f 75 74 69 6e 65 20 74 arison routine t
12490 68 61 74 20 64 65 66 69 6e 65 73 20 74 68 65 20 hat defines the
124a0 6f 72 64 65 72 20 6f 66 20 74 68 61 74 20 73 65 order of that se
124b0 71 75 65 6e 63 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 quence..**.** If
124c0 20 43 6f 6c 6c 53 65 71 2e 78 43 6d 70 20 69 73 CollSeq.xCmp is
124d0 20 4e 55 4c 4c 2c 20 69 74 20 6d 65 61 6e 73 20 NULL, it means
124e0 74 68 61 74 20 74 68 65 0a 2a 2a 20 63 6f 6c 6c that the.** coll
124f0 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 69 ating sequence i
12500 73 20 75 6e 64 65 66 69 6e 65 64 2e 20 20 49 6e s undefined. In
12510 64 69 63 65 73 20 62 75 69 6c 74 20 6f 6e 20 61 dices built on a
12520 6e 20 75 6e 64 65 66 69 6e 65 64 0a 2a 2a 20 63 n undefined.** c
12530 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 ollating sequenc
12540 65 20 6d 61 79 20 6e 6f 74 20 62 65 20 72 65 61 e may not be rea
12550 64 20 6f 72 20 77 72 69 74 74 65 6e 2e 0a 2a 2f d or written..*/
12560 0a 73 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 .struct CollSeq
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 20 2f 2a 20 4e 61 6d /* Nam
12590 65 20 6f 66 20 74 68 65 20 63 6f 6c 6c 61 74 69 e of the collati
125a0 6e 67 20 73 65 71 75 65 6e 63 65 2c 20 55 54 46 ng sequence, UTF
125b0 2d 38 20 65 6e 63 6f 64 65 64 20 2a 2f 0a 20 20 -8 encoded */.
125c0 75 38 20 65 6e 63 3b 20 20 20 20 20 20 20 20 20 u8 enc;
125d0 20 20 20 20 20 20 2f 2a 20 54 65 78 74 20 65 6e /* Text en
125e0 63 6f 64 69 6e 67 20 68 61 6e 64 6c 65 64 20 62 coding handled b
125f0 79 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 76 6f y xCmp() */. vo
12600 69 64 20 2a 70 55 73 65 72 3b 20 20 20 20 20 20 id *pUser;
12610 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 /* First arg
12620 75 6d 65 6e 74 20 74 6f 20 78 43 6d 70 28 29 20 ument to xCmp()
12630 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 43 6d 70 29 */. int (*xCmp)
12640 28 76 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f 6e 73 (void*,int, cons
12650 74 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 63 6f t void*, int, co
12660 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 76 6f nst void*);. vo
12670 69 64 20 28 2a 78 44 65 6c 29 28 76 6f 69 64 2a id (*xDel)(void*
12680 29 3b 20 20 2f 2a 20 44 65 73 74 72 75 63 74 6f ); /* Destructo
12690 72 20 66 6f 72 20 70 55 73 65 72 20 2a 2f 0a 7d r for pUser */.}
126a0 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 73 6f 72 74 20 ;../*.** A sort
126b0 6f 72 64 65 72 20 63 61 6e 20 62 65 20 65 69 74 order can be eit
126c0 68 65 72 20 41 53 43 20 6f 72 20 44 45 53 43 2e her ASC or DESC.
126d0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
126e0 54 45 5f 53 4f 5f 41 53 43 20 20 20 20 20 20 20 TE_SO_ASC
126f0 30 20 20 2f 2a 20 53 6f 72 74 20 69 6e 20 61 73 0 /* Sort in as
12700 63 65 6e 64 69 6e 67 20 6f 72 64 65 72 20 2a 2f cending order */
12710 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
12720 53 4f 5f 44 45 53 43 20 20 20 20 20 20 31 20 20 SO_DESC 1
12730 2f 2a 20 53 6f 72 74 20 69 6e 20 61 73 63 65 6e /* Sort in ascen
12740 64 69 6e 67 20 6f 72 64 65 72 20 2a 2f 0a 23 64 ding order */.#d
12750 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f efine SQLITE_SO_
12760 55 4e 44 45 46 49 4e 45 44 20 2d 31 20 2f 2a 20 UNDEFINED -1 /*
12770 4e 6f 20 73 6f 72 74 20 6f 72 64 65 72 20 73 70 No sort order sp
12780 65 63 69 66 69 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a ecified */../*.*
12790 2a 20 43 6f 6c 75 6d 6e 20 61 66 66 69 6e 69 74 * Column affinit
127a0 79 20 74 79 70 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 y types..**.** T
127b0 68 65 73 65 20 75 73 65 64 20 74 6f 20 68 61 76 hese used to hav
127c0 65 20 6d 6e 65 6d 6f 6e 69 63 20 6e 61 6d 65 20 e mnemonic name
127d0 6c 69 6b 65 20 27 69 27 20 66 6f 72 20 53 51 4c like 'i' for SQL
127e0 49 54 45 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 ITE_AFF_INTEGER
127f0 61 6e 64 0a 2a 2a 20 27 74 27 20 66 6f 72 20 53 and.** 't' for S
12800 51 4c 49 54 45 5f 41 46 46 5f 54 45 58 54 2e 20 QLITE_AFF_TEXT.
12810 20 42 75 74 20 77 65 20 63 61 6e 20 73 61 76 65 But we can save
12820 20 61 20 6c 69 74 74 6c 65 20 73 70 61 63 65 20 a little space
12830 61 6e 64 20 69 6d 70 72 6f 76 65 0a 2a 2a 20 74 and improve.** t
12840 68 65 20 73 70 65 65 64 20 61 20 6c 69 74 74 6c he speed a littl
12850 65 20 62 79 20 6e 75 6d 62 65 72 69 6e 67 20 74 e by numbering t
12860 68 65 20 76 61 6c 75 65 73 20 63 6f 6e 73 65 63 he values consec
12870 75 74 69 76 65 6c 79 2e 0a 2a 2a 0a 2a 2a 20 42 utively..**.** B
12880 75 74 20 72 61 74 68 65 72 20 74 68 61 6e 20 73 ut rather than s
12890 74 61 72 74 20 77 69 74 68 20 30 20 6f 72 20 31 tart with 0 or 1
128a0 2c 20 77 65 20 62 65 67 69 6e 20 77 69 74 68 20 , we begin with
128b0 27 41 27 2e 20 20 54 68 61 74 20 77 61 79 2c 0a 'A'. That way,.
128c0 2a 2a 20 77 68 65 6e 20 6d 75 6c 74 69 70 6c 65 ** when multiple
128d0 20 61 66 66 69 6e 69 74 79 20 74 79 70 65 73 20 affinity types
128e0 61 72 65 20 63 6f 6e 63 61 74 65 6e 61 74 65 64 are concatenated
128f0 20 69 6e 74 6f 20 61 20 73 74 72 69 6e 67 20 61 into a string a
12900 6e 64 0a 2a 2a 20 75 73 65 64 20 61 73 20 74 68 nd.** used as th
12910 65 20 50 34 20 6f 70 65 72 61 6e 64 2c 20 74 68 e P4 operand, th
12920 65 79 20 77 69 6c 6c 20 62 65 20 6d 6f 72 65 20 ey will be more
12930 72 65 61 64 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 readable..**.**
12940 4e 6f 74 65 20 61 6c 73 6f 20 74 68 61 74 20 74 Note also that t
12950 68 65 20 6e 75 6d 65 72 69 63 20 74 79 70 65 73 he numeric types
12960 20 61 72 65 20 67 72 6f 75 70 65 64 20 74 6f 67 are grouped tog
12970 65 74 68 65 72 20 73 6f 20 74 68 61 74 20 74 65 ether so that te
12980 73 74 69 6e 67 0a 2a 2a 20 66 6f 72 20 61 20 6e sting.** for a n
12990 75 6d 65 72 69 63 20 74 79 70 65 20 69 73 20 61 umeric type is a
129a0 20 73 69 6e 67 6c 65 20 63 6f 6d 70 61 72 69 73 single comparis
129b0 6f 6e 2e 20 20 41 6e 64 20 74 68 65 20 42 4c 4f on. And the BLO
129c0 42 20 74 79 70 65 20 69 73 20 66 69 72 73 74 2e B type is first.
129d0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
129e0 54 45 5f 41 46 46 5f 4e 4f 4e 45 20 20 20 20 20 TE_AFF_NONE
129f0 30 78 34 30 20 20 2f 2a 20 27 40 27 20 2a 2f 0a 0x40 /* '@' */.
12a00 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
12a10 46 46 5f 42 4c 4f 42 20 20 20 20 20 30 78 34 31 FF_BLOB 0x41
12a20 20 20 2f 2a 20 27 41 27 20 2a 2f 0a 23 64 65 66 /* 'A' */.#def
12a30 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 ine SQLITE_AFF_T
12a40 45 58 54 20 20 20 20 20 30 78 34 32 20 20 2f 2a EXT 0x42 /*
12a50 20 27 42 27 20 2a 2f 0a 23 64 65 66 69 6e 65 20 'B' */.#define
12a60 53 51 4c 49 54 45 5f 41 46 46 5f 4e 55 4d 45 52 SQLITE_AFF_NUMER
12a70 49 43 20 20 30 78 34 33 20 20 2f 2a 20 27 43 27 IC 0x43 /* 'C'
12a80 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
12a90 54 45 5f 41 46 46 5f 49 4e 54 45 47 45 52 20 20 TE_AFF_INTEGER
12aa0 30 78 34 34 20 20 2f 2a 20 27 44 27 20 2a 2f 0a 0x44 /* 'D' */.
12ab0 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
12ac0 46 46 5f 52 45 41 4c 20 20 20 20 20 30 78 34 35 FF_REAL 0x45
12ad0 20 20 2f 2a 20 27 45 27 20 2a 2f 0a 0a 23 64 65 /* 'E' */..#de
12ae0 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 75 fine sqlite3IsNu
12af0 6d 65 72 69 63 41 66 66 69 6e 69 74 79 28 58 29 mericAffinity(X)
12b00 20 20 28 28 58 29 3e 3d 53 51 4c 49 54 45 5f 41 ((X)>=SQLITE_A
12b10 46 46 5f 4e 55 4d 45 52 49 43 29 0a 0a 2f 2a 0a FF_NUMERIC)../*.
12b20 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 41 46 ** The SQLITE_AF
12b30 46 5f 4d 41 53 4b 20 76 61 6c 75 65 73 20 6d 61 F_MASK values ma
12b40 73 6b 73 20 6f 66 66 20 74 68 65 20 73 69 67 6e sks off the sign
12b50 69 66 69 63 61 6e 74 20 62 69 74 73 20 6f 66 20 ificant bits of
12b60 61 6e 0a 2a 2a 20 61 66 66 69 6e 69 74 79 20 76 an.** affinity v
12b70 61 6c 75 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 alue..*/.#define
12b80 20 53 51 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b SQLITE_AFF_MASK
12b90 20 20 20 20 20 30 78 34 37 0a 0a 2f 2a 0a 2a 2a 0x47../*.**
12ba0 20 41 64 64 69 74 69 6f 6e 61 6c 20 62 69 74 20 Additional bit
12bb0 76 61 6c 75 65 73 20 74 68 61 74 20 63 61 6e 20 values that can
12bc0 62 65 20 4f 52 65 64 20 77 69 74 68 20 61 6e 20 be ORed with an
12bd0 61 66 66 69 6e 69 74 79 20 77 69 74 68 6f 75 74 affinity without
12be0 0a 2a 2a 20 63 68 61 6e 67 69 6e 67 20 74 68 65 .** changing the
12bf0 20 61 66 66 69 6e 69 74 79 2e 0a 2a 2a 0a 2a 2a affinity..**.**
12c00 20 54 68 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e The SQLITE_NOTN
12c10 55 4c 4c 20 66 6c 61 67 20 69 73 20 61 20 63 6f ULL flag is a co
12c20 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 4e 55 4c mbination of NUL
12c30 4c 45 51 20 61 6e 64 20 4a 55 4d 50 49 46 4e 55 LEQ and JUMPIFNU
12c40 4c 4c 2e 0a 2a 2a 20 49 74 20 63 61 75 73 65 73 LL..** It causes
12c50 20 61 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 an assert() to
12c60 66 69 72 65 20 69 66 20 65 69 74 68 65 72 20 6f fire if either o
12c70 70 65 72 61 6e 64 20 74 6f 20 61 20 63 6f 6d 70 perand to a comp
12c80 61 72 69 73 6f 6e 0a 2a 2a 20 6f 70 65 72 61 74 arison.** operat
12c90 6f 72 20 69 73 20 4e 55 4c 4c 2e 20 20 49 74 20 or is NULL. It
12ca0 69 73 20 61 64 64 65 64 20 74 6f 20 63 65 72 74 is added to cert
12cb0 61 69 6e 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f ain comparison o
12cc0 70 65 72 61 74 6f 72 73 20 74 6f 0a 2a 2a 20 70 perators to.** p
12cd0 72 6f 76 65 20 74 68 61 74 20 74 68 65 20 6f 70 rove that the op
12ce0 65 72 61 6e 64 73 20 61 72 65 20 61 6c 77 61 79 erands are alway
12cf0 73 20 4e 4f 54 20 4e 55 4c 4c 2e 0a 2a 2f 0a 23 s NOT NULL..*/.#
12d00 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4b 45 define SQLITE_KE
12d10 45 50 4e 55 4c 4c 20 20 20 20 20 30 78 30 38 20 EPNULL 0x08
12d20 20 2f 2a 20 55 73 65 64 20 62 79 20 76 65 63 74 /* Used by vect
12d30 6f 72 20 3d 3d 20 6f 72 20 3c 3e 20 2a 2f 0a 23 or == or <> */.#
12d40 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4a 55 define SQLITE_JU
12d50 4d 50 49 46 4e 55 4c 4c 20 20 20 30 78 31 30 20 MPIFNULL 0x10
12d60 20 2f 2a 20 6a 75 6d 70 73 20 69 66 20 65 69 74 /* jumps if eit
12d70 68 65 72 20 6f 70 65 72 61 6e 64 20 69 73 20 4e her operand is N
12d80 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ULL */.#define S
12d90 51 4c 49 54 45 5f 53 54 4f 52 45 50 32 20 20 20 QLITE_STOREP2
12da0 20 20 20 30 78 32 30 20 20 2f 2a 20 53 74 6f 72 0x20 /* Stor
12db0 65 20 72 65 73 75 6c 74 20 69 6e 20 72 65 67 5b e result in reg[
12dc0 50 32 5d 20 72 61 74 68 65 72 20 74 68 61 6e 20 P2] rather than
12dd0 6a 75 6d 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 jump */.#define
12de0 53 51 4c 49 54 45 5f 4e 55 4c 4c 45 51 20 20 20 SQLITE_NULLEQ
12df0 20 20 20 20 30 78 38 30 20 20 2f 2a 20 4e 55 4c 0x80 /* NUL
12e00 4c 3d 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e L=NULL */.#defin
12e10 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c e SQLITE_NOTNULL
12e20 20 20 20 20 20 20 30 78 39 30 20 20 2f 2a 20 41 0x90 /* A
12e30 73 73 65 72 74 20 74 68 61 74 20 6f 70 65 72 61 ssert that opera
12e40 6e 64 73 20 61 72 65 20 6e 65 76 65 72 20 4e 55 nds are never NU
12e50 4c 4c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 LL */../*.** An
12e60 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 73 20 74 object of this t
12e70 79 70 65 20 69 73 20 63 72 65 61 74 65 64 20 66 ype is created f
12e80 6f 72 20 65 61 63 68 20 76 69 72 74 75 61 6c 20 or each virtual
12e90 74 61 62 6c 65 20 70 72 65 73 65 6e 74 20 69 6e table present in
12ea0 0a 2a 2a 20 74 68 65 20 64 61 74 61 62 61 73 65 .** the database
12eb0 20 73 63 68 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 49 schema..**.** I
12ec0 66 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 f the database s
12ed0 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c chema is shared,
12ee0 20 74 68 65 6e 20 74 68 65 72 65 20 69 73 20 6f then there is o
12ef0 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 ne instance of t
12f00 68 69 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 his.** structure
12f10 20 66 6f 72 20 65 61 63 68 20 64 61 74 61 62 61 for each databa
12f20 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 28 73 se connection (s
12f30 71 6c 69 74 65 33 2a 29 20 74 68 61 74 20 75 73 qlite3*) that us
12f40 65 73 20 74 68 65 20 73 68 61 72 65 64 0a 2a 2a es the shared.**
12f50 20 73 63 68 65 6d 61 2e 20 54 68 69 73 20 69 73 schema. This is
12f60 20 62 65 63 61 75 73 65 20 65 61 63 68 20 64 61 because each da
12f70 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
12f80 6e 20 72 65 71 75 69 72 65 73 20 69 74 73 20 6f n requires its o
12f90 77 6e 20 75 6e 69 71 75 65 0a 2a 2a 20 69 6e 73 wn unique.** ins
12fa0 74 61 6e 63 65 20 6f 66 20 74 68 65 20 73 71 6c tance of the sql
12fb0 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c ite3_vtab* handl
12fc0 65 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 e used to access
12fd0 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 the virtual tab
12fe0 6c 65 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 le.** implementa
12ff0 74 69 6f 6e 2e 20 73 71 6c 69 74 65 33 5f 76 74 tion. sqlite3_vt
13000 61 62 2a 20 68 61 6e 64 6c 65 73 20 63 61 6e 20 ab* handles can
13010 6e 6f 74 20 62 65 20 73 68 61 72 65 64 20 62 65 not be shared be
13020 74 77 65 65 6e 0a 2a 2a 20 64 61 74 61 62 61 73 tween.** databas
13030 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 2c 20 65 e connections, e
13040 76 65 6e 20 77 68 65 6e 20 74 68 65 20 72 65 73 ven when the res
13050 74 20 6f 66 20 74 68 65 20 69 6e 2d 6d 65 6d 6f t of the in-memo
13060 72 79 20 64 61 74 61 62 61 73 65 0a 2a 2a 20 73 ry database.** s
13070 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c chema is shared,
13080 20 61 73 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e as the implemen
13090 74 61 74 69 6f 6e 20 6f 66 74 65 6e 20 73 74 6f tation often sto
130a0 72 65 73 20 74 68 65 20 64 61 74 61 62 61 73 65 res the database
130b0 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 .** connection h
130c0 61 6e 64 6c 65 20 70 61 73 73 65 64 20 74 6f 20 andle passed to
130d0 69 74 20 76 69 61 20 74 68 65 20 78 43 6f 6e 6e it via the xConn
130e0 65 63 74 28 29 20 6f 72 20 78 43 72 65 61 74 65 ect() or xCreate
130f0 28 29 20 6d 65 74 68 6f 64 0a 2a 2a 20 64 75 72 () method.** dur
13100 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ing initializati
13110 6f 6e 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 20 54 on internally. T
13120 68 69 73 20 64 61 74 61 62 61 73 65 20 63 6f 6e his database con
13130 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 6d nection handle m
13140 61 79 0a 2a 2a 20 74 68 65 6e 20 62 65 20 75 73 ay.** then be us
13150 65 64 20 62 79 20 74 68 65 20 76 69 72 74 75 61 ed by the virtua
13160 6c 20 74 61 62 6c 65 20 69 6d 70 6c 65 6d 65 6e l table implemen
13170 74 61 74 69 6f 6e 20 74 6f 20 61 63 63 65 73 73 tation to access
13180 20 72 65 61 6c 20 74 61 62 6c 65 73 0a 2a 2a 20 real tables.**
13190 77 69 74 68 69 6e 20 74 68 65 20 64 61 74 61 62 within the datab
131a0 61 73 65 2e 20 53 6f 20 74 68 61 74 20 74 68 65 ase. So that the
131b0 79 20 61 70 70 65 61 72 20 61 73 20 70 61 72 74 y appear as part
131c0 20 6f 66 20 74 68 65 20 63 61 6c 6c 65 72 73 0a of the callers.
131d0 2a 2a 20 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 ** transaction,
131e0 74 68 65 73 65 20 61 63 63 65 73 73 65 73 20 6e these accesses n
131f0 65 65 64 20 74 6f 20 62 65 20 6d 61 64 65 20 76 eed to be made v
13200 69 61 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 ia the same data
13210 62 61 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 base.** connecti
13220 6f 6e 20 61 73 20 74 68 61 74 20 75 73 65 64 20 on as that used
13230 74 6f 20 65 78 65 63 75 74 65 20 53 51 4c 20 6f to execute SQL o
13240 70 65 72 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 perations on the
13250 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0a virtual table..
13260 2a 2a 0a 2a 2a 20 41 6c 6c 20 56 54 61 62 6c 65 **.** All VTable
13270 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 63 6f objects that co
13280 72 72 65 73 70 6f 6e 64 20 74 6f 20 61 20 73 69 rrespond to a si
13290 6e 67 6c 65 20 74 61 62 6c 65 20 69 6e 20 61 20 ngle table in a
132a0 73 68 61 72 65 64 0a 2a 2a 20 64 61 74 61 62 61 shared.** databa
132b0 73 65 20 73 63 68 65 6d 61 20 61 72 65 20 69 6e se schema are in
132c0 69 74 69 61 6c 6c 79 20 73 74 6f 72 65 64 20 69 itially stored i
132d0 6e 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 n a linked-list
132e0 70 6f 69 6e 74 65 64 20 74 6f 20 62 79 0a 2a 2a pointed to by.**
132f0 20 74 68 65 20 54 61 62 6c 65 2e 70 56 54 61 62 the Table.pVTab
13300 6c 65 20 6d 65 6d 62 65 72 20 76 61 72 69 61 62 le member variab
13310 6c 65 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 le of the corres
13320 70 6f 6e 64 69 6e 67 20 54 61 62 6c 65 20 6f 62 ponding Table ob
13330 6a 65 63 74 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e ject..** When an
13340 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 sqlite3_prepare
13350 28 29 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 () operation is
13360 72 65 71 75 69 72 65 64 20 74 6f 20 61 63 63 65 required to acce
13370 73 73 20 74 68 65 20 76 69 72 74 75 61 6c 0a 2a ss the virtual.*
13380 2a 20 74 61 62 6c 65 2c 20 69 74 20 73 65 61 72 * table, it sear
13390 63 68 65 73 20 74 68 65 20 6c 69 73 74 20 66 6f ches the list fo
133a0 72 20 74 68 65 20 56 54 61 62 6c 65 20 74 68 61 r the VTable tha
133b0 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f t corresponds to
133c0 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 the.** database
133d0 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 6f 69 6e connection doin
133e0 67 20 74 68 65 20 70 72 65 70 61 72 69 6e 67 20 g the preparing
133f0 73 6f 20 61 73 20 74 6f 20 75 73 65 20 74 68 65 so as to use the
13400 20 63 6f 72 72 65 63 74 0a 2a 2a 20 73 71 6c 69 correct.** sqli
13410 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 te3_vtab* handle
13420 20 69 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 64 in the compiled
13430 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 query..**.** Wh
13440 65 6e 20 61 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 en an in-memory
13450 54 61 62 6c 65 20 6f 62 6a 65 63 74 20 69 73 20 Table object is
13460 64 65 6c 65 74 65 64 20 28 66 6f 72 20 65 78 61 deleted (for exa
13470 6d 70 6c 65 20 77 68 65 6e 20 74 68 65 0a 2a 2a mple when the.**
13480 20 73 63 68 65 6d 61 20 69 73 20 62 65 69 6e 67 schema is being
13490 20 72 65 6c 6f 61 64 65 64 20 66 6f 72 20 73 6f reloaded for so
134a0 6d 65 20 72 65 61 73 6f 6e 29 2c 20 74 68 65 20 me reason), the
134b0 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 61 VTable objects a
134c0 72 65 20 6e 6f 74 0a 2a 2a 20 64 65 6c 65 74 65 re not.** delete
134d0 64 20 61 6e 64 20 74 68 65 20 73 71 6c 69 74 65 d and the sqlite
134e0 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 3_vtab* handles
134f0 61 72 65 20 6e 6f 74 20 78 44 69 73 63 6f 6e 6e are not xDisconn
13500 65 63 74 28 29 65 64 0a 2a 2a 20 69 6d 6d 65 64 ect()ed.** immed
13510 69 61 74 65 6c 79 2e 20 49 6e 73 74 65 61 64 2c iately. Instead,
13520 20 74 68 65 79 20 61 72 65 20 6d 6f 76 65 64 20 they are moved
13530 66 72 6f 6d 20 74 68 65 20 54 61 62 6c 65 2e 70 from the Table.p
13540 56 54 61 62 6c 65 20 6c 69 73 74 20 74 6f 0a 2a VTable list to.*
13550 2a 20 61 6e 6f 74 68 65 72 20 6c 69 6e 6b 65 64 * another linked
13560 20 6c 69 73 74 20 68 65 61 64 65 64 20 62 79 20 list headed by
13570 74 68 65 20 73 71 6c 69 74 65 33 2e 70 44 69 73 the sqlite3.pDis
13580 63 6f 6e 6e 65 63 74 20 6d 65 6d 62 65 72 20 6f connect member o
13590 66 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 f the.** corresp
135a0 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 20 73 onding sqlite3 s
135b0 74 72 75 63 74 75 72 65 2e 20 54 68 65 79 20 61 tructure. They a
135c0 72 65 20 74 68 65 6e 20 64 65 6c 65 74 65 64 2f re then deleted/
135d0 78 44 69 73 63 6f 6e 6e 65 63 74 65 64 0a 2a 2a xDisconnected.**
135e0 20 6e 65 78 74 20 74 69 6d 65 20 61 20 73 74 61 next time a sta
135f0 74 65 6d 65 6e 74 20 69 73 20 70 72 65 70 61 72 tement is prepar
13600 65 64 20 75 73 69 6e 67 20 73 61 69 64 20 73 71 ed using said sq
13610 6c 69 74 65 33 2a 2e 20 54 68 69 73 20 69 73 20 lite3*. This is
13620 64 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 6f 69 64 done.** to avoid
13630 20 64 65 61 64 6c 6f 63 6b 20 69 73 73 75 65 73 deadlock issues
13640 20 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 6c 74 69 involving multi
13650 70 6c 65 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 ple sqlite3.mute
13660 78 20 6d 75 74 65 78 65 73 2e 0a 2a 2a 20 52 65 x mutexes..** Re
13670 66 65 72 20 74 6f 20 63 6f 6d 6d 65 6e 74 73 20 fer to comments
13680 61 62 6f 76 65 20 66 75 6e 63 74 69 6f 6e 20 73 above function s
13690 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b qlite3VtabUnlock
136a0 4c 69 73 74 28 29 20 66 6f 72 20 61 6e 0a 2a 2a List() for an.**
136b0 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 61 73 20 explanation as
136c0 74 6f 20 77 68 79 20 69 74 20 69 73 20 73 61 66 to why it is saf
136d0 65 20 74 6f 20 61 64 64 20 61 6e 20 65 6e 74 72 e to add an entr
136e0 79 20 74 6f 20 61 6e 20 73 71 6c 69 74 65 33 2e y to an sqlite3.
136f0 70 44 69 73 63 6f 6e 6e 65 63 74 0a 2a 2a 20 6c pDisconnect.** l
13700 69 73 74 20 77 69 74 68 6f 75 74 20 68 6f 6c 64 ist without hold
13710 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 70 6f ing the correspo
13720 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 2e 6d 75 nding sqlite3.mu
13730 74 65 78 20 6d 75 74 65 78 2e 0a 2a 2a 0a 2a 2a tex mutex..**.**
13740 20 54 68 65 20 6d 65 6d 6f 72 79 20 66 6f 72 20 The memory for
13750 6f 62 6a 65 63 74 73 20 6f 66 20 74 68 69 73 20 objects of this
13760 74 79 70 65 20 69 73 20 61 6c 77 61 79 73 20 61 type is always a
13770 6c 6c 6f 63 61 74 65 64 20 62 79 0a 2a 2a 20 73 llocated by.** s
13780 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 28 29 qlite3DbMalloc()
13790 2c 20 75 73 69 6e 67 20 74 68 65 20 63 6f 6e 6e , using the conn
137a0 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 73 74 ection handle st
137b0 6f 72 65 64 20 69 6e 20 56 54 61 62 6c 65 2e 64 ored in VTable.d
137c0 62 20 61 73 0a 2a 2a 20 74 68 65 20 66 69 72 73 b as.** the firs
137d0 74 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f 0a 73 t argument..*/.s
137e0 74 72 75 63 74 20 56 54 61 62 6c 65 20 7b 0a 20 truct VTable {.
137f0 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 sqlite3 *db;
13800 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 61 /* Da
13810 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
13820 6e 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 n associated wit
13830 68 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a h this table */.
13840 20 20 4d 6f 64 75 6c 65 20 2a 70 4d 6f 64 3b 20 Module *pMod;
13850 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
13860 6f 69 6e 74 65 72 20 74 6f 20 6d 6f 64 75 6c 65 ointer to module
13870 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
13880 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 76 74 61 */. sqlite3_vta
13890 62 20 2a 70 56 74 61 62 3b 20 20 20 20 20 20 2f b *pVtab; /
138a0 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 76 74 61 * Pointer to vta
138b0 62 20 69 6e 73 74 61 6e 63 65 20 2a 2f 0a 20 20 b instance */.
138c0 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 20 20 int nRef;
138d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
138e0 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 ber of pointers
138f0 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 72 to this structur
13900 65 20 2a 2f 0a 20 20 75 38 20 62 43 6f 6e 73 74 e */. u8 bConst
13910 72 61 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 raint;
13920 20 2f 2a 20 54 72 75 65 20 69 66 20 63 6f 6e 73 /* True if cons
13930 74 72 61 69 6e 74 73 20 61 72 65 20 73 75 70 70 traints are supp
13940 6f 72 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 orted */. int i
13950 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 Savepoint;
13960 20 20 20 20 20 2f 2a 20 44 65 70 74 68 20 6f 66 /* Depth of
13970 20 74 68 65 20 53 41 56 45 50 4f 49 4e 54 20 73 the SAVEPOINT s
13980 74 61 63 6b 20 2a 2f 0a 20 20 56 54 61 62 6c 65 tack */. VTable
13990 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 *pNext;
139a0 20 20 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c /* Next in l
139b0 69 6e 6b 65 64 20 6c 69 73 74 20 28 73 65 65 20 inked list (see
139c0 61 62 6f 76 65 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a above) */.};../*
139d0 0a 2a 2a 20 54 68 65 20 73 63 68 65 6d 61 20 66 .** The schema f
139e0 6f 72 20 65 61 63 68 20 53 51 4c 20 74 61 62 6c or each SQL tabl
139f0 65 20 61 6e 64 20 76 69 65 77 20 69 73 20 72 65 e and view is re
13a00 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 6d presented in mem
13a10 6f 72 79 0a 2a 2a 20 62 79 20 61 6e 20 69 6e 73 ory.** by an ins
13a20 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
13a30 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
13a40 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 61 62 6c ..*/.struct Tabl
13a50 65 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d e {. char *zNam
13a60 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 e; /* Na
13a70 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 me of the table
13a80 6f 72 20 76 69 65 77 20 2a 2f 0a 20 20 43 6f 6c or view */. Col
13a90 75 6d 6e 20 2a 61 43 6f 6c 3b 20 20 20 20 20 20 umn *aCol;
13aa0 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e /* Information
13ab0 20 61 62 6f 75 74 20 65 61 63 68 20 63 6f 6c 75 about each colu
13ac0 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 mn */. Index *p
13ad0 49 6e 64 65 78 3b 20 20 20 20 20 20 20 2f 2a 20 Index; /*
13ae0 4c 69 73 74 20 6f 66 20 53 51 4c 20 69 6e 64 65 List of SQL inde
13af0 78 65 73 20 6f 6e 20 74 68 69 73 20 74 61 62 6c xes on this tabl
13b00 65 2e 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a e. */. Select *
13b10 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 pSelect; /*
13b20 4e 55 4c 4c 20 66 6f 72 20 74 61 62 6c 65 73 2e NULL for tables.
13b30 20 20 50 6f 69 6e 74 73 20 74 6f 20 64 65 66 69 Points to defi
13b40 6e 69 74 69 6f 6e 20 69 66 20 61 20 76 69 65 77 nition if a view
13b50 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 46 4b . */. FKey *pFK
13b60 65 79 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4c ey; /* L
13b70 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 61 6c inked list of al
13b80 6c 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 69 l foreign keys i
13b90 6e 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a n this table */.
13ba0 20 20 63 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b char *zColAff;
13bb0 20 20 20 20 20 20 20 2f 2a 20 53 74 72 69 6e 67 /* String
13bc0 20 64 65 66 69 6e 69 6e 67 20 74 68 65 20 61 66 defining the af
13bd0 66 69 6e 69 74 79 20 6f 66 20 65 61 63 68 20 63 finity of each c
13be0 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 78 70 72 4c olumn */. ExprL
13bf0 69 73 74 20 2a 70 43 68 65 63 6b 3b 20 20 20 20 ist *pCheck;
13c00 2f 2a 20 41 6c 6c 20 43 48 45 43 4b 20 63 6f 6e /* All CHECK con
13c10 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 straints */.
13c20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13c30 20 20 20 2f 2a 20 20 20 2e 2e 2e 20 61 6c 73 6f /* ... also
13c40 20 75 73 65 64 20 61 73 20 63 6f 6c 75 6d 6e 20 used as column
13c50 6e 61 6d 65 20 6c 69 73 74 20 69 6e 20 61 20 56 name list in a V
13c60 49 45 57 20 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 IEW */. int tnu
13c70 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
13c80 20 52 6f 6f 74 20 42 54 72 65 65 20 70 61 67 65 Root BTree page
13c90 20 66 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 for this table
13ca0 2a 2f 0a 20 20 75 33 32 20 6e 54 61 62 52 65 66 */. u32 nTabRef
13cb0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d ; /* Num
13cc0 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 ber of pointers
13cd0 74 6f 20 74 68 69 73 20 54 61 62 6c 65 20 2a 2f to this Table */
13ce0 0a 20 20 75 33 32 20 74 61 62 46 6c 61 67 73 3b . u32 tabFlags;
13cf0 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 73 6b 20 /* Mask
13d00 6f 66 20 54 46 5f 2a 20 76 61 6c 75 65 73 20 2a of TF_* values *
13d10 2f 0a 20 20 69 31 36 20 69 50 4b 65 79 3b 20 20 /. i16 iPKey;
13d20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e /* If n
13d30 6f 74 20 6e 65 67 61 74 69 76 65 2c 20 75 73 65 ot negative, use
13d40 20 61 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 73 20 aCol[iPKey] as
13d50 74 68 65 20 72 6f 77 69 64 20 2a 2f 0a 20 20 69 the rowid */. i
13d60 31 36 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 16 nCol;
13d70 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
13d80 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 columns in this
13d90 20 74 61 62 6c 65 20 2a 2f 0a 20 20 69 31 36 20 table */. i16
13da0 6e 4e 56 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 nNVCol;
13db0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f /* Number of co
13dc0 6c 75 6d 6e 73 20 74 68 61 74 20 61 72 65 20 6e lumns that are n
13dd0 6f 74 20 56 49 52 54 55 41 4c 20 2a 2f 0a 20 20 ot VIRTUAL */.
13de0 4c 6f 67 45 73 74 20 6e 52 6f 77 4c 6f 67 45 73 LogEst nRowLogEs
13df0 74 3b 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 t; /* Estimate
13e00 64 20 72 6f 77 73 20 69 6e 20 74 61 62 6c 65 20 d rows in table
13e10 2d 20 66 72 6f 6d 20 73 71 6c 69 74 65 5f 73 74 - from sqlite_st
13e20 61 74 31 20 74 61 62 6c 65 20 2a 2f 0a 20 20 4c at1 table */. L
13e30 6f 67 45 73 74 20 73 7a 54 61 62 52 6f 77 3b 20 ogEst szTabRow;
13e40 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 /* Estimated
13e50 20 73 69 7a 65 20 6f 66 20 65 61 63 68 20 74 61 size of each ta
13e60 62 6c 65 20 72 6f 77 20 69 6e 20 62 79 74 65 73 ble row in bytes
13e70 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 */.#ifdef SQLIT
13e80 45 5f 45 4e 41 42 4c 45 5f 43 4f 53 54 4d 55 4c E_ENABLE_COSTMUL
13e90 54 0a 20 20 4c 6f 67 45 73 74 20 63 6f 73 74 4d T. LogEst costM
13ea0 75 6c 74 3b 20 20 20 20 20 2f 2a 20 43 6f 73 74 ult; /* Cost
13eb0 20 6d 75 6c 74 69 70 6c 69 65 72 20 66 6f 72 20 multiplier for
13ec0 75 73 69 6e 67 20 74 68 69 73 20 74 61 62 6c 65 using this table
13ed0 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 75 38 20 */.#endif. u8
13ee0 6b 65 79 43 6f 6e 66 3b 20 20 20 20 20 20 20 20 keyConf;
13ef0 20 20 2f 2a 20 57 68 61 74 20 74 6f 20 64 6f 20 /* What to do
13f00 69 6e 20 63 61 73 65 20 6f 66 20 75 6e 69 71 75 in case of uniqu
13f10 65 6e 65 73 73 20 63 6f 6e 66 6c 69 63 74 20 6f eness conflict o
13f20 6e 20 69 50 4b 65 79 20 2a 2f 0a 23 69 66 6e 64 n iPKey */.#ifnd
13f30 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 ef SQLITE_OMIT_A
13f40 4c 54 45 52 54 41 42 4c 45 0a 20 20 69 6e 74 20 LTERTABLE. int
13f50 61 64 64 43 6f 6c 4f 66 66 73 65 74 3b 20 20 20 addColOffset;
13f60 20 2f 2a 20 4f 66 66 73 65 74 20 69 6e 20 43 52 /* Offset in CR
13f70 45 41 54 45 20 54 41 42 4c 45 20 73 74 6d 74 20 EATE TABLE stmt
13f80 74 6f 20 61 64 64 20 61 20 6e 65 77 20 63 6f 6c to add a new col
13f90 75 6d 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 umn */.#endif.#i
13fa0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
13fb0 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 T_VIRTUALTABLE.
13fc0 20 69 6e 74 20 6e 4d 6f 64 75 6c 65 41 72 67 3b int nModuleArg;
13fd0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
13fe0 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 of arguments to
13ff0 74 68 65 20 6d 6f 64 75 6c 65 20 2a 2f 0a 20 20 the module */.
14000 63 68 61 72 20 2a 2a 61 7a 4d 6f 64 75 6c 65 41 char **azModuleA
14010 72 67 3b 20 20 2f 2a 20 30 3a 20 6d 6f 64 75 6c rg; /* 0: modul
14020 65 20 31 3a 20 73 63 68 65 6d 61 20 32 3a 20 76 e 1: schema 2: v
14030 74 61 62 20 6e 61 6d 65 20 33 2e 2e 2e 3a 20 61 tab name 3...: a
14040 72 67 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 rgs */. VTable
14050 2a 70 56 54 61 62 6c 65 3b 20 20 20 20 20 2f 2a *pVTable; /*
14060 20 4c 69 73 74 20 6f 66 20 56 54 61 62 6c 65 20 List of VTable
14070 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a 23 65 6e 64 objects. */.#end
14080 69 66 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 if. Trigger *pT
14090 72 69 67 67 65 72 3b 20 20 20 2f 2a 20 4c 69 73 rigger; /* Lis
140a0 74 20 6f 66 20 74 72 69 67 67 65 72 73 20 73 74 t of triggers st
140b0 6f 72 65 64 20 69 6e 20 70 53 63 68 65 6d 61 20 ored in pSchema
140c0 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 */. Schema *pSc
140d0 68 65 6d 61 3b 20 20 20 20 20 2f 2a 20 53 63 68 hema; /* Sch
140e0 65 6d 61 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ema that contain
140f0 73 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a s this table */.
14100 20 20 54 61 62 6c 65 20 2a 70 4e 65 78 74 5a 6f Table *pNextZo
14110 6d 62 69 65 3b 20 20 2f 2a 20 4e 65 78 74 20 6f mbie; /* Next o
14120 6e 20 74 68 65 20 50 61 72 73 65 2e 70 5a 6f 6d n the Parse.pZom
14130 62 69 65 54 61 62 20 6c 69 73 74 20 2a 2f 0a 7d bieTab list */.}
14140 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 ;../*.** Allowed
14150 20 76 61 6c 75 65 73 20 66 6f 72 20 54 61 62 6c values for Tabl
14160 65 2e 74 61 62 46 6c 61 67 73 2e 0a 2a 2a 0a 2a e.tabFlags..**.*
14170 2a 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 61 * TF_OOOHidden a
14180 70 70 6c 69 65 73 20 74 6f 20 74 61 62 6c 65 73 pplies to tables
14190 20 6f 72 20 76 69 65 77 20 74 68 61 74 20 68 61 or view that ha
141a0 76 65 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e ve hidden column
141b0 73 20 74 68 61 74 20 61 72 65 0a 2a 2a 20 66 6f s that are.** fo
141c0 6c 6c 6f 77 65 64 20 62 79 20 6e 6f 6e 2d 68 69 llowed by non-hi
141d0 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 2e 20 20 45 dden columns. E
141e0 78 61 6d 70 6c 65 3a 20 20 22 43 52 45 41 54 45 xample: "CREATE
141f0 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 VIRTUAL TABLE x
14200 20 55 53 49 4e 47 0a 2a 2a 20 76 74 61 62 31 28 USING.** vtab1(
14210 61 20 48 49 44 44 45 4e 2c 20 62 29 3b 22 2e 20 a HIDDEN, b);".
14220 20 53 69 6e 63 65 20 22 62 22 20 69 73 20 61 20 Since "b" is a
14230 6e 6f 6e 2d 68 69 64 64 65 6e 20 63 6f 6c 75 6d non-hidden colum
14240 6e 20 62 75 74 20 22 61 22 20 69 73 20 68 69 64 n but "a" is hid
14250 64 65 6e 2c 0a 2a 2a 20 74 68 65 20 54 46 5f 4f den,.** the TF_O
14260 4f 4f 48 69 64 64 65 6e 20 61 74 74 72 69 62 75 OOHidden attribu
14270 74 65 20 77 6f 75 6c 64 20 61 70 70 6c 79 20 69 te would apply i
14280 6e 20 74 68 69 73 20 63 61 73 65 2e 20 20 53 75 n this case. Su
14290 63 68 20 74 61 62 6c 65 73 20 72 65 71 75 69 72 ch tables requir
142a0 65 0a 2a 2a 20 73 70 65 63 69 61 6c 20 68 61 6e e.** special han
142b0 64 6c 69 6e 67 20 64 75 72 69 6e 67 20 49 4e 53 dling during INS
142c0 45 52 54 20 70 72 6f 63 65 73 73 69 6e 67 2e 20 ERT processing.
142d0 54 68 65 20 22 4f 4f 4f 22 20 6d 65 61 6e 73 20 The "OOO" means
142e0 22 4f 75 74 20 4f 66 20 4f 72 64 65 72 22 2e 0a "Out Of Order"..
142f0 2a 2a 0a 2a 2a 20 43 6f 6e 73 74 72 61 69 6e 74 **.** Constraint
14300 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 s:.**.**
14310 20 54 46 5f 48 61 73 56 69 72 74 75 61 6c 20 3d TF_HasVirtual =
14320 3d 20 43 4f 4c 46 4c 41 47 5f 56 69 72 74 75 61 = COLFLAG_Virtua
14330 6c 0a 2a 2a 20 20 20 20 20 20 20 20 20 54 46 5f l.** TF_
14340 48 61 73 53 74 6f 72 65 64 20 20 3d 3d 20 43 4f HasStored == CO
14350 4c 46 4c 41 47 5f 53 74 6f 72 65 64 0a 2a 2f 0a LFLAG_Stored.*/.
14360 23 64 65 66 69 6e 65 20 54 46 5f 52 65 61 64 6f #define TF_Reado
14370 6e 6c 79 20 20 20 20 20 20 20 20 30 78 30 30 30 nly 0x000
14380 31 20 20 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 1 /* Read-onl
14390 79 20 73 79 73 74 65 6d 20 74 61 62 6c 65 20 2a y system table *
143a0 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 45 70 68 /.#define TF_Eph
143b0 65 6d 65 72 61 6c 20 20 20 20 20 20 20 30 78 30 emeral 0x0
143c0 30 30 32 20 20 20 20 2f 2a 20 41 6e 20 65 70 68 002 /* An eph
143d0 65 6d 65 72 61 6c 20 74 61 62 6c 65 20 2a 2f 0a emeral table */.
143e0 23 64 65 66 69 6e 65 20 54 46 5f 48 61 73 50 72 #define TF_HasPr
143f0 69 6d 61 72 79 4b 65 79 20 20 20 30 78 30 30 30 imaryKey 0x000
14400 34 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 68 61 4 /* Table ha
14410 73 20 61 20 70 72 69 6d 61 72 79 20 6b 65 79 20 s a primary key
14420 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 41 75 */.#define TF_Au
14430 74 6f 69 6e 63 72 65 6d 65 6e 74 20 20 20 30 78 toincrement 0x
14440 30 30 30 38 20 20 20 20 2f 2a 20 49 6e 74 65 67 0008 /* Integ
14450 65 72 20 70 72 69 6d 61 72 79 20 6b 65 79 20 69 er primary key i
14460 73 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 s autoincrement
14470 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 48 61 */.#define TF_Ha
14480 73 53 74 61 74 31 20 20 20 20 20 20 20 20 30 78 sStat1 0x
14490 30 30 31 30 20 20 20 20 2f 2a 20 6e 52 6f 77 4c 0010 /* nRowL
144a0 6f 67 45 73 74 20 73 65 74 20 66 72 6f 6d 20 73 ogEst set from s
144b0 71 6c 69 74 65 5f 73 74 61 74 31 20 2a 2f 0a 23 qlite_stat1 */.#
144c0 64 65 66 69 6e 65 20 54 46 5f 48 61 73 56 69 72 define TF_HasVir
144d0 74 75 61 6c 20 20 20 20 20 20 30 78 30 30 32 30 tual 0x0020
144e0 20 20 20 20 2f 2a 20 48 61 73 20 6f 6e 65 20 6f /* Has one o
144f0 72 20 6d 6f 72 65 20 56 49 52 54 55 41 4c 20 63 r more VIRTUAL c
14500 6f 6c 75 6d 6e 73 20 2a 2f 0a 23 64 65 66 69 6e olumns */.#defin
14510 65 20 54 46 5f 48 61 73 53 74 6f 72 65 64 20 20 e TF_HasStored
14520 20 20 20 20 20 30 78 30 30 34 30 20 20 20 20 2f 0x0040 /
14530 2a 20 48 61 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 * Has one or mor
14540 65 20 53 54 4f 52 45 44 20 63 6f 6c 75 6d 6e 73 e STORED columns
14550 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 57 */.#define TF_W
14560 69 74 68 6f 75 74 52 6f 77 69 64 20 20 20 20 30 ithoutRowid 0
14570 78 30 30 38 30 20 20 20 20 2f 2a 20 4e 6f 20 72 x0080 /* No r
14580 6f 77 69 64 2e 20 20 50 52 49 4d 41 52 59 20 4b owid. PRIMARY K
14590 45 59 20 69 73 20 74 68 65 20 6b 65 79 20 2a 2f EY is the key */
145a0 0a 23 64 65 66 69 6e 65 20 54 46 5f 53 74 61 74 .#define TF_Stat
145b0 73 55 73 65 64 20 20 20 20 20 20 20 30 78 30 31 sUsed 0x01
145c0 30 30 20 20 20 20 2f 2a 20 51 75 65 72 79 20 70 00 /* Query p
145d0 6c 61 6e 6e 65 72 20 64 65 63 69 73 69 6f 6e 73 lanner decisions
145e0 20 61 66 66 65 63 74 65 64 20 62 79 0a 20 20 20 affected by.
145f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14600 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
14610 20 20 2a 2a 20 49 6e 64 65 78 2e 61 69 52 6f 77 ** Index.aiRow
14620 4c 6f 67 45 73 74 5b 5d 20 76 61 6c 75 65 73 20 LogEst[] values
14630 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 4e 6f */.#define TF_No
14640 56 69 73 69 62 6c 65 52 6f 77 69 64 20 20 30 78 VisibleRowid 0x
14650 30 32 30 30 20 20 20 20 2f 2a 20 4e 6f 20 75 73 0200 /* No us
14660 65 72 2d 76 69 73 69 62 6c 65 20 22 72 6f 77 69 er-visible "rowi
14670 64 22 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 64 65 d" column */.#de
14680 66 69 6e 65 20 54 46 5f 4f 4f 4f 48 69 64 64 65 fine TF_OOOHidde
14690 6e 20 20 20 20 20 20 20 30 78 30 34 30 30 20 20 n 0x0400
146a0 20 20 2f 2a 20 4f 75 74 2d 6f 66 2d 4f 72 64 65 /* Out-of-Orde
146b0 72 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 r hidden columns
146c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 48 */.#define TF_H
146d0 61 73 4e 6f 74 4e 75 6c 6c 20 20 20 20 20 20 30 asNotNull 0
146e0 78 30 38 30 30 20 20 20 20 2f 2a 20 43 6f 6e 74 x0800 /* Cont
146f0 61 69 6e 73 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f ains NOT NULL co
14700 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 nstraints */.#de
14710 66 69 6e 65 20 54 46 5f 53 68 61 64 6f 77 20 20 fine TF_Shadow
14720 20 20 20 20 20 20 20 20 30 78 31 30 30 30 20 20 0x1000
14730 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 20 /* True for a
14740 73 68 61 64 6f 77 20 74 61 62 6c 65 20 2a 2f 0a shadow table */.
14750 0a 2f 2a 0a 2a 2a 20 54 65 73 74 20 74 6f 20 73 ./*.** Test to s
14760 65 65 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f ee whether or no
14770 74 20 61 20 74 61 62 6c 65 20 69 73 20 61 20 76 t a table is a v
14780 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 20 20 54 irtual table. T
14790 68 69 73 20 69 73 0a 2a 2a 20 64 6f 6e 65 20 61 his is.** done a
147a0 73 20 61 20 6d 61 63 72 6f 20 73 6f 20 74 68 61 s a macro so tha
147b0 74 20 69 74 20 77 69 6c 6c 20 62 65 20 6f 70 74 t it will be opt
147c0 69 6d 69 7a 65 64 20 6f 75 74 20 77 68 65 6e 20 imized out when
147d0 76 69 72 74 75 61 6c 0a 2a 2a 20 74 61 62 6c 65 virtual.** table
147e0 20 73 75 70 70 6f 72 74 20 69 73 20 6f 6d 69 74 support is omit
147f0 74 65 64 20 66 72 6f 6d 20 74 68 65 20 62 75 69 ted from the bui
14800 6c 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ld..*/.#ifndef S
14810 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 QLITE_OMIT_VIRTU
14820 41 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 69 6e ALTABLE.# defin
14830 65 20 49 73 56 69 72 74 75 61 6c 28 58 29 20 20 e IsVirtual(X)
14840 20 20 20 20 28 28 58 29 2d 3e 6e 4d 6f 64 75 6c ((X)->nModul
14850 65 41 72 67 29 0a 23 65 6c 73 65 0a 23 20 20 64 eArg).#else.# d
14860 65 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 efine IsVirtual(
14870 58 29 20 20 20 20 20 20 30 0a 23 65 6e 64 69 66 X) 0.#endif
14880 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 ../*.** Macros t
14890 6f 20 64 65 74 65 72 6d 69 6e 65 20 69 66 20 61 o determine if a
148a0 20 63 6f 6c 75 6d 6e 20 69 73 20 68 69 64 64 65 column is hidde
148b0 6e 2e 20 20 49 73 4f 72 64 69 6e 61 72 79 48 69 n. IsOrdinaryHi
148c0 64 64 65 6e 43 6f 6c 75 6d 6e 28 29 0a 2a 2a 20 ddenColumn().**
148d0 6f 6e 6c 79 20 77 6f 72 6b 73 20 66 6f 72 20 6e only works for n
148e0 6f 6e 2d 76 69 72 74 75 61 6c 20 74 61 62 6c 65 on-virtual table
148f0 73 20 28 6f 72 64 69 6e 61 72 79 20 74 61 62 6c s (ordinary tabl
14900 65 73 20 61 6e 64 20 76 69 65 77 73 29 20 61 6e es and views) an
14910 64 20 69 73 0a 2a 2a 20 61 6c 77 61 79 73 20 66 d is.** always f
14920 61 6c 73 65 20 75 6e 6c 65 73 73 20 53 51 4c 49 alse unless SQLI
14930 54 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 45 4e TE_ENABLE_HIDDEN
14940 5f 43 4f 4c 55 4d 4e 53 20 69 73 20 64 65 66 69 _COLUMNS is defi
14950 6e 65 64 2e 20 20 54 68 65 0a 2a 2a 20 49 73 48 ned. The.** IsH
14960 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 29 20 6d 61 iddenColumn() ma
14970 63 72 6f 20 69 73 20 67 65 6e 65 72 61 6c 20 70 cro is general p
14980 75 72 70 6f 73 65 2e 0a 2a 2f 0a 23 69 66 20 64 urpose..*/.#if d
14990 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e efined(SQLITE_EN
149a0 41 42 4c 45 5f 48 49 44 44 45 4e 5f 43 4f 4c 55 ABLE_HIDDEN_COLU
149b0 4d 4e 53 29 0a 23 20 20 64 65 66 69 6e 65 20 49 MNS).# define I
149c0 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 sHiddenColumn(X)
149d0 20 20 20 20 20 20 20 20 20 28 28 28 58 29 2d 3e (((X)->
149e0 63 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c colFlags & COLFL
149f0 41 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 AG_HIDDEN)!=0).#
14a00 20 20 64 65 66 69 6e 65 20 49 73 4f 72 64 69 6e define IsOrdin
14a10 61 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 aryHiddenColumn(
14a20 58 29 20 28 28 28 58 29 2d 3e 63 6f 6c 46 6c 61 X) (((X)->colFla
14a30 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f 48 49 44 gs & COLFLAG_HID
14a40 44 45 4e 29 21 3d 30 29 0a 23 65 6c 69 66 20 21 DEN)!=0).#elif !
14a50 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f defined(SQLITE_O
14a60 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
14a70 29 0a 23 20 20 64 65 66 69 6e 65 20 49 73 48 69 ).# define IsHi
14a80 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 20 20 ddenColumn(X)
14a90 20 20 20 20 20 20 28 28 28 58 29 2d 3e 63 6f 6c (((X)->col
14aa0 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f Flags & COLFLAG_
14ab0 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 20 20 64 HIDDEN)!=0).# d
14ac0 65 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 72 79 efine IsOrdinary
14ad0 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 HiddenColumn(X)
14ae0 30 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 0.#else.# defin
14af0 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e e IsHiddenColumn
14b00 28 58 29 20 20 20 20 20 20 20 20 20 30 0a 23 20 (X) 0.#
14b10 20 64 65 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 define IsOrdina
14b20 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 ryHiddenColumn(X
14b30 29 20 30 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 20 ) 0.#endif.../*
14b40 44 6f 65 73 20 74 68 65 20 74 61 62 6c 65 20 68 Does the table h
14b50 61 76 65 20 61 20 72 6f 77 69 64 20 2a 2f 0a 23 ave a rowid */.#
14b60 64 65 66 69 6e 65 20 48 61 73 52 6f 77 69 64 28 define HasRowid(
14b70 58 29 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 X) (((X)->ta
14b80 62 46 6c 61 67 73 20 26 20 54 46 5f 57 69 74 68 bFlags & TF_With
14b90 6f 75 74 52 6f 77 69 64 29 3d 3d 30 29 0a 23 64 outRowid)==0).#d
14ba0 65 66 69 6e 65 20 56 69 73 69 62 6c 65 52 6f 77 efine VisibleRow
14bb0 69 64 28 58 29 20 28 28 28 58 29 2d 3e 74 61 62 id(X) (((X)->tab
14bc0 46 6c 61 67 73 20 26 20 54 46 5f 4e 6f 56 69 73 Flags & TF_NoVis
14bd0 69 62 6c 65 52 6f 77 69 64 29 3d 3d 30 29 0a 0a ibleRowid)==0)..
14be0 2f 2a 0a 2a 2a 20 45 61 63 68 20 66 6f 72 65 69 /*.** Each forei
14bf0 67 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 69 6e gn key constrain
14c00 74 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 t is an instance
14c10 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
14c20 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a g structure..**.
14c30 2a 2a 20 41 20 66 6f 72 65 69 67 6e 20 6b 65 79 ** A foreign key
14c40 20 69 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 is associated w
14c50 69 74 68 20 74 77 6f 20 74 61 62 6c 65 73 2e 20 ith two tables.
14c60 20 54 68 65 20 22 66 72 6f 6d 22 20 74 61 62 6c The "from" tabl
14c70 65 20 69 73 0a 2a 2a 20 74 68 65 20 74 61 62 6c e is.** the tabl
14c80 65 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 e that contains
14c90 74 68 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 the REFERENCES c
14ca0 6c 61 75 73 65 20 74 68 61 74 20 63 72 65 61 74 lause that creat
14cb0 65 73 20 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a es the foreign.*
14cc0 2a 20 6b 65 79 2e 20 20 54 68 65 20 22 74 6f 22 * key. The "to"
14cd0 20 74 61 62 6c 65 20 69 73 20 74 68 65 20 74 61 table is the ta
14ce0 62 6c 65 20 74 68 61 74 20 69 73 20 6e 61 6d 65 ble that is name
14cf0 64 20 69 6e 20 74 68 65 20 52 45 46 45 52 45 4e d in the REFEREN
14d00 43 45 53 20 63 6c 61 75 73 65 2e 0a 2a 2a 20 43 CES clause..** C
14d10 6f 6e 73 69 64 65 72 20 74 68 69 73 20 65 78 61 onsider this exa
14d20 6d 70 6c 65 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 mple:.**.**
14d30 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 78 31 CREATE TABLE ex1
14d40 28 0a 2a 2a 20 20 20 20 20 20 20 61 20 49 4e 54 (.** a INT
14d50 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY
14d60 2c 0a 2a 2a 20 20 20 20 20 20 20 62 20 49 4e 54 ,.** b INT
14d70 45 47 45 52 20 43 4f 4e 53 54 52 41 49 4e 54 20 EGER CONSTRAINT
14d80 66 6b 31 20 52 45 46 45 52 45 4e 43 45 53 20 65 fk1 REFERENCES e
14d90 78 32 28 78 29 0a 2a 2a 20 20 20 20 20 29 3b 0a x2(x).** );.
14da0 2a 2a 0a 2a 2a 20 46 6f 72 20 66 6f 72 65 69 67 **.** For foreig
14db0 6e 20 6b 65 79 20 22 66 6b 31 22 2c 20 74 68 65 n key "fk1", the
14dc0 20 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 22 from-table is "
14dd0 65 78 31 22 20 61 6e 64 20 74 68 65 20 74 6f 2d ex1" and the to-
14de0 74 61 62 6c 65 20 69 73 20 22 65 78 32 22 2e 0a table is "ex2"..
14df0 2a 2a 20 45 71 75 69 76 61 6c 65 6e 74 20 6e 61 ** Equivalent na
14e00 6d 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 66 mes:.**.** f
14e10 72 6f 6d 2d 74 61 62 6c 65 20 3d 3d 20 63 68 69 rom-table == chi
14e20 6c 64 2d 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 ld-table.**
14e30 20 20 74 6f 2d 74 61 62 6c 65 20 3d 3d 20 70 61 to-table == pa
14e40 72 65 6e 74 2d 74 61 62 6c 65 0a 2a 2a 0a 2a 2a rent-table.**.**
14e50 20 45 61 63 68 20 52 45 46 45 52 45 4e 43 45 53 Each REFERENCES
14e60 20 63 6c 61 75 73 65 20 67 65 6e 65 72 61 74 65 clause generate
14e70 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 s an instance of
14e80 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
14e90 74 72 75 63 74 75 72 65 0a 2a 2a 20 77 68 69 63 tructure.** whic
14ea0 68 20 69 73 20 61 74 74 61 63 68 65 64 20 74 6f h is attached to
14eb0 20 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 2e the from-table.
14ec0 20 20 54 68 65 20 74 6f 2d 74 61 62 6c 65 20 6e The to-table n
14ed0 65 65 64 20 6e 6f 74 20 65 78 69 73 74 20 77 68 eed not exist wh
14ee0 65 6e 0a 2a 2a 20 74 68 65 20 66 72 6f 6d 2d 74 en.** the from-t
14ef0 61 62 6c 65 20 69 73 20 63 72 65 61 74 65 64 2e able is created.
14f00 20 20 54 68 65 20 65 78 69 73 74 65 6e 63 65 20 The existence
14f10 6f 66 20 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 of the to-table
14f20 69 73 20 6e 6f 74 20 63 68 65 63 6b 65 64 2e 0a is not checked..
14f30 2a 2a 0a 2a 2a 20 54 68 65 20 6c 69 73 74 20 6f **.** The list o
14f40 66 20 61 6c 6c 20 70 61 72 65 6e 74 73 20 66 6f f all parents fo
14f50 72 20 63 68 69 6c 64 20 54 61 62 6c 65 20 58 20 r child Table X
14f60 69 73 20 68 65 6c 64 20 61 74 20 58 2e 70 46 4b is held at X.pFK
14f70 65 79 2e 0a 2a 2a 0a 2a 2a 20 41 20 6c 69 73 74 ey..**.** A list
14f80 20 6f 66 20 61 6c 6c 20 63 68 69 6c 64 72 65 6e of all children
14f90 20 66 6f 72 20 61 20 74 61 62 6c 65 20 6e 61 6d for a table nam
14fa0 65 64 20 5a 20 28 77 68 69 63 68 20 6d 69 67 68 ed Z (which migh
14fb0 74 20 6e 6f 74 20 65 76 65 6e 20 65 78 69 73 74 t not even exist
14fc0 29 0a 2a 2a 20 69 73 20 68 65 6c 64 20 69 6e 20 ).** is held in
14fd0 53 63 68 65 6d 61 2e 66 6b 65 79 48 61 73 68 20 Schema.fkeyHash
14fe0 77 69 74 68 20 61 20 68 61 73 68 20 6b 65 79 20 with a hash key
14ff0 6f 66 20 5a 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 of Z..*/.struct
15000 46 4b 65 79 20 7b 0a 20 20 54 61 62 6c 65 20 2a FKey {. Table *
15010 70 46 72 6f 6d 3b 20 20 20 20 20 2f 2a 20 54 61 pFrom; /* Ta
15020 62 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 ble containing t
15030 68 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c he REFERENCES cl
15040 61 75 73 65 20 28 61 6b 61 3a 20 43 68 69 6c 64 ause (aka: Child
15050 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 ) */. FKey *pNe
15060 78 74 46 72 6f 6d 3b 20 20 2f 2a 20 4e 65 78 74 xtFrom; /* Next
15070 20 46 4b 65 79 20 77 69 74 68 20 74 68 65 20 73 FKey with the s
15080 61 6d 65 20 69 6e 20 70 46 72 6f 6d 2e 20 4e 65 ame in pFrom. Ne
15090 78 74 20 70 61 72 65 6e 74 20 6f 66 20 70 46 72 xt parent of pFr
150a0 6f 6d 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 om */. char *zT
150b0 6f 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d o; /* Nam
150c0 65 20 6f 66 20 74 61 62 6c 65 20 74 68 61 74 20 e of table that
150d0 74 68 65 20 6b 65 79 20 70 6f 69 6e 74 73 20 74 the key points t
150e0 6f 20 28 61 6b 61 3a 20 50 61 72 65 6e 74 29 20 o (aka: Parent)
150f0 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 74 */. FKey *pNext
15100 54 6f 3b 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 To; /* Next w
15110 69 74 68 20 74 68 65 20 73 61 6d 65 20 7a 54 6f ith the same zTo
15120 2e 20 4e 65 78 74 20 63 68 69 6c 64 20 6f 66 20 . Next child of
15130 7a 54 6f 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a zTo. */. FKey *
15140 70 50 72 65 76 54 6f 3b 20 20 20 20 2f 2a 20 50 pPrevTo; /* P
15150 72 65 76 69 6f 75 73 20 77 69 74 68 20 74 68 65 revious with the
15160 20 73 61 6d 65 20 7a 54 6f 20 2a 2f 0a 20 20 69 same zTo */. i
15170 6e 74 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 nt nCol;
15180 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f /* Number of co
15190 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 6b 65 lumns in this ke
151a0 79 20 2a 2f 0a 20 20 2f 2a 20 45 56 3a 20 52 2d y */. /* EV: R-
151b0 33 30 33 32 33 2d 32 31 39 31 37 20 2a 2f 0a 20 30323-21917 */.
151c0 20 75 38 20 69 73 44 65 66 65 72 72 65 64 3b 20 u8 isDeferred;
151d0 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
151e0 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 68 65 63 constraint chec
151f0 6b 69 6e 67 20 69 73 20 64 65 66 65 72 72 65 64 king is deferred
15200 20 74 69 6c 6c 20 43 4f 4d 4d 49 54 20 2a 2f 0a till COMMIT */.
15210 20 20 75 38 20 61 41 63 74 69 6f 6e 5b 32 5d 3b u8 aAction[2];
15220 20 20 20 20 20 20 20 20 2f 2a 20 4f 4e 20 44 45 /* ON DE
15230 4c 45 54 45 20 61 6e 64 20 4f 4e 20 55 50 44 41 LETE and ON UPDA
15240 54 45 20 61 63 74 69 6f 6e 73 2c 20 72 65 73 70 TE actions, resp
15250 65 63 74 69 76 65 6c 79 20 2a 2f 0a 20 20 54 72 ectively */. Tr
15260 69 67 67 65 72 20 2a 61 70 54 72 69 67 67 65 72 igger *apTrigger
15270 5b 32 5d 3b 2f 2a 20 54 72 69 67 67 65 72 73 20 [2];/* Triggers
15280 66 6f 72 20 61 41 63 74 69 6f 6e 5b 5d 20 61 63 for aAction[] ac
15290 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 tions */. struc
152a0 74 20 73 43 6f 6c 4d 61 70 20 7b 20 20 20 20 20 t sColMap {
152b0 20 2f 2a 20 4d 61 70 70 69 6e 67 20 6f 66 20 63 /* Mapping of c
152c0 6f 6c 75 6d 6e 73 20 69 6e 20 70 46 72 6f 6d 20 olumns in pFrom
152d0 74 6f 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 7a 54 to columns in zT
152e0 6f 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 46 72 o */. int iFr
152f0 6f 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f om; /
15300 2a 20 49 6e 64 65 78 20 6f 66 20 63 6f 6c 75 6d * Index of colum
15310 6e 20 69 6e 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 n in pFrom */.
15320 20 20 63 68 61 72 20 2a 7a 43 6f 6c 3b 20 20 20 char *zCol;
15330 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 /* Name
15340 6f 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 7a 54 6f of column in zTo
15350 2e 20 20 49 66 20 4e 55 4c 4c 20 75 73 65 20 50 . If NULL use P
15360 52 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 RIMARY KEY */.
15370 7d 20 61 43 6f 6c 5b 31 5d 3b 20 20 20 20 20 20 } aCol[1];
15380 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 65 6e 74 /* One ent
15390 72 79 20 66 6f 72 20 65 61 63 68 20 6f 66 20 6e ry for each of n
153a0 43 6f 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 7d Col columns */.}
153b0 3b 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 69 74 65 20 ;../*.** SQLite
153c0 73 75 70 70 6f 72 74 73 20 6d 61 6e 79 20 64 69 supports many di
153d0 66 66 65 72 65 6e 74 20 77 61 79 73 20 74 6f 20 fferent ways to
153e0 72 65 73 6f 6c 76 65 20 61 20 63 6f 6e 73 74 72 resolve a constr
153f0 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 2e 20 20 aint.** error.
15400 52 4f 4c 4c 42 41 43 4b 20 70 72 6f 63 65 73 73 ROLLBACK process
15410 69 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 20 61 ing means that a
15420 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c constraint viol
15430 61 74 69 6f 6e 0a 2a 2a 20 63 61 75 73 65 73 20 ation.** causes
15440 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e the operation in
15450 20 70 72 6f 63 65 73 73 20 74 6f 20 66 61 69 6c process to fail
15460 20 61 6e 64 20 66 6f 72 20 74 68 65 20 63 75 72 and for the cur
15470 72 65 6e 74 20 74 72 61 6e 73 61 63 74 69 6f 6e rent transaction
15480 0a 2a 2a 20 74 6f 20 62 65 20 72 6f 6c 6c 65 64 .** to be rolled
15490 20 62 61 63 6b 2e 20 20 41 42 4f 52 54 20 70 72 back. ABORT pr
154a0 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 ocessing means t
154b0 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 he operation in
154c0 70 72 6f 63 65 73 73 0a 2a 2a 20 66 61 69 6c 73 process.** fails
154d0 20 61 6e 64 20 61 6e 79 20 70 72 69 6f 72 20 63 and any prior c
154e0 68 61 6e 67 65 73 20 66 72 6f 6d 20 74 68 61 74 hanges from that
154f0 20 6f 6e 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 one operation a
15500 72 65 20 62 61 63 6b 65 64 20 6f 75 74 2c 0a 2a re backed out,.*
15510 2a 20 62 75 74 20 74 68 65 20 74 72 61 6e 73 61 * but the transa
15520 63 74 69 6f 6e 20 69 73 20 6e 6f 74 20 72 6f 6c ction is not rol
15530 6c 65 64 20 62 61 63 6b 2e 20 20 46 41 49 4c 20 led back. FAIL
15540 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 processing means
15550 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 6f 70 65 that.** the ope
15560 72 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 ration in progre
15570 73 73 20 73 74 6f 70 73 20 61 6e 64 20 72 65 74 ss stops and ret
15580 75 72 6e 73 20 61 6e 20 65 72 72 6f 72 20 63 6f urns an error co
15590 64 65 2e 20 20 42 75 74 20 70 72 69 6f 72 0a 2a de. But prior.*
155a0 2a 20 63 68 61 6e 67 65 73 20 64 75 65 20 74 6f * changes due to
155b0 20 74 68 65 20 73 61 6d 65 20 6f 70 65 72 61 74 the same operat
155c0 69 6f 6e 20 61 72 65 20 6e 6f 74 20 62 61 63 6b ion are not back
155d0 65 64 20 6f 75 74 20 61 6e 64 20 6e 6f 20 72 6f ed out and no ro
155e0 6c 6c 62 61 63 6b 0a 2a 2a 20 6f 63 63 75 72 73 llback.** occurs
155f0 2e 20 20 49 47 4e 4f 52 45 20 6d 65 61 6e 73 20 . IGNORE means
15600 74 68 61 74 20 74 68 65 20 70 61 72 74 69 63 75 that the particu
15610 6c 61 72 20 72 6f 77 20 74 68 61 74 20 63 61 75 lar row that cau
15620 73 65 64 20 74 68 65 20 63 6f 6e 73 74 72 61 69 sed the constrai
15630 6e 74 0a 2a 2a 20 65 72 72 6f 72 20 69 73 20 6e nt.** error is n
15640 6f 74 20 69 6e 73 65 72 74 65 64 20 6f 72 20 75 ot inserted or u
15650 70 64 61 74 65 64 2e 20 20 50 72 6f 63 65 73 73 pdated. Process
15660 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e ing continues an
15670 64 20 6e 6f 20 65 72 72 6f 72 0a 2a 2a 20 69 73 d no error.** is
15680 20 72 65 74 75 72 6e 65 64 2e 20 20 52 45 50 4c returned. REPL
15690 41 43 45 20 6d 65 61 6e 73 20 74 68 61 74 20 70 ACE means that p
156a0 72 65 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 reexisting datab
156b0 61 73 65 20 72 6f 77 73 20 74 68 61 74 20 63 61 ase rows that ca
156c0 75 73 65 64 0a 2a 2a 20 61 20 55 4e 49 51 55 45 used.** a UNIQUE
156d0 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c constraint viol
156e0 61 74 69 6f 6e 20 61 72 65 20 72 65 6d 6f 76 65 ation are remove
156f0 64 20 73 6f 20 74 68 61 74 20 74 68 65 20 6e 65 d so that the ne
15700 77 20 69 6e 73 65 72 74 20 6f 72 0a 2a 2a 20 75 w insert or.** u
15710 70 64 61 74 65 20 63 61 6e 20 70 72 6f 63 65 65 pdate can procee
15720 64 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 20 63 d. Processing c
15730 6f 6e 74 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 ontinues and no
15740 65 72 72 6f 72 20 69 73 20 72 65 70 6f 72 74 65 error is reporte
15750 64 2e 0a 2a 2a 0a 2a 2a 20 52 45 53 54 52 49 43 d..**.** RESTRIC
15760 54 2c 20 53 45 54 4e 55 4c 4c 2c 20 61 6e 64 20 T, SETNULL, and
15770 43 41 53 43 41 44 45 20 61 63 74 69 6f 6e 73 20 CASCADE actions
15780 61 70 70 6c 79 20 6f 6e 6c 79 20 74 6f 20 66 6f apply only to fo
15790 72 65 69 67 6e 20 6b 65 79 73 2e 0a 2a 2a 20 52 reign keys..** R
157a0 45 53 54 52 49 43 54 20 69 73 20 74 68 65 20 73 ESTRICT is the s
157b0 61 6d 65 20 61 73 20 41 42 4f 52 54 20 66 6f 72 ame as ABORT for
157c0 20 49 4d 4d 45 44 49 41 54 45 20 66 6f 72 65 69 IMMEDIATE forei
157d0 67 6e 20 6b 65 79 73 20 61 6e 64 20 74 68 65 0a gn keys and the.
157e0 2a 2a 20 73 61 6d 65 20 61 73 20 52 4f 4c 4c 42 ** same as ROLLB
157f0 41 43 4b 20 66 6f 72 20 44 45 46 45 52 52 45 44 ACK for DEFERRED
15800 20 6b 65 79 73 2e 20 20 53 45 54 4e 55 4c 4c 20 keys. SETNULL
15810 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 66 means that the f
15820 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 69 73 oreign.** key is
15830 20 73 65 74 20 74 6f 20 4e 55 4c 4c 2e 20 20 43 set to NULL. C
15840 41 53 43 41 44 45 20 6d 65 61 6e 73 20 74 68 61 ASCADE means tha
15850 74 20 61 20 44 45 4c 45 54 45 20 6f 72 20 55 50 t a DELETE or UP
15860 44 41 54 45 20 6f 66 20 74 68 65 0a 2a 2a 20 72 DATE of the.** r
15870 65 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 eferenced table
15880 72 6f 77 20 69 73 20 70 72 6f 70 61 67 61 74 65 row is propagate
15890 64 20 69 6e 74 6f 20 74 68 65 20 72 6f 77 20 74 d into the row t
158a0 68 61 74 20 68 6f 6c 64 73 20 74 68 65 0a 2a 2a hat holds the.**
158b0 20 66 6f 72 65 69 67 6e 20 6b 65 79 2e 0a 2a 2a foreign key..**
158c0 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
158d0 67 20 73 79 6d 62 6f 6c 69 63 20 76 61 6c 75 65 g symbolic value
158e0 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 72 65 s are used to re
158f0 63 6f 72 64 20 77 68 69 63 68 20 74 79 70 65 0a cord which type.
15900 2a 2a 20 6f 66 20 61 63 74 69 6f 6e 20 74 6f 20 ** of action to
15910 74 61 6b 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 take..*/.#define
15920 20 4f 45 5f 4e 6f 6e 65 20 20 20 20 20 30 20 20 OE_None 0
15930 20 2f 2a 20 54 68 65 72 65 20 69 73 20 6e 6f 20 /* There is no
15940 63 6f 6e 73 74 72 61 69 6e 74 20 74 6f 20 63 68 constraint to ch
15950 65 63 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f eck */.#define O
15960 45 5f 52 6f 6c 6c 62 61 63 6b 20 31 20 20 20 2f E_Rollback 1 /
15970 2a 20 46 61 69 6c 20 74 68 65 20 6f 70 65 72 61 * Fail the opera
15980 74 69 6f 6e 20 61 6e 64 20 72 6f 6c 6c 62 61 63 tion and rollbac
15990 6b 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f k the transactio
159a0 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f n */.#define OE_
159b0 41 62 6f 72 74 20 20 20 20 32 20 20 20 2f 2a 20 Abort 2 /*
159c0 42 61 63 6b 20 6f 75 74 20 63 68 61 6e 67 65 73 Back out changes
159d0 20 62 75 74 20 64 6f 20 6e 6f 20 72 6f 6c 6c 62 but do no rollb
159e0 61 63 6b 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 ack transaction
159f0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 46 61 */.#define OE_Fa
15a00 69 6c 20 20 20 20 20 33 20 20 20 2f 2a 20 53 74 il 3 /* St
15a10 6f 70 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e op the operation
15a20 20 62 75 74 20 6c 65 61 76 65 20 61 6c 6c 20 70 but leave all p
15a30 72 69 6f 72 20 63 68 61 6e 67 65 73 20 2a 2f 0a rior changes */.
15a40 23 64 65 66 69 6e 65 20 4f 45 5f 49 67 6e 6f 72 #define OE_Ignor
15a50 65 20 20 20 34 20 20 20 2f 2a 20 49 67 6e 6f 72 e 4 /* Ignor
15a60 65 20 74 68 65 20 65 72 72 6f 72 2e 20 44 6f 20 e the error. Do
15a70 6e 6f 74 20 64 6f 20 74 68 65 20 49 4e 53 45 52 not do the INSER
15a80 54 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 23 T or UPDATE */.#
15a90 64 65 66 69 6e 65 20 4f 45 5f 52 65 70 6c 61 63 define OE_Replac
15aa0 65 20 20 35 20 20 20 2f 2a 20 44 65 6c 65 74 65 e 5 /* Delete
15ab0 20 65 78 69 73 74 69 6e 67 20 72 65 63 6f 72 64 existing record
15ac0 2c 20 74 68 65 6e 20 64 6f 20 49 4e 53 45 52 54 , then do INSERT
15ad0 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 or UPDATE */.#d
15ae0 65 66 69 6e 65 20 4f 45 5f 55 70 64 61 74 65 20 efine OE_Update
15af0 20 20 36 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 6 /* Process
15b00 20 61 73 20 61 20 44 4f 20 55 50 44 41 54 45 20 as a DO UPDATE
15b10 69 6e 20 61 6e 20 75 70 73 65 72 74 20 2a 2f 0a in an upsert */.
15b20 23 64 65 66 69 6e 65 20 4f 45 5f 52 65 73 74 72 #define OE_Restr
15b30 69 63 74 20 37 20 20 20 2f 2a 20 4f 45 5f 41 62 ict 7 /* OE_Ab
15b40 6f 72 74 20 66 6f 72 20 49 4d 4d 45 44 49 41 54 ort for IMMEDIAT
15b50 45 2c 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 66 E, OE_Rollback f
15b60 6f 72 20 44 45 46 45 52 52 45 44 20 2a 2f 0a 23 or DEFERRED */.#
15b70 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 4e 75 6c define OE_SetNul
15b80 6c 20 20 38 20 20 20 2f 2a 20 53 65 74 20 74 68 l 8 /* Set th
15b90 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 e foreign key va
15ba0 6c 75 65 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a 23 lue to NULL */.#
15bb0 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 44 66 6c define OE_SetDfl
15bc0 74 20 20 39 20 20 20 2f 2a 20 53 65 74 20 74 68 t 9 /* Set th
15bd0 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 e foreign key va
15be0 6c 75 65 20 74 6f 20 69 74 73 20 64 65 66 61 75 lue to its defau
15bf0 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 lt */.#define OE
15c00 5f 43 61 73 63 61 64 65 20 20 31 30 20 20 2f 2a _Cascade 10 /*
15c10 20 43 61 73 63 61 64 65 20 74 68 65 20 63 68 61 Cascade the cha
15c20 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 nges */.#define
15c30 4f 45 5f 44 65 66 61 75 6c 74 20 20 31 31 20 20 OE_Default 11
15c40 2f 2a 20 44 6f 20 77 68 61 74 65 76 65 72 20 74 /* Do whatever t
15c50 68 65 20 64 65 66 61 75 6c 74 20 61 63 74 69 6f he default actio
15c60 6e 20 69 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 n is */.../*.**
15c70 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
15c80 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
15c90 75 63 74 75 72 65 20 69 73 20 70 61 73 73 65 64 ucture is passed
15ca0 20 61 73 20 74 68 65 20 66 69 72 73 74 0a 2a 2a as the first.**
15cb0 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 73 71 6c argument to sql
15cc0 69 74 65 33 56 64 62 65 4b 65 79 43 6f 6d 70 61 ite3VdbeKeyCompa
15cd0 72 65 20 61 6e 64 20 69 73 20 75 73 65 64 20 74 re and is used t
15ce0 6f 20 63 6f 6e 74 72 6f 6c 20 74 68 65 0a 2a 2a o control the.**
15cf0 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 66 20 74 comparison of t
15d00 68 65 20 74 77 6f 20 69 6e 64 65 78 20 6b 65 79 he two index key
15d10 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 s..**.** Note th
15d20 61 74 20 61 53 6f 72 74 4f 72 64 65 72 5b 5d 20 at aSortOrder[]
15d30 61 6e 64 20 61 43 6f 6c 6c 5b 5d 20 68 61 76 65 and aColl[] have
15d40 20 6e 46 69 65 6c 64 2b 31 20 73 6c 6f 74 73 2e nField+1 slots.
15d50 20 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 6e There.** are n
15d60 46 69 65 6c 64 20 73 6c 6f 74 73 20 66 6f 72 20 Field slots for
15d70 74 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 61 the columns of a
15d80 6e 20 69 6e 64 65 78 20 74 68 65 6e 20 6f 6e 65 n index then one
15d90 20 65 78 74 72 61 20 73 6c 6f 74 0a 2a 2a 20 66 extra slot.** f
15da0 6f 72 20 74 68 65 20 72 6f 77 69 64 20 61 74 20 or the rowid at
15db0 74 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 the end..*/.stru
15dc0 63 74 20 4b 65 79 49 6e 66 6f 20 7b 0a 20 20 75 ct KeyInfo {. u
15dd0 33 32 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 32 nRef;
15de0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
15df0 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 68 references to th
15e00 69 73 20 4b 65 79 49 6e 66 6f 20 6f 62 6a 65 63 is KeyInfo objec
15e10 74 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 t */. u8 enc;
15e20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 /* Te
15e30 78 74 20 65 6e 63 6f 64 69 6e 67 20 2d 20 6f 6e xt encoding - on
15e40 65 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 5f e of the SQLITE_
15e50 55 54 46 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 UTF* values */.
15e60 20 75 31 36 20 6e 4b 65 79 46 69 65 6c 64 3b 20 u16 nKeyField;
15e70 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
15e80 66 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 69 6e f key columns in
15e90 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 20 the index */.
15ea0 75 31 36 20 6e 41 6c 6c 46 69 65 6c 64 3b 20 20 u16 nAllField;
15eb0 20 20 20 20 2f 2a 20 54 6f 74 61 6c 20 63 6f 6c /* Total col
15ec0 75 6d 6e 73 2c 20 69 6e 63 6c 75 64 69 6e 67 20 umns, including
15ed0 6b 65 79 20 70 6c 75 73 20 6f 74 68 65 72 73 20 key plus others
15ee0 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 */. sqlite3 *db
15ef0 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ; /* The
15f00 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
15f10 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f ion */. u8 *aSo
15f20 72 74 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 rtFlags; /*
15f30 53 6f 72 74 20 6f 72 64 65 72 20 66 6f 72 20 65 Sort order for e
15f40 61 63 68 20 63 6f 6c 75 6d 6e 2e 20 2a 2f 0a 20 ach column. */.
15f50 20 43 6f 6c 6c 53 65 71 20 2a 61 43 6f 6c 6c 5b CollSeq *aColl[
15f60 31 5d 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 1]; /* Collatin
15f70 67 20 73 65 71 75 65 6e 63 65 20 66 6f 72 20 65 g sequence for e
15f80 61 63 68 20 74 65 72 6d 20 6f 66 20 74 68 65 20 ach term of the
15f90 6b 65 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a key */.};../*.**
15fa0 20 41 6c 6c 6f 77 65 64 20 62 69 74 20 76 61 6c Allowed bit val
15fb0 75 65 73 20 66 6f 72 20 65 6e 74 72 69 65 73 20 ues for entries
15fc0 69 6e 20 74 68 65 20 4b 65 79 49 6e 66 6f 2e 61 in the KeyInfo.a
15fd0 53 6f 72 74 46 6c 61 67 73 5b 5d 20 61 72 72 61 SortFlags[] arra
15fe0 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4b 45 y..*/.#define KE
15ff0 59 49 4e 46 4f 5f 4f 52 44 45 52 5f 44 45 53 43 YINFO_ORDER_DESC
16000 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 44 0x01 /* D
16010 45 53 43 20 73 6f 72 74 20 6f 72 64 65 72 20 2a ESC sort order *
16020 2f 0a 23 64 65 66 69 6e 65 20 4b 45 59 49 4e 46 /.#define KEYINF
16030 4f 5f 4f 52 44 45 52 5f 42 49 47 4e 55 4c 4c 20 O_ORDER_BIGNULL
16040 30 78 30 32 20 20 20 20 2f 2a 20 4e 55 4c 4c 20 0x02 /* NULL
16050 69 73 20 6c 61 72 67 65 72 20 74 68 61 6e 20 61 is larger than a
16060 6e 79 20 6f 74 68 65 72 20 76 61 6c 75 65 20 2a ny other value *
16070 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 6f 62 /../*.** This ob
16080 6a 65 63 74 20 68 6f 6c 64 73 20 61 20 72 65 63 ject holds a rec
16090 6f 72 64 20 77 68 69 63 68 20 68 61 73 20 62 65 ord which has be
160a0 65 6e 20 70 61 72 73 65 64 20 6f 75 74 20 69 6e en parsed out in
160b0 74 6f 20 69 6e 64 69 76 69 64 75 61 6c 0a 2a 2a to individual.**
160c0 20 66 69 65 6c 64 73 2c 20 66 6f 72 20 74 68 65 fields, for the
160d0 20 70 75 72 70 6f 73 65 73 20 6f 66 20 64 6f 69 purposes of doi
160e0 6e 67 20 61 20 63 6f 6d 70 61 72 69 73 6f 6e 2e ng a comparison.
160f0 0a 2a 2a 0a 2a 2a 20 41 20 72 65 63 6f 72 64 20 .**.** A record
16100 69 73 20 61 6e 20 6f 62 6a 65 63 74 20 74 68 61 is an object tha
16110 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f t contains one o
16120 72 20 6d 6f 72 65 20 66 69 65 6c 64 73 20 6f 66 r more fields of
16130 20 64 61 74 61 2e 0a 2a 2a 20 52 65 63 6f 72 64 data..** Record
16140 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 73 74 s are used to st
16150 6f 72 65 20 74 68 65 20 63 6f 6e 74 65 6e 74 20 ore the content
16160 6f 66 20 61 20 74 61 62 6c 65 20 72 6f 77 20 61 of a table row a
16170 6e 64 20 74 6f 20 73 74 6f 72 65 0a 2a 2a 20 74 nd to store.** t
16180 68 65 20 6b 65 79 20 6f 66 20 61 6e 20 69 6e 64 he key of an ind
16190 65 78 2e 20 20 41 20 62 6c 6f 62 20 65 6e 63 6f ex. A blob enco
161a0 64 69 6e 67 20 6f 66 20 61 20 72 65 63 6f 72 64 ding of a record
161b0 20 69 73 20 63 72 65 61 74 65 64 20 62 79 0a 2a is created by.*
161c0 2a 20 74 68 65 20 4f 50 5f 4d 61 6b 65 52 65 63 * the OP_MakeRec
161d0 6f 72 64 20 6f 70 63 6f 64 65 20 6f 66 20 74 68 ord opcode of th
161e0 65 20 56 44 42 45 20 61 6e 64 20 69 73 20 64 69 e VDBE and is di
161f0 73 61 73 73 65 6d 62 6c 65 64 20 62 79 20 74 68 sassembled by th
16200 65 0a 2a 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f e.** OP_Column o
16210 70 63 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 6e 20 pcode..**.** An
16220 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 instance of this
16230 20 6f 62 6a 65 63 74 20 73 65 72 76 65 73 20 61 object serves a
16240 73 20 61 20 22 6b 65 79 22 20 66 6f 72 20 64 6f s a "key" for do
16250 69 6e 67 20 61 20 73 65 61 72 63 68 20 6f 6e 0a ing a search on.
16260 2a 2a 20 61 6e 20 69 6e 64 65 78 20 62 2b 74 72 ** an index b+tr
16270 65 65 2e 20 54 68 65 20 67 6f 61 6c 20 6f 66 20 ee. The goal of
16280 74 68 65 20 73 65 61 72 63 68 20 69 73 20 74 6f the search is to
16290 20 66 69 6e 64 20 74 68 65 20 65 6e 74 72 79 20 find the entry
162a0 74 68 61 74 0a 2a 2a 20 69 73 20 63 6c 6f 73 65 that.** is close
162b0 64 20 74 6f 20 74 68 65 20 6b 65 79 20 64 65 73 d to the key des
162c0 63 72 69 62 65 64 20 62 79 20 74 68 69 73 20 6f cribed by this o
162d0 62 6a 65 63 74 2e 20 20 54 68 69 73 20 6f 62 6a bject. This obj
162e0 65 63 74 20 6d 69 67 68 74 20 68 6f 6c 64 0a 2a ect might hold.*
162f0 2a 20 6a 75 73 74 20 61 20 70 72 65 66 69 78 20 * just a prefix
16300 6f 66 20 74 68 65 20 6b 65 79 2e 20 20 54 68 65 of the key. The
16310 20 6e 75 6d 62 65 72 20 6f 66 20 66 69 65 6c 64 number of field
16320 73 20 69 73 20 67 69 76 65 6e 20 62 79 0a 2a 2a s is given by.**
16330 20 70 4b 65 79 49 6e 66 6f 2d 3e 6e 46 69 65 6c pKeyInfo->nFiel
16340 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 72 31 20 d..**.** The r1
16350 61 6e 64 20 72 32 20 66 69 65 6c 64 73 20 61 72 and r2 fields ar
16360 65 20 74 68 65 20 76 61 6c 75 65 73 20 74 6f 20 e the values to
16370 72 65 74 75 72 6e 20 69 66 20 74 68 69 73 20 6b return if this k
16380 65 79 20 69 73 20 6c 65 73 73 20 74 68 61 6e 0a ey is less than.
16390 2a 2a 20 6f 72 20 67 72 65 61 74 65 72 20 74 68 ** or greater th
163a0 61 6e 20 61 20 6b 65 79 20 69 6e 20 74 68 65 20 an a key in the
163b0 62 74 72 65 65 2c 20 72 65 73 70 65 63 74 69 76 btree, respectiv
163c0 65 6c 79 2e 20 20 54 68 65 73 65 20 61 72 65 20 ely. These are
163d0 6e 6f 72 6d 61 6c 6c 79 0a 2a 2a 20 2d 31 20 61 normally.** -1 a
163e0 6e 64 20 2b 31 20 72 65 73 70 65 63 74 69 76 65 nd +1 respective
163f0 6c 79 2c 20 62 75 74 20 6d 69 67 68 74 20 62 65 ly, but might be
16400 20 69 6e 76 65 72 74 65 64 20 74 6f 20 2b 31 20 inverted to +1
16410 61 6e 64 20 2d 31 20 69 66 20 74 68 65 20 62 2d and -1 if the b-
16420 74 72 65 65 0a 2a 2a 20 69 73 20 69 6e 20 44 45 tree.** is in DE
16430 53 43 20 6f 72 64 65 72 2e 0a 2a 2a 0a 2a 2a 20 SC order..**.**
16440 54 68 65 20 6b 65 79 20 63 6f 6d 70 61 72 69 73 The key comparis
16450 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 61 63 74 on functions act
16460 75 61 6c 6c 79 20 72 65 74 75 72 6e 20 64 65 66 ually return def
16470 61 75 6c 74 5f 72 63 20 77 68 65 6e 20 74 68 65 ault_rc when the
16480 79 20 66 69 6e 64 0a 2a 2a 20 61 6e 20 65 71 75 y find.** an equ
16490 61 6c 73 20 63 6f 6d 70 61 72 69 73 6f 6e 2e 20 als comparison.
164a0 20 64 65 66 61 75 6c 74 5f 72 63 20 63 61 6e 20 default_rc can
164b0 62 65 20 2d 31 2c 20 30 2c 20 6f 72 20 2b 31 2e be -1, 0, or +1.
164c0 20 20 49 66 20 74 68 65 72 65 20 61 72 65 0a 2a If there are.*
164d0 2a 20 6d 75 6c 74 69 70 6c 65 20 65 6e 74 72 69 * multiple entri
164e0 65 73 20 69 6e 20 74 68 65 20 62 2d 74 72 65 65 es in the b-tree
164f0 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 6b with the same k
16500 65 79 20 28 77 68 65 6e 20 6f 6e 6c 79 20 6c 6f ey (when only lo
16510 6f 6b 69 6e 67 0a 2a 2a 20 61 74 20 74 68 65 20 oking.** at the
16520 66 69 72 73 74 20 70 4b 65 79 49 6e 66 6f 2d 3e first pKeyInfo->
16530 6e 46 69 65 6c 64 73 2c 29 20 74 68 65 6e 20 64 nFields,) then d
16540 65 66 61 75 6c 74 5f 72 63 20 63 61 6e 20 62 65 efault_rc can be
16550 20 73 65 74 20 74 6f 20 2d 31 20 74 6f 0a 2a 2a set to -1 to.**
16560 20 63 61 75 73 65 20 74 68 65 20 73 65 61 72 63 cause the searc
16570 68 20 74 6f 20 66 69 6e 64 20 74 68 65 20 6c 61 h to find the la
16580 73 74 20 6d 61 74 63 68 2c 20 6f 72 20 2b 31 20 st match, or +1
16590 74 6f 20 63 61 75 73 65 20 74 68 65 20 73 65 61 to cause the sea
165a0 72 63 68 20 74 6f 0a 2a 2a 20 66 69 6e 64 20 74 rch to.** find t
165b0 68 65 20 66 69 72 73 74 20 6d 61 74 63 68 2e 0a he first match..
165c0 2a 2a 0a 2a 2a 20 54 68 65 20 6b 65 79 20 63 6f **.** The key co
165d0 6d 70 61 72 69 73 6f 6e 20 66 75 6e 63 74 69 6f mparison functio
165e0 6e 73 20 77 69 6c 6c 20 73 65 74 20 65 71 53 65 ns will set eqSe
165f0 65 6e 20 74 6f 20 74 72 75 65 20 69 66 20 74 68 en to true if th
16600 65 79 20 65 76 65 72 0a 2a 2a 20 67 65 74 20 61 ey ever.** get a
16610 6e 64 20 65 71 75 61 6c 20 72 65 73 75 6c 74 73 nd equal results
16620 20 77 68 65 6e 20 63 6f 6d 70 61 72 69 6e 67 20 when comparing
16630 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 74 this structure t
16640 6f 20 61 20 62 2d 74 72 65 65 20 72 65 63 6f 72 o a b-tree recor
16650 64 2e 0a 2a 2a 20 57 68 65 6e 20 64 65 66 61 75 d..** When defau
16660 6c 74 5f 72 63 21 3d 30 2c 20 74 68 65 20 73 65 lt_rc!=0, the se
16670 61 72 63 68 20 6d 69 67 68 74 20 65 6e 64 20 75 arch might end u
16680 70 20 6f 6e 20 74 68 65 20 72 65 63 6f 72 64 20 p on the record
16690 69 6d 6d 65 64 69 61 74 65 6c 79 0a 2a 2a 20 62 immediately.** b
166a0 65 66 6f 72 65 20 74 68 65 20 66 69 72 73 74 20 efore the first
166b0 6d 61 74 63 68 20 6f 72 20 69 6d 6d 65 64 69 61 match or immedia
166c0 74 65 6c 79 20 61 66 74 65 72 20 74 68 65 20 6c tely after the l
166d0 61 73 74 20 6d 61 74 63 68 2e 20 20 54 68 65 0a ast match. The.
166e0 2a 2a 20 65 71 53 65 65 6e 20 66 69 65 6c 64 20 ** eqSeen field
166f0 77 69 6c 6c 20 69 6e 64 69 63 61 74 65 20 77 68 will indicate wh
16700 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 61 6e 20 ether or not an
16710 65 78 61 63 74 20 6d 61 74 63 68 20 65 78 69 73 exact match exis
16720 74 73 20 69 6e 20 74 68 65 0a 2a 2a 20 62 2d 74 ts in the.** b-t
16730 72 65 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 55 ree..*/.struct U
16740 6e 70 61 63 6b 65 64 52 65 63 6f 72 64 20 7b 0a npackedRecord {.
16750 20 20 4b 65 79 49 6e 66 6f 20 2a 70 4b 65 79 49 KeyInfo *pKeyI
16760 6e 66 6f 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 nfo; /* Collati
16770 6f 6e 20 61 6e 64 20 73 6f 72 74 2d 6f 72 64 65 on and sort-orde
16780 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f r information */
16790 0a 20 20 4d 65 6d 20 2a 61 4d 65 6d 3b 20 20 20 . Mem *aMem;
167a0 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 73 /* Values
167b0 20 2a 2f 0a 20 20 75 31 36 20 6e 46 69 65 6c 64 */. u16 nField
167c0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d ; /* Num
167d0 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 69 ber of entries i
167e0 6e 20 61 70 4d 65 6d 5b 5d 20 2a 2f 0a 20 20 69 n apMem[] */. i
167f0 38 20 64 65 66 61 75 6c 74 5f 72 63 3b 20 20 20 8 default_rc;
16800 20 20 20 2f 2a 20 43 6f 6d 70 61 72 69 73 6f 6e /* Comparison
16810 20 72 65 73 75 6c 74 20 69 66 20 6b 65 79 73 20 result if keys
16820 61 72 65 20 65 71 75 61 6c 20 2a 2f 0a 20 20 75 are equal */. u
16830 38 20 65 72 72 43 6f 64 65 3b 20 20 20 20 20 20 8 errCode;
16840 20 20 20 2f 2a 20 45 72 72 6f 72 20 64 65 74 65 /* Error dete
16850 63 74 65 64 20 62 79 20 78 52 65 63 6f 72 64 43 cted by xRecordC
16860 6f 6d 70 61 72 65 20 28 43 4f 52 52 55 50 54 20 ompare (CORRUPT
16870 6f 72 20 4e 4f 4d 45 4d 29 20 2a 2f 0a 20 20 69 or NOMEM) */. i
16880 38 20 72 31 3b 20 20 20 20 20 20 20 20 20 20 20 8 r1;
16890 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 /* Value to r
168a0 65 74 75 72 6e 20 69 66 20 28 6c 68 73 20 3c 20 eturn if (lhs <
168b0 72 68 73 29 20 2a 2f 0a 20 20 69 38 20 72 32 3b rhs) */. i8 r2;
168c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
168d0 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e Value to return
168e0 20 69 66 20 28 6c 68 73 20 3e 20 72 68 73 29 20 if (lhs > rhs)
168f0 2a 2f 0a 20 20 75 38 20 65 71 53 65 65 6e 3b 20 */. u8 eqSeen;
16900 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
16910 20 69 66 20 61 6e 20 65 71 75 61 6c 69 74 79 20 if an equality
16920 63 6f 6d 70 61 72 69 73 6f 6e 20 68 61 73 20 62 comparison has b
16930 65 65 6e 20 73 65 65 6e 20 2a 2f 0a 7d 3b 0a 0a een seen */.};..
16940 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 ./*.** Each SQL
16950 69 6e 64 65 78 20 69 73 20 72 65 70 72 65 73 65 index is represe
16960 6e 74 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20 62 nted in memory b
16970 79 20 61 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 y an.** instance
16980 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
16990 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a g structure..**.
169a0 2a 2a 20 54 68 65 20 63 6f 6c 75 6d 6e 73 20 6f ** The columns o
169b0 66 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 f the table that
169c0 20 61 72 65 20 74 6f 20 62 65 20 69 6e 64 65 78 are to be index
169d0 65 64 20 61 72 65 20 64 65 73 63 72 69 62 65 64 ed are described
169e0 0a 2a 2a 20 62 79 20 74 68 65 20 61 69 43 6f 6c .** by the aiCol
169f0 75 6d 6e 5b 5d 20 66 69 65 6c 64 20 6f 66 20 74 umn[] field of t
16a00 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 his structure.
16a10 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 73 75 70 For example, sup
16a20 70 6f 73 65 0a 2a 2a 20 77 65 20 68 61 76 65 20 pose.** we have
16a30 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 61 the following ta
16a40 62 6c 65 20 61 6e 64 20 69 6e 64 65 78 3a 0a 2a ble and index:.*
16a50 2a 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 45 20 *.** CREATE
16a60 54 41 42 4c 45 20 45 78 31 28 63 31 20 69 6e 74 TABLE Ex1(c1 int
16a70 2c 20 63 32 20 69 6e 74 2c 20 63 33 20 74 65 78 , c2 int, c3 tex
16a80 74 29 3b 0a 2a 2a 20 20 20 20 20 43 52 45 41 54 t);.** CREAT
16a90 45 20 49 4e 44 45 58 20 45 78 32 20 4f 4e 20 45 E INDEX Ex2 ON E
16aa0 78 31 28 63 33 2c 63 31 29 3b 0a 2a 2a 0a 2a 2a x1(c3,c1);.**.**
16ab0 20 49 6e 20 74 68 65 20 54 61 62 6c 65 20 73 74 In the Table st
16ac0 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 69 ructure describi
16ad0 6e 67 20 45 78 31 2c 20 6e 43 6f 6c 3d 3d 33 20 ng Ex1, nCol==3
16ae0 62 65 63 61 75 73 65 20 74 68 65 72 65 20 61 72 because there ar
16af0 65 0a 2a 2a 20 74 68 72 65 65 20 63 6f 6c 75 6d e.** three colum
16b00 6e 73 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e ns in the table.
16b10 20 20 49 6e 20 74 68 65 20 49 6e 64 65 78 20 73 In the Index s
16b20 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 tructure describ
16b30 69 6e 67 0a 2a 2a 20 45 78 32 2c 20 6e 43 6f 6c ing.** Ex2, nCol
16b40 75 6d 6e 3d 3d 32 20 73 69 6e 63 65 20 32 20 6f umn==2 since 2 o
16b50 66 20 74 68 65 20 33 20 63 6f 6c 75 6d 6e 73 20 f the 3 columns
16b60 6f 66 20 45 78 31 20 61 72 65 20 69 6e 64 65 78 of Ex1 are index
16b70 65 64 2e 0a 2a 2a 20 54 68 65 20 76 61 6c 75 65 ed..** The value
16b80 20 6f 66 20 61 69 43 6f 6c 75 6d 6e 20 69 73 20 of aiColumn is
16b90 7b 32 2c 20 30 7d 2e 20 20 61 69 43 6f 6c 75 6d {2, 0}. aiColum
16ba0 6e 5b 30 5d 3d 3d 32 20 62 65 63 61 75 73 65 20 n[0]==2 because
16bb0 74 68 65 0a 2a 2a 20 66 69 72 73 74 20 63 6f 6c the.** first col
16bc0 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 65 78 65 umn to be indexe
16bd0 64 20 28 63 33 29 20 68 61 73 20 61 6e 20 69 6e d (c3) has an in
16be0 64 65 78 20 6f 66 20 32 20 69 6e 20 45 78 31 2e dex of 2 in Ex1.
16bf0 61 43 6f 6c 5b 5d 2e 0a 2a 2a 20 54 68 65 20 73 aCol[]..** The s
16c00 65 63 6f 6e 64 20 63 6f 6c 75 6d 6e 20 74 6f 20 econd column to
16c10 62 65 20 69 6e 64 65 78 65 64 20 28 63 31 29 20 be indexed (c1)
16c20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 20 has an index of
16c30 30 20 69 6e 0a 2a 2a 20 45 78 31 2e 61 43 6f 6c 0 in.** Ex1.aCol
16c40 5b 5d 2c 20 68 65 6e 63 65 20 45 78 32 2e 61 69 [], hence Ex2.ai
16c50 43 6f 6c 75 6d 6e 5b 31 5d 3d 3d 30 2e 0a 2a 2a Column[1]==0..**
16c60 0a 2a 2a 20 54 68 65 20 49 6e 64 65 78 2e 6f 6e .** The Index.on
16c70 45 72 72 6f 72 20 66 69 65 6c 64 20 64 65 74 65 Error field dete
16c80 72 6d 69 6e 65 73 20 77 68 65 74 68 65 72 20 6f rmines whether o
16c90 72 20 6e 6f 74 20 74 68 65 20 69 6e 64 65 78 65 r not the indexe
16ca0 64 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 6d 75 73 d columns.** mus
16cb0 74 20 62 65 20 75 6e 69 71 75 65 20 61 6e 64 20 t be unique and
16cc0 77 68 61 74 20 74 6f 20 64 6f 20 69 66 20 74 68 what to do if th
16cd0 65 79 20 61 72 65 20 6e 6f 74 2e 20 20 57 68 65 ey are not. Whe
16ce0 6e 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 3d n Index.onError=
16cf0 4f 45 5f 4e 6f 6e 65 2c 0a 2a 2a 20 69 74 20 6d OE_None,.** it m
16d00 65 61 6e 73 20 74 68 69 73 20 69 73 20 6e 6f 74 eans this is not
16d10 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 78 2e a unique index.
16d20 20 20 4f 74 68 65 72 77 69 73 65 20 69 74 20 69 Otherwise it i
16d30 73 20 61 20 75 6e 69 71 75 65 20 69 6e 64 65 78 s a unique index
16d40 0a 2a 2a 20 61 6e 64 20 74 68 65 20 76 61 6c 75 .** and the valu
16d50 65 20 6f 66 20 49 6e 64 65 78 2e 6f 6e 45 72 72 e of Index.onErr
16d60 6f 72 20 69 6e 64 69 63 61 74 65 20 74 68 65 20 or indicate the
16d70 77 68 69 63 68 20 63 6f 6e 66 6c 69 63 74 20 72 which conflict r
16d80 65 73 6f 6c 75 74 69 6f 6e 0a 2a 2a 20 61 6c 67 esolution.** alg
16d90 6f 72 69 74 68 6d 20 74 6f 20 65 6d 70 6c 6f 79 orithm to employ
16da0 20 77 68 65 6e 65 76 65 72 20 61 6e 20 61 74 74 whenever an att
16db0 65 6d 70 74 20 69 73 20 6d 61 64 65 20 74 6f 20 empt is made to
16dc0 69 6e 73 65 72 74 20 61 20 6e 6f 6e 2d 75 6e 69 insert a non-uni
16dd0 71 75 65 0a 2a 2a 20 65 6c 65 6d 65 6e 74 2e 0a que.** element..
16de0 2a 2a 0a 2a 2a 20 57 68 69 6c 65 20 70 61 72 73 **.** While pars
16df0 69 6e 67 20 61 20 43 52 45 41 54 45 20 54 41 42 ing a CREATE TAB
16e00 4c 45 20 6f 72 20 43 52 45 41 54 45 20 49 4e 44 LE or CREATE IND
16e10 45 58 20 73 74 61 74 65 6d 65 6e 74 20 69 6e 20 EX statement in
16e20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 65 6e 65 order to.** gene
16e30 72 61 74 65 20 56 44 42 45 20 63 6f 64 65 20 28 rate VDBE code (
16e40 61 73 20 6f 70 70 6f 73 65 64 20 74 6f 20 70 61 as opposed to pa
16e50 72 73 69 6e 67 20 6f 6e 65 20 72 65 61 64 20 66 rsing one read f
16e60 72 6f 6d 20 61 6e 20 73 71 6c 69 74 65 5f 6d 61 rom an sqlite_ma
16e70 73 74 65 72 0a 2a 2a 20 74 61 62 6c 65 20 61 73 ster.** table as
16e80 20 70 61 72 74 20 6f 66 20 70 61 72 73 69 6e 67 part of parsing
16e90 20 61 6e 20 65 78 69 73 74 69 6e 67 20 64 61 74 an existing dat
16ea0 61 62 61 73 65 20 73 63 68 65 6d 61 29 2c 20 74 abase schema), t
16eb0 72 61 6e 73 69 65 6e 74 20 69 6e 73 74 61 6e 63 ransient instanc
16ec0 65 73 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 es.** of this st
16ed0 72 75 63 74 75 72 65 20 6d 61 79 20 62 65 20 63 ructure may be c
16ee0 72 65 61 74 65 64 2e 20 49 6e 20 74 68 69 73 20 reated. In this
16ef0 63 61 73 65 20 74 68 65 20 49 6e 64 65 78 2e 74 case the Index.t
16f00 6e 75 6d 20 76 61 72 69 61 62 6c 65 20 69 73 0a num variable is.
16f10 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 ** used to store
16f20 20 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 the address of
16f30 61 20 56 44 42 45 20 69 6e 73 74 72 75 63 74 69 a VDBE instructi
16f40 6f 6e 2c 20 6e 6f 74 20 61 20 64 61 74 61 62 61 on, not a databa
16f50 73 65 20 70 61 67 65 0a 2a 2a 20 6e 75 6d 62 65 se page.** numbe
16f60 72 20 28 69 74 20 63 61 6e 6e 6f 74 20 2d 20 74 r (it cannot - t
16f70 68 65 20 64 61 74 61 62 61 73 65 20 70 61 67 65 he database page
16f80 20 69 73 20 6e 6f 74 20 61 6c 6c 6f 63 61 74 65 is not allocate
16f90 64 20 75 6e 74 69 6c 20 74 68 65 20 56 44 42 45 d until the VDBE
16fa0 0a 2a 2a 20 70 72 6f 67 72 61 6d 20 69 73 20 65 .** program is e
16fb0 78 65 63 75 74 65 64 29 2e 20 53 65 65 20 63 6f xecuted). See co
16fc0 6e 76 65 72 74 54 6f 57 69 74 68 6f 75 74 52 6f nvertToWithoutRo
16fd0 77 69 64 54 61 62 6c 65 28 29 20 66 6f 72 20 64 widTable() for d
16fe0 65 74 61 69 6c 73 2e 0a 2a 2f 0a 73 74 72 75 63 etails..*/.struc
16ff0 74 20 49 6e 64 65 78 20 7b 0a 20 20 63 68 61 72 t Index {. char
17000 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 *zName;
17010 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
17020 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 this index */.
17030 69 31 36 20 2a 61 69 43 6f 6c 75 6d 6e 3b 20 20 i16 *aiColumn;
17040 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 69 63 /* Whic
17050 68 20 63 6f 6c 75 6d 6e 73 20 61 72 65 20 75 73 h columns are us
17060 65 64 20 62 79 20 74 68 69 73 20 69 6e 64 65 78 ed by this index
17070 2e 20 20 31 73 74 20 69 73 20 30 20 2a 2f 0a 20 . 1st is 0 */.
17080 20 4c 6f 67 45 73 74 20 2a 61 69 52 6f 77 4c 6f LogEst *aiRowLo
17090 67 45 73 74 3b 20 20 20 20 20 2f 2a 20 46 72 6f gEst; /* Fro
170a0 6d 20 41 4e 41 4c 59 5a 45 3a 20 45 73 74 2e 20 m ANALYZE: Est.
170b0 72 6f 77 73 20 73 65 6c 65 63 74 65 64 20 62 79 rows selected by
170c0 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a each column */.
170d0 20 20 54 61 62 6c 65 20 2a 70 54 61 62 6c 65 3b Table *pTable;
170e0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 /* Th
170f0 65 20 53 51 4c 20 74 61 62 6c 65 20 62 65 69 6e e SQL table bein
17100 67 20 69 6e 64 65 78 65 64 20 2a 2f 0a 20 20 63 g indexed */. c
17110 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b 20 20 20 har *zColAff;
17120 20 20 20 20 20 20 20 20 2f 2a 20 53 74 72 69 6e /* Strin
17130 67 20 64 65 66 69 6e 69 6e 67 20 74 68 65 20 61 g defining the a
17140 66 66 69 6e 69 74 79 20 6f 66 20 65 61 63 68 20 ffinity of each
17150 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 column */. Inde
17160 78 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 x *pNext;
17170 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 65 78 74 /* The next
17180 20 69 6e 64 65 78 20 61 73 73 6f 63 69 61 74 65 index associate
17190 64 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 d with the same
171a0 74 61 62 6c 65 20 2a 2f 0a 20 20 53 63 68 65 6d table */. Schem
171b0 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 20 a *pSchema;
171c0 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f /* Schema co
171d0 6e 74 61 69 6e 69 6e 67 20 74 68 69 73 20 69 6e ntaining this in
171e0 64 65 78 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f dex */. u8 *aSo
171f0 72 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 20 rtOrder;
17200 20 20 2f 2a 20 66 6f 72 20 65 61 63 68 20 63 6f /* for each co
17210 6c 75 6d 6e 3a 20 54 72 75 65 3d 3d 44 45 53 43 lumn: True==DESC
17220 2c 20 46 61 6c 73 65 3d 3d 41 53 43 20 2a 2f 0a , False==ASC */.
17230 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2a 61 const char **a
17240 7a 43 6f 6c 6c 3b 20 20 20 20 20 2f 2a 20 41 72 zColl; /* Ar
17250 72 61 79 20 6f 66 20 63 6f 6c 6c 61 74 69 6f 6e ray of collation
17260 20 73 65 71 75 65 6e 63 65 20 6e 61 6d 65 73 20 sequence names
17270 66 6f 72 20 69 6e 64 65 78 20 2a 2f 0a 20 20 45 for index */. E
17280 78 70 72 20 2a 70 50 61 72 74 49 64 78 57 68 65 xpr *pPartIdxWhe
17290 72 65 3b 20 20 20 20 20 2f 2a 20 57 48 45 52 45 re; /* WHERE
172a0 20 63 6c 61 75 73 65 20 66 6f 72 20 70 61 72 74 clause for part
172b0 69 61 6c 20 69 6e 64 69 63 65 73 20 2a 2f 0a 20 ial indices */.
172c0 20 45 78 70 72 4c 69 73 74 20 2a 61 43 6f 6c 45 ExprList *aColE
172d0 78 70 72 3b 20 20 20 20 20 20 2f 2a 20 43 6f 6c xpr; /* Col
172e0 75 6d 6e 20 65 78 70 72 65 73 73 69 6f 6e 73 20 umn expressions
172f0 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 6d 3b 20 20 */. int tnum;
17300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
17310 20 44 42 20 50 61 67 65 20 63 6f 6e 74 61 69 6e DB Page contain
17320 69 6e 67 20 72 6f 6f 74 20 6f 66 20 74 68 69 73 ing root of this
17330 20 69 6e 64 65 78 20 2a 2f 0a 20 20 4c 6f 67 45 index */. LogE
17340 73 74 20 73 7a 49 64 78 52 6f 77 3b 20 20 20 20 st szIdxRow;
17350 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 /* Estimate
17360 64 20 61 76 65 72 61 67 65 20 72 6f 77 20 73 69 d average row si
17370 7a 65 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 ze in bytes */.
17380 20 75 31 36 20 6e 4b 65 79 43 6f 6c 3b 20 20 20 u16 nKeyCol;
17390 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
173a0 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 66 ber of columns f
173b0 6f 72 6d 69 6e 67 20 74 68 65 20 6b 65 79 20 2a orming the key *
173c0 2f 0a 20 20 75 31 36 20 6e 43 6f 6c 75 6d 6e 3b /. u16 nColumn;
173d0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
173e0 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e Number of column
173f0 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 s stored in the
17400 69 6e 64 65 78 20 2a 2f 0a 20 20 75 38 20 6f 6e index */. u8 on
17410 45 72 72 6f 72 3b 20 20 20 20 20 20 20 20 20 20 Error;
17420 20 20 20 20 2f 2a 20 4f 45 5f 41 62 6f 72 74 2c /* OE_Abort,
17430 20 4f 45 5f 49 67 6e 6f 72 65 2c 20 4f 45 5f 52 OE_Ignore, OE_R
17440 65 70 6c 61 63 65 2c 20 6f 72 20 4f 45 5f 4e 6f eplace, or OE_No
17450 6e 65 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 ne */. unsigned
17460 20 69 64 78 54 79 70 65 3a 32 3b 20 20 20 20 20 idxType:2;
17470 20 2f 2a 20 30 3a 4e 6f 72 6d 61 6c 20 31 3a 55 /* 0:Normal 1:U
17480 4e 49 51 55 45 2c 20 32 3a 50 52 49 4d 41 52 59 NIQUE, 2:PRIMARY
17490 20 4b 45 59 2c 20 33 3a 49 50 4b 20 2a 2f 0a 20 KEY, 3:IPK */.
174a0 20 75 6e 73 69 67 6e 65 64 20 62 55 6e 6f 72 64 unsigned bUnord
174b0 65 72 65 64 3a 31 3b 20 20 20 2f 2a 20 55 73 65 ered:1; /* Use
174c0 20 74 68 69 73 20 69 6e 64 65 78 20 66 6f 72 20 this index for
174d0 3d 3d 20 6f 72 20 49 4e 20 71 75 65 72 69 65 73 == or IN queries
174e0 20 6f 6e 6c 79 20 2a 2f 0a 20 20 75 6e 73 69 67 only */. unsig
174f0 6e 65 64 20 75 6e 69 71 4e 6f 74 4e 75 6c 6c 3a ned uniqNotNull:
17500 31 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 20 55 1; /* True if U
17510 4e 49 51 55 45 20 61 6e 64 20 4e 4f 54 20 4e 55 NIQUE and NOT NU
17520 4c 4c 20 66 6f 72 20 61 6c 6c 20 63 6f 6c 75 6d LL for all colum
17530 6e 73 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 ns */. unsigned
17540 20 69 73 52 65 73 69 7a 65 64 3a 31 3b 20 20 20 isResized:1;
17550 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 69 /* True if resi
17560 7a 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 29 20 zeIndexObject()
17570 68 61 73 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 has been called
17580 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 73 */. unsigned is
17590 43 6f 76 65 72 69 6e 67 3a 31 3b 20 20 20 2f 2a Covering:1; /*
175a0 20 54 72 75 65 20 69 66 20 74 68 69 73 20 69 73 True if this is
175b0 20 61 20 63 6f 76 65 72 69 6e 67 20 69 6e 64 65 a covering inde
175c0 78 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 x */. unsigned
175d0 6e 6f 53 6b 69 70 53 63 61 6e 3a 31 3b 20 20 20 noSkipScan:1;
175e0 2f 2a 20 44 6f 20 6e 6f 74 20 74 72 79 20 74 6f /* Do not try to
175f0 20 75 73 65 20 73 6b 69 70 2d 73 63 61 6e 20 69 use skip-scan i
17600 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 6e 73 69 f true */. unsi
17610 67 6e 65 64 20 68 61 73 53 74 61 74 31 3a 31 3b gned hasStat1:1;
17620 20 20 20 20 20 2f 2a 20 61 69 52 6f 77 4c 6f 67 /* aiRowLog
17630 45 73 74 20 76 61 6c 75 65 73 20 63 6f 6d 65 20 Est values come
17640 66 72 6f 6d 20 73 71 6c 69 74 65 5f 73 74 61 74 from sqlite_stat
17650 31 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 1 */. unsigned
17660 62 4e 6f 51 75 65 72 79 3a 31 3b 20 20 20 20 20 bNoQuery:1;
17670 2f 2a 20 44 6f 20 6e 6f 74 20 75 73 65 20 74 68 /* Do not use th
17680 69 73 20 69 6e 64 65 78 20 74 6f 20 6f 70 74 69 is index to opti
17690 6d 69 7a 65 20 71 75 65 72 69 65 73 20 2a 2f 0a mize queries */.
176a0 20 20 75 6e 73 69 67 6e 65 64 20 62 41 73 63 4b unsigned bAscK
176b0 65 79 42 75 67 3a 31 3b 20 20 20 2f 2a 20 54 72 eyBug:1; /* Tr
176c0 75 65 20 69 66 20 74 68 65 20 62 62 61 37 62 36 ue if the bba7b6
176d0 39 66 39 38 34 39 62 35 62 66 20 62 75 67 20 61 9f9849b5bf bug a
176e0 70 70 6c 69 65 73 20 2a 2f 0a 23 69 66 64 65 66 pplies */.#ifdef
176f0 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
17700 54 41 54 34 0a 20 20 69 6e 74 20 6e 53 61 6d 70 TAT4. int nSamp
17710 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 le;
17720 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6c 65 /* Number of ele
17730 6d 65 6e 74 73 20 69 6e 20 61 53 61 6d 70 6c 65 ments in aSample
17740 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 6d [] */. int nSam
17750 70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 pleCol;
17760 20 2f 2a 20 53 69 7a 65 20 6f 66 20 49 6e 64 65 /* Size of Inde
17770 78 53 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d 20 61 xSample.anEq[] a
17780 6e 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 74 52 nd so on */. tR
17790 6f 77 63 6e 74 20 2a 61 41 76 67 45 71 3b 20 20 owcnt *aAvgEq;
177a0 20 20 20 20 20 20 20 2f 2a 20 41 76 65 72 61 67 /* Averag
177b0 65 20 6e 45 71 20 76 61 6c 75 65 73 20 66 6f 72 e nEq values for
177c0 20 6b 65 79 73 20 6e 6f 74 20 69 6e 20 61 53 61 keys not in aSa
177d0 6d 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 78 53 mple */. IndexS
177e0 61 6d 70 6c 65 20 2a 61 53 61 6d 70 6c 65 3b 20 ample *aSample;
177f0 20 20 20 2f 2a 20 53 61 6d 70 6c 65 73 20 6f 66 /* Samples of
17800 20 74 68 65 20 6c 65 66 74 2d 6d 6f 73 74 20 6b the left-most k
17810 65 79 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 ey */. tRowcnt
17820 2a 61 69 52 6f 77 45 73 74 3b 20 20 20 20 20 20 *aiRowEst;
17830 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 /* Non-logarith
17840 6d 69 63 20 73 74 61 74 31 20 64 61 74 61 20 66 mic stat1 data f
17850 6f 72 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f or this index */
17860 0a 20 20 74 52 6f 77 63 6e 74 20 6e 52 6f 77 45 . tRowcnt nRowE
17870 73 74 30 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e st0; /* N
17880 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 63 20 6e on-logarithmic n
17890 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 69 6e umber of rows in
178a0 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 23 65 the index */.#e
178b0 6e 64 69 66 0a 20 20 42 69 74 6d 61 73 6b 20 63 ndif. Bitmask c
178c0 6f 6c 4e 6f 74 49 64 78 65 64 3b 20 20 20 20 20 olNotIdxed;
178d0 2f 2a 20 30 20 66 6f 72 20 75 6e 69 6e 64 65 78 /* 0 for unindex
178e0 65 64 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 70 54 ed columns in pT
178f0 61 62 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ab */.};../*.**
17900 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
17910 6f 72 20 49 6e 64 65 78 2e 69 64 78 54 79 70 65 or Index.idxType
17920 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
17930 54 45 5f 49 44 58 54 59 50 45 5f 41 50 50 44 45 TE_IDXTYPE_APPDE
17940 46 20 20 20 20 20 20 30 20 20 20 2f 2a 20 43 72 F 0 /* Cr
17950 65 61 74 65 64 20 75 73 69 6e 67 20 43 52 45 41 eated using CREA
17960 54 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 TE INDEX */.#def
17970 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 ine SQLITE_IDXTY
17980 50 45 5f 55 4e 49 51 55 45 20 20 20 20 20 20 31 PE_UNIQUE 1
17990 20 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 74 73 /* Implements
179a0 20 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 a UNIQUE constr
179b0 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 aint */.#define
179c0 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 50 SQLITE_IDXTYPE_P
179d0 52 49 4d 41 52 59 4b 45 59 20 20 32 20 20 20 2f RIMARYKEY 2 /
179e0 2a 20 49 73 20 74 68 65 20 50 52 49 4d 41 52 59 * Is the PRIMARY
179f0 20 4b 45 59 20 66 6f 72 20 74 68 65 20 74 61 62 KEY for the tab
17a00 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 le */.#define SQ
17a10 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 49 50 4b LITE_IDXTYPE_IPK
17a20 20 20 20 20 20 20 20 20 20 33 20 20 20 2f 2a 20 3 /*
17a30 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
17a40 4b 45 59 20 69 6e 64 65 78 20 2a 2f 0a 0a 2f 2a KEY index */../*
17a50 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 Return true if
17a60 69 6e 64 65 78 20 58 20 69 73 20 61 20 50 52 49 index X is a PRI
17a70 4d 41 52 59 20 4b 45 59 20 69 6e 64 65 78 20 2a MARY KEY index *
17a80 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 72 69 6d /.#define IsPrim
17a90 61 72 79 4b 65 79 49 6e 64 65 78 28 58 29 20 20 aryKeyIndex(X)
17aa0 28 28 58 29 2d 3e 69 64 78 54 79 70 65 3d 3d 53 ((X)->idxType==S
17ab0 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 50 52 QLITE_IDXTYPE_PR
17ac0 49 4d 41 52 59 4b 45 59 29 0a 0a 2f 2a 20 52 65 IMARYKEY)../* Re
17ad0 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 6e 64 turn true if ind
17ae0 65 78 20 58 20 69 73 20 61 20 55 4e 49 51 55 45 ex X is a UNIQUE
17af0 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e index */.#defin
17b00 65 20 49 73 55 6e 69 71 75 65 49 6e 64 65 78 28 e IsUniqueIndex(
17b10 58 29 20 20 20 20 20 20 28 28 58 29 2d 3e 6f 6e X) ((X)->on
17b20 45 72 72 6f 72 21 3d 4f 45 5f 4e 6f 6e 65 29 0a Error!=OE_None).
17b30 0a 2f 2a 20 54 68 65 20 49 6e 64 65 78 2e 61 69 ./* The Index.ai
17b40 43 6f 6c 75 6d 6e 5b 5d 20 76 61 6c 75 65 73 20 Column[] values
17b50 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 20 70 6f 73 are normally pos
17b60 69 74 69 76 65 20 69 6e 74 65 67 65 72 2e 20 20 itive integer.
17b70 42 75 74 0a 2a 2a 20 74 68 65 72 65 20 61 72 65 But.** there are
17b80 20 73 6f 6d 65 20 6e 65 67 61 74 69 76 65 20 76 some negative v
17b90 61 6c 75 65 73 20 74 68 61 74 20 68 61 76 65 20 alues that have
17ba0 73 70 65 63 69 61 6c 20 6d 65 61 6e 69 6e 67 3a special meaning:
17bb0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 58 4e 5f 52 .*/.#define XN_R
17bc0 4f 57 49 44 20 20 20 20 20 28 2d 31 29 20 20 20 OWID (-1)
17bd0 20 20 2f 2a 20 49 6e 64 65 78 65 64 20 63 6f 6c /* Indexed col
17be0 75 6d 6e 20 69 73 20 74 68 65 20 72 6f 77 69 64 umn is the rowid
17bf0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 58 4e 5f 45 */.#define XN_E
17c00 58 50 52 20 20 20 20 20 20 28 2d 32 29 20 20 20 XPR (-2)
17c10 20 20 2f 2a 20 49 6e 64 65 78 65 64 20 63 6f 6c /* Indexed col
17c20 75 6d 6e 20 69 73 20 61 6e 20 65 78 70 72 65 73 umn is an expres
17c30 73 69 6f 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 sion */../*.** E
17c40 61 63 68 20 73 61 6d 70 6c 65 20 73 74 6f 72 65 ach sample store
17c50 64 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 5f d in the sqlite_
17c60 73 74 61 74 34 20 74 61 62 6c 65 20 69 73 20 72 stat4 table is r
17c70 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 epresented in me
17c80 6d 6f 72 79 0a 2a 2a 20 75 73 69 6e 67 20 61 20 mory.** using a
17c90 73 74 72 75 63 74 75 72 65 20 6f 66 20 74 68 69 structure of thi
17ca0 73 20 74 79 70 65 2e 20 20 53 65 65 20 64 6f 63 s type. See doc
17cb0 75 6d 65 6e 74 61 74 69 6f 6e 20 61 74 20 74 68 umentation at th
17cc0 65 20 74 6f 70 20 6f 66 20 74 68 65 0a 2a 2a 20 e top of the.**
17cd0 61 6e 61 6c 79 7a 65 2e 63 20 73 6f 75 72 63 65 analyze.c source
17ce0 20 66 69 6c 65 20 66 6f 72 20 61 64 64 69 74 69 file for additi
17cf0 6f 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e onal information
17d00 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 ..*/.struct Inde
17d10 78 53 61 6d 70 6c 65 20 7b 0a 20 20 76 6f 69 64 xSample {. void
17d20 20 2a 70 3b 20 20 20 20 20 20 20 20 20 20 2f 2a *p; /*
17d30 20 50 6f 69 6e 74 65 72 20 74 6f 20 73 61 6d 70 Pointer to samp
17d40 6c 65 64 20 72 65 63 6f 72 64 20 2a 2f 0a 20 20 led record */.
17d50 69 6e 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 int n;
17d60 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 72 65 63 /* Size of rec
17d70 6f 72 64 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a ord in bytes */.
17d80 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 45 71 3b tRowcnt *anEq;
17d90 20 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 /* Est. numb
17da0 65 72 20 6f 66 20 72 6f 77 73 20 77 68 65 72 65 er of rows where
17db0 20 74 68 65 20 6b 65 79 20 65 71 75 61 6c 73 20 the key equals
17dc0 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 this sample */.
17dd0 20 74 52 6f 77 63 6e 74 20 2a 61 6e 4c 74 3b 20 tRowcnt *anLt;
17de0 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 /* Est. numbe
17df0 72 20 6f 66 20 72 6f 77 73 20 77 68 65 72 65 20 r of rows where
17e00 6b 65 79 20 69 73 20 6c 65 73 73 20 74 68 61 6e key is less than
17e10 20 74 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a this sample */.
17e20 20 20 74 52 6f 77 63 6e 74 20 2a 61 6e 44 4c 74 tRowcnt *anDLt
17e30 3b 20 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 ; /* Est. numb
17e40 65 72 20 6f 66 20 64 69 73 74 69 6e 63 74 20 6b er of distinct k
17e50 65 79 73 20 6c 65 73 73 20 74 68 61 6e 20 74 68 eys less than th
17e60 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 7d 3b 0a is sample */.};.
17e70 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 20 ./*.** Possible
17e80 76 61 6c 75 65 73 20 74 6f 20 75 73 65 20 77 69 values to use wi
17e90 74 68 69 6e 20 74 68 65 20 66 6c 61 67 73 20 61 thin the flags a
17ea0 72 67 75 6d 65 6e 74 20 74 6f 20 73 71 6c 69 74 rgument to sqlit
17eb0 65 33 47 65 74 54 6f 6b 65 6e 28 29 2e 0a 2a 2f e3GetToken()..*/
17ec0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
17ed0 54 4f 4b 45 4e 5f 51 55 4f 54 45 44 20 20 20 20 TOKEN_QUOTED
17ee0 30 78 31 20 2f 2a 20 54 6f 6b 65 6e 20 69 73 20 0x1 /* Token is
17ef0 61 20 71 75 6f 74 65 64 20 69 64 65 6e 74 69 66 a quoted identif
17f00 69 65 72 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ier. */.#define
17f10 53 51 4c 49 54 45 5f 54 4f 4b 45 4e 5f 4b 45 59 SQLITE_TOKEN_KEY
17f20 57 4f 52 44 20 20 20 30 78 32 20 2f 2a 20 54 6f WORD 0x2 /* To
17f30 6b 65 6e 20 69 73 20 61 20 6b 65 79 77 6f 72 64 ken is a keyword
17f40 2e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 . */../*.** Each
17f50 20 74 6f 6b 65 6e 20 63 6f 6d 69 6e 67 20 6f 75 token coming ou
17f60 74 20 6f 66 20 74 68 65 20 6c 65 78 65 72 20 69 t of the lexer i
17f70 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 s an instance of
17f80 0a 2a 2a 20 74 68 69 73 20 73 74 72 75 63 74 75 .** this structu
17f90 72 65 2e 20 20 54 6f 6b 65 6e 73 20 61 72 65 20 re. Tokens are
17fa0 61 6c 73 6f 20 75 73 65 64 20 61 73 20 70 61 72 also used as par
17fb0 74 20 6f 66 20 61 6e 20 65 78 70 72 65 73 73 69 t of an expressi
17fc0 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6d 65 on..**.** The me
17fd0 6d 6f 72 79 20 74 68 61 74 20 22 7a 22 20 70 6f mory that "z" po
17fe0 69 6e 74 73 20 74 6f 20 69 73 20 6f 77 6e 65 64 ints to is owned
17ff0 20 62 79 20 6f 74 68 65 72 20 6f 62 6a 65 63 74 by other object
18000 73 2e 20 20 54 61 6b 65 20 63 61 72 65 0a 2a 2a s. Take care.**
18010 20 74 68 61 74 20 74 68 65 20 6f 77 6e 65 72 20 that the owner
18020 6f 66 20 74 68 65 20 22 7a 22 20 73 74 72 69 6e of the "z" strin
18030 67 20 64 6f 65 73 20 6e 6f 74 20 64 65 61 6c 6c g does not deall
18040 6f 63 61 74 65 20 74 68 65 20 73 74 72 69 6e 67 ocate the string
18050 20 62 65 66 6f 72 65 0a 2a 2a 20 74 68 65 20 54 before.** the T
18060 6f 6b 65 6e 20 67 6f 65 73 20 6f 75 74 20 6f 66 oken goes out of
18070 20 73 63 6f 70 65 21 20 20 56 65 72 79 20 6f 66 scope! Very of
18080 74 65 6e 2c 20 74 68 65 20 22 7a 22 20 70 6f 69 ten, the "z" poi
18090 6e 74 73 20 74 6f 20 73 6f 6d 65 20 70 6c 61 63 nts to some plac
180a0 65 0a 2a 2a 20 69 6e 20 74 68 65 20 6d 69 64 64 e.** in the midd
180b0 6c 65 20 6f 66 20 74 68 65 20 50 61 72 73 65 2e le of the Parse.
180c0 7a 53 71 6c 20 74 65 78 74 2e 20 20 42 75 74 20 zSql text. But
180d0 69 74 20 6d 69 67 68 74 20 61 6c 73 6f 20 70 6f it might also po
180e0 69 6e 74 20 74 6f 20 61 0a 2a 2a 20 73 74 61 74 int to a.** stat
180f0 69 63 20 73 74 72 69 6e 67 2e 0a 2a 2f 0a 73 74 ic string..*/.st
18100 72 75 63 74 20 54 6f 6b 65 6e 20 7b 0a 20 20 63 ruct Token {. c
18110 6f 6e 73 74 20 63 68 61 72 20 2a 7a 3b 20 20 20 onst char *z;
18120 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 74 68 65 /* Text of the
18130 20 74 6f 6b 65 6e 2e 20 20 4e 6f 74 20 4e 55 4c token. Not NUL
18140 4c 2d 74 65 72 6d 69 6e 61 74 65 64 21 20 2a 2f L-terminated! */
18150 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 . unsigned int
18160 6e 3b 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 n; /* Number
18170 6f 66 20 63 68 61 72 61 63 74 65 72 73 20 69 6e of characters in
18180 20 74 68 69 73 20 74 6f 6b 65 6e 20 2a 2f 0a 7d this token */.}
18190 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 ;../*.** An inst
181a0 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 ance of this str
181b0 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 ucture contains
181c0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 information need
181d0 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a ed to generate.*
181e0 2a 20 63 6f 64 65 20 66 6f 72 20 61 20 53 45 4c * code for a SEL
181f0 45 43 54 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ECT that contain
18200 73 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 s aggregate func
18210 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 tions..**.** If
18220 45 78 70 72 2e 6f 70 3d 3d 54 4b 5f 41 47 47 5f Expr.op==TK_AGG_
18230 43 4f 4c 55 4d 4e 20 6f 72 20 54 4b 5f 41 47 47 COLUMN or TK_AGG
18240 5f 46 55 4e 43 54 49 4f 4e 20 74 68 65 6e 20 45 _FUNCTION then E
18250 78 70 72 2e 70 41 67 67 49 6e 66 6f 20 69 73 20 xpr.pAggInfo is
18260 61 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 74 6f 20 a.** pointer to
18270 74 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 this structure.
18280 20 54 68 65 20 45 78 70 72 2e 69 43 6f 6c 75 6d The Expr.iColum
18290 6e 20 66 69 65 6c 64 20 69 73 20 74 68 65 20 69 n field is the i
182a0 6e 64 65 78 20 69 6e 0a 2a 2a 20 41 67 67 49 6e ndex in.** AggIn
182b0 66 6f 2e 61 43 6f 6c 5b 5d 20 6f 72 20 41 67 67 fo.aCol[] or Agg
182c0 49 6e 66 6f 2e 61 46 75 6e 63 5b 5d 20 6f 66 20 Info.aFunc[] of
182d0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 information need
182e0 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a ed to generate.*
182f0 2a 20 63 6f 64 65 20 66 6f 72 20 74 68 61 74 20 * code for that
18300 6e 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 67 67 49 node..**.** AggI
18310 6e 66 6f 2e 70 47 72 6f 75 70 42 79 20 61 6e 64 nfo.pGroupBy and
18320 20 41 67 67 49 6e 66 6f 2e 61 46 75 6e 63 2e 70 AggInfo.aFunc.p
18330 45 78 70 72 20 70 6f 69 6e 74 20 74 6f 20 66 69 Expr point to fi
18340 65 6c 64 73 20 77 69 74 68 69 6e 20 74 68 65 0a elds within the.
18350 2a 2a 20 6f 72 69 67 69 6e 61 6c 20 53 65 6c 65 ** original Sele
18360 63 74 20 73 74 72 75 63 74 75 72 65 20 74 68 61 ct structure tha
18370 74 20 64 65 73 63 72 69 62 65 73 20 74 68 65 20 t describes the
18380 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
18390 2e 20 20 54 68 65 73 65 0a 2a 2a 20 66 69 65 6c . These.** fiel
183a0 64 73 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74 ds do not need t
183b0 6f 20 62 65 20 66 72 65 65 64 20 77 68 65 6e 20 o be freed when
183c0 64 65 61 6c 6c 6f 63 61 74 69 6e 67 20 74 68 65 deallocating the
183d0 20 41 67 67 49 6e 66 6f 20 73 74 72 75 63 74 75 AggInfo structu
183e0 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 67 re..*/.struct Ag
183f0 67 49 6e 66 6f 20 7b 0a 20 20 75 38 20 64 69 72 gInfo {. u8 dir
18400 65 63 74 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 ectMode;
18410 20 20 2f 2a 20 44 69 72 65 63 74 20 72 65 6e 64 /* Direct rend
18420 65 72 69 6e 67 20 6d 6f 64 65 20 6d 65 61 6e 73 ering mode means
18430 20 74 61 6b 65 20 64 61 74 61 20 64 69 72 65 63 take data direc
18440 74 6c 79 0a 20 20 20 20 20 20 20 20 20 20 20 20 tly.
18450 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
18460 20 66 72 6f 6d 20 73 6f 75 72 63 65 20 74 61 62 from source tab
18470 6c 65 73 20 72 61 74 68 65 72 20 74 68 61 6e 20 les rather than
18480 66 72 6f 6d 20 61 63 63 75 6d 75 6c 61 74 6f 72 from accumulator
18490 73 20 2a 2f 0a 20 20 75 38 20 75 73 65 53 6f 72 s */. u8 useSor
184a0 74 69 6e 67 49 64 78 3b 20 20 20 20 20 20 20 2f tingIdx; /
184b0 2a 20 49 6e 20 64 69 72 65 63 74 20 6d 6f 64 65 * In direct mode
184c0 2c 20 72 65 66 65 72 65 6e 63 65 20 74 68 65 20 , reference the
184d0 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 72 61 sorting index ra
184e0 74 68 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 ther.
184f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
18500 2a 20 74 68 61 6e 20 74 68 65 20 73 6f 75 72 63 * than the sourc
18510 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 e table */. int
18520 20 73 6f 72 74 69 6e 67 49 64 78 3b 20 20 20 20 sortingIdx;
18530 20 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e /* Cursor n
18540 75 6d 62 65 72 20 6f 66 20 74 68 65 20 73 6f 72 umber of the sor
18550 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 ting index */.
18560 69 6e 74 20 73 6f 72 74 69 6e 67 49 64 78 50 54 int sortingIdxPT
18570 61 62 3b 20 20 20 20 20 2f 2a 20 43 75 72 73 6f ab; /* Curso
18580 72 20 6e 75 6d 62 65 72 20 6f 66 20 70 73 65 75 r number of pseu
18590 64 6f 2d 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e do-table */. in
185a0 74 20 6e 53 6f 72 74 69 6e 67 43 6f 6c 75 6d 6e t nSortingColumn
185b0 3b 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 ; /* Number
185c0 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
185d0 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 e sorting index
185e0 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 67 2c 20 */. int mnReg,
185f0 6d 78 52 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 mxReg; /*
18600 52 61 6e 67 65 20 6f 66 20 72 65 67 69 73 74 65 Range of registe
18610 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 rs allocated for
18620 20 61 43 6f 6c 20 61 6e 64 20 61 46 75 6e 63 20 aCol and aFunc
18630 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
18640 47 72 6f 75 70 42 79 3b 20 20 20 20 20 2f 2a 20 GroupBy; /*
18650 54 68 65 20 67 72 6f 75 70 20 62 79 20 63 6c 61 The group by cla
18660 75 73 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 use */. struct
18670 41 67 67 49 6e 66 6f 5f 63 6f 6c 20 7b 20 20 20 AggInfo_col {
18680 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 63 6f 6c /* For each col
18690 75 6d 6e 20 75 73 65 64 20 69 6e 20 73 6f 75 72 umn used in sour
186a0 63 65 20 74 61 62 6c 65 73 20 2a 2f 0a 20 20 20 ce tables */.
186b0 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 Table *pTab;
186c0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 6f 75 /* Sou
186d0 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 rce table */.
186e0 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 int iTable;
186f0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 /* Cur
18700 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 sor number of th
18710 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 2a e source table *
18720 2f 0a 20 20 20 20 69 6e 74 20 69 43 6f 6c 75 6d /. int iColum
18730 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f n; /
18740 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 * Column number
18750 77 69 74 68 69 6e 20 74 68 65 20 73 6f 75 72 63 within the sourc
18760 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 e table */. i
18770 6e 74 20 69 53 6f 72 74 65 72 43 6f 6c 75 6d 6e nt iSorterColumn
18780 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d ; /* Colum
18790 6e 20 6e 75 6d 62 65 72 20 69 6e 20 74 68 65 20 n number in the
187a0 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f sorting index */
187b0 0a 20 20 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 . int iMem;
187c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
187d0 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e Memory location
187e0 20 74 68 61 74 20 61 63 74 73 20 61 73 20 61 63 that acts as ac
187f0 63 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 cumulator */.
18800 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 Expr *pExpr;
18810 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 /* The
18820 20 6f 72 69 67 69 6e 61 6c 20 65 78 70 72 65 73 original expres
18830 73 69 6f 6e 20 2a 2f 0a 20 20 7d 20 2a 61 43 6f sion */. } *aCo
18840 6c 3b 0a 20 20 69 6e 74 20 6e 43 6f 6c 75 6d 6e l;. int nColumn
18850 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
18860 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 64 20 65 Number of used e
18870 6e 74 72 69 65 73 20 69 6e 20 61 43 6f 6c 5b 5d ntries in aCol[]
18880 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 63 63 75 6d */. int nAccum
18890 75 6c 61 74 6f 72 3b 20 20 20 20 20 20 20 2f 2a ulator; /*
188a0 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
188b0 6e 73 20 74 68 61 74 20 73 68 6f 77 20 74 68 72 ns that show thr
188c0 6f 75 67 68 20 74 6f 20 74 68 65 20 6f 75 74 70 ough to the outp
188d0 75 74 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 ut..
188e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
188f0 20 41 64 64 69 74 69 6f 6e 61 6c 20 63 6f 6c 75 Additional colu
18900 6d 6e 73 20 61 72 65 20 75 73 65 64 20 6f 6e 6c mns are used onl
18910 79 20 61 73 20 70 61 72 61 6d 65 74 65 72 73 20 y as parameters
18920 74 6f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 to.
18930 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
18940 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 aggregate functi
18950 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 ons */. struct
18960 41 67 67 49 6e 66 6f 5f 66 75 6e 63 20 7b 20 20 AggInfo_func {
18970 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 61 67 67 /* For each agg
18980 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 regate function
18990 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a 70 45 78 */. Expr *pEx
189a0 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pr;
189b0 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 65 6e /* Expression en
189c0 63 6f 64 69 6e 67 20 74 68 65 20 66 75 6e 63 74 coding the funct
189d0 69 6f 6e 20 2a 2f 0a 20 20 20 20 46 75 6e 63 44 ion */. FuncD
189e0 65 66 20 2a 70 46 75 6e 63 3b 20 20 20 20 20 20 ef *pFunc;
189f0 20 20 20 20 2f 2a 20 54 68 65 20 61 67 67 72 65 /* The aggre
18a00 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 69 6d gate function im
18a10 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a plementation */.
18a20 20 20 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 20 int iMem;
18a30 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
18a40 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 Memory location
18a50 74 68 61 74 20 61 63 74 73 20 61 73 20 61 63 63 that acts as acc
18a60 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 20 umulator */.
18a70 69 6e 74 20 69 44 69 73 74 69 6e 63 74 3b 20 20 int iDistinct;
18a80 20 20 20 20 20 20 20 20 20 2f 2a 20 45 70 68 65 /* Ephe
18a90 6d 65 72 61 6c 20 74 61 62 6c 65 20 75 73 65 64 meral table used
18aa0 20 74 6f 20 65 6e 66 6f 72 63 65 20 44 49 53 54 to enforce DIST
18ab0 49 4e 43 54 20 2a 2f 0a 20 20 7d 20 2a 61 46 75 INCT */. } *aFu
18ac0 6e 63 3b 0a 20 20 69 6e 74 20 6e 46 75 6e 63 3b nc;. int nFunc;
18ad0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
18ae0 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 Number of entri
18af0 65 73 20 69 6e 20 61 46 75 6e 63 5b 5d 20 2a 2f es in aFunc[] */
18b00 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 .};../*.** The d
18b10 61 74 61 74 79 70 65 20 79 6e 56 61 72 20 69 73 atatype ynVar is
18b20 20 61 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 a signed intege
18b30 72 2c 20 65 69 74 68 65 72 20 31 36 2d 62 69 74 r, either 16-bit
18b40 20 6f 72 20 33 32 2d 62 69 74 2e 0a 2a 2a 20 55 or 32-bit..** U
18b50 73 75 61 6c 6c 79 20 69 74 20 69 73 20 31 36 2d sually it is 16-
18b60 62 69 74 73 2e 20 20 42 75 74 20 69 66 20 53 51 bits. But if SQ
18b70 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c LITE_MAX_VARIABL
18b80 45 5f 4e 55 4d 42 45 52 20 69 73 20 67 72 65 61 E_NUMBER is grea
18b90 74 65 72 0a 2a 2a 20 74 68 61 6e 20 33 32 37 36 ter.** than 3276
18ba0 37 20 77 65 20 68 61 76 65 20 74 6f 20 6d 61 6b 7 we have to mak
18bb0 65 20 69 74 20 33 32 2d 62 69 74 2e 20 20 31 36 e it 32-bit. 16
18bc0 2d 62 69 74 20 69 73 20 70 72 65 66 65 72 72 65 -bit is preferre
18bd0 64 20 62 65 63 61 75 73 65 0a 2a 2a 20 69 74 20 d because.** it
18be0 75 73 65 73 20 6c 65 73 73 20 6d 65 6d 6f 72 79 uses less memory
18bf0 20 69 6e 20 74 68 65 20 45 78 70 72 20 6f 62 6a in the Expr obj
18c00 65 63 74 2c 20 77 68 69 63 68 20 69 73 20 61 20 ect, which is a
18c10 62 69 67 20 6d 65 6d 6f 72 79 20 75 73 65 72 0a big memory user.
18c20 2a 2a 20 69 6e 20 73 79 73 74 65 6d 73 20 77 69 ** in systems wi
18c30 74 68 20 6c 6f 74 73 20 6f 66 20 70 72 65 70 61 th lots of prepa
18c40 72 65 64 20 73 74 61 74 65 6d 65 6e 74 73 2e 20 red statements.
18c50 20 41 6e 64 20 66 65 77 20 61 70 70 6c 69 63 61 And few applica
18c60 74 69 6f 6e 73 0a 2a 2a 20 6e 65 65 64 20 6d 6f tions.** need mo
18c70 72 65 20 74 68 61 6e 20 61 62 6f 75 74 20 31 30 re than about 10
18c80 20 6f 72 20 32 30 20 76 61 72 69 61 62 6c 65 73 or 20 variables
18c90 2e 20 20 42 75 74 20 73 6f 6d 65 20 65 78 74 72 . But some extr
18ca0 65 6d 65 20 75 73 65 72 73 20 77 61 6e 74 0a 2a eme users want.*
18cb0 2a 20 74 6f 20 68 61 76 65 20 70 72 65 70 61 72 * to have prepar
18cc0 65 64 20 73 74 61 74 65 6d 65 6e 74 73 20 77 69 ed statements wi
18cd0 74 68 20 6f 76 65 72 20 33 32 37 36 37 20 76 61 th over 32767 va
18ce0 72 69 61 62 6c 65 73 2c 20 61 6e 64 20 66 6f 72 riables, and for
18cf0 20 74 68 65 6d 0a 2a 2a 20 74 68 65 20 6f 70 74 them.** the opt
18d00 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c 65 ion is available
18d10 20 28 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d (at compile-tim
18d20 65 29 2e 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 54 e)..*/.#if SQLIT
18d30 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f 4e E_MAX_VARIABLE_N
18d40 55 4d 42 45 52 3c 3d 33 32 37 36 37 0a 74 79 70 UMBER<=32767.typ
18d50 65 64 65 66 20 69 31 36 20 79 6e 56 61 72 3b 0a edef i16 ynVar;.
18d60 23 65 6c 73 65 0a 74 79 70 65 64 65 66 20 69 6e #else.typedef in
18d70 74 20 79 6e 56 61 72 3b 0a 23 65 6e 64 69 66 0a t ynVar;.#endif.
18d80 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 6e 6f 64 65 ./*.** Each node
18d90 20 6f 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f of an expressio
18da0 6e 20 69 6e 20 74 68 65 20 70 61 72 73 65 20 74 n in the parse t
18db0 72 65 65 20 69 73 20 61 6e 20 69 6e 73 74 61 6e ree is an instan
18dc0 63 65 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 ce.** of this st
18dd0 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 45 ructure..**.** E
18de0 78 70 72 2e 6f 70 20 69 73 20 74 68 65 20 6f 70 xpr.op is the op
18df0 63 6f 64 65 2e 20 54 68 65 20 69 6e 74 65 67 65 code. The intege
18e00 72 20 70 61 72 73 65 72 20 74 6f 6b 65 6e 20 63 r parser token c
18e10 6f 64 65 73 20 61 72 65 20 72 65 75 73 65 64 0a odes are reused.
18e20 2a 2a 20 61 73 20 6f 70 63 6f 64 65 73 20 68 65 ** as opcodes he
18e30 72 65 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c re. For example,
18e40 20 74 68 65 20 70 61 72 73 65 72 20 64 65 66 69 the parser defi
18e50 6e 65 73 20 54 4b 5f 47 45 20 74 6f 20 62 65 20 nes TK_GE to be
18e60 61 6e 20 69 6e 74 65 67 65 72 0a 2a 2a 20 63 6f an integer.** co
18e70 64 65 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 de representing
18e80 74 68 65 20 22 3e 3d 22 20 6f 70 65 72 61 74 6f the ">=" operato
18e90 72 2e 20 54 68 69 73 20 73 61 6d 65 20 69 6e 74 r. This same int
18ea0 65 67 65 72 20 63 6f 64 65 20 69 73 20 72 65 75 eger code is reu
18eb0 73 65 64 0a 2a 2a 20 74 6f 20 72 65 70 72 65 73 sed.** to repres
18ec0 65 6e 74 20 74 68 65 20 67 72 65 61 74 65 72 2d ent the greater-
18ed0 74 68 61 6e 2d 6f 72 2d 65 71 75 61 6c 2d 74 6f than-or-equal-to
18ee0 20 6f 70 65 72 61 74 6f 72 20 69 6e 20 74 68 65 operator in the
18ef0 20 65 78 70 72 65 73 73 69 6f 6e 0a 2a 2a 20 74 expression.** t
18f00 72 65 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 ree..**.** If th
18f10 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 e expression is
18f20 61 6e 20 53 51 4c 20 6c 69 74 65 72 61 6c 20 28 an SQL literal (
18f30 54 4b 5f 49 4e 54 45 47 45 52 2c 20 54 4b 5f 46 TK_INTEGER, TK_F
18f40 4c 4f 41 54 2c 20 54 4b 5f 42 4c 4f 42 2c 0a 2a LOAT, TK_BLOB,.*
18f50 2a 20 6f 72 20 54 4b 5f 53 54 52 49 4e 47 29 2c * or TK_STRING),
18f60 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e then Expr.token
18f70 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 74 65 contains the te
18f80 78 74 20 6f 66 20 74 68 65 20 53 51 4c 20 6c 69 xt of the SQL li
18f90 74 65 72 61 6c 2e 20 49 66 0a 2a 2a 20 74 68 65 teral. If.** the
18fa0 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 expression is a
18fb0 20 76 61 72 69 61 62 6c 65 20 28 54 4b 5f 56 41 variable (TK_VA
18fc0 52 49 41 42 4c 45 29 2c 20 74 68 65 6e 20 45 78 RIABLE), then Ex
18fd0 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e pr.token contain
18fe0 73 20 74 68 65 0a 2a 2a 20 76 61 72 69 61 62 6c s the.** variabl
18ff0 65 20 6e 61 6d 65 2e 20 46 69 6e 61 6c 6c 79 2c e name. Finally,
19000 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
19010 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
19020 63 74 69 6f 6e 20 28 54 4b 5f 46 55 4e 43 54 49 ction (TK_FUNCTI
19030 4f 4e 29 2c 0a 2a 2a 20 74 68 65 6e 20 45 78 70 ON),.** then Exp
19040 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 r.token contains
19050 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 the name of the
19060 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a function..**.**
19070 20 45 78 70 72 2e 70 52 69 67 68 74 20 61 6e 64 Expr.pRight and
19080 20 45 78 70 72 2e 70 4c 65 66 74 20 61 72 65 20 Expr.pLeft are
19090 74 68 65 20 6c 65 66 74 20 61 6e 64 20 72 69 67 the left and rig
190a0 68 74 20 73 75 62 65 78 70 72 65 73 73 69 6f 6e ht subexpression
190b0 73 20 6f 66 20 61 0a 2a 2a 20 62 69 6e 61 72 79 s of a.** binary
190c0 20 6f 70 65 72 61 74 6f 72 2e 20 45 69 74 68 65 operator. Eithe
190d0 72 20 6f 72 20 62 6f 74 68 20 6d 61 79 20 62 65 r or both may be
190e0 20 4e 55 4c 4c 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 NULL..**.** Exp
190f0 72 2e 78 2e 70 4c 69 73 74 20 69 73 20 61 20 6c r.x.pList is a l
19100 69 73 74 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ist of arguments
19110 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
19120 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
19130 63 74 69 6f 6e 2c 0a 2a 2a 20 61 20 43 41 53 45 ction,.** a CASE
19140 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 72 20 61 expression or a
19150 6e 20 49 4e 20 65 78 70 72 65 73 73 69 6f 6e 20 n IN expression
19160 6f 66 20 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 of the form "<lh
19170 73 3e 20 49 4e 20 28 3c 79 3e 2c 20 3c 7a 3e 2e s> IN (<y>, <z>.
19180 2e 2e 29 22 2e 0a 2a 2a 20 45 78 70 72 2e 78 2e ..)"..** Expr.x.
19190 70 53 65 6c 65 63 74 20 69 73 20 75 73 65 64 20 pSelect is used
191a0 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f if the expressio
191b0 6e 20 69 73 20 61 20 73 75 62 2d 73 65 6c 65 63 n is a sub-selec
191c0 74 20 6f 72 20 61 6e 20 65 78 70 72 65 73 73 69 t or an expressi
191d0 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 66 6f 72 on of.** the for
191e0 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 53 45 4c m "<lhs> IN (SEL
191f0 45 43 54 20 2e 2e 2e 29 22 2e 20 49 66 20 74 68 ECT ...)". If th
19200 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 62 e EP_xIsSelect b
19210 69 74 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 it is set in the
19220 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 73 20 6d .** Expr.flags m
19230 61 73 6b 2c 20 74 68 65 6e 20 45 78 70 72 2e 78 ask, then Expr.x
19240 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 .pSelect is vali
19250 64 2e 20 4f 74 68 65 72 77 69 73 65 2c 20 45 78 d. Otherwise, Ex
19260 70 72 2e 78 2e 70 4c 69 73 74 20 69 73 0a 2a 2a pr.x.pList is.**
19270 20 76 61 6c 69 64 2e 0a 2a 2a 0a 2a 2a 20 41 6e valid..**.** An
19280 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 expression of t
19290 68 65 20 66 6f 72 6d 20 49 44 20 6f 72 20 49 44 he form ID or ID
192a0 2e 49 44 20 72 65 66 65 72 73 20 74 6f 20 61 20 .ID refers to a
192b0 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 74 61 62 6c column in a tabl
192c0 65 2e 0a 2a 2a 20 46 6f 72 20 73 75 63 68 20 65 e..** For such e
192d0 78 70 72 65 73 73 69 6f 6e 73 2c 20 45 78 70 72 xpressions, Expr
192e0 2e 6f 70 20 69 73 20 73 65 74 20 74 6f 20 54 4b .op is set to TK
192f0 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 45 78 70 72 _COLUMN and Expr
19300 2e 69 54 61 62 6c 65 20 69 73 0a 2a 2a 20 74 68 .iTable is.** th
19310 65 20 69 6e 74 65 67 65 72 20 63 75 72 73 6f 72 e integer cursor
19320 20 6e 75 6d 62 65 72 20 6f 66 20 61 20 56 44 42 number of a VDB
19330 45 20 63 75 72 73 6f 72 20 70 6f 69 6e 74 69 6e E cursor pointin
19340 67 20 74 6f 20 74 68 61 74 20 74 61 62 6c 65 20 g to that table
19350 61 6e 64 0a 2a 2a 20 45 78 70 72 2e 69 43 6f 6c and.** Expr.iCol
19360 75 6d 6e 20 69 73 20 74 68 65 20 63 6f 6c 75 6d umn is the colum
19370 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 65 n number for the
19380 20 73 70 65 63 69 66 69 63 20 63 6f 6c 75 6d 6e specific column
19390 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 65 78 70 . If the.** exp
193a0 72 65 73 73 69 6f 6e 20 69 73 20 75 73 65 64 20 ression is used
193b0 61 73 20 61 20 72 65 73 75 6c 74 20 69 6e 20 61 as a result in a
193c0 6e 20 61 67 67 72 65 67 61 74 65 20 53 45 4c 45 n aggregate SELE
193d0 43 54 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 CT, then the.**
193e0 76 61 6c 75 65 20 69 73 20 61 6c 73 6f 20 73 74 value is also st
193f0 6f 72 65 64 20 69 6e 20 74 68 65 20 45 78 70 72 ored in the Expr
19400 2e 69 41 67 67 20 63 6f 6c 75 6d 6e 20 69 6e 20 .iAgg column in
19410 74 68 65 20 61 67 67 72 65 67 61 74 65 20 73 6f the aggregate so
19420 20 74 68 61 74 0a 2a 2a 20 69 74 20 63 61 6e 20 that.** it can
19430 62 65 20 61 63 63 65 73 73 65 64 20 61 66 74 65 be accessed afte
19440 72 20 61 6c 6c 20 61 67 67 72 65 67 61 74 65 73 r all aggregates
19450 20 61 72 65 20 63 6f 6d 70 75 74 65 64 2e 0a 2a are computed..*
19460 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 *.** If the expr
19470 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 75 6e 62 ession is an unb
19480 6f 75 6e 64 20 76 61 72 69 61 62 6c 65 20 6d 61 ound variable ma
19490 72 6b 65 72 20 28 61 20 71 75 65 73 74 69 6f 6e rker (a question
194a0 20 6d 61 72 6b 0a 2a 2a 20 63 68 61 72 61 63 74 mark.** charact
194b0 65 72 20 27 3f 27 20 69 6e 20 74 68 65 20 6f 72 er '?' in the or
194c0 69 67 69 6e 61 6c 20 53 51 4c 29 20 74 68 65 6e iginal SQL) then
194d0 20 74 68 65 20 45 78 70 72 2e 69 54 61 62 6c 65 the Expr.iTable
194e0 20 68 6f 6c 64 73 20 74 68 65 20 69 6e 64 65 78 holds the index
194f0 0a 2a 2a 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 .** number for t
19500 68 61 74 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a hat variable..**
19510 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 .** If the expre
19520 73 73 69 6f 6e 20 69 73 20 61 20 73 75 62 71 75 ssion is a subqu
19530 65 72 79 20 74 68 65 6e 20 45 78 70 72 2e 69 43 ery then Expr.iC
19540 6f 6c 75 6d 6e 20 68 6f 6c 64 73 20 61 6e 20 69 olumn holds an i
19550 6e 74 65 67 65 72 0a 2a 2a 20 72 65 67 69 73 74 nteger.** regist
19560 65 72 20 6e 75 6d 62 65 72 20 63 6f 6e 74 61 69 er number contai
19570 6e 69 6e 67 20 74 68 65 20 72 65 73 75 6c 74 20 ning the result
19580 6f 66 20 74 68 65 20 73 75 62 71 75 65 72 79 2e of the subquery.
19590 20 20 49 66 20 74 68 65 0a 2a 2a 20 73 75 62 71 If the.** subq
195a0 75 65 72 79 20 67 69 76 65 73 20 61 20 63 6f 6e uery gives a con
195b0 73 74 61 6e 74 20 72 65 73 75 6c 74 2c 20 74 68 stant result, th
195c0 65 6e 20 69 54 61 62 6c 65 20 69 73 20 2d 31 2e en iTable is -1.
195d0 20 20 49 66 20 74 68 65 20 73 75 62 71 75 65 72 If the subquer
195e0 79 0a 2a 2a 20 67 69 76 65 73 20 61 20 64 69 66 y.** gives a dif
195f0 66 65 72 65 6e 74 20 61 6e 73 77 65 72 20 61 74 ferent answer at
19600 20 64 69 66 66 65 72 65 6e 74 20 74 69 6d 65 73 different times
19610 20 64 75 72 69 6e 67 20 73 74 61 74 65 6d 65 6e during statemen
19620 74 20 70 72 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 t processing.**
19630 74 68 65 6e 20 69 54 61 62 6c 65 20 69 73 20 74 then iTable is t
19640 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 he address of a
19650 73 75 62 72 6f 75 74 69 6e 65 20 74 68 61 74 20 subroutine that
19660 63 6f 6d 70 75 74 65 73 20 74 68 65 20 73 75 62 computes the sub
19670 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 query..**.** If
19680 74 68 65 20 45 78 70 72 20 69 73 20 6f 66 20 74 the Expr is of t
19690 79 70 65 20 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 ype OP_Column, a
196a0 6e 64 20 74 68 65 20 74 61 62 6c 65 20 69 74 20 nd the table it
196b0 69 73 20 73 65 6c 65 63 74 69 6e 67 20 66 72 6f is selecting fro
196c0 6d 0a 2a 2a 20 69 73 20 61 20 64 69 73 6b 20 74 m.** is a disk t
196d0 61 62 6c 65 20 6f 72 20 74 68 65 20 22 6f 6c 64 able or the "old
196e0 2e 2a 22 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 .*" pseudo-table
196f0 2c 20 74 68 65 6e 20 70 54 61 62 20 70 6f 69 6e , then pTab poin
19700 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 ts to the.** cor
19710 72 65 73 70 6f 6e 64 69 6e 67 20 74 61 62 6c 65 responding table
19720 20 64 65 66 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a definition..**.
19730 2a 2a 20 41 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f ** ALLOCATION NO
19740 54 45 53 3a 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 TES:.**.** Expr
19750 6f 62 6a 65 63 74 73 20 63 61 6e 20 75 73 65 20 objects can use
19760 61 20 6c 6f 74 20 6f 66 20 6d 65 6d 6f 72 79 20 a lot of memory
19770 73 70 61 63 65 20 69 6e 20 64 61 74 61 62 61 73 space in databas
19780 65 20 73 63 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a e schema. To.**
19790 20 68 65 6c 70 20 72 65 64 75 63 65 20 6d 65 6d help reduce mem
197a0 6f 72 79 20 72 65 71 75 69 72 65 6d 65 6e 74 73 ory requirements
197b0 2c 20 73 6f 6d 65 74 69 6d 65 73 20 61 6e 20 45 , sometimes an E
197c0 78 70 72 20 6f 62 6a 65 63 74 20 77 69 6c 6c 20 xpr object will
197d0 62 65 0a 2a 2a 20 74 72 75 6e 63 61 74 65 64 2e be.** truncated.
197e0 20 20 41 6e 64 20 74 6f 20 72 65 64 75 63 65 20 And to reduce
197f0 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 6d 65 the number of me
19800 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 mory allocations
19810 2c 20 73 6f 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 , sometimes.** t
19820 77 6f 20 6f 72 20 6d 6f 72 65 20 45 78 70 72 20 wo or more Expr
19830 6f 62 6a 65 63 74 73 20 77 69 6c 6c 20 62 65 20 objects will be
19840 73 74 6f 72 65 64 20 69 6e 20 61 20 73 69 6e 67 stored in a sing
19850 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 le memory alloca
19860 74 69 6f 6e 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 tion,.** togethe
19870 72 20 77 69 74 68 20 45 78 70 72 2e 7a 54 6f 6b r with Expr.zTok
19880 65 6e 20 73 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a en strings..**.*
19890 2a 20 49 66 20 74 68 65 20 45 50 5f 52 65 64 75 * If the EP_Redu
198a0 63 65 64 20 61 6e 64 20 45 50 5f 54 6f 6b 65 6e ced and EP_Token
198b0 4f 6e 6c 79 20 66 6c 61 67 73 20 61 72 65 20 73 Only flags are s
198c0 65 74 20 77 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 et when.** an Ex
198d0 70 72 20 6f 62 6a 65 63 74 20 69 73 20 74 72 75 pr object is tru
198e0 6e 63 61 74 65 64 2e 20 20 57 68 65 6e 20 45 50 ncated. When EP
198f0 5f 52 65 64 75 63 65 64 20 69 73 20 73 65 74 2c _Reduced is set,
19900 20 74 68 65 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 then all.** the
19910 20 63 68 69 6c 64 20 45 78 70 72 20 6f 62 6a 65 child Expr obje
19920 63 74 73 20 69 6e 20 74 68 65 20 45 78 70 72 2e cts in the Expr.
19930 70 4c 65 66 74 20 61 6e 64 20 45 78 70 72 2e 70 pLeft and Expr.p
19940 52 69 67 68 74 20 73 75 62 74 72 65 65 73 0a 2a Right subtrees.*
19950 2a 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 * are contained
19960 77 69 74 68 69 6e 20 74 68 65 20 73 61 6d 65 20 within the same
19970 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f memory allocatio
19980 6e 2e 20 20 4e 6f 74 65 2c 20 68 6f 77 65 76 65 n. Note, howeve
19990 72 2c 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 73 r, that.** the s
199a0 75 62 74 72 65 65 73 20 69 6e 20 45 78 70 72 2e ubtrees in Expr.
199b0 78 2e 70 4c 69 73 74 20 6f 72 20 45 78 70 72 2e x.pList or Expr.
199c0 78 2e 70 53 65 6c 65 63 74 20 61 72 65 20 61 6c x.pSelect are al
199d0 77 61 79 73 20 73 65 70 61 72 61 74 65 6c 79 0a ways separately.
199e0 2a 2a 20 61 6c 6c 6f 63 61 74 65 64 2c 20 72 65 ** allocated, re
199f0 67 61 72 64 6c 65 73 73 20 6f 66 20 77 68 65 74 gardless of whet
19a00 68 65 72 20 6f 72 20 6e 6f 74 20 45 50 5f 52 65 her or not EP_Re
19a10 64 75 63 65 64 20 69 73 20 73 65 74 2e 0a 2a 2f duced is set..*/
19a20 0a 73 74 72 75 63 74 20 45 78 70 72 20 7b 0a 20 .struct Expr {.
19a30 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 u8 op;
19a40 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 65 72 61 /* Opera
19a50 74 69 6f 6e 20 70 65 72 66 6f 72 6d 65 64 20 62 tion performed b
19a60 79 20 74 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 y this node */.
19a70 20 63 68 61 72 20 61 66 66 45 78 70 72 3b 20 20 char affExpr;
19a80 20 20 20 20 20 20 20 20 2f 2a 20 61 66 66 69 6e /* affin
19a90 69 74 79 2c 20 6f 72 20 52 41 49 53 45 20 74 79 ity, or RAISE ty
19aa0 70 65 20 2a 2f 0a 20 20 75 33 32 20 66 6c 61 67 pe */. u32 flag
19ab0 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f s; /
19ac0 2a 20 56 61 72 69 6f 75 73 20 66 6c 61 67 73 2e * Various flags.
19ad0 20 20 45 50 5f 2a 20 53 65 65 20 62 65 6c 6f 77 EP_* See below
19ae0 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 */. union {.
19af0 20 20 63 68 61 72 20 2a 7a 54 6f 6b 65 6e 3b 20 char *zToken;
19b00 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 /* Toke
19b10 6e 20 76 61 6c 75 65 2e 20 5a 65 72 6f 20 74 65 n value. Zero te
19b20 72 6d 69 6e 61 74 65 64 20 61 6e 64 20 64 65 71 rminated and deq
19b30 75 6f 74 65 64 20 2a 2f 0a 20 20 20 20 69 6e 74 uoted */. int
19b40 20 69 56 61 6c 75 65 3b 20 20 20 20 20 20 20 20 iValue;
19b50 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6e 65 67 61 74 /* Non-negat
19b60 69 76 65 20 69 6e 74 65 67 65 72 20 76 61 6c 75 ive integer valu
19b70 65 20 69 66 20 45 50 5f 49 6e 74 56 61 6c 75 65 e if EP_IntValue
19b80 20 2a 2f 0a 20 20 7d 20 75 3b 0a 0a 20 20 2f 2a */. } u;.. /*
19b90 20 49 66 20 74 68 65 20 45 50 5f 54 6f 6b 65 6e If the EP_Token
19ba0 4f 6e 6c 79 20 66 6c 61 67 20 69 73 20 73 65 74 Only flag is set
19bb0 20 69 6e 20 74 68 65 20 45 78 70 72 2e 66 6c 61 in the Expr.fla
19bc0 67 73 20 6d 61 73 6b 2c 20 74 68 65 6e 20 6e 6f gs mask, then no
19bd0 0a 20 20 2a 2a 20 73 70 61 63 65 20 69 73 20 61 . ** space is a
19be0 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 74 68 65 llocated for the
19bf0 20 66 69 65 6c 64 73 20 62 65 6c 6f 77 20 74 68 fields below th
19c00 69 73 20 70 6f 69 6e 74 2e 20 41 6e 20 61 74 74 is point. An att
19c10 65 6d 70 74 20 74 6f 0a 20 20 2a 2a 20 61 63 63 empt to. ** acc
19c20 65 73 73 20 74 68 65 6d 20 77 69 6c 6c 20 72 65 ess them will re
19c30 73 75 6c 74 20 69 6e 20 61 20 73 65 67 66 61 75 sult in a segfau
19c40 6c 74 20 6f 72 20 6d 61 6c 66 75 6e 63 74 69 6f lt or malfunctio
19c50 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a n.. ***********
19c60 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19c70 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19c80 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19c90 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 45 **********/.. E
19ca0 78 70 72 20 2a 70 4c 65 66 74 3b 20 20 20 20 20 xpr *pLeft;
19cb0 20 20 20 20 20 20 2f 2a 20 4c 65 66 74 20 73 75 /* Left su
19cc0 62 6e 6f 64 65 20 2a 2f 0a 20 20 45 78 70 72 20 bnode */. Expr
19cd0 2a 70 52 69 67 68 74 3b 20 20 20 20 20 20 20 20 *pRight;
19ce0 20 20 2f 2a 20 52 69 67 68 74 20 73 75 62 6e 6f /* Right subno
19cf0 64 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a de */. union {.
19d00 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4c ExprList *pL
19d10 69 73 74 3b 20 20 20 20 20 2f 2a 20 6f 70 20 3d ist; /* op =
19d20 20 49 4e 2c 20 45 58 49 53 54 53 2c 20 53 45 4c IN, EXISTS, SEL
19d30 45 43 54 2c 20 43 41 53 45 2c 20 46 55 4e 43 54 ECT, CASE, FUNCT
19d40 49 4f 4e 2c 20 42 45 54 57 45 45 4e 20 2a 2f 0a ION, BETWEEN */.
19d50 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c Select *pSel
19d60 65 63 74 3b 20 20 20 20 20 2f 2a 20 45 50 5f 78 ect; /* EP_x
19d70 49 73 53 65 6c 65 63 74 20 61 6e 64 20 6f 70 20 IsSelect and op
19d80 3d 20 49 4e 2c 20 45 58 49 53 54 53 2c 20 53 45 = IN, EXISTS, SE
19d90 4c 45 43 54 20 2a 2f 0a 20 20 7d 20 78 3b 0a 0a LECT */. } x;..
19da0 20 20 2f 2a 20 49 66 20 74 68 65 20 45 50 5f 52 /* If the EP_R
19db0 65 64 75 63 65 64 20 66 6c 61 67 20 69 73 20 73 educed flag is s
19dc0 65 74 20 69 6e 20 74 68 65 20 45 78 70 72 2e 66 et in the Expr.f
19dd0 6c 61 67 73 20 6d 61 73 6b 2c 20 74 68 65 6e 20 lags mask, then
19de0 6e 6f 0a 20 20 2a 2a 20 73 70 61 63 65 20 69 73 no. ** space is
19df0 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 74 allocated for t
19e00 68 65 20 66 69 65 6c 64 73 20 62 65 6c 6f 77 20 he fields below
19e10 74 68 69 73 20 70 6f 69 6e 74 2e 20 41 6e 20 61 this point. An a
19e20 74 74 65 6d 70 74 20 74 6f 0a 20 20 2a 2a 20 61 ttempt to. ** a
19e30 63 63 65 73 73 20 74 68 65 6d 20 77 69 6c 6c 20 ccess them will
19e40 72 65 73 75 6c 74 20 69 6e 20 61 20 73 65 67 66 result in a segf
19e50 61 75 6c 74 20 6f 72 20 6d 61 6c 66 75 6e 63 74 ault or malfunct
19e60 69 6f 6e 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a ion.. *********
19e70 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19e80 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19e90 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
19ea0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 23 ************/..#
19eb0 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 45 58 if SQLITE_MAX_EX
19ec0 50 52 5f 44 45 50 54 48 3e 30 0a 20 20 69 6e 74 PR_DEPTH>0. int
19ed0 20 6e 48 65 69 67 68 74 3b 20 20 20 20 20 20 20 nHeight;
19ee0 20 20 20 20 2f 2a 20 48 65 69 67 68 74 20 6f 66 /* Height of
19ef0 20 74 68 65 20 74 72 65 65 20 68 65 61 64 65 64 the tree headed
19f00 20 62 79 20 74 68 69 73 20 6e 6f 64 65 20 2a 2f by this node */
19f10 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 69 54 .#endif. int iT
19f20 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 able;
19f30 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 /* TK_COLUMN: c
19f40 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 ursor number of
19f50 74 61 62 6c 65 20 68 6f 6c 64 69 6e 67 20 63 6f table holding co
19f60 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 20 20 lumn.
19f70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
19f80 20 54 4b 5f 52 45 47 49 53 54 45 52 3a 20 72 65 TK_REGISTER: re
19f90 67 69 73 74 65 72 20 6e 75 6d 62 65 72 0a 20 20 gister number.
19fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19fb0 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 54 52 49 ** TK_TRI
19fc0 47 47 45 52 3a 20 31 20 2d 3e 20 6e 65 77 2c 20 GGER: 1 -> new,
19fd0 30 20 2d 3e 20 6f 6c 64 0a 20 20 20 20 20 20 20 0 -> old.
19fe0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
19ff0 20 20 2a 2a 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 ** EP_Unlikely
1a000 3a 20 20 31 33 34 32 31 37 37 32 38 20 74 69 6d : 134217728 tim
1a010 65 73 20 6c 69 6b 65 6c 69 68 6f 6f 64 0a 20 20 es likelihood.
1a020 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a030 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 49 4e 3a ** TK_IN:
1a040 20 65 70 68 65 6d 65 72 69 61 6c 20 74 61 62 6c ephemerial tabl
1a050 65 20 68 6f 6c 64 69 6e 67 20 52 48 53 0a 20 20 e holding RHS.
1a060 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a070 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 53 45 4c ** TK_SEL
1a080 45 43 54 5f 43 4f 4c 55 4d 4e 3a 20 4e 75 6d 62 ECT_COLUMN: Numb
1a090 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 6f 6e er of columns on
1a0a0 20 74 68 65 20 4c 48 53 0a 20 20 20 20 20 20 20 the LHS.
1a0b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a0c0 20 20 2a 2a 20 54 4b 5f 53 45 4c 45 43 54 3a 20 ** TK_SELECT:
1a0d0 31 73 74 20 72 65 67 69 73 74 65 72 20 6f 66 20 1st register of
1a0e0 72 65 73 75 6c 74 20 76 65 63 74 6f 72 20 2a 2f result vector */
1a0f0 0a 20 20 79 6e 56 61 72 20 69 43 6f 6c 75 6d 6e . ynVar iColumn
1a100 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f ; /* TK_
1a110 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d 6e 20 69 COLUMN: column i
1a120 6e 64 65 78 2e 20 20 2d 31 20 66 6f 72 20 72 6f ndex. -1 for ro
1a130 77 69 64 2e 0a 20 20 20 20 20 20 20 20 20 20 20 wid..
1a140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
1a150 20 54 4b 5f 56 41 52 49 41 42 4c 45 3a 20 76 61 TK_VARIABLE: va
1a160 72 69 61 62 6c 65 20 6e 75 6d 62 65 72 20 28 61 riable number (a
1a170 6c 77 61 79 73 20 3e 3d 20 31 29 2e 0a 20 20 20 lways >= 1)..
1a180 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a190 20 20 20 20 20 20 2a 2a 20 54 4b 5f 53 45 4c 45 ** TK_SELE
1a1a0 43 54 5f 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d CT_COLUMN: colum
1a1b0 6e 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 n of the result
1a1c0 76 65 63 74 6f 72 20 2a 2f 0a 20 20 69 31 36 20 vector */. i16
1a1d0 69 41 67 67 3b 20 20 20 20 20 20 20 20 20 20 20 iAgg;
1a1e0 20 20 20 2f 2a 20 57 68 69 63 68 20 65 6e 74 72 /* Which entr
1a1f0 79 20 69 6e 20 70 41 67 67 49 6e 66 6f 2d 3e 61 y in pAggInfo->a
1a200 43 6f 6c 5b 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 Col[] or ->aFunc
1a210 5b 5d 20 2a 2f 0a 20 20 69 31 36 20 69 52 69 67 [] */. i16 iRig
1a220 68 74 4a 6f 69 6e 54 61 62 6c 65 3b 20 20 20 2f htJoinTable; /
1a230 2a 20 49 66 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e * If EP_FromJoin
1a240 2c 20 74 68 65 20 72 69 67 68 74 20 74 61 62 6c , the right tabl
1a250 65 20 6f 66 20 74 68 65 20 6a 6f 69 6e 20 2a 2f e of the join */
1a260 0a 20 20 75 38 20 6f 70 32 3b 20 20 20 20 20 20 . u8 op2;
1a270 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f /* TK_
1a280 52 45 47 49 53 54 45 52 2f 54 4b 5f 54 52 55 54 REGISTER/TK_TRUT
1a290 48 3a 20 6f 72 69 67 69 6e 61 6c 20 76 61 6c 75 H: original valu
1a2a0 65 20 6f 66 20 45 78 70 72 2e 6f 70 0a 20 20 20 e of Expr.op.
1a2b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a2c0 20 20 20 20 20 20 2a 2a 20 54 4b 5f 43 4f 4c 55 ** TK_COLU
1a2d0 4d 4e 3a 20 74 68 65 20 76 61 6c 75 65 20 6f 66 MN: the value of
1a2e0 20 70 35 20 66 6f 72 20 4f 50 5f 43 6f 6c 75 6d p5 for OP_Colum
1a2f0 6e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n.
1a300 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b ** TK
1a310 5f 41 47 47 5f 46 55 4e 43 54 49 4f 4e 3a 20 6e _AGG_FUNCTION: n
1a320 65 73 74 69 6e 67 20 64 65 70 74 68 20 2a 2f 0a esting depth */.
1a330 20 20 41 67 67 49 6e 66 6f 20 2a 70 41 67 67 49 AggInfo *pAggI
1a340 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 55 73 65 64 nfo; /* Used
1a350 20 62 79 20 54 4b 5f 41 47 47 5f 43 4f 4c 55 4d by TK_AGG_COLUM
1a360 4e 20 61 6e 64 20 54 4b 5f 41 47 47 5f 46 55 4e N and TK_AGG_FUN
1a370 43 54 49 4f 4e 20 2a 2f 0a 20 20 75 6e 69 6f 6e CTION */. union
1a380 20 7b 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 54 {. Table *pT
1a390 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ab; /*
1a3a0 20 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 54 61 62 6c TK_COLUMN: Tabl
1a3b0 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 63 6f 6c e containing col
1a3c0 75 6d 6e 2e 20 43 61 6e 20 62 65 20 4e 55 4c 4c umn. Can be NULL
1a3d0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1a3e0 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 66 ** f
1a3f0 6f 72 20 61 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 or a column of a
1a400 6e 20 69 6e 64 65 78 20 6f 6e 20 61 6e 20 65 78 n index on an ex
1a410 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 pression */.
1a420 57 69 6e 64 6f 77 20 2a 70 57 69 6e 3b 20 20 20 Window *pWin;
1a430 20 20 20 20 20 20 20 2f 2a 20 45 50 5f 57 69 6e /* EP_Win
1a440 46 75 6e 63 3a 20 57 69 6e 64 6f 77 2f 46 69 6c Func: Window/Fil
1a450 74 65 72 20 64 65 66 6e 20 66 6f 72 20 61 20 66 ter defn for a f
1a460 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 73 unction */. s
1a470 74 72 75 63 74 20 7b 20 20 20 20 20 20 20 20 20 truct {
1a480 20 20 20 20 20 20 2f 2a 20 54 4b 5f 49 4e 2c 20 /* TK_IN,
1a490 54 4b 5f 53 45 4c 45 43 54 2c 20 61 6e 64 20 54 TK_SELECT, and T
1a4a0 4b 5f 45 58 49 53 54 53 20 2a 2f 0a 20 20 20 20 K_EXISTS */.
1a4b0 20 20 69 6e 74 20 69 41 64 64 72 3b 20 20 20 20 int iAddr;
1a4c0 20 20 20 20 20 20 20 20 20 2f 2a 20 53 75 62 72 /* Subr
1a4d0 6f 75 74 69 6e 65 20 65 6e 74 72 79 20 61 64 64 outine entry add
1a4e0 72 65 73 73 20 2a 2f 0a 20 20 20 20 20 20 69 6e ress */. in
1a4f0 74 20 72 65 67 52 65 74 75 72 6e 3b 20 20 20 20 t regReturn;
1a500 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 /* Register
1a510 20 75 73 65 64 20 74 6f 20 68 6f 6c 64 20 72 65 used to hold re
1a520 74 75 72 6e 20 61 64 64 72 65 73 73 20 2a 2f 0a turn address */.
1a530 20 20 20 20 7d 20 73 75 62 3b 0a 20 20 7d 20 79 } sub;. } y
1a540 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ;.};../*.** The
1a550 66 6f 6c 6c 6f 77 69 6e 67 20 61 72 65 20 74 68 following are th
1a560 65 20 6d 65 61 6e 69 6e 67 73 20 6f 66 20 62 69 e meanings of bi
1a570 74 73 20 69 6e 20 74 68 65 20 45 78 70 72 2e 66 ts in the Expr.f
1a580 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2a 20 56 lags field..** V
1a590 61 6c 75 65 20 72 65 73 74 72 69 63 74 69 6f 6e alue restriction
1a5a0 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 s:.**.**
1a5b0 20 20 45 50 5f 41 67 67 20 3d 3d 20 4e 43 5f 48 EP_Agg == NC_H
1a5c0 61 73 41 67 67 20 3d 3d 20 53 46 5f 48 61 73 41 asAgg == SF_HasA
1a5d0 67 67 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 45 gg.** E
1a5e0 50 5f 57 69 6e 20 3d 3d 20 4e 43 5f 48 61 73 57 P_Win == NC_HasW
1a5f0 69 6e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 in.*/.#define EP
1a600 5f 46 72 6f 6d 4a 6f 69 6e 20 20 20 30 78 30 30 _FromJoin 0x00
1a610 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 6e 61 74 0001 /* Originat
1a620 65 73 20 69 6e 20 4f 4e 2f 55 53 49 4e 47 20 63 es in ON/USING c
1a630 6c 61 75 73 65 20 6f 66 20 6f 75 74 65 72 20 6a lause of outer j
1a640 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 oin */.#define E
1a650 50 5f 44 69 73 74 69 6e 63 74 20 20 20 30 78 30 P_Distinct 0x0
1a660 30 30 30 30 32 20 2f 2a 20 41 67 67 72 65 67 61 00002 /* Aggrega
1a670 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 te function with
1a680 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 DISTINCT keywor
1a690 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f d */.#define EP_
1a6a0 48 61 73 46 75 6e 63 20 20 20 20 30 78 30 30 30 HasFunc 0x000
1a6b0 30 30 34 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 004 /* Contains
1a6c0 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 66 75 6e 63 one or more func
1a6d0 74 69 6f 6e 73 20 6f 66 20 61 6e 79 20 6b 69 6e tions of any kin
1a6e0 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f d */.#define EP_
1a6f0 46 69 78 65 64 43 6f 6c 20 20 20 30 78 30 30 30 FixedCol 0x000
1a700 30 30 38 20 2f 2a 20 54 4b 5f 43 6f 6c 75 6d 6e 008 /* TK_Column
1a710 20 77 69 74 68 20 61 20 6b 6e 6f 77 6e 20 66 69 with a known fi
1a720 78 65 64 20 76 61 6c 75 65 20 2a 2f 0a 23 64 65 xed value */.#de
1a730 66 69 6e 65 20 45 50 5f 41 67 67 20 20 20 20 20 fine EP_Agg
1a740 20 20 20 30 78 30 30 30 30 31 30 20 2f 2a 20 43 0x000010 /* C
1a750 6f 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d ontains one or m
1a760 6f 72 65 20 61 67 67 72 65 67 61 74 65 20 66 75 ore aggregate fu
1a770 6e 63 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 nctions */.#defi
1a780 6e 65 20 45 50 5f 56 61 72 53 65 6c 65 63 74 20 ne EP_VarSelect
1a790 20 30 78 30 30 30 30 32 30 20 2f 2a 20 70 53 65 0x000020 /* pSe
1a7a0 6c 65 63 74 20 69 73 20 63 6f 72 72 65 6c 61 74 lect is correlat
1a7b0 65 64 2c 20 6e 6f 74 20 63 6f 6e 73 74 61 6e 74 ed, not constant
1a7c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 44 */.#define EP_D
1a7d0 62 6c 51 75 6f 74 65 64 20 20 30 78 30 30 30 30 blQuoted 0x0000
1a7e0 34 30 20 2f 2a 20 74 6f 6b 65 6e 2e 7a 20 77 61 40 /* token.z wa
1a7f0 73 20 6f 72 69 67 69 6e 61 6c 6c 79 20 69 6e 20 s originally in
1a800 22 2e 2e 2e 22 20 2a 2f 0a 23 64 65 66 69 6e 65 "..." */.#define
1a810 20 45 50 5f 49 6e 66 69 78 46 75 6e 63 20 20 30 EP_InfixFunc 0
1a820 78 30 30 30 30 38 30 20 2f 2a 20 54 72 75 65 20 x000080 /* True
1a830 66 6f 72 20 61 6e 20 69 6e 66 69 78 20 66 75 6e for an infix fun
1a840 63 74 69 6f 6e 3a 20 4c 49 4b 45 2c 20 47 4c 4f ction: LIKE, GLO
1a850 42 2c 20 65 74 63 20 2a 2f 0a 23 64 65 66 69 6e B, etc */.#defin
1a860 65 20 45 50 5f 43 6f 6c 6c 61 74 65 20 20 20 20 e EP_Collate
1a870 30 78 30 30 30 31 30 30 20 2f 2a 20 54 72 65 65 0x000100 /* Tree
1a880 20 63 6f 6e 74 61 69 6e 73 20 61 20 54 4b 5f 43 contains a TK_C
1a890 4f 4c 4c 41 54 45 20 6f 70 65 72 61 74 6f 72 20 OLLATE operator
1a8a0 2a 2f 0a 20 20 2f 2a 20 20 20 20 20 20 20 20 20 */. /*
1a8b0 20 20 20 20 20 20 20 20 20 30 78 30 30 30 32 30 0x00020
1a8c0 30 20 41 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 0 Available for
1a8d0 72 65 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 reuse */.#define
1a8e0 20 45 50 5f 49 6e 74 56 61 6c 75 65 20 20 20 30 EP_IntValue 0
1a8f0 78 30 30 30 34 30 30 20 2f 2a 20 49 6e 74 65 67 x000400 /* Integ
1a900 65 72 20 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e er value contain
1a910 65 64 20 69 6e 20 75 2e 69 56 61 6c 75 65 20 2a ed in u.iValue *
1a920 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 78 49 73 /.#define EP_xIs
1a930 53 65 6c 65 63 74 20 20 30 78 30 30 30 38 30 30 Select 0x000800
1a940 20 2f 2a 20 78 2e 70 53 65 6c 65 63 74 20 69 73 /* x.pSelect is
1a950 20 76 61 6c 69 64 20 28 6f 74 68 65 72 77 69 73 valid (otherwis
1a960 65 20 78 2e 70 4c 69 73 74 20 69 73 29 20 2a 2f e x.pList is) */
1a970 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 6b 69 70 .#define EP_Skip
1a980 20 20 20 20 20 20 20 30 78 30 30 31 30 30 30 20 0x001000
1a990 2f 2a 20 4f 70 65 72 61 74 6f 72 20 64 6f 65 73 /* Operator does
1a9a0 20 6e 6f 74 20 63 6f 6e 74 72 69 62 75 74 65 20 not contribute
1a9b0 74 6f 20 61 66 66 69 6e 69 74 79 20 2a 2f 0a 23 to affinity */.#
1a9c0 64 65 66 69 6e 65 20 45 50 5f 52 65 64 75 63 65 define EP_Reduce
1a9d0 64 20 20 20 20 30 78 30 30 32 30 30 30 20 2f 2a d 0x002000 /*
1a9e0 20 45 78 70 72 20 73 74 72 75 63 74 20 45 58 50 Expr struct EXP
1a9f0 52 5f 52 45 44 55 43 45 44 53 49 5a 45 20 62 79 R_REDUCEDSIZE by
1aa00 74 65 73 20 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 tes only */.#def
1aa10 69 6e 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 ine EP_TokenOnly
1aa20 20 20 30 78 30 30 34 30 30 30 20 2f 2a 20 45 78 0x004000 /* Ex
1aa30 70 72 20 73 74 72 75 63 74 20 45 58 50 52 5f 54 pr struct EXPR_T
1aa40 4f 4b 45 4e 4f 4e 4c 59 53 49 5a 45 20 62 79 74 OKENONLYSIZE byt
1aa50 65 73 20 6f 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 es only */.#defi
1aa60 6e 65 20 45 50 5f 57 69 6e 20 20 20 20 20 20 20 ne EP_Win
1aa70 20 30 78 30 30 38 30 30 30 20 2f 2a 20 43 6f 6e 0x008000 /* Con
1aa80 74 61 69 6e 73 20 77 69 6e 64 6f 77 20 66 75 6e tains window fun
1aa90 63 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e ctions */.#defin
1aaa0 65 20 45 50 5f 4d 65 6d 54 6f 6b 65 6e 20 20 20 e EP_MemToken
1aab0 30 78 30 31 30 30 30 30 20 2f 2a 20 4e 65 65 64 0x010000 /* Need
1aac0 20 74 6f 20 73 71 6c 69 74 65 33 44 62 46 72 65 to sqlite3DbFre
1aad0 65 28 29 20 45 78 70 72 2e 7a 54 6f 6b 65 6e 20 e() Expr.zToken
1aae0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4e 6f */.#define EP_No
1aaf0 52 65 64 75 63 65 20 20 20 30 78 30 32 30 30 30 Reduce 0x02000
1ab00 30 20 2f 2a 20 43 61 6e 6e 6f 74 20 45 58 50 52 0 /* Cannot EXPR
1ab10 44 55 50 5f 52 45 44 55 43 45 20 74 68 69 73 20 DUP_REDUCE this
1ab20 45 78 70 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 Expr */.#define
1ab30 45 50 5f 55 6e 6c 69 6b 65 6c 79 20 20 20 30 78 EP_Unlikely 0x
1ab40 30 34 30 30 30 30 20 2f 2a 20 75 6e 6c 69 6b 65 040000 /* unlike
1ab50 6c 79 28 29 20 6f 72 20 6c 69 6b 65 6c 69 68 6f ly() or likeliho
1ab60 6f 64 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f od() function */
1ab70 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f 6e 73 .#define EP_Cons
1ab80 74 46 75 6e 63 20 20 30 78 30 38 30 30 30 30 20 tFunc 0x080000
1ab90 2f 2a 20 41 20 53 51 4c 49 54 45 5f 46 55 4e 43 /* A SQLITE_FUNC
1aba0 5f 43 4f 4e 53 54 41 4e 54 20 6f 72 20 5f 53 4c _CONSTANT or _SL
1abb0 4f 43 48 4e 47 20 66 75 6e 63 74 69 6f 6e 20 2a OCHNG function *
1abc0 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 61 6e /.#define EP_Can
1abd0 42 65 4e 75 6c 6c 20 20 30 78 31 30 30 30 30 30 BeNull 0x100000
1abe0 20 2f 2a 20 43 61 6e 20 62 65 20 6e 75 6c 6c 20 /* Can be null
1abf0 64 65 73 70 69 74 65 20 4e 4f 54 20 4e 55 4c 4c despite NOT NULL
1ac00 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 constraint */.#
1ac10 64 65 66 69 6e 65 20 45 50 5f 53 75 62 71 75 65 define EP_Subque
1ac20 72 79 20 20 20 30 78 32 30 30 30 30 30 20 2f 2a ry 0x200000 /*
1ac30 20 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 Tree contains a
1ac40 20 54 4b 5f 53 45 4c 45 43 54 20 6f 70 65 72 61 TK_SELECT opera
1ac50 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 tor */.#define E
1ac60 50 5f 41 6c 69 61 73 20 20 20 20 20 20 30 78 34 P_Alias 0x4
1ac70 30 30 30 30 30 20 2f 2a 20 49 73 20 61 6e 20 61 00000 /* Is an a
1ac80 6c 69 61 73 20 66 6f 72 20 61 20 72 65 73 75 6c lias for a resul
1ac90 74 20 73 65 74 20 63 6f 6c 75 6d 6e 20 2a 2f 0a t set column */.
1aca0 23 64 65 66 69 6e 65 20 45 50 5f 4c 65 61 66 20 #define EP_Leaf
1acb0 20 20 20 20 20 20 30 78 38 30 30 30 30 30 20 2f 0x800000 /
1acc0 2a 20 45 78 70 72 2e 70 4c 65 66 74 2c 20 2e 70 * Expr.pLeft, .p
1acd0 52 69 67 68 74 2c 20 2e 75 2e 70 53 65 6c 65 63 Right, .u.pSelec
1ace0 74 20 61 6c 6c 20 4e 55 4c 4c 20 2a 2f 0a 23 64 t all NULL */.#d
1acf0 65 66 69 6e 65 20 45 50 5f 57 69 6e 46 75 6e 63 efine EP_WinFunc
1ad00 20 20 20 30 78 31 30 30 30 30 30 30 20 2f 2a 20 0x1000000 /*
1ad10 54 4b 5f 46 55 4e 43 54 49 4f 4e 20 77 69 74 68 TK_FUNCTION with
1ad20 20 45 78 70 72 2e 79 2e 70 57 69 6e 20 73 65 74 Expr.y.pWin set
1ad30 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 */.#define EP_S
1ad40 75 62 72 74 6e 20 20 20 20 30 78 32 30 30 30 30 ubrtn 0x20000
1ad50 30 30 20 2f 2a 20 55 73 65 73 20 45 78 70 72 2e 00 /* Uses Expr.
1ad60 79 2e 73 75 62 2e 20 54 4b 5f 49 4e 2c 20 5f 53 y.sub. TK_IN, _S
1ad70 45 4c 45 43 54 2c 20 6f 72 20 5f 45 58 49 53 54 ELECT, or _EXIST
1ad80 53 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f S */.#define EP_
1ad90 51 75 6f 74 65 64 20 20 20 20 30 78 34 30 30 30 Quoted 0x4000
1ada0 30 30 30 20 2f 2a 20 54 4b 5f 49 44 20 77 61 73 000 /* TK_ID was
1adb0 20 6f 72 69 67 69 6e 61 6c 6c 79 20 71 75 6f 74 originally quot
1adc0 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 ed */.#define EP
1add0 5f 53 74 61 74 69 63 20 20 20 20 30 78 38 30 30 _Static 0x800
1ade0 30 30 30 30 20 2f 2a 20 48 65 6c 64 20 69 6e 20 0000 /* Held in
1adf0 6d 65 6d 6f 72 79 20 6e 6f 74 20 6f 62 74 61 69 memory not obtai
1ae00 6e 65 64 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 ned from malloc(
1ae10 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f ) */.#define EP_
1ae20 49 73 54 72 75 65 20 20 20 30 78 31 30 30 30 30 IsTrue 0x10000
1ae30 30 30 30 20 2f 2a 20 41 6c 77 61 79 73 20 68 61 000 /* Always ha
1ae40 73 20 62 6f 6f 6c 65 61 6e 20 76 61 6c 75 65 20 s boolean value
1ae50 6f 66 20 54 52 55 45 20 2a 2f 0a 23 64 65 66 69 of TRUE */.#defi
1ae60 6e 65 20 45 50 5f 49 73 46 61 6c 73 65 20 20 30 ne EP_IsFalse 0
1ae70 78 32 30 30 30 30 30 30 30 20 2f 2a 20 41 6c 77 x20000000 /* Alw
1ae80 61 79 73 20 68 61 73 20 62 6f 6f 6c 65 61 6e 20 ays has boolean
1ae90 76 61 6c 75 65 20 6f 66 20 46 41 4c 53 45 20 2a value of FALSE *
1aea0 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 6e 64 /.#define EP_Ind
1aeb0 69 72 65 63 74 20 30 78 34 30 30 30 30 30 30 30 irect 0x40000000
1aec0 20 2f 2a 20 43 6f 6e 74 61 69 6e 65 64 20 77 69 /* Contained wi
1aed0 74 68 69 6e 20 61 20 54 52 49 47 47 45 52 20 6f thin a TRIGGER o
1aee0 72 20 61 20 56 49 45 57 20 2a 2f 0a 0a 2f 2a 0a r a VIEW */../*.
1aef0 2a 2a 20 54 68 65 20 45 50 5f 50 72 6f 70 61 67 ** The EP_Propag
1af00 61 74 65 20 6d 61 73 6b 20 69 73 20 61 20 73 65 ate mask is a se
1af10 74 20 6f 66 20 70 72 6f 70 65 72 74 69 65 73 20 t of properties
1af20 74 68 61 74 20 61 75 74 6f 6d 61 74 69 63 61 6c that automatical
1af30 6c 79 20 70 72 6f 70 61 67 61 74 65 0a 2a 2a 20 ly propagate.**
1af40 75 70 77 61 72 64 73 20 69 6e 74 6f 20 70 61 72 upwards into par
1af50 65 6e 74 20 6e 6f 64 65 73 2e 0a 2a 2f 0a 23 64 ent nodes..*/.#d
1af60 65 66 69 6e 65 20 45 50 5f 50 72 6f 70 61 67 61 efine EP_Propaga
1af70 74 65 20 28 45 50 5f 43 6f 6c 6c 61 74 65 7c 45 te (EP_Collate|E
1af80 50 5f 53 75 62 71 75 65 72 79 7c 45 50 5f 48 61 P_Subquery|EP_Ha
1af90 73 46 75 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 sFunc)../*.** Th
1afa0 65 73 65 20 6d 61 63 72 6f 73 20 63 61 6e 20 62 ese macros can b
1afb0 65 20 75 73 65 64 20 74 6f 20 74 65 73 74 2c 20 e used to test,
1afc0 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 20 62 69 set, or clear bi
1afd0 74 73 20 69 6e 20 74 68 65 0a 2a 2a 20 45 78 70 ts in the.** Exp
1afe0 72 2e 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a r.flags field..*
1aff0 2f 0a 23 64 65 66 69 6e 65 20 45 78 70 72 48 61 /.#define ExprHa
1b000 73 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 sProperty(E,P)
1b010 20 20 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 (((E)->flags&
1b020 28 50 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 (P))!=0).#define
1b030 20 45 78 70 72 48 61 73 41 6c 6c 50 72 6f 70 65 ExprHasAllPrope
1b040 72 74 79 28 45 2c 50 29 20 20 28 28 28 45 29 2d rty(E,P) (((E)-
1b050 3e 66 6c 61 67 73 26 28 50 29 29 3d 3d 28 50 29 >flags&(P))==(P)
1b060 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 53 65 ).#define ExprSe
1b070 74 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 tProperty(E,P)
1b080 20 20 20 28 45 29 2d 3e 66 6c 61 67 73 7c 3d 28 (E)->flags|=(
1b090 50 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 43 P).#define ExprC
1b0a0 6c 65 61 72 50 72 6f 70 65 72 74 79 28 45 2c 50 learProperty(E,P
1b0b0 29 20 20 20 28 45 29 2d 3e 66 6c 61 67 73 26 3d ) (E)->flags&=
1b0c0 7e 28 50 29 0a 23 64 65 66 69 6e 65 20 45 78 70 ~(P).#define Exp
1b0d0 72 41 6c 77 61 79 73 54 72 75 65 28 45 29 20 20 rAlwaysTrue(E)
1b0e0 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 45 (((E)->flags&(E
1b0f0 50 5f 46 72 6f 6d 4a 6f 69 6e 7c 45 50 5f 49 73 P_FromJoin|EP_Is
1b100 54 72 75 65 29 29 3d 3d 45 50 5f 49 73 54 72 75 True))==EP_IsTru
1b110 65 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 41 e).#define ExprA
1b120 6c 77 61 79 73 46 61 6c 73 65 28 45 29 20 20 28 lwaysFalse(E) (
1b130 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 45 50 5f ((E)->flags&(EP_
1b140 46 72 6f 6d 4a 6f 69 6e 7c 45 50 5f 49 73 46 61 FromJoin|EP_IsFa
1b150 6c 73 65 29 29 3d 3d 45 50 5f 49 73 46 61 6c 73 lse))==EP_IsFals
1b160 65 29 0a 0a 2f 2a 20 54 68 65 20 45 78 70 72 53 e)../* The ExprS
1b170 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 29 20 etVVAProperty()
1b180 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 66 6f macro is used fo
1b190 72 20 56 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 r Verification,
1b1a0 56 61 6c 69 64 61 74 69 6f 6e 2c 0a 2a 2a 20 61 Validation,.** a
1b1b0 6e 64 20 41 63 63 72 65 64 69 74 61 74 69 6f 6e nd Accreditation
1b1c0 20 6f 6e 6c 79 2e 20 20 49 74 20 77 6f 72 6b 73 only. It works
1b1d0 20 6c 69 6b 65 20 45 78 70 72 53 65 74 50 72 6f like ExprSetPro
1b1e0 70 65 72 74 79 28 29 20 64 75 72 69 6e 67 20 56 perty() during V
1b1f0 56 41 0a 2a 2a 20 70 72 6f 63 65 73 73 65 73 20 VA.** processes
1b200 62 75 74 20 69 73 20 61 20 6e 6f 2d 6f 70 20 66 but is a no-op f
1b210 6f 72 20 64 65 6c 69 76 65 72 79 2e 0a 2a 2f 0a or delivery..*/.
1b220 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 #ifdef SQLITE_DE
1b230 42 55 47 0a 23 20 64 65 66 69 6e 65 20 45 78 70 BUG.# define Exp
1b240 72 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 rSetVVAProperty(
1b250 45 2c 50 29 20 20 28 45 29 2d 3e 66 6c 61 67 73 E,P) (E)->flags
1b260 7c 3d 28 50 29 0a 23 65 6c 73 65 0a 23 20 64 65 |=(P).#else.# de
1b270 66 69 6e 65 20 45 78 70 72 53 65 74 56 56 41 50 fine ExprSetVVAP
1b280 72 6f 70 65 72 74 79 28 45 2c 50 29 0a 23 65 6e roperty(E,P).#en
1b290 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f dif../*.** Macro
1b2a0 73 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 74 s to determine t
1b2b0 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 62 79 74 he number of byt
1b2c0 65 73 20 72 65 71 75 69 72 65 64 20 62 79 20 61 es required by a
1b2d0 20 6e 6f 72 6d 61 6c 20 45 78 70 72 0a 2a 2a 20 normal Expr.**
1b2e0 73 74 72 75 63 74 2c 20 61 6e 20 45 78 70 72 20 struct, an Expr
1b2f0 73 74 72 75 63 74 20 77 69 74 68 20 74 68 65 20 struct with the
1b300 45 50 5f 52 65 64 75 63 65 64 20 66 6c 61 67 20 EP_Reduced flag
1b310 73 65 74 20 69 6e 20 45 78 70 72 2e 66 6c 61 67 set in Expr.flag
1b320 73 0a 2a 2a 20 61 6e 64 20 61 6e 20 45 78 70 72 s.** and an Expr
1b330 20 73 74 72 75 63 74 20 77 69 74 68 20 74 68 65 struct with the
1b340 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c EP_TokenOnly fl
1b350 61 67 20 73 65 74 2e 0a 2a 2f 0a 23 64 65 66 69 ag set..*/.#defi
1b360 6e 65 20 45 58 50 52 5f 46 55 4c 4c 53 49 5a 45 ne EXPR_FULLSIZE
1b370 20 20 20 20 20 20 20 20 20 20 20 73 69 7a 65 6f sizeo
1b380 66 28 45 78 70 72 29 20 20 20 20 20 20 20 20 20 f(Expr)
1b390 20 20 2f 2a 20 46 75 6c 6c 20 73 69 7a 65 20 2a /* Full size *
1b3a0 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 5f 52 /.#define EXPR_R
1b3b0 45 44 55 43 45 44 53 49 5a 45 20 20 20 20 20 20 EDUCEDSIZE
1b3c0 20 20 6f 66 66 73 65 74 6f 66 28 45 78 70 72 2c offsetof(Expr,
1b3d0 69 54 61 62 6c 65 29 20 20 2f 2a 20 43 6f 6d 6d iTable) /* Comm
1b3e0 6f 6e 20 66 65 61 74 75 72 65 73 20 2a 2f 0a 23 on features */.#
1b3f0 64 65 66 69 6e 65 20 45 58 50 52 5f 54 4f 4b 45 define EXPR_TOKE
1b400 4e 4f 4e 4c 59 53 49 5a 45 20 20 20 20 20 20 6f NONLYSIZE o
1b410 66 66 73 65 74 6f 66 28 45 78 70 72 2c 70 4c 65 ffsetof(Expr,pLe
1b420 66 74 29 20 20 20 2f 2a 20 46 65 77 65 72 20 66 ft) /* Fewer f
1b430 65 61 74 75 72 65 73 20 2a 2f 0a 0a 2f 2a 0a 2a eatures */../*.*
1b440 2a 20 46 6c 61 67 73 20 70 61 73 73 65 64 20 74 * Flags passed t
1b450 6f 20 74 68 65 20 73 71 6c 69 74 65 33 45 78 70 o the sqlite3Exp
1b460 72 44 75 70 28 29 20 66 75 6e 63 74 69 6f 6e 2e rDup() function.
1b470 20 53 65 65 20 74 68 65 20 68 65 61 64 65 72 20 See the header
1b480 63 6f 6d 6d 65 6e 74 0a 2a 2a 20 61 62 6f 76 65 comment.** above
1b490 20 73 71 6c 69 74 65 33 45 78 70 72 44 75 70 28 sqlite3ExprDup(
1b4a0 29 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 0a 2a ) for details..*
1b4b0 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 44 55 /.#define EXPRDU
1b4c0 50 5f 52 45 44 55 43 45 20 20 20 20 20 20 20 20 P_REDUCE
1b4d0 20 30 78 30 30 30 31 20 20 2f 2a 20 55 73 65 64 0x0001 /* Used
1b4e0 20 72 65 64 75 63 65 64 2d 73 69 7a 65 20 45 78 reduced-size Ex
1b4f0 70 72 20 6e 6f 64 65 73 20 2a 2f 0a 0a 2f 2a 0a pr nodes */../*.
1b500 2a 2a 20 54 72 75 65 20 69 66 20 74 68 65 20 65 ** True if the e
1b510 78 70 72 65 73 73 69 6f 6e 20 70 61 73 73 65 64 xpression passed
1b520 20 61 73 20 61 6e 20 61 72 67 75 6d 65 6e 74 20 as an argument
1b530 77 61 73 20 61 20 66 75 6e 63 74 69 6f 6e 20 77 was a function w
1b540 69 74 68 0a 2a 2a 20 61 6e 20 4f 56 45 52 28 29 ith.** an OVER()
1b550 20 63 6c 61 75 73 65 20 28 61 20 77 69 6e 64 6f clause (a windo
1b560 77 20 66 75 6e 63 74 69 6f 6e 29 2e 0a 2a 2f 0a w function)..*/.
1b570 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d #ifdef SQLITE_OM
1b580 49 54 5f 57 49 4e 44 4f 57 46 55 4e 43 0a 23 20 IT_WINDOWFUNC.#
1b590 64 65 66 69 6e 65 20 49 73 57 69 6e 64 6f 77 46 define IsWindowF
1b5a0 75 6e 63 28 70 29 20 30 0a 23 65 6c 73 65 0a 23 unc(p) 0.#else.#
1b5b0 20 64 65 66 69 6e 65 20 49 73 57 69 6e 64 6f 77 define IsWindow
1b5c0 46 75 6e 63 28 70 29 20 28 20 5c 0a 20 20 20 20 Func(p) ( \.
1b5d0 45 78 70 72 48 61 73 50 72 6f 70 65 72 74 79 28 ExprHasProperty(
1b5e0 28 70 29 2c 20 45 50 5f 57 69 6e 46 75 6e 63 29 (p), EP_WinFunc)
1b5f0 20 26 26 20 70 2d 3e 79 2e 70 57 69 6e 2d 3e 65 && p->y.pWin->e
1b600 46 72 6d 54 79 70 65 21 3d 54 4b 5f 46 49 4c 54 FrmType!=TK_FILT
1b610 45 52 20 5c 0a 20 29 0a 23 65 6e 64 69 66 0a 0a ER \. ).#endif..
1b620 2f 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 6f 66 20 /*.** A list of
1b630 65 78 70 72 65 73 73 69 6f 6e 73 2e 20 20 45 61 expressions. Ea
1b640 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 6d 61 ch expression ma
1b650 79 20 6f 70 74 69 6f 6e 61 6c 6c 79 20 68 61 76 y optionally hav
1b660 65 20 61 0a 2a 2a 20 6e 61 6d 65 2e 20 20 41 6e e a.** name. An
1b670 20 65 78 70 72 2f 6e 61 6d 65 20 63 6f 6d 62 69 expr/name combi
1b680 6e 61 74 69 6f 6e 20 63 61 6e 20 62 65 20 75 73 nation can be us
1b690 65 64 20 69 6e 20 73 65 76 65 72 61 6c 20 77 61 ed in several wa
1b6a0 79 73 2c 20 73 75 63 68 0a 2a 2a 20 61 73 20 74 ys, such.** as t
1b6b0 68 65 20 6c 69 73 74 20 6f 66 20 22 65 78 70 72 he list of "expr
1b6c0 20 41 53 20 49 44 22 20 66 69 65 6c 64 73 20 66 AS ID" fields f
1b6d0 6f 6c 6c 6f 77 69 6e 67 20 61 20 22 53 45 4c 45 ollowing a "SELE
1b6e0 43 54 22 20 6f 72 20 69 6e 20 74 68 65 0a 2a 2a CT" or in the.**
1b6f0 20 6c 69 73 74 20 6f 66 20 22 49 44 20 3d 20 65 list of "ID = e
1b700 78 70 72 22 20 69 74 65 6d 73 20 69 6e 20 61 6e xpr" items in an
1b710 20 55 50 44 41 54 45 2e 20 20 41 20 6c 69 73 74 UPDATE. A list
1b720 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 of expressions
1b730 63 61 6e 0a 2a 2a 20 61 6c 73 6f 20 62 65 20 75 can.** also be u
1b740 73 65 64 20 61 73 20 74 68 65 20 61 72 67 75 6d sed as the argum
1b750 65 6e 74 20 74 6f 20 61 20 66 75 6e 63 74 69 6f ent to a functio
1b760 6e 2c 20 69 6e 20 77 68 69 63 68 20 63 61 73 65 n, in which case
1b770 20 74 68 65 20 61 2e 7a 4e 61 6d 65 0a 2a 2a 20 the a.zName.**
1b780 66 69 65 6c 64 20 69 73 20 6e 6f 74 20 75 73 65 field is not use
1b790 64 2e 0a 2a 2a 0a 2a 2a 20 42 79 20 64 65 66 61 d..**.** By defa
1b7a0 75 6c 74 20 74 68 65 20 45 78 70 72 2e 7a 53 70 ult the Expr.zSp
1b7b0 61 6e 20 66 69 65 6c 64 20 68 6f 6c 64 73 20 61 an field holds a
1b7c0 20 68 75 6d 61 6e 2d 72 65 61 64 61 62 6c 65 20 human-readable
1b7d0 64 65 73 63 72 69 70 74 69 6f 6e 20 6f 66 0a 2a description of.*
1b7e0 2a 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e * the expression
1b7f0 20 74 68 61 74 20 69 73 20 75 73 65 64 20 69 6e that is used in
1b800 20 74 68 65 20 67 65 6e 65 72 61 74 69 6f 6e 20 the generation
1b810 6f 66 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 of error message
1b820 73 20 61 6e 64 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 s and.** column
1b830 6c 61 62 65 6c 73 2e 20 20 49 6e 20 74 68 69 73 labels. In this
1b840 20 63 61 73 65 2c 20 45 78 70 72 2e 7a 53 70 61 case, Expr.zSpa
1b850 6e 20 69 73 20 74 79 70 69 63 61 6c 6c 79 20 74 n is typically t
1b860 68 65 20 74 65 78 74 20 6f 66 20 61 0a 2a 2a 20 he text of a.**
1b870 63 6f 6c 75 6d 6e 20 65 78 70 72 65 73 73 69 6f column expressio
1b880 6e 20 61 73 20 69 74 20 65 78 69 73 74 73 20 69 n as it exists i
1b890 6e 20 61 20 53 45 4c 45 43 54 20 73 74 61 74 65 n a SELECT state
1b8a0 6d 65 6e 74 2e 20 20 48 6f 77 65 76 65 72 2c 20 ment. However,
1b8b0 69 66 0a 2a 2a 20 74 68 65 20 62 53 70 61 6e 49 if.** the bSpanI
1b8c0 73 54 61 62 20 66 6c 61 67 20 69 73 20 73 65 74 sTab flag is set
1b8d0 2c 20 74 68 65 6e 20 7a 53 70 61 6e 20 69 73 20 , then zSpan is
1b8e0 6f 76 65 72 6c 6f 61 64 65 64 20 74 6f 20 6d 65 overloaded to me
1b8f0 61 6e 20 74 68 65 20 6e 61 6d 65 0a 2a 2a 20 6f an the name.** o
1b900 66 20 74 68 65 20 72 65 73 75 6c 74 20 63 6f 6c f the result col
1b910 75 6d 6e 20 69 6e 20 74 68 65 20 66 6f 72 6d 3a umn in the form:
1b920 20 44 41 54 41 42 41 53 45 2e 54 41 42 4c 45 2e DATABASE.TABLE.
1b930 43 4f 4c 55 4d 4e 2e 20 20 54 68 69 73 20 6c 61 COLUMN. This la
1b940 74 65 72 0a 2a 2a 20 66 6f 72 6d 20 69 73 20 75 ter.** form is u
1b950 73 65 64 20 66 6f 72 20 6e 61 6d 65 20 72 65 73 sed for name res
1b960 6f 6c 75 74 69 6f 6e 20 77 69 74 68 20 6e 65 73 olution with nes
1b970 74 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 73 ted FROM clauses
1b980 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 70 72 ..*/.struct Expr
1b990 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 45 78 List {. int nEx
1b9a0 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pr;
1b9b0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 78 70 /* Number of exp
1b9c0 72 65 73 73 69 6f 6e 73 20 6f 6e 20 74 68 65 20 ressions on the
1b9d0 6c 69 73 74 20 2a 2f 0a 20 20 73 74 72 75 63 74 list */. struct
1b9e0 20 45 78 70 72 4c 69 73 74 5f 69 74 65 6d 20 7b ExprList_item {
1b9f0 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 65 78 70 /* For each exp
1ba00 72 65 73 73 69 6f 6e 20 69 6e 20 74 68 65 20 6c ression in the l
1ba10 69 73 74 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 ist */. Expr
1ba20 2a 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 *pExpr;
1ba30 20 20 20 2f 2a 20 54 68 65 20 70 61 72 73 65 20 /* The parse
1ba40 74 72 65 65 20 66 6f 72 20 74 68 69 73 20 65 78 tree for this ex
1ba50 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 pression */.
1ba60 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
1ba70 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e /* Token
1ba80 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
1ba90 20 74 68 69 73 20 65 78 70 72 65 73 73 69 6f 6e this expression
1baa0 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 53 */. char *zS
1bab0 70 61 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 pan;
1bac0 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 74 65 78 74 /* Original text
1bad0 20 6f 66 20 74 68 65 20 65 78 70 72 65 73 73 69 of the expressi
1bae0 6f 6e 20 2a 2f 0a 20 20 20 20 75 38 20 73 6f 72 on */. u8 sor
1baf0 74 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 tFlags;
1bb00 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 4b 45 59 /* Mask of KEY
1bb10 49 4e 46 4f 5f 4f 52 44 45 52 5f 2a 20 66 6c 61 INFO_ORDER_* fla
1bb20 67 73 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e gs */. unsign
1bb30 65 64 20 64 6f 6e 65 20 3a 31 3b 20 20 20 20 20 ed done :1;
1bb40 20 20 2f 2a 20 41 20 66 6c 61 67 20 74 6f 20 69 /* A flag to i
1bb50 6e 64 69 63 61 74 65 20 77 68 65 6e 20 70 72 6f ndicate when pro
1bb60 63 65 73 73 69 6e 67 20 69 73 20 66 69 6e 69 73 cessing is finis
1bb70 68 65 64 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 hed */. unsig
1bb80 6e 65 64 20 62 53 70 61 6e 49 73 54 61 62 20 3a ned bSpanIsTab :
1bb90 31 3b 20 2f 2a 20 7a 53 70 61 6e 20 68 6f 6c 64 1; /* zSpan hold
1bba0 73 20 44 42 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d s DB.TABLE.COLUM
1bbb0 4e 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 N */. unsigne
1bbc0 64 20 72 65 75 73 61 62 6c 65 20 3a 31 3b 20 20 d reusable :1;
1bbd0 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 78 70 /* Constant exp
1bbe0 72 65 73 73 69 6f 6e 20 69 73 20 72 65 75 73 61 ression is reusa
1bbf0 62 6c 65 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 ble */. unsig
1bc00 6e 65 64 20 62 53 6f 72 74 65 72 52 65 66 20 3a ned bSorterRef :
1bc10 31 3b 20 2f 2a 20 44 65 66 65 72 20 65 76 61 6c 1; /* Defer eval
1bc20 75 61 74 69 6f 6e 20 75 6e 74 69 6c 20 61 66 74 uation until aft
1bc30 65 72 20 73 6f 72 74 69 6e 67 20 2a 2f 0a 20 20 er sorting */.
1bc40 20 20 75 6e 73 69 67 6e 65 64 20 62 4e 75 6c 6c unsigned bNull
1bc50 73 3a 20 31 3b 20 20 20 20 20 2f 2a 20 54 72 75 s: 1; /* Tru
1bc60 65 20 69 66 20 65 78 70 6c 69 63 69 74 20 22 4e e if explicit "N
1bc70 55 4c 4c 53 20 46 49 52 53 54 2f 4c 41 53 54 22 ULLS FIRST/LAST"
1bc80 20 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b 0a */. union {.
1bc90 20 20 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 struct {.
1bca0 20 20 20 20 20 20 20 75 31 36 20 69 4f 72 64 65 u16 iOrde
1bcb0 72 42 79 43 6f 6c 3b 20 20 20 20 20 20 2f 2a 20 rByCol; /*
1bcc0 46 6f 72 20 4f 52 44 45 52 20 42 59 2c 20 63 6f For ORDER BY, co
1bcd0 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e 20 72 lumn number in r
1bce0 65 73 75 6c 74 20 73 65 74 20 2a 2f 0a 20 20 20 esult set */.
1bcf0 20 20 20 20 20 75 31 36 20 69 41 6c 69 61 73 3b u16 iAlias;
1bd00 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e /* In
1bd10 64 65 78 20 69 6e 74 6f 20 50 61 72 73 65 2e 61 dex into Parse.a
1bd20 41 6c 69 61 73 5b 5d 20 66 6f 72 20 7a 4e 61 6d Alias[] for zNam
1bd30 65 20 2a 2f 0a 20 20 20 20 20 20 7d 20 78 3b 0a e */. } x;.
1bd40 20 20 20 20 20 20 69 6e 74 20 69 43 6f 6e 73 74 int iConst
1bd50 45 78 70 72 52 65 67 3b 20 20 20 20 20 20 2f 2a ExprReg; /*
1bd60 20 52 65 67 69 73 74 65 72 20 69 6e 20 77 68 69 Register in whi
1bd70 63 68 20 45 78 70 72 20 76 61 6c 75 65 20 69 73 ch Expr value is
1bd80 20 63 61 63 68 65 64 20 2a 2f 0a 20 20 20 20 7d cached */. }
1bd90 20 75 3b 0a 20 20 7d 20 61 5b 31 5d 3b 20 20 20 u;. } a[1];
1bda0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1bdb0 2a 20 4f 6e 65 20 73 6c 6f 74 20 66 6f 72 20 65 * One slot for e
1bdc0 61 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 69 ach expression i
1bdd0 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b n the list */.};
1bde0 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 ../*.** An insta
1bdf0 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 nce of this stru
1be00 63 74 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 61 cture can hold a
1be10 20 73 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 20 simple list of
1be20 69 64 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a 20 identifiers,.**
1be30 73 75 63 68 20 61 73 20 74 68 65 20 6c 69 73 74 such as the list
1be40 20 22 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 20 "a,b,c" in the
1be50 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 6d following statem
1be60 65 6e 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ents:.**.**
1be70 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 INSERT INTO t(a
1be80 2c 62 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e 2e ,b,c) VALUES ...
1be90 3b 0a 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 ;.** CREATE
1bea0 20 49 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 28 INDEX idx ON t(
1beb0 61 2c 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 20 a,b,c);.**
1bec0 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20 74 CREATE TRIGGER t
1bed0 72 69 67 20 42 45 46 4f 52 45 20 55 50 44 41 54 rig BEFORE UPDAT
1bee0 45 20 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e 2e E ON t(a,b,c) ..
1bef0 2e 3b 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 4c .;.**.** The IdL
1bf00 69 73 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 20 ist.a.idx field
1bf10 69 73 20 75 73 65 64 20 77 68 65 6e 20 74 68 65 is used when the
1bf20 20 49 64 4c 69 73 74 20 72 65 70 72 65 73 65 6e IdList represen
1bf30 74 73 20 74 68 65 20 6c 69 73 74 20 6f 66 0a 2a ts the list of.*
1bf40 2a 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 * column names a
1bf50 66 74 65 72 20 61 20 74 61 62 6c 65 20 6e 61 6d fter a table nam
1bf60 65 20 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 73 e in an INSERT s
1bf70 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 68 tatement. In th
1bf80 65 20 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a 2a e statement.**.*
1bf90 2a 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 * INSERT INT
1bfa0 4f 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a 2a O t(a,b,c) ....*
1bfb0 2a 0a 2a 2a 20 49 66 20 22 61 22 20 69 73 20 74 *.** If "a" is t
1bfc0 68 65 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 6f he k-th column o
1bfd0 66 20 74 61 62 6c 65 20 22 74 22 2c 20 74 68 65 f table "t", the
1bfe0 6e 20 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 64 n IdList.a[0].id
1bff0 78 3d 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 x==k..*/.struct
1c000 49 64 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 63 IdList {. struc
1c010 74 20 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b 0a t IdList_item {.
1c020 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b char *zName;
1c030 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 /* Name of
1c040 20 74 68 65 20 69 64 65 6e 74 69 66 69 65 72 20 the identifier
1c050 2a 2f 0a 20 20 20 20 69 6e 74 20 69 64 78 3b 20 */. int idx;
1c060 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 /* Inde
1c070 78 20 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 2e x in some Table.
1c080 61 43 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c 75 aCol[] of a colu
1c090 6d 6e 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 2a mn named zName *
1c0a0 2f 0a 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 20 /. } *a;. int
1c0b0 6e 49 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 nId; /*
1c0c0 4e 75 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 69 Number of identi
1c0d0 66 69 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 73 fiers on the lis
1c0e0 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 t */.};../*.** T
1c0f0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
1c100 75 63 74 75 72 65 20 64 65 73 63 72 69 62 65 73 ucture describes
1c110 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 the FROM clause
1c120 20 6f 66 20 61 20 53 45 4c 45 43 54 20 73 74 61 of a SELECT sta
1c130 74 65 6d 65 6e 74 2e 0a 2a 2a 20 45 61 63 68 20 tement..** Each
1c140 74 61 62 6c 65 20 6f 72 20 73 75 62 71 75 65 72 table or subquer
1c150 79 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c y in the FROM cl
1c160 61 75 73 65 20 69 73 20 61 20 73 65 70 61 72 61 ause is a separa
1c170 74 65 20 65 6c 65 6d 65 6e 74 20 6f 66 0a 2a 2a te element of.**
1c180 20 74 68 65 20 53 72 63 4c 69 73 74 2e 61 5b 5d the SrcList.a[]
1c190 20 61 72 72 61 79 2e 0a 2a 2a 0a 2a 2a 20 57 69 array..**.** Wi
1c1a0 74 68 20 74 68 65 20 61 64 64 69 74 69 6f 6e 20 th the addition
1c1b0 6f 66 20 6d 75 6c 74 69 70 6c 65 20 64 61 74 61 of multiple data
1c1c0 62 61 73 65 20 73 75 70 70 6f 72 74 2c 20 74 68 base support, th
1c1d0 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
1c1e0 63 74 75 72 65 0a 2a 2a 20 63 61 6e 20 61 6c 73 cture.** can als
1c1f0 6f 20 62 65 20 75 73 65 64 20 74 6f 20 64 65 73 o be used to des
1c200 63 72 69 62 65 20 61 20 70 61 72 74 69 63 75 6c cribe a particul
1c210 61 72 20 74 61 62 6c 65 20 73 75 63 68 20 61 73 ar table such as
1c220 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 0a the table that.
1c230 2a 2a 20 69 73 20 6d 6f 64 69 66 69 65 64 20 62 ** is modified b
1c240 79 20 61 6e 20 49 4e 53 45 52 54 2c 20 44 45 4c y an INSERT, DEL
1c250 45 54 45 2c 20 6f 72 20 55 50 44 41 54 45 20 73 ETE, or UPDATE s
1c260 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 73 74 tatement. In st
1c270 61 6e 64 61 72 64 20 53 51 4c 2c 0a 2a 2a 20 73 andard SQL,.** s
1c280 75 63 68 20 61 20 74 61 62 6c 65 20 6d 75 73 74 uch a table must
1c290 20 62 65 20 61 20 73 69 6d 70 6c 65 20 6e 61 6d be a simple nam
1c2a0 65 3a 20 49 44 2e 20 20 42 75 74 20 69 6e 20 53 e: ID. But in S
1c2b0 51 4c 69 74 65 2c 20 74 68 65 20 74 61 62 6c 65 QLite, the table
1c2c0 20 63 61 6e 0a 2a 2a 20 6e 6f 77 20 62 65 20 69 can.** now be i
1c2d0 64 65 6e 74 69 66 69 65 64 20 62 79 20 61 20 64 dentified by a d
1c2e0 61 74 61 62 61 73 65 20 6e 61 6d 65 2c 20 61 20 atabase name, a
1c2f0 64 6f 74 2c 20 74 68 65 6e 20 74 68 65 20 74 61 dot, then the ta
1c300 62 6c 65 20 6e 61 6d 65 3a 20 49 44 2e 49 44 2e ble name: ID.ID.
1c310 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6a 6f 69 6e 74 .**.** The joint
1c320 79 70 65 20 73 74 61 72 74 73 20 6f 75 74 20 73 ype starts out s
1c330 68 6f 77 69 6e 67 20 74 68 65 20 6a 6f 69 6e 20 howing the join
1c340 74 79 70 65 20 62 65 74 77 65 65 6e 20 74 68 65 type between the
1c350 20 63 75 72 72 65 6e 74 20 74 61 62 6c 65 0a 2a current table.*
1c360 2a 20 61 6e 64 20 74 68 65 20 6e 65 78 74 20 74 * and the next t
1c370 61 62 6c 65 20 6f 6e 20 74 68 65 20 6c 69 73 74 able on the list
1c380 2e 20 20 54 68 65 20 70 61 72 73 65 72 20 62 75 . The parser bu
1c390 69 6c 64 73 20 74 68 65 20 6c 69 73 74 20 74 68 ilds the list th
1c3a0 69 73 20 77 61 79 2e 0a 2a 2a 20 42 75 74 20 73 is way..** But s
1c3b0 71 6c 69 74 65 33 53 72 63 4c 69 73 74 53 68 69 qlite3SrcListShi
1c3c0 66 74 4a 6f 69 6e 54 79 70 65 28 29 20 6c 61 74 ftJoinType() lat
1c3d0 65 72 20 73 68 69 66 74 73 20 74 68 65 20 6a 6f er shifts the jo
1c3e0 69 6e 74 79 70 65 73 20 73 6f 20 74 68 61 74 20 intypes so that
1c3f0 65 61 63 68 0a 2a 2a 20 6a 6f 69 6e 74 79 70 65 each.** jointype
1c400 20 65 78 70 72 65 73 73 65 73 20 74 68 65 20 6a expresses the j
1c410 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 65 20 oin between the
1c420 74 61 62 6c 65 20 61 6e 64 20 74 68 65 20 70 72 table and the pr
1c430 65 76 69 6f 75 73 20 74 61 62 6c 65 2e 0a 2a 2a evious table..**
1c440 0a 2a 2a 20 49 6e 20 74 68 65 20 63 6f 6c 55 73 .** In the colUs
1c450 65 64 20 66 69 65 6c 64 2c 20 74 68 65 20 68 69 ed field, the hi
1c460 67 68 2d 6f 72 64 65 72 20 62 69 74 20 28 62 69 gh-order bit (bi
1c470 74 20 36 33 29 20 69 73 20 73 65 74 20 69 66 20 t 63) is set if
1c480 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 63 6f 6e the table.** con
1c490 74 61 69 6e 73 20 6d 6f 72 65 20 74 68 61 6e 20 tains more than
1c4a0 36 33 20 63 6f 6c 75 6d 6e 73 20 61 6e 64 20 74 63 columns and t
1c4b0 68 65 20 36 34 2d 74 68 20 6f 72 20 6c 61 74 65 he 64-th or late
1c4c0 72 20 63 6f 6c 75 6d 6e 20 69 73 20 75 73 65 64 r column is used
1c4d0 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 72 63 4c ..*/.struct SrcL
1c4e0 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 53 72 63 ist {. int nSrc
1c4f0 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 ; /* Numb
1c500 65 72 20 6f 66 20 74 61 62 6c 65 73 20 6f 72 20 er of tables or
1c510 73 75 62 71 75 65 72 69 65 73 20 69 6e 20 74 68 subqueries in th
1c520 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f e FROM clause */
1c530 0a 20 20 75 33 32 20 6e 41 6c 6c 6f 63 3b 20 20 . u32 nAlloc;
1c540 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1c550 20 65 6e 74 72 69 65 73 20 61 6c 6c 6f 63 61 74 entries allocat
1c560 65 64 20 69 6e 20 61 5b 5d 20 62 65 6c 6f 77 20 ed in a[] below
1c570 2a 2f 0a 20 20 73 74 72 75 63 74 20 53 72 63 4c */. struct SrcL
1c580 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 20 20 53 ist_item {. S
1c590 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 chema *pSchema;
1c5a0 20 2f 2a 20 53 63 68 65 6d 61 20 74 6f 20 77 68 /* Schema to wh
1c5b0 69 63 68 20 74 68 69 73 20 69 74 65 6d 20 69 73 ich this item is
1c5c0 20 66 69 78 65 64 20 2a 2f 0a 20 20 20 20 63 68 fixed */. ch
1c5d0 61 72 20 2a 7a 44 61 74 61 62 61 73 65 3b 20 20 ar *zDatabase;
1c5e0 2f 2a 20 4e 61 6d 65 20 6f 66 20 64 61 74 61 62 /* Name of datab
1c5f0 61 73 65 20 68 6f 6c 64 69 6e 67 20 74 68 69 73 ase holding this
1c600 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 table */. ch
1c610 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
1c620 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 /* Name of the t
1c630 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 able */. char
1c640 20 2a 7a 41 6c 69 61 73 3b 20 20 20 20 20 2f 2a *zAlias; /*
1c650 20 54 68 65 20 22 42 22 20 70 61 72 74 20 6f 66 The "B" part of
1c660 20 61 20 22 41 20 41 53 20 42 22 20 70 68 72 61 a "A AS B" phra
1c670 73 65 2e 20 20 7a 4e 61 6d 65 20 69 73 20 74 68 se. zName is th
1c680 65 20 22 41 22 20 2a 2f 0a 20 20 20 20 54 61 62 e "A" */. Tab
1c690 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 2f le *pTab; /
1c6a0 2a 20 41 6e 20 53 51 4c 20 74 61 62 6c 65 20 63 * An SQL table c
1c6b0 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 orresponding to
1c6c0 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 20 53 65 6c zName */. Sel
1c6d0 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 2f ect *pSelect; /
1c6e0 2a 20 41 20 53 45 4c 45 43 54 20 73 74 61 74 65 * A SELECT state
1c6f0 6d 65 6e 74 20 75 73 65 64 20 69 6e 20 70 6c 61 ment used in pla
1c700 63 65 20 6f 66 20 61 20 74 61 62 6c 65 20 6e 61 ce of a table na
1c710 6d 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 61 64 me */. int ad
1c720 64 72 46 69 6c 6c 53 75 62 3b 20 20 2f 2a 20 41 drFillSub; /* A
1c730 64 64 72 65 73 73 20 6f 66 20 73 75 62 72 6f 75 ddress of subrou
1c740 74 69 6e 65 20 74 6f 20 6d 61 6e 69 66 65 73 74 tine to manifest
1c750 20 61 20 73 75 62 71 75 65 72 79 20 2a 2f 0a 20 a subquery */.
1c760 20 20 20 69 6e 74 20 72 65 67 52 65 74 75 72 6e int regReturn
1c770 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 ; /* Register
1c780 20 68 6f 6c 64 69 6e 67 20 72 65 74 75 72 6e 20 holding return
1c790 61 64 64 72 65 73 73 20 6f 66 20 61 64 64 72 46 address of addrF
1c7a0 69 6c 6c 53 75 62 20 2a 2f 0a 20 20 20 20 69 6e illSub */. in
1c7b0 74 20 72 65 67 52 65 73 75 6c 74 3b 20 20 20 20 t regResult;
1c7c0 2f 2a 20 52 65 67 69 73 74 65 72 73 20 68 6f 6c /* Registers hol
1c7d0 64 69 6e 67 20 72 65 73 75 6c 74 73 20 6f 66 20 ding results of
1c7e0 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a a co-routine */.
1c7f0 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 20 20 struct {.
1c800 20 20 20 75 38 20 6a 6f 69 6e 74 79 70 65 3b 20 u8 jointype;
1c810 20 20 20 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 /* Type of
1c820 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 69 join between thi
1c830 73 20 74 61 62 6c 65 20 61 6e 64 20 74 68 65 20 s table and the
1c840 70 72 65 76 69 6f 75 73 20 2a 2f 0a 20 20 20 20 previous */.
1c850 20 20 75 6e 73 69 67 6e 65 64 20 6e 6f 74 49 6e unsigned notIn
1c860 64 65 78 65 64 20 3a 31 3b 20 20 20 20 2f 2a 20 dexed :1; /*
1c870 54 72 75 65 20 69 66 20 74 68 65 72 65 20 69 73 True if there is
1c880 20 61 20 4e 4f 54 20 49 4e 44 45 58 45 44 20 63 a NOT INDEXED c
1c890 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 75 lause */. u
1c8a0 6e 73 69 67 6e 65 64 20 69 73 49 6e 64 65 78 65 nsigned isIndexe
1c8b0 64 42 79 20 3a 31 3b 20 20 20 2f 2a 20 54 72 75 dBy :1; /* Tru
1c8c0 65 20 69 66 20 74 68 65 72 65 20 69 73 20 61 6e e if there is an
1c8d0 20 49 4e 44 45 58 45 44 20 42 59 20 63 6c 61 75 INDEXED BY clau
1c8e0 73 65 20 2a 2f 0a 20 20 20 20 20 20 75 6e 73 69 se */. unsi
1c8f0 67 6e 65 64 20 69 73 54 61 62 46 75 6e 63 20 3a gned isTabFunc :
1c900 31 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 1; /* True i
1c910 66 20 74 61 62 6c 65 2d 76 61 6c 75 65 64 2d 66 f table-valued-f
1c920 75 6e 63 74 69 6f 6e 20 73 79 6e 74 61 78 20 2a unction syntax *
1c930 2f 0a 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 /. unsigned
1c940 20 69 73 43 6f 72 72 65 6c 61 74 65 64 20 3a 31 isCorrelated :1
1c950 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 75 ; /* True if su
1c960 62 2d 71 75 65 72 79 20 69 73 20 63 6f 72 72 65 b-query is corre
1c970 6c 61 74 65 64 20 2a 2f 0a 20 20 20 20 20 20 75 lated */. u
1c980 6e 73 69 67 6e 65 64 20 76 69 61 43 6f 72 6f 75 nsigned viaCorou
1c990 74 69 6e 65 20 3a 31 3b 20 20 2f 2a 20 49 6d 70 tine :1; /* Imp
1c9a0 6c 65 6d 65 6e 74 65 64 20 61 73 20 61 20 63 6f lemented as a co
1c9b0 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 20 20 -routine */.
1c9c0 20 20 75 6e 73 69 67 6e 65 64 20 69 73 52 65 63 unsigned isRec
1c9d0 75 72 73 69 76 65 20 3a 31 3b 20 20 20 2f 2a 20 ursive :1; /*
1c9e0 54 72 75 65 20 66 6f 72 20 72 65 63 75 72 73 69 True for recursi
1c9f0 76 65 20 72 65 66 65 72 65 6e 63 65 20 69 6e 20 ve reference in
1ca00 57 49 54 48 20 2a 2f 0a 20 20 20 20 7d 20 66 67 WITH */. } fg
1ca10 3b 0a 20 20 20 20 69 6e 74 20 69 43 75 72 73 6f ;. int iCurso
1ca20 72 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 56 r; /* The V
1ca30 44 42 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 DBE cursor numbe
1ca40 72 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 r used to access
1ca50 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 this table */.
1ca60 20 20 20 45 78 70 72 20 2a 70 4f 6e 3b 20 20 20 Expr *pOn;
1ca70 20 20 20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 63 /* The ON c
1ca80 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e 20 lause of a join
1ca90 2a 2f 0a 20 20 20 20 49 64 4c 69 73 74 20 2a 70 */. IdList *p
1caa0 55 73 69 6e 67 3b 20 20 20 2f 2a 20 54 68 65 20 Using; /* The
1cab0 55 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 USING clause of
1cac0 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 69 a join */. Bi
1cad0 74 6d 61 73 6b 20 63 6f 6c 55 73 65 64 3b 20 20 tmask colUsed;
1cae0 2f 2a 20 42 69 74 20 4e 20 28 31 3c 3c 4e 29 20 /* Bit N (1<<N)
1caf0 73 65 74 20 69 66 20 63 6f 6c 75 6d 6e 20 4e 20 set if column N
1cb00 6f 66 20 70 54 61 62 20 69 73 20 75 73 65 64 20 of pTab is used
1cb10 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b 0a 20 */. union {.
1cb20 20 20 20 20 20 63 68 61 72 20 2a 7a 49 6e 64 65 char *zInde
1cb30 78 65 64 42 79 3b 20 20 20 20 2f 2a 20 49 64 65 xedBy; /* Ide
1cb40 6e 74 69 66 69 65 72 20 66 72 6f 6d 20 22 49 4e ntifier from "IN
1cb50 44 45 58 45 44 20 42 59 20 3c 7a 49 6e 64 65 78 DEXED BY <zIndex
1cb60 3e 22 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 >" clause */.
1cb70 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 46 75 ExprList *pFu
1cb80 6e 63 41 72 67 3b 20 20 2f 2a 20 41 72 67 75 6d ncArg; /* Argum
1cb90 65 6e 74 73 20 74 6f 20 74 61 62 6c 65 2d 76 61 ents to table-va
1cba0 6c 75 65 64 2d 66 75 6e 63 74 69 6f 6e 20 2a 2f lued-function */
1cbb0 0a 20 20 20 20 7d 20 75 31 3b 0a 20 20 20 20 49 . } u1;. I
1cbc0 6e 64 65 78 20 2a 70 49 42 49 6e 64 65 78 3b 20 ndex *pIBIndex;
1cbd0 20 2f 2a 20 49 6e 64 65 78 20 73 74 72 75 63 74 /* Index struct
1cbe0 75 72 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e ure correspondin
1cbf0 67 20 74 6f 20 75 31 2e 7a 49 6e 64 65 78 65 64 g to u1.zIndexed
1cc00 42 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 By */. } a[1];
1cc10 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
1cc20 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 61 63 ne entry for eac
1cc30 68 20 69 64 65 6e 74 69 66 69 65 72 20 6f 6e 20 h identifier on
1cc40 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a the list */.};..
1cc50 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 65 64 20 /*.** Permitted
1cc60 76 61 6c 75 65 73 20 6f 66 20 74 68 65 20 53 72 values of the Sr
1cc70 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 cList.a.jointype
1cc80 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e field.*/.#defin
1cc90 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 20 20 30 e JT_INNER 0
1cca0 78 30 30 30 31 20 20 20 20 2f 2a 20 41 6e 79 20 x0001 /* Any
1ccb0 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 20 6f 72 kind of inner or
1ccc0 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 cross join */.#
1ccd0 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f 53 53 20 define JT_CROSS
1cce0 20 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a 0x0002 /*
1ccf0 20 45 78 70 6c 69 63 69 74 20 75 73 65 20 6f 66 Explicit use of
1cd00 20 74 68 65 20 43 52 4f 53 53 20 6b 65 79 77 6f the CROSS keywo
1cd10 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 rd */.#define JT
1cd20 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 30 30 30 _NATURAL 0x000
1cd30 34 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 4 /* True for
1cd40 20 61 20 22 6e 61 74 75 72 61 6c 22 20 6a 6f 69 a "natural" joi
1cd50 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f n */.#define JT_
1cd60 4c 45 46 54 20 20 20 20 20 20 30 78 30 30 30 38 LEFT 0x0008
1cd70 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 75 74 65 /* Left oute
1cd80 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e r join */.#defin
1cd90 65 20 4a 54 5f 52 49 47 48 54 20 20 20 20 20 30 e JT_RIGHT 0
1cda0 78 30 30 31 30 20 20 20 20 2f 2a 20 52 69 67 68 x0010 /* Righ
1cdb0 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a t outer join */.
1cdc0 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 54 45 52 #define JT_OUTER
1cdd0 20 20 20 20 20 30 78 30 30 32 30 20 20 20 20 2f 0x0020 /
1cde0 2a 20 54 68 65 20 22 4f 55 54 45 52 22 20 6b 65 * The "OUTER" ke
1cdf0 79 77 6f 72 64 20 69 73 20 70 72 65 73 65 6e 74 yword is present
1ce00 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 45 */.#define JT_E
1ce10 52 52 4f 52 20 20 20 20 20 30 78 30 30 34 30 20 RROR 0x0040
1ce20 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 /* unknown or
1ce30 20 75 6e 73 75 70 70 6f 72 74 65 64 20 6a 6f 69 unsupported joi
1ce40 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a n type */.../*.*
1ce50 2a 20 46 6c 61 67 73 20 61 70 70 72 6f 70 72 69 * Flags appropri
1ce60 61 74 65 20 66 6f 72 20 74 68 65 20 77 63 74 72 ate for the wctr
1ce70 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 74 65 72 lFlags parameter
1ce80 20 6f 66 20 73 71 6c 69 74 65 33 57 68 65 72 65 of sqlite3Where
1ce90 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 Begin().** and t
1cea0 68 65 20 57 68 65 72 65 49 6e 66 6f 2e 77 63 74 he WhereInfo.wct
1ceb0 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 72 2e 0a rlFlags member..
1cec0 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e 73 **.** Value cons
1ced0 74 72 61 69 6e 74 73 20 28 65 6e 66 6f 72 63 65 traints (enforce
1cee0 64 20 76 69 61 20 61 73 73 65 72 74 28 29 29 3a d via assert()):
1cef0 0a 2a 2a 20 20 20 20 20 57 48 45 52 45 5f 55 53 .** WHERE_US
1cf00 45 5f 4c 49 4d 49 54 20 20 3d 3d 20 53 46 5f 46 E_LIMIT == SF_F
1cf10 69 78 65 64 4c 69 6d 69 74 0a 2a 2f 0a 23 64 65 ixedLimit.*/.#de
1cf20 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 45 52 fine WHERE_ORDER
1cf30 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 78 30 30 BY_NORMAL 0x00
1cf40 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a 2f 0a 23 00 /* No-op */.#
1cf50 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 define WHERE_ORD
1cf60 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 20 30 78 ERBY_MIN 0x
1cf70 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 20 42 59 0001 /* ORDER BY
1cf80 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 20 processing for
1cf90 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f 0a 23 64 min() func */.#d
1cfa0 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 45 efine WHERE_ORDE
1cfb0 52 42 59 5f 4d 41 58 20 20 20 20 20 20 30 78 30 RBY_MAX 0x0
1cfc0 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 42 59 20 002 /* ORDER BY
1cfd0 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 20 6d processing for m
1cfe0 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a 23 64 65 ax() func */.#de
1cff0 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 41 fine WHERE_ONEPA
1d000 53 53 5f 44 45 53 49 52 45 44 20 20 30 78 30 30 SS_DESIRED 0x00
1d010 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f 20 64 6f 04 /* Want to do
1d020 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 41 54 45 one-pass UPDATE
1d030 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 65 66 69 /DELETE */.#defi
1d040 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 41 53 53 ne WHERE_ONEPASS
1d050 5f 4d 55 4c 54 49 52 4f 57 20 30 78 30 30 30 38 _MULTIROW 0x0008
1d060 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 73 20 6f /* ONEPASS is o
1d070 6b 20 77 69 74 68 20 6d 75 6c 74 69 70 6c 65 20 k with multiple
1d080 72 6f 77 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 rows */.#define
1d090 57 48 45 52 45 5f 44 55 50 4c 49 43 41 54 45 53 WHERE_DUPLICATES
1d0a0 5f 4f 4b 20 20 20 20 30 78 30 30 31 30 20 2f 2a _OK 0x0010 /*
1d0b0 20 4f 6b 20 74 6f 20 72 65 74 75 72 6e 20 61 20 Ok to return a
1d0c0 72 6f 77 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e row more than on
1d0d0 63 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 ce */.#define WH
1d0e0 45 52 45 5f 4f 52 5f 53 55 42 43 4c 41 55 53 45 ERE_OR_SUBCLAUSE
1d0f0 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 50 0x0020 /* P
1d100 72 6f 63 65 73 73 69 6e 67 20 61 20 73 75 62 2d rocessing a sub-
1d110 57 48 45 52 45 20 61 73 20 70 61 72 74 20 6f 66 WHERE as part of
1d120 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1d130 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d140 20 20 20 20 20 20 20 2a 2a 20 74 68 65 20 4f 52 ** the OR
1d150 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 20 2a optimization *
1d160 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
1d170 47 52 4f 55 50 42 59 20 20 20 20 20 20 20 20 20 GROUPBY
1d180 20 30 78 30 30 34 30 20 2f 2a 20 70 4f 72 64 65 0x0040 /* pOrde
1d190 72 42 79 20 69 73 20 72 65 61 6c 6c 79 20 61 20 rBy is really a
1d1a0 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 65 66 GROUP BY */.#def
1d1b0 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e ine WHERE_DISTIN
1d1c0 43 54 42 59 20 20 20 20 20 20 20 30 78 30 30 38 CTBY 0x008
1d1d0 30 20 2f 2a 20 70 4f 72 64 65 72 62 79 20 69 73 0 /* pOrderby is
1d1e0 20 72 65 61 6c 6c 79 20 61 20 44 49 53 54 49 4e really a DISTIN
1d1f0 43 54 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 CT clause */.#de
1d200 66 69 6e 65 20 57 48 45 52 45 5f 57 41 4e 54 5f fine WHERE_WANT_
1d210 44 49 53 54 49 4e 43 54 20 20 20 20 30 78 30 31 DISTINCT 0x01
1d220 30 30 20 2f 2a 20 41 6c 6c 20 6f 75 74 70 75 74 00 /* All output
1d230 20 6e 65 65 64 73 20 74 6f 20 62 65 20 64 69 73 needs to be dis
1d240 74 69 6e 63 74 20 2a 2f 0a 23 64 65 66 69 6e 65 tinct */.#define
1d250 20 57 48 45 52 45 5f 53 4f 52 54 42 59 47 52 4f WHERE_SORTBYGRO
1d260 55 50 20 20 20 20 20 20 30 78 30 32 30 30 20 2f UP 0x0200 /
1d270 2a 20 53 75 70 70 6f 72 74 20 73 71 6c 69 74 65 * Support sqlite
1d280 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 28 29 3WhereIsSorted()
1d290 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
1d2a0 45 5f 53 45 45 4b 5f 54 41 42 4c 45 20 20 20 20 E_SEEK_TABLE
1d2b0 20 20 20 30 78 30 34 30 30 20 2f 2a 20 44 6f 20 0x0400 /* Do
1d2c0 6e 6f 74 20 64 65 66 65 72 20 73 65 65 6b 73 20 not defer seeks
1d2d0 6f 6e 20 6d 61 69 6e 20 74 61 62 6c 65 20 2a 2f on main table */
1d2e0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
1d2f0 52 44 45 52 42 59 5f 4c 49 4d 49 54 20 20 20 20 RDERBY_LIMIT
1d300 30 78 30 38 30 30 20 2f 2a 20 4f 52 44 45 52 42 0x0800 /* ORDERB
1d310 59 2b 4c 49 4d 49 54 20 6f 6e 20 74 68 65 20 69 Y+LIMIT on the i
1d320 6e 6e 65 72 20 6c 6f 6f 70 20 2a 2f 0a 23 64 65 nner loop */.#de
1d330 66 69 6e 65 20 57 48 45 52 45 5f 53 45 45 4b 5f fine WHERE_SEEK_
1d340 55 4e 49 51 5f 54 41 42 4c 45 20 20 30 78 31 30 UNIQ_TABLE 0x10
1d350 30 30 20 2f 2a 20 44 6f 20 6e 6f 74 20 64 65 66 00 /* Do not def
1d360 65 72 20 73 65 65 6b 73 20 69 66 20 75 6e 69 71 er seeks if uniq
1d370 75 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 ue */.
1d380 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1d390 20 20 20 20 20 30 78 32 30 30 30 20 20 20 20 6e 0x2000 n
1d3a0 6f 74 20 63 75 72 72 65 6e 74 6c 79 20 75 73 65 ot currently use
1d3b0 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 d */.#define WHE
1d3c0 52 45 5f 55 53 45 5f 4c 49 4d 49 54 20 20 20 20 RE_USE_LIMIT
1d3d0 20 20 20 20 30 78 34 30 30 30 20 2f 2a 20 55 73 0x4000 /* Us
1d3e0 65 20 74 68 65 20 4c 49 4d 49 54 20 69 6e 20 63 e the LIMIT in c
1d3f0 6f 73 74 20 65 73 74 69 6d 61 74 65 73 20 2a 2f ost estimates */
1d400 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1d410 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 20 20 /*
1d420 30 78 38 30 30 30 20 20 20 20 6e 6f 74 20 63 75 0x8000 not cu
1d430 72 72 65 6e 74 6c 79 20 75 73 65 64 20 2a 2f 0a rrently used */.
1d440 0a 2f 2a 20 41 6c 6c 6f 77 65 64 20 72 65 74 75 ./* Allowed retu
1d450 72 6e 20 76 61 6c 75 65 73 20 66 72 6f 6d 20 73 rn values from s
1d460 71 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 qlite3WhereIsDis
1d470 74 69 6e 63 74 28 29 0a 2a 2f 0a 23 64 65 66 69 tinct().*/.#defi
1d480 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 ne WHERE_DISTINC
1d490 54 5f 4e 4f 4f 50 20 20 20 20 20 20 30 20 20 2f T_NOOP 0 /
1d4a0 2a 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f * DISTINCT keywo
1d4b0 72 64 20 6e 6f 74 20 75 73 65 64 20 2a 2f 0a 23 rd not used */.#
1d4c0 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 define WHERE_DIS
1d4d0 54 49 4e 43 54 5f 55 4e 49 51 55 45 20 20 20 20 TINCT_UNIQUE
1d4e0 31 20 20 2f 2a 20 4e 6f 20 64 75 70 6c 69 63 61 1 /* No duplica
1d4f0 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 tes */.#define W
1d500 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 4f 52 HERE_DISTINCT_OR
1d510 44 45 52 45 44 20 20 20 32 20 20 2f 2a 20 41 6c DERED 2 /* Al
1d520 6c 20 64 75 70 6c 69 63 61 74 65 73 20 61 72 65 l duplicates are
1d530 20 61 64 6a 61 63 65 6e 74 20 2a 2f 0a 23 64 65 adjacent */.#de
1d540 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 fine WHERE_DISTI
1d550 4e 43 54 5f 55 4e 4f 52 44 45 52 45 44 20 33 20 NCT_UNORDERED 3
1d560 20 2f 2a 20 44 75 70 6c 69 63 61 74 65 73 20 61 /* Duplicates a
1d570 72 65 20 73 63 61 74 74 65 72 65 64 20 2a 2f 0a re scattered */.
1d580 0a 2f 2a 0a 2a 2a 20 41 20 4e 61 6d 65 43 6f 6e ./*.** A NameCon
1d590 74 65 78 74 20 64 65 66 69 6e 65 73 20 61 20 63 text defines a c
1d5a0 6f 6e 74 65 78 74 20 69 6e 20 77 68 69 63 68 20 ontext in which
1d5b0 74 6f 20 72 65 73 6f 6c 76 65 20 74 61 62 6c 65 to resolve table
1d5c0 20 61 6e 64 20 63 6f 6c 75 6d 6e 0a 2a 2a 20 6e and column.** n
1d5d0 61 6d 65 73 2e 20 20 54 68 65 20 63 6f 6e 74 65 ames. The conte
1d5e0 78 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 xt consists of a
1d5f0 20 6c 69 73 74 20 6f 66 20 74 61 62 6c 65 73 20 list of tables
1d600 28 74 68 65 20 70 53 72 63 4c 69 73 74 29 20 66 (the pSrcList) f
1d610 69 65 6c 64 20 61 6e 64 0a 2a 2a 20 61 20 6c 69 ield and.** a li
1d620 73 74 20 6f 66 20 6e 61 6d 65 64 20 65 78 70 72 st of named expr
1d630 65 73 73 69 6f 6e 20 28 70 45 4c 69 73 74 29 2e ession (pEList).
1d640 20 20 54 68 65 20 6e 61 6d 65 64 20 65 78 70 72 The named expr
1d650 65 73 73 69 6f 6e 20 6c 69 73 74 20 6d 61 79 0a ession list may.
1d660 2a 2a 20 62 65 20 4e 55 4c 4c 2e 20 20 54 68 65 ** be NULL. The
1d670 20 70 53 72 63 20 63 6f 72 72 65 73 70 6f 6e 64 pSrc correspond
1d680 73 20 74 6f 20 74 68 65 20 46 52 4f 4d 20 63 6c s to the FROM cl
1d690 61 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 54 ause of a SELECT
1d6a0 20 6f 72 0a 2a 2a 20 74 6f 20 74 68 65 20 74 61 or.** to the ta
1d6b0 62 6c 65 20 62 65 69 6e 67 20 6f 70 65 72 61 74 ble being operat
1d6c0 65 64 20 6f 6e 20 62 79 20 49 4e 53 45 52 54 2c ed on by INSERT,
1d6d0 20 55 50 44 41 54 45 2c 20 6f 72 20 44 45 4c 45 UPDATE, or DELE
1d6e0 54 45 2e 20 20 54 68 65 0a 2a 2a 20 70 45 4c 69 TE. The.** pELi
1d6f0 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 st corresponds t
1d700 6f 20 74 68 65 20 72 65 73 75 6c 74 20 73 65 74 o the result set
1d710 20 6f 66 20 61 20 53 45 4c 45 43 54 20 61 6e 64 of a SELECT and
1d720 20 69 73 20 4e 55 4c 4c 20 66 6f 72 0a 2a 2a 20 is NULL for.**
1d730 6f 74 68 65 72 20 73 74 61 74 65 6d 65 6e 74 73 other statements
1d740 2e 0a 2a 2a 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 ..**.** NameCont
1d750 65 78 74 73 20 63 61 6e 20 62 65 20 6e 65 73 74 exts can be nest
1d760 65 64 2e 20 20 57 68 65 6e 20 72 65 73 6f 6c 76 ed. When resolv
1d770 69 6e 67 20 6e 61 6d 65 73 2c 20 74 68 65 20 69 ing names, the i
1d780 6e 6e 65 72 2d 6d 6f 73 74 0a 2a 2a 20 63 6f 6e nner-most.** con
1d790 74 65 78 74 20 69 73 20 73 65 61 72 63 68 65 64 text is searched
1d7a0 20 66 69 72 73 74 2e 20 20 49 66 20 6e 6f 20 6d first. If no m
1d7b0 61 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 atch is found, t
1d7c0 68 65 20 6e 65 78 74 20 6f 75 74 65 72 0a 2a 2a he next outer.**
1d7d0 20 63 6f 6e 74 65 78 74 20 69 73 20 63 68 65 63 context is chec
1d7e0 6b 65 64 2e 20 20 49 66 20 74 68 65 72 65 20 69 ked. If there i
1d7f0 73 20 73 74 69 6c 6c 20 6e 6f 20 6d 61 74 63 68 s still no match
1d800 2c 20 74 68 65 20 6e 65 78 74 20 63 6f 6e 74 65 , the next conte
1d810 78 74 0a 2a 2a 20 69 73 20 63 68 65 63 6b 65 64 xt.** is checked
1d820 2e 20 20 54 68 69 73 20 70 72 6f 63 65 73 73 20 . This process
1d830 63 6f 6e 74 69 6e 75 65 73 20 75 6e 74 69 6c 20 continues until
1d840 65 69 74 68 65 72 20 61 20 6d 61 74 63 68 20 69 either a match i
1d850 73 20 66 6f 75 6e 64 0a 2a 2a 20 6f 72 20 61 6c s found.** or al
1d860 6c 20 63 6f 6e 74 65 78 74 73 20 61 72 65 20 63 l contexts are c
1d870 68 65 63 6b 2e 20 20 57 68 65 6e 20 61 20 6d 61 heck. When a ma
1d880 74 63 68 20 69 73 20 66 6f 75 6e 64 2c 20 74 68 tch is found, th
1d890 65 20 6e 52 65 66 20 6d 65 6d 62 65 72 20 6f 66 e nRef member of
1d8a0 0a 2a 2a 20 74 68 65 20 63 6f 6e 74 65 78 74 20 .** the context
1d8b0 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 6d containing the m
1d8c0 61 74 63 68 20 69 73 20 69 6e 63 72 65 6d 65 6e atch is incremen
1d8d0 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 45 61 63 68 20 ted..**.** Each
1d8e0 73 75 62 71 75 65 72 79 20 67 65 74 73 20 61 20 subquery gets a
1d8f0 6e 65 77 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2e new NameContext.
1d900 20 20 54 68 65 20 70 4e 65 78 74 20 66 69 65 6c The pNext fiel
1d910 64 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 65 0a d points to the.
1d920 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 69 ** NameContext i
1d930 6e 20 74 68 65 20 70 61 72 65 6e 74 20 71 75 65 n the parent que
1d940 72 79 2e 20 20 54 68 75 73 20 74 68 65 20 70 72 ry. Thus the pr
1d950 6f 63 65 73 73 20 6f 66 20 73 63 61 6e 6e 69 6e ocess of scannin
1d960 67 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e g the.** NameCon
1d970 74 65 78 74 20 6c 69 73 74 20 63 6f 72 72 65 73 text list corres
1d980 70 6f 6e 64 73 20 74 6f 20 73 65 61 72 63 68 69 ponds to searchi
1d990 6e 67 20 74 68 72 6f 75 67 68 20 73 75 63 63 65 ng through succe
1d9a0 73 73 69 76 65 6c 79 20 6f 75 74 65 72 0a 2a 2a ssively outer.**
1d9b0 20 73 75 62 71 75 65 72 69 65 73 20 6c 6f 6f 6b subqueries look
1d9c0 69 6e 67 20 66 6f 72 20 61 20 6d 61 74 63 68 2e ing for a match.
1d9d0 0a 2a 2f 0a 73 74 72 75 63 74 20 4e 61 6d 65 43 .*/.struct NameC
1d9e0 6f 6e 74 65 78 74 20 7b 0a 20 20 50 61 72 73 65 ontext {. Parse
1d9f0 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 *pParse;
1da00 2f 2a 20 54 68 65 20 70 61 72 73 65 72 20 2a 2f /* The parser */
1da10 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 . SrcList *pSrc
1da20 4c 69 73 74 3b 20 20 20 2f 2a 20 4f 6e 65 20 6f List; /* One o
1da30 72 20 6d 6f 72 65 20 74 61 62 6c 65 73 20 75 73 r more tables us
1da40 65 64 20 74 6f 20 72 65 73 6f 6c 76 65 20 6e 61 ed to resolve na
1da50 6d 65 73 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b mes */. union {
1da60 0a 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 . ExprList *p
1da70 45 4c 69 73 74 3b 20 20 20 20 2f 2a 20 4f 70 74 EList; /* Opt
1da80 69 6f 6e 61 6c 20 6c 69 73 74 20 6f 66 20 72 65 ional list of re
1da90 73 75 6c 74 2d 73 65 74 20 63 6f 6c 75 6d 6e 73 sult-set columns
1daa0 20 2a 2f 0a 20 20 20 20 41 67 67 49 6e 66 6f 20 */. AggInfo
1dab0 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 2f 2a 20 *pAggInfo; /*
1dac0 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 Information abou
1dad0 74 20 61 67 67 72 65 67 61 74 65 73 20 61 74 20 t aggregates at
1dae0 74 68 69 73 20 6c 65 76 65 6c 20 2a 2f 0a 20 20 this level */.
1daf0 20 20 55 70 73 65 72 74 20 2a 70 55 70 73 65 72 Upsert *pUpser
1db00 74 3b 20 20 20 20 20 2f 2a 20 4f 4e 20 43 4f 4e t; /* ON CON
1db10 46 4c 49 43 54 20 63 6c 61 75 73 65 20 69 6e 66 FLICT clause inf
1db20 6f 72 6d 61 74 69 6f 6e 20 66 72 6f 6d 20 61 6e ormation from an
1db30 20 75 70 73 65 72 74 20 2a 2f 0a 20 20 7d 20 75 upsert */. } u
1db40 4e 43 3b 0a 20 20 4e 61 6d 65 43 6f 6e 74 65 78 NC;. NameContex
1db50 74 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 t *pNext; /* Ne
1db60 78 74 20 6f 75 74 65 72 20 6e 61 6d 65 20 63 6f xt outer name co
1db70 6e 74 65 78 74 2e 20 20 4e 55 4c 4c 20 66 6f 72 ntext. NULL for
1db80 20 6f 75 74 65 72 6d 6f 73 74 20 2a 2f 0a 20 20 outermost */.
1db90 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 20 20 int nRef;
1dba0 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
1dbb0 66 20 6e 61 6d 65 73 20 72 65 73 6f 6c 76 65 64 f names resolved
1dbc0 20 62 79 20 74 68 69 73 20 63 6f 6e 74 65 78 74 by this context
1dbd0 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 */. int nErr;
1dbe0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1dbf0 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 20 65 mber of errors e
1dc00 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 6c 65 ncountered while
1dc10 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 resolving names
1dc20 20 2a 2f 0a 20 20 69 6e 74 20 6e 63 46 6c 61 67 */. int ncFlag
1dc30 73 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 5a 65 s; /* Ze
1dc40 72 6f 20 6f 72 20 6d 6f 72 65 20 4e 43 5f 2a 20 ro or more NC_*
1dc50 66 6c 61 67 73 20 64 65 66 69 6e 65 64 20 62 65 flags defined be
1dc60 6c 6f 77 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 low */. Select
1dc70 2a 70 57 69 6e 53 65 6c 65 63 74 3b 20 20 2f 2a *pWinSelect; /*
1dc80 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e SELECT statemen
1dc90 74 20 66 6f 72 20 61 6e 79 20 77 69 6e 64 6f 77 t for any window
1dca0 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a 7d 3b functions */.};
1dcb0 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 ../*.** Allowed
1dcc0 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 4e values for the N
1dcd0 61 6d 65 43 6f 6e 74 65 78 74 2c 20 6e 63 46 6c ameContext, ncFl
1dce0 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a ags field..**.**
1dcf0 20 56 61 6c 75 65 20 63 6f 6e 73 74 72 61 69 6e Value constrain
1dd00 74 73 20 28 61 6c 6c 20 63 68 65 63 6b 65 64 20 ts (all checked
1dd10 76 69 61 20 61 73 73 65 72 74 28 29 29 3a 0a 2a via assert()):.*
1dd20 2a 20 20 20 20 4e 43 5f 48 61 73 41 67 67 20 20 * NC_HasAgg
1dd30 20 20 3d 3d 20 53 46 5f 48 61 73 41 67 67 20 20 == SF_HasAgg
1dd40 20 20 3d 3d 20 45 50 5f 41 67 67 0a 2a 2a 20 20 == EP_Agg.**
1dd50 20 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 3d NC_MinMaxAgg =
1dd60 3d 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 3d = SF_MinMaxAgg =
1dd70 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 = SQLITE_FUNC_MI
1dd80 4e 4d 41 58 0a 2a 2a 20 20 20 20 4e 43 5f 48 61 NMAX.** NC_Ha
1dd90 73 57 69 6e 20 20 20 20 3d 3d 20 45 50 5f 57 69 sWin == EP_Wi
1dda0 6e 0a 2a 2a 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 n.**.*/.#define
1ddb0 4e 43 5f 41 6c 6c 6f 77 41 67 67 20 20 30 78 30 NC_AllowAgg 0x0
1ddc0 30 30 30 31 20 20 2f 2a 20 41 67 67 72 65 67 61 0001 /* Aggrega
1ddd0 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 te functions are
1dde0 20 61 6c 6c 6f 77 65 64 20 68 65 72 65 20 2a 2f allowed here */
1ddf0 0a 23 64 65 66 69 6e 65 20 4e 43 5f 50 61 72 74 .#define NC_Part
1de00 49 64 78 20 20 20 30 78 30 30 30 30 32 20 20 2f Idx 0x00002 /
1de10 2a 20 54 72 75 65 20 69 66 20 72 65 73 6f 6c 76 * True if resolv
1de20 69 6e 67 20 61 20 70 61 72 74 69 61 6c 20 69 6e ing a partial in
1de30 64 65 78 20 57 48 45 52 45 20 2a 2f 0a 23 64 65 dex WHERE */.#de
1de40 66 69 6e 65 20 4e 43 5f 49 73 43 68 65 63 6b 20 fine NC_IsCheck
1de50 20 20 30 78 30 30 30 30 34 20 20 2f 2a 20 54 72 0x00004 /* Tr
1de60 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 ue if resolving
1de70 61 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 61 69 a CHECK constrai
1de80 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 nt */.#define NC
1de90 5f 49 6e 41 67 67 46 75 6e 63 20 30 78 30 30 30 _InAggFunc 0x000
1dea0 30 38 20 20 2f 2a 20 54 72 75 65 20 69 66 20 61 08 /* True if a
1deb0 6e 61 6c 79 7a 69 6e 67 20 61 72 67 75 6d 65 6e nalyzing argumen
1dec0 74 73 20 74 6f 20 61 6e 20 61 67 67 20 66 75 6e ts to an agg fun
1ded0 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f c */.#define NC_
1dee0 48 61 73 41 67 67 20 20 20 20 30 78 30 30 30 31 HasAgg 0x0001
1def0 30 20 20 2f 2a 20 4f 6e 65 20 6f 72 20 6d 6f 72 0 /* One or mor
1df00 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 e aggregate func
1df10 74 69 6f 6e 73 20 73 65 65 6e 20 2a 2f 0a 23 64 tions seen */.#d
1df20 65 66 69 6e 65 20 4e 43 5f 49 64 78 45 78 70 72 efine NC_IdxExpr
1df30 20 20 20 30 78 30 30 30 32 30 20 20 2f 2a 20 54 0x00020 /* T
1df40 72 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 rue if resolving
1df50 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 43 52 45 41 columns of CREA
1df60 54 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 65 66 TE INDEX */.#def
1df70 69 6e 65 20 4e 43 5f 56 61 72 53 65 6c 65 63 74 ine NC_VarSelect
1df80 20 30 78 30 30 30 34 30 20 20 2f 2a 20 41 20 63 0x00040 /* A c
1df90 6f 72 72 65 6c 61 74 65 64 20 73 75 62 71 75 65 orrelated subque
1dfa0 72 79 20 68 61 73 20 62 65 65 6e 20 73 65 65 6e ry has been seen
1dfb0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 55 */.#define NC_U
1dfc0 45 4c 69 73 74 20 20 20 20 30 78 30 30 30 38 30 EList 0x00080
1dfd0 20 20 2f 2a 20 54 72 75 65 20 69 66 20 75 4e 43 /* True if uNC
1dfe0 2e 70 45 4c 69 73 74 20 69 73 20 75 73 65 64 20 .pEList is used
1dff0 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 55 41 */.#define NC_UA
1e000 67 67 49 6e 66 6f 20 20 30 78 30 30 31 30 30 20 ggInfo 0x00100
1e010 20 2f 2a 20 54 72 75 65 20 69 66 20 75 4e 43 2e /* True if uNC.
1e020 70 41 67 67 49 6e 66 6f 20 69 73 20 75 73 65 64 pAggInfo is used
1e030 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 55 */.#define NC_U
1e040 55 70 73 65 72 74 20 20 20 30 78 30 30 32 30 30 Upsert 0x00200
1e050 20 20 2f 2a 20 54 72 75 65 20 69 66 20 75 4e 43 /* True if uNC
1e060 2e 70 55 70 73 65 72 74 20 69 73 20 75 73 65 64 .pUpsert is used
1e070 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 4d */.#define NC_M
1e080 69 6e 4d 61 78 41 67 67 20 30 78 30 31 30 30 30 inMaxAgg 0x01000
1e090 20 20 2f 2a 20 6d 69 6e 2f 6d 61 78 20 61 67 67 /* min/max agg
1e0a0 72 65 67 61 74 65 73 20 73 65 65 6e 2e 20 20 53 regates seen. S
1e0b0 65 65 20 6e 6f 74 65 20 61 62 6f 76 65 20 2a 2f ee note above */
1e0c0 0a 23 64 65 66 69 6e 65 20 4e 43 5f 43 6f 6d 70 .#define NC_Comp
1e0d0 6c 65 78 20 20 20 30 78 30 32 30 30 30 20 20 2f lex 0x02000 /
1e0e0 2a 20 54 72 75 65 20 69 66 20 61 20 66 75 6e 63 * True if a func
1e0f0 74 69 6f 6e 20 6f 72 20 73 75 62 71 75 65 72 79 tion or subquery
1e100 20 73 65 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 seen */.#define
1e110 20 4e 43 5f 41 6c 6c 6f 77 57 69 6e 20 20 30 78 NC_AllowWin 0x
1e120 30 34 30 30 30 20 20 2f 2a 20 57 69 6e 64 6f 77 04000 /* Window
1e130 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 61 functions are a
1e140 6c 6c 6f 77 65 64 20 68 65 72 65 20 2a 2f 0a 23 llowed here */.#
1e150 64 65 66 69 6e 65 20 4e 43 5f 48 61 73 57 69 6e define NC_HasWin
1e160 20 20 20 20 30 78 30 38 30 30 30 20 20 2f 2a 20 0x08000 /*
1e170 4f 6e 65 20 6f 72 20 6d 6f 72 65 20 77 69 6e 64 One or more wind
1e180 6f 77 20 66 75 6e 63 74 69 6f 6e 73 20 73 65 65 ow functions see
1e190 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f n */.#define NC_
1e1a0 49 73 44 44 4c 20 20 20 20 20 30 78 31 30 30 30 IsDDL 0x1000
1e1b0 30 20 20 2f 2a 20 52 65 73 6f 6c 76 69 6e 67 20 0 /* Resolving
1e1c0 6e 61 6d 65 73 20 69 6e 20 61 20 43 52 45 41 54 names in a CREAT
1e1d0 45 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f 0a 23 E statement */.#
1e1e0 64 65 66 69 6e 65 20 4e 43 5f 47 65 6e 43 6f 6c define NC_GenCol
1e1f0 20 20 20 20 30 78 32 30 30 30 30 20 20 2f 2a 20 0x20000 /*
1e200 54 72 75 65 20 66 6f 72 20 61 20 47 45 4e 45 52 True for a GENER
1e210 41 54 45 44 20 41 4c 57 41 59 53 20 41 53 20 63 ATED ALWAYS AS c
1e220 6c 61 75 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 lause */../*.**
1e230 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
1e240 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6f 62 6a he following obj
1e250 65 63 74 20 64 65 73 63 72 69 62 65 73 20 61 20 ect describes a
1e260 73 69 6e 67 6c 65 20 4f 4e 20 43 4f 4e 46 4c 49 single ON CONFLI
1e270 43 54 0a 2a 2a 20 63 6c 61 75 73 65 20 69 6e 20 CT.** clause in
1e280 61 6e 20 75 70 73 65 72 74 2e 0a 2a 2a 0a 2a 2a an upsert..**.**
1e290 20 54 68 65 20 70 55 70 73 65 72 74 54 61 72 67 The pUpsertTarg
1e2a0 65 74 20 66 69 65 6c 64 20 69 73 20 6f 6e 6c 79 et field is only
1e2b0 20 73 65 74 20 69 66 20 74 68 65 20 4f 4e 20 43 set if the ON C
1e2c0 4f 4e 46 4c 49 43 54 20 63 6c 61 75 73 65 20 69 ONFLICT clause i
1e2d0 6e 63 6c 75 64 65 73 0a 2a 2a 20 63 6f 6e 66 6c ncludes.** confl
1e2e0 69 63 74 2d 74 61 72 67 65 74 20 63 6c 61 75 73 ict-target claus
1e2f0 65 2e 20 20 28 49 6e 20 22 4f 4e 20 43 4f 4e 46 e. (In "ON CONF
1e300 4c 49 43 54 28 61 2c 62 29 22 20 74 68 65 20 22 LICT(a,b)" the "
1e310 28 61 2c 62 29 22 20 69 73 20 74 68 65 0a 2a 2a (a,b)" is the.**
1e320 20 63 6f 6e 66 6c 69 63 74 2d 74 61 72 67 65 74 conflict-target
1e330 20 63 6c 61 75 73 65 2e 29 20 20 54 68 65 20 70 clause.) The p
1e340 55 70 73 65 72 74 54 61 72 67 65 74 57 68 65 72 UpsertTargetWher
1e350 65 20 69 73 20 74 68 65 20 6f 70 74 69 6f 6e 61 e is the optiona
1e360 6c 0a 2a 2a 20 57 48 45 52 45 20 63 6c 61 75 73 l.** WHERE claus
1e370 65 20 75 73 65 64 20 74 6f 20 69 64 65 6e 74 69 e used to identi
1e380 66 79 20 70 61 72 74 69 61 6c 20 75 6e 69 71 75 fy partial uniqu
1e390 65 20 69 6e 64 65 78 65 73 2e 0a 2a 2a 0a 2a 2a e indexes..**.**
1e3a0 20 70 55 70 73 65 72 74 53 65 74 20 69 73 20 74 pUpsertSet is t
1e3b0 68 65 20 6c 69 73 74 20 6f 66 20 63 6f 6c 75 6d he list of colum
1e3c0 6e 3d 65 78 70 72 20 74 65 72 6d 73 20 6f 66 20 n=expr terms of
1e3d0 74 68 65 20 55 50 44 41 54 45 20 73 74 61 74 65 the UPDATE state
1e3e0 6d 65 6e 74 2e 20 0a 2a 2a 20 54 68 65 20 70 55 ment. .** The pU
1e3f0 70 73 65 72 74 53 65 74 20 66 69 65 6c 64 20 69 psertSet field i
1e400 73 20 4e 55 4c 4c 20 66 6f 72 20 61 20 4f 4e 20 s NULL for a ON
1e410 43 4f 4e 46 4c 49 43 54 20 44 4f 20 4e 4f 54 48 CONFLICT DO NOTH
1e420 49 4e 47 2e 20 20 54 68 65 0a 2a 2a 20 70 55 70 ING. The.** pUp
1e430 73 65 72 74 57 68 65 72 65 20 69 73 20 74 68 65 sertWhere is the
1e440 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 66 6f WHERE clause fo
1e450 72 20 74 68 65 20 55 50 44 41 54 45 20 61 6e 64 r the UPDATE and
1e460 20 69 73 20 4e 55 4c 4c 20 69 66 20 74 68 65 0a is NULL if the.
1e470 2a 2a 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 ** WHERE clause
1e480 69 73 20 6f 6d 69 74 74 65 64 2e 0a 2a 2f 0a 73 is omitted..*/.s
1e490 74 72 75 63 74 20 55 70 73 65 72 74 20 7b 0a 20 truct Upsert {.
1e4a0 20 45 78 70 72 4c 69 73 74 20 2a 70 55 70 73 65 ExprList *pUpse
1e4b0 72 74 54 61 72 67 65 74 3b 20 20 2f 2a 20 4f 70 rtTarget; /* Op
1e4c0 74 69 6f 6e 61 6c 20 64 65 73 63 72 69 70 74 69 tional descripti
1e4d0 6f 6e 20 6f 66 20 63 6f 6e 66 6c 69 63 74 69 6e on of conflictin
1e4e0 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 45 78 70 g index */. Exp
1e4f0 72 20 2a 70 55 70 73 65 72 74 54 61 72 67 65 74 r *pUpsertTarget
1e500 57 68 65 72 65 3b 20 2f 2a 20 57 48 45 52 45 20 Where; /* WHERE
1e510 63 6c 61 75 73 65 20 66 6f 72 20 70 61 72 74 69 clause for parti
1e520 61 6c 20 69 6e 64 65 78 20 74 61 72 67 65 74 73 al index targets
1e530 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1e540 70 55 70 73 65 72 74 53 65 74 3b 20 20 20 20 20 pUpsertSet;
1e550 2f 2a 20 54 68 65 20 53 45 54 20 63 6c 61 75 73 /* The SET claus
1e560 65 20 66 72 6f 6d 20 61 6e 20 4f 4e 20 43 4f 4e e from an ON CON
1e570 46 4c 49 43 54 20 55 50 44 41 54 45 20 2a 2f 0a FLICT UPDATE */.
1e580 20 20 45 78 70 72 20 2a 70 55 70 73 65 72 74 57 Expr *pUpsertW
1e590 68 65 72 65 3b 20 20 20 20 20 20 20 2f 2a 20 57 here; /* W
1e5a0 48 45 52 45 20 63 6c 61 75 73 65 20 66 6f 72 20 HERE clause for
1e5b0 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 the ON CONFLICT
1e5c0 55 50 44 41 54 45 20 2a 2f 0a 20 20 2f 2a 20 54 UPDATE */. /* T
1e5d0 68 65 20 66 69 65 6c 64 73 20 61 62 6f 76 65 20 he fields above
1e5e0 63 6f 6d 70 72 69 73 65 20 74 68 65 20 70 61 72 comprise the par
1e5f0 73 65 20 74 72 65 65 20 66 6f 72 20 74 68 65 20 se tree for the
1e600 75 70 73 65 72 74 20 63 6c 61 75 73 65 2e 0a 20 upsert clause..
1e610 20 2a 2a 20 54 68 65 20 66 69 65 6c 64 73 20 62 ** The fields b
1e620 65 6c 6f 77 20 61 72 65 20 75 73 65 64 20 74 6f elow are used to
1e630 20 74 72 61 6e 73 66 65 72 20 69 6e 66 6f 72 6d transfer inform
1e640 61 74 69 6f 6e 20 66 72 6f 6d 20 74 68 65 20 49 ation from the I
1e650 4e 53 45 52 54 0a 20 20 2a 2a 20 70 72 6f 63 65 NSERT. ** proce
1e660 73 73 69 6e 67 20 64 6f 77 6e 20 69 6e 74 6f 20 ssing down into
1e670 74 68 65 20 55 50 44 41 54 45 20 70 72 6f 63 65 the UPDATE proce
1e680 73 73 69 6e 67 20 77 68 69 6c 65 20 67 65 6e 65 ssing while gene
1e690 72 61 74 69 6e 67 20 63 6f 64 65 2e 0a 20 20 2a rating code.. *
1e6a0 2a 20 55 70 73 65 72 74 20 6f 77 6e 73 20 74 68 * Upsert owns th
1e6b0 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 e memory allocat
1e6c0 65 64 20 61 62 6f 76 65 2c 20 62 75 74 20 6e 6f ed above, but no
1e6d0 74 20 74 68 65 20 6d 65 6d 6f 72 79 20 62 65 6c t the memory bel
1e6e0 6f 77 2e 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a ow. */. Index *
1e6f0 70 55 70 73 65 72 74 49 64 78 3b 20 20 20 20 20 pUpsertIdx;
1e700 20 20 20 2f 2a 20 43 6f 6e 73 74 72 61 69 6e 74 /* Constraint
1e710 20 74 68 61 74 20 70 55 70 73 65 72 74 54 61 72 that pUpsertTar
1e720 67 65 74 20 69 64 65 6e 74 69 66 69 65 73 20 2a get identifies *
1e730 2f 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 55 70 /. SrcList *pUp
1e740 73 65 72 74 53 72 63 3b 20 20 20 20 20 20 2f 2a sertSrc; /*
1e750 20 54 61 62 6c 65 20 74 6f 20 62 65 20 75 70 64 Table to be upd
1e760 61 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 72 65 ated */. int re
1e770 67 44 61 74 61 3b 20 20 20 20 20 20 20 20 20 20 gData;
1e780 20 20 20 20 2f 2a 20 46 69 72 73 74 20 72 65 67 /* First reg
1e790 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 61 72 ister holding ar
1e7a0 72 61 79 20 6f 66 20 56 41 4c 55 45 53 20 2a 2f ray of VALUES */
1e7b0 0a 20 20 69 6e 74 20 69 44 61 74 61 43 75 72 3b . int iDataCur;
1e7c0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1e7d0 49 6e 64 65 78 20 6f 66 20 74 68 65 20 64 61 74 Index of the dat
1e7e0 61 20 63 75 72 73 6f 72 20 2a 2f 0a 20 20 69 6e a cursor */. in
1e7f0 74 20 69 49 64 78 43 75 72 3b 20 20 20 20 20 20 t iIdxCur;
1e800 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 /* Index
1e810 20 6f 66 20 74 68 65 20 66 69 72 73 74 20 69 6e of the first in
1e820 64 65 78 20 63 75 72 73 6f 72 20 2a 2f 0a 7d 3b dex cursor */.};
1e830 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 ../*.** An insta
1e840 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f nce of the follo
1e850 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 wing structure c
1e860 6f 6e 74 61 69 6e 73 20 61 6c 6c 20 69 6e 66 6f ontains all info
1e870 72 6d 61 74 69 6f 6e 0a 2a 2a 20 6e 65 65 64 65 rmation.** neede
1e880 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 63 6f d to generate co
1e890 64 65 20 66 6f 72 20 61 20 73 69 6e 67 6c 65 20 de for a single
1e8a0 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
1e8b0 2e 0a 2a 2a 0a 2a 2a 20 53 65 65 20 74 68 65 20 ..**.** See the
1e8c0 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e 74 20 6f header comment o
1e8d0 6e 20 74 68 65 20 63 6f 6d 70 75 74 65 4c 69 6d n the computeLim
1e8e0 69 74 52 65 67 69 73 74 65 72 73 28 29 20 72 6f itRegisters() ro
1e8f0 75 74 69 6e 65 20 66 6f 72 20 61 0a 2a 2a 20 64 utine for a.** d
1e900 65 74 61 69 6c 65 64 20 64 65 73 63 72 69 70 74 etailed descript
1e910 69 6f 6e 20 6f 66 20 74 68 65 20 6d 65 61 6e 69 ion of the meani
1e920 6e 67 20 6f 66 20 74 68 65 20 69 4c 69 6d 69 74 ng of the iLimit
1e930 20 61 6e 64 20 69 4f 66 66 73 65 74 20 66 69 65 and iOffset fie
1e940 6c 64 73 2e 0a 2a 2a 0a 2a 2a 20 61 64 64 72 4f lds..**.** addrO
1e950 70 65 6e 45 70 68 6d 5b 5d 20 65 6e 74 72 69 65 penEphm[] entrie
1e960 73 20 63 6f 6e 74 61 69 6e 20 74 68 65 20 61 64 s contain the ad
1e970 64 72 65 73 73 20 6f 66 20 4f 50 5f 4f 70 65 6e dress of OP_Open
1e980 45 70 68 65 6d 65 72 61 6c 20 6f 70 63 6f 64 65 Ephemeral opcode
1e990 73 2e 0a 2a 2a 20 54 68 65 73 65 20 61 64 64 72 s..** These addr
1e9a0 65 73 73 65 73 20 6d 75 73 74 20 62 65 20 73 74 esses must be st
1e9b0 6f 72 65 64 20 73 6f 20 74 68 61 74 20 77 65 20 ored so that we
1e9c0 63 61 6e 20 67 6f 20 62 61 63 6b 20 61 6e 64 20 can go back and
1e9d0 66 69 6c 6c 20 69 6e 0a 2a 2a 20 74 68 65 20 50 fill in.** the P
1e9e0 34 5f 4b 45 59 49 4e 46 4f 20 61 6e 64 20 50 32 4_KEYINFO and P2
1e9f0 20 70 61 72 61 6d 65 74 65 72 73 20 6c 61 74 65 parameters late
1ea00 72 2e 20 20 4e 65 69 74 68 65 72 20 74 68 65 20 r. Neither the
1ea10 4b 65 79 49 6e 66 6f 20 6e 6f 72 0a 2a 2a 20 74 KeyInfo nor.** t
1ea20 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 6f 6c he number of col
1ea30 75 6d 6e 73 20 69 6e 20 50 32 20 63 61 6e 20 62 umns in P2 can b
1ea40 65 20 63 6f 6d 70 75 74 65 64 20 61 74 20 74 68 e computed at th
1ea50 65 20 73 61 6d 65 20 74 69 6d 65 0a 2a 2a 20 61 e same time.** a
1ea60 73 20 74 68 65 20 4f 50 5f 4f 70 65 6e 45 70 68 s the OP_OpenEph
1ea70 6d 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 69 73 m instruction is
1ea80 20 63 6f 64 65 64 20 62 65 63 61 75 73 65 20 6e coded because n
1ea90 6f 74 0a 2a 2a 20 65 6e 6f 75 67 68 20 69 6e 66 ot.** enough inf
1eaa0 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 ormation about t
1eab0 68 65 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 he compound quer
1eac0 79 20 69 73 20 6b 6e 6f 77 6e 20 61 74 20 74 68 y is known at th
1ead0 61 74 20 70 6f 69 6e 74 2e 0a 2a 2a 20 54 68 65 at point..** The
1eae0 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 KeyInfo for add
1eaf0 72 4f 70 65 6e 54 72 61 6e 5b 30 5d 20 61 6e 64 rOpenTran[0] and
1eb00 20 5b 31 5d 20 63 6f 6e 74 61 69 6e 73 20 63 6f [1] contains co
1eb10 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 llating sequence
1eb20 73 0a 2a 2a 20 66 6f 72 20 74 68 65 20 72 65 73 s.** for the res
1eb30 75 6c 74 20 73 65 74 2e 20 20 54 68 65 20 4b 65 ult set. The Ke
1eb40 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 72 4f 70 yInfo for addrOp
1eb50 65 6e 45 70 68 6d 5b 32 5d 20 63 6f 6e 74 61 69 enEphm[2] contai
1eb60 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 0a 2a 2a 20 ns collating.**
1eb70 73 65 71 75 65 6e 63 65 73 20 66 6f 72 20 74 68 sequences for th
1eb80 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
1eb90 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c e..*/.struct Sel
1eba0 65 63 74 20 7b 0a 20 20 45 78 70 72 4c 69 73 74 ect {. ExprList
1ebb0 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 20 20 2f *pEList; /
1ebc0 2a 20 54 68 65 20 66 69 65 6c 64 73 20 6f 66 20 * The fields of
1ebd0 74 68 65 20 72 65 73 75 6c 74 20 2a 2f 0a 20 20 the result */.
1ebe0 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 20 u8 op;
1ebf0 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 /* One of
1ec00 3a 20 54 4b 5f 55 4e 49 4f 4e 20 54 4b 5f 41 4c : TK_UNION TK_AL
1ec10 4c 20 54 4b 5f 49 4e 54 45 52 53 45 43 54 20 54 L TK_INTERSECT T
1ec20 4b 5f 45 58 43 45 50 54 20 2a 2f 0a 20 20 4c 6f K_EXCEPT */. Lo
1ec30 67 45 73 74 20 6e 53 65 6c 65 63 74 52 6f 77 3b gEst nSelectRow;
1ec40 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 /* Estimate
1ec50 64 20 6e 75 6d 62 65 72 20 6f 66 20 72 65 73 75 d number of resu
1ec60 6c 74 20 72 6f 77 73 20 2a 2f 0a 20 20 75 33 32 lt rows */. u32
1ec70 20 73 65 6c 46 6c 61 67 73 3b 20 20 20 20 20 20 selFlags;
1ec80 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 53 /* Various S
1ec90 46 5f 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 F_* values */.
1eca0 69 6e 74 20 69 4c 69 6d 69 74 2c 20 69 4f 66 66 int iLimit, iOff
1ecb0 73 65 74 3b 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 set; /* Memory
1ecc0 20 72 65 67 69 73 74 65 72 73 20 68 6f 6c 64 69 registers holdi
1ecd0 6e 67 20 4c 49 4d 49 54 20 26 20 4f 46 46 53 45 ng LIMIT & OFFSE
1ece0 54 20 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 20 20 T counters */.
1ecf0 75 33 32 20 73 65 6c 49 64 3b 20 20 20 20 20 20 u32 selId;
1ed00 20 20 20 20 20 20 20 2f 2a 20 55 6e 69 71 75 65 /* Unique
1ed10 20 69 64 65 6e 74 69 66 69 65 72 20 6e 75 6d 62 identifier numb
1ed20 65 72 20 66 6f 72 20 74 68 69 73 20 53 45 4c 45 er for this SELE
1ed30 43 54 20 2a 2f 0a 20 20 69 6e 74 20 61 64 64 72 CT */. int addr
1ed40 4f 70 65 6e 45 70 68 6d 5b 32 5d 3b 20 20 20 2f OpenEphm[2]; /
1ed50 2a 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 20 6f * OP_OpenEphem o
1ed60 70 63 6f 64 65 73 20 72 65 6c 61 74 65 64 20 74 pcodes related t
1ed70 6f 20 74 68 69 73 20 73 65 6c 65 63 74 20 2a 2f o this select */
1ed80 0a 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 . SrcList *pSrc
1ed90 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 ; /* The
1eda0 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a FROM clause */.
1edb0 20 20 45 78 70 72 20 2a 70 57 68 65 72 65 3b 20 Expr *pWhere;
1edc0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
1edd0 57 48 45 52 45 20 63 6c 61 75 73 65 20 2a 2f 0a WHERE clause */.
1ede0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f ExprList *pGro
1edf0 75 70 42 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 upBy; /* The
1ee00 47 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 GROUP BY clause
1ee10 2a 2f 0a 20 20 45 78 70 72 20 2a 70 48 61 76 69 */. Expr *pHavi
1ee20 6e 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 ng; /* T
1ee30 68 65 20 48 41 56 49 4e 47 20 63 6c 61 75 73 65 he HAVING clause
1ee40 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a */. ExprList *
1ee50 70 4f 72 64 65 72 42 79 3b 20 20 20 20 2f 2a 20 pOrderBy; /*
1ee60 54 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 The ORDER BY cla
1ee70 75 73 65 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 use */. Select
1ee80 2a 70 50 72 69 6f 72 3b 20 20 20 20 20 20 20 20 *pPrior;
1ee90 2f 2a 20 50 72 69 6f 72 20 73 65 6c 65 63 74 20 /* Prior select
1eea0 69 6e 20 61 20 63 6f 6d 70 6f 75 6e 64 20 73 65 in a compound se
1eeb0 6c 65 63 74 20 73 74 61 74 65 6d 65 6e 74 20 2a lect statement *
1eec0 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 4e 65 78 /. Select *pNex
1eed0 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 t; /* Ne
1eee0 78 74 20 73 65 6c 65 63 74 20 74 6f 20 74 68 65 xt select to the
1eef0 20 6c 65 66 74 20 69 6e 20 61 20 63 6f 6d 70 6f left in a compo
1ef00 75 6e 64 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 und */. Expr *p
1ef10 4c 69 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 Limit;
1ef20 2f 2a 20 4c 49 4d 49 54 20 65 78 70 72 65 73 73 /* LIMIT express
1ef30 69 6f 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 ion. NULL means
1ef40 6e 6f 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 57 not used. */. W
1ef50 69 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 20 ith *pWith;
1ef60 20 20 20 20 20 20 2f 2a 20 57 49 54 48 20 63 6c /* WITH cl
1ef70 61 75 73 65 20 61 74 74 61 63 68 65 64 20 74 6f ause attached to
1ef80 20 74 68 69 73 20 73 65 6c 65 63 74 2e 20 4f 72 this select. Or
1ef90 20 4e 55 4c 4c 2e 20 2a 2f 0a 23 69 66 6e 64 65 NULL. */.#ifnde
1efa0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 49 f SQLITE_OMIT_WI
1efb0 4e 44 4f 57 46 55 4e 43 0a 20 20 57 69 6e 64 6f NDOWFUNC. Windo
1efc0 77 20 2a 70 57 69 6e 3b 20 20 20 20 20 20 20 20 w *pWin;
1efd0 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 77 69 6e /* List of win
1efe0 64 6f 77 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f dow functions */
1eff0 0a 20 20 57 69 6e 64 6f 77 20 2a 70 57 69 6e 44 . Window *pWinD
1f000 65 66 6e 3b 20 20 20 20 20 20 2f 2a 20 4c 69 73 efn; /* Lis
1f010 74 20 6f 66 20 6e 61 6d 65 64 20 77 69 6e 64 6f t of named windo
1f020 77 20 64 65 66 69 6e 69 74 69 6f 6e 73 20 2a 2f w definitions */
1f030 0a 23 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a .#endif.};../*.*
1f040 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
1f050 20 66 6f 72 20 53 65 6c 65 63 74 2e 73 65 6c 46 for Select.selF
1f060 6c 61 67 73 2e 20 20 54 68 65 20 22 53 46 22 20 lags. The "SF"
1f070 70 72 65 66 69 78 20 73 74 61 6e 64 73 20 66 6f prefix stands fo
1f080 72 0a 2a 2a 20 22 53 65 6c 65 63 74 20 46 6c 61 r.** "Select Fla
1f090 67 22 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 g"..**.** Value
1f0a0 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 61 6c 6c constraints (all
1f0b0 20 63 68 65 63 6b 65 64 20 76 69 61 20 61 73 73 checked via ass
1f0c0 65 72 74 28 29 29 0a 2a 2a 20 20 20 20 20 53 46 ert()).** SF
1f0d0 5f 48 61 73 41 67 67 20 20 20 20 20 3d 3d 20 4e _HasAgg == N
1f0e0 43 5f 48 61 73 41 67 67 0a 2a 2a 20 20 20 20 20 C_HasAgg.**
1f0f0 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 20 3d 3d SF_MinMaxAgg ==
1f100 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 20 20 NC_MinMaxAgg
1f110 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 == SQLITE_FUNC
1f120 5f 4d 49 4e 4d 41 58 0a 2a 2a 20 20 20 20 20 53 _MINMAX.** S
1f130 46 5f 46 69 78 65 64 4c 69 6d 69 74 20 3d 3d 20 F_FixedLimit ==
1f140 57 48 45 52 45 5f 55 53 45 5f 4c 49 4d 49 54 0a WHERE_USE_LIMIT.
1f150 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 44 69 */.#define SF_Di
1f160 73 74 69 6e 63 74 20 20 20 20 20 20 20 30 78 30 stinct 0x0
1f170 30 30 30 31 20 20 2f 2a 20 4f 75 74 70 75 74 20 0001 /* Output
1f180 73 68 6f 75 6c 64 20 62 65 20 44 49 53 54 49 4e should be DISTIN
1f190 43 54 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 CT */.#define SF
1f1a0 5f 41 6c 6c 20 20 20 20 20 20 20 20 20 20 20 20 _All
1f1b0 30 78 30 30 30 30 32 20 20 2f 2a 20 49 6e 63 6c 0x00002 /* Incl
1f1c0 75 64 65 73 20 74 68 65 20 41 4c 4c 20 6b 65 79 udes the ALL key
1f1d0 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 word */.#define
1f1e0 53 46 5f 52 65 73 6f 6c 76 65 64 20 20 20 20 20 SF_Resolved
1f1f0 20 20 30 78 30 30 30 30 34 20 20 2f 2a 20 49 64 0x00004 /* Id
1f200 65 6e 74 69 66 69 65 72 73 20 68 61 76 65 20 62 entifiers have b
1f210 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 2a 2f 0a een resolved */.
1f220 23 64 65 66 69 6e 65 20 53 46 5f 41 67 67 72 65 #define SF_Aggre
1f230 67 61 74 65 20 20 20 20 20 20 30 78 30 30 30 30 gate 0x0000
1f240 38 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 8 /* Contains a
1f250 67 67 20 66 75 6e 63 74 69 6f 6e 73 20 6f 72 20 gg functions or
1f260 61 20 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 a GROUP BY */.#d
1f270 65 66 69 6e 65 20 53 46 5f 48 61 73 41 67 67 20 efine SF_HasAgg
1f280 20 20 20 20 20 20 20 20 30 78 30 30 30 31 30 20 0x00010
1f290 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 /* Contains agg
1f2a0 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 regate functions
1f2b0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 55 */.#define SF_U
1f2c0 73 65 73 45 70 68 65 6d 65 72 61 6c 20 20 30 78 sesEphemeral 0x
1f2d0 30 30 30 32 30 20 20 2f 2a 20 55 73 65 73 20 74 00020 /* Uses t
1f2e0 68 65 20 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c he OpenEphemeral
1f2f0 20 6f 70 63 6f 64 65 20 2a 2f 0a 23 64 65 66 69 opcode */.#defi
1f300 6e 65 20 53 46 5f 45 78 70 61 6e 64 65 64 20 20 ne SF_Expanded
1f310 20 20 20 20 20 30 78 30 30 30 34 30 20 20 2f 2a 0x00040 /*
1f320 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 45 78 sqlite3SelectEx
1f330 70 61 6e 64 28 29 20 63 61 6c 6c 65 64 20 6f 6e pand() called on
1f340 20 74 68 69 73 20 2a 2f 0a 23 64 65 66 69 6e 65 this */.#define
1f350 20 53 46 5f 48 61 73 54 79 70 65 49 6e 66 6f 20 SF_HasTypeInfo
1f360 20 20 20 30 78 30 30 30 38 30 20 20 2f 2a 20 46 0x00080 /* F
1f370 52 4f 4d 20 73 75 62 71 75 65 72 69 65 73 20 68 ROM subqueries h
1f380 61 76 65 20 54 61 62 6c 65 20 6d 65 74 61 64 61 ave Table metada
1f390 74 61 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 ta */.#define SF
1f3a0 5f 43 6f 6d 70 6f 75 6e 64 20 20 20 20 20 20 20 _Compound
1f3b0 30 78 30 30 31 30 30 20 20 2f 2a 20 50 61 72 74 0x00100 /* Part
1f3c0 20 6f 66 20 61 20 63 6f 6d 70 6f 75 6e 64 20 71 of a compound q
1f3d0 75 65 72 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 uery */.#define
1f3e0 53 46 5f 56 61 6c 75 65 73 20 20 20 20 20 20 20 SF_Values
1f3f0 20 20 30 78 30 30 32 30 30 20 20 2f 2a 20 53 79 0x00200 /* Sy
1f400 6e 74 68 65 73 69 7a 65 64 20 66 72 6f 6d 20 56 nthesized from V
1f410 41 4c 55 45 53 20 63 6c 61 75 73 65 20 2a 2f 0a ALUES clause */.
1f420 23 64 65 66 69 6e 65 20 53 46 5f 4d 75 6c 74 69 #define SF_Multi
1f430 56 61 6c 75 65 20 20 20 20 20 30 78 30 30 34 30 Value 0x0040
1f440 30 20 20 2f 2a 20 53 69 6e 67 6c 65 20 56 41 4c 0 /* Single VAL
1f450 55 45 53 20 74 65 72 6d 20 77 69 74 68 20 6d 75 UES term with mu
1f460 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 23 ltiple rows */.#
1f470 64 65 66 69 6e 65 20 53 46 5f 4e 65 73 74 65 64 define SF_Nested
1f480 46 72 6f 6d 20 20 20 20 20 30 78 30 30 38 30 30 From 0x00800
1f490 20 20 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 70 /* Part of a p
1f4a0 61 72 65 6e 74 68 65 73 69 7a 65 64 20 46 52 4f arenthesized FRO
1f4b0 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 66 M clause */.#def
1f4c0 69 6e 65 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 ine SF_MinMaxAgg
1f4d0 20 20 20 20 20 20 30 78 30 31 30 30 30 20 20 2f 0x01000 /
1f4e0 2a 20 41 67 67 72 65 67 61 74 65 20 63 6f 6e 74 * Aggregate cont
1f4f0 61 69 6e 69 6e 67 20 6d 69 6e 28 29 20 6f 72 20 aining min() or
1f500 6d 61 78 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 max() */.#define
1f510 20 53 46 5f 52 65 63 75 72 73 69 76 65 20 20 20 SF_Recursive
1f520 20 20 20 30 78 30 32 30 30 30 20 20 2f 2a 20 54 0x02000 /* T
1f530 68 65 20 72 65 63 75 72 73 69 76 65 20 70 61 72 he recursive par
1f540 74 20 6f 66 20 61 20 72 65 63 75 72 73 69 76 65 t of a recursive
1f550 20 43 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 CTE */.#define
1f560 53 46 5f 46 69 78 65 64 4c 69 6d 69 74 20 20 20 SF_FixedLimit
1f570 20 20 30 78 30 34 30 30 30 20 20 2f 2a 20 6e 53 0x04000 /* nS
1f580 65 6c 65 63 74 52 6f 77 20 73 65 74 20 62 79 20 electRow set by
1f590 61 20 63 6f 6e 73 74 61 6e 74 20 4c 49 4d 49 54 a constant LIMIT
1f5a0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d */.#define SF_M
1f5b0 61 79 62 65 43 6f 6e 76 65 72 74 20 20 20 30 78 aybeConvert 0x
1f5c0 30 38 30 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 08000 /* Need c
1f5d0 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 onvertCompoundSe
1f5e0 6c 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 lectToSubquery()
1f5f0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 */.#define SF_C
1f600 6f 6e 76 65 72 74 65 64 20 20 20 20 20 20 30 78 onverted 0x
1f610 31 30 30 30 30 20 20 2f 2a 20 42 79 20 63 6f 6e 10000 /* By con
1f620 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 vertCompoundSele
1f630 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a ctToSubquery() *
1f640 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 49 6e 63 /.#define SF_Inc
1f650 6c 75 64 65 48 69 64 64 65 6e 20 20 30 78 32 30 ludeHidden 0x20
1f660 30 30 30 20 20 2f 2a 20 49 6e 63 6c 75 64 65 20 000 /* Include
1f670 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 69 hidden columns i
1f680 6e 20 6f 75 74 70 75 74 20 2a 2f 0a 23 64 65 66 n output */.#def
1f690 69 6e 65 20 53 46 5f 43 6f 6d 70 6c 65 78 52 65 ine SF_ComplexRe
1f6a0 73 75 6c 74 20 20 30 78 34 30 30 30 30 20 20 2f sult 0x40000 /
1f6b0 2a 20 52 65 73 75 6c 74 20 63 6f 6e 74 61 69 6e * Result contain
1f6c0 73 20 73 75 62 71 75 65 72 79 20 6f 72 20 66 75 s subquery or fu
1f6d0 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e nction */.#defin
1f6e0 65 20 53 46 5f 57 68 65 72 65 42 65 67 69 6e 20 e SF_WhereBegin
1f6f0 20 20 20 20 30 78 38 30 30 30 30 20 20 2f 2a 20 0x80000 /*
1f700 52 65 61 6c 6c 79 20 61 20 57 68 65 72 65 42 65 Really a WhereBe
1f710 67 69 6e 28 29 20 63 61 6c 6c 2e 20 20 44 65 62 gin() call. Deb
1f720 75 67 20 4f 6e 6c 79 20 2a 2f 0a 0a 2f 2a 0a 2a ug Only */../*.*
1f730 2a 20 54 68 65 20 72 65 73 75 6c 74 73 20 6f 66 * The results of
1f740 20 61 20 53 45 4c 45 43 54 20 63 61 6e 20 62 65 a SELECT can be
1f750 20 64 69 73 74 72 69 62 75 74 65 64 20 69 6e 20 distributed in
1f760 73 65 76 65 72 61 6c 20 77 61 79 73 2c 20 61 73 several ways, as
1f770 20 64 65 66 69 6e 65 64 0a 2a 2a 20 62 79 20 6f defined.** by o
1f780 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ne of the follow
1f790 69 6e 67 20 6d 61 63 72 6f 73 2e 20 20 54 68 65 ing macros. The
1f7a0 20 22 53 52 54 22 20 70 72 65 66 69 78 20 6d 65 "SRT" prefix me
1f7b0 61 6e 73 20 22 53 45 4c 45 43 54 20 52 65 73 75 ans "SELECT Resu
1f7c0 6c 74 0a 2a 2a 20 54 79 70 65 22 2e 0a 2a 2a 0a lt.** Type"..**.
1f7d0 2a 2a 20 20 20 20 20 53 52 54 5f 55 6e 69 6f 6e ** SRT_Union
1f7e0 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 73 Store res
1f7f0 75 6c 74 73 20 61 73 20 61 20 6b 65 79 20 69 6e ults as a key in
1f800 20 61 20 74 65 6d 70 6f 72 61 72 79 20 69 6e 64 a temporary ind
1f810 65 78 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 ex.**
1f820 20 20 20 20 20 20 20 20 20 20 69 64 65 6e 74 69 identi
1f830 66 69 65 64 20 62 79 20 70 44 65 73 74 2d 3e 69 fied by pDest->i
1f840 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 SDParm..**.**
1f850 20 20 53 52 54 5f 45 78 63 65 70 74 20 20 20 20 SRT_Except
1f860 20 20 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 73 Remove results
1f870 20 66 72 6f 6d 20 74 68 65 20 74 65 6d 70 6f 72 from the tempor
1f880 61 72 79 20 69 6e 64 65 78 20 70 44 65 73 74 2d ary index pDest-
1f890 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 >iSDParm..**.**
1f8a0 20 20 20 20 53 52 54 5f 45 78 69 73 74 73 20 20 SRT_Exists
1f8b0 20 20 20 20 53 74 6f 72 65 20 61 20 31 20 69 6e Store a 1 in
1f8c0 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 70 44 65 memory cell pDe
1f8d0 73 74 2d 3e 69 53 44 50 61 72 6d 20 69 66 20 74 st->iSDParm if t
1f8e0 68 65 20 72 65 73 75 6c 74 0a 2a 2a 20 20 20 20 he result.**
1f8f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f900 20 73 65 74 20 69 73 20 6e 6f 74 20 65 6d 70 74 set is not empt
1f910 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 y..**.** SRT
1f920 5f 44 69 73 63 61 72 64 20 20 20 20 20 54 68 72 _Discard Thr
1f930 6f 77 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 ow the results a
1f940 77 61 79 2e 20 20 54 68 69 73 20 69 73 20 75 73 way. This is us
1f950 65 64 20 62 79 20 53 45 4c 45 43 54 0a 2a 2a 20 ed by SELECT.**
1f960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f970 20 20 20 20 73 74 61 74 65 6d 65 6e 74 73 20 77 statements w
1f980 69 74 68 69 6e 20 74 72 69 67 67 65 72 73 20 77 ithin triggers w
1f990 68 6f 73 65 20 6f 6e 6c 79 20 70 75 72 70 6f 73 hose only purpos
1f9a0 65 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 e is.**
1f9b0 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 the
1f9c0 73 69 64 65 2d 65 66 66 65 63 74 73 20 6f 66 20 side-effects of
1f9d0 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a functions..**.**
1f9e0 20 41 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f 76 All of the abov
1f9f0 65 20 61 72 65 20 66 72 65 65 20 74 6f 20 69 67 e are free to ig
1fa00 6e 6f 72 65 20 74 68 65 69 72 20 4f 52 44 45 52 nore their ORDER
1fa10 20 42 59 20 63 6c 61 75 73 65 2e 20 54 68 6f 73 BY clause. Thos
1fa20 65 20 74 68 61 74 0a 2a 2a 20 66 6f 6c 6c 6f 77 e that.** follow
1fa30 20 6d 75 73 74 20 68 6f 6e 6f 72 20 74 68 65 20 must honor the
1fa40 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e ORDER BY clause.
1fa50 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4f .**.** SRT_O
1fa60 75 74 70 75 74 20 20 20 20 20 20 47 65 6e 65 72 utput Gener
1fa70 61 74 65 20 61 20 72 6f 77 20 6f 66 20 6f 75 74 ate a row of out
1fa80 70 75 74 20 28 75 73 69 6e 67 20 74 68 65 20 4f put (using the O
1fa90 50 5f 52 65 73 75 6c 74 52 6f 77 0a 2a 2a 20 20 P_ResultRow.**
1faa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fab0 20 20 20 6f 70 63 6f 64 65 29 20 66 6f 72 20 65 opcode) for e
1fac0 61 63 68 20 72 6f 77 20 69 6e 20 74 68 65 20 72 ach row in the r
1fad0 65 73 75 6c 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a esult set..**.**
1fae0 20 20 20 20 20 53 52 54 5f 4d 65 6d 20 20 20 20 SRT_Mem
1faf0 20 20 20 20 20 4f 6e 6c 79 20 76 61 6c 69 64 20 Only valid
1fb00 69 66 20 74 68 65 20 72 65 73 75 6c 74 20 69 73 if the result is
1fb10 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c 75 6d 6e a single column
1fb20 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ..**
1fb30 20 20 20 20 20 20 20 20 20 53 74 6f 72 65 20 74 Store t
1fb40 68 65 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 he first column
1fb50 6f 66 20 74 68 65 20 66 69 72 73 74 20 72 65 73 of the first res
1fb60 75 6c 74 20 72 6f 77 0a 2a 2a 20 20 20 20 20 20 ult row.**
1fb70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1fb80 6e 20 72 65 67 69 73 74 65 72 20 70 44 65 73 74 n register pDest
1fb90 2d 3e 69 53 44 50 61 72 6d 20 74 68 65 6e 20 61 ->iSDParm then a
1fba0 62 61 6e 64 6f 6e 20 74 68 65 20 72 65 73 74 0a bandon the rest.
1fbb0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1fbc0 20 20 20 20 20 20 20 6f 66 20 74 68 65 20 71 75 of the qu
1fbd0 65 72 79 2e 20 20 54 68 69 73 20 64 65 73 74 69 ery. This desti
1fbe0 6e 61 74 69 6f 6e 20 69 6d 70 6c 69 65 73 20 22 nation implies "
1fbf0 4c 49 4d 49 54 20 31 22 2e 0a 2a 2a 0a 2a 2a 20 LIMIT 1"..**.**
1fc00 20 20 20 20 53 52 54 5f 53 65 74 20 20 20 20 20 SRT_Set
1fc10 20 20 20 20 54 68 65 20 72 65 73 75 6c 74 20 6d The result m
1fc20 75 73 74 20 62 65 20 61 20 73 69 6e 67 6c 65 20 ust be a single
1fc30 63 6f 6c 75 6d 6e 2e 20 20 53 74 6f 72 65 20 65 column. Store e
1fc40 61 63 68 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ach.**
1fc50 20 20 20 20 20 20 20 20 20 20 20 72 6f 77 20 6f row o
1fc60 66 20 72 65 73 75 6c 74 20 61 73 20 74 68 65 20 f result as the
1fc70 6b 65 79 20 69 6e 20 74 61 62 6c 65 20 70 44 65 key in table pDe
1fc80 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 st->iSDParm..**
1fc90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fca0 20 20 20 20 41 70 70 6c 79 20 74 68 65 20 61 66 Apply the af
1fcb0 66 69 6e 69 74 79 20 70 44 65 73 74 2d 3e 61 66 finity pDest->af
1fcc0 66 53 64 73 74 20 62 65 66 6f 72 65 20 73 74 6f fSdst before sto
1fcd0 72 69 6e 67 0a 2a 2a 20 20 20 20 20 20 20 20 20 ring.**
1fce0 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 resu
1fcf0 6c 74 73 2e 20 20 55 73 65 64 20 74 6f 20 69 6d lts. Used to im
1fd00 70 6c 65 6d 65 6e 74 20 22 49 4e 20 28 53 45 4c plement "IN (SEL
1fd10 45 43 54 20 2e 2e 2e 29 22 2e 0a 2a 2a 0a 2a 2a ECT ...)"..**.**
1fd20 20 20 20 20 20 53 52 54 5f 45 70 68 65 6d 54 61 SRT_EphemTa
1fd30 62 20 20 20 20 43 72 65 61 74 65 20 61 6e 20 74 b Create an t
1fd40 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 emporary table p
1fd50 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 61 6e Dest->iSDParm an
1fd60 64 20 73 74 6f 72 65 0a 2a 2a 20 20 20 20 20 20 d store.**
1fd70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
1fd80 68 65 20 72 65 73 75 6c 74 20 74 68 65 72 65 2e he result there.
1fd90 20 54 68 65 20 63 75 72 73 6f 72 20 69 73 20 6c The cursor is l
1fda0 65 66 74 20 6f 70 65 6e 20 61 66 74 65 72 0a 2a eft open after.*
1fdb0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1fdc0 20 20 20 20 20 20 72 65 74 75 72 6e 69 6e 67 2e returning.
1fdd0 20 20 54 68 69 73 20 69 73 20 6c 69 6b 65 20 53 This is like S
1fde0 52 54 5f 54 61 62 6c 65 20 65 78 63 65 70 74 20 RT_Table except
1fdf0 74 68 61 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 that.**
1fe00 20 20 20 20 20 20 20 20 20 20 20 20 74 68 69 73 this
1fe10 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 75 73 65 destination use
1fe20 73 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 s OP_OpenEphemer
1fe30 61 6c 20 74 6f 20 63 72 65 61 74 65 0a 2a 2a 20 al to create.**
1fe40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fe50 20 20 20 20 74 68 65 20 74 61 62 6c 65 20 66 69 the table fi
1fe60 72 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 rst..**.** S
1fe70 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 20 47 RT_Coroutine G
1fe80 65 6e 65 72 61 74 65 20 61 20 63 6f 2d 72 6f 75 enerate a co-rou
1fe90 74 69 6e 65 20 74 68 61 74 20 72 65 74 75 72 6e tine that return
1fea0 73 20 61 20 6e 65 77 20 72 6f 77 20 6f 66 0a 2a s a new row of.*
1feb0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1fec0 20 20 20 20 20 20 72 65 73 75 6c 74 73 20 65 61 results ea
1fed0 63 68 20 74 69 6d 65 20 69 74 20 69 73 20 69 6e ch time it is in
1fee0 76 6f 6b 65 64 2e 20 20 54 68 65 20 65 6e 74 72 voked. The entr
1fef0 79 20 70 6f 69 6e 74 0a 2a 2a 20 20 20 20 20 20 y point.**
1ff00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
1ff10 66 20 74 68 65 20 63 6f 2d 72 6f 75 74 69 6e 65 f the co-routine
1ff20 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 72 65 is stored in re
1ff30 67 69 73 74 65 72 20 70 44 65 73 74 2d 3e 69 53 gister pDest->iS
1ff40 44 50 61 72 6d 0a 2a 2a 20 20 20 20 20 20 20 20 DParm.**
1ff50 20 20 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 and
1ff60 20 74 68 65 20 72 65 73 75 6c 74 20 72 6f 77 20 the result row
1ff70 69 73 20 73 74 6f 72 65 64 20 69 6e 20 70 44 65 is stored in pDe
1ff80 73 74 2d 3e 6e 44 65 73 74 20 72 65 67 69 73 74 st->nDest regist
1ff90 65 72 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ers.**
1ffa0 20 20 20 20 20 20 20 20 20 20 20 73 74 61 72 74 start
1ffb0 69 6e 67 20 77 69 74 68 20 70 44 65 73 74 2d 3e ing with pDest->
1ffc0 69 53 64 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 iSdst..**.**
1ffd0 20 53 52 54 5f 54 61 62 6c 65 20 20 20 20 20 20 SRT_Table
1ffe0 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 Store results i
1fff0 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c n temporary tabl
20000 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
20010 2e 0a 2a 2a 20 20 20 20 20 53 52 54 5f 46 69 66 ..** SRT_Fif
20020 6f 20 20 20 20 20 20 20 20 54 68 69 73 20 69 73 o This is
20030 20 6c 69 6b 65 20 53 52 54 5f 45 70 68 65 6d 54 like SRT_EphemT
20040 61 62 20 65 78 63 65 70 74 20 74 68 61 74 20 74 ab except that t
20050 68 65 20 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 he table.**
20060 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20070 69 73 20 61 73 73 75 6d 65 64 20 74 6f 20 61 6c is assumed to al
20080 72 65 61 64 79 20 62 65 20 6f 70 65 6e 2e 20 20 ready be open.
20090 53 52 54 5f 46 69 66 6f 20 68 61 73 0a 2a 2a 20 SRT_Fifo has.**
200a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
200b0 20 20 20 20 74 68 65 20 61 64 64 69 74 69 6f 6e the addition
200c0 61 6c 20 70 72 6f 70 65 72 74 79 20 6f 66 20 62 al property of b
200d0 65 69 6e 67 20 61 62 6c 65 20 74 6f 20 69 67 6e eing able to ign
200e0 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ore.**
200f0 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 4f the O
20100 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a RDER BY clause..
20110 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 **.** SRT_Di
20120 73 74 46 69 66 6f 20 20 20 20 53 74 6f 72 65 20 stFifo Store
20130 72 65 73 75 6c 74 73 20 69 6e 20 61 20 74 65 6d results in a tem
20140 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 porary table pDe
20150 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 st->iSDParm..**
20160 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20170 20 20 20 20 42 75 74 20 61 6c 73 6f 20 75 73 65 But also use
20180 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 temporary table
20190 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b pDest->iSDParm+
201a0 31 20 61 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 1 as.**
201b0 20 20 20 20 20 20 20 20 20 20 20 20 61 20 72 65 a re
201c0 63 6f 72 64 20 6f 66 20 61 6c 6c 20 70 72 69 6f cord of all prio
201d0 72 20 72 65 73 75 6c 74 73 20 61 6e 64 20 69 67 r results and ig
201e0 6e 6f 72 65 20 61 6e 79 20 64 75 70 6c 69 63 61 nore any duplica
201f0 74 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 te.**
20200 20 20 20 20 20 20 20 20 20 20 72 6f 77 73 2e 20 rows.
20210 20 4e 61 6d 65 20 6d 65 61 6e 73 3a 20 20 22 44 Name means: "D
20220 69 73 74 69 6e 63 74 20 46 69 66 6f 22 2e 0a 2a istinct Fifo"..*
20230 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 51 75 65 *.** SRT_Que
20240 75 65 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 ue Store r
20250 65 73 75 6c 74 73 20 69 6e 20 70 72 69 6f 72 69 esults in priori
20260 74 79 20 71 75 65 75 65 20 70 44 65 73 74 2d 3e ty queue pDest->
20270 69 53 44 50 61 72 6d 20 28 72 65 61 6c 6c 79 0a iSDParm (really.
20280 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
20290 20 20 20 20 20 20 20 61 6e 20 69 6e 64 65 78 29 an index)
202a0 2e 20 20 41 70 70 65 6e 64 20 61 20 73 65 71 75 . Append a sequ
202b0 65 6e 63 65 20 6e 75 6d 62 65 72 20 73 6f 20 74 ence number so t
202c0 68 61 74 20 61 6c 6c 20 65 6e 74 72 69 65 73 0a hat all entries.
202d0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
202e0 20 20 20 20 20 20 20 61 72 65 20 64 69 73 74 69 are disti
202f0 6e 63 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 nct..**.** S
20300 52 54 5f 44 69 73 74 51 75 65 75 65 20 20 20 53 RT_DistQueue S
20310 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 tore results in
20320 70 72 69 6f 72 69 74 79 20 71 75 65 75 65 20 70 priority queue p
20330 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 6f 6e Dest->iSDParm on
20340 6c 79 20 69 66 0a 2a 2a 20 20 20 20 20 20 20 20 ly if.**
20350 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 the
20360 20 73 61 6d 65 20 72 65 63 6f 72 64 20 68 61 73 same record has
20370 20 6e 65 76 65 72 20 62 65 65 6e 20 73 74 6f 72 never been stor
20380 65 64 20 62 65 66 6f 72 65 2e 20 20 54 68 65 0a ed before. The.
20390 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
203a0 20 20 20 20 20 20 20 69 6e 64 65 78 20 61 74 20 index at
203b0 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 pDest->iSDParm+1
203c0 20 68 6f 6c 64 20 61 6c 6c 20 70 72 69 6f 72 20 hold all prior
203d0 73 74 6f 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 stores..*/.#defi
203e0 6e 65 20 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 ne SRT_Union
203f0 20 20 20 20 31 20 20 2f 2a 20 53 74 6f 72 65 20 1 /* Store
20400 72 65 73 75 6c 74 20 61 73 20 6b 65 79 73 20 69 result as keys i
20410 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 n an index */.#d
20420 65 66 69 6e 65 20 53 52 54 5f 45 78 63 65 70 74 efine SRT_Except
20430 20 20 20 20 20 20 20 32 20 20 2f 2a 20 52 65 6d 2 /* Rem
20440 6f 76 65 20 72 65 73 75 6c 74 20 66 72 6f 6d 20 ove result from
20450 61 20 55 4e 49 4f 4e 20 69 6e 64 65 78 20 2a 2f a UNION index */
20460 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 45 78 69 .#define SRT_Exi
20470 73 74 73 20 20 20 20 20 20 20 33 20 20 2f 2a 20 sts 3 /*
20480 53 74 6f 72 65 20 31 20 69 66 20 74 68 65 20 72 Store 1 if the r
20490 65 73 75 6c 74 20 69 73 20 6e 6f 74 20 65 6d 70 esult is not emp
204a0 74 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ty */.#define SR
204b0 54 5f 44 69 73 63 61 72 64 20 20 20 20 20 20 34 T_Discard 4
204c0 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 73 61 76 65 /* Do not save
204d0 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 6e 79 the results any
204e0 77 68 65 72 65 20 2a 2f 0a 23 64 65 66 69 6e 65 where */.#define
204f0 20 53 52 54 5f 46 69 66 6f 20 20 20 20 20 20 20 SRT_Fifo
20500 20 20 35 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 5 /* Store re
20510 73 75 6c 74 20 61 73 20 64 61 74 61 20 77 69 74 sult as data wit
20520 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 h an automatic r
20530 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 owid */.#define
20540 53 52 54 5f 44 69 73 74 46 69 66 6f 20 20 20 20 SRT_DistFifo
20550 20 36 20 20 2f 2a 20 4c 69 6b 65 20 53 52 54 5f 6 /* Like SRT_
20560 46 69 66 6f 2c 20 62 75 74 20 75 6e 69 71 75 65 Fifo, but unique
20570 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 2a 2f results only */
20580 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 51 75 65 .#define SRT_Que
20590 75 65 20 20 20 20 20 20 20 20 37 20 20 2f 2a 20 ue 7 /*
205a0 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e 20 Store result in
205b0 61 6e 20 71 75 65 75 65 20 2a 2f 0a 23 64 65 66 an queue */.#def
205c0 69 6e 65 20 53 52 54 5f 44 69 73 74 51 75 65 75 ine SRT_DistQueu
205d0 65 20 20 20 20 38 20 20 2f 2a 20 4c 69 6b 65 20 e 8 /* Like
205e0 53 52 54 5f 51 75 65 75 65 2c 20 62 75 74 20 75 SRT_Queue, but u
205f0 6e 69 71 75 65 20 72 65 73 75 6c 74 73 20 6f 6e nique results on
20600 6c 79 20 2a 2f 0a 0a 2f 2a 20 54 68 65 20 4f 52 ly */../* The OR
20610 44 45 52 20 42 59 20 63 6c 61 75 73 65 20 69 73 DER BY clause is
20620 20 69 67 6e 6f 72 65 64 20 66 6f 72 20 61 6c 6c ignored for all
20630 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 2a 2f of the above */
20640 0a 23 64 65 66 69 6e 65 20 49 67 6e 6f 72 61 62 .#define Ignorab
20650 6c 65 4f 72 64 65 72 62 79 28 58 29 20 28 28 58 leOrderby(X) ((X
20660 2d 3e 65 44 65 73 74 29 3c 3d 53 52 54 5f 44 69 ->eDest)<=SRT_Di
20670 73 74 51 75 65 75 65 29 0a 0a 23 64 65 66 69 6e stQueue)..#defin
20680 65 20 53 52 54 5f 4f 75 74 70 75 74 20 20 20 20 e SRT_Output
20690 20 20 20 39 20 20 2f 2a 20 4f 75 74 70 75 74 20 9 /* Output
206a0 65 61 63 68 20 72 6f 77 20 6f 66 20 72 65 73 75 each row of resu
206b0 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 lt */.#define SR
206c0 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 20 31 30 T_Mem 10
206d0 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
206e0 74 20 69 6e 20 61 20 6d 65 6d 6f 72 79 20 63 65 t in a memory ce
206f0 6c 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ll */.#define SR
20700 54 5f 53 65 74 20 20 20 20 20 20 20 20 20 31 31 T_Set 11
20710 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
20720 74 73 20 61 73 20 6b 65 79 73 20 69 6e 20 61 6e ts as keys in an
20730 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e index */.#defin
20740 65 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 20 e SRT_EphemTab
20750 20 20 31 32 20 20 2f 2a 20 43 72 65 61 74 65 20 12 /* Create
20760 74 72 61 6e 73 69 65 6e 74 20 74 61 62 20 61 6e transient tab an
20770 64 20 73 74 6f 72 65 20 6c 69 6b 65 20 53 52 54 d store like SRT
20780 5f 54 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e _Table */.#defin
20790 65 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 e SRT_Coroutine
207a0 20 20 31 33 20 20 2f 2a 20 47 65 6e 65 72 61 74 13 /* Generat
207b0 65 20 61 20 73 69 6e 67 6c 65 20 72 6f 77 20 6f e a single row o
207c0 66 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 f result */.#def
207d0 69 6e 65 20 53 52 54 5f 54 61 62 6c 65 20 20 20 ine SRT_Table
207e0 20 20 20 20 31 34 20 20 2f 2a 20 53 74 6f 72 65 14 /* Store
207f0 20 72 65 73 75 6c 74 20 61 73 20 64 61 74 61 20 result as data
20800 77 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 with an automati
20810 63 20 72 6f 77 69 64 20 2a 2f 0a 0a 2f 2a 0a 2a c rowid */../*.*
20820 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
20830 20 74 68 69 73 20 6f 62 6a 65 63 74 20 64 65 73 this object des
20840 63 72 69 62 65 73 20 77 68 65 72 65 20 74 6f 20 cribes where to
20850 70 75 74 20 6f 66 20 74 68 65 20 72 65 73 75 6c put of the resul
20860 74 73 20 6f 66 0a 2a 2a 20 61 20 53 45 4c 45 43 ts of.** a SELEC
20870 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a T statement..*/.
20880 73 74 72 75 63 74 20 53 65 6c 65 63 74 44 65 73 struct SelectDes
20890 74 20 7b 0a 20 20 75 38 20 65 44 65 73 74 3b 20 t {. u8 eDest;
208a0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 6f /* Ho
208b0 77 20 74 6f 20 64 69 73 70 6f 73 65 20 6f 66 20 w to dispose of
208c0 74 68 65 20 72 65 73 75 6c 74 73 2e 20 20 4f 6e the results. On
208d0 20 6f 66 20 53 52 54 5f 2a 20 61 62 6f 76 65 2e of SRT_* above.
208e0 20 2a 2f 0a 20 20 69 6e 74 20 69 53 44 50 61 72 */. int iSDPar
208f0 6d 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 m; /* A
20900 70 61 72 61 6d 65 74 65 72 20 75 73 65 64 20 62 parameter used b
20910 79 20 74 68 65 20 65 44 65 73 74 20 64 69 73 70 y the eDest disp
20920 6f 73 61 6c 20 6d 65 74 68 6f 64 20 2a 2f 0a 20 osal method */.
20930 20 69 6e 74 20 69 53 64 73 74 3b 20 20 20 20 20 int iSdst;
20940 20 20 20 20 20 20 2f 2a 20 42 61 73 65 20 72 65 /* Base re
20950 67 69 73 74 65 72 20 77 68 65 72 65 20 72 65 73 gister where res
20960 75 6c 74 73 20 61 72 65 20 77 72 69 74 74 65 6e ults are written
20970 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 64 73 74 3b */. int nSdst;
20980 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
20990 6d 62 65 72 20 6f 66 20 72 65 67 69 73 74 65 72 mber of register
209a0 73 20 61 6c 6c 6f 63 61 74 65 64 20 2a 2f 0a 20 s allocated */.
209b0 20 63 68 61 72 20 2a 7a 41 66 66 53 64 73 74 3b char *zAffSdst;
209c0 20 20 20 20 20 20 2f 2a 20 41 66 66 69 6e 69 74 /* Affinit
209d0 79 20 75 73 65 64 20 77 68 65 6e 20 65 44 65 73 y used when eDes
209e0 74 3d 3d 53 52 54 5f 53 65 74 20 2a 2f 0a 20 20 t==SRT_Set */.
209f0 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 ExprList *pOrder
20a00 42 79 3b 20 20 2f 2a 20 4b 65 79 20 63 6f 6c 75 By; /* Key colu
20a10 6d 6e 73 20 66 6f 72 20 53 52 54 5f 51 75 65 75 mns for SRT_Queu
20a20 65 20 61 6e 64 20 53 52 54 5f 44 69 73 74 51 75 e and SRT_DistQu
20a30 65 75 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a eue */.};../*.**
20a40 20 44 75 72 69 6e 67 20 63 6f 64 65 20 67 65 6e During code gen
20a50 65 72 61 74 69 6f 6e 20 6f 66 20 73 74 61 74 65 eration of state
20a60 6d 65 6e 74 73 20 74 68 61 74 20 64 6f 20 69 6e ments that do in
20a70 73 65 72 74 73 20 69 6e 74 6f 20 41 55 54 4f 49 serts into AUTOI
20a80 4e 43 52 45 4d 45 4e 54 0a 2a 2a 20 74 61 62 6c NCREMENT.** tabl
20a90 65 73 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e es, the followin
20aa0 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 73 g information is
20ab0 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 65 attached to the
20ac0 20 54 61 62 6c 65 2e 75 2e 61 75 74 6f 49 6e 63 Table.u.autoInc
20ad0 2e 70 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 6f 66 .p.** pointer of
20ae0 20 65 61 63 68 20 61 75 74 6f 69 6e 63 72 65 6d each autoincrem
20af0 65 6e 74 20 74 61 62 6c 65 20 74 6f 20 72 65 63 ent table to rec
20b00 6f 72 64 20 73 6f 6d 65 20 73 69 64 65 20 69 6e ord some side in
20b10 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 74 0a 2a formation that.*
20b20 2a 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 * the code gener
20b30 61 74 6f 72 20 6e 65 65 64 73 2e 20 20 57 65 20 ator needs. We
20b40 68 61 76 65 20 74 6f 20 6b 65 65 70 20 70 65 72 have to keep per
20b50 2d 74 61 62 6c 65 20 61 75 74 6f 69 6e 63 72 65 -table autoincre
20b60 6d 65 6e 74 0a 2a 2a 20 69 6e 66 6f 72 6d 61 74 ment.** informat
20b70 69 6f 6e 20 69 6e 20 63 61 73 65 20 69 6e 73 65 ion in case inse
20b80 72 74 73 20 61 72 65 20 64 6f 6e 65 20 77 69 74 rts are done wit
20b90 68 69 6e 20 74 72 69 67 67 65 72 73 2e 20 20 54 hin triggers. T
20ba0 72 69 67 67 65 72 73 20 64 6f 20 6e 6f 74 0a 2a riggers do not.*
20bb0 2a 20 6e 6f 72 6d 61 6c 6c 79 20 63 6f 6f 72 64 * normally coord
20bc0 69 6e 61 74 65 20 74 68 65 69 72 20 61 63 74 69 inate their acti
20bd0 76 69 74 69 65 73 2c 20 62 75 74 20 77 65 20 64 vities, but we d
20be0 6f 20 6e 65 65 64 20 74 6f 20 63 6f 6f 72 64 69 o need to coordi
20bf0 6e 61 74 65 20 74 68 65 0a 2a 2a 20 6c 6f 61 64 nate the.** load
20c00 69 6e 67 20 61 6e 64 20 73 61 76 69 6e 67 20 6f ing and saving o
20c10 66 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 f autoincrement
20c20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a information..*/.
20c30 73 74 72 75 63 74 20 41 75 74 6f 69 6e 63 49 6e struct AutoincIn
20c40 66 6f 20 7b 0a 20 20 41 75 74 6f 69 6e 63 49 6e fo {. AutoincIn
20c50 66 6f 20 2a 70 4e 65 78 74 3b 20 20 20 2f 2a 20 fo *pNext; /*
20c60 4e 65 78 74 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 Next info block
20c70 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 74 68 65 in a list of the
20c80 6d 20 61 6c 6c 20 2a 2f 0a 20 20 54 61 62 6c 65 m all */. Table
20c90 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 *pTab;
20ca0 20 2f 2a 20 54 61 62 6c 65 20 74 68 69 73 20 69 /* Table this i
20cb0 6e 66 6f 20 62 6c 6f 63 6b 20 72 65 66 65 72 73 nfo block refers
20cc0 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 to */. int iDb
20cd0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
20ce0 2a 20 49 6e 64 65 78 20 69 6e 20 73 71 6c 69 74 * Index in sqlit
20cf0 65 33 2e 61 44 62 5b 5d 20 6f 66 20 64 61 74 61 e3.aDb[] of data
20d00 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 70 54 61 base holding pTa
20d10 62 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 43 74 b */. int regCt
20d20 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
20d30 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 20 Memory register
20d40 68 6f 6c 64 69 6e 67 20 74 68 65 20 72 6f 77 69 holding the rowi
20d50 64 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 7d 3b 0a d counter */.};.
20d60 0a 2f 2a 0a 2a 2a 20 41 74 20 6c 65 61 73 74 20 ./*.** At least
20d70 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 one instance of
20d80 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
20d90 72 75 63 74 75 72 65 20 69 73 20 63 72 65 61 74 ructure is creat
20da0 65 64 20 66 6f 72 20 65 61 63 68 0a 2a 2a 20 74 ed for each.** t
20db0 72 69 67 67 65 72 20 74 68 61 74 20 6d 61 79 20 rigger that may
20dc0 62 65 20 66 69 72 65 64 20 77 68 69 6c 65 20 70 be fired while p
20dd0 61 72 73 69 6e 67 20 61 6e 20 49 4e 53 45 52 54 arsing an INSERT
20de0 2c 20 55 50 44 41 54 45 20 6f 72 20 44 45 4c 45 , UPDATE or DELE
20df0 54 45 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 2e TE.** statement.
20e00 20 41 6c 6c 20 73 75 63 68 20 6f 62 6a 65 63 74 All such object
20e10 73 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 s are stored in
20e20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 the linked list
20e30 68 65 61 64 65 64 20 61 74 0a 2a 2a 20 50 61 72 headed at.** Par
20e40 73 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 61 se.pTriggerPrg a
20e50 6e 64 20 64 65 6c 65 74 65 64 20 6f 6e 63 65 20 nd deleted once
20e60 73 74 61 74 65 6d 65 6e 74 20 63 6f 6d 70 69 6c statement compil
20e70 61 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 0a 2a ation has been.*
20e80 2a 20 63 6f 6d 70 6c 65 74 65 64 2e 0a 2a 2a 0a * completed..**.
20e90 2a 2a 20 41 20 56 64 62 65 20 73 75 62 2d 70 72 ** A Vdbe sub-pr
20ea0 6f 67 72 61 6d 20 74 68 61 74 20 69 6d 70 6c 65 ogram that imple
20eb0 6d 65 6e 74 73 20 74 68 65 20 62 6f 64 79 20 61 ments the body a
20ec0 6e 64 20 57 48 45 4e 20 63 6c 61 75 73 65 20 6f nd WHEN clause o
20ed0 66 20 74 72 69 67 67 65 72 0a 2a 2a 20 54 72 69 f trigger.** Tri
20ee0 67 67 65 72 50 72 67 2e 70 54 72 69 67 67 65 72 ggerPrg.pTrigger
20ef0 2c 20 61 73 73 75 6d 69 6e 67 20 61 20 64 65 66 , assuming a def
20f00 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 ault ON CONFLICT
20f10 20 63 6c 61 75 73 65 20 6f 66 0a 2a 2a 20 54 72 clause of.** Tr
20f20 69 67 67 65 72 50 72 67 2e 6f 72 63 6f 6e 66 2c iggerPrg.orconf,
20f30 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 is stored in th
20f40 65 20 54 72 69 67 67 65 72 50 72 67 2e 70 50 72 e TriggerPrg.pPr
20f50 6f 67 72 61 6d 20 76 61 72 69 61 62 6c 65 2e 0a ogram variable..
20f60 2a 2a 20 54 68 65 20 50 61 72 73 65 2e 70 54 72 ** The Parse.pTr
20f70 69 67 67 65 72 50 72 67 20 6c 69 73 74 20 6e 65 iggerPrg list ne
20f80 76 65 72 20 63 6f 6e 74 61 69 6e 73 20 74 77 6f ver contains two
20f90 20 65 6e 74 72 69 65 73 20 77 69 74 68 20 74 68 entries with th
20fa0 65 20 73 61 6d 65 0a 2a 2a 20 76 61 6c 75 65 73 e same.** values
20fb0 20 66 6f 72 20 62 6f 74 68 20 70 54 72 69 67 67 for both pTrigg
20fc0 65 72 20 61 6e 64 20 6f 72 63 6f 6e 66 2e 0a 2a er and orconf..*
20fd0 2a 0a 2a 2a 20 54 68 65 20 54 72 69 67 67 65 72 *.** The Trigger
20fe0 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b 30 5d 20 Prg.aColmask[0]
20ff0 76 61 72 69 61 62 6c 65 20 69 73 20 73 65 74 20 variable is set
21000 74 6f 20 61 20 6d 61 73 6b 20 6f 66 20 6f 6c 64 to a mask of old
21010 2e 2a 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 61 63 .* columns.** ac
21020 63 65 73 73 65 64 20 28 6f 72 20 73 65 74 20 74 cessed (or set t
21030 6f 20 30 20 66 6f 72 20 74 72 69 67 67 65 72 73 o 0 for triggers
21040 20 66 69 72 65 64 20 61 73 20 61 20 72 65 73 75 fired as a resu
21050 6c 74 20 6f 66 20 49 4e 53 45 52 54 0a 2a 2a 20 lt of INSERT.**
21060 73 74 61 74 65 6d 65 6e 74 73 29 2e 20 53 69 6d statements). Sim
21070 69 6c 61 72 6c 79 2c 20 74 68 65 20 54 72 69 67 ilarly, the Trig
21080 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b gerPrg.aColmask[
21090 31 5d 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 1] variable is s
210a0 65 74 20 74 6f 0a 2a 2a 20 61 20 6d 61 73 6b 20 et to.** a mask
210b0 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d 6e 73 of new.* columns
210c0 20 75 73 65 64 20 62 79 20 74 68 65 20 70 72 6f used by the pro
210d0 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 gram..*/.struct
210e0 54 72 69 67 67 65 72 50 72 67 20 7b 0a 20 20 54 TriggerPrg {. T
210f0 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 65 72 rigger *pTrigger
21100 3b 20 20 20 20 20 20 2f 2a 20 54 72 69 67 67 65 ; /* Trigge
21110 72 20 74 68 69 73 20 70 72 6f 67 72 61 6d 20 77 r this program w
21120 61 73 20 63 6f 64 65 64 20 66 72 6f 6d 20 2a 2f as coded from */
21130 0a 20 20 54 72 69 67 67 65 72 50 72 67 20 2a 70 . TriggerPrg *p
21140 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 4e 65 Next; /* Ne
21150 78 74 20 65 6e 74 72 79 20 69 6e 20 50 61 72 73 xt entry in Pars
21160 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 6c 69 e.pTriggerPrg li
21170 73 74 20 2a 2f 0a 20 20 53 75 62 50 72 6f 67 72 st */. SubProgr
21180 61 6d 20 2a 70 50 72 6f 67 72 61 6d 3b 20 20 20 am *pProgram;
21190 2f 2a 20 50 72 6f 67 72 61 6d 20 69 6d 70 6c 65 /* Program imple
211a0 6d 65 6e 74 69 6e 67 20 70 54 72 69 67 67 65 72 menting pTrigger
211b0 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 20 69 6e 74 /orconf */. int
211c0 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 orconf;
211d0 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 /* Default
211e0 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 70 6f 6c 69 ON CONFLICT poli
211f0 63 79 20 2a 2f 0a 20 20 75 33 32 20 61 43 6f 6c cy */. u32 aCol
21200 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 20 20 20 20 mask[2];
21210 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 6f 6c 64 2e /* Masks of old.
21220 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d 6e 73 *, new.* columns
21230 20 61 63 63 65 73 73 65 64 20 2a 2f 0a 7d 3b 0a accessed */.};.
21240 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 44 62 4d 61 ./*.** The yDbMa
21250 73 6b 20 64 61 74 61 74 79 70 65 20 66 6f 72 20 sk datatype for
21260 74 68 65 20 62 69 74 6d 61 73 6b 20 6f 66 20 61 the bitmask of a
21270 6c 6c 20 61 74 74 61 63 68 65 64 20 64 61 74 61 ll attached data
21280 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 66 20 53 51 bases..*/.#if SQ
21290 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 LITE_MAX_ATTACHE
212a0 44 3e 33 30 0a 20 20 74 79 70 65 64 65 66 20 75 D>30. typedef u
212b0 6e 73 69 67 6e 65 64 20 63 68 61 72 20 79 44 62 nsigned char yDb
212c0 4d 61 73 6b 5b 28 53 51 4c 49 54 45 5f 4d 41 58 Mask[(SQLITE_MAX
212d0 5f 41 54 54 41 43 48 45 44 2b 39 29 2f 38 5d 3b _ATTACHED+9)/8];
212e0 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b .# define DbMask
212f0 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 28 28 Test(M,I) (((
21300 4d 29 5b 28 49 29 2f 38 5d 26 28 31 3c 3c 28 28 M)[(I)/8]&(1<<((
21310 49 29 26 37 29 29 29 21 3d 30 29 0a 23 20 64 65 I)&7)))!=0).# de
21320 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 6f 28 fine DbMaskZero(
21330 4d 29 20 20 20 20 20 20 6d 65 6d 73 65 74 28 28 M) memset((
21340 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 4d 29 29 0a M),0,sizeof(M)).
21350 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 53 # define DbMaskS
21360 65 74 28 4d 2c 49 29 20 20 20 20 20 28 4d 29 5b et(M,I) (M)[
21370 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c 28 28 49 29 (I)/8]|=(1<<((I)
21380 26 37 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 &7)).# define Db
21390 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 20 20 MaskAllZero(M)
213a0 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c sqlite3DbMaskAl
213b0 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 65 66 69 6e lZero(M).# defin
213c0 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 6f 28 e DbMaskNonZero(
213d0 4d 29 20 20 20 28 73 71 6c 69 74 65 33 44 62 4d M) (sqlite3DbM
213e0 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 3d 3d 30 askAllZero(M)==0
213f0 29 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 64 65 ).#else. typede
21400 66 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 79 f unsigned int y
21410 44 62 4d 61 73 6b 3b 0a 23 20 64 65 66 69 6e 65 DbMask;.# define
21420 20 44 62 4d 61 73 6b 54 65 73 74 28 4d 2c 49 29 DbMaskTest(M,I)
21430 20 20 20 20 28 28 28 4d 29 26 28 28 28 79 44 62 (((M)&(((yDb
21440 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 29 21 3d Mask)1)<<(I)))!=
21450 30 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 0).# define DbMa
21460 73 6b 5a 65 72 6f 28 4d 29 20 20 20 20 20 20 28 skZero(M) (
21470 4d 29 3d 30 0a 23 20 64 65 66 69 6e 65 20 44 62 M)=0.# define Db
21480 4d 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 MaskSet(M,I)
21490 20 28 4d 29 7c 3d 28 28 28 79 44 62 4d 61 73 6b (M)|=(((yDbMask
214a0 29 31 29 3c 3c 28 49 29 29 0a 23 20 64 65 66 69 )1)<<(I)).# defi
214b0 6e 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f ne DbMaskAllZero
214c0 28 4d 29 20 20 20 28 4d 29 3d 3d 30 0a 23 20 64 (M) (M)==0.# d
214d0 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a efine DbMaskNonZ
214e0 65 72 6f 28 4d 29 20 20 20 28 4d 29 21 3d 30 0a ero(M) (M)!=0.
214f0 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e #endif../*.** An
21500 20 53 51 4c 20 70 61 72 73 65 72 20 63 6f 6e 74 SQL parser cont
21510 65 78 74 2e 20 20 41 20 63 6f 70 79 20 6f 66 20 ext. A copy of
21520 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 69 this structure i
21530 73 20 70 61 73 73 65 64 20 74 68 72 6f 75 67 68 s passed through
21540 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 72 20 61 .** the parser a
21550 6e 64 20 64 6f 77 6e 20 69 6e 74 6f 20 61 6c 6c nd down into all
21560 20 74 68 65 20 70 61 72 73 65 72 20 61 63 74 69 the parser acti
21570 6f 6e 20 72 6f 75 74 69 6e 65 20 69 6e 20 6f 72 on routine in or
21580 64 65 72 20 74 6f 0a 2a 2a 20 63 61 72 72 79 20 der to.** carry
21590 61 72 6f 75 6e 64 20 69 6e 66 6f 72 6d 61 74 69 around informati
215a0 6f 6e 20 74 68 61 74 20 69 73 20 67 6c 6f 62 61 on that is globa
215b0 6c 20 74 6f 20 74 68 65 20 65 6e 74 69 72 65 20 l to the entire
215c0 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 parse..**.** The
215d0 20 73 74 72 75 63 74 75 72 65 20 69 73 20 64 69 structure is di
215e0 76 69 64 65 64 20 69 6e 74 6f 20 74 77 6f 20 70 vided into two p
215f0 61 72 74 73 2e 20 20 57 68 65 6e 20 74 68 65 20 arts. When the
21600 70 61 72 73 65 72 20 61 6e 64 20 63 6f 64 65 0a parser and code.
21610 2a 2a 20 67 65 6e 65 72 61 74 65 20 63 61 6c 6c ** generate call
21620 20 74 68 65 6d 73 65 6c 76 65 73 20 72 65 63 75 themselves recu
21630 72 73 69 76 65 6c 79 2c 20 74 68 65 20 66 69 72 rsively, the fir
21640 73 74 20 70 61 72 74 20 6f 66 20 74 68 65 20 73 st part of the s
21650 74 72 75 63 74 75 72 65 0a 2a 2a 20 69 73 20 63 tructure.** is c
21660 6f 6e 73 74 61 6e 74 20 62 75 74 20 74 68 65 20 onstant but the
21670 73 65 63 6f 6e 64 20 70 61 72 74 20 69 73 20 72 second part is r
21680 65 73 65 74 20 61 74 20 74 68 65 20 62 65 67 69 eset at the begi
21690 6e 6e 69 6e 67 20 61 6e 64 20 65 6e 64 20 6f 66 nning and end of
216a0 0a 2a 2a 20 65 61 63 68 20 72 65 63 75 72 73 69 .** each recursi
216b0 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6e 54 on..**.** The nT
216c0 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 20 61 54 61 ableLock and aTa
216d0 62 6c 65 4c 6f 63 6b 20 76 61 72 69 61 62 6c 65 bleLock variable
216e0 73 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 64 20 s are only used
216f0 69 66 20 74 68 65 20 73 68 61 72 65 64 2d 63 61 if the shared-ca
21700 63 68 65 0a 2a 2a 20 66 65 61 74 75 72 65 20 69 che.** feature i
21710 73 20 65 6e 61 62 6c 65 64 20 28 69 66 20 73 71 s enabled (if sq
21720 6c 69 74 65 33 54 73 64 28 29 2d 3e 75 73 65 53 lite3Tsd()->useS
21730 68 61 72 65 64 44 61 74 61 20 69 73 20 74 72 75 haredData is tru
21740 65 29 2e 20 54 68 65 79 20 61 72 65 0a 2a 2a 20 e). They are.**
21750 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 used to store th
21760 65 20 73 65 74 20 6f 66 20 74 61 62 6c 65 2d 6c e set of table-l
21770 6f 63 6b 73 20 72 65 71 75 69 72 65 64 20 62 79 ocks required by
21780 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 20 62 the statement b
21790 65 69 6e 67 0a 2a 2a 20 63 6f 6d 70 69 6c 65 64 eing.** compiled
217a0 2e 20 46 75 6e 63 74 69 6f 6e 20 73 71 6c 69 74 . Function sqlit
217b0 65 33 54 61 62 6c 65 4c 6f 63 6b 28 29 20 69 73 e3TableLock() is
217c0 20 75 73 65 64 20 74 6f 20 61 64 64 20 65 6e 74 used to add ent
217d0 72 69 65 73 20 74 6f 20 74 68 65 0a 2a 2a 20 6c ries to the.** l
217e0 69 73 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 50 ist..*/.struct P
217f0 61 72 73 65 20 7b 0a 20 20 73 71 6c 69 74 65 33 arse {. sqlite3
21800 20 2a 64 62 3b 20 20 20 20 20 20 20 20 20 2f 2a *db; /*
21810 20 54 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 The main databa
21820 73 65 20 73 74 72 75 63 74 75 72 65 20 2a 2f 0a se structure */.
21830 20 20 63 68 61 72 20 2a 7a 45 72 72 4d 73 67 3b char *zErrMsg;
21840 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 72 72 /* An err
21850 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f 0a 20 20 or message */.
21860 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 20 20 Vdbe *pVdbe;
21870 20 20 20 20 20 2f 2a 20 41 6e 20 65 6e 67 69 6e /* An engin
21880 65 20 66 6f 72 20 65 78 65 63 75 74 69 6e 67 20 e for executing
21890 64 61 74 61 62 61 73 65 20 62 79 74 65 63 6f 64 database bytecod
218a0 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 20 e */. int rc;
218b0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 /* R
218c0 65 74 75 72 6e 20 63 6f 64 65 20 66 72 6f 6d 20 eturn code from
218d0 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a 20 20 75 execution */. u
218e0 38 20 63 6f 6c 4e 61 6d 65 73 53 65 74 3b 20 20 8 colNamesSet;
218f0 20 20 20 20 2f 2a 20 54 52 55 45 20 61 66 74 65 /* TRUE afte
21900 72 20 4f 50 5f 43 6f 6c 75 6d 6e 4e 61 6d 65 20 r OP_ColumnName
21910 68 61 73 20 62 65 65 6e 20 69 73 73 75 65 64 20 has been issued
21920 74 6f 20 70 56 64 62 65 20 2a 2f 0a 20 20 75 38 to pVdbe */. u8
21930 20 63 68 65 63 6b 53 63 68 65 6d 61 3b 20 20 20 checkSchema;
21940 20 20 20 2f 2a 20 43 61 75 73 65 73 20 73 63 68 /* Causes sch
21950 65 6d 61 20 63 6f 6f 6b 69 65 20 63 68 65 63 6b ema cookie check
21960 20 61 66 74 65 72 20 61 6e 20 65 72 72 6f 72 20 after an error
21970 2a 2f 0a 20 20 75 38 20 6e 65 73 74 65 64 3b 20 */. u8 nested;
21980 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
21990 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 63 61 ber of nested ca
219a0 6c 6c 73 20 74 6f 20 74 68 65 20 70 61 72 73 65 lls to the parse
219b0 72 2f 63 6f 64 65 20 67 65 6e 65 72 61 74 6f 72 r/code generator
219c0 20 2a 2f 0a 20 20 75 38 20 6e 54 65 6d 70 52 65 */. u8 nTempRe
219d0 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 g; /* Nu
219e0 6d 62 65 72 20 6f 66 20 74 65 6d 70 6f 72 61 72 mber of temporar
219f0 79 20 72 65 67 69 73 74 65 72 73 20 69 6e 20 61 y registers in a
21a00 54 65 6d 70 52 65 67 5b 5d 20 2a 2f 0a 20 20 75 TempReg[] */. u
21a10 38 20 69 73 4d 75 6c 74 69 57 72 69 74 65 3b 20 8 isMultiWrite;
21a20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 /* True if s
21a30 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 6d 6f 64 tatement may mod
21a40 69 66 79 2f 69 6e 73 65 72 74 20 6d 75 6c 74 69 ify/insert multi
21a50 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 20 20 75 38 ple rows */. u8
21a60 20 6d 61 79 41 62 6f 72 74 3b 20 20 20 20 20 20 mayAbort;
21a70 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 74 /* True if st
21a80 61 74 65 6d 65 6e 74 20 6d 61 79 20 74 68 72 6f atement may thro
21a90 77 20 61 6e 20 41 42 4f 52 54 20 65 78 63 65 70 w an ABORT excep
21aa0 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 68 61 73 tion */. u8 has
21ab0 43 6f 6d 70 6f 75 6e 64 3b 20 20 20 20 20 20 2f Compound; /
21ac0 2a 20 4e 65 65 64 20 74 6f 20 69 6e 76 6f 6b 65 * Need to invoke
21ad0 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 convertCompound
21ae0 53 65 6c 65 63 74 54 6f 53 75 62 71 75 65 72 79 SelectToSubquery
21af0 28 29 20 2a 2f 0a 20 20 75 38 20 6f 6b 43 6f 6e () */. u8 okCon
21b00 73 74 46 61 63 74 6f 72 3b 20 20 20 20 2f 2a 20 stFactor; /*
21b10 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 6f 75 74 OK to factor out
21b20 20 63 6f 6e 73 74 61 6e 74 73 20 2a 2f 0a 20 20 constants */.
21b30 75 38 20 64 69 73 61 62 6c 65 4c 6f 6f 6b 61 73 u8 disableLookas
21b40 69 64 65 3b 20 2f 2a 20 4e 75 6d 62 65 72 20 6f ide; /* Number o
21b50 66 20 74 69 6d 65 73 20 6c 6f 6f 6b 61 73 69 64 f times lookasid
21b60 65 20 68 61 73 20 62 65 65 6e 20 64 69 73 61 62 e has been disab
21b70 6c 65 64 20 2a 2f 0a 20 20 75 38 20 64 69 73 61 led */. u8 disa
21b80 62 6c 65 56 74 61 62 3b 20 20 20 20 20 20 2f 2a bleVtab; /*
21b90 20 44 69 73 61 62 6c 65 20 61 6c 6c 20 76 69 72 Disable all vir
21ba0 74 75 61 6c 20 74 61 62 6c 65 73 20 66 6f 72 20 tual tables for
21bb0 74 68 69 73 20 70 61 72 73 65 20 2a 2f 0a 20 20 this parse */.
21bc0 69 6e 74 20 6e 52 61 6e 67 65 52 65 67 3b 20 20 int nRangeReg;
21bd0 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 /* Size of
21be0 74 68 65 20 74 65 6d 70 6f 72 61 72 79 20 72 65 the temporary re
21bf0 67 69 73 74 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a gister block */.
21c00 20 20 69 6e 74 20 69 52 61 6e 67 65 52 65 67 3b int iRangeReg;
21c10 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 /* First
21c20 72 65 67 69 73 74 65 72 20 69 6e 20 74 65 6d 70 register in temp
21c30 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 20 62 orary register b
21c40 6c 6f 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 lock */. int nE
21c50 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f rr; /
21c60 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 72 72 6f * Number of erro
21c70 72 73 20 73 65 65 6e 20 2a 2f 0a 20 20 69 6e 74 rs seen */. int
21c80 20 6e 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 nTab;
21c90 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 /* Number of p
21ca0 72 65 76 69 6f 75 73 6c 79 20 61 6c 6c 6f 63 61 reviously alloca
21cb0 74 65 64 20 56 44 42 45 20 63 75 72 73 6f 72 73 ted VDBE cursors
21cc0 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 65 6d 3b 20 */. int nMem;
21cd0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
21ce0 6d 62 65 72 20 6f 66 20 6d 65 6d 6f 72 79 20 63 mber of memory c
21cf0 65 6c 6c 73 20 75 73 65 64 20 73 6f 20 66 61 72 ells used so far
21d00 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 4f 70 41 6c */. int szOpAl
21d10 6c 6f 63 3b 20 20 20 20 20 20 20 2f 2a 20 42 79 loc; /* By
21d20 74 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 73 70 tes of memory sp
21d30 61 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f ace allocated fo
21d40 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 2a 2f 0a r Vdbe.aOp[] */.
21d50 20 20 69 6e 74 20 69 53 65 6c 66 54 61 62 3b 20 int iSelfTab;
21d60 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 /* Table
21d70 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
21d80 61 6e 20 69 6e 64 65 78 20 6f 6e 20 65 78 70 72 an index on expr
21d90 2c 20 6f 72 20 6e 65 67 61 74 69 76 65 0a 20 20 , or negative.
21da0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21db0 20 20 20 20 20 2a 2a 20 6f 66 20 74 68 65 20 62 ** of the b
21dc0 61 73 65 20 72 65 67 69 73 74 65 72 20 64 75 72 ase register dur
21dd0 69 6e 67 20 63 68 65 63 6b 2d 63 6f 6e 73 74 72 ing check-constr
21de0 61 69 6e 74 20 65 76 61 6c 20 2a 2f 0a 20 20 69 aint eval */. i
21df0 6e 74 20 6e 4c 61 62 65 6c 3b 20 20 20 20 20 20 nt nLabel;
21e00 20 20 20 20 2f 2a 20 54 68 65 20 2a 6e 65 67 61 /* The *nega
21e10 74 69 76 65 2a 20 6f 66 20 74 68 65 20 6e 75 6d tive* of the num
21e20 62 65 72 20 6f 66 20 6c 61 62 65 6c 73 20 75 73 ber of labels us
21e30 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 61 62 ed */. int nLab
21e40 65 6c 41 6c 6c 6f 63 3b 20 20 20 20 20 2f 2a 20 elAlloc; /*
21e50 4e 75 6d 62 65 72 20 6f 66 20 73 6c 6f 74 73 20 Number of slots
21e60 69 6e 20 61 4c 61 62 65 6c 20 2a 2f 0a 20 20 69 in aLabel */. i
21e70 6e 74 20 2a 61 4c 61 62 65 6c 3b 20 20 20 20 20 nt *aLabel;
21e80 20 20 20 20 2f 2a 20 53 70 61 63 65 20 74 6f 20 /* Space to
21e90 68 6f 6c 64 20 74 68 65 20 6c 61 62 65 6c 73 20 hold the labels
21ea0 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
21eb0 43 6f 6e 73 74 45 78 70 72 3b 2f 2a 20 43 6f 6e ConstExpr;/* Con
21ec0 73 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e stant expression
21ed0 73 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 63 6f 6e s */. Token con
21ee0 73 74 72 61 69 6e 74 4e 61 6d 65 3b 2f 2a 20 4e straintName;/* N
21ef0 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6e 73 74 ame of the const
21f00 72 61 69 6e 74 20 63 75 72 72 65 6e 74 6c 79 20 raint currently
21f10 62 65 69 6e 67 20 70 61 72 73 65 64 20 2a 2f 0a being parsed */.
21f20 20 20 79 44 62 4d 61 73 6b 20 77 72 69 74 65 4d yDbMask writeM
21f30 61 73 6b 3b 20 20 20 2f 2a 20 53 74 61 72 74 20 ask; /* Start
21f40 61 20 77 72 69 74 65 20 74 72 61 6e 73 61 63 74 a write transact
21f50 69 6f 6e 20 6f 6e 20 74 68 65 73 65 20 64 61 74 ion on these dat
21f60 61 62 61 73 65 73 20 2a 2f 0a 20 20 79 44 62 4d abases */. yDbM
21f70 61 73 6b 20 63 6f 6f 6b 69 65 4d 61 73 6b 3b 20 ask cookieMask;
21f80 20 2f 2a 20 42 69 74 6d 61 73 6b 20 6f 66 20 73 /* Bitmask of s
21f90 63 68 65 6d 61 20 76 65 72 69 66 69 65 64 20 64 chema verified d
21fa0 61 74 61 62 61 73 65 73 20 2a 2f 0a 20 20 69 6e atabases */. in
21fb0 74 20 72 65 67 52 6f 77 69 64 3b 20 20 20 20 20 t regRowid;
21fc0 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 /* Register h
21fd0 6f 6c 64 69 6e 67 20 72 6f 77 69 64 20 6f 66 20 olding rowid of
21fe0 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 6e 74 CREATE TABLE ent
21ff0 72 79 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 52 ry */. int regR
22000 6f 6f 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 oot; /*
22010 52 65 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 Register holding
22020 20 72 6f 6f 74 20 70 61 67 65 20 6e 75 6d 62 65 root page numbe
22030 72 20 66 6f 72 20 6e 65 77 20 6f 62 6a 65 63 74 r for new object
22040 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 78 41 s */. int nMaxA
22050 72 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4d rg; /* M
22060 61 78 20 61 72 67 73 20 70 61 73 73 65 64 20 74 ax args passed t
22070 6f 20 75 73 65 72 20 66 75 6e 63 74 69 6f 6e 20 o user function
22080 62 79 20 73 75 62 2d 70 72 6f 67 72 61 6d 20 2a by sub-program *
22090 2f 0a 20 20 69 6e 74 20 6e 53 65 6c 65 63 74 3b /. int nSelect;
220a0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
220b0 65 72 20 6f 66 20 53 45 4c 45 43 54 20 73 74 6d er of SELECT stm
220c0 74 73 2e 20 43 6f 75 6e 74 65 72 20 66 6f 72 20 ts. Counter for
220d0 53 65 6c 65 63 74 2e 73 65 6c 49 64 20 2a 2f 0a Select.selId */.
220e0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
220f0 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 45 MIT_SHARED_CACHE
22100 0a 20 20 69 6e 74 20 6e 54 61 62 6c 65 4c 6f 63 . int nTableLoc
22110 6b 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d k; /* Num
22120 62 65 72 20 6f 66 20 6c 6f 63 6b 73 20 69 6e 20 ber of locks in
22130 61 54 61 62 6c 65 4c 6f 63 6b 20 2a 2f 0a 20 20 aTableLock */.
22140 54 61 62 6c 65 4c 6f 63 6b 20 2a 61 54 61 62 6c TableLock *aTabl
22150 65 4c 6f 63 6b 3b 20 2f 2a 20 52 65 71 75 69 72 eLock; /* Requir
22160 65 64 20 74 61 62 6c 65 20 6c 6f 63 6b 73 20 66 ed table locks f
22170 6f 72 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 or shared-cache
22180 6d 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 mode */.#endif.
22190 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 41 AutoincInfo *pA
221a0 69 6e 63 3b 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 inc; /* Informa
221b0 74 69 6f 6e 20 61 62 6f 75 74 20 41 55 54 4f 49 tion about AUTOI
221c0 4e 43 52 45 4d 45 4e 54 20 63 6f 75 6e 74 65 72 NCREMENT counter
221d0 73 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 54 s */. Parse *pT
221e0 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a 20 50 oplevel; /* P
221f0 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 66 arse structure f
22200 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 6d 20 or main program
22210 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 54 (or NULL) */. T
22220 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 54 61 able *pTriggerTa
22230 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 72 69 b; /* Table tri
22240 67 67 65 72 73 20 61 72 65 20 62 65 69 6e 67 20 ggers are being
22250 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 20 50 coded for */. P
22260 61 72 73 65 20 2a 70 50 61 72 65 6e 74 50 61 72 arse *pParentPar
22270 73 65 3b 20 2f 2a 20 50 61 72 65 6e 74 20 70 61 se; /* Parent pa
22280 72 73 65 72 20 69 66 20 74 68 69 73 20 70 61 72 rser if this par
22290 73 65 72 20 69 73 20 6e 65 73 74 65 64 20 2a 2f ser is nested */
222a0 0a 20 20 69 6e 74 20 61 64 64 72 43 72 54 61 62 . int addrCrTab
222b0 3b 20 20 20 20 20 20 20 2f 2a 20 41 64 64 72 65 ; /* Addre
222c0 73 73 20 6f 66 20 4f 50 5f 43 72 65 61 74 65 42 ss of OP_CreateB
222d0 74 72 65 65 20 6f 70 63 6f 64 65 20 6f 6e 20 43 tree opcode on C
222e0 52 45 41 54 45 20 54 41 42 4c 45 20 2a 2f 0a 20 REATE TABLE */.
222f0 20 75 33 32 20 6e 51 75 65 72 79 4c 6f 6f 70 3b u32 nQueryLoop;
22300 20 20 20 20 20 20 2f 2a 20 45 73 74 20 6e 75 6d /* Est num
22310 62 65 72 20 6f 66 20 69 74 65 72 61 74 69 6f 6e ber of iteration
22320 73 20 6f 66 20 61 20 71 75 65 72 79 20 28 31 30 s of a query (10
22330 2a 6c 6f 67 32 28 4e 29 29 20 2a 2f 0a 20 20 75 *log2(N)) */. u
22340 33 32 20 6f 6c 64 6d 61 73 6b 3b 20 20 20 20 20 32 oldmask;
22350 20 20 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f /* Mask of o
22360 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 ld.* columns ref
22370 65 72 65 6e 63 65 64 20 2a 2f 0a 20 20 75 33 32 erenced */. u32
22380 20 6e 65 77 6d 61 73 6b 3b 20 20 20 20 20 20 20 newmask;
22390 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 6e 65 77 /* Mask of new
223a0 2e 2a 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 .* columns refer
223b0 65 6e 63 65 64 20 2a 2f 0a 20 20 75 38 20 65 54 enced */. u8 eT
223c0 72 69 67 67 65 72 4f 70 3b 20 20 20 20 20 20 20 riggerOp;
223d0 2f 2a 20 54 4b 5f 55 50 44 41 54 45 2c 20 54 4b /* TK_UPDATE, TK
223e0 5f 49 4e 53 45 52 54 20 6f 72 20 54 4b 5f 44 45 _INSERT or TK_DE
223f0 4c 45 54 45 20 2a 2f 0a 20 20 75 38 20 65 4f 72 LETE */. u8 eOr
22400 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 20 2f conf; /
22410 2a 20 44 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e * Default ON CON
22420 46 4c 49 43 54 20 70 6f 6c 69 63 79 20 66 6f 72 FLICT policy for
22430 20 74 72 69 67 67 65 72 20 73 74 65 70 73 20 2a trigger steps *
22440 2f 0a 20 20 75 38 20 64 69 73 61 62 6c 65 54 72 /. u8 disableTr
22450 69 67 67 65 72 73 3b 20 20 2f 2a 20 54 72 75 65 iggers; /* True
22460 20 74 6f 20 64 69 73 61 62 6c 65 20 74 72 69 67 to disable trig
22470 67 65 72 73 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a gers */.. /****
22480 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22490 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
224a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
224b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
224c0 2a 2a 2a 2a 2a 2a 0a 20 20 2a 2a 20 46 69 65 6c ******. ** Fiel
224d0 64 73 20 61 62 6f 76 65 20 6d 75 73 74 20 62 65 ds above must be
224e0 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 74 6f 20 initialized to
224f0 7a 65 72 6f 2e 20 20 54 68 65 20 66 69 65 6c 64 zero. The field
22500 73 20 74 68 61 74 20 66 6f 6c 6c 6f 77 2c 0a 20 s that follow,.
22510 20 2a 2a 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 ** down to the
22520 62 65 67 69 6e 6e 69 6e 67 20 6f 66 20 74 68 65 beginning of the
22530 20 72 65 63 75 72 73 69 76 65 20 73 65 63 74 69 recursive secti
22540 6f 6e 2c 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 on, do not need
22550 74 6f 20 62 65 0a 20 20 2a 2a 20 69 6e 69 74 69 to be. ** initi
22560 61 6c 69 7a 65 64 20 61 73 20 74 68 65 79 20 77 alized as they w
22570 69 6c 6c 20 62 65 20 73 65 74 20 62 65 66 6f 72 ill be set befor
22580 65 20 62 65 69 6e 67 20 75 73 65 64 2e 20 20 54 e being used. T
22590 68 65 20 62 6f 75 6e 64 61 72 79 20 69 73 0a 20 he boundary is.
225a0 20 2a 2a 20 64 65 74 65 72 6d 69 6e 65 64 20 62 ** determined b
225b0 79 20 6f 66 66 73 65 74 6f 66 28 50 61 72 73 65 y offsetof(Parse
225c0 2c 61 54 65 6d 70 52 65 67 29 2e 0a 20 20 2a 2a ,aTempReg).. **
225d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
225e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
225f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22600 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22610 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 69 6e 74 ********/.. int
22620 20 61 54 65 6d 70 52 65 67 5b 38 5d 3b 20 20 20 aTempReg[8];
22630 20 20 20 20 20 2f 2a 20 48 6f 6c 64 69 6e 67 20 /* Holding
22640 61 72 65 61 20 66 6f 72 20 74 65 6d 70 6f 72 61 area for tempora
22650 72 79 20 72 65 67 69 73 74 65 72 73 20 2a 2f 0a ry registers */.
22660 20 20 54 6f 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b Token sNameTok
22670 65 6e 3b 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b en; /* Tok
22680 65 6e 20 77 69 74 68 20 75 6e 71 75 61 6c 69 66 en with unqualif
22690 69 65 64 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 ied schema objec
226a0 74 20 6e 61 6d 65 20 2a 2f 0a 0a 20 20 2f 2a 2a t name */.. /**
226b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
226c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
226d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
226e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
226f0 2a 2a 2a 2a 2a 2a 0a 20 20 2a 2a 20 41 62 6f 76 ******. ** Abov
22700 65 20 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 65 e is constant be
22710 74 77 65 65 6e 20 72 65 63 75 72 73 69 6f 6e 73 tween recursions
22720 2e 20 20 42 65 6c 6f 77 20 69 73 20 72 65 73 65 . Below is rese
22730 74 20 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 t before and aft
22740 65 72 0a 20 20 2a 2a 20 65 61 63 68 20 72 65 63 er. ** each rec
22750 75 72 73 69 6f 6e 2e 20 20 54 68 65 20 62 6f 75 ursion. The bou
22760 6e 64 61 72 79 20 62 65 74 77 65 65 6e 20 74 68 ndary between th
22770 65 73 65 20 74 77 6f 20 72 65 67 69 6f 6e 73 20 ese two regions
22780 69 73 20 64 65 74 65 72 6d 69 6e 65 64 0a 20 20 is determined.
22790 2a 2a 20 75 73 69 6e 67 20 6f 66 66 73 65 74 6f ** using offseto
227a0 66 28 50 61 72 73 65 2c 73 4c 61 73 74 54 6f 6b f(Parse,sLastTok
227b0 65 6e 29 20 73 6f 20 74 68 65 20 73 4c 61 73 74 en) so the sLast
227c0 54 6f 6b 65 6e 20 66 69 65 6c 64 20 6d 75 73 74 Token field must
227d0 20 62 65 20 74 68 65 0a 20 20 2a 2a 20 66 69 72 be the. ** fir
227e0 73 74 20 66 69 65 6c 64 20 69 6e 20 74 68 65 20 st field in the
227f0 72 65 63 75 72 73 69 76 65 20 72 65 67 69 6f 6e recursive region
22800 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .. ************
22810 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22820 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22830 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
22840 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 ************/..
22850 20 54 6f 6b 65 6e 20 73 4c 61 73 74 54 6f 6b 65 Token sLastToke
22860 6e 3b 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 n; /* The
22870 6c 61 73 74 20 74 6f 6b 65 6e 20 70 61 72 73 65 last token parse
22880 64 20 2a 2f 0a 20 20 79 6e 56 61 72 20 6e 56 61 d */. ynVar nVa
22890 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
228a0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 27 3f /* Number of '?
228b0 27 20 76 61 72 69 61 62 6c 65 73 20 73 65 65 6e ' variables seen
228c0 20 69 6e 20 74 68 65 20 53 51 4c 20 73 6f 20 66 in the SQL so f
228d0 61 72 20 2a 2f 0a 20 20 75 38 20 69 50 6b 53 6f ar */. u8 iPkSo
228e0 72 74 4f 72 64 65 72 3b 20 20 20 20 20 20 20 20 rtOrder;
228f0 20 20 2f 2a 20 41 53 43 20 6f 72 20 44 45 53 43 /* ASC or DESC
22900 20 66 6f 72 20 49 4e 54 45 47 45 52 20 50 52 49 for INTEGER PRI
22910 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 75 38 MARY KEY */. u8
22920 20 65 78 70 6c 61 69 6e 3b 20 20 20 20 20 20 20 explain;
22930 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
22940 69 66 20 74 68 65 20 45 58 50 4c 41 49 4e 20 66 if the EXPLAIN f
22950 6c 61 67 20 69 73 20 66 6f 75 6e 64 20 6f 6e 20 lag is found on
22960 74 68 65 20 71 75 65 72 79 20 2a 2f 0a 23 69 66 the query */.#if
22970 20 21 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 !(defined(SQLIT
22980 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 E_OMIT_VIRTUALTA
22990 42 4c 45 29 20 26 26 20 64 65 66 69 6e 65 64 28 BLE) && defined(
229a0 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 4c 54 45 SQLITE_OMIT_ALTE
229b0 52 54 41 42 4c 45 29 29 0a 20 20 75 38 20 65 50 RTABLE)). u8 eP
229c0 61 72 73 65 4d 6f 64 65 3b 20 20 20 20 20 20 20 arseMode;
229d0 20 20 20 20 20 2f 2a 20 50 41 52 53 45 5f 4d 4f /* PARSE_MO
229e0 44 45 5f 58 58 58 20 63 6f 6e 73 74 61 6e 74 20 DE_XXX constant
229f0 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 */.#endif.#ifnde
22a00 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 f SQLITE_OMIT_VI
22a10 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 RTUALTABLE. int
22a20 20 6e 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 nVtabLock;
22a30 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
22a40 20 6f 66 20 76 69 72 74 75 61 6c 20 74 61 62 6c of virtual tabl
22a50 65 73 20 74 6f 20 6c 6f 63 6b 20 2a 2f 0a 23 65 es to lock */.#e
22a60 6e 64 69 66 0a 20 20 69 6e 74 20 6e 48 65 69 67 ndif. int nHeig
22a70 68 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ht;
22a80 20 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 74 /* Expression t
22a90 72 65 65 20 68 65 69 67 68 74 20 6f 66 20 63 75 ree height of cu
22aa0 72 72 65 6e 74 20 73 75 62 2d 73 65 6c 65 63 74 rrent sub-select
22ab0 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
22ac0 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a TE_OMIT_EXPLAIN.
22ad0 20 20 69 6e 74 20 61 64 64 72 45 78 70 6c 61 69 int addrExplai
22ae0 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 n; /* A
22af0 64 64 72 65 73 73 20 6f 66 20 63 75 72 72 65 6e ddress of curren
22b00 74 20 4f 50 5f 45 78 70 6c 61 69 6e 20 6f 70 63 t OP_Explain opc
22b10 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 ode */.#endif.
22b20 56 4c 69 73 74 20 2a 70 56 4c 69 73 74 3b 20 20 VList *pVList;
22b30 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 70 /* Map
22b40 70 69 6e 67 20 62 65 74 77 65 65 6e 20 76 61 72 ping between var
22b50 69 61 62 6c 65 20 6e 61 6d 65 73 20 61 6e 64 20 iable names and
22b60 6e 75 6d 62 65 72 73 20 2a 2f 0a 20 20 56 64 62 numbers */. Vdb
22b70 65 20 2a 70 52 65 70 72 65 70 61 72 65 3b 20 20 e *pReprepare;
22b80 20 20 20 20 20 20 20 2f 2a 20 56 4d 20 62 65 69 /* VM bei
22b90 6e 67 20 72 65 70 72 65 70 61 72 65 64 20 28 73 ng reprepared (s
22ba0 71 6c 69 74 65 33 52 65 70 72 65 70 61 72 65 28 qlite3Reprepare(
22bb0 29 29 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 )) */. const ch
22bc0 61 72 20 2a 7a 54 61 69 6c 3b 20 20 20 20 20 20 ar *zTail;
22bd0 20 20 2f 2a 20 41 6c 6c 20 53 51 4c 20 74 65 78 /* All SQL tex
22be0 74 20 70 61 73 74 20 74 68 65 20 6c 61 73 74 20 t past the last
22bf0 73 65 6d 69 63 6f 6c 6f 6e 20 70 61 72 73 65 64 semicolon parsed
22c00 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 4e 65 */. Table *pNe
22c10 77 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 wTable;
22c20 2f 2a 20 41 20 74 61 62 6c 65 20 62 65 69 6e 67 /* A table being
22c30 20 63 6f 6e 73 74 72 75 63 74 65 64 20 62 79 20 constructed by
22c40 43 52 45 41 54 45 20 54 41 42 4c 45 20 2a 2f 0a CREATE TABLE */.
22c50 20 20 49 6e 64 65 78 20 2a 70 4e 65 77 49 6e 64 Index *pNewInd
22c60 65 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 ex; /* A
22c70 6e 20 69 6e 64 65 78 20 62 65 69 6e 67 20 63 6f n index being co
22c80 6e 73 74 72 75 63 74 65 64 20 62 79 20 43 52 45 nstructed by CRE
22c90 41 54 45 20 49 4e 44 45 58 2e 0a 20 20 20 20 20 ATE INDEX..
22ca0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22cb0 20 20 20 20 20 20 20 2a 2a 20 41 6c 73 6f 20 75 ** Also u
22cc0 73 65 64 20 74 6f 20 68 6f 6c 64 20 72 65 64 75 sed to hold redu
22cd0 6e 64 61 6e 74 20 55 4e 49 51 55 45 20 63 6f 6e ndant UNIQUE con
22ce0 73 74 72 61 69 6e 74 73 0a 20 20 20 20 20 20 20 straints.
22cf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22d00 20 20 20 20 20 2a 2a 20 64 75 72 69 6e 67 20 61 ** during a
22d10 20 52 45 4e 41 4d 45 20 43 4f 4c 55 4d 4e 20 2a RENAME COLUMN *
22d20 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e 65 /. Trigger *pNe
22d30 77 54 72 69 67 67 65 72 3b 20 20 20 20 20 2f 2a wTrigger; /*
22d40 20 54 72 69 67 67 65 72 20 75 6e 64 65 72 20 63 Trigger under c
22d50 6f 6e 73 74 72 75 63 74 20 62 79 20 61 20 43 52 onstruct by a CR
22d60 45 41 54 45 20 54 52 49 47 47 45 52 20 2a 2f 0a EATE TRIGGER */.
22d70 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 const char *zA
22d80 75 74 68 43 6f 6e 74 65 78 74 3b 20 2f 2a 20 54 uthContext; /* T
22d90 68 65 20 36 74 68 20 70 61 72 61 6d 65 74 65 72 he 6th parameter
22da0 20 74 6f 20 64 62 2d 3e 78 41 75 74 68 20 63 61 to db->xAuth ca
22db0 6c 6c 62 61 63 6b 73 20 2a 2f 0a 23 69 66 6e 64 llbacks */.#ifnd
22dc0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 ef SQLITE_OMIT_V
22dd0 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 54 6f IRTUALTABLE. To
22de0 6b 65 6e 20 73 41 72 67 3b 20 20 20 20 20 20 20 ken sArg;
22df0 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6d 70 6c /* Compl
22e00 65 74 65 20 74 65 78 74 20 6f 66 20 61 20 6d 6f ete text of a mo
22e10 64 75 6c 65 20 61 72 67 75 6d 65 6e 74 20 2a 2f dule argument */
22e20 0a 20 20 54 61 62 6c 65 20 2a 2a 61 70 56 74 61 . Table **apVta
22e30 62 4c 6f 63 6b 3b 20 20 20 20 20 20 20 2f 2a 20 bLock; /*
22e40 50 6f 69 6e 74 65 72 20 74 6f 20 76 69 72 74 75 Pointer to virtu
22e50 61 6c 20 74 61 62 6c 65 73 20 6e 65 65 64 69 6e al tables needin
22e60 67 20 6c 6f 63 6b 69 6e 67 20 2a 2f 0a 23 65 6e g locking */.#en
22e70 64 69 66 0a 20 20 54 61 62 6c 65 20 2a 70 5a 6f dif. Table *pZo
22e80 6d 62 69 65 54 61 62 3b 20 20 20 20 20 20 20 20 mbieTab;
22e90 2f 2a 20 4c 69 73 74 20 6f 66 20 54 61 62 6c 65 /* List of Table
22ea0 20 6f 62 6a 65 63 74 73 20 74 6f 20 64 65 6c 65 objects to dele
22eb0 74 65 20 61 66 74 65 72 20 63 6f 64 65 20 67 65 te after code ge
22ec0 6e 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 72 n */. TriggerPr
22ed0 67 20 2a 70 54 72 69 67 67 65 72 50 72 67 3b 20 g *pTriggerPrg;
22ee0 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 /* Linked list
22ef0 6f 66 20 63 6f 64 65 64 20 74 72 69 67 67 65 72 of coded trigger
22f00 73 20 2a 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 s */. With *pWi
22f10 74 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 th;
22f20 20 2f 2a 20 43 75 72 72 65 6e 74 20 57 49 54 48 /* Current WITH
22f30 20 63 6c 61 75 73 65 2c 20 6f 72 20 4e 55 4c 4c clause, or NULL
22f40 20 2a 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 74 */. With *pWit
22f50 68 54 6f 46 72 65 65 3b 20 20 20 20 20 20 20 20 hToFree;
22f60 2f 2a 20 46 72 65 65 20 74 68 69 73 20 57 49 54 /* Free this WIT
22f70 48 20 6f 62 6a 65 63 74 20 61 74 20 74 68 65 20 H object at the
22f80 65 6e 64 20 6f 66 20 74 68 65 20 70 61 72 73 65 end of the parse
22f90 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
22fa0 54 45 5f 4f 4d 49 54 5f 41 4c 54 45 52 54 41 42 TE_OMIT_ALTERTAB
22fb0 4c 45 0a 20 20 52 65 6e 61 6d 65 54 6f 6b 65 6e LE. RenameToken
22fc0 20 2a 70 52 65 6e 61 6d 65 3b 20 20 20 20 20 2f *pRename; /
22fd0 2a 20 54 6f 6b 65 6e 73 20 73 75 62 6a 65 63 74 * Tokens subject
22fe0 20 74 6f 20 72 65 6e 61 6d 69 6e 67 20 62 79 20 to renaming by
22ff0 41 4c 54 45 52 20 54 41 42 4c 45 20 2a 2f 0a 23 ALTER TABLE */.#
23000 65 6e 64 69 66 0a 7d 3b 0a 0a 23 64 65 66 69 6e endif.};..#defin
23010 65 20 50 41 52 53 45 5f 4d 4f 44 45 5f 4e 4f 52 e PARSE_MODE_NOR
23020 4d 41 4c 20 20 20 20 20 20 20 20 30 0a 23 64 65 MAL 0.#de
23030 66 69 6e 65 20 50 41 52 53 45 5f 4d 4f 44 45 5f fine PARSE_MODE_
23040 44 45 43 4c 41 52 45 5f 56 54 41 42 20 20 31 0a DECLARE_VTAB 1.
23050 23 64 65 66 69 6e 65 20 50 41 52 53 45 5f 4d 4f #define PARSE_MO
23060 44 45 5f 52 45 4e 41 4d 45 5f 43 4f 4c 55 4d 4e DE_RENAME_COLUMN
23070 20 32 0a 23 64 65 66 69 6e 65 20 50 41 52 53 45 2.#define PARSE
23080 5f 4d 4f 44 45 5f 52 45 4e 41 4d 45 5f 54 41 42 _MODE_RENAME_TAB
23090 4c 45 20 20 33 0a 0a 2f 2a 0a 2a 2a 20 53 69 7a LE 3../*.** Siz
230a0 65 73 20 61 6e 64 20 70 6f 69 6e 74 65 72 73 20 es and pointers
230b0 6f 66 20 76 61 72 69 6f 75 73 20 70 61 72 74 73 of various parts
230c0 20 6f 66 20 74 68 65 20 50 61 72 73 65 20 6f 62 of the Parse ob
230d0 6a 65 63 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ject..*/.#define
230e0 20 50 41 52 53 45 5f 48 44 52 5f 53 5a 20 6f 66 PARSE_HDR_SZ of
230f0 66 73 65 74 6f 66 28 50 61 72 73 65 2c 61 54 65 fsetof(Parse,aTe
23100 6d 70 52 65 67 29 20 2f 2a 20 52 65 63 75 72 73 mpReg) /* Recurs
23110 69 76 65 20 70 61 72 74 20 77 2f 6f 20 61 43 6f ive part w/o aCo
23120 6c 43 61 63 68 65 2a 2f 0a 23 64 65 66 69 6e 65 lCache*/.#define
23130 20 50 41 52 53 45 5f 52 45 43 55 52 53 45 5f 53 PARSE_RECURSE_S
23140 5a 20 6f 66 66 73 65 74 6f 66 28 50 61 72 73 65 Z offsetof(Parse
23150 2c 73 4c 61 73 74 54 6f 6b 65 6e 29 20 20 20 20 ,sLastToken)
23160 2f 2a 20 52 65 63 75 72 73 69 76 65 20 70 61 72 /* Recursive par
23170 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 52 t */.#define PAR
23180 53 45 5f 54 41 49 4c 5f 53 5a 20 28 73 69 7a 65 SE_TAIL_SZ (size
23190 6f 66 28 50 61 72 73 65 29 2d 50 41 52 53 45 5f of(Parse)-PARSE_
231a0 52 45 43 55 52 53 45 5f 53 5a 29 20 2f 2a 20 4e RECURSE_SZ) /* N
231b0 6f 6e 2d 72 65 63 75 72 73 69 76 65 20 70 61 72 on-recursive par
231c0 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 50 41 52 t */.#define PAR
231d0 53 45 5f 54 41 49 4c 28 58 29 20 28 28 28 63 68 SE_TAIL(X) (((ch
231e0 61 72 2a 29 28 58 29 29 2b 50 41 52 53 45 5f 52 ar*)(X))+PARSE_R
231f0 45 43 55 52 53 45 5f 53 5a 29 20 20 2f 2a 20 50 ECURSE_SZ) /* P
23200 6f 69 6e 74 65 72 20 74 6f 20 74 61 69 6c 20 2a ointer to tail *
23210 2f 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 /../*.** Return
23220 74 72 75 65 20 69 66 20 63 75 72 72 65 6e 74 6c true if currentl
23230 79 20 69 6e 73 69 64 65 20 61 6e 20 73 71 6c 69 y inside an sqli
23240 74 65 33 5f 64 65 63 6c 61 72 65 5f 76 74 61 62 te3_declare_vtab
23250 28 29 20 63 61 6c 6c 2e 0a 2a 2f 0a 23 69 66 64 () call..*/.#ifd
23260 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 ef SQLITE_OMIT_V
23270 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 23 64 IRTUALTABLE. #d
23280 65 66 69 6e 65 20 49 4e 5f 44 45 43 4c 41 52 45 efine IN_DECLARE
23290 5f 56 54 41 42 20 30 0a 23 65 6c 73 65 0a 20 20 _VTAB 0.#else.
232a0 23 64 65 66 69 6e 65 20 49 4e 5f 44 45 43 4c 41 #define IN_DECLA
232b0 52 45 5f 56 54 41 42 20 28 70 50 61 72 73 65 2d RE_VTAB (pParse-
232c0 3e 65 50 61 72 73 65 4d 6f 64 65 3d 3d 50 41 52 >eParseMode==PAR
232d0 53 45 5f 4d 4f 44 45 5f 44 45 43 4c 41 52 45 5f SE_MODE_DECLARE_
232e0 56 54 41 42 29 0a 23 65 6e 64 69 66 0a 0a 23 69 VTAB).#endif..#i
232f0 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 f defined(SQLITE
23300 5f 4f 4d 49 54 5f 41 4c 54 45 52 54 41 42 4c 45 _OMIT_ALTERTABLE
23310 29 0a 20 20 23 64 65 66 69 6e 65 20 49 4e 5f 52 ). #define IN_R
23320 45 4e 41 4d 45 5f 4f 42 4a 45 43 54 20 30 0a 23 ENAME_OBJECT 0.#
23330 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 49 else. #define I
23340 4e 5f 52 45 4e 41 4d 45 5f 4f 42 4a 45 43 54 20 N_RENAME_OBJECT
23350 28 70 50 61 72 73 65 2d 3e 65 50 61 72 73 65 4d (pParse->eParseM
23360 6f 64 65 3e 3d 50 41 52 53 45 5f 4d 4f 44 45 5f ode>=PARSE_MODE_
23370 52 45 4e 41 4d 45 5f 43 4f 4c 55 4d 4e 29 0a 23 RENAME_COLUMN).#
23380 65 6e 64 69 66 0a 0a 23 69 66 20 64 65 66 69 6e endif..#if defin
23390 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 ed(SQLITE_OMIT_V
233a0 49 52 54 55 41 4c 54 41 42 4c 45 29 20 26 26 20 IRTUALTABLE) &&
233b0 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f defined(SQLITE_O
233c0 4d 49 54 5f 41 4c 54 45 52 54 41 42 4c 45 29 0a MIT_ALTERTABLE).
233d0 20 20 23 64 65 66 69 6e 65 20 49 4e 5f 53 50 45 #define IN_SPE
233e0 43 49 41 4c 5f 50 41 52 53 45 20 30 0a 23 65 6c CIAL_PARSE 0.#el
233f0 73 65 0a 20 20 23 64 65 66 69 6e 65 20 49 4e 5f se. #define IN_
23400 53 50 45 43 49 41 4c 5f 50 41 52 53 45 20 28 70 SPECIAL_PARSE (p
23410 50 61 72 73 65 2d 3e 65 50 61 72 73 65 4d 6f 64 Parse->eParseMod
23420 65 21 3d 50 41 52 53 45 5f 4d 4f 44 45 5f 4e 4f e!=PARSE_MODE_NO
23430 52 4d 41 4c 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a RMAL).#endif../*
23440 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
23450 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
23460 20 73 74 72 75 63 74 75 72 65 20 63 61 6e 20 62 structure can b
23470 65 20 64 65 63 6c 61 72 65 64 20 6f 6e 20 61 20 e declared on a
23480 73 74 61 63 6b 20 61 6e 64 20 75 73 65 64 0a 2a stack and used.*
23490 2a 20 74 6f 20 73 61 76 65 20 74 68 65 20 50 61 * to save the Pa
234a0 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 rse.zAuthContext
234b0 20 76 61 6c 75 65 20 73 6f 20 74 68 61 74 20 69 value so that i
234c0 74 20 63 61 6e 20 62 65 20 72 65 73 74 6f 72 65 t can be restore
234d0 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 73 74 72 75 d later..*/.stru
234e0 63 74 20 41 75 74 68 43 6f 6e 74 65 78 74 20 7b ct AuthContext {
234f0 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
23500 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 20 20 2f AuthContext; /
23510 2a 20 50 75 74 20 73 61 76 65 64 20 50 61 72 73 * Put saved Pars
23520 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 68 e.zAuthContext h
23530 65 72 65 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a ere */. Parse *
23540 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 pParse;
23550 20 20 20 20 20 2f 2a 20 54 68 65 20 50 61 72 73 /* The Pars
23560 65 20 73 74 72 75 63 74 75 72 65 20 2a 2f 0a 7d e structure */.}
23570 3b 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 66 69 65 6c ;../*.** Bitfiel
23580 64 20 66 6c 61 67 73 20 66 6f 72 20 50 35 20 76 d flags for P5 v
23590 61 6c 75 65 20 69 6e 20 76 61 72 69 6f 75 73 20 alue in various
235a0 6f 70 63 6f 64 65 73 2e 0a 2a 2a 0a 2a 2a 20 56 opcodes..**.** V
235b0 61 6c 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 alue constraints
235c0 20 28 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 (enforced via a
235d0 73 73 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 ssert()):.**
235e0 4f 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 OPFLAG_LENGTHARG
235f0 20 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 == SQLITE_FU
23600 4e 43 5f 4c 45 4e 47 54 48 0a 2a 2a 20 20 20 20 NC_LENGTH.**
23610 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 OPFLAG_TYPEOFARG
23620 20 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 == SQLITE_FU
23630 4e 43 5f 54 59 50 45 4f 46 0a 2a 2a 20 20 20 20 NC_TYPEOF.**
23640 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 OPFLAG_BULKCSR
23650 20 20 20 20 3d 3d 20 42 54 52 45 45 5f 42 55 4c == BTREE_BUL
23660 4b 4c 4f 41 44 0a 2a 2a 20 20 20 20 4f 50 46 4c KLOAD.** OPFL
23670 41 47 5f 53 45 45 4b 45 51 20 20 20 20 20 20 20 AG_SEEKEQ
23680 3d 3d 20 42 54 52 45 45 5f 53 45 45 4b 5f 45 51 == BTREE_SEEK_EQ
23690 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 47 5f 46 4f .** OPFLAG_FO
236a0 52 44 45 4c 45 54 45 20 20 20 20 3d 3d 20 42 54 RDELETE == BT
236b0 52 45 45 5f 46 4f 52 44 45 4c 45 54 45 0a 2a 2a REE_FORDELETE.**
236c0 20 20 20 20 4f 50 46 4c 41 47 5f 53 41 56 45 50 OPFLAG_SAVEP
236d0 4f 53 49 54 49 4f 4e 20 3d 3d 20 42 54 52 45 45 OSITION == BTREE
236e0 5f 53 41 56 45 50 4f 53 49 54 49 4f 4e 0a 2a 2a _SAVEPOSITION.**
236f0 20 20 20 20 4f 50 46 4c 41 47 5f 41 55 58 44 45 OPFLAG_AUXDE
23700 4c 45 54 45 20 20 20 20 3d 3d 20 42 54 52 45 45 LETE == BTREE
23710 5f 41 55 58 44 45 4c 45 54 45 0a 2a 2f 0a 23 64 _AUXDELETE.*/.#d
23720 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 43 48 efine OPFLAG_NCH
23730 41 4e 47 45 20 20 20 20 20 20 20 30 78 30 31 20 ANGE 0x01
23740 20 20 20 2f 2a 20 4f 50 5f 49 6e 73 65 72 74 3a /* OP_Insert:
23750 20 53 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 Set to update d
23760 62 2d 3e 6e 43 68 61 6e 67 65 20 2a 2f 0a 20 20 b->nChange */.
23770 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23780 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23790 20 20 20 2f 2a 20 41 6c 73 6f 20 75 73 65 64 20 /* Also used
237a0 69 6e 20 50 32 20 28 6e 6f 74 20 50 35 29 20 6f in P2 (not P5) o
237b0 66 20 4f 50 5f 44 65 6c 65 74 65 20 2a 2f 0a 23 f OP_Delete */.#
237c0 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 4f define OPFLAG_NO
237d0 43 48 4e 47 20 20 20 20 20 20 20 20 30 78 30 31 CHNG 0x01
237e0 20 20 20 20 2f 2a 20 4f 50 5f 56 43 6f 6c 75 6d /* OP_VColum
237f0 6e 20 6e 6f 63 68 61 6e 67 65 20 66 6f 72 20 55 n nochange for U
23800 50 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 PDATE */.#define
23810 20 4f 50 46 4c 41 47 5f 45 50 48 45 4d 20 20 20 OPFLAG_EPHEM
23820 20 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 0x01 /*
23830 20 4f 50 5f 43 6f 6c 75 6d 6e 3a 20 45 70 68 65 OP_Column: Ephe
23840 6d 65 72 61 6c 20 6f 75 74 70 75 74 20 69 73 20 meral output is
23850 6f 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 ok */.#define OP
23860 46 4c 41 47 5f 4c 41 53 54 52 4f 57 49 44 20 20 FLAG_LASTROWID
23870 20 20 20 30 78 32 30 20 20 20 20 2f 2a 20 53 65 0x20 /* Se
23880 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 2d 3e t to update db->
23890 6c 61 73 74 52 6f 77 69 64 20 2a 2f 0a 23 64 65 lastRowid */.#de
238a0 66 69 6e 65 20 4f 50 46 4c 41 47 5f 49 53 55 50 fine OPFLAG_ISUP
238b0 44 41 54 45 20 20 20 20 20 20 30 78 30 34 20 20 DATE 0x04
238c0 20 20 2f 2a 20 54 68 69 73 20 4f 50 5f 49 6e 73 /* This OP_Ins
238d0 65 72 74 20 69 73 20 61 6e 20 73 71 6c 20 55 50 ert is an sql UP
238e0 44 41 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 DATE */.#define
238f0 4f 50 46 4c 41 47 5f 41 50 50 45 4e 44 20 20 20 OPFLAG_APPEND
23900 20 20 20 20 20 30 78 30 38 20 20 20 20 2f 2a 20 0x08 /*
23910 54 68 69 73 20 69 73 20 6c 69 6b 65 6c 79 20 74 This is likely t
23920 6f 20 62 65 20 61 6e 20 61 70 70 65 6e 64 20 2a o be an append *
23930 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
23940 5f 55 53 45 53 45 45 4b 52 45 53 55 4c 54 20 30 _USESEEKRESULT 0
23950 78 31 30 20 20 20 20 2f 2a 20 54 72 79 20 74 6f x10 /* Try to
23960 20 61 76 6f 69 64 20 61 20 73 65 65 6b 20 69 6e avoid a seek in
23970 20 42 74 72 65 65 49 6e 73 65 72 74 28 29 20 2a BtreeInsert() *
23980 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
23990 5f 49 53 4e 4f 4f 50 20 20 20 20 20 20 20 20 30 _ISNOOP 0
239a0 78 34 30 20 20 20 20 2f 2a 20 4f 50 5f 44 65 6c x40 /* OP_Del
239b0 65 74 65 20 64 6f 65 73 20 70 72 65 2d 75 70 64 ete does pre-upd
239c0 61 74 65 2d 68 6f 6f 6b 20 6f 6e 6c 79 20 2a 2f ate-hook only */
239d0 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
239e0 4c 45 4e 47 54 48 41 52 47 20 20 20 20 20 30 78 LENGTHARG 0x
239f0 34 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 40 /* OP_Colu
23a00 6d 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 mn only used for
23a10 20 6c 65 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 length() */.#de
23a20 66 69 6e 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 fine OPFLAG_TYPE
23a30 4f 46 41 52 47 20 20 20 20 20 30 78 38 30 20 20 OFARG 0x80
23a40 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f /* OP_Column o
23a50 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 74 79 70 nly used for typ
23a60 65 6f 66 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 eof() */.#define
23a70 20 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 OPFLAG_BULKCSR
23a80 20 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 0x01 /*
23a90 20 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 OP_Open** used
23aa0 74 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 to open bulk cur
23ab0 73 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f sor */.#define O
23ac0 50 46 4c 41 47 5f 53 45 45 4b 45 51 20 20 20 20 PFLAG_SEEKEQ
23ad0 20 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 4f 0x02 /* O
23ae0 50 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 6f 72 20 P_Open** cursor
23af0 75 73 65 73 20 45 51 20 73 65 65 6b 20 6f 6e 6c uses EQ seek onl
23b00 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 y */.#define OPF
23b10 4c 41 47 5f 46 4f 52 44 45 4c 45 54 45 20 20 20 LAG_FORDELETE
23b20 20 20 30 78 30 38 20 20 20 20 2f 2a 20 4f 50 5f 0x08 /* OP_
23b30 4f 70 65 6e 20 73 68 6f 75 6c 64 20 75 73 65 20 Open should use
23b40 42 54 52 45 45 5f 46 4f 52 44 45 4c 45 54 45 20 BTREE_FORDELETE
23b50 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 */.#define OPFLA
23b60 47 5f 50 32 49 53 52 45 47 20 20 20 20 20 20 20 G_P2ISREG
23b70 30 78 31 30 20 20 20 20 2f 2a 20 50 32 20 74 6f 0x10 /* P2 to
23b80 20 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 61 20 OP_Open** is a
23b90 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 20 register number
23ba0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 */.#define OPFLA
23bb0 47 5f 50 45 52 4d 55 54 45 20 20 20 20 20 20 20 G_PERMUTE
23bc0 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 0x01 /* OP_Co
23bd0 6d 70 61 72 65 3a 20 75 73 65 20 74 68 65 20 70 mpare: use the p
23be0 65 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a 23 64 ermutation */.#d
23bf0 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 53 41 56 efine OPFLAG_SAV
23c00 45 50 4f 53 49 54 49 4f 4e 20 20 30 78 30 32 20 EPOSITION 0x02
23c10 20 20 20 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 2f /* OP_Delete/
23c20 49 6e 73 65 72 74 3a 20 73 61 76 65 20 63 75 72 Insert: save cur
23c30 73 6f 72 20 70 6f 73 20 2a 2f 0a 23 64 65 66 69 sor pos */.#defi
23c40 6e 65 20 4f 50 46 4c 41 47 5f 41 55 58 44 45 4c ne OPFLAG_AUXDEL
23c50 45 54 45 20 20 20 20 20 30 78 30 34 20 20 20 20 ETE 0x04
23c60 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 3a 20 69 6e /* OP_Delete: in
23c70 64 65 78 20 69 6e 20 61 20 44 45 4c 45 54 45 20 dex in a DELETE
23c80 6f 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 op */.#define OP
23c90 46 4c 41 47 5f 4e 4f 43 48 4e 47 5f 4d 41 47 49 FLAG_NOCHNG_MAGI
23ca0 43 20 20 30 78 36 64 20 20 20 20 2f 2a 20 4f 50 C 0x6d /* OP
23cb0 5f 4d 61 6b 65 52 65 63 6f 72 64 3a 20 73 65 72 _MakeRecord: ser
23cc0 69 61 6c 74 79 70 65 20 31 30 20 69 73 20 6f 6b ialtype 10 is ok
23cd0 20 2a 2f 0a 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 */../*. * Each
23ce0 74 72 69 67 67 65 72 20 70 72 65 73 65 6e 74 20 trigger present
23cf0 69 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 20 in the database
23d00 73 63 68 65 6d 61 20 69 73 20 73 74 6f 72 65 64 schema is stored
23d10 20 61 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 as an instance
23d20 6f 66 0a 20 2a 20 73 74 72 75 63 74 20 54 72 69 of. * struct Tri
23d30 67 67 65 72 2e 0a 20 2a 0a 20 2a 20 50 6f 69 6e gger.. *. * Poin
23d40 74 65 72 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 ters to instance
23d50 73 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 s of struct Trig
23d60 67 65 72 20 61 72 65 20 73 74 6f 72 65 64 20 69 ger are stored i
23d70 6e 20 74 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 n two ways.. * 1
23d80 2e 20 49 6e 20 74 68 65 20 22 74 72 69 67 48 61 . In the "trigHa
23d90 73 68 22 20 68 61 73 68 20 74 61 62 6c 65 20 28 sh" hash table (
23da0 70 61 72 74 20 6f 66 20 74 68 65 20 73 71 6c 69 part of the sqli
23db0 74 65 33 2a 20 74 68 61 74 20 72 65 70 72 65 73 te3* that repres
23dc0 65 6e 74 73 20 74 68 65 0a 20 2a 20 20 20 20 64 ents the. * d
23dd0 61 74 61 62 61 73 65 29 2e 20 54 68 69 73 20 61 atabase). This a
23de0 6c 6c 6f 77 73 20 54 72 69 67 67 65 72 20 73 74 llows Trigger st
23df0 72 75 63 74 75 72 65 73 20 74 6f 20 62 65 20 72 ructures to be r
23e00 65 74 72 69 65 76 65 64 20 62 79 20 6e 61 6d 65 etrieved by name
23e10 2e 0a 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 67 .. * 2. All trig
23e20 67 65 72 73 20 61 73 73 6f 63 69 61 74 65 64 20 gers associated
23e30 77 69 74 68 20 61 20 73 69 6e 67 6c 65 20 74 61 with a single ta
23e40 62 6c 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b 65 ble form a linke
23e50 64 20 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 68 d list, using th
23e60 65 0a 20 2a 20 20 20 20 70 4e 65 78 74 20 6d 65 e. * pNext me
23e70 6d 62 65 72 20 6f 66 20 73 74 72 75 63 74 20 54 mber of struct T
23e80 72 69 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 65 rigger. A pointe
23e90 72 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 65 r to the first e
23ea0 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 2a lement of the. *
23eb0 20 20 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 linked list
23ec0 69 73 20 73 74 6f 72 65 64 20 61 73 20 74 68 65 is stored as the
23ed0 20 22 70 54 72 69 67 67 65 72 22 20 6d 65 6d 62 "pTrigger" memb
23ee0 65 72 20 6f 66 20 74 68 65 20 61 73 73 6f 63 69 er of the associ
23ef0 61 74 65 64 0a 20 2a 20 20 20 20 73 74 72 75 63 ated. * struc
23f00 74 20 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 54 t Table.. *. * T
23f10 68 65 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d he "step_list" m
23f20 65 6d 62 65 72 20 70 6f 69 6e 74 73 20 74 6f 20 ember points to
23f30 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e the first elemen
23f40 74 20 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c 69 t of a linked li
23f50 73 74 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 st. * containing
23f60 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 the SQL stateme
23f70 6e 74 73 20 73 70 65 63 69 66 69 65 64 20 61 73 nts specified as
23f80 20 74 68 65 20 74 72 69 67 67 65 72 20 70 72 6f the trigger pro
23f90 67 72 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 74 gram.. */.struct
23fa0 20 54 72 69 67 67 65 72 20 7b 0a 20 20 63 68 61 Trigger {. cha
23fb0 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 r *zName;
23fc0 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d 65 /* The name
23fd0 20 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 20 of the trigger
23fe0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23ff0 20 20 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 72 */. char
24000 20 2a 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 *table;
24010 20 20 20 20 2f 2a 20 54 68 65 20 74 61 62 6c 65 /* The table
24020 20 6f 72 20 76 69 65 77 20 74 6f 20 77 68 69 63 or view to whic
24030 68 20 74 68 65 20 74 72 69 67 67 65 72 20 61 70 h the trigger ap
24040 70 6c 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f 70 plies */. u8 op
24050 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
24060 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f /* One of TK_
24070 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 DELETE, TK_UPDAT
24080 45 2c 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 20 E, TK_INSERT
24090 20 20 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 5f */. u8 tr_
240a0 74 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 tm;
240b0 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 47 /* One of TRIG
240c0 47 45 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 47 GER_BEFORE, TRIG
240d0 47 45 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 45 GER_AFTER */. E
240e0 78 70 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 20 xpr *pWhen;
240f0 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 /* The WH
24100 45 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 EN clause of the
24110 20 65 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 79 expression (may
24120 20 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 49 be NULL) */. I
24130 64 4c 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 3b dList *pColumns;
24140 20 20 20 20 20 20 20 2f 2a 20 49 66 20 74 68 69 /* If thi
24150 73 20 69 73 20 61 6e 20 55 50 44 41 54 45 20 4f s is an UPDATE O
24160 46 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 F <column-list>
24170 74 72 69 67 67 65 72 2c 0a 20 20 20 20 20 20 20 trigger,.
24180 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24190 20 20 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 6d the <colum
241a0 6e 2d 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 65 n-list> is store
241b0 64 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 d here */. Sche
241c0 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
241d0 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f /* Schema co
241e0 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74 72 69 ntaining the tri
241f0 67 67 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d 61 gger */. Schema
24200 20 2a 70 54 61 62 53 63 68 65 6d 61 3b 20 20 20 *pTabSchema;
24210 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 /* Schema cont
24220 61 69 6e 69 6e 67 20 74 68 65 20 74 61 62 6c 65 aining the table
24230 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 */. TriggerSte
24240 70 20 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f 2a p *step_list; /*
24250 20 4c 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 72 Link list of tr
24260 69 67 67 65 72 20 70 72 6f 67 72 61 6d 20 73 74 igger program st
24270 65 70 73 20 20 20 20 20 20 20 20 20 20 20 20 20 eps
24280 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e */. Trigger *pN
24290 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ext; /*
242a0 4e 65 78 74 20 74 72 69 67 67 65 72 20 61 73 73 Next trigger ass
242b0 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 ociated with the
242c0 20 74 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a table */.};../*
242d0 0a 2a 2a 20 41 20 74 72 69 67 67 65 72 20 69 73 .** A trigger is
242e0 20 65 69 74 68 65 72 20 61 20 42 45 46 4f 52 45 either a BEFORE
242f0 20 6f 72 20 61 6e 20 41 46 54 45 52 20 74 72 69 or an AFTER tri
24300 67 67 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c 6f gger. The follo
24310 77 69 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a 2a wing constants.*
24320 2a 20 64 65 74 65 72 6d 69 6e 65 20 77 68 69 63 * determine whic
24330 68 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 h..**.** If ther
24340 65 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 20 74 e are multiple t
24350 72 69 67 67 65 72 73 2c 20 79 6f 75 20 6d 69 67 riggers, you mig
24360 68 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 4f 52 ht of some BEFOR
24370 45 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 45 52 E and some AFTER
24380 2e 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 61 73 ..** In that cas
24390 65 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 6e 74 es, the constant
243a0 73 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 20 4f s below can be O
243b0 52 65 64 20 74 6f 67 65 74 68 65 72 2e 0a 2a 2f Red together..*/
243c0 0a 23 64 65 66 69 6e 65 20 54 52 49 47 47 45 52 .#define TRIGGER
243d0 5f 42 45 46 4f 52 45 20 20 31 0a 23 64 65 66 69 _BEFORE 1.#defi
243e0 6e 65 20 54 52 49 47 47 45 52 5f 41 46 54 45 52 ne TRIGGER_AFTER
243f0 20 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 2../*. * An i
24400 6e 73 74 61 6e 63 65 20 6f 66 20 73 74 72 75 63 nstance of struc
24410 74 20 54 72 69 67 67 65 72 53 74 65 70 20 69 73 t TriggerStep is
24420 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 61 used to store a
24430 20 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 single SQL stat
24440 65 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 69 73 ement. * that is
24450 20 61 20 70 61 72 74 20 6f 66 20 61 20 74 72 69 a part of a tri
24460 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 0a 20 2a gger-program.. *
24470 0a 20 2a 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 . * Instances of
24480 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 struct TriggerS
24490 74 65 70 20 61 72 65 20 73 74 6f 72 65 64 20 69 tep are stored i
244a0 6e 20 61 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 n a singly linke
244b0 64 20 6c 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 d list (linked.
244c0 2a 20 75 73 69 6e 67 20 74 68 65 20 22 70 4e 65 * using the "pNe
244d0 78 74 22 20 6d 65 6d 62 65 72 29 20 72 65 66 65 xt" member) refe
244e0 72 65 6e 63 65 64 20 62 79 20 74 68 65 20 22 73 renced by the "s
244f0 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 tep_list" member
24500 20 6f 66 20 74 68 65 0a 20 2a 20 61 73 73 6f 63 of the. * assoc
24510 69 61 74 65 64 20 73 74 72 75 63 74 20 54 72 69 iated struct Tri
24520 67 67 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 54 gger instance. T
24530 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 he first element
24540 20 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c of the linked l
24550 69 73 74 20 69 73 0a 20 2a 20 74 68 65 20 66 69 ist is. * the fi
24560 72 73 74 20 73 74 65 70 20 6f 66 20 74 68 65 20 rst step of the
24570 74 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e trigger-program.
24580 0a 20 2a 0a 20 2a 20 54 68 65 20 22 6f 70 22 20 . *. * The "op"
24590 6d 65 6d 62 65 72 20 69 6e 64 69 63 61 74 65 73 member indicates
245a0 20 77 68 65 74 68 65 72 20 74 68 69 73 20 69 73 whether this is
245b0 20 61 20 22 44 45 4c 45 54 45 22 2c 20 22 49 4e a "DELETE", "IN
245c0 53 45 52 54 22 2c 20 22 55 50 44 41 54 45 22 20 SERT", "UPDATE"
245d0 6f 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 20 73 or. * "SELECT" s
245e0 74 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 6d 65 tatement. The me
245f0 61 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 6f 74 anings of the ot
24600 68 65 72 20 6d 65 6d 62 65 72 73 20 69 73 20 64 her members is d
24610 65 74 65 72 6d 69 6e 65 64 20 62 79 20 74 68 65 etermined by the
24620 0a 20 2a 20 76 61 6c 75 65 20 6f 66 20 22 6f 70 . * value of "op
24630 22 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 20 2a " as follows:. *
24640 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 49 4e . * (op == TK_IN
24650 53 45 52 54 29 0a 20 2a 20 6f 72 63 6f 6e 66 20 SERT). * orconf
24660 20 20 20 2d 3e 20 73 74 6f 72 65 73 20 74 68 65 -> stores the
24670 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 61 6c 67 ON CONFLICT alg
24680 6f 72 69 74 68 6d 0a 20 2a 20 70 53 65 6c 65 63 orithm. * pSelec
24690 74 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 t -> If this i
246a0 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f s an INSERT INTO
246b0 20 2e 2e 2e 20 53 45 4c 45 43 54 20 2e 2e 2e 20 ... SELECT ...
246c0 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 0a statement, then.
246d0 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
246e0 74 68 69 73 20 73 74 6f 72 65 73 20 61 20 70 6f this stores a po
246f0 69 6e 74 65 72 20 74 6f 20 74 68 65 20 53 45 4c inter to the SEL
24700 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 4f ECT statement. O
24710 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
24720 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 * zTarget -> D
24730 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 equoted name of
24740 74 68 65 20 74 61 62 6c 65 20 74 6f 20 69 6e 73 the table to ins
24750 65 72 74 20 69 6e 74 6f 2e 0a 20 2a 20 70 45 78 ert into.. * pEx
24760 70 72 4c 69 73 74 20 2d 3e 20 49 66 20 74 68 69 prList -> If thi
24770 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 s is an INSERT I
24780 4e 54 4f 20 2e 2e 2e 20 56 41 4c 55 45 53 20 2e NTO ... VALUES .
24790 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 .. statement, th
247a0 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 en. *
247b0 20 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 76 this stores v
247c0 61 6c 75 65 73 20 74 6f 20 62 65 20 69 6e 73 65 alues to be inse
247d0 72 74 65 64 2e 20 4f 74 68 65 72 77 69 73 65 20 rted. Otherwise
247e0 4e 55 4c 4c 2e 0a 20 2a 20 70 49 64 4c 69 73 74 NULL.. * pIdList
247f0 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 73 -> If this is
24800 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 an INSERT INTO
24810 2e 2e 2e 20 28 3c 63 6f 6c 75 6d 6e 2d 6e 61 6d ... (<column-nam
24820 65 73 3e 29 20 56 41 4c 55 45 53 20 2e 2e 2e 0a es>) VALUES ....
24830 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
24840 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 20 statement, then
24850 74 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 20 this stores the
24860 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 74 6f 20 column-names to
24870 62 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 be. *
24880 20 20 20 69 6e 73 65 72 74 65 64 20 69 6e 74 6f inserted into
24890 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 .. *. * (op == T
248a0 4b 5f 44 45 4c 45 54 45 29 0a 20 2a 20 7a 54 61 K_DELETE). * zTa
248b0 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f 74 rget -> Dequot
248c0 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 ed name of the t
248d0 61 62 6c 65 20 74 6f 20 64 65 6c 65 74 65 20 66 able to delete f
248e0 72 6f 6d 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 rom.. * pWhere
248f0 20 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 -> The WHERE c
24900 6c 61 75 73 65 20 6f 66 20 74 68 65 20 44 45 4c lause of the DEL
24910 45 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 ETE statement if
24920 20 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 one is specifie
24930 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 d.. *
24940 20 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c Otherwise NUL
24950 4c 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 L.. *. * (op ==
24960 54 4b 5f 55 50 44 41 54 45 29 0a 20 2a 20 7a 54 TK_UPDATE). * zT
24970 61 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f arget -> Dequo
24980 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 ted name of the
24990 74 61 62 6c 65 20 74 6f 20 75 70 64 61 74 65 2e table to update.
249a0 0a 20 2a 20 70 57 68 65 72 65 20 20 20 20 2d 3e . * pWhere ->
249b0 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 The WHERE claus
249c0 65 20 6f 66 20 74 68 65 20 55 50 44 41 54 45 20 e of the UPDATE
249d0 73 74 61 74 65 6d 65 6e 74 20 69 66 20 6f 6e 65 statement if one
249e0 20 69 73 20 73 70 65 63 69 66 69 65 64 2e 0a 20 is specified..
249f0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4f * O
24a00 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
24a10 2a 20 70 45 78 70 72 4c 69 73 74 20 2d 3e 20 41 * pExprList -> A
24a20 20 6c 69 73 74 20 6f 66 20 74 68 65 20 63 6f 6c list of the col
24a30 75 6d 6e 73 20 74 6f 20 75 70 64 61 74 65 20 61 umns to update a
24a40 6e 64 20 74 68 65 20 65 78 70 72 65 73 73 69 6f nd the expressio
24a50 6e 73 20 74 6f 20 75 70 64 61 74 65 0a 20 2a 20 ns to update. *
24a60 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 the
24a70 6d 20 74 6f 2e 20 53 65 65 20 73 71 6c 69 74 65 m to. See sqlite
24a80 33 55 70 64 61 74 65 28 29 20 64 6f 63 75 6d 65 3Update() docume
24a90 6e 74 61 74 69 6f 6e 20 6f 66 20 22 70 43 68 61 ntation of "pCha
24aa0 6e 67 65 73 22 0a 20 2a 20 20 20 20 20 20 20 20 nges". *
24ab0 20 20 20 20 20 20 61 72 67 75 6d 65 6e 74 2e 0a argument..
24ac0 20 2a 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 72 *. */.struct Tr
24ad0 69 67 67 65 72 53 74 65 70 20 7b 0a 20 20 75 38 iggerStep {. u8
24ae0 20 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 op;
24af0 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f /* One of TK_
24b00 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 DELETE, TK_UPDAT
24b10 45 2c 20 54 4b 5f 49 4e 53 45 52 54 2c 20 54 4b E, TK_INSERT, TK
24b20 5f 53 45 4c 45 43 54 20 2a 2f 0a 20 20 75 38 20 _SELECT */. u8
24b30 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 orconf;
24b40 20 20 2f 2a 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b /* OE_Rollback
24b50 20 65 74 63 2e 20 2a 2f 0a 20 20 54 72 69 67 67 etc. */. Trigg
24b60 65 72 20 2a 70 54 72 69 67 3b 20 20 20 20 20 20 er *pTrig;
24b70 2f 2a 20 54 68 65 20 74 72 69 67 67 65 72 20 74 /* The trigger t
24b80 68 61 74 20 74 68 69 73 20 73 74 65 70 20 69 73 hat this step is
24b90 20 61 20 70 61 72 74 20 6f 66 20 2a 2f 0a 20 20 a part of */.
24ba0 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b Select *pSelect;
24bb0 20 20 20 20 20 2f 2a 20 53 45 4c 45 43 54 20 73 /* SELECT s
24bc0 74 61 74 65 6d 65 6e 74 20 6f 72 20 52 48 53 20 tatement or RHS
24bd0 6f 66 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 53 of INSERT INTO S
24be0 45 4c 45 43 54 20 2e 2e 2e 20 2a 2f 0a 20 20 63 ELECT ... */. c
24bf0 68 61 72 20 2a 7a 54 61 72 67 65 74 3b 20 20 20 har *zTarget;
24c00 20 20 20 20 2f 2a 20 54 61 72 67 65 74 20 74 61 /* Target ta
24c10 62 6c 65 20 66 6f 72 20 44 45 4c 45 54 45 2c 20 ble for DELETE,
24c20 55 50 44 41 54 45 2c 20 49 4e 53 45 52 54 20 2a UPDATE, INSERT *
24c30 2f 0a 20 20 45 78 70 72 20 2a 70 57 68 65 72 65 /. Expr *pWhere
24c40 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ; /* The
24c50 57 48 45 52 45 20 63 6c 61 75 73 65 20 66 6f 72 WHERE clause for
24c60 20 44 45 4c 45 54 45 20 6f 72 20 55 50 44 41 54 DELETE or UPDAT
24c70 45 20 73 74 65 70 73 20 2a 2f 0a 20 20 45 78 70 E steps */. Exp
24c80 72 4c 69 73 74 20 2a 70 45 78 70 72 4c 69 73 74 rList *pExprList
24c90 3b 20 2f 2a 20 53 45 54 20 63 6c 61 75 73 65 20 ; /* SET clause
24ca0 66 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 20 20 for UPDATE */.
24cb0 49 64 4c 69 73 74 20 2a 70 49 64 4c 69 73 74 3b IdList *pIdList;
24cc0 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e /* Column n
24cd0 61 6d 65 73 20 66 6f 72 20 49 4e 53 45 52 54 20 ames for INSERT
24ce0 2a 2f 0a 20 20 55 70 73 65 72 74 20 2a 70 55 70 */. Upsert *pUp
24cf0 73 65 72 74 3b 20 20 20 20 20 2f 2a 20 55 70 73 sert; /* Ups
24d00 65 72 74 20 63 6c 61 75 73 65 73 20 6f 6e 20 61 ert clauses on a
24d10 6e 20 49 4e 53 45 52 54 20 2a 2f 0a 20 20 63 68 n INSERT */. ch
24d20 61 72 20 2a 7a 53 70 61 6e 3b 20 20 20 20 20 20 ar *zSpan;
24d30 20 20 20 2f 2a 20 4f 72 69 67 69 6e 61 6c 20 53 /* Original S
24d40 51 4c 20 74 65 78 74 20 6f 66 20 74 68 69 73 20 QL text of this
24d50 63 6f 6d 6d 61 6e 64 20 2a 2f 0a 20 20 54 72 69 command */. Tri
24d60 67 67 65 72 53 74 65 70 20 2a 70 4e 65 78 74 3b ggerStep *pNext;
24d70 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 74 68 65 /* Next in the
24d80 20 6c 69 6e 6b 2d 6c 69 73 74 20 2a 2f 0a 20 20 link-list */.
24d90 54 72 69 67 67 65 72 53 74 65 70 20 2a 70 4c 61 TriggerStep *pLa
24da0 73 74 3b 20 20 2f 2a 20 4c 61 73 74 20 65 6c 65 st; /* Last ele
24db0 6d 65 6e 74 20 69 6e 20 6c 69 6e 6b 2d 6c 69 73 ment in link-lis
24dc0 74 2e 20 56 61 6c 69 64 20 66 6f 72 20 31 73 74 t. Valid for 1st
24dd0 20 65 6c 65 6d 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b elem only */.};
24de0 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c ../*.** The foll
24df0 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 owing structure
24e00 63 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 6d 61 contains informa
24e10 74 69 6f 6e 20 75 73 65 64 20 62 79 20 74 68 65 tion used by the
24e20 20 73 71 6c 69 74 65 46 69 78 2e 2e 2e 0a 2a 2a sqliteFix....**
24e30 20 72 6f 75 74 69 6e 65 73 20 61 73 20 74 68 65 routines as the
24e40 79 20 77 61 6c 6b 20 74 68 65 20 70 61 72 73 65 y walk the parse
24e50 20 74 72 65 65 20 74 6f 20 6d 61 6b 65 20 64 61 tree to make da
24e60 74 61 62 61 73 65 20 72 65 66 65 72 65 6e 63 65 tabase reference
24e70 73 0a 2a 2a 20 65 78 70 6c 69 63 69 74 2e 0a 2a s.** explicit..*
24e80 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
24e90 20 44 62 46 69 78 65 72 20 44 62 46 69 78 65 72 DbFixer DbFixer
24ea0 3b 0a 73 74 72 75 63 74 20 44 62 46 69 78 65 72 ;.struct DbFixer
24eb0 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 {. Parse *pPar
24ec0 73 65 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 se; /* The
24ed0 70 61 72 73 69 6e 67 20 63 6f 6e 74 65 78 74 2e parsing context.
24ee0 20 20 45 72 72 6f 72 20 6d 65 73 73 61 67 65 73 Error messages
24ef0 20 77 72 69 74 74 65 6e 20 68 65 72 65 20 2a 2f written here */
24f00 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 . Schema *pSche
24f10 6d 61 3b 20 20 20 20 2f 2a 20 46 69 78 20 69 74 ma; /* Fix it
24f20 65 6d 73 20 74 6f 20 74 68 69 73 20 73 63 68 65 ems to this sche
24f30 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 62 56 61 72 ma */. int bVar
24f40 4f 6e 6c 79 3b 20 20 20 20 20 20 20 2f 2a 20 43 Only; /* C
24f50 68 65 63 6b 20 66 6f 72 20 76 61 72 69 61 62 6c heck for variabl
24f60 65 20 72 65 66 65 72 65 6e 63 65 73 20 6f 6e 6c e references onl
24f70 79 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 y */. const cha
24f80 72 20 2a 7a 44 62 3b 20 20 20 20 2f 2a 20 4d 61 r *zDb; /* Ma
24f90 6b 65 20 73 75 72 65 20 61 6c 6c 20 6f 62 6a 65 ke sure all obje
24fa0 63 74 73 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 cts are containe
24fb0 64 20 69 6e 20 74 68 69 73 20 64 61 74 61 62 61 d in this databa
24fc0 73 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 se */. const ch
24fd0 61 72 20 2a 7a 54 79 70 65 3b 20 20 2f 2a 20 54 ar *zType; /* T
24fe0 79 70 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 ype of the conta
24ff0 69 6e 65 72 20 2d 20 75 73 65 64 20 66 6f 72 20 iner - used for
25000 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 2a error messages *
25010 2f 0a 20 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 20 /. const Token
25020 2a 70 4e 61 6d 65 3b 20 2f 2a 20 4e 61 6d 65 20 *pName; /* Name
25030 6f 66 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 of the container
25040 20 2d 20 75 73 65 64 20 66 6f 72 20 65 72 72 6f - used for erro
25050 72 20 6d 65 73 73 61 67 65 73 20 2a 2f 0a 7d 3b r messages */.};
25060 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 63 ../*.** An objec
25070 74 65 64 20 75 73 65 64 20 74 6f 20 61 63 63 75 ted used to accu
25080 6d 75 6c 61 74 65 20 74 68 65 20 74 65 78 74 20 mulate the text
25090 6f 66 20 61 20 73 74 72 69 6e 67 20 77 68 65 72 of a string wher
250a0 65 20 77 65 0a 2a 2a 20 64 6f 20 6e 6f 74 20 6e e we.** do not n
250b0 65 63 65 73 73 61 72 69 6c 79 20 6b 6e 6f 77 20 ecessarily know
250c0 68 6f 77 20 62 69 67 20 74 68 65 20 73 74 72 69 how big the stri
250d0 6e 67 20 77 69 6c 6c 20 62 65 20 69 6e 20 74 68 ng will be in th
250e0 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 e end..*/.struct
250f0 20 73 71 6c 69 74 65 33 5f 73 74 72 20 7b 0a 20 sqlite3_str {.
25100 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 sqlite3 *db;
25110 20 20 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 /* Optiona
25120 6c 20 64 61 74 61 62 61 73 65 20 66 6f 72 20 6c l database for l
25130 6f 6f 6b 61 73 69 64 65 2e 20 20 43 61 6e 20 62 ookaside. Can b
25140 65 20 4e 55 4c 4c 20 2a 2f 0a 20 20 63 68 61 72 e NULL */. char
25150 20 2a 7a 54 65 78 74 3b 20 20 20 20 20 20 20 20 *zText;
25160 20 2f 2a 20 54 68 65 20 73 74 72 69 6e 67 20 63 /* The string c
25170 6f 6c 6c 65 63 74 65 64 20 73 6f 20 66 61 72 20 ollected so far
25180 2a 2f 0a 20 20 75 33 32 20 20 6e 41 6c 6c 6f 63 */. u32 nAlloc
25190 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6d 6f ; /* Amo
251a0 75 6e 74 20 6f 66 20 73 70 61 63 65 20 61 6c 6c unt of space all
251b0 6f 63 61 74 65 64 20 69 6e 20 7a 54 65 78 74 20 ocated in zText
251c0 2a 2f 0a 20 20 75 33 32 20 20 6d 78 41 6c 6c 6f */. u32 mxAllo
251d0 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 c; /* Max
251e0 69 6d 75 6d 20 61 6c 6c 6f 77 65 64 20 61 6c 6c imum allowed all
251f0 6f 63 61 74 69 6f 6e 2e 20 20 30 20 66 6f 72 20 ocation. 0 for
25200 6e 6f 20 6d 61 6c 6c 6f 63 20 75 73 61 67 65 20 no malloc usage
25210 2a 2f 0a 20 20 75 33 32 20 20 6e 43 68 61 72 3b */. u32 nChar;
25220 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 6e /* Len
25230 67 74 68 20 6f 66 20 74 68 65 20 73 74 72 69 6e gth of the strin
25240 67 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 75 38 g so far */. u8
25250 20 20 20 61 63 63 45 72 72 6f 72 3b 20 20 20 20 accError;
25260 20 20 20 2f 2a 20 53 51 4c 49 54 45 5f 4e 4f 4d /* SQLITE_NOM
25270 45 4d 20 6f 72 20 53 51 4c 49 54 45 5f 54 4f 4f EM or SQLITE_TOO
25280 42 49 47 20 2a 2f 0a 20 20 75 38 20 20 20 70 72 BIG */. u8 pr
25290 69 6e 74 66 46 6c 61 67 73 3b 20 20 20 20 2f 2a intfFlags; /*
252a0 20 53 51 4c 49 54 45 5f 50 52 49 4e 54 46 20 66 SQLITE_PRINTF f
252b0 6c 61 67 73 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b lags below */.};
252c0 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
252d0 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 4c 20 PRINTF_INTERNAL
252e0 30 78 30 31 20 20 2f 2a 20 49 6e 74 65 72 6e 61 0x01 /* Interna
252f0 6c 2d 75 73 65 2d 6f 6e 6c 79 20 63 6f 6e 76 65 l-use-only conve
25300 72 74 65 72 73 20 61 6c 6c 6f 77 65 64 20 2a 2f rters allowed */
25310 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
25320 50 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 20 20 PRINTF_SQLFUNC
25330 30 78 30 32 20 20 2f 2a 20 53 51 4c 20 66 75 6e 0x02 /* SQL fun
25340 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 73 20 ction arguments
25350 74 6f 20 56 58 50 72 69 6e 74 66 20 2a 2f 0a 23 to VXPrintf */.#
25360 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 52 define SQLITE_PR
25370 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 20 30 78 INTF_MALLOCED 0x
25380 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 78 04 /* True if x
25390 54 65 78 74 20 69 73 20 61 6c 6c 6f 63 61 74 65 Text is allocate
253a0 64 20 73 70 61 63 65 20 2a 2f 0a 0a 23 64 65 66 d space */..#def
253b0 69 6e 65 20 69 73 4d 61 6c 6c 6f 63 65 64 28 58 ine isMalloced(X
253c0 29 20 20 28 28 28 58 29 2d 3e 70 72 69 6e 74 66 ) (((X)->printf
253d0 46 6c 61 67 73 20 26 20 53 51 4c 49 54 45 5f 50 Flags & SQLITE_P
253e0 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 29 21 RINTF_MALLOCED)!
253f0 3d 30 29 0a 0a 0a 2f 2a 0a 2a 2a 20 41 20 70 6f =0).../*.** A po
25400 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 inter to this st
25410 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 20 ructure is used
25420 74 6f 20 63 6f 6d 6d 75 6e 69 63 61 74 65 20 69 to communicate i
25430 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 66 72 nformation.** fr
25440 6f 6d 20 73 71 6c 69 74 65 33 49 6e 69 74 20 61 om sqlite3Init a
25450 6e 64 20 4f 50 5f 50 61 72 73 65 53 63 68 65 6d nd OP_ParseSchem
25460 61 20 69 6e 74 6f 20 74 68 65 20 73 71 6c 69 74 a into the sqlit
25470 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b 2e 0a e3InitCallback..
25480 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
25490 74 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 t {. sqlite3 *d
254a0 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 b; /* The
254b0 20 64 61 74 61 62 61 73 65 20 62 65 69 6e 67 20 database being
254c0 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 initialized */.
254d0 20 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 67 char **pzErrMsg
254e0 3b 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 ; /* Error me
254f0 73 73 61 67 65 20 73 74 6f 72 65 64 20 68 65 72 ssage stored her
25500 65 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b 20 e */. int iDb;
25510 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 30 20 /* 0
25520 66 6f 72 20 6d 61 69 6e 20 64 61 74 61 62 61 73 for main databas
25530 65 2e 20 20 31 20 66 6f 72 20 54 45 4d 50 2c 20 e. 1 for TEMP,
25540 32 2e 2e 20 66 6f 72 20 41 54 54 41 43 48 65 64 2.. for ATTACHed
25550 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 20 20 */. int rc;
25560 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 73 /* Res
25570 75 6c 74 20 63 6f 64 65 20 73 74 6f 72 65 64 20 ult code stored
25580 68 65 72 65 20 2a 2f 0a 20 20 75 33 32 20 6d 49 here */. u32 mI
25590 6e 69 74 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a nitFlags; /*
255a0 20 46 6c 61 67 73 20 63 6f 6e 74 72 6f 6c 6c 69 Flags controlli
255b0 6e 67 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 ng error message
255c0 73 20 2a 2f 0a 20 20 75 33 32 20 6e 49 6e 69 74 s */. u32 nInit
255d0 52 6f 77 3b 20 20 20 20 20 20 20 2f 2a 20 4e 75 Row; /* Nu
255e0 6d 62 65 72 20 6f 66 20 72 6f 77 73 20 70 72 6f mber of rows pro
255f0 63 65 73 73 65 64 20 2a 2f 0a 7d 20 49 6e 69 74 cessed */.} Init
25600 44 61 74 61 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c Data;../*.** All
25610 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 owed values for
25620 6d 49 6e 69 74 46 6c 61 67 73 0a 2a 2f 0a 23 64 mInitFlags.*/.#d
25630 65 66 69 6e 65 20 49 4e 49 54 46 4c 41 47 5f 41 efine INITFLAG_A
25640 6c 74 65 72 54 61 62 6c 65 20 20 20 30 78 30 30 lterTable 0x00
25650 30 31 20 20 2f 2a 20 54 68 69 73 20 69 73 20 61 01 /* This is a
25660 20 72 65 70 61 72 73 65 20 61 66 74 65 72 20 41 reparse after A
25670 4c 54 45 52 20 54 41 42 4c 45 20 2a 2f 0a 0a 2f LTER TABLE */../
25680 2a 0a 2a 2a 20 53 74 72 75 63 74 75 72 65 20 63 *.** Structure c
25690 6f 6e 74 61 69 6e 69 6e 67 20 67 6c 6f 62 61 6c ontaining global
256a0 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 64 configuration d
256b0 61 74 61 20 66 6f 72 20 74 68 65 20 53 51 4c 69 ata for the SQLi
256c0 74 65 20 6c 69 62 72 61 72 79 2e 0a 2a 2a 0a 2a te library..**.*
256d0 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 72 65 * This structure
256e0 20 61 6c 73 6f 20 63 6f 6e 74 61 69 6e 73 20 73 also contains s
256f0 6f 6d 65 20 73 74 61 74 65 20 69 6e 66 6f 72 6d ome state inform
25700 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 ation..*/.struct
25710 20 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 7b Sqlite3Config {
25720 0a 20 20 69 6e 74 20 62 4d 65 6d 73 74 61 74 3b . int bMemstat;
25730 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25740 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 /* True to
25750 65 6e 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 74 enable memory st
25760 61 74 75 73 20 2a 2f 0a 20 20 75 38 20 62 43 6f atus */. u8 bCo
25770 72 65 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 reMutex;
25780 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
25790 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 63 6f rue to enable co
257a0 72 65 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 re mutexing */.
257b0 20 75 38 20 62 46 75 6c 6c 4d 75 74 65 78 3b 20 u8 bFullMutex;
257c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
257d0 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e /* True to en
257e0 61 62 6c 65 20 66 75 6c 6c 20 6d 75 74 65 78 69 able full mutexi
257f0 6e 67 20 2a 2f 0a 20 20 75 38 20 62 4f 70 65 6e ng */. u8 bOpen
25800 55 72 69 3b 20 20 20 20 20 20 20 20 20 20 20 20 Uri;
25810 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
25820 65 20 74 6f 20 69 6e 74 65 72 70 72 65 74 20 66 e to interpret f
25830 69 6c 65 6e 61 6d 65 73 20 61 73 20 55 52 49 73 ilenames as URIs
25840 20 2a 2f 0a 20 20 75 38 20 62 55 73 65 43 69 73 */. u8 bUseCis
25850 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
25860 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 20 63 /* Use c
25870 6f 76 65 72 69 6e 67 20 69 6e 64 69 63 65 73 20 overing indices
25880 66 6f 72 20 66 75 6c 6c 2d 73 63 61 6e 73 20 2a for full-scans *
25890 2f 0a 20 20 75 38 20 62 53 6d 61 6c 6c 4d 61 6c /. u8 bSmallMal
258a0 6c 6f 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 loc;
258b0 20 20 20 20 20 20 2f 2a 20 41 76 6f 69 64 20 6c /* Avoid l
258c0 61 72 67 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f arge memory allo
258d0 63 61 74 69 6f 6e 73 20 69 66 20 74 72 75 65 20 cations if true
258e0 2a 2f 0a 20 20 75 38 20 62 45 78 74 72 61 53 63 */. u8 bExtraSc
258f0 68 65 6d 61 43 68 65 63 6b 73 3b 20 20 20 20 20 hemaChecks;
25900 20 20 20 20 20 20 20 2f 2a 20 56 65 72 69 66 79 /* Verify
25910 20 74 79 70 65 2c 6e 61 6d 65 2c 74 62 6c 5f 6e type,name,tbl_n
25920 61 6d 65 20 69 6e 20 73 63 68 65 6d 61 20 2a 2f ame in schema */
25930 0a 20 20 69 6e 74 20 6d 78 53 74 72 6c 65 6e 3b . int mxStrlen;
25940 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25950 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 /* Maximum
25960 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 2a 2f string length */
25970 0a 20 20 69 6e 74 20 6e 65 76 65 72 43 6f 72 72 . int neverCorr
25980 75 70 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 upt;
25990 20 20 20 20 20 2f 2a 20 44 61 74 61 62 61 73 65 /* Database
259a0 20 69 73 20 61 6c 77 61 79 73 20 77 65 6c 6c 2d is always well-
259b0 66 6f 72 6d 65 64 20 2a 2f 0a 20 20 69 6e 74 20 formed */. int
259c0 73 7a 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 szLookaside;
259d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
259e0 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 69 Default lookasi
259f0 64 65 20 62 75 66 66 65 72 20 73 69 7a 65 20 2a de buffer size *
25a00 2f 0a 20 20 69 6e 74 20 6e 4c 6f 6f 6b 61 73 69 /. int nLookasi
25a10 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 de;
25a20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 /* Default
25a30 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 65 lookaside buffe
25a40 72 20 63 6f 75 6e 74 20 2a 2f 0a 20 20 69 6e 74 r count */. int
25a50 20 6e 53 74 6d 74 53 70 69 6c 6c 3b 20 20 20 20 nStmtSpill;
25a60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
25a70 2a 20 53 74 6d 74 2d 6a 6f 75 72 6e 61 6c 20 73 * Stmt-journal s
25a80 70 69 6c 6c 2d 74 6f 2d 64 69 73 6b 20 74 68 72 pill-to-disk thr
25a90 65 73 68 6f 6c 64 20 2a 2f 0a 20 20 73 71 6c 69 eshold */. sqli
25aa0 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 te3_mem_methods
25ab0 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
25ac0 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 65 6d 6f 72 Low-level memor
25ad0 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e 74 y allocation int
25ae0 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 71 6c 69 erface */. sqli
25af0 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 te3_mutex_method
25b00 73 20 6d 75 74 65 78 3b 20 20 20 20 20 20 2f 2a s mutex; /*
25b10 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 75 74 65 78 Low-level mutex
25b20 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 interface */.
25b30 73 71 6c 69 74 65 33 5f 70 63 61 63 68 65 5f 6d sqlite3_pcache_m
25b40 65 74 68 6f 64 73 32 20 70 63 61 63 68 65 32 3b ethods2 pcache2;
25b50 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 70 /* Low-level p
25b60 61 67 65 2d 63 61 63 68 65 20 69 6e 74 65 72 66 age-cache interf
25b70 61 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ace */. void *p
25b80 48 65 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 Heap;
25b90 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 65 /* He
25ba0 61 70 20 73 74 6f 72 61 67 65 20 73 70 61 63 65 ap storage space
25bb0 20 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 61 70 3b */. int nHeap;
25bc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25bd0 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
25be0 6f 66 20 70 48 65 61 70 5b 5d 20 2a 2f 0a 20 20 of pHeap[] */.
25bf0 69 6e 74 20 6d 6e 52 65 71 2c 20 6d 78 52 65 71 int mnReq, mxReq
25c00 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
25c10 20 20 2f 2a 20 4d 69 6e 20 61 6e 64 20 6d 61 78 /* Min and max
25c20 20 68 65 61 70 20 72 65 71 75 65 73 74 73 20 73 heap requests s
25c30 69 7a 65 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 izes */. sqlite
25c40 33 5f 69 6e 74 36 34 20 73 7a 4d 6d 61 70 3b 20 3_int64 szMmap;
25c50 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6d /* m
25c60 6d 61 70 28 29 20 73 70 61 63 65 20 70 65 72 20 map() space per
25c70 6f 70 65 6e 20 66 69 6c 65 20 2a 2f 0a 20 20 73 open file */. s
25c80 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 6d 78 4d qlite3_int64 mxM
25c90 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 map;
25ca0 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 76 61 6c 75 /* Maximum valu
25cb0 65 20 66 6f 72 20 73 7a 4d 6d 61 70 20 2a 2f 0a e for szMmap */.
25cc0 20 20 76 6f 69 64 20 2a 70 50 61 67 65 3b 20 20 void *pPage;
25cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25ce0 20 20 20 20 2f 2a 20 50 61 67 65 20 63 61 63 68 /* Page cach
25cf0 65 20 6d 65 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e e memory */. in
25d00 74 20 73 7a 50 61 67 65 3b 20 20 20 20 20 20 20 t szPage;
25d10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25d20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 20 /* Size of each
25d30 70 61 67 65 20 69 6e 20 70 50 61 67 65 5b 5d 20 page in pPage[]
25d40 2a 2f 0a 20 20 69 6e 74 20 6e 50 61 67 65 3b 20 */. int nPage;
25d50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25d60 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
25d70 20 6f 66 20 70 61 67 65 73 20 69 6e 20 70 50 61 of pages in pPa
25d80 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 ge[] */. int mx
25d90 50 61 72 73 65 72 53 74 61 63 6b 3b 20 20 20 20 ParserStack;
25da0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6d /* m
25db0 61 78 69 6d 75 6d 20 64 65 70 74 68 20 6f 66 20 aximum depth of
25dc0 74 68 65 20 70 61 72 73 65 72 20 73 74 61 63 6b the parser stack
25dd0 20 2a 2f 0a 20 20 69 6e 74 20 73 68 61 72 65 64 */. int shared
25de0 43 61 63 68 65 45 6e 61 62 6c 65 64 3b 20 20 20 CacheEnabled;
25df0 20 20 20 20 20 20 20 20 2f 2a 20 74 72 75 65 20 /* true
25e00 69 66 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 if shared-cache
25e10 6d 6f 64 65 20 65 6e 61 62 6c 65 64 20 2a 2f 0a mode enabled */.
25e20 20 20 75 33 32 20 73 7a 50 6d 61 3b 20 20 20 20 u32 szPma;
25e30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
25e40 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 53 /* Maximum S
25e50 6f 72 74 65 72 20 50 4d 41 20 73 69 7a 65 20 2a orter PMA size *
25e60 2f 0a 20 20 2f 2a 20 54 68 65 20 61 62 6f 76 65 /. /* The above
25e70 20 6d 69 67 68 74 20 62 65 20 69 6e 69 74 69 61 might be initia
25e80 6c 69 7a 65 64 20 74 6f 20 6e 6f 6e 2d 7a 65 72 lized to non-zer
25e90 6f 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e o. The followin
25ea0 67 20 6e 65 65 64 20 74 6f 20 61 6c 77 61 79 73 g need to always
25eb0 0a 20 20 2a 2a 20 69 6e 69 74 69 61 6c 6c 79 20 . ** initially
25ec0 62 65 20 7a 65 72 6f 2c 20 68 6f 77 65 76 65 72 be zero, however
25ed0 2e 20 2a 2f 0a 20 20 69 6e 74 20 69 73 49 6e 69 . */. int isIni
25ee0 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
25ef0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
25f00 20 61 66 74 65 72 20 69 6e 69 74 69 61 6c 69 7a after initializ
25f10 61 74 69 6f 6e 20 68 61 73 20 66 69 6e 69 73 68 ation has finish
25f20 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 6e 50 72 ed */. int inPr
25f30 6f 67 72 65 73 73 3b 20 20 20 20 20 20 20 20 20 ogress;
25f40 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
25f50 65 20 77 68 69 6c 65 20 69 6e 69 74 69 61 6c 69 e while initiali
25f60 7a 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 zation in progre
25f70 73 73 20 2a 2f 0a 20 20 69 6e 74 20 69 73 4d 75 ss */. int isMu
25f80 74 65 78 49 6e 69 74 3b 20 20 20 20 20 20 20 20 texInit;
25f90 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
25fa0 65 20 61 66 74 65 72 20 6d 75 74 65 78 65 73 20 e after mutexes
25fb0 61 72 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 are initialized
25fc0 2a 2f 0a 20 20 69 6e 74 20 69 73 4d 61 6c 6c 6f */. int isMallo
25fd0 63 49 6e 69 74 3b 20 20 20 20 20 20 20 20 20 20 cInit;
25fe0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 /* True a
25ff0 66 74 65 72 20 6d 61 6c 6c 6f 63 20 69 73 20 69 fter malloc is i
26000 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 nitialized */.
26010 69 6e 74 20 69 73 50 43 61 63 68 65 49 6e 69 74 int isPCacheInit
26020 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
26030 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 /* True after
26040 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 69 61 malloc is initia
26050 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 6e lized */. int n
26060 52 65 66 49 6e 69 74 4d 75 74 65 78 3b 20 20 20 RefInitMutex;
26070 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
26080 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 72 73 20 Number of users
26090 6f 66 20 70 49 6e 69 74 4d 75 74 65 78 20 2a 2f of pInitMutex */
260a0 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 . sqlite3_mutex
260b0 20 2a 70 49 6e 69 74 4d 75 74 65 78 3b 20 20 20 *pInitMutex;
260c0 20 20 20 20 20 2f 2a 20 4d 75 74 65 78 20 75 73 /* Mutex us
260d0 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f 69 6e ed by sqlite3_in
260e0 69 74 69 61 6c 69 7a 65 28 29 20 2a 2f 0a 20 20 itialize() */.
260f0 76 6f 69 64 20 28 2a 78 4c 6f 67 29 28 76 6f 69 void (*xLog)(voi
26100 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 d*,int,const cha
26110 72 2a 29 3b 20 2f 2a 20 46 75 6e 63 74 69 6f 6e r*); /* Function
26120 20 66 6f 72 20 6c 6f 67 67 69 6e 67 20 2a 2f 0a for logging */.
26130 20 20 76 6f 69 64 20 2a 70 4c 6f 67 41 72 67 3b void *pLogArg;
26140 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26150 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 /* First
26160 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 4c 6f 67 argument to xLog
26170 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c () */.#ifdef SQL
26180 49 54 45 5f 45 4e 41 42 4c 45 5f 53 51 4c 4c 4f ITE_ENABLE_SQLLO
26190 47 0a 20 20 76 6f 69 64 28 2a 78 53 71 6c 6c 6f G. void(*xSqllo
261a0 67 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 g)(void*,sqlite3
261b0 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 *,const char*, i
261c0 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 53 71 nt);. void *pSq
261d0 6c 6c 6f 67 41 72 67 3b 0a 23 65 6e 64 69 66 0a llogArg;.#endif.
261e0 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 56 44 #ifdef SQLITE_VD
261f0 42 45 5f 43 4f 56 45 52 41 47 45 0a 20 20 2f 2a BE_COVERAGE. /*
26200 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 The following c
26210 61 6c 6c 62 61 63 6b 20 28 69 66 20 6e 6f 74 20 allback (if not
26220 4e 55 4c 4c 29 20 69 73 20 69 6e 76 6f 6b 65 64 NULL) is invoked
26230 20 6f 6e 20 65 76 65 72 79 20 56 44 42 45 20 62 on every VDBE b
26240 72 61 6e 63 68 0a 20 20 2a 2a 20 6f 70 65 72 61 ranch. ** opera
26250 74 69 6f 6e 2e 20 20 53 65 74 20 74 68 65 20 63 tion. Set the c
26260 61 6c 6c 62 61 63 6b 20 75 73 69 6e 67 20 53 51 allback using SQ
26270 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f 56 44 LITE_TESTCTRL_VD
26280 42 45 5f 43 4f 56 45 52 41 47 45 2e 0a 20 20 2a BE_COVERAGE.. *
26290 2f 0a 20 20 76 6f 69 64 20 28 2a 78 56 64 62 65 /. void (*xVdbe
262a0 42 72 61 6e 63 68 29 28 76 6f 69 64 2a 2c 75 6e Branch)(void*,un
262b0 73 69 67 6e 65 64 20 69 53 72 63 4c 69 6e 65 2c signed iSrcLine,
262c0 75 38 20 65 54 68 69 73 2c 75 38 20 65 4d 78 29 u8 eThis,u8 eMx)
262d0 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 2a ; /* Callback *
262e0 2f 0a 20 20 76 6f 69 64 20 2a 70 56 64 62 65 42 /. void *pVdbeB
262f0 72 61 6e 63 68 41 72 67 3b 20 20 20 20 20 20 20 ranchArg;
26300 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26310 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
26320 20 31 73 74 20 61 72 67 75 6d 65 6e 74 20 2a 2f 1st argument */
26330 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 .#endif.#ifdef S
26340 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 45 53 QLITE_ENABLE_DES
26350 45 52 49 41 4c 49 5a 45 0a 20 20 73 71 6c 69 74 ERIALIZE. sqlit
26360 65 33 5f 69 6e 74 36 34 20 6d 78 4d 65 6d 64 62 e3_int64 mxMemdb
26370 53 69 7a 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 Size; /*
26380 44 65 66 61 75 6c 74 20 6d 61 78 20 6d 65 6d 64 Default max memd
26390 62 20 73 69 7a 65 20 2a 2f 0a 23 65 6e 64 69 66 b size */.#endif
263a0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
263b0 55 4e 54 45 53 54 41 42 4c 45 0a 20 20 69 6e 74 UNTESTABLE. int
263c0 20 28 2a 78 54 65 73 74 43 61 6c 6c 62 61 63 6b (*xTestCallback
263d0 29 28 69 6e 74 29 3b 20 20 20 20 20 20 20 20 2f )(int); /
263e0 2a 20 49 6e 76 6f 6b 65 64 20 62 79 20 73 71 6c * Invoked by sql
263f0 69 74 65 33 46 61 75 6c 74 53 69 6d 28 29 20 2a ite3FaultSim() *
26400 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 62 /.#endif. int b
26410 4c 6f 63 61 6c 74 69 6d 65 46 61 75 6c 74 3b 20 LocaltimeFault;
26420 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
26430 54 72 75 65 20 74 6f 20 66 61 69 6c 20 6c 6f 63 True to fail loc
26440 61 6c 74 69 6d 65 28 29 20 63 61 6c 6c 73 20 2a altime() calls *
26450 2f 0a 20 20 69 6e 74 20 62 49 6e 74 65 72 6e 61 /. int bInterna
26460 6c 46 75 6e 63 74 69 6f 6e 73 3b 20 20 20 20 20 lFunctions;
26470 20 20 20 20 20 20 2f 2a 20 49 6e 74 65 72 6e 61 /* Interna
26480 6c 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 73 20 l SQL functions
26490 61 72 65 20 76 69 73 69 62 6c 65 20 2a 2f 0a 20 are visible */.
264a0 20 69 6e 74 20 69 4f 6e 63 65 52 65 73 65 74 54 int iOnceResetT
264b0 68 72 65 73 68 6f 6c 64 3b 20 20 20 20 20 20 20 hreshold;
264c0 20 20 20 2f 2a 20 57 68 65 6e 20 74 6f 20 72 65 /* When to re
264d0 73 65 74 20 4f 50 5f 4f 6e 63 65 20 63 6f 75 6e set OP_Once coun
264e0 74 65 72 73 20 2a 2f 0a 20 20 75 33 32 20 73 7a ters */. u32 sz
264f0 53 6f 72 74 65 72 52 65 66 3b 20 20 20 20 20 20 SorterRef;
26500 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d /* M
26510 69 6e 20 73 69 7a 65 20 69 6e 20 62 79 74 65 73 in size in bytes
26520 20 74 6f 20 75 73 65 20 73 6f 72 74 65 72 2d 72 to use sorter-r
26530 65 66 73 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 efs */. unsigne
26540 64 20 69 6e 74 20 69 50 72 6e 67 53 65 65 64 3b d int iPrngSeed;
26550 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c /* Al
26560 74 65 72 6e 61 74 69 76 65 20 66 69 78 65 64 20 ternative fixed
26570 73 65 65 64 20 66 6f 72 20 74 68 65 20 50 52 4e seed for the PRN
26580 47 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 G */.};../*.** T
26590 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 his macro is use
265a0 64 20 69 6e 73 69 64 65 20 6f 66 20 61 73 73 65 d inside of asse
265b0 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 20 rt() statements
265c0 74 6f 20 69 6e 64 69 63 61 74 65 20 74 68 61 74 to indicate that
265d0 0a 2a 2a 20 74 68 65 20 61 73 73 65 72 74 20 69 .** the assert i
265e0 73 20 6f 6e 6c 79 20 76 61 6c 69 64 20 6f 6e 20 s only valid on
265f0 61 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 a well-formed da
26600 74 61 62 61 73 65 2e 20 20 49 6e 73 74 65 61 64 tabase. Instead
26610 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 of:.**.** a
26620 73 73 65 72 74 28 20 58 20 29 3b 0a 2a 2a 0a 2a ssert( X );.**.*
26630 2a 20 4f 6e 65 20 77 72 69 74 65 73 3a 0a 2a 2a * One writes:.**
26640 0a 2a 2a 20 20 20 20 20 61 73 73 65 72 74 28 20 .** assert(
26650 58 20 7c 7c 20 43 4f 52 52 55 50 54 5f 44 42 20 X || CORRUPT_DB
26660 29 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 52 55 50 54 );.**.** CORRUPT
26670 5f 44 42 20 69 73 20 74 72 75 65 20 64 75 72 69 _DB is true duri
26680 6e 67 20 6e 6f 72 6d 61 6c 20 6f 70 65 72 61 74 ng normal operat
26690 69 6f 6e 2e 20 20 43 4f 52 52 55 50 54 5f 44 42 ion. CORRUPT_DB
266a0 20 64 6f 65 73 20 6e 6f 74 20 69 6e 64 69 63 61 does not indica
266b0 74 65 0a 2a 2a 20 74 68 61 74 20 74 68 65 20 64 te.** that the d
266c0 61 74 61 62 61 73 65 20 69 73 20 64 65 66 69 6e atabase is defin
266d0 69 74 65 6c 79 20 63 6f 72 72 75 70 74 2c 20 6f itely corrupt, o
266e0 6e 6c 79 20 74 68 61 74 20 69 74 20 6d 69 67 68 nly that it migh
266f0 74 20 62 65 20 63 6f 72 72 75 70 74 2e 0a 2a 2a t be corrupt..**
26700 20 46 6f 72 20 6d 6f 73 74 20 74 65 73 74 20 63 For most test c
26710 61 73 65 73 2c 20 43 4f 52 52 55 50 54 5f 44 42 ases, CORRUPT_DB
26720 20 69 73 20 73 65 74 20 74 6f 20 66 61 6c 73 65 is set to false
26730 20 75 73 69 6e 67 20 61 20 73 70 65 63 69 61 6c using a special
26740 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 74 .** sqlite3_test
26750 5f 63 6f 6e 74 72 6f 6c 28 29 2e 20 20 54 68 69 _control(). Thi
26760 73 20 65 6e 61 62 6c 65 73 20 61 73 73 65 72 74 s enables assert
26770 28 29 20 73 74 61 74 65 6d 65 6e 74 73 20 74 6f () statements to
26780 20 70 72 6f 76 65 0a 2a 2a 20 74 68 69 6e 67 73 prove.** things
26790 20 74 68 61 74 20 61 72 65 20 61 6c 77 61 79 73 that are always
267a0 20 74 72 75 65 20 66 6f 72 20 77 65 6c 6c 2d 66 true for well-f
267b0 6f 72 6d 65 64 20 64 61 74 61 62 61 73 65 73 2e ormed databases.
267c0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 52 52 .*/.#define CORR
267d0 55 50 54 5f 44 42 20 20 28 73 71 6c 69 74 65 33 UPT_DB (sqlite3
267e0 43 6f 6e 66 69 67 2e 6e 65 76 65 72 43 6f 72 72 Config.neverCorr
267f0 75 70 74 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 43 upt==0)../*.** C
26800 6f 6e 74 65 78 74 20 70 6f 69 6e 74 65 72 20 70 ontext pointer p
26810 61 73 73 65 64 20 64 6f 77 6e 20 74 68 72 6f 75 assed down throu
26820 67 68 20 74 68 65 20 74 72 65 65 2d 77 61 6c 6b gh the tree-walk
26830 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 61 6c 6b ..*/.struct Walk
26840 65 72 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 er {. Parse *pP
26850 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 20 arse;
26860 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26870 20 2f 2a 20 50 61 72 73 65 72 20 63 6f 6e 74 65 /* Parser conte
26880 78 74 2e 20 20 2a 2f 0a 20 20 69 6e 74 20 28 2a xt. */. int (*
26890 78 45 78 70 72 43 61 6c 6c 62 61 63 6b 29 28 57 xExprCallback)(W
268a0 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a 29 3b 20 alker*, Expr*);
268b0 20 20 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 /* Callback
268c0 66 6f 72 20 65 78 70 72 65 73 73 69 6f 6e 73 20 for expressions
268d0 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 53 65 6c 65 */. int (*xSele
268e0 63 74 43 61 6c 6c 62 61 63 6b 29 28 57 61 6c 6b ctCallback)(Walk
268f0 65 72 2a 2c 53 65 6c 65 63 74 2a 29 3b 20 20 2f er*,Select*); /
26900 2a 20 43 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 * Callback for S
26910 45 4c 45 43 54 73 20 2a 2f 0a 20 20 76 6f 69 64 ELECTs */. void
26920 20 28 2a 78 53 65 6c 65 63 74 43 61 6c 6c 62 61 (*xSelectCallba
26930 63 6b 32 29 28 57 61 6c 6b 65 72 2a 2c 53 65 6c ck2)(Walker*,Sel
26940 65 63 74 2a 29 3b 2f 2a 20 53 65 63 6f 6e 64 20 ect*);/* Second
26950 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 53 45 4c callback for SEL
26960 45 43 54 73 20 2a 2f 0a 20 20 69 6e 74 20 77 61 ECTs */. int wa
26970 6c 6b 65 72 44 65 70 74 68 3b 20 20 20 20 20 20 lkerDepth;
26980 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26990 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
269a0 20 73 75 62 71 75 65 72 69 65 73 20 2a 2f 0a 20 subqueries */.
269b0 20 75 38 20 65 43 6f 64 65 3b 20 20 20 20 20 20 u8 eCode;
269c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
269d0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 /* A
269e0 73 6d 61 6c 6c 20 70 72 6f 63 65 73 73 69 6e 67 small processing
269f0 20 63 6f 64 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e code */. union
26a00 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
26a10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26a20 20 20 20 20 20 2f 2a 20 45 78 74 72 61 20 64 61 /* Extra da
26a30 74 61 20 66 6f 72 20 63 61 6c 6c 62 61 63 6b 20 ta for callback
26a40 2a 2f 0a 20 20 20 20 4e 61 6d 65 43 6f 6e 74 65 */. NameConte
26a50 78 74 20 2a 70 4e 43 3b 20 20 20 20 20 20 20 20 xt *pNC;
26a60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26a70 20 2f 2a 20 4e 61 6d 69 6e 67 20 63 6f 6e 74 65 /* Naming conte
26a80 78 74 20 2a 2f 0a 20 20 20 20 69 6e 74 20 6e 3b xt */. int n;
26a90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26aa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26ab0 20 20 20 20 2f 2a 20 41 20 63 6f 75 6e 74 65 72 /* A counter
26ac0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 43 75 72 */. int iCur
26ad0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
26ae0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26af0 20 20 2f 2a 20 41 20 63 75 72 73 6f 72 20 6e 75 /* A cursor nu
26b00 6d 62 65 72 20 2a 2f 0a 20 20 20 20 53 72 63 4c mber */. SrcL
26b10 69 73 74 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 ist *pSrcList;
26b20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26b30 20 20 20 20 20 20 2f 2a 20 46 52 4f 4d 20 63 6c /* FROM cl
26b40 61 75 73 65 20 2a 2f 0a 20 20 20 20 73 74 72 75 ause */. stru
26b50 63 74 20 53 72 63 43 6f 75 6e 74 20 2a 70 53 72 ct SrcCount *pSr
26b60 63 43 6f 75 6e 74 3b 20 20 20 20 20 20 20 20 20 cCount;
26b70 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 69 6e /* Countin
26b80 67 20 63 6f 6c 75 6d 6e 20 72 65 66 65 72 65 6e g column referen
26b90 63 65 73 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 ces */. struc
26ba0 74 20 43 43 75 72 48 69 6e 74 20 2a 70 43 43 75 t CCurHint *pCCu
26bb0 72 48 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 rHint;
26bc0 20 20 20 20 20 2f 2a 20 55 73 65 64 20 62 79 20 /* Used by
26bd0 63 6f 64 65 43 75 72 73 6f 72 48 69 6e 74 28 29 codeCursorHint()
26be0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 2a 61 69 43 */. int *aiC
26bf0 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ol;
26c00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26c10 20 20 2f 2a 20 61 72 72 61 79 20 6f 66 20 63 6f /* array of co
26c20 6c 75 6d 6e 20 69 6e 64 65 78 65 73 20 2a 2f 0a lumn indexes */.
26c30 20 20 20 20 73 74 72 75 63 74 20 49 64 78 43 6f struct IdxCo
26c40 76 65 72 20 2a 70 49 64 78 43 6f 76 65 72 3b 20 ver *pIdxCover;
26c50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
26c60 20 43 68 65 63 6b 20 66 6f 72 20 69 6e 64 65 78 Check for index
26c70 20 63 6f 76 65 72 61 67 65 20 2a 2f 0a 20 20 20 coverage */.
26c80 20 73 74 72 75 63 74 20 49 64 78 45 78 70 72 54 struct IdxExprT
26c90 72 61 6e 73 20 2a 70 49 64 78 54 72 61 6e 73 3b rans *pIdxTrans;
26ca0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f /* Co
26cb0 6e 76 65 72 74 20 69 64 78 65 64 20 65 78 70 72 nvert idxed expr
26cc0 20 74 6f 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 to column */.
26cd0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f ExprList *pGro
26ce0 75 70 42 79 3b 20 20 20 20 20 20 20 20 20 20 20 upBy;
26cf0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 47 /* G
26d00 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 2a ROUP BY clause *
26d10 2f 0a 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 /. Select *pS
26d20 65 6c 65 63 74 3b 20 20 20 20 20 20 20 20 20 20 elect;
26d30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26d40 2f 2a 20 48 41 56 49 4e 47 20 74 6f 20 57 48 45 /* HAVING to WHE
26d50 52 45 20 63 6c 61 75 73 65 20 63 74 78 20 2a 2f RE clause ctx */
26d60 0a 20 20 20 20 73 74 72 75 63 74 20 57 69 6e 64 . struct Wind
26d70 6f 77 52 65 77 72 69 74 65 20 2a 70 52 65 77 72 owRewrite *pRewr
26d80 69 74 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f ite; /
26d90 2a 20 57 69 6e 64 6f 77 20 72 65 77 72 69 74 65 * Window rewrite
26da0 20 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 20 20 context */.
26db0 73 74 72 75 63 74 20 57 68 65 72 65 43 6f 6e 73 struct WhereCons
26dc0 74 20 2a 70 43 6f 6e 73 74 3b 20 20 20 20 20 20 t *pConst;
26dd0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 48 45 /* WHE
26de0 52 45 20 63 6c 61 75 73 65 20 63 6f 6e 73 74 61 RE clause consta
26df0 6e 74 73 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 nts */. struc
26e00 74 20 52 65 6e 61 6d 65 43 74 78 20 2a 70 52 65 t RenameCtx *pRe
26e10 6e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 name;
26e20 20 20 20 20 20 2f 2a 20 52 45 4e 41 4d 45 20 43 /* RENAME C
26e30 4f 4c 55 4d 4e 20 63 6f 6e 74 65 78 74 20 2a 2f OLUMN context */
26e40 0a 20 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f 2a 20 46 . } u;.};../* F
26e50 6f 72 77 61 72 64 20 64 65 63 6c 61 72 61 74 69 orward declarati
26e60 6f 6e 73 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 ons */.int sqlit
26e70 65 33 57 61 6c 6b 45 78 70 72 28 57 61 6c 6b 65 e3WalkExpr(Walke
26e80 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 r*, Expr*);.int
26e90 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 70 72 4c sqlite3WalkExprL
26ea0 69 73 74 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 ist(Walker*, Exp
26eb0 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c rList*);.int sql
26ec0 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 28 57 ite3WalkSelect(W
26ed0 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 alker*, Select*)
26ee0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c ;.int sqlite3Wal
26ef0 6b 53 65 6c 65 63 74 45 78 70 72 28 57 61 6c 6b kSelectExpr(Walk
26f00 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 er*, Select*);.i
26f10 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 65 nt sqlite3WalkSe
26f20 6c 65 63 74 46 72 6f 6d 28 57 61 6c 6b 65 72 2a lectFrom(Walker*
26f30 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 , Select*);.int
26f40 73 71 6c 69 74 65 33 45 78 70 72 57 61 6c 6b 4e sqlite3ExprWalkN
26f50 6f 6f 70 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 oop(Walker*, Exp
26f60 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
26f70 53 65 6c 65 63 74 57 61 6c 6b 4e 6f 6f 70 28 57 SelectWalkNoop(W
26f80 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 alker*, Select*)
26f90 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c ;.int sqlite3Sel
26fa0 65 63 74 57 61 6c 6b 46 61 69 6c 28 57 61 6c 6b ectWalkFail(Walk
26fb0 65 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 23 er*, Select*);.#
26fc0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
26fd0 55 47 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 UG.void sqlite3S
26fe0 65 6c 65 63 74 57 61 6c 6b 41 73 73 65 72 74 32 electWalkAssert2
26ff0 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 (Walker*, Select
27000 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a *);.#endif../*.*
27010 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 * Return code fr
27020 6f 6d 20 74 68 65 20 70 61 72 73 65 2d 74 72 65 om the parse-tre
27030 65 20 77 61 6c 6b 69 6e 67 20 70 72 69 6d 69 74 e walking primit
27040 69 76 65 73 20 61 6e 64 20 74 68 65 69 72 0a 2a ives and their.*
27050 2a 20 63 61 6c 6c 62 61 63 6b 73 2e 0a 2a 2f 0a * callbacks..*/.
27060 23 64 65 66 69 6e 65 20 57 52 43 5f 43 6f 6e 74 #define WRC_Cont
27070 69 6e 75 65 20 20 20 20 30 20 20 20 2f 2a 20 43 inue 0 /* C
27080 6f 6e 74 69 6e 75 65 20 64 6f 77 6e 20 69 6e 74 ontinue down int
27090 6f 20 63 68 69 6c 64 72 65 6e 20 2a 2f 0a 23 64 o children */.#d
270a0 65 66 69 6e 65 20 57 52 43 5f 50 72 75 6e 65 20 efine WRC_Prune
270b0 20 20 20 20 20 20 31 20 20 20 2f 2a 20 4f 6d 69 1 /* Omi
270c0 74 20 63 68 69 6c 64 72 65 6e 20 62 75 74 20 63 t children but c
270d0 6f 6e 74 69 6e 75 65 20 77 61 6c 6b 69 6e 67 20 ontinue walking
270e0 73 69 62 6c 69 6e 67 73 20 2a 2f 0a 23 64 65 66 siblings */.#def
270f0 69 6e 65 20 57 52 43 5f 41 62 6f 72 74 20 20 20 ine WRC_Abort
27100 20 20 20 20 32 20 20 20 2f 2a 20 41 62 61 6e 64 2 /* Aband
27110 6f 6e 20 74 68 65 20 74 72 65 65 20 77 61 6c 6b on the tree walk
27120 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e */../*.** An in
27130 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 stance of this s
27140 74 72 75 63 74 75 72 65 20 72 65 70 72 65 73 65 tructure represe
27150 6e 74 73 20 61 20 73 65 74 20 6f 66 20 6f 6e 65 nts a set of one
27160 20 6f 72 20 6d 6f 72 65 20 43 54 45 73 0a 2a 2a or more CTEs.**
27170 20 28 63 6f 6d 6d 6f 6e 20 74 61 62 6c 65 20 65 (common table e
27180 78 70 72 65 73 73 69 6f 6e 73 29 20 63 72 65 61 xpressions) crea
27190 74 65 64 20 62 79 20 61 20 73 69 6e 67 6c 65 20 ted by a single
271a0 57 49 54 48 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a WITH clause..*/.
271b0 73 74 72 75 63 74 20 57 69 74 68 20 7b 0a 20 20 struct With {.
271c0 69 6e 74 20 6e 43 74 65 3b 20 20 20 20 20 20 20 int nCte;
271d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
271e0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 43 54 45 /* Number of CTE
271f0 73 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c s in the WITH cl
27200 61 75 73 65 20 2a 2f 0a 20 20 57 69 74 68 20 2a ause */. With *
27210 70 4f 75 74 65 72 3b 20 20 20 20 20 20 20 20 20 pOuter;
27220 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e /* Con
27230 74 61 69 6e 69 6e 67 20 57 49 54 48 20 63 6c 61 taining WITH cla
27240 75 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a use, or NULL */.
27250 20 20 73 74 72 75 63 74 20 43 74 65 20 7b 20 20 struct Cte {
27260 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
27270 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 43 54 /* For each CT
27280 45 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 6c E in the WITH cl
27290 61 75 73 65 2e 2e 2e 2e 20 2a 2f 0a 20 20 20 20 ause.... */.
272a0 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
272b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
272c0 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 /* Name of this
272d0 43 54 45 20 2a 2f 0a 20 20 20 20 45 78 70 72 4c CTE */. ExprL
272e0 69 73 74 20 2a 70 43 6f 6c 73 3b 20 20 20 20 20 ist *pCols;
272f0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 /* Li
27300 73 74 20 6f 66 20 65 78 70 6c 69 63 69 74 20 63 st of explicit c
27310 6f 6c 75 6d 6e 20 6e 61 6d 65 73 2c 20 6f 72 20 olumn names, or
27320 4e 55 4c 4c 20 2a 2f 0a 20 20 20 20 53 65 6c 65 NULL */. Sele
27330 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 ct *pSelect;
27340 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
27350 68 65 20 64 65 66 69 6e 69 74 69 6f 6e 20 6f 66 he definition of
27360 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 20 20 this CTE */.
27370 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 74 const char *zCt
27380 65 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 eErr;
27390 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 67 /* Error messag
273a0 65 20 66 6f 72 20 63 69 72 63 75 6c 61 72 20 72 e for circular r
273b0 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 20 7d eferences */. }
273c0 20 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 69 66 64 65 a[1];.};..#ifde
273d0 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 2f f SQLITE_DEBUG./
273e0 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
273f0 20 6f 66 20 74 68 65 20 54 72 65 65 56 69 65 77 of the TreeView
27400 20 6f 62 6a 65 63 74 20 69 73 20 75 73 65 64 20 object is used
27410 66 6f 72 20 70 72 69 6e 74 69 6e 67 20 74 68 65 for printing the
27420 20 63 6f 6e 74 65 6e 74 20 6f 66 0a 2a 2a 20 64 content of.** d
27430 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20 6f ata structures o
27440 6e 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 72 n sqlite3DebugPr
27450 69 6e 74 66 28 29 20 75 73 69 6e 67 20 61 20 74 intf() using a t
27460 72 65 65 2d 6c 69 6b 65 20 76 69 65 77 2e 0a 2a ree-like view..*
27470 2f 0a 73 74 72 75 63 74 20 54 72 65 65 56 69 65 /.struct TreeVie
27480 77 20 7b 0a 20 20 69 6e 74 20 69 4c 65 76 65 6c w {. int iLevel
27490 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
274a0 20 57 68 69 63 68 20 6c 65 76 65 6c 20 6f 66 20 Which level of
274b0 74 68 65 20 74 72 65 65 20 77 65 20 61 72 65 20 the tree we are
274c0 6f 6e 20 2a 2f 0a 20 20 75 38 20 20 62 4c 69 6e on */. u8 bLin
274d0 65 5b 31 30 30 5d 3b 20 20 20 20 20 20 20 20 20 e[100];
274e0 2f 2a 20 44 72 61 77 20 76 65 72 74 69 63 61 6c /* Draw vertical
274f0 20 69 6e 20 63 6f 6c 75 6d 6e 20 69 20 69 66 20 in column i if
27500 62 4c 69 6e 65 5b 69 5d 20 69 73 20 74 72 75 65 bLine[i] is true
27510 20 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 66 20 2f 2a */.};.#endif /*
27520 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 2a 2f SQLITE_DEBUG */
27530 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 6f 62 6a ../*.** This obj
27540 65 63 74 20 69 73 20 75 73 65 64 20 69 6e 20 76 ect is used in v
27550 61 72 69 6f 75 73 20 77 61 79 73 2c 20 6d 6f 73 arious ways, mos
27560 74 20 28 62 75 74 20 6e 6f 74 20 61 6c 6c 29 20 t (but not all)
27570 72 65 6c 61 74 65 64 20 74 6f 20 77 69 6e 64 6f related to windo
27580 77 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 2e 0a w.** functions..
27590 2a 2a 0a 2a 2a 20 20 20 28 31 29 20 41 20 73 69 **.** (1) A si
275a0 6e 67 6c 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 ngle instance of
275b0 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 this structure
275c0 69 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 is attached to t
275d0 68 65 0a 2a 2a 20 20 20 20 20 20 20 74 68 65 20 he.** the
275e0 45 78 70 72 2e 79 2e 70 57 69 6e 20 66 69 65 6c Expr.y.pWin fiel
275f0 64 20 66 6f 72 20 65 61 63 68 20 77 69 6e 64 6f d for each windo
27600 77 20 66 75 6e 63 74 69 6f 6e 20 69 6e 20 61 6e w function in an
27610 20 65 78 70 72 65 73 73 69 6f 6e 20 74 72 65 65 expression tree
27620 2e 0a 2a 2a 20 20 20 20 20 20 20 54 68 69 73 20 ..** This
27630 6f 62 6a 65 63 74 20 68 6f 6c 64 73 20 74 68 65 object holds the
27640 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 6f 6e information con
27650 74 61 69 6e 65 64 20 69 6e 20 74 68 65 20 4f 56 tained in the OV
27660 45 52 20 63 6c 61 75 73 65 2c 0a 2a 2a 20 20 20 ER clause,.**
27670 20 20 20 20 70 6c 75 73 20 61 64 64 69 74 69 6f plus additio
27680 6e 61 6c 20 66 69 65 6c 64 73 20 75 73 65 64 20 nal fields used
27690 64 75 72 69 6e 67 20 63 6f 64 65 20 67 65 6e 65 during code gene
276a0 72 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 20 20 ration..**.**
276b0 28 32 29 20 41 6c 6c 20 77 69 6e 64 6f 77 20 66 (2) All window f
276c0 75 6e 63 74 69 6f 6e 73 20 69 6e 20 61 20 73 69 unctions in a si
276d0 6e 67 6c 65 20 53 45 4c 45 43 54 20 66 6f 72 6d ngle SELECT form
276e0 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 0a 2a a linked-list.*
276f0 2a 20 20 20 20 20 20 20 61 74 74 61 63 68 65 64 * attached
27700 20 74 6f 20 53 65 6c 65 63 74 2e 70 57 69 6e 2e to Select.pWin.
27710 20 20 54 68 65 20 57 69 6e 64 6f 77 2e 70 46 75 The Window.pFu
27720 6e 63 20 61 6e 64 20 57 69 6e 64 6f 77 2e 70 45 nc and Window.pE
27730 78 70 72 0a 2a 2a 20 20 20 20 20 20 20 66 69 65 xpr.** fie
27740 6c 64 73 20 70 6f 69 6e 74 20 62 61 63 6b 20 74 lds point back t
27750 6f 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e o the expression
27760 20 74 68 61 74 20 69 73 20 74 68 65 20 77 69 6e that is the win
27770 64 6f 77 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2a dow function..**
27780 0a 2a 2a 20 20 20 28 33 29 20 54 68 65 20 74 65 .** (3) The te
27790 72 6d 73 20 6f 66 20 74 68 65 20 57 49 4e 44 4f rms of the WINDO
277a0 57 20 63 6c 61 75 73 65 20 6f 66 20 61 20 53 45 W clause of a SE
277b0 4c 45 43 54 20 61 72 65 20 69 6e 73 74 61 6e 63 LECT are instanc
277c0 65 73 20 6f 66 20 74 68 69 73 0a 2a 2a 20 20 20 es of this.**
277d0 20 20 20 20 6f 62 6a 65 63 74 20 6f 6e 20 61 20 object on a
277e0 6c 69 6e 6b 65 64 20 6c 69 73 74 20 61 74 74 61 linked list atta
277f0 63 68 65 64 20 74 6f 20 53 65 6c 65 63 74 2e 70 ched to Select.p
27800 57 69 6e 44 65 66 6e 2e 0a 2a 2a 0a 2a 2a 20 20 WinDefn..**.**
27810 20 28 34 29 20 46 6f 72 20 61 6e 20 61 67 67 72 (4) For an aggr
27820 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 egate function w
27830 69 74 68 20 61 20 46 49 4c 54 45 52 20 63 6c 61 ith a FILTER cla
27840 75 73 65 2c 20 61 6e 20 69 6e 73 74 61 6e 63 65 use, an instance
27850 0a 2a 2a 20 20 20 20 20 20 20 6f 66 20 74 68 69 .** of thi
27860 73 20 6f 62 6a 65 63 74 20 69 73 20 73 74 6f 72 s object is stor
27870 65 64 20 69 6e 20 45 78 70 72 2e 79 2e 70 57 69 ed in Expr.y.pWi
27880 6e 20 77 69 74 68 20 65 46 72 6d 54 79 70 65 20 n with eFrmType
27890 73 65 74 20 74 6f 0a 2a 2a 20 20 20 20 20 20 20 set to.**
278a0 54 4b 5f 46 49 4c 54 45 52 2e 20 49 6e 20 74 68 TK_FILTER. In th
278b0 69 73 20 63 61 73 65 20 74 68 65 20 6f 6e 6c 79 is case the only
278c0 20 66 69 65 6c 64 20 75 73 65 64 20 69 73 20 57 field used is W
278d0 69 6e 64 6f 77 2e 70 46 69 6c 74 65 72 2e 0a 2a indow.pFilter..*
278e0 2a 0a 2a 2a 20 54 68 65 20 75 73 65 73 20 28 31 *.** The uses (1
278f0 29 20 61 6e 64 20 28 32 29 20 61 72 65 20 72 65 ) and (2) are re
27900 61 6c 6c 79 20 74 68 65 20 73 61 6d 65 20 57 69 ally the same Wi
27910 6e 64 6f 77 20 6f 62 6a 65 63 74 20 74 68 61 74 ndow object that
27920 20 6a 75 73 74 20 68 61 70 70 65 6e 73 0a 2a 2a just happens.**
27930 20 74 6f 20 62 65 20 61 63 63 65 73 73 69 62 6c to be accessibl
27940 65 20 69 6e 20 74 77 6f 20 64 69 66 66 65 72 65 e in two differe
27950 6e 74 20 77 61 79 73 2e 20 20 55 73 65 20 63 61 nt ways. Use ca
27960 73 65 20 28 33 29 20 61 72 65 20 73 65 70 61 72 se (3) are separ
27970 61 74 65 20 6f 62 6a 65 63 74 73 2e 0a 2a 2f 0a ate objects..*/.
27980 73 74 72 75 63 74 20 57 69 6e 64 6f 77 20 7b 0a struct Window {.
27990 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
279a0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d /* Nam
279b0 65 20 6f 66 20 77 69 6e 64 6f 77 20 28 6d 61 79 e of window (may
279c0 20 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 63 be NULL) */. c
279d0 68 61 72 20 2a 7a 42 61 73 65 3b 20 20 20 20 20 har *zBase;
279e0 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
279f0 66 20 62 61 73 65 20 77 69 6e 64 6f 77 20 66 6f f base window fo
27a00 72 20 63 68 61 69 6e 69 6e 67 20 28 6d 61 79 20 r chaining (may
27a10 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 45 78 be NULL) */. Ex
27a20 70 72 4c 69 73 74 20 2a 70 50 61 72 74 69 74 69 prList *pPartiti
27a30 6f 6e 3b 20 20 20 2f 2a 20 50 41 52 54 49 54 49 on; /* PARTITI
27a40 4f 4e 20 42 59 20 63 6c 61 75 73 65 20 2a 2f 0a ON BY clause */.
27a50 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 ExprList *pOrd
27a60 65 72 42 79 3b 20 20 20 20 20 2f 2a 20 4f 52 44 erBy; /* ORD
27a70 45 52 20 42 59 20 63 6c 61 75 73 65 20 2a 2f 0a ER BY clause */.
27a80 20 20 75 38 20 65 46 72 6d 54 79 70 65 3b 20 20 u8 eFrmType;
27a90 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f /* TK_
27aa0 52 41 4e 47 45 2c 20 54 4b 5f 47 52 4f 55 50 53 RANGE, TK_GROUPS
27ab0 2c 20 54 4b 5f 52 4f 57 53 2c 20 6f 72 20 30 20 , TK_ROWS, or 0
27ac0 2a 2f 0a 20 20 75 38 20 65 53 74 61 72 74 3b 20 */. u8 eStart;
27ad0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
27ae0 55 4e 42 4f 55 4e 44 45 44 2c 20 43 55 52 52 45 UNBOUNDED, CURRE
27af0 4e 54 2c 20 50 52 45 43 45 44 49 4e 47 20 6f 72 NT, PRECEDING or
27b00 20 46 4f 4c 4c 4f 57 49 4e 47 20 2a 2f 0a 20 20 FOLLOWING */.
27b10 75 38 20 65 45 6e 64 3b 20 20 20 20 20 20 20 20 u8 eEnd;
27b20 20 20 20 20 20 20 20 20 2f 2a 20 55 4e 42 4f 55 /* UNBOU
27b30 4e 44 45 44 2c 20 43 55 52 52 45 4e 54 2c 20 50 NDED, CURRENT, P
27b40 52 45 43 45 44 49 4e 47 20 6f 72 20 46 4f 4c 4c RECEDING or FOLL
27b50 4f 57 49 4e 47 20 2a 2f 0a 20 20 75 38 20 62 49 OWING */. u8 bI
27b60 6d 70 6c 69 63 69 74 46 72 61 6d 65 3b 20 20 20 mplicitFrame;
27b70 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 66 72 /* True if fr
27b80 61 6d 65 20 77 61 73 20 69 6d 70 6c 69 63 69 74 ame was implicit
27b90 6c 79 20 73 70 65 63 69 66 69 65 64 20 2a 2f 0a ly specified */.
27ba0 20 20 75 38 20 65 45 78 63 6c 75 64 65 3b 20 20 u8 eExclude;
27bb0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f /* TK_
27bc0 4e 4f 2c 20 54 4b 5f 43 55 52 52 45 4e 54 2c 20 NO, TK_CURRENT,
27bd0 54 4b 5f 54 49 45 53 2c 20 54 4b 5f 47 52 4f 55 TK_TIES, TK_GROU
27be0 50 2c 20 6f 72 20 30 20 2a 2f 0a 20 20 45 78 70 P, or 0 */. Exp
27bf0 72 20 2a 70 53 74 61 72 74 3b 20 20 20 20 20 20 r *pStart;
27c00 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 73 69 /* Expressi
27c10 6f 6e 20 66 6f 72 20 22 3c 65 78 70 72 3e 20 50 on for "<expr> P
27c20 52 45 43 45 44 49 4e 47 22 20 2a 2f 0a 20 20 45 RECEDING" */. E
27c30 78 70 72 20 2a 70 45 6e 64 3b 20 20 20 20 20 20 xpr *pEnd;
27c40 20 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 /* Expres
27c50 73 69 6f 6e 20 66 6f 72 20 22 3c 65 78 70 72 3e sion for "<expr>
27c60 20 46 4f 4c 4c 4f 57 49 4e 47 22 20 2a 2f 0a 20 FOLLOWING" */.
27c70 20 57 69 6e 64 6f 77 20 2a 2a 70 70 54 68 69 73 Window **ppThis
27c80 3b 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e ; /* Poin
27c90 74 65 72 20 74 6f 20 74 68 69 73 20 6f 62 6a 65 ter to this obje
27ca0 63 74 20 69 6e 20 53 65 6c 65 63 74 2e 70 57 69 ct in Select.pWi
27cb0 6e 20 6c 69 73 74 20 2a 2f 0a 20 20 57 69 6e 64 n list */. Wind
27cc0 6f 77 20 2a 70 4e 65 78 74 57 69 6e 3b 20 20 20 ow *pNextWin;
27cd0 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 69 6e 64 /* Next wind
27ce0 6f 77 20 66 75 6e 63 74 69 6f 6e 20 62 65 6c 6f ow function belo
27cf0 6e 67 69 6e 67 20 74 6f 20 74 68 69 73 20 53 45 nging to this SE
27d00 4c 45 43 54 20 2a 2f 0a 20 20 45 78 70 72 20 2a LECT */. Expr *
27d10 70 46 69 6c 74 65 72 3b 20 20 20 20 20 20 20 20 pFilter;
27d20 20 20 2f 2a 20 54 68 65 20 46 49 4c 54 45 52 20 /* The FILTER
27d30 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 expression */.
27d40 46 75 6e 63 44 65 66 20 2a 70 46 75 6e 63 3b 20 FuncDef *pFunc;
27d50 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 66 /* The f
27d60 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 69 6e 74 unction */. int
27d70 20 69 45 70 68 43 73 72 3b 20 20 20 20 20 20 20 iEphCsr;
27d80 20 20 20 20 20 2f 2a 20 50 61 72 74 69 74 69 6f /* Partitio
27d90 6e 20 62 75 66 66 65 72 20 6f 72 20 50 65 65 72 n buffer or Peer
27da0 20 62 75 66 66 65 72 20 2a 2f 0a 20 20 69 6e 74 buffer */. int
27db0 20 72 65 67 41 63 63 75 6d 3b 20 20 20 20 20 20 regAccum;
27dc0 20 20 20 20 20 2f 2a 20 41 63 63 75 6d 75 6c 61 /* Accumula
27dd0 74 6f 72 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 tor */. int reg
27de0 52 65 73 75 6c 74 3b 20 20 20 20 20 20 20 20 20 Result;
27df0 20 2f 2a 20 49 6e 74 65 72 69 6d 20 72 65 73 75 /* Interim resu
27e00 6c 74 20 2a 2f 0a 20 20 69 6e 74 20 63 73 72 41 lt */. int csrA
27e10 70 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pp;
27e20 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 63 75 72 73 /* Function curs
27e30 6f 72 20 28 75 73 65 64 20 62 79 20 6d 69 6e 2f or (used by min/
27e40 6d 61 78 29 20 2a 2f 0a 20 20 69 6e 74 20 72 65 max) */. int re
27e50 67 41 70 70 3b 20 20 20 20 20 20 20 20 20 20 20 gApp;
27e60 20 20 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 72 65 /* Function re
27e70 67 69 73 74 65 72 20 28 61 6c 73 6f 20 75 73 65 gister (also use
27e80 64 20 62 79 20 6d 69 6e 2f 6d 61 78 29 20 2a 2f d by min/max) */
27e90 0a 20 20 69 6e 74 20 72 65 67 50 61 72 74 3b 20 . int regPart;
27ea0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 /* Ar
27eb0 72 61 79 20 6f 66 20 72 65 67 69 73 74 65 72 73 ray of registers
27ec0 20 66 6f 72 20 50 41 52 54 49 54 49 4f 4e 20 42 for PARTITION B
27ed0 59 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 45 78 Y values */. Ex
27ee0 70 72 20 2a 70 4f 77 6e 65 72 3b 20 20 20 20 20 pr *pOwner;
27ef0 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 73 /* Express
27f00 69 6f 6e 20 6f 62 6a 65 63 74 20 74 68 69 73 20 ion object this
27f10 77 69 6e 64 6f 77 20 69 73 20 61 74 74 61 63 68 window is attach
27f20 65 64 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 6e ed to */. int n
27f30 42 75 66 66 65 72 43 6f 6c 3b 20 20 20 20 20 20 BufferCol;
27f40 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
27f50 63 6f 6c 75 6d 6e 73 20 69 6e 20 62 75 66 66 65 columns in buffe
27f60 72 20 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 r table */. int
27f70 20 69 41 72 67 43 6f 6c 3b 20 20 20 20 20 20 20 iArgCol;
27f80 20 20 20 20 20 2f 2a 20 4f 66 66 73 65 74 20 6f /* Offset o
27f90 66 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e 74 f first argument
27fa0 20 66 6f 72 20 74 68 69 73 20 66 75 6e 63 74 69 for this functi
27fb0 6f 6e 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 4f on */. int regO
27fc0 6e 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ne;
27fd0 2f 2a 20 52 65 67 69 73 74 65 72 20 63 6f 6e 74 /* Register cont
27fe0 61 69 6e 69 6e 67 20 63 6f 6e 73 74 61 6e 74 20 aining constant
27ff0 76 61 6c 75 65 20 31 20 2a 2f 0a 20 20 69 6e 74 value 1 */. int
28000 20 72 65 67 53 74 61 72 74 52 6f 77 69 64 3b 0a regStartRowid;.
28010 20 20 69 6e 74 20 72 65 67 45 6e 64 52 6f 77 69 int regEndRowi
28020 64 3b 0a 20 20 75 38 20 62 45 78 70 72 41 72 67 d;. u8 bExprArg
28030 73 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 s; /*
28040 44 65 66 65 72 20 65 76 61 6c 75 61 74 69 6f 6e Defer evaluation
28050 20 6f 66 20 77 69 6e 64 6f 77 20 66 75 6e 63 74 of window funct
28060 69 6f 6e 20 61 72 67 75 6d 65 6e 74 73 0a 20 20 ion arguments.
28070 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28080 20 20 20 20 20 20 20 20 2a 2a 20 64 75 65 20 74 ** due t
28090 6f 20 74 68 65 20 53 51 4c 49 54 45 5f 53 55 42 o the SQLITE_SUB
280a0 54 59 50 45 20 66 6c 61 67 20 2a 2f 0a 7d 3b 0a TYPE flag */.};.
280b0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
280c0 4f 4d 49 54 5f 57 49 4e 44 4f 57 46 55 4e 43 0a OMIT_WINDOWFUNC.
280d0 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 6e 64 void sqlite3Wind
280e0 6f 77 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 owDelete(sqlite3
280f0 2a 2c 20 57 69 6e 64 6f 77 2a 29 3b 0a 76 6f 69 *, Window*);.voi
28100 64 20 73 71 6c 69 74 65 33 57 69 6e 64 6f 77 55 d sqlite3WindowU
28110 6e 6c 69 6e 6b 46 72 6f 6d 53 65 6c 65 63 74 28 nlinkFromSelect(
28120 57 69 6e 64 6f 77 2a 29 3b 0a 76 6f 69 64 20 73 Window*);.void s
28130 71 6c 69 74 65 33 57 69 6e 64 6f 77 4c 69 73 74 qlite3WindowList
28140 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 20 2a Delete(sqlite3 *
28150 64 62 2c 20 57 69 6e 64 6f 77 20 2a 70 29 3b 0a db, Window *p);.
28160 57 69 6e 64 6f 77 20 2a 73 71 6c 69 74 65 33 57 Window *sqlite3W
28170 69 6e 64 6f 77 41 6c 6c 6f 63 28 50 61 72 73 65 indowAlloc(Parse
28180 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 45 78 70 *, int, int, Exp
28190 72 2a 2c 20 69 6e 74 20 2c 20 45 78 70 72 2a 2c r*, int , Expr*,
281a0 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 u8);.void sqlit
281b0 65 33 57 69 6e 64 6f 77 41 74 74 61 63 68 28 50 e3WindowAttach(P
281c0 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 57 69 arse*, Expr*, Wi
281d0 6e 64 6f 77 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ndow*);.void sql
281e0 69 74 65 33 57 69 6e 64 6f 77 4c 69 6e 6b 28 53 ite3WindowLink(S
281f0 65 6c 65 63 74 20 2a 70 53 65 6c 2c 20 57 69 6e elect *pSel, Win
28200 64 6f 77 20 2a 70 57 69 6e 29 3b 0a 69 6e 74 20 dow *pWin);.int
28210 73 71 6c 69 74 65 33 57 69 6e 64 6f 77 43 6f 6d sqlite3WindowCom
28220 70 61 72 65 28 50 61 72 73 65 2a 2c 20 57 69 6e pare(Parse*, Win
28230 64 6f 77 2a 2c 20 57 69 6e 64 6f 77 2a 2c 20 69 dow*, Window*, i
28240 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
28250 33 57 69 6e 64 6f 77 43 6f 64 65 49 6e 69 74 28 3WindowCodeInit(
28260 50 61 72 73 65 2a 2c 20 57 69 6e 64 6f 77 2a 29 Parse*, Window*)
28270 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 ;.void sqlite3Wi
28280 6e 64 6f 77 43 6f 64 65 53 74 65 70 28 50 61 72 ndowCodeStep(Par
28290 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 57 68 se*, Select*, Wh
282a0 65 72 65 49 6e 66 6f 2a 2c 20 69 6e 74 2c 20 69 ereInfo*, int, i
282b0 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
282c0 57 69 6e 64 6f 77 52 65 77 72 69 74 65 28 50 61 WindowRewrite(Pa
282d0 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a rse*, Select*);.
282e0 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 61 6e int sqlite3Expan
282f0 64 53 75 62 71 75 65 72 79 28 50 61 72 73 65 2a dSubquery(Parse*
28300 2c 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 , struct SrcList
28310 5f 69 74 65 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 _item*);.void sq
28320 6c 69 74 65 33 57 69 6e 64 6f 77 55 70 64 61 74 lite3WindowUpdat
28330 65 28 50 61 72 73 65 2a 2c 20 57 69 6e 64 6f 77 e(Parse*, Window
28340 2a 2c 20 57 69 6e 64 6f 77 2a 2c 20 46 75 6e 63 *, Window*, Func
28350 44 65 66 2a 29 3b 0a 57 69 6e 64 6f 77 20 2a 73 Def*);.Window *s
28360 71 6c 69 74 65 33 57 69 6e 64 6f 77 44 75 70 28 qlite3WindowDup(
28370 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 45 78 70 sqlite3 *db, Exp
28380 72 20 2a 70 4f 77 6e 65 72 2c 20 57 69 6e 64 6f r *pOwner, Windo
28390 77 20 2a 70 29 3b 0a 57 69 6e 64 6f 77 20 2a 73 w *p);.Window *s
283a0 71 6c 69 74 65 33 57 69 6e 64 6f 77 4c 69 73 74 qlite3WindowList
283b0 44 75 70 28 73 71 6c 69 74 65 33 20 2a 64 62 2c Dup(sqlite3 *db,
283c0 20 57 69 6e 64 6f 77 20 2a 70 29 3b 0a 76 6f 69 Window *p);.voi
283d0 64 20 73 71 6c 69 74 65 33 57 69 6e 64 6f 77 46 d sqlite3WindowF
283e0 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a unctions(void);.
283f0 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 6e 64 void sqlite3Wind
28400 6f 77 43 68 61 69 6e 28 50 61 72 73 65 2a 2c 20 owChain(Parse*,
28410 57 69 6e 64 6f 77 2a 2c 20 57 69 6e 64 6f 77 2a Window*, Window*
28420 29 3b 0a 57 69 6e 64 6f 77 20 2a 73 71 6c 69 74 );.Window *sqlit
28430 65 33 57 69 6e 64 6f 77 41 73 73 65 6d 62 6c 65 e3WindowAssemble
28440 28 50 61 72 73 65 2a 2c 20 57 69 6e 64 6f 77 2a (Parse*, Window*
28450 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 , ExprList*, Exp
28460 72 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b rList*, Token*);
28470 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
28480 73 71 6c 69 74 65 33 57 69 6e 64 6f 77 44 65 6c sqlite3WindowDel
28490 65 74 65 28 61 2c 62 29 0a 23 20 64 65 66 69 6e ete(a,b).# defin
284a0 65 20 73 71 6c 69 74 65 33 57 69 6e 64 6f 77 46 e sqlite3WindowF
284b0 75 6e 63 74 69 6f 6e 73 28 29 0a 23 20 64 65 66 unctions().# def
284c0 69 6e 65 20 73 71 6c 69 74 65 33 57 69 6e 64 6f ine sqlite3Windo
284d0 77 41 74 74 61 63 68 28 61 2c 62 2c 63 29 0a 23 wAttach(a,b,c).#
284e0 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 endif../*.** Ass
284f0 75 6d 69 6e 67 20 7a 49 6e 20 70 6f 69 6e 74 73 uming zIn points
28500 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 62 79 to the first by
28510 74 65 20 6f 66 20 61 20 55 54 46 2d 38 20 63 68 te of a UTF-8 ch
28520 61 72 61 63 74 65 72 2c 0a 2a 2a 20 61 64 76 61 aracter,.** adva
28530 6e 63 65 20 7a 49 6e 20 74 6f 20 70 6f 69 6e 74 nce zIn to point
28540 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 62 79 to the first by
28550 74 65 20 6f 66 20 74 68 65 20 6e 65 78 74 20 55 te of the next U
28560 54 46 2d 38 20 63 68 61 72 61 63 74 65 72 2e 0a TF-8 character..
28570 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
28580 45 5f 53 4b 49 50 5f 55 54 46 38 28 7a 49 6e 29 E_SKIP_UTF8(zIn)
28590 20 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
285a0 20 20 20 20 20 20 20 20 20 20 5c 0a 20 20 69 66 \. if
285b0 28 20 28 2a 28 7a 49 6e 2b 2b 29 29 3e 3d 30 78 ( (*(zIn++))>=0x
285c0 63 30 20 29 7b 20 20 20 20 20 20 20 20 20 20 20 c0 ){
285d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
285e0 20 20 20 5c 0a 20 20 20 20 77 68 69 6c 65 28 20 \. while(
285f0 28 2a 7a 49 6e 20 26 20 30 78 63 30 29 3d 3d 30 (*zIn & 0xc0)==0
28600 78 38 30 20 29 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 x80 ){ zIn++; }
28610 20 20 20 20 20 20 20 20 20 20 20 20 5c 0a 20 20 \.
28620 7d 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 }
28630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28650 20 20 20 20 20 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 \.}../*.**
28660 54 68 65 20 53 51 4c 49 54 45 5f 2a 5f 42 4b 50 The SQLITE_*_BKP
28670 54 20 6d 61 63 72 6f 73 20 61 72 65 20 73 75 62 T macros are sub
28680 73 74 69 74 75 74 65 73 20 66 6f 72 20 74 68 65 stitutes for the
28690 20 65 72 72 6f 72 20 63 6f 64 65 73 20 77 69 74 error codes wit
286a0 68 0a 2a 2a 20 74 68 65 20 73 61 6d 65 20 6e 61 h.** the same na
286b0 6d 65 20 62 75 74 20 77 69 74 68 6f 75 74 20 74 me but without t
286c0 68 65 20 5f 42 4b 50 54 20 73 75 66 66 69 78 2e he _BKPT suffix.
286d0 20 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 69 These macros i
286e0 6e 76 6f 6b 65 0a 2a 2a 20 72 6f 75 74 69 6e 65 nvoke.** routine
286f0 73 20 74 68 61 74 20 72 65 70 6f 72 74 20 74 68 s that report th
28700 65 20 6c 69 6e 65 2d 6e 75 6d 62 65 72 20 6f 6e e line-number on
28710 20 77 68 69 63 68 20 74 68 65 20 65 72 72 6f 72 which the error
28720 20 6f 72 69 67 69 6e 61 74 65 64 0a 2a 2a 20 75 originated.** u
28730 73 69 6e 67 20 73 71 6c 69 74 65 33 5f 6c 6f 67 sing sqlite3_log
28740 28 29 2e 20 20 54 68 65 20 72 6f 75 74 69 6e 65 (). The routine
28750 73 20 61 6c 73 6f 20 70 72 6f 76 69 64 65 20 61 s also provide a
28760 20 63 6f 6e 76 65 6e 69 65 6e 74 20 70 6c 61 63 convenient plac
28770 65 0a 2a 2a 20 74 6f 20 73 65 74 20 61 20 64 65 e.** to set a de
28780 62 75 67 67 65 72 20 62 72 65 61 6b 70 6f 69 6e bugger breakpoin
28790 74 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 t..*/.int sqlite
287a0 33 52 65 70 6f 72 74 45 72 72 6f 72 28 69 6e 74 3ReportError(int
287b0 20 69 45 72 72 2c 20 69 6e 74 20 6c 69 6e 65 6e iErr, int linen
287c0 6f 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a o, const char *z
287d0 54 79 70 65 29 3b 0a 69 6e 74 20 73 71 6c 69 74 Type);.int sqlit
287e0 65 33 43 6f 72 72 75 70 74 45 72 72 6f 72 28 69 e3CorruptError(i
287f0 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
28800 4d 69 73 75 73 65 45 72 72 6f 72 28 69 6e 74 29 MisuseError(int)
28810 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 61 6e ;.int sqlite3Can
28820 74 6f 70 65 6e 45 72 72 6f 72 28 69 6e 74 29 3b topenError(int);
28830 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
28840 43 4f 52 52 55 50 54 5f 42 4b 50 54 20 73 71 6c CORRUPT_BKPT sql
28850 69 74 65 33 43 6f 72 72 75 70 74 45 72 72 6f 72 ite3CorruptError
28860 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 65 66 69 (__LINE__).#defi
28870 6e 65 20 53 51 4c 49 54 45 5f 4d 49 53 55 53 45 ne SQLITE_MISUSE
28880 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 4d 69 73 _BKPT sqlite3Mis
28890 75 73 65 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f useError(__LINE_
288a0 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 _).#define SQLIT
288b0 45 5f 43 41 4e 54 4f 50 45 4e 5f 42 4b 50 54 20 E_CANTOPEN_BKPT
288c0 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e 45 sqlite3CantopenE
288d0 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 rror(__LINE__).#
288e0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
288f0 55 47 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 UG. int sqlite3
28900 4e 6f 6d 65 6d 45 72 72 6f 72 28 69 6e 74 29 3b NomemError(int);
28910 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 49 6f . int sqlite3Io
28920 65 72 72 6e 6f 6d 65 6d 45 72 72 6f 72 28 69 6e errnomemError(in
28930 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 t);. int sqlite
28940 33 43 6f 72 72 75 70 74 50 67 6e 6f 45 72 72 6f 3CorruptPgnoErro
28950 72 28 69 6e 74 2c 50 67 6e 6f 29 3b 0a 23 20 64 r(int,Pgno);.# d
28960 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 4d efine SQLITE_NOM
28970 45 4d 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 4e EM_BKPT sqlite3N
28980 6f 6d 65 6d 45 72 72 6f 72 28 5f 5f 4c 49 4e 45 omemError(__LINE
28990 5f 5f 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c __).# define SQL
289a0 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d 45 4d 5f ITE_IOERR_NOMEM_
289b0 42 4b 50 54 20 73 71 6c 69 74 65 33 49 6f 65 72 BKPT sqlite3Ioer
289c0 72 6e 6f 6d 65 6d 45 72 72 6f 72 28 5f 5f 4c 49 rnomemError(__LI
289d0 4e 45 5f 5f 29 0a 23 20 64 65 66 69 6e 65 20 53 NE__).# define S
289e0 51 4c 49 54 45 5f 43 4f 52 52 55 50 54 5f 50 47 QLITE_CORRUPT_PG
289f0 4e 4f 28 50 29 20 73 71 6c 69 74 65 33 43 6f 72 NO(P) sqlite3Cor
28a00 72 75 70 74 50 67 6e 6f 45 72 72 6f 72 28 5f 5f ruptPgnoError(__
28a10 4c 49 4e 45 5f 5f 2c 28 50 29 29 0a 23 65 6c 73 LINE__,(P)).#els
28a20 65 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 e.# define SQLIT
28a30 45 5f 4e 4f 4d 45 4d 5f 42 4b 50 54 20 53 51 4c E_NOMEM_BKPT SQL
28a40 49 54 45 5f 4e 4f 4d 45 4d 0a 23 20 64 65 66 69 ITE_NOMEM.# defi
28a50 6e 65 20 53 51 4c 49 54 45 5f 49 4f 45 52 52 5f ne SQLITE_IOERR_
28a60 4e 4f 4d 45 4d 5f 42 4b 50 54 20 53 51 4c 49 54 NOMEM_BKPT SQLIT
28a70 45 5f 49 4f 45 52 52 5f 4e 4f 4d 45 4d 0a 23 20 E_IOERR_NOMEM.#
28a80 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f define SQLITE_CO
28a90 52 52 55 50 54 5f 50 47 4e 4f 28 50 29 20 73 71 RRUPT_PGNO(P) sq
28aa0 6c 69 74 65 33 43 6f 72 72 75 70 74 45 72 72 6f lite3CorruptErro
28ab0 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 65 6e 64 r(__LINE__).#end
28ac0 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 33 20 61 if../*.** FTS3 a
28ad0 6e 64 20 46 54 53 34 20 62 6f 74 68 20 72 65 71 nd FTS4 both req
28ae0 75 69 72 65 20 76 69 72 74 75 61 6c 20 74 61 62 uire virtual tab
28af0 6c 65 20 73 75 70 70 6f 72 74 0a 2a 2f 0a 23 69 le support.*/.#i
28b00 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 f defined(SQLITE
28b10 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
28b20 4c 45 29 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 LE).# undef SQLI
28b30 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 0a 23 TE_ENABLE_FTS3.#
28b40 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e undef SQLITE_EN
28b50 41 42 4c 45 5f 46 54 53 34 0a 23 65 6e 64 69 66 ABLE_FTS4.#endif
28b60 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 34 20 69 73 20 ../*.** FTS4 is
28b70 72 65 61 6c 6c 79 20 61 6e 20 65 78 74 65 6e 73 really an extens
28b80 69 6f 6e 20 66 6f 72 20 46 54 53 33 2e 20 20 49 ion for FTS3. I
28b90 74 20 69 73 20 65 6e 61 62 6c 65 64 20 75 73 69 t is enabled usi
28ba0 6e 67 20 74 68 65 0a 2a 2a 20 53 51 4c 49 54 45 ng the.** SQLITE
28bb0 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 6d 61 63 _ENABLE_FTS3 mac
28bc0 72 6f 2e 20 20 42 75 74 20 74 6f 20 61 76 6f 69 ro. But to avoi
28bd0 64 20 63 6f 6e 66 75 73 69 6f 6e 20 77 65 20 61 d confusion we a
28be0 6c 73 6f 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 lso call.** the
28bf0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
28c00 53 34 20 6d 61 63 72 6f 20 74 6f 20 73 65 72 76 S4 macro to serv
28c10 65 20 61 73 20 61 6e 20 61 6c 69 61 73 20 66 6f e as an alias fo
28c20 72 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f r SQLITE_ENABLE_
28c30 46 54 53 33 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 FTS3..*/.#if def
28c40 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
28c50 4c 45 5f 46 54 53 34 29 20 26 26 20 21 64 65 66 LE_FTS4) && !def
28c60 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
28c70 4c 45 5f 46 54 53 33 29 0a 23 20 64 65 66 69 6e LE_FTS3).# defin
28c80 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f e SQLITE_ENABLE_
28c90 46 54 53 33 20 31 0a 23 65 6e 64 69 66 0a 0a 2f FTS3 1.#endif../
28ca0 2a 0a 2a 2a 20 54 68 65 20 63 74 79 70 65 2e 68 *.** The ctype.h
28cb0 20 68 65 61 64 65 72 20 69 73 20 6e 65 65 64 65 header is neede
28cc0 64 20 66 6f 72 20 6e 6f 6e 2d 41 53 43 49 49 20 d for non-ASCII
28cd0 73 79 73 74 65 6d 73 2e 20 20 49 74 20 69 73 20 systems. It is
28ce0 61 6c 73 6f 0a 2a 2a 20 6e 65 65 64 65 64 20 62 also.** needed b
28cf0 79 20 46 54 53 33 20 77 68 65 6e 20 46 54 53 33 y FTS3 when FTS3
28d00 20 69 73 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 is included in
28d10 74 68 65 20 61 6d 61 6c 67 61 6d 61 74 69 6f 6e the amalgamation
28d20 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 ..*/.#if !define
28d30 64 28 53 51 4c 49 54 45 5f 41 53 43 49 49 29 20 d(SQLITE_ASCII)
28d40 7c 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 || \. (define
28d50 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
28d60 46 54 53 33 29 20 26 26 20 64 65 66 69 6e 65 64 FTS3) && defined
28d70 28 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 (SQLITE_AMALGAMA
28d80 54 49 4f 4e 29 29 0a 23 20 69 6e 63 6c 75 64 65 TION)).# include
28d90 20 3c 63 74 79 70 65 2e 68 3e 0a 23 65 6e 64 69 <ctype.h>.#endi
28da0 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c f../*.** The fol
28db0 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 6d 69 lowing macros mi
28dc0 6d 69 63 20 74 68 65 20 73 74 61 6e 64 61 72 64 mic the standard
28dd0 20 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f library functio
28de0 6e 73 20 74 6f 75 70 70 65 72 28 29 2c 0a 2a 2a ns toupper(),.**
28df0 20 69 73 73 70 61 63 65 28 29 2c 20 69 73 61 6c isspace(), isal
28e00 6e 75 6d 28 29 2c 20 69 73 64 69 67 69 74 28 29 num(), isdigit()
28e10 20 61 6e 64 20 69 73 78 64 69 67 69 74 28 29 2c and isxdigit(),
28e20 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 54 respectively. T
28e30 68 65 0a 2a 2a 20 73 71 6c 69 74 65 20 76 65 72 he.** sqlite ver
28e40 73 69 6f 6e 73 20 6f 6e 6c 79 20 77 6f 72 6b 20 sions only work
28e50 66 6f 72 20 41 53 43 49 49 20 63 68 61 72 61 63 for ASCII charac
28e60 74 65 72 73 2c 20 72 65 67 61 72 64 6c 65 73 73 ters, regardless
28e70 20 6f 66 20 6c 6f 63 61 6c 65 2e 0a 2a 2f 0a 23 of locale..*/.#
28e80 69 66 64 65 66 20 53 51 4c 49 54 45 5f 41 53 43 ifdef SQLITE_ASC
28e90 49 49 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 II.# define sqli
28ea0 74 65 33 54 6f 75 70 70 65 72 28 78 29 20 20 28 te3Toupper(x) (
28eb0 28 78 29 26 7e 28 73 71 6c 69 74 65 33 43 74 79 (x)&~(sqlite3Cty
28ec0 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 peMap[(unsigned
28ed0 63 68 61 72 29 28 78 29 5d 26 30 78 32 30 29 29 char)(x)]&0x20))
28ee0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
28ef0 33 49 73 73 70 61 63 65 28 78 29 20 20 20 28 73 3Isspace(x) (s
28f00 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
28f10 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
28f20 29 5d 26 30 78 30 31 29 0a 23 20 64 65 66 69 6e )]&0x01).# defin
28f30 65 20 73 71 6c 69 74 65 33 49 73 61 6c 6e 75 6d e sqlite3Isalnum
28f40 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
28f50 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
28f60 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 36 29 char)(x)]&0x06)
28f70 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
28f80 33 49 73 61 6c 70 68 61 28 78 29 20 20 20 28 73 3Isalpha(x) (s
28f90 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
28fa0 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
28fb0 29 5d 26 30 78 30 32 29 0a 23 20 64 65 66 69 6e )]&0x02).# defin
28fc0 65 20 73 71 6c 69 74 65 33 49 73 64 69 67 69 74 e sqlite3Isdigit
28fd0 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
28fe0 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
28ff0 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 34 29 char)(x)]&0x04)
29000 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
29010 33 49 73 78 64 69 67 69 74 28 78 29 20 20 28 73 3Isxdigit(x) (s
29020 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
29030 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
29040 29 5d 26 30 78 30 38 29 0a 23 20 64 65 66 69 6e )]&0x08).# defin
29050 65 20 73 71 6c 69 74 65 33 54 6f 6c 6f 77 65 72 e sqlite3Tolower
29060 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 55 70 (x) (sqlite3Up
29070 70 65 72 54 6f 4c 6f 77 65 72 5b 28 75 6e 73 69 perToLower[(unsi
29080 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 29 0a gned char)(x)]).
29090 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
290a0 49 73 71 75 6f 74 65 28 78 29 20 20 20 28 73 71 Isquote(x) (sq
290b0 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
290c0 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
290d0 5d 26 30 78 38 30 29 0a 23 65 6c 73 65 0a 23 20 ]&0x80).#else.#
290e0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f define sqlite3To
290f0 75 70 70 65 72 28 78 29 20 20 20 74 6f 75 70 70 upper(x) toupp
29100 65 72 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er((unsigned cha
29110 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
29120 73 71 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 sqlite3Isspace(x
29130 29 20 20 20 69 73 73 70 61 63 65 28 28 75 6e 73 ) isspace((uns
29140 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
29150 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
29160 49 73 61 6c 6e 75 6d 28 78 29 20 20 20 69 73 61 Isalnum(x) isa
29170 6c 6e 75 6d 28 28 75 6e 73 69 67 6e 65 64 20 63 lnum((unsigned c
29180 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
29190 65 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 e sqlite3Isalpha
291a0 28 78 29 20 20 20 69 73 61 6c 70 68 61 28 28 75 (x) isalpha((u
291b0 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
291c0 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
291d0 65 33 49 73 64 69 67 69 74 28 78 29 20 20 20 69 e3Isdigit(x) i
291e0 73 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 sdigit((unsigned
291f0 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 char)(x)).# def
29200 69 6e 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 ine sqlite3Isxdi
29210 67 69 74 28 78 29 20 20 69 73 78 64 69 67 69 74 git(x) isxdigit
29220 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
29230 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
29240 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 lite3Tolower(x)
29250 20 20 74 6f 6c 6f 77 65 72 28 28 75 6e 73 69 67 tolower((unsig
29260 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 ned char)(x)).#
29270 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
29280 71 75 6f 74 65 28 78 29 20 20 20 28 28 78 29 3d quote(x) ((x)=
29290 3d 27 22 27 7c 7c 28 78 29 3d 3d 27 5c 27 27 7c ='"'||(x)=='\''|
292a0 7c 28 78 29 3d 3d 27 5b 27 7c 7c 28 78 29 3d 3d |(x)=='['||(x)==
292b0 27 60 27 29 0a 23 65 6e 64 69 66 0a 69 6e 74 20 '`').#endif.int
292c0 73 71 6c 69 74 65 33 49 73 49 64 43 68 61 72 28 sqlite3IsIdChar(
292d0 75 38 29 3b 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 u8);../*.** Inte
292e0 72 6e 61 6c 20 66 75 6e 63 74 69 6f 6e 20 70 72 rnal function pr
292f0 6f 74 6f 74 79 70 65 73 0a 2a 2f 0a 69 6e 74 20 ototypes.*/.int
29300 73 71 6c 69 74 65 33 53 74 72 49 43 6d 70 28 63 sqlite3StrICmp(c
29310 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 onst char*,const
29320 20 63 68 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c char*);.int sql
29330 69 74 65 33 53 74 72 6c 65 6e 33 30 28 63 6f 6e ite3Strlen30(con
29340 73 74 20 63 68 61 72 2a 29 3b 0a 23 64 65 66 69 st char*);.#defi
29350 6e 65 20 73 71 6c 69 74 65 33 53 74 72 6c 65 6e ne sqlite3Strlen
29360 33 30 4e 4e 28 43 29 20 28 73 74 72 6c 65 6e 28 30NN(C) (strlen(
29370 43 29 26 30 78 33 66 66 66 66 66 66 66 29 0a 63 C)&0x3fffffff).c
29380 68 61 72 20 2a 73 71 6c 69 74 65 33 43 6f 6c 75 har *sqlite3Colu
29390 6d 6e 54 79 70 65 28 43 6f 6c 75 6d 6e 2a 2c 63 mnType(Column*,c
293a0 68 61 72 2a 29 3b 0a 23 64 65 66 69 6e 65 20 73 har*);.#define s
293b0 71 6c 69 74 65 33 53 74 72 4e 49 43 6d 70 20 73 qlite3StrNICmp s
293c0 71 6c 69 74 65 33 5f 73 74 72 6e 69 63 6d 70 0a qlite3_strnicmp.
293d0 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c .int sqlite3Mall
293e0 6f 63 49 6e 69 74 28 76 6f 69 64 29 3b 0a 76 6f ocInit(void);.vo
293f0 69 64 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 id sqlite3Malloc
29400 45 6e 64 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 End(void);.void
29410 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 28 75 *sqlite3Malloc(u
29420 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 64);.void *sqlit
29430 65 33 4d 61 6c 6c 6f 63 5a 65 72 6f 28 75 36 34 e3MallocZero(u64
29440 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
29450 44 62 4d 61 6c 6c 6f 63 5a 65 72 6f 28 73 71 6c DbMallocZero(sql
29460 69 74 65 33 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 ite3*, u64);.voi
29470 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c d *sqlite3DbMall
29480 6f 63 52 61 77 28 73 71 6c 69 74 65 33 2a 2c 20 ocRaw(sqlite3*,
29490 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 u64);.void *sqli
294a0 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 4e 4e te3DbMallocRawNN
294b0 28 73 71 6c 69 74 65 33 2a 2c 20 75 36 34 29 3b (sqlite3*, u64);
294c0 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 44 62 .char *sqlite3Db
294d0 53 74 72 44 75 70 28 73 71 6c 69 74 65 33 2a 2c StrDup(sqlite3*,
294e0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 63 68 const char*);.ch
294f0 61 72 20 2a 73 71 6c 69 74 65 33 44 62 53 74 72 ar *sqlite3DbStr
29500 4e 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 63 6f NDup(sqlite3*,co
29510 6e 73 74 20 63 68 61 72 2a 2c 20 75 36 34 29 3b nst char*, u64);
29520 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 44 62 .char *sqlite3Db
29530 53 70 61 6e 44 75 70 28 73 71 6c 69 74 65 33 2a SpanDup(sqlite3*
29540 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e ,const char*,con
29550 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
29560 2a 73 71 6c 69 74 65 33 52 65 61 6c 6c 6f 63 28 *sqlite3Realloc(
29570 76 6f 69 64 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 void*, u64);.voi
29580 64 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 6c d *sqlite3DbReal
29590 6c 6f 63 4f 72 46 72 65 65 28 73 71 6c 69 74 65 locOrFree(sqlite
295a0 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 3 *, void *, u64
295b0 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
295c0 44 62 52 65 61 6c 6c 6f 63 28 73 71 6c 69 74 65 DbRealloc(sqlite
295d0 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 3 *, void *, u64
295e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
295f0 62 46 72 65 65 28 73 71 6c 69 74 65 33 2a 2c 20 bFree(sqlite3*,
29600 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c void*);.void sql
29610 69 74 65 33 44 62 46 72 65 65 4e 4e 28 73 71 6c ite3DbFreeNN(sql
29620 69 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 69 ite3*, void*);.i
29630 6e 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 nt sqlite3Malloc
29640 53 69 7a 65 28 76 6f 69 64 2a 29 3b 0a 69 6e 74 Size(void*);.int
29650 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 sqlite3DbMalloc
29660 53 69 7a 65 28 73 71 6c 69 74 65 33 2a 2c 20 76 Size(sqlite3*, v
29670 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 2a 73 71 6c oid*);.void *sql
29680 69 74 65 33 50 61 67 65 4d 61 6c 6c 6f 63 28 69 ite3PageMalloc(i
29690 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
296a0 33 50 61 67 65 46 72 65 65 28 76 6f 69 64 2a 29 3PageFree(void*)
296b0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 ;.void sqlite3Me
296c0 6d 53 65 74 44 65 66 61 75 6c 74 28 76 6f 69 64 mSetDefault(void
296d0 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
296e0 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a 76 6f 69 E_UNTESTABLE.voi
296f0 64 20 73 71 6c 69 74 65 33 42 65 6e 69 67 6e 4d d sqlite3BenignM
29700 61 6c 6c 6f 63 48 6f 6f 6b 73 28 76 6f 69 64 20 allocHooks(void
29710 28 2a 29 28 76 6f 69 64 29 2c 20 76 6f 69 64 20 (*)(void), void
29720 28 2a 29 28 76 6f 69 64 29 29 3b 0a 23 65 6e 64 (*)(void));.#end
29730 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 48 65 if.int sqlite3He
29740 61 70 4e 65 61 72 6c 79 46 75 6c 6c 28 76 6f 69 apNearlyFull(voi
29750 64 29 3b 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 20 73 79 d);../*.** On sy
29760 73 74 65 6d 73 20 77 69 74 68 20 61 6d 70 6c 65 stems with ample
29770 20 73 74 61 63 6b 20 73 70 61 63 65 20 61 6e 64 stack space and
29780 20 74 68 61 74 20 73 75 70 70 6f 72 74 20 61 6c that support al
29790 6c 6f 63 61 28 29 2c 20 6d 61 6b 65 0a 2a 2a 20 loca(), make.**
297a0 75 73 65 20 6f 66 20 61 6c 6c 6f 63 61 28 29 20 use of alloca()
297b0 74 6f 20 6f 62 74 61 69 6e 20 73 70 61 63 65 20 to obtain space
297c0 66 6f 72 20 6c 61 72 67 65 20 61 75 74 6f 6d 61 for large automa
297d0 74 69 63 20 6f 62 6a 65 63 74 73 2e 20 20 42 79 tic objects. By
297e0 20 64 65 66 61 75 6c 74 2c 0a 2a 2a 20 6f 62 74 default,.** obt
297f0 61 69 6e 20 73 70 61 63 65 20 66 72 6f 6d 20 6d ain space from m
29800 61 6c 6c 6f 63 28 29 2e 0a 2a 2a 0a 2a 2a 20 54 alloc()..**.** T
29810 68 65 20 61 6c 6c 6f 63 61 28 29 20 72 6f 75 74 he alloca() rout
29820 69 6e 65 20 6e 65 76 65 72 20 72 65 74 75 72 6e ine never return
29830 73 20 4e 55 4c 4c 2e 20 20 54 68 69 73 20 77 69 s NULL. This wi
29840 6c 6c 20 63 61 75 73 65 20 63 6f 64 65 20 70 61 ll cause code pa
29850 74 68 73 0a 2a 2a 20 74 68 61 74 20 64 65 61 6c ths.** that deal
29860 20 77 69 74 68 20 73 71 6c 69 74 65 33 53 74 61 with sqlite3Sta
29870 63 6b 41 6c 6c 6f 63 28 29 20 66 61 69 6c 75 72 ckAlloc() failur
29880 65 73 20 74 6f 20 62 65 20 75 6e 72 65 61 63 68 es to be unreach
29890 61 62 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 able..*/.#ifdef
298a0 53 51 4c 49 54 45 5f 55 53 45 5f 41 4c 4c 4f 43 SQLITE_USE_ALLOC
298b0 41 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 A.# define sqlit
298c0 65 33 53 74 61 63 6b 41 6c 6c 6f 63 52 61 77 28 e3StackAllocRaw(
298d0 44 2c 4e 29 20 20 20 61 6c 6c 6f 63 61 28 4e 29 D,N) alloca(N)
298e0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
298f0 33 53 74 61 63 6b 41 6c 6c 6f 63 5a 65 72 6f 28 3StackAllocZero(
29900 44 2c 4e 29 20 20 6d 65 6d 73 65 74 28 61 6c 6c D,N) memset(all
29910 6f 63 61 28 4e 29 2c 20 30 2c 20 4e 29 0a 23 20 oca(N), 0, N).#
29920 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 define sqlite3St
29930 61 63 6b 46 72 65 65 28 44 2c 50 29 0a 23 65 6c ackFree(D,P).#el
29940 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
29950 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 52 61 77 te3StackAllocRaw
29960 28 44 2c 4e 29 20 20 20 73 71 6c 69 74 65 33 44 (D,N) sqlite3D
29970 62 4d 61 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 0a bMallocRaw(D,N).
29980 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
29990 53 74 61 63 6b 41 6c 6c 6f 63 5a 65 72 6f 28 44 StackAllocZero(D
299a0 2c 4e 29 20 20 73 71 6c 69 74 65 33 44 62 4d 61 ,N) sqlite3DbMa
299b0 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 0a 23 20 llocZero(D,N).#
299c0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 define sqlite3St
299d0 61 63 6b 46 72 65 65 28 44 2c 50 29 20 20 20 20 ackFree(D,P)
299e0 20 20 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 sqlite3DbFree
299f0 28 44 2c 50 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a (D,P).#endif../*
29a00 20 44 6f 20 6e 6f 74 20 61 6c 6c 6f 77 20 62 6f Do not allow bo
29a10 74 68 20 4d 45 4d 53 59 53 35 20 61 6e 64 20 4d th MEMSYS5 and M
29a20 45 4d 53 59 53 33 20 74 6f 20 62 65 20 64 65 66 EMSYS3 to be def
29a30 69 6e 65 64 20 74 6f 67 65 74 68 65 72 2e 20 20 ined together.
29a40 49 66 20 74 68 65 79 0a 2a 2a 20 61 72 65 2c 20 If they.** are,
29a50 64 69 73 61 62 6c 65 20 4d 45 4d 53 59 53 33 0a disable MEMSYS3.
29a60 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
29a70 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 35 0a _ENABLE_MEMSYS5.
29a80 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 65 const sqlite3_me
29a90 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 74 m_methods *sqlit
29aa0 65 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 35 28 e3MemGetMemsys5(
29ab0 76 6f 69 64 29 3b 0a 23 75 6e 64 65 66 20 53 51 void);.#undef SQ
29ac0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 LITE_ENABLE_MEMS
29ad0 59 53 33 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 YS3.#endif.#ifde
29ae0 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
29af0 4d 45 4d 53 59 53 33 0a 63 6f 6e 73 74 20 73 71 MEMSYS3.const sq
29b00 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 lite3_mem_method
29b10 73 20 2a 73 71 6c 69 74 65 33 4d 65 6d 47 65 74 s *sqlite3MemGet
29b20 4d 65 6d 73 79 73 33 28 76 6f 69 64 29 3b 0a 23 Memsys3(void);.#
29b30 65 6e 64 69 66 0a 0a 0a 23 69 66 6e 64 65 66 20 endif...#ifndef
29b40 53 51 4c 49 54 45 5f 4d 55 54 45 58 5f 4f 4d 49 SQLITE_MUTEX_OMI
29b50 54 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 T. sqlite3_mute
29b60 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e 73 74 20 x_methods const
29b70 2a 73 71 6c 69 74 65 33 44 65 66 61 75 6c 74 4d *sqlite3DefaultM
29b80 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 utex(void);. sq
29b90 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 lite3_mutex_meth
29ba0 6f 64 73 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 ods const *sqlit
29bb0 65 33 4e 6f 6f 70 4d 75 74 65 78 28 76 6f 69 64 e3NoopMutex(void
29bc0 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 );. sqlite3_mut
29bd0 65 78 20 2a 73 71 6c 69 74 65 33 4d 75 74 65 78 ex *sqlite3Mutex
29be0 41 6c 6c 6f 63 28 69 6e 74 29 3b 0a 20 20 69 6e Alloc(int);. in
29bf0 74 20 73 71 6c 69 74 65 33 4d 75 74 65 78 49 6e t sqlite3MutexIn
29c00 69 74 28 76 6f 69 64 29 3b 0a 20 20 69 6e 74 20 it(void);. int
29c10 73 71 6c 69 74 65 33 4d 75 74 65 78 45 6e 64 28 sqlite3MutexEnd(
29c20 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 23 69 void);.#endif.#i
29c30 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 f !defined(SQLIT
29c40 45 5f 4d 55 54 45 58 5f 4f 4d 49 54 29 20 26 26 E_MUTEX_OMIT) &&
29c50 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
29c60 5f 4d 55 54 45 58 5f 4e 4f 4f 50 29 0a 20 20 76 _MUTEX_NOOP). v
29c70 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d 6f 72 oid sqlite3Memor
29c80 79 42 61 72 72 69 65 72 28 76 6f 69 64 29 3b 0a yBarrier(void);.
29c90 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
29ca0 71 6c 69 74 65 33 4d 65 6d 6f 72 79 42 61 72 72 qlite3MemoryBarr
29cb0 69 65 72 28 29 0a 23 65 6e 64 69 66 0a 0a 73 71 ier().#endif..sq
29cc0 6c 69 74 65 33 5f 69 6e 74 36 34 20 73 71 6c 69 lite3_int64 sqli
29cd0 74 65 33 53 74 61 74 75 73 56 61 6c 75 65 28 69 te3StatusValue(i
29ce0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
29cf0 33 53 74 61 74 75 73 55 70 28 69 6e 74 2c 20 69 3StatusUp(int, i
29d00 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
29d10 33 53 74 61 74 75 73 44 6f 77 6e 28 69 6e 74 2c 3StatusDown(int,
29d20 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
29d30 74 65 33 53 74 61 74 75 73 48 69 67 68 77 61 74 te3StatusHighwat
29d40 65 72 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 69 6e er(int, int);.in
29d50 74 20 73 71 6c 69 74 65 33 4c 6f 6f 6b 61 73 69 t sqlite3Lookasi
29d60 64 65 55 73 65 64 28 73 71 6c 69 74 65 33 2a 2c deUsed(sqlite3*,
29d70 69 6e 74 2a 29 3b 0a 0a 2f 2a 20 41 63 63 65 73 int*);../* Acces
29d80 73 20 74 6f 20 6d 75 74 65 78 65 73 20 75 73 65 s to mutexes use
29d90 64 20 62 79 20 73 71 6c 69 74 65 33 5f 73 74 61 d by sqlite3_sta
29da0 74 75 73 28 29 20 2a 2f 0a 73 71 6c 69 74 65 33 tus() */.sqlite3
29db0 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 50 _mutex *sqlite3P
29dc0 63 61 63 68 65 31 4d 75 74 65 78 28 76 6f 69 64 cache1Mutex(void
29dd0 29 3b 0a 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 );.sqlite3_mutex
29de0 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 4d *sqlite3MallocM
29df0 75 74 65 78 28 76 6f 69 64 29 3b 0a 0a 23 69 66 utex(void);..#if
29e00 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
29e10 45 4e 41 42 4c 45 5f 4d 55 4c 54 49 54 48 52 45 ENABLE_MULTITHRE
29e20 41 44 45 44 5f 43 48 45 43 4b 53 29 20 26 26 20 ADED_CHECKS) &&
29e30 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
29e40 4d 55 54 45 58 5f 4f 4d 49 54 29 0a 76 6f 69 64 MUTEX_OMIT).void
29e50 20 73 71 6c 69 74 65 33 4d 75 74 65 78 57 61 72 sqlite3MutexWar
29e60 6e 4f 6e 43 6f 6e 74 65 6e 74 69 6f 6e 28 73 71 nOnContention(sq
29e70 6c 69 74 65 33 5f 6d 75 74 65 78 2a 29 3b 0a 23 lite3_mutex*);.#
29e80 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
29e90 6c 69 74 65 33 4d 75 74 65 78 57 61 72 6e 4f 6e lite3MutexWarnOn
29ea0 43 6f 6e 74 65 6e 74 69 6f 6e 28 78 29 0a 23 65 Contention(x).#e
29eb0 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 ndif..#ifndef SQ
29ec0 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 LITE_OMIT_FLOATI
29ed0 4e 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 6e NG_POINT.# defin
29ee0 65 20 45 58 50 37 35 34 20 28 28 28 75 36 34 29 e EXP754 (((u64)
29ef0 30 78 37 66 66 29 3c 3c 35 32 29 0a 23 20 64 65 0x7ff)<<52).# de
29f00 66 69 6e 65 20 4d 41 4e 37 35 34 20 28 28 28 28 fine MAN754 ((((
29f10 75 36 34 29 31 29 3c 3c 35 32 29 2d 31 29 0a 23 u64)1)<<52)-1).#
29f20 20 64 65 66 69 6e 65 20 49 73 4e 61 4e 28 58 29 define IsNaN(X)
29f30 20 28 28 28 58 29 26 45 58 50 37 35 34 29 3d 3d (((X)&EXP754)==
29f40 45 58 50 37 35 34 20 26 26 20 28 28 58 29 26 4d EXP754 && ((X)&M
29f50 41 4e 37 35 34 29 21 3d 30 29 0a 20 20 69 6e 74 AN754)!=0). int
29f60 20 73 71 6c 69 74 65 33 49 73 4e 61 4e 28 64 6f sqlite3IsNaN(do
29f70 75 62 6c 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 uble);.#else.# d
29f80 65 66 69 6e 65 20 49 73 4e 61 4e 28 58 29 20 20 efine IsNaN(X)
29f90 20 20 20 20 20 20 20 30 0a 23 20 64 65 66 69 6e 0.# defin
29fa0 65 20 73 71 6c 69 74 65 33 49 73 4e 61 4e 28 58 e sqlite3IsNaN(X
29fb0 29 20 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a ) 0.#endif../*.
29fc0 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
29fd0 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
29fe0 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 73 20 structure holds
29ff0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 information abou
2a000 74 20 53 51 4c 0a 2a 2a 20 66 75 6e 63 74 69 6f t SQL.** functio
2a010 6e 73 20 61 72 67 75 6d 65 6e 74 73 20 74 68 61 ns arguments tha
2a020 74 20 61 72 65 20 74 68 65 20 70 61 72 61 6d 65 t are the parame
2a030 74 65 72 73 20 74 6f 20 74 68 65 20 70 72 69 6e ters to the prin
2a040 74 66 28 29 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a tf() function..*
2a050 2f 0a 73 74 72 75 63 74 20 50 72 69 6e 74 66 41 /.struct PrintfA
2a060 72 67 75 6d 65 6e 74 73 20 7b 0a 20 20 69 6e 74 rguments {. int
2a070 20 6e 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 nArg;
2a080 20 20 20 20 20 20 2f 2a 20 54 6f 74 61 6c 20 6e /* Total n
2a090 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e umber of argumen
2a0a0 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 55 73 65 ts */. int nUse
2a0b0 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 d;
2a0c0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 72 /* Number of ar
2a0d0 67 75 6d 65 6e 74 73 20 75 73 65 64 20 73 6f 20 guments used so
2a0e0 66 61 72 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 far */. sqlite3
2a0f0 5f 76 61 6c 75 65 20 2a 2a 61 70 41 72 67 3b 20 _value **apArg;
2a100 20 20 2f 2a 20 54 68 65 20 61 72 67 75 6d 65 6e /* The argumen
2a110 74 20 76 61 6c 75 65 73 20 2a 2f 0a 7d 3b 0a 0a t values */.};..
2a120 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4d 50 72 char *sqlite3MPr
2a130 69 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f intf(sqlite3*,co
2a140 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b nst char*, ...);
2a150 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 56 4d .char *sqlite3VM
2a160 50 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c Printf(sqlite3*,
2a170 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 5f const char*, va_
2a180 6c 69 73 74 29 3b 0a 23 69 66 20 64 65 66 69 6e list);.#if defin
2a190 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 ed(SQLITE_DEBUG)
2a1a0 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 || defined(SQLI
2a1b0 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 TE_HAVE_OS_TRACE
2a1c0 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ). void sqlite3
2a1d0 44 65 62 75 67 50 72 69 6e 74 66 28 63 6f 6e 73 DebugPrintf(cons
2a1e0 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 23 t char*, ...);.#
2a1f0 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 endif.#if define
2a200 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a 20 d(SQLITE_TEST).
2a210 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 54 65 void *sqlite3Te
2a220 73 74 54 65 78 74 54 6f 50 74 72 28 63 6f 6e 73 stTextToPtr(cons
2a230 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 t char*);.#endif
2a240 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 ..#if defined(SQ
2a250 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 20 76 6f LITE_DEBUG). vo
2a260 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 id sqlite3TreeVi
2a270 65 77 45 78 70 72 28 54 72 65 65 56 69 65 77 2a ewExpr(TreeView*
2a280 2c 20 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 75 , const Expr*, u
2a290 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 8);. void sqlit
2a2a0 65 33 54 72 65 65 56 69 65 77 42 61 72 65 45 78 e3TreeViewBareEx
2a2b0 70 72 4c 69 73 74 28 54 72 65 65 56 69 65 77 2a prList(TreeView*
2a2c0 2c 20 63 6f 6e 73 74 20 45 78 70 72 4c 69 73 74 , const ExprList
2a2d0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
2a2e0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 . void sqlite3T
2a2f0 72 65 65 56 69 65 77 45 78 70 72 4c 69 73 74 28 reeViewExprList(
2a300 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 TreeView*, const
2a310 20 45 78 70 72 4c 69 73 74 2a 2c 20 75 38 2c 20 ExprList*, u8,
2a320 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 const char*);.
2a330 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 void sqlite3Tree
2a340 56 69 65 77 53 72 63 4c 69 73 74 28 54 72 65 65 ViewSrcList(Tree
2a350 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 53 72 63 View*, const Src
2a360 4c 69 73 74 2a 29 3b 0a 20 20 76 6f 69 64 20 73 List*);. void s
2a370 71 6c 69 74 65 33 54 72 65 65 56 69 65 77 53 65 qlite3TreeViewSe
2a380 6c 65 63 74 28 54 72 65 65 56 69 65 77 2a 2c 20 lect(TreeView*,
2a390 63 6f 6e 73 74 20 53 65 6c 65 63 74 2a 2c 20 75 const Select*, u
2a3a0 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 8);. void sqlit
2a3b0 65 33 54 72 65 65 56 69 65 77 57 69 74 68 28 54 e3TreeViewWith(T
2a3c0 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 reeView*, const
2a3d0 57 69 74 68 2a 2c 20 75 38 29 3b 0a 23 69 66 6e With*, u8);.#ifn
2a3e0 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
2a3f0 57 49 4e 44 4f 57 46 55 4e 43 0a 20 20 76 6f 69 WINDOWFUNC. voi
2a400 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 65 d sqlite3TreeVie
2a410 77 57 69 6e 64 6f 77 28 54 72 65 65 56 69 65 77 wWindow(TreeView
2a420 2a 2c 20 63 6f 6e 73 74 20 57 69 6e 64 6f 77 2a *, const Window*
2a430 2c 20 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 , u8);. void sq
2a440 6c 69 74 65 33 54 72 65 65 56 69 65 77 57 69 6e lite3TreeViewWin
2a450 46 75 6e 63 28 54 72 65 65 56 69 65 77 2a 2c 20 Func(TreeView*,
2a460 63 6f 6e 73 74 20 57 69 6e 64 6f 77 2a 2c 20 75 const Window*, u
2a470 38 29 3b 0a 23 65 6e 64 69 66 0a 23 65 6e 64 69 8);.#endif.#endi
2a480 66 0a 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 f...void sqlite3
2a490 53 65 74 53 74 72 69 6e 67 28 63 68 61 72 20 2a SetString(char *
2a4a0 2a 2c 20 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e *, sqlite3*, con
2a4b0 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
2a4c0 73 71 6c 69 74 65 33 45 72 72 6f 72 4d 73 67 28 sqlite3ErrorMsg(
2a4d0 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 Parse*, const ch
2a4e0 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 69 6e 74 20 73 ar*, ...);.int s
2a4f0 71 6c 69 74 65 33 45 72 72 6f 72 54 6f 50 61 72 qlite3ErrorToPar
2a500 73 65 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ser(sqlite3*,int
2a510 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
2a520 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 0a 76 equote(char*);.v
2a530 6f 69 64 20 73 71 6c 69 74 65 33 44 65 71 75 6f oid sqlite3Dequo
2a540 74 65 45 78 70 72 28 45 78 70 72 2a 29 3b 0a 76 teExpr(Expr*);.v
2a550 6f 69 64 20 73 71 6c 69 74 65 33 54 6f 6b 65 6e oid sqlite3Token
2a560 49 6e 69 74 28 54 6f 6b 65 6e 2a 2c 63 68 61 72 Init(Token*,char
2a570 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b *);.int sqlite3K
2a580 65 79 77 6f 72 64 43 6f 64 65 28 63 6f 6e 73 74 eywordCode(const
2a590 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 2c unsigned char*,
2a5a0 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
2a5b0 65 33 52 75 6e 50 61 72 73 65 72 28 50 61 72 73 e3RunParser(Pars
2a5c0 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c e*, const char*,
2a5d0 20 63 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 20 char **);.void
2a5e0 73 71 6c 69 74 65 33 46 69 6e 69 73 68 43 6f 64 sqlite3FinishCod
2a5f0 69 6e 67 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 ing(Parse*);.int
2a600 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d 70 52 sqlite3GetTempR
2a610 65 67 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 eg(Parse*);.void
2a620 20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 sqlite3ReleaseT
2a630 65 6d 70 52 65 67 28 50 61 72 73 65 2a 2c 69 6e empReg(Parse*,in
2a640 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 t);.int sqlite3G
2a650 65 74 54 65 6d 70 52 61 6e 67 65 28 50 61 72 73 etTempRange(Pars
2a660 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 e*,int);.void sq
2a670 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 lite3ReleaseTemp
2a680 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e 74 Range(Parse*,int
2a690 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
2a6a0 74 65 33 43 6c 65 61 72 54 65 6d 70 52 65 67 43 te3ClearTempRegC
2a6b0 61 63 68 65 28 50 61 72 73 65 2a 29 3b 0a 23 69 ache(Parse*);.#i
2a6c0 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 fdef SQLITE_DEBU
2a6d0 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f 54 G.int sqlite3NoT
2a6e0 65 6d 70 73 49 6e 52 61 6e 67 65 28 50 61 72 73 empsInRange(Pars
2a6f0 65 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 23 65 6e e*,int,int);.#en
2a700 64 69 66 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 dif.Expr *sqlite
2a710 33 45 78 70 72 41 6c 6c 6f 63 28 73 71 6c 69 74 3ExprAlloc(sqlit
2a720 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 54 6f e3*,int,const To
2a730 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 45 78 70 72 20 ken*,int);.Expr
2a740 2a 73 71 6c 69 74 65 33 45 78 70 72 28 73 71 6c *sqlite3Expr(sql
2a750 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 ite3*,int,const
2a760 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c char*);.void sql
2a770 69 74 65 33 45 78 70 72 41 74 74 61 63 68 53 75 ite3ExprAttachSu
2a780 62 74 72 65 65 73 28 73 71 6c 69 74 65 33 2a 2c btrees(sqlite3*,
2a790 45 78 70 72 2a 2c 45 78 70 72 2a 2c 45 78 70 72 Expr*,Expr*,Expr
2a7a0 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 *);.Expr *sqlite
2a7b0 33 50 45 78 70 72 28 50 61 72 73 65 2a 2c 20 69 3PExpr(Parse*, i
2a7c0 6e 74 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a nt, Expr*, Expr*
2a7d0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
2a7e0 45 78 70 72 41 64 64 53 65 6c 65 63 74 28 50 61 ExprAddSelect(Pa
2a7f0 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 53 65 6c rse*, Expr*, Sel
2a800 65 63 74 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c ect*);.Expr *sql
2a810 69 74 65 33 45 78 70 72 41 6e 64 28 50 61 72 73 ite3ExprAnd(Pars
2a820 65 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 2a 29 e*,Expr*, Expr*)
2a830 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 ;.Expr *sqlite3E
2a840 78 70 72 53 69 6d 70 6c 69 66 69 65 64 41 6e 64 xprSimplifiedAnd
2a850 4f 72 28 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 Or(Expr*);.Expr
2a860 2a 73 71 6c 69 74 65 33 45 78 70 72 46 75 6e 63 *sqlite3ExprFunc
2a870 74 69 6f 6e 28 50 61 72 73 65 2a 2c 45 78 70 72 tion(Parse*,Expr
2a880 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 69 List*, Token*, i
2a890 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
2a8a0 33 45 78 70 72 41 73 73 69 67 6e 56 61 72 4e 75 3ExprAssignVarNu
2a8b0 6d 62 65 72 28 50 61 72 73 65 2a 2c 20 45 78 70 mber(Parse*, Exp
2a8c0 72 2a 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 r*, u32);.void s
2a8d0 71 6c 69 74 65 33 45 78 70 72 44 65 6c 65 74 65 qlite3ExprDelete
2a8e0 28 73 71 6c 69 74 65 33 2a 2c 20 45 78 70 72 2a (sqlite3*, Expr*
2a8f0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
2a900 78 70 72 55 6e 6d 61 70 41 6e 64 44 65 6c 65 74 xprUnmapAndDelet
2a910 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 e(Parse*, Expr*)
2a920 3b 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 ;.ExprList *sqli
2a930 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e te3ExprListAppen
2a940 64 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 d(Parse*,ExprLis
2a950 74 2a 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 4c t*,Expr*);.ExprL
2a960 69 73 74 20 2a 73 71 6c 69 74 65 33 45 78 70 72 ist *sqlite3Expr
2a970 4c 69 73 74 41 70 70 65 6e 64 56 65 63 74 6f 72 ListAppendVector
2a980 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 (Parse*,ExprList
2a990 2a 2c 49 64 4c 69 73 74 2a 2c 45 78 70 72 2a 29 *,IdList*,Expr*)
2a9a0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
2a9b0 70 72 4c 69 73 74 53 65 74 53 6f 72 74 4f 72 64 prListSetSortOrd
2a9c0 65 72 28 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 er(ExprList*,int
2a9d0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
2a9e0 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 4e 61 te3ExprListSetNa
2a9f0 6d 65 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 me(Parse*,ExprLi
2aa00 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b st*,Token*,int);
2aa10 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
2aa20 72 4c 69 73 74 53 65 74 53 70 61 6e 28 50 61 72 rListSetSpan(Par
2aa30 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 63 6f se*,ExprList*,co
2aa40 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 nst char*,const
2aa50 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c char*);.void sql
2aa60 69 74 65 33 45 78 70 72 4c 69 73 74 44 65 6c 65 ite3ExprListDele
2aa70 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 45 78 70 te(sqlite3*, Exp
2aa80 72 4c 69 73 74 2a 29 3b 0a 75 33 32 20 73 71 6c rList*);.u32 sql
2aa90 69 74 65 33 45 78 70 72 4c 69 73 74 46 6c 61 67 ite3ExprListFlag
2aaa0 73 28 63 6f 6e 73 74 20 45 78 70 72 4c 69 73 74 s(const ExprList
2aab0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 *);.int sqlite3I
2aac0 6e 64 65 78 48 61 73 44 75 70 6c 69 63 61 74 65 ndexHasDuplicate
2aad0 52 6f 6f 74 50 61 67 65 28 49 6e 64 65 78 2a 29 RootPage(Index*)
2aae0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 69 ;.int sqlite3Ini
2aaf0 74 28 73 71 6c 69 74 65 33 2a 2c 20 63 68 61 72 t(sqlite3*, char
2ab00 2a 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 **);.int sqlite3
2ab10 49 6e 69 74 43 61 6c 6c 62 61 63 6b 28 76 6f 69 InitCallback(voi
2ab20 64 2a 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2a 2c d*, int, char**,
2ab30 20 63 68 61 72 2a 2a 29 3b 0a 69 6e 74 20 73 71 char**);.int sq
2ab40 6c 69 74 65 33 49 6e 69 74 4f 6e 65 28 73 71 6c lite3InitOne(sql
2ab50 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 68 61 72 ite3*, int, char
2ab60 2a 2a 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 **, u32);.void s
2ab70 71 6c 69 74 65 33 50 72 61 67 6d 61 28 50 61 72 qlite3Pragma(Par
2ab80 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e se*,Token*,Token
2ab90 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 23 *,Token*,int);.#
2aba0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
2abb0 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a IT_VIRTUALTABLE.
2abc0 4d 6f 64 75 6c 65 20 2a 73 71 6c 69 74 65 33 50 Module *sqlite3P
2abd0 72 61 67 6d 61 56 74 61 62 52 65 67 69 73 74 65 ragmaVtabRegiste
2abe0 72 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 r(sqlite3*,const
2abf0 20 63 68 61 72 20 2a 7a 4e 61 6d 65 29 3b 0a 23 char *zName);.#
2ac00 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
2ac10 65 33 52 65 73 65 74 41 6c 6c 53 63 68 65 6d 61 e3ResetAllSchema
2ac20 73 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e 28 73 71 sOfConnection(sq
2ac30 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
2ac40 6c 69 74 65 33 52 65 73 65 74 4f 6e 65 53 63 68 lite3ResetOneSch
2ac50 65 6d 61 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ema(sqlite3*,int
2ac60 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
2ac70 6f 6c 6c 61 70 73 65 44 61 74 61 62 61 73 65 41 ollapseDatabaseA
2ac80 72 72 61 79 28 73 71 6c 69 74 65 33 2a 29 3b 0a rray(sqlite3*);.
2ac90 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 6d void sqlite3Comm
2aca0 69 74 49 6e 74 65 72 6e 61 6c 43 68 61 6e 67 65 itInternalChange
2acb0 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 s(sqlite3*);.voi
2acc0 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 43 d sqlite3DeleteC
2acd0 6f 6c 75 6d 6e 4e 61 6d 65 73 28 73 71 6c 69 74 olumnNames(sqlit
2ace0 65 33 2a 2c 54 61 62 6c 65 2a 29 3b 0a 69 6e 74 e3*,Table*);.int
2acf0 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 73 46 sqlite3ColumnsF
2ad00 72 6f 6d 45 78 70 72 4c 69 73 74 28 50 61 72 73 romExprList(Pars
2ad10 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 31 36 e*,ExprList*,i16
2ad20 2a 2c 43 6f 6c 75 6d 6e 2a 2a 29 3b 0a 76 6f 69 *,Column**);.voi
2ad30 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 41 d sqlite3SelectA
2ad40 64 64 43 6f 6c 75 6d 6e 54 79 70 65 41 6e 64 43 ddColumnTypeAndC
2ad50 6f 6c 6c 61 74 69 6f 6e 28 50 61 72 73 65 2a 2c ollation(Parse*,
2ad60 54 61 62 6c 65 2a 2c 53 65 6c 65 63 74 2a 2c 63 Table*,Select*,c
2ad70 68 61 72 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c har);.Table *sql
2ad80 69 74 65 33 52 65 73 75 6c 74 53 65 74 4f 66 53 ite3ResultSetOfS
2ad90 65 6c 65 63 74 28 50 61 72 73 65 2a 2c 53 65 6c elect(Parse*,Sel
2ada0 65 63 74 2a 2c 63 68 61 72 29 3b 0a 76 6f 69 64 ect*,char);.void
2adb0 20 73 71 6c 69 74 65 33 4f 70 65 6e 4d 61 73 74 sqlite3OpenMast
2adc0 65 72 54 61 62 6c 65 28 50 61 72 73 65 20 2a 2c erTable(Parse *,
2add0 20 69 6e 74 29 3b 0a 49 6e 64 65 78 20 2a 73 71 int);.Index *sq
2ade0 6c 69 74 65 33 50 72 69 6d 61 72 79 4b 65 79 49 lite3PrimaryKeyI
2adf0 6e 64 65 78 28 54 61 62 6c 65 2a 29 3b 0a 69 31 ndex(Table*);.i1
2ae00 36 20 73 71 6c 69 74 65 33 54 61 62 6c 65 43 6f 6 sqlite3TableCo
2ae10 6c 75 6d 6e 54 6f 49 6e 64 65 78 28 49 6e 64 65 lumnToIndex(Inde
2ae20 78 2a 2c 20 69 31 36 29 3b 0a 23 69 66 64 65 66 x*, i16);.#ifdef
2ae30 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 47 45 4e SQLITE_OMIT_GEN
2ae40 45 52 41 54 45 44 5f 43 4f 4c 55 4d 4e 53 0a 23 ERATED_COLUMNS.#
2ae50 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 define sqlite3T
2ae60 61 62 6c 65 43 6f 6c 75 6d 6e 54 6f 53 74 6f 72 ableColumnToStor
2ae70 61 67 65 28 54 2c 58 29 20 28 58 29 20 20 2f 2a age(T,X) (X) /*
2ae80 20 4e 6f 2d 6f 70 20 70 61 73 73 2d 74 68 72 6f No-op pass-thro
2ae90 75 67 68 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 ugh */.# define
2aea0 73 71 6c 69 74 65 33 53 74 6f 72 61 67 65 43 6f sqlite3StorageCo
2aeb0 6c 75 6d 6e 54 6f 54 61 62 6c 65 28 54 2c 58 29 lumnToTable(T,X)
2aec0 20 28 58 29 20 20 2f 2a 20 4e 6f 2d 6f 70 20 70 (X) /* No-op p
2aed0 61 73 73 2d 74 68 72 6f 75 67 68 20 2a 2f 0a 23 ass-through */.#
2aee0 65 6c 73 65 0a 20 20 69 31 36 20 73 71 6c 69 74 else. i16 sqlit
2aef0 65 33 54 61 62 6c 65 43 6f 6c 75 6d 6e 54 6f 53 e3TableColumnToS
2af00 74 6f 72 61 67 65 28 54 61 62 6c 65 2a 2c 20 69 torage(Table*, i
2af10 31 36 29 3b 0a 20 20 69 31 36 20 73 71 6c 69 74 16);. i16 sqlit
2af20 65 33 53 74 6f 72 61 67 65 43 6f 6c 75 6d 6e 54 e3StorageColumnT
2af30 6f 54 61 62 6c 65 28 54 61 62 6c 65 2a 2c 20 69 oTable(Table*, i
2af40 31 36 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 16);.#endif.void
2af50 20 73 71 6c 69 74 65 33 53 74 61 72 74 54 61 62 sqlite3StartTab
2af60 6c 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a le(Parse*,Token*
2af70 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c ,Token*,int,int,
2af80 69 6e 74 2c 69 6e 74 29 3b 0a 23 69 66 20 53 51 int,int);.#if SQ
2af90 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 LITE_ENABLE_HIDD
2afa0 45 4e 5f 43 4f 4c 55 4d 4e 53 0a 20 20 76 6f 69 EN_COLUMNS. voi
2afb0 64 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 50 d sqlite3ColumnP
2afc0 72 6f 70 65 72 74 69 65 73 46 72 6f 6d 4e 61 6d ropertiesFromNam
2afd0 65 28 54 61 62 6c 65 2a 2c 20 43 6f 6c 75 6d 6e e(Table*, Column
2afe0 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
2aff0 6e 65 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e ne sqlite3Column
2b000 50 72 6f 70 65 72 74 69 65 73 46 72 6f 6d 4e 61 PropertiesFromNa
2b010 6d 65 28 54 2c 43 29 20 2f 2a 20 6e 6f 2d 6f 70 me(T,C) /* no-op
2b020 20 2a 2f 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 */.#endif.void
2b030 73 71 6c 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e sqlite3AddColumn
2b040 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 (Parse*,Token*,T
2b050 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
2b060 69 74 65 33 41 64 64 4e 6f 74 4e 75 6c 6c 28 50 ite3AddNotNull(P
2b070 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 arse*, int);.voi
2b080 64 20 73 71 6c 69 74 65 33 41 64 64 50 72 69 6d d sqlite3AddPrim
2b090 61 72 79 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 aryKey(Parse*, E
2b0a0 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 xprList*, int, i
2b0b0 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
2b0c0 71 6c 69 74 65 33 41 64 64 43 68 65 63 6b 43 6f qlite3AddCheckCo
2b0d0 6e 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c nstraint(Parse*,
2b0e0 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 Expr*);.void sq
2b0f0 6c 69 74 65 33 41 64 64 44 65 66 61 75 6c 74 56 lite3AddDefaultV
2b100 61 6c 75 65 28 50 61 72 73 65 2a 2c 45 78 70 72 alue(Parse*,Expr
2b110 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f *,const char*,co
2b120 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 nst char*);.void
2b130 20 73 71 6c 69 74 65 33 41 64 64 43 6f 6c 6c 61 sqlite3AddColla
2b140 74 65 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 teType(Parse*, T
2b150 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
2b160 69 74 65 33 41 64 64 47 65 6e 65 72 61 74 65 64 ite3AddGenerated
2b170 28 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 54 6f (Parse*,Expr*,To
2b180 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
2b190 74 65 33 45 6e 64 54 61 62 6c 65 28 50 61 72 73 te3EndTable(Pars
2b1a0 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a e*,Token*,Token*
2b1b0 2c 75 38 2c 53 65 6c 65 63 74 2a 29 3b 0a 69 6e ,u8,Select*);.in
2b1c0 74 20 73 71 6c 69 74 65 33 50 61 72 73 65 55 72 t sqlite3ParseUr
2b1d0 69 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f i(const char*,co
2b1e0 6e 73 74 20 63 68 61 72 2a 2c 75 6e 73 69 67 6e nst char*,unsign
2b1f0 65 64 20 69 6e 74 2a 2c 0a 20 20 20 20 20 20 20 ed int*,.
2b200 20 20 20 20 20 20 20 20 20 20 20 20 20 73 71 6c sql
2b210 69 74 65 33 5f 76 66 73 2a 2a 2c 63 68 61 72 2a ite3_vfs**,char*
2b220 2a 2c 63 68 61 72 20 2a 2a 29 3b 0a 23 69 66 64 *,char **);.#ifd
2b230 65 66 20 53 51 4c 49 54 45 5f 48 41 53 5f 43 4f ef SQLITE_HAS_CO
2b240 44 45 43 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 DEC. int sqlite
2b250 33 43 6f 64 65 63 51 75 65 72 79 50 61 72 61 6d 3CodecQueryParam
2b260 65 74 65 72 73 28 73 71 6c 69 74 65 33 2a 2c 63 eters(sqlite3*,c
2b270 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 onst char*,const
2b280 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 65 0a 23 char*);.#else.#
2b290 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 define sqlite3C
2b2a0 6f 64 65 63 51 75 65 72 79 50 61 72 61 6d 65 74 odecQueryParamet
2b2b0 65 72 73 28 41 2c 42 2c 43 29 20 30 0a 23 65 6e ers(A,B,C) 0.#en
2b2c0 64 69 66 0a 42 74 72 65 65 20 2a 73 71 6c 69 74 dif.Btree *sqlit
2b2d0 65 33 44 62 4e 61 6d 65 54 6f 42 74 72 65 65 28 e3DbNameToBtree(
2b2e0 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
2b2f0 68 61 72 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 har*);..#ifdef S
2b300 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 QLITE_UNTESTABLE
2b310 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
2b320 33 46 61 75 6c 74 53 69 6d 28 58 29 20 53 51 4c 3FaultSim(X) SQL
2b330 49 54 45 5f 4f 4b 0a 23 65 6c 73 65 0a 20 20 69 ITE_OK.#else. i
2b340 6e 74 20 73 71 6c 69 74 65 33 46 61 75 6c 74 53 nt sqlite3FaultS
2b350 69 6d 28 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a im(int);.#endif.
2b360 0a 42 69 74 76 65 63 20 2a 73 71 6c 69 74 65 33 .Bitvec *sqlite3
2b370 42 69 74 76 65 63 43 72 65 61 74 65 28 75 33 32 BitvecCreate(u32
2b380 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 69 );.int sqlite3Bi
2b390 74 76 65 63 54 65 73 74 28 42 69 74 76 65 63 2a tvecTest(Bitvec*
2b3a0 2c 20 75 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 , u32);.int sqli
2b3b0 74 65 33 42 69 74 76 65 63 54 65 73 74 4e 6f 74 te3BitvecTestNot
2b3c0 4e 75 6c 6c 28 42 69 74 76 65 63 2a 2c 20 75 33 Null(Bitvec*, u3
2b3d0 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 2);.int sqlite3B
2b3e0 69 74 76 65 63 53 65 74 28 42 69 74 76 65 63 2a itvecSet(Bitvec*
2b3f0 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 73 71 6c , u32);.void sql
2b400 69 74 65 33 42 69 74 76 65 63 43 6c 65 61 72 28 ite3BitvecClear(
2b410 42 69 74 76 65 63 2a 2c 20 75 33 32 2c 20 76 6f Bitvec*, u32, vo
2b420 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 id*);.void sqlit
2b430 65 33 42 69 74 76 65 63 44 65 73 74 72 6f 79 28 e3BitvecDestroy(
2b440 42 69 74 76 65 63 2a 29 3b 0a 75 33 32 20 73 71 Bitvec*);.u32 sq
2b450 6c 69 74 65 33 42 69 74 76 65 63 53 69 7a 65 28 lite3BitvecSize(
2b460 42 69 74 76 65 63 2a 29 3b 0a 23 69 66 6e 64 65 Bitvec*);.#ifnde
2b470 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 f SQLITE_UNTESTA
2b480 42 4c 45 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 BLE.int sqlite3B
2b490 69 74 76 65 63 42 75 69 6c 74 69 6e 54 65 73 74 itvecBuiltinTest
2b4a0 28 69 6e 74 2c 69 6e 74 2a 29 3b 0a 23 65 6e 64 (int,int*);.#end
2b4b0 69 66 0a 0a 52 6f 77 53 65 74 20 2a 73 71 6c 69 if..RowSet *sqli
2b4c0 74 65 33 52 6f 77 53 65 74 49 6e 69 74 28 73 71 te3RowSetInit(sq
2b4d0 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
2b4e0 6c 69 74 65 33 52 6f 77 53 65 74 44 65 6c 65 74 lite3RowSetDelet
2b4f0 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 e(void*);.void s
2b500 71 6c 69 74 65 33 52 6f 77 53 65 74 43 6c 65 61 qlite3RowSetClea
2b510 72 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 r(void*);.void s
2b520 71 6c 69 74 65 33 52 6f 77 53 65 74 49 6e 73 65 qlite3RowSetInse
2b530 72 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 29 rt(RowSet*, i64)
2b540 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 ;.int sqlite3Row
2b550 53 65 74 54 65 73 74 28 52 6f 77 53 65 74 2a 2c SetTest(RowSet*,
2b560 20 69 6e 74 20 69 42 61 74 63 68 2c 20 69 36 34 int iBatch, i64
2b570 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f );.int sqlite3Ro
2b580 77 53 65 74 4e 65 78 74 28 52 6f 77 53 65 74 2a wSetNext(RowSet*
2b590 2c 20 69 36 34 2a 29 3b 0a 0a 76 6f 69 64 20 73 , i64*);..void s
2b5a0 71 6c 69 74 65 33 43 72 65 61 74 65 56 69 65 77 qlite3CreateView
2b5b0 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 (Parse*,Token*,T
2b5c0 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 oken*,Token*,Exp
2b5d0 72 4c 69 73 74 2a 2c 53 65 6c 65 63 74 2a 2c 69 rList*,Select*,i
2b5e0 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 66 20 21 64 nt,int);..#if !d
2b5f0 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d efined(SQLITE_OM
2b600 49 54 5f 56 49 45 57 29 20 7c 7c 20 21 64 65 66 IT_VIEW) || !def
2b610 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 ined(SQLITE_OMIT
2b620 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 0a 20 _VIRTUALTABLE).
2b630 20 69 6e 74 20 73 71 6c 69 74 65 33 56 69 65 77 int sqlite3View
2b640 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 50 GetColumnNames(P
2b650 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a 23 arse*,Table*);.#
2b660 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 else.# define sq
2b670 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f 6c 75 lite3ViewGetColu
2b680 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 20 30 0a 23 mnNames(A,B) 0.#
2b690 65 6e 64 69 66 0a 0a 23 69 66 20 53 51 4c 49 54 endif..#if SQLIT
2b6a0 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 3e 33 E_MAX_ATTACHED>3
2b6b0 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 44 0. int sqlite3D
2b6c0 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 79 44 62 bMaskAllZero(yDb
2b6d0 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 66 0a 76 6f Mask);.#endif.vo
2b6e0 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 54 61 id sqlite3DropTa
2b6f0 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 63 4c ble(Parse*, SrcL
2b700 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b ist*, int, int);
2b710 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 .void sqlite3Cod
2b720 65 44 72 6f 70 54 61 62 6c 65 28 50 61 72 73 65 eDropTable(Parse
2b730 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 *, Table*, int,
2b740 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
2b750 65 33 44 65 6c 65 74 65 54 61 62 6c 65 28 73 71 e3DeleteTable(sq
2b760 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 3b lite3*, Table*);
2b770 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 72 65 .void sqlite3Fre
2b780 65 49 6e 64 65 78 28 73 71 6c 69 74 65 33 2a 2c eIndex(sqlite3*,
2b790 20 49 6e 64 65 78 2a 29 3b 0a 23 69 66 6e 64 65 Index*);.#ifnde
2b7a0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
2b7b0 54 4f 49 4e 43 52 45 4d 45 4e 54 0a 20 20 76 6f TOINCREMENT. vo
2b7c0 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e id sqlite3Autoin
2b7d0 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 50 61 72 crementBegin(Par
2b7e0 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 20 20 76 se *pParse);. v
2b7f0 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 oid sqlite3Autoi
2b800 6e 63 72 65 6d 65 6e 74 45 6e 64 28 50 61 72 73 ncrementEnd(Pars
2b810 65 20 2a 70 50 61 72 73 65 29 3b 0a 23 65 6c 73 e *pParse);.#els
2b820 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
2b830 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 42 e3AutoincrementB
2b840 65 67 69 6e 28 58 29 0a 23 20 64 65 66 69 6e 65 egin(X).# define
2b850 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 sqlite3Autoincr
2b860 65 6d 65 6e 74 45 6e 64 28 58 29 0a 23 65 6e 64 ementEnd(X).#end
2b870 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 if.void sqlite3I
2b880 6e 73 65 72 74 28 50 61 72 73 65 2a 2c 20 53 72 nsert(Parse*, Sr
2b890 63 4c 69 73 74 2a 2c 20 53 65 6c 65 63 74 2a 2c cList*, Select*,
2b8a0 20 49 64 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 55 IdList*, int, U
2b8b0 70 73 65 72 74 2a 29 3b 0a 23 69 66 6e 64 65 66 psert*);.#ifndef
2b8c0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 47 45 4e SQLITE_OMIT_GEN
2b8d0 45 52 41 54 45 44 5f 43 4f 4c 55 4d 4e 53 0a 20 ERATED_COLUMNS.
2b8e0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d void sqlite3Com
2b8f0 70 75 74 65 47 65 6e 65 72 61 74 65 64 43 6f 6c puteGeneratedCol
2b900 75 6d 6e 73 28 50 61 72 73 65 2a 2c 20 69 6e 74 umns(Parse*, int
2b910 2c 20 54 61 62 6c 65 2a 29 3b 0a 23 65 6e 64 69 , Table*);.#endi
2b920 66 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 41 f.void *sqlite3A
2b930 72 72 61 79 41 6c 6c 6f 63 61 74 65 28 73 71 6c rrayAllocate(sql
2b940 69 74 65 33 2a 2c 76 6f 69 64 2a 2c 69 6e 74 2c ite3*,void*,int,
2b950 69 6e 74 2a 2c 69 6e 74 2a 29 3b 0a 49 64 4c 69 int*,int*);.IdLi
2b960 73 74 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 st *sqlite3IdLis
2b970 74 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c 20 tAppend(Parse*,
2b980 49 64 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 IdList*, Token*)
2b990 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 64 4c ;.int sqlite3IdL
2b9a0 69 73 74 49 6e 64 65 78 28 49 64 4c 69 73 74 2a istIndex(IdList*
2b9b0 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 53 ,const char*);.S
2b9c0 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 rcList *sqlite3S
2b9d0 72 63 4c 69 73 74 45 6e 6c 61 72 67 65 28 50 61 rcListEnlarge(Pa
2b9e0 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 rse*, SrcList*,
2b9f0 69 6e 74 2c 20 69 6e 74 29 3b 0a 53 72 63 4c 69 int, int);.SrcLi
2ba00 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 st *sqlite3SrcLi
2ba10 73 74 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c stAppend(Parse*,
2ba20 20 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e SrcList*, Token
2ba30 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 53 72 63 4c *, Token*);.SrcL
2ba40 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c ist *sqlite3SrcL
2ba50 69 73 74 41 70 70 65 6e 64 46 72 6f 6d 54 65 72 istAppendFromTer
2ba60 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 m(Parse*, SrcLis
2ba70 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 t*, Token*, Toke
2ba80 6e 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 n*,.
2ba90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2baa0 20 20 20 20 20 20 20 20 20 20 54 6f 6b 65 6e 2a Token*
2bab0 2c 20 53 65 6c 65 63 74 2a 2c 20 45 78 70 72 2a , Select*, Expr*
2bac0 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 , IdList*);.void
2bad0 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 49 sqlite3SrcListI
2bae0 6e 64 65 78 65 64 42 79 28 50 61 72 73 65 20 2a ndexedBy(Parse *
2baf0 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 6f 6b , SrcList *, Tok
2bb00 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 en *);.void sqli
2bb10 74 65 33 53 72 63 4c 69 73 74 46 75 6e 63 41 72 te3SrcListFuncAr
2bb20 67 73 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 gs(Parse*, SrcLi
2bb30 73 74 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b st*, ExprList*);
2bb40 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 64 65 .int sqlite3Inde
2bb50 78 65 64 42 79 4c 6f 6f 6b 75 70 28 50 61 72 73 xedByLookup(Pars
2bb60 65 20 2a 2c 20 73 74 72 75 63 74 20 53 72 63 4c e *, struct SrcL
2bb70 69 73 74 5f 69 74 65 6d 20 2a 29 3b 0a 76 6f 69 ist_item *);.voi
2bb80 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 d sqlite3SrcList
2bb90 53 68 69 66 74 4a 6f 69 6e 54 79 70 65 28 53 72 ShiftJoinType(Sr
2bba0 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 cList*);.void sq
2bbb0 6c 69 74 65 33 53 72 63 4c 69 73 74 41 73 73 69 lite3SrcListAssi
2bbc0 67 6e 43 75 72 73 6f 72 73 28 50 61 72 73 65 2a gnCursors(Parse*
2bbd0 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 , SrcList*);.voi
2bbe0 64 20 73 71 6c 69 74 65 33 49 64 4c 69 73 74 44 d sqlite3IdListD
2bbf0 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 elete(sqlite3*,
2bc00 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 IdList*);.void s
2bc10 71 6c 69 74 65 33 53 72 63 4c 69 73 74 44 65 6c qlite3SrcListDel
2bc20 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 53 72 ete(sqlite3*, Sr
2bc30 63 4c 69 73 74 2a 29 3b 0a 49 6e 64 65 78 20 2a cList*);.Index *
2bc40 73 71 6c 69 74 65 33 41 6c 6c 6f 63 61 74 65 49 sqlite3AllocateI
2bc50 6e 64 65 78 4f 62 6a 65 63 74 28 73 71 6c 69 74 ndexObject(sqlit
2bc60 65 33 2a 2c 69 31 36 2c 69 6e 74 2c 63 68 61 72 e3*,i16,int,char
2bc70 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 **);.void sqlite
2bc80 33 43 72 65 61 74 65 49 6e 64 65 78 28 50 61 72 3CreateIndex(Par
2bc90 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e se*,Token*,Token
2bca0 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 4c *,SrcList*,ExprL
2bcb0 69 73 74 2a 2c 69 6e 74 2c 54 6f 6b 65 6e 2a 2c ist*,int,Token*,
2bcc0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
2bcd0 20 20 20 20 20 20 20 20 20 20 20 45 78 70 72 2a Expr*
2bce0 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b , int, int, u8);
2bcf0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f .void sqlite3Dro
2bd00 70 49 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 53 pIndex(Parse*, S
2bd10 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a 69 rcList*, int);.i
2bd20 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 nt sqlite3Select
2bd30 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a (Parse*, Select*
2bd40 2c 20 53 65 6c 65 63 74 44 65 73 74 2a 29 3b 0a , SelectDest*);.
2bd50 53 65 6c 65 63 74 20 2a 73 71 6c 69 74 65 33 53 Select *sqlite3S
2bd60 65 6c 65 63 74 4e 65 77 28 50 61 72 73 65 2a 2c electNew(Parse*,
2bd70 45 78 70 72 4c 69 73 74 2a 2c 53 72 63 4c 69 73 ExprList*,SrcLis
2bd80 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 t*,Expr*,ExprLis
2bd90 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 t*,.
2bda0 20 20 20 20 20 20 20 20 20 20 20 20 20 45 78 70 Exp
2bdb0 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 75 33 32 r*,ExprList*,u32
2bdc0 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 ,Expr*);.void sq
2bdd0 6c 69 74 65 33 53 65 6c 65 63 74 44 65 6c 65 74 lite3SelectDelet
2bde0 65 28 73 71 6c 69 74 65 33 2a 2c 20 53 65 6c 65 e(sqlite3*, Sele
2bdf0 63 74 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c ct*);.Table *sql
2be00 69 74 65 33 53 72 63 4c 69 73 74 4c 6f 6f 6b 75 ite3SrcListLooku
2be10 70 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 p(Parse*, SrcLis
2be20 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
2be30 49 73 52 65 61 64 4f 6e 6c 79 28 50 61 72 73 65 IsReadOnly(Parse
2be40 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 3b *, Table*, int);
2be50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f 70 65 .void sqlite3Ope
2be60 6e 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 69 nTable(Parse*, i
2be70 6e 74 20 69 43 75 72 2c 20 69 6e 74 20 69 44 62 nt iCur, int iDb
2be80 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 3b 0a , Table*, int);.
2be90 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
2bea0 54 45 5f 45 4e 41 42 4c 45 5f 55 50 44 41 54 45 TE_ENABLE_UPDATE
2beb0 5f 44 45 4c 45 54 45 5f 4c 49 4d 49 54 29 20 26 _DELETE_LIMIT) &
2bec0 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 & !defined(SQLIT
2bed0 45 5f 4f 4d 49 54 5f 53 55 42 51 55 45 52 59 29 E_OMIT_SUBQUERY)
2bee0 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 4c 69 .Expr *sqlite3Li
2bef0 6d 69 74 57 68 65 72 65 28 50 61 72 73 65 2a 2c mitWhere(Parse*,
2bf00 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 SrcList*,Expr*,E
2bf10 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 63 xprList*,Expr*,c
2bf20 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f har*);.#endif.vo
2bf30 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 id sqlite3Delete
2bf40 46 72 6f 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 From(Parse*, Src
2bf50 4c 69 73 74 2a 2c 20 45 78 70 72 2a 2c 20 45 78 List*, Expr*, Ex
2bf60 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 2a 29 3b prList*, Expr*);
2bf70 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 70 64 .void sqlite3Upd
2bf80 61 74 65 28 50 61 72 73 65 2a 2c 20 53 72 63 4c ate(Parse*, SrcL
2bf90 69 73 74 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c ist*, ExprList*,
2bfa0 45 78 70 72 2a 2c 69 6e 74 2c 45 78 70 72 4c 69 Expr*,int,ExprLi
2bfb0 73 74 2a 2c 45 78 70 72 2a 2c 0a 20 20 20 20 20 st*,Expr*,.
2bfc0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 55 70 Up
2bfd0 73 65 72 74 2a 29 3b 0a 57 68 65 72 65 49 6e 66 sert*);.WhereInf
2bfe0 6f 20 2a 73 71 6c 69 74 65 33 57 68 65 72 65 42 o *sqlite3WhereB
2bff0 65 67 69 6e 28 50 61 72 73 65 2a 2c 53 72 63 4c egin(Parse*,SrcL
2c000 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c ist*,Expr*,ExprL
2c010 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 75 ist*,ExprList*,u
2c020 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 16,int);.void sq
2c030 6c 69 74 65 33 57 68 65 72 65 45 6e 64 28 57 68 lite3WhereEnd(Wh
2c040 65 72 65 49 6e 66 6f 2a 29 3b 0a 4c 6f 67 45 73 ereInfo*);.LogEs
2c050 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 4f 75 t sqlite3WhereOu
2c060 74 70 75 74 52 6f 77 43 6f 75 6e 74 28 57 68 65 tputRowCount(Whe
2c070 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 reInfo*);.int sq
2c080 6c 69 74 65 33 57 68 65 72 65 49 73 44 69 73 74 lite3WhereIsDist
2c090 69 6e 63 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 inct(WhereInfo*)
2c0a0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 ;.int sqlite3Whe
2c0b0 72 65 49 73 4f 72 64 65 72 65 64 28 57 68 65 72 reIsOrdered(Wher
2c0c0 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
2c0d0 69 74 65 33 57 68 65 72 65 4f 72 64 65 72 42 79 ite3WhereOrderBy
2c0e0 4c 69 6d 69 74 4f 70 74 4c 61 62 65 6c 28 57 68 LimitOptLabel(Wh
2c0f0 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 ereInfo*);.int s
2c100 71 6c 69 74 65 33 57 68 65 72 65 49 73 53 6f 72 qlite3WhereIsSor
2c110 74 65 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b ted(WhereInfo*);
2c120 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
2c130 65 43 6f 6e 74 69 6e 75 65 4c 61 62 65 6c 28 57 eContinueLabel(W
2c140 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 hereInfo*);.int
2c150 73 71 6c 69 74 65 33 57 68 65 72 65 42 72 65 61 sqlite3WhereBrea
2c160 6b 4c 61 62 65 6c 28 57 68 65 72 65 49 6e 66 6f kLabel(WhereInfo
2c170 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 *);.int sqlite3W
2c180 68 65 72 65 4f 6b 4f 6e 65 50 61 73 73 28 57 68 hereOkOnePass(Wh
2c190 65 72 65 49 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b ereInfo*, int*);
2c1a0 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 53 .#define ONEPASS
2c1b0 5f 4f 46 46 20 20 20 20 20 20 30 20 20 20 20 20 _OFF 0
2c1c0 20 20 20 2f 2a 20 55 73 65 20 6f 66 20 4f 4e 45 /* Use of ONE
2c1d0 50 41 53 53 20 6e 6f 74 20 61 6c 6c 6f 77 65 64 PASS not allowed
2c1e0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 */.#define ONEP
2c1f0 41 53 53 5f 53 49 4e 47 4c 45 20 20 20 31 20 20 ASS_SINGLE 1
2c200 20 20 20 20 20 20 2f 2a 20 4f 4e 45 50 41 53 53 /* ONEPASS
2c210 20 76 61 6c 69 64 20 66 6f 72 20 61 20 73 69 6e valid for a sin
2c220 67 6c 65 20 72 6f 77 20 75 70 64 61 74 65 20 2a gle row update *
2c230 2f 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 /.#define ONEPAS
2c240 53 5f 4d 55 4c 54 49 20 20 20 20 32 20 20 20 20 S_MULTI 2
2c250 20 20 20 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 /* ONEPASS i
2c260 73 20 76 61 6c 69 64 20 66 6f 72 20 6d 75 6c 74 s valid for mult
2c270 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 76 6f 69 iple rows */.voi
2c280 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 d sqlite3ExprCod
2c290 65 4c 6f 61 64 49 6e 64 65 78 43 6f 6c 75 6d 6e eLoadIndexColumn
2c2a0 28 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c (Parse*, Index*,
2c2b0 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
2c2c0 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
2c2d0 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 28 50 61 CodeGetColumn(Pa
2c2e0 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e rse*, Table*, in
2c2f0 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 t, int, int, u8)
2c300 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
2c310 70 72 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 4f prCodeGetColumnO
2c320 66 54 61 62 6c 65 28 56 64 62 65 2a 2c 20 54 61 fTable(Vdbe*, Ta
2c330 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 ble*, int, int,
2c340 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
2c350 65 33 45 78 70 72 43 6f 64 65 4d 6f 76 65 28 50 e3ExprCodeMove(P
2c360 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c arse*, int, int,
2c370 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
2c380 74 65 33 45 78 70 72 43 6f 64 65 28 50 61 72 73 te3ExprCode(Pars
2c390 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b e*, Expr*, int);
2c3a0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
2c3b0 72 43 6f 64 65 43 6f 70 79 28 50 61 72 73 65 2a rCodeCopy(Parse*
2c3c0 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 , Expr*, int);.v
2c3d0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
2c3e0 6f 64 65 46 61 63 74 6f 72 61 62 6c 65 28 50 61 odeFactorable(Pa
2c3f0 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 rse*, Expr*, int
2c400 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
2c410 70 72 43 6f 64 65 41 74 49 6e 69 74 28 50 61 72 prCodeAtInit(Par
2c420 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 se*, Expr*, int)
2c430 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 ;.int sqlite3Exp
2c440 72 43 6f 64 65 54 65 6d 70 28 50 61 72 73 65 2a rCodeTemp(Parse*
2c450 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a , Expr*, int*);.
2c460 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
2c470 6f 64 65 54 61 72 67 65 74 28 50 61 72 73 65 2a odeTarget(Parse*
2c480 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 , Expr*, int);.v
2c490 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
2c4a0 6f 64 65 41 6e 64 43 61 63 68 65 28 50 61 72 73 odeAndCache(Pars
2c4b0 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b e*, Expr*, int);
2c4c0 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
2c4d0 43 6f 64 65 45 78 70 72 4c 69 73 74 28 50 61 72 CodeExprList(Par
2c4e0 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 se*, ExprList*,
2c4f0 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 23 int, int, u8);.#
2c500 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 43 define SQLITE_EC
2c510 45 4c 5f 44 55 50 20 20 20 20 20 20 30 78 30 31 EL_DUP 0x01
2c520 20 20 2f 2a 20 44 65 65 70 2c 20 6e 6f 74 20 73 /* Deep, not s
2c530 68 61 6c 6c 6f 77 20 63 6f 70 69 65 73 20 2a 2f hallow copies */
2c540 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
2c550 45 43 45 4c 5f 46 41 43 54 4f 52 20 20 20 30 78 ECEL_FACTOR 0x
2c560 30 32 20 20 2f 2a 20 46 61 63 74 6f 72 20 6f 75 02 /* Factor ou
2c570 74 20 63 6f 6e 73 74 61 6e 74 20 74 65 72 6d 73 t constant terms
2c580 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
2c590 54 45 5f 45 43 45 4c 5f 52 45 46 20 20 20 20 20 TE_ECEL_REF
2c5a0 20 30 78 30 34 20 20 2f 2a 20 55 73 65 20 45 78 0x04 /* Use Ex
2c5b0 70 72 4c 69 73 74 2e 75 2e 78 2e 69 4f 72 64 65 prList.u.x.iOrde
2c5c0 72 42 79 43 6f 6c 20 2a 2f 0a 23 64 65 66 69 6e rByCol */.#defin
2c5d0 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 4f 4d e SQLITE_ECEL_OM
2c5e0 49 54 52 45 46 20 20 30 78 30 38 20 20 2f 2a 20 ITREF 0x08 /*
2c5f0 4f 6d 69 74 20 69 66 20 45 78 70 72 4c 69 73 74 Omit if ExprList
2c600 2e 75 2e 78 2e 69 4f 72 64 65 72 42 79 43 6f 6c .u.x.iOrderByCol
2c610 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 */.void sqlite3
2c620 45 78 70 72 49 66 54 72 75 65 28 50 61 72 73 65 ExprIfTrue(Parse
2c630 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 *, Expr*, int, i
2c640 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
2c650 33 45 78 70 72 49 66 46 61 6c 73 65 28 50 61 72 3ExprIfFalse(Par
2c660 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c se*, Expr*, int,
2c670 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
2c680 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 44 75 te3ExprIfFalseDu
2c690 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c p(Parse*, Expr*,
2c6a0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 54 61 62 6c int, int);.Tabl
2c6b0 65 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 54 61 e *sqlite3FindTa
2c6c0 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ble(sqlite3*,con
2c6d0 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
2c6e0 63 68 61 72 2a 29 3b 0a 23 64 65 66 69 6e 65 20 char*);.#define
2c6f0 4c 4f 43 41 54 45 5f 56 49 45 57 20 20 20 20 30 LOCATE_VIEW 0
2c700 78 30 31 0a 23 64 65 66 69 6e 65 20 4c 4f 43 41 x01.#define LOCA
2c710 54 45 5f 4e 4f 45 52 52 20 20 20 30 78 30 32 0a TE_NOERR 0x02.
2c720 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 4c 6f Table *sqlite3Lo
2c730 63 61 74 65 54 61 62 6c 65 28 50 61 72 73 65 2a cateTable(Parse*
2c740 2c 75 33 32 20 66 6c 61 67 73 2c 63 6f 6e 73 74 ,u32 flags,const
2c750 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 char*, const ch
2c760 61 72 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c ar*);.Table *sql
2c770 69 74 65 33 4c 6f 63 61 74 65 54 61 62 6c 65 49 ite3LocateTableI
2c780 74 65 6d 28 50 61 72 73 65 2a 2c 75 33 32 20 66 tem(Parse*,u32 f
2c790 6c 61 67 73 2c 73 74 72 75 63 74 20 53 72 63 4c lags,struct SrcL
2c7a0 69 73 74 5f 69 74 65 6d 20 2a 29 3b 0a 49 6e 64 ist_item *);.Ind
2c7b0 65 78 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 49 ex *sqlite3FindI
2c7c0 6e 64 65 78 28 73 71 6c 69 74 65 33 2a 2c 63 6f ndex(sqlite3*,co
2c7d0 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 nst char*, const
2c7e0 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 char*);.void sq
2c7f0 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 lite3UnlinkAndDe
2c800 6c 65 74 65 54 61 62 6c 65 28 73 71 6c 69 74 65 leteTable(sqlite
2c810 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 3*,int,const cha
2c820 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
2c830 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 3UnlinkAndDelete
2c840 49 6e 64 65 78 28 73 71 6c 69 74 65 33 2a 2c 69 Index(sqlite3*,i
2c850 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b nt,const char*);
2c860 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 63 .void sqlite3Vac
2c870 75 75 6d 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e uum(Parse*,Token
2c880 2a 2c 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 *,Expr*);.int sq
2c890 6c 69 74 65 33 52 75 6e 56 61 63 75 75 6d 28 63 lite3RunVacuum(c
2c8a0 68 61 72 2a 2a 2c 20 73 71 6c 69 74 65 33 2a 2c har**, sqlite3*,
2c8b0 20 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f 76 61 int, sqlite3_va
2c8c0 6c 75 65 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c lue*);.char *sql
2c8d0 69 74 65 33 4e 61 6d 65 46 72 6f 6d 54 6f 6b 65 ite3NameFromToke
2c8e0 6e 28 73 71 6c 69 74 65 33 2a 2c 20 54 6f 6b 65 n(sqlite3*, Toke
2c8f0 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 n*);.int sqlite3
2c900 45 78 70 72 43 6f 6d 70 61 72 65 28 50 61 72 73 ExprCompare(Pars
2c910 65 2a 2c 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c e*,Expr*, Expr*,
2c920 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
2c930 65 33 45 78 70 72 43 6f 6d 70 61 72 65 53 6b 69 e3ExprCompareSki
2c940 70 28 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 p(Expr*, Expr*,
2c950 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
2c960 33 45 78 70 72 4c 69 73 74 43 6f 6d 70 61 72 65 3ExprListCompare
2c970 28 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 (ExprList*, Expr
2c980 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 List*, int);.int
2c990 20 73 71 6c 69 74 65 33 45 78 70 72 49 6d 70 6c sqlite3ExprImpl
2c9a0 69 65 73 45 78 70 72 28 50 61 72 73 65 2a 2c 45 iesExpr(Parse*,E
2c9b0 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 xpr*, Expr*, int
2c9c0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
2c9d0 70 72 49 6d 70 6c 69 65 73 4e 6f 6e 4e 75 6c 6c prImpliesNonNull
2c9e0 52 6f 77 28 45 78 70 72 2a 2c 69 6e 74 29 3b 0a Row(Expr*,int);.
2c9f0 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
2ca00 41 6e 61 6c 79 7a 65 41 67 67 72 65 67 61 74 65 AnalyzeAggregate
2ca10 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 s(NameContext*,
2ca20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
2ca30 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a 65 41 ite3ExprAnalyzeA
2ca40 67 67 4c 69 73 74 28 4e 61 6d 65 43 6f 6e 74 65 ggList(NameConte
2ca50 78 74 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b 0a xt*,ExprList*);.
2ca60 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
2ca70 6f 76 65 72 65 64 42 79 49 6e 64 65 78 28 45 78 overedByIndex(Ex
2ca80 70 72 2a 2c 20 69 6e 74 20 69 43 75 72 2c 20 49 pr*, int iCur, I
2ca90 6e 64 65 78 20 2a 70 49 64 78 29 3b 0a 69 6e 74 ndex *pIdx);.int
2caa0 20 73 71 6c 69 74 65 33 46 75 6e 63 74 69 6f 6e sqlite3Function
2cab0 55 73 65 73 54 68 69 73 53 72 63 28 45 78 70 72 UsesThisSrc(Expr
2cac0 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 56 64 *, SrcList*);.Vd
2cad0 62 65 20 2a 73 71 6c 69 74 65 33 47 65 74 56 64 be *sqlite3GetVd
2cae0 62 65 28 50 61 72 73 65 2a 29 3b 0a 23 69 66 6e be(Parse*);.#ifn
2caf0 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 def SQLITE_UNTES
2cb00 54 41 42 4c 45 0a 76 6f 69 64 20 73 71 6c 69 74 TABLE.void sqlit
2cb10 65 33 50 72 6e 67 53 61 76 65 53 74 61 74 65 28 e3PrngSaveState(
2cb20 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 void);.void sqli
2cb30 74 65 33 50 72 6e 67 52 65 73 74 6f 72 65 53 74 te3PrngRestoreSt
2cb40 61 74 65 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 ate(void);.#endi
2cb50 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 6f f.void sqlite3Ro
2cb60 6c 6c 62 61 63 6b 41 6c 6c 28 73 71 6c 69 74 65 llbackAll(sqlite
2cb70 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 3*,int);.void sq
2cb80 6c 69 74 65 33 43 6f 64 65 56 65 72 69 66 79 53 lite3CodeVerifyS
2cb90 63 68 65 6d 61 28 50 61 72 73 65 2a 2c 20 69 6e chema(Parse*, in
2cba0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
2cbb0 43 6f 64 65 56 65 72 69 66 79 4e 61 6d 65 64 53 CodeVerifyNamedS
2cbc0 63 68 65 6d 61 28 50 61 72 73 65 2a 2c 20 63 6f chema(Parse*, co
2cbd0 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 29 3b 0a nst char *zDb);.
2cbe0 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 void sqlite3Begi
2cbf0 6e 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 nTransaction(Par
2cc00 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 se*, int);.void
2cc10 73 71 6c 69 74 65 33 45 6e 64 54 72 61 6e 73 61 sqlite3EndTransa
2cc20 63 74 69 6f 6e 28 50 61 72 73 65 2a 2c 69 6e 74 ction(Parse*,int
2cc30 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
2cc40 61 76 65 70 6f 69 6e 74 28 50 61 72 73 65 2a 2c avepoint(Parse*,
2cc50 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 int, Token*);.v
2cc60 6f 69 64 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 oid sqlite3Close
2cc70 53 61 76 65 70 6f 69 6e 74 73 28 73 71 6c 69 74 Savepoints(sqlit
2cc80 65 33 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 e3 *);.void sqli
2cc90 74 65 33 4c 65 61 76 65 4d 75 74 65 78 41 6e 64 te3LeaveMutexAnd
2cca0 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 73 71 6c 69 CloseZombie(sqli
2ccb0 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 te3*);.int sqlit
2ccc0 65 33 45 78 70 72 49 64 54 6f 54 72 75 65 46 61 e3ExprIdToTrueFa
2ccd0 6c 73 65 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 lse(Expr*);.int
2cce0 73 71 6c 69 74 65 33 45 78 70 72 54 72 75 74 68 sqlite3ExprTruth
2ccf0 56 61 6c 75 65 28 63 6f 6e 73 74 20 45 78 70 72 Value(const Expr
2cd00 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
2cd10 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 28 45 78 xprIsConstant(Ex
2cd20 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 pr*);.int sqlite
2cd30 33 45 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4e 3ExprIsConstantN
2cd40 6f 74 4a 6f 69 6e 28 45 78 70 72 2a 29 3b 0a 69 otJoin(Expr*);.i
2cd50 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 nt sqlite3ExprIs
2cd60 43 6f 6e 73 74 61 6e 74 4f 72 46 75 6e 63 74 69 ConstantOrFuncti
2cd70 6f 6e 28 45 78 70 72 2a 2c 20 75 38 29 3b 0a 69 on(Expr*, u8);.i
2cd80 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 nt sqlite3ExprIs
2cd90 43 6f 6e 73 74 61 6e 74 4f 72 47 72 6f 75 70 42 ConstantOrGroupB
2cda0 79 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c y(Parse*, Expr*,
2cdb0 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 ExprList*);.int
2cdc0 20 73 71 6c 69 74 65 33 45 78 70 72 49 73 54 61 sqlite3ExprIsTa
2cdd0 62 6c 65 43 6f 6e 73 74 61 6e 74 28 45 78 70 72 bleConstant(Expr
2cde0 2a 2c 69 6e 74 29 3b 0a 23 69 66 64 65 66 20 53 *,int);.#ifdef S
2cdf0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 43 55 52 QLITE_ENABLE_CUR
2ce00 53 4f 52 5f 48 49 4e 54 53 0a 69 6e 74 20 73 71 SOR_HINTS.int sq
2ce10 6c 69 74 65 33 45 78 70 72 43 6f 6e 74 61 69 6e lite3ExprContain
2ce20 73 53 75 62 71 75 65 72 79 28 45 78 70 72 2a 29 sSubquery(Expr*)
2ce30 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c ;.#endif.int sql
2ce40 69 74 65 33 45 78 70 72 49 73 49 6e 74 65 67 65 ite3ExprIsIntege
2ce50 72 28 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a r(Expr*, int*);.
2ce60 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
2ce70 61 6e 42 65 4e 75 6c 6c 28 63 6f 6e 73 74 20 45 anBeNull(const E
2ce80 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 xpr*);.int sqlit
2ce90 65 33 45 78 70 72 4e 65 65 64 73 4e 6f 41 66 66 e3ExprNeedsNoAff
2cea0 69 6e 69 74 79 43 68 61 6e 67 65 28 63 6f 6e 73 inityChange(cons
2ceb0 74 20 45 78 70 72 2a 2c 20 63 68 61 72 29 3b 0a t Expr*, char);.
2cec0 69 6e 74 20 73 71 6c 69 74 65 33 49 73 52 6f 77 int sqlite3IsRow
2ced0 69 64 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b id(const char*);
2cee0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
2cef0 65 72 61 74 65 52 6f 77 44 65 6c 65 74 65 28 0a erateRowDelete(.
2cf00 20 20 20 20 50 61 72 73 65 2a 2c 54 61 62 6c 65 Parse*,Table
2cf10 2a 2c 54 72 69 67 67 65 72 2a 2c 69 6e 74 2c 69 *,Trigger*,int,i
2cf20 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 38 2c 75 38 nt,int,i16,u8,u8
2cf30 2c 75 38 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 ,u8,int);.void s
2cf40 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f qlite3GenerateRo
2cf50 77 49 6e 64 65 78 44 65 6c 65 74 65 28 50 61 72 wIndexDelete(Par
2cf60 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
2cf70 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 , int, int*, int
2cf80 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 );.int sqlite3Ge
2cf90 6e 65 72 61 74 65 49 6e 64 65 78 4b 65 79 28 50 nerateIndexKey(P
2cfa0 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c 20 69 arse*, Index*, i
2cfb0 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e nt, int, int, in
2cfc0 74 2a 2c 49 6e 64 65 78 2a 2c 69 6e 74 29 3b 0a t*,Index*,int);.
2cfd0 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 6f void sqlite3Reso
2cfe0 6c 76 65 50 61 72 74 49 64 78 4c 61 62 65 6c 28 lvePartIdxLabel(
2cff0 50 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 69 6e 74 Parse*,int);.int
2d000 20 73 71 6c 69 74 65 33 45 78 70 72 52 65 66 65 sqlite3ExprRefe
2d010 72 65 6e 63 65 73 55 70 64 61 74 65 64 43 6f 6c rencesUpdatedCol
2d020 75 6d 6e 28 45 78 70 72 2a 2c 69 6e 74 2a 2c 69 umn(Expr*,int*,i
2d030 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
2d040 33 47 65 6e 65 72 61 74 65 43 6f 6e 73 74 72 61 3GenerateConstra
2d050 69 6e 74 43 68 65 63 6b 73 28 50 61 72 73 65 2a intChecks(Parse*
2d060 2c 54 61 62 6c 65 2a 2c 69 6e 74 2a 2c 69 6e 74 ,Table*,int*,int
2d070 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 0a 20 20 ,int,int,int,.
2d080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d090 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d0a0 20 20 20 75 38 2c 75 38 2c 69 6e 74 2c 69 6e 74 u8,u8,int,int
2d0b0 2a 2c 69 6e 74 2a 2c 55 70 73 65 72 74 2a 29 3b *,int*,Upsert*);
2d0c0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
2d0d0 4e 41 42 4c 45 5f 4e 55 4c 4c 5f 54 52 49 4d 0a NABLE_NULL_TRIM.
2d0e0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 void sqlite3Se
2d0f0 74 4d 61 6b 65 52 65 63 6f 72 64 50 35 28 56 64 tMakeRecordP5(Vd
2d100 62 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a 23 65 6c be*,Table*);.#el
2d110 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
2d120 74 65 33 53 65 74 4d 61 6b 65 52 65 63 6f 72 64 te3SetMakeRecord
2d130 50 35 28 41 2c 42 29 0a 23 65 6e 64 69 66 0a 76 P5(A,B).#endif.v
2d140 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 70 6c oid sqlite3Compl
2d150 65 74 65 49 6e 73 65 72 74 69 6f 6e 28 50 61 72 eteInsertion(Par
2d160 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 69 se*,Table*,int,i
2d170 6e 74 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2c nt,int,int*,int,
2d180 69 6e 74 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 int,int);.int sq
2d190 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 41 6e lite3OpenTableAn
2d1a0 64 49 6e 64 69 63 65 73 28 50 61 72 73 65 2a 2c dIndices(Parse*,
2d1b0 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 75 38 Table*, int, u8
2d1c0 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 69 6e 74 2a , int, u8*, int*
2d1d0 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 71 , int*);.void sq
2d1e0 6c 69 74 65 33 42 65 67 69 6e 57 72 69 74 65 4f lite3BeginWriteO
2d1f0 70 65 72 61 74 69 6f 6e 28 50 61 72 73 65 2a 2c peration(Parse*,
2d200 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
2d210 20 73 71 6c 69 74 65 33 4d 75 6c 74 69 57 72 69 sqlite3MultiWri
2d220 74 65 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 te(Parse*);.void
2d230 20 73 71 6c 69 74 65 33 4d 61 79 41 62 6f 72 74 sqlite3MayAbort
2d240 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 (Parse*);.void s
2d250 71 6c 69 74 65 33 48 61 6c 74 43 6f 6e 73 74 72 qlite3HaltConstr
2d260 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 aint(Parse*, int
2d270 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2c 20 69 38 , int, char*, i8
2d280 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 , u8);.void sqli
2d290 74 65 33 55 6e 69 71 75 65 43 6f 6e 73 74 72 61 te3UniqueConstra
2d2a0 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c int(Parse*, int,
2d2b0 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 Index*);.void s
2d2c0 71 6c 69 74 65 33 52 6f 77 69 64 43 6f 6e 73 74 qlite3RowidConst
2d2d0 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e raint(Parse*, in
2d2e0 74 2c 20 54 61 62 6c 65 2a 29 3b 0a 45 78 70 72 t, Table*);.Expr
2d2f0 20 2a 73 71 6c 69 74 65 33 45 78 70 72 44 75 70 *sqlite3ExprDup
2d300 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c (sqlite3*,Expr*,
2d310 69 6e 74 29 3b 0a 45 78 70 72 4c 69 73 74 20 2a int);.ExprList *
2d320 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 44 sqlite3ExprListD
2d330 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 up(sqlite3*,Expr
2d340 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 53 72 63 4c List*,int);.SrcL
2d350 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 4c ist *sqlite3SrcL
2d360 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c istDup(sqlite3*,
2d370 53 72 63 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 49 SrcList*,int);.I
2d380 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 49 64 dList *sqlite3Id
2d390 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a ListDup(sqlite3*
2d3a0 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 65 6c 65 63 ,IdList*);.Selec
2d3b0 74 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 74 t *sqlite3Select
2d3c0 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 6c Dup(sqlite3*,Sel
2d3d0 65 63 74 2a 2c 69 6e 74 29 3b 0a 46 75 6e 63 44 ect*,int);.FuncD
2d3e0 65 66 20 2a 73 71 6c 69 74 65 33 46 75 6e 63 74 ef *sqlite3Funct
2d3f0 69 6f 6e 53 65 61 72 63 68 28 69 6e 74 2c 63 6f ionSearch(int,co
2d400 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 nst char*);.void
2d410 20 73 71 6c 69 74 65 33 49 6e 73 65 72 74 42 75 sqlite3InsertBu
2d420 69 6c 74 69 6e 46 75 6e 63 73 28 46 75 6e 63 44 iltinFuncs(FuncD
2d430 65 66 2a 2c 69 6e 74 29 3b 0a 46 75 6e 63 44 65 ef*,int);.FuncDe
2d440 66 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 46 75 f *sqlite3FindFu
2d450 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c nction(sqlite3*,
2d460 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c const char*,int,
2d470 75 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c u8,u8);.void sql
2d480 69 74 65 33 52 65 67 69 73 74 65 72 42 75 69 6c ite3RegisterBuil
2d490 74 69 6e 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 tinFunctions(voi
2d4a0 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 d);.void sqlite3
2d4b0 52 65 67 69 73 74 65 72 44 61 74 65 54 69 6d 65 RegisterDateTime
2d4c0 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
2d4d0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 .void sqlite3Reg
2d4e0 69 73 74 65 72 50 65 72 43 6f 6e 6e 65 63 74 69 isterPerConnecti
2d4f0 6f 6e 42 75 69 6c 74 69 6e 46 75 6e 63 74 69 6f onBuiltinFunctio
2d500 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e ns(sqlite3*);.in
2d510 74 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 43 t sqlite3SafetyC
2d520 68 65 63 6b 4f 6b 28 73 71 6c 69 74 65 33 2a 29 heckOk(sqlite3*)
2d530 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 61 66 ;.int sqlite3Saf
2d540 65 74 79 43 68 65 63 6b 53 69 63 6b 4f 72 4f 6b etyCheckSickOrOk
2d550 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
2d560 20 73 71 6c 69 74 65 33 43 68 61 6e 67 65 43 6f sqlite3ChangeCo
2d570 6f 6b 69 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 okie(Parse*, int
2d580 29 3b 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 64 );..#if !defined
2d590 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 (SQLITE_OMIT_VIE
2d5a0 57 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 W) && !defined(S
2d5b0 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 QLITE_OMIT_TRIGG
2d5c0 45 52 29 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 ER).void sqlite3
2d5d0 4d 61 74 65 72 69 61 6c 69 7a 65 56 69 65 77 28 MaterializeView(
2d5e0 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 Parse*, Table*,
2d5f0 45 78 70 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a Expr*, ExprList*
2d600 2c 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 23 65 6e ,Expr*,int);.#en
2d610 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c dif..#ifndef SQL
2d620 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 ITE_OMIT_TRIGGER
2d630 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 42 . void sqlite3B
2d640 65 67 69 6e 54 72 69 67 67 65 72 28 50 61 72 73 eginTrigger(Pars
2d650 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e e*, Token*,Token
2d660 2a 2c 69 6e 74 2c 69 6e 74 2c 49 64 4c 69 73 74 *,int,int,IdList
2d670 2a 2c 53 72 63 4c 69 73 74 2a 2c 0a 20 20 20 20 *,SrcList*,.
2d680 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d690 20 20 20 20 20 20 20 45 78 70 72 2a 2c 69 6e 74 Expr*,int
2d6a0 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 , int);. void s
2d6b0 71 6c 69 74 65 33 46 69 6e 69 73 68 54 72 69 67 qlite3FinishTrig
2d6c0 67 65 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 ger(Parse*, Trig
2d6d0 67 65 72 53 74 65 70 2a 2c 20 54 6f 6b 65 6e 2a gerStep*, Token*
2d6e0 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
2d6f0 33 44 72 6f 70 54 72 69 67 67 65 72 28 50 61 72 3DropTrigger(Par
2d700 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 se*, SrcList*, i
2d710 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 nt);. void sqli
2d720 74 65 33 44 72 6f 70 54 72 69 67 67 65 72 50 74 te3DropTriggerPt
2d730 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 r(Parse*, Trigge
2d740 72 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 20 2a r*);. Trigger *
2d750 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 73 45 sqlite3TriggersE
2d760 78 69 73 74 28 50 61 72 73 65 20 2a 2c 20 54 61 xist(Parse *, Ta
2d770 62 6c 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c ble*, int, ExprL
2d780 69 73 74 2a 2c 20 69 6e 74 20 2a 70 4d 61 73 6b ist*, int *pMask
2d790 29 3b 0a 20 20 54 72 69 67 67 65 72 20 2a 73 71 );. Trigger *sq
2d7a0 6c 69 74 65 33 54 72 69 67 67 65 72 4c 69 73 74 lite3TriggerList
2d7b0 28 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 20 (Parse *, Table
2d7c0 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
2d7d0 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 e3CodeRowTrigger
2d7e0 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 (Parse*, Trigger
2d7f0 20 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 *, int, ExprLis
2d800 74 2a 2c 20 69 6e 74 2c 20 54 61 62 6c 65 20 2a t*, int, Table *
2d810 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
2d820 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e in
2d830 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 t, int, int);.
2d840 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 void sqlite3Code
2d850 52 6f 77 54 72 69 67 67 65 72 44 69 72 65 63 74 RowTriggerDirect
2d860 28 50 61 72 73 65 20 2a 2c 20 54 72 69 67 67 65 (Parse *, Trigge
2d870 72 20 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e r *, Table *, in
2d880 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 t, int, int);.
2d890 76 6f 69 64 20 73 71 6c 69 74 65 56 69 65 77 54 void sqliteViewT
2d8a0 72 69 67 67 65 72 73 28 50 61 72 73 65 2a 2c 20 riggers(Parse*,
2d8b0 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Table*, Expr*, i
2d8c0 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a nt, ExprList*);.
2d8d0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 void sqlite3De
2d8e0 6c 65 74 65 54 72 69 67 67 65 72 53 74 65 70 28 leteTriggerStep(
2d8f0 73 71 6c 69 74 65 33 2a 2c 20 54 72 69 67 67 65 sqlite3*, Trigge
2d900 72 53 74 65 70 2a 29 3b 0a 20 20 54 72 69 67 67 rStep*);. Trigg
2d910 65 72 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 erStep *sqlite3T
2d920 72 69 67 67 65 72 53 65 6c 65 63 74 53 74 65 70 riggerSelectStep
2d930 28 73 71 6c 69 74 65 33 2a 2c 53 65 6c 65 63 74 (sqlite3*,Select
2d940 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 *,.
2d950 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d960 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 const
2d970 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 char*,const cha
2d980 72 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 r*);. TriggerSt
2d990 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 ep *sqlite3Trigg
2d9a0 65 72 49 6e 73 65 72 74 53 74 65 70 28 50 61 72 erInsertStep(Par
2d9b0 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 20 49 64 4c 69 se*,Token*, IdLi
2d9c0 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 st*,.
2d9d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2d9e0 20 20 20 20 20 20 20 20 20 20 20 20 20 53 65 6c Sel
2d9f0 65 63 74 2a 2c 75 38 2c 55 70 73 65 72 74 2a 2c ect*,u8,Upsert*,
2da00 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
2da10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2da20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 const c
2da30 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a har*,const char*
2da40 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 );. TriggerStep
2da50 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 *sqlite3Trigger
2da60 55 70 64 61 74 65 53 74 65 70 28 50 61 72 73 65 UpdateStep(Parse
2da70 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 *,Token*,ExprLis
2da80 74 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c 0a 20 t*, Expr*, u8,.
2da90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2daa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2dab0 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 const cha
2dac0 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b r*,const char*);
2dad0 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a . TriggerStep *
2dae0 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 44 65 sqlite3TriggerDe
2daf0 6c 65 74 65 53 74 65 70 28 50 61 72 73 65 2a 2c leteStep(Parse*,
2db00 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 2a 2c 0a 20 Token*, Expr*,.
2db10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2db20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2db30 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 const cha
2db40 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b r*,const char*);
2db50 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 . void sqlite3D
2db60 65 6c 65 74 65 54 72 69 67 67 65 72 28 73 71 6c eleteTrigger(sql
2db70 69 74 65 33 2a 2c 20 54 72 69 67 67 65 72 2a 29 ite3*, Trigger*)
2db80 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
2db90 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 UnlinkAndDeleteT
2dba0 72 69 67 67 65 72 28 73 71 6c 69 74 65 33 2a 2c rigger(sqlite3*,
2dbb0 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 int,const char*)
2dbc0 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 65 33 54 ;. u32 sqlite3T
2dbd0 72 69 67 67 65 72 43 6f 6c 6d 61 73 6b 28 50 61 riggerColmask(Pa
2dbe0 72 73 65 2a 2c 54 72 69 67 67 65 72 2a 2c 45 78 rse*,Trigger*,Ex
2dbf0 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 69 6e 74 2c prList*,int,int,
2dc00 54 61 62 6c 65 2a 2c 69 6e 74 29 3b 0a 23 20 64 Table*,int);.# d
2dc10 65 66 69 6e 65 20 73 71 6c 69 74 65 33 50 61 72 efine sqlite3Par
2dc20 73 65 54 6f 70 6c 65 76 65 6c 28 70 29 20 28 28 seToplevel(p) ((
2dc30 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 3f 20 p)->pToplevel ?
2dc40 28 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 3a (p)->pToplevel :
2dc50 20 28 70 29 29 0a 23 20 64 65 66 69 6e 65 20 73 (p)).# define s
2dc60 71 6c 69 74 65 33 49 73 54 6f 70 6c 65 76 65 6c qlite3IsToplevel
2dc70 28 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 6c 65 (p) ((p)->pTople
2dc80 76 65 6c 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 20 vel==0).#else.#
2dc90 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 define sqlite3Tr
2dca0 69 67 67 65 72 73 45 78 69 73 74 28 42 2c 43 2c iggersExist(B,C,
2dcb0 44 2c 45 2c 46 29 20 30 0a 23 20 64 65 66 69 6e D,E,F) 0.# defin
2dcc0 65 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 54 e sqlite3DeleteT
2dcd0 72 69 67 67 65 72 28 41 2c 42 29 0a 23 20 64 65 rigger(A,B).# de
2dce0 66 69 6e 65 20 73 71 6c 69 74 65 33 44 72 6f 70 fine sqlite3Drop
2dcf0 54 72 69 67 67 65 72 50 74 72 28 41 2c 42 29 0a TriggerPtr(A,B).
2dd00 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
2dd10 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 UnlinkAndDeleteT
2dd20 72 69 67 67 65 72 28 41 2c 42 2c 43 29 0a 23 20 rigger(A,B,C).#
2dd30 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f define sqlite3Co
2dd40 64 65 52 6f 77 54 72 69 67 67 65 72 28 41 2c 42 deRowTrigger(A,B
2dd50 2c 43 2c 44 2c 45 2c 46 2c 47 2c 48 2c 49 29 0a ,C,D,E,F,G,H,I).
2dd60 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
2dd70 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 44 69 CodeRowTriggerDi
2dd80 72 65 63 74 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 rect(A,B,C,D,E,F
2dd90 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
2dda0 65 33 54 72 69 67 67 65 72 4c 69 73 74 28 58 2c e3TriggerList(X,
2ddb0 20 59 29 20 30 0a 23 20 64 65 66 69 6e 65 20 73 Y) 0.# define s
2ddc0 71 6c 69 74 65 33 50 61 72 73 65 54 6f 70 6c 65 qlite3ParseTople
2ddd0 76 65 6c 28 70 29 20 70 0a 23 20 64 65 66 69 6e vel(p) p.# defin
2dde0 65 20 73 71 6c 69 74 65 33 49 73 54 6f 70 6c 65 e sqlite3IsTople
2ddf0 76 65 6c 28 70 29 20 31 0a 23 20 64 65 66 69 6e vel(p) 1.# defin
2de00 65 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 e sqlite3Trigger
2de10 43 6f 6c 6d 61 73 6b 28 41 2c 42 2c 43 2c 44 2c Colmask(A,B,C,D,
2de20 45 2c 46 2c 47 29 20 30 0a 23 65 6e 64 69 66 0a E,F,G) 0.#endif.
2de30 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 69 6e .int sqlite3Join
2de40 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b Type(Parse*, Tok
2de50 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b en*, Token*, Tok
2de60 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
2de70 65 33 43 72 65 61 74 65 46 6f 72 65 69 67 6e 4b e3CreateForeignK
2de80 65 79 28 50 61 72 73 65 2a 2c 20 45 78 70 72 4c ey(Parse*, ExprL
2de90 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 45 78 ist*, Token*, Ex
2dea0 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a 76 prList*, int);.v
2deb0 6f 69 64 20 73 71 6c 69 74 65 33 44 65 66 65 72 oid sqlite3Defer
2dec0 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 72 73 65 ForeignKey(Parse
2ded0 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 6e 64 65 66 *, int);.#ifndef
2dee0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 54 SQLITE_OMIT_AUT
2def0 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 76 6f 69 HORIZATION. voi
2df00 64 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 d sqlite3AuthRea
2df10 64 28 50 61 72 73 65 2a 2c 45 78 70 72 2a 2c 53 d(Parse*,Expr*,S
2df20 63 68 65 6d 61 2a 2c 53 72 63 4c 69 73 74 2a 29 chema*,SrcList*)
2df30 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 41 ;. int sqlite3A
2df40 75 74 68 43 68 65 63 6b 28 50 61 72 73 65 2a 2c uthCheck(Parse*,
2df50 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a int, const char*
2df60 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 , const char*, c
2df70 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 onst char*);. v
2df80 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 68 43 oid sqlite3AuthC
2df90 6f 6e 74 65 78 74 50 75 73 68 28 50 61 72 73 65 ontextPush(Parse
2dfa0 2a 2c 20 41 75 74 68 43 6f 6e 74 65 78 74 2a 2c *, AuthContext*,
2dfb0 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 const char*);.
2dfc0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 void sqlite3Aut
2dfd0 68 43 6f 6e 74 65 78 74 50 6f 70 28 41 75 74 68 hContextPop(Auth
2dfe0 43 6f 6e 74 65 78 74 2a 29 3b 0a 20 20 69 6e 74 Context*);. int
2dff0 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 64 sqlite3AuthRead
2e000 43 6f 6c 28 50 61 72 73 65 2a 2c 20 63 6f 6e 73 Col(Parse*, cons
2e010 74 20 63 68 61 72 20 2a 2c 20 63 6f 6e 73 74 20 t char *, const
2e020 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 23 65 char *, int);.#e
2e030 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
2e040 69 74 65 33 41 75 74 68 52 65 61 64 28 61 2c 62 ite3AuthRead(a,b
2e050 2c 63 2c 64 29 0a 23 20 64 65 66 69 6e 65 20 73 ,c,d).# define s
2e060 71 6c 69 74 65 33 41 75 74 68 43 68 65 63 6b 28 qlite3AuthCheck(
2e070 61 2c 62 2c 63 2c 64 2c 65 29 20 20 20 20 53 51 a,b,c,d,e) SQ
2e080 4c 49 54 45 5f 4f 4b 0a 23 20 64 65 66 69 6e 65 LITE_OK.# define
2e090 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 sqlite3AuthCont
2e0a0 65 78 74 50 75 73 68 28 61 2c 62 2c 63 29 0a 23 extPush(a,b,c).#
2e0b0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 define sqlite3A
2e0c0 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 61 29 uthContextPop(a)
2e0d0 20 20 28 28 76 6f 69 64 29 28 61 29 29 0a 23 65 ((void)(a)).#e
2e0e0 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 ndif.void sqlite
2e0f0 33 41 74 74 61 63 68 28 50 61 72 73 65 2a 2c 20 3Attach(Parse*,
2e100 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 45 78 Expr*, Expr*, Ex
2e110 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 pr*);.void sqlit
2e120 65 33 44 65 74 61 63 68 28 50 61 72 73 65 2a 2c e3Detach(Parse*,
2e130 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 Expr*);.void sq
2e140 6c 69 74 65 33 46 69 78 49 6e 69 74 28 44 62 46 lite3FixInit(DbF
2e150 69 78 65 72 2a 2c 20 50 61 72 73 65 2a 2c 20 69 ixer*, Parse*, i
2e160 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c nt, const char*,
2e170 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 29 3b 0a const Token*);.
2e180 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 53 72 int sqlite3FixSr
2e190 63 4c 69 73 74 28 44 62 46 69 78 65 72 2a 2c 20 cList(DbFixer*,
2e1a0 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 SrcList*);.int s
2e1b0 71 6c 69 74 65 33 46 69 78 53 65 6c 65 63 74 28 qlite3FixSelect(
2e1c0 44 62 46 69 78 65 72 2a 2c 20 53 65 6c 65 63 74 DbFixer*, Select
2e1d0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 *);.int sqlite3F
2e1e0 69 78 45 78 70 72 28 44 62 46 69 78 65 72 2a 2c ixExpr(DbFixer*,
2e1f0 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c Expr*);.int sql
2e200 69 74 65 33 46 69 78 45 78 70 72 4c 69 73 74 28 ite3FixExprList(
2e210 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 4c 69 DbFixer*, ExprLi
2e220 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 st*);.int sqlite
2e230 33 46 69 78 54 72 69 67 67 65 72 53 74 65 70 28 3FixTriggerStep(
2e240 44 62 46 69 78 65 72 2a 2c 20 54 72 69 67 67 65 DbFixer*, Trigge
2e250 72 53 74 65 70 2a 29 3b 0a 69 6e 74 20 73 71 6c rStep*);.int sql
2e260 69 74 65 33 52 65 61 6c 53 61 6d 65 41 73 49 6e ite3RealSameAsIn
2e270 74 28 64 6f 75 62 6c 65 2c 73 71 6c 69 74 65 33 t(double,sqlite3
2e280 5f 69 6e 74 36 34 29 3b 0a 69 6e 74 20 73 71 6c _int64);.int sql
2e290 69 74 65 33 41 74 6f 46 28 63 6f 6e 73 74 20 63 ite3AtoF(const c
2e2a0 68 61 72 20 2a 7a 2c 20 64 6f 75 62 6c 65 2a 2c har *z, double*,
2e2b0 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 int, u8);.int s
2e2c0 71 6c 69 74 65 33 47 65 74 49 6e 74 33 32 28 63 qlite3GetInt32(c
2e2d0 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 onst char *, int
2e2e0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 *);.int sqlite3A
2e2f0 74 6f 69 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 toi(const char*)
2e300 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
2e310 5f 4f 4d 49 54 5f 55 54 46 31 36 0a 69 6e 74 20 _OMIT_UTF16.int
2e320 73 71 6c 69 74 65 33 55 74 66 31 36 42 79 74 65 sqlite3Utf16Byte
2e330 4c 65 6e 28 63 6f 6e 73 74 20 76 6f 69 64 20 2a Len(const void *
2e340 70 44 61 74 61 2c 20 69 6e 74 20 6e 43 68 61 72 pData, int nChar
2e350 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 );.#endif.int sq
2e360 6c 69 74 65 33 55 74 66 38 43 68 61 72 4c 65 6e lite3Utf8CharLen
2e370 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 44 61 (const char *pDa
2e380 74 61 2c 20 69 6e 74 20 6e 42 79 74 65 29 3b 0a ta, int nByte);.
2e390 75 33 32 20 73 71 6c 69 74 65 33 55 74 66 38 52 u32 sqlite3Utf8R
2e3a0 65 61 64 28 63 6f 6e 73 74 20 75 38 2a 2a 29 3b ead(const u8**);
2e3b0 0a 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 33 4c .LogEst sqlite3L
2e3c0 6f 67 45 73 74 28 75 36 34 29 3b 0a 4c 6f 67 45 ogEst(u64);.LogE
2e3d0 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 st sqlite3LogEst
2e3e0 41 64 64 28 4c 6f 67 45 73 74 2c 4c 6f 67 45 73 Add(LogEst,LogEs
2e3f0 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 t);.#ifndef SQLI
2e400 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
2e410 41 42 4c 45 0a 4c 6f 67 45 73 74 20 73 71 6c 69 ABLE.LogEst sqli
2e420 74 65 33 4c 6f 67 45 73 74 46 72 6f 6d 44 6f 75 te3LogEstFromDou
2e430 62 6c 65 28 64 6f 75 62 6c 65 29 3b 0a 23 65 6e ble(double);.#en
2e440 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
2e450 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
2e460 4d 54 5f 53 43 41 4e 53 54 41 54 55 53 29 20 7c MT_SCANSTATUS) |
2e470 7c 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 | \. defined(
2e480 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
2e490 41 54 34 29 20 7c 7c 20 5c 0a 20 20 20 20 64 65 AT4) || \. de
2e4a0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 58 50 fined(SQLITE_EXP
2e4b0 4c 41 49 4e 5f 45 53 54 49 4d 41 54 45 44 5f 52 LAIN_ESTIMATED_R
2e4c0 4f 57 53 29 0a 75 36 34 20 73 71 6c 69 74 65 33 OWS).u64 sqlite3
2e4d0 4c 6f 67 45 73 74 54 6f 49 6e 74 28 4c 6f 67 45 LogEstToInt(LogE
2e4e0 73 74 29 3b 0a 23 65 6e 64 69 66 0a 56 4c 69 73 st);.#endif.VLis
2e4f0 74 20 2a 73 71 6c 69 74 65 33 56 4c 69 73 74 41 t *sqlite3VListA
2e500 64 64 28 73 71 6c 69 74 65 33 2a 2c 56 4c 69 73 dd(sqlite3*,VLis
2e510 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 t*,const char*,i
2e520 6e 74 2c 69 6e 74 29 3b 0a 63 6f 6e 73 74 20 63 nt,int);.const c
2e530 68 61 72 20 2a 73 71 6c 69 74 65 33 56 4c 69 73 har *sqlite3VLis
2e540 74 4e 75 6d 54 6f 4e 61 6d 65 28 56 4c 69 73 74 tNumToName(VList
2e550 2a 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 *,int);.int sqli
2e560 74 65 33 56 4c 69 73 74 4e 61 6d 65 54 6f 4e 75 te3VListNameToNu
2e570 6d 28 56 4c 69 73 74 2a 2c 63 6f 6e 73 74 20 63 m(VList*,const c
2e580 68 61 72 2a 2c 69 6e 74 29 3b 0a 0a 2f 2a 0a 2a har*,int);../*.*
2e590 2a 20 52 6f 75 74 69 6e 65 73 20 74 6f 20 72 65 * Routines to re
2e5a0 61 64 20 61 6e 64 20 77 72 69 74 65 20 76 61 72 ad and write var
2e5b0 69 61 62 6c 65 2d 6c 65 6e 67 74 68 20 69 6e 74 iable-length int
2e5c0 65 67 65 72 73 2e 20 20 54 68 65 73 65 20 75 73 egers. These us
2e5d0 65 64 20 74 6f 0a 2a 2a 20 62 65 20 64 65 66 69 ed to.** be defi
2e5e0 6e 65 64 20 6c 6f 63 61 6c 6c 79 2c 20 62 75 74 ned locally, but
2e5f0 20 6e 6f 77 20 77 65 20 75 73 65 20 74 68 65 20 now we use the
2e600 76 61 72 69 6e 74 20 72 6f 75 74 69 6e 65 73 20 varint routines
2e610 69 6e 20 74 68 65 20 75 74 69 6c 2e 63 0a 2a 2a in the util.c.**
2e620 20 66 69 6c 65 2e 0a 2a 2f 0a 69 6e 74 20 73 71 file..*/.int sq
2e630 6c 69 74 65 33 50 75 74 56 61 72 69 6e 74 28 75 lite3PutVarint(u
2e640 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 2c 20 75 nsigned char*, u
2e650 36 34 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 64);.u8 sqlite3G
2e660 65 74 56 61 72 69 6e 74 28 63 6f 6e 73 74 20 75 etVarint(const u
2e670 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 nsigned char *,
2e680 75 36 34 20 2a 29 3b 0a 75 38 20 73 71 6c 69 74 u64 *);.u8 sqlit
2e690 65 33 47 65 74 56 61 72 69 6e 74 33 32 28 63 6f e3GetVarint32(co
2e6a0 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 nst unsigned cha
2e6b0 72 20 2a 2c 20 75 33 32 20 2a 29 3b 0a 69 6e 74 r *, u32 *);.int
2e6c0 20 73 71 6c 69 74 65 33 56 61 72 69 6e 74 4c 65 sqlite3VarintLe
2e6d0 6e 28 75 36 34 20 76 29 3b 0a 0a 2f 2a 0a 2a 2a n(u64 v);../*.**
2e6e0 20 54 68 65 20 63 6f 6d 6d 6f 6e 20 63 61 73 65 The common case
2e6f0 20 69 73 20 66 6f 72 20 61 20 76 61 72 69 6e 74 is for a varint
2e700 20 74 6f 20 62 65 20 61 20 73 69 6e 67 6c 65 20 to be a single
2e710 62 79 74 65 2e 20 20 54 68 65 79 20 66 6f 6c 6c byte. They foll
2e720 6f 77 69 6e 67 0a 2a 2a 20 6d 61 63 72 6f 73 20 owing.** macros
2e730 68 61 6e 64 6c 65 20 74 68 65 20 63 6f 6d 6d 6f handle the commo
2e740 6e 20 63 61 73 65 20 77 69 74 68 6f 75 74 20 61 n case without a
2e750 20 70 72 6f 63 65 64 75 72 65 20 63 61 6c 6c 2c procedure call,
2e760 20 62 75 74 20 74 68 65 6e 20 63 61 6c 6c 0a 2a but then call.*
2e770 2a 20 74 68 65 20 70 72 6f 63 65 64 75 72 65 20 * the procedure
2e780 66 6f 72 20 6c 61 72 67 65 72 20 76 61 72 69 6e for larger varin
2e790 74 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 67 ts..*/.#define g
2e7a0 65 74 56 61 72 69 6e 74 33 32 28 41 2c 42 29 20 etVarint32(A,B)
2e7b0 20 5c 0a 20 20 28 75 38 29 28 28 2a 28 41 29 3c \. (u8)((*(A)<
2e7c0 28 75 38 29 30 78 38 30 29 3f 28 28 42 29 3d 28 (u8)0x80)?((B)=(
2e7d0 75 33 32 29 2a 28 41 29 29 2c 31 3a 73 71 6c 69 u32)*(A)),1:sqli
2e7e0 74 65 33 47 65 74 56 61 72 69 6e 74 33 32 28 28 te3GetVarint32((
2e7f0 41 29 2c 28 75 33 32 20 2a 29 26 28 42 29 29 29 A),(u32 *)&(B)))
2e800 0a 23 64 65 66 69 6e 65 20 70 75 74 56 61 72 69 .#define putVari
2e810 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a 20 20 28 nt32(A,B) \. (
2e820 75 38 29 28 28 28 75 33 32 29 28 42 29 3c 28 75 u8)(((u32)(B)<(u
2e830 33 32 29 30 78 38 30 29 3f 28 2a 28 41 29 3d 28 32)0x80)?(*(A)=(
2e840 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 42 unsigned char)(B
2e850 29 29 2c 31 3a 5c 0a 20 20 73 71 6c 69 74 65 33 )),1:\. sqlite3
2e860 50 75 74 56 61 72 69 6e 74 28 28 41 29 2c 28 42 PutVarint((A),(B
2e870 29 29 29 0a 23 64 65 66 69 6e 65 20 67 65 74 56 ))).#define getV
2e880 61 72 69 6e 74 20 20 20 20 73 71 6c 69 74 65 33 arint sqlite3
2e890 47 65 74 56 61 72 69 6e 74 0a 23 64 65 66 69 6e GetVarint.#defin
2e8a0 65 20 70 75 74 56 61 72 69 6e 74 20 20 20 20 73 e putVarint s
2e8b0 71 6c 69 74 65 33 50 75 74 56 61 72 69 6e 74 0a qlite3PutVarint.
2e8c0 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 ..const char *sq
2e8d0 6c 69 74 65 33 49 6e 64 65 78 41 66 66 69 6e 69 lite3IndexAffini
2e8e0 74 79 53 74 72 28 73 71 6c 69 74 65 33 2a 2c 20 tyStr(sqlite3*,
2e8f0 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 Index*);.void sq
2e900 6c 69 74 65 33 54 61 62 6c 65 41 66 66 69 6e 69 lite3TableAffini
2e910 74 79 28 56 64 62 65 2a 2c 20 54 61 62 6c 65 2a ty(Vdbe*, Table*
2e920 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 73 71 6c , int);.char sql
2e930 69 74 65 33 43 6f 6d 70 61 72 65 41 66 66 69 6e ite3CompareAffin
2e940 69 74 79 28 45 78 70 72 20 2a 70 45 78 70 72 2c ity(Expr *pExpr,
2e950 20 63 68 61 72 20 61 66 66 32 29 3b 0a 69 6e 74 char aff2);.int
2e960 20 73 71 6c 69 74 65 33 49 6e 64 65 78 41 66 66 sqlite3IndexAff
2e970 69 6e 69 74 79 4f 6b 28 45 78 70 72 20 2a 70 45 inityOk(Expr *pE
2e980 78 70 72 2c 20 63 68 61 72 20 69 64 78 5f 61 66 xpr, char idx_af
2e990 66 69 6e 69 74 79 29 3b 0a 63 68 61 72 20 73 71 finity);.char sq
2e9a0 6c 69 74 65 33 54 61 62 6c 65 43 6f 6c 75 6d 6e lite3TableColumn
2e9b0 41 66 66 69 6e 69 74 79 28 54 61 62 6c 65 2a 2c Affinity(Table*,
2e9c0 69 6e 74 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 int);.char sqlit
2e9d0 65 33 45 78 70 72 41 66 66 69 6e 69 74 79 28 45 e3ExprAffinity(E
2e9e0 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 69 6e 74 xpr *pExpr);.int
2e9f0 20 73 71 6c 69 74 65 33 41 74 6f 69 36 34 28 63 sqlite3Atoi64(c
2ea00 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a onst char*, i64*
2ea10 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 , int, u8);.int
2ea20 73 71 6c 69 74 65 33 44 65 63 4f 72 48 65 78 54 sqlite3DecOrHexT
2ea30 6f 49 36 34 28 63 6f 6e 73 74 20 63 68 61 72 2a oI64(const char*
2ea40 2c 20 69 36 34 2a 29 3b 0a 76 6f 69 64 20 73 71 , i64*);.void sq
2ea50 6c 69 74 65 33 45 72 72 6f 72 57 69 74 68 4d 73 lite3ErrorWithMs
2ea60 67 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c g(sqlite3*, int,
2ea70 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e 2e 2e const char*,...
2ea80 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
2ea90 72 72 6f 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e rror(sqlite3*,in
2eaa0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
2eab0 53 79 73 74 65 6d 45 72 72 6f 72 28 73 71 6c 69 SystemError(sqli
2eac0 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 te3*,int);.void
2ead0 2a 73 71 6c 69 74 65 33 48 65 78 54 6f 42 6c 6f *sqlite3HexToBlo
2eae0 62 28 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 b(sqlite3*, cons
2eaf0 74 20 63 68 61 72 20 2a 7a 2c 20 69 6e 74 20 6e t char *z, int n
2eb00 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 48 65 78 );.u8 sqlite3Hex
2eb10 54 6f 49 6e 74 28 69 6e 74 20 68 29 3b 0a 69 6e ToInt(int h);.in
2eb20 74 20 73 71 6c 69 74 65 33 54 77 6f 50 61 72 74 t sqlite3TwoPart
2eb30 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c 20 54 6f Name(Parse *, To
2eb40 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c 20 ken *, Token *,
2eb50 54 6f 6b 65 6e 20 2a 2a 29 3b 0a 0a 23 69 66 20 Token **);..#if
2eb60 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4e defined(SQLITE_N
2eb70 45 45 44 5f 45 52 52 5f 4e 41 4d 45 29 0a 63 6f EED_ERR_NAME).co
2eb80 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 nst char *sqlite
2eb90 33 45 72 72 4e 61 6d 65 28 69 6e 74 29 3b 0a 23 3ErrName(int);.#
2eba0 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
2ebb0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 45 53 45 LITE_ENABLE_DESE
2ebc0 52 49 41 4c 49 5a 45 0a 69 6e 74 20 73 71 6c 69 RIALIZE.int sqli
2ebd0 74 65 33 4d 65 6d 64 62 49 6e 69 74 28 76 6f 69 te3MemdbInit(voi
2ebe0 64 29 3b 0a 23 65 6e 64 69 66 0a 0a 63 6f 6e 73 d);.#endif..cons
2ebf0 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 45 t char *sqlite3E
2ec00 72 72 53 74 72 28 69 6e 74 29 3b 0a 69 6e 74 20 rrStr(int);.int
2ec10 73 71 6c 69 74 65 33 52 65 61 64 53 63 68 65 6d sqlite3ReadSchem
2ec20 61 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 29 a(Parse *pParse)
2ec30 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 ;.CollSeq *sqlit
2ec40 65 33 46 69 6e 64 43 6f 6c 6c 53 65 71 28 73 71 e3FindCollSeq(sq
2ec50 6c 69 74 65 33 2a 2c 75 38 20 65 6e 63 2c 20 63 lite3*,u8 enc, c
2ec60 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b onst char*,int);
2ec70 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 73 42 69 .int sqlite3IsBi
2ec80 6e 61 72 79 28 63 6f 6e 73 74 20 43 6f 6c 6c 53 nary(const CollS
2ec90 65 71 2a 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 eq*);.CollSeq *s
2eca0 71 6c 69 74 65 33 4c 6f 63 61 74 65 43 6f 6c 6c qlite3LocateColl
2ecb0 53 65 71 28 50 61 72 73 65 20 2a 70 50 61 72 73 Seq(Parse *pPars
2ecc0 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 7a 4e e, const char*zN
2ecd0 61 6d 65 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 ame);.CollSeq *s
2ece0 71 6c 69 74 65 33 45 78 70 72 43 6f 6c 6c 53 65 qlite3ExprCollSe
2ecf0 71 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c q(Parse *pParse,
2ed00 20 45 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 43 Expr *pExpr);.C
2ed10 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 45 ollSeq *sqlite3E
2ed20 78 70 72 4e 4e 43 6f 6c 6c 53 65 71 28 50 61 72 xprNNCollSeq(Par
2ed30 73 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 se *pParse, Expr
2ed40 20 2a 70 45 78 70 72 29 3b 0a 69 6e 74 20 73 71 *pExpr);.int sq
2ed50 6c 69 74 65 33 45 78 70 72 43 6f 6c 6c 53 65 71 lite3ExprCollSeq
2ed60 4d 61 74 63 68 28 50 61 72 73 65 2a 2c 45 78 70 Match(Parse*,Exp
2ed70 72 2a 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 r*,Expr*);.Expr
2ed80 2a 73 71 6c 69 74 65 33 45 78 70 72 41 64 64 43 *sqlite3ExprAddC
2ed90 6f 6c 6c 61 74 65 54 6f 6b 65 6e 28 50 61 72 73 ollateToken(Pars
2eda0 65 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 2a e *pParse, Expr*
2edb0 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c 20 , const Token*,
2edc0 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 int);.Expr *sqli
2edd0 74 65 33 45 78 70 72 41 64 64 43 6f 6c 6c 61 74 te3ExprAddCollat
2ede0 65 53 74 72 69 6e 67 28 50 61 72 73 65 2a 2c 45 eString(Parse*,E
2edf0 78 70 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a xpr*,const char*
2ee00 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
2ee10 45 78 70 72 53 6b 69 70 43 6f 6c 6c 61 74 65 28 ExprSkipCollate(
2ee20 45 78 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 Expr*);.Expr *sq
2ee30 6c 69 74 65 33 45 78 70 72 53 6b 69 70 43 6f 6c lite3ExprSkipCol
2ee40 6c 61 74 65 41 6e 64 4c 69 6b 65 6c 79 28 45 78 lateAndLikely(Ex
2ee50 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 pr*);.int sqlite
2ee60 33 43 68 65 63 6b 43 6f 6c 6c 53 65 71 28 50 61 3CheckCollSeq(Pa
2ee70 72 73 65 20 2a 2c 20 43 6f 6c 6c 53 65 71 20 2a rse *, CollSeq *
2ee80 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 72 );.int sqlite3Wr
2ee90 69 74 61 62 6c 65 53 63 68 65 6d 61 28 73 71 6c itableSchema(sql
2eea0 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ite3*);.int sqli
2eeb0 74 65 33 43 68 65 63 6b 4f 62 6a 65 63 74 4e 61 te3CheckObjectNa
2eec0 6d 65 28 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 me(Parse*, const
2eed0 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 char*,const cha
2eee0 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b r*,const char*);
2eef0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 64 62 .void sqlite3Vdb
2ef00 65 53 65 74 43 68 61 6e 67 65 73 28 73 71 6c 69 eSetChanges(sqli
2ef10 74 65 33 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 te3 *, int);.int
2ef20 20 73 71 6c 69 74 65 33 41 64 64 49 6e 74 36 34 sqlite3AddInt64
2ef30 28 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 (i64*,i64);.int
2ef40 73 71 6c 69 74 65 33 53 75 62 49 6e 74 36 34 28 sqlite3SubInt64(
2ef50 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 i64*,i64);.int s
2ef60 71 6c 69 74 65 33 4d 75 6c 49 6e 74 36 34 28 69 qlite3MulInt64(i
2ef70 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 64*,i64);.int sq
2ef80 6c 69 74 65 33 41 62 73 49 6e 74 33 32 28 69 6e lite3AbsInt32(in
2ef90 74 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 54 t);.#ifdef SQLIT
2efa0 45 5f 45 4e 41 42 4c 45 5f 38 5f 33 5f 4e 41 4d E_ENABLE_8_3_NAM
2efb0 45 53 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 ES.void sqlite3F
2efc0 69 6c 65 53 75 66 66 69 78 33 28 63 6f 6e 73 74 ileSuffix3(const
2efd0 20 63 68 61 72 2a 2c 20 63 68 61 72 2a 29 3b 0a char*, char*);.
2efe0 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
2eff0 71 6c 69 74 65 33 46 69 6c 65 53 75 66 66 69 78 qlite3FileSuffix
2f000 33 28 58 2c 59 29 0a 23 65 6e 64 69 66 0a 75 38 3(X,Y).#endif.u8
2f010 20 73 71 6c 69 74 65 33 47 65 74 42 6f 6f 6c 65 sqlite3GetBoole
2f020 61 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a an(const char *z
2f030 2c 75 38 29 3b 0a 0a 63 6f 6e 73 74 20 76 6f 69 ,u8);..const voi
2f040 64 20 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 54 d *sqlite3ValueT
2f050 65 78 74 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ext(sqlite3_valu
2f060 65 2a 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c e*, u8);.int sql
2f070 69 74 65 33 56 61 6c 75 65 42 79 74 65 73 28 73 ite3ValueBytes(s
2f080 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 qlite3_value*, u
2f090 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 8);.void sqlite3
2f0a0 56 61 6c 75 65 53 65 74 53 74 72 28 73 71 6c 69 ValueSetStr(sqli
2f0b0 74 65 33 5f 76 61 6c 75 65 2a 2c 20 69 6e 74 2c te3_value*, int,
2f0c0 20 63 6f 6e 73 74 20 76 6f 69 64 20 2a 2c 75 38 const void *,u8
2f0d0 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
2f0e0 20 20 20 20 20 20 20 20 20 20 76 6f 69 64 28 2a void(*
2f0f0 29 28 76 6f 69 64 2a 29 29 3b 0a 76 6f 69 64 20 )(void*));.void
2f100 73 71 6c 69 74 65 33 56 61 6c 75 65 53 65 74 4e sqlite3ValueSetN
2f110 75 6c 6c 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ull(sqlite3_valu
2f120 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
2f130 33 56 61 6c 75 65 46 72 65 65 28 73 71 6c 69 74 3ValueFree(sqlit
2f140 65 33 5f 76 61 6c 75 65 2a 29 3b 0a 23 69 66 6e e3_value*);.#ifn
2f150 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 def SQLITE_UNTES
2f160 54 41 42 4c 45 0a 76 6f 69 64 20 73 71 6c 69 74 TABLE.void sqlit
2f170 65 33 52 65 73 75 6c 74 49 6e 74 52 65 61 6c 28 e3ResultIntReal(
2f180 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
2f190 29 3b 0a 23 65 6e 64 69 66 0a 73 71 6c 69 74 65 );.#endif.sqlite
2f1a0 33 5f 76 61 6c 75 65 20 2a 73 71 6c 69 74 65 33 3_value *sqlite3
2f1b0 56 61 6c 75 65 4e 65 77 28 73 71 6c 69 74 65 33 ValueNew(sqlite3
2f1c0 20 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c *);.#ifndef SQL
2f1d0 49 54 45 5f 4f 4d 49 54 5f 55 54 46 31 36 0a 63 ITE_OMIT_UTF16.c
2f1e0 68 61 72 20 2a 73 71 6c 69 74 65 33 55 74 66 31 har *sqlite3Utf1
2f1f0 36 74 6f 38 28 73 71 6c 69 74 65 33 20 2a 2c 20 6to8(sqlite3 *,
2f200 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 const void*, int
2f210 2c 20 75 38 29 3b 0a 23 65 6e 64 69 66 0a 69 6e , u8);.#endif.in
2f220 74 20 73 71 6c 69 74 65 33 56 61 6c 75 65 46 72 t sqlite3ValueFr
2f230 6f 6d 45 78 70 72 28 73 71 6c 69 74 65 33 20 2a omExpr(sqlite3 *
2f240 2c 20 45 78 70 72 20 2a 2c 20 75 38 2c 20 75 38 , Expr *, u8, u8
2f250 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 , sqlite3_value
2f260 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 **);.void sqlite
2f270 33 56 61 6c 75 65 41 70 70 6c 79 41 66 66 69 6e 3ValueApplyAffin
2f280 69 74 79 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ity(sqlite3_valu
2f290 65 20 2a 2c 20 75 38 2c 20 75 38 29 3b 0a 23 69 e *, u8, u8);.#i
2f2a0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 fndef SQLITE_AMA
2f2b0 4c 47 41 4d 41 54 49 4f 4e 0a 65 78 74 65 72 6e LGAMATION.extern
2f2c0 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 const unsigned
2f2d0 63 68 61 72 20 73 71 6c 69 74 65 33 4f 70 63 6f char sqlite3Opco
2f2e0 64 65 50 72 6f 70 65 72 74 79 5b 5d 3b 0a 65 78 deProperty[];.ex
2f2f0 74 65 72 6e 20 63 6f 6e 73 74 20 63 68 61 72 20 tern const char
2f300 73 71 6c 69 74 65 33 53 74 72 42 49 4e 41 52 59 sqlite3StrBINARY
2f310 5b 5d 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 [];.extern const
2f320 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 unsigned char s
2f330 71 6c 69 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 qlite3UpperToLow
2f340 65 72 5b 5d 3b 0a 65 78 74 65 72 6e 20 63 6f 6e er[];.extern con
2f350 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 st unsigned char
2f360 20 73 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 sqlite3CtypeMap
2f370 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 51 4c 49 54 [];.extern SQLIT
2f380 45 5f 57 53 44 20 73 74 72 75 63 74 20 53 71 6c E_WSD struct Sql
2f390 69 74 65 33 43 6f 6e 66 69 67 20 73 71 6c 69 74 ite3Config sqlit
2f3a0 65 33 43 6f 6e 66 69 67 3b 0a 65 78 74 65 72 6e e3Config;.extern
2f3b0 20 46 75 6e 63 44 65 66 48 61 73 68 20 73 71 6c FuncDefHash sql
2f3c0 69 74 65 33 42 75 69 6c 74 69 6e 46 75 6e 63 74 ite3BuiltinFunct
2f3d0 69 6f 6e 73 3b 0a 23 69 66 6e 64 65 66 20 53 51 ions;.#ifndef SQ
2f3e0 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 65 78 LITE_OMIT_WSD.ex
2f3f0 74 65 72 6e 20 69 6e 74 20 73 71 6c 69 74 65 33 tern int sqlite3
2f400 50 65 6e 64 69 6e 67 42 79 74 65 3b 0a 23 65 6e PendingByte;.#en
2f410 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 dif.#endif.#ifde
2f420 66 20 56 44 42 45 5f 50 52 4f 46 49 4c 45 0a 65 f VDBE_PROFILE.e
2f430 78 74 65 72 6e 20 73 71 6c 69 74 65 33 5f 75 69 xtern sqlite3_ui
2f440 6e 74 36 34 20 73 71 6c 69 74 65 33 4e 50 72 6f nt64 sqlite3NPro
2f450 66 69 6c 65 43 6e 74 3b 0a 23 65 6e 64 69 66 0a fileCnt;.#endif.
2f460 76 6f 69 64 20 73 71 6c 69 74 65 33 52 6f 6f 74 void sqlite3Root
2f470 50 61 67 65 4d 6f 76 65 64 28 73 71 6c 69 74 65 PageMoved(sqlite
2f480 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 3*, int, int, in
2f490 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
2f4a0 52 65 69 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 Reindex(Parse*,
2f4b0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b Token*, Token*);
2f4c0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 .void sqlite3Alt
2f4d0 65 72 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 erFunctions(void
2f4e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
2f4f0 6c 74 65 72 52 65 6e 61 6d 65 54 61 62 6c 65 28 lterRenameTable(
2f500 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a Parse*, SrcList*
2f510 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
2f520 73 71 6c 69 74 65 33 41 6c 74 65 72 52 65 6e 61 sqlite3AlterRena
2f530 6d 65 43 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c meColumn(Parse*,
2f540 20 53 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e SrcList*, Token
2f550 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 *, Token*);.int
2f560 73 71 6c 69 74 65 33 47 65 74 54 6f 6b 65 6e 28 sqlite3GetToken(
2f570 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 const unsigned c
2f580 68 61 72 20 2a 2c 20 69 6e 74 20 2a 29 3b 0a 76 har *, int *);.v
2f590 6f 69 64 20 73 71 6c 69 74 65 33 4e 65 73 74 65 oid sqlite3Neste
2f5a0 64 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 63 dParse(Parse*, c
2f5b0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 onst char*, ...)
2f5c0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
2f5d0 70 69 72 65 50 72 65 70 61 72 65 64 53 74 61 74 pirePreparedStat
2f5e0 65 6d 65 6e 74 73 28 73 71 6c 69 74 65 33 2a 2c ements(sqlite3*,
2f5f0 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
2f600 74 65 33 43 6f 64 65 52 68 73 4f 66 49 4e 28 50 te3CodeRhsOfIN(P
2f610 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
2f620 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 t);.int sqlite3C
2f630 6f 64 65 53 75 62 73 65 6c 65 63 74 28 50 61 72 odeSubselect(Par
2f640 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 se*, Expr*);.voi
2f650 64 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 50 d sqlite3SelectP
2f660 72 65 70 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 rep(Parse*, Sele
2f670 63 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 ct*, NameContext
2f680 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2f690 53 65 6c 65 63 74 57 72 6f 6e 67 4e 75 6d 54 65 SelectWrongNumTe
2f6a0 72 6d 73 45 72 72 6f 72 28 50 61 72 73 65 20 2a rmsError(Parse *
2f6b0 70 50 61 72 73 65 2c 20 53 65 6c 65 63 74 20 2a pParse, Select *
2f6c0 70 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d p);.int sqlite3M
2f6d0 61 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e atchSpanName(con
2f6e0 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
2f6f0 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
2f700 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
2f710 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 ;.int sqlite3Res
2f720 6f 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 olveExprNames(Na
2f730 6d 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 meContext*, Expr
2f740 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 *);.int sqlite3R
2f750 65 73 6f 6c 76 65 45 78 70 72 4c 69 73 74 4e 61 esolveExprListNa
2f760 6d 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a mes(NameContext*
2f770 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 76 6f , ExprList*);.vo
2f780 69 64 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 id sqlite3Resolv
2f790 65 53 65 6c 65 63 74 4e 61 6d 65 73 28 50 61 72 eSelectNames(Par
2f7a0 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 4e 61 se*, Select*, Na
2f7b0 6d 65 43 6f 6e 74 65 78 74 2a 29 3b 0a 69 6e 74 meContext*);.int
2f7c0 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 53 sqlite3ResolveS
2f7d0 65 6c 66 52 65 66 65 72 65 6e 63 65 28 50 61 72 elfReference(Par
2f7e0 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 45 se*,Table*,int,E
2f7f0 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b xpr*,ExprList*);
2f800 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f .int sqlite3Reso
2f810 6c 76 65 4f 72 64 65 72 47 72 6f 75 70 42 79 28 lveOrderGroupBy(
2f820 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c Parse*, Select*,
2f830 20 45 78 70 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 ExprList*, cons
2f840 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 t char*);.void s
2f850 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 44 65 66 61 qlite3ColumnDefa
2f860 75 6c 74 28 56 64 62 65 20 2a 2c 20 54 61 62 6c ult(Vdbe *, Tabl
2f870 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a e *, int, int);.
2f880 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 65 void sqlite3Alte
2f890 72 46 69 6e 69 73 68 41 64 64 43 6f 6c 75 6d 6e rFinishAddColumn
2f8a0 28 50 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 (Parse *, Token
2f8b0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2f8c0 41 6c 74 65 72 42 65 67 69 6e 41 64 64 43 6f 6c AlterBeginAddCol
2f8d0 75 6d 6e 28 50 61 72 73 65 20 2a 2c 20 53 72 63 umn(Parse *, Src
2f8e0 4c 69 73 74 20 2a 29 3b 0a 76 6f 69 64 20 2a 73 List *);.void *s
2f8f0 71 6c 69 74 65 33 52 65 6e 61 6d 65 54 6f 6b 65 qlite3RenameToke
2f900 6e 4d 61 70 28 50 61 72 73 65 2a 2c 20 76 6f 69 nMap(Parse*, voi
2f910 64 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 d*, Token*);.voi
2f920 64 20 73 71 6c 69 74 65 33 52 65 6e 61 6d 65 54 d sqlite3RenameT
2f930 6f 6b 65 6e 52 65 6d 61 70 28 50 61 72 73 65 2a okenRemap(Parse*
2f940 2c 20 76 6f 69 64 20 2a 70 54 6f 2c 20 76 6f 69 , void *pTo, voi
2f950 64 20 2a 70 46 72 6f 6d 29 3b 0a 76 6f 69 64 20 d *pFrom);.void
2f960 73 71 6c 69 74 65 33 52 65 6e 61 6d 65 45 78 70 sqlite3RenameExp
2f970 72 55 6e 6d 61 70 28 50 61 72 73 65 2a 2c 20 45 rUnmap(Parse*, E
2f980 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
2f990 74 65 33 52 65 6e 61 6d 65 45 78 70 72 6c 69 73 te3RenameExprlis
2f9a0 74 55 6e 6d 61 70 28 50 61 72 73 65 2a 2c 20 45 tUnmap(Parse*, E
2f9b0 78 70 72 4c 69 73 74 2a 29 3b 0a 43 6f 6c 6c 53 xprList*);.CollS
2f9c0 65 71 20 2a 73 71 6c 69 74 65 33 47 65 74 43 6f eq *sqlite3GetCo
2f9d0 6c 6c 53 65 71 28 50 61 72 73 65 2a 2c 20 75 38 llSeq(Parse*, u8
2f9e0 2c 20 43 6f 6c 6c 53 65 71 20 2a 2c 20 63 6f 6e , CollSeq *, con
2f9f0 73 74 20 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 st char*);.char
2fa00 73 71 6c 69 74 65 33 41 66 66 69 6e 69 74 79 54 sqlite3AffinityT
2fa10 79 70 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c ype(const char*,
2fa20 20 43 6f 6c 75 6d 6e 2a 29 3b 0a 76 6f 69 64 20 Column*);.void
2fa30 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 28 50 sqlite3Analyze(P
2fa40 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
2fa50 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 oken*);.int sqli
2fa60 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 48 61 6e te3InvokeBusyHan
2fa70 64 6c 65 72 28 42 75 73 79 48 61 6e 64 6c 65 72 dler(BusyHandler
2fa80 2a 2c 20 73 71 6c 69 74 65 33 5f 66 69 6c 65 2a *, sqlite3_file*
2fa90 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 );.int sqlite3Fi
2faa0 6e 64 44 62 28 73 71 6c 69 74 65 33 2a 2c 20 54 ndDb(sqlite3*, T
2fab0 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 oken*);.int sqli
2fac0 74 65 33 46 69 6e 64 44 62 4e 61 6d 65 28 73 71 te3FindDbName(sq
2fad0 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 63 lite3 *, const c
2fae0 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 har *);.int sqli
2faf0 74 65 33 41 6e 61 6c 79 73 69 73 4c 6f 61 64 28 te3AnalysisLoad(
2fb00 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 69 44 42 sqlite3*,int iDB
2fb10 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
2fb20 65 6c 65 74 65 49 6e 64 65 78 53 61 6d 70 6c 65 eleteIndexSample
2fb30 73 28 73 71 6c 69 74 65 33 2a 2c 49 6e 64 65 78 s(sqlite3*,Index
2fb40 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2fb50 44 65 66 61 75 6c 74 52 6f 77 45 73 74 28 49 6e DefaultRowEst(In
2fb60 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 dex*);.void sqli
2fb70 74 65 33 52 65 67 69 73 74 65 72 4c 69 6b 65 46 te3RegisterLikeF
2fb80 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 65 33 unctions(sqlite3
2fb90 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c *, int);.int sql
2fba0 69 74 65 33 49 73 4c 69 6b 65 46 75 6e 63 74 69 ite3IsLikeFuncti
2fbb0 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 on(sqlite3*,Expr
2fbc0 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a 29 3b 0a 76 *,int*,char*);.v
2fbd0 6f 69 64 20 73 71 6c 69 74 65 33 53 63 68 65 6d oid sqlite3Schem
2fbe0 61 43 6c 65 61 72 28 76 6f 69 64 20 2a 29 3b 0a aClear(void *);.
2fbf0 53 63 68 65 6d 61 20 2a 73 71 6c 69 74 65 33 53 Schema *sqlite3S
2fc00 63 68 65 6d 61 47 65 74 28 73 71 6c 69 74 65 33 chemaGet(sqlite3
2fc10 20 2a 2c 20 42 74 72 65 65 20 2a 29 3b 0a 69 6e *, Btree *);.in
2fc20 74 20 73 71 6c 69 74 65 33 53 63 68 65 6d 61 54 t sqlite3SchemaT
2fc30 6f 49 6e 64 65 78 28 73 71 6c 69 74 65 33 20 2a oIndex(sqlite3 *
2fc40 64 62 2c 20 53 63 68 65 6d 61 20 2a 29 3b 0a 4b db, Schema *);.K
2fc50 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b eyInfo *sqlite3K
2fc60 65 79 49 6e 66 6f 41 6c 6c 6f 63 28 73 71 6c 69 eyInfoAlloc(sqli
2fc70 74 65 33 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 76 te3*,int,int);.v
2fc80 6f 69 64 20 73 71 6c 69 74 65 33 4b 65 79 49 6e oid sqlite3KeyIn
2fc90 66 6f 55 6e 72 65 66 28 4b 65 79 49 6e 66 6f 2a foUnref(KeyInfo*
2fca0 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 );.KeyInfo *sqli
2fcb0 74 65 33 4b 65 79 49 6e 66 6f 52 65 66 28 4b 65 te3KeyInfoRef(Ke
2fcc0 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f yInfo*);.KeyInfo
2fcd0 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f *sqlite3KeyInfo
2fce0 4f 66 49 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 OfIndex(Parse*,
2fcf0 49 6e 64 65 78 2a 29 3b 0a 4b 65 79 49 6e 66 6f Index*);.KeyInfo
2fd00 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f *sqlite3KeyInfo
2fd10 46 72 6f 6d 45 78 70 72 4c 69 73 74 28 50 61 72 FromExprList(Par
2fd20 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 se*, ExprList*,
2fd30 69 6e 74 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 int, int);.int s
2fd40 71 6c 69 74 65 33 48 61 73 45 78 70 6c 69 63 69 qlite3HasExplici
2fd50 74 4e 75 6c 6c 73 28 50 61 72 73 65 2a 2c 20 45 tNulls(Parse*, E
2fd60 78 70 72 4c 69 73 74 2a 29 3b 0a 0a 23 69 66 64 xprList*);..#ifd
2fd70 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a ef SQLITE_DEBUG.
2fd80 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 49 6e int sqlite3KeyIn
2fd90 66 6f 49 73 57 72 69 74 65 61 62 6c 65 28 4b 65 foIsWriteable(Ke
2fda0 79 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 66 0a yInfo*);.#endif.
2fdb0 69 6e 74 20 73 71 6c 69 74 65 33 43 72 65 61 74 int sqlite3Creat
2fdc0 65 46 75 6e 63 28 73 71 6c 69 74 65 33 20 2a 2c eFunc(sqlite3 *,
2fdd0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 const char *, i
2fde0 6e 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 2a 2c nt, int, void *,
2fdf0 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 71 6c 69 . void (*)(sqli
2fe00 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 te3_context*,int
2fe10 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a ,sqlite3_value *
2fe20 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 *),. void (*)(s
2fe30 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
2fe40 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
2fe50 65 20 2a 2a 29 2c 20 0a 20 20 76 6f 69 64 20 28 e **), . void (
2fe60 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 *)(sqlite3_conte
2fe70 78 74 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 xt*),. void (*)
2fe80 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
2fe90 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 *),. void (*)(s
2fea0 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
2feb0 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
2fec0 65 20 2a 2a 29 2c 20 0a 20 20 46 75 6e 63 44 65 e **), . FuncDe
2fed0 73 74 72 75 63 74 6f 72 20 2a 70 44 65 73 74 72 structor *pDestr
2fee0 75 63 74 6f 72 0a 29 3b 0a 76 6f 69 64 20 73 71 uctor.);.void sq
2fef0 6c 69 74 65 33 4e 6f 6f 70 44 65 73 74 72 75 63 lite3NoopDestruc
2ff00 74 6f 72 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 tor(void*);.void
2ff10 20 73 71 6c 69 74 65 33 4f 6f 6d 46 61 75 6c 74 sqlite3OomFault
2ff20 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
2ff30 20 73 71 6c 69 74 65 33 4f 6f 6d 43 6c 65 61 72 sqlite3OomClear
2ff40 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 (sqlite3*);.int
2ff50 73 71 6c 69 74 65 33 41 70 69 45 78 69 74 28 73 sqlite3ApiExit(s
2ff60 71 6c 69 74 65 33 20 2a 64 62 2c 20 69 6e 74 29 qlite3 *db, int)
2ff70 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 ;.int sqlite3Ope
2ff80 6e 54 65 6d 70 44 61 74 61 62 61 73 65 28 50 61 nTempDatabase(Pa
2ff90 72 73 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 rse *);..void sq
2ffa0 6c 69 74 65 33 53 74 72 41 63 63 75 6d 49 6e 69 lite3StrAccumIni
2ffb0 74 28 53 74 72 41 63 63 75 6d 2a 2c 20 73 71 6c t(StrAccum*, sql
2ffc0 69 74 65 33 2a 2c 20 63 68 61 72 2a 2c 20 69 6e ite3*, char*, in
2ffd0 74 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 2a 73 t, int);.char *s
2ffe0 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d 46 69 qlite3StrAccumFi
2fff0 6e 69 73 68 28 53 74 72 41 63 63 75 6d 2a 29 3b nish(StrAccum*);
30000 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c .void sqlite3Sel
30010 65 63 74 44 65 73 74 49 6e 69 74 28 53 65 6c 65 ectDestInit(Sele
30020 63 74 44 65 73 74 2a 2c 69 6e 74 2c 69 6e 74 29 ctDest*,int,int)
30030 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 43 ;.Expr *sqlite3C
30040 72 65 61 74 65 43 6f 6c 75 6d 6e 45 78 70 72 28 reateColumnExpr(
30050 73 71 6c 69 74 65 33 20 2a 2c 20 53 72 63 4c 69 sqlite3 *, SrcLi
30060 73 74 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b st *, int, int);
30070 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 61 ..void sqlite3Ba
30080 63 6b 75 70 52 65 73 74 61 72 74 28 73 71 6c 69 ckupRestart(sqli
30090 74 65 33 5f 62 61 63 6b 75 70 20 2a 29 3b 0a 76 te3_backup *);.v
300a0 6f 69 64 20 73 71 6c 69 74 65 33 42 61 63 6b 75 oid sqlite3Backu
300b0 70 55 70 64 61 74 65 28 73 71 6c 69 74 65 33 5f pUpdate(sqlite3_
300c0 62 61 63 6b 75 70 20 2a 2c 20 50 67 6e 6f 2c 20 backup *, Pgno,
300d0 63 6f 6e 73 74 20 75 38 20 2a 29 3b 0a 0a 23 69 const u8 *);..#i
300e0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
300f0 54 5f 53 55 42 51 55 45 52 59 0a 69 6e 74 20 73 T_SUBQUERY.int s
30100 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 49 qlite3ExprCheckI
30110 4e 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 N(Parse*, Expr*)
30120 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
30130 20 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 sqlite3ExprChec
30140 6b 49 4e 28 78 2c 79 29 20 53 51 4c 49 54 45 5f kIN(x,y) SQLITE_
30150 4f 4b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 OK.#endif..#ifde
30160 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
30170 53 54 41 54 34 0a 69 6e 74 20 73 71 6c 69 74 65 STAT4.int sqlite
30180 33 53 74 61 74 34 50 72 6f 62 65 53 65 74 56 61 3Stat4ProbeSetVa
30190 6c 75 65 28 0a 20 20 20 20 50 61 72 73 65 2a 2c lue(. Parse*,
301a0 49 6e 64 65 78 2a 2c 55 6e 70 61 63 6b 65 64 52 Index*,UnpackedR
301b0 65 63 6f 72 64 2a 2a 2c 45 78 70 72 2a 2c 69 6e ecord**,Expr*,in
301c0 74 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a 69 6e 74 t,int,int*);.int
301d0 20 73 71 6c 69 74 65 33 53 74 61 74 34 56 61 6c sqlite3Stat4Val
301e0 75 65 46 72 6f 6d 45 78 70 72 28 50 61 72 73 65 ueFromExpr(Parse
301f0 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c 20 73 71 *, Expr*, u8, sq
30200 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a lite3_value**);.
30210 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 void sqlite3Stat
30220 34 50 72 6f 62 65 46 72 65 65 28 55 6e 70 61 63 4ProbeFree(Unpac
30230 6b 65 64 52 65 63 6f 72 64 2a 29 3b 0a 69 6e 74 kedRecord*);.int
30240 20 73 71 6c 69 74 65 33 53 74 61 74 34 43 6f 6c sqlite3Stat4Col
30250 75 6d 6e 28 73 71 6c 69 74 65 33 2a 2c 20 63 6f umn(sqlite3*, co
30260 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 nst void*, int,
30270 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c int, sqlite3_val
30280 75 65 2a 2a 29 3b 0a 63 68 61 72 20 73 71 6c 69 ue**);.char sqli
30290 74 65 33 49 6e 64 65 78 43 6f 6c 75 6d 6e 41 66 te3IndexColumnAf
302a0 66 69 6e 69 74 79 28 73 71 6c 69 74 65 33 2a 2c finity(sqlite3*,
302b0 20 49 6e 64 65 78 2a 2c 20 69 6e 74 29 3b 0a 23 Index*, int);.#
302c0 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
302d0 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 74 68 interface to th
302e0 65 20 4c 45 4d 4f 4e 2d 67 65 6e 65 72 61 74 65 e LEMON-generate
302f0 64 20 70 61 72 73 65 72 0a 2a 2f 0a 23 69 66 6e d parser.*/.#ifn
30300 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c 47 def SQLITE_AMALG
30310 41 4d 41 54 49 4f 4e 0a 20 20 76 6f 69 64 20 2a AMATION. void *
30320 73 71 6c 69 74 65 33 50 61 72 73 65 72 41 6c 6c sqlite3ParserAll
30330 6f 63 28 76 6f 69 64 2a 28 2a 29 28 75 36 34 29 oc(void*(*)(u64)
30340 2c 20 50 61 72 73 65 2a 29 3b 0a 20 20 76 6f 69 , Parse*);. voi
30350 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 46 d sqlite3ParserF
30360 72 65 65 28 76 6f 69 64 2a 2c 20 76 6f 69 64 28 ree(void*, void(
30370 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 23 65 6e 64 *)(void*));.#end
30380 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 if.void sqlite3P
30390 61 72 73 65 72 28 76 6f 69 64 2a 2c 20 69 6e 74 arser(void*, int
303a0 2c 20 54 6f 6b 65 6e 29 3b 0a 69 6e 74 20 73 71 , Token);.int sq
303b0 6c 69 74 65 33 50 61 72 73 65 72 46 61 6c 6c 62 lite3ParserFallb
303c0 61 63 6b 28 69 6e 74 29 3b 0a 23 69 66 64 65 66 ack(int);.#ifdef
303d0 20 59 59 54 52 41 43 4b 4d 41 58 53 54 41 43 4b YYTRACKMAXSTACK
303e0 44 45 50 54 48 0a 20 20 69 6e 74 20 73 71 6c 69 DEPTH. int sqli
303f0 74 65 33 50 61 72 73 65 72 53 74 61 63 6b 50 65 te3ParserStackPe
30400 61 6b 28 76 6f 69 64 2a 29 3b 0a 23 65 6e 64 69 ak(void*);.#endi
30410 66 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 f..void sqlite3A
30420 75 74 6f 4c 6f 61 64 45 78 74 65 6e 73 69 6f 6e utoLoadExtension
30430 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 69 66 s(sqlite3*);.#if
30440 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
30450 5f 4c 4f 41 44 5f 45 58 54 45 4e 53 49 4f 4e 0a _LOAD_EXTENSION.
30460 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c void sqlite3Cl
30470 6f 73 65 45 78 74 65 6e 73 69 6f 6e 73 28 73 71 oseExtensions(sq
30480 6c 69 74 65 33 2a 29 3b 0a 23 65 6c 73 65 0a 23 lite3*);.#else.#
30490 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 define sqlite3C
304a0 6c 6f 73 65 45 78 74 65 6e 73 69 6f 6e 73 28 58 loseExtensions(X
304b0 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 6e 64 65 ).#endif..#ifnde
304c0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 48 f SQLITE_OMIT_SH
304d0 41 52 45 44 5f 43 41 43 48 45 0a 20 20 76 6f 69 ARED_CACHE. voi
304e0 64 20 73 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f d sqlite3TableLo
304f0 63 6b 28 50 61 72 73 65 20 2a 2c 20 69 6e 74 2c ck(Parse *, int,
30500 20 69 6e 74 2c 20 75 38 2c 20 63 6f 6e 73 74 20 int, u8, const
30510 63 68 61 72 20 2a 29 3b 0a 23 65 6c 73 65 0a 20 char *);.#else.
30520 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
30530 54 61 62 6c 65 4c 6f 63 6b 28 76 2c 77 2c 78 2c TableLock(v,w,x,
30540 79 2c 7a 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 y,z).#endif..#if
30550 64 65 66 20 53 51 4c 49 54 45 5f 54 45 53 54 0a def SQLITE_TEST.
30560 20 20 69 6e 74 20 73 71 6c 69 74 65 33 55 74 66 int sqlite3Utf
30570 38 54 6f 38 28 75 6e 73 69 67 6e 65 64 20 63 68 8To8(unsigned ch
30580 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 ar*);.#endif..#i
30590 66 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fdef SQLITE_OMIT
305a0 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 23 20 _VIRTUALTABLE.#
305b0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
305c0 74 61 62 43 6c 65 61 72 28 59 29 0a 23 20 20 64 tabClear(Y).# d
305d0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
305e0 62 53 79 6e 63 28 58 2c 59 29 20 53 51 4c 49 54 bSync(X,Y) SQLIT
305f0 45 5f 4f 4b 0a 23 20 20 64 65 66 69 6e 65 20 73 E_OK.# define s
30600 71 6c 69 74 65 33 56 74 61 62 52 6f 6c 6c 62 61 qlite3VtabRollba
30610 63 6b 28 58 29 0a 23 20 20 64 65 66 69 6e 65 20 ck(X).# define
30620 73 71 6c 69 74 65 33 56 74 61 62 43 6f 6d 6d 69 sqlite3VtabCommi
30630 74 28 58 29 0a 23 20 20 64 65 66 69 6e 65 20 73 t(X).# define s
30640 71 6c 69 74 65 33 56 74 61 62 49 6e 53 79 6e 63 qlite3VtabInSync
30650 28 64 62 29 20 30 0a 23 20 20 64 65 66 69 6e 65 (db) 0.# define
30660 20 73 71 6c 69 74 65 33 56 74 61 62 4c 6f 63 6b sqlite3VtabLock
30670 28 58 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 (X).# define sq
30680 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 28 lite3VtabUnlock(
30690 58 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c X).# define sql
306a0 69 74 65 33 56 74 61 62 4d 6f 64 75 6c 65 55 6e ite3VtabModuleUn
306b0 72 65 66 28 44 2c 58 29 0a 23 20 20 64 65 66 69 ref(D,X).# defi
306c0 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e ne sqlite3VtabUn
306d0 6c 6f 63 6b 4c 69 73 74 28 58 29 0a 23 20 20 64 lockList(X).# d
306e0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
306f0 62 53 61 76 65 70 6f 69 6e 74 28 58 2c 20 59 2c bSavepoint(X, Y,
30700 20 5a 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 Z) SQLITE_OK.#
30710 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 define sqlite3G
30720 65 74 56 54 61 62 6c 65 28 58 2c 59 29 20 20 28 etVTable(X,Y) (
30730 28 56 54 61 62 6c 65 2a 29 30 29 0a 23 65 6c 73 (VTable*)0).#els
30740 65 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 e. void sqlite
30750 33 56 74 61 62 43 6c 65 61 72 28 73 71 6c 69 74 3VtabClear(sqlit
30760 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 2a 29 3b e3 *db, Table*);
30770 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
30780 56 74 61 62 44 69 73 63 6f 6e 6e 65 63 74 28 73 VtabDisconnect(s
30790 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c qlite3 *db, Tabl
307a0 65 20 2a 70 29 3b 0a 20 20 20 69 6e 74 20 73 71 e *p);. int sq
307b0 6c 69 74 65 33 56 74 61 62 53 79 6e 63 28 73 71 lite3VtabSync(sq
307c0 6c 69 74 65 33 20 2a 64 62 2c 20 56 64 62 65 2a lite3 *db, Vdbe*
307d0 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 );. int sqlite
307e0 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 73 71 3VtabRollback(sq
307f0 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 20 69 lite3 *db);. i
30800 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f nt sqlite3VtabCo
30810 6d 6d 69 74 28 73 71 6c 69 74 65 33 20 2a 64 62 mmit(sqlite3 *db
30820 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 );. void sqlit
30830 65 33 56 74 61 62 4c 6f 63 6b 28 56 54 61 62 6c e3VtabLock(VTabl
30840 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 e *);. void sq
30850 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 28 lite3VtabUnlock(
30860 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f VTable *);. vo
30870 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 4d 6f id sqlite3VtabMo
30880 64 75 6c 65 55 6e 72 65 66 28 73 71 6c 69 74 65 duleUnref(sqlite
30890 33 2a 2c 4d 6f 64 75 6c 65 2a 29 3b 0a 20 20 20 3*,Module*);.
308a0 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 void sqlite3Vtab
308b0 55 6e 6c 6f 63 6b 4c 69 73 74 28 73 71 6c 69 74 UnlockList(sqlit
308c0 65 33 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c e3*);. int sql
308d0 69 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 6e ite3VtabSavepoin
308e0 74 28 73 71 6c 69 74 65 33 20 2a 2c 20 69 6e 74 t(sqlite3 *, int
308f0 2c 20 69 6e 74 29 3b 0a 20 20 20 76 6f 69 64 20 , int);. void
30900 73 71 6c 69 74 65 33 56 74 61 62 49 6d 70 6f 72 sqlite3VtabImpor
30910 74 45 72 72 6d 73 67 28 56 64 62 65 2a 2c 20 73 tErrmsg(Vdbe*, s
30920 71 6c 69 74 65 33 5f 76 74 61 62 2a 29 3b 0a 20 qlite3_vtab*);.
30930 20 20 56 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 VTable *sqlite
30940 33 47 65 74 56 54 61 62 6c 65 28 73 71 6c 69 74 3GetVTable(sqlit
30950 65 33 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 e3*, Table*);.
30960 20 4d 6f 64 75 6c 65 20 2a 73 71 6c 69 74 65 33 Module *sqlite3
30970 56 74 61 62 43 72 65 61 74 65 4d 6f 64 75 6c 65 VtabCreateModule
30980 28 0a 20 20 20 20 20 73 71 6c 69 74 65 33 2a 2c (. sqlite3*,
30990 0a 20 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 . const char
309a0 2a 2c 0a 20 20 20 20 20 63 6f 6e 73 74 20 73 71 *,. const sq
309b0 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 2a 2c 0a 20 lite3_module*,.
309c0 20 20 20 20 76 6f 69 64 2a 2c 0a 20 20 20 20 20 void*,.
309d0 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 0a 20 void(*)(void*).
309e0 20 20 29 3b 0a 23 20 20 64 65 66 69 6e 65 20 73 );.# define s
309f0 71 6c 69 74 65 33 56 74 61 62 49 6e 53 79 6e 63 qlite3VtabInSync
30a00 28 64 62 29 20 28 28 64 62 29 2d 3e 6e 56 54 72 (db) ((db)->nVTr
30a10 61 6e 73 3e 30 20 26 26 20 28 64 62 29 2d 3e 61 ans>0 && (db)->a
30a20 56 54 72 61 6e 73 3d 3d 30 29 0a 23 65 6e 64 69 VTrans==0).#endi
30a30 66 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 f.int sqlite3Vta
30a40 62 45 70 6f 6e 79 6d 6f 75 73 54 61 62 6c 65 49 bEponymousTableI
30a50 6e 69 74 28 50 61 72 73 65 2a 2c 4d 6f 64 75 6c nit(Parse*,Modul
30a60 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
30a70 33 56 74 61 62 45 70 6f 6e 79 6d 6f 75 73 54 61 3VtabEponymousTa
30a80 62 6c 65 43 6c 65 61 72 28 73 71 6c 69 74 65 33 bleClear(sqlite3
30a90 2a 2c 4d 6f 64 75 6c 65 2a 29 3b 0a 76 6f 69 64 *,Module*);.void
30aa0 20 73 71 6c 69 74 65 33 56 74 61 62 4d 61 6b 65 sqlite3VtabMake
30ab0 57 72 69 74 61 62 6c 65 28 50 61 72 73 65 2a 2c Writable(Parse*,
30ac0 54 61 62 6c 65 2a 29 3b 0a 76 6f 69 64 20 73 71 Table*);.void sq
30ad0 6c 69 74 65 33 56 74 61 62 42 65 67 69 6e 50 61 lite3VtabBeginPa
30ae0 72 73 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 rse(Parse*, Toke
30af0 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 n*, Token*, Toke
30b00 6e 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 n*, int);.void s
30b10 71 6c 69 74 65 33 56 74 61 62 46 69 6e 69 73 68 qlite3VtabFinish
30b20 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 54 6f Parse(Parse*, To
30b30 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
30b40 74 65 33 56 74 61 62 41 72 67 49 6e 69 74 28 50 te3VtabArgInit(P
30b50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c arse*);.void sql
30b60 69 74 65 33 56 74 61 62 41 72 67 45 78 74 65 6e ite3VtabArgExten
30b70 64 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a d(Parse*, Token*
30b80 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 );.int sqlite3Vt
30b90 61 62 43 61 6c 6c 43 72 65 61 74 65 28 73 71 6c abCallCreate(sql
30ba0 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 ite3*, int, cons
30bb0 74 20 63 68 61 72 20 2a 2c 20 63 68 61 72 20 2a t char *, char *
30bc0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 *);.int sqlite3V
30bd0 74 61 62 43 61 6c 6c 43 6f 6e 6e 65 63 74 28 50 tabCallConnect(P
30be0 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a arse*, Table*);.
30bf0 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 int sqlite3VtabC
30c00 61 6c 6c 44 65 73 74 72 6f 79 28 73 71 6c 69 74 allDestroy(sqlit
30c10 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 e3*, int, const
30c20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c char *);.int sql
30c30 69 74 65 33 56 74 61 62 42 65 67 69 6e 28 73 71 ite3VtabBegin(sq
30c40 6c 69 74 65 33 20 2a 2c 20 56 54 61 62 6c 65 20 lite3 *, VTable
30c50 2a 29 3b 0a 46 75 6e 63 44 65 66 20 2a 73 71 6c *);.FuncDef *sql
30c60 69 74 65 33 56 74 61 62 4f 76 65 72 6c 6f 61 64 ite3VtabOverload
30c70 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 Function(sqlite3
30c80 20 2a 2c 46 75 6e 63 44 65 66 2a 2c 20 69 6e 74 *,FuncDef*, int
30c90 20 6e 41 72 67 2c 20 45 78 70 72 2a 29 3b 0a 73 nArg, Expr*);.s
30ca0 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 73 71 6c qlite3_int64 sql
30cb0 69 74 65 33 53 74 6d 74 43 75 72 72 65 6e 74 54 ite3StmtCurrentT
30cc0 69 6d 65 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 ime(sqlite3_cont
30cd0 65 78 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ext*);.int sqlit
30ce0 65 33 56 64 62 65 50 61 72 61 6d 65 74 65 72 49 e3VdbeParameterI
30cf0 6e 64 65 78 28 56 64 62 65 2a 2c 20 63 6f 6e 73 ndex(Vdbe*, cons
30d00 74 20 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a 69 t char*, int);.i
30d10 6e 74 20 73 71 6c 69 74 65 33 54 72 61 6e 73 66 nt sqlite3Transf
30d20 65 72 42 69 6e 64 69 6e 67 73 28 73 71 6c 69 74 erBindings(sqlit
30d30 65 33 5f 73 74 6d 74 20 2a 2c 20 73 71 6c 69 74 e3_stmt *, sqlit
30d40 65 33 5f 73 74 6d 74 20 2a 29 3b 0a 76 6f 69 64 e3_stmt *);.void
30d50 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 52 65 sqlite3ParserRe
30d60 73 65 74 28 50 61 72 73 65 2a 29 3b 0a 23 69 66 set(Parse*);.#if
30d70 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c def SQLITE_ENABL
30d80 45 5f 4e 4f 52 4d 41 4c 49 5a 45 0a 63 68 61 72 E_NORMALIZE.char
30d90 20 2a 73 71 6c 69 74 65 33 4e 6f 72 6d 61 6c 69 *sqlite3Normali
30da0 7a 65 28 56 64 62 65 2a 2c 20 63 6f 6e 73 74 20 ze(Vdbe*, const
30db0 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 69 char*);.#endif.i
30dc0 6e 74 20 73 71 6c 69 74 65 33 52 65 70 72 65 70 nt sqlite3Reprep
30dd0 61 72 65 28 56 64 62 65 2a 29 3b 0a 76 6f 69 64 are(Vdbe*);.void
30de0 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 sqlite3ExprList
30df0 43 68 65 63 6b 4c 65 6e 67 74 68 28 50 61 72 73 CheckLength(Pars
30e00 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 63 e*, ExprList*, c
30e10 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 43 6f 6c onst char*);.Col
30e20 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 42 69 6e lSeq *sqlite3Bin
30e30 61 72 79 43 6f 6d 70 61 72 65 43 6f 6c 6c 53 65 aryCompareCollSe
30e40 71 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 q(Parse *, Expr
30e50 2a 2c 20 45 78 70 72 20 2a 29 3b 0a 69 6e 74 20 *, Expr *);.int
30e60 73 71 6c 69 74 65 33 54 65 6d 70 49 6e 4d 65 6d sqlite3TempInMem
30e70 6f 72 79 28 63 6f 6e 73 74 20 73 71 6c 69 74 65 ory(const sqlite
30e80 33 2a 29 3b 0a 63 6f 6e 73 74 20 63 68 61 72 20 3*);.const char
30e90 2a 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 4d *sqlite3JournalM
30ea0 6f 64 65 6e 61 6d 65 28 69 6e 74 29 3b 0a 23 69 odename(int);.#i
30eb0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
30ec0 54 5f 57 41 4c 0a 20 20 69 6e 74 20 73 71 6c 69 T_WAL. int sqli
30ed0 74 65 33 43 68 65 63 6b 70 6f 69 6e 74 28 73 71 te3Checkpoint(sq
30ee0 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 lite3*, int, int
30ef0 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 3b 0a 20 , int*, int*);.
30f00 20 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 44 int sqlite3WalD
30f10 65 66 61 75 6c 74 48 6f 6f 6b 28 76 6f 69 64 2a efaultHook(void*
30f20 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 ,sqlite3*,const
30f30 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 23 65 6e 64 char*,int);.#end
30f40 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
30f50 45 5f 4f 4d 49 54 5f 43 54 45 0a 20 20 57 69 74 E_OMIT_CTE. Wit
30f60 68 20 2a 73 71 6c 69 74 65 33 57 69 74 68 41 64 h *sqlite3WithAd
30f70 64 28 50 61 72 73 65 2a 2c 57 69 74 68 2a 2c 54 d(Parse*,With*,T
30f80 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
30f90 53 65 6c 65 63 74 2a 29 3b 0a 20 20 76 6f 69 64 Select*);. void
30fa0 20 73 71 6c 69 74 65 33 57 69 74 68 44 65 6c 65 sqlite3WithDele
30fb0 74 65 28 73 71 6c 69 74 65 33 2a 2c 57 69 74 68 te(sqlite3*,With
30fc0 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
30fd0 65 33 57 69 74 68 50 75 73 68 28 50 61 72 73 65 e3WithPush(Parse
30fe0 2a 2c 20 57 69 74 68 2a 2c 20 75 38 29 3b 0a 23 *, With*, u8);.#
30ff0 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 73 71 6c else.#define sql
31000 69 74 65 33 57 69 74 68 50 75 73 68 28 78 2c 79 ite3WithPush(x,y
31010 2c 7a 29 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 ,z).#define sqli
31020 74 65 33 57 69 74 68 44 65 6c 65 74 65 28 78 2c te3WithDelete(x,
31030 79 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 y).#endif.#ifnde
31040 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 55 50 f SQLITE_OMIT_UP
31050 53 45 52 54 0a 20 20 55 70 73 65 72 74 20 2a 73 SERT. Upsert *s
31060 71 6c 69 74 65 33 55 70 73 65 72 74 4e 65 77 28 qlite3UpsertNew(
31070 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 4c 69 73 sqlite3*,ExprLis
31080 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 t*,Expr*,ExprLis
31090 74 2a 2c 45 78 70 72 2a 29 3b 0a 20 20 76 6f 69 t*,Expr*);. voi
310a0 64 20 73 71 6c 69 74 65 33 55 70 73 65 72 74 44 d sqlite3UpsertD
310b0 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 55 elete(sqlite3*,U
310c0 70 73 65 72 74 2a 29 3b 0a 20 20 55 70 73 65 72 psert*);. Upser
310d0 74 20 2a 73 71 6c 69 74 65 33 55 70 73 65 72 74 t *sqlite3Upsert
310e0 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 55 70 73 Dup(sqlite3*,Ups
310f0 65 72 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c ert*);. int sql
31100 69 74 65 33 55 70 73 65 72 74 41 6e 61 6c 79 7a ite3UpsertAnalyz
31110 65 54 61 72 67 65 74 28 50 61 72 73 65 2a 2c 53 eTarget(Parse*,S
31120 72 63 4c 69 73 74 2a 2c 55 70 73 65 72 74 2a 29 rcList*,Upsert*)
31130 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
31140 55 70 73 65 72 74 44 6f 55 70 64 61 74 65 28 50 UpsertDoUpdate(P
31150 61 72 73 65 2a 2c 55 70 73 65 72 74 2a 2c 54 61 arse*,Upsert*,Ta
31160 62 6c 65 2a 2c 49 6e 64 65 78 2a 2c 69 6e 74 29 ble*,Index*,int)
31170 3b 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 ;.#else.#define
31180 73 71 6c 69 74 65 33 55 70 73 65 72 74 4e 65 77 sqlite3UpsertNew
31190 28 76 2c 77 2c 78 2c 79 2c 7a 29 20 28 28 55 70 (v,w,x,y,z) ((Up
311a0 73 65 72 74 2a 29 30 29 0a 23 64 65 66 69 6e 65 sert*)0).#define
311b0 20 73 71 6c 69 74 65 33 55 70 73 65 72 74 44 65 sqlite3UpsertDe
311c0 6c 65 74 65 28 78 2c 79 29 0a 23 64 65 66 69 6e lete(x,y).#defin
311d0 65 20 73 71 6c 69 74 65 33 55 70 73 65 72 74 44 e sqlite3UpsertD
311e0 75 70 28 78 2c 79 29 20 20 20 20 20 20 20 28 28 up(x,y) ((
311f0 55 70 73 65 72 74 2a 29 30 29 0a 23 65 6e 64 69 Upsert*)0).#endi
31200 66 0a 0a 0a 2f 2a 20 44 65 63 6c 61 72 61 74 69 f.../* Declarati
31210 6f 6e 73 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e ons for function
31220 73 20 69 6e 20 66 6b 65 79 2e 63 2e 20 41 6c 6c s in fkey.c. All
31230 20 6f 66 20 74 68 65 73 65 20 61 72 65 20 72 65 of these are re
31240 70 6c 61 63 65 64 20 62 79 0a 2a 2a 20 6e 6f 2d placed by.** no-
31250 6f 70 20 6d 61 63 72 6f 73 20 69 66 20 4f 4d 49 op macros if OMI
31260 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 20 69 73 T_FOREIGN_KEY is
31270 20 64 65 66 69 6e 65 64 2e 20 49 6e 20 74 68 69 defined. In thi
31280 73 20 63 61 73 65 20 6e 6f 20 66 6f 72 65 69 67 s case no foreig
31290 6e 0a 2a 2a 20 6b 65 79 20 66 75 6e 63 74 69 6f n.** key functio
312a0 6e 61 6c 69 74 79 20 69 73 20 61 76 61 69 6c 61 nality is availa
312b0 62 6c 65 2e 20 49 66 20 4f 4d 49 54 5f 54 52 49 ble. If OMIT_TRI
312c0 47 47 45 52 20 69 73 20 64 65 66 69 6e 65 64 20 GGER is defined
312d0 62 75 74 0a 2a 2a 20 4f 4d 49 54 5f 46 4f 52 45 but.** OMIT_FORE
312e0 49 47 4e 5f 4b 45 59 20 69 73 20 6e 6f 74 2c 20 IGN_KEY is not,
312f0 6f 6e 6c 79 20 73 6f 6d 65 20 6f 66 20 74 68 65 only some of the
31300 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e functions are n
31310 6f 2d 6f 70 65 64 2e 20 49 6e 0a 2a 2a 20 74 68 o-oped. In.** th
31320 69 73 20 63 61 73 65 20 66 6f 72 65 69 67 6e 20 is case foreign
31330 6b 65 79 73 20 61 72 65 20 70 61 72 73 65 64 2c keys are parsed,
31340 20 62 75 74 20 6e 6f 20 6f 74 68 65 72 20 66 75 but no other fu
31350 6e 63 74 69 6f 6e 61 6c 69 74 79 20 69 73 0a 2a nctionality is.*
31360 2a 20 70 72 6f 76 69 64 65 64 20 28 65 6e 66 6f * provided (enfo
31370 72 63 65 6d 65 6e 74 20 6f 66 20 46 4b 20 63 6f rcement of FK co
31380 6e 73 74 72 61 69 6e 74 73 20 72 65 71 75 69 72 nstraints requir
31390 65 73 20 74 68 65 20 74 72 69 67 67 65 72 73 20 es the triggers
313a0 73 75 62 2d 73 79 73 74 65 6d 29 2e 0a 2a 2f 0a sub-system)..*/.
313b0 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
313c0 49 54 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 4e ITE_OMIT_FOREIGN
313d0 5f 4b 45 59 29 20 26 26 20 21 64 65 66 69 6e 65 _KEY) && !define
313e0 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 d(SQLITE_OMIT_TR
313f0 49 47 47 45 52 29 0a 20 20 76 6f 69 64 20 73 71 IGGER). void sq
31400 6c 69 74 65 33 46 6b 43 68 65 63 6b 28 50 61 72 lite3FkCheck(Par
31410 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
31420 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 , int, int*, int
31430 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
31440 33 46 6b 44 72 6f 70 54 61 62 6c 65 28 50 61 72 3FkDropTable(Par
31450 73 65 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 se*, SrcList *,
31460 54 61 62 6c 65 2a 29 3b 0a 20 20 76 6f 69 64 20 Table*);. void
31470 73 71 6c 69 74 65 33 46 6b 41 63 74 69 6f 6e 73 sqlite3FkActions
31480 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
31490 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c ExprList*, int,
314a0 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 69 int*, int);. i
314b0 6e 74 20 73 71 6c 69 74 65 33 46 6b 52 65 71 75 nt sqlite3FkRequ
314c0 69 72 65 64 28 50 61 72 73 65 2a 2c 20 54 61 62 ired(Parse*, Tab
314d0 6c 65 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b le*, int*, int);
314e0 0a 20 20 75 33 32 20 73 71 6c 69 74 65 33 46 6b . u32 sqlite3Fk
314f0 4f 6c 64 6d 61 73 6b 28 50 61 72 73 65 2a 2c 20 Oldmask(Parse*,
31500 54 61 62 6c 65 2a 29 3b 0a 20 20 46 4b 65 79 20 Table*);. FKey
31510 2a 73 71 6c 69 74 65 33 46 6b 52 65 66 65 72 65 *sqlite3FkRefere
31520 6e 63 65 73 28 54 61 62 6c 65 20 2a 29 3b 0a 23 nces(Table *);.#
31530 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 else. #define s
31540 71 6c 69 74 65 33 46 6b 41 63 74 69 6f 6e 73 28 qlite3FkActions(
31550 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 20 23 a,b,c,d,e,f). #
31560 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
31570 43 68 65 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 2c Check(a,b,c,d,e,
31580 66 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c f). #define sql
31590 69 74 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 28 ite3FkDropTable(
315a0 61 2c 62 2c 63 29 0a 20 20 23 64 65 66 69 6e 65 a,b,c). #define
315b0 20 73 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 61 73 sqlite3FkOldmas
315c0 6b 28 61 2c 62 29 20 20 20 20 20 20 20 20 20 30 k(a,b) 0
315d0 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
315e0 65 33 46 6b 52 65 71 75 69 72 65 64 28 61 2c 62 e3FkRequired(a,b
315f0 2c 63 2c 64 29 20 20 20 20 30 0a 20 20 23 64 65 ,c,d) 0. #de
31600 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 52 65 fine sqlite3FkRe
31610 66 65 72 65 6e 63 65 73 28 61 29 20 20 20 20 20 ferences(a)
31620 20 20 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 6e 0.#endif.#ifn
31630 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
31640 46 4f 52 45 49 47 4e 5f 4b 45 59 0a 20 20 76 6f FOREIGN_KEY. vo
31650 69 64 20 73 71 6c 69 74 65 33 46 6b 44 65 6c 65 id sqlite3FkDele
31660 74 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 54 61 te(sqlite3 *, Ta
31670 62 6c 65 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c ble*);. int sql
31680 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e 64 65 ite3FkLocateInde
31690 78 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c x(Parse*,Table*,
316a0 46 4b 65 79 2a 2c 49 6e 64 65 78 2a 2a 2c 69 6e FKey*,Index**,in
316b0 74 2a 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 t**);.#else. #d
316c0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 44 efine sqlite3FkD
316d0 65 6c 65 74 65 28 61 2c 62 29 0a 20 20 23 64 65 elete(a,b). #de
316e0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 4c 6f fine sqlite3FkLo
316f0 63 61 74 65 49 6e 64 65 78 28 61 2c 62 2c 63 2c cateIndex(a,b,c,
31700 64 2c 65 29 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a d,e).#endif.../*
31710 0a 2a 2a 20 41 76 61 69 6c 61 62 6c 65 20 66 61 .** Available fa
31720 75 6c 74 20 69 6e 6a 65 63 74 6f 72 73 2e 20 20 ult injectors.
31730 53 68 6f 75 6c 64 20 62 65 20 6e 75 6d 62 65 72 Should be number
31740 65 64 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 ed beginning wit
31750 68 20 30 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 h 0..*/.#define
31760 53 51 4c 49 54 45 5f 46 41 55 4c 54 49 4e 4a 45 SQLITE_FAULTINJE
31770 43 54 4f 52 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 CTOR_MALLOC
31780 30 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 0.#define SQLITE
31790 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 43 _FAULTINJECTOR_C
317a0 4f 55 4e 54 20 20 20 20 20 20 31 0a 0a 2f 2a 0a OUNT 1../*.
317b0 2a 2a 20 54 68 65 20 69 6e 74 65 72 66 61 63 65 ** The interface
317c0 20 74 6f 20 74 68 65 20 63 6f 64 65 20 69 6e 20 to the code in
317d0 66 61 75 6c 74 2e 63 20 75 73 65 64 20 66 6f 72 fault.c used for
317e0 20 69 64 65 6e 74 69 66 79 69 6e 67 20 22 62 65 identifying "be
317f0 6e 69 67 6e 22 0a 2a 2a 20 6d 61 6c 6c 6f 63 20 nign".** malloc
31800 66 61 69 6c 75 72 65 73 2e 20 54 68 69 73 20 69 failures. This i
31810 73 20 6f 6e 6c 79 20 70 72 65 73 65 6e 74 20 69 s only present i
31820 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 f SQLITE_UNTESTA
31830 42 4c 45 0a 2a 2a 20 69 73 20 6e 6f 74 20 64 65 BLE.** is not de
31840 66 69 6e 65 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 fined..*/.#ifnde
31850 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 f SQLITE_UNTESTA
31860 42 4c 45 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 BLE. void sqlit
31870 65 33 42 65 67 69 6e 42 65 6e 69 67 6e 4d 61 6c e3BeginBenignMal
31880 6c 6f 63 28 76 6f 69 64 29 3b 0a 20 20 76 6f 69 loc(void);. voi
31890 64 20 73 71 6c 69 74 65 33 45 6e 64 42 65 6e 69 d sqlite3EndBeni
318a0 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a gnMalloc(void);.
318b0 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
318c0 73 71 6c 69 74 65 33 42 65 67 69 6e 42 65 6e 69 sqlite3BeginBeni
318d0 67 6e 4d 61 6c 6c 6f 63 28 29 0a 20 20 23 64 65 gnMalloc(). #de
318e0 66 69 6e 65 20 73 71 6c 69 74 65 33 45 6e 64 42 fine sqlite3EndB
318f0 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a 23 65 enignMalloc().#e
31900 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f ndif../*.** Allo
31910 77 65 64 20 72 65 74 75 72 6e 20 76 61 6c 75 65 wed return value
31920 73 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 46 69 s from sqlite3Fi
31930 6e 64 49 6e 49 6e 64 65 78 28 29 0a 2a 2f 0a 23 ndInIndex().*/.#
31940 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
31950 52 4f 57 49 44 20 20 20 20 20 20 20 20 31 20 20 ROWID 1
31960 20 2f 2a 20 53 65 61 72 63 68 20 74 68 65 20 72 /* Search the r
31970 6f 77 69 64 20 6f 66 20 74 68 65 20 74 61 62 6c owid of the tabl
31980 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f e */.#define IN_
31990 49 4e 44 45 58 5f 45 50 48 20 20 20 20 20 20 20 INDEX_EPH
319a0 20 20 20 32 20 20 20 2f 2a 20 53 65 61 72 63 68 2 /* Search
319b0 20 61 6e 20 65 70 68 65 6d 65 72 61 6c 20 62 2d an ephemeral b-
319c0 74 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tree */.#define
319d0 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 58 5f 41 IN_INDEX_INDEX_A
319e0 53 43 20 20 20 20 33 20 20 20 2f 2a 20 45 78 69 SC 3 /* Exi
319f0 73 74 69 6e 67 20 69 6e 64 65 78 20 41 53 43 45 sting index ASCE
31a00 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 66 69 6e 65 NDING */.#define
31a10 20 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 58 5f IN_INDEX_INDEX_
31a20 44 45 53 43 20 20 20 34 20 20 20 2f 2a 20 45 78 DESC 4 /* Ex
31a30 69 73 74 69 6e 67 20 69 6e 64 65 78 20 44 45 53 isting index DES
31a40 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 66 69 CENDING */.#defi
31a50 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 ne IN_INDEX_NOOP
31a60 20 20 20 20 20 20 20 20 20 35 20 20 20 2f 2a 20 5 /*
31a70 4e 6f 20 74 61 62 6c 65 20 61 76 61 69 6c 61 62 No table availab
31a80 6c 65 2e 20 55 73 65 20 63 6f 6d 70 61 72 69 73 le. Use comparis
31a90 6f 6e 73 20 2a 2f 0a 2f 2a 0a 2a 2a 20 41 6c 6c ons */./*.** All
31aa0 6f 77 65 64 20 66 6c 61 67 73 20 66 6f 72 20 74 owed flags for t
31ab0 68 65 20 33 72 64 20 70 61 72 61 6d 65 74 65 72 he 3rd parameter
31ac0 20 74 6f 20 73 71 6c 69 74 65 33 46 69 6e 64 49 to sqlite3FindI
31ad0 6e 49 6e 64 65 78 28 29 2e 0a 2a 2f 0a 23 64 65 nIndex()..*/.#de
31ae0 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f fine IN_INDEX_NO
31af0 4f 50 5f 4f 4b 20 20 20 20 20 30 78 30 30 30 31 OP_OK 0x0001
31b00 20 20 2f 2a 20 4f 4b 20 74 6f 20 72 65 74 75 72 /* OK to retur
31b10 6e 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 20 n IN_INDEX_NOOP
31b20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
31b30 44 45 58 5f 4d 45 4d 42 45 52 53 48 49 50 20 20 DEX_MEMBERSHIP
31b40 30 78 30 30 30 32 20 20 2f 2a 20 49 4e 20 6f 70 0x0002 /* IN op
31b50 65 72 61 74 6f 72 20 75 73 65 64 20 66 6f 72 20 erator used for
31b60 6d 65 6d 62 65 72 73 68 69 70 20 74 65 73 74 20 membership test
31b70 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
31b80 44 45 58 5f 4c 4f 4f 50 20 20 20 20 20 20 20 20 DEX_LOOP
31b90 30 78 30 30 30 34 20 20 2f 2a 20 49 4e 20 6f 70 0x0004 /* IN op
31ba0 65 72 61 74 6f 72 20 75 73 65 64 20 61 73 20 61 erator used as a
31bb0 20 6c 6f 6f 70 20 2a 2f 0a 69 6e 74 20 73 71 6c loop */.int sql
31bc0 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 ite3FindInIndex(
31bd0 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 2a 2c Parse *, Expr *,
31be0 20 75 33 32 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a u32, int*, int*
31bf0 2c 20 69 6e 74 2a 29 3b 0a 0a 69 6e 74 20 73 71 , int*);..int sq
31c00 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e lite3JournalOpen
31c10 28 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 2c 20 (sqlite3_vfs *,
31c20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 73 71 const char *, sq
31c30 6c 69 74 65 33 5f 66 69 6c 65 20 2a 2c 20 69 6e lite3_file *, in
31c40 74 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c t, int);.int sql
31c50 69 74 65 33 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 ite3JournalSize(
31c60 73 71 6c 69 74 65 33 5f 76 66 73 20 2a 29 3b 0a sqlite3_vfs *);.
31c70 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
31c80 54 45 5f 45 4e 41 42 4c 45 5f 41 54 4f 4d 49 43 TE_ENABLE_ATOMIC
31c90 5f 57 52 49 54 45 29 20 5c 0a 20 7c 7c 20 64 65 _WRITE) \. || de
31ca0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
31cb0 42 4c 45 5f 42 41 54 43 48 5f 41 54 4f 4d 49 43 BLE_BATCH_ATOMIC
31cc0 5f 57 52 49 54 45 29 0a 20 20 69 6e 74 20 73 71 _WRITE). int sq
31cd0 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 43 72 65 61 lite3JournalCrea
31ce0 74 65 28 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 te(sqlite3_file
31cf0 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 69 6e 74 20 *);.#endif..int
31d00 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 49 73 sqlite3JournalIs
31d10 49 6e 4d 65 6d 6f 72 79 28 73 71 6c 69 74 65 33 InMemory(sqlite3
31d20 5f 66 69 6c 65 20 2a 70 29 3b 0a 76 6f 69 64 20 _file *p);.void
31d30 73 71 6c 69 74 65 33 4d 65 6d 4a 6f 75 72 6e 61 sqlite3MemJourna
31d40 6c 4f 70 65 6e 28 73 71 6c 69 74 65 33 5f 66 69 lOpen(sqlite3_fi
31d50 6c 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c le *);..void sql
31d60 69 74 65 33 45 78 70 72 53 65 74 48 65 69 67 68 ite3ExprSetHeigh
31d70 74 41 6e 64 46 6c 61 67 73 28 50 61 72 73 65 20 tAndFlags(Parse
31d80 2a 70 50 61 72 73 65 2c 20 45 78 70 72 20 2a 70 *pParse, Expr *p
31d90 29 3b 0a 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 );.#if SQLITE_MA
31da0 58 5f 45 58 50 52 5f 44 45 50 54 48 3e 30 0a 20 X_EXPR_DEPTH>0.
31db0 20 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 int sqlite3Sele
31dc0 63 74 45 78 70 72 48 65 69 67 68 74 28 53 65 6c ctExprHeight(Sel
31dd0 65 63 74 20 2a 29 3b 0a 20 20 69 6e 74 20 73 71 ect *);. int sq
31de0 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 lite3ExprCheckHe
31df0 69 67 68 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 ight(Parse*, int
31e00 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 );.#else. #defi
31e10 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 ne sqlite3Select
31e20 45 78 70 72 48 65 69 67 68 74 28 78 29 20 30 0a ExprHeight(x) 0.
31e30 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
31e40 33 45 78 70 72 43 68 65 63 6b 48 65 69 67 68 74 3ExprCheckHeight
31e50 28 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a 75 33 (x,y).#endif..u3
31e60 32 20 73 71 6c 69 74 65 33 47 65 74 34 62 79 74 2 sqlite3Get4byt
31e70 65 28 63 6f 6e 73 74 20 75 38 2a 29 3b 0a 76 6f e(const u8*);.vo
31e80 69 64 20 73 71 6c 69 74 65 33 50 75 74 34 62 79 id sqlite3Put4by
31e90 74 65 28 75 38 2a 2c 20 75 33 32 29 3b 0a 0a 23 te(u8*, u32);..#
31ea0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
31eb0 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 BLE_UNLOCK_NOTIF
31ec0 59 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 Y. void sqlite3
31ed0 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 ConnectionBlocke
31ee0 64 28 73 71 6c 69 74 65 33 20 2a 2c 20 73 71 6c d(sqlite3 *, sql
31ef0 69 74 65 33 20 2a 29 3b 0a 20 20 76 6f 69 64 20 ite3 *);. void
31f00 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f sqlite3Connectio
31f10 6e 55 6e 6c 6f 63 6b 65 64 28 73 71 6c 69 74 65 nUnlocked(sqlite
31f20 33 20 2a 64 62 29 3b 0a 20 20 76 6f 69 64 20 73 3 *db);. void s
31f30 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
31f40 43 6c 6f 73 65 64 28 73 71 6c 69 74 65 33 20 2a Closed(sqlite3 *
31f50 64 62 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 db);.#else. #de
31f60 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e fine sqlite3Conn
31f70 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 64 28 78 2c ectionBlocked(x,
31f80 79 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c y). #define sql
31f90 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 55 6e ite3ConnectionUn
31fa0 6c 6f 63 6b 65 64 28 78 29 0a 20 20 23 64 65 66 locked(x). #def
31fb0 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 ine sqlite3Conne
31fc0 63 74 69 6f 6e 43 6c 6f 73 65 64 28 78 29 0a 23 ctionClosed(x).#
31fd0 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
31fe0 4c 49 54 45 5f 44 45 42 55 47 0a 20 20 76 6f 69 LITE_DEBUG. voi
31ff0 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 54 d sqlite3ParserT
32000 72 61 63 65 28 46 49 4c 45 2a 2c 20 63 68 61 72 race(FILE*, char
32010 20 2a 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 *);.#endif.#if
32020 64 65 66 69 6e 65 64 28 59 59 43 4f 56 45 52 41 defined(YYCOVERA
32030 47 45 29 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 GE). int sqlite
32040 33 50 61 72 73 65 72 43 6f 76 65 72 61 67 65 28 3ParserCoverage(
32050 46 49 4c 45 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a FILE*);.#endif..
32060 2f 2a 0a 2a 2a 20 49 66 20 74 68 65 20 53 51 4c /*.** If the SQL
32070 49 54 45 5f 45 4e 41 42 4c 45 20 49 4f 54 52 41 ITE_ENABLE IOTRA
32080 43 45 20 65 78 69 73 74 73 20 74 68 65 6e 20 74 CE exists then t
32090 68 65 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 he global variab
320a0 6c 65 0a 2a 2a 20 73 71 6c 69 74 65 33 49 6f 54 le.** sqlite3IoT
320b0 72 61 63 65 20 69 73 20 61 20 70 6f 69 6e 74 65 race is a pointe
320c0 72 20 74 6f 20 61 20 70 72 69 6e 74 66 2d 6c 69 r to a printf-li
320d0 6b 65 20 72 6f 75 74 69 6e 65 20 75 73 65 64 20 ke routine used
320e0 74 6f 0a 2a 2a 20 70 72 69 6e 74 20 49 2f 4f 20 to.** print I/O
320f0 74 72 61 63 69 6e 67 20 6d 65 73 73 61 67 65 73 tracing messages
32100 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
32110 54 45 5f 45 4e 41 42 4c 45 5f 49 4f 54 52 41 43 TE_ENABLE_IOTRAC
32120 45 0a 23 20 64 65 66 69 6e 65 20 49 4f 54 52 41 E.# define IOTRA
32130 43 45 28 41 29 20 20 69 66 28 20 73 71 6c 69 74 CE(A) if( sqlit
32140 65 33 49 6f 54 72 61 63 65 20 29 7b 20 73 71 6c e3IoTrace ){ sql
32150 69 74 65 33 49 6f 54 72 61 63 65 20 41 3b 20 7d ite3IoTrace A; }
32160 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 . void sqlite3V
32170 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 56 64 dbeIOTraceSql(Vd
32180 62 65 2a 29 3b 0a 53 51 4c 49 54 45 5f 41 50 49 be*);.SQLITE_API
32190 20 53 51 4c 49 54 45 5f 45 58 54 45 52 4e 20 76 SQLITE_EXTERN v
321a0 6f 69 64 20 28 53 51 4c 49 54 45 5f 43 44 45 43 oid (SQLITE_CDEC
321b0 4c 20 2a 73 71 6c 69 74 65 33 49 6f 54 72 61 63 L *sqlite3IoTrac
321c0 65 29 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e e)(const char*,.
321d0 2e 2e 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 ..);.#else.# def
321e0 69 6e 65 20 49 4f 54 52 41 43 45 28 41 29 0a 23 ine IOTRACE(A).#
321f0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
32200 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 58 29 dbeIOTraceSql(X)
32210 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
32220 68 65 73 65 20 72 6f 75 74 69 6e 65 73 20 61 72 hese routines ar
32230 65 20 61 76 61 69 6c 61 62 6c 65 20 66 6f 72 20 e available for
32240 74 68 65 20 6d 65 6d 32 2e 63 20 64 65 62 75 67 the mem2.c debug
32250 67 69 6e 67 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f ging memory allo
32260 63 61 74 6f 72 0a 2a 2a 20 6f 6e 6c 79 2e 20 20 cator.** only.
32270 54 68 65 79 20 61 72 65 20 75 73 65 64 20 74 6f They are used to
32280 20 76 65 72 69 66 79 20 74 68 61 74 20 64 69 66 verify that dif
32290 66 65 72 65 6e 74 20 22 74 79 70 65 73 22 20 6f ferent "types" o
322a0 66 20 6d 65 6d 6f 72 79 0a 2a 2a 20 61 6c 6c 6f f memory.** allo
322b0 63 61 74 69 6f 6e 73 20 61 72 65 20 70 72 6f 70 cations are prop
322c0 65 72 6c 79 20 74 72 61 63 6b 65 64 20 62 79 20 erly tracked by
322d0 74 68 65 20 73 79 73 74 65 6d 2e 0a 2a 2a 0a 2a the system..**.*
322e0 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 * sqlite3Memdebu
322f0 67 53 65 74 54 79 70 65 28 29 20 73 65 74 73 20 gSetType() sets
32300 74 68 65 20 22 74 79 70 65 22 20 6f 66 20 61 6e the "type" of an
32310 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 74 6f 20 6f allocation to o
32320 6e 65 20 6f 66 0a 2a 2a 20 74 68 65 20 4d 45 4d ne of.** the MEM
32330 54 59 50 45 5f 2a 20 6d 61 63 72 6f 73 20 64 65 TYPE_* macros de
32340 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 20 54 68 fined below. Th
32350 65 20 74 79 70 65 20 6d 75 73 74 20 62 65 20 61 e type must be a
32360 20 62 69 74 6d 61 73 6b 20 77 69 74 68 0a 2a 2a bitmask with.**
32370 20 61 20 73 69 6e 67 6c 65 20 62 69 74 20 73 65 a single bit se
32380 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 t..**.** sqlite3
32390 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 28 MemdebugHasType(
323a0 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 69 ) returns true i
323b0 66 20 61 6e 79 20 6f 66 20 74 68 65 20 62 69 74 f any of the bit
323c0 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e 64 0a s in its second.
323d0 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 74 63 ** argument matc
323e0 68 20 74 68 65 20 74 79 70 65 20 73 65 74 20 62 h the type set b
323f0 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 73 y the previous s
32400 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 qlite3MemdebugSe
32410 74 54 79 70 65 28 29 2e 0a 2a 2a 20 73 71 6c 69 tType()..** sqli
32420 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 te3MemdebugHasTy
32430 70 65 28 29 20 69 73 20 69 6e 74 65 6e 64 65 64 pe() is intended
32440 20 66 6f 72 20 75 73 65 20 69 6e 73 69 64 65 20 for use inside
32450 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
32460 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 nts..**.** sqlit
32470 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 e3MemdebugNoType
32480 28 29 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 () returns true
32490 69 66 20 6e 6f 6e 65 20 6f 66 20 74 68 65 20 62 if none of the b
324a0 69 74 73 20 69 6e 20 69 74 73 20 73 65 63 6f 6e its in its secon
324b0 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d 61 d.** argument ma
324c0 74 63 68 20 74 68 65 20 74 79 70 65 20 73 65 74 tch the type set
324d0 20 62 79 20 74 68 65 20 70 72 65 76 69 6f 75 73 by the previous
324e0 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
324f0 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a 0a 2a 2a SetType()..**.**
32500 20 50 65 72 68 61 70 73 20 74 68 65 20 6d 6f 73 Perhaps the mos
32510 74 20 69 6d 70 6f 72 74 61 6e 74 20 70 6f 69 6e t important poin
32520 74 20 69 73 20 74 68 65 20 64 69 66 66 65 72 65 t is the differe
32530 6e 63 65 20 62 65 74 77 65 65 6e 20 4d 45 4d 54 nce between MEMT
32540 59 50 45 5f 48 45 41 50 0a 2a 2a 20 61 6e 64 20 YPE_HEAP.** and
32550 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 MEMTYPE_LOOKASID
32560 45 2e 20 20 49 66 20 61 6e 20 61 6c 6c 6f 63 61 E. If an alloca
32570 74 69 6f 6e 20 69 73 20 4d 45 4d 54 59 50 45 5f tion is MEMTYPE_
32580 4c 4f 4f 4b 41 53 49 44 45 2c 20 74 68 61 74 20 LOOKASIDE, that
32590 6d 65 61 6e 73 0a 2a 2a 20 69 74 20 6d 69 67 68 means.** it migh
325a0 74 20 68 61 76 65 20 62 65 65 6e 20 61 6c 6c 6f t have been allo
325b0 63 61 74 65 64 20 62 79 20 6c 6f 6f 6b 61 73 69 cated by lookasi
325c0 64 65 2c 20 65 78 63 65 70 74 20 74 68 65 20 61 de, except the a
325d0 6c 6c 6f 63 61 74 69 6f 6e 20 77 61 73 0a 2a 2a llocation was.**
325e0 20 74 6f 6f 20 6c 61 72 67 65 20 6f 72 20 6c 6f too large or lo
325f0 6f 6b 61 73 69 64 65 20 77 61 73 20 61 6c 72 65 okaside was alre
32600 61 64 79 20 66 75 6c 6c 2e 20 20 49 74 20 69 73 ady full. It is
32610 20 69 6d 70 6f 72 74 61 6e 74 20 74 6f 20 76 65 important to ve
32620 72 69 66 79 0a 2a 2a 20 74 68 61 74 20 61 6c 6c rify.** that all
32630 6f 63 61 74 69 6f 6e 73 20 74 68 61 74 20 6d 69 ocations that mi
32640 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 73 61 ght have been sa
32650 74 69 73 66 69 65 64 20 62 79 20 6c 6f 6f 6b 61 tisfied by looka
32660 73 69 64 65 20 61 72 65 20 6e 6f 74 0a 2a 2a 20 side are not.**
32670 70 61 73 73 65 64 20 62 61 63 6b 20 74 6f 20 6e passed back to n
32680 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 66 72 65 on-lookaside fre
32690 65 28 29 20 72 6f 75 74 69 6e 65 73 2e 20 20 41 e() routines. A
326a0 73 73 65 72 74 73 20 73 75 63 68 20 61 73 20 74 sserts such as t
326b0 68 65 0a 2a 2a 20 65 78 61 6d 70 6c 65 20 61 62 he.** example ab
326c0 6f 76 65 20 61 72 65 20 70 6c 61 63 65 64 20 6f ove are placed o
326d0 6e 20 74 68 65 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 n the non-lookas
326e0 69 64 65 20 66 72 65 65 28 29 20 72 6f 75 74 69 ide free() routi
326f0 6e 65 73 20 74 6f 20 76 65 72 69 66 79 0a 2a 2a nes to verify.**
32700 20 74 68 69 73 20 63 6f 6e 73 74 72 61 69 6e 74 this constraint
32710 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f 66 20 74 ..**.** All of t
32720 68 69 73 20 69 73 20 6e 6f 2d 6f 70 20 66 6f 72 his is no-op for
32730 20 61 20 70 72 6f 64 75 63 74 69 6f 6e 20 62 75 a production bu
32740 69 6c 64 2e 20 20 49 74 20 6f 6e 6c 79 20 63 6f ild. It only co
32750 6d 65 73 20 69 6e 74 6f 0a 2a 2a 20 70 6c 61 79 mes into.** play
32760 20 77 68 65 6e 20 74 68 65 20 53 51 4c 49 54 45 when the SQLITE
32770 5f 4d 45 4d 44 45 42 55 47 20 63 6f 6d 70 69 6c _MEMDEBUG compil
32780 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e 20 69 73 e-time option is
32790 20 75 73 65 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 used..*/.#ifdef
327a0 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 SQLITE_MEMDEBUG
327b0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 4d . void sqlite3M
327c0 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 76 emdebugSetType(v
327d0 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 20 oid*,u8);. int
327e0 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 sqlite3MemdebugH
327f0 61 73 54 79 70 65 28 76 6f 69 64 2a 2c 75 38 29 asType(void*,u8)
32800 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d ;. int sqlite3M
32810 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 28 76 6f emdebugNoType(vo
32820 69 64 2a 2c 75 38 29 3b 0a 23 65 6c 73 65 0a 23 id*,u8);.#else.#
32830 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d define sqlite3M
32840 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 58 emdebugSetType(X
32850 2c 59 29 20 20 2f 2a 20 6e 6f 2d 6f 70 20 2a 2f ,Y) /* no-op */
32860 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
32870 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 65 3MemdebugHasType
32880 28 58 2c 59 29 20 20 31 0a 23 20 64 65 66 69 6e (X,Y) 1.# defin
32890 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 e sqlite3Memdebu
328a0 67 4e 6f 54 79 70 65 28 58 2c 59 29 20 20 20 31 gNoType(X,Y) 1
328b0 0a 23 65 6e 64 69 66 0a 23 64 65 66 69 6e 65 20 .#endif.#define
328c0 4d 45 4d 54 59 50 45 5f 48 45 41 50 20 20 20 20 MEMTYPE_HEAP
328d0 20 20 20 30 78 30 31 20 20 2f 2a 20 47 65 6e 65 0x01 /* Gene
328e0 72 61 6c 20 68 65 61 70 20 61 6c 6c 6f 63 61 74 ral heap allocat
328f0 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ions */.#define
32900 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 MEMTYPE_LOOKASID
32910 45 20 20 30 78 30 32 20 20 2f 2a 20 48 65 61 70 E 0x02 /* Heap
32920 20 74 68 61 74 20 6d 69 67 68 74 20 68 61 76 65 that might have
32930 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 69 64 65 20 been lookaside
32940 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 */.#define MEMTY
32950 50 45 5f 50 43 41 43 48 45 20 20 20 20 20 30 78 PE_PCACHE 0x
32960 30 34 20 20 2f 2a 20 50 61 67 65 20 63 61 63 68 04 /* Page cach
32970 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f e allocations */
32980 0a 0a 2f 2a 0a 2a 2a 20 54 68 72 65 61 64 69 6e ../*.** Threadin
32990 67 20 69 6e 74 65 72 66 61 63 65 0a 2a 2f 0a 23 g interface.*/.#
329a0 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f if SQLITE_MAX_WO
329b0 52 4b 45 52 5f 54 48 52 45 41 44 53 3e 30 0a 69 RKER_THREADS>0.i
329c0 6e 74 20 73 71 6c 69 74 65 33 54 68 72 65 61 64 nt sqlite3Thread
329d0 43 72 65 61 74 65 28 53 51 4c 69 74 65 54 68 72 Create(SQLiteThr
329e0 65 61 64 2a 2a 2c 76 6f 69 64 2a 28 2a 29 28 76 ead**,void*(*)(v
329f0 6f 69 64 2a 29 2c 76 6f 69 64 2a 29 3b 0a 69 6e oid*),void*);.in
32a00 74 20 73 71 6c 69 74 65 33 54 68 72 65 61 64 4a t sqlite3ThreadJ
32a10 6f 69 6e 28 53 51 4c 69 74 65 54 68 72 65 61 64 oin(SQLiteThread
32a20 2a 2c 20 76 6f 69 64 2a 2a 29 3b 0a 23 65 6e 64 *, void**);.#end
32a30 69 66 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 if..#if defined(
32a40 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 42 SQLITE_ENABLE_DB
32a50 50 41 47 45 5f 56 54 41 42 29 20 7c 7c 20 64 65 PAGE_VTAB) || de
32a60 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 fined(SQLITE_TES
32a70 54 29 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 T).int sqlite3Db
32a80 70 61 67 65 52 65 67 69 73 74 65 72 28 73 71 6c pageRegister(sql
32a90 69 74 65 33 2a 29 3b 0a 23 65 6e 64 69 66 0a 23 ite3*);.#endif.#
32aa0 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
32ab0 45 5f 45 4e 41 42 4c 45 5f 44 42 53 54 41 54 5f E_ENABLE_DBSTAT_
32ac0 56 54 41 42 29 20 7c 7c 20 64 65 66 69 6e 65 64 VTAB) || defined
32ad0 28 53 51 4c 49 54 45 5f 54 45 53 54 29 0a 69 6e (SQLITE_TEST).in
32ae0 74 20 73 71 6c 69 74 65 33 44 62 73 74 61 74 52 t sqlite3DbstatR
32af0 65 67 69 73 74 65 72 28 73 71 6c 69 74 65 33 2a egister(sqlite3*
32b00 29 3b 0a 23 65 6e 64 69 66 0a 0a 69 6e 74 20 73 );.#endif..int s
32b10 71 6c 69 74 65 33 45 78 70 72 56 65 63 74 6f 72 qlite3ExprVector
32b20 53 69 7a 65 28 45 78 70 72 20 2a 70 45 78 70 72 Size(Expr *pExpr
32b30 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
32b40 70 72 49 73 56 65 63 74 6f 72 28 45 78 70 72 20 prIsVector(Expr
32b50 2a 70 45 78 70 72 29 3b 0a 45 78 70 72 20 2a 73 *pExpr);.Expr *s
32b60 71 6c 69 74 65 33 56 65 63 74 6f 72 46 69 65 6c qlite3VectorFiel
32b70 64 53 75 62 65 78 70 72 28 45 78 70 72 2a 2c 20 dSubexpr(Expr*,
32b80 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 int);.Expr *sqli
32b90 74 65 33 45 78 70 72 46 6f 72 56 65 63 74 6f 72 te3ExprForVector
32ba0 46 69 65 6c 64 28 50 61 72 73 65 2a 2c 45 78 70 Field(Parse*,Exp
32bb0 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 r*,int);.void sq
32bc0 6c 69 74 65 33 56 65 63 74 6f 72 45 72 72 6f 72 lite3VectorError
32bd0 4d 73 67 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Msg(Parse*, Expr
32be0 2a 29 3b 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c *);..#ifndef SQL
32bf0 49 54 45 5f 4f 4d 49 54 5f 43 4f 4d 50 49 4c 45 ITE_OMIT_COMPILE
32c00 4f 50 54 49 4f 4e 5f 44 49 41 47 53 0a 63 6f 6e OPTION_DIAGS.con
32c10 73 74 20 63 68 61 72 20 2a 2a 73 71 6c 69 74 65 st char **sqlite
32c20 33 43 6f 6d 70 69 6c 65 4f 70 74 69 6f 6e 73 28 3CompileOptions(
32c30 69 6e 74 20 2a 70 6e 4f 70 74 29 3b 0a 23 65 6e int *pnOpt);.#en
32c40 64 69 66 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 53 dif..#endif /* S
32c50 51 4c 49 54 45 49 4e 54 5f 48 20 2a 2f 0a QLITEINT_H */.