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 4d 61 6b 65 20 73 75 72 ../*.** Make sur
0770: 65 20 74 68 61 74 20 72 61 6e 64 5f 73 28 29 20 e that rand_s()
0780: 69 73 20 61 76 61 69 6c 61 62 6c 65 20 6f 6e 20 is available on
0790: 57 69 6e 64 6f 77 73 20 73 79 73 74 65 6d 73 20 Windows systems
07a0: 77 69 74 68 20 4d 53 56 43 20 32 30 30 35 0a 2a with MSVC 2005.*
07b0: 2a 20 6f 72 20 68 69 67 68 65 72 2e 0a 2a 2f 0a * or higher..*/.
07c0: 23 69 66 20 64 65 66 69 6e 65 64 28 5f 4d 53 43 #if defined(_MSC
07d0: 5f 56 45 52 29 20 26 26 20 5f 4d 53 43 5f 56 45 _VER) && _MSC_VE
07e0: 52 3e 3d 31 34 30 30 0a 23 20 20 64 65 66 69 6e R>=1400.# defin
07f0: 65 20 5f 43 52 54 5f 52 41 4e 44 5f 53 0a 23 65 e _CRT_RAND_S.#e
0800: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c ndif../*.** Incl
0810: 75 64 65 20 74 68 65 20 68 65 61 64 65 72 20 66 ude the header f
0820: 69 6c 65 20 75 73 65 64 20 74 6f 20 63 75 73 74 ile used to cust
0830: 6f 6d 69 7a 65 20 74 68 65 20 63 6f 6d 70 69 6c omize the compil
0840: 65 72 20 6f 70 74 69 6f 6e 73 20 66 6f 72 20 4d er options for M
0850: 53 56 43 2e 0a 2a 2a 20 54 68 69 73 20 73 68 6f SVC..** This sho
0860: 75 6c 64 20 62 65 20 64 6f 6e 65 20 66 69 72 73 uld be done firs
0870: 74 20 73 6f 20 74 68 61 74 20 69 74 20 63 61 6e t so that it can
0880: 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 70 72 successfully pr
0890: 65 76 65 6e 74 20 73 70 75 72 69 6f 75 73 0a 2a event spurious.*
08a0: 2a 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e 69 * compiler warni
08b0: 6e 67 73 20 64 75 65 20 74 6f 20 73 75 62 73 65 ngs due to subse
08c0: 71 75 65 6e 74 20 63 6f 6e 74 65 6e 74 20 69 6e quent content in
08d0: 20 74 68 69 73 20 66 69 6c 65 20 61 6e 64 20 6f this file and o
08e0: 74 68 65 72 20 66 69 6c 65 73 0a 2a 2a 20 74 68 ther files.** th
08f0: 61 74 20 61 72 65 20 69 6e 63 6c 75 64 65 64 20 at are included
0900: 62 79 20 74 68 69 73 20 66 69 6c 65 2e 0a 2a 2f by this file..*/
0910: 0a 23 69 6e 63 6c 75 64 65 20 22 6d 73 76 63 2e .#include "msvc.
0920: 68 22 0a 0a 2f 2a 0a 2a 2a 20 53 70 65 63 69 61 h"../*.** Specia
0930: 6c 20 73 65 74 75 70 20 66 6f 72 20 56 78 57 6f l setup for VxWo
0940: 72 6b 73 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 rks.*/.#include
0950: 22 76 78 77 6f 72 6b 73 2e 68 22 0a 0a 2f 2a 0a "vxworks.h"../*.
0960: 2a 2a 20 54 68 65 73 65 20 23 64 65 66 69 6e 65 ** These #define
0970: 73 20 73 68 6f 75 6c 64 20 65 6e 61 62 6c 65 20 s should enable
0980: 3e 32 47 42 20 66 69 6c 65 20 73 75 70 70 6f 72 >2GB file suppor
0990: 74 20 6f 6e 20 50 4f 53 49 58 20 69 66 20 74 68 t on POSIX if th
09a0: 65 0a 2a 2a 20 75 6e 64 65 72 6c 79 69 6e 67 20 e.** underlying
09b0: 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d operating system
09c0: 20 73 75 70 70 6f 72 74 73 20 69 74 2e 20 20 49 supports it. I
09d0: 66 20 74 68 65 20 4f 53 20 6c 61 63 6b 73 0a 2a f the OS lacks.*
09e0: 2a 20 6c 61 72 67 65 20 66 69 6c 65 20 73 75 70 * large file sup
09f0: 70 6f 72 74 2c 20 6f 72 20 69 66 20 74 68 65 20 port, or if the
0a00: 4f 53 20 69 73 20 77 69 6e 64 6f 77 73 2c 20 74 OS is windows, t
0a10: 68 65 73 65 20 73 68 6f 75 6c 64 20 62 65 20 6e hese should be n
0a20: 6f 2d 6f 70 73 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 o-ops..**.** Tic
0a30: 6b 65 74 20 23 32 37 33 39 3a 20 20 54 68 65 20 ket #2739: The
0a40: 5f 4c 41 52 47 45 46 49 4c 45 5f 53 4f 55 52 43 _LARGEFILE_SOURC
0a50: 45 20 6d 61 63 72 6f 20 6d 75 73 74 20 61 70 70 E macro must app
0a60: 65 61 72 20 62 65 66 6f 72 65 20 61 6e 79 0a 2a ear before any.*
0a70: 2a 20 73 79 73 74 65 6d 20 23 69 6e 63 6c 75 64 * system #includ
0a80: 65 73 2e 20 20 48 65 6e 63 65 2c 20 74 68 69 73 es. Hence, this
0a90: 20 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 20 6d block of code m
0aa0: 75 73 74 20 62 65 20 74 68 65 20 76 65 72 79 20 ust be the very
0ab0: 66 69 72 73 74 0a 2a 2a 20 63 6f 64 65 20 69 6e first.** code in
0ac0: 20 61 6c 6c 20 73 6f 75 72 63 65 20 66 69 6c 65 all source file
0ad0: 73 2e 0a 2a 2a 0a 2a 2a 20 4c 61 72 67 65 20 66 s..**.** Large f
0ae0: 69 6c 65 20 73 75 70 70 6f 72 74 20 63 61 6e 20 ile support can
0af0: 62 65 20 64 69 73 61 62 6c 65 64 20 75 73 69 6e be disabled usin
0b00: 67 20 74 68 65 20 2d 44 53 51 4c 49 54 45 5f 44 g the -DSQLITE_D
0b10: 49 53 41 42 4c 45 5f 4c 46 53 20 73 77 69 74 63 ISABLE_LFS switc
0b20: 68 0a 2a 2a 20 6f 6e 20 74 68 65 20 63 6f 6d 70 h.** on the comp
0b30: 69 6c 65 72 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e iler command lin
0b40: 65 2e 20 20 54 68 69 73 20 69 73 20 6e 65 63 65 e. This is nece
0b50: 73 73 61 72 79 20 69 66 20 79 6f 75 20 61 72 65 ssary if you are
0b60: 20 63 6f 6d 70 69 6c 69 6e 67 0a 2a 2a 20 6f 6e compiling.** on
0b70: 20 61 20 72 65 63 65 6e 74 20 6d 61 63 68 69 6e a recent machin
0b80: 65 20 28 65 78 3a 20 52 65 64 20 48 61 74 20 37 e (ex: Red Hat 7
0b90: 2e 32 29 20 62 75 74 20 79 6f 75 20 77 61 6e 74 .2) but you want
0ba0: 20 79 6f 75 72 20 63 6f 64 65 20 74 6f 20 77 6f your code to wo
0bb0: 72 6b 0a 2a 2a 20 6f 6e 20 61 6e 20 6f 6c 64 65 rk.** on an olde
0bc0: 72 20 6d 61 63 68 69 6e 65 20 28 65 78 3a 20 52 r machine (ex: R
0bd0: 65 64 20 48 61 74 20 36 2e 30 29 2e 20 20 49 66 ed Hat 6.0). If
0be0: 20 79 6f 75 20 63 6f 6d 70 69 6c 65 20 6f 6e 20 you compile on
0bf0: 52 65 64 20 48 61 74 20 37 2e 32 0a 2a 2a 20 77 Red Hat 7.2.** w
0c00: 69 74 68 6f 75 74 20 74 68 69 73 20 6f 70 74 69 ithout this opti
0c10: 6f 6e 2c 20 4c 46 53 20 69 73 20 65 6e 61 62 6c on, LFS is enabl
0c20: 65 2e 20 20 42 75 74 20 4c 46 53 20 64 6f 65 73 e. But LFS does
0c30: 20 6e 6f 74 20 65 78 69 73 74 20 69 6e 20 74 68 not exist in th
0c40: 65 20 6b 65 72 6e 65 6c 0a 2a 2a 20 69 6e 20 52 e kernel.** in R
0c50: 65 64 20 48 61 74 20 36 2e 30 2c 20 73 6f 20 74 ed Hat 6.0, so t
0c60: 68 65 20 63 6f 64 65 20 77 6f 6e 27 74 20 77 6f he code won't wo
0c70: 72 6b 2e 20 20 48 65 6e 63 65 2c 20 66 6f 72 20 rk. Hence, for
0c80: 6d 61 78 69 6d 75 6d 20 62 69 6e 61 72 79 0a 2a maximum binary.*
0c90: 2a 20 70 6f 72 74 61 62 69 6c 69 74 79 20 79 6f * portability yo
0ca0: 75 20 73 68 6f 75 6c 64 20 6f 6d 69 74 20 4c 46 u should omit LF
0cb0: 53 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 70 72 65 S..**.** The pre
0cc0: 76 69 6f 75 73 20 70 61 72 61 67 72 61 70 68 20 vious paragraph
0cd0: 77 61 73 20 77 72 69 74 74 65 6e 20 69 6e 20 32 was written in 2
0ce0: 30 30 35 2e 20 20 28 54 68 69 73 20 70 61 72 61 005. (This para
0cf0: 67 72 61 70 68 20 69 73 20 77 72 69 74 74 65 6e graph is written
0d00: 0a 2a 2a 20 6f 6e 20 32 30 30 38 2d 31 31 2d 32 .** on 2008-11-2
0d10: 38 2e 29 20 54 68 65 73 65 20 64 61 79 73 2c 20 8.) These days,
0d20: 61 6c 6c 20 4c 69 6e 75 78 20 6b 65 72 6e 65 6c all Linux kernel
0d30: 73 20 73 75 70 70 6f 72 74 20 6c 61 72 67 65 20 s support large
0d40: 66 69 6c 65 73 2c 20 73 6f 0a 2a 2a 20 79 6f 75 files, so.** you
0d50: 20 73 68 6f 75 6c 64 20 70 72 6f 62 61 62 6c 79 should probably
0d60: 20 6c 65 61 76 65 20 4c 46 53 20 65 6e 61 62 6c leave LFS enabl
0d70: 65 64 2e 20 20 42 75 74 20 73 6f 6d 65 20 65 6d ed. But some em
0d80: 62 65 64 64 65 64 20 70 6c 61 74 66 6f 72 6d 73 bedded platforms
0d90: 20 6d 69 67 68 74 0a 2a 2a 20 6c 61 63 6b 20 4c might.** lack L
0da0: 46 53 20 69 6e 20 77 68 69 63 68 20 63 61 73 65 FS in which case
0db0: 20 74 68 65 20 53 51 4c 49 54 45 5f 44 49 53 41 the SQLITE_DISA
0dc0: 42 4c 45 5f 4c 46 53 20 6d 61 63 72 6f 20 6d 69 BLE_LFS macro mi
0dd0: 67 68 74 20 73 74 69 6c 6c 20 62 65 20 75 73 65 ght still be use
0de0: 66 75 6c 2e 0a 2a 2a 0a 2a 2a 20 53 69 6d 69 6c ful..**.** Simil
0df0: 61 72 20 69 73 20 74 72 75 65 20 66 6f 72 20 4d ar is true for M
0e00: 61 63 20 4f 53 20 58 2e 20 20 4c 46 53 20 69 73 ac OS X. LFS is
0e10: 20 6f 6e 6c 79 20 73 75 70 70 6f 72 74 65 64 20 only supported
0e20: 6f 6e 20 4d 61 63 20 4f 53 20 58 20 39 20 61 6e on Mac OS X 9 an
0e30: 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 23 69 66 6e d later..*/.#ifn
0e40: 64 65 66 20 53 51 4c 49 54 45 5f 44 49 53 41 42 def SQLITE_DISAB
0e50: 4c 45 5f 4c 46 53 0a 23 20 64 65 66 69 6e 65 20 LE_LFS.# define
0e60: 5f 4c 41 52 47 45 5f 46 49 4c 45 20 20 20 20 20 _LARGE_FILE
0e70: 20 20 31 0a 23 20 69 66 6e 64 65 66 20 5f 46 49 1.# ifndef _FI
0e80: 4c 45 5f 4f 46 46 53 45 54 5f 42 49 54 53 0a 23 LE_OFFSET_BITS.#
0e90: 20 20 20 64 65 66 69 6e 65 20 5f 46 49 4c 45 5f define _FILE_
0ea0: 4f 46 46 53 45 54 5f 42 49 54 53 20 36 34 0a 23 OFFSET_BITS 64.#
0eb0: 20 65 6e 64 69 66 0a 23 20 64 65 66 69 6e 65 20 endif.# define
0ec0: 5f 4c 41 52 47 45 46 49 4c 45 5f 53 4f 55 52 43 _LARGEFILE_SOURC
0ed0: 45 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 57 E 1.#endif../* W
0ee0: 68 61 74 20 76 65 72 73 69 6f 6e 20 6f 66 20 47 hat version of G
0ef0: 43 43 20 69 73 20 62 65 69 6e 67 20 75 73 65 64 CC is being used
0f00: 2e 20 20 30 20 6d 65 61 6e 73 20 47 43 43 20 69 . 0 means GCC i
0f10: 73 20 6e 6f 74 20 62 65 69 6e 67 20 75 73 65 64 s not being used
0f20: 20 2a 2f 0a 23 69 66 64 65 66 20 5f 5f 47 4e 55 */.#ifdef __GNU
0f30: 43 5f 5f 0a 23 20 64 65 66 69 6e 65 20 47 43 43 C__.# define GCC
0f40: 5f 56 45 52 53 49 4f 4e 20 28 5f 5f 47 4e 55 43 _VERSION (__GNUC
0f50: 5f 5f 2a 31 30 30 30 30 30 30 2b 5f 5f 47 4e 55 __*1000000+__GNU
0f60: 43 5f 4d 49 4e 4f 52 5f 5f 2a 31 30 30 30 2b 5f C_MINOR__*1000+_
0f70: 5f 47 4e 55 43 5f 50 41 54 43 48 4c 45 56 45 4c _GNUC_PATCHLEVEL
0f80: 5f 5f 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 __).#else.# defi
0f90: 6e 65 20 47 43 43 5f 56 45 52 53 49 4f 4e 20 30 ne GCC_VERSION 0
0fa0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 57 68 61 74 .#endif../* What
0fb0: 20 76 65 72 73 69 6f 6e 20 6f 66 20 43 4c 41 4e version of CLAN
0fc0: 47 20 69 73 20 62 65 69 6e 67 20 75 73 65 64 2e G is being used.
0fd0: 20 20 30 20 6d 65 61 6e 73 20 43 4c 41 4e 47 20 0 means CLANG
0fe0: 69 73 20 6e 6f 74 20 62 65 69 6e 67 20 75 73 65 is not being use
0ff0: 64 20 2a 2f 0a 23 69 66 64 65 66 20 5f 5f 63 6c d */.#ifdef __cl
1000: 61 6e 67 5f 5f 0a 23 20 64 65 66 69 6e 65 20 43 ang__.# define C
1010: 4c 41 4e 47 5f 56 45 52 53 49 4f 4e 20 5c 0a 20 LANG_VERSION \.
1020: 20 20 20 20 20 20 20 20 20 20 20 28 5f 5f 63 6c (__cl
1030: 61 6e 67 5f 6d 61 6a 6f 72 5f 5f 2a 31 30 30 30 ang_major__*1000
1040: 30 30 30 2b 5f 5f 63 6c 61 6e 67 5f 6d 69 6e 6f 000+__clang_mino
1050: 72 5f 5f 2a 31 30 30 30 2b 5f 5f 63 6c 61 6e 67 r__*1000+__clang
1060: 5f 70 61 74 63 68 6c 65 76 65 6c 5f 5f 29 0a 23 _patchlevel__).#
1070: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 43 4c else.# define CL
1080: 41 4e 47 5f 56 45 52 53 49 4f 4e 20 30 0a 23 65 ANG_VERSION 0.#e
1090: 6e 64 69 66 0a 0a 2f 2a 20 4e 65 65 64 65 64 20 ndif../* Needed
10a0: 66 6f 72 20 76 61 72 69 6f 75 73 20 64 65 66 69 for various defi
10b0: 6e 69 74 69 6f 6e 73 2e 2e 2e 20 2a 2f 0a 23 69 nitions... */.#i
10c0: 66 20 64 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 f defined(__GNUC
10d0: 5f 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 __) && !defined(
10e0: 5f 47 4e 55 5f 53 4f 55 52 43 45 29 0a 23 20 64 _GNU_SOURCE).# d
10f0: 65 66 69 6e 65 20 5f 47 4e 55 5f 53 4f 55 52 43 efine _GNU_SOURC
1100: 45 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 64 65 E.#endif..#if de
1110: 66 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f fined(__OpenBSD_
1120: 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f _) && !defined(_
1130: 42 53 44 5f 53 4f 55 52 43 45 29 0a 23 20 64 65 BSD_SOURCE).# de
1140: 66 69 6e 65 20 5f 42 53 44 5f 53 4f 55 52 43 45 fine _BSD_SOURCE
1150: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 .#endif../*.** F
1160: 6f 72 20 4d 69 6e 47 57 2c 20 63 68 65 63 6b 20 or MinGW, check
1170: 74 6f 20 73 65 65 20 69 66 20 77 65 20 63 61 6e to see if we can
1180: 20 69 6e 63 6c 75 64 65 20 74 68 65 20 68 65 61 include the hea
1190: 64 65 72 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e der file contain
11a0: 69 6e 67 20 69 74 73 0a 2a 2a 20 76 65 72 73 69 ing its.** versi
11b0: 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c 20 on information,
11c0: 61 6d 6f 6e 67 20 6f 74 68 65 72 20 74 68 69 6e among other thin
11d0: 67 73 2e 20 20 4e 6f 72 6d 61 6c 6c 79 2c 20 74 gs. Normally, t
11e0: 68 69 73 20 69 6e 74 65 72 6e 61 6c 20 4d 69 6e his internal Min
11f0: 47 57 0a 2a 2a 20 68 65 61 64 65 72 20 66 69 6c GW.** header fil
1200: 65 20 77 6f 75 6c 64 20 5b 6f 6e 6c 79 5d 20 62 e would [only] b
1210: 65 20 69 6e 63 6c 75 64 65 64 20 61 75 74 6f 6d e included autom
1220: 61 74 69 63 61 6c 6c 79 20 62 79 20 6f 74 68 65 atically by othe
1230: 72 20 4d 69 6e 47 57 20 68 65 61 64 65 72 0a 2a r MinGW header.*
1240: 2a 20 66 69 6c 65 73 3b 20 68 6f 77 65 76 65 72 * files; however
1250: 2c 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 64 20 , the contained
1260: 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 version informat
1270: 69 6f 6e 20 69 73 20 6e 6f 77 20 72 65 71 75 69 ion is now requi
1280: 72 65 64 20 62 79 20 74 68 69 73 0a 2a 2a 20 68 red by this.** h
1290: 65 61 64 65 72 20 66 69 6c 65 20 74 6f 20 77 6f eader file to wo
12a0: 72 6b 20 61 72 6f 75 6e 64 20 62 69 6e 61 72 79 rk around binary
12b0: 20 63 6f 6d 70 61 74 69 62 69 6c 69 74 79 20 69 compatibility i
12c0: 73 73 75 65 73 20 28 73 65 65 20 62 65 6c 6f 77 ssues (see below
12d0: 29 20 61 6e 64 0a 2a 2a 20 74 68 69 73 20 69 73 ) and.** this is
12e0: 20 74 68 65 20 6f 6e 6c 79 20 6b 6e 6f 77 6e 20 the only known
12f0: 77 61 79 20 74 6f 20 72 65 6c 69 61 62 6c 79 20 way to reliably
1300: 6f 62 74 61 69 6e 20 69 74 2e 20 20 54 68 69 73 obtain it. This
1310: 20 65 6e 74 69 72 65 20 23 69 66 20 62 6c 6f 63 entire #if bloc
1320: 6b 0a 2a 2a 20 77 6f 75 6c 64 20 62 65 20 63 6f k.** would be co
1330: 6d 70 6c 65 74 65 6c 79 20 75 6e 6e 65 63 65 73 mpletely unneces
1340: 73 61 72 79 20 69 66 20 74 68 65 72 65 20 77 61 sary if there wa
1350: 73 20 61 6e 79 20 6f 74 68 65 72 20 77 61 79 20 s any other way
1360: 6f 66 20 64 65 74 65 63 74 69 6e 67 0a 2a 2a 20 of detecting.**
1370: 4d 69 6e 47 57 20 76 69 61 20 74 68 65 69 72 20 MinGW via their
1380: 70 72 65 70 72 6f 63 65 73 73 6f 72 20 28 65 2e preprocessor (e.
1390: 67 2e 20 69 66 20 74 68 65 79 20 63 75 73 74 6f g. if they custo
13a0: 6d 69 7a 65 64 20 74 68 65 69 72 20 47 43 43 20 mized their GCC
13b0: 74 6f 20 64 65 66 69 6e 65 0a 2a 2a 20 73 6f 6d to define.** som
13c0: 65 20 4d 69 6e 47 57 2d 73 70 65 63 69 66 69 63 e MinGW-specific
13d0: 20 6d 61 63 72 6f 73 29 2e 20 20 57 68 65 6e 20 macros). When
13e0: 63 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 20 4d 69 compiling for Mi
13f0: 6e 47 57 2c 20 65 69 74 68 65 72 20 74 68 65 0a nGW, either the.
1400: 2a 2a 20 5f 48 41 56 45 5f 4d 49 4e 47 57 5f 48 ** _HAVE_MINGW_H
1410: 20 6f 72 20 5f 48 41 56 45 5f 5f 4d 49 4e 47 57 or _HAVE__MINGW
1420: 5f 48 20 28 6e 6f 74 65 20 74 68 65 20 65 78 74 _H (note the ext
1430: 72 61 20 75 6e 64 65 72 73 63 6f 72 65 29 20 6d ra underscore) m
1440: 61 63 72 6f 20 6d 75 73 74 20 62 65 0a 2a 2a 20 acro must be.**
1450: 64 65 66 69 6e 65 64 3b 20 6f 74 68 65 72 77 69 defined; otherwi
1460: 73 65 2c 20 64 65 74 65 63 74 69 6f 6e 20 6f 66 se, detection of
1470: 20 63 6f 6e 64 69 74 69 6f 6e 73 20 73 70 65 63 conditions spec
1480: 69 66 69 63 20 74 6f 20 4d 69 6e 47 57 20 77 69 ific to MinGW wi
1490: 6c 6c 20 62 65 0a 2a 2a 20 64 69 73 61 62 6c 65 ll be.** disable
14a0: 64 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 d..*/.#if define
14b0: 64 28 5f 48 41 56 45 5f 4d 49 4e 47 57 5f 48 29 d(_HAVE_MINGW_H)
14c0: 0a 23 20 69 6e 63 6c 75 64 65 20 22 6d 69 6e 67 .# include "ming
14d0: 77 2e 68 22 0a 23 65 6c 69 66 20 64 65 66 69 6e w.h".#elif defin
14e0: 65 64 28 5f 48 41 56 45 5f 5f 4d 49 4e 47 57 5f ed(_HAVE__MINGW_
14f0: 48 29 0a 23 20 69 6e 63 6c 75 64 65 20 22 5f 6d H).# include "_m
1500: 69 6e 67 77 2e 68 22 0a 23 65 6e 64 69 66 0a 0a ingw.h".#endif..
1510: 2f 2a 0a 2a 2a 20 46 6f 72 20 4d 69 6e 47 57 20 /*.** For MinGW
1520: 76 65 72 73 69 6f 6e 20 34 2e 78 20 28 61 6e 64 version 4.x (and
1530: 20 68 69 67 68 65 72 29 2c 20 63 68 65 63 6b 20 higher), check
1540: 74 6f 20 73 65 65 20 69 66 20 74 68 65 20 5f 55 to see if the _U
1550: 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 5f 54 0a SE_32BIT_TIME_T.
1560: 2a 2a 20 64 65 66 69 6e 65 20 69 73 20 72 65 71 ** define is req
1570: 75 69 72 65 64 20 74 6f 20 6d 61 69 6e 74 61 69 uired to maintai
1580: 6e 20 62 69 6e 61 72 79 20 63 6f 6d 70 61 74 69 n binary compati
1590: 62 69 6c 69 74 79 20 77 69 74 68 20 74 68 65 20 bility with the
15a0: 4d 53 56 43 20 72 75 6e 74 69 6d 65 0a 2a 2a 20 MSVC runtime.**
15b0: 6c 69 62 72 61 72 79 20 69 6e 20 75 73 65 20 28 library in use (
15c0: 65 2e 67 2e 20 66 6f 72 20 57 69 6e 64 6f 77 73 e.g. for Windows
15d0: 20 58 50 29 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 XP)..*/.#if !de
15e0: 66 69 6e 65 64 28 5f 55 53 45 5f 33 32 42 49 54 fined(_USE_32BIT
15f0: 5f 54 49 4d 45 5f 54 29 20 26 26 20 21 64 65 66 _TIME_T) && !def
1600: 69 6e 65 64 28 5f 55 53 45 5f 36 34 42 49 54 5f ined(_USE_64BIT_
1610: 54 49 4d 45 5f 54 29 20 26 26 20 5c 0a 20 20 20 TIME_T) && \.
1620: 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 defined(_WIN32)
1630: 20 26 26 20 21 64 65 66 69 6e 65 64 28 5f 57 49 && !defined(_WI
1640: 4e 36 34 29 20 26 26 20 5c 0a 20 20 20 20 64 65 N64) && \. de
1650: 66 69 6e 65 64 28 5f 5f 4d 49 4e 47 57 5f 4d 41 fined(__MINGW_MA
1660: 4a 4f 52 5f 56 45 52 53 49 4f 4e 29 20 26 26 20 JOR_VERSION) &&
1670: 5f 5f 4d 49 4e 47 57 5f 4d 41 4a 4f 52 5f 56 45 __MINGW_MAJOR_VE
1680: 52 53 49 4f 4e 20 3e 3d 20 34 20 26 26 20 5c 0a RSION >= 4 && \.
1690: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 5f 4d 53 defined(__MS
16a0: 56 43 52 54 5f 5f 29 0a 23 20 64 65 66 69 6e 65 VCRT__).# define
16b0: 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 _USE_32BIT_TIME
16c0: 5f 54 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 54 68 _T.#endif../* Th
16d0: 65 20 70 75 62 6c 69 63 20 53 51 4c 69 74 65 20 e public SQLite
16e0: 69 6e 74 65 72 66 61 63 65 2e 20 20 54 68 65 20 interface. The
16f0: 5f 46 49 4c 45 5f 4f 46 46 53 45 54 5f 42 49 54 _FILE_OFFSET_BIT
1700: 53 20 6d 61 63 72 6f 20 6d 75 73 74 20 61 70 70 S macro must app
1710: 65 61 72 0a 2a 2a 20 66 69 72 73 74 20 69 6e 20 ear.** first in
1720: 51 4e 58 2e 20 20 41 6c 73 6f 2c 20 74 68 65 20 QNX. Also, the
1730: 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 5f _USE_32BIT_TIME_
1740: 54 20 6d 61 63 72 6f 20 6d 75 73 74 20 61 70 70 T macro must app
1750: 65 61 72 20 66 69 72 73 74 20 66 6f 72 0a 2a 2a ear first for.**
1760: 20 4d 69 6e 47 57 2e 0a 2a 2f 0a 23 69 6e 63 6c MinGW..*/.#incl
1770: 75 64 65 20 22 73 71 6c 69 74 65 33 2e 68 22 0a ude "sqlite3.h".
1780: 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 74 ./*.** Include t
1790: 68 65 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e he configuration
17a0: 20 68 65 61 64 65 72 20 6f 75 74 70 75 74 20 62 header output b
17b0: 79 20 27 63 6f 6e 66 69 67 75 72 65 27 20 69 66 y 'configure' if
17c0: 20 77 65 27 72 65 20 75 73 69 6e 67 20 74 68 65 we're using the
17d0: 0a 2a 2a 20 61 75 74 6f 63 6f 6e 66 2d 62 61 73 .** autoconf-bas
17e0: 65 64 20 62 75 69 6c 64 0a 2a 2f 0a 23 69 66 64 ed build.*/.#ifd
17f0: 65 66 20 5f 48 41 56 45 5f 53 51 4c 49 54 45 5f ef _HAVE_SQLITE_
1800: 43 4f 4e 46 49 47 5f 48 0a 23 69 6e 63 6c 75 64 CONFIG_H.#includ
1810: 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a 23 65 6e e "config.h".#en
1820: 64 69 66 0a 0a 23 69 6e 63 6c 75 64 65 20 22 73 dif..#include "s
1830: 71 6c 69 74 65 4c 69 6d 69 74 2e 68 22 0a 0a 2f qliteLimit.h"../
1840: 2a 20 44 69 73 61 62 6c 65 20 6e 75 69 73 61 6e * Disable nuisan
1850: 63 65 20 77 61 72 6e 69 6e 67 73 20 6f 6e 20 42 ce warnings on B
1860: 6f 72 6c 61 6e 64 20 63 6f 6d 70 69 6c 65 72 73 orland compilers
1870: 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 */.#if defined(
1880: 5f 5f 42 4f 52 4c 41 4e 44 43 5f 5f 29 0a 23 70 __BORLANDC__).#p
1890: 72 61 67 6d 61 20 77 61 72 6e 20 2d 72 63 68 20 ragma warn -rch
18a0: 2f 2a 20 75 6e 72 65 61 63 68 61 62 6c 65 20 63 /* unreachable c
18b0: 6f 64 65 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 ode */.#pragma w
18c0: 61 72 6e 20 2d 63 63 63 20 2f 2a 20 43 6f 6e 64 arn -ccc /* Cond
18d0: 69 74 69 6f 6e 20 69 73 20 61 6c 77 61 79 73 20 ition is always
18e0: 74 72 75 65 20 6f 72 20 66 61 6c 73 65 20 2a 2f true or false */
18f0: 0a 23 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 61 .#pragma warn -a
1900: 75 73 20 2f 2a 20 41 73 73 69 67 6e 65 64 20 76 us /* Assigned v
1910: 61 6c 75 65 20 69 73 20 6e 65 76 65 72 20 75 73 alue is never us
1920: 65 64 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 ed */.#pragma wa
1930: 72 6e 20 2d 63 73 75 20 2f 2a 20 43 6f 6d 70 61 rn -csu /* Compa
1940: 72 69 6e 67 20 73 69 67 6e 65 64 20 61 6e 64 20 ring signed and
1950: 75 6e 73 69 67 6e 65 64 20 2a 2f 0a 23 70 72 61 unsigned */.#pra
1960: 67 6d 61 20 77 61 72 6e 20 2d 73 70 61 20 2f 2a gma warn -spa /*
1970: 20 53 75 73 70 69 63 69 6f 75 73 20 70 6f 69 6e Suspicious poin
1980: 74 65 72 20 61 72 69 74 68 6d 65 74 69 63 20 2a ter arithmetic *
1990: 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 /.#endif../*.**
19a0: 49 6e 63 6c 75 64 65 20 73 74 61 6e 64 61 72 64 Include standard
19b0: 20 68 65 61 64 65 72 20 66 69 6c 65 73 20 61 73 header files as
19c0: 20 6e 65 63 65 73 73 61 72 79 0a 2a 2f 0a 23 69 necessary.*/.#i
19d0: 66 64 65 66 20 48 41 56 45 5f 53 54 44 49 4e 54 fdef HAVE_STDINT
19e0: 5f 48 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 _H.#include <std
19f0: 69 6e 74 2e 68 3e 0a 23 65 6e 64 69 66 0a 23 69 int.h>.#endif.#i
1a00: 66 64 65 66 20 48 41 56 45 5f 49 4e 54 54 59 50 fdef HAVE_INTTYP
1a10: 45 53 5f 48 0a 23 69 6e 63 6c 75 64 65 20 3c 69 ES_H.#include <i
1a20: 6e 74 74 79 70 65 73 2e 68 3e 0a 23 65 6e 64 69 nttypes.h>.#endi
1a30: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c f../*.** The fol
1a40: 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 lowing macros ar
1a50: 65 20 75 73 65 64 20 74 6f 20 63 61 73 74 20 70 e used to cast p
1a60: 6f 69 6e 74 65 72 73 20 74 6f 20 69 6e 74 65 67 ointers to integ
1a70: 65 72 73 20 61 6e 64 0a 2a 2a 20 69 6e 74 65 67 ers and.** integ
1a80: 65 72 73 20 74 6f 20 70 6f 69 6e 74 65 72 73 2e ers to pointers.
1a90: 20 20 54 68 65 20 77 61 79 20 79 6f 75 20 64 6f The way you do
1aa0: 20 74 68 69 73 20 76 61 72 69 65 73 20 66 72 6f this varies fro
1ab0: 6d 20 6f 6e 65 20 63 6f 6d 70 69 6c 65 72 0a 2a m one compiler.*
1ac0: 2a 20 74 6f 20 74 68 65 20 6e 65 78 74 2c 20 73 * to the next, s
1ad0: 6f 20 77 65 20 68 61 76 65 20 64 65 76 65 6c 6f o we have develo
1ae0: 70 65 64 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e ped the followin
1af0: 67 20 73 65 74 20 6f 66 20 23 69 66 20 73 74 61 g set of #if sta
1b00: 74 65 6d 65 6e 74 73 0a 2a 2a 20 74 6f 20 67 65 tements.** to ge
1b10: 6e 65 72 61 74 65 20 61 70 70 72 6f 70 72 69 61 nerate appropria
1b20: 74 65 20 6d 61 63 72 6f 73 20 66 6f 72 20 61 20 te macros for a
1b30: 77 69 64 65 20 72 61 6e 67 65 20 6f 66 20 63 6f wide range of co
1b40: 6d 70 69 6c 65 72 73 2e 0a 2a 2a 0a 2a 2a 20 54 mpilers..**.** T
1b50: 68 65 20 63 6f 72 72 65 63 74 20 22 41 4e 53 49 he correct "ANSI
1b60: 22 20 77 61 79 20 74 6f 20 64 6f 20 74 68 69 73 " way to do this
1b70: 20 69 73 20 74 6f 20 75 73 65 20 74 68 65 20 69 is to use the i
1b80: 6e 74 70 74 72 5f 74 20 74 79 70 65 2e 0a 2a 2a ntptr_t type..**
1b90: 20 55 6e 66 6f 72 74 75 6e 61 74 65 6c 79 2c 20 Unfortunately,
1ba0: 74 68 61 74 20 74 79 70 65 64 65 66 20 69 73 20 that typedef is
1bb0: 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 20 6f 6e not available on
1bc0: 20 61 6c 6c 20 63 6f 6d 70 69 6c 65 72 73 2c 20 all compilers,
1bd0: 6f 72 0a 2a 2a 20 69 66 20 69 74 20 69 73 20 61 or.** if it is a
1be0: 76 61 69 6c 61 62 6c 65 2c 20 69 74 20 72 65 71 vailable, it req
1bf0: 75 69 72 65 73 20 61 6e 20 23 69 6e 63 6c 75 64 uires an #includ
1c00: 65 20 6f 66 20 73 70 65 63 69 66 69 63 20 68 65 e of specific he
1c10: 61 64 65 72 73 0a 2a 2a 20 74 68 61 74 20 76 61 aders.** that va
1c20: 72 79 20 66 72 6f 6d 20 6f 6e 65 20 6d 61 63 68 ry from one mach
1c30: 69 6e 65 20 74 6f 20 74 68 65 20 6e 65 78 74 2e ine to the next.
1c40: 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 20 23 33 .**.** Ticket #3
1c50: 38 36 30 3a 20 20 54 68 65 20 6c 6c 76 6d 2d 67 860: The llvm-g
1c60: 63 63 2d 34 2e 32 20 63 6f 6d 70 69 6c 65 72 20 cc-4.2 compiler
1c70: 66 72 6f 6d 20 41 70 70 6c 65 20 63 68 6f 6b 65 from Apple choke
1c80: 73 20 6f 6e 0a 2a 2a 20 74 68 65 20 28 28 76 6f s on.** the ((vo
1c90: 69 64 2a 29 26 28 28 63 68 61 72 2a 29 30 29 5b id*)&((char*)0)[
1ca0: 58 5d 29 20 63 6f 6e 73 74 72 75 63 74 2e 20 20 X]) construct.
1cb0: 42 75 74 20 4d 53 56 43 20 63 68 6f 6b 65 73 20 But MSVC chokes
1cc0: 6f 6e 20 28 28 76 6f 69 64 2a 29 28 58 29 29 2e on ((void*)(X)).
1cd0: 0a 2a 2a 20 53 6f 20 77 65 20 68 61 76 65 20 74 .** So we have t
1ce0: 6f 20 64 65 66 69 6e 65 20 74 68 65 20 6d 61 63 o define the mac
1cf0: 72 6f 73 20 69 6e 20 64 69 66 66 65 72 65 6e 74 ros in different
1d00: 20 77 61 79 73 20 64 65 70 65 6e 64 69 6e 67 20 ways depending
1d10: 6f 6e 20 74 68 65 0a 2a 2a 20 63 6f 6d 70 69 6c on the.** compil
1d20: 65 72 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e er..*/.#if defin
1d30: 65 64 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 ed(__PTRDIFF_TYP
1d40: 45 5f 5f 29 20 20 2f 2a 20 54 68 69 73 20 63 61 E__) /* This ca
1d50: 73 65 20 73 68 6f 75 6c 64 20 77 6f 72 6b 20 66 se should work f
1d60: 6f 72 20 47 43 43 20 2a 2f 0a 23 20 64 65 66 69 or GCC */.# defi
1d70: 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f ne SQLITE_INT_TO
1d80: 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 2a _PTR(X) ((void*
1d90: 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 45 )(__PTRDIFF_TYPE
1da0: 5f 5f 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 __)(X)).# define
1db0: 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 SQLITE_PTR_TO_I
1dc0: 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 5f 5f NT(X) ((int)(__
1dd0: 50 54 52 44 49 46 46 5f 54 59 50 45 5f 5f 29 28 PTRDIFF_TYPE__)(
1de0: 58 29 29 0a 23 65 6c 69 66 20 21 64 65 66 69 6e X)).#elif !defin
1df0: 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 20 20 20 20 ed(__GNUC__)
1e00: 20 20 20 2f 2a 20 57 6f 72 6b 73 20 66 6f 72 20 /* Works for
1e10: 63 6f 6d 70 69 6c 65 72 73 20 6f 74 68 65 72 20 compilers other
1e20: 74 68 61 6e 20 4c 4c 56 4d 20 2a 2f 0a 23 20 64 than LLVM */.# d
1e30: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 efine SQLITE_INT
1e40: 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f _TO_PTR(X) ((vo
1e50: 69 64 2a 29 26 28 28 63 68 61 72 2a 29 30 29 5b id*)&((char*)0)[
1e60: 58 5d 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c X]).# define SQL
1e70: 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 ITE_PTR_TO_INT(X
1e80: 29 20 20 28 28 69 6e 74 29 28 28 28 63 68 61 72 ) ((int)(((char
1e90: 2a 29 58 29 2d 28 63 68 61 72 2a 29 30 29 29 0a *)X)-(char*)0)).
1ea0: 23 65 6c 69 66 20 64 65 66 69 6e 65 64 28 48 41 #elif defined(HA
1eb0: 56 45 5f 53 54 44 49 4e 54 5f 48 29 20 20 20 2f VE_STDINT_H) /
1ec0: 2a 20 55 73 65 20 74 68 69 73 20 63 61 73 65 20 * Use this case
1ed0: 69 66 20 77 65 20 68 61 76 65 20 41 4e 53 49 20 if we have ANSI
1ee0: 68 65 61 64 65 72 73 20 2a 2f 0a 23 20 64 65 66 headers */.# def
1ef0: 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 ine SQLITE_INT_T
1f00: 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 O_PTR(X) ((void
1f10: 2a 29 28 69 6e 74 70 74 72 5f 74 29 28 58 29 29 *)(intptr_t)(X))
1f20: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
1f30: 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 _PTR_TO_INT(X)
1f40: 28 28 69 6e 74 29 28 69 6e 74 70 74 72 5f 74 29 ((int)(intptr_t)
1f50: 28 58 29 29 0a 23 65 6c 73 65 20 20 20 20 20 20 (X)).#else
1f60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f70: 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 74 65 73 /* Generates
1f80: 20 61 20 77 61 72 6e 69 6e 67 20 2d 20 62 75 74 a warning - but
1f90: 20 69 74 20 61 6c 77 61 79 73 20 77 6f 72 6b 73 it always works
1fa0: 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c */.# define SQL
1fb0: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 ITE_INT_TO_PTR(X
1fc0: 29 20 20 28 28 76 6f 69 64 2a 29 28 58 29 29 0a ) ((void*)(X)).
1fd0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
1fe0: 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 PTR_TO_INT(X) (
1ff0: 28 69 6e 74 29 28 58 29 29 0a 23 65 6e 64 69 66 (int)(X)).#endif
2000: 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 72 6f 20 ../*.** A macro
2010: 74 6f 20 68 69 6e 74 20 74 6f 20 74 68 65 20 63 to hint to the c
2020: 6f 6d 70 69 6c 65 72 20 74 68 61 74 20 61 20 66 ompiler that a f
2030: 75 6e 63 74 69 6f 6e 20 73 68 6f 75 6c 64 20 6e unction should n
2040: 6f 74 20 62 65 0a 2a 2a 20 69 6e 6c 69 6e 65 64 ot be.** inlined
2050: 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 ..*/.#if defined
2060: 28 5f 5f 47 4e 55 43 5f 5f 29 0a 23 20 20 64 65 (__GNUC__).# de
2070: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 49 4e fine SQLITE_NOIN
2080: 4c 49 4e 45 20 20 5f 5f 61 74 74 72 69 62 75 74 LINE __attribut
2090: 65 5f 5f 28 28 6e 6f 69 6e 6c 69 6e 65 29 29 0a e__((noinline)).
20a0: 23 65 6c 69 66 20 64 65 66 69 6e 65 64 28 5f 4d #elif defined(_M
20b0: 53 43 5f 56 45 52 29 20 26 26 20 5f 4d 53 43 5f SC_VER) && _MSC_
20c0: 56 45 52 3e 3d 31 33 31 30 0a 23 20 20 64 65 66 VER>=1310.# def
20d0: 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 49 4e 4c ine SQLITE_NOINL
20e0: 49 4e 45 20 20 5f 5f 64 65 63 6c 73 70 65 63 28 INE __declspec(
20f0: 6e 6f 69 6e 6c 69 6e 65 29 0a 23 65 6c 73 65 0a noinline).#else.
2100: 23 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 # define SQLITE
2110: 5f 4e 4f 49 4e 4c 49 4e 45 0a 23 65 6e 64 69 66 _NOINLINE.#endif
2120: 0a 0a 2f 2a 0a 2a 2a 20 4d 61 6b 65 20 73 75 72 ../*.** Make sur
2130: 65 20 74 68 61 74 20 74 68 65 20 63 6f 6d 70 69 e that the compi
2140: 6c 65 72 20 69 6e 74 72 69 6e 73 69 63 73 20 77 ler intrinsics w
2150: 65 20 64 65 73 69 72 65 20 61 72 65 20 65 6e 61 e desire are ena
2160: 62 6c 65 64 20 77 68 65 6e 0a 2a 2a 20 63 6f 6d bled when.** com
2170: 70 69 6c 69 6e 67 20 77 69 74 68 20 61 6e 20 61 piling with an a
2180: 70 70 72 6f 70 72 69 61 74 65 20 76 65 72 73 69 ppropriate versi
2190: 6f 6e 20 6f 66 20 4d 53 56 43 20 75 6e 6c 65 73 on of MSVC unles
21a0: 73 20 70 72 65 76 65 6e 74 65 64 20 62 79 0a 2a s prevented by.*
21b0: 2a 20 74 68 65 20 53 51 4c 49 54 45 5f 44 49 53 * the SQLITE_DIS
21c0: 41 42 4c 45 5f 49 4e 54 52 49 4e 53 49 43 20 64 ABLE_INTRINSIC d
21d0: 65 66 69 6e 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 efine..*/.#if !d
21e0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 49 efined(SQLITE_DI
21f0: 53 41 42 4c 45 5f 49 4e 54 52 49 4e 53 49 43 29 SABLE_INTRINSIC)
2200: 0a 23 20 20 69 66 20 64 65 66 69 6e 65 64 28 5f .# if defined(_
2210: 4d 53 43 5f 56 45 52 29 20 26 26 20 5f 4d 53 43 MSC_VER) && _MSC
2220: 5f 56 45 52 3e 3d 31 34 30 30 0a 23 20 20 20 20 _VER>=1400.#
2230: 69 66 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e if !defined(_WIN
2240: 33 32 5f 57 43 45 29 0a 23 20 20 20 20 20 20 69 32_WCE).# i
2250: 6e 63 6c 75 64 65 20 3c 69 6e 74 72 69 6e 2e 68 nclude <intrin.h
2260: 3e 0a 23 20 20 20 20 20 20 70 72 61 67 6d 61 20 >.# pragma
2270: 69 6e 74 72 69 6e 73 69 63 28 5f 62 79 74 65 73 intrinsic(_bytes
2280: 77 61 70 5f 75 73 68 6f 72 74 29 0a 23 20 20 20 wap_ushort).#
2290: 20 20 20 70 72 61 67 6d 61 20 69 6e 74 72 69 6e pragma intrin
22a0: 73 69 63 28 5f 62 79 74 65 73 77 61 70 5f 75 6c sic(_byteswap_ul
22b0: 6f 6e 67 29 0a 23 20 20 20 20 20 20 70 72 61 67 ong).# prag
22c0: 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 5f 52 65 ma intrinsic(_Re
22d0: 61 64 57 72 69 74 65 42 61 72 72 69 65 72 29 0a adWriteBarrier).
22e0: 23 20 20 20 20 65 6c 73 65 0a 23 20 20 20 20 20 # else.#
22f0: 20 69 6e 63 6c 75 64 65 20 3c 63 6d 6e 69 6e 74 include <cmnint
2300: 72 69 6e 2e 68 3e 0a 23 20 20 20 20 65 6e 64 69 rin.h>.# endi
2310: 66 0a 23 20 20 65 6e 64 69 66 0a 23 65 6e 64 69 f.# endif.#endi
2320: 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 4c f../*.** The SQL
2330: 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 20 6d ITE_THREADSAFE m
2340: 61 63 72 6f 20 6d 75 73 74 20 62 65 20 64 65 66 acro must be def
2350: 69 6e 65 64 20 61 73 20 30 2c 20 31 2c 20 6f 72 ined as 0, 1, or
2360: 20 32 2e 0a 2a 2a 20 30 20 6d 65 61 6e 73 20 6d 2..** 0 means m
2370: 75 74 65 78 65 73 20 61 72 65 20 70 65 72 6d 61 utexes are perma
2380: 6e 65 6e 74 6c 79 20 64 69 73 61 62 6c 65 20 61 nently disable a
2390: 6e 64 20 74 68 65 20 6c 69 62 72 61 72 79 20 69 nd the library i
23a0: 73 20 6e 65 76 65 72 0a 2a 2a 20 74 68 72 65 61 s never.** threa
23b0: 64 73 61 66 65 2e 20 20 31 20 6d 65 61 6e 73 20 dsafe. 1 means
23c0: 74 68 65 20 6c 69 62 72 61 72 79 20 69 73 20 73 the library is s
23d0: 65 72 69 61 6c 69 7a 65 64 20 77 68 69 63 68 20 erialized which
23e0: 69 73 20 74 68 65 20 68 69 67 68 65 73 74 0a 2a is the highest.*
23f0: 2a 20 6c 65 76 65 6c 20 6f 66 20 74 68 72 65 61 * level of threa
2400: 64 73 61 66 65 74 79 2e 20 20 32 20 6d 65 61 6e dsafety. 2 mean
2410: 73 20 74 68 65 20 6c 69 62 72 61 72 79 20 69 73 s the library is
2420: 20 6d 75 6c 74 69 74 68 72 65 61 64 65 64 20 2d multithreaded -
2430: 20 6d 75 6c 74 69 70 6c 65 0a 2a 2a 20 74 68 72 multiple.** thr
2440: 65 61 64 73 20 63 61 6e 20 75 73 65 20 53 51 4c eads can use SQL
2450: 69 74 65 20 61 73 20 6c 6f 6e 67 20 61 73 20 6e ite as long as n
2460: 6f 20 74 77 6f 20 74 68 72 65 61 64 73 20 74 72 o two threads tr
2470: 79 20 74 6f 20 75 73 65 20 74 68 65 20 73 61 6d y to use the sam
2480: 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 6f e.** database co
2490: 6e 6e 65 63 74 69 6f 6e 20 61 74 20 74 68 65 20 nnection at the
24a0: 73 61 6d 65 20 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a same time..**.**
24b0: 20 4f 6c 64 65 72 20 76 65 72 73 69 6f 6e 73 20 Older versions
24c0: 6f 66 20 53 51 4c 69 74 65 20 75 73 65 64 20 61 of SQLite used a
24d0: 6e 20 6f 70 74 69 6f 6e 61 6c 20 54 48 52 45 41 n optional THREA
24e0: 44 53 41 46 45 20 6d 61 63 72 6f 2e 0a 2a 2a 20 DSAFE macro..**
24f0: 57 65 20 73 75 70 70 6f 72 74 20 74 68 61 74 20 We support that
2500: 66 6f 72 20 6c 65 67 61 63 79 2e 0a 2a 2f 0a 23 for legacy..*/.#
2510: 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
2520: 54 45 5f 54 48 52 45 41 44 53 41 46 45 29 0a 23 TE_THREADSAFE).#
2530: 20 69 66 20 64 65 66 69 6e 65 64 28 54 48 52 45 if defined(THRE
2540: 41 44 53 41 46 45 29 0a 23 20 20 20 64 65 66 69 ADSAFE).# defi
2550: 6e 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 ne SQLITE_THREAD
2560: 53 41 46 45 20 54 48 52 45 41 44 53 41 46 45 0a SAFE THREADSAFE.
2570: 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e # else.# defin
2580: 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 53 e SQLITE_THREADS
2590: 41 46 45 20 31 20 2f 2a 20 49 4d 50 3a 20 52 2d AFE 1 /* IMP: R-
25a0: 30 37 32 37 32 2d 32 32 33 30 39 20 2a 2f 0a 23 07272-22309 */.#
25b0: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f endif.#endif../
25c0: 2a 0a 2a 2a 20 50 6f 77 65 72 73 61 66 65 20 6f *.** Powersafe o
25d0: 76 65 72 77 72 69 74 65 20 69 73 20 6f 6e 20 62 verwrite is on b
25e0: 79 20 64 65 66 61 75 6c 74 2e 20 20 42 75 74 20 y default. But
25f0: 63 61 6e 20 62 65 20 74 75 72 6e 65 64 20 6f 66 can be turned of
2600: 66 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65 20 2d f using.** the -
2610: 44 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 DSQLITE_POWERSAF
2620: 45 5f 4f 56 45 52 57 52 49 54 45 3d 30 20 63 6f E_OVERWRITE=0 co
2630: 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f mmand-line optio
2640: 6e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 n..*/.#ifndef SQ
2650: 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 45 5f 4f LITE_POWERSAFE_O
2660: 56 45 52 57 52 49 54 45 0a 23 20 64 65 66 69 6e VERWRITE.# defin
2670: 65 20 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 e SQLITE_POWERSA
2680: 46 45 5f 4f 56 45 52 57 52 49 54 45 20 31 0a 23 FE_OVERWRITE 1.#
2690: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 56 49 endif../*.** EVI
26a0: 44 45 4e 43 45 2d 4f 46 3a 20 52 2d 32 35 37 31 DENCE-OF: R-2571
26b0: 35 2d 33 37 30 37 32 20 4d 65 6d 6f 72 79 20 61 5-37072 Memory a
26c0: 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 69 73 llocation statis
26d0: 74 69 63 73 20 61 72 65 20 65 6e 61 62 6c 65 64 tics are enabled
26e0: 20 62 79 0a 2a 2a 20 64 65 66 61 75 6c 74 20 75 by.** default u
26f0: 6e 6c 65 73 73 20 53 51 4c 69 74 65 20 69 73 20 nless SQLite is
2700: 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 20 53 51 compiled with SQ
2710: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d LITE_DEFAULT_MEM
2720: 53 54 41 54 55 53 3d 30 20 69 6e 0a 2a 2a 20 77 STATUS=0 in.** w
2730: 68 69 63 68 20 63 61 73 65 20 6d 65 6d 6f 72 79 hich case memory
2740: 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 74 allocation stat
2750: 69 73 74 69 63 73 20 61 72 65 20 64 69 73 61 62 istics are disab
2760: 6c 65 64 20 62 79 20 64 65 66 61 75 6c 74 2e 0a led by default..
2770: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
2780: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
2790: 45 4d 53 54 41 54 55 53 29 0a 23 20 64 65 66 69 EMSTATUS).# defi
27a0: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
27b0: 54 5f 4d 45 4d 53 54 41 54 55 53 20 31 0a 23 65 T_MEMSTATUS 1.#e
27c0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 78 61 63 ndif../*.** Exac
27d0: 74 6c 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 tly one of the f
27e0: 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 ollowing macros
27f0: 6d 75 73 74 20 62 65 20 64 65 66 69 6e 65 64 20 must be defined
2800: 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 73 in order to.** s
2810: 70 65 63 69 66 79 20 77 68 69 63 68 20 6d 65 6d pecify which mem
2820: 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 ory allocation s
2830: 75 62 73 79 73 74 65 6d 20 74 6f 20 75 73 65 2e ubsystem to use.
2840: 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 .**.** SQLIT
2850: 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 E_SYSTEM_MALLOC
2860: 20 20 20 20 20 20 20 20 20 2f 2f 20 55 73 65 20 // Use
2870: 6e 6f 72 6d 61 6c 20 73 79 73 74 65 6d 20 6d 61 normal system ma
2880: 6c 6c 6f 63 28 29 0a 2a 2a 20 20 20 20 20 53 51 lloc().** SQ
2890: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
28a0: 43 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 55 C // U
28b0: 73 65 20 57 69 6e 33 32 20 6e 61 74 69 76 65 20 se Win32 native
28c0: 68 65 61 70 20 41 50 49 0a 2a 2a 20 20 20 20 20 heap API.**
28d0: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
28e0: 4f 43 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f OC //
28f0: 20 55 73 65 20 61 20 73 74 75 62 20 61 6c 6c 6f Use a stub allo
2900: 63 61 74 6f 72 20 74 68 61 74 20 61 6c 77 61 79 cator that alway
2910: 73 20 66 61 69 6c 73 0a 2a 2a 20 20 20 20 20 53 s fails.** S
2920: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 20 QLITE_MEMDEBUG
2930: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2f 20 //
2940: 44 65 62 75 67 67 69 6e 67 20 76 65 72 73 69 6f Debugging versio
2950: 6e 20 6f 66 20 73 79 73 74 65 6d 20 6d 61 6c 6c n of system mall
2960: 6f 63 28 29 0a 2a 2a 0a 2a 2a 20 4f 6e 20 57 69 oc().**.** On Wi
2970: 6e 64 6f 77 73 2c 20 69 66 20 74 68 65 20 53 51 ndows, if the SQ
2980: 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f LITE_WIN32_MALLO
2990: 43 5f 56 41 4c 49 44 41 54 45 20 6d 61 63 72 6f C_VALIDATE macro
29a0: 20 69 73 20 64 65 66 69 6e 65 64 20 61 6e 64 20 is defined and
29b0: 74 68 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 the.** assert()
29c0: 6d 61 63 72 6f 20 69 73 20 65 6e 61 62 6c 65 64 macro is enabled
29d0: 2c 20 65 61 63 68 20 63 61 6c 6c 20 69 6e 74 6f , each call into
29e0: 20 74 68 65 20 57 69 6e 33 32 20 6e 61 74 69 76 the Win32 nativ
29f0: 65 20 68 65 61 70 20 73 75 62 73 79 73 74 65 6d e heap subsystem
2a00: 0a 2a 2a 20 77 69 6c 6c 20 63 61 75 73 65 20 48 .** will cause H
2a10: 65 61 70 56 61 6c 69 64 61 74 65 20 74 6f 20 62 eapValidate to b
2a20: 65 20 63 61 6c 6c 65 64 2e 20 20 49 66 20 68 65 e called. If he
2a30: 61 70 20 76 61 6c 69 64 61 74 69 6f 6e 20 73 68 ap validation sh
2a40: 6f 75 6c 64 20 66 61 69 6c 2c 20 61 6e 0a 2a 2a ould fail, an.**
2a50: 20 61 73 73 65 72 74 69 6f 6e 20 77 69 6c 6c 20 assertion will
2a60: 62 65 20 74 72 69 67 67 65 72 65 64 2e 0a 2a 2a be triggered..**
2a70: 0a 2a 2a 20 49 66 20 6e 6f 6e 65 20 6f 66 20 74 .** If none of t
2a80: 68 65 20 61 62 6f 76 65 20 61 72 65 20 64 65 66 he above are def
2a90: 69 6e 65 64 2c 20 74 68 65 6e 20 73 65 74 20 53 ined, then set S
2aa0: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
2ab0: 4c 4f 43 20 61 73 0a 2a 2a 20 74 68 65 20 64 65 LOC as.** the de
2ac0: 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 66 20 64 65 fault..*/.#if de
2ad0: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 53 fined(SQLITE_SYS
2ae0: 54 45 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 TEM_MALLOC) \.
2af0: 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 + defined(SQLITE
2b00: 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 5c _WIN32_MALLOC) \
2b10: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
2b20: 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 29 ITE_ZERO_MALLOC)
2b30: 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 \. + defined(S
2b40: 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 3e QLITE_MEMDEBUG)>
2b50: 31 0a 23 20 65 72 72 6f 72 20 22 54 77 6f 20 6f 1.# error "Two o
2b60: 72 20 6d 6f 72 65 20 6f 66 20 74 68 65 20 66 6f r more of the fo
2b70: 6c 6c 6f 77 69 6e 67 20 63 6f 6d 70 69 6c 65 2d llowing compile-
2b80: 74 69 6d 65 20 63 6f 6e 66 69 67 75 72 61 74 69 time configurati
2b90: 6f 6e 20 6f 70 74 69 6f 6e 73 5c 0a 20 61 72 65 on options\. are
2ba0: 20 64 65 66 69 6e 65 64 20 62 75 74 20 61 74 20 defined but at
2bb0: 6d 6f 73 74 20 6f 6e 65 20 69 73 20 61 6c 6c 6f most one is allo
2bc0: 77 65 64 3a 5c 0a 20 53 51 4c 49 54 45 5f 53 59 wed:\. SQLITE_SY
2bd0: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c STEM_MALLOC, SQL
2be0: 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 ITE_WIN32_MALLOC
2bf0: 2c 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 , SQLITE_MEMDEBU
2c00: 47 2c 5c 0a 20 53 51 4c 49 54 45 5f 5a 45 52 4f G,\. SQLITE_ZERO
2c10: 5f 4d 41 4c 4c 4f 43 22 0a 23 65 6e 64 69 66 0a _MALLOC".#endif.
2c20: 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
2c30: 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 TE_SYSTEM_MALLOC
2c40: 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 ) \. + defined(
2c50: 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c SQLITE_WIN32_MAL
2c60: 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e LOC) \. + defin
2c70: 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d ed(SQLITE_ZERO_M
2c80: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
2c90: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 45 4d 44 ined(SQLITE_MEMD
2ca0: 45 42 55 47 29 3d 3d 30 0a 23 20 64 65 66 69 6e EBUG)==0.# defin
2cb0: 65 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f e SQLITE_SYSTEM_
2cc0: 4d 41 4c 4c 4f 43 20 31 0a 23 65 6e 64 69 66 0a MALLOC 1.#endif.
2cd0: 0a 2f 2a 0a 2a 2a 20 49 66 20 53 51 4c 49 54 45 ./*.** If SQLITE
2ce0: 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d _MALLOC_SOFT_LIM
2cf0: 49 54 20 69 73 20 6e 6f 74 20 7a 65 72 6f 2c 20 IT is not zero,
2d00: 74 68 65 6e 20 74 72 79 20 74 6f 20 6b 65 65 70 then try to keep
2d10: 20 74 68 65 0a 2a 2a 20 73 69 7a 65 73 20 6f 66 the.** sizes of
2d20: 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
2d30: 6f 6e 73 20 62 65 6c 6f 77 20 74 68 69 73 20 76 ons below this v
2d40: 61 6c 75 65 20 77 68 65 72 65 20 70 6f 73 73 69 alue where possi
2d50: 62 6c 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 ble..*/.#if !def
2d60: 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 41 4c 4c ined(SQLITE_MALL
2d70: 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 29 0a 23 OC_SOFT_LIMIT).#
2d80: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d define SQLITE_M
2d90: 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 ALLOC_SOFT_LIMIT
2da0: 20 31 30 32 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 1024.#endif../*
2db0: 0a 2a 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 64 .** We need to d
2dc0: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
2dd0: 52 43 45 20 61 73 20 66 6f 6c 6c 6f 77 73 20 69 RCE as follows i
2de0: 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 61 62 6c n order to enabl
2df0: 65 0a 2a 2a 20 72 65 63 75 72 73 69 76 65 20 6d e.** recursive m
2e00: 75 74 65 78 65 73 20 6f 6e 20 6d 6f 73 74 20 55 utexes on most U
2e10: 6e 69 78 20 73 79 73 74 65 6d 73 20 61 6e 64 20 nix systems and
2e20: 66 63 68 6d 6f 64 28 29 20 6f 6e 20 4f 70 65 6e fchmod() on Open
2e30: 42 53 44 2e 0a 2a 2a 20 42 75 74 20 5f 58 4f 50 BSD..** But _XOP
2e40: 45 4e 5f 53 4f 55 52 43 45 20 64 65 66 69 6e 65 EN_SOURCE define
2e50: 20 63 61 75 73 65 73 20 70 72 6f 62 6c 65 6d 73 causes problems
2e60: 20 66 6f 72 20 4d 61 63 20 4f 53 20 58 2c 20 73 for Mac OS X, s
2e70: 6f 20 6f 6d 69 74 0a 2a 2a 20 69 74 2e 0a 2a 2f o omit.** it..*/
2e80: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 5f 58 .#if !defined(_X
2e90: 4f 50 45 4e 5f 53 4f 55 52 43 45 29 20 26 26 20 OPEN_SOURCE) &&
2ea0: 21 64 65 66 69 6e 65 64 28 5f 5f 44 41 52 57 49 !defined(__DARWI
2eb0: 4e 5f 5f 29 20 26 26 20 21 64 65 66 69 6e 65 64 N__) && !defined
2ec0: 28 5f 5f 41 50 50 4c 45 5f 5f 29 0a 23 20 20 64 (__APPLE__).# d
2ed0: 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f 53 4f 55 efine _XOPEN_SOU
2ee0: 52 43 45 20 36 30 30 0a 23 65 6e 64 69 66 0a 0a RCE 600.#endif..
2ef0: 2f 2a 0a 2a 2a 20 4e 44 45 42 55 47 20 61 6e 64 /*.** NDEBUG and
2f00: 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 61 72 SQLITE_DEBUG ar
2f10: 65 20 6f 70 70 6f 73 69 74 65 73 2e 20 20 49 74 e opposites. It
2f20: 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 73 20 62 should always b
2f30: 65 20 74 72 75 65 20 74 68 61 74 0a 2a 2a 20 64 e true that.** d
2f40: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 3d 3d efined(NDEBUG)==
2f50: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
2f60: 44 45 42 55 47 29 2e 20 20 49 66 20 74 68 69 73 DEBUG). If this
2f70: 20 69 73 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c is not currentl
2f80: 79 20 74 72 75 65 2c 0a 2a 2a 20 6d 61 6b 65 20 y true,.** make
2f90: 69 74 20 74 72 75 65 20 62 79 20 64 65 66 69 6e it true by defin
2fa0: 69 6e 67 20 6f 72 20 75 6e 64 65 66 69 6e 69 6e ing or undefinin
2fb0: 67 20 4e 44 45 42 55 47 2e 0a 2a 2a 0a 2a 2a 20 g NDEBUG..**.**
2fc0: 53 65 74 74 69 6e 67 20 4e 44 45 42 55 47 20 6d Setting NDEBUG m
2fd0: 61 6b 65 73 20 74 68 65 20 63 6f 64 65 20 73 6d akes the code sm
2fe0: 61 6c 6c 65 72 20 61 6e 64 20 66 61 73 74 65 72 aller and faster
2ff0: 20 62 79 20 64 69 73 61 62 6c 69 6e 67 20 74 68 by disabling th
3000: 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 20 73 74 e.** assert() st
3010: 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 atements in the
3020: 63 6f 64 65 2e 20 20 53 6f 20 77 65 20 77 61 6e code. So we wan
3030: 74 20 74 68 65 20 64 65 66 61 75 6c 74 20 61 63 t the default ac
3040: 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 66 6f tion.** to be fo
3050: 72 20 4e 44 45 42 55 47 20 74 6f 20 62 65 20 73 r NDEBUG to be s
3060: 65 74 20 61 6e 64 20 4e 44 45 42 55 47 20 74 6f et and NDEBUG to
3070: 20 62 65 20 75 6e 64 65 66 69 6e 65 64 20 6f 6e be undefined on
3080: 6c 79 20 69 66 20 53 51 4c 49 54 45 5f 44 45 42 ly if SQLITE_DEB
3090: 55 47 0a 2a 2a 20 69 73 20 73 65 74 2e 20 20 54 UG.** is set. T
30a0: 68 75 73 20 4e 44 45 42 55 47 20 62 65 63 6f 6d hus NDEBUG becom
30b0: 65 73 20 61 6e 20 6f 70 74 2d 69 6e 20 72 61 74 es an opt-in rat
30c0: 68 65 72 20 74 68 61 6e 20 61 6e 20 6f 70 74 2d her than an opt-
30d0: 6f 75 74 0a 2a 2a 20 66 65 61 74 75 72 65 2e 0a out.** feature..
30e0: 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
30f0: 4e 44 45 42 55 47 29 20 26 26 20 21 64 65 66 69 NDEBUG) && !defi
3100: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
3110: 29 0a 23 20 64 65 66 69 6e 65 20 4e 44 45 42 55 ).# define NDEBU
3120: 47 20 31 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 G 1.#endif.#if d
3130: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 26 efined(NDEBUG) &
3140: 26 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 & defined(SQLITE
3150: 5f 44 45 42 55 47 29 0a 23 20 75 6e 64 65 66 20 _DEBUG).# undef
3160: 4e 44 45 42 55 47 0a 23 65 6e 64 69 66 0a 0a 2f NDEBUG.#endif../
3170: 2a 0a 2a 2a 20 45 6e 61 62 6c 65 20 53 51 4c 49 *.** Enable SQLI
3180: 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 TE_ENABLE_EXPLAI
3190: 4e 5f 43 4f 4d 4d 45 4e 54 53 20 69 66 20 53 51 N_COMMENTS if SQ
31a0: 4c 49 54 45 5f 44 45 42 55 47 20 69 73 20 74 75 LITE_DEBUG is tu
31b0: 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 69 66 20 rned on..*/.#if
31c0: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
31d0: 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 ENABLE_EXPLAIN_C
31e0: 4f 4d 4d 45 4e 54 53 29 20 26 26 20 64 65 66 69 OMMENTS) && defi
31f0: 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 ned(SQLITE_DEBUG
3200: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
3210: 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e E_ENABLE_EXPLAIN
3220: 5f 43 4f 4d 4d 45 4e 54 53 20 31 0a 23 65 6e 64 _COMMENTS 1.#end
3230: 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 74 65 if../*.** The te
3240: 73 74 63 61 73 65 28 29 20 6d 61 63 72 6f 20 69 stcase() macro i
3250: 73 20 75 73 65 64 20 74 6f 20 61 69 64 20 69 6e s used to aid in
3260: 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 6e coverage testin
3270: 67 2e 20 20 57 68 65 6e 0a 2a 2a 20 64 6f 69 6e g. When.** doin
3280: 67 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 g coverage testi
3290: 6e 67 2c 20 74 68 65 20 63 6f 6e 64 69 74 69 6f ng, the conditio
32a0: 6e 20 69 6e 73 69 64 65 20 74 68 65 20 61 72 67 n inside the arg
32b0: 75 6d 65 6e 74 20 74 6f 0a 2a 2a 20 74 65 73 74 ument to.** test
32c0: 63 61 73 65 28 29 20 6d 75 73 74 20 62 65 20 65 case() must be e
32d0: 76 61 6c 75 61 74 65 64 20 62 6f 74 68 20 74 72 valuated both tr
32e0: 75 65 20 61 6e 64 20 66 61 6c 73 65 20 69 6e 20 ue and false in
32f0: 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 65 74 20 order to.** get
3300: 66 75 6c 6c 20 62 72 61 6e 63 68 20 63 6f 76 65 full branch cove
3310: 72 61 67 65 2e 20 20 54 68 65 20 74 65 73 74 63 rage. The testc
3320: 61 73 65 28 29 20 6d 61 63 72 6f 20 69 73 20 69 ase() macro is i
3330: 6e 73 65 72 74 65 64 0a 2a 2a 20 74 6f 20 68 65 nserted.** to he
3340: 6c 70 20 65 6e 73 75 72 65 20 61 64 65 71 75 61 lp ensure adequa
3350: 74 65 20 74 65 73 74 20 63 6f 76 65 72 61 67 65 te test coverage
3360: 20 69 6e 20 70 6c 61 63 65 73 20 77 68 65 72 65 in places where
3370: 20 73 69 6d 70 6c 65 0a 2a 2a 20 63 6f 6e 64 69 simple.** condi
3380: 74 69 6f 6e 2f 64 65 63 69 73 69 6f 6e 20 63 6f tion/decision co
3390: 76 65 72 61 67 65 20 69 73 20 69 6e 61 64 65 71 verage is inadeq
33a0: 75 61 74 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 uate. For examp
33b0: 6c 65 2c 20 74 65 73 74 63 61 73 65 28 29 0a 2a le, testcase().*
33c0: 2a 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f * can be used to
33d0: 20 6d 61 6b 65 20 73 75 72 65 20 62 6f 75 6e 64 make sure bound
33e0: 61 72 79 20 76 61 6c 75 65 73 20 61 72 65 20 74 ary values are t
33f0: 65 73 74 65 64 2e 20 20 46 6f 72 0a 2a 2a 20 62 ested. For.** b
3400: 69 74 6d 61 73 6b 20 74 65 73 74 73 2c 20 74 65 itmask tests, te
3410: 73 74 63 61 73 65 28 29 20 63 61 6e 20 62 65 20 stcase() can be
3420: 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 73 75 72 used to make sur
3430: 65 20 65 61 63 68 20 62 69 74 0a 2a 2a 20 69 73 e each bit.** is
3440: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 61 6e 64 significant and
3450: 20 75 73 65 64 20 61 74 20 6c 65 61 73 74 20 6f used at least o
3460: 6e 63 65 2e 20 20 4f 6e 20 73 77 69 74 63 68 20 nce. On switch
3470: 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a 20 77 68 statements.** wh
3480: 65 72 65 20 6d 75 6c 74 69 70 6c 65 20 63 61 73 ere multiple cas
3490: 65 73 20 67 6f 20 74 6f 20 74 68 65 20 73 61 6d es go to the sam
34a0: 65 20 62 6c 6f 63 6b 20 6f 66 20 63 6f 64 65 2c e block of code,
34b0: 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 testcase().** c
34c0: 61 6e 20 69 6e 73 75 72 65 20 74 68 61 74 20 61 an insure that a
34d0: 6c 6c 20 63 61 73 65 73 20 61 72 65 20 65 76 61 ll cases are eva
34e0: 6c 75 61 74 65 64 2e 0a 2a 2a 0a 2a 2f 0a 23 69 luated..**.*/.#i
34f0: 66 64 65 66 20 53 51 4c 49 54 45 5f 43 4f 56 45 fdef SQLITE_COVE
3500: 52 41 47 45 5f 54 45 53 54 0a 20 20 76 6f 69 64 RAGE_TEST. void
3510: 20 73 71 6c 69 74 65 33 43 6f 76 65 72 61 67 65 sqlite3Coverage
3520: 28 69 6e 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 (int);.# define
3530: 74 65 73 74 63 61 73 65 28 58 29 20 20 69 66 28 testcase(X) if(
3540: 20 58 20 29 7b 20 73 71 6c 69 74 65 33 43 6f 76 X ){ sqlite3Cov
3550: 65 72 61 67 65 28 5f 5f 4c 49 4e 45 5f 5f 29 3b erage(__LINE__);
3560: 20 7d 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e }.#else.# defin
3570: 65 20 74 65 73 74 63 61 73 65 28 58 29 0a 23 65 e testcase(X).#e
3580: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
3590: 54 45 53 54 4f 4e 4c 59 20 6d 61 63 72 6f 20 69 TESTONLY macro i
35a0: 73 20 75 73 65 64 20 74 6f 20 65 6e 63 6c 6f 73 s used to enclos
35b0: 65 20 76 61 72 69 61 62 6c 65 20 64 65 63 6c 61 e variable decla
35c0: 72 61 74 69 6f 6e 73 20 6f 72 0a 2a 2a 20 6f 74 rations or.** ot
35d0: 68 65 72 20 62 69 74 73 20 6f 66 20 63 6f 64 65 her bits of code
35e0: 20 74 68 61 74 20 61 72 65 20 6e 65 65 64 65 64 that are needed
35f0: 20 74 6f 20 73 75 70 70 6f 72 74 20 74 68 65 20 to support the
3600: 61 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 77 69 74 arguments.** wit
3610: 68 69 6e 20 74 65 73 74 63 61 73 65 28 29 20 61 hin testcase() a
3620: 6e 64 20 61 73 73 65 72 74 28 29 20 6d 61 63 72 nd assert() macr
3630: 6f 73 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 os..*/.#if !defi
3640: 6e 65 64 28 4e 44 45 42 55 47 29 20 7c 7c 20 64 ned(NDEBUG) || d
3650: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 43 4f efined(SQLITE_CO
3660: 56 45 52 41 47 45 5f 54 45 53 54 29 0a 23 20 64 VERAGE_TEST).# d
3670: 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 efine TESTONLY(X
3680: 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 ) X.#else.# def
3690: 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 58 29 0a ine TESTONLY(X).
36a0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f #endif../*.** So
36b0: 6d 65 74 69 6d 65 73 20 77 65 20 6e 65 65 64 20 metimes we need
36c0: 61 20 73 6d 61 6c 6c 20 61 6d 6f 75 6e 74 20 6f a small amount o
36d0: 66 20 63 6f 64 65 20 73 75 63 68 20 61 73 20 61 f code such as a
36e0: 20 76 61 72 69 61 62 6c 65 20 69 6e 69 74 69 61 variable initia
36f0: 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 74 6f 20 73 lization.** to s
3700: 65 74 75 70 20 66 6f 72 20 61 20 6c 61 74 65 72 etup for a later
3710: 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d assert() statem
3720: 65 6e 74 2e 20 20 57 65 20 64 6f 20 6e 6f 74 20 ent. We do not
3730: 77 61 6e 74 20 74 68 69 73 20 63 6f 64 65 20 74 want this code t
3740: 6f 0a 2a 2a 20 61 70 70 65 61 72 20 77 68 65 6e o.** appear when
3750: 20 61 73 73 65 72 74 28 29 20 69 73 20 64 69 73 assert() is dis
3760: 61 62 6c 65 64 2e 20 20 54 68 65 20 66 6f 6c 6c abled. The foll
3770: 6f 77 69 6e 67 20 6d 61 63 72 6f 20 69 73 20 74 owing macro is t
3780: 68 65 72 65 66 6f 72 65 0a 2a 2a 20 75 73 65 64 herefore.** used
3790: 20 74 6f 20 63 6f 6e 74 61 69 6e 20 74 68 61 74 to contain that
37a0: 20 73 65 74 75 70 20 63 6f 64 65 2e 20 20 54 68 setup code. Th
37b0: 65 20 22 56 56 41 22 20 61 63 72 6f 6e 79 6d 20 e "VVA" acronym
37c0: 73 74 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 56 stands for.** "V
37d0: 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 56 61 6c erification, Val
37e0: 69 64 61 74 69 6f 6e 2c 20 61 6e 64 20 41 63 63 idation, and Acc
37f0: 72 65 64 69 74 61 74 69 6f 6e 22 2e 20 20 49 6e reditation". In
3800: 20 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 74 68 other words, th
3810: 65 0a 2a 2a 20 63 6f 64 65 20 77 69 74 68 69 6e e.** code within
3820: 20 56 56 41 5f 4f 4e 4c 59 28 29 20 77 69 6c 6c VVA_ONLY() will
3830: 20 6f 6e 6c 79 20 72 75 6e 20 64 75 72 69 6e 67 only run during
3840: 20 76 65 72 69 66 69 63 61 74 69 6f 6e 20 70 72 verification pr
3850: 6f 63 65 73 73 65 73 2e 0a 2a 2f 0a 23 69 66 6e ocesses..*/.#ifn
3860: 64 65 66 20 4e 44 45 42 55 47 0a 23 20 64 65 66 def NDEBUG.# def
3870: 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 20 ine VVA_ONLY(X)
3880: 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e X.#else.# defin
3890: 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 0a 23 65 e VVA_ONLY(X).#e
38a0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
38b0: 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 45 52 ALWAYS and NEVER
38c0: 20 6d 61 63 72 6f 73 20 73 75 72 72 6f 75 6e 64 macros surround
38d0: 20 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 boolean express
38e0: 69 6f 6e 73 20 77 68 69 63 68 0a 2a 2a 20 61 72 ions which.** ar
38f0: 65 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 61 6c e intended to al
3900: 77 61 79 73 20 62 65 20 74 72 75 65 20 6f 72 20 ways be true or
3910: 66 61 6c 73 65 2c 20 72 65 73 70 65 63 74 69 76 false, respectiv
3920: 65 6c 79 2e 20 20 53 75 63 68 0a 2a 2a 20 65 78 ely. Such.** ex
3930: 70 72 65 73 73 69 6f 6e 73 20 63 6f 75 6c 64 20 pressions could
3940: 62 65 20 6f 6d 69 74 74 65 64 20 66 72 6f 6d 20 be omitted from
3950: 74 68 65 20 63 6f 64 65 20 63 6f 6d 70 6c 65 74 the code complet
3960: 65 6c 79 2e 20 20 42 75 74 20 74 68 65 79 0a 2a ely. But they.*
3970: 2a 20 61 72 65 20 69 6e 63 6c 75 64 65 64 20 69 * are included i
3980: 6e 20 61 20 66 65 77 20 63 61 73 65 73 20 69 6e n a few cases in
3990: 20 6f 72 64 65 72 20 74 6f 20 65 6e 68 61 6e 63 order to enhanc
39a0: 65 20 74 68 65 20 72 65 73 69 6c 69 65 6e 63 65 e the resilience
39b0: 0a 2a 2a 20 6f 66 20 53 51 4c 69 74 65 20 74 6f .** of SQLite to
39c0: 20 75 6e 65 78 70 65 63 74 65 64 20 62 65 68 61 unexpected beha
39d0: 76 69 6f 72 20 2d 20 74 6f 20 6d 61 6b 65 20 74 vior - to make t
39e0: 68 65 20 63 6f 64 65 20 22 73 65 6c 66 2d 68 65 he code "self-he
39f0: 61 6c 69 6e 67 22 0a 2a 2a 20 6f 72 20 22 64 75 aling".** or "du
3a00: 63 74 69 6c 65 22 20 72 61 74 68 65 72 20 74 68 ctile" rather th
3a10: 61 6e 20 62 65 69 6e 67 20 22 62 72 69 74 74 6c an being "brittl
3a20: 65 22 20 61 6e 64 20 63 72 61 73 68 69 6e 67 20 e" and crashing
3a30: 61 74 20 74 68 65 20 66 69 72 73 74 0a 2a 2a 20 at the first.**
3a40: 68 69 6e 74 20 6f 66 20 75 6e 70 6c 61 6e 6e 65 hint of unplanne
3a50: 64 20 62 65 68 61 76 69 6f 72 2e 0a 2a 2a 0a 2a d behavior..**.*
3a60: 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 * In other words
3a70: 2c 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 56 , ALWAYS and NEV
3a80: 45 52 20 61 72 65 20 61 64 64 65 64 20 66 6f 72 ER are added for
3a90: 20 64 65 66 65 6e 73 69 76 65 20 63 6f 64 65 2e defensive code.
3aa0: 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 64 6f 69 6e .**.** When doin
3ab0: 67 20 63 6f 76 65 72 61 67 65 20 74 65 73 74 69 g coverage testi
3ac0: 6e 67 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 ng ALWAYS and NE
3ad0: 56 45 52 20 61 72 65 20 68 61 72 64 2d 63 6f 64 VER are hard-cod
3ae0: 65 64 20 74 6f 0a 2a 2a 20 62 65 20 74 72 75 65 ed to.** be true
3af0: 20 61 6e 64 20 66 61 6c 73 65 20 73 6f 20 74 68 and false so th
3b00: 61 74 20 74 68 65 20 75 6e 72 65 61 63 68 61 62 at the unreachab
3b10: 6c 65 20 63 6f 64 65 20 74 68 65 79 20 73 70 65 le code they spe
3b20: 63 69 66 79 20 77 69 6c 6c 0a 2a 2a 20 6e 6f 74 cify will.** not
3b30: 20 62 65 20 63 6f 75 6e 74 65 64 20 61 73 20 75 be counted as u
3b40: 6e 74 65 73 74 65 64 20 63 6f 64 65 2e 0a 2a 2f ntested code..*/
3b50: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c .#if defined(SQL
3b60: 49 54 45 5f 43 4f 56 45 52 41 47 45 5f 54 45 53 ITE_COVERAGE_TES
3b70: 54 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 T) || defined(SQ
3b80: 4c 49 54 45 5f 4d 55 54 41 54 49 4f 4e 5f 54 45 LITE_MUTATION_TE
3b90: 53 54 29 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 ST).# define ALW
3ba0: 41 59 53 28 58 29 20 20 20 20 20 20 28 31 29 0a AYS(X) (1).
3bb0: 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 58 # define NEVER(X
3bc0: 29 20 20 20 20 20 20 20 28 30 29 0a 23 65 6c 69 ) (0).#eli
3bd0: 66 20 21 64 65 66 69 6e 65 64 28 4e 44 45 42 55 f !defined(NDEBU
3be0: 47 29 0a 23 20 64 65 66 69 6e 65 20 41 4c 57 41 G).# define ALWA
3bf0: 59 53 28 58 29 20 20 20 20 20 20 28 28 58 29 3f YS(X) ((X)?
3c00: 31 3a 28 61 73 73 65 72 74 28 30 29 2c 30 29 29 1:(assert(0),0))
3c10: 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 .# define NEVER(
3c20: 58 29 20 20 20 20 20 20 20 28 28 58 29 3f 28 61 X) ((X)?(a
3c30: 73 73 65 72 74 28 30 29 2c 31 29 3a 30 29 0a 23 ssert(0),1):0).#
3c40: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 41 4c else.# define AL
3c50: 57 41 59 53 28 58 29 20 20 20 20 20 20 28 58 29 WAYS(X) (X)
3c60: 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 52 28 .# define NEVER(
3c70: 58 29 20 20 20 20 20 20 20 28 58 29 0a 23 65 6e X) (X).#en
3c80: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f 6d 65 20 dif../*.** Some
3c90: 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 65 73 20 malloc failures
3ca0: 61 72 65 20 6f 6e 6c 79 20 70 6f 73 73 69 62 6c are only possibl
3cb0: 65 20 69 66 20 53 51 4c 49 54 45 5f 54 45 53 54 e if SQLITE_TEST
3cc0: 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 53 53 20 _REALLOC_STRESS
3cd0: 69 73 0a 2a 2a 20 64 65 66 69 6e 65 64 2e 20 20 is.** defined.
3ce0: 57 65 20 6e 65 65 64 20 74 6f 20 64 65 66 65 6e We need to defen
3cf0: 64 20 61 67 61 69 6e 73 74 20 74 68 6f 73 65 20 d against those
3d00: 66 61 69 6c 75 72 65 73 20 77 68 65 6e 20 74 65 failures when te
3d10: 73 74 69 6e 67 20 77 69 74 68 0a 2a 2a 20 53 51 sting with.** SQ
3d20: 4c 49 54 45 5f 54 45 53 54 5f 52 45 41 4c 4c 4f LITE_TEST_REALLO
3d30: 43 5f 53 54 52 45 53 53 2c 20 62 75 74 20 77 65 C_STRESS, but we
3d40: 20 64 6f 6e 27 74 20 77 61 6e 74 20 74 68 65 20 don't want the
3d50: 75 6e 72 65 61 63 68 61 62 6c 65 20 62 72 61 6e unreachable bran
3d60: 63 68 65 73 0a 2a 2a 20 64 75 72 69 6e 67 20 61 ches.** during a
3d70: 20 6e 6f 72 6d 61 6c 20 62 75 69 6c 64 2e 20 20 normal build.
3d80: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 The following ma
3d90: 63 72 6f 20 63 61 6e 20 62 65 20 75 73 65 64 20 cro can be used
3da0: 74 6f 20 64 69 73 61 62 6c 65 20 74 65 73 74 73 to disable tests
3db0: 0a 2a 2a 20 74 68 61 74 20 61 72 65 20 61 6c 77 .** that are alw
3dc0: 61 79 73 20 66 61 6c 73 65 20 65 78 63 65 70 74 ays false except
3dd0: 20 77 68 65 6e 20 53 51 4c 49 54 45 5f 54 45 53 when SQLITE_TES
3de0: 54 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 53 53 T_REALLOC_STRESS
3df0: 20 69 73 20 73 65 74 2e 0a 2a 2f 0a 23 69 66 20 is set..*/.#if
3e00: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 defined(SQLITE_T
3e10: 45 53 54 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 EST_REALLOC_STRE
3e20: 53 53 29 0a 23 20 64 65 66 69 6e 65 20 4f 4e 4c SS).# define ONL
3e30: 59 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 Y_IF_REALLOC_STR
3e40: 45 53 53 28 58 29 20 20 28 58 29 0a 23 65 6c 69 ESS(X) (X).#eli
3e50: 66 20 21 64 65 66 69 6e 65 64 28 4e 44 45 42 55 f !defined(NDEBU
3e60: 47 29 0a 23 20 64 65 66 69 6e 65 20 4f 4e 4c 59 G).# define ONLY
3e70: 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 _IF_REALLOC_STRE
3e80: 53 53 28 58 29 20 20 28 28 58 29 3f 28 61 73 73 SS(X) ((X)?(ass
3e90: 65 72 74 28 30 29 2c 31 29 3a 30 29 0a 23 65 6c ert(0),1):0).#el
3ea0: 73 65 0a 23 20 64 65 66 69 6e 65 20 4f 4e 4c 59 se.# define ONLY
3eb0: 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 _IF_REALLOC_STRE
3ec0: 53 53 28 58 29 20 20 28 30 29 0a 23 65 6e 64 69 SS(X) (0).#endi
3ed0: 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 63 6c 61 72 61 f../*.** Declara
3ee0: 74 69 6f 6e 73 20 75 73 65 64 20 66 6f 72 20 74 tions used for t
3ef0: 72 61 63 69 6e 67 20 74 68 65 20 6f 70 65 72 61 racing the opera
3f00: 74 69 6e 67 20 73 79 73 74 65 6d 20 69 6e 74 65 ting system inte
3f10: 72 66 61 63 65 73 2e 0a 2a 2f 0a 23 69 66 20 64 rfaces..*/.#if d
3f20: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 46 4f efined(SQLITE_FO
3f30: 52 43 45 5f 4f 53 5f 54 52 41 43 45 29 20 7c 7c RCE_OS_TRACE) ||
3f40: 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
3f50: 54 45 53 54 29 20 7c 7c 20 5c 0a 20 20 20 20 28 TEST) || \. (
3f60: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 defined(SQLITE_D
3f70: 45 42 55 47 29 20 26 26 20 53 51 4c 49 54 45 5f EBUG) && SQLITE_
3f80: 4f 53 5f 57 49 4e 29 0a 20 20 65 78 74 65 72 6e OS_WIN). extern
3f90: 20 69 6e 74 20 73 71 6c 69 74 65 33 4f 53 54 72 int sqlite3OSTr
3fa0: 61 63 65 3b 0a 23 20 64 65 66 69 6e 65 20 4f 53 ace;.# define OS
3fb0: 54 52 41 43 45 28 58 29 20 20 20 20 20 20 20 20 TRACE(X)
3fc0: 20 20 69 66 28 20 73 71 6c 69 74 65 33 4f 53 54 if( sqlite3OST
3fd0: 72 61 63 65 20 29 20 73 71 6c 69 74 65 33 44 65 race ) sqlite3De
3fe0: 62 75 67 50 72 69 6e 74 66 20 58 0a 23 20 64 65 bugPrintf X.# de
3ff0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 48 41 56 45 fine SQLITE_HAVE
4000: 5f 4f 53 5f 54 52 41 43 45 0a 23 65 6c 73 65 0a _OS_TRACE.#else.
4010: 23 20 64 65 66 69 6e 65 20 4f 53 54 52 41 43 45 # define OSTRACE
4020: 28 58 29 0a 23 20 75 6e 64 65 66 20 20 53 51 4c (X).# undef SQL
4030: 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 ITE_HAVE_OS_TRAC
4040: 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 E.#endif../*.**
4050: 49 73 20 74 68 65 20 73 71 6c 69 74 65 33 45 72 Is the sqlite3Er
4060: 72 4e 61 6d 65 28 29 20 66 75 6e 63 74 69 6f 6e rName() function
4070: 20 6e 65 65 64 65 64 20 69 6e 20 74 68 65 20 62 needed in the b
4080: 75 69 6c 64 3f 20 20 43 75 72 72 65 6e 74 6c 79 uild? Currently
4090: 2c 0a 2a 2a 20 69 74 20 69 73 20 6e 65 65 64 65 ,.** it is neede
40a0: 64 20 62 79 20 22 6d 75 74 65 78 5f 77 33 32 2e d by "mutex_w32.
40b0: 63 22 20 28 77 68 65 6e 20 64 65 62 75 67 67 69 c" (when debuggi
40c0: 6e 67 29 2c 20 22 6f 73 5f 77 69 6e 2e 63 22 20 ng), "os_win.c"
40d0: 28 77 68 65 6e 0a 2a 2a 20 4f 53 54 52 41 43 45 (when.** OSTRACE
40e0: 20 69 73 20 65 6e 61 62 6c 65 64 29 2c 20 61 6e is enabled), an
40f0: 64 20 62 79 20 73 65 76 65 72 61 6c 20 22 74 65 d by several "te
4100: 73 74 2a 2e 63 22 20 66 69 6c 65 73 20 28 77 68 st*.c" files (wh
4110: 69 63 68 20 61 72 65 0a 2a 2a 20 63 6f 6d 70 69 ich are.** compi
4120: 6c 65 64 20 75 73 69 6e 67 20 53 51 4c 49 54 45 led using SQLITE
4130: 5f 54 45 53 54 29 2e 0a 2a 2f 0a 23 69 66 20 64 _TEST)..*/.#if d
4140: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 48 41 efined(SQLITE_HA
4150: 56 45 5f 4f 53 5f 54 52 41 43 45 29 20 7c 7c 20 VE_OS_TRACE) ||
4160: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 defined(SQLITE_T
4170: 45 53 54 29 20 7c 7c 20 5c 0a 20 20 20 20 28 64 EST) || \. (d
4180: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 efined(SQLITE_DE
4190: 42 55 47 29 20 26 26 20 53 51 4c 49 54 45 5f 4f BUG) && SQLITE_O
41a0: 53 5f 57 49 4e 29 0a 23 20 64 65 66 69 6e 65 20 S_WIN).# define
41b0: 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 52 5f SQLITE_NEED_ERR_
41c0: 4e 41 4d 45 0a 23 65 6c 73 65 0a 23 20 75 6e 64 NAME.#else.# und
41d0: 65 66 20 20 53 51 4c 49 54 45 5f 4e 45 45 44 5f ef SQLITE_NEED_
41e0: 45 52 52 5f 4e 41 4d 45 0a 23 65 6e 64 69 66 0a ERR_NAME.#endif.
41f0: 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 5f 45 4e ./*.** SQLITE_EN
4200: 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d ABLE_EXPLAIN_COM
4210: 4d 45 4e 54 53 20 69 73 20 69 6e 63 6f 6d 70 61 MENTS is incompa
4220: 74 69 62 6c 65 20 77 69 74 68 20 53 51 4c 49 54 tible with SQLIT
4230: 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 2a E_OMIT_EXPLAIN.*
4240: 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
4250: 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 23 20 75 OMIT_EXPLAIN.# u
4260: 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 ndef SQLITE_ENAB
4270: 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 LE_EXPLAIN_COMME
4280: 4e 54 53 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a NTS.#endif../*.*
4290: 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 28 6e * Return true (n
42a0: 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 74 68 65 20 on-zero) if the
42b0: 69 6e 70 75 74 20 69 73 20 61 6e 20 69 6e 74 65 input is an inte
42c0: 67 65 72 20 74 68 61 74 20 69 73 20 74 6f 6f 20 ger that is too
42d0: 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 66 69 74 20 large.** to fit
42e0: 69 6e 20 33 32 2d 62 69 74 73 2e 20 20 54 68 69 in 32-bits. Thi
42f0: 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 s macro is used
4300: 69 6e 73 69 64 65 20 6f 66 20 76 61 72 69 6f 75 inside of variou
4310: 73 20 74 65 73 74 63 61 73 65 28 29 0a 2a 2a 20 s testcase().**
4320: 6d 61 63 72 6f 73 20 74 6f 20 76 65 72 69 66 79 macros to verify
4330: 20 74 68 61 74 20 77 65 20 68 61 76 65 20 74 65 that we have te
4340: 73 74 65 64 20 53 51 4c 69 74 65 20 66 6f 72 20 sted SQLite for
4350: 6c 61 72 67 65 2d 66 69 6c 65 20 73 75 70 70 6f large-file suppo
4360: 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 rt..*/.#define I
4370: 53 5f 42 49 47 5f 49 4e 54 28 58 29 20 20 28 28 S_BIG_INT(X) ((
4380: 28 58 29 26 7e 28 69 36 34 29 30 78 66 66 66 66 (X)&~(i64)0xffff
4390: 66 66 66 66 29 21 3d 30 29 0a 0a 2f 2a 0a 2a 2a ffff)!=0)../*.**
43a0: 20 54 68 65 20 6d 61 63 72 6f 20 75 6e 6c 69 6b The macro unlik
43b0: 65 6c 79 28 29 20 69 73 20 61 20 68 69 6e 74 20 ely() is a hint
43c0: 74 68 61 74 20 73 75 72 72 6f 75 6e 64 73 20 61 that surrounds a
43d0: 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 65 78 70 72 boolean.** expr
43e0: 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 20 75 ession that is u
43f0: 73 75 61 6c 6c 79 20 66 61 6c 73 65 2e 20 20 4d sually false. M
4400: 61 63 72 6f 20 6c 69 6b 65 6c 79 28 29 20 73 75 acro likely() su
4410: 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 20 62 6f 6f rrounds.** a boo
4420: 6c 65 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 lean expression
4430: 74 68 61 74 20 69 73 20 75 73 75 61 6c 6c 79 20 that is usually
4440: 74 72 75 65 2e 20 20 54 68 65 73 65 20 68 69 6e true. These hin
4450: 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a 20 69 6e 20 ts could,.** in
4460: 74 68 65 6f 72 79 2c 20 62 65 20 75 73 65 64 20 theory, be used
4470: 62 79 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 by the compiler
4480: 74 6f 20 67 65 6e 65 72 61 74 65 20 62 65 74 74 to generate bett
4490: 65 72 20 63 6f 64 65 2c 20 62 75 74 0a 2a 2a 20 er code, but.**
44a0: 63 75 72 72 65 6e 74 6c 79 20 74 68 65 79 20 61 currently they a
44b0: 72 65 20 6a 75 73 74 20 63 6f 6d 6d 65 6e 74 73 re just comments
44c0: 20 66 6f 72 20 68 75 6d 61 6e 20 72 65 61 64 65 for human reade
44d0: 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 6c rs..*/.#define l
44e0: 69 6b 65 6c 79 28 58 29 20 20 20 20 28 58 29 0a ikely(X) (X).
44f0: 23 64 65 66 69 6e 65 20 75 6e 6c 69 6b 65 6c 79 #define unlikely
4500: 28 58 29 20 20 28 58 29 0a 0a 23 69 6e 63 6c 75 (X) (X)..#inclu
4510: 64 65 20 22 68 61 73 68 2e 68 22 0a 23 69 6e 63 de "hash.h".#inc
4520: 6c 75 64 65 20 22 70 61 72 73 65 2e 68 22 0a 23 lude "parse.h".#
4530: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 include <stdio.h
4540: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c >.#include <stdl
4550: 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c ib.h>.#include <
4560: 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 string.h>.#inclu
4570: 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a 23 69 de <assert.h>.#i
4580: 6e 63 6c 75 64 65 20 3c 73 74 64 64 65 66 2e 68 nclude <stddef.h
4590: 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 63 6f 6d 70 >../*.** If comp
45a0: 69 6c 69 6e 67 20 66 6f 72 20 61 20 70 72 6f 63 iling for a proc
45b0: 65 73 73 6f 72 20 74 68 61 74 20 6c 61 63 6b 73 essor that lacks
45c0: 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e 74 20 floating point
45d0: 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 73 75 62 73 support,.** subs
45e0: 74 69 74 75 74 65 20 69 6e 74 65 67 65 72 20 66 titute integer f
45f0: 6f 72 20 66 6c 6f 61 74 69 6e 67 2d 70 6f 69 6e or floating-poin
4600: 74 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 t.*/.#ifdef SQLI
4610: 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 4e 47 TE_OMIT_FLOATING
4620: 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 6e 65 20 _POINT.# define
4630: 64 6f 75 62 6c 65 20 73 71 6c 69 74 65 5f 69 6e double sqlite_in
4640: 74 36 34 0a 23 20 64 65 66 69 6e 65 20 66 6c 6f t64.# define flo
4650: 61 74 20 73 71 6c 69 74 65 5f 69 6e 74 36 34 0a at sqlite_int64.
4660: 23 20 64 65 66 69 6e 65 20 4c 4f 4e 47 44 4f 55 # define LONGDOU
4670: 42 4c 45 5f 54 59 50 45 20 73 71 6c 69 74 65 5f BLE_TYPE sqlite_
4680: 69 6e 74 36 34 0a 23 20 69 66 6e 64 65 66 20 53 int64.# ifndef S
4690: 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 20 QLITE_BIG_DBL.#
46a0: 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f define SQLITE_
46b0: 42 49 47 5f 44 42 4c 20 28 28 28 73 71 6c 69 74 BIG_DBL (((sqlit
46c0: 65 33 5f 69 6e 74 36 34 29 31 29 3c 3c 35 30 29 e3_int64)1)<<50)
46d0: 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 66 69 6e .# endif.# defin
46e0: 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 44 41 e SQLITE_OMIT_DA
46f0: 54 45 54 49 4d 45 5f 46 55 4e 43 53 20 31 0a 23 TETIME_FUNCS 1.#
4700: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f define SQLITE_O
4710: 4d 49 54 5f 54 52 41 43 45 20 31 0a 23 20 75 6e MIT_TRACE 1.# un
4720: 64 65 66 20 53 51 4c 49 54 45 5f 4d 49 58 45 44 def SQLITE_MIXED
4730: 5f 45 4e 44 49 41 4e 5f 36 34 42 49 54 5f 46 4c _ENDIAN_64BIT_FL
4740: 4f 41 54 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 OAT.# undef SQLI
4750: 54 45 5f 48 41 56 45 5f 49 53 4e 41 4e 0a 23 65 TE_HAVE_ISNAN.#e
4760: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
4770: 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 20 64 65 ITE_BIG_DBL.# de
4780: 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 5f fine SQLITE_BIG_
4790: 44 42 4c 20 28 31 65 39 39 29 0a 23 65 6e 64 69 DBL (1e99).#endi
47a0: 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 54 5f 54 45 f../*.** OMIT_TE
47b0: 4d 50 44 42 20 69 73 20 73 65 74 20 74 6f 20 31 MPDB is set to 1
47c0: 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f if SQLITE_OMIT_
47d0: 54 45 4d 50 44 42 20 69 73 20 64 65 66 69 6e 65 TEMPDB is define
47e0: 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 66 74 65 72 d, or 0.** after
47f0: 77 61 72 64 2e 20 48 61 76 69 6e 67 20 74 68 69 ward. Having thi
4800: 73 20 6d 61 63 72 6f 20 61 6c 6c 6f 77 73 20 75 s macro allows u
4810: 73 20 74 6f 20 63 61 75 73 65 20 74 68 65 20 43 s to cause the C
4820: 20 63 6f 6d 70 69 6c 65 72 0a 2a 2a 20 74 6f 20 compiler.** to
4830: 6f 6d 69 74 20 63 6f 64 65 20 75 73 65 64 20 62 omit code used b
4840: 79 20 54 45 4d 50 20 74 61 62 6c 65 73 20 77 69 y TEMP tables wi
4850: 74 68 6f 75 74 20 6d 65 73 73 79 20 23 69 66 6e thout messy #ifn
4860: 64 65 66 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a def statements..
4870: 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
4880: 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 0a 23 64 65 _OMIT_TEMPDB.#de
4890: 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 42 fine OMIT_TEMPDB
48a0: 20 31 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 1.#else.#define
48b0: 20 4f 4d 49 54 5f 54 45 4d 50 44 42 20 30 0a 23 OMIT_TEMPDB 0.#
48c0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
48d0: 20 22 66 69 6c 65 20 66 6f 72 6d 61 74 22 20 6e "file format" n
48e0: 75 6d 62 65 72 20 69 73 20 61 6e 20 69 6e 74 65 umber is an inte
48f0: 67 65 72 20 74 68 61 74 20 69 73 20 69 6e 63 72 ger that is incr
4900: 65 6d 65 6e 74 65 64 20 77 68 65 6e 65 76 65 72 emented whenever
4910: 0a 2a 2a 20 74 68 65 20 56 44 42 45 2d 6c 65 76 .** the VDBE-lev
4920: 65 6c 20 66 69 6c 65 20 66 6f 72 6d 61 74 20 63 el file format c
4930: 68 61 6e 67 65 73 2e 20 20 54 68 65 20 66 6f 6c hanges. The fol
4940: 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 64 65 lowing macros de
4950: 66 69 6e 65 20 74 68 65 0a 2a 2a 20 74 68 65 20 fine the.** the
4960: 64 65 66 61 75 6c 74 20 66 69 6c 65 20 66 6f 72 default file for
4970: 6d 61 74 20 66 6f 72 20 6e 65 77 20 64 61 74 61 mat for new data
4980: 62 61 73 65 73 20 61 6e 64 20 74 68 65 20 6d 61 bases and the ma
4990: 78 69 6d 75 6d 20 66 69 6c 65 20 66 6f 72 6d 61 ximum file forma
49a0: 74 0a 2a 2a 20 74 68 61 74 20 74 68 65 20 6c 69 t.** that the li
49b0: 62 72 61 72 79 20 63 61 6e 20 72 65 61 64 2e 0a brary can read..
49c0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
49d0: 45 5f 4d 41 58 5f 46 49 4c 45 5f 46 4f 52 4d 41 E_MAX_FILE_FORMA
49e0: 54 20 34 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 T 4.#ifndef SQLI
49f0: 54 45 5f 44 45 46 41 55 4c 54 5f 46 49 4c 45 5f TE_DEFAULT_FILE_
4a00: 46 4f 52 4d 41 54 0a 23 20 64 65 66 69 6e 65 20 FORMAT.# define
4a10: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 46 SQLITE_DEFAULT_F
4a20: 49 4c 45 5f 46 4f 52 4d 41 54 20 34 0a 23 65 6e ILE_FORMAT 4.#en
4a30: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 65 72 dif../*.** Deter
4a40: 6d 69 6e 65 20 77 68 65 74 68 65 72 20 74 72 69 mine whether tri
4a50: 67 67 65 72 73 20 61 72 65 20 72 65 63 75 72 73 ggers are recurs
4a60: 69 76 65 20 62 79 20 64 65 66 61 75 6c 74 2e 20 ive by default.
4a70: 20 54 68 69 73 20 63 61 6e 20 62 65 0a 2a 2a 20 This can be.**
4a80: 63 68 61 6e 67 65 64 20 61 74 20 72 75 6e 2d 74 changed at run-t
4a90: 69 6d 65 20 75 73 69 6e 67 20 61 20 70 72 61 67 ime using a prag
4aa0: 6d 61 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ma..*/.#ifndef S
4ab0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 QLITE_DEFAULT_RE
4ac0: 43 55 52 53 49 56 45 5f 54 52 49 47 47 45 52 53 CURSIVE_TRIGGERS
4ad0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
4ae0: 5f 44 45 46 41 55 4c 54 5f 52 45 43 55 52 53 49 _DEFAULT_RECURSI
4af0: 56 45 5f 54 52 49 47 47 45 52 53 20 30 0a 23 65 VE_TRIGGERS 0.#e
4b00: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 72 6f 76 ndif../*.** Prov
4b10: 69 64 65 20 61 20 64 65 66 61 75 6c 74 20 76 61 ide a default va
4b20: 6c 75 65 20 66 6f 72 20 53 51 4c 49 54 45 5f 54 lue for SQLITE_T
4b30: 45 4d 50 5f 53 54 4f 52 45 20 69 6e 20 63 61 73 EMP_STORE in cas
4b40: 65 20 69 74 20 69 73 20 6e 6f 74 20 73 70 65 63 e it is not spec
4b50: 69 66 69 65 64 0a 2a 2a 20 6f 6e 20 74 68 65 20 ified.** on the
4b60: 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 0a 2a 2f 0a command-line.*/.
4b70: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 54 #ifndef SQLITE_T
4b80: 45 4d 50 5f 53 54 4f 52 45 0a 23 20 64 65 66 69 EMP_STORE.# defi
4b90: 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 ne SQLITE_TEMP_S
4ba0: 54 4f 52 45 20 31 0a 23 20 64 65 66 69 6e 65 20 TORE 1.# define
4bb0: 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 SQLITE_TEMP_STOR
4bc0: 45 5f 78 63 20 31 20 20 2f 2a 20 45 78 63 6c 75 E_xc 1 /* Exclu
4bd0: 64 65 20 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 de from ctime.c
4be0: 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a */.#endif../*.**
4bf0: 20 49 66 20 6e 6f 20 76 61 6c 75 65 20 68 61 73 If no value has
4c00: 20 62 65 65 6e 20 70 72 6f 76 69 64 65 64 20 66 been provided f
4c10: 6f 72 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f or SQLITE_MAX_WO
4c20: 52 4b 45 52 5f 54 48 52 45 41 44 53 2c 20 6f 72 RKER_THREADS, or
4c30: 20 69 66 0a 2a 2a 20 53 51 4c 49 54 45 5f 54 45 if.** SQLITE_TE
4c40: 4d 50 5f 53 54 4f 52 45 20 69 73 20 73 65 74 20 MP_STORE is set
4c50: 74 6f 20 33 20 28 6e 65 76 65 72 20 75 73 65 20 to 3 (never use
4c60: 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 73 29 temporary files)
4c70: 2c 20 73 65 74 20 69 74 0a 2a 2a 20 74 6f 20 7a , set it.** to z
4c80: 65 72 6f 2e 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 ero..*/.#if SQLI
4c90: 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 3d 3d 33 TE_TEMP_STORE==3
4ca0: 20 7c 7c 20 53 51 4c 49 54 45 5f 54 48 52 45 41 || SQLITE_THREA
4cb0: 44 53 41 46 45 3d 3d 30 0a 23 20 75 6e 64 65 66 DSAFE==0.# undef
4cc0: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b SQLITE_MAX_WORK
4cd0: 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 66 ER_THREADS.# def
4ce0: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 ine SQLITE_MAX_W
4cf0: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 20 30 0a ORKER_THREADS 0.
4d00: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
4d10: 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
4d20: 5f 54 48 52 45 41 44 53 0a 23 20 64 65 66 69 6e _THREADS.# defin
4d30: 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 e SQLITE_MAX_WOR
4d40: 4b 45 52 5f 54 48 52 45 41 44 53 20 38 0a 23 65 KER_THREADS 8.#e
4d50: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
4d60: 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f 52 4b ITE_DEFAULT_WORK
4d70: 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 66 ER_THREADS.# def
4d80: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
4d90: 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 LT_WORKER_THREAD
4da0: 53 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 20 53 S 0.#endif.#if S
4db0: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f QLITE_DEFAULT_WO
4dc0: 52 4b 45 52 5f 54 48 52 45 41 44 53 3e 53 51 4c RKER_THREADS>SQL
4dd0: 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 5f 54 ITE_MAX_WORKER_T
4de0: 48 52 45 41 44 53 0a 23 20 75 6e 64 65 66 20 53 HREADS.# undef S
4df0: 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 52 QLITE_MAX_WORKER
4e00: 5f 54 48 52 45 41 44 53 0a 23 20 64 65 66 69 6e _THREADS.# defin
4e10: 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 e SQLITE_MAX_WOR
4e20: 4b 45 52 5f 54 48 52 45 41 44 53 20 53 51 4c 49 KER_THREADS SQLI
4e30: 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f 52 4b 45 TE_DEFAULT_WORKE
4e40: 52 5f 54 48 52 45 41 44 53 0a 23 65 6e 64 69 66 R_THREADS.#endif
4e50: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 65 66 61 ../*.** The defa
4e60: 75 6c 74 20 69 6e 69 74 69 61 6c 20 61 6c 6c 6f ult initial allo
4e70: 63 61 74 69 6f 6e 20 66 6f 72 20 74 68 65 20 70 cation for the p
4e80: 61 67 65 63 61 63 68 65 20 77 68 65 6e 20 75 73 agecache when us
4e90: 69 6e 67 20 73 65 70 61 72 61 74 65 0a 2a 2a 20 ing separate.**
4ea0: 70 61 67 65 63 61 63 68 65 73 20 66 6f 72 20 65 pagecaches for e
4eb0: 61 63 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e ach database con
4ec0: 6e 65 63 74 69 6f 6e 2e 20 20 41 20 70 6f 73 69 nection. A posi
4ed0: 74 69 76 65 20 6e 75 6d 62 65 72 20 69 73 20 74 tive number is t
4ee0: 68 65 0a 2a 2a 20 6e 75 6d 62 65 72 20 6f 66 20 he.** number of
4ef0: 70 61 67 65 73 2e 20 20 41 20 6e 65 67 61 74 69 pages. A negati
4f00: 76 65 20 6e 75 6d 62 65 72 20 4e 20 74 72 61 6e ve number N tran
4f10: 73 6c 61 74 69 6f 6e 73 20 6d 65 61 6e 73 20 74 slations means t
4f20: 68 61 74 20 61 20 62 75 66 66 65 72 0a 2a 2a 20 hat a buffer.**
4f30: 6f 66 20 2d 31 30 32 34 2a 4e 20 62 79 74 65 73 of -1024*N bytes
4f40: 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 20 61 6e is allocated an
4f50: 64 20 75 73 65 64 20 66 6f 72 20 61 73 20 6d 61 d used for as ma
4f60: 6e 79 20 70 61 67 65 73 20 61 73 20 69 74 20 77 ny pages as it w
4f70: 69 6c 6c 20 68 6f 6c 64 2e 0a 2a 2a 0a 2a 2a 20 ill hold..**.**
4f80: 54 68 65 20 64 65 66 61 75 6c 74 20 76 61 6c 75 The default valu
4f90: 65 20 6f 66 20 22 32 30 22 20 77 61 73 20 63 68 e of "20" was ch
4fa0: 6f 6f 73 65 6e 20 74 6f 20 6d 69 6e 69 6d 69 7a oosen to minimiz
4fb0: 65 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 20 6f e the run-time o
4fc0: 66 20 74 68 65 0a 2a 2a 20 73 70 65 65 64 74 65 f the.** speedte
4fd0: 73 74 31 20 74 65 73 74 20 70 72 6f 67 72 61 6d st1 test program
4fe0: 20 77 69 74 68 20 6f 70 74 69 6f 6e 73 3a 20 2d with options: -
4ff0: 2d 73 68 72 69 6e 6b 2d 6d 65 6d 6f 72 79 20 2d -shrink-memory -
5000: 2d 72 65 70 72 65 70 61 72 65 0a 2a 2f 0a 23 69 -reprepare.*/.#i
5010: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 45 46 fndef SQLITE_DEF
5020: 41 55 4c 54 5f 50 43 41 43 48 45 5f 49 4e 49 54 AULT_PCACHE_INIT
5030: 53 5a 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 SZ.# define SQLI
5040: 54 45 5f 44 45 46 41 55 4c 54 5f 50 43 41 43 48 TE_DEFAULT_PCACH
5050: 45 5f 49 4e 49 54 53 5a 20 32 30 0a 23 65 6e 64 E_INITSZ 20.#end
5060: 69 66 0a 0a 2f 2a 0a 2a 2a 20 47 43 43 20 64 6f if../*.** GCC do
5070: 65 73 20 6e 6f 74 20 64 65 66 69 6e 65 20 74 68 es not define th
5080: 65 20 6f 66 66 73 65 74 6f 66 28 29 20 6d 61 63 e offsetof() mac
5090: 72 6f 20 73 6f 20 77 65 27 6c 6c 20 68 61 76 65 ro so we'll have
50a0: 20 74 6f 20 64 6f 20 69 74 0a 2a 2a 20 6f 75 72 to do it.** our
50b0: 73 65 6c 76 65 73 2e 0a 2a 2f 0a 23 69 66 6e 64 selves..*/.#ifnd
50c0: 65 66 20 6f 66 66 73 65 74 6f 66 0a 23 64 65 66 ef offsetof.#def
50d0: 69 6e 65 20 6f 66 66 73 65 74 6f 66 28 53 54 52 ine offsetof(STR
50e0: 55 43 54 55 52 45 2c 46 49 45 4c 44 29 20 28 28 UCTURE,FIELD) ((
50f0: 69 6e 74 29 28 28 63 68 61 72 2a 29 26 28 28 53 int)((char*)&((S
5100: 54 52 55 43 54 55 52 45 2a 29 30 29 2d 3e 46 49 TRUCTURE*)0)->FI
5110: 45 4c 44 29 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a ELD)).#endif../*
5120: 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 63 6f .** Macros to co
5130: 6d 70 75 74 65 20 6d 69 6e 69 6d 75 6d 20 61 6e mpute minimum an
5140: 64 20 6d 61 78 69 6d 75 6d 20 6f 66 20 74 77 6f d maximum of two
5150: 20 6e 75 6d 62 65 72 73 2e 0a 2a 2f 0a 23 69 66 numbers..*/.#if
5160: 6e 64 65 66 20 4d 49 4e 0a 23 20 64 65 66 69 6e ndef MIN.# defin
5170: 65 20 4d 49 4e 28 41 2c 42 29 20 28 28 41 29 3c e MIN(A,B) ((A)<
5180: 28 42 29 3f 28 41 29 3a 28 42 29 29 0a 23 65 6e (B)?(A):(B)).#en
5190: 64 69 66 0a 23 69 66 6e 64 65 66 20 4d 41 58 0a dif.#ifndef MAX.
51a0: 23 20 64 65 66 69 6e 65 20 4d 41 58 28 41 2c 42 # define MAX(A,B
51b0: 29 20 28 28 41 29 3e 28 42 29 3f 28 41 29 3a 28 ) ((A)>(B)?(A):(
51c0: 42 29 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a B)).#endif../*.*
51d0: 2a 20 53 77 61 70 20 74 77 6f 20 6f 62 6a 65 63 * Swap two objec
51e0: 74 73 20 6f 66 20 74 79 70 65 20 54 59 50 45 2e ts of type TYPE.
51f0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 57 41 50 .*/.#define SWAP
5200: 28 54 59 50 45 2c 41 2c 42 29 20 7b 54 59 50 45 (TYPE,A,B) {TYPE
5210: 20 74 3d 41 3b 20 41 3d 42 3b 20 42 3d 74 3b 7d t=A; A=B; B=t;}
5220: 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63 6b 20 74 6f ../*.** Check to
5230: 20 73 65 65 20 69 66 20 74 68 69 73 20 6d 61 63 see if this mac
5240: 68 69 6e 65 20 75 73 65 73 20 45 42 43 44 49 43 hine uses EBCDIC
5250: 2e 20 20 28 59 65 73 2c 20 62 65 6c 69 65 76 65 . (Yes, believe
5260: 20 69 74 20 6f 72 0a 2a 2a 20 6e 6f 74 2c 20 74 it or.** not, t
5270: 68 65 72 65 20 61 72 65 20 73 74 69 6c 6c 20 6d here are still m
5280: 61 63 68 69 6e 65 73 20 6f 75 74 20 74 68 65 72 achines out ther
5290: 65 20 74 68 61 74 20 75 73 65 20 45 42 43 44 49 e that use EBCDI
52a0: 43 2e 29 0a 2a 2f 0a 23 69 66 20 27 41 27 20 3d C.).*/.#if 'A' =
52b0: 3d 20 27 5c 33 30 31 27 0a 23 20 64 65 66 69 6e = '\301'.# defin
52c0: 65 20 53 51 4c 49 54 45 5f 45 42 43 44 49 43 20 e SQLITE_EBCDIC
52d0: 31 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 1.#else.# define
52e0: 20 53 51 4c 49 54 45 5f 41 53 43 49 49 20 31 0a SQLITE_ASCII 1.
52f0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e #endif../*.** In
5300: 74 65 67 65 72 73 20 6f 66 20 6b 6e 6f 77 6e 20 tegers of known
5310: 73 69 7a 65 73 2e 20 20 54 68 65 73 65 20 74 79 sizes. These ty
5320: 70 65 64 65 66 73 20 6d 69 67 68 74 20 63 68 61 pedefs might cha
5330: 6e 67 65 20 66 6f 72 20 61 72 63 68 69 74 65 63 nge for architec
5340: 74 75 72 65 73 0a 2a 2a 20 77 68 65 72 65 20 74 tures.** where t
5350: 68 65 20 73 69 7a 65 73 20 76 65 72 79 2e 20 20 he sizes very.
5360: 50 72 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 Preprocessor mac
5370: 72 6f 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c ros are availabl
5380: 65 20 73 6f 20 74 68 61 74 20 74 68 65 0a 2a 2a e so that the.**
5390: 20 74 79 70 65 73 20 63 61 6e 20 62 65 20 63 6f types can be co
53a0: 6e 76 65 6e 69 65 6e 74 6c 79 20 72 65 64 65 66 nveniently redef
53b0: 69 6e 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d ined at compile-
53c0: 74 79 70 65 2e 20 20 4c 69 6b 65 20 74 68 69 73 type. Like this
53d0: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 20 20 20 :.**.**
53e0: 63 63 20 27 2d 44 55 49 4e 54 50 54 52 5f 54 59 cc '-DUINTPTR_TY
53f0: 50 45 3d 6c 6f 6e 67 20 6c 6f 6e 67 20 69 6e 74 PE=long long int
5400: 27 20 2e 2e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 ' ....*/.#ifndef
5410: 20 55 49 4e 54 33 32 5f 54 59 50 45 0a 23 20 69 UINT32_TYPE.# i
5420: 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 33 32 fdef HAVE_UINT32
5430: 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e _T.# define UIN
5440: 54 33 32 5f 54 59 50 45 20 75 69 6e 74 33 32 5f T32_TYPE uint32_
5450: 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 t.# else.# defi
5460: 6e 65 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 ne UINT32_TYPE u
5470: 6e 73 69 67 6e 65 64 20 69 6e 74 0a 23 20 65 6e nsigned int.# en
5480: 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 dif.#endif.#ifnd
5490: 65 66 20 55 49 4e 54 31 36 5f 54 59 50 45 0a 23 ef UINT16_TYPE.#
54a0: 20 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e 54 ifdef HAVE_UINT
54b0: 31 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 16_T.# define U
54c0: 49 4e 54 31 36 5f 54 59 50 45 20 75 69 6e 74 31 INT16_TYPE uint1
54d0: 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 6_t.# else.# de
54e0: 66 69 6e 65 20 55 49 4e 54 31 36 5f 54 59 50 45 fine UINT16_TYPE
54f0: 20 75 6e 73 69 67 6e 65 64 20 73 68 6f 72 74 20 unsigned short
5500: 69 6e 74 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 int.# endif.#end
5510: 69 66 0a 23 69 66 6e 64 65 66 20 49 4e 54 31 36 if.#ifndef INT16
5520: 5f 54 59 50 45 0a 23 20 69 66 64 65 66 20 48 41 _TYPE.# ifdef HA
5530: 56 45 5f 49 4e 54 31 36 5f 54 0a 23 20 20 64 65 VE_INT16_T.# de
5540: 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 fine INT16_TYPE
5550: 69 6e 74 31 36 5f 74 0a 23 20 65 6c 73 65 0a 23 int16_t.# else.#
5560: 20 20 64 65 66 69 6e 65 20 49 4e 54 31 36 5f 54 define INT16_T
5570: 59 50 45 20 73 68 6f 72 74 20 69 6e 74 0a 23 20 YPE short int.#
5580: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 endif.#endif.#if
5590: 6e 64 65 66 20 55 49 4e 54 38 5f 54 59 50 45 0a ndef UINT8_TYPE.
55a0: 23 20 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e # ifdef HAVE_UIN
55b0: 54 38 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 55 T8_T.# define U
55c0: 49 4e 54 38 5f 54 59 50 45 20 75 69 6e 74 38 5f INT8_TYPE uint8_
55d0: 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 t.# else.# defi
55e0: 6e 65 20 55 49 4e 54 38 5f 54 59 50 45 20 75 6e ne UINT8_TYPE un
55f0: 73 69 67 6e 65 64 20 63 68 61 72 0a 23 20 65 6e signed char.# en
5600: 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 dif.#endif.#ifnd
5610: 65 66 20 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 ef INT8_TYPE.# i
5620: 66 64 65 66 20 48 41 56 45 5f 49 4e 54 38 5f 54 fdef HAVE_INT8_T
5630: 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f .# define INT8_
5640: 54 59 50 45 20 69 6e 74 38 5f 74 0a 23 20 65 6c TYPE int8_t.# el
5650: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 se.# define INT
5660: 38 5f 54 59 50 45 20 73 69 67 6e 65 64 20 63 68 8_TYPE signed ch
5670: 61 72 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 ar.# endif.#endi
5680: 66 0a 23 69 66 6e 64 65 66 20 4c 4f 4e 47 44 4f f.#ifndef LONGDO
5690: 55 42 4c 45 5f 54 59 50 45 0a 23 20 64 65 66 69 UBLE_TYPE.# defi
56a0: 6e 65 20 4c 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 ne LONGDOUBLE_TY
56b0: 50 45 20 6c 6f 6e 67 20 64 6f 75 62 6c 65 0a 23 PE long double.#
56c0: 65 6e 64 69 66 0a 74 79 70 65 64 65 66 20 73 71 endif.typedef sq
56d0: 6c 69 74 65 5f 69 6e 74 36 34 20 69 36 34 3b 20 lite_int64 i64;
56e0: 20 20 20 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 /* 8-by
56f0: 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 te signed intege
5700: 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 73 71 6c r */.typedef sql
5710: 69 74 65 5f 75 69 6e 74 36 34 20 75 36 34 3b 20 ite_uint64 u64;
5720: 20 20 20 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 /* 8-byt
5730: 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 e unsigned integ
5740: 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 er */.typedef UI
5750: 4e 54 33 32 5f 54 59 50 45 20 75 33 32 3b 20 20 NT32_TYPE u32;
5760: 20 20 20 20 20 20 20 20 20 2f 2a 20 34 2d 62 79 /* 4-by
5770: 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 te unsigned inte
5780: 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 ger */.typedef U
5790: 49 4e 54 31 36 5f 54 59 50 45 20 75 31 36 3b 20 INT16_TYPE u16;
57a0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 /* 2-b
57b0: 79 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 yte unsigned int
57c0: 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 eger */.typedef
57d0: 49 4e 54 31 36 5f 54 59 50 45 20 69 31 36 3b 20 INT16_TYPE i16;
57e0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 32 2d /* 2-
57f0: 62 79 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 byte signed inte
5800: 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 55 ger */.typedef U
5810: 49 4e 54 38 5f 54 59 50 45 20 75 38 3b 20 20 20 INT8_TYPE u8;
5820: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 /* 1-b
5830: 79 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 yte unsigned int
5840: 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 eger */.typedef
5850: 49 4e 54 38 5f 54 59 50 45 20 69 38 3b 20 20 20 INT8_TYPE i8;
5860: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 2d /* 1-
5870: 62 79 74 65 20 73 69 67 6e 65 64 20 69 6e 74 65 byte signed inte
5880: 67 65 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 53 51 ger */../*.** SQ
5890: 4c 49 54 45 5f 4d 41 58 5f 55 33 32 20 69 73 20 LITE_MAX_U32 is
58a0: 61 20 75 36 34 20 63 6f 6e 73 74 61 6e 74 20 74 a u64 constant t
58b0: 68 61 74 20 69 73 20 74 68 65 20 6d 61 78 69 6d hat is the maxim
58c0: 75 6d 20 75 36 34 20 76 61 6c 75 65 0a 2a 2a 20 um u64 value.**
58d0: 74 68 61 74 20 63 61 6e 20 62 65 20 73 74 6f 72 that can be stor
58e0: 65 64 20 69 6e 20 61 20 75 33 32 20 77 69 74 68 ed in a u32 with
58f0: 6f 75 74 20 6c 6f 73 73 20 6f 66 20 64 61 74 61 out loss of data
5900: 2e 20 20 54 68 65 20 76 61 6c 75 65 0a 2a 2a 20 . The value.**
5910: 69 73 20 30 78 30 30 30 30 30 30 30 30 66 66 66 is 0x00000000fff
5920: 66 66 66 66 66 2e 20 20 42 75 74 20 62 65 63 61 fffff. But beca
5930: 75 73 65 20 6f 66 20 71 75 69 72 6b 73 20 6f 66 use of quirks of
5940: 20 73 6f 6d 65 20 63 6f 6d 70 69 6c 65 72 73 2c some compilers,
5950: 20 77 65 0a 2a 2a 20 68 61 76 65 20 74 6f 20 73 we.** have to s
5960: 70 65 63 69 66 79 20 74 68 65 20 76 61 6c 75 65 pecify the value
5970: 20 69 6e 20 74 68 65 20 6c 65 73 73 20 69 6e 74 in the less int
5980: 75 69 74 69 76 65 20 6d 61 6e 6e 65 72 20 73 68 uitive manner sh
5990: 6f 77 6e 3a 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 own:.*/.#define
59a0: 53 51 4c 49 54 45 5f 4d 41 58 5f 55 33 32 20 20 SQLITE_MAX_U32
59b0: 28 28 28 28 75 36 34 29 31 29 3c 3c 33 32 29 2d ((((u64)1)<<32)-
59c0: 31 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 1)../*.** The da
59d0: 74 61 74 79 70 65 20 75 73 65 64 20 74 6f 20 73 tatype used to s
59e0: 74 6f 72 65 20 65 73 74 69 6d 61 74 65 73 20 6f tore estimates o
59f0: 66 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 f the number of
5a00: 72 6f 77 73 20 69 6e 20 61 0a 2a 2a 20 74 61 62 rows in a.** tab
5a10: 6c 65 20 6f 72 20 69 6e 64 65 78 2e 20 20 54 68 le or index. Th
5a20: 69 73 20 69 73 20 61 6e 20 75 6e 73 69 67 6e 65 is is an unsigne
5a30: 64 20 69 6e 74 65 67 65 72 20 74 79 70 65 2e 20 d integer type.
5a40: 20 46 6f 72 20 39 39 2e 39 25 20 6f 66 0a 2a 2a For 99.9% of.**
5a50: 20 74 68 65 20 77 6f 72 6c 64 2c 20 61 20 33 32 the world, a 32
5a60: 2d 62 69 74 20 69 6e 74 65 67 65 72 20 69 73 20 -bit integer is
5a70: 73 75 66 66 69 63 69 65 6e 74 2e 20 20 42 75 74 sufficient. But
5a80: 20 61 20 36 34 2d 62 69 74 20 69 6e 74 65 67 65 a 64-bit intege
5a90: 72 0a 2a 2a 20 63 61 6e 20 62 65 20 75 73 65 64 r.** can be used
5aa0: 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 at compile-time
5ab0: 20 69 66 20 64 65 73 69 72 65 64 2e 0a 2a 2f 0a if desired..*/.
5ac0: 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 36 34 #ifdef SQLITE_64
5ad0: 42 49 54 5f 53 54 41 54 53 0a 20 74 79 70 65 64 BIT_STATS. typed
5ae0: 65 66 20 75 36 34 20 74 52 6f 77 63 6e 74 3b 20 ef u64 tRowcnt;
5af0: 20 20 20 2f 2a 20 36 34 2d 62 69 74 20 6f 6e 6c /* 64-bit onl
5b00: 79 20 69 66 20 72 65 71 75 65 73 74 65 64 20 61 y if requested a
5b10: 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 2a t compile-time *
5b20: 2f 0a 23 65 6c 73 65 0a 20 74 79 70 65 64 65 66 /.#else. typedef
5b30: 20 75 33 32 20 74 52 6f 77 63 6e 74 3b 20 20 20 u32 tRowcnt;
5b40: 20 2f 2a 20 33 32 2d 62 69 74 20 69 73 20 74 68 /* 32-bit is th
5b50: 65 20 64 65 66 61 75 6c 74 20 2a 2f 0a 23 65 6e e default */.#en
5b60: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 73 74 69 6d dif../*.** Estim
5b70: 61 74 65 64 20 71 75 61 6e 74 69 74 69 65 73 20 ated quantities
5b80: 75 73 65 64 20 66 6f 72 20 71 75 65 72 79 20 70 used for query p
5b90: 6c 61 6e 6e 69 6e 67 20 61 72 65 20 73 74 6f 72 lanning are stor
5ba0: 65 64 20 61 73 20 31 36 2d 62 69 74 0a 2a 2a 20 ed as 16-bit.**
5bb0: 6c 6f 67 61 72 69 74 68 6d 73 2e 20 20 46 6f 72 logarithms. For
5bc0: 20 71 75 61 6e 74 69 74 79 20 58 2c 20 74 68 65 quantity X, the
5bd0: 20 76 61 6c 75 65 20 73 74 6f 72 65 64 20 69 73 value stored is
5be0: 20 31 30 2a 6c 6f 67 32 28 58 29 2e 20 20 54 68 10*log2(X). Th
5bf0: 69 73 0a 2a 2a 20 67 69 76 65 73 20 61 20 70 6f is.** gives a po
5c00: 73 73 69 62 6c 65 20 72 61 6e 67 65 20 6f 66 20 ssible range of
5c10: 76 61 6c 75 65 73 20 6f 66 20 61 70 70 72 6f 78 values of approx
5c20: 69 6d 61 74 65 6c 79 20 31 2e 30 65 39 38 36 20 imately 1.0e986
5c30: 74 6f 20 31 65 2d 39 38 36 2e 0a 2a 2a 20 42 75 to 1e-986..** Bu
5c40: 74 20 74 68 65 20 61 6c 6c 6f 77 65 64 20 76 61 t the allowed va
5c50: 6c 75 65 73 20 61 72 65 20 22 67 72 61 69 6e 79 lues are "grainy
5c60: 22 2e 20 20 4e 6f 74 20 65 76 65 72 79 20 76 61 ". Not every va
5c70: 6c 75 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 lue is represent
5c80: 61 62 6c 65 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 able..** For exa
5c90: 6d 70 6c 65 2c 20 71 75 61 6e 74 69 74 69 65 73 mple, quantities
5ca0: 20 31 36 20 61 6e 64 20 31 37 20 61 72 65 20 62 16 and 17 are b
5cb0: 6f 74 68 20 72 65 70 72 65 73 65 6e 74 65 64 20 oth represented
5cc0: 62 79 20 61 20 4c 6f 67 45 73 74 0a 2a 2a 20 6f by a LogEst.** o
5cd0: 66 20 34 30 2e 20 20 48 6f 77 65 76 65 72 2c 20 f 40. However,
5ce0: 73 69 6e 63 65 20 4c 6f 67 45 73 74 20 71 75 61 since LogEst qua
5cf0: 6e 74 69 74 69 65 73 20 61 72 65 20 73 75 70 70 ntities are supp
5d00: 6f 73 65 20 74 6f 20 62 65 20 65 73 74 69 6d 61 ose to be estima
5d10: 74 65 73 2c 0a 2a 2a 20 6e 6f 74 20 65 78 61 63 tes,.** not exac
5d20: 74 20 76 61 6c 75 65 73 2c 20 74 68 69 73 20 69 t values, this i
5d30: 6d 70 72 65 63 69 73 69 6f 6e 20 69 73 20 6e 6f mprecision is no
5d40: 74 20 61 20 70 72 6f 62 6c 65 6d 2e 0a 2a 2a 0a t a problem..**.
5d50: 2a 2a 20 22 4c 6f 67 45 73 74 22 20 69 73 20 73 ** "LogEst" is s
5d60: 68 6f 72 74 20 66 6f 72 20 22 4c 6f 67 61 72 69 hort for "Logari
5d70: 74 68 6d 69 63 20 45 73 74 69 6d 61 74 65 22 2e thmic Estimate".
5d80: 0a 2a 2a 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 3a .**.** Examples:
5d90: 0a 2a 2a 20 20 20 20 20 20 31 20 2d 3e 20 30 20 .** 1 -> 0
5da0: 20 20 20 20 20 20 20 20 20 20 20 20 20 32 30 20 20
5db0: 2d 3e 20 34 33 20 20 20 20 20 20 20 20 20 20 31 -> 43 1
5dc0: 30 30 30 30 20 2d 3e 20 31 33 32 0a 2a 2a 20 20 0000 -> 132.**
5dd0: 20 20 20 20 32 20 2d 3e 20 31 30 20 20 20 20 20 2 -> 10
5de0: 20 20 20 20 20 20 20 20 32 35 20 2d 3e 20 34 36 25 -> 46
5df0: 20 20 20 20 20 20 20 20 20 20 32 35 30 30 30 20 25000
5e00: 2d 3e 20 31 34 36 0a 2a 2a 20 20 20 20 20 20 33 -> 146.** 3
5e10: 20 2d 3e 20 31 36 20 20 20 20 20 20 20 20 20 20 -> 16
5e20: 20 20 31 30 30 20 2d 3e 20 36 36 20 20 20 20 20 100 -> 66
5e30: 20 20 20 31 30 30 30 30 30 30 20 2d 3e 20 31 39 1000000 -> 19
5e40: 39 0a 2a 2a 20 20 20 20 20 20 34 20 2d 3e 20 32 9.** 4 -> 2
5e50: 30 20 20 20 20 20 20 20 20 20 20 20 31 30 30 30 0 1000
5e60: 20 2d 3e 20 39 39 20 20 20 20 20 20 20 20 31 30 -> 99 10
5e70: 34 38 35 37 36 20 2d 3e 20 32 30 30 0a 2a 2a 20 48576 -> 200.**
5e80: 20 20 20 20 31 30 20 2d 3e 20 33 33 20 20 20 20 10 -> 33
5e90: 20 20 20 20 20 20 20 31 30 32 34 20 2d 3e 20 31 1024 -> 1
5ea0: 30 30 20 20 20 20 34 32 39 34 39 36 37 32 39 36 00 4294967296
5eb0: 20 2d 3e 20 33 32 30 0a 2a 2a 0a 2a 2a 20 54 68 -> 320.**.** Th
5ec0: 65 20 4c 6f 67 45 73 74 20 63 61 6e 20 62 65 20 e LogEst can be
5ed0: 6e 65 67 61 74 69 76 65 20 74 6f 20 69 6e 64 69 negative to indi
5ee0: 63 61 74 65 20 66 72 61 63 74 69 6f 6e 61 6c 20 cate fractional
5ef0: 76 61 6c 75 65 73 2e 0a 2a 2a 20 45 78 61 6d 70 values..** Examp
5f00: 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 30 2e les:.**.** 0.
5f10: 35 20 2d 3e 20 2d 31 30 20 20 20 20 20 20 20 20 5 -> -10
5f20: 20 20 20 30 2e 31 20 2d 3e 20 2d 33 33 20 20 20 0.1 -> -33
5f30: 20 20 20 20 20 30 2e 30 36 32 35 20 2d 3e 20 2d 0.0625 -> -
5f40: 34 30 0a 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 40.*/.typedef IN
5f50: 54 31 36 5f 54 59 50 45 20 4c 6f 67 45 73 74 3b T16_TYPE LogEst;
5f60: 0a 0a 2f 2a 0a 2a 2a 20 53 65 74 20 74 68 65 20 ../*.** Set the
5f70: 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 6d SQLITE_PTRSIZE m
5f80: 61 63 72 6f 20 74 6f 20 74 68 65 20 6e 75 6d 62 acro to the numb
5f90: 65 72 20 6f 66 20 62 79 74 65 73 20 69 6e 20 61 er of bytes in a
5fa0: 20 70 6f 69 6e 74 65 72 0a 2a 2f 0a 23 69 66 6e pointer.*/.#ifn
5fb0: 64 65 66 20 53 51 4c 49 54 45 5f 50 54 52 53 49 def SQLITE_PTRSI
5fc0: 5a 45 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 ZE.# if defined(
5fd0: 5f 5f 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 __SIZEOF_POINTER
5fe0: 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 __).# define S
5ff0: 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 5f 5f QLITE_PTRSIZE __
6000: 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 52 5f 5f SIZEOF_POINTER__
6010: 0a 23 20 65 6c 69 66 20 64 65 66 69 6e 65 64 28 .# elif defined(
6020: 69 33 38 36 29 20 20 20 20 20 7c 7c 20 64 65 66 i386) || def
6030: 69 6e 65 64 28 5f 5f 69 33 38 36 5f 5f 29 20 20 ined(__i386__)
6040: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 || defined(_M_I
6050: 58 38 36 29 20 7c 7c 20 20 20 20 5c 0a 20 20 20 X86) || \.
6060: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 defined(_M_A
6070: 52 4d 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 RM) || defined
6080: 28 5f 5f 61 72 6d 5f 5f 29 20 20 20 20 7c 7c 20 (__arm__) ||
6090: 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 29 0a 23 defined(__x86).#
60a0: 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 define SQLITE
60b0: 5f 50 54 52 53 49 5a 45 20 34 0a 23 20 65 6c 73 _PTRSIZE 4.# els
60c0: 65 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c e.# define SQL
60d0: 49 54 45 5f 50 54 52 53 49 5a 45 20 38 0a 23 20 ITE_PTRSIZE 8.#
60e0: 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a endif.#endif../*
60f0: 20 54 68 65 20 75 70 74 72 20 74 79 70 65 20 69 The uptr type i
6100: 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 20 69 6e s an unsigned in
6110: 74 65 67 65 72 20 6c 61 72 67 65 20 65 6e 6f 75 teger large enou
6120: 67 68 20 74 6f 20 68 6f 6c 64 20 61 20 70 6f 69 gh to hold a poi
6130: 6e 74 65 72 0a 2a 2f 0a 23 69 66 20 64 65 66 69 nter.*/.#if defi
6140: 6e 65 64 28 48 41 56 45 5f 53 54 44 49 4e 54 5f ned(HAVE_STDINT_
6150: 48 29 0a 20 20 74 79 70 65 64 65 66 20 75 69 6e H). typedef uin
6160: 74 70 74 72 5f 74 20 75 70 74 72 3b 0a 23 65 6c tptr_t uptr;.#el
6170: 69 66 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a if SQLITE_PTRSIZ
6180: 45 3d 3d 34 0a 20 20 74 79 70 65 64 65 66 20 75 E==4. typedef u
6190: 33 32 20 75 70 74 72 3b 0a 23 65 6c 73 65 0a 20 32 uptr;.#else.
61a0: 20 74 79 70 65 64 65 66 20 75 36 34 20 75 70 74 typedef u64 upt
61b0: 72 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a r;.#endif../*.**
61c0: 20 54 68 65 20 53 51 4c 49 54 45 5f 57 49 54 48 The SQLITE_WITH
61d0: 49 4e 28 50 2c 53 2c 45 29 20 6d 61 63 72 6f 20 IN(P,S,E) macro
61e0: 63 68 65 63 6b 73 20 74 6f 20 73 65 65 20 69 66 checks to see if
61f0: 20 70 6f 69 6e 74 65 72 20 50 20 70 6f 69 6e 74 pointer P point
6200: 73 20 74 6f 0a 2a 2a 20 73 6f 6d 65 74 68 69 6e s to.** somethin
6210: 67 20 62 65 74 77 65 65 6e 20 53 20 28 69 6e 63 g between S (inc
6220: 6c 75 73 69 76 65 29 20 61 6e 64 20 45 20 28 65 lusive) and E (e
6230: 78 63 6c 75 73 69 76 65 29 2e 0a 2a 2a 0a 2a 2a xclusive)..**.**
6240: 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 2c In other words,
6250: 20 53 20 69 73 20 61 20 62 75 66 66 65 72 20 61 S is a buffer a
6260: 6e 64 20 45 20 69 73 20 61 20 70 6f 69 6e 74 65 nd E is a pointe
6270: 72 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 62 r to the first b
6280: 79 74 65 20 61 66 74 65 72 0a 2a 2a 20 74 68 65 yte after.** the
6290: 20 65 6e 64 20 6f 66 20 62 75 66 66 65 72 20 53 end of buffer S
62a0: 2e 20 20 54 68 69 73 20 6d 61 63 72 6f 20 72 65 . This macro re
62b0: 74 75 72 6e 73 20 74 72 75 65 20 69 66 20 50 20 turns true if P
62c0: 70 6f 69 6e 74 73 20 74 6f 20 73 6f 6d 65 74 68 points to someth
62d0: 69 6e 67 0a 2a 2a 20 63 6f 6e 74 61 69 6e 65 64 ing.** contained
62e0: 20 77 69 74 68 69 6e 20 74 68 65 20 62 75 66 66 within the buff
62f0: 65 72 20 53 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 er S..*/.#define
6300: 20 53 51 4c 49 54 45 5f 57 49 54 48 49 4e 28 50 SQLITE_WITHIN(P
6310: 2c 53 2c 45 29 20 28 28 28 75 70 74 72 29 28 50 ,S,E) (((uptr)(P
6320: 29 3e 3d 28 75 70 74 72 29 28 53 29 29 26 26 28 )>=(uptr)(S))&&(
6330: 28 75 70 74 72 29 28 50 29 3c 28 75 70 74 72 29 (uptr)(P)<(uptr)
6340: 28 45 29 29 29 0a 0a 0a 2f 2a 0a 2a 2a 20 4d 61 (E))).../*.** Ma
6350: 63 72 6f 73 20 74 6f 20 64 65 74 65 72 6d 69 6e cros to determin
6360: 65 20 77 68 65 74 68 65 72 20 74 68 65 20 6d 61 e whether the ma
6370: 63 68 69 6e 65 20 69 73 20 62 69 67 20 6f 72 20 chine is big or
6380: 6c 69 74 74 6c 65 20 65 6e 64 69 61 6e 2c 0a 2a little endian,.*
6390: 2a 20 61 6e 64 20 77 68 65 74 68 65 72 20 6f 72 * and whether or
63a0: 20 6e 6f 74 20 74 68 61 74 20 64 65 74 65 72 6d not that determ
63b0: 69 6e 61 74 69 6f 6e 20 69 73 20 72 75 6e 2d 74 ination is run-t
63c0: 69 6d 65 20 6f 72 20 63 6f 6d 70 69 6c 65 2d 74 ime or compile-t
63d0: 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 62 ime..**.** For b
63e0: 65 73 74 20 70 65 72 66 6f 72 6d 61 6e 63 65 2c est performance,
63f0: 20 61 6e 20 61 74 74 65 6d 70 74 20 69 73 20 6d an attempt is m
6400: 61 64 65 20 74 6f 20 67 75 65 73 73 20 61 74 20 ade to guess at
6410: 74 68 65 20 62 79 74 65 2d 6f 72 64 65 72 0a 2a the byte-order.*
6420: 2a 20 75 73 69 6e 67 20 43 2d 70 72 65 70 72 6f * using C-prepro
6430: 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 2e 20 20 cessor macros.
6440: 49 66 20 74 68 61 74 20 69 73 20 75 6e 73 75 63 If that is unsuc
6450: 63 65 73 73 66 75 6c 2c 20 6f 72 20 69 66 0a 2a cessful, or if.*
6460: 2a 20 2d 44 53 51 4c 49 54 45 5f 52 55 4e 54 49 * -DSQLITE_RUNTI
6470: 4d 45 5f 42 59 54 45 4f 52 44 45 52 3d 31 20 69 ME_BYTEORDER=1 i
6480: 73 20 73 65 74 2c 20 74 68 65 6e 20 62 79 74 65 s set, then byte
6490: 2d 6f 72 64 65 72 20 69 73 20 64 65 74 65 72 6d -order is determ
64a0: 69 6e 65 64 0a 2a 2a 20 61 74 20 72 75 6e 2d 74 ined.** at run-t
64b0: 69 6d 65 2e 0a 2a 2f 0a 23 69 66 20 28 64 65 66 ime..*/.#if (def
64c0: 69 6e 65 64 28 69 33 38 36 29 20 20 20 20 20 7c ined(i386) |
64d0: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 69 33 38 36 | defined(__i386
64e0: 5f 5f 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 __) || defined
64f0: 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 20 20 20 (_M_IX86) ||
6500: 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f \. defined(_
6510: 5f 78 38 36 5f 36 34 29 20 7c 7c 20 64 65 66 69 _x86_64) || defi
6520: 6e 65 64 28 5f 5f 78 38 36 5f 36 34 5f 5f 29 20 ned(__x86_64__)
6530: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 58 36 || defined(_M_X6
6540: 34 29 20 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 4) || \.
6550: 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 4d 44 36 defined(_M_AMD6
6560: 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 4) || defined(_M
6570: 5f 41 52 4d 29 20 20 20 20 20 7c 7c 20 64 65 66 _ARM) || def
6580: 69 6e 65 64 28 5f 5f 78 38 36 29 20 20 20 7c 7c ined(__x86) ||
6590: 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 6e \. defin
65a0: 65 64 28 5f 5f 61 72 6d 5f 5f 29 29 20 26 26 20 ed(__arm__)) &&
65b0: 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
65c0: 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 RUNTIME_BYTEORDE
65d0: 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 R).# define SQLI
65e0: 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 TE_BYTEORDER
65f0: 31 32 33 34 0a 23 20 64 65 66 69 6e 65 20 53 51 1234.# define SQ
6600: 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 LITE_BIGENDIAN
6610: 20 20 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 0.# define SQL
6620: 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e ITE_LITTLEENDIAN
6630: 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1.# define SQLI
6640: 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 TE_UTF16NATIVE
6650: 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 0a 23 SQLITE_UTF16LE.#
6660: 65 6e 64 69 66 0a 23 69 66 20 28 64 65 66 69 6e endif.#if (defin
6670: 65 64 28 73 70 61 72 63 29 20 20 20 20 7c 7c 20 ed(sparc) ||
6680: 64 65 66 69 6e 65 64 28 5f 5f 70 70 63 5f 5f 29 defined(__ppc__)
6690: 29 20 20 5c 0a 20 20 20 20 26 26 20 21 64 65 66 ) \. && !def
66a0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 52 55 4e 54 ined(SQLITE_RUNT
66b0: 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 29 0a 23 IME_BYTEORDER).#
66c0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 define SQLITE_B
66d0: 59 54 45 4f 52 44 45 52 20 20 20 20 34 33 32 31 YTEORDER 4321
66e0: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
66f0: 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 31 0a _BIGENDIAN 1.
6700: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
6710: 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 30 0a 23 LITTLEENDIAN 0.#
6720: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 55 define SQLITE_U
6730: 54 46 31 36 4e 41 54 49 56 45 20 20 53 51 4c 49 TF16NATIVE SQLI
6740: 54 45 5f 55 54 46 31 36 42 45 0a 23 65 6e 64 69 TE_UTF16BE.#endi
6750: 66 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 f.#if !defined(S
6760: 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 29 QLITE_BYTEORDER)
6770: 0a 23 20 69 66 64 65 66 20 53 51 4c 49 54 45 5f .# ifdef SQLITE_
6780: 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a 20 20 63 AMALGAMATION. c
6790: 6f 6e 73 74 20 69 6e 74 20 73 71 6c 69 74 65 33 onst int sqlite3
67a0: 6f 6e 65 20 3d 20 31 3b 0a 23 20 65 6c 73 65 0a one = 1;.# else.
67b0: 20 20 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 69 extern const i
67c0: 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 3b 0a 23 nt sqlite3one;.#
67d0: 20 65 6e 64 69 66 0a 23 20 64 65 66 69 6e 65 20 endif.# define
67e0: 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 SQLITE_BYTEORDER
67f0: 20 20 20 20 30 20 20 20 20 20 2f 2a 20 30 20 6d 0 /* 0 m
6800: 65 61 6e 73 20 22 75 6e 6b 6e 6f 77 6e 20 61 74 eans "unknown at
6810: 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 22 20 2a compile-time" *
6820: 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 /.# define SQLIT
6830: 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 28 E_BIGENDIAN (
6840: 2a 28 63 68 61 72 20 2a 29 28 26 73 71 6c 69 74 *(char *)(&sqlit
6850: 65 33 6f 6e 65 29 3d 3d 30 29 0a 23 20 64 65 66 e3one)==0).# def
6860: 69 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c ine SQLITE_LITTL
6870: 45 45 4e 44 49 41 4e 20 28 2a 28 63 68 61 72 20 EENDIAN (*(char
6880: 2a 29 28 26 73 71 6c 69 74 65 33 6f 6e 65 29 3d *)(&sqlite3one)=
6890: 3d 31 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c =1).# define SQL
68a0: 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 ITE_UTF16NATIVE
68b0: 20 28 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 (SQLITE_BIGENDI
68c0: 41 4e 3f 53 51 4c 49 54 45 5f 55 54 46 31 36 42 AN?SQLITE_UTF16B
68d0: 45 3a 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 E:SQLITE_UTF16LE
68e0: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
68f0: 43 6f 6e 73 74 61 6e 74 73 20 66 6f 72 20 74 68 Constants for th
6900: 65 20 6c 61 72 67 65 73 74 20 61 6e 64 20 73 6d e largest and sm
6910: 61 6c 6c 65 73 74 20 70 6f 73 73 69 62 6c 65 20 allest possible
6920: 36 34 2d 62 69 74 20 73 69 67 6e 65 64 20 69 6e 64-bit signed in
6930: 74 65 67 65 72 73 2e 0a 2a 2a 20 54 68 65 73 65 tegers..** These
6940: 20 6d 61 63 72 6f 73 20 61 72 65 20 64 65 73 69 macros are desi
6950: 67 6e 65 64 20 74 6f 20 77 6f 72 6b 20 63 6f 72 gned to work cor
6960: 72 65 63 74 6c 79 20 6f 6e 20 62 6f 74 68 20 33 rectly on both 3
6970: 32 2d 62 69 74 20 61 6e 64 20 36 34 2d 62 69 74 2-bit and 64-bit
6980: 0a 2a 2a 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a .** compilers..*
6990: 2f 0a 23 64 65 66 69 6e 65 20 4c 41 52 47 45 53 /.#define LARGES
69a0: 54 5f 49 4e 54 36 34 20 20 28 30 78 66 66 66 66 T_INT64 (0xffff
69b0: 66 66 66 66 7c 28 28 28 69 36 34 29 30 78 37 66 ffff|(((i64)0x7f
69c0: 66 66 66 66 66 66 29 3c 3c 33 32 29 29 0a 23 64 ffffff)<<32)).#d
69d0: 65 66 69 6e 65 20 53 4d 41 4c 4c 45 53 54 5f 49 efine SMALLEST_I
69e0: 4e 54 36 34 20 28 28 28 69 36 34 29 2d 31 29 20 NT64 (((i64)-1)
69f0: 2d 20 4c 41 52 47 45 53 54 5f 49 4e 54 36 34 29 - LARGEST_INT64)
6a00: 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e 64 20 75 70 ../*.** Round up
6a10: 20 61 20 6e 75 6d 62 65 72 20 74 6f 20 74 68 65 a number to the
6a20: 20 6e 65 78 74 20 6c 61 72 67 65 72 20 6d 75 6c next larger mul
6a30: 74 69 70 6c 65 20 6f 66 20 38 2e 20 20 54 68 69 tiple of 8. Thi
6a40: 73 20 69 73 20 75 73 65 64 0a 2a 2a 20 74 6f 20 s is used.** to
6a50: 66 6f 72 63 65 20 38 2d 62 79 74 65 20 61 6c 69 force 8-byte ali
6a60: 67 6e 6d 65 6e 74 20 6f 6e 20 36 34 2d 62 69 74 gnment on 64-bit
6a70: 20 61 72 63 68 69 74 65 63 74 75 72 65 73 2e 0a architectures..
6a80: 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e 44 */.#define ROUND
6a90: 38 28 78 29 20 20 20 20 20 28 28 28 78 29 2b 37 8(x) (((x)+7
6aa0: 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 )&~7)../*.** Rou
6ab0: 6e 64 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 6e nd down to the n
6ac0: 65 61 72 65 73 74 20 6d 75 6c 74 69 70 6c 65 20 earest multiple
6ad0: 6f 66 20 38 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 of 8.*/.#define
6ae0: 52 4f 55 4e 44 44 4f 57 4e 38 28 78 29 20 28 28 ROUNDDOWN8(x) ((
6af0: 78 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 41 73 x)&~7)../*.** As
6b00: 73 65 72 74 20 74 68 61 74 20 74 68 65 20 70 6f sert that the po
6b10: 69 6e 74 65 72 20 58 20 69 73 20 61 6c 69 67 6e inter X is align
6b20: 65 64 20 74 6f 20 61 6e 20 38 2d 62 79 74 65 20 ed to an 8-byte
6b30: 62 6f 75 6e 64 61 72 79 2e 20 20 54 68 69 73 0a boundary. This.
6b40: 2a 2a 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 ** macro is used
6b50: 20 6f 6e 6c 79 20 77 69 74 68 69 6e 20 61 73 73 only within ass
6b60: 65 72 74 28 29 20 74 6f 20 76 65 72 69 66 79 20 ert() to verify
6b70: 74 68 61 74 20 74 68 65 20 63 6f 64 65 20 67 65 that the code ge
6b80: 74 73 0a 2a 2a 20 61 6c 6c 20 61 6c 69 67 6e 6d ts.** all alignm
6b90: 65 6e 74 20 72 65 73 74 72 69 63 74 69 6f 6e 73 ent restrictions
6ba0: 20 63 6f 72 72 65 63 74 2e 0a 2a 2a 0a 2a 2a 20 correct..**.**
6bb0: 45 78 63 65 70 74 2c 20 69 66 20 53 51 4c 49 54 Except, if SQLIT
6bc0: 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 E_4_BYTE_ALIGNED
6bd0: 5f 4d 41 4c 4c 4f 43 20 69 73 20 64 65 66 69 6e _MALLOC is defin
6be0: 65 64 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 ed, then the.**
6bf0: 75 6e 64 65 72 6c 79 69 6e 67 20 6d 61 6c 6c 6f underlying mallo
6c00: 63 28 29 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 c() implementati
6c10: 6f 6e 20 6d 69 67 68 74 20 72 65 74 75 72 6e 20 on might return
6c20: 75 73 20 34 2d 62 79 74 65 20 61 6c 69 67 6e 65 us 4-byte aligne
6c30: 64 0a 2a 2a 20 70 6f 69 6e 74 65 72 73 2e 20 20 d.** pointers.
6c40: 49 6e 20 74 68 61 74 20 63 61 73 65 2c 20 6f 6e In that case, on
6c50: 6c 79 20 76 65 72 69 66 79 20 34 2d 62 79 74 65 ly verify 4-byte
6c60: 20 61 6c 69 67 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 alignment..*/.#
6c70: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 34 5f 42 ifdef SQLITE_4_B
6c80: 59 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c YTE_ALIGNED_MALL
6c90: 4f 43 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 OC.# define EIGH
6ca0: 54 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 T_BYTE_ALIGNMENT
6cb0: 28 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 (X) ((((char*)
6cc0: 28 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 (X) - (char*)0)&
6cd0: 33 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 20 64 3)==0).#else.# d
6ce0: 65 66 69 6e 65 20 45 49 47 48 54 5f 42 59 54 45 efine EIGHT_BYTE
6cf0: 5f 41 4c 49 47 4e 4d 45 4e 54 28 58 29 20 20 20 _ALIGNMENT(X)
6d00: 28 28 28 28 63 68 61 72 2a 29 28 58 29 20 2d 20 ((((char*)(X) -
6d10: 28 63 68 61 72 2a 29 30 29 26 37 29 3d 3d 30 29 (char*)0)&7)==0)
6d20: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 .#endif../*.** D
6d30: 69 73 61 62 6c 65 20 4d 4d 41 50 20 6f 6e 20 70 isable MMAP on p
6d40: 6c 61 74 66 6f 72 6d 73 20 77 68 65 72 65 20 69 latforms where i
6d50: 74 20 69 73 20 6b 6e 6f 77 6e 20 74 6f 20 6e 6f t is known to no
6d60: 74 20 77 6f 72 6b 0a 2a 2f 0a 23 69 66 20 64 65 t work.*/.#if de
6d70: 66 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f fined(__OpenBSD_
6d80: 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f _) || defined(__
6d90: 51 4e 58 4e 54 4f 5f 5f 29 0a 23 20 75 6e 64 65 QNXNTO__).# unde
6da0: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 f SQLITE_MAX_MMA
6db0: 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 P_SIZE.# define
6dc0: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
6dd0: 53 49 5a 45 20 30 0a 23 65 6e 64 69 66 0a 0a 2f SIZE 0.#endif../
6de0: 2a 0a 2a 2a 20 44 65 66 61 75 6c 74 20 6d 61 78 *.** Default max
6df0: 69 6d 75 6d 20 73 69 7a 65 20 6f 66 20 6d 65 6d imum size of mem
6e00: 6f 72 79 20 75 73 65 64 20 62 79 20 6d 65 6d 6f ory used by memo
6e10: 72 79 2d 6d 61 70 70 65 64 20 49 2f 4f 20 69 6e ry-mapped I/O in
6e20: 20 74 68 65 20 56 46 53 0a 2a 2f 0a 23 69 66 64 the VFS.*/.#ifd
6e30: 65 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a 23 20 69 ef __APPLE__.# i
6e40: 6e 63 6c 75 64 65 20 3c 54 61 72 67 65 74 43 6f nclude <TargetCo
6e50: 6e 64 69 74 69 6f 6e 61 6c 73 2e 68 3e 0a 23 65 nditionals.h>.#e
6e60: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
6e70: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
6e80: 45 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f E.# if defined(_
6e90: 5f 6c 69 6e 75 78 5f 5f 29 20 5c 0a 20 20 7c 7c _linux__) \. ||
6ea0: 20 64 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 defined(_WIN32)
6eb0: 20 5c 0a 20 20 7c 7c 20 28 64 65 66 69 6e 65 64 \. || (defined
6ec0: 28 5f 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 64 (__APPLE__) && d
6ed0: 65 66 69 6e 65 64 28 5f 5f 4d 41 43 48 5f 5f 29 efined(__MACH__)
6ee0: 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 64 ) \. || defined
6ef0: 28 5f 5f 73 75 6e 29 20 5c 0a 20 20 7c 7c 20 64 (__sun) \. || d
6f00: 65 66 69 6e 65 64 28 5f 5f 46 72 65 65 42 53 44 efined(__FreeBSD
6f10: 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 6e __) \. || defin
6f20: 65 64 28 5f 5f 44 72 61 67 6f 6e 46 6c 79 5f 5f ed(__DragonFly__
6f30: 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c ).# define SQL
6f40: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
6f50: 45 20 30 78 37 66 66 66 30 30 30 30 20 20 2f 2a E 0x7fff0000 /*
6f60: 20 32 31 34 37 34 31 38 31 31 32 20 2a 2f 0a 23 2147418112 */.#
6f70: 20 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e 65 else.# define
6f80: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
6f90: 5f 53 49 5a 45 20 30 0a 23 20 65 6e 64 69 66 0a _SIZE 0.# endif.
6fa0: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
6fb0: 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 MAX_MMAP_SIZE_xc
6fc0: 20 31 20 2f 2a 20 65 78 63 6c 75 64 65 20 66 72 1 /* exclude fr
6fd0: 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 om ctime.c */.#e
6fe0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
6ff0: 64 65 66 61 75 6c 74 20 4d 4d 41 50 5f 53 49 5a default MMAP_SIZ
7000: 45 20 69 73 20 7a 65 72 6f 20 6f 6e 20 61 6c 6c E is zero on all
7010: 20 70 6c 61 74 66 6f 72 6d 73 2e 20 20 4f 72 2c platforms. Or,
7020: 20 65 76 65 6e 20 69 66 20 61 20 6c 61 72 67 65 even if a large
7030: 72 0a 2a 2a 20 64 65 66 61 75 6c 74 20 4d 4d 41 r.** default MMA
7040: 50 5f 53 49 5a 45 20 69 73 20 73 70 65 63 69 66 P_SIZE is specif
7050: 69 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 ied at compile-t
7060: 69 6d 65 2c 20 6d 61 6b 65 20 73 75 72 65 20 74 ime, make sure t
7070: 68 61 74 20 69 74 20 64 6f 65 73 0a 2a 2a 20 6e hat it does.** n
7080: 6f 74 20 65 78 63 65 65 64 20 74 68 65 20 6d 61 ot exceed the ma
7090: 78 69 6d 75 6d 20 6d 6d 61 70 20 73 69 7a 65 2e ximum mmap size.
70a0: 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 .*/.#ifndef SQLI
70b0: 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f TE_DEFAULT_MMAP_
70c0: 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 51 SIZE.# define SQ
70d0: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 LITE_DEFAULT_MMA
70e0: 50 5f 53 49 5a 45 20 30 0a 23 20 64 65 66 69 6e P_SIZE 0.# defin
70f0: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
7100: 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 20 31 20 _MMAP_SIZE_xc 1
7110: 20 2f 2a 20 45 78 63 6c 75 64 65 20 66 72 6f 6d /* Exclude from
7120: 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 65 6e 64 ctime.c */.#end
7130: 69 66 0a 23 69 66 20 53 51 4c 49 54 45 5f 44 45 if.#if SQLITE_DE
7140: 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 3e FAULT_MMAP_SIZE>
7150: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
7160: 53 49 5a 45 0a 23 20 75 6e 64 65 66 20 53 51 4c SIZE.# undef SQL
7170: 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 ITE_DEFAULT_MMAP
7180: 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 _SIZE.# define S
7190: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d QLITE_DEFAULT_MM
71a0: 41 50 5f 53 49 5a 45 20 53 51 4c 49 54 45 5f 4d AP_SIZE SQLITE_M
71b0: 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a 23 65 6e AX_MMAP_SIZE.#en
71c0: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 6c 79 20 dif../*.** Only
71d0: 6f 6e 65 20 6f 66 20 53 51 4c 49 54 45 5f 45 4e one of SQLITE_EN
71e0: 41 42 4c 45 5f 53 54 41 54 33 20 6f 72 20 53 51 ABLE_STAT3 or SQ
71f0: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
7200: 34 20 63 61 6e 20 62 65 20 64 65 66 69 6e 65 64 4 can be defined
7210: 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 79 20 69 73 ..** Priority is
7220: 20 67 69 76 65 6e 20 74 6f 20 53 51 4c 49 54 45 given to SQLITE
7230: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 2e 20 20 _ENABLE_STAT4.
7240: 49 66 20 65 69 74 68 65 72 20 61 72 65 20 64 65 If either are de
7250: 66 69 6e 65 64 2c 20 61 6c 73 6f 0a 2a 2a 20 64 fined, also.** d
7260: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 efine SQLITE_ENA
7270: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
7280: 54 34 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c T4.*/.#ifdef SQL
7290: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 ITE_ENABLE_STAT4
72a0: 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f .# undef SQLITE_
72b0: 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 20 64 ENABLE_STAT3.# d
72c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 efine SQLITE_ENA
72d0: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
72e0: 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c 49 54 T4 1.#elif SQLIT
72f0: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a 23 E_ENABLE_STAT3.#
7300: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 define SQLITE_E
7310: 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
7320: 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 51 4c TAT4 1.#elif SQL
7330: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
7340: 5f 4f 52 5f 53 54 41 54 34 0a 23 20 75 6e 64 65 _OR_STAT4.# unde
7350: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
7360: 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 STAT3_OR_STAT4.#
7370: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 45 4c endif../*.** SEL
7380: 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 ECTTRACE_ENABLED
7390: 20 77 69 6c 6c 20 62 65 20 65 69 74 68 65 72 20 will be either
73a0: 31 20 6f 72 20 30 20 64 65 70 65 6e 64 69 6e 67 1 or 0 depending
73b0: 20 6f 6e 20 77 68 65 74 68 65 72 20 6f 72 20 6e on whether or n
73c0: 6f 74 0a 2a 2a 20 74 68 65 20 53 65 6c 65 63 74 ot.** the Select
73d0: 20 71 75 65 72 79 20 67 65 6e 65 72 61 74 6f 72 query generator
73e0: 20 74 72 61 63 69 6e 67 20 6c 6f 67 69 63 20 69 tracing logic i
73f0: 73 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a s turned on..*/.
7400: 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 #if defined(SQLI
7410: 54 45 5f 44 45 42 55 47 29 20 7c 7c 20 64 65 66 TE_DEBUG) || def
7420: 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 ined(SQLITE_ENAB
7430: 4c 45 5f 53 45 4c 45 43 54 54 52 41 43 45 29 0a LE_SELECTTRACE).
7440: 23 20 64 65 66 69 6e 65 20 53 45 4c 45 43 54 54 # define SELECTT
7450: 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 31 0a 23 RACE_ENABLED 1.#
7460: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 45 else.# define SE
7470: 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 LECTTRACE_ENABLE
7480: 44 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a D 0.#endif../*.*
7490: 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
74a0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
74b0: 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 tructure is used
74c0: 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 62 75 to store the bu
74d0: 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 sy-handler.** ca
74e0: 6c 6c 62 61 63 6b 20 66 6f 72 20 61 20 67 69 76 llback for a giv
74f0: 65 6e 20 73 71 6c 69 74 65 20 68 61 6e 64 6c 65 en sqlite handle
7500: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 71 6c 69 ..**.** The sqli
7510: 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 72 20 6d te.busyHandler m
7520: 65 6d 62 65 72 20 6f 66 20 74 68 65 20 73 71 6c ember of the sql
7530: 69 74 65 20 73 74 72 75 63 74 20 63 6f 6e 74 61 ite struct conta
7540: 69 6e 73 20 74 68 65 20 62 75 73 79 0a 2a 2a 20 ins the busy.**
7550: 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 74 68 65 callback for the
7560: 20 64 61 74 61 62 61 73 65 20 68 61 6e 64 6c 65 database handle
7570: 2e 20 45 61 63 68 20 70 61 67 65 72 20 6f 70 65 . Each pager ope
7580: 6e 65 64 20 76 69 61 20 74 68 65 20 73 71 6c 69 ned via the sqli
7590: 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 69 73 20 te.** handle is
75a0: 70 61 73 73 65 64 20 61 20 70 6f 69 6e 74 65 72 passed a pointer
75b0: 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 73 79 48 to sqlite.busyH
75c0: 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 75 73 79 andler. The busy
75d0: 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c 6c -handler.** call
75e0: 62 61 63 6b 20 69 73 20 63 75 72 72 65 6e 74 6c back is currentl
75f0: 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c 79 20 66 y invoked only f
7600: 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 67 65 72 rom within pager
7610: 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 .c..*/.typedef s
7620: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
7630: 72 20 42 75 73 79 48 61 6e 64 6c 65 72 3b 0a 73 r BusyHandler;.s
7640: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
7650: 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 46 75 6e r {. int (*xFun
7660: 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 29 3b 20 c)(void *,int);
7670: 20 2f 2a 20 54 68 65 20 62 75 73 79 20 63 61 6c /* The busy cal
7680: 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 lback */. void
7690: 2a 70 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 *pArg;
76a0: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 /* First a
76b0: 72 67 20 74 6f 20 62 75 73 79 20 63 61 6c 6c 62 rg to busy callb
76c0: 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 42 75 ack */. int nBu
76d0: 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 sy;
76e0: 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d 65 6e 74 /* Increment
76f0: 65 64 20 77 69 74 68 20 65 61 63 68 20 62 75 73 ed with each bus
7700: 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a 0a 2f 2a y call */.};../*
7710: 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 .** Name of the
7720: 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 master database
7730: 74 61 62 6c 65 2e 20 20 54 68 65 20 6d 61 73 74 table. The mast
7740: 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 6c er database tabl
7750: 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 63 69 61 e.** is a specia
7760: 6c 20 74 61 62 6c 65 20 74 68 61 74 20 68 6f 6c l table that hol
7770: 64 73 20 74 68 65 20 6e 61 6d 65 73 20 61 6e 64 ds the names and
7780: 20 61 74 74 72 69 62 75 74 65 73 20 6f 66 20 61 attributes of a
7790: 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 62 6c 65 ll.** user table
77a0: 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 0a 2a s and indices..*
77b0: 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 /.#define MASTER
77c0: 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 73 71 6c _NAME "sql
77d0: 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 64 65 66 ite_master".#def
77e0: 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 45 52 5f ine TEMP_MASTER_
77f0: 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 5f 74 65 NAME "sqlite_te
7800: 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f 2a 0a 2a mp_master"../*.*
7810: 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 67 65 20 * The root-page
7820: 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 of the master da
7830: 74 61 62 61 73 65 20 74 61 62 6c 65 2e 0a 2a 2f tabase table..*/
7840: 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 5f .#define MASTER_
7850: 52 4f 4f 54 20 20 20 20 20 20 20 31 0a 0a 2f 2a ROOT 1../*
7860: 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 .** The name of
7870: 74 68 65 20 73 63 68 65 6d 61 20 74 61 62 6c 65 the schema table
7880: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 ..*/.#define SCH
7890: 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 20 28 28 EMA_TABLE(x) ((
78a0: 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 26 26 28 !OMIT_TEMPDB)&&(
78b0: 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 53 54 45 x==1)?TEMP_MASTE
78c0: 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 5f 4e 41 R_NAME:MASTER_NA
78d0: 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 63 6f 6e ME)../*.** A con
78e0: 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 6f 20 74 venience macro t
78f0: 68 61 74 20 72 65 74 75 72 6e 73 20 74 68 65 20 hat returns the
7900: 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e number of elemen
7910: 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 72 72 61 ts in.** an arra
7920: 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 41 72 y..*/.#define Ar
7930: 72 61 79 53 69 7a 65 28 58 29 20 20 20 20 28 28 raySize(X) ((
7940: 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 29 2f 73 int)(sizeof(X)/s
7950: 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 0a 0a 2f izeof(X[0])))../
7960: 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 *.** Determine i
7970: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 69 f the argument i
7980: 73 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f s a power of two
7990: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 6f .*/.#define IsPo
79a0: 77 65 72 4f 66 54 77 6f 28 58 29 20 28 28 28 58 werOfTwo(X) (((X
79b0: 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 29 0a 0a )&((X)-1))==0)..
79c0: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
79d0: 69 6e 67 20 76 61 6c 75 65 20 61 73 20 61 20 64 ing value as a d
79e0: 65 73 74 72 75 63 74 6f 72 20 6d 65 61 6e 73 20 estructor means
79f0: 74 6f 20 75 73 65 20 73 71 6c 69 74 65 33 44 62 to use sqlite3Db
7a00: 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 65 20 73 Free()..** The s
7a10: 71 6c 69 74 65 33 44 62 46 72 65 65 28 29 20 72 qlite3DbFree() r
7a20: 6f 75 74 69 6e 65 20 72 65 71 75 69 72 65 73 20 outine requires
7a30: 74 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 69 two parameters i
7a40: 6e 73 74 65 61 64 20 6f 66 20 74 68 65 0a 2a 2a nstead of the.**
7a50: 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 72 20 74 one parameter t
7a60: 68 61 74 20 64 65 73 74 72 75 63 74 6f 72 73 20 hat destructors
7a70: 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 2e 20 20 normally want.
7a80: 53 6f 20 77 65 20 68 61 76 65 20 74 6f 20 69 6e So we have to in
7a90: 74 72 6f 64 75 63 65 0a 2a 2a 20 74 68 69 73 20 troduce.** this
7aa0: 6d 61 67 69 63 20 76 61 6c 75 65 20 74 68 61 74 magic value that
7ab0: 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f 77 73 20 the code knows
7ac0: 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 66 65 72 to handle differ
7ad0: 65 6e 74 6c 79 2e 20 20 41 6e 79 0a 2a 2a 20 70 ently. Any.** p
7ae0: 6f 69 6e 74 65 72 20 77 69 6c 6c 20 77 6f 72 6b ointer will work
7af0: 20 68 65 72 65 20 61 73 20 6c 6f 6e 67 20 61 73 here as long as
7b00: 20 69 74 20 69 73 20 64 69 73 74 69 6e 63 74 20 it is distinct
7b10: 66 72 6f 6d 20 53 51 4c 49 54 45 5f 53 54 41 54 from SQLITE_STAT
7b20: 49 43 0a 2a 2a 20 61 6e 64 20 53 51 4c 49 54 45 IC.** and SQLITE
7b30: 5f 54 52 41 4e 53 49 45 4e 54 2e 0a 2a 2f 0a 23 _TRANSIENT..*/.#
7b40: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 59 define SQLITE_DY
7b50: 4e 41 4d 49 43 20 20 20 28 28 73 71 6c 69 74 65 NAMIC ((sqlite
7b60: 33 5f 64 65 73 74 72 75 63 74 6f 72 5f 74 79 70 3_destructor_typ
7b70: 65 29 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 53 e)sqlite3MallocS
7b80: 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 57 68 65 6e ize)../*.** When
7b90: 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 SQLITE_OMIT_WSD
7ba0: 20 69 73 20 64 65 66 69 6e 65 64 2c 20 69 74 20 is defined, it
7bb0: 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 74 means that the t
7bc0: 61 72 67 65 74 20 70 6c 61 74 66 6f 72 6d 20 64 arget platform d
7bd0: 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 75 70 70 6f oes.** not suppo
7be0: 72 74 20 57 72 69 74 61 62 6c 65 20 53 74 61 74 rt Writable Stat
7bf0: 69 63 20 44 61 74 61 20 28 57 53 44 29 20 73 75 ic Data (WSD) su
7c00: 63 68 20 61 73 20 67 6c 6f 62 61 6c 20 61 6e 64 ch as global and
7c10: 20 73 74 61 74 69 63 20 76 61 72 69 61 62 6c 65 static variable
7c20: 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 72 69 61 62 s..** All variab
7c30: 6c 65 73 20 6d 75 73 74 20 65 69 74 68 65 72 20 les must either
7c40: 62 65 20 6f 6e 20 74 68 65 20 73 74 61 63 6b 20 be on the stack
7c50: 6f 72 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 61 or dynamically a
7c60: 6c 6c 6f 63 61 74 65 64 20 66 72 6f 6d 0a 2a 2a llocated from.**
7c70: 20 74 68 65 20 68 65 61 70 2e 20 20 57 68 65 6e the heap. When
7c80: 20 57 53 44 20 69 73 20 75 6e 73 75 70 70 6f 72 WSD is unsuppor
7c90: 74 65 64 2c 20 74 68 65 20 76 61 72 69 61 62 6c ted, the variabl
7ca0: 65 20 64 65 63 6c 61 72 61 74 69 6f 6e 73 20 73 e declarations s
7cb0: 63 61 74 74 65 72 65 64 0a 2a 2a 20 74 68 72 6f cattered.** thro
7cc0: 75 67 68 6f 75 74 20 74 68 65 20 53 51 4c 69 74 ughout the SQLit
7cd0: 65 20 63 6f 64 65 20 6d 75 73 74 20 62 65 63 6f e code must beco
7ce0: 6d 65 20 63 6f 6e 73 74 61 6e 74 73 20 69 6e 73 me constants ins
7cf0: 74 65 61 64 2e 20 20 54 68 65 20 53 51 4c 49 54 tead. The SQLIT
7d00: 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 72 6f 20 69 E_WSD.** macro i
7d10: 73 20 75 73 65 64 20 66 6f 72 20 74 68 69 73 20 s used for this
7d20: 70 75 72 70 6f 73 65 2e 20 20 41 6e 64 20 69 6e purpose. And in
7d30: 73 74 65 61 64 20 6f 66 20 72 65 66 65 72 65 6e stead of referen
7d40: 63 69 6e 67 20 74 68 65 20 76 61 72 69 61 62 6c cing the variabl
7d50: 65 0a 2a 2a 20 64 69 72 65 63 74 6c 79 2c 20 77 e.** directly, w
7d60: 65 20 75 73 65 20 69 74 73 20 63 6f 6e 73 74 61 e use its consta
7d70: 6e 74 20 61 73 20 61 20 6b 65 79 20 74 6f 20 6c nt as a key to l
7d80: 6f 6f 6b 75 70 20 74 68 65 20 72 75 6e 2d 74 69 ookup the run-ti
7d90: 6d 65 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 me allocated.**
7da0: 62 75 66 66 65 72 20 74 68 61 74 20 68 6f 6c 64 buffer that hold
7db0: 73 20 72 65 61 6c 20 76 61 72 69 61 62 6c 65 2e s real variable.
7dc0: 20 20 54 68 65 20 63 6f 6e 73 74 61 6e 74 20 69 The constant i
7dd0: 73 20 61 6c 73 6f 20 74 68 65 20 69 6e 69 74 69 s also the initi
7de0: 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f 72 20 74 68 alizer.** for th
7df0: 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c 6c 6f 63 e run-time alloc
7e00: 61 74 65 64 20 62 75 66 66 65 72 2e 0a 2a 2a 0a ated buffer..**.
7e10: 2a 2a 20 49 6e 20 74 68 65 20 75 73 75 61 6c 20 ** In the usual
7e20: 63 61 73 65 20 77 68 65 72 65 20 57 53 44 20 69 case where WSD i
7e30: 73 20 73 75 70 70 6f 72 74 65 64 2c 20 74 68 65 s supported, the
7e40: 20 53 51 4c 49 54 45 5f 57 53 44 20 61 6e 64 20 SQLITE_WSD and
7e50: 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 63 72 6f 73 GLOBAL.** macros
7e60: 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f 70 73 20 61 become no-ops a
7e70: 6e 64 20 68 61 76 65 20 7a 65 72 6f 20 70 65 72 nd have zero per
7e80: 66 6f 72 6d 61 6e 63 65 20 69 6d 70 61 63 74 2e formance impact.
7e90: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
7ea0: 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 20 23 64 65 E_OMIT_WSD. #de
7eb0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 53 44 20 fine SQLITE_WSD
7ec0: 63 6f 6e 73 74 0a 20 20 23 64 65 66 69 6e 65 20 const. #define
7ed0: 47 4c 4f 42 41 4c 28 74 2c 76 29 20 28 2a 28 74 GLOBAL(t,v) (*(t
7ee0: 2a 29 73 71 6c 69 74 65 33 5f 77 73 64 5f 66 69 *)sqlite3_wsd_fi
7ef0: 6e 64 28 28 76 6f 69 64 2a 29 26 28 76 29 2c 20 nd((void*)&(v),
7f00: 73 69 7a 65 6f 66 28 76 29 29 29 0a 20 20 23 64 sizeof(v))). #d
7f10: 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 6c 6f efine sqlite3Glo
7f20: 62 61 6c 43 6f 6e 66 69 67 20 47 4c 4f 42 41 4c balConfig GLOBAL
7f30: 28 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 43 (struct Sqlite3C
7f40: 6f 6e 66 69 67 2c 20 73 71 6c 69 74 65 33 43 6f onfig, sqlite3Co
7f50: 6e 66 69 67 29 0a 20 20 69 6e 74 20 73 71 6c 69 nfig). int sqli
7f60: 74 65 33 5f 77 73 64 5f 69 6e 69 74 28 69 6e 74 te3_wsd_init(int
7f70: 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a 20 20 76 6f N, int J);. vo
7f80: 69 64 20 2a 73 71 6c 69 74 65 33 5f 77 73 64 5f id *sqlite3_wsd_
7f90: 66 69 6e 64 28 76 6f 69 64 20 2a 4b 2c 20 69 6e find(void *K, in
7fa0: 74 20 4c 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 t L);.#else. #d
7fb0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 53 44 efine SQLITE_WSD
7fc0: 0a 20 20 23 64 65 66 69 6e 65 20 47 4c 4f 42 41 . #define GLOBA
7fd0: 4c 28 74 2c 76 29 20 76 0a 20 20 23 64 65 66 69 L(t,v) v. #defi
7fe0: 6e 65 20 73 71 6c 69 74 65 33 47 6c 6f 62 61 6c ne sqlite3Global
7ff0: 43 6f 6e 66 69 67 20 73 71 6c 69 74 65 33 43 6f Config sqlite3Co
8000: 6e 66 69 67 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a nfig.#endif../*.
8010: 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ** The following
8020: 20 6d 61 63 72 6f 73 20 61 72 65 20 75 73 65 64 macros are used
8030: 20 74 6f 20 73 75 70 70 72 65 73 73 20 63 6f 6d to suppress com
8040: 70 69 6c 65 72 20 77 61 72 6e 69 6e 67 73 20 61 piler warnings a
8050: 6e 64 20 74 6f 0a 2a 2a 20 6d 61 6b 65 20 69 74 nd to.** make it
8060: 20 63 6c 65 61 72 20 74 6f 20 68 75 6d 61 6e 20 clear to human
8070: 72 65 61 64 65 72 73 20 77 68 65 6e 20 61 20 66 readers when a f
8080: 75 6e 63 74 69 6f 6e 20 70 61 72 61 6d 65 74 65 unction paramete
8090: 72 20 69 73 20 64 65 6c 69 62 65 72 61 74 65 6c r is deliberatel
80a0: 79 0a 2a 2a 20 6c 65 66 74 20 75 6e 75 73 65 64 y.** left unused
80b0: 20 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 within the body
80c0: 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2e 20 of a function.
80d0: 54 68 69 73 20 75 73 75 61 6c 6c 79 20 68 61 70 This usually hap
80e0: 70 65 6e 73 20 77 68 65 6e 0a 2a 2a 20 61 20 66 pens when.** a f
80f0: 75 6e 63 74 69 6f 6e 20 69 73 20 63 61 6c 6c 65 unction is calle
8100: 64 20 76 69 61 20 61 20 66 75 6e 63 74 69 6f 6e d via a function
8110: 20 70 6f 69 6e 74 65 72 2e 20 46 6f 72 20 65 78 pointer. For ex
8120: 61 6d 70 6c 65 20 74 68 65 0a 2a 2a 20 69 6d 70 ample the.** imp
8130: 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 61 lementation of a
8140: 6e 20 53 51 4c 20 61 67 67 72 65 67 61 74 65 20 n SQL aggregate
8150: 73 74 65 70 20 63 61 6c 6c 62 61 63 6b 20 6d 61 step callback ma
8160: 79 20 6e 6f 74 20 75 73 65 20 74 68 65 0a 2a 2a y not use the.**
8170: 20 70 61 72 61 6d 65 74 65 72 20 69 6e 64 69 63 parameter indic
8180: 61 74 69 6e 67 20 74 68 65 20 6e 75 6d 62 65 72 ating the number
8190: 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 70 61 of arguments pa
81a0: 73 73 65 64 20 74 6f 20 74 68 65 20 61 67 67 72 ssed to the aggr
81b0: 65 67 61 74 65 2c 0a 2a 2a 20 69 66 20 69 74 20 egate,.** if it
81c0: 6b 6e 6f 77 73 20 74 68 61 74 20 74 68 69 73 20 knows that this
81d0: 69 73 20 65 6e 66 6f 72 63 65 64 20 65 6c 73 65 is enforced else
81e0: 77 68 65 72 65 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 where..**.** Whe
81f0: 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 n a function par
8200: 61 6d 65 74 65 72 20 69 73 20 6e 6f 74 20 75 73 ameter is not us
8210: 65 64 20 61 74 20 61 6c 6c 20 77 69 74 68 69 6e ed at all within
8220: 20 74 68 65 20 62 6f 64 79 20 6f 66 20 61 20 66 the body of a f
8230: 75 6e 63 74 69 6f 6e 2c 0a 2a 2a 20 69 74 20 69 unction,.** it i
8240: 73 20 67 65 6e 65 72 61 6c 6c 79 20 6e 61 6d 65 s generally name
8250: 64 20 22 4e 6f 74 55 73 65 64 22 20 6f 72 20 22 d "NotUsed" or "
8260: 4e 6f 74 55 73 65 64 32 22 20 74 6f 20 6d 61 6b NotUsed2" to mak
8270: 65 20 74 68 69 6e 67 73 20 65 76 65 6e 20 63 6c e things even cl
8280: 65 61 72 65 72 2e 0a 2a 2a 20 48 6f 77 65 76 65 earer..** Howeve
8290: 72 2c 20 74 68 65 73 65 20 6d 61 63 72 6f 73 20 r, these macros
82a0: 6d 61 79 20 61 6c 73 6f 20 62 65 20 75 73 65 64 may also be used
82b0: 20 74 6f 20 73 75 70 70 72 65 73 73 20 77 61 72 to suppress war
82c0: 6e 69 6e 67 73 20 72 65 6c 61 74 65 64 20 74 6f nings related to
82d0: 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 73 20 74 .** parameters t
82e0: 68 61 74 20 6d 61 79 20 6f 72 20 6d 61 79 20 6e hat may or may n
82f0: 6f 74 20 62 65 20 75 73 65 64 20 64 65 70 65 6e ot be used depen
8300: 64 69 6e 67 20 6f 6e 20 63 6f 6d 70 69 6c 61 74 ding on compilat
8310: 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a 2a 2a 20 ion options..**
8320: 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 6f 73 For example thos
8330: 65 20 70 61 72 61 6d 65 74 65 72 73 20 6f 6e 6c e parameters onl
8340: 79 20 75 73 65 64 20 69 6e 20 61 73 73 65 72 74 y used in assert
8350: 28 29 20 73 74 61 74 65 6d 65 6e 74 73 2e 20 49 () statements. I
8360: 6e 20 74 68 65 73 65 0a 2a 2a 20 63 61 73 65 73 n these.** cases
8370: 20 74 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 the parameters
8380: 61 72 65 20 6e 61 6d 65 64 20 61 73 20 70 65 72 are named as per
8390: 20 74 68 65 20 75 73 75 61 6c 20 63 6f 6e 76 65 the usual conve
83a0: 6e 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 66 69 ntions..*/.#defi
83b0: 6e 65 20 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 ne UNUSED_PARAME
83c0: 54 45 52 28 78 29 20 28 76 6f 69 64 29 28 78 29 TER(x) (void)(x)
83d0: 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 5f .#define UNUSED_
83e0: 50 41 52 41 4d 45 54 45 52 32 28 78 2c 79 29 20 PARAMETER2(x,y)
83f0: 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 UNUSED_PARAMETER
8400: 28 78 29 2c 55 4e 55 53 45 44 5f 50 41 52 41 4d (x),UNUSED_PARAM
8410: 45 54 45 52 28 79 29 0a 0a 2f 2a 0a 2a 2a 20 46 ETER(y)../*.** F
8420: 6f 72 77 61 72 64 20 72 65 66 65 72 65 6e 63 65 orward reference
8430: 73 20 74 6f 20 73 74 72 75 63 74 75 72 65 73 0a s to structures.
8440: 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
8450: 74 20 41 67 67 49 6e 66 6f 20 41 67 67 49 6e 66 t AggInfo AggInf
8460: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
8470: 74 20 41 75 74 68 43 6f 6e 74 65 78 74 20 41 75 t AuthContext Au
8480: 74 68 43 6f 6e 74 65 78 74 3b 0a 74 79 70 65 64 thContext;.typed
8490: 65 66 20 73 74 72 75 63 74 20 41 75 74 6f 69 6e ef struct Autoin
84a0: 63 49 6e 66 6f 20 41 75 74 6f 69 6e 63 49 6e 66 cInfo AutoincInf
84b0: 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 o;.typedef struc
84c0: 74 20 42 69 74 76 65 63 20 42 69 74 76 65 63 3b t Bitvec Bitvec;
84d0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
84e0: 43 6f 6c 6c 53 65 71 20 43 6f 6c 6c 53 65 71 3b CollSeq CollSeq;
84f0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8500: 43 6f 6c 75 6d 6e 20 43 6f 6c 75 6d 6e 3b 0a 74 Column Column;.t
8510: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 44 62 ypedef struct Db
8520: 20 44 62 3b 0a 74 79 70 65 64 65 66 20 73 74 72 Db;.typedef str
8530: 75 63 74 20 53 63 68 65 6d 61 20 53 63 68 65 6d uct Schema Schem
8540: 61 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 a;.typedef struc
8550: 74 20 45 78 70 72 20 45 78 70 72 3b 0a 74 79 70 t Expr Expr;.typ
8560: 65 64 65 66 20 73 74 72 75 63 74 20 45 78 70 72 edef struct Expr
8570: 4c 69 73 74 20 45 78 70 72 4c 69 73 74 3b 0a 74 List ExprList;.t
8580: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 45 78 ypedef struct Ex
8590: 70 72 53 70 61 6e 20 45 78 70 72 53 70 61 6e 3b prSpan ExprSpan;
85a0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
85b0: 46 4b 65 79 20 46 4b 65 79 3b 0a 74 79 70 65 64 FKey FKey;.typed
85c0: 65 66 20 73 74 72 75 63 74 20 46 75 6e 63 44 65 ef struct FuncDe
85d0: 73 74 72 75 63 74 6f 72 20 46 75 6e 63 44 65 73 structor FuncDes
85e0: 74 72 75 63 74 6f 72 3b 0a 74 79 70 65 64 65 66 tructor;.typedef
85f0: 20 73 74 72 75 63 74 20 46 75 6e 63 44 65 66 20 struct FuncDef
8600: 46 75 6e 63 44 65 66 3b 0a 74 79 70 65 64 65 66 FuncDef;.typedef
8610: 20 73 74 72 75 63 74 20 46 75 6e 63 44 65 66 48 struct FuncDefH
8620: 61 73 68 20 46 75 6e 63 44 65 66 48 61 73 68 3b ash FuncDefHash;
8630: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
8640: 49 64 4c 69 73 74 20 49 64 4c 69 73 74 3b 0a 74 IdList IdList;.t
8650: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 49 6e ypedef struct In
8660: 64 65 78 20 49 6e 64 65 78 3b 0a 74 79 70 65 64 dex Index;.typed
8670: 65 66 20 73 74 72 75 63 74 20 49 6e 64 65 78 53 ef struct IndexS
8680: 61 6d 70 6c 65 20 49 6e 64 65 78 53 61 6d 70 6c ample IndexSampl
8690: 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 e;.typedef struc
86a0: 74 20 4b 65 79 43 6c 61 73 73 20 4b 65 79 43 6c t KeyClass KeyCl
86b0: 61 73 73 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ass;.typedef str
86c0: 75 63 74 20 4b 65 79 49 6e 66 6f 20 4b 65 79 49 uct KeyInfo KeyI
86d0: 6e 66 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 72 nfo;.typedef str
86e0: 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 20 4c 6f uct Lookaside Lo
86f0: 6f 6b 61 73 69 64 65 3b 0a 74 79 70 65 64 65 66 okaside;.typedef
8700: 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 struct Lookasid
8710: 65 53 6c 6f 74 20 4c 6f 6f 6b 61 73 69 64 65 53 eSlot LookasideS
8720: 6c 6f 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 lot;.typedef str
8730: 75 63 74 20 4d 6f 64 75 6c 65 20 4d 6f 64 75 6c uct Module Modul
8740: 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 e;.typedef struc
8750: 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 4e 61 t NameContext Na
8760: 6d 65 43 6f 6e 74 65 78 74 3b 0a 74 79 70 65 64 meContext;.typed
8770: 65 66 20 73 74 72 75 63 74 20 50 61 72 73 65 20 ef struct Parse
8780: 50 61 72 73 65 3b 0a 74 79 70 65 64 65 66 20 73 Parse;.typedef s
8790: 74 72 75 63 74 20 50 72 65 55 70 64 61 74 65 20 truct PreUpdate
87a0: 50 72 65 55 70 64 61 74 65 3b 0a 74 79 70 65 64 PreUpdate;.typed
87b0: 65 66 20 73 74 72 75 63 74 20 50 72 69 6e 74 66 ef struct Printf
87c0: 41 72 67 75 6d 65 6e 74 73 20 50 72 69 6e 74 66 Arguments Printf
87d0: 41 72 67 75 6d 65 6e 74 73 3b 0a 74 79 70 65 64 Arguments;.typed
87e0: 65 66 20 73 74 72 75 63 74 20 52 6f 77 53 65 74 ef struct RowSet
87f0: 20 52 6f 77 53 65 74 3b 0a 74 79 70 65 64 65 66 RowSet;.typedef
8800: 20 73 74 72 75 63 74 20 53 61 76 65 70 6f 69 6e struct Savepoin
8810: 74 20 53 61 76 65 70 6f 69 6e 74 3b 0a 74 79 70 t Savepoint;.typ
8820: 65 64 65 66 20 73 74 72 75 63 74 20 53 65 6c 65 edef struct Sele
8830: 63 74 20 53 65 6c 65 63 74 3b 0a 74 79 70 65 64 ct Select;.typed
8840: 65 66 20 73 74 72 75 63 74 20 53 51 4c 69 74 65 ef struct SQLite
8850: 54 68 72 65 61 64 20 53 51 4c 69 74 65 54 68 72 Thread SQLiteThr
8860: 65 61 64 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ead;.typedef str
8870: 75 63 74 20 53 65 6c 65 63 74 44 65 73 74 20 53 uct SelectDest S
8880: 65 6c 65 63 74 44 65 73 74 3b 0a 74 79 70 65 64 electDest;.typed
8890: 65 66 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 ef struct SrcLis
88a0: 74 20 53 72 63 4c 69 73 74 3b 0a 74 79 70 65 64 t SrcList;.typed
88b0: 65 66 20 73 74 72 75 63 74 20 53 74 72 41 63 63 ef struct StrAcc
88c0: 75 6d 20 53 74 72 41 63 63 75 6d 3b 0a 74 79 70 um StrAccum;.typ
88d0: 65 64 65 66 20 73 74 72 75 63 74 20 54 61 62 6c edef struct Tabl
88e0: 65 20 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 66 e Table;.typedef
88f0: 20 73 74 72 75 63 74 20 54 61 62 6c 65 4c 6f 63 struct TableLoc
8900: 6b 20 54 61 62 6c 65 4c 6f 63 6b 3b 0a 74 79 70 k TableLock;.typ
8910: 65 64 65 66 20 73 74 72 75 63 74 20 54 6f 6b 65 edef struct Toke
8920: 6e 20 54 6f 6b 65 6e 3b 0a 74 79 70 65 64 65 66 n Token;.typedef
8930: 20 73 74 72 75 63 74 20 54 72 65 65 56 69 65 77 struct TreeView
8940: 20 54 72 65 65 56 69 65 77 3b 0a 74 79 70 65 64 TreeView;.typed
8950: 65 66 20 73 74 72 75 63 74 20 54 72 69 67 67 65 ef struct Trigge
8960: 72 20 54 72 69 67 67 65 72 3b 0a 74 79 70 65 64 r Trigger;.typed
8970: 65 66 20 73 74 72 75 63 74 20 54 72 69 67 67 65 ef struct Trigge
8980: 72 50 72 67 20 54 72 69 67 67 65 72 50 72 67 3b rPrg TriggerPrg;
8990: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
89a0: 54 72 69 67 67 65 72 53 74 65 70 20 54 72 69 67 TriggerStep Trig
89b0: 67 65 72 53 74 65 70 3b 0a 74 79 70 65 64 65 66 gerStep;.typedef
89c0: 20 73 74 72 75 63 74 20 55 6e 70 61 63 6b 65 64 struct Unpacked
89d0: 52 65 63 6f 72 64 20 55 6e 70 61 63 6b 65 64 52 Record UnpackedR
89e0: 65 63 6f 72 64 3b 0a 74 79 70 65 64 65 66 20 73 ecord;.typedef s
89f0: 74 72 75 63 74 20 56 54 61 62 6c 65 20 56 54 61 truct VTable VTa
8a00: 62 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ble;.typedef str
8a10: 75 63 74 20 56 74 61 62 43 74 78 20 56 74 61 62 uct VtabCtx Vtab
8a20: 43 74 78 3b 0a 74 79 70 65 64 65 66 20 73 74 72 Ctx;.typedef str
8a30: 75 63 74 20 57 61 6c 6b 65 72 20 57 61 6c 6b 65 uct Walker Walke
8a40: 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 r;.typedef struc
8a50: 74 20 57 68 65 72 65 49 6e 66 6f 20 57 68 65 72 t WhereInfo Wher
8a60: 65 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 20 73 eInfo;.typedef s
8a70: 74 72 75 63 74 20 57 69 74 68 20 57 69 74 68 3b truct With With;
8a80: 0a 0a 2f 2a 20 41 20 56 4c 69 73 74 20 6f 62 6a ../* A VList obj
8a90: 65 63 74 20 72 65 63 6f 72 64 73 20 61 20 6d 61 ect records a ma
8aa0: 70 70 69 6e 67 20 62 65 74 77 65 65 6e 20 70 61 pping between pa
8ab0: 72 61 6d 65 74 65 72 73 2f 76 61 72 69 61 62 6c rameters/variabl
8ac0: 65 73 2f 77 69 6c 64 63 61 72 64 73 0a 2a 2a 20 es/wildcards.**
8ad0: 69 6e 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 in the SQL state
8ae0: 6d 65 6e 74 20 28 73 75 63 68 20 61 73 20 24 61 ment (such as $a
8af0: 62 63 2c 20 40 70 71 72 2c 20 6f 72 20 3a 78 79 bc, @pqr, or :xy
8b00: 7a 29 20 61 6e 64 20 74 68 65 20 69 6e 74 65 67 z) and the integ
8b10: 65 72 0a 2a 2a 20 76 61 72 69 61 62 6c 65 20 6e er.** variable n
8b20: 75 6d 62 65 72 20 61 73 73 6f 63 69 61 74 65 64 umber associated
8b30: 20 77 69 74 68 20 74 68 61 74 20 70 61 72 61 6d with that param
8b40: 65 74 65 72 2e 20 20 53 65 65 20 74 68 65 20 66 eter. See the f
8b50: 6f 72 6d 61 74 20 64 65 73 63 72 69 70 74 69 6f ormat descriptio
8b60: 6e 0a 2a 2a 20 6f 6e 20 74 68 65 20 73 71 6c 69 n.** on the sqli
8b70: 74 65 33 56 4c 69 73 74 41 64 64 28 29 20 72 6f te3VListAdd() ro
8b80: 75 74 69 6e 65 20 66 6f 72 20 6d 6f 72 65 20 69 utine for more i
8b90: 6e 66 6f 72 6d 61 74 69 6f 6e 2e 20 20 41 20 56 nformation. A V
8ba0: 4c 69 73 74 20 69 73 20 72 65 61 6c 6c 79 0a 2a List is really.*
8bb0: 2a 20 6a 75 73 74 20 61 6e 20 61 72 72 61 79 20 * just an array
8bc0: 6f 66 20 69 6e 74 65 67 65 72 73 2e 0a 2a 2f 0a of integers..*/.
8bd0: 74 79 70 65 64 65 66 20 69 6e 74 20 56 4c 69 73 typedef int VLis
8be0: 74 3b 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 65 72 20 t;../*.** Defer
8bf0: 73 6f 75 72 63 69 6e 67 20 76 64 62 65 2e 68 20 sourcing vdbe.h
8c00: 61 6e 64 20 62 74 72 65 65 2e 68 20 75 6e 74 69 and btree.h unti
8c10: 6c 20 61 66 74 65 72 20 74 68 65 20 22 75 38 22 l after the "u8"
8c20: 20 61 6e 64 0a 2a 2a 20 22 42 75 73 79 48 61 6e and.** "BusyHan
8c30: 64 6c 65 72 22 20 74 79 70 65 64 65 66 73 2e 20 dler" typedefs.
8c40: 76 64 62 65 2e 68 20 61 6c 73 6f 20 72 65 71 75 vdbe.h also requ
8c50: 69 72 65 73 20 61 20 66 65 77 20 6f 66 20 74 68 ires a few of th
8c60: 65 20 6f 70 61 71 75 65 0a 2a 2a 20 70 6f 69 6e e opaque.** poin
8c70: 74 65 72 20 74 79 70 65 73 20 28 69 2e 65 2e 20 ter types (i.e.
8c80: 46 75 6e 63 44 65 66 29 20 64 65 66 69 6e 65 64 FuncDef) defined
8c90: 20 61 62 6f 76 65 2e 0a 2a 2f 0a 23 69 6e 63 6c above..*/.#incl
8ca0: 75 64 65 20 22 62 74 72 65 65 2e 68 22 0a 23 69 ude "btree.h".#i
8cb0: 6e 63 6c 75 64 65 20 22 76 64 62 65 2e 68 22 0a nclude "vdbe.h".
8cc0: 23 69 6e 63 6c 75 64 65 20 22 70 61 67 65 72 2e #include "pager.
8cd0: 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 63 61 h".#include "pca
8ce0: 63 68 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 che.h".#include
8cf0: 22 6f 73 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 "os.h".#include
8d00: 22 6d 75 74 65 78 2e 68 22 0a 0a 2f 2a 20 54 68 "mutex.h"../* Th
8d10: 65 20 53 51 4c 49 54 45 5f 45 58 54 52 41 5f 44 e SQLITE_EXTRA_D
8d20: 55 52 41 42 4c 45 20 63 6f 6d 70 69 6c 65 2d 74 URABLE compile-t
8d30: 69 6d 65 20 6f 70 74 69 6f 6e 20 75 73 65 64 20 ime option used
8d40: 74 6f 20 73 65 74 20 74 68 65 20 64 65 66 61 75 to set the defau
8d50: 6c 74 0a 2a 2a 20 73 79 6e 63 68 72 6f 6e 6f 75 lt.** synchronou
8d60: 73 20 73 65 74 74 69 6e 67 20 74 6f 20 45 58 54 s setting to EXT
8d70: 52 41 2e 20 20 49 74 20 69 73 20 6e 6f 20 6c 6f RA. It is no lo
8d80: 6e 67 65 72 20 73 75 70 70 6f 72 74 65 64 2e 0a nger supported..
8d90: 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
8da0: 5f 45 58 54 52 41 5f 44 55 52 41 42 4c 45 0a 23 _EXTRA_DURABLE.#
8db0: 20 77 61 72 6e 69 6e 67 20 55 73 65 20 53 51 4c warning Use SQL
8dc0: 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 ITE_DEFAULT_SYNC
8dd0: 48 52 4f 4e 4f 55 53 3d 33 20 69 6e 73 74 65 61 HRONOUS=3 instea
8de0: 64 20 6f 66 20 53 51 4c 49 54 45 5f 45 58 54 52 d of SQLITE_EXTR
8df0: 41 5f 44 55 52 41 42 4c 45 0a 23 20 64 65 66 69 A_DURABLE.# defi
8e00: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
8e10: 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 33 0a T_SYNCHRONOUS 3.
8e20: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 #endif../*.** De
8e30: 66 61 75 6c 74 20 73 79 6e 63 68 72 6f 6e 6f 75 fault synchronou
8e40: 73 20 6c 65 76 65 6c 73 2e 0a 2a 2a 0a 2a 2a 20 s levels..**.**
8e50: 4e 6f 74 65 20 74 68 61 74 20 28 66 6f 72 20 68 Note that (for h
8e60: 69 73 74 6f 72 63 61 6c 20 72 65 61 73 6f 6e 73 istorcal reasons
8e70: 29 20 74 68 65 20 50 41 47 45 52 5f 53 59 4e 43 ) the PAGER_SYNC
8e80: 48 52 4f 4e 4f 55 53 5f 2a 20 6d 61 63 72 6f 73 HRONOUS_* macros
8e90: 20 64 69 66 66 65 72 0a 2a 2a 20 66 72 6f 6d 20 differ.** from
8ea0: 74 68 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 the SQLITE_DEFAU
8eb0: 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 76 LT_SYNCHRONOUS v
8ec0: 61 6c 75 65 20 62 79 20 31 2e 0a 2a 2a 0a 2a 2a alue by 1..**.**
8ed0: 20 20 20 20 20 20 20 20 20 20 20 50 41 47 45 52 PAGER
8ee0: 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 20 20 20 _SYNCHRONOUS
8ef0: 20 20 20 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 DEFAULT_SYNCH
8f00: 52 4f 4e 4f 55 53 0a 2a 2a 20 20 20 4f 46 46 20 RONOUS.** OFF
8f10: 20 20 20 20 20 20 20 20 20 20 31 20 20 20 20 20 1
8f20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8f30: 20 20 20 20 30 0a 2a 2a 20 20 20 4e 4f 52 4d 41 0.** NORMA
8f40: 4c 20 20 20 20 20 20 20 20 32 20 20 20 20 20 20 L 2
8f50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8f60: 20 20 20 31 0a 2a 2a 20 20 20 46 55 4c 4c 20 20 1.** FULL
8f70: 20 20 20 20 20 20 20 20 33 20 20 20 20 20 20 20 3
8f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8f90: 20 20 32 0a 2a 2a 20 20 20 45 58 54 52 41 20 20 2.** EXTRA
8fa0: 20 20 20 20 20 20 20 34 20 20 20 20 20 20 20 20 4
8fb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8fc0: 20 33 0a 2a 2a 0a 2a 2a 20 54 68 65 20 22 50 52 3.**.** The "PR
8fd0: 41 47 4d 41 20 73 79 6e 63 68 72 6f 6e 6f 75 73 AGMA synchronous
8fe0: 22 20 73 74 61 74 65 6d 65 6e 74 20 61 6c 73 6f " statement also
8ff0: 20 75 73 65 73 20 74 68 65 20 7a 65 72 6f 2d 62 uses the zero-b
9000: 61 73 65 64 20 6e 75 6d 62 65 72 73 2e 0a 2a 2a ased numbers..**
9010: 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 2c In other words,
9020: 20 74 68 65 20 7a 65 72 6f 2d 62 61 73 65 64 20 the zero-based
9030: 6e 75 6d 62 65 72 73 20 61 72 65 20 75 73 65 64 numbers are used
9040: 20 66 6f 72 20 61 6c 6c 20 65 78 74 65 72 6e 61 for all externa
9050: 6c 20 69 6e 74 65 72 66 61 63 65 73 0a 2a 2a 20 l interfaces.**
9060: 61 6e 64 20 74 68 65 20 6f 6e 65 2d 62 61 73 65 and the one-base
9070: 64 20 76 61 6c 75 65 73 20 61 72 65 20 75 73 65 d values are use
9080: 64 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 0a 2a 2f d internally..*/
9090: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
90a0: 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e DEFAULT_SYNCHRON
90b0: 4f 55 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c OUS.# define SQL
90c0: 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 ITE_DEFAULT_SYNC
90d0: 48 52 4f 4e 4f 55 53 20 28 50 41 47 45 52 5f 53 HRONOUS (PAGER_S
90e0: 59 4e 43 48 52 4f 4e 4f 55 53 5f 46 55 4c 4c 2d YNCHRONOUS_FULL-
90f0: 31 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 1).#endif.#ifnde
9100: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
9110: 5f 57 41 4c 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 _WAL_SYNCHRONOUS
9120: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
9130: 5f 44 45 46 41 55 4c 54 5f 57 41 4c 5f 53 59 4e _DEFAULT_WAL_SYN
9140: 43 48 52 4f 4e 4f 55 53 20 53 51 4c 49 54 45 5f CHRONOUS SQLITE_
9150: 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f 4e DEFAULT_SYNCHRON
9160: 4f 55 53 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a OUS.#endif../*.*
9170: 2a 20 45 61 63 68 20 64 61 74 61 62 61 73 65 20 * Each database
9180: 66 69 6c 65 20 74 6f 20 62 65 20 61 63 63 65 73 file to be acces
9190: 73 65 64 20 62 79 20 74 68 65 20 73 79 73 74 65 sed by the syste
91a0: 6d 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 m is an instance
91b0: 0a 2a 2a 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f .** of the follo
91c0: 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e 20 wing structure.
91d0: 20 54 68 65 72 65 20 61 72 65 20 6e 6f 72 6d 61 There are norma
91e0: 6c 6c 79 20 74 77 6f 20 6f 66 20 74 68 65 73 65 lly two of these
91f0: 20 73 74 72 75 63 74 75 72 65 73 0a 2a 2a 20 69 structures.** i
9200: 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 44 62 n the sqlite.aDb
9210: 5b 5d 20 61 72 72 61 79 2e 20 20 61 44 62 5b 30 [] array. aDb[0
9220: 5d 20 69 73 20 74 68 65 20 6d 61 69 6e 20 64 61 ] is the main da
9230: 74 61 62 61 73 65 20 66 69 6c 65 20 61 6e 64 0a tabase file and.
9240: 2a 2a 20 61 44 62 5b 31 5d 20 69 73 20 74 68 65 ** aDb[1] is the
9250: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 75 database file u
9260: 73 65 64 20 74 6f 20 68 6f 6c 64 20 74 65 6d 70 sed to hold temp
9270: 6f 72 61 72 79 20 74 61 62 6c 65 73 2e 20 20 41 orary tables. A
9280: 64 64 69 74 69 6f 6e 61 6c 0a 2a 2a 20 64 61 74 dditional.** dat
9290: 61 62 61 73 65 73 20 6d 61 79 20 62 65 20 61 74 abases may be at
92a0: 74 61 63 68 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 tached..*/.struc
92b0: 74 20 44 62 20 7b 0a 20 20 63 68 61 72 20 2a 7a t Db {. char *z
92c0: 44 62 53 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a DbSName; /*
92d0: 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 64 61 Name of this da
92e0: 74 61 62 61 73 65 2e 20 28 73 63 68 65 6d 61 20 tabase. (schema
92f0: 6e 61 6d 65 2c 20 6e 6f 74 20 66 69 6c 65 6e 61 name, not filena
9300: 6d 65 29 20 2a 2f 0a 20 20 42 74 72 65 65 20 2a me) */. Btree *
9310: 70 42 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a pBt; /*
9320: 20 54 68 65 20 42 2a 54 72 65 65 20 73 74 72 75 The B*Tree stru
9330: 63 74 75 72 65 20 66 6f 72 20 74 68 69 73 20 64 cture for this d
9340: 61 74 61 62 61 73 65 20 66 69 6c 65 20 2a 2f 0a atabase file */.
9350: 20 20 75 38 20 73 61 66 65 74 79 5f 6c 65 76 65 u8 safety_leve
9360: 6c 3b 20 20 20 20 20 2f 2a 20 48 6f 77 20 61 67 l; /* How ag
9370: 67 72 65 73 73 69 76 65 20 61 74 20 73 79 6e 63 gressive at sync
9380: 69 6e 67 20 64 61 74 61 20 74 6f 20 64 69 73 6b ing data to disk
9390: 20 2a 2f 0a 20 20 75 38 20 62 53 79 6e 63 53 65 */. u8 bSyncSe
93a0: 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 t; /* Tr
93b0: 75 65 20 69 66 20 22 50 52 41 47 4d 41 20 73 79 ue if "PRAGMA sy
93c0: 6e 63 68 72 6f 6e 6f 75 73 3d 4e 22 20 68 61 73 nchronous=N" has
93d0: 20 62 65 65 6e 20 72 75 6e 20 2a 2f 0a 20 20 53 been run */. S
93e0: 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 chema *pSchema;
93f0: 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 /* Pointer t
9400: 6f 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d o database schem
9410: 61 20 28 70 6f 73 73 69 62 6c 79 20 73 68 61 72 a (possibly shar
9420: 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ed) */.};../*.**
9430: 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
9440: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
9450: 72 75 63 74 75 72 65 20 73 74 6f 72 65 73 20 61 ructure stores a
9460: 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d 61 database schema
9470: 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 53 63 68 ..**.** Most Sch
9480: 65 6d 61 20 6f 62 6a 65 63 74 73 20 61 72 65 20 ema objects are
9490: 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 associated with
94a0: 61 20 42 74 72 65 65 2e 20 20 54 68 65 20 65 78 a Btree. The ex
94b0: 63 65 70 74 69 6f 6e 20 69 73 0a 2a 2a 20 74 68 ception is.** th
94c0: 65 20 53 63 68 65 6d 61 20 66 6f 72 20 74 68 65 e Schema for the
94d0: 20 54 45 4d 50 20 64 61 74 61 62 61 65 73 20 28 TEMP databaes (
94e0: 73 71 6c 69 74 65 33 2e 61 44 62 5b 31 5d 29 20 sqlite3.aDb[1])
94f0: 77 68 69 63 68 20 69 73 20 66 72 65 65 2d 73 74 which is free-st
9500: 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 6e 20 73 68 anding..** In sh
9510: 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 2c ared cache mode,
9520: 20 61 20 73 69 6e 67 6c 65 20 53 63 68 65 6d 61 a single Schema
9530: 20 6f 62 6a 65 63 74 20 63 61 6e 20 62 65 20 73 object can be s
9540: 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 70 6c hared by multipl
9550: 65 0a 2a 2a 20 42 74 72 65 65 73 20 74 68 61 74 e.** Btrees that
9560: 20 72 65 66 65 72 20 74 6f 20 74 68 65 20 73 61 refer to the sa
9570: 6d 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 42 74 me underlying Bt
9580: 53 68 61 72 65 64 20 6f 62 6a 65 63 74 2e 0a 2a Shared object..*
9590: 2a 0a 2a 2a 20 53 63 68 65 6d 61 20 6f 62 6a 65 *.** Schema obje
95a0: 63 74 73 20 61 72 65 20 61 75 74 6f 6d 61 74 69 cts are automati
95b0: 63 61 6c 6c 79 20 64 65 61 6c 6c 6f 63 61 74 65 cally deallocate
95c0: 64 20 77 68 65 6e 20 74 68 65 20 6c 61 73 74 20 d when the last
95d0: 42 74 72 65 65 20 74 68 61 74 0a 2a 2a 20 72 65 Btree that.** re
95e0: 66 65 72 65 6e 63 65 73 20 74 68 65 6d 20 69 73 ferences them is
95f0: 20 64 65 73 74 72 6f 79 65 64 2e 20 20 20 54 68 destroyed. Th
9600: 65 20 54 45 4d 50 20 53 63 68 65 6d 61 20 69 73 e TEMP Schema is
9610: 20 6d 61 6e 75 61 6c 6c 79 20 66 72 65 65 64 20 manually freed
9620: 62 79 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 63 6c by.** sqlite3_cl
9630: 6f 73 65 28 29 2e 0a 2a 0a 2a 2a 20 41 20 74 68 ose()..*.** A th
9640: 72 65 61 64 20 6d 75 73 74 20 62 65 20 68 6f 6c read must be hol
9650: 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f 6e 20 ding a mutex on
9660: 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e the correspondin
9670: 67 20 42 74 72 65 65 20 69 6e 20 6f 72 64 65 72 g Btree in order
9680: 0a 2a 2a 20 74 6f 20 61 63 63 65 73 73 20 53 63 .** to access Sc
9690: 68 65 6d 61 20 63 6f 6e 74 65 6e 74 2e 20 20 54 hema content. T
96a0: 68 69 73 20 69 6d 70 6c 69 65 73 20 74 68 61 74 his implies that
96b0: 20 74 68 65 20 74 68 72 65 61 64 20 6d 75 73 74 the thread must
96c0: 20 61 6c 73 6f 20 62 65 0a 2a 2a 20 68 6f 6c 64 also be.** hold
96d0: 69 6e 67 20 61 20 6d 75 74 65 78 20 6f 6e 20 74 ing a mutex on t
96e0: 68 65 20 73 71 6c 69 74 65 33 20 63 6f 6e 6e 65 he sqlite3 conne
96f0: 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 20 74 68 ction pointer th
9700: 61 74 20 6f 77 6e 73 20 74 68 65 20 42 74 72 65 at owns the Btre
9710: 65 2e 0a 2a 2a 20 46 6f 72 20 61 20 54 45 4d 50 e..** For a TEMP
9720: 20 53 63 68 65 6d 61 2c 20 6f 6e 6c 79 20 74 68 Schema, only th
9730: 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 e connection mut
9740: 65 78 20 69 73 20 72 65 71 75 69 72 65 64 2e 0a ex is required..
9750: 2a 2f 0a 73 74 72 75 63 74 20 53 63 68 65 6d 61 */.struct Schema
9760: 20 7b 0a 20 20 69 6e 74 20 73 63 68 65 6d 61 5f {. int schema_
9770: 63 6f 6f 6b 69 65 3b 20 20 20 2f 2a 20 44 61 74 cookie; /* Dat
9780: 61 62 61 73 65 20 73 63 68 65 6d 61 20 76 65 72 abase schema ver
9790: 73 69 6f 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 sion number for
97a0: 74 68 69 73 20 66 69 6c 65 20 2a 2f 0a 20 20 69 this file */. i
97b0: 6e 74 20 69 47 65 6e 65 72 61 74 69 6f 6e 3b 20 nt iGeneration;
97c0: 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 74 69 6f /* Generatio
97d0: 6e 20 63 6f 75 6e 74 65 72 2e 20 20 49 6e 63 72 n counter. Incr
97e0: 65 6d 65 6e 74 65 64 20 77 69 74 68 20 65 61 63 emented with eac
97f0: 68 20 63 68 61 6e 67 65 20 2a 2f 0a 20 20 48 61 h change */. Ha
9800: 73 68 20 74 62 6c 48 61 73 68 3b 20 20 20 20 20 sh tblHash;
9810: 20 20 20 2f 2a 20 41 6c 6c 20 74 61 62 6c 65 73 /* All tables
9820: 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 indexed by name
9830: 20 2a 2f 0a 20 20 48 61 73 68 20 69 64 78 48 61 */. Hash idxHa
9840: 73 68 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 6c sh; /* Al
9850: 6c 20 28 6e 61 6d 65 64 29 20 69 6e 64 69 63 65 l (named) indice
9860: 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d s indexed by nam
9870: 65 20 2a 2f 0a 20 20 48 61 73 68 20 74 72 69 67 e */. Hash trig
9880: 48 61 73 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 Hash; /* A
9890: 6c 6c 20 74 72 69 67 67 65 72 73 20 69 6e 64 65 ll triggers inde
98a0: 78 65 64 20 62 79 20 6e 61 6d 65 20 2a 2f 0a 20 xed by name */.
98b0: 20 48 61 73 68 20 66 6b 65 79 48 61 73 68 3b 20 Hash fkeyHash;
98c0: 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 66 6f 72 /* All for
98d0: 65 69 67 6e 20 6b 65 79 73 20 62 79 20 72 65 66 eign keys by ref
98e0: 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 6e 61 erenced table na
98f0: 6d 65 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 me */. Table *p
9900: 53 65 71 54 61 62 3b 20 20 20 20 20 20 2f 2a 20 SeqTab; /*
9910: 54 68 65 20 73 71 6c 69 74 65 5f 73 65 71 75 65 The sqlite_seque
9920: 6e 63 65 20 74 61 62 6c 65 20 75 73 65 64 20 62 nce table used b
9930: 79 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 20 y AUTOINCREMENT
9940: 2a 2f 0a 20 20 75 38 20 66 69 6c 65 5f 66 6f 72 */. u8 file_for
9950: 6d 61 74 3b 20 20 20 20 20 20 2f 2a 20 53 63 68 mat; /* Sch
9960: 65 6d 61 20 66 6f 72 6d 61 74 20 76 65 72 73 69 ema format versi
9970: 6f 6e 20 66 6f 72 20 74 68 69 73 20 66 69 6c 65 on for this file
9980: 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 */. u8 enc;
9990: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 /* Te
99a0: 78 74 20 65 6e 63 6f 64 69 6e 67 20 75 73 65 64 xt encoding used
99b0: 20 62 79 20 74 68 69 73 20 64 61 74 61 62 61 73 by this databas
99c0: 65 20 2a 2f 0a 20 20 75 31 36 20 73 63 68 65 6d e */. u16 schem
99d0: 61 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 46 aFlags; /* F
99e0: 6c 61 67 73 20 61 73 73 6f 63 69 61 74 65 64 20 lags associated
99f0: 77 69 74 68 20 74 68 69 73 20 73 63 68 65 6d 61 with this schema
9a00: 20 2a 2f 0a 20 20 69 6e 74 20 63 61 63 68 65 5f */. int cache_
9a10: 73 69 7a 65 3b 20 20 20 20 20 20 2f 2a 20 4e 75 size; /* Nu
9a20: 6d 62 65 72 20 6f 66 20 70 61 67 65 73 20 74 6f mber of pages to
9a30: 20 75 73 65 20 69 6e 20 74 68 65 20 63 61 63 68 use in the cach
9a40: 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 e */.};../*.** T
9a50: 68 65 73 65 20 6d 61 63 72 6f 73 20 63 61 6e 20 hese macros can
9a60: 62 65 20 75 73 65 64 20 74 6f 20 74 65 73 74 2c be used to test,
9a70: 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 20 62 set, or clear b
9a80: 69 74 73 20 69 6e 20 74 68 65 0a 2a 2a 20 44 62 its in the.** Db
9a90: 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 67 73 20 .pSchema->flags
9aa0: 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e field..*/.#defin
9ab0: 65 20 44 62 48 61 73 50 72 6f 70 65 72 74 79 28 e DbHasProperty(
9ac0: 44 2c 49 2c 50 29 20 20 20 20 20 28 28 28 44 29 D,I,P) (((D)
9ad0: 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 ->aDb[I].pSchema
9ae0: 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 28 50 ->schemaFlags&(P
9af0: 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 ))==(P)).#define
9b00: 20 44 62 48 61 73 41 6e 79 50 72 6f 70 65 72 74 DbHasAnyPropert
9b10: 79 28 44 2c 49 2c 50 29 20 20 28 28 28 44 29 2d y(D,I,P) (((D)-
9b20: 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 2d >aDb[I].pSchema-
9b30: 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 28 50 29 >schemaFlags&(P)
9b40: 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 44 62 )!=0).#define Db
9b50: 53 65 74 50 72 6f 70 65 72 74 79 28 44 2c 49 2c SetProperty(D,I,
9b60: 50 29 20 20 20 20 20 28 44 29 2d 3e 61 44 62 5b P) (D)->aDb[
9b70: 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 I].pSchema->sche
9b80: 6d 61 46 6c 61 67 73 7c 3d 28 50 29 0a 23 64 65 maFlags|=(P).#de
9b90: 66 69 6e 65 20 44 62 43 6c 65 61 72 50 72 6f 70 fine DbClearProp
9ba0: 65 72 74 79 28 44 2c 49 2c 50 29 20 20 20 28 44 erty(D,I,P) (D
9bb0: 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d )->aDb[I].pSchem
9bc0: 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 3d a->schemaFlags&=
9bd0: 7e 28 50 29 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f ~(P)../*.** Allo
9be0: 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 74 wed values for t
9bf0: 68 65 20 44 42 2e 70 53 63 68 65 6d 61 2d 3e 66 he DB.pSchema->f
9c00: 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a 2a lags field..**.*
9c10: 2a 20 54 68 65 20 44 42 5f 53 63 68 65 6d 61 4c * The DB_SchemaL
9c20: 6f 61 64 65 64 20 66 6c 61 67 20 69 73 20 73 65 oaded flag is se
9c30: 74 20 61 66 74 65 72 20 74 68 65 20 64 61 74 61 t after the data
9c40: 62 61 73 65 20 73 63 68 65 6d 61 20 68 61 73 20 base schema has
9c50: 62 65 65 6e 0a 2a 2a 20 72 65 61 64 20 69 6e 74 been.** read int
9c60: 6f 20 69 6e 74 65 72 6e 61 6c 20 68 61 73 68 20 o internal hash
9c70: 74 61 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 44 42 tables..**.** DB
9c80: 5f 55 6e 72 65 73 65 74 56 69 65 77 73 20 6d 65 _UnresetViews me
9c90: 61 6e 73 20 74 68 61 74 20 6f 6e 65 20 6f 72 20 ans that one or
9ca0: 6d 6f 72 65 20 76 69 65 77 73 20 68 61 76 65 20 more views have
9cb0: 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 74 68 61 column names tha
9cc0: 74 0a 2a 2a 20 68 61 76 65 20 62 65 65 6e 20 66 t.** have been f
9cd0: 69 6c 6c 65 64 20 6f 75 74 2e 20 20 49 66 20 74 illed out. If t
9ce0: 68 65 20 73 63 68 65 6d 61 20 63 68 61 6e 67 65 he schema change
9cf0: 73 2c 20 74 68 65 73 65 20 63 6f 6c 75 6d 6e 20 s, these column
9d00: 6e 61 6d 65 73 20 6d 69 67 68 74 0a 2a 2a 20 63 names might.** c
9d10: 68 61 6e 67 65 73 20 61 6e 64 20 73 6f 20 74 68 hanges and so th
9d20: 65 20 76 69 65 77 20 77 69 6c 6c 20 6e 65 65 64 e view will need
9d30: 20 74 6f 20 62 65 20 72 65 73 65 74 2e 0a 2a 2f to be reset..*/
9d40: 0a 23 64 65 66 69 6e 65 20 44 42 5f 53 63 68 65 .#define DB_Sche
9d50: 6d 61 4c 6f 61 64 65 64 20 20 20 20 30 78 30 30 maLoaded 0x00
9d60: 30 31 20 20 2f 2a 20 54 68 65 20 73 63 68 65 6d 01 /* The schem
9d70: 61 20 68 61 73 20 62 65 65 6e 20 6c 6f 61 64 65 a has been loade
9d80: 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f d */.#define DB_
9d90: 55 6e 72 65 73 65 74 56 69 65 77 73 20 20 20 20 UnresetViews
9da0: 30 78 30 30 30 32 20 20 2f 2a 20 53 6f 6d 65 20 0x0002 /* Some
9db0: 76 69 65 77 73 20 68 61 76 65 20 64 65 66 69 6e views have defin
9dc0: 65 64 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 ed column names
9dd0: 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 45 6d */.#define DB_Em
9de0: 70 74 79 20 20 20 20 20 20 20 20 20 20 20 30 78 pty 0x
9df0: 30 30 30 34 20 20 2f 2a 20 54 68 65 20 66 69 6c 0004 /* The fil
9e00: 65 20 69 73 20 65 6d 70 74 79 20 28 6c 65 6e 67 e is empty (leng
9e10: 74 68 20 30 20 62 79 74 65 73 29 20 2a 2f 0a 0a th 0 bytes) */..
9e20: 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 /*.** The number
9e30: 20 6f 66 20 64 69 66 66 65 72 65 6e 74 20 6b 69 of different ki
9e40: 6e 64 73 20 6f 66 20 74 68 69 6e 67 73 20 74 68 nds of things th
9e50: 61 74 20 63 61 6e 20 62 65 20 6c 69 6d 69 74 65 at can be limite
9e60: 64 0a 2a 2a 20 75 73 69 6e 67 20 74 68 65 20 73 d.** using the s
9e70: 71 6c 69 74 65 33 5f 6c 69 6d 69 74 28 29 20 69 qlite3_limit() i
9e80: 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a 23 64 65 nterface..*/.#de
9e90: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 4c 49 fine SQLITE_N_LI
9ea0: 4d 49 54 20 28 53 51 4c 49 54 45 5f 4c 49 4d 49 MIT (SQLITE_LIMI
9eb0: 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 T_WORKER_THREADS
9ec0: 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b 61 +1)../*.** Looka
9ed0: 73 69 64 65 20 6d 61 6c 6c 6f 63 20 69 73 20 61 side malloc is a
9ee0: 20 73 65 74 20 6f 66 20 66 69 78 65 64 2d 73 69 set of fixed-si
9ef0: 7a 65 20 62 75 66 66 65 72 73 20 74 68 61 74 20 ze buffers that
9f00: 63 61 6e 20 62 65 20 75 73 65 64 0a 2a 2a 20 74 can be used.** t
9f10: 6f 20 73 61 74 69 73 66 79 20 73 6d 61 6c 6c 20 o satisfy small
9f20: 74 72 61 6e 73 69 65 6e 74 20 6d 65 6d 6f 72 79 transient memory
9f30: 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 72 65 71 75 allocation requ
9f40: 65 73 74 73 20 66 6f 72 20 6f 62 6a 65 63 74 73 ests for objects
9f50: 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65 64 20 77 .** associated w
9f60: 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 72 ith a particular
9f70: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
9f80: 74 69 6f 6e 2e 20 20 54 68 65 20 75 73 65 20 6f tion. The use o
9f90: 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 6d f.** lookaside m
9fa0: 61 6c 6c 6f 63 20 70 72 6f 76 69 64 65 73 20 61 alloc provides a
9fb0: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 70 65 72 significant per
9fc0: 66 6f 72 6d 61 6e 63 65 20 65 6e 68 61 6e 63 65 formance enhance
9fd0: 6d 65 6e 74 0a 2a 2a 20 28 61 70 70 72 6f 78 20 ment.** (approx
9fe0: 31 30 25 29 20 62 79 20 61 76 6f 69 64 69 6e 67 10%) by avoiding
9ff0: 20 6e 75 6d 65 72 6f 75 73 20 6d 61 6c 6c 6f 63 numerous malloc
a000: 2f 66 72 65 65 20 72 65 71 75 65 73 74 73 20 77 /free requests w
a010: 68 69 6c 65 20 70 61 72 73 69 6e 67 0a 2a 2a 20 hile parsing.**
a020: 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a SQL statements..
a030: 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 6f 6b 61 73 **.** The Lookas
a040: 69 64 65 20 73 74 72 75 63 74 75 72 65 20 68 6f ide structure ho
a050: 6c 64 73 20 63 6f 6e 66 69 67 75 72 61 74 69 6f lds configuratio
a060: 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 n information ab
a070: 6f 75 74 20 74 68 65 0a 2a 2a 20 6c 6f 6f 6b 61 out the.** looka
a080: 73 69 64 65 20 6d 61 6c 6c 6f 63 20 73 75 62 73 side malloc subs
a090: 79 73 74 65 6d 2e 20 20 45 61 63 68 20 61 76 61 ystem. Each ava
a0a0: 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 61 6c ilable memory al
a0b0: 6c 6f 63 61 74 69 6f 6e 20 69 6e 0a 2a 2a 20 74 location in.** t
a0c0: 68 65 20 6c 6f 6f 6b 61 73 69 64 65 20 73 75 62 he lookaside sub
a0d0: 73 79 73 74 65 6d 20 69 73 20 73 74 6f 72 65 64 system is stored
a0e0: 20 6f 6e 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 on a linked lis
a0f0: 74 20 6f 66 20 4c 6f 6f 6b 61 73 69 64 65 53 6c t of LookasideSl
a100: 6f 74 0a 2a 2a 20 6f 62 6a 65 63 74 73 2e 0a 2a ot.** objects..*
a110: 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 61 *.** Lookaside a
a120: 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 6f llocations are o
a130: 6e 6c 79 20 61 6c 6c 6f 77 65 64 20 66 6f 72 20 nly allowed for
a140: 6f 62 6a 65 63 74 73 20 74 68 61 74 20 61 72 65 objects that are
a150: 20 61 73 73 6f 63 69 61 74 65 64 0a 2a 2a 20 77 associated.** w
a160: 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 72 ith a particular
a170: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
a180: 74 69 6f 6e 2e 20 20 48 65 6e 63 65 2c 20 73 63 tion. Hence, sc
a190: 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f 6e hema information
a1a0: 20 63 61 6e 6e 6f 74 0a 2a 2a 20 62 65 20 73 74 cannot.** be st
a1b0: 6f 72 65 64 20 69 6e 20 6c 6f 6f 6b 61 73 69 64 ored in lookasid
a1c0: 65 20 62 65 63 61 75 73 65 20 69 6e 20 73 68 61 e because in sha
a1d0: 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 20 74 red cache mode t
a1e0: 68 65 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d he schema inform
a1f0: 61 74 69 6f 6e 0a 2a 2a 20 69 73 20 73 68 61 72 ation.** is shar
a200: 65 64 20 62 79 20 6d 75 6c 74 69 70 6c 65 20 64 ed by multiple d
a210: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
a220: 6f 6e 73 2e 20 20 54 68 65 72 65 66 6f 72 65 2c ons. Therefore,
a230: 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a 2a while parsing.*
a240: 2a 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 * schema informa
a250: 74 69 6f 6e 2c 20 74 68 65 20 4c 6f 6f 6b 61 73 tion, the Lookas
a260: 69 64 65 2e 62 45 6e 61 62 6c 65 64 20 66 6c 61 ide.bEnabled fla
a270: 67 20 69 73 20 63 6c 65 61 72 65 64 20 73 6f 20 g is cleared so
a280: 74 68 61 74 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 that.** lookasid
a290: 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 e allocations ar
a2a0: 65 20 6e 6f 74 20 75 73 65 64 20 74 6f 20 63 6f e not used to co
a2b0: 6e 73 74 72 75 63 74 20 74 68 65 20 73 63 68 65 nstruct the sche
a2c0: 6d 61 20 6f 62 6a 65 63 74 73 2e 0a 2a 2f 0a 73 ma objects..*/.s
a2d0: 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 20 truct Lookaside
a2e0: 7b 0a 20 20 75 33 32 20 62 44 69 73 61 62 6c 65 {. u32 bDisable
a2f0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f ; /* O
a300: 6e 6c 79 20 6f 70 65 72 61 74 65 20 74 68 65 20 nly operate the
a310: 6c 6f 6f 6b 61 73 69 64 65 20 77 68 65 6e 20 7a lookaside when z
a320: 65 72 6f 20 2a 2f 0a 20 20 75 31 36 20 73 7a 3b ero */. u16 sz;
a330: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a340: 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 /* Size of each
a350: 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 65 73 buffer in bytes
a360: 20 2a 2f 0a 20 20 75 38 20 62 4d 61 6c 6c 6f 63 */. u8 bMalloc
a370: 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ed; /*
a380: 20 54 72 75 65 20 69 66 20 70 53 74 61 72 74 20 True if pStart
a390: 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 73 71 obtained from sq
a3a0: 6c 69 74 65 33 5f 6d 61 6c 6c 6f 63 28 29 20 2a lite3_malloc() *
a3b0: 2f 0a 20 20 69 6e 74 20 6e 4f 75 74 3b 20 20 20 /. int nOut;
a3c0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
a3d0: 75 6d 62 65 72 20 6f 66 20 62 75 66 66 65 72 73 umber of buffers
a3e0: 20 63 75 72 72 65 6e 74 6c 79 20 63 68 65 63 6b currently check
a3f0: 65 64 20 6f 75 74 20 2a 2f 0a 20 20 69 6e 74 20 ed out */. int
a400: 6d 78 4f 75 74 3b 20 20 20 20 20 20 20 20 20 20 mxOut;
a410: 20 20 20 20 2f 2a 20 48 69 67 68 77 61 74 65 72 /* Highwater
a420: 20 6d 61 72 6b 20 66 6f 72 20 6e 4f 75 74 20 2a mark for nOut *
a430: 2f 0a 20 20 69 6e 74 20 61 6e 53 74 61 74 5b 33 /. int anStat[3
a440: 5d 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 30 ]; /* 0
a450: 3a 20 68 69 74 73 2e 20 20 31 3a 20 73 69 7a 65 : hits. 1: size
a460: 20 6d 69 73 73 65 73 2e 20 20 32 3a 20 66 75 6c misses. 2: ful
a470: 6c 20 6d 69 73 73 65 73 20 2a 2f 0a 20 20 4c 6f l misses */. Lo
a480: 6f 6b 61 73 69 64 65 53 6c 6f 74 20 2a 70 46 72 okasideSlot *pFr
a490: 65 65 3b 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 ee; /* List of
a4a0: 20 61 76 61 69 6c 61 62 6c 65 20 62 75 66 66 65 available buffe
a4b0: 72 73 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 53 rs */. void *pS
a4c0: 74 61 72 74 3b 20 20 20 20 20 20 20 20 20 20 20 tart;
a4d0: 2f 2a 20 46 69 72 73 74 20 62 79 74 65 20 6f 66 /* First byte of
a4e0: 20 61 76 61 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 available memor
a4f0: 79 20 73 70 61 63 65 20 2a 2f 0a 20 20 76 6f 69 y space */. voi
a500: 64 20 2a 70 45 6e 64 3b 20 20 20 20 20 20 20 20 d *pEnd;
a510: 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 62 79 /* First by
a520: 74 65 20 70 61 73 74 20 65 6e 64 20 6f 66 20 61 te past end of a
a530: 76 61 69 6c 61 62 6c 65 20 73 70 61 63 65 20 2a vailable space *
a540: 2f 0a 7d 3b 0a 73 74 72 75 63 74 20 4c 6f 6f 6b /.};.struct Look
a550: 61 73 69 64 65 53 6c 6f 74 20 7b 0a 20 20 4c 6f asideSlot {. Lo
a560: 6f 6b 61 73 69 64 65 53 6c 6f 74 20 2a 70 4e 65 okasideSlot *pNe
a570: 78 74 3b 20 20 20 20 2f 2a 20 4e 65 78 74 20 62 xt; /* Next b
a580: 75 66 66 65 72 20 69 6e 20 74 68 65 20 6c 69 73 uffer in the lis
a590: 74 20 6f 66 20 66 72 65 65 20 62 75 66 66 65 72 t of free buffer
a5a0: 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 s */.};../*.** A
a5b0: 20 68 61 73 68 20 74 61 62 6c 65 20 66 6f 72 20 hash table for
a5c0: 62 75 69 6c 74 2d 69 6e 20 66 75 6e 63 74 69 6f built-in functio
a5d0: 6e 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e 20 20 n definitions.
a5e0: 28 41 70 70 6c 69 63 61 74 69 6f 6e 2d 64 65 66 (Application-def
a5f0: 69 6e 65 64 0a 2a 2a 20 66 75 6e 63 74 69 6f 6e ined.** function
a600: 73 20 75 73 65 20 61 20 72 65 67 75 6c 61 72 20 s use a regular
a610: 74 61 62 6c 65 20 74 61 62 6c 65 20 66 72 6f 6d table table from
a620: 20 68 61 73 68 2e 68 2e 29 0a 2a 2a 0a 2a 2a 20 hash.h.).**.**
a630: 48 61 73 68 20 65 61 63 68 20 46 75 6e 63 44 65 Hash each FuncDe
a640: 66 20 73 74 72 75 63 74 75 72 65 20 69 6e 74 6f f structure into
a650: 20 6f 6e 65 20 6f 66 20 74 68 65 20 46 75 6e 63 one of the Func
a660: 44 65 66 48 61 73 68 2e 61 5b 5d 20 73 6c 6f 74 DefHash.a[] slot
a670: 73 2e 0a 2a 2a 20 43 6f 6c 6c 69 73 69 6f 6e 73 s..** Collisions
a680: 20 61 72 65 20 6f 6e 20 74 68 65 20 46 75 6e 63 are on the Func
a690: 44 65 66 2e 75 2e 70 48 61 73 68 20 63 68 61 69 Def.u.pHash chai
a6a0: 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 n..*/.#define SQ
a6b0: 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 5f 53 LITE_FUNC_HASH_S
a6c0: 5a 20 32 33 0a 73 74 72 75 63 74 20 46 75 6e 63 Z 23.struct Func
a6d0: 44 65 66 48 61 73 68 20 7b 0a 20 20 46 75 6e 63 DefHash {. Func
a6e0: 44 65 66 20 2a 61 5b 53 51 4c 49 54 45 5f 46 55 Def *a[SQLITE_FU
a6f0: 4e 43 5f 48 41 53 48 5f 53 5a 5d 3b 20 20 20 20 NC_HASH_SZ];
a700: 20 20 20 2f 2a 20 48 61 73 68 20 74 61 62 6c 65 /* Hash table
a710: 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 2a for functions *
a720: 2f 0a 7d 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c /.};..#ifdef SQL
a730: 49 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e 54 ITE_USER_AUTHENT
a740: 49 43 41 54 49 4f 4e 0a 2f 2a 0a 2a 2a 20 49 6e ICATION./*.** In
a750: 66 6f 72 6d 61 74 69 6f 6e 20 68 65 6c 64 20 69 formation held i
a760: 6e 20 74 68 65 20 22 73 71 6c 69 74 65 33 22 20 n the "sqlite3"
a770: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
a780: 69 6f 6e 20 6f 62 6a 65 63 74 20 61 6e 64 20 75 ion object and u
a790: 73 65 64 0a 2a 2a 20 74 6f 20 6d 61 6e 61 67 65 sed.** to manage
a7a0: 20 75 73 65 72 20 61 75 74 68 65 6e 74 69 63 61 user authentica
a7b0: 74 69 6f 6e 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 tion..*/.typedef
a7c0: 20 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 5f struct sqlite3_
a7d0: 75 73 65 72 61 75 74 68 20 73 71 6c 69 74 65 33 userauth sqlite3
a7e0: 5f 75 73 65 72 61 75 74 68 3b 0a 73 74 72 75 63 _userauth;.struc
a7f0: 74 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 75 t sqlite3_userau
a800: 74 68 20 7b 0a 20 20 75 38 20 61 75 74 68 4c 65 th {. u8 authLe
a810: 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 vel;
a820: 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 /* Current
a830: 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6c authentication l
a840: 65 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 evel */. int nA
a850: 75 74 68 50 57 3b 20 20 20 20 20 20 20 20 20 20 uthPW;
a860: 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
a870: 6f 66 20 74 68 65 20 7a 41 75 74 68 50 57 20 69 of the zAuthPW i
a880: 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 63 68 61 n bytes */. cha
a890: 72 20 2a 7a 41 75 74 68 50 57 3b 20 20 20 20 20 r *zAuthPW;
a8a0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 /* Pa
a8b0: 73 73 77 6f 72 64 20 75 73 65 64 20 74 6f 20 61 ssword used to a
a8c0: 75 74 68 65 6e 74 69 63 61 74 65 20 2a 2f 0a 20 uthenticate */.
a8d0: 20 63 68 61 72 20 2a 7a 41 75 74 68 55 73 65 72 char *zAuthUser
a8e0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
a8f0: 2a 20 55 73 65 72 20 6e 61 6d 65 20 75 73 65 64 * User name used
a900: 20 74 6f 20 61 75 74 68 65 6e 74 69 63 61 74 65 to authenticate
a910: 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 */.};../* Allow
a920: 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 73 71 ed values for sq
a930: 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 2e 61 lite3_userauth.a
a940: 75 74 68 4c 65 76 65 6c 20 2a 2f 0a 23 64 65 66 uthLevel */.#def
a950: 69 6e 65 20 55 41 55 54 48 5f 55 6e 6b 6e 6f 77 ine UAUTH_Unknow
a960: 6e 20 20 20 20 20 30 20 20 20 20 20 2f 2a 20 41 n 0 /* A
a970: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6e 6f uthentication no
a980: 74 20 79 65 74 20 63 68 65 63 6b 65 64 20 2a 2f t yet checked */
a990: 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f 46 .#define UAUTH_F
a9a0: 61 69 6c 20 20 20 20 20 20 20 20 31 20 20 20 20 ail 1
a9b0: 20 2f 2a 20 55 73 65 72 20 61 75 74 68 65 6e 74 /* User authent
a9c0: 69 63 61 74 69 6f 6e 20 66 61 69 6c 65 64 20 2a ication failed *
a9d0: 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f /.#define UAUTH_
a9e0: 55 73 65 72 20 20 20 20 20 20 20 20 32 20 20 20 User 2
a9f0: 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 74 /* Authenticat
aa00: 65 64 20 61 73 20 61 20 6e 6f 72 6d 61 6c 20 75 ed as a normal u
aa10: 73 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 55 ser */.#define U
aa20: 41 55 54 48 5f 41 64 6d 69 6e 20 20 20 20 20 20 AUTH_Admin
aa30: 20 33 20 20 20 20 20 2f 2a 20 41 75 74 68 65 6e 3 /* Authen
aa40: 74 69 63 61 74 65 64 20 61 73 20 61 6e 20 61 64 ticated as an ad
aa50: 6d 69 6e 69 73 74 72 61 74 6f 72 20 2a 2f 0a 0a ministrator */..
aa60: 2f 2a 20 46 75 6e 63 74 69 6f 6e 73 20 75 73 65 /* Functions use
aa70: 64 20 6f 6e 6c 79 20 62 79 20 75 73 65 72 20 61 d only by user a
aa80: 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 6c 6f 67 uthorization log
aa90: 69 63 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 ic */.int sqlite
aaa0: 33 55 73 65 72 41 75 74 68 54 61 62 6c 65 28 63 3UserAuthTable(c
aab0: 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 onst char*);.int
aac0: 20 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 68 sqlite3UserAuth
aad0: 43 68 65 63 6b 4c 6f 67 69 6e 28 73 71 6c 69 74 CheckLogin(sqlit
aae0: 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c e3*,const char*,
aaf0: 75 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 u8*);.void sqlit
ab00: 65 33 55 73 65 72 41 75 74 68 49 6e 69 74 28 73 e3UserAuthInit(s
ab10: 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 qlite3*);.void s
ab20: 71 6c 69 74 65 33 43 72 79 70 74 46 75 6e 63 28 qlite3CryptFunc(
ab30: 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
ab40: 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c ,int,sqlite3_val
ab50: 75 65 2a 2a 29 3b 0a 0a 23 65 6e 64 69 66 20 2f ue**);..#endif /
ab60: 2a 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 * SQLITE_USER_AU
ab70: 54 48 45 4e 54 49 43 41 54 49 4f 4e 20 2a 2f 0a THENTICATION */.
ab80: 0a 2f 2a 0a 2a 2a 20 74 79 70 65 64 65 66 20 66 ./*.** typedef f
ab90: 6f 72 20 74 68 65 20 61 75 74 68 6f 72 69 7a 61 or the authoriza
aba0: 74 69 6f 6e 20 63 61 6c 6c 62 61 63 6b 20 66 75 tion callback fu
abb0: 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 64 65 nction..*/.#ifde
abc0: 66 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 55 f SQLITE_USER_AU
abd0: 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a 20 20 74 THENTICATION. t
abe0: 79 70 65 64 65 66 20 69 6e 74 20 28 2a 73 71 6c ypedef int (*sql
abf0: 69 74 65 33 5f 78 61 75 74 68 29 28 76 6f 69 64 ite3_xauth)(void
ac00: 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 *,int,const char
ac10: 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f *,const char*,co
ac20: 6e 73 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 nst char*,.
ac30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ac40: 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 const
ac50: 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
ac60: 72 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 r*);.#else. typ
ac70: 65 64 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 74 edef int (*sqlit
ac80: 65 33 5f 78 61 75 74 68 29 28 76 6f 69 64 2a 2c e3_xauth)(void*,
ac90: 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c int,const char*,
aca0: 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 const char*,cons
acb0: 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 20 t char*,.
acc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
acd0: 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 68 const ch
ace0: 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 ar*);.#endif..#i
acf0: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
ad00: 54 5f 44 45 50 52 45 43 41 54 45 44 0a 2f 2a 20 T_DEPRECATED./*
ad10: 54 68 69 73 20 69 73 20 61 6e 20 65 78 74 72 61 This is an extra
ad20: 20 53 51 4c 49 54 45 5f 54 52 41 43 45 20 6d 61 SQLITE_TRACE ma
ad30: 63 72 6f 20 74 68 61 74 20 69 6e 64 69 63 61 74 cro that indicat
ad40: 65 73 20 22 6c 65 67 61 63 79 22 20 74 72 61 63 es "legacy" trac
ad50: 69 6e 67 0a 2a 2a 20 69 6e 20 74 68 65 20 73 74 ing.** in the st
ad60: 79 6c 65 20 6f 66 20 73 71 6c 69 74 65 33 5f 74 yle of sqlite3_t
ad70: 72 61 63 65 28 29 0a 2a 2f 0a 23 64 65 66 69 6e race().*/.#defin
ad80: 65 20 53 51 4c 49 54 45 5f 54 52 41 43 45 5f 4c e SQLITE_TRACE_L
ad90: 45 47 41 43 59 20 20 30 78 38 30 0a 23 65 6c 73 EGACY 0x80.#els
ada0: 65 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 e.#define SQLITE
adb0: 5f 54 52 41 43 45 5f 4c 45 47 41 43 59 20 20 30 _TRACE_LEGACY 0
adc0: 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 54 .#endif /* SQLIT
add0: 45 5f 4f 4d 49 54 5f 44 45 50 52 45 43 41 54 45 E_OMIT_DEPRECATE
ade0: 44 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 D */.../*.** Eac
adf0: 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 h database conne
ae00: 63 74 69 6f 6e 20 69 73 20 61 6e 20 69 6e 73 74 ction is an inst
ae10: 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c ance of the foll
ae20: 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e owing structure.
ae30: 0a 2a 2f 0a 73 74 72 75 63 74 20 73 71 6c 69 74 .*/.struct sqlit
ae40: 65 33 20 7b 0a 20 20 73 71 6c 69 74 65 33 5f 76 e3 {. sqlite3_v
ae50: 66 73 20 2a 70 56 66 73 3b 20 20 20 20 20 20 20 fs *pVfs;
ae60: 20 20 20 20 20 2f 2a 20 4f 53 20 49 6e 74 65 72 /* OS Inter
ae70: 66 61 63 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 face */. struct
ae80: 20 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 20 Vdbe *pVdbe;
ae90: 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 /* List
aea0: 6f 66 20 61 63 74 69 76 65 20 76 69 72 74 75 61 of active virtua
aeb0: 6c 20 6d 61 63 68 69 6e 65 73 20 2a 2f 0a 20 20 l machines */.
aec0: 43 6f 6c 6c 53 65 71 20 2a 70 44 66 6c 74 43 6f CollSeq *pDfltCo
aed0: 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ll; /*
aee0: 20 54 68 65 20 64 65 66 61 75 6c 74 20 63 6f 6c The default col
aef0: 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 20 lating sequence
af00: 28 42 49 4e 41 52 59 29 20 2a 2f 0a 20 20 73 71 (BINARY) */. sq
af10: 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 6d 75 74 lite3_mutex *mut
af20: 65 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 43 ex; /* C
af30: 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 65 78 20 onnection mutex
af40: 2a 2f 0a 20 20 44 62 20 2a 61 44 62 3b 20 20 20 */. Db *aDb;
af50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
af60: 20 20 20 2f 2a 20 41 6c 6c 20 62 61 63 6b 65 6e /* All backen
af70: 64 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 44 62 3b ds */. int nDb;
af80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
af90: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
afa0: 6f 66 20 62 61 63 6b 65 6e 64 73 20 63 75 72 72 of backends curr
afb0: 65 6e 74 6c 79 20 69 6e 20 75 73 65 20 2a 2f 0a ently in use */.
afc0: 20 20 69 6e 74 20 66 6c 61 67 73 3b 20 20 20 20 int flags;
afd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
afe0: 2f 2a 20 4d 69 73 63 65 6c 6c 61 6e 65 6f 75 73 /* Miscellaneous
aff0: 20 66 6c 61 67 73 2e 20 53 65 65 20 62 65 6c 6f flags. See belo
b000: 77 20 2a 2f 0a 20 20 69 36 34 20 6c 61 73 74 52 w */. i64 lastR
b010: 6f 77 69 64 3b 20 20 20 20 20 20 20 20 20 20 20 owid;
b020: 20 20 20 20 20 2f 2a 20 52 4f 57 49 44 20 6f 66 /* ROWID of
b030: 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 69 6e 73 most recent ins
b040: 65 72 74 20 28 73 65 65 20 61 62 6f 76 65 29 20 ert (see above)
b050: 2a 2f 0a 20 20 69 36 34 20 73 7a 4d 6d 61 70 3b */. i64 szMmap;
b060: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b070: 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 6d 6d /* Default mm
b080: 61 70 5f 73 69 7a 65 20 73 65 74 74 69 6e 67 20 ap_size setting
b090: 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e */. unsigned in
b0a0: 74 20 6f 70 65 6e 46 6c 61 67 73 3b 20 20 20 20 t openFlags;
b0b0: 20 20 20 2f 2a 20 46 6c 61 67 73 20 70 61 73 73 /* Flags pass
b0c0: 65 64 20 74 6f 20 73 71 6c 69 74 65 33 5f 76 66 ed to sqlite3_vf
b0d0: 73 2e 78 4f 70 65 6e 28 29 20 2a 2f 0a 20 20 69 s.xOpen() */. i
b0e0: 6e 74 20 65 72 72 43 6f 64 65 3b 20 20 20 20 20 nt errCode;
b0f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
b100: 4d 6f 73 74 20 72 65 63 65 6e 74 20 65 72 72 6f Most recent erro
b110: 72 20 63 6f 64 65 20 28 53 51 4c 49 54 45 5f 2a r code (SQLITE_*
b120: 29 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 4d 61 ) */. int errMa
b130: 73 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 sk;
b140: 20 20 20 20 20 2f 2a 20 26 20 72 65 73 75 6c 74 /* & result
b150: 20 63 6f 64 65 73 20 77 69 74 68 20 74 68 69 73 codes with this
b160: 20 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 6e before returnin
b170: 67 20 2a 2f 0a 20 20 69 6e 74 20 69 53 79 73 45 g */. int iSysE
b180: 72 72 6e 6f 3b 20 20 20 20 20 20 20 20 20 20 20 rrno;
b190: 20 20 20 20 20 2f 2a 20 45 72 72 6e 6f 20 76 61 /* Errno va
b1a0: 6c 75 65 20 66 72 6f 6d 20 6c 61 73 74 20 73 79 lue from last sy
b1b0: 73 74 65 6d 20 65 72 72 6f 72 20 2a 2f 0a 20 20 stem error */.
b1c0: 75 31 36 20 64 62 4f 70 74 46 6c 61 67 73 3b 20 u16 dbOptFlags;
b1d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
b1e0: 20 46 6c 61 67 73 20 74 6f 20 65 6e 61 62 6c 65 Flags to enable
b1f0: 2f 64 69 73 61 62 6c 65 20 6f 70 74 69 6d 69 7a /disable optimiz
b200: 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 75 38 20 65 ations */. u8 e
b210: 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
b220: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
b230: 74 20 65 6e 63 6f 64 69 6e 67 20 2a 2f 0a 20 20 t encoding */.
b240: 75 38 20 61 75 74 6f 43 6f 6d 6d 69 74 3b 20 20 u8 autoCommit;
b250: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
b260: 20 54 68 65 20 61 75 74 6f 2d 63 6f 6d 6d 69 74 The auto-commit
b270: 20 66 6c 61 67 2e 20 2a 2f 0a 20 20 75 38 20 74 flag. */. u8 t
b280: 65 6d 70 5f 73 74 6f 72 65 3b 20 20 20 20 20 20 emp_store;
b290: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 3a 20 /* 1:
b2a0: 66 69 6c 65 20 32 3a 20 6d 65 6d 6f 72 79 20 30 file 2: memory 0
b2b0: 3a 20 64 65 66 61 75 6c 74 20 2a 2f 0a 20 20 75 : default */. u
b2c0: 38 20 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 3b 20 8 mallocFailed;
b2d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
b2e0: 54 72 75 65 20 69 66 20 77 65 20 68 61 76 65 20 True if we have
b2f0: 73 65 65 6e 20 61 20 6d 61 6c 6c 6f 63 20 66 61 seen a malloc fa
b300: 69 6c 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 42 ilure */. u8 bB
b310: 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3b 20 20 20 20 enignMalloc;
b320: 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e /* Do n
b330: 6f 74 20 72 65 71 75 69 72 65 20 4f 4f 4d 73 20 ot require OOMs
b340: 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 20 if true */. u8
b350: 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 3b 20 20 20 dfltLockMode;
b360: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 /* De
b370: 66 61 75 6c 74 20 6c 6f 63 6b 69 6e 67 2d 6d 6f fault locking-mo
b380: 64 65 20 66 6f 72 20 61 74 74 61 63 68 65 64 20 de for attached
b390: 64 62 73 20 2a 2f 0a 20 20 73 69 67 6e 65 64 20 dbs */. signed
b3a0: 63 68 61 72 20 6e 65 78 74 41 75 74 6f 76 61 63 char nextAutovac
b3b0: 3b 20 20 20 20 20 20 2f 2a 20 41 75 74 6f 76 61 ; /* Autova
b3c0: 63 20 73 65 74 74 69 6e 67 20 61 66 74 65 72 20 c setting after
b3d0: 56 41 43 55 55 4d 20 69 66 20 3e 3d 30 20 2a 2f VACUUM if >=0 */
b3e0: 0a 20 20 75 38 20 73 75 70 70 72 65 73 73 45 72 . u8 suppressEr
b3f0: 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
b400: 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 73 73 75 65 /* Do not issue
b410: 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 error messages
b420: 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 20 if true */. u8
b430: 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 63 74 3b 20 vtabOnConflict;
b440: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 /* Va
b450: 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 66 6f lue to return fo
b460: 72 20 73 33 5f 76 74 61 62 5f 6f 6e 5f 63 6f 6e r s3_vtab_on_con
b470: 66 6c 69 63 74 28 29 20 2a 2f 0a 20 20 75 38 20 flict() */. u8
b480: 69 73 54 72 61 6e 73 61 63 74 69 6f 6e 53 61 76 isTransactionSav
b490: 65 70 6f 69 6e 74 3b 20 20 20 20 2f 2a 20 54 72 epoint; /* Tr
b4a0: 75 65 20 69 66 20 74 68 65 20 6f 75 74 65 72 6d ue if the outerm
b4b0: 6f 73 74 20 73 61 76 65 70 6f 69 6e 74 20 69 73 ost savepoint is
b4c0: 20 61 20 54 53 20 2a 2f 0a 20 20 75 38 20 6d 54 a TS */. u8 mT
b4d0: 72 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 20 race;
b4e0: 20 20 20 20 20 20 20 20 20 2f 2a 20 7a 65 72 6f /* zero
b4f0: 20 6f 72 20 6d 6f 72 65 20 53 51 4c 49 54 45 5f or more SQLITE_
b500: 54 52 41 43 45 20 66 6c 61 67 73 20 2a 2f 0a 20 TRACE flags */.
b510: 20 75 38 20 73 6b 69 70 42 74 72 65 65 4d 75 74 u8 skipBtreeMut
b520: 65 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ex; /
b530: 2a 20 54 72 75 65 20 69 66 20 6e 6f 20 73 68 61 * True if no sha
b540: 72 65 64 2d 63 61 63 68 65 20 62 61 63 6b 65 6e red-cache backen
b550: 64 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 65 78 74 ds */. int next
b560: 50 61 67 65 73 69 7a 65 3b 20 20 20 20 20 20 20 Pagesize;
b570: 20 20 20 20 20 20 2f 2a 20 50 61 67 65 73 69 7a /* Pagesiz
b580: 65 20 61 66 74 65 72 20 56 41 43 55 55 4d 20 69 e after VACUUM i
b590: 66 20 3e 30 20 2a 2f 0a 20 20 75 33 32 20 6d 61 f >0 */. u32 ma
b5a0: 67 69 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 gic;
b5b0: 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 67 69 63 /* Magic
b5c0: 20 6e 75 6d 62 65 72 20 66 6f 72 20 64 65 74 65 number for dete
b5d0: 63 74 20 6c 69 62 72 61 72 79 20 6d 69 73 75 73 ct library misus
b5e0: 65 20 2a 2f 0a 20 20 69 6e 74 20 6e 43 68 61 6e e */. int nChan
b5f0: 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ge;
b600: 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 72 65 /* Value re
b610: 74 75 72 6e 65 64 20 62 79 20 73 71 6c 69 74 65 turned by sqlite
b620: 33 5f 63 68 61 6e 67 65 73 28 29 20 2a 2f 0a 20 3_changes() */.
b630: 20 69 6e 74 20 6e 54 6f 74 61 6c 43 68 61 6e 67 int nTotalChang
b640: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f e; /
b650: 2a 20 56 61 6c 75 65 20 72 65 74 75 72 6e 65 64 * Value returned
b660: 20 62 79 20 73 71 6c 69 74 65 33 5f 74 6f 74 61 by sqlite3_tota
b670: 6c 5f 63 68 61 6e 67 65 73 28 29 20 2a 2f 0a 20 l_changes() */.
b680: 20 69 6e 74 20 61 4c 69 6d 69 74 5b 53 51 4c 49 int aLimit[SQLI
b690: 54 45 5f 4e 5f 4c 49 4d 49 54 5d 3b 20 20 20 2f TE_N_LIMIT]; /
b6a0: 2a 20 4c 69 6d 69 74 73 20 2a 2f 0a 20 20 69 6e * Limits */. in
b6b0: 74 20 6e 4d 61 78 53 6f 72 74 65 72 4d 6d 61 70 t nMaxSorterMmap
b6c0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d ; /* M
b6d0: 61 78 69 6d 75 6d 20 73 69 7a 65 20 6f 66 20 72 aximum size of r
b6e0: 65 67 69 6f 6e 73 20 6d 61 70 70 65 64 20 62 79 egions mapped by
b6f0: 20 73 6f 72 74 65 72 20 2a 2f 0a 20 20 73 74 72 sorter */. str
b700: 75 63 74 20 73 71 6c 69 74 65 33 49 6e 69 74 49 uct sqlite3InitI
b710: 6e 66 6f 20 7b 20 20 20 20 20 20 2f 2a 20 49 6e nfo { /* In
b720: 66 6f 72 6d 61 74 69 6f 6e 20 75 73 65 64 20 64 formation used d
b730: 75 72 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 uring initializa
b740: 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 6e 74 20 tion */. int
b750: 6e 65 77 54 6e 75 6d 3b 20 20 20 20 20 20 20 20 newTnum;
b760: 20 20 20 20 20 20 20 20 2f 2a 20 52 6f 6f 74 70 /* Rootp
b770: 61 67 65 20 6f 66 20 74 61 62 6c 65 20 62 65 69 age of table bei
b780: 6e 67 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a ng initialized *
b790: 2f 0a 20 20 20 20 75 38 20 69 44 62 3b 20 20 20 /. u8 iDb;
b7a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b7b0: 20 20 2f 2a 20 57 68 69 63 68 20 64 62 20 66 69 /* Which db fi
b7c0: 6c 65 20 69 73 20 62 65 69 6e 67 20 69 6e 69 74 le is being init
b7d0: 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 20 75 ialized */. u
b7e0: 38 20 62 75 73 79 3b 20 20 20 20 20 20 20 20 20 8 busy;
b7f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 52 /* TR
b800: 55 45 20 69 66 20 63 75 72 72 65 6e 74 6c 79 20 UE if currently
b810: 69 6e 69 74 69 61 6c 69 7a 69 6e 67 20 2a 2f 0a initializing */.
b820: 20 20 20 20 75 38 20 6f 72 70 68 61 6e 54 72 69 u8 orphanTri
b830: 67 67 65 72 3b 20 20 20 20 20 20 20 20 20 20 20 gger;
b840: 2f 2a 20 4c 61 73 74 20 73 74 61 74 65 6d 65 6e /* Last statemen
b850: 74 20 69 73 20 6f 72 70 68 61 6e 65 64 20 54 45 t is orphaned TE
b860: 4d 50 20 74 72 69 67 67 65 72 20 2a 2f 0a 20 20 MP trigger */.
b870: 20 20 75 38 20 69 6d 70 6f 73 74 65 72 54 61 62 u8 imposterTab
b880: 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a le; /*
b890: 20 42 75 69 6c 64 69 6e 67 20 61 6e 20 69 6d 70 Building an imp
b8a0: 6f 73 74 65 72 20 74 61 62 6c 65 20 2a 2f 0a 20 oster table */.
b8b0: 20 7d 20 69 6e 69 74 3b 0a 20 20 69 6e 74 20 6e } init;. int n
b8c0: 56 64 62 65 41 63 74 69 76 65 3b 20 20 20 20 20 VdbeActive;
b8d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
b8e0: 65 72 20 6f 66 20 56 44 42 45 73 20 63 75 72 72 er of VDBEs curr
b8f0: 65 6e 74 6c 79 20 72 75 6e 6e 69 6e 67 20 2a 2f ently running */
b900: 0a 20 20 69 6e 74 20 6e 56 64 62 65 52 65 61 64 . int nVdbeRead
b910: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
b920: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 /* Number of ac
b930: 74 69 76 65 20 56 44 42 45 73 20 74 68 61 74 20 tive VDBEs that
b940: 72 65 61 64 20 6f 72 20 77 72 69 74 65 20 2a 2f read or write */
b950: 0a 20 20 69 6e 74 20 6e 56 64 62 65 57 72 69 74 . int nVdbeWrit
b960: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
b970: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 63 /* Number of ac
b980: 74 69 76 65 20 56 44 42 45 73 20 74 68 61 74 20 tive VDBEs that
b990: 72 65 61 64 20 61 6e 64 20 77 72 69 74 65 20 2a read and write *
b9a0: 2f 0a 20 20 69 6e 74 20 6e 56 64 62 65 45 78 65 /. int nVdbeExe
b9b0: 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
b9c0: 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e /* Number of n
b9d0: 65 73 74 65 64 20 63 61 6c 6c 73 20 74 6f 20 56 ested calls to V
b9e0: 64 62 65 45 78 65 63 28 29 20 2a 2f 0a 20 20 69 dbeExec() */. i
b9f0: 6e 74 20 6e 56 44 65 73 74 72 6f 79 3b 20 20 20 nt nVDestroy;
ba00: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
ba10: 4e 75 6d 62 65 72 20 6f 66 20 61 63 74 69 76 65 Number of active
ba20: 20 4f 50 5f 56 44 65 73 74 72 6f 79 20 6f 70 65 OP_VDestroy ope
ba30: 72 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 rations */. int
ba40: 20 6e 45 78 74 65 6e 73 69 6f 6e 3b 20 20 20 20 nExtension;
ba50: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
ba60: 6d 62 65 72 20 6f 66 20 6c 6f 61 64 65 64 20 65 mber of loaded e
ba70: 78 74 65 6e 73 69 6f 6e 73 20 2a 2f 0a 20 20 76 xtensions */. v
ba80: 6f 69 64 20 2a 2a 61 45 78 74 65 6e 73 69 6f 6e oid **aExtension
ba90: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
baa0: 41 72 72 61 79 20 6f 66 20 73 68 61 72 65 64 20 Array of shared
bab0: 6c 69 62 72 61 72 79 20 68 61 6e 64 6c 65 73 20 library handles
bac0: 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 54 72 61 63 */. int (*xTrac
bad0: 65 29 28 75 33 32 2c 76 6f 69 64 2a 2c 76 6f 69 e)(u32,void*,voi
bae0: 64 2a 2c 76 6f 69 64 2a 29 3b 20 20 20 20 20 2f d*,void*); /
baf0: 2a 20 54 72 61 63 65 20 66 75 6e 63 74 69 6f 6e * Trace function
bb00: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 54 72 61 */. void *pTra
bb10: 63 65 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 ceArg;
bb20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
bb30: 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 74 /* Argument to t
bb40: 68 65 20 74 72 61 63 65 20 66 75 6e 63 74 69 6f he trace functio
bb50: 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 50 n */. void (*xP
bb60: 72 6f 66 69 6c 65 29 28 76 6f 69 64 2a 2c 63 6f rofile)(void*,co
bb70: 6e 73 74 20 63 68 61 72 2a 2c 75 36 34 29 3b 20 nst char*,u64);
bb80: 20 2f 2a 20 50 72 6f 66 69 6c 69 6e 67 20 66 75 /* Profiling fu
bb90: 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 nction */. void
bba0: 20 2a 70 50 72 6f 66 69 6c 65 41 72 67 3b 20 20 *pProfileArg;
bbb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
bbc0: 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e /* Argumen
bbd0: 74 20 74 6f 20 70 72 6f 66 69 6c 65 20 66 75 6e t to profile fun
bbe0: 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 ction */. void
bbf0: 2a 70 43 6f 6d 6d 69 74 41 72 67 3b 20 20 20 20 *pCommitArg;
bc00: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
bc10: 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 43 6f 6d Argument to xCom
bc20: 6d 69 74 43 61 6c 6c 62 61 63 6b 28 29 20 2a 2f mitCallback() */
bc30: 0a 20 20 69 6e 74 20 28 2a 78 43 6f 6d 6d 69 74 . int (*xCommit
bc40: 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 29 Callback)(void*)
bc50: 3b 20 20 20 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 ; /* Invoked
bc60: 61 74 20 65 76 65 72 79 20 63 6f 6d 6d 69 74 2e at every commit.
bc70: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 52 6f 6c */. void *pRol
bc80: 6c 62 61 63 6b 41 72 67 3b 20 20 20 20 20 20 20 lbackArg;
bc90: 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d /* Argum
bca0: 65 6e 74 20 74 6f 20 78 52 6f 6c 6c 62 61 63 6b ent to xRollback
bcb0: 43 61 6c 6c 62 61 63 6b 28 29 20 2a 2f 0a 20 20 Callback() */.
bcc0: 76 6f 69 64 20 28 2a 78 52 6f 6c 6c 62 61 63 6b void (*xRollback
bcd0: 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 29 Callback)(void*)
bce0: 3b 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 ; /* Invoked at
bcf0: 65 76 65 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f every commit. */
bd00: 0a 20 20 76 6f 69 64 20 2a 70 55 70 64 61 74 65 . void *pUpdate
bd10: 41 72 67 3b 0a 20 20 76 6f 69 64 20 28 2a 78 55 Arg;. void (*xU
bd20: 70 64 61 74 65 43 61 6c 6c 62 61 63 6b 29 28 76 pdateCallback)(v
bd30: 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 oid*,int, const
bd40: 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 char*,const char
bd50: 2a 2c 73 71 6c 69 74 65 5f 69 6e 74 36 34 29 3b *,sqlite_int64);
bd60: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
bd70: 4e 41 42 4c 45 5f 50 52 45 55 50 44 41 54 45 5f NABLE_PREUPDATE_
bd80: 48 4f 4f 4b 0a 20 20 76 6f 69 64 20 2a 70 50 72 HOOK. void *pPr
bd90: 65 55 70 64 61 74 65 41 72 67 3b 20 20 20 20 20 eUpdateArg;
bda0: 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 72 /* First ar
bdb0: 67 75 6d 65 6e 74 20 74 6f 20 78 50 72 65 55 70 gument to xPreUp
bdc0: 64 61 74 65 43 61 6c 6c 62 61 63 6b 20 2a 2f 0a dateCallback */.
bdd0: 20 20 76 6f 69 64 20 28 2a 78 50 72 65 55 70 64 void (*xPreUpd
bde0: 61 74 65 43 61 6c 6c 62 61 63 6b 29 28 20 20 20 ateCallback)(
bdf0: 2f 2a 20 52 65 67 69 73 74 65 72 65 64 20 75 73 /* Registered us
be00: 69 6e 67 20 73 71 6c 69 74 65 33 5f 70 72 65 75 ing sqlite3_preu
be10: 70 64 61 74 65 5f 68 6f 6f 6b 28 29 20 2a 2f 0a pdate_hook() */.
be20: 20 20 20 20 76 6f 69 64 2a 2c 73 71 6c 69 74 65 void*,sqlite
be30: 33 2a 2c 69 6e 74 2c 63 68 61 72 20 63 6f 6e 73 3*,int,char cons
be40: 74 2a 2c 63 68 61 72 20 63 6f 6e 73 74 2a 2c 73 t*,char const*,s
be50: 71 6c 69 74 65 33 5f 69 6e 74 36 34 2c 73 71 6c qlite3_int64,sql
be60: 69 74 65 33 5f 69 6e 74 36 34 0a 20 20 29 3b 0a ite3_int64. );.
be70: 20 20 50 72 65 55 70 64 61 74 65 20 2a 70 50 72 PreUpdate *pPr
be80: 65 55 70 64 61 74 65 3b 20 20 20 20 20 20 20 20 eUpdate;
be90: 2f 2a 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 61 /* Context for a
bea0: 63 74 69 76 65 20 70 72 65 2d 75 70 64 61 74 65 ctive pre-update
beb0: 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e callback */.#en
bec0: 64 69 66 20 2f 2a 20 53 51 4c 49 54 45 5f 45 4e dif /* SQLITE_EN
bed0: 41 42 4c 45 5f 50 52 45 55 50 44 41 54 45 5f 48 ABLE_PREUPDATE_H
bee0: 4f 4f 4b 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 OOK */.#ifndef S
bef0: 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 QLITE_OMIT_WAL.
bf00: 20 69 6e 74 20 28 2a 78 57 61 6c 43 61 6c 6c 62 int (*xWalCallb
bf10: 61 63 6b 29 28 76 6f 69 64 20 2a 2c 20 73 71 6c ack)(void *, sql
bf20: 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 63 68 ite3 *, const ch
bf30: 61 72 20 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 6f ar *, int);. vo
bf40: 69 64 20 2a 70 57 61 6c 41 72 67 3b 0a 23 65 6e id *pWalArg;.#en
bf50: 64 69 66 0a 20 20 76 6f 69 64 28 2a 78 43 6f 6c dif. void(*xCol
bf60: 6c 4e 65 65 64 65 64 29 28 76 6f 69 64 2a 2c 73 lNeeded)(void*,s
bf70: 71 6c 69 74 65 33 2a 2c 69 6e 74 20 65 54 65 78 qlite3*,int eTex
bf80: 74 52 65 70 2c 63 6f 6e 73 74 20 63 68 61 72 2a tRep,const char*
bf90: 29 3b 0a 20 20 76 6f 69 64 28 2a 78 43 6f 6c 6c );. void(*xColl
bfa0: 4e 65 65 64 65 64 31 36 29 28 76 6f 69 64 2a 2c Needed16)(void*,
bfb0: 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 65 54 65 sqlite3*,int eTe
bfc0: 78 74 52 65 70 2c 63 6f 6e 73 74 20 76 6f 69 64 xtRep,const void
bfd0: 2a 29 3b 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6c *);. void *pCol
bfe0: 6c 4e 65 65 64 65 64 41 72 67 3b 0a 20 20 73 71 lNeededArg;. sq
bff0: 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 70 45 72 lite3_value *pEr
c000: 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d r; /* M
c010: 6f 73 74 20 72 65 63 65 6e 74 20 65 72 72 6f 72 ost recent error
c020: 20 6d 65 73 73 61 67 65 20 2a 2f 0a 20 20 75 6e message */. un
c030: 69 6f 6e 20 7b 0a 20 20 20 20 76 6f 6c 61 74 69 ion {. volati
c040: 6c 65 20 69 6e 74 20 69 73 49 6e 74 65 72 72 75 le int isInterru
c050: 70 74 65 64 3b 20 2f 2a 20 54 72 75 65 20 69 66 pted; /* True if
c060: 20 73 71 6c 69 74 65 33 5f 69 6e 74 65 72 72 75 sqlite3_interru
c070: 70 74 20 68 61 73 20 62 65 65 6e 20 63 61 6c 6c pt has been call
c080: 65 64 20 2a 2f 0a 20 20 20 20 64 6f 75 62 6c 65 ed */. double
c090: 20 6e 6f 74 55 73 65 64 31 3b 20 20 20 20 20 20 notUsed1;
c0a0: 20 20 20 20 20 20 2f 2a 20 53 70 61 63 65 72 20 /* Spacer
c0b0: 2a 2f 0a 20 20 7d 20 75 31 3b 0a 20 20 4c 6f 6f */. } u1;. Loo
c0c0: 6b 61 73 69 64 65 20 6c 6f 6f 6b 61 73 69 64 65 kaside lookaside
c0d0: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f ; /* Lo
c0e0: 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 63 okaside malloc c
c0f0: 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 2a 2f 0a onfiguration */.
c100: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
c110: 4d 49 54 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f MIT_AUTHORIZATIO
c120: 4e 0a 20 20 73 71 6c 69 74 65 33 5f 78 61 75 74 N. sqlite3_xaut
c130: 68 20 78 41 75 74 68 3b 20 20 20 20 20 20 20 20 h xAuth;
c140: 20 20 2f 2a 20 41 63 63 65 73 73 20 61 75 74 68 /* Access auth
c150: 6f 72 69 7a 61 74 69 6f 6e 20 66 75 6e 63 74 69 orization functi
c160: 6f 6e 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 41 on */. void *pA
c170: 75 74 68 41 72 67 3b 20 20 20 20 20 20 20 20 20 uthArg;
c180: 20 20 20 20 20 20 2f 2a 20 31 73 74 20 61 72 67 /* 1st arg
c190: 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 61 63 63 ument to the acc
c1a0: 65 73 73 20 61 75 74 68 20 66 75 6e 63 74 69 6f ess auth functio
c1b0: 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e n */.#endif.#ifn
c1c0: 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f def SQLITE_OMIT_
c1d0: 50 52 4f 47 52 45 53 53 5f 43 41 4c 4c 42 41 43 PROGRESS_CALLBAC
c1e0: 4b 0a 20 20 69 6e 74 20 28 2a 78 50 72 6f 67 72 K. int (*xProgr
c1f0: 65 73 73 29 28 76 6f 69 64 20 2a 29 3b 20 20 20 ess)(void *);
c200: 20 20 2f 2a 20 54 68 65 20 70 72 6f 67 72 65 73 /* The progres
c210: 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 s callback */.
c220: 76 6f 69 64 20 2a 70 50 72 6f 67 72 65 73 73 41 void *pProgressA
c230: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a rg; /*
c240: 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 Argument to the
c250: 20 70 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 progress callba
c260: 63 6b 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 ck */. unsigned
c270: 20 6e 50 72 6f 67 72 65 73 73 4f 70 73 3b 20 20 nProgressOps;
c280: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
c290: 6f 66 20 6f 70 63 6f 64 65 73 20 66 6f 72 20 70 of opcodes for p
c2a0: 72 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b rogress callback
c2b0: 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 */.#endif.#ifnd
c2c0: 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 ef SQLITE_OMIT_V
c2d0: 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e IRTUALTABLE. in
c2e0: 74 20 6e 56 54 72 61 6e 73 3b 20 20 20 20 20 20 t nVTrans;
c2f0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 /* A
c300: 6c 6c 6f 63 61 74 65 64 20 73 69 7a 65 20 6f 66 llocated size of
c310: 20 61 56 54 72 61 6e 73 20 2a 2f 0a 20 20 48 61 aVTrans */. Ha
c320: 73 68 20 61 4d 6f 64 75 6c 65 3b 20 20 20 20 20 sh aModule;
c330: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 70 /* p
c340: 6f 70 75 6c 61 74 65 64 20 62 79 20 73 71 6c 69 opulated by sqli
c350: 74 65 33 5f 63 72 65 61 74 65 5f 6d 6f 64 75 6c te3_create_modul
c360: 65 28 29 20 2a 2f 0a 20 20 56 74 61 62 43 74 78 e() */. VtabCtx
c370: 20 2a 70 56 74 61 62 43 74 78 3b 20 20 20 20 20 *pVtabCtx;
c380: 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 74 65 78 /* Contex
c390: 74 20 66 6f 72 20 61 63 74 69 76 65 20 76 74 61 t for active vta
c3a0: 62 20 63 6f 6e 6e 65 63 74 2f 63 72 65 61 74 65 b connect/create
c3b0: 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 2a 61 */. VTable **a
c3c0: 56 54 72 61 6e 73 3b 20 20 20 20 20 20 20 20 20 VTrans;
c3d0: 20 20 20 20 2f 2a 20 56 69 72 74 75 61 6c 20 74 /* Virtual t
c3e0: 61 62 6c 65 73 20 77 69 74 68 20 6f 70 65 6e 20 ables with open
c3f0: 74 72 61 6e 73 61 63 74 69 6f 6e 73 20 2a 2f 0a transactions */.
c400: 20 20 56 54 61 62 6c 65 20 2a 70 44 69 73 63 6f VTable *pDisco
c410: 6e 6e 65 63 74 3b 20 20 20 20 2f 2a 20 44 69 73 nnect; /* Dis
c420: 63 6f 6e 6e 65 63 74 20 74 68 65 73 65 20 69 6e connect these in
c430: 20 6e 65 78 74 20 73 71 6c 69 74 65 33 5f 70 72 next sqlite3_pr
c440: 65 70 61 72 65 28 29 20 2a 2f 0a 23 65 6e 64 69 epare() */.#endi
c450: 66 0a 20 20 48 61 73 68 20 61 46 75 6e 63 3b 20 f. Hash aFunc;
c460: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c470: 20 20 2f 2a 20 48 61 73 68 20 74 61 62 6c 65 20 /* Hash table
c480: 6f 66 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 66 75 of connection fu
c490: 6e 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 48 61 73 nctions */. Has
c4a0: 68 20 61 43 6f 6c 6c 53 65 71 3b 20 20 20 20 20 h aCollSeq;
c4b0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6c /* Al
c4c0: 6c 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 l collating sequ
c4d0: 65 6e 63 65 73 20 2a 2f 0a 20 20 42 75 73 79 48 ences */. BusyH
c4e0: 61 6e 64 6c 65 72 20 62 75 73 79 48 61 6e 64 6c andler busyHandl
c4f0: 65 72 3b 20 20 20 20 20 20 2f 2a 20 42 75 73 79 er; /* Busy
c500: 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 44 callback */. D
c510: 62 20 61 44 62 53 74 61 74 69 63 5b 32 5d 3b 20 b aDbStatic[2];
c520: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c530: 53 74 61 74 69 63 20 73 70 61 63 65 20 66 6f 72 Static space for
c540: 20 74 68 65 20 32 20 64 65 66 61 75 6c 74 20 62 the 2 default b
c550: 61 63 6b 65 6e 64 73 20 2a 2f 0a 20 20 53 61 76 ackends */. Sav
c560: 65 70 6f 69 6e 74 20 2a 70 53 61 76 65 70 6f 69 epoint *pSavepoi
c570: 6e 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 nt; /* Li
c580: 73 74 20 6f 66 20 61 63 74 69 76 65 20 73 61 76 st of active sav
c590: 65 70 6f 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 epoints */. int
c5a0: 20 62 75 73 79 54 69 6d 65 6f 75 74 3b 20 20 20 busyTimeout;
c5b0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 75 /* Bu
c5c0: 73 79 20 68 61 6e 64 6c 65 72 20 74 69 6d 65 6f sy handler timeo
c5d0: 75 74 2c 20 69 6e 20 6d 73 65 63 20 2a 2f 0a 20 ut, in msec */.
c5e0: 20 69 6e 74 20 6e 53 61 76 65 70 6f 69 6e 74 3b int nSavepoint;
c5f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
c600: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 6f 6e 2d * Number of non-
c610: 74 72 61 6e 73 61 63 74 69 6f 6e 20 73 61 76 65 transaction save
c620: 70 6f 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 points */. int
c630: 6e 53 74 61 74 65 6d 65 6e 74 3b 20 20 20 20 20 nStatement;
c640: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
c650: 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 73 74 ber of nested st
c660: 61 74 65 6d 65 6e 74 2d 74 72 61 6e 73 61 63 74 atement-transact
c670: 69 6f 6e 73 20 20 2a 2f 0a 20 20 69 36 34 20 6e ions */. i64 n
c680: 44 65 66 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 DeferredCons;
c690: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 20 /* Net
c6a0: 64 65 66 65 72 72 65 64 20 63 6f 6e 73 74 72 61 deferred constra
c6b0: 69 6e 74 73 20 74 68 69 73 20 74 72 61 6e 73 61 ints this transa
c6c0: 63 74 69 6f 6e 2e 20 2a 2f 0a 20 20 69 36 34 20 ction. */. i64
c6d0: 6e 44 65 66 65 72 72 65 64 49 6d 6d 43 6f 6e 73 nDeferredImmCons
c6e0: 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 74 ; /* Net
c6f0: 20 64 65 66 65 72 72 65 64 20 69 6d 6d 65 64 69 deferred immedi
c700: 61 74 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 ate constraints
c710: 2a 2f 0a 20 20 69 6e 74 20 2a 70 6e 42 79 74 65 */. int *pnByte
c720: 73 46 72 65 65 64 3b 20 20 20 20 20 20 20 20 20 sFreed;
c730: 20 20 20 2f 2a 20 49 66 20 6e 6f 74 20 4e 55 4c /* If not NUL
c740: 4c 2c 20 69 6e 63 72 65 6d 65 6e 74 20 74 68 69 L, increment thi
c750: 73 20 69 6e 20 44 62 46 72 65 65 28 29 20 2a 2f s in DbFree() */
c760: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
c770: 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e 4f 54 NABLE_UNLOCK_NOT
c780: 49 46 59 0a 20 20 2f 2a 20 54 68 65 20 66 6f 6c IFY. /* The fol
c790: 6c 6f 77 69 6e 67 20 76 61 72 69 61 62 6c 65 73 lowing variables
c7a0: 20 61 72 65 20 61 6c 6c 20 70 72 6f 74 65 63 74 are all protect
c7b0: 65 64 20 62 79 20 74 68 65 20 53 54 41 54 49 43 ed by the STATIC
c7c0: 5f 4d 41 53 54 45 52 0a 20 20 2a 2a 20 6d 75 74 _MASTER. ** mut
c7d0: 65 78 2c 20 6e 6f 74 20 62 79 20 73 71 6c 69 74 ex, not by sqlit
c7e0: 65 33 2e 6d 75 74 65 78 2e 20 54 68 65 79 20 61 e3.mutex. They a
c7f0: 72 65 20 75 73 65 64 20 62 79 20 63 6f 64 65 20 re used by code
c800: 69 6e 20 6e 6f 74 69 66 79 2e 63 2e 0a 20 20 2a in notify.c.. *
c810: 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 55 *. ** When X.pU
c820: 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3d nlockConnection=
c830: 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e 73 20 74 =Y, that means t
c840: 68 61 74 20 58 20 69 73 20 77 61 69 74 69 6e 67 hat X is waiting
c850: 20 66 6f 72 20 59 20 74 6f 0a 20 20 2a 2a 20 75 for Y to. ** u
c860: 6e 6c 6f 63 6b 20 73 6f 20 74 68 61 74 20 69 74 nlock so that it
c870: 20 63 61 6e 20 70 72 6f 63 65 65 64 2e 0a 20 20 can proceed..
c880: 2a 2a 0a 20 20 2a 2a 20 57 68 65 6e 20 58 2e 70 **. ** When X.p
c890: 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 69 BlockingConnecti
c8a0: 6f 6e 3d 3d 59 2c 20 74 68 61 74 20 6d 65 61 6e on==Y, that mean
c8b0: 73 20 74 68 61 74 20 73 6f 6d 65 74 68 69 6e 67 s that something
c8c0: 20 74 68 61 74 20 58 20 74 72 69 65 64 0a 20 20 that X tried.
c8d0: 2a 2a 20 74 72 69 65 64 20 74 6f 20 64 6f 20 72 ** tried to do r
c8e0: 65 63 65 6e 74 6c 79 20 66 61 69 6c 65 64 20 77 ecently failed w
c8f0: 69 74 68 20 61 6e 20 53 51 4c 49 54 45 5f 4c 4f ith an SQLITE_LO
c900: 43 4b 45 44 20 65 72 72 6f 72 20 64 75 65 20 74 CKED error due t
c910: 6f 20 6c 6f 63 6b 73 0a 20 20 2a 2a 20 68 65 6c o locks. ** hel
c920: 64 20 62 79 20 59 2e 0a 20 20 2a 2f 0a 20 20 73 d by Y.. */. s
c930: 71 6c 69 74 65 33 20 2a 70 42 6c 6f 63 6b 69 6e qlite3 *pBlockin
c940: 67 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 2f 2a 20 gConnection; /*
c950: 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 68 61 74 20 Connection that
c960: 63 61 75 73 65 64 20 53 51 4c 49 54 45 5f 4c 4f caused SQLITE_LO
c970: 43 4b 45 44 20 2a 2f 0a 20 20 73 71 6c 69 74 65 CKED */. sqlite
c980: 33 20 2a 70 55 6e 6c 6f 63 6b 43 6f 6e 6e 65 63 3 *pUnlockConnec
c990: 74 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 20 tion;
c9a0: 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 74 6f /* Connection to
c9b0: 20 77 61 74 63 68 20 66 6f 72 20 75 6e 6c 6f 63 watch for unloc
c9c0: 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 6e k */. void *pUn
c9d0: 6c 6f 63 6b 41 72 67 3b 20 20 20 20 20 20 20 20 lockArg;
c9e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
c9f0: 41 72 67 75 6d 65 6e 74 20 74 6f 20 78 55 6e 6c Argument to xUnl
ca00: 6f 63 6b 4e 6f 74 69 66 79 20 2a 2f 0a 20 20 76 ockNotify */. v
ca10: 6f 69 64 20 28 2a 78 55 6e 6c 6f 63 6b 4e 6f 74 oid (*xUnlockNot
ca20: 69 66 79 29 28 76 6f 69 64 20 2a 2a 2c 20 69 6e ify)(void **, in
ca30: 74 29 3b 20 20 2f 2a 20 55 6e 6c 6f 63 6b 20 6e t); /* Unlock n
ca40: 6f 74 69 66 79 20 63 61 6c 6c 62 61 63 6b 20 2a otify callback *
ca50: 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 4e 65 /. sqlite3 *pNe
ca60: 78 74 42 6c 6f 63 6b 65 64 3b 20 20 20 20 20 20 xtBlocked;
ca70: 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c 69 73 /* Next in lis
ca80: 74 20 6f 66 20 61 6c 6c 20 62 6c 6f 63 6b 65 64 t of all blocked
ca90: 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 20 2a 2f 0a connections */.
caa0: 23 65 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 #endif.#ifdef SQ
cab0: 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e LITE_USER_AUTHEN
cac0: 54 49 43 41 54 49 4f 4e 0a 20 20 73 71 6c 69 74 TICATION. sqlit
cad0: 65 33 5f 75 73 65 72 61 75 74 68 20 61 75 74 68 e3_userauth auth
cae0: 3b 20 20 20 20 20 20 20 20 2f 2a 20 55 73 65 72 ; /* User
caf0: 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 authentication
cb00: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 23 information */.#
cb10: 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 endif.};../*.**
cb20: 41 20 6d 61 63 72 6f 20 74 6f 20 64 69 73 63 6f A macro to disco
cb30: 76 65 72 20 74 68 65 20 65 6e 63 6f 64 69 6e 67 ver the encoding
cb40: 20 6f 66 20 61 20 64 61 74 61 62 61 73 65 2e 0a of a database..
cb50: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 45 4d */.#define SCHEM
cb60: 41 5f 45 4e 43 28 64 62 29 20 28 28 64 62 29 2d A_ENC(db) ((db)-
cb70: 3e 61 44 62 5b 30 5d 2e 70 53 63 68 65 6d 61 2d >aDb[0].pSchema-
cb80: 3e 65 6e 63 29 0a 23 64 65 66 69 6e 65 20 45 4e >enc).#define EN
cb90: 43 28 64 62 29 20 20 20 20 20 20 20 20 28 28 64 C(db) ((d
cba0: 62 29 2d 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 b)->enc)../*.**
cbb0: 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 Possible values
cbc0: 66 6f 72 20 74 68 65 20 73 71 6c 69 74 65 33 2e for the sqlite3.
cbd0: 66 6c 61 67 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c flags..**.** Val
cbe0: 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 ue constraints (
cbf0: 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 73 73 enforced via ass
cc00: 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 20 20 ert()):.**
cc10: 53 51 4c 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 SQLITE_FullFSync
cc20: 20 20 20 20 20 3d 3d 20 50 41 47 45 52 5f 46 55 == PAGER_FU
cc30: 4c 4c 46 53 59 4e 43 0a 2a 2a 20 20 20 20 20 20 LLFSYNC.**
cc40: 53 51 4c 49 54 45 5f 43 6b 70 74 46 75 6c 6c 46 SQLITE_CkptFullF
cc50: 53 79 6e 63 20 3d 3d 20 50 41 47 45 52 5f 43 4b Sync == PAGER_CK
cc60: 50 54 5f 46 55 4c 4c 46 53 59 4e 43 0a 2a 2a 20 PT_FULLFSYNC.**
cc70: 20 20 20 20 20 53 51 4c 49 54 45 5f 43 61 63 68 SQLITE_Cach
cc80: 65 53 70 69 6c 6c 20 20 20 20 3d 3d 20 50 41 47 eSpill == PAG
cc90: 45 52 5f 43 41 43 48 45 5f 53 50 49 4c 4c 0a 2a ER_CACHE_SPILL.*
cca0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
ccb0: 5f 56 64 62 65 54 72 61 63 65 20 20 20 20 20 20 _VdbeTrace
ccc0: 30 78 30 30 30 30 30 30 30 31 20 20 2f 2a 20 54 0x00000001 /* T
ccd0: 72 75 65 20 74 6f 20 74 72 61 63 65 20 56 44 42 rue to trace VDB
cce0: 45 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a 23 E execution */.#
ccf0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 6e define SQLITE_In
cd00: 74 65 72 6e 43 68 61 6e 67 65 73 20 20 30 78 30 ternChanges 0x0
cd10: 30 30 30 30 30 30 32 20 20 2f 2a 20 55 6e 63 6f 0000002 /* Unco
cd20: 6d 6d 69 74 74 65 64 20 48 61 73 68 20 74 61 62 mmitted Hash tab
cd30: 6c 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 le changes */.#d
cd40: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 6c efine SQLITE_Ful
cd50: 6c 43 6f 6c 4e 61 6d 65 73 20 20 20 30 78 30 30 lColNames 0x00
cd60: 30 30 30 30 30 34 20 20 2f 2a 20 53 68 6f 77 20 000004 /* Show
cd70: 66 75 6c 6c 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 full column name
cd80: 73 20 6f 6e 20 53 45 4c 45 43 54 20 2a 2f 0a 23 s on SELECT */.#
cd90: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 75 define SQLITE_Fu
cda0: 6c 6c 46 53 79 6e 63 20 20 20 20 20 20 30 78 30 llFSync 0x0
cdb0: 30 30 30 30 30 30 38 20 20 2f 2a 20 55 73 65 20 0000008 /* Use
cdc0: 66 75 6c 6c 20 66 73 79 6e 63 20 6f 6e 20 74 68 full fsync on th
cdd0: 65 20 62 61 63 6b 65 6e 64 20 2a 2f 0a 23 64 65 e backend */.#de
cde0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6b 70 74 fine SQLITE_Ckpt
cdf0: 46 75 6c 6c 46 53 79 6e 63 20 20 30 78 30 30 30 FullFSync 0x000
ce00: 30 30 30 31 30 20 20 2f 2a 20 55 73 65 20 66 75 00010 /* Use fu
ce10: 6c 6c 20 66 73 79 6e 63 20 66 6f 72 20 63 68 65 ll fsync for che
ce20: 63 6b 70 6f 69 6e 74 20 2a 2f 0a 23 64 65 66 69 ckpoint */.#defi
ce30: 6e 65 20 53 51 4c 49 54 45 5f 43 61 63 68 65 53 ne SQLITE_CacheS
ce40: 70 69 6c 6c 20 20 20 20 20 30 78 30 30 30 30 30 pill 0x00000
ce50: 30 32 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 73 70 020 /* OK to sp
ce60: 69 6c 6c 20 70 61 67 65 72 20 63 61 63 68 65 20 ill pager cache
ce70: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
ce80: 45 5f 53 68 6f 72 74 43 6f 6c 4e 61 6d 65 73 20 E_ShortColNames
ce90: 20 30 78 30 30 30 30 30 30 34 30 20 20 2f 2a 20 0x00000040 /*
cea0: 53 68 6f 77 20 73 68 6f 72 74 20 63 6f 6c 75 6d Show short colum
ceb0: 6e 73 20 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 ns names */.#def
cec0: 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f 75 6e 74 ine SQLITE_Count
ced0: 52 6f 77 73 20 20 20 20 20 20 30 78 30 30 30 30 Rows 0x0000
cee0: 30 30 38 30 20 20 2f 2a 20 43 6f 75 6e 74 20 72 0080 /* Count r
cef0: 6f 77 73 20 63 68 61 6e 67 65 64 20 62 79 20 49 ows changed by I
cf00: 4e 53 45 52 54 2c 20 2a 2f 0a 20 20 20 20 20 20 NSERT, */.
cf10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cf20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cf30: 20 20 20 20 2f 2a 20 20 20 44 45 4c 45 54 45 2c /* DELETE,
cf40: 20 6f 72 20 55 50 44 41 54 45 20 61 6e 64 20 72 or UPDATE and r
cf50: 65 74 75 72 6e 20 2a 2f 0a 20 20 20 20 20 20 20 eturn */.
cf60: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cf70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cf80: 20 20 20 2f 2a 20 20 20 74 68 65 20 63 6f 75 6e /* the coun
cf90: 74 20 75 73 69 6e 67 20 61 20 63 61 6c 6c 62 61 t using a callba
cfa0: 63 6b 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ck. */.#define S
cfb0: 51 4c 49 54 45 5f 4e 75 6c 6c 43 61 6c 6c 62 61 QLITE_NullCallba
cfc0: 63 6b 20 20 20 30 78 30 30 30 30 30 31 30 30 20 ck 0x00000100
cfd0: 20 2f 2a 20 49 6e 76 6f 6b 65 20 74 68 65 20 63 /* Invoke the c
cfe0: 61 6c 6c 62 61 63 6b 20 6f 6e 63 65 20 69 66 20 allback once if
cff0: 74 68 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 the */.
d000: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d010: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
d020: 20 2f 2a 20 20 20 72 65 73 75 6c 74 20 73 65 74 /* result set
d030: 20 69 73 20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 is empty */.#de
d040: 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 71 6c 54 fine SQLITE_SqlT
d050: 72 61 63 65 20 20 20 20 20 20 20 30 78 30 30 30 race 0x000
d060: 30 30 32 30 30 20 20 2f 2a 20 44 65 62 75 67 20 00200 /* Debug
d070: 70 72 69 6e 74 20 53 51 4c 20 61 73 20 69 74 20 print SQL as it
d080: 65 78 65 63 75 74 65 73 20 2a 2f 0a 23 64 65 66 executes */.#def
d090: 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 4c ine SQLITE_VdbeL
d0a0: 69 73 74 69 6e 67 20 20 20 20 30 78 30 30 30 30 isting 0x0000
d0b0: 30 34 30 30 20 20 2f 2a 20 44 65 62 75 67 20 6c 0400 /* Debug l
d0c0: 69 73 74 69 6e 67 73 20 6f 66 20 56 44 42 45 20 istings of VDBE
d0d0: 70 72 6f 67 72 61 6d 73 20 2a 2f 0a 23 64 65 66 programs */.#def
d0e0: 69 6e 65 20 53 51 4c 49 54 45 5f 57 72 69 74 65 ine SQLITE_Write
d0f0: 53 63 68 65 6d 61 20 20 20 20 30 78 30 30 30 30 Schema 0x0000
d100: 30 38 30 30 20 20 2f 2a 20 4f 4b 20 74 6f 20 75 0800 /* OK to u
d110: 70 64 61 74 65 20 53 51 4c 49 54 45 5f 4d 41 53 pdate SQLITE_MAS
d120: 54 45 52 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 TER */.#define S
d130: 51 4c 49 54 45 5f 56 64 62 65 41 64 64 6f 70 54 QLITE_VdbeAddopT
d140: 72 61 63 65 20 30 78 30 30 30 30 31 30 30 30 20 race 0x00001000
d150: 20 2f 2a 20 54 72 61 63 65 20 73 71 6c 69 74 65 /* Trace sqlite
d160: 33 56 64 62 65 41 64 64 4f 70 28 29 20 63 61 6c 3VdbeAddOp() cal
d170: 6c 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ls */.#define SQ
d180: 4c 49 54 45 5f 49 67 6e 6f 72 65 43 68 65 63 6b LITE_IgnoreCheck
d190: 73 20 20 20 30 78 30 30 30 30 32 30 30 30 20 20 s 0x00002000
d1a0: 2f 2a 20 44 6f 20 6e 6f 74 20 65 6e 66 6f 72 63 /* Do not enforc
d1b0: 65 20 63 68 65 63 6b 20 63 6f 6e 73 74 72 61 69 e check constrai
d1c0: 6e 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 nts */.#define S
d1d0: 51 4c 49 54 45 5f 52 65 61 64 55 6e 63 6f 6d 6d QLITE_ReadUncomm
d1e0: 69 74 74 65 64 20 30 78 30 30 30 34 30 30 30 20 itted 0x0004000
d1f0: 20 2f 2a 20 46 6f 72 20 73 68 61 72 65 64 2d 63 /* For shared-c
d200: 61 63 68 65 20 6d 6f 64 65 20 2a 2f 0a 23 64 65 ache mode */.#de
d210: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 65 67 61 fine SQLITE_Lega
d220: 63 79 46 69 6c 65 46 6d 74 20 20 30 78 30 30 30 cyFileFmt 0x000
d230: 30 38 30 30 30 20 20 2f 2a 20 43 72 65 61 74 65 08000 /* Create
d240: 20 6e 65 77 20 64 61 74 61 62 61 73 65 73 20 69 new databases i
d250: 6e 20 66 6f 72 6d 61 74 20 31 20 2a 2f 0a 23 64 n format 1 */.#d
d260: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 63 efine SQLITE_Rec
d270: 6f 76 65 72 79 4d 6f 64 65 20 20 20 30 78 30 30 overyMode 0x00
d280: 30 31 30 30 30 30 20 20 2f 2a 20 49 67 6e 6f 72 010000 /* Ignor
d290: 65 20 73 63 68 65 6d 61 20 65 72 72 6f 72 73 20 e schema errors
d2a0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
d2b0: 45 5f 52 65 76 65 72 73 65 4f 72 64 65 72 20 20 E_ReverseOrder
d2c0: 20 30 78 30 30 30 32 30 30 30 30 20 20 2f 2a 20 0x00020000 /*
d2d0: 52 65 76 65 72 73 65 20 75 6e 6f 72 64 65 72 65 Reverse unordere
d2e0: 64 20 53 45 4c 45 43 54 73 20 2a 2f 0a 23 64 65 d SELECTs */.#de
d2f0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 63 54 fine SQLITE_RecT
d300: 72 69 67 67 65 72 73 20 20 20 20 30 78 30 30 30 riggers 0x000
d310: 34 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 40000 /* Enable
d320: 20 72 65 63 75 72 73 69 76 65 20 74 72 69 67 67 recursive trigg
d330: 65 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ers */.#define S
d340: 51 4c 49 54 45 5f 46 6f 72 65 69 67 6e 4b 65 79 QLITE_ForeignKey
d350: 73 20 20 20 20 30 78 30 30 30 38 30 30 30 30 20 s 0x00080000
d360: 20 2f 2a 20 45 6e 66 6f 72 63 65 20 66 6f 72 65 /* Enforce fore
d370: 69 67 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 69 ign key constrai
d380: 6e 74 73 20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 nts */.#define
d390: 53 51 4c 49 54 45 5f 41 75 74 6f 49 6e 64 65 78 SQLITE_AutoIndex
d3a0: 20 20 20 20 20 20 30 78 30 30 31 30 30 30 30 30 0x00100000
d3b0: 20 20 2f 2a 20 45 6e 61 62 6c 65 20 61 75 74 6f /* Enable auto
d3c0: 6d 61 74 69 63 20 69 6e 64 65 78 65 73 20 2a 2f matic indexes */
d3d0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
d3e0: 50 72 65 66 65 72 42 75 69 6c 74 69 6e 20 20 30 PreferBuiltin 0
d3f0: 78 30 30 32 30 30 30 30 30 20 20 2f 2a 20 50 72 x00200000 /* Pr
d400: 65 66 65 72 65 6e 63 65 20 74 6f 20 62 75 69 6c eference to buil
d410: 74 2d 69 6e 20 66 75 6e 63 73 20 2a 2f 0a 23 64 t-in funcs */.#d
d420: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 6f 61 efine SQLITE_Loa
d430: 64 45 78 74 65 6e 73 69 6f 6e 20 20 30 78 30 30 dExtension 0x00
d440: 34 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 400000 /* Enabl
d450: 65 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e e load_extension
d460: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
d470: 54 45 5f 4c 6f 61 64 45 78 74 46 75 6e 63 20 20 TE_LoadExtFunc
d480: 20 20 30 78 30 30 38 30 30 30 30 30 20 20 2f 2a 0x00800000 /*
d490: 20 45 6e 61 62 6c 65 20 6c 6f 61 64 5f 65 78 74 Enable load_ext
d4a0: 65 6e 73 69 6f 6e 28 29 20 53 51 4c 20 66 75 6e ension() SQL fun
d4b0: 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c c */.#define SQL
d4c0: 49 54 45 5f 45 6e 61 62 6c 65 54 72 69 67 67 65 ITE_EnableTrigge
d4d0: 72 20 20 30 78 30 31 30 30 30 30 30 30 20 20 2f r 0x01000000 /
d4e0: 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 * True to enable
d4f0: 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 23 64 65 triggers */.#de
d500: 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 65 66 65 fine SQLITE_Defe
d510: 72 46 4b 73 20 20 20 20 20 20 20 30 78 30 32 30 rFKs 0x020
d520: 30 30 30 30 30 20 20 2f 2a 20 44 65 66 65 72 20 00000 /* Defer
d530: 61 6c 6c 20 46 4b 20 63 6f 6e 73 74 72 61 69 6e all FK constrain
d540: 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ts */.#define SQ
d550: 4c 49 54 45 5f 51 75 65 72 79 4f 6e 6c 79 20 20 LITE_QueryOnly
d560: 20 20 20 20 30 78 30 34 30 30 30 30 30 30 20 20 0x04000000
d570: 2f 2a 20 44 69 73 61 62 6c 65 20 64 61 74 61 62 /* Disable datab
d580: 61 73 65 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 ase changes */.#
d590: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 define SQLITE_Vd
d5a0: 62 65 45 51 50 20 20 20 20 20 20 20 20 30 78 30 beEQP 0x0
d5b0: 38 30 30 30 30 30 30 20 20 2f 2a 20 44 65 62 75 8000000 /* Debu
d5c0: 67 20 45 58 50 4c 41 49 4e 20 51 55 45 52 59 20 g EXPLAIN QUERY
d5d0: 50 4c 41 4e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 PLAN */.#define
d5e0: 53 51 4c 49 54 45 5f 56 61 63 75 75 6d 20 20 20 SQLITE_Vacuum
d5f0: 20 20 20 20 20 20 30 78 31 30 30 30 30 30 30 30 0x10000000
d600: 20 20 2f 2a 20 43 75 72 72 65 6e 74 6c 79 20 69 /* Currently i
d610: 6e 20 61 20 56 41 43 55 55 4d 20 2a 2f 0a 23 64 n a VACUUM */.#d
d620: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 65 6c efine SQLITE_Cel
d630: 6c 53 69 7a 65 43 6b 20 20 20 20 20 30 78 32 30 lSizeCk 0x20
d640: 30 30 30 30 30 30 20 20 2f 2a 20 43 68 65 63 6b 000000 /* Check
d650: 20 62 74 72 65 65 20 63 65 6c 6c 20 73 69 7a 65 btree cell size
d660: 73 20 6f 6e 20 6c 6f 61 64 20 2a 2f 0a 23 64 65 s on load */.#de
d670: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 74 73 33 fine SQLITE_Fts3
d680: 54 6f 6b 65 6e 69 7a 65 72 20 20 30 78 34 30 30 Tokenizer 0x400
d690: 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 65 00000 /* Enable
d6a0: 20 66 74 73 33 5f 74 6f 6b 65 6e 69 7a 65 72 28 fts3_tokenizer(
d6b0: 32 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 2) */.#define SQ
d6c0: 4c 49 54 45 5f 4e 6f 43 6b 70 74 4f 6e 43 6c 6f LITE_NoCkptOnClo
d6d0: 73 65 20 20 30 78 38 30 30 30 30 30 30 30 20 20 se 0x80000000
d6e0: 2f 2a 20 4e 6f 20 63 68 65 63 6b 70 6f 69 6e 74 /* No checkpoint
d6f0: 20 6f 6e 20 63 6c 6f 73 65 28 29 2f 44 45 54 41 on close()/DETA
d700: 43 48 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 42 69 CH */.../*.** Bi
d710: 74 73 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 ts of the sqlite
d720: 33 2e 64 62 4f 70 74 46 6c 61 67 73 20 66 69 65 3.dbOptFlags fie
d730: 6c 64 20 74 68 61 74 20 61 72 65 20 75 73 65 64 ld that are used
d740: 20 62 79 20 74 68 65 0a 2a 2a 20 73 71 6c 69 74 by the.** sqlit
d750: 65 33 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 e3_test_control(
d760: 53 51 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f SQLITE_TESTCTRL_
d770: 4f 50 54 49 4d 49 5a 41 54 49 4f 4e 53 2c 2e 2e OPTIMIZATIONS,..
d780: 2e 29 20 69 6e 74 65 72 66 61 63 65 20 74 6f 0a .) interface to.
d790: 2a 2a 20 73 65 6c 65 63 74 69 76 65 6c 79 20 64 ** selectively d
d7a0: 69 73 61 62 6c 65 20 76 61 72 69 6f 75 73 20 6f isable various o
d7b0: 70 74 69 6d 69 7a 61 74 69 6f 6e 73 2e 0a 2a 2f ptimizations..*/
d7c0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
d7d0: 51 75 65 72 79 46 6c 61 74 74 65 6e 65 72 20 30 QueryFlattener 0
d7e0: 78 30 30 30 31 20 20 20 2f 2a 20 51 75 65 72 79 x0001 /* Query
d7f0: 20 66 6c 61 74 74 65 6e 69 6e 67 20 2a 2f 0a 23 flattening */.#
d800: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 6f define SQLITE_Co
d810: 6c 75 6d 6e 43 61 63 68 65 20 20 20 20 30 78 30 lumnCache 0x0
d820: 30 30 32 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 002 /* Column
d830: 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 cache */.#define
d840: 20 53 51 4c 49 54 45 5f 47 72 6f 75 70 42 79 4f SQLITE_GroupByO
d850: 72 64 65 72 20 20 20 30 78 30 30 30 34 20 20 20 rder 0x0004
d860: 2f 2a 20 47 52 4f 55 50 42 59 20 63 6f 76 65 72 /* GROUPBY cover
d870: 20 6f 66 20 4f 52 44 45 52 42 59 20 2a 2f 0a 23 of ORDERBY */.#
d880: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 61 define SQLITE_Fa
d890: 63 74 6f 72 4f 75 74 43 6f 6e 73 74 20 30 78 30 ctorOutConst 0x0
d8a0: 30 30 38 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e 008 /* Constan
d8b0: 74 20 66 61 63 74 6f 72 69 6e 67 20 2a 2f 0a 2f t factoring */./
d8c0: 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
d8d0: 20 6e 6f 74 20 75 73 65 64 20 20 20 20 30 78 30 not used 0x0
d8e0: 30 31 30 20 20 20 2f 2f 20 57 61 73 3a 20 53 51 010 // Was: SQ
d8f0: 4c 49 54 45 5f 49 64 78 52 65 61 6c 41 73 49 6e LITE_IdxRealAsIn
d900: 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c t */.#define SQL
d910: 49 54 45 5f 44 69 73 74 69 6e 63 74 4f 70 74 20 ITE_DistinctOpt
d920: 20 20 20 30 78 30 30 32 30 20 20 20 2f 2a 20 44 0x0020 /* D
d930: 49 53 54 49 4e 43 54 20 75 73 69 6e 67 20 69 6e ISTINCT using in
d940: 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 dexes */.#define
d950: 20 53 51 4c 49 54 45 5f 43 6f 76 65 72 49 64 78 SQLITE_CoverIdx
d960: 53 63 61 6e 20 20 20 30 78 30 30 34 30 20 20 20 Scan 0x0040
d970: 2f 2a 20 43 6f 76 65 72 69 6e 67 20 69 6e 64 65 /* Covering inde
d980: 78 20 73 63 61 6e 73 20 2a 2f 0a 23 64 65 66 69 x scans */.#defi
d990: 6e 65 20 53 51 4c 49 54 45 5f 4f 72 64 65 72 42 ne SQLITE_OrderB
d9a0: 79 49 64 78 4a 6f 69 6e 20 30 78 30 30 38 30 20 yIdxJoin 0x0080
d9b0: 20 20 2f 2a 20 4f 52 44 45 52 20 42 59 20 6f 66 /* ORDER BY of
d9c0: 20 6a 6f 69 6e 73 20 76 69 61 20 69 6e 64 65 78 joins via index
d9d0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
d9e0: 54 45 5f 53 75 62 71 43 6f 72 6f 75 74 69 6e 65 TE_SubqCoroutine
d9f0: 20 20 30 78 30 31 30 30 20 20 20 2f 2a 20 45 76 0x0100 /* Ev
da00: 61 6c 75 61 74 65 20 73 75 62 71 75 65 72 69 65 aluate subquerie
da10: 73 20 61 73 20 63 6f 72 6f 75 74 69 6e 65 73 20 s as coroutines
da20: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
da30: 45 5f 54 72 61 6e 73 69 74 69 76 65 20 20 20 20 E_Transitive
da40: 20 30 78 30 32 30 30 20 20 20 2f 2a 20 54 72 61 0x0200 /* Tra
da50: 6e 73 69 74 69 76 65 20 63 6f 6e 73 74 72 61 69 nsitive constrai
da60: 6e 74 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 nts */.#define S
da70: 51 4c 49 54 45 5f 4f 6d 69 74 4e 6f 6f 70 4a 6f QLITE_OmitNoopJo
da80: 69 6e 20 20 20 30 78 30 34 30 30 20 20 20 2f 2a in 0x0400 /*
da90: 20 4f 6d 69 74 20 75 6e 75 73 65 64 20 74 61 62 Omit unused tab
daa0: 6c 65 73 20 69 6e 20 6a 6f 69 6e 73 20 2a 2f 0a les in joins */.
dab0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
dac0: 74 61 74 33 34 20 20 20 20 20 20 20 20 20 30 78 tat34 0x
dad0: 30 38 30 30 20 20 20 2f 2a 20 55 73 65 20 53 54 0800 /* Use ST
dae0: 41 54 33 20 6f 72 20 53 54 41 54 34 20 64 61 74 AT3 or STAT4 dat
daf0: 61 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c a */.#define SQL
db00: 49 54 45 5f 43 75 72 73 6f 72 48 69 6e 74 73 20 ITE_CursorHints
db10: 20 20 20 30 78 32 30 30 30 20 20 20 2f 2a 20 41 0x2000 /* A
db20: 64 64 20 4f 50 5f 43 75 72 73 6f 72 48 69 6e 74 dd OP_CursorHint
db30: 20 6f 70 63 6f 64 65 73 20 2a 2f 0a 23 64 65 66 opcodes */.#def
db40: 69 6e 65 20 53 51 4c 49 54 45 5f 41 6c 6c 4f 70 ine SQLITE_AllOp
db50: 74 73 20 20 20 20 20 20 20 20 30 78 66 66 66 66 ts 0xffff
db60: 20 20 20 2f 2a 20 41 6c 6c 20 6f 70 74 69 6d 69 /* All optimi
db70: 7a 61 74 69 6f 6e 73 20 2a 2f 0a 0a 2f 2a 0a 2a zations */../*.*
db80: 2a 20 4d 61 63 72 6f 73 20 66 6f 72 20 74 65 73 * Macros for tes
db90: 74 69 6e 67 20 77 68 65 74 68 65 72 20 6f 72 20 ting whether or
dba0: 6e 6f 74 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e not optimization
dbb0: 73 20 61 72 65 20 65 6e 61 62 6c 65 64 20 6f 72 s are enabled or
dbc0: 20 64 69 73 61 62 6c 65 64 2e 0a 2a 2f 0a 23 64 disabled..*/.#d
dbd0: 65 66 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 efine Optimizati
dbe0: 6f 6e 44 69 73 61 62 6c 65 64 28 64 62 2c 20 6d onDisabled(db, m
dbf0: 61 73 6b 29 20 20 28 28 28 64 62 29 2d 3e 64 62 ask) (((db)->db
dc00: 4f 70 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 OptFlags&(mask))
dc10: 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 4f 70 74 !=0).#define Opt
dc20: 69 6d 69 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 64 imizationEnabled
dc30: 28 64 62 2c 20 6d 61 73 6b 29 20 20 20 28 28 28 (db, mask) (((
dc40: 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 67 73 26 db)->dbOptFlags&
dc50: 28 6d 61 73 6b 29 29 3d 3d 30 29 0a 0a 2f 2a 0a (mask))==0)../*.
dc60: 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 ** Return true i
dc70: 66 20 69 74 20 4f 4b 20 74 6f 20 66 61 63 74 6f f it OK to facto
dc80: 72 20 63 6f 6e 73 74 61 6e 74 20 65 78 70 72 65 r constant expre
dc90: 73 73 69 6f 6e 73 20 69 6e 74 6f 20 74 68 65 20 ssions into the
dca0: 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 0a 2a initialization.*
dcb0: 2a 20 63 6f 64 65 2e 20 54 68 65 20 61 72 67 75 * code. The argu
dcc0: 6d 65 6e 74 20 69 73 20 61 20 50 61 72 73 65 20 ment is a Parse
dcd0: 6f 62 6a 65 63 74 20 66 6f 72 20 74 68 65 20 63 object for the c
dce0: 6f 64 65 20 67 65 6e 65 72 61 74 6f 72 2e 0a 2a ode generator..*
dcf0: 2f 0a 23 64 65 66 69 6e 65 20 43 6f 6e 73 74 46 /.#define ConstF
dd00: 61 63 74 6f 72 4f 6b 28 50 29 20 28 28 50 29 2d actorOk(P) ((P)-
dd10: 3e 6f 6b 43 6f 6e 73 74 46 61 63 74 6f 72 29 0a >okConstFactor).
dd20: 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 20 ./*.** Possible
dd30: 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 73 values for the s
dd40: 71 6c 69 74 65 2e 6d 61 67 69 63 20 66 69 65 6c qlite.magic fiel
dd50: 64 2e 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 72 d..** The number
dd60: 73 20 61 72 65 20 6f 62 74 61 69 6e 65 64 20 61 s are obtained a
dd70: 74 20 72 61 6e 64 6f 6d 20 61 6e 64 20 68 61 76 t random and hav
dd80: 65 20 6e 6f 20 73 70 65 63 69 61 6c 20 6d 65 61 e no special mea
dd90: 6e 69 6e 67 2c 20 6f 74 68 65 72 0a 2a 2a 20 74 ning, other.** t
dda0: 68 61 6e 20 62 65 69 6e 67 20 64 69 73 74 69 6e han being distin
ddb0: 63 74 20 66 72 6f 6d 20 6f 6e 65 20 61 6e 6f 74 ct from one anot
ddc0: 68 65 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 her..*/.#define
ddd0: 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 4f 50 45 SQLITE_MAGIC_OPE
dde0: 4e 20 20 20 20 20 30 78 61 30 32 39 61 36 39 37 N 0xa029a697
ddf0: 20 20 2f 2a 20 44 61 74 61 62 61 73 65 20 69 73 /* Database is
de00: 20 6f 70 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 open */.#define
de10: 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 43 4c SQLITE_MAGIC_CL
de20: 4f 53 45 44 20 20 20 30 78 39 66 33 63 32 64 33 OSED 0x9f3c2d3
de30: 33 20 20 2f 2a 20 44 61 74 61 62 61 73 65 20 69 3 /* Database i
de40: 73 20 63 6c 6f 73 65 64 20 2a 2f 0a 23 64 65 66 s closed */.#def
de50: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
de60: 5f 53 49 43 4b 20 20 20 20 20 30 78 34 62 37 37 _SICK 0x4b77
de70: 31 32 39 30 20 20 2f 2a 20 45 72 72 6f 72 20 61 1290 /* Error a
de80: 6e 64 20 61 77 61 69 74 69 6e 67 20 63 6c 6f 73 nd awaiting clos
de90: 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c e */.#define SQL
dea0: 49 54 45 5f 4d 41 47 49 43 5f 42 55 53 59 20 20 ITE_MAGIC_BUSY
deb0: 20 20 20 30 78 66 30 33 62 37 39 30 36 20 20 2f 0xf03b7906 /
dec0: 2a 20 44 61 74 61 62 61 73 65 20 63 75 72 72 65 * Database curre
ded0: 6e 74 6c 79 20 69 6e 20 75 73 65 20 2a 2f 0a 23 ntly in use */.#
dee0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
def0: 47 49 43 5f 45 52 52 4f 52 20 20 20 20 30 78 62 GIC_ERROR 0xb
df00: 35 33 35 37 39 33 30 20 20 2f 2a 20 41 6e 20 53 5357930 /* An S
df10: 51 4c 49 54 45 5f 4d 49 53 55 53 45 20 65 72 72 QLITE_MISUSE err
df20: 6f 72 20 6f 63 63 75 72 72 65 64 20 2a 2f 0a 23 or occurred */.#
df30: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
df40: 47 49 43 5f 5a 4f 4d 42 49 45 20 20 20 30 78 36 GIC_ZOMBIE 0x6
df50: 34 63 66 66 63 37 66 20 20 2f 2a 20 43 6c 6f 73 4cffc7f /* Clos
df60: 65 20 77 69 74 68 20 6c 61 73 74 20 73 74 61 74 e with last stat
df70: 65 6d 65 6e 74 20 63 6c 6f 73 65 20 2a 2f 0a 0a ement close */..
df80: 2f 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 66 /*.** Each SQL f
df90: 75 6e 63 74 69 6f 6e 20 69 73 20 64 65 66 69 6e unction is defin
dfa0: 65 64 20 62 79 20 61 6e 20 69 6e 73 74 61 6e 63 ed by an instanc
dfb0: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
dfc0: 6e 67 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 2e ng.** structure.
dfd0: 20 20 46 6f 72 20 67 6c 6f 62 61 6c 20 62 75 69 For global bui
dfe0: 6c 74 2d 69 6e 20 66 75 6e 63 74 69 6f 6e 73 20 lt-in functions
dff0: 28 65 78 3a 20 73 75 62 73 74 72 28 29 2c 20 6d (ex: substr(), m
e000: 61 78 28 29 2c 20 63 6f 75 6e 74 28 29 29 0a 2a ax(), count()).*
e010: 2a 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 * a pointer to t
e020: 68 69 73 20 73 74 72 75 63 74 75 72 65 20 69 73 his structure is
e030: 20 68 65 6c 64 20 69 6e 20 74 68 65 20 73 71 6c held in the sql
e040: 69 74 65 33 42 75 69 6c 74 69 6e 46 75 6e 63 74 ite3BuiltinFunct
e050: 69 6f 6e 73 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 ions object..**
e060: 46 6f 72 20 70 65 72 2d 63 6f 6e 6e 65 63 74 69 For per-connecti
e070: 6f 6e 20 61 70 70 6c 69 63 61 74 69 6f 6e 2d 64 on application-d
e080: 65 66 69 6e 65 64 20 66 75 6e 63 74 69 6f 6e 73 efined functions
e090: 2c 20 61 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 , a pointer to t
e0a0: 68 69 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 his.** structure
e0b0: 20 69 73 20 68 65 6c 64 20 69 6e 20 74 68 65 20 is held in the
e0c0: 64 62 2d 3e 61 48 61 73 68 20 68 61 73 68 20 74 db->aHash hash t
e0d0: 61 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 able..**.** The
e0e0: 75 2e 70 48 61 73 68 20 66 69 65 6c 64 20 69 73 u.pHash field is
e0f0: 20 75 73 65 64 20 62 79 20 74 68 65 20 67 6c 6f used by the glo
e100: 62 61 6c 20 62 75 69 6c 74 2d 69 6e 73 2e 20 20 bal built-ins.
e110: 54 68 65 20 75 2e 70 44 65 73 74 72 75 63 74 6f The u.pDestructo
e120: 72 0a 2a 2a 20 66 69 65 6c 64 20 69 73 20 75 73 r.** field is us
e130: 65 64 20 62 79 20 70 65 72 2d 63 6f 6e 6e 65 63 ed by per-connec
e140: 74 69 6f 6e 20 61 70 70 2d 64 65 66 20 66 75 6e tion app-def fun
e150: 63 74 69 6f 6e 73 2e 0a 2a 2f 0a 73 74 72 75 63 ctions..*/.struc
e160: 74 20 46 75 6e 63 44 65 66 20 7b 0a 20 20 69 38 t FuncDef {. i8
e170: 20 6e 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 nArg;
e180: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
e190: 61 72 67 75 6d 65 6e 74 73 2e 20 20 2d 31 20 6d arguments. -1 m
e1a0: 65 61 6e 73 20 75 6e 6c 69 6d 69 74 65 64 20 2a eans unlimited *
e1b0: 2f 0a 20 20 75 31 36 20 66 75 6e 63 46 6c 61 67 /. u16 funcFlag
e1c0: 73 3b 20 20 20 20 20 20 20 2f 2a 20 53 6f 6d 65 s; /* Some
e1d0: 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 combination of
e1e0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 2a 20 2a 2f SQLITE_FUNC_* */
e1f0: 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 72 44 61 . void *pUserDa
e200: 74 61 3b 20 20 20 20 20 2f 2a 20 55 73 65 72 20 ta; /* User
e210: 64 61 74 61 20 70 61 72 61 6d 65 74 65 72 20 2a data parameter *
e220: 2f 0a 20 20 46 75 6e 63 44 65 66 20 2a 70 4e 65 /. FuncDef *pNe
e230: 78 74 3b 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 xt; /* Next
e240: 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 73 function with s
e250: 61 6d 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 76 6f ame name */. vo
e260: 69 64 20 28 2a 78 53 46 75 6e 63 29 28 73 71 6c id (*xSFunc)(sql
e270: 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e ite3_context*,in
e280: 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a t,sqlite3_value*
e290: 2a 29 3b 20 2f 2a 20 66 75 6e 63 20 6f 72 20 61 *); /* func or a
e2a0: 67 67 2d 73 74 65 70 20 2a 2f 0a 20 20 76 6f 69 gg-step */. voi
e2b0: 64 20 28 2a 78 46 69 6e 61 6c 69 7a 65 29 28 73 d (*xFinalize)(s
e2c0: 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 qlite3_context*)
e2d0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
e2e0: 20 20 20 2f 2a 20 41 67 67 20 66 69 6e 61 6c 69 /* Agg finali
e2f0: 7a 65 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 zer */. const c
e300: 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 2f 2a har *zName; /*
e310: 20 53 51 4c 20 6e 61 6d 65 20 6f 66 20 74 68 65 SQL name of the
e320: 20 66 75 6e 63 74 69 6f 6e 2e 20 2a 2f 0a 20 20 function. */.
e330: 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 46 75 6e 63 union {. Func
e340: 44 65 66 20 2a 70 48 61 73 68 3b 20 20 20 20 20 Def *pHash;
e350: 20 2f 2a 20 4e 65 78 74 20 77 69 74 68 20 61 20 /* Next with a
e360: 64 69 66 66 65 72 65 6e 74 20 6e 61 6d 65 20 62 different name b
e370: 75 74 20 74 68 65 20 73 61 6d 65 20 68 61 73 68 ut the same hash
e380: 20 2a 2f 0a 20 20 20 20 46 75 6e 63 44 65 73 74 */. FuncDest
e390: 72 75 63 74 6f 72 20 2a 70 44 65 73 74 72 75 63 ructor *pDestruc
e3a0: 74 6f 72 3b 20 20 20 2f 2a 20 52 65 66 65 72 65 tor; /* Refere
e3b0: 6e 63 65 20 63 6f 75 6e 74 65 64 20 64 65 73 74 nce counted dest
e3c0: 72 75 63 74 6f 72 20 66 75 6e 63 74 69 6f 6e 20 ructor function
e3d0: 2a 2f 0a 20 20 7d 20 75 3b 0a 7d 3b 0a 0a 2f 2a */. } u;.};../*
e3e0: 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 .** This structu
e3f0: 72 65 20 65 6e 63 61 70 73 75 6c 61 74 65 73 20 re encapsulates
e400: 61 20 75 73 65 72 2d 66 75 6e 63 74 69 6f 6e 20 a user-function
e410: 64 65 73 74 72 75 63 74 6f 72 20 63 61 6c 6c 62 destructor callb
e420: 61 63 6b 20 28 61 73 0a 2a 2a 20 63 6f 6e 66 69 ack (as.** confi
e430: 67 75 72 65 64 20 75 73 69 6e 67 20 63 72 65 61 gured using crea
e440: 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 29 te_function_v2()
e450: 29 20 61 6e 64 20 61 20 72 65 66 65 72 65 6e 63 ) and a referenc
e460: 65 20 63 6f 75 6e 74 65 72 2e 20 57 68 65 6e 0a e counter. When.
e470: 2a 2a 20 63 72 65 61 74 65 5f 66 75 6e 63 74 69 ** create_functi
e480: 6f 6e 5f 76 32 28 29 20 69 73 20 63 61 6c 6c 65 on_v2() is calle
e490: 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 66 75 d to create a fu
e4a0: 6e 63 74 69 6f 6e 20 77 69 74 68 20 61 20 64 65 nction with a de
e4b0: 73 74 72 75 63 74 6f 72 2c 0a 2a 2a 20 61 20 73 structor,.** a s
e4c0: 69 6e 67 6c 65 20 6f 62 6a 65 63 74 20 6f 66 20 ingle object of
e4d0: 74 68 69 73 20 74 79 70 65 20 69 73 20 61 6c 6c this type is all
e4e0: 6f 63 61 74 65 64 2e 20 46 75 6e 63 44 65 73 74 ocated. FuncDest
e4f0: 72 75 63 74 6f 72 2e 6e 52 65 66 20 69 73 20 73 ructor.nRef is s
e500: 65 74 20 74 6f 0a 2a 2a 20 74 68 65 20 6e 75 6d et to.** the num
e510: 62 65 72 20 6f 66 20 46 75 6e 63 44 65 66 20 6f ber of FuncDef o
e520: 62 6a 65 63 74 73 20 63 72 65 61 74 65 64 20 28 bjects created (
e530: 65 69 74 68 65 72 20 31 20 6f 72 20 33 2c 20 64 either 1 or 3, d
e540: 65 70 65 6e 64 69 6e 67 20 6f 6e 20 77 68 65 74 epending on whet
e550: 68 65 72 0a 2a 2a 20 6f 72 20 6e 6f 74 20 74 68 her.** or not th
e560: 65 20 73 70 65 63 69 66 69 65 64 20 65 6e 63 6f e specified enco
e570: 64 69 6e 67 20 69 73 20 53 51 4c 49 54 45 5f 41 ding is SQLITE_A
e580: 4e 59 29 2e 20 54 68 65 20 46 75 6e 63 44 65 66 NY). The FuncDef
e590: 2e 70 44 65 73 74 72 75 63 74 6f 72 0a 2a 2a 20 .pDestructor.**
e5a0: 6d 65 6d 62 65 72 20 6f 66 20 65 61 63 68 20 6f member of each o
e5b0: 66 20 74 68 65 20 6e 65 77 20 46 75 6e 63 44 65 f the new FuncDe
e5c0: 66 20 6f 62 6a 65 63 74 73 20 69 73 20 73 65 74 f objects is set
e5d0: 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 to point to the
e5e0: 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 46 75 allocated.** Fu
e5f0: 6e 63 44 65 73 74 72 75 63 74 6f 72 2e 0a 2a 2a ncDestructor..**
e600: 0a 2a 2a 20 54 68 65 72 65 61 66 74 65 72 2c 20 .** Thereafter,
e610: 77 68 65 6e 20 6f 6e 65 20 6f 66 20 74 68 65 20 when one of the
e620: 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 20 FuncDef objects
e630: 69 73 20 64 65 6c 65 74 65 64 2c 20 74 68 65 20 is deleted, the
e640: 72 65 66 65 72 65 6e 63 65 0a 2a 2a 20 63 6f 75 reference.** cou
e650: 6e 74 20 6f 6e 20 74 68 69 73 20 6f 62 6a 65 63 nt on this objec
e660: 74 20 69 73 20 64 65 63 72 65 6d 65 6e 74 65 64 t is decremented
e670: 2e 20 57 68 65 6e 20 69 74 20 72 65 61 63 68 65 . When it reache
e680: 73 20 30 2c 20 74 68 65 20 64 65 73 74 72 75 63 s 0, the destruc
e690: 74 6f 72 0a 2a 2a 20 69 73 20 69 6e 76 6f 6b 65 tor.** is invoke
e6a0: 64 20 61 6e 64 20 74 68 65 20 46 75 6e 63 44 65 d and the FuncDe
e6b0: 73 74 72 75 63 74 6f 72 20 73 74 72 75 63 74 75 structor structu
e6c0: 72 65 20 66 72 65 65 64 2e 0a 2a 2f 0a 73 74 72 re freed..*/.str
e6d0: 75 63 74 20 46 75 6e 63 44 65 73 74 72 75 63 74 uct FuncDestruct
e6e0: 6f 72 20 7b 0a 20 20 69 6e 74 20 6e 52 65 66 3b or {. int nRef;
e6f0: 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 73 74 72 . void (*xDestr
e700: 6f 79 29 28 76 6f 69 64 20 2a 29 3b 0a 20 20 76 oy)(void *);. v
e710: 6f 69 64 20 2a 70 55 73 65 72 44 61 74 61 3b 0a oid *pUserData;.
e720: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 };../*.** Possib
e730: 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 46 75 le values for Fu
e740: 6e 63 44 65 66 2e 66 6c 61 67 73 2e 20 20 4e 6f ncDef.flags. No
e750: 74 65 20 74 68 61 74 20 74 68 65 20 5f 4c 45 4e te that the _LEN
e760: 47 54 48 20 61 6e 64 20 5f 54 59 50 45 4f 46 0a GTH and _TYPEOF.
e770: 2a 2a 20 76 61 6c 75 65 73 20 6d 75 73 74 20 63 ** values must c
e780: 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 4f 50 46 orrespond to OPF
e790: 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 61 6e LAG_LENGTHARG an
e7a0: 64 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 d OPFLAG_TYPEOFA
e7b0: 52 47 2e 20 20 41 6e 64 0a 2a 2a 20 53 51 4c 49 RG. And.** SQLI
e7c0: 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 TE_FUNC_CONSTANT
e7d0: 20 6d 75 73 74 20 62 65 20 74 68 65 20 73 61 6d must be the sam
e7e0: 65 20 61 73 20 53 51 4c 49 54 45 5f 44 45 54 45 e as SQLITE_DETE
e7f0: 52 4d 49 4e 49 53 54 49 43 2e 20 20 54 68 65 72 RMINISTIC. Ther
e800: 65 0a 2a 2a 20 61 72 65 20 61 73 73 65 72 74 28 e.** are assert(
e810: 29 20 73 74 61 74 65 6d 65 6e 74 73 20 69 6e 20 ) statements in
e820: 74 68 65 20 63 6f 64 65 20 74 6f 20 76 65 72 69 the code to veri
e830: 66 79 20 74 68 69 73 2e 0a 2a 2a 0a 2a 2a 20 56 fy this..**.** V
e840: 61 6c 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 alue constraints
e850: 20 28 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 (enforced via a
e860: 73 73 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 ssert()):.**
e870: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 4e SQLITE_FUNC_MIN
e880: 4d 41 58 20 20 20 20 3d 3d 20 20 4e 43 5f 4d 69 MAX == NC_Mi
e890: 6e 4d 61 78 41 67 67 20 20 20 20 20 20 3d 3d 20 nMaxAgg ==
e8a0: 53 46 5f 4d 69 6e 4d 61 78 41 67 67 0a 2a 2a 20 SF_MinMaxAgg.**
e8b0: 20 20 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f SQLITE_FUNC_
e8c0: 4c 45 4e 47 54 48 20 20 20 20 3d 3d 20 20 4f 50 LENGTH == OP
e8d0: 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 0a 2a FLAG_LENGTHARG.*
e8e0: 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 46 55 4e * SQLITE_FUN
e8f0: 43 5f 54 59 50 45 4f 46 20 20 20 20 3d 3d 20 20 C_TYPEOF ==
e900: 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 OPFLAG_TYPEOFARG
e910: 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 46 .** SQLITE_F
e920: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 20 3d 3d UNC_CONSTANT ==
e930: 20 20 53 51 4c 49 54 45 5f 44 45 54 45 52 4d 49 SQLITE_DETERMI
e940: 4e 49 53 54 49 43 20 66 72 6f 6d 20 74 68 65 20 NISTIC from the
e950: 41 50 49 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 API.** SQLIT
e960: 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 53 4b 20 20 E_FUNC_ENCMASK
e970: 20 64 65 70 65 6e 64 73 20 6f 6e 20 53 51 4c 49 depends on SQLI
e980: 54 45 5f 55 54 46 2a 20 6d 61 63 72 6f 73 20 69 TE_UTF* macros i
e990: 6e 20 74 68 65 20 41 50 49 0a 2a 2f 0a 23 64 65 n the API.*/.#de
e9a0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 fine SQLITE_FUNC
e9b0: 5f 45 4e 43 4d 41 53 4b 20 20 30 78 30 30 30 33 _ENCMASK 0x0003
e9c0: 20 2f 2a 20 53 51 4c 49 54 45 5f 55 54 46 38 2c /* SQLITE_UTF8,
e9d0: 20 53 51 4c 49 54 45 5f 55 54 46 31 36 42 45 20 SQLITE_UTF16BE
e9e0: 6f 72 20 55 54 46 31 36 4c 45 20 2a 2f 0a 23 64 or UTF16LE */.#d
e9f0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
ea00: 43 5f 4c 49 4b 45 20 20 20 20 20 30 78 30 30 30 C_LIKE 0x000
ea10: 34 20 2f 2a 20 43 61 6e 64 69 64 61 74 65 20 66 4 /* Candidate f
ea20: 6f 72 20 74 68 65 20 4c 49 4b 45 20 6f 70 74 69 or the LIKE opti
ea30: 6d 69 7a 61 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 mization */.#def
ea40: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
ea50: 43 41 53 45 20 20 20 20 20 30 78 30 30 30 38 20 CASE 0x0008
ea60: 2f 2a 20 43 61 73 65 2d 73 65 6e 73 69 74 69 76 /* Case-sensitiv
ea70: 65 20 4c 49 4b 45 2d 74 79 70 65 20 66 75 6e 63 e LIKE-type func
ea80: 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
ea90: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 45 50 48 45 SQLITE_FUNC_EPHE
eaa0: 4d 20 20 20 20 30 78 30 30 31 30 20 2f 2a 20 45 M 0x0010 /* E
eab0: 70 68 65 6d 65 72 61 6c 2e 20 20 44 65 6c 65 74 phemeral. Delet
eac0: 65 20 77 69 74 68 20 56 44 42 45 20 2a 2f 0a 23 e with VDBE */.#
ead0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
eae0: 4e 43 5f 4e 45 45 44 43 4f 4c 4c 20 30 78 30 30 NC_NEEDCOLL 0x00
eaf0: 32 30 20 2f 2a 20 73 71 6c 69 74 65 33 47 65 74 20 /* sqlite3Get
eb00: 46 75 6e 63 43 6f 6c 6c 53 65 71 28 29 20 6d 69 FuncCollSeq() mi
eb10: 67 68 74 20 62 65 20 63 61 6c 6c 65 64 2a 2f 0a ght be called*/.
eb20: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
eb30: 55 4e 43 5f 4c 45 4e 47 54 48 20 20 20 30 78 30 UNC_LENGTH 0x0
eb40: 30 34 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 040 /* Built-in
eb50: 6c 65 6e 67 74 68 28 29 20 66 75 6e 63 74 69 6f length() functio
eb60: 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c n */.#define SQL
eb70: 49 54 45 5f 46 55 4e 43 5f 54 59 50 45 4f 46 20 ITE_FUNC_TYPEOF
eb80: 20 20 30 78 30 30 38 30 20 2f 2a 20 42 75 69 6c 0x0080 /* Buil
eb90: 74 2d 69 6e 20 74 79 70 65 6f 66 28 29 20 66 75 t-in typeof() fu
eba0: 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e nction */.#defin
ebb0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
ebc0: 55 4e 54 20 20 20 20 30 78 30 31 30 30 20 2f 2a UNT 0x0100 /*
ebd0: 20 42 75 69 6c 74 2d 69 6e 20 63 6f 75 6e 74 28 Built-in count(
ebe0: 2a 29 20 61 67 67 72 65 67 61 74 65 20 2a 2f 0a *) aggregate */.
ebf0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
ec00: 55 4e 43 5f 43 4f 41 4c 45 53 43 45 20 30 78 30 UNC_COALESCE 0x0
ec10: 32 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 200 /* Built-in
ec20: 63 6f 61 6c 65 73 63 65 28 29 20 6f 72 20 69 66 coalesce() or if
ec30: 6e 75 6c 6c 28 29 20 2a 2f 0a 23 64 65 66 69 6e null() */.#defin
ec40: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 55 4e e SQLITE_FUNC_UN
ec50: 4c 49 4b 45 4c 59 20 30 78 30 34 30 30 20 2f 2a LIKELY 0x0400 /*
ec60: 20 42 75 69 6c 74 2d 69 6e 20 75 6e 6c 69 6b 65 Built-in unlike
ec70: 6c 79 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ly() function */
ec80: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ec90: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 30 78 FUNC_CONSTANT 0x
eca0: 30 38 30 30 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 0800 /* Constant
ecb0: 20 69 6e 70 75 74 73 20 67 69 76 65 20 61 20 63 inputs give a c
ecc0: 6f 6e 73 74 61 6e 74 20 6f 75 74 70 75 74 20 2a onstant output *
ecd0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
ece0: 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 20 20 20 30 _FUNC_MINMAX 0
ecf0: 78 31 30 30 30 20 2f 2a 20 54 72 75 65 20 66 6f x1000 /* True fo
ed00: 72 20 6d 69 6e 28 29 20 61 6e 64 20 6d 61 78 28 r min() and max(
ed10: 29 20 61 67 67 72 65 67 61 74 65 73 20 2a 2f 0a ) aggregates */.
ed20: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
ed30: 55 4e 43 5f 53 4c 4f 43 48 4e 47 20 20 30 78 32 UNC_SLOCHNG 0x2
ed40: 30 30 30 20 2f 2a 20 22 53 6c 6f 77 20 43 68 61 000 /* "Slow Cha
ed50: 6e 67 65 22 2e 20 56 61 6c 75 65 20 63 6f 6e 73 nge". Value cons
ed60: 74 61 6e 74 20 64 75 72 69 6e 67 20 61 0a 20 20 tant during a.
ed70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ed80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ed90: 20 20 2a 2a 20 73 69 6e 67 6c 65 20 71 75 65 72 ** single quer
eda0: 79 20 2d 20 6d 69 67 68 74 20 63 68 61 6e 67 65 y - might change
edb0: 20 6f 76 65 72 20 74 69 6d 65 20 2a 2f 0a 23 64 over time */.#d
edc0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
edd0: 43 5f 41 46 46 49 4e 49 54 59 20 30 78 34 30 30 C_AFFINITY 0x400
ede0: 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 61 66 0 /* Built-in af
edf0: 66 69 6e 69 74 79 28 29 20 66 75 6e 63 74 69 6f finity() functio
ee00: 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 n */../*.** The
ee10: 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 72 65 65 20 following three
ee20: 6d 61 63 72 6f 73 2c 20 46 55 4e 43 54 49 4f 4e macros, FUNCTION
ee30: 28 29 2c 20 4c 49 4b 45 46 55 4e 43 28 29 20 61 (), LIKEFUNC() a
ee40: 6e 64 20 41 47 47 52 45 47 41 54 45 28 29 20 61 nd AGGREGATE() a
ee50: 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f 20 63 72 re.** used to cr
ee60: 65 61 74 65 20 74 68 65 20 69 6e 69 74 69 61 6c eate the initial
ee70: 69 7a 65 72 73 20 66 6f 72 20 74 68 65 20 46 75 izers for the Fu
ee80: 6e 63 44 65 66 20 73 74 72 75 63 74 75 72 65 73 ncDef structures
ee90: 2e 0a 2a 2a 0a 2a 2a 20 20 20 46 55 4e 43 54 49 ..**.** FUNCTI
eea0: 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 ON(zName, nArg,
eeb0: 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 iArg, bNC, xFunc
eec0: 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 20 74 6f ).** Used to
eed0: 20 63 72 65 61 74 65 20 61 20 73 63 61 6c 61 72 create a scalar
eee0: 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 function defini
eef0: 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e 63 74 69 tion of a functi
ef00: 6f 6e 20 7a 4e 61 6d 65 0a 2a 2a 20 20 20 20 20 on zName.**
ef10: 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 20 43 implemented by C
ef20: 20 66 75 6e 63 74 69 6f 6e 20 78 46 75 6e 63 20 function xFunc
ef30: 74 68 61 74 20 61 63 63 65 70 74 73 20 6e 41 72 that accepts nAr
ef40: 67 20 61 72 67 75 6d 65 6e 74 73 2e 20 54 68 65 g arguments. The
ef50: 0a 2a 2a 20 20 20 20 20 76 61 6c 75 65 20 70 61 .** value pa
ef60: 73 73 65 64 20 61 73 20 69 41 72 67 20 69 73 20 ssed as iArg is
ef70: 63 61 73 74 20 74 6f 20 61 20 28 76 6f 69 64 2a cast to a (void*
ef80: 29 20 61 6e 64 20 6d 61 64 65 20 61 76 61 69 6c ) and made avail
ef90: 61 62 6c 65 0a 2a 2a 20 20 20 20 20 61 73 20 74 able.** as t
efa0: 68 65 20 75 73 65 72 2d 64 61 74 61 20 28 73 71 he user-data (sq
efb0: 6c 69 74 65 33 5f 75 73 65 72 5f 64 61 74 61 28 lite3_user_data(
efc0: 29 29 20 66 6f 72 20 74 68 65 20 66 75 6e 63 74 )) for the funct
efd0: 69 6f 6e 2e 20 49 66 0a 2a 2a 20 20 20 20 20 61 ion. If.** a
efe0: 72 67 75 6d 65 6e 74 20 62 4e 43 20 69 73 20 74 rgument bNC is t
eff0: 72 75 65 2c 20 74 68 65 6e 20 74 68 65 20 53 51 rue, then the SQ
f000: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
f010: 4c 4c 20 66 6c 61 67 20 69 73 20 73 65 74 2e 0a LL flag is set..
f020: 2a 2a 0a 2a 2a 20 20 20 56 46 55 4e 43 54 49 4f **.** VFUNCTIO
f030: 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 N(zName, nArg, i
f040: 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 Arg, bNC, xFunc)
f050: 0a 2a 2a 20 20 20 20 20 4c 69 6b 65 20 46 55 4e .** Like FUN
f060: 43 54 49 4f 4e 20 65 78 63 65 70 74 20 69 74 20 CTION except it
f070: 6f 6d 69 74 73 20 74 68 65 20 53 51 4c 49 54 45 omits the SQLITE
f080: 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 66 _FUNC_CONSTANT f
f090: 6c 61 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 44 46 55 lag..**.** DFU
f0a0: 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 NCTION(zName, nA
f0b0: 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 rg, iArg, bNC, x
f0c0: 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 4c 69 6b Func).** Lik
f0d0: 65 20 46 55 4e 43 54 49 4f 4e 20 65 78 63 65 70 e FUNCTION excep
f0e0: 74 20 69 74 20 6f 6d 69 74 73 20 74 68 65 20 53 t it omits the S
f0f0: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 QLITE_FUNC_CONST
f100: 41 4e 54 20 66 6c 61 67 20 61 6e 64 0a 2a 2a 20 ANT flag and.**
f110: 20 20 20 20 61 64 64 73 20 74 68 65 20 53 51 4c adds the SQL
f120: 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 ITE_FUNC_SLOCHNG
f130: 20 66 6c 61 67 2e 20 20 55 73 65 64 20 66 6f 72 flag. Used for
f140: 20 64 61 74 65 20 26 20 74 69 6d 65 20 66 75 6e date & time fun
f150: 63 74 69 6f 6e 73 0a 2a 2a 20 20 20 20 20 61 6e ctions.** an
f160: 64 20 66 75 6e 63 74 69 6f 6e 73 20 6c 69 6b 65 d functions like
f170: 20 73 71 6c 69 74 65 5f 76 65 72 73 69 6f 6e 28 sqlite_version(
f180: 29 20 74 68 61 74 20 63 61 6e 20 63 68 61 6e 67 ) that can chang
f190: 65 2c 20 62 75 74 20 6e 6f 74 20 64 75 72 69 6e e, but not durin
f1a0: 67 0a 2a 2a 20 20 20 20 20 61 20 73 69 6e 67 6c g.** a singl
f1b0: 65 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 20 e query..**.**
f1c0: 20 41 47 47 52 45 47 41 54 45 28 7a 4e 61 6d 65 AGGREGATE(zName
f1d0: 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e , nArg, iArg, bN
f1e0: 43 2c 20 78 53 74 65 70 2c 20 78 46 69 6e 61 6c C, xStep, xFinal
f1f0: 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 20 74 6f ).** Used to
f200: 20 63 72 65 61 74 65 20 61 6e 20 61 67 67 72 65 create an aggre
f210: 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 64 65 gate function de
f220: 66 69 6e 69 74 69 6f 6e 20 69 6d 70 6c 65 6d 65 finition impleme
f230: 6e 74 65 64 20 62 79 0a 2a 2a 20 20 20 20 20 74 nted by.** t
f240: 68 65 20 43 20 66 75 6e 63 74 69 6f 6e 73 20 78 he C functions x
f250: 53 74 65 70 20 61 6e 64 20 78 46 69 6e 61 6c 2e Step and xFinal.
f260: 20 54 68 65 20 66 69 72 73 74 20 66 6f 75 72 20 The first four
f270: 70 61 72 61 6d 65 74 65 72 73 0a 2a 2a 20 20 20 parameters.**
f280: 20 20 61 72 65 20 69 6e 74 65 72 70 72 65 74 65 are interprete
f290: 64 20 69 6e 20 74 68 65 20 73 61 6d 65 20 77 61 d in the same wa
f2a0: 79 20 61 73 20 74 68 65 20 66 69 72 73 74 20 34 y as the first 4
f2b0: 20 70 61 72 61 6d 65 74 65 72 73 20 74 6f 0a 2a parameters to.*
f2c0: 2a 20 20 20 20 20 46 55 4e 43 54 49 4f 4e 28 29 * FUNCTION()
f2d0: 2e 0a 2a 2a 0a 2a 2a 20 20 20 4c 49 4b 45 46 55 ..**.** LIKEFU
f2e0: 4e 43 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 NC(zName, nArg,
f2f0: 70 41 72 67 2c 20 66 6c 61 67 73 29 0a 2a 2a 20 pArg, flags).**
f300: 20 20 20 20 55 73 65 64 20 74 6f 20 63 72 65 61 Used to crea
f310: 74 65 20 61 20 73 63 61 6c 61 72 20 66 75 6e 63 te a scalar func
f320: 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 20 tion definition
f330: 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 20 7a 4e of a function zN
f340: 61 6d 65 0a 2a 2a 20 20 20 20 20 74 68 61 74 20 ame.** that
f350: 61 63 63 65 70 74 73 20 6e 41 72 67 20 61 72 67 accepts nArg arg
f360: 75 6d 65 6e 74 73 20 61 6e 64 20 69 73 20 69 6d uments and is im
f370: 70 6c 65 6d 65 6e 74 65 64 20 62 79 20 61 20 63 plemented by a c
f380: 61 6c 6c 20 74 6f 20 43 0a 2a 2a 20 20 20 20 20 all to C.**
f390: 66 75 6e 63 74 69 6f 6e 20 6c 69 6b 65 46 75 6e function likeFun
f3a0: 63 2e 20 41 72 67 75 6d 65 6e 74 20 70 41 72 67 c. Argument pArg
f3b0: 20 69 73 20 63 61 73 74 20 74 6f 20 61 20 28 76 is cast to a (v
f3c0: 6f 69 64 20 2a 29 20 61 6e 64 20 6d 61 64 65 0a oid *) and made.
f3d0: 2a 2a 20 20 20 20 20 61 76 61 69 6c 61 62 6c 65 ** available
f3e0: 20 61 73 20 74 68 65 20 66 75 6e 63 74 69 6f 6e as the function
f3f0: 20 75 73 65 72 2d 64 61 74 61 20 28 73 71 6c 69 user-data (sqli
f400: 74 65 33 5f 75 73 65 72 5f 64 61 74 61 28 29 29 te3_user_data())
f410: 2e 20 54 68 65 0a 2a 2a 20 20 20 20 20 46 75 6e . The.** Fun
f420: 63 44 65 66 2e 66 6c 61 67 73 20 76 61 72 69 61 cDef.flags varia
f430: 62 6c 65 20 69 73 20 73 65 74 20 74 6f 20 74 68 ble is set to th
f440: 65 20 76 61 6c 75 65 20 70 61 73 73 65 64 20 61 e value passed a
f450: 73 20 74 68 65 20 66 6c 61 67 73 0a 2a 2a 20 20 s the flags.**
f460: 20 20 20 70 61 72 61 6d 65 74 65 72 2e 0a 2a 2f parameter..*/
f470: 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f .#define FUNCTIO
f480: 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 N(zName, nArg, i
f490: 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 Arg, bNC, xFunc)
f4a0: 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 \. {nArg, SQLI
f4b0: 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 TE_FUNC_CONSTANT
f4c0: 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e |SQLITE_UTF8|(bN
f4d0: 43 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 C*SQLITE_FUNC_NE
f4e0: 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 EDCOLL), \. SQ
f4f0: 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 LITE_INT_TO_PTR(
f500: 69 41 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c iArg), 0, xFunc,
f510: 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 0, #zName, {0}
f520: 7d 0a 23 64 65 66 69 6e 65 20 56 46 55 4e 43 54 }.#define VFUNCT
f530: 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c ION(zName, nArg,
f540: 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e iArg, bNC, xFun
f550: 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 c) \. {nArg, SQ
f560: 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 LITE_UTF8|(bNC*S
f570: 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 QLITE_FUNC_NEEDC
f580: 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 OLL), \. SQLIT
f590: 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 E_INT_TO_PTR(iAr
f5a0: 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c g), 0, xFunc, 0,
f5b0: 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0a 23 #zName, {0} }.#
f5c0: 64 65 66 69 6e 65 20 44 46 55 4e 43 54 49 4f 4e define DFUNCTION
f5d0: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 (zName, nArg, iA
f5e0: 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 rg, bNC, xFunc)
f5f0: 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 \. {nArg, SQLIT
f600: 45 5f 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 7c 53 E_FUNC_SLOCHNG|S
f610: 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a QLITE_UTF8|(bNC*
f620: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 SQLITE_FUNC_NEED
f630: 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 COLL), \. SQLI
f640: 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 TE_INT_TO_PTR(iA
f650: 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 rg), 0, xFunc, 0
f660: 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0a , #zName, {0} }.
f670: 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f 4e #define FUNCTION
f680: 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 2(zName, nArg, i
f690: 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 2c Arg, bNC, xFunc,
f6a0: 20 65 78 74 72 61 46 6c 61 67 73 29 20 5c 0a 20 extraFlags) \.
f6b0: 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f 46 55 {nArg,SQLITE_FU
f6c0: 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 NC_CONSTANT|SQLI
f6d0: 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c TE_UTF8|(bNC*SQL
f6e0: 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c ITE_FUNC_NEEDCOL
f6f0: 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 5c 0a L)|extraFlags,\.
f700: 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f SQLITE_INT_TO
f710: 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 78 _PTR(iArg), 0, x
f720: 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c Func, 0, #zName,
f730: 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 53 {0} }.#define S
f740: 54 52 5f 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d TR_FUNCTION(zNam
f750: 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 62 e, nArg, pArg, b
f760: 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 20 7b NC, xFunc) \. {
f770: 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e nArg, SQLITE_FUN
f780: 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c 49 54 45 C_SLOCHNG|SQLITE
f790: 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 4c 49 54 _UTF8|(bNC*SQLIT
f7a0: 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c 29 E_FUNC_NEEDCOLL)
f7b0: 2c 20 5c 0a 20 20 20 70 41 72 67 2c 20 30 2c 20 , \. pArg, 0,
f7c0: 78 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 xFunc, 0, #zName
f7d0: 2c 20 7d 0a 23 64 65 66 69 6e 65 20 4c 49 4b 45 , }.#define LIKE
f7e0: 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 FUNC(zName, nArg
f7f0: 2c 20 61 72 67 2c 20 66 6c 61 67 73 29 20 5c 0a , arg, flags) \.
f800: 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
f810: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 FUNC_CONSTANT|SQ
f820: 4c 49 54 45 5f 55 54 46 38 7c 66 6c 61 67 73 2c LITE_UTF8|flags,
f830: 20 5c 0a 20 20 20 28 76 6f 69 64 20 2a 29 61 72 \. (void *)ar
f840: 67 2c 20 30 2c 20 6c 69 6b 65 46 75 6e 63 2c 20 g, 0, likeFunc,
f850: 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 7d 0, #zName, {0} }
f860: 0a 23 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 .#define AGGREGA
f870: 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 TE(zName, nArg,
f880: 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 arg, nc, xStep,
f890: 78 46 69 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 xFinal) \. {nAr
f8a0: 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
f8b0: 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
f8c0: 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 EEDCOLL), \. S
f8d0: 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 QLITE_INT_TO_PTR
f8e0: 28 61 72 67 29 2c 20 30 2c 20 78 53 74 65 70 2c (arg), 0, xStep,
f8f0: 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 20 7b xFinal,#zName, {
f900: 30 7d 7d 0a 23 64 65 66 69 6e 65 20 41 47 47 52 0}}.#define AGGR
f910: 45 47 41 54 45 32 28 7a 4e 61 6d 65 2c 20 6e 41 EGATE2(zName, nA
f920: 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 rg, arg, nc, xSt
f930: 65 70 2c 20 78 46 69 6e 61 6c 2c 20 65 78 74 72 ep, xFinal, extr
f940: 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b 6e 41 72 aFlags) \. {nAr
f950: 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 g, SQLITE_UTF8|(
f960: 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e nc*SQLITE_FUNC_N
f970: 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 61 46 6c EEDCOLL)|extraFl
f980: 61 67 73 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 ags, \. SQLITE
f990: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 72 67 29 _INT_TO_PTR(arg)
f9a0: 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 69 6e 61 , 0, xStep,xFina
f9b0: 6c 2c 23 7a 4e 61 6d 65 2c 20 7b 30 7d 7d 0a 0a l,#zName, {0}}..
f9c0: 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 72 72 65 6e /*.** All curren
f9d0: 74 20 73 61 76 65 70 6f 69 6e 74 73 20 61 72 65 t savepoints are
f9e0: 20 73 74 6f 72 65 64 20 69 6e 20 61 20 6c 69 6e stored in a lin
f9f0: 6b 65 64 20 6c 69 73 74 20 73 74 61 72 74 69 6e ked list startin
fa00: 67 20 61 74 0a 2a 2a 20 73 71 6c 69 74 65 33 2e g at.** sqlite3.
fa10: 70 53 61 76 65 70 6f 69 6e 74 2e 20 54 68 65 20 pSavepoint. The
fa20: 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e first element in
fa30: 20 74 68 65 20 6c 69 73 74 20 69 73 20 74 68 65 the list is the
fa40: 20 6d 6f 73 74 20 72 65 63 65 6e 74 6c 79 0a 2a most recently.*
fa50: 2a 20 6f 70 65 6e 65 64 20 73 61 76 65 70 6f 69 * opened savepoi
fa60: 6e 74 2e 20 53 61 76 65 70 6f 69 6e 74 73 20 61 nt. Savepoints a
fa70: 72 65 20 61 64 64 65 64 20 74 6f 20 74 68 65 20 re added to the
fa80: 6c 69 73 74 20 62 79 20 74 68 65 20 76 64 62 65 list by the vdbe
fa90: 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 6f 69 6e 74 .** OP_Savepoint
faa0: 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 2a 2f instruction..*/
fab0: 0a 73 74 72 75 63 74 20 53 61 76 65 70 6f 69 6e .struct Savepoin
fac0: 74 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d t {. char *zNam
fad0: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
fae0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 61 76 /* Sav
faf0: 65 70 6f 69 6e 74 20 6e 61 6d 65 20 28 6e 75 6c epoint name (nul
fb00: 2d 74 65 72 6d 69 6e 61 74 65 64 29 20 2a 2f 0a -terminated) */.
fb10: 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 43 i64 nDeferredC
fb20: 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ons;
fb30: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
fb40: 6f 66 20 64 65 66 65 72 72 65 64 20 66 6b 20 76 of deferred fk v
fb50: 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 69 iolations */. i
fb60: 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d 6d 43 64 nDeferredImmC
fb70: 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ons;
fb80: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
fb90: 64 65 66 65 72 72 65 64 20 69 6d 6d 20 66 6b 2e deferred imm fk.
fba0: 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e 74 20 */. Savepoint
fbb0: 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 *pNext;
fbc0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 /* Par
fbd0: 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 20 28 69 ent savepoint (i
fbe0: 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a f any) */.};../*
fbf0: 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
fc00: 67 20 61 72 65 20 75 73 65 64 20 61 73 20 74 68 g are used as th
fc10: 65 20 73 65 63 6f 6e 64 20 70 61 72 61 6d 65 74 e second paramet
fc20: 65 72 20 74 6f 20 73 71 6c 69 74 65 33 53 61 76 er to sqlite3Sav
fc30: 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 20 61 6e 64 epoint(),.** and
fc40: 20 61 73 20 74 68 65 20 50 31 20 61 72 67 75 6d as the P1 argum
fc50: 65 6e 74 20 74 6f 20 74 68 65 20 4f 50 5f 53 61 ent to the OP_Sa
fc60: 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 75 63 74 vepoint instruct
fc70: 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ion..*/.#define
fc80: 53 41 56 45 50 4f 49 4e 54 5f 42 45 47 49 4e 20 SAVEPOINT_BEGIN
fc90: 20 20 20 20 20 30 0a 23 64 65 66 69 6e 65 20 53 0.#define S
fca0: 41 56 45 50 4f 49 4e 54 5f 52 45 4c 45 41 53 45 AVEPOINT_RELEASE
fcb0: 20 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 41 1.#define SA
fcc0: 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c 42 41 43 4b VEPOINT_ROLLBACK
fcd0: 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 2.../*.** Eac
fce0: 68 20 53 51 4c 69 74 65 20 6d 6f 64 75 6c 65 20 h SQLite module
fcf0: 28 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 64 (virtual table d
fd00: 65 66 69 6e 69 74 69 6f 6e 29 20 69 73 20 64 65 efinition) is de
fd10: 66 69 6e 65 64 20 62 79 20 61 6e 0a 2a 2a 20 69 fined by an.** i
fd20: 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
fd30: 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
fd40: 72 65 2c 20 73 74 6f 72 65 64 20 69 6e 20 74 68 re, stored in th
fd50: 65 20 73 71 6c 69 74 65 33 2e 61 4d 6f 64 75 6c e sqlite3.aModul
fd60: 65 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c 65 2e e.** hash table.
fd70: 0a 2a 2f 0a 73 74 72 75 63 74 20 4d 6f 64 75 6c .*/.struct Modul
fd80: 65 20 7b 0a 20 20 63 6f 6e 73 74 20 73 71 6c 69 e {. const sqli
fd90: 74 65 33 5f 6d 6f 64 75 6c 65 20 2a 70 4d 6f 64 te3_module *pMod
fda0: 75 6c 65 3b 20 20 20 20 20 20 20 2f 2a 20 43 61 ule; /* Ca
fdb0: 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 65 72 73 20 llback pointers
fdc0: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 */. const char
fdd0: 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
fde0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d /* Nam
fdf0: 65 20 70 61 73 73 65 64 20 74 6f 20 63 72 65 61 e passed to crea
fe00: 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 te_module() */.
fe10: 20 76 6f 69 64 20 2a 70 41 75 78 3b 20 20 20 20 void *pAux;
fe20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fe30: 20 20 20 20 20 20 2f 2a 20 70 41 75 78 20 70 61 /* pAux pa
fe40: 73 73 65 64 20 74 6f 20 63 72 65 61 74 65 5f 6d ssed to create_m
fe50: 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 76 6f 69 odule() */. voi
fe60: 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 76 6f d (*xDestroy)(vo
fe70: 69 64 20 2a 29 3b 20 20 20 20 20 20 20 20 20 20 id *);
fe80: 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 64 65 73 74 /* Module dest
fe90: 72 75 63 74 6f 72 20 66 75 6e 63 74 69 6f 6e 20 ructor function
fea0: 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 45 70 6f */. Table *pEpo
feb0: 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 Tab;
fec0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 70 6f /* Epo
fed0: 6e 79 6d 6f 75 73 20 74 61 62 6c 65 20 66 6f 72 nymous table for
fee0: 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 2a 2f 0a this module */.
fef0: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e 66 6f 72 6d };../*.** inform
ff00: 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 ation about each
ff10: 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 6e 20 53 51 column of an SQ
ff20: 4c 20 74 61 62 6c 65 20 69 73 20 68 65 6c 64 20 L table is held
ff30: 69 6e 20 61 6e 20 69 6e 73 74 61 6e 63 65 0a 2a in an instance.*
ff40: 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 * of this struct
ff50: 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 43 ure..*/.struct C
ff60: 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 61 72 20 2a olumn {. char *
ff70: 7a 4e 61 6d 65 3b 20 20 20 20 20 2f 2a 20 4e 61 zName; /* Na
ff80: 6d 65 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d me of this colum
ff90: 6e 2c 20 5c 30 30 30 2c 20 74 68 65 6e 20 74 68 n, \000, then th
ffa0: 65 20 74 79 70 65 20 2a 2f 0a 20 20 45 78 70 72 e type */. Expr
ffb0: 20 2a 70 44 66 6c 74 3b 20 20 20 20 20 2f 2a 20 *pDflt; /*
ffc0: 44 65 66 61 75 6c 74 20 76 61 6c 75 65 20 6f 66 Default value of
ffd0: 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a this column */.
ffe0: 20 20 63 68 61 72 20 2a 7a 43 6f 6c 6c 3b 20 20 char *zColl;
fff0: 20 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 20 /* Collating
10000 73 65 71 75 65 6e 63 65 2e 20 20 49 66 20 4e 55 sequence. If NU
10010 4c 4c 2c 20 75 73 65 20 74 68 65 20 64 65 66 61 LL, use the defa
10020 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6e 6f 74 4e ult */. u8 notN
10030 75 6c 6c 3b 20 20 20 20 20 20 2f 2a 20 41 6e 20 ull; /* An
10040 4f 45 5f 20 63 6f 64 65 20 66 6f 72 20 68 61 6e OE_ code for han
10050 64 6c 69 6e 67 20 61 20 4e 4f 54 20 4e 55 4c 4c dling a NOT NULL
10060 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 20 constraint */.
10070 20 63 68 61 72 20 61 66 66 69 6e 69 74 79 3b 20 char affinity;
10080 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 74 68 65 20 /* One of the
10090 53 51 4c 49 54 45 5f 41 46 46 5f 2e 2e 2e 20 76 SQLITE_AFF_... v
100a0 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 73 7a alues */. u8 sz
100b0 45 73 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 Est; /* E
100c0 73 74 69 6d 61 74 65 64 20 73 69 7a 65 20 6f 66 stimated size of
100d0 20 76 61 6c 75 65 20 69 6e 20 74 68 69 73 20 63 value in this c
100e0 6f 6c 75 6d 6e 2e 20 73 69 7a 65 6f 66 28 49 4e olumn. sizeof(IN
100f0 54 29 3d 3d 31 20 2a 2f 0a 20 20 75 38 20 63 6f T)==1 */. u8 co
10100 6c 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 42 lFlags; /* B
10110 6f 6f 6c 65 61 6e 20 70 72 6f 70 65 72 74 69 65 oolean propertie
10120 73 2e 20 20 53 65 65 20 43 4f 4c 46 4c 41 47 5f s. See COLFLAG_
10130 20 64 65 66 69 6e 65 73 20 62 65 6c 6f 77 20 2a defines below *
10140 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 64 /.};../* Allowed
10150 20 76 61 6c 75 65 73 20 66 6f 72 20 43 6f 6c 75 values for Colu
10160 6d 6e 2e 63 6f 6c 46 6c 61 67 73 3a 0a 2a 2f 0a mn.colFlags:.*/.
10170 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f #define COLFLAG_
10180 50 52 49 4d 4b 45 59 20 20 30 78 30 30 30 31 20 PRIMKEY 0x0001
10190 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 69 73 20 /* Column is
101a0 70 61 72 74 20 6f 66 20 74 68 65 20 70 72 69 6d part of the prim
101b0 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 69 ary key */.#defi
101c0 6e 65 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 45 ne COLFLAG_HIDDE
101d0 4e 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a N 0x0002 /*
101e0 20 41 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e A hidden column
101f0 20 69 6e 20 61 20 76 69 72 74 75 61 6c 20 74 61 in a virtual ta
10200 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 ble */.#define C
10210 4f 4c 46 4c 41 47 5f 48 41 53 54 59 50 45 20 20 OLFLAG_HASTYPE
10220 30 78 30 30 30 34 20 20 20 20 2f 2a 20 54 79 70 0x0004 /* Typ
10230 65 20 6e 61 6d 65 20 66 6f 6c 6c 6f 77 73 20 63 e name follows c
10240 6f 6c 75 6d 6e 20 6e 61 6d 65 20 2a 2f 0a 0a 2f olumn name */../
10250 2a 0a 2a 2a 20 41 20 22 43 6f 6c 6c 61 74 69 6e *.** A "Collatin
10260 67 20 53 65 71 75 65 6e 63 65 22 20 69 73 20 64 g Sequence" is d
10270 65 66 69 6e 65 64 20 62 79 20 61 6e 20 69 6e 73 efined by an ins
10280 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
10290 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 75 63 74 lowing.** struct
102a0 75 72 65 2e 20 43 6f 6e 63 65 70 74 75 61 6c 6c ure. Conceptuall
102b0 79 2c 20 61 20 63 6f 6c 6c 61 74 69 6e 67 20 73 y, a collating s
102c0 65 71 75 65 6e 63 65 20 63 6f 6e 73 69 73 74 73 equence consists
102d0 20 6f 66 20 61 20 6e 61 6d 65 20 61 6e 64 0a 2a of a name and.*
102e0 2a 20 61 20 63 6f 6d 70 61 72 69 73 6f 6e 20 72 * a comparison r
102f0 6f 75 74 69 6e 65 20 74 68 61 74 20 64 65 66 69 outine that defi
10300 6e 65 73 20 74 68 65 20 6f 72 64 65 72 20 6f 66 nes the order of
10310 20 74 68 61 74 20 73 65 71 75 65 6e 63 65 2e 0a that sequence..
10320 2a 2a 0a 2a 2a 20 49 66 20 43 6f 6c 6c 53 65 71 **.** If CollSeq
10330 2e 78 43 6d 70 20 69 73 20 4e 55 4c 4c 2c 20 69 .xCmp is NULL, i
10340 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 t means that the
10350 0a 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 .** collating se
10360 71 75 65 6e 63 65 20 69 73 20 75 6e 64 65 66 69 quence is undefi
10370 6e 65 64 2e 20 20 49 6e 64 69 63 65 73 20 62 75 ned. Indices bu
10380 69 6c 74 20 6f 6e 20 61 6e 20 75 6e 64 65 66 69 ilt on an undefi
10390 6e 65 64 0a 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 ned.** collating
103a0 20 73 65 71 75 65 6e 63 65 20 6d 61 79 20 6e 6f sequence may no
103b0 74 20 62 65 20 72 65 61 64 20 6f 72 20 77 72 69 t be read or wri
103c0 74 74 65 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 tten..*/.struct
103d0 43 6f 6c 6c 53 65 71 20 7b 0a 20 20 63 68 61 72 CollSeq {. char
103e0 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 *zName;
103f0 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 /* Name of the
10400 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 collating seque
10410 6e 63 65 2c 20 55 54 46 2d 38 20 65 6e 63 6f 64 nce, UTF-8 encod
10420 65 64 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 ed */. u8 enc;
10430 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
10440 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 68 Text encoding h
10450 61 6e 64 6c 65 64 20 62 79 20 78 43 6d 70 28 29 andled by xCmp()
10460 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 55 73 65 */. void *pUse
10470 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 r; /* F
10480 69 72 73 74 20 61 72 67 75 6d 65 6e 74 20 74 6f irst argument to
10490 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 69 6e 74 xCmp() */. int
104a0 20 28 2a 78 43 6d 70 29 28 76 6f 69 64 2a 2c 69 (*xCmp)(void*,i
104b0 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c nt, const void*,
104c0 20 69 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 64 int, const void
104d0 2a 29 3b 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 *);. void (*xDe
104e0 6c 29 28 76 6f 69 64 2a 29 3b 20 20 2f 2a 20 44 l)(void*); /* D
104f0 65 73 74 72 75 63 74 6f 72 20 66 6f 72 20 70 55 estructor for pU
10500 73 65 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ser */.};../*.**
10510 20 41 20 73 6f 72 74 20 6f 72 64 65 72 20 63 61 A sort order ca
10520 6e 20 62 65 20 65 69 74 68 65 72 20 41 53 43 20 n be either ASC
10530 6f 72 20 44 45 53 43 2e 0a 2a 2f 0a 23 64 65 66 or DESC..*/.#def
10540 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f 41 53 ine SQLITE_SO_AS
10550 43 20 20 20 20 20 20 20 30 20 20 2f 2a 20 53 6f C 0 /* So
10560 72 74 20 69 6e 20 61 73 63 65 6e 64 69 6e 67 20 rt in ascending
10570 6f 72 64 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 order */.#define
10580 20 53 51 4c 49 54 45 5f 53 4f 5f 44 45 53 43 20 SQLITE_SO_DESC
10590 20 20 20 20 20 31 20 20 2f 2a 20 53 6f 72 74 20 1 /* Sort
105a0 69 6e 20 61 73 63 65 6e 64 69 6e 67 20 6f 72 64 in ascending ord
105b0 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 er */.#define SQ
105c0 4c 49 54 45 5f 53 4f 5f 55 4e 44 45 46 49 4e 45 LITE_SO_UNDEFINE
105d0 44 20 2d 31 20 2f 2a 20 4e 6f 20 73 6f 72 74 20 D -1 /* No sort
105e0 6f 72 64 65 72 20 73 70 65 63 69 66 69 65 64 20 order specified
105f0 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6c 75 6d 6e */../*.** Column
10600 20 61 66 66 69 6e 69 74 79 20 74 79 70 65 73 2e affinity types.
10610 0a 2a 2a 0a 2a 2a 20 54 68 65 73 65 20 75 73 65 .**.** These use
10620 64 20 74 6f 20 68 61 76 65 20 6d 6e 65 6d 6f 6e d to have mnemon
10630 69 63 20 6e 61 6d 65 20 6c 69 6b 65 20 27 69 27 ic name like 'i'
10640 20 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 5f for SQLITE_AFF_
10650 49 4e 54 45 47 45 52 20 61 6e 64 0a 2a 2a 20 27 INTEGER and.** '
10660 74 27 20 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 t' for SQLITE_AF
10670 46 5f 54 45 58 54 2e 20 20 42 75 74 20 77 65 20 F_TEXT. But we
10680 63 61 6e 20 73 61 76 65 20 61 20 6c 69 74 74 6c can save a littl
10690 65 20 73 70 61 63 65 20 61 6e 64 20 69 6d 70 72 e space and impr
106a0 6f 76 65 0a 2a 2a 20 74 68 65 20 73 70 65 65 64 ove.** the speed
106b0 20 61 20 6c 69 74 74 6c 65 20 62 79 20 6e 75 6d a little by num
106c0 62 65 72 69 6e 67 20 74 68 65 20 76 61 6c 75 65 bering the value
106d0 73 20 63 6f 6e 73 65 63 75 74 69 76 65 6c 79 2e s consecutively.
106e0 0a 2a 2a 0a 2a 2a 20 42 75 74 20 72 61 74 68 65 .**.** But rathe
106f0 72 20 74 68 61 6e 20 73 74 61 72 74 20 77 69 74 r than start wit
10700 68 20 30 20 6f 72 20 31 2c 20 77 65 20 62 65 67 h 0 or 1, we beg
10710 69 6e 20 77 69 74 68 20 27 41 27 2e 20 20 54 68 in with 'A'. Th
10720 61 74 20 77 61 79 2c 0a 2a 2a 20 77 68 65 6e 20 at way,.** when
10730 6d 75 6c 74 69 70 6c 65 20 61 66 66 69 6e 69 74 multiple affinit
10740 79 20 74 79 70 65 73 20 61 72 65 20 63 6f 6e 63 y types are conc
10750 61 74 65 6e 61 74 65 64 20 69 6e 74 6f 20 61 20 atenated into a
10760 73 74 72 69 6e 67 20 61 6e 64 0a 2a 2a 20 75 73 string and.** us
10770 65 64 20 61 73 20 74 68 65 20 50 34 20 6f 70 65 ed as the P4 ope
10780 72 61 6e 64 2c 20 74 68 65 79 20 77 69 6c 6c 20 rand, they will
10790 62 65 20 6d 6f 72 65 20 72 65 61 64 61 62 6c 65 be more readable
107a0 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 61 6c 73 ..**.** Note als
107b0 6f 20 74 68 61 74 20 74 68 65 20 6e 75 6d 65 72 o that the numer
107c0 69 63 20 74 79 70 65 73 20 61 72 65 20 67 72 6f ic types are gro
107d0 75 70 65 64 20 74 6f 67 65 74 68 65 72 20 73 6f uped together so
107e0 20 74 68 61 74 20 74 65 73 74 69 6e 67 0a 2a 2a that testing.**
107f0 20 66 6f 72 20 61 20 6e 75 6d 65 72 69 63 20 74 for a numeric t
10800 79 70 65 20 69 73 20 61 20 73 69 6e 67 6c 65 20 ype is a single
10810 63 6f 6d 70 61 72 69 73 6f 6e 2e 20 20 41 6e 64 comparison. And
10820 20 74 68 65 20 42 4c 4f 42 20 74 79 70 65 20 69 the BLOB type i
10830 73 20 66 69 72 73 74 2e 0a 2a 2f 0a 23 64 65 66 s first..*/.#def
10840 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 42 ine SQLITE_AFF_B
10850 4c 4f 42 20 20 20 20 20 27 41 27 0a 23 64 65 66 LOB 'A'.#def
10860 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 54 ine SQLITE_AFF_T
10870 45 58 54 20 20 20 20 20 27 42 27 0a 23 64 65 66 EXT 'B'.#def
10880 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4e ine SQLITE_AFF_N
10890 55 4d 45 52 49 43 20 20 27 43 27 0a 23 64 65 66 UMERIC 'C'.#def
108a0 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 ine SQLITE_AFF_I
108b0 4e 54 45 47 45 52 20 20 27 44 27 0a 23 64 65 66 NTEGER 'D'.#def
108c0 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 52 ine SQLITE_AFF_R
108d0 45 41 4c 20 20 20 20 20 27 45 27 0a 0a 23 64 65 EAL 'E'..#de
108e0 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 75 fine sqlite3IsNu
108f0 6d 65 72 69 63 41 66 66 69 6e 69 74 79 28 58 29 mericAffinity(X)
10900 20 20 28 28 58 29 3e 3d 53 51 4c 49 54 45 5f 41 ((X)>=SQLITE_A
10910 46 46 5f 4e 55 4d 45 52 49 43 29 0a 0a 2f 2a 0a FF_NUMERIC)../*.
10920 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 41 46 ** The SQLITE_AF
10930 46 5f 4d 41 53 4b 20 76 61 6c 75 65 73 20 6d 61 F_MASK values ma
10940 73 6b 73 20 6f 66 66 20 74 68 65 20 73 69 67 6e sks off the sign
10950 69 66 69 63 61 6e 74 20 62 69 74 73 20 6f 66 20 ificant bits of
10960 61 6e 0a 2a 2a 20 61 66 66 69 6e 69 74 79 20 76 an.** affinity v
10970 61 6c 75 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 alue..*/.#define
10980 20 53 51 4c 49 54 45 5f 41 46 46 5f 4d 41 53 4b SQLITE_AFF_MASK
10990 20 20 20 20 20 30 78 34 37 0a 0a 2f 2a 0a 2a 2a 0x47../*.**
109a0 20 41 64 64 69 74 69 6f 6e 61 6c 20 62 69 74 20 Additional bit
109b0 76 61 6c 75 65 73 20 74 68 61 74 20 63 61 6e 20 values that can
109c0 62 65 20 4f 52 65 64 20 77 69 74 68 20 61 6e 20 be ORed with an
109d0 61 66 66 69 6e 69 74 79 20 77 69 74 68 6f 75 74 affinity without
109e0 0a 2a 2a 20 63 68 61 6e 67 69 6e 67 20 74 68 65 .** changing the
109f0 20 61 66 66 69 6e 69 74 79 2e 0a 2a 2a 0a 2a 2a affinity..**.**
10a00 20 54 68 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e The SQLITE_NOTN
10a10 55 4c 4c 20 66 6c 61 67 20 69 73 20 61 20 63 6f ULL flag is a co
10a20 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 4e 55 4c mbination of NUL
10a30 4c 45 51 20 61 6e 64 20 4a 55 4d 50 49 46 4e 55 LEQ and JUMPIFNU
10a40 4c 4c 2e 0a 2a 2a 20 49 74 20 63 61 75 73 65 73 LL..** It causes
10a50 20 61 6e 20 61 73 73 65 72 74 28 29 20 74 6f 20 an assert() to
10a60 66 69 72 65 20 69 66 20 65 69 74 68 65 72 20 6f fire if either o
10a70 70 65 72 61 6e 64 20 74 6f 20 61 20 63 6f 6d 70 perand to a comp
10a80 61 72 69 73 6f 6e 0a 2a 2a 20 6f 70 65 72 61 74 arison.** operat
10a90 6f 72 20 69 73 20 4e 55 4c 4c 2e 20 20 49 74 20 or is NULL. It
10aa0 69 73 20 61 64 64 65 64 20 74 6f 20 63 65 72 74 is added to cert
10ab0 61 69 6e 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f ain comparison o
10ac0 70 65 72 61 74 6f 72 73 20 74 6f 0a 2a 2a 20 70 perators to.** p
10ad0 72 6f 76 65 20 74 68 61 74 20 74 68 65 20 6f 70 rove that the op
10ae0 65 72 61 6e 64 73 20 61 72 65 20 61 6c 77 61 79 erands are alway
10af0 73 20 4e 4f 54 20 4e 55 4c 4c 2e 0a 2a 2f 0a 23 s NOT NULL..*/.#
10b00 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4b 45 define SQLITE_KE
10b10 45 50 4e 55 4c 4c 20 20 20 20 20 30 78 30 38 20 EPNULL 0x08
10b20 20 2f 2a 20 55 73 65 64 20 62 79 20 76 65 63 74 /* Used by vect
10b30 6f 72 20 3d 3d 20 6f 72 20 3c 3e 20 2a 2f 0a 23 or == or <> */.#
10b40 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4a 55 define SQLITE_JU
10b50 4d 50 49 46 4e 55 4c 4c 20 20 20 30 78 31 30 20 MPIFNULL 0x10
10b60 20 2f 2a 20 6a 75 6d 70 73 20 69 66 20 65 69 74 /* jumps if eit
10b70 68 65 72 20 6f 70 65 72 61 6e 64 20 69 73 20 4e her operand is N
10b80 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ULL */.#define S
10b90 51 4c 49 54 45 5f 53 54 4f 52 45 50 32 20 20 20 QLITE_STOREP2
10ba0 20 20 20 30 78 32 30 20 20 2f 2a 20 53 74 6f 72 0x20 /* Stor
10bb0 65 20 72 65 73 75 6c 74 20 69 6e 20 72 65 67 5b e result in reg[
10bc0 50 32 5d 20 72 61 74 68 65 72 20 74 68 61 6e 20 P2] rather than
10bd0 6a 75 6d 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 jump */.#define
10be0 53 51 4c 49 54 45 5f 4e 55 4c 4c 45 51 20 20 20 SQLITE_NULLEQ
10bf0 20 20 20 20 30 78 38 30 20 20 2f 2a 20 4e 55 4c 0x80 /* NUL
10c00 4c 3d 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e L=NULL */.#defin
10c10 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e 55 4c 4c e SQLITE_NOTNULL
10c20 20 20 20 20 20 20 30 78 39 30 20 20 2f 2a 20 41 0x90 /* A
10c30 73 73 65 72 74 20 74 68 61 74 20 6f 70 65 72 61 ssert that opera
10c40 6e 64 73 20 61 72 65 20 6e 65 76 65 72 20 4e 55 nds are never NU
10c50 4c 4c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 LL */../*.** An
10c60 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 73 20 74 object of this t
10c70 79 70 65 20 69 73 20 63 72 65 61 74 65 64 20 66 ype is created f
10c80 6f 72 20 65 61 63 68 20 76 69 72 74 75 61 6c 20 or each virtual
10c90 74 61 62 6c 65 20 70 72 65 73 65 6e 74 20 69 6e table present in
10ca0 0a 2a 2a 20 74 68 65 20 64 61 74 61 62 61 73 65 .** the database
10cb0 20 73 63 68 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 49 schema..**.** I
10cc0 66 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 f the database s
10cd0 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c chema is shared,
10ce0 20 74 68 65 6e 20 74 68 65 72 65 20 69 73 20 6f then there is o
10cf0 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 ne instance of t
10d00 68 69 73 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 his.** structure
10d10 20 66 6f 72 20 65 61 63 68 20 64 61 74 61 62 61 for each databa
10d20 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 28 73 se connection (s
10d30 71 6c 69 74 65 33 2a 29 20 74 68 61 74 20 75 73 qlite3*) that us
10d40 65 73 20 74 68 65 20 73 68 61 72 65 64 0a 2a 2a es the shared.**
10d50 20 73 63 68 65 6d 61 2e 20 54 68 69 73 20 69 73 schema. This is
10d60 20 62 65 63 61 75 73 65 20 65 61 63 68 20 64 61 because each da
10d70 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
10d80 6e 20 72 65 71 75 69 72 65 73 20 69 74 73 20 6f n requires its o
10d90 77 6e 20 75 6e 69 71 75 65 0a 2a 2a 20 69 6e 73 wn unique.** ins
10da0 74 61 6e 63 65 20 6f 66 20 74 68 65 20 73 71 6c tance of the sql
10db0 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c ite3_vtab* handl
10dc0 65 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 e used to access
10dd0 20 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 the virtual tab
10de0 6c 65 0a 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 le.** implementa
10df0 74 69 6f 6e 2e 20 73 71 6c 69 74 65 33 5f 76 74 tion. sqlite3_vt
10e00 61 62 2a 20 68 61 6e 64 6c 65 73 20 63 61 6e 20 ab* handles can
10e10 6e 6f 74 20 62 65 20 73 68 61 72 65 64 20 62 65 not be shared be
10e20 74 77 65 65 6e 0a 2a 2a 20 64 61 74 61 62 61 73 tween.** databas
10e30 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 2c 20 65 e connections, e
10e40 76 65 6e 20 77 68 65 6e 20 74 68 65 20 72 65 73 ven when the res
10e50 74 20 6f 66 20 74 68 65 20 69 6e 2d 6d 65 6d 6f t of the in-memo
10e60 72 79 20 64 61 74 61 62 61 73 65 0a 2a 2a 20 73 ry database.** s
10e70 63 68 65 6d 61 20 69 73 20 73 68 61 72 65 64 2c chema is shared,
10e80 20 61 73 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e as the implemen
10e90 74 61 74 69 6f 6e 20 6f 66 74 65 6e 20 73 74 6f tation often sto
10ea0 72 65 73 20 74 68 65 20 64 61 74 61 62 61 73 65 res the database
10eb0 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 .** connection h
10ec0 61 6e 64 6c 65 20 70 61 73 73 65 64 20 74 6f 20 andle passed to
10ed0 69 74 20 76 69 61 20 74 68 65 20 78 43 6f 6e 6e it via the xConn
10ee0 65 63 74 28 29 20 6f 72 20 78 43 72 65 61 74 65 ect() or xCreate
10ef0 28 29 20 6d 65 74 68 6f 64 0a 2a 2a 20 64 75 72 () method.** dur
10f00 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ing initializati
10f10 6f 6e 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 20 54 on internally. T
10f20 68 69 73 20 64 61 74 61 62 61 73 65 20 63 6f 6e his database con
10f30 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 6d nection handle m
10f40 61 79 0a 2a 2a 20 74 68 65 6e 20 62 65 20 75 73 ay.** then be us
10f50 65 64 20 62 79 20 74 68 65 20 76 69 72 74 75 61 ed by the virtua
10f60 6c 20 74 61 62 6c 65 20 69 6d 70 6c 65 6d 65 6e l table implemen
10f70 74 61 74 69 6f 6e 20 74 6f 20 61 63 63 65 73 73 tation to access
10f80 20 72 65 61 6c 20 74 61 62 6c 65 73 0a 2a 2a 20 real tables.**
10f90 77 69 74 68 69 6e 20 74 68 65 20 64 61 74 61 62 within the datab
10fa0 61 73 65 2e 20 53 6f 20 74 68 61 74 20 74 68 65 ase. So that the
10fb0 79 20 61 70 70 65 61 72 20 61 73 20 70 61 72 74 y appear as part
10fc0 20 6f 66 20 74 68 65 20 63 61 6c 6c 65 72 73 0a of the callers.
10fd0 2a 2a 20 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 ** transaction,
10fe0 74 68 65 73 65 20 61 63 63 65 73 73 65 73 20 6e these accesses n
10ff0 65 65 64 20 74 6f 20 62 65 20 6d 61 64 65 20 76 eed to be made v
11000 69 61 20 74 68 65 20 73 61 6d 65 20 64 61 74 61 ia the same data
11010 62 61 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 base.** connecti
11020 6f 6e 20 61 73 20 74 68 61 74 20 75 73 65 64 20 on as that used
11030 74 6f 20 65 78 65 63 75 74 65 20 53 51 4c 20 6f to execute SQL o
11040 70 65 72 61 74 69 6f 6e 73 20 6f 6e 20 74 68 65 perations on the
11050 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 0a virtual table..
11060 2a 2a 0a 2a 2a 20 41 6c 6c 20 56 54 61 62 6c 65 **.** All VTable
11070 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 63 6f objects that co
11080 72 72 65 73 70 6f 6e 64 20 74 6f 20 61 20 73 69 rrespond to a si
11090 6e 67 6c 65 20 74 61 62 6c 65 20 69 6e 20 61 20 ngle table in a
110a0 73 68 61 72 65 64 0a 2a 2a 20 64 61 74 61 62 61 shared.** databa
110b0 73 65 20 73 63 68 65 6d 61 20 61 72 65 20 69 6e se schema are in
110c0 69 74 69 61 6c 6c 79 20 73 74 6f 72 65 64 20 69 itially stored i
110d0 6e 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 n a linked-list
110e0 70 6f 69 6e 74 65 64 20 74 6f 20 62 79 0a 2a 2a pointed to by.**
110f0 20 74 68 65 20 54 61 62 6c 65 2e 70 56 54 61 62 the Table.pVTab
11100 6c 65 20 6d 65 6d 62 65 72 20 76 61 72 69 61 62 le member variab
11110 6c 65 20 6f 66 20 74 68 65 20 63 6f 72 72 65 73 le of the corres
11120 70 6f 6e 64 69 6e 67 20 54 61 62 6c 65 20 6f 62 ponding Table ob
11130 6a 65 63 74 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e ject..** When an
11140 20 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 sqlite3_prepare
11150 28 29 20 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 () operation is
11160 72 65 71 75 69 72 65 64 20 74 6f 20 61 63 63 65 required to acce
11170 73 73 20 74 68 65 20 76 69 72 74 75 61 6c 0a 2a ss the virtual.*
11180 2a 20 74 61 62 6c 65 2c 20 69 74 20 73 65 61 72 * table, it sear
11190 63 68 65 73 20 74 68 65 20 6c 69 73 74 20 66 6f ches the list fo
111a0 72 20 74 68 65 20 56 54 61 62 6c 65 20 74 68 61 r the VTable tha
111b0 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f t corresponds to
111c0 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 the.** database
111d0 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 6f 69 6e connection doin
111e0 67 20 74 68 65 20 70 72 65 70 61 72 69 6e 67 20 g the preparing
111f0 73 6f 20 61 73 20 74 6f 20 75 73 65 20 74 68 65 so as to use the
11200 20 63 6f 72 72 65 63 74 0a 2a 2a 20 73 71 6c 69 correct.** sqli
11210 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 te3_vtab* handle
11220 20 69 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 64 in the compiled
11230 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 query..**.** Wh
11240 65 6e 20 61 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 en an in-memory
11250 54 61 62 6c 65 20 6f 62 6a 65 63 74 20 69 73 20 Table object is
11260 64 65 6c 65 74 65 64 20 28 66 6f 72 20 65 78 61 deleted (for exa
11270 6d 70 6c 65 20 77 68 65 6e 20 74 68 65 0a 2a 2a mple when the.**
11280 20 73 63 68 65 6d 61 20 69 73 20 62 65 69 6e 67 schema is being
11290 20 72 65 6c 6f 61 64 65 64 20 66 6f 72 20 73 6f reloaded for so
112a0 6d 65 20 72 65 61 73 6f 6e 29 2c 20 74 68 65 20 me reason), the
112b0 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 61 VTable objects a
112c0 72 65 20 6e 6f 74 0a 2a 2a 20 64 65 6c 65 74 65 re not.** delete
112d0 64 20 61 6e 64 20 74 68 65 20 73 71 6c 69 74 65 d and the sqlite
112e0 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 3_vtab* handles
112f0 61 72 65 20 6e 6f 74 20 78 44 69 73 63 6f 6e 6e are not xDisconn
11300 65 63 74 28 29 65 64 0a 2a 2a 20 69 6d 6d 65 64 ect()ed.** immed
11310 69 61 74 65 6c 79 2e 20 49 6e 73 74 65 61 64 2c iately. Instead,
11320 20 74 68 65 79 20 61 72 65 20 6d 6f 76 65 64 20 they are moved
11330 66 72 6f 6d 20 74 68 65 20 54 61 62 6c 65 2e 70 from the Table.p
11340 56 54 61 62 6c 65 20 6c 69 73 74 20 74 6f 0a 2a VTable list to.*
11350 2a 20 61 6e 6f 74 68 65 72 20 6c 69 6e 6b 65 64 * another linked
11360 20 6c 69 73 74 20 68 65 61 64 65 64 20 62 79 20 list headed by
11370 74 68 65 20 73 71 6c 69 74 65 33 2e 70 44 69 73 the sqlite3.pDis
11380 63 6f 6e 6e 65 63 74 20 6d 65 6d 62 65 72 20 6f connect member o
11390 66 20 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 f the.** corresp
113a0 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 20 73 onding sqlite3 s
113b0 74 72 75 63 74 75 72 65 2e 20 54 68 65 79 20 61 tructure. They a
113c0 72 65 20 74 68 65 6e 20 64 65 6c 65 74 65 64 2f re then deleted/
113d0 78 44 69 73 63 6f 6e 6e 65 63 74 65 64 0a 2a 2a xDisconnected.**
113e0 20 6e 65 78 74 20 74 69 6d 65 20 61 20 73 74 61 next time a sta
113f0 74 65 6d 65 6e 74 20 69 73 20 70 72 65 70 61 72 tement is prepar
11400 65 64 20 75 73 69 6e 67 20 73 61 69 64 20 73 71 ed using said sq
11410 6c 69 74 65 33 2a 2e 20 54 68 69 73 20 69 73 20 lite3*. This is
11420 64 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 6f 69 64 done.** to avoid
11430 20 64 65 61 64 6c 6f 63 6b 20 69 73 73 75 65 73 deadlock issues
11440 20 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 6c 74 69 involving multi
11450 70 6c 65 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 ple sqlite3.mute
11460 78 20 6d 75 74 65 78 65 73 2e 0a 2a 2a 20 52 65 x mutexes..** Re
11470 66 65 72 20 74 6f 20 63 6f 6d 6d 65 6e 74 73 20 fer to comments
11480 61 62 6f 76 65 20 66 75 6e 63 74 69 6f 6e 20 73 above function s
11490 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b qlite3VtabUnlock
114a0 4c 69 73 74 28 29 20 66 6f 72 20 61 6e 0a 2a 2a List() for an.**
114b0 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 61 73 20 explanation as
114c0 74 6f 20 77 68 79 20 69 74 20 69 73 20 73 61 66 to why it is saf
114d0 65 20 74 6f 20 61 64 64 20 61 6e 20 65 6e 74 72 e to add an entr
114e0 79 20 74 6f 20 61 6e 20 73 71 6c 69 74 65 33 2e y to an sqlite3.
114f0 70 44 69 73 63 6f 6e 6e 65 63 74 0a 2a 2a 20 6c pDisconnect.** l
11500 69 73 74 20 77 69 74 68 6f 75 74 20 68 6f 6c 64 ist without hold
11510 69 6e 67 20 74 68 65 20 63 6f 72 72 65 73 70 6f ing the correspo
11520 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 2e 6d 75 nding sqlite3.mu
11530 74 65 78 20 6d 75 74 65 78 2e 0a 2a 2a 0a 2a 2a tex mutex..**.**
11540 20 54 68 65 20 6d 65 6d 6f 72 79 20 66 6f 72 20 The memory for
11550 6f 62 6a 65 63 74 73 20 6f 66 20 74 68 69 73 20 objects of this
11560 74 79 70 65 20 69 73 20 61 6c 77 61 79 73 20 61 type is always a
11570 6c 6c 6f 63 61 74 65 64 20 62 79 0a 2a 2a 20 73 llocated by.** s
11580 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 28 29 qlite3DbMalloc()
11590 2c 20 75 73 69 6e 67 20 74 68 65 20 63 6f 6e 6e , using the conn
115a0 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 73 74 ection handle st
115b0 6f 72 65 64 20 69 6e 20 56 54 61 62 6c 65 2e 64 ored in VTable.d
115c0 62 20 61 73 0a 2a 2a 20 74 68 65 20 66 69 72 73 b as.** the firs
115d0 74 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f 0a 73 t argument..*/.s
115e0 74 72 75 63 74 20 56 54 61 62 6c 65 20 7b 0a 20 truct VTable {.
115f0 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 sqlite3 *db;
11600 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 61 /* Da
11610 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f tabase connectio
11620 6e 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 n associated wit
11630 68 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a h this table */.
11640 20 20 4d 6f 64 75 6c 65 20 2a 70 4d 6f 64 3b 20 Module *pMod;
11650 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
11660 6f 69 6e 74 65 72 20 74 6f 20 6d 6f 64 75 6c 65 ointer to module
11670 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
11680 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 76 74 61 */. sqlite3_vta
11690 62 20 2a 70 56 74 61 62 3b 20 20 20 20 20 20 2f b *pVtab; /
116a0 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 76 74 61 * Pointer to vta
116b0 62 20 69 6e 73 74 61 6e 63 65 20 2a 2f 0a 20 20 b instance */.
116c0 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 20 20 int nRef;
116d0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
116e0 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 ber of pointers
116f0 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 72 to this structur
11700 65 20 2a 2f 0a 20 20 75 38 20 62 43 6f 6e 73 74 e */. u8 bConst
11710 72 61 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 raint;
11720 20 2f 2a 20 54 72 75 65 20 69 66 20 63 6f 6e 73 /* True if cons
11730 74 72 61 69 6e 74 73 20 61 72 65 20 73 75 70 70 traints are supp
11740 6f 72 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 orted */. int i
11750 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 Savepoint;
11760 20 20 20 20 20 2f 2a 20 44 65 70 74 68 20 6f 66 /* Depth of
11770 20 74 68 65 20 53 41 56 45 50 4f 49 4e 54 20 73 the SAVEPOINT s
11780 74 61 63 6b 20 2a 2f 0a 20 20 56 54 61 62 6c 65 tack */. VTable
11790 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 *pNext;
117a0 20 20 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 6c /* Next in l
117b0 69 6e 6b 65 64 20 6c 69 73 74 20 28 73 65 65 20 inked list (see
117c0 61 62 6f 76 65 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a above) */.};../*
117d0 0a 2a 2a 20 54 68 65 20 73 63 68 65 6d 61 20 66 .** The schema f
117e0 6f 72 20 65 61 63 68 20 53 51 4c 20 74 61 62 6c or each SQL tabl
117f0 65 20 61 6e 64 20 76 69 65 77 20 69 73 20 72 65 e and view is re
11800 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 6d presented in mem
11810 6f 72 79 0a 2a 2a 20 62 79 20 61 6e 20 69 6e 73 ory.** by an ins
11820 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
11830 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
11840 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 61 62 6c ..*/.struct Tabl
11850 65 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d e {. char *zNam
11860 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 e; /* Na
11870 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 me of the table
11880 6f 72 20 76 69 65 77 20 2a 2f 0a 20 20 43 6f 6c or view */. Col
11890 75 6d 6e 20 2a 61 43 6f 6c 3b 20 20 20 20 20 20 umn *aCol;
118a0 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e /* Information
118b0 20 61 62 6f 75 74 20 65 61 63 68 20 63 6f 6c 75 about each colu
118c0 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 mn */. Index *p
118d0 49 6e 64 65 78 3b 20 20 20 20 20 20 20 2f 2a 20 Index; /*
118e0 4c 69 73 74 20 6f 66 20 53 51 4c 20 69 6e 64 65 List of SQL inde
118f0 78 65 73 20 6f 6e 20 74 68 69 73 20 74 61 62 6c xes on this tabl
11900 65 2e 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a e. */. Select *
11910 70 53 65 6c 65 63 74 3b 20 20 20 20 20 2f 2a 20 pSelect; /*
11920 4e 55 4c 4c 20 66 6f 72 20 74 61 62 6c 65 73 2e NULL for tables.
11930 20 20 50 6f 69 6e 74 73 20 74 6f 20 64 65 66 69 Points to defi
11940 6e 69 74 69 6f 6e 20 69 66 20 61 20 76 69 65 77 nition if a view
11950 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 46 4b . */. FKey *pFK
11960 65 79 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4c ey; /* L
11970 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 20 61 6c inked list of al
11980 6c 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 69 l foreign keys i
11990 6e 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a n this table */.
119a0 20 20 63 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b char *zColAff;
119b0 20 20 20 20 20 20 20 2f 2a 20 53 74 72 69 6e 67 /* String
119c0 20 64 65 66 69 6e 69 6e 67 20 74 68 65 20 61 66 defining the af
119d0 66 69 6e 69 74 79 20 6f 66 20 65 61 63 68 20 63 finity of each c
119e0 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 78 70 72 4c olumn */. ExprL
119f0 69 73 74 20 2a 70 43 68 65 63 6b 3b 20 20 20 20 ist *pCheck;
11a00 2f 2a 20 41 6c 6c 20 43 48 45 43 4b 20 63 6f 6e /* All CHECK con
11a10 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 straints */.
11a20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
11a30 20 20 20 2f 2a 20 20 20 2e 2e 2e 20 61 6c 73 6f /* ... also
11a40 20 75 73 65 64 20 61 73 20 63 6f 6c 75 6d 6e 20 used as column
11a50 6e 61 6d 65 20 6c 69 73 74 20 69 6e 20 61 20 56 name list in a V
11a60 49 45 57 20 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 IEW */. int tnu
11a70 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
11a80 20 52 6f 6f 74 20 42 54 72 65 65 20 70 61 67 65 Root BTree page
11a90 20 66 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 for this table
11aa0 2a 2f 0a 20 20 75 33 32 20 6e 54 61 62 52 65 66 */. u32 nTabRef
11ab0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d ; /* Num
11ac0 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 ber of pointers
11ad0 74 6f 20 74 68 69 73 20 54 61 62 6c 65 20 2a 2f to this Table */
11ae0 0a 20 20 69 31 36 20 69 50 4b 65 79 3b 20 20 20 . i16 iPKey;
11af0 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f /* If no
11b00 74 20 6e 65 67 61 74 69 76 65 2c 20 75 73 65 20 t negative, use
11b10 61 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 73 20 74 aCol[iPKey] as t
11b20 68 65 20 72 6f 77 69 64 20 2a 2f 0a 20 20 69 31 he rowid */. i1
11b30 36 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 6 nCol;
11b40 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
11b50 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 columns in this
11b60 74 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 table */. LogEs
11b70 74 20 6e 52 6f 77 4c 6f 67 45 73 74 3b 20 20 20 t nRowLogEst;
11b80 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 72 6f 77 /* Estimated row
11b90 73 20 69 6e 20 74 61 62 6c 65 20 2d 20 66 72 6f s in table - fro
11ba0 6d 20 73 71 6c 69 74 65 5f 73 74 61 74 31 20 74 m sqlite_stat1 t
11bb0 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 able */. LogEst
11bc0 20 73 7a 54 61 62 52 6f 77 3b 20 20 20 20 20 2f szTabRow; /
11bd0 2a 20 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 * Estimated size
11be0 20 6f 66 20 65 61 63 68 20 74 61 62 6c 65 20 72 of each table r
11bf0 6f 77 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 23 ow in bytes */.#
11c00 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
11c10 42 4c 45 5f 43 4f 53 54 4d 55 4c 54 0a 20 20 4c BLE_COSTMULT. L
11c20 6f 67 45 73 74 20 63 6f 73 74 4d 75 6c 74 3b 20 ogEst costMult;
11c30 20 20 20 20 2f 2a 20 43 6f 73 74 20 6d 75 6c 74 /* Cost mult
11c40 69 70 6c 69 65 72 20 66 6f 72 20 75 73 69 6e 67 iplier for using
11c50 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 23 this table */.#
11c60 65 6e 64 69 66 0a 20 20 75 38 20 74 61 62 46 6c endif. u8 tabFl
11c70 61 67 73 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ags; /*
11c80 4d 61 73 6b 20 6f 66 20 54 46 5f 2a 20 76 61 6c Mask of TF_* val
11c90 75 65 73 20 2a 2f 0a 20 20 75 38 20 6b 65 79 43 ues */. u8 keyC
11ca0 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 20 2f 2a onf; /*
11cb0 20 57 68 61 74 20 74 6f 20 64 6f 20 69 6e 20 63 What to do in c
11cc0 61 73 65 20 6f 66 20 75 6e 69 71 75 65 6e 65 73 ase of uniquenes
11cd0 73 20 63 6f 6e 66 6c 69 63 74 20 6f 6e 20 69 50 s conflict on iP
11ce0 4b 65 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 Key */.#ifndef S
11cf0 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 4c 54 45 52 QLITE_OMIT_ALTER
11d00 54 41 42 4c 45 0a 20 20 69 6e 74 20 61 64 64 43 TABLE. int addC
11d10 6f 6c 4f 66 66 73 65 74 3b 20 20 20 20 2f 2a 20 olOffset; /*
11d20 4f 66 66 73 65 74 20 69 6e 20 43 52 45 41 54 45 Offset in CREATE
11d30 20 54 41 42 4c 45 20 73 74 6d 74 20 74 6f 20 61 TABLE stmt to a
11d40 64 64 20 61 20 6e 65 77 20 63 6f 6c 75 6d 6e 20 dd a new column
11d50 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 */.#endif.#ifnde
11d60 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 f SQLITE_OMIT_VI
11d70 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 69 6e 74 RTUALTABLE. int
11d80 20 6e 4d 6f 64 75 6c 65 41 72 67 3b 20 20 20 20 nModuleArg;
11d90 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 /* Number of a
11da0 72 67 75 6d 65 6e 74 73 20 74 6f 20 74 68 65 20 rguments to the
11db0 6d 6f 64 75 6c 65 20 2a 2f 0a 20 20 63 68 61 72 module */. char
11dc0 20 2a 2a 61 7a 4d 6f 64 75 6c 65 41 72 67 3b 20 **azModuleArg;
11dd0 20 2f 2a 20 30 3a 20 6d 6f 64 75 6c 65 20 31 3a /* 0: module 1:
11de0 20 73 63 68 65 6d 61 20 32 3a 20 76 74 61 62 20 schema 2: vtab
11df0 6e 61 6d 65 20 33 2e 2e 2e 3a 20 61 72 67 73 20 name 3...: args
11e00 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 56 54 */. VTable *pVT
11e10 61 62 6c 65 3b 20 20 20 20 20 2f 2a 20 4c 69 73 able; /* Lis
11e20 74 20 6f 66 20 56 54 61 62 6c 65 20 6f 62 6a 65 t of VTable obje
11e30 63 74 73 2e 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 cts. */.#endif.
11e40 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 Trigger *pTrigg
11e50 65 72 3b 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 er; /* List of
11e60 20 74 72 69 67 67 65 72 73 20 73 74 6f 72 65 64 triggers stored
11e70 20 69 6e 20 70 53 63 68 65 6d 61 20 2a 2f 0a 20 in pSchema */.
11e80 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 Schema *pSchema
11e90 3b 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 ; /* Schema
11ea0 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 that contains th
11eb0 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 54 61 is table */. Ta
11ec0 62 6c 65 20 2a 70 4e 65 78 74 5a 6f 6d 62 69 65 ble *pNextZombie
11ed0 3b 20 20 2f 2a 20 4e 65 78 74 20 6f 6e 20 74 68 ; /* Next on th
11ee0 65 20 50 61 72 73 65 2e 70 5a 6f 6d 62 69 65 54 e Parse.pZombieT
11ef0 61 62 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f ab list */.};../
11f00 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c *.** Allowed val
11f10 75 65 73 20 66 6f 72 20 54 61 62 6c 65 2e 74 61 ues for Table.ta
11f20 62 46 6c 61 67 73 2e 0a 2a 2a 0a 2a 2a 20 54 46 bFlags..**.** TF
11f30 5f 4f 4f 4f 48 69 64 64 65 6e 20 61 70 70 6c 69 _OOOHidden appli
11f40 65 73 20 74 6f 20 74 61 62 6c 65 73 20 6f 72 20 es to tables or
11f50 76 69 65 77 20 74 68 61 74 20 68 61 76 65 20 68 view that have h
11f60 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 74 68 idden columns th
11f70 61 74 20 61 72 65 0a 2a 2a 20 66 6f 6c 6c 6f 77 at are.** follow
11f80 65 64 20 62 79 20 6e 6f 6e 2d 68 69 64 64 65 6e ed by non-hidden
11f90 20 63 6f 6c 75 6d 6e 73 2e 20 20 45 78 61 6d 70 columns. Examp
11fa0 6c 65 3a 20 20 22 43 52 45 41 54 45 20 56 49 52 le: "CREATE VIR
11fb0 54 55 41 4c 20 54 41 42 4c 45 20 78 20 55 53 49 TUAL TABLE x USI
11fc0 4e 47 0a 2a 2a 20 76 74 61 62 31 28 61 20 48 49 NG.** vtab1(a HI
11fd0 44 44 45 4e 2c 20 62 29 3b 22 2e 20 20 53 69 6e DDEN, b);". Sin
11fe0 63 65 20 22 62 22 20 69 73 20 61 20 6e 6f 6e 2d ce "b" is a non-
11ff0 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 20 62 75 hidden column bu
12000 74 20 22 61 22 20 69 73 20 68 69 64 64 65 6e 2c t "a" is hidden,
12010 0a 2a 2a 20 74 68 65 20 54 46 5f 4f 4f 4f 48 69 .** the TF_OOOHi
12020 64 64 65 6e 20 61 74 74 72 69 62 75 74 65 20 77 dden attribute w
12030 6f 75 6c 64 20 61 70 70 6c 79 20 69 6e 20 74 68 ould apply in th
12040 69 73 20 63 61 73 65 2e 20 20 53 75 63 68 20 74 is case. Such t
12050 61 62 6c 65 73 20 72 65 71 75 69 72 65 0a 2a 2a ables require.**
12060 20 73 70 65 63 69 61 6c 20 68 61 6e 64 6c 69 6e special handlin
12070 67 20 64 75 72 69 6e 67 20 49 4e 53 45 52 54 20 g during INSERT
12080 70 72 6f 63 65 73 73 69 6e 67 2e 0a 2a 2f 0a 23 processing..*/.#
12090 64 65 66 69 6e 65 20 54 46 5f 52 65 61 64 6f 6e define TF_Readon
120a0 6c 79 20 20 20 20 20 20 20 20 30 78 30 31 20 20 ly 0x01
120b0 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 79 20 73 /* Read-only s
120c0 79 73 74 65 6d 20 74 61 62 6c 65 20 2a 2f 0a 23 ystem table */.#
120d0 64 65 66 69 6e 65 20 54 46 5f 45 70 68 65 6d 65 define TF_Epheme
120e0 72 61 6c 20 20 20 20 20 20 20 30 78 30 32 20 20 ral 0x02
120f0 20 20 2f 2a 20 41 6e 20 65 70 68 65 6d 65 72 61 /* An ephemera
12100 6c 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 l table */.#defi
12110 6e 65 20 54 46 5f 48 61 73 50 72 69 6d 61 72 79 ne TF_HasPrimary
12120 4b 65 79 20 20 20 30 78 30 34 20 20 20 20 2f 2a Key 0x04 /*
12130 20 54 61 62 6c 65 20 68 61 73 20 61 20 70 72 69 Table has a pri
12140 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 65 66 mary key */.#def
12150 69 6e 65 20 54 46 5f 41 75 74 6f 69 6e 63 72 65 ine TF_Autoincre
12160 6d 65 6e 74 20 20 20 30 78 30 38 20 20 20 20 2f ment 0x08 /
12170 2a 20 49 6e 74 65 67 65 72 20 70 72 69 6d 61 72 * Integer primar
12180 79 20 6b 65 79 20 69 73 20 61 75 74 6f 69 6e 63 y key is autoinc
12190 72 65 6d 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e rement */.#defin
121a0 65 20 54 46 5f 56 69 72 74 75 61 6c 20 20 20 20 e TF_Virtual
121b0 20 20 20 20 20 30 78 31 30 20 20 20 20 2f 2a 20 0x10 /*
121c0 49 73 20 61 20 76 69 72 74 75 61 6c 20 74 61 62 Is a virtual tab
121d0 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 le */.#define TF
121e0 5f 57 69 74 68 6f 75 74 52 6f 77 69 64 20 20 20 _WithoutRowid
121f0 20 30 78 32 30 20 20 20 20 2f 2a 20 4e 6f 20 72 0x20 /* No r
12200 6f 77 69 64 2e 20 20 50 52 49 4d 41 52 59 20 4b owid. PRIMARY K
12210 45 59 20 69 73 20 74 68 65 20 6b 65 79 20 2a 2f EY is the key */
12220 0a 23 64 65 66 69 6e 65 20 54 46 5f 4e 6f 56 69 .#define TF_NoVi
12230 73 69 62 6c 65 52 6f 77 69 64 20 20 30 78 34 30 sibleRowid 0x40
12240 20 20 20 20 2f 2a 20 4e 6f 20 75 73 65 72 2d 76 /* No user-v
12250 69 73 69 62 6c 65 20 22 72 6f 77 69 64 22 20 63 isible "rowid" c
12260 6f 6c 75 6d 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 olumn */.#define
12270 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 20 20 TF_OOOHidden
12280 20 20 20 20 30 78 38 30 20 20 20 20 2f 2a 20 4f 0x80 /* O
12290 75 74 2d 6f 66 2d 4f 72 64 65 72 20 68 69 64 64 ut-of-Order hidd
122a0 65 6e 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 0a 0a en columns */...
122b0 2f 2a 0a 2a 2a 20 54 65 73 74 20 74 6f 20 73 65 /*.** Test to se
122c0 65 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 e whether or not
122d0 20 61 20 74 61 62 6c 65 20 69 73 20 61 20 76 69 a table is a vi
122e0 72 74 75 61 6c 20 74 61 62 6c 65 2e 20 20 54 68 rtual table. Th
122f0 69 73 20 69 73 0a 2a 2a 20 64 6f 6e 65 20 61 73 is is.** done as
12300 20 61 20 6d 61 63 72 6f 20 73 6f 20 74 68 61 74 a macro so that
12310 20 69 74 20 77 69 6c 6c 20 62 65 20 6f 70 74 69 it will be opti
12320 6d 69 7a 65 64 20 6f 75 74 20 77 68 65 6e 20 76 mized out when v
12330 69 72 74 75 61 6c 0a 2a 2a 20 74 61 62 6c 65 20 irtual.** table
12340 73 75 70 70 6f 72 74 20 69 73 20 6f 6d 69 74 74 support is omitt
12350 65 64 20 66 72 6f 6d 20 74 68 65 20 62 75 69 6c ed from the buil
12360 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 d..*/.#ifndef SQ
12370 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
12380 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 69 6e 65 LTABLE.# define
12390 20 49 73 56 69 72 74 75 61 6c 28 58 29 20 20 20 IsVirtual(X)
123a0 20 20 20 28 28 28 58 29 2d 3e 74 61 62 46 6c 61 (((X)->tabFla
123b0 67 73 20 26 20 54 46 5f 56 69 72 74 75 61 6c 29 gs & TF_Virtual)
123c0 21 3d 30 29 0a 23 65 6c 73 65 0a 23 20 20 64 65 !=0).#else.# de
123d0 66 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 58 fine IsVirtual(X
123e0 29 20 20 20 20 20 20 30 0a 23 65 6e 64 69 66 0a ) 0.#endif.
123f0 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f ./*.** Macros to
12400 20 64 65 74 65 72 6d 69 6e 65 20 69 66 20 61 20 determine if a
12410 63 6f 6c 75 6d 6e 20 69 73 20 68 69 64 64 65 6e column is hidden
12420 2e 20 20 49 73 4f 72 64 69 6e 61 72 79 48 69 64 . IsOrdinaryHid
12430 64 65 6e 43 6f 6c 75 6d 6e 28 29 0a 2a 2a 20 6f denColumn().** o
12440 6e 6c 79 20 77 6f 72 6b 73 20 66 6f 72 20 6e 6f nly works for no
12450 6e 2d 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 n-virtual tables
12460 20 28 6f 72 64 69 6e 61 72 79 20 74 61 62 6c 65 (ordinary table
12470 73 20 61 6e 64 20 76 69 65 77 73 29 20 61 6e 64 s and views) and
12480 20 69 73 0a 2a 2a 20 61 6c 77 61 79 73 20 66 61 is.** always fa
12490 6c 73 65 20 75 6e 6c 65 73 73 20 53 51 4c 49 54 lse unless SQLIT
124a0 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 45 4e 5f E_ENABLE_HIDDEN_
124b0 43 4f 4c 55 4d 4e 53 20 69 73 20 64 65 66 69 6e COLUMNS is defin
124c0 65 64 2e 20 20 54 68 65 0a 2a 2a 20 49 73 48 69 ed. The.** IsHi
124d0 64 64 65 6e 43 6f 6c 75 6d 6e 28 29 20 6d 61 63 ddenColumn() mac
124e0 72 6f 20 69 73 20 67 65 6e 65 72 61 6c 20 70 75 ro is general pu
124f0 72 70 6f 73 65 2e 0a 2a 2f 0a 23 69 66 20 64 65 rpose..*/.#if de
12500 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
12510 42 4c 45 5f 48 49 44 44 45 4e 5f 43 4f 4c 55 4d BLE_HIDDEN_COLUM
12520 4e 53 29 0a 23 20 20 64 65 66 69 6e 65 20 49 73 NS).# define Is
12530 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 HiddenColumn(X)
12540 20 20 20 20 20 20 20 20 28 28 28 58 29 2d 3e 63 (((X)->c
12550 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 olFlags & COLFLA
12560 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 20 G_HIDDEN)!=0).#
12570 20 64 65 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 define IsOrdina
12580 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 ryHiddenColumn(X
12590 29 20 28 28 28 58 29 2d 3e 63 6f 6c 46 6c 61 67 ) (((X)->colFlag
125a0 73 20 26 20 43 4f 4c 46 4c 41 47 5f 48 49 44 44 s & COLFLAG_HIDD
125b0 45 4e 29 21 3d 30 29 0a 23 65 6c 69 66 20 21 64 EN)!=0).#elif !d
125c0 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d efined(SQLITE_OM
125d0 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 IT_VIRTUALTABLE)
125e0 0a 23 20 20 64 65 66 69 6e 65 20 49 73 48 69 64 .# define IsHid
125f0 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 20 20 20 denColumn(X)
12600 20 20 20 20 20 28 28 28 58 29 2d 3e 63 6f 6c 46 (((X)->colF
12610 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f 48 lags & COLFLAG_H
12620 49 44 44 45 4e 29 21 3d 30 29 0a 23 20 20 64 65 IDDEN)!=0).# de
12630 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 72 79 48 fine IsOrdinaryH
12640 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 30 iddenColumn(X) 0
12650 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 .#else.# define
12660 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 IsHiddenColumn(
12670 58 29 20 20 20 20 20 20 20 20 20 30 0a 23 20 20 X) 0.#
12680 64 65 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 72 define IsOrdinar
12690 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 yHiddenColumn(X)
126a0 20 30 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 20 44 0.#endif.../* D
126b0 6f 65 73 20 74 68 65 20 74 61 62 6c 65 20 68 61 oes the table ha
126c0 76 65 20 61 20 72 6f 77 69 64 20 2a 2f 0a 23 64 ve a rowid */.#d
126d0 65 66 69 6e 65 20 48 61 73 52 6f 77 69 64 28 58 efine HasRowid(X
126e0 29 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 62 ) (((X)->tab
126f0 46 6c 61 67 73 20 26 20 54 46 5f 57 69 74 68 6f Flags & TF_Witho
12700 75 74 52 6f 77 69 64 29 3d 3d 30 29 0a 23 64 65 utRowid)==0).#de
12710 66 69 6e 65 20 56 69 73 69 62 6c 65 52 6f 77 69 fine VisibleRowi
12720 64 28 58 29 20 28 28 28 58 29 2d 3e 74 61 62 46 d(X) (((X)->tabF
12730 6c 61 67 73 20 26 20 54 46 5f 4e 6f 56 69 73 69 lags & TF_NoVisi
12740 62 6c 65 52 6f 77 69 64 29 3d 3d 30 29 0a 0a 2f bleRowid)==0)../
12750 2a 0a 2a 2a 20 45 61 63 68 20 66 6f 72 65 69 67 *.** Each foreig
12760 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 69 6e 74 n key constraint
12770 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 is an instance
12780 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
12790 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a structure..**.*
127a0 2a 20 41 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 * A foreign key
127b0 69 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 is associated wi
127c0 74 68 20 74 77 6f 20 74 61 62 6c 65 73 2e 20 20 th two tables.
127d0 54 68 65 20 22 66 72 6f 6d 22 20 74 61 62 6c 65 The "from" table
127e0 20 69 73 0a 2a 2a 20 74 68 65 20 74 61 62 6c 65 is.** the table
127f0 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 that contains t
12800 68 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c he REFERENCES cl
12810 61 75 73 65 20 74 68 61 74 20 63 72 65 61 74 65 ause that create
12820 73 20 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a 2a s the foreign.**
12830 20 6b 65 79 2e 20 20 54 68 65 20 22 74 6f 22 20 key. The "to"
12840 74 61 62 6c 65 20 69 73 20 74 68 65 20 74 61 62 table is the tab
12850 6c 65 20 74 68 61 74 20 69 73 20 6e 61 6d 65 64 le that is named
12860 20 69 6e 20 74 68 65 20 52 45 46 45 52 45 4e 43 in the REFERENC
12870 45 53 20 63 6c 61 75 73 65 2e 0a 2a 2a 20 43 6f ES clause..** Co
12880 6e 73 69 64 65 72 20 74 68 69 73 20 65 78 61 6d nsider this exam
12890 70 6c 65 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 43 ple:.**.** C
128a0 52 45 41 54 45 20 54 41 42 4c 45 20 65 78 31 28 REATE TABLE ex1(
128b0 0a 2a 2a 20 20 20 20 20 20 20 61 20 49 4e 54 45 .** a INTE
128c0 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
128d0 0a 2a 2a 20 20 20 20 20 20 20 62 20 49 4e 54 45 .** b INTE
128e0 47 45 52 20 43 4f 4e 53 54 52 41 49 4e 54 20 66 GER CONSTRAINT f
128f0 6b 31 20 52 45 46 45 52 45 4e 43 45 53 20 65 78 k1 REFERENCES ex
12900 32 28 78 29 0a 2a 2a 20 20 20 20 20 29 3b 0a 2a 2(x).** );.*
12910 2a 0a 2a 2a 20 46 6f 72 20 66 6f 72 65 69 67 6e *.** For foreign
12920 20 6b 65 79 20 22 66 6b 31 22 2c 20 74 68 65 20 key "fk1", the
12930 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 20 22 65 from-table is "e
12940 78 31 22 20 61 6e 64 20 74 68 65 20 74 6f 2d 74 x1" and the to-t
12950 61 62 6c 65 20 69 73 20 22 65 78 32 22 2e 0a 2a able is "ex2"..*
12960 2a 20 45 71 75 69 76 61 6c 65 6e 74 20 6e 61 6d * Equivalent nam
12970 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 66 72 es:.**.** fr
12980 6f 6d 2d 74 61 62 6c 65 20 3d 3d 20 63 68 69 6c om-table == chil
12990 64 2d 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 d-table.**
129a0 20 74 6f 2d 74 61 62 6c 65 20 3d 3d 20 70 61 72 to-table == par
129b0 65 6e 74 2d 74 61 62 6c 65 0a 2a 2a 0a 2a 2a 20 ent-table.**.**
129c0 45 61 63 68 20 52 45 46 45 52 45 4e 43 45 53 20 Each REFERENCES
129d0 63 6c 61 75 73 65 20 67 65 6e 65 72 61 74 65 73 clause generates
129e0 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 an instance of
129f0 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
12a00 72 75 63 74 75 72 65 0a 2a 2a 20 77 68 69 63 68 ructure.** which
12a10 20 69 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 is attached to
12a20 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 2e 20 the from-table.
12a30 20 54 68 65 20 74 6f 2d 74 61 62 6c 65 20 6e 65 The to-table ne
12a40 65 64 20 6e 6f 74 20 65 78 69 73 74 20 77 68 65 ed not exist whe
12a50 6e 0a 2a 2a 20 74 68 65 20 66 72 6f 6d 2d 74 61 n.** the from-ta
12a60 62 6c 65 20 69 73 20 63 72 65 61 74 65 64 2e 20 ble is created.
12a70 20 54 68 65 20 65 78 69 73 74 65 6e 63 65 20 6f The existence o
12a80 66 20 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 69 f the to-table i
12a90 73 20 6e 6f 74 20 63 68 65 63 6b 65 64 2e 0a 2a s not checked..*
12aa0 2a 0a 2a 2a 20 54 68 65 20 6c 69 73 74 20 6f 66 *.** The list of
12ab0 20 61 6c 6c 20 70 61 72 65 6e 74 73 20 66 6f 72 all parents for
12ac0 20 63 68 69 6c 64 20 54 61 62 6c 65 20 58 20 69 child Table X i
12ad0 73 20 68 65 6c 64 20 61 74 20 58 2e 70 46 4b 65 s held at X.pFKe
12ae0 79 2e 0a 2a 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 y..**.** A list
12af0 6f 66 20 61 6c 6c 20 63 68 69 6c 64 72 65 6e 20 of all children
12b00 66 6f 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 for a table name
12b10 64 20 5a 20 28 77 68 69 63 68 20 6d 69 67 68 74 d Z (which might
12b20 20 6e 6f 74 20 65 76 65 6e 20 65 78 69 73 74 29 not even exist)
12b30 0a 2a 2a 20 69 73 20 68 65 6c 64 20 69 6e 20 53 .** is held in S
12b40 63 68 65 6d 61 2e 66 6b 65 79 48 61 73 68 20 77 chema.fkeyHash w
12b50 69 74 68 20 61 20 68 61 73 68 20 6b 65 79 20 6f ith a hash key o
12b60 66 20 5a 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 f Z..*/.struct F
12b70 4b 65 79 20 7b 0a 20 20 54 61 62 6c 65 20 2a 70 Key {. Table *p
12b80 46 72 6f 6d 3b 20 20 20 20 20 2f 2a 20 54 61 62 From; /* Tab
12b90 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 le containing th
12ba0 65 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 e REFERENCES cla
12bb0 75 73 65 20 28 61 6b 61 3a 20 43 68 69 6c 64 29 use (aka: Child)
12bc0 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 */. FKey *pNex
12bd0 74 46 72 6f 6d 3b 20 20 2f 2a 20 4e 65 78 74 20 tFrom; /* Next
12be0 46 4b 65 79 20 77 69 74 68 20 74 68 65 20 73 61 FKey with the sa
12bf0 6d 65 20 69 6e 20 70 46 72 6f 6d 2e 20 4e 65 78 me in pFrom. Nex
12c00 74 20 70 61 72 65 6e 74 20 6f 66 20 70 46 72 6f t parent of pFro
12c10 6d 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 6f m */. char *zTo
12c20 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 ; /* Name
12c30 20 6f 66 20 74 61 62 6c 65 20 74 68 61 74 20 74 of table that t
12c40 68 65 20 6b 65 79 20 70 6f 69 6e 74 73 20 74 6f he key points to
12c50 20 28 61 6b 61 3a 20 50 61 72 65 6e 74 29 20 2a (aka: Parent) *
12c60 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 74 54 /. FKey *pNextT
12c70 6f 3b 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 69 o; /* Next wi
12c80 74 68 20 74 68 65 20 73 61 6d 65 20 7a 54 6f 2e th the same zTo.
12c90 20 4e 65 78 74 20 63 68 69 6c 64 20 6f 66 20 7a Next child of z
12ca0 54 6f 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 To. */. FKey *p
12cb0 50 72 65 76 54 6f 3b 20 20 20 20 2f 2a 20 50 72 PrevTo; /* Pr
12cc0 65 76 69 6f 75 73 20 77 69 74 68 20 74 68 65 20 evious with the
12cd0 73 61 6d 65 20 7a 54 6f 20 2a 2f 0a 20 20 69 6e same zTo */. in
12ce0 74 20 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 t nCol;
12cf0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c /* Number of col
12d00 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 6b 65 79 umns in this key
12d10 20 2a 2f 0a 20 20 2f 2a 20 45 56 3a 20 52 2d 33 */. /* EV: R-3
12d20 30 33 32 33 2d 32 31 39 31 37 20 2a 2f 0a 20 20 0323-21917 */.
12d30 75 38 20 69 73 44 65 66 65 72 72 65 64 3b 20 20 u8 isDeferred;
12d40 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
12d50 63 6f 6e 73 74 72 61 69 6e 74 20 63 68 65 63 6b constraint check
12d60 69 6e 67 20 69 73 20 64 65 66 65 72 72 65 64 20 ing is deferred
12d70 74 69 6c 6c 20 43 4f 4d 4d 49 54 20 2a 2f 0a 20 till COMMIT */.
12d80 20 75 38 20 61 41 63 74 69 6f 6e 5b 32 5d 3b 20 u8 aAction[2];
12d90 20 20 20 20 20 20 20 2f 2a 20 4f 4e 20 44 45 4c /* ON DEL
12da0 45 54 45 20 61 6e 64 20 4f 4e 20 55 50 44 41 54 ETE and ON UPDAT
12db0 45 20 61 63 74 69 6f 6e 73 2c 20 72 65 73 70 65 E actions, respe
12dc0 63 74 69 76 65 6c 79 20 2a 2f 0a 20 20 54 72 69 ctively */. Tri
12dd0 67 67 65 72 20 2a 61 70 54 72 69 67 67 65 72 5b gger *apTrigger[
12de0 32 5d 3b 2f 2a 20 54 72 69 67 67 65 72 73 20 66 2];/* Triggers f
12df0 6f 72 20 61 41 63 74 69 6f 6e 5b 5d 20 61 63 74 or aAction[] act
12e00 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 ions */. struct
12e10 20 73 43 6f 6c 4d 61 70 20 7b 20 20 20 20 20 20 sColMap {
12e20 2f 2a 20 4d 61 70 70 69 6e 67 20 6f 66 20 63 6f /* Mapping of co
12e30 6c 75 6d 6e 73 20 69 6e 20 70 46 72 6f 6d 20 74 lumns in pFrom t
12e40 6f 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 7a 54 6f o columns in zTo
12e50 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 46 72 6f */. int iFro
12e60 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
12e70 20 49 6e 64 65 78 20 6f 66 20 63 6f 6c 75 6d 6e Index of column
12e80 20 69 6e 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 20 in pFrom */.
12e90 20 63 68 61 72 20 2a 7a 43 6f 6c 3b 20 20 20 20 char *zCol;
12ea0 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
12eb0 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 7a 54 6f 2e f column in zTo.
12ec0 20 20 49 66 20 4e 55 4c 4c 20 75 73 65 20 50 52 If NULL use PR
12ed0 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 7d IMARY KEY */. }
12ee0 20 61 43 6f 6c 5b 31 5d 3b 20 20 20 20 20 20 20 aCol[1];
12ef0 20 20 20 20 20 2f 2a 20 4f 6e 65 20 65 6e 74 72 /* One entr
12f00 79 20 66 6f 72 20 65 61 63 68 20 6f 66 20 6e 43 y for each of nC
12f10 6f 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 7d 3b ol columns */.};
12f20 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 69 74 65 20 73 ../*.** SQLite s
12f30 75 70 70 6f 72 74 73 20 6d 61 6e 79 20 64 69 66 upports many dif
12f40 66 65 72 65 6e 74 20 77 61 79 73 20 74 6f 20 72 ferent ways to r
12f50 65 73 6f 6c 76 65 20 61 20 63 6f 6e 73 74 72 61 esolve a constra
12f60 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 2e 20 20 52 int.** error. R
12f70 4f 4c 4c 42 41 43 4b 20 70 72 6f 63 65 73 73 69 OLLBACK processi
12f80 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 20 61 20 ng means that a
12f90 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 constraint viola
12fa0 74 69 6f 6e 0a 2a 2a 20 63 61 75 73 65 73 20 74 tion.** causes t
12fb0 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 he operation in
12fc0 70 72 6f 63 65 73 73 20 74 6f 20 66 61 69 6c 20 process to fail
12fd0 61 6e 64 20 66 6f 72 20 74 68 65 20 63 75 72 72 and for the curr
12fe0 65 6e 74 20 74 72 61 6e 73 61 63 74 69 6f 6e 0a ent transaction.
12ff0 2a 2a 20 74 6f 20 62 65 20 72 6f 6c 6c 65 64 20 ** to be rolled
13000 62 61 63 6b 2e 20 20 41 42 4f 52 54 20 70 72 6f back. ABORT pro
13010 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 cessing means th
13020 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 e operation in p
13030 72 6f 63 65 73 73 0a 2a 2a 20 66 61 69 6c 73 20 rocess.** fails
13040 61 6e 64 20 61 6e 79 20 70 72 69 6f 72 20 63 68 and any prior ch
13050 61 6e 67 65 73 20 66 72 6f 6d 20 74 68 61 74 20 anges from that
13060 6f 6e 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 72 one operation ar
13070 65 20 62 61 63 6b 65 64 20 6f 75 74 2c 0a 2a 2a e backed out,.**
13080 20 62 75 74 20 74 68 65 20 74 72 61 6e 73 61 63 but the transac
13090 74 69 6f 6e 20 69 73 20 6e 6f 74 20 72 6f 6c 6c tion is not roll
130a0 65 64 20 62 61 63 6b 2e 20 20 46 41 49 4c 20 70 ed back. FAIL p
130b0 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 rocessing means
130c0 74 68 61 74 0a 2a 2a 20 74 68 65 20 6f 70 65 72 that.** the oper
130d0 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 73 ation in progres
130e0 73 20 73 74 6f 70 73 20 61 6e 64 20 72 65 74 75 s stops and retu
130f0 72 6e 73 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 rns an error cod
13100 65 2e 20 20 42 75 74 20 70 72 69 6f 72 0a 2a 2a e. But prior.**
13110 20 63 68 61 6e 67 65 73 20 64 75 65 20 74 6f 20 changes due to
13120 74 68 65 20 73 61 6d 65 20 6f 70 65 72 61 74 69 the same operati
13130 6f 6e 20 61 72 65 20 6e 6f 74 20 62 61 63 6b 65 on are not backe
13140 64 20 6f 75 74 20 61 6e 64 20 6e 6f 20 72 6f 6c d out and no rol
13150 6c 62 61 63 6b 0a 2a 2a 20 6f 63 63 75 72 73 2e lback.** occurs.
13160 20 20 49 47 4e 4f 52 45 20 6d 65 61 6e 73 20 74 IGNORE means t
13170 68 61 74 20 74 68 65 20 70 61 72 74 69 63 75 6c hat the particul
13180 61 72 20 72 6f 77 20 74 68 61 74 20 63 61 75 73 ar row that caus
13190 65 64 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e ed the constrain
131a0 74 0a 2a 2a 20 65 72 72 6f 72 20 69 73 20 6e 6f t.** error is no
131b0 74 20 69 6e 73 65 72 74 65 64 20 6f 72 20 75 70 t inserted or up
131c0 64 61 74 65 64 2e 20 20 50 72 6f 63 65 73 73 69 dated. Processi
131d0 6e 67 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e 64 ng continues and
131e0 20 6e 6f 20 65 72 72 6f 72 0a 2a 2a 20 69 73 20 no error.** is
131f0 72 65 74 75 72 6e 65 64 2e 20 20 52 45 50 4c 41 returned. REPLA
13200 43 45 20 6d 65 61 6e 73 20 74 68 61 74 20 70 72 CE means that pr
13210 65 65 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 eexisting databa
13220 73 65 20 72 6f 77 73 20 74 68 61 74 20 63 61 75 se rows that cau
13230 73 65 64 0a 2a 2a 20 61 20 55 4e 49 51 55 45 20 sed.** a UNIQUE
13240 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 constraint viola
13250 74 69 6f 6e 20 61 72 65 20 72 65 6d 6f 76 65 64 tion are removed
13260 20 73 6f 20 74 68 61 74 20 74 68 65 20 6e 65 77 so that the new
13270 20 69 6e 73 65 72 74 20 6f 72 0a 2a 2a 20 75 70 insert or.** up
13280 64 61 74 65 20 63 61 6e 20 70 72 6f 63 65 65 64 date can proceed
13290 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 20 63 6f . Processing co
132a0 6e 74 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 65 ntinues and no e
132b0 72 72 6f 72 20 69 73 20 72 65 70 6f 72 74 65 64 rror is reported
132c0 2e 0a 2a 2a 0a 2a 2a 20 52 45 53 54 52 49 43 54 ..**.** RESTRICT
132d0 2c 20 53 45 54 4e 55 4c 4c 2c 20 61 6e 64 20 43 , SETNULL, and C
132e0 41 53 43 41 44 45 20 61 63 74 69 6f 6e 73 20 61 ASCADE actions a
132f0 70 70 6c 79 20 6f 6e 6c 79 20 74 6f 20 66 6f 72 pply only to for
13300 65 69 67 6e 20 6b 65 79 73 2e 0a 2a 2a 20 52 45 eign keys..** RE
13310 53 54 52 49 43 54 20 69 73 20 74 68 65 20 73 61 STRICT is the sa
13320 6d 65 20 61 73 20 41 42 4f 52 54 20 66 6f 72 20 me as ABORT for
13330 49 4d 4d 45 44 49 41 54 45 20 66 6f 72 65 69 67 IMMEDIATE foreig
13340 6e 20 6b 65 79 73 20 61 6e 64 20 74 68 65 0a 2a n keys and the.*
13350 2a 20 73 61 6d 65 20 61 73 20 52 4f 4c 4c 42 41 * same as ROLLBA
13360 43 4b 20 66 6f 72 20 44 45 46 45 52 52 45 44 20 CK for DEFERRED
13370 6b 65 79 73 2e 20 20 53 45 54 4e 55 4c 4c 20 6d keys. SETNULL m
13380 65 61 6e 73 20 74 68 61 74 20 74 68 65 20 66 6f eans that the fo
13390 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 69 73 20 reign.** key is
133a0 73 65 74 20 74 6f 20 4e 55 4c 4c 2e 20 20 43 41 set to NULL. CA
133b0 53 43 41 44 45 20 6d 65 61 6e 73 20 74 68 61 74 SCADE means that
133c0 20 61 20 44 45 4c 45 54 45 20 6f 72 20 55 50 44 a DELETE or UPD
133d0 41 54 45 20 6f 66 20 74 68 65 0a 2a 2a 20 72 65 ATE of the.** re
133e0 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 72 ferenced table r
133f0 6f 77 20 69 73 20 70 72 6f 70 61 67 61 74 65 64 ow is propagated
13400 20 69 6e 74 6f 20 74 68 65 20 72 6f 77 20 74 68 into the row th
13410 61 74 20 68 6f 6c 64 73 20 74 68 65 0a 2a 2a 20 at holds the.**
13420 66 6f 72 65 69 67 6e 20 6b 65 79 2e 0a 2a 2a 0a foreign key..**.
13430 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ** The following
13440 20 73 79 6d 62 6f 6c 69 63 20 76 61 6c 75 65 73 symbolic values
13450 20 61 72 65 20 75 73 65 64 20 74 6f 20 72 65 63 are used to rec
13460 6f 72 64 20 77 68 69 63 68 20 74 79 70 65 0a 2a ord which type.*
13470 2a 20 6f 66 20 61 63 74 69 6f 6e 20 74 6f 20 74 * of action to t
13480 61 6b 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ake..*/.#define
13490 4f 45 5f 4e 6f 6e 65 20 20 20 20 20 30 20 20 20 OE_None 0
134a0 2f 2a 20 54 68 65 72 65 20 69 73 20 6e 6f 20 63 /* There is no c
134b0 6f 6e 73 74 72 61 69 6e 74 20 74 6f 20 63 68 65 onstraint to che
134c0 63 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 ck */.#define OE
134d0 5f 52 6f 6c 6c 62 61 63 6b 20 31 20 20 20 2f 2a _Rollback 1 /*
134e0 20 46 61 69 6c 20 74 68 65 20 6f 70 65 72 61 74 Fail the operat
134f0 69 6f 6e 20 61 6e 64 20 72 6f 6c 6c 62 61 63 6b ion and rollback
13500 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f 6e the transaction
13510 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 41 */.#define OE_A
13520 62 6f 72 74 20 20 20 20 32 20 20 20 2f 2a 20 42 bort 2 /* B
13530 61 63 6b 20 6f 75 74 20 63 68 61 6e 67 65 73 20 ack out changes
13540 62 75 74 20 64 6f 20 6e 6f 20 72 6f 6c 6c 62 61 but do no rollba
13550 63 6b 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 2a ck transaction *
13560 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 46 61 69 /.#define OE_Fai
13570 6c 20 20 20 20 20 33 20 20 20 2f 2a 20 53 74 6f l 3 /* Sto
13580 70 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 p the operation
13590 62 75 74 20 6c 65 61 76 65 20 61 6c 6c 20 70 72 but leave all pr
135a0 69 6f 72 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 ior changes */.#
135b0 64 65 66 69 6e 65 20 4f 45 5f 49 67 6e 6f 72 65 define OE_Ignore
135c0 20 20 20 34 20 20 20 2f 2a 20 49 67 6e 6f 72 65 4 /* Ignore
135d0 20 74 68 65 20 65 72 72 6f 72 2e 20 44 6f 20 6e the error. Do n
135e0 6f 74 20 64 6f 20 74 68 65 20 49 4e 53 45 52 54 ot do the INSERT
135f0 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 or UPDATE */.#d
13600 65 66 69 6e 65 20 4f 45 5f 52 65 70 6c 61 63 65 efine OE_Replace
13610 20 20 35 20 20 20 2f 2a 20 44 65 6c 65 74 65 20 5 /* Delete
13620 65 78 69 73 74 69 6e 67 20 72 65 63 6f 72 64 2c existing record,
13630 20 74 68 65 6e 20 64 6f 20 49 4e 53 45 52 54 20 then do INSERT
13640 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 0a 23 64 or UPDATE */..#d
13650 65 66 69 6e 65 20 4f 45 5f 52 65 73 74 72 69 63 efine OE_Restric
13660 74 20 36 20 20 20 2f 2a 20 4f 45 5f 41 62 6f 72 t 6 /* OE_Abor
13670 74 20 66 6f 72 20 49 4d 4d 45 44 49 41 54 45 2c t for IMMEDIATE,
13680 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 66 6f 72 OE_Rollback for
13690 20 44 45 46 45 52 52 45 44 20 2a 2f 0a 23 64 65 DEFERRED */.#de
136a0 66 69 6e 65 20 4f 45 5f 53 65 74 4e 75 6c 6c 20 fine OE_SetNull
136b0 20 37 20 20 20 2f 2a 20 53 65 74 20 74 68 65 20 7 /* Set the
136c0 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c 75 foreign key valu
136d0 65 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a 23 64 65 e to NULL */.#de
136e0 66 69 6e 65 20 4f 45 5f 53 65 74 44 66 6c 74 20 fine OE_SetDflt
136f0 20 38 20 20 20 2f 2a 20 53 65 74 20 74 68 65 20 8 /* Set the
13700 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c 75 foreign key valu
13710 65 20 74 6f 20 69 74 73 20 64 65 66 61 75 6c 74 e to its default
13720 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 43 */.#define OE_C
13730 61 73 63 61 64 65 20 20 39 20 20 20 2f 2a 20 43 ascade 9 /* C
13740 61 73 63 61 64 65 20 74 68 65 20 63 68 61 6e 67 ascade the chang
13750 65 73 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 4f es */..#define O
13760 45 5f 44 65 66 61 75 6c 74 20 20 31 30 20 20 2f E_Default 10 /
13770 2a 20 44 6f 20 77 68 61 74 65 76 65 72 20 74 68 * Do whatever th
13780 65 20 64 65 66 61 75 6c 74 20 61 63 74 69 6f 6e e default action
13790 20 69 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 41 is */.../*.** A
137a0 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
137b0 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
137c0 63 74 75 72 65 20 69 73 20 70 61 73 73 65 64 20 cture is passed
137d0 61 73 20 74 68 65 20 66 69 72 73 74 0a 2a 2a 20 as the first.**
137e0 61 72 67 75 6d 65 6e 74 20 74 6f 20 73 71 6c 69 argument to sqli
137f0 74 65 33 56 64 62 65 4b 65 79 43 6f 6d 70 61 72 te3VdbeKeyCompar
13800 65 20 61 6e 64 20 69 73 20 75 73 65 64 20 74 6f e and is used to
13810 20 63 6f 6e 74 72 6f 6c 20 74 68 65 0a 2a 2a 20 control the.**
13820 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 66 20 74 68 comparison of th
13830 65 20 74 77 6f 20 69 6e 64 65 78 20 6b 65 79 73 e two index keys
13840 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 61 ..**.** Note tha
13850 74 20 61 53 6f 72 74 4f 72 64 65 72 5b 5d 20 61 t aSortOrder[] a
13860 6e 64 20 61 43 6f 6c 6c 5b 5d 20 68 61 76 65 20 nd aColl[] have
13870 6e 46 69 65 6c 64 2b 31 20 73 6c 6f 74 73 2e 20 nField+1 slots.
13880 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 6e 46 There.** are nF
13890 69 65 6c 64 20 73 6c 6f 74 73 20 66 6f 72 20 74 ield slots for t
138a0 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 61 6e he columns of an
138b0 20 69 6e 64 65 78 20 74 68 65 6e 20 6f 6e 65 20 index then one
138c0 65 78 74 72 61 20 73 6c 6f 74 0a 2a 2a 20 66 6f extra slot.** fo
138d0 72 20 74 68 65 20 72 6f 77 69 64 20 61 74 20 74 r the rowid at t
138e0 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 he end..*/.struc
138f0 74 20 4b 65 79 49 6e 66 6f 20 7b 0a 20 20 75 33 t KeyInfo {. u3
13900 32 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 2 nRef;
13910 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 72 /* Number of r
13920 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 68 69 eferences to thi
13930 73 20 4b 65 79 49 6e 66 6f 20 6f 62 6a 65 63 74 s KeyInfo object
13940 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 */. u8 enc;
13950 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
13960 74 20 65 6e 63 6f 64 69 6e 67 20 2d 20 6f 6e 65 t encoding - one
13970 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 5f 55 of the SQLITE_U
13980 54 46 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 TF* values */.
13990 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 20 20 20 u16 nField;
139a0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
139b0 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 key columns in
139c0 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 the index */. u
139d0 31 36 20 6e 58 46 69 65 6c 64 3b 20 20 20 20 20 16 nXField;
139e0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
139f0 63 6f 6c 75 6d 6e 73 20 62 65 79 6f 6e 64 20 74 columns beyond t
13a00 68 65 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 2a he key columns *
13a10 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b /. sqlite3 *db;
13a20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 /* The d
13a30 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
13a40 6f 6e 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f 72 on */. u8 *aSor
13a50 74 4f 72 64 65 72 3b 20 20 20 20 20 2f 2a 20 53 tOrder; /* S
13a60 6f 72 74 20 6f 72 64 65 72 20 66 6f 72 20 65 61 ort order for ea
13a70 63 68 20 63 6f 6c 75 6d 6e 2e 20 2a 2f 0a 20 20 ch column. */.
13a80 43 6f 6c 6c 53 65 71 20 2a 61 43 6f 6c 6c 5b 31 CollSeq *aColl[1
13a90 5d 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 ]; /* Collating
13aa0 20 73 65 71 75 65 6e 63 65 20 66 6f 72 20 65 61 sequence for ea
13ab0 63 68 20 74 65 72 6d 20 6f 66 20 74 68 65 20 6b ch term of the k
13ac0 65 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ey */.};../*.**
13ad0 54 68 69 73 20 6f 62 6a 65 63 74 20 68 6f 6c 64 This object hold
13ae0 73 20 61 20 72 65 63 6f 72 64 20 77 68 69 63 68 s a record which
13af0 20 68 61 73 20 62 65 65 6e 20 70 61 72 73 65 64 has been parsed
13b00 20 6f 75 74 20 69 6e 74 6f 20 69 6e 64 69 76 69 out into indivi
13b10 64 75 61 6c 0a 2a 2a 20 66 69 65 6c 64 73 2c 20 dual.** fields,
13b20 66 6f 72 20 74 68 65 20 70 75 72 70 6f 73 65 73 for the purposes
13b30 20 6f 66 20 64 6f 69 6e 67 20 61 20 63 6f 6d 70 of doing a comp
13b40 61 72 69 73 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 41 20 arison..**.** A
13b50 72 65 63 6f 72 64 20 69 73 20 61 6e 20 6f 62 6a record is an obj
13b60 65 63 74 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ect that contain
13b70 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 66 69 s one or more fi
13b80 65 6c 64 73 20 6f 66 20 64 61 74 61 2e 0a 2a 2a elds of data..**
13b90 20 52 65 63 6f 72 64 73 20 61 72 65 20 75 73 65 Records are use
13ba0 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 63 d to store the c
13bb0 6f 6e 74 65 6e 74 20 6f 66 20 61 20 74 61 62 6c ontent of a tabl
13bc0 65 20 72 6f 77 20 61 6e 64 20 74 6f 20 73 74 6f e row and to sto
13bd0 72 65 0a 2a 2a 20 74 68 65 20 6b 65 79 20 6f 66 re.** the key of
13be0 20 61 6e 20 69 6e 64 65 78 2e 20 20 41 20 62 6c an index. A bl
13bf0 6f 62 20 65 6e 63 6f 64 69 6e 67 20 6f 66 20 61 ob encoding of a
13c00 20 72 65 63 6f 72 64 20 69 73 20 63 72 65 61 74 record is creat
13c10 65 64 20 62 79 0a 2a 2a 20 74 68 65 20 4f 50 5f ed by.** the OP_
13c20 4d 61 6b 65 52 65 63 6f 72 64 20 6f 70 63 6f 64 MakeRecord opcod
13c30 65 20 6f 66 20 74 68 65 20 56 44 42 45 20 61 6e e of the VDBE an
13c40 64 20 69 73 20 64 69 73 61 73 73 65 6d 62 6c 65 d is disassemble
13c50 64 20 62 79 20 74 68 65 0a 2a 2a 20 4f 50 5f 43 d by the.** OP_C
13c60 6f 6c 75 6d 6e 20 6f 70 63 6f 64 65 2e 0a 2a 2a olumn opcode..**
13c70 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
13c80 6f 66 20 74 68 69 73 20 6f 62 6a 65 63 74 20 73 of this object s
13c90 65 72 76 65 73 20 61 73 20 61 20 22 6b 65 79 22 erves as a "key"
13ca0 20 66 6f 72 20 64 6f 69 6e 67 20 61 20 73 65 61 for doing a sea
13cb0 72 63 68 20 6f 6e 0a 2a 2a 20 61 6e 20 69 6e 64 rch on.** an ind
13cc0 65 78 20 62 2b 74 72 65 65 2e 20 54 68 65 20 67 ex b+tree. The g
13cd0 6f 61 6c 20 6f 66 20 74 68 65 20 73 65 61 72 63 oal of the searc
13ce0 68 20 69 73 20 74 6f 20 66 69 6e 64 20 74 68 65 h is to find the
13cf0 20 65 6e 74 72 79 20 74 68 61 74 0a 2a 2a 20 69 entry that.** i
13d00 73 20 63 6c 6f 73 65 64 20 74 6f 20 74 68 65 20 s closed to the
13d10 6b 65 79 20 64 65 73 63 72 69 62 65 64 20 62 79 key described by
13d20 20 74 68 69 73 20 6f 62 6a 65 63 74 2e 20 20 54 this object. T
13d30 68 69 73 20 6f 62 6a 65 63 74 20 6d 69 67 68 74 his object might
13d40 20 68 6f 6c 64 0a 2a 2a 20 6a 75 73 74 20 61 20 hold.** just a
13d50 70 72 65 66 69 78 20 6f 66 20 74 68 65 20 6b 65 prefix of the ke
13d60 79 2e 20 20 54 68 65 20 6e 75 6d 62 65 72 20 6f y. The number o
13d70 66 20 66 69 65 6c 64 73 20 69 73 20 67 69 76 65 f fields is give
13d80 6e 20 62 79 0a 2a 2a 20 70 4b 65 79 49 6e 66 6f n by.** pKeyInfo
13d90 2d 3e 6e 46 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 ->nField..**.**
13da0 54 68 65 20 72 31 20 61 6e 64 20 72 32 20 66 69 The r1 and r2 fi
13db0 65 6c 64 73 20 61 72 65 20 74 68 65 20 76 61 6c elds are the val
13dc0 75 65 73 20 74 6f 20 72 65 74 75 72 6e 20 69 66 ues to return if
13dd0 20 74 68 69 73 20 6b 65 79 20 69 73 20 6c 65 73 this key is les
13de0 73 20 74 68 61 6e 0a 2a 2a 20 6f 72 20 67 72 65 s than.** or gre
13df0 61 74 65 72 20 74 68 61 6e 20 61 20 6b 65 79 20 ater than a key
13e00 69 6e 20 74 68 65 20 62 74 72 65 65 2c 20 72 65 in the btree, re
13e10 73 70 65 63 74 69 76 65 6c 79 2e 20 20 54 68 65 spectively. The
13e20 73 65 20 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 0a se are normally.
13e30 2a 2a 20 2d 31 20 61 6e 64 20 2b 31 20 72 65 73 ** -1 and +1 res
13e40 70 65 63 74 69 76 65 6c 79 2c 20 62 75 74 20 6d pectively, but m
13e50 69 67 68 74 20 62 65 20 69 6e 76 65 72 74 65 64 ight be inverted
13e60 20 74 6f 20 2b 31 20 61 6e 64 20 2d 31 20 69 66 to +1 and -1 if
13e70 20 74 68 65 20 62 2d 74 72 65 65 0a 2a 2a 20 69 the b-tree.** i
13e80 73 20 69 6e 20 44 45 53 43 20 6f 72 64 65 72 2e s in DESC order.
13e90 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6b 65 79 20 63 .**.** The key c
13ea0 6f 6d 70 61 72 69 73 6f 6e 20 66 75 6e 63 74 69 omparison functi
13eb0 6f 6e 73 20 61 63 74 75 61 6c 6c 79 20 72 65 74 ons actually ret
13ec0 75 72 6e 20 64 65 66 61 75 6c 74 5f 72 63 20 77 urn default_rc w
13ed0 68 65 6e 20 74 68 65 79 20 66 69 6e 64 0a 2a 2a hen they find.**
13ee0 20 61 6e 20 65 71 75 61 6c 73 20 63 6f 6d 70 61 an equals compa
13ef0 72 69 73 6f 6e 2e 20 20 64 65 66 61 75 6c 74 5f rison. default_
13f00 72 63 20 63 61 6e 20 62 65 20 2d 31 2c 20 30 2c rc can be -1, 0,
13f10 20 6f 72 20 2b 31 2e 20 20 49 66 20 74 68 65 72 or +1. If ther
13f20 65 20 61 72 65 0a 2a 2a 20 6d 75 6c 74 69 70 6c e are.** multipl
13f30 65 20 65 6e 74 72 69 65 73 20 69 6e 20 74 68 65 e entries in the
13f40 20 62 2d 74 72 65 65 20 77 69 74 68 20 74 68 65 b-tree with the
13f50 20 73 61 6d 65 20 6b 65 79 20 28 77 68 65 6e 20 same key (when
13f60 6f 6e 6c 79 20 6c 6f 6f 6b 69 6e 67 0a 2a 2a 20 only looking.**
13f70 61 74 20 74 68 65 20 66 69 72 73 74 20 70 4b 65 at the first pKe
13f80 79 49 6e 66 6f 2d 3e 6e 46 69 65 6c 64 73 2c 29 yInfo->nFields,)
13f90 20 74 68 65 6e 20 64 65 66 61 75 6c 74 5f 72 63 then default_rc
13fa0 20 63 61 6e 20 62 65 20 73 65 74 20 74 6f 20 2d can be set to -
13fb0 31 20 74 6f 0a 2a 2a 20 63 61 75 73 65 20 74 68 1 to.** cause th
13fc0 65 20 73 65 61 72 63 68 20 74 6f 20 66 69 6e 64 e search to find
13fd0 20 74 68 65 20 6c 61 73 74 20 6d 61 74 63 68 2c the last match,
13fe0 20 6f 72 20 2b 31 20 74 6f 20 63 61 75 73 65 20 or +1 to cause
13ff0 74 68 65 20 73 65 61 72 63 68 20 74 6f 0a 2a 2a the search to.**
14000 20 66 69 6e 64 20 74 68 65 20 66 69 72 73 74 20 find the first
14010 6d 61 74 63 68 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 match..**.** The
14020 20 6b 65 79 20 63 6f 6d 70 61 72 69 73 6f 6e 20 key comparison
14030 66 75 6e 63 74 69 6f 6e 73 20 77 69 6c 6c 20 73 functions will s
14040 65 74 20 65 71 53 65 65 6e 20 74 6f 20 74 72 75 et eqSeen to tru
14050 65 20 69 66 20 74 68 65 79 20 65 76 65 72 0a 2a e if they ever.*
14060 2a 20 67 65 74 20 61 6e 64 20 65 71 75 61 6c 20 * get and equal
14070 72 65 73 75 6c 74 73 20 77 68 65 6e 20 63 6f 6d results when com
14080 70 61 72 69 6e 67 20 74 68 69 73 20 73 74 72 75 paring this stru
14090 63 74 75 72 65 20 74 6f 20 61 20 62 2d 74 72 65 cture to a b-tre
140a0 65 20 72 65 63 6f 72 64 2e 0a 2a 2a 20 57 68 65 e record..** Whe
140b0 6e 20 64 65 66 61 75 6c 74 5f 72 63 21 3d 30 2c n default_rc!=0,
140c0 20 74 68 65 20 73 65 61 72 63 68 20 6d 69 67 68 the search migh
140d0 74 20 65 6e 64 20 75 70 20 6f 6e 20 74 68 65 20 t end up on the
140e0 72 65 63 6f 72 64 20 69 6d 6d 65 64 69 61 74 65 record immediate
140f0 6c 79 0a 2a 2a 20 62 65 66 6f 72 65 20 74 68 65 ly.** before the
14100 20 66 69 72 73 74 20 6d 61 74 63 68 20 6f 72 20 first match or
14110 69 6d 6d 65 64 69 61 74 65 6c 79 20 61 66 74 65 immediately afte
14120 72 20 74 68 65 20 6c 61 73 74 20 6d 61 74 63 68 r the last match
14130 2e 20 20 54 68 65 0a 2a 2a 20 65 71 53 65 65 6e . The.** eqSeen
14140 20 66 69 65 6c 64 20 77 69 6c 6c 20 69 6e 64 69 field will indi
14150 63 61 74 65 20 77 68 65 74 68 65 72 20 6f 72 20 cate whether or
14160 6e 6f 74 20 61 6e 20 65 78 61 63 74 20 6d 61 74 not an exact mat
14170 63 68 20 65 78 69 73 74 73 20 69 6e 20 74 68 65 ch exists in the
14180 0a 2a 2a 20 62 2d 74 72 65 65 2e 0a 2a 2f 0a 73 .** b-tree..*/.s
14190 74 72 75 63 74 20 55 6e 70 61 63 6b 65 64 52 65 truct UnpackedRe
141a0 63 6f 72 64 20 7b 0a 20 20 4b 65 79 49 6e 66 6f cord {. KeyInfo
141b0 20 2a 70 4b 65 79 49 6e 66 6f 3b 20 20 2f 2a 20 *pKeyInfo; /*
141c0 43 6f 6c 6c 61 74 69 6f 6e 20 61 6e 64 20 73 6f Collation and so
141d0 72 74 2d 6f 72 64 65 72 20 69 6e 66 6f 72 6d 61 rt-order informa
141e0 74 69 6f 6e 20 2a 2f 0a 20 20 4d 65 6d 20 2a 61 tion */. Mem *a
141f0 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 2f 2a Mem; /*
14200 20 56 61 6c 75 65 73 20 2a 2f 0a 20 20 75 31 36 Values */. u16
14210 20 6e 46 69 65 6c 64 3b 20 20 20 20 20 20 20 20 nField;
14220 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e /* Number of en
14230 74 72 69 65 73 20 69 6e 20 61 70 4d 65 6d 5b 5d tries in apMem[]
14240 20 2a 2f 0a 20 20 69 38 20 64 65 66 61 75 6c 74 */. i8 default
14250 5f 72 63 3b 20 20 20 20 20 20 2f 2a 20 43 6f 6d _rc; /* Com
14260 70 61 72 69 73 6f 6e 20 72 65 73 75 6c 74 20 69 parison result i
14270 66 20 6b 65 79 73 20 61 72 65 20 65 71 75 61 6c f keys are equal
14280 20 2a 2f 0a 20 20 75 38 20 65 72 72 43 6f 64 65 */. u8 errCode
14290 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 72 ; /* Err
142a0 6f 72 20 64 65 74 65 63 74 65 64 20 62 79 20 78 or detected by x
142b0 52 65 63 6f 72 64 43 6f 6d 70 61 72 65 20 28 43 RecordCompare (C
142c0 4f 52 52 55 50 54 20 6f 72 20 4e 4f 4d 45 4d 29 ORRUPT or NOMEM)
142d0 20 2a 2f 0a 20 20 69 38 20 72 31 3b 20 20 20 20 */. i8 r1;
142e0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c /* Val
142f0 75 65 20 74 6f 20 72 65 74 75 72 6e 20 69 66 20 ue to return if
14300 28 6c 68 73 20 3e 20 72 68 73 29 20 2a 2f 0a 20 (lhs > rhs) */.
14310 20 69 38 20 72 32 3b 20 20 20 20 20 20 20 20 20 i8 r2;
14320 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f /* Value to
14330 20 72 65 74 75 72 6e 20 69 66 20 28 72 68 73 20 return if (rhs
14340 3c 20 6c 68 73 29 20 2a 2f 0a 20 20 75 38 20 65 < lhs) */. u8 e
14350 71 53 65 65 6e 3b 20 20 20 20 20 20 20 20 20 20 qSeen;
14360 2f 2a 20 54 72 75 65 20 69 66 20 61 6e 20 65 71 /* True if an eq
14370 75 61 6c 69 74 79 20 63 6f 6d 70 61 72 69 73 6f uality compariso
14380 6e 20 68 61 73 20 62 65 65 6e 20 73 65 65 6e 20 n has been seen
14390 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 */.};.../*.** Ea
143a0 63 68 20 53 51 4c 20 69 6e 64 65 78 20 69 73 20 ch SQL index is
143b0 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 6d represented in m
143c0 65 6d 6f 72 79 20 62 79 20 61 6e 0a 2a 2a 20 69 emory by an.** i
143d0 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
143e0 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
143f0 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 63 6f re..**.** The co
14400 6c 75 6d 6e 73 20 6f 66 20 74 68 65 20 74 61 62 lumns of the tab
14410 6c 65 20 74 68 61 74 20 61 72 65 20 74 6f 20 62 le that are to b
14420 65 20 69 6e 64 65 78 65 64 20 61 72 65 20 64 65 e indexed are de
14430 73 63 72 69 62 65 64 0a 2a 2a 20 62 79 20 74 68 scribed.** by th
14440 65 20 61 69 43 6f 6c 75 6d 6e 5b 5d 20 66 69 65 e aiColumn[] fie
14450 6c 64 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ld of this struc
14460 74 75 72 65 2e 20 20 46 6f 72 20 65 78 61 6d 70 ture. For examp
14470 6c 65 2c 20 73 75 70 70 6f 73 65 0a 2a 2a 20 77 le, suppose.** w
14480 65 20 68 61 76 65 20 74 68 65 20 66 6f 6c 6c 6f e have the follo
14490 77 69 6e 67 20 74 61 62 6c 65 20 61 6e 64 20 69 wing table and i
144a0 6e 64 65 78 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 ndex:.**.**
144b0 43 52 45 41 54 45 20 54 41 42 4c 45 20 45 78 31 CREATE TABLE Ex1
144c0 28 63 31 20 69 6e 74 2c 20 63 32 20 69 6e 74 2c (c1 int, c2 int,
144d0 20 63 33 20 74 65 78 74 29 3b 0a 2a 2a 20 20 20 c3 text);.**
144e0 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 45 CREATE INDEX E
144f0 78 32 20 4f 4e 20 45 78 31 28 63 33 2c 63 31 29 x2 ON Ex1(c3,c1)
14500 3b 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 54 ;.**.** In the T
14510 61 62 6c 65 20 73 74 72 75 63 74 75 72 65 20 64 able structure d
14520 65 73 63 72 69 62 69 6e 67 20 45 78 31 2c 20 6e escribing Ex1, n
14530 43 6f 6c 3d 3d 33 20 62 65 63 61 75 73 65 20 74 Col==3 because t
14540 68 65 72 65 20 61 72 65 0a 2a 2a 20 74 68 72 65 here are.** thre
14550 65 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 e columns in the
14560 20 74 61 62 6c 65 2e 20 20 49 6e 20 74 68 65 20 table. In the
14570 49 6e 64 65 78 20 73 74 72 75 63 74 75 72 65 20 Index structure
14580 64 65 73 63 72 69 62 69 6e 67 0a 2a 2a 20 45 78 describing.** Ex
14590 32 2c 20 6e 43 6f 6c 75 6d 6e 3d 3d 32 20 73 69 2, nColumn==2 si
145a0 6e 63 65 20 32 20 6f 66 20 74 68 65 20 33 20 63 nce 2 of the 3 c
145b0 6f 6c 75 6d 6e 73 20 6f 66 20 45 78 31 20 61 72 olumns of Ex1 ar
145c0 65 20 69 6e 64 65 78 65 64 2e 0a 2a 2a 20 54 68 e indexed..** Th
145d0 65 20 76 61 6c 75 65 20 6f 66 20 61 69 43 6f 6c e value of aiCol
145e0 75 6d 6e 20 69 73 20 7b 32 2c 20 30 7d 2e 20 20 umn is {2, 0}.
145f0 61 69 43 6f 6c 75 6d 6e 5b 30 5d 3d 3d 32 20 62 aiColumn[0]==2 b
14600 65 63 61 75 73 65 20 74 68 65 0a 2a 2a 20 66 69 ecause the.** fi
14610 72 73 74 20 63 6f 6c 75 6d 6e 20 74 6f 20 62 65 rst column to be
14620 20 69 6e 64 65 78 65 64 20 28 63 33 29 20 68 61 indexed (c3) ha
14630 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 20 32 20 s an index of 2
14640 69 6e 20 45 78 31 2e 61 43 6f 6c 5b 5d 2e 0a 2a in Ex1.aCol[]..*
14650 2a 20 54 68 65 20 73 65 63 6f 6e 64 20 63 6f 6c * The second col
14660 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 65 78 65 umn to be indexe
14670 64 20 28 63 31 29 20 68 61 73 20 61 6e 20 69 6e d (c1) has an in
14680 64 65 78 20 6f 66 20 30 20 69 6e 0a 2a 2a 20 45 dex of 0 in.** E
14690 78 31 2e 61 43 6f 6c 5b 5d 2c 20 68 65 6e 63 65 x1.aCol[], hence
146a0 20 45 78 32 2e 61 69 43 6f 6c 75 6d 6e 5b 31 5d Ex2.aiColumn[1]
146b0 3d 3d 30 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 ==0..**.** The I
146c0 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 66 69 65 ndex.onError fie
146d0 6c 64 20 64 65 74 65 72 6d 69 6e 65 73 20 77 68 ld determines wh
146e0 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 65 ether or not the
146f0 20 69 6e 64 65 78 65 64 20 63 6f 6c 75 6d 6e 73 indexed columns
14700 0a 2a 2a 20 6d 75 73 74 20 62 65 20 75 6e 69 71 .** must be uniq
14710 75 65 20 61 6e 64 20 77 68 61 74 20 74 6f 20 64 ue and what to d
14720 6f 20 69 66 20 74 68 65 79 20 61 72 65 20 6e 6f o if they are no
14730 74 2e 20 20 57 68 65 6e 20 49 6e 64 65 78 2e 6f t. When Index.o
14740 6e 45 72 72 6f 72 3d 4f 45 5f 4e 6f 6e 65 2c 0a nError=OE_None,.
14750 2a 2a 20 69 74 20 6d 65 61 6e 73 20 74 68 69 73 ** it means this
14760 20 69 73 20 6e 6f 74 20 61 20 75 6e 69 71 75 65 is not a unique
14770 20 69 6e 64 65 78 2e 20 20 4f 74 68 65 72 77 69 index. Otherwi
14780 73 65 20 69 74 20 69 73 20 61 20 75 6e 69 71 75 se it is a uniqu
14790 65 20 69 6e 64 65 78 0a 2a 2a 20 61 6e 64 20 74 e index.** and t
147a0 68 65 20 76 61 6c 75 65 20 6f 66 20 49 6e 64 65 he value of Inde
147b0 78 2e 6f 6e 45 72 72 6f 72 20 69 6e 64 69 63 61 x.onError indica
147c0 74 65 20 74 68 65 20 77 68 69 63 68 20 63 6f 6e te the which con
147d0 66 6c 69 63 74 20 72 65 73 6f 6c 75 74 69 6f 6e flict resolution
147e0 0a 2a 2a 20 61 6c 67 6f 72 69 74 68 6d 20 74 6f .** algorithm to
147f0 20 65 6d 70 6c 6f 79 20 77 68 65 6e 65 76 65 72 employ whenever
14800 20 61 6e 20 61 74 74 65 6d 70 74 20 69 73 20 6d an attempt is m
14810 61 64 65 20 74 6f 20 69 6e 73 65 72 74 20 61 20 ade to insert a
14820 6e 6f 6e 2d 75 6e 69 71 75 65 0a 2a 2a 20 65 6c non-unique.** el
14830 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 57 68 69 ement..**.** Whi
14840 6c 65 20 70 61 72 73 69 6e 67 20 61 20 43 52 45 le parsing a CRE
14850 41 54 45 20 54 41 42 4c 45 20 6f 72 20 43 52 45 ATE TABLE or CRE
14860 41 54 45 20 49 4e 44 45 58 20 73 74 61 74 65 6d ATE INDEX statem
14870 65 6e 74 20 69 6e 20 6f 72 64 65 72 20 74 6f 0a ent in order to.
14880 2a 2a 20 67 65 6e 65 72 61 74 65 20 56 44 42 45 ** generate VDBE
14890 20 63 6f 64 65 20 28 61 73 20 6f 70 70 6f 73 65 code (as oppose
148a0 64 20 74 6f 20 70 61 72 73 69 6e 67 20 6f 6e 65 d to parsing one
148b0 20 72 65 61 64 20 66 72 6f 6d 20 61 6e 20 73 71 read from an sq
148c0 6c 69 74 65 5f 6d 61 73 74 65 72 0a 2a 2a 20 74 lite_master.** t
148d0 61 62 6c 65 20 61 73 20 70 61 72 74 20 6f 66 20 able as part of
148e0 70 61 72 73 69 6e 67 20 61 6e 20 65 78 69 73 74 parsing an exist
148f0 69 6e 67 20 64 61 74 61 62 61 73 65 20 73 63 68 ing database sch
14900 65 6d 61 29 2c 20 74 72 61 6e 73 69 65 6e 74 20 ema), transient
14910 69 6e 73 74 61 6e 63 65 73 0a 2a 2a 20 6f 66 20 instances.** of
14920 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 6d this structure m
14930 61 79 20 62 65 20 63 72 65 61 74 65 64 2e 20 49 ay be created. I
14940 6e 20 74 68 69 73 20 63 61 73 65 20 74 68 65 20 n this case the
14950 49 6e 64 65 78 2e 74 6e 75 6d 20 76 61 72 69 61 Index.tnum varia
14960 62 6c 65 20 69 73 0a 2a 2a 20 75 73 65 64 20 74 ble is.** used t
14970 6f 20 73 74 6f 72 65 20 74 68 65 20 61 64 64 72 o store the addr
14980 65 73 73 20 6f 66 20 61 20 56 44 42 45 20 69 6e ess of a VDBE in
14990 73 74 72 75 63 74 69 6f 6e 2c 20 6e 6f 74 20 61 struction, not a
149a0 20 64 61 74 61 62 61 73 65 20 70 61 67 65 0a 2a database page.*
149b0 2a 20 6e 75 6d 62 65 72 20 28 69 74 20 63 61 6e * number (it can
149c0 6e 6f 74 20 2d 20 74 68 65 20 64 61 74 61 62 61 not - the databa
149d0 73 65 20 70 61 67 65 20 69 73 20 6e 6f 74 20 61 se page is not a
149e0 6c 6c 6f 63 61 74 65 64 20 75 6e 74 69 6c 20 74 llocated until t
149f0 68 65 20 56 44 42 45 0a 2a 2a 20 70 72 6f 67 72 he VDBE.** progr
14a00 61 6d 20 69 73 20 65 78 65 63 75 74 65 64 29 2e am is executed).
14a10 20 53 65 65 20 63 6f 6e 76 65 72 74 54 6f 57 69 See convertToWi
14a20 74 68 6f 75 74 52 6f 77 69 64 54 61 62 6c 65 28 thoutRowidTable(
14a30 29 20 66 6f 72 20 64 65 74 61 69 6c 73 2e 0a 2a ) for details..*
14a40 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 78 20 7b /.struct Index {
14a50 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
14a60 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
14a70 61 6d 65 20 6f 66 20 74 68 69 73 20 69 6e 64 65 ame of this inde
14a80 78 20 2a 2f 0a 20 20 69 31 36 20 2a 61 69 43 6f x */. i16 *aiCo
14a90 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 20 lumn;
14aa0 2f 2a 20 57 68 69 63 68 20 63 6f 6c 75 6d 6e 73 /* Which columns
14ab0 20 61 72 65 20 75 73 65 64 20 62 79 20 74 68 69 are used by thi
14ac0 73 20 69 6e 64 65 78 2e 20 20 31 73 74 20 69 73 s index. 1st is
14ad0 20 30 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 2a 0 */. LogEst *
14ae0 61 69 52 6f 77 4c 6f 67 45 73 74 3b 20 20 20 20 aiRowLogEst;
14af0 20 2f 2a 20 46 72 6f 6d 20 41 4e 41 4c 59 5a 45 /* From ANALYZE
14b00 3a 20 45 73 74 2e 20 72 6f 77 73 20 73 65 6c 65 : Est. rows sele
14b10 63 74 65 64 20 62 79 20 65 61 63 68 20 63 6f 6c cted by each col
14b20 75 6d 6e 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a umn */. Table *
14b30 70 54 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 pTable;
14b40 20 20 2f 2a 20 54 68 65 20 53 51 4c 20 74 61 62 /* The SQL tab
14b50 6c 65 20 62 65 69 6e 67 20 69 6e 64 65 78 65 64 le being indexed
14b60 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c */. char *zCol
14b70 41 66 66 3b 20 20 20 20 20 20 20 20 20 20 20 2f Aff; /
14b80 2a 20 53 74 72 69 6e 67 20 64 65 66 69 6e 69 6e * String definin
14b90 67 20 74 68 65 20 61 66 66 69 6e 69 74 79 20 6f g the affinity o
14ba0 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f f each column */
14bb0 0a 20 20 49 6e 64 65 78 20 2a 70 4e 65 78 74 3b . Index *pNext;
14bc0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
14bd0 68 65 20 6e 65 78 74 20 69 6e 64 65 78 20 61 73 he next index as
14be0 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 sociated with th
14bf0 65 20 73 61 6d 65 20 74 61 62 6c 65 20 2a 2f 0a e same table */.
14c00 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d Schema *pSchem
14c10 61 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 53 63 a; /* Sc
14c20 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 6e 67 20 hema containing
14c30 74 68 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 this index */.
14c40 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 72 3b 20 u8 *aSortOrder;
14c50 20 20 20 20 20 20 20 20 20 2f 2a 20 66 6f 72 20 /* for
14c60 65 61 63 68 20 63 6f 6c 75 6d 6e 3a 20 54 72 75 each column: Tru
14c70 65 3d 3d 44 45 53 43 2c 20 46 61 6c 73 65 3d 3d e==DESC, False==
14c80 41 53 43 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 ASC */. const c
14c90 68 61 72 20 2a 2a 61 7a 43 6f 6c 6c 3b 20 20 20 har **azColl;
14ca0 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 20 63 6f /* Array of co
14cb0 6c 6c 61 74 69 6f 6e 20 73 65 71 75 65 6e 63 65 llation sequence
14cc0 20 6e 61 6d 65 73 20 66 6f 72 20 69 6e 64 65 78 names for index
14cd0 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 50 61 72 */. Expr *pPar
14ce0 74 49 64 78 57 68 65 72 65 3b 20 20 20 20 20 2f tIdxWhere; /
14cf0 2a 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 66 * WHERE clause f
14d00 6f 72 20 70 61 72 74 69 61 6c 20 69 6e 64 69 63 or partial indic
14d10 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 es */. ExprList
14d20 20 2a 61 43 6f 6c 45 78 70 72 3b 20 20 20 20 20 *aColExpr;
14d30 20 2f 2a 20 43 6f 6c 75 6d 6e 20 65 78 70 72 65 /* Column expre
14d40 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 ssions */. int
14d50 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 20 20 tnum;
14d60 20 20 20 20 20 2f 2a 20 44 42 20 50 61 67 65 20 /* DB Page
14d70 63 6f 6e 74 61 69 6e 69 6e 67 20 72 6f 6f 74 20 containing root
14d80 6f 66 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f of this index */
14d90 0a 20 20 4c 6f 67 45 73 74 20 73 7a 49 64 78 52 . LogEst szIdxR
14da0 6f 77 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 45 ow; /* E
14db0 73 74 69 6d 61 74 65 64 20 61 76 65 72 61 67 65 stimated average
14dc0 20 72 6f 77 20 73 69 7a 65 20 69 6e 20 62 79 74 row size in byt
14dd0 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e 4b 65 79 es */. u16 nKey
14de0 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 Col;
14df0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f /* Number of co
14e00 6c 75 6d 6e 73 20 66 6f 72 6d 69 6e 67 20 74 68 lumns forming th
14e10 65 20 6b 65 79 20 2a 2f 0a 20 20 75 31 36 20 6e e key */. u16 n
14e20 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 Column;
14e30 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
14e40 20 63 6f 6c 75 6d 6e 73 20 73 74 6f 72 65 64 20 columns stored
14e50 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a in the index */.
14e60 20 20 75 38 20 6f 6e 45 72 72 6f 72 3b 20 20 20 u8 onError;
14e70 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 45 /* OE
14e80 5f 41 62 6f 72 74 2c 20 4f 45 5f 49 67 6e 6f 72 _Abort, OE_Ignor
14e90 65 2c 20 4f 45 5f 52 65 70 6c 61 63 65 2c 20 6f e, OE_Replace, o
14ea0 72 20 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a 20 20 75 r OE_None */. u
14eb0 6e 73 69 67 6e 65 64 20 69 64 78 54 79 70 65 3a nsigned idxType:
14ec0 32 3b 20 20 20 20 20 20 2f 2a 20 31 3d 3d 55 4e 2; /* 1==UN
14ed0 49 51 55 45 2c 20 32 3d 3d 50 52 49 4d 41 52 59 IQUE, 2==PRIMARY
14ee0 20 4b 45 59 2c 20 30 3d 3d 43 52 45 41 54 45 20 KEY, 0==CREATE
14ef0 49 4e 44 45 58 20 2a 2f 0a 20 20 75 6e 73 69 67 INDEX */. unsig
14f00 6e 65 64 20 62 55 6e 6f 72 64 65 72 65 64 3a 31 ned bUnordered:1
14f10 3b 20 20 20 2f 2a 20 55 73 65 20 74 68 69 73 20 ; /* Use this
14f20 69 6e 64 65 78 20 66 6f 72 20 3d 3d 20 6f 72 20 index for == or
14f30 49 4e 20 71 75 65 72 69 65 73 20 6f 6e 6c 79 20 IN queries only
14f40 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 75 6e */. unsigned un
14f50 69 71 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 20 2f 2a iqNotNull:1; /*
14f60 20 54 72 75 65 20 69 66 20 55 4e 49 51 55 45 20 True if UNIQUE
14f70 61 6e 64 20 4e 4f 54 20 4e 55 4c 4c 20 66 6f 72 and NOT NULL for
14f80 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a all columns */.
14f90 20 20 75 6e 73 69 67 6e 65 64 20 69 73 52 65 73 unsigned isRes
14fa0 69 7a 65 64 3a 31 3b 20 20 20 20 2f 2a 20 54 72 ized:1; /* Tr
14fb0 75 65 20 69 66 20 72 65 73 69 7a 65 49 6e 64 65 ue if resizeInde
14fc0 78 4f 62 6a 65 63 74 28 29 20 68 61 73 20 62 65 xObject() has be
14fd0 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 20 75 en called */. u
14fe0 6e 73 69 67 6e 65 64 20 69 73 43 6f 76 65 72 69 nsigned isCoveri
14ff0 6e 67 3a 31 3b 20 20 20 2f 2a 20 54 72 75 65 20 ng:1; /* True
15000 69 66 20 74 68 69 73 20 69 73 20 61 20 63 6f 76 if this is a cov
15010 65 72 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 ering index */.
15020 20 75 6e 73 69 67 6e 65 64 20 6e 6f 53 6b 69 70 unsigned noSkip
15030 53 63 61 6e 3a 31 3b 20 20 20 2f 2a 20 44 6f 20 Scan:1; /* Do
15040 6e 6f 74 20 74 72 79 20 74 6f 20 75 73 65 20 73 not try to use s
15050 6b 69 70 2d 73 63 61 6e 20 69 66 20 74 72 75 65 kip-scan if true
15060 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 */.#ifdef SQLIT
15070 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f E_ENABLE_STAT3_O
15080 52 5f 53 54 41 54 34 0a 20 20 69 6e 74 20 6e 53 R_STAT4. int nS
15090 61 6d 70 6c 65 3b 20 20 20 20 20 20 20 20 20 20 ample;
150a0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
150b0 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61 53 61 6d elements in aSam
150c0 70 6c 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e ple[] */. int n
150d0 53 61 6d 70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 SampleCol;
150e0 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 49 /* Size of I
150f0 6e 64 65 78 53 61 6d 70 6c 65 2e 61 6e 45 71 5b ndexSample.anEq[
15100 5d 20 61 6e 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 ] and so on */.
15110 20 74 52 6f 77 63 6e 74 20 2a 61 41 76 67 45 71 tRowcnt *aAvgEq
15120 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 76 65 ; /* Ave
15130 72 61 67 65 20 6e 45 71 20 76 61 6c 75 65 73 20 rage nEq values
15140 66 6f 72 20 6b 65 79 73 20 6e 6f 74 20 69 6e 20 for keys not in
15150 61 53 61 6d 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 aSample */. Ind
15160 65 78 53 61 6d 70 6c 65 20 2a 61 53 61 6d 70 6c exSample *aSampl
15170 65 3b 20 20 20 20 2f 2a 20 53 61 6d 70 6c 65 73 e; /* Samples
15180 20 6f 66 20 74 68 65 20 6c 65 66 74 2d 6d 6f 73 of the left-mos
15190 74 20 6b 65 79 20 2a 2f 0a 20 20 74 52 6f 77 63 t key */. tRowc
151a0 6e 74 20 2a 61 69 52 6f 77 45 73 74 3b 20 20 20 nt *aiRowEst;
151b0 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 /* Non-logar
151c0 69 74 68 6d 69 63 20 73 74 61 74 31 20 64 61 74 ithmic stat1 dat
151d0 61 20 66 6f 72 20 74 68 69 73 20 69 6e 64 65 78 a for this index
151e0 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 20 6e 52 */. tRowcnt nR
151f0 6f 77 45 73 74 30 3b 20 20 20 20 20 20 20 20 2f owEst0; /
15200 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 68 6d 69 * Non-logarithmi
15210 63 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 c number of rows
15220 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f in the index */
15230 0a 23 65 6e 64 69 66 0a 7d 3b 0a 0a 2f 2a 0a 2a .#endif.};../*.*
15240 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
15250 20 66 6f 72 20 49 6e 64 65 78 2e 69 64 78 54 79 for Index.idxTy
15260 70 65 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 pe.*/.#define SQ
15270 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 41 50 50 LITE_IDXTYPE_APP
15280 44 45 46 20 20 20 20 20 20 30 20 20 20 2f 2a 20 DEF 0 /*
15290 43 72 65 61 74 65 64 20 75 73 69 6e 67 20 43 52 Created using CR
152a0 45 41 54 45 20 49 4e 44 45 58 20 2a 2f 0a 23 64 EATE INDEX */.#d
152b0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 efine SQLITE_IDX
152c0 54 59 50 45 5f 55 4e 49 51 55 45 20 20 20 20 20 TYPE_UNIQUE
152d0 20 31 20 20 20 2f 2a 20 49 6d 70 6c 65 6d 65 6e 1 /* Implemen
152e0 74 73 20 61 20 55 4e 49 51 55 45 20 63 6f 6e 73 ts a UNIQUE cons
152f0 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 66 69 6e traint */.#defin
15300 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 e SQLITE_IDXTYPE
15310 5f 50 52 49 4d 41 52 59 4b 45 59 20 20 32 20 20 _PRIMARYKEY 2
15320 20 2f 2a 20 49 73 20 74 68 65 20 50 52 49 4d 41 /* Is the PRIMA
15330 52 59 20 4b 45 59 20 66 6f 72 20 74 68 65 20 74 RY KEY for the t
15340 61 62 6c 65 20 2a 2f 0a 0a 2f 2a 20 52 65 74 75 able */../* Retu
15350 72 6e 20 74 72 75 65 20 69 66 20 69 6e 64 65 78 rn true if index
15360 20 58 20 69 73 20 61 20 50 52 49 4d 41 52 59 20 X is a PRIMARY
15370 4b 45 59 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 KEY index */.#de
15380 66 69 6e 65 20 49 73 50 72 69 6d 61 72 79 4b 65 fine IsPrimaryKe
15390 79 49 6e 64 65 78 28 58 29 20 20 28 28 58 29 2d yIndex(X) ((X)-
153a0 3e 69 64 78 54 79 70 65 3d 3d 53 51 4c 49 54 45 >idxType==SQLITE
153b0 5f 49 44 58 54 59 50 45 5f 50 52 49 4d 41 52 59 _IDXTYPE_PRIMARY
153c0 4b 45 59 29 0a 0a 2f 2a 20 52 65 74 75 72 6e 20 KEY)../* Return
153d0 74 72 75 65 20 69 66 20 69 6e 64 65 78 20 58 20 true if index X
153e0 69 73 20 61 20 55 4e 49 51 55 45 20 69 6e 64 65 is a UNIQUE inde
153f0 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 55 x */.#define IsU
15400 6e 69 71 75 65 49 6e 64 65 78 28 58 29 20 20 20 niqueIndex(X)
15410 20 20 20 28 28 58 29 2d 3e 6f 6e 45 72 72 6f 72 ((X)->onError
15420 21 3d 4f 45 5f 4e 6f 6e 65 29 0a 0a 2f 2a 20 54 !=OE_None)../* T
15430 68 65 20 49 6e 64 65 78 2e 61 69 43 6f 6c 75 6d he Index.aiColum
15440 6e 5b 5d 20 76 61 6c 75 65 73 20 61 72 65 20 6e n[] values are n
15450 6f 72 6d 61 6c 6c 79 20 70 6f 73 69 74 69 76 65 ormally positive
15460 20 69 6e 74 65 67 65 72 2e 20 20 42 75 74 0a 2a integer. But.*
15470 2a 20 74 68 65 72 65 20 61 72 65 20 73 6f 6d 65 * there are some
15480 20 6e 65 67 61 74 69 76 65 20 76 61 6c 75 65 73 negative values
15490 20 74 68 61 74 20 68 61 76 65 20 73 70 65 63 69 that have speci
154a0 61 6c 20 6d 65 61 6e 69 6e 67 3a 0a 2a 2f 0a 23 al meaning:.*/.#
154b0 64 65 66 69 6e 65 20 58 4e 5f 52 4f 57 49 44 20 define XN_ROWID
154c0 20 20 20 20 28 2d 31 29 20 20 20 20 20 2f 2a 20 (-1) /*
154d0 49 6e 64 65 78 65 64 20 63 6f 6c 75 6d 6e 20 69 Indexed column i
154e0 73 20 74 68 65 20 72 6f 77 69 64 20 2a 2f 0a 23 s the rowid */.#
154f0 64 65 66 69 6e 65 20 58 4e 5f 45 58 50 52 20 20 define XN_EXPR
15500 20 20 20 20 28 2d 32 29 20 20 20 20 20 2f 2a 20 (-2) /*
15510 49 6e 64 65 78 65 64 20 63 6f 6c 75 6d 6e 20 69 Indexed column i
15520 73 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 s an expression
15530 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 73 */../*.** Each s
15540 61 6d 70 6c 65 20 73 74 6f 72 65 64 20 69 6e 20 ample stored in
15550 74 68 65 20 73 71 6c 69 74 65 5f 73 74 61 74 33 the sqlite_stat3
15560 20 74 61 62 6c 65 20 69 73 20 72 65 70 72 65 73 table is repres
15570 65 6e 74 65 64 20 69 6e 20 6d 65 6d 6f 72 79 0a ented in memory.
15580 2a 2a 20 75 73 69 6e 67 20 61 20 73 74 72 75 63 ** using a struc
15590 74 75 72 65 20 6f 66 20 74 68 69 73 20 74 79 70 ture of this typ
155a0 65 2e 20 20 53 65 65 20 64 6f 63 75 6d 65 6e 74 e. See document
155b0 61 74 69 6f 6e 20 61 74 20 74 68 65 20 74 6f 70 ation at the top
155c0 20 6f 66 20 74 68 65 0a 2a 2a 20 61 6e 61 6c 79 of the.** analy
155d0 7a 65 2e 63 20 73 6f 75 72 63 65 20 66 69 6c 65 ze.c source file
155e0 20 66 6f 72 20 61 64 64 69 74 69 6f 6e 61 6c 20 for additional
155f0 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a information..*/.
15600 73 74 72 75 63 74 20 49 6e 64 65 78 53 61 6d 70 struct IndexSamp
15610 6c 65 20 7b 0a 20 20 76 6f 69 64 20 2a 70 3b 20 le {. void *p;
15620 20 20 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e /* Poin
15630 74 65 72 20 74 6f 20 73 61 6d 70 6c 65 64 20 72 ter to sampled r
15640 65 63 6f 72 64 20 2a 2f 0a 20 20 69 6e 74 20 6e ecord */. int n
15650 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
15660 53 69 7a 65 20 6f 66 20 72 65 63 6f 72 64 20 69 Size of record i
15670 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 74 52 6f n bytes */. tRo
15680 77 63 6e 74 20 2a 61 6e 45 71 3b 20 20 20 20 2f wcnt *anEq; /
15690 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 * Est. number of
156a0 20 72 6f 77 73 20 77 68 65 72 65 20 74 68 65 20 rows where the
156b0 6b 65 79 20 65 71 75 61 6c 73 20 74 68 69 73 20 key equals this
156c0 73 61 6d 70 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 sample */. tRow
156d0 63 6e 74 20 2a 61 6e 4c 74 3b 20 20 20 20 2f 2a cnt *anLt; /*
156e0 20 45 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 Est. number of
156f0 72 6f 77 73 20 77 68 65 72 65 20 6b 65 79 20 69 rows where key i
15700 73 20 6c 65 73 73 20 74 68 61 6e 20 74 68 69 73 s less than this
15710 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 20 74 52 6f sample */. tRo
15720 77 63 6e 74 20 2a 61 6e 44 4c 74 3b 20 20 20 2f wcnt *anDLt; /
15730 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 * Est. number of
15740 20 64 69 73 74 69 6e 63 74 20 6b 65 79 73 20 6c distinct keys l
15750 65 73 73 20 74 68 61 6e 20 74 68 69 73 20 73 61 ess than this sa
15760 6d 70 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a mple */.};../*.*
15770 2a 20 45 61 63 68 20 74 6f 6b 65 6e 20 63 6f 6d * Each token com
15780 69 6e 67 20 6f 75 74 20 6f 66 20 74 68 65 20 6c ing out of the l
15790 65 78 65 72 20 69 73 20 61 6e 20 69 6e 73 74 61 exer is an insta
157a0 6e 63 65 20 6f 66 0a 2a 2a 20 74 68 69 73 20 73 nce of.** this s
157b0 74 72 75 63 74 75 72 65 2e 20 20 54 6f 6b 65 6e tructure. Token
157c0 73 20 61 72 65 20 61 6c 73 6f 20 75 73 65 64 20 s are also used
157d0 61 73 20 70 61 72 74 20 6f 66 20 61 6e 20 65 78 as part of an ex
157e0 70 72 65 73 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 pression..**.**
157f0 4e 6f 74 65 20 69 66 20 54 6f 6b 65 6e 2e 7a 3d Note if Token.z=
15800 3d 30 20 74 68 65 6e 20 54 6f 6b 65 6e 2e 64 79 =0 then Token.dy
15810 6e 20 61 6e 64 20 54 6f 6b 65 6e 2e 6e 20 61 72 n and Token.n ar
15820 65 20 75 6e 64 65 66 69 6e 65 64 20 61 6e 64 0a e undefined and.
15830 2a 2a 20 6d 61 79 20 63 6f 6e 74 61 69 6e 20 72 ** may contain r
15840 61 6e 64 6f 6d 20 76 61 6c 75 65 73 2e 20 20 44 andom values. D
15850 6f 20 6e 6f 74 20 6d 61 6b 65 20 61 6e 79 20 61 o not make any a
15860 73 73 75 6d 70 74 69 6f 6e 73 20 61 62 6f 75 74 ssumptions about
15870 20 54 6f 6b 65 6e 2e 64 79 6e 0a 2a 2a 20 61 6e Token.dyn.** an
15880 64 20 54 6f 6b 65 6e 2e 6e 20 77 68 65 6e 20 54 d Token.n when T
15890 6f 6b 65 6e 2e 7a 3d 3d 30 2e 0a 2a 2f 0a 73 74 oken.z==0..*/.st
158a0 72 75 63 74 20 54 6f 6b 65 6e 20 7b 0a 20 20 63 ruct Token {. c
158b0 6f 6e 73 74 20 63 68 61 72 20 2a 7a 3b 20 20 20 onst char *z;
158c0 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 74 68 65 /* Text of the
158d0 20 74 6f 6b 65 6e 2e 20 20 4e 6f 74 20 4e 55 4c token. Not NUL
158e0 4c 2d 74 65 72 6d 69 6e 61 74 65 64 21 20 2a 2f L-terminated! */
158f0 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 . unsigned int
15900 6e 3b 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 n; /* Number
15910 6f 66 20 63 68 61 72 61 63 74 65 72 73 20 69 6e of characters in
15920 20 74 68 69 73 20 74 6f 6b 65 6e 20 2a 2f 0a 7d this token */.}
15930 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 ;../*.** An inst
15940 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 ance of this str
15950 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 ucture contains
15960 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 information need
15970 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a ed to generate.*
15980 2a 20 63 6f 64 65 20 66 6f 72 20 61 20 53 45 4c * code for a SEL
15990 45 43 54 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ECT that contain
159a0 73 20 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 s aggregate func
159b0 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 tions..**.** If
159c0 45 78 70 72 2e 6f 70 3d 3d 54 4b 5f 41 47 47 5f Expr.op==TK_AGG_
159d0 43 4f 4c 55 4d 4e 20 6f 72 20 54 4b 5f 41 47 47 COLUMN or TK_AGG
159e0 5f 46 55 4e 43 54 49 4f 4e 20 74 68 65 6e 20 45 _FUNCTION then E
159f0 78 70 72 2e 70 41 67 67 49 6e 66 6f 20 69 73 20 xpr.pAggInfo is
15a00 61 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 74 6f 20 a.** pointer to
15a10 74 68 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 this structure.
15a20 20 54 68 65 20 45 78 70 72 2e 69 43 6f 6c 75 6d The Expr.iColum
15a30 6e 20 66 69 65 6c 64 20 69 73 20 74 68 65 20 69 n field is the i
15a40 6e 64 65 78 20 69 6e 0a 2a 2a 20 41 67 67 49 6e ndex in.** AggIn
15a50 66 6f 2e 61 43 6f 6c 5b 5d 20 6f 72 20 41 67 67 fo.aCol[] or Agg
15a60 49 6e 66 6f 2e 61 46 75 6e 63 5b 5d 20 6f 66 20 Info.aFunc[] of
15a70 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 information need
15a80 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a ed to generate.*
15a90 2a 20 63 6f 64 65 20 66 6f 72 20 74 68 61 74 20 * code for that
15aa0 6e 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 67 67 49 node..**.** AggI
15ab0 6e 66 6f 2e 70 47 72 6f 75 70 42 79 20 61 6e 64 nfo.pGroupBy and
15ac0 20 41 67 67 49 6e 66 6f 2e 61 46 75 6e 63 2e 70 AggInfo.aFunc.p
15ad0 45 78 70 72 20 70 6f 69 6e 74 20 74 6f 20 66 69 Expr point to fi
15ae0 65 6c 64 73 20 77 69 74 68 69 6e 20 74 68 65 0a elds within the.
15af0 2a 2a 20 6f 72 69 67 69 6e 61 6c 20 53 65 6c 65 ** original Sele
15b00 63 74 20 73 74 72 75 63 74 75 72 65 20 74 68 61 ct structure tha
15b10 74 20 64 65 73 63 72 69 62 65 73 20 74 68 65 20 t describes the
15b20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
15b30 2e 20 20 54 68 65 73 65 0a 2a 2a 20 66 69 65 6c . These.** fiel
15b40 64 73 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74 ds do not need t
15b50 6f 20 62 65 20 66 72 65 65 64 20 77 68 65 6e 20 o be freed when
15b60 64 65 61 6c 6c 6f 63 61 74 69 6e 67 20 74 68 65 deallocating the
15b70 20 41 67 67 49 6e 66 6f 20 73 74 72 75 63 74 75 AggInfo structu
15b80 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 67 re..*/.struct Ag
15b90 67 49 6e 66 6f 20 7b 0a 20 20 75 38 20 64 69 72 gInfo {. u8 dir
15ba0 65 63 74 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 ectMode;
15bb0 20 20 2f 2a 20 44 69 72 65 63 74 20 72 65 6e 64 /* Direct rend
15bc0 65 72 69 6e 67 20 6d 6f 64 65 20 6d 65 61 6e 73 ering mode means
15bd0 20 74 61 6b 65 20 64 61 74 61 20 64 69 72 65 63 take data direc
15be0 74 6c 79 0a 20 20 20 20 20 20 20 20 20 20 20 20 tly.
15bf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
15c00 20 66 72 6f 6d 20 73 6f 75 72 63 65 20 74 61 62 from source tab
15c10 6c 65 73 20 72 61 74 68 65 72 20 74 68 61 6e 20 les rather than
15c20 66 72 6f 6d 20 61 63 63 75 6d 75 6c 61 74 6f 72 from accumulator
15c30 73 20 2a 2f 0a 20 20 75 38 20 75 73 65 53 6f 72 s */. u8 useSor
15c40 74 69 6e 67 49 64 78 3b 20 20 20 20 20 20 20 2f tingIdx; /
15c50 2a 20 49 6e 20 64 69 72 65 63 74 20 6d 6f 64 65 * In direct mode
15c60 2c 20 72 65 66 65 72 65 6e 63 65 20 74 68 65 20 , reference the
15c70 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 72 61 sorting index ra
15c80 74 68 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 ther.
15c90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
15ca0 2a 20 74 68 61 6e 20 74 68 65 20 73 6f 75 72 63 * than the sourc
15cb0 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 e table */. int
15cc0 20 73 6f 72 74 69 6e 67 49 64 78 3b 20 20 20 20 sortingIdx;
15cd0 20 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e /* Cursor n
15ce0 75 6d 62 65 72 20 6f 66 20 74 68 65 20 73 6f 72 umber of the sor
15cf0 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 ting index */.
15d00 69 6e 74 20 73 6f 72 74 69 6e 67 49 64 78 50 54 int sortingIdxPT
15d10 61 62 3b 20 20 20 20 20 2f 2a 20 43 75 72 73 6f ab; /* Curso
15d20 72 20 6e 75 6d 62 65 72 20 6f 66 20 70 73 65 75 r number of pseu
15d30 64 6f 2d 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e do-table */. in
15d40 74 20 6e 53 6f 72 74 69 6e 67 43 6f 6c 75 6d 6e t nSortingColumn
15d50 3b 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 ; /* Number
15d60 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
15d70 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 e sorting index
15d80 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 67 2c 20 */. int mnReg,
15d90 6d 78 52 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 mxReg; /*
15da0 52 61 6e 67 65 20 6f 66 20 72 65 67 69 73 74 65 Range of registe
15db0 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 rs allocated for
15dc0 20 61 43 6f 6c 20 61 6e 64 20 61 46 75 6e 63 20 aCol and aFunc
15dd0 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
15de0 47 72 6f 75 70 42 79 3b 20 20 20 20 20 2f 2a 20 GroupBy; /*
15df0 54 68 65 20 67 72 6f 75 70 20 62 79 20 63 6c 61 The group by cla
15e00 75 73 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 use */. struct
15e10 41 67 67 49 6e 66 6f 5f 63 6f 6c 20 7b 20 20 20 AggInfo_col {
15e20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 63 6f 6c /* For each col
15e30 75 6d 6e 20 75 73 65 64 20 69 6e 20 73 6f 75 72 umn used in sour
15e40 63 65 20 74 61 62 6c 65 73 20 2a 2f 0a 20 20 20 ce tables */.
15e50 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 Table *pTab;
15e60 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 6f 75 /* Sou
15e70 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 rce table */.
15e80 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 int iTable;
15e90 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 /* Cur
15ea0 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 sor number of th
15eb0 65 20 73 6f 75 72 63 65 20 74 61 62 6c 65 20 2a e source table *
15ec0 2f 0a 20 20 20 20 69 6e 74 20 69 43 6f 6c 75 6d /. int iColum
15ed0 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f n; /
15ee0 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 * Column number
15ef0 77 69 74 68 69 6e 20 74 68 65 20 73 6f 75 72 63 within the sourc
15f00 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 e table */. i
15f10 6e 74 20 69 53 6f 72 74 65 72 43 6f 6c 75 6d 6e nt iSorterColumn
15f20 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d ; /* Colum
15f30 6e 20 6e 75 6d 62 65 72 20 69 6e 20 74 68 65 20 n number in the
15f40 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f sorting index */
15f50 0a 20 20 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 . int iMem;
15f60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
15f70 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e Memory location
15f80 20 74 68 61 74 20 61 63 74 73 20 61 73 20 61 63 that acts as ac
15f90 63 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 cumulator */.
15fa0 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 Expr *pExpr;
15fb0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 /* The
15fc0 20 6f 72 69 67 69 6e 61 6c 20 65 78 70 72 65 73 original expres
15fd0 73 69 6f 6e 20 2a 2f 0a 20 20 7d 20 2a 61 43 6f sion */. } *aCo
15fe0 6c 3b 0a 20 20 69 6e 74 20 6e 43 6f 6c 75 6d 6e l;. int nColumn
15ff0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
16000 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 64 20 65 Number of used e
16010 6e 74 72 69 65 73 20 69 6e 20 61 43 6f 6c 5b 5d ntries in aCol[]
16020 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 63 63 75 6d */. int nAccum
16030 75 6c 61 74 6f 72 3b 20 20 20 20 20 20 20 2f 2a ulator; /*
16040 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
16050 6e 73 20 74 68 61 74 20 73 68 6f 77 20 74 68 72 ns that show thr
16060 6f 75 67 68 20 74 6f 20 74 68 65 20 6f 75 74 70 ough to the outp
16070 75 74 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 ut..
16080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
16090 20 41 64 64 69 74 69 6f 6e 61 6c 20 63 6f 6c 75 Additional colu
160a0 6d 6e 73 20 61 72 65 20 75 73 65 64 20 6f 6e 6c mns are used onl
160b0 79 20 61 73 20 70 61 72 61 6d 65 74 65 72 73 20 y as parameters
160c0 74 6f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 to.
160d0 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
160e0 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 aggregate functi
160f0 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 ons */. struct
16100 41 67 67 49 6e 66 6f 5f 66 75 6e 63 20 7b 20 20 AggInfo_func {
16110 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 61 67 67 /* For each agg
16120 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 regate function
16130 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a 70 45 78 */. Expr *pEx
16140 70 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pr;
16150 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 65 6e /* Expression en
16160 63 6f 64 69 6e 67 20 74 68 65 20 66 75 6e 63 74 coding the funct
16170 69 6f 6e 20 2a 2f 0a 20 20 20 20 46 75 6e 63 44 ion */. FuncD
16180 65 66 20 2a 70 46 75 6e 63 3b 20 20 20 20 20 20 ef *pFunc;
16190 20 20 20 20 2f 2a 20 54 68 65 20 61 67 67 72 65 /* The aggre
161a0 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 69 6d gate function im
161b0 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a plementation */.
161c0 20 20 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 20 int iMem;
161d0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
161e0 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 Memory location
161f0 74 68 61 74 20 61 63 74 73 20 61 73 20 61 63 63 that acts as acc
16200 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 20 umulator */.
16210 69 6e 74 20 69 44 69 73 74 69 6e 63 74 3b 20 20 int iDistinct;
16220 20 20 20 20 20 20 20 20 20 2f 2a 20 45 70 68 65 /* Ephe
16230 6d 65 72 61 6c 20 74 61 62 6c 65 20 75 73 65 64 meral table used
16240 20 74 6f 20 65 6e 66 6f 72 63 65 20 44 49 53 54 to enforce DIST
16250 49 4e 43 54 20 2a 2f 0a 20 20 7d 20 2a 61 46 75 INCT */. } *aFu
16260 6e 63 3b 0a 20 20 69 6e 74 20 6e 46 75 6e 63 3b nc;. int nFunc;
16270 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
16280 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 Number of entri
16290 65 73 20 69 6e 20 61 46 75 6e 63 5b 5d 20 2a 2f es in aFunc[] */
162a0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 .};../*.** The d
162b0 61 74 61 74 79 70 65 20 79 6e 56 61 72 20 69 73 atatype ynVar is
162c0 20 61 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 a signed intege
162d0 72 2c 20 65 69 74 68 65 72 20 31 36 2d 62 69 74 r, either 16-bit
162e0 20 6f 72 20 33 32 2d 62 69 74 2e 0a 2a 2a 20 55 or 32-bit..** U
162f0 73 75 61 6c 6c 79 20 69 74 20 69 73 20 31 36 2d sually it is 16-
16300 62 69 74 73 2e 20 20 42 75 74 20 69 66 20 53 51 bits. But if SQ
16310 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c LITE_MAX_VARIABL
16320 45 5f 4e 55 4d 42 45 52 20 69 73 20 67 72 65 61 E_NUMBER is grea
16330 74 65 72 0a 2a 2a 20 74 68 61 6e 20 33 32 37 36 ter.** than 3276
16340 37 20 77 65 20 68 61 76 65 20 74 6f 20 6d 61 6b 7 we have to mak
16350 65 20 69 74 20 33 32 2d 62 69 74 2e 20 20 31 36 e it 32-bit. 16
16360 2d 62 69 74 20 69 73 20 70 72 65 66 65 72 72 65 -bit is preferre
16370 64 20 62 65 63 61 75 73 65 0a 2a 2a 20 69 74 20 d because.** it
16380 75 73 65 73 20 6c 65 73 73 20 6d 65 6d 6f 72 79 uses less memory
16390 20 69 6e 20 74 68 65 20 45 78 70 72 20 6f 62 6a in the Expr obj
163a0 65 63 74 2c 20 77 68 69 63 68 20 69 73 20 61 20 ect, which is a
163b0 62 69 67 20 6d 65 6d 6f 72 79 20 75 73 65 72 0a big memory user.
163c0 2a 2a 20 69 6e 20 73 79 73 74 65 6d 73 20 77 69 ** in systems wi
163d0 74 68 20 6c 6f 74 73 20 6f 66 20 70 72 65 70 61 th lots of prepa
163e0 72 65 64 20 73 74 61 74 65 6d 65 6e 74 73 2e 20 red statements.
163f0 20 41 6e 64 20 66 65 77 20 61 70 70 6c 69 63 61 And few applica
16400 74 69 6f 6e 73 0a 2a 2a 20 6e 65 65 64 20 6d 6f tions.** need mo
16410 72 65 20 74 68 61 6e 20 61 62 6f 75 74 20 31 30 re than about 10
16420 20 6f 72 20 32 30 20 76 61 72 69 61 62 6c 65 73 or 20 variables
16430 2e 20 20 42 75 74 20 73 6f 6d 65 20 65 78 74 72 . But some extr
16440 65 6d 65 20 75 73 65 72 73 20 77 61 6e 74 0a 2a eme users want.*
16450 2a 20 74 6f 20 68 61 76 65 20 70 72 65 70 61 72 * to have prepar
16460 65 64 20 73 74 61 74 65 6d 65 6e 74 73 20 77 69 ed statements wi
16470 74 68 20 6f 76 65 72 20 33 32 37 36 37 20 76 61 th over 32767 va
16480 72 69 61 62 6c 65 73 2c 20 61 6e 64 20 66 6f 72 riables, and for
16490 20 74 68 65 6d 0a 2a 2a 20 74 68 65 20 6f 70 74 them.** the opt
164a0 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 62 6c 65 ion is available
164b0 20 28 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d (at compile-tim
164c0 65 29 2e 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 54 e)..*/.#if SQLIT
164d0 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f 4e E_MAX_VARIABLE_N
164e0 55 4d 42 45 52 3c 3d 33 32 37 36 37 0a 74 79 70 UMBER<=32767.typ
164f0 65 64 65 66 20 69 31 36 20 79 6e 56 61 72 3b 0a edef i16 ynVar;.
16500 23 65 6c 73 65 0a 74 79 70 65 64 65 66 20 69 6e #else.typedef in
16510 74 20 79 6e 56 61 72 3b 0a 23 65 6e 64 69 66 0a t ynVar;.#endif.
16520 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 6e 6f 64 65 ./*.** Each node
16530 20 6f 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f of an expressio
16540 6e 20 69 6e 20 74 68 65 20 70 61 72 73 65 20 74 n in the parse t
16550 72 65 65 20 69 73 20 61 6e 20 69 6e 73 74 61 6e ree is an instan
16560 63 65 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 ce.** of this st
16570 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 45 ructure..**.** E
16580 78 70 72 2e 6f 70 20 69 73 20 74 68 65 20 6f 70 xpr.op is the op
16590 63 6f 64 65 2e 20 54 68 65 20 69 6e 74 65 67 65 code. The intege
165a0 72 20 70 61 72 73 65 72 20 74 6f 6b 65 6e 20 63 r parser token c
165b0 6f 64 65 73 20 61 72 65 20 72 65 75 73 65 64 0a odes are reused.
165c0 2a 2a 20 61 73 20 6f 70 63 6f 64 65 73 20 68 65 ** as opcodes he
165d0 72 65 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c re. For example,
165e0 20 74 68 65 20 70 61 72 73 65 72 20 64 65 66 69 the parser defi
165f0 6e 65 73 20 54 4b 5f 47 45 20 74 6f 20 62 65 20 nes TK_GE to be
16600 61 6e 20 69 6e 74 65 67 65 72 0a 2a 2a 20 63 6f an integer.** co
16610 64 65 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 de representing
16620 74 68 65 20 22 3e 3d 22 20 6f 70 65 72 61 74 6f the ">=" operato
16630 72 2e 20 54 68 69 73 20 73 61 6d 65 20 69 6e 74 r. This same int
16640 65 67 65 72 20 63 6f 64 65 20 69 73 20 72 65 75 eger code is reu
16650 73 65 64 0a 2a 2a 20 74 6f 20 72 65 70 72 65 73 sed.** to repres
16660 65 6e 74 20 74 68 65 20 67 72 65 61 74 65 72 2d ent the greater-
16670 74 68 61 6e 2d 6f 72 2d 65 71 75 61 6c 2d 74 6f than-or-equal-to
16680 20 6f 70 65 72 61 74 6f 72 20 69 6e 20 74 68 65 operator in the
16690 20 65 78 70 72 65 73 73 69 6f 6e 0a 2a 2a 20 74 expression.** t
166a0 72 65 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 ree..**.** If th
166b0 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 e expression is
166c0 61 6e 20 53 51 4c 20 6c 69 74 65 72 61 6c 20 28 an SQL literal (
166d0 54 4b 5f 49 4e 54 45 47 45 52 2c 20 54 4b 5f 46 TK_INTEGER, TK_F
166e0 4c 4f 41 54 2c 20 54 4b 5f 42 4c 4f 42 2c 0a 2a LOAT, TK_BLOB,.*
166f0 2a 20 6f 72 20 54 4b 5f 53 54 52 49 4e 47 29 2c * or TK_STRING),
16700 20 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e then Expr.token
16710 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 74 65 contains the te
16720 78 74 20 6f 66 20 74 68 65 20 53 51 4c 20 6c 69 xt of the SQL li
16730 74 65 72 61 6c 2e 20 49 66 0a 2a 2a 20 74 68 65 teral. If.** the
16740 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 expression is a
16750 20 76 61 72 69 61 62 6c 65 20 28 54 4b 5f 56 41 variable (TK_VA
16760 52 49 41 42 4c 45 29 2c 20 74 68 65 6e 20 45 78 RIABLE), then Ex
16770 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e pr.token contain
16780 73 20 74 68 65 0a 2a 2a 20 76 61 72 69 61 62 6c s the.** variabl
16790 65 20 6e 61 6d 65 2e 20 46 69 6e 61 6c 6c 79 2c e name. Finally,
167a0 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
167b0 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
167c0 63 74 69 6f 6e 20 28 54 4b 5f 46 55 4e 43 54 49 ction (TK_FUNCTI
167d0 4f 4e 29 2c 0a 2a 2a 20 74 68 65 6e 20 45 78 70 ON),.** then Exp
167e0 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 r.token contains
167f0 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 the name of the
16800 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a function..**.**
16810 20 45 78 70 72 2e 70 52 69 67 68 74 20 61 6e 64 Expr.pRight and
16820 20 45 78 70 72 2e 70 4c 65 66 74 20 61 72 65 20 Expr.pLeft are
16830 74 68 65 20 6c 65 66 74 20 61 6e 64 20 72 69 67 the left and rig
16840 68 74 20 73 75 62 65 78 70 72 65 73 73 69 6f 6e ht subexpression
16850 73 20 6f 66 20 61 0a 2a 2a 20 62 69 6e 61 72 79 s of a.** binary
16860 20 6f 70 65 72 61 74 6f 72 2e 20 45 69 74 68 65 operator. Eithe
16870 72 20 6f 72 20 62 6f 74 68 20 6d 61 79 20 62 65 r or both may be
16880 20 4e 55 4c 4c 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 NULL..**.** Exp
16890 72 2e 78 2e 70 4c 69 73 74 20 69 73 20 61 20 6c r.x.pList is a l
168a0 69 73 74 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ist of arguments
168b0 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
168c0 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
168d0 63 74 69 6f 6e 2c 0a 2a 2a 20 61 20 43 41 53 45 ction,.** a CASE
168e0 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 72 20 61 expression or a
168f0 6e 20 49 4e 20 65 78 70 72 65 73 73 69 6f 6e 20 n IN expression
16900 6f 66 20 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 of the form "<lh
16910 73 3e 20 49 4e 20 28 3c 79 3e 2c 20 3c 7a 3e 2e s> IN (<y>, <z>.
16920 2e 2e 29 22 2e 0a 2a 2a 20 45 78 70 72 2e 78 2e ..)"..** Expr.x.
16930 70 53 65 6c 65 63 74 20 69 73 20 75 73 65 64 20 pSelect is used
16940 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f if the expressio
16950 6e 20 69 73 20 61 20 73 75 62 2d 73 65 6c 65 63 n is a sub-selec
16960 74 20 6f 72 20 61 6e 20 65 78 70 72 65 73 73 69 t or an expressi
16970 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 66 6f 72 on of.** the for
16980 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 53 45 4c m "<lhs> IN (SEL
16990 45 43 54 20 2e 2e 2e 29 22 2e 20 49 66 20 74 68 ECT ...)". If th
169a0 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 62 e EP_xIsSelect b
169b0 69 74 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 it is set in the
169c0 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 73 20 6d .** Expr.flags m
169d0 61 73 6b 2c 20 74 68 65 6e 20 45 78 70 72 2e 78 ask, then Expr.x
169e0 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 .pSelect is vali
169f0 64 2e 20 4f 74 68 65 72 77 69 73 65 2c 20 45 78 d. Otherwise, Ex
16a00 70 72 2e 78 2e 70 4c 69 73 74 20 69 73 0a 2a 2a pr.x.pList is.**
16a10 20 76 61 6c 69 64 2e 0a 2a 2a 0a 2a 2a 20 41 6e valid..**.** An
16a20 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 74 expression of t
16a30 68 65 20 66 6f 72 6d 20 49 44 20 6f 72 20 49 44 he form ID or ID
16a40 2e 49 44 20 72 65 66 65 72 73 20 74 6f 20 61 20 .ID refers to a
16a50 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 74 61 62 6c column in a tabl
16a60 65 2e 0a 2a 2a 20 46 6f 72 20 73 75 63 68 20 65 e..** For such e
16a70 78 70 72 65 73 73 69 6f 6e 73 2c 20 45 78 70 72 xpressions, Expr
16a80 2e 6f 70 20 69 73 20 73 65 74 20 74 6f 20 54 4b .op is set to TK
16a90 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 45 78 70 72 _COLUMN and Expr
16aa0 2e 69 54 61 62 6c 65 20 69 73 0a 2a 2a 20 74 68 .iTable is.** th
16ab0 65 20 69 6e 74 65 67 65 72 20 63 75 72 73 6f 72 e integer cursor
16ac0 20 6e 75 6d 62 65 72 20 6f 66 20 61 20 56 44 42 number of a VDB
16ad0 45 20 63 75 72 73 6f 72 20 70 6f 69 6e 74 69 6e E cursor pointin
16ae0 67 20 74 6f 20 74 68 61 74 20 74 61 62 6c 65 20 g to that table
16af0 61 6e 64 0a 2a 2a 20 45 78 70 72 2e 69 43 6f 6c and.** Expr.iCol
16b00 75 6d 6e 20 69 73 20 74 68 65 20 63 6f 6c 75 6d umn is the colum
16b10 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 65 n number for the
16b20 20 73 70 65 63 69 66 69 63 20 63 6f 6c 75 6d 6e specific column
16b30 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 65 78 70 . If the.** exp
16b40 72 65 73 73 69 6f 6e 20 69 73 20 75 73 65 64 20 ression is used
16b50 61 73 20 61 20 72 65 73 75 6c 74 20 69 6e 20 61 as a result in a
16b60 6e 20 61 67 67 72 65 67 61 74 65 20 53 45 4c 45 n aggregate SELE
16b70 43 54 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a 20 CT, then the.**
16b80 76 61 6c 75 65 20 69 73 20 61 6c 73 6f 20 73 74 value is also st
16b90 6f 72 65 64 20 69 6e 20 74 68 65 20 45 78 70 72 ored in the Expr
16ba0 2e 69 41 67 67 20 63 6f 6c 75 6d 6e 20 69 6e 20 .iAgg column in
16bb0 74 68 65 20 61 67 67 72 65 67 61 74 65 20 73 6f the aggregate so
16bc0 20 74 68 61 74 0a 2a 2a 20 69 74 20 63 61 6e 20 that.** it can
16bd0 62 65 20 61 63 63 65 73 73 65 64 20 61 66 74 65 be accessed afte
16be0 72 20 61 6c 6c 20 61 67 67 72 65 67 61 74 65 73 r all aggregates
16bf0 20 61 72 65 20 63 6f 6d 70 75 74 65 64 2e 0a 2a are computed..*
16c00 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 *.** If the expr
16c10 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 75 6e 62 ession is an unb
16c20 6f 75 6e 64 20 76 61 72 69 61 62 6c 65 20 6d 61 ound variable ma
16c30 72 6b 65 72 20 28 61 20 71 75 65 73 74 69 6f 6e rker (a question
16c40 20 6d 61 72 6b 0a 2a 2a 20 63 68 61 72 61 63 74 mark.** charact
16c50 65 72 20 27 3f 27 20 69 6e 20 74 68 65 20 6f 72 er '?' in the or
16c60 69 67 69 6e 61 6c 20 53 51 4c 29 20 74 68 65 6e iginal SQL) then
16c70 20 74 68 65 20 45 78 70 72 2e 69 54 61 62 6c 65 the Expr.iTable
16c80 20 68 6f 6c 64 73 20 74 68 65 20 69 6e 64 65 78 holds the index
16c90 0a 2a 2a 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 .** number for t
16ca0 68 61 74 20 76 61 72 69 61 62 6c 65 2e 0a 2a 2a hat variable..**
16cb0 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 72 65 .** If the expre
16cc0 73 73 69 6f 6e 20 69 73 20 61 20 73 75 62 71 75 ssion is a subqu
16cd0 65 72 79 20 74 68 65 6e 20 45 78 70 72 2e 69 43 ery then Expr.iC
16ce0 6f 6c 75 6d 6e 20 68 6f 6c 64 73 20 61 6e 20 69 olumn holds an i
16cf0 6e 74 65 67 65 72 0a 2a 2a 20 72 65 67 69 73 74 nteger.** regist
16d00 65 72 20 6e 75 6d 62 65 72 20 63 6f 6e 74 61 69 er number contai
16d10 6e 69 6e 67 20 74 68 65 20 72 65 73 75 6c 74 20 ning the result
16d20 6f 66 20 74 68 65 20 73 75 62 71 75 65 72 79 2e of the subquery.
16d30 20 20 49 66 20 74 68 65 0a 2a 2a 20 73 75 62 71 If the.** subq
16d40 75 65 72 79 20 67 69 76 65 73 20 61 20 63 6f 6e uery gives a con
16d50 73 74 61 6e 74 20 72 65 73 75 6c 74 2c 20 74 68 stant result, th
16d60 65 6e 20 69 54 61 62 6c 65 20 69 73 20 2d 31 2e en iTable is -1.
16d70 20 20 49 66 20 74 68 65 20 73 75 62 71 75 65 72 If the subquer
16d80 79 0a 2a 2a 20 67 69 76 65 73 20 61 20 64 69 66 y.** gives a dif
16d90 66 65 72 65 6e 74 20 61 6e 73 77 65 72 20 61 74 ferent answer at
16da0 20 64 69 66 66 65 72 65 6e 74 20 74 69 6d 65 73 different times
16db0 20 64 75 72 69 6e 67 20 73 74 61 74 65 6d 65 6e during statemen
16dc0 74 20 70 72 6f 63 65 73 73 69 6e 67 0a 2a 2a 20 t processing.**
16dd0 74 68 65 6e 20 69 54 61 62 6c 65 20 69 73 20 74 then iTable is t
16de0 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 61 20 he address of a
16df0 73 75 62 72 6f 75 74 69 6e 65 20 74 68 61 74 20 subroutine that
16e00 63 6f 6d 70 75 74 65 73 20 74 68 65 20 73 75 62 computes the sub
16e10 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 query..**.** If
16e20 74 68 65 20 45 78 70 72 20 69 73 20 6f 66 20 74 the Expr is of t
16e30 79 70 65 20 4f 50 5f 43 6f 6c 75 6d 6e 2c 20 61 ype OP_Column, a
16e40 6e 64 20 74 68 65 20 74 61 62 6c 65 20 69 74 20 nd the table it
16e50 69 73 20 73 65 6c 65 63 74 69 6e 67 20 66 72 6f is selecting fro
16e60 6d 0a 2a 2a 20 69 73 20 61 20 64 69 73 6b 20 74 m.** is a disk t
16e70 61 62 6c 65 20 6f 72 20 74 68 65 20 22 6f 6c 64 able or the "old
16e80 2e 2a 22 20 70 73 65 75 64 6f 2d 74 61 62 6c 65 .*" pseudo-table
16e90 2c 20 74 68 65 6e 20 70 54 61 62 20 70 6f 69 6e , then pTab poin
16ea0 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 63 6f 72 ts to the.** cor
16eb0 72 65 73 70 6f 6e 64 69 6e 67 20 74 61 62 6c 65 responding table
16ec0 20 64 65 66 69 6e 69 74 69 6f 6e 2e 0a 2a 2a 0a definition..**.
16ed0 2a 2a 20 41 4c 4c 4f 43 41 54 49 4f 4e 20 4e 4f ** ALLOCATION NO
16ee0 54 45 53 3a 0a 2a 2a 0a 2a 2a 20 45 78 70 72 20 TES:.**.** Expr
16ef0 6f 62 6a 65 63 74 73 20 63 61 6e 20 75 73 65 20 objects can use
16f00 61 20 6c 6f 74 20 6f 66 20 6d 65 6d 6f 72 79 20 a lot of memory
16f10 73 70 61 63 65 20 69 6e 20 64 61 74 61 62 61 73 space in databas
16f20 65 20 73 63 68 65 6d 61 2e 20 20 54 6f 0a 2a 2a e schema. To.**
16f30 20 68 65 6c 70 20 72 65 64 75 63 65 20 6d 65 6d help reduce mem
16f40 6f 72 79 20 72 65 71 75 69 72 65 6d 65 6e 74 73 ory requirements
16f50 2c 20 73 6f 6d 65 74 69 6d 65 73 20 61 6e 20 45 , sometimes an E
16f60 78 70 72 20 6f 62 6a 65 63 74 20 77 69 6c 6c 20 xpr object will
16f70 62 65 0a 2a 2a 20 74 72 75 6e 63 61 74 65 64 2e be.** truncated.
16f80 20 20 41 6e 64 20 74 6f 20 72 65 64 75 63 65 20 And to reduce
16f90 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 6d 65 the number of me
16fa0 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 mory allocations
16fb0 2c 20 73 6f 6d 65 74 69 6d 65 73 0a 2a 2a 20 74 , sometimes.** t
16fc0 77 6f 20 6f 72 20 6d 6f 72 65 20 45 78 70 72 20 wo or more Expr
16fd0 6f 62 6a 65 63 74 73 20 77 69 6c 6c 20 62 65 20 objects will be
16fe0 73 74 6f 72 65 64 20 69 6e 20 61 20 73 69 6e 67 stored in a sing
16ff0 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 le memory alloca
17000 74 69 6f 6e 2c 0a 2a 2a 20 74 6f 67 65 74 68 65 tion,.** togethe
17010 72 20 77 69 74 68 20 45 78 70 72 2e 7a 54 6f 6b r with Expr.zTok
17020 65 6e 20 73 74 72 69 6e 67 73 2e 0a 2a 2a 0a 2a en strings..**.*
17030 2a 20 49 66 20 74 68 65 20 45 50 5f 52 65 64 75 * If the EP_Redu
17040 63 65 64 20 61 6e 64 20 45 50 5f 54 6f 6b 65 6e ced and EP_Token
17050 4f 6e 6c 79 20 66 6c 61 67 73 20 61 72 65 20 73 Only flags are s
17060 65 74 20 77 68 65 6e 0a 2a 2a 20 61 6e 20 45 78 et when.** an Ex
17070 70 72 20 6f 62 6a 65 63 74 20 69 73 20 74 72 75 pr object is tru
17080 6e 63 61 74 65 64 2e 20 20 57 68 65 6e 20 45 50 ncated. When EP
17090 5f 52 65 64 75 63 65 64 20 69 73 20 73 65 74 2c _Reduced is set,
170a0 20 74 68 65 6e 20 61 6c 6c 0a 2a 2a 20 74 68 65 then all.** the
170b0 20 63 68 69 6c 64 20 45 78 70 72 20 6f 62 6a 65 child Expr obje
170c0 63 74 73 20 69 6e 20 74 68 65 20 45 78 70 72 2e cts in the Expr.
170d0 70 4c 65 66 74 20 61 6e 64 20 45 78 70 72 2e 70 pLeft and Expr.p
170e0 52 69 67 68 74 20 73 75 62 74 72 65 65 73 0a 2a Right subtrees.*
170f0 2a 20 61 72 65 20 63 6f 6e 74 61 69 6e 65 64 20 * are contained
17100 77 69 74 68 69 6e 20 74 68 65 20 73 61 6d 65 20 within the same
17110 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f memory allocatio
17120 6e 2e 20 20 4e 6f 74 65 2c 20 68 6f 77 65 76 65 n. Note, howeve
17130 72 2c 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 73 r, that.** the s
17140 75 62 74 72 65 65 73 20 69 6e 20 45 78 70 72 2e ubtrees in Expr.
17150 78 2e 70 4c 69 73 74 20 6f 72 20 45 78 70 72 2e x.pList or Expr.
17160 78 2e 70 53 65 6c 65 63 74 20 61 72 65 20 61 6c x.pSelect are al
17170 77 61 79 73 20 73 65 70 61 72 61 74 65 6c 79 0a ways separately.
17180 2a 2a 20 61 6c 6c 6f 63 61 74 65 64 2c 20 72 65 ** allocated, re
17190 67 61 72 64 6c 65 73 73 20 6f 66 20 77 68 65 74 gardless of whet
171a0 68 65 72 20 6f 72 20 6e 6f 74 20 45 50 5f 52 65 her or not EP_Re
171b0 64 75 63 65 64 20 69 73 20 73 65 74 2e 0a 2a 2f duced is set..*/
171c0 0a 73 74 72 75 63 74 20 45 78 70 72 20 7b 0a 20 .struct Expr {.
171d0 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 u8 op;
171e0 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 65 72 61 /* Opera
171f0 74 69 6f 6e 20 70 65 72 66 6f 72 6d 65 64 20 62 tion performed b
17200 79 20 74 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 20 y this node */.
17210 20 63 68 61 72 20 61 66 66 69 6e 69 74 79 3b 20 char affinity;
17220 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 61 /* The a
17230 66 66 69 6e 69 74 79 20 6f 66 20 74 68 65 20 63 ffinity of the c
17240 6f 6c 75 6d 6e 20 6f 72 20 30 20 69 66 20 6e 6f olumn or 0 if no
17250 74 20 61 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 t a column */.
17260 75 33 32 20 66 6c 61 67 73 3b 20 20 20 20 20 20 u32 flags;
17270 20 20 20 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 /* Variou
17280 73 20 66 6c 61 67 73 2e 20 20 45 50 5f 2a 20 53 s flags. EP_* S
17290 65 65 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 75 6e ee below */. un
172a0 69 6f 6e 20 7b 0a 20 20 20 20 63 68 61 72 20 2a ion {. char *
172b0 7a 54 6f 6b 65 6e 3b 20 20 20 20 20 20 20 20 20 zToken;
172c0 20 2f 2a 20 54 6f 6b 65 6e 20 76 61 6c 75 65 2e /* Token value.
172d0 20 5a 65 72 6f 20 74 65 72 6d 69 6e 61 74 65 64 Zero terminated
172e0 20 61 6e 64 20 64 65 71 75 6f 74 65 64 20 2a 2f and dequoted */
172f0 0a 20 20 20 20 69 6e 74 20 69 56 61 6c 75 65 3b . int iValue;
17300 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
17310 6f 6e 2d 6e 65 67 61 74 69 76 65 20 69 6e 74 65 on-negative inte
17320 67 65 72 20 76 61 6c 75 65 20 69 66 20 45 50 5f ger value if EP_
17330 49 6e 74 56 61 6c 75 65 20 2a 2f 0a 20 20 7d 20 IntValue */. }
17340 75 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 68 65 20 u;.. /* If the
17350 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 EP_TokenOnly fla
17360 67 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 20 g is set in the
17370 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 6b 2c Expr.flags mask,
17380 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 73 70 then no. ** sp
17390 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 ace is allocated
173a0 20 66 6f 72 20 74 68 65 20 66 69 65 6c 64 73 20 for the fields
173b0 62 65 6c 6f 77 20 74 68 69 73 20 70 6f 69 6e 74 below this point
173c0 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 74 6f 0a . An attempt to.
173d0 20 20 2a 2a 20 61 63 63 65 73 73 20 74 68 65 6d ** access them
173e0 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 will result in
173f0 61 20 73 65 67 66 61 75 6c 74 20 6f 72 20 6d 61 a segfault or ma
17400 6c 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 2a 2a 2a lfunction.. ***
17410 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17420 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17430 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17440 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17450 2a 2a 2f 0a 0a 20 20 45 78 70 72 20 2a 70 4c 65 **/.. Expr *pLe
17460 66 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ft; /*
17470 20 4c 65 66 74 20 73 75 62 6e 6f 64 65 20 2a 2f Left subnode */
17480 0a 20 20 45 78 70 72 20 2a 70 52 69 67 68 74 3b . Expr *pRight;
17490 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 69 67 /* Rig
174a0 68 74 20 73 75 62 6e 6f 64 65 20 2a 2f 0a 20 20 ht subnode */.
174b0 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 45 78 70 72 union {. Expr
174c0 4c 69 73 74 20 2a 70 4c 69 73 74 3b 20 20 20 20 List *pList;
174d0 20 2f 2a 20 6f 70 20 3d 20 49 4e 2c 20 45 58 49 /* op = IN, EXI
174e0 53 54 53 2c 20 53 45 4c 45 43 54 2c 20 43 41 53 STS, SELECT, CAS
174f0 45 2c 20 46 55 4e 43 54 49 4f 4e 2c 20 42 45 54 E, FUNCTION, BET
17500 57 45 45 4e 20 2a 2f 0a 20 20 20 20 53 65 6c 65 WEEN */. Sele
17510 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 ct *pSelect;
17520 20 2f 2a 20 45 50 5f 78 49 73 53 65 6c 65 63 74 /* EP_xIsSelect
17530 20 61 6e 64 20 6f 70 20 3d 20 49 4e 2c 20 45 58 and op = IN, EX
17540 49 53 54 53 2c 20 53 45 4c 45 43 54 20 2a 2f 0a ISTS, SELECT */.
17550 20 20 7d 20 78 3b 0a 0a 20 20 2f 2a 20 49 66 20 } x;.. /* If
17560 74 68 65 20 45 50 5f 52 65 64 75 63 65 64 20 66 the EP_Reduced f
17570 6c 61 67 20 69 73 20 73 65 74 20 69 6e 20 74 68 lag is set in th
17580 65 20 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 73 e Expr.flags mas
17590 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a 20 k, then no. **
175a0 73 70 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 74 space is allocat
175b0 65 64 20 66 6f 72 20 74 68 65 20 66 69 65 6c 64 ed for the field
175c0 73 20 62 65 6c 6f 77 20 74 68 69 73 20 70 6f 69 s below this poi
175d0 6e 74 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 74 nt. An attempt t
175e0 6f 0a 20 20 2a 2a 20 61 63 63 65 73 73 20 74 68 o. ** access th
175f0 65 6d 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 em will result i
17600 6e 20 61 20 73 65 67 66 61 75 6c 74 20 6f 72 20 n a segfault or
17610 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 2a malfunction.. *
17620 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17630 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17640 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17650 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
17660 2a 2a 2a 2a 2f 0a 0a 23 69 66 20 53 51 4c 49 54 ****/..#if SQLIT
17670 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 E_MAX_EXPR_DEPTH
17680 3e 30 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 74 >0. int nHeight
17690 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 ; /* H
176a0 65 69 67 68 74 20 6f 66 20 74 68 65 20 74 72 65 eight of the tre
176b0 65 20 68 65 61 64 65 64 20 62 79 20 74 68 69 73 e headed by this
176c0 20 6e 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a node */.#endif.
176d0 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 int iTable;
176e0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 43 /* TK_C
176f0 4f 4c 55 4d 4e 3a 20 63 75 72 73 6f 72 20 6e 75 OLUMN: cursor nu
17700 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 20 68 6f mber of table ho
17710 6c 64 69 6e 67 20 63 6f 6c 75 6d 6e 0a 20 20 20 lding column.
17720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17730 20 20 20 20 20 20 2a 2a 20 54 4b 5f 52 45 47 49 ** TK_REGI
17740 53 54 45 52 3a 20 72 65 67 69 73 74 65 72 20 6e STER: register n
17750 75 6d 62 65 72 0a 20 20 20 20 20 20 20 20 20 20 umber.
17760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
17770 2a 20 54 4b 5f 54 52 49 47 47 45 52 3a 20 31 20 * TK_TRIGGER: 1
17780 2d 3e 20 6e 65 77 2c 20 30 20 2d 3e 20 6f 6c 64 -> new, 0 -> old
17790 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
177a0 20 20 20 20 20 20 20 20 20 20 2a 2a 20 45 50 5f ** EP_
177b0 55 6e 6c 69 6b 65 6c 79 3a 20 20 31 33 34 32 31 Unlikely: 13421
177c0 37 37 32 38 20 74 69 6d 65 73 20 6c 69 6b 65 6c 7728 times likel
177d0 69 68 6f 6f 64 0a 20 20 20 20 20 20 20 20 20 20 ihood.
177e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
177f0 2a 20 54 4b 5f 53 45 4c 45 43 54 3a 20 31 73 74 * TK_SELECT: 1st
17800 20 72 65 67 69 73 74 65 72 20 6f 66 20 72 65 73 register of res
17810 75 6c 74 20 76 65 63 74 6f 72 20 2a 2f 0a 20 20 ult vector */.
17820 79 6e 56 61 72 20 69 43 6f 6c 75 6d 6e 3b 20 20 ynVar iColumn;
17830 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 43 4f 4c /* TK_COL
17840 55 4d 4e 3a 20 63 6f 6c 75 6d 6e 20 69 6e 64 65 UMN: column inde
17850 78 2e 20 20 2d 31 20 66 6f 72 20 72 6f 77 69 64 x. -1 for rowid
17860 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
17870 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b ** TK
17880 5f 56 41 52 49 41 42 4c 45 3a 20 76 61 72 69 61 _VARIABLE: varia
17890 62 6c 65 20 6e 75 6d 62 65 72 20 28 61 6c 77 61 ble number (alwa
178a0 79 73 20 3e 3d 20 31 29 2e 0a 20 20 20 20 20 20 ys >= 1)..
178b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
178c0 20 20 20 2a 2a 20 54 4b 5f 53 45 4c 45 43 54 5f ** TK_SELECT_
178d0 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d 6e 20 6f COLUMN: column o
178e0 66 20 74 68 65 20 72 65 73 75 6c 74 20 76 65 63 f the result vec
178f0 74 6f 72 20 2a 2f 0a 20 20 69 31 36 20 69 41 67 tor */. i16 iAg
17900 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
17910 2f 2a 20 57 68 69 63 68 20 65 6e 74 72 79 20 69 /* Which entry i
17920 6e 20 70 41 67 67 49 6e 66 6f 2d 3e 61 43 6f 6c n pAggInfo->aCol
17930 5b 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 5b 5d 20 [] or ->aFunc[]
17940 2a 2f 0a 20 20 69 31 36 20 69 52 69 67 68 74 4a */. i16 iRightJ
17950 6f 69 6e 54 61 62 6c 65 3b 20 20 20 2f 2a 20 49 oinTable; /* I
17960 66 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 2c 20 74 f EP_FromJoin, t
17970 68 65 20 72 69 67 68 74 20 74 61 62 6c 65 20 6f he right table o
17980 66 20 74 68 65 20 6a 6f 69 6e 20 2a 2f 0a 20 20 f the join */.
17990 75 38 20 6f 70 32 3b 20 20 20 20 20 20 20 20 20 u8 op2;
179a0 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 52 45 47 /* TK_REG
179b0 49 53 54 45 52 3a 20 6f 72 69 67 69 6e 61 6c 20 ISTER: original
179c0 76 61 6c 75 65 20 6f 66 20 45 78 70 72 2e 6f 70 value of Expr.op
179d0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
179e0 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f ** TK_
179f0 43 4f 4c 55 4d 4e 3a 20 74 68 65 20 76 61 6c 75 COLUMN: the valu
17a00 65 20 6f 66 20 70 35 20 66 6f 72 20 4f 50 5f 43 e of p5 for OP_C
17a10 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 20 olumn.
17a20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
17a30 2a 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f * TK_AGG_FUNCTIO
17a40 4e 3a 20 6e 65 73 74 69 6e 67 20 64 65 70 74 68 N: nesting depth
17a50 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 */. AggInfo *p
17a60 41 67 67 49 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 AggInfo; /*
17a70 55 73 65 64 20 62 79 20 54 4b 5f 41 47 47 5f 43 Used by TK_AGG_C
17a80 4f 4c 55 4d 4e 20 61 6e 64 20 54 4b 5f 41 47 47 OLUMN and TK_AGG
17a90 5f 46 55 4e 43 54 49 4f 4e 20 2a 2f 0a 20 20 54 _FUNCTION */. T
17aa0 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 able *pTab;
17ab0 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 66 /* Table f
17ac0 6f 72 20 54 4b 5f 43 4f 4c 55 4d 4e 20 65 78 70 or TK_COLUMN exp
17ad0 72 65 73 73 69 6f 6e 73 2e 20 2a 2f 0a 7d 3b 0a ressions. */.};.
17ae0 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
17af0 77 69 6e 67 20 61 72 65 20 74 68 65 20 6d 65 61 wing are the mea
17b00 6e 69 6e 67 73 20 6f 66 20 62 69 74 73 20 69 6e nings of bits in
17b10 20 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 the Expr.flags
17b20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e field..*/.#defin
17b30 65 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 20 30 e EP_FromJoin 0
17b40 78 30 30 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 x000001 /* Origi
17b50 6e 61 74 65 73 20 69 6e 20 4f 4e 2f 55 53 49 4e nates in ON/USIN
17b60 47 20 63 6c 61 75 73 65 20 6f 66 20 6f 75 74 65 G clause of oute
17b70 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e r join */.#defin
17b80 65 20 45 50 5f 41 67 67 20 20 20 20 20 20 20 30 e EP_Agg 0
17b90 78 30 30 30 30 30 32 20 2f 2a 20 43 6f 6e 74 61 x000002 /* Conta
17ba0 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 ins one or more
17bb0 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 aggregate functi
17bc0 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ons */.#define E
17bd0 50 5f 52 65 73 6f 6c 76 65 64 20 20 30 78 30 30 P_Resolved 0x00
17be0 30 30 30 34 20 2f 2a 20 49 44 73 20 68 61 76 65 0004 /* IDs have
17bf0 20 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 74 been resolved t
17c00 6f 20 43 4f 4c 55 4d 4e 73 20 2a 2f 0a 23 64 65 o COLUMNs */.#de
17c10 66 69 6e 65 20 45 50 5f 45 72 72 6f 72 20 20 20 fine EP_Error
17c20 20 20 30 78 30 30 30 30 30 38 20 2f 2a 20 45 78 0x000008 /* Ex
17c30 70 72 65 73 73 69 6f 6e 20 63 6f 6e 74 61 69 6e pression contain
17c40 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 65 72 s one or more er
17c50 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 rors */.#define
17c60 45 50 5f 44 69 73 74 69 6e 63 74 20 20 30 78 30 EP_Distinct 0x0
17c70 30 30 30 31 30 20 2f 2a 20 41 67 67 72 65 67 61 00010 /* Aggrega
17c80 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 te function with
17c90 20 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 DISTINCT keywor
17ca0 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f d */.#define EP_
17cb0 56 61 72 53 65 6c 65 63 74 20 30 78 30 30 30 30 VarSelect 0x0000
17cc0 32 30 20 2f 2a 20 70 53 65 6c 65 63 74 20 69 73 20 /* pSelect is
17cd0 20 63 6f 72 72 65 6c 61 74 65 64 2c 20 6e 6f 74 correlated, not
17ce0 20 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a 23 64 65 constant */.#de
17cf0 66 69 6e 65 20 45 50 5f 44 62 6c 51 75 6f 74 65 fine EP_DblQuote
17d00 64 20 30 78 30 30 30 30 34 30 20 2f 2a 20 74 6f d 0x000040 /* to
17d10 6b 65 6e 2e 7a 20 77 61 73 20 6f 72 69 67 69 6e ken.z was origin
17d20 61 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 20 2a 2f ally in "..." */
17d30 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 6e 66 69 .#define EP_Infi
17d40 78 46 75 6e 63 20 30 78 30 30 30 30 38 30 20 2f xFunc 0x000080 /
17d50 2a 20 54 72 75 65 20 66 6f 72 20 61 6e 20 69 6e * True for an in
17d60 66 69 78 20 66 75 6e 63 74 69 6f 6e 3a 20 4c 49 fix function: LI
17d70 4b 45 2c 20 47 4c 4f 42 2c 20 65 74 63 20 2a 2f KE, GLOB, etc */
17d80 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f 6c 6c .#define EP_Coll
17d90 61 74 65 20 20 20 30 78 30 30 30 31 30 30 20 2f ate 0x000100 /
17da0 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 * Tree contains
17db0 61 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 6f 70 65 a TK_COLLATE ope
17dc0 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 rator */.#define
17dd0 20 45 50 5f 47 65 6e 65 72 69 63 20 20 20 30 78 EP_Generic 0x
17de0 30 30 30 32 30 30 20 2f 2a 20 49 67 6e 6f 72 65 000200 /* Ignore
17df0 20 43 4f 4c 4c 41 54 45 20 6f 72 20 61 66 66 69 COLLATE or affi
17e00 6e 69 74 79 20 6f 6e 20 74 68 69 73 20 74 72 65 nity on this tre
17e10 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f e */.#define EP_
17e20 49 6e 74 56 61 6c 75 65 20 20 30 78 30 30 30 34 IntValue 0x0004
17e30 30 30 20 2f 2a 20 49 6e 74 65 67 65 72 20 76 61 00 /* Integer va
17e40 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e lue contained in
17e50 20 75 2e 69 56 61 6c 75 65 20 2a 2f 0a 23 64 65 u.iValue */.#de
17e60 66 69 6e 65 20 45 50 5f 78 49 73 53 65 6c 65 63 fine EP_xIsSelec
17e70 74 20 30 78 30 30 30 38 30 30 20 2f 2a 20 78 2e t 0x000800 /* x.
17e80 70 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 64 pSelect is valid
17e90 20 28 6f 74 68 65 72 77 69 73 65 20 78 2e 70 4c (otherwise x.pL
17ea0 69 73 74 20 69 73 29 20 2a 2f 0a 23 64 65 66 69 ist is) */.#defi
17eb0 6e 65 20 45 50 5f 53 6b 69 70 20 20 20 20 20 20 ne EP_Skip
17ec0 30 78 30 30 31 30 30 30 20 2f 2a 20 43 4f 4c 4c 0x001000 /* COLL
17ed0 41 54 45 2c 20 41 53 2c 20 6f 72 20 55 4e 4c 49 ATE, AS, or UNLI
17ee0 4b 45 4c 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 KELY */.#define
17ef0 45 50 5f 52 65 64 75 63 65 64 20 20 20 30 78 30 EP_Reduced 0x0
17f00 30 32 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 02000 /* Expr st
17f10 72 75 63 74 20 45 58 50 52 5f 52 45 44 55 43 45 ruct EXPR_REDUCE
17f20 44 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 DSIZE bytes only
17f30 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 54 */.#define EP_T
17f40 6f 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 34 30 30 okenOnly 0x00400
17f50 30 20 2f 2a 20 45 78 70 72 20 73 74 72 75 63 74 0 /* Expr struct
17f60 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 EXPR_TOKENONLYS
17f70 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a IZE bytes only *
17f80 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 74 61 /.#define EP_Sta
17f90 74 69 63 20 20 20 20 30 78 30 30 38 30 30 30 20 tic 0x008000
17fa0 2f 2a 20 48 65 6c 64 20 69 6e 20 6d 65 6d 6f 72 /* Held in memor
17fb0 79 20 6e 6f 74 20 6f 62 74 61 69 6e 65 64 20 66 y not obtained f
17fc0 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a rom malloc() */.
17fd0 23 64 65 66 69 6e 65 20 45 50 5f 4d 65 6d 54 6f #define EP_MemTo
17fe0 6b 65 6e 20 20 30 78 30 31 30 30 30 30 20 2f 2a ken 0x010000 /*
17ff0 20 4e 65 65 64 20 74 6f 20 73 71 6c 69 74 65 33 Need to sqlite3
18000 44 62 46 72 65 65 28 29 20 45 78 70 72 2e 7a 54 DbFree() Expr.zT
18010 6f 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 oken */.#define
18020 45 50 5f 4e 6f 52 65 64 75 63 65 20 20 30 78 30 EP_NoReduce 0x0
18030 32 30 30 30 30 20 2f 2a 20 43 61 6e 6e 6f 74 20 20000 /* Cannot
18040 45 58 50 52 44 55 50 5f 52 45 44 55 43 45 20 74 EXPRDUP_REDUCE t
18050 68 69 73 20 45 78 70 72 20 2a 2f 0a 23 64 65 66 his Expr */.#def
18060 69 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 20 ine EP_Unlikely
18070 20 30 78 30 34 30 30 30 30 20 2f 2a 20 75 6e 6c 0x040000 /* unl
18080 69 6b 65 6c 79 28 29 20 6f 72 20 6c 69 6b 65 6c ikely() or likel
18090 69 68 6f 6f 64 28 29 20 66 75 6e 63 74 69 6f 6e ihood() function
180a0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 */.#define EP_C
180b0 6f 6e 73 74 46 75 6e 63 20 30 78 30 38 30 30 30 onstFunc 0x08000
180c0 30 20 2f 2a 20 41 20 53 51 4c 49 54 45 5f 46 55 0 /* A SQLITE_FU
180d0 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 6f 72 20 5f NC_CONSTANT or _
180e0 53 4c 4f 43 48 4e 47 20 66 75 6e 63 74 69 6f 6e SLOCHNG function
180f0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 */.#define EP_C
18100 61 6e 42 65 4e 75 6c 6c 20 30 78 31 30 30 30 30 anBeNull 0x10000
18110 30 20 2f 2a 20 43 61 6e 20 62 65 20 6e 75 6c 6c 0 /* Can be null
18120 20 64 65 73 70 69 74 65 20 4e 4f 54 20 4e 55 4c despite NOT NUL
18130 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a L constraint */.
18140 23 64 65 66 69 6e 65 20 45 50 5f 53 75 62 71 75 #define EP_Subqu
18150 65 72 79 20 20 30 78 32 30 30 30 30 30 20 2f 2a ery 0x200000 /*
18160 20 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 Tree contains a
18170 20 54 4b 5f 53 45 4c 45 43 54 20 6f 70 65 72 61 TK_SELECT opera
18180 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 tor */.#define E
18190 50 5f 41 6c 69 61 73 20 20 20 20 20 30 78 34 30 P_Alias 0x40
181a0 30 30 30 30 20 2f 2a 20 49 73 20 61 6e 20 61 6c 0000 /* Is an al
181b0 69 61 73 20 66 6f 72 20 61 20 72 65 73 75 6c 74 ias for a result
181c0 20 73 65 74 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 set column */.#
181d0 64 65 66 69 6e 65 20 45 50 5f 4c 65 61 66 20 20 define EP_Leaf
181e0 20 20 20 20 30 78 38 30 30 30 30 30 20 2f 2a 20 0x800000 /*
181f0 45 78 70 72 2e 70 4c 65 66 74 2c 20 2e 70 52 69 Expr.pLeft, .pRi
18200 67 68 74 2c 20 2e 75 2e 70 53 65 6c 65 63 74 20 ght, .u.pSelect
18210 61 6c 6c 20 4e 55 4c 4c 20 2a 2f 0a 0a 2f 2a 0a all NULL */../*.
18220 2a 2a 20 43 6f 6d 62 69 6e 61 74 69 6f 6e 73 20 ** Combinations
18230 6f 66 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 45 of two or more E
18240 50 5f 2a 20 66 6c 61 67 73 0a 2a 2f 0a 23 64 65 P_* flags.*/.#de
18250 66 69 6e 65 20 45 50 5f 50 72 6f 70 61 67 61 74 fine EP_Propagat
18260 65 20 28 45 50 5f 43 6f 6c 6c 61 74 65 7c 45 50 e (EP_Collate|EP
18270 5f 53 75 62 71 75 65 72 79 29 20 2f 2a 20 50 72 _Subquery) /* Pr
18280 6f 70 61 67 61 74 65 20 74 68 65 73 65 20 62 69 opagate these bi
18290 74 73 20 75 70 20 74 72 65 65 20 2a 2f 0a 0a 2f ts up tree */../
182a0 2a 0a 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f *.** These macro
182b0 73 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f s can be used to
182c0 20 74 65 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 test, set, or c
182d0 6c 65 61 72 20 62 69 74 73 20 69 6e 20 74 68 65 lear bits in the
182e0 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 73 20 66 .** Expr.flags f
182f0 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ield..*/.#define
18300 20 45 78 70 72 48 61 73 50 72 6f 70 65 72 74 79 ExprHasProperty
18310 28 45 2c 50 29 20 20 20 20 20 28 28 28 45 29 2d (E,P) (((E)-
18320 3e 66 6c 61 67 73 26 28 50 29 29 21 3d 30 29 0a >flags&(P))!=0).
18330 23 64 65 66 69 6e 65 20 45 78 70 72 48 61 73 41 #define ExprHasA
18340 6c 6c 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 llProperty(E,P)
18350 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 26 28 50 (((E)->flags&(P
18360 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 ))==(P)).#define
18370 20 45 78 70 72 53 65 74 50 72 6f 70 65 72 74 79 ExprSetProperty
18380 28 45 2c 50 29 20 20 20 20 20 28 45 29 2d 3e 66 (E,P) (E)->f
18390 6c 61 67 73 7c 3d 28 50 29 0a 23 64 65 66 69 6e lags|=(P).#defin
183a0 65 20 45 78 70 72 43 6c 65 61 72 50 72 6f 70 65 e ExprClearPrope
183b0 72 74 79 28 45 2c 50 29 20 20 20 28 45 29 2d 3e rty(E,P) (E)->
183c0 66 6c 61 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 20 flags&=~(P)../*
183d0 54 68 65 20 45 78 70 72 53 65 74 56 56 41 50 72 The ExprSetVVAPr
183e0 6f 70 65 72 74 79 28 29 20 6d 61 63 72 6f 20 69 operty() macro i
183f0 73 20 75 73 65 64 20 66 6f 72 20 56 65 72 69 66 s used for Verif
18400 69 63 61 74 69 6f 6e 2c 20 56 61 6c 69 64 61 74 ication, Validat
18410 69 6f 6e 2c 0a 2a 2a 20 61 6e 64 20 41 63 63 72 ion,.** and Accr
18420 65 64 69 74 61 74 69 6f 6e 20 6f 6e 6c 79 2e 20 editation only.
18430 20 49 74 20 77 6f 72 6b 73 20 6c 69 6b 65 20 45 It works like E
18440 78 70 72 53 65 74 50 72 6f 70 65 72 74 79 28 29 xprSetProperty()
18450 20 64 75 72 69 6e 67 20 56 56 41 0a 2a 2a 20 70 during VVA.** p
18460 72 6f 63 65 73 73 65 73 20 62 75 74 20 69 73 20 rocesses but is
18470 61 20 6e 6f 2d 6f 70 20 66 6f 72 20 64 65 6c 69 a no-op for deli
18480 76 65 72 79 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 very..*/.#ifdef
18490 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 23 20 64 SQLITE_DEBUG.# d
184a0 65 66 69 6e 65 20 45 78 70 72 53 65 74 56 56 41 efine ExprSetVVA
184b0 50 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 28 Property(E,P) (
184c0 45 29 2d 3e 66 6c 61 67 73 7c 3d 28 50 29 0a 23 E)->flags|=(P).#
184d0 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 45 78 else.# define Ex
184e0 70 72 53 65 74 56 56 41 50 72 6f 70 65 72 74 79 prSetVVAProperty
184f0 28 45 2c 50 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a (E,P).#endif../*
18500 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 .** Macros to de
18510 74 65 72 6d 69 6e 65 20 74 68 65 20 6e 75 6d 62 termine the numb
18520 65 72 20 6f 66 20 62 79 74 65 73 20 72 65 71 75 er of bytes requ
18530 69 72 65 64 20 62 79 20 61 20 6e 6f 72 6d 61 6c ired by a normal
18540 20 45 78 70 72 0a 2a 2a 20 73 74 72 75 63 74 2c Expr.** struct,
18550 20 61 6e 20 45 78 70 72 20 73 74 72 75 63 74 20 an Expr struct
18560 77 69 74 68 20 74 68 65 20 45 50 5f 52 65 64 75 with the EP_Redu
18570 63 65 64 20 66 6c 61 67 20 73 65 74 20 69 6e 20 ced flag set in
18580 45 78 70 72 2e 66 6c 61 67 73 0a 2a 2a 20 61 6e Expr.flags.** an
18590 64 20 61 6e 20 45 78 70 72 20 73 74 72 75 63 74 d an Expr struct
185a0 20 77 69 74 68 20 74 68 65 20 45 50 5f 54 6f 6b with the EP_Tok
185b0 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 73 65 74 2e enOnly flag set.
185c0 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 .*/.#define EXPR
185d0 5f 46 55 4c 4c 53 49 5a 45 20 20 20 20 20 20 20 _FULLSIZE
185e0 20 20 20 20 73 69 7a 65 6f 66 28 45 78 70 72 29 sizeof(Expr)
185f0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 75 /* Fu
18600 6c 6c 20 73 69 7a 65 20 2a 2f 0a 23 64 65 66 69 ll size */.#defi
18610 6e 65 20 45 58 50 52 5f 52 45 44 55 43 45 44 53 ne EXPR_REDUCEDS
18620 49 5a 45 20 20 20 20 20 20 20 20 6f 66 66 73 65 IZE offse
18630 74 6f 66 28 45 78 70 72 2c 69 54 61 62 6c 65 29 tof(Expr,iTable)
18640 20 20 2f 2a 20 43 6f 6d 6d 6f 6e 20 66 65 61 74 /* Common feat
18650 75 72 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ures */.#define
18660 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 EXPR_TOKENONLYSI
18670 5a 45 20 20 20 20 20 20 6f 66 66 73 65 74 6f 66 ZE offsetof
18680 28 45 78 70 72 2c 70 4c 65 66 74 29 20 20 20 2f (Expr,pLeft) /
18690 2a 20 46 65 77 65 72 20 66 65 61 74 75 72 65 73 * Fewer features
186a0 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 73 */../*.** Flags
186b0 20 70 61 73 73 65 64 20 74 6f 20 74 68 65 20 73 passed to the s
186c0 71 6c 69 74 65 33 45 78 70 72 44 75 70 28 29 20 qlite3ExprDup()
186d0 66 75 6e 63 74 69 6f 6e 2e 20 53 65 65 20 74 68 function. See th
186e0 65 20 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e 74 e header comment
186f0 0a 2a 2a 20 61 62 6f 76 65 20 73 71 6c 69 74 65 .** above sqlite
18700 33 45 78 70 72 44 75 70 28 29 20 66 6f 72 20 64 3ExprDup() for d
18710 65 74 61 69 6c 73 2e 0a 2a 2f 0a 23 64 65 66 69 etails..*/.#defi
18720 6e 65 20 45 58 50 52 44 55 50 5f 52 45 44 55 43 ne EXPRDUP_REDUC
18730 45 20 20 20 20 20 20 20 20 20 30 78 30 30 30 31 E 0x0001
18740 20 20 2f 2a 20 55 73 65 64 20 72 65 64 75 63 65 /* Used reduce
18750 64 2d 73 69 7a 65 20 45 78 70 72 20 6e 6f 64 65 d-size Expr node
18760 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 6c 69 s */../*.** A li
18770 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e st of expression
18780 73 2e 20 20 45 61 63 68 20 65 78 70 72 65 73 73 s. Each express
18790 69 6f 6e 20 6d 61 79 20 6f 70 74 69 6f 6e 61 6c ion may optional
187a0 6c 79 20 68 61 76 65 20 61 0a 2a 2a 20 6e 61 6d ly have a.** nam
187b0 65 2e 20 20 41 6e 20 65 78 70 72 2f 6e 61 6d 65 e. An expr/name
187c0 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 63 61 6e combination can
187d0 20 62 65 20 75 73 65 64 20 69 6e 20 73 65 76 65 be used in seve
187e0 72 61 6c 20 77 61 79 73 2c 20 73 75 63 68 0a 2a ral ways, such.*
187f0 2a 20 61 73 20 74 68 65 20 6c 69 73 74 20 6f 66 * as the list of
18800 20 22 65 78 70 72 20 41 53 20 49 44 22 20 66 69 "expr AS ID" fi
18810 65 6c 64 73 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 elds following a
18820 20 22 53 45 4c 45 43 54 22 20 6f 72 20 69 6e 20 "SELECT" or in
18830 74 68 65 0a 2a 2a 20 6c 69 73 74 20 6f 66 20 22 the.** list of "
18840 49 44 20 3d 20 65 78 70 72 22 20 69 74 65 6d 73 ID = expr" items
18850 20 69 6e 20 61 6e 20 55 50 44 41 54 45 2e 20 20 in an UPDATE.
18860 41 20 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 A list of expres
18870 73 69 6f 6e 73 20 63 61 6e 0a 2a 2a 20 61 6c 73 sions can.** als
18880 6f 20 62 65 20 75 73 65 64 20 61 73 20 74 68 65 o be used as the
18890 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 61 20 66 argument to a f
188a0 75 6e 63 74 69 6f 6e 2c 20 69 6e 20 77 68 69 63 unction, in whic
188b0 68 20 63 61 73 65 20 74 68 65 20 61 2e 7a 4e 61 h case the a.zNa
188c0 6d 65 0a 2a 2a 20 66 69 65 6c 64 20 69 73 20 6e me.** field is n
188d0 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 42 ot used..**.** B
188e0 79 20 64 65 66 61 75 6c 74 20 74 68 65 20 45 78 y default the Ex
188f0 70 72 2e 7a 53 70 61 6e 20 66 69 65 6c 64 20 68 pr.zSpan field h
18900 6f 6c 64 73 20 61 20 68 75 6d 61 6e 2d 72 65 61 olds a human-rea
18910 64 61 62 6c 65 20 64 65 73 63 72 69 70 74 69 6f dable descriptio
18920 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 65 78 70 72 n of.** the expr
18930 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 20 75 ession that is u
18940 73 65 64 20 69 6e 20 74 68 65 20 67 65 6e 65 72 sed in the gener
18950 61 74 69 6f 6e 20 6f 66 20 65 72 72 6f 72 20 6d ation of error m
18960 65 73 73 61 67 65 73 20 61 6e 64 0a 2a 2a 20 63 essages and.** c
18970 6f 6c 75 6d 6e 20 6c 61 62 65 6c 73 2e 20 20 49 olumn labels. I
18980 6e 20 74 68 69 73 20 63 61 73 65 2c 20 45 78 70 n this case, Exp
18990 72 2e 7a 53 70 61 6e 20 69 73 20 74 79 70 69 63 r.zSpan is typic
189a0 61 6c 6c 79 20 74 68 65 20 74 65 78 74 20 6f 66 ally the text of
189b0 20 61 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 65 78 70 a.** column exp
189c0 72 65 73 73 69 6f 6e 20 61 73 20 69 74 20 65 78 ression as it ex
189d0 69 73 74 73 20 69 6e 20 61 20 53 45 4c 45 43 54 ists in a SELECT
189e0 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 48 6f 77 statement. How
189f0 65 76 65 72 2c 20 69 66 0a 2a 2a 20 74 68 65 20 ever, if.** the
18a00 62 53 70 61 6e 49 73 54 61 62 20 66 6c 61 67 20 bSpanIsTab flag
18a10 69 73 20 73 65 74 2c 20 74 68 65 6e 20 7a 53 70 is set, then zSp
18a20 61 6e 20 69 73 20 6f 76 65 72 6c 6f 61 64 65 64 an is overloaded
18a30 20 74 6f 20 6d 65 61 6e 20 74 68 65 20 6e 61 6d to mean the nam
18a40 65 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 73 75 e.** of the resu
18a50 6c 74 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 lt column in the
18a60 20 66 6f 72 6d 3a 20 44 41 54 41 42 41 53 45 2e form: DATABASE.
18a70 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 2e 20 20 54 TABLE.COLUMN. T
18a80 68 69 73 20 6c 61 74 65 72 0a 2a 2a 20 66 6f 72 his later.** for
18a90 6d 20 69 73 20 75 73 65 64 20 66 6f 72 20 6e 61 m is used for na
18aa0 6d 65 20 72 65 73 6f 6c 75 74 69 6f 6e 20 77 69 me resolution wi
18ab0 74 68 20 6e 65 73 74 65 64 20 46 52 4f 4d 20 63 th nested FROM c
18ac0 6c 61 75 73 65 73 2e 0a 2a 2f 0a 73 74 72 75 63 lauses..*/.struc
18ad0 74 20 45 78 70 72 4c 69 73 74 20 7b 0a 20 20 69 t ExprList {. i
18ae0 6e 74 20 6e 45 78 70 72 3b 20 20 20 20 20 20 20 nt nExpr;
18af0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
18b00 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 6f of expressions o
18b10 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 20 20 n the list */.
18b20 73 74 72 75 63 74 20 45 78 70 72 4c 69 73 74 5f struct ExprList_
18b30 69 74 65 6d 20 7b 20 2f 2a 20 46 6f 72 20 65 61 item { /* For ea
18b40 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e ch expression in
18b50 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 20 20 20 the list */.
18b60 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 Expr *pExpr;
18b70 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
18b80 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 list of expressi
18b90 6f 6e 73 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 ons */. char
18ba0 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
18bb0 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 61 73 73 6f /* Token asso
18bc0 63 69 61 74 65 64 20 77 69 74 68 20 74 68 69 73 ciated with this
18bd0 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 expression */.
18be0 20 20 20 63 68 61 72 20 2a 7a 53 70 61 6e 3b 20 char *zSpan;
18bf0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 72 /* Or
18c00 69 67 69 6e 61 6c 20 74 65 78 74 20 6f 66 20 74 iginal text of t
18c10 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f he expression */
18c20 0a 20 20 20 20 75 38 20 73 6f 72 74 4f 72 64 65 . u8 sortOrde
18c30 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
18c40 31 20 66 6f 72 20 44 45 53 43 20 6f 72 20 30 20 1 for DESC or 0
18c50 66 6f 72 20 41 53 43 20 2a 2f 0a 20 20 20 20 75 for ASC */. u
18c60 6e 73 69 67 6e 65 64 20 64 6f 6e 65 20 3a 31 3b nsigned done :1;
18c70 20 20 20 20 20 20 20 2f 2a 20 41 20 66 6c 61 67 /* A flag
18c80 20 74 6f 20 69 6e 64 69 63 61 74 65 20 77 68 65 to indicate whe
18c90 6e 20 70 72 6f 63 65 73 73 69 6e 67 20 69 73 20 n processing is
18ca0 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 20 20 20 finished */.
18cb0 75 6e 73 69 67 6e 65 64 20 62 53 70 61 6e 49 73 unsigned bSpanIs
18cc0 54 61 62 20 3a 31 3b 20 2f 2a 20 7a 53 70 61 6e Tab :1; /* zSpan
18cd0 20 68 6f 6c 64 73 20 44 42 2e 54 41 42 4c 45 2e holds DB.TABLE.
18ce0 43 4f 4c 55 4d 4e 20 2a 2f 0a 20 20 20 20 75 6e COLUMN */. un
18cf0 73 69 67 6e 65 64 20 72 65 75 73 61 62 6c 65 20 signed reusable
18d00 3a 31 3b 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e :1; /* Constan
18d10 74 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 t expression is
18d20 72 65 75 73 61 62 6c 65 20 2a 2f 0a 20 20 20 20 reusable */.
18d30 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 20 20 73 74 union {. st
18d40 72 75 63 74 20 7b 0a 20 20 20 20 20 20 20 20 75 ruct {. u
18d50 31 36 20 69 4f 72 64 65 72 42 79 43 6f 6c 3b 20 16 iOrderByCol;
18d60 20 20 20 20 20 2f 2a 20 46 6f 72 20 4f 52 44 45 /* For ORDE
18d70 52 20 42 59 2c 20 63 6f 6c 75 6d 6e 20 6e 75 6d R BY, column num
18d80 62 65 72 20 69 6e 20 72 65 73 75 6c 74 20 73 65 ber in result se
18d90 74 20 2a 2f 0a 20 20 20 20 20 20 20 20 75 31 36 t */. u16
18da0 20 69 41 6c 69 61 73 3b 20 20 20 20 20 20 20 20 iAlias;
18db0 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e 74 6f /* Index into
18dc0 20 50 61 72 73 65 2e 61 41 6c 69 61 73 5b 5d 20 Parse.aAlias[]
18dd0 66 6f 72 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 for zName */.
18de0 20 20 20 7d 20 78 3b 0a 20 20 20 20 20 20 69 6e } x;. in
18df0 74 20 69 43 6f 6e 73 74 45 78 70 72 52 65 67 3b t iConstExprReg;
18e00 20 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 /* Registe
18e10 72 20 69 6e 20 77 68 69 63 68 20 45 78 70 72 20 r in which Expr
18e20 76 61 6c 75 65 20 69 73 20 63 61 63 68 65 64 20 value is cached
18e30 2a 2f 0a 20 20 20 20 7d 20 75 3b 0a 20 20 7d 20 */. } u;. }
18e40 2a 61 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 *a;
18e50 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 20 61 20 /* Alloc a
18e60 70 6f 77 65 72 20 6f 66 20 74 77 6f 20 67 72 65 power of two gre
18e70 61 74 65 72 20 6f 72 20 65 71 75 61 6c 20 74 6f ater or equal to
18e80 20 6e 45 78 70 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a nExpr */.};../*
18e90 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
18ea0 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 of this structur
18eb0 65 20 69 73 20 75 73 65 64 20 62 79 20 74 68 65 e is used by the
18ec0 20 70 61 72 73 65 72 20 74 6f 20 72 65 63 6f 72 parser to recor
18ed0 64 20 62 6f 74 68 0a 2a 2a 20 74 68 65 20 70 61 d both.** the pa
18ee0 72 73 65 20 74 72 65 65 20 66 6f 72 20 61 6e 20 rse tree for an
18ef0 65 78 70 72 65 73 73 69 6f 6e 20 61 6e 64 20 74 expression and t
18f00 68 65 20 73 70 61 6e 20 6f 66 20 69 6e 70 75 74 he span of input
18f10 20 74 65 78 74 20 66 6f 72 20 61 6e 0a 2a 2a 20 text for an.**
18f20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a 2f 0a 73 expression..*/.s
18f30 74 72 75 63 74 20 45 78 70 72 53 70 61 6e 20 7b truct ExprSpan {
18f40 0a 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 . Expr *pExpr;
18f50 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
18f60 65 78 70 72 65 73 73 69 6f 6e 20 70 61 72 73 65 expression parse
18f70 20 74 72 65 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 tree */. const
18f80 20 63 68 61 72 20 2a 7a 53 74 61 72 74 3b 20 20 char *zStart;
18f90 20 2f 2a 20 46 69 72 73 74 20 63 68 61 72 61 63 /* First charac
18fa0 74 65 72 20 6f 66 20 69 6e 70 75 74 20 74 65 78 ter of input tex
18fb0 74 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 t */. const cha
18fc0 72 20 2a 7a 45 6e 64 3b 20 20 20 20 20 2f 2a 20 r *zEnd; /*
18fd0 4f 6e 65 20 63 68 61 72 61 63 74 65 72 20 70 61 One character pa
18fe0 73 74 20 74 68 65 20 65 6e 64 20 6f 66 20 69 6e st the end of in
18ff0 70 75 74 20 74 65 78 74 20 2a 2f 0a 7d 3b 0a 0a put text */.};..
19000 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
19010 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 e of this struct
19020 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 61 20 73 ure can hold a s
19030 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 20 69 64 imple list of id
19040 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a 20 73 75 entifiers,.** su
19050 63 68 20 61 73 20 74 68 65 20 6c 69 73 74 20 22 ch as the list "
19060 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 20 66 6f a,b,c" in the fo
19070 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 6d 65 6e llowing statemen
19080 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 49 ts:.**.** I
19090 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 2c 62 NSERT INTO t(a,b
190a0 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e 2e 3b 0a ,c) VALUES ...;.
190b0 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 20 49 ** CREATE I
190c0 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 28 61 2c NDEX idx ON t(a,
190d0 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 20 43 52 b,c);.** CR
190e0 45 41 54 45 20 54 52 49 47 47 45 52 20 74 72 69 EATE TRIGGER tri
190f0 67 20 42 45 46 4f 52 45 20 55 50 44 41 54 45 20 g BEFORE UPDATE
19100 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 3b ON t(a,b,c) ...;
19110 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 4c 69 73 .**.** The IdLis
19120 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 20 69 73 t.a.idx field is
19130 20 75 73 65 64 20 77 68 65 6e 20 74 68 65 20 49 used when the I
19140 64 4c 69 73 74 20 72 65 70 72 65 73 65 6e 74 73 dList represents
19150 20 74 68 65 20 6c 69 73 74 20 6f 66 0a 2a 2a 20 the list of.**
19160 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 66 74 column names aft
19170 65 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 20 er a table name
19180 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 73 74 61 in an INSERT sta
19190 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 68 65 20 tement. In the
191a0 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a 2a 2a 20 statement.**.**
191b0 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 INSERT INTO
191c0 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a 2a 2a 0a t(a,b,c) ....**.
191d0 2a 2a 20 49 66 20 22 61 22 20 69 73 20 74 68 65 ** If "a" is the
191e0 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 k-th column of
191f0 74 61 62 6c 65 20 22 74 22 2c 20 74 68 65 6e 20 table "t", then
19200 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 64 78 3d IdList.a[0].idx=
19210 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 64 =k..*/.struct Id
19220 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 63 74 20 List {. struct
19230 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 IdList_item {.
19240 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
19250 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 /* Name of t
19260 68 65 20 69 64 65 6e 74 69 66 69 65 72 20 2a 2f he identifier */
19270 0a 20 20 20 20 69 6e 74 20 69 64 78 3b 20 20 20 . int idx;
19280 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 /* Index
19290 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 2e 61 43 in some Table.aC
192a0 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c 75 6d 6e ol[] of a column
192b0 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 2a 2f 0a named zName */.
192c0 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 20 6e 49 } *a;. int nI
192d0 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 d; /* Nu
192e0 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 69 66 69 mber of identifi
192f0 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 73 74 20 ers on the list
19300 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 */.};../*.** The
19310 20 62 69 74 6d 61 73 6b 20 64 61 74 61 74 79 70 bitmask datatyp
19320 65 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 20 e defined below
19330 69 73 20 75 73 65 64 20 66 6f 72 20 76 61 72 69 is used for vari
19340 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e ous optimization
19350 73 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e 67 69 6e s..**.** Changin
19360 67 20 74 68 69 73 20 66 72 6f 6d 20 61 20 36 34 g this from a 64
19370 2d 62 69 74 20 74 6f 20 61 20 33 32 2d 62 69 74 -bit to a 32-bit
19380 20 74 79 70 65 20 6c 69 6d 69 74 73 20 74 68 65 type limits the
19390 20 6e 75 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 61 number of.** ta
193a0 62 6c 65 73 20 69 6e 20 61 20 6a 6f 69 6e 20 74 bles in a join t
193b0 6f 20 33 32 20 69 6e 73 74 65 61 64 20 6f 66 20 o 32 instead of
193c0 36 34 2e 20 20 42 75 74 20 69 74 20 61 6c 73 6f 64. But it also
193d0 20 72 65 64 75 63 65 73 20 74 68 65 20 73 69 7a reduces the siz
193e0 65 0a 2a 2a 20 6f 66 20 74 68 65 20 6c 69 62 72 e.** of the libr
193f0 61 72 79 20 62 79 20 37 33 38 20 62 79 74 65 73 ary by 738 bytes
19400 20 6f 6e 20 69 78 38 36 2e 0a 2a 2f 0a 23 69 66 on ix86..*/.#if
19410 64 65 66 20 53 51 4c 49 54 45 5f 42 49 54 4d 41 def SQLITE_BITMA
19420 53 4b 5f 54 59 50 45 0a 20 20 74 79 70 65 64 65 SK_TYPE. typede
19430 66 20 53 51 4c 49 54 45 5f 42 49 54 4d 41 53 4b f SQLITE_BITMASK
19440 5f 54 59 50 45 20 42 69 74 6d 61 73 6b 3b 0a 23 _TYPE Bitmask;.#
19450 65 6c 73 65 0a 20 20 74 79 70 65 64 65 66 20 75 else. typedef u
19460 36 34 20 42 69 74 6d 61 73 6b 3b 0a 23 65 6e 64 64 Bitmask;.#end
19470 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 if../*.** The nu
19480 6d 62 65 72 20 6f 66 20 62 69 74 73 20 69 6e 20 mber of bits in
19490 61 20 42 69 74 6d 61 73 6b 2e 20 20 22 42 4d 53 a Bitmask. "BMS
194a0 22 20 6d 65 61 6e 73 20 22 42 69 74 4d 61 73 6b " means "BitMask
194b0 20 53 69 7a 65 22 2e 0a 2a 2f 0a 23 64 65 66 69 Size"..*/.#defi
194c0 6e 65 20 42 4d 53 20 20 28 28 69 6e 74 29 28 73 ne BMS ((int)(s
194d0 69 7a 65 6f 66 28 42 69 74 6d 61 73 6b 29 2a 38 izeof(Bitmask)*8
194e0 29 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 62 69 74 20 ))../*.** A bit
194f0 69 6e 20 61 20 42 69 74 6d 61 73 6b 0a 2a 2f 0a in a Bitmask.*/.
19500 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 54 28 #define MASKBIT(
19510 6e 29 20 20 20 28 28 28 42 69 74 6d 61 73 6b 29 n) (((Bitmask)
19520 31 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e 65 1)<<(n)).#define
19530 20 4d 41 53 4b 42 49 54 33 32 28 6e 29 20 28 28 MASKBIT32(n) ((
19540 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 31 29 (unsigned int)1)
19550 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e 65 20 41 <<(n)).#define A
19560 4c 4c 42 49 54 53 20 20 20 20 20 20 28 28 42 69 LLBITS ((Bi
19570 74 6d 61 73 6b 29 2d 31 29 0a 0a 2f 2a 0a 2a 2a tmask)-1)../*.**
19580 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 The following s
19590 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62 tructure describ
195a0 65 73 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 es the FROM clau
195b0 73 65 20 6f 66 20 61 20 53 45 4c 45 43 54 20 73 se of a SELECT s
195c0 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 20 45 61 63 tatement..** Eac
195d0 68 20 74 61 62 6c 65 20 6f 72 20 73 75 62 71 75 h table or subqu
195e0 65 72 79 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 ery in the FROM
195f0 63 6c 61 75 73 65 20 69 73 20 61 20 73 65 70 61 clause is a sepa
19600 72 61 74 65 20 65 6c 65 6d 65 6e 74 20 6f 66 0a rate element of.
19610 2a 2a 20 74 68 65 20 53 72 63 4c 69 73 74 2e 61 ** the SrcList.a
19620 5b 5d 20 61 72 72 61 79 2e 0a 2a 2a 0a 2a 2a 20 [] array..**.**
19630 57 69 74 68 20 74 68 65 20 61 64 64 69 74 69 6f With the additio
19640 6e 20 6f 66 20 6d 75 6c 74 69 70 6c 65 20 64 61 n of multiple da
19650 74 61 62 61 73 65 20 73 75 70 70 6f 72 74 2c 20 tabase support,
19660 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
19670 72 75 63 74 75 72 65 0a 2a 2a 20 63 61 6e 20 61 ructure.** can a
19680 6c 73 6f 20 62 65 20 75 73 65 64 20 74 6f 20 64 lso be used to d
19690 65 73 63 72 69 62 65 20 61 20 70 61 72 74 69 63 escribe a partic
196a0 75 6c 61 72 20 74 61 62 6c 65 20 73 75 63 68 20 ular table such
196b0 61 73 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 as the table tha
196c0 74 0a 2a 2a 20 69 73 20 6d 6f 64 69 66 69 65 64 t.** is modified
196d0 20 62 79 20 61 6e 20 49 4e 53 45 52 54 2c 20 44 by an INSERT, D
196e0 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 41 54 45 ELETE, or UPDATE
196f0 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 statement. In
19700 73 74 61 6e 64 61 72 64 20 53 51 4c 2c 0a 2a 2a standard SQL,.**
19710 20 73 75 63 68 20 61 20 74 61 62 6c 65 20 6d 75 such a table mu
19720 73 74 20 62 65 20 61 20 73 69 6d 70 6c 65 20 6e st be a simple n
19730 61 6d 65 3a 20 49 44 2e 20 20 42 75 74 20 69 6e ame: ID. But in
19740 20 53 51 4c 69 74 65 2c 20 74 68 65 20 74 61 62 SQLite, the tab
19750 6c 65 20 63 61 6e 0a 2a 2a 20 6e 6f 77 20 62 65 le can.** now be
19760 20 69 64 65 6e 74 69 66 69 65 64 20 62 79 20 61 identified by a
19770 20 64 61 74 61 62 61 73 65 20 6e 61 6d 65 2c 20 database name,
19780 61 20 64 6f 74 2c 20 74 68 65 6e 20 74 68 65 20 a dot, then the
19790 74 61 62 6c 65 20 6e 61 6d 65 3a 20 49 44 2e 49 table name: ID.I
197a0 44 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6a 6f 69 D..**.** The joi
197b0 6e 74 79 70 65 20 73 74 61 72 74 73 20 6f 75 74 ntype starts out
197c0 20 73 68 6f 77 69 6e 67 20 74 68 65 20 6a 6f 69 showing the joi
197d0 6e 20 74 79 70 65 20 62 65 74 77 65 65 6e 20 74 n type between t
197e0 68 65 20 63 75 72 72 65 6e 74 20 74 61 62 6c 65 he current table
197f0 0a 2a 2a 20 61 6e 64 20 74 68 65 20 6e 65 78 74 .** and the next
19800 20 74 61 62 6c 65 20 6f 6e 20 74 68 65 20 6c 69 table on the li
19810 73 74 2e 20 20 54 68 65 20 70 61 72 73 65 72 20 st. The parser
19820 62 75 69 6c 64 73 20 74 68 65 20 6c 69 73 74 20 builds the list
19830 74 68 69 73 20 77 61 79 2e 0a 2a 2a 20 42 75 74 this way..** But
19840 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 53 sqlite3SrcListS
19850 68 69 66 74 4a 6f 69 6e 54 79 70 65 28 29 20 6c hiftJoinType() l
19860 61 74 65 72 20 73 68 69 66 74 73 20 74 68 65 20 ater shifts the
19870 6a 6f 69 6e 74 79 70 65 73 20 73 6f 20 74 68 61 jointypes so tha
19880 74 20 65 61 63 68 0a 2a 2a 20 6a 6f 69 6e 74 79 t each.** jointy
19890 70 65 20 65 78 70 72 65 73 73 65 73 20 74 68 65 pe expresses the
198a0 20 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 join between th
198b0 65 20 74 61 62 6c 65 20 61 6e 64 20 74 68 65 20 e table and the
198c0 70 72 65 76 69 6f 75 73 20 74 61 62 6c 65 2e 0a previous table..
198d0 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 63 6f 6c **.** In the col
198e0 55 73 65 64 20 66 69 65 6c 64 2c 20 74 68 65 20 Used field, the
198f0 68 69 67 68 2d 6f 72 64 65 72 20 62 69 74 20 28 high-order bit (
19900 62 69 74 20 36 33 29 20 69 73 20 73 65 74 20 69 bit 63) is set i
19910 66 20 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 63 f the table.** c
19920 6f 6e 74 61 69 6e 73 20 6d 6f 72 65 20 74 68 61 ontains more tha
19930 6e 20 36 33 20 63 6f 6c 75 6d 6e 73 20 61 6e 64 n 63 columns and
19940 20 74 68 65 20 36 34 2d 74 68 20 6f 72 20 6c 61 the 64-th or la
19950 74 65 72 20 63 6f 6c 75 6d 6e 20 69 73 20 75 73 ter column is us
19960 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 72 ed..*/.struct Sr
19970 63 4c 69 73 74 20 7b 0a 20 20 69 6e 74 20 6e 53 cList {. int nS
19980 72 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 rc; /* Nu
19990 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 73 20 6f mber of tables o
199a0 72 20 73 75 62 71 75 65 72 69 65 73 20 69 6e 20 r subqueries in
199b0 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 the FROM clause
199c0 2a 2f 0a 20 20 75 33 32 20 6e 41 6c 6c 6f 63 3b */. u32 nAlloc;
199d0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
199e0 6f 66 20 65 6e 74 72 69 65 73 20 61 6c 6c 6f 63 of entries alloc
199f0 61 74 65 64 20 69 6e 20 61 5b 5d 20 62 65 6c 6f ated in a[] belo
19a00 77 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 53 72 w */. struct Sr
19a10 63 4c 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 20 cList_item {.
19a20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 Schema *pSchema
19a30 3b 20 20 2f 2a 20 53 63 68 65 6d 61 20 74 6f 20 ; /* Schema to
19a40 77 68 69 63 68 20 74 68 69 73 20 69 74 65 6d 20 which this item
19a50 69 73 20 66 69 78 65 64 20 2a 2f 0a 20 20 20 20 is fixed */.
19a60 63 68 61 72 20 2a 7a 44 61 74 61 62 61 73 65 3b char *zDatabase;
19a70 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 64 61 74 /* Name of dat
19a80 61 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 74 68 abase holding th
19a90 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 is table */.
19aa0 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
19ab0 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 /* Name of the
19ac0 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 table */. ch
19ad0 61 72 20 2a 7a 41 6c 69 61 73 3b 20 20 20 20 20 ar *zAlias;
19ae0 2f 2a 20 54 68 65 20 22 42 22 20 70 61 72 74 20 /* The "B" part
19af0 6f 66 20 61 20 22 41 20 41 53 20 42 22 20 70 68 of a "A AS B" ph
19b00 72 61 73 65 2e 20 20 7a 4e 61 6d 65 20 69 73 20 rase. zName is
19b10 74 68 65 20 22 41 22 20 2a 2f 0a 20 20 20 20 54 the "A" */. T
19b20 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 able *pTab;
19b30 20 2f 2a 20 41 6e 20 53 51 4c 20 74 61 62 6c 65 /* An SQL table
19b40 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 corresponding t
19b50 6f 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 20 53 o zName */. S
19b60 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 elect *pSelect;
19b70 20 2f 2a 20 41 20 53 45 4c 45 43 54 20 73 74 61 /* A SELECT sta
19b80 74 65 6d 65 6e 74 20 75 73 65 64 20 69 6e 20 70 tement used in p
19b90 6c 61 63 65 20 6f 66 20 61 20 74 61 62 6c 65 20 lace of a table
19ba0 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 name */. int
19bb0 61 64 64 72 46 69 6c 6c 53 75 62 3b 20 20 2f 2a addrFillSub; /*
19bc0 20 41 64 64 72 65 73 73 20 6f 66 20 73 75 62 72 Address of subr
19bd0 6f 75 74 69 6e 65 20 74 6f 20 6d 61 6e 69 66 65 outine to manife
19be0 73 74 20 61 20 73 75 62 71 75 65 72 79 20 2a 2f st a subquery */
19bf0 0a 20 20 20 20 69 6e 74 20 72 65 67 52 65 74 75 . int regRetu
19c00 72 6e 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 74 rn; /* Regist
19c10 65 72 20 68 6f 6c 64 69 6e 67 20 72 65 74 75 72 er holding retur
19c20 6e 20 61 64 64 72 65 73 73 20 6f 66 20 61 64 64 n address of add
19c30 72 46 69 6c 6c 53 75 62 20 2a 2f 0a 20 20 20 20 rFillSub */.
19c40 69 6e 74 20 72 65 67 52 65 73 75 6c 74 3b 20 20 int regResult;
19c50 20 20 2f 2a 20 52 65 67 69 73 74 65 72 73 20 68 /* Registers h
19c60 6f 6c 64 69 6e 67 20 72 65 73 75 6c 74 73 20 6f olding results o
19c70 66 20 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 2a f a co-routine *
19c80 2f 0a 20 20 20 20 73 74 72 75 63 74 20 7b 0a 20 /. struct {.
19c90 20 20 20 20 20 75 38 20 6a 6f 69 6e 74 79 70 65 u8 jointype
19ca0 3b 20 20 20 20 20 20 2f 2a 20 54 79 70 65 20 6f ; /* Type o
19cb0 66 20 6a 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 f join between t
19cc0 68 69 73 20 74 61 62 6c 65 20 61 6e 64 20 74 68 his table and th
19cd0 65 20 70 72 65 76 69 6f 75 73 20 2a 2f 0a 20 20 e previous */.
19ce0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 6e 6f 74 unsigned not
19cf0 49 6e 64 65 78 65 64 20 3a 31 3b 20 20 20 20 2f Indexed :1; /
19d00 2a 20 54 72 75 65 20 69 66 20 74 68 65 72 65 20 * True if there
19d10 69 73 20 61 20 4e 4f 54 20 49 4e 44 45 58 45 44 is a NOT INDEXED
19d20 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 clause */.
19d30 20 75 6e 73 69 67 6e 65 64 20 69 73 49 6e 64 65 unsigned isInde
19d40 78 65 64 42 79 20 3a 31 3b 20 20 20 2f 2a 20 54 xedBy :1; /* T
19d50 72 75 65 20 69 66 20 74 68 65 72 65 20 69 73 20 rue if there is
19d60 61 6e 20 49 4e 44 45 58 45 44 20 42 59 20 63 6c an INDEXED BY cl
19d70 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 75 6e ause */. un
19d80 73 69 67 6e 65 64 20 69 73 54 61 62 46 75 6e 63 signed isTabFunc
19d90 20 3a 31 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 :1; /* True
19da0 20 69 66 20 74 61 62 6c 65 2d 76 61 6c 75 65 64 if table-valued
19db0 2d 66 75 6e 63 74 69 6f 6e 20 73 79 6e 74 61 78 -function syntax
19dc0 20 2a 2f 0a 20 20 20 20 20 20 75 6e 73 69 67 6e */. unsign
19dd0 65 64 20 69 73 43 6f 72 72 65 6c 61 74 65 64 20 ed isCorrelated
19de0 3a 31 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 20 :1; /* True if
19df0 73 75 62 2d 71 75 65 72 79 20 69 73 20 63 6f 72 sub-query is cor
19e00 72 65 6c 61 74 65 64 20 2a 2f 0a 20 20 20 20 20 related */.
19e10 20 75 6e 73 69 67 6e 65 64 20 76 69 61 43 6f 72 unsigned viaCor
19e20 6f 75 74 69 6e 65 20 3a 31 3b 20 20 2f 2a 20 49 outine :1; /* I
19e30 6d 70 6c 65 6d 65 6e 74 65 64 20 61 73 20 61 20 mplemented as a
19e40 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 co-routine */.
19e50 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 73 52 unsigned isR
19e60 65 63 75 72 73 69 76 65 20 3a 31 3b 20 20 20 2f ecursive :1; /
19e70 2a 20 54 72 75 65 20 66 6f 72 20 72 65 63 75 72 * True for recur
19e80 73 69 76 65 20 72 65 66 65 72 65 6e 63 65 20 69 sive reference i
19e90 6e 20 57 49 54 48 20 2a 2f 0a 20 20 20 20 7d 20 n WITH */. }
19ea0 66 67 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 fg;.#ifndef SQLI
19eb0 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a TE_OMIT_EXPLAIN.
19ec0 20 20 20 20 75 38 20 69 53 65 6c 65 63 74 49 64 u8 iSelectId
19ed0 3b 20 20 20 20 20 2f 2a 20 49 66 20 70 53 65 6c ; /* If pSel
19ee0 65 63 74 21 3d 30 2c 20 74 68 65 20 69 64 20 6f ect!=0, the id o
19ef0 66 20 74 68 65 20 73 75 62 2d 73 65 6c 65 63 74 f the sub-select
19f00 20 69 6e 20 45 51 50 20 2a 2f 0a 23 65 6e 64 69 in EQP */.#endi
19f10 66 0a 20 20 20 20 69 6e 74 20 69 43 75 72 73 6f f. int iCurso
19f20 72 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 56 r; /* The V
19f30 44 42 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 DBE cursor numbe
19f40 72 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 73 r used to access
19f50 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 this table */.
19f60 20 20 20 45 78 70 72 20 2a 70 4f 6e 3b 20 20 20 Expr *pOn;
19f70 20 20 20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 63 /* The ON c
19f80 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e 20 lause of a join
19f90 2a 2f 0a 20 20 20 20 49 64 4c 69 73 74 20 2a 70 */. IdList *p
19fa0 55 73 69 6e 67 3b 20 20 20 2f 2a 20 54 68 65 20 Using; /* The
19fb0 55 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 USING clause of
19fc0 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 69 a join */. Bi
19fd0 74 6d 61 73 6b 20 63 6f 6c 55 73 65 64 3b 20 20 tmask colUsed;
19fe0 2f 2a 20 42 69 74 20 4e 20 28 31 3c 3c 4e 29 20 /* Bit N (1<<N)
19ff0 73 65 74 20 69 66 20 63 6f 6c 75 6d 6e 20 4e 20 set if column N
1a000 6f 66 20 70 54 61 62 20 69 73 20 75 73 65 64 20 of pTab is used
1a010 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 7b 0a 20 */. union {.
1a020 20 20 20 20 20 63 68 61 72 20 2a 7a 49 6e 64 65 char *zInde
1a030 78 65 64 42 79 3b 20 20 20 20 2f 2a 20 49 64 65 xedBy; /* Ide
1a040 6e 74 69 66 69 65 72 20 66 72 6f 6d 20 22 49 4e ntifier from "IN
1a050 44 45 58 45 44 20 42 59 20 3c 7a 49 6e 64 65 78 DEXED BY <zIndex
1a060 3e 22 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 >" clause */.
1a070 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 46 75 ExprList *pFu
1a080 6e 63 41 72 67 3b 20 20 2f 2a 20 41 72 67 75 6d ncArg; /* Argum
1a090 65 6e 74 73 20 74 6f 20 74 61 62 6c 65 2d 76 61 ents to table-va
1a0a0 6c 75 65 64 2d 66 75 6e 63 74 69 6f 6e 20 2a 2f lued-function */
1a0b0 0a 20 20 20 20 7d 20 75 31 3b 0a 20 20 20 20 49 . } u1;. I
1a0c0 6e 64 65 78 20 2a 70 49 42 49 6e 64 65 78 3b 20 ndex *pIBIndex;
1a0d0 20 2f 2a 20 49 6e 64 65 78 20 73 74 72 75 63 74 /* Index struct
1a0e0 75 72 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e ure correspondin
1a0f0 67 20 74 6f 20 75 31 2e 7a 49 6e 64 65 78 65 64 g to u1.zIndexed
1a100 42 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 20 By */. } a[1];
1a110 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f /* O
1a120 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 65 61 63 ne entry for eac
1a130 68 20 69 64 65 6e 74 69 66 69 65 72 20 6f 6e 20 h identifier on
1a140 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d 3b 0a 0a the list */.};..
1a150 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 65 64 20 /*.** Permitted
1a160 76 61 6c 75 65 73 20 6f 66 20 74 68 65 20 53 72 values of the Sr
1a170 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 79 70 65 cList.a.jointype
1a180 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 66 69 6e field.*/.#defin
1a190 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 20 20 30 e JT_INNER 0
1a1a0 78 30 30 30 31 20 20 20 20 2f 2a 20 41 6e 79 20 x0001 /* Any
1a1b0 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 20 6f 72 kind of inner or
1a1c0 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a 2f 0a 23 cross join */.#
1a1d0 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f 53 53 20 define JT_CROSS
1a1e0 20 20 20 20 30 78 30 30 30 32 20 20 20 20 2f 2a 0x0002 /*
1a1f0 20 45 78 70 6c 69 63 69 74 20 75 73 65 20 6f 66 Explicit use of
1a200 20 74 68 65 20 43 52 4f 53 53 20 6b 65 79 77 6f the CROSS keywo
1a210 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 rd */.#define JT
1a220 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 30 30 30 _NATURAL 0x000
1a230 34 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 4 /* True for
1a240 20 61 20 22 6e 61 74 75 72 61 6c 22 20 6a 6f 69 a "natural" joi
1a250 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f n */.#define JT_
1a260 4c 45 46 54 20 20 20 20 20 20 30 78 30 30 30 38 LEFT 0x0008
1a270 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 75 74 65 /* Left oute
1a280 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e r join */.#defin
1a290 65 20 4a 54 5f 52 49 47 48 54 20 20 20 20 20 30 e JT_RIGHT 0
1a2a0 78 30 30 31 30 20 20 20 20 2f 2a 20 52 69 67 68 x0010 /* Righ
1a2b0 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a t outer join */.
1a2c0 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 54 45 52 #define JT_OUTER
1a2d0 20 20 20 20 20 30 78 30 30 32 30 20 20 20 20 2f 0x0020 /
1a2e0 2a 20 54 68 65 20 22 4f 55 54 45 52 22 20 6b 65 * The "OUTER" ke
1a2f0 79 77 6f 72 64 20 69 73 20 70 72 65 73 65 6e 74 yword is present
1a300 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 45 */.#define JT_E
1a310 52 52 4f 52 20 20 20 20 20 30 78 30 30 34 30 20 RROR 0x0040
1a320 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 20 6f 72 /* unknown or
1a330 20 75 6e 73 75 70 70 6f 72 74 65 64 20 6a 6f 69 unsupported joi
1a340 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f 2a 0a 2a n type */.../*.*
1a350 2a 20 46 6c 61 67 73 20 61 70 70 72 6f 70 72 69 * Flags appropri
1a360 61 74 65 20 66 6f 72 20 74 68 65 20 77 63 74 72 ate for the wctr
1a370 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 74 65 72 lFlags parameter
1a380 20 6f 66 20 73 71 6c 69 74 65 33 57 68 65 72 65 of sqlite3Where
1a390 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e 64 20 74 Begin().** and t
1a3a0 68 65 20 57 68 65 72 65 49 6e 66 6f 2e 77 63 74 he WhereInfo.wct
1a3b0 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 72 2e 0a rlFlags member..
1a3c0 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e 73 **.** Value cons
1a3d0 74 72 61 69 6e 74 73 20 28 65 6e 66 6f 72 63 65 traints (enforce
1a3e0 64 20 76 69 61 20 61 73 73 65 72 74 28 29 29 3a d via assert()):
1a3f0 0a 2a 2a 20 20 20 20 20 57 48 45 52 45 5f 55 53 .** WHERE_US
1a400 45 5f 4c 49 4d 49 54 20 20 3d 3d 20 53 46 5f 46 E_LIMIT == SF_F
1a410 69 78 65 64 4c 69 6d 69 74 0a 2a 2f 0a 23 64 65 ixedLimit.*/.#de
1a420 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 45 52 fine WHERE_ORDER
1a430 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 78 30 30 BY_NORMAL 0x00
1a440 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a 2f 0a 23 00 /* No-op */.#
1a450 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 define WHERE_ORD
1a460 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 20 30 78 ERBY_MIN 0x
1a470 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 20 42 59 0001 /* ORDER BY
1a480 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 20 processing for
1a490 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f 0a 23 64 min() func */.#d
1a4a0 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 44 45 efine WHERE_ORDE
1a4b0 52 42 59 5f 4d 41 58 20 20 20 20 20 20 30 78 30 RBY_MAX 0x0
1a4c0 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 42 59 20 002 /* ORDER BY
1a4d0 70 72 6f 63 65 73 73 69 6e 67 20 66 6f 72 20 6d processing for m
1a4e0 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a 23 64 65 ax() func */.#de
1a4f0 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 41 fine WHERE_ONEPA
1a500 53 53 5f 44 45 53 49 52 45 44 20 20 30 78 30 30 SS_DESIRED 0x00
1a510 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f 20 64 6f 04 /* Want to do
1a520 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 41 54 45 one-pass UPDATE
1a530 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 65 66 69 /DELETE */.#defi
1a540 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 41 53 53 ne WHERE_ONEPASS
1a550 5f 4d 55 4c 54 49 52 4f 57 20 30 78 30 30 30 38 _MULTIROW 0x0008
1a560 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 73 20 6f /* ONEPASS is o
1a570 6b 20 77 69 74 68 20 6d 75 6c 74 69 70 6c 65 20 k with multiple
1a580 72 6f 77 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 rows */.#define
1a590 57 48 45 52 45 5f 44 55 50 4c 49 43 41 54 45 53 WHERE_DUPLICATES
1a5a0 5f 4f 4b 20 20 20 20 30 78 30 30 31 30 20 2f 2a _OK 0x0010 /*
1a5b0 20 4f 6b 20 74 6f 20 72 65 74 75 72 6e 20 61 20 Ok to return a
1a5c0 72 6f 77 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e row more than on
1a5d0 63 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 ce */.#define WH
1a5e0 45 52 45 5f 4f 52 5f 53 55 42 43 4c 41 55 53 45 ERE_OR_SUBCLAUSE
1a5f0 20 20 20 20 20 30 78 30 30 32 30 20 2f 2a 20 50 0x0020 /* P
1a600 72 6f 63 65 73 73 69 6e 67 20 61 20 73 75 62 2d rocessing a sub-
1a610 57 48 45 52 45 20 61 73 20 70 61 72 74 20 6f 66 WHERE as part of
1a620 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
1a630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a640 20 20 20 20 20 20 20 2a 2a 20 74 68 65 20 4f 52 ** the OR
1a650 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 20 2a optimization *
1a660 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
1a670 47 52 4f 55 50 42 59 20 20 20 20 20 20 20 20 20 GROUPBY
1a680 20 30 78 30 30 34 30 20 2f 2a 20 70 4f 72 64 65 0x0040 /* pOrde
1a690 72 42 79 20 69 73 20 72 65 61 6c 6c 79 20 61 20 rBy is really a
1a6a0 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 65 66 GROUP BY */.#def
1a6b0 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 4e ine WHERE_DISTIN
1a6c0 43 54 42 59 20 20 20 20 20 20 20 30 78 30 30 38 CTBY 0x008
1a6d0 30 20 2f 2a 20 70 4f 72 64 65 72 62 79 20 69 73 0 /* pOrderby is
1a6e0 20 72 65 61 6c 6c 79 20 61 20 44 49 53 54 49 4e really a DISTIN
1a6f0 43 54 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 CT clause */.#de
1a700 66 69 6e 65 20 57 48 45 52 45 5f 57 41 4e 54 5f fine WHERE_WANT_
1a710 44 49 53 54 49 4e 43 54 20 20 20 20 30 78 30 31 DISTINCT 0x01
1a720 30 30 20 2f 2a 20 41 6c 6c 20 6f 75 74 70 75 74 00 /* All output
1a730 20 6e 65 65 64 73 20 74 6f 20 62 65 20 64 69 73 needs to be dis
1a740 74 69 6e 63 74 20 2a 2f 0a 23 64 65 66 69 6e 65 tinct */.#define
1a750 20 57 48 45 52 45 5f 53 4f 52 54 42 59 47 52 4f WHERE_SORTBYGRO
1a760 55 50 20 20 20 20 20 20 30 78 30 32 30 30 20 2f UP 0x0200 /
1a770 2a 20 53 75 70 70 6f 72 74 20 73 71 6c 69 74 65 * Support sqlite
1a780 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 28 29 3WhereIsSorted()
1a790 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
1a7a0 45 5f 53 45 45 4b 5f 54 41 42 4c 45 20 20 20 20 E_SEEK_TABLE
1a7b0 20 20 20 30 78 30 34 30 30 20 2f 2a 20 44 6f 20 0x0400 /* Do
1a7c0 6e 6f 74 20 64 65 66 65 72 20 73 65 65 6b 73 20 not defer seeks
1a7d0 6f 6e 20 6d 61 69 6e 20 74 61 62 6c 65 20 2a 2f on main table */
1a7e0 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
1a7f0 52 44 45 52 42 59 5f 4c 49 4d 49 54 20 20 20 20 RDERBY_LIMIT
1a800 30 78 30 38 30 30 20 2f 2a 20 4f 52 44 45 52 42 0x0800 /* ORDERB
1a810 59 2b 4c 49 4d 49 54 20 6f 6e 20 74 68 65 20 69 Y+LIMIT on the i
1a820 6e 6e 65 72 20 6c 6f 6f 70 20 2a 2f 0a 20 20 20 nner loop */.
1a830 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a840 20 20 20 20 20 2f 2a 20 20 20 20 20 30 78 31 30 /* 0x10
1a850 30 30 20 20 20 20 6e 6f 74 20 63 75 72 72 65 6e 00 not curren
1a860 74 6c 79 20 75 73 65 64 20 2a 2f 0a 20 20 20 20 tly used */.
1a870 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a880 20 20 20 20 2f 2a 20 20 20 20 20 30 78 32 30 30 /* 0x200
1a890 30 20 20 20 20 6e 6f 74 20 63 75 72 72 65 6e 74 0 not current
1a8a0 6c 79 20 75 73 65 64 20 2a 2f 0a 23 64 65 66 69 ly used */.#defi
1a8b0 6e 65 20 57 48 45 52 45 5f 55 53 45 5f 4c 49 4d ne WHERE_USE_LIM
1a8c0 49 54 20 20 20 20 20 20 20 20 30 78 34 30 30 30 IT 0x4000
1a8d0 20 2f 2a 20 55 73 65 20 74 68 65 20 4c 49 4d 49 /* Use the LIMI
1a8e0 54 20 69 6e 20 63 6f 73 74 20 65 73 74 69 6d 61 T in cost estima
1a8f0 74 65 73 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 tes */.
1a900 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1a910 2a 20 20 20 20 20 30 78 38 30 30 30 20 20 20 20 * 0x8000
1a920 6e 6f 74 20 63 75 72 72 65 6e 74 6c 79 20 75 73 not currently us
1a930 65 64 20 2a 2f 0a 0a 2f 2a 20 41 6c 6c 6f 77 65 ed */../* Allowe
1a940 64 20 72 65 74 75 72 6e 20 76 61 6c 75 65 73 20 d return values
1a950 66 72 6f 6d 20 73 71 6c 69 74 65 33 57 68 65 72 from sqlite3Wher
1a960 65 49 73 44 69 73 74 69 6e 63 74 28 29 0a 2a 2f eIsDistinct().*/
1a970 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 .#define WHERE_D
1a980 49 53 54 49 4e 43 54 5f 4e 4f 4f 50 20 20 20 20 ISTINCT_NOOP
1a990 20 20 30 20 20 2f 2a 20 44 49 53 54 49 4e 43 54 0 /* DISTINCT
1a9a0 20 6b 65 79 77 6f 72 64 20 6e 6f 74 20 75 73 65 keyword not use
1a9b0 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 d */.#define WHE
1a9c0 52 45 5f 44 49 53 54 49 4e 43 54 5f 55 4e 49 51 RE_DISTINCT_UNIQ
1a9d0 55 45 20 20 20 20 31 20 20 2f 2a 20 4e 6f 20 64 UE 1 /* No d
1a9e0 75 70 6c 69 63 61 74 65 73 20 2a 2f 0a 23 64 65 uplicates */.#de
1a9f0 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 49 fine WHERE_DISTI
1aa00 4e 43 54 5f 4f 52 44 45 52 45 44 20 20 20 32 20 NCT_ORDERED 2
1aa10 20 2f 2a 20 41 6c 6c 20 64 75 70 6c 69 63 61 74 /* All duplicat
1aa20 65 73 20 61 72 65 20 61 64 6a 61 63 65 6e 74 20 es are adjacent
1aa30 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 */.#define WHERE
1aa40 5f 44 49 53 54 49 4e 43 54 5f 55 4e 4f 52 44 45 _DISTINCT_UNORDE
1aa50 52 45 44 20 33 20 20 2f 2a 20 44 75 70 6c 69 63 RED 3 /* Duplic
1aa60 61 74 65 73 20 61 72 65 20 73 63 61 74 74 65 72 ates are scatter
1aa70 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 4e ed */../*.** A N
1aa80 61 6d 65 43 6f 6e 74 65 78 74 20 64 65 66 69 6e ameContext defin
1aa90 65 73 20 61 20 63 6f 6e 74 65 78 74 20 69 6e 20 es a context in
1aaa0 77 68 69 63 68 20 74 6f 20 72 65 73 6f 6c 76 65 which to resolve
1aab0 20 74 61 62 6c 65 20 61 6e 64 20 63 6f 6c 75 6d table and colum
1aac0 6e 0a 2a 2a 20 6e 61 6d 65 73 2e 20 20 54 68 65 n.** names. The
1aad0 20 63 6f 6e 74 65 78 74 20 63 6f 6e 73 69 73 74 context consist
1aae0 73 20 6f 66 20 61 20 6c 69 73 74 20 6f 66 20 74 s of a list of t
1aaf0 61 62 6c 65 73 20 28 74 68 65 20 70 53 72 63 4c ables (the pSrcL
1ab00 69 73 74 29 20 66 69 65 6c 64 20 61 6e 64 0a 2a ist) field and.*
1ab10 2a 20 61 20 6c 69 73 74 20 6f 66 20 6e 61 6d 65 * a list of name
1ab20 64 20 65 78 70 72 65 73 73 69 6f 6e 20 28 70 45 d expression (pE
1ab30 4c 69 73 74 29 2e 20 20 54 68 65 20 6e 61 6d 65 List). The name
1ab40 64 20 65 78 70 72 65 73 73 69 6f 6e 20 6c 69 73 d expression lis
1ab50 74 20 6d 61 79 0a 2a 2a 20 62 65 20 4e 55 4c 4c t may.** be NULL
1ab60 2e 20 20 54 68 65 20 70 53 72 63 20 63 6f 72 72 . The pSrc corr
1ab70 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 46 esponds to the F
1ab80 52 4f 4d 20 63 6c 61 75 73 65 20 6f 66 20 61 20 ROM clause of a
1ab90 53 45 4c 45 43 54 20 6f 72 0a 2a 2a 20 74 6f 20 SELECT or.** to
1aba0 74 68 65 20 74 61 62 6c 65 20 62 65 69 6e 67 20 the table being
1abb0 6f 70 65 72 61 74 65 64 20 6f 6e 20 62 79 20 49 operated on by I
1abc0 4e 53 45 52 54 2c 20 55 50 44 41 54 45 2c 20 6f NSERT, UPDATE, o
1abd0 72 20 44 45 4c 45 54 45 2e 20 20 54 68 65 0a 2a r DELETE. The.*
1abe0 2a 20 70 45 4c 69 73 74 20 63 6f 72 72 65 73 70 * pEList corresp
1abf0 6f 6e 64 73 20 74 6f 20 74 68 65 20 72 65 73 75 onds to the resu
1ac00 6c 74 20 73 65 74 20 6f 66 20 61 20 53 45 4c 45 lt set of a SELE
1ac10 43 54 20 61 6e 64 20 69 73 20 4e 55 4c 4c 20 66 CT and is NULL f
1ac20 6f 72 0a 2a 2a 20 6f 74 68 65 72 20 73 74 61 74 or.** other stat
1ac30 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 4e 61 ements..**.** Na
1ac40 6d 65 43 6f 6e 74 65 78 74 73 20 63 61 6e 20 62 meContexts can b
1ac50 65 20 6e 65 73 74 65 64 2e 20 20 57 68 65 6e 20 e nested. When
1ac60 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d 65 73 2c resolving names,
1ac70 20 74 68 65 20 69 6e 6e 65 72 2d 6d 6f 73 74 0a the inner-most.
1ac80 2a 2a 20 63 6f 6e 74 65 78 74 20 69 73 20 73 65 ** context is se
1ac90 61 72 63 68 65 64 20 66 69 72 73 74 2e 20 20 49 arched first. I
1aca0 66 20 6e 6f 20 6d 61 74 63 68 20 69 73 20 66 6f f no match is fo
1acb0 75 6e 64 2c 20 74 68 65 20 6e 65 78 74 20 6f 75 und, the next ou
1acc0 74 65 72 0a 2a 2a 20 63 6f 6e 74 65 78 74 20 69 ter.** context i
1acd0 73 20 63 68 65 63 6b 65 64 2e 20 20 49 66 20 74 s checked. If t
1ace0 68 65 72 65 20 69 73 20 73 74 69 6c 6c 20 6e 6f here is still no
1acf0 20 6d 61 74 63 68 2c 20 74 68 65 20 6e 65 78 74 match, the next
1ad00 20 63 6f 6e 74 65 78 74 0a 2a 2a 20 69 73 20 63 context.** is c
1ad10 68 65 63 6b 65 64 2e 20 20 54 68 69 73 20 70 72 hecked. This pr
1ad20 6f 63 65 73 73 20 63 6f 6e 74 69 6e 75 65 73 20 ocess continues
1ad30 75 6e 74 69 6c 20 65 69 74 68 65 72 20 61 20 6d until either a m
1ad40 61 74 63 68 20 69 73 20 66 6f 75 6e 64 0a 2a 2a atch is found.**
1ad50 20 6f 72 20 61 6c 6c 20 63 6f 6e 74 65 78 74 73 or all contexts
1ad60 20 61 72 65 20 63 68 65 63 6b 2e 20 20 57 68 65 are check. Whe
1ad70 6e 20 61 20 6d 61 74 63 68 20 69 73 20 66 6f 75 n a match is fou
1ad80 6e 64 2c 20 74 68 65 20 6e 52 65 66 20 6d 65 6d nd, the nRef mem
1ad90 62 65 72 20 6f 66 0a 2a 2a 20 74 68 65 20 63 6f ber of.** the co
1ada0 6e 74 65 78 74 20 63 6f 6e 74 61 69 6e 69 6e 67 ntext containing
1adb0 20 74 68 65 20 6d 61 74 63 68 20 69 73 20 69 6e the match is in
1adc0 63 72 65 6d 65 6e 74 65 64 2e 0a 2a 2a 0a 2a 2a cremented..**.**
1add0 20 45 61 63 68 20 73 75 62 71 75 65 72 79 20 67 Each subquery g
1ade0 65 74 73 20 61 20 6e 65 77 20 4e 61 6d 65 43 6f ets a new NameCo
1adf0 6e 74 65 78 74 2e 20 20 54 68 65 20 70 4e 65 78 ntext. The pNex
1ae00 74 20 66 69 65 6c 64 20 70 6f 69 6e 74 73 20 74 t field points t
1ae10 6f 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e o the.** NameCon
1ae20 74 65 78 74 20 69 6e 20 74 68 65 20 70 61 72 65 text in the pare
1ae30 6e 74 20 71 75 65 72 79 2e 20 20 54 68 75 73 20 nt query. Thus
1ae40 74 68 65 20 70 72 6f 63 65 73 73 20 6f 66 20 73 the process of s
1ae50 63 61 6e 6e 69 6e 67 20 74 68 65 0a 2a 2a 20 4e canning the.** N
1ae60 61 6d 65 43 6f 6e 74 65 78 74 20 6c 69 73 74 20 ameContext list
1ae70 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 73 corresponds to s
1ae80 65 61 72 63 68 69 6e 67 20 74 68 72 6f 75 67 68 earching through
1ae90 20 73 75 63 63 65 73 73 69 76 65 6c 79 20 6f 75 successively ou
1aea0 74 65 72 0a 2a 2a 20 73 75 62 71 75 65 72 69 65 ter.** subquerie
1aeb0 73 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 20 61 20 s looking for a
1aec0 6d 61 74 63 68 2e 0a 2a 2f 0a 73 74 72 75 63 74 match..*/.struct
1aed0 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 7b 0a 20 NameContext {.
1aee0 20 50 61 72 73 65 20 2a 70 50 61 72 73 65 3b 20 Parse *pParse;
1aef0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 70 61 72 /* The par
1af00 73 65 72 20 2a 2f 0a 20 20 53 72 63 4c 69 73 74 ser */. SrcList
1af10 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 20 2f 2a *pSrcList; /*
1af20 20 4f 6e 65 20 6f 72 20 6d 6f 72 65 20 74 61 62 One or more tab
1af30 6c 65 73 20 75 73 65 64 20 74 6f 20 72 65 73 6f les used to reso
1af40 6c 76 65 20 6e 61 6d 65 73 20 2a 2f 0a 20 20 45 lve names */. E
1af50 78 70 72 4c 69 73 74 20 2a 70 45 4c 69 73 74 3b xprList *pEList;
1af60 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 /* Optional
1af70 6c 69 73 74 20 6f 66 20 72 65 73 75 6c 74 2d 73 list of result-s
1af80 65 74 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 20 20 et columns */.
1af90 41 67 67 49 6e 66 6f 20 2a 70 41 67 67 49 6e 66 AggInfo *pAggInf
1afa0 6f 3b 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 o; /* Informat
1afb0 69 6f 6e 20 61 62 6f 75 74 20 61 67 67 72 65 67 ion about aggreg
1afc0 61 74 65 73 20 61 74 20 74 68 69 73 20 6c 65 76 ates at this lev
1afd0 65 6c 20 2a 2f 0a 20 20 4e 61 6d 65 43 6f 6e 74 el */. NameCont
1afe0 65 78 74 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 ext *pNext; /*
1aff0 4e 65 78 74 20 6f 75 74 65 72 20 6e 61 6d 65 20 Next outer name
1b000 63 6f 6e 74 65 78 74 2e 20 20 4e 55 4c 4c 20 66 context. NULL f
1b010 6f 72 20 6f 75 74 65 72 6d 6f 73 74 20 2a 2f 0a or outermost */.
1b020 20 20 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 int nRef;
1b030 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1b040 20 6f 66 20 6e 61 6d 65 73 20 72 65 73 6f 6c 76 of names resolv
1b050 65 64 20 62 79 20 74 68 69 73 20 63 6f 6e 74 65 ed by this conte
1b060 78 74 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 xt */. int nErr
1b070 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1b080 4e 75 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 Number of errors
1b090 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 encountered whi
1b0a0 6c 65 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d le resolving nam
1b0b0 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e 63 46 6c es */. u16 ncFl
1b0c0 61 67 73 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ags; /*
1b0d0 5a 65 72 6f 20 6f 72 20 6d 6f 72 65 20 4e 43 5f Zero or more NC_
1b0e0 2a 20 66 6c 61 67 73 20 64 65 66 69 6e 65 64 20 * flags defined
1b0f0 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a below */.};../*.
1b100 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 ** Allowed value
1b110 73 20 66 6f 72 20 74 68 65 20 4e 61 6d 65 43 6f s for the NameCo
1b120 6e 74 65 78 74 2c 20 6e 63 46 6c 61 67 73 20 66 ntext, ncFlags f
1b130 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 ield..**.** Valu
1b140 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 61 e constraints (a
1b150 6c 6c 20 63 68 65 63 6b 65 64 20 76 69 61 20 61 ll checked via a
1b160 73 73 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 ssert()):.**
1b170 4e 43 5f 48 61 73 41 67 67 20 20 20 20 3d 3d 20 NC_HasAgg ==
1b180 53 46 5f 48 61 73 41 67 67 0a 2a 2a 20 20 20 20 SF_HasAgg.**
1b190 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 3d 3d 20 NC_MinMaxAgg ==
1b1a0 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 3d 3d 20 SF_MinMaxAgg ==
1b1b0 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d 49 4e 4d SQLITE_FUNC_MINM
1b1c0 41 58 0a 2a 2a 0a 2a 2f 0a 23 64 65 66 69 6e 65 AX.**.*/.#define
1b1d0 20 4e 43 5f 41 6c 6c 6f 77 41 67 67 20 20 30 78 NC_AllowAgg 0x
1b1e0 30 30 30 31 20 20 2f 2a 20 41 67 67 72 65 67 61 0001 /* Aggrega
1b1f0 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 te functions are
1b200 20 61 6c 6c 6f 77 65 64 20 68 65 72 65 20 2a 2f allowed here */
1b210 0a 23 64 65 66 69 6e 65 20 4e 43 5f 50 61 72 74 .#define NC_Part
1b220 49 64 78 20 20 20 30 78 30 30 30 32 20 20 2f 2a Idx 0x0002 /*
1b230 20 54 72 75 65 20 69 66 20 72 65 73 6f 6c 76 69 True if resolvi
1b240 6e 67 20 61 20 70 61 72 74 69 61 6c 20 69 6e 64 ng a partial ind
1b250 65 78 20 57 48 45 52 45 20 2a 2f 0a 23 64 65 66 ex WHERE */.#def
1b260 69 6e 65 20 4e 43 5f 49 73 43 68 65 63 6b 20 20 ine NC_IsCheck
1b270 20 30 78 30 30 30 34 20 20 2f 2a 20 54 72 75 65 0x0004 /* True
1b280 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 if resolving na
1b290 6d 65 73 20 69 6e 20 61 20 43 48 45 43 4b 20 63 mes in a CHECK c
1b2a0 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 onstraint */.#de
1b2b0 66 69 6e 65 20 4e 43 5f 49 6e 41 67 67 46 75 6e fine NC_InAggFun
1b2c0 63 20 30 78 30 30 30 38 20 20 2f 2a 20 54 72 75 c 0x0008 /* Tru
1b2d0 65 20 69 66 20 61 6e 61 6c 79 7a 69 6e 67 20 61 e if analyzing a
1b2e0 72 67 75 6d 65 6e 74 73 20 74 6f 20 61 6e 20 61 rguments to an a
1b2f0 67 67 20 66 75 6e 63 20 2a 2f 0a 23 64 65 66 69 gg func */.#defi
1b300 6e 65 20 4e 43 5f 48 61 73 41 67 67 20 20 20 20 ne NC_HasAgg
1b310 30 78 30 30 31 30 20 20 2f 2a 20 4f 6e 65 20 6f 0x0010 /* One o
1b320 72 20 6d 6f 72 65 20 61 67 67 72 65 67 61 74 65 r more aggregate
1b330 20 66 75 6e 63 74 69 6f 6e 73 20 73 65 65 6e 20 functions seen
1b340 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 49 64 */.#define NC_Id
1b350 78 45 78 70 72 20 20 20 30 78 30 30 32 30 20 20 xExpr 0x0020
1b360 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 6f 6c /* True if resol
1b370 76 69 6e 67 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 ving columns of
1b380 43 52 45 41 54 45 20 49 4e 44 45 58 20 2a 2f 0a CREATE INDEX */.
1b390 23 64 65 66 69 6e 65 20 4e 43 5f 56 61 72 53 65 #define NC_VarSe
1b3a0 6c 65 63 74 20 30 78 30 30 34 30 20 20 2f 2a 20 lect 0x0040 /*
1b3b0 41 20 63 6f 72 72 65 6c 61 74 65 64 20 73 75 62 A correlated sub
1b3c0 71 75 65 72 79 20 68 61 73 20 62 65 65 6e 20 73 query has been s
1b3d0 65 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e een */.#define N
1b3e0 43 5f 4d 69 6e 4d 61 78 41 67 67 20 30 78 31 30 C_MinMaxAgg 0x10
1b3f0 30 30 20 20 2f 2a 20 6d 69 6e 2f 6d 61 78 20 61 00 /* min/max a
1b400 67 67 72 65 67 61 74 65 73 20 73 65 65 6e 2e 20 ggregates seen.
1b410 20 53 65 65 20 6e 6f 74 65 20 61 62 6f 76 65 20 See note above
1b420 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 */../*.** An ins
1b430 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
1b440 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
1b450 20 63 6f 6e 74 61 69 6e 73 20 61 6c 6c 20 69 6e contains all in
1b460 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 6e 65 65 formation.** nee
1b470 64 65 64 20 74 6f 20 67 65 6e 65 72 61 74 65 20 ded to generate
1b480 63 6f 64 65 20 66 6f 72 20 61 20 73 69 6e 67 6c code for a singl
1b490 65 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 e SELECT stateme
1b4a0 6e 74 2e 0a 2a 2a 0a 2a 2a 20 6e 4c 69 6d 69 74 nt..**.** nLimit
1b4b0 20 69 73 20 73 65 74 20 74 6f 20 2d 31 20 69 66 is set to -1 if
1b4c0 20 74 68 65 72 65 20 69 73 20 6e 6f 20 4c 49 4d there is no LIM
1b4d0 49 54 20 63 6c 61 75 73 65 2e 20 20 6e 4f 66 66 IT clause. nOff
1b4e0 73 65 74 20 69 73 20 73 65 74 20 74 6f 20 30 2e set is set to 0.
1b4f0 0a 2a 2a 20 49 66 20 74 68 65 72 65 20 69 73 20 .** If there is
1b500 61 20 4c 49 4d 49 54 20 63 6c 61 75 73 65 2c 20 a LIMIT clause,
1b510 74 68 65 20 70 61 72 73 65 72 20 73 65 74 73 20 the parser sets
1b520 6e 4c 69 6d 69 74 20 74 6f 20 74 68 65 20 76 61 nLimit to the va
1b530 6c 75 65 20 6f 66 20 74 68 65 0a 2a 2a 20 6c 69 lue of the.** li
1b540 6d 69 74 20 61 6e 64 20 6e 4f 66 66 73 65 74 20 mit and nOffset
1b550 74 6f 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 to the value of
1b560 74 68 65 20 6f 66 66 73 65 74 20 28 6f 72 20 30 the offset (or 0
1b570 20 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 74 if there is not
1b580 0a 2a 2a 20 6f 66 66 73 65 74 29 2e 20 20 42 75 .** offset). Bu
1b590 74 20 6c 61 74 65 72 20 6f 6e 2c 20 6e 4c 69 6d t later on, nLim
1b5a0 69 74 20 61 6e 64 20 6e 4f 66 66 73 65 74 20 62 it and nOffset b
1b5b0 65 63 6f 6d 65 20 74 68 65 20 6d 65 6d 6f 72 79 ecome the memory
1b5c0 20 6c 6f 63 61 74 69 6f 6e 73 0a 2a 2a 20 69 6e locations.** in
1b5d0 20 74 68 65 20 56 44 42 45 20 74 68 61 74 20 72 the VDBE that r
1b5e0 65 63 6f 72 64 20 74 68 65 20 6c 69 6d 69 74 20 ecord the limit
1b5f0 61 6e 64 20 6f 66 66 73 65 74 20 63 6f 75 6e 74 and offset count
1b600 65 72 73 2e 0a 2a 2a 0a 2a 2a 20 61 64 64 72 4f ers..**.** addrO
1b610 70 65 6e 45 70 68 6d 5b 5d 20 65 6e 74 72 69 65 penEphm[] entrie
1b620 73 20 63 6f 6e 74 61 69 6e 20 74 68 65 20 61 64 s contain the ad
1b630 64 72 65 73 73 20 6f 66 20 4f 50 5f 4f 70 65 6e dress of OP_Open
1b640 45 70 68 65 6d 65 72 61 6c 20 6f 70 63 6f 64 65 Ephemeral opcode
1b650 73 2e 0a 2a 2a 20 54 68 65 73 65 20 61 64 64 72 s..** These addr
1b660 65 73 73 65 73 20 6d 75 73 74 20 62 65 20 73 74 esses must be st
1b670 6f 72 65 64 20 73 6f 20 74 68 61 74 20 77 65 20 ored so that we
1b680 63 61 6e 20 67 6f 20 62 61 63 6b 20 61 6e 64 20 can go back and
1b690 66 69 6c 6c 20 69 6e 0a 2a 2a 20 74 68 65 20 50 fill in.** the P
1b6a0 34 5f 4b 45 59 49 4e 46 4f 20 61 6e 64 20 50 32 4_KEYINFO and P2
1b6b0 20 70 61 72 61 6d 65 74 65 72 73 20 6c 61 74 65 parameters late
1b6c0 72 2e 20 20 4e 65 69 74 68 65 72 20 74 68 65 20 r. Neither the
1b6d0 4b 65 79 49 6e 66 6f 20 6e 6f 72 0a 2a 2a 20 74 KeyInfo nor.** t
1b6e0 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 6f 6c he number of col
1b6f0 75 6d 6e 73 20 69 6e 20 50 32 20 63 61 6e 20 62 umns in P2 can b
1b700 65 20 63 6f 6d 70 75 74 65 64 20 61 74 20 74 68 e computed at th
1b710 65 20 73 61 6d 65 20 74 69 6d 65 0a 2a 2a 20 61 e same time.** a
1b720 73 20 74 68 65 20 4f 50 5f 4f 70 65 6e 45 70 68 s the OP_OpenEph
1b730 6d 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 69 73 m instruction is
1b740 20 63 6f 64 65 64 20 62 65 63 61 75 73 65 20 6e coded because n
1b750 6f 74 0a 2a 2a 20 65 6e 6f 75 67 68 20 69 6e 66 ot.** enough inf
1b760 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 ormation about t
1b770 68 65 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 he compound quer
1b780 79 20 69 73 20 6b 6e 6f 77 6e 20 61 74 20 74 68 y is known at th
1b790 61 74 20 70 6f 69 6e 74 2e 0a 2a 2a 20 54 68 65 at point..** The
1b7a0 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 KeyInfo for add
1b7b0 72 4f 70 65 6e 54 72 61 6e 5b 30 5d 20 61 6e 64 rOpenTran[0] and
1b7c0 20 5b 31 5d 20 63 6f 6e 74 61 69 6e 73 20 63 6f [1] contains co
1b7d0 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 llating sequence
1b7e0 73 0a 2a 2a 20 66 6f 72 20 74 68 65 20 72 65 73 s.** for the res
1b7f0 75 6c 74 20 73 65 74 2e 20 20 54 68 65 20 4b 65 ult set. The Ke
1b800 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 72 4f 70 yInfo for addrOp
1b810 65 6e 45 70 68 6d 5b 32 5d 20 63 6f 6e 74 61 69 enEphm[2] contai
1b820 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 0a 2a 2a 20 ns collating.**
1b830 73 65 71 75 65 6e 63 65 73 20 66 6f 72 20 74 68 sequences for th
1b840 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
1b850 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c e..*/.struct Sel
1b860 65 63 74 20 7b 0a 20 20 45 78 70 72 4c 69 73 74 ect {. ExprList
1b870 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 20 20 2f *pEList; /
1b880 2a 20 54 68 65 20 66 69 65 6c 64 73 20 6f 66 20 * The fields of
1b890 74 68 65 20 72 65 73 75 6c 74 20 2a 2f 0a 20 20 the result */.
1b8a0 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 20 20 u8 op;
1b8b0 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 /* One of
1b8c0 3a 20 54 4b 5f 55 4e 49 4f 4e 20 54 4b 5f 41 4c : TK_UNION TK_AL
1b8d0 4c 20 54 4b 5f 49 4e 54 45 52 53 45 43 54 20 54 L TK_INTERSECT T
1b8e0 4b 5f 45 58 43 45 50 54 20 2a 2f 0a 20 20 4c 6f K_EXCEPT */. Lo
1b8f0 67 45 73 74 20 6e 53 65 6c 65 63 74 52 6f 77 3b gEst nSelectRow;
1b900 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 /* Estimate
1b910 64 20 6e 75 6d 62 65 72 20 6f 66 20 72 65 73 75 d number of resu
1b920 6c 74 20 72 6f 77 73 20 2a 2f 0a 20 20 75 33 32 lt rows */. u32
1b930 20 73 65 6c 46 6c 61 67 73 3b 20 20 20 20 20 20 selFlags;
1b940 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 73 20 53 /* Various S
1b950 46 5f 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 F_* values */.
1b960 69 6e 74 20 69 4c 69 6d 69 74 2c 20 69 4f 66 66 int iLimit, iOff
1b970 73 65 74 3b 20 20 20 2f 2a 20 4d 65 6d 6f 72 79 set; /* Memory
1b980 20 72 65 67 69 73 74 65 72 73 20 68 6f 6c 64 69 registers holdi
1b990 6e 67 20 4c 49 4d 49 54 20 26 20 4f 46 46 53 45 ng LIMIT & OFFSE
1b9a0 54 20 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 23 69 T counters */.#i
1b9b0 66 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e f SELECTTRACE_EN
1b9c0 41 42 4c 45 44 0a 20 20 63 68 61 72 20 7a 53 65 ABLED. char zSe
1b9d0 6c 4e 61 6d 65 5b 31 32 5d 3b 20 20 20 20 20 2f lName[12]; /
1b9e0 2a 20 53 79 6d 62 6f 6c 69 63 20 6e 61 6d 65 20 * Symbolic name
1b9f0 6f 66 20 74 68 69 73 20 53 45 4c 45 43 54 20 75 of this SELECT u
1ba00 73 65 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 se for debugging
1ba10 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 */.#endif. int
1ba20 20 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b 32 5d addrOpenEphm[2]
1ba30 3b 20 20 20 2f 2a 20 4f 50 5f 4f 70 65 6e 45 70 ; /* OP_OpenEp
1ba40 68 65 6d 20 6f 70 63 6f 64 65 73 20 72 65 6c 61 hem opcodes rela
1ba50 74 65 64 20 74 6f 20 74 68 69 73 20 73 65 6c 65 ted to this sele
1ba60 63 74 20 2a 2f 0a 20 20 53 72 63 4c 69 73 74 20 ct */. SrcList
1ba70 2a 70 53 72 63 3b 20 20 20 20 20 20 20 20 20 2f *pSrc; /
1ba80 2a 20 54 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 * The FROM claus
1ba90 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 57 68 e */. Expr *pWh
1baa0 65 72 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ere; /*
1bab0 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 The WHERE claus
1bac0 65 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 e */. ExprList
1bad0 2a 70 47 72 6f 75 70 42 79 3b 20 20 20 20 2f 2a *pGroupBy; /*
1bae0 20 54 68 65 20 47 52 4f 55 50 20 42 59 20 63 6c The GROUP BY cl
1baf0 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a ause */. Expr *
1bb00 70 48 61 76 69 6e 67 3b 20 20 20 20 20 20 20 20 pHaving;
1bb10 20 2f 2a 20 54 68 65 20 48 41 56 49 4e 47 20 63 /* The HAVING c
1bb20 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 4c lause */. ExprL
1bb30 69 73 74 20 2a 70 4f 72 64 65 72 42 79 3b 20 20 ist *pOrderBy;
1bb40 20 20 2f 2a 20 54 68 65 20 4f 52 44 45 52 20 42 /* The ORDER B
1bb50 59 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 53 65 Y clause */. Se
1bb60 6c 65 63 74 20 2a 70 50 72 69 6f 72 3b 20 20 20 lect *pPrior;
1bb70 20 20 20 20 20 2f 2a 20 50 72 69 6f 72 20 73 65 /* Prior se
1bb80 6c 65 63 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 lect in a compou
1bb90 6e 64 20 73 65 6c 65 63 74 20 73 74 61 74 65 6d nd select statem
1bba0 65 6e 74 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 ent */. Select
1bbb0 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 20 20 *pNext;
1bbc0 2f 2a 20 4e 65 78 74 20 73 65 6c 65 63 74 20 74 /* Next select t
1bbd0 6f 20 74 68 65 20 6c 65 66 74 20 69 6e 20 61 20 o the left in a
1bbe0 63 6f 6d 70 6f 75 6e 64 20 2a 2f 0a 20 20 45 78 compound */. Ex
1bbf0 70 72 20 2a 70 4c 69 6d 69 74 3b 20 20 20 20 20 pr *pLimit;
1bc00 20 20 20 20 20 2f 2a 20 4c 49 4d 49 54 20 65 78 /* LIMIT ex
1bc10 70 72 65 73 73 69 6f 6e 2e 20 4e 55 4c 4c 20 6d pression. NULL m
1bc20 65 61 6e 73 20 6e 6f 74 20 75 73 65 64 2e 20 2a eans not used. *
1bc30 2f 0a 20 20 45 78 70 72 20 2a 70 4f 66 66 73 65 /. Expr *pOffse
1bc40 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 46 t; /* OF
1bc50 46 53 45 54 20 65 78 70 72 65 73 73 69 6f 6e 2e FSET expression.
1bc60 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e 6f 74 20 NULL means not
1bc70 75 73 65 64 2e 20 2a 2f 0a 20 20 57 69 74 68 20 used. */. With
1bc80 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 20 *pWith;
1bc90 20 20 2f 2a 20 57 49 54 48 20 63 6c 61 75 73 65 /* WITH clause
1bca0 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 69 attached to thi
1bcb0 73 20 73 65 6c 65 63 74 2e 20 4f 72 20 4e 55 4c s select. Or NUL
1bcc0 4c 2e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 L. */.};../*.**
1bcd0 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 20 66 Allowed values f
1bce0 6f 72 20 53 65 6c 65 63 74 2e 73 65 6c 46 6c 61 or Select.selFla
1bcf0 67 73 2e 20 20 54 68 65 20 22 53 46 22 20 70 72 gs. The "SF" pr
1bd00 65 66 69 78 20 73 74 61 6e 64 73 20 66 6f 72 0a efix stands for.
1bd10 2a 2a 20 22 53 65 6c 65 63 74 20 46 6c 61 67 22 ** "Select Flag"
1bd20 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f ..**.** Value co
1bd30 6e 73 74 72 61 69 6e 74 73 20 28 61 6c 6c 20 63 nstraints (all c
1bd40 68 65 63 6b 65 64 20 76 69 61 20 61 73 73 65 72 hecked via asser
1bd50 74 28 29 29 0a 2a 2a 20 20 20 20 20 53 46 5f 48 t()).** SF_H
1bd60 61 73 41 67 67 20 20 20 20 20 3d 3d 20 4e 43 5f asAgg == NC_
1bd70 48 61 73 41 67 67 0a 2a 2a 20 20 20 20 20 53 46 HasAgg.** SF
1bd80 5f 4d 69 6e 4d 61 78 41 67 67 20 20 3d 3d 20 4e _MinMaxAgg == N
1bd90 43 5f 4d 69 6e 4d 61 78 41 67 67 20 20 20 20 20 C_MinMaxAgg
1bda0 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d == SQLITE_FUNC_M
1bdb0 49 4e 4d 41 58 0a 2a 2a 20 20 20 20 20 53 46 5f INMAX.** SF_
1bdc0 46 69 78 65 64 4c 69 6d 69 74 20 3d 3d 20 57 48 FixedLimit == WH
1bdd0 45 52 45 5f 55 53 45 5f 4c 49 4d 49 54 0a 2a 2f ERE_USE_LIMIT.*/
1bde0 0a 23 64 65 66 69 6e 65 20 53 46 5f 44 69 73 74 .#define SF_Dist
1bdf0 69 6e 63 74 20 20 20 20 20 20 20 30 78 30 30 30 inct 0x000
1be00 30 31 20 20 2f 2a 20 4f 75 74 70 75 74 20 73 68 01 /* Output sh
1be10 6f 75 6c 64 20 62 65 20 44 49 53 54 49 4e 43 54 ould be DISTINCT
1be20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 41 */.#define SF_A
1be30 6c 6c 20 20 20 20 20 20 20 20 20 20 20 20 30 78 ll 0x
1be40 30 30 30 30 32 20 20 2f 2a 20 49 6e 63 6c 75 64 00002 /* Includ
1be50 65 73 20 74 68 65 20 41 4c 4c 20 6b 65 79 77 6f es the ALL keywo
1be60 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 rd */.#define SF
1be70 5f 52 65 73 6f 6c 76 65 64 20 20 20 20 20 20 20 _Resolved
1be80 30 78 30 30 30 30 34 20 20 2f 2a 20 49 64 65 6e 0x00004 /* Iden
1be90 74 69 66 69 65 72 73 20 68 61 76 65 20 62 65 65 tifiers have bee
1bea0 6e 20 72 65 73 6f 6c 76 65 64 20 2a 2f 0a 23 64 n resolved */.#d
1beb0 65 66 69 6e 65 20 53 46 5f 41 67 67 72 65 67 61 efine SF_Aggrega
1bec0 74 65 20 20 20 20 20 20 30 78 30 30 30 30 38 20 te 0x00008
1bed0 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 /* Contains agg
1bee0 20 66 75 6e 63 74 69 6f 6e 73 20 6f 72 20 61 20 functions or a
1bef0 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 65 66 GROUP BY */.#def
1bf00 69 6e 65 20 53 46 5f 48 61 73 41 67 67 20 20 20 ine SF_HasAgg
1bf10 20 20 20 20 20 20 30 78 30 30 30 31 30 20 20 2f 0x00010 /
1bf20 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 * Contains aggre
1bf30 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a gate functions *
1bf40 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 55 73 65 /.#define SF_Use
1bf50 73 45 70 68 65 6d 65 72 61 6c 20 20 30 78 30 30 sEphemeral 0x00
1bf60 30 32 30 20 20 2f 2a 20 55 73 65 73 20 74 68 65 020 /* Uses the
1bf70 20 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f OpenEphemeral o
1bf80 70 63 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 pcode */.#define
1bf90 20 53 46 5f 45 78 70 61 6e 64 65 64 20 20 20 20 SF_Expanded
1bfa0 20 20 20 30 78 30 30 30 34 30 20 20 2f 2a 20 73 0x00040 /* s
1bfb0 71 6c 69 74 65 33 53 65 6c 65 63 74 45 78 70 61 qlite3SelectExpa
1bfc0 6e 64 28 29 20 63 61 6c 6c 65 64 20 6f 6e 20 74 nd() called on t
1bfd0 68 69 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 his */.#define S
1bfe0 46 5f 48 61 73 54 79 70 65 49 6e 66 6f 20 20 20 F_HasTypeInfo
1bff0 20 30 78 30 30 30 38 30 20 20 2f 2a 20 46 52 4f 0x00080 /* FRO
1c000 4d 20 73 75 62 71 75 65 72 69 65 73 20 68 61 76 M subqueries hav
1c010 65 20 54 61 62 6c 65 20 6d 65 74 61 64 61 74 61 e Table metadata
1c020 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 */.#define SF_C
1c030 6f 6d 70 6f 75 6e 64 20 20 20 20 20 20 20 30 78 ompound 0x
1c040 30 30 31 30 30 20 20 2f 2a 20 50 61 72 74 20 6f 00100 /* Part o
1c050 66 20 61 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 f a compound que
1c060 72 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 ry */.#define SF
1c070 5f 56 61 6c 75 65 73 20 20 20 20 20 20 20 20 20 _Values
1c080 30 78 30 30 32 30 30 20 20 2f 2a 20 53 79 6e 74 0x00200 /* Synt
1c090 68 65 73 69 7a 65 64 20 66 72 6f 6d 20 56 41 4c hesized from VAL
1c0a0 55 45 53 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 UES clause */.#d
1c0b0 65 66 69 6e 65 20 53 46 5f 4d 75 6c 74 69 56 61 efine SF_MultiVa
1c0c0 6c 75 65 20 20 20 20 20 30 78 30 30 34 30 30 20 lue 0x00400
1c0d0 20 2f 2a 20 53 69 6e 67 6c 65 20 56 41 4c 55 45 /* Single VALUE
1c0e0 53 20 74 65 72 6d 20 77 69 74 68 20 6d 75 6c 74 S term with mult
1c0f0 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 23 64 65 iple rows */.#de
1c100 66 69 6e 65 20 53 46 5f 4e 65 73 74 65 64 46 72 fine SF_NestedFr
1c110 6f 6d 20 20 20 20 20 30 78 30 30 38 30 30 20 20 om 0x00800
1c120 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 70 61 72 /* Part of a par
1c130 65 6e 74 68 65 73 69 7a 65 64 20 46 52 4f 4d 20 enthesized FROM
1c140 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e clause */.#defin
1c150 65 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 20 e SF_MinMaxAgg
1c160 20 20 20 20 30 78 30 31 30 30 30 20 20 2f 2a 20 0x01000 /*
1c170 41 67 67 72 65 67 61 74 65 20 63 6f 6e 74 61 69 Aggregate contai
1c180 6e 69 6e 67 20 6d 69 6e 28 29 20 6f 72 20 6d 61 ning min() or ma
1c190 78 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 x() */.#define S
1c1a0 46 5f 52 65 63 75 72 73 69 76 65 20 20 20 20 20 F_Recursive
1c1b0 20 30 78 30 32 30 30 30 20 20 2f 2a 20 54 68 65 0x02000 /* The
1c1c0 20 72 65 63 75 72 73 69 76 65 20 70 61 72 74 20 recursive part
1c1d0 6f 66 20 61 20 72 65 63 75 72 73 69 76 65 20 43 of a recursive C
1c1e0 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 TE */.#define SF
1c1f0 5f 46 69 78 65 64 4c 69 6d 69 74 20 20 20 20 20 _FixedLimit
1c200 30 78 30 34 30 30 30 20 20 2f 2a 20 6e 53 65 6c 0x04000 /* nSel
1c210 65 63 74 52 6f 77 20 73 65 74 20 62 79 20 61 20 ectRow set by a
1c220 63 6f 6e 73 74 61 6e 74 20 4c 49 4d 49 54 20 2a constant LIMIT *
1c230 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 61 79 /.#define SF_May
1c240 62 65 43 6f 6e 76 65 72 74 20 20 20 30 78 30 38 beConvert 0x08
1c250 30 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 6f 6e 000 /* Need con
1c260 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 vertCompoundSele
1c270 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a ctToSubquery() *
1c280 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 6f 6e /.#define SF_Con
1c290 76 65 72 74 65 64 20 20 20 20 20 20 30 78 31 30 verted 0x10
1c2a0 30 30 30 20 20 2f 2a 20 42 79 20 63 6f 6e 76 65 000 /* By conve
1c2b0 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c 65 63 74 rtCompoundSelect
1c2c0 54 6f 53 75 62 71 75 65 72 79 28 29 20 2a 2f 0a ToSubquery() */.
1c2d0 23 64 65 66 69 6e 65 20 53 46 5f 49 6e 63 6c 75 #define SF_Inclu
1c2e0 64 65 48 69 64 64 65 6e 20 20 30 78 32 30 30 30 deHidden 0x2000
1c2f0 30 20 20 2f 2a 20 49 6e 63 6c 75 64 65 20 68 69 0 /* Include hi
1c300 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 dden columns in
1c310 6f 75 74 70 75 74 20 2a 2f 0a 0a 0a 2f 2a 0a 2a output */.../*.*
1c320 2a 20 54 68 65 20 72 65 73 75 6c 74 73 20 6f 66 * The results of
1c330 20 61 20 53 45 4c 45 43 54 20 63 61 6e 20 62 65 a SELECT can be
1c340 20 64 69 73 74 72 69 62 75 74 65 64 20 69 6e 20 distributed in
1c350 73 65 76 65 72 61 6c 20 77 61 79 73 2c 20 61 73 several ways, as
1c360 20 64 65 66 69 6e 65 64 0a 2a 2a 20 62 79 20 6f defined.** by o
1c370 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ne of the follow
1c380 69 6e 67 20 6d 61 63 72 6f 73 2e 20 20 54 68 65 ing macros. The
1c390 20 22 53 52 54 22 20 70 72 65 66 69 78 20 6d 65 "SRT" prefix me
1c3a0 61 6e 73 20 22 53 45 4c 45 43 54 20 52 65 73 75 ans "SELECT Resu
1c3b0 6c 74 0a 2a 2a 20 54 79 70 65 22 2e 0a 2a 2a 0a lt.** Type"..**.
1c3c0 2a 2a 20 20 20 20 20 53 52 54 5f 55 6e 69 6f 6e ** SRT_Union
1c3d0 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 73 Store res
1c3e0 75 6c 74 73 20 61 73 20 61 20 6b 65 79 20 69 6e ults as a key in
1c3f0 20 61 20 74 65 6d 70 6f 72 61 72 79 20 69 6e 64 a temporary ind
1c400 65 78 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 ex.**
1c410 20 20 20 20 20 20 20 20 20 20 69 64 65 6e 74 69 identi
1c420 66 69 65 64 20 62 79 20 70 44 65 73 74 2d 3e 69 fied by pDest->i
1c430 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 SDParm..**.**
1c440 20 20 53 52 54 5f 45 78 63 65 70 74 20 20 20 20 SRT_Except
1c450 20 20 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 73 Remove results
1c460 20 66 72 6f 6d 20 74 68 65 20 74 65 6d 70 6f 72 from the tempor
1c470 61 72 79 20 69 6e 64 65 78 20 70 44 65 73 74 2d ary index pDest-
1c480 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 >iSDParm..**.**
1c490 20 20 20 20 53 52 54 5f 45 78 69 73 74 73 20 20 SRT_Exists
1c4a0 20 20 20 20 53 74 6f 72 65 20 61 20 31 20 69 6e Store a 1 in
1c4b0 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 70 44 65 memory cell pDe
1c4c0 73 74 2d 3e 69 53 44 50 61 72 6d 20 69 66 20 74 st->iSDParm if t
1c4d0 68 65 20 72 65 73 75 6c 74 0a 2a 2a 20 20 20 20 he result.**
1c4e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c4f0 20 73 65 74 20 69 73 20 6e 6f 74 20 65 6d 70 74 set is not empt
1c500 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 y..**.** SRT
1c510 5f 44 69 73 63 61 72 64 20 20 20 20 20 54 68 72 _Discard Thr
1c520 6f 77 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 ow the results a
1c530 77 61 79 2e 20 20 54 68 69 73 20 69 73 20 75 73 way. This is us
1c540 65 64 20 62 79 20 53 45 4c 45 43 54 0a 2a 2a 20 ed by SELECT.**
1c550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c560 20 20 20 20 73 74 61 74 65 6d 65 6e 74 73 20 77 statements w
1c570 69 74 68 69 6e 20 74 72 69 67 67 65 72 73 20 77 ithin triggers w
1c580 68 6f 73 65 20 6f 6e 6c 79 20 70 75 72 70 6f 73 hose only purpos
1c590 65 20 69 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 e is.**
1c5a0 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 the
1c5b0 73 69 64 65 2d 65 66 66 65 63 74 73 20 6f 66 20 side-effects of
1c5c0 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a functions..**.**
1c5d0 20 41 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f 76 All of the abov
1c5e0 65 20 61 72 65 20 66 72 65 65 20 74 6f 20 69 67 e are free to ig
1c5f0 6e 6f 72 65 20 74 68 65 69 72 20 4f 52 44 45 52 nore their ORDER
1c600 20 42 59 20 63 6c 61 75 73 65 2e 20 54 68 6f 73 BY clause. Thos
1c610 65 20 74 68 61 74 0a 2a 2a 20 66 6f 6c 6c 6f 77 e that.** follow
1c620 20 6d 75 73 74 20 68 6f 6e 6f 72 20 74 68 65 20 must honor the
1c630 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e ORDER BY clause.
1c640 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4f .**.** SRT_O
1c650 75 74 70 75 74 20 20 20 20 20 20 47 65 6e 65 72 utput Gener
1c660 61 74 65 20 61 20 72 6f 77 20 6f 66 20 6f 75 74 ate a row of out
1c670 70 75 74 20 28 75 73 69 6e 67 20 74 68 65 20 4f put (using the O
1c680 50 5f 52 65 73 75 6c 74 52 6f 77 0a 2a 2a 20 20 P_ResultRow.**
1c690 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c6a0 20 20 20 6f 70 63 6f 64 65 29 20 66 6f 72 20 65 opcode) for e
1c6b0 61 63 68 20 72 6f 77 20 69 6e 20 74 68 65 20 72 ach row in the r
1c6c0 65 73 75 6c 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a esult set..**.**
1c6d0 20 20 20 20 20 53 52 54 5f 4d 65 6d 20 20 20 20 SRT_Mem
1c6e0 20 20 20 20 20 4f 6e 6c 79 20 76 61 6c 69 64 20 Only valid
1c6f0 69 66 20 74 68 65 20 72 65 73 75 6c 74 20 69 73 if the result is
1c700 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c 75 6d 6e a single column
1c710 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 ..**
1c720 20 20 20 20 20 20 20 20 20 53 74 6f 72 65 20 74 Store t
1c730 68 65 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 he first column
1c740 6f 66 20 74 68 65 20 66 69 72 73 74 20 72 65 73 of the first res
1c750 75 6c 74 20 72 6f 77 0a 2a 2a 20 20 20 20 20 20 ult row.**
1c760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 i
1c770 6e 20 72 65 67 69 73 74 65 72 20 70 44 65 73 74 n register pDest
1c780 2d 3e 69 53 44 50 61 72 6d 20 74 68 65 6e 20 61 ->iSDParm then a
1c790 62 61 6e 64 6f 6e 20 74 68 65 20 72 65 73 74 0a bandon the rest.
1c7a0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c7b0 20 20 20 20 20 20 20 6f 66 20 74 68 65 20 71 75 of the qu
1c7c0 65 72 79 2e 20 20 54 68 69 73 20 64 65 73 74 69 ery. This desti
1c7d0 6e 61 74 69 6f 6e 20 69 6d 70 6c 69 65 73 20 22 nation implies "
1c7e0 4c 49 4d 49 54 20 31 22 2e 0a 2a 2a 0a 2a 2a 20 LIMIT 1"..**.**
1c7f0 20 20 20 20 53 52 54 5f 53 65 74 20 20 20 20 20 SRT_Set
1c800 20 20 20 20 54 68 65 20 72 65 73 75 6c 74 20 6d The result m
1c810 75 73 74 20 62 65 20 61 20 73 69 6e 67 6c 65 20 ust be a single
1c820 63 6f 6c 75 6d 6e 2e 20 20 53 74 6f 72 65 20 65 column. Store e
1c830 61 63 68 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ach.**
1c840 20 20 20 20 20 20 20 20 20 20 20 72 6f 77 20 6f row o
1c850 66 20 72 65 73 75 6c 74 20 61 73 20 74 68 65 20 f result as the
1c860 6b 65 79 20 69 6e 20 74 61 62 6c 65 20 70 44 65 key in table pDe
1c870 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 st->iSDParm..**
1c880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c890 20 20 20 20 41 70 70 6c 79 20 74 68 65 20 61 66 Apply the af
1c8a0 66 69 6e 69 74 79 20 70 44 65 73 74 2d 3e 61 66 finity pDest->af
1c8b0 66 53 64 73 74 20 62 65 66 6f 72 65 20 73 74 6f fSdst before sto
1c8c0 72 69 6e 67 0a 2a 2a 20 20 20 20 20 20 20 20 20 ring.**
1c8d0 20 20 20 20 20 20 20 20 20 20 20 20 72 65 73 75 resu
1c8e0 6c 74 73 2e 20 20 55 73 65 64 20 74 6f 20 69 6d lts. Used to im
1c8f0 70 6c 65 6d 65 6e 74 20 22 49 4e 20 28 53 45 4c plement "IN (SEL
1c900 45 43 54 20 2e 2e 2e 29 22 2e 0a 2a 2a 0a 2a 2a ECT ...)"..**.**
1c910 20 20 20 20 20 53 52 54 5f 45 70 68 65 6d 54 61 SRT_EphemTa
1c920 62 20 20 20 20 43 72 65 61 74 65 20 61 6e 20 74 b Create an t
1c930 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 emporary table p
1c940 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 61 6e Dest->iSDParm an
1c950 64 20 73 74 6f 72 65 0a 2a 2a 20 20 20 20 20 20 d store.**
1c960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
1c970 68 65 20 72 65 73 75 6c 74 20 74 68 65 72 65 2e he result there.
1c980 20 54 68 65 20 63 75 72 73 6f 72 20 69 73 20 6c The cursor is l
1c990 65 66 74 20 6f 70 65 6e 20 61 66 74 65 72 0a 2a eft open after.*
1c9a0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1c9b0 20 20 20 20 20 20 72 65 74 75 72 6e 69 6e 67 2e returning.
1c9c0 20 20 54 68 69 73 20 69 73 20 6c 69 6b 65 20 53 This is like S
1c9d0 52 54 5f 54 61 62 6c 65 20 65 78 63 65 70 74 20 RT_Table except
1c9e0 74 68 61 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 that.**
1c9f0 20 20 20 20 20 20 20 20 20 20 20 20 74 68 69 73 this
1ca00 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 75 73 65 destination use
1ca10 73 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 s OP_OpenEphemer
1ca20 61 6c 20 74 6f 20 63 72 65 61 74 65 0a 2a 2a 20 al to create.**
1ca30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ca40 20 20 20 20 74 68 65 20 74 61 62 6c 65 20 66 69 the table fi
1ca50 72 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 rst..**.** S
1ca60 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 20 47 RT_Coroutine G
1ca70 65 6e 65 72 61 74 65 20 61 20 63 6f 2d 72 6f 75 enerate a co-rou
1ca80 74 69 6e 65 20 74 68 61 74 20 72 65 74 75 72 6e tine that return
1ca90 73 20 61 20 6e 65 77 20 72 6f 77 20 6f 66 0a 2a s a new row of.*
1caa0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1cab0 20 20 20 20 20 20 72 65 73 75 6c 74 73 20 65 61 results ea
1cac0 63 68 20 74 69 6d 65 20 69 74 20 69 73 20 69 6e ch time it is in
1cad0 76 6f 6b 65 64 2e 20 20 54 68 65 20 65 6e 74 72 voked. The entr
1cae0 79 20 70 6f 69 6e 74 0a 2a 2a 20 20 20 20 20 20 y point.**
1caf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
1cb00 66 20 74 68 65 20 63 6f 2d 72 6f 75 74 69 6e 65 f the co-routine
1cb10 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 72 65 is stored in re
1cb20 67 69 73 74 65 72 20 70 44 65 73 74 2d 3e 69 53 gister pDest->iS
1cb30 44 50 61 72 6d 0a 2a 2a 20 20 20 20 20 20 20 20 DParm.**
1cb40 20 20 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 and
1cb50 20 74 68 65 20 72 65 73 75 6c 74 20 72 6f 77 20 the result row
1cb60 69 73 20 73 74 6f 72 65 64 20 69 6e 20 70 44 65 is stored in pDe
1cb70 73 74 2d 3e 6e 44 65 73 74 20 72 65 67 69 73 74 st->nDest regist
1cb80 65 72 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ers.**
1cb90 20 20 20 20 20 20 20 20 20 20 20 73 74 61 72 74 start
1cba0 69 6e 67 20 77 69 74 68 20 70 44 65 73 74 2d 3e ing with pDest->
1cbb0 69 53 64 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 iSdst..**.**
1cbc0 20 53 52 54 5f 54 61 62 6c 65 20 20 20 20 20 20 SRT_Table
1cbd0 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 Store results i
1cbe0 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c n temporary tabl
1cbf0 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
1cc00 2e 0a 2a 2a 20 20 20 20 20 53 52 54 5f 46 69 66 ..** SRT_Fif
1cc10 6f 20 20 20 20 20 20 20 20 54 68 69 73 20 69 73 o This is
1cc20 20 6c 69 6b 65 20 53 52 54 5f 45 70 68 65 6d 54 like SRT_EphemT
1cc30 61 62 20 65 78 63 65 70 74 20 74 68 61 74 20 74 ab except that t
1cc40 68 65 20 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 he table.**
1cc50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1cc60 69 73 20 61 73 73 75 6d 65 64 20 74 6f 20 61 6c is assumed to al
1cc70 72 65 61 64 79 20 62 65 20 6f 70 65 6e 2e 20 20 ready be open.
1cc80 53 52 54 5f 46 69 66 6f 20 68 61 73 0a 2a 2a 20 SRT_Fifo has.**
1cc90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1cca0 20 20 20 20 74 68 65 20 61 64 64 69 74 69 6f 6e the addition
1ccb0 61 6c 20 70 72 6f 70 65 72 74 79 20 6f 66 20 62 al property of b
1ccc0 65 69 6e 67 20 61 62 6c 65 20 74 6f 20 69 67 6e eing able to ign
1ccd0 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 ore.**
1cce0 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 4f the O
1ccf0 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a RDER BY clause..
1cd00 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 **.** SRT_Di
1cd10 73 74 46 69 66 6f 20 20 20 20 53 74 6f 72 65 20 stFifo Store
1cd20 72 65 73 75 6c 74 73 20 69 6e 20 61 20 74 65 6d results in a tem
1cd30 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 porary table pDe
1cd40 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 st->iSDParm..**
1cd50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1cd60 20 20 20 20 42 75 74 20 61 6c 73 6f 20 75 73 65 But also use
1cd70 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 temporary table
1cd80 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b pDest->iSDParm+
1cd90 31 20 61 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 1 as.**
1cda0 20 20 20 20 20 20 20 20 20 20 20 20 61 20 72 65 a re
1cdb0 63 6f 72 64 20 6f 66 20 61 6c 6c 20 70 72 69 6f cord of all prio
1cdc0 72 20 72 65 73 75 6c 74 73 20 61 6e 64 20 69 67 r results and ig
1cdd0 6e 6f 72 65 20 61 6e 79 20 64 75 70 6c 69 63 61 nore any duplica
1cde0 74 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 te.**
1cdf0 20 20 20 20 20 20 20 20 20 20 72 6f 77 73 2e 20 rows.
1ce00 20 4e 61 6d 65 20 6d 65 61 6e 73 3a 20 20 22 44 Name means: "D
1ce10 69 73 74 69 6e 63 74 20 46 69 66 6f 22 2e 0a 2a istinct Fifo"..*
1ce20 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 51 75 65 *.** SRT_Que
1ce30 75 65 20 20 20 20 20 20 20 53 74 6f 72 65 20 72 ue Store r
1ce40 65 73 75 6c 74 73 20 69 6e 20 70 72 69 6f 72 69 esults in priori
1ce50 74 79 20 71 75 65 75 65 20 70 44 65 73 74 2d 3e ty queue pDest->
1ce60 69 53 44 50 61 72 6d 20 28 72 65 61 6c 6c 79 0a iSDParm (really.
1ce70 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1ce80 20 20 20 20 20 20 20 61 6e 20 69 6e 64 65 78 29 an index)
1ce90 2e 20 20 41 70 70 65 6e 64 20 61 20 73 65 71 75 . Append a sequ
1cea0 65 6e 63 65 20 6e 75 6d 62 65 72 20 73 6f 20 74 ence number so t
1ceb0 68 61 74 20 61 6c 6c 20 65 6e 74 72 69 65 73 0a hat all entries.
1cec0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1ced0 20 20 20 20 20 20 20 61 72 65 20 64 69 73 74 69 are disti
1cee0 6e 63 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 nct..**.** S
1cef0 52 54 5f 44 69 73 74 51 75 65 75 65 20 20 20 53 RT_DistQueue S
1cf00 74 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 tore results in
1cf10 70 72 69 6f 72 69 74 79 20 71 75 65 75 65 20 70 priority queue p
1cf20 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 6f 6e Dest->iSDParm on
1cf30 6c 79 20 69 66 0a 2a 2a 20 20 20 20 20 20 20 20 ly if.**
1cf40 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 the
1cf50 20 73 61 6d 65 20 72 65 63 6f 72 64 20 68 61 73 same record has
1cf60 20 6e 65 76 65 72 20 62 65 65 6e 20 73 74 6f 72 never been stor
1cf70 65 64 20 62 65 66 6f 72 65 2e 20 20 54 68 65 0a ed before. The.
1cf80 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1cf90 20 20 20 20 20 20 20 69 6e 64 65 78 20 61 74 20 index at
1cfa0 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 pDest->iSDParm+1
1cfb0 20 68 6f 6c 64 20 61 6c 6c 20 70 72 69 6f 72 20 hold all prior
1cfc0 73 74 6f 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 stores..*/.#defi
1cfd0 6e 65 20 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 ne SRT_Union
1cfe0 20 20 20 20 31 20 20 2f 2a 20 53 74 6f 72 65 20 1 /* Store
1cff0 72 65 73 75 6c 74 20 61 73 20 6b 65 79 73 20 69 result as keys i
1d000 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 n an index */.#d
1d010 65 66 69 6e 65 20 53 52 54 5f 45 78 63 65 70 74 efine SRT_Except
1d020 20 20 20 20 20 20 20 32 20 20 2f 2a 20 52 65 6d 2 /* Rem
1d030 6f 76 65 20 72 65 73 75 6c 74 20 66 72 6f 6d 20 ove result from
1d040 61 20 55 4e 49 4f 4e 20 69 6e 64 65 78 20 2a 2f a UNION index */
1d050 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 45 78 69 .#define SRT_Exi
1d060 73 74 73 20 20 20 20 20 20 20 33 20 20 2f 2a 20 sts 3 /*
1d070 53 74 6f 72 65 20 31 20 69 66 20 74 68 65 20 72 Store 1 if the r
1d080 65 73 75 6c 74 20 69 73 20 6e 6f 74 20 65 6d 70 esult is not emp
1d090 74 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ty */.#define SR
1d0a0 54 5f 44 69 73 63 61 72 64 20 20 20 20 20 20 34 T_Discard 4
1d0b0 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 73 61 76 65 /* Do not save
1d0c0 20 74 68 65 20 72 65 73 75 6c 74 73 20 61 6e 79 the results any
1d0d0 77 68 65 72 65 20 2a 2f 0a 23 64 65 66 69 6e 65 where */.#define
1d0e0 20 53 52 54 5f 46 69 66 6f 20 20 20 20 20 20 20 SRT_Fifo
1d0f0 20 20 35 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 5 /* Store re
1d100 73 75 6c 74 20 61 73 20 64 61 74 61 20 77 69 74 sult as data wit
1d110 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 h an automatic r
1d120 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 owid */.#define
1d130 53 52 54 5f 44 69 73 74 46 69 66 6f 20 20 20 20 SRT_DistFifo
1d140 20 36 20 20 2f 2a 20 4c 69 6b 65 20 53 52 54 5f 6 /* Like SRT_
1d150 46 69 66 6f 2c 20 62 75 74 20 75 6e 69 71 75 65 Fifo, but unique
1d160 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 2a 2f results only */
1d170 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 51 75 65 .#define SRT_Que
1d180 75 65 20 20 20 20 20 20 20 20 37 20 20 2f 2a 20 ue 7 /*
1d190 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e 20 Store result in
1d1a0 61 6e 20 71 75 65 75 65 20 2a 2f 0a 23 64 65 66 an queue */.#def
1d1b0 69 6e 65 20 53 52 54 5f 44 69 73 74 51 75 65 75 ine SRT_DistQueu
1d1c0 65 20 20 20 20 38 20 20 2f 2a 20 4c 69 6b 65 20 e 8 /* Like
1d1d0 53 52 54 5f 51 75 65 75 65 2c 20 62 75 74 20 75 SRT_Queue, but u
1d1e0 6e 69 71 75 65 20 72 65 73 75 6c 74 73 20 6f 6e nique results on
1d1f0 6c 79 20 2a 2f 0a 0a 2f 2a 20 54 68 65 20 4f 52 ly */../* The OR
1d200 44 45 52 20 42 59 20 63 6c 61 75 73 65 20 69 73 DER BY clause is
1d210 20 69 67 6e 6f 72 65 64 20 66 6f 72 20 61 6c 6c ignored for all
1d220 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 2a 2f of the above */
1d230 0a 23 64 65 66 69 6e 65 20 49 67 6e 6f 72 61 62 .#define Ignorab
1d240 6c 65 4f 72 64 65 72 62 79 28 58 29 20 28 28 58 leOrderby(X) ((X
1d250 2d 3e 65 44 65 73 74 29 3c 3d 53 52 54 5f 44 69 ->eDest)<=SRT_Di
1d260 73 74 51 75 65 75 65 29 0a 0a 23 64 65 66 69 6e stQueue)..#defin
1d270 65 20 53 52 54 5f 4f 75 74 70 75 74 20 20 20 20 e SRT_Output
1d280 20 20 20 39 20 20 2f 2a 20 4f 75 74 70 75 74 20 9 /* Output
1d290 65 61 63 68 20 72 6f 77 20 6f 66 20 72 65 73 75 each row of resu
1d2a0 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 lt */.#define SR
1d2b0 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 20 31 30 T_Mem 10
1d2c0 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
1d2d0 74 20 69 6e 20 61 20 6d 65 6d 6f 72 79 20 63 65 t in a memory ce
1d2e0 6c 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 ll */.#define SR
1d2f0 54 5f 53 65 74 20 20 20 20 20 20 20 20 20 31 31 T_Set 11
1d300 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
1d310 74 73 20 61 73 20 6b 65 79 73 20 69 6e 20 61 6e ts as keys in an
1d320 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e index */.#defin
1d330 65 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 20 e SRT_EphemTab
1d340 20 20 31 32 20 20 2f 2a 20 43 72 65 61 74 65 20 12 /* Create
1d350 74 72 61 6e 73 69 65 6e 74 20 74 61 62 20 61 6e transient tab an
1d360 64 20 73 74 6f 72 65 20 6c 69 6b 65 20 53 52 54 d store like SRT
1d370 5f 54 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e _Table */.#defin
1d380 65 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 e SRT_Coroutine
1d390 20 20 31 33 20 20 2f 2a 20 47 65 6e 65 72 61 74 13 /* Generat
1d3a0 65 20 61 20 73 69 6e 67 6c 65 20 72 6f 77 20 6f e a single row o
1d3b0 66 20 72 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 f result */.#def
1d3c0 69 6e 65 20 53 52 54 5f 54 61 62 6c 65 20 20 20 ine SRT_Table
1d3d0 20 20 20 20 31 34 20 20 2f 2a 20 53 74 6f 72 65 14 /* Store
1d3e0 20 72 65 73 75 6c 74 20 61 73 20 64 61 74 61 20 result as data
1d3f0 77 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 with an automati
1d400 63 20 72 6f 77 69 64 20 2a 2f 0a 0a 2f 2a 0a 2a c rowid */../*.*
1d410 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
1d420 20 74 68 69 73 20 6f 62 6a 65 63 74 20 64 65 73 this object des
1d430 63 72 69 62 65 73 20 77 68 65 72 65 20 74 6f 20 cribes where to
1d440 70 75 74 20 6f 66 20 74 68 65 20 72 65 73 75 6c put of the resul
1d450 74 73 20 6f 66 0a 2a 2a 20 61 20 53 45 4c 45 43 ts of.** a SELEC
1d460 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a T statement..*/.
1d470 73 74 72 75 63 74 20 53 65 6c 65 63 74 44 65 73 struct SelectDes
1d480 74 20 7b 0a 20 20 75 38 20 65 44 65 73 74 3b 20 t {. u8 eDest;
1d490 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 6f /* Ho
1d4a0 77 20 74 6f 20 64 69 73 70 6f 73 65 20 6f 66 20 w to dispose of
1d4b0 74 68 65 20 72 65 73 75 6c 74 73 2e 20 20 4f 6e the results. On
1d4c0 20 6f 66 20 53 52 54 5f 2a 20 61 62 6f 76 65 2e of SRT_* above.
1d4d0 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 41 66 66 */. char *zAff
1d4e0 53 64 73 74 3b 20 20 20 20 20 20 2f 2a 20 41 66 Sdst; /* Af
1d4f0 66 69 6e 69 74 79 20 75 73 65 64 20 77 68 65 6e finity used when
1d500 20 65 44 65 73 74 3d 3d 53 52 54 5f 53 65 74 20 eDest==SRT_Set
1d510 2a 2f 0a 20 20 69 6e 74 20 69 53 44 50 61 72 6d */. int iSDParm
1d520 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 70 ; /* A p
1d530 61 72 61 6d 65 74 65 72 20 75 73 65 64 20 62 79 arameter used by
1d540 20 74 68 65 20 65 44 65 73 74 20 64 69 73 70 6f the eDest dispo
1d550 73 61 6c 20 6d 65 74 68 6f 64 20 2a 2f 0a 20 20 sal method */.
1d560 69 6e 74 20 69 53 64 73 74 3b 20 20 20 20 20 20 int iSdst;
1d570 20 20 20 20 20 2f 2a 20 42 61 73 65 20 72 65 67 /* Base reg
1d580 69 73 74 65 72 20 77 68 65 72 65 20 72 65 73 75 ister where resu
1d590 6c 74 73 20 61 72 65 20 77 72 69 74 74 65 6e 20 lts are written
1d5a0 2a 2f 0a 20 20 69 6e 74 20 6e 53 64 73 74 3b 20 */. int nSdst;
1d5b0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1d5c0 62 65 72 20 6f 66 20 72 65 67 69 73 74 65 72 73 ber of registers
1d5d0 20 61 6c 6c 6f 63 61 74 65 64 20 2a 2f 0a 20 20 allocated */.
1d5e0 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 ExprList *pOrder
1d5f0 42 79 3b 20 20 2f 2a 20 4b 65 79 20 63 6f 6c 75 By; /* Key colu
1d600 6d 6e 73 20 66 6f 72 20 53 52 54 5f 51 75 65 75 mns for SRT_Queu
1d610 65 20 61 6e 64 20 53 52 54 5f 44 69 73 74 51 75 e and SRT_DistQu
1d620 65 75 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a eue */.};../*.**
1d630 20 44 75 72 69 6e 67 20 63 6f 64 65 20 67 65 6e During code gen
1d640 65 72 61 74 69 6f 6e 20 6f 66 20 73 74 61 74 65 eration of state
1d650 6d 65 6e 74 73 20 74 68 61 74 20 64 6f 20 69 6e ments that do in
1d660 73 65 72 74 73 20 69 6e 74 6f 20 41 55 54 4f 49 serts into AUTOI
1d670 4e 43 52 45 4d 45 4e 54 0a 2a 2a 20 74 61 62 6c NCREMENT.** tabl
1d680 65 73 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e es, the followin
1d690 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 73 g information is
1d6a0 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 65 attached to the
1d6b0 20 54 61 62 6c 65 2e 75 2e 61 75 74 6f 49 6e 63 Table.u.autoInc
1d6c0 2e 70 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 6f 66 .p.** pointer of
1d6d0 20 65 61 63 68 20 61 75 74 6f 69 6e 63 72 65 6d each autoincrem
1d6e0 65 6e 74 20 74 61 62 6c 65 20 74 6f 20 72 65 63 ent table to rec
1d6f0 6f 72 64 20 73 6f 6d 65 20 73 69 64 65 20 69 6e ord some side in
1d700 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 74 0a 2a formation that.*
1d710 2a 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 * the code gener
1d720 61 74 6f 72 20 6e 65 65 64 73 2e 20 20 57 65 20 ator needs. We
1d730 68 61 76 65 20 74 6f 20 6b 65 65 70 20 70 65 72 have to keep per
1d740 2d 74 61 62 6c 65 20 61 75 74 6f 69 6e 63 72 65 -table autoincre
1d750 6d 65 6e 74 0a 2a 2a 20 69 6e 66 6f 72 6d 61 74 ment.** informat
1d760 69 6f 6e 20 69 6e 20 63 61 73 65 20 69 6e 73 65 ion in case inse
1d770 72 74 73 20 61 72 65 20 64 6f 6e 65 20 77 69 74 rts are done wit
1d780 68 69 6e 20 74 72 69 67 67 65 72 73 2e 20 20 54 hin triggers. T
1d790 72 69 67 67 65 72 73 20 64 6f 20 6e 6f 74 0a 2a riggers do not.*
1d7a0 2a 20 6e 6f 72 6d 61 6c 6c 79 20 63 6f 6f 72 64 * normally coord
1d7b0 69 6e 61 74 65 20 74 68 65 69 72 20 61 63 74 69 inate their acti
1d7c0 76 69 74 69 65 73 2c 20 62 75 74 20 77 65 20 64 vities, but we d
1d7d0 6f 20 6e 65 65 64 20 74 6f 20 63 6f 6f 72 64 69 o need to coordi
1d7e0 6e 61 74 65 20 74 68 65 0a 2a 2a 20 6c 6f 61 64 nate the.** load
1d7f0 69 6e 67 20 61 6e 64 20 73 61 76 69 6e 67 20 6f ing and saving o
1d800 66 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 f autoincrement
1d810 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a information..*/.
1d820 73 74 72 75 63 74 20 41 75 74 6f 69 6e 63 49 6e struct AutoincIn
1d830 66 6f 20 7b 0a 20 20 41 75 74 6f 69 6e 63 49 6e fo {. AutoincIn
1d840 66 6f 20 2a 70 4e 65 78 74 3b 20 20 20 2f 2a 20 fo *pNext; /*
1d850 4e 65 78 74 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 Next info block
1d860 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 74 68 65 in a list of the
1d870 6d 20 61 6c 6c 20 2a 2f 0a 20 20 54 61 62 6c 65 m all */. Table
1d880 20 2a 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 *pTab;
1d890 20 2f 2a 20 54 61 62 6c 65 20 74 68 69 73 20 69 /* Table this i
1d8a0 6e 66 6f 20 62 6c 6f 63 6b 20 72 65 66 65 72 73 nfo block refers
1d8b0 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 to */. int iDb
1d8c0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
1d8d0 2a 20 49 6e 64 65 78 20 69 6e 20 73 71 6c 69 74 * Index in sqlit
1d8e0 65 33 2e 61 44 62 5b 5d 20 6f 66 20 64 61 74 61 e3.aDb[] of data
1d8f0 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 70 54 61 base holding pTa
1d900 62 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 43 74 b */. int regCt
1d910 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
1d920 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 20 Memory register
1d930 68 6f 6c 64 69 6e 67 20 74 68 65 20 72 6f 77 69 holding the rowi
1d940 64 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 7d 3b 0a d counter */.};.
1d950 0a 2f 2a 0a 2a 2a 20 53 69 7a 65 20 6f 66 20 74 ./*.** Size of t
1d960 68 65 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 0a he column cache.
1d970 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
1d980 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 0a 23 20 64 E_N_COLCACHE.# d
1d990 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 43 efine SQLITE_N_C
1d9a0 4f 4c 43 41 43 48 45 20 31 30 0a 23 65 6e 64 69 OLCACHE 10.#endi
1d9b0 66 0a 0a 2f 2a 0a 2a 2a 20 41 74 20 6c 65 61 73 f../*.** At leas
1d9c0 74 20 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f t one instance o
1d9d0 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
1d9e0 73 74 72 75 63 74 75 72 65 20 69 73 20 63 72 65 structure is cre
1d9f0 61 74 65 64 20 66 6f 72 20 65 61 63 68 0a 2a 2a ated for each.**
1da00 20 74 72 69 67 67 65 72 20 74 68 61 74 20 6d 61 trigger that ma
1da10 79 20 62 65 20 66 69 72 65 64 20 77 68 69 6c 65 y be fired while
1da20 20 70 61 72 73 69 6e 67 20 61 6e 20 49 4e 53 45 parsing an INSE
1da30 52 54 2c 20 55 50 44 41 54 45 20 6f 72 20 44 45 RT, UPDATE or DE
1da40 4c 45 54 45 0a 2a 2a 20 73 74 61 74 65 6d 65 6e LETE.** statemen
1da50 74 2e 20 41 6c 6c 20 73 75 63 68 20 6f 62 6a 65 t. All such obje
1da60 63 74 73 20 61 72 65 20 73 74 6f 72 65 64 20 69 cts are stored i
1da70 6e 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 73 n the linked lis
1da80 74 20 68 65 61 64 65 64 20 61 74 0a 2a 2a 20 50 t headed at.** P
1da90 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 67 arse.pTriggerPrg
1daa0 20 61 6e 64 20 64 65 6c 65 74 65 64 20 6f 6e 63 and deleted onc
1dab0 65 20 73 74 61 74 65 6d 65 6e 74 20 63 6f 6d 70 e statement comp
1dac0 69 6c 61 74 69 6f 6e 20 68 61 73 20 62 65 65 6e ilation has been
1dad0 0a 2a 2a 20 63 6f 6d 70 6c 65 74 65 64 2e 0a 2a .** completed..*
1dae0 2a 0a 2a 2a 20 41 20 56 64 62 65 20 73 75 62 2d *.** A Vdbe sub-
1daf0 70 72 6f 67 72 61 6d 20 74 68 61 74 20 69 6d 70 program that imp
1db00 6c 65 6d 65 6e 74 73 20 74 68 65 20 62 6f 64 79 lements the body
1db10 20 61 6e 64 20 57 48 45 4e 20 63 6c 61 75 73 65 and WHEN clause
1db20 20 6f 66 20 74 72 69 67 67 65 72 0a 2a 2a 20 54 of trigger.** T
1db30 72 69 67 67 65 72 50 72 67 2e 70 54 72 69 67 67 riggerPrg.pTrigg
1db40 65 72 2c 20 61 73 73 75 6d 69 6e 67 20 61 20 64 er, assuming a d
1db50 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 efault ON CONFLI
1db60 43 54 20 63 6c 61 75 73 65 20 6f 66 0a 2a 2a 20 CT clause of.**
1db70 54 72 69 67 67 65 72 50 72 67 2e 6f 72 63 6f 6e TriggerPrg.orcon
1db80 66 2c 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 f, is stored in
1db90 74 68 65 20 54 72 69 67 67 65 72 50 72 67 2e 70 the TriggerPrg.p
1dba0 50 72 6f 67 72 61 6d 20 76 61 72 69 61 62 6c 65 Program variable
1dbb0 2e 0a 2a 2a 20 54 68 65 20 50 61 72 73 65 2e 70 ..** The Parse.p
1dbc0 54 72 69 67 67 65 72 50 72 67 20 6c 69 73 74 20 TriggerPrg list
1dbd0 6e 65 76 65 72 20 63 6f 6e 74 61 69 6e 73 20 74 never contains t
1dbe0 77 6f 20 65 6e 74 72 69 65 73 20 77 69 74 68 20 wo entries with
1dbf0 74 68 65 20 73 61 6d 65 0a 2a 2a 20 76 61 6c 75 the same.** valu
1dc00 65 73 20 66 6f 72 20 62 6f 74 68 20 70 54 72 69 es for both pTri
1dc10 67 67 65 72 20 61 6e 64 20 6f 72 63 6f 6e 66 2e gger and orconf.
1dc20 0a 2a 2a 0a 2a 2a 20 54 68 65 20 54 72 69 67 67 .**.** The Trigg
1dc30 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b 30 erPrg.aColmask[0
1dc40 5d 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 65 ] variable is se
1dc50 74 20 74 6f 20 61 20 6d 61 73 6b 20 6f 66 20 6f t to a mask of o
1dc60 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 ld.* columns.**
1dc70 61 63 63 65 73 73 65 64 20 28 6f 72 20 73 65 74 accessed (or set
1dc80 20 74 6f 20 30 20 66 6f 72 20 74 72 69 67 67 65 to 0 for trigge
1dc90 72 73 20 66 69 72 65 64 20 61 73 20 61 20 72 65 rs fired as a re
1dca0 73 75 6c 74 20 6f 66 20 49 4e 53 45 52 54 0a 2a sult of INSERT.*
1dcb0 2a 20 73 74 61 74 65 6d 65 6e 74 73 29 2e 20 53 * statements). S
1dcc0 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65 20 54 72 imilarly, the Tr
1dcd0 69 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 iggerPrg.aColmas
1dce0 6b 5b 31 5d 20 76 61 72 69 61 62 6c 65 20 69 73 k[1] variable is
1dcf0 20 73 65 74 20 74 6f 0a 2a 2a 20 61 20 6d 61 73 set to.** a mas
1dd00 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d k of new.* colum
1dd10 6e 73 20 75 73 65 64 20 62 79 20 74 68 65 20 70 ns used by the p
1dd20 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 75 63 rogram..*/.struc
1dd30 74 20 54 72 69 67 67 65 72 50 72 67 20 7b 0a 20 t TriggerPrg {.
1dd40 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 Trigger *pTrigg
1dd50 65 72 3b 20 20 20 20 20 20 2f 2a 20 54 72 69 67 er; /* Trig
1dd60 67 65 72 20 74 68 69 73 20 70 72 6f 67 72 61 6d ger this program
1dd70 20 77 61 73 20 63 6f 64 65 64 20 66 72 6f 6d 20 was coded from
1dd80 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 72 67 20 */. TriggerPrg
1dd90 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 *pNext; /*
1dda0 4e 65 78 74 20 65 6e 74 72 79 20 69 6e 20 50 61 Next entry in Pa
1ddb0 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 rse.pTriggerPrg
1ddc0 6c 69 73 74 20 2a 2f 0a 20 20 53 75 62 50 72 6f list */. SubPro
1ddd0 67 72 61 6d 20 2a 70 50 72 6f 67 72 61 6d 3b 20 gram *pProgram;
1dde0 20 20 2f 2a 20 50 72 6f 67 72 61 6d 20 69 6d 70 /* Program imp
1ddf0 6c 65 6d 65 6e 74 69 6e 67 20 70 54 72 69 67 67 lementing pTrigg
1de00 65 72 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 20 69 er/orconf */. i
1de10 6e 74 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 nt orconf;
1de20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
1de30 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 70 6f t ON CONFLICT po
1de40 6c 69 63 79 20 2a 2f 0a 20 20 75 33 32 20 61 43 licy */. u32 aC
1de50 6f 6c 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 20 20 olmask[2];
1de60 20 20 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 6f 6c /* Masks of ol
1de70 64 2e 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d d.*, new.* colum
1de80 6e 73 20 61 63 63 65 73 73 65 64 20 2a 2f 0a 7d ns accessed */.}
1de90 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 44 62 ;../*.** The yDb
1dea0 4d 61 73 6b 20 64 61 74 61 74 79 70 65 20 66 6f Mask datatype fo
1deb0 72 20 74 68 65 20 62 69 74 6d 61 73 6b 20 6f 66 r the bitmask of
1dec0 20 61 6c 6c 20 61 74 74 61 63 68 65 64 20 64 61 all attached da
1ded0 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 66 20 tabases..*/.#if
1dee0 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 SQLITE_MAX_ATTAC
1def0 48 45 44 3e 33 30 0a 20 20 74 79 70 65 64 65 66 HED>30. typedef
1df00 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 79 unsigned char y
1df10 44 62 4d 61 73 6b 5b 28 53 51 4c 49 54 45 5f 4d DbMask[(SQLITE_M
1df20 41 58 5f 41 54 54 41 43 48 45 44 2b 39 29 2f 38 AX_ATTACHED+9)/8
1df30 5d 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 ];.# define DbMa
1df40 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 skTest(M,I) (
1df50 28 28 4d 29 5b 28 49 29 2f 38 5d 26 28 31 3c 3c ((M)[(I)/8]&(1<<
1df60 28 28 49 29 26 37 29 29 29 21 3d 30 29 0a 23 20 ((I)&7)))!=0).#
1df70 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 define DbMaskZer
1df80 6f 28 4d 29 20 20 20 20 20 20 6d 65 6d 73 65 74 o(M) memset
1df90 28 28 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 4d 29 ((M),0,sizeof(M)
1dfa0 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 ).# define DbMas
1dfb0 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 20 28 4d kSet(M,I) (M
1dfc0 29 5b 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c 28 28 )[(I)/8]|=(1<<((
1dfd0 49 29 26 37 29 29 0a 23 20 64 65 66 69 6e 65 20 I)&7)).# define
1dfe0 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 DbMaskAllZero(M)
1dff0 20 20 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b sqlite3DbMask
1e000 41 6c 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 65 66 AllZero(M).# def
1e010 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 ine DbMaskNonZer
1e020 6f 28 4d 29 20 20 20 28 73 71 6c 69 74 65 33 44 o(M) (sqlite3D
1e030 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 3d bMaskAllZero(M)=
1e040 3d 30 29 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 =0).#else. type
1e050 64 65 66 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 def unsigned int
1e060 20 79 44 62 4d 61 73 6b 3b 0a 23 20 64 65 66 69 yDbMask;.# defi
1e070 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 4d 2c ne DbMaskTest(M,
1e080 49 29 20 20 20 20 28 28 28 4d 29 26 28 28 28 79 I) (((M)&(((y
1e090 44 62 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 29 DbMask)1)<<(I)))
1e0a0 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 44 62 !=0).# define Db
1e0b0 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 20 20 MaskZero(M)
1e0c0 20 28 4d 29 3d 30 0a 23 20 64 65 66 69 6e 65 20 (M)=0.# define
1e0d0 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 DbMaskSet(M,I)
1e0e0 20 20 20 28 4d 29 7c 3d 28 28 28 79 44 62 4d 61 (M)|=(((yDbMa
1e0f0 73 6b 29 31 29 3c 3c 28 49 29 29 0a 23 20 64 65 sk)1)<<(I)).# de
1e100 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 fine DbMaskAllZe
1e110 72 6f 28 4d 29 20 20 20 28 4d 29 3d 3d 30 0a 23 ro(M) (M)==0.#
1e120 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f define DbMaskNo
1e130 6e 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 21 3d nZero(M) (M)!=
1e140 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
1e150 41 6e 20 53 51 4c 20 70 61 72 73 65 72 20 63 6f An SQL parser co
1e160 6e 74 65 78 74 2e 20 20 41 20 63 6f 70 79 20 6f ntext. A copy o
1e170 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
1e180 20 69 73 20 70 61 73 73 65 64 20 74 68 72 6f 75 is passed throu
1e190 67 68 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 72 gh.** the parser
1e1a0 20 61 6e 64 20 64 6f 77 6e 20 69 6e 74 6f 20 61 and down into a
1e1b0 6c 6c 20 74 68 65 20 70 61 72 73 65 72 20 61 63 ll the parser ac
1e1c0 74 69 6f 6e 20 72 6f 75 74 69 6e 65 20 69 6e 20 tion routine in
1e1d0 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 63 61 72 72 order to.** carr
1e1e0 79 20 61 72 6f 75 6e 64 20 69 6e 66 6f 72 6d 61 y around informa
1e1f0 74 69 6f 6e 20 74 68 61 74 20 69 73 20 67 6c 6f tion that is glo
1e200 62 61 6c 20 74 6f 20 74 68 65 20 65 6e 74 69 72 bal to the entir
1e210 65 20 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a 20 54 e parse..**.** T
1e220 68 65 20 73 74 72 75 63 74 75 72 65 20 69 73 20 he structure is
1e230 64 69 76 69 64 65 64 20 69 6e 74 6f 20 74 77 6f divided into two
1e240 20 70 61 72 74 73 2e 20 20 57 68 65 6e 20 74 68 parts. When th
1e250 65 20 70 61 72 73 65 72 20 61 6e 64 20 63 6f 64 e parser and cod
1e260 65 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 63 61 e.** generate ca
1e270 6c 6c 20 74 68 65 6d 73 65 6c 76 65 73 20 72 65 ll themselves re
1e280 63 75 72 73 69 76 65 6c 79 2c 20 74 68 65 20 66 cursively, the f
1e290 69 72 73 74 20 70 61 72 74 20 6f 66 20 74 68 65 irst part of the
1e2a0 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 69 73 structure.** is
1e2b0 20 63 6f 6e 73 74 61 6e 74 20 62 75 74 20 74 68 constant but th
1e2c0 65 20 73 65 63 6f 6e 64 20 70 61 72 74 20 69 73 e second part is
1e2d0 20 72 65 73 65 74 20 61 74 20 74 68 65 20 62 65 reset at the be
1e2e0 67 69 6e 6e 69 6e 67 20 61 6e 64 20 65 6e 64 20 ginning and end
1e2f0 6f 66 0a 2a 2a 20 65 61 63 68 20 72 65 63 75 72 of.** each recur
1e300 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 sion..**.** The
1e310 6e 54 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 20 61 nTableLock and a
1e320 54 61 62 6c 65 4c 6f 63 6b 20 76 61 72 69 61 62 TableLock variab
1e330 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 les are only use
1e340 64 20 69 66 20 74 68 65 20 73 68 61 72 65 64 2d d if the shared-
1e350 63 61 63 68 65 0a 2a 2a 20 66 65 61 74 75 72 65 cache.** feature
1e360 20 69 73 20 65 6e 61 62 6c 65 64 20 28 69 66 20 is enabled (if
1e370 73 71 6c 69 74 65 33 54 73 64 28 29 2d 3e 75 73 sqlite3Tsd()->us
1e380 65 53 68 61 72 65 64 44 61 74 61 20 69 73 20 74 eSharedData is t
1e390 72 75 65 29 2e 20 54 68 65 79 20 61 72 65 0a 2a rue). They are.*
1e3a0 2a 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 * used to store
1e3b0 74 68 65 20 73 65 74 20 6f 66 20 74 61 62 6c 65 the set of table
1e3c0 2d 6c 6f 63 6b 73 20 72 65 71 75 69 72 65 64 20 -locks required
1e3d0 62 79 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 by the statement
1e3e0 20 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d 70 69 6c being.** compil
1e3f0 65 64 2e 20 46 75 6e 63 74 69 6f 6e 20 73 71 6c ed. Function sql
1e400 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 29 20 ite3TableLock()
1e410 69 73 20 75 73 65 64 20 74 6f 20 61 64 64 20 65 is used to add e
1e420 6e 74 72 69 65 73 20 74 6f 20 74 68 65 0a 2a 2a ntries to the.**
1e430 20 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 75 63 74 list..*/.struct
1e440 20 50 61 72 73 65 20 7b 0a 20 20 73 71 6c 69 74 Parse {. sqlit
1e450 65 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 20 e3 *db;
1e460 2f 2a 20 54 68 65 20 6d 61 69 6e 20 64 61 74 61 /* The main data
1e470 62 61 73 65 20 73 74 72 75 63 74 75 72 65 20 2a base structure *
1e480 2f 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 4d 73 /. char *zErrMs
1e490 67 3b 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 g; /* An e
1e4a0 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f 0a rror message */.
1e4b0 20 20 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 Vdbe *pVdbe;
1e4c0 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 6e 67 /* An eng
1e4d0 69 6e 65 20 66 6f 72 20 65 78 65 63 75 74 69 6e ine for executin
1e4e0 67 20 64 61 74 61 62 61 73 65 20 62 79 74 65 63 g database bytec
1e4f0 6f 64 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b ode */. int rc;
1e500 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1e510 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 6f Return code fro
1e520 6d 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a 20 m execution */.
1e530 20 75 38 20 63 6f 6c 4e 61 6d 65 73 53 65 74 3b u8 colNamesSet;
1e540 20 20 20 20 20 20 2f 2a 20 54 52 55 45 20 61 66 /* TRUE af
1e550 74 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e 4e 61 6d ter OP_ColumnNam
1e560 65 20 68 61 73 20 62 65 65 6e 20 69 73 73 75 65 e has been issue
1e570 64 20 74 6f 20 70 56 64 62 65 20 2a 2f 0a 20 20 d to pVdbe */.
1e580 75 38 20 63 68 65 63 6b 53 63 68 65 6d 61 3b 20 u8 checkSchema;
1e590 20 20 20 20 20 2f 2a 20 43 61 75 73 65 73 20 73 /* Causes s
1e5a0 63 68 65 6d 61 20 63 6f 6f 6b 69 65 20 63 68 65 chema cookie che
1e5b0 63 6b 20 61 66 74 65 72 20 61 6e 20 65 72 72 6f ck after an erro
1e5c0 72 20 2a 2f 0a 20 20 75 38 20 6e 65 73 74 65 64 r */. u8 nested
1e5d0 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e ; /* N
1e5e0 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 umber of nested
1e5f0 63 61 6c 6c 73 20 74 6f 20 74 68 65 20 70 61 72 calls to the par
1e600 73 65 72 2f 63 6f 64 65 20 67 65 6e 65 72 61 74 ser/code generat
1e610 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 54 65 6d 70 or */. u8 nTemp
1e620 52 65 67 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 Reg; /*
1e630 4e 75 6d 62 65 72 20 6f 66 20 74 65 6d 70 6f 72 Number of tempor
1e640 61 72 79 20 72 65 67 69 73 74 65 72 73 20 69 6e ary registers in
1e650 20 61 54 65 6d 70 52 65 67 5b 5d 20 2a 2f 0a 20 aTempReg[] */.
1e660 20 75 38 20 69 73 4d 75 6c 74 69 57 72 69 74 65 u8 isMultiWrite
1e670 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 ; /* True if
1e680 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 6d statement may m
1e690 6f 64 69 66 79 2f 69 6e 73 65 72 74 20 6d 75 6c odify/insert mul
1e6a0 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 20 20 tiple rows */.
1e6b0 75 38 20 6d 61 79 41 62 6f 72 74 3b 20 20 20 20 u8 mayAbort;
1e6c0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1e6d0 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 74 68 statement may th
1e6e0 72 6f 77 20 61 6e 20 41 42 4f 52 54 20 65 78 63 row an ABORT exc
1e6f0 65 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 68 eption */. u8 h
1e700 61 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 20 20 20 asCompound;
1e710 20 2f 2a 20 4e 65 65 64 20 74 6f 20 69 6e 76 6f /* Need to invo
1e720 6b 65 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 ke convertCompou
1e730 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 71 75 65 ndSelectToSubque
1e740 72 79 28 29 20 2a 2f 0a 20 20 75 38 20 6f 6b 43 ry() */. u8 okC
1e750 6f 6e 73 74 46 61 63 74 6f 72 3b 20 20 20 20 2f onstFactor; /
1e760 2a 20 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 6f * OK to factor o
1e770 75 74 20 63 6f 6e 73 74 61 6e 74 73 20 2a 2f 0a ut constants */.
1e780 20 20 75 38 20 64 69 73 61 62 6c 65 4c 6f 6f 6b u8 disableLook
1e790 61 73 69 64 65 3b 20 2f 2a 20 4e 75 6d 62 65 72 aside; /* Number
1e7a0 20 6f 66 20 74 69 6d 65 73 20 6c 6f 6f 6b 61 73 of times lookas
1e7b0 69 64 65 20 68 61 73 20 62 65 65 6e 20 64 69 73 ide has been dis
1e7c0 61 62 6c 65 64 20 2a 2f 0a 20 20 75 38 20 6e 43 abled */. u8 nC
1e7d0 6f 6c 43 61 63 68 65 3b 20 20 20 20 20 20 20 20 olCache;
1e7e0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e 74 /* Number of ent
1e7f0 72 69 65 73 20 69 6e 20 61 43 6f 6c 43 61 63 68 ries in aColCach
1e800 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 61 e[] */. int nRa
1e810 6e 67 65 52 65 67 3b 20 20 20 20 20 20 20 2f 2a ngeReg; /*
1e820 20 53 69 7a 65 20 6f 66 20 74 68 65 20 74 65 6d Size of the tem
1e830 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 20 porary register
1e840 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 69 block */. int i
1e850 52 61 6e 67 65 52 65 67 3b 20 20 20 20 20 20 20 RangeReg;
1e860 2f 2a 20 46 69 72 73 74 20 72 65 67 69 73 74 65 /* First registe
1e870 72 20 69 6e 20 74 65 6d 70 6f 72 61 72 79 20 72 r in temporary r
1e880 65 67 69 73 74 65 72 20 62 6c 6f 63 6b 20 2a 2f egister block */
1e890 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 20 20 20 . int nErr;
1e8a0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1e8b0 72 20 6f 66 20 65 72 72 6f 72 73 20 73 65 65 6e r of errors seen
1e8c0 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 61 62 3b 20 */. int nTab;
1e8d0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1e8e0 6d 62 65 72 20 6f 66 20 70 72 65 76 69 6f 75 73 mber of previous
1e8f0 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 56 44 42 ly allocated VDB
1e900 45 20 63 75 72 73 6f 72 73 20 2a 2f 0a 20 20 69 E cursors */. i
1e910 6e 74 20 6e 4d 65 6d 3b 20 20 20 20 20 20 20 20 nt nMem;
1e920 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1e930 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 73 20 75 73 memory cells us
1e940 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 ed so far */. i
1e950 6e 74 20 6e 4f 70 41 6c 6c 6f 63 3b 20 20 20 20 nt nOpAlloc;
1e960 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1e970 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 74 65 64 slots allocated
1e980 20 66 6f 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 for Vdbe.aOp[]
1e990 2a 2f 0a 20 20 69 6e 74 20 73 7a 4f 70 41 6c 6c */. int szOpAll
1e9a0 6f 63 3b 20 20 20 20 20 20 20 2f 2a 20 42 79 74 oc; /* Byt
1e9b0 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 73 70 61 es of memory spa
1e9c0 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 ce allocated for
1e9d0 20 56 64 62 65 2e 61 4f 70 5b 5d 20 2a 2f 0a 20 Vdbe.aOp[] */.
1e9e0 20 69 6e 74 20 63 6b 42 61 73 65 3b 20 20 20 20 int ckBase;
1e9f0 20 20 20 20 20 20 2f 2a 20 42 61 73 65 20 72 65 /* Base re
1ea00 67 69 73 74 65 72 20 6f 66 20 64 61 74 61 20 64 gister of data d
1ea10 75 72 69 6e 67 20 63 68 65 63 6b 20 63 6f 6e 73 uring check cons
1ea20 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 traints */. int
1ea30 20 69 53 65 6c 66 54 61 62 3b 20 20 20 20 20 20 iSelfTab;
1ea40 20 20 2f 2a 20 54 61 62 6c 65 20 6f 66 20 61 6e /* Table of an
1ea50 20 69 6e 64 65 78 20 77 68 6f 73 65 20 65 78 70 index whose exp
1ea60 72 73 20 61 72 65 20 62 65 69 6e 67 20 63 6f 64 rs are being cod
1ea70 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 ed */. int iCac
1ea80 68 65 4c 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 heLevel; /*
1ea90 43 6f 6c 43 61 63 68 65 20 76 61 6c 69 64 20 77 ColCache valid w
1eaa0 68 65 6e 20 61 43 6f 6c 43 61 63 68 65 5b 5d 2e hen aColCache[].
1eab0 69 4c 65 76 65 6c 3c 3d 69 43 61 63 68 65 4c 65 iLevel<=iCacheLe
1eac0 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 vel */. int iCa
1ead0 63 68 65 43 6e 74 3b 20 20 20 20 20 20 20 2f 2a cheCnt; /*
1eae0 20 43 6f 75 6e 74 65 72 20 75 73 65 64 20 74 6f Counter used to
1eaf0 20 67 65 6e 65 72 61 74 65 20 61 43 6f 6c 43 61 generate aColCa
1eb00 63 68 65 5b 5d 2e 6c 72 75 20 76 61 6c 75 65 73 che[].lru values
1eb10 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 61 62 65 6c */. int nLabel
1eb20 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ; /* Nu
1eb30 6d 62 65 72 20 6f 66 20 6c 61 62 65 6c 73 20 75 mber of labels u
1eb40 73 65 64 20 2a 2f 0a 20 20 69 6e 74 20 2a 61 4c sed */. int *aL
1eb50 61 62 65 6c 3b 20 20 20 20 20 20 20 20 20 2f 2a abel; /*
1eb60 20 53 70 61 63 65 20 74 6f 20 68 6f 6c 64 20 74 Space to hold t
1eb70 68 65 20 6c 61 62 65 6c 73 20 2a 2f 0a 20 20 45 he labels */. E
1eb80 78 70 72 4c 69 73 74 20 2a 70 43 6f 6e 73 74 45 xprList *pConstE
1eb90 78 70 72 3b 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 xpr;/* Constant
1eba0 65 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 expressions */.
1ebb0 20 54 6f 6b 65 6e 20 63 6f 6e 73 74 72 61 69 6e Token constrain
1ebc0 74 4e 61 6d 65 3b 2f 2a 20 4e 61 6d 65 20 6f 66 tName;/* Name of
1ebd0 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 20 the constraint
1ebe0 63 75 72 72 65 6e 74 6c 79 20 62 65 69 6e 67 20 currently being
1ebf0 70 61 72 73 65 64 20 2a 2f 0a 20 20 79 44 62 4d parsed */. yDbM
1ec00 61 73 6b 20 77 72 69 74 65 4d 61 73 6b 3b 20 20 ask writeMask;
1ec10 20 2f 2a 20 53 74 61 72 74 20 61 20 77 72 69 74 /* Start a writ
1ec20 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 6f 6e e transaction on
1ec30 20 74 68 65 73 65 20 64 61 74 61 62 61 73 65 73 these databases
1ec40 20 2a 2f 0a 20 20 79 44 62 4d 61 73 6b 20 63 6f */. yDbMask co
1ec50 6f 6b 69 65 4d 61 73 6b 3b 20 20 2f 2a 20 42 69 okieMask; /* Bi
1ec60 74 6d 61 73 6b 20 6f 66 20 73 63 68 65 6d 61 20 tmask of schema
1ec70 76 65 72 69 66 69 65 64 20 64 61 74 61 62 61 73 verified databas
1ec80 65 73 20 2a 2f 0a 20 20 69 6e 74 20 72 65 67 52 es */. int regR
1ec90 6f 77 69 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 owid; /*
1eca0 52 65 67 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 Register holding
1ecb0 20 72 6f 77 69 64 20 6f 66 20 43 52 45 41 54 45 rowid of CREATE
1ecc0 20 54 41 42 4c 45 20 65 6e 74 72 79 20 2a 2f 0a TABLE entry */.
1ecd0 20 20 69 6e 74 20 72 65 67 52 6f 6f 74 3b 20 20 int regRoot;
1ece0 20 20 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 /* Regist
1ecf0 65 72 20 68 6f 6c 64 69 6e 67 20 72 6f 6f 74 20 er holding root
1ed00 70 61 67 65 20 6e 75 6d 62 65 72 20 66 6f 72 20 page number for
1ed10 6e 65 77 20 6f 62 6a 65 63 74 73 20 2a 2f 0a 20 new objects */.
1ed20 20 69 6e 74 20 6e 4d 61 78 41 72 67 3b 20 20 20 int nMaxArg;
1ed30 20 20 20 20 20 20 2f 2a 20 4d 61 78 20 61 72 67 /* Max arg
1ed40 73 20 70 61 73 73 65 64 20 74 6f 20 75 73 65 72 s passed to user
1ed50 20 66 75 6e 63 74 69 6f 6e 20 62 79 20 73 75 62 function by sub
1ed60 2d 70 72 6f 67 72 61 6d 20 2a 2f 0a 23 69 66 20 -program */.#if
1ed70 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
1ed80 4c 45 44 0a 20 20 69 6e 74 20 6e 53 65 6c 65 63 LED. int nSelec
1ed90 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 t; /* Nu
1eda0 6d 62 65 72 20 6f 66 20 53 45 4c 45 43 54 20 73 mber of SELECT s
1edb0 74 61 74 65 6d 65 6e 74 73 20 73 65 65 6e 20 2a tatements seen *
1edc0 2f 0a 20 20 69 6e 74 20 6e 53 65 6c 65 63 74 49 /. int nSelectI
1edd0 6e 64 65 6e 74 3b 20 20 20 2f 2a 20 48 6f 77 20 ndent; /* How
1ede0 66 61 72 20 74 6f 20 69 6e 64 65 6e 74 20 53 45 far to indent SE
1edf0 4c 45 43 54 54 52 41 43 45 28 29 20 6f 75 74 70 LECTTRACE() outp
1ee00 75 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 ut */.#endif.#if
1ee10 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
1ee20 5f 53 48 41 52 45 44 5f 43 41 43 48 45 0a 20 20 _SHARED_CACHE.
1ee30 69 6e 74 20 6e 54 61 62 6c 65 4c 6f 63 6b 3b 20 int nTableLock;
1ee40 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1ee50 20 6f 66 20 6c 6f 63 6b 73 20 69 6e 20 61 54 61 of locks in aTa
1ee60 62 6c 65 4c 6f 63 6b 20 2a 2f 0a 20 20 54 61 62 bleLock */. Tab
1ee70 6c 65 4c 6f 63 6b 20 2a 61 54 61 62 6c 65 4c 6f leLock *aTableLo
1ee80 63 6b 3b 20 2f 2a 20 52 65 71 75 69 72 65 64 20 ck; /* Required
1ee90 74 61 62 6c 65 20 6c 6f 63 6b 73 20 66 6f 72 20 table locks for
1eea0 73 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 shared-cache mod
1eeb0 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 41 75 e */.#endif. Au
1eec0 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 41 69 6e 63 toincInfo *pAinc
1eed0 3b 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f ; /* Informatio
1eee0 6e 20 61 62 6f 75 74 20 41 55 54 4f 49 4e 43 52 n about AUTOINCR
1eef0 45 4d 45 4e 54 20 63 6f 75 6e 74 65 72 73 20 2a EMENT counters *
1ef00 2f 0a 20 20 50 61 72 73 65 20 2a 70 54 6f 70 6c /. Parse *pTopl
1ef10 65 76 65 6c 3b 20 20 20 20 2f 2a 20 50 61 72 73 evel; /* Pars
1ef20 65 20 73 74 72 75 63 74 75 72 65 20 66 6f 72 20 e structure for
1ef30 6d 61 69 6e 20 70 72 6f 67 72 61 6d 20 28 6f 72 main program (or
1ef40 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 54 61 62 6c NULL) */. Tabl
1ef50 65 20 2a 70 54 72 69 67 67 65 72 54 61 62 3b 20 e *pTriggerTab;
1ef60 20 2f 2a 20 54 61 62 6c 65 20 74 72 69 67 67 65 /* Table trigge
1ef70 72 73 20 61 72 65 20 62 65 69 6e 67 20 63 6f 64 rs are being cod
1ef80 65 64 20 66 6f 72 20 2a 2f 0a 20 20 69 6e 74 20 ed for */. int
1ef90 61 64 64 72 43 72 54 61 62 3b 20 20 20 20 20 20 addrCrTab;
1efa0 20 2f 2a 20 41 64 64 72 65 73 73 20 6f 66 20 4f /* Address of O
1efb0 50 5f 43 72 65 61 74 65 54 61 62 6c 65 20 6f 70 P_CreateTable op
1efc0 63 6f 64 65 20 6f 6e 20 43 52 45 41 54 45 20 54 code on CREATE T
1efd0 41 42 4c 45 20 2a 2f 0a 20 20 75 33 32 20 6e 51 ABLE */. u32 nQ
1efe0 75 65 72 79 4c 6f 6f 70 3b 20 20 20 20 20 20 2f ueryLoop; /
1eff0 2a 20 45 73 74 20 6e 75 6d 62 65 72 20 6f 66 20 * Est number of
1f000 69 74 65 72 61 74 69 6f 6e 73 20 6f 66 20 61 20 iterations of a
1f010 71 75 65 72 79 20 28 31 30 2a 6c 6f 67 32 28 4e query (10*log2(N
1f020 29 29 20 2a 2f 0a 20 20 75 33 32 20 6f 6c 64 6d )) */. u32 oldm
1f030 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ask; /*
1f040 4d 61 73 6b 20 6f 66 20 6f 6c 64 2e 2a 20 63 6f Mask of old.* co
1f050 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 65 64 lumns referenced
1f060 20 2a 2f 0a 20 20 75 33 32 20 6e 65 77 6d 61 73 */. u32 newmas
1f070 6b 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 k; /* Ma
1f080 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c 75 sk of new.* colu
1f090 6d 6e 73 20 72 65 66 65 72 65 6e 63 65 64 20 2a mns referenced *
1f0a0 2f 0a 20 20 75 38 20 65 54 72 69 67 67 65 72 4f /. u8 eTriggerO
1f0b0 70 3b 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 55 p; /* TK_U
1f0c0 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 45 52 54 PDATE, TK_INSERT
1f0d0 20 6f 72 20 54 4b 5f 44 45 4c 45 54 45 20 2a 2f or TK_DELETE */
1f0e0 0a 20 20 75 38 20 65 4f 72 63 6f 6e 66 3b 20 20 . u8 eOrconf;
1f0f0 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 /* Defau
1f100 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 70 lt ON CONFLICT p
1f110 6f 6c 69 63 79 20 66 6f 72 20 74 72 69 67 67 65 olicy for trigge
1f120 72 20 73 74 65 70 73 20 2a 2f 0a 20 20 75 38 20 r steps */. u8
1f130 64 69 73 61 62 6c 65 54 72 69 67 67 65 72 73 3b disableTriggers;
1f140 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 64 69 73 /* True to dis
1f150 61 62 6c 65 20 74 72 69 67 67 65 72 73 20 2a 2f able triggers */
1f160 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .. /***********
1f170 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f180 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f190 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f1a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a ***************.
1f1b0 20 20 2a 2a 20 46 69 65 6c 64 73 20 61 62 6f 76 ** Fields abov
1f1c0 65 20 6d 75 73 74 20 62 65 20 69 6e 69 74 69 61 e must be initia
1f1d0 6c 69 7a 65 64 20 74 6f 20 7a 65 72 6f 2e 20 20 lized to zero.
1f1e0 54 68 65 20 66 69 65 6c 64 73 20 74 68 61 74 20 The fields that
1f1f0 66 6f 6c 6c 6f 77 2c 0a 20 20 2a 2a 20 64 6f 77 follow,. ** dow
1f200 6e 20 74 6f 20 74 68 65 20 62 65 67 69 6e 6e 69 n to the beginni
1f210 6e 67 20 6f 66 20 74 68 65 20 72 65 63 75 72 73 ng of the recurs
1f220 69 76 65 20 73 65 63 74 69 6f 6e 2c 20 64 6f 20 ive section, do
1f230 6e 6f 74 20 6e 65 65 64 20 74 6f 20 62 65 0a 20 not need to be.
1f240 20 2a 2a 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 ** initialized
1f250 61 73 20 74 68 65 79 20 77 69 6c 6c 20 62 65 20 as they will be
1f260 73 65 74 20 62 65 66 6f 72 65 20 62 65 69 6e 67 set before being
1f270 20 75 73 65 64 2e 20 20 54 68 65 20 62 6f 75 6e used. The boun
1f280 64 61 72 79 20 69 73 0a 20 20 2a 2a 20 64 65 74 dary is. ** det
1f290 65 72 6d 69 6e 65 64 20 62 79 20 6f 66 66 73 65 ermined by offse
1f2a0 74 6f 66 28 50 61 72 73 65 2c 61 43 6f 6c 43 61 tof(Parse,aColCa
1f2b0 63 68 65 29 2e 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a che).. ********
1f2c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f2d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f2e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f2f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f300 2a 2a 2f 0a 0a 20 20 73 74 72 75 63 74 20 79 43 **/.. struct yC
1f310 6f 6c 43 61 63 68 65 20 7b 0a 20 20 20 20 69 6e olCache {. in
1f320 74 20 69 54 61 62 6c 65 3b 20 20 20 20 20 20 20 t iTable;
1f330 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 63 75 72 /* Table cur
1f340 73 6f 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 sor number */.
1f350 20 20 69 31 36 20 69 43 6f 6c 75 6d 6e 3b 20 20 i16 iColumn;
1f360 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 /* Table
1f370 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 2a column number *
1f380 2f 0a 20 20 20 20 75 38 20 74 65 6d 70 52 65 67 /. u8 tempReg
1f390 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 69 ; /* i
1f3a0 52 65 67 20 69 73 20 61 20 74 65 6d 70 20 72 65 Reg is a temp re
1f3b0 67 69 73 74 65 72 20 74 68 61 74 20 6e 65 65 64 gister that need
1f3c0 73 20 74 6f 20 62 65 20 66 72 65 65 64 20 2a 2f s to be freed */
1f3d0 0a 20 20 20 20 69 6e 74 20 69 4c 65 76 65 6c 3b . int iLevel;
1f3e0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 /* Ne
1f3f0 73 74 69 6e 67 20 6c 65 76 65 6c 20 2a 2f 0a 20 sting level */.
1f400 20 20 20 69 6e 74 20 69 52 65 67 3b 20 20 20 20 int iReg;
1f410 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 67 20 /* Reg
1f420 77 69 74 68 20 76 61 6c 75 65 20 6f 66 20 74 68 with value of th
1f430 69 73 20 63 6f 6c 75 6d 6e 2e 20 30 20 6d 65 61 is column. 0 mea
1f440 6e 73 20 6e 6f 6e 65 2e 20 2a 2f 0a 20 20 20 20 ns none. */.
1f450 69 6e 74 20 6c 72 75 3b 20 20 20 20 20 20 20 20 int lru;
1f460 20 20 20 20 20 20 2f 2a 20 4c 65 61 73 74 20 72 /* Least r
1f470 65 63 65 6e 74 6c 79 20 75 73 65 64 20 65 6e 74 ecently used ent
1f480 72 79 20 68 61 73 20 74 68 65 20 73 6d 61 6c 6c ry has the small
1f490 65 73 74 20 76 61 6c 75 65 20 2a 2f 0a 20 20 7d est value */. }
1f4a0 20 61 43 6f 6c 43 61 63 68 65 5b 53 51 4c 49 54 aColCache[SQLIT
1f4b0 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 5d 3b 20 20 E_N_COLCACHE];
1f4c0 2f 2a 20 4f 6e 65 20 66 6f 72 20 65 61 63 68 20 /* One for each
1f4d0 63 6f 6c 75 6d 6e 20 63 61 63 68 65 20 65 6e 74 column cache ent
1f4e0 72 79 20 2a 2f 0a 20 20 69 6e 74 20 61 54 65 6d ry */. int aTem
1f4f0 70 52 65 67 5b 38 5d 3b 20 20 20 20 20 20 20 20 pReg[8];
1f500 2f 2a 20 48 6f 6c 64 69 6e 67 20 61 72 65 61 20 /* Holding area
1f510 66 6f 72 20 74 65 6d 70 6f 72 61 72 79 20 72 65 for temporary re
1f520 67 69 73 74 65 72 73 20 2a 2f 0a 20 20 54 6f 6b gisters */. Tok
1f530 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 6e 3b 20 20 en sNameToken;
1f540 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 77 69 /* Token wi
1f550 74 68 20 75 6e 71 75 61 6c 69 66 69 65 64 20 73 th unqualified s
1f560 63 68 65 6d 61 20 6f 62 6a 65 63 74 20 6e 61 6d chema object nam
1f570 65 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a 2a e */.. /*******
1f580 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f590 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f5a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f5b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f5c0 2a 0a 20 20 2a 2a 20 41 62 6f 76 65 20 69 73 20 *. ** Above is
1f5d0 63 6f 6e 73 74 61 6e 74 20 62 65 74 77 65 65 6e constant between
1f5e0 20 72 65 63 75 72 73 69 6f 6e 73 2e 20 20 42 65 recursions. Be
1f5f0 6c 6f 77 20 69 73 20 72 65 73 65 74 20 62 65 66 low is reset bef
1f600 6f 72 65 20 61 6e 64 20 61 66 74 65 72 0a 20 20 ore and after.
1f610 2a 2a 20 65 61 63 68 20 72 65 63 75 72 73 69 6f ** each recursio
1f620 6e 2e 20 20 54 68 65 20 62 6f 75 6e 64 61 72 79 n. The boundary
1f630 20 62 65 74 77 65 65 6e 20 74 68 65 73 65 20 74 between these t
1f640 77 6f 20 72 65 67 69 6f 6e 73 20 69 73 20 64 65 wo regions is de
1f650 74 65 72 6d 69 6e 65 64 0a 20 20 2a 2a 20 75 73 termined. ** us
1f660 69 6e 67 20 6f 66 66 73 65 74 6f 66 28 50 61 72 ing offsetof(Par
1f670 73 65 2c 73 4c 61 73 74 54 6f 6b 65 6e 29 20 73 se,sLastToken) s
1f680 6f 20 74 68 65 20 73 4c 61 73 74 54 6f 6b 65 6e o the sLastToken
1f690 20 66 69 65 6c 64 20 6d 75 73 74 20 62 65 20 74 field must be t
1f6a0 68 65 0a 20 20 2a 2a 20 66 69 72 73 74 20 66 69 he. ** first fi
1f6b0 65 6c 64 20 69 6e 20 74 68 65 20 72 65 63 75 72 eld in the recur
1f6c0 73 69 76 65 20 72 65 67 69 6f 6e 2e 0a 20 20 2a sive region.. *
1f6d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f6e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f6f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f700 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f710 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 54 6f 6b 65 *******/.. Toke
1f720 6e 20 73 4c 61 73 74 54 6f 6b 65 6e 3b 20 20 20 n sLastToken;
1f730 20 20 20 20 2f 2a 20 54 68 65 20 6c 61 73 74 20 /* The last
1f740 74 6f 6b 65 6e 20 70 61 72 73 65 64 20 2a 2f 0a token parsed */.
1f750 20 20 79 6e 56 61 72 20 6e 56 61 72 3b 20 20 20 ynVar nVar;
1f760 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
1f770 75 6d 62 65 72 20 6f 66 20 27 3f 27 20 76 61 72 umber of '?' var
1f780 69 61 62 6c 65 73 20 73 65 65 6e 20 69 6e 20 74 iables seen in t
1f790 68 65 20 53 51 4c 20 73 6f 20 66 61 72 20 2a 2f he SQL so far */
1f7a0 0a 20 20 75 38 20 69 50 6b 53 6f 72 74 4f 72 64 . u8 iPkSortOrd
1f7b0 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 er; /*
1f7c0 41 53 43 20 6f 72 20 44 45 53 43 20 66 6f 72 20 ASC or DESC for
1f7d0 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
1f7e0 4b 45 59 20 2a 2f 0a 20 20 75 38 20 65 78 70 6c KEY */. u8 expl
1f7f0 61 69 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 ain;
1f800 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 /* True if th
1f810 65 20 45 58 50 4c 41 49 4e 20 66 6c 61 67 20 69 e EXPLAIN flag i
1f820 73 20 66 6f 75 6e 64 20 6f 6e 20 74 68 65 20 71 s found on the q
1f830 75 65 72 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 uery */.#ifndef
1f840 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
1f850 55 41 4c 54 41 42 4c 45 0a 20 20 75 38 20 64 65 UALTABLE. u8 de
1f860 63 6c 61 72 65 56 74 61 62 3b 20 20 20 20 20 20 clareVtab;
1f870 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 /* True if
1f880 69 6e 73 69 64 65 20 73 71 6c 69 74 65 33 5f 64 inside sqlite3_d
1f890 65 63 6c 61 72 65 5f 76 74 61 62 28 29 20 2a 2f eclare_vtab() */
1f8a0 0a 20 20 69 6e 74 20 6e 56 74 61 62 4c 6f 63 6b . int nVtabLock
1f8b0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
1f8c0 4e 75 6d 62 65 72 20 6f 66 20 76 69 72 74 75 61 Number of virtua
1f8d0 6c 20 74 61 62 6c 65 73 20 74 6f 20 6c 6f 63 6b l tables to lock
1f8e0 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 */.#endif. int
1f8f0 20 6e 48 65 69 67 68 74 3b 20 20 20 20 20 20 20 nHeight;
1f900 20 20 20 20 20 20 20 2f 2a 20 45 78 70 72 65 73 /* Expres
1f910 73 69 6f 6e 20 74 72 65 65 20 68 65 69 67 68 74 sion tree height
1f920 20 6f 66 20 63 75 72 72 65 6e 74 20 73 75 62 2d of current sub-
1f930 73 65 6c 65 63 74 20 2a 2f 0a 23 69 66 6e 64 65 select */.#ifnde
1f940 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 45 58 f SQLITE_OMIT_EX
1f950 50 4c 41 49 4e 0a 20 20 69 6e 74 20 69 53 65 6c PLAIN. int iSel
1f960 65 63 74 49 64 3b 20 20 20 20 20 20 20 20 20 20 ectId;
1f970 20 20 2f 2a 20 49 44 20 6f 66 20 63 75 72 72 65 /* ID of curre
1f980 6e 74 20 73 65 6c 65 63 74 20 66 6f 72 20 45 58 nt select for EX
1f990 50 4c 41 49 4e 20 6f 75 74 70 75 74 20 2a 2f 0a PLAIN output */.
1f9a0 20 20 69 6e 74 20 69 4e 65 78 74 53 65 6c 65 63 int iNextSelec
1f9b0 74 49 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e tId; /* N
1f9c0 65 78 74 20 61 76 61 69 6c 61 62 6c 65 20 73 65 ext available se
1f9d0 6c 65 63 74 20 49 44 20 66 6f 72 20 45 58 50 4c lect ID for EXPL
1f9e0 41 49 4e 20 6f 75 74 70 75 74 20 2a 2f 0a 23 65 AIN output */.#e
1f9f0 6e 64 69 66 0a 20 20 56 4c 69 73 74 20 2a 70 56 ndif. VList *pV
1fa00 4c 69 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 List;
1fa10 20 2f 2a 20 4d 61 70 70 69 6e 67 20 62 65 74 77 /* Mapping betw
1fa20 65 65 6e 20 76 61 72 69 61 62 6c 65 20 6e 61 6d een variable nam
1fa30 65 73 20 61 6e 64 20 6e 75 6d 62 65 72 73 20 2a es and numbers *
1fa40 2f 0a 20 20 56 64 62 65 20 2a 70 52 65 70 72 65 /. Vdbe *pRepre
1fa50 70 61 72 65 3b 20 20 20 20 20 20 20 20 20 2f 2a pare; /*
1fa60 20 56 4d 20 62 65 69 6e 67 20 72 65 70 72 65 70 VM being reprep
1fa70 61 72 65 64 20 28 73 71 6c 69 74 65 33 52 65 70 ared (sqlite3Rep
1fa80 72 65 70 61 72 65 28 29 29 20 2a 2f 0a 20 20 63 repare()) */. c
1fa90 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 61 69 6c onst char *zTail
1faa0 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 ; /* All
1fab0 53 51 4c 20 74 65 78 74 20 70 61 73 74 20 74 68 SQL text past th
1fac0 65 20 6c 61 73 74 20 73 65 6d 69 63 6f 6c 6f 6e e last semicolon
1fad0 20 70 61 72 73 65 64 20 2a 2f 0a 20 20 54 61 62 parsed */. Tab
1fae0 6c 65 20 2a 70 4e 65 77 54 61 62 6c 65 3b 20 20 le *pNewTable;
1faf0 20 20 20 20 20 20 20 2f 2a 20 41 20 74 61 62 6c /* A tabl
1fb00 65 20 62 65 69 6e 67 20 63 6f 6e 73 74 72 75 63 e being construc
1fb10 74 65 64 20 62 79 20 43 52 45 41 54 45 20 54 41 ted by CREATE TA
1fb20 42 4c 45 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 BLE */. Trigger
1fb30 20 2a 70 4e 65 77 54 72 69 67 67 65 72 3b 20 20 *pNewTrigger;
1fb40 20 20 20 2f 2a 20 54 72 69 67 67 65 72 20 75 6e /* Trigger un
1fb50 64 65 72 20 63 6f 6e 73 74 72 75 63 74 20 62 79 der construct by
1fb60 20 61 20 43 52 45 41 54 45 20 54 52 49 47 47 45 a CREATE TRIGGE
1fb70 52 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 R */. const cha
1fb80 72 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b r *zAuthContext;
1fb90 20 2f 2a 20 54 68 65 20 36 74 68 20 70 61 72 61 /* The 6th para
1fba0 6d 65 74 65 72 20 74 6f 20 64 62 2d 3e 78 41 75 meter to db->xAu
1fbb0 74 68 20 63 61 6c 6c 62 61 63 6b 73 20 2a 2f 0a th callbacks */.
1fbc0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1fbd0 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
1fbe0 0a 20 20 54 6f 6b 65 6e 20 73 41 72 67 3b 20 20 . Token sArg;
1fbf0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1fc00 43 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 6f 66 Complete text of
1fc10 20 61 20 6d 6f 64 75 6c 65 20 61 72 67 75 6d 65 a module argume
1fc20 6e 74 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 2a nt */. Table **
1fc30 61 70 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 apVtabLock;
1fc40 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
1fc50 76 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 6e virtual tables n
1fc60 65 65 64 69 6e 67 20 6c 6f 63 6b 69 6e 67 20 2a eeding locking *
1fc70 2f 0a 23 65 6e 64 69 66 0a 20 20 54 61 62 6c 65 /.#endif. Table
1fc80 20 2a 70 5a 6f 6d 62 69 65 54 61 62 3b 20 20 20 *pZombieTab;
1fc90 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 /* List of
1fca0 54 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 6f Table objects to
1fcb0 20 64 65 6c 65 74 65 20 61 66 74 65 72 20 63 6f delete after co
1fcc0 64 65 20 67 65 6e 20 2a 2f 0a 20 20 54 72 69 67 de gen */. Trig
1fcd0 67 65 72 50 72 67 20 2a 70 54 72 69 67 67 65 72 gerPrg *pTrigger
1fce0 50 72 67 3b 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 Prg; /* Linked
1fcf0 6c 69 73 74 20 6f 66 20 63 6f 64 65 64 20 74 72 list of coded tr
1fd00 69 67 67 65 72 73 20 2a 2f 0a 20 20 57 69 74 68 iggers */. With
1fd10 20 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 *pWith;
1fd20 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 /* Current
1fd30 20 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 WITH clause, or
1fd40 20 4e 55 4c 4c 20 2a 2f 0a 20 20 57 69 74 68 20 NULL */. With
1fd50 2a 70 57 69 74 68 54 6f 46 72 65 65 3b 20 20 20 *pWithToFree;
1fd60 20 20 20 20 20 2f 2a 20 46 72 65 65 20 74 68 69 /* Free thi
1fd70 73 20 57 49 54 48 20 6f 62 6a 65 63 74 20 61 74 s WITH object at
1fd80 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 the end of the
1fd90 70 61 72 73 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a parse */.};../*.
1fda0 2a 2a 20 53 69 7a 65 73 20 61 6e 64 20 70 6f 69 ** Sizes and poi
1fdb0 6e 74 65 72 73 20 6f 66 20 76 61 72 69 6f 75 73 nters of various
1fdc0 20 70 61 72 74 73 20 6f 66 20 74 68 65 20 50 61 parts of the Pa
1fdd0 72 73 65 20 6f 62 6a 65 63 74 2e 0a 2a 2f 0a 23 rse object..*/.#
1fde0 64 65 66 69 6e 65 20 50 41 52 53 45 5f 48 44 52 define PARSE_HDR
1fdf0 5f 53 5a 20 6f 66 66 73 65 74 6f 66 28 50 61 72 _SZ offsetof(Par
1fe00 73 65 2c 61 43 6f 6c 43 61 63 68 65 29 20 2f 2a se,aColCache) /*
1fe10 20 52 65 63 75 72 73 69 76 65 20 70 61 72 74 20 Recursive part
1fe20 77 2f 6f 20 61 43 6f 6c 43 61 63 68 65 2a 2f 0a w/o aColCache*/.
1fe30 23 64 65 66 69 6e 65 20 50 41 52 53 45 5f 52 45 #define PARSE_RE
1fe40 43 55 52 53 45 5f 53 5a 20 6f 66 66 73 65 74 6f CURSE_SZ offseto
1fe50 66 28 50 61 72 73 65 2c 73 4c 61 73 74 54 6f 6b f(Parse,sLastTok
1fe60 65 6e 29 20 20 20 20 2f 2a 20 52 65 63 75 72 73 en) /* Recurs
1fe70 69 76 65 20 70 61 72 74 20 2a 2f 0a 23 64 65 66 ive part */.#def
1fe80 69 6e 65 20 50 41 52 53 45 5f 54 41 49 4c 5f 53 ine PARSE_TAIL_S
1fe90 5a 20 28 73 69 7a 65 6f 66 28 50 61 72 73 65 29 Z (sizeof(Parse)
1fea0 2d 50 41 52 53 45 5f 52 45 43 55 52 53 45 5f 53 -PARSE_RECURSE_S
1feb0 5a 29 20 2f 2a 20 4e 6f 6e 2d 72 65 63 75 72 73 Z) /* Non-recurs
1fec0 69 76 65 20 70 61 72 74 20 2a 2f 0a 23 64 65 66 ive part */.#def
1fed0 69 6e 65 20 50 41 52 53 45 5f 54 41 49 4c 28 58 ine PARSE_TAIL(X
1fee0 29 20 28 28 28 63 68 61 72 2a 29 28 58 29 29 2b ) (((char*)(X))+
1fef0 50 41 52 53 45 5f 52 45 43 55 52 53 45 5f 53 5a PARSE_RECURSE_SZ
1ff00 29 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f ) /* Pointer to
1ff10 20 74 61 69 6c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 tail */../*.**
1ff20 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 63 Return true if c
1ff30 75 72 72 65 6e 74 6c 79 20 69 6e 73 69 64 65 20 urrently inside
1ff40 61 6e 20 73 71 6c 69 74 65 33 5f 64 65 63 6c 61 an sqlite3_decla
1ff50 72 65 5f 76 74 61 62 28 29 20 63 61 6c 6c 2e 0a re_vtab() call..
1ff60 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
1ff70 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
1ff80 4c 45 0a 20 20 23 64 65 66 69 6e 65 20 49 4e 5f LE. #define IN_
1ff90 44 45 43 4c 41 52 45 5f 56 54 41 42 20 30 0a 23 DECLARE_VTAB 0.#
1ffa0 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 49 else. #define I
1ffb0 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 20 28 N_DECLARE_VTAB (
1ffc0 70 50 61 72 73 65 2d 3e 64 65 63 6c 61 72 65 56 pParse->declareV
1ffd0 74 61 62 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a tab).#endif../*.
1ffe0 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
1fff0 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
20000 73 74 72 75 63 74 75 72 65 20 63 61 6e 20 62 65 structure can be
20010 20 64 65 63 6c 61 72 65 64 20 6f 6e 20 61 20 73 declared on a s
20020 74 61 63 6b 20 61 6e 64 20 75 73 65 64 0a 2a 2a tack and used.**
20030 20 74 6f 20 73 61 76 65 20 74 68 65 20 50 61 72 to save the Par
20040 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 se.zAuthContext
20050 76 61 6c 75 65 20 73 6f 20 74 68 61 74 20 69 74 value so that it
20060 20 63 61 6e 20 62 65 20 72 65 73 74 6f 72 65 64 can be restored
20070 20 6c 61 74 65 72 2e 0a 2a 2f 0a 73 74 72 75 63 later..*/.struc
20080 74 20 41 75 74 68 43 6f 6e 74 65 78 74 20 7b 0a t AuthContext {.
20090 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 const char *zA
200a0 75 74 68 43 6f 6e 74 65 78 74 3b 20 20 20 2f 2a uthContext; /*
200b0 20 50 75 74 20 73 61 76 65 64 20 50 61 72 73 65 Put saved Parse
200c0 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 68 65 .zAuthContext he
200d0 72 65 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 re */. Parse *p
200e0 50 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 Parse;
200f0 20 20 20 20 2f 2a 20 54 68 65 20 50 61 72 73 65 /* The Parse
20100 20 73 74 72 75 63 74 75 72 65 20 2a 2f 0a 7d 3b structure */.};
20110 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 66 69 65 6c 64 ../*.** Bitfield
20120 20 66 6c 61 67 73 20 66 6f 72 20 50 35 20 76 61 flags for P5 va
20130 6c 75 65 20 69 6e 20 76 61 72 69 6f 75 73 20 6f lue in various o
20140 70 63 6f 64 65 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 pcodes..**.** Va
20150 6c 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 lue constraints
20160 28 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 73 (enforced via as
20170 73 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 4f sert()):.** O
20180 50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 PFLAG_LENGTHARG
20190 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e == SQLITE_FUN
201a0 43 5f 4c 45 4e 47 54 48 0a 2a 2a 20 20 20 20 4f C_LENGTH.** O
201b0 50 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 20 PFLAG_TYPEOFARG
201c0 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e == SQLITE_FUN
201d0 43 5f 54 59 50 45 4f 46 0a 2a 2a 20 20 20 20 4f C_TYPEOF.** O
201e0 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 20 PFLAG_BULKCSR
201f0 20 20 20 3d 3d 20 42 54 52 45 45 5f 42 55 4c 4b == BTREE_BULK
20200 4c 4f 41 44 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 LOAD.** OPFLA
20210 47 5f 53 45 45 4b 45 51 20 20 20 20 20 20 20 3d G_SEEKEQ =
20220 3d 20 42 54 52 45 45 5f 53 45 45 4b 5f 45 51 0a = BTREE_SEEK_EQ.
20230 2a 2a 20 20 20 20 4f 50 46 4c 41 47 5f 46 4f 52 ** OPFLAG_FOR
20240 44 45 4c 45 54 45 20 20 20 20 3d 3d 20 42 54 52 DELETE == BTR
20250 45 45 5f 46 4f 52 44 45 4c 45 54 45 0a 2a 2a 20 EE_FORDELETE.**
20260 20 20 20 4f 50 46 4c 41 47 5f 53 41 56 45 50 4f OPFLAG_SAVEPO
20270 53 49 54 49 4f 4e 20 3d 3d 20 42 54 52 45 45 5f SITION == BTREE_
20280 53 41 56 45 50 4f 53 49 54 49 4f 4e 0a 2a 2a 20 SAVEPOSITION.**
20290 20 20 20 4f 50 46 4c 41 47 5f 41 55 58 44 45 4c OPFLAG_AUXDEL
202a0 45 54 45 20 20 20 20 3d 3d 20 42 54 52 45 45 5f ETE == BTREE_
202b0 41 55 58 44 45 4c 45 54 45 0a 2a 2f 0a 23 64 65 AUXDELETE.*/.#de
202c0 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 43 48 41 fine OPFLAG_NCHA
202d0 4e 47 45 20 20 20 20 20 20 20 30 78 30 31 20 20 NGE 0x01
202e0 20 20 2f 2a 20 4f 50 5f 49 6e 73 65 72 74 3a 20 /* OP_Insert:
202f0 53 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 Set to update db
20300 2d 3e 6e 43 68 61 6e 67 65 20 2a 2f 0a 20 20 20 ->nChange */.
20310 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20320 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20330 20 20 2f 2a 20 41 6c 73 6f 20 75 73 65 64 20 69 /* Also used i
20340 6e 20 50 32 20 28 6e 6f 74 20 50 35 29 20 6f 66 n P2 (not P5) of
20350 20 4f 50 5f 44 65 6c 65 74 65 20 2a 2f 0a 23 64 OP_Delete */.#d
20360 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 45 50 48 efine OPFLAG_EPH
20370 45 4d 20 20 20 20 20 20 20 20 20 30 78 30 31 20 EM 0x01
20380 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 3a /* OP_Column:
20390 20 45 70 68 65 6d 65 72 61 6c 20 6f 75 74 70 75 Ephemeral outpu
203a0 74 20 69 73 20 6f 6b 20 2a 2f 0a 23 64 65 66 69 t is ok */.#defi
203b0 6e 65 20 4f 50 46 4c 41 47 5f 4c 41 53 54 52 4f ne OPFLAG_LASTRO
203c0 57 49 44 20 20 20 20 20 30 78 30 32 20 20 20 20 WID 0x02
203d0 2f 2a 20 53 65 74 20 74 6f 20 75 70 64 61 74 65 /* Set to update
203e0 20 64 62 2d 3e 6c 61 73 74 52 6f 77 69 64 20 2a db->lastRowid *
203f0 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
20400 5f 49 53 55 50 44 41 54 45 20 20 20 20 20 20 30 _ISUPDATE 0
20410 78 30 34 20 20 20 20 2f 2a 20 54 68 69 73 20 4f x04 /* This O
20420 50 5f 49 6e 73 65 72 74 20 69 73 20 61 6e 20 73 P_Insert is an s
20430 71 6c 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 65 ql UPDATE */.#de
20440 66 69 6e 65 20 4f 50 46 4c 41 47 5f 41 50 50 45 fine OPFLAG_APPE
20450 4e 44 20 20 20 20 20 20 20 20 30 78 30 38 20 20 ND 0x08
20460 20 20 2f 2a 20 54 68 69 73 20 69 73 20 6c 69 6b /* This is lik
20470 65 6c 79 20 74 6f 20 62 65 20 61 6e 20 61 70 70 ely to be an app
20480 65 6e 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f end */.#define O
20490 50 46 4c 41 47 5f 55 53 45 53 45 45 4b 52 45 53 PFLAG_USESEEKRES
204a0 55 4c 54 20 30 78 31 30 20 20 20 20 2f 2a 20 54 ULT 0x10 /* T
204b0 72 79 20 74 6f 20 61 76 6f 69 64 20 61 20 73 65 ry to avoid a se
204c0 65 6b 20 69 6e 20 42 74 72 65 65 49 6e 73 65 72 ek in BtreeInser
204d0 74 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 t() */.#ifdef SQ
204e0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 45 55 LITE_ENABLE_PREU
204f0 50 44 41 54 45 5f 48 4f 4f 4b 0a 23 64 65 66 69 PDATE_HOOK.#defi
20500 6e 65 20 4f 50 46 4c 41 47 5f 49 53 4e 4f 4f 50 ne OPFLAG_ISNOOP
20510 20 20 20 20 20 20 20 20 30 78 34 30 20 20 20 20 0x40
20520 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 20 64 6f 65 /* OP_Delete doe
20530 73 20 70 72 65 2d 75 70 64 61 74 65 2d 68 6f 6f s pre-update-hoo
20540 6b 20 6f 6e 6c 79 20 2a 2f 0a 23 65 6e 64 69 66 k only */.#endif
20550 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
20560 4c 45 4e 47 54 48 41 52 47 20 20 20 20 20 30 78 LENGTHARG 0x
20570 34 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 40 /* OP_Colu
20580 6d 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 mn only used for
20590 20 6c 65 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 length() */.#de
205a0 66 69 6e 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 fine OPFLAG_TYPE
205b0 4f 46 41 52 47 20 20 20 20 20 30 78 38 30 20 20 OFARG 0x80
205c0 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f /* OP_Column o
205d0 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 74 79 70 nly used for typ
205e0 65 6f 66 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 eof() */.#define
205f0 20 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 OPFLAG_BULKCSR
20600 20 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 0x01 /*
20610 20 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 OP_Open** used
20620 74 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 to open bulk cur
20630 73 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f sor */.#define O
20640 50 46 4c 41 47 5f 53 45 45 4b 45 51 20 20 20 20 PFLAG_SEEKEQ
20650 20 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 4f 0x02 /* O
20660 50 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 6f 72 20 P_Open** cursor
20670 75 73 65 73 20 45 51 20 73 65 65 6b 20 6f 6e 6c uses EQ seek onl
20680 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 y */.#define OPF
20690 4c 41 47 5f 46 4f 52 44 45 4c 45 54 45 20 20 20 LAG_FORDELETE
206a0 20 20 30 78 30 38 20 20 20 20 2f 2a 20 4f 50 5f 0x08 /* OP_
206b0 4f 70 65 6e 20 73 68 6f 75 6c 64 20 75 73 65 20 Open should use
206c0 42 54 52 45 45 5f 46 4f 52 44 45 4c 45 54 45 20 BTREE_FORDELETE
206d0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 */.#define OPFLA
206e0 47 5f 50 32 49 53 52 45 47 20 20 20 20 20 20 20 G_P2ISREG
206f0 30 78 31 30 20 20 20 20 2f 2a 20 50 32 20 74 6f 0x10 /* P2 to
20700 20 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 61 20 OP_Open** is a
20710 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 20 register number
20720 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 */.#define OPFLA
20730 47 5f 50 45 52 4d 55 54 45 20 20 20 20 20 20 20 G_PERMUTE
20740 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 0x01 /* OP_Co
20750 6d 70 61 72 65 3a 20 75 73 65 20 74 68 65 20 70 mpare: use the p
20760 65 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a 23 64 ermutation */.#d
20770 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 53 41 56 efine OPFLAG_SAV
20780 45 50 4f 53 49 54 49 4f 4e 20 20 30 78 30 32 20 EPOSITION 0x02
20790 20 20 20 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 3a /* OP_Delete:
207a0 20 6b 65 65 70 20 63 75 72 73 6f 72 20 70 6f 73 keep cursor pos
207b0 69 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 ition */.#define
207c0 20 4f 50 46 4c 41 47 5f 41 55 58 44 45 4c 45 54 OPFLAG_AUXDELET
207d0 45 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a E 0x04 /*
207e0 20 4f 50 5f 44 65 6c 65 74 65 3a 20 69 6e 64 65 OP_Delete: inde
207f0 78 20 69 6e 20 61 20 44 45 4c 45 54 45 20 6f 70 x in a DELETE op
20800 20 2a 2f 0a 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 */../*. * Each
20810 74 72 69 67 67 65 72 20 70 72 65 73 65 6e 74 20 trigger present
20820 69 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 20 in the database
20830 73 63 68 65 6d 61 20 69 73 20 73 74 6f 72 65 64 schema is stored
20840 20 61 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 as an instance
20850 6f 66 0a 20 2a 20 73 74 72 75 63 74 20 54 72 69 of. * struct Tri
20860 67 67 65 72 2e 0a 20 2a 0a 20 2a 20 50 6f 69 6e gger.. *. * Poin
20870 74 65 72 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 ters to instance
20880 73 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 s of struct Trig
20890 67 65 72 20 61 72 65 20 73 74 6f 72 65 64 20 69 ger are stored i
208a0 6e 20 74 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 n two ways.. * 1
208b0 2e 20 49 6e 20 74 68 65 20 22 74 72 69 67 48 61 . In the "trigHa
208c0 73 68 22 20 68 61 73 68 20 74 61 62 6c 65 20 28 sh" hash table (
208d0 70 61 72 74 20 6f 66 20 74 68 65 20 73 71 6c 69 part of the sqli
208e0 74 65 33 2a 20 74 68 61 74 20 72 65 70 72 65 73 te3* that repres
208f0 65 6e 74 73 20 74 68 65 0a 20 2a 20 20 20 20 64 ents the. * d
20900 61 74 61 62 61 73 65 29 2e 20 54 68 69 73 20 61 atabase). This a
20910 6c 6c 6f 77 73 20 54 72 69 67 67 65 72 20 73 74 llows Trigger st
20920 72 75 63 74 75 72 65 73 20 74 6f 20 62 65 20 72 ructures to be r
20930 65 74 72 69 65 76 65 64 20 62 79 20 6e 61 6d 65 etrieved by name
20940 2e 0a 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 67 .. * 2. All trig
20950 67 65 72 73 20 61 73 73 6f 63 69 61 74 65 64 20 gers associated
20960 77 69 74 68 20 61 20 73 69 6e 67 6c 65 20 74 61 with a single ta
20970 62 6c 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b 65 ble form a linke
20980 64 20 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 68 d list, using th
20990 65 0a 20 2a 20 20 20 20 70 4e 65 78 74 20 6d 65 e. * pNext me
209a0 6d 62 65 72 20 6f 66 20 73 74 72 75 63 74 20 54 mber of struct T
209b0 72 69 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 65 rigger. A pointe
209c0 72 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 65 r to the first e
209d0 6c 65 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 2a lement of the. *
209e0 20 20 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 linked list
209f0 69 73 20 73 74 6f 72 65 64 20 61 73 20 74 68 65 is stored as the
20a00 20 22 70 54 72 69 67 67 65 72 22 20 6d 65 6d 62 "pTrigger" memb
20a10 65 72 20 6f 66 20 74 68 65 20 61 73 73 6f 63 69 er of the associ
20a20 61 74 65 64 0a 20 2a 20 20 20 20 73 74 72 75 63 ated. * struc
20a30 74 20 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 54 t Table.. *. * T
20a40 68 65 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d he "step_list" m
20a50 65 6d 62 65 72 20 70 6f 69 6e 74 73 20 74 6f 20 ember points to
20a60 74 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e the first elemen
20a70 74 20 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c 69 t of a linked li
20a80 73 74 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 st. * containing
20a90 20 74 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 the SQL stateme
20aa0 6e 74 73 20 73 70 65 63 69 66 69 65 64 20 61 73 nts specified as
20ab0 20 74 68 65 20 74 72 69 67 67 65 72 20 70 72 6f the trigger pro
20ac0 67 72 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 74 gram.. */.struct
20ad0 20 54 72 69 67 67 65 72 20 7b 0a 20 20 63 68 61 Trigger {. cha
20ae0 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 r *zName;
20af0 20 20 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d 65 /* The name
20b00 20 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 20 of the trigger
20b10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20b20 20 20 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 72 */. char
20b30 20 2a 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 *table;
20b40 20 20 20 20 2f 2a 20 54 68 65 20 74 61 62 6c 65 /* The table
20b50 20 6f 72 20 76 69 65 77 20 74 6f 20 77 68 69 63 or view to whic
20b60 68 20 74 68 65 20 74 72 69 67 67 65 72 20 61 70 h the trigger ap
20b70 70 6c 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f 70 plies */. u8 op
20b80 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
20b90 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f /* One of TK_
20ba0 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 DELETE, TK_UPDAT
20bb0 45 2c 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 20 E, TK_INSERT
20bc0 20 20 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 5f */. u8 tr_
20bd0 74 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 tm;
20be0 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 47 /* One of TRIG
20bf0 47 45 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 47 GER_BEFORE, TRIG
20c00 47 45 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 45 GER_AFTER */. E
20c10 78 70 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 20 xpr *pWhen;
20c20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 /* The WH
20c30 45 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 EN clause of the
20c40 20 65 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 79 expression (may
20c50 20 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 49 be NULL) */. I
20c60 64 4c 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 3b dList *pColumns;
20c70 20 20 20 20 20 20 20 2f 2a 20 49 66 20 74 68 69 /* If thi
20c80 73 20 69 73 20 61 6e 20 55 50 44 41 54 45 20 4f s is an UPDATE O
20c90 46 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 F <column-list>
20ca0 74 72 69 67 67 65 72 2c 0a 20 20 20 20 20 20 20 trigger,.
20cb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20cc0 20 20 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 6d the <colum
20cd0 6e 2d 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 65 n-list> is store
20ce0 64 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 d here */. Sche
20cf0 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
20d00 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f /* Schema co
20d10 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74 72 69 ntaining the tri
20d20 67 67 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d 61 gger */. Schema
20d30 20 2a 70 54 61 62 53 63 68 65 6d 61 3b 20 20 20 *pTabSchema;
20d40 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 /* Schema cont
20d50 61 69 6e 69 6e 67 20 74 68 65 20 74 61 62 6c 65 aining the table
20d60 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 */. TriggerSte
20d70 70 20 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f 2a p *step_list; /*
20d80 20 4c 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 72 Link list of tr
20d90 69 67 67 65 72 20 70 72 6f 67 72 61 6d 20 73 74 igger program st
20da0 65 70 73 20 20 20 20 20 20 20 20 20 20 20 20 20 eps
20db0 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e */. Trigger *pN
20dc0 65 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ext; /*
20dd0 4e 65 78 74 20 74 72 69 67 67 65 72 20 61 73 73 Next trigger ass
20de0 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 ociated with the
20df0 20 74 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a table */.};../*
20e00 0a 2a 2a 20 41 20 74 72 69 67 67 65 72 20 69 73 .** A trigger is
20e10 20 65 69 74 68 65 72 20 61 20 42 45 46 4f 52 45 either a BEFORE
20e20 20 6f 72 20 61 6e 20 41 46 54 45 52 20 74 72 69 or an AFTER tri
20e30 67 67 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c 6f gger. The follo
20e40 77 69 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a 2a wing constants.*
20e50 2a 20 64 65 74 65 72 6d 69 6e 65 20 77 68 69 63 * determine whic
20e60 68 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 h..**.** If ther
20e70 65 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 20 74 e are multiple t
20e80 72 69 67 67 65 72 73 2c 20 79 6f 75 20 6d 69 67 riggers, you mig
20e90 68 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 4f 52 ht of some BEFOR
20ea0 45 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 45 52 E and some AFTER
20eb0 2e 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 61 73 ..** In that cas
20ec0 65 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 6e 74 es, the constant
20ed0 73 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 20 4f s below can be O
20ee0 52 65 64 20 74 6f 67 65 74 68 65 72 2e 0a 2a 2f Red together..*/
20ef0 0a 23 64 65 66 69 6e 65 20 54 52 49 47 47 45 52 .#define TRIGGER
20f00 5f 42 45 46 4f 52 45 20 20 31 0a 23 64 65 66 69 _BEFORE 1.#defi
20f10 6e 65 20 54 52 49 47 47 45 52 5f 41 46 54 45 52 ne TRIGGER_AFTER
20f20 20 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 2../*. * An i
20f30 6e 73 74 61 6e 63 65 20 6f 66 20 73 74 72 75 63 nstance of struc
20f40 74 20 54 72 69 67 67 65 72 53 74 65 70 20 69 73 t TriggerStep is
20f50 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 61 used to store a
20f60 20 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 single SQL stat
20f70 65 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 69 73 ement. * that is
20f80 20 61 20 70 61 72 74 20 6f 66 20 61 20 74 72 69 a part of a tri
20f90 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 0a 20 2a gger-program.. *
20fa0 0a 20 2a 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 . * Instances of
20fb0 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 struct TriggerS
20fc0 74 65 70 20 61 72 65 20 73 74 6f 72 65 64 20 69 tep are stored i
20fd0 6e 20 61 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 n a singly linke
20fe0 64 20 6c 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 d list (linked.
20ff0 2a 20 75 73 69 6e 67 20 74 68 65 20 22 70 4e 65 * using the "pNe
21000 78 74 22 20 6d 65 6d 62 65 72 29 20 72 65 66 65 xt" member) refe
21010 72 65 6e 63 65 64 20 62 79 20 74 68 65 20 22 73 renced by the "s
21020 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 tep_list" member
21030 20 6f 66 20 74 68 65 0a 20 2a 20 61 73 73 6f 63 of the. * assoc
21040 69 61 74 65 64 20 73 74 72 75 63 74 20 54 72 69 iated struct Tri
21050 67 67 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 54 gger instance. T
21060 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 he first element
21070 20 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c of the linked l
21080 69 73 74 20 69 73 0a 20 2a 20 74 68 65 20 66 69 ist is. * the fi
21090 72 73 74 20 73 74 65 70 20 6f 66 20 74 68 65 20 rst step of the
210a0 74 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e trigger-program.
210b0 0a 20 2a 0a 20 2a 20 54 68 65 20 22 6f 70 22 20 . *. * The "op"
210c0 6d 65 6d 62 65 72 20 69 6e 64 69 63 61 74 65 73 member indicates
210d0 20 77 68 65 74 68 65 72 20 74 68 69 73 20 69 73 whether this is
210e0 20 61 20 22 44 45 4c 45 54 45 22 2c 20 22 49 4e a "DELETE", "IN
210f0 53 45 52 54 22 2c 20 22 55 50 44 41 54 45 22 20 SERT", "UPDATE"
21100 6f 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 20 73 or. * "SELECT" s
21110 74 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 6d 65 tatement. The me
21120 61 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 6f 74 anings of the ot
21130 68 65 72 20 6d 65 6d 62 65 72 73 20 69 73 20 64 her members is d
21140 65 74 65 72 6d 69 6e 65 64 20 62 79 20 74 68 65 etermined by the
21150 0a 20 2a 20 76 61 6c 75 65 20 6f 66 20 22 6f 70 . * value of "op
21160 22 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 20 2a " as follows:. *
21170 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 49 4e . * (op == TK_IN
21180 53 45 52 54 29 0a 20 2a 20 6f 72 63 6f 6e 66 20 SERT). * orconf
21190 20 20 20 2d 3e 20 73 74 6f 72 65 73 20 74 68 65 -> stores the
211a0 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 61 6c 67 ON CONFLICT alg
211b0 6f 72 69 74 68 6d 0a 20 2a 20 70 53 65 6c 65 63 orithm. * pSelec
211c0 74 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 t -> If this i
211d0 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f s an INSERT INTO
211e0 20 2e 2e 2e 20 53 45 4c 45 43 54 20 2e 2e 2e 20 ... SELECT ...
211f0 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 0a statement, then.
21200 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
21210 74 68 69 73 20 73 74 6f 72 65 73 20 61 20 70 6f this stores a po
21220 69 6e 74 65 72 20 74 6f 20 74 68 65 20 53 45 4c inter to the SEL
21230 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 4f ECT statement. O
21240 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
21250 2a 20 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 * zTarget -> D
21260 65 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 equoted name of
21270 74 68 65 20 74 61 62 6c 65 20 74 6f 20 69 6e 73 the table to ins
21280 65 72 74 20 69 6e 74 6f 2e 0a 20 2a 20 70 45 78 ert into.. * pEx
21290 70 72 4c 69 73 74 20 2d 3e 20 49 66 20 74 68 69 prList -> If thi
212a0 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 s is an INSERT I
212b0 4e 54 4f 20 2e 2e 2e 20 56 41 4c 55 45 53 20 2e NTO ... VALUES .
212c0 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 .. statement, th
212d0 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 en. *
212e0 20 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 76 this stores v
212f0 61 6c 75 65 73 20 74 6f 20 62 65 20 69 6e 73 65 alues to be inse
21300 72 74 65 64 2e 20 4f 74 68 65 72 77 69 73 65 20 rted. Otherwise
21310 4e 55 4c 4c 2e 0a 20 2a 20 70 49 64 4c 69 73 74 NULL.. * pIdList
21320 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 73 -> If this is
21330 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 an INSERT INTO
21340 2e 2e 2e 20 28 3c 63 6f 6c 75 6d 6e 2d 6e 61 6d ... (<column-nam
21350 65 73 3e 29 20 56 41 4c 55 45 53 20 2e 2e 2e 0a es>) VALUES ....
21360 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
21370 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 20 statement, then
21380 74 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 20 this stores the
21390 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 74 6f 20 column-names to
213a0 62 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 be. *
213b0 20 20 20 69 6e 73 65 72 74 65 64 20 69 6e 74 6f inserted into
213c0 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 .. *. * (op == T
213d0 4b 5f 44 45 4c 45 54 45 29 0a 20 2a 20 7a 54 61 K_DELETE). * zTa
213e0 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f 74 rget -> Dequot
213f0 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 ed name of the t
21400 61 62 6c 65 20 74 6f 20 64 65 6c 65 74 65 20 66 able to delete f
21410 72 6f 6d 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 rom.. * pWhere
21420 20 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 -> The WHERE c
21430 6c 61 75 73 65 20 6f 66 20 74 68 65 20 44 45 4c lause of the DEL
21440 45 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 ETE statement if
21450 20 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 one is specifie
21460 64 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 d.. *
21470 20 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c Otherwise NUL
21480 4c 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 L.. *. * (op ==
21490 54 4b 5f 55 50 44 41 54 45 29 0a 20 2a 20 7a 54 TK_UPDATE). * zT
214a0 61 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f arget -> Dequo
214b0 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 ted name of the
214c0 74 61 62 6c 65 20 74 6f 20 75 70 64 61 74 65 2e table to update.
214d0 0a 20 2a 20 70 57 68 65 72 65 20 20 20 20 2d 3e . * pWhere ->
214e0 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 The WHERE claus
214f0 65 20 6f 66 20 74 68 65 20 55 50 44 41 54 45 20 e of the UPDATE
21500 73 74 61 74 65 6d 65 6e 74 20 69 66 20 6f 6e 65 statement if one
21510 20 69 73 20 73 70 65 63 69 66 69 65 64 2e 0a 20 is specified..
21520 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4f * O
21530 74 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 therwise NULL..
21540 2a 20 70 45 78 70 72 4c 69 73 74 20 2d 3e 20 41 * pExprList -> A
21550 20 6c 69 73 74 20 6f 66 20 74 68 65 20 63 6f 6c list of the col
21560 75 6d 6e 73 20 74 6f 20 75 70 64 61 74 65 20 61 umns to update a
21570 6e 64 20 74 68 65 20 65 78 70 72 65 73 73 69 6f nd the expressio
21580 6e 73 20 74 6f 20 75 70 64 61 74 65 0a 20 2a 20 ns to update. *
21590 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 the
215a0 6d 20 74 6f 2e 20 53 65 65 20 73 71 6c 69 74 65 m to. See sqlite
215b0 33 55 70 64 61 74 65 28 29 20 64 6f 63 75 6d 65 3Update() docume
215c0 6e 74 61 74 69 6f 6e 20 6f 66 20 22 70 43 68 61 ntation of "pCha
215d0 6e 67 65 73 22 0a 20 2a 20 20 20 20 20 20 20 20 nges". *
215e0 20 20 20 20 20 20 61 72 67 75 6d 65 6e 74 2e 0a argument..
215f0 20 2a 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 72 *. */.struct Tr
21600 69 67 67 65 72 53 74 65 70 20 7b 0a 20 20 75 38 iggerStep {. u8
21610 20 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 op;
21620 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f /* One of TK_
21630 44 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 DELETE, TK_UPDAT
21640 45 2c 20 54 4b 5f 49 4e 53 45 52 54 2c 20 54 4b E, TK_INSERT, TK
21650 5f 53 45 4c 45 43 54 20 2a 2f 0a 20 20 75 38 20 _SELECT */. u8
21660 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 orconf;
21670 20 20 2f 2a 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b /* OE_Rollback
21680 20 65 74 63 2e 20 2a 2f 0a 20 20 54 72 69 67 67 etc. */. Trigg
21690 65 72 20 2a 70 54 72 69 67 3b 20 20 20 20 20 20 er *pTrig;
216a0 2f 2a 20 54 68 65 20 74 72 69 67 67 65 72 20 74 /* The trigger t
216b0 68 61 74 20 74 68 69 73 20 73 74 65 70 20 69 73 hat this step is
216c0 20 61 20 70 61 72 74 20 6f 66 20 2a 2f 0a 20 20 a part of */.
216d0 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b Select *pSelect;
216e0 20 20 20 20 20 2f 2a 20 53 45 4c 45 43 54 20 73 /* SELECT s
216f0 74 61 74 65 6d 65 6e 74 20 6f 72 20 52 48 53 20 tatement or RHS
21700 6f 66 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 53 of INSERT INTO S
21710 45 4c 45 43 54 20 2e 2e 2e 20 2a 2f 0a 20 20 63 ELECT ... */. c
21720 68 61 72 20 2a 7a 54 61 72 67 65 74 3b 20 20 20 har *zTarget;
21730 20 20 20 20 2f 2a 20 54 61 72 67 65 74 20 74 61 /* Target ta
21740 62 6c 65 20 66 6f 72 20 44 45 4c 45 54 45 2c 20 ble for DELETE,
21750 55 50 44 41 54 45 2c 20 49 4e 53 45 52 54 20 2a UPDATE, INSERT *
21760 2f 0a 20 20 45 78 70 72 20 2a 70 57 68 65 72 65 /. Expr *pWhere
21770 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 ; /* The
21780 57 48 45 52 45 20 63 6c 61 75 73 65 20 66 6f 72 WHERE clause for
21790 20 44 45 4c 45 54 45 20 6f 72 20 55 50 44 41 54 DELETE or UPDAT
217a0 45 20 73 74 65 70 73 20 2a 2f 0a 20 20 45 78 70 E steps */. Exp
217b0 72 4c 69 73 74 20 2a 70 45 78 70 72 4c 69 73 74 rList *pExprList
217c0 3b 20 2f 2a 20 53 45 54 20 63 6c 61 75 73 65 20 ; /* SET clause
217d0 66 6f 72 20 55 50 44 41 54 45 2e 20 2a 2f 0a 20 for UPDATE. */.
217e0 20 49 64 4c 69 73 74 20 2a 70 49 64 4c 69 73 74 IdList *pIdList
217f0 3b 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 ; /* Column
21800 6e 61 6d 65 73 20 66 6f 72 20 49 4e 53 45 52 54 names for INSERT
21810 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 */. TriggerSte
21820 70 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 p *pNext; /* Ne
21830 78 74 20 69 6e 20 74 68 65 20 6c 69 6e 6b 2d 6c xt in the link-l
21840 69 73 74 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 ist */. Trigger
21850 53 74 65 70 20 2a 70 4c 61 73 74 3b 20 20 2f 2a Step *pLast; /*
21860 20 4c 61 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e Last element in
21870 20 6c 69 6e 6b 2d 6c 69 73 74 2e 20 56 61 6c 69 link-list. Vali
21880 64 20 66 6f 72 20 31 73 74 20 65 6c 65 6d 20 6f d for 1st elem o
21890 6e 6c 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a nly */.};../*.**
218a0 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 The following s
218b0 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e tructure contain
218c0 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 73 s information us
218d0 65 64 20 62 79 20 74 68 65 20 73 71 6c 69 74 65 ed by the sqlite
218e0 46 69 78 2e 2e 2e 0a 2a 2a 20 72 6f 75 74 69 6e Fix....** routin
218f0 65 73 20 61 73 20 74 68 65 79 20 77 61 6c 6b 20 es as they walk
21900 74 68 65 20 70 61 72 73 65 20 74 72 65 65 20 74 the parse tree t
21910 6f 20 6d 61 6b 65 20 64 61 74 61 62 61 73 65 20 o make database
21920 72 65 66 65 72 65 6e 63 65 73 0a 2a 2a 20 65 78 references.** ex
21930 70 6c 69 63 69 74 2e 0a 2a 2f 0a 74 79 70 65 64 plicit..*/.typed
21940 65 66 20 73 74 72 75 63 74 20 44 62 46 69 78 65 ef struct DbFixe
21950 72 20 44 62 46 69 78 65 72 3b 0a 73 74 72 75 63 r DbFixer;.struc
21960 74 20 44 62 46 69 78 65 72 20 7b 0a 20 20 50 61 t DbFixer {. Pa
21970 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 rse *pParse;
21980 20 20 2f 2a 20 54 68 65 20 70 61 72 73 69 6e 67 /* The parsing
21990 20 63 6f 6e 74 65 78 74 2e 20 20 45 72 72 6f 72 context. Error
219a0 20 6d 65 73 73 61 67 65 73 20 77 72 69 74 74 65 messages writte
219b0 6e 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 n here */. Sche
219c0 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 ma *pSchema;
219d0 2f 2a 20 46 69 78 20 69 74 65 6d 73 20 74 6f 20 /* Fix items to
219e0 74 68 69 73 20 73 63 68 65 6d 61 20 2a 2f 0a 20 this schema */.
219f0 20 69 6e 74 20 62 56 61 72 4f 6e 6c 79 3b 20 20 int bVarOnly;
21a00 20 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 66 6f /* Check fo
21a10 72 20 76 61 72 69 61 62 6c 65 20 72 65 66 65 72 r variable refer
21a20 65 6e 63 65 73 20 6f 6e 6c 79 20 2a 2f 0a 20 20 ences only */.
21a30 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 3b const char *zDb;
21a40 20 20 20 20 2f 2a 20 4d 61 6b 65 20 73 75 72 65 /* Make sure
21a50 20 61 6c 6c 20 6f 62 6a 65 63 74 73 20 61 72 65 all objects are
21a60 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 74 68 contained in th
21a70 69 73 20 64 61 74 61 62 61 73 65 20 2a 2f 0a 20 is database */.
21a80 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 79 const char *zTy
21a90 70 65 3b 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 pe; /* Type of
21aa0 74 68 65 20 63 6f 6e 74 61 69 6e 65 72 20 2d 20 the container -
21ab0 75 73 65 64 20 66 6f 72 20 65 72 72 6f 72 20 6d used for error m
21ac0 65 73 73 61 67 65 73 20 2a 2f 0a 20 20 63 6f 6e essages */. con
21ad0 73 74 20 54 6f 6b 65 6e 20 2a 70 4e 61 6d 65 3b st Token *pName;
21ae0 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 /* Name of the
21af0 63 6f 6e 74 61 69 6e 65 72 20 2d 20 75 73 65 64 container - used
21b00 20 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 for error messa
21b10 67 65 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ges */.};../*.**
21b20 20 41 6e 20 6f 62 6a 65 63 74 65 64 20 75 73 65 An objected use
21b30 64 20 74 6f 20 61 63 63 75 6d 75 6c 61 74 65 20 d to accumulate
21b40 74 68 65 20 74 65 78 74 20 6f 66 20 61 20 73 74 the text of a st
21b50 72 69 6e 67 20 77 68 65 72 65 20 77 65 0a 2a 2a ring where we.**
21b60 20 64 6f 20 6e 6f 74 20 6e 65 63 65 73 73 61 72 do not necessar
21b70 69 6c 79 20 6b 6e 6f 77 20 68 6f 77 20 62 69 67 ily know how big
21b80 20 74 68 65 20 73 74 72 69 6e 67 20 77 69 6c 6c the string will
21b90 20 62 65 20 69 6e 20 74 68 65 20 65 6e 64 2e 0a be in the end..
21ba0 2a 2f 0a 73 74 72 75 63 74 20 53 74 72 41 63 63 */.struct StrAcc
21bb0 75 6d 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a um {. sqlite3 *
21bc0 64 62 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4f db; /* O
21bd0 70 74 69 6f 6e 61 6c 20 64 61 74 61 62 61 73 65 ptional database
21be0 20 66 6f 72 20 6c 6f 6f 6b 61 73 69 64 65 2e 20 for lookaside.
21bf0 20 43 61 6e 20 62 65 20 4e 55 4c 4c 20 2a 2f 0a Can be NULL */.
21c00 20 20 63 68 61 72 20 2a 7a 42 61 73 65 3b 20 20 char *zBase;
21c10 20 20 20 20 20 20 20 2f 2a 20 41 20 62 61 73 65 /* A base
21c20 20 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 4e 6f allocation. No
21c30 74 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 2e 20 2a t from malloc. *
21c40 2f 0a 20 20 63 68 61 72 20 2a 7a 54 65 78 74 3b /. char *zText;
21c50 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
21c60 73 74 72 69 6e 67 20 63 6f 6c 6c 65 63 74 65 64 string collected
21c70 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 75 33 32 so far */. u32
21c80 20 20 6e 43 68 61 72 3b 20 20 20 20 20 20 20 20 nChar;
21c90 20 20 2f 2a 20 4c 65 6e 67 74 68 20 6f 66 20 74 /* Length of t
21ca0 68 65 20 73 74 72 69 6e 67 20 73 6f 20 66 61 72 he string so far
21cb0 20 2a 2f 0a 20 20 75 33 32 20 20 6e 41 6c 6c 6f */. u32 nAllo
21cc0 63 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6d c; /* Am
21cd0 6f 75 6e 74 20 6f 66 20 73 70 61 63 65 20 61 6c ount of space al
21ce0 6c 6f 63 61 74 65 64 20 69 6e 20 7a 54 65 78 74 located in zText
21cf0 20 2a 2f 0a 20 20 75 33 32 20 20 6d 78 41 6c 6c */. u32 mxAll
21d00 6f 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 oc; /* Ma
21d10 78 69 6d 75 6d 20 61 6c 6c 6f 77 65 64 20 61 6c ximum allowed al
21d20 6c 6f 63 61 74 69 6f 6e 2e 20 20 30 20 66 6f 72 location. 0 for
21d30 20 6e 6f 20 6d 61 6c 6c 6f 63 20 75 73 61 67 65 no malloc usage
21d40 20 2a 2f 0a 20 20 75 38 20 20 20 61 63 63 45 72 */. u8 accEr
21d50 72 6f 72 3b 20 20 20 20 20 20 20 2f 2a 20 53 54 ror; /* ST
21d60 52 41 43 43 55 4d 5f 4e 4f 4d 45 4d 20 6f 72 20 RACCUM_NOMEM or
21d70 53 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 STRACCUM_TOOBIG
21d80 2a 2f 0a 20 20 75 38 20 20 20 70 72 69 6e 74 66 */. u8 printf
21d90 46 6c 61 67 73 3b 20 20 20 20 2f 2a 20 53 51 4c Flags; /* SQL
21da0 49 54 45 5f 50 52 49 4e 54 46 20 66 6c 61 67 73 ITE_PRINTF flags
21db0 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 23 64 65 below */.};.#de
21dc0 66 69 6e 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f fine STRACCUM_NO
21dd0 4d 45 4d 20 20 20 31 0a 23 64 65 66 69 6e 65 20 MEM 1.#define
21de0 53 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 STRACCUM_TOOBIG
21df0 20 32 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 2.#define SQLIT
21e00 45 5f 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 E_PRINTF_INTERNA
21e10 4c 20 30 78 30 31 20 20 2f 2a 20 49 6e 74 65 72 L 0x01 /* Inter
21e20 6e 61 6c 2d 75 73 65 2d 6f 6e 6c 79 20 63 6f 6e nal-use-only con
21e30 76 65 72 74 65 72 73 20 61 6c 6c 6f 77 65 64 20 verters allowed
21e40 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
21e50 45 5f 50 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 E_PRINTF_SQLFUNC
21e60 20 20 30 78 30 32 20 20 2f 2a 20 53 51 4c 20 66 0x02 /* SQL f
21e70 75 6e 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 unction argument
21e80 73 20 74 6f 20 56 58 50 72 69 6e 74 66 20 2a 2f s to VXPrintf */
21e90 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
21ea0 50 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 20 PRINTF_MALLOCED
21eb0 30 78 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 0x04 /* True if
21ec0 20 78 54 65 78 74 20 69 73 20 61 6c 6c 6f 63 61 xText is alloca
21ed0 74 65 64 20 73 70 61 63 65 20 2a 2f 0a 0a 23 64 ted space */..#d
21ee0 65 66 69 6e 65 20 69 73 4d 61 6c 6c 6f 63 65 64 efine isMalloced
21ef0 28 58 29 20 20 28 28 28 58 29 2d 3e 70 72 69 6e (X) (((X)->prin
21f00 74 66 46 6c 61 67 73 20 26 20 53 51 4c 49 54 45 tfFlags & SQLITE
21f10 5f 50 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 _PRINTF_MALLOCED
21f20 29 21 3d 30 29 0a 0a 0a 2f 2a 0a 2a 2a 20 41 20 )!=0).../*.** A
21f30 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 pointer to this
21f40 73 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 structure is use
21f50 64 20 74 6f 20 63 6f 6d 6d 75 6e 69 63 61 74 65 d to communicate
21f60 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 information.**
21f70 66 72 6f 6d 20 73 71 6c 69 74 65 33 49 6e 69 74 from sqlite3Init
21f80 20 61 6e 64 20 4f 50 5f 50 61 72 73 65 53 63 68 and OP_ParseSch
21f90 65 6d 61 20 69 6e 74 6f 20 74 68 65 20 73 71 6c ema into the sql
21fa0 69 74 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b ite3InitCallback
21fb0 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 ..*/.typedef str
21fc0 75 63 74 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 uct {. sqlite3
21fd0 2a 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 *db; /* T
21fe0 68 65 20 64 61 74 61 62 61 73 65 20 62 65 69 6e he database bein
21ff0 67 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f g initialized */
22000 0a 20 20 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d . char **pzErrM
22010 73 67 3b 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 sg; /* Error
22020 6d 65 73 73 61 67 65 20 73 74 6f 72 65 64 20 68 message stored h
22030 65 72 65 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 ere */. int iDb
22040 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
22050 30 20 66 6f 72 20 6d 61 69 6e 20 64 61 74 61 62 0 for main datab
22060 61 73 65 2e 20 20 31 20 66 6f 72 20 54 45 4d 50 ase. 1 for TEMP
22070 2c 20 32 2e 2e 20 66 6f 72 20 41 54 54 41 43 48 , 2.. for ATTACH
22080 65 64 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 ed */. int rc;
22090 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 /* R
220a0 65 73 75 6c 74 20 63 6f 64 65 20 73 74 6f 72 65 esult code store
220b0 64 20 68 65 72 65 20 2a 2f 0a 7d 20 49 6e 69 74 d here */.} Init
220c0 44 61 74 61 3b 0a 0a 2f 2a 0a 2a 2a 20 53 74 72 Data;../*.** Str
220d0 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 69 6e ucture containin
220e0 67 20 67 6c 6f 62 61 6c 20 63 6f 6e 66 69 67 75 g global configu
220f0 72 61 74 69 6f 6e 20 64 61 74 61 20 66 6f 72 20 ration data for
22100 74 68 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 the SQLite libra
22110 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 ry..**.** This s
22120 74 72 75 63 74 75 72 65 20 61 6c 73 6f 20 63 6f tructure also co
22130 6e 74 61 69 6e 73 20 73 6f 6d 65 20 73 74 61 74 ntains some stat
22140 65 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a e information..*
22150 2f 0a 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 /.struct Sqlite3
22160 43 6f 6e 66 69 67 20 7b 0a 20 20 69 6e 74 20 62 Config {. int b
22170 4d 65 6d 73 74 61 74 3b 20 20 20 20 20 20 20 20 Memstat;
22180 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
22190 54 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 6d True to enable m
221a0 65 6d 6f 72 79 20 73 74 61 74 75 73 20 2a 2f 0a emory status */.
221b0 20 20 69 6e 74 20 62 43 6f 72 65 4d 75 74 65 78 int bCoreMutex
221c0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
221d0 20 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 /* True to e
221e0 6e 61 62 6c 65 20 63 6f 72 65 20 6d 75 74 65 78 nable core mutex
221f0 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 62 46 75 ing */. int bFu
22200 6c 6c 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 llMutex;
22210 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
22220 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 66 75 6c ue to enable ful
22230 6c 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 20 l mutexing */.
22240 69 6e 74 20 62 4f 70 65 6e 55 72 69 3b 20 20 20 int bOpenUri;
22250 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22260 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 69 6e 74 /* True to int
22270 65 72 70 72 65 74 20 66 69 6c 65 6e 61 6d 65 73 erpret filenames
22280 20 61 73 20 55 52 49 73 20 2a 2f 0a 20 20 69 6e as URIs */. in
22290 74 20 62 55 73 65 43 69 73 3b 20 20 20 20 20 20 t bUseCis;
222a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
222b0 2f 2a 20 55 73 65 20 63 6f 76 65 72 69 6e 67 20 /* Use covering
222c0 69 6e 64 69 63 65 73 20 66 6f 72 20 66 75 6c 6c indices for full
222d0 2d 73 63 61 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 -scans */. int
222e0 6d 78 53 74 72 6c 65 6e 3b 20 20 20 20 20 20 20 mxStrlen;
222f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
22300 20 4d 61 78 69 6d 75 6d 20 73 74 72 69 6e 67 20 Maximum string
22310 6c 65 6e 67 74 68 20 2a 2f 0a 20 20 69 6e 74 20 length */. int
22320 6e 65 76 65 72 43 6f 72 72 75 70 74 3b 20 20 20 neverCorrupt;
22330 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
22340 20 44 61 74 61 62 61 73 65 20 69 73 20 61 6c 77 Database is alw
22350 61 79 73 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 ays well-formed
22360 2a 2f 0a 20 20 69 6e 74 20 73 7a 4c 6f 6f 6b 61 */. int szLooka
22370 73 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 side;
22380 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
22390 74 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 t lookaside buff
223a0 65 72 20 73 69 7a 65 20 2a 2f 0a 20 20 69 6e 74 er size */. int
223b0 20 6e 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 nLookaside;
223c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
223d0 2a 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 * Default lookas
223e0 69 64 65 20 62 75 66 66 65 72 20 63 6f 75 6e 74 ide buffer count
223f0 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 6d 74 53 */. int nStmtS
22400 70 69 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 pill;
22410 20 20 20 20 20 20 20 20 2f 2a 20 53 74 6d 74 2d /* Stmt-
22420 6a 6f 75 72 6e 61 6c 20 73 70 69 6c 6c 2d 74 6f journal spill-to
22430 2d 64 69 73 6b 20 74 68 72 65 73 68 6f 6c 64 20 -disk threshold
22440 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 65 6d */. sqlite3_mem
22450 5f 6d 65 74 68 6f 64 73 20 6d 3b 20 20 20 20 20 _methods m;
22460 20 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 /* Low-le
22470 76 65 6c 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 vel memory alloc
22480 61 74 69 6f 6e 20 69 6e 74 65 72 66 61 63 65 20 ation interface
22490 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 */. sqlite3_mut
224a0 65 78 5f 6d 65 74 68 6f 64 73 20 6d 75 74 65 78 ex_methods mutex
224b0 3b 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 ; /* Low-le
224c0 76 65 6c 20 6d 75 74 65 78 20 69 6e 74 65 72 66 vel mutex interf
224d0 61 63 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 ace */. sqlite3
224e0 5f 70 63 61 63 68 65 5f 6d 65 74 68 6f 64 73 32 _pcache_methods2
224f0 20 70 63 61 63 68 65 32 3b 20 20 2f 2a 20 4c 6f pcache2; /* Lo
22500 77 2d 6c 65 76 65 6c 20 70 61 67 65 2d 63 61 63 w-level page-cac
22510 68 65 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a he interface */.
22520 20 20 76 6f 69 64 20 2a 70 48 65 61 70 3b 20 20 void *pHeap;
22530 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22540 20 20 20 20 2f 2a 20 48 65 61 70 20 73 74 6f 72 /* Heap stor
22550 61 67 65 20 73 70 61 63 65 20 2a 2f 0a 20 20 69 age space */. i
22560 6e 74 20 6e 48 65 61 70 3b 20 20 20 20 20 20 20 nt nHeap;
22570 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22580 20 2f 2a 20 53 69 7a 65 20 6f 66 20 70 48 65 61 /* Size of pHea
22590 70 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 p[] */. int mnR
225a0 65 71 2c 20 6d 78 52 65 71 3b 20 20 20 20 20 20 eq, mxReq;
225b0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 69 /* Mi
225c0 6e 20 61 6e 64 20 6d 61 78 20 68 65 61 70 20 72 n and max heap r
225d0 65 71 75 65 73 74 73 20 73 69 7a 65 73 20 2a 2f equests sizes */
225e0 0a 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 . sqlite3_int64
225f0 20 73 7a 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 szMmap;
22600 20 20 20 20 20 2f 2a 20 6d 6d 61 70 28 29 20 73 /* mmap() s
22610 70 61 63 65 20 70 65 72 20 6f 70 65 6e 20 66 69 pace per open fi
22620 6c 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f le */. sqlite3_
22630 69 6e 74 36 34 20 6d 78 4d 6d 61 70 3b 20 20 20 int64 mxMmap;
22640 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 /* Max
22650 69 6d 75 6d 20 76 61 6c 75 65 20 66 6f 72 20 73 imum value for s
22660 7a 4d 6d 61 70 20 2a 2f 0a 20 20 76 6f 69 64 20 zMmap */. void
22670 2a 70 53 63 72 61 74 63 68 3b 20 20 20 20 20 20 *pScratch;
22680 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
22690 53 63 72 61 74 63 68 20 6d 65 6d 6f 72 79 20 2a Scratch memory *
226a0 2f 0a 20 20 69 6e 74 20 73 7a 53 63 72 61 74 63 /. int szScratc
226b0 68 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 h;
226c0 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 /* Size of
226d0 20 65 61 63 68 20 73 63 72 61 74 63 68 20 62 75 each scratch bu
226e0 66 66 65 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 ffer */. int nS
226f0 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 20 20 cratch;
22700 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
22710 75 6d 62 65 72 20 6f 66 20 73 63 72 61 74 63 68 umber of scratch
22720 20 62 75 66 66 65 72 73 20 2a 2f 0a 20 20 76 6f buffers */. vo
22730 69 64 20 2a 70 50 61 67 65 3b 20 20 20 20 20 20 id *pPage;
22740 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22750 2f 2a 20 50 61 67 65 20 63 61 63 68 65 20 6d 65 /* Page cache me
22760 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e 74 20 73 7a mory */. int sz
22770 50 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 Page;
22780 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
22790 69 7a 65 20 6f 66 20 65 61 63 68 20 70 61 67 65 ize of each page
227a0 20 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 in pPage[] */.
227b0 20 69 6e 74 20 6e 50 61 67 65 3b 20 20 20 20 20 int nPage;
227c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
227d0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
227e0 70 61 67 65 73 20 69 6e 20 70 50 61 67 65 5b 5d pages in pPage[]
227f0 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 50 61 72 73 */. int mxPars
22800 65 72 53 74 61 63 6b 3b 20 20 20 20 20 20 20 20 erStack;
22810 20 20 20 20 20 20 20 20 2f 2a 20 6d 61 78 69 6d /* maxim
22820 75 6d 20 64 65 70 74 68 20 6f 66 20 74 68 65 20 um depth of the
22830 70 61 72 73 65 72 20 73 74 61 63 6b 20 2a 2f 0a parser stack */.
22840 20 20 69 6e 74 20 73 68 61 72 65 64 43 61 63 68 int sharedCach
22850 65 45 6e 61 62 6c 65 64 3b 20 20 20 20 20 20 20 eEnabled;
22860 20 20 20 20 2f 2a 20 74 72 75 65 20 69 66 20 73 /* true if s
22870 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 hared-cache mode
22880 20 65 6e 61 62 6c 65 64 20 2a 2f 0a 20 20 75 33 enabled */. u3
22890 32 20 73 7a 50 6d 61 3b 20 20 20 20 20 20 20 20 2 szPma;
228a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
228b0 2f 2a 20 4d 61 78 69 6d 75 6d 20 53 6f 72 74 65 /* Maximum Sorte
228c0 72 20 50 4d 41 20 73 69 7a 65 20 2a 2f 0a 20 20 r PMA size */.
228d0 2f 2a 20 54 68 65 20 61 62 6f 76 65 20 6d 69 67 /* The above mig
228e0 68 74 20 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 ht be initialize
228f0 64 20 74 6f 20 6e 6f 6e 2d 7a 65 72 6f 2e 20 20 d to non-zero.
22900 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6e 65 The following ne
22910 65 64 20 74 6f 20 61 6c 77 61 79 73 0a 20 20 2a ed to always. *
22920 2a 20 69 6e 69 74 69 61 6c 6c 79 20 62 65 20 7a * initially be z
22930 65 72 6f 2c 20 68 6f 77 65 76 65 72 2e 20 2a 2f ero, however. */
22940 0a 20 20 69 6e 74 20 69 73 49 6e 69 74 3b 20 20 . int isInit;
22950 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22960 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 /* True aft
22970 65 72 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f er initializatio
22980 6e 20 68 61 73 20 66 69 6e 69 73 68 65 64 20 2a n has finished *
22990 2f 0a 20 20 69 6e 74 20 69 6e 50 72 6f 67 72 65 /. int inProgre
229a0 73 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ss;
229b0 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 77 68 /* True wh
229c0 69 6c 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ile initializati
229d0 6f 6e 20 69 6e 20 70 72 6f 67 72 65 73 73 20 2a on in progress *
229e0 2f 0a 20 20 69 6e 74 20 69 73 4d 75 74 65 78 49 /. int isMutexI
229f0 6e 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 nit;
22a00 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 /* True af
22a10 74 65 72 20 6d 75 74 65 78 65 73 20 61 72 65 20 ter mutexes are
22a20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 initialized */.
22a30 20 69 6e 74 20 69 73 4d 61 6c 6c 6f 63 49 6e 69 int isMallocIni
22a40 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
22a50 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 /* True after
22a60 20 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 69 malloc is initi
22a70 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 alized */. int
22a80 69 73 50 43 61 63 68 65 49 6e 69 74 3b 20 20 20 isPCacheInit;
22a90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
22aa0 20 54 72 75 65 20 61 66 74 65 72 20 6d 61 6c 6c True after mall
22ab0 6f 63 20 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 oc is initialize
22ac0 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 49 d */. int nRefI
22ad0 6e 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 20 nitMutex;
22ae0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
22af0 65 72 20 6f 66 20 75 73 65 72 73 20 6f 66 20 70 er of users of p
22b00 49 6e 69 74 4d 75 74 65 78 20 2a 2f 0a 20 20 73 InitMutex */. s
22b10 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 70 49 qlite3_mutex *pI
22b20 6e 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 20 nitMutex;
22b30 20 2f 2a 20 4d 75 74 65 78 20 75 73 65 64 20 62 /* Mutex used b
22b40 79 20 73 71 6c 69 74 65 33 5f 69 6e 69 74 69 61 y sqlite3_initia
22b50 6c 69 7a 65 28 29 20 2a 2f 0a 20 20 76 6f 69 64 lize() */. void
22b60 20 28 2a 78 4c 6f 67 29 28 76 6f 69 64 2a 2c 69 (*xLog)(void*,i
22b70 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b nt,const char*);
22b80 20 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 66 6f 72 /* Function for
22b90 20 6c 6f 67 67 69 6e 67 20 2a 2f 0a 20 20 76 6f logging */. vo
22ba0 69 64 20 2a 70 4c 6f 67 41 72 67 3b 20 20 20 20 id *pLogArg;
22bb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22bc0 20 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 75 /* First argu
22bd0 6d 65 6e 74 20 74 6f 20 78 4c 6f 67 28 29 20 2a ment to xLog() *
22be0 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
22bf0 45 4e 41 42 4c 45 5f 53 51 4c 4c 4f 47 0a 20 20 ENABLE_SQLLOG.
22c00 76 6f 69 64 28 2a 78 53 71 6c 6c 6f 67 29 28 76 void(*xSqllog)(v
22c10 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 6f oid*,sqlite3*,co
22c20 6e 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 29 3b nst char*, int);
22c30 0a 20 20 76 6f 69 64 20 2a 70 53 71 6c 6c 6f 67 . void *pSqllog
22c40 41 72 67 3b 0a 23 65 6e 64 69 66 0a 23 69 66 64 Arg;.#endif.#ifd
22c50 65 66 20 53 51 4c 49 54 45 5f 56 44 42 45 5f 43 ef SQLITE_VDBE_C
22c60 4f 56 45 52 41 47 45 0a 20 20 2f 2a 20 54 68 65 OVERAGE. /* The
22c70 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 6c 6c 62 following callb
22c80 61 63 6b 20 28 69 66 20 6e 6f 74 20 4e 55 4c 4c ack (if not NULL
22c90 29 20 69 73 20 69 6e 76 6f 6b 65 64 20 6f 6e 20 ) is invoked on
22ca0 65 76 65 72 79 20 56 44 42 45 20 62 72 61 6e 63 every VDBE branc
22cb0 68 0a 20 20 2a 2a 20 6f 70 65 72 61 74 69 6f 6e h. ** operation
22cc0 2e 20 20 53 65 74 20 74 68 65 20 63 61 6c 6c 62 . Set the callb
22cd0 61 63 6b 20 75 73 69 6e 67 20 53 51 4c 49 54 45 ack using SQLITE
22ce0 5f 54 45 53 54 43 54 52 4c 5f 56 44 42 45 5f 43 _TESTCTRL_VDBE_C
22cf0 4f 56 45 52 41 47 45 2e 0a 20 20 2a 2f 0a 20 20 OVERAGE.. */.
22d00 76 6f 69 64 20 28 2a 78 56 64 62 65 42 72 61 6e void (*xVdbeBran
22d10 63 68 29 28 76 6f 69 64 2a 2c 69 6e 74 20 69 53 ch)(void*,int iS
22d20 72 63 4c 69 6e 65 2c 75 38 20 65 54 68 69 73 2c rcLine,u8 eThis,
22d30 75 38 20 65 4d 78 29 3b 20 20 2f 2a 20 43 61 6c u8 eMx); /* Cal
22d40 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 lback */. void
22d50 2a 70 56 64 62 65 42 72 61 6e 63 68 41 72 67 3b *pVdbeBranchArg;
22d60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22d70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22d80 20 20 20 20 20 2f 2a 20 31 73 74 20 61 72 67 75 /* 1st argu
22d90 6d 65 6e 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 ment */.#endif.#
22da0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e ifndef SQLITE_UN
22db0 54 45 53 54 41 42 4c 45 0a 20 20 69 6e 74 20 28 TESTABLE. int (
22dc0 2a 78 54 65 73 74 43 61 6c 6c 62 61 63 6b 29 28 *xTestCallback)(
22dd0 69 6e 74 29 3b 20 20 20 20 20 20 20 20 2f 2a 20 int); /*
22de0 49 6e 76 6f 6b 65 64 20 62 79 20 73 71 6c 69 74 Invoked by sqlit
22df0 65 33 46 61 75 6c 74 53 69 6d 28 29 20 2a 2f 0a e3FaultSim() */.
22e00 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 62 4c 6f #endif. int bLo
22e10 63 61 6c 74 69 6d 65 46 61 75 6c 74 3b 20 20 20 caltimeFault;
22e20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
22e30 75 65 20 74 6f 20 66 61 69 6c 20 6c 6f 63 61 6c ue to fail local
22e40 74 69 6d 65 28 29 20 63 61 6c 6c 73 20 2a 2f 0a time() calls */.
22e50 20 20 69 6e 74 20 69 4f 6e 63 65 52 65 73 65 74 int iOnceReset
22e60 54 68 72 65 73 68 6f 6c 64 3b 20 20 20 20 20 20 Threshold;
22e70 20 20 20 20 2f 2a 20 57 68 65 6e 20 74 6f 20 72 /* When to r
22e80 65 73 65 74 20 4f 50 5f 4f 6e 63 65 20 63 6f 75 eset OP_Once cou
22e90 6e 74 65 72 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a nters */.};../*.
22ea0 2a 2a 20 54 68 69 73 20 6d 61 63 72 6f 20 69 73 ** This macro is
22eb0 20 75 73 65 64 20 69 6e 73 69 64 65 20 6f 66 20 used inside of
22ec0 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
22ed0 6e 74 73 20 74 6f 20 69 6e 64 69 63 61 74 65 20 nts to indicate
22ee0 74 68 61 74 0a 2a 2a 20 74 68 65 20 61 73 73 65 that.** the asse
22ef0 72 74 20 69 73 20 6f 6e 6c 79 20 76 61 6c 69 64 rt is only valid
22f00 20 6f 6e 20 61 20 77 65 6c 6c 2d 66 6f 72 6d 65 on a well-forme
22f10 64 20 64 61 74 61 62 61 73 65 2e 20 20 49 6e 73 d database. Ins
22f20 74 65 61 64 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 tead of:.**.**
22f30 20 20 20 61 73 73 65 72 74 28 20 58 20 29 3b 0a assert( X );.
22f40 2a 2a 0a 2a 2a 20 4f 6e 65 20 77 72 69 74 65 73 **.** One writes
22f50 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 73 73 65 :.**.** asse
22f60 72 74 28 20 58 20 7c 7c 20 43 4f 52 52 55 50 54 rt( X || CORRUPT
22f70 5f 44 42 20 29 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 _DB );.**.** COR
22f80 52 55 50 54 5f 44 42 20 69 73 20 74 72 75 65 20 RUPT_DB is true
22f90 64 75 72 69 6e 67 20 6e 6f 72 6d 61 6c 20 6f 70 during normal op
22fa0 65 72 61 74 69 6f 6e 2e 20 20 43 4f 52 52 55 50 eration. CORRUP
22fb0 54 5f 44 42 20 64 6f 65 73 20 6e 6f 74 20 69 6e T_DB does not in
22fc0 64 69 63 61 74 65 0a 2a 2a 20 74 68 61 74 20 74 dicate.** that t
22fd0 68 65 20 64 61 74 61 62 61 73 65 20 69 73 20 64 he database is d
22fe0 65 66 69 6e 69 74 65 6c 79 20 63 6f 72 72 75 70 efinitely corrup
22ff0 74 2c 20 6f 6e 6c 79 20 74 68 61 74 20 69 74 20 t, only that it
23000 6d 69 67 68 74 20 62 65 20 63 6f 72 72 75 70 74 might be corrupt
23010 2e 0a 2a 2a 20 46 6f 72 20 6d 6f 73 74 20 74 65 ..** For most te
23020 73 74 20 63 61 73 65 73 2c 20 43 4f 52 52 55 50 st cases, CORRUP
23030 54 5f 44 42 20 69 73 20 73 65 74 20 74 6f 20 66 T_DB is set to f
23040 61 6c 73 65 20 75 73 69 6e 67 20 61 20 73 70 65 alse using a spe
23050 63 69 61 6c 0a 2a 2a 20 73 71 6c 69 74 65 33 5f cial.** sqlite3_
23060 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 29 2e 20 test_control().
23070 20 54 68 69 73 20 65 6e 61 62 6c 65 73 20 61 73 This enables as
23080 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 sert() statement
23090 73 20 74 6f 20 70 72 6f 76 65 0a 2a 2a 20 74 68 s to prove.** th
230a0 69 6e 67 73 20 74 68 61 74 20 61 72 65 20 61 6c ings that are al
230b0 77 61 79 73 20 74 72 75 65 20 66 6f 72 20 77 65 ways true for we
230c0 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 74 61 62 61 ll-formed databa
230d0 73 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ses..*/.#define
230e0 43 4f 52 52 55 50 54 5f 44 42 20 20 28 73 71 6c CORRUPT_DB (sql
230f0 69 74 65 33 43 6f 6e 66 69 67 2e 6e 65 76 65 72 ite3Config.never
23100 43 6f 72 72 75 70 74 3d 3d 30 29 0a 0a 2f 2a 0a Corrupt==0)../*.
23110 2a 2a 20 43 6f 6e 74 65 78 74 20 70 6f 69 6e 74 ** Context point
23120 65 72 20 70 61 73 73 65 64 20 64 6f 77 6e 20 74 er passed down t
23130 68 72 6f 75 67 68 20 74 68 65 20 74 72 65 65 2d hrough the tree-
23140 77 61 6c 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 walk..*/.struct
23150 57 61 6c 6b 65 72 20 7b 0a 20 20 50 61 72 73 65 Walker {. Parse
23160 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 *pParse;
23170 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23180 20 20 20 20 20 2f 2a 20 50 61 72 73 65 72 20 63 /* Parser c
23190 6f 6e 74 65 78 74 2e 20 20 2a 2f 0a 20 20 69 6e ontext. */. in
231a0 74 20 28 2a 78 45 78 70 72 43 61 6c 6c 62 61 63 t (*xExprCallbac
231b0 6b 29 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 k)(Walker*, Expr
231c0 2a 29 3b 20 20 20 20 20 2f 2a 20 43 61 6c 6c 62 *); /* Callb
231d0 61 63 6b 20 66 6f 72 20 65 78 70 72 65 73 73 69 ack for expressi
231e0 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 ons */. int (*x
231f0 53 65 6c 65 63 74 43 61 6c 6c 62 61 63 6b 29 28 SelectCallback)(
23200 57 61 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a 29 Walker*,Select*)
23210 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 66 ; /* Callback f
23220 6f 72 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 or SELECTs */.
23230 76 6f 69 64 20 28 2a 78 53 65 6c 65 63 74 43 61 void (*xSelectCa
23240 6c 6c 62 61 63 6b 32 29 28 57 61 6c 6b 65 72 2a llback2)(Walker*
23250 2c 53 65 6c 65 63 74 2a 29 3b 2f 2a 20 53 65 63 ,Select*);/* Sec
23260 6f 6e 64 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 ond callback for
23270 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 69 6e SELECTs */. in
23280 74 20 77 61 6c 6b 65 72 44 65 70 74 68 3b 20 20 t walkerDepth;
23290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
232a0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
232b0 72 20 6f 66 20 73 75 62 71 75 65 72 69 65 73 20 r of subqueries
232c0 2a 2f 0a 20 20 75 38 20 65 43 6f 64 65 3b 20 20 */. u8 eCode;
232d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
232e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
232f0 2a 20 41 20 73 6d 61 6c 6c 20 70 72 6f 63 65 73 * A small proces
23300 73 69 6e 67 20 63 6f 64 65 20 2a 2f 0a 20 20 75 sing code */. u
23310 6e 69 6f 6e 20 7b 20 20 20 20 20 20 20 20 20 20 nion {
23320 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23330 20 20 20 20 20 20 20 20 20 2f 2a 20 45 78 74 72 /* Extr
23340 61 20 64 61 74 61 20 66 6f 72 20 63 61 6c 6c 62 a data for callb
23350 61 63 6b 20 2a 2f 0a 20 20 20 20 4e 61 6d 65 43 ack */. NameC
23360 6f 6e 74 65 78 74 20 2a 70 4e 43 3b 20 20 20 20 ontext *pNC;
23370 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23380 20 20 20 20 20 20 2f 2a 20 4e 61 6d 69 6e 67 20 /* Naming
23390 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 20 20 69 context */. i
233a0 6e 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 nt n;
233b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
233c0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 /* A c
233d0 6f 75 6e 74 65 72 20 2a 2f 0a 20 20 20 20 69 6e ounter */. in
233e0 74 20 69 43 75 72 3b 20 20 20 20 20 20 20 20 20 t iCur;
233f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23400 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 75 /* A cu
23410 72 73 6f 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 rsor number */.
23420 20 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 SrcList *pSrc
23430 4c 69 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 List;
23440 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
23450 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a FROM clause */.
23460 20 20 20 20 73 74 72 75 63 74 20 53 72 63 43 6f struct SrcCo
23470 75 6e 74 20 2a 70 53 72 63 43 6f 75 6e 74 3b 20 unt *pSrcCount;
23480 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
23490 2a 20 43 6f 75 6e 74 69 6e 67 20 63 6f 6c 75 6d * Counting colum
234a0 6e 20 72 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a n references */.
234b0 20 20 20 20 73 74 72 75 63 74 20 43 43 75 72 48 struct CCurH
234c0 69 6e 74 20 2a 70 43 43 75 72 48 69 6e 74 3b 20 int *pCCurHint;
234d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
234e0 2a 20 55 73 65 64 20 62 79 20 63 6f 64 65 43 75 * Used by codeCu
234f0 72 73 6f 72 48 69 6e 74 28 29 20 2a 2f 0a 20 20 rsorHint() */.
23500 20 20 69 6e 74 20 2a 61 69 43 6f 6c 3b 20 20 20 int *aiCol;
23510 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23520 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
23530 61 72 72 61 79 20 6f 66 20 63 6f 6c 75 6d 6e 20 array of column
23540 69 6e 64 65 78 65 73 20 2a 2f 0a 20 20 20 20 73 indexes */. s
23550 74 72 75 63 74 20 49 64 78 43 6f 76 65 72 20 2a truct IdxCover *
23560 70 49 64 78 43 6f 76 65 72 3b 20 20 20 20 20 20 pIdxCover;
23570 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 68 65 /* Che
23580 63 6b 20 66 6f 72 20 69 6e 64 65 78 20 63 6f 76 ck for index cov
23590 65 72 61 67 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a erage */. } u;.
235a0 7d 3b 0a 0a 2f 2a 20 46 6f 72 77 61 72 64 20 64 };../* Forward d
235b0 65 63 6c 61 72 61 74 69 6f 6e 73 20 2a 2f 0a 69 eclarations */.i
235c0 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 nt sqlite3WalkEx
235d0 70 72 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 pr(Walker*, Expr
235e0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 *);.int sqlite3W
235f0 61 6c 6b 45 78 70 72 4c 69 73 74 28 57 61 6c 6b alkExprList(Walk
23600 65 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b er*, ExprList*);
23610 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b .int sqlite3Walk
23620 53 65 6c 65 63 74 28 57 61 6c 6b 65 72 2a 2c 20 Select(Walker*,
23630 53 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 Select*);.int sq
23640 6c 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 45 lite3WalkSelectE
23650 78 70 72 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c xpr(Walker*, Sel
23660 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ect*);.int sqlit
23670 65 33 57 61 6c 6b 53 65 6c 65 63 74 46 72 6f 6d e3WalkSelectFrom
23680 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 (Walker*, Select
23690 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
236a0 78 70 72 57 61 6c 6b 4e 6f 6f 70 28 57 61 6c 6b xprWalkNoop(Walk
236b0 65 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 0a 2f 2a er*, Expr*);../*
236c0 0a 2a 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 .** Return code
236d0 66 72 6f 6d 20 74 68 65 20 70 61 72 73 65 2d 74 from the parse-t
236e0 72 65 65 20 77 61 6c 6b 69 6e 67 20 70 72 69 6d ree walking prim
236f0 69 74 69 76 65 73 20 61 6e 64 20 74 68 65 69 72 itives and their
23700 0a 2a 2a 20 63 61 6c 6c 62 61 63 6b 73 2e 0a 2a .** callbacks..*
23710 2f 0a 23 64 65 66 69 6e 65 20 57 52 43 5f 43 6f /.#define WRC_Co
23720 6e 74 69 6e 75 65 20 20 20 20 30 20 20 20 2f 2a ntinue 0 /*
23730 20 43 6f 6e 74 69 6e 75 65 20 64 6f 77 6e 20 69 Continue down i
23740 6e 74 6f 20 63 68 69 6c 64 72 65 6e 20 2a 2f 0a nto children */.
23750 23 64 65 66 69 6e 65 20 57 52 43 5f 50 72 75 6e #define WRC_Prun
23760 65 20 20 20 20 20 20 20 31 20 20 20 2f 2a 20 4f e 1 /* O
23770 6d 69 74 20 63 68 69 6c 64 72 65 6e 20 62 75 74 mit children but
23780 20 63 6f 6e 74 69 6e 75 65 20 77 61 6c 6b 69 6e continue walkin
23790 67 20 73 69 62 6c 69 6e 67 73 20 2a 2f 0a 23 64 g siblings */.#d
237a0 65 66 69 6e 65 20 57 52 43 5f 41 62 6f 72 74 20 efine WRC_Abort
237b0 20 20 20 20 20 20 32 20 20 20 2f 2a 20 41 62 61 2 /* Aba
237c0 6e 64 6f 6e 20 74 68 65 20 74 72 65 65 20 77 61 ndon the tree wa
237d0 6c 6b 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 lk */../*.** An
237e0 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 instance of this
237f0 20 73 74 72 75 63 74 75 72 65 20 72 65 70 72 65 structure repre
23800 73 65 6e 74 73 20 61 20 73 65 74 20 6f 66 20 6f sents a set of o
23810 6e 65 20 6f 72 20 6d 6f 72 65 20 43 54 45 73 0a ne or more CTEs.
23820 2a 2a 20 28 63 6f 6d 6d 6f 6e 20 74 61 62 6c 65 ** (common table
23830 20 65 78 70 72 65 73 73 69 6f 6e 73 29 20 63 72 expressions) cr
23840 65 61 74 65 64 20 62 79 20 61 20 73 69 6e 67 6c eated by a singl
23850 65 20 57 49 54 48 20 63 6c 61 75 73 65 2e 0a 2a e WITH clause..*
23860 2f 0a 73 74 72 75 63 74 20 57 69 74 68 20 7b 0a /.struct With {.
23870 20 20 69 6e 74 20 6e 43 74 65 3b 20 20 20 20 20 int nCte;
23880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23890 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 43 /* Number of C
238a0 54 45 73 20 69 6e 20 74 68 65 20 57 49 54 48 20 TEs in the WITH
238b0 63 6c 61 75 73 65 20 2a 2f 0a 20 20 57 69 74 68 clause */. With
238c0 20 2a 70 4f 75 74 65 72 3b 20 20 20 20 20 20 20 *pOuter;
238d0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
238e0 6f 6e 74 61 69 6e 69 6e 67 20 57 49 54 48 20 63 ontaining WITH c
238f0 6c 61 75 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a lause, or NULL *
23900 2f 0a 20 20 73 74 72 75 63 74 20 43 74 65 20 7b /. struct Cte {
23910 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23920 20 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 /* For each
23930 43 54 45 20 69 6e 20 74 68 65 20 57 49 54 48 20 CTE in the WITH
23940 63 6c 61 75 73 65 2e 2e 2e 2e 20 2a 2f 0a 20 20 clause.... */.
23950 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
23960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23970 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 /* Name of thi
23980 73 20 43 54 45 20 2a 2f 0a 20 20 20 20 45 78 70 s CTE */. Exp
23990 72 4c 69 73 74 20 2a 70 43 6f 6c 73 3b 20 20 20 rList *pCols;
239a0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
239b0 4c 69 73 74 20 6f 66 20 65 78 70 6c 69 63 69 74 List of explicit
239c0 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 2c 20 6f column names, o
239d0 72 20 4e 55 4c 4c 20 2a 2f 0a 20 20 20 20 53 65 r NULL */. Se
239e0 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 lect *pSelect;
239f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
23a00 20 54 68 65 20 64 65 66 69 6e 69 74 69 6f 6e 20 The definition
23a10 6f 66 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 of this CTE */.
23a20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a const char *z
23a30 43 74 65 45 72 72 3b 20 20 20 20 20 20 20 20 20 CteErr;
23a40 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 /* Error mess
23a50 61 67 65 20 66 6f 72 20 63 69 72 63 75 6c 61 72 age for circular
23a60 20 72 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 references */.
23a70 20 7d 20 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 69 66 } a[1];.};..#if
23a80 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 def SQLITE_DEBUG
23a90 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
23aa0 63 65 20 6f 66 20 74 68 65 20 54 72 65 65 56 69 ce of the TreeVi
23ab0 65 77 20 6f 62 6a 65 63 74 20 69 73 20 75 73 65 ew object is use
23ac0 64 20 66 6f 72 20 70 72 69 6e 74 69 6e 67 20 74 d for printing t
23ad0 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 0a 2a 2a he content of.**
23ae0 20 64 61 74 61 20 73 74 72 75 63 74 75 72 65 73 data structures
23af0 20 6f 6e 20 73 71 6c 69 74 65 33 44 65 62 75 67 on sqlite3Debug
23b00 50 72 69 6e 74 66 28 29 20 75 73 69 6e 67 20 61 Printf() using a
23b10 20 74 72 65 65 2d 6c 69 6b 65 20 76 69 65 77 2e tree-like view.
23b20 0a 2a 2f 0a 73 74 72 75 63 74 20 54 72 65 65 56 .*/.struct TreeV
23b30 69 65 77 20 7b 0a 20 20 69 6e 74 20 69 4c 65 76 iew {. int iLev
23b40 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 el;
23b50 2f 2a 20 57 68 69 63 68 20 6c 65 76 65 6c 20 6f /* Which level o
23b60 66 20 74 68 65 20 74 72 65 65 20 77 65 20 61 72 f the tree we ar
23b70 65 20 6f 6e 20 2a 2f 0a 20 20 75 38 20 20 62 4c e on */. u8 bL
23b80 69 6e 65 5b 31 30 30 5d 3b 20 20 20 20 20 20 20 ine[100];
23b90 20 20 2f 2a 20 44 72 61 77 20 76 65 72 74 69 63 /* Draw vertic
23ba0 61 6c 20 69 6e 20 63 6f 6c 75 6d 6e 20 69 20 69 al in column i i
23bb0 66 20 62 4c 69 6e 65 5b 69 5d 20 69 73 20 74 72 f bLine[i] is tr
23bc0 75 65 20 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 66 20 ue */.};.#endif
23bd0 2f 2a 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 /* SQLITE_DEBUG
23be0 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 75 6d 69 */../*.** Assumi
23bf0 6e 67 20 7a 49 6e 20 70 6f 69 6e 74 73 20 74 6f ng zIn points to
23c00 20 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 the first byte
23c10 6f 66 20 61 20 55 54 46 2d 38 20 63 68 61 72 61 of a UTF-8 chara
23c20 63 74 65 72 2c 0a 2a 2a 20 61 64 76 61 6e 63 65 cter,.** advance
23c30 20 7a 49 6e 20 74 6f 20 70 6f 69 6e 74 20 74 6f zIn to point to
23c40 20 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 the first byte
23c50 6f 66 20 74 68 65 20 6e 65 78 74 20 55 54 46 2d of the next UTF-
23c60 38 20 63 68 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 8 character..*/.
23c70 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 #define SQLITE_S
23c80 4b 49 50 5f 55 54 46 38 28 7a 49 6e 29 20 7b 20 KIP_UTF8(zIn) {
23c90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23ca0 20 20 20 20 20 20 20 5c 0a 20 20 69 66 28 20 28 \. if( (
23cb0 2a 28 7a 49 6e 2b 2b 29 29 3e 3d 30 78 63 30 20 *(zIn++))>=0xc0
23cc0 29 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ){
23cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23ce0 5c 0a 20 20 20 20 77 68 69 6c 65 28 20 28 2a 7a \. while( (*z
23cf0 49 6e 20 26 20 30 78 63 30 29 3d 3d 30 78 38 30 In & 0xc0)==0x80
23d00 20 29 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 20 20 20 ){ zIn++; }
23d10 20 20 20 20 20 20 20 20 20 5c 0a 20 20 7d 20 20 \. }
23d20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23d30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23d40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23d50 20 20 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 \.}../*.** The
23d60 20 53 51 4c 49 54 45 5f 2a 5f 42 4b 50 54 20 6d SQLITE_*_BKPT m
23d70 61 63 72 6f 73 20 61 72 65 20 73 75 62 73 74 69 acros are substi
23d80 74 75 74 65 73 20 66 6f 72 20 74 68 65 20 65 72 tutes for the er
23d90 72 6f 72 20 63 6f 64 65 73 20 77 69 74 68 0a 2a ror codes with.*
23da0 2a 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 20 * the same name
23db0 62 75 74 20 77 69 74 68 6f 75 74 20 74 68 65 20 but without the
23dc0 5f 42 4b 50 54 20 73 75 66 66 69 78 2e 20 20 54 _BKPT suffix. T
23dd0 68 65 73 65 20 6d 61 63 72 6f 73 20 69 6e 76 6f hese macros invo
23de0 6b 65 0a 2a 2a 20 72 6f 75 74 69 6e 65 73 20 74 ke.** routines t
23df0 68 61 74 20 72 65 70 6f 72 74 20 74 68 65 20 6c hat report the l
23e00 69 6e 65 2d 6e 75 6d 62 65 72 20 6f 6e 20 77 68 ine-number on wh
23e10 69 63 68 20 74 68 65 20 65 72 72 6f 72 20 6f 72 ich the error or
23e20 69 67 69 6e 61 74 65 64 0a 2a 2a 20 75 73 69 6e iginated.** usin
23e30 67 20 73 71 6c 69 74 65 33 5f 6c 6f 67 28 29 2e g sqlite3_log().
23e40 20 20 54 68 65 20 72 6f 75 74 69 6e 65 73 20 61 The routines a
23e50 6c 73 6f 20 70 72 6f 76 69 64 65 20 61 20 63 6f lso provide a co
23e60 6e 76 65 6e 69 65 6e 74 20 70 6c 61 63 65 0a 2a nvenient place.*
23e70 2a 20 74 6f 20 73 65 74 20 61 20 64 65 62 75 67 * to set a debug
23e80 67 65 72 20 62 72 65 61 6b 70 6f 69 6e 74 2e 0a ger breakpoint..
23e90 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f */.int sqlite3Co
23ea0 72 72 75 70 74 45 72 72 6f 72 28 69 6e 74 29 3b rruptError(int);
23eb0 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 69 73 75 .int sqlite3Misu
23ec0 73 65 45 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e seError(int);.in
23ed0 74 20 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 t sqlite3Cantope
23ee0 6e 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 64 65 nError(int);.#de
23ef0 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 fine SQLITE_CORR
23f00 55 50 54 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 UPT_BKPT sqlite3
23f10 43 6f 72 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c CorruptError(__L
23f20 49 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 INE__).#define S
23f30 51 4c 49 54 45 5f 4d 49 53 55 53 45 5f 42 4b 50 QLITE_MISUSE_BKP
23f40 54 20 73 71 6c 69 74 65 33 4d 69 73 75 73 65 45 T sqlite3MisuseE
23f50 72 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 rror(__LINE__).#
23f60 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 41 define SQLITE_CA
23f70 4e 54 4f 50 45 4e 5f 42 4b 50 54 20 73 71 6c 69 NTOPEN_BKPT sqli
23f80 74 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 te3CantopenError
23f90 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 69 66 64 65 (__LINE__).#ifde
23fa0 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 f SQLITE_DEBUG.
23fb0 20 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f 6d 65 int sqlite3Nome
23fc0 6d 45 72 72 6f 72 28 69 6e 74 29 3b 0a 20 20 69 mError(int);. i
23fd0 6e 74 20 73 71 6c 69 74 65 33 49 6f 65 72 72 6e nt sqlite3Ioerrn
23fe0 6f 6d 65 6d 45 72 72 6f 72 28 69 6e 74 29 3b 0a omemError(int);.
23ff0 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
24000 4e 4f 4d 45 4d 5f 42 4b 50 54 20 73 71 6c 69 74 NOMEM_BKPT sqlit
24010 65 33 4e 6f 6d 65 6d 45 72 72 6f 72 28 5f 5f 4c e3NomemError(__L
24020 49 4e 45 5f 5f 29 0a 23 20 64 65 66 69 6e 65 20 INE__).# define
24030 53 51 4c 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d SQLITE_IOERR_NOM
24040 45 4d 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 49 EM_BKPT sqlite3I
24050 6f 65 72 72 6e 6f 6d 65 6d 45 72 72 6f 72 28 5f oerrnomemError(_
24060 5f 4c 49 4e 45 5f 5f 29 0a 23 65 6c 73 65 0a 23 _LINE__).#else.#
24070 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e define SQLITE_N
24080 4f 4d 45 4d 5f 42 4b 50 54 20 53 51 4c 49 54 45 OMEM_BKPT SQLITE
24090 5f 4e 4f 4d 45 4d 0a 23 20 64 65 66 69 6e 65 20 _NOMEM.# define
240a0 53 51 4c 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d SQLITE_IOERR_NOM
240b0 45 4d 5f 42 4b 50 54 20 53 51 4c 49 54 45 5f 49 EM_BKPT SQLITE_I
240c0 4f 45 52 52 5f 4e 4f 4d 45 4d 0a 23 65 6e 64 69 OERR_NOMEM.#endi
240d0 66 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 33 20 61 6e f../*.** FTS3 an
240e0 64 20 46 54 53 34 20 62 6f 74 68 20 72 65 71 75 d FTS4 both requ
240f0 69 72 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c ire virtual tabl
24100 65 20 73 75 70 70 6f 72 74 0a 2a 2f 0a 23 69 66 e support.*/.#if
24110 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
24120 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
24130 45 29 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 E).# undef SQLIT
24140 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 0a 23 20 E_ENABLE_FTS3.#
24150 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 undef SQLITE_ENA
24160 42 4c 45 5f 46 54 53 34 0a 23 65 6e 64 69 66 0a BLE_FTS4.#endif.
24170 0a 2f 2a 0a 2a 2a 20 46 54 53 34 20 69 73 20 72 ./*.** FTS4 is r
24180 65 61 6c 6c 79 20 61 6e 20 65 78 74 65 6e 73 69 eally an extensi
24190 6f 6e 20 66 6f 72 20 46 54 53 33 2e 20 20 49 74 on for FTS3. It
241a0 20 69 73 20 65 6e 61 62 6c 65 64 20 75 73 69 6e is enabled usin
241b0 67 20 74 68 65 0a 2a 2a 20 53 51 4c 49 54 45 5f g the.** SQLITE_
241c0 45 4e 41 42 4c 45 5f 46 54 53 33 20 6d 61 63 72 ENABLE_FTS3 macr
241d0 6f 2e 20 20 42 75 74 20 74 6f 20 61 76 6f 69 64 o. But to avoid
241e0 20 63 6f 6e 66 75 73 69 6f 6e 20 77 65 20 61 6c confusion we al
241f0 73 6f 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 53 so call.** the S
24200 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
24210 34 20 6d 61 63 72 6f 20 74 6f 20 73 65 72 76 65 4 macro to serve
24220 20 61 73 20 61 6e 20 61 6c 69 61 73 20 66 6f 72 as an alias for
24230 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 SQLITE_ENABLE_F
24240 54 53 33 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 TS3..*/.#if defi
24250 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c ned(SQLITE_ENABL
24260 45 5f 46 54 53 34 29 20 26 26 20 21 64 65 66 69 E_FTS4) && !defi
24270 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c ned(SQLITE_ENABL
24280 45 5f 46 54 53 33 29 0a 23 20 64 65 66 69 6e 65 E_FTS3).# define
24290 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 SQLITE_ENABLE_F
242a0 54 53 33 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a TS3 1.#endif../*
242b0 0a 2a 2a 20 54 68 65 20 63 74 79 70 65 2e 68 20 .** The ctype.h
242c0 68 65 61 64 65 72 20 69 73 20 6e 65 65 64 65 64 header is needed
242d0 20 66 6f 72 20 6e 6f 6e 2d 41 53 43 49 49 20 73 for non-ASCII s
242e0 79 73 74 65 6d 73 2e 20 20 49 74 20 69 73 20 61 ystems. It is a
242f0 6c 73 6f 0a 2a 2a 20 6e 65 65 64 65 64 20 62 79 lso.** needed by
24300 20 46 54 53 33 20 77 68 65 6e 20 46 54 53 33 20 FTS3 when FTS3
24310 69 73 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 74 is included in t
24320 68 65 20 61 6d 61 6c 67 61 6d 61 74 69 6f 6e 2e he amalgamation.
24330 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 .*/.#if !defined
24340 28 53 51 4c 49 54 45 5f 41 53 43 49 49 29 20 7c (SQLITE_ASCII) |
24350 7c 20 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 64 | \. (defined
24360 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 (SQLITE_ENABLE_F
24370 54 53 33 29 20 26 26 20 64 65 66 69 6e 65 64 28 TS3) && defined(
24380 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 SQLITE_AMALGAMAT
24390 49 4f 4e 29 29 0a 23 20 69 6e 63 6c 75 64 65 20 ION)).# include
243a0 3c 63 74 79 70 65 2e 68 3e 0a 23 65 6e 64 69 66 <ctype.h>.#endif
243b0 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c ../*.** The foll
243c0 6f 77 69 6e 67 20 6d 61 63 72 6f 73 20 6d 69 6d owing macros mim
243d0 69 63 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 ic the standard
243e0 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f 6e library function
243f0 73 20 74 6f 75 70 70 65 72 28 29 2c 0a 2a 2a 20 s toupper(),.**
24400 69 73 73 70 61 63 65 28 29 2c 20 69 73 61 6c 6e isspace(), isaln
24410 75 6d 28 29 2c 20 69 73 64 69 67 69 74 28 29 20 um(), isdigit()
24420 61 6e 64 20 69 73 78 64 69 67 69 74 28 29 2c 20 and isxdigit(),
24430 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 54 68 respectively. Th
24440 65 0a 2a 2a 20 73 71 6c 69 74 65 20 76 65 72 73 e.** sqlite vers
24450 69 6f 6e 73 20 6f 6e 6c 79 20 77 6f 72 6b 20 66 ions only work f
24460 6f 72 20 41 53 43 49 49 20 63 68 61 72 61 63 74 or ASCII charact
24470 65 72 73 2c 20 72 65 67 61 72 64 6c 65 73 73 20 ers, regardless
24480 6f 66 20 6c 6f 63 61 6c 65 2e 0a 2a 2f 0a 23 69 of locale..*/.#i
24490 66 64 65 66 20 53 51 4c 49 54 45 5f 41 53 43 49 fdef SQLITE_ASCI
244a0 49 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 I.# define sqlit
244b0 65 33 54 6f 75 70 70 65 72 28 78 29 20 20 28 28 e3Toupper(x) ((
244c0 78 29 26 7e 28 73 71 6c 69 74 65 33 43 74 79 70 x)&~(sqlite3Ctyp
244d0 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 eMap[(unsigned c
244e0 68 61 72 29 28 78 29 5d 26 30 78 32 30 29 29 0a har)(x)]&0x20)).
244f0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
24500 49 73 73 70 61 63 65 28 78 29 20 20 20 28 73 71 Isspace(x) (sq
24510 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
24520 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
24530 5d 26 30 78 30 31 29 0a 23 20 64 65 66 69 6e 65 ]&0x01).# define
24540 20 73 71 6c 69 74 65 33 49 73 61 6c 6e 75 6d 28 sqlite3Isalnum(
24550 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 x) (sqlite3Cty
24560 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 peMap[(unsigned
24570 63 68 61 72 29 28 78 29 5d 26 30 78 30 36 29 0a char)(x)]&0x06).
24580 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
24590 49 73 61 6c 70 68 61 28 78 29 20 20 20 28 73 71 Isalpha(x) (sq
245a0 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
245b0 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
245c0 5d 26 30 78 30 32 29 0a 23 20 64 65 66 69 6e 65 ]&0x02).# define
245d0 20 73 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 sqlite3Isdigit(
245e0 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 x) (sqlite3Cty
245f0 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 peMap[(unsigned
24600 63 68 61 72 29 28 78 29 5d 26 30 78 30 34 29 0a char)(x)]&0x04).
24610 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
24620 49 73 78 64 69 67 69 74 28 78 29 20 20 28 73 71 Isxdigit(x) (sq
24630 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
24640 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
24650 5d 26 30 78 30 38 29 0a 23 20 64 65 66 69 6e 65 ]&0x08).# define
24660 20 73 71 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 sqlite3Tolower(
24670 78 29 20 20 20 28 73 71 6c 69 74 65 33 55 70 70 x) (sqlite3Upp
24680 65 72 54 6f 4c 6f 77 65 72 5b 28 75 6e 73 69 67 erToLower[(unsig
24690 6e 65 64 20 63 68 61 72 29 28 78 29 5d 29 0a 23 ned char)(x)]).#
246a0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 define sqlite3I
246b0 73 71 75 6f 74 65 28 78 29 20 20 20 28 73 71 6c squote(x) (sql
246c0 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e ite3CtypeMap[(un
246d0 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d signed char)(x)]
246e0 26 30 78 38 30 29 0a 23 65 6c 73 65 0a 23 20 64 &0x80).#else.# d
246f0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f 75 efine sqlite3Tou
24700 70 70 65 72 28 78 29 20 20 20 74 6f 75 70 70 65 pper(x) touppe
24710 72 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 r((unsigned char
24720 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 )(x)).# define s
24730 71 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 29 qlite3Isspace(x)
24740 20 20 20 69 73 73 70 61 63 65 28 28 75 6e 73 69 isspace((unsi
24750 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 gned char)(x)).#
24760 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 define sqlite3I
24770 73 61 6c 6e 75 6d 28 78 29 20 20 20 69 73 61 6c salnum(x) isal
24780 6e 75 6d 28 28 75 6e 73 69 67 6e 65 64 20 63 68 num((unsigned ch
24790 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 ar)(x)).# define
247a0 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 28 sqlite3Isalpha(
247b0 78 29 20 20 20 69 73 61 6c 70 68 61 28 28 75 6e x) isalpha((un
247c0 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 signed char)(x))
247d0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
247e0 33 49 73 64 69 67 69 74 28 78 29 20 20 20 69 73 3Isdigit(x) is
247f0 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 20 digit((unsigned
24800 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 char)(x)).# defi
24810 6e 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 67 ne sqlite3Isxdig
24820 69 74 28 78 29 20 20 69 73 78 64 69 67 69 74 28 it(x) isxdigit(
24830 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 (unsigned char)(
24840 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c x)).# define sql
24850 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 ite3Tolower(x)
24860 20 74 6f 6c 6f 77 65 72 28 28 75 6e 73 69 67 6e tolower((unsign
24870 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 ed char)(x)).# d
24880 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 71 efine sqlite3Isq
24890 75 6f 74 65 28 78 29 20 20 20 28 28 78 29 3d 3d uote(x) ((x)==
248a0 27 22 27 7c 7c 28 78 29 3d 3d 27 5c 27 27 7c 7c '"'||(x)=='\''||
248b0 28 78 29 3d 3d 27 5b 27 7c 7c 28 78 29 3d 3d 27 (x)=='['||(x)=='
248c0 60 27 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 `').#endif.#ifnd
248d0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 ef SQLITE_OMIT_C
248e0 4f 4d 50 49 4c 45 4f 50 54 49 4f 4e 5f 44 49 41 OMPILEOPTION_DIA
248f0 47 53 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 73 GS.int sqlite3Is
24900 49 64 43 68 61 72 28 75 38 29 3b 0a 23 65 6e 64 IdChar(u8);.#end
24910 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 72 6e if../*.** Intern
24920 61 6c 20 66 75 6e 63 74 69 6f 6e 20 70 72 6f 74 al function prot
24930 6f 74 79 70 65 73 0a 2a 2f 0a 69 6e 74 20 73 71 otypes.*/.int sq
24940 6c 69 74 65 33 53 74 72 49 43 6d 70 28 63 6f 6e lite3StrICmp(con
24950 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 st char*,const c
24960 68 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 har*);.int sqlit
24970 65 33 53 74 72 6c 65 6e 33 30 28 63 6f 6e 73 74 e3Strlen30(const
24980 20 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 2a 73 char*);.char *s
24990 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 54 79 70 65 qlite3ColumnType
249a0 28 43 6f 6c 75 6d 6e 2a 2c 63 68 61 72 2a 29 3b (Column*,char*);
249b0 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 .#define sqlite3
249c0 53 74 72 4e 49 43 6d 70 20 73 71 6c 69 74 65 33 StrNICmp sqlite3
249d0 5f 73 74 72 6e 69 63 6d 70 0a 0a 69 6e 74 20 73 _strnicmp..int s
249e0 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 49 6e 69 74 qlite3MallocInit
249f0 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c (void);.void sql
24a00 69 74 65 33 4d 61 6c 6c 6f 63 45 6e 64 28 76 6f ite3MallocEnd(vo
24a10 69 64 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 id);.void *sqlit
24a20 65 33 4d 61 6c 6c 6f 63 28 75 36 34 29 3b 0a 76 e3Malloc(u64);.v
24a30 6f 69 64 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c oid *sqlite3Mall
24a40 6f 63 5a 65 72 6f 28 75 36 34 29 3b 0a 76 6f 69 ocZero(u64);.voi
24a50 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c d *sqlite3DbMall
24a60 6f 63 5a 65 72 6f 28 73 71 6c 69 74 65 33 2a 2c ocZero(sqlite3*,
24a70 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c u64);.void *sql
24a80 69 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 28 ite3DbMallocRaw(
24a90 73 71 6c 69 74 65 33 2a 2c 20 75 36 34 29 3b 0a sqlite3*, u64);.
24aa0 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 62 4d void *sqlite3DbM
24ab0 61 6c 6c 6f 63 52 61 77 4e 4e 28 73 71 6c 69 74 allocRawNN(sqlit
24ac0 65 33 2a 2c 20 75 36 34 29 3b 0a 63 68 61 72 20 e3*, u64);.char
24ad0 2a 73 71 6c 69 74 65 33 44 62 53 74 72 44 75 70 *sqlite3DbStrDup
24ae0 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 (sqlite3*,const
24af0 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 2a 73 71 char*);.char *sq
24b00 6c 69 74 65 33 44 62 53 74 72 4e 44 75 70 28 73 lite3DbStrNDup(s
24b10 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
24b20 61 72 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 ar*, u64);.void
24b30 2a 73 71 6c 69 74 65 33 52 65 61 6c 6c 6f 63 28 *sqlite3Realloc(
24b40 76 6f 69 64 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 void*, u64);.voi
24b50 64 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 6c d *sqlite3DbReal
24b60 6c 6f 63 4f 72 46 72 65 65 28 73 71 6c 69 74 65 locOrFree(sqlite
24b70 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 3 *, void *, u64
24b80 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
24b90 44 62 52 65 61 6c 6c 6f 63 28 73 71 6c 69 74 65 DbRealloc(sqlite
24ba0 33 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 3 *, void *, u64
24bb0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 );.void sqlite3D
24bc0 62 46 72 65 65 28 73 71 6c 69 74 65 33 2a 2c 20 bFree(sqlite3*,
24bd0 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 void*);.int sqli
24be0 74 65 33 4d 61 6c 6c 6f 63 53 69 7a 65 28 76 6f te3MallocSize(vo
24bf0 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 id*);.int sqlite
24c00 33 44 62 4d 61 6c 6c 6f 63 53 69 7a 65 28 73 71 3DbMallocSize(sq
24c10 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a lite3*, void*);.
24c20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 53 63 72 void *sqlite3Scr
24c30 61 74 63 68 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b atchMalloc(int);
24c40 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 72 .void sqlite3Scr
24c50 61 74 63 68 46 72 65 65 28 76 6f 69 64 2a 29 3b atchFree(void*);
24c60 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 50 61 .void *sqlite3Pa
24c70 67 65 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 geMalloc(int);.v
24c80 6f 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 46 oid sqlite3PageF
24c90 72 65 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 ree(void*);.void
24ca0 20 73 71 6c 69 74 65 33 4d 65 6d 53 65 74 44 65 sqlite3MemSetDe
24cb0 66 61 75 6c 74 28 76 6f 69 64 29 3b 0a 23 69 66 fault(void);.#if
24cc0 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 ndef SQLITE_UNTE
24cd0 53 54 41 42 4c 45 0a 76 6f 69 64 20 73 71 6c 69 STABLE.void sqli
24ce0 74 65 33 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 48 te3BenignMallocH
24cf0 6f 6f 6b 73 28 76 6f 69 64 20 28 2a 29 28 76 6f ooks(void (*)(vo
24d00 69 64 29 2c 20 76 6f 69 64 20 28 2a 29 28 76 6f id), void (*)(vo
24d10 69 64 29 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 id));.#endif.int
24d20 20 73 71 6c 69 74 65 33 48 65 61 70 4e 65 61 72 sqlite3HeapNear
24d30 6c 79 46 75 6c 6c 28 76 6f 69 64 29 3b 0a 0a 2f lyFull(void);../
24d40 2a 0a 2a 2a 20 4f 6e 20 73 79 73 74 65 6d 73 20 *.** On systems
24d50 77 69 74 68 20 61 6d 70 6c 65 20 73 74 61 63 6b with ample stack
24d60 20 73 70 61 63 65 20 61 6e 64 20 74 68 61 74 20 space and that
24d70 73 75 70 70 6f 72 74 20 61 6c 6c 6f 63 61 28 29 support alloca()
24d80 2c 20 6d 61 6b 65 0a 2a 2a 20 75 73 65 20 6f 66 , make.** use of
24d90 20 61 6c 6c 6f 63 61 28 29 20 74 6f 20 6f 62 74 alloca() to obt
24da0 61 69 6e 20 73 70 61 63 65 20 66 6f 72 20 6c 61 ain space for la
24db0 72 67 65 20 61 75 74 6f 6d 61 74 69 63 20 6f 62 rge automatic ob
24dc0 6a 65 63 74 73 2e 20 20 42 79 20 64 65 66 61 75 jects. By defau
24dd0 6c 74 2c 0a 2a 2a 20 6f 62 74 61 69 6e 20 73 70 lt,.** obtain sp
24de0 61 63 65 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 ace from malloc(
24df0 29 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 61 6c 6c )..**.** The all
24e00 6f 63 61 28 29 20 72 6f 75 74 69 6e 65 20 6e 65 oca() routine ne
24e10 76 65 72 20 72 65 74 75 72 6e 73 20 4e 55 4c 4c ver returns NULL
24e20 2e 20 20 54 68 69 73 20 77 69 6c 6c 20 63 61 75 . This will cau
24e30 73 65 20 63 6f 64 65 20 70 61 74 68 73 0a 2a 2a se code paths.**
24e40 20 74 68 61 74 20 64 65 61 6c 20 77 69 74 68 20 that deal with
24e50 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f sqlite3StackAllo
24e60 63 28 29 20 66 61 69 6c 75 72 65 73 20 74 6f 20 c() failures to
24e70 62 65 20 75 6e 72 65 61 63 68 61 62 6c 65 2e 0a be unreachable..
24e80 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
24e90 5f 55 53 45 5f 41 4c 4c 4f 43 41 0a 23 20 64 65 _USE_ALLOCA.# de
24ea0 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
24eb0 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 kAllocRaw(D,N)
24ec0 20 61 6c 6c 6f 63 61 28 4e 29 0a 23 20 64 65 66 alloca(N).# def
24ed0 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b ine sqlite3Stack
24ee0 41 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 AllocZero(D,N)
24ef0 6d 65 6d 73 65 74 28 61 6c 6c 6f 63 61 28 4e 29 memset(alloca(N)
24f00 2c 20 30 2c 20 4e 29 0a 23 20 64 65 66 69 6e 65 , 0, N).# define
24f10 20 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 sqlite3StackFre
24f20 65 28 44 2c 50 29 0a 23 65 6c 73 65 0a 23 20 64 e(D,P).#else.# d
24f30 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 efine sqlite3Sta
24f40 63 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 ckAllocRaw(D,N)
24f50 20 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f sqlite3DbMallo
24f60 63 52 61 77 28 44 2c 4e 29 0a 23 20 64 65 66 69 cRaw(D,N).# defi
24f70 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 ne sqlite3StackA
24f80 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 73 llocZero(D,N) s
24f90 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 qlite3DbMallocZe
24fa0 72 6f 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 ro(D,N).# define
24fb0 20 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 sqlite3StackFre
24fc0 65 28 44 2c 50 29 20 20 20 20 20 20 20 73 71 6c e(D,P) sql
24fd0 69 74 65 33 44 62 46 72 65 65 28 44 2c 50 29 0a ite3DbFree(D,P).
24fe0 23 65 6e 64 69 66 0a 0a 2f 2a 20 44 6f 20 6e 6f #endif../* Do no
24ff0 74 20 61 6c 6c 6f 77 20 62 6f 74 68 20 4d 45 4d t allow both MEM
25000 53 59 53 35 20 61 6e 64 20 4d 45 4d 53 59 53 33 SYS5 and MEMSYS3
25010 20 74 6f 20 62 65 20 64 65 66 69 6e 65 64 20 74 to be defined t
25020 6f 67 65 74 68 65 72 2e 20 20 49 66 20 74 68 65 ogether. If the
25030 79 0a 2a 2a 20 61 72 65 2c 20 64 69 73 61 62 6c y.** are, disabl
25040 65 20 4d 45 4d 53 59 53 33 0a 2a 2f 0a 23 69 66 e MEMSYS3.*/.#if
25050 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c def SQLITE_ENABL
25060 45 5f 4d 45 4d 53 59 53 35 0a 63 6f 6e 73 74 20 E_MEMSYS5.const
25070 73 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 sqlite3_mem_meth
25080 6f 64 73 20 2a 73 71 6c 69 74 65 33 4d 65 6d 47 ods *sqlite3MemG
25090 65 74 4d 65 6d 73 79 73 35 28 76 6f 69 64 29 3b etMemsys5(void);
250a0 0a 23 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 .#undef SQLITE_E
250b0 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 33 0a 23 65 NABLE_MEMSYS3.#e
250c0 6e 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c 49 ndif.#ifdef SQLI
250d0 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 TE_ENABLE_MEMSYS
250e0 33 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 3.const sqlite3_
250f0 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c mem_methods *sql
25100 69 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 ite3MemGetMemsys
25110 33 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 3(void);.#endif.
25120 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ..#ifndef SQLITE
25130 5f 4d 55 54 45 58 5f 4f 4d 49 54 0a 20 20 73 71 _MUTEX_OMIT. sq
25140 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 lite3_mutex_meth
25150 6f 64 73 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 ods const *sqlit
25160 65 33 44 65 66 61 75 6c 74 4d 75 74 65 78 28 76 e3DefaultMutex(v
25170 6f 69 64 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f oid);. sqlite3_
25180 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f mutex_methods co
25190 6e 73 74 20 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 nst *sqlite3Noop
251a0 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 Mutex(void);. s
251b0 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 qlite3_mutex *sq
251c0 6c 69 74 65 33 4d 75 74 65 78 41 6c 6c 6f 63 28 lite3MutexAlloc(
251d0 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 int);. int sqli
251e0 74 65 33 4d 75 74 65 78 49 6e 69 74 28 76 6f 69 te3MutexInit(voi
251f0 64 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 d);. int sqlite
25200 33 4d 75 74 65 78 45 6e 64 28 76 6f 69 64 29 3b 3MutexEnd(void);
25210 0a 23 65 6e 64 69 66 0a 23 69 66 20 21 64 65 66 .#endif.#if !def
25220 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 55 54 45 ined(SQLITE_MUTE
25230 58 5f 4f 4d 49 54 29 20 26 26 20 21 64 65 66 69 X_OMIT) && !defi
25240 6e 65 64 28 53 51 4c 49 54 45 5f 4d 55 54 45 58 ned(SQLITE_MUTEX
25250 5f 4e 4f 4f 50 29 0a 20 20 76 6f 69 64 20 73 71 _NOOP). void sq
25260 6c 69 74 65 33 4d 65 6d 6f 72 79 42 61 72 72 69 lite3MemoryBarri
25270 65 72 28 76 6f 69 64 29 3b 0a 23 65 6c 73 65 0a er(void);.#else.
25280 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
25290 4d 65 6d 6f 72 79 42 61 72 72 69 65 72 28 29 0a MemoryBarrier().
252a0 23 65 6e 64 69 66 0a 0a 73 71 6c 69 74 65 33 5f #endif..sqlite3_
252b0 69 6e 74 36 34 20 73 71 6c 69 74 65 33 53 74 61 int64 sqlite3Sta
252c0 74 75 73 56 61 6c 75 65 28 69 6e 74 29 3b 0a 76 tusValue(int);.v
252d0 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 oid sqlite3Statu
252e0 73 55 70 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 sUp(int, int);.v
252f0 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 oid sqlite3Statu
25300 73 44 6f 77 6e 28 69 6e 74 2c 20 69 6e 74 29 3b sDown(int, int);
25310 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 .void sqlite3Sta
25320 74 75 73 48 69 67 68 77 61 74 65 72 28 69 6e 74 tusHighwater(int
25330 2c 20 69 6e 74 29 3b 0a 0a 2f 2a 20 41 63 63 65 , int);../* Acce
25340 73 73 20 74 6f 20 6d 75 74 65 78 65 73 20 75 73 ss to mutexes us
25350 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f 73 74 ed by sqlite3_st
25360 61 74 75 73 28 29 20 2a 2f 0a 73 71 6c 69 74 65 atus() */.sqlite
25370 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 3_mutex *sqlite3
25380 50 63 61 63 68 65 31 4d 75 74 65 78 28 76 6f 69 Pcache1Mutex(voi
25390 64 29 3b 0a 73 71 6c 69 74 65 33 5f 6d 75 74 65 d);.sqlite3_mute
253a0 78 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 x *sqlite3Malloc
253b0 4d 75 74 65 78 28 76 6f 69 64 29 3b 0a 0a 23 69 Mutex(void);..#i
253c0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
253d0 54 5f 46 4c 4f 41 54 49 4e 47 5f 50 4f 49 4e 54 T_FLOATING_POINT
253e0 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 49 73 . int sqlite3Is
253f0 4e 61 4e 28 64 6f 75 62 6c 65 29 3b 0a 23 65 6c NaN(double);.#el
25400 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
25410 74 65 33 49 73 4e 61 4e 28 58 29 20 20 30 0a 23 te3IsNaN(X) 0.#
25420 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 endif../*.** An
25430 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
25440 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
25450 75 72 65 20 68 6f 6c 64 73 20 69 6e 66 6f 72 6d ure holds inform
25460 61 74 69 6f 6e 20 61 62 6f 75 74 20 53 51 4c 0a ation about SQL.
25470 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 67 ** functions arg
25480 75 6d 65 6e 74 73 20 74 68 61 74 20 61 72 65 20 uments that are
25490 74 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 74 the parameters t
254a0 6f 20 74 68 65 20 70 72 69 6e 74 66 28 29 20 66 o the printf() f
254b0 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 unction..*/.stru
254c0 63 74 20 50 72 69 6e 74 66 41 72 67 75 6d 65 6e ct PrintfArgumen
254d0 74 73 20 7b 0a 20 20 69 6e 74 20 6e 41 72 67 3b ts {. int nArg;
254e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
254f0 2f 2a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 /* Total number
25500 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a of arguments */.
25510 20 20 69 6e 74 20 6e 55 73 65 64 3b 20 20 20 20 int nUsed;
25520 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
25530 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 mber of argument
25540 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f s used so far */
25550 0a 20 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 . sqlite3_value
25560 20 2a 2a 61 70 41 72 67 3b 20 20 20 2f 2a 20 54 **apArg; /* T
25570 68 65 20 61 72 67 75 6d 65 6e 74 20 76 61 6c 75 he argument valu
25580 65 73 20 2a 2f 0a 7d 3b 0a 0a 76 6f 69 64 20 73 es */.};..void s
25590 71 6c 69 74 65 33 56 58 50 72 69 6e 74 66 28 53 qlite3VXPrintf(S
255a0 74 72 41 63 63 75 6d 2a 2c 20 63 6f 6e 73 74 20 trAccum*, const
255b0 63 68 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b char*, va_list);
255c0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 58 50 72 .void sqlite3XPr
255d0 69 6e 74 66 28 53 74 72 41 63 63 75 6d 2a 2c 20 intf(StrAccum*,
255e0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e const char*, ...
255f0 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
25600 4d 50 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a MPrintf(sqlite3*
25610 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e ,const char*, ..
25620 2e 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 .);.char *sqlite
25630 33 56 4d 50 72 69 6e 74 66 28 73 71 6c 69 74 65 3VMPrintf(sqlite
25640 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 3*,const char*,
25650 76 61 5f 6c 69 73 74 29 3b 0a 23 69 66 20 64 65 va_list);.#if de
25660 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 fined(SQLITE_DEB
25670 55 47 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 UG) || defined(S
25680 51 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 QLITE_HAVE_OS_TR
25690 41 43 45 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 ACE). void sqli
256a0 74 65 33 44 65 62 75 67 50 72 69 6e 74 66 28 63 te3DebugPrintf(c
256b0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 onst char*, ...)
256c0 3b 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 ;.#endif.#if def
256d0 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 ined(SQLITE_TEST
256e0 29 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 ). void *sqlite
256f0 33 54 65 73 74 54 65 78 74 54 6f 50 74 72 28 63 3TestTextToPtr(c
25700 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e onst char*);.#en
25710 64 69 66 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 dif..#if defined
25720 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 (SQLITE_DEBUG).
25730 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 void sqlite3Tre
25740 65 56 69 65 77 45 78 70 72 28 54 72 65 65 56 69 eViewExpr(TreeVi
25750 65 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 2a ew*, const Expr*
25760 2c 20 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 , u8);. void sq
25770 6c 69 74 65 33 54 72 65 65 56 69 65 77 42 61 72 lite3TreeViewBar
25780 65 45 78 70 72 4c 69 73 74 28 54 72 65 65 56 69 eExprList(TreeVi
25790 65 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 4c ew*, const ExprL
257a0 69 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 ist*, const char
257b0 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
257c0 65 33 54 72 65 65 56 69 65 77 45 78 70 72 4c 69 e3TreeViewExprLi
257d0 73 74 28 54 72 65 65 56 69 65 77 2a 2c 20 63 6f st(TreeView*, co
257e0 6e 73 74 20 45 78 70 72 4c 69 73 74 2a 2c 20 75 nst ExprList*, u
257f0 38 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 8, const char*);
25800 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 . void sqlite3T
25810 72 65 65 56 69 65 77 53 65 6c 65 63 74 28 54 72 reeViewSelect(Tr
25820 65 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 53 eeView*, const S
25830 65 6c 65 63 74 2a 2c 20 75 38 29 3b 0a 20 20 76 elect*, u8);. v
25840 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 oid sqlite3TreeV
25850 69 65 77 57 69 74 68 28 54 72 65 65 56 69 65 77 iewWith(TreeView
25860 2a 2c 20 63 6f 6e 73 74 20 57 69 74 68 2a 2c 20 *, const With*,
25870 75 38 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 76 6f u8);.#endif...vo
25880 69 64 20 73 71 6c 69 74 65 33 53 65 74 53 74 72 id sqlite3SetStr
25890 69 6e 67 28 63 68 61 72 20 2a 2a 2c 20 73 71 6c ing(char **, sql
258a0 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 ite3*, const cha
258b0 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
258c0 33 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 3ErrorMsg(Parse*
258d0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e , const char*, .
258e0 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 ..);.void sqlite
258f0 33 44 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 3Dequote(char*);
25900 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 54 6f 6b .void sqlite3Tok
25910 65 6e 49 6e 69 74 28 54 6f 6b 65 6e 2a 2c 63 68 enInit(Token*,ch
25920 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ar*);.int sqlite
25930 33 4b 65 79 77 6f 72 64 43 6f 64 65 28 63 6f 6e 3KeywordCode(con
25940 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 st unsigned char
25950 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c *, int);.int sql
25960 69 74 65 33 52 75 6e 50 61 72 73 65 72 28 50 61 ite3RunParser(Pa
25970 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 rse*, const char
25980 2a 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 *, char **);.voi
25990 64 20 73 71 6c 69 74 65 33 46 69 6e 69 73 68 43 d sqlite3FinishC
259a0 6f 64 69 6e 67 28 50 61 72 73 65 2a 29 3b 0a 69 oding(Parse*);.i
259b0 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d nt sqlite3GetTem
259c0 70 52 65 67 28 50 61 72 73 65 2a 29 3b 0a 76 6f pReg(Parse*);.vo
259d0 69 64 20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 id sqlite3Releas
259e0 65 54 65 6d 70 52 65 67 28 50 61 72 73 65 2a 2c eTempReg(Parse*,
259f0 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
25a00 33 47 65 74 54 65 6d 70 52 61 6e 67 65 28 50 61 3GetTempRange(Pa
25a10 72 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 rse*,int);.void
25a20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 sqlite3ReleaseTe
25a30 6d 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 mpRange(Parse*,i
25a40 6e 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 nt,int);.void sq
25a50 6c 69 74 65 33 43 6c 65 61 72 54 65 6d 70 52 65 lite3ClearTempRe
25a60 67 43 61 63 68 65 28 50 61 72 73 65 2a 29 3b 0a gCache(Parse*);.
25a70 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 #ifdef SQLITE_DE
25a80 42 55 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4e BUG.int sqlite3N
25a90 6f 54 65 6d 70 73 49 6e 52 61 6e 67 65 28 50 61 oTempsInRange(Pa
25aa0 72 73 65 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 23 rse*,int,int);.#
25ab0 65 6e 64 69 66 0a 45 78 70 72 20 2a 73 71 6c 69 endif.Expr *sqli
25ac0 74 65 33 45 78 70 72 41 6c 6c 6f 63 28 73 71 6c te3ExprAlloc(sql
25ad0 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 ite3*,int,const
25ae0 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 45 78 70 Token*,int);.Exp
25af0 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 28 73 r *sqlite3Expr(s
25b00 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 qlite3*,int,cons
25b10 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 t char*);.void s
25b20 71 6c 69 74 65 33 45 78 70 72 41 74 74 61 63 68 qlite3ExprAttach
25b30 53 75 62 74 72 65 65 73 28 73 71 6c 69 74 65 33 Subtrees(sqlite3
25b40 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 45 78 *,Expr*,Expr*,Ex
25b50 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 pr*);.Expr *sqli
25b60 74 65 33 50 45 78 70 72 28 50 61 72 73 65 2a 2c te3PExpr(Parse*,
25b70 20 69 6e 74 2c 20 45 78 70 72 2a 2c 20 45 78 70 int, Expr*, Exp
25b80 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
25b90 33 50 45 78 70 72 41 64 64 53 65 6c 65 63 74 28 3PExprAddSelect(
25ba0 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 53 Parse*, Expr*, S
25bb0 65 6c 65 63 74 2a 29 3b 0a 45 78 70 72 20 2a 73 elect*);.Expr *s
25bc0 71 6c 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 qlite3ExprAnd(sq
25bd0 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 lite3*,Expr*, Ex
25be0 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 pr*);.Expr *sqli
25bf0 74 65 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 te3ExprFunction(
25c00 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a Parse*,ExprList*
25c10 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
25c20 73 71 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 sqlite3ExprAssig
25c30 6e 56 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 nVarNumber(Parse
25c40 2a 2c 20 45 78 70 72 2a 2c 20 75 33 32 29 3b 0a *, Expr*, u32);.
25c50 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
25c60 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c Delete(sqlite3*,
25c70 20 45 78 70 72 2a 29 3b 0a 45 78 70 72 4c 69 73 Expr*);.ExprLis
25c80 74 20 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 t *sqlite3ExprLi
25c90 73 74 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c stAppend(Parse*,
25ca0 45 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 29 ExprList*,Expr*)
25cb0 3b 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 ;.ExprList *sqli
25cc0 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e te3ExprListAppen
25cd0 64 56 65 63 74 6f 72 28 50 61 72 73 65 2a 2c 45 dVector(Parse*,E
25ce0 78 70 72 4c 69 73 74 2a 2c 49 64 4c 69 73 74 2a xprList*,IdList*
25cf0 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 ,Expr*);.void sq
25d00 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 lite3ExprListSet
25d10 53 6f 72 74 4f 72 64 65 72 28 45 78 70 72 4c 69 SortOrder(ExprLi
25d20 73 74 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 st*,int);.void s
25d30 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 qlite3ExprListSe
25d40 74 4e 61 6d 65 28 50 61 72 73 65 2a 2c 45 78 70 tName(Parse*,Exp
25d50 72 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e rList*,Token*,in
25d60 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
25d70 45 78 70 72 4c 69 73 74 53 65 74 53 70 61 6e 28 ExprListSetSpan(
25d80 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a Parse*,ExprList*
25d90 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f 69 ,ExprSpan*);.voi
25da0 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 d sqlite3ExprLis
25db0 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a tDelete(sqlite3*
25dc0 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 75 33 , ExprList*);.u3
25dd0 32 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 2 sqlite3ExprLis
25de0 74 46 6c 61 67 73 28 63 6f 6e 73 74 20 45 78 70 tFlags(const Exp
25df0 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c rList*);.int sql
25e00 69 74 65 33 49 6e 69 74 28 73 71 6c 69 74 65 33 ite3Init(sqlite3
25e10 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a 69 6e 74 20 *, char**);.int
25e20 73 71 6c 69 74 65 33 49 6e 69 74 43 61 6c 6c 62 sqlite3InitCallb
25e30 61 63 6b 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 ack(void*, int,
25e40 63 68 61 72 2a 2a 2c 20 63 68 61 72 2a 2a 29 3b char**, char**);
25e50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 61 .void sqlite3Pra
25e60 67 6d 61 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e gma(Parse*,Token
25e70 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c *,Token*,Token*,
25e80 69 6e 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 int);.#ifndef SQ
25e90 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
25ea0 4c 54 41 42 4c 45 0a 4d 6f 64 75 6c 65 20 2a 73 LTABLE.Module *s
25eb0 71 6c 69 74 65 33 50 72 61 67 6d 61 56 74 61 62 qlite3PragmaVtab
25ec0 52 65 67 69 73 74 65 72 28 73 71 6c 69 74 65 33 Register(sqlite3
25ed0 2a 2c 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e *,const char *zN
25ee0 61 6d 65 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 ame);.#endif.voi
25ef0 64 20 73 71 6c 69 74 65 33 52 65 73 65 74 41 6c d sqlite3ResetAl
25f00 6c 53 63 68 65 6d 61 73 4f 66 43 6f 6e 6e 65 63 lSchemasOfConnec
25f10 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 29 3b 0a tion(sqlite3*);.
25f20 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 65 void sqlite3Rese
25f30 74 4f 6e 65 53 63 68 65 6d 61 28 73 71 6c 69 74 tOneSchema(sqlit
25f40 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 e3*,int);.void s
25f50 71 6c 69 74 65 33 43 6f 6c 6c 61 70 73 65 44 61 qlite3CollapseDa
25f60 74 61 62 61 73 65 41 72 72 61 79 28 73 71 6c 69 tabaseArray(sqli
25f70 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 te3*);.void sqli
25f80 74 65 33 43 6f 6d 6d 69 74 49 6e 74 65 72 6e 61 te3CommitInterna
25f90 6c 43 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 lChanges(sqlite3
25fa0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
25fb0 44 65 6c 65 74 65 43 6f 6c 75 6d 6e 4e 61 6d 65 DeleteColumnName
25fc0 73 28 73 71 6c 69 74 65 33 2a 2c 54 61 62 6c 65 s(sqlite3*,Table
25fd0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 *);.int sqlite3C
25fe0 6f 6c 75 6d 6e 73 46 72 6f 6d 45 78 70 72 4c 69 olumnsFromExprLi
25ff0 73 74 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 st(Parse*,ExprLi
26000 73 74 2a 2c 69 31 36 2a 2c 43 6f 6c 75 6d 6e 2a st*,i16*,Column*
26010 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
26020 53 65 6c 65 63 74 41 64 64 43 6f 6c 75 6d 6e 54 SelectAddColumnT
26030 79 70 65 41 6e 64 43 6f 6c 6c 61 74 69 6f 6e 28 ypeAndCollation(
26040 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 53 65 Parse*,Table*,Se
26050 6c 65 63 74 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 lect*);.Table *s
26060 71 6c 69 74 65 33 52 65 73 75 6c 74 53 65 74 4f qlite3ResultSetO
26070 66 53 65 6c 65 63 74 28 50 61 72 73 65 2a 2c 53 fSelect(Parse*,S
26080 65 6c 65 63 74 2a 29 3b 0a 76 6f 69 64 20 73 71 elect*);.void sq
26090 6c 69 74 65 33 4f 70 65 6e 4d 61 73 74 65 72 54 lite3OpenMasterT
260a0 61 62 6c 65 28 50 61 72 73 65 20 2a 2c 20 69 6e able(Parse *, in
260b0 74 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 74 t);.Index *sqlit
260c0 65 33 50 72 69 6d 61 72 79 4b 65 79 49 6e 64 65 e3PrimaryKeyInde
260d0 78 28 54 61 62 6c 65 2a 29 3b 0a 69 31 36 20 73 x(Table*);.i16 s
260e0 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 4f 66 49 6e qlite3ColumnOfIn
260f0 64 65 78 28 49 6e 64 65 78 2a 2c 20 69 31 36 29 dex(Index*, i16)
26100 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 ;.void sqlite3St
26110 61 72 74 54 61 62 6c 65 28 50 61 72 73 65 2a 2c artTable(Parse*,
26120 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e Token*,Token*,in
26130 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b 0a t,int,int,int);.
26140 23 69 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c #if SQLITE_ENABL
26150 45 5f 48 49 44 44 45 4e 5f 43 4f 4c 55 4d 4e 53 E_HIDDEN_COLUMNS
26160 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
26170 6f 6c 75 6d 6e 50 72 6f 70 65 72 74 69 65 73 46 olumnPropertiesF
26180 72 6f 6d 4e 61 6d 65 28 54 61 62 6c 65 2a 2c 20 romName(Table*,
26190 43 6f 6c 75 6d 6e 2a 29 3b 0a 23 65 6c 73 65 0a Column*);.#else.
261a0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
261b0 43 6f 6c 75 6d 6e 50 72 6f 70 65 72 74 69 65 73 ColumnProperties
261c0 46 72 6f 6d 4e 61 6d 65 28 54 2c 43 29 20 2f 2a FromName(T,C) /*
261d0 20 6e 6f 2d 6f 70 20 2a 2f 0a 23 65 6e 64 69 66 no-op */.#endif
261e0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
261f0 43 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c 54 6f Column(Parse*,To
26200 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 76 6f ken*,Token*);.vo
26210 69 64 20 73 71 6c 69 74 65 33 41 64 64 4e 6f 74 id sqlite3AddNot
26220 4e 75 6c 6c 28 50 61 72 73 65 2a 2c 20 69 6e 74 Null(Parse*, int
26230 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 );.void sqlite3A
26240 64 64 50 72 69 6d 61 72 79 4b 65 79 28 50 61 72 ddPrimaryKey(Par
26250 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 se*, ExprList*,
26260 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a int, int, int);.
26270 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 43 void sqlite3AddC
26280 68 65 63 6b 43 6f 6e 73 74 72 61 69 6e 74 28 50 heckConstraint(P
26290 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 arse*, Expr*);.v
262a0 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 44 65 oid sqlite3AddDe
262b0 66 61 75 6c 74 56 61 6c 75 65 28 50 61 72 73 65 faultValue(Parse
262c0 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f *,ExprSpan*);.vo
262d0 69 64 20 73 71 6c 69 74 65 33 41 64 64 43 6f 6c id sqlite3AddCol
262e0 6c 61 74 65 54 79 70 65 28 50 61 72 73 65 2a 2c lateType(Parse*,
262f0 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
26300 71 6c 69 74 65 33 45 6e 64 54 61 62 6c 65 28 50 qlite3EndTable(P
26310 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b arse*,Token*,Tok
26320 65 6e 2a 2c 75 38 2c 53 65 6c 65 63 74 2a 29 3b en*,u8,Select*);
26330 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 61 72 73 .int sqlite3Pars
26340 65 55 72 69 28 63 6f 6e 73 74 20 63 68 61 72 2a eUri(const char*
26350 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 75 6e 73 ,const char*,uns
26360 69 67 6e 65 64 20 69 6e 74 2a 2c 0a 20 20 20 20 igned int*,.
26370 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26380 73 71 6c 69 74 65 33 5f 76 66 73 2a 2a 2c 63 68 sqlite3_vfs**,ch
26390 61 72 2a 2a 2c 63 68 61 72 20 2a 2a 29 3b 0a 42 ar**,char **);.B
263a0 74 72 65 65 20 2a 73 71 6c 69 74 65 33 44 62 4e tree *sqlite3DbN
263b0 61 6d 65 54 6f 42 74 72 65 65 28 73 71 6c 69 74 ameToBtree(sqlit
263c0 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 e3*,const char*)
263d0 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
263e0 5f 55 4e 54 45 53 54 41 42 4c 45 0a 23 20 64 65 _UNTESTABLE.# de
263f0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 61 75 6c fine sqlite3Faul
26400 74 53 69 6d 28 58 29 20 53 51 4c 49 54 45 5f 4f tSim(X) SQLITE_O
26410 4b 0a 23 65 6c 73 65 0a 20 20 69 6e 74 20 73 71 K.#else. int sq
26420 6c 69 74 65 33 46 61 75 6c 74 53 69 6d 28 69 6e lite3FaultSim(in
26430 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 42 69 74 76 t);.#endif..Bitv
26440 65 63 20 2a 73 71 6c 69 74 65 33 42 69 74 76 65 ec *sqlite3Bitve
26450 63 43 72 65 61 74 65 28 75 33 32 29 3b 0a 69 6e cCreate(u32);.in
26460 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 54 t sqlite3BitvecT
26470 65 73 74 28 42 69 74 76 65 63 2a 2c 20 75 33 32 est(Bitvec*, u32
26480 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 69 );.int sqlite3Bi
26490 74 76 65 63 54 65 73 74 4e 6f 74 4e 75 6c 6c 28 tvecTestNotNull(
264a0 42 69 74 76 65 63 2a 2c 20 75 33 32 29 3b 0a 69 Bitvec*, u32);.i
264b0 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
264c0 53 65 74 28 42 69 74 76 65 63 2a 2c 20 75 33 32 Set(Bitvec*, u32
264d0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 );.void sqlite3B
264e0 69 74 76 65 63 43 6c 65 61 72 28 42 69 74 76 65 itvecClear(Bitve
264f0 63 2a 2c 20 75 33 32 2c 20 76 6f 69 64 2a 29 3b c*, u32, void*);
26500 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 69 74 .void sqlite3Bit
26510 76 65 63 44 65 73 74 72 6f 79 28 42 69 74 76 65 vecDestroy(Bitve
26520 63 2a 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 c*);.u32 sqlite3
26530 42 69 74 76 65 63 53 69 7a 65 28 42 69 74 76 65 BitvecSize(Bitve
26540 63 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c c*);.#ifndef SQL
26550 49 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a 69 ITE_UNTESTABLE.i
26560 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 nt sqlite3Bitvec
26570 42 75 69 6c 74 69 6e 54 65 73 74 28 69 6e 74 2c BuiltinTest(int,
26580 69 6e 74 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 52 int*);.#endif..R
26590 6f 77 53 65 74 20 2a 73 71 6c 69 74 65 33 52 6f owSet *sqlite3Ro
265a0 77 53 65 74 49 6e 69 74 28 73 71 6c 69 74 65 33 wSetInit(sqlite3
265b0 2a 2c 20 76 6f 69 64 2a 2c 20 75 6e 73 69 67 6e *, void*, unsign
265c0 65 64 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 ed int);.void sq
265d0 6c 69 74 65 33 52 6f 77 53 65 74 43 6c 65 61 72 lite3RowSetClear
265e0 28 52 6f 77 53 65 74 2a 29 3b 0a 76 6f 69 64 20 (RowSet*);.void
265f0 73 71 6c 69 74 65 33 52 6f 77 53 65 74 49 6e 73 sqlite3RowSetIns
26600 65 72 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 ert(RowSet*, i64
26610 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 6f );.int sqlite3Ro
26620 77 53 65 74 54 65 73 74 28 52 6f 77 53 65 74 2a wSetTest(RowSet*
26630 2c 20 69 6e 74 20 69 42 61 74 63 68 2c 20 69 36 , int iBatch, i6
26640 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 4);.int sqlite3R
26650 6f 77 53 65 74 4e 65 78 74 28 52 6f 77 53 65 74 owSetNext(RowSet
26660 2a 2c 20 69 36 34 2a 29 3b 0a 0a 76 6f 69 64 20 *, i64*);..void
26670 73 71 6c 69 74 65 33 43 72 65 61 74 65 56 69 65 sqlite3CreateVie
26680 77 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c w(Parse*,Token*,
26690 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 Token*,Token*,Ex
266a0 70 72 4c 69 73 74 2a 2c 53 65 6c 65 63 74 2a 2c prList*,Select*,
266b0 69 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 66 20 21 int,int);..#if !
266c0 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f defined(SQLITE_O
266d0 4d 49 54 5f 56 49 45 57 29 20 7c 7c 20 21 64 65 MIT_VIEW) || !de
266e0 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 fined(SQLITE_OMI
266f0 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 0a T_VIRTUALTABLE).
26700 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 69 65 int sqlite3Vie
26710 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 28 wGetColumnNames(
26720 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a Parse*,Table*);.
26730 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
26740 71 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f 6c qlite3ViewGetCol
26750 75 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 20 30 0a umnNames(A,B) 0.
26760 23 65 6e 64 69 66 0a 0a 23 69 66 20 53 51 4c 49 #endif..#if SQLI
26770 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 3e TE_MAX_ATTACHED>
26780 33 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 30. int sqlite3
26790 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 79 44 DbMaskAllZero(yD
267a0 62 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 66 0a 76 bMask);.#endif.v
267b0 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 54 oid sqlite3DropT
267c0 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 63 able(Parse*, Src
267d0 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 List*, int, int)
267e0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f ;.void sqlite3Co
267f0 64 65 44 72 6f 70 54 61 62 6c 65 28 50 61 72 73 deDropTable(Pars
26800 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
26810 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
26820 74 65 33 44 65 6c 65 74 65 54 61 62 6c 65 28 73 te3DeleteTable(s
26830 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 qlite3*, Table*)
26840 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
26850 5f 4f 4d 49 54 5f 41 55 54 4f 49 4e 43 52 45 4d _OMIT_AUTOINCREM
26860 45 4e 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 ENT. void sqlit
26870 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 42 e3AutoincrementB
26880 65 67 69 6e 28 50 61 72 73 65 20 2a 70 50 61 72 egin(Parse *pPar
26890 73 65 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 se);. void sqli
268a0 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 te3Autoincrement
268b0 45 6e 64 28 50 61 72 73 65 20 2a 70 50 61 72 73 End(Parse *pPars
268c0 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 e);.#else.# defi
268d0 6e 65 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e ne sqlite3Autoin
268e0 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 58 29 0a crementBegin(X).
268f0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
26900 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 45 6e 64 AutoincrementEnd
26910 28 58 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 (X).#endif.void
26920 73 71 6c 69 74 65 33 49 6e 73 65 72 74 28 50 61 sqlite3Insert(Pa
26930 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 rse*, SrcList*,
26940 53 65 6c 65 63 74 2a 2c 20 49 64 4c 69 73 74 2a Select*, IdList*
26950 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 71 , int);.void *sq
26960 6c 69 74 65 33 41 72 72 61 79 41 6c 6c 6f 63 61 lite3ArrayAlloca
26970 74 65 28 73 71 6c 69 74 65 33 2a 2c 76 6f 69 64 te(sqlite3*,void
26980 2a 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2a 29 *,int,int*,int*)
26990 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 ;.IdList *sqlite
269a0 33 49 64 4c 69 73 74 41 70 70 65 6e 64 28 73 71 3IdListAppend(sq
269b0 6c 69 74 65 33 2a 2c 20 49 64 4c 69 73 74 2a 2c lite3*, IdList*,
269c0 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 Token*);.int sq
269d0 6c 69 74 65 33 49 64 4c 69 73 74 49 6e 64 65 78 lite3IdListIndex
269e0 28 49 64 4c 69 73 74 2a 2c 63 6f 6e 73 74 20 63 (IdList*,const c
269f0 68 61 72 2a 29 3b 0a 53 72 63 4c 69 73 74 20 2a har*);.SrcList *
26a00 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 45 6e sqlite3SrcListEn
26a10 6c 61 72 67 65 28 73 71 6c 69 74 65 33 2a 2c 20 large(sqlite3*,
26a20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 SrcList*, int, i
26a30 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 2a 73 71 nt);.SrcList *sq
26a40 6c 69 74 65 33 53 72 63 4c 69 73 74 41 70 70 65 lite3SrcListAppe
26a50 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 53 72 63 nd(sqlite3*, Src
26a60 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 List*, Token*, T
26a70 6f 6b 65 6e 2a 29 3b 0a 53 72 63 4c 69 73 74 20 oken*);.SrcList
26a80 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 41 *sqlite3SrcListA
26a90 70 70 65 6e 64 46 72 6f 6d 54 65 72 6d 28 50 61 ppendFromTerm(Pa
26aa0 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 rse*, SrcList*,
26ab0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 0a Token*, Token*,.
26ac0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26ad0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26ae0 20 20 20 20 20 20 54 6f 6b 65 6e 2a 2c 20 53 65 Token*, Se
26af0 6c 65 63 74 2a 2c 20 45 78 70 72 2a 2c 20 49 64 lect*, Expr*, Id
26b00 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c List*);.void sql
26b10 69 74 65 33 53 72 63 4c 69 73 74 49 6e 64 65 78 ite3SrcListIndex
26b20 65 64 42 79 28 50 61 72 73 65 20 2a 2c 20 53 72 edBy(Parse *, Sr
26b30 63 4c 69 73 74 20 2a 2c 20 54 6f 6b 65 6e 20 2a cList *, Token *
26b40 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
26b50 72 63 4c 69 73 74 46 75 6e 63 41 72 67 73 28 50 rcListFuncArgs(P
26b60 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c arse*, SrcList*,
26b70 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 ExprList*);.int
26b80 20 73 71 6c 69 74 65 33 49 6e 64 65 78 65 64 42 sqlite3IndexedB
26b90 79 4c 6f 6f 6b 75 70 28 50 61 72 73 65 20 2a 2c yLookup(Parse *,
26ba0 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f struct SrcList_
26bb0 69 74 65 6d 20 2a 29 3b 0a 76 6f 69 64 20 73 71 item *);.void sq
26bc0 6c 69 74 65 33 53 72 63 4c 69 73 74 53 68 69 66 lite3SrcListShif
26bd0 74 4a 6f 69 6e 54 79 70 65 28 53 72 63 4c 69 73 tJoinType(SrcLis
26be0 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 t*);.void sqlite
26bf0 33 53 72 63 4c 69 73 74 41 73 73 69 67 6e 43 75 3SrcListAssignCu
26c00 72 73 6f 72 73 28 50 61 72 73 65 2a 2c 20 53 72 rsors(Parse*, Sr
26c10 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 cList*);.void sq
26c20 6c 69 74 65 33 49 64 4c 69 73 74 44 65 6c 65 74 lite3IdListDelet
26c30 65 28 73 71 6c 69 74 65 33 2a 2c 20 49 64 4c 69 e(sqlite3*, IdLi
26c40 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 st*);.void sqlit
26c50 65 33 53 72 63 4c 69 73 74 44 65 6c 65 74 65 28 e3SrcListDelete(
26c60 73 71 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 sqlite3*, SrcLis
26c70 74 2a 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 t*);.Index *sqli
26c80 74 65 33 41 6c 6c 6f 63 61 74 65 49 6e 64 65 78 te3AllocateIndex
26c90 4f 62 6a 65 63 74 28 73 71 6c 69 74 65 33 2a 2c Object(sqlite3*,
26ca0 69 31 36 2c 69 6e 74 2c 63 68 61 72 2a 2a 29 3b i16,int,char**);
26cb0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 72 65 .void sqlite3Cre
26cc0 61 74 65 49 6e 64 65 78 28 50 61 72 73 65 2a 2c ateIndex(Parse*,
26cd0 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 53 72 Token*,Token*,Sr
26ce0 63 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 2a cList*,ExprList*
26cf0 2c 69 6e 74 2c 54 6f 6b 65 6e 2a 2c 0a 20 20 20 ,int,Token*,.
26d00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26d10 20 20 20 20 20 20 20 45 78 70 72 2a 2c 20 69 6e Expr*, in
26d20 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 76 6f 69 t, int, u8);.voi
26d30 64 20 73 71 6c 69 74 65 33 44 72 6f 70 49 6e 64 d sqlite3DropInd
26d40 65 78 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 ex(Parse*, SrcLi
26d50 73 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 st*, int);.int s
26d60 71 6c 69 74 65 33 53 65 6c 65 63 74 28 50 61 72 qlite3Select(Par
26d70 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 53 65 se*, Select*, Se
26d80 6c 65 63 74 44 65 73 74 2a 29 3b 0a 53 65 6c 65 lectDest*);.Sele
26d90 63 74 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 ct *sqlite3Selec
26da0 74 4e 65 77 28 50 61 72 73 65 2a 2c 45 78 70 72 tNew(Parse*,Expr
26db0 4c 69 73 74 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 List*,SrcList*,E
26dc0 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 0a xpr*,ExprList*,.
26dd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26de0 20 20 20 20 20 20 20 20 20 45 78 70 72 2a 2c 45 Expr*,E
26df0 78 70 72 4c 69 73 74 2a 2c 75 33 32 2c 45 78 70 xprList*,u32,Exp
26e00 72 2a 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 r*,Expr*);.void
26e10 73 71 6c 69 74 65 33 53 65 6c 65 63 74 44 65 6c sqlite3SelectDel
26e20 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 53 65 ete(sqlite3*, Se
26e30 6c 65 63 74 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 lect*);.Table *s
26e40 71 6c 69 74 65 33 53 72 63 4c 69 73 74 4c 6f 6f qlite3SrcListLoo
26e50 6b 75 70 28 50 61 72 73 65 2a 2c 20 53 72 63 4c kup(Parse*, SrcL
26e60 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ist*);.int sqlit
26e70 65 33 49 73 52 65 61 64 4f 6e 6c 79 28 50 61 72 e3IsReadOnly(Par
26e80 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
26e90 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f );.void sqlite3O
26ea0 70 65 6e 54 61 62 6c 65 28 50 61 72 73 65 2a 2c penTable(Parse*,
26eb0 20 69 6e 74 20 69 43 75 72 2c 20 69 6e 74 20 69 int iCur, int i
26ec0 44 62 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 Db, Table*, int)
26ed0 3b 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 ;.#if defined(SQ
26ee0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 50 44 41 LITE_ENABLE_UPDA
26ef0 54 45 5f 44 45 4c 45 54 45 5f 4c 49 4d 49 54 29 TE_DELETE_LIMIT)
26f00 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c && !defined(SQL
26f10 49 54 45 5f 4f 4d 49 54 5f 53 55 42 51 55 45 52 ITE_OMIT_SUBQUER
26f20 59 29 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 Y).Expr *sqlite3
26f30 4c 69 6d 69 74 57 68 65 72 65 28 50 61 72 73 65 LimitWhere(Parse
26f40 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a *,SrcList*,Expr*
26f50 2c 45 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a ,ExprList*,Expr*
26f60 2c 45 78 70 72 2a 2c 63 68 61 72 2a 29 3b 0a 23 ,Expr*,char*);.#
26f70 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
26f80 65 33 44 65 6c 65 74 65 46 72 6f 6d 28 50 61 72 e3DeleteFrom(Par
26f90 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 45 se*, SrcList*, E
26fa0 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
26fb0 74 65 33 55 70 64 61 74 65 28 50 61 72 73 65 2a te3Update(Parse*
26fc0 2c 20 53 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 , SrcList*, Expr
26fd0 4c 69 73 74 2a 2c 20 45 78 70 72 2a 2c 20 69 6e List*, Expr*, in
26fe0 74 29 3b 0a 57 68 65 72 65 49 6e 66 6f 20 2a 73 t);.WhereInfo *s
26ff0 71 6c 69 74 65 33 57 68 65 72 65 42 65 67 69 6e qlite3WhereBegin
27000 28 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a (Parse*,SrcList*
27010 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a ,Expr*,ExprList*
27020 2c 45 78 70 72 4c 69 73 74 2a 2c 75 31 36 2c 69 ,ExprList*,u16,i
27030 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27040 33 57 68 65 72 65 45 6e 64 28 57 68 65 72 65 49 3WhereEnd(WhereI
27050 6e 66 6f 2a 29 3b 0a 4c 6f 67 45 73 74 20 73 71 nfo*);.LogEst sq
27060 6c 69 74 65 33 57 68 65 72 65 4f 75 74 70 75 74 lite3WhereOutput
27070 52 6f 77 43 6f 75 6e 74 28 57 68 65 72 65 49 6e RowCount(WhereIn
27080 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 fo*);.int sqlite
27090 33 57 68 65 72 65 49 73 44 69 73 74 69 6e 63 74 3WhereIsDistinct
270a0 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e (WhereInfo*);.in
270b0 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 t sqlite3WhereIs
270c0 4f 72 64 65 72 65 64 28 57 68 65 72 65 49 6e 66 Ordered(WhereInf
270d0 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 o*);.int sqlite3
270e0 57 68 65 72 65 4f 72 64 65 72 65 64 49 6e 6e 65 WhereOrderedInne
270f0 72 4c 6f 6f 70 28 57 68 65 72 65 49 6e 66 6f 2a rLoop(WhereInfo*
27100 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 );.int sqlite3Wh
27110 65 72 65 49 73 53 6f 72 74 65 64 28 57 68 65 72 ereIsSorted(Wher
27120 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c eInfo*);.int sql
27130 69 74 65 33 57 68 65 72 65 43 6f 6e 74 69 6e 75 ite3WhereContinu
27140 65 4c 61 62 65 6c 28 57 68 65 72 65 49 6e 66 6f eLabel(WhereInfo
27150 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 *);.int sqlite3W
27160 68 65 72 65 42 72 65 61 6b 4c 61 62 65 6c 28 57 hereBreakLabel(W
27170 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 hereInfo*);.int
27180 73 71 6c 69 74 65 33 57 68 65 72 65 4f 6b 4f 6e sqlite3WhereOkOn
27190 65 50 61 73 73 28 57 68 65 72 65 49 6e 66 6f 2a ePass(WhereInfo*
271a0 2c 20 69 6e 74 2a 29 3b 0a 23 64 65 66 69 6e 65 , int*);.#define
271b0 20 4f 4e 45 50 41 53 53 5f 4f 46 46 20 20 20 20 ONEPASS_OFF
271c0 20 20 30 20 20 20 20 20 20 20 20 2f 2a 20 55 73 0 /* Us
271d0 65 20 6f 66 20 4f 4e 45 50 41 53 53 20 6e 6f 74 e of ONEPASS not
271e0 20 61 6c 6c 6f 77 65 64 20 2a 2f 0a 23 64 65 66 allowed */.#def
271f0 69 6e 65 20 4f 4e 45 50 41 53 53 5f 53 49 4e 47 ine ONEPASS_SING
27200 4c 45 20 20 20 31 20 20 20 20 20 20 20 20 2f 2a LE 1 /*
27210 20 4f 4e 45 50 41 53 53 20 76 61 6c 69 64 20 66 ONEPASS valid f
27220 6f 72 20 61 20 73 69 6e 67 6c 65 20 72 6f 77 20 or a single row
27230 75 70 64 61 74 65 20 2a 2f 0a 23 64 65 66 69 6e update */.#defin
27240 65 20 4f 4e 45 50 41 53 53 5f 4d 55 4c 54 49 20 e ONEPASS_MULTI
27250 20 20 20 32 20 20 20 20 20 20 20 20 2f 2a 20 4f 2 /* O
27260 4e 45 50 41 53 53 20 69 73 20 76 61 6c 69 64 20 NEPASS is valid
27270 66 6f 72 20 6d 75 6c 74 69 70 6c 65 20 72 6f 77 for multiple row
27280 73 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 65 s */.void sqlite
27290 33 45 78 70 72 43 6f 64 65 4c 6f 61 64 49 6e 64 3ExprCodeLoadInd
272a0 65 78 43 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c exColumn(Parse*,
272b0 20 49 6e 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e Index*, int, in
272c0 74 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c t, int);.int sql
272d0 69 74 65 33 45 78 70 72 43 6f 64 65 47 65 74 43 ite3ExprCodeGetC
272e0 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c 20 54 61 olumn(Parse*, Ta
272f0 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 ble*, int, int,
27300 69 6e 74 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 int, u8);.void s
27310 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 47 65 qlite3ExprCodeGe
27320 74 43 6f 6c 75 6d 6e 54 6f 52 65 67 28 50 61 72 tColumnToReg(Par
27330 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
27340 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
27350 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 d sqlite3ExprCod
27360 65 47 65 74 43 6f 6c 75 6d 6e 4f 66 54 61 62 6c eGetColumnOfTabl
27370 65 28 56 64 62 65 2a 2c 20 54 61 62 6c 65 2a 2c e(Vdbe*, Table*,
27380 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
27390 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
273a0 72 43 6f 64 65 4d 6f 76 65 28 50 61 72 73 65 2a rCodeMove(Parse*
273b0 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
273c0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
273d0 70 72 43 61 63 68 65 53 74 6f 72 65 28 50 61 72 prCacheStore(Par
273e0 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 se*, int, int, i
273f0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27400 33 45 78 70 72 43 61 63 68 65 50 75 73 68 28 50 3ExprCachePush(P
27410 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c arse*);.void sql
27420 69 74 65 33 45 78 70 72 43 61 63 68 65 50 6f 70 ite3ExprCachePop
27430 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 (Parse*);.void s
27440 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 52 qlite3ExprCacheR
27450 65 6d 6f 76 65 28 50 61 72 73 65 2a 2c 20 69 6e emove(Parse*, in
27460 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
27470 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 43 6c lite3ExprCacheCl
27480 65 61 72 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ear(Parse*);.voi
27490 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 d sqlite3ExprCac
274a0 68 65 41 66 66 69 6e 69 74 79 43 68 61 6e 67 65 heAffinityChange
274b0 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e (Parse*, int, in
274c0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
274d0 45 78 70 72 43 6f 64 65 28 50 61 72 73 65 2a 2c ExprCode(Parse*,
274e0 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f Expr*, int);.vo
274f0 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f id sqlite3ExprCo
27500 64 65 43 6f 70 79 28 50 61 72 73 65 2a 2c 20 45 deCopy(Parse*, E
27510 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 xpr*, int);.void
27520 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 sqlite3ExprCode
27530 46 61 63 74 6f 72 61 62 6c 65 28 50 61 72 73 65 Factorable(Parse
27540 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a *, Expr*, int);.
27550 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
27560 43 6f 64 65 41 74 49 6e 69 74 28 50 61 72 73 65 CodeAtInit(Parse
27570 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 75 *, Expr*, int, u
27580 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 8);.int sqlite3E
27590 78 70 72 43 6f 64 65 54 65 6d 70 28 50 61 72 73 xprCodeTemp(Pars
275a0 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2a 29 e*, Expr*, int*)
275b0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 ;.int sqlite3Exp
275c0 72 43 6f 64 65 54 61 72 67 65 74 28 50 61 72 73 rCodeTarget(Pars
275d0 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b e*, Expr*, int);
275e0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
275f0 72 43 6f 64 65 41 6e 64 43 61 63 68 65 28 50 61 rCodeAndCache(Pa
27600 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 rse*, Expr*, int
27610 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
27620 70 72 43 6f 64 65 45 78 70 72 4c 69 73 74 28 50 prCodeExprList(P
27630 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a arse*, ExprList*
27640 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b , int, int, u8);
27650 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
27660 45 43 45 4c 5f 44 55 50 20 20 20 20 20 20 30 78 ECEL_DUP 0x
27670 30 31 20 20 2f 2a 20 44 65 65 70 2c 20 6e 6f 74 01 /* Deep, not
27680 20 73 68 61 6c 6c 6f 77 20 63 6f 70 69 65 73 20 shallow copies
27690 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
276a0 45 5f 45 43 45 4c 5f 46 41 43 54 4f 52 20 20 20 E_ECEL_FACTOR
276b0 30 78 30 32 20 20 2f 2a 20 46 61 63 74 6f 72 20 0x02 /* Factor
276c0 6f 75 74 20 63 6f 6e 73 74 61 6e 74 20 74 65 72 out constant ter
276d0 6d 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ms */.#define SQ
276e0 4c 49 54 45 5f 45 43 45 4c 5f 52 45 46 20 20 20 LITE_ECEL_REF
276f0 20 20 20 30 78 30 34 20 20 2f 2a 20 55 73 65 20 0x04 /* Use
27700 45 78 70 72 4c 69 73 74 2e 75 2e 78 2e 69 4f 72 ExprList.u.x.iOr
27710 64 65 72 42 79 43 6f 6c 20 2a 2f 0a 23 64 65 66 derByCol */.#def
27720 69 6e 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f ine SQLITE_ECEL_
27730 4f 4d 49 54 52 45 46 20 20 30 78 30 38 20 20 2f OMITREF 0x08 /
27740 2a 20 4f 6d 69 74 20 69 66 20 45 78 70 72 4c 69 * Omit if ExprLi
27750 73 74 2e 75 2e 78 2e 69 4f 72 64 65 72 42 79 43 st.u.x.iOrderByC
27760 6f 6c 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 ol */.void sqlit
27770 65 33 45 78 70 72 49 66 54 72 75 65 28 50 61 72 e3ExprIfTrue(Par
27780 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c se*, Expr*, int,
27790 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
277a0 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 28 50 te3ExprIfFalse(P
277b0 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
277c0 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
277d0 6c 69 74 65 33 45 78 70 72 49 66 46 61 6c 73 65 lite3ExprIfFalse
277e0 44 75 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 Dup(Parse*, Expr
277f0 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 54 61 *, int, int);.Ta
27800 62 6c 65 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 ble *sqlite3Find
27810 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 63 Table(sqlite3*,c
27820 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
27830 74 20 63 68 61 72 2a 29 3b 0a 23 64 65 66 69 6e t char*);.#defin
27840 65 20 4c 4f 43 41 54 45 5f 56 49 45 57 20 20 20 e LOCATE_VIEW
27850 20 30 78 30 31 0a 23 64 65 66 69 6e 65 20 4c 4f 0x01.#define LO
27860 43 41 54 45 5f 4e 4f 45 52 52 20 20 20 30 78 30 CATE_NOERR 0x0
27870 32 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 2.Table *sqlite3
27880 4c 6f 63 61 74 65 54 61 62 6c 65 28 50 61 72 73 LocateTable(Pars
27890 65 2a 2c 75 33 32 20 66 6c 61 67 73 2c 63 6f 6e e*,u32 flags,con
278a0 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
278b0 63 68 61 72 2a 29 3b 0a 54 61 62 6c 65 20 2a 73 char*);.Table *s
278c0 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 62 6c qlite3LocateTabl
278d0 65 49 74 65 6d 28 50 61 72 73 65 2a 2c 75 33 32 eItem(Parse*,u32
278e0 20 66 6c 61 67 73 2c 73 74 72 75 63 74 20 53 72 flags,struct Sr
278f0 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 3b 0a 49 cList_item *);.I
27900 6e 64 65 78 20 2a 73 71 6c 69 74 65 33 46 69 6e ndex *sqlite3Fin
27910 64 49 6e 64 65 78 28 73 71 6c 69 74 65 33 2a 2c dIndex(sqlite3*,
27920 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
27930 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
27940 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 sqlite3UnlinkAnd
27950 44 65 6c 65 74 65 54 61 62 6c 65 28 73 71 6c 69 DeleteTable(sqli
27960 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 te3*,int,const c
27970 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 har*);.void sqli
27980 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 te3UnlinkAndDele
27990 74 65 49 6e 64 65 78 28 73 71 6c 69 74 65 33 2a teIndex(sqlite3*
279a0 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
279b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 );.void sqlite3V
279c0 61 63 75 75 6d 28 50 61 72 73 65 2a 2c 54 6f 6b acuum(Parse*,Tok
279d0 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 en*);.int sqlite
279e0 33 52 75 6e 56 61 63 75 75 6d 28 63 68 61 72 2a 3RunVacuum(char*
279f0 2a 2c 20 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 *, sqlite3*, int
27a00 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
27a10 4e 61 6d 65 46 72 6f 6d 54 6f 6b 65 6e 28 73 71 NameFromToken(sq
27a20 6c 69 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a 29 3b lite3*, Token*);
27a30 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
27a40 43 6f 6d 70 61 72 65 28 45 78 70 72 2a 2c 20 45 Compare(Expr*, E
27a50 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 xpr*, int);.int
27a60 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 43 sqlite3ExprListC
27a70 6f 6d 70 61 72 65 28 45 78 70 72 4c 69 73 74 2a ompare(ExprList*
27a80 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 , ExprList*, int
27a90 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
27aa0 70 72 49 6d 70 6c 69 65 73 45 78 70 72 28 45 78 prImpliesExpr(Ex
27ab0 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 pr*, Expr*, int)
27ac0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
27ad0 70 72 41 6e 61 6c 79 7a 65 41 67 67 72 65 67 61 prAnalyzeAggrega
27ae0 74 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a tes(NameContext*
27af0 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 , Expr*);.void s
27b00 71 6c 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a qlite3ExprAnalyz
27b10 65 41 67 67 4c 69 73 74 28 4e 61 6d 65 43 6f 6e eAggList(NameCon
27b20 74 65 78 74 2a 2c 45 78 70 72 4c 69 73 74 2a 29 text*,ExprList*)
27b30 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 ;.int sqlite3Exp
27b40 72 43 6f 76 65 72 65 64 42 79 49 6e 64 65 78 28 rCoveredByIndex(
27b50 45 78 70 72 2a 2c 20 69 6e 74 20 69 43 75 72 2c Expr*, int iCur,
27b60 20 49 6e 64 65 78 20 2a 70 49 64 78 29 3b 0a 69 Index *pIdx);.i
27b70 6e 74 20 73 71 6c 69 74 65 33 46 75 6e 63 74 69 nt sqlite3Functi
27b80 6f 6e 55 73 65 73 54 68 69 73 53 72 63 28 45 78 onUsesThisSrc(Ex
27b90 70 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a pr*, SrcList*);.
27ba0 56 64 62 65 20 2a 73 71 6c 69 74 65 33 47 65 74 Vdbe *sqlite3Get
27bb0 56 64 62 65 28 50 61 72 73 65 2a 29 3b 0a 23 69 Vdbe(Parse*);.#i
27bc0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 fndef SQLITE_UNT
27bd0 45 53 54 41 42 4c 45 0a 76 6f 69 64 20 73 71 6c ESTABLE.void sql
27be0 69 74 65 33 50 72 6e 67 53 61 76 65 53 74 61 74 ite3PrngSaveStat
27bf0 65 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 e(void);.void sq
27c00 6c 69 74 65 33 50 72 6e 67 52 65 73 74 6f 72 65 lite3PrngRestore
27c10 53 74 61 74 65 28 76 6f 69 64 29 3b 0a 23 65 6e State(void);.#en
27c20 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
27c30 52 6f 6c 6c 62 61 63 6b 41 6c 6c 28 73 71 6c 69 RollbackAll(sqli
27c40 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 te3*,int);.void
27c50 73 71 6c 69 74 65 33 43 6f 64 65 56 65 72 69 66 sqlite3CodeVerif
27c60 79 53 63 68 65 6d 61 28 50 61 72 73 65 2a 2c 20 ySchema(Parse*,
27c70 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
27c80 65 33 43 6f 64 65 56 65 72 69 66 79 4e 61 6d 65 e3CodeVerifyName
27c90 64 53 63 68 65 6d 61 28 50 61 72 73 65 2a 2c 20 dSchema(Parse*,
27ca0 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 29 const char *zDb)
27cb0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 ;.void sqlite3Be
27cc0 67 69 6e 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 ginTransaction(P
27cd0 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 arse*, int);.voi
27ce0 64 20 73 71 6c 69 74 65 33 43 6f 6d 6d 69 74 54 d sqlite3CommitT
27cf0 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 73 65 ransaction(Parse
27d00 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
27d10 52 6f 6c 6c 62 61 63 6b 54 72 61 6e 73 61 63 74 RollbackTransact
27d20 69 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ion(Parse*);.voi
27d30 64 20 73 71 6c 69 74 65 33 53 61 76 65 70 6f 69 d sqlite3Savepoi
27d40 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 nt(Parse*, int,
27d50 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 Token*);.void sq
27d60 6c 69 74 65 33 43 6c 6f 73 65 53 61 76 65 70 6f lite3CloseSavepo
27d70 69 6e 74 73 28 73 71 6c 69 74 65 33 20 2a 29 3b ints(sqlite3 *);
27d80 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4c 65 61 .void sqlite3Lea
27d90 76 65 4d 75 74 65 78 41 6e 64 43 6c 6f 73 65 5a veMutexAndCloseZ
27da0 6f 6d 62 69 65 28 73 71 6c 69 74 65 33 2a 29 3b ombie(sqlite3*);
27db0 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
27dc0 49 73 43 6f 6e 73 74 61 6e 74 28 45 78 70 72 2a IsConstant(Expr*
27dd0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
27de0 70 72 49 73 43 6f 6e 73 74 61 6e 74 4e 6f 74 4a prIsConstantNotJ
27df0 6f 69 6e 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 oin(Expr*);.int
27e00 73 71 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e sqlite3ExprIsCon
27e10 73 74 61 6e 74 4f 72 46 75 6e 63 74 69 6f 6e 28 stantOrFunction(
27e20 45 78 70 72 2a 2c 20 75 38 29 3b 0a 69 6e 74 20 Expr*, u8);.int
27e30 73 71 6c 69 74 65 33 45 78 70 72 49 73 54 61 62 sqlite3ExprIsTab
27e40 6c 65 43 6f 6e 73 74 61 6e 74 28 45 78 70 72 2a leConstant(Expr*
27e50 2c 69 6e 74 29 3b 0a 23 69 66 64 65 66 20 53 51 ,int);.#ifdef SQ
27e60 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 43 55 52 53 LITE_ENABLE_CURS
27e70 4f 52 5f 48 49 4e 54 53 0a 69 6e 74 20 73 71 6c OR_HINTS.int sql
27e80 69 74 65 33 45 78 70 72 43 6f 6e 74 61 69 6e 73 ite3ExprContains
27e90 53 75 62 71 75 65 72 79 28 45 78 70 72 2a 29 3b Subquery(Expr*);
27ea0 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 .#endif.int sqli
27eb0 74 65 33 45 78 70 72 49 73 49 6e 74 65 67 65 72 te3ExprIsInteger
27ec0 28 45 78 70 72 2a 2c 20 69 6e 74 2a 29 3b 0a 69 (Expr*, int*);.i
27ed0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 nt sqlite3ExprCa
27ee0 6e 42 65 4e 75 6c 6c 28 63 6f 6e 73 74 20 45 78 nBeNull(const Ex
27ef0 70 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 pr*);.int sqlite
27f00 33 45 78 70 72 4e 65 65 64 73 4e 6f 41 66 66 69 3ExprNeedsNoAffi
27f10 6e 69 74 79 43 68 61 6e 67 65 28 63 6f 6e 73 74 nityChange(const
27f20 20 45 78 70 72 2a 2c 20 63 68 61 72 29 3b 0a 69 Expr*, char);.i
27f30 6e 74 20 73 71 6c 69 74 65 33 49 73 52 6f 77 69 nt sqlite3IsRowi
27f40 64 28 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a d(const char*);.
27f50 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e 65 void sqlite3Gene
27f60 72 61 74 65 52 6f 77 44 65 6c 65 74 65 28 0a 20 rateRowDelete(.
27f70 20 20 20 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a Parse*,Table*
27f80 2c 54 72 69 67 67 65 72 2a 2c 69 6e 74 2c 69 6e ,Trigger*,int,in
27f90 74 2c 69 6e 74 2c 69 31 36 2c 75 38 2c 75 38 2c t,int,i16,u8,u8,
27fa0 75 38 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 u8,int);.void sq
27fb0 6c 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 lite3GenerateRow
27fc0 49 6e 64 65 78 44 65 6c 65 74 65 28 50 61 72 73 IndexDelete(Pars
27fd0 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
27fe0 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 int, int*, int)
27ff0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 6e ;.int sqlite3Gen
28000 65 72 61 74 65 49 6e 64 65 78 4b 65 79 28 50 61 erateIndexKey(Pa
28010 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c 20 69 6e rse*, Index*, in
28020 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 t, int, int, int
28030 2a 2c 49 6e 64 65 78 2a 2c 69 6e 74 29 3b 0a 76 *,Index*,int);.v
28040 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 6f 6c oid sqlite3Resol
28050 76 65 50 61 72 74 49 64 78 4c 61 62 65 6c 28 50 vePartIdxLabel(P
28060 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 arse*,int);.void
28070 20 73 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 sqlite3Generate
28080 43 6f 6e 73 74 72 61 69 6e 74 43 68 65 63 6b 73 ConstraintChecks
28090 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 (Parse*,Table*,i
280a0 6e 74 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c nt*,int,int,int,
280b0 69 6e 74 2c 0a 20 20 20 20 20 20 20 20 20 20 20 int,.
280c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
280d0 20 20 20 20 20 20 20 20 20 20 75 38 2c 75 38 2c u8,u8,
280e0 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2a 29 3b 0a int,int*,int*);.
280f0 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 70 void sqlite3Comp
28100 6c 65 74 65 49 6e 73 65 72 74 69 6f 6e 28 50 61 leteInsertion(Pa
28110 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c rse*,Table*,int,
28120 69 6e 74 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 int,int,int*,int
28130 2c 69 6e 74 2c 69 6e 74 29 3b 0a 69 6e 74 20 73 ,int,int);.int s
28140 71 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 41 qlite3OpenTableA
28150 6e 64 49 6e 64 69 63 65 73 28 50 61 72 73 65 2a ndIndices(Parse*
28160 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 75 , Table*, int, u
28170 38 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 69 6e 74 8, int, u8*, int
28180 2a 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 *, int*);.void s
28190 71 6c 69 74 65 33 42 65 67 69 6e 57 72 69 74 65 qlite3BeginWrite
281a0 4f 70 65 72 61 74 69 6f 6e 28 50 61 72 73 65 2a Operation(Parse*
281b0 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
281c0 64 20 73 71 6c 69 74 65 33 4d 75 6c 74 69 57 72 d sqlite3MultiWr
281d0 69 74 65 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ite(Parse*);.voi
281e0 64 20 73 71 6c 69 74 65 33 4d 61 79 41 62 6f 72 d sqlite3MayAbor
281f0 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 t(Parse*);.void
28200 73 71 6c 69 74 65 33 48 61 6c 74 43 6f 6e 73 74 sqlite3HaltConst
28210 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e raint(Parse*, in
28220 74 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2c 20 69 t, int, char*, i
28230 38 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 8, u8);.void sql
28240 69 74 65 33 55 6e 69 71 75 65 43 6f 6e 73 74 72 ite3UniqueConstr
28250 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 aint(Parse*, int
28260 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 , Index*);.void
28270 73 71 6c 69 74 65 33 52 6f 77 69 64 43 6f 6e 73 sqlite3RowidCons
28280 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 traint(Parse*, i
28290 6e 74 2c 20 54 61 62 6c 65 2a 29 3b 0a 45 78 70 nt, Table*);.Exp
282a0 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 44 75 r *sqlite3ExprDu
282b0 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a p(sqlite3*,Expr*
282c0 2c 69 6e 74 29 3b 0a 45 78 70 72 4c 69 73 74 20 ,int);.ExprList
282d0 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 *sqlite3ExprList
282e0 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 Dup(sqlite3*,Exp
282f0 72 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 53 72 63 rList*,int);.Src
28300 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 List *sqlite3Src
28310 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a ListDup(sqlite3*
28320 2c 53 72 63 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a ,SrcList*,int);.
28330 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 49 IdList *sqlite3I
28340 64 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 33 dListDup(sqlite3
28350 2a 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 65 6c 65 *,IdList*);.Sele
28360 63 74 20 2a 73 71 6c 69 74 65 33 53 65 6c 65 63 ct *sqlite3Selec
28370 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 53 65 tDup(sqlite3*,Se
28380 6c 65 63 74 2a 2c 69 6e 74 29 3b 0a 23 69 66 20 lect*,int);.#if
28390 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
283a0 4c 45 44 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 LED.void sqlite3
283b0 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 28 53 65 SelectSetName(Se
283c0 6c 65 63 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 lect*,const char
283d0 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
283e0 6e 65 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 ne sqlite3Select
283f0 53 65 74 4e 61 6d 65 28 41 2c 42 29 0a 23 65 6e SetName(A,B).#en
28400 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 dif.void sqlite3
28410 49 6e 73 65 72 74 42 75 69 6c 74 69 6e 46 75 6e InsertBuiltinFun
28420 63 73 28 46 75 6e 63 44 65 66 2a 2c 69 6e 74 29 cs(FuncDef*,int)
28430 3b 0a 46 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 ;.FuncDef *sqlit
28440 65 33 46 69 6e 64 46 75 6e 63 74 69 6f 6e 28 73 e3FindFunction(s
28450 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
28460 61 72 2a 2c 69 6e 74 2c 75 38 2c 75 38 29 3b 0a ar*,int,u8,u8);.
28470 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 void sqlite3Regi
28480 73 74 65 72 42 75 69 6c 74 69 6e 46 75 6e 63 74 sterBuiltinFunct
28490 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 ions(void);.void
284a0 20 73 71 6c 69 74 65 33 52 65 67 69 73 74 65 72 sqlite3Register
284b0 44 61 74 65 54 69 6d 65 46 75 6e 63 74 69 6f 6e DateTimeFunction
284c0 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 s(void);.void sq
284d0 6c 69 74 65 33 52 65 67 69 73 74 65 72 50 65 72 lite3RegisterPer
284e0 43 6f 6e 6e 65 63 74 69 6f 6e 42 75 69 6c 74 69 ConnectionBuilti
284f0 6e 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 nFunctions(sqlit
28500 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 e3*);.int sqlite
28510 33 53 61 66 65 74 79 43 68 65 63 6b 4f 6b 28 73 3SafetyCheckOk(s
28520 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 qlite3*);.int sq
28530 6c 69 74 65 33 53 61 66 65 74 79 43 68 65 63 6b lite3SafetyCheck
28540 53 69 63 6b 4f 72 4f 6b 28 73 71 6c 69 74 65 33 SickOrOk(sqlite3
28550 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
28560 43 68 61 6e 67 65 43 6f 6f 6b 69 65 28 50 61 72 ChangeCookie(Par
28570 73 65 2a 2c 20 69 6e 74 29 3b 0a 0a 23 69 66 20 se*, int);..#if
28580 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
28590 4f 4d 49 54 5f 56 49 45 57 29 20 26 26 20 21 64 OMIT_VIEW) && !d
285a0 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d efined(SQLITE_OM
285b0 49 54 5f 54 52 49 47 47 45 52 29 0a 76 6f 69 64 IT_TRIGGER).void
285c0 20 73 71 6c 69 74 65 33 4d 61 74 65 72 69 61 6c sqlite3Material
285d0 69 7a 65 56 69 65 77 28 50 61 72 73 65 2a 2c 20 izeView(Parse*,
285e0 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Table*, Expr*, i
285f0 6e 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 nt);.#endif..#if
28600 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
28610 5f 54 52 49 47 47 45 52 0a 20 20 76 6f 69 64 20 _TRIGGER. void
28620 73 71 6c 69 74 65 33 42 65 67 69 6e 54 72 69 67 sqlite3BeginTrig
28630 67 65 72 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 ger(Parse*, Toke
28640 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e n*,Token*,int,in
28650 74 2c 49 64 4c 69 73 74 2a 2c 53 72 63 4c 69 73 t,IdList*,SrcLis
28660 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 t*,.
28670 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 45 E
28680 78 70 72 2a 2c 69 6e 74 2c 20 69 6e 74 29 3b 0a xpr*,int, int);.
28690 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 69 void sqlite3Fi
286a0 6e 69 73 68 54 72 69 67 67 65 72 28 50 61 72 73 nishTrigger(Pars
286b0 65 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 2a e*, TriggerStep*
286c0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 20 20 76 6f 69 , Token*);. voi
286d0 64 20 73 71 6c 69 74 65 33 44 72 6f 70 54 72 69 d sqlite3DropTri
286e0 67 67 65 72 28 50 61 72 73 65 2a 2c 20 53 72 63 gger(Parse*, Src
286f0 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 List*, int);. v
28700 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 54 oid sqlite3DropT
28710 72 69 67 67 65 72 50 74 72 28 50 61 72 73 65 2a riggerPtr(Parse*
28720 2c 20 54 72 69 67 67 65 72 2a 29 3b 0a 20 20 54 , Trigger*);. T
28730 72 69 67 67 65 72 20 2a 73 71 6c 69 74 65 33 54 rigger *sqlite3T
28740 72 69 67 67 65 72 73 45 78 69 73 74 28 50 61 72 riggersExist(Par
28750 73 65 20 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e se *, Table*, in
28760 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e t, ExprList*, in
28770 74 20 2a 70 4d 61 73 6b 29 3b 0a 20 20 54 72 69 t *pMask);. Tri
28780 67 67 65 72 20 2a 73 71 6c 69 74 65 33 54 72 69 gger *sqlite3Tri
28790 67 67 65 72 4c 69 73 74 28 50 61 72 73 65 20 2a ggerList(Parse *
287a0 2c 20 54 61 62 6c 65 20 2a 29 3b 0a 20 20 76 6f , Table *);. vo
287b0 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f id sqlite3CodeRo
287c0 77 54 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c wTrigger(Parse*,
287d0 20 54 72 69 67 67 65 72 20 2a 2c 20 69 6e 74 2c Trigger *, int,
287e0 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c ExprList*, int,
287f0 20 54 61 62 6c 65 20 2a 2c 0a 20 20 20 20 20 20 Table *,.
28800 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28810 20 20 20 20 20 20 69 6e 74 2c 20 69 6e 74 2c 20 int, int,
28820 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c int);. void sql
28830 69 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 ite3CodeRowTrigg
28840 65 72 44 69 72 65 63 74 28 50 61 72 73 65 20 2a erDirect(Parse *
28850 2c 20 54 72 69 67 67 65 72 20 2a 2c 20 54 61 62 , Trigger *, Tab
28860 6c 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 le *, int, int,
28870 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c int);. void sql
28880 69 74 65 56 69 65 77 54 72 69 67 67 65 72 73 28 iteViewTriggers(
28890 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 Parse*, Table*,
288a0 45 78 70 72 2a 2c 20 69 6e 74 2c 20 45 78 70 72 Expr*, int, Expr
288b0 4c 69 73 74 2a 29 3b 0a 20 20 76 6f 69 64 20 73 List*);. void s
288c0 71 6c 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 qlite3DeleteTrig
288d0 67 65 72 53 74 65 70 28 73 71 6c 69 74 65 33 2a gerStep(sqlite3*
288e0 2c 20 54 72 69 67 67 65 72 53 74 65 70 2a 29 3b , TriggerStep*);
288f0 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a . TriggerStep *
28900 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 53 65 sqlite3TriggerSe
28910 6c 65 63 74 53 74 65 70 28 73 71 6c 69 74 65 33 lectStep(sqlite3
28920 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a 20 20 54 72 *,Select*);. Tr
28930 69 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 74 iggerStep *sqlit
28940 65 33 54 72 69 67 67 65 72 49 6e 73 65 72 74 53 e3TriggerInsertS
28950 74 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 6f 6b tep(sqlite3*,Tok
28960 65 6e 2a 2c 20 49 64 4c 69 73 74 2a 2c 0a 20 20 en*, IdList*,.
28970 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28980 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
28990 20 20 20 20 20 20 53 65 6c 65 63 74 2a 2c 75 38 Select*,u8
289a0 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 );. TriggerStep
289b0 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 *sqlite3Trigger
289c0 55 70 64 61 74 65 53 74 65 70 28 73 71 6c 69 74 UpdateStep(sqlit
289d0 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c e3*,Token*,ExprL
289e0 69 73 74 2a 2c 20 45 78 70 72 2a 2c 20 75 38 29 ist*, Expr*, u8)
289f0 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 ;. TriggerStep
28a00 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 44 *sqlite3TriggerD
28a10 65 6c 65 74 65 53 74 65 70 28 73 71 6c 69 74 65 eleteStep(sqlite
28a20 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 2a 3*,Token*, Expr*
28a30 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
28a40 33 44 65 6c 65 74 65 54 72 69 67 67 65 72 28 73 3DeleteTrigger(s
28a50 71 6c 69 74 65 33 2a 2c 20 54 72 69 67 67 65 72 qlite3*, Trigger
28a60 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
28a70 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 e3UnlinkAndDelet
28a80 65 54 72 69 67 67 65 72 28 73 71 6c 69 74 65 33 eTrigger(sqlite3
28a90 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 *,int,const char
28aa0 2a 29 3b 0a 20 20 75 33 32 20 73 71 6c 69 74 65 *);. u32 sqlite
28ab0 33 54 72 69 67 67 65 72 43 6f 6c 6d 61 73 6b 28 3TriggerColmask(
28ac0 50 61 72 73 65 2a 2c 54 72 69 67 67 65 72 2a 2c Parse*,Trigger*,
28ad0 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 69 6e ExprList*,int,in
28ae0 74 2c 54 61 62 6c 65 2a 2c 69 6e 74 29 3b 0a 23 t,Table*,int);.#
28af0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 50 define sqlite3P
28b00 61 72 73 65 54 6f 70 6c 65 76 65 6c 28 70 29 20 arseToplevel(p)
28b10 28 28 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 20 ((p)->pToplevel
28b20 3f 20 28 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c ? (p)->pToplevel
28b30 20 3a 20 28 70 29 29 0a 23 20 64 65 66 69 6e 65 : (p)).# define
28b40 20 73 71 6c 69 74 65 33 49 73 54 6f 70 6c 65 76 sqlite3IsToplev
28b50 65 6c 28 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 el(p) ((p)->pTop
28b60 6c 65 76 65 6c 3d 3d 30 29 0a 23 65 6c 73 65 0a level==0).#else.
28b70 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
28b80 54 72 69 67 67 65 72 73 45 78 69 73 74 28 42 2c TriggersExist(B,
28b90 43 2c 44 2c 45 2c 46 29 20 30 0a 23 20 64 65 66 C,D,E,F) 0.# def
28ba0 69 6e 65 20 73 71 6c 69 74 65 33 44 65 6c 65 74 ine sqlite3Delet
28bb0 65 54 72 69 67 67 65 72 28 41 2c 42 29 0a 23 20 eTrigger(A,B).#
28bc0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 44 72 define sqlite3Dr
28bd0 6f 70 54 72 69 67 67 65 72 50 74 72 28 41 2c 42 opTriggerPtr(A,B
28be0 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
28bf0 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 e3UnlinkAndDelet
28c00 65 54 72 69 67 67 65 72 28 41 2c 42 2c 43 29 0a eTrigger(A,B,C).
28c10 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
28c20 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 28 41 CodeRowTrigger(A
28c30 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 2c 48 2c 49 ,B,C,D,E,F,G,H,I
28c40 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
28c50 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 e3CodeRowTrigger
28c60 44 69 72 65 63 74 28 41 2c 42 2c 43 2c 44 2c 45 Direct(A,B,C,D,E
28c70 2c 46 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ,F).# define sql
28c80 69 74 65 33 54 72 69 67 67 65 72 4c 69 73 74 28 ite3TriggerList(
28c90 58 2c 20 59 29 20 30 0a 23 20 64 65 66 69 6e 65 X, Y) 0.# define
28ca0 20 73 71 6c 69 74 65 33 50 61 72 73 65 54 6f 70 sqlite3ParseTop
28cb0 6c 65 76 65 6c 28 70 29 20 70 0a 23 20 64 65 66 level(p) p.# def
28cc0 69 6e 65 20 73 71 6c 69 74 65 33 49 73 54 6f 70 ine sqlite3IsTop
28cd0 6c 65 76 65 6c 28 70 29 20 31 0a 23 20 64 65 66 level(p) 1.# def
28ce0 69 6e 65 20 73 71 6c 69 74 65 33 54 72 69 67 67 ine sqlite3Trigg
28cf0 65 72 43 6f 6c 6d 61 73 6b 28 41 2c 42 2c 43 2c erColmask(A,B,C,
28d00 44 2c 45 2c 46 2c 47 29 20 30 0a 23 65 6e 64 69 D,E,F,G) 0.#endi
28d10 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f f..int sqlite3Jo
28d20 69 6e 54 79 70 65 28 50 61 72 73 65 2a 2c 20 54 inType(Parse*, T
28d30 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 oken*, Token*, T
28d40 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
28d50 69 74 65 33 43 72 65 61 74 65 46 6f 72 65 69 67 ite3CreateForeig
28d60 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 70 nKey(Parse*, Exp
28d70 72 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 rList*, Token*,
28d80 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 29 3b ExprList*, int);
28d90 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 66 .void sqlite3Def
28da0 65 72 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 72 erForeignKey(Par
28db0 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 6e 64 se*, int);.#ifnd
28dc0 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 ef SQLITE_OMIT_A
28dd0 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 76 UTHORIZATION. v
28de0 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 68 52 oid sqlite3AuthR
28df0 65 61 64 28 50 61 72 73 65 2a 2c 45 78 70 72 2a ead(Parse*,Expr*
28e00 2c 53 63 68 65 6d 61 2a 2c 53 72 63 4c 69 73 74 ,Schema*,SrcList
28e10 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 *);. int sqlite
28e20 33 41 75 74 68 43 68 65 63 6b 28 50 61 72 73 65 3AuthCheck(Parse
28e30 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 *,int, const cha
28e40 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c r*, const char*,
28e50 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 const char*);.
28e60 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 void sqlite3Aut
28e70 68 43 6f 6e 74 65 78 74 50 75 73 68 28 50 61 72 hContextPush(Par
28e80 73 65 2a 2c 20 41 75 74 68 43 6f 6e 74 65 78 74 se*, AuthContext
28e90 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
28ea0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 . void sqlite3A
28eb0 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 41 75 uthContextPop(Au
28ec0 74 68 43 6f 6e 74 65 78 74 2a 29 3b 0a 20 20 69 thContext*);. i
28ed0 6e 74 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 nt sqlite3AuthRe
28ee0 61 64 43 6f 6c 28 50 61 72 73 65 2a 2c 20 63 6f adCol(Parse*, co
28ef0 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 6f 6e 73 nst char *, cons
28f00 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 29 3b 0a t char *, int);.
28f10 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
28f20 71 6c 69 74 65 33 41 75 74 68 52 65 61 64 28 61 qlite3AuthRead(a
28f30 2c 62 2c 63 2c 64 29 0a 23 20 64 65 66 69 6e 65 ,b,c,d).# define
28f40 20 73 71 6c 69 74 65 33 41 75 74 68 43 68 65 63 sqlite3AuthChec
28f50 6b 28 61 2c 62 2c 63 2c 64 2c 65 29 20 20 20 20 k(a,b,c,d,e)
28f60 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 64 65 66 69 SQLITE_OK.# defi
28f70 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f ne sqlite3AuthCo
28f80 6e 74 65 78 74 50 75 73 68 28 61 2c 62 2c 63 29 ntextPush(a,b,c)
28f90 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
28fa0 33 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 28 3AuthContextPop(
28fb0 61 29 20 20 28 28 76 6f 69 64 29 28 61 29 29 0a a) ((void)(a)).
28fc0 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
28fd0 74 65 33 41 74 74 61 63 68 28 50 61 72 73 65 2a te3Attach(Parse*
28fe0 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 , Expr*, Expr*,
28ff0 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
29000 69 74 65 33 44 65 74 61 63 68 28 50 61 72 73 65 ite3Detach(Parse
29010 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 *, Expr*);.void
29020 73 71 6c 69 74 65 33 46 69 78 49 6e 69 74 28 44 sqlite3FixInit(D
29030 62 46 69 78 65 72 2a 2c 20 50 61 72 73 65 2a 2c bFixer*, Parse*,
29040 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 int, const char
29050 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 29 *, const Token*)
29060 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 ;.int sqlite3Fix
29070 53 72 63 4c 69 73 74 28 44 62 46 69 78 65 72 2a SrcList(DbFixer*
29080 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 , SrcList*);.int
29090 20 73 71 6c 69 74 65 33 46 69 78 53 65 6c 65 63 sqlite3FixSelec
290a0 74 28 44 62 46 69 78 65 72 2a 2c 20 53 65 6c 65 t(DbFixer*, Sele
290b0 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ct*);.int sqlite
290c0 33 46 69 78 45 78 70 72 28 44 62 46 69 78 65 72 3FixExpr(DbFixer
290d0 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 *, Expr*);.int s
290e0 71 6c 69 74 65 33 46 69 78 45 78 70 72 4c 69 73 qlite3FixExprLis
290f0 74 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 t(DbFixer*, Expr
29100 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 List*);.int sqli
29110 74 65 33 46 69 78 54 72 69 67 67 65 72 53 74 65 te3FixTriggerSte
29120 70 28 44 62 46 69 78 65 72 2a 2c 20 54 72 69 67 p(DbFixer*, Trig
29130 67 65 72 53 74 65 70 2a 29 3b 0a 69 6e 74 20 73 gerStep*);.int s
29140 71 6c 69 74 65 33 41 74 6f 46 28 63 6f 6e 73 74 qlite3AtoF(const
29150 20 63 68 61 72 20 2a 7a 2c 20 64 6f 75 62 6c 65 char *z, double
29160 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 *, int, u8);.int
29170 20 73 71 6c 69 74 65 33 47 65 74 49 6e 74 33 32 sqlite3GetInt32
29180 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 (const char *, i
29190 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 nt*);.int sqlite
291a0 33 41 74 6f 69 28 63 6f 6e 73 74 20 63 68 61 72 3Atoi(const char
291b0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 *);.int sqlite3U
291c0 74 66 31 36 42 79 74 65 4c 65 6e 28 63 6f 6e 73 tf16ByteLen(cons
291d0 74 20 76 6f 69 64 20 2a 70 44 61 74 61 2c 20 69 t void *pData, i
291e0 6e 74 20 6e 43 68 61 72 29 3b 0a 69 6e 74 20 73 nt nChar);.int s
291f0 71 6c 69 74 65 33 55 74 66 38 43 68 61 72 4c 65 qlite3Utf8CharLe
29200 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 44 n(const char *pD
29210 61 74 61 2c 20 69 6e 74 20 6e 42 79 74 65 29 3b ata, int nByte);
29220 0a 75 33 32 20 73 71 6c 69 74 65 33 55 74 66 38 .u32 sqlite3Utf8
29230 52 65 61 64 28 63 6f 6e 73 74 20 75 38 2a 2a 29 Read(const u8**)
29240 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 33 ;.LogEst sqlite3
29250 4c 6f 67 45 73 74 28 75 36 34 29 3b 0a 4c 6f 67 LogEst(u64);.Log
29260 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 Est sqlite3LogEs
29270 74 41 64 64 28 4c 6f 67 45 73 74 2c 4c 6f 67 45 tAdd(LogEst,LogE
29280 73 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c st);.#ifndef SQL
29290 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
292a0 54 41 42 4c 45 0a 4c 6f 67 45 73 74 20 73 71 6c TABLE.LogEst sql
292b0 69 74 65 33 4c 6f 67 45 73 74 46 72 6f 6d 44 6f ite3LogEstFromDo
292c0 75 62 6c 65 28 64 6f 75 62 6c 65 29 3b 0a 23 65 uble(double);.#e
292d0 6e 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 ndif.#if defined
292e0 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 (SQLITE_ENABLE_S
292f0 54 4d 54 5f 53 43 41 4e 53 54 41 54 55 53 29 20 TMT_SCANSTATUS)
29300 7c 7c 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 || \. defined
29310 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 (SQLITE_ENABLE_S
29320 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 29 20 7c TAT3_OR_STAT4) |
29330 7c 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 | \. defined(
29340 53 51 4c 49 54 45 5f 45 58 50 4c 41 49 4e 5f 45 SQLITE_EXPLAIN_E
29350 53 54 49 4d 41 54 45 44 5f 52 4f 57 53 29 0a 75 STIMATED_ROWS).u
29360 36 34 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 64 sqlite3LogEst
29370 54 6f 49 6e 74 28 4c 6f 67 45 73 74 29 3b 0a 23 ToInt(LogEst);.#
29380 65 6e 64 69 66 0a 56 4c 69 73 74 20 2a 73 71 6c endif.VList *sql
29390 69 74 65 33 56 4c 69 73 74 41 64 64 28 73 71 6c ite3VListAdd(sql
293a0 69 74 65 33 2a 2c 56 4c 69 73 74 2a 2c 63 6f 6e ite3*,VList*,con
293b0 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c 69 6e 74 st char*,int,int
293c0 29 3b 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 );.const char *s
293d0 71 6c 69 74 65 33 56 4c 69 73 74 4e 75 6d 54 6f qlite3VListNumTo
293e0 4e 61 6d 65 28 56 4c 69 73 74 2a 2c 69 6e 74 29 Name(VList*,int)
293f0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 4c 69 ;.int sqlite3VLi
29400 73 74 4e 61 6d 65 54 6f 4e 75 6d 28 56 4c 69 73 stNameToNum(VLis
29410 74 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 t*,const char*,i
29420 6e 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 74 nt);../*.** Rout
29430 69 6e 65 73 20 74 6f 20 72 65 61 64 20 61 6e 64 ines to read and
29440 20 77 72 69 74 65 20 76 61 72 69 61 62 6c 65 2d write variable-
29450 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 72 73 2e length integers.
29460 20 20 54 68 65 73 65 20 75 73 65 64 20 74 6f 0a These used to.
29470 2a 2a 20 62 65 20 64 65 66 69 6e 65 64 20 6c 6f ** be defined lo
29480 63 61 6c 6c 79 2c 20 62 75 74 20 6e 6f 77 20 77 cally, but now w
29490 65 20 75 73 65 20 74 68 65 20 76 61 72 69 6e 74 e use the varint
294a0 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 74 68 65 routines in the
294b0 20 75 74 69 6c 2e 63 0a 2a 2a 20 66 69 6c 65 2e util.c.** file.
294c0 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 .*/.int sqlite3P
294d0 75 74 56 61 72 69 6e 74 28 75 6e 73 69 67 6e 65 utVarint(unsigne
294e0 64 20 63 68 61 72 2a 2c 20 75 36 34 29 3b 0a 75 d char*, u64);.u
294f0 38 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 69 8 sqlite3GetVari
29500 6e 74 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 nt(const unsigne
29510 64 20 63 68 61 72 20 2a 2c 20 75 36 34 20 2a 29 d char *, u64 *)
29520 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 56 ;.u8 sqlite3GetV
29530 61 72 69 6e 74 33 32 28 63 6f 6e 73 74 20 75 6e arint32(const un
29540 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 75 signed char *, u
29550 33 32 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 32 *);.int sqlit
29560 65 33 56 61 72 69 6e 74 4c 65 6e 28 75 36 34 20 e3VarintLen(u64
29570 76 29 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 v);../*.** The c
29580 6f 6d 6d 6f 6e 20 63 61 73 65 20 69 73 20 66 6f ommon case is fo
29590 72 20 61 20 76 61 72 69 6e 74 20 74 6f 20 62 65 r a varint to be
295a0 20 61 20 73 69 6e 67 6c 65 20 62 79 74 65 2e 20 a single byte.
295b0 20 54 68 65 79 20 66 6f 6c 6c 6f 77 69 6e 67 0a They following.
295c0 2a 2a 20 6d 61 63 72 6f 73 20 68 61 6e 64 6c 65 ** macros handle
295d0 20 74 68 65 20 63 6f 6d 6d 6f 6e 20 63 61 73 65 the common case
295e0 20 77 69 74 68 6f 75 74 20 61 20 70 72 6f 63 65 without a proce
295f0 64 75 72 65 20 63 61 6c 6c 2c 20 62 75 74 20 74 dure call, but t
29600 68 65 6e 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 hen call.** the
29610 70 72 6f 63 65 64 75 72 65 20 66 6f 72 20 6c 61 procedure for la
29620 72 67 65 72 20 76 61 72 69 6e 74 73 2e 0a 2a 2f rger varints..*/
29630 0a 23 64 65 66 69 6e 65 20 67 65 74 56 61 72 69 .#define getVari
29640 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a 20 20 28 nt32(A,B) \. (
29650 75 38 29 28 28 2a 28 41 29 3c 28 75 38 29 30 78 u8)((*(A)<(u8)0x
29660 38 30 29 3f 28 28 42 29 3d 28 75 33 32 29 2a 28 80)?((B)=(u32)*(
29670 41 29 29 2c 31 3a 73 71 6c 69 74 65 33 47 65 74 A)),1:sqlite3Get
29680 56 61 72 69 6e 74 33 32 28 28 41 29 2c 28 75 33 Varint32((A),(u3
29690 32 20 2a 29 26 28 42 29 29 29 0a 23 64 65 66 69 2 *)&(B))).#defi
296a0 6e 65 20 70 75 74 56 61 72 69 6e 74 33 32 28 41 ne putVarint32(A
296b0 2c 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 28 ,B) \. (u8)(((
296c0 75 33 32 29 28 42 29 3c 28 75 33 32 29 30 78 38 u32)(B)<(u32)0x8
296d0 30 29 3f 28 2a 28 41 29 3d 28 75 6e 73 69 67 6e 0)?(*(A)=(unsign
296e0 65 64 20 63 68 61 72 29 28 42 29 29 2c 31 3a 5c ed char)(B)),1:\
296f0 0a 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 . sqlite3PutVar
29700 69 6e 74 28 28 41 29 2c 28 42 29 29 29 0a 23 64 int((A),(B))).#d
29710 65 66 69 6e 65 20 67 65 74 56 61 72 69 6e 74 20 efine getVarint
29720 20 20 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 sqlite3GetVar
29730 69 6e 74 0a 23 64 65 66 69 6e 65 20 70 75 74 56 int.#define putV
29740 61 72 69 6e 74 20 20 20 20 73 71 6c 69 74 65 33 arint sqlite3
29750 50 75 74 56 61 72 69 6e 74 0a 0a 0a 63 6f 6e 73 PutVarint...cons
29760 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 49 t char *sqlite3I
29770 6e 64 65 78 41 66 66 69 6e 69 74 79 53 74 72 28 ndexAffinityStr(
29780 73 71 6c 69 74 65 33 2a 2c 20 49 6e 64 65 78 2a sqlite3*, Index*
29790 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 54 );.void sqlite3T
297a0 61 62 6c 65 41 66 66 69 6e 69 74 79 28 56 64 62 ableAffinity(Vdb
297b0 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 29 e*, Table*, int)
297c0 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 43 6f ;.char sqlite3Co
297d0 6d 70 61 72 65 41 66 66 69 6e 69 74 79 28 45 78 mpareAffinity(Ex
297e0 70 72 20 2a 70 45 78 70 72 2c 20 63 68 61 72 20 pr *pExpr, char
297f0 61 66 66 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 aff2);.int sqlit
29800 65 33 49 6e 64 65 78 41 66 66 69 6e 69 74 79 4f e3IndexAffinityO
29810 6b 28 45 78 70 72 20 2a 70 45 78 70 72 2c 20 63 k(Expr *pExpr, c
29820 68 61 72 20 69 64 78 5f 61 66 66 69 6e 69 74 79 har idx_affinity
29830 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 54 );.char sqlite3T
29840 61 62 6c 65 43 6f 6c 75 6d 6e 41 66 66 69 6e 69 ableColumnAffini
29850 74 79 28 54 61 62 6c 65 2a 2c 69 6e 74 29 3b 0a ty(Table*,int);.
29860 63 68 61 72 20 73 71 6c 69 74 65 33 45 78 70 72 char sqlite3Expr
29870 41 66 66 69 6e 69 74 79 28 45 78 70 72 20 2a 70 Affinity(Expr *p
29880 45 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 Expr);.int sqlit
29890 65 33 41 74 6f 69 36 34 28 63 6f 6e 73 74 20 63 e3Atoi64(const c
298a0 68 61 72 2a 2c 20 69 36 34 2a 2c 20 69 6e 74 2c har*, i64*, int,
298b0 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u8);.int sqlite
298c0 33 44 65 63 4f 72 48 65 78 54 6f 49 36 34 28 63 3DecOrHexToI64(c
298d0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a onst char*, i64*
298e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
298f0 72 72 6f 72 57 69 74 68 4d 73 67 28 73 71 6c 69 rrorWithMsg(sqli
29900 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 te3*, int, const
29910 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 76 6f 69 char*,...);.voi
29920 64 20 73 71 6c 69 74 65 33 45 72 72 6f 72 28 73 d sqlite3Error(s
29930 71 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f qlite3*,int);.vo
29940 69 64 20 73 71 6c 69 74 65 33 53 79 73 74 65 6d id sqlite3System
29950 45 72 72 6f 72 28 73 71 6c 69 74 65 33 2a 2c 69 Error(sqlite3*,i
29960 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 nt);.void *sqlit
29970 65 33 48 65 78 54 6f 42 6c 6f 62 28 73 71 6c 69 e3HexToBlob(sqli
29980 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 te3*, const char
29990 20 2a 7a 2c 20 69 6e 74 20 6e 29 3b 0a 75 38 20 *z, int n);.u8
299a0 73 71 6c 69 74 65 33 48 65 78 54 6f 49 6e 74 28 sqlite3HexToInt(
299b0 69 6e 74 20 68 29 3b 0a 69 6e 74 20 73 71 6c 69 int h);.int sqli
299c0 74 65 33 54 77 6f 50 61 72 74 4e 61 6d 65 28 50 te3TwoPartName(P
299d0 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c arse *, Token *,
299e0 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 Token *, Token
299f0 2a 2a 29 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 **);..#if define
29a00 64 28 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 52 d(SQLITE_NEED_ER
29a10 52 5f 4e 41 4d 45 29 0a 63 6f 6e 73 74 20 63 68 R_NAME).const ch
29a20 61 72 20 2a 73 71 6c 69 74 65 33 45 72 72 4e 61 ar *sqlite3ErrNa
29a30 6d 65 28 69 6e 74 29 3b 0a 23 65 6e 64 69 66 0a me(int);.#endif.
29a40 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c .const char *sql
29a50 69 74 65 33 45 72 72 53 74 72 28 69 6e 74 29 3b ite3ErrStr(int);
29a60 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 61 64 .int sqlite3Read
29a70 53 63 68 65 6d 61 28 50 61 72 73 65 20 2a 70 50 Schema(Parse *pP
29a80 61 72 73 65 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a arse);.CollSeq *
29a90 73 71 6c 69 74 65 33 46 69 6e 64 43 6f 6c 6c 53 sqlite3FindCollS
29aa0 65 71 28 73 71 6c 69 74 65 33 2a 2c 75 38 20 65 eq(sqlite3*,u8 e
29ab0 6e 63 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c nc, const char*,
29ac0 69 6e 74 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 int);.CollSeq *s
29ad0 71 6c 69 74 65 33 4c 6f 63 61 74 65 43 6f 6c 6c qlite3LocateColl
29ae0 53 65 71 28 50 61 72 73 65 20 2a 70 50 61 72 73 Seq(Parse *pPars
29af0 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 7a 4e e, const char*zN
29b00 61 6d 65 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 ame);.CollSeq *s
29b10 71 6c 69 74 65 33 45 78 70 72 43 6f 6c 6c 53 65 qlite3ExprCollSe
29b20 71 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c q(Parse *pParse,
29b30 20 45 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 45 Expr *pExpr);.E
29b40 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 xpr *sqlite3Expr
29b50 41 64 64 43 6f 6c 6c 61 74 65 54 6f 6b 65 6e 28 AddCollateToken(
29b60 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 45 Parse *pParse, E
29b70 78 70 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 xpr*, const Toke
29b80 6e 2a 2c 20 69 6e 74 29 3b 0a 45 78 70 72 20 2a n*, int);.Expr *
29b90 73 71 6c 69 74 65 33 45 78 70 72 41 64 64 43 6f sqlite3ExprAddCo
29ba0 6c 6c 61 74 65 53 74 72 69 6e 67 28 50 61 72 73 llateString(Pars
29bb0 65 2a 2c 45 78 70 72 2a 2c 63 6f 6e 73 74 20 63 e*,Expr*,const c
29bc0 68 61 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c har*);.Expr *sql
29bd0 69 74 65 33 45 78 70 72 53 6b 69 70 43 6f 6c 6c ite3ExprSkipColl
29be0 61 74 65 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 ate(Expr*);.int
29bf0 73 71 6c 69 74 65 33 43 68 65 63 6b 43 6f 6c 6c sqlite3CheckColl
29c00 53 65 71 28 50 61 72 73 65 20 2a 2c 20 43 6f 6c Seq(Parse *, Col
29c10 6c 53 65 71 20 2a 29 3b 0a 69 6e 74 20 73 71 6c lSeq *);.int sql
29c20 69 74 65 33 43 68 65 63 6b 4f 62 6a 65 63 74 4e ite3CheckObjectN
29c30 61 6d 65 28 50 61 72 73 65 20 2a 2c 20 63 6f 6e ame(Parse *, con
29c40 73 74 20 63 68 61 72 20 2a 29 3b 0a 76 6f 69 64 st char *);.void
29c50 20 73 71 6c 69 74 65 33 56 64 62 65 53 65 74 43 sqlite3VdbeSetC
29c60 68 61 6e 67 65 73 28 73 71 6c 69 74 65 33 20 2a hanges(sqlite3 *
29c70 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
29c80 74 65 33 41 64 64 49 6e 74 36 34 28 69 36 34 2a te3AddInt64(i64*
29c90 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ,i64);.int sqlit
29ca0 65 33 53 75 62 49 6e 74 36 34 28 69 36 34 2a 2c e3SubInt64(i64*,
29cb0 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 i64);.int sqlite
29cc0 33 4d 75 6c 49 6e 74 36 34 28 69 36 34 2a 2c 69 3MulInt64(i64*,i
29cd0 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 64);.int sqlite3
29ce0 41 62 73 49 6e 74 33 32 28 69 6e 74 29 3b 0a 23 AbsInt32(int);.#
29cf0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
29d00 42 4c 45 5f 38 5f 33 5f 4e 41 4d 45 53 0a 76 6f BLE_8_3_NAMES.vo
29d10 69 64 20 73 71 6c 69 74 65 33 46 69 6c 65 53 75 id sqlite3FileSu
29d20 66 66 69 78 33 28 63 6f 6e 73 74 20 63 68 61 72 ffix3(const char
29d30 2a 2c 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 65 *, char*);.#else
29d40 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
29d50 33 46 69 6c 65 53 75 66 66 69 78 33 28 58 2c 59 3FileSuffix3(X,Y
29d60 29 0a 23 65 6e 64 69 66 0a 75 38 20 73 71 6c 69 ).#endif.u8 sqli
29d70 74 65 33 47 65 74 42 6f 6f 6c 65 61 6e 28 63 6f te3GetBoolean(co
29d80 6e 73 74 20 63 68 61 72 20 2a 7a 2c 75 38 29 3b nst char *z,u8);
29d90 0a 0a 63 6f 6e 73 74 20 76 6f 69 64 20 2a 73 71 ..const void *sq
29da0 6c 69 74 65 33 56 61 6c 75 65 54 65 78 74 28 73 lite3ValueText(s
29db0 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 qlite3_value*, u
29dc0 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 8);.int sqlite3V
29dd0 61 6c 75 65 42 79 74 65 73 28 73 71 6c 69 74 65 alueBytes(sqlite
29de0 33 5f 76 61 6c 75 65 2a 2c 20 75 38 29 3b 0a 76 3_value*, u8);.v
29df0 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 65 oid sqlite3Value
29e00 53 65 74 53 74 72 28 73 71 6c 69 74 65 33 5f 76 SetStr(sqlite3_v
29e10 61 6c 75 65 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 alue*, int, cons
29e20 74 20 76 6f 69 64 20 2a 2c 75 38 2c 0a 20 20 20 t void *,u8,.
29e30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
29e40 20 20 20 20 20 76 6f 69 64 28 2a 29 28 76 6f 69 void(*)(voi
29e50 64 2a 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 d*));.void sqlit
29e60 65 33 56 61 6c 75 65 53 65 74 4e 75 6c 6c 28 73 e3ValueSetNull(s
29e70 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 29 3b 0a qlite3_value*);.
29e80 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 void sqlite3Valu
29e90 65 46 72 65 65 28 73 71 6c 69 74 65 33 5f 76 61 eFree(sqlite3_va
29ea0 6c 75 65 2a 29 3b 0a 73 71 6c 69 74 65 33 5f 76 lue*);.sqlite3_v
29eb0 61 6c 75 65 20 2a 73 71 6c 69 74 65 33 56 61 6c alue *sqlite3Val
29ec0 75 65 4e 65 77 28 73 71 6c 69 74 65 33 20 2a 29 ueNew(sqlite3 *)
29ed0 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 55 ;.char *sqlite3U
29ee0 74 66 31 36 74 6f 38 28 73 71 6c 69 74 65 33 20 tf16to8(sqlite3
29ef0 2a 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 *, const void*,
29f00 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 int, u8);.int sq
29f10 6c 69 74 65 33 56 61 6c 75 65 46 72 6f 6d 45 78 lite3ValueFromEx
29f20 70 72 28 73 71 6c 69 74 65 33 20 2a 2c 20 45 78 pr(sqlite3 *, Ex
29f30 70 72 20 2a 2c 20 75 38 2c 20 75 38 2c 20 73 71 pr *, u8, u8, sq
29f40 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 2a 29 3b lite3_value **);
29f50 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c .void sqlite3Val
29f60 75 65 41 70 70 6c 79 41 66 66 69 6e 69 74 79 28 ueApplyAffinity(
29f70 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 2c sqlite3_value *,
29f80 20 75 38 2c 20 75 38 29 3b 0a 23 69 66 6e 64 65 u8, u8);.#ifnde
29f90 66 20 53 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d f SQLITE_AMALGAM
29fa0 41 54 49 4f 4e 0a 65 78 74 65 72 6e 20 63 6f 6e ATION.extern con
29fb0 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 st unsigned char
29fc0 20 73 71 6c 69 74 65 33 4f 70 63 6f 64 65 50 72 sqlite3OpcodePr
29fd0 6f 70 65 72 74 79 5b 5d 3b 0a 65 78 74 65 72 6e operty[];.extern
29fe0 20 63 6f 6e 73 74 20 63 68 61 72 20 73 71 6c 69 const char sqli
29ff0 74 65 33 53 74 72 42 49 4e 41 52 59 5b 5d 3b 0a te3StrBINARY[];.
2a000 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 extern const uns
2a010 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 igned char sqlit
2a020 65 33 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b 5d e3UpperToLower[]
2a030 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 ;.extern const u
2a040 6e 73 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c nsigned char sql
2a050 69 74 65 33 43 74 79 70 65 4d 61 70 5b 5d 3b 0a ite3CtypeMap[];.
2a060 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 54 6f 6b extern const Tok
2a070 65 6e 20 73 71 6c 69 74 65 33 49 6e 74 54 6f 6b en sqlite3IntTok
2a080 65 6e 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 51 ens[];.extern SQ
2a090 4c 49 54 45 5f 57 53 44 20 73 74 72 75 63 74 20 LITE_WSD struct
2a0a0 53 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 73 71 Sqlite3Config sq
2a0b0 6c 69 74 65 33 43 6f 6e 66 69 67 3b 0a 65 78 74 lite3Config;.ext
2a0c0 65 72 6e 20 46 75 6e 63 44 65 66 48 61 73 68 20 ern FuncDefHash
2a0d0 73 71 6c 69 74 65 33 42 75 69 6c 74 69 6e 46 75 sqlite3BuiltinFu
2a0e0 6e 63 74 69 6f 6e 73 3b 0a 23 69 66 6e 64 65 66 nctions;.#ifndef
2a0f0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 SQLITE_OMIT_WSD
2a100 0a 65 78 74 65 72 6e 20 69 6e 74 20 73 71 6c 69 .extern int sqli
2a110 74 65 33 50 65 6e 64 69 6e 67 42 79 74 65 3b 0a te3PendingByte;.
2a120 23 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 76 6f #endif.#endif.vo
2a130 69 64 20 73 71 6c 69 74 65 33 52 6f 6f 74 50 61 id sqlite3RootPa
2a140 67 65 4d 6f 76 65 64 28 73 71 6c 69 74 65 33 2a geMoved(sqlite3*
2a150 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
2a160 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 ;.void sqlite3Re
2a170 69 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 54 6f index(Parse*, To
2a180 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 ken*, Token*);.v
2a190 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 65 72 oid sqlite3Alter
2a1a0 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
2a1b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 .void sqlite3Alt
2a1c0 65 72 52 65 6e 61 6d 65 54 61 62 6c 65 28 50 61 erRenameTable(Pa
2a1d0 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 rse*, SrcList*,
2a1e0 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
2a1f0 69 74 65 33 47 65 74 54 6f 6b 65 6e 28 63 6f 6e ite3GetToken(con
2a200 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 st unsigned char
2a210 20 2a 2c 20 69 6e 74 20 2a 29 3b 0a 76 6f 69 64 *, int *);.void
2a220 20 73 71 6c 69 74 65 33 4e 65 73 74 65 64 50 61 sqlite3NestedPa
2a230 72 73 65 28 50 61 72 73 65 2a 2c 20 63 6f 6e 73 rse(Parse*, cons
2a240 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 76 t char*, ...);.v
2a250 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 69 72 oid sqlite3Expir
2a260 65 50 72 65 70 61 72 65 64 53 74 61 74 65 6d 65 ePreparedStateme
2a270 6e 74 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 nts(sqlite3*);.i
2a280 6e 74 20 73 71 6c 69 74 65 33 43 6f 64 65 53 75 nt sqlite3CodeSu
2a290 62 73 65 6c 65 63 74 28 50 61 72 73 65 2a 2c 20 bselect(Parse*,
2a2a0 45 78 70 72 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 Expr *, int, int
2a2b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
2a2c0 65 6c 65 63 74 50 72 65 70 28 50 61 72 73 65 2a electPrep(Parse*
2a2d0 2c 20 53 65 6c 65 63 74 2a 2c 20 4e 61 6d 65 43 , Select*, NameC
2a2e0 6f 6e 74 65 78 74 2a 29 3b 0a 76 6f 69 64 20 73 ontext*);.void s
2a2f0 71 6c 69 74 65 33 53 65 6c 65 63 74 57 72 6f 6e qlite3SelectWron
2a300 67 4e 75 6d 54 65 72 6d 73 45 72 72 6f 72 28 50 gNumTermsError(P
2a310 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 53 65 arse *pParse, Se
2a320 6c 65 63 74 20 2a 70 29 3b 0a 69 6e 74 20 73 71 lect *p);.int sq
2a330 6c 69 74 65 33 4d 61 74 63 68 53 70 61 6e 4e 61 lite3MatchSpanNa
2a340 6d 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 me(const char*,
2a350 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e const char*, con
2a360 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 st char*, const
2a370 63 68 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 char*);.int sqli
2a380 74 65 33 52 65 73 6f 6c 76 65 45 78 70 72 4e 61 te3ResolveExprNa
2a390 6d 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a mes(NameContext*
2a3a0 2c 20 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 71 , Expr*);.int sq
2a3b0 6c 69 74 65 33 52 65 73 6f 6c 76 65 45 78 70 72 lite3ResolveExpr
2a3c0 4c 69 73 74 4e 61 6d 65 73 28 4e 61 6d 65 43 6f ListNames(NameCo
2a3d0 6e 74 65 78 74 2a 2c 20 45 78 70 72 4c 69 73 74 ntext*, ExprList
2a3e0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2a3f0 52 65 73 6f 6c 76 65 53 65 6c 65 63 74 4e 61 6d ResolveSelectNam
2a400 65 73 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 es(Parse*, Selec
2a410 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a t*, NameContext*
2a420 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
2a430 65 73 6f 6c 76 65 53 65 6c 66 52 65 66 65 72 65 esolveSelfRefere
2a440 6e 63 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 nce(Parse*,Table
2a450 2a 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 78 70 72 *,int,Expr*,Expr
2a460 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 List*);.int sqli
2a470 74 65 33 52 65 73 6f 6c 76 65 4f 72 64 65 72 47 te3ResolveOrderG
2a480 72 6f 75 70 42 79 28 50 61 72 73 65 2a 2c 20 53 roupBy(Parse*, S
2a490 65 6c 65 63 74 2a 2c 20 45 78 70 72 4c 69 73 74 elect*, ExprList
2a4a0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
2a4b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6c .void sqlite3Col
2a4c0 75 6d 6e 44 65 66 61 75 6c 74 28 56 64 62 65 20 umnDefault(Vdbe
2a4d0 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c *, Table *, int,
2a4e0 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
2a4f0 74 65 33 41 6c 74 65 72 46 69 6e 69 73 68 41 64 te3AlterFinishAd
2a500 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 2a 2c dColumn(Parse *,
2a510 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 Token *);.void
2a520 73 71 6c 69 74 65 33 41 6c 74 65 72 42 65 67 69 sqlite3AlterBegi
2a530 6e 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 nAddColumn(Parse
2a540 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 29 3b 0a *, SrcList *);.
2a550 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 CollSeq *sqlite3
2a560 47 65 74 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 GetCollSeq(Parse
2a570 2a 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 71 20 2a *, u8, CollSeq *
2a580 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
2a590 63 68 61 72 20 73 71 6c 69 74 65 33 41 66 66 69 char sqlite3Affi
2a5a0 6e 69 74 79 54 79 70 65 28 63 6f 6e 73 74 20 63 nityType(const c
2a5b0 68 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 6f 69 64 har*, u8*);.void
2a5c0 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 28 sqlite3Analyze(
2a5d0 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Parse*, Token*,
2a5e0 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
2a5f0 69 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 48 61 ite3InvokeBusyHa
2a600 6e 64 6c 65 72 28 42 75 73 79 48 61 6e 64 6c 65 ndler(BusyHandle
2a610 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
2a620 46 69 6e 64 44 62 28 73 71 6c 69 74 65 33 2a 2c FindDb(sqlite3*,
2a630 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 Token*);.int sq
2a640 6c 69 74 65 33 46 69 6e 64 44 62 4e 61 6d 65 28 lite3FindDbName(
2a650 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 sqlite3 *, const
2a660 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 char *);.int sq
2a670 6c 69 74 65 33 41 6e 61 6c 79 73 69 73 4c 6f 61 lite3AnalysisLoa
2a680 64 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 69 d(sqlite3*,int i
2a690 44 42 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 DB);.void sqlite
2a6a0 33 44 65 6c 65 74 65 49 6e 64 65 78 53 61 6d 70 3DeleteIndexSamp
2a6b0 6c 65 73 28 73 71 6c 69 74 65 33 2a 2c 49 6e 64 les(sqlite3*,Ind
2a6c0 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ex*);.void sqlit
2a6d0 65 33 44 65 66 61 75 6c 74 52 6f 77 45 73 74 28 e3DefaultRowEst(
2a6e0 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 Index*);.void sq
2a6f0 6c 69 74 65 33 52 65 67 69 73 74 65 72 4c 69 6b lite3RegisterLik
2a700 65 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 eFunctions(sqlit
2a710 65 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 e3*, int);.int s
2a720 71 6c 69 74 65 33 49 73 4c 69 6b 65 46 75 6e 63 qlite3IsLikeFunc
2a730 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 45 78 tion(sqlite3*,Ex
2a740 70 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a 29 3b pr*,int*,char*);
2a750 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 68 .void sqlite3Sch
2a760 65 6d 61 43 6c 65 61 72 28 76 6f 69 64 20 2a 29 emaClear(void *)
2a770 3b 0a 53 63 68 65 6d 61 20 2a 73 71 6c 69 74 65 ;.Schema *sqlite
2a780 33 53 63 68 65 6d 61 47 65 74 28 73 71 6c 69 74 3SchemaGet(sqlit
2a790 65 33 20 2a 2c 20 42 74 72 65 65 20 2a 29 3b 0a e3 *, Btree *);.
2a7a0 69 6e 74 20 73 71 6c 69 74 65 33 53 63 68 65 6d int sqlite3Schem
2a7b0 61 54 6f 49 6e 64 65 78 28 73 71 6c 69 74 65 33 aToIndex(sqlite3
2a7c0 20 2a 64 62 2c 20 53 63 68 65 6d 61 20 2a 29 3b *db, Schema *);
2a7d0 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 .KeyInfo *sqlite
2a7e0 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f 63 28 73 71 3KeyInfoAlloc(sq
2a7f0 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 6e 74 29 3b lite3*,int,int);
2a800 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4b 65 79 .void sqlite3Key
2a810 49 6e 66 6f 55 6e 72 65 66 28 4b 65 79 49 6e 66 InfoUnref(KeyInf
2a820 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 o*);.KeyInfo *sq
2a830 6c 69 74 65 33 4b 65 79 49 6e 66 6f 52 65 66 28 lite3KeyInfoRef(
2a840 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e KeyInfo*);.KeyIn
2a850 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e fo *sqlite3KeyIn
2a860 66 6f 4f 66 49 6e 64 65 78 28 50 61 72 73 65 2a foOfIndex(Parse*
2a870 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 69 66 64 65 , Index*);.#ifde
2a880 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 69 f SQLITE_DEBUG.i
2a890 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 nt sqlite3KeyInf
2a8a0 6f 49 73 57 72 69 74 65 61 62 6c 65 28 4b 65 79 oIsWriteable(Key
2a8b0 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 66 0a 69 Info*);.#endif.i
2a8c0 6e 74 20 73 71 6c 69 74 65 33 43 72 65 61 74 65 nt sqlite3Create
2a8d0 46 75 6e 63 28 73 71 6c 69 74 65 33 20 2a 2c 20 Func(sqlite3 *,
2a8e0 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e const char *, in
2a8f0 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 2a 2c 0a t, int, void *,.
2a900 20 20 76 6f 69 64 20 28 2a 29 28 73 71 6c 69 74 void (*)(sqlit
2a910 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c e3_context*,int,
2a920 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 2a sqlite3_value **
2a930 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 71 ),. void (*)(sq
2a940 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 lite3_context*,i
2a950 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 nt,sqlite3_value
2a960 20 2a 2a 29 2c 20 76 6f 69 64 20 28 2a 29 28 73 **), void (*)(s
2a970 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 qlite3_context*)
2a980 2c 0a 20 20 46 75 6e 63 44 65 73 74 72 75 63 74 ,. FuncDestruct
2a990 6f 72 20 2a 70 44 65 73 74 72 75 63 74 6f 72 0a or *pDestructor.
2a9a0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f );.void sqlite3O
2a9b0 6f 6d 46 61 75 6c 74 28 73 71 6c 69 74 65 33 2a omFault(sqlite3*
2a9c0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f );.void sqlite3O
2a9d0 6f 6d 43 6c 65 61 72 28 73 71 6c 69 74 65 33 2a omClear(sqlite3*
2a9e0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 70 );.int sqlite3Ap
2a9f0 69 45 78 69 74 28 73 71 6c 69 74 65 33 20 2a 64 iExit(sqlite3 *d
2aa00 62 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c b, int);.int sql
2aa10 69 74 65 33 4f 70 65 6e 54 65 6d 70 44 61 74 61 ite3OpenTempData
2aa20 62 61 73 65 28 50 61 72 73 65 20 2a 29 3b 0a 0a base(Parse *);..
2aa30 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 41 void sqlite3StrA
2aa40 63 63 75 6d 49 6e 69 74 28 53 74 72 41 63 63 75 ccumInit(StrAccu
2aa50 6d 2a 2c 20 73 71 6c 69 74 65 33 2a 2c 20 63 68 m*, sqlite3*, ch
2aa60 61 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a ar*, int, int);.
2aa70 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 41 void sqlite3StrA
2aa80 63 63 75 6d 41 70 70 65 6e 64 28 53 74 72 41 63 ccumAppend(StrAc
2aa90 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a cum*,const char*
2aaa0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
2aab0 74 65 33 53 74 72 41 63 63 75 6d 41 70 70 65 6e te3StrAccumAppen
2aac0 64 41 6c 6c 28 53 74 72 41 63 63 75 6d 2a 2c 63 dAll(StrAccum*,c
2aad0 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 onst char*);.voi
2aae0 64 20 73 71 6c 69 74 65 33 41 70 70 65 6e 64 43 d sqlite3AppendC
2aaf0 68 61 72 28 53 74 72 41 63 63 75 6d 2a 2c 69 6e har(StrAccum*,in
2ab00 74 2c 63 68 61 72 29 3b 0a 63 68 61 72 20 2a 73 t,char);.char *s
2ab10 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d 46 69 qlite3StrAccumFi
2ab20 6e 69 73 68 28 53 74 72 41 63 63 75 6d 2a 29 3b nish(StrAccum*);
2ab30 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 .void sqlite3Str
2ab40 41 63 63 75 6d 52 65 73 65 74 28 53 74 72 41 63 AccumReset(StrAc
2ab50 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 cum*);.void sqli
2ab60 74 65 33 53 65 6c 65 63 74 44 65 73 74 49 6e 69 te3SelectDestIni
2ab70 74 28 53 65 6c 65 63 74 44 65 73 74 2a 2c 69 6e t(SelectDest*,in
2ab80 74 2c 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 71 t,int);.Expr *sq
2ab90 6c 69 74 65 33 43 72 65 61 74 65 43 6f 6c 75 6d lite3CreateColum
2aba0 6e 45 78 70 72 28 73 71 6c 69 74 65 33 20 2a 2c nExpr(sqlite3 *,
2abb0 20 53 72 63 4c 69 73 74 20 2a 2c 20 69 6e 74 2c SrcList *, int,
2abc0 20 69 6e 74 29 3b 0a 0a 76 6f 69 64 20 73 71 6c int);..void sql
2abd0 69 74 65 33 42 61 63 6b 75 70 52 65 73 74 61 72 ite3BackupRestar
2abe0 74 28 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 t(sqlite3_backup
2abf0 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
2ac00 33 42 61 63 6b 75 70 55 70 64 61 74 65 28 73 71 3BackupUpdate(sq
2ac10 6c 69 74 65 33 5f 62 61 63 6b 75 70 20 2a 2c 20 lite3_backup *,
2ac20 50 67 6e 6f 2c 20 63 6f 6e 73 74 20 75 38 20 2a Pgno, const u8 *
2ac30 29 3b 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 );..#ifndef SQLI
2ac40 54 45 5f 4f 4d 49 54 5f 53 55 42 51 55 45 52 59 TE_OMIT_SUBQUERY
2ac50 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
2ac60 43 68 65 63 6b 49 4e 28 50 61 72 73 65 2a 2c 20 CheckIN(Parse*,
2ac70 45 78 70 72 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 Expr*);.#else.#
2ac80 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 45 78 define sqlite3Ex
2ac90 70 72 43 68 65 63 6b 49 4e 28 78 2c 79 29 20 53 prCheckIN(x,y) S
2aca0 51 4c 49 54 45 5f 4f 4b 0a 23 65 6e 64 69 66 0a QLITE_OK.#endif.
2acb0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
2acc0 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
2acd0 54 41 54 34 0a 76 6f 69 64 20 73 71 6c 69 74 65 TAT4.void sqlite
2ace0 33 41 6e 61 6c 79 7a 65 46 75 6e 63 74 69 6f 6e 3AnalyzeFunction
2acf0 73 28 76 6f 69 64 29 3b 0a 69 6e 74 20 73 71 6c s(void);.int sql
2ad00 69 74 65 33 53 74 61 74 34 50 72 6f 62 65 53 65 ite3Stat4ProbeSe
2ad10 74 56 61 6c 75 65 28 0a 20 20 20 20 50 61 72 73 tValue(. Pars
2ad20 65 2a 2c 49 6e 64 65 78 2a 2c 55 6e 70 61 63 6b e*,Index*,Unpack
2ad30 65 64 52 65 63 6f 72 64 2a 2a 2c 45 78 70 72 2a edRecord**,Expr*
2ad40 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a ,int,int,int*);.
2ad50 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 int sqlite3Stat4
2ad60 56 61 6c 75 65 46 72 6f 6d 45 78 70 72 28 50 61 ValueFromExpr(Pa
2ad70 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c rse*, Expr*, u8,
2ad80 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a sqlite3_value**
2ad90 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
2ada0 74 61 74 34 50 72 6f 62 65 46 72 65 65 28 55 6e tat4ProbeFree(Un
2adb0 70 61 63 6b 65 64 52 65 63 6f 72 64 2a 29 3b 0a packedRecord*);.
2adc0 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 int sqlite3Stat4
2add0 43 6f 6c 75 6d 6e 28 73 71 6c 69 74 65 33 2a 2c Column(sqlite3*,
2ade0 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e const void*, in
2adf0 74 2c 20 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f t, int, sqlite3_
2ae00 76 61 6c 75 65 2a 2a 29 3b 0a 63 68 61 72 20 73 value**);.char s
2ae10 71 6c 69 74 65 33 49 6e 64 65 78 43 6f 6c 75 6d qlite3IndexColum
2ae20 6e 41 66 66 69 6e 69 74 79 28 73 71 6c 69 74 65 nAffinity(sqlite
2ae30 33 2a 2c 20 49 6e 64 65 78 2a 2c 20 69 6e 74 29 3*, Index*, int)
2ae40 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ;.#endif../*.**
2ae50 54 68 65 20 69 6e 74 65 72 66 61 63 65 20 74 6f The interface to
2ae60 20 74 68 65 20 4c 45 4d 4f 4e 2d 67 65 6e 65 72 the LEMON-gener
2ae70 61 74 65 64 20 70 61 72 73 65 72 0a 2a 2f 0a 76 ated parser.*/.v
2ae80 6f 69 64 20 2a 73 71 6c 69 74 65 33 50 61 72 73 oid *sqlite3Pars
2ae90 65 72 41 6c 6c 6f 63 28 76 6f 69 64 2a 28 2a 29 erAlloc(void*(*)
2aea0 28 75 36 34 29 29 3b 0a 76 6f 69 64 20 73 71 6c (u64));.void sql
2aeb0 69 74 65 33 50 61 72 73 65 72 46 72 65 65 28 76 ite3ParserFree(v
2aec0 6f 69 64 2a 2c 20 76 6f 69 64 28 2a 29 28 76 6f oid*, void(*)(vo
2aed0 69 64 2a 29 29 3b 0a 76 6f 69 64 20 73 71 6c 69 id*));.void sqli
2aee0 74 65 33 50 61 72 73 65 72 28 76 6f 69 64 2a 2c te3Parser(void*,
2aef0 20 69 6e 74 2c 20 54 6f 6b 65 6e 2c 20 50 61 72 int, Token, Par
2af00 73 65 2a 29 3b 0a 23 69 66 64 65 66 20 59 59 54 se*);.#ifdef YYT
2af10 52 41 43 4b 4d 41 58 53 54 41 43 4b 44 45 50 54 RACKMAXSTACKDEPT
2af20 48 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 50 H. int sqlite3P
2af30 61 72 73 65 72 53 74 61 63 6b 50 65 61 6b 28 76 arserStackPeak(v
2af40 6f 69 64 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 76 oid*);.#endif..v
2af50 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 4c oid sqlite3AutoL
2af60 6f 61 64 45 78 74 65 6e 73 69 6f 6e 73 28 73 71 oadExtensions(sq
2af70 6c 69 74 65 33 2a 29 3b 0a 23 69 66 6e 64 65 66 lite3*);.#ifndef
2af80 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 4c 4f 41 SQLITE_OMIT_LOA
2af90 44 5f 45 58 54 45 4e 53 49 4f 4e 0a 20 20 76 6f D_EXTENSION. vo
2afa0 69 64 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 45 id sqlite3CloseE
2afb0 78 74 65 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 xtensions(sqlite
2afc0 33 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 3*);.#else.# def
2afd0 69 6e 65 20 73 71 6c 69 74 65 33 43 6c 6f 73 65 ine sqlite3Close
2afe0 45 78 74 65 6e 73 69 6f 6e 73 28 58 29 0a 23 65 Extensions(X).#e
2aff0 6e 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 ndif..#ifndef SQ
2b000 4c 49 54 45 5f 4f 4d 49 54 5f 53 48 41 52 45 44 LITE_OMIT_SHARED
2b010 5f 43 41 43 48 45 0a 20 20 76 6f 69 64 20 73 71 _CACHE. void sq
2b020 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 50 lite3TableLock(P
2b030 61 72 73 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 arse *, int, int
2b040 2c 20 75 38 2c 20 63 6f 6e 73 74 20 63 68 61 72 , u8, const char
2b050 20 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 *);.#else. #de
2b060 66 69 6e 65 20 73 71 6c 69 74 65 33 54 61 62 6c fine sqlite3Tabl
2b070 65 4c 6f 63 6b 28 76 2c 77 2c 78 2c 79 2c 7a 29 eLock(v,w,x,y,z)
2b080 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 .#endif..#ifdef
2b090 53 51 4c 49 54 45 5f 54 45 53 54 0a 20 20 69 6e SQLITE_TEST. in
2b0a0 74 20 73 71 6c 69 74 65 33 55 74 66 38 54 6f 38 t sqlite3Utf8To8
2b0b0 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 29 (unsigned char*)
2b0c0 3b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 ;.#endif..#ifdef
2b0d0 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 SQLITE_OMIT_VIR
2b0e0 54 55 41 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 TUALTABLE.# def
2b0f0 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 43 ine sqlite3VtabC
2b100 6c 65 61 72 28 59 29 0a 23 20 20 64 65 66 69 6e lear(Y).# defin
2b110 65 20 73 71 6c 69 74 65 33 56 74 61 62 53 79 6e e sqlite3VtabSyn
2b120 63 28 58 2c 59 29 20 53 51 4c 49 54 45 5f 4f 4b c(X,Y) SQLITE_OK
2b130 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
2b140 65 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 58 e3VtabRollback(X
2b150 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 ).# define sqli
2b160 74 65 33 56 74 61 62 43 6f 6d 6d 69 74 28 58 29 te3VtabCommit(X)
2b170 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
2b180 65 33 56 74 61 62 49 6e 53 79 6e 63 28 64 62 29 e3VtabInSync(db)
2b190 20 30 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 0.# define sql
2b1a0 69 74 65 33 56 74 61 62 4c 6f 63 6b 28 58 29 0a ite3VtabLock(X).
2b1b0 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
2b1c0 33 56 74 61 62 55 6e 6c 6f 63 6b 28 58 29 0a 23 3VtabUnlock(X).#
2b1d0 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 define sqlite3
2b1e0 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 58 VtabUnlockList(X
2b1f0 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 ).# define sqli
2b200 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 6e 74 te3VtabSavepoint
2b210 28 58 2c 20 59 2c 20 5a 29 20 53 51 4c 49 54 45 (X, Y, Z) SQLITE
2b220 5f 4f 4b 0a 23 20 20 64 65 66 69 6e 65 20 73 71 _OK.# define sq
2b230 6c 69 74 65 33 47 65 74 56 54 61 62 6c 65 28 58 lite3GetVTable(X
2b240 2c 59 29 20 20 28 28 56 54 61 62 6c 65 2a 29 30 ,Y) ((VTable*)0
2b250 29 0a 23 65 6c 73 65 0a 20 20 20 76 6f 69 64 20 ).#else. void
2b260 73 71 6c 69 74 65 33 56 74 61 62 43 6c 65 61 72 sqlite3VtabClear
2b270 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 (sqlite3 *db, Ta
2b280 62 6c 65 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 ble*);. void s
2b290 71 6c 69 74 65 33 56 74 61 62 44 69 73 63 6f 6e qlite3VtabDiscon
2b2a0 6e 65 63 74 28 73 71 6c 69 74 65 33 20 2a 64 62 nect(sqlite3 *db
2b2b0 2c 20 54 61 62 6c 65 20 2a 70 29 3b 0a 20 20 20 , Table *p);.
2b2c0 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 53 int sqlite3VtabS
2b2d0 79 6e 63 28 73 71 6c 69 74 65 33 20 2a 64 62 2c ync(sqlite3 *db,
2b2e0 20 56 64 62 65 2a 29 3b 0a 20 20 20 69 6e 74 20 Vdbe*);. int
2b2f0 73 71 6c 69 74 65 33 56 74 61 62 52 6f 6c 6c 62 sqlite3VtabRollb
2b300 61 63 6b 28 73 71 6c 69 74 65 33 20 2a 64 62 29 ack(sqlite3 *db)
2b310 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ;. int sqlite3
2b320 56 74 61 62 43 6f 6d 6d 69 74 28 73 71 6c 69 74 VtabCommit(sqlit
2b330 65 33 20 2a 64 62 29 3b 0a 20 20 20 76 6f 69 64 e3 *db);. void
2b340 20 73 71 6c 69 74 65 33 56 74 61 62 4c 6f 63 6b sqlite3VtabLock
2b350 28 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 (VTable *);. v
2b360 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 55 oid sqlite3VtabU
2b370 6e 6c 6f 63 6b 28 56 54 61 62 6c 65 20 2a 29 3b nlock(VTable *);
2b380 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
2b390 56 74 61 62 55 6e 6c 6f 63 6b 4c 69 73 74 28 73 VtabUnlockList(s
2b3a0 71 6c 69 74 65 33 2a 29 3b 0a 20 20 20 69 6e 74 qlite3*);. int
2b3b0 20 73 71 6c 69 74 65 33 56 74 61 62 53 61 76 65 sqlite3VtabSave
2b3c0 70 6f 69 6e 74 28 73 71 6c 69 74 65 33 20 2a 2c point(sqlite3 *,
2b3d0 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 20 76 int, int);. v
2b3e0 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 49 oid sqlite3VtabI
2b3f0 6d 70 6f 72 74 45 72 72 6d 73 67 28 56 64 62 65 mportErrmsg(Vdbe
2b400 2a 2c 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a *, sqlite3_vtab*
2b410 29 3b 0a 20 20 20 56 54 61 62 6c 65 20 2a 73 71 );. VTable *sq
2b420 6c 69 74 65 33 47 65 74 56 54 61 62 6c 65 28 73 lite3GetVTable(s
2b430 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a 29 qlite3*, Table*)
2b440 3b 0a 20 20 20 4d 6f 64 75 6c 65 20 2a 73 71 6c ;. Module *sql
2b450 69 74 65 33 56 74 61 62 43 72 65 61 74 65 4d 6f ite3VtabCreateMo
2b460 64 75 6c 65 28 0a 20 20 20 20 20 73 71 6c 69 74 dule(. sqlit
2b470 65 33 2a 2c 0a 20 20 20 20 20 63 6f 6e 73 74 20 e3*,. const
2b480 63 68 61 72 2a 2c 0a 20 20 20 20 20 63 6f 6e 73 char*,. cons
2b490 74 20 73 71 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 t sqlite3_module
2b4a0 2a 2c 0a 20 20 20 20 20 76 6f 69 64 2a 2c 0a 20 *,. void*,.
2b4b0 20 20 20 20 76 6f 69 64 28 2a 29 28 76 6f 69 64 void(*)(void
2b4c0 2a 29 0a 20 20 20 29 3b 0a 23 20 20 64 65 66 69 *). );.# defi
2b4d0 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 6e ne sqlite3VtabIn
2b4e0 53 79 6e 63 28 64 62 29 20 28 28 64 62 29 2d 3e Sync(db) ((db)->
2b4f0 6e 56 54 72 61 6e 73 3e 30 20 26 26 20 28 64 62 nVTrans>0 && (db
2b500 29 2d 3e 61 56 54 72 61 6e 73 3d 3d 30 29 0a 23 )->aVTrans==0).#
2b510 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 74 65 endif.int sqlite
2b520 33 56 74 61 62 45 70 6f 6e 79 6d 6f 75 73 54 61 3VtabEponymousTa
2b530 62 6c 65 49 6e 69 74 28 50 61 72 73 65 2a 2c 4d bleInit(Parse*,M
2b540 6f 64 75 6c 65 2a 29 3b 0a 76 6f 69 64 20 73 71 odule*);.void sq
2b550 6c 69 74 65 33 56 74 61 62 45 70 6f 6e 79 6d 6f lite3VtabEponymo
2b560 75 73 54 61 62 6c 65 43 6c 65 61 72 28 73 71 6c usTableClear(sql
2b570 69 74 65 33 2a 2c 4d 6f 64 75 6c 65 2a 29 3b 0a ite3*,Module*);.
2b580 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 void sqlite3Vtab
2b590 4d 61 6b 65 57 72 69 74 61 62 6c 65 28 50 61 72 MakeWritable(Par
2b5a0 73 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a 76 6f 69 se*,Table*);.voi
2b5b0 64 20 73 71 6c 69 74 65 33 56 74 61 62 42 65 67 d sqlite3VtabBeg
2b5c0 69 6e 50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 inParse(Parse*,
2b5d0 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 Token*, Token*,
2b5e0 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a 76 6f Token*, int);.vo
2b5f0 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 46 69 id sqlite3VtabFi
2b600 6e 69 73 68 50 61 72 73 65 28 50 61 72 73 65 2a nishParse(Parse*
2b610 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
2b620 73 71 6c 69 74 65 33 56 74 61 62 41 72 67 49 6e sqlite3VtabArgIn
2b630 69 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 it(Parse*);.void
2b640 20 73 71 6c 69 74 65 33 56 74 61 62 41 72 67 45 sqlite3VtabArgE
2b650 78 74 65 6e 64 28 50 61 72 73 65 2a 2c 20 54 6f xtend(Parse*, To
2b660 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ken*);.int sqlit
2b670 65 33 56 74 61 62 43 61 6c 6c 43 72 65 61 74 65 e3VtabCallCreate
2b680 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
2b690 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 68 const char *, ch
2b6a0 61 72 20 2a 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ar **);.int sqli
2b6b0 74 65 33 56 74 61 62 43 61 6c 6c 43 6f 6e 6e 65 te3VtabCallConne
2b6c0 63 74 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 ct(Parse*, Table
2b6d0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 *);.int sqlite3V
2b6e0 74 61 62 43 61 6c 6c 44 65 73 74 72 6f 79 28 73 tabCallDestroy(s
2b6f0 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f qlite3*, int, co
2b700 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 69 6e 74 nst char *);.int
2b710 20 73 71 6c 69 74 65 33 56 74 61 62 42 65 67 69 sqlite3VtabBegi
2b720 6e 28 73 71 6c 69 74 65 33 20 2a 2c 20 56 54 61 n(sqlite3 *, VTa
2b730 62 6c 65 20 2a 29 3b 0a 46 75 6e 63 44 65 66 20 ble *);.FuncDef
2b740 2a 73 71 6c 69 74 65 33 56 74 61 62 4f 76 65 72 *sqlite3VtabOver
2b750 6c 6f 61 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c loadFunction(sql
2b760 69 74 65 33 20 2a 2c 46 75 6e 63 44 65 66 2a 2c ite3 *,FuncDef*,
2b770 20 69 6e 74 20 6e 41 72 67 2c 20 45 78 70 72 2a int nArg, Expr*
2b780 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 );.void sqlite3I
2b790 6e 76 61 6c 69 64 46 75 6e 63 74 69 6f 6e 28 73 nvalidFunction(s
2b7a0 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
2b7b0 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
2b7c0 65 2a 2a 29 3b 0a 73 71 6c 69 74 65 33 5f 69 6e e**);.sqlite3_in
2b7d0 74 36 34 20 73 71 6c 69 74 65 33 53 74 6d 74 43 t64 sqlite3StmtC
2b7e0 75 72 72 65 6e 74 54 69 6d 65 28 73 71 6c 69 74 urrentTime(sqlit
2b7f0 65 33 5f 63 6f 6e 74 65 78 74 2a 29 3b 0a 69 6e e3_context*);.in
2b800 74 20 73 71 6c 69 74 65 33 56 64 62 65 50 61 72 t sqlite3VdbePar
2b810 61 6d 65 74 65 72 49 6e 64 65 78 28 56 64 62 65 ameterIndex(Vdbe
2b820 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 *, const char*,
2b830 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
2b840 33 54 72 61 6e 73 66 65 72 42 69 6e 64 69 6e 67 3TransferBinding
2b850 73 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a s(sqlite3_stmt *
2b860 2c 20 73 71 6c 69 74 65 33 5f 73 74 6d 74 20 2a , sqlite3_stmt *
2b870 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
2b880 61 72 73 65 72 52 65 73 65 74 28 50 61 72 73 65 arserReset(Parse
2b890 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 *);.int sqlite3R
2b8a0 65 70 72 65 70 61 72 65 28 56 64 62 65 2a 29 3b eprepare(Vdbe*);
2b8b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
2b8c0 72 4c 69 73 74 43 68 65 63 6b 4c 65 6e 67 74 68 rListCheckLength
2b8d0 28 50 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 73 (Parse*, ExprLis
2b8e0 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 t*, const char*)
2b8f0 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 ;.CollSeq *sqlit
2b900 65 33 42 69 6e 61 72 79 43 6f 6d 70 61 72 65 43 e3BinaryCompareC
2b910 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 2c 20 ollSeq(Parse *,
2b920 45 78 70 72 20 2a 2c 20 45 78 70 72 20 2a 29 3b Expr *, Expr *);
2b930 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 65 6d 70 .int sqlite3Temp
2b940 49 6e 4d 65 6d 6f 72 79 28 63 6f 6e 73 74 20 73 InMemory(const s
2b950 71 6c 69 74 65 33 2a 29 3b 0a 63 6f 6e 73 74 20 qlite3*);.const
2b960 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4a 6f 75 char *sqlite3Jou
2b970 72 6e 61 6c 4d 6f 64 65 6e 61 6d 65 28 69 6e 74 rnalModename(int
2b980 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
2b990 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 E_OMIT_WAL. int
2b9a0 20 73 71 6c 69 74 65 33 43 68 65 63 6b 70 6f 69 sqlite3Checkpoi
2b9b0 6e 74 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 nt(sqlite3*, int
2b9c0 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 , int, int*, int
2b9d0 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 *);. int sqlite
2b9e0 33 57 61 6c 44 65 66 61 75 6c 74 48 6f 6f 6b 28 3WalDefaultHook(
2b9f0 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 void*,sqlite3*,c
2ba00 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b onst char*,int);
2ba10 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
2ba20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 54 45 0a SQLITE_OMIT_CTE.
2ba30 20 20 57 69 74 68 20 2a 73 71 6c 69 74 65 33 57 With *sqlite3W
2ba40 69 74 68 41 64 64 28 50 61 72 73 65 2a 2c 57 69 ithAdd(Parse*,Wi
2ba50 74 68 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 72 4c th*,Token*,ExprL
2ba60 69 73 74 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a 20 ist*,Select*);.
2ba70 20 76 6f 69 64 20 73 71 6c 69 74 65 33 57 69 74 void sqlite3Wit
2ba80 68 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a hDelete(sqlite3*
2ba90 2c 57 69 74 68 2a 29 3b 0a 20 20 76 6f 69 64 20 ,With*);. void
2baa0 73 71 6c 69 74 65 33 57 69 74 68 50 75 73 68 28 sqlite3WithPush(
2bab0 50 61 72 73 65 2a 2c 20 57 69 74 68 2a 2c 20 75 Parse*, With*, u
2bac0 38 29 3b 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 8);.#else.#defin
2bad0 65 20 73 71 6c 69 74 65 33 57 69 74 68 50 75 73 e sqlite3WithPus
2bae0 68 28 78 2c 79 2c 7a 29 0a 23 64 65 66 69 6e 65 h(x,y,z).#define
2baf0 20 73 71 6c 69 74 65 33 57 69 74 68 44 65 6c 65 sqlite3WithDele
2bb00 74 65 28 78 2c 79 29 0a 23 65 6e 64 69 66 0a 0a te(x,y).#endif..
2bb10 2f 2a 20 44 65 63 6c 61 72 61 74 69 6f 6e 73 20 /* Declarations
2bb20 66 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e for functions in
2bb30 20 66 6b 65 79 2e 63 2e 20 41 6c 6c 20 6f 66 20 fkey.c. All of
2bb40 74 68 65 73 65 20 61 72 65 20 72 65 70 6c 61 63 these are replac
2bb50 65 64 20 62 79 0a 2a 2a 20 6e 6f 2d 6f 70 20 6d ed by.** no-op m
2bb60 61 63 72 6f 73 20 69 66 20 4f 4d 49 54 5f 46 4f acros if OMIT_FO
2bb70 52 45 49 47 4e 5f 4b 45 59 20 69 73 20 64 65 66 REIGN_KEY is def
2bb80 69 6e 65 64 2e 20 49 6e 20 74 68 69 73 20 63 61 ined. In this ca
2bb90 73 65 20 6e 6f 20 66 6f 72 65 69 67 6e 0a 2a 2a se no foreign.**
2bba0 20 6b 65 79 20 66 75 6e 63 74 69 6f 6e 61 6c 69 key functionali
2bbb0 74 79 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2e ty is available.
2bbc0 20 49 66 20 4f 4d 49 54 5f 54 52 49 47 47 45 52 If OMIT_TRIGGER
2bbd0 20 69 73 20 64 65 66 69 6e 65 64 20 62 75 74 0a is defined but.
2bbe0 2a 2a 20 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f ** OMIT_FOREIGN_
2bbf0 4b 45 59 20 69 73 20 6e 6f 74 2c 20 6f 6e 6c 79 KEY is not, only
2bc00 20 73 6f 6d 65 20 6f 66 20 74 68 65 20 66 75 6e some of the fun
2bc10 63 74 69 6f 6e 73 20 61 72 65 20 6e 6f 2d 6f 70 ctions are no-op
2bc20 65 64 2e 20 49 6e 0a 2a 2a 20 74 68 69 73 20 63 ed. In.** this c
2bc30 61 73 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 ase foreign keys
2bc40 20 61 72 65 20 70 61 72 73 65 64 2c 20 62 75 74 are parsed, but
2bc50 20 6e 6f 20 6f 74 68 65 72 20 66 75 6e 63 74 69 no other functi
2bc60 6f 6e 61 6c 69 74 79 20 69 73 0a 2a 2a 20 70 72 onality is.** pr
2bc70 6f 76 69 64 65 64 20 28 65 6e 66 6f 72 63 65 6d ovided (enforcem
2bc80 65 6e 74 20 6f 66 20 46 4b 20 63 6f 6e 73 74 72 ent of FK constr
2bc90 61 69 6e 74 73 20 72 65 71 75 69 72 65 73 20 74 aints requires t
2bca0 68 65 20 74 72 69 67 67 65 72 73 20 73 75 62 2d he triggers sub-
2bcb0 73 79 73 74 65 6d 29 2e 0a 2a 2f 0a 23 69 66 20 system)..*/.#if
2bcc0 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
2bcd0 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 OMIT_FOREIGN_KEY
2bce0 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 ) && !defined(SQ
2bcf0 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 LITE_OMIT_TRIGGE
2bd00 52 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 R). void sqlite
2bd10 33 46 6b 43 68 65 63 6b 28 50 61 72 73 65 2a 2c 3FkCheck(Parse*,
2bd20 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e Table*, int, in
2bd30 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 t, int*, int);.
2bd40 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 44 void sqlite3FkD
2bd50 72 6f 70 54 61 62 6c 65 28 50 61 72 73 65 2a 2c ropTable(Parse*,
2bd60 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 61 62 6c SrcList *, Tabl
2bd70 65 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 e*);. void sqli
2bd80 74 65 33 46 6b 41 63 74 69 6f 6e 73 28 50 61 72 te3FkActions(Par
2bd90 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 se*, Table*, Exp
2bda0 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 rList*, int, int
2bdb0 2a 2c 20 69 6e 74 29 3b 0a 20 20 69 6e 74 20 73 *, int);. int s
2bdc0 71 6c 69 74 65 33 46 6b 52 65 71 75 69 72 65 64 qlite3FkRequired
2bdd0 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c (Parse*, Table*,
2bde0 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 75 int*, int);. u
2bdf0 33 32 20 73 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 32 sqlite3FkOldm
2be00 61 73 6b 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ask(Parse*, Tabl
2be10 65 2a 29 3b 0a 20 20 46 4b 65 79 20 2a 73 71 6c e*);. FKey *sql
2be20 69 74 65 33 46 6b 52 65 66 65 72 65 6e 63 65 73 ite3FkReferences
2be30 28 54 61 62 6c 65 20 2a 29 3b 0a 23 65 6c 73 65 (Table *);.#else
2be40 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
2be50 65 33 46 6b 41 63 74 69 6f 6e 73 28 61 2c 62 2c e3FkActions(a,b,
2be60 63 2c 64 2c 65 2c 66 29 0a 20 20 23 64 65 66 69 c,d,e,f). #defi
2be70 6e 65 20 73 71 6c 69 74 65 33 46 6b 43 68 65 63 ne sqlite3FkChec
2be80 6b 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 k(a,b,c,d,e,f).
2be90 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2bea0 46 6b 44 72 6f 70 54 61 62 6c 65 28 61 2c 62 2c FkDropTable(a,b,
2beb0 63 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c c). #define sql
2bec0 69 74 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 61 2c ite3FkOldmask(a,
2bed0 62 29 20 20 20 20 20 20 20 20 20 30 0a 20 20 23 b) 0. #
2bee0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
2bef0 52 65 71 75 69 72 65 64 28 61 2c 62 2c 63 2c 64 Required(a,b,c,d
2bf00 29 20 20 20 20 30 0a 23 65 6e 64 69 66 0a 23 69 ) 0.#endif.#i
2bf10 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
2bf20 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 0a 20 20 T_FOREIGN_KEY.
2bf30 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 44 65 void sqlite3FkDe
2bf40 6c 65 74 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 lete(sqlite3 *,
2bf50 54 61 62 6c 65 2a 29 3b 0a 20 20 69 6e 74 20 73 Table*);. int s
2bf60 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 49 6e qlite3FkLocateIn
2bf70 64 65 78 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 dex(Parse*,Table
2bf80 2a 2c 46 4b 65 79 2a 2c 49 6e 64 65 78 2a 2a 2c *,FKey*,Index**,
2bf90 69 6e 74 2a 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 int**);.#else.
2bfa0 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 #define sqlite3F
2bfb0 6b 44 65 6c 65 74 65 28 61 2c 62 29 0a 20 20 23 kDelete(a,b). #
2bfc0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
2bfd0 4c 6f 63 61 74 65 49 6e 64 65 78 28 61 2c 62 2c LocateIndex(a,b,
2bfe0 63 2c 64 2c 65 29 0a 23 65 6e 64 69 66 0a 0a 0a c,d,e).#endif...
2bff0 2f 2a 0a 2a 2a 20 41 76 61 69 6c 61 62 6c 65 20 /*.** Available
2c000 66 61 75 6c 74 20 69 6e 6a 65 63 74 6f 72 73 2e fault injectors.
2c010 20 20 53 68 6f 75 6c 64 20 62 65 20 6e 75 6d 62 Should be numb
2c020 65 72 65 64 20 62 65 67 69 6e 6e 69 6e 67 20 77 ered beginning w
2c030 69 74 68 20 30 2e 0a 2a 2f 0a 23 64 65 66 69 6e ith 0..*/.#defin
2c040 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 49 4e e SQLITE_FAULTIN
2c050 4a 45 43 54 4f 52 5f 4d 41 4c 4c 4f 43 20 20 20 JECTOR_MALLOC
2c060 20 20 30 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 0.#define SQLI
2c070 54 45 5f 46 41 55 4c 54 49 4e 4a 45 43 54 4f 52 TE_FAULTINJECTOR
2c080 5f 43 4f 55 4e 54 20 20 20 20 20 20 31 0a 0a 2f _COUNT 1../
2c090 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 66 61 *.** The interfa
2c0a0 63 65 20 74 6f 20 74 68 65 20 63 6f 64 65 20 69 ce to the code i
2c0b0 6e 20 66 61 75 6c 74 2e 63 20 75 73 65 64 20 66 n fault.c used f
2c0c0 6f 72 20 69 64 65 6e 74 69 66 79 69 6e 67 20 22 or identifying "
2c0d0 62 65 6e 69 67 6e 22 0a 2a 2a 20 6d 61 6c 6c 6f benign".** mallo
2c0e0 63 20 66 61 69 6c 75 72 65 73 2e 20 54 68 69 73 c failures. This
2c0f0 20 69 73 20 6f 6e 6c 79 20 70 72 65 73 65 6e 74 is only present
2c100 20 69 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 if SQLITE_UNTES
2c110 54 41 42 4c 45 0a 2a 2a 20 69 73 20 6e 6f 74 20 TABLE.** is not
2c120 64 65 66 69 6e 65 64 2e 0a 2a 2f 0a 23 69 66 6e defined..*/.#ifn
2c130 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 def SQLITE_UNTES
2c140 54 41 42 4c 45 0a 20 20 76 6f 69 64 20 73 71 6c TABLE. void sql
2c150 69 74 65 33 42 65 67 69 6e 42 65 6e 69 67 6e 4d ite3BeginBenignM
2c160 61 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a 20 20 76 alloc(void);. v
2c170 6f 69 64 20 73 71 6c 69 74 65 33 45 6e 64 42 65 oid sqlite3EndBe
2c180 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 29 nignMalloc(void)
2c190 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e ;.#else. #defin
2c1a0 65 20 73 71 6c 69 74 65 33 42 65 67 69 6e 42 65 e sqlite3BeginBe
2c1b0 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a 20 20 23 nignMalloc(). #
2c1c0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 45 6e define sqlite3En
2c1d0 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a dBenignMalloc().
2c1e0 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6c #endif../*.** Al
2c1f0 6c 6f 77 65 64 20 72 65 74 75 72 6e 20 76 61 6c lowed return val
2c200 75 65 73 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 ues from sqlite3
2c210 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 0a 2a 2f FindInIndex().*/
2c220 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 .#define IN_INDE
2c230 58 5f 52 4f 57 49 44 20 20 20 20 20 20 20 20 31 X_ROWID 1
2c240 20 20 20 2f 2a 20 53 65 61 72 63 68 20 74 68 65 /* Search the
2c250 20 72 6f 77 69 64 20 6f 66 20 74 68 65 20 74 61 rowid of the ta
2c260 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 ble */.#define I
2c270 4e 5f 49 4e 44 45 58 5f 45 50 48 20 20 20 20 20 N_INDEX_EPH
2c280 20 20 20 20 20 32 20 20 20 2f 2a 20 53 65 61 72 2 /* Sear
2c290 63 68 20 61 6e 20 65 70 68 65 6d 65 72 61 6c 20 ch an ephemeral
2c2a0 62 2d 74 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e b-tree */.#defin
2c2b0 65 20 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 58 e IN_INDEX_INDEX
2c2c0 5f 41 53 43 20 20 20 20 33 20 20 20 2f 2a 20 45 _ASC 3 /* E
2c2d0 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 41 53 xisting index AS
2c2e0 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 66 69 CENDING */.#defi
2c2f0 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 45 ne IN_INDEX_INDE
2c300 58 5f 44 45 53 43 20 20 20 34 20 20 20 2f 2a 20 X_DESC 4 /*
2c310 45 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 44 Existing index D
2c320 45 53 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 ESCENDING */.#de
2c330 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f fine IN_INDEX_NO
2c340 4f 50 20 20 20 20 20 20 20 20 20 35 20 20 20 2f OP 5 /
2c350 2a 20 4e 6f 20 74 61 62 6c 65 20 61 76 61 69 6c * No table avail
2c360 61 62 6c 65 2e 20 55 73 65 20 63 6f 6d 70 61 72 able. Use compar
2c370 69 73 6f 6e 73 20 2a 2f 0a 2f 2a 0a 2a 2a 20 41 isons */./*.** A
2c380 6c 6c 6f 77 65 64 20 66 6c 61 67 73 20 66 6f 72 llowed flags for
2c390 20 74 68 65 20 33 72 64 20 70 61 72 61 6d 65 74 the 3rd paramet
2c3a0 65 72 20 74 6f 20 73 71 6c 69 74 65 33 46 69 6e er to sqlite3Fin
2c3b0 64 49 6e 49 6e 64 65 78 28 29 2e 0a 2a 2f 0a 23 dInIndex()..*/.#
2c3c0 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
2c3d0 4e 4f 4f 50 5f 4f 4b 20 20 20 20 20 30 78 30 30 NOOP_OK 0x00
2c3e0 30 31 20 20 2f 2a 20 4f 4b 20 74 6f 20 72 65 74 01 /* OK to ret
2c3f0 75 72 6e 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f urn IN_INDEX_NOO
2c400 50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f P */.#define IN_
2c410 49 4e 44 45 58 5f 4d 45 4d 42 45 52 53 48 49 50 INDEX_MEMBERSHIP
2c420 20 20 30 78 30 30 30 32 20 20 2f 2a 20 49 4e 20 0x0002 /* IN
2c430 6f 70 65 72 61 74 6f 72 20 75 73 65 64 20 66 6f operator used fo
2c440 72 20 6d 65 6d 62 65 72 73 68 69 70 20 74 65 73 r membership tes
2c450 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f t */.#define IN_
2c460 49 4e 44 45 58 5f 4c 4f 4f 50 20 20 20 20 20 20 INDEX_LOOP
2c470 20 20 30 78 30 30 30 34 20 20 2f 2a 20 49 4e 20 0x0004 /* IN
2c480 6f 70 65 72 61 74 6f 72 20 75 73 65 64 20 61 73 operator used as
2c490 20 61 20 6c 6f 6f 70 20 2a 2f 0a 69 6e 74 20 73 a loop */.int s
2c4a0 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 65 qlite3FindInInde
2c4b0 78 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 x(Parse *, Expr
2c4c0 2a 2c 20 75 33 32 2c 20 69 6e 74 2a 2c 20 69 6e *, u32, int*, in
2c4d0 74 2a 29 3b 0a 0a 69 6e 74 20 73 71 6c 69 74 65 t*);..int sqlite
2c4e0 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 6c 3JournalOpen(sql
2c4f0 69 74 65 33 5f 76 66 73 20 2a 2c 20 63 6f 6e 73 ite3_vfs *, cons
2c500 74 20 63 68 61 72 20 2a 2c 20 73 71 6c 69 74 65 t char *, sqlite
2c510 33 5f 66 69 6c 65 20 2a 2c 20 69 6e 74 2c 20 69 3_file *, int, i
2c520 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
2c530 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 73 71 6c 69 JournalSize(sqli
2c540 74 65 33 5f 76 66 73 20 2a 29 3b 0a 23 69 66 64 te3_vfs *);.#ifd
2c550 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
2c560 5f 41 54 4f 4d 49 43 5f 57 52 49 54 45 0a 20 20 _ATOMIC_WRITE.
2c570 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e int sqlite3Journ
2c580 61 6c 43 72 65 61 74 65 28 73 71 6c 69 74 65 33 alCreate(sqlite3
2c590 5f 66 69 6c 65 20 2a 29 3b 0a 23 65 6e 64 69 66 _file *);.#endif
2c5a0 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 ..int sqlite3Jou
2c5b0 72 6e 61 6c 49 73 49 6e 4d 65 6d 6f 72 79 28 73 rnalIsInMemory(s
2c5c0 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a 70 29 3b qlite3_file *p);
2c5d0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 65 6d .void sqlite3Mem
2c5e0 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 6c 69 JournalOpen(sqli
2c5f0 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 0a 76 6f te3_file *);..vo
2c600 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 53 65 id sqlite3ExprSe
2c610 74 48 65 69 67 68 74 41 6e 64 46 6c 61 67 73 28 tHeightAndFlags(
2c620 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 45 Parse *pParse, E
2c630 78 70 72 20 2a 70 29 3b 0a 23 69 66 20 53 51 4c xpr *p);.#if SQL
2c640 49 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 ITE_MAX_EXPR_DEP
2c650 54 48 3e 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 TH>0. int sqlit
2c660 65 33 53 65 6c 65 63 74 45 78 70 72 48 65 69 67 e3SelectExprHeig
2c670 68 74 28 53 65 6c 65 63 74 20 2a 29 3b 0a 20 20 ht(Select *);.
2c680 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 43 int sqlite3ExprC
2c690 68 65 63 6b 48 65 69 67 68 74 28 50 61 72 73 65 heckHeight(Parse
2c6a0 2a 2c 20 69 6e 74 29 3b 0a 23 65 6c 73 65 0a 20 *, int);.#else.
2c6b0 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2c6c0 53 65 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 SelectExprHeight
2c6d0 28 78 29 20 30 0a 20 20 23 64 65 66 69 6e 65 20 (x) 0. #define
2c6e0 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b sqlite3ExprCheck
2c6f0 48 65 69 67 68 74 28 78 2c 79 29 0a 23 65 6e 64 Height(x,y).#end
2c700 69 66 0a 0a 75 33 32 20 73 71 6c 69 74 65 33 47 if..u32 sqlite3G
2c710 65 74 34 62 79 74 65 28 63 6f 6e 73 74 20 75 38 et4byte(const u8
2c720 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2c730 50 75 74 34 62 79 74 65 28 75 38 2a 2c 20 75 33 Put4byte(u8*, u3
2c740 32 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 2);..#ifdef SQLI
2c750 54 45 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b TE_ENABLE_UNLOCK
2c760 5f 4e 4f 54 49 46 59 0a 20 20 76 6f 69 64 20 73 _NOTIFY. void s
2c770 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e qlite3Connection
2c780 42 6c 6f 63 6b 65 64 28 73 71 6c 69 74 65 33 20 Blocked(sqlite3
2c790 2a 2c 20 73 71 6c 69 74 65 33 20 2a 29 3b 0a 20 *, sqlite3 *);.
2c7a0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6e void sqlite3Con
2c7b0 6e 65 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 nectionUnlocked(
2c7c0 73 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 sqlite3 *db);.
2c7d0 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e void sqlite3Conn
2c7e0 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 73 71 6c ectionClosed(sql
2c7f0 69 74 65 33 20 2a 64 62 29 3b 0a 23 65 6c 73 65 ite3 *db);.#else
2c800 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
2c810 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 e3ConnectionBloc
2c820 6b 65 64 28 78 2c 79 29 0a 20 20 23 64 65 66 69 ked(x,y). #defi
2c830 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 ne sqlite3Connec
2c840 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 78 29 0a tionUnlocked(x).
2c850 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
2c860 33 43 6f 6e 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 3ConnectionClose
2c870 64 28 78 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 d(x).#endif..#if
2c880 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 def SQLITE_DEBUG
2c890 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 50 . void sqlite3P
2c8a0 61 72 73 65 72 54 72 61 63 65 28 46 49 4c 45 2a arserTrace(FILE*
2c8b0 2c 20 63 68 61 72 20 2a 29 3b 0a 23 65 6e 64 69 , char *);.#endi
2c8c0 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 74 68 65 20 f../*.** If the
2c8d0 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 20 49 4f SQLITE_ENABLE IO
2c8e0 54 52 41 43 45 20 65 78 69 73 74 73 20 74 68 65 TRACE exists the
2c8f0 6e 20 74 68 65 20 67 6c 6f 62 61 6c 20 76 61 72 n the global var
2c900 69 61 62 6c 65 0a 2a 2a 20 73 71 6c 69 74 65 33 iable.** sqlite3
2c910 49 6f 54 72 61 63 65 20 69 73 20 61 20 70 6f 69 IoTrace is a poi
2c920 6e 74 65 72 20 74 6f 20 61 20 70 72 69 6e 74 66 nter to a printf
2c930 2d 6c 69 6b 65 20 72 6f 75 74 69 6e 65 20 75 73 -like routine us
2c940 65 64 20 74 6f 0a 2a 2a 20 70 72 69 6e 74 20 49 ed to.** print I
2c950 2f 4f 20 74 72 61 63 69 6e 67 20 6d 65 73 73 61 /O tracing messa
2c960 67 65 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 ges..*/.#ifdef S
2c970 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 49 4f 54 QLITE_ENABLE_IOT
2c980 52 41 43 45 0a 23 20 64 65 66 69 6e 65 20 49 4f RACE.# define IO
2c990 54 52 41 43 45 28 41 29 20 20 69 66 28 20 73 71 TRACE(A) if( sq
2c9a0 6c 69 74 65 33 49 6f 54 72 61 63 65 20 29 7b 20 lite3IoTrace ){
2c9b0 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 20 41 sqlite3IoTrace A
2c9c0 3b 20 7d 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 ; }. void sqlit
2c9d0 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 71 6c e3VdbeIOTraceSql
2c9e0 28 56 64 62 65 2a 29 3b 0a 53 51 4c 49 54 45 5f (Vdbe*);.SQLITE_
2c9f0 41 50 49 20 53 51 4c 49 54 45 5f 45 58 54 45 52 API SQLITE_EXTER
2ca00 4e 20 76 6f 69 64 20 28 53 51 4c 49 54 45 5f 43 N void (SQLITE_C
2ca10 44 45 43 4c 20 2a 73 71 6c 69 74 65 33 49 6f 54 DECL *sqlite3IoT
2ca20 72 61 63 65 29 28 63 6f 6e 73 74 20 63 68 61 72 race)(const char
2ca30 2a 2c 2e 2e 2e 29 3b 0a 23 65 6c 73 65 0a 23 20 *,...);.#else.#
2ca40 64 65 66 69 6e 65 20 49 4f 54 52 41 43 45 28 41 define IOTRACE(A
2ca50 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
2ca60 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 71 6c e3VdbeIOTraceSql
2ca70 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a (X).#endif../*.*
2ca80 2a 20 54 68 65 73 65 20 72 6f 75 74 69 6e 65 73 * These routines
2ca90 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 20 66 are available f
2caa0 6f 72 20 74 68 65 20 6d 65 6d 32 2e 63 20 64 65 or the mem2.c de
2cab0 62 75 67 67 69 6e 67 20 6d 65 6d 6f 72 79 20 61 bugging memory a
2cac0 6c 6c 6f 63 61 74 6f 72 0a 2a 2a 20 6f 6e 6c 79 llocator.** only
2cad0 2e 20 20 54 68 65 79 20 61 72 65 20 75 73 65 64 . They are used
2cae0 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 to verify that
2caf0 64 69 66 66 65 72 65 6e 74 20 22 74 79 70 65 73 different "types
2cb00 22 20 6f 66 20 6d 65 6d 6f 72 79 0a 2a 2a 20 61 " of memory.** a
2cb10 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 70 llocations are p
2cb20 72 6f 70 65 72 6c 79 20 74 72 61 63 6b 65 64 20 roperly tracked
2cb30 62 79 20 74 68 65 20 73 79 73 74 65 6d 2e 0a 2a by the system..*
2cb40 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 *.** sqlite3Memd
2cb50 65 62 75 67 53 65 74 54 79 70 65 28 29 20 73 65 ebugSetType() se
2cb60 74 73 20 74 68 65 20 22 74 79 70 65 22 20 6f 66 ts the "type" of
2cb70 20 61 6e 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 74 an allocation t
2cb80 6f 20 6f 6e 65 20 6f 66 0a 2a 2a 20 74 68 65 20 o one of.** the
2cb90 4d 45 4d 54 59 50 45 5f 2a 20 6d 61 63 72 6f 73 MEMTYPE_* macros
2cba0 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 2e 20 defined below.
2cbb0 20 54 68 65 20 74 79 70 65 20 6d 75 73 74 20 62 The type must b
2cbc0 65 20 61 20 62 69 74 6d 61 73 6b 20 77 69 74 68 e a bitmask with
2cbd0 0a 2a 2a 20 61 20 73 69 6e 67 6c 65 20 62 69 74 .** a single bit
2cbe0 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 set..**.** sqli
2cbf0 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 te3MemdebugHasTy
2cc00 70 65 28 29 20 72 65 74 75 72 6e 73 20 74 72 75 pe() returns tru
2cc10 65 20 69 66 20 61 6e 79 20 6f 66 20 74 68 65 20 e if any of the
2cc20 62 69 74 73 20 69 6e 20 69 74 73 20 73 65 63 6f bits in its seco
2cc30 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 20 6d nd.** argument m
2cc40 61 74 63 68 20 74 68 65 20 74 79 70 65 20 73 65 atch the type se
2cc50 74 20 62 79 20 74 68 65 20 70 72 65 76 69 6f 75 t by the previou
2cc60 73 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 s sqlite3Memdebu
2cc70 67 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a 20 73 gSetType()..** s
2cc80 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 qlite3MemdebugHa
2cc90 73 54 79 70 65 28 29 20 69 73 20 69 6e 74 65 6e sType() is inten
2cca0 64 65 64 20 66 6f 72 20 75 73 65 20 69 6e 73 69 ded for use insi
2ccb0 64 65 20 61 73 73 65 72 74 28 29 20 73 74 61 74 de assert() stat
2ccc0 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 73 71 ements..**.** sq
2ccd0 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 lite3MemdebugNoT
2cce0 79 70 65 28 29 20 72 65 74 75 72 6e 73 20 74 72 ype() returns tr
2ccf0 75 65 20 69 66 20 6e 6f 6e 65 20 6f 66 20 74 68 ue if none of th
2cd00 65 20 62 69 74 73 20 69 6e 20 69 74 73 20 73 65 e bits in its se
2cd10 63 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 cond.** argument
2cd20 20 6d 61 74 63 68 20 74 68 65 20 74 79 70 65 20 match the type
2cd30 73 65 74 20 62 79 20 74 68 65 20 70 72 65 76 69 set by the previ
2cd40 6f 75 73 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 ous sqlite3Memde
2cd50 62 75 67 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a bugSetType()..**
2cd60 0a 2a 2a 20 50 65 72 68 61 70 73 20 74 68 65 20 .** Perhaps the
2cd70 6d 6f 73 74 20 69 6d 70 6f 72 74 61 6e 74 20 70 most important p
2cd80 6f 69 6e 74 20 69 73 20 74 68 65 20 64 69 66 66 oint is the diff
2cd90 65 72 65 6e 63 65 20 62 65 74 77 65 65 6e 20 4d erence between M
2cda0 45 4d 54 59 50 45 5f 48 45 41 50 0a 2a 2a 20 61 EMTYPE_HEAP.** a
2cdb0 6e 64 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 nd MEMTYPE_LOOKA
2cdc0 53 49 44 45 2e 20 20 49 66 20 61 6e 20 61 6c 6c SIDE. If an all
2cdd0 6f 63 61 74 69 6f 6e 20 69 73 20 4d 45 4d 54 59 ocation is MEMTY
2cde0 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 2c 20 74 68 PE_LOOKASIDE, th
2cdf0 61 74 20 6d 65 61 6e 73 0a 2a 2a 20 69 74 20 6d at means.** it m
2ce00 69 67 68 74 20 68 61 76 65 20 62 65 65 6e 20 61 ight have been a
2ce10 6c 6c 6f 63 61 74 65 64 20 62 79 20 6c 6f 6f 6b llocated by look
2ce20 61 73 69 64 65 2c 20 65 78 63 65 70 74 20 74 68 aside, except th
2ce30 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 77 61 73 e allocation was
2ce40 0a 2a 2a 20 74 6f 6f 20 6c 61 72 67 65 20 6f 72 .** too large or
2ce50 20 6c 6f 6f 6b 61 73 69 64 65 20 77 61 73 20 61 lookaside was a
2ce60 6c 72 65 61 64 79 20 66 75 6c 6c 2e 20 20 49 74 lready full. It
2ce70 20 69 73 20 69 6d 70 6f 72 74 61 6e 74 20 74 6f is important to
2ce80 20 76 65 72 69 66 79 0a 2a 2a 20 74 68 61 74 20 verify.** that
2ce90 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 74 68 61 74 allocations that
2cea0 20 6d 69 67 68 74 20 68 61 76 65 20 62 65 65 6e might have been
2ceb0 20 73 61 74 69 73 66 69 65 64 20 62 79 20 6c 6f satisfied by lo
2cec0 6f 6b 61 73 69 64 65 20 61 72 65 20 6e 6f 74 0a okaside are not.
2ced0 2a 2a 20 70 61 73 73 65 64 20 62 61 63 6b 20 74 ** passed back t
2cee0 6f 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 o non-lookaside
2cef0 66 72 65 65 28 29 20 72 6f 75 74 69 6e 65 73 2e free() routines.
2cf00 20 20 41 73 73 65 72 74 73 20 73 75 63 68 20 61 Asserts such a
2cf10 73 20 74 68 65 0a 2a 2a 20 65 78 61 6d 70 6c 65 s the.** example
2cf20 20 61 62 6f 76 65 20 61 72 65 20 70 6c 61 63 65 above are place
2cf30 64 20 6f 6e 20 74 68 65 20 6e 6f 6e 2d 6c 6f 6f d on the non-loo
2cf40 6b 61 73 69 64 65 20 66 72 65 65 28 29 20 72 6f kaside free() ro
2cf50 75 74 69 6e 65 73 20 74 6f 20 76 65 72 69 66 79 utines to verify
2cf60 0a 2a 2a 20 74 68 69 73 20 63 6f 6e 73 74 72 61 .** this constra
2cf70 69 6e 74 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 6f int..**.** All o
2cf80 66 20 74 68 69 73 20 69 73 20 6e 6f 2d 6f 70 20 f this is no-op
2cf90 66 6f 72 20 61 20 70 72 6f 64 75 63 74 69 6f 6e for a production
2cfa0 20 62 75 69 6c 64 2e 20 20 49 74 20 6f 6e 6c 79 build. It only
2cfb0 20 63 6f 6d 65 73 20 69 6e 74 6f 0a 2a 2a 20 70 comes into.** p
2cfc0 6c 61 79 20 77 68 65 6e 20 74 68 65 20 53 51 4c lay when the SQL
2cfd0 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 63 6f 6d ITE_MEMDEBUG com
2cfe0 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 6f 6e pile-time option
2cff0 20 69 73 20 75 73 65 64 2e 0a 2a 2f 0a 23 69 66 is used..*/.#if
2d000 64 65 66 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 def SQLITE_MEMDE
2d010 42 55 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 BUG. void sqlit
2d020 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 e3MemdebugSetTyp
2d030 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 e(void*,u8);. i
2d040 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 nt sqlite3Memdeb
2d050 75 67 48 61 73 54 79 70 65 28 76 6f 69 64 2a 2c ugHasType(void*,
2d060 75 38 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 u8);. int sqlit
2d070 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 70 65 e3MemdebugNoType
2d080 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 23 65 6c 73 (void*,u8);.#els
2d090 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
2d0a0 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 e3MemdebugSetTyp
2d0b0 65 28 58 2c 59 29 20 20 2f 2a 20 6e 6f 2d 6f 70 e(X,Y) /* no-op
2d0c0 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 73 71 6c */.# define sql
2d0d0 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 ite3MemdebugHasT
2d0e0 79 70 65 28 58 2c 59 29 20 20 31 0a 23 20 64 65 ype(X,Y) 1.# de
2d0f0 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 fine sqlite3Memd
2d100 65 62 75 67 4e 6f 54 79 70 65 28 58 2c 59 29 20 ebugNoType(X,Y)
2d110 20 20 31 0a 23 65 6e 64 69 66 0a 23 64 65 66 69 1.#endif.#defi
2d120 6e 65 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 20 ne MEMTYPE_HEAP
2d130 20 20 20 20 20 20 30 78 30 31 20 20 2f 2a 20 47 0x01 /* G
2d140 65 6e 65 72 61 6c 20 68 65 61 70 20 61 6c 6c 6f eneral heap allo
2d150 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 cations */.#defi
2d160 6e 65 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 ne MEMTYPE_LOOKA
2d170 53 49 44 45 20 20 30 78 30 32 20 20 2f 2a 20 48 SIDE 0x02 /* H
2d180 65 61 70 20 74 68 61 74 20 6d 69 67 68 74 20 68 eap that might h
2d190 61 76 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 69 ave been lookasi
2d1a0 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 de */.#define ME
2d1b0 4d 54 59 50 45 5f 53 43 52 41 54 43 48 20 20 20 MTYPE_SCRATCH
2d1c0 20 30 78 30 34 20 20 2f 2a 20 53 63 72 61 74 63 0x04 /* Scratc
2d1d0 68 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f h allocations */
2d1e0 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 50 45 .#define MEMTYPE
2d1f0 5f 50 43 41 43 48 45 20 20 20 20 20 30 78 30 38 _PCACHE 0x08
2d200 20 20 2f 2a 20 50 61 67 65 20 63 61 63 68 65 20 /* Page cache
2d210 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 0a allocations */..
2d220 2f 2a 0a 2a 2a 20 54 68 72 65 61 64 69 6e 67 20 /*.** Threading
2d230 69 6e 74 65 72 66 61 63 65 0a 2a 2f 0a 23 69 66 interface.*/.#if
2d240 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b SQLITE_MAX_WORK
2d250 45 52 5f 54 48 52 45 41 44 53 3e 30 0a 69 6e 74 ER_THREADS>0.int
2d260 20 73 71 6c 69 74 65 33 54 68 72 65 61 64 43 72 sqlite3ThreadCr
2d270 65 61 74 65 28 53 51 4c 69 74 65 54 68 72 65 61 eate(SQLiteThrea
2d280 64 2a 2a 2c 76 6f 69 64 2a 28 2a 29 28 76 6f 69 d**,void*(*)(voi
2d290 64 2a 29 2c 76 6f 69 64 2a 29 3b 0a 69 6e 74 20 d*),void*);.int
2d2a0 73 71 6c 69 74 65 33 54 68 72 65 61 64 4a 6f 69 sqlite3ThreadJoi
2d2b0 6e 28 53 51 4c 69 74 65 54 68 72 65 61 64 2a 2c n(SQLiteThread*,
2d2c0 20 76 6f 69 64 2a 2a 29 3b 0a 23 65 6e 64 69 66 void**);.#endif
2d2d0 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 ..#if defined(SQ
2d2e0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 42 53 54 LITE_ENABLE_DBST
2d2f0 41 54 5f 56 54 41 42 29 20 7c 7c 20 64 65 66 69 AT_VTAB) || defi
2d300 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 ned(SQLITE_TEST)
2d310 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 73 74 .int sqlite3Dbst
2d320 61 74 52 65 67 69 73 74 65 72 28 73 71 6c 69 74 atRegister(sqlit
2d330 65 33 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 69 6e e3*);.#endif..in
2d340 74 20 73 71 6c 69 74 65 33 45 78 70 72 56 65 63 t sqlite3ExprVec
2d350 74 6f 72 53 69 7a 65 28 45 78 70 72 20 2a 70 45 torSize(Expr *pE
2d360 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 xpr);.int sqlite
2d370 33 45 78 70 72 49 73 56 65 63 74 6f 72 28 45 78 3ExprIsVector(Ex
2d380 70 72 20 2a 70 45 78 70 72 29 3b 0a 45 78 70 72 pr *pExpr);.Expr
2d390 20 2a 73 71 6c 69 74 65 33 56 65 63 74 6f 72 46 *sqlite3VectorF
2d3a0 69 65 6c 64 53 75 62 65 78 70 72 28 45 78 70 72 ieldSubexpr(Expr
2d3b0 2a 2c 20 69 6e 74 29 3b 0a 45 78 70 72 20 2a 73 *, int);.Expr *s
2d3c0 71 6c 69 74 65 33 45 78 70 72 46 6f 72 56 65 63 qlite3ExprForVec
2d3d0 74 6f 72 46 69 65 6c 64 28 50 61 72 73 65 2a 2c torField(Parse*,
2d3e0 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 Expr*,int);.void
2d3f0 20 73 71 6c 69 74 65 33 56 65 63 74 6f 72 45 72 sqlite3VectorEr
2d400 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c 20 45 rorMsg(Parse*, E
2d410 78 70 72 2a 29 3b 0a 0a 23 65 6e 64 69 66 20 2f xpr*);..#endif /
2d420 2a 20 53 51 4c 49 54 45 49 4e 54 5f 48 20 2a 2f * SQLITEINT_H */
2d430 0a .