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 4e 65 65 64 .#endif../* Need
0fb0: 65 64 20 66 6f 72 20 76 61 72 69 6f 75 73 20 64 ed for various d
0fc0: 65 66 69 6e 69 74 69 6f 6e 73 2e 2e 2e 20 2a 2f efinitions... */
0fd0: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 47 .#if defined(__G
0fe0: 4e 55 43 5f 5f 29 20 26 26 20 21 64 65 66 69 6e NUC__) && !defin
0ff0: 65 64 28 5f 47 4e 55 5f 53 4f 55 52 43 45 29 0a ed(_GNU_SOURCE).
1000: 23 20 64 65 66 69 6e 65 20 5f 47 4e 55 5f 53 4f # define _GNU_SO
1010: 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a 23 69 66 URCE.#endif..#if
1020: 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 defined(__OpenB
1030: 53 44 5f 5f 29 20 26 26 20 21 64 65 66 69 6e 65 SD__) && !define
1040: 64 28 5f 42 53 44 5f 53 4f 55 52 43 45 29 0a 23 d(_BSD_SOURCE).#
1050: 20 64 65 66 69 6e 65 20 5f 42 53 44 5f 53 4f 55 define _BSD_SOU
1060: 52 43 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a RCE.#endif../*.*
1070: 2a 20 46 6f 72 20 4d 69 6e 47 57 2c 20 63 68 65 * For MinGW, che
1080: 63 6b 20 74 6f 20 73 65 65 20 69 66 20 77 65 20 ck to see if we
1090: 63 61 6e 20 69 6e 63 6c 75 64 65 20 74 68 65 20 can include the
10a0: 68 65 61 64 65 72 20 66 69 6c 65 20 63 6f 6e 74 header file cont
10b0: 61 69 6e 69 6e 67 20 69 74 73 0a 2a 2a 20 76 65 aining its.** ve
10c0: 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f rsion informatio
10d0: 6e 2c 20 61 6d 6f 6e 67 20 6f 74 68 65 72 20 74 n, among other t
10e0: 68 69 6e 67 73 2e 20 20 4e 6f 72 6d 61 6c 6c 79 hings. Normally
10f0: 2c 20 74 68 69 73 20 69 6e 74 65 72 6e 61 6c 20 , this internal
1100: 4d 69 6e 47 57 0a 2a 2a 20 68 65 61 64 65 72 20 MinGW.** header
1110: 66 69 6c 65 20 77 6f 75 6c 64 20 5b 6f 6e 6c 79 file would [only
1120: 5d 20 62 65 20 69 6e 63 6c 75 64 65 64 20 61 75 ] be included au
1130: 74 6f 6d 61 74 69 63 61 6c 6c 79 20 62 79 20 6f tomatically by o
1140: 74 68 65 72 20 4d 69 6e 47 57 20 68 65 61 64 65 ther MinGW heade
1150: 72 0a 2a 2a 20 66 69 6c 65 73 3b 20 68 6f 77 65 r.** files; howe
1160: 76 65 72 2c 20 74 68 65 20 63 6f 6e 74 61 69 6e ver, the contain
1170: 65 64 20 76 65 72 73 69 6f 6e 20 69 6e 66 6f 72 ed version infor
1180: 6d 61 74 69 6f 6e 20 69 73 20 6e 6f 77 20 72 65 mation is now re
1190: 71 75 69 72 65 64 20 62 79 20 74 68 69 73 0a 2a quired by this.*
11a0: 2a 20 68 65 61 64 65 72 20 66 69 6c 65 20 74 6f * header file to
11b0: 20 77 6f 72 6b 20 61 72 6f 75 6e 64 20 62 69 6e work around bin
11c0: 61 72 79 20 63 6f 6d 70 61 74 69 62 69 6c 69 74 ary compatibilit
11d0: 79 20 69 73 73 75 65 73 20 28 73 65 65 20 62 65 y issues (see be
11e0: 6c 6f 77 29 20 61 6e 64 0a 2a 2a 20 74 68 69 73 low) and.** this
11f0: 20 69 73 20 74 68 65 20 6f 6e 6c 79 20 6b 6e 6f is the only kno
1200: 77 6e 20 77 61 79 20 74 6f 20 72 65 6c 69 61 62 wn way to reliab
1210: 6c 79 20 6f 62 74 61 69 6e 20 69 74 2e 20 20 54 ly obtain it. T
1220: 68 69 73 20 65 6e 74 69 72 65 20 23 69 66 20 62 his entire #if b
1230: 6c 6f 63 6b 0a 2a 2a 20 77 6f 75 6c 64 20 62 65 lock.** would be
1240: 20 63 6f 6d 70 6c 65 74 65 6c 79 20 75 6e 6e 65 completely unne
1250: 63 65 73 73 61 72 79 20 69 66 20 74 68 65 72 65 cessary if there
1260: 20 77 61 73 20 61 6e 79 20 6f 74 68 65 72 20 77 was any other w
1270: 61 79 20 6f 66 20 64 65 74 65 63 74 69 6e 67 0a ay of detecting.
1280: 2a 2a 20 4d 69 6e 47 57 20 76 69 61 20 74 68 65 ** MinGW via the
1290: 69 72 20 70 72 65 70 72 6f 63 65 73 73 6f 72 20 ir preprocessor
12a0: 28 65 2e 67 2e 20 69 66 20 74 68 65 79 20 63 75 (e.g. if they cu
12b0: 73 74 6f 6d 69 7a 65 64 20 74 68 65 69 72 20 47 stomized their G
12c0: 43 43 20 74 6f 20 64 65 66 69 6e 65 0a 2a 2a 20 CC to define.**
12d0: 73 6f 6d 65 20 4d 69 6e 47 57 2d 73 70 65 63 69 some MinGW-speci
12e0: 66 69 63 20 6d 61 63 72 6f 73 29 2e 20 20 57 68 fic macros). Wh
12f0: 65 6e 20 63 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 en compiling for
1300: 20 4d 69 6e 47 57 2c 20 65 69 74 68 65 72 20 74 MinGW, either t
1310: 68 65 0a 2a 2a 20 5f 48 41 56 45 5f 4d 49 4e 47 he.** _HAVE_MING
1320: 57 5f 48 20 6f 72 20 5f 48 41 56 45 5f 5f 4d 49 W_H or _HAVE__MI
1330: 4e 47 57 5f 48 20 28 6e 6f 74 65 20 74 68 65 20 NGW_H (note the
1340: 65 78 74 72 61 20 75 6e 64 65 72 73 63 6f 72 65 extra underscore
1350: 29 20 6d 61 63 72 6f 20 6d 75 73 74 20 62 65 0a ) macro must be.
1360: 2a 2a 20 64 65 66 69 6e 65 64 3b 20 6f 74 68 65 ** defined; othe
1370: 72 77 69 73 65 2c 20 64 65 74 65 63 74 69 6f 6e rwise, detection
1380: 20 6f 66 20 63 6f 6e 64 69 74 69 6f 6e 73 20 73 of conditions s
1390: 70 65 63 69 66 69 63 20 74 6f 20 4d 69 6e 47 57 pecific to MinGW
13a0: 20 77 69 6c 6c 20 62 65 0a 2a 2a 20 64 69 73 61 will be.** disa
13b0: 62 6c 65 64 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 bled..*/.#if def
13c0: 69 6e 65 64 28 5f 48 41 56 45 5f 4d 49 4e 47 57 ined(_HAVE_MINGW
13d0: 5f 48 29 0a 23 20 69 6e 63 6c 75 64 65 20 22 6d _H).# include "m
13e0: 69 6e 67 77 2e 68 22 0a 23 65 6c 69 66 20 64 65 ingw.h".#elif de
13f0: 66 69 6e 65 64 28 5f 48 41 56 45 5f 5f 4d 49 4e fined(_HAVE__MIN
1400: 47 57 5f 48 29 0a 23 20 69 6e 63 6c 75 64 65 20 GW_H).# include
1410: 22 5f 6d 69 6e 67 77 2e 68 22 0a 23 65 6e 64 69 "_mingw.h".#endi
1420: 66 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 20 4d 69 6e f../*.** For Min
1430: 47 57 20 76 65 72 73 69 6f 6e 20 34 2e 78 20 28 GW version 4.x (
1440: 61 6e 64 20 68 69 67 68 65 72 29 2c 20 63 68 65 and higher), che
1450: 63 6b 20 74 6f 20 73 65 65 20 69 66 20 74 68 65 ck to see if the
1460: 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 _USE_32BIT_TIME
1470: 5f 54 0a 2a 2a 20 64 65 66 69 6e 65 20 69 73 20 _T.** define is
1480: 72 65 71 75 69 72 65 64 20 74 6f 20 6d 61 69 6e required to main
1490: 74 61 69 6e 20 62 69 6e 61 72 79 20 63 6f 6d 70 tain binary comp
14a0: 61 74 69 62 69 6c 69 74 79 20 77 69 74 68 20 74 atibility with t
14b0: 68 65 20 4d 53 56 43 20 72 75 6e 74 69 6d 65 0a he MSVC runtime.
14c0: 2a 2a 20 6c 69 62 72 61 72 79 20 69 6e 20 75 73 ** library in us
14d0: 65 20 28 65 2e 67 2e 20 66 6f 72 20 57 69 6e 64 e (e.g. for Wind
14e0: 6f 77 73 20 58 50 29 2e 0a 2a 2f 0a 23 69 66 20 ows XP)..*/.#if
14f0: 21 64 65 66 69 6e 65 64 28 5f 55 53 45 5f 33 32 !defined(_USE_32
1500: 42 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 20 21 BIT_TIME_T) && !
1510: 64 65 66 69 6e 65 64 28 5f 55 53 45 5f 36 34 42 defined(_USE_64B
1520: 49 54 5f 54 49 4d 45 5f 54 29 20 26 26 20 5c 0a IT_TIME_T) && \.
1530: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 57 49 4e defined(_WIN
1540: 33 32 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 32) && !defined(
1550: 5f 57 49 4e 36 34 29 20 26 26 20 5c 0a 20 20 20 _WIN64) && \.
1560: 20 64 65 66 69 6e 65 64 28 5f 5f 4d 49 4e 47 57 defined(__MINGW
1570: 5f 4d 41 4a 4f 52 5f 56 45 52 53 49 4f 4e 29 20 _MAJOR_VERSION)
1580: 26 26 20 5f 5f 4d 49 4e 47 57 5f 4d 41 4a 4f 52 && __MINGW_MAJOR
1590: 5f 56 45 52 53 49 4f 4e 20 3e 3d 20 34 20 26 26 _VERSION >= 4 &&
15a0: 20 5c 0a 20 20 20 20 64 65 66 69 6e 65 64 28 5f \. defined(_
15b0: 5f 4d 53 56 43 52 54 5f 5f 29 0a 23 20 64 65 66 _MSVCRT__).# def
15c0: 69 6e 65 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 ine _USE_32BIT_T
15d0: 49 4d 45 5f 54 0a 23 65 6e 64 69 66 0a 0a 2f 2a IME_T.#endif../*
15e0: 20 54 68 65 20 70 75 62 6c 69 63 20 53 51 4c 69 The public SQLi
15f0: 74 65 20 69 6e 74 65 72 66 61 63 65 2e 20 20 54 te interface. T
1600: 68 65 20 5f 46 49 4c 45 5f 4f 46 46 53 45 54 5f he _FILE_OFFSET_
1610: 42 49 54 53 20 6d 61 63 72 6f 20 6d 75 73 74 20 BITS macro must
1620: 61 70 70 65 61 72 0a 2a 2a 20 66 69 72 73 74 20 appear.** first
1630: 69 6e 20 51 4e 58 2e 20 20 41 6c 73 6f 2c 20 74 in QNX. Also, t
1640: 68 65 20 5f 55 53 45 5f 33 32 42 49 54 5f 54 49 he _USE_32BIT_TI
1650: 4d 45 5f 54 20 6d 61 63 72 6f 20 6d 75 73 74 20 ME_T macro must
1660: 61 70 70 65 61 72 20 66 69 72 73 74 20 66 6f 72 appear first for
1670: 0a 2a 2a 20 4d 69 6e 47 57 2e 0a 2a 2f 0a 23 69 .** MinGW..*/.#i
1680: 6e 63 6c 75 64 65 20 22 73 71 6c 69 74 65 33 2e nclude "sqlite3.
1690: 68 22 0a 0a 2f 2a 0a 2a 2a 20 49 6e 63 6c 75 64 h"../*.** Includ
16a0: 65 20 74 68 65 20 63 6f 6e 66 69 67 75 72 61 74 e the configurat
16b0: 69 6f 6e 20 68 65 61 64 65 72 20 6f 75 74 70 75 ion header outpu
16c0: 74 20 62 79 20 27 63 6f 6e 66 69 67 75 72 65 27 t by 'configure'
16d0: 20 69 66 20 77 65 27 72 65 20 75 73 69 6e 67 20 if we're using
16e0: 74 68 65 0a 2a 2a 20 61 75 74 6f 63 6f 6e 66 2d the.** autoconf-
16f0: 62 61 73 65 64 20 62 75 69 6c 64 0a 2a 2f 0a 23 based build.*/.#
1700: 69 66 64 65 66 20 5f 48 41 56 45 5f 53 51 4c 49 ifdef _HAVE_SQLI
1710: 54 45 5f 43 4f 4e 46 49 47 5f 48 0a 23 69 6e 63 TE_CONFIG_H.#inc
1720: 6c 75 64 65 20 22 63 6f 6e 66 69 67 2e 68 22 0a lude "config.h".
1730: 23 65 6e 64 69 66 0a 0a 23 69 6e 63 6c 75 64 65 #endif..#include
1740: 20 22 73 71 6c 69 74 65 4c 69 6d 69 74 2e 68 22 "sqliteLimit.h"
1750: 0a 0a 2f 2a 20 44 69 73 61 62 6c 65 20 6e 75 69 ../* Disable nui
1760: 73 61 6e 63 65 20 77 61 72 6e 69 6e 67 73 20 6f sance warnings o
1770: 6e 20 42 6f 72 6c 61 6e 64 20 63 6f 6d 70 69 6c n Borland compil
1780: 65 72 73 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e ers */.#if defin
1790: 65 64 28 5f 5f 42 4f 52 4c 41 4e 44 43 5f 5f 29 ed(__BORLANDC__)
17a0: 0a 23 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 72 .#pragma warn -r
17b0: 63 68 20 2f 2a 20 75 6e 72 65 61 63 68 61 62 6c ch /* unreachabl
17c0: 65 20 63 6f 64 65 20 2a 2f 0a 23 70 72 61 67 6d e code */.#pragm
17d0: 61 20 77 61 72 6e 20 2d 63 63 63 20 2f 2a 20 43 a warn -ccc /* C
17e0: 6f 6e 64 69 74 69 6f 6e 20 69 73 20 61 6c 77 61 ondition is alwa
17f0: 79 73 20 74 72 75 65 20 6f 72 20 66 61 6c 73 65 ys true or false
1800: 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 72 6e */.#pragma warn
1810: 20 2d 61 75 73 20 2f 2a 20 41 73 73 69 67 6e 65 -aus /* Assigne
1820: 64 20 76 61 6c 75 65 20 69 73 20 6e 65 76 65 72 d value is never
1830: 20 75 73 65 64 20 2a 2f 0a 23 70 72 61 67 6d 61 used */.#pragma
1840: 20 77 61 72 6e 20 2d 63 73 75 20 2f 2a 20 43 6f warn -csu /* Co
1850: 6d 70 61 72 69 6e 67 20 73 69 67 6e 65 64 20 61 mparing signed a
1860: 6e 64 20 75 6e 73 69 67 6e 65 64 20 2a 2f 0a 23 nd unsigned */.#
1870: 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 73 70 61 pragma warn -spa
1880: 20 2f 2a 20 53 75 73 70 69 63 69 6f 75 73 20 70 /* Suspicious p
1890: 6f 69 6e 74 65 72 20 61 72 69 74 68 6d 65 74 69 ointer arithmeti
18a0: 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a c */.#endif../*.
18b0: 2a 2a 20 49 6e 63 6c 75 64 65 20 73 74 61 6e 64 ** Include stand
18c0: 61 72 64 20 68 65 61 64 65 72 20 66 69 6c 65 73 ard header files
18d0: 20 61 73 20 6e 65 63 65 73 73 61 72 79 0a 2a 2f as necessary.*/
18e0: 0a 23 69 66 64 65 66 20 48 41 56 45 5f 53 54 44 .#ifdef HAVE_STD
18f0: 49 4e 54 5f 48 0a 23 69 6e 63 6c 75 64 65 20 3c INT_H.#include <
1900: 73 74 64 69 6e 74 2e 68 3e 0a 23 65 6e 64 69 66 stdint.h>.#endif
1910: 0a 23 69 66 64 65 66 20 48 41 56 45 5f 49 4e 54 .#ifdef HAVE_INT
1920: 54 59 50 45 53 5f 48 0a 23 69 6e 63 6c 75 64 65 TYPES_H.#include
1930: 20 3c 69 6e 74 74 79 70 65 73 2e 68 3e 0a 23 65 <inttypes.h>.#e
1940: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
1950: 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 following macros
1960: 20 61 72 65 20 75 73 65 64 20 74 6f 20 63 61 73 are used to cas
1970: 74 20 70 6f 69 6e 74 65 72 73 20 74 6f 20 69 6e t pointers to in
1980: 74 65 67 65 72 73 20 61 6e 64 0a 2a 2a 20 69 6e tegers and.** in
1990: 74 65 67 65 72 73 20 74 6f 20 70 6f 69 6e 74 65 tegers to pointe
19a0: 72 73 2e 20 20 54 68 65 20 77 61 79 20 79 6f 75 rs. The way you
19b0: 20 64 6f 20 74 68 69 73 20 76 61 72 69 65 73 20 do this varies
19c0: 66 72 6f 6d 20 6f 6e 65 20 63 6f 6d 70 69 6c 65 from one compile
19d0: 72 0a 2a 2a 20 74 6f 20 74 68 65 20 6e 65 78 74 r.** to the next
19e0: 2c 20 73 6f 20 77 65 20 68 61 76 65 20 64 65 76 , so we have dev
19f0: 65 6c 6f 70 65 64 20 74 68 65 20 66 6f 6c 6c 6f eloped the follo
1a00: 77 69 6e 67 20 73 65 74 20 6f 66 20 23 69 66 20 wing set of #if
1a10: 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a 20 74 6f statements.** to
1a20: 20 67 65 6e 65 72 61 74 65 20 61 70 70 72 6f 70 generate approp
1a30: 72 69 61 74 65 20 6d 61 63 72 6f 73 20 66 6f 72 riate macros for
1a40: 20 61 20 77 69 64 65 20 72 61 6e 67 65 20 6f 66 a wide range of
1a50: 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a 2a 0a 2a compilers..**.*
1a60: 2a 20 54 68 65 20 63 6f 72 72 65 63 74 20 22 41 * The correct "A
1a70: 4e 53 49 22 20 77 61 79 20 74 6f 20 64 6f 20 74 NSI" way to do t
1a80: 68 69 73 20 69 73 20 74 6f 20 75 73 65 20 74 68 his is to use th
1a90: 65 20 69 6e 74 70 74 72 5f 74 20 74 79 70 65 2e e intptr_t type.
1aa0: 0a 2a 2a 20 55 6e 66 6f 72 74 75 6e 61 74 65 6c .** Unfortunatel
1ab0: 79 2c 20 74 68 61 74 20 74 79 70 65 64 65 66 20 y, that typedef
1ac0: 69 73 20 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 is not available
1ad0: 20 6f 6e 20 61 6c 6c 20 63 6f 6d 70 69 6c 65 72 on all compiler
1ae0: 73 2c 20 6f 72 0a 2a 2a 20 69 66 20 69 74 20 69 s, or.** if it i
1af0: 73 20 61 76 61 69 6c 61 62 6c 65 2c 20 69 74 20 s available, it
1b00: 72 65 71 75 69 72 65 73 20 61 6e 20 23 69 6e 63 requires an #inc
1b10: 6c 75 64 65 20 6f 66 20 73 70 65 63 69 66 69 63 lude of specific
1b20: 20 68 65 61 64 65 72 73 0a 2a 2a 20 74 68 61 74 headers.** that
1b30: 20 76 61 72 79 20 66 72 6f 6d 20 6f 6e 65 20 6d vary from one m
1b40: 61 63 68 69 6e 65 20 74 6f 20 74 68 65 20 6e 65 achine to the ne
1b50: 78 74 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 xt..**.** Ticket
1b60: 20 23 33 38 36 30 3a 20 20 54 68 65 20 6c 6c 76 #3860: The llv
1b70: 6d 2d 67 63 63 2d 34 2e 32 20 63 6f 6d 70 69 6c m-gcc-4.2 compil
1b80: 65 72 20 66 72 6f 6d 20 41 70 70 6c 65 20 63 68 er from Apple ch
1b90: 6f 6b 65 73 20 6f 6e 0a 2a 2a 20 74 68 65 20 28 okes on.** the (
1ba0: 28 76 6f 69 64 2a 29 26 28 28 63 68 61 72 2a 29 (void*)&((char*)
1bb0: 30 29 5b 58 5d 29 20 63 6f 6e 73 74 72 75 63 74 0)[X]) construct
1bc0: 2e 20 20 42 75 74 20 4d 53 56 43 20 63 68 6f 6b . But MSVC chok
1bd0: 65 73 20 6f 6e 20 28 28 76 6f 69 64 2a 29 28 58 es on ((void*)(X
1be0: 29 29 2e 0a 2a 2a 20 53 6f 20 77 65 20 68 61 76 ))..** So we hav
1bf0: 65 20 74 6f 20 64 65 66 69 6e 65 20 74 68 65 20 e to define the
1c00: 6d 61 63 72 6f 73 20 69 6e 20 64 69 66 66 65 72 macros in differ
1c10: 65 6e 74 20 77 61 79 73 20 64 65 70 65 6e 64 69 ent ways dependi
1c20: 6e 67 20 6f 6e 20 74 68 65 0a 2a 2a 20 63 6f 6d ng on the.** com
1c30: 70 69 6c 65 72 2e 0a 2a 2f 0a 23 69 66 20 64 65 piler..*/.#if de
1c40: 66 69 6e 65 64 28 5f 5f 50 54 52 44 49 46 46 5f fined(__PTRDIFF_
1c50: 54 59 50 45 5f 5f 29 20 20 2f 2a 20 54 68 69 73 TYPE__) /* This
1c60: 20 63 61 73 65 20 73 68 6f 75 6c 64 20 77 6f 72 case should wor
1c70: 6b 20 66 6f 72 20 47 43 43 20 2a 2f 0a 23 20 64 k for GCC */.# d
1c80: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 efine SQLITE_INT
1c90: 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f _TO_PTR(X) ((vo
1ca0: 69 64 2a 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 id*)(__PTRDIFF_T
1cb0: 59 50 45 5f 5f 29 28 58 29 29 0a 23 20 64 65 66 YPE__)(X)).# def
1cc0: 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 ine SQLITE_PTR_T
1cd0: 4f 5f 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 O_INT(X) ((int)
1ce0: 28 5f 5f 50 54 52 44 49 46 46 5f 54 59 50 45 5f (__PTRDIFF_TYPE_
1cf0: 5f 29 28 58 29 29 0a 23 65 6c 69 66 20 21 64 65 _)(X)).#elif !de
1d00: 66 69 6e 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 20 fined(__GNUC__)
1d10: 20 20 20 20 20 20 2f 2a 20 57 6f 72 6b 73 20 66 /* Works f
1d20: 6f 72 20 63 6f 6d 70 69 6c 65 72 73 20 6f 74 68 or compilers oth
1d30: 65 72 20 74 68 61 6e 20 4c 4c 56 4d 20 2a 2f 0a er than LLVM */.
1d40: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
1d50: 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 INT_TO_PTR(X) (
1d60: 28 76 6f 69 64 2a 29 26 28 28 63 68 61 72 2a 29 (void*)&((char*)
1d70: 30 29 5b 58 5d 29 0a 23 20 64 65 66 69 6e 65 20 0)[X]).# define
1d80: 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e SQLITE_PTR_TO_IN
1d90: 54 28 58 29 20 20 28 28 69 6e 74 29 28 28 28 63 T(X) ((int)(((c
1da0: 68 61 72 2a 29 58 29 2d 28 63 68 61 72 2a 29 30 har*)X)-(char*)0
1db0: 29 29 0a 23 65 6c 69 66 20 64 65 66 69 6e 65 64 )).#elif defined
1dc0: 28 48 41 56 45 5f 53 54 44 49 4e 54 5f 48 29 20 (HAVE_STDINT_H)
1dd0: 20 20 2f 2a 20 55 73 65 20 74 68 69 73 20 63 61 /* Use this ca
1de0: 73 65 20 69 66 20 77 65 20 68 61 76 65 20 41 4e se if we have AN
1df0: 53 49 20 68 65 61 64 65 72 73 20 2a 2f 0a 23 20 SI headers */.#
1e00: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e define SQLITE_IN
1e10: 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 28 28 76 T_TO_PTR(X) ((v
1e20: 6f 69 64 2a 29 28 69 6e 74 70 74 72 5f 74 29 28 oid*)(intptr_t)(
1e30: 58 29 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c X)).# define SQL
1e40: 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 ITE_PTR_TO_INT(X
1e50: 29 20 20 28 28 69 6e 74 29 28 69 6e 74 70 74 72 ) ((int)(intptr
1e60: 5f 74 29 28 58 29 29 0a 23 65 6c 73 65 20 20 20 _t)(X)).#else
1e70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e80: 20 20 20 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 /* Genera
1e90: 74 65 73 20 61 20 77 61 72 6e 69 6e 67 20 2d 20 tes a warning -
1ea0: 62 75 74 20 69 74 20 61 6c 77 61 79 73 20 77 6f but it always wo
1eb0: 72 6b 73 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 rks */.# define
1ec0: 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 SQLITE_INT_TO_PT
1ed0: 52 28 58 29 20 20 28 28 76 6f 69 64 2a 29 28 58 R(X) ((void*)(X
1ee0: 29 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 )).# define SQLI
1ef0: 54 45 5f 50 54 52 5f 54 4f 5f 49 4e 54 28 58 29 TE_PTR_TO_INT(X)
1f00: 20 20 28 28 69 6e 74 29 28 58 29 29 0a 23 65 6e ((int)(X)).#en
1f10: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 dif../*.** A mac
1f20: 72 6f 20 74 6f 20 68 69 6e 74 20 74 6f 20 74 68 ro to hint to th
1f30: 65 20 63 6f 6d 70 69 6c 65 72 20 74 68 61 74 20 e compiler that
1f40: 61 20 66 75 6e 63 74 69 6f 6e 20 73 68 6f 75 6c a function shoul
1f50: 64 20 6e 6f 74 20 62 65 0a 2a 2a 20 69 6e 6c 69 d not be.** inli
1f60: 6e 65 64 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 ned..*/.#if defi
1f70: 6e 65 64 28 5f 5f 47 4e 55 43 5f 5f 29 0a 23 20 ned(__GNUC__).#
1f80: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e define SQLITE_N
1f90: 4f 49 4e 4c 49 4e 45 20 20 5f 5f 61 74 74 72 69 OINLINE __attri
1fa0: 62 75 74 65 5f 5f 28 28 6e 6f 69 6e 6c 69 6e 65 bute__((noinline
1fb0: 29 29 0a 23 65 6c 69 66 20 64 65 66 69 6e 65 64 )).#elif defined
1fc0: 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 20 5f 4d (_MSC_VER) && _M
1fd0: 53 43 5f 56 45 52 3e 3d 31 33 31 30 0a 23 20 20 SC_VER>=1310.#
1fe0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f define SQLITE_NO
1ff0: 49 4e 4c 49 4e 45 20 20 5f 5f 64 65 63 6c 73 70 INLINE __declsp
2000: 65 63 28 6e 6f 69 6e 6c 69 6e 65 29 0a 23 65 6c ec(noinline).#el
2010: 73 65 0a 23 20 20 64 65 66 69 6e 65 20 53 51 4c se.# define SQL
2020: 49 54 45 5f 4e 4f 49 4e 4c 49 4e 45 0a 23 65 6e ITE_NOINLINE.#en
2030: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 6b 65 20 dif../*.** Make
2040: 73 75 72 65 20 74 68 61 74 20 74 68 65 20 63 6f sure that the co
2050: 6d 70 69 6c 65 72 20 69 6e 74 72 69 6e 73 69 63 mpiler intrinsic
2060: 73 20 77 65 20 64 65 73 69 72 65 20 61 72 65 20 s we desire are
2070: 65 6e 61 62 6c 65 64 20 77 68 65 6e 0a 2a 2a 20 enabled when.**
2080: 63 6f 6d 70 69 6c 69 6e 67 20 77 69 74 68 20 61 compiling with a
2090: 6e 20 61 70 70 72 6f 70 72 69 61 74 65 20 76 65 n appropriate ve
20a0: 72 73 69 6f 6e 20 6f 66 20 4d 53 56 43 20 75 6e rsion of MSVC un
20b0: 6c 65 73 73 20 70 72 65 76 65 6e 74 65 64 20 62 less prevented b
20c0: 79 0a 2a 2a 20 74 68 65 20 53 51 4c 49 54 45 5f y.** the SQLITE_
20d0: 44 49 53 41 42 4c 45 5f 49 4e 54 52 49 4e 53 49 DISABLE_INTRINSI
20e0: 43 20 64 65 66 69 6e 65 2e 0a 2a 2f 0a 23 69 66 C define..*/.#if
20f0: 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
2100: 5f 44 49 53 41 42 4c 45 5f 49 4e 54 52 49 4e 53 _DISABLE_INTRINS
2110: 49 43 29 0a 23 20 20 69 66 20 64 65 66 69 6e 65 IC).# if define
2120: 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 20 5f d(_MSC_VER) && _
2130: 4d 53 43 5f 56 45 52 3e 3d 31 34 30 30 0a 23 20 MSC_VER>=1400.#
2140: 20 20 20 69 66 20 21 64 65 66 69 6e 65 64 28 5f if !defined(_
2150: 57 49 4e 33 32 5f 57 43 45 29 0a 23 20 20 20 20 WIN32_WCE).#
2160: 20 20 69 6e 63 6c 75 64 65 20 3c 69 6e 74 72 69 include <intri
2170: 6e 2e 68 3e 0a 23 20 20 20 20 20 20 70 72 61 67 n.h>.# prag
2180: 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 5f 62 79 ma intrinsic(_by
2190: 74 65 73 77 61 70 5f 75 73 68 6f 72 74 29 0a 23 teswap_ushort).#
21a0: 20 20 20 20 20 20 70 72 61 67 6d 61 20 69 6e 74 pragma int
21b0: 72 69 6e 73 69 63 28 5f 62 79 74 65 73 77 61 70 rinsic(_byteswap
21c0: 5f 75 6c 6f 6e 67 29 0a 23 20 20 20 20 20 20 70 _ulong).# p
21d0: 72 61 67 6d 61 20 69 6e 74 72 69 6e 73 69 63 28 ragma intrinsic(
21e0: 5f 52 65 61 64 57 72 69 74 65 42 61 72 72 69 65 _ReadWriteBarrie
21f0: 72 29 0a 23 20 20 20 20 65 6c 73 65 0a 23 20 20 r).# else.#
2200: 20 20 20 20 69 6e 63 6c 75 64 65 20 3c 63 6d 6e include <cmn
2210: 69 6e 74 72 69 6e 2e 68 3e 0a 23 20 20 20 20 65 intrin.h>.# e
2220: 6e 64 69 66 0a 23 20 20 65 6e 64 69 66 0a 23 65 ndif.# endif.#e
2230: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ndif../*.** The
2240: 53 51 4c 49 54 45 5f 54 48 52 45 41 44 53 41 46 SQLITE_THREADSAF
2250: 45 20 6d 61 63 72 6f 20 6d 75 73 74 20 62 65 20 E macro must be
2260: 64 65 66 69 6e 65 64 20 61 73 20 30 2c 20 31 2c defined as 0, 1,
2270: 20 6f 72 20 32 2e 0a 2a 2a 20 30 20 6d 65 61 6e or 2..** 0 mean
2280: 73 20 6d 75 74 65 78 65 73 20 61 72 65 20 70 65 s mutexes are pe
2290: 72 6d 61 6e 65 6e 74 6c 79 20 64 69 73 61 62 6c rmanently disabl
22a0: 65 20 61 6e 64 20 74 68 65 20 6c 69 62 72 61 72 e and the librar
22b0: 79 20 69 73 20 6e 65 76 65 72 0a 2a 2a 20 74 68 y is never.** th
22c0: 72 65 61 64 73 61 66 65 2e 20 20 31 20 6d 65 61 readsafe. 1 mea
22d0: 6e 73 20 74 68 65 20 6c 69 62 72 61 72 79 20 69 ns the library i
22e0: 73 20 73 65 72 69 61 6c 69 7a 65 64 20 77 68 69 s serialized whi
22f0: 63 68 20 69 73 20 74 68 65 20 68 69 67 68 65 73 ch is the highes
2300: 74 0a 2a 2a 20 6c 65 76 65 6c 20 6f 66 20 74 68 t.** level of th
2310: 72 65 61 64 73 61 66 65 74 79 2e 20 20 32 20 6d readsafety. 2 m
2320: 65 61 6e 73 20 74 68 65 20 6c 69 62 72 61 72 79 eans the library
2330: 20 69 73 20 6d 75 6c 74 69 74 68 72 65 61 64 65 is multithreade
2340: 64 20 2d 20 6d 75 6c 74 69 70 6c 65 0a 2a 2a 20 d - multiple.**
2350: 74 68 72 65 61 64 73 20 63 61 6e 20 75 73 65 20 threads can use
2360: 53 51 4c 69 74 65 20 61 73 20 6c 6f 6e 67 20 61 SQLite as long a
2370: 73 20 6e 6f 20 74 77 6f 20 74 68 72 65 61 64 73 s no two threads
2380: 20 74 72 79 20 74 6f 20 75 73 65 20 74 68 65 20 try to use the
2390: 73 61 6d 65 0a 2a 2a 20 64 61 74 61 62 61 73 65 same.** database
23a0: 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 74 20 74 connection at t
23b0: 68 65 20 73 61 6d 65 20 74 69 6d 65 2e 0a 2a 2a he same time..**
23c0: 0a 2a 2a 20 4f 6c 64 65 72 20 76 65 72 73 69 6f .** Older versio
23d0: 6e 73 20 6f 66 20 53 51 4c 69 74 65 20 75 73 65 ns of SQLite use
23e0: 64 20 61 6e 20 6f 70 74 69 6f 6e 61 6c 20 54 48 d an optional TH
23f0: 52 45 41 44 53 41 46 45 20 6d 61 63 72 6f 2e 0a READSAFE macro..
2400: 2a 2a 20 57 65 20 73 75 70 70 6f 72 74 20 74 68 ** We support th
2410: 61 74 20 66 6f 72 20 6c 65 67 61 63 79 2e 0a 2a at for legacy..*
2420: 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 /.#if !defined(S
2430: 51 4c 49 54 45 5f 54 48 52 45 41 44 53 41 46 45 QLITE_THREADSAFE
2440: 29 0a 23 20 69 66 20 64 65 66 69 6e 65 64 28 54 ).# if defined(T
2450: 48 52 45 41 44 53 41 46 45 29 0a 23 20 20 20 64 HREADSAFE).# d
2460: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 48 52 efine SQLITE_THR
2470: 45 41 44 53 41 46 45 20 54 48 52 45 41 44 53 41 EADSAFE THREADSA
2480: 46 45 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 FE.# else.# de
2490: 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 48 52 45 fine SQLITE_THRE
24a0: 41 44 53 41 46 45 20 31 20 2f 2a 20 49 4d 50 3a ADSAFE 1 /* IMP:
24b0: 20 52 2d 30 37 32 37 32 2d 32 32 33 30 39 20 2a R-07272-22309 *
24c0: 2f 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 /.# endif.#endif
24d0: 0a 0a 2f 2a 0a 2a 2a 20 50 6f 77 65 72 73 61 66 ../*.** Powersaf
24e0: 65 20 6f 76 65 72 77 72 69 74 65 20 69 73 20 6f e overwrite is o
24f0: 6e 20 62 79 20 64 65 66 61 75 6c 74 2e 20 20 42 n by default. B
2500: 75 74 20 63 61 6e 20 62 65 20 74 75 72 6e 65 64 ut can be turned
2510: 20 6f 66 66 20 75 73 69 6e 67 0a 2a 2a 20 74 68 off using.** th
2520: 65 20 2d 44 53 51 4c 49 54 45 5f 50 4f 57 45 52 e -DSQLITE_POWER
2530: 53 41 46 45 5f 4f 56 45 52 57 52 49 54 45 3d 30 SAFE_OVERWRITE=0
2540: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 command-line op
2550: 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 tion..*/.#ifndef
2560: 20 53 51 4c 49 54 45 5f 50 4f 57 45 52 53 41 46 SQLITE_POWERSAF
2570: 45 5f 4f 56 45 52 57 52 49 54 45 0a 23 20 64 65 E_OVERWRITE.# de
2580: 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 4f 57 45 fine SQLITE_POWE
2590: 52 53 41 46 45 5f 4f 56 45 52 57 52 49 54 45 20 RSAFE_OVERWRITE
25a0: 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 1.#endif../*.**
25b0: 45 56 49 44 45 4e 43 45 2d 4f 46 3a 20 52 2d 32 EVIDENCE-OF: R-2
25c0: 35 37 31 35 2d 33 37 30 37 32 20 4d 65 6d 6f 72 5715-37072 Memor
25d0: 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 74 61 y allocation sta
25e0: 74 69 73 74 69 63 73 20 61 72 65 20 65 6e 61 62 tistics are enab
25f0: 6c 65 64 20 62 79 0a 2a 2a 20 64 65 66 61 75 6c led by.** defaul
2600: 74 20 75 6e 6c 65 73 73 20 53 51 4c 69 74 65 20 t unless SQLite
2610: 69 73 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 is compiled with
2620: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
2630: 4d 45 4d 53 54 41 54 55 53 3d 30 20 69 6e 0a 2a MEMSTATUS=0 in.*
2640: 2a 20 77 68 69 63 68 20 63 61 73 65 20 6d 65 6d * which case mem
2650: 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 73 ory allocation s
2660: 74 61 74 69 73 74 69 63 73 20 61 72 65 20 64 69 tatistics are di
2670: 73 61 62 6c 65 64 20 62 79 20 64 65 66 61 75 6c sabled by defaul
2680: 74 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e t..*/.#if !defin
2690: 65 64 28 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ed(SQLITE_DEFAUL
26a0: 54 5f 4d 45 4d 53 54 41 54 55 53 29 0a 23 20 64 T_MEMSTATUS).# d
26b0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 efine SQLITE_DEF
26c0: 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 53 20 31 AULT_MEMSTATUS 1
26d0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 .#endif../*.** E
26e0: 78 61 63 74 6c 79 20 6f 6e 65 20 6f 66 20 74 68 xactly one of th
26f0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 e following macr
2700: 6f 73 20 6d 75 73 74 20 62 65 20 64 65 66 69 6e os must be defin
2710: 65 64 20 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a ed in order to.*
2720: 2a 20 73 70 65 63 69 66 79 20 77 68 69 63 68 20 * specify which
2730: 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f memory allocatio
2740: 6e 20 73 75 62 73 79 73 74 65 6d 20 74 6f 20 75 n subsystem to u
2750: 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 51 se..**.** SQ
2760: 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c LITE_SYSTEM_MALL
2770: 4f 43 20 20 20 20 20 20 20 20 20 20 2f 2f 20 55 OC // U
2780: 73 65 20 6e 6f 72 6d 61 6c 20 73 79 73 74 65 6d se normal system
2790: 20 6d 61 6c 6c 6f 63 28 29 0a 2a 2a 20 20 20 20 malloc().**
27a0: 20 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 SQLITE_WIN32_MA
27b0: 4c 4c 4f 43 20 20 20 20 20 20 20 20 20 20 20 2f LLOC /
27c0: 2f 20 55 73 65 20 57 69 6e 33 32 20 6e 61 74 69 / Use Win32 nati
27d0: 76 65 20 68 65 61 70 20 41 50 49 0a 2a 2a 20 20 ve heap API.**
27e0: 20 20 20 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d SQLITE_ZERO_M
27f0: 41 4c 4c 4f 43 20 20 20 20 20 20 20 20 20 20 20 ALLOC
2800: 20 2f 2f 20 55 73 65 20 61 20 73 74 75 62 20 61 // Use a stub a
2810: 6c 6c 6f 63 61 74 6f 72 20 74 68 61 74 20 61 6c llocator that al
2820: 77 61 79 73 20 66 61 69 6c 73 0a 2a 2a 20 20 20 ways fails.**
2830: 20 20 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 SQLITE_MEMDEBU
2840: 47 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 G
2850: 2f 2f 20 44 65 62 75 67 67 69 6e 67 20 76 65 72 // Debugging ver
2860: 73 69 6f 6e 20 6f 66 20 73 79 73 74 65 6d 20 6d sion of system m
2870: 61 6c 6c 6f 63 28 29 0a 2a 2a 0a 2a 2a 20 4f 6e alloc().**.** On
2880: 20 57 69 6e 64 6f 77 73 2c 20 69 66 20 74 68 65 Windows, if the
2890: 20 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 SQLITE_WIN32_MA
28a0: 4c 4c 4f 43 5f 56 41 4c 49 44 41 54 45 20 6d 61 LLOC_VALIDATE ma
28b0: 63 72 6f 20 69 73 20 64 65 66 69 6e 65 64 20 61 cro is defined a
28c0: 6e 64 20 74 68 65 0a 2a 2a 20 61 73 73 65 72 74 nd the.** assert
28d0: 28 29 20 6d 61 63 72 6f 20 69 73 20 65 6e 61 62 () macro is enab
28e0: 6c 65 64 2c 20 65 61 63 68 20 63 61 6c 6c 20 69 led, each call i
28f0: 6e 74 6f 20 74 68 65 20 57 69 6e 33 32 20 6e 61 nto the Win32 na
2900: 74 69 76 65 20 68 65 61 70 20 73 75 62 73 79 73 tive heap subsys
2910: 74 65 6d 0a 2a 2a 20 77 69 6c 6c 20 63 61 75 73 tem.** will caus
2920: 65 20 48 65 61 70 56 61 6c 69 64 61 74 65 20 74 e HeapValidate t
2930: 6f 20 62 65 20 63 61 6c 6c 65 64 2e 20 20 49 66 o be called. If
2940: 20 68 65 61 70 20 76 61 6c 69 64 61 74 69 6f 6e heap validation
2950: 20 73 68 6f 75 6c 64 20 66 61 69 6c 2c 20 61 6e should fail, an
2960: 0a 2a 2a 20 61 73 73 65 72 74 69 6f 6e 20 77 69 .** assertion wi
2970: 6c 6c 20 62 65 20 74 72 69 67 67 65 72 65 64 2e ll be triggered.
2980: 0a 2a 2a 0a 2a 2a 20 49 66 20 6e 6f 6e 65 20 6f .**.** If none o
2990: 66 20 74 68 65 20 61 62 6f 76 65 20 61 72 65 20 f the above are
29a0: 64 65 66 69 6e 65 64 2c 20 74 68 65 6e 20 73 65 defined, then se
29b0: 74 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f t SQLITE_SYSTEM_
29c0: 4d 41 4c 4c 4f 43 20 61 73 0a 2a 2a 20 74 68 65 MALLOC as.** the
29d0: 20 64 65 66 61 75 6c 74 2e 0a 2a 2f 0a 23 69 66 default..*/.#if
29e0: 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
29f0: 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 29 20 5c SYSTEM_MALLOC) \
2a00: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
2a10: 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c 4c 4f 43 ITE_WIN32_MALLOC
2a20: 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 ) \. + defined(
2a30: 53 51 4c 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c SQLITE_ZERO_MALL
2a40: 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 OC) \. + define
2a50: 64 28 53 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 d(SQLITE_MEMDEBU
2a60: 47 29 3e 31 0a 23 20 65 72 72 6f 72 20 22 54 77 G)>1.# error "Tw
2a70: 6f 20 6f 72 20 6d 6f 72 65 20 6f 66 20 74 68 65 o or more of the
2a80: 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f 6d 70 69 following compi
2a90: 6c 65 2d 74 69 6d 65 20 63 6f 6e 66 69 67 75 72 le-time configur
2aa0: 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 5c 0a 20 ation options\.
2ab0: 61 72 65 20 64 65 66 69 6e 65 64 20 62 75 74 20 are defined but
2ac0: 61 74 20 6d 6f 73 74 20 6f 6e 65 20 69 73 20 61 at most one is a
2ad0: 6c 6c 6f 77 65 64 3a 5c 0a 20 53 51 4c 49 54 45 llowed:\. SQLITE
2ae0: 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 2c 20 _SYSTEM_MALLOC,
2af0: 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d 41 4c SQLITE_WIN32_MAL
2b00: 4c 4f 43 2c 20 53 51 4c 49 54 45 5f 4d 45 4d 44 LOC, SQLITE_MEMD
2b10: 45 42 55 47 2c 5c 0a 20 53 51 4c 49 54 45 5f 5a EBUG,\. SQLITE_Z
2b20: 45 52 4f 5f 4d 41 4c 4c 4f 43 22 0a 23 65 6e 64 ERO_MALLOC".#end
2b30: 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 if.#if defined(S
2b40: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
2b50: 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e LOC) \. + defin
2b60: 65 64 28 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f ed(SQLITE_WIN32_
2b70: 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 MALLOC) \. + de
2b80: 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 fined(SQLITE_ZER
2b90: 4f 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 O_MALLOC) \. +
2ba0: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d defined(SQLITE_M
2bb0: 45 4d 44 45 42 55 47 29 3d 3d 30 0a 23 20 64 65 EMDEBUG)==0.# de
2bc0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 59 53 54 fine SQLITE_SYST
2bd0: 45 4d 5f 4d 41 4c 4c 4f 43 20 31 0a 23 65 6e 64 EM_MALLOC 1.#end
2be0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 53 51 4c if../*.** If SQL
2bf0: 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f ITE_MALLOC_SOFT_
2c00: 4c 49 4d 49 54 20 69 73 20 6e 6f 74 20 7a 65 72 LIMIT is not zer
2c10: 6f 2c 20 74 68 65 6e 20 74 72 79 20 74 6f 20 6b o, then try to k
2c20: 65 65 70 20 74 68 65 0a 2a 2a 20 73 69 7a 65 73 eep the.** sizes
2c30: 20 6f 66 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 of memory alloc
2c40: 61 74 69 6f 6e 73 20 62 65 6c 6f 77 20 74 68 69 ations below thi
2c50: 73 20 76 61 6c 75 65 20 77 68 65 72 65 20 70 6f s value where po
2c60: 73 73 69 62 6c 65 2e 0a 2a 2f 0a 23 69 66 20 21 ssible..*/.#if !
2c70: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d defined(SQLITE_M
2c80: 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 4d 49 54 ALLOC_SOFT_LIMIT
2c90: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
2ca0: 45 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f 4c 49 E_MALLOC_SOFT_LI
2cb0: 4d 49 54 20 31 30 32 34 0a 23 65 6e 64 69 66 0a MIT 1024.#endif.
2cc0: 0a 2f 2a 0a 2a 2a 20 57 65 20 6e 65 65 64 20 74 ./*.** We need t
2cd0: 6f 20 64 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f o define _XOPEN_
2ce0: 53 4f 55 52 43 45 20 61 73 20 66 6f 6c 6c 6f 77 SOURCE as follow
2cf0: 73 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e s in order to en
2d00: 61 62 6c 65 0a 2a 2a 20 72 65 63 75 72 73 69 76 able.** recursiv
2d10: 65 20 6d 75 74 65 78 65 73 20 6f 6e 20 6d 6f 73 e mutexes on mos
2d20: 74 20 55 6e 69 78 20 73 79 73 74 65 6d 73 20 61 t Unix systems a
2d30: 6e 64 20 66 63 68 6d 6f 64 28 29 20 6f 6e 20 4f nd fchmod() on O
2d40: 70 65 6e 42 53 44 2e 0a 2a 2a 20 42 75 74 20 5f penBSD..** But _
2d50: 58 4f 50 45 4e 5f 53 4f 55 52 43 45 20 64 65 66 XOPEN_SOURCE def
2d60: 69 6e 65 20 63 61 75 73 65 73 20 70 72 6f 62 6c ine causes probl
2d70: 65 6d 73 20 66 6f 72 20 4d 61 63 20 4f 53 20 58 ems for Mac OS X
2d80: 2c 20 73 6f 20 6f 6d 69 74 0a 2a 2a 20 69 74 2e , so omit.** it.
2d90: 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 .*/.#if !defined
2da0: 28 5f 58 4f 50 45 4e 5f 53 4f 55 52 43 45 29 20 (_XOPEN_SOURCE)
2db0: 26 26 20 21 64 65 66 69 6e 65 64 28 5f 5f 44 41 && !defined(__DA
2dc0: 52 57 49 4e 5f 5f 29 20 26 26 20 21 64 65 66 69 RWIN__) && !defi
2dd0: 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 0a 23 ned(__APPLE__).#
2de0: 20 20 64 65 66 69 6e 65 20 5f 58 4f 50 45 4e 5f define _XOPEN_
2df0: 53 4f 55 52 43 45 20 36 30 30 0a 23 65 6e 64 69 SOURCE 600.#endi
2e00: 66 0a 0a 2f 2a 0a 2a 2a 20 4e 44 45 42 55 47 20 f../*.** NDEBUG
2e10: 61 6e 64 20 53 51 4c 49 54 45 5f 44 45 42 55 47 and SQLITE_DEBUG
2e20: 20 61 72 65 20 6f 70 70 6f 73 69 74 65 73 2e 20 are opposites.
2e30: 20 49 74 20 73 68 6f 75 6c 64 20 61 6c 77 61 79 It should alway
2e40: 73 20 62 65 20 74 72 75 65 20 74 68 61 74 0a 2a s be true that.*
2e50: 2a 20 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 * defined(NDEBUG
2e60: 29 3d 3d 21 64 65 66 69 6e 65 64 28 53 51 4c 49 )==!defined(SQLI
2e70: 54 45 5f 44 45 42 55 47 29 2e 20 20 49 66 20 74 TE_DEBUG). If t
2e80: 68 69 73 20 69 73 20 6e 6f 74 20 63 75 72 72 65 his is not curre
2e90: 6e 74 6c 79 20 74 72 75 65 2c 0a 2a 2a 20 6d 61 ntly true,.** ma
2ea0: 6b 65 20 69 74 20 74 72 75 65 20 62 79 20 64 65 ke it true by de
2eb0: 66 69 6e 69 6e 67 20 6f 72 20 75 6e 64 65 66 69 fining or undefi
2ec0: 6e 69 6e 67 20 4e 44 45 42 55 47 2e 0a 2a 2a 0a ning NDEBUG..**.
2ed0: 2a 2a 20 53 65 74 74 69 6e 67 20 4e 44 45 42 55 ** Setting NDEBU
2ee0: 47 20 6d 61 6b 65 73 20 74 68 65 20 63 6f 64 65 G makes the code
2ef0: 20 73 6d 61 6c 6c 65 72 20 61 6e 64 20 66 61 73 smaller and fas
2f00: 74 65 72 20 62 79 20 64 69 73 61 62 6c 69 6e 67 ter by disabling
2f10: 20 74 68 65 0a 2a 2a 20 61 73 73 65 72 74 28 29 the.** assert()
2f20: 20 73 74 61 74 65 6d 65 6e 74 73 20 69 6e 20 74 statements in t
2f30: 68 65 20 63 6f 64 65 2e 20 20 53 6f 20 77 65 20 he code. So we
2f40: 77 61 6e 74 20 74 68 65 20 64 65 66 61 75 6c 74 want the default
2f50: 20 61 63 74 69 6f 6e 0a 2a 2a 20 74 6f 20 62 65 action.** to be
2f60: 20 66 6f 72 20 4e 44 45 42 55 47 20 74 6f 20 62 for NDEBUG to b
2f70: 65 20 73 65 74 20 61 6e 64 20 4e 44 45 42 55 47 e set and NDEBUG
2f80: 20 74 6f 20 62 65 20 75 6e 64 65 66 69 6e 65 64 to be undefined
2f90: 20 6f 6e 6c 79 20 69 66 20 53 51 4c 49 54 45 5f only if SQLITE_
2fa0: 44 45 42 55 47 0a 2a 2a 20 69 73 20 73 65 74 2e DEBUG.** is set.
2fb0: 20 20 54 68 75 73 20 4e 44 45 42 55 47 20 62 65 Thus NDEBUG be
2fc0: 63 6f 6d 65 73 20 61 6e 20 6f 70 74 2d 69 6e 20 comes an opt-in
2fd0: 72 61 74 68 65 72 20 74 68 61 6e 20 61 6e 20 6f rather than an o
2fe0: 70 74 2d 6f 75 74 0a 2a 2a 20 66 65 61 74 75 72 pt-out.** featur
2ff0: 65 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e e..*/.#if !defin
3000: 65 64 28 4e 44 45 42 55 47 29 20 26 26 20 21 64 ed(NDEBUG) && !d
3010: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 efined(SQLITE_DE
3020: 42 55 47 29 0a 23 20 64 65 66 69 6e 65 20 4e 44 BUG).# define ND
3030: 45 42 55 47 20 31 0a 23 65 6e 64 69 66 0a 23 69 EBUG 1.#endif.#i
3040: 66 20 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 f defined(NDEBUG
3050: 29 20 26 26 20 64 65 66 69 6e 65 64 28 53 51 4c ) && defined(SQL
3060: 49 54 45 5f 44 45 42 55 47 29 0a 23 20 75 6e 64 ITE_DEBUG).# und
3070: 65 66 20 4e 44 45 42 55 47 0a 23 65 6e 64 69 66 ef NDEBUG.#endif
3080: 0a 0a 2f 2a 0a 2a 2a 20 45 6e 61 62 6c 65 20 53 ../*.** Enable S
3090: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 QLITE_ENABLE_EXP
30a0: 4c 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 20 69 66 LAIN_COMMENTS if
30b0: 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 69 73 SQLITE_DEBUG is
30c0: 20 74 75 72 6e 65 64 20 6f 6e 2e 0a 2a 2f 0a 23 turned on..*/.#
30d0: 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 if !defined(SQLI
30e0: 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 TE_ENABLE_EXPLAI
30f0: 4e 5f 43 4f 4d 4d 45 4e 54 53 29 20 26 26 20 64 N_COMMENTS) && d
3100: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 efined(SQLITE_DE
3110: 42 55 47 29 0a 23 20 64 65 66 69 6e 65 20 53 51 BUG).# define SQ
3120: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 45 58 50 4c LITE_ENABLE_EXPL
3130: 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 20 31 0a 23 AIN_COMMENTS 1.#
3140: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
3150: 20 74 65 73 74 63 61 73 65 28 29 20 6d 61 63 72 testcase() macr
3160: 6f 20 69 73 20 75 73 65 64 20 74 6f 20 61 69 64 o is used to aid
3170: 20 69 6e 20 63 6f 76 65 72 61 67 65 20 74 65 73 in coverage tes
3180: 74 69 6e 67 2e 20 20 57 68 65 6e 0a 2a 2a 20 64 ting. When.** d
3190: 6f 69 6e 67 20 63 6f 76 65 72 61 67 65 20 74 65 oing coverage te
31a0: 73 74 69 6e 67 2c 20 74 68 65 20 63 6f 6e 64 69 sting, the condi
31b0: 74 69 6f 6e 20 69 6e 73 69 64 65 20 74 68 65 20 tion inside the
31c0: 61 72 67 75 6d 65 6e 74 20 74 6f 0a 2a 2a 20 74 argument to.** t
31d0: 65 73 74 63 61 73 65 28 29 20 6d 75 73 74 20 62 estcase() must b
31e0: 65 20 65 76 61 6c 75 61 74 65 64 20 62 6f 74 68 e evaluated both
31f0: 20 74 72 75 65 20 61 6e 64 20 66 61 6c 73 65 20 true and false
3200: 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 67 in order to.** g
3210: 65 74 20 66 75 6c 6c 20 62 72 61 6e 63 68 20 63 et full branch c
3220: 6f 76 65 72 61 67 65 2e 20 20 54 68 65 20 74 65 overage. The te
3230: 73 74 63 61 73 65 28 29 20 6d 61 63 72 6f 20 69 stcase() macro i
3240: 73 20 69 6e 73 65 72 74 65 64 0a 2a 2a 20 74 6f s inserted.** to
3250: 20 68 65 6c 70 20 65 6e 73 75 72 65 20 61 64 65 help ensure ade
3260: 71 75 61 74 65 20 74 65 73 74 20 63 6f 76 65 72 quate test cover
3270: 61 67 65 20 69 6e 20 70 6c 61 63 65 73 20 77 68 age in places wh
3280: 65 72 65 20 73 69 6d 70 6c 65 0a 2a 2a 20 63 6f ere simple.** co
3290: 6e 64 69 74 69 6f 6e 2f 64 65 63 69 73 69 6f 6e ndition/decision
32a0: 20 63 6f 76 65 72 61 67 65 20 69 73 20 69 6e 61 coverage is ina
32b0: 64 65 71 75 61 74 65 2e 20 20 46 6f 72 20 65 78 dequate. For ex
32c0: 61 6d 70 6c 65 2c 20 74 65 73 74 63 61 73 65 28 ample, testcase(
32d0: 29 0a 2a 2a 20 63 61 6e 20 62 65 20 75 73 65 64 ).** can be used
32e0: 20 74 6f 20 6d 61 6b 65 20 73 75 72 65 20 62 6f to make sure bo
32f0: 75 6e 64 61 72 79 20 76 61 6c 75 65 73 20 61 72 undary values ar
3300: 65 20 74 65 73 74 65 64 2e 20 20 46 6f 72 0a 2a e tested. For.*
3310: 2a 20 62 69 74 6d 61 73 6b 20 74 65 73 74 73 2c * bitmask tests,
3320: 20 74 65 73 74 63 61 73 65 28 29 20 63 61 6e 20 testcase() can
3330: 62 65 20 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 be used to make
3340: 73 75 72 65 20 65 61 63 68 20 62 69 74 0a 2a 2a sure each bit.**
3350: 20 69 73 20 73 69 67 6e 69 66 69 63 61 6e 74 20 is significant
3360: 61 6e 64 20 75 73 65 64 20 61 74 20 6c 65 61 73 and used at leas
3370: 74 20 6f 6e 63 65 2e 20 20 4f 6e 20 73 77 69 74 t once. On swit
3380: 63 68 20 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a ch statements.**
3390: 20 77 68 65 72 65 20 6d 75 6c 74 69 70 6c 65 20 where multiple
33a0: 63 61 73 65 73 20 67 6f 20 74 6f 20 74 68 65 20 cases go to the
33b0: 73 61 6d 65 20 62 6c 6f 63 6b 20 6f 66 20 63 6f same block of co
33c0: 64 65 2c 20 74 65 73 74 63 61 73 65 28 29 0a 2a de, testcase().*
33d0: 2a 20 63 61 6e 20 69 6e 73 75 72 65 20 74 68 61 * can insure tha
33e0: 74 20 61 6c 6c 20 63 61 73 65 73 20 61 72 65 20 t all cases are
33f0: 65 76 61 6c 75 61 74 65 64 2e 0a 2a 2a 0a 2a 2f evaluated..**.*/
3400: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 43 .#ifdef SQLITE_C
3410: 4f 56 45 52 41 47 45 5f 54 45 53 54 0a 20 20 76 OVERAGE_TEST. v
3420: 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 76 65 72 oid sqlite3Cover
3430: 61 67 65 28 69 6e 74 29 3b 0a 23 20 64 65 66 69 age(int);.# defi
3440: 6e 65 20 74 65 73 74 63 61 73 65 28 58 29 20 20 ne testcase(X)
3450: 69 66 28 20 58 20 29 7b 20 73 71 6c 69 74 65 33 if( X ){ sqlite3
3460: 43 6f 76 65 72 61 67 65 28 5f 5f 4c 49 4e 45 5f Coverage(__LINE_
3470: 5f 29 3b 20 7d 0a 23 65 6c 73 65 0a 23 20 64 65 _); }.#else.# de
3480: 66 69 6e 65 20 74 65 73 74 63 61 73 65 28 58 29 fine testcase(X)
3490: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
34a0: 68 65 20 54 45 53 54 4f 4e 4c 59 20 6d 61 63 72 he TESTONLY macr
34b0: 6f 20 69 73 20 75 73 65 64 20 74 6f 20 65 6e 63 o is used to enc
34c0: 6c 6f 73 65 20 76 61 72 69 61 62 6c 65 20 64 65 lose variable de
34d0: 63 6c 61 72 61 74 69 6f 6e 73 20 6f 72 0a 2a 2a clarations or.**
34e0: 20 6f 74 68 65 72 20 62 69 74 73 20 6f 66 20 63 other bits of c
34f0: 6f 64 65 20 74 68 61 74 20 61 72 65 20 6e 65 65 ode that are nee
3500: 64 65 64 20 74 6f 20 73 75 70 70 6f 72 74 20 74 ded to support t
3510: 68 65 20 61 72 67 75 6d 65 6e 74 73 0a 2a 2a 20 he arguments.**
3520: 77 69 74 68 69 6e 20 74 65 73 74 63 61 73 65 28 within testcase(
3530: 29 20 61 6e 64 20 61 73 73 65 72 74 28 29 20 6d ) and assert() m
3540: 61 63 72 6f 73 2e 0a 2a 2f 0a 23 69 66 20 21 64 acros..*/.#if !d
3550: 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 7c efined(NDEBUG) |
3560: 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 | defined(SQLITE
3570: 5f 43 4f 56 45 52 41 47 45 5f 54 45 53 54 29 0a _COVERAGE_TEST).
3580: 23 20 64 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c # define TESTONL
3590: 59 28 58 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 Y(X) X.#else.#
35a0: 64 65 66 69 6e 65 20 54 45 53 54 4f 4e 4c 59 28 define TESTONLY(
35b0: 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a X).#endif../*.**
35c0: 20 53 6f 6d 65 74 69 6d 65 73 20 77 65 20 6e 65 Sometimes we ne
35d0: 65 64 20 61 20 73 6d 61 6c 6c 20 61 6d 6f 75 6e ed a small amoun
35e0: 74 20 6f 66 20 63 6f 64 65 20 73 75 63 68 20 61 t of code such a
35f0: 73 20 61 20 76 61 72 69 61 62 6c 65 20 69 6e 69 s a variable ini
3600: 74 69 61 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 74 tialization.** t
3610: 6f 20 73 65 74 75 70 20 66 6f 72 20 61 20 6c 61 o setup for a la
3620: 74 65 72 20 61 73 73 65 72 74 28 29 20 73 74 61 ter assert() sta
3630: 74 65 6d 65 6e 74 2e 20 20 57 65 20 64 6f 20 6e tement. We do n
3640: 6f 74 20 77 61 6e 74 20 74 68 69 73 20 63 6f 64 ot want this cod
3650: 65 20 74 6f 0a 2a 2a 20 61 70 70 65 61 72 20 77 e to.** appear w
3660: 68 65 6e 20 61 73 73 65 72 74 28 29 20 69 73 20 hen assert() is
3670: 64 69 73 61 62 6c 65 64 2e 20 20 54 68 65 20 66 disabled. The f
3680: 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 20 69 ollowing macro i
3690: 73 20 74 68 65 72 65 66 6f 72 65 0a 2a 2a 20 75 s therefore.** u
36a0: 73 65 64 20 74 6f 20 63 6f 6e 74 61 69 6e 20 74 sed to contain t
36b0: 68 61 74 20 73 65 74 75 70 20 63 6f 64 65 2e 20 hat setup code.
36c0: 20 54 68 65 20 22 56 56 41 22 20 61 63 72 6f 6e The "VVA" acron
36d0: 79 6d 20 73 74 61 6e 64 73 20 66 6f 72 0a 2a 2a ym stands for.**
36e0: 20 22 56 65 72 69 66 69 63 61 74 69 6f 6e 2c 20 "Verification,
36f0: 56 61 6c 69 64 61 74 69 6f 6e 2c 20 61 6e 64 20 Validation, and
3700: 41 63 63 72 65 64 69 74 61 74 69 6f 6e 22 2e 20 Accreditation".
3710: 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 2c In other words,
3720: 20 74 68 65 0a 2a 2a 20 63 6f 64 65 20 77 69 74 the.** code wit
3730: 68 69 6e 20 56 56 41 5f 4f 4e 4c 59 28 29 20 77 hin VVA_ONLY() w
3740: 69 6c 6c 20 6f 6e 6c 79 20 72 75 6e 20 64 75 72 ill only run dur
3750: 69 6e 67 20 76 65 72 69 66 69 63 61 74 69 6f 6e ing verification
3760: 20 70 72 6f 63 65 73 73 65 73 2e 0a 2a 2f 0a 23 processes..*/.#
3770: 69 66 6e 64 65 66 20 4e 44 45 42 55 47 0a 23 20 ifndef NDEBUG.#
3780: 64 65 66 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 define VVA_ONLY(
3790: 58 29 20 20 58 0a 23 65 6c 73 65 0a 23 20 64 65 X) X.#else.# de
37a0: 66 69 6e 65 20 56 56 41 5f 4f 4e 4c 59 28 58 29 fine VVA_ONLY(X)
37b0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
37c0: 68 65 20 41 4c 57 41 59 53 20 61 6e 64 20 4e 45 he ALWAYS and NE
37d0: 56 45 52 20 6d 61 63 72 6f 73 20 73 75 72 72 6f VER macros surro
37e0: 75 6e 64 20 62 6f 6f 6c 65 61 6e 20 65 78 70 72 und boolean expr
37f0: 65 73 73 69 6f 6e 73 20 77 68 69 63 68 0a 2a 2a essions which.**
3800: 20 61 72 65 20 69 6e 74 65 6e 64 65 64 20 74 6f are intended to
3810: 20 61 6c 77 61 79 73 20 62 65 20 74 72 75 65 20 always be true
3820: 6f 72 20 66 61 6c 73 65 2c 20 72 65 73 70 65 63 or false, respec
3830: 74 69 76 65 6c 79 2e 20 20 53 75 63 68 0a 2a 2a tively. Such.**
3840: 20 65 78 70 72 65 73 73 69 6f 6e 73 20 63 6f 75 expressions cou
3850: 6c 64 20 62 65 20 6f 6d 69 74 74 65 64 20 66 72 ld be omitted fr
3860: 6f 6d 20 74 68 65 20 63 6f 64 65 20 63 6f 6d 70 om the code comp
3870: 6c 65 74 65 6c 79 2e 20 20 42 75 74 20 74 68 65 letely. But the
3880: 79 0a 2a 2a 20 61 72 65 20 69 6e 63 6c 75 64 65 y.** are include
3890: 64 20 69 6e 20 61 20 66 65 77 20 63 61 73 65 73 d in a few cases
38a0: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 65 6e 68 in order to enh
38b0: 61 6e 63 65 20 74 68 65 20 72 65 73 69 6c 69 65 ance the resilie
38c0: 6e 63 65 0a 2a 2a 20 6f 66 20 53 51 4c 69 74 65 nce.** of SQLite
38d0: 20 74 6f 20 75 6e 65 78 70 65 63 74 65 64 20 62 to unexpected b
38e0: 65 68 61 76 69 6f 72 20 2d 20 74 6f 20 6d 61 6b ehavior - to mak
38f0: 65 20 74 68 65 20 63 6f 64 65 20 22 73 65 6c 66 e the code "self
3900: 2d 68 65 61 6c 69 6e 67 22 0a 2a 2a 20 6f 72 20 -healing".** or
3910: 22 64 75 63 74 69 6c 65 22 20 72 61 74 68 65 72 "ductile" rather
3920: 20 74 68 61 6e 20 62 65 69 6e 67 20 22 62 72 69 than being "bri
3930: 74 74 6c 65 22 20 61 6e 64 20 63 72 61 73 68 69 ttle" and crashi
3940: 6e 67 20 61 74 20 74 68 65 20 66 69 72 73 74 0a ng at the first.
3950: 2a 2a 20 68 69 6e 74 20 6f 66 20 75 6e 70 6c 61 ** hint of unpla
3960: 6e 6e 65 64 20 62 65 68 61 76 69 6f 72 2e 0a 2a nned behavior..*
3970: 2a 0a 2a 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f *.** In other wo
3980: 72 64 73 2c 20 41 4c 57 41 59 53 20 61 6e 64 20 rds, ALWAYS and
3990: 4e 45 56 45 52 20 61 72 65 20 61 64 64 65 64 20 NEVER are added
39a0: 66 6f 72 20 64 65 66 65 6e 73 69 76 65 20 63 6f for defensive co
39b0: 64 65 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 64 de..**.** When d
39c0: 6f 69 6e 67 20 63 6f 76 65 72 61 67 65 20 74 65 oing coverage te
39d0: 73 74 69 6e 67 20 41 4c 57 41 59 53 20 61 6e 64 sting ALWAYS and
39e0: 20 4e 45 56 45 52 20 61 72 65 20 68 61 72 64 2d NEVER are hard-
39f0: 63 6f 64 65 64 20 74 6f 0a 2a 2a 20 62 65 20 74 coded to.** be t
3a00: 72 75 65 20 61 6e 64 20 66 61 6c 73 65 20 73 6f rue and false so
3a10: 20 74 68 61 74 20 74 68 65 20 75 6e 72 65 61 63 that the unreac
3a20: 68 61 62 6c 65 20 63 6f 64 65 20 74 68 65 79 20 hable code they
3a30: 73 70 65 63 69 66 79 20 77 69 6c 6c 0a 2a 2a 20 specify will.**
3a40: 6e 6f 74 20 62 65 20 63 6f 75 6e 74 65 64 20 61 not be counted a
3a50: 73 20 75 6e 74 65 73 74 65 64 20 63 6f 64 65 2e s untested code.
3a60: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
3a70: 53 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 5f SQLITE_COVERAGE_
3a80: 54 45 53 54 29 20 7c 7c 20 64 65 66 69 6e 65 64 TEST) || defined
3a90: 28 53 51 4c 49 54 45 5f 4d 55 54 41 54 49 4f 4e (SQLITE_MUTATION
3aa0: 5f 54 45 53 54 29 0a 23 20 64 65 66 69 6e 65 20 _TEST).# define
3ab0: 41 4c 57 41 59 53 28 58 29 20 20 20 20 20 20 28 ALWAYS(X) (
3ac0: 31 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 45 1).# define NEVE
3ad0: 52 28 58 29 20 20 20 20 20 20 20 28 30 29 0a 23 R(X) (0).#
3ae0: 65 6c 69 66 20 21 64 65 66 69 6e 65 64 28 4e 44 elif !defined(ND
3af0: 45 42 55 47 29 0a 23 20 64 65 66 69 6e 65 20 41 EBUG).# define A
3b00: 4c 57 41 59 53 28 58 29 20 20 20 20 20 20 28 28 LWAYS(X) ((
3b10: 58 29 3f 31 3a 28 61 73 73 65 72 74 28 30 29 2c X)?1:(assert(0),
3b20: 30 29 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 0)).# define NEV
3b30: 45 52 28 58 29 20 20 20 20 20 20 20 28 28 58 29 ER(X) ((X)
3b40: 3f 28 61 73 73 65 72 74 28 30 29 2c 31 29 3a 30 ?(assert(0),1):0
3b50: 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ).#else.# define
3b60: 20 41 4c 57 41 59 53 28 58 29 20 20 20 20 20 20 ALWAYS(X)
3b70: 28 58 29 0a 23 20 64 65 66 69 6e 65 20 4e 45 56 (X).# define NEV
3b80: 45 52 28 58 29 20 20 20 20 20 20 20 28 58 29 0a ER(X) (X).
3b90: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 6f #endif../*.** So
3ba0: 6d 65 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 75 72 me malloc failur
3bb0: 65 73 20 61 72 65 20 6f 6e 6c 79 20 70 6f 73 73 es are only poss
3bc0: 69 62 6c 65 20 69 66 20 53 51 4c 49 54 45 5f 54 ible if SQLITE_T
3bd0: 45 53 54 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 45 EST_REALLOC_STRE
3be0: 53 53 20 69 73 0a 2a 2a 20 64 65 66 69 6e 65 64 SS is.** defined
3bf0: 2e 20 20 57 65 20 6e 65 65 64 20 74 6f 20 64 65 . We need to de
3c00: 66 65 6e 64 20 61 67 61 69 6e 73 74 20 74 68 6f fend against tho
3c10: 73 65 20 66 61 69 6c 75 72 65 73 20 77 68 65 6e se failures when
3c20: 20 74 65 73 74 69 6e 67 20 77 69 74 68 0a 2a 2a testing with.**
3c30: 20 53 51 4c 49 54 45 5f 54 45 53 54 5f 52 45 41 SQLITE_TEST_REA
3c40: 4c 4c 4f 43 5f 53 54 52 45 53 53 2c 20 62 75 74 LLOC_STRESS, but
3c50: 20 77 65 20 64 6f 6e 27 74 20 77 61 6e 74 20 74 we don't want t
3c60: 68 65 20 75 6e 72 65 61 63 68 61 62 6c 65 20 62 he unreachable b
3c70: 72 61 6e 63 68 65 73 0a 2a 2a 20 64 75 72 69 6e ranches.** durin
3c80: 67 20 61 20 6e 6f 72 6d 61 6c 20 62 75 69 6c 64 g a normal build
3c90: 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 . The following
3ca0: 20 6d 61 63 72 6f 20 63 61 6e 20 62 65 20 75 73 macro can be us
3cb0: 65 64 20 74 6f 20 64 69 73 61 62 6c 65 20 74 65 ed to disable te
3cc0: 73 74 73 0a 2a 2a 20 74 68 61 74 20 61 72 65 20 sts.** that are
3cd0: 61 6c 77 61 79 73 20 66 61 6c 73 65 20 65 78 63 always false exc
3ce0: 65 70 74 20 77 68 65 6e 20 53 51 4c 49 54 45 5f ept when SQLITE_
3cf0: 54 45 53 54 5f 52 45 41 4c 4c 4f 43 5f 53 54 52 TEST_REALLOC_STR
3d00: 45 53 53 20 69 73 20 73 65 74 2e 0a 2a 2f 0a 23 ESS is set..*/.#
3d10: 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
3d20: 45 5f 54 45 53 54 5f 52 45 41 4c 4c 4f 43 5f 53 E_TEST_REALLOC_S
3d30: 54 52 45 53 53 29 0a 23 20 64 65 66 69 6e 65 20 TRESS).# define
3d40: 4f 4e 4c 59 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f ONLY_IF_REALLOC_
3d50: 53 54 52 45 53 53 28 58 29 20 20 28 58 29 0a 23 STRESS(X) (X).#
3d60: 65 6c 69 66 20 21 64 65 66 69 6e 65 64 28 4e 44 elif !defined(ND
3d70: 45 42 55 47 29 0a 23 20 64 65 66 69 6e 65 20 4f EBUG).# define O
3d80: 4e 4c 59 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f 53 NLY_IF_REALLOC_S
3d90: 54 52 45 53 53 28 58 29 20 20 28 28 58 29 3f 28 TRESS(X) ((X)?(
3da0: 61 73 73 65 72 74 28 30 29 2c 31 29 3a 30 29 0a assert(0),1):0).
3db0: 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 4f #else.# define O
3dc0: 4e 4c 59 5f 49 46 5f 52 45 41 4c 4c 4f 43 5f 53 NLY_IF_REALLOC_S
3dd0: 54 52 45 53 53 28 58 29 20 20 28 30 29 0a 23 65 TRESS(X) (0).#e
3de0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 63 6c ndif../*.** Decl
3df0: 61 72 61 74 69 6f 6e 73 20 75 73 65 64 20 66 6f arations used fo
3e00: 72 20 74 72 61 63 69 6e 67 20 74 68 65 20 6f 70 r tracing the op
3e10: 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d 20 69 erating system i
3e20: 6e 74 65 72 66 61 63 65 73 2e 0a 2a 2f 0a 23 69 nterfaces..*/.#i
3e30: 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 f defined(SQLITE
3e40: 5f 46 4f 52 43 45 5f 4f 53 5f 54 52 41 43 45 29 _FORCE_OS_TRACE)
3e50: 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 || defined(SQLI
3e60: 54 45 5f 54 45 53 54 29 20 7c 7c 20 5c 0a 20 20 TE_TEST) || \.
3e70: 20 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 (defined(SQLIT
3e80: 45 5f 44 45 42 55 47 29 20 26 26 20 53 51 4c 49 E_DEBUG) && SQLI
3e90: 54 45 5f 4f 53 5f 57 49 4e 29 0a 20 20 65 78 74 TE_OS_WIN). ext
3ea0: 65 72 6e 20 69 6e 74 20 73 71 6c 69 74 65 33 4f ern int sqlite3O
3eb0: 53 54 72 61 63 65 3b 0a 23 20 64 65 66 69 6e 65 STrace;.# define
3ec0: 20 4f 53 54 52 41 43 45 28 58 29 20 20 20 20 20 OSTRACE(X)
3ed0: 20 20 20 20 20 69 66 28 20 73 71 6c 69 74 65 33 if( sqlite3
3ee0: 4f 53 54 72 61 63 65 20 29 20 73 71 6c 69 74 65 OSTrace ) sqlite
3ef0: 33 44 65 62 75 67 50 72 69 6e 74 66 20 58 0a 23 3DebugPrintf X.#
3f00: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 48 define SQLITE_H
3f10: 41 56 45 5f 4f 53 5f 54 52 41 43 45 0a 23 65 6c AVE_OS_TRACE.#el
3f20: 73 65 0a 23 20 64 65 66 69 6e 65 20 4f 53 54 52 se.# define OSTR
3f30: 41 43 45 28 58 29 0a 23 20 75 6e 64 65 66 20 20 ACE(X).# undef
3f40: 53 51 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 SQLITE_HAVE_OS_T
3f50: 52 41 43 45 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a RACE.#endif../*.
3f60: 2a 2a 20 49 73 20 74 68 65 20 73 71 6c 69 74 65 ** Is the sqlite
3f70: 33 45 72 72 4e 61 6d 65 28 29 20 66 75 6e 63 74 3ErrName() funct
3f80: 69 6f 6e 20 6e 65 65 64 65 64 20 69 6e 20 74 68 ion needed in th
3f90: 65 20 62 75 69 6c 64 3f 20 20 43 75 72 72 65 6e e build? Curren
3fa0: 74 6c 79 2c 0a 2a 2a 20 69 74 20 69 73 20 6e 65 tly,.** it is ne
3fb0: 65 64 65 64 20 62 79 20 22 6d 75 74 65 78 5f 77 eded by "mutex_w
3fc0: 33 32 2e 63 22 20 28 77 68 65 6e 20 64 65 62 75 32.c" (when debu
3fd0: 67 67 69 6e 67 29 2c 20 22 6f 73 5f 77 69 6e 2e gging), "os_win.
3fe0: 63 22 20 28 77 68 65 6e 0a 2a 2a 20 4f 53 54 52 c" (when.** OSTR
3ff0: 41 43 45 20 69 73 20 65 6e 61 62 6c 65 64 29 2c ACE is enabled),
4000: 20 61 6e 64 20 62 79 20 73 65 76 65 72 61 6c 20 and by several
4010: 22 74 65 73 74 2a 2e 63 22 20 66 69 6c 65 73 20 "test*.c" files
4020: 28 77 68 69 63 68 20 61 72 65 0a 2a 2a 20 63 6f (which are.** co
4030: 6d 70 69 6c 65 64 20 75 73 69 6e 67 20 53 51 4c mpiled using SQL
4040: 49 54 45 5f 54 45 53 54 29 2e 0a 2a 2f 0a 23 69 ITE_TEST)..*/.#i
4050: 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 f defined(SQLITE
4060: 5f 48 41 56 45 5f 4f 53 5f 54 52 41 43 45 29 20 _HAVE_OS_TRACE)
4070: 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 || defined(SQLIT
4080: 45 5f 54 45 53 54 29 20 7c 7c 20 5c 0a 20 20 20 E_TEST) || \.
4090: 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 (defined(SQLITE
40a0: 5f 44 45 42 55 47 29 20 26 26 20 53 51 4c 49 54 _DEBUG) && SQLIT
40b0: 45 5f 4f 53 5f 57 49 4e 29 0a 23 20 64 65 66 69 E_OS_WIN).# defi
40c0: 6e 65 20 53 51 4c 49 54 45 5f 4e 45 45 44 5f 45 ne SQLITE_NEED_E
40d0: 52 52 5f 4e 41 4d 45 0a 23 65 6c 73 65 0a 23 20 RR_NAME.#else.#
40e0: 75 6e 64 65 66 20 20 53 51 4c 49 54 45 5f 4e 45 undef SQLITE_NE
40f0: 45 44 5f 45 52 52 5f 4e 41 4d 45 0a 23 65 6e 64 ED_ERR_NAME.#end
4100: 69 66 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 if../*.** SQLITE
4110: 5f 45 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f _ENABLE_EXPLAIN_
4120: 43 4f 4d 4d 45 4e 54 53 20 69 73 20 69 6e 63 6f COMMENTS is inco
4130: 6d 70 61 74 69 62 6c 65 20 77 69 74 68 20 53 51 mpatible with SQ
4140: 4c 49 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 LITE_OMIT_EXPLAI
4150: 4e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 N.*/.#ifdef SQLI
4160: 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a TE_OMIT_EXPLAIN.
4170: 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 # undef SQLITE_E
4180: 4e 41 42 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f NABLE_EXPLAIN_CO
4190: 4d 4d 45 4e 54 53 0a 23 65 6e 64 69 66 0a 0a 2f MMENTS.#endif../
41a0: 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 *.** Return true
41b0: 20 28 6e 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 74 (non-zero) if t
41c0: 68 65 20 69 6e 70 75 74 20 69 73 20 61 6e 20 69 he input is an i
41d0: 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 74 nteger that is t
41e0: 6f 6f 20 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 66 oo large.** to f
41f0: 69 74 20 69 6e 20 33 32 2d 62 69 74 73 2e 20 20 it in 32-bits.
4200: 54 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 This macro is us
4210: 65 64 20 69 6e 73 69 64 65 20 6f 66 20 76 61 72 ed inside of var
4220: 69 6f 75 73 20 74 65 73 74 63 61 73 65 28 29 0a ious testcase().
4230: 2a 2a 20 6d 61 63 72 6f 73 20 74 6f 20 76 65 72 ** macros to ver
4240: 69 66 79 20 74 68 61 74 20 77 65 20 68 61 76 65 ify that we have
4250: 20 74 65 73 74 65 64 20 53 51 4c 69 74 65 20 66 tested SQLite f
4260: 6f 72 20 6c 61 72 67 65 2d 66 69 6c 65 20 73 75 or large-file su
4270: 70 70 6f 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e pport..*/.#defin
4280: 65 20 49 53 5f 42 49 47 5f 49 4e 54 28 58 29 20 e IS_BIG_INT(X)
4290: 20 28 28 28 58 29 26 7e 28 69 36 34 29 30 78 66 (((X)&~(i64)0xf
42a0: 66 66 66 66 66 66 66 29 21 3d 30 29 0a 0a 2f 2a fffffff)!=0)../*
42b0: 0a 2a 2a 20 54 68 65 20 6d 61 63 72 6f 20 75 6e .** The macro un
42c0: 6c 69 6b 65 6c 79 28 29 20 69 73 20 61 20 68 69 likely() is a hi
42d0: 6e 74 20 74 68 61 74 20 73 75 72 72 6f 75 6e 64 nt that surround
42e0: 73 20 61 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 65 s a boolean.** e
42f0: 78 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 xpression that i
4300: 73 20 75 73 75 61 6c 6c 79 20 66 61 6c 73 65 2e s usually false.
4310: 20 20 4d 61 63 72 6f 20 6c 69 6b 65 6c 79 28 29 Macro likely()
4320: 20 73 75 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 20 surrounds.** a
4330: 62 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 69 boolean expressi
4340: 6f 6e 20 74 68 61 74 20 69 73 20 75 73 75 61 6c on that is usual
4350: 6c 79 20 74 72 75 65 2e 20 20 54 68 65 73 65 20 ly true. These
4360: 68 69 6e 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a 20 hints could,.**
4370: 69 6e 20 74 68 65 6f 72 79 2c 20 62 65 20 75 73 in theory, be us
4380: 65 64 20 62 79 20 74 68 65 20 63 6f 6d 70 69 6c ed by the compil
4390: 65 72 20 74 6f 20 67 65 6e 65 72 61 74 65 20 62 er to generate b
43a0: 65 74 74 65 72 20 63 6f 64 65 2c 20 62 75 74 0a etter code, but.
43b0: 2a 2a 20 63 75 72 72 65 6e 74 6c 79 20 74 68 65 ** currently the
43c0: 79 20 61 72 65 20 6a 75 73 74 20 63 6f 6d 6d 65 y are just comme
43d0: 6e 74 73 20 66 6f 72 20 68 75 6d 61 6e 20 72 65 nts for human re
43e0: 61 64 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e aders..*/.#defin
43f0: 65 20 6c 69 6b 65 6c 79 28 58 29 20 20 20 20 28 e likely(X) (
4400: 58 29 0a 23 64 65 66 69 6e 65 20 75 6e 6c 69 6b X).#define unlik
4410: 65 6c 79 28 58 29 20 20 28 58 29 0a 0a 23 69 6e ely(X) (X)..#in
4420: 63 6c 75 64 65 20 22 68 61 73 68 2e 68 22 0a 23 clude "hash.h".#
4430: 69 6e 63 6c 75 64 65 20 22 70 61 72 73 65 2e 68 include "parse.h
4440: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 ".#include <stdi
4450: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 o.h>.#include <s
4460: 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 tdlib.h>.#includ
4470: 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e e <string.h>.#in
4480: 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e clude <assert.h>
4490: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 64 65 .#include <stdde
44a0: 66 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 63 f.h>../*.** If c
44b0: 6f 6d 70 69 6c 69 6e 67 20 66 6f 72 20 61 20 70 ompiling for a p
44c0: 72 6f 63 65 73 73 6f 72 20 74 68 61 74 20 6c 61 rocessor that la
44d0: 63 6b 73 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 cks floating poi
44e0: 6e 74 20 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 73 nt support,.** s
44f0: 75 62 73 74 69 74 75 74 65 20 69 6e 74 65 67 65 ubstitute intege
4500: 72 20 66 6f 72 20 66 6c 6f 61 74 69 6e 67 2d 70 r for floating-p
4510: 6f 69 6e 74 0a 2a 2f 0a 23 69 66 64 65 66 20 53 oint.*/.#ifdef S
4520: 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 QLITE_OMIT_FLOAT
4530: 49 4e 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 ING_POINT.# defi
4540: 6e 65 20 64 6f 75 62 6c 65 20 73 71 6c 69 74 65 ne double sqlite
4550: 5f 69 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 20 _int64.# define
4560: 66 6c 6f 61 74 20 73 71 6c 69 74 65 5f 69 6e 74 float sqlite_int
4570: 36 34 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e 47 64.# define LONG
4580: 44 4f 55 42 4c 45 5f 54 59 50 45 20 73 71 6c 69 DOUBLE_TYPE sqli
4590: 74 65 5f 69 6e 74 36 34 0a 23 20 69 66 6e 64 65 te_int64.# ifnde
45a0: 66 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c f SQLITE_BIG_DBL
45b0: 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 .# define SQLI
45c0: 54 45 5f 42 49 47 5f 44 42 4c 20 28 28 28 73 71 TE_BIG_DBL (((sq
45d0: 6c 69 74 65 33 5f 69 6e 74 36 34 29 31 29 3c 3c lite3_int64)1)<<
45e0: 35 30 29 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 50).# endif.# de
45f0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54 fine SQLITE_OMIT
4600: 5f 44 41 54 45 54 49 4d 45 5f 46 55 4e 43 53 20 _DATETIME_FUNCS
4610: 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 1.# define SQLIT
4620: 45 5f 4f 4d 49 54 5f 54 52 41 43 45 20 31 0a 23 E_OMIT_TRACE 1.#
4630: 20 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 49 undef SQLITE_MI
4640: 58 45 44 5f 45 4e 44 49 41 4e 5f 36 34 42 49 54 XED_ENDIAN_64BIT
4650: 5f 46 4c 4f 41 54 0a 23 20 75 6e 64 65 66 20 53 _FLOAT.# undef S
4660: 51 4c 49 54 45 5f 48 41 56 45 5f 49 53 4e 41 4e QLITE_HAVE_ISNAN
4670: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
4680: 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 SQLITE_BIG_DBL.#
4690: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 define SQLITE_B
46a0: 49 47 5f 44 42 4c 20 28 31 65 39 39 29 0a 23 65 IG_DBL (1e99).#e
46b0: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 54 ndif../*.** OMIT
46c0: 5f 54 45 4d 50 44 42 20 69 73 20 73 65 74 20 74 _TEMPDB is set t
46d0: 6f 20 31 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d o 1 if SQLITE_OM
46e0: 49 54 5f 54 45 4d 50 44 42 20 69 73 20 64 65 66 IT_TEMPDB is def
46f0: 69 6e 65 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 66 ined, or 0.** af
4700: 74 65 72 77 61 72 64 2e 20 48 61 76 69 6e 67 20 terward. Having
4710: 74 68 69 73 20 6d 61 63 72 6f 20 61 6c 6c 6f 77 this macro allow
4720: 73 20 75 73 20 74 6f 20 63 61 75 73 65 20 74 68 s us to cause th
4730: 65 20 43 20 63 6f 6d 70 69 6c 65 72 0a 2a 2a 20 e C compiler.**
4740: 74 6f 20 6f 6d 69 74 20 63 6f 64 65 20 75 73 65 to omit code use
4750: 64 20 62 79 20 54 45 4d 50 20 74 61 62 6c 65 73 d by TEMP tables
4760: 20 77 69 74 68 6f 75 74 20 6d 65 73 73 79 20 23 without messy #
4770: 69 66 6e 64 65 66 20 73 74 61 74 65 6d 65 6e 74 ifndef statement
4780: 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c s..*/.#ifdef SQL
4790: 49 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 0a ITE_OMIT_TEMPDB.
47a0: 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d #define OMIT_TEM
47b0: 50 44 42 20 31 0a 23 65 6c 73 65 0a 23 64 65 66 PDB 1.#else.#def
47c0: 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 42 20 ine OMIT_TEMPDB
47d0: 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
47e0: 54 68 65 20 22 66 69 6c 65 20 66 6f 72 6d 61 74 The "file format
47f0: 22 20 6e 75 6d 62 65 72 20 69 73 20 61 6e 20 69 " number is an i
4800: 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 69 nteger that is i
4810: 6e 63 72 65 6d 65 6e 74 65 64 20 77 68 65 6e 65 ncremented whene
4820: 76 65 72 0a 2a 2a 20 74 68 65 20 56 44 42 45 2d ver.** the VDBE-
4830: 6c 65 76 65 6c 20 66 69 6c 65 20 66 6f 72 6d 61 level file forma
4840: 74 20 63 68 61 6e 67 65 73 2e 20 20 54 68 65 20 t changes. The
4850: 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 following macros
4860: 20 64 65 66 69 6e 65 20 74 68 65 0a 2a 2a 20 74 define the.** t
4870: 68 65 20 64 65 66 61 75 6c 74 20 66 69 6c 65 20 he default file
4880: 66 6f 72 6d 61 74 20 66 6f 72 20 6e 65 77 20 64 format for new d
4890: 61 74 61 62 61 73 65 73 20 61 6e 64 20 74 68 65 atabases and the
48a0: 20 6d 61 78 69 6d 75 6d 20 66 69 6c 65 20 66 6f maximum file fo
48b0: 72 6d 61 74 0a 2a 2a 20 74 68 61 74 20 74 68 65 rmat.** that the
48c0: 20 6c 69 62 72 61 72 79 20 63 61 6e 20 72 65 61 library can rea
48d0: 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 d..*/.#define SQ
48e0: 4c 49 54 45 5f 4d 41 58 5f 46 49 4c 45 5f 46 4f LITE_MAX_FILE_FO
48f0: 52 4d 41 54 20 34 0a 23 69 66 6e 64 65 66 20 53 RMAT 4.#ifndef S
4900: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 46 49 QLITE_DEFAULT_FI
4910: 4c 45 5f 46 4f 52 4d 41 54 0a 23 20 64 65 66 69 LE_FORMAT.# defi
4920: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
4930: 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 20 34 0a T_FILE_FORMAT 4.
4940: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 #endif../*.** De
4950: 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 termine whether
4960: 74 72 69 67 67 65 72 73 20 61 72 65 20 72 65 63 triggers are rec
4970: 75 72 73 69 76 65 20 62 79 20 64 65 66 61 75 6c ursive by defaul
4980: 74 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 0a t. This can be.
4990: 2a 2a 20 63 68 61 6e 67 65 64 20 61 74 20 72 75 ** changed at ru
49a0: 6e 2d 74 69 6d 65 20 75 73 69 6e 67 20 61 20 70 n-time using a p
49b0: 72 61 67 6d 61 2e 0a 2a 2f 0a 23 69 66 6e 64 65 ragma..*/.#ifnde
49c0: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
49d0: 5f 52 45 43 55 52 53 49 56 45 5f 54 52 49 47 47 _RECURSIVE_TRIGG
49e0: 45 52 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ERS.# define SQL
49f0: 49 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 43 55 ITE_DEFAULT_RECU
4a00: 52 53 49 56 45 5f 54 52 49 47 47 45 52 53 20 30 RSIVE_TRIGGERS 0
4a10: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 .#endif../*.** P
4a20: 72 6f 76 69 64 65 20 61 20 64 65 66 61 75 6c 74 rovide a default
4a30: 20 76 61 6c 75 65 20 66 6f 72 20 53 51 4c 49 54 value for SQLIT
4a40: 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 6e 20 E_TEMP_STORE in
4a50: 63 61 73 65 20 69 74 20 69 73 20 6e 6f 74 20 73 case it is not s
4a60: 70 65 63 69 66 69 65 64 0a 2a 2a 20 6f 6e 20 74 pecified.** on t
4a70: 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 0a he command-line.
4a80: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
4a90: 45 5f 54 45 4d 50 5f 53 54 4f 52 45 0a 23 20 64 E_TEMP_STORE.# d
4aa0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d efine SQLITE_TEM
4ab0: 50 5f 53 54 4f 52 45 20 31 0a 23 20 64 65 66 69 P_STORE 1.# defi
4ac0: 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 ne SQLITE_TEMP_S
4ad0: 54 4f 52 45 5f 78 63 20 31 20 20 2f 2a 20 45 78 TORE_xc 1 /* Ex
4ae0: 63 6c 75 64 65 20 66 72 6f 6d 20 63 74 69 6d 65 clude from ctime
4af0: 2e 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a .c */.#endif../*
4b00: 0a 2a 2a 20 49 66 20 6e 6f 20 76 61 6c 75 65 20 .** If no value
4b10: 68 61 73 20 62 65 65 6e 20 70 72 6f 76 69 64 65 has been provide
4b20: 64 20 66 6f 72 20 53 51 4c 49 54 45 5f 4d 41 58 d for SQLITE_MAX
4b30: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 2c _WORKER_THREADS,
4b40: 20 6f 72 20 69 66 0a 2a 2a 20 53 51 4c 49 54 45 or if.** SQLITE
4b50: 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 73 20 73 _TEMP_STORE is s
4b60: 65 74 20 74 6f 20 33 20 28 6e 65 76 65 72 20 75 et to 3 (never u
4b70: 73 65 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c se temporary fil
4b80: 65 73 29 2c 20 73 65 74 20 69 74 0a 2a 2a 20 74 es), set it.** t
4b90: 6f 20 7a 65 72 6f 2e 0a 2a 2f 0a 23 69 66 20 53 o zero..*/.#if S
4ba0: 51 4c 49 54 45 5f 54 45 4d 50 5f 53 54 4f 52 45 QLITE_TEMP_STORE
4bb0: 3d 3d 33 20 7c 7c 20 53 51 4c 49 54 45 5f 54 48 ==3 || SQLITE_TH
4bc0: 52 45 41 44 53 41 46 45 3d 3d 30 0a 23 20 75 6e READSAFE==0.# un
4bd0: 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 def SQLITE_MAX_W
4be0: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
4bf0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
4c00: 58 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 X_WORKER_THREADS
4c10: 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 0.#endif.#ifnde
4c20: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 f SQLITE_MAX_WOR
4c30: 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 KER_THREADS.# de
4c40: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
4c50: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 20 38 WORKER_THREADS 8
4c60: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
4c70: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 SQLITE_DEFAULT_W
4c80: 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 ORKER_THREADS.#
4c90: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 define SQLITE_DE
4ca0: 46 41 55 4c 54 5f 57 4f 52 4b 45 52 5f 54 48 52 FAULT_WORKER_THR
4cb0: 45 41 44 53 20 30 0a 23 65 6e 64 69 66 0a 23 69 EADS 0.#endif.#i
4cc0: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
4cd0: 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 3e _WORKER_THREADS>
4ce0: 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 4b 45 SQLITE_MAX_WORKE
4cf0: 52 5f 54 48 52 45 41 44 53 0a 23 20 75 6e 64 65 R_THREADS.# unde
4d00: 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f 52 f SQLITE_MAX_WOR
4d10: 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 20 64 65 KER_THREADS.# de
4d20: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
4d30: 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 53 20 53 WORKER_THREADS S
4d40: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 57 4f QLITE_DEFAULT_WO
4d50: 52 4b 45 52 5f 54 48 52 45 41 44 53 0a 23 65 6e RKER_THREADS.#en
4d60: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 dif../*.** The d
4d70: 65 66 61 75 6c 74 20 69 6e 69 74 69 61 6c 20 61 efault initial a
4d80: 6c 6c 6f 63 61 74 69 6f 6e 20 66 6f 72 20 74 68 llocation for th
4d90: 65 20 70 61 67 65 63 61 63 68 65 20 77 68 65 6e e pagecache when
4da0: 20 75 73 69 6e 67 20 73 65 70 61 72 61 74 65 0a using separate.
4db0: 2a 2a 20 70 61 67 65 63 61 63 68 65 73 20 66 6f ** pagecaches fo
4dc0: 72 20 65 61 63 68 20 64 61 74 61 62 61 73 65 20 r each database
4dd0: 63 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 41 20 70 connection. A p
4de0: 6f 73 69 74 69 76 65 20 6e 75 6d 62 65 72 20 69 ositive number i
4df0: 73 20 74 68 65 0a 2a 2a 20 6e 75 6d 62 65 72 20 s the.** number
4e00: 6f 66 20 70 61 67 65 73 2e 20 20 41 20 6e 65 67 of pages. A neg
4e10: 61 74 69 76 65 20 6e 75 6d 62 65 72 20 4e 20 74 ative number N t
4e20: 72 61 6e 73 6c 61 74 69 6f 6e 73 20 6d 65 61 6e ranslations mean
4e30: 73 20 74 68 61 74 20 61 20 62 75 66 66 65 72 0a s that a buffer.
4e40: 2a 2a 20 6f 66 20 2d 31 30 32 34 2a 4e 20 62 79 ** of -1024*N by
4e50: 74 65 73 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 tes is allocated
4e60: 20 61 6e 64 20 75 73 65 64 20 66 6f 72 20 61 73 and used for as
4e70: 20 6d 61 6e 79 20 70 61 67 65 73 20 61 73 20 69 many pages as i
4e80: 74 20 77 69 6c 6c 20 68 6f 6c 64 2e 0a 2a 2f 0a t will hold..*/.
4e90: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 44 #ifndef SQLITE_D
4ea0: 45 46 41 55 4c 54 5f 50 43 41 43 48 45 5f 49 4e EFAULT_PCACHE_IN
4eb0: 49 54 53 5a 0a 23 20 64 65 66 69 6e 65 20 53 51 ITSZ.# define SQ
4ec0: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 50 43 41 LITE_DEFAULT_PCA
4ed0: 43 48 45 5f 49 4e 49 54 53 5a 20 31 30 30 0a 23 CHE_INITSZ 100.#
4ee0: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 47 43 43 endif../*.** GCC
4ef0: 20 64 6f 65 73 20 6e 6f 74 20 64 65 66 69 6e 65 does not define
4f00: 20 74 68 65 20 6f 66 66 73 65 74 6f 66 28 29 20 the offsetof()
4f10: 6d 61 63 72 6f 20 73 6f 20 77 65 27 6c 6c 20 68 macro so we'll h
4f20: 61 76 65 20 74 6f 20 64 6f 20 69 74 0a 2a 2a 20 ave to do it.**
4f30: 6f 75 72 73 65 6c 76 65 73 2e 0a 2a 2f 0a 23 69 ourselves..*/.#i
4f40: 66 6e 64 65 66 20 6f 66 66 73 65 74 6f 66 0a 23 fndef offsetof.#
4f50: 64 65 66 69 6e 65 20 6f 66 66 73 65 74 6f 66 28 define offsetof(
4f60: 53 54 52 55 43 54 55 52 45 2c 46 49 45 4c 44 29 STRUCTURE,FIELD)
4f70: 20 28 28 69 6e 74 29 28 28 63 68 61 72 2a 29 26 ((int)((char*)&
4f80: 28 28 53 54 52 55 43 54 55 52 45 2a 29 30 29 2d ((STRUCTURE*)0)-
4f90: 3e 46 49 45 4c 44 29 29 0a 23 65 6e 64 69 66 0a >FIELD)).#endif.
4fa0: 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f ./*.** Macros to
4fb0: 20 63 6f 6d 70 75 74 65 20 6d 69 6e 69 6d 75 6d compute minimum
4fc0: 20 61 6e 64 20 6d 61 78 69 6d 75 6d 20 6f 66 20 and maximum of
4fd0: 74 77 6f 20 6e 75 6d 62 65 72 73 2e 0a 2a 2f 0a two numbers..*/.
4fe0: 23 69 66 6e 64 65 66 20 4d 49 4e 0a 23 20 64 65 #ifndef MIN.# de
4ff0: 66 69 6e 65 20 4d 49 4e 28 41 2c 42 29 20 28 28 fine MIN(A,B) ((
5000: 41 29 3c 28 42 29 3f 28 41 29 3a 28 42 29 29 0a A)<(B)?(A):(B)).
5010: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 4d #endif.#ifndef M
5020: 41 58 0a 23 20 64 65 66 69 6e 65 20 4d 41 58 28 AX.# define MAX(
5030: 41 2c 42 29 20 28 28 41 29 3e 28 42 29 3f 28 41 A,B) ((A)>(B)?(A
5040: 29 3a 28 42 29 29 0a 23 65 6e 64 69 66 0a 0a 2f ):(B)).#endif../
5050: 2a 0a 2a 2a 20 53 77 61 70 20 74 77 6f 20 6f 62 *.** Swap two ob
5060: 6a 65 63 74 73 20 6f 66 20 74 79 70 65 20 54 59 jects of type TY
5070: 50 45 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 PE..*/.#define S
5080: 57 41 50 28 54 59 50 45 2c 41 2c 42 29 20 7b 54 WAP(TYPE,A,B) {T
5090: 59 50 45 20 74 3d 41 3b 20 41 3d 42 3b 20 42 3d YPE t=A; A=B; B=
50a0: 74 3b 7d 0a 0a 2f 2a 0a 2a 2a 20 43 68 65 63 6b t;}../*.** Check
50b0: 20 74 6f 20 73 65 65 20 69 66 20 74 68 69 73 20 to see if this
50c0: 6d 61 63 68 69 6e 65 20 75 73 65 73 20 45 42 43 machine uses EBC
50d0: 44 49 43 2e 20 20 28 59 65 73 2c 20 62 65 6c 69 DIC. (Yes, beli
50e0: 65 76 65 20 69 74 20 6f 72 0a 2a 2a 20 6e 6f 74 eve it or.** not
50f0: 2c 20 74 68 65 72 65 20 61 72 65 20 73 74 69 6c , there are stil
5100: 6c 20 6d 61 63 68 69 6e 65 73 20 6f 75 74 20 74 l machines out t
5110: 68 65 72 65 20 74 68 61 74 20 75 73 65 20 45 42 here that use EB
5120: 43 44 49 43 2e 29 0a 2a 2f 0a 23 69 66 20 27 41 CDIC.).*/.#if 'A
5130: 27 20 3d 3d 20 27 5c 33 30 31 27 0a 23 20 64 65 ' == '\301'.# de
5140: 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 42 43 44 fine SQLITE_EBCD
5150: 49 43 20 31 0a 23 65 6c 73 65 0a 23 20 64 65 66 IC 1.#else.# def
5160: 69 6e 65 20 53 51 4c 49 54 45 5f 41 53 43 49 49 ine SQLITE_ASCII
5170: 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 1.#endif../*.**
5180: 20 49 6e 74 65 67 65 72 73 20 6f 66 20 6b 6e 6f Integers of kno
5190: 77 6e 20 73 69 7a 65 73 2e 20 20 54 68 65 73 65 wn sizes. These
51a0: 20 74 79 70 65 64 65 66 73 20 6d 69 67 68 74 20 typedefs might
51b0: 63 68 61 6e 67 65 20 66 6f 72 20 61 72 63 68 69 change for archi
51c0: 74 65 63 74 75 72 65 73 0a 2a 2a 20 77 68 65 72 tectures.** wher
51d0: 65 20 74 68 65 20 73 69 7a 65 73 20 76 65 72 79 e the sizes very
51e0: 2e 20 20 50 72 65 70 72 6f 63 65 73 73 6f 72 20 . Preprocessor
51f0: 6d 61 63 72 6f 73 20 61 72 65 20 61 76 61 69 6c macros are avail
5200: 61 62 6c 65 20 73 6f 20 74 68 61 74 20 74 68 65 able so that the
5210: 0a 2a 2a 20 74 79 70 65 73 20 63 61 6e 20 62 65 .** types can be
5220: 20 63 6f 6e 76 65 6e 69 65 6e 74 6c 79 20 72 65 conveniently re
5230: 64 65 66 69 6e 65 64 20 61 74 20 63 6f 6d 70 69 defined at compi
5240: 6c 65 2d 74 79 70 65 2e 20 20 4c 69 6b 65 20 74 le-type. Like t
5250: 68 69 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 his:.**.**
5260: 20 20 20 63 63 20 27 2d 44 55 49 4e 54 50 54 52 cc '-DUINTPTR
5270: 5f 54 59 50 45 3d 6c 6f 6e 67 20 6c 6f 6e 67 20 _TYPE=long long
5280: 69 6e 74 27 20 2e 2e 2e 0a 2a 2f 0a 23 69 66 6e int' ....*/.#ifn
5290: 64 65 66 20 55 49 4e 54 33 32 5f 54 59 50 45 0a def UINT32_TYPE.
52a0: 23 20 69 66 64 65 66 20 48 41 56 45 5f 55 49 4e # ifdef HAVE_UIN
52b0: 54 33 32 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 T32_T.# define
52c0: 55 49 4e 54 33 32 5f 54 59 50 45 20 75 69 6e 74 UINT32_TYPE uint
52d0: 33 32 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 32_t.# else.# d
52e0: 65 66 69 6e 65 20 55 49 4e 54 33 32 5f 54 59 50 efine UINT32_TYP
52f0: 45 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 0a 23 E unsigned int.#
5300: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 endif.#endif.#i
5310: 66 6e 64 65 66 20 55 49 4e 54 31 36 5f 54 59 50 fndef UINT16_TYP
5320: 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f 55 E.# ifdef HAVE_U
5330: 49 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 69 6e INT16_T.# defin
5340: 65 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 69 e UINT16_TYPE ui
5350: 6e 74 31 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 nt16_t.# else.#
5360: 20 64 65 66 69 6e 65 20 55 49 4e 54 31 36 5f 54 define UINT16_T
5370: 59 50 45 20 75 6e 73 69 67 6e 65 64 20 73 68 6f YPE unsigned sho
5380: 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a 23 rt int.# endif.#
5390: 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 4e endif.#ifndef IN
53a0: 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 65 66 T16_TYPE.# ifdef
53b0: 20 48 41 56 45 5f 49 4e 54 31 36 5f 54 0a 23 20 HAVE_INT16_T.#
53c0: 20 64 65 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 define INT16_TY
53d0: 50 45 20 69 6e 74 31 36 5f 74 0a 23 20 65 6c 73 PE int16_t.# els
53e0: 65 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 54 31 e.# define INT1
53f0: 36 5f 54 59 50 45 20 73 68 6f 72 74 20 69 6e 74 6_TYPE short int
5400: 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a .# endif.#endif.
5410: 23 69 66 6e 64 65 66 20 55 49 4e 54 38 5f 54 59 #ifndef UINT8_TY
5420: 50 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f PE.# ifdef HAVE_
5430: 55 49 4e 54 38 5f 54 0a 23 20 20 64 65 66 69 6e UINT8_T.# defin
5440: 65 20 55 49 4e 54 38 5f 54 59 50 45 20 75 69 6e e UINT8_TYPE uin
5450: 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 t8_t.# else.# d
5460: 65 66 69 6e 65 20 55 49 4e 54 38 5f 54 59 50 45 efine UINT8_TYPE
5470: 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 0a 23 unsigned char.#
5480: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 endif.#endif.#i
5490: 66 6e 64 65 66 20 49 4e 54 38 5f 54 59 50 45 0a fndef INT8_TYPE.
54a0: 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 4e 54 # ifdef HAVE_INT
54b0: 38 5f 54 0a 23 20 20 64 65 66 69 6e 65 20 49 4e 8_T.# define IN
54c0: 54 38 5f 54 59 50 45 20 69 6e 74 38 5f 74 0a 23 T8_TYPE int8_t.#
54d0: 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 else.# define
54e0: 49 4e 54 38 5f 54 59 50 45 20 73 69 67 6e 65 64 INT8_TYPE signed
54f0: 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a 23 65 char.# endif.#e
5500: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 4c 4f 4e ndif.#ifndef LON
5510: 47 44 4f 55 42 4c 45 5f 54 59 50 45 0a 23 20 64 GDOUBLE_TYPE.# d
5520: 65 66 69 6e 65 20 4c 4f 4e 47 44 4f 55 42 4c 45 efine LONGDOUBLE
5530: 5f 54 59 50 45 20 6c 6f 6e 67 20 64 6f 75 62 6c _TYPE long doubl
5540: 65 0a 23 65 6e 64 69 66 0a 74 79 70 65 64 65 66 e.#endif.typedef
5550: 20 73 71 6c 69 74 65 5f 69 6e 74 36 34 20 69 36 sqlite_int64 i6
5560: 34 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 38 4; /* 8
5570: 2d 62 79 74 65 20 73 69 67 6e 65 64 20 69 6e 74 -byte signed int
5580: 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 20 eger */.typedef
5590: 73 71 6c 69 74 65 5f 75 69 6e 74 36 34 20 75 36 sqlite_uint64 u6
55a0: 34 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 38 2d 4; /* 8-
55b0: 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 69 6e byte unsigned in
55c0: 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 66 teger */.typedef
55d0: 20 55 49 4e 54 33 32 5f 54 59 50 45 20 75 33 32 UINT32_TYPE u32
55e0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 34 ; /* 4
55f0: 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 69 -byte unsigned i
5600: 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 nteger */.typede
5610: 66 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 31 f UINT16_TYPE u1
5620: 36 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6; /*
5630: 32 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 2-byte unsigned
5640: 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 integer */.typed
5650: 65 66 20 49 4e 54 31 36 5f 54 59 50 45 20 69 31 ef INT16_TYPE i1
5660: 36 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 6; /*
5670: 20 32 2d 62 79 74 65 20 73 69 67 6e 65 64 20 69 2-byte signed i
5680: 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 65 nteger */.typede
5690: 66 20 55 49 4e 54 38 5f 54 59 50 45 20 75 38 3b f UINT8_TYPE u8;
56a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
56b0: 31 2d 62 79 74 65 20 75 6e 73 69 67 6e 65 64 20 1-byte unsigned
56c0: 69 6e 74 65 67 65 72 20 2a 2f 0a 74 79 70 65 64 integer */.typed
56d0: 65 66 20 49 4e 54 38 5f 54 59 50 45 20 69 38 3b ef INT8_TYPE i8;
56e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
56f0: 20 31 2d 62 79 74 65 20 73 69 67 6e 65 64 20 69 1-byte signed i
5700: 6e 74 65 67 65 72 20 2a 2f 0a 0a 2f 2a 0a 2a 2a nteger */../*.**
5710: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 55 33 32 20 SQLITE_MAX_U32
5720: 69 73 20 61 20 75 36 34 20 63 6f 6e 73 74 61 6e is a u64 constan
5730: 74 20 74 68 61 74 20 69 73 20 74 68 65 20 6d 61 t that is the ma
5740: 78 69 6d 75 6d 20 75 36 34 20 76 61 6c 75 65 0a ximum u64 value.
5750: 2a 2a 20 74 68 61 74 20 63 61 6e 20 62 65 20 73 ** that can be s
5760: 74 6f 72 65 64 20 69 6e 20 61 20 75 33 32 20 77 tored in a u32 w
5770: 69 74 68 6f 75 74 20 6c 6f 73 73 20 6f 66 20 64 ithout loss of d
5780: 61 74 61 2e 20 20 54 68 65 20 76 61 6c 75 65 0a ata. The value.
5790: 2a 2a 20 69 73 20 30 78 30 30 30 30 30 30 30 30 ** is 0x00000000
57a0: 66 66 66 66 66 66 66 66 2e 20 20 42 75 74 20 62 ffffffff. But b
57b0: 65 63 61 75 73 65 20 6f 66 20 71 75 69 72 6b 73 ecause of quirks
57c0: 20 6f 66 20 73 6f 6d 65 20 63 6f 6d 70 69 6c 65 of some compile
57d0: 72 73 2c 20 77 65 0a 2a 2a 20 68 61 76 65 20 74 rs, we.** have t
57e0: 6f 20 73 70 65 63 69 66 79 20 74 68 65 20 76 61 o specify the va
57f0: 6c 75 65 20 69 6e 20 74 68 65 20 6c 65 73 73 20 lue in the less
5800: 69 6e 74 75 69 74 69 76 65 20 6d 61 6e 6e 65 72 intuitive manner
5810: 20 73 68 6f 77 6e 3a 0a 2a 2f 0a 23 64 65 66 69 shown:.*/.#defi
5820: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 55 33 ne SQLITE_MAX_U3
5830: 32 20 20 28 28 28 28 75 36 34 29 31 29 3c 3c 33 2 ((((u64)1)<<3
5840: 32 29 2d 31 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 2)-1)../*.** The
5850: 20 64 61 74 61 74 79 70 65 20 75 73 65 64 20 74 datatype used t
5860: 6f 20 73 74 6f 72 65 20 65 73 74 69 6d 61 74 65 o store estimate
5870: 73 20 6f 66 20 74 68 65 20 6e 75 6d 62 65 72 20 s of the number
5880: 6f 66 20 72 6f 77 73 20 69 6e 20 61 0a 2a 2a 20 of rows in a.**
5890: 74 61 62 6c 65 20 6f 72 20 69 6e 64 65 78 2e 20 table or index.
58a0: 20 54 68 69 73 20 69 73 20 61 6e 20 75 6e 73 69 This is an unsi
58b0: 67 6e 65 64 20 69 6e 74 65 67 65 72 20 74 79 70 gned integer typ
58c0: 65 2e 20 20 46 6f 72 20 39 39 2e 39 25 20 6f 66 e. For 99.9% of
58d0: 0a 2a 2a 20 74 68 65 20 77 6f 72 6c 64 2c 20 61 .** the world, a
58e0: 20 33 32 2d 62 69 74 20 69 6e 74 65 67 65 72 20 32-bit integer
58f0: 69 73 20 73 75 66 66 69 63 69 65 6e 74 2e 20 20 is sufficient.
5900: 42 75 74 20 61 20 36 34 2d 62 69 74 20 69 6e 74 But a 64-bit int
5910: 65 67 65 72 0a 2a 2a 20 63 61 6e 20 62 65 20 75 eger.** can be u
5920: 73 65 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 sed at compile-t
5930: 69 6d 65 20 69 66 20 64 65 73 69 72 65 64 2e 0a ime if desired..
5940: 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
5950: 5f 36 34 42 49 54 5f 53 54 41 54 53 0a 20 74 79 _64BIT_STATS. ty
5960: 70 65 64 65 66 20 75 36 34 20 74 52 6f 77 63 6e pedef u64 tRowcn
5970: 74 3b 20 20 20 20 2f 2a 20 36 34 2d 62 69 74 20 t; /* 64-bit
5980: 6f 6e 6c 79 20 69 66 20 72 65 71 75 65 73 74 65 only if requeste
5990: 64 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d d at compile-tim
59a0: 65 20 2a 2f 0a 23 65 6c 73 65 0a 20 74 79 70 65 e */.#else. type
59b0: 64 65 66 20 75 33 32 20 74 52 6f 77 63 6e 74 3b def u32 tRowcnt;
59c0: 20 20 20 20 2f 2a 20 33 32 2d 62 69 74 20 69 73 /* 32-bit is
59d0: 20 74 68 65 20 64 65 66 61 75 6c 74 20 2a 2f 0a the default */.
59e0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 73 #endif../*.** Es
59f0: 74 69 6d 61 74 65 64 20 71 75 61 6e 74 69 74 69 timated quantiti
5a00: 65 73 20 75 73 65 64 20 66 6f 72 20 71 75 65 72 es used for quer
5a10: 79 20 70 6c 61 6e 6e 69 6e 67 20 61 72 65 20 73 y planning are s
5a20: 74 6f 72 65 64 20 61 73 20 31 36 2d 62 69 74 0a tored as 16-bit.
5a30: 2a 2a 20 6c 6f 67 61 72 69 74 68 6d 73 2e 20 20 ** logarithms.
5a40: 46 6f 72 20 71 75 61 6e 74 69 74 79 20 58 2c 20 For quantity X,
5a50: 74 68 65 20 76 61 6c 75 65 20 73 74 6f 72 65 64 the value stored
5a60: 20 69 73 20 31 30 2a 6c 6f 67 32 28 58 29 2e 20 is 10*log2(X).
5a70: 20 54 68 69 73 0a 2a 2a 20 67 69 76 65 73 20 61 This.** gives a
5a80: 20 70 6f 73 73 69 62 6c 65 20 72 61 6e 67 65 20 possible range
5a90: 6f 66 20 76 61 6c 75 65 73 20 6f 66 20 61 70 70 of values of app
5aa0: 72 6f 78 69 6d 61 74 65 6c 79 20 31 2e 30 65 39 roximately 1.0e9
5ab0: 38 36 20 74 6f 20 31 65 2d 39 38 36 2e 0a 2a 2a 86 to 1e-986..**
5ac0: 20 42 75 74 20 74 68 65 20 61 6c 6c 6f 77 65 64 But the allowed
5ad0: 20 76 61 6c 75 65 73 20 61 72 65 20 22 67 72 61 values are "gra
5ae0: 69 6e 79 22 2e 20 20 4e 6f 74 20 65 76 65 72 79 iny". Not every
5af0: 20 76 61 6c 75 65 20 69 73 20 72 65 70 72 65 73 value is repres
5b00: 65 6e 74 61 62 6c 65 2e 0a 2a 2a 20 46 6f 72 20 entable..** For
5b10: 65 78 61 6d 70 6c 65 2c 20 71 75 61 6e 74 69 74 example, quantit
5b20: 69 65 73 20 31 36 20 61 6e 64 20 31 37 20 61 72 ies 16 and 17 ar
5b30: 65 20 62 6f 74 68 20 72 65 70 72 65 73 65 6e 74 e both represent
5b40: 65 64 20 62 79 20 61 20 4c 6f 67 45 73 74 0a 2a ed by a LogEst.*
5b50: 2a 20 6f 66 20 34 30 2e 20 20 48 6f 77 65 76 65 * of 40. Howeve
5b60: 72 2c 20 73 69 6e 63 65 20 4c 6f 67 45 73 74 20 r, since LogEst
5b70: 71 75 61 6e 74 69 74 69 65 73 20 61 72 65 20 73 quantities are s
5b80: 75 70 70 6f 73 65 20 74 6f 20 62 65 20 65 73 74 uppose to be est
5b90: 69 6d 61 74 65 73 2c 0a 2a 2a 20 6e 6f 74 20 65 imates,.** not e
5ba0: 78 61 63 74 20 76 61 6c 75 65 73 2c 20 74 68 69 xact values, thi
5bb0: 73 20 69 6d 70 72 65 63 69 73 69 6f 6e 20 69 73 s imprecision is
5bc0: 20 6e 6f 74 20 61 20 70 72 6f 62 6c 65 6d 2e 0a not a problem..
5bd0: 2a 2a 0a 2a 2a 20 22 4c 6f 67 45 73 74 22 20 69 **.** "LogEst" i
5be0: 73 20 73 68 6f 72 74 20 66 6f 72 20 22 4c 6f 67 s short for "Log
5bf0: 61 72 69 74 68 6d 69 63 20 45 73 74 69 6d 61 74 arithmic Estimat
5c00: 65 22 2e 0a 2a 2a 0a 2a 2a 20 45 78 61 6d 70 6c e"..**.** Exampl
5c10: 65 73 3a 0a 2a 2a 20 20 20 20 20 20 31 20 2d 3e es:.** 1 ->
5c20: 20 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0
5c30: 32 30 20 2d 3e 20 34 33 20 20 20 20 20 20 20 20 20 -> 43
5c40: 20 20 31 30 30 30 30 20 2d 3e 20 31 33 32 0a 2a 10000 -> 132.*
5c50: 2a 20 20 20 20 20 20 32 20 2d 3e 20 31 30 20 20 * 2 -> 10
5c60: 20 20 20 20 20 20 20 20 20 20 20 32 35 20 2d 3e 25 ->
5c70: 20 34 36 20 20 20 20 20 20 20 20 20 20 32 35 30 46 250
5c80: 30 30 20 2d 3e 20 31 34 36 0a 2a 2a 20 20 20 20 00 -> 146.**
5c90: 20 20 33 20 2d 3e 20 31 36 20 20 20 20 20 20 20 3 -> 16
5ca0: 20 20 20 20 20 31 30 30 20 2d 3e 20 36 36 20 20 100 -> 66
5cb0: 20 20 20 20 20 20 31 30 30 30 30 30 30 20 2d 3e 1000000 ->
5cc0: 20 31 39 39 0a 2a 2a 20 20 20 20 20 20 34 20 2d 199.** 4 -
5cd0: 3e 20 32 30 20 20 20 20 20 20 20 20 20 20 20 31 > 20 1
5ce0: 30 30 30 20 2d 3e 20 39 39 20 20 20 20 20 20 20 000 -> 99
5cf0: 20 31 30 34 38 35 37 36 20 2d 3e 20 32 30 30 0a 1048576 -> 200.
5d00: 2a 2a 20 20 20 20 20 31 30 20 2d 3e 20 33 33 20 ** 10 -> 33
5d10: 20 20 20 20 20 20 20 20 20 20 31 30 32 34 20 2d 1024 -
5d20: 3e 20 31 30 30 20 20 20 20 34 32 39 34 39 36 37 > 100 4294967
5d30: 32 39 36 20 2d 3e 20 33 32 30 0a 2a 2a 0a 2a 2a 296 -> 320.**.**
5d40: 20 54 68 65 20 4c 6f 67 45 73 74 20 63 61 6e 20 The LogEst can
5d50: 62 65 20 6e 65 67 61 74 69 76 65 20 74 6f 20 69 be negative to i
5d60: 6e 64 69 63 61 74 65 20 66 72 61 63 74 69 6f 6e ndicate fraction
5d70: 61 6c 20 76 61 6c 75 65 73 2e 0a 2a 2a 20 45 78 al values..** Ex
5d80: 61 6d 70 6c 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 amples:.**.**
5d90: 20 30 2e 35 20 2d 3e 20 2d 31 30 20 20 20 20 20 0.5 -> -10
5da0: 20 20 20 20 20 20 30 2e 31 20 2d 3e 20 2d 33 33 0.1 -> -33
5db0: 20 20 20 20 20 20 20 20 30 2e 30 36 32 35 20 2d 0.0625 -
5dc0: 3e 20 2d 34 30 0a 2a 2f 0a 74 79 70 65 64 65 66 > -40.*/.typedef
5dd0: 20 49 4e 54 31 36 5f 54 59 50 45 20 4c 6f 67 45 INT16_TYPE LogE
5de0: 73 74 3b 0a 0a 2f 2a 0a 2a 2a 20 53 65 74 20 74 st;../*.** Set t
5df0: 68 65 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a he SQLITE_PTRSIZ
5e00: 45 20 6d 61 63 72 6f 20 74 6f 20 74 68 65 20 6e E macro to the n
5e10: 75 6d 62 65 72 20 6f 66 20 62 79 74 65 73 20 69 umber of bytes i
5e20: 6e 20 61 20 70 6f 69 6e 74 65 72 0a 2a 2f 0a 23 n a pointer.*/.#
5e30: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 50 54 ifndef SQLITE_PT
5e40: 52 53 49 5a 45 0a 23 20 69 66 20 64 65 66 69 6e RSIZE.# if defin
5e50: 65 64 28 5f 5f 53 49 5a 45 4f 46 5f 50 4f 49 4e ed(__SIZEOF_POIN
5e60: 54 45 52 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e TER__).# defin
5e70: 65 20 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 e SQLITE_PTRSIZE
5e80: 20 5f 5f 53 49 5a 45 4f 46 5f 50 4f 49 4e 54 45 __SIZEOF_POINTE
5e90: 52 5f 5f 0a 23 20 65 6c 69 66 20 64 65 66 69 6e R__.# elif defin
5ea0: 65 64 28 69 33 38 36 29 20 20 20 20 20 7c 7c 20 ed(i386) ||
5eb0: 64 65 66 69 6e 65 64 28 5f 5f 69 33 38 36 5f 5f defined(__i386__
5ec0: 29 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f ) || defined(_
5ed0: 4d 5f 49 58 38 36 29 20 7c 7c 20 20 20 20 5c 0a M_IX86) || \.
5ee0: 20 20 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f defined(_
5ef0: 4d 5f 41 52 4d 29 20 20 20 7c 7c 20 64 65 66 69 M_ARM) || defi
5f00: 6e 65 64 28 5f 5f 61 72 6d 5f 5f 29 20 20 20 20 ned(__arm__)
5f10: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 || defined(__x86
5f20: 29 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c ).# define SQL
5f30: 49 54 45 5f 50 54 52 53 49 5a 45 20 34 0a 23 20 ITE_PTRSIZE 4.#
5f40: 65 6c 73 65 0a 23 20 20 20 64 65 66 69 6e 65 20 else.# define
5f50: 53 51 4c 49 54 45 5f 50 54 52 53 49 5a 45 20 38 SQLITE_PTRSIZE 8
5f60: 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a .# endif.#endif.
5f70: 0a 2f 2a 20 54 68 65 20 75 70 74 72 20 74 79 70 ./* The uptr typ
5f80: 65 20 69 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 e is an unsigned
5f90: 20 69 6e 74 65 67 65 72 20 6c 61 72 67 65 20 65 integer large e
5fa0: 6e 6f 75 67 68 20 74 6f 20 68 6f 6c 64 20 61 20 nough to hold a
5fb0: 70 6f 69 6e 74 65 72 0a 2a 2f 0a 23 69 66 20 64 pointer.*/.#if d
5fc0: 65 66 69 6e 65 64 28 48 41 56 45 5f 53 54 44 49 efined(HAVE_STDI
5fd0: 4e 54 5f 48 29 0a 20 20 74 79 70 65 64 65 66 20 NT_H). typedef
5fe0: 75 69 6e 74 70 74 72 5f 74 20 75 70 74 72 3b 0a uintptr_t uptr;.
5ff0: 23 65 6c 69 66 20 53 51 4c 49 54 45 5f 50 54 52 #elif SQLITE_PTR
6000: 53 49 5a 45 3d 3d 34 0a 20 20 74 79 70 65 64 65 SIZE==4. typede
6010: 66 20 75 33 32 20 75 70 74 72 3b 0a 23 65 6c 73 f u32 uptr;.#els
6020: 65 0a 20 20 74 79 70 65 64 65 66 20 75 36 34 20 e. typedef u64
6030: 75 70 74 72 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a uptr;.#endif../*
6040: 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 57 .** The SQLITE_W
6050: 49 54 48 49 4e 28 50 2c 53 2c 45 29 20 6d 61 63 ITHIN(P,S,E) mac
6060: 72 6f 20 63 68 65 63 6b 73 20 74 6f 20 73 65 65 ro checks to see
6070: 20 69 66 20 70 6f 69 6e 74 65 72 20 50 20 70 6f if pointer P po
6080: 69 6e 74 73 20 74 6f 0a 2a 2a 20 73 6f 6d 65 74 ints to.** somet
6090: 68 69 6e 67 20 62 65 74 77 65 65 6e 20 53 20 28 hing between S (
60a0: 69 6e 63 6c 75 73 69 76 65 29 20 61 6e 64 20 45 inclusive) and E
60b0: 20 28 65 78 63 6c 75 73 69 76 65 29 2e 0a 2a 2a (exclusive)..**
60c0: 0a 2a 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 .** In other wor
60d0: 64 73 2c 20 53 20 69 73 20 61 20 62 75 66 66 65 ds, S is a buffe
60e0: 72 20 61 6e 64 20 45 20 69 73 20 61 20 70 6f 69 r and E is a poi
60f0: 6e 74 65 72 20 74 6f 20 74 68 65 20 66 69 72 73 nter to the firs
6100: 74 20 62 79 74 65 20 61 66 74 65 72 0a 2a 2a 20 t byte after.**
6110: 74 68 65 20 65 6e 64 20 6f 66 20 62 75 66 66 65 the end of buffe
6120: 72 20 53 2e 20 20 54 68 69 73 20 6d 61 63 72 6f r S. This macro
6130: 20 72 65 74 75 72 6e 73 20 74 72 75 65 20 69 66 returns true if
6140: 20 50 20 70 6f 69 6e 74 73 20 74 6f 20 73 6f 6d P points to som
6150: 65 74 68 69 6e 67 0a 2a 2a 20 63 6f 6e 74 61 69 ething.** contai
6160: 6e 65 64 20 77 69 74 68 69 6e 20 74 68 65 20 62 ned within the b
6170: 75 66 66 65 72 20 53 2e 0a 2a 2f 0a 23 64 65 66 uffer S..*/.#def
6180: 69 6e 65 20 53 51 4c 49 54 45 5f 57 49 54 48 49 ine SQLITE_WITHI
6190: 4e 28 50 2c 53 2c 45 29 20 28 28 28 75 70 74 72 N(P,S,E) (((uptr
61a0: 29 28 50 29 3e 3d 28 75 70 74 72 29 28 53 29 29 )(P)>=(uptr)(S))
61b0: 26 26 28 28 75 70 74 72 29 28 50 29 3c 28 75 70 &&((uptr)(P)<(up
61c0: 74 72 29 28 45 29 29 29 0a 0a 0a 2f 2a 0a 2a 2a tr)(E))).../*.**
61d0: 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 74 65 72 Macros to deter
61e0: 6d 69 6e 65 20 77 68 65 74 68 65 72 20 74 68 65 mine whether the
61f0: 20 6d 61 63 68 69 6e 65 20 69 73 20 62 69 67 20 machine is big
6200: 6f 72 20 6c 69 74 74 6c 65 20 65 6e 64 69 61 6e or little endian
6210: 2c 0a 2a 2a 20 61 6e 64 20 77 68 65 74 68 65 72 ,.** and whether
6220: 20 6f 72 20 6e 6f 74 20 74 68 61 74 20 64 65 74 or not that det
6230: 65 72 6d 69 6e 61 74 69 6f 6e 20 69 73 20 72 75 ermination is ru
6240: 6e 2d 74 69 6d 65 20 6f 72 20 63 6f 6d 70 69 6c n-time or compil
6250: 65 2d 74 69 6d 65 2e 0a 2a 2a 0a 2a 2a 20 46 6f e-time..**.** Fo
6260: 72 20 62 65 73 74 20 70 65 72 66 6f 72 6d 61 6e r best performan
6270: 63 65 2c 20 61 6e 20 61 74 74 65 6d 70 74 20 69 ce, an attempt i
6280: 73 20 6d 61 64 65 20 74 6f 20 67 75 65 73 73 20 s made to guess
6290: 61 74 20 74 68 65 20 62 79 74 65 2d 6f 72 64 65 at the byte-orde
62a0: 72 0a 2a 2a 20 75 73 69 6e 67 20 43 2d 70 72 65 r.** using C-pre
62b0: 70 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 processor macros
62c0: 2e 20 20 49 66 20 74 68 61 74 20 69 73 20 75 6e . If that is un
62d0: 73 75 63 63 65 73 73 66 75 6c 2c 20 6f 72 20 69 successful, or i
62e0: 66 0a 2a 2a 20 2d 44 53 51 4c 49 54 45 5f 52 55 f.** -DSQLITE_RU
62f0: 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 3d NTIME_BYTEORDER=
6300: 31 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 62 1 is set, then b
6310: 79 74 65 2d 6f 72 64 65 72 20 69 73 20 64 65 74 yte-order is det
6320: 65 72 6d 69 6e 65 64 0a 2a 2a 20 61 74 20 72 75 ermined.** at ru
6330: 6e 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 69 66 20 28 n-time..*/.#if (
6340: 64 65 66 69 6e 65 64 28 69 33 38 36 29 20 20 20 defined(i386)
6350: 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 69 || defined(__i
6360: 33 38 36 5f 5f 29 20 20 20 7c 7c 20 64 65 66 69 386__) || defi
6370: 6e 65 64 28 5f 4d 5f 49 58 38 36 29 20 7c 7c 20 ned(_M_IX86) ||
6380: 20 20 20 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 \. define
6390: 64 28 5f 5f 78 38 36 5f 36 34 29 20 7c 7c 20 64 d(__x86_64) || d
63a0: 65 66 69 6e 65 64 28 5f 5f 78 38 36 5f 36 34 5f efined(__x86_64_
63b0: 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d _) || defined(_M
63c0: 5f 58 36 34 29 20 20 7c 7c 20 20 20 20 5c 0a 20 _X64) || \.
63d0: 20 20 20 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 defined(_M_A
63e0: 4d 44 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 MD64) || defined
63f0: 28 5f 4d 5f 41 52 4d 29 20 20 20 20 20 7c 7c 20 (_M_ARM) ||
6400: 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 29 20 20 defined(__x86)
6410: 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 64 65 || \. de
6420: 66 69 6e 65 64 28 5f 5f 61 72 6d 5f 5f 29 29 20 fined(__arm__))
6430: 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
6440: 54 45 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f TE_RUNTIME_BYTEO
6450: 52 44 45 52 29 0a 23 20 64 65 66 69 6e 65 20 53 RDER).# define S
6460: 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 QLITE_BYTEORDER
6470: 20 20 20 31 32 33 34 0a 23 20 64 65 66 69 6e 65 1234.# define
6480: 20 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 SQLITE_BIGENDIA
6490: 4e 20 20 20 20 30 0a 23 20 64 65 66 69 6e 65 20 N 0.# define
64a0: 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 SQLITE_LITTLEEND
64b0: 49 41 4e 20 31 0a 23 20 64 65 66 69 6e 65 20 53 IAN 1.# define S
64c0: 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 QLITE_UTF16NATIV
64d0: 45 20 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4c E SQLITE_UTF16L
64e0: 45 0a 23 65 6e 64 69 66 0a 23 69 66 20 28 64 65 E.#endif.#if (de
64f0: 66 69 6e 65 64 28 73 70 61 72 63 29 20 20 20 20 fined(sparc)
6500: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 70 70 63 || defined(__ppc
6510: 5f 5f 29 29 20 20 5c 0a 20 20 20 20 26 26 20 21 __)) \. && !
6520: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 52 defined(SQLITE_R
6530: 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 44 45 52 UNTIME_BYTEORDER
6540: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
6550: 45 5f 42 59 54 45 4f 52 44 45 52 20 20 20 20 34 E_BYTEORDER 4
6560: 33 32 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 321.# define SQL
6570: 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 ITE_BIGENDIAN
6580: 20 31 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 1.# define SQLI
6590: 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 41 4e 20 TE_LITTLEENDIAN
65a0: 30 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 0.# define SQLIT
65b0: 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 20 53 E_UTF16NATIVE S
65c0: 51 4c 49 54 45 5f 55 54 46 31 36 42 45 0a 23 65 QLITE_UTF16BE.#e
65d0: 6e 64 69 66 0a 23 69 66 20 21 64 65 66 69 6e 65 ndif.#if !define
65e0: 64 28 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 d(SQLITE_BYTEORD
65f0: 45 52 29 0a 23 20 69 66 64 65 66 20 53 51 4c 49 ER).# ifdef SQLI
6600: 54 45 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a TE_AMALGAMATION.
6610: 20 20 63 6f 6e 73 74 20 69 6e 74 20 73 71 6c 69 const int sqli
6620: 74 65 33 6f 6e 65 20 3d 20 31 3b 0a 23 20 65 6c te3one = 1;.# el
6630: 73 65 0a 20 20 65 78 74 65 72 6e 20 63 6f 6e 73 se. extern cons
6640: 74 20 69 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 t int sqlite3one
6650: 3b 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 66 69 ;.# endif.# defi
6660: 6e 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 ne SQLITE_BYTEOR
6670: 44 45 52 20 20 20 20 30 20 20 20 20 20 2f 2a 20 DER 0 /*
6680: 30 20 6d 65 61 6e 73 20 22 75 6e 6b 6e 6f 77 6e 0 means "unknown
6690: 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 at compile-time
66a0: 22 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 " */.# define SQ
66b0: 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 LITE_BIGENDIAN
66c0: 20 20 28 2a 28 63 68 61 72 20 2a 29 28 26 73 71 (*(char *)(&sq
66d0: 6c 69 74 65 33 6f 6e 65 29 3d 3d 30 29 0a 23 20 lite3one)==0).#
66e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 49 define SQLITE_LI
66f0: 54 54 4c 45 45 4e 44 49 41 4e 20 28 2a 28 63 68 TTLEENDIAN (*(ch
6700: 61 72 20 2a 29 28 26 73 71 6c 69 74 65 33 6f 6e ar *)(&sqlite3on
6710: 65 29 3d 3d 31 29 0a 23 20 64 65 66 69 6e 65 20 e)==1).# define
6720: 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 49 SQLITE_UTF16NATI
6730: 56 45 20 20 28 53 51 4c 49 54 45 5f 42 49 47 45 VE (SQLITE_BIGE
6740: 4e 44 49 41 4e 3f 53 51 4c 49 54 45 5f 55 54 46 NDIAN?SQLITE_UTF
6750: 31 36 42 45 3a 53 51 4c 49 54 45 5f 55 54 46 31 16BE:SQLITE_UTF1
6760: 36 4c 45 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 6LE).#endif../*.
6770: 2a 2a 20 43 6f 6e 73 74 61 6e 74 73 20 66 6f 72 ** Constants for
6780: 20 74 68 65 20 6c 61 72 67 65 73 74 20 61 6e 64 the largest and
6790: 20 73 6d 61 6c 6c 65 73 74 20 70 6f 73 73 69 62 smallest possib
67a0: 6c 65 20 36 34 2d 62 69 74 20 73 69 67 6e 65 64 le 64-bit signed
67b0: 20 69 6e 74 65 67 65 72 73 2e 0a 2a 2a 20 54 68 integers..** Th
67c0: 65 73 65 20 6d 61 63 72 6f 73 20 61 72 65 20 64 ese macros are d
67d0: 65 73 69 67 6e 65 64 20 74 6f 20 77 6f 72 6b 20 esigned to work
67e0: 63 6f 72 72 65 63 74 6c 79 20 6f 6e 20 62 6f 74 correctly on bot
67f0: 68 20 33 32 2d 62 69 74 20 61 6e 64 20 36 34 2d h 32-bit and 64-
6800: 62 69 74 0a 2a 2a 20 63 6f 6d 70 69 6c 65 72 73 bit.** compilers
6810: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4c 41 52 ..*/.#define LAR
6820: 47 45 53 54 5f 49 4e 54 36 34 20 20 28 30 78 66 GEST_INT64 (0xf
6830: 66 66 66 66 66 66 66 7c 28 28 28 69 36 34 29 30 fffffff|(((i64)0
6840: 78 37 66 66 66 66 66 66 66 29 3c 3c 33 32 29 29 x7fffffff)<<32))
6850: 0a 23 64 65 66 69 6e 65 20 53 4d 41 4c 4c 45 53 .#define SMALLES
6860: 54 5f 49 4e 54 36 34 20 28 28 28 69 36 34 29 2d T_INT64 (((i64)-
6870: 31 29 20 2d 20 4c 41 52 47 45 53 54 5f 49 4e 54 1) - LARGEST_INT
6880: 36 34 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 75 6e 64 64)../*.** Round
6890: 20 75 70 20 61 20 6e 75 6d 62 65 72 20 74 6f 20 up a number to
68a0: 74 68 65 20 6e 65 78 74 20 6c 61 72 67 65 72 20 the next larger
68b0: 6d 75 6c 74 69 70 6c 65 20 6f 66 20 38 2e 20 20 multiple of 8.
68c0: 54 68 69 73 20 69 73 20 75 73 65 64 0a 2a 2a 20 This is used.**
68d0: 74 6f 20 66 6f 72 63 65 20 38 2d 62 79 74 65 20 to force 8-byte
68e0: 61 6c 69 67 6e 6d 65 6e 74 20 6f 6e 20 36 34 2d alignment on 64-
68f0: 62 69 74 20 61 72 63 68 69 74 65 63 74 75 72 65 bit architecture
6900: 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f s..*/.#define RO
6910: 55 4e 44 38 28 78 29 20 20 20 20 20 28 28 28 78 UND8(x) (((x
6920: 29 2b 37 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 )+7)&~7)../*.**
6930: 52 6f 75 6e 64 20 64 6f 77 6e 20 74 6f 20 74 68 Round down to th
6940: 65 20 6e 65 61 72 65 73 74 20 6d 75 6c 74 69 70 e nearest multip
6950: 6c 65 20 6f 66 20 38 0a 2a 2f 0a 23 64 65 66 69 le of 8.*/.#defi
6960: 6e 65 20 52 4f 55 4e 44 44 4f 57 4e 38 28 78 29 ne ROUNDDOWN8(x)
6970: 20 28 28 78 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a ((x)&~7)../*.**
6980: 20 41 73 73 65 72 74 20 74 68 61 74 20 74 68 65 Assert that the
6990: 20 70 6f 69 6e 74 65 72 20 58 20 69 73 20 61 6c pointer X is al
69a0: 69 67 6e 65 64 20 74 6f 20 61 6e 20 38 2d 62 79 igned to an 8-by
69b0: 74 65 20 62 6f 75 6e 64 61 72 79 2e 20 20 54 68 te boundary. Th
69c0: 69 73 0a 2a 2a 20 6d 61 63 72 6f 20 69 73 20 75 is.** macro is u
69d0: 73 65 64 20 6f 6e 6c 79 20 77 69 74 68 69 6e 20 sed only within
69e0: 61 73 73 65 72 74 28 29 20 74 6f 20 76 65 72 69 assert() to veri
69f0: 66 79 20 74 68 61 74 20 74 68 65 20 63 6f 64 65 fy that the code
6a00: 20 67 65 74 73 0a 2a 2a 20 61 6c 6c 20 61 6c 69 gets.** all ali
6a10: 67 6e 6d 65 6e 74 20 72 65 73 74 72 69 63 74 69 gnment restricti
6a20: 6f 6e 73 20 63 6f 72 72 65 63 74 2e 0a 2a 2a 0a ons correct..**.
6a30: 2a 2a 20 45 78 63 65 70 74 2c 20 69 66 20 53 51 ** Except, if SQ
6a40: 4c 49 54 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 LITE_4_BYTE_ALIG
6a50: 4e 45 44 5f 4d 41 4c 4c 4f 43 20 69 73 20 64 65 NED_MALLOC is de
6a60: 66 69 6e 65 64 2c 20 74 68 65 6e 20 74 68 65 0a fined, then the.
6a70: 2a 2a 20 75 6e 64 65 72 6c 79 69 6e 67 20 6d 61 ** underlying ma
6a80: 6c 6c 6f 63 28 29 20 69 6d 70 6c 65 6d 65 6e 74 lloc() implement
6a90: 61 74 69 6f 6e 20 6d 69 67 68 74 20 72 65 74 75 ation might retu
6aa0: 72 6e 20 75 73 20 34 2d 62 79 74 65 20 61 6c 69 rn us 4-byte ali
6ab0: 67 6e 65 64 0a 2a 2a 20 70 6f 69 6e 74 65 72 73 gned.** pointers
6ac0: 2e 20 20 49 6e 20 74 68 61 74 20 63 61 73 65 2c . In that case,
6ad0: 20 6f 6e 6c 79 20 76 65 72 69 66 79 20 34 2d 62 only verify 4-b
6ae0: 79 74 65 20 61 6c 69 67 6e 6d 65 6e 74 2e 0a 2a yte alignment..*
6af0: 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
6b00: 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 4_BYTE_ALIGNED_M
6b10: 41 4c 4c 4f 43 0a 23 20 64 65 66 69 6e 65 20 45 ALLOC.# define E
6b20: 49 47 48 54 5f 42 59 54 45 5f 41 4c 49 47 4e 4d IGHT_BYTE_ALIGNM
6b30: 45 4e 54 28 58 29 20 20 20 28 28 28 28 63 68 61 ENT(X) ((((cha
6b40: 72 2a 29 28 58 29 20 2d 20 28 63 68 61 72 2a 29 r*)(X) - (char*)
6b50: 30 29 26 33 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 0)&3)==0).#else.
6b60: 23 20 64 65 66 69 6e 65 20 45 49 47 48 54 5f 42 # define EIGHT_B
6b70: 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 58 29 YTE_ALIGNMENT(X)
6b80: 20 20 20 28 28 28 28 63 68 61 72 2a 29 28 58 29 ((((char*)(X)
6b90: 20 2d 20 28 63 68 61 72 2a 29 30 29 26 37 29 3d - (char*)0)&7)=
6ba0: 3d 30 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a =0).#endif../*.*
6bb0: 2a 20 44 69 73 61 62 6c 65 20 4d 4d 41 50 20 6f * Disable MMAP o
6bc0: 6e 20 70 6c 61 74 66 6f 72 6d 73 20 77 68 65 72 n platforms wher
6bd0: 65 20 69 74 20 69 73 20 6b 6e 6f 77 6e 20 74 6f e it is known to
6be0: 20 6e 6f 74 20 77 6f 72 6b 0a 2a 2f 0a 23 69 66 not work.*/.#if
6bf0: 20 64 65 66 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 defined(__OpenB
6c00: 53 44 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 SD__) || defined
6c10: 28 5f 5f 51 4e 58 4e 54 4f 5f 5f 29 0a 23 20 75 (__QNXNTO__).# u
6c20: 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f ndef SQLITE_MAX_
6c30: 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 MMAP_SIZE.# defi
6c40: 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ne SQLITE_MAX_MM
6c50: 41 50 5f 53 49 5a 45 20 30 0a 23 65 6e 64 69 66 AP_SIZE 0.#endif
6c60: 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 61 75 6c 74 20 ../*.** Default
6c70: 6d 61 78 69 6d 75 6d 20 73 69 7a 65 20 6f 66 20 maximum size of
6c80: 6d 65 6d 6f 72 79 20 75 73 65 64 20 62 79 20 6d memory used by m
6c90: 65 6d 6f 72 79 2d 6d 61 70 70 65 64 20 49 2f 4f emory-mapped I/O
6ca0: 20 69 6e 20 74 68 65 20 56 46 53 0a 2a 2f 0a 23 in the VFS.*/.#
6cb0: 69 66 64 65 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a ifdef __APPLE__.
6cc0: 23 20 69 6e 63 6c 75 64 65 20 3c 54 61 72 67 65 # include <Targe
6cd0: 74 43 6f 6e 64 69 74 69 6f 6e 61 6c 73 2e 68 3e tConditionals.h>
6ce0: 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 .#endif.#ifndef
6cf0: 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f SQLITE_MAX_MMAP_
6d00: 53 49 5a 45 0a 23 20 69 66 20 64 65 66 69 6e 65 SIZE.# if define
6d10: 64 28 5f 5f 6c 69 6e 75 78 5f 5f 29 20 5c 0a 20 d(__linux__) \.
6d20: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 57 49 4e || defined(_WIN
6d30: 33 32 29 20 5c 0a 20 20 7c 7c 20 28 64 65 66 69 32) \. || (defi
6d40: 6e 65 64 28 5f 5f 41 50 50 4c 45 5f 5f 29 20 26 ned(__APPLE__) &
6d50: 26 20 64 65 66 69 6e 65 64 28 5f 5f 4d 41 43 48 & defined(__MACH
6d60: 5f 5f 29 29 20 5c 0a 20 20 7c 7c 20 64 65 66 69 __)) \. || defi
6d70: 6e 65 64 28 5f 5f 73 75 6e 29 20 5c 0a 20 20 7c ned(__sun) \. |
6d80: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 46 72 65 65 | defined(__Free
6d90: 42 53 44 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 65 BSD__) \. || de
6da0: 66 69 6e 65 64 28 5f 5f 44 72 61 67 6f 6e 46 6c fined(__DragonFl
6db0: 79 5f 5f 29 0a 23 20 20 20 64 65 66 69 6e 65 20 y__).# 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 78 37 66 66 66 30 30 30 30 20 SIZE 0x7fff0000
6de0: 20 2f 2a 20 32 31 34 37 34 31 38 31 31 32 20 2a /* 2147418112 *
6df0: 2f 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 66 /.# else.# def
6e00: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d ine SQLITE_MAX_M
6e10: 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 65 6e 64 MAP_SIZE 0.# end
6e20: 69 66 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 if.# define SQLI
6e30: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
6e40: 5f 78 63 20 31 20 2f 2a 20 65 78 63 6c 75 64 65 _xc 1 /* exclude
6e50: 20 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f from ctime.c */
6e60: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
6e70: 68 65 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 5f he default MMAP_
6e80: 53 49 5a 45 20 69 73 20 7a 65 72 6f 20 6f 6e 20 SIZE is zero on
6e90: 61 6c 6c 20 70 6c 61 74 66 6f 72 6d 73 2e 20 20 all platforms.
6ea0: 4f 72 2c 20 65 76 65 6e 20 69 66 20 61 20 6c 61 Or, even if a la
6eb0: 72 67 65 72 0a 2a 2a 20 64 65 66 61 75 6c 74 20 rger.** default
6ec0: 4d 4d 41 50 5f 53 49 5a 45 20 69 73 20 73 70 65 MMAP_SIZE is spe
6ed0: 63 69 66 69 65 64 20 61 74 20 63 6f 6d 70 69 6c cified at compil
6ee0: 65 2d 74 69 6d 65 2c 20 6d 61 6b 65 20 73 75 72 e-time, make sur
6ef0: 65 20 74 68 61 74 20 69 74 20 64 6f 65 73 0a 2a e that it does.*
6f00: 2a 20 6e 6f 74 20 65 78 63 65 65 64 20 74 68 65 * not exceed the
6f10: 20 6d 61 78 69 6d 75 6d 20 6d 6d 61 70 20 73 69 maximum mmap si
6f20: 7a 65 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ze..*/.#ifndef S
6f30: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d 4d QLITE_DEFAULT_MM
6f40: 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 AP_SIZE.# define
6f50: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
6f60: 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 64 65 MMAP_SIZE 0.# de
6f70: 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 fine SQLITE_DEFA
6f80: 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 63 ULT_MMAP_SIZE_xc
6f90: 20 31 20 20 2f 2a 20 45 78 63 6c 75 64 65 20 66 1 /* Exclude f
6fa0: 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 rom ctime.c */.#
6fb0: 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 45 endif.#if SQLITE
6fc0: 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 _DEFAULT_MMAP_SI
6fd0: 5a 45 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d ZE>SQLITE_MAX_MM
6fe0: 41 50 5f 53 49 5a 45 0a 23 20 75 6e 64 65 66 20 AP_SIZE.# undef
6ff0: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
7000: 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e MAP_SIZE.# defin
7010: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
7020: 5f 4d 4d 41 50 5f 53 49 5a 45 20 53 51 4c 49 54 _MMAP_SIZE SQLIT
7030: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a E_MAX_MMAP_SIZE.
7040: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 6e #endif../*.** On
7050: 6c 79 20 6f 6e 65 20 6f 66 20 53 51 4c 49 54 45 ly one of SQLITE
7060: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 20 6f 72 _ENABLE_STAT3 or
7070: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
7080: 54 41 54 34 20 63 61 6e 20 62 65 20 64 65 66 69 TAT4 can be defi
7090: 6e 65 64 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 79 ned..** Priority
70a0: 20 69 73 20 67 69 76 65 6e 20 74 6f 20 53 51 4c is given to SQL
70b0: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 34 ITE_ENABLE_STAT4
70c0: 2e 20 20 49 66 20 65 69 74 68 65 72 20 61 72 65 . If either are
70d0: 20 64 65 66 69 6e 65 64 2c 20 61 6c 73 6f 0a 2a defined, also.*
70e0: 2a 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f * define SQLITE_
70f0: 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f ENABLE_STAT3_OR_
7100: 53 54 41 54 34 0a 2a 2f 0a 23 69 66 64 65 66 20 STAT4.*/.#ifdef
7110: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
7120: 41 54 34 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 AT4.# undef SQLI
7130: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 0a TE_ENABLE_STAT3.
7140: 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
7150: 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f ENABLE_STAT3_OR_
7160: 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 51 STAT4 1.#elif SQ
7170: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
7180: 33 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 3.# define SQLIT
7190: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f E_ENABLE_STAT3_O
71a0: 52 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 R_STAT4 1.#elif
71b0: 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 SQLITE_ENABLE_ST
71c0: 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 20 75 AT3_OR_STAT4.# u
71d0: 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 ndef SQLITE_ENAB
71e0: 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 54 LE_STAT3_OR_STAT
71f0: 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4.#endif../*.**
7200: 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 42 SELECTTRACE_ENAB
7210: 4c 45 44 20 77 69 6c 6c 20 62 65 20 65 69 74 68 LED will be eith
7220: 65 72 20 31 20 6f 72 20 30 20 64 65 70 65 6e 64 er 1 or 0 depend
7230: 69 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 20 6f ing on whether o
7240: 72 20 6e 6f 74 0a 2a 2a 20 74 68 65 20 53 65 6c r not.** the Sel
7250: 65 63 74 20 71 75 65 72 79 20 67 65 6e 65 72 61 ect query genera
7260: 74 6f 72 20 74 72 61 63 69 6e 67 20 6c 6f 67 69 tor tracing logi
7270: 63 20 69 73 20 74 75 72 6e 65 64 20 6f 6e 2e 0a c is turned on..
7280: 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 */.#if defined(S
7290: 51 4c 49 54 45 5f 44 45 42 55 47 29 20 7c 7c 20 QLITE_DEBUG) ||
72a0: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 defined(SQLITE_E
72b0: 4e 41 42 4c 45 5f 53 45 4c 45 43 54 54 52 41 43 NABLE_SELECTTRAC
72c0: 45 29 0a 23 20 64 65 66 69 6e 65 20 53 45 4c 45 E).# define SELE
72d0: 43 54 54 52 41 43 45 5f 45 4e 41 42 4c 45 44 20 CTTRACE_ENABLED
72e0: 31 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 1.#else.# define
72f0: 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 4e 41 SELECTTRACE_ENA
7300: 42 4c 45 44 20 30 0a 23 65 6e 64 69 66 0a 0a 2f BLED 0.#endif../
7310: 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
7320: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
7330: 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 75 g structure is u
7340: 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 sed to store the
7350: 20 62 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a busy-handler.**
7360: 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 61 20 callback for a
7370: 67 69 76 65 6e 20 73 71 6c 69 74 65 20 68 61 6e given sqlite han
7380: 64 6c 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 dle..**.** The s
7390: 71 6c 69 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 qlite.busyHandle
73a0: 72 20 6d 65 6d 62 65 72 20 6f 66 20 74 68 65 20 r member of the
73b0: 73 71 6c 69 74 65 20 73 74 72 75 63 74 20 63 6f sqlite struct co
73c0: 6e 74 61 69 6e 73 20 74 68 65 20 62 75 73 79 0a ntains the busy.
73d0: 2a 2a 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 ** callback for
73e0: 74 68 65 20 64 61 74 61 62 61 73 65 20 68 61 6e the database han
73f0: 64 6c 65 2e 20 45 61 63 68 20 70 61 67 65 72 20 dle. Each pager
7400: 6f 70 65 6e 65 64 20 76 69 61 20 74 68 65 20 73 opened via the s
7410: 71 6c 69 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 qlite.** handle
7420: 69 73 20 70 61 73 73 65 64 20 61 20 70 6f 69 6e is passed a poin
7430: 74 65 72 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 ter to sqlite.bu
7440: 73 79 48 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 syHandler. The b
7450: 75 73 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 usy-handler.** c
7460: 61 6c 6c 62 61 63 6b 20 69 73 20 63 75 72 72 65 allback is curre
7470: 6e 74 6c 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c ntly invoked onl
7480: 79 20 66 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 y from within pa
7490: 67 65 72 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 ger.c..*/.typede
74a0: 66 20 73 74 72 75 63 74 20 42 75 73 79 48 61 6e f struct BusyHan
74b0: 64 6c 65 72 20 42 75 73 79 48 61 6e 64 6c 65 72 dler BusyHandler
74c0: 3b 0a 73 74 72 75 63 74 20 42 75 73 79 48 61 6e ;.struct BusyHan
74d0: 64 6c 65 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 dler {. int (*x
74e0: 46 75 6e 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 Func)(void *,int
74f0: 29 3b 20 20 2f 2a 20 54 68 65 20 62 75 73 79 20 ); /* The busy
7500: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f callback */. vo
7510: 69 64 20 2a 70 41 72 67 3b 20 20 20 20 20 20 20 id *pArg;
7520: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 /* Firs
7530: 74 20 61 72 67 20 74 6f 20 62 75 73 79 20 63 61 t arg to busy ca
7540: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 llback */. int
7550: 6e 42 75 73 79 3b 20 20 20 20 20 20 20 20 20 20 nBusy;
7560: 20 20 20 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d /* Increm
7570: 65 6e 74 65 64 20 77 69 74 68 20 65 61 63 68 20 ented with each
7580: 62 75 73 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a busy call */.};.
7590: 0a 2f 2a 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 ./*.** Name of t
75a0: 68 65 20 6d 61 73 74 65 72 20 64 61 74 61 62 61 he master databa
75b0: 73 65 20 74 61 62 6c 65 2e 20 20 54 68 65 20 6d se table. The m
75c0: 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 74 aster database t
75d0: 61 62 6c 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 able.** is a spe
75e0: 63 69 61 6c 20 74 61 62 6c 65 20 74 68 61 74 20 cial table that
75f0: 68 6f 6c 64 73 20 74 68 65 20 6e 61 6d 65 73 20 holds the names
7600: 61 6e 64 20 61 74 74 72 69 62 75 74 65 73 20 6f and attributes o
7610: 66 20 61 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 f all.** user ta
7620: 62 6c 65 73 20 61 6e 64 20 69 6e 64 69 63 65 73 bles and indices
7630: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 ..*/.#define MAS
7640: 54 45 52 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 TER_NAME "
7650: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 sqlite_master".#
7660: 64 65 66 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 define TEMP_MAST
7670: 45 52 5f 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 ER_NAME "sqlite
7680: 5f 74 65 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f _temp_master"../
7690: 2a 0a 2a 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 *.** The root-pa
76a0: 67 65 20 6f 66 20 74 68 65 20 6d 61 73 74 65 72 ge of the master
76b0: 20 64 61 74 61 62 61 73 65 20 74 61 62 6c 65 2e database table.
76c0: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 .*/.#define MAST
76d0: 45 52 5f 52 4f 4f 54 20 20 20 20 20 20 20 31 0a ER_ROOT 1.
76e0: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 ./*.** The name
76f0: 6f 66 20 74 68 65 20 73 63 68 65 6d 61 20 74 61 of the schema ta
7700: 62 6c 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ble..*/.#define
7710: 53 43 48 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 SCHEMA_TABLE(x)
7720: 20 28 28 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 ((!OMIT_TEMPDB)
7730: 26 26 28 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 &&(x==1)?TEMP_MA
7740: 53 54 45 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 STER_NAME:MASTER
7750: 5f 4e 41 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 _NAME)../*.** A
7760: 63 6f 6e 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 convenience macr
7770: 6f 20 74 68 61 74 20 72 65 74 75 72 6e 73 20 74 o that returns t
7780: 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 he number of ele
7790: 6d 65 6e 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 ments in.** an a
77a0: 72 72 61 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 rray..*/.#define
77b0: 20 41 72 72 61 79 53 69 7a 65 28 58 29 20 20 20 ArraySize(X)
77c0: 20 28 28 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 ((int)(sizeof(X
77d0: 29 2f 73 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 )/sizeof(X[0])))
77e0: 0a 0a 2f 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e ../*.** Determin
77f0: 65 20 69 66 20 74 68 65 20 61 72 67 75 6d 65 6e e if the argumen
7800: 74 20 69 73 20 61 20 70 6f 77 65 72 20 6f 66 20 t is a power of
7810: 74 77 6f 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 two.*/.#define I
7820: 73 50 6f 77 65 72 4f 66 54 77 6f 28 58 29 20 28 sPowerOfTwo(X) (
7830: 28 28 58 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 ((X)&((X)-1))==0
7840: 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c )../*.** The fol
7850: 6c 6f 77 69 6e 67 20 76 61 6c 75 65 20 61 73 20 lowing value as
7860: 61 20 64 65 73 74 72 75 63 74 6f 72 20 6d 65 61 a destructor mea
7870: 6e 73 20 74 6f 20 75 73 65 20 73 71 6c 69 74 65 ns to use sqlite
7880: 33 44 62 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 3DbFree()..** Th
7890: 65 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 e sqlite3DbFree(
78a0: 29 20 72 6f 75 74 69 6e 65 20 72 65 71 75 69 72 ) routine requir
78b0: 65 73 20 74 77 6f 20 70 61 72 61 6d 65 74 65 72 es two parameter
78c0: 73 20 69 6e 73 74 65 61 64 20 6f 66 20 74 68 65 s instead of the
78d0: 0a 2a 2a 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 .** one paramete
78e0: 72 20 74 68 61 74 20 64 65 73 74 72 75 63 74 6f r that destructo
78f0: 72 73 20 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 rs normally want
7900: 2e 20 20 53 6f 20 77 65 20 68 61 76 65 20 74 6f . So we have to
7910: 20 69 6e 74 72 6f 64 75 63 65 0a 2a 2a 20 74 68 introduce.** th
7920: 69 73 20 6d 61 67 69 63 20 76 61 6c 75 65 20 74 is magic value t
7930: 68 61 74 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f hat the code kno
7940: 77 73 20 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 ws to handle dif
7950: 66 65 72 65 6e 74 6c 79 2e 20 20 41 6e 79 0a 2a ferently. Any.*
7960: 2a 20 70 6f 69 6e 74 65 72 20 77 69 6c 6c 20 77 * pointer will w
7970: 6f 72 6b 20 68 65 72 65 20 61 73 20 6c 6f 6e 67 ork here as long
7980: 20 61 73 20 69 74 20 69 73 20 64 69 73 74 69 6e as it is distin
7990: 63 74 20 66 72 6f 6d 20 53 51 4c 49 54 45 5f 53 ct from SQLITE_S
79a0: 54 41 54 49 43 0a 2a 2a 20 61 6e 64 20 53 51 4c TATIC.** and SQL
79b0: 49 54 45 5f 54 52 41 4e 53 49 45 4e 54 2e 0a 2a ITE_TRANSIENT..*
79c0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
79d0: 5f 44 59 4e 41 4d 49 43 20 20 20 28 28 73 71 6c _DYNAMIC ((sql
79e0: 69 74 65 33 5f 64 65 73 74 72 75 63 74 6f 72 5f ite3_destructor_
79f0: 74 79 70 65 29 73 71 6c 69 74 65 33 4d 61 6c 6c type)sqlite3Mall
7a00: 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 57 ocSize)../*.** W
7a10: 68 65 6e 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f hen SQLITE_OMIT_
7a20: 57 53 44 20 69 73 20 64 65 66 69 6e 65 64 2c 20 WSD is defined,
7a30: 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 it means that th
7a40: 65 20 74 61 72 67 65 74 20 70 6c 61 74 66 6f 72 e target platfor
7a50: 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 75 m does.** not su
7a60: 70 70 6f 72 74 20 57 72 69 74 61 62 6c 65 20 53 pport Writable S
7a70: 74 61 74 69 63 20 44 61 74 61 20 28 57 53 44 29 tatic Data (WSD)
7a80: 20 73 75 63 68 20 61 73 20 67 6c 6f 62 61 6c 20 such as global
7a90: 61 6e 64 20 73 74 61 74 69 63 20 76 61 72 69 61 and static varia
7aa0: 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 72 bles..** All var
7ab0: 69 61 62 6c 65 73 20 6d 75 73 74 20 65 69 74 68 iables must eith
7ac0: 65 72 20 62 65 20 6f 6e 20 74 68 65 20 73 74 61 er be on the sta
7ad0: 63 6b 20 6f 72 20 64 79 6e 61 6d 69 63 61 6c 6c ck or dynamicall
7ae0: 79 20 61 6c 6c 6f 63 61 74 65 64 20 66 72 6f 6d y allocated from
7af0: 0a 2a 2a 20 74 68 65 20 68 65 61 70 2e 20 20 57 .** the heap. W
7b00: 68 65 6e 20 57 53 44 20 69 73 20 75 6e 73 75 70 hen WSD is unsup
7b10: 70 6f 72 74 65 64 2c 20 74 68 65 20 76 61 72 69 ported, the vari
7b20: 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f 6e able declaration
7b30: 73 20 73 63 61 74 74 65 72 65 64 0a 2a 2a 20 74 s scattered.** t
7b40: 68 72 6f 75 67 68 6f 75 74 20 74 68 65 20 53 51 hroughout the SQ
7b50: 4c 69 74 65 20 63 6f 64 65 20 6d 75 73 74 20 62 Lite code must b
7b60: 65 63 6f 6d 65 20 63 6f 6e 73 74 61 6e 74 73 20 ecome constants
7b70: 69 6e 73 74 65 61 64 2e 20 20 54 68 65 20 53 51 instead. The SQ
7b80: 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 72 LITE_WSD.** macr
7b90: 6f 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 68 o is used for th
7ba0: 69 73 20 70 75 72 70 6f 73 65 2e 20 20 41 6e 64 is purpose. And
7bb0: 20 69 6e 73 74 65 61 64 20 6f 66 20 72 65 66 65 instead of refe
7bc0: 72 65 6e 63 69 6e 67 20 74 68 65 20 76 61 72 69 rencing the vari
7bd0: 61 62 6c 65 0a 2a 2a 20 64 69 72 65 63 74 6c 79 able.** directly
7be0: 2c 20 77 65 20 75 73 65 20 69 74 73 20 63 6f 6e , we use its con
7bf0: 73 74 61 6e 74 20 61 73 20 61 20 6b 65 79 20 74 stant as a key t
7c00: 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 72 75 6e o lookup the run
7c10: 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 74 65 64 0a -time allocated.
7c20: 2a 2a 20 62 75 66 66 65 72 20 74 68 61 74 20 68 ** buffer that h
7c30: 6f 6c 64 73 20 72 65 61 6c 20 76 61 72 69 61 62 olds real variab
7c40: 6c 65 2e 20 20 54 68 65 20 63 6f 6e 73 74 61 6e le. The constan
7c50: 74 20 69 73 20 61 6c 73 6f 20 74 68 65 20 69 6e t is also the in
7c60: 69 74 69 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f 72 itializer.** for
7c70: 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c the run-time al
7c80: 6c 6f 63 61 74 65 64 20 62 75 66 66 65 72 2e 0a located buffer..
7c90: 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 75 73 75 **.** In the usu
7ca0: 61 6c 20 63 61 73 65 20 77 68 65 72 65 20 57 53 al case where WS
7cb0: 44 20 69 73 20 73 75 70 70 6f 72 74 65 64 2c 20 D is supported,
7cc0: 74 68 65 20 53 51 4c 49 54 45 5f 57 53 44 20 61 the SQLITE_WSD a
7cd0: 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 63 nd GLOBAL.** mac
7ce0: 72 6f 73 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f 70 ros become no-op
7cf0: 73 20 61 6e 64 20 68 61 76 65 20 7a 65 72 6f 20 s and have zero
7d00: 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 6d 70 61 performance impa
7d10: 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 ct..*/.#ifdef SQ
7d20: 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 20 LITE_OMIT_WSD.
7d30: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 #define SQLITE_W
7d40: 53 44 20 63 6f 6e 73 74 0a 20 20 23 64 65 66 69 SD const. #defi
7d50: 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 28 ne GLOBAL(t,v) (
7d60: 2a 28 74 2a 29 73 71 6c 69 74 65 33 5f 77 73 64 *(t*)sqlite3_wsd
7d70: 5f 66 69 6e 64 28 28 76 6f 69 64 2a 29 26 28 76 _find((void*)&(v
7d80: 29 2c 20 73 69 7a 65 6f 66 28 76 29 29 29 0a 20 ), sizeof(v))).
7d90: 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
7da0: 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 47 4c 4f GlobalConfig GLO
7db0: 42 41 4c 28 73 74 72 75 63 74 20 53 71 6c 69 74 BAL(struct Sqlit
7dc0: 65 33 43 6f 6e 66 69 67 2c 20 73 71 6c 69 74 65 e3Config, sqlite
7dd0: 33 43 6f 6e 66 69 67 29 0a 20 20 69 6e 74 20 73 3Config). int s
7de0: 71 6c 69 74 65 33 5f 77 73 64 5f 69 6e 69 74 28 qlite3_wsd_init(
7df0: 69 6e 74 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a 20 int N, int J);.
7e00: 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 5f 77 void *sqlite3_w
7e10: 73 64 5f 66 69 6e 64 28 76 6f 69 64 20 2a 4b 2c sd_find(void *K,
7e20: 20 69 6e 74 20 4c 29 3b 0a 23 65 6c 73 65 0a 20 int L);.#else.
7e30: 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f #define SQLITE_
7e40: 57 53 44 0a 20 20 23 64 65 66 69 6e 65 20 47 4c WSD. #define GL
7e50: 4f 42 41 4c 28 74 2c 76 29 20 76 0a 20 20 23 64 OBAL(t,v) v. #d
7e60: 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 6c 6f efine sqlite3Glo
7e70: 62 61 6c 43 6f 6e 66 69 67 20 73 71 6c 69 74 65 balConfig sqlite
7e80: 33 43 6f 6e 66 69 67 0a 23 65 6e 64 69 66 0a 0a 3Config.#endif..
7e90: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
7ea0: 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 65 20 75 ing macros are u
7eb0: 73 65 64 20 74 6f 20 73 75 70 70 72 65 73 73 20 sed to suppress
7ec0: 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e 69 6e 67 compiler warning
7ed0: 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 6d 61 6b 65 s and to.** make
7ee0: 20 69 74 20 63 6c 65 61 72 20 74 6f 20 68 75 6d it clear to hum
7ef0: 61 6e 20 72 65 61 64 65 72 73 20 77 68 65 6e 20 an readers when
7f00: 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 61 6d a function param
7f10: 65 74 65 72 20 69 73 20 64 65 6c 69 62 65 72 61 eter is delibera
7f20: 74 65 6c 79 0a 2a 2a 20 6c 65 66 74 20 75 6e 75 tely.** left unu
7f30: 73 65 64 20 77 69 74 68 69 6e 20 74 68 65 20 62 sed within the b
7f40: 6f 64 79 20 6f 66 20 61 20 66 75 6e 63 74 69 6f ody of a functio
7f50: 6e 2e 20 54 68 69 73 20 75 73 75 61 6c 6c 79 20 n. This usually
7f60: 68 61 70 70 65 6e 73 20 77 68 65 6e 0a 2a 2a 20 happens when.**
7f70: 61 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 63 61 a function is ca
7f80: 6c 6c 65 64 20 76 69 61 20 61 20 66 75 6e 63 74 lled via a funct
7f90: 69 6f 6e 20 70 6f 69 6e 74 65 72 2e 20 46 6f 72 ion pointer. For
7fa0: 20 65 78 61 6d 70 6c 65 20 74 68 65 0a 2a 2a 20 example the.**
7fb0: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f implementation o
7fc0: 66 20 61 6e 20 53 51 4c 20 61 67 67 72 65 67 61 f an SQL aggrega
7fd0: 74 65 20 73 74 65 70 20 63 61 6c 6c 62 61 63 6b te step callback
7fe0: 20 6d 61 79 20 6e 6f 74 20 75 73 65 20 74 68 65 may not use the
7ff0: 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 20 69 6e .** parameter in
8000: 64 69 63 61 74 69 6e 67 20 74 68 65 20 6e 75 6d dicating the num
8010: 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
8020: 20 70 61 73 73 65 64 20 74 6f 20 74 68 65 20 61 passed to the a
8030: 67 67 72 65 67 61 74 65 2c 0a 2a 2a 20 69 66 20 ggregate,.** if
8040: 69 74 20 6b 6e 6f 77 73 20 74 68 61 74 20 74 68 it knows that th
8050: 69 73 20 69 73 20 65 6e 66 6f 72 63 65 64 20 65 is is enforced e
8060: 6c 73 65 77 68 65 72 65 2e 0a 2a 2a 0a 2a 2a 20 lsewhere..**.**
8070: 57 68 65 6e 20 61 20 66 75 6e 63 74 69 6f 6e 20 When a function
8080: 70 61 72 61 6d 65 74 65 72 20 69 73 20 6e 6f 74 parameter is not
8090: 20 75 73 65 64 20 61 74 20 61 6c 6c 20 77 69 74 used at all wit
80a0: 68 69 6e 20 74 68 65 20 62 6f 64 79 20 6f 66 20 hin the body of
80b0: 61 20 66 75 6e 63 74 69 6f 6e 2c 0a 2a 2a 20 69 a function,.** i
80c0: 74 20 69 73 20 67 65 6e 65 72 61 6c 6c 79 20 6e t is generally n
80d0: 61 6d 65 64 20 22 4e 6f 74 55 73 65 64 22 20 6f amed "NotUsed" o
80e0: 72 20 22 4e 6f 74 55 73 65 64 32 22 20 74 6f 20 r "NotUsed2" to
80f0: 6d 61 6b 65 20 74 68 69 6e 67 73 20 65 76 65 6e make things even
8100: 20 63 6c 65 61 72 65 72 2e 0a 2a 2a 20 48 6f 77 clearer..** How
8110: 65 76 65 72 2c 20 74 68 65 73 65 20 6d 61 63 72 ever, these macr
8120: 6f 73 20 6d 61 79 20 61 6c 73 6f 20 62 65 20 75 os may also be u
8130: 73 65 64 20 74 6f 20 73 75 70 70 72 65 73 73 20 sed to suppress
8140: 77 61 72 6e 69 6e 67 73 20 72 65 6c 61 74 65 64 warnings related
8150: 20 74 6f 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 to.** parameter
8160: 73 20 74 68 61 74 20 6d 61 79 20 6f 72 20 6d 61 s that may or ma
8170: 79 20 6e 6f 74 20 62 65 20 75 73 65 64 20 64 65 y not be used de
8180: 70 65 6e 64 69 6e 67 20 6f 6e 20 63 6f 6d 70 69 pending on compi
8190: 6c 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a lation options..
81a0: 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c 65 20 74 ** For example t
81b0: 68 6f 73 65 20 70 61 72 61 6d 65 74 65 72 73 20 hose parameters
81c0: 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 61 73 73 only used in ass
81d0: 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
81e0: 2e 20 49 6e 20 74 68 65 73 65 0a 2a 2a 20 63 61 . In these.** ca
81f0: 73 65 73 20 74 68 65 20 70 61 72 61 6d 65 74 65 ses the paramete
8200: 72 73 20 61 72 65 20 6e 61 6d 65 64 20 61 73 20 rs are named as
8210: 70 65 72 20 74 68 65 20 75 73 75 61 6c 20 63 6f per the usual co
8220: 6e 76 65 6e 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 nventions..*/.#d
8230: 65 66 69 6e 65 20 55 4e 55 53 45 44 5f 50 41 52 efine UNUSED_PAR
8240: 41 4d 45 54 45 52 28 78 29 20 28 76 6f 69 64 29 AMETER(x) (void)
8250: 28 78 29 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 (x).#define UNUS
8260: 45 44 5f 50 41 52 41 4d 45 54 45 52 32 28 78 2c ED_PARAMETER2(x,
8270: 79 29 20 55 4e 55 53 45 44 5f 50 41 52 41 4d 45 y) UNUSED_PARAME
8280: 54 45 52 28 78 29 2c 55 4e 55 53 45 44 5f 50 41 TER(x),UNUSED_PA
8290: 52 41 4d 45 54 45 52 28 79 29 0a 0a 2f 2a 0a 2a RAMETER(y)../*.*
82a0: 2a 20 46 6f 72 77 61 72 64 20 72 65 66 65 72 65 * Forward refere
82b0: 6e 63 65 73 20 74 6f 20 73 74 72 75 63 74 75 72 nces to structur
82c0: 65 73 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 es.*/.typedef st
82d0: 72 75 63 74 20 41 67 67 49 6e 66 6f 20 41 67 67 ruct AggInfo Agg
82e0: 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 Info;.typedef st
82f0: 72 75 63 74 20 41 75 74 68 43 6f 6e 74 65 78 74 ruct AuthContext
8300: 20 41 75 74 68 43 6f 6e 74 65 78 74 3b 0a 74 79 AuthContext;.ty
8310: 70 65 64 65 66 20 73 74 72 75 63 74 20 41 75 74 pedef struct Aut
8320: 6f 69 6e 63 49 6e 66 6f 20 41 75 74 6f 69 6e 63 oincInfo Autoinc
8330: 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 20 73 74 Info;.typedef st
8340: 72 75 63 74 20 42 69 74 76 65 63 20 42 69 74 76 ruct Bitvec Bitv
8350: 65 63 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 ec;.typedef stru
8360: 63 74 20 43 6f 6c 6c 53 65 71 20 43 6f 6c 6c 53 ct CollSeq CollS
8370: 65 71 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 eq;.typedef stru
8380: 63 74 20 43 6f 6c 75 6d 6e 20 43 6f 6c 75 6d 6e ct Column Column
8390: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
83a0: 20 44 62 20 44 62 3b 0a 74 79 70 65 64 65 66 20 Db Db;.typedef
83b0: 73 74 72 75 63 74 20 53 63 68 65 6d 61 20 53 63 struct Schema Sc
83c0: 68 65 6d 61 3b 0a 74 79 70 65 64 65 66 20 73 74 hema;.typedef st
83d0: 72 75 63 74 20 45 78 70 72 20 45 78 70 72 3b 0a ruct Expr Expr;.
83e0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 45 typedef struct E
83f0: 78 70 72 4c 69 73 74 20 45 78 70 72 4c 69 73 74 xprList ExprList
8400: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
8410: 20 45 78 70 72 53 70 61 6e 20 45 78 70 72 53 70 ExprSpan ExprSp
8420: 61 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 an;.typedef stru
8430: 63 74 20 46 4b 65 79 20 46 4b 65 79 3b 0a 74 79 ct FKey FKey;.ty
8440: 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 6e pedef struct Fun
8450: 63 44 65 73 74 72 75 63 74 6f 72 20 46 75 6e 63 cDestructor Func
8460: 44 65 73 74 72 75 63 74 6f 72 3b 0a 74 79 70 65 Destructor;.type
8470: 64 65 66 20 73 74 72 75 63 74 20 46 75 6e 63 44 def struct FuncD
8480: 65 66 20 46 75 6e 63 44 65 66 3b 0a 74 79 70 65 ef FuncDef;.type
8490: 64 65 66 20 73 74 72 75 63 74 20 46 75 6e 63 44 def struct FuncD
84a0: 65 66 48 61 73 68 20 46 75 6e 63 44 65 66 48 61 efHash FuncDefHa
84b0: 73 68 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 sh;.typedef stru
84c0: 63 74 20 49 64 4c 69 73 74 20 49 64 4c 69 73 74 ct IdList IdList
84d0: 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 ;.typedef struct
84e0: 20 49 6e 64 65 78 20 49 6e 64 65 78 3b 0a 74 79 Index Index;.ty
84f0: 70 65 64 65 66 20 73 74 72 75 63 74 20 49 6e 64 pedef struct Ind
8500: 65 78 53 61 6d 70 6c 65 20 49 6e 64 65 78 53 61 exSample IndexSa
8510: 6d 70 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 74 mple;.typedef st
8520: 72 75 63 74 20 4b 65 79 43 6c 61 73 73 20 4b 65 ruct KeyClass Ke
8530: 79 43 6c 61 73 73 3b 0a 74 79 70 65 64 65 66 20 yClass;.typedef
8540: 73 74 72 75 63 74 20 4b 65 79 49 6e 66 6f 20 4b struct KeyInfo K
8550: 65 79 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 20 eyInfo;.typedef
8560: 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 struct Lookaside
8570: 20 4c 6f 6f 6b 61 73 69 64 65 3b 0a 74 79 70 65 Lookaside;.type
8580: 64 65 66 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 def struct Looka
8590: 73 69 64 65 53 6c 6f 74 20 4c 6f 6f 6b 61 73 69 sideSlot Lookasi
85a0: 64 65 53 6c 6f 74 3b 0a 74 79 70 65 64 65 66 20 deSlot;.typedef
85b0: 73 74 72 75 63 74 20 4d 6f 64 75 6c 65 20 4d 6f struct Module Mo
85c0: 64 75 6c 65 3b 0a 74 79 70 65 64 65 66 20 73 74 dule;.typedef st
85d0: 72 75 63 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 ruct NameContext
85e0: 20 4e 61 6d 65 43 6f 6e 74 65 78 74 3b 0a 74 79 NameContext;.ty
85f0: 70 65 64 65 66 20 73 74 72 75 63 74 20 50 61 72 pedef struct Par
8600: 73 65 20 50 61 72 73 65 3b 0a 74 79 70 65 64 65 se Parse;.typede
8610: 66 20 73 74 72 75 63 74 20 50 72 65 55 70 64 61 f struct PreUpda
8620: 74 65 20 50 72 65 55 70 64 61 74 65 3b 0a 74 79 te PreUpdate;.ty
8630: 70 65 64 65 66 20 73 74 72 75 63 74 20 50 72 69 pedef struct Pri
8640: 6e 74 66 41 72 67 75 6d 65 6e 74 73 20 50 72 69 ntfArguments Pri
8650: 6e 74 66 41 72 67 75 6d 65 6e 74 73 3b 0a 74 79 ntfArguments;.ty
8660: 70 65 64 65 66 20 73 74 72 75 63 74 20 52 6f 77 pedef struct Row
8670: 53 65 74 20 52 6f 77 53 65 74 3b 0a 74 79 70 65 Set RowSet;.type
8680: 64 65 66 20 73 74 72 75 63 74 20 53 61 76 65 70 def struct Savep
8690: 6f 69 6e 74 20 53 61 76 65 70 6f 69 6e 74 3b 0a oint Savepoint;.
86a0: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 typedef struct S
86b0: 65 6c 65 63 74 20 53 65 6c 65 63 74 3b 0a 74 79 elect Select;.ty
86c0: 70 65 64 65 66 20 73 74 72 75 63 74 20 53 51 4c pedef struct SQL
86d0: 69 74 65 54 68 72 65 61 64 20 53 51 4c 69 74 65 iteThread SQLite
86e0: 54 68 72 65 61 64 3b 0a 74 79 70 65 64 65 66 20 Thread;.typedef
86f0: 73 74 72 75 63 74 20 53 65 6c 65 63 74 44 65 73 struct SelectDes
8700: 74 20 53 65 6c 65 63 74 44 65 73 74 3b 0a 74 79 t SelectDest;.ty
8710: 70 65 64 65 66 20 73 74 72 75 63 74 20 53 72 63 pedef struct Src
8720: 4c 69 73 74 20 53 72 63 4c 69 73 74 3b 0a 74 79 List SrcList;.ty
8730: 70 65 64 65 66 20 73 74 72 75 63 74 20 53 74 72 pedef struct Str
8740: 41 63 63 75 6d 20 53 74 72 41 63 63 75 6d 3b 0a Accum StrAccum;.
8750: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
8760: 61 62 6c 65 20 54 61 62 6c 65 3b 0a 74 79 70 65 able Table;.type
8770: 64 65 66 20 73 74 72 75 63 74 20 54 61 62 6c 65 def struct Table
8780: 4c 6f 63 6b 20 54 61 62 6c 65 4c 6f 63 6b 3b 0a Lock TableLock;.
8790: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 54 typedef struct T
87a0: 6f 6b 65 6e 20 54 6f 6b 65 6e 3b 0a 74 79 70 65 oken Token;.type
87b0: 64 65 66 20 73 74 72 75 63 74 20 54 72 65 65 56 def struct TreeV
87c0: 69 65 77 20 54 72 65 65 56 69 65 77 3b 0a 74 79 iew TreeView;.ty
87d0: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 72 69 pedef struct Tri
87e0: 67 67 65 72 20 54 72 69 67 67 65 72 3b 0a 74 79 gger Trigger;.ty
87f0: 70 65 64 65 66 20 73 74 72 75 63 74 20 54 72 69 pedef struct Tri
8800: 67 67 65 72 50 72 67 20 54 72 69 67 67 65 72 50 ggerPrg TriggerP
8810: 72 67 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 rg;.typedef stru
8820: 63 74 20 54 72 69 67 67 65 72 53 74 65 70 20 54 ct TriggerStep T
8830: 72 69 67 67 65 72 53 74 65 70 3b 0a 74 79 70 65 riggerStep;.type
8840: 64 65 66 20 73 74 72 75 63 74 20 55 6e 70 61 63 def struct Unpac
8850: 6b 65 64 52 65 63 6f 72 64 20 55 6e 70 61 63 6b kedRecord Unpack
8860: 65 64 52 65 63 6f 72 64 3b 0a 74 79 70 65 64 65 edRecord;.typede
8870: 66 20 73 74 72 75 63 74 20 56 54 61 62 6c 65 20 f struct VTable
8880: 56 54 61 62 6c 65 3b 0a 74 79 70 65 64 65 66 20 VTable;.typedef
8890: 73 74 72 75 63 74 20 56 74 61 62 43 74 78 20 56 struct VtabCtx V
88a0: 74 61 62 43 74 78 3b 0a 74 79 70 65 64 65 66 20 tabCtx;.typedef
88b0: 73 74 72 75 63 74 20 57 61 6c 6b 65 72 20 57 61 struct Walker Wa
88c0: 6c 6b 65 72 3b 0a 74 79 70 65 64 65 66 20 73 74 lker;.typedef st
88d0: 72 75 63 74 20 57 68 65 72 65 49 6e 66 6f 20 57 ruct WhereInfo W
88e0: 68 65 72 65 49 6e 66 6f 3b 0a 74 79 70 65 64 65 hereInfo;.typede
88f0: 66 20 73 74 72 75 63 74 20 57 69 74 68 20 57 69 f struct With Wi
8900: 74 68 3b 0a 0a 2f 2a 0a 2a 2a 20 44 65 66 65 72 th;../*.** Defer
8910: 20 73 6f 75 72 63 69 6e 67 20 76 64 62 65 2e 68 sourcing vdbe.h
8920: 20 61 6e 64 20 62 74 72 65 65 2e 68 20 75 6e 74 and btree.h unt
8930: 69 6c 20 61 66 74 65 72 20 74 68 65 20 22 75 38 il after the "u8
8940: 22 20 61 6e 64 0a 2a 2a 20 22 42 75 73 79 48 61 " and.** "BusyHa
8950: 6e 64 6c 65 72 22 20 74 79 70 65 64 65 66 73 2e ndler" typedefs.
8960: 20 76 64 62 65 2e 68 20 61 6c 73 6f 20 72 65 71 vdbe.h also req
8970: 75 69 72 65 73 20 61 20 66 65 77 20 6f 66 20 74 uires a few of t
8980: 68 65 20 6f 70 61 71 75 65 0a 2a 2a 20 70 6f 69 he opaque.** poi
8990: 6e 74 65 72 20 74 79 70 65 73 20 28 69 2e 65 2e nter types (i.e.
89a0: 20 46 75 6e 63 44 65 66 29 20 64 65 66 69 6e 65 FuncDef) define
89b0: 64 20 61 62 6f 76 65 2e 0a 2a 2f 0a 23 69 6e 63 d above..*/.#inc
89c0: 6c 75 64 65 20 22 62 74 72 65 65 2e 68 22 0a 23 lude "btree.h".#
89d0: 69 6e 63 6c 75 64 65 20 22 76 64 62 65 2e 68 22 include "vdbe.h"
89e0: 0a 23 69 6e 63 6c 75 64 65 20 22 70 61 67 65 72 .#include "pager
89f0: 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 63 .h".#include "pc
8a00: 61 63 68 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 ache.h".#include
8a10: 20 22 6f 73 2e 68 22 0a 23 69 6e 63 6c 75 64 65 "os.h".#include
8a20: 20 22 6d 75 74 65 78 2e 68 22 0a 0a 2f 2a 20 54 "mutex.h"../* T
8a30: 68 65 20 53 51 4c 49 54 45 5f 45 58 54 52 41 5f he SQLITE_EXTRA_
8a40: 44 55 52 41 42 4c 45 20 63 6f 6d 70 69 6c 65 2d DURABLE compile-
8a50: 74 69 6d 65 20 6f 70 74 69 6f 6e 20 75 73 65 64 time option used
8a60: 20 74 6f 20 73 65 74 20 74 68 65 20 64 65 66 61 to set the defa
8a70: 75 6c 74 0a 2a 2a 20 73 79 6e 63 68 72 6f 6e 6f ult.** synchrono
8a80: 75 73 20 73 65 74 74 69 6e 67 20 74 6f 20 45 58 us setting to EX
8a90: 54 52 41 2e 20 20 49 74 20 69 73 20 6e 6f 20 6c TRA. It is no l
8aa0: 6f 6e 67 65 72 20 73 75 70 70 6f 72 74 65 64 2e onger supported.
8ab0: 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 .*/.#ifdef SQLIT
8ac0: 45 5f 45 58 54 52 41 5f 44 55 52 41 42 4c 45 0a E_EXTRA_DURABLE.
8ad0: 23 20 77 61 72 6e 69 6e 67 20 55 73 65 20 53 51 # warning Use SQ
8ae0: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 4e LITE_DEFAULT_SYN
8af0: 43 48 52 4f 4e 4f 55 53 3d 33 20 69 6e 73 74 65 CHRONOUS=3 inste
8b00: 61 64 20 6f 66 20 53 51 4c 49 54 45 5f 45 58 54 ad of SQLITE_EXT
8b10: 52 41 5f 44 55 52 41 42 4c 45 0a 23 20 64 65 66 RA_DURABLE.# def
8b20: 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 ine SQLITE_DEFAU
8b30: 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 33 LT_SYNCHRONOUS 3
8b40: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 .#endif../*.** D
8b50: 65 66 61 75 6c 74 20 73 79 6e 63 68 72 6f 6e 6f efault synchrono
8b60: 75 73 20 6c 65 76 65 6c 73 2e 0a 2a 2a 0a 2a 2a us levels..**.**
8b70: 20 4e 6f 74 65 20 74 68 61 74 20 28 66 6f 72 20 Note that (for
8b80: 68 69 73 74 6f 72 63 61 6c 20 72 65 61 73 6f 6e historcal reason
8b90: 73 29 20 74 68 65 20 50 41 47 45 52 5f 53 59 4e s) the PAGER_SYN
8ba0: 43 48 52 4f 4e 4f 55 53 5f 2a 20 6d 61 63 72 6f CHRONOUS_* macro
8bb0: 73 20 64 69 66 66 65 72 0a 2a 2a 20 66 72 6f 6d s differ.** from
8bc0: 20 74 68 65 20 53 51 4c 49 54 45 5f 44 45 46 41 the SQLITE_DEFA
8bd0: 55 4c 54 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 ULT_SYNCHRONOUS
8be0: 76 61 6c 75 65 20 62 79 20 31 2e 0a 2a 2a 0a 2a value by 1..**.*
8bf0: 2a 20 20 20 20 20 20 20 20 20 20 20 50 41 47 45 * PAGE
8c00: 52 5f 53 59 4e 43 48 52 4f 4e 4f 55 53 20 20 20 R_SYNCHRONOUS
8c10: 20 20 20 20 44 45 46 41 55 4c 54 5f 53 59 4e 43 DEFAULT_SYNC
8c20: 48 52 4f 4e 4f 55 53 0a 2a 2a 20 20 20 4f 46 46 HRONOUS.** OFF
8c30: 20 20 20 20 20 20 20 20 20 20 20 31 20 20 20 20 1
8c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8c50: 20 20 20 20 20 30 0a 2a 2a 20 20 20 4e 4f 52 4d 0.** NORM
8c60: 41 4c 20 20 20 20 20 20 20 20 32 20 20 20 20 20 AL 2
8c70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8c80: 20 20 20 20 31 0a 2a 2a 20 20 20 46 55 4c 4c 20 1.** FULL
8c90: 20 20 20 20 20 20 20 20 20 33 20 20 20 20 20 20 3
8ca0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8cb0: 20 20 20 32 0a 2a 2a 20 20 20 45 58 54 52 41 20 2.** EXTRA
8cc0: 20 20 20 20 20 20 20 20 34 20 20 20 20 20 20 20 4
8cd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8ce0: 20 20 33 0a 2a 2a 0a 2a 2a 20 54 68 65 20 22 50 3.**.** The "P
8cf0: 52 41 47 4d 41 20 73 79 6e 63 68 72 6f 6e 6f 75 RAGMA synchronou
8d00: 73 22 20 73 74 61 74 65 6d 65 6e 74 20 61 6c 73 s" statement als
8d10: 6f 20 75 73 65 73 20 74 68 65 20 7a 65 72 6f 2d o uses the zero-
8d20: 62 61 73 65 64 20 6e 75 6d 62 65 72 73 2e 0a 2a based numbers..*
8d30: 2a 20 49 6e 20 6f 74 68 65 72 20 77 6f 72 64 73 * In other words
8d40: 2c 20 74 68 65 20 7a 65 72 6f 2d 62 61 73 65 64 , the zero-based
8d50: 20 6e 75 6d 62 65 72 73 20 61 72 65 20 75 73 65 numbers are use
8d60: 64 20 66 6f 72 20 61 6c 6c 20 65 78 74 65 72 6e d for all extern
8d70: 61 6c 20 69 6e 74 65 72 66 61 63 65 73 0a 2a 2a al interfaces.**
8d80: 20 61 6e 64 20 74 68 65 20 6f 6e 65 2d 62 61 73 and the one-bas
8d90: 65 64 20 76 61 6c 75 65 73 20 61 72 65 20 75 73 ed values are us
8da0: 65 64 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 0a 2a ed internally..*
8db0: 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
8dc0: 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f _DEFAULT_SYNCHRO
8dd0: 4e 4f 55 53 0a 23 20 64 65 66 69 6e 65 20 53 51 NOUS.# define SQ
8de0: 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 53 59 4e LITE_DEFAULT_SYN
8df0: 43 48 52 4f 4e 4f 55 53 20 28 50 41 47 45 52 5f CHRONOUS (PAGER_
8e00: 53 59 4e 43 48 52 4f 4e 4f 55 53 5f 46 55 4c 4c SYNCHRONOUS_FULL
8e10: 2d 31 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 -1).#endif.#ifnd
8e20: 65 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ef SQLITE_DEFAUL
8e30: 54 5f 57 41 4c 5f 53 59 4e 43 48 52 4f 4e 4f 55 T_WAL_SYNCHRONOU
8e40: 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 S.# define SQLIT
8e50: 45 5f 44 45 46 41 55 4c 54 5f 57 41 4c 5f 53 59 E_DEFAULT_WAL_SY
8e60: 4e 43 48 52 4f 4e 4f 55 53 20 53 51 4c 49 54 45 NCHRONOUS SQLITE
8e70: 5f 44 45 46 41 55 4c 54 5f 53 59 4e 43 48 52 4f _DEFAULT_SYNCHRO
8e80: 4e 4f 55 53 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a NOUS.#endif../*.
8e90: 2a 2a 20 45 61 63 68 20 64 61 74 61 62 61 73 65 ** Each database
8ea0: 20 66 69 6c 65 20 74 6f 20 62 65 20 61 63 63 65 file to be acce
8eb0: 73 73 65 64 20 62 79 20 74 68 65 20 73 79 73 74 ssed by the syst
8ec0: 65 6d 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 em is an instanc
8ed0: 65 0a 2a 2a 20 6f 66 20 74 68 65 20 66 6f 6c 6c e.** of the foll
8ee0: 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e owing structure.
8ef0: 20 20 54 68 65 72 65 20 61 72 65 20 6e 6f 72 6d There are norm
8f00: 61 6c 6c 79 20 74 77 6f 20 6f 66 20 74 68 65 73 ally two of thes
8f10: 65 20 73 74 72 75 63 74 75 72 65 73 0a 2a 2a 20 e structures.**
8f20: 69 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 44 in the sqlite.aD
8f30: 62 5b 5d 20 61 72 72 61 79 2e 20 20 61 44 62 5b b[] array. aDb[
8f40: 30 5d 20 69 73 20 74 68 65 20 6d 61 69 6e 20 64 0] is the main d
8f50: 61 74 61 62 61 73 65 20 66 69 6c 65 20 61 6e 64 atabase file and
8f60: 0a 2a 2a 20 61 44 62 5b 31 5d 20 69 73 20 74 68 .** aDb[1] is th
8f70: 65 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 e database file
8f80: 75 73 65 64 20 74 6f 20 68 6f 6c 64 20 74 65 6d used to hold tem
8f90: 70 6f 72 61 72 79 20 74 61 62 6c 65 73 2e 20 20 porary tables.
8fa0: 41 64 64 69 74 69 6f 6e 61 6c 0a 2a 2a 20 64 61 Additional.** da
8fb0: 74 61 62 61 73 65 73 20 6d 61 79 20 62 65 20 61 tabases may be a
8fc0: 74 74 61 63 68 65 64 2e 0a 2a 2f 0a 73 74 72 75 ttached..*/.stru
8fd0: 63 74 20 44 62 20 7b 0a 20 20 63 68 61 72 20 2a ct Db {. char *
8fe0: 7a 44 62 53 4e 61 6d 65 3b 20 20 20 20 20 20 2f zDbSName; /
8ff0: 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 64 * Name of this d
9000: 61 74 61 62 61 73 65 2e 20 28 73 63 68 65 6d 61 atabase. (schema
9010: 20 6e 61 6d 65 2c 20 6e 6f 74 20 66 69 6c 65 6e name, not filen
9020: 61 6d 65 29 20 2a 2f 0a 20 20 42 74 72 65 65 20 ame) */. Btree
9030: 2a 70 42 74 3b 20 20 20 20 20 20 20 20 20 20 2f *pBt; /
9040: 2a 20 54 68 65 20 42 2a 54 72 65 65 20 73 74 72 * The B*Tree str
9050: 75 63 74 75 72 65 20 66 6f 72 20 74 68 69 73 20 ucture for this
9060: 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 2a 2f database file */
9070: 0a 20 20 75 38 20 73 61 66 65 74 79 5f 6c 65 76 . u8 safety_lev
9080: 65 6c 3b 20 20 20 20 20 2f 2a 20 48 6f 77 20 61 el; /* How a
9090: 67 67 72 65 73 73 69 76 65 20 61 74 20 73 79 6e ggressive at syn
90a0: 63 69 6e 67 20 64 61 74 61 20 74 6f 20 64 69 73 cing data to dis
90b0: 6b 20 2a 2f 0a 20 20 75 38 20 62 53 79 6e 63 53 k */. u8 bSyncS
90c0: 65 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 et; /* T
90d0: 72 75 65 20 69 66 20 22 50 52 41 47 4d 41 20 73 rue if "PRAGMA s
90e0: 79 6e 63 68 72 6f 6e 6f 75 73 3d 4e 22 20 68 61 ynchronous=N" ha
90f0: 73 20 62 65 65 6e 20 72 75 6e 20 2a 2f 0a 20 20 s been run */.
9100: 53 63 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b Schema *pSchema;
9110: 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 /* Pointer
9120: 74 6f 20 64 61 74 61 62 61 73 65 20 73 63 68 65 to database sche
9130: 6d 61 20 28 70 6f 73 73 69 62 6c 79 20 73 68 61 ma (possibly sha
9140: 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a red) */.};../*.*
9150: 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
9160: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
9170: 74 72 75 63 74 75 72 65 20 73 74 6f 72 65 73 20 tructure stores
9180: 61 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d a database schem
9190: 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 20 53 63 a..**.** Most Sc
91a0: 68 65 6d 61 20 6f 62 6a 65 63 74 73 20 61 72 65 hema objects are
91b0: 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
91c0: 20 61 20 42 74 72 65 65 2e 20 20 54 68 65 20 65 a Btree. The e
91d0: 78 63 65 70 74 69 6f 6e 20 69 73 0a 2a 2a 20 74 xception is.** t
91e0: 68 65 20 53 63 68 65 6d 61 20 66 6f 72 20 74 68 he Schema for th
91f0: 65 20 54 45 4d 50 20 64 61 74 61 62 61 65 73 20 e TEMP databaes
9200: 28 73 71 6c 69 74 65 33 2e 61 44 62 5b 31 5d 29 (sqlite3.aDb[1])
9210: 20 77 68 69 63 68 20 69 73 20 66 72 65 65 2d 73 which is free-s
9220: 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 6e 20 73 tanding..** In s
9230: 68 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 hared cache mode
9240: 2c 20 61 20 73 69 6e 67 6c 65 20 53 63 68 65 6d , a single Schem
9250: 61 20 6f 62 6a 65 63 74 20 63 61 6e 20 62 65 20 a object can be
9260: 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 70 shared by multip
9270: 6c 65 0a 2a 2a 20 42 74 72 65 65 73 20 74 68 61 le.** Btrees tha
9280: 74 20 72 65 66 65 72 20 74 6f 20 74 68 65 20 73 t refer to the s
9290: 61 6d 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 42 ame underlying B
92a0: 74 53 68 61 72 65 64 20 6f 62 6a 65 63 74 2e 0a tShared object..
92b0: 2a 2a 0a 2a 2a 20 53 63 68 65 6d 61 20 6f 62 6a **.** Schema obj
92c0: 65 63 74 73 20 61 72 65 20 61 75 74 6f 6d 61 74 ects are automat
92d0: 69 63 61 6c 6c 79 20 64 65 61 6c 6c 6f 63 61 74 ically deallocat
92e0: 65 64 20 77 68 65 6e 20 74 68 65 20 6c 61 73 74 ed when the last
92f0: 20 42 74 72 65 65 20 74 68 61 74 0a 2a 2a 20 72 Btree that.** r
9300: 65 66 65 72 65 6e 63 65 73 20 74 68 65 6d 20 69 eferences them i
9310: 73 20 64 65 73 74 72 6f 79 65 64 2e 20 20 20 54 s destroyed. T
9320: 68 65 20 54 45 4d 50 20 53 63 68 65 6d 61 20 69 he TEMP Schema i
9330: 73 20 6d 61 6e 75 61 6c 6c 79 20 66 72 65 65 64 s manually freed
9340: 20 62 79 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 63 by.** sqlite3_c
9350: 6c 6f 73 65 28 29 2e 0a 2a 0a 2a 2a 20 41 20 74 lose()..*.** A t
9360: 68 72 65 61 64 20 6d 75 73 74 20 62 65 20 68 6f hread must be ho
9370: 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f 6e lding a mutex on
9380: 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 the correspondi
9390: 6e 67 20 42 74 72 65 65 20 69 6e 20 6f 72 64 65 ng Btree in orde
93a0: 72 0a 2a 2a 20 74 6f 20 61 63 63 65 73 73 20 53 r.** to access S
93b0: 63 68 65 6d 61 20 63 6f 6e 74 65 6e 74 2e 20 20 chema content.
93c0: 54 68 69 73 20 69 6d 70 6c 69 65 73 20 74 68 61 This implies tha
93d0: 74 20 74 68 65 20 74 68 72 65 61 64 20 6d 75 73 t the thread mus
93e0: 74 20 61 6c 73 6f 20 62 65 0a 2a 2a 20 68 6f 6c t also be.** hol
93f0: 64 69 6e 67 20 61 20 6d 75 74 65 78 20 6f 6e 20 ding a mutex on
9400: 74 68 65 20 73 71 6c 69 74 65 33 20 63 6f 6e 6e the sqlite3 conn
9410: 65 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 20 74 ection pointer t
9420: 68 61 74 20 6f 77 6e 73 20 74 68 65 20 42 74 72 hat owns the Btr
9430: 65 65 2e 0a 2a 2a 20 46 6f 72 20 61 20 54 45 4d ee..** For a TEM
9440: 50 20 53 63 68 65 6d 61 2c 20 6f 6e 6c 79 20 74 P Schema, only t
9450: 68 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 he connection mu
9460: 74 65 78 20 69 73 20 72 65 71 75 69 72 65 64 2e tex is required.
9470: 0a 2a 2f 0a 73 74 72 75 63 74 20 53 63 68 65 6d .*/.struct Schem
9480: 61 20 7b 0a 20 20 69 6e 74 20 73 63 68 65 6d 61 a {. int schema
9490: 5f 63 6f 6f 6b 69 65 3b 20 20 20 2f 2a 20 44 61 _cookie; /* Da
94a0: 74 61 62 61 73 65 20 73 63 68 65 6d 61 20 76 65 tabase schema ve
94b0: 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 66 6f 72 rsion number for
94c0: 20 74 68 69 73 20 66 69 6c 65 20 2a 2f 0a 20 20 this file */.
94d0: 69 6e 74 20 69 47 65 6e 65 72 61 74 69 6f 6e 3b int iGeneration;
94e0: 20 20 20 20 20 2f 2a 20 47 65 6e 65 72 61 74 69 /* Generati
94f0: 6f 6e 20 63 6f 75 6e 74 65 72 2e 20 20 49 6e 63 on counter. Inc
9500: 72 65 6d 65 6e 74 65 64 20 77 69 74 68 20 65 61 remented with ea
9510: 63 68 20 63 68 61 6e 67 65 20 2a 2f 0a 20 20 48 ch change */. H
9520: 61 73 68 20 74 62 6c 48 61 73 68 3b 20 20 20 20 ash tblHash;
9530: 20 20 20 20 2f 2a 20 41 6c 6c 20 74 61 62 6c 65 /* All table
9540: 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d s indexed by nam
9550: 65 20 2a 2f 0a 20 20 48 61 73 68 20 69 64 78 48 e */. Hash idxH
9560: 61 73 68 3b 20 20 20 20 20 20 20 20 2f 2a 20 41 ash; /* A
9570: 6c 6c 20 28 6e 61 6d 65 64 29 20 69 6e 64 69 63 ll (named) indic
9580: 65 73 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 es indexed by na
9590: 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 74 72 69 me */. Hash tri
95a0: 67 48 61 73 68 3b 20 20 20 20 20 20 20 2f 2a 20 gHash; /*
95b0: 41 6c 6c 20 74 72 69 67 67 65 72 73 20 69 6e 64 All triggers ind
95c0: 65 78 65 64 20 62 79 20 6e 61 6d 65 20 2a 2f 0a exed by name */.
95d0: 20 20 48 61 73 68 20 66 6b 65 79 48 61 73 68 3b Hash fkeyHash;
95e0: 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 66 6f /* All fo
95f0: 72 65 69 67 6e 20 6b 65 79 73 20 62 79 20 72 65 reign keys by re
9600: 66 65 72 65 6e 63 65 64 20 74 61 62 6c 65 20 6e ferenced table n
9610: 61 6d 65 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a ame */. Table *
9620: 70 53 65 71 54 61 62 3b 20 20 20 20 20 20 2f 2a pSeqTab; /*
9630: 20 54 68 65 20 73 71 6c 69 74 65 5f 73 65 71 75 The sqlite_sequ
9640: 65 6e 63 65 20 74 61 62 6c 65 20 75 73 65 64 20 ence table used
9650: 62 79 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 by AUTOINCREMENT
9660: 20 2a 2f 0a 20 20 75 38 20 66 69 6c 65 5f 66 6f */. u8 file_fo
9670: 72 6d 61 74 3b 20 20 20 20 20 20 2f 2a 20 53 63 rmat; /* Sc
9680: 68 65 6d 61 20 66 6f 72 6d 61 74 20 76 65 72 73 hema format vers
9690: 69 6f 6e 20 66 6f 72 20 74 68 69 73 20 66 69 6c ion for this fil
96a0: 65 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 e */. u8 enc;
96b0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
96c0: 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 75 73 65 ext encoding use
96d0: 64 20 62 79 20 74 68 69 73 20 64 61 74 61 62 61 d by this databa
96e0: 73 65 20 2a 2f 0a 20 20 75 31 36 20 73 63 68 65 se */. u16 sche
96f0: 6d 61 46 6c 61 67 73 3b 20 20 20 20 20 2f 2a 20 maFlags; /*
9700: 46 6c 61 67 73 20 61 73 73 6f 63 69 61 74 65 64 Flags associated
9710: 20 77 69 74 68 20 74 68 69 73 20 73 63 68 65 6d with this schem
9720: 61 20 2a 2f 0a 20 20 69 6e 74 20 63 61 63 68 65 a */. int cache
9730: 5f 73 69 7a 65 3b 20 20 20 20 20 20 2f 2a 20 4e _size; /* N
9740: 75 6d 62 65 72 20 6f 66 20 70 61 67 65 73 20 74 umber of pages t
9750: 6f 20 75 73 65 20 69 6e 20 74 68 65 20 63 61 63 o use in the cac
9760: 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 he */.};../*.**
9770: 54 68 65 73 65 20 6d 61 63 72 6f 73 20 63 61 6e These macros can
9780: 20 62 65 20 75 73 65 64 20 74 6f 20 74 65 73 74 be used to test
9790: 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 20 , set, or clear
97a0: 62 69 74 73 20 69 6e 20 74 68 65 0a 2a 2a 20 44 bits in the.** D
97b0: 62 2e 70 53 63 68 65 6d 61 2d 3e 66 6c 61 67 73 b.pSchema->flags
97c0: 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 field..*/.#defi
97d0: 6e 65 20 44 62 48 61 73 50 72 6f 70 65 72 74 79 ne DbHasProperty
97e0: 28 44 2c 49 2c 50 29 20 20 20 20 20 28 28 28 44 (D,I,P) (((D
97f0: 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d )->aDb[I].pSchem
9800: 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 28 a->schemaFlags&(
9810: 50 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 69 6e P))==(P)).#defin
9820: 65 20 44 62 48 61 73 41 6e 79 50 72 6f 70 65 72 e DbHasAnyProper
9830: 74 79 28 44 2c 49 2c 50 29 20 20 28 28 28 44 29 ty(D,I,P) (((D)
9840: 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 ->aDb[I].pSchema
9850: 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 28 50 ->schemaFlags&(P
9860: 29 29 21 3d 30 29 0a 23 64 65 66 69 6e 65 20 44 ))!=0).#define D
9870: 62 53 65 74 50 72 6f 70 65 72 74 79 28 44 2c 49 bSetProperty(D,I
9880: 2c 50 29 20 20 20 20 20 28 44 29 2d 3e 61 44 62 ,P) (D)->aDb
9890: 5b 49 5d 2e 70 53 63 68 65 6d 61 2d 3e 73 63 68 [I].pSchema->sch
98a0: 65 6d 61 46 6c 61 67 73 7c 3d 28 50 29 0a 23 64 emaFlags|=(P).#d
98b0: 65 66 69 6e 65 20 44 62 43 6c 65 61 72 50 72 6f efine DbClearPro
98c0: 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 20 28 perty(D,I,P) (
98d0: 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 D)->aDb[I].pSche
98e0: 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 26 ma->schemaFlags&
98f0: 3d 7e 28 50 29 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c =~(P)../*.** All
9900: 6f 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 owed values for
9910: 74 68 65 20 44 42 2e 70 53 63 68 65 6d 61 2d 3e the DB.pSchema->
9920: 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a flags field..**.
9930: 2a 2a 20 54 68 65 20 44 42 5f 53 63 68 65 6d 61 ** The DB_Schema
9940: 4c 6f 61 64 65 64 20 66 6c 61 67 20 69 73 20 73 Loaded flag is s
9950: 65 74 20 61 66 74 65 72 20 74 68 65 20 64 61 74 et after the dat
9960: 61 62 61 73 65 20 73 63 68 65 6d 61 20 68 61 73 abase schema has
9970: 20 62 65 65 6e 0a 2a 2a 20 72 65 61 64 20 69 6e been.** read in
9980: 74 6f 20 69 6e 74 65 72 6e 61 6c 20 68 61 73 68 to internal hash
9990: 20 74 61 62 6c 65 73 2e 0a 2a 2a 0a 2a 2a 20 44 tables..**.** D
99a0: 42 5f 55 6e 72 65 73 65 74 56 69 65 77 73 20 6d B_UnresetViews m
99b0: 65 61 6e 73 20 74 68 61 74 20 6f 6e 65 20 6f 72 eans that one or
99c0: 20 6d 6f 72 65 20 76 69 65 77 73 20 68 61 76 65 more views have
99d0: 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 74 68 column names th
99e0: 61 74 0a 2a 2a 20 68 61 76 65 20 62 65 65 6e 20 at.** have been
99f0: 66 69 6c 6c 65 64 20 6f 75 74 2e 20 20 49 66 20 filled out. If
9a00: 74 68 65 20 73 63 68 65 6d 61 20 63 68 61 6e 67 the schema chang
9a10: 65 73 2c 20 74 68 65 73 65 20 63 6f 6c 75 6d 6e es, these column
9a20: 20 6e 61 6d 65 73 20 6d 69 67 68 74 0a 2a 2a 20 names might.**
9a30: 63 68 61 6e 67 65 73 20 61 6e 64 20 73 6f 20 74 changes and so t
9a40: 68 65 20 76 69 65 77 20 77 69 6c 6c 20 6e 65 65 he view will nee
9a50: 64 20 74 6f 20 62 65 20 72 65 73 65 74 2e 0a 2a d to be reset..*
9a60: 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 53 63 68 /.#define DB_Sch
9a70: 65 6d 61 4c 6f 61 64 65 64 20 20 20 20 30 78 30 emaLoaded 0x0
9a80: 30 30 31 20 20 2f 2a 20 54 68 65 20 73 63 68 65 001 /* The sche
9a90: 6d 61 20 68 61 73 20 62 65 65 6e 20 6c 6f 61 64 ma has been load
9aa0: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 ed */.#define DB
9ab0: 5f 55 6e 72 65 73 65 74 56 69 65 77 73 20 20 20 _UnresetViews
9ac0: 20 30 78 30 30 30 32 20 20 2f 2a 20 53 6f 6d 65 0x0002 /* Some
9ad0: 20 76 69 65 77 73 20 68 61 76 65 20 64 65 66 69 views have defi
9ae0: 6e 65 64 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 ned column names
9af0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 44 42 5f 45 */.#define DB_E
9b00: 6d 70 74 79 20 20 20 20 20 20 20 20 20 20 20 30 mpty 0
9b10: 78 30 30 30 34 20 20 2f 2a 20 54 68 65 20 66 69 x0004 /* The fi
9b20: 6c 65 20 69 73 20 65 6d 70 74 79 20 28 6c 65 6e le is empty (len
9b30: 67 74 68 20 30 20 62 79 74 65 73 29 20 2a 2f 0a gth 0 bytes) */.
9b40: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d 62 65 ./*.** The numbe
9b50: 72 20 6f 66 20 64 69 66 66 65 72 65 6e 74 20 6b r of different k
9b60: 69 6e 64 73 20 6f 66 20 74 68 69 6e 67 73 20 74 inds of things t
9b70: 68 61 74 20 63 61 6e 20 62 65 20 6c 69 6d 69 74 hat can be limit
9b80: 65 64 0a 2a 2a 20 75 73 69 6e 67 20 74 68 65 20 ed.** using the
9b90: 73 71 6c 69 74 65 33 5f 6c 69 6d 69 74 28 29 20 sqlite3_limit()
9ba0: 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a 23 64 interface..*/.#d
9bb0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 4c efine SQLITE_N_L
9bc0: 49 4d 49 54 20 28 53 51 4c 49 54 45 5f 4c 49 4d IMIT (SQLITE_LIM
9bd0: 49 54 5f 57 4f 52 4b 45 52 5f 54 48 52 45 41 44 IT_WORKER_THREAD
9be0: 53 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 4c 6f 6f 6b S+1)../*.** Look
9bf0: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 69 73 20 aside malloc is
9c00: 61 20 73 65 74 20 6f 66 20 66 69 78 65 64 2d 73 a set of fixed-s
9c10: 69 7a 65 20 62 75 66 66 65 72 73 20 74 68 61 74 ize buffers that
9c20: 20 63 61 6e 20 62 65 20 75 73 65 64 0a 2a 2a 20 can be used.**
9c30: 74 6f 20 73 61 74 69 73 66 79 20 73 6d 61 6c 6c to satisfy small
9c40: 20 74 72 61 6e 73 69 65 6e 74 20 6d 65 6d 6f 72 transient memor
9c50: 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 72 65 71 y allocation req
9c60: 75 65 73 74 73 20 66 6f 72 20 6f 62 6a 65 63 74 uests for object
9c70: 73 0a 2a 2a 20 61 73 73 6f 63 69 61 74 65 64 20 s.** associated
9c80: 77 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 with a particula
9c90: 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 r database conne
9ca0: 63 74 69 6f 6e 2e 20 20 54 68 65 20 75 73 65 20 ction. The use
9cb0: 6f 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 64 65 20 of.** lookaside
9cc0: 6d 61 6c 6c 6f 63 20 70 72 6f 76 69 64 65 73 20 malloc provides
9cd0: 61 20 73 69 67 6e 69 66 69 63 61 6e 74 20 70 65 a significant pe
9ce0: 72 66 6f 72 6d 61 6e 63 65 20 65 6e 68 61 6e 63 rformance enhanc
9cf0: 65 6d 65 6e 74 0a 2a 2a 20 28 61 70 70 72 6f 78 ement.** (approx
9d00: 20 31 30 25 29 20 62 79 20 61 76 6f 69 64 69 6e 10%) by avoidin
9d10: 67 20 6e 75 6d 65 72 6f 75 73 20 6d 61 6c 6c 6f g numerous mallo
9d20: 63 2f 66 72 65 65 20 72 65 71 75 65 73 74 73 20 c/free requests
9d30: 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a 2a 2a while parsing.**
9d40: 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 73 2e SQL statements.
9d50: 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 6f 6b 61 .**.** The Looka
9d60: 73 69 64 65 20 73 74 72 75 63 74 75 72 65 20 68 side structure h
9d70: 6f 6c 64 73 20 63 6f 6e 66 69 67 75 72 61 74 69 olds configurati
9d80: 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 on information a
9d90: 62 6f 75 74 20 74 68 65 0a 2a 2a 20 6c 6f 6f 6b bout the.** look
9da0: 61 73 69 64 65 20 6d 61 6c 6c 6f 63 20 73 75 62 aside malloc sub
9db0: 73 79 73 74 65 6d 2e 20 20 45 61 63 68 20 61 76 system. Each av
9dc0: 61 69 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 61 ailable memory a
9dd0: 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e 0a 2a 2a 20 llocation in.**
9de0: 74 68 65 20 6c 6f 6f 6b 61 73 69 64 65 20 73 75 the lookaside su
9df0: 62 73 79 73 74 65 6d 20 69 73 20 73 74 6f 72 65 bsystem is store
9e00: 64 20 6f 6e 20 61 20 6c 69 6e 6b 65 64 20 6c 69 d on a linked li
9e10: 73 74 20 6f 66 20 4c 6f 6f 6b 61 73 69 64 65 53 st of LookasideS
9e20: 6c 6f 74 0a 2a 2a 20 6f 62 6a 65 63 74 73 2e 0a lot.** objects..
9e30: 2a 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 69 64 65 20 **.** Lookaside
9e40: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 20 allocations are
9e50: 6f 6e 6c 79 20 61 6c 6c 6f 77 65 64 20 66 6f 72 only allowed for
9e60: 20 6f 62 6a 65 63 74 73 20 74 68 61 74 20 61 72 objects that ar
9e70: 65 20 61 73 73 6f 63 69 61 74 65 64 0a 2a 2a 20 e associated.**
9e80: 77 69 74 68 20 61 20 70 61 72 74 69 63 75 6c 61 with a particula
9e90: 72 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 r database conne
9ea0: 63 74 69 6f 6e 2e 20 20 48 65 6e 63 65 2c 20 73 ction. Hence, s
9eb0: 63 68 65 6d 61 20 69 6e 66 6f 72 6d 61 74 69 6f chema informatio
9ec0: 6e 20 63 61 6e 6e 6f 74 0a 2a 2a 20 62 65 20 73 n cannot.** be s
9ed0: 74 6f 72 65 64 20 69 6e 20 6c 6f 6f 6b 61 73 69 tored in lookasi
9ee0: 64 65 20 62 65 63 61 75 73 65 20 69 6e 20 73 68 de because in sh
9ef0: 61 72 65 64 20 63 61 63 68 65 20 6d 6f 64 65 20 ared cache mode
9f00: 74 68 65 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 the schema infor
9f10: 6d 61 74 69 6f 6e 0a 2a 2a 20 69 73 20 73 68 61 mation.** is sha
9f20: 72 65 64 20 62 79 20 6d 75 6c 74 69 70 6c 65 20 red by multiple
9f30: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
9f40: 69 6f 6e 73 2e 20 20 54 68 65 72 65 66 6f 72 65 ions. Therefore
9f50: 2c 20 77 68 69 6c 65 20 70 61 72 73 69 6e 67 0a , while parsing.
9f60: 2a 2a 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d ** schema inform
9f70: 61 74 69 6f 6e 2c 20 74 68 65 20 4c 6f 6f 6b 61 ation, the Looka
9f80: 73 69 64 65 2e 62 45 6e 61 62 6c 65 64 20 66 6c side.bEnabled fl
9f90: 61 67 20 69 73 20 63 6c 65 61 72 65 64 20 73 6f ag is cleared so
9fa0: 20 74 68 61 74 0a 2a 2a 20 6c 6f 6f 6b 61 73 69 that.** lookasi
9fb0: 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 de allocations a
9fc0: 72 65 20 6e 6f 74 20 75 73 65 64 20 74 6f 20 63 re not used to c
9fd0: 6f 6e 73 74 72 75 63 74 20 74 68 65 20 73 63 68 onstruct the sch
9fe0: 65 6d 61 20 6f 62 6a 65 63 74 73 2e 0a 2a 2f 0a ema objects..*/.
9ff0: 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 struct Lookaside
a000: 20 7b 0a 20 20 75 33 32 20 62 44 69 73 61 62 6c {. u32 bDisabl
a010: 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 e; /*
a020: 4f 6e 6c 79 20 6f 70 65 72 61 74 65 20 74 68 65 Only operate the
a030: 20 6c 6f 6f 6b 61 73 69 64 65 20 77 68 65 6e 20 lookaside when
a040: 7a 65 72 6f 20 2a 2f 0a 20 20 75 31 36 20 73 7a zero */. u16 sz
a050: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
a060: 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 /* Size of eac
a070: 68 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 65 h buffer in byte
a080: 73 20 2a 2f 0a 20 20 75 38 20 62 4d 61 6c 6c 6f s */. u8 bMallo
a090: 63 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f ced; /
a0a0: 2a 20 54 72 75 65 20 69 66 20 70 53 74 61 72 74 * True if pStart
a0b0: 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 73 obtained from s
a0c0: 71 6c 69 74 65 33 5f 6d 61 6c 6c 6f 63 28 29 20 qlite3_malloc()
a0d0: 2a 2f 0a 20 20 69 6e 74 20 6e 4f 75 74 3b 20 20 */. int nOut;
a0e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
a0f0: 4e 75 6d 62 65 72 20 6f 66 20 62 75 66 66 65 72 Number of buffer
a100: 73 20 63 75 72 72 65 6e 74 6c 79 20 63 68 65 63 s currently chec
a110: 6b 65 64 20 6f 75 74 20 2a 2f 0a 20 20 69 6e 74 ked out */. int
a120: 20 6d 78 4f 75 74 3b 20 20 20 20 20 20 20 20 20 mxOut;
a130: 20 20 20 20 20 2f 2a 20 48 69 67 68 77 61 74 65 /* Highwate
a140: 72 20 6d 61 72 6b 20 66 6f 72 20 6e 4f 75 74 20 r mark for nOut
a150: 2a 2f 0a 20 20 69 6e 74 20 61 6e 53 74 61 74 5b */. int anStat[
a160: 33 5d 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 3]; /*
a170: 30 3a 20 68 69 74 73 2e 20 20 31 3a 20 73 69 7a 0: hits. 1: siz
a180: 65 20 6d 69 73 73 65 73 2e 20 20 32 3a 20 66 75 e misses. 2: fu
a190: 6c 6c 20 6d 69 73 73 65 73 20 2a 2f 0a 20 20 4c ll misses */. L
a1a0: 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 2a 70 46 ookasideSlot *pF
a1b0: 72 65 65 3b 20 20 20 2f 2a 20 4c 69 73 74 20 6f ree; /* List o
a1c0: 66 20 61 76 61 69 6c 61 62 6c 65 20 62 75 66 66 f available buff
a1d0: 65 72 73 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ers */. void *p
a1e0: 53 74 61 72 74 3b 20 20 20 20 20 20 20 20 20 20 Start;
a1f0: 20 2f 2a 20 46 69 72 73 74 20 62 79 74 65 20 6f /* First byte o
a200: 66 20 61 76 61 69 6c 61 62 6c 65 20 6d 65 6d 6f f available memo
a210: 72 79 20 73 70 61 63 65 20 2a 2f 0a 20 20 76 6f ry space */. vo
a220: 69 64 20 2a 70 45 6e 64 3b 20 20 20 20 20 20 20 id *pEnd;
a230: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 62 /* First b
a240: 79 74 65 20 70 61 73 74 20 65 6e 64 20 6f 66 20 yte past end of
a250: 61 76 61 69 6c 61 62 6c 65 20 73 70 61 63 65 20 available space
a260: 2a 2f 0a 7d 3b 0a 73 74 72 75 63 74 20 4c 6f 6f */.};.struct Loo
a270: 6b 61 73 69 64 65 53 6c 6f 74 20 7b 0a 20 20 4c kasideSlot {. L
a280: 6f 6f 6b 61 73 69 64 65 53 6c 6f 74 20 2a 70 4e ookasideSlot *pN
a290: 65 78 74 3b 20 20 20 20 2f 2a 20 4e 65 78 74 20 ext; /* Next
a2a0: 62 75 66 66 65 72 20 69 6e 20 74 68 65 20 6c 69 buffer in the li
a2b0: 73 74 20 6f 66 20 66 72 65 65 20 62 75 66 66 65 st of free buffe
a2c0: 72 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 rs */.};../*.**
a2d0: 41 20 68 61 73 68 20 74 61 62 6c 65 20 66 6f 72 A hash table for
a2e0: 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e 63 74 69 built-in functi
a2f0: 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e 20 on definitions.
a300: 20 28 41 70 70 6c 69 63 61 74 69 6f 6e 2d 64 65 (Application-de
a310: 66 69 6e 65 64 0a 2a 2a 20 66 75 6e 63 74 69 6f fined.** functio
a320: 6e 73 20 75 73 65 20 61 20 72 65 67 75 6c 61 72 ns use a regular
a330: 20 74 61 62 6c 65 20 74 61 62 6c 65 20 66 72 6f table table fro
a340: 6d 20 68 61 73 68 2e 68 2e 29 0a 2a 2a 0a 2a 2a m hash.h.).**.**
a350: 20 48 61 73 68 20 65 61 63 68 20 46 75 6e 63 44 Hash each FuncD
a360: 65 66 20 73 74 72 75 63 74 75 72 65 20 69 6e 74 ef structure int
a370: 6f 20 6f 6e 65 20 6f 66 20 74 68 65 20 46 75 6e o one of the Fun
a380: 63 44 65 66 48 61 73 68 2e 61 5b 5d 20 73 6c 6f cDefHash.a[] slo
a390: 74 73 2e 0a 2a 2a 20 43 6f 6c 6c 69 73 69 6f 6e ts..** Collision
a3a0: 73 20 61 72 65 20 6f 6e 20 74 68 65 20 46 75 6e s are on the Fun
a3b0: 63 44 65 66 2e 75 2e 70 48 61 73 68 20 63 68 61 cDef.u.pHash cha
a3c0: 69 6e 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 in..*/.#define S
a3d0: 51 4c 49 54 45 5f 46 55 4e 43 5f 48 41 53 48 5f QLITE_FUNC_HASH_
a3e0: 53 5a 20 32 33 0a 73 74 72 75 63 74 20 46 75 6e SZ 23.struct Fun
a3f0: 63 44 65 66 48 61 73 68 20 7b 0a 20 20 46 75 6e cDefHash {. Fun
a400: 63 44 65 66 20 2a 61 5b 53 51 4c 49 54 45 5f 46 cDef *a[SQLITE_F
a410: 55 4e 43 5f 48 41 53 48 5f 53 5a 5d 3b 20 20 20 UNC_HASH_SZ];
a420: 20 20 20 20 2f 2a 20 48 61 73 68 20 74 61 62 6c /* Hash tabl
a430: 65 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 e for functions
a440: 2a 2f 0a 7d 3b 0a 0a 23 69 66 64 65 66 20 53 51 */.};..#ifdef SQ
a450: 4c 49 54 45 5f 55 53 45 52 5f 41 55 54 48 45 4e LITE_USER_AUTHEN
a460: 54 49 43 41 54 49 4f 4e 0a 2f 2a 0a 2a 2a 20 49 TICATION./*.** I
a470: 6e 66 6f 72 6d 61 74 69 6f 6e 20 68 65 6c 64 20 nformation held
a480: 69 6e 20 74 68 65 20 22 73 71 6c 69 74 65 33 22 in the "sqlite3"
a490: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
a4a0: 74 69 6f 6e 20 6f 62 6a 65 63 74 20 61 6e 64 20 tion object and
a4b0: 75 73 65 64 0a 2a 2a 20 74 6f 20 6d 61 6e 61 67 used.** to manag
a4c0: 65 20 75 73 65 72 20 61 75 74 68 65 6e 74 69 63 e user authentic
a4d0: 61 74 69 6f 6e 2e 0a 2a 2f 0a 74 79 70 65 64 65 ation..*/.typede
a4e0: 66 20 73 74 72 75 63 74 20 73 71 6c 69 74 65 33 f struct sqlite3
a4f0: 5f 75 73 65 72 61 75 74 68 20 73 71 6c 69 74 65 _userauth sqlite
a500: 33 5f 75 73 65 72 61 75 74 68 3b 0a 73 74 72 75 3_userauth;.stru
a510: 63 74 20 73 71 6c 69 74 65 33 5f 75 73 65 72 61 ct sqlite3_usera
a520: 75 74 68 20 7b 0a 20 20 75 38 20 61 75 74 68 4c uth {. u8 authL
a530: 65 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 evel;
a540: 20 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 /* Current
a550: 20 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 authentication
a560: 6c 65 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 6e level */. int n
a570: 41 75 74 68 50 57 3b 20 20 20 20 20 20 20 20 20 AuthPW;
a580: 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 /* Size
a590: 20 6f 66 20 74 68 65 20 7a 41 75 74 68 50 57 20 of the zAuthPW
a5a0: 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 63 68 in bytes */. ch
a5b0: 61 72 20 2a 7a 41 75 74 68 50 57 3b 20 20 20 20 ar *zAuthPW;
a5c0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 /* P
a5d0: 61 73 73 77 6f 72 64 20 75 73 65 64 20 74 6f 20 assword used to
a5e0: 61 75 74 68 65 6e 74 69 63 61 74 65 20 2a 2f 0a authenticate */.
a5f0: 20 20 63 68 61 72 20 2a 7a 41 75 74 68 55 73 65 char *zAuthUse
a600: 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r;
a610: 2f 2a 20 55 73 65 72 20 6e 61 6d 65 20 75 73 65 /* User name use
a620: 64 20 74 6f 20 61 75 74 68 65 6e 74 69 63 61 74 d to authenticat
a630: 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f e */.};../* Allo
a640: 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 73 wed values for s
a650: 71 6c 69 74 65 33 5f 75 73 65 72 61 75 74 68 2e qlite3_userauth.
a660: 61 75 74 68 4c 65 76 65 6c 20 2a 2f 0a 23 64 65 authLevel */.#de
a670: 66 69 6e 65 20 55 41 55 54 48 5f 55 6e 6b 6e 6f fine UAUTH_Unkno
a680: 77 6e 20 20 20 20 20 30 20 20 20 20 20 2f 2a 20 wn 0 /*
a690: 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 20 6e Authentication n
a6a0: 6f 74 20 79 65 74 20 63 68 65 63 6b 65 64 20 2a ot yet checked *
a6b0: 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 5f /.#define UAUTH_
a6c0: 46 61 69 6c 20 20 20 20 20 20 20 20 31 20 20 20 Fail 1
a6d0: 20 20 2f 2a 20 55 73 65 72 20 61 75 74 68 65 6e /* User authen
a6e0: 74 69 63 61 74 69 6f 6e 20 66 61 69 6c 65 64 20 tication failed
a6f0: 2a 2f 0a 23 64 65 66 69 6e 65 20 55 41 55 54 48 */.#define UAUTH
a700: 5f 55 73 65 72 20 20 20 20 20 20 20 20 32 20 20 _User 2
a710: 20 20 20 2f 2a 20 41 75 74 68 65 6e 74 69 63 61 /* Authentica
a720: 74 65 64 20 61 73 20 61 20 6e 6f 72 6d 61 6c 20 ted as a normal
a730: 75 73 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 user */.#define
a740: 55 41 55 54 48 5f 41 64 6d 69 6e 20 20 20 20 20 UAUTH_Admin
a750: 20 20 33 20 20 20 20 20 2f 2a 20 41 75 74 68 65 3 /* Authe
a760: 6e 74 69 63 61 74 65 64 20 61 73 20 61 6e 20 61 nticated as an a
a770: 64 6d 69 6e 69 73 74 72 61 74 6f 72 20 2a 2f 0a dministrator */.
a780: 0a 2f 2a 20 46 75 6e 63 74 69 6f 6e 73 20 75 73 ./* Functions us
a790: 65 64 20 6f 6e 6c 79 20 62 79 20 75 73 65 72 20 ed only by user
a7a0: 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 6c 6f authorization lo
a7b0: 67 69 63 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 gic */.int sqlit
a7c0: 65 33 55 73 65 72 41 75 74 68 54 61 62 6c 65 28 e3UserAuthTable(
a7d0: 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e const char*);.in
a7e0: 74 20 73 71 6c 69 74 65 33 55 73 65 72 41 75 74 t sqlite3UserAut
a7f0: 68 43 68 65 63 6b 4c 6f 67 69 6e 28 73 71 6c 69 hCheckLogin(sqli
a800: 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a te3*,const char*
a810: 2c 75 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,u8*);.void sqli
a820: 74 65 33 55 73 65 72 41 75 74 68 49 6e 69 74 28 te3UserAuthInit(
a830: 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 sqlite3*);.void
a840: 73 71 6c 69 74 65 33 43 72 79 70 74 46 75 6e 63 sqlite3CryptFunc
a850: 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
a860: 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 *,int,sqlite3_va
a870: 6c 75 65 2a 2a 29 3b 0a 0a 23 65 6e 64 69 66 20 lue**);..#endif
a880: 2f 2a 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 /* SQLITE_USER_A
a890: 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 20 2a 2f UTHENTICATION */
a8a0: 0a 0a 2f 2a 0a 2a 2a 20 74 79 70 65 64 65 66 20 ../*.** typedef
a8b0: 66 6f 72 20 74 68 65 20 61 75 74 68 6f 72 69 7a for the authoriz
a8c0: 61 74 69 6f 6e 20 63 61 6c 6c 62 61 63 6b 20 66 ation callback f
a8d0: 75 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 64 unction..*/.#ifd
a8e0: 65 66 20 53 51 4c 49 54 45 5f 55 53 45 52 5f 41 ef SQLITE_USER_A
a8f0: 55 54 48 45 4e 54 49 43 41 54 49 4f 4e 0a 20 20 UTHENTICATION.
a900: 74 79 70 65 64 65 66 20 69 6e 74 20 28 2a 73 71 typedef int (*sq
a910: 6c 69 74 65 33 5f 78 61 75 74 68 29 28 76 6f 69 lite3_xauth)(voi
a920: 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 d*,int,const cha
a930: 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 r*,const char*,c
a940: 6f 6e 73 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 onst char*,.
a950: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a960: 20 20 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 const
a970: 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 char*, const ch
a980: 61 72 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 74 79 ar*);.#else. ty
a990: 70 65 64 65 66 20 69 6e 74 20 28 2a 73 71 6c 69 pedef int (*sqli
a9a0: 74 65 33 5f 78 61 75 74 68 29 28 76 6f 69 64 2a te3_xauth)(void*
a9b0: 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
a9c0: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e ,const char*,con
a9d0: 73 74 20 63 68 61 72 2a 2c 0a 20 20 20 20 20 20 st char*,.
a9e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a9f0: 20 20 20 20 20 20 20 20 20 63 6f 6e 73 74 20 63 const c
aa00: 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 23 har*);.#endif..#
aa10: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
aa20: 49 54 5f 44 45 50 52 45 43 41 54 45 44 0a 2f 2a IT_DEPRECATED./*
aa30: 20 54 68 69 73 20 69 73 20 61 6e 20 65 78 74 72 This is an extr
aa40: 61 20 53 51 4c 49 54 45 5f 54 52 41 43 45 20 6d a SQLITE_TRACE m
aa50: 61 63 72 6f 20 74 68 61 74 20 69 6e 64 69 63 61 acro that indica
aa60: 74 65 73 20 22 6c 65 67 61 63 79 22 20 74 72 61 tes "legacy" tra
aa70: 63 69 6e 67 0a 2a 2a 20 69 6e 20 74 68 65 20 73 cing.** in the s
aa80: 74 79 6c 65 20 6f 66 20 73 71 6c 69 74 65 33 5f tyle of sqlite3_
aa90: 74 72 61 63 65 28 29 0a 2a 2f 0a 23 64 65 66 69 trace().*/.#defi
aaa0: 6e 65 20 53 51 4c 49 54 45 5f 54 52 41 43 45 5f ne SQLITE_TRACE_
aab0: 4c 45 47 41 43 59 20 20 30 78 38 30 0a 23 65 6c LEGACY 0x80.#el
aac0: 73 65 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 se.#define SQLIT
aad0: 45 5f 54 52 41 43 45 5f 4c 45 47 41 43 59 20 20 E_TRACE_LEGACY
aae0: 30 0a 23 65 6e 64 69 66 20 2f 2a 20 53 51 4c 49 0.#endif /* SQLI
aaf0: 54 45 5f 4f 4d 49 54 5f 44 45 50 52 45 43 41 54 TE_OMIT_DEPRECAT
ab00: 45 44 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 45 61 ED */.../*.** Ea
ab10: 63 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e ch database conn
ab20: 65 63 74 69 6f 6e 20 69 73 20 61 6e 20 69 6e 73 ection is an ins
ab30: 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 6f 6c tance of the fol
ab40: 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 lowing structure
ab50: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 73 71 6c 69 ..*/.struct sqli
ab60: 74 65 33 20 7b 0a 20 20 73 71 6c 69 74 65 33 5f te3 {. sqlite3_
ab70: 76 66 73 20 2a 70 56 66 73 3b 20 20 20 20 20 20 vfs *pVfs;
ab80: 20 20 20 20 20 20 2f 2a 20 4f 53 20 49 6e 74 65 /* OS Inte
ab90: 72 66 61 63 65 20 2a 2f 0a 20 20 73 74 72 75 63 rface */. struc
aba0: 74 20 56 64 62 65 20 2a 70 56 64 62 65 3b 20 20 t Vdbe *pVdbe;
abb0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 /* List
abc0: 20 6f 66 20 61 63 74 69 76 65 20 76 69 72 74 75 of active virtu
abd0: 61 6c 20 6d 61 63 68 69 6e 65 73 20 2a 2f 0a 20 al machines */.
abe0: 20 43 6f 6c 6c 53 65 71 20 2a 70 44 66 6c 74 43 CollSeq *pDfltC
abf0: 6f 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f oll; /
ac00: 2a 20 54 68 65 20 64 65 66 61 75 6c 74 20 63 6f * The default co
ac10: 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 llating sequence
ac20: 20 28 42 49 4e 41 52 59 29 20 2a 2f 0a 20 20 73 (BINARY) */. s
ac30: 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 6d 75 qlite3_mutex *mu
ac40: 74 65 78 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 tex; /*
ac50: 43 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 74 65 78 Connection mutex
ac60: 20 2a 2f 0a 20 20 44 62 20 2a 61 44 62 3b 20 20 */. Db *aDb;
ac70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ac80: 20 20 20 20 2f 2a 20 41 6c 6c 20 62 61 63 6b 65 /* All backe
ac90: 6e 64 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 44 62 nds */. int nDb
aca0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
acb0: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
acc0: 20 6f 66 20 62 61 63 6b 65 6e 64 73 20 63 75 72 of backends cur
acd0: 72 65 6e 74 6c 79 20 69 6e 20 75 73 65 20 2a 2f rently in use */
ace0: 0a 20 20 69 6e 74 20 66 6c 61 67 73 3b 20 20 20 . int flags;
acf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ad00: 20 2f 2a 20 4d 69 73 63 65 6c 6c 61 6e 65 6f 75 /* Miscellaneou
ad10: 73 20 66 6c 61 67 73 2e 20 53 65 65 20 62 65 6c s flags. See bel
ad20: 6f 77 20 2a 2f 0a 20 20 69 36 34 20 6c 61 73 74 ow */. i64 last
ad30: 52 6f 77 69 64 3b 20 20 20 20 20 20 20 20 20 20 Rowid;
ad40: 20 20 20 20 20 20 2f 2a 20 52 4f 57 49 44 20 6f /* ROWID o
ad50: 66 20 6d 6f 73 74 20 72 65 63 65 6e 74 20 69 6e f most recent in
ad60: 73 65 72 74 20 28 73 65 65 20 61 62 6f 76 65 29 sert (see above)
ad70: 20 2a 2f 0a 20 20 69 36 34 20 73 7a 4d 6d 61 70 */. i64 szMmap
ad80: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
ad90: 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 6d /* Default m
ada0: 6d 61 70 5f 73 69 7a 65 20 73 65 74 74 69 6e 67 map_size setting
adb0: 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 */. unsigned i
adc0: 6e 74 20 6f 70 65 6e 46 6c 61 67 73 3b 20 20 20 nt openFlags;
add0: 20 20 20 20 2f 2a 20 46 6c 61 67 73 20 70 61 73 /* Flags pas
ade0: 73 65 64 20 74 6f 20 73 71 6c 69 74 65 33 5f 76 sed to sqlite3_v
adf0: 66 73 2e 78 4f 70 65 6e 28 29 20 2a 2f 0a 20 20 fs.xOpen() */.
ae00: 69 6e 74 20 65 72 72 43 6f 64 65 3b 20 20 20 20 int errCode;
ae10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
ae20: 20 4d 6f 73 74 20 72 65 63 65 6e 74 20 65 72 72 Most recent err
ae30: 6f 72 20 63 6f 64 65 20 28 53 51 4c 49 54 45 5f or code (SQLITE_
ae40: 2a 29 20 2a 2f 0a 20 20 69 6e 74 20 65 72 72 4d *) */. int errM
ae50: 61 73 6b 3b 20 20 20 20 20 20 20 20 20 20 20 20 ask;
ae60: 20 20 20 20 20 20 2f 2a 20 26 20 72 65 73 75 6c /* & resul
ae70: 74 20 63 6f 64 65 73 20 77 69 74 68 20 74 68 69 t codes with thi
ae80: 73 20 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 s before returni
ae90: 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 69 53 79 73 ng */. int iSys
aea0: 45 72 72 6e 6f 3b 20 20 20 20 20 20 20 20 20 20 Errno;
aeb0: 20 20 20 20 20 20 2f 2a 20 45 72 72 6e 6f 20 76 /* Errno v
aec0: 61 6c 75 65 20 66 72 6f 6d 20 6c 61 73 74 20 73 alue from last s
aed0: 79 73 74 65 6d 20 65 72 72 6f 72 20 2a 2f 0a 20 ystem error */.
aee0: 20 75 31 36 20 64 62 4f 70 74 46 6c 61 67 73 3b u16 dbOptFlags;
aef0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
af00: 2a 20 46 6c 61 67 73 20 74 6f 20 65 6e 61 62 6c * Flags to enabl
af10: 65 2f 64 69 73 61 62 6c 65 20 6f 70 74 69 6d 69 e/disable optimi
af20: 7a 61 74 69 6f 6e 73 20 2a 2f 0a 20 20 75 38 20 zations */. u8
af30: 65 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 enc;
af40: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 /* Te
af50: 78 74 20 65 6e 63 6f 64 69 6e 67 20 2a 2f 0a 20 xt encoding */.
af60: 20 75 38 20 61 75 74 6f 43 6f 6d 6d 69 74 3b 20 u8 autoCommit;
af70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
af80: 2a 20 54 68 65 20 61 75 74 6f 2d 63 6f 6d 6d 69 * The auto-commi
af90: 74 20 66 6c 61 67 2e 20 2a 2f 0a 20 20 75 38 20 t flag. */. u8
afa0: 74 65 6d 70 5f 73 74 6f 72 65 3b 20 20 20 20 20 temp_store;
afb0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 3a /* 1:
afc0: 20 66 69 6c 65 20 32 3a 20 6d 65 6d 6f 72 79 20 file 2: memory
afd0: 30 3a 20 64 65 66 61 75 6c 74 20 2a 2f 0a 20 20 0: default */.
afe0: 75 38 20 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 3b u8 mallocFailed;
aff0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
b000: 20 54 72 75 65 20 69 66 20 77 65 20 68 61 76 65 True if we have
b010: 20 73 65 65 6e 20 61 20 6d 61 6c 6c 6f 63 20 66 seen a malloc f
b020: 61 69 6c 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 ailure */. u8 b
b030: 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 3b 20 20 20 BenignMalloc;
b040: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 6f 20 /* Do
b050: 6e 6f 74 20 72 65 71 75 69 72 65 20 4f 4f 4d 73 not require OOMs
b060: 20 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 if true */. u8
b070: 20 64 66 6c 74 4c 6f 63 6b 4d 6f 64 65 3b 20 20 dfltLockMode;
b080: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 /* D
b090: 65 66 61 75 6c 74 20 6c 6f 63 6b 69 6e 67 2d 6d efault locking-m
b0a0: 6f 64 65 20 66 6f 72 20 61 74 74 61 63 68 65 64 ode for attached
b0b0: 20 64 62 73 20 2a 2f 0a 20 20 73 69 67 6e 65 64 dbs */. signed
b0c0: 20 63 68 61 72 20 6e 65 78 74 41 75 74 6f 76 61 char nextAutova
b0d0: 63 3b 20 20 20 20 20 20 2f 2a 20 41 75 74 6f 76 c; /* Autov
b0e0: 61 63 20 73 65 74 74 69 6e 67 20 61 66 74 65 72 ac setting after
b0f0: 20 56 41 43 55 55 4d 20 69 66 20 3e 3d 30 20 2a VACUUM if >=0 *
b100: 2f 0a 20 20 75 38 20 73 75 70 70 72 65 73 73 45 /. u8 suppressE
b110: 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rr;
b120: 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 69 73 73 75 /* Do not issu
b130: 65 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 e error messages
b140: 20 69 66 20 74 72 75 65 20 2a 2f 0a 20 20 75 38 if true */. u8
b150: 20 76 74 61 62 4f 6e 43 6f 6e 66 6c 69 63 74 3b vtabOnConflict;
b160: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 /* V
b170: 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 66 alue to return f
b180: 6f 72 20 73 33 5f 76 74 61 62 5f 6f 6e 5f 63 6f or s3_vtab_on_co
b190: 6e 66 6c 69 63 74 28 29 20 2a 2f 0a 20 20 75 38 nflict() */. u8
b1a0: 20 69 73 54 72 61 6e 73 61 63 74 69 6f 6e 53 61 isTransactionSa
b1b0: 76 65 70 6f 69 6e 74 3b 20 20 20 20 2f 2a 20 54 vepoint; /* T
b1c0: 72 75 65 20 69 66 20 74 68 65 20 6f 75 74 65 72 rue if the outer
b1d0: 6d 6f 73 74 20 73 61 76 65 70 6f 69 6e 74 20 69 most savepoint i
b1e0: 73 20 61 20 54 53 20 2a 2f 0a 20 20 75 38 20 6d s a TS */. u8 m
b1f0: 54 72 61 63 65 3b 20 20 20 20 20 20 20 20 20 20 Trace;
b200: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 7a 65 72 /* zer
b210: 6f 20 6f 72 20 6d 6f 72 65 20 53 51 4c 49 54 45 o or more SQLITE
b220: 5f 54 52 41 43 45 20 66 6c 61 67 73 20 2a 2f 0a _TRACE flags */.
b230: 20 20 69 6e 74 20 6e 65 78 74 50 61 67 65 73 69 int nextPagesi
b240: 7a 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ze;
b250: 2f 2a 20 50 61 67 65 73 69 7a 65 20 61 66 74 65 /* Pagesize afte
b260: 72 20 56 41 43 55 55 4d 20 69 66 20 3e 30 20 2a r VACUUM if >0 *
b270: 2f 0a 20 20 75 33 32 20 6d 61 67 69 63 3b 20 20 /. u32 magic;
b280: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b290: 20 20 2f 2a 20 4d 61 67 69 63 20 6e 75 6d 62 65 /* Magic numbe
b2a0: 72 20 66 6f 72 20 64 65 74 65 63 74 20 6c 69 62 r for detect lib
b2b0: 72 61 72 79 20 6d 69 73 75 73 65 20 2a 2f 0a 20 rary misuse */.
b2c0: 20 69 6e 74 20 6e 43 68 61 6e 67 65 3b 20 20 20 int nChange;
b2d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
b2e0: 2a 20 56 61 6c 75 65 20 72 65 74 75 72 6e 65 64 * Value returned
b2f0: 20 62 79 20 73 71 6c 69 74 65 33 5f 63 68 61 6e by sqlite3_chan
b300: 67 65 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e ges() */. int n
b310: 54 6f 74 61 6c 43 68 61 6e 67 65 3b 20 20 20 20 TotalChange;
b320: 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 /* Valu
b330: 65 20 72 65 74 75 72 6e 65 64 20 62 79 20 73 71 e returned by sq
b340: 6c 69 74 65 33 5f 74 6f 74 61 6c 5f 63 68 61 6e lite3_total_chan
b350: 67 65 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 61 ges() */. int a
b360: 4c 69 6d 69 74 5b 53 51 4c 49 54 45 5f 4e 5f 4c Limit[SQLITE_N_L
b370: 49 4d 49 54 5d 3b 20 20 20 2f 2a 20 4c 69 6d 69 IMIT]; /* Limi
b380: 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4d 61 78 ts */. int nMax
b390: 53 6f 72 74 65 72 4d 6d 61 70 3b 20 20 20 20 20 SorterMmap;
b3a0: 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d /* Maximum
b3b0: 20 73 69 7a 65 20 6f 66 20 72 65 67 69 6f 6e 73 size of regions
b3c0: 20 6d 61 70 70 65 64 20 62 79 20 73 6f 72 74 65 mapped by sorte
b3d0: 72 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 73 71 r */. struct sq
b3e0: 6c 69 74 65 33 49 6e 69 74 49 6e 66 6f 20 7b 20 lite3InitInfo {
b3f0: 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 /* Informat
b400: 69 6f 6e 20 75 73 65 64 20 64 75 72 69 6e 67 20 ion used during
b410: 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 2a initialization *
b420: 2f 0a 20 20 20 20 69 6e 74 20 6e 65 77 54 6e 75 /. int newTnu
b430: 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 m;
b440: 20 20 2f 2a 20 52 6f 6f 74 70 61 67 65 20 6f 66 /* Rootpage of
b450: 20 74 61 62 6c 65 20 62 65 69 6e 67 20 69 6e 69 table being ini
b460: 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 20 tialized */.
b470: 75 38 20 69 44 62 3b 20 20 20 20 20 20 20 20 20 u8 iDb;
b480: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 /* W
b490: 68 69 63 68 20 64 62 20 66 69 6c 65 20 69 73 20 hich db file is
b4a0: 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 65 being initialize
b4b0: 64 20 2a 2f 0a 20 20 20 20 75 38 20 62 75 73 79 d */. u8 busy
b4c0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
b4d0: 20 20 20 20 20 2f 2a 20 54 52 55 45 20 69 66 20 /* TRUE if
b4e0: 63 75 72 72 65 6e 74 6c 79 20 69 6e 69 74 69 61 currently initia
b4f0: 6c 69 7a 69 6e 67 20 2a 2f 0a 20 20 20 20 75 38 lizing */. u8
b500: 20 6f 72 70 68 61 6e 54 72 69 67 67 65 72 3b 20 orphanTrigger;
b510: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 61 73 /* Las
b520: 74 20 73 74 61 74 65 6d 65 6e 74 20 69 73 20 6f t statement is o
b530: 72 70 68 61 6e 65 64 20 54 45 4d 50 20 74 72 69 rphaned TEMP tri
b540: 67 67 65 72 20 2a 2f 0a 20 20 20 20 75 38 20 69 gger */. u8 i
b550: 6d 70 6f 73 74 65 72 54 61 62 6c 65 3b 20 20 20 mposterTable;
b560: 20 20 20 20 20 20 20 20 2f 2a 20 42 75 69 6c 64 /* Build
b570: 69 6e 67 20 61 6e 20 69 6d 70 6f 73 74 65 72 20 ing an imposter
b580: 74 61 62 6c 65 20 2a 2f 0a 20 20 7d 20 69 6e 69 table */. } ini
b590: 74 3b 0a 20 20 69 6e 74 20 6e 56 64 62 65 41 63 t;. int nVdbeAc
b5a0: 74 69 76 65 3b 20 20 20 20 20 20 20 20 20 20 20 tive;
b5b0: 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
b5c0: 56 44 42 45 73 20 63 75 72 72 65 6e 74 6c 79 20 VDBEs currently
b5d0: 72 75 6e 6e 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 running */. int
b5e0: 20 6e 56 64 62 65 52 65 61 64 3b 20 20 20 20 20 nVdbeRead;
b5f0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
b600: 6d 62 65 72 20 6f 66 20 61 63 74 69 76 65 20 56 mber of active V
b610: 44 42 45 73 20 74 68 61 74 20 72 65 61 64 20 6f DBEs that read o
b620: 72 20 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 r write */. int
b630: 20 6e 56 64 62 65 57 72 69 74 65 3b 20 20 20 20 nVdbeWrite;
b640: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
b650: 6d 62 65 72 20 6f 66 20 61 63 74 69 76 65 20 56 mber of active V
b660: 44 42 45 73 20 74 68 61 74 20 72 65 61 64 20 61 DBEs that read a
b670: 6e 64 20 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e nd write */. in
b680: 74 20 6e 56 64 62 65 45 78 65 63 3b 20 20 20 20 t nVdbeExec;
b690: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
b6a0: 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 umber of nested
b6b0: 63 61 6c 6c 73 20 74 6f 20 56 64 62 65 45 78 65 calls to VdbeExe
b6c0: 63 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 56 44 c() */. int nVD
b6d0: 65 73 74 72 6f 79 3b 20 20 20 20 20 20 20 20 20 estroy;
b6e0: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
b6f0: 20 6f 66 20 61 63 74 69 76 65 20 4f 50 5f 56 44 of active OP_VD
b700: 65 73 74 72 6f 79 20 6f 70 65 72 61 74 69 6f 6e estroy operation
b710: 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 78 74 65 s */. int nExte
b720: 6e 73 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 nsion;
b730: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
b740: 66 20 6c 6f 61 64 65 64 20 65 78 74 65 6e 73 69 f loaded extensi
b750: 6f 6e 73 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 2a ons */. void **
b760: 61 45 78 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 aExtension;
b770: 20 20 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 /* Array
b780: 6f 66 20 73 68 61 72 65 64 20 6c 69 62 72 61 72 of shared librar
b790: 79 20 68 61 6e 64 6c 65 73 20 2a 2f 0a 20 20 69 y handles */. i
b7a0: 6e 74 20 28 2a 78 54 72 61 63 65 29 28 75 33 32 nt (*xTrace)(u32
b7b0: 2c 76 6f 69 64 2a 2c 76 6f 69 64 2a 2c 76 6f 69 ,void*,void*,voi
b7c0: 64 2a 29 3b 20 20 20 20 20 2f 2a 20 54 72 61 63 d*); /* Trac
b7d0: 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 e function */.
b7e0: 76 6f 69 64 20 2a 70 54 72 61 63 65 41 72 67 3b void *pTraceArg;
b7f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b800: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 /* Arg
b810: 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 74 72 61 ument to the tra
b820: 63 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 ce function */.
b830: 20 76 6f 69 64 20 28 2a 78 50 72 6f 66 69 6c 65 void (*xProfile
b840: 29 28 76 6f 69 64 2a 2c 63 6f 6e 73 74 20 63 68 )(void*,const ch
b850: 61 72 2a 2c 75 36 34 29 3b 20 20 2f 2a 20 50 72 ar*,u64); /* Pr
b860: 6f 66 69 6c 69 6e 67 20 66 75 6e 63 74 69 6f 6e ofiling function
b870: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f */. void *pPro
b880: 66 69 6c 65 41 72 67 3b 20 20 20 20 20 20 20 20 fileArg;
b890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
b8a0: 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 70 /* Argument to p
b8b0: 72 6f 66 69 6c 65 20 66 75 6e 63 74 69 6f 6e 20 rofile function
b8c0: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6d 6d */. void *pComm
b8d0: 69 74 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 itArg;
b8e0: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
b8f0: 6e 74 20 74 6f 20 78 43 6f 6d 6d 69 74 43 61 6c nt to xCommitCal
b900: 6c 62 61 63 6b 28 29 20 2a 2f 0a 20 20 69 6e 74 lback() */. int
b910: 20 28 2a 78 43 6f 6d 6d 69 74 43 61 6c 6c 62 61 (*xCommitCallba
b920: 63 6b 29 28 76 6f 69 64 2a 29 3b 20 20 20 20 2f ck)(void*); /
b930: 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 * Invoked at eve
b940: 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 ry commit. */.
b950: 76 6f 69 64 20 2a 70 52 6f 6c 6c 62 61 63 6b 41 void *pRollbackA
b960: 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rg;
b970: 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f /* Argument to
b980: 20 78 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 xRollbackCallba
b990: 63 6b 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 28 ck() */. void (
b9a0: 2a 78 52 6f 6c 6c 62 61 63 6b 43 61 6c 6c 62 61 *xRollbackCallba
b9b0: 63 6b 29 28 76 6f 69 64 2a 29 3b 20 2f 2a 20 49 ck)(void*); /* I
b9c0: 6e 76 6f 6b 65 64 20 61 74 20 65 76 65 72 79 20 nvoked at every
b9d0: 63 6f 6d 6d 69 74 2e 20 2a 2f 0a 20 20 76 6f 69 commit. */. voi
b9e0: 64 20 2a 70 55 70 64 61 74 65 41 72 67 3b 0a 20 d *pUpdateArg;.
b9f0: 20 76 6f 69 64 20 28 2a 78 55 70 64 61 74 65 43 void (*xUpdateC
ba00: 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 2c 69 allback)(void*,i
ba10: 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c nt, const char*,
ba20: 63 6f 6e 73 74 20 63 68 61 72 2a 2c 73 71 6c 69 const char*,sqli
ba30: 74 65 5f 69 6e 74 36 34 29 3b 0a 23 69 66 64 65 te_int64);.#ifde
ba40: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
ba50: 50 52 45 55 50 44 41 54 45 5f 48 4f 4f 4b 0a 20 PREUPDATE_HOOK.
ba60: 20 76 6f 69 64 20 2a 70 50 72 65 55 70 64 61 74 void *pPreUpdat
ba70: 65 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 2f eArg; /
ba80: 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 * First argument
ba90: 20 74 6f 20 78 50 72 65 55 70 64 61 74 65 43 61 to xPreUpdateCa
baa0: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 llback */. void
bab0: 20 28 2a 78 50 72 65 55 70 64 61 74 65 43 61 6c (*xPreUpdateCal
bac0: 6c 62 61 63 6b 29 28 20 20 20 2f 2a 20 52 65 67 lback)( /* Reg
bad0: 69 73 74 65 72 65 64 20 75 73 69 6e 67 20 73 71 istered using sq
bae0: 6c 69 74 65 33 5f 70 72 65 75 70 64 61 74 65 5f lite3_preupdate_
baf0: 68 6f 6f 6b 28 29 20 2a 2f 0a 20 20 20 20 76 6f hook() */. vo
bb00: 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 69 6e 74 id*,sqlite3*,int
bb10: 2c 63 68 61 72 20 63 6f 6e 73 74 2a 2c 63 68 61 ,char const*,cha
bb20: 72 20 63 6f 6e 73 74 2a 2c 73 71 6c 69 74 65 33 r const*,sqlite3
bb30: 5f 69 6e 74 36 34 2c 73 71 6c 69 74 65 33 5f 69 _int64,sqlite3_i
bb40: 6e 74 36 34 0a 20 20 29 3b 0a 20 20 50 72 65 55 nt64. );. PreU
bb50: 70 64 61 74 65 20 2a 70 50 72 65 55 70 64 61 74 pdate *pPreUpdat
bb60: 65 3b 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e e; /* Con
bb70: 74 65 78 74 20 66 6f 72 20 61 63 74 69 76 65 20 text for active
bb80: 70 72 65 2d 75 70 64 61 74 65 20 63 61 6c 6c 62 pre-update callb
bb90: 61 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 20 2f 2a ack */.#endif /*
bba0: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 50 SQLITE_ENABLE_P
bbb0: 52 45 55 50 44 41 54 45 5f 48 4f 4f 4b 20 2a 2f REUPDATE_HOOK */
bbc0: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
bbd0: 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 28 OMIT_WAL. int (
bbe0: 2a 78 57 61 6c 43 61 6c 6c 62 61 63 6b 29 28 76 *xWalCallback)(v
bbf0: 6f 69 64 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a oid *, sqlite3 *
bc00: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 , const char *,
bc10: 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 57 int);. void *pW
bc20: 61 6c 41 72 67 3b 0a 23 65 6e 64 69 66 0a 20 20 alArg;.#endif.
bc30: 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 void(*xCollNeede
bc40: 64 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 d)(void*,sqlite3
bc50: 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 *,int eTextRep,c
bc60: 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 onst char*);. v
bc70: 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 oid(*xCollNeeded
bc80: 31 36 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 16)(void*,sqlite
bc90: 33 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 3*,int eTextRep,
bca0: 63 6f 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 const void*);.
bcb0: 76 6f 69 64 20 2a 70 43 6f 6c 6c 4e 65 65 64 65 void *pCollNeede
bcc0: 64 41 72 67 3b 0a 20 20 73 71 6c 69 74 65 33 5f dArg;. sqlite3_
bcd0: 76 61 6c 75 65 20 2a 70 45 72 72 3b 20 20 20 20 value *pErr;
bce0: 20 20 20 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 /* Most re
bcf0: 63 65 6e 74 20 65 72 72 6f 72 20 6d 65 73 73 61 cent error messa
bd00: 67 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a ge */. union {.
bd10: 20 20 20 20 76 6f 6c 61 74 69 6c 65 20 69 6e 74 volatile int
bd20: 20 69 73 49 6e 74 65 72 72 75 70 74 65 64 3b 20 isInterrupted;
bd30: 2f 2a 20 54 72 75 65 20 69 66 20 73 71 6c 69 74 /* True if sqlit
bd40: 65 33 5f 69 6e 74 65 72 72 75 70 74 20 68 61 73 e3_interrupt has
bd50: 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a been called */.
bd60: 20 20 20 20 64 6f 75 62 6c 65 20 6e 6f 74 55 73 double notUs
bd70: 65 64 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 ed1;
bd80: 2f 2a 20 53 70 61 63 65 72 20 2a 2f 0a 20 20 7d /* Spacer */. }
bd90: 20 75 31 3b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 u1;. Lookaside
bda0: 20 6c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 lookaside;
bdb0: 20 20 20 20 20 2f 2a 20 4c 6f 6f 6b 61 73 69 64 /* Lookasid
bdc0: 65 20 6d 61 6c 6c 6f 63 20 63 6f 6e 66 69 67 75 e malloc configu
bdd0: 72 61 74 69 6f 6e 20 2a 2f 0a 23 69 66 6e 64 65 ration */.#ifnde
bde0: 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
bdf0: 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 73 71 THORIZATION. sq
be00: 6c 69 74 65 33 5f 78 61 75 74 68 20 78 41 75 74 lite3_xauth xAut
be10: 68 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 h; /* A
be20: 63 63 65 73 73 20 61 75 74 68 6f 72 69 7a 61 74 ccess authorizat
be30: 69 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a ion function */.
be40: 20 20 76 6f 69 64 20 2a 70 41 75 74 68 41 72 67 void *pAuthArg
be50: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
be60: 2f 2a 20 31 73 74 20 61 72 67 75 6d 65 6e 74 20 /* 1st argument
be70: 74 6f 20 74 68 65 20 61 63 63 65 73 73 20 61 75 to the access au
be80: 74 68 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 th function */.#
be90: 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 endif.#ifndef SQ
bea0: 4c 49 54 45 5f 4f 4d 49 54 5f 50 52 4f 47 52 45 LITE_OMIT_PROGRE
beb0: 53 53 5f 43 41 4c 4c 42 41 43 4b 0a 20 20 69 6e SS_CALLBACK. in
bec0: 74 20 28 2a 78 50 72 6f 67 72 65 73 73 29 28 76 t (*xProgress)(v
bed0: 6f 69 64 20 2a 29 3b 20 20 20 20 20 2f 2a 20 54 oid *); /* T
bee0: 68 65 20 70 72 6f 67 72 65 73 73 20 63 61 6c 6c he progress call
bef0: 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a back */. void *
bf00: 70 50 72 6f 67 72 65 73 73 41 72 67 3b 20 20 20 pProgressArg;
bf10: 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d /* Argum
bf20: 65 6e 74 20 74 6f 20 74 68 65 20 70 72 6f 67 72 ent to the progr
bf30: 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a ess callback */.
bf40: 20 20 75 6e 73 69 67 6e 65 64 20 6e 50 72 6f 67 unsigned nProg
bf50: 72 65 73 73 4f 70 73 3b 20 20 20 20 20 20 20 20 ressOps;
bf60: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6f 70 63 /* Number of opc
bf70: 6f 64 65 73 20 66 6f 72 20 70 72 6f 67 72 65 73 odes for progres
bf80: 73 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 23 65 s callback */.#e
bf90: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
bfa0: 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
bfb0: 54 41 42 4c 45 0a 20 20 69 6e 74 20 6e 56 54 72 TABLE. int nVTr
bfc0: 61 6e 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 ans;
bfd0: 20 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 61 74 /* Allocat
bfe0: 65 64 20 73 69 7a 65 20 6f 66 20 61 56 54 72 61 ed size of aVTra
bff0: 6e 73 20 2a 2f 0a 20 20 48 61 73 68 20 61 4d 6f ns */. Hash aMo
c000: 64 75 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 dule;
c010: 20 20 20 20 20 20 2f 2a 20 70 6f 70 75 6c 61 74 /* populat
c020: 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f 63 72 ed by sqlite3_cr
c030: 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f eate_module() */
c040: 0a 20 20 56 74 61 62 43 74 78 20 2a 70 56 74 61 . VtabCtx *pVta
c050: 62 43 74 78 3b 20 20 20 20 20 20 20 20 20 20 20 bCtx;
c060: 20 2f 2a 20 43 6f 6e 74 65 78 74 20 66 6f 72 20 /* Context for
c070: 61 63 74 69 76 65 20 76 74 61 62 20 63 6f 6e 6e active vtab conn
c080: 65 63 74 2f 63 72 65 61 74 65 20 2a 2f 0a 20 20 ect/create */.
c090: 56 54 61 62 6c 65 20 2a 2a 61 56 54 72 61 6e 73 VTable **aVTrans
c0a0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
c0b0: 20 56 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 Virtual tables
c0c0: 77 69 74 68 20 6f 70 65 6e 20 74 72 61 6e 73 61 with open transa
c0d0: 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 56 54 61 62 ctions */. VTab
c0e0: 6c 65 20 2a 70 44 69 73 63 6f 6e 6e 65 63 74 3b le *pDisconnect;
c0f0: 20 20 20 20 2f 2a 20 44 69 73 63 6f 6e 6e 65 63 /* Disconnec
c100: 74 20 74 68 65 73 65 20 69 6e 20 6e 65 78 74 20 t these in next
c110: 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72 65 28 sqlite3_prepare(
c120: 29 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 48 61 ) */.#endif. Ha
c130: 73 68 20 61 46 75 6e 63 3b 20 20 20 20 20 20 20 sh aFunc;
c140: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 /* H
c150: 61 73 68 20 74 61 62 6c 65 20 6f 66 20 63 6f 6e ash table of con
c160: 6e 65 63 74 69 6f 6e 20 66 75 6e 63 74 69 6f 6e nection function
c170: 73 20 2a 2f 0a 20 20 48 61 73 68 20 61 43 6f 6c s */. Hash aCol
c180: 6c 53 65 71 3b 20 20 20 20 20 20 20 20 20 20 20 lSeq;
c190: 20 20 20 20 20 2f 2a 20 41 6c 6c 20 63 6f 6c 6c /* All coll
c1a0: 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 73 20 ating sequences
c1b0: 2a 2f 0a 20 20 42 75 73 79 48 61 6e 64 6c 65 72 */. BusyHandler
c1c0: 20 62 75 73 79 48 61 6e 64 6c 65 72 3b 20 20 20 busyHandler;
c1d0: 20 20 20 2f 2a 20 42 75 73 79 20 63 61 6c 6c 62 /* Busy callb
c1e0: 61 63 6b 20 2a 2f 0a 20 20 44 62 20 61 44 62 53 ack */. Db aDbS
c1f0: 74 61 74 69 63 5b 32 5d 3b 20 20 20 20 20 20 20 tatic[2];
c200: 20 20 20 20 20 20 20 2f 2a 20 53 74 61 74 69 63 /* Static
c210: 20 73 70 61 63 65 20 66 6f 72 20 74 68 65 20 32 space for the 2
c220: 20 64 65 66 61 75 6c 74 20 62 61 63 6b 65 6e 64 default backend
c230: 73 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 6e 74 s */. Savepoint
c240: 20 2a 70 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 *pSavepoint;
c250: 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 /* List of
c260: 61 63 74 69 76 65 20 73 61 76 65 70 6f 69 6e 74 active savepoint
c270: 73 20 2a 2f 0a 20 20 69 6e 74 20 62 75 73 79 54 s */. int busyT
c280: 69 6d 65 6f 75 74 3b 20 20 20 20 20 20 20 20 20 imeout;
c290: 20 20 20 20 20 2f 2a 20 42 75 73 79 20 68 61 6e /* Busy han
c2a0: 64 6c 65 72 20 74 69 6d 65 6f 75 74 2c 20 69 6e dler timeout, in
c2b0: 20 6d 73 65 63 20 2a 2f 0a 20 20 69 6e 74 20 6e msec */. int n
c2c0: 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 Savepoint;
c2d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
c2e0: 65 72 20 6f 66 20 6e 6f 6e 2d 74 72 61 6e 73 61 er of non-transa
c2f0: 63 74 69 6f 6e 20 73 61 76 65 70 6f 69 6e 74 73 ction savepoints
c300: 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 61 74 65 */. int nState
c310: 6d 65 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 ment;
c320: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
c330: 20 6e 65 73 74 65 64 20 73 74 61 74 65 6d 65 6e nested statemen
c340: 74 2d 74 72 61 6e 73 61 63 74 69 6f 6e 73 20 20 t-transactions
c350: 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 */. i64 nDeferr
c360: 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 edCons;
c370: 20 20 20 2f 2a 20 4e 65 74 20 64 65 66 65 72 72 /* Net deferr
c380: 65 64 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 74 ed constraints t
c390: 68 69 73 20 74 72 61 6e 73 61 63 74 69 6f 6e 2e his transaction.
c3a0: 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 */. i64 nDefer
c3b0: 72 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 20 20 20 redImmCons;
c3c0: 20 20 20 20 2f 2a 20 4e 65 74 20 64 65 66 65 72 /* Net defer
c3d0: 72 65 64 20 69 6d 6d 65 64 69 61 74 65 20 63 6f red immediate co
c3e0: 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 69 nstraints */. i
c3f0: 6e 74 20 2a 70 6e 42 79 74 65 73 46 72 65 65 64 nt *pnBytesFreed
c400: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
c410: 49 66 20 6e 6f 74 20 4e 55 4c 4c 2c 20 69 6e 63 If not NULL, inc
c420: 72 65 6d 65 6e 74 20 74 68 69 73 20 69 6e 20 44 rement this in D
c430: 62 46 72 65 65 28 29 20 2a 2f 0a 23 69 66 64 65 bFree() */.#ifde
c440: 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f f SQLITE_ENABLE_
c450: 55 4e 4c 4f 43 4b 5f 4e 4f 54 49 46 59 0a 20 20 UNLOCK_NOTIFY.
c460: 2f 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 /* The following
c470: 20 76 61 72 69 61 62 6c 65 73 20 61 72 65 20 61 variables are a
c480: 6c 6c 20 70 72 6f 74 65 63 74 65 64 20 62 79 20 ll protected by
c490: 74 68 65 20 53 54 41 54 49 43 5f 4d 41 53 54 45 the STATIC_MASTE
c4a0: 52 0a 20 20 2a 2a 20 6d 75 74 65 78 2c 20 6e 6f R. ** mutex, no
c4b0: 74 20 62 79 20 73 71 6c 69 74 65 33 2e 6d 75 74 t by sqlite3.mut
c4c0: 65 78 2e 20 54 68 65 79 20 61 72 65 20 75 73 65 ex. They are use
c4d0: 64 20 62 79 20 63 6f 64 65 20 69 6e 20 6e 6f 74 d by code in not
c4e0: 69 66 79 2e 63 2e 0a 20 20 2a 2a 0a 20 20 2a 2a ify.c.. **. **
c4f0: 20 57 68 65 6e 20 58 2e 70 55 6e 6c 6f 63 6b 43 When X.pUnlockC
c500: 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 68 onnection==Y, th
c510: 61 74 20 6d 65 61 6e 73 20 74 68 61 74 20 58 20 at means that X
c520: 69 73 20 77 61 69 74 69 6e 67 20 66 6f 72 20 59 is waiting for Y
c530: 20 74 6f 0a 20 20 2a 2a 20 75 6e 6c 6f 63 6b 20 to. ** unlock
c540: 73 6f 20 74 68 61 74 20 69 74 20 63 61 6e 20 70 so that it can p
c550: 72 6f 63 65 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a roceed.. **. *
c560: 2a 20 57 68 65 6e 20 58 2e 70 42 6c 6f 63 6b 69 * When X.pBlocki
c570: 6e 67 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c ngConnection==Y,
c580: 20 74 68 61 74 20 6d 65 61 6e 73 20 74 68 61 74 that means that
c590: 20 73 6f 6d 65 74 68 69 6e 67 20 74 68 61 74 20 something that
c5a0: 58 20 74 72 69 65 64 0a 20 20 2a 2a 20 74 72 69 X tried. ** tri
c5b0: 65 64 20 74 6f 20 64 6f 20 72 65 63 65 6e 74 6c ed to do recentl
c5c0: 79 20 66 61 69 6c 65 64 20 77 69 74 68 20 61 6e y failed with an
c5d0: 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 65 SQLITE_LOCKED e
c5e0: 72 72 6f 72 20 64 75 65 20 74 6f 20 6c 6f 63 6b rror due to lock
c5f0: 73 0a 20 20 2a 2a 20 68 65 6c 64 20 62 79 20 59 s. ** held by Y
c600: 2e 0a 20 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 .. */. sqlite3
c610: 20 2a 70 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 *pBlockingConne
c620: 63 74 69 6f 6e 3b 20 2f 2a 20 43 6f 6e 6e 65 63 ction; /* Connec
c630: 74 69 6f 6e 20 74 68 61 74 20 63 61 75 73 65 64 tion that caused
c640: 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 2a SQLITE_LOCKED *
c650: 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 70 55 6e /. sqlite3 *pUn
c660: 6c 6f 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 lockConnection;
c670: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e /* Con
c680: 6e 65 63 74 69 6f 6e 20 74 6f 20 77 61 74 63 68 nection to watch
c690: 20 66 6f 72 20 75 6e 6c 6f 63 6b 20 2a 2f 0a 20 for unlock */.
c6a0: 20 76 6f 69 64 20 2a 70 55 6e 6c 6f 63 6b 41 72 void *pUnlockAr
c6b0: 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
c6c0: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
c6d0: 6e 74 20 74 6f 20 78 55 6e 6c 6f 63 6b 4e 6f 74 nt to xUnlockNot
c6e0: 69 66 79 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a ify */. void (*
c6f0: 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 79 29 28 76 xUnlockNotify)(v
c700: 6f 69 64 20 2a 2a 2c 20 69 6e 74 29 3b 20 20 2f oid **, int); /
c710: 2a 20 55 6e 6c 6f 63 6b 20 6e 6f 74 69 66 79 20 * Unlock notify
c720: 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 73 71 callback */. sq
c730: 6c 69 74 65 33 20 2a 70 4e 65 78 74 42 6c 6f 63 lite3 *pNextBloc
c740: 6b 65 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e ked; /* N
c750: 65 78 74 20 69 6e 20 6c 69 73 74 20 6f 66 20 61 ext in list of a
c760: 6c 6c 20 62 6c 6f 63 6b 65 64 20 63 6f 6e 6e 65 ll blocked conne
c770: 63 74 69 6f 6e 73 20 2a 2f 0a 23 65 6e 64 69 66 ctions */.#endif
c780: 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 55 .#ifdef SQLITE_U
c790: 53 45 52 5f 41 55 54 48 45 4e 54 49 43 41 54 49 SER_AUTHENTICATI
c7a0: 4f 4e 0a 20 20 73 71 6c 69 74 65 33 5f 75 73 65 ON. sqlite3_use
c7b0: 72 61 75 74 68 20 61 75 74 68 3b 20 20 20 20 20 rauth auth;
c7c0: 20 20 20 2f 2a 20 55 73 65 72 20 61 75 74 68 65 /* User authe
c7d0: 6e 74 69 63 61 74 69 6f 6e 20 69 6e 66 6f 72 6d ntication inform
c7e0: 61 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a ation */.#endif.
c7f0: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 72 };../*.** A macr
c800: 6f 20 74 6f 20 64 69 73 63 6f 76 65 72 20 74 68 o to discover th
c810: 65 20 65 6e 63 6f 64 69 6e 67 20 6f 66 20 61 20 e encoding of a
c820: 64 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 23 64 65 database..*/.#de
c830: 66 69 6e 65 20 53 43 48 45 4d 41 5f 45 4e 43 28 fine SCHEMA_ENC(
c840: 64 62 29 20 28 28 64 62 29 2d 3e 61 44 62 5b 30 db) ((db)->aDb[0
c850: 5d 2e 70 53 63 68 65 6d 61 2d 3e 65 6e 63 29 0a ].pSchema->enc).
c860: 23 64 65 66 69 6e 65 20 45 4e 43 28 64 62 29 20 #define ENC(db)
c870: 20 20 20 20 20 20 20 28 28 64 62 29 2d 3e 65 6e ((db)->en
c880: 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 62 c)../*.** Possib
c890: 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 74 68 le values for th
c8a0: 65 20 73 71 6c 69 74 65 33 2e 66 6c 61 67 73 2e e sqlite3.flags.
c8b0: 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 6f 6e .**.** Value con
c8c0: 73 74 72 61 69 6e 74 73 20 28 65 6e 66 6f 72 63 straints (enforc
c8d0: 65 64 20 76 69 61 20 61 73 73 65 72 74 28 29 29 ed via assert())
c8e0: 3a 0a 2a 2a 20 20 20 20 20 20 53 51 4c 49 54 45 :.** SQLITE
c8f0: 5f 46 75 6c 6c 46 53 79 6e 63 20 20 20 20 20 3d _FullFSync =
c900: 3d 20 50 41 47 45 52 5f 46 55 4c 4c 46 53 59 4e = PAGER_FULLFSYN
c910: 43 0a 2a 2a 20 20 20 20 20 20 53 51 4c 49 54 45 C.** SQLITE
c920: 5f 43 6b 70 74 46 75 6c 6c 46 53 79 6e 63 20 3d _CkptFullFSync =
c930: 3d 20 50 41 47 45 52 5f 43 4b 50 54 5f 46 55 4c = PAGER_CKPT_FUL
c940: 4c 46 53 59 4e 43 0a 2a 2a 20 20 20 20 20 20 53 LFSYNC.** S
c950: 51 4c 49 54 45 5f 43 61 63 68 65 53 70 69 6c 6c QLITE_CacheSpill
c960: 20 20 20 20 3d 3d 20 50 41 47 45 52 5f 43 41 43 == PAGER_CAC
c970: 48 45 5f 53 50 49 4c 4c 0a 2a 2f 0a 23 64 65 66 HE_SPILL.*/.#def
c980: 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 65 54 ine SQLITE_VdbeT
c990: 72 61 63 65 20 20 20 20 20 20 30 78 30 30 30 30 race 0x0000
c9a0: 30 30 30 31 20 20 2f 2a 20 54 72 75 65 20 74 6f 0001 /* True to
c9b0: 20 74 72 61 63 65 20 56 44 42 45 20 65 78 65 63 trace VDBE exec
c9c0: 75 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 ution */.#define
c9d0: 20 53 51 4c 49 54 45 5f 49 6e 74 65 72 6e 43 68 SQLITE_InternCh
c9e0: 61 6e 67 65 73 20 20 30 78 30 30 30 30 30 30 30 anges 0x0000000
c9f0: 32 20 20 2f 2a 20 55 6e 63 6f 6d 6d 69 74 74 65 2 /* Uncommitte
ca00: 64 20 48 61 73 68 20 74 61 62 6c 65 20 63 68 61 d Hash table cha
ca10: 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 nges */.#define
ca20: 53 51 4c 49 54 45 5f 46 75 6c 6c 43 6f 6c 4e 61 SQLITE_FullColNa
ca30: 6d 65 73 20 20 20 30 78 30 30 30 30 30 30 30 34 mes 0x00000004
ca40: 20 20 2f 2a 20 53 68 6f 77 20 66 75 6c 6c 20 63 /* Show full c
ca50: 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6f 6e 20 53 olumn names on S
ca60: 45 4c 45 43 54 20 2a 2f 0a 23 64 65 66 69 6e 65 ELECT */.#define
ca70: 20 53 51 4c 49 54 45 5f 46 75 6c 6c 46 53 79 6e SQLITE_FullFSyn
ca80: 63 20 20 20 20 20 20 30 78 30 30 30 30 30 30 30 c 0x0000000
ca90: 38 20 20 2f 2a 20 55 73 65 20 66 75 6c 6c 20 66 8 /* Use full f
caa0: 73 79 6e 63 20 6f 6e 20 74 68 65 20 62 61 63 6b sync on the back
cab0: 65 6e 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 end */.#define S
cac0: 51 4c 49 54 45 5f 43 6b 70 74 46 75 6c 6c 46 53 QLITE_CkptFullFS
cad0: 79 6e 63 20 20 30 78 30 30 30 30 30 30 31 30 20 ync 0x00000010
cae0: 20 2f 2a 20 55 73 65 20 66 75 6c 6c 20 66 73 79 /* Use full fsy
caf0: 6e 63 20 66 6f 72 20 63 68 65 63 6b 70 6f 69 6e nc for checkpoin
cb00: 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c t */.#define SQL
cb10: 49 54 45 5f 43 61 63 68 65 53 70 69 6c 6c 20 20 ITE_CacheSpill
cb20: 20 20 20 30 78 30 30 30 30 30 30 32 30 20 20 2f 0x00000020 /
cb30: 2a 20 4f 4b 20 74 6f 20 73 70 69 6c 6c 20 70 61 * OK to spill pa
cb40: 67 65 72 20 63 61 63 68 65 20 2a 2f 0a 23 64 65 ger cache */.#de
cb50: 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 68 6f 72 fine SQLITE_Shor
cb60: 74 43 6f 6c 4e 61 6d 65 73 20 20 30 78 30 30 30 tColNames 0x000
cb70: 30 30 30 34 30 20 20 2f 2a 20 53 68 6f 77 20 73 00040 /* Show s
cb80: 68 6f 72 74 20 63 6f 6c 75 6d 6e 73 20 6e 61 6d hort columns nam
cb90: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
cba0: 4c 49 54 45 5f 43 6f 75 6e 74 52 6f 77 73 20 20 LITE_CountRows
cbb0: 20 20 20 20 30 78 30 30 30 30 30 30 38 30 20 20 0x00000080
cbc0: 2f 2a 20 43 6f 75 6e 74 20 72 6f 77 73 20 63 68 /* Count rows ch
cbd0: 61 6e 67 65 64 20 62 79 20 49 4e 53 45 52 54 2c anged by INSERT,
cbe0: 20 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 */.
cbf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cc00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
cc10: 20 20 20 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 DELETE, or UP
cc20: 44 41 54 45 20 61 6e 64 20 72 65 74 75 72 6e 20 DATE and return
cc30: 2a 2f 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 */.
cc40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
cc50: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
cc60: 20 20 74 68 65 20 63 6f 75 6e 74 20 75 73 69 6e the count usin
cc70: 67 20 61 20 63 61 6c 6c 62 61 63 6b 2e 20 2a 2f g a callback. */
cc80: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
cc90: 4e 75 6c 6c 43 61 6c 6c 62 61 63 6b 20 20 20 30 NullCallback 0
cca0: 78 30 30 30 30 30 31 30 30 20 20 2f 2a 20 49 6e x00000100 /* In
ccb0: 76 6f 6b 65 20 74 68 65 20 63 61 6c 6c 62 61 63 voke the callbac
ccc0: 6b 20 6f 6e 63 65 20 69 66 20 74 68 65 20 2a 2f k once if the */
ccd0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
cce0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ccf0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 /*
cd00: 72 65 73 75 6c 74 20 73 65 74 20 69 73 20 65 6d result set is em
cd10: 70 74 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 pty */.#define S
cd20: 51 4c 49 54 45 5f 53 71 6c 54 72 61 63 65 20 20 QLITE_SqlTrace
cd30: 20 20 20 20 20 30 78 30 30 30 30 30 32 30 30 20 0x00000200
cd40: 20 2f 2a 20 44 65 62 75 67 20 70 72 69 6e 74 20 /* Debug print
cd50: 53 51 4c 20 61 73 20 69 74 20 65 78 65 63 75 74 SQL as it execut
cd60: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
cd70: 4c 49 54 45 5f 56 64 62 65 4c 69 73 74 69 6e 67 LITE_VdbeListing
cd80: 20 20 20 20 30 78 30 30 30 30 30 34 30 30 20 20 0x00000400
cd90: 2f 2a 20 44 65 62 75 67 20 6c 69 73 74 69 6e 67 /* Debug listing
cda0: 73 20 6f 66 20 56 44 42 45 20 70 72 6f 67 72 61 s of VDBE progra
cdb0: 6d 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ms */.#define SQ
cdc0: 4c 49 54 45 5f 57 72 69 74 65 53 63 68 65 6d 61 LITE_WriteSchema
cdd0: 20 20 20 20 30 78 30 30 30 30 30 38 30 30 20 20 0x00000800
cde0: 2f 2a 20 4f 4b 20 74 6f 20 75 70 64 61 74 65 20 /* OK to update
cdf0: 53 51 4c 49 54 45 5f 4d 41 53 54 45 52 20 2a 2f SQLITE_MASTER */
ce00: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ce10: 56 64 62 65 41 64 64 6f 70 54 72 61 63 65 20 30 VdbeAddopTrace 0
ce20: 78 30 30 30 30 31 30 30 30 20 20 2f 2a 20 54 72 x00001000 /* Tr
ce30: 61 63 65 20 73 71 6c 69 74 65 33 56 64 62 65 41 ace sqlite3VdbeA
ce40: 64 64 4f 70 28 29 20 63 61 6c 6c 73 20 2a 2f 0a ddOp() calls */.
ce50: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 #define SQLITE_I
ce60: 67 6e 6f 72 65 43 68 65 63 6b 73 20 20 20 30 78 gnoreChecks 0x
ce70: 30 30 30 30 32 30 30 30 20 20 2f 2a 20 44 6f 20 00002000 /* Do
ce80: 6e 6f 74 20 65 6e 66 6f 72 63 65 20 63 68 65 63 not enforce chec
ce90: 6b 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f k constraints */
cea0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ceb0: 52 65 61 64 55 6e 63 6f 6d 6d 69 74 74 65 64 20 ReadUncommitted
cec0: 30 78 30 30 30 34 30 30 30 20 20 2f 2a 20 46 6f 0x0004000 /* Fo
ced0: 72 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 6d r shared-cache m
cee0: 6f 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ode */.#define S
cef0: 51 4c 49 54 45 5f 4c 65 67 61 63 79 46 69 6c 65 QLITE_LegacyFile
cf00: 46 6d 74 20 20 30 78 30 30 30 30 38 30 30 30 20 Fmt 0x00008000
cf10: 20 2f 2a 20 43 72 65 61 74 65 20 6e 65 77 20 64 /* Create new d
cf20: 61 74 61 62 61 73 65 73 20 69 6e 20 66 6f 72 6d atabases in form
cf30: 61 74 20 31 20 2a 2f 0a 23 64 65 66 69 6e 65 20 at 1 */.#define
cf40: 53 51 4c 49 54 45 5f 52 65 63 6f 76 65 72 79 4d SQLITE_RecoveryM
cf50: 6f 64 65 20 20 20 30 78 30 30 30 31 30 30 30 30 ode 0x00010000
cf60: 20 20 2f 2a 20 49 67 6e 6f 72 65 20 73 63 68 65 /* Ignore sche
cf70: 6d 61 20 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 ma errors */.#de
cf80: 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 76 65 fine SQLITE_Reve
cf90: 72 73 65 4f 72 64 65 72 20 20 20 30 78 30 30 30 rseOrder 0x000
cfa0: 32 30 30 30 30 20 20 2f 2a 20 52 65 76 65 72 73 20000 /* Revers
cfb0: 65 20 75 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 e unordered SELE
cfc0: 43 54 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 CTs */.#define S
cfd0: 51 4c 49 54 45 5f 52 65 63 54 72 69 67 67 65 72 QLITE_RecTrigger
cfe0: 73 20 20 20 20 30 78 30 30 30 34 30 30 30 30 20 s 0x00040000
cff0: 20 2f 2a 20 45 6e 61 62 6c 65 20 72 65 63 75 72 /* Enable recur
d000: 73 69 76 65 20 74 72 69 67 67 65 72 73 20 2a 2f sive triggers */
d010: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
d020: 46 6f 72 65 69 67 6e 4b 65 79 73 20 20 20 20 30 ForeignKeys 0
d030: 78 30 30 30 38 30 30 30 30 20 20 2f 2a 20 45 6e x00080000 /* En
d040: 66 6f 72 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 force foreign ke
d050: 79 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a y constraints *
d060: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
d070: 5f 41 75 74 6f 49 6e 64 65 78 20 20 20 20 20 20 _AutoIndex
d080: 30 78 30 30 31 30 30 30 30 30 20 20 2f 2a 20 45 0x00100000 /* E
d090: 6e 61 62 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 nable automatic
d0a0: 69 6e 64 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 indexes */.#defi
d0b0: 6e 65 20 53 51 4c 49 54 45 5f 50 72 65 66 65 72 ne SQLITE_Prefer
d0c0: 42 75 69 6c 74 69 6e 20 20 30 78 30 30 32 30 30 Builtin 0x00200
d0d0: 30 30 30 20 20 2f 2a 20 50 72 65 66 65 72 65 6e 000 /* Preferen
d0e0: 63 65 20 74 6f 20 62 75 69 6c 74 2d 69 6e 20 66 ce to built-in f
d0f0: 75 6e 63 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 uncs */.#define
d100: 53 51 4c 49 54 45 5f 4c 6f 61 64 45 78 74 65 6e SQLITE_LoadExten
d110: 73 69 6f 6e 20 20 30 78 30 30 34 30 30 30 30 30 sion 0x00400000
d120: 20 20 2f 2a 20 45 6e 61 62 6c 65 20 6c 6f 61 64 /* Enable load
d130: 5f 65 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 23 64 _extension */.#d
d140: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4c 6f 61 efine SQLITE_Loa
d150: 64 45 78 74 46 75 6e 63 20 20 20 20 30 78 30 30 dExtFunc 0x00
d160: 38 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 6c 800000 /* Enabl
d170: 65 20 6c 6f 61 64 5f 65 78 74 65 6e 73 69 6f 6e e load_extension
d180: 28 29 20 53 51 4c 20 66 75 6e 63 20 2a 2f 0a 23 () SQL func */.#
d190: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 6e define SQLITE_En
d1a0: 61 62 6c 65 54 72 69 67 67 65 72 20 20 30 78 30 ableTrigger 0x0
d1b0: 31 30 30 30 30 30 30 20 20 2f 2a 20 54 72 75 65 1000000 /* True
d1c0: 20 74 6f 20 65 6e 61 62 6c 65 20 74 72 69 67 67 to enable trigg
d1d0: 65 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ers */.#define S
d1e0: 51 4c 49 54 45 5f 44 65 66 65 72 46 4b 73 20 20 QLITE_DeferFKs
d1f0: 20 20 20 20 20 30 78 30 32 30 30 30 30 30 30 20 0x02000000
d200: 20 2f 2a 20 44 65 66 65 72 20 61 6c 6c 20 46 4b /* Defer all FK
d210: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
d220: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 51 #define SQLITE_Q
d230: 75 65 72 79 4f 6e 6c 79 20 20 20 20 20 20 30 78 ueryOnly 0x
d240: 30 34 30 30 30 30 30 30 20 20 2f 2a 20 44 69 73 04000000 /* Dis
d250: 61 62 6c 65 20 64 61 74 61 62 61 73 65 20 63 68 able database ch
d260: 61 6e 67 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 anges */.#define
d270: 20 53 51 4c 49 54 45 5f 56 64 62 65 45 51 50 20 SQLITE_VdbeEQP
d280: 20 20 20 20 20 20 20 30 78 30 38 30 30 30 30 30 0x0800000
d290: 30 20 20 2f 2a 20 44 65 62 75 67 20 45 58 50 4c 0 /* Debug EXPL
d2a0: 41 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 20 2a AIN QUERY PLAN *
d2b0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
d2c0: 5f 56 61 63 75 75 6d 20 20 20 20 20 20 20 20 20 _Vacuum
d2d0: 30 78 31 30 30 30 30 30 30 30 20 20 2f 2a 20 43 0x10000000 /* C
d2e0: 75 72 72 65 6e 74 6c 79 20 69 6e 20 61 20 56 41 urrently in a VA
d2f0: 43 55 55 4d 20 2a 2f 0a 23 64 65 66 69 6e 65 20 CUUM */.#define
d300: 53 51 4c 49 54 45 5f 43 65 6c 6c 53 69 7a 65 43 SQLITE_CellSizeC
d310: 6b 20 20 20 20 20 30 78 32 30 30 30 30 30 30 30 k 0x20000000
d320: 20 20 2f 2a 20 43 68 65 63 6b 20 62 74 72 65 65 /* Check btree
d330: 20 63 65 6c 6c 20 73 69 7a 65 73 20 6f 6e 20 6c cell sizes on l
d340: 6f 61 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 oad */.#define S
d350: 51 4c 49 54 45 5f 46 74 73 33 54 6f 6b 65 6e 69 QLITE_Fts3Tokeni
d360: 7a 65 72 20 20 30 78 34 30 30 30 30 30 30 30 20 zer 0x40000000
d370: 20 2f 2a 20 45 6e 61 62 6c 65 20 66 74 73 33 5f /* Enable fts3_
d380: 74 6f 6b 65 6e 69 7a 65 72 28 32 29 20 2a 2f 0a tokenizer(2) */.
d390: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e #define SQLITE_N
d3a0: 6f 43 6b 70 74 4f 6e 43 6c 6f 73 65 20 20 30 78 oCkptOnClose 0x
d3b0: 38 30 30 30 30 30 30 30 20 20 2f 2a 20 4e 6f 20 80000000 /* No
d3c0: 63 68 65 63 6b 70 6f 69 6e 74 20 6f 6e 20 63 6c checkpoint on cl
d3d0: 6f 73 65 28 29 2f 44 45 54 41 43 48 20 2a 2f 0a ose()/DETACH */.
d3e0: 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 73 20 6f 66 20 ../*.** Bits of
d3f0: 74 68 65 20 73 71 6c 69 74 65 33 2e 64 62 4f 70 the sqlite3.dbOp
d400: 74 46 6c 61 67 73 20 66 69 65 6c 64 20 74 68 61 tFlags field tha
d410: 74 20 61 72 65 20 75 73 65 64 20 62 79 20 74 68 t are used by th
d420: 65 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 e.** sqlite3_tes
d430: 74 5f 63 6f 6e 74 72 6f 6c 28 53 51 4c 49 54 45 t_control(SQLITE
d440: 5f 54 45 53 54 43 54 52 4c 5f 4f 50 54 49 4d 49 _TESTCTRL_OPTIMI
d450: 5a 41 54 49 4f 4e 53 2c 2e 2e 2e 29 20 69 6e 74 ZATIONS,...) int
d460: 65 72 66 61 63 65 20 74 6f 0a 2a 2a 20 73 65 6c erface to.** sel
d470: 65 63 74 69 76 65 6c 79 20 64 69 73 61 62 6c 65 ectively disable
d480: 20 76 61 72 69 6f 75 73 20 6f 70 74 69 6d 69 7a various optimiz
d490: 61 74 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 66 69 ations..*/.#defi
d4a0: 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 72 79 46 ne SQLITE_QueryF
d4b0: 6c 61 74 74 65 6e 65 72 20 30 78 30 30 30 31 20 lattener 0x0001
d4c0: 20 20 2f 2a 20 51 75 65 72 79 20 66 6c 61 74 74 /* Query flatt
d4d0: 65 6e 69 6e 67 20 2a 2f 0a 23 64 65 66 69 6e 65 ening */.#define
d4e0: 20 53 51 4c 49 54 45 5f 43 6f 6c 75 6d 6e 43 61 SQLITE_ColumnCa
d4f0: 63 68 65 20 20 20 20 30 78 30 30 30 32 20 20 20 che 0x0002
d500: 2f 2a 20 43 6f 6c 75 6d 6e 20 63 61 63 68 65 20 /* Column cache
d510: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
d520: 45 5f 47 72 6f 75 70 42 79 4f 72 64 65 72 20 20 E_GroupByOrder
d530: 20 30 78 30 30 30 34 20 20 20 2f 2a 20 47 52 4f 0x0004 /* GRO
d540: 55 50 42 59 20 63 6f 76 65 72 20 6f 66 20 4f 52 UPBY cover of OR
d550: 44 45 52 42 59 20 2a 2f 0a 23 64 65 66 69 6e 65 DERBY */.#define
d560: 20 53 51 4c 49 54 45 5f 46 61 63 74 6f 72 4f 75 SQLITE_FactorOu
d570: 74 43 6f 6e 73 74 20 30 78 30 30 30 38 20 20 20 tConst 0x0008
d580: 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 66 61 63 74 /* Constant fact
d590: 6f 72 69 6e 67 20 2a 2f 0a 2f 2a 20 20 20 20 20 oring */./*
d5a0: 20 20 20 20 20 20 20 20 20 20 20 6e 6f 74 20 75 not u
d5b0: 73 65 64 20 20 20 20 30 78 30 30 31 30 20 20 20 sed 0x0010
d5c0: 2f 2f 20 57 61 73 3a 20 53 51 4c 49 54 45 5f 49 // Was: SQLITE_I
d5d0: 64 78 52 65 61 6c 41 73 49 6e 74 20 2a 2f 0a 23 dxRealAsInt */.#
d5e0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 69 define SQLITE_Di
d5f0: 73 74 69 6e 63 74 4f 70 74 20 20 20 20 30 78 30 stinctOpt 0x0
d600: 30 32 30 20 20 20 2f 2a 20 44 49 53 54 49 4e 43 020 /* DISTINC
d610: 54 20 75 73 69 6e 67 20 69 6e 64 65 78 65 73 20 T using indexes
d620: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
d630: 45 5f 43 6f 76 65 72 49 64 78 53 63 61 6e 20 20 E_CoverIdxScan
d640: 20 30 78 30 30 34 30 20 20 20 2f 2a 20 43 6f 76 0x0040 /* Cov
d650: 65 72 69 6e 67 20 69 6e 64 65 78 20 73 63 61 6e ering index scan
d660: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
d670: 49 54 45 5f 4f 72 64 65 72 42 79 49 64 78 4a 6f ITE_OrderByIdxJo
d680: 69 6e 20 30 78 30 30 38 30 20 20 20 2f 2a 20 4f in 0x0080 /* O
d690: 52 44 45 52 20 42 59 20 6f 66 20 6a 6f 69 6e 73 RDER BY of joins
d6a0: 20 76 69 61 20 69 6e 64 65 78 20 2a 2f 0a 23 64 via index */.#d
d6b0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 75 62 efine SQLITE_Sub
d6c0: 71 43 6f 72 6f 75 74 69 6e 65 20 20 30 78 30 31 qCoroutine 0x01
d6d0: 30 30 20 20 20 2f 2a 20 45 76 61 6c 75 61 74 65 00 /* Evaluate
d6e0: 20 73 75 62 71 75 65 72 69 65 73 20 61 73 20 63 subqueries as c
d6f0: 6f 72 6f 75 74 69 6e 65 73 20 2a 2f 0a 23 64 65 oroutines */.#de
d700: 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 72 61 6e fine SQLITE_Tran
d710: 73 69 74 69 76 65 20 20 20 20 20 30 78 30 32 30 sitive 0x020
d720: 30 20 20 20 2f 2a 20 54 72 61 6e 73 69 74 69 76 0 /* Transitiv
d730: 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f e constraints */
d740: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
d750: 4f 6d 69 74 4e 6f 6f 70 4a 6f 69 6e 20 20 20 30 OmitNoopJoin 0
d760: 78 30 34 30 30 20 20 20 2f 2a 20 4f 6d 69 74 20 x0400 /* Omit
d770: 75 6e 75 73 65 64 20 74 61 62 6c 65 73 20 69 6e unused tables in
d780: 20 6a 6f 69 6e 73 20 2a 2f 0a 23 64 65 66 69 6e joins */.#defin
d790: 65 20 53 51 4c 49 54 45 5f 53 74 61 74 33 34 20 e SQLITE_Stat34
d7a0: 20 20 20 20 20 20 20 20 30 78 30 38 30 30 20 20 0x0800
d7b0: 20 2f 2a 20 55 73 65 20 53 54 41 54 33 20 6f 72 /* Use STAT3 or
d7c0: 20 53 54 41 54 34 20 64 61 74 61 20 2a 2f 0a 23 STAT4 data */.#
d7d0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 75 define SQLITE_Cu
d7e0: 72 73 6f 72 48 69 6e 74 73 20 20 20 20 30 78 32 rsorHints 0x2
d7f0: 30 30 30 20 20 20 2f 2a 20 41 64 64 20 4f 50 5f 000 /* Add OP_
d800: 43 75 72 73 6f 72 48 69 6e 74 20 6f 70 63 6f 64 CursorHint opcod
d810: 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 es */.#define SQ
d820: 4c 49 54 45 5f 41 6c 6c 4f 70 74 73 20 20 20 20 LITE_AllOpts
d830: 20 20 20 20 30 78 66 66 66 66 20 20 20 2f 2a 20 0xffff /*
d840: 41 6c 6c 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e All optimization
d850: 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 s */../*.** Macr
d860: 6f 73 20 66 6f 72 20 74 65 73 74 69 6e 67 20 77 os for testing w
d870: 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 6f 70 hether or not op
d880: 74 69 6d 69 7a 61 74 69 6f 6e 73 20 61 72 65 20 timizations are
d890: 65 6e 61 62 6c 65 64 20 6f 72 20 64 69 73 61 62 enabled or disab
d8a0: 6c 65 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 led..*/.#define
d8b0: 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 OptimizationDisa
d8c0: 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 bled(db, mask)
d8d0: 28 28 28 64 62 29 2d 3e 64 62 4f 70 74 46 6c 61 (((db)->dbOptFla
d8e0: 67 73 26 28 6d 61 73 6b 29 29 21 3d 30 29 0a 23 gs&(mask))!=0).#
d8f0: 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 7a 61 74 define Optimizat
d900: 69 6f 6e 45 6e 61 62 6c 65 64 28 64 62 2c 20 6d ionEnabled(db, m
d910: 61 73 6b 29 20 20 20 28 28 28 64 62 29 2d 3e 64 ask) (((db)->d
d920: 62 4f 70 74 46 6c 61 67 73 26 28 6d 61 73 6b 29 bOptFlags&(mask)
d930: 29 3d 3d 30 29 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 )==0)../*.** Ret
d940: 75 72 6e 20 74 72 75 65 20 69 66 20 69 74 20 4f urn true if it O
d950: 4b 20 74 6f 20 66 61 63 74 6f 72 20 63 6f 6e 73 K to factor cons
d960: 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 73 tant expressions
d970: 20 69 6e 74 6f 20 74 68 65 20 69 6e 69 74 69 61 into the initia
d980: 6c 69 7a 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 65 lization.** code
d990: 2e 20 54 68 65 20 61 72 67 75 6d 65 6e 74 20 69 . The argument i
d9a0: 73 20 61 20 50 61 72 73 65 20 6f 62 6a 65 63 74 s a Parse object
d9b0: 20 66 6f 72 20 74 68 65 20 63 6f 64 65 20 67 65 for the code ge
d9c0: 6e 65 72 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 66 nerator..*/.#def
d9d0: 69 6e 65 20 43 6f 6e 73 74 46 61 63 74 6f 72 4f ine ConstFactorO
d9e0: 6b 28 50 29 20 28 28 50 29 2d 3e 6f 6b 43 6f 6e k(P) ((P)->okCon
d9f0: 73 74 46 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a 2a stFactor)../*.**
da00: 20 50 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 Possible values
da10: 20 66 6f 72 20 74 68 65 20 73 71 6c 69 74 65 2e for the sqlite.
da20: 6d 61 67 69 63 20 66 69 65 6c 64 2e 0a 2a 2a 20 magic field..**
da30: 54 68 65 20 6e 75 6d 62 65 72 73 20 61 72 65 20 The numbers are
da40: 6f 62 74 61 69 6e 65 64 20 61 74 20 72 61 6e 64 obtained at rand
da50: 6f 6d 20 61 6e 64 20 68 61 76 65 20 6e 6f 20 73 om and have no s
da60: 70 65 63 69 61 6c 20 6d 65 61 6e 69 6e 67 2c 20 pecial meaning,
da70: 6f 74 68 65 72 0a 2a 2a 20 74 68 61 6e 20 62 65 other.** than be
da80: 69 6e 67 20 64 69 73 74 69 6e 63 74 20 66 72 6f ing distinct fro
da90: 6d 20 6f 6e 65 20 61 6e 6f 74 68 65 72 2e 0a 2a m one another..*
daa0: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
dab0: 5f 4d 41 47 49 43 5f 4f 50 45 4e 20 20 20 20 20 _MAGIC_OPEN
dac0: 30 78 61 30 32 39 61 36 39 37 20 20 2f 2a 20 44 0xa029a697 /* D
dad0: 61 74 61 62 61 73 65 20 69 73 20 6f 70 65 6e 20 atabase is open
dae0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
daf0: 45 5f 4d 41 47 49 43 5f 43 4c 4f 53 45 44 20 20 E_MAGIC_CLOSED
db00: 20 30 78 39 66 33 63 32 64 33 33 20 20 2f 2a 20 0x9f3c2d33 /*
db10: 44 61 74 61 62 61 73 65 20 69 73 20 63 6c 6f 73 Database is clos
db20: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ed */.#define SQ
db30: 4c 49 54 45 5f 4d 41 47 49 43 5f 53 49 43 4b 20 LITE_MAGIC_SICK
db40: 20 20 20 20 30 78 34 62 37 37 31 32 39 30 20 20 0x4b771290
db50: 2f 2a 20 45 72 72 6f 72 20 61 6e 64 20 61 77 61 /* Error and awa
db60: 69 74 69 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a 23 iting close */.#
db70: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
db80: 47 49 43 5f 42 55 53 59 20 20 20 20 20 30 78 66 GIC_BUSY 0xf
db90: 30 33 62 37 39 30 36 20 20 2f 2a 20 44 61 74 61 03b7906 /* Data
dba0: 62 61 73 65 20 63 75 72 72 65 6e 74 6c 79 20 69 base currently i
dbb0: 6e 20 75 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 n use */.#define
dbc0: 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 45 52 SQLITE_MAGIC_ER
dbd0: 52 4f 52 20 20 20 20 30 78 62 35 33 35 37 39 33 ROR 0xb535793
dbe0: 30 20 20 2f 2a 20 41 6e 20 53 51 4c 49 54 45 5f 0 /* An SQLITE_
dbf0: 4d 49 53 55 53 45 20 65 72 72 6f 72 20 6f 63 63 MISUSE error occ
dc00: 75 72 72 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 urred */.#define
dc10: 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 5f 5a 4f SQLITE_MAGIC_ZO
dc20: 4d 42 49 45 20 20 20 30 78 36 34 63 66 66 63 37 MBIE 0x64cffc7
dc30: 66 20 20 2f 2a 20 43 6c 6f 73 65 20 77 69 74 68 f /* Close with
dc40: 20 6c 61 73 74 20 73 74 61 74 65 6d 65 6e 74 20 last statement
dc50: 63 6c 6f 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 close */../*.**
dc60: 45 61 63 68 20 53 51 4c 20 66 75 6e 63 74 69 6f Each SQL functio
dc70: 6e 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 20 n is defined by
dc80: 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 an instance of t
dc90: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 he following.**
dca0: 73 74 72 75 63 74 75 72 65 2e 20 20 46 6f 72 20 structure. For
dcb0: 67 6c 6f 62 61 6c 20 62 75 69 6c 74 2d 69 6e 20 global built-in
dcc0: 66 75 6e 63 74 69 6f 6e 73 20 28 65 78 3a 20 73 functions (ex: s
dcd0: 75 62 73 74 72 28 29 2c 20 6d 61 78 28 29 2c 20 ubstr(), max(),
dce0: 63 6f 75 6e 74 28 29 29 0a 2a 2a 20 61 20 70 6f count()).** a po
dcf0: 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 74 inter to this st
dd00: 72 75 63 74 75 72 65 20 69 73 20 68 65 6c 64 20 ructure is held
dd10: 69 6e 20 74 68 65 20 73 71 6c 69 74 65 33 42 75 in the sqlite3Bu
dd20: 69 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 73 20 6f iltinFunctions o
dd30: 62 6a 65 63 74 2e 0a 2a 2a 20 46 6f 72 20 70 65 bject..** For pe
dd40: 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 70 70 r-connection app
dd50: 6c 69 63 61 74 69 6f 6e 2d 64 65 66 69 6e 65 64 lication-defined
dd60: 20 66 75 6e 63 74 69 6f 6e 73 2c 20 61 20 70 6f functions, a po
dd70: 69 6e 74 65 72 20 74 6f 20 74 68 69 73 0a 2a 2a inter to this.**
dd80: 20 73 74 72 75 63 74 75 72 65 20 69 73 20 68 65 structure is he
dd90: 6c 64 20 69 6e 20 74 68 65 20 64 62 2d 3e 61 48 ld in the db->aH
dda0: 61 73 68 20 68 61 73 68 20 74 61 62 6c 65 2e 0a ash hash table..
ddb0: 2a 2a 0a 2a 2a 20 54 68 65 20 75 2e 70 48 61 73 **.** The u.pHas
ddc0: 68 20 66 69 65 6c 64 20 69 73 20 75 73 65 64 20 h field is used
ddd0: 62 79 20 74 68 65 20 67 6c 6f 62 61 6c 20 62 75 by the global bu
dde0: 69 6c 74 2d 69 6e 73 2e 20 20 54 68 65 20 75 2e ilt-ins. The u.
ddf0: 70 44 65 73 74 72 75 63 74 6f 72 0a 2a 2a 20 66 pDestructor.** f
de00: 69 65 6c 64 20 69 73 20 75 73 65 64 20 62 79 20 ield is used by
de10: 70 65 72 2d 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 per-connection a
de20: 70 70 2d 64 65 66 20 66 75 6e 63 74 69 6f 6e 73 pp-def functions
de30: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 75 6e 63 ..*/.struct Func
de40: 44 65 66 20 7b 0a 20 20 69 38 20 6e 41 72 67 3b Def {. i8 nArg;
de50: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
de60: 4e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 Number of argume
de70: 6e 74 73 2e 20 20 2d 31 20 6d 65 61 6e 73 20 75 nts. -1 means u
de80: 6e 6c 69 6d 69 74 65 64 20 2a 2f 0a 20 20 75 31 nlimited */. u1
de90: 36 20 66 75 6e 63 46 6c 61 67 73 3b 20 20 20 20 6 funcFlags;
dea0: 20 20 20 2f 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 /* Some combi
deb0: 6e 61 74 69 6f 6e 20 6f 66 20 53 51 4c 49 54 45 nation of SQLITE
dec0: 5f 46 55 4e 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 _FUNC_* */. voi
ded0: 64 20 2a 70 55 73 65 72 44 61 74 61 3b 20 20 20 d *pUserData;
dee0: 20 20 2f 2a 20 55 73 65 72 20 64 61 74 61 20 70 /* User data p
def0: 61 72 61 6d 65 74 65 72 20 2a 2f 0a 20 20 46 75 arameter */. Fu
df00: 6e 63 44 65 66 20 2a 70 4e 65 78 74 3b 20 20 20 ncDef *pNext;
df10: 20 20 20 2f 2a 20 4e 65 78 74 20 66 75 6e 63 74 /* Next funct
df20: 69 6f 6e 20 77 69 74 68 20 73 61 6d 65 20 6e 61 ion with same na
df30: 6d 65 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 me */. void (*x
df40: 53 46 75 6e 63 29 28 73 71 6c 69 74 65 33 5f 63 SFunc)(sqlite3_c
df50: 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 ontext*,int,sqli
df60: 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b 20 2f 2a te3_value**); /*
df70: 20 66 75 6e 63 20 6f 72 20 61 67 67 2d 73 74 65 func or agg-ste
df80: 70 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 46 p */. void (*xF
df90: 69 6e 61 6c 69 7a 65 29 28 73 71 6c 69 74 65 33 inalize)(sqlite3
dfa0: 5f 63 6f 6e 74 65 78 74 2a 29 3b 20 20 20 20 20 _context*);
dfb0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
dfc0: 41 67 67 20 66 69 6e 61 6c 69 7a 65 72 20 2a 2f Agg finalizer */
dfd0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a . const char *z
dfe0: 4e 61 6d 65 3b 20 20 20 2f 2a 20 53 51 4c 20 6e Name; /* SQL n
dff0: 61 6d 65 20 6f 66 20 74 68 65 20 66 75 6e 63 74 ame of the funct
e000: 69 6f 6e 2e 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 ion. */. union
e010: 7b 0a 20 20 20 20 46 75 6e 63 44 65 66 20 2a 70 {. FuncDef *p
e020: 48 61 73 68 3b 20 20 20 20 20 20 2f 2a 20 4e 65 Hash; /* Ne
e030: 78 74 20 77 69 74 68 20 61 20 64 69 66 66 65 72 xt with a differ
e040: 65 6e 74 20 6e 61 6d 65 20 62 75 74 20 74 68 65 ent name but the
e050: 20 73 61 6d 65 20 68 61 73 68 20 2a 2f 0a 20 20 same hash */.
e060: 20 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 FuncDestructor
e070: 20 2a 70 44 65 73 74 72 75 63 74 6f 72 3b 20 20 *pDestructor;
e080: 20 2f 2a 20 52 65 66 65 72 65 6e 63 65 20 63 6f /* Reference co
e090: 75 6e 74 65 64 20 64 65 73 74 72 75 63 74 6f 72 unted destructor
e0a0: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 7d function */. }
e0b0: 20 75 3b 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 u;.};../*.** Th
e0c0: 69 73 20 73 74 72 75 63 74 75 72 65 20 65 6e 63 is structure enc
e0d0: 61 70 73 75 6c 61 74 65 73 20 61 20 75 73 65 72 apsulates a user
e0e0: 2d 66 75 6e 63 74 69 6f 6e 20 64 65 73 74 72 75 -function destru
e0f0: 63 74 6f 72 20 63 61 6c 6c 62 61 63 6b 20 28 61 ctor callback (a
e100: 73 0a 2a 2a 20 63 6f 6e 66 69 67 75 72 65 64 20 s.** configured
e110: 75 73 69 6e 67 20 63 72 65 61 74 65 5f 66 75 6e using create_fun
e120: 63 74 69 6f 6e 5f 76 32 28 29 29 20 61 6e 64 20 ction_v2()) and
e130: 61 20 72 65 66 65 72 65 6e 63 65 20 63 6f 75 6e a reference coun
e140: 74 65 72 2e 20 57 68 65 6e 0a 2a 2a 20 63 72 65 ter. When.** cre
e150: 61 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 ate_function_v2(
e160: 29 20 69 73 20 63 61 6c 6c 65 64 20 74 6f 20 63 ) is called to c
e170: 72 65 61 74 65 20 61 20 66 75 6e 63 74 69 6f 6e reate a function
e180: 20 77 69 74 68 20 61 20 64 65 73 74 72 75 63 74 with a destruct
e190: 6f 72 2c 0a 2a 2a 20 61 20 73 69 6e 67 6c 65 20 or,.** a single
e1a0: 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 73 20 74 object of this t
e1b0: 79 70 65 20 69 73 20 61 6c 6c 6f 63 61 74 65 64 ype is allocated
e1c0: 2e 20 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 . FuncDestructor
e1d0: 2e 6e 52 65 66 20 69 73 20 73 65 74 20 74 6f 0a .nRef is set to.
e1e0: 2a 2a 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ** the number of
e1f0: 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 FuncDef objects
e200: 20 63 72 65 61 74 65 64 20 28 65 69 74 68 65 72 created (either
e210: 20 31 20 6f 72 20 33 2c 20 64 65 70 65 6e 64 69 1 or 3, dependi
e220: 6e 67 20 6f 6e 20 77 68 65 74 68 65 72 0a 2a 2a ng on whether.**
e230: 20 6f 72 20 6e 6f 74 20 74 68 65 20 73 70 65 63 or not the spec
e240: 69 66 69 65 64 20 65 6e 63 6f 64 69 6e 67 20 69 ified encoding i
e250: 73 20 53 51 4c 49 54 45 5f 41 4e 59 29 2e 20 54 s SQLITE_ANY). T
e260: 68 65 20 46 75 6e 63 44 65 66 2e 70 44 65 73 74 he FuncDef.pDest
e270: 72 75 63 74 6f 72 0a 2a 2a 20 6d 65 6d 62 65 72 ructor.** member
e280: 20 6f 66 20 65 61 63 68 20 6f 66 20 74 68 65 20 of each of the
e290: 6e 65 77 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 new FuncDef obje
e2a0: 63 74 73 20 69 73 20 73 65 74 20 74 6f 20 70 6f cts is set to po
e2b0: 69 6e 74 20 74 6f 20 74 68 65 20 61 6c 6c 6f 63 int to the alloc
e2c0: 61 74 65 64 0a 2a 2a 20 46 75 6e 63 44 65 73 74 ated.** FuncDest
e2d0: 72 75 63 74 6f 72 2e 0a 2a 2a 0a 2a 2a 20 54 68 ructor..**.** Th
e2e0: 65 72 65 61 66 74 65 72 2c 20 77 68 65 6e 20 6f ereafter, when o
e2f0: 6e 65 20 6f 66 20 74 68 65 20 46 75 6e 63 44 65 ne of the FuncDe
e300: 66 20 6f 62 6a 65 63 74 73 20 69 73 20 64 65 6c f objects is del
e310: 65 74 65 64 2c 20 74 68 65 20 72 65 66 65 72 65 eted, the refere
e320: 6e 63 65 0a 2a 2a 20 63 6f 75 6e 74 20 6f 6e 20 nce.** count on
e330: 74 68 69 73 20 6f 62 6a 65 63 74 20 69 73 20 64 this object is d
e340: 65 63 72 65 6d 65 6e 74 65 64 2e 20 57 68 65 6e ecremented. When
e350: 20 69 74 20 72 65 61 63 68 65 73 20 30 2c 20 74 it reaches 0, t
e360: 68 65 20 64 65 73 74 72 75 63 74 6f 72 0a 2a 2a he destructor.**
e370: 20 69 73 20 69 6e 76 6f 6b 65 64 20 61 6e 64 20 is invoked and
e380: 74 68 65 20 46 75 6e 63 44 65 73 74 72 75 63 74 the FuncDestruct
e390: 6f 72 20 73 74 72 75 63 74 75 72 65 20 66 72 65 or structure fre
e3a0: 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 75 ed..*/.struct Fu
e3b0: 6e 63 44 65 73 74 72 75 63 74 6f 72 20 7b 0a 20 ncDestructor {.
e3c0: 20 69 6e 74 20 6e 52 65 66 3b 0a 20 20 76 6f 69 int nRef;. voi
e3d0: 64 20 28 2a 78 44 65 73 74 72 6f 79 29 28 76 6f d (*xDestroy)(vo
e3e0: 69 64 20 2a 29 3b 0a 20 20 76 6f 69 64 20 2a 70 id *);. void *p
e3f0: 55 73 65 72 44 61 74 61 3b 0a 7d 3b 0a 0a 2f 2a UserData;.};../*
e400: 0a 2a 2a 20 50 6f 73 73 69 62 6c 65 20 76 61 6c .** Possible val
e410: 75 65 73 20 66 6f 72 20 46 75 6e 63 44 65 66 2e ues for FuncDef.
e420: 66 6c 61 67 73 2e 20 20 4e 6f 74 65 20 74 68 61 flags. Note tha
e430: 74 20 74 68 65 20 5f 4c 45 4e 47 54 48 20 61 6e t the _LENGTH an
e440: 64 20 5f 54 59 50 45 4f 46 0a 2a 2a 20 76 61 6c d _TYPEOF.** val
e450: 75 65 73 20 6d 75 73 74 20 63 6f 72 72 65 73 70 ues must corresp
e460: 6f 6e 64 20 74 6f 20 4f 50 46 4c 41 47 5f 4c 45 ond to OPFLAG_LE
e470: 4e 47 54 48 41 52 47 20 61 6e 64 20 4f 50 46 4c NGTHARG and OPFL
e480: 41 47 5f 54 59 50 45 4f 46 41 52 47 2e 20 20 41 AG_TYPEOFARG. A
e490: 6e 64 0a 2a 2a 20 53 51 4c 49 54 45 5f 46 55 4e nd.** SQLITE_FUN
e4a0: 43 5f 43 4f 4e 53 54 41 4e 54 20 6d 75 73 74 20 C_CONSTANT must
e4b0: 62 65 20 74 68 65 20 73 61 6d 65 20 61 73 20 53 be the same as S
e4c0: 51 4c 49 54 45 5f 44 45 54 45 52 4d 49 4e 49 53 QLITE_DETERMINIS
e4d0: 54 49 43 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 TIC. There.** a
e4e0: 72 65 20 61 73 73 65 72 74 28 29 20 73 74 61 74 re assert() stat
e4f0: 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 63 6f ements in the co
e500: 64 65 20 74 6f 20 76 65 72 69 66 79 20 74 68 69 de to verify thi
e510: 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 s..**.** Value c
e520: 6f 6e 73 74 72 61 69 6e 74 73 20 28 65 6e 66 6f onstraints (enfo
e530: 72 63 65 64 20 76 69 61 20 61 73 73 65 72 74 28 rced via assert(
e540: 29 29 3a 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 )):.** SQLIT
e550: 45 5f 46 55 4e 43 5f 4d 49 4e 4d 41 58 20 20 20 E_FUNC_MINMAX
e560: 20 3d 3d 20 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 == NC_MinMaxAg
e570: 67 20 20 20 20 20 20 3d 3d 20 53 46 5f 4d 69 6e g == SF_Min
e580: 4d 61 78 41 67 67 0a 2a 2a 20 20 20 20 20 53 51 MaxAgg.** SQ
e590: 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 LITE_FUNC_LENGTH
e5a0: 20 20 20 20 3d 3d 20 20 4f 50 46 4c 41 47 5f 4c == OPFLAG_L
e5b0: 45 4e 47 54 48 41 52 47 0a 2a 2a 20 20 20 20 20 ENGTHARG.**
e5c0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 54 59 50 45 SQLITE_FUNC_TYPE
e5d0: 4f 46 20 20 20 20 3d 3d 20 20 4f 50 46 4c 41 47 OF == OPFLAG
e5e0: 5f 54 59 50 45 4f 46 41 52 47 0a 2a 2a 20 20 20 _TYPEOFARG.**
e5f0: 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f SQLITE_FUNC_CO
e600: 4e 53 54 41 4e 54 20 20 3d 3d 20 20 53 51 4c 49 NSTANT == SQLI
e610: 54 45 5f 44 45 54 45 52 4d 49 4e 49 53 54 49 43 TE_DETERMINISTIC
e620: 20 66 72 6f 6d 20 74 68 65 20 41 50 49 0a 2a 2a from the API.**
e630: 20 20 20 20 20 53 51 4c 49 54 45 5f 46 55 4e 43 SQLITE_FUNC
e640: 5f 45 4e 43 4d 41 53 4b 20 20 20 64 65 70 65 6e _ENCMASK depen
e650: 64 73 20 6f 6e 20 53 51 4c 49 54 45 5f 55 54 46 ds on SQLITE_UTF
e660: 2a 20 6d 61 63 72 6f 73 20 69 6e 20 74 68 65 20 * macros in the
e670: 41 50 49 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 API.*/.#define S
e680: 51 4c 49 54 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 QLITE_FUNC_ENCMA
e690: 53 4b 20 20 30 78 30 30 30 33 20 2f 2a 20 53 51 SK 0x0003 /* SQ
e6a0: 4c 49 54 45 5f 55 54 46 38 2c 20 53 51 4c 49 54 LITE_UTF8, SQLIT
e6b0: 45 5f 55 54 46 31 36 42 45 20 6f 72 20 55 54 46 E_UTF16BE or UTF
e6c0: 31 36 4c 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 16LE */.#define
e6d0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 49 4b 45 SQLITE_FUNC_LIKE
e6e0: 20 20 20 20 20 30 78 30 30 30 34 20 2f 2a 20 43 0x0004 /* C
e6f0: 61 6e 64 69 64 61 74 65 20 66 6f 72 20 74 68 65 andidate for the
e700: 20 4c 49 4b 45 20 6f 70 74 69 6d 69 7a 61 74 69 LIKE optimizati
e710: 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 on */.#define SQ
e720: 4c 49 54 45 5f 46 55 4e 43 5f 43 41 53 45 20 20 LITE_FUNC_CASE
e730: 20 20 20 30 78 30 30 30 38 20 2f 2a 20 43 61 73 0x0008 /* Cas
e740: 65 2d 73 65 6e 73 69 74 69 76 65 20 4c 49 4b 45 e-sensitive LIKE
e750: 2d 74 79 70 65 20 66 75 6e 63 74 69 6f 6e 20 2a -type function *
e760: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
e770: 5f 46 55 4e 43 5f 45 50 48 45 4d 20 20 20 20 30 _FUNC_EPHEM 0
e780: 78 30 30 31 30 20 2f 2a 20 45 70 68 65 6d 65 72 x0010 /* Ephemer
e790: 61 6c 2e 20 20 44 65 6c 65 74 65 20 77 69 74 68 al. Delete with
e7a0: 20 56 44 42 45 20 2a 2f 0a 23 64 65 66 69 6e 65 VDBE */.#define
e7b0: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 SQLITE_FUNC_NEE
e7c0: 44 43 4f 4c 4c 20 30 78 30 30 32 30 20 2f 2a 20 DCOLL 0x0020 /*
e7d0: 73 71 6c 69 74 65 33 47 65 74 46 75 6e 63 43 6f sqlite3GetFuncCo
e7e0: 6c 6c 53 65 71 28 29 20 6d 69 67 68 74 20 62 65 llSeq() might be
e7f0: 20 63 61 6c 6c 65 64 2a 2f 0a 23 64 65 66 69 6e called*/.#defin
e800: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4c 45 e SQLITE_FUNC_LE
e810: 4e 47 54 48 20 20 20 30 78 30 30 34 30 20 2f 2a NGTH 0x0040 /*
e820: 20 42 75 69 6c 74 2d 69 6e 20 6c 65 6e 67 74 68 Built-in length
e830: 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 () function */.#
e840: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 define SQLITE_FU
e850: 4e 43 5f 54 59 50 45 4f 46 20 20 20 30 78 30 30 NC_TYPEOF 0x00
e860: 38 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 74 80 /* Built-in t
e870: 79 70 65 6f 66 28 29 20 66 75 6e 63 74 69 6f 6e ypeof() function
e880: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
e890: 54 45 5f 46 55 4e 43 5f 43 4f 55 4e 54 20 20 20 TE_FUNC_COUNT
e8a0: 20 30 78 30 31 30 30 20 2f 2a 20 42 75 69 6c 74 0x0100 /* Built
e8b0: 2d 69 6e 20 63 6f 75 6e 74 28 2a 29 20 61 67 67 -in count(*) agg
e8c0: 72 65 67 61 74 65 20 2a 2f 0a 23 64 65 66 69 6e regate */.#defin
e8d0: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
e8e0: 41 4c 45 53 43 45 20 30 78 30 32 30 30 20 2f 2a ALESCE 0x0200 /*
e8f0: 20 42 75 69 6c 74 2d 69 6e 20 63 6f 61 6c 65 73 Built-in coales
e900: 63 65 28 29 20 6f 72 20 69 66 6e 75 6c 6c 28 29 ce() or ifnull()
e910: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
e920: 54 45 5f 46 55 4e 43 5f 55 4e 4c 49 4b 45 4c 59 TE_FUNC_UNLIKELY
e930: 20 30 78 30 34 30 30 20 2f 2a 20 42 75 69 6c 74 0x0400 /* Built
e940: 2d 69 6e 20 75 6e 6c 69 6b 65 6c 79 28 29 20 66 -in unlikely() f
e950: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 unction */.#defi
e960: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 ne SQLITE_FUNC_C
e970: 4f 4e 53 54 41 4e 54 20 30 78 30 38 30 30 20 2f ONSTANT 0x0800 /
e980: 2a 20 43 6f 6e 73 74 61 6e 74 20 69 6e 70 75 74 * Constant input
e990: 73 20 67 69 76 65 20 61 20 63 6f 6e 73 74 61 6e s give a constan
e9a0: 74 20 6f 75 74 70 75 74 20 2a 2f 0a 23 64 65 66 t output */.#def
e9b0: 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f ine SQLITE_FUNC_
e9c0: 4d 49 4e 4d 41 58 20 20 20 30 78 31 30 30 30 20 MINMAX 0x1000
e9d0: 2f 2a 20 54 72 75 65 20 66 6f 72 20 6d 69 6e 28 /* True for min(
e9e0: 29 20 61 6e 64 20 6d 61 78 28 29 20 61 67 67 72 ) and max() aggr
e9f0: 65 67 61 74 65 73 20 2a 2f 0a 23 64 65 66 69 6e egates */.#defin
ea00: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 4c e SQLITE_FUNC_SL
ea10: 4f 43 48 4e 47 20 20 30 78 32 30 30 30 20 2f 2a OCHNG 0x2000 /*
ea20: 20 22 53 6c 6f 77 20 43 68 61 6e 67 65 22 2e 20 "Slow Change".
ea30: 56 61 6c 75 65 20 63 6f 6e 73 74 61 6e 74 20 64 Value constant d
ea40: 75 72 69 6e 67 20 61 0a 20 20 20 20 20 20 20 20 uring a.
ea50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ea60: 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 73 ** s
ea70: 69 6e 67 6c 65 20 71 75 65 72 79 20 2d 20 6d 69 ingle query - mi
ea80: 67 68 74 20 63 68 61 6e 67 65 20 6f 76 65 72 20 ght change over
ea90: 74 69 6d 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 time */../*.** T
eaa0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 72 he following thr
eab0: 65 65 20 6d 61 63 72 6f 73 2c 20 46 55 4e 43 54 ee macros, FUNCT
eac0: 49 4f 4e 28 29 2c 20 4c 49 4b 45 46 55 4e 43 28 ION(), LIKEFUNC(
ead0: 29 20 61 6e 64 20 41 47 47 52 45 47 41 54 45 28 ) and AGGREGATE(
eae0: 29 20 61 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f ) are.** used to
eaf0: 20 63 72 65 61 74 65 20 74 68 65 20 69 6e 69 74 create the init
eb00: 69 61 6c 69 7a 65 72 73 20 66 6f 72 20 74 68 65 ializers for the
eb10: 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 74 75 FuncDef structu
eb20: 72 65 73 2e 0a 2a 2a 0a 2a 2a 20 20 20 46 55 4e res..**.** FUN
eb30: 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 CTION(zName, nAr
eb40: 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 g, iArg, bNC, xF
eb50: 75 6e 63 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 unc).** Used
eb60: 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 63 61 to create a sca
eb70: 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 65 66 lar function def
eb80: 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 75 6e inition of a fun
eb90: 63 74 69 6f 6e 20 7a 4e 61 6d 65 0a 2a 2a 20 20 ction zName.**
eba0: 20 20 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 implemented b
ebb0: 79 20 43 20 66 75 6e 63 74 69 6f 6e 20 78 46 75 y C function xFu
ebc0: 6e 63 20 74 68 61 74 20 61 63 63 65 70 74 73 20 nc that accepts
ebd0: 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 73 2e 20 nArg arguments.
ebe0: 54 68 65 0a 2a 2a 20 20 20 20 20 76 61 6c 75 65 The.** value
ebf0: 20 70 61 73 73 65 64 20 61 73 20 69 41 72 67 20 passed as iArg
ec00: 69 73 20 63 61 73 74 20 74 6f 20 61 20 28 76 6f is cast to a (vo
ec10: 69 64 2a 29 20 61 6e 64 20 6d 61 64 65 20 61 76 id*) and made av
ec20: 61 69 6c 61 62 6c 65 0a 2a 2a 20 20 20 20 20 61 ailable.** a
ec30: 73 20 74 68 65 20 75 73 65 72 2d 64 61 74 61 20 s the user-data
ec40: 28 73 71 6c 69 74 65 33 5f 75 73 65 72 5f 64 61 (sqlite3_user_da
ec50: 74 61 28 29 29 20 66 6f 72 20 74 68 65 20 66 75 ta()) for the fu
ec60: 6e 63 74 69 6f 6e 2e 20 49 66 0a 2a 2a 20 20 20 nction. If.**
ec70: 20 20 61 72 67 75 6d 65 6e 74 20 62 4e 43 20 69 argument bNC i
ec80: 73 20 74 72 75 65 2c 20 74 68 65 6e 20 74 68 65 s true, then the
ec90: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 SQLITE_FUNC_NEE
eca0: 44 43 4f 4c 4c 20 66 6c 61 67 20 69 73 20 73 65 DCOLL flag is se
ecb0: 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 56 46 55 4e 43 t..**.** VFUNC
ecc0: 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 TION(zName, nArg
ecd0: 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 , iArg, bNC, xFu
ece0: 6e 63 29 0a 2a 2a 20 20 20 20 20 4c 69 6b 65 20 nc).** Like
ecf0: 46 55 4e 43 54 49 4f 4e 20 65 78 63 65 70 74 20 FUNCTION except
ed00: 69 74 20 6f 6d 69 74 73 20 74 68 65 20 53 51 4c it omits the SQL
ed10: 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e ITE_FUNC_CONSTAN
ed20: 54 20 66 6c 61 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 T flag..**.**
ed30: 44 46 55 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c DFUNCTION(zName,
ed40: 20 6e 41 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 nArg, iArg, bNC
ed50: 2c 20 78 46 75 6e 63 29 0a 2a 2a 20 20 20 20 20 , xFunc).**
ed60: 4c 69 6b 65 20 46 55 4e 43 54 49 4f 4e 20 65 78 Like FUNCTION ex
ed70: 63 65 70 74 20 69 74 20 6f 6d 69 74 73 20 74 68 cept it omits th
ed80: 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f e SQLITE_FUNC_CO
ed90: 4e 53 54 41 4e 54 20 66 6c 61 67 20 61 6e 64 0a NSTANT flag and.
eda0: 2a 2a 20 20 20 20 20 61 64 64 73 20 74 68 65 20 ** adds the
edb0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 SQLITE_FUNC_SLOC
edc0: 48 4e 47 20 66 6c 61 67 2e 20 20 55 73 65 64 20 HNG flag. Used
edd0: 66 6f 72 20 64 61 74 65 20 26 20 74 69 6d 65 20 for date & time
ede0: 66 75 6e 63 74 69 6f 6e 73 0a 2a 2a 20 20 20 20 functions.**
edf0: 20 61 6e 64 20 66 75 6e 63 74 69 6f 6e 73 20 6c and functions l
ee00: 69 6b 65 20 73 71 6c 69 74 65 5f 76 65 72 73 69 ike sqlite_versi
ee10: 6f 6e 28 29 20 74 68 61 74 20 63 61 6e 20 63 68 on() that can ch
ee20: 61 6e 67 65 2c 20 62 75 74 20 6e 6f 74 20 64 75 ange, but not du
ee30: 72 69 6e 67 0a 2a 2a 20 20 20 20 20 61 20 73 69 ring.** a si
ee40: 6e 67 6c 65 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a ngle query..**.*
ee50: 2a 20 20 20 41 47 47 52 45 47 41 54 45 28 7a 4e * AGGREGATE(zN
ee60: 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c ame, nArg, iArg,
ee70: 20 62 4e 43 2c 20 78 53 74 65 70 2c 20 78 46 69 bNC, xStep, xFi
ee80: 6e 61 6c 29 0a 2a 2a 20 20 20 20 20 55 73 65 64 nal).** Used
ee90: 20 74 6f 20 63 72 65 61 74 65 20 61 6e 20 61 67 to create an ag
eea0: 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
eeb0: 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 6d 70 6c definition impl
eec0: 65 6d 65 6e 74 65 64 20 62 79 0a 2a 2a 20 20 20 emented by.**
eed0: 20 20 74 68 65 20 43 20 66 75 6e 63 74 69 6f 6e the C function
eee0: 73 20 78 53 74 65 70 20 61 6e 64 20 78 46 69 6e s xStep and xFin
eef0: 61 6c 2e 20 54 68 65 20 66 69 72 73 74 20 66 6f al. The first fo
ef00: 75 72 20 70 61 72 61 6d 65 74 65 72 73 0a 2a 2a ur parameters.**
ef10: 20 20 20 20 20 61 72 65 20 69 6e 74 65 72 70 72 are interpr
ef20: 65 74 65 64 20 69 6e 20 74 68 65 20 73 61 6d 65 eted in the same
ef30: 20 77 61 79 20 61 73 20 74 68 65 20 66 69 72 73 way as the firs
ef40: 74 20 34 20 70 61 72 61 6d 65 74 65 72 73 20 74 t 4 parameters t
ef50: 6f 0a 2a 2a 20 20 20 20 20 46 55 4e 43 54 49 4f o.** FUNCTIO
ef60: 4e 28 29 2e 0a 2a 2a 0a 2a 2a 20 20 20 4c 49 4b N()..**.** LIK
ef70: 45 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 6e 41 72 EFUNC(zName, nAr
ef80: 67 2c 20 70 41 72 67 2c 20 66 6c 61 67 73 29 0a g, pArg, flags).
ef90: 2a 2a 20 20 20 20 20 55 73 65 64 20 74 6f 20 63 ** Used to c
efa0: 72 65 61 74 65 20 61 20 73 63 61 6c 61 72 20 66 reate a scalar f
efb0: 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 unction definiti
efc0: 6f 6e 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e on of a function
efd0: 20 7a 4e 61 6d 65 0a 2a 2a 20 20 20 20 20 74 68 zName.** th
efe0: 61 74 20 61 63 63 65 70 74 73 20 6e 41 72 67 20 at accepts nArg
eff0: 61 72 67 75 6d 65 6e 74 73 20 61 6e 64 20 69 73 arguments and is
f000: 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 79 20 implemented by
f010: 61 20 63 61 6c 6c 20 74 6f 20 43 0a 2a 2a 20 20 a call to C.**
f020: 20 20 20 66 75 6e 63 74 69 6f 6e 20 6c 69 6b 65 function like
f030: 46 75 6e 63 2e 20 41 72 67 75 6d 65 6e 74 20 70 Func. Argument p
f040: 41 72 67 20 69 73 20 63 61 73 74 20 74 6f 20 61 Arg is cast to a
f050: 20 28 76 6f 69 64 20 2a 29 20 61 6e 64 20 6d 61 (void *) and ma
f060: 64 65 0a 2a 2a 20 20 20 20 20 61 76 61 69 6c 61 de.** availa
f070: 62 6c 65 20 61 73 20 74 68 65 20 66 75 6e 63 74 ble as the funct
f080: 69 6f 6e 20 75 73 65 72 2d 64 61 74 61 20 28 73 ion user-data (s
f090: 71 6c 69 74 65 33 5f 75 73 65 72 5f 64 61 74 61 qlite3_user_data
f0a0: 28 29 29 2e 20 54 68 65 0a 2a 2a 20 20 20 20 20 ()). The.**
f0b0: 46 75 6e 63 44 65 66 2e 66 6c 61 67 73 20 76 61 FuncDef.flags va
f0c0: 72 69 61 62 6c 65 20 69 73 20 73 65 74 20 74 6f riable is set to
f0d0: 20 74 68 65 20 76 61 6c 75 65 20 70 61 73 73 65 the value passe
f0e0: 64 20 61 73 20 74 68 65 20 66 6c 61 67 73 0a 2a d as the flags.*
f0f0: 2a 20 20 20 20 20 70 61 72 61 6d 65 74 65 72 2e * parameter.
f100: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 .*/.#define FUNC
f110: 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 TION(zName, nArg
f120: 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 , iArg, bNC, xFu
f130: 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 nc) \. {nArg, S
f140: 51 4c 49 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 QLITE_FUNC_CONST
f150: 41 4e 54 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c ANT|SQLITE_UTF8|
f160: 28 62 4e 43 2a 53 51 4c 49 54 45 5f 46 55 4e 43 (bNC*SQLITE_FUNC
f170: 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 _NEEDCOLL), \.
f180: 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 SQLITE_INT_TO_P
f190: 54 52 28 69 41 72 67 29 2c 20 30 2c 20 78 46 75 TR(iArg), 0, xFu
f1a0: 6e 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b nc, 0, #zName, {
f1b0: 30 7d 20 7d 0a 23 64 65 66 69 6e 65 20 56 46 55 0} }.#define VFU
f1c0: 4e 43 54 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 NCTION(zName, nA
f1d0: 72 67 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 rg, iArg, bNC, x
f1e0: 46 75 6e 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c Func) \. {nArg,
f1f0: 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e SQLITE_UTF8|(bN
f200: 43 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 C*SQLITE_FUNC_NE
f210: 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 EDCOLL), \. SQ
f220: 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 LITE_INT_TO_PTR(
f230: 69 41 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 2c iArg), 0, xFunc,
f240: 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d 20 0, #zName, {0}
f250: 7d 0a 23 64 65 66 69 6e 65 20 44 46 55 4e 43 54 }.#define DFUNCT
f260: 49 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c ION(zName, nArg,
f270: 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e iArg, bNC, xFun
f280: 63 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 c) \. {nArg, SQ
f290: 4c 49 54 45 5f 46 55 4e 43 5f 53 4c 4f 43 48 4e LITE_FUNC_SLOCHN
f2a0: 47 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 G|SQLITE_UTF8|(b
f2b0: 4e 43 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e NC*SQLITE_FUNC_N
f2c0: 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 EEDCOLL), \. S
f2d0: 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 QLITE_INT_TO_PTR
f2e0: 28 69 41 72 67 29 2c 20 30 2c 20 78 46 75 6e 63 (iArg), 0, xFunc
f2f0: 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 7d , 0, #zName, {0}
f300: 20 7d 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 54 }.#define FUNCT
f310: 49 4f 4e 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 ION2(zName, nArg
f320: 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 , iArg, bNC, xFu
f330: 6e 63 2c 20 65 78 74 72 61 46 6c 61 67 73 29 20 nc, extraFlags)
f340: 5c 0a 20 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 \. {nArg,SQLITE
f350: 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 _FUNC_CONSTANT|S
f360: 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a QLITE_UTF8|(bNC*
f370: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 SQLITE_FUNC_NEED
f380: 43 4f 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 COLL)|extraFlags
f390: 2c 5c 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 ,\. SQLITE_INT
f3a0: 5f 54 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 _TO_PTR(iArg), 0
f3b0: 2c 20 78 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 61 , xFunc, 0, #zNa
f3c0: 6d 65 2c 20 7b 30 7d 20 7d 0a 23 64 65 66 69 6e me, {0} }.#defin
f3d0: 65 20 53 54 52 5f 46 55 4e 43 54 49 4f 4e 28 7a e STR_FUNCTION(z
f3e0: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 Name, nArg, pArg
f3f0: 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a , bNC, xFunc) \.
f400: 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f {nArg, SQLITE_
f410: 46 55 4e 43 5f 53 4c 4f 43 48 4e 47 7c 53 51 4c FUNC_SLOCHNG|SQL
f420: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
f430: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
f440: 4c 4c 29 2c 20 5c 0a 20 20 20 70 41 72 67 2c 20 LL), \. pArg,
f450: 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 23 7a 4e 0, xFunc, 0, #zN
f460: 61 6d 65 2c 20 7d 0a 23 64 65 66 69 6e 65 20 4c ame, }.#define L
f470: 49 4b 45 46 55 4e 43 28 7a 4e 61 6d 65 2c 20 6e IKEFUNC(zName, n
f480: 41 72 67 2c 20 61 72 67 2c 20 66 6c 61 67 73 29 Arg, arg, flags)
f490: 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 \. {nArg, SQLI
f4a0: 54 45 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 TE_FUNC_CONSTANT
f4b0: 7c 53 51 4c 49 54 45 5f 55 54 46 38 7c 66 6c 61 |SQLITE_UTF8|fla
f4c0: 67 73 2c 20 5c 0a 20 20 20 28 76 6f 69 64 20 2a gs, \. (void *
f4d0: 29 61 72 67 2c 20 30 2c 20 6c 69 6b 65 46 75 6e )arg, 0, likeFun
f4e0: 63 2c 20 30 2c 20 23 7a 4e 61 6d 65 2c 20 7b 30 c, 0, #zName, {0
f4f0: 7d 20 7d 0a 23 64 65 66 69 6e 65 20 41 47 47 52 } }.#define AGGR
f500: 45 47 41 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 EGATE(zName, nAr
f510: 67 2c 20 61 72 67 2c 20 6e 63 2c 20 78 53 74 65 g, arg, nc, xSte
f520: 70 2c 20 78 46 69 6e 61 6c 29 20 5c 0a 20 20 7b p, xFinal) \. {
f530: 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 nArg, SQLITE_UTF
f540: 38 7c 28 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 8|(nc*SQLITE_FUN
f550: 43 5f 4e 45 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 C_NEEDCOLL), \.
f560: 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f SQLITE_INT_TO_
f570: 50 54 52 28 61 72 67 29 2c 20 30 2c 20 78 53 74 PTR(arg), 0, xSt
f580: 65 70 2c 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 ep,xFinal,#zName
f590: 2c 20 7b 30 7d 7d 0a 23 64 65 66 69 6e 65 20 41 , {0}}.#define A
f5a0: 47 47 52 45 47 41 54 45 32 28 7a 4e 61 6d 65 2c GGREGATE2(zName,
f5b0: 20 6e 41 72 67 2c 20 61 72 67 2c 20 6e 63 2c 20 nArg, arg, nc,
f5c0: 78 53 74 65 70 2c 20 78 46 69 6e 61 6c 2c 20 65 xStep, xFinal, e
f5d0: 78 74 72 61 46 6c 61 67 73 29 20 5c 0a 20 20 7b xtraFlags) \. {
f5e0: 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 55 54 46 nArg, SQLITE_UTF
f5f0: 38 7c 28 6e 63 2a 53 51 4c 49 54 45 5f 46 55 4e 8|(nc*SQLITE_FUN
f600: 43 5f 4e 45 45 44 43 4f 4c 4c 29 7c 65 78 74 72 C_NEEDCOLL)|extr
f610: 61 46 6c 61 67 73 2c 20 5c 0a 20 20 20 53 51 4c aFlags, \. SQL
f620: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 61 ITE_INT_TO_PTR(a
f630: 72 67 29 2c 20 30 2c 20 78 53 74 65 70 2c 78 46 rg), 0, xStep,xF
f640: 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c 20 7b 30 7d inal,#zName, {0}
f650: 7d 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 63 75 72 }../*.** All cur
f660: 72 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 73 20 rent savepoints
f670: 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 61 20 are stored in a
f680: 6c 69 6e 6b 65 64 20 6c 69 73 74 20 73 74 61 72 linked list star
f690: 74 69 6e 67 20 61 74 0a 2a 2a 20 73 71 6c 69 74 ting at.** sqlit
f6a0: 65 33 2e 70 53 61 76 65 70 6f 69 6e 74 2e 20 54 e3.pSavepoint. T
f6b0: 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 he first element
f6c0: 20 69 6e 20 74 68 65 20 6c 69 73 74 20 69 73 20 in the list is
f6d0: 74 68 65 20 6d 6f 73 74 20 72 65 63 65 6e 74 6c the most recentl
f6e0: 79 0a 2a 2a 20 6f 70 65 6e 65 64 20 73 61 76 65 y.** opened save
f6f0: 70 6f 69 6e 74 2e 20 53 61 76 65 70 6f 69 6e 74 point. Savepoint
f700: 73 20 61 72 65 20 61 64 64 65 64 20 74 6f 20 74 s are added to t
f710: 68 65 20 6c 69 73 74 20 62 79 20 74 68 65 20 76 he list by the v
f720: 64 62 65 0a 2a 2a 20 4f 50 5f 53 61 76 65 70 6f dbe.** OP_Savepo
f730: 69 6e 74 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e int instruction.
f740: 0a 2a 2f 0a 73 74 72 75 63 74 20 53 61 76 65 70 .*/.struct Savep
f750: 6f 69 6e 74 20 7b 0a 20 20 63 68 61 72 20 2a 7a oint {. char *z
f760: 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 Name;
f770: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
f780: 53 61 76 65 70 6f 69 6e 74 20 6e 61 6d 65 20 28 Savepoint name (
f790: 6e 75 6c 2d 74 65 72 6d 69 6e 61 74 65 64 29 20 nul-terminated)
f7a0: 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 */. i64 nDeferr
f7b0: 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 edCons;
f7c0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
f7d0: 65 72 20 6f 66 20 64 65 66 65 72 72 65 64 20 66 er of deferred f
f7e0: 6b 20 76 69 6f 6c 61 74 69 6f 6e 73 20 2a 2f 0a k violations */.
f7f0: 20 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 49 i64 nDeferredI
f800: 6d 6d 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 mmCons;
f810: 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
f820: 6f 66 20 64 65 66 65 72 72 65 64 20 69 6d 6d 20 of deferred imm
f830: 66 6b 2e 20 2a 2f 0a 20 20 53 61 76 65 70 6f 69 fk. */. Savepoi
f840: 6e 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 nt *pNext;
f850: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
f860: 50 61 72 65 6e 74 20 73 61 76 65 70 6f 69 6e 74 Parent savepoint
f870: 20 28 69 66 20 61 6e 79 29 20 2a 2f 0a 7d 3b 0a (if any) */.};.
f880: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
f890: 77 69 6e 67 20 61 72 65 20 75 73 65 64 20 61 73 wing are used as
f8a0: 20 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 61 the second para
f8b0: 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 74 65 33 meter to sqlite3
f8c0: 53 61 76 65 70 6f 69 6e 74 28 29 2c 0a 2a 2a 20 Savepoint(),.**
f8d0: 61 6e 64 20 61 73 20 74 68 65 20 50 31 20 61 72 and as the P1 ar
f8e0: 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 4f 50 gument to the OP
f8f0: 5f 53 61 76 65 70 6f 69 6e 74 20 69 6e 73 74 72 _Savepoint instr
f900: 75 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 64 65 66 69 uction..*/.#defi
f910: 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f 42 45 47 ne SAVEPOINT_BEG
f920: 49 4e 20 20 20 20 20 20 30 0a 23 64 65 66 69 6e IN 0.#defin
f930: 65 20 53 41 56 45 50 4f 49 4e 54 5f 52 45 4c 45 e SAVEPOINT_RELE
f940: 41 53 45 20 20 20 20 31 0a 23 64 65 66 69 6e 65 ASE 1.#define
f950: 20 53 41 56 45 50 4f 49 4e 54 5f 52 4f 4c 4c 42 SAVEPOINT_ROLLB
f960: 41 43 4b 20 20 20 32 0a 0a 0a 2f 2a 0a 2a 2a 20 ACK 2.../*.**
f970: 45 61 63 68 20 53 51 4c 69 74 65 20 6d 6f 64 75 Each SQLite modu
f980: 6c 65 20 28 76 69 72 74 75 61 6c 20 74 61 62 6c le (virtual tabl
f990: 65 20 64 65 66 69 6e 69 74 69 6f 6e 29 20 69 73 e definition) is
f9a0: 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 0a 2a defined by an.*
f9b0: 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 * instance of th
f9c0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
f9d0: 63 74 75 72 65 2c 20 73 74 6f 72 65 64 20 69 6e cture, stored in
f9e0: 20 74 68 65 20 73 71 6c 69 74 65 33 2e 61 4d 6f the sqlite3.aMo
f9f0: 64 75 6c 65 0a 2a 2a 20 68 61 73 68 20 74 61 62 dule.** hash tab
fa00: 6c 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 4d 6f le..*/.struct Mo
fa10: 64 75 6c 65 20 7b 0a 20 20 63 6f 6e 73 74 20 73 dule {. const s
fa20: 71 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 20 2a 70 qlite3_module *p
fa30: 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 20 2f 2a Module; /*
fa40: 20 43 61 6c 6c 62 61 63 6b 20 70 6f 69 6e 74 65 Callback pointe
fa50: 72 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 rs */. const ch
fa60: 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
fa70: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
fa80: 4e 61 6d 65 20 70 61 73 73 65 64 20 74 6f 20 63 Name passed to c
fa90: 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a reate_module() *
faa0: 2f 0a 20 20 76 6f 69 64 20 2a 70 41 75 78 3b 20 /. void *pAux;
fab0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
fac0: 20 20 20 20 20 20 20 20 20 2f 2a 20 70 41 75 78 /* pAux
fad0: 20 70 61 73 73 65 64 20 74 6f 20 63 72 65 61 74 passed to creat
fae0: 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 e_module() */.
faf0: 76 6f 69 64 20 28 2a 78 44 65 73 74 72 6f 79 29 void (*xDestroy)
fb00: 28 76 6f 69 64 20 2a 29 3b 20 20 20 20 20 20 20 (void *);
fb10: 20 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 64 /* Module d
fb20: 65 73 74 72 75 63 74 6f 72 20 66 75 6e 63 74 69 estructor functi
fb30: 6f 6e 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 on */. Table *p
fb40: 45 70 6f 54 61 62 3b 20 20 20 20 20 20 20 20 20 EpoTab;
fb50: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
fb60: 45 70 6f 6e 79 6d 6f 75 73 20 74 61 62 6c 65 20 Eponymous table
fb70: 66 6f 72 20 74 68 69 73 20 6d 6f 64 75 6c 65 20 for this module
fb80: 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 69 6e 66 */.};../*.** inf
fb90: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 65 ormation about e
fba0: 61 63 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 61 6e ach column of an
fbb0: 20 53 51 4c 20 74 61 62 6c 65 20 69 73 20 68 65 SQL table is he
fbc0: 6c 64 20 69 6e 20 61 6e 20 69 6e 73 74 61 6e 63 ld in an instanc
fbd0: 65 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 72 e.** of this str
fbe0: 75 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 ucture..*/.struc
fbf0: 74 20 43 6f 6c 75 6d 6e 20 7b 0a 20 20 63 68 61 t Column {. cha
fc00: 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 2f 2a r *zName; /*
fc10: 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 63 6f Name of this co
fc20: 6c 75 6d 6e 2c 20 5c 30 30 30 2c 20 74 68 65 6e lumn, \000, then
fc30: 20 74 68 65 20 74 79 70 65 20 2a 2f 0a 20 20 45 the type */. E
fc40: 78 70 72 20 2a 70 44 66 6c 74 3b 20 20 20 20 20 xpr *pDflt;
fc50: 2f 2a 20 44 65 66 61 75 6c 74 20 76 61 6c 75 65 /* Default value
fc60: 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 of this column
fc70: 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c 6c */. char *zColl
fc80: 3b 20 20 20 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 ; /* Collati
fc90: 6e 67 20 73 65 71 75 65 6e 63 65 2e 20 20 49 66 ng sequence. If
fca0: 20 4e 55 4c 4c 2c 20 75 73 65 20 74 68 65 20 64 NULL, use the d
fcb0: 65 66 61 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6e efault */. u8 n
fcc0: 6f 74 4e 75 6c 6c 3b 20 20 20 20 20 20 2f 2a 20 otNull; /*
fcd0: 41 6e 20 4f 45 5f 20 63 6f 64 65 20 66 6f 72 20 An OE_ code for
fce0: 68 61 6e 64 6c 69 6e 67 20 61 20 4e 4f 54 20 4e handling a NOT N
fcf0: 55 4c 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a ULL constraint *
fd00: 2f 0a 20 20 63 68 61 72 20 61 66 66 69 6e 69 74 /. char affinit
fd10: 79 3b 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 74 y; /* One of t
fd20: 68 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 2e 2e he SQLITE_AFF_..
fd30: 2e 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 . values */. u8
fd40: 20 73 7a 45 73 74 3b 20 20 20 20 20 20 20 20 2f szEst; /
fd50: 2a 20 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 * Estimated size
fd60: 20 6f 66 20 76 61 6c 75 65 20 69 6e 20 74 68 69 of value in thi
fd70: 73 20 63 6f 6c 75 6d 6e 2e 20 73 69 7a 65 6f 66 s column. sizeof
fd80: 28 49 4e 54 29 3d 3d 31 20 2a 2f 0a 20 20 75 38 (INT)==1 */. u8
fd90: 20 63 6f 6c 46 6c 61 67 73 3b 20 20 20 20 20 2f colFlags; /
fda0: 2a 20 42 6f 6f 6c 65 61 6e 20 70 72 6f 70 65 72 * Boolean proper
fdb0: 74 69 65 73 2e 20 20 53 65 65 20 43 4f 4c 46 4c ties. See COLFL
fdc0: 41 47 5f 20 64 65 66 69 6e 65 73 20 62 65 6c 6f AG_ defines belo
fdd0: 77 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f w */.};../* Allo
fde0: 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 43 wed values for C
fdf0: 6f 6c 75 6d 6e 2e 63 6f 6c 46 6c 61 67 73 3a 0a olumn.colFlags:.
fe00: 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c */.#define COLFL
fe10: 41 47 5f 50 52 49 4d 4b 45 59 20 20 30 78 30 30 AG_PRIMKEY 0x00
fe20: 30 31 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 01 /* Column
fe30: 69 73 20 70 61 72 74 20 6f 66 20 74 68 65 20 70 is part of the p
fe40: 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 rimary key */.#d
fe50: 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 48 49 efine COLFLAG_HI
fe60: 44 44 45 4e 20 20 20 30 78 30 30 30 32 20 20 20 DDEN 0x0002
fe70: 20 2f 2a 20 41 20 68 69 64 64 65 6e 20 63 6f 6c /* A hidden col
fe80: 75 6d 6e 20 69 6e 20 61 20 76 69 72 74 75 61 6c umn in a virtual
fe90: 20 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e table */.#defin
fea0: 65 20 43 4f 4c 46 4c 41 47 5f 48 41 53 54 59 50 e COLFLAG_HASTYP
feb0: 45 20 20 30 78 30 30 30 34 20 20 20 20 2f 2a 20 E 0x0004 /*
fec0: 54 79 70 65 20 6e 61 6d 65 20 66 6f 6c 6c 6f 77 Type name follow
fed0: 73 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 20 2a 2f s column name */
fee0: 0a 0a 2f 2a 0a 2a 2a 20 41 20 22 43 6f 6c 6c 61 ../*.** A "Colla
fef0: 74 69 6e 67 20 53 65 71 75 65 6e 63 65 22 20 69 ting Sequence" i
ff00: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 20 s defined by an
ff10: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
ff20: 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 following.** str
ff30: 75 63 74 75 72 65 2e 20 43 6f 6e 63 65 70 74 75 ucture. Conceptu
ff40: 61 6c 6c 79 2c 20 61 20 63 6f 6c 6c 61 74 69 6e ally, a collatin
ff50: 67 20 73 65 71 75 65 6e 63 65 20 63 6f 6e 73 69 g sequence consi
ff60: 73 74 73 20 6f 66 20 61 20 6e 61 6d 65 20 61 6e sts of a name an
ff70: 64 0a 2a 2a 20 61 20 63 6f 6d 70 61 72 69 73 6f d.** a compariso
ff80: 6e 20 72 6f 75 74 69 6e 65 20 74 68 61 74 20 64 n routine that d
ff90: 65 66 69 6e 65 73 20 74 68 65 20 6f 72 64 65 72 efines the order
ffa0: 20 6f 66 20 74 68 61 74 20 73 65 71 75 65 6e 63 of that sequenc
ffb0: 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 43 6f 6c 6c e..**.** If Coll
ffc0: 53 65 71 2e 78 43 6d 70 20 69 73 20 4e 55 4c 4c Seq.xCmp is NULL
ffd0: 2c 20 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 , it means that
ffe0: 74 68 65 0a 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 the.** collating
fff0: 20 73 65 71 75 65 6e 63 65 20 69 73 20 75 6e 64 sequence is und
10000 65 66 69 6e 65 64 2e 20 20 49 6e 64 69 63 65 73 efined. Indices
10010 20 62 75 69 6c 74 20 6f 6e 20 61 6e 20 75 6e 64 built on an und
10020 65 66 69 6e 65 64 0a 2a 2a 20 63 6f 6c 6c 61 74 efined.** collat
10030 69 6e 67 20 73 65 71 75 65 6e 63 65 20 6d 61 79 ing sequence may
10040 20 6e 6f 74 20 62 65 20 72 65 61 64 20 6f 72 20 not be read or
10050 77 72 69 74 74 65 6e 2e 0a 2a 2f 0a 73 74 72 75 written..*/.stru
10060 63 74 20 43 6f 6c 6c 53 65 71 20 7b 0a 20 20 63 ct CollSeq {. c
10070 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
10080 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
10090 74 68 65 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 the collating se
100a0 71 75 65 6e 63 65 2c 20 55 54 46 2d 38 20 65 6e quence, UTF-8 en
100b0 63 6f 64 65 64 20 2a 2f 0a 20 20 75 38 20 65 6e coded */. u8 en
100c0 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
100d0 20 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e /* Text encodin
100e0 67 20 68 61 6e 64 6c 65 64 20 62 79 20 78 43 6d g handled by xCm
100f0 70 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 p() */. void *p
10100 55 73 65 72 3b 20 20 20 20 20 20 20 20 20 20 2f User; /
10110 2a 20 46 69 72 73 74 20 61 72 67 75 6d 65 6e 74 * First argument
10120 20 74 6f 20 78 43 6d 70 28 29 20 2a 2f 0a 20 20 to xCmp() */.
10130 69 6e 74 20 28 2a 78 43 6d 70 29 28 76 6f 69 64 int (*xCmp)(void
10140 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 *,int, const voi
10150 64 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 76 d*, int, const v
10160 6f 69 64 2a 29 3b 0a 20 20 76 6f 69 64 20 28 2a oid*);. void (*
10170 78 44 65 6c 29 28 76 6f 69 64 2a 29 3b 20 20 2f xDel)(void*); /
10180 2a 20 44 65 73 74 72 75 63 74 6f 72 20 66 6f 72 * Destructor for
10190 20 70 55 73 65 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a pUser */.};../*
101a0 0a 2a 2a 20 41 20 73 6f 72 74 20 6f 72 64 65 72 .** A sort order
101b0 20 63 61 6e 20 62 65 20 65 69 74 68 65 72 20 41 can be either A
101c0 53 43 20 6f 72 20 44 45 53 43 2e 0a 2a 2f 0a 23 SC or DESC..*/.#
101d0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f define SQLITE_SO
101e0 5f 41 53 43 20 20 20 20 20 20 20 30 20 20 2f 2a _ASC 0 /*
101f0 20 53 6f 72 74 20 69 6e 20 61 73 63 65 6e 64 69 Sort in ascendi
10200 6e 67 20 6f 72 64 65 72 20 2a 2f 0a 23 64 65 66 ng order */.#def
10210 69 6e 65 20 53 51 4c 49 54 45 5f 53 4f 5f 44 45 ine SQLITE_SO_DE
10220 53 43 20 20 20 20 20 20 31 20 20 2f 2a 20 53 6f SC 1 /* So
10230 72 74 20 69 6e 20 61 73 63 65 6e 64 69 6e 67 20 rt in ascending
10240 6f 72 64 65 72 20 2a 2f 0a 23 64 65 66 69 6e 65 order */.#define
10250 20 53 51 4c 49 54 45 5f 53 4f 5f 55 4e 44 45 46 SQLITE_SO_UNDEF
10260 49 4e 45 44 20 2d 31 20 2f 2a 20 4e 6f 20 73 6f INED -1 /* No so
10270 72 74 20 6f 72 64 65 72 20 73 70 65 63 69 66 69 rt order specifi
10280 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6c ed */../*.** Col
10290 75 6d 6e 20 61 66 66 69 6e 69 74 79 20 74 79 70 umn affinity typ
102a0 65 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 73 65 20 es..**.** These
102b0 75 73 65 64 20 74 6f 20 68 61 76 65 20 6d 6e 65 used to have mne
102c0 6d 6f 6e 69 63 20 6e 61 6d 65 20 6c 69 6b 65 20 monic name like
102d0 27 69 27 20 66 6f 72 20 53 51 4c 49 54 45 5f 41 'i' for SQLITE_A
102e0 46 46 5f 49 4e 54 45 47 45 52 20 61 6e 64 0a 2a FF_INTEGER and.*
102f0 2a 20 27 74 27 20 66 6f 72 20 53 51 4c 49 54 45 * 't' for SQLITE
10300 5f 41 46 46 5f 54 45 58 54 2e 20 20 42 75 74 20 _AFF_TEXT. But
10310 77 65 20 63 61 6e 20 73 61 76 65 20 61 20 6c 69 we can save a li
10320 74 74 6c 65 20 73 70 61 63 65 20 61 6e 64 20 69 ttle space and i
10330 6d 70 72 6f 76 65 0a 2a 2a 20 74 68 65 20 73 70 mprove.** the sp
10340 65 65 64 20 61 20 6c 69 74 74 6c 65 20 62 79 20 eed a little by
10350 6e 75 6d 62 65 72 69 6e 67 20 74 68 65 20 76 61 numbering the va
10360 6c 75 65 73 20 63 6f 6e 73 65 63 75 74 69 76 65 lues consecutive
10370 6c 79 2e 0a 2a 2a 0a 2a 2a 20 42 75 74 20 72 61 ly..**.** But ra
10380 74 68 65 72 20 74 68 61 6e 20 73 74 61 72 74 20 ther than start
10390 77 69 74 68 20 30 20 6f 72 20 31 2c 20 77 65 20 with 0 or 1, we
103a0 62 65 67 69 6e 20 77 69 74 68 20 27 41 27 2e 20 begin with 'A'.
103b0 20 54 68 61 74 20 77 61 79 2c 0a 2a 2a 20 77 68 That way,.** wh
103c0 65 6e 20 6d 75 6c 74 69 70 6c 65 20 61 66 66 69 en multiple affi
103d0 6e 69 74 79 20 74 79 70 65 73 20 61 72 65 20 63 nity types are c
103e0 6f 6e 63 61 74 65 6e 61 74 65 64 20 69 6e 74 6f oncatenated into
103f0 20 61 20 73 74 72 69 6e 67 20 61 6e 64 0a 2a 2a a string and.**
10400 20 75 73 65 64 20 61 73 20 74 68 65 20 50 34 20 used as the P4
10410 6f 70 65 72 61 6e 64 2c 20 74 68 65 79 20 77 69 operand, they wi
10420 6c 6c 20 62 65 20 6d 6f 72 65 20 72 65 61 64 61 ll be more reada
10430 62 6c 65 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 ble..**.** Note
10440 61 6c 73 6f 20 74 68 61 74 20 74 68 65 20 6e 75 also that the nu
10450 6d 65 72 69 63 20 74 79 70 65 73 20 61 72 65 20 meric types are
10460 67 72 6f 75 70 65 64 20 74 6f 67 65 74 68 65 72 grouped together
10470 20 73 6f 20 74 68 61 74 20 74 65 73 74 69 6e 67 so that testing
10480 0a 2a 2a 20 66 6f 72 20 61 20 6e 75 6d 65 72 69 .** for a numeri
10490 63 20 74 79 70 65 20 69 73 20 61 20 73 69 6e 67 c type is a sing
104a0 6c 65 20 63 6f 6d 70 61 72 69 73 6f 6e 2e 20 20 le comparison.
104b0 41 6e 64 20 74 68 65 20 42 4c 4f 42 20 74 79 70 And the BLOB typ
104c0 65 20 69 73 20 66 69 72 73 74 2e 0a 2a 2f 0a 23 e is first..*/.#
104d0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 define SQLITE_AF
104e0 46 5f 42 4c 4f 42 20 20 20 20 20 27 41 27 0a 23 F_BLOB 'A'.#
104f0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 define SQLITE_AF
10500 46 5f 54 45 58 54 20 20 20 20 20 27 42 27 0a 23 F_TEXT 'B'.#
10510 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 define SQLITE_AF
10520 46 5f 4e 55 4d 45 52 49 43 20 20 27 43 27 0a 23 F_NUMERIC 'C'.#
10530 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 define SQLITE_AF
10540 46 5f 49 4e 54 45 47 45 52 20 20 27 44 27 0a 23 F_INTEGER 'D'.#
10550 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 define SQLITE_AF
10560 46 5f 52 45 41 4c 20 20 20 20 20 27 45 27 0a 0a F_REAL 'E'..
10570 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 #define sqlite3I
10580 73 4e 75 6d 65 72 69 63 41 66 66 69 6e 69 74 79 sNumericAffinity
10590 28 58 29 20 20 28 28 58 29 3e 3d 53 51 4c 49 54 (X) ((X)>=SQLIT
105a0 45 5f 41 46 46 5f 4e 55 4d 45 52 49 43 29 0a 0a E_AFF_NUMERIC)..
105b0 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 /*.** The SQLITE
105c0 5f 41 46 46 5f 4d 41 53 4b 20 76 61 6c 75 65 73 _AFF_MASK values
105d0 20 6d 61 73 6b 73 20 6f 66 66 20 74 68 65 20 73 masks off the s
105e0 69 67 6e 69 66 69 63 61 6e 74 20 62 69 74 73 20 ignificant bits
105f0 6f 66 20 61 6e 0a 2a 2a 20 61 66 66 69 6e 69 74 of an.** affinit
10600 79 20 76 61 6c 75 65 2e 0a 2a 2f 0a 23 64 65 66 y value..*/.#def
10610 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 4d ine SQLITE_AFF_M
10620 41 53 4b 20 20 20 20 20 30 78 34 37 0a 0a 2f 2a ASK 0x47../*
10630 0a 2a 2a 20 41 64 64 69 74 69 6f 6e 61 6c 20 62 .** Additional b
10640 69 74 20 76 61 6c 75 65 73 20 74 68 61 74 20 63 it values that c
10650 61 6e 20 62 65 20 4f 52 65 64 20 77 69 74 68 20 an be ORed with
10660 61 6e 20 61 66 66 69 6e 69 74 79 20 77 69 74 68 an affinity with
10670 6f 75 74 0a 2a 2a 20 63 68 61 6e 67 69 6e 67 20 out.** changing
10680 74 68 65 20 61 66 66 69 6e 69 74 79 2e 0a 2a 2a the affinity..**
10690 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 4e .** The SQLITE_N
106a0 4f 54 4e 55 4c 4c 20 66 6c 61 67 20 69 73 20 61 OTNULL flag is a
106b0 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 6f 66 20 combination of
106c0 4e 55 4c 4c 45 51 20 61 6e 64 20 4a 55 4d 50 49 NULLEQ and JUMPI
106d0 46 4e 55 4c 4c 2e 0a 2a 2a 20 49 74 20 63 61 75 FNULL..** It cau
106e0 73 65 73 20 61 6e 20 61 73 73 65 72 74 28 29 20 ses an assert()
106f0 74 6f 20 66 69 72 65 20 69 66 20 65 69 74 68 65 to fire if eithe
10700 72 20 6f 70 65 72 61 6e 64 20 74 6f 20 61 20 63 r operand to a c
10710 6f 6d 70 61 72 69 73 6f 6e 0a 2a 2a 20 6f 70 65 omparison.** ope
10720 72 61 74 6f 72 20 69 73 20 4e 55 4c 4c 2e 20 20 rator is NULL.
10730 49 74 20 69 73 20 61 64 64 65 64 20 74 6f 20 63 It is added to c
10740 65 72 74 61 69 6e 20 63 6f 6d 70 61 72 69 73 6f ertain compariso
10750 6e 20 6f 70 65 72 61 74 6f 72 73 20 74 6f 0a 2a n operators to.*
10760 2a 20 70 72 6f 76 65 20 74 68 61 74 20 74 68 65 * prove that the
10770 20 6f 70 65 72 61 6e 64 73 20 61 72 65 20 61 6c operands are al
10780 77 61 79 73 20 4e 4f 54 20 4e 55 4c 4c 2e 0a 2a ways NOT NULL..*
10790 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
107a0 5f 4b 45 45 50 4e 55 4c 4c 20 20 20 20 20 30 78 _KEEPNULL 0x
107b0 30 38 20 20 2f 2a 20 55 73 65 64 20 62 79 20 76 08 /* Used by v
107c0 65 63 74 6f 72 20 3d 3d 20 6f 72 20 3c 3e 20 2a ector == or <> *
107d0 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
107e0 5f 4a 55 4d 50 49 46 4e 55 4c 4c 20 20 20 30 78 _JUMPIFNULL 0x
107f0 31 30 20 20 2f 2a 20 6a 75 6d 70 73 20 69 66 20 10 /* jumps if
10800 65 69 74 68 65 72 20 6f 70 65 72 61 6e 64 20 69 either operand i
10810 73 20 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 69 6e s NULL */.#defin
10820 65 20 53 51 4c 49 54 45 5f 53 54 4f 52 45 50 32 e SQLITE_STOREP2
10830 20 20 20 20 20 20 30 78 32 30 20 20 2f 2a 20 53 0x20 /* S
10840 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e 20 72 tore result in r
10850 65 67 5b 50 32 5d 20 72 61 74 68 65 72 20 74 68 eg[P2] rather th
10860 61 6e 20 6a 75 6d 70 20 2a 2f 0a 23 64 65 66 69 an jump */.#defi
10870 6e 65 20 53 51 4c 49 54 45 5f 4e 55 4c 4c 45 51 ne SQLITE_NULLEQ
10880 20 20 20 20 20 20 20 30 78 38 30 20 20 2f 2a 20 0x80 /*
10890 4e 55 4c 4c 3d 4e 55 4c 4c 20 2a 2f 0a 23 64 65 NULL=NULL */.#de
108a0 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f 54 4e fine SQLITE_NOTN
108b0 55 4c 4c 20 20 20 20 20 20 30 78 39 30 20 20 2f ULL 0x90 /
108c0 2a 20 41 73 73 65 72 74 20 74 68 61 74 20 6f 70 * Assert that op
108d0 65 72 61 6e 64 73 20 61 72 65 20 6e 65 76 65 72 erands are never
108e0 20 4e 55 4c 4c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 NULL */../*.**
108f0 41 6e 20 6f 62 6a 65 63 74 20 6f 66 20 74 68 69 An object of thi
10900 73 20 74 79 70 65 20 69 73 20 63 72 65 61 74 65 s type is create
10910 64 20 66 6f 72 20 65 61 63 68 20 76 69 72 74 75 d for each virtu
10920 61 6c 20 74 61 62 6c 65 20 70 72 65 73 65 6e 74 al table present
10930 20 69 6e 0a 2a 2a 20 74 68 65 20 64 61 74 61 62 in.** the datab
10940 61 73 65 20 73 63 68 65 6d 61 2e 0a 2a 2a 0a 2a ase schema..**.*
10950 2a 20 49 66 20 74 68 65 20 64 61 74 61 62 61 73 * If the databas
10960 65 20 73 63 68 65 6d 61 20 69 73 20 73 68 61 72 e schema is shar
10970 65 64 2c 20 74 68 65 6e 20 74 68 65 72 65 20 69 ed, then there i
10980 73 20 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f s one instance o
10990 66 20 74 68 69 73 0a 2a 2a 20 73 74 72 75 63 74 f this.** struct
109a0 75 72 65 20 66 6f 72 20 65 61 63 68 20 64 61 74 ure for each dat
109b0 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
109c0 20 28 73 71 6c 69 74 65 33 2a 29 20 74 68 61 74 (sqlite3*) that
109d0 20 75 73 65 73 20 74 68 65 20 73 68 61 72 65 64 uses the shared
109e0 0a 2a 2a 20 73 63 68 65 6d 61 2e 20 54 68 69 73 .** schema. This
109f0 20 69 73 20 62 65 63 61 75 73 65 20 65 61 63 68 is because each
10a00 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
10a10 74 69 6f 6e 20 72 65 71 75 69 72 65 73 20 69 74 tion requires it
10a20 73 20 6f 77 6e 20 75 6e 69 71 75 65 0a 2a 2a 20 s own unique.**
10a30 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
10a40 73 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 sqlite3_vtab* ha
10a50 6e 64 6c 65 20 75 73 65 64 20 74 6f 20 61 63 63 ndle used to acc
10a60 65 73 73 20 74 68 65 20 76 69 72 74 75 61 6c 20 ess the virtual
10a70 74 61 62 6c 65 0a 2a 2a 20 69 6d 70 6c 65 6d 65 table.** impleme
10a80 6e 74 61 74 69 6f 6e 2e 20 73 71 6c 69 74 65 33 ntation. sqlite3
10a90 5f 76 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 63 _vtab* handles c
10aa0 61 6e 20 6e 6f 74 20 62 65 20 73 68 61 72 65 64 an not be shared
10ab0 20 62 65 74 77 65 65 6e 0a 2a 2a 20 64 61 74 61 between.** data
10ac0 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 73 base connections
10ad0 2c 20 65 76 65 6e 20 77 68 65 6e 20 74 68 65 20 , even when the
10ae0 72 65 73 74 20 6f 66 20 74 68 65 20 69 6e 2d 6d rest of the in-m
10af0 65 6d 6f 72 79 20 64 61 74 61 62 61 73 65 0a 2a emory database.*
10b00 2a 20 73 63 68 65 6d 61 20 69 73 20 73 68 61 72 * schema is shar
10b10 65 64 2c 20 61 73 20 74 68 65 20 69 6d 70 6c 65 ed, as the imple
10b20 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 74 65 6e 20 mentation often
10b30 73 74 6f 72 65 73 20 74 68 65 20 64 61 74 61 62 stores the datab
10b40 61 73 65 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f ase.** connectio
10b50 6e 20 68 61 6e 64 6c 65 20 70 61 73 73 65 64 20 n handle passed
10b60 74 6f 20 69 74 20 76 69 61 20 74 68 65 20 78 43 to it via the xC
10b70 6f 6e 6e 65 63 74 28 29 20 6f 72 20 78 43 72 65 onnect() or xCre
10b80 61 74 65 28 29 20 6d 65 74 68 6f 64 0a 2a 2a 20 ate() method.**
10b90 64 75 72 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a during initializ
10ba0 61 74 69 6f 6e 20 69 6e 74 65 72 6e 61 6c 6c 79 ation internally
10bb0 2e 20 54 68 69 73 20 64 61 74 61 62 61 73 65 20 . This database
10bc0 63 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c connection handl
10bd0 65 20 6d 61 79 0a 2a 2a 20 74 68 65 6e 20 62 65 e may.** then be
10be0 20 75 73 65 64 20 62 79 20 74 68 65 20 76 69 72 used by the vir
10bf0 74 75 61 6c 20 74 61 62 6c 65 20 69 6d 70 6c 65 tual table imple
10c00 6d 65 6e 74 61 74 69 6f 6e 20 74 6f 20 61 63 63 mentation to acc
10c10 65 73 73 20 72 65 61 6c 20 74 61 62 6c 65 73 0a ess real tables.
10c20 2a 2a 20 77 69 74 68 69 6e 20 74 68 65 20 64 61 ** within the da
10c30 74 61 62 61 73 65 2e 20 53 6f 20 74 68 61 74 20 tabase. So that
10c40 74 68 65 79 20 61 70 70 65 61 72 20 61 73 20 70 they appear as p
10c50 61 72 74 20 6f 66 20 74 68 65 20 63 61 6c 6c 65 art of the calle
10c60 72 73 0a 2a 2a 20 74 72 61 6e 73 61 63 74 69 6f rs.** transactio
10c70 6e 2c 20 74 68 65 73 65 20 61 63 63 65 73 73 65 n, these accesse
10c80 73 20 6e 65 65 64 20 74 6f 20 62 65 20 6d 61 64 s need to be mad
10c90 65 20 76 69 61 20 74 68 65 20 73 61 6d 65 20 64 e via the same d
10ca0 61 74 61 62 61 73 65 0a 2a 2a 20 63 6f 6e 6e 65 atabase.** conne
10cb0 63 74 69 6f 6e 20 61 73 20 74 68 61 74 20 75 73 ction as that us
10cc0 65 64 20 74 6f 20 65 78 65 63 75 74 65 20 53 51 ed to execute SQ
10cd0 4c 20 6f 70 65 72 61 74 69 6f 6e 73 20 6f 6e 20 L operations on
10ce0 74 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c the virtual tabl
10cf0 65 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c 20 56 54 61 e..**.** All VTa
10d00 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 68 61 74 ble objects that
10d10 20 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 61 correspond to a
10d20 20 73 69 6e 67 6c 65 20 74 61 62 6c 65 20 69 6e single table in
10d30 20 61 20 73 68 61 72 65 64 0a 2a 2a 20 64 61 74 a shared.** dat
10d40 61 62 61 73 65 20 73 63 68 65 6d 61 20 61 72 65 abase schema are
10d50 20 69 6e 69 74 69 61 6c 6c 79 20 73 74 6f 72 65 initially store
10d60 64 20 69 6e 20 61 20 6c 69 6e 6b 65 64 2d 6c 69 d in a linked-li
10d70 73 74 20 70 6f 69 6e 74 65 64 20 74 6f 20 62 79 st pointed to by
10d80 0a 2a 2a 20 74 68 65 20 54 61 62 6c 65 2e 70 56 .** the Table.pV
10d90 54 61 62 6c 65 20 6d 65 6d 62 65 72 20 76 61 72 Table member var
10da0 69 61 62 6c 65 20 6f 66 20 74 68 65 20 63 6f 72 iable of the cor
10db0 72 65 73 70 6f 6e 64 69 6e 67 20 54 61 62 6c 65 responding Table
10dc0 20 6f 62 6a 65 63 74 2e 0a 2a 2a 20 57 68 65 6e object..** When
10dd0 20 61 6e 20 73 71 6c 69 74 65 33 5f 70 72 65 70 an sqlite3_prep
10de0 61 72 65 28 29 20 6f 70 65 72 61 74 69 6f 6e 20 are() operation
10df0 69 73 20 72 65 71 75 69 72 65 64 20 74 6f 20 61 is required to a
10e00 63 63 65 73 73 20 74 68 65 20 76 69 72 74 75 61 ccess the virtua
10e10 6c 0a 2a 2a 20 74 61 62 6c 65 2c 20 69 74 20 73 l.** table, it s
10e20 65 61 72 63 68 65 73 20 74 68 65 20 6c 69 73 74 earches the list
10e30 20 66 6f 72 20 74 68 65 20 56 54 61 62 6c 65 20 for the VTable
10e40 74 68 61 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 that corresponds
10e50 20 74 6f 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 to the.** datab
10e60 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 64 ase connection d
10e70 6f 69 6e 67 20 74 68 65 20 70 72 65 70 61 72 69 oing the prepari
10e80 6e 67 20 73 6f 20 61 73 20 74 6f 20 75 73 65 20 ng so as to use
10e90 74 68 65 20 63 6f 72 72 65 63 74 0a 2a 2a 20 73 the correct.** s
10ea0 71 6c 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e qlite3_vtab* han
10eb0 64 6c 65 20 69 6e 20 74 68 65 20 63 6f 6d 70 69 dle in the compi
10ec0 6c 65 64 20 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a led query..**.**
10ed0 20 57 68 65 6e 20 61 6e 20 69 6e 2d 6d 65 6d 6f When an in-memo
10ee0 72 79 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 20 ry Table object
10ef0 69 73 20 64 65 6c 65 74 65 64 20 28 66 6f 72 20 is deleted (for
10f00 65 78 61 6d 70 6c 65 20 77 68 65 6e 20 74 68 65 example when the
10f10 0a 2a 2a 20 73 63 68 65 6d 61 20 69 73 20 62 65 .** schema is be
10f20 69 6e 67 20 72 65 6c 6f 61 64 65 64 20 66 6f 72 ing reloaded for
10f30 20 73 6f 6d 65 20 72 65 61 73 6f 6e 29 2c 20 74 some reason), t
10f40 68 65 20 56 54 61 62 6c 65 20 6f 62 6a 65 63 74 he VTable object
10f50 73 20 61 72 65 20 6e 6f 74 0a 2a 2a 20 64 65 6c s are not.** del
10f60 65 74 65 64 20 61 6e 64 20 74 68 65 20 73 71 6c eted and the sql
10f70 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c ite3_vtab* handl
10f80 65 73 20 61 72 65 20 6e 6f 74 20 78 44 69 73 63 es are not xDisc
10f90 6f 6e 6e 65 63 74 28 29 65 64 0a 2a 2a 20 69 6d onnect()ed.** im
10fa0 6d 65 64 69 61 74 65 6c 79 2e 20 49 6e 73 74 65 mediately. Inste
10fb0 61 64 2c 20 74 68 65 79 20 61 72 65 20 6d 6f 76 ad, they are mov
10fc0 65 64 20 66 72 6f 6d 20 74 68 65 20 54 61 62 6c ed from the Tabl
10fd0 65 2e 70 56 54 61 62 6c 65 20 6c 69 73 74 20 74 e.pVTable list t
10fe0 6f 0a 2a 2a 20 61 6e 6f 74 68 65 72 20 6c 69 6e o.** another lin
10ff0 6b 65 64 20 6c 69 73 74 20 68 65 61 64 65 64 20 ked list headed
11000 62 79 20 74 68 65 20 73 71 6c 69 74 65 33 2e 70 by the sqlite3.p
11010 44 69 73 63 6f 6e 6e 65 63 74 20 6d 65 6d 62 65 Disconnect membe
11020 72 20 6f 66 20 74 68 65 0a 2a 2a 20 63 6f 72 72 r of the.** corr
11030 65 73 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 esponding sqlite
11040 33 20 73 74 72 75 63 74 75 72 65 2e 20 54 68 65 3 structure. The
11050 79 20 61 72 65 20 74 68 65 6e 20 64 65 6c 65 74 y are then delet
11060 65 64 2f 78 44 69 73 63 6f 6e 6e 65 63 74 65 64 ed/xDisconnected
11070 0a 2a 2a 20 6e 65 78 74 20 74 69 6d 65 20 61 20 .** next time a
11080 73 74 61 74 65 6d 65 6e 74 20 69 73 20 70 72 65 statement is pre
11090 70 61 72 65 64 20 75 73 69 6e 67 20 73 61 69 64 pared using said
110a0 20 73 71 6c 69 74 65 33 2a 2e 20 54 68 69 73 20 sqlite3*. This
110b0 69 73 20 64 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 is done.** to av
110c0 6f 69 64 20 64 65 61 64 6c 6f 63 6b 20 69 73 73 oid deadlock iss
110d0 75 65 73 20 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 ues involving mu
110e0 6c 74 69 70 6c 65 20 73 71 6c 69 74 65 33 2e 6d ltiple sqlite3.m
110f0 75 74 65 78 20 6d 75 74 65 78 65 73 2e 0a 2a 2a utex mutexes..**
11100 20 52 65 66 65 72 20 74 6f 20 63 6f 6d 6d 65 6e Refer to commen
11110 74 73 20 61 62 6f 76 65 20 66 75 6e 63 74 69 6f ts above functio
11120 6e 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c n sqlite3VtabUnl
11130 6f 63 6b 4c 69 73 74 28 29 20 66 6f 72 20 61 6e ockList() for an
11140 0a 2a 2a 20 65 78 70 6c 61 6e 61 74 69 6f 6e 20 .** explanation
11150 61 73 20 74 6f 20 77 68 79 20 69 74 20 69 73 20 as to why it is
11160 73 61 66 65 20 74 6f 20 61 64 64 20 61 6e 20 65 safe to add an e
11170 6e 74 72 79 20 74 6f 20 61 6e 20 73 71 6c 69 74 ntry to an sqlit
11180 65 33 2e 70 44 69 73 63 6f 6e 6e 65 63 74 0a 2a e3.pDisconnect.*
11190 2a 20 6c 69 73 74 20 77 69 74 68 6f 75 74 20 68 * list without h
111a0 6f 6c 64 69 6e 67 20 74 68 65 20 63 6f 72 72 65 olding the corre
111b0 73 70 6f 6e 64 69 6e 67 20 73 71 6c 69 74 65 33 sponding sqlite3
111c0 2e 6d 75 74 65 78 20 6d 75 74 65 78 2e 0a 2a 2a .mutex mutex..**
111d0 0a 2a 2a 20 54 68 65 20 6d 65 6d 6f 72 79 20 66 .** The memory f
111e0 6f 72 20 6f 62 6a 65 63 74 73 20 6f 66 20 74 68 or objects of th
111f0 69 73 20 74 79 70 65 20 69 73 20 61 6c 77 61 79 is type is alway
11200 73 20 61 6c 6c 6f 63 61 74 65 64 20 62 79 0a 2a s allocated by.*
11210 2a 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f * sqlite3DbMallo
11220 63 28 29 2c 20 75 73 69 6e 67 20 74 68 65 20 63 c(), using the c
11230 6f 6e 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 onnection handle
11240 20 73 74 6f 72 65 64 20 69 6e 20 56 54 61 62 6c stored in VTabl
11250 65 2e 64 62 20 61 73 0a 2a 2a 20 74 68 65 20 66 e.db as.** the f
11260 69 72 73 74 20 61 72 67 75 6d 65 6e 74 2e 0a 2a irst argument..*
11270 2f 0a 73 74 72 75 63 74 20 56 54 61 62 6c 65 20 /.struct VTable
11280 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b {. sqlite3 *db;
11290 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
112a0 20 44 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 Database connec
112b0 74 69 6f 6e 20 61 73 73 6f 63 69 61 74 65 64 20 tion associated
112c0 77 69 74 68 20 74 68 69 73 20 74 61 62 6c 65 20 with this table
112d0 2a 2f 0a 20 20 4d 6f 64 75 6c 65 20 2a 70 4d 6f */. Module *pMo
112e0 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f d; /
112f0 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 6d 6f 64 * Pointer to mod
11300 75 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 ule implementati
11310 6f 6e 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f on */. sqlite3_
11320 76 74 61 62 20 2a 70 56 74 61 62 3b 20 20 20 20 vtab *pVtab;
11330 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
11340 76 74 61 62 20 69 6e 73 74 61 6e 63 65 20 2a 2f vtab instance */
11350 0a 20 20 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 . int nRef;
11360 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
11370 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 Number of pointe
11380 72 73 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 rs to this struc
11390 74 75 72 65 20 2a 2f 0a 20 20 75 38 20 62 43 6f ture */. u8 bCo
113a0 6e 73 74 72 61 69 6e 74 3b 20 20 20 20 20 20 20 nstraint;
113b0 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 /* True if c
113c0 6f 6e 73 74 72 61 69 6e 74 73 20 61 72 65 20 73 onstraints are s
113d0 75 70 70 6f 72 74 65 64 20 2a 2f 0a 20 20 69 6e upported */. in
113e0 74 20 69 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 t iSavepoint;
113f0 20 20 20 20 20 20 20 20 2f 2a 20 44 65 70 74 68 /* Depth
11400 20 6f 66 20 74 68 65 20 53 41 56 45 50 4f 49 4e of the SAVEPOIN
11410 54 20 73 74 61 63 6b 20 2a 2f 0a 20 20 56 54 61 T stack */. VTa
11420 62 6c 65 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 ble *pNext;
11430 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 69 /* Next i
11440 6e 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 28 73 n linked list (s
11450 65 65 20 61 62 6f 76 65 29 20 2a 2f 0a 7d 3b 0a ee above) */.};.
11460 0a 2f 2a 0a 2a 2a 20 54 68 65 20 73 63 68 65 6d ./*.** The schem
11470 61 20 66 6f 72 20 65 61 63 68 20 53 51 4c 20 74 a for each SQL t
11480 61 62 6c 65 20 61 6e 64 20 76 69 65 77 20 69 73 able and view is
11490 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e 20 represented in
114a0 6d 65 6d 6f 72 79 0a 2a 2a 20 62 79 20 61 6e 20 memory.** by an
114b0 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
114c0 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
114d0 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 54 ure..*/.struct T
114e0 61 62 6c 65 20 7b 0a 20 20 63 68 61 72 20 2a 7a able {. char *z
114f0 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 2f 2a Name; /*
11500 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 Name of the tab
11510 6c 65 20 6f 72 20 76 69 65 77 20 2a 2f 0a 20 20 le or view */.
11520 43 6f 6c 75 6d 6e 20 2a 61 43 6f 6c 3b 20 20 20 Column *aCol;
11530 20 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 /* Informat
11540 69 6f 6e 20 61 62 6f 75 74 20 65 61 63 68 20 63 ion about each c
11550 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 6e 64 65 78 olumn */. Index
11560 20 2a 70 49 6e 64 65 78 3b 20 20 20 20 20 20 20 *pIndex;
11570 2f 2a 20 4c 69 73 74 20 6f 66 20 53 51 4c 20 69 /* List of SQL i
11580 6e 64 65 78 65 73 20 6f 6e 20 74 68 69 73 20 74 ndexes on this t
11590 61 62 6c 65 2e 20 2a 2f 0a 20 20 53 65 6c 65 63 able. */. Selec
115a0 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 20 20 t *pSelect;
115b0 2f 2a 20 4e 55 4c 4c 20 66 6f 72 20 74 61 62 6c /* NULL for tabl
115c0 65 73 2e 20 20 50 6f 69 6e 74 73 20 74 6f 20 64 es. Points to d
115d0 65 66 69 6e 69 74 69 6f 6e 20 69 66 20 61 20 76 efinition if a v
115e0 69 65 77 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a iew. */. FKey *
115f0 70 46 4b 65 79 3b 20 20 20 20 20 20 20 20 20 2f pFKey; /
11600 2a 20 4c 69 6e 6b 65 64 20 6c 69 73 74 20 6f 66 * Linked list of
11610 20 61 6c 6c 20 66 6f 72 65 69 67 6e 20 6b 65 79 all foreign key
11620 73 20 69 6e 20 74 68 69 73 20 74 61 62 6c 65 20 s in this table
11630 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c 41 */. char *zColA
11640 66 66 3b 20 20 20 20 20 20 20 2f 2a 20 53 74 72 ff; /* Str
11650 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 68 65 ing defining the
11660 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 61 63 affinity of eac
11670 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 45 78 h column */. Ex
11680 70 72 4c 69 73 74 20 2a 70 43 68 65 63 6b 3b 20 prList *pCheck;
11690 20 20 20 2f 2a 20 41 6c 6c 20 43 48 45 43 4b 20 /* All CHECK
116a0 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 constraints */.
116b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
116c0 20 20 20 20 20 20 2f 2a 20 20 20 2e 2e 2e 20 61 /* ... a
116d0 6c 73 6f 20 75 73 65 64 20 61 73 20 63 6f 6c 75 lso used as colu
116e0 6d 6e 20 6e 61 6d 65 20 6c 69 73 74 20 69 6e 20 mn name list in
116f0 61 20 56 49 45 57 20 2a 2f 0a 20 20 69 6e 74 20 a VIEW */. int
11700 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 20 20 tnum;
11710 20 2f 2a 20 52 6f 6f 74 20 42 54 72 65 65 20 70 /* Root BTree p
11720 61 67 65 20 66 6f 72 20 74 68 69 73 20 74 61 62 age for this tab
11730 6c 65 20 2a 2f 0a 20 20 75 33 32 20 6e 52 65 66 le */. u32 nRef
11740 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
11750 4e 75 6d 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 Number of pointe
11760 72 73 20 74 6f 20 74 68 69 73 20 54 61 62 6c 65 rs to this Table
11770 20 2a 2f 0a 20 20 69 31 36 20 69 50 4b 65 79 3b */. i16 iPKey;
11780 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 66 /* If
11790 20 6e 6f 74 20 6e 65 67 61 74 69 76 65 2c 20 75 not negative, u
117a0 73 65 20 61 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 se aCol[iPKey] a
117b0 73 20 74 68 65 20 72 6f 77 69 64 20 2a 2f 0a 20 s the rowid */.
117c0 20 69 31 36 20 6e 43 6f 6c 3b 20 20 20 20 20 20 i16 nCol;
117d0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
117e0 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 of columns in th
117f0 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f is table */. Lo
11800 67 45 73 74 20 6e 52 6f 77 4c 6f 67 45 73 74 3b gEst nRowLogEst;
11810 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 /* Estimated
11820 72 6f 77 73 20 69 6e 20 74 61 62 6c 65 20 2d 20 rows in table -
11830 66 72 6f 6d 20 73 71 6c 69 74 65 5f 73 74 61 74 from sqlite_stat
11840 31 20 74 61 62 6c 65 20 2a 2f 0a 20 20 4c 6f 67 1 table */. Log
11850 45 73 74 20 73 7a 54 61 62 52 6f 77 3b 20 20 20 Est szTabRow;
11860 20 20 2f 2a 20 45 73 74 69 6d 61 74 65 64 20 73 /* Estimated s
11870 69 7a 65 20 6f 66 20 65 61 63 68 20 74 61 62 6c ize of each tabl
11880 65 20 72 6f 77 20 69 6e 20 62 79 74 65 73 20 2a e row in bytes *
11890 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
118a0 45 4e 41 42 4c 45 5f 43 4f 53 54 4d 55 4c 54 0a ENABLE_COSTMULT.
118b0 20 20 4c 6f 67 45 73 74 20 63 6f 73 74 4d 75 6c LogEst costMul
118c0 74 3b 20 20 20 20 20 2f 2a 20 43 6f 73 74 20 6d t; /* Cost m
118d0 75 6c 74 69 70 6c 69 65 72 20 66 6f 72 20 75 73 ultiplier for us
118e0 69 6e 67 20 74 68 69 73 20 74 61 62 6c 65 20 2a ing this table *
118f0 2f 0a 23 65 6e 64 69 66 0a 20 20 75 38 20 74 61 /.#endif. u8 ta
11900 62 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 bFlags;
11910 2f 2a 20 4d 61 73 6b 20 6f 66 20 54 46 5f 2a 20 /* Mask of TF_*
11920 76 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 20 6b values */. u8 k
11930 65 79 43 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 eyConf;
11940 20 2f 2a 20 57 68 61 74 20 74 6f 20 64 6f 20 69 /* What to do i
11950 6e 20 63 61 73 65 20 6f 66 20 75 6e 69 71 75 65 n case of unique
11960 6e 65 73 73 20 63 6f 6e 66 6c 69 63 74 20 6f 6e ness conflict on
11970 20 69 50 4b 65 79 20 2a 2f 0a 23 69 66 6e 64 65 iPKey */.#ifnde
11980 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 4c f SQLITE_OMIT_AL
11990 54 45 52 54 41 42 4c 45 0a 20 20 69 6e 74 20 61 TERTABLE. int a
119a0 64 64 43 6f 6c 4f 66 66 73 65 74 3b 20 20 20 20 ddColOffset;
119b0 2f 2a 20 4f 66 66 73 65 74 20 69 6e 20 43 52 45 /* Offset in CRE
119c0 41 54 45 20 54 41 42 4c 45 20 73 74 6d 74 20 74 ATE TABLE stmt t
119d0 6f 20 61 64 64 20 61 20 6e 65 77 20 63 6f 6c 75 o add a new colu
119e0 6d 6e 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 66 mn */.#endif.#if
119f0 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
11a00 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 20 20 _VIRTUALTABLE.
11a10 69 6e 74 20 6e 4d 6f 64 75 6c 65 41 72 67 3b 20 int nModuleArg;
11a20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
11a30 66 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 74 f arguments to t
11a40 68 65 20 6d 6f 64 75 6c 65 20 2a 2f 0a 20 20 63 he module */. c
11a50 68 61 72 20 2a 2a 61 7a 4d 6f 64 75 6c 65 41 72 har **azModuleAr
11a60 67 3b 20 20 2f 2a 20 30 3a 20 6d 6f 64 75 6c 65 g; /* 0: module
11a70 20 31 3a 20 73 63 68 65 6d 61 20 32 3a 20 76 74 1: schema 2: vt
11a80 61 62 20 6e 61 6d 65 20 33 2e 2e 2e 3a 20 61 72 ab name 3...: ar
11a90 67 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a gs */. VTable *
11aa0 70 56 54 61 62 6c 65 3b 20 20 20 20 20 2f 2a 20 pVTable; /*
11ab0 4c 69 73 74 20 6f 66 20 56 54 61 62 6c 65 20 6f List of VTable o
11ac0 62 6a 65 63 74 73 2e 20 2a 2f 0a 23 65 6e 64 69 bjects. */.#endi
11ad0 66 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 f. Trigger *pTr
11ae0 69 67 67 65 72 3b 20 20 20 2f 2a 20 4c 69 73 74 igger; /* List
11af0 20 6f 66 20 74 72 69 67 67 65 72 73 20 73 74 6f of triggers sto
11b00 72 65 64 20 69 6e 20 70 53 63 68 65 6d 61 20 2a red in pSchema *
11b10 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 /. Schema *pSch
11b20 65 6d 61 3b 20 20 20 20 20 2f 2a 20 53 63 68 65 ema; /* Sche
11b30 6d 61 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 ma that contains
11b40 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 this table */.
11b50 20 54 61 62 6c 65 20 2a 70 4e 65 78 74 5a 6f 6d Table *pNextZom
11b60 62 69 65 3b 20 20 2f 2a 20 4e 65 78 74 20 6f 6e bie; /* Next on
11b70 20 74 68 65 20 50 61 72 73 65 2e 70 5a 6f 6d 62 the Parse.pZomb
11b80 69 65 54 61 62 20 6c 69 73 74 20 2a 2f 0a 7d 3b ieTab list */.};
11b90 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 ../*.** Allowed
11ba0 76 61 6c 75 65 73 20 66 6f 72 20 54 61 62 6c 65 values for Table
11bb0 2e 74 61 62 46 6c 61 67 73 2e 0a 2a 2a 0a 2a 2a .tabFlags..**.**
11bc0 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e 20 61 70 TF_OOOHidden ap
11bd0 70 6c 69 65 73 20 74 6f 20 74 61 62 6c 65 73 20 plies to tables
11be0 6f 72 20 76 69 65 77 20 74 68 61 74 20 68 61 76 or view that hav
11bf0 65 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 e hidden columns
11c00 20 74 68 61 74 20 61 72 65 0a 2a 2a 20 66 6f 6c that are.** fol
11c10 6c 6f 77 65 64 20 62 79 20 6e 6f 6e 2d 68 69 64 lowed by non-hid
11c20 64 65 6e 20 63 6f 6c 75 6d 6e 73 2e 20 20 45 78 den columns. Ex
11c30 61 6d 70 6c 65 3a 20 20 22 43 52 45 41 54 45 20 ample: "CREATE
11c40 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 20 VIRTUAL TABLE x
11c50 55 53 49 4e 47 0a 2a 2a 20 76 74 61 62 31 28 61 USING.** vtab1(a
11c60 20 48 49 44 44 45 4e 2c 20 62 29 3b 22 2e 20 20 HIDDEN, b);".
11c70 53 69 6e 63 65 20 22 62 22 20 69 73 20 61 20 6e Since "b" is a n
11c80 6f 6e 2d 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e on-hidden column
11c90 20 62 75 74 20 22 61 22 20 69 73 20 68 69 64 64 but "a" is hidd
11ca0 65 6e 2c 0a 2a 2a 20 74 68 65 20 54 46 5f 4f 4f en,.** the TF_OO
11cb0 4f 48 69 64 64 65 6e 20 61 74 74 72 69 62 75 74 OHidden attribut
11cc0 65 20 77 6f 75 6c 64 20 61 70 70 6c 79 20 69 6e e would apply in
11cd0 20 74 68 69 73 20 63 61 73 65 2e 20 20 53 75 63 this case. Suc
11ce0 68 20 74 61 62 6c 65 73 20 72 65 71 75 69 72 65 h tables require
11cf0 0a 2a 2a 20 73 70 65 63 69 61 6c 20 68 61 6e 64 .** special hand
11d00 6c 69 6e 67 20 64 75 72 69 6e 67 20 49 4e 53 45 ling during INSE
11d10 52 54 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a 2a RT processing..*
11d20 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 52 65 61 /.#define TF_Rea
11d30 64 6f 6e 6c 79 20 20 20 20 20 20 20 20 30 78 30 donly 0x0
11d40 31 20 20 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 1 /* Read-onl
11d50 79 20 73 79 73 74 65 6d 20 74 61 62 6c 65 20 2a y system table *
11d60 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 45 70 68 /.#define TF_Eph
11d70 65 6d 65 72 61 6c 20 20 20 20 20 20 20 30 78 30 emeral 0x0
11d80 32 20 20 20 20 2f 2a 20 41 6e 20 65 70 68 65 6d 2 /* An ephem
11d90 65 72 61 6c 20 74 61 62 6c 65 20 2a 2f 0a 23 64 eral table */.#d
11da0 65 66 69 6e 65 20 54 46 5f 48 61 73 50 72 69 6d efine TF_HasPrim
11db0 61 72 79 4b 65 79 20 20 20 30 78 30 34 20 20 20 aryKey 0x04
11dc0 20 2f 2a 20 54 61 62 6c 65 20 68 61 73 20 61 20 /* Table has a
11dd0 70 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 primary key */.#
11de0 64 65 66 69 6e 65 20 54 46 5f 41 75 74 6f 69 6e define TF_Autoin
11df0 63 72 65 6d 65 6e 74 20 20 20 30 78 30 38 20 20 crement 0x08
11e00 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 70 72 69 /* Integer pri
11e10 6d 61 72 79 20 6b 65 79 20 69 73 20 61 75 74 6f mary key is auto
11e20 69 6e 63 72 65 6d 65 6e 74 20 2a 2f 0a 23 64 65 increment */.#de
11e30 66 69 6e 65 20 54 46 5f 56 69 72 74 75 61 6c 20 fine TF_Virtual
11e40 20 20 20 20 20 20 20 20 30 78 31 30 20 20 20 20 0x10
11e50 2f 2a 20 49 73 20 61 20 76 69 72 74 75 61 6c 20 /* Is a virtual
11e60 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 table */.#define
11e70 20 54 46 5f 57 69 74 68 6f 75 74 52 6f 77 69 64 TF_WithoutRowid
11e80 20 20 20 20 30 78 32 30 20 20 20 20 2f 2a 20 4e 0x20 /* N
11e90 6f 20 72 6f 77 69 64 2e 20 20 50 52 49 4d 41 52 o rowid. PRIMAR
11ea0 59 20 4b 45 59 20 69 73 20 74 68 65 20 6b 65 79 Y KEY is the key
11eb0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 4e */.#define TF_N
11ec0 6f 56 69 73 69 62 6c 65 52 6f 77 69 64 20 20 30 oVisibleRowid 0
11ed0 78 34 30 20 20 20 20 2f 2a 20 4e 6f 20 75 73 65 x40 /* No use
11ee0 72 2d 76 69 73 69 62 6c 65 20 22 72 6f 77 69 64 r-visible "rowid
11ef0 22 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 64 65 66 " column */.#def
11f00 69 6e 65 20 54 46 5f 4f 4f 4f 48 69 64 64 65 6e ine TF_OOOHidden
11f10 20 20 20 20 20 20 20 30 78 38 30 20 20 20 20 2f 0x80 /
11f20 2a 20 4f 75 74 2d 6f 66 2d 4f 72 64 65 72 20 68 * Out-of-Order h
11f30 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 2a 2f idden columns */
11f40 0a 0a 0a 2f 2a 0a 2a 2a 20 54 65 73 74 20 74 6f .../*.** Test to
11f50 20 73 65 65 20 77 68 65 74 68 65 72 20 6f 72 20 see whether or
11f60 6e 6f 74 20 61 20 74 61 62 6c 65 20 69 73 20 61 not a table is a
11f70 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 2e 20 virtual table.
11f80 20 54 68 69 73 20 69 73 0a 2a 2a 20 64 6f 6e 65 This is.** done
11f90 20 61 73 20 61 20 6d 61 63 72 6f 20 73 6f 20 74 as a macro so t
11fa0 68 61 74 20 69 74 20 77 69 6c 6c 20 62 65 20 6f hat it will be o
11fb0 70 74 69 6d 69 7a 65 64 20 6f 75 74 20 77 68 65 ptimized out whe
11fc0 6e 20 76 69 72 74 75 61 6c 0a 2a 2a 20 74 61 62 n virtual.** tab
11fd0 6c 65 20 73 75 70 70 6f 72 74 20 69 73 20 6f 6d le support is om
11fe0 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 20 62 itted from the b
11ff0 75 69 6c 64 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 uild..*/.#ifndef
12000 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 SQLITE_OMIT_VIR
12010 54 55 41 4c 54 41 42 4c 45 0a 23 20 20 64 65 66 TUALTABLE.# def
12020 69 6e 65 20 49 73 56 69 72 74 75 61 6c 28 58 29 ine IsVirtual(X)
12030 20 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 62 (((X)->tab
12040 46 6c 61 67 73 20 26 20 54 46 5f 56 69 72 74 75 Flags & TF_Virtu
12050 61 6c 29 21 3d 30 29 0a 23 65 6c 73 65 0a 23 20 al)!=0).#else.#
12060 20 64 65 66 69 6e 65 20 49 73 56 69 72 74 75 61 define IsVirtua
12070 6c 28 58 29 20 20 20 20 20 20 30 0a 23 65 6e 64 l(X) 0.#end
12080 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 if../*.** Macros
12090 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 69 66 to determine if
120a0 20 61 20 63 6f 6c 75 6d 6e 20 69 73 20 68 69 64 a column is hid
120b0 64 65 6e 2e 20 20 49 73 4f 72 64 69 6e 61 72 79 den. IsOrdinary
120c0 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 29 0a 2a HiddenColumn().*
120d0 2a 20 6f 6e 6c 79 20 77 6f 72 6b 73 20 66 6f 72 * only works for
120e0 20 6e 6f 6e 2d 76 69 72 74 75 61 6c 20 74 61 62 non-virtual tab
120f0 6c 65 73 20 28 6f 72 64 69 6e 61 72 79 20 74 61 les (ordinary ta
12100 62 6c 65 73 20 61 6e 64 20 76 69 65 77 73 29 20 bles and views)
12110 61 6e 64 20 69 73 0a 2a 2a 20 61 6c 77 61 79 73 and is.** always
12120 20 66 61 6c 73 65 20 75 6e 6c 65 73 73 20 53 51 false unless SQ
12130 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 LITE_ENABLE_HIDD
12140 45 4e 5f 43 4f 4c 55 4d 4e 53 20 69 73 20 64 65 EN_COLUMNS is de
12150 66 69 6e 65 64 2e 20 20 54 68 65 0a 2a 2a 20 49 fined. The.** I
12160 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 29 20 sHiddenColumn()
12170 6d 61 63 72 6f 20 69 73 20 67 65 6e 65 72 61 6c macro is general
12180 20 70 75 72 70 6f 73 65 2e 0a 2a 2f 0a 23 69 66 purpose..*/.#if
12190 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
121a0 45 4e 41 42 4c 45 5f 48 49 44 44 45 4e 5f 43 4f ENABLE_HIDDEN_CO
121b0 4c 55 4d 4e 53 29 0a 23 20 20 64 65 66 69 6e 65 LUMNS).# define
121c0 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 IsHiddenColumn(
121d0 58 29 20 20 20 20 20 20 20 20 20 28 28 28 58 29 X) (((X)
121e0 2d 3e 63 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c ->colFlags & COL
121f0 46 4c 41 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 FLAG_HIDDEN)!=0)
12200 0a 23 20 20 64 65 66 69 6e 65 20 49 73 4f 72 64 .# define IsOrd
12210 69 6e 61 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d inaryHiddenColum
12220 6e 28 58 29 20 28 28 28 58 29 2d 3e 63 6f 6c 46 n(X) (((X)->colF
12230 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 47 5f 48 lags & COLFLAG_H
12240 49 44 44 45 4e 29 21 3d 30 29 0a 23 65 6c 69 66 IDDEN)!=0).#elif
12250 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
12260 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
12270 4c 45 29 0a 23 20 20 64 65 66 69 6e 65 20 49 73 LE).# define Is
12280 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 20 HiddenColumn(X)
12290 20 20 20 20 20 20 20 20 28 28 28 58 29 2d 3e 63 (((X)->c
122a0 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c 46 4c 41 olFlags & COLFLA
122b0 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 0a 23 20 G_HIDDEN)!=0).#
122c0 20 64 65 66 69 6e 65 20 49 73 4f 72 64 69 6e 61 define IsOrdina
122d0 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 ryHiddenColumn(X
122e0 29 20 30 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 ) 0.#else.# def
122f0 69 6e 65 20 49 73 48 69 64 64 65 6e 43 6f 6c 75 ine IsHiddenColu
12300 6d 6e 28 58 29 20 20 20 20 20 20 20 20 20 30 0a mn(X) 0.
12310 23 20 20 64 65 66 69 6e 65 20 49 73 4f 72 64 69 # define IsOrdi
12320 6e 61 72 79 48 69 64 64 65 6e 43 6f 6c 75 6d 6e naryHiddenColumn
12330 28 58 29 20 30 0a 23 65 6e 64 69 66 0a 0a 0a 2f (X) 0.#endif.../
12340 2a 20 44 6f 65 73 20 74 68 65 20 74 61 62 6c 65 * Does the table
12350 20 68 61 76 65 20 61 20 72 6f 77 69 64 20 2a 2f have a rowid */
12360 0a 23 64 65 66 69 6e 65 20 48 61 73 52 6f 77 69 .#define HasRowi
12370 64 28 58 29 20 20 20 20 20 28 28 28 58 29 2d 3e d(X) (((X)->
12380 74 61 62 46 6c 61 67 73 20 26 20 54 46 5f 57 69 tabFlags & TF_Wi
12390 74 68 6f 75 74 52 6f 77 69 64 29 3d 3d 30 29 0a thoutRowid)==0).
123a0 23 64 65 66 69 6e 65 20 56 69 73 69 62 6c 65 52 #define VisibleR
123b0 6f 77 69 64 28 58 29 20 28 28 28 58 29 2d 3e 74 owid(X) (((X)->t
123c0 61 62 46 6c 61 67 73 20 26 20 54 46 5f 4e 6f 56 abFlags & TF_NoV
123d0 69 73 69 62 6c 65 52 6f 77 69 64 29 3d 3d 30 29 isibleRowid)==0)
123e0 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 66 6f 72 ../*.** Each for
123f0 65 69 67 6e 20 6b 65 79 20 63 6f 6e 73 74 72 61 eign key constra
12400 69 6e 74 20 69 73 20 61 6e 20 69 6e 73 74 61 6e int is an instan
12410 63 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 ce of the follow
12420 69 6e 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a ing structure..*
12430 2a 0a 2a 2a 20 41 20 66 6f 72 65 69 67 6e 20 6b *.** A foreign k
12440 65 79 20 69 73 20 61 73 73 6f 63 69 61 74 65 64 ey is associated
12450 20 77 69 74 68 20 74 77 6f 20 74 61 62 6c 65 73 with two tables
12460 2e 20 20 54 68 65 20 22 66 72 6f 6d 22 20 74 61 . The "from" ta
12470 62 6c 65 20 69 73 0a 2a 2a 20 74 68 65 20 74 61 ble is.** the ta
12480 62 6c 65 20 74 68 61 74 20 63 6f 6e 74 61 69 6e ble that contain
12490 73 20 74 68 65 20 52 45 46 45 52 45 4e 43 45 53 s the REFERENCES
124a0 20 63 6c 61 75 73 65 20 74 68 61 74 20 63 72 65 clause that cre
124b0 61 74 65 73 20 74 68 65 20 66 6f 72 65 69 67 6e ates the foreign
124c0 0a 2a 2a 20 6b 65 79 2e 20 20 54 68 65 20 22 74 .** key. The "t
124d0 6f 22 20 74 61 62 6c 65 20 69 73 20 74 68 65 20 o" table is the
124e0 74 61 62 6c 65 20 74 68 61 74 20 69 73 20 6e 61 table that is na
124f0 6d 65 64 20 69 6e 20 74 68 65 20 52 45 46 45 52 med in the REFER
12500 45 4e 43 45 53 20 63 6c 61 75 73 65 2e 0a 2a 2a ENCES clause..**
12510 20 43 6f 6e 73 69 64 65 72 20 74 68 69 73 20 65 Consider this e
12520 78 61 6d 70 6c 65 3a 0a 2a 2a 0a 2a 2a 20 20 20 xample:.**.**
12530 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 CREATE TABLE e
12540 78 31 28 0a 2a 2a 20 20 20 20 20 20 20 61 20 49 x1(.** a I
12550 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b NTEGER PRIMARY K
12560 45 59 2c 0a 2a 2a 20 20 20 20 20 20 20 62 20 49 EY,.** b I
12570 4e 54 45 47 45 52 20 43 4f 4e 53 54 52 41 49 4e NTEGER CONSTRAIN
12580 54 20 66 6b 31 20 52 45 46 45 52 45 4e 43 45 53 T fk1 REFERENCES
12590 20 65 78 32 28 78 29 0a 2a 2a 20 20 20 20 20 29 ex2(x).** )
125a0 3b 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 66 6f 72 65 ;.**.** For fore
125b0 69 67 6e 20 6b 65 79 20 22 66 6b 31 22 2c 20 74 ign key "fk1", t
125c0 68 65 20 66 72 6f 6d 2d 74 61 62 6c 65 20 69 73 he from-table is
125d0 20 22 65 78 31 22 20 61 6e 64 20 74 68 65 20 74 "ex1" and the t
125e0 6f 2d 74 61 62 6c 65 20 69 73 20 22 65 78 32 22 o-table is "ex2"
125f0 2e 0a 2a 2a 20 45 71 75 69 76 61 6c 65 6e 74 20 ..** Equivalent
12600 6e 61 6d 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 names:.**.**
12610 20 66 72 6f 6d 2d 74 61 62 6c 65 20 3d 3d 20 63 from-table == c
12620 68 69 6c 64 2d 74 61 62 6c 65 0a 2a 2a 20 20 20 hild-table.**
12630 20 20 20 20 74 6f 2d 74 61 62 6c 65 20 3d 3d 20 to-table ==
12640 70 61 72 65 6e 74 2d 74 61 62 6c 65 0a 2a 2a 0a parent-table.**.
12650 2a 2a 20 45 61 63 68 20 52 45 46 45 52 45 4e 43 ** Each REFERENC
12660 45 53 20 63 6c 61 75 73 65 20 67 65 6e 65 72 61 ES clause genera
12670 74 65 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 tes an instance
12680 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
12690 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 77 68 structure.** wh
126a0 69 63 68 20 69 73 20 61 74 74 61 63 68 65 64 20 ich is attached
126b0 74 6f 20 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c to the from-tabl
126c0 65 2e 20 20 54 68 65 20 74 6f 2d 74 61 62 6c 65 e. The to-table
126d0 20 6e 65 65 64 20 6e 6f 74 20 65 78 69 73 74 20 need not exist
126e0 77 68 65 6e 0a 2a 2a 20 74 68 65 20 66 72 6f 6d when.** the from
126f0 2d 74 61 62 6c 65 20 69 73 20 63 72 65 61 74 65 -table is create
12700 64 2e 20 20 54 68 65 20 65 78 69 73 74 65 6e 63 d. The existenc
12710 65 20 6f 66 20 74 68 65 20 74 6f 2d 74 61 62 6c e of the to-tabl
12720 65 20 69 73 20 6e 6f 74 20 63 68 65 63 6b 65 64 e is not checked
12730 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6c 69 73 74 ..**.** The list
12740 20 6f 66 20 61 6c 6c 20 70 61 72 65 6e 74 73 20 of all parents
12750 66 6f 72 20 63 68 69 6c 64 20 54 61 62 6c 65 20 for child Table
12760 58 20 69 73 20 68 65 6c 64 20 61 74 20 58 2e 70 X is held at X.p
12770 46 4b 65 79 2e 0a 2a 2a 0a 2a 2a 20 41 20 6c 69 FKey..**.** A li
12780 73 74 20 6f 66 20 61 6c 6c 20 63 68 69 6c 64 72 st of all childr
12790 65 6e 20 66 6f 72 20 61 20 74 61 62 6c 65 20 6e en for a table n
127a0 61 6d 65 64 20 5a 20 28 77 68 69 63 68 20 6d 69 amed Z (which mi
127b0 67 68 74 20 6e 6f 74 20 65 76 65 6e 20 65 78 69 ght not even exi
127c0 73 74 29 0a 2a 2a 20 69 73 20 68 65 6c 64 20 69 st).** is held i
127d0 6e 20 53 63 68 65 6d 61 2e 66 6b 65 79 48 61 73 n Schema.fkeyHas
127e0 68 20 77 69 74 68 20 61 20 68 61 73 68 20 6b 65 h with a hash ke
127f0 79 20 6f 66 20 5a 2e 0a 2a 2f 0a 73 74 72 75 63 y of Z..*/.struc
12800 74 20 46 4b 65 79 20 7b 0a 20 20 54 61 62 6c 65 t FKey {. Table
12810 20 2a 70 46 72 6f 6d 3b 20 20 20 20 20 2f 2a 20 *pFrom; /*
12820 54 61 62 6c 65 20 63 6f 6e 74 61 69 6e 69 6e 67 Table containing
12830 20 74 68 65 20 52 45 46 45 52 45 4e 43 45 53 20 the REFERENCES
12840 63 6c 61 75 73 65 20 28 61 6b 61 3a 20 43 68 69 clause (aka: Chi
12850 6c 64 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 ld) */. FKey *p
12860 4e 65 78 74 46 72 6f 6d 3b 20 20 2f 2a 20 4e 65 NextFrom; /* Ne
12870 78 74 20 46 4b 65 79 20 77 69 74 68 20 74 68 65 xt FKey with the
12880 20 73 61 6d 65 20 69 6e 20 70 46 72 6f 6d 2e 20 same in pFrom.
12890 4e 65 78 74 20 70 61 72 65 6e 74 20 6f 66 20 70 Next parent of p
128a0 46 72 6f 6d 20 2a 2f 0a 20 20 63 68 61 72 20 2a From */. char *
128b0 7a 54 6f 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e zTo; /* N
128c0 61 6d 65 20 6f 66 20 74 61 62 6c 65 20 74 68 61 ame of table tha
128d0 74 20 74 68 65 20 6b 65 79 20 70 6f 69 6e 74 73 t the key points
128e0 20 74 6f 20 28 61 6b 61 3a 20 50 61 72 65 6e 74 to (aka: Parent
128f0 29 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 ) */. FKey *pNe
12900 78 74 54 6f 3b 20 20 20 20 2f 2a 20 4e 65 78 74 xtTo; /* Next
12910 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 7a with the same z
12920 54 6f 2e 20 4e 65 78 74 20 63 68 69 6c 64 20 6f To. Next child o
12930 66 20 7a 54 6f 2e 20 2a 2f 0a 20 20 46 4b 65 79 f zTo. */. FKey
12940 20 2a 70 50 72 65 76 54 6f 3b 20 20 20 20 2f 2a *pPrevTo; /*
12950 20 50 72 65 76 69 6f 75 73 20 77 69 74 68 20 74 Previous with t
12960 68 65 20 73 61 6d 65 20 7a 54 6f 20 2a 2f 0a 20 he same zTo */.
12970 20 69 6e 74 20 6e 43 6f 6c 3b 20 20 20 20 20 20 int nCol;
12980 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
12990 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 69 73 20 columns in this
129a0 6b 65 79 20 2a 2f 0a 20 20 2f 2a 20 45 56 3a 20 key */. /* EV:
129b0 52 2d 33 30 33 32 33 2d 32 31 39 31 37 20 2a 2f R-30323-21917 */
129c0 0a 20 20 75 38 20 69 73 44 65 66 65 72 72 65 64 . u8 isDeferred
129d0 3b 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 ; /* True
129e0 69 66 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 68 if constraint ch
129f0 65 63 6b 69 6e 67 20 69 73 20 64 65 66 65 72 72 ecking is deferr
12a00 65 64 20 74 69 6c 6c 20 43 4f 4d 4d 49 54 20 2a ed till COMMIT *
12a10 2f 0a 20 20 75 38 20 61 41 63 74 69 6f 6e 5b 32 /. u8 aAction[2
12a20 5d 3b 20 20 20 20 20 20 20 20 2f 2a 20 4f 4e 20 ]; /* ON
12a30 44 45 4c 45 54 45 20 61 6e 64 20 4f 4e 20 55 50 DELETE and ON UP
12a40 44 41 54 45 20 61 63 74 69 6f 6e 73 2c 20 72 65 DATE actions, re
12a50 73 70 65 63 74 69 76 65 6c 79 20 2a 2f 0a 20 20 spectively */.
12a60 54 72 69 67 67 65 72 20 2a 61 70 54 72 69 67 67 Trigger *apTrigg
12a70 65 72 5b 32 5d 3b 2f 2a 20 54 72 69 67 67 65 72 er[2];/* Trigger
12a80 73 20 66 6f 72 20 61 41 63 74 69 6f 6e 5b 5d 20 s for aAction[]
12a90 61 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 actions */. str
12aa0 75 63 74 20 73 43 6f 6c 4d 61 70 20 7b 20 20 20 uct sColMap {
12ab0 20 20 20 2f 2a 20 4d 61 70 70 69 6e 67 20 6f 66 /* Mapping of
12ac0 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 70 46 72 6f columns in pFro
12ad0 6d 20 74 6f 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 m to columns in
12ae0 7a 54 6f 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 zTo */. int i
12af0 46 72 6f 6d 3b 20 20 20 20 20 20 20 20 20 20 20 From;
12b00 20 2f 2a 20 49 6e 64 65 78 20 6f 66 20 63 6f 6c /* Index of col
12b10 75 6d 6e 20 69 6e 20 70 46 72 6f 6d 20 2a 2f 0a umn in pFrom */.
12b20 20 20 20 20 63 68 61 72 20 2a 7a 43 6f 6c 3b 20 char *zCol;
12b30 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d /* Nam
12b40 65 20 6f 66 20 63 6f 6c 75 6d 6e 20 69 6e 20 7a e of column in z
12b50 54 6f 2e 20 20 49 66 20 4e 55 4c 4c 20 75 73 65 To. If NULL use
12b60 20 50 52 49 4d 41 52 59 20 4b 45 59 20 2a 2f 0a PRIMARY KEY */.
12b70 20 20 7d 20 61 43 6f 6c 5b 31 5d 3b 20 20 20 20 } aCol[1];
12b80 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 65 /* One e
12b90 6e 74 72 79 20 66 6f 72 20 65 61 63 68 20 6f 66 ntry for each of
12ba0 20 6e 43 6f 6c 20 63 6f 6c 75 6d 6e 73 20 2a 2f nCol columns */
12bb0 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 69 74 .};../*.** SQLit
12bc0 65 20 73 75 70 70 6f 72 74 73 20 6d 61 6e 79 20 e supports many
12bd0 64 69 66 66 65 72 65 6e 74 20 77 61 79 73 20 74 different ways t
12be0 6f 20 72 65 73 6f 6c 76 65 20 61 20 63 6f 6e 73 o resolve a cons
12bf0 74 72 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 2e traint.** error.
12c00 20 20 52 4f 4c 4c 42 41 43 4b 20 70 72 6f 63 65 ROLLBACK proce
12c10 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 61 74 ssing means that
12c20 20 61 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 a constraint vi
12c30 6f 6c 61 74 69 6f 6e 0a 2a 2a 20 63 61 75 73 65 olation.** cause
12c40 73 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 s the operation
12c50 69 6e 20 70 72 6f 63 65 73 73 20 74 6f 20 66 61 in process to fa
12c60 69 6c 20 61 6e 64 20 66 6f 72 20 74 68 65 20 63 il and for the c
12c70 75 72 72 65 6e 74 20 74 72 61 6e 73 61 63 74 69 urrent transacti
12c80 6f 6e 0a 2a 2a 20 74 6f 20 62 65 20 72 6f 6c 6c on.** to be roll
12c90 65 64 20 62 61 63 6b 2e 20 20 41 42 4f 52 54 20 ed back. ABORT
12ca0 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 processing means
12cb0 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 69 the operation i
12cc0 6e 20 70 72 6f 63 65 73 73 0a 2a 2a 20 66 61 69 n process.** fai
12cd0 6c 73 20 61 6e 64 20 61 6e 79 20 70 72 69 6f 72 ls and any prior
12ce0 20 63 68 61 6e 67 65 73 20 66 72 6f 6d 20 74 68 changes from th
12cf0 61 74 20 6f 6e 65 20 6f 70 65 72 61 74 69 6f 6e at one operation
12d00 20 61 72 65 20 62 61 63 6b 65 64 20 6f 75 74 2c are backed out,
12d10 0a 2a 2a 20 62 75 74 20 74 68 65 20 74 72 61 6e .** but the tran
12d20 73 61 63 74 69 6f 6e 20 69 73 20 6e 6f 74 20 72 saction is not r
12d30 6f 6c 6c 65 64 20 62 61 63 6b 2e 20 20 46 41 49 olled back. FAI
12d40 4c 20 70 72 6f 63 65 73 73 69 6e 67 20 6d 65 61 L processing mea
12d50 6e 73 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 6f ns that.** the o
12d60 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 peration in prog
12d70 72 65 73 73 20 73 74 6f 70 73 20 61 6e 64 20 72 ress stops and r
12d80 65 74 75 72 6e 73 20 61 6e 20 65 72 72 6f 72 20 eturns an error
12d90 63 6f 64 65 2e 20 20 42 75 74 20 70 72 69 6f 72 code. But prior
12da0 0a 2a 2a 20 63 68 61 6e 67 65 73 20 64 75 65 20 .** changes due
12db0 74 6f 20 74 68 65 20 73 61 6d 65 20 6f 70 65 72 to the same oper
12dc0 61 74 69 6f 6e 20 61 72 65 20 6e 6f 74 20 62 61 ation are not ba
12dd0 63 6b 65 64 20 6f 75 74 20 61 6e 64 20 6e 6f 20 cked out and no
12de0 72 6f 6c 6c 62 61 63 6b 0a 2a 2a 20 6f 63 63 75 rollback.** occu
12df0 72 73 2e 20 20 49 47 4e 4f 52 45 20 6d 65 61 6e rs. IGNORE mean
12e00 73 20 74 68 61 74 20 74 68 65 20 70 61 72 74 69 s that the parti
12e10 63 75 6c 61 72 20 72 6f 77 20 74 68 61 74 20 63 cular row that c
12e20 61 75 73 65 64 20 74 68 65 20 63 6f 6e 73 74 72 aused the constr
12e30 61 69 6e 74 0a 2a 2a 20 65 72 72 6f 72 20 69 73 aint.** error is
12e40 20 6e 6f 74 20 69 6e 73 65 72 74 65 64 20 6f 72 not inserted or
12e50 20 75 70 64 61 74 65 64 2e 20 20 50 72 6f 63 65 updated. Proce
12e60 73 73 69 6e 67 20 63 6f 6e 74 69 6e 75 65 73 20 ssing continues
12e70 61 6e 64 20 6e 6f 20 65 72 72 6f 72 0a 2a 2a 20 and no error.**
12e80 69 73 20 72 65 74 75 72 6e 65 64 2e 20 20 52 45 is returned. RE
12e90 50 4c 41 43 45 20 6d 65 61 6e 73 20 74 68 61 74 PLACE means that
12ea0 20 70 72 65 65 78 69 73 74 69 6e 67 20 64 61 74 preexisting dat
12eb0 61 62 61 73 65 20 72 6f 77 73 20 74 68 61 74 20 abase rows that
12ec0 63 61 75 73 65 64 0a 2a 2a 20 61 20 55 4e 49 51 caused.** a UNIQ
12ed0 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 UE constraint vi
12ee0 6f 6c 61 74 69 6f 6e 20 61 72 65 20 72 65 6d 6f olation are remo
12ef0 76 65 64 20 73 6f 20 74 68 61 74 20 74 68 65 20 ved so that the
12f00 6e 65 77 20 69 6e 73 65 72 74 20 6f 72 0a 2a 2a new insert or.**
12f10 20 75 70 64 61 74 65 20 63 61 6e 20 70 72 6f 63 update can proc
12f20 65 65 64 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 eed. Processing
12f30 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e 64 20 6e continues and n
12f40 6f 20 65 72 72 6f 72 20 69 73 20 72 65 70 6f 72 o error is repor
12f50 74 65 64 2e 0a 2a 2a 0a 2a 2a 20 52 45 53 54 52 ted..**.** RESTR
12f60 49 43 54 2c 20 53 45 54 4e 55 4c 4c 2c 20 61 6e ICT, SETNULL, an
12f70 64 20 43 41 53 43 41 44 45 20 61 63 74 69 6f 6e d CASCADE action
12f80 73 20 61 70 70 6c 79 20 6f 6e 6c 79 20 74 6f 20 s apply only to
12f90 66 6f 72 65 69 67 6e 20 6b 65 79 73 2e 0a 2a 2a foreign keys..**
12fa0 20 52 45 53 54 52 49 43 54 20 69 73 20 74 68 65 RESTRICT is the
12fb0 20 73 61 6d 65 20 61 73 20 41 42 4f 52 54 20 66 same as ABORT f
12fc0 6f 72 20 49 4d 4d 45 44 49 41 54 45 20 66 6f 72 or IMMEDIATE for
12fd0 65 69 67 6e 20 6b 65 79 73 20 61 6e 64 20 74 68 eign keys and th
12fe0 65 0a 2a 2a 20 73 61 6d 65 20 61 73 20 52 4f 4c e.** same as ROL
12ff0 4c 42 41 43 4b 20 66 6f 72 20 44 45 46 45 52 52 LBACK for DEFERR
13000 45 44 20 6b 65 79 73 2e 20 20 53 45 54 4e 55 4c ED keys. SETNUL
13010 4c 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 L means that the
13020 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 foreign.** key
13030 69 73 20 73 65 74 20 74 6f 20 4e 55 4c 4c 2e 20 is set to NULL.
13040 20 43 41 53 43 41 44 45 20 6d 65 61 6e 73 20 74 CASCADE means t
13050 68 61 74 20 61 20 44 45 4c 45 54 45 20 6f 72 20 hat a DELETE or
13060 55 50 44 41 54 45 20 6f 66 20 74 68 65 0a 2a 2a UPDATE of the.**
13070 20 72 65 66 65 72 65 6e 63 65 64 20 74 61 62 6c referenced tabl
13080 65 20 72 6f 77 20 69 73 20 70 72 6f 70 61 67 61 e row is propaga
13090 74 65 64 20 69 6e 74 6f 20 74 68 65 20 72 6f 77 ted into the row
130a0 20 74 68 61 74 20 68 6f 6c 64 73 20 74 68 65 0a that holds the.
130b0 2a 2a 20 66 6f 72 65 69 67 6e 20 6b 65 79 2e 0a ** foreign key..
130c0 2a 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 **.** The follow
130d0 69 6e 67 20 73 79 6d 62 6f 6c 69 63 20 76 61 6c ing symbolic val
130e0 75 65 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 ues are used to
130f0 72 65 63 6f 72 64 20 77 68 69 63 68 20 74 79 70 record which typ
13100 65 0a 2a 2a 20 6f 66 20 61 63 74 69 6f 6e 20 74 e.** of action t
13110 6f 20 74 61 6b 65 2e 0a 2a 2f 0a 23 64 65 66 69 o take..*/.#defi
13120 6e 65 20 4f 45 5f 4e 6f 6e 65 20 20 20 20 20 30 ne OE_None 0
13130 20 20 20 2f 2a 20 54 68 65 72 65 20 69 73 20 6e /* There is n
13140 6f 20 63 6f 6e 73 74 72 61 69 6e 74 20 74 6f 20 o constraint to
13150 63 68 65 63 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 check */.#define
13160 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 31 20 20 OE_Rollback 1
13170 20 2f 2a 20 46 61 69 6c 20 74 68 65 20 6f 70 65 /* Fail the ope
13180 72 61 74 69 6f 6e 20 61 6e 64 20 72 6f 6c 6c 62 ration and rollb
13190 61 63 6b 20 74 68 65 20 74 72 61 6e 73 61 63 74 ack the transact
131a0 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ion */.#define O
131b0 45 5f 41 62 6f 72 74 20 20 20 20 32 20 20 20 2f E_Abort 2 /
131c0 2a 20 42 61 63 6b 20 6f 75 74 20 63 68 61 6e 67 * Back out chang
131d0 65 73 20 62 75 74 20 64 6f 20 6e 6f 20 72 6f 6c es but do no rol
131e0 6c 62 61 63 6b 20 74 72 61 6e 73 61 63 74 69 6f lback transactio
131f0 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f n */.#define OE_
13200 46 61 69 6c 20 20 20 20 20 33 20 20 20 2f 2a 20 Fail 3 /*
13210 53 74 6f 70 20 74 68 65 20 6f 70 65 72 61 74 69 Stop the operati
13220 6f 6e 20 62 75 74 20 6c 65 61 76 65 20 61 6c 6c on but leave all
13230 20 70 72 69 6f 72 20 63 68 61 6e 67 65 73 20 2a prior changes *
13240 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 49 67 6e /.#define OE_Ign
13250 6f 72 65 20 20 20 34 20 20 20 2f 2a 20 49 67 6e ore 4 /* Ign
13260 6f 72 65 20 74 68 65 20 65 72 72 6f 72 2e 20 44 ore the error. D
13270 6f 20 6e 6f 74 20 64 6f 20 74 68 65 20 49 4e 53 o not do the INS
13280 45 52 54 20 6f 72 20 55 50 44 41 54 45 20 2a 2f ERT or UPDATE */
13290 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 65 70 6c .#define OE_Repl
132a0 61 63 65 20 20 35 20 20 20 2f 2a 20 44 65 6c 65 ace 5 /* Dele
132b0 74 65 20 65 78 69 73 74 69 6e 67 20 72 65 63 6f te existing reco
132c0 72 64 2c 20 74 68 65 6e 20 64 6f 20 49 4e 53 45 rd, then do INSE
132d0 52 54 20 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a RT or UPDATE */.
132e0 0a 23 64 65 66 69 6e 65 20 4f 45 5f 52 65 73 74 .#define OE_Rest
132f0 72 69 63 74 20 36 20 20 20 2f 2a 20 4f 45 5f 41 rict 6 /* OE_A
13300 62 6f 72 74 20 66 6f 72 20 49 4d 4d 45 44 49 41 bort for IMMEDIA
13310 54 45 2c 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 TE, OE_Rollback
13320 66 6f 72 20 44 45 46 45 52 52 45 44 20 2a 2f 0a for DEFERRED */.
13330 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 4e 75 #define OE_SetNu
13340 6c 6c 20 20 37 20 20 20 2f 2a 20 53 65 74 20 74 ll 7 /* Set t
13350 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 he foreign key v
13360 61 6c 75 65 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a alue to NULL */.
13370 23 64 65 66 69 6e 65 20 4f 45 5f 53 65 74 44 66 #define OE_SetDf
13380 6c 74 20 20 38 20 20 20 2f 2a 20 53 65 74 20 74 lt 8 /* Set t
13390 68 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 76 he foreign key v
133a0 61 6c 75 65 20 74 6f 20 69 74 73 20 64 65 66 61 alue to its defa
133b0 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ult */.#define O
133c0 45 5f 43 61 73 63 61 64 65 20 20 39 20 20 20 2f E_Cascade 9 /
133d0 2a 20 43 61 73 63 61 64 65 20 74 68 65 20 63 68 * Cascade the ch
133e0 61 6e 67 65 73 20 2a 2f 0a 0a 23 64 65 66 69 6e anges */..#defin
133f0 65 20 4f 45 5f 44 65 66 61 75 6c 74 20 20 31 30 e OE_Default 10
13400 20 20 2f 2a 20 44 6f 20 77 68 61 74 65 76 65 72 /* Do whatever
13410 20 74 68 65 20 64 65 66 61 75 6c 74 20 61 63 74 the default act
13420 69 6f 6e 20 69 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a ion is */.../*.*
13430 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
13440 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
13450 74 72 75 63 74 75 72 65 20 69 73 20 70 61 73 73 tructure is pass
13460 65 64 20 61 73 20 74 68 65 20 66 69 72 73 74 0a ed as the first.
13470 2a 2a 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 73 ** argument to s
13480 71 6c 69 74 65 33 56 64 62 65 4b 65 79 43 6f 6d qlite3VdbeKeyCom
13490 70 61 72 65 20 61 6e 64 20 69 73 20 75 73 65 64 pare and is used
134a0 20 74 6f 20 63 6f 6e 74 72 6f 6c 20 74 68 65 0a to control the.
134b0 2a 2a 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 66 ** comparison of
134c0 20 74 68 65 20 74 77 6f 20 69 6e 64 65 78 20 6b the two index k
134d0 65 79 73 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 eys..**.** Note
134e0 74 68 61 74 20 61 53 6f 72 74 4f 72 64 65 72 5b that aSortOrder[
134f0 5d 20 61 6e 64 20 61 43 6f 6c 6c 5b 5d 20 68 61 ] and aColl[] ha
13500 76 65 20 6e 46 69 65 6c 64 2b 31 20 73 6c 6f 74 ve nField+1 slot
13510 73 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 s. There.** are
13520 20 6e 46 69 65 6c 64 20 73 6c 6f 74 73 20 66 6f nField slots fo
13530 72 20 74 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 r the columns of
13540 20 61 6e 20 69 6e 64 65 78 20 74 68 65 6e 20 6f an index then o
13550 6e 65 20 65 78 74 72 61 20 73 6c 6f 74 0a 2a 2a ne extra slot.**
13560 20 66 6f 72 20 74 68 65 20 72 6f 77 69 64 20 61 for the rowid a
13570 74 20 74 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 t the end..*/.st
13580 72 75 63 74 20 4b 65 79 49 6e 66 6f 20 7b 0a 20 ruct KeyInfo {.
13590 20 75 33 32 20 6e 52 65 66 3b 20 20 20 20 20 20 u32 nRef;
135a0 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
135b0 66 20 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 f references to
135c0 74 68 69 73 20 4b 65 79 49 6e 66 6f 20 6f 62 6a this KeyInfo obj
135d0 65 63 74 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b ect */. u8 enc;
135e0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
135f0 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 20 2d 20 Text encoding -
13600 6f 6e 65 20 6f 66 20 74 68 65 20 53 51 4c 49 54 one of the SQLIT
13610 45 5f 55 54 46 2a 20 76 61 6c 75 65 73 20 2a 2f E_UTF* values */
13620 0a 20 20 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 . u16 nField;
13630 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
13640 20 6f 66 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 of key columns
13650 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a in the index */.
13660 20 20 75 31 36 20 6e 58 46 69 65 6c 64 3b 20 20 u16 nXField;
13670 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
13680 6f 66 20 63 6f 6c 75 6d 6e 73 20 62 65 79 6f 6e of columns beyon
13690 64 20 74 68 65 20 6b 65 79 20 63 6f 6c 75 6d 6e d the key column
136a0 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a s */. sqlite3 *
136b0 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 db; /* Th
136c0 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 e database conne
136d0 63 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 2a 61 ction */. u8 *a
136e0 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 2f SortOrder; /
136f0 2a 20 53 6f 72 74 20 6f 72 64 65 72 20 66 6f 72 * Sort order for
13700 20 65 61 63 68 20 63 6f 6c 75 6d 6e 2e 20 2a 2f each column. */
13710 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 61 43 6f 6c . CollSeq *aCol
13720 6c 5b 31 5d 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 l[1]; /* Collat
13730 69 6e 67 20 73 65 71 75 65 6e 63 65 20 66 6f 72 ing sequence for
13740 20 65 61 63 68 20 74 65 72 6d 20 6f 66 20 74 68 each term of th
13750 65 20 6b 65 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a e key */.};../*.
13760 2a 2a 20 54 68 69 73 20 6f 62 6a 65 63 74 20 68 ** This object h
13770 6f 6c 64 73 20 61 20 72 65 63 6f 72 64 20 77 68 olds a record wh
13780 69 63 68 20 68 61 73 20 62 65 65 6e 20 70 61 72 ich has been par
13790 73 65 64 20 6f 75 74 20 69 6e 74 6f 20 69 6e 64 sed out into ind
137a0 69 76 69 64 75 61 6c 0a 2a 2a 20 66 69 65 6c 64 ividual.** field
137b0 73 2c 20 66 6f 72 20 74 68 65 20 70 75 72 70 6f s, for the purpo
137c0 73 65 73 20 6f 66 20 64 6f 69 6e 67 20 61 20 63 ses of doing a c
137d0 6f 6d 70 61 72 69 73 6f 6e 2e 0a 2a 2a 0a 2a 2a omparison..**.**
137e0 20 41 20 72 65 63 6f 72 64 20 69 73 20 61 6e 20 A record is an
137f0 6f 62 6a 65 63 74 20 74 68 61 74 20 63 6f 6e 74 object that cont
13800 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 ains one or more
13810 20 66 69 65 6c 64 73 20 6f 66 20 64 61 74 61 2e fields of data.
13820 0a 2a 2a 20 52 65 63 6f 72 64 73 20 61 72 65 20 .** Records are
13830 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 74 68 used to store th
13840 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 61 20 74 e content of a t
13850 61 62 6c 65 20 72 6f 77 20 61 6e 64 20 74 6f 20 able row and to
13860 73 74 6f 72 65 0a 2a 2a 20 74 68 65 20 6b 65 79 store.** the key
13870 20 6f 66 20 61 6e 20 69 6e 64 65 78 2e 20 20 41 of an index. A
13880 20 62 6c 6f 62 20 65 6e 63 6f 64 69 6e 67 20 6f blob encoding o
13890 66 20 61 20 72 65 63 6f 72 64 20 69 73 20 63 72 f a record is cr
138a0 65 61 74 65 64 20 62 79 0a 2a 2a 20 74 68 65 20 eated by.** the
138b0 4f 50 5f 4d 61 6b 65 52 65 63 6f 72 64 20 6f 70 OP_MakeRecord op
138c0 63 6f 64 65 20 6f 66 20 74 68 65 20 56 44 42 45 code of the VDBE
138d0 20 61 6e 64 20 69 73 20 64 69 73 61 73 73 65 6d and is disassem
138e0 62 6c 65 64 20 62 79 20 74 68 65 0a 2a 2a 20 4f bled by the.** O
138f0 50 5f 43 6f 6c 75 6d 6e 20 6f 70 63 6f 64 65 2e P_Column opcode.
13900 0a 2a 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e .**.** An instan
13910 63 65 20 6f 66 20 74 68 69 73 20 6f 62 6a 65 63 ce of this objec
13920 74 20 73 65 72 76 65 73 20 61 73 20 61 20 22 6b t serves as a "k
13930 65 79 22 20 66 6f 72 20 64 6f 69 6e 67 20 61 20 ey" for doing a
13940 73 65 61 72 63 68 20 6f 6e 0a 2a 2a 20 61 6e 20 search on.** an
13950 69 6e 64 65 78 20 62 2b 74 72 65 65 2e 20 54 68 index b+tree. Th
13960 65 20 67 6f 61 6c 20 6f 66 20 74 68 65 20 73 65 e goal of the se
13970 61 72 63 68 20 69 73 20 74 6f 20 66 69 6e 64 20 arch is to find
13980 74 68 65 20 65 6e 74 72 79 20 74 68 61 74 0a 2a the entry that.*
13990 2a 20 69 73 20 63 6c 6f 73 65 64 20 74 6f 20 74 * is closed to t
139a0 68 65 20 6b 65 79 20 64 65 73 63 72 69 62 65 64 he key described
139b0 20 62 79 20 74 68 69 73 20 6f 62 6a 65 63 74 2e by this object.
139c0 20 20 54 68 69 73 20 6f 62 6a 65 63 74 20 6d 69 This object mi
139d0 67 68 74 20 68 6f 6c 64 0a 2a 2a 20 6a 75 73 74 ght hold.** just
139e0 20 61 20 70 72 65 66 69 78 20 6f 66 20 74 68 65 a prefix of the
139f0 20 6b 65 79 2e 20 20 54 68 65 20 6e 75 6d 62 65 key. The numbe
13a00 72 20 6f 66 20 66 69 65 6c 64 73 20 69 73 20 67 r of fields is g
13a10 69 76 65 6e 20 62 79 0a 2a 2a 20 70 4b 65 79 49 iven by.** pKeyI
13a20 6e 66 6f 2d 3e 6e 46 69 65 6c 64 2e 0a 2a 2a 0a nfo->nField..**.
13a30 2a 2a 20 54 68 65 20 72 31 20 61 6e 64 20 72 32 ** The r1 and r2
13a40 20 66 69 65 6c 64 73 20 61 72 65 20 74 68 65 20 fields are the
13a50 76 61 6c 75 65 73 20 74 6f 20 72 65 74 75 72 6e values to return
13a60 20 69 66 20 74 68 69 73 20 6b 65 79 20 69 73 20 if this key is
13a70 6c 65 73 73 20 74 68 61 6e 0a 2a 2a 20 6f 72 20 less than.** or
13a80 67 72 65 61 74 65 72 20 74 68 61 6e 20 61 20 6b greater than a k
13a90 65 79 20 69 6e 20 74 68 65 20 62 74 72 65 65 2c ey in the btree,
13aa0 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 20 respectively.
13ab0 54 68 65 73 65 20 61 72 65 20 6e 6f 72 6d 61 6c These are normal
13ac0 6c 79 0a 2a 2a 20 2d 31 20 61 6e 64 20 2b 31 20 ly.** -1 and +1
13ad0 72 65 73 70 65 63 74 69 76 65 6c 79 2c 20 62 75 respectively, bu
13ae0 74 20 6d 69 67 68 74 20 62 65 20 69 6e 76 65 72 t might be inver
13af0 74 65 64 20 74 6f 20 2b 31 20 61 6e 64 20 2d 31 ted to +1 and -1
13b00 20 69 66 20 74 68 65 20 62 2d 74 72 65 65 0a 2a if the b-tree.*
13b10 2a 20 69 73 20 69 6e 20 44 45 53 43 20 6f 72 64 * is in DESC ord
13b20 65 72 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 6b 65 er..**.** The ke
13b30 79 20 63 6f 6d 70 61 72 69 73 6f 6e 20 66 75 6e y comparison fun
13b40 63 74 69 6f 6e 73 20 61 63 74 75 61 6c 6c 79 20 ctions actually
13b50 72 65 74 75 72 6e 20 64 65 66 61 75 6c 74 5f 72 return default_r
13b60 63 20 77 68 65 6e 20 74 68 65 79 20 66 69 6e 64 c when they find
13b70 0a 2a 2a 20 61 6e 20 65 71 75 61 6c 73 20 63 6f .** an equals co
13b80 6d 70 61 72 69 73 6f 6e 2e 20 20 64 65 66 61 75 mparison. defau
13b90 6c 74 5f 72 63 20 63 61 6e 20 62 65 20 2d 31 2c lt_rc can be -1,
13ba0 20 30 2c 20 6f 72 20 2b 31 2e 20 20 49 66 20 74 0, or +1. If t
13bb0 68 65 72 65 20 61 72 65 0a 2a 2a 20 6d 75 6c 74 here are.** mult
13bc0 69 70 6c 65 20 65 6e 74 72 69 65 73 20 69 6e 20 iple entries in
13bd0 74 68 65 20 62 2d 74 72 65 65 20 77 69 74 68 20 the b-tree with
13be0 74 68 65 20 73 61 6d 65 20 6b 65 79 20 28 77 68 the same key (wh
13bf0 65 6e 20 6f 6e 6c 79 20 6c 6f 6f 6b 69 6e 67 0a en only looking.
13c00 2a 2a 20 61 74 20 74 68 65 20 66 69 72 73 74 20 ** at the first
13c10 70 4b 65 79 49 6e 66 6f 2d 3e 6e 46 69 65 6c 64 pKeyInfo->nField
13c20 73 2c 29 20 74 68 65 6e 20 64 65 66 61 75 6c 74 s,) then default
13c30 5f 72 63 20 63 61 6e 20 62 65 20 73 65 74 20 74 _rc can be set t
13c40 6f 20 2d 31 20 74 6f 0a 2a 2a 20 63 61 75 73 65 o -1 to.** cause
13c50 20 74 68 65 20 73 65 61 72 63 68 20 74 6f 20 66 the search to f
13c60 69 6e 64 20 74 68 65 20 6c 61 73 74 20 6d 61 74 ind the last mat
13c70 63 68 2c 20 6f 72 20 2b 31 20 74 6f 20 63 61 75 ch, or +1 to cau
13c80 73 65 20 74 68 65 20 73 65 61 72 63 68 20 74 6f se the search to
13c90 0a 2a 2a 20 66 69 6e 64 20 74 68 65 20 66 69 72 .** find the fir
13ca0 73 74 20 6d 61 74 63 68 2e 0a 2a 2a 0a 2a 2a 20 st match..**.**
13cb0 54 68 65 20 6b 65 79 20 63 6f 6d 70 61 72 69 73 The key comparis
13cc0 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 77 69 6c on functions wil
13cd0 6c 20 73 65 74 20 65 71 53 65 65 6e 20 74 6f 20 l set eqSeen to
13ce0 74 72 75 65 20 69 66 20 74 68 65 79 20 65 76 65 true if they eve
13cf0 72 0a 2a 2a 20 67 65 74 20 61 6e 64 20 65 71 75 r.** get and equ
13d00 61 6c 20 72 65 73 75 6c 74 73 20 77 68 65 6e 20 al results when
13d10 63 6f 6d 70 61 72 69 6e 67 20 74 68 69 73 20 73 comparing this s
13d20 74 72 75 63 74 75 72 65 20 74 6f 20 61 20 62 2d tructure to a b-
13d30 74 72 65 65 20 72 65 63 6f 72 64 2e 0a 2a 2a 20 tree record..**
13d40 57 68 65 6e 20 64 65 66 61 75 6c 74 5f 72 63 21 When default_rc!
13d50 3d 30 2c 20 74 68 65 20 73 65 61 72 63 68 20 6d =0, the search m
13d60 69 67 68 74 20 65 6e 64 20 75 70 20 6f 6e 20 74 ight end up on t
13d70 68 65 20 72 65 63 6f 72 64 20 69 6d 6d 65 64 69 he record immedi
13d80 61 74 65 6c 79 0a 2a 2a 20 62 65 66 6f 72 65 20 ately.** before
13d90 74 68 65 20 66 69 72 73 74 20 6d 61 74 63 68 20 the first match
13da0 6f 72 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 61 or immediately a
13db0 66 74 65 72 20 74 68 65 20 6c 61 73 74 20 6d 61 fter the last ma
13dc0 74 63 68 2e 20 20 54 68 65 0a 2a 2a 20 65 71 53 tch. The.** eqS
13dd0 65 65 6e 20 66 69 65 6c 64 20 77 69 6c 6c 20 69 een field will i
13de0 6e 64 69 63 61 74 65 20 77 68 65 74 68 65 72 20 ndicate whether
13df0 6f 72 20 6e 6f 74 20 61 6e 20 65 78 61 63 74 20 or not an exact
13e00 6d 61 74 63 68 20 65 78 69 73 74 73 20 69 6e 20 match exists in
13e10 74 68 65 0a 2a 2a 20 62 2d 74 72 65 65 2e 0a 2a the.** b-tree..*
13e20 2f 0a 73 74 72 75 63 74 20 55 6e 70 61 63 6b 65 /.struct Unpacke
13e30 64 52 65 63 6f 72 64 20 7b 0a 20 20 4b 65 79 49 dRecord {. KeyI
13e40 6e 66 6f 20 2a 70 4b 65 79 49 6e 66 6f 3b 20 20 nfo *pKeyInfo;
13e50 2f 2a 20 43 6f 6c 6c 61 74 69 6f 6e 20 61 6e 64 /* Collation and
13e60 20 73 6f 72 74 2d 6f 72 64 65 72 20 69 6e 66 6f sort-order info
13e70 72 6d 61 74 69 6f 6e 20 2a 2f 0a 20 20 4d 65 6d rmation */. Mem
13e80 20 2a 61 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 *aMem;
13e90 20 2f 2a 20 56 61 6c 75 65 73 20 2a 2f 0a 20 20 /* Values */.
13ea0 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 20 20 20 u16 nField;
13eb0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
13ec0 20 65 6e 74 72 69 65 73 20 69 6e 20 61 70 4d 65 entries in apMe
13ed0 6d 5b 5d 20 2a 2f 0a 20 20 69 38 20 64 65 66 61 m[] */. i8 defa
13ee0 75 6c 74 5f 72 63 3b 20 20 20 20 20 20 2f 2a 20 ult_rc; /*
13ef0 43 6f 6d 70 61 72 69 73 6f 6e 20 72 65 73 75 6c Comparison resul
13f00 74 20 69 66 20 6b 65 79 73 20 61 72 65 20 65 71 t if keys are eq
13f10 75 61 6c 20 2a 2f 0a 20 20 75 38 20 65 72 72 43 ual */. u8 errC
13f20 6f 64 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ode; /*
13f30 45 72 72 6f 72 20 64 65 74 65 63 74 65 64 20 62 Error detected b
13f40 79 20 78 52 65 63 6f 72 64 43 6f 6d 70 61 72 65 y xRecordCompare
13f50 20 28 43 4f 52 52 55 50 54 20 6f 72 20 4e 4f 4d (CORRUPT or NOM
13f60 45 4d 29 20 2a 2f 0a 20 20 69 38 20 72 31 3b 20 EM) */. i8 r1;
13f70 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
13f80 56 61 6c 75 65 20 74 6f 20 72 65 74 75 72 6e 20 Value to return
13f90 69 66 20 28 6c 68 73 20 3e 20 72 68 73 29 20 2a if (lhs > rhs) *
13fa0 2f 0a 20 20 69 38 20 72 32 3b 20 20 20 20 20 20 /. i8 r2;
13fb0 20 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 /* Value
13fc0 20 74 6f 20 72 65 74 75 72 6e 20 69 66 20 28 72 to return if (r
13fd0 68 73 20 3c 20 6c 68 73 29 20 2a 2f 0a 20 20 75 hs < lhs) */. u
13fe0 38 20 65 71 53 65 65 6e 3b 20 20 20 20 20 20 20 8 eqSeen;
13ff0 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 61 6e /* True if an
14000 20 65 71 75 61 6c 69 74 79 20 63 6f 6d 70 61 72 equality compar
14010 69 73 6f 6e 20 68 61 73 20 62 65 65 6e 20 73 65 ison has been se
14020 65 6e 20 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a en */.};.../*.**
14030 20 45 61 63 68 20 53 51 4c 20 69 6e 64 65 78 20 Each SQL index
14040 69 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 is represented i
14050 6e 20 6d 65 6d 6f 72 79 20 62 79 20 61 6e 0a 2a n memory by an.*
14060 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 * instance of th
14070 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
14080 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 cture..**.** The
14090 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 74 68 65 20 columns of the
140a0 74 61 62 6c 65 20 74 68 61 74 20 61 72 65 20 74 table that are t
140b0 6f 20 62 65 20 69 6e 64 65 78 65 64 20 61 72 65 o be indexed are
140c0 20 64 65 73 63 72 69 62 65 64 0a 2a 2a 20 62 79 described.** by
140d0 20 74 68 65 20 61 69 43 6f 6c 75 6d 6e 5b 5d 20 the aiColumn[]
140e0 66 69 65 6c 64 20 6f 66 20 74 68 69 73 20 73 74 field of this st
140f0 72 75 63 74 75 72 65 2e 20 20 46 6f 72 20 65 78 ructure. For ex
14100 61 6d 70 6c 65 2c 20 73 75 70 70 6f 73 65 0a 2a ample, suppose.*
14110 2a 20 77 65 20 68 61 76 65 20 74 68 65 20 66 6f * we have the fo
14120 6c 6c 6f 77 69 6e 67 20 74 61 62 6c 65 20 61 6e llowing table an
14130 64 20 69 6e 64 65 78 3a 0a 2a 2a 0a 2a 2a 20 20 d index:.**.**
14140 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 CREATE TABLE
14150 45 78 31 28 63 31 20 69 6e 74 2c 20 63 32 20 69 Ex1(c1 int, c2 i
14160 6e 74 2c 20 63 33 20 74 65 78 74 29 3b 0a 2a 2a nt, c3 text);.**
14170 20 20 20 20 20 43 52 45 41 54 45 20 49 4e 44 45 CREATE INDE
14180 58 20 45 78 32 20 4f 4e 20 45 78 31 28 63 33 2c X Ex2 ON Ex1(c3,
14190 63 31 29 3b 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 c1);.**.** In th
141a0 65 20 54 61 62 6c 65 20 73 74 72 75 63 74 75 72 e Table structur
141b0 65 20 64 65 73 63 72 69 62 69 6e 67 20 45 78 31 e describing Ex1
141c0 2c 20 6e 43 6f 6c 3d 3d 33 20 62 65 63 61 75 73 , nCol==3 becaus
141d0 65 20 74 68 65 72 65 20 61 72 65 0a 2a 2a 20 74 e there are.** t
141e0 68 72 65 65 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 hree columns in
141f0 74 68 65 20 74 61 62 6c 65 2e 20 20 49 6e 20 74 the table. In t
14200 68 65 20 49 6e 64 65 78 20 73 74 72 75 63 74 75 he Index structu
14210 72 65 20 64 65 73 63 72 69 62 69 6e 67 0a 2a 2a re describing.**
14220 20 45 78 32 2c 20 6e 43 6f 6c 75 6d 6e 3d 3d 32 Ex2, nColumn==2
14230 20 73 69 6e 63 65 20 32 20 6f 66 20 74 68 65 20 since 2 of the
14240 33 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 45 78 31 3 columns of Ex1
14250 20 61 72 65 20 69 6e 64 65 78 65 64 2e 0a 2a 2a are indexed..**
14260 20 54 68 65 20 76 61 6c 75 65 20 6f 66 20 61 69 The value of ai
14270 43 6f 6c 75 6d 6e 20 69 73 20 7b 32 2c 20 30 7d Column is {2, 0}
14280 2e 20 20 61 69 43 6f 6c 75 6d 6e 5b 30 5d 3d 3d . aiColumn[0]==
14290 32 20 62 65 63 61 75 73 65 20 74 68 65 0a 2a 2a 2 because the.**
142a0 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 74 6f first column to
142b0 20 62 65 20 69 6e 64 65 78 65 64 20 28 63 33 29 be indexed (c3)
142c0 20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 has an index of
142d0 20 32 20 69 6e 20 45 78 31 2e 61 43 6f 6c 5b 5d 2 in Ex1.aCol[]
142e0 2e 0a 2a 2a 20 54 68 65 20 73 65 63 6f 6e 64 20 ..** The second
142f0 63 6f 6c 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 column to be ind
14300 65 78 65 64 20 28 63 31 29 20 68 61 73 20 61 6e exed (c1) has an
14310 20 69 6e 64 65 78 20 6f 66 20 30 20 69 6e 0a 2a index of 0 in.*
14320 2a 20 45 78 31 2e 61 43 6f 6c 5b 5d 2c 20 68 65 * Ex1.aCol[], he
14330 6e 63 65 20 45 78 32 2e 61 69 43 6f 6c 75 6d 6e nce Ex2.aiColumn
14340 5b 31 5d 3d 3d 30 2e 0a 2a 2a 0a 2a 2a 20 54 68 [1]==0..**.** Th
14350 65 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 e Index.onError
14360 66 69 65 6c 64 20 64 65 74 65 72 6d 69 6e 65 73 field determines
14370 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 whether or not
14380 74 68 65 20 69 6e 64 65 78 65 64 20 63 6f 6c 75 the indexed colu
14390 6d 6e 73 0a 2a 2a 20 6d 75 73 74 20 62 65 20 75 mns.** must be u
143a0 6e 69 71 75 65 20 61 6e 64 20 77 68 61 74 20 74 nique and what t
143b0 6f 20 64 6f 20 69 66 20 74 68 65 79 20 61 72 65 o do if they are
143c0 20 6e 6f 74 2e 20 20 57 68 65 6e 20 49 6e 64 65 not. When Inde
143d0 78 2e 6f 6e 45 72 72 6f 72 3d 4f 45 5f 4e 6f 6e x.onError=OE_Non
143e0 65 2c 0a 2a 2a 20 69 74 20 6d 65 61 6e 73 20 74 e,.** it means t
143f0 68 69 73 20 69 73 20 6e 6f 74 20 61 20 75 6e 69 his is not a uni
14400 71 75 65 20 69 6e 64 65 78 2e 20 20 4f 74 68 65 que index. Othe
14410 72 77 69 73 65 20 69 74 20 69 73 20 61 20 75 6e rwise it is a un
14420 69 71 75 65 20 69 6e 64 65 78 0a 2a 2a 20 61 6e ique index.** an
14430 64 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 49 d the value of I
14440 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 69 6e 64 ndex.onError ind
14450 69 63 61 74 65 20 74 68 65 20 77 68 69 63 68 20 icate the which
14460 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f 6c 75 74 conflict resolut
14470 69 6f 6e 0a 2a 2a 20 61 6c 67 6f 72 69 74 68 6d ion.** algorithm
14480 20 74 6f 20 65 6d 70 6c 6f 79 20 77 68 65 6e 65 to employ whene
14490 76 65 72 20 61 6e 20 61 74 74 65 6d 70 74 20 69 ver an attempt i
144a0 73 20 6d 61 64 65 20 74 6f 20 69 6e 73 65 72 74 s made to insert
144b0 20 61 20 6e 6f 6e 2d 75 6e 69 71 75 65 0a 2a 2a a non-unique.**
144c0 20 65 6c 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 element..**.**
144d0 57 68 69 6c 65 20 70 61 72 73 69 6e 67 20 61 20 While parsing a
144e0 43 52 45 41 54 45 20 54 41 42 4c 45 20 6f 72 20 CREATE TABLE or
144f0 43 52 45 41 54 45 20 49 4e 44 45 58 20 73 74 61 CREATE INDEX sta
14500 74 65 6d 65 6e 74 20 69 6e 20 6f 72 64 65 72 20 tement in order
14510 74 6f 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 56 to.** generate V
14520 44 42 45 20 63 6f 64 65 20 28 61 73 20 6f 70 70 DBE code (as opp
14530 6f 73 65 64 20 74 6f 20 70 61 72 73 69 6e 67 20 osed to parsing
14540 6f 6e 65 20 72 65 61 64 20 66 72 6f 6d 20 61 6e one read from an
14550 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 0a 2a sqlite_master.*
14560 2a 20 74 61 62 6c 65 20 61 73 20 70 61 72 74 20 * table as part
14570 6f 66 20 70 61 72 73 69 6e 67 20 61 6e 20 65 78 of parsing an ex
14580 69 73 74 69 6e 67 20 64 61 74 61 62 61 73 65 20 isting database
14590 73 63 68 65 6d 61 29 2c 20 74 72 61 6e 73 69 65 schema), transie
145a0 6e 74 20 69 6e 73 74 61 6e 63 65 73 0a 2a 2a 20 nt instances.**
145b0 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 of this structur
145c0 65 20 6d 61 79 20 62 65 20 63 72 65 61 74 65 64 e may be created
145d0 2e 20 49 6e 20 74 68 69 73 20 63 61 73 65 20 74 . In this case t
145e0 68 65 20 49 6e 64 65 78 2e 74 6e 75 6d 20 76 61 he Index.tnum va
145f0 72 69 61 62 6c 65 20 69 73 0a 2a 2a 20 75 73 65 riable is.** use
14600 64 20 74 6f 20 73 74 6f 72 65 20 74 68 65 20 61 d to store the a
14610 64 64 72 65 73 73 20 6f 66 20 61 20 56 44 42 45 ddress of a VDBE
14620 20 69 6e 73 74 72 75 63 74 69 6f 6e 2c 20 6e 6f instruction, no
14630 74 20 61 20 64 61 74 61 62 61 73 65 20 70 61 67 t a database pag
14640 65 0a 2a 2a 20 6e 75 6d 62 65 72 20 28 69 74 20 e.** number (it
14650 63 61 6e 6e 6f 74 20 2d 20 74 68 65 20 64 61 74 cannot - the dat
14660 61 62 61 73 65 20 70 61 67 65 20 69 73 20 6e 6f abase page is no
14670 74 20 61 6c 6c 6f 63 61 74 65 64 20 75 6e 74 69 t allocated unti
14680 6c 20 74 68 65 20 56 44 42 45 0a 2a 2a 20 70 72 l the VDBE.** pr
14690 6f 67 72 61 6d 20 69 73 20 65 78 65 63 75 74 65 ogram is execute
146a0 64 29 2e 20 53 65 65 20 63 6f 6e 76 65 72 74 54 d). See convertT
146b0 6f 57 69 74 68 6f 75 74 52 6f 77 69 64 54 61 62 oWithoutRowidTab
146c0 6c 65 28 29 20 66 6f 72 20 64 65 74 61 69 6c 73 le() for details
146d0 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 ..*/.struct Inde
146e0 78 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d x {. char *zNam
146f0 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f e; /
14700 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 20 69 * Name of this i
14710 6e 64 65 78 20 2a 2f 0a 20 20 69 31 36 20 2a 61 ndex */. i16 *a
14720 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 iColumn;
14730 20 20 20 2f 2a 20 57 68 69 63 68 20 63 6f 6c 75 /* Which colu
14740 6d 6e 73 20 61 72 65 20 75 73 65 64 20 62 79 20 mns are used by
14750 74 68 69 73 20 69 6e 64 65 78 2e 20 20 31 73 74 this index. 1st
14760 20 69 73 20 30 20 2a 2f 0a 20 20 4c 6f 67 45 73 is 0 */. LogEs
14770 74 20 2a 61 69 52 6f 77 4c 6f 67 45 73 74 3b 20 t *aiRowLogEst;
14780 20 20 20 20 2f 2a 20 46 72 6f 6d 20 41 4e 41 4c /* From ANAL
14790 59 5a 45 3a 20 45 73 74 2e 20 72 6f 77 73 20 73 YZE: Est. rows s
147a0 65 6c 65 63 74 65 64 20 62 79 20 65 61 63 68 20 elected by each
147b0 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 54 61 62 6c column */. Tabl
147c0 65 20 2a 70 54 61 62 6c 65 3b 20 20 20 20 20 20 e *pTable;
147d0 20 20 20 20 20 2f 2a 20 54 68 65 20 53 51 4c 20 /* The SQL
147e0 74 61 62 6c 65 20 62 65 69 6e 67 20 69 6e 64 65 table being inde
147f0 78 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a xed */. char *z
14800 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 20 20 20 ColAff;
14810 20 20 2f 2a 20 53 74 72 69 6e 67 20 64 65 66 69 /* String defi
14820 6e 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 ning the affinit
14830 79 20 6f 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e y of each column
14840 20 2a 2f 0a 20 20 49 6e 64 65 78 20 2a 70 4e 65 */. Index *pNe
14850 78 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f xt; /
14860 2a 20 54 68 65 20 6e 65 78 74 20 69 6e 64 65 78 * The next index
14870 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
14880 20 74 68 65 20 73 61 6d 65 20 74 61 62 6c 65 20 the same table
14890 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 */. Schema *pSc
148a0 68 65 6d 61 3b 20 20 20 20 20 20 20 20 20 2f 2a hema; /*
148b0 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 6e 69 Schema containi
148c0 6e 67 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f ng this index */
148d0 0a 20 20 75 38 20 2a 61 53 6f 72 74 4f 72 64 65 . u8 *aSortOrde
148e0 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 66 r; /* f
148f0 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 3a 20 or each column:
14900 54 72 75 65 3d 3d 44 45 53 43 2c 20 46 61 6c 73 True==DESC, Fals
14910 65 3d 3d 41 53 43 20 2a 2f 0a 20 20 63 6f 6e 73 e==ASC */. cons
14920 74 20 63 68 61 72 20 2a 2a 61 7a 43 6f 6c 6c 3b t char **azColl;
14930 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 6f 66 /* Array of
14940 20 63 6f 6c 6c 61 74 69 6f 6e 20 73 65 71 75 65 collation seque
14950 6e 63 65 20 6e 61 6d 65 73 20 66 6f 72 20 69 6e nce names for in
14960 64 65 78 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 dex */. Expr *p
14970 50 61 72 74 49 64 78 57 68 65 72 65 3b 20 20 20 PartIdxWhere;
14980 20 20 2f 2a 20 57 48 45 52 45 20 63 6c 61 75 73 /* WHERE claus
14990 65 20 66 6f 72 20 70 61 72 74 69 61 6c 20 69 6e e for partial in
149a0 64 69 63 65 73 20 2a 2f 0a 20 20 45 78 70 72 4c dices */. ExprL
149b0 69 73 74 20 2a 61 43 6f 6c 45 78 70 72 3b 20 20 ist *aColExpr;
149c0 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 65 78 /* Column ex
149d0 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 69 pressions */. i
149e0 6e 74 20 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 nt tnum;
149f0 20 20 20 20 20 20 20 20 2f 2a 20 44 42 20 50 61 /* DB Pa
14a00 67 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 72 6f ge containing ro
14a10 6f 74 20 6f 66 20 74 68 69 73 20 69 6e 64 65 78 ot of this index
14a20 20 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 73 7a 49 */. LogEst szI
14a30 64 78 52 6f 77 3b 20 20 20 20 20 20 20 20 20 2f dxRow; /
14a40 2a 20 45 73 74 69 6d 61 74 65 64 20 61 76 65 72 * Estimated aver
14a50 61 67 65 20 72 6f 77 20 73 69 7a 65 20 69 6e 20 age row size in
14a60 62 79 74 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e bytes */. u16 n
14a70 4b 65 79 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 KeyCol;
14a80 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
14a90 20 63 6f 6c 75 6d 6e 73 20 66 6f 72 6d 69 6e 67 columns forming
14aa0 20 74 68 65 20 6b 65 79 20 2a 2f 0a 20 20 75 31 the key */. u1
14ab0 36 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 6 nColumn;
14ac0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
14ad0 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 73 74 6f 72 of columns stor
14ae0 65 64 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 ed in the index
14af0 2a 2f 0a 20 20 75 38 20 6f 6e 45 72 72 6f 72 3b */. u8 onError;
14b00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
14b10 20 4f 45 5f 41 62 6f 72 74 2c 20 4f 45 5f 49 67 OE_Abort, OE_Ig
14b20 6e 6f 72 65 2c 20 4f 45 5f 52 65 70 6c 61 63 65 nore, OE_Replace
14b30 2c 20 6f 72 20 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a , or OE_None */.
14b40 20 20 75 6e 73 69 67 6e 65 64 20 69 64 78 54 79 unsigned idxTy
14b50 70 65 3a 32 3b 20 20 20 20 20 20 2f 2a 20 31 3d pe:2; /* 1=
14b60 3d 55 4e 49 51 55 45 2c 20 32 3d 3d 50 52 49 4d =UNIQUE, 2==PRIM
14b70 41 52 59 20 4b 45 59 2c 20 30 3d 3d 43 52 45 41 ARY KEY, 0==CREA
14b80 54 45 20 49 4e 44 45 58 20 2a 2f 0a 20 20 75 6e TE INDEX */. un
14b90 73 69 67 6e 65 64 20 62 55 6e 6f 72 64 65 72 65 signed bUnordere
14ba0 64 3a 31 3b 20 20 20 2f 2a 20 55 73 65 20 74 68 d:1; /* Use th
14bb0 69 73 20 69 6e 64 65 78 20 66 6f 72 20 3d 3d 20 is index for ==
14bc0 6f 72 20 49 4e 20 71 75 65 72 69 65 73 20 6f 6e or IN queries on
14bd0 6c 79 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 ly */. unsigned
14be0 20 75 6e 69 71 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 uniqNotNull:1;
14bf0 20 2f 2a 20 54 72 75 65 20 69 66 20 55 4e 49 51 /* True if UNIQ
14c00 55 45 20 61 6e 64 20 4e 4f 54 20 4e 55 4c 4c 20 UE and NOT NULL
14c10 66 6f 72 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 for all columns
14c20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 73 */. unsigned is
14c30 52 65 73 69 7a 65 64 3a 31 3b 20 20 20 20 2f 2a Resized:1; /*
14c40 20 54 72 75 65 20 69 66 20 72 65 73 69 7a 65 49 True if resizeI
14c50 6e 64 65 78 4f 62 6a 65 63 74 28 29 20 68 61 73 ndexObject() has
14c60 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a been called */.
14c70 20 20 75 6e 73 69 67 6e 65 64 20 69 73 43 6f 76 unsigned isCov
14c80 65 72 69 6e 67 3a 31 3b 20 20 20 2f 2a 20 54 72 ering:1; /* Tr
14c90 75 65 20 69 66 20 74 68 69 73 20 69 73 20 61 20 ue if this is a
14ca0 63 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 2a covering index *
14cb0 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 6e 6f 53 /. unsigned noS
14cc0 6b 69 70 53 63 61 6e 3a 31 3b 20 20 20 2f 2a 20 kipScan:1; /*
14cd0 44 6f 20 6e 6f 74 20 74 72 79 20 74 6f 20 75 73 Do not try to us
14ce0 65 20 73 6b 69 70 2d 73 63 61 6e 20 69 66 20 74 e skip-scan if t
14cf0 72 75 65 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 rue */.#ifdef SQ
14d00 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
14d10 33 5f 4f 52 5f 53 54 41 54 34 0a 20 20 69 6e 74 3_OR_STAT4. int
14d20 20 6e 53 61 6d 70 6c 65 3b 20 20 20 20 20 20 20 nSample;
14d30 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
14d40 6f 66 20 65 6c 65 6d 65 6e 74 73 20 69 6e 20 61 of elements in a
14d50 53 61 6d 70 6c 65 5b 5d 20 2a 2f 0a 20 20 69 6e Sample[] */. in
14d60 74 20 6e 53 61 6d 70 6c 65 43 6f 6c 3b 20 20 20 t nSampleCol;
14d70 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f /* Size o
14d80 66 20 49 6e 64 65 78 53 61 6d 70 6c 65 2e 61 6e f IndexSample.an
14d90 45 71 5b 5d 20 61 6e 64 20 73 6f 20 6f 6e 20 2a Eq[] and so on *
14da0 2f 0a 20 20 74 52 6f 77 63 6e 74 20 2a 61 41 76 /. tRowcnt *aAv
14db0 67 45 71 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 gEq; /*
14dc0 41 76 65 72 61 67 65 20 6e 45 71 20 76 61 6c 75 Average nEq valu
14dd0 65 73 20 66 6f 72 20 6b 65 79 73 20 6e 6f 74 20 es for keys not
14de0 69 6e 20 61 53 61 6d 70 6c 65 20 2a 2f 0a 20 20 in aSample */.
14df0 49 6e 64 65 78 53 61 6d 70 6c 65 20 2a 61 53 61 IndexSample *aSa
14e00 6d 70 6c 65 3b 20 20 20 20 2f 2a 20 53 61 6d 70 mple; /* Samp
14e10 6c 65 73 20 6f 66 20 74 68 65 20 6c 65 66 74 2d les of the left-
14e20 6d 6f 73 74 20 6b 65 79 20 2a 2f 0a 20 20 74 52 most key */. tR
14e30 6f 77 63 6e 74 20 2a 61 69 52 6f 77 45 73 74 3b owcnt *aiRowEst;
14e40 20 20 20 20 20 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f /* Non-lo
14e50 67 61 72 69 74 68 6d 69 63 20 73 74 61 74 31 20 garithmic stat1
14e60 64 61 74 61 20 66 6f 72 20 74 68 69 73 20 69 6e data for this in
14e70 64 65 78 20 2a 2f 0a 20 20 74 52 6f 77 63 6e 74 dex */. tRowcnt
14e80 20 6e 52 6f 77 45 73 74 30 3b 20 20 20 20 20 20 nRowEst0;
14e90 20 20 2f 2a 20 4e 6f 6e 2d 6c 6f 67 61 72 69 74 /* Non-logarit
14ea0 68 6d 69 63 20 6e 75 6d 62 65 72 20 6f 66 20 72 hmic number of r
14eb0 6f 77 73 20 69 6e 20 74 68 65 20 69 6e 64 65 78 ows in the index
14ec0 20 2a 2f 0a 23 65 6e 64 69 66 0a 7d 3b 0a 0a 2f */.#endif.};../
14ed0 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c *.** Allowed val
14ee0 75 65 73 20 66 6f 72 20 49 6e 64 65 78 2e 69 64 ues for Index.id
14ef0 78 54 79 70 65 0a 2a 2f 0a 23 64 65 66 69 6e 65 xType.*/.#define
14f00 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f SQLITE_IDXTYPE_
14f10 41 50 50 44 45 46 20 20 20 20 20 20 30 20 20 20 APPDEF 0
14f20 2f 2a 20 43 72 65 61 74 65 64 20 75 73 69 6e 67 /* Created using
14f30 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 2a 2f CREATE INDEX */
14f40 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
14f50 49 44 58 54 59 50 45 5f 55 4e 49 51 55 45 20 20 IDXTYPE_UNIQUE
14f60 20 20 20 20 31 20 20 20 2f 2a 20 49 6d 70 6c 65 1 /* Imple
14f70 6d 65 6e 74 73 20 61 20 55 4e 49 51 55 45 20 63 ments a UNIQUE c
14f80 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 64 65 onstraint */.#de
14f90 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 fine SQLITE_IDXT
14fa0 59 50 45 5f 50 52 49 4d 41 52 59 4b 45 59 20 20 YPE_PRIMARYKEY
14fb0 32 20 20 20 2f 2a 20 49 73 20 74 68 65 20 50 52 2 /* Is the PR
14fc0 49 4d 41 52 59 20 4b 45 59 20 66 6f 72 20 74 68 IMARY KEY for th
14fd0 65 20 74 61 62 6c 65 20 2a 2f 0a 0a 2f 2a 20 52 e table */../* R
14fe0 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 6e eturn true if in
14ff0 64 65 78 20 58 20 69 73 20 61 20 50 52 49 4d 41 dex X is a PRIMA
15000 52 59 20 4b 45 59 20 69 6e 64 65 78 20 2a 2f 0a RY KEY index */.
15010 23 64 65 66 69 6e 65 20 49 73 50 72 69 6d 61 72 #define IsPrimar
15020 79 4b 65 79 49 6e 64 65 78 28 58 29 20 20 28 28 yKeyIndex(X) ((
15030 58 29 2d 3e 69 64 78 54 79 70 65 3d 3d 53 51 4c X)->idxType==SQL
15040 49 54 45 5f 49 44 58 54 59 50 45 5f 50 52 49 4d ITE_IDXTYPE_PRIM
15050 41 52 59 4b 45 59 29 0a 0a 2f 2a 20 52 65 74 75 ARYKEY)../* Retu
15060 72 6e 20 74 72 75 65 20 69 66 20 69 6e 64 65 78 rn true if index
15070 20 58 20 69 73 20 61 20 55 4e 49 51 55 45 20 69 X is a UNIQUE i
15080 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ndex */.#define
15090 49 73 55 6e 69 71 75 65 49 6e 64 65 78 28 58 29 IsUniqueIndex(X)
150a0 20 20 20 20 20 20 28 28 58 29 2d 3e 6f 6e 45 72 ((X)->onEr
150b0 72 6f 72 21 3d 4f 45 5f 4e 6f 6e 65 29 0a 0a 2f ror!=OE_None)../
150c0 2a 20 54 68 65 20 49 6e 64 65 78 2e 61 69 43 6f * The Index.aiCo
150d0 6c 75 6d 6e 5b 5d 20 76 61 6c 75 65 73 20 61 72 lumn[] values ar
150e0 65 20 6e 6f 72 6d 61 6c 6c 79 20 70 6f 73 69 74 e normally posit
150f0 69 76 65 20 69 6e 74 65 67 65 72 2e 20 20 42 75 ive integer. Bu
15100 74 0a 2a 2a 20 74 68 65 72 65 20 61 72 65 20 73 t.** there are s
15110 6f 6d 65 20 6e 65 67 61 74 69 76 65 20 76 61 6c ome negative val
15120 75 65 73 20 74 68 61 74 20 68 61 76 65 20 73 70 ues that have sp
15130 65 63 69 61 6c 20 6d 65 61 6e 69 6e 67 3a 0a 2a ecial meaning:.*
15140 2f 0a 23 64 65 66 69 6e 65 20 58 4e 5f 52 4f 57 /.#define XN_ROW
15150 49 44 20 20 20 20 20 28 2d 31 29 20 20 20 20 20 ID (-1)
15160 2f 2a 20 49 6e 64 65 78 65 64 20 63 6f 6c 75 6d /* Indexed colum
15170 6e 20 69 73 20 74 68 65 20 72 6f 77 69 64 20 2a n is the rowid *
15180 2f 0a 23 64 65 66 69 6e 65 20 58 4e 5f 45 58 50 /.#define XN_EXP
15190 52 20 20 20 20 20 20 28 2d 32 29 20 20 20 20 20 R (-2)
151a0 2f 2a 20 49 6e 64 65 78 65 64 20 63 6f 6c 75 6d /* Indexed colum
151b0 6e 20 69 73 20 61 6e 20 65 78 70 72 65 73 73 69 n is an expressi
151c0 6f 6e 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 on */../*.** Eac
151d0 68 20 73 61 6d 70 6c 65 20 73 74 6f 72 65 64 20 h sample stored
151e0 69 6e 20 74 68 65 20 73 71 6c 69 74 65 5f 73 74 in the sqlite_st
151f0 61 74 33 20 74 61 62 6c 65 20 69 73 20 72 65 70 at3 table is rep
15200 72 65 73 65 6e 74 65 64 20 69 6e 20 6d 65 6d 6f resented in memo
15210 72 79 0a 2a 2a 20 75 73 69 6e 67 20 61 20 73 74 ry.** using a st
15220 72 75 63 74 75 72 65 20 6f 66 20 74 68 69 73 20 ructure of this
15230 74 79 70 65 2e 20 20 53 65 65 20 64 6f 63 75 6d type. See docum
15240 65 6e 74 61 74 69 6f 6e 20 61 74 20 74 68 65 20 entation at the
15250 74 6f 70 20 6f 66 20 74 68 65 0a 2a 2a 20 61 6e top of the.** an
15260 61 6c 79 7a 65 2e 63 20 73 6f 75 72 63 65 20 66 alyze.c source f
15270 69 6c 65 20 66 6f 72 20 61 64 64 69 74 69 6f 6e ile for addition
15280 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a al information..
15290 2a 2f 0a 73 74 72 75 63 74 20 49 6e 64 65 78 53 */.struct IndexS
152a0 61 6d 70 6c 65 20 7b 0a 20 20 76 6f 69 64 20 2a ample {. void *
152b0 70 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 p; /* P
152c0 6f 69 6e 74 65 72 20 74 6f 20 73 61 6d 70 6c 65 ointer to sample
152d0 64 20 72 65 63 6f 72 64 20 2a 2f 0a 20 20 69 6e d record */. in
152e0 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 t n;
152f0 2f 2a 20 53 69 7a 65 20 6f 66 20 72 65 63 6f 72 /* Size of recor
15300 64 20 69 6e 20 62 79 74 65 73 20 2a 2f 0a 20 20 d in bytes */.
15310 74 52 6f 77 63 6e 74 20 2a 61 6e 45 71 3b 20 20 tRowcnt *anEq;
15320 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 /* Est. number
15330 20 6f 66 20 72 6f 77 73 20 77 68 65 72 65 20 74 of rows where t
15340 68 65 20 6b 65 79 20 65 71 75 61 6c 73 20 74 68 he key equals th
15350 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 20 74 is sample */. t
15360 52 6f 77 63 6e 74 20 2a 61 6e 4c 74 3b 20 20 20 Rowcnt *anLt;
15370 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 20 /* Est. number
15380 6f 66 20 72 6f 77 73 20 77 68 65 72 65 20 6b 65 of rows where ke
15390 79 20 69 73 20 6c 65 73 73 20 74 68 61 6e 20 74 y is less than t
153a0 68 69 73 20 73 61 6d 70 6c 65 20 2a 2f 0a 20 20 his sample */.
153b0 74 52 6f 77 63 6e 74 20 2a 61 6e 44 4c 74 3b 20 tRowcnt *anDLt;
153c0 20 20 2f 2a 20 45 73 74 2e 20 6e 75 6d 62 65 72 /* Est. number
153d0 20 6f 66 20 64 69 73 74 69 6e 63 74 20 6b 65 79 of distinct key
153e0 73 20 6c 65 73 73 20 74 68 61 6e 20 74 68 69 73 s less than this
153f0 20 73 61 6d 70 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f sample */.};../
15400 2a 0a 2a 2a 20 45 61 63 68 20 74 6f 6b 65 6e 20 *.** Each token
15410 63 6f 6d 69 6e 67 20 6f 75 74 20 6f 66 20 74 68 coming out of th
15420 65 20 6c 65 78 65 72 20 69 73 20 61 6e 20 69 6e e lexer is an in
15430 73 74 61 6e 63 65 20 6f 66 0a 2a 2a 20 74 68 69 stance of.** thi
15440 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 54 6f s structure. To
15450 6b 65 6e 73 20 61 72 65 20 61 6c 73 6f 20 75 73 kens are also us
15460 65 64 20 61 73 20 70 61 72 74 20 6f 66 20 61 6e ed as part of an
15470 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a 2a 0a expression..**.
15480 2a 2a 20 4e 6f 74 65 20 69 66 20 54 6f 6b 65 6e ** Note if Token
15490 2e 7a 3d 3d 30 20 74 68 65 6e 20 54 6f 6b 65 6e .z==0 then Token
154a0 2e 64 79 6e 20 61 6e 64 20 54 6f 6b 65 6e 2e 6e .dyn and Token.n
154b0 20 61 72 65 20 75 6e 64 65 66 69 6e 65 64 20 61 are undefined a
154c0 6e 64 0a 2a 2a 20 6d 61 79 20 63 6f 6e 74 61 69 nd.** may contai
154d0 6e 20 72 61 6e 64 6f 6d 20 76 61 6c 75 65 73 2e n random values.
154e0 20 20 44 6f 20 6e 6f 74 20 6d 61 6b 65 20 61 6e Do not make an
154f0 79 20 61 73 73 75 6d 70 74 69 6f 6e 73 20 61 62 y assumptions ab
15500 6f 75 74 20 54 6f 6b 65 6e 2e 64 79 6e 0a 2a 2a out Token.dyn.**
15510 20 61 6e 64 20 54 6f 6b 65 6e 2e 6e 20 77 68 65 and Token.n whe
15520 6e 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 2e 0a 2a 2f n Token.z==0..*/
15530 0a 73 74 72 75 63 74 20 54 6f 6b 65 6e 20 7b 0a .struct Token {.
15540 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 3b const char *z;
15550 20 20 20 20 20 2f 2a 20 54 65 78 74 20 6f 66 20 /* Text of
15560 74 68 65 20 74 6f 6b 65 6e 2e 20 20 4e 6f 74 20 the token. Not
15570 4e 55 4c 4c 2d 74 65 72 6d 69 6e 61 74 65 64 21 NULL-terminated!
15580 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 */. unsigned i
15590 6e 74 20 6e 3b 20 20 20 20 2f 2a 20 4e 75 6d 62 nt n; /* Numb
155a0 65 72 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 er of characters
155b0 20 69 6e 20 74 68 69 73 20 74 6f 6b 65 6e 20 2a in this token *
155c0 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 /.};../*.** An i
155d0 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 nstance of this
155e0 73 74 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 structure contai
155f0 6e 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e ns information n
15600 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 61 74 eeded to generat
15610 65 0a 2a 2a 20 63 6f 64 65 20 66 6f 72 20 61 20 e.** code for a
15620 53 45 4c 45 43 54 20 74 68 61 74 20 63 6f 6e 74 SELECT that cont
15630 61 69 6e 73 20 61 67 67 72 65 67 61 74 65 20 66 ains aggregate f
15640 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 unctions..**.**
15650 49 66 20 45 78 70 72 2e 6f 70 3d 3d 54 4b 5f 41 If Expr.op==TK_A
15660 47 47 5f 43 4f 4c 55 4d 4e 20 6f 72 20 54 4b 5f GG_COLUMN or TK_
15670 41 47 47 5f 46 55 4e 43 54 49 4f 4e 20 74 68 65 AGG_FUNCTION the
15680 6e 20 45 78 70 72 2e 70 41 67 67 49 6e 66 6f 20 n Expr.pAggInfo
15690 69 73 20 61 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 is a.** pointer
156a0 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 72 to this structur
156b0 65 2e 20 20 54 68 65 20 45 78 70 72 2e 69 43 6f e. The Expr.iCo
156c0 6c 75 6d 6e 20 66 69 65 6c 64 20 69 73 20 74 68 lumn field is th
156d0 65 20 69 6e 64 65 78 20 69 6e 0a 2a 2a 20 41 67 e index in.** Ag
156e0 67 49 6e 66 6f 2e 61 43 6f 6c 5b 5d 20 6f 72 20 gInfo.aCol[] or
156f0 41 67 67 49 6e 66 6f 2e 61 46 75 6e 63 5b 5d 20 AggInfo.aFunc[]
15700 6f 66 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6e of information n
15710 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 61 74 eeded to generat
15720 65 0a 2a 2a 20 63 6f 64 65 20 66 6f 72 20 74 68 e.** code for th
15730 61 74 20 6e 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 at node..**.** A
15740 67 67 49 6e 66 6f 2e 70 47 72 6f 75 70 42 79 20 ggInfo.pGroupBy
15750 61 6e 64 20 41 67 67 49 6e 66 6f 2e 61 46 75 6e and AggInfo.aFun
15760 63 2e 70 45 78 70 72 20 70 6f 69 6e 74 20 74 6f c.pExpr point to
15770 20 66 69 65 6c 64 73 20 77 69 74 68 69 6e 20 74 fields within t
15780 68 65 0a 2a 2a 20 6f 72 69 67 69 6e 61 6c 20 53 he.** original S
15790 65 6c 65 63 74 20 73 74 72 75 63 74 75 72 65 20 elect structure
157a0 74 68 61 74 20 64 65 73 63 72 69 62 65 73 20 74 that describes t
157b0 68 65 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d he SELECT statem
157c0 65 6e 74 2e 20 20 54 68 65 73 65 0a 2a 2a 20 66 ent. These.** f
157d0 69 65 6c 64 73 20 64 6f 20 6e 6f 74 20 6e 65 65 ields do not nee
157e0 64 20 74 6f 20 62 65 20 66 72 65 65 64 20 77 68 d to be freed wh
157f0 65 6e 20 64 65 61 6c 6c 6f 63 61 74 69 6e 67 20 en deallocating
15800 74 68 65 20 41 67 67 49 6e 66 6f 20 73 74 72 75 the AggInfo stru
15810 63 74 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 cture..*/.struct
15820 20 41 67 67 49 6e 66 6f 20 7b 0a 20 20 75 38 20 AggInfo {. u8
15830 64 69 72 65 63 74 4d 6f 64 65 3b 20 20 20 20 20 directMode;
15840 20 20 20 20 20 2f 2a 20 44 69 72 65 63 74 20 72 /* Direct r
15850 65 6e 64 65 72 69 6e 67 20 6d 6f 64 65 20 6d 65 endering mode me
15860 61 6e 73 20 74 61 6b 65 20 64 61 74 61 20 64 69 ans take data di
15870 72 65 63 74 6c 79 0a 20 20 20 20 20 20 20 20 20 rectly.
15880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15890 20 2a 2a 20 66 72 6f 6d 20 73 6f 75 72 63 65 20 ** from source
158a0 74 61 62 6c 65 73 20 72 61 74 68 65 72 20 74 68 tables rather th
158b0 61 6e 20 66 72 6f 6d 20 61 63 63 75 6d 75 6c 61 an from accumula
158c0 74 6f 72 73 20 2a 2f 0a 20 20 75 38 20 75 73 65 tors */. u8 use
158d0 53 6f 72 74 69 6e 67 49 64 78 3b 20 20 20 20 20 SortingIdx;
158e0 20 20 2f 2a 20 49 6e 20 64 69 72 65 63 74 20 6d /* In direct m
158f0 6f 64 65 2c 20 72 65 66 65 72 65 6e 63 65 20 74 ode, reference t
15900 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 he sorting index
15910 20 72 61 74 68 65 72 0a 20 20 20 20 20 20 20 20 rather.
15920 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15930 20 20 2a 2a 20 74 68 61 6e 20 74 68 65 20 73 6f ** than the so
15940 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 urce table */.
15950 69 6e 74 20 73 6f 72 74 69 6e 67 49 64 78 3b 20 int sortingIdx;
15960 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 73 6f /* Curso
15970 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 65 20 r number of the
15980 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f sorting index */
15990 0a 20 20 69 6e 74 20 73 6f 72 74 69 6e 67 49 64 . int sortingId
159a0 78 50 54 61 62 3b 20 20 20 20 20 2f 2a 20 43 75 xPTab; /* Cu
159b0 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 70 rsor number of p
159c0 73 65 75 64 6f 2d 74 61 62 6c 65 20 2a 2f 0a 20 seudo-table */.
159d0 20 69 6e 74 20 6e 53 6f 72 74 69 6e 67 43 6f 6c int nSortingCol
159e0 75 6d 6e 3b 20 20 20 20 20 2f 2a 20 4e 75 6d 62 umn; /* Numb
159f0 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
15a00 20 74 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 the sorting ind
15a10 65 78 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 ex */. int mnRe
15a20 67 2c 20 6d 78 52 65 67 3b 20 20 20 20 20 20 20 g, mxReg;
15a30 2f 2a 20 52 61 6e 67 65 20 6f 66 20 72 65 67 69 /* Range of regi
15a40 73 74 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 sters allocated
15a50 66 6f 72 20 61 43 6f 6c 20 61 6e 64 20 61 46 75 for aCol and aFu
15a60 6e 63 20 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 nc */. ExprList
15a70 20 2a 70 47 72 6f 75 70 42 79 3b 20 20 20 20 20 *pGroupBy;
15a80 2f 2a 20 54 68 65 20 67 72 6f 75 70 20 62 79 20 /* The group by
15a90 63 6c 61 75 73 65 20 2a 2f 0a 20 20 73 74 72 75 clause */. stru
15aa0 63 74 20 41 67 67 49 6e 66 6f 5f 63 6f 6c 20 7b ct AggInfo_col {
15ab0 20 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 /* For each
15ac0 63 6f 6c 75 6d 6e 20 75 73 65 64 20 69 6e 20 73 column used in s
15ad0 6f 75 72 63 65 20 74 61 62 6c 65 73 20 2a 2f 0a ource tables */.
15ae0 20 20 20 20 54 61 62 6c 65 20 2a 70 54 61 62 3b Table *pTab;
15af0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
15b00 53 6f 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a Source table */.
15b10 20 20 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 int iTable;
15b20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
15b30 43 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 Cursor number of
15b40 20 74 68 65 20 73 6f 75 72 63 65 20 74 61 62 6c the source tabl
15b50 65 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 43 6f e */. int iCo
15b60 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 20 lumn;
15b70 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e 75 6d 62 /* Column numb
15b80 65 72 20 77 69 74 68 69 6e 20 74 68 65 20 73 6f er within the so
15b90 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 urce table */.
15ba0 20 20 69 6e 74 20 69 53 6f 72 74 65 72 43 6f 6c int iSorterCol
15bb0 75 6d 6e 3b 20 20 20 20 20 20 20 2f 2a 20 43 6f umn; /* Co
15bc0 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 69 6e 20 74 lumn number in t
15bd0 68 65 20 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 he sorting index
15be0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4d 65 6d */. int iMem
15bf0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
15c00 20 2f 2a 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 /* Memory locat
15c10 69 6f 6e 20 74 68 61 74 20 61 63 74 73 20 61 73 ion that acts as
15c20 20 61 63 63 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a accumulator */.
15c30 20 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b Expr *pExpr;
15c40 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
15c50 54 68 65 20 6f 72 69 67 69 6e 61 6c 20 65 78 70 The original exp
15c60 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 20 7d 20 2a ression */. } *
15c70 61 43 6f 6c 3b 0a 20 20 69 6e 74 20 6e 43 6f 6c aCol;. int nCol
15c80 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 umn;
15c90 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 /* Number of use
15ca0 64 20 65 6e 74 72 69 65 73 20 69 6e 20 61 43 6f d entries in aCo
15cb0 6c 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 41 63 l[] */. int nAc
15cc0 63 75 6d 75 6c 61 74 6f 72 3b 20 20 20 20 20 20 cumulator;
15cd0 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f /* Number of co
15ce0 6c 75 6d 6e 73 20 74 68 61 74 20 73 68 6f 77 20 lumns that show
15cf0 74 68 72 6f 75 67 68 20 74 6f 20 74 68 65 20 6f through to the o
15d00 75 74 70 75 74 2e 0a 20 20 20 20 20 20 20 20 20 utput..
15d10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15d20 20 2a 2a 20 41 64 64 69 74 69 6f 6e 61 6c 20 63 ** Additional c
15d30 6f 6c 75 6d 6e 73 20 61 72 65 20 75 73 65 64 20 olumns are used
15d40 6f 6e 6c 79 20 61 73 20 70 61 72 61 6d 65 74 65 only as paramete
15d50 72 73 20 74 6f 0a 20 20 20 20 20 20 20 20 20 20 rs to.
15d60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15d70 2a 2a 20 61 67 67 72 65 67 61 74 65 20 66 75 6e ** aggregate fun
15d80 63 74 69 6f 6e 73 20 2a 2f 0a 20 20 73 74 72 75 ctions */. stru
15d90 63 74 20 41 67 67 49 6e 66 6f 5f 66 75 6e 63 20 ct AggInfo_func
15da0 7b 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 { /* For each
15db0 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 aggregate functi
15dc0 6f 6e 20 2a 2f 0a 20 20 20 20 45 78 70 72 20 2a on */. Expr *
15dd0 70 45 78 70 72 3b 20 20 20 20 20 20 20 20 20 20 pExpr;
15de0 20 20 20 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e /* Expression
15df0 20 65 6e 63 6f 64 69 6e 67 20 74 68 65 20 66 75 encoding the fu
15e00 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 46 75 nction */. Fu
15e10 6e 63 44 65 66 20 2a 70 46 75 6e 63 3b 20 20 20 ncDef *pFunc;
15e20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 61 67 /* The ag
15e30 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
15e40 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
15e50 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4d 65 6d 3b */. int iMem;
15e60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15e70 2f 2a 20 4d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 /* Memory locati
15e80 6f 6e 20 74 68 61 74 20 61 63 74 73 20 61 73 20 on that acts as
15e90 61 63 63 75 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 accumulator */.
15ea0 20 20 20 69 6e 74 20 69 44 69 73 74 69 6e 63 74 int iDistinct
15eb0 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 45 ; /* E
15ec0 70 68 65 6d 65 72 61 6c 20 74 61 62 6c 65 20 75 phemeral table u
15ed0 73 65 64 20 74 6f 20 65 6e 66 6f 72 63 65 20 44 sed to enforce D
15ee0 49 53 54 49 4e 43 54 20 2a 2f 0a 20 20 7d 20 2a ISTINCT */. } *
15ef0 61 46 75 6e 63 3b 0a 20 20 69 6e 74 20 6e 46 75 aFunc;. int nFu
15f00 6e 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nc;
15f10 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6e /* Number of en
15f20 74 72 69 65 73 20 69 6e 20 61 46 75 6e 63 5b 5d tries in aFunc[]
15f30 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 */.};../*.** Th
15f40 65 20 64 61 74 61 74 79 70 65 20 79 6e 56 61 72 e datatype ynVar
15f50 20 69 73 20 61 20 73 69 67 6e 65 64 20 69 6e 74 is a signed int
15f60 65 67 65 72 2c 20 65 69 74 68 65 72 20 31 36 2d eger, either 16-
15f70 62 69 74 20 6f 72 20 33 32 2d 62 69 74 2e 0a 2a bit or 32-bit..*
15f80 2a 20 55 73 75 61 6c 6c 79 20 69 74 20 69 73 20 * Usually it is
15f90 31 36 2d 62 69 74 73 2e 20 20 42 75 74 20 69 66 16-bits. But if
15fa0 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 SQLITE_MAX_VARI
15fb0 41 42 4c 45 5f 4e 55 4d 42 45 52 20 69 73 20 67 ABLE_NUMBER is g
15fc0 72 65 61 74 65 72 0a 2a 2a 20 74 68 61 6e 20 33 reater.** than 3
15fd0 32 37 36 37 20 77 65 20 68 61 76 65 20 74 6f 20 2767 we have to
15fe0 6d 61 6b 65 20 69 74 20 33 32 2d 62 69 74 2e 20 make it 32-bit.
15ff0 20 31 36 2d 62 69 74 20 69 73 20 70 72 65 66 65 16-bit is prefe
16000 72 72 65 64 20 62 65 63 61 75 73 65 0a 2a 2a 20 rred because.**
16010 69 74 20 75 73 65 73 20 6c 65 73 73 20 6d 65 6d it uses less mem
16020 6f 72 79 20 69 6e 20 74 68 65 20 45 78 70 72 20 ory in the Expr
16030 6f 62 6a 65 63 74 2c 20 77 68 69 63 68 20 69 73 object, which is
16040 20 61 20 62 69 67 20 6d 65 6d 6f 72 79 20 75 73 a big memory us
16050 65 72 0a 2a 2a 20 69 6e 20 73 79 73 74 65 6d 73 er.** in systems
16060 20 77 69 74 68 20 6c 6f 74 73 20 6f 66 20 70 72 with lots of pr
16070 65 70 61 72 65 64 20 73 74 61 74 65 6d 65 6e 74 epared statement
16080 73 2e 20 20 41 6e 64 20 66 65 77 20 61 70 70 6c s. And few appl
16090 69 63 61 74 69 6f 6e 73 0a 2a 2a 20 6e 65 65 64 ications.** need
160a0 20 6d 6f 72 65 20 74 68 61 6e 20 61 62 6f 75 74 more than about
160b0 20 31 30 20 6f 72 20 32 30 20 76 61 72 69 61 62 10 or 20 variab
160c0 6c 65 73 2e 20 20 42 75 74 20 73 6f 6d 65 20 65 les. But some e
160d0 78 74 72 65 6d 65 20 75 73 65 72 73 20 77 61 6e xtreme users wan
160e0 74 0a 2a 2a 20 74 6f 20 68 61 76 65 20 70 72 65 t.** to have pre
160f0 70 61 72 65 64 20 73 74 61 74 65 6d 65 6e 74 73 pared statements
16100 20 77 69 74 68 20 6f 76 65 72 20 33 32 37 36 37 with over 32767
16110 20 76 61 72 69 61 62 6c 65 73 2c 20 61 6e 64 20 variables, and
16120 66 6f 72 20 74 68 65 6d 0a 2a 2a 20 74 68 65 20 for them.** the
16130 6f 70 74 69 6f 6e 20 69 73 20 61 76 61 69 6c 61 option is availa
16140 62 6c 65 20 28 61 74 20 63 6f 6d 70 69 6c 65 2d ble (at compile-
16150 74 69 6d 65 29 2e 0a 2a 2f 0a 23 69 66 20 53 51 time)..*/.#if SQ
16160 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c LITE_MAX_VARIABL
16170 45 5f 4e 55 4d 42 45 52 3c 3d 33 32 37 36 37 0a E_NUMBER<=32767.
16180 74 79 70 65 64 65 66 20 69 31 36 20 79 6e 56 61 typedef i16 ynVa
16190 72 3b 0a 23 65 6c 73 65 0a 74 79 70 65 64 65 66 r;.#else.typedef
161a0 20 69 6e 74 20 79 6e 56 61 72 3b 0a 23 65 6e 64 int ynVar;.#end
161b0 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 6e if../*.** Each n
161c0 6f 64 65 20 6f 66 20 61 6e 20 65 78 70 72 65 73 ode of an expres
161d0 73 69 6f 6e 20 69 6e 20 74 68 65 20 70 61 72 73 sion in the pars
161e0 65 20 74 72 65 65 20 69 73 20 61 6e 20 69 6e 73 e tree is an ins
161f0 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 69 73 tance.** of this
16200 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a structure..**.*
16210 2a 20 45 78 70 72 2e 6f 70 20 69 73 20 74 68 65 * Expr.op is the
16220 20 6f 70 63 6f 64 65 2e 20 54 68 65 20 69 6e 74 opcode. The int
16230 65 67 65 72 20 70 61 72 73 65 72 20 74 6f 6b 65 eger parser toke
16240 6e 20 63 6f 64 65 73 20 61 72 65 20 72 65 75 73 n codes are reus
16250 65 64 0a 2a 2a 20 61 73 20 6f 70 63 6f 64 65 73 ed.** as opcodes
16260 20 68 65 72 65 2e 20 46 6f 72 20 65 78 61 6d 70 here. For examp
16270 6c 65 2c 20 74 68 65 20 70 61 72 73 65 72 20 64 le, the parser d
16280 65 66 69 6e 65 73 20 54 4b 5f 47 45 20 74 6f 20 efines TK_GE to
16290 62 65 20 61 6e 20 69 6e 74 65 67 65 72 0a 2a 2a be an integer.**
162a0 20 63 6f 64 65 20 72 65 70 72 65 73 65 6e 74 69 code representi
162b0 6e 67 20 74 68 65 20 22 3e 3d 22 20 6f 70 65 72 ng the ">=" oper
162c0 61 74 6f 72 2e 20 54 68 69 73 20 73 61 6d 65 20 ator. This same
162d0 69 6e 74 65 67 65 72 20 63 6f 64 65 20 69 73 20 integer code is
162e0 72 65 75 73 65 64 0a 2a 2a 20 74 6f 20 72 65 70 reused.** to rep
162f0 72 65 73 65 6e 74 20 74 68 65 20 67 72 65 61 74 resent the great
16300 65 72 2d 74 68 61 6e 2d 6f 72 2d 65 71 75 61 6c er-than-or-equal
16310 2d 74 6f 20 6f 70 65 72 61 74 6f 72 20 69 6e 20 -to operator in
16320 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 0a 2a the expression.*
16330 2a 20 74 72 65 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 * tree..**.** If
16340 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 the expression
16350 69 73 20 61 6e 20 53 51 4c 20 6c 69 74 65 72 61 is an SQL litera
16360 6c 20 28 54 4b 5f 49 4e 54 45 47 45 52 2c 20 54 l (TK_INTEGER, T
16370 4b 5f 46 4c 4f 41 54 2c 20 54 4b 5f 42 4c 4f 42 K_FLOAT, TK_BLOB
16380 2c 0a 2a 2a 20 6f 72 20 54 4b 5f 53 54 52 49 4e ,.** or TK_STRIN
16390 47 29 2c 20 74 68 65 6e 20 45 78 70 72 2e 74 6f G), then Expr.to
163a0 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 ken contains the
163b0 20 74 65 78 74 20 6f 66 20 74 68 65 20 53 51 4c text of the SQL
163c0 20 6c 69 74 65 72 61 6c 2e 20 49 66 0a 2a 2a 20 literal. If.**
163d0 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 69 the expression i
163e0 73 20 61 20 76 61 72 69 61 62 6c 65 20 28 54 4b s a variable (TK
163f0 5f 56 41 52 49 41 42 4c 45 29 2c 20 74 68 65 6e _VARIABLE), then
16400 20 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 Expr.token cont
16410 61 69 6e 73 20 74 68 65 0a 2a 2a 20 76 61 72 69 ains the.** vari
16420 61 62 6c 65 20 6e 61 6d 65 2e 20 46 69 6e 61 6c able name. Final
16430 6c 79 2c 20 69 66 20 74 68 65 20 65 78 70 72 65 ly, if the expre
16440 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 ssion is an SQL
16450 66 75 6e 63 74 69 6f 6e 20 28 54 4b 5f 46 55 4e function (TK_FUN
16460 43 54 49 4f 4e 29 2c 0a 2a 2a 20 74 68 65 6e 20 CTION),.** then
16470 45 78 70 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 Expr.token conta
16480 69 6e 73 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 ins the name of
16490 74 68 65 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2a the function..**
164a0 0a 2a 2a 20 45 78 70 72 2e 70 52 69 67 68 74 20 .** Expr.pRight
164b0 61 6e 64 20 45 78 70 72 2e 70 4c 65 66 74 20 61 and Expr.pLeft a
164c0 72 65 20 74 68 65 20 6c 65 66 74 20 61 6e 64 20 re the left and
164d0 72 69 67 68 74 20 73 75 62 65 78 70 72 65 73 73 right subexpress
164e0 69 6f 6e 73 20 6f 66 20 61 0a 2a 2a 20 62 69 6e ions of a.** bin
164f0 61 72 79 20 6f 70 65 72 61 74 6f 72 2e 20 45 69 ary operator. Ei
16500 74 68 65 72 20 6f 72 20 62 6f 74 68 20 6d 61 79 ther or both may
16510 20 62 65 20 4e 55 4c 4c 2e 0a 2a 2a 0a 2a 2a 20 be NULL..**.**
16520 45 78 70 72 2e 78 2e 70 4c 69 73 74 20 69 73 20 Expr.x.pList is
16530 61 20 6c 69 73 74 20 6f 66 20 61 72 67 75 6d 65 a list of argume
16540 6e 74 73 20 69 66 20 74 68 65 20 65 78 70 72 65 nts if the expre
16550 73 73 69 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 ssion is an SQL
16560 66 75 6e 63 74 69 6f 6e 2c 0a 2a 2a 20 61 20 43 function,.** a C
16570 41 53 45 20 65 78 70 72 65 73 73 69 6f 6e 20 6f ASE expression o
16580 72 20 61 6e 20 49 4e 20 65 78 70 72 65 73 73 69 r an IN expressi
16590 6f 6e 20 6f 66 20 74 68 65 20 66 6f 72 6d 20 22 on of the form "
165a0 3c 6c 68 73 3e 20 49 4e 20 28 3c 79 3e 2c 20 3c <lhs> IN (<y>, <
165b0 7a 3e 2e 2e 2e 29 22 2e 0a 2a 2a 20 45 78 70 72 z>...)"..** Expr
165c0 2e 78 2e 70 53 65 6c 65 63 74 20 69 73 20 75 73 .x.pSelect is us
165d0 65 64 20 69 66 20 74 68 65 20 65 78 70 72 65 73 ed if the expres
165e0 73 69 6f 6e 20 69 73 20 61 20 73 75 62 2d 73 65 sion is a sub-se
165f0 6c 65 63 74 20 6f 72 20 61 6e 20 65 78 70 72 65 lect or an expre
16600 73 73 69 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 ssion of.** the
16610 66 6f 72 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 form "<lhs> IN (
16620 53 45 4c 45 43 54 20 2e 2e 2e 29 22 2e 20 49 66 SELECT ...)". If
16630 20 74 68 65 20 45 50 5f 78 49 73 53 65 6c 65 63 the EP_xIsSelec
16640 74 20 62 69 74 20 69 73 20 73 65 74 20 69 6e 20 t bit is set in
16650 74 68 65 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 the.** Expr.flag
16660 73 20 6d 61 73 6b 2c 20 74 68 65 6e 20 45 78 70 s mask, then Exp
16670 72 2e 78 2e 70 53 65 6c 65 63 74 20 69 73 20 76 r.x.pSelect is v
16680 61 6c 69 64 2e 20 4f 74 68 65 72 77 69 73 65 2c alid. Otherwise,
16690 20 45 78 70 72 2e 78 2e 70 4c 69 73 74 20 69 73 Expr.x.pList is
166a0 0a 2a 2a 20 76 61 6c 69 64 2e 0a 2a 2a 0a 2a 2a .** valid..**.**
166b0 20 41 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 6f An expression o
166c0 66 20 74 68 65 20 66 6f 72 6d 20 49 44 20 6f 72 f the form ID or
166d0 20 49 44 2e 49 44 20 72 65 66 65 72 73 20 74 6f ID.ID refers to
166e0 20 61 20 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 74 a column in a t
166f0 61 62 6c 65 2e 0a 2a 2a 20 46 6f 72 20 73 75 63 able..** For suc
16700 68 20 65 78 70 72 65 73 73 69 6f 6e 73 2c 20 45 h expressions, E
16710 78 70 72 2e 6f 70 20 69 73 20 73 65 74 20 74 6f xpr.op is set to
16720 20 54 4b 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 45 TK_COLUMN and E
16730 78 70 72 2e 69 54 61 62 6c 65 20 69 73 0a 2a 2a xpr.iTable is.**
16740 20 74 68 65 20 69 6e 74 65 67 65 72 20 63 75 72 the integer cur
16750 73 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 61 20 sor number of a
16760 56 44 42 45 20 63 75 72 73 6f 72 20 70 6f 69 6e VDBE cursor poin
16770 74 69 6e 67 20 74 6f 20 74 68 61 74 20 74 61 62 ting to that tab
16780 6c 65 20 61 6e 64 0a 2a 2a 20 45 78 70 72 2e 69 le and.** Expr.i
16790 43 6f 6c 75 6d 6e 20 69 73 20 74 68 65 20 63 6f Column is the co
167a0 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 lumn number for
167b0 74 68 65 20 73 70 65 63 69 66 69 63 20 63 6f 6c the specific col
167c0 75 6d 6e 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 umn. If the.**
167d0 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 75 73 expression is us
167e0 65 64 20 61 73 20 61 20 72 65 73 75 6c 74 20 69 ed as a result i
167f0 6e 20 61 6e 20 61 67 67 72 65 67 61 74 65 20 53 n an aggregate S
16800 45 4c 45 43 54 2c 20 74 68 65 6e 20 74 68 65 0a ELECT, then the.
16810 2a 2a 20 76 61 6c 75 65 20 69 73 20 61 6c 73 6f ** value is also
16820 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 45 stored in the E
16830 78 70 72 2e 69 41 67 67 20 63 6f 6c 75 6d 6e 20 xpr.iAgg column
16840 69 6e 20 74 68 65 20 61 67 67 72 65 67 61 74 65 in the aggregate
16850 20 73 6f 20 74 68 61 74 0a 2a 2a 20 69 74 20 63 so that.** it c
16860 61 6e 20 62 65 20 61 63 63 65 73 73 65 64 20 61 an be accessed a
16870 66 74 65 72 20 61 6c 6c 20 61 67 67 72 65 67 61 fter all aggrega
16880 74 65 73 20 61 72 65 20 63 6f 6d 70 75 74 65 64 tes are computed
16890 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 ..**.** If the e
168a0 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 xpression is an
168b0 75 6e 62 6f 75 6e 64 20 76 61 72 69 61 62 6c 65 unbound variable
168c0 20 6d 61 72 6b 65 72 20 28 61 20 71 75 65 73 74 marker (a quest
168d0 69 6f 6e 20 6d 61 72 6b 0a 2a 2a 20 63 68 61 72 ion mark.** char
168e0 61 63 74 65 72 20 27 3f 27 20 69 6e 20 74 68 65 acter '?' in the
168f0 20 6f 72 69 67 69 6e 61 6c 20 53 51 4c 29 20 74 original SQL) t
16900 68 65 6e 20 74 68 65 20 45 78 70 72 2e 69 54 61 hen the Expr.iTa
16910 62 6c 65 20 68 6f 6c 64 73 20 74 68 65 20 69 6e ble holds the in
16920 64 65 78 0a 2a 2a 20 6e 75 6d 62 65 72 20 66 6f dex.** number fo
16930 72 20 74 68 61 74 20 76 61 72 69 61 62 6c 65 2e r that variable.
16940 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 .**.** If the ex
16950 70 72 65 73 73 69 6f 6e 20 69 73 20 61 20 73 75 pression is a su
16960 62 71 75 65 72 79 20 74 68 65 6e 20 45 78 70 72 bquery then Expr
16970 2e 69 43 6f 6c 75 6d 6e 20 68 6f 6c 64 73 20 61 .iColumn holds a
16980 6e 20 69 6e 74 65 67 65 72 0a 2a 2a 20 72 65 67 n integer.** reg
16990 69 73 74 65 72 20 6e 75 6d 62 65 72 20 63 6f 6e ister number con
169a0 74 61 69 6e 69 6e 67 20 74 68 65 20 72 65 73 75 taining the resu
169b0 6c 74 20 6f 66 20 74 68 65 20 73 75 62 71 75 65 lt of the subque
169c0 72 79 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 73 ry. If the.** s
169d0 75 62 71 75 65 72 79 20 67 69 76 65 73 20 61 20 ubquery gives a
169e0 63 6f 6e 73 74 61 6e 74 20 72 65 73 75 6c 74 2c constant result,
169f0 20 74 68 65 6e 20 69 54 61 62 6c 65 20 69 73 20 then iTable is
16a00 2d 31 2e 20 20 49 66 20 74 68 65 20 73 75 62 71 -1. If the subq
16a10 75 65 72 79 0a 2a 2a 20 67 69 76 65 73 20 61 20 uery.** gives a
16a20 64 69 66 66 65 72 65 6e 74 20 61 6e 73 77 65 72 different answer
16a30 20 61 74 20 64 69 66 66 65 72 65 6e 74 20 74 69 at different ti
16a40 6d 65 73 20 64 75 72 69 6e 67 20 73 74 61 74 65 mes during state
16a50 6d 65 6e 74 20 70 72 6f 63 65 73 73 69 6e 67 0a ment processing.
16a60 2a 2a 20 74 68 65 6e 20 69 54 61 62 6c 65 20 69 ** then iTable i
16a70 73 20 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 s the address of
16a80 20 61 20 73 75 62 72 6f 75 74 69 6e 65 20 74 68 a subroutine th
16a90 61 74 20 63 6f 6d 70 75 74 65 73 20 74 68 65 20 at computes the
16aa0 73 75 62 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 subquery..**.**
16ab0 49 66 20 74 68 65 20 45 78 70 72 20 69 73 20 6f If the Expr is o
16ac0 66 20 74 79 70 65 20 4f 50 5f 43 6f 6c 75 6d 6e f type OP_Column
16ad0 2c 20 61 6e 64 20 74 68 65 20 74 61 62 6c 65 20 , and the table
16ae0 69 74 20 69 73 20 73 65 6c 65 63 74 69 6e 67 20 it is selecting
16af0 66 72 6f 6d 0a 2a 2a 20 69 73 20 61 20 64 69 73 from.** is a dis
16b00 6b 20 74 61 62 6c 65 20 6f 72 20 74 68 65 20 22 k table or the "
16b10 6f 6c 64 2e 2a 22 20 70 73 65 75 64 6f 2d 74 61 old.*" pseudo-ta
16b20 62 6c 65 2c 20 74 68 65 6e 20 70 54 61 62 20 70 ble, then pTab p
16b30 6f 69 6e 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 oints to the.**
16b40 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 61 corresponding ta
16b50 62 6c 65 20 64 65 66 69 6e 69 74 69 6f 6e 2e 0a ble definition..
16b60 2a 2a 0a 2a 2a 20 41 4c 4c 4f 43 41 54 49 4f 4e **.** ALLOCATION
16b70 20 4e 4f 54 45 53 3a 0a 2a 2a 0a 2a 2a 20 45 78 NOTES:.**.** Ex
16b80 70 72 20 6f 62 6a 65 63 74 73 20 63 61 6e 20 75 pr objects can u
16b90 73 65 20 61 20 6c 6f 74 20 6f 66 20 6d 65 6d 6f se a lot of memo
16ba0 72 79 20 73 70 61 63 65 20 69 6e 20 64 61 74 61 ry space in data
16bb0 62 61 73 65 20 73 63 68 65 6d 61 2e 20 20 54 6f base schema. To
16bc0 0a 2a 2a 20 68 65 6c 70 20 72 65 64 75 63 65 20 .** help reduce
16bd0 6d 65 6d 6f 72 79 20 72 65 71 75 69 72 65 6d 65 memory requireme
16be0 6e 74 73 2c 20 73 6f 6d 65 74 69 6d 65 73 20 61 nts, sometimes a
16bf0 6e 20 45 78 70 72 20 6f 62 6a 65 63 74 20 77 69 n Expr object wi
16c00 6c 6c 20 62 65 0a 2a 2a 20 74 72 75 6e 63 61 74 ll be.** truncat
16c10 65 64 2e 20 20 41 6e 64 20 74 6f 20 72 65 64 75 ed. And to redu
16c20 63 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ce the number of
16c30 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
16c40 6f 6e 73 2c 20 73 6f 6d 65 74 69 6d 65 73 0a 2a ons, sometimes.*
16c50 2a 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 45 78 * two or more Ex
16c60 70 72 20 6f 62 6a 65 63 74 73 20 77 69 6c 6c 20 pr objects will
16c70 62 65 20 73 74 6f 72 65 64 20 69 6e 20 61 20 73 be stored in a s
16c80 69 6e 67 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c ingle memory all
16c90 6f 63 61 74 69 6f 6e 2c 0a 2a 2a 20 74 6f 67 65 ocation,.** toge
16ca0 74 68 65 72 20 77 69 74 68 20 45 78 70 72 2e 7a ther with Expr.z
16cb0 54 6f 6b 65 6e 20 73 74 72 69 6e 67 73 2e 0a 2a Token strings..*
16cc0 2a 0a 2a 2a 20 49 66 20 74 68 65 20 45 50 5f 52 *.** If the EP_R
16cd0 65 64 75 63 65 64 20 61 6e 64 20 45 50 5f 54 6f educed and EP_To
16ce0 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 73 20 61 72 kenOnly flags ar
16cf0 65 20 73 65 74 20 77 68 65 6e 0a 2a 2a 20 61 6e e set when.** an
16d00 20 45 78 70 72 20 6f 62 6a 65 63 74 20 69 73 20 Expr object is
16d10 74 72 75 6e 63 61 74 65 64 2e 20 20 57 68 65 6e truncated. When
16d20 20 45 50 5f 52 65 64 75 63 65 64 20 69 73 20 73 EP_Reduced is s
16d30 65 74 2c 20 74 68 65 6e 20 61 6c 6c 0a 2a 2a 20 et, then all.**
16d40 74 68 65 20 63 68 69 6c 64 20 45 78 70 72 20 6f the child Expr o
16d50 62 6a 65 63 74 73 20 69 6e 20 74 68 65 20 45 78 bjects in the Ex
16d60 70 72 2e 70 4c 65 66 74 20 61 6e 64 20 45 78 70 pr.pLeft and Exp
16d70 72 2e 70 52 69 67 68 74 20 73 75 62 74 72 65 65 r.pRight subtree
16d80 73 0a 2a 2a 20 61 72 65 20 63 6f 6e 74 61 69 6e s.** are contain
16d90 65 64 20 77 69 74 68 69 6e 20 74 68 65 20 73 61 ed within the sa
16da0 6d 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 me memory alloca
16db0 74 69 6f 6e 2e 20 20 4e 6f 74 65 2c 20 68 6f 77 tion. Note, how
16dc0 65 76 65 72 2c 20 74 68 61 74 0a 2a 2a 20 74 68 ever, that.** th
16dd0 65 20 73 75 62 74 72 65 65 73 20 69 6e 20 45 78 e subtrees in Ex
16de0 70 72 2e 78 2e 70 4c 69 73 74 20 6f 72 20 45 78 pr.x.pList or Ex
16df0 70 72 2e 78 2e 70 53 65 6c 65 63 74 20 61 72 65 pr.x.pSelect are
16e00 20 61 6c 77 61 79 73 20 73 65 70 61 72 61 74 65 always separate
16e10 6c 79 0a 2a 2a 20 61 6c 6c 6f 63 61 74 65 64 2c ly.** allocated,
16e20 20 72 65 67 61 72 64 6c 65 73 73 20 6f 66 20 77 regardless of w
16e30 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 45 50 hether or not EP
16e40 5f 52 65 64 75 63 65 64 20 69 73 20 73 65 74 2e _Reduced is set.
16e50 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 70 72 20 .*/.struct Expr
16e60 7b 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 {. u8 op;
16e70 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 /* Op
16e80 65 72 61 74 69 6f 6e 20 70 65 72 66 6f 72 6d 65 eration performe
16e90 64 20 62 79 20 74 68 69 73 20 6e 6f 64 65 20 2a d by this node *
16ea0 2f 0a 20 20 63 68 61 72 20 61 66 66 69 6e 69 74 /. char affinit
16eb0 79 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 y; /* Th
16ec0 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 74 68 e affinity of th
16ed0 65 20 63 6f 6c 75 6d 6e 20 6f 72 20 30 20 69 66 e column or 0 if
16ee0 20 6e 6f 74 20 61 20 63 6f 6c 75 6d 6e 20 2a 2f not a column */
16ef0 0a 20 20 75 33 32 20 66 6c 61 67 73 3b 20 20 20 . u32 flags;
16f00 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 72 /* Var
16f10 69 6f 75 73 20 66 6c 61 67 73 2e 20 20 45 50 5f ious flags. EP_
16f20 2a 20 53 65 65 20 62 65 6c 6f 77 20 2a 2f 0a 20 * See below */.
16f30 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 63 68 61 union {. cha
16f40 72 20 2a 7a 54 6f 6b 65 6e 3b 20 20 20 20 20 20 r *zToken;
16f50 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 76 61 6c /* Token val
16f60 75 65 2e 20 5a 65 72 6f 20 74 65 72 6d 69 6e 61 ue. Zero termina
16f70 74 65 64 20 61 6e 64 20 64 65 71 75 6f 74 65 64 ted and dequoted
16f80 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 56 61 6c */. int iVal
16f90 75 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ue; /
16fa0 2a 20 4e 6f 6e 2d 6e 65 67 61 74 69 76 65 20 69 * Non-negative i
16fb0 6e 74 65 67 65 72 20 76 61 6c 75 65 20 69 66 20 nteger value if
16fc0 45 50 5f 49 6e 74 56 61 6c 75 65 20 2a 2f 0a 20 EP_IntValue */.
16fd0 20 7d 20 75 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 } u;.. /* If t
16fe0 68 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 he EP_TokenOnly
16ff0 66 6c 61 67 20 69 73 20 73 65 74 20 69 6e 20 74 flag is set in t
17000 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 he Expr.flags ma
17010 73 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a sk, then no. **
17020 20 73 70 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 space is alloca
17030 74 65 64 20 66 6f 72 20 74 68 65 20 66 69 65 6c ted for the fiel
17040 64 73 20 62 65 6c 6f 77 20 74 68 69 73 20 70 6f ds below this po
17050 69 6e 74 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 int. An attempt
17060 74 6f 0a 20 20 2a 2a 20 61 63 63 65 73 73 20 74 to. ** access t
17070 68 65 6d 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 hem will result
17080 69 6e 20 61 20 73 65 67 66 61 75 6c 74 20 6f 72 in a segfault or
17090 20 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e 0a 20 20 malfunction..
170a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
170b0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
170c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
170d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
170e0 2a 2a 2a 2a 2a 2f 0a 0a 20 20 45 78 70 72 20 2a *****/.. Expr *
170f0 70 4c 65 66 74 3b 20 20 20 20 20 20 20 20 20 20 pLeft;
17100 20 2f 2a 20 4c 65 66 74 20 73 75 62 6e 6f 64 65 /* Left subnode
17110 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 52 69 67 */. Expr *pRig
17120 68 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ht; /*
17130 52 69 67 68 74 20 73 75 62 6e 6f 64 65 20 2a 2f Right subnode */
17140 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 45 . union {. E
17150 78 70 72 4c 69 73 74 20 2a 70 4c 69 73 74 3b 20 xprList *pList;
17160 20 20 20 20 2f 2a 20 6f 70 20 3d 20 49 4e 2c 20 /* op = IN,
17170 45 58 49 53 54 53 2c 20 53 45 4c 45 43 54 2c 20 EXISTS, SELECT,
17180 43 41 53 45 2c 20 46 55 4e 43 54 49 4f 4e 2c 20 CASE, FUNCTION,
17190 42 45 54 57 45 45 4e 20 2a 2f 0a 20 20 20 20 53 BETWEEN */. S
171a0 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 elect *pSelect;
171b0 20 20 20 20 2f 2a 20 45 50 5f 78 49 73 53 65 6c /* EP_xIsSel
171c0 65 63 74 20 61 6e 64 20 6f 70 20 3d 20 49 4e 2c ect and op = IN,
171d0 20 45 58 49 53 54 53 2c 20 53 45 4c 45 43 54 20 EXISTS, SELECT
171e0 2a 2f 0a 20 20 7d 20 78 3b 0a 0a 20 20 2f 2a 20 */. } x;.. /*
171f0 49 66 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 If the EP_Reduce
17200 64 20 66 6c 61 67 20 69 73 20 73 65 74 20 69 6e d flag is set in
17210 20 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 the Expr.flags
17220 6d 61 73 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 20 mask, then no.
17230 2a 2a 20 73 70 61 63 65 20 69 73 20 61 6c 6c 6f ** space is allo
17240 63 61 74 65 64 20 66 6f 72 20 74 68 65 20 66 69 cated for the fi
17250 65 6c 64 73 20 62 65 6c 6f 77 20 74 68 69 73 20 elds below this
17260 70 6f 69 6e 74 2e 20 41 6e 20 61 74 74 65 6d 70 point. An attemp
17270 74 20 74 6f 0a 20 20 2a 2a 20 61 63 63 65 73 73 t to. ** access
17280 20 74 68 65 6d 20 77 69 6c 6c 20 72 65 73 75 6c them will resul
17290 74 20 69 6e 20 61 20 73 65 67 66 61 75 6c 74 20 t in a segfault
172a0 6f 72 20 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e 0a or malfunction..
172b0 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a **************
172c0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
172d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
172e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
172f0 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 23 69 66 20 53 51 *******/..#if SQ
17300 4c 49 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 LITE_MAX_EXPR_DE
17310 50 54 48 3e 30 0a 20 20 69 6e 74 20 6e 48 65 69 PTH>0. int nHei
17320 67 68 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f ght; /
17330 2a 20 48 65 69 67 68 74 20 6f 66 20 74 68 65 20 * Height of the
17340 74 72 65 65 20 68 65 61 64 65 64 20 62 79 20 74 tree headed by t
17350 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 23 65 6e 64 his node */.#end
17360 69 66 0a 20 20 69 6e 74 20 69 54 61 62 6c 65 3b if. int iTable;
17370 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
17380 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 75 72 73 6f 72 K_COLUMN: cursor
17390 20 6e 75 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 number of table
173a0 20 68 6f 6c 64 69 6e 67 20 63 6f 6c 75 6d 6e 0a holding column.
173b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
173c0 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f 52 ** TK_R
173d0 45 47 49 53 54 45 52 3a 20 72 65 67 69 73 74 65 EGISTER: registe
173e0 72 20 6e 75 6d 62 65 72 0a 20 20 20 20 20 20 20 r number.
173f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17400 20 20 2a 2a 20 54 4b 5f 54 52 49 47 47 45 52 3a ** TK_TRIGGER:
17410 20 31 20 2d 3e 20 6e 65 77 2c 20 30 20 2d 3e 20 1 -> new, 0 ->
17420 6f 6c 64 0a 20 20 20 20 20 20 20 20 20 20 20 20 old.
17430 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
17440 45 50 5f 55 6e 6c 69 6b 65 6c 79 3a 20 20 31 33 EP_Unlikely: 13
17450 34 32 31 37 37 32 38 20 74 69 6d 65 73 20 6c 69 4217728 times li
17460 6b 65 6c 69 68 6f 6f 64 0a 20 20 20 20 20 20 20 kelihood.
17470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17480 20 20 2a 2a 20 54 4b 5f 53 45 4c 45 43 54 3a 20 ** TK_SELECT:
17490 31 73 74 20 72 65 67 69 73 74 65 72 20 6f 66 20 1st register of
174a0 72 65 73 75 6c 74 20 76 65 63 74 6f 72 20 2a 2f result vector */
174b0 0a 20 20 79 6e 56 61 72 20 69 43 6f 6c 75 6d 6e . ynVar iColumn
174c0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f ; /* TK_
174d0 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d 6e 20 69 COLUMN: column i
174e0 6e 64 65 78 2e 20 20 2d 31 20 66 6f 72 20 72 6f ndex. -1 for ro
174f0 77 69 64 2e 0a 20 20 20 20 20 20 20 20 20 20 20 wid..
17500 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
17510 20 54 4b 5f 56 41 52 49 41 42 4c 45 3a 20 76 61 TK_VARIABLE: va
17520 72 69 61 62 6c 65 20 6e 75 6d 62 65 72 20 28 61 riable number (a
17530 6c 77 61 79 73 20 3e 3d 20 31 29 2e 0a 20 20 20 lways >= 1)..
17540 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
17550 20 20 20 20 20 20 2a 2a 20 54 4b 5f 53 45 4c 45 ** TK_SELE
17560 43 54 5f 43 4f 4c 55 4d 4e 3a 20 63 6f 6c 75 6d CT_COLUMN: colum
17570 6e 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 n of the result
17580 76 65 63 74 6f 72 20 2a 2f 0a 20 20 69 31 36 20 vector */. i16
17590 69 41 67 67 3b 20 20 20 20 20 20 20 20 20 20 20 iAgg;
175a0 20 20 20 2f 2a 20 57 68 69 63 68 20 65 6e 74 72 /* Which entr
175b0 79 20 69 6e 20 70 41 67 67 49 6e 66 6f 2d 3e 61 y in pAggInfo->a
175c0 43 6f 6c 5b 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 Col[] or ->aFunc
175d0 5b 5d 20 2a 2f 0a 20 20 69 31 36 20 69 52 69 67 [] */. i16 iRig
175e0 68 74 4a 6f 69 6e 54 61 62 6c 65 3b 20 20 20 2f htJoinTable; /
175f0 2a 20 49 66 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e * If EP_FromJoin
17600 2c 20 74 68 65 20 72 69 67 68 74 20 74 61 62 6c , the right tabl
17610 65 20 6f 66 20 74 68 65 20 6a 6f 69 6e 20 2a 2f e of the join */
17620 0a 20 20 75 38 20 6f 70 32 3b 20 20 20 20 20 20 . u8 op2;
17630 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f /* TK_
17640 52 45 47 49 53 54 45 52 3a 20 6f 72 69 67 69 6e REGISTER: origin
17650 61 6c 20 76 61 6c 75 65 20 6f 66 20 45 78 70 72 al value of Expr
17660 2e 6f 70 0a 20 20 20 20 20 20 20 20 20 20 20 20 .op.
17670 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
17680 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 74 68 65 20 76 TK_COLUMN: the v
17690 61 6c 75 65 20 6f 66 20 70 35 20 66 6f 72 20 4f alue of p5 for O
176a0 50 5f 43 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 P_Column.
176b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
176c0 20 20 2a 2a 20 54 4b 5f 41 47 47 5f 46 55 4e 43 ** TK_AGG_FUNC
176d0 54 49 4f 4e 3a 20 6e 65 73 74 69 6e 67 20 64 65 TION: nesting de
176e0 70 74 68 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f pth */. AggInfo
176f0 20 2a 70 41 67 67 49 6e 66 6f 3b 20 20 20 20 20 *pAggInfo;
17700 2f 2a 20 55 73 65 64 20 62 79 20 54 4b 5f 41 47 /* Used by TK_AG
17710 47 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 54 4b 5f G_COLUMN and TK_
17720 41 47 47 5f 46 55 4e 43 54 49 4f 4e 20 2a 2f 0a AGG_FUNCTION */.
17730 20 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 Table *pTab;
17740 20 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c /* Tabl
17750 65 20 66 6f 72 20 54 4b 5f 43 4f 4c 55 4d 4e 20 e for TK_COLUMN
17760 65 78 70 72 65 73 73 69 6f 6e 73 2e 20 2a 2f 0a expressions. */.
17770 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f };../*.** The fo
17780 6c 6c 6f 77 69 6e 67 20 61 72 65 20 74 68 65 20 llowing are the
17790 6d 65 61 6e 69 6e 67 73 20 6f 66 20 62 69 74 73 meanings of bits
177a0 20 69 6e 20 74 68 65 20 45 78 70 72 2e 66 6c 61 in the Expr.fla
177b0 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 gs field..*/.#de
177c0 66 69 6e 65 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e fine EP_FromJoin
177d0 20 20 30 78 30 30 30 30 30 31 20 2f 2a 20 4f 72 0x000001 /* Or
177e0 69 67 69 6e 61 74 65 73 20 69 6e 20 4f 4e 2f 55 iginates in ON/U
177f0 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 6f SING clause of o
17800 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 uter join */.#de
17810 66 69 6e 65 20 45 50 5f 41 67 67 20 20 20 20 20 fine EP_Agg
17820 20 20 30 78 30 30 30 30 30 32 20 2f 2a 20 43 6f 0x000002 /* Co
17830 6e 74 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f ntains one or mo
17840 72 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e re aggregate fun
17850 63 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 66 69 6e ctions */.#defin
17860 65 20 45 50 5f 52 65 73 6f 6c 76 65 64 20 20 30 e EP_Resolved 0
17870 78 30 30 30 30 30 34 20 2f 2a 20 49 44 73 20 68 x000004 /* IDs h
17880 61 76 65 20 62 65 65 6e 20 72 65 73 6f 6c 76 65 ave been resolve
17890 64 20 74 6f 20 43 4f 4c 55 4d 4e 73 20 2a 2f 0a d to COLUMNs */.
178a0 23 64 65 66 69 6e 65 20 45 50 5f 45 72 72 6f 72 #define EP_Error
178b0 20 20 20 20 20 30 78 30 30 30 30 30 38 20 2f 2a 0x000008 /*
178c0 20 45 78 70 72 65 73 73 69 6f 6e 20 63 6f 6e 74 Expression cont
178d0 61 69 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 ains one or more
178e0 20 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 errors */.#defi
178f0 6e 65 20 45 50 5f 44 69 73 74 69 6e 63 74 20 20 ne EP_Distinct
17900 30 78 30 30 30 30 31 30 20 2f 2a 20 41 67 67 72 0x000010 /* Aggr
17910 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 77 egate function w
17920 69 74 68 20 44 49 53 54 49 4e 43 54 20 6b 65 79 ith DISTINCT key
17930 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 word */.#define
17940 45 50 5f 56 61 72 53 65 6c 65 63 74 20 30 78 30 EP_VarSelect 0x0
17950 30 30 30 32 30 20 2f 2a 20 70 53 65 6c 65 63 74 00020 /* pSelect
17960 20 69 73 20 63 6f 72 72 65 6c 61 74 65 64 2c 20 is correlated,
17970 6e 6f 74 20 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a not constant */.
17980 23 64 65 66 69 6e 65 20 45 50 5f 44 62 6c 51 75 #define EP_DblQu
17990 6f 74 65 64 20 30 78 30 30 30 30 34 30 20 2f 2a oted 0x000040 /*
179a0 20 74 6f 6b 65 6e 2e 7a 20 77 61 73 20 6f 72 69 token.z was ori
179b0 67 69 6e 61 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 ginally in "..."
179c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 */.#define EP_I
179d0 6e 66 69 78 46 75 6e 63 20 30 78 30 30 30 30 38 nfixFunc 0x00008
179e0 30 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 61 6e 0 /* True for an
179f0 20 69 6e 66 69 78 20 66 75 6e 63 74 69 6f 6e 3a infix function:
17a00 20 4c 49 4b 45 2c 20 47 4c 4f 42 2c 20 65 74 63 LIKE, GLOB, etc
17a10 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 */.#define EP_C
17a20 6f 6c 6c 61 74 65 20 20 20 30 78 30 30 30 31 30 ollate 0x00010
17a30 30 20 2f 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 0 /* Tree contai
17a40 6e 73 20 61 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 ns a TK_COLLATE
17a50 6f 70 65 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 operator */.#def
17a60 69 6e 65 20 45 50 5f 47 65 6e 65 72 69 63 20 20 ine EP_Generic
17a70 20 30 78 30 30 30 32 30 30 20 2f 2a 20 49 67 6e 0x000200 /* Ign
17a80 6f 72 65 20 43 4f 4c 4c 41 54 45 20 6f 72 20 61 ore COLLATE or a
17a90 66 66 69 6e 69 74 79 20 6f 6e 20 74 68 69 73 20 ffinity on this
17aa0 74 72 65 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tree */.#define
17ab0 45 50 5f 49 6e 74 56 61 6c 75 65 20 20 30 78 30 EP_IntValue 0x0
17ac0 30 30 34 30 30 20 2f 2a 20 49 6e 74 65 67 65 72 00400 /* Integer
17ad0 20 76 61 6c 75 65 20 63 6f 6e 74 61 69 6e 65 64 value contained
17ae0 20 69 6e 20 75 2e 69 56 61 6c 75 65 20 2a 2f 0a in u.iValue */.
17af0 23 64 65 66 69 6e 65 20 45 50 5f 78 49 73 53 65 #define EP_xIsSe
17b00 6c 65 63 74 20 30 78 30 30 30 38 30 30 20 2f 2a lect 0x000800 /*
17b10 20 78 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 x.pSelect is va
17b20 6c 69 64 20 28 6f 74 68 65 72 77 69 73 65 20 78 lid (otherwise x
17b30 2e 70 4c 69 73 74 20 69 73 29 20 2a 2f 0a 23 64 .pList is) */.#d
17b40 65 66 69 6e 65 20 45 50 5f 53 6b 69 70 20 20 20 efine EP_Skip
17b50 20 20 20 30 78 30 30 31 30 30 30 20 2f 2a 20 43 0x001000 /* C
17b60 4f 4c 4c 41 54 45 2c 20 41 53 2c 20 6f 72 20 55 OLLATE, AS, or U
17b70 4e 4c 49 4b 45 4c 59 20 2a 2f 0a 23 64 65 66 69 NLIKELY */.#defi
17b80 6e 65 20 45 50 5f 52 65 64 75 63 65 64 20 20 20 ne EP_Reduced
17b90 30 78 30 30 32 30 30 30 20 2f 2a 20 45 78 70 72 0x002000 /* Expr
17ba0 20 73 74 72 75 63 74 20 45 58 50 52 5f 52 45 44 struct EXPR_RED
17bb0 55 43 45 44 53 49 5a 45 20 62 79 74 65 73 20 6f UCEDSIZE bytes o
17bc0 6e 6c 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 nly */.#define E
17bd0 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 P_TokenOnly 0x00
17be0 34 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 4000 /* Expr str
17bf0 75 63 74 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e uct EXPR_TOKENON
17c00 4c 59 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c LYSIZE bytes onl
17c10 79 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f y */.#define EP_
17c20 53 74 61 74 69 63 20 20 20 20 30 78 30 30 38 30 Static 0x0080
17c30 30 30 20 2f 2a 20 48 65 6c 64 20 69 6e 20 6d 65 00 /* Held in me
17c40 6d 6f 72 79 20 6e 6f 74 20 6f 62 74 61 69 6e 65 mory not obtaine
17c50 64 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 d from malloc()
17c60 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4d 65 */.#define EP_Me
17c70 6d 54 6f 6b 65 6e 20 20 30 78 30 31 30 30 30 30 mToken 0x010000
17c80 20 2f 2a 20 4e 65 65 64 20 74 6f 20 73 71 6c 69 /* Need to sqli
17c90 74 65 33 44 62 46 72 65 65 28 29 20 45 78 70 72 te3DbFree() Expr
17ca0 2e 7a 54 6f 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 .zToken */.#defi
17cb0 6e 65 20 45 50 5f 4e 6f 52 65 64 75 63 65 20 20 ne EP_NoReduce
17cc0 30 78 30 32 30 30 30 30 20 2f 2a 20 43 61 6e 6e 0x020000 /* Cann
17cd0 6f 74 20 45 58 50 52 44 55 50 5f 52 45 44 55 43 ot EXPRDUP_REDUC
17ce0 45 20 74 68 69 73 20 45 78 70 72 20 2a 2f 0a 23 E this Expr */.#
17cf0 64 65 66 69 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 define EP_Unlike
17d00 6c 79 20 20 30 78 30 34 30 30 30 30 20 2f 2a 20 ly 0x040000 /*
17d10 75 6e 6c 69 6b 65 6c 79 28 29 20 6f 72 20 6c 69 unlikely() or li
17d20 6b 65 6c 69 68 6f 6f 64 28 29 20 66 75 6e 63 74 kelihood() funct
17d30 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ion */.#define E
17d40 50 5f 43 6f 6e 73 74 46 75 6e 63 20 30 78 30 38 P_ConstFunc 0x08
17d50 30 30 30 30 20 2f 2a 20 41 20 53 51 4c 49 54 45 0000 /* A SQLITE
17d60 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 6f _FUNC_CONSTANT o
17d70 72 20 5f 53 4c 4f 43 48 4e 47 20 66 75 6e 63 74 r _SLOCHNG funct
17d80 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ion */.#define E
17d90 50 5f 43 61 6e 42 65 4e 75 6c 6c 20 30 78 31 30 P_CanBeNull 0x10
17da0 30 30 30 30 20 2f 2a 20 43 61 6e 20 62 65 20 6e 0000 /* Can be n
17db0 75 6c 6c 20 64 65 73 70 69 74 65 20 4e 4f 54 20 ull despite NOT
17dc0 4e 55 4c 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 NULL constraint
17dd0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 75 */.#define EP_Su
17de0 62 71 75 65 72 79 20 20 30 78 32 30 30 30 30 30 bquery 0x200000
17df0 20 2f 2a 20 54 72 65 65 20 63 6f 6e 74 61 69 6e /* Tree contain
17e00 73 20 61 20 54 4b 5f 53 45 4c 45 43 54 20 6f 70 s a TK_SELECT op
17e10 65 72 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e erator */.#defin
17e20 65 20 45 50 5f 41 6c 69 61 73 20 20 20 20 20 30 e EP_Alias 0
17e30 78 34 30 30 30 30 30 20 2f 2a 20 49 73 20 61 6e x400000 /* Is an
17e40 20 61 6c 69 61 73 20 66 6f 72 20 61 20 72 65 73 alias for a res
17e50 75 6c 74 20 73 65 74 20 63 6f 6c 75 6d 6e 20 2a ult set column *
17e60 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 4c 65 61 /.#define EP_Lea
17e70 66 20 20 20 20 20 20 30 78 38 30 30 30 30 30 20 f 0x800000
17e80 2f 2a 20 45 78 70 72 2e 70 4c 65 66 74 2c 20 2e /* Expr.pLeft, .
17e90 70 52 69 67 68 74 2c 20 2e 75 2e 70 53 65 6c 65 pRight, .u.pSele
17ea0 63 74 20 61 6c 6c 20 4e 55 4c 4c 20 2a 2f 0a 0a ct all NULL */..
17eb0 2f 2a 0a 2a 2a 20 43 6f 6d 62 69 6e 61 74 69 6f /*.** Combinatio
17ec0 6e 73 20 6f 66 20 74 77 6f 20 6f 72 20 6d 6f 72 ns of two or mor
17ed0 65 20 45 50 5f 2a 20 66 6c 61 67 73 0a 2a 2f 0a e EP_* flags.*/.
17ee0 23 64 65 66 69 6e 65 20 45 50 5f 50 72 6f 70 61 #define EP_Propa
17ef0 67 61 74 65 20 28 45 50 5f 43 6f 6c 6c 61 74 65 gate (EP_Collate
17f00 7c 45 50 5f 53 75 62 71 75 65 72 79 29 20 2f 2a |EP_Subquery) /*
17f10 20 50 72 6f 70 61 67 61 74 65 20 74 68 65 73 65 Propagate these
17f20 20 62 69 74 73 20 75 70 20 74 72 65 65 20 2a 2f bits up tree */
17f30 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 65 20 6d 61 ../*.** These ma
17f40 63 72 6f 73 20 63 61 6e 20 62 65 20 75 73 65 64 cros can be used
17f50 20 74 6f 20 74 65 73 74 2c 20 73 65 74 2c 20 6f to test, set, o
17f60 72 20 63 6c 65 61 72 20 62 69 74 73 20 69 6e 20 r clear bits in
17f70 74 68 65 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 the.** Expr.flag
17f80 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 s field..*/.#def
17f90 69 6e 65 20 45 78 70 72 48 61 73 50 72 6f 70 65 ine ExprHasPrope
17fa0 72 74 79 28 45 2c 50 29 20 20 20 20 20 28 28 28 rty(E,P) (((
17fb0 45 29 2d 3e 66 6c 61 67 73 26 28 50 29 29 21 3d E)->flags&(P))!=
17fc0 30 29 0a 23 64 65 66 69 6e 65 20 45 78 70 72 48 0).#define ExprH
17fd0 61 73 41 6c 6c 50 72 6f 70 65 72 74 79 28 45 2c asAllProperty(E,
17fe0 50 29 20 20 28 28 28 45 29 2d 3e 66 6c 61 67 73 P) (((E)->flags
17ff0 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 64 65 66 &(P))==(P)).#def
18000 69 6e 65 20 45 78 70 72 53 65 74 50 72 6f 70 65 ine ExprSetPrope
18010 72 74 79 28 45 2c 50 29 20 20 20 20 20 28 45 29 rty(E,P) (E)
18020 2d 3e 66 6c 61 67 73 7c 3d 28 50 29 0a 23 64 65 ->flags|=(P).#de
18030 66 69 6e 65 20 45 78 70 72 43 6c 65 61 72 50 72 fine ExprClearPr
18040 6f 70 65 72 74 79 28 45 2c 50 29 20 20 20 28 45 operty(E,P) (E
18050 29 2d 3e 66 6c 61 67 73 26 3d 7e 28 50 29 0a 0a )->flags&=~(P)..
18060 2f 2a 20 54 68 65 20 45 78 70 72 53 65 74 56 56 /* The ExprSetVV
18070 41 50 72 6f 70 65 72 74 79 28 29 20 6d 61 63 72 AProperty() macr
18080 6f 20 69 73 20 75 73 65 64 20 66 6f 72 20 56 65 o is used for Ve
18090 72 69 66 69 63 61 74 69 6f 6e 2c 20 56 61 6c 69 rification, Vali
180a0 64 61 74 69 6f 6e 2c 0a 2a 2a 20 61 6e 64 20 41 dation,.** and A
180b0 63 63 72 65 64 69 74 61 74 69 6f 6e 20 6f 6e 6c ccreditation onl
180c0 79 2e 20 20 49 74 20 77 6f 72 6b 73 20 6c 69 6b y. It works lik
180d0 65 20 45 78 70 72 53 65 74 50 72 6f 70 65 72 74 e ExprSetPropert
180e0 79 28 29 20 64 75 72 69 6e 67 20 56 56 41 0a 2a y() during VVA.*
180f0 2a 20 70 72 6f 63 65 73 73 65 73 20 62 75 74 20 * processes but
18100 69 73 20 61 20 6e 6f 2d 6f 70 20 66 6f 72 20 64 is a no-op for d
18110 65 6c 69 76 65 72 79 2e 0a 2a 2f 0a 23 69 66 64 elivery..*/.#ifd
18120 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a ef SQLITE_DEBUG.
18130 23 20 64 65 66 69 6e 65 20 45 78 70 72 53 65 74 # define ExprSet
18140 56 56 41 50 72 6f 70 65 72 74 79 28 45 2c 50 29 VVAProperty(E,P)
18150 20 20 28 45 29 2d 3e 66 6c 61 67 73 7c 3d 28 50 (E)->flags|=(P
18160 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ).#else.# define
18170 20 45 78 70 72 53 65 74 56 56 41 50 72 6f 70 65 ExprSetVVAPrope
18180 72 74 79 28 45 2c 50 29 0a 23 65 6e 64 69 66 0a rty(E,P).#endif.
18190 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f ./*.** Macros to
181a0 20 64 65 74 65 72 6d 69 6e 65 20 74 68 65 20 6e determine the n
181b0 75 6d 62 65 72 20 6f 66 20 62 79 74 65 73 20 72 umber of bytes r
181c0 65 71 75 69 72 65 64 20 62 79 20 61 20 6e 6f 72 equired by a nor
181d0 6d 61 6c 20 45 78 70 72 0a 2a 2a 20 73 74 72 75 mal Expr.** stru
181e0 63 74 2c 20 61 6e 20 45 78 70 72 20 73 74 72 75 ct, an Expr stru
181f0 63 74 20 77 69 74 68 20 74 68 65 20 45 50 5f 52 ct with the EP_R
18200 65 64 75 63 65 64 20 66 6c 61 67 20 73 65 74 20 educed flag set
18210 69 6e 20 45 78 70 72 2e 66 6c 61 67 73 0a 2a 2a in Expr.flags.**
18220 20 61 6e 64 20 61 6e 20 45 78 70 72 20 73 74 72 and an Expr str
18230 75 63 74 20 77 69 74 68 20 74 68 65 20 45 50 5f uct with the EP_
18240 54 6f 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 20 73 TokenOnly flag s
18250 65 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 et..*/.#define E
18260 58 50 52 5f 46 55 4c 4c 53 49 5a 45 20 20 20 20 XPR_FULLSIZE
18270 20 20 20 20 20 20 20 73 69 7a 65 6f 66 28 45 78 sizeof(Ex
18280 70 72 29 20 20 20 20 20 20 20 20 20 20 20 2f 2a pr) /*
18290 20 46 75 6c 6c 20 73 69 7a 65 20 2a 2f 0a 23 64 Full size */.#d
182a0 65 66 69 6e 65 20 45 58 50 52 5f 52 45 44 55 43 efine EXPR_REDUC
182b0 45 44 53 49 5a 45 20 20 20 20 20 20 20 20 6f 66 EDSIZE of
182c0 66 73 65 74 6f 66 28 45 78 70 72 2c 69 54 61 62 fsetof(Expr,iTab
182d0 6c 65 29 20 20 2f 2a 20 43 6f 6d 6d 6f 6e 20 66 le) /* Common f
182e0 65 61 74 75 72 65 73 20 2a 2f 0a 23 64 65 66 69 eatures */.#defi
182f0 6e 65 20 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c ne EXPR_TOKENONL
18300 59 53 49 5a 45 20 20 20 20 20 20 6f 66 66 73 65 YSIZE offse
18310 74 6f 66 28 45 78 70 72 2c 70 4c 65 66 74 29 20 tof(Expr,pLeft)
18320 20 20 2f 2a 20 46 65 77 65 72 20 66 65 61 74 75 /* Fewer featu
18330 72 65 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 46 6c res */../*.** Fl
18340 61 67 73 20 70 61 73 73 65 64 20 74 6f 20 74 68 ags passed to th
18350 65 20 73 71 6c 69 74 65 33 45 78 70 72 44 75 70 e sqlite3ExprDup
18360 28 29 20 66 75 6e 63 74 69 6f 6e 2e 20 53 65 65 () function. See
18370 20 74 68 65 20 68 65 61 64 65 72 20 63 6f 6d 6d the header comm
18380 65 6e 74 0a 2a 2a 20 61 62 6f 76 65 20 73 71 6c ent.** above sql
18390 69 74 65 33 45 78 70 72 44 75 70 28 29 20 66 6f ite3ExprDup() fo
183a0 72 20 64 65 74 61 69 6c 73 2e 0a 2a 2f 0a 23 64 r details..*/.#d
183b0 65 66 69 6e 65 20 45 58 50 52 44 55 50 5f 52 45 efine EXPRDUP_RE
183c0 44 55 43 45 20 20 20 20 20 20 20 20 20 30 78 30 DUCE 0x0
183d0 30 30 31 20 20 2f 2a 20 55 73 65 64 20 72 65 64 001 /* Used red
183e0 75 63 65 64 2d 73 69 7a 65 20 45 78 70 72 20 6e uced-size Expr n
183f0 6f 64 65 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 odes */../*.** A
18400 20 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 73 list of express
18410 69 6f 6e 73 2e 20 20 45 61 63 68 20 65 78 70 72 ions. Each expr
18420 65 73 73 69 6f 6e 20 6d 61 79 20 6f 70 74 69 6f ession may optio
18430 6e 61 6c 6c 79 20 68 61 76 65 20 61 0a 2a 2a 20 nally have a.**
18440 6e 61 6d 65 2e 20 20 41 6e 20 65 78 70 72 2f 6e name. An expr/n
18450 61 6d 65 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 ame combination
18460 63 61 6e 20 62 65 20 75 73 65 64 20 69 6e 20 73 can be used in s
18470 65 76 65 72 61 6c 20 77 61 79 73 2c 20 73 75 63 everal ways, suc
18480 68 0a 2a 2a 20 61 73 20 74 68 65 20 6c 69 73 74 h.** as the list
18490 20 6f 66 20 22 65 78 70 72 20 41 53 20 49 44 22 of "expr AS ID"
184a0 20 66 69 65 6c 64 73 20 66 6f 6c 6c 6f 77 69 6e fields followin
184b0 67 20 61 20 22 53 45 4c 45 43 54 22 20 6f 72 20 g a "SELECT" or
184c0 69 6e 20 74 68 65 0a 2a 2a 20 6c 69 73 74 20 6f in the.** list o
184d0 66 20 22 49 44 20 3d 20 65 78 70 72 22 20 69 74 f "ID = expr" it
184e0 65 6d 73 20 69 6e 20 61 6e 20 55 50 44 41 54 45 ems in an UPDATE
184f0 2e 20 20 41 20 6c 69 73 74 20 6f 66 20 65 78 70 . A list of exp
18500 72 65 73 73 69 6f 6e 73 20 63 61 6e 0a 2a 2a 20 ressions can.**
18510 61 6c 73 6f 20 62 65 20 75 73 65 64 20 61 73 20 also be used as
18520 74 68 65 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 the argument to
18530 61 20 66 75 6e 63 74 69 6f 6e 2c 20 69 6e 20 77 a function, in w
18540 68 69 63 68 20 63 61 73 65 20 74 68 65 20 61 2e hich case the a.
18550 7a 4e 61 6d 65 0a 2a 2a 20 66 69 65 6c 64 20 69 zName.** field i
18560 73 20 6e 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a s not used..**.*
18570 2a 20 42 79 20 64 65 66 61 75 6c 74 20 74 68 65 * By default the
18580 20 45 78 70 72 2e 7a 53 70 61 6e 20 66 69 65 6c Expr.zSpan fiel
18590 64 20 68 6f 6c 64 73 20 61 20 68 75 6d 61 6e 2d d holds a human-
185a0 72 65 61 64 61 62 6c 65 20 64 65 73 63 72 69 70 readable descrip
185b0 74 69 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 65 tion of.** the e
185c0 78 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 xpression that i
185d0 73 20 75 73 65 64 20 69 6e 20 74 68 65 20 67 65 s used in the ge
185e0 6e 65 72 61 74 69 6f 6e 20 6f 66 20 65 72 72 6f neration of erro
185f0 72 20 6d 65 73 73 61 67 65 73 20 61 6e 64 0a 2a r messages and.*
18600 2a 20 63 6f 6c 75 6d 6e 20 6c 61 62 65 6c 73 2e * column labels.
18610 20 20 49 6e 20 74 68 69 73 20 63 61 73 65 2c 20 In this case,
18620 45 78 70 72 2e 7a 53 70 61 6e 20 69 73 20 74 79 Expr.zSpan is ty
18630 70 69 63 61 6c 6c 79 20 74 68 65 20 74 65 78 74 pically the text
18640 20 6f 66 20 61 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 of a.** column
18650 65 78 70 72 65 73 73 69 6f 6e 20 61 73 20 69 74 expression as it
18660 20 65 78 69 73 74 73 20 69 6e 20 61 20 53 45 4c exists in a SEL
18670 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 ECT statement.
18680 48 6f 77 65 76 65 72 2c 20 69 66 0a 2a 2a 20 74 However, if.** t
18690 68 65 20 62 53 70 61 6e 49 73 54 61 62 20 66 6c he bSpanIsTab fl
186a0 61 67 20 69 73 20 73 65 74 2c 20 74 68 65 6e 20 ag is set, then
186b0 7a 53 70 61 6e 20 69 73 20 6f 76 65 72 6c 6f 61 zSpan is overloa
186c0 64 65 64 20 74 6f 20 6d 65 61 6e 20 74 68 65 20 ded to mean the
186d0 6e 61 6d 65 0a 2a 2a 20 6f 66 20 74 68 65 20 72 name.** of the r
186e0 65 73 75 6c 74 20 63 6f 6c 75 6d 6e 20 69 6e 20 esult column in
186f0 74 68 65 20 66 6f 72 6d 3a 20 44 41 54 41 42 41 the form: DATABA
18700 53 45 2e 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 2e SE.TABLE.COLUMN.
18710 20 20 54 68 69 73 20 6c 61 74 65 72 0a 2a 2a 20 This later.**
18720 66 6f 72 6d 20 69 73 20 75 73 65 64 20 66 6f 72 form is used for
18730 20 6e 61 6d 65 20 72 65 73 6f 6c 75 74 69 6f 6e name resolution
18740 20 77 69 74 68 20 6e 65 73 74 65 64 20 46 52 4f with nested FRO
18750 4d 20 63 6c 61 75 73 65 73 2e 0a 2a 2f 0a 73 74 M clauses..*/.st
18760 72 75 63 74 20 45 78 70 72 4c 69 73 74 20 7b 0a ruct ExprList {.
18770 20 20 69 6e 74 20 6e 45 78 70 72 3b 20 20 20 20 int nExpr;
18780 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
18790 65 72 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e er of expression
187a0 73 20 6f 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f s on the list */
187b0 0a 20 20 73 74 72 75 63 74 20 45 78 70 72 4c 69 . struct ExprLi
187c0 73 74 5f 69 74 65 6d 20 7b 20 2f 2a 20 46 6f 72 st_item { /* For
187d0 20 65 61 63 68 20 65 78 70 72 65 73 73 69 6f 6e each expression
187e0 20 69 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a in the list */.
187f0 20 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b Expr *pExpr;
18800 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
18810 68 65 20 6c 69 73 74 20 6f 66 20 65 78 70 72 65 he list of expre
18820 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 20 20 63 68 ssions */. ch
18830 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
18840 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 61 /* Token a
18850 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 ssociated with t
18860 68 69 73 20 65 78 70 72 65 73 73 69 6f 6e 20 2a his expression *
18870 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 53 70 61 /. char *zSpa
18880 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a n; /*
18890 20 4f 72 69 67 69 6e 61 6c 20 74 65 78 74 20 6f Original text o
188a0 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e f the expression
188b0 20 2a 2f 0a 20 20 20 20 75 38 20 73 6f 72 74 4f */. u8 sortO
188c0 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 20 20 rder;
188d0 2f 2a 20 31 20 66 6f 72 20 44 45 53 43 20 6f 72 /* 1 for DESC or
188e0 20 30 20 66 6f 72 20 41 53 43 20 2a 2f 0a 20 20 0 for ASC */.
188f0 20 20 75 6e 73 69 67 6e 65 64 20 64 6f 6e 65 20 unsigned done
18900 3a 31 3b 20 20 20 20 20 20 20 2f 2a 20 41 20 66 :1; /* A f
18910 6c 61 67 20 74 6f 20 69 6e 64 69 63 61 74 65 20 lag to indicate
18920 77 68 65 6e 20 70 72 6f 63 65 73 73 69 6e 67 20 when processing
18930 69 73 20 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 is finished */.
18940 20 20 20 75 6e 73 69 67 6e 65 64 20 62 53 70 61 unsigned bSpa
18950 6e 49 73 54 61 62 20 3a 31 3b 20 2f 2a 20 7a 53 nIsTab :1; /* zS
18960 70 61 6e 20 68 6f 6c 64 73 20 44 42 2e 54 41 42 pan holds DB.TAB
18970 4c 45 2e 43 4f 4c 55 4d 4e 20 2a 2f 0a 20 20 20 LE.COLUMN */.
18980 20 75 6e 73 69 67 6e 65 64 20 72 65 75 73 61 62 unsigned reusab
18990 6c 65 20 3a 31 3b 20 20 20 2f 2a 20 43 6f 6e 73 le :1; /* Cons
189a0 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 20 tant expression
189b0 69 73 20 72 65 75 73 61 62 6c 65 20 2a 2f 0a 20 is reusable */.
189c0 20 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 20 union {.
189d0 20 73 74 72 75 63 74 20 7b 0a 20 20 20 20 20 20 struct {.
189e0 20 20 75 31 36 20 69 4f 72 64 65 72 42 79 43 6f u16 iOrderByCo
189f0 6c 3b 20 20 20 20 20 20 2f 2a 20 46 6f 72 20 4f l; /* For O
18a00 52 44 45 52 20 42 59 2c 20 63 6f 6c 75 6d 6e 20 RDER BY, column
18a10 6e 75 6d 62 65 72 20 69 6e 20 72 65 73 75 6c 74 number in result
18a20 20 73 65 74 20 2a 2f 0a 20 20 20 20 20 20 20 20 set */.
18a30 75 31 36 20 69 41 6c 69 61 73 3b 20 20 20 20 20 u16 iAlias;
18a40 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 /* Index i
18a50 6e 74 6f 20 50 61 72 73 65 2e 61 41 6c 69 61 73 nto Parse.aAlias
18a60 5b 5d 20 66 6f 72 20 7a 4e 61 6d 65 20 2a 2f 0a [] for zName */.
18a70 20 20 20 20 20 20 7d 20 78 3b 0a 20 20 20 20 20 } x;.
18a80 20 69 6e 74 20 69 43 6f 6e 73 74 45 78 70 72 52 int iConstExprR
18a90 65 67 3b 20 20 20 20 20 20 2f 2a 20 52 65 67 69 eg; /* Regi
18aa0 73 74 65 72 20 69 6e 20 77 68 69 63 68 20 45 78 ster in which Ex
18ab0 70 72 20 76 61 6c 75 65 20 69 73 20 63 61 63 68 pr value is cach
18ac0 65 64 20 2a 2f 0a 20 20 20 20 7d 20 75 3b 0a 20 ed */. } u;.
18ad0 20 7d 20 2a 61 3b 20 20 20 20 20 20 20 20 20 20 } *a;
18ae0 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 /* Alloc
18af0 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f 20 a power of two
18b00 67 72 65 61 74 65 72 20 6f 72 20 65 71 75 61 6c greater or equal
18b10 20 74 6f 20 6e 45 78 70 72 20 2a 2f 0a 7d 3b 0a to nExpr */.};.
18b20 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
18b30 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ce of this struc
18b40 74 75 72 65 20 69 73 20 75 73 65 64 20 62 79 20 ture is used by
18b50 74 68 65 20 70 61 72 73 65 72 20 74 6f 20 72 65 the parser to re
18b60 63 6f 72 64 20 62 6f 74 68 0a 2a 2a 20 74 68 65 cord both.** the
18b70 20 70 61 72 73 65 20 74 72 65 65 20 66 6f 72 20 parse tree for
18b80 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 61 6e an expression an
18b90 64 20 74 68 65 20 73 70 61 6e 20 6f 66 20 69 6e d the span of in
18ba0 70 75 74 20 74 65 78 74 20 66 6f 72 20 61 6e 0a put text for an.
18bb0 2a 2a 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a ** expression..*
18bc0 2f 0a 73 74 72 75 63 74 20 45 78 70 72 53 70 61 /.struct ExprSpa
18bd0 6e 20 7b 0a 20 20 45 78 70 72 20 2a 70 45 78 70 n {. Expr *pExp
18be0 72 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 r; /* T
18bf0 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 70 61 he expression pa
18c00 72 73 65 20 74 72 65 65 20 2a 2f 0a 20 20 63 6f rse tree */. co
18c10 6e 73 74 20 63 68 61 72 20 2a 7a 53 74 61 72 74 nst char *zStart
18c20 3b 20 20 20 2f 2a 20 46 69 72 73 74 20 63 68 61 ; /* First cha
18c30 72 61 63 74 65 72 20 6f 66 20 69 6e 70 75 74 20 racter of input
18c40 74 65 78 74 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 text */. const
18c50 63 68 61 72 20 2a 7a 45 6e 64 3b 20 20 20 20 20 char *zEnd;
18c60 2f 2a 20 4f 6e 65 20 63 68 61 72 61 63 74 65 72 /* One character
18c70 20 70 61 73 74 20 74 68 65 20 65 6e 64 20 6f 66 past the end of
18c80 20 69 6e 70 75 74 20 74 65 78 74 20 2a 2f 0a 7d input text */.}
18c90 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 ;../*.** An inst
18ca0 61 6e 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 ance of this str
18cb0 75 63 74 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 ucture can hold
18cc0 61 20 73 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 a simple list of
18cd0 20 69 64 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a identifiers,.**
18ce0 20 73 75 63 68 20 61 73 20 74 68 65 20 6c 69 73 such as the lis
18cf0 74 20 22 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 t "a,b,c" in the
18d00 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 following state
18d10 6d 65 6e 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 ments:.**.**
18d20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 INSERT INTO t(
18d30 61 2c 62 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e a,b,c) VALUES ..
18d40 2e 3b 0a 2a 2a 20 20 20 20 20 20 43 52 45 41 54 .;.** CREAT
18d50 45 20 49 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 E INDEX idx ON t
18d60 28 61 2c 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 (a,b,c);.**
18d70 20 43 52 45 41 54 45 20 54 52 49 47 47 45 52 20 CREATE TRIGGER
18d80 74 72 69 67 20 42 45 46 4f 52 45 20 55 50 44 41 trig BEFORE UPDA
18d90 54 45 20 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e TE ON t(a,b,c) .
18da0 2e 2e 3b 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 ..;.**.** The Id
18db0 4c 69 73 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 List.a.idx field
18dc0 20 69 73 20 75 73 65 64 20 77 68 65 6e 20 74 68 is used when th
18dd0 65 20 49 64 4c 69 73 74 20 72 65 70 72 65 73 65 e IdList represe
18de0 6e 74 73 20 74 68 65 20 6c 69 73 74 20 6f 66 0a nts the list of.
18df0 2a 2a 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 ** column names
18e00 61 66 74 65 72 20 61 20 74 61 62 6c 65 20 6e 61 after a table na
18e10 6d 65 20 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 me in an INSERT
18e20 73 74 61 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 statement. In t
18e30 68 65 20 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a he statement.**.
18e40 2a 2a 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e ** INSERT IN
18e50 54 4f 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a TO t(a,b,c) ....
18e60 2a 2a 0a 2a 2a 20 49 66 20 22 61 22 20 69 73 20 **.** If "a" is
18e70 74 68 65 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 the k-th column
18e80 6f 66 20 74 61 62 6c 65 20 22 74 22 2c 20 74 68 of table "t", th
18e90 65 6e 20 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 en IdList.a[0].i
18ea0 64 78 3d 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 dx==k..*/.struct
18eb0 20 49 64 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 IdList {. stru
18ec0 63 74 20 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b ct IdList_item {
18ed0 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 . char *zName
18ee0 3b 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f ; /* Name o
18ef0 66 20 74 68 65 20 69 64 65 6e 74 69 66 69 65 72 f the identifier
18f00 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 64 78 3b */. int idx;
18f10 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 /* Ind
18f20 65 78 20 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 ex in some Table
18f30 2e 61 43 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c .aCol[] of a col
18f40 75 6d 6e 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 umn named zName
18f50 2a 2f 0a 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 */. } *a;. int
18f60 20 6e 49 64 3b 20 20 20 20 20 20 20 20 20 2f 2a nId; /*
18f70 20 4e 75 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 Number of ident
18f80 69 66 69 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 ifiers on the li
18f90 73 74 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 st */.};../*.**
18fa0 54 68 65 20 62 69 74 6d 61 73 6b 20 64 61 74 61 The bitmask data
18fb0 74 79 70 65 20 64 65 66 69 6e 65 64 20 62 65 6c type defined bel
18fc0 6f 77 20 69 73 20 75 73 65 64 20 66 6f 72 20 76 ow is used for v
18fd0 61 72 69 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 arious optimizat
18fe0 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e ions..**.** Chan
18ff0 67 69 6e 67 20 74 68 69 73 20 66 72 6f 6d 20 61 ging this from a
19000 20 36 34 2d 62 69 74 20 74 6f 20 61 20 33 32 2d 64-bit to a 32-
19010 62 69 74 20 74 79 70 65 20 6c 69 6d 69 74 73 20 bit type limits
19020 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 0a 2a 2a the number of.**
19030 20 74 61 62 6c 65 73 20 69 6e 20 61 20 6a 6f 69 tables in a joi
19040 6e 20 74 6f 20 33 32 20 69 6e 73 74 65 61 64 20 n to 32 instead
19050 6f 66 20 36 34 2e 20 20 42 75 74 20 69 74 20 61 of 64. But it a
19060 6c 73 6f 20 72 65 64 75 63 65 73 20 74 68 65 20 lso reduces the
19070 73 69 7a 65 0a 2a 2a 20 6f 66 20 74 68 65 20 6c size.** of the l
19080 69 62 72 61 72 79 20 62 79 20 37 33 38 20 62 79 ibrary by 738 by
19090 74 65 73 20 6f 6e 20 69 78 38 36 2e 0a 2a 2f 0a tes on ix86..*/.
190a0 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 42 49 #ifdef SQLITE_BI
190b0 54 4d 41 53 4b 5f 54 59 50 45 0a 20 20 74 79 70 TMASK_TYPE. typ
190c0 65 64 65 66 20 53 51 4c 49 54 45 5f 42 49 54 4d edef SQLITE_BITM
190d0 41 53 4b 5f 54 59 50 45 20 42 69 74 6d 61 73 6b ASK_TYPE Bitmask
190e0 3b 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 64 65 ;.#else. typede
190f0 66 20 75 36 34 20 42 69 74 6d 61 73 6b 3b 0a 23 f u64 Bitmask;.#
19100 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
19110 20 6e 75 6d 62 65 72 20 6f 66 20 62 69 74 73 20 number of bits
19120 69 6e 20 61 20 42 69 74 6d 61 73 6b 2e 20 20 22 in a Bitmask. "
19130 42 4d 53 22 20 6d 65 61 6e 73 20 22 42 69 74 4d BMS" means "BitM
19140 61 73 6b 20 53 69 7a 65 22 2e 0a 2a 2f 0a 23 64 ask Size"..*/.#d
19150 65 66 69 6e 65 20 42 4d 53 20 20 28 28 69 6e 74 efine BMS ((int
19160 29 28 73 69 7a 65 6f 66 28 42 69 74 6d 61 73 6b )(sizeof(Bitmask
19170 29 2a 38 29 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 62 )*8))../*.** A b
19180 69 74 20 69 6e 20 61 20 42 69 74 6d 61 73 6b 0a it in a Bitmask.
19190 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 4b 42 */.#define MASKB
191a0 49 54 28 6e 29 20 20 20 28 28 28 42 69 74 6d 61 IT(n) (((Bitma
191b0 73 6b 29 31 29 3c 3c 28 6e 29 29 0a 23 64 65 66 sk)1)<<(n)).#def
191c0 69 6e 65 20 4d 41 53 4b 42 49 54 33 32 28 6e 29 ine MASKBIT32(n)
191d0 20 28 28 28 75 6e 73 69 67 6e 65 64 20 69 6e 74 (((unsigned int
191e0 29 31 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e )1)<<(n)).#defin
191f0 65 20 41 4c 4c 42 49 54 53 20 20 20 20 20 20 28 e ALLBITS (
19200 28 42 69 74 6d 61 73 6b 29 2d 31 29 0a 0a 2f 2a (Bitmask)-1)../*
19210 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e .** The followin
19220 67 20 73 74 72 75 63 74 75 72 65 20 64 65 73 63 g structure desc
19230 72 69 62 65 73 20 74 68 65 20 46 52 4f 4d 20 63 ribes the FROM c
19240 6c 61 75 73 65 20 6f 66 20 61 20 53 45 4c 45 43 lause of a SELEC
19250 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 20 T statement..**
19260 45 61 63 68 20 74 61 62 6c 65 20 6f 72 20 73 75 Each table or su
19270 62 71 75 65 72 79 20 69 6e 20 74 68 65 20 46 52 bquery in the FR
19280 4f 4d 20 63 6c 61 75 73 65 20 69 73 20 61 20 73 OM clause is a s
19290 65 70 61 72 61 74 65 20 65 6c 65 6d 65 6e 74 20 eparate element
192a0 6f 66 0a 2a 2a 20 74 68 65 20 53 72 63 4c 69 73 of.** the SrcLis
192b0 74 2e 61 5b 5d 20 61 72 72 61 79 2e 0a 2a 2a 0a t.a[] array..**.
192c0 2a 2a 20 57 69 74 68 20 74 68 65 20 61 64 64 69 ** With the addi
192d0 74 69 6f 6e 20 6f 66 20 6d 75 6c 74 69 70 6c 65 tion of multiple
192e0 20 64 61 74 61 62 61 73 65 20 73 75 70 70 6f 72 database suppor
192f0 74 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 t, the following
19300 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 63 61 structure.** ca
19310 6e 20 61 6c 73 6f 20 62 65 20 75 73 65 64 20 74 n also be used t
19320 6f 20 64 65 73 63 72 69 62 65 20 61 20 70 61 72 o describe a par
19330 74 69 63 75 6c 61 72 20 74 61 62 6c 65 20 73 75 ticular table su
19340 63 68 20 61 73 20 74 68 65 20 74 61 62 6c 65 20 ch as the table
19350 74 68 61 74 0a 2a 2a 20 69 73 20 6d 6f 64 69 66 that.** is modif
19360 69 65 64 20 62 79 20 61 6e 20 49 4e 53 45 52 54 ied by an INSERT
19370 2c 20 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 , DELETE, or UPD
19380 41 54 45 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 ATE statement.
19390 49 6e 20 73 74 61 6e 64 61 72 64 20 53 51 4c 2c In standard SQL,
193a0 0a 2a 2a 20 73 75 63 68 20 61 20 74 61 62 6c 65 .** such a table
193b0 20 6d 75 73 74 20 62 65 20 61 20 73 69 6d 70 6c must be a simpl
193c0 65 20 6e 61 6d 65 3a 20 49 44 2e 20 20 42 75 74 e name: ID. But
193d0 20 69 6e 20 53 51 4c 69 74 65 2c 20 74 68 65 20 in SQLite, the
193e0 74 61 62 6c 65 20 63 61 6e 0a 2a 2a 20 6e 6f 77 table can.** now
193f0 20 62 65 20 69 64 65 6e 74 69 66 69 65 64 20 62 be identified b
19400 79 20 61 20 64 61 74 61 62 61 73 65 20 6e 61 6d y a database nam
19410 65 2c 20 61 20 64 6f 74 2c 20 74 68 65 6e 20 74 e, a dot, then t
19420 68 65 20 74 61 62 6c 65 20 6e 61 6d 65 3a 20 49 he table name: I
19430 44 2e 49 44 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 D.ID..**.** The
19440 6a 6f 69 6e 74 79 70 65 20 73 74 61 72 74 73 20 jointype starts
19450 6f 75 74 20 73 68 6f 77 69 6e 67 20 74 68 65 20 out showing the
19460 6a 6f 69 6e 20 74 79 70 65 20 62 65 74 77 65 65 join type betwee
19470 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 61 n the current ta
19480 62 6c 65 0a 2a 2a 20 61 6e 64 20 74 68 65 20 6e ble.** and the n
19490 65 78 74 20 74 61 62 6c 65 20 6f 6e 20 74 68 65 ext table on the
194a0 20 6c 69 73 74 2e 20 20 54 68 65 20 70 61 72 73 list. The pars
194b0 65 72 20 62 75 69 6c 64 73 20 74 68 65 20 6c 69 er builds the li
194c0 73 74 20 74 68 69 73 20 77 61 79 2e 0a 2a 2a 20 st this way..**
194d0 42 75 74 20 73 71 6c 69 74 65 33 53 72 63 4c 69 But sqlite3SrcLi
194e0 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 70 65 28 stShiftJoinType(
194f0 29 20 6c 61 74 65 72 20 73 68 69 66 74 73 20 74 ) later shifts t
19500 68 65 20 6a 6f 69 6e 74 79 70 65 73 20 73 6f 20 he jointypes so
19510 74 68 61 74 20 65 61 63 68 0a 2a 2a 20 6a 6f 69 that each.** joi
19520 6e 74 79 70 65 20 65 78 70 72 65 73 73 65 73 20 ntype expresses
19530 74 68 65 20 6a 6f 69 6e 20 62 65 74 77 65 65 6e the join between
19540 20 74 68 65 20 74 61 62 6c 65 20 61 6e 64 20 74 the table and t
19550 68 65 20 70 72 65 76 69 6f 75 73 20 74 61 62 6c he previous tabl
19560 65 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 e..**.** In the
19570 63 6f 6c 55 73 65 64 20 66 69 65 6c 64 2c 20 74 colUsed field, t
19580 68 65 20 68 69 67 68 2d 6f 72 64 65 72 20 62 69 he high-order bi
19590 74 20 28 62 69 74 20 36 33 29 20 69 73 20 73 65 t (bit 63) is se
195a0 74 20 69 66 20 74 68 65 20 74 61 62 6c 65 0a 2a t if the table.*
195b0 2a 20 63 6f 6e 74 61 69 6e 73 20 6d 6f 72 65 20 * contains more
195c0 74 68 61 6e 20 36 33 20 63 6f 6c 75 6d 6e 73 20 than 63 columns
195d0 61 6e 64 20 74 68 65 20 36 34 2d 74 68 20 6f 72 and the 64-th or
195e0 20 6c 61 74 65 72 20 63 6f 6c 75 6d 6e 20 69 73 later column is
195f0 20 75 73 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 used..*/.struct
19600 20 53 72 63 4c 69 73 74 20 7b 0a 20 20 69 6e 74 SrcList {. int
19610 20 6e 53 72 63 3b 20 20 20 20 20 20 20 20 2f 2a nSrc; /*
19620 20 4e 75 6d 62 65 72 20 6f 66 20 74 61 62 6c 65 Number of table
19630 73 20 6f 72 20 73 75 62 71 75 65 72 69 65 73 20 s or subqueries
19640 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 in the FROM clau
19650 73 65 20 2a 2f 0a 20 20 75 33 32 20 6e 41 6c 6c se */. u32 nAll
19660 6f 63 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 oc; /* Numb
19670 65 72 20 6f 66 20 65 6e 74 72 69 65 73 20 61 6c er of entries al
19680 6c 6f 63 61 74 65 64 20 69 6e 20 61 5b 5d 20 62 located in a[] b
19690 65 6c 6f 77 20 2a 2f 0a 20 20 73 74 72 75 63 74 elow */. struct
196a0 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 7b 0a SrcList_item {.
196b0 20 20 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 Schema *pSch
196c0 65 6d 61 3b 20 20 2f 2a 20 53 63 68 65 6d 61 20 ema; /* Schema
196d0 74 6f 20 77 68 69 63 68 20 74 68 69 73 20 69 74 to which this it
196e0 65 6d 20 69 73 20 66 69 78 65 64 20 2a 2f 0a 20 em is fixed */.
196f0 20 20 20 63 68 61 72 20 2a 7a 44 61 74 61 62 61 char *zDataba
19700 73 65 3b 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 se; /* Name of
19710 64 61 74 61 62 61 73 65 20 68 6f 6c 64 69 6e 67 database holding
19720 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a 20 this table */.
19730 20 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 char *zName;
19740 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
19750 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 the table */.
19760 20 63 68 61 72 20 2a 7a 41 6c 69 61 73 3b 20 20 char *zAlias;
19770 20 20 20 2f 2a 20 54 68 65 20 22 42 22 20 70 61 /* The "B" pa
19780 72 74 20 6f 66 20 61 20 22 41 20 41 53 20 42 22 rt of a "A AS B"
19790 20 70 68 72 61 73 65 2e 20 20 7a 4e 61 6d 65 20 phrase. zName
197a0 69 73 20 74 68 65 20 22 41 22 20 2a 2f 0a 20 20 is the "A" */.
197b0 20 20 54 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 Table *pTab;
197c0 20 20 20 20 2f 2a 20 41 6e 20 53 51 4c 20 74 61 /* An SQL ta
197d0 62 6c 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e ble correspondin
197e0 67 20 74 6f 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 g to zName */.
197f0 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 Select *pSelec
19800 74 3b 20 20 2f 2a 20 41 20 53 45 4c 45 43 54 20 t; /* A SELECT
19810 73 74 61 74 65 6d 65 6e 74 20 75 73 65 64 20 69 statement used i
19820 6e 20 70 6c 61 63 65 20 6f 66 20 61 20 74 61 62 n place of a tab
19830 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 69 le name */. i
19840 6e 74 20 61 64 64 72 46 69 6c 6c 53 75 62 3b 20 nt addrFillSub;
19850 20 2f 2a 20 41 64 64 72 65 73 73 20 6f 66 20 73 /* Address of s
19860 75 62 72 6f 75 74 69 6e 65 20 74 6f 20 6d 61 6e ubroutine to man
19870 69 66 65 73 74 20 61 20 73 75 62 71 75 65 72 79 ifest a subquery
19880 20 2a 2f 0a 20 20 20 20 69 6e 74 20 72 65 67 52 */. int regR
19890 65 74 75 72 6e 3b 20 20 20 20 2f 2a 20 52 65 67 eturn; /* Reg
198a0 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 65 ister holding re
198b0 74 75 72 6e 20 61 64 64 72 65 73 73 20 6f 66 20 turn address of
198c0 61 64 64 72 46 69 6c 6c 53 75 62 20 2a 2f 0a 20 addrFillSub */.
198d0 20 20 20 69 6e 74 20 72 65 67 52 65 73 75 6c 74 int regResult
198e0 3b 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 ; /* Register
198f0 73 20 68 6f 6c 64 69 6e 67 20 72 65 73 75 6c 74 s holding result
19900 73 20 6f 66 20 61 20 63 6f 2d 72 6f 75 74 69 6e s of a co-routin
19910 65 20 2a 2f 0a 20 20 20 20 73 74 72 75 63 74 20 e */. struct
19920 7b 0a 20 20 20 20 20 20 75 38 20 6a 6f 69 6e 74 {. u8 joint
19930 79 70 65 3b 20 20 20 20 20 20 2f 2a 20 54 79 70 ype; /* Typ
19940 65 20 6f 66 20 6a 6f 69 6e 20 62 65 74 77 65 65 e of join betwee
19950 6e 20 74 68 69 73 20 74 61 62 6c 65 20 61 6e 64 n this table and
19960 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 2a 2f the previous */
19970 0a 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 . unsigned
19980 6e 6f 74 49 6e 64 65 78 65 64 20 3a 31 3b 20 20 notIndexed :1;
19990 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 /* True if the
199a0 72 65 20 69 73 20 61 20 4e 4f 54 20 49 4e 44 45 re is a NOT INDE
199b0 58 45 44 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 XED clause */.
199c0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 73 49 unsigned isI
199d0 6e 64 65 78 65 64 42 79 20 3a 31 3b 20 20 20 2f ndexedBy :1; /
199e0 2a 20 54 72 75 65 20 69 66 20 74 68 65 72 65 20 * True if there
199f0 69 73 20 61 6e 20 49 4e 44 45 58 45 44 20 42 59 is an INDEXED BY
19a00 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 clause */.
19a10 20 75 6e 73 69 67 6e 65 64 20 69 73 54 61 62 46 unsigned isTabF
19a20 75 6e 63 20 3a 31 3b 20 20 20 20 20 2f 2a 20 54 unc :1; /* T
19a30 72 75 65 20 69 66 20 74 61 62 6c 65 2d 76 61 6c rue if table-val
19a40 75 65 64 2d 66 75 6e 63 74 69 6f 6e 20 73 79 6e ued-function syn
19a50 74 61 78 20 2a 2f 0a 20 20 20 20 20 20 75 6e 73 tax */. uns
19a60 69 67 6e 65 64 20 69 73 43 6f 72 72 65 6c 61 74 igned isCorrelat
19a70 65 64 20 3a 31 3b 20 20 2f 2a 20 54 72 75 65 20 ed :1; /* True
19a80 69 66 20 73 75 62 2d 71 75 65 72 79 20 69 73 20 if sub-query is
19a90 63 6f 72 72 65 6c 61 74 65 64 20 2a 2f 0a 20 20 correlated */.
19aa0 20 20 20 20 75 6e 73 69 67 6e 65 64 20 76 69 61 unsigned via
19ab0 43 6f 72 6f 75 74 69 6e 65 20 3a 31 3b 20 20 2f Coroutine :1; /
19ac0 2a 20 49 6d 70 6c 65 6d 65 6e 74 65 64 20 61 73 * Implemented as
19ad0 20 61 20 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f a co-routine */
19ae0 0a 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 20 . unsigned
19af0 69 73 52 65 63 75 72 73 69 76 65 20 3a 31 3b 20 isRecursive :1;
19b00 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 72 65 /* True for re
19b10 63 75 72 73 69 76 65 20 72 65 66 65 72 65 6e 63 cursive referenc
19b20 65 20 69 6e 20 57 49 54 48 20 2a 2f 0a 20 20 20 e in WITH */.
19b30 20 7d 20 66 67 3b 0a 23 69 66 6e 64 65 66 20 53 } fg;.#ifndef S
19b40 51 4c 49 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 QLITE_OMIT_EXPLA
19b50 49 4e 0a 20 20 20 20 75 38 20 69 53 65 6c 65 63 IN. u8 iSelec
19b60 74 49 64 3b 20 20 20 20 20 2f 2a 20 49 66 20 70 tId; /* If p
19b70 53 65 6c 65 63 74 21 3d 30 2c 20 74 68 65 20 69 Select!=0, the i
19b80 64 20 6f 66 20 74 68 65 20 73 75 62 2d 73 65 6c d of the sub-sel
19b90 65 63 74 20 69 6e 20 45 51 50 20 2a 2f 0a 23 65 ect in EQP */.#e
19ba0 6e 64 69 66 0a 20 20 20 20 69 6e 74 20 69 43 75 ndif. int iCu
19bb0 72 73 6f 72 3b 20 20 20 20 20 20 2f 2a 20 54 68 rsor; /* Th
19bc0 65 20 56 44 42 45 20 63 75 72 73 6f 72 20 6e 75 e VDBE cursor nu
19bd0 6d 62 65 72 20 75 73 65 64 20 74 6f 20 61 63 63 mber used to acc
19be0 65 73 73 20 74 68 69 73 20 74 61 62 6c 65 20 2a ess this table *
19bf0 2f 0a 20 20 20 20 45 78 70 72 20 2a 70 4f 6e 3b /. Expr *pOn;
19c00 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 4f /* The O
19c10 4e 20 63 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f N clause of a jo
19c20 69 6e 20 2a 2f 0a 20 20 20 20 49 64 4c 69 73 74 in */. IdList
19c30 20 2a 70 55 73 69 6e 67 3b 20 20 20 2f 2a 20 54 *pUsing; /* T
19c40 68 65 20 55 53 49 4e 47 20 63 6c 61 75 73 65 20 he USING clause
19c50 6f 66 20 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 of a join */.
19c60 20 42 69 74 6d 61 73 6b 20 63 6f 6c 55 73 65 64 Bitmask colUsed
19c70 3b 20 20 2f 2a 20 42 69 74 20 4e 20 28 31 3c 3c ; /* Bit N (1<<
19c80 4e 29 20 73 65 74 20 69 66 20 63 6f 6c 75 6d 6e N) set if column
19c90 20 4e 20 6f 66 20 70 54 61 62 20 69 73 20 75 73 N of pTab is us
19ca0 65 64 20 2a 2f 0a 20 20 20 20 75 6e 69 6f 6e 20 ed */. union
19cb0 7b 0a 20 20 20 20 20 20 63 68 61 72 20 2a 7a 49 {. char *zI
19cc0 6e 64 65 78 65 64 42 79 3b 20 20 20 20 2f 2a 20 ndexedBy; /*
19cd0 49 64 65 6e 74 69 66 69 65 72 20 66 72 6f 6d 20 Identifier from
19ce0 22 49 4e 44 45 58 45 44 20 42 59 20 3c 7a 49 6e "INDEXED BY <zIn
19cf0 64 65 78 3e 22 20 63 6c 61 75 73 65 20 2a 2f 0a dex>" clause */.
19d00 20 20 20 20 20 20 45 78 70 72 4c 69 73 74 20 2a ExprList *
19d10 70 46 75 6e 63 41 72 67 3b 20 20 2f 2a 20 41 72 pFuncArg; /* Ar
19d20 67 75 6d 65 6e 74 73 20 74 6f 20 74 61 62 6c 65 guments to table
19d30 2d 76 61 6c 75 65 64 2d 66 75 6e 63 74 69 6f 6e -valued-function
19d40 20 2a 2f 0a 20 20 20 20 7d 20 75 31 3b 0a 20 20 */. } u1;.
19d50 20 20 49 6e 64 65 78 20 2a 70 49 42 49 6e 64 65 Index *pIBInde
19d60 78 3b 20 20 2f 2a 20 49 6e 64 65 78 20 73 74 72 x; /* Index str
19d70 75 63 74 75 72 65 20 63 6f 72 72 65 73 70 6f 6e ucture correspon
19d80 64 69 6e 67 20 74 6f 20 75 31 2e 7a 49 6e 64 65 ding to u1.zInde
19d90 78 65 64 42 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 xedBy */. } a[1
19da0 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ]; /
19db0 2a 20 4f 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 * One entry for
19dc0 65 61 63 68 20 69 64 65 6e 74 69 66 69 65 72 20 each identifier
19dd0 6f 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d on the list */.}
19de0 3b 0a 0a 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 ;../*.** Permitt
19df0 65 64 20 76 61 6c 75 65 73 20 6f 66 20 74 68 65 ed values of the
19e00 20 53 72 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 SrcList.a.joint
19e10 79 70 65 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 ype field.*/.#de
19e20 66 69 6e 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 fine JT_INNER
19e30 20 20 30 78 30 30 30 31 20 20 20 20 2f 2a 20 41 0x0001 /* A
19e40 6e 79 20 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 ny kind of inner
19e50 20 6f 72 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a or cross join *
19e60 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f /.#define JT_CRO
19e70 53 53 20 20 20 20 20 30 78 30 30 30 32 20 20 20 SS 0x0002
19e80 20 2f 2a 20 45 78 70 6c 69 63 69 74 20 75 73 65 /* Explicit use
19e90 20 6f 66 20 74 68 65 20 43 52 4f 53 53 20 6b 65 of the CROSS ke
19ea0 79 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 yword */.#define
19eb0 20 4a 54 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 JT_NATURAL 0x
19ec0 30 30 30 34 20 20 20 20 2f 2a 20 54 72 75 65 20 0004 /* True
19ed0 66 6f 72 20 61 20 22 6e 61 74 75 72 61 6c 22 20 for a "natural"
19ee0 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 join */.#define
19ef0 4a 54 5f 4c 45 46 54 20 20 20 20 20 20 30 78 30 JT_LEFT 0x0
19f00 30 30 38 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 008 /* Left o
19f10 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 uter join */.#de
19f20 66 69 6e 65 20 4a 54 5f 52 49 47 48 54 20 20 20 fine JT_RIGHT
19f30 20 20 30 78 30 30 31 30 20 20 20 20 2f 2a 20 52 0x0010 /* R
19f40 69 67 68 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 ight outer join
19f50 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 */.#define JT_OU
19f60 54 45 52 20 20 20 20 20 30 78 30 30 32 30 20 20 TER 0x0020
19f70 20 20 2f 2a 20 54 68 65 20 22 4f 55 54 45 52 22 /* The "OUTER"
19f80 20 6b 65 79 77 6f 72 64 20 69 73 20 70 72 65 73 keyword is pres
19f90 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a ent */.#define J
19fa0 54 5f 45 52 52 4f 52 20 20 20 20 20 30 78 30 30 T_ERROR 0x00
19fb0 34 30 20 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 40 /* unknown
19fc0 20 6f 72 20 75 6e 73 75 70 70 6f 72 74 65 64 20 or unsupported
19fd0 6a 6f 69 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f join type */.../
19fe0 2a 0a 2a 2a 20 46 6c 61 67 73 20 61 70 70 72 6f *.** Flags appro
19ff0 70 72 69 61 74 65 20 66 6f 72 20 74 68 65 20 77 priate for the w
1a000 63 74 72 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 ctrlFlags parame
1a010 74 65 72 20 6f 66 20 73 71 6c 69 74 65 33 57 68 ter of sqlite3Wh
1a020 65 72 65 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e ereBegin().** an
1a030 64 20 74 68 65 20 57 68 65 72 65 49 6e 66 6f 2e d the WhereInfo.
1a040 77 63 74 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 wctrlFlags membe
1a050 72 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 20 63 r..**.** Value c
1a060 6f 6e 73 74 72 61 69 6e 74 73 20 28 65 6e 66 6f onstraints (enfo
1a070 72 63 65 64 20 76 69 61 20 61 73 73 65 72 74 28 rced via assert(
1a080 29 29 3a 0a 2a 2a 20 20 20 20 20 57 48 45 52 45 )):.** WHERE
1a090 5f 55 53 45 5f 4c 49 4d 49 54 20 20 3d 3d 20 53 _USE_LIMIT == S
1a0a0 46 5f 46 69 78 65 64 4c 69 6d 69 74 0a 2a 2f 0a F_FixedLimit.*/.
1a0b0 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 52 #define WHERE_OR
1a0c0 44 45 52 42 59 5f 4e 4f 52 4d 41 4c 20 20 20 30 DERBY_NORMAL 0
1a0d0 78 30 30 30 30 20 2f 2a 20 4e 6f 2d 6f 70 20 2a x0000 /* No-op *
1a0e0 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
1a0f0 4f 52 44 45 52 42 59 5f 4d 49 4e 20 20 20 20 20 ORDERBY_MIN
1a100 20 30 78 30 30 30 31 20 2f 2a 20 4f 52 44 45 52 0x0001 /* ORDER
1a110 20 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 BY processing f
1a120 6f 72 20 6d 69 6e 28 29 20 66 75 6e 63 20 2a 2f or min() func */
1a130 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f .#define WHERE_O
1a140 52 44 45 52 42 59 5f 4d 41 58 20 20 20 20 20 20 RDERBY_MAX
1a150 30 78 30 30 30 32 20 2f 2a 20 4f 52 44 45 52 20 0x0002 /* ORDER
1a160 42 59 20 70 72 6f 63 65 73 73 69 6e 67 20 66 6f BY processing fo
1a170 72 20 6d 61 78 28 29 20 66 75 6e 63 20 2a 2f 0a r max() func */.
1a180 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e #define WHERE_ON
1a190 45 50 41 53 53 5f 44 45 53 49 52 45 44 20 20 30 EPASS_DESIRED 0
1a1a0 78 30 30 30 34 20 2f 2a 20 57 61 6e 74 20 74 6f x0004 /* Want to
1a1b0 20 64 6f 20 6f 6e 65 2d 70 61 73 73 20 55 50 44 do one-pass UPD
1a1c0 41 54 45 2f 44 45 4c 45 54 45 20 2a 2f 0a 23 64 ATE/DELETE */.#d
1a1d0 65 66 69 6e 65 20 57 48 45 52 45 5f 4f 4e 45 50 efine WHERE_ONEP
1a1e0 41 53 53 5f 4d 55 4c 54 49 52 4f 57 20 30 78 30 ASS_MULTIROW 0x0
1a1f0 30 30 38 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 008 /* ONEPASS i
1a200 73 20 6f 6b 20 77 69 74 68 20 6d 75 6c 74 69 70 s ok with multip
1a210 6c 65 20 72 6f 77 73 20 2a 2f 0a 23 64 65 66 69 le rows */.#defi
1a220 6e 65 20 57 48 45 52 45 5f 44 55 50 4c 49 43 41 ne WHERE_DUPLICA
1a230 54 45 53 5f 4f 4b 20 20 20 20 30 78 30 30 31 30 TES_OK 0x0010
1a240 20 2f 2a 20 4f 6b 20 74 6f 20 72 65 74 75 72 6e /* Ok to return
1a250 20 61 20 72 6f 77 20 6d 6f 72 65 20 74 68 61 6e a row more than
1a260 20 6f 6e 63 65 20 2a 2f 0a 23 64 65 66 69 6e 65 once */.#define
1a270 20 57 48 45 52 45 5f 4f 52 5f 53 55 42 43 4c 41 WHERE_OR_SUBCLA
1a280 55 53 45 20 20 20 20 20 30 78 30 30 32 30 20 2f USE 0x0020 /
1a290 2a 20 50 72 6f 63 65 73 73 69 6e 67 20 61 20 73 * Processing a s
1a2a0 75 62 2d 57 48 45 52 45 20 61 73 20 70 61 72 74 ub-WHERE as part
1a2b0 20 6f 66 0a 20 20 20 20 20 20 20 20 20 20 20 20 of.
1a2c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a2d0 20 20 20 20 20 20 20 20 20 20 2a 2a 20 74 68 65 ** the
1a2e0 20 4f 52 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e OR optimization
1a2f0 20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 */.#define WHE
1a300 52 45 5f 47 52 4f 55 50 42 59 20 20 20 20 20 20 RE_GROUPBY
1a310 20 20 20 20 30 78 30 30 34 30 20 2f 2a 20 70 4f 0x0040 /* pO
1a320 72 64 65 72 42 79 20 69 73 20 72 65 61 6c 6c 79 rderBy is really
1a330 20 61 20 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 a GROUP BY */.#
1a340 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 define WHERE_DIS
1a350 54 49 4e 43 54 42 59 20 20 20 20 20 20 20 30 78 TINCTBY 0x
1a360 30 30 38 30 20 2f 2a 20 70 4f 72 64 65 72 62 79 0080 /* pOrderby
1a370 20 69 73 20 72 65 61 6c 6c 79 20 61 20 44 49 53 is really a DIS
1a380 54 49 4e 43 54 20 63 6c 61 75 73 65 20 2a 2f 0a TINCT clause */.
1a390 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 57 41 #define WHERE_WA
1a3a0 4e 54 5f 44 49 53 54 49 4e 43 54 20 20 20 20 30 NT_DISTINCT 0
1a3b0 78 30 31 30 30 20 2f 2a 20 41 6c 6c 20 6f 75 74 x0100 /* All out
1a3c0 70 75 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 put needs to be
1a3d0 64 69 73 74 69 6e 63 74 20 2a 2f 0a 23 64 65 66 distinct */.#def
1a3e0 69 6e 65 20 57 48 45 52 45 5f 53 4f 52 54 42 59 ine WHERE_SORTBY
1a3f0 47 52 4f 55 50 20 20 20 20 20 20 30 78 30 32 30 GROUP 0x020
1a400 30 20 2f 2a 20 53 75 70 70 6f 72 74 20 73 71 6c 0 /* Support sql
1a410 69 74 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 ite3WhereIsSorte
1a420 64 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 d() */.#define W
1a430 48 45 52 45 5f 53 45 45 4b 5f 54 41 42 4c 45 20 HERE_SEEK_TABLE
1a440 20 20 20 20 20 20 30 78 30 34 30 30 20 2f 2a 20 0x0400 /*
1a450 44 6f 20 6e 6f 74 20 64 65 66 65 72 20 73 65 65 Do not defer see
1a460 6b 73 20 6f 6e 20 6d 61 69 6e 20 74 61 62 6c 65 ks on main table
1a470 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
1a480 45 5f 4f 52 44 45 52 42 59 5f 4c 49 4d 49 54 20 E_ORDERBY_LIMIT
1a490 20 20 20 30 78 30 38 30 30 20 2f 2a 20 4f 52 44 0x0800 /* ORD
1a4a0 45 52 42 59 2b 4c 49 4d 49 54 20 6f 6e 20 74 68 ERBY+LIMIT on th
1a4b0 65 20 69 6e 6e 65 72 20 6c 6f 6f 70 20 2a 2f 0a e inner loop */.
1a4c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a4d0 20 20 20 20 20 20 20 20 2f 2a 20 20 20 20 20 30 /* 0
1a4e0 78 31 30 30 30 20 20 20 20 6e 6f 74 20 63 75 72 x1000 not cur
1a4f0 72 65 6e 74 6c 79 20 75 73 65 64 20 2a 2f 0a 20 rently used */.
1a500 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a510 20 20 20 20 20 20 20 2f 2a 20 20 20 20 20 30 78 /* 0x
1a520 32 30 30 30 20 20 20 20 6e 6f 74 20 63 75 72 72 2000 not curr
1a530 65 6e 74 6c 79 20 75 73 65 64 20 2a 2f 0a 23 64 ently used */.#d
1a540 65 66 69 6e 65 20 57 48 45 52 45 5f 55 53 45 5f efine WHERE_USE_
1a550 4c 49 4d 49 54 20 20 20 20 20 20 20 20 30 78 34 LIMIT 0x4
1a560 30 30 30 20 2f 2a 20 55 73 65 20 74 68 65 20 4c 000 /* Use the L
1a570 49 4d 49 54 20 69 6e 20 63 6f 73 74 20 65 73 74 IMIT in cost est
1a580 69 6d 61 74 65 73 20 2a 2f 0a 20 20 20 20 20 20 imates */.
1a590 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1a5a0 20 20 2f 2a 20 20 20 20 20 30 78 38 30 30 30 20 /* 0x8000
1a5b0 20 20 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c 79 not currently
1a5c0 20 75 73 65 64 20 2a 2f 0a 0a 2f 2a 20 41 6c 6c used */../* All
1a5d0 6f 77 65 64 20 72 65 74 75 72 6e 20 76 61 6c 75 owed return valu
1a5e0 65 73 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 57 es from sqlite3W
1a5f0 68 65 72 65 49 73 44 69 73 74 69 6e 63 74 28 29 hereIsDistinct()
1a600 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 .*/.#define WHER
1a610 45 5f 44 49 53 54 49 4e 43 54 5f 4e 4f 4f 50 20 E_DISTINCT_NOOP
1a620 20 20 20 20 20 30 20 20 2f 2a 20 44 49 53 54 49 0 /* DISTI
1a630 4e 43 54 20 6b 65 79 77 6f 72 64 20 6e 6f 74 20 NCT keyword not
1a640 75 73 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 used */.#define
1a650 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 55 WHERE_DISTINCT_U
1a660 4e 49 51 55 45 20 20 20 20 31 20 20 2f 2a 20 4e NIQUE 1 /* N
1a670 6f 20 64 75 70 6c 69 63 61 74 65 73 20 2a 2f 0a o duplicates */.
1a680 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 #define WHERE_DI
1a690 53 54 49 4e 43 54 5f 4f 52 44 45 52 45 44 20 20 STINCT_ORDERED
1a6a0 20 32 20 20 2f 2a 20 41 6c 6c 20 64 75 70 6c 69 2 /* All dupli
1a6b0 63 61 74 65 73 20 61 72 65 20 61 64 6a 61 63 65 cates are adjace
1a6c0 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 nt */.#define WH
1a6d0 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 55 4e 4f ERE_DISTINCT_UNO
1a6e0 52 44 45 52 45 44 20 33 20 20 2f 2a 20 44 75 70 RDERED 3 /* Dup
1a6f0 6c 69 63 61 74 65 73 20 61 72 65 20 73 63 61 74 licates are scat
1a700 74 65 72 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 tered */../*.**
1a710 41 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 64 65 A NameContext de
1a720 66 69 6e 65 73 20 61 20 63 6f 6e 74 65 78 74 20 fines a context
1a730 69 6e 20 77 68 69 63 68 20 74 6f 20 72 65 73 6f in which to reso
1a740 6c 76 65 20 74 61 62 6c 65 20 61 6e 64 20 63 6f lve table and co
1a750 6c 75 6d 6e 0a 2a 2a 20 6e 61 6d 65 73 2e 20 20 lumn.** names.
1a760 54 68 65 20 63 6f 6e 74 65 78 74 20 63 6f 6e 73 The context cons
1a770 69 73 74 73 20 6f 66 20 61 20 6c 69 73 74 20 6f ists of a list o
1a780 66 20 74 61 62 6c 65 73 20 28 74 68 65 20 70 53 f tables (the pS
1a790 72 63 4c 69 73 74 29 20 66 69 65 6c 64 20 61 6e rcList) field an
1a7a0 64 0a 2a 2a 20 61 20 6c 69 73 74 20 6f 66 20 6e d.** a list of n
1a7b0 61 6d 65 64 20 65 78 70 72 65 73 73 69 6f 6e 20 amed expression
1a7c0 28 70 45 4c 69 73 74 29 2e 20 20 54 68 65 20 6e (pEList). The n
1a7d0 61 6d 65 64 20 65 78 70 72 65 73 73 69 6f 6e 20 amed expression
1a7e0 6c 69 73 74 20 6d 61 79 0a 2a 2a 20 62 65 20 4e list may.** be N
1a7f0 55 4c 4c 2e 20 20 54 68 65 20 70 53 72 63 20 63 ULL. The pSrc c
1a800 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 orresponds to th
1a810 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 6f 66 e FROM clause of
1a820 20 61 20 53 45 4c 45 43 54 20 6f 72 0a 2a 2a 20 a SELECT or.**
1a830 74 6f 20 74 68 65 20 74 61 62 6c 65 20 62 65 69 to the table bei
1a840 6e 67 20 6f 70 65 72 61 74 65 64 20 6f 6e 20 62 ng operated on b
1a850 79 20 49 4e 53 45 52 54 2c 20 55 50 44 41 54 45 y INSERT, UPDATE
1a860 2c 20 6f 72 20 44 45 4c 45 54 45 2e 20 20 54 68 , or DELETE. Th
1a870 65 0a 2a 2a 20 70 45 4c 69 73 74 20 63 6f 72 72 e.** pEList corr
1a880 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 72 esponds to the r
1a890 65 73 75 6c 74 20 73 65 74 20 6f 66 20 61 20 53 esult set of a S
1a8a0 45 4c 45 43 54 20 61 6e 64 20 69 73 20 4e 55 4c ELECT and is NUL
1a8b0 4c 20 66 6f 72 0a 2a 2a 20 6f 74 68 65 72 20 73 L for.** other s
1a8c0 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a tatements..**.**
1a8d0 20 4e 61 6d 65 43 6f 6e 74 65 78 74 73 20 63 61 NameContexts ca
1a8e0 6e 20 62 65 20 6e 65 73 74 65 64 2e 20 20 57 68 n be nested. Wh
1a8f0 65 6e 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 6d en resolving nam
1a900 65 73 2c 20 74 68 65 20 69 6e 6e 65 72 2d 6d 6f es, the inner-mo
1a910 73 74 0a 2a 2a 20 63 6f 6e 74 65 78 74 20 69 73 st.** context is
1a920 20 73 65 61 72 63 68 65 64 20 66 69 72 73 74 2e searched first.
1a930 20 20 49 66 20 6e 6f 20 6d 61 74 63 68 20 69 73 If no match is
1a940 20 66 6f 75 6e 64 2c 20 74 68 65 20 6e 65 78 74 found, the next
1a950 20 6f 75 74 65 72 0a 2a 2a 20 63 6f 6e 74 65 78 outer.** contex
1a960 74 20 69 73 20 63 68 65 63 6b 65 64 2e 20 20 49 t is checked. I
1a970 66 20 74 68 65 72 65 20 69 73 20 73 74 69 6c 6c f there is still
1a980 20 6e 6f 20 6d 61 74 63 68 2c 20 74 68 65 20 6e no match, the n
1a990 65 78 74 20 63 6f 6e 74 65 78 74 0a 2a 2a 20 69 ext context.** i
1a9a0 73 20 63 68 65 63 6b 65 64 2e 20 20 54 68 69 73 s checked. This
1a9b0 20 70 72 6f 63 65 73 73 20 63 6f 6e 74 69 6e 75 process continu
1a9c0 65 73 20 75 6e 74 69 6c 20 65 69 74 68 65 72 20 es until either
1a9d0 61 20 6d 61 74 63 68 20 69 73 20 66 6f 75 6e 64 a match is found
1a9e0 0a 2a 2a 20 6f 72 20 61 6c 6c 20 63 6f 6e 74 65 .** or all conte
1a9f0 78 74 73 20 61 72 65 20 63 68 65 63 6b 2e 20 20 xts are check.
1aa00 57 68 65 6e 20 61 20 6d 61 74 63 68 20 69 73 20 When a match is
1aa10 66 6f 75 6e 64 2c 20 74 68 65 20 6e 52 65 66 20 found, the nRef
1aa20 6d 65 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 68 65 member of.** the
1aa30 20 63 6f 6e 74 65 78 74 20 63 6f 6e 74 61 69 6e context contain
1aa40 69 6e 67 20 74 68 65 20 6d 61 74 63 68 20 69 73 ing the match is
1aa50 20 69 6e 63 72 65 6d 65 6e 74 65 64 2e 0a 2a 2a incremented..**
1aa60 0a 2a 2a 20 45 61 63 68 20 73 75 62 71 75 65 72 .** Each subquer
1aa70 79 20 67 65 74 73 20 61 20 6e 65 77 20 4e 61 6d y gets a new Nam
1aa80 65 43 6f 6e 74 65 78 74 2e 20 20 54 68 65 20 70 eContext. The p
1aa90 4e 65 78 74 20 66 69 65 6c 64 20 70 6f 69 6e 74 Next field point
1aaa0 73 20 74 6f 20 74 68 65 0a 2a 2a 20 4e 61 6d 65 s to the.** Name
1aab0 43 6f 6e 74 65 78 74 20 69 6e 20 74 68 65 20 70 Context in the p
1aac0 61 72 65 6e 74 20 71 75 65 72 79 2e 20 20 54 68 arent query. Th
1aad0 75 73 20 74 68 65 20 70 72 6f 63 65 73 73 20 6f us the process o
1aae0 66 20 73 63 61 6e 6e 69 6e 67 20 74 68 65 0a 2a f scanning the.*
1aaf0 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 6c 69 * NameContext li
1ab00 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 st corresponds t
1ab10 6f 20 73 65 61 72 63 68 69 6e 67 20 74 68 72 6f o searching thro
1ab20 75 67 68 20 73 75 63 63 65 73 73 69 76 65 6c 79 ugh successively
1ab30 20 6f 75 74 65 72 0a 2a 2a 20 73 75 62 71 75 65 outer.** subque
1ab40 72 69 65 73 20 6c 6f 6f 6b 69 6e 67 20 66 6f 72 ries looking for
1ab50 20 61 20 6d 61 74 63 68 2e 0a 2a 2f 0a 73 74 72 a match..*/.str
1ab60 75 63 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 uct NameContext
1ab70 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 61 72 73 {. Parse *pPars
1ab80 65 3b 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 e; /* The
1ab90 70 61 72 73 65 72 20 2a 2f 0a 20 20 53 72 63 4c parser */. SrcL
1aba0 69 73 74 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 ist *pSrcList;
1abb0 20 2f 2a 20 4f 6e 65 20 6f 72 20 6d 6f 72 65 20 /* One or more
1abc0 74 61 62 6c 65 73 20 75 73 65 64 20 74 6f 20 72 tables used to r
1abd0 65 73 6f 6c 76 65 20 6e 61 6d 65 73 20 2a 2f 0a esolve names */.
1abe0 20 20 45 78 70 72 4c 69 73 74 20 2a 70 45 4c 69 ExprList *pELi
1abf0 73 74 3b 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e st; /* Option
1ac00 61 6c 20 6c 69 73 74 20 6f 66 20 72 65 73 75 6c al list of resul
1ac10 74 2d 73 65 74 20 63 6f 6c 75 6d 6e 73 20 2a 2f t-set columns */
1ac20 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 41 67 67 . AggInfo *pAgg
1ac30 49 6e 66 6f 3b 20 20 20 2f 2a 20 49 6e 66 6f 72 Info; /* Infor
1ac40 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 67 67 mation about agg
1ac50 72 65 67 61 74 65 73 20 61 74 20 74 68 69 73 20 regates at this
1ac60 6c 65 76 65 6c 20 2a 2f 0a 20 20 4e 61 6d 65 43 level */. NameC
1ac70 6f 6e 74 65 78 74 20 2a 70 4e 65 78 74 3b 20 20 ontext *pNext;
1ac80 2f 2a 20 4e 65 78 74 20 6f 75 74 65 72 20 6e 61 /* Next outer na
1ac90 6d 65 20 63 6f 6e 74 65 78 74 2e 20 20 4e 55 4c me context. NUL
1aca0 4c 20 66 6f 72 20 6f 75 74 65 72 6d 6f 73 74 20 L for outermost
1acb0 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 3b 20 20 */. int nRef;
1acc0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1acd0 62 65 72 20 6f 66 20 6e 61 6d 65 73 20 72 65 73 ber of names res
1ace0 6f 6c 76 65 64 20 62 79 20 74 68 69 73 20 63 6f olved by this co
1acf0 6e 74 65 78 74 20 2a 2f 0a 20 20 69 6e 74 20 6e ntext */. int n
1ad00 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 20 20 Err;
1ad10 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 72 72 /* Number of err
1ad20 6f 72 73 20 65 6e 63 6f 75 6e 74 65 72 65 64 20 ors encountered
1ad30 77 68 69 6c 65 20 72 65 73 6f 6c 76 69 6e 67 20 while resolving
1ad40 6e 61 6d 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e names */. u16 n
1ad50 63 46 6c 61 67 73 3b 20 20 20 20 20 20 20 20 20 cFlags;
1ad60 2f 2a 20 5a 65 72 6f 20 6f 72 20 6d 6f 72 65 20 /* Zero or more
1ad70 4e 43 5f 2a 20 66 6c 61 67 73 20 64 65 66 69 6e NC_* flags defin
1ad80 65 64 20 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 0a ed below */.};..
1ad90 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 /*.** Allowed va
1ada0 6c 75 65 73 20 66 6f 72 20 74 68 65 20 4e 61 6d lues for the Nam
1adb0 65 43 6f 6e 74 65 78 74 2c 20 6e 63 46 6c 61 67 eContext, ncFlag
1adc0 73 20 66 69 65 6c 64 2e 0a 2a 2a 0a 2a 2a 20 56 s field..**.** V
1add0 61 6c 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 alue constraints
1ade0 20 28 61 6c 6c 20 63 68 65 63 6b 65 64 20 76 69 (all checked vi
1adf0 61 20 61 73 73 65 72 74 28 29 29 3a 0a 2a 2a 20 a assert()):.**
1ae00 20 20 20 4e 43 5f 48 61 73 41 67 67 20 20 20 20 NC_HasAgg
1ae10 3d 3d 20 53 46 5f 48 61 73 41 67 67 0a 2a 2a 20 == SF_HasAgg.**
1ae20 20 20 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 NC_MinMaxAgg
1ae30 3d 3d 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 == SF_MinMaxAgg
1ae40 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4d == SQLITE_FUNC_M
1ae50 49 4e 4d 41 58 0a 2a 2a 0a 2a 2f 0a 23 64 65 66 INMAX.**.*/.#def
1ae60 69 6e 65 20 4e 43 5f 41 6c 6c 6f 77 41 67 67 20 ine NC_AllowAgg
1ae70 20 30 78 30 30 30 31 20 20 2f 2a 20 41 67 67 72 0x0001 /* Aggr
1ae80 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 egate functions
1ae90 61 72 65 20 61 6c 6c 6f 77 65 64 20 68 65 72 65 are allowed here
1aea0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 50 */.#define NC_P
1aeb0 61 72 74 49 64 78 20 20 20 30 78 30 30 30 32 20 artIdx 0x0002
1aec0 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 73 6f /* True if reso
1aed0 6c 76 69 6e 67 20 61 20 70 61 72 74 69 61 6c 20 lving a partial
1aee0 69 6e 64 65 78 20 57 48 45 52 45 20 2a 2f 0a 23 index WHERE */.#
1aef0 64 65 66 69 6e 65 20 4e 43 5f 49 73 43 68 65 63 define NC_IsChec
1af00 6b 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 54 k 0x0004 /* T
1af10 72 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 rue if resolving
1af20 20 6e 61 6d 65 73 20 69 6e 20 61 20 43 48 45 43 names in a CHEC
1af30 4b 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a K constraint */.
1af40 23 64 65 66 69 6e 65 20 4e 43 5f 49 6e 41 67 67 #define NC_InAgg
1af50 46 75 6e 63 20 30 78 30 30 30 38 20 20 2f 2a 20 Func 0x0008 /*
1af60 54 72 75 65 20 69 66 20 61 6e 61 6c 79 7a 69 6e True if analyzin
1af70 67 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 61 g arguments to a
1af80 6e 20 61 67 67 20 66 75 6e 63 20 2a 2f 0a 23 64 n agg func */.#d
1af90 65 66 69 6e 65 20 4e 43 5f 48 61 73 41 67 67 20 efine NC_HasAgg
1afa0 20 20 20 30 78 30 30 31 30 20 20 2f 2a 20 4f 6e 0x0010 /* On
1afb0 65 20 6f 72 20 6d 6f 72 65 20 61 67 67 72 65 67 e or more aggreg
1afc0 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 20 73 65 ate functions se
1afd0 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 en */.#define NC
1afe0 5f 49 64 78 45 78 70 72 20 20 20 30 78 30 30 32 _IdxExpr 0x002
1aff0 30 20 20 2f 2a 20 54 72 75 65 20 69 66 20 72 65 0 /* True if re
1b000 73 6f 6c 76 69 6e 67 20 63 6f 6c 75 6d 6e 73 20 solving columns
1b010 6f 66 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 of CREATE INDEX
1b020 2a 2f 0a 23 64 65 66 69 6e 65 20 4e 43 5f 56 61 */.#define NC_Va
1b030 72 53 65 6c 65 63 74 20 30 78 30 30 34 30 20 20 rSelect 0x0040
1b040 2f 2a 20 41 20 63 6f 72 72 65 6c 61 74 65 64 20 /* A correlated
1b050 73 75 62 71 75 65 72 79 20 68 61 73 20 62 65 65 subquery has bee
1b060 6e 20 73 65 65 6e 20 2a 2f 0a 23 64 65 66 69 6e n seen */.#defin
1b070 65 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 30 e NC_MinMaxAgg 0
1b080 78 31 30 30 30 20 20 2f 2a 20 6d 69 6e 2f 6d 61 x1000 /* min/ma
1b090 78 20 61 67 67 72 65 67 61 74 65 73 20 73 65 65 x aggregates see
1b0a0 6e 2e 20 20 53 65 65 20 6e 6f 74 65 20 61 62 6f n. See note abo
1b0b0 76 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 ve */../*.** An
1b0c0 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
1b0d0 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
1b0e0 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 61 6c 6c ure contains all
1b0f0 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 information.**
1b100 6e 65 65 64 65 64 20 74 6f 20 67 65 6e 65 72 61 needed to genera
1b110 74 65 20 63 6f 64 65 20 66 6f 72 20 61 20 73 69 te code for a si
1b120 6e 67 6c 65 20 53 45 4c 45 43 54 20 73 74 61 74 ngle SELECT stat
1b130 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 6e 4c 69 ement..**.** nLi
1b140 6d 69 74 20 69 73 20 73 65 74 20 74 6f 20 2d 31 mit is set to -1
1b150 20 69 66 20 74 68 65 72 65 20 69 73 20 6e 6f 20 if there is no
1b160 4c 49 4d 49 54 20 63 6c 61 75 73 65 2e 20 20 6e LIMIT clause. n
1b170 4f 66 66 73 65 74 20 69 73 20 73 65 74 20 74 6f Offset is set to
1b180 20 30 2e 0a 2a 2a 20 49 66 20 74 68 65 72 65 20 0..** If there
1b190 69 73 20 61 20 4c 49 4d 49 54 20 63 6c 61 75 73 is a LIMIT claus
1b1a0 65 2c 20 74 68 65 20 70 61 72 73 65 72 20 73 65 e, the parser se
1b1b0 74 73 20 6e 4c 69 6d 69 74 20 74 6f 20 74 68 65 ts nLimit to the
1b1c0 20 76 61 6c 75 65 20 6f 66 20 74 68 65 0a 2a 2a value of the.**
1b1d0 20 6c 69 6d 69 74 20 61 6e 64 20 6e 4f 66 66 73 limit and nOffs
1b1e0 65 74 20 74 6f 20 74 68 65 20 76 61 6c 75 65 20 et to the value
1b1f0 6f 66 20 74 68 65 20 6f 66 66 73 65 74 20 28 6f of the offset (o
1b200 72 20 30 20 69 66 20 74 68 65 72 65 20 69 73 20 r 0 if there is
1b210 6e 6f 74 0a 2a 2a 20 6f 66 66 73 65 74 29 2e 20 not.** offset).
1b220 20 42 75 74 20 6c 61 74 65 72 20 6f 6e 2c 20 6e But later on, n
1b230 4c 69 6d 69 74 20 61 6e 64 20 6e 4f 66 66 73 65 Limit and nOffse
1b240 74 20 62 65 63 6f 6d 65 20 74 68 65 20 6d 65 6d t become the mem
1b250 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 73 0a 2a 2a ory locations.**
1b260 20 69 6e 20 74 68 65 20 56 44 42 45 20 74 68 61 in the VDBE tha
1b270 74 20 72 65 63 6f 72 64 20 74 68 65 20 6c 69 6d t record the lim
1b280 69 74 20 61 6e 64 20 6f 66 66 73 65 74 20 63 6f it and offset co
1b290 75 6e 74 65 72 73 2e 0a 2a 2a 0a 2a 2a 20 61 64 unters..**.** ad
1b2a0 64 72 4f 70 65 6e 45 70 68 6d 5b 5d 20 65 6e 74 drOpenEphm[] ent
1b2b0 72 69 65 73 20 63 6f 6e 74 61 69 6e 20 74 68 65 ries contain the
1b2c0 20 61 64 64 72 65 73 73 20 6f 66 20 4f 50 5f 4f address of OP_O
1b2d0 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f 70 63 penEphemeral opc
1b2e0 6f 64 65 73 2e 0a 2a 2a 20 54 68 65 73 65 20 61 odes..** These a
1b2f0 64 64 72 65 73 73 65 73 20 6d 75 73 74 20 62 65 ddresses must be
1b300 20 73 74 6f 72 65 64 20 73 6f 20 74 68 61 74 20 stored so that
1b310 77 65 20 63 61 6e 20 67 6f 20 62 61 63 6b 20 61 we can go back a
1b320 6e 64 20 66 69 6c 6c 20 69 6e 0a 2a 2a 20 74 68 nd fill in.** th
1b330 65 20 50 34 5f 4b 45 59 49 4e 46 4f 20 61 6e 64 e P4_KEYINFO and
1b340 20 50 32 20 70 61 72 61 6d 65 74 65 72 73 20 6c P2 parameters l
1b350 61 74 65 72 2e 20 20 4e 65 69 74 68 65 72 20 74 ater. Neither t
1b360 68 65 20 4b 65 79 49 6e 66 6f 20 6e 6f 72 0a 2a he KeyInfo nor.*
1b370 2a 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 * the number of
1b380 63 6f 6c 75 6d 6e 73 20 69 6e 20 50 32 20 63 61 columns in P2 ca
1b390 6e 20 62 65 20 63 6f 6d 70 75 74 65 64 20 61 74 n be computed at
1b3a0 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 0a 2a the same time.*
1b3b0 2a 20 61 73 20 74 68 65 20 4f 50 5f 4f 70 65 6e * as the OP_Open
1b3c0 45 70 68 6d 20 69 6e 73 74 72 75 63 74 69 6f 6e Ephm instruction
1b3d0 20 69 73 20 63 6f 64 65 64 20 62 65 63 61 75 73 is coded becaus
1b3e0 65 20 6e 6f 74 0a 2a 2a 20 65 6e 6f 75 67 68 20 e not.** enough
1b3f0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 information abou
1b400 74 20 74 68 65 20 63 6f 6d 70 6f 75 6e 64 20 71 t the compound q
1b410 75 65 72 79 20 69 73 20 6b 6e 6f 77 6e 20 61 74 uery is known at
1b420 20 74 68 61 74 20 70 6f 69 6e 74 2e 0a 2a 2a 20 that point..**
1b430 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 The KeyInfo for
1b440 61 64 64 72 4f 70 65 6e 54 72 61 6e 5b 30 5d 20 addrOpenTran[0]
1b450 61 6e 64 20 5b 31 5d 20 63 6f 6e 74 61 69 6e 73 and [1] contains
1b460 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 collating seque
1b470 6e 63 65 73 0a 2a 2a 20 66 6f 72 20 74 68 65 20 nces.** for the
1b480 72 65 73 75 6c 74 20 73 65 74 2e 20 20 54 68 65 result set. The
1b490 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 61 64 64 KeyInfo for add
1b4a0 72 4f 70 65 6e 45 70 68 6d 5b 32 5d 20 63 6f 6e rOpenEphm[2] con
1b4b0 74 61 69 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 0a tains collating.
1b4c0 2a 2a 20 73 65 71 75 65 6e 63 65 73 20 66 6f 72 ** sequences for
1b4d0 20 74 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c the ORDER BY cl
1b4e0 61 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 ause..*/.struct
1b4f0 53 65 6c 65 63 74 20 7b 0a 20 20 45 78 70 72 4c Select {. ExprL
1b500 69 73 74 20 2a 70 45 4c 69 73 74 3b 20 20 20 20 ist *pEList;
1b510 20 20 2f 2a 20 54 68 65 20 66 69 65 6c 64 73 20 /* The fields
1b520 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 2a 2f of the result */
1b530 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 . u8 op;
1b540 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 /* One
1b550 20 6f 66 3a 20 54 4b 5f 55 4e 49 4f 4e 20 54 4b of: TK_UNION TK
1b560 5f 41 4c 4c 20 54 4b 5f 49 4e 54 45 52 53 45 43 _ALL TK_INTERSEC
1b570 54 20 54 4b 5f 45 58 43 45 50 54 20 2a 2f 0a 20 T TK_EXCEPT */.
1b580 20 4c 6f 67 45 73 74 20 6e 53 65 6c 65 63 74 52 LogEst nSelectR
1b590 6f 77 3b 20 20 20 20 20 2f 2a 20 45 73 74 69 6d ow; /* Estim
1b5a0 61 74 65 64 20 6e 75 6d 62 65 72 20 6f 66 20 72 ated number of r
1b5b0 65 73 75 6c 74 20 72 6f 77 73 20 2a 2f 0a 20 20 esult rows */.
1b5c0 75 33 32 20 73 65 6c 46 6c 61 67 73 3b 20 20 20 u32 selFlags;
1b5d0 20 20 20 20 20 20 20 2f 2a 20 56 61 72 69 6f 75 /* Variou
1b5e0 73 20 53 46 5f 2a 20 76 61 6c 75 65 73 20 2a 2f s SF_* values */
1b5f0 0a 20 20 69 6e 74 20 69 4c 69 6d 69 74 2c 20 69 . int iLimit, i
1b600 4f 66 66 73 65 74 3b 20 20 20 2f 2a 20 4d 65 6d Offset; /* Mem
1b610 6f 72 79 20 72 65 67 69 73 74 65 72 73 20 68 6f ory registers ho
1b620 6c 64 69 6e 67 20 4c 49 4d 49 54 20 26 20 4f 46 lding LIMIT & OF
1b630 46 53 45 54 20 63 6f 75 6e 74 65 72 73 20 2a 2f FSET counters */
1b640 0a 23 69 66 20 53 45 4c 45 43 54 54 52 41 43 45 .#if SELECTTRACE
1b650 5f 45 4e 41 42 4c 45 44 0a 20 20 63 68 61 72 20 _ENABLED. char
1b660 7a 53 65 6c 4e 61 6d 65 5b 31 32 5d 3b 20 20 20 zSelName[12];
1b670 20 20 2f 2a 20 53 79 6d 62 6f 6c 69 63 20 6e 61 /* Symbolic na
1b680 6d 65 20 6f 66 20 74 68 69 73 20 53 45 4c 45 43 me of this SELEC
1b690 54 20 75 73 65 20 66 6f 72 20 64 65 62 75 67 67 T use for debugg
1b6a0 69 6e 67 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 ing */.#endif.
1b6b0 69 6e 74 20 61 64 64 72 4f 70 65 6e 45 70 68 6d int addrOpenEphm
1b6c0 5b 32 5d 3b 20 20 20 2f 2a 20 4f 50 5f 4f 70 65 [2]; /* OP_Ope
1b6d0 6e 45 70 68 65 6d 20 6f 70 63 6f 64 65 73 20 72 nEphem opcodes r
1b6e0 65 6c 61 74 65 64 20 74 6f 20 74 68 69 73 20 73 elated to this s
1b6f0 65 6c 65 63 74 20 2a 2f 0a 20 20 53 72 63 4c 69 elect */. SrcLi
1b700 73 74 20 2a 70 53 72 63 3b 20 20 20 20 20 20 20 st *pSrc;
1b710 20 20 2f 2a 20 54 68 65 20 46 52 4f 4d 20 63 6c /* The FROM cl
1b720 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a ause */. Expr *
1b730 70 57 68 65 72 65 3b 20 20 20 20 20 20 20 20 20 pWhere;
1b740 20 2f 2a 20 54 68 65 20 57 48 45 52 45 20 63 6c /* The WHERE cl
1b750 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 72 4c 69 ause */. ExprLi
1b760 73 74 20 2a 70 47 72 6f 75 70 42 79 3b 20 20 20 st *pGroupBy;
1b770 20 2f 2a 20 54 68 65 20 47 52 4f 55 50 20 42 59 /* The GROUP BY
1b780 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 70 clause */. Exp
1b790 72 20 2a 70 48 61 76 69 6e 67 3b 20 20 20 20 20 r *pHaving;
1b7a0 20 20 20 20 2f 2a 20 54 68 65 20 48 41 56 49 4e /* The HAVIN
1b7b0 47 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 45 78 G clause */. Ex
1b7c0 70 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 42 79 prList *pOrderBy
1b7d0 3b 20 20 20 20 2f 2a 20 54 68 65 20 4f 52 44 45 ; /* The ORDE
1b7e0 52 20 42 59 20 63 6c 61 75 73 65 20 2a 2f 0a 20 R BY clause */.
1b7f0 20 53 65 6c 65 63 74 20 2a 70 50 72 69 6f 72 3b Select *pPrior;
1b800 20 20 20 20 20 20 20 20 2f 2a 20 50 72 69 6f 72 /* Prior
1b810 20 73 65 6c 65 63 74 20 69 6e 20 61 20 63 6f 6d select in a com
1b820 70 6f 75 6e 64 20 73 65 6c 65 63 74 20 73 74 61 pound select sta
1b830 74 65 6d 65 6e 74 20 2a 2f 0a 20 20 53 65 6c 65 tement */. Sele
1b840 63 74 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 ct *pNext;
1b850 20 20 20 2f 2a 20 4e 65 78 74 20 73 65 6c 65 63 /* Next selec
1b860 74 20 74 6f 20 74 68 65 20 6c 65 66 74 20 69 6e t to the left in
1b870 20 61 20 63 6f 6d 70 6f 75 6e 64 20 2a 2f 0a 20 a compound */.
1b880 20 45 78 70 72 20 2a 70 4c 69 6d 69 74 3b 20 20 Expr *pLimit;
1b890 20 20 20 20 20 20 20 20 2f 2a 20 4c 49 4d 49 54 /* LIMIT
1b8a0 20 65 78 70 72 65 73 73 69 6f 6e 2e 20 4e 55 4c expression. NUL
1b8b0 4c 20 6d 65 61 6e 73 20 6e 6f 74 20 75 73 65 64 L means not used
1b8c0 2e 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4f 66 . */. Expr *pOf
1b8d0 66 73 65 74 3b 20 20 20 20 20 20 20 20 20 2f 2a fset; /*
1b8e0 20 4f 46 46 53 45 54 20 65 78 70 72 65 73 73 69 OFFSET expressi
1b8f0 6f 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e on. NULL means n
1b900 6f 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 57 69 ot used. */. Wi
1b910 74 68 20 2a 70 57 69 74 68 3b 20 20 20 20 20 20 th *pWith;
1b920 20 20 20 20 20 2f 2a 20 57 49 54 48 20 63 6c 61 /* WITH cla
1b930 75 73 65 20 61 74 74 61 63 68 65 64 20 74 6f 20 use attached to
1b940 74 68 69 73 20 73 65 6c 65 63 74 2e 20 4f 72 20 this select. Or
1b950 4e 55 4c 4c 2e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a NULL. */.};../*.
1b960 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 ** Allowed value
1b970 73 20 66 6f 72 20 53 65 6c 65 63 74 2e 73 65 6c s for Select.sel
1b980 46 6c 61 67 73 2e 20 20 54 68 65 20 22 53 46 22 Flags. The "SF"
1b990 20 70 72 65 66 69 78 20 73 74 61 6e 64 73 20 66 prefix stands f
1b9a0 6f 72 0a 2a 2a 20 22 53 65 6c 65 63 74 20 46 6c or.** "Select Fl
1b9b0 61 67 22 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c 75 65 ag"..**.** Value
1b9c0 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 61 6c constraints (al
1b9d0 6c 20 63 68 65 63 6b 65 64 20 76 69 61 20 61 73 l checked via as
1b9e0 73 65 72 74 28 29 29 0a 2a 2a 20 20 20 20 20 53 sert()).** S
1b9f0 46 5f 48 61 73 41 67 67 20 20 20 20 20 3d 3d 20 F_HasAgg ==
1ba00 4e 43 5f 48 61 73 41 67 67 0a 2a 2a 20 20 20 20 NC_HasAgg.**
1ba10 20 53 46 5f 4d 69 6e 4d 61 78 41 67 67 20 20 3d SF_MinMaxAgg =
1ba20 3d 20 4e 43 5f 4d 69 6e 4d 61 78 41 67 67 20 20 = NC_MinMaxAgg
1ba30 20 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e == SQLITE_FUN
1ba40 43 5f 4d 49 4e 4d 41 58 0a 2a 2a 20 20 20 20 20 C_MINMAX.**
1ba50 53 46 5f 46 69 78 65 64 4c 69 6d 69 74 20 3d 3d SF_FixedLimit ==
1ba60 20 57 48 45 52 45 5f 55 53 45 5f 4c 49 4d 49 54 WHERE_USE_LIMIT
1ba70 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 44 .*/.#define SF_D
1ba80 69 73 74 69 6e 63 74 20 20 20 20 20 20 20 30 78 istinct 0x
1ba90 30 30 30 30 31 20 20 2f 2a 20 4f 75 74 70 75 74 00001 /* Output
1baa0 20 73 68 6f 75 6c 64 20 62 65 20 44 49 53 54 49 should be DISTI
1bab0 4e 43 54 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 NCT */.#define S
1bac0 46 5f 41 6c 6c 20 20 20 20 20 20 20 20 20 20 20 F_All
1bad0 20 30 78 30 30 30 30 32 20 20 2f 2a 20 49 6e 63 0x00002 /* Inc
1bae0 6c 75 64 65 73 20 74 68 65 20 41 4c 4c 20 6b 65 ludes the ALL ke
1baf0 79 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 yword */.#define
1bb00 20 53 46 5f 52 65 73 6f 6c 76 65 64 20 20 20 20 SF_Resolved
1bb10 20 20 20 30 78 30 30 30 30 34 20 20 2f 2a 20 49 0x00004 /* I
1bb20 64 65 6e 74 69 66 69 65 72 73 20 68 61 76 65 20 dentifiers have
1bb30 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 2a 2f been resolved */
1bb40 0a 23 64 65 66 69 6e 65 20 53 46 5f 41 67 67 72 .#define SF_Aggr
1bb50 65 67 61 74 65 20 20 20 20 20 20 30 78 30 30 30 egate 0x000
1bb60 30 38 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 08 /* Contains
1bb70 61 67 67 20 66 75 6e 63 74 69 6f 6e 73 20 6f 72 agg functions or
1bb80 20 61 20 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 a GROUP BY */.#
1bb90 64 65 66 69 6e 65 20 53 46 5f 48 61 73 41 67 67 define SF_HasAgg
1bba0 20 20 20 20 20 20 20 20 20 30 78 30 30 30 31 30 0x00010
1bbb0 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 73 20 61 67 /* Contains ag
1bbc0 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
1bbd0 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f s */.#define SF_
1bbe0 55 73 65 73 45 70 68 65 6d 65 72 61 6c 20 20 30 UsesEphemeral 0
1bbf0 78 30 30 30 32 30 20 20 2f 2a 20 55 73 65 73 20 x00020 /* Uses
1bc00 74 68 65 20 4f 70 65 6e 45 70 68 65 6d 65 72 61 the OpenEphemera
1bc10 6c 20 6f 70 63 6f 64 65 20 2a 2f 0a 23 64 65 66 l opcode */.#def
1bc20 69 6e 65 20 53 46 5f 45 78 70 61 6e 64 65 64 20 ine SF_Expanded
1bc30 20 20 20 20 20 20 30 78 30 30 30 34 30 20 20 2f 0x00040 /
1bc40 2a 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 45 * sqlite3SelectE
1bc50 78 70 61 6e 64 28 29 20 63 61 6c 6c 65 64 20 6f xpand() called o
1bc60 6e 20 74 68 69 73 20 2a 2f 0a 23 64 65 66 69 6e n this */.#defin
1bc70 65 20 53 46 5f 48 61 73 54 79 70 65 49 6e 66 6f e SF_HasTypeInfo
1bc80 20 20 20 20 30 78 30 30 30 38 30 20 20 2f 2a 20 0x00080 /*
1bc90 46 52 4f 4d 20 73 75 62 71 75 65 72 69 65 73 20 FROM subqueries
1bca0 68 61 76 65 20 54 61 62 6c 65 20 6d 65 74 61 64 have Table metad
1bcb0 61 74 61 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ata */.#define S
1bcc0 46 5f 43 6f 6d 70 6f 75 6e 64 20 20 20 20 20 20 F_Compound
1bcd0 20 30 78 30 30 31 30 30 20 20 2f 2a 20 50 61 72 0x00100 /* Par
1bce0 74 20 6f 66 20 61 20 63 6f 6d 70 6f 75 6e 64 20 t of a compound
1bcf0 71 75 65 72 79 20 2a 2f 0a 23 64 65 66 69 6e 65 query */.#define
1bd00 20 53 46 5f 56 61 6c 75 65 73 20 20 20 20 20 20 SF_Values
1bd10 20 20 20 30 78 30 30 32 30 30 20 20 2f 2a 20 53 0x00200 /* S
1bd20 79 6e 74 68 65 73 69 7a 65 64 20 66 72 6f 6d 20 ynthesized from
1bd30 56 41 4c 55 45 53 20 63 6c 61 75 73 65 20 2a 2f VALUES clause */
1bd40 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d 75 6c 74 .#define SF_Mult
1bd50 69 56 61 6c 75 65 20 20 20 20 20 30 78 30 30 34 iValue 0x004
1bd60 30 30 20 20 2f 2a 20 53 69 6e 67 6c 65 20 56 41 00 /* Single VA
1bd70 4c 55 45 53 20 74 65 72 6d 20 77 69 74 68 20 6d LUES term with m
1bd80 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a ultiple rows */.
1bd90 23 64 65 66 69 6e 65 20 53 46 5f 4e 65 73 74 65 #define SF_Neste
1bda0 64 46 72 6f 6d 20 20 20 20 20 30 78 30 30 38 30 dFrom 0x0080
1bdb0 30 20 20 2f 2a 20 50 61 72 74 20 6f 66 20 61 20 0 /* Part of a
1bdc0 70 61 72 65 6e 74 68 65 73 69 7a 65 64 20 46 52 parenthesized FR
1bdd0 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 23 64 65 OM clause */.#de
1bde0 66 69 6e 65 20 53 46 5f 4d 69 6e 4d 61 78 41 67 fine SF_MinMaxAg
1bdf0 67 20 20 20 20 20 20 30 78 30 31 30 30 30 20 20 g 0x01000
1be00 2f 2a 20 41 67 67 72 65 67 61 74 65 20 63 6f 6e /* Aggregate con
1be10 74 61 69 6e 69 6e 67 20 6d 69 6e 28 29 20 6f 72 taining min() or
1be20 20 6d 61 78 28 29 20 2a 2f 0a 23 64 65 66 69 6e max() */.#defin
1be30 65 20 53 46 5f 52 65 63 75 72 73 69 76 65 20 20 e SF_Recursive
1be40 20 20 20 20 30 78 30 32 30 30 30 20 20 2f 2a 20 0x02000 /*
1be50 54 68 65 20 72 65 63 75 72 73 69 76 65 20 70 61 The recursive pa
1be60 72 74 20 6f 66 20 61 20 72 65 63 75 72 73 69 76 rt of a recursiv
1be70 65 20 43 54 45 20 2a 2f 0a 23 64 65 66 69 6e 65 e CTE */.#define
1be80 20 53 46 5f 46 69 78 65 64 4c 69 6d 69 74 20 20 SF_FixedLimit
1be90 20 20 20 30 78 30 34 30 30 30 20 20 2f 2a 20 6e 0x04000 /* n
1bea0 53 65 6c 65 63 74 52 6f 77 20 73 65 74 20 62 79 SelectRow set by
1beb0 20 61 20 63 6f 6e 73 74 61 6e 74 20 4c 49 4d 49 a constant LIMI
1bec0 54 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f T */.#define SF_
1bed0 4d 61 79 62 65 43 6f 6e 76 65 72 74 20 20 20 30 MaybeConvert 0
1bee0 78 30 38 30 30 30 20 20 2f 2a 20 4e 65 65 64 20 x08000 /* Need
1bef0 63 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 convertCompoundS
1bf00 65 6c 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 electToSubquery(
1bf10 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f ) */.#define SF_
1bf20 43 6f 6e 76 65 72 74 65 64 20 20 20 20 20 20 30 Converted 0
1bf30 78 31 30 30 30 30 20 20 2f 2a 20 42 79 20 63 6f x10000 /* By co
1bf40 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 6c nvertCompoundSel
1bf50 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 20 ectToSubquery()
1bf60 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 49 6e */.#define SF_In
1bf70 63 6c 75 64 65 48 69 64 64 65 6e 20 20 30 78 32 cludeHidden 0x2
1bf80 30 30 30 30 20 20 2f 2a 20 49 6e 63 6c 75 64 65 0000 /* Include
1bf90 20 68 69 64 64 65 6e 20 63 6f 6c 75 6d 6e 73 20 hidden columns
1bfa0 69 6e 20 6f 75 74 70 75 74 20 2a 2f 0a 0a 0a 2f in output */.../
1bfb0 2a 0a 2a 2a 20 54 68 65 20 72 65 73 75 6c 74 73 *.** The results
1bfc0 20 6f 66 20 61 20 53 45 4c 45 43 54 20 63 61 6e of a SELECT can
1bfd0 20 62 65 20 64 69 73 74 72 69 62 75 74 65 64 20 be distributed
1bfe0 69 6e 20 73 65 76 65 72 61 6c 20 77 61 79 73 2c in several ways,
1bff0 20 61 73 20 64 65 66 69 6e 65 64 0a 2a 2a 20 62 as defined.** b
1c000 79 20 6f 6e 65 20 6f 66 20 74 68 65 20 66 6f 6c y one of the fol
1c010 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 2e 20 20 lowing macros.
1c020 54 68 65 20 22 53 52 54 22 20 70 72 65 66 69 78 The "SRT" prefix
1c030 20 6d 65 61 6e 73 20 22 53 45 4c 45 43 54 20 52 means "SELECT R
1c040 65 73 75 6c 74 0a 2a 2a 20 54 79 70 65 22 2e 0a esult.** Type"..
1c050 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 55 6e **.** SRT_Un
1c060 69 6f 6e 20 20 20 20 20 20 20 53 74 6f 72 65 20 ion Store
1c070 72 65 73 75 6c 74 73 20 61 73 20 61 20 6b 65 79 results as a key
1c080 20 69 6e 20 61 20 74 65 6d 70 6f 72 61 72 79 20 in a temporary
1c090 69 6e 64 65 78 0a 2a 2a 20 20 20 20 20 20 20 20 index.**
1c0a0 20 20 20 20 20 20 20 20 20 20 20 20 20 69 64 65 ide
1c0b0 6e 74 69 66 69 65 64 20 62 79 20 70 44 65 73 74 ntified by pDest
1c0c0 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a ->iSDParm..**.**
1c0d0 20 20 20 20 20 53 52 54 5f 45 78 63 65 70 74 20 SRT_Except
1c0e0 20 20 20 20 20 52 65 6d 6f 76 65 20 72 65 73 75 Remove resu
1c0f0 6c 74 73 20 66 72 6f 6d 20 74 68 65 20 74 65 6d lts from the tem
1c100 70 6f 72 61 72 79 20 69 6e 64 65 78 20 70 44 65 porary index pDe
1c110 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 0a st->iSDParm..**.
1c120 2a 2a 20 20 20 20 20 53 52 54 5f 45 78 69 73 74 ** SRT_Exist
1c130 73 20 20 20 20 20 20 53 74 6f 72 65 20 61 20 31 s Store a 1
1c140 20 69 6e 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 in memory cell
1c150 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 69 pDest->iSDParm i
1c160 66 20 74 68 65 20 72 65 73 75 6c 74 0a 2a 2a 20 f the result.**
1c170 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c180 20 20 20 20 73 65 74 20 69 73 20 6e 6f 74 20 65 set is not e
1c190 6d 70 74 79 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 mpty..**.**
1c1a0 53 52 54 5f 44 69 73 63 61 72 64 20 20 20 20 20 SRT_Discard
1c1b0 54 68 72 6f 77 20 74 68 65 20 72 65 73 75 6c 74 Throw the result
1c1c0 73 20 61 77 61 79 2e 20 20 54 68 69 73 20 69 73 s away. This is
1c1d0 20 75 73 65 64 20 62 79 20 53 45 4c 45 43 54 0a used by SELECT.
1c1e0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c1f0 20 20 20 20 20 20 20 73 74 61 74 65 6d 65 6e 74 statement
1c200 73 20 77 69 74 68 69 6e 20 74 72 69 67 67 65 72 s within trigger
1c210 73 20 77 68 6f 73 65 20 6f 6e 6c 79 20 70 75 72 s whose only pur
1c220 70 6f 73 65 20 69 73 0a 2a 2a 20 20 20 20 20 20 pose is.**
1c230 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
1c240 68 65 20 73 69 64 65 2d 65 66 66 65 63 74 73 20 he side-effects
1c250 6f 66 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 2a 2a of functions..**
1c260 0a 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 65 20 61 .** All of the a
1c270 62 6f 76 65 20 61 72 65 20 66 72 65 65 20 74 6f bove are free to
1c280 20 69 67 6e 6f 72 65 20 74 68 65 69 72 20 4f 52 ignore their OR
1c290 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 20 54 DER BY clause. T
1c2a0 68 6f 73 65 20 74 68 61 74 0a 2a 2a 20 66 6f 6c hose that.** fol
1c2b0 6c 6f 77 20 6d 75 73 74 20 68 6f 6e 6f 72 20 74 low must honor t
1c2c0 68 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 he ORDER BY clau
1c2d0 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 se..**.** SR
1c2e0 54 5f 4f 75 74 70 75 74 20 20 20 20 20 20 47 65 T_Output Ge
1c2f0 6e 65 72 61 74 65 20 61 20 72 6f 77 20 6f 66 20 nerate a row of
1c300 6f 75 74 70 75 74 20 28 75 73 69 6e 67 20 74 68 output (using th
1c310 65 20 4f 50 5f 52 65 73 75 6c 74 52 6f 77 0a 2a e OP_ResultRow.*
1c320 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1c330 20 20 20 20 20 20 6f 70 63 6f 64 65 29 20 66 6f opcode) fo
1c340 72 20 65 61 63 68 20 72 6f 77 20 69 6e 20 74 68 r each row in th
1c350 65 20 72 65 73 75 6c 74 20 73 65 74 2e 0a 2a 2a e result set..**
1c360 0a 2a 2a 20 20 20 20 20 53 52 54 5f 4d 65 6d 20 .** SRT_Mem
1c370 20 20 20 20 20 20 20 20 4f 6e 6c 79 20 76 61 6c Only val
1c380 69 64 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 id if the result
1c390 20 69 73 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c is a single col
1c3a0 75 6d 6e 2e 0a 2a 2a 20 20 20 20 20 20 20 20 20 umn..**
1c3b0 20 20 20 20 20 20 20 20 20 20 20 20 53 74 6f 72 Stor
1c3c0 65 20 74 68 65 20 66 69 72 73 74 20 63 6f 6c 75 e the first colu
1c3d0 6d 6e 20 6f 66 20 74 68 65 20 66 69 72 73 74 20 mn of the first
1c3e0 72 65 73 75 6c 74 20 72 6f 77 0a 2a 2a 20 20 20 result row.**
1c3f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c400 20 20 69 6e 20 72 65 67 69 73 74 65 72 20 70 44 in register pD
1c410 65 73 74 2d 3e 69 53 44 50 61 72 6d 20 74 68 65 est->iSDParm the
1c420 6e 20 61 62 61 6e 64 6f 6e 20 74 68 65 20 72 65 n abandon the re
1c430 73 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 st.**
1c440 20 20 20 20 20 20 20 20 20 20 6f 66 20 74 68 65 of the
1c450 20 71 75 65 72 79 2e 20 20 54 68 69 73 20 64 65 query. This de
1c460 73 74 69 6e 61 74 69 6f 6e 20 69 6d 70 6c 69 65 stination implie
1c470 73 20 22 4c 49 4d 49 54 20 31 22 2e 0a 2a 2a 0a s "LIMIT 1"..**.
1c480 2a 2a 20 20 20 20 20 53 52 54 5f 53 65 74 20 20 ** SRT_Set
1c490 20 20 20 20 20 20 20 54 68 65 20 72 65 73 75 6c The resul
1c4a0 74 20 6d 75 73 74 20 62 65 20 61 20 73 69 6e 67 t must be a sing
1c4b0 6c 65 20 63 6f 6c 75 6d 6e 2e 20 20 53 74 6f 72 le column. Stor
1c4c0 65 20 65 61 63 68 0a 2a 2a 20 20 20 20 20 20 20 e each.**
1c4d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 6f ro
1c4e0 77 20 6f 66 20 72 65 73 75 6c 74 20 61 73 20 74 w of result as t
1c4f0 68 65 20 6b 65 79 20 69 6e 20 74 61 62 6c 65 20 he key in table
1c500 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a pDest->iSDParm..
1c510 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c520 20 20 20 20 20 20 20 41 70 70 6c 79 20 74 68 65 Apply the
1c530 20 61 66 66 69 6e 69 74 79 20 70 44 65 73 74 2d affinity pDest-
1c540 3e 61 66 66 53 64 73 74 20 62 65 66 6f 72 65 20 >affSdst before
1c550 73 74 6f 72 69 6e 67 0a 2a 2a 20 20 20 20 20 20 storing.**
1c560 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
1c570 65 73 75 6c 74 73 2e 20 20 55 73 65 64 20 74 6f esults. Used to
1c580 20 69 6d 70 6c 65 6d 65 6e 74 20 22 49 4e 20 28 implement "IN (
1c590 53 45 4c 45 43 54 20 2e 2e 2e 29 22 2e 0a 2a 2a SELECT ...)"..**
1c5a0 0a 2a 2a 20 20 20 20 20 53 52 54 5f 45 70 68 65 .** SRT_Ephe
1c5b0 6d 54 61 62 20 20 20 20 43 72 65 61 74 65 20 61 mTab Create a
1c5c0 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c n temporary tabl
1c5d0 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
1c5e0 20 61 6e 64 20 73 74 6f 72 65 0a 2a 2a 20 20 20 and store.**
1c5f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c600 20 20 74 68 65 20 72 65 73 75 6c 74 20 74 68 65 the result the
1c610 72 65 2e 20 54 68 65 20 63 75 72 73 6f 72 20 69 re. The cursor i
1c620 73 20 6c 65 66 74 20 6f 70 65 6e 20 61 66 74 65 s left open afte
1c630 72 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 r.**
1c640 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 69 returni
1c650 6e 67 2e 20 20 54 68 69 73 20 69 73 20 6c 69 6b ng. This is lik
1c660 65 20 53 52 54 5f 54 61 62 6c 65 20 65 78 63 65 e SRT_Table exce
1c670 70 74 20 74 68 61 74 0a 2a 2a 20 20 20 20 20 20 pt that.**
1c680 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 t
1c690 68 69 73 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 his destination
1c6a0 75 73 65 73 20 4f 50 5f 4f 70 65 6e 45 70 68 65 uses OP_OpenEphe
1c6b0 6d 65 72 61 6c 20 74 6f 20 63 72 65 61 74 65 0a meral to create.
1c6c0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c6d0 20 20 20 20 20 20 20 74 68 65 20 74 61 62 6c 65 the table
1c6e0 20 66 69 72 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 first..**.**
1c6f0 20 20 53 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 SRT_Coroutine
1c700 20 20 47 65 6e 65 72 61 74 65 20 61 20 63 6f 2d Generate a co-
1c710 72 6f 75 74 69 6e 65 20 74 68 61 74 20 72 65 74 routine that ret
1c720 75 72 6e 73 20 61 20 6e 65 77 20 72 6f 77 20 6f urns a new row o
1c730 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 f.**
1c740 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 73 results
1c750 20 65 61 63 68 20 74 69 6d 65 20 69 74 20 69 73 each time it is
1c760 20 69 6e 76 6f 6b 65 64 2e 20 20 54 68 65 20 65 invoked. The e
1c770 6e 74 72 79 20 70 6f 69 6e 74 0a 2a 2a 20 20 20 ntry point.**
1c780 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c790 20 20 6f 66 20 74 68 65 20 63 6f 2d 72 6f 75 74 of the co-rout
1c7a0 69 6e 65 20 69 73 20 73 74 6f 72 65 64 20 69 6e ine is stored in
1c7b0 20 72 65 67 69 73 74 65 72 20 70 44 65 73 74 2d register pDest-
1c7c0 3e 69 53 44 50 61 72 6d 0a 2a 2a 20 20 20 20 20 >iSDParm.**
1c7d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c7e0 61 6e 64 20 74 68 65 20 72 65 73 75 6c 74 20 72 and the result r
1c7f0 6f 77 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 ow is stored in
1c800 70 44 65 73 74 2d 3e 6e 44 65 73 74 20 72 65 67 pDest->nDest reg
1c810 69 73 74 65 72 73 0a 2a 2a 20 20 20 20 20 20 20 isters.**
1c820 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 74 st
1c830 61 72 74 69 6e 67 20 77 69 74 68 20 70 44 65 73 arting with pDes
1c840 74 2d 3e 69 53 64 73 74 2e 0a 2a 2a 0a 2a 2a 20 t->iSdst..**.**
1c850 20 20 20 20 53 52 54 5f 54 61 62 6c 65 20 20 20 SRT_Table
1c860 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 Store result
1c870 73 20 69 6e 20 74 65 6d 70 6f 72 61 72 79 20 74 s in temporary t
1c880 61 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 able pDest->iSDP
1c890 61 72 6d 2e 0a 2a 2a 20 20 20 20 20 53 52 54 5f arm..** SRT_
1c8a0 46 69 66 6f 20 20 20 20 20 20 20 20 54 68 69 73 Fifo This
1c8b0 20 69 73 20 6c 69 6b 65 20 53 52 54 5f 45 70 68 is like SRT_Eph
1c8c0 65 6d 54 61 62 20 65 78 63 65 70 74 20 74 68 61 emTab except tha
1c8d0 74 20 74 68 65 20 74 61 62 6c 65 0a 2a 2a 20 20 t the table.**
1c8e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c8f0 20 20 20 69 73 20 61 73 73 75 6d 65 64 20 74 6f is assumed to
1c900 20 61 6c 72 65 61 64 79 20 62 65 20 6f 70 65 6e already be open
1c910 2e 20 20 53 52 54 5f 46 69 66 6f 20 68 61 73 0a . SRT_Fifo has.
1c920 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c930 20 20 20 20 20 20 20 74 68 65 20 61 64 64 69 74 the addit
1c940 69 6f 6e 61 6c 20 70 72 6f 70 65 72 74 79 20 6f ional property o
1c950 66 20 62 65 69 6e 67 20 61 62 6c 65 20 74 6f 20 f being able to
1c960 69 67 6e 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 ignore.**
1c970 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 68 th
1c980 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
1c990 65 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 e..**.** SRT
1c9a0 5f 44 69 73 74 46 69 66 6f 20 20 20 20 53 74 6f _DistFifo Sto
1c9b0 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 61 20 re results in a
1c9c0 74 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 temporary table
1c9d0 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a pDest->iSDParm..
1c9e0 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
1c9f0 20 20 20 20 20 20 20 42 75 74 20 61 6c 73 6f 20 But also
1ca00 75 73 65 20 74 65 6d 70 6f 72 61 72 79 20 74 61 use temporary ta
1ca10 62 6c 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 ble pDest->iSDPa
1ca20 72 6d 2b 31 20 61 73 0a 2a 2a 20 20 20 20 20 20 rm+1 as.**
1ca30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 a
1ca40 20 72 65 63 6f 72 64 20 6f 66 20 61 6c 6c 20 70 record of all p
1ca50 72 69 6f 72 20 72 65 73 75 6c 74 73 20 61 6e 64 rior results and
1ca60 20 69 67 6e 6f 72 65 20 61 6e 79 20 64 75 70 6c ignore any dupl
1ca70 69 63 61 74 65 0a 2a 2a 20 20 20 20 20 20 20 20 icate.**
1ca80 20 20 20 20 20 20 20 20 20 20 20 20 20 72 6f 77 row
1ca90 73 2e 20 20 4e 61 6d 65 20 6d 65 61 6e 73 3a 20 s. Name means:
1caa0 20 22 44 69 73 74 69 6e 63 74 20 46 69 66 6f 22 "Distinct Fifo"
1cab0 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
1cac0 51 75 65 75 65 20 20 20 20 20 20 20 53 74 6f 72 Queue Stor
1cad0 65 20 72 65 73 75 6c 74 73 20 69 6e 20 70 72 69 e results in pri
1cae0 6f 72 69 74 79 20 71 75 65 75 65 20 70 44 65 73 ority queue pDes
1caf0 74 2d 3e 69 53 44 50 61 72 6d 20 28 72 65 61 6c t->iSDParm (real
1cb00 6c 79 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 ly.**
1cb10 20 20 20 20 20 20 20 20 20 20 61 6e 20 69 6e 64 an ind
1cb20 65 78 29 2e 20 20 41 70 70 65 6e 64 20 61 20 73 ex). Append a s
1cb30 65 71 75 65 6e 63 65 20 6e 75 6d 62 65 72 20 73 equence number s
1cb40 6f 20 74 68 61 74 20 61 6c 6c 20 65 6e 74 72 69 o that all entri
1cb50 65 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 es.**
1cb60 20 20 20 20 20 20 20 20 20 20 61 72 65 20 64 69 are di
1cb70 73 74 69 6e 63 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 stinct..**.**
1cb80 20 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 20 SRT_DistQueue
1cb90 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 Store results
1cba0 69 6e 20 70 72 69 6f 72 69 74 79 20 71 75 65 75 in priority queu
1cbb0 65 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 6d e pDest->iSDParm
1cbc0 20 6f 6e 6c 79 20 69 66 0a 2a 2a 20 20 20 20 20 only if.**
1cbd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1cbe0 74 68 65 20 73 61 6d 65 20 72 65 63 6f 72 64 20 the same record
1cbf0 68 61 73 20 6e 65 76 65 72 20 62 65 65 6e 20 73 has never been s
1cc00 74 6f 72 65 64 20 62 65 66 6f 72 65 2e 20 20 54 tored before. T
1cc10 68 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 he.**
1cc20 20 20 20 20 20 20 20 20 20 20 69 6e 64 65 78 20 index
1cc30 61 74 20 70 44 65 73 74 2d 3e 69 53 44 50 61 72 at pDest->iSDPar
1cc40 6d 2b 31 20 68 6f 6c 64 20 61 6c 6c 20 70 72 69 m+1 hold all pri
1cc50 6f 72 20 73 74 6f 72 65 73 2e 0a 2a 2f 0a 23 64 or stores..*/.#d
1cc60 65 66 69 6e 65 20 53 52 54 5f 55 6e 69 6f 6e 20 efine SRT_Union
1cc70 20 20 20 20 20 20 20 31 20 20 2f 2a 20 53 74 6f 1 /* Sto
1cc80 72 65 20 72 65 73 75 6c 74 20 61 73 20 6b 65 79 re result as key
1cc90 73 20 69 6e 20 61 6e 20 69 6e 64 65 78 20 2a 2f s in an index */
1cca0 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 45 78 63 .#define SRT_Exc
1ccb0 65 70 74 20 20 20 20 20 20 20 32 20 20 2f 2a 20 ept 2 /*
1ccc0 52 65 6d 6f 76 65 20 72 65 73 75 6c 74 20 66 72 Remove result fr
1ccd0 6f 6d 20 61 20 55 4e 49 4f 4e 20 69 6e 64 65 78 om a UNION index
1cce0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f */.#define SRT_
1ccf0 45 78 69 73 74 73 20 20 20 20 20 20 20 33 20 20 Exists 3
1cd00 2f 2a 20 53 74 6f 72 65 20 31 20 69 66 20 74 68 /* Store 1 if th
1cd10 65 20 72 65 73 75 6c 74 20 69 73 20 6e 6f 74 20 e result is not
1cd20 65 6d 70 74 79 20 2a 2f 0a 23 64 65 66 69 6e 65 empty */.#define
1cd30 20 53 52 54 5f 44 69 73 63 61 72 64 20 20 20 20 SRT_Discard
1cd40 20 20 34 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 73 4 /* Do not s
1cd50 61 76 65 20 74 68 65 20 72 65 73 75 6c 74 73 20 ave the results
1cd60 61 6e 79 77 68 65 72 65 20 2a 2f 0a 23 64 65 66 anywhere */.#def
1cd70 69 6e 65 20 53 52 54 5f 46 69 66 6f 20 20 20 20 ine SRT_Fifo
1cd80 20 20 20 20 20 35 20 20 2f 2a 20 53 74 6f 72 65 5 /* Store
1cd90 20 72 65 73 75 6c 74 20 61 73 20 64 61 74 61 20 result as data
1cda0 77 69 74 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 with an automati
1cdb0 63 20 72 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 c rowid */.#defi
1cdc0 6e 65 20 53 52 54 5f 44 69 73 74 46 69 66 6f 20 ne SRT_DistFifo
1cdd0 20 20 20 20 36 20 20 2f 2a 20 4c 69 6b 65 20 53 6 /* Like S
1cde0 52 54 5f 46 69 66 6f 2c 20 62 75 74 20 75 6e 69 RT_Fifo, but uni
1cdf0 71 75 65 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 que results only
1ce00 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f */.#define SRT_
1ce10 51 75 65 75 65 20 20 20 20 20 20 20 20 37 20 20 Queue 7
1ce20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 /* Store result
1ce30 69 6e 20 61 6e 20 71 75 65 75 65 20 2a 2f 0a 23 in an queue */.#
1ce40 64 65 66 69 6e 65 20 53 52 54 5f 44 69 73 74 51 define SRT_DistQ
1ce50 75 65 75 65 20 20 20 20 38 20 20 2f 2a 20 4c 69 ueue 8 /* Li
1ce60 6b 65 20 53 52 54 5f 51 75 65 75 65 2c 20 62 75 ke SRT_Queue, bu
1ce70 74 20 75 6e 69 71 75 65 20 72 65 73 75 6c 74 73 t unique results
1ce80 20 6f 6e 6c 79 20 2a 2f 0a 0a 2f 2a 20 54 68 65 only */../* The
1ce90 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 ORDER BY clause
1cea0 20 69 73 20 69 67 6e 6f 72 65 64 20 66 6f 72 20 is ignored for
1ceb0 61 6c 6c 20 6f 66 20 74 68 65 20 61 62 6f 76 65 all of the above
1cec0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 67 6e 6f */.#define Igno
1ced0 72 61 62 6c 65 4f 72 64 65 72 62 79 28 58 29 20 rableOrderby(X)
1cee0 28 28 58 2d 3e 65 44 65 73 74 29 3c 3d 53 52 54 ((X->eDest)<=SRT
1cef0 5f 44 69 73 74 51 75 65 75 65 29 0a 0a 23 64 65 _DistQueue)..#de
1cf00 66 69 6e 65 20 53 52 54 5f 4f 75 74 70 75 74 20 fine SRT_Output
1cf10 20 20 20 20 20 20 39 20 20 2f 2a 20 4f 75 74 70 9 /* Outp
1cf20 75 74 20 65 61 63 68 20 72 6f 77 20 6f 66 20 72 ut each row of r
1cf30 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 esult */.#define
1cf40 20 53 52 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 SRT_Mem
1cf50 20 31 30 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 10 /* Store re
1cf60 73 75 6c 74 20 69 6e 20 61 20 6d 65 6d 6f 72 79 sult in a memory
1cf70 20 63 65 6c 6c 20 2a 2f 0a 23 64 65 66 69 6e 65 cell */.#define
1cf80 20 53 52 54 5f 53 65 74 20 20 20 20 20 20 20 20 SRT_Set
1cf90 20 31 31 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 11 /* Store re
1cfa0 73 75 6c 74 73 20 61 73 20 6b 65 79 73 20 69 6e sults as keys in
1cfb0 20 61 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 an index */.#de
1cfc0 66 69 6e 65 20 53 52 54 5f 45 70 68 65 6d 54 61 fine SRT_EphemTa
1cfd0 62 20 20 20 20 31 32 20 20 2f 2a 20 43 72 65 61 b 12 /* Crea
1cfe0 74 65 20 74 72 61 6e 73 69 65 6e 74 20 74 61 62 te transient tab
1cff0 20 61 6e 64 20 73 74 6f 72 65 20 6c 69 6b 65 20 and store like
1d000 53 52 54 5f 54 61 62 6c 65 20 2a 2f 0a 23 64 65 SRT_Table */.#de
1d010 66 69 6e 65 20 53 52 54 5f 43 6f 72 6f 75 74 69 fine SRT_Corouti
1d020 6e 65 20 20 20 31 33 20 20 2f 2a 20 47 65 6e 65 ne 13 /* Gene
1d030 72 61 74 65 20 61 20 73 69 6e 67 6c 65 20 72 6f rate a single ro
1d040 77 20 6f 66 20 72 65 73 75 6c 74 20 2a 2f 0a 23 w of result */.#
1d050 64 65 66 69 6e 65 20 53 52 54 5f 54 61 62 6c 65 define SRT_Table
1d060 20 20 20 20 20 20 20 31 34 20 20 2f 2a 20 53 74 14 /* St
1d070 6f 72 65 20 72 65 73 75 6c 74 20 61 73 20 64 61 ore result as da
1d080 74 61 20 77 69 74 68 20 61 6e 20 61 75 74 6f 6d ta with an autom
1d090 61 74 69 63 20 72 6f 77 69 64 20 2a 2f 0a 0a 2f atic rowid */../
1d0a0 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
1d0b0 20 6f 66 20 74 68 69 73 20 6f 62 6a 65 63 74 20 of this object
1d0c0 64 65 73 63 72 69 62 65 73 20 77 68 65 72 65 20 describes where
1d0d0 74 6f 20 70 75 74 20 6f 66 20 74 68 65 20 72 65 to put of the re
1d0e0 73 75 6c 74 73 20 6f 66 0a 2a 2a 20 61 20 53 45 sults of.** a SE
1d0f0 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 0a LECT statement..
1d100 2a 2f 0a 73 74 72 75 63 74 20 53 65 6c 65 63 74 */.struct Select
1d110 44 65 73 74 20 7b 0a 20 20 75 38 20 65 44 65 73 Dest {. u8 eDes
1d120 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a t; /*
1d130 20 48 6f 77 20 74 6f 20 64 69 73 70 6f 73 65 20 How to dispose
1d140 6f 66 20 74 68 65 20 72 65 73 75 6c 74 73 2e 20 of the results.
1d150 20 4f 6e 20 6f 66 20 53 52 54 5f 2a 20 61 62 6f On of SRT_* abo
1d160 76 65 2e 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a ve. */. char *z
1d170 41 66 66 53 64 73 74 3b 20 20 20 20 20 20 2f 2a AffSdst; /*
1d180 20 41 66 66 69 6e 69 74 79 20 75 73 65 64 20 77 Affinity used w
1d190 68 65 6e 20 65 44 65 73 74 3d 3d 53 52 54 5f 53 hen eDest==SRT_S
1d1a0 65 74 20 2a 2f 0a 20 20 69 6e 74 20 69 53 44 50 et */. int iSDP
1d1b0 61 72 6d 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 arm; /*
1d1c0 41 20 70 61 72 61 6d 65 74 65 72 20 75 73 65 64 A parameter used
1d1d0 20 62 79 20 74 68 65 20 65 44 65 73 74 20 64 69 by the eDest di
1d1e0 73 70 6f 73 61 6c 20 6d 65 74 68 6f 64 20 2a 2f sposal method */
1d1f0 0a 20 20 69 6e 74 20 69 53 64 73 74 3b 20 20 20 . int iSdst;
1d200 20 20 20 20 20 20 20 20 2f 2a 20 42 61 73 65 20 /* Base
1d210 72 65 67 69 73 74 65 72 20 77 68 65 72 65 20 72 register where r
1d220 65 73 75 6c 74 73 20 61 72 65 20 77 72 69 74 74 esults are writt
1d230 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 64 73 en */. int nSds
1d240 74 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 t; /*
1d250 4e 75 6d 62 65 72 20 6f 66 20 72 65 67 69 73 74 Number of regist
1d260 65 72 73 20 61 6c 6c 6f 63 61 74 65 64 20 2a 2f ers allocated */
1d270 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f 72 . ExprList *pOr
1d280 64 65 72 42 79 3b 20 20 2f 2a 20 4b 65 79 20 63 derBy; /* Key c
1d290 6f 6c 75 6d 6e 73 20 66 6f 72 20 53 52 54 5f 51 olumns for SRT_Q
1d2a0 75 65 75 65 20 61 6e 64 20 53 52 54 5f 44 69 73 ueue and SRT_Dis
1d2b0 74 51 75 65 75 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a tQueue */.};../*
1d2c0 0a 2a 2a 20 44 75 72 69 6e 67 20 63 6f 64 65 20 .** During code
1d2d0 67 65 6e 65 72 61 74 69 6f 6e 20 6f 66 20 73 74 generation of st
1d2e0 61 74 65 6d 65 6e 74 73 20 74 68 61 74 20 64 6f atements that do
1d2f0 20 69 6e 73 65 72 74 73 20 69 6e 74 6f 20 41 55 inserts into AU
1d300 54 4f 49 4e 43 52 45 4d 45 4e 54 0a 2a 2a 20 74 TOINCREMENT.** t
1d310 61 62 6c 65 73 2c 20 74 68 65 20 66 6f 6c 6c 6f ables, the follo
1d320 77 69 6e 67 20 69 6e 66 6f 72 6d 61 74 69 6f 6e wing information
1d330 20 69 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 is attached to
1d340 74 68 65 20 54 61 62 6c 65 2e 75 2e 61 75 74 6f the Table.u.auto
1d350 49 6e 63 2e 70 0a 2a 2a 20 70 6f 69 6e 74 65 72 Inc.p.** pointer
1d360 20 6f 66 20 65 61 63 68 20 61 75 74 6f 69 6e 63 of each autoinc
1d370 72 65 6d 65 6e 74 20 74 61 62 6c 65 20 74 6f 20 rement table to
1d380 72 65 63 6f 72 64 20 73 6f 6d 65 20 73 69 64 65 record some side
1d390 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 74 68 61 information tha
1d3a0 74 0a 2a 2a 20 74 68 65 20 63 6f 64 65 20 67 65 t.** the code ge
1d3b0 6e 65 72 61 74 6f 72 20 6e 65 65 64 73 2e 20 20 nerator needs.
1d3c0 57 65 20 68 61 76 65 20 74 6f 20 6b 65 65 70 20 We have to keep
1d3d0 70 65 72 2d 74 61 62 6c 65 20 61 75 74 6f 69 6e per-table autoin
1d3e0 63 72 65 6d 65 6e 74 0a 2a 2a 20 69 6e 66 6f 72 crement.** infor
1d3f0 6d 61 74 69 6f 6e 20 69 6e 20 63 61 73 65 20 69 mation in case i
1d400 6e 73 65 72 74 73 20 61 72 65 20 64 6f 6e 65 20 nserts are done
1d410 77 69 74 68 69 6e 20 74 72 69 67 67 65 72 73 2e within triggers.
1d420 20 20 54 72 69 67 67 65 72 73 20 64 6f 20 6e 6f Triggers do no
1d430 74 0a 2a 2a 20 6e 6f 72 6d 61 6c 6c 79 20 63 6f t.** normally co
1d440 6f 72 64 69 6e 61 74 65 20 74 68 65 69 72 20 61 ordinate their a
1d450 63 74 69 76 69 74 69 65 73 2c 20 62 75 74 20 77 ctivities, but w
1d460 65 20 64 6f 20 6e 65 65 64 20 74 6f 20 63 6f 6f e do need to coo
1d470 72 64 69 6e 61 74 65 20 74 68 65 0a 2a 2a 20 6c rdinate the.** l
1d480 6f 61 64 69 6e 67 20 61 6e 64 20 73 61 76 69 6e oading and savin
1d490 67 20 6f 66 20 61 75 74 6f 69 6e 63 72 65 6d 65 g of autoincreme
1d4a0 6e 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a nt information..
1d4b0 2a 2f 0a 73 74 72 75 63 74 20 41 75 74 6f 69 6e */.struct Autoin
1d4c0 63 49 6e 66 6f 20 7b 0a 20 20 41 75 74 6f 69 6e cInfo {. Autoin
1d4d0 63 49 6e 66 6f 20 2a 70 4e 65 78 74 3b 20 20 20 cInfo *pNext;
1d4e0 2f 2a 20 4e 65 78 74 20 69 6e 66 6f 20 62 6c 6f /* Next info blo
1d4f0 63 6b 20 69 6e 20 61 20 6c 69 73 74 20 6f 66 20 ck in a list of
1d500 74 68 65 6d 20 61 6c 6c 20 2a 2f 0a 20 20 54 61 them all */. Ta
1d510 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 20 ble *pTab;
1d520 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 74 68 69 /* Table thi
1d530 73 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 72 65 66 s info block ref
1d540 65 72 73 20 74 6f 20 2a 2f 0a 20 20 69 6e 74 20 ers to */. int
1d550 69 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 iDb;
1d560 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e 20 73 71 /* Index in sq
1d570 6c 69 74 65 33 2e 61 44 62 5b 5d 20 6f 66 20 64 lite3.aDb[] of d
1d580 61 74 61 62 61 73 65 20 68 6f 6c 64 69 6e 67 20 atabase holding
1d590 70 54 61 62 20 2a 2f 0a 20 20 69 6e 74 20 72 65 pTab */. int re
1d5a0 67 43 74 72 3b 20 20 20 20 20 20 20 20 20 20 20 gCtr;
1d5b0 2f 2a 20 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 /* Memory regist
1d5c0 65 72 20 68 6f 6c 64 69 6e 67 20 74 68 65 20 72 er holding the r
1d5d0 6f 77 69 64 20 63 6f 75 6e 74 65 72 20 2a 2f 0a owid counter */.
1d5e0 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 53 69 7a 65 20 6f };../*.** Size o
1d5f0 66 20 74 68 65 20 63 6f 6c 75 6d 6e 20 63 61 63 f the column cac
1d600 68 65 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 he.*/.#ifndef SQ
1d610 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 0a LITE_N_COLCACHE.
1d620 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f # define SQLITE_
1d630 4e 5f 43 4f 4c 43 41 43 48 45 20 31 30 0a 23 65 N_COLCACHE 10.#e
1d640 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 74 20 6c ndif../*.** At l
1d650 65 61 73 74 20 6f 6e 65 20 69 6e 73 74 61 6e 63 east one instanc
1d660 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
1d670 6e 67 20 73 74 72 75 63 74 75 72 65 20 69 73 20 ng structure is
1d680 63 72 65 61 74 65 64 20 66 6f 72 20 65 61 63 68 created for each
1d690 0a 2a 2a 20 74 72 69 67 67 65 72 20 74 68 61 74 .** trigger that
1d6a0 20 6d 61 79 20 62 65 20 66 69 72 65 64 20 77 68 may be fired wh
1d6b0 69 6c 65 20 70 61 72 73 69 6e 67 20 61 6e 20 49 ile parsing an I
1d6c0 4e 53 45 52 54 2c 20 55 50 44 41 54 45 20 6f 72 NSERT, UPDATE or
1d6d0 20 44 45 4c 45 54 45 0a 2a 2a 20 73 74 61 74 65 DELETE.** state
1d6e0 6d 65 6e 74 2e 20 41 6c 6c 20 73 75 63 68 20 6f ment. All such o
1d6f0 62 6a 65 63 74 73 20 61 72 65 20 73 74 6f 72 65 bjects are store
1d700 64 20 69 6e 20 74 68 65 20 6c 69 6e 6b 65 64 20 d in the linked
1d710 6c 69 73 74 20 68 65 61 64 65 64 20 61 74 0a 2a list headed at.*
1d720 2a 20 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 * Parse.pTrigger
1d730 50 72 67 20 61 6e 64 20 64 65 6c 65 74 65 64 20 Prg and deleted
1d740 6f 6e 63 65 20 73 74 61 74 65 6d 65 6e 74 20 63 once statement c
1d750 6f 6d 70 69 6c 61 74 69 6f 6e 20 68 61 73 20 62 ompilation has b
1d760 65 65 6e 0a 2a 2a 20 63 6f 6d 70 6c 65 74 65 64 een.** completed
1d770 2e 0a 2a 2a 0a 2a 2a 20 41 20 56 64 62 65 20 73 ..**.** A Vdbe s
1d780 75 62 2d 70 72 6f 67 72 61 6d 20 74 68 61 74 20 ub-program that
1d790 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68 65 20 62 implements the b
1d7a0 6f 64 79 20 61 6e 64 20 57 48 45 4e 20 63 6c 61 ody and WHEN cla
1d7b0 75 73 65 20 6f 66 20 74 72 69 67 67 65 72 0a 2a use of trigger.*
1d7c0 2a 20 54 72 69 67 67 65 72 50 72 67 2e 70 54 72 * TriggerPrg.pTr
1d7d0 69 67 67 65 72 2c 20 61 73 73 75 6d 69 6e 67 20 igger, assuming
1d7e0 61 20 64 65 66 61 75 6c 74 20 4f 4e 20 43 4f 4e a default ON CON
1d7f0 46 4c 49 43 54 20 63 6c 61 75 73 65 20 6f 66 0a FLICT clause of.
1d800 2a 2a 20 54 72 69 67 67 65 72 50 72 67 2e 6f 72 ** TriggerPrg.or
1d810 63 6f 6e 66 2c 20 69 73 20 73 74 6f 72 65 64 20 conf, is stored
1d820 69 6e 20 74 68 65 20 54 72 69 67 67 65 72 50 72 in the TriggerPr
1d830 67 2e 70 50 72 6f 67 72 61 6d 20 76 61 72 69 61 g.pProgram varia
1d840 62 6c 65 2e 0a 2a 2a 20 54 68 65 20 50 61 72 73 ble..** The Pars
1d850 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 6c 69 e.pTriggerPrg li
1d860 73 74 20 6e 65 76 65 72 20 63 6f 6e 74 61 69 6e st never contain
1d870 73 20 74 77 6f 20 65 6e 74 72 69 65 73 20 77 69 s two entries wi
1d880 74 68 20 74 68 65 20 73 61 6d 65 0a 2a 2a 20 76 th the same.** v
1d890 61 6c 75 65 73 20 66 6f 72 20 62 6f 74 68 20 70 alues for both p
1d8a0 54 72 69 67 67 65 72 20 61 6e 64 20 6f 72 63 6f Trigger and orco
1d8b0 6e 66 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 54 72 nf..**.** The Tr
1d8c0 69 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 iggerPrg.aColmas
1d8d0 6b 5b 30 5d 20 76 61 72 69 61 62 6c 65 20 69 73 k[0] variable is
1d8e0 20 73 65 74 20 74 6f 20 61 20 6d 61 73 6b 20 6f set to a mask o
1d8f0 66 20 6f 6c 64 2e 2a 20 63 6f 6c 75 6d 6e 73 0a f old.* columns.
1d900 2a 2a 20 61 63 63 65 73 73 65 64 20 28 6f 72 20 ** accessed (or
1d910 73 65 74 20 74 6f 20 30 20 66 6f 72 20 74 72 69 set to 0 for tri
1d920 67 67 65 72 73 20 66 69 72 65 64 20 61 73 20 61 ggers fired as a
1d930 20 72 65 73 75 6c 74 20 6f 66 20 49 4e 53 45 52 result of INSER
1d940 54 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 73 29 T.** statements)
1d950 2e 20 53 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65 . Similarly, the
1d960 20 54 72 69 67 67 65 72 50 72 67 2e 61 43 6f 6c TriggerPrg.aCol
1d970 6d 61 73 6b 5b 31 5d 20 76 61 72 69 61 62 6c 65 mask[1] variable
1d980 20 69 73 20 73 65 74 20 74 6f 0a 2a 2a 20 61 20 is set to.** a
1d990 6d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f mask of new.* co
1d9a0 6c 75 6d 6e 73 20 75 73 65 64 20 62 79 20 74 68 lumns used by th
1d9b0 65 20 70 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 e program..*/.st
1d9c0 72 75 63 74 20 54 72 69 67 67 65 72 50 72 67 20 ruct TriggerPrg
1d9d0 7b 0a 20 20 54 72 69 67 67 65 72 20 2a 70 54 72 {. Trigger *pTr
1d9e0 69 67 67 65 72 3b 20 20 20 20 20 20 2f 2a 20 54 igger; /* T
1d9f0 72 69 67 67 65 72 20 74 68 69 73 20 70 72 6f 67 rigger this prog
1da00 72 61 6d 20 77 61 73 20 63 6f 64 65 64 20 66 72 ram was coded fr
1da10 6f 6d 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 om */. TriggerP
1da20 72 67 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 rg *pNext;
1da30 2f 2a 20 4e 65 78 74 20 65 6e 74 72 79 20 69 6e /* Next entry in
1da40 20 50 61 72 73 65 2e 70 54 72 69 67 67 65 72 50 Parse.pTriggerP
1da50 72 67 20 6c 69 73 74 20 2a 2f 0a 20 20 53 75 62 rg list */. Sub
1da60 50 72 6f 67 72 61 6d 20 2a 70 50 72 6f 67 72 61 Program *pProgra
1da70 6d 3b 20 20 20 2f 2a 20 50 72 6f 67 72 61 6d 20 m; /* Program
1da80 69 6d 70 6c 65 6d 65 6e 74 69 6e 67 20 70 54 72 implementing pTr
1da90 69 67 67 65 72 2f 6f 72 63 6f 6e 66 20 2a 2f 0a igger/orconf */.
1daa0 20 20 69 6e 74 20 6f 72 63 6f 6e 66 3b 20 20 20 int orconf;
1dab0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 /* Def
1dac0 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 ault ON CONFLICT
1dad0 20 70 6f 6c 69 63 79 20 2a 2f 0a 20 20 75 33 32 policy */. u32
1dae0 20 61 43 6f 6c 6d 61 73 6b 5b 32 5d 3b 20 20 20 aColmask[2];
1daf0 20 20 20 20 20 2f 2a 20 4d 61 73 6b 73 20 6f 66 /* Masks of
1db00 20 6f 6c 64 2e 2a 2c 20 6e 65 77 2e 2a 20 63 6f old.*, new.* co
1db10 6c 75 6d 6e 73 20 61 63 63 65 73 73 65 64 20 2a lumns accessed *
1db20 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 /.};../*.** The
1db30 79 44 62 4d 61 73 6b 20 64 61 74 61 74 79 70 65 yDbMask datatype
1db40 20 66 6f 72 20 74 68 65 20 62 69 74 6d 61 73 6b for the bitmask
1db50 20 6f 66 20 61 6c 6c 20 61 74 74 61 63 68 65 64 of all attached
1db60 20 64 61 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 databases..*/.#
1db70 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 if SQLITE_MAX_AT
1db80 54 41 43 48 45 44 3e 33 30 0a 20 20 74 79 70 65 TACHED>30. type
1db90 64 65 66 20 75 6e 73 69 67 6e 65 64 20 63 68 61 def unsigned cha
1dba0 72 20 79 44 62 4d 61 73 6b 5b 28 53 51 4c 49 54 r yDbMask[(SQLIT
1dbb0 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 2b 39 E_MAX_ATTACHED+9
1dbc0 29 2f 38 5d 3b 0a 23 20 64 65 66 69 6e 65 20 44 )/8];.# define D
1dbd0 62 4d 61 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 bMaskTest(M,I)
1dbe0 20 20 28 28 28 4d 29 5b 28 49 29 2f 38 5d 26 28 (((M)[(I)/8]&(
1dbf0 31 3c 3c 28 28 49 29 26 37 29 29 29 21 3d 30 29 1<<((I)&7)))!=0)
1dc00 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b .# define DbMask
1dc10 5a 65 72 6f 28 4d 29 20 20 20 20 20 20 6d 65 6d Zero(M) mem
1dc20 73 65 74 28 28 4d 29 2c 30 2c 73 69 7a 65 6f 66 set((M),0,sizeof
1dc30 28 4d 29 29 0a 23 20 64 65 66 69 6e 65 20 44 62 (M)).# define Db
1dc40 4d 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 MaskSet(M,I)
1dc50 20 28 4d 29 5b 28 49 29 2f 38 5d 7c 3d 28 31 3c (M)[(I)/8]|=(1<
1dc60 3c 28 28 49 29 26 37 29 29 0a 23 20 64 65 66 69 <((I)&7)).# defi
1dc70 6e 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f ne DbMaskAllZero
1dc80 28 4d 29 20 20 20 73 71 6c 69 74 65 33 44 62 4d (M) sqlite3DbM
1dc90 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 0a 23 20 askAllZero(M).#
1dca0 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e define DbMaskNon
1dcb0 5a 65 72 6f 28 4d 29 20 20 20 28 73 71 6c 69 74 Zero(M) (sqlit
1dcc0 65 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 e3DbMaskAllZero(
1dcd0 4d 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 20 20 74 M)==0).#else. t
1dce0 79 70 65 64 65 66 20 75 6e 73 69 67 6e 65 64 20 ypedef unsigned
1dcf0 69 6e 74 20 79 44 62 4d 61 73 6b 3b 0a 23 20 64 int yDbMask;.# d
1dd00 65 66 69 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 efine DbMaskTest
1dd10 28 4d 2c 49 29 20 20 20 20 28 28 28 4d 29 26 28 (M,I) (((M)&(
1dd20 28 28 79 44 62 4d 61 73 6b 29 31 29 3c 3c 28 49 ((yDbMask)1)<<(I
1dd30 29 29 29 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 )))!=0).# define
1dd40 20 44 62 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 DbMaskZero(M)
1dd50 20 20 20 20 28 4d 29 3d 30 0a 23 20 64 65 66 69 (M)=0.# defi
1dd60 6e 65 20 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 ne DbMaskSet(M,I
1dd70 29 20 20 20 20 20 28 4d 29 7c 3d 28 28 28 79 44 ) (M)|=(((yD
1dd80 62 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 0a 23 bMask)1)<<(I)).#
1dd90 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c define DbMaskAl
1dda0 6c 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 3d 3d lZero(M) (M)==
1ddb0 30 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 0.# define DbMas
1ddc0 6b 4e 6f 6e 5a 65 72 6f 28 4d 29 20 20 20 28 4d kNonZero(M) (M
1ddd0 29 21 3d 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a )!=0.#endif../*.
1dde0 2a 2a 20 41 6e 20 53 51 4c 20 70 61 72 73 65 72 ** An SQL parser
1ddf0 20 63 6f 6e 74 65 78 74 2e 20 20 41 20 63 6f 70 context. A cop
1de00 79 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 y of this struct
1de10 75 72 65 20 69 73 20 70 61 73 73 65 64 20 74 68 ure is passed th
1de20 72 6f 75 67 68 0a 2a 2a 20 74 68 65 20 70 61 72 rough.** the par
1de30 73 65 72 20 61 6e 64 20 64 6f 77 6e 20 69 6e 74 ser and down int
1de40 6f 20 61 6c 6c 20 74 68 65 20 70 61 72 73 65 72 o all the parser
1de50 20 61 63 74 69 6f 6e 20 72 6f 75 74 69 6e 65 20 action routine
1de60 69 6e 20 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 63 in order to.** c
1de70 61 72 72 79 20 61 72 6f 75 6e 64 20 69 6e 66 6f arry around info
1de80 72 6d 61 74 69 6f 6e 20 74 68 61 74 20 69 73 20 rmation that is
1de90 67 6c 6f 62 61 6c 20 74 6f 20 74 68 65 20 65 6e global to the en
1dea0 74 69 72 65 20 70 61 72 73 65 2e 0a 2a 2a 0a 2a tire parse..**.*
1deb0 2a 20 54 68 65 20 73 74 72 75 63 74 75 72 65 20 * The structure
1dec0 69 73 20 64 69 76 69 64 65 64 20 69 6e 74 6f 20 is divided into
1ded0 74 77 6f 20 70 61 72 74 73 2e 20 20 57 68 65 6e two parts. When
1dee0 20 74 68 65 20 70 61 72 73 65 72 20 61 6e 64 20 the parser and
1def0 63 6f 64 65 0a 2a 2a 20 67 65 6e 65 72 61 74 65 code.** generate
1df00 20 63 61 6c 6c 20 74 68 65 6d 73 65 6c 76 65 73 call themselves
1df10 20 72 65 63 75 72 73 69 76 65 6c 79 2c 20 74 68 recursively, th
1df20 65 20 66 69 72 73 74 20 70 61 72 74 20 6f 66 20 e first part of
1df30 74 68 65 20 73 74 72 75 63 74 75 72 65 0a 2a 2a the structure.**
1df40 20 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 75 74 is constant but
1df50 20 74 68 65 20 73 65 63 6f 6e 64 20 70 61 72 74 the second part
1df60 20 69 73 20 72 65 73 65 74 20 61 74 20 74 68 65 is reset at the
1df70 20 62 65 67 69 6e 6e 69 6e 67 20 61 6e 64 20 65 beginning and e
1df80 6e 64 20 6f 66 0a 2a 2a 20 65 61 63 68 20 72 65 nd of.** each re
1df90 63 75 72 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 cursion..**.** T
1dfa0 68 65 20 6e 54 61 62 6c 65 4c 6f 63 6b 20 61 6e he nTableLock an
1dfb0 64 20 61 54 61 62 6c 65 4c 6f 63 6b 20 76 61 72 d aTableLock var
1dfc0 69 61 62 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 iables are only
1dfd0 75 73 65 64 20 69 66 20 74 68 65 20 73 68 61 72 used if the shar
1dfe0 65 64 2d 63 61 63 68 65 0a 2a 2a 20 66 65 61 74 ed-cache.** feat
1dff0 75 72 65 20 69 73 20 65 6e 61 62 6c 65 64 20 28 ure is enabled (
1e000 69 66 20 73 71 6c 69 74 65 33 54 73 64 28 29 2d if sqlite3Tsd()-
1e010 3e 75 73 65 53 68 61 72 65 64 44 61 74 61 20 69 >useSharedData i
1e020 73 20 74 72 75 65 29 2e 20 54 68 65 79 20 61 72 s true). They ar
1e030 65 0a 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f e.** used to sto
1e040 72 65 20 74 68 65 20 73 65 74 20 6f 66 20 74 61 re the set of ta
1e050 62 6c 65 2d 6c 6f 63 6b 73 20 72 65 71 75 69 72 ble-locks requir
1e060 65 64 20 62 79 20 74 68 65 20 73 74 61 74 65 6d ed by the statem
1e070 65 6e 74 20 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d ent being.** com
1e080 70 69 6c 65 64 2e 20 46 75 6e 63 74 69 6f 6e 20 piled. Function
1e090 73 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b sqlite3TableLock
1e0a0 28 29 20 69 73 20 75 73 65 64 20 74 6f 20 61 64 () is used to ad
1e0b0 64 20 65 6e 74 72 69 65 73 20 74 6f 20 74 68 65 d entries to the
1e0c0 0a 2a 2a 20 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 .** list..*/.str
1e0d0 75 63 74 20 50 61 72 73 65 20 7b 0a 20 20 73 71 uct Parse {. sq
1e0e0 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 lite3 *db;
1e0f0 20 20 20 2f 2a 20 54 68 65 20 6d 61 69 6e 20 64 /* The main d
1e100 61 74 61 62 61 73 65 20 73 74 72 75 63 74 75 72 atabase structur
1e110 65 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 45 72 e */. char *zEr
1e120 72 4d 73 67 3b 20 20 20 20 20 20 20 2f 2a 20 41 rMsg; /* A
1e130 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 n error message
1e140 2a 2f 0a 20 20 56 64 62 65 20 2a 70 56 64 62 65 */. Vdbe *pVdbe
1e150 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 ; /* An
1e160 65 6e 67 69 6e 65 20 66 6f 72 20 65 78 65 63 75 engine for execu
1e170 74 69 6e 67 20 64 61 74 61 62 61 73 65 20 62 79 ting database by
1e180 74 65 63 6f 64 65 20 2a 2f 0a 20 20 69 6e 74 20 tecode */. int
1e190 72 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 rc;
1e1a0 20 2f 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 /* Return code
1e1b0 66 72 6f 6d 20 65 78 65 63 75 74 69 6f 6e 20 2a from execution *
1e1c0 2f 0a 20 20 75 38 20 63 6f 6c 4e 61 6d 65 73 53 /. u8 colNamesS
1e1d0 65 74 3b 20 20 20 20 20 20 2f 2a 20 54 52 55 45 et; /* TRUE
1e1e0 20 61 66 74 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e after OP_Column
1e1f0 4e 61 6d 65 20 68 61 73 20 62 65 65 6e 20 69 73 Name has been is
1e200 73 75 65 64 20 74 6f 20 70 56 64 62 65 20 2a 2f sued to pVdbe */
1e210 0a 20 20 75 38 20 63 68 65 63 6b 53 63 68 65 6d . u8 checkSchem
1e220 61 3b 20 20 20 20 20 20 2f 2a 20 43 61 75 73 65 a; /* Cause
1e230 73 20 73 63 68 65 6d 61 20 63 6f 6f 6b 69 65 20 s schema cookie
1e240 63 68 65 63 6b 20 61 66 74 65 72 20 61 6e 20 65 check after an e
1e250 72 72 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 65 73 rror */. u8 nes
1e260 74 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f ted; /
1e270 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 * Number of nest
1e280 65 64 20 63 61 6c 6c 73 20 74 6f 20 74 68 65 20 ed calls to the
1e290 70 61 72 73 65 72 2f 63 6f 64 65 20 67 65 6e 65 parser/code gene
1e2a0 72 61 74 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 54 rator */. u8 nT
1e2b0 65 6d 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 empReg;
1e2c0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 74 65 6d /* Number of tem
1e2d0 70 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 73 porary registers
1e2e0 20 69 6e 20 61 54 65 6d 70 52 65 67 5b 5d 20 2a in aTempReg[] *
1e2f0 2f 0a 20 20 75 38 20 69 73 4d 75 6c 74 69 57 72 /. u8 isMultiWr
1e300 69 74 65 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 ite; /* True
1e310 20 69 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 if statement ma
1e320 79 20 6d 6f 64 69 66 79 2f 69 6e 73 65 72 74 20 y modify/insert
1e330 6d 75 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f multiple rows */
1e340 0a 20 20 75 38 20 6d 61 79 41 62 6f 72 74 3b 20 . u8 mayAbort;
1e350 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1e360 69 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 if statement may
1e370 20 74 68 72 6f 77 20 61 6e 20 41 42 4f 52 54 20 throw an ABORT
1e380 65 78 63 65 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 exception */. u
1e390 38 20 68 61 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 8 hasCompound;
1e3a0 20 20 20 20 2f 2a 20 4e 65 65 64 20 74 6f 20 69 /* Need to i
1e3b0 6e 76 6f 6b 65 20 63 6f 6e 76 65 72 74 43 6f 6d nvoke convertCom
1e3c0 70 6f 75 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 poundSelectToSub
1e3d0 71 75 65 72 79 28 29 20 2a 2f 0a 20 20 75 38 20 query() */. u8
1e3e0 6f 6b 43 6f 6e 73 74 46 61 63 74 6f 72 3b 20 20 okConstFactor;
1e3f0 20 20 2f 2a 20 4f 4b 20 74 6f 20 66 61 63 74 6f /* OK to facto
1e400 72 20 6f 75 74 20 63 6f 6e 73 74 61 6e 74 73 20 r out constants
1e410 2a 2f 0a 20 20 75 38 20 64 69 73 61 62 6c 65 4c */. u8 disableL
1e420 6f 6f 6b 61 73 69 64 65 3b 20 2f 2a 20 4e 75 6d ookaside; /* Num
1e430 62 65 72 20 6f 66 20 74 69 6d 65 73 20 6c 6f 6f ber of times loo
1e440 6b 61 73 69 64 65 20 68 61 73 20 62 65 65 6e 20 kaside has been
1e450 64 69 73 61 62 6c 65 64 20 2a 2f 0a 20 20 75 38 disabled */. u8
1e460 20 6e 43 6f 6c 43 61 63 68 65 3b 20 20 20 20 20 nColCache;
1e470 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1e480 65 6e 74 72 69 65 73 20 69 6e 20 61 43 6f 6c 43 entries in aColC
1e490 61 63 68 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 ache[] */. int
1e4a0 6e 52 61 6e 67 65 52 65 67 3b 20 20 20 20 20 20 nRangeReg;
1e4b0 20 2f 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 20 /* Size of the
1e4c0 74 65 6d 70 6f 72 61 72 79 20 72 65 67 69 73 74 temporary regist
1e4d0 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 6e er block */. in
1e4e0 74 20 69 52 61 6e 67 65 52 65 67 3b 20 20 20 20 t iRangeReg;
1e4f0 20 20 20 2f 2a 20 46 69 72 73 74 20 72 65 67 69 /* First regi
1e500 73 74 65 72 20 69 6e 20 74 65 6d 70 6f 72 61 72 ster in temporar
1e510 79 20 72 65 67 69 73 74 65 72 20 62 6c 6f 63 6b y register block
1e520 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 72 72 3b 20 */. int nErr;
1e530 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1e540 6d 62 65 72 20 6f 66 20 65 72 72 6f 72 73 20 73 mber of errors s
1e550 65 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 61 een */. int nTa
1e560 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a b; /*
1e570 20 4e 75 6d 62 65 72 20 6f 66 20 70 72 65 76 69 Number of previ
1e580 6f 75 73 6c 79 20 61 6c 6c 6f 63 61 74 65 64 20 ously allocated
1e590 56 44 42 45 20 63 75 72 73 6f 72 73 20 2a 2f 0a VDBE cursors */.
1e5a0 20 20 69 6e 74 20 6e 4d 65 6d 3b 20 20 20 20 20 int nMem;
1e5b0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1e5c0 20 6f 66 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 73 of memory cells
1e5d0 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a used so far */.
1e5e0 20 20 69 6e 74 20 6e 4f 70 41 6c 6c 6f 63 3b 20 int nOpAlloc;
1e5f0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1e600 20 6f 66 20 73 6c 6f 74 73 20 61 6c 6c 6f 63 61 of slots alloca
1e610 74 65 64 20 66 6f 72 20 56 64 62 65 2e 61 4f 70 ted for Vdbe.aOp
1e620 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 4f 70 [] */. int szOp
1e630 41 6c 6c 6f 63 3b 20 20 20 20 20 20 20 2f 2a 20 Alloc; /*
1e640 42 79 74 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 Bytes of memory
1e650 73 70 61 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 space allocated
1e660 66 6f 72 20 56 64 62 65 2e 61 4f 70 5b 5d 20 2a for Vdbe.aOp[] *
1e670 2f 0a 20 20 69 6e 74 20 63 6b 42 61 73 65 3b 20 /. int ckBase;
1e680 20 20 20 20 20 20 20 20 20 2f 2a 20 42 61 73 65 /* Base
1e690 20 72 65 67 69 73 74 65 72 20 6f 66 20 64 61 74 register of dat
1e6a0 61 20 64 75 72 69 6e 67 20 63 68 65 63 6b 20 63 a during check c
1e6b0 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20 onstraints */.
1e6c0 69 6e 74 20 69 53 65 6c 66 54 61 62 3b 20 20 20 int iSelfTab;
1e6d0 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 6f 66 /* Table of
1e6e0 20 61 6e 20 69 6e 64 65 78 20 77 68 6f 73 65 20 an index whose
1e6f0 65 78 70 72 73 20 61 72 65 20 62 65 69 6e 67 20 exprs are being
1e700 63 6f 64 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 coded */. int i
1e710 43 61 63 68 65 4c 65 76 65 6c 3b 20 20 20 20 20 CacheLevel;
1e720 2f 2a 20 43 6f 6c 43 61 63 68 65 20 76 61 6c 69 /* ColCache vali
1e730 64 20 77 68 65 6e 20 61 43 6f 6c 43 61 63 68 65 d when aColCache
1e740 5b 5d 2e 69 4c 65 76 65 6c 3c 3d 69 43 61 63 68 [].iLevel<=iCach
1e750 65 4c 65 76 65 6c 20 2a 2f 0a 20 20 69 6e 74 20 eLevel */. int
1e760 69 43 61 63 68 65 43 6e 74 3b 20 20 20 20 20 20 iCacheCnt;
1e770 20 2f 2a 20 43 6f 75 6e 74 65 72 20 75 73 65 64 /* Counter used
1e780 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61 43 6f to generate aCo
1e790 6c 43 61 63 68 65 5b 5d 2e 6c 72 75 20 76 61 6c lCache[].lru val
1e7a0 75 65 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 4c 61 ues */. int nLa
1e7b0 62 65 6c 3b 20 20 20 20 20 20 20 20 20 20 2f 2a bel; /*
1e7c0 20 4e 75 6d 62 65 72 20 6f 66 20 6c 61 62 65 6c Number of label
1e7d0 73 20 75 73 65 64 20 2a 2f 0a 20 20 69 6e 74 20 s used */. int
1e7e0 2a 61 4c 61 62 65 6c 3b 20 20 20 20 20 20 20 20 *aLabel;
1e7f0 20 2f 2a 20 53 70 61 63 65 20 74 6f 20 68 6f 6c /* Space to hol
1e800 64 20 74 68 65 20 6c 61 62 65 6c 73 20 2a 2f 0a d the labels */.
1e810 20 20 45 78 70 72 4c 69 73 74 20 2a 70 43 6f 6e ExprList *pCon
1e820 73 74 45 78 70 72 3b 2f 2a 20 43 6f 6e 73 74 61 stExpr;/* Consta
1e830 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 73 20 2a nt expressions *
1e840 2f 0a 20 20 54 6f 6b 65 6e 20 63 6f 6e 73 74 72 /. Token constr
1e850 61 69 6e 74 4e 61 6d 65 3b 2f 2a 20 4e 61 6d 65 aintName;/* Name
1e860 20 6f 66 20 74 68 65 20 63 6f 6e 73 74 72 61 69 of the constrai
1e870 6e 74 20 63 75 72 72 65 6e 74 6c 79 20 62 65 69 nt currently bei
1e880 6e 67 20 70 61 72 73 65 64 20 2a 2f 0a 20 20 79 ng parsed */. y
1e890 44 62 4d 61 73 6b 20 77 72 69 74 65 4d 61 73 6b DbMask writeMask
1e8a0 3b 20 20 20 2f 2a 20 53 74 61 72 74 20 61 20 77 ; /* Start a w
1e8b0 72 69 74 65 20 74 72 61 6e 73 61 63 74 69 6f 6e rite transaction
1e8c0 20 6f 6e 20 74 68 65 73 65 20 64 61 74 61 62 61 on these databa
1e8d0 73 65 73 20 2a 2f 0a 20 20 79 44 62 4d 61 73 6b ses */. yDbMask
1e8e0 20 63 6f 6f 6b 69 65 4d 61 73 6b 3b 20 20 2f 2a cookieMask; /*
1e8f0 20 42 69 74 6d 61 73 6b 20 6f 66 20 73 63 68 65 Bitmask of sche
1e900 6d 61 20 76 65 72 69 66 69 65 64 20 64 61 74 61 ma verified data
1e910 62 61 73 65 73 20 2a 2f 0a 20 20 69 6e 74 20 72 bases */. int r
1e920 65 67 52 6f 77 69 64 3b 20 20 20 20 20 20 20 20 egRowid;
1e930 2f 2a 20 52 65 67 69 73 74 65 72 20 68 6f 6c 64 /* Register hold
1e940 69 6e 67 20 72 6f 77 69 64 20 6f 66 20 43 52 45 ing rowid of CRE
1e950 41 54 45 20 54 41 42 4c 45 20 65 6e 74 72 79 20 ATE TABLE entry
1e960 2a 2f 0a 20 20 69 6e 74 20 72 65 67 52 6f 6f 74 */. int regRoot
1e970 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 67 ; /* Reg
1e980 69 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 6f ister holding ro
1e990 6f 74 20 70 61 67 65 20 6e 75 6d 62 65 72 20 66 ot page number f
1e9a0 6f 72 20 6e 65 77 20 6f 62 6a 65 63 74 73 20 2a or new objects *
1e9b0 2f 0a 20 20 69 6e 74 20 6e 4d 61 78 41 72 67 3b /. int nMaxArg;
1e9c0 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 20 /* Max
1e9d0 61 72 67 73 20 70 61 73 73 65 64 20 74 6f 20 75 args passed to u
1e9e0 73 65 72 20 66 75 6e 63 74 69 6f 6e 20 62 79 20 ser function by
1e9f0 73 75 62 2d 70 72 6f 67 72 61 6d 20 2a 2f 0a 23 sub-program */.#
1ea00 69 66 20 53 45 4c 45 43 54 54 52 41 43 45 5f 45 if SELECTTRACE_E
1ea10 4e 41 42 4c 45 44 0a 20 20 69 6e 74 20 6e 53 65 NABLED. int nSe
1ea20 6c 65 63 74 3b 20 20 20 20 20 20 20 20 20 2f 2a lect; /*
1ea30 20 4e 75 6d 62 65 72 20 6f 66 20 53 45 4c 45 43 Number of SELEC
1ea40 54 20 73 74 61 74 65 6d 65 6e 74 73 20 73 65 65 T statements see
1ea50 6e 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 65 6c 65 n */. int nSele
1ea60 63 74 49 6e 64 65 6e 74 3b 20 20 20 2f 2a 20 48 ctIndent; /* H
1ea70 6f 77 20 66 61 72 20 74 6f 20 69 6e 64 65 6e 74 ow far to indent
1ea80 20 53 45 4c 45 43 54 54 52 41 43 45 28 29 20 6f SELECTTRACE() o
1ea90 75 74 70 75 74 20 2a 2f 0a 23 65 6e 64 69 66 0a utput */.#endif.
1eaa0 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1eab0 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 45 MIT_SHARED_CACHE
1eac0 0a 20 20 69 6e 74 20 6e 54 61 62 6c 65 4c 6f 63 . int nTableLoc
1ead0 6b 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d k; /* Num
1eae0 62 65 72 20 6f 66 20 6c 6f 63 6b 73 20 69 6e 20 ber of locks in
1eaf0 61 54 61 62 6c 65 4c 6f 63 6b 20 2a 2f 0a 20 20 aTableLock */.
1eb00 54 61 62 6c 65 4c 6f 63 6b 20 2a 61 54 61 62 6c TableLock *aTabl
1eb10 65 4c 6f 63 6b 3b 20 2f 2a 20 52 65 71 75 69 72 eLock; /* Requir
1eb20 65 64 20 74 61 62 6c 65 20 6c 6f 63 6b 73 20 66 ed table locks f
1eb30 6f 72 20 73 68 61 72 65 64 2d 63 61 63 68 65 20 or shared-cache
1eb40 6d 6f 64 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 mode */.#endif.
1eb50 20 41 75 74 6f 69 6e 63 49 6e 66 6f 20 2a 70 41 AutoincInfo *pA
1eb60 69 6e 63 3b 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 inc; /* Informa
1eb70 74 69 6f 6e 20 61 62 6f 75 74 20 41 55 54 4f 49 tion about AUTOI
1eb80 4e 43 52 45 4d 45 4e 54 20 63 6f 75 6e 74 65 72 NCREMENT counter
1eb90 73 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 54 s */. Parse *pT
1eba0 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a 20 50 oplevel; /* P
1ebb0 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 66 arse structure f
1ebc0 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 6d 20 or main program
1ebd0 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 54 (or NULL) */. T
1ebe0 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 54 61 able *pTriggerTa
1ebf0 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 72 69 b; /* Table tri
1ec00 67 67 65 72 73 20 61 72 65 20 62 65 69 6e 67 20 ggers are being
1ec10 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 20 69 coded for */. i
1ec20 6e 74 20 61 64 64 72 43 72 54 61 62 3b 20 20 20 nt addrCrTab;
1ec30 20 20 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f /* Address o
1ec40 66 20 4f 50 5f 43 72 65 61 74 65 54 61 62 6c 65 f OP_CreateTable
1ec50 20 6f 70 63 6f 64 65 20 6f 6e 20 43 52 45 41 54 opcode on CREAT
1ec60 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 75 33 32 E TABLE */. u32
1ec70 20 6e 51 75 65 72 79 4c 6f 6f 70 3b 20 20 20 20 nQueryLoop;
1ec80 20 20 2f 2a 20 45 73 74 20 6e 75 6d 62 65 72 20 /* Est number
1ec90 6f 66 20 69 74 65 72 61 74 69 6f 6e 73 20 6f 66 of iterations of
1eca0 20 61 20 71 75 65 72 79 20 28 31 30 2a 6c 6f 67 a query (10*log
1ecb0 32 28 4e 29 29 20 2a 2f 0a 20 20 75 33 32 20 6f 2(N)) */. u32 o
1ecc0 6c 64 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 ldmask;
1ecd0 2f 2a 20 4d 61 73 6b 20 6f 66 20 6f 6c 64 2e 2a /* Mask of old.*
1ece0 20 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e columns referen
1ecf0 63 65 64 20 2a 2f 0a 20 20 75 33 32 20 6e 65 77 ced */. u32 new
1ed00 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f 2a mask; /*
1ed10 20 4d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 Mask of new.* c
1ed20 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 65 olumns reference
1ed30 64 20 2a 2f 0a 20 20 75 38 20 65 54 72 69 67 67 d */. u8 eTrigg
1ed40 65 72 4f 70 3b 20 20 20 20 20 20 20 2f 2a 20 54 erOp; /* T
1ed50 4b 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 K_UPDATE, TK_INS
1ed60 45 52 54 20 6f 72 20 54 4b 5f 44 45 4c 45 54 45 ERT or TK_DELETE
1ed70 20 2a 2f 0a 20 20 75 38 20 65 4f 72 63 6f 6e 66 */. u8 eOrconf
1ed80 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 ; /* De
1ed90 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 fault ON CONFLIC
1eda0 54 20 70 6f 6c 69 63 79 20 66 6f 72 20 74 72 69 T policy for tri
1edb0 67 67 65 72 20 73 74 65 70 73 20 2a 2f 0a 20 20 gger steps */.
1edc0 75 38 20 64 69 73 61 62 6c 65 54 72 69 67 67 65 u8 disableTrigge
1edd0 72 73 3b 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 rs; /* True to
1ede0 64 69 73 61 62 6c 65 20 74 72 69 67 67 65 72 73 disable triggers
1edf0 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a 2a 2a */.. /********
1ee00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ee10 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ee20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ee30 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ee40 2a 2a 0a 20 20 2a 2a 20 46 69 65 6c 64 73 20 61 **. ** Fields a
1ee50 62 6f 76 65 20 6d 75 73 74 20 62 65 20 69 6e 69 bove must be ini
1ee60 74 69 61 6c 69 7a 65 64 20 74 6f 20 7a 65 72 6f tialized to zero
1ee70 2e 20 20 54 68 65 20 66 69 65 6c 64 73 20 74 68 . The fields th
1ee80 61 74 20 66 6f 6c 6c 6f 77 2c 0a 20 20 2a 2a 20 at follow,. **
1ee90 64 6f 77 6e 20 74 6f 20 74 68 65 20 62 65 67 69 down to the begi
1eea0 6e 6e 69 6e 67 20 6f 66 20 74 68 65 20 72 65 63 nning of the rec
1eeb0 75 72 73 69 76 65 20 73 65 63 74 69 6f 6e 2c 20 ursive section,
1eec0 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 62 do not need to b
1eed0 65 0a 20 20 2a 2a 20 69 6e 69 74 69 61 6c 69 7a e. ** initializ
1eee0 65 64 20 61 73 20 74 68 65 79 20 77 69 6c 6c 20 ed as they will
1eef0 62 65 20 73 65 74 20 62 65 66 6f 72 65 20 62 65 be set before be
1ef00 69 6e 67 20 75 73 65 64 2e 20 20 54 68 65 20 62 ing used. The b
1ef10 6f 75 6e 64 61 72 79 20 69 73 0a 20 20 2a 2a 20 oundary is. **
1ef20 64 65 74 65 72 6d 69 6e 65 64 20 62 79 20 6f 66 determined by of
1ef30 66 73 65 74 6f 66 28 50 61 72 73 65 2c 61 43 6f fsetof(Parse,aCo
1ef40 6c 43 61 63 68 65 29 2e 0a 20 20 2a 2a 2a 2a 2a lCache).. *****
1ef50 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ef60 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ef70 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ef80 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1ef90 2a 2a 2a 2a 2a 2f 0a 0a 20 20 73 74 72 75 63 74 *****/.. struct
1efa0 20 79 43 6f 6c 43 61 63 68 65 20 7b 0a 20 20 20 yColCache {.
1efb0 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 int iTable;
1efc0 20 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 /* Table
1efd0 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 20 2a 2f cursor number */
1efe0 0a 20 20 20 20 69 31 36 20 69 43 6f 6c 75 6d 6e . i16 iColumn
1eff0 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 61 ; /* Ta
1f000 62 6c 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62 65 ble column numbe
1f010 72 20 2a 2f 0a 20 20 20 20 75 38 20 74 65 6d 70 r */. u8 temp
1f020 52 65 67 3b 20 20 20 20 20 20 20 20 20 20 20 2f Reg; /
1f030 2a 20 69 52 65 67 20 69 73 20 61 20 74 65 6d 70 * iReg is a temp
1f040 20 72 65 67 69 73 74 65 72 20 74 68 61 74 20 6e register that n
1f050 65 65 64 73 20 74 6f 20 62 65 20 66 72 65 65 64 eeds to be freed
1f060 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 4c 65 76 */. int iLev
1f070 65 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a el; /*
1f080 20 4e 65 73 74 69 6e 67 20 6c 65 76 65 6c 20 2a Nesting level *
1f090 2f 0a 20 20 20 20 69 6e 74 20 69 52 65 67 3b 20 /. int iReg;
1f0a0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 /* R
1f0b0 65 67 20 77 69 74 68 20 76 61 6c 75 65 20 6f 66 eg with value of
1f0c0 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e 20 30 20 this column. 0
1f0d0 6d 65 61 6e 73 20 6e 6f 6e 65 2e 20 2a 2f 0a 20 means none. */.
1f0e0 20 20 20 69 6e 74 20 6c 72 75 3b 20 20 20 20 20 int lru;
1f0f0 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 61 73 /* Leas
1f100 74 20 72 65 63 65 6e 74 6c 79 20 75 73 65 64 20 t recently used
1f110 65 6e 74 72 79 20 68 61 73 20 74 68 65 20 73 6d entry has the sm
1f120 61 6c 6c 65 73 74 20 76 61 6c 75 65 20 2a 2f 0a allest value */.
1f130 20 20 7d 20 61 43 6f 6c 43 61 63 68 65 5b 53 51 } aColCache[SQ
1f140 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 48 45 5d LITE_N_COLCACHE]
1f150 3b 20 20 2f 2a 20 4f 6e 65 20 66 6f 72 20 65 61 ; /* One for ea
1f160 63 68 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 20 ch column cache
1f170 65 6e 74 72 79 20 2a 2f 0a 20 20 69 6e 74 20 61 entry */. int a
1f180 54 65 6d 70 52 65 67 5b 38 5d 3b 20 20 20 20 20 TempReg[8];
1f190 20 20 20 2f 2a 20 48 6f 6c 64 69 6e 67 20 61 72 /* Holding ar
1f1a0 65 61 20 66 6f 72 20 74 65 6d 70 6f 72 61 72 79 ea for temporary
1f1b0 20 72 65 67 69 73 74 65 72 73 20 2a 2f 0a 20 20 registers */.
1f1c0 54 6f 6b 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 6e Token sNameToken
1f1d0 3b 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e ; /* Token
1f1e0 20 77 69 74 68 20 75 6e 71 75 61 6c 69 66 69 65 with unqualifie
1f1f0 64 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 20 d schema object
1f200 6e 61 6d 65 20 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a name */.. /****
1f210 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f220 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f230 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f240 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f250 2a 2a 2a 2a 0a 20 20 2a 2a 20 41 62 6f 76 65 20 ****. ** Above
1f260 69 73 20 63 6f 6e 73 74 61 6e 74 20 62 65 74 77 is constant betw
1f270 65 65 6e 20 72 65 63 75 72 73 69 6f 6e 73 2e 20 een recursions.
1f280 20 42 65 6c 6f 77 20 69 73 20 72 65 73 65 74 20 Below is reset
1f290 62 65 66 6f 72 65 20 61 6e 64 20 61 66 74 65 72 before and after
1f2a0 0a 20 20 2a 2a 20 65 61 63 68 20 72 65 63 75 72 . ** each recur
1f2b0 73 69 6f 6e 2e 20 20 54 68 65 20 62 6f 75 6e 64 sion. The bound
1f2c0 61 72 79 20 62 65 74 77 65 65 6e 20 74 68 65 73 ary between thes
1f2d0 65 20 74 77 6f 20 72 65 67 69 6f 6e 73 20 69 73 e two regions is
1f2e0 20 64 65 74 65 72 6d 69 6e 65 64 0a 20 20 2a 2a determined. **
1f2f0 20 75 73 69 6e 67 20 6f 66 66 73 65 74 6f 66 28 using offsetof(
1f300 50 61 72 73 65 2c 73 4c 61 73 74 54 6f 6b 65 6e Parse,sLastToken
1f310 29 20 73 6f 20 74 68 65 20 73 4c 61 73 74 54 6f ) so the sLastTo
1f320 6b 65 6e 20 66 69 65 6c 64 20 6d 75 73 74 20 62 ken field must b
1f330 65 20 74 68 65 0a 20 20 2a 2a 20 66 69 72 73 74 e the. ** first
1f340 20 66 69 65 6c 64 20 69 6e 20 74 68 65 20 72 65 field in the re
1f350 63 75 72 73 69 76 65 20 72 65 67 69 6f 6e 2e 0a cursive region..
1f360 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a **************
1f370 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f380 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f390 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1f3a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 54 **********/.. T
1f3b0 6f 6b 65 6e 20 73 4c 61 73 74 54 6f 6b 65 6e 3b oken sLastToken;
1f3c0 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6c 61 /* The la
1f3d0 73 74 20 74 6f 6b 65 6e 20 70 61 72 73 65 64 20 st token parsed
1f3e0 2a 2f 0a 20 20 79 6e 56 61 72 20 6e 56 61 72 3b */. ynVar nVar;
1f3f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1f400 2a 20 4e 75 6d 62 65 72 20 6f 66 20 27 3f 27 20 * Number of '?'
1f410 76 61 72 69 61 62 6c 65 73 20 73 65 65 6e 20 69 variables seen i
1f420 6e 20 74 68 65 20 53 51 4c 20 73 6f 20 66 61 72 n the SQL so far
1f430 20 2a 2f 0a 20 20 69 6e 74 20 6e 7a 56 61 72 3b */. int nzVar;
1f440 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1f450 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 61 76 61 /* Number of ava
1f460 69 6c 61 62 6c 65 20 73 6c 6f 74 73 20 69 6e 20 ilable slots in
1f470 61 7a 56 61 72 5b 5d 20 2a 2f 0a 20 20 75 38 20 azVar[] */. u8
1f480 69 50 6b 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 iPkSortOrder;
1f490 20 20 20 20 20 20 20 2f 2a 20 41 53 43 20 6f 72 /* ASC or
1f4a0 20 44 45 53 43 20 66 6f 72 20 49 4e 54 45 47 45 DESC for INTEGE
1f4b0 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 2a 2f R PRIMARY KEY */
1f4c0 0a 20 20 75 38 20 65 78 70 6c 61 69 6e 3b 20 20 . u8 explain;
1f4d0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1f4e0 54 72 75 65 20 69 66 20 74 68 65 20 45 58 50 4c True if the EXPL
1f4f0 41 49 4e 20 66 6c 61 67 20 69 73 20 66 6f 75 6e AIN flag is foun
1f500 64 20 6f 6e 20 74 68 65 20 71 75 65 72 79 20 2a d on the query *
1f510 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 /.#ifndef SQLITE
1f520 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
1f530 4c 45 0a 20 20 75 38 20 64 65 63 6c 61 72 65 56 LE. u8 declareV
1f540 74 61 62 3b 20 20 20 20 20 20 20 20 20 20 20 2f tab; /
1f550 2a 20 54 72 75 65 20 69 66 20 69 6e 73 69 64 65 * True if inside
1f560 20 73 71 6c 69 74 65 33 5f 64 65 63 6c 61 72 65 sqlite3_declare
1f570 5f 76 74 61 62 28 29 20 2a 2f 0a 20 20 69 6e 74 _vtab() */. int
1f580 20 6e 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 nVtabLock;
1f590 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1f5a0 20 6f 66 20 76 69 72 74 75 61 6c 20 74 61 62 6c of virtual tabl
1f5b0 65 73 20 74 6f 20 6c 6f 63 6b 20 2a 2f 0a 23 65 es to lock */.#e
1f5c0 6e 64 69 66 0a 20 20 69 6e 74 20 6e 48 65 69 67 ndif. int nHeig
1f5d0 68 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ht;
1f5e0 20 2f 2a 20 45 78 70 72 65 73 73 69 6f 6e 20 74 /* Expression t
1f5f0 72 65 65 20 68 65 69 67 68 74 20 6f 66 20 63 75 ree height of cu
1f600 72 72 65 6e 74 20 73 75 62 2d 73 65 6c 65 63 74 rrent sub-select
1f610 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 */.#ifndef SQLI
1f620 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e 0a TE_OMIT_EXPLAIN.
1f630 20 20 69 6e 74 20 69 53 65 6c 65 63 74 49 64 3b int iSelectId;
1f640 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 /* I
1f650 44 20 6f 66 20 63 75 72 72 65 6e 74 20 73 65 6c D of current sel
1f660 65 63 74 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 ect for EXPLAIN
1f670 6f 75 74 70 75 74 20 2a 2f 0a 20 20 69 6e 74 20 output */. int
1f680 69 4e 65 78 74 53 65 6c 65 63 74 49 64 3b 20 20 iNextSelectId;
1f690 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 61 76 /* Next av
1f6a0 61 69 6c 61 62 6c 65 20 73 65 6c 65 63 74 20 49 ailable select I
1f6b0 44 20 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f 75 D for EXPLAIN ou
1f6c0 74 70 75 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 tput */.#endif.
1f6d0 20 63 68 61 72 20 2a 2a 61 7a 56 61 72 3b 20 20 char **azVar;
1f6e0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 50 6f /* Po
1f6f0 69 6e 74 65 72 73 20 74 6f 20 6e 61 6d 65 73 20 inters to names
1f700 6f 66 20 70 61 72 61 6d 65 74 65 72 73 20 2a 2f of parameters */
1f710 0a 20 20 56 64 62 65 20 2a 70 52 65 70 72 65 70 . Vdbe *pReprep
1f720 61 72 65 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 are; /*
1f730 56 4d 20 62 65 69 6e 67 20 72 65 70 72 65 70 61 VM being reprepa
1f740 72 65 64 20 28 73 71 6c 69 74 65 33 52 65 70 72 red (sqlite3Repr
1f750 65 70 61 72 65 28 29 29 20 2a 2f 0a 20 20 63 6f epare()) */. co
1f760 6e 73 74 20 63 68 61 72 20 2a 7a 54 61 69 6c 3b nst char *zTail;
1f770 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 53 /* All S
1f780 51 4c 20 74 65 78 74 20 70 61 73 74 20 74 68 65 QL text past the
1f790 20 6c 61 73 74 20 73 65 6d 69 63 6f 6c 6f 6e 20 last semicolon
1f7a0 70 61 72 73 65 64 20 2a 2f 0a 20 20 54 61 62 6c parsed */. Tabl
1f7b0 65 20 2a 70 4e 65 77 54 61 62 6c 65 3b 20 20 20 e *pNewTable;
1f7c0 20 20 20 20 20 20 2f 2a 20 41 20 74 61 62 6c 65 /* A table
1f7d0 20 62 65 69 6e 67 20 63 6f 6e 73 74 72 75 63 74 being construct
1f7e0 65 64 20 62 79 20 43 52 45 41 54 45 20 54 41 42 ed by CREATE TAB
1f7f0 4c 45 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 20 LE */. Trigger
1f800 2a 70 4e 65 77 54 72 69 67 67 65 72 3b 20 20 20 *pNewTrigger;
1f810 20 20 2f 2a 20 54 72 69 67 67 65 72 20 75 6e 64 /* Trigger und
1f820 65 72 20 63 6f 6e 73 74 72 75 63 74 20 62 79 20 er construct by
1f830 61 20 43 52 45 41 54 45 20 54 52 49 47 47 45 52 a CREATE TRIGGER
1f840 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 */. const char
1f850 20 2a 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 *zAuthContext;
1f860 2f 2a 20 54 68 65 20 36 74 68 20 70 61 72 61 6d /* The 6th param
1f870 65 74 65 72 20 74 6f 20 64 62 2d 3e 78 41 75 74 eter to db->xAut
1f880 68 20 63 61 6c 6c 62 61 63 6b 73 20 2a 2f 0a 23 h callbacks */.#
1f890 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
1f8a0 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a IT_VIRTUALTABLE.
1f8b0 20 20 54 6f 6b 65 6e 20 73 41 72 67 3b 20 20 20 Token sArg;
1f8c0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
1f8d0 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 6f 66 20 omplete text of
1f8e0 61 20 6d 6f 64 75 6c 65 20 61 72 67 75 6d 65 6e a module argumen
1f8f0 74 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 2a 61 t */. Table **a
1f900 70 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 20 pVtabLock;
1f910 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 76 /* Pointer to v
1f920 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 6e 65 irtual tables ne
1f930 65 64 69 6e 67 20 6c 6f 63 6b 69 6e 67 20 2a 2f eding locking */
1f940 0a 23 65 6e 64 69 66 0a 20 20 54 61 62 6c 65 20 .#endif. Table
1f950 2a 70 5a 6f 6d 62 69 65 54 61 62 3b 20 20 20 20 *pZombieTab;
1f960 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 54 /* List of T
1f970 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 6f 20 able objects to
1f980 64 65 6c 65 74 65 20 61 66 74 65 72 20 63 6f 64 delete after cod
1f990 65 20 67 65 6e 20 2a 2f 0a 20 20 54 72 69 67 67 e gen */. Trigg
1f9a0 65 72 50 72 67 20 2a 70 54 72 69 67 67 65 72 50 erPrg *pTriggerP
1f9b0 72 67 3b 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c rg; /* Linked l
1f9c0 69 73 74 20 6f 66 20 63 6f 64 65 64 20 74 72 69 ist of coded tri
1f9d0 67 67 65 72 73 20 2a 2f 0a 20 20 57 69 74 68 20 ggers */. With
1f9e0 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 20 *pWith;
1f9f0 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 /* Current
1fa00 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 20 WITH clause, or
1fa10 4e 55 4c 4c 20 2a 2f 0a 20 20 57 69 74 68 20 2a NULL */. With *
1fa20 70 57 69 74 68 54 6f 46 72 65 65 3b 20 20 20 20 pWithToFree;
1fa30 20 20 20 20 2f 2a 20 46 72 65 65 20 74 68 69 73 /* Free this
1fa40 20 57 49 54 48 20 6f 62 6a 65 63 74 20 61 74 20 WITH object at
1fa50 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 70 the end of the p
1fa60 61 72 73 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a arse */.};../*.*
1fa70 2a 20 53 69 7a 65 73 20 61 6e 64 20 70 6f 69 6e * Sizes and poin
1fa80 74 65 72 73 20 6f 66 20 76 61 72 69 6f 75 73 20 ters of various
1fa90 70 61 72 74 73 20 6f 66 20 74 68 65 20 50 61 72 parts of the Par
1faa0 73 65 20 6f 62 6a 65 63 74 2e 0a 2a 2f 0a 23 64 se object..*/.#d
1fab0 65 66 69 6e 65 20 50 41 52 53 45 5f 48 44 52 5f efine PARSE_HDR_
1fac0 53 5a 20 6f 66 66 73 65 74 6f 66 28 50 61 72 73 SZ offsetof(Pars
1fad0 65 2c 61 43 6f 6c 43 61 63 68 65 29 20 2f 2a 20 e,aColCache) /*
1fae0 52 65 63 75 72 73 69 76 65 20 70 61 72 74 20 77 Recursive part w
1faf0 2f 6f 20 61 43 6f 6c 43 61 63 68 65 2a 2f 0a 23 /o aColCache*/.#
1fb00 64 65 66 69 6e 65 20 50 41 52 53 45 5f 52 45 43 define PARSE_REC
1fb10 55 52 53 45 5f 53 5a 20 6f 66 66 73 65 74 6f 66 URSE_SZ offsetof
1fb20 28 50 61 72 73 65 2c 73 4c 61 73 74 54 6f 6b 65 (Parse,sLastToke
1fb30 6e 29 20 20 20 20 2f 2a 20 52 65 63 75 72 73 69 n) /* Recursi
1fb40 76 65 20 70 61 72 74 20 2a 2f 0a 23 64 65 66 69 ve part */.#defi
1fb50 6e 65 20 50 41 52 53 45 5f 54 41 49 4c 5f 53 5a ne PARSE_TAIL_SZ
1fb60 20 28 73 69 7a 65 6f 66 28 50 61 72 73 65 29 2d (sizeof(Parse)-
1fb70 50 41 52 53 45 5f 52 45 43 55 52 53 45 5f 53 5a PARSE_RECURSE_SZ
1fb80 29 20 2f 2a 20 4e 6f 6e 2d 72 65 63 75 72 73 69 ) /* Non-recursi
1fb90 76 65 20 70 61 72 74 20 2a 2f 0a 23 64 65 66 69 ve part */.#defi
1fba0 6e 65 20 50 41 52 53 45 5f 54 41 49 4c 28 58 29 ne PARSE_TAIL(X)
1fbb0 20 28 28 28 63 68 61 72 2a 29 28 58 29 29 2b 50 (((char*)(X))+P
1fbc0 41 52 53 45 5f 52 45 43 55 52 53 45 5f 53 5a 29 ARSE_RECURSE_SZ)
1fbd0 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
1fbe0 74 61 69 6c 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 52 tail */../*.** R
1fbf0 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 63 75 eturn true if cu
1fc00 72 72 65 6e 74 6c 79 20 69 6e 73 69 64 65 20 61 rrently inside a
1fc10 6e 20 73 71 6c 69 74 65 33 5f 64 65 63 6c 61 72 n sqlite3_declar
1fc20 65 5f 76 74 61 62 28 29 20 63 61 6c 6c 2e 0a 2a e_vtab() call..*
1fc30 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
1fc40 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
1fc50 45 0a 20 20 23 64 65 66 69 6e 65 20 49 4e 5f 44 E. #define IN_D
1fc60 45 43 4c 41 52 45 5f 56 54 41 42 20 30 0a 23 65 ECLARE_VTAB 0.#e
1fc70 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 49 4e lse. #define IN
1fc80 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 20 28 70 _DECLARE_VTAB (p
1fc90 50 61 72 73 65 2d 3e 64 65 63 6c 61 72 65 56 74 Parse->declareVt
1fca0 61 62 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a ab).#endif../*.*
1fcb0 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
1fcc0 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
1fcd0 74 72 75 63 74 75 72 65 20 63 61 6e 20 62 65 20 tructure can be
1fce0 64 65 63 6c 61 72 65 64 20 6f 6e 20 61 20 73 74 declared on a st
1fcf0 61 63 6b 20 61 6e 64 20 75 73 65 64 0a 2a 2a 20 ack and used.**
1fd00 74 6f 20 73 61 76 65 20 74 68 65 20 50 61 72 73 to save the Pars
1fd10 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 76 e.zAuthContext v
1fd20 61 6c 75 65 20 73 6f 20 74 68 61 74 20 69 74 20 alue so that it
1fd30 63 61 6e 20 62 65 20 72 65 73 74 6f 72 65 64 20 can be restored
1fd40 6c 61 74 65 72 2e 0a 2a 2f 0a 73 74 72 75 63 74 later..*/.struct
1fd50 20 41 75 74 68 43 6f 6e 74 65 78 74 20 7b 0a 20 AuthContext {.
1fd60 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 75 const char *zAu
1fd70 74 68 43 6f 6e 74 65 78 74 3b 20 20 20 2f 2a 20 thContext; /*
1fd80 50 75 74 20 73 61 76 65 64 20 50 61 72 73 65 2e Put saved Parse.
1fd90 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 68 65 72 zAuthContext her
1fda0 65 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 50 e */. Parse *pP
1fdb0 61 72 73 65 3b 20 20 20 20 20 20 20 20 20 20 20 arse;
1fdc0 20 20 20 2f 2a 20 54 68 65 20 50 61 72 73 65 20 /* The Parse
1fdd0 73 74 72 75 63 74 75 72 65 20 2a 2f 0a 7d 3b 0a structure */.};.
1fde0 0a 2f 2a 0a 2a 2a 20 42 69 74 66 69 65 6c 64 20 ./*.** Bitfield
1fdf0 66 6c 61 67 73 20 66 6f 72 20 50 35 20 76 61 6c flags for P5 val
1fe00 75 65 20 69 6e 20 76 61 72 69 6f 75 73 20 6f 70 ue in various op
1fe10 63 6f 64 65 73 2e 0a 2a 2a 0a 2a 2a 20 56 61 6c codes..**.** Val
1fe20 75 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 28 ue constraints (
1fe30 65 6e 66 6f 72 63 65 64 20 76 69 61 20 61 73 73 enforced via ass
1fe40 65 72 74 28 29 29 3a 0a 2a 2a 20 20 20 20 4f 50 ert()):.** OP
1fe50 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 20 FLAG_LENGTHARG
1fe60 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 == SQLITE_FUNC
1fe70 5f 4c 45 4e 47 54 48 0a 2a 2a 20 20 20 20 4f 50 _LENGTH.** OP
1fe80 46 4c 41 47 5f 54 59 50 45 4f 46 41 52 47 20 20 FLAG_TYPEOFARG
1fe90 20 20 3d 3d 20 53 51 4c 49 54 45 5f 46 55 4e 43 == SQLITE_FUNC
1fea0 5f 54 59 50 45 4f 46 0a 2a 2a 20 20 20 20 4f 50 _TYPEOF.** OP
1feb0 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 20 20 FLAG_BULKCSR
1fec0 20 20 3d 3d 20 42 54 52 45 45 5f 42 55 4c 4b 4c == BTREE_BULKL
1fed0 4f 41 44 0a 2a 2a 20 20 20 20 4f 50 46 4c 41 47 OAD.** OPFLAG
1fee0 5f 53 45 45 4b 45 51 20 20 20 20 20 20 20 3d 3d _SEEKEQ ==
1fef0 20 42 54 52 45 45 5f 53 45 45 4b 5f 45 51 0a 2a BTREE_SEEK_EQ.*
1ff00 2a 20 20 20 20 4f 50 46 4c 41 47 5f 46 4f 52 44 * OPFLAG_FORD
1ff10 45 4c 45 54 45 20 20 20 20 3d 3d 20 42 54 52 45 ELETE == BTRE
1ff20 45 5f 46 4f 52 44 45 4c 45 54 45 0a 2a 2a 20 20 E_FORDELETE.**
1ff30 20 20 4f 50 46 4c 41 47 5f 53 41 56 45 50 4f 53 OPFLAG_SAVEPOS
1ff40 49 54 49 4f 4e 20 3d 3d 20 42 54 52 45 45 5f 53 ITION == BTREE_S
1ff50 41 56 45 50 4f 53 49 54 49 4f 4e 0a 2a 2a 20 20 AVEPOSITION.**
1ff60 20 20 4f 50 46 4c 41 47 5f 41 55 58 44 45 4c 45 OPFLAG_AUXDELE
1ff70 54 45 20 20 20 20 3d 3d 20 42 54 52 45 45 5f 41 TE == BTREE_A
1ff80 55 58 44 45 4c 45 54 45 0a 2a 2f 0a 23 64 65 66 UXDELETE.*/.#def
1ff90 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 43 48 41 4e ine OPFLAG_NCHAN
1ffa0 47 45 20 20 20 20 20 20 20 30 78 30 31 20 20 20 GE 0x01
1ffb0 20 2f 2a 20 4f 50 5f 49 6e 73 65 72 74 3a 20 53 /* OP_Insert: S
1ffc0 65 74 20 74 6f 20 75 70 64 61 74 65 20 64 62 2d et to update db-
1ffd0 3e 6e 43 68 61 6e 67 65 20 2a 2f 0a 20 20 20 20 >nChange */.
1ffe0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1fff0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20000 20 2f 2a 20 41 6c 73 6f 20 75 73 65 64 20 69 6e /* Also used in
20010 20 50 32 20 28 6e 6f 74 20 50 35 29 20 6f 66 20 P2 (not P5) of
20020 4f 50 5f 44 65 6c 65 74 65 20 2a 2f 0a 23 64 65 OP_Delete */.#de
20030 66 69 6e 65 20 4f 50 46 4c 41 47 5f 45 50 48 45 fine OPFLAG_EPHE
20040 4d 20 20 20 20 20 20 20 20 20 30 78 30 31 20 20 M 0x01
20050 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 3a 20 /* OP_Column:
20060 45 70 68 65 6d 65 72 61 6c 20 6f 75 74 70 75 74 Ephemeral output
20070 20 69 73 20 6f 6b 20 2a 2f 0a 23 64 65 66 69 6e is ok */.#defin
20080 65 20 4f 50 46 4c 41 47 5f 4c 41 53 54 52 4f 57 e OPFLAG_LASTROW
20090 49 44 20 20 20 20 20 30 78 30 32 20 20 20 20 2f ID 0x02 /
200a0 2a 20 53 65 74 20 74 6f 20 75 70 64 61 74 65 20 * Set to update
200b0 64 62 2d 3e 6c 61 73 74 52 6f 77 69 64 20 2a 2f db->lastRowid */
200c0 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f .#define OPFLAG_
200d0 49 53 55 50 44 41 54 45 20 20 20 20 20 20 30 78 ISUPDATE 0x
200e0 30 34 20 20 20 20 2f 2a 20 54 68 69 73 20 4f 50 04 /* This OP
200f0 5f 49 6e 73 65 72 74 20 69 73 20 61 6e 20 73 71 _Insert is an sq
20100 6c 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 65 66 l UPDATE */.#def
20110 69 6e 65 20 4f 50 46 4c 41 47 5f 41 50 50 45 4e ine OPFLAG_APPEN
20120 44 20 20 20 20 20 20 20 20 30 78 30 38 20 20 20 D 0x08
20130 20 2f 2a 20 54 68 69 73 20 69 73 20 6c 69 6b 65 /* This is like
20140 6c 79 20 74 6f 20 62 65 20 61 6e 20 61 70 70 65 ly to be an appe
20150 6e 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 nd */.#define OP
20160 46 4c 41 47 5f 55 53 45 53 45 45 4b 52 45 53 55 FLAG_USESEEKRESU
20170 4c 54 20 30 78 31 30 20 20 20 20 2f 2a 20 54 72 LT 0x10 /* Tr
20180 79 20 74 6f 20 61 76 6f 69 64 20 61 20 73 65 65 y to avoid a see
20190 6b 20 69 6e 20 42 74 72 65 65 49 6e 73 65 72 74 k in BtreeInsert
201a0 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c () */.#ifdef SQL
201b0 49 54 45 5f 45 4e 41 42 4c 45 5f 50 52 45 55 50 ITE_ENABLE_PREUP
201c0 44 41 54 45 5f 48 4f 4f 4b 0a 23 64 65 66 69 6e DATE_HOOK.#defin
201d0 65 20 4f 50 46 4c 41 47 5f 49 53 4e 4f 4f 50 20 e OPFLAG_ISNOOP
201e0 20 20 20 20 20 20 20 30 78 34 30 20 20 20 20 2f 0x40 /
201f0 2a 20 4f 50 5f 44 65 6c 65 74 65 20 64 6f 65 73 * OP_Delete does
20200 20 70 72 65 2d 75 70 64 61 74 65 2d 68 6f 6f 6b pre-update-hook
20210 20 6f 6e 6c 79 20 2a 2f 0a 23 65 6e 64 69 66 0a only */.#endif.
20220 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4c #define OPFLAG_L
20230 45 4e 47 54 48 41 52 47 20 20 20 20 20 30 78 34 ENGTHARG 0x4
20240 30 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 0 /* OP_Colum
20250 6e 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 n only used for
20260 6c 65 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 66 length() */.#def
20270 69 6e 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f ine OPFLAG_TYPEO
20280 46 41 52 47 20 20 20 20 20 30 78 38 30 20 20 20 FARG 0x80
20290 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 6e /* OP_Column on
202a0 6c 79 20 75 73 65 64 20 66 6f 72 20 74 79 70 65 ly used for type
202b0 6f 66 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 of() */.#define
202c0 4f 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 OPFLAG_BULKCSR
202d0 20 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 0x01 /*
202e0 4f 50 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 74 OP_Open** used t
202f0 6f 20 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 73 o open bulk curs
20300 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 or */.#define OP
20310 46 4c 41 47 5f 53 45 45 4b 45 51 20 20 20 20 20 FLAG_SEEKEQ
20320 20 20 20 30 78 30 32 20 20 20 20 2f 2a 20 4f 50 0x02 /* OP
20330 5f 4f 70 65 6e 2a 2a 20 63 75 72 73 6f 72 20 75 _Open** cursor u
20340 73 65 73 20 45 51 20 73 65 65 6b 20 6f 6e 6c 79 ses EQ seek only
20350 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
20360 41 47 5f 46 4f 52 44 45 4c 45 54 45 20 20 20 20 AG_FORDELETE
20370 20 30 78 30 38 20 20 20 20 2f 2a 20 4f 50 5f 4f 0x08 /* OP_O
20380 70 65 6e 20 73 68 6f 75 6c 64 20 75 73 65 20 42 pen should use B
20390 54 52 45 45 5f 46 4f 52 44 45 4c 45 54 45 20 2a TREE_FORDELETE *
203a0 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
203b0 5f 50 32 49 53 52 45 47 20 20 20 20 20 20 20 30 _P2ISREG 0
203c0 78 31 30 20 20 20 20 2f 2a 20 50 32 20 74 6f 20 x10 /* P2 to
203d0 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 61 20 72 OP_Open** is a r
203e0 65 67 69 73 74 65 72 20 6e 75 6d 62 65 72 20 2a egister number *
203f0 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
20400 5f 50 45 52 4d 55 54 45 20 20 20 20 20 20 20 30 _PERMUTE 0
20410 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6d x01 /* OP_Com
20420 70 61 72 65 3a 20 75 73 65 20 74 68 65 20 70 65 pare: use the pe
20430 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a 23 64 65 rmutation */.#de
20440 66 69 6e 65 20 4f 50 46 4c 41 47 5f 53 41 56 45 fine OPFLAG_SAVE
20450 50 4f 53 49 54 49 4f 4e 20 20 30 78 30 32 20 20 POSITION 0x02
20460 20 20 2f 2a 20 4f 50 5f 44 65 6c 65 74 65 3a 20 /* OP_Delete:
20470 6b 65 65 70 20 63 75 72 73 6f 72 20 70 6f 73 69 keep cursor posi
20480 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 tion */.#define
20490 4f 50 46 4c 41 47 5f 41 55 58 44 45 4c 45 54 45 OPFLAG_AUXDELETE
204a0 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 0x04 /*
204b0 4f 50 5f 44 65 6c 65 74 65 3a 20 69 6e 64 65 78 OP_Delete: index
204c0 20 69 6e 20 61 20 44 45 4c 45 54 45 20 6f 70 20 in a DELETE op
204d0 2a 2f 0a 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 74 */../*. * Each t
204e0 72 69 67 67 65 72 20 70 72 65 73 65 6e 74 20 69 rigger present i
204f0 6e 20 74 68 65 20 64 61 74 61 62 61 73 65 20 73 n the database s
20500 63 68 65 6d 61 20 69 73 20 73 74 6f 72 65 64 20 chema is stored
20510 61 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f as an instance o
20520 66 0a 20 2a 20 73 74 72 75 63 74 20 54 72 69 67 f. * struct Trig
20530 67 65 72 2e 0a 20 2a 0a 20 2a 20 50 6f 69 6e 74 ger.. *. * Point
20540 65 72 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 73 ers to instances
20550 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 67 67 of struct Trigg
20560 65 72 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e er are stored in
20570 20 74 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 2e two ways.. * 1.
20580 20 49 6e 20 74 68 65 20 22 74 72 69 67 48 61 73 In the "trigHas
20590 68 22 20 68 61 73 68 20 74 61 62 6c 65 20 28 70 h" hash table (p
205a0 61 72 74 20 6f 66 20 74 68 65 20 73 71 6c 69 74 art of the sqlit
205b0 65 33 2a 20 74 68 61 74 20 72 65 70 72 65 73 65 e3* that represe
205c0 6e 74 73 20 74 68 65 0a 20 2a 20 20 20 20 64 61 nts the. * da
205d0 74 61 62 61 73 65 29 2e 20 54 68 69 73 20 61 6c tabase). This al
205e0 6c 6f 77 73 20 54 72 69 67 67 65 72 20 73 74 72 lows Trigger str
205f0 75 63 74 75 72 65 73 20 74 6f 20 62 65 20 72 65 uctures to be re
20600 74 72 69 65 76 65 64 20 62 79 20 6e 61 6d 65 2e trieved by name.
20610 0a 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 67 67 . * 2. All trigg
20620 65 72 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 ers associated w
20630 69 74 68 20 61 20 73 69 6e 67 6c 65 20 74 61 62 ith a single tab
20640 6c 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b 65 64 le form a linked
20650 20 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 68 65 list, using the
20660 0a 20 2a 20 20 20 20 70 4e 65 78 74 20 6d 65 6d . * pNext mem
20670 62 65 72 20 6f 66 20 73 74 72 75 63 74 20 54 72 ber of struct Tr
20680 69 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 65 72 igger. A pointer
20690 20 74 6f 20 74 68 65 20 66 69 72 73 74 20 65 6c to the first el
206a0 65 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 2a 20 ement of the. *
206b0 20 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 69 linked list i
206c0 73 20 73 74 6f 72 65 64 20 61 73 20 74 68 65 20 s stored as the
206d0 22 70 54 72 69 67 67 65 72 22 20 6d 65 6d 62 65 "pTrigger" membe
206e0 72 20 6f 66 20 74 68 65 20 61 73 73 6f 63 69 61 r of the associa
206f0 74 65 64 0a 20 2a 20 20 20 20 73 74 72 75 63 74 ted. * struct
20700 20 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 54 68 Table.. *. * Th
20710 65 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d 65 e "step_list" me
20720 6d 62 65 72 20 70 6f 69 6e 74 73 20 74 6f 20 74 mber points to t
20730 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 he first element
20740 20 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 of a linked lis
20750 74 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 20 t. * containing
20760 74 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e the SQL statemen
20770 74 73 20 73 70 65 63 69 66 69 65 64 20 61 73 20 ts specified as
20780 74 68 65 20 74 72 69 67 67 65 72 20 70 72 6f 67 the trigger prog
20790 72 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 74 20 ram.. */.struct
207a0 54 72 69 67 67 65 72 20 7b 0a 20 20 63 68 61 72 Trigger {. char
207b0 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 *zName;
207c0 20 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d 65 20 /* The name
207d0 6f 66 20 74 68 65 20 74 72 69 67 67 65 72 20 20 of the trigger
207e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
207f0 20 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 72 20 */. char
20800 2a 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 *table;
20810 20 20 20 2f 2a 20 54 68 65 20 74 61 62 6c 65 20 /* The table
20820 6f 72 20 76 69 65 77 20 74 6f 20 77 68 69 63 68 or view to which
20830 20 74 68 65 20 74 72 69 67 67 65 72 20 61 70 70 the trigger app
20840 6c 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f 70 3b lies */. u8 op;
20850 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20860 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f 44 /* One of TK_D
20870 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 45 ELETE, TK_UPDATE
20880 2c 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 20 20 , TK_INSERT
20890 20 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 5f 74 */. u8 tr_t
208a0 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 m;
208b0 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 47 47 /* One of TRIGG
208c0 45 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 47 47 ER_BEFORE, TRIGG
208d0 45 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 45 78 ER_AFTER */. Ex
208e0 70 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 20 20 pr *pWhen;
208f0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 45 /* The WHE
20900 4e 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 N clause of the
20910 65 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 79 20 expression (may
20920 62 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 49 64 be NULL) */. Id
20930 4c 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 3b 20 List *pColumns;
20940 20 20 20 20 20 20 2f 2a 20 49 66 20 74 68 69 73 /* If this
20950 20 69 73 20 61 6e 20 55 50 44 41 54 45 20 4f 46 is an UPDATE OF
20960 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 74 <column-list> t
20970 72 69 67 67 65 72 2c 0a 20 20 20 20 20 20 20 20 rigger,.
20980 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20990 20 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 6d 6e the <column
209a0 2d 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 65 64 -list> is stored
209b0 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 6d here */. Schem
209c0 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 20 a *pSchema;
209d0 20 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e /* Schema con
209e0 74 61 69 6e 69 6e 67 20 74 68 65 20 74 72 69 67 taining the trig
209f0 67 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 ger */. Schema
20a00 2a 70 54 61 62 53 63 68 65 6d 61 3b 20 20 20 20 *pTabSchema;
20a10 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 /* Schema conta
20a20 69 6e 69 6e 67 20 74 68 65 20 74 61 62 6c 65 20 ining the table
20a30 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 */. TriggerStep
20a40 20 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f 2a 20 *step_list; /*
20a50 4c 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 72 69 Link list of tri
20a60 67 67 65 72 20 70 72 6f 67 72 61 6d 20 73 74 65 gger program ste
20a70 70 73 20 20 20 20 20 20 20 20 20 20 20 20 20 2a ps *
20a80 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e 65 /. Trigger *pNe
20a90 78 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e xt; /* N
20aa0 65 78 74 20 74 72 69 67 67 65 72 20 61 73 73 6f ext trigger asso
20ab0 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 ciated with the
20ac0 74 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a table */.};../*.
20ad0 2a 2a 20 41 20 74 72 69 67 67 65 72 20 69 73 20 ** A trigger is
20ae0 65 69 74 68 65 72 20 61 20 42 45 46 4f 52 45 20 either a BEFORE
20af0 6f 72 20 61 6e 20 41 46 54 45 52 20 74 72 69 67 or an AFTER trig
20b00 67 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 ger. The follow
20b10 69 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a 2a 2a ing constants.**
20b20 20 64 65 74 65 72 6d 69 6e 65 20 77 68 69 63 68 determine which
20b30 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 65 ..**.** If there
20b40 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 20 74 72 are multiple tr
20b50 69 67 67 65 72 73 2c 20 79 6f 75 20 6d 69 67 68 iggers, you migh
20b60 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 4f 52 45 t of some BEFORE
20b70 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 45 52 2e and some AFTER.
20b80 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 61 73 65 .** In that case
20b90 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 6e 74 73 s, the constants
20ba0 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 20 4f 52 below can be OR
20bb0 65 64 20 74 6f 67 65 74 68 65 72 2e 0a 2a 2f 0a ed together..*/.
20bc0 23 64 65 66 69 6e 65 20 54 52 49 47 47 45 52 5f #define TRIGGER_
20bd0 42 45 46 4f 52 45 20 20 31 0a 23 64 65 66 69 6e BEFORE 1.#defin
20be0 65 20 54 52 49 47 47 45 52 5f 41 46 54 45 52 20 e TRIGGER_AFTER
20bf0 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 6e 2../*. * An in
20c00 73 74 61 6e 63 65 20 6f 66 20 73 74 72 75 63 74 stance of struct
20c10 20 54 72 69 67 67 65 72 53 74 65 70 20 69 73 20 TriggerStep is
20c20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 61 20 used to store a
20c30 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 65 single SQL state
20c40 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 69 73 20 ment. * that is
20c50 61 20 70 61 72 74 20 6f 66 20 61 20 74 72 69 67 a part of a trig
20c60 67 65 72 2d 70 72 6f 67 72 61 6d 2e 0a 20 2a 0a ger-program.. *.
20c70 20 2a 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 20 * Instances of
20c80 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 struct TriggerSt
20c90 65 70 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e ep are stored in
20ca0 20 61 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 64 a singly linked
20cb0 20 6c 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 2a list (linked. *
20cc0 20 75 73 69 6e 67 20 74 68 65 20 22 70 4e 65 78 using the "pNex
20cd0 74 22 20 6d 65 6d 62 65 72 29 20 72 65 66 65 72 t" member) refer
20ce0 65 6e 63 65 64 20 62 79 20 74 68 65 20 22 73 74 enced by the "st
20cf0 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 20 ep_list" member
20d00 6f 66 20 74 68 65 0a 20 2a 20 61 73 73 6f 63 69 of the. * associ
20d10 61 74 65 64 20 73 74 72 75 63 74 20 54 72 69 67 ated struct Trig
20d20 67 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 54 68 ger instance. Th
20d30 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 e first element
20d40 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 of the linked li
20d50 73 74 20 69 73 0a 20 2a 20 74 68 65 20 66 69 72 st is. * the fir
20d60 73 74 20 73 74 65 70 20 6f 66 20 74 68 65 20 74 st step of the t
20d70 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d 2e 0a rigger-program..
20d80 20 2a 0a 20 2a 20 54 68 65 20 22 6f 70 22 20 6d *. * The "op" m
20d90 65 6d 62 65 72 20 69 6e 64 69 63 61 74 65 73 20 ember indicates
20da0 77 68 65 74 68 65 72 20 74 68 69 73 20 69 73 20 whether this is
20db0 61 20 22 44 45 4c 45 54 45 22 2c 20 22 49 4e 53 a "DELETE", "INS
20dc0 45 52 54 22 2c 20 22 55 50 44 41 54 45 22 20 6f ERT", "UPDATE" o
20dd0 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 20 73 74 r. * "SELECT" st
20de0 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 6d 65 61 atement. The mea
20df0 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 6f 74 68 nings of the oth
20e00 65 72 20 6d 65 6d 62 65 72 73 20 69 73 20 64 65 er members is de
20e10 74 65 72 6d 69 6e 65 64 20 62 79 20 74 68 65 0a termined by the.
20e20 20 2a 20 76 61 6c 75 65 20 6f 66 20 22 6f 70 22 * value of "op"
20e30 20 61 73 20 66 6f 6c 6c 6f 77 73 3a 0a 20 2a 0a as follows:. *.
20e40 20 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 49 4e 53 * (op == TK_INS
20e50 45 52 54 29 0a 20 2a 20 6f 72 63 6f 6e 66 20 20 ERT). * orconf
20e60 20 20 2d 3e 20 73 74 6f 72 65 73 20 74 68 65 20 -> stores the
20e70 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 61 6c 67 6f ON CONFLICT algo
20e80 72 69 74 68 6d 0a 20 2a 20 70 53 65 6c 65 63 74 rithm. * pSelect
20e90 20 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 73 -> If this is
20ea0 20 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 an INSERT INTO
20eb0 2e 2e 2e 20 53 45 4c 45 43 54 20 2e 2e 2e 20 73 ... SELECT ... s
20ec0 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 0a 20 tatement, then.
20ed0 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 74 * t
20ee0 68 69 73 20 73 74 6f 72 65 73 20 61 20 70 6f 69 his stores a poi
20ef0 6e 74 65 72 20 74 6f 20 74 68 65 20 53 45 4c 45 nter to the SELE
20f00 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 4f 74 CT statement. Ot
20f10 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a herwise NULL.. *
20f20 20 7a 54 61 72 67 65 74 20 20 20 2d 3e 20 44 65 zTarget -> De
20f30 71 75 6f 74 65 64 20 6e 61 6d 65 20 6f 66 20 74 quoted name of t
20f40 68 65 20 74 61 62 6c 65 20 74 6f 20 69 6e 73 65 he table to inse
20f50 72 74 20 69 6e 74 6f 2e 0a 20 2a 20 70 45 78 70 rt into.. * pExp
20f60 72 4c 69 73 74 20 2d 3e 20 49 66 20 74 68 69 73 rList -> If this
20f70 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 4e is an INSERT IN
20f80 54 4f 20 2e 2e 2e 20 56 41 4c 55 45 53 20 2e 2e TO ... VALUES ..
20f90 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 . statement, the
20fa0 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 n. *
20fb0 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 76 61 this stores va
20fc0 6c 75 65 73 20 74 6f 20 62 65 20 69 6e 73 65 72 lues to be inser
20fd0 74 65 64 2e 20 4f 74 68 65 72 77 69 73 65 20 4e ted. Otherwise N
20fe0 55 4c 4c 2e 0a 20 2a 20 70 49 64 4c 69 73 74 20 ULL.. * pIdList
20ff0 20 20 2d 3e 20 49 66 20 74 68 69 73 20 69 73 20 -> If this is
21000 61 6e 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 2e an INSERT INTO .
21010 2e 2e 20 28 3c 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 .. (<column-name
21020 73 3e 29 20 56 41 4c 55 45 53 20 2e 2e 2e 0a 20 s>) VALUES ....
21030 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 73 * s
21040 74 61 74 65 6d 65 6e 74 2c 20 74 68 65 6e 20 74 tatement, then t
21050 68 69 73 20 73 74 6f 72 65 73 20 74 68 65 20 63 his stores the c
21060 6f 6c 75 6d 6e 2d 6e 61 6d 65 73 20 74 6f 20 62 olumn-names to b
21070 65 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 e. *
21080 20 20 69 6e 73 65 72 74 65 64 20 69 6e 74 6f 2e inserted into.
21090 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b . *. * (op == TK
210a0 5f 44 45 4c 45 54 45 29 0a 20 2a 20 7a 54 61 72 _DELETE). * zTar
210b0 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f 74 65 get -> Dequote
210c0 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 d name of the ta
210d0 62 6c 65 20 74 6f 20 64 65 6c 65 74 65 20 66 72 ble to delete fr
210e0 6f 6d 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 20 om.. * pWhere
210f0 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 6c -> The WHERE cl
21100 61 75 73 65 20 6f 66 20 74 68 65 20 44 45 4c 45 ause of the DELE
21110 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 20 TE statement if
21120 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 64 one is specified
21130 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 .. *
21140 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c Otherwise NULL
21150 2e 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 .. *. * (op == T
21160 4b 5f 55 50 44 41 54 45 29 0a 20 2a 20 7a 54 61 K_UPDATE). * zTa
21170 72 67 65 74 20 20 20 2d 3e 20 44 65 71 75 6f 74 rget -> Dequot
21180 65 64 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 74 ed name of the t
21190 61 62 6c 65 20 74 6f 20 75 70 64 61 74 65 2e 0a able to update..
211a0 20 2a 20 70 57 68 65 72 65 20 20 20 20 2d 3e 20 * pWhere ->
211b0 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 The WHERE clause
211c0 20 6f 66 20 74 68 65 20 55 50 44 41 54 45 20 73 of the UPDATE s
211d0 74 61 74 65 6d 65 6e 74 20 69 66 20 6f 6e 65 20 tatement if one
211e0 69 73 20 73 70 65 63 69 66 69 65 64 2e 0a 20 2a is specified.. *
211f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4f 74 Ot
21200 68 65 72 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a herwise NULL.. *
21210 20 70 45 78 70 72 4c 69 73 74 20 2d 3e 20 41 20 pExprList -> A
21220 6c 69 73 74 20 6f 66 20 74 68 65 20 63 6f 6c 75 list of the colu
21230 6d 6e 73 20 74 6f 20 75 70 64 61 74 65 20 61 6e mns to update an
21240 64 20 74 68 65 20 65 78 70 72 65 73 73 69 6f 6e d the expression
21250 73 20 74 6f 20 75 70 64 61 74 65 0a 20 2a 20 20 s to update. *
21260 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 6d them
21270 20 74 6f 2e 20 53 65 65 20 73 71 6c 69 74 65 33 to. See sqlite3
21280 55 70 64 61 74 65 28 29 20 64 6f 63 75 6d 65 6e Update() documen
21290 74 61 74 69 6f 6e 20 6f 66 20 22 70 43 68 61 6e tation of "pChan
212a0 67 65 73 22 0a 20 2a 20 20 20 20 20 20 20 20 20 ges". *
212b0 20 20 20 20 20 61 72 67 75 6d 65 6e 74 2e 0a 20 argument..
212c0 2a 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 72 69 *. */.struct Tri
212d0 67 67 65 72 53 74 65 70 20 7b 0a 20 20 75 38 20 ggerStep {. u8
212e0 6f 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 op;
212f0 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f 44 /* One of TK_D
21300 45 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 45 ELETE, TK_UPDATE
21310 2c 20 54 4b 5f 49 4e 53 45 52 54 2c 20 54 4b 5f , TK_INSERT, TK_
21320 53 45 4c 45 43 54 20 2a 2f 0a 20 20 75 38 20 6f SELECT */. u8 o
21330 72 63 6f 6e 66 3b 20 20 20 20 20 20 20 20 20 20 rconf;
21340 20 2f 2a 20 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 /* OE_Rollback
21350 65 74 63 2e 20 2a 2f 0a 20 20 54 72 69 67 67 65 etc. */. Trigge
21360 72 20 2a 70 54 72 69 67 3b 20 20 20 20 20 20 2f r *pTrig; /
21370 2a 20 54 68 65 20 74 72 69 67 67 65 72 20 74 68 * The trigger th
21380 61 74 20 74 68 69 73 20 73 74 65 70 20 69 73 20 at this step is
21390 61 20 70 61 72 74 20 6f 66 20 2a 2f 0a 20 20 53 a part of */. S
213a0 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 elect *pSelect;
213b0 20 20 20 20 2f 2a 20 53 45 4c 45 43 54 20 73 74 /* SELECT st
213c0 61 74 65 6d 65 6e 74 20 6f 72 20 52 48 53 20 6f atement or RHS o
213d0 66 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 53 45 f INSERT INTO SE
213e0 4c 45 43 54 20 2e 2e 2e 20 2a 2f 0a 20 20 63 68 LECT ... */. ch
213f0 61 72 20 2a 7a 54 61 72 67 65 74 3b 20 20 20 20 ar *zTarget;
21400 20 20 20 2f 2a 20 54 61 72 67 65 74 20 74 61 62 /* Target tab
21410 6c 65 20 66 6f 72 20 44 45 4c 45 54 45 2c 20 55 le for DELETE, U
21420 50 44 41 54 45 2c 20 49 4e 53 45 52 54 20 2a 2f PDATE, INSERT */
21430 0a 20 20 45 78 70 72 20 2a 70 57 68 65 72 65 3b . Expr *pWhere;
21440 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 /* The W
21450 48 45 52 45 20 63 6c 61 75 73 65 20 66 6f 72 20 HERE clause for
21460 44 45 4c 45 54 45 20 6f 72 20 55 50 44 41 54 45 DELETE or UPDATE
21470 20 73 74 65 70 73 20 2a 2f 0a 20 20 45 78 70 72 steps */. Expr
21480 4c 69 73 74 20 2a 70 45 78 70 72 4c 69 73 74 3b List *pExprList;
21490 20 2f 2a 20 53 45 54 20 63 6c 61 75 73 65 20 66 /* SET clause f
214a0 6f 72 20 55 50 44 41 54 45 2e 20 2a 2f 0a 20 20 or UPDATE. */.
214b0 49 64 4c 69 73 74 20 2a 70 49 64 4c 69 73 74 3b IdList *pIdList;
214c0 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 6e /* Column n
214d0 61 6d 65 73 20 66 6f 72 20 49 4e 53 45 52 54 20 ames for INSERT
214e0 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 */. TriggerStep
214f0 20 2a 70 4e 65 78 74 3b 20 20 2f 2a 20 4e 65 78 *pNext; /* Nex
21500 74 20 69 6e 20 74 68 65 20 6c 69 6e 6b 2d 6c 69 t in the link-li
21510 73 74 20 2a 2f 0a 20 20 54 72 69 67 67 65 72 53 st */. TriggerS
21520 74 65 70 20 2a 70 4c 61 73 74 3b 20 20 2f 2a 20 tep *pLast; /*
21530 4c 61 73 74 20 65 6c 65 6d 65 6e 74 20 69 6e 20 Last element in
21540 6c 69 6e 6b 2d 6c 69 73 74 2e 20 56 61 6c 69 64 link-list. Valid
21550 20 66 6f 72 20 31 73 74 20 65 6c 65 6d 20 6f 6e for 1st elem on
21560 6c 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ly */.};../*.**
21570 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 The following st
21580 72 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 ructure contains
21590 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 73 65 information use
215a0 64 20 62 79 20 74 68 65 20 73 71 6c 69 74 65 46 d by the sqliteF
215b0 69 78 2e 2e 2e 0a 2a 2a 20 72 6f 75 74 69 6e 65 ix....** routine
215c0 73 20 61 73 20 74 68 65 79 20 77 61 6c 6b 20 74 s as they walk t
215d0 68 65 20 70 61 72 73 65 20 74 72 65 65 20 74 6f he parse tree to
215e0 20 6d 61 6b 65 20 64 61 74 61 62 61 73 65 20 72 make database r
215f0 65 66 65 72 65 6e 63 65 73 0a 2a 2a 20 65 78 70 eferences.** exp
21600 6c 69 63 69 74 2e 0a 2a 2f 0a 74 79 70 65 64 65 licit..*/.typede
21610 66 20 73 74 72 75 63 74 20 44 62 46 69 78 65 72 f struct DbFixer
21620 20 44 62 46 69 78 65 72 3b 0a 73 74 72 75 63 74 DbFixer;.struct
21630 20 44 62 46 69 78 65 72 20 7b 0a 20 20 50 61 72 DbFixer {. Par
21640 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 20 se *pParse;
21650 20 2f 2a 20 54 68 65 20 70 61 72 73 69 6e 67 20 /* The parsing
21660 63 6f 6e 74 65 78 74 2e 20 20 45 72 72 6f 72 20 context. Error
21670 6d 65 73 73 61 67 65 73 20 77 72 69 74 74 65 6e messages written
21680 20 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 6d here */. Schem
21690 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 2f a *pSchema; /
216a0 2a 20 46 69 78 20 69 74 65 6d 73 20 74 6f 20 74 * Fix items to t
216b0 68 69 73 20 73 63 68 65 6d 61 20 2a 2f 0a 20 20 his schema */.
216c0 69 6e 74 20 62 56 61 72 4f 6e 6c 79 3b 20 20 20 int bVarOnly;
216d0 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 66 6f 72 /* Check for
216e0 20 76 61 72 69 61 62 6c 65 20 72 65 66 65 72 65 variable refere
216f0 6e 63 65 73 20 6f 6e 6c 79 20 2a 2f 0a 20 20 63 nces only */. c
21700 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 62 3b 20 onst char *zDb;
21710 20 20 20 2f 2a 20 4d 61 6b 65 20 73 75 72 65 20 /* Make sure
21720 61 6c 6c 20 6f 62 6a 65 63 74 73 20 61 72 65 20 all objects are
21730 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 74 68 69 contained in thi
21740 73 20 64 61 74 61 62 61 73 65 20 2a 2f 0a 20 20 s database */.
21750 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 79 70 const char *zTyp
21760 65 3b 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 74 e; /* Type of t
21770 68 65 20 63 6f 6e 74 61 69 6e 65 72 20 2d 20 75 he container - u
21780 73 65 64 20 66 6f 72 20 65 72 72 6f 72 20 6d 65 sed for error me
21790 73 73 61 67 65 73 20 2a 2f 0a 20 20 63 6f 6e 73 ssages */. cons
217a0 74 20 54 6f 6b 65 6e 20 2a 70 4e 61 6d 65 3b 20 t Token *pName;
217b0 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 63 /* Name of the c
217c0 6f 6e 74 61 69 6e 65 72 20 2d 20 75 73 65 64 20 ontainer - used
217d0 66 6f 72 20 65 72 72 6f 72 20 6d 65 73 73 61 67 for error messag
217e0 65 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 es */.};../*.**
217f0 41 6e 20 6f 62 6a 65 63 74 65 64 20 75 73 65 64 An objected used
21800 20 74 6f 20 61 63 63 75 6d 75 6c 61 74 65 20 74 to accumulate t
21810 68 65 20 74 65 78 74 20 6f 66 20 61 20 73 74 72 he text of a str
21820 69 6e 67 20 77 68 65 72 65 20 77 65 0a 2a 2a 20 ing where we.**
21830 64 6f 20 6e 6f 74 20 6e 65 63 65 73 73 61 72 69 do not necessari
21840 6c 79 20 6b 6e 6f 77 20 68 6f 77 20 62 69 67 20 ly know how big
21850 74 68 65 20 73 74 72 69 6e 67 20 77 69 6c 6c 20 the string will
21860 62 65 20 69 6e 20 74 68 65 20 65 6e 64 2e 0a 2a be in the end..*
21870 2f 0a 73 74 72 75 63 74 20 53 74 72 41 63 63 75 /.struct StrAccu
21880 6d 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 m {. sqlite3 *d
21890 62 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 b; /* Op
218a0 74 69 6f 6e 61 6c 20 64 61 74 61 62 61 73 65 20 tional database
218b0 66 6f 72 20 6c 6f 6f 6b 61 73 69 64 65 2e 20 20 for lookaside.
218c0 43 61 6e 20 62 65 20 4e 55 4c 4c 20 2a 2f 0a 20 Can be NULL */.
218d0 20 63 68 61 72 20 2a 7a 42 61 73 65 3b 20 20 20 char *zBase;
218e0 20 20 20 20 20 20 2f 2a 20 41 20 62 61 73 65 20 /* A base
218f0 61 6c 6c 6f 63 61 74 69 6f 6e 2e 20 20 4e 6f 74 allocation. Not
21900 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 2e 20 2a 2f from malloc. */
21910 0a 20 20 63 68 61 72 20 2a 7a 54 65 78 74 3b 20 . char *zText;
21920 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 73 /* The s
21930 74 72 69 6e 67 20 63 6f 6c 6c 65 63 74 65 64 20 tring collected
21940 73 6f 20 66 61 72 20 2a 2f 0a 20 20 75 33 32 20 so far */. u32
21950 20 6e 43 68 61 72 3b 20 20 20 20 20 20 20 20 20 nChar;
21960 20 2f 2a 20 4c 65 6e 67 74 68 20 6f 66 20 74 68 /* Length of th
21970 65 20 73 74 72 69 6e 67 20 73 6f 20 66 61 72 20 e string so far
21980 2a 2f 0a 20 20 75 33 32 20 20 6e 41 6c 6c 6f 63 */. u32 nAlloc
21990 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 41 6d 6f ; /* Amo
219a0 75 6e 74 20 6f 66 20 73 70 61 63 65 20 61 6c 6c unt of space all
219b0 6f 63 61 74 65 64 20 69 6e 20 7a 54 65 78 74 20 ocated in zText
219c0 2a 2f 0a 20 20 75 33 32 20 20 6d 78 41 6c 6c 6f */. u32 mxAllo
219d0 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 c; /* Max
219e0 69 6d 75 6d 20 61 6c 6c 6f 77 65 64 20 61 6c 6c imum allowed all
219f0 6f 63 61 74 69 6f 6e 2e 20 20 30 20 66 6f 72 20 ocation. 0 for
21a00 6e 6f 20 6d 61 6c 6c 6f 63 20 75 73 61 67 65 20 no malloc usage
21a10 2a 2f 0a 20 20 75 38 20 20 20 61 63 63 45 72 72 */. u8 accErr
21a20 6f 72 3b 20 20 20 20 20 20 20 2f 2a 20 53 54 52 or; /* STR
21a30 41 43 43 55 4d 5f 4e 4f 4d 45 4d 20 6f 72 20 53 ACCUM_NOMEM or S
21a40 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 2a TRACCUM_TOOBIG *
21a50 2f 0a 20 20 75 38 20 20 20 70 72 69 6e 74 66 46 /. u8 printfF
21a60 6c 61 67 73 3b 20 20 20 20 2f 2a 20 53 51 4c 49 lags; /* SQLI
21a70 54 45 5f 50 52 49 4e 54 46 20 66 6c 61 67 73 20 TE_PRINTF flags
21a80 62 65 6c 6f 77 20 2a 2f 0a 7d 3b 0a 23 64 65 66 below */.};.#def
21a90 69 6e 65 20 53 54 52 41 43 43 55 4d 5f 4e 4f 4d ine STRACCUM_NOM
21aa0 45 4d 20 20 20 31 0a 23 64 65 66 69 6e 65 20 53 EM 1.#define S
21ab0 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 20 20 TRACCUM_TOOBIG
21ac0 32 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 2.#define SQLITE
21ad0 5f 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 4c _PRINTF_INTERNAL
21ae0 20 30 78 30 31 20 20 2f 2a 20 49 6e 74 65 72 6e 0x01 /* Intern
21af0 61 6c 2d 75 73 65 2d 6f 6e 6c 79 20 63 6f 6e 76 al-use-only conv
21b00 65 72 74 65 72 73 20 61 6c 6c 6f 77 65 64 20 2a erters allowed *
21b10 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
21b20 5f 50 52 49 4e 54 46 5f 53 51 4c 46 55 4e 43 20 _PRINTF_SQLFUNC
21b30 20 30 78 30 32 20 20 2f 2a 20 53 51 4c 20 66 75 0x02 /* SQL fu
21b40 6e 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 73 nction arguments
21b50 20 74 6f 20 56 58 50 72 69 6e 74 66 20 2a 2f 0a to VXPrintf */.
21b60 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 #define SQLITE_P
21b70 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 20 30 RINTF_MALLOCED 0
21b80 78 30 34 20 20 2f 2a 20 54 72 75 65 20 69 66 20 x04 /* True if
21b90 78 54 65 78 74 20 69 73 20 61 6c 6c 6f 63 61 74 xText is allocat
21ba0 65 64 20 73 70 61 63 65 20 2a 2f 0a 0a 23 64 65 ed space */..#de
21bb0 66 69 6e 65 20 69 73 4d 61 6c 6c 6f 63 65 64 28 fine isMalloced(
21bc0 58 29 20 20 28 28 28 58 29 2d 3e 70 72 69 6e 74 X) (((X)->print
21bd0 66 46 6c 61 67 73 20 26 20 53 51 4c 49 54 45 5f fFlags & SQLITE_
21be0 50 52 49 4e 54 46 5f 4d 41 4c 4c 4f 43 45 44 29 PRINTF_MALLOCED)
21bf0 21 3d 30 29 0a 0a 0a 2f 2a 0a 2a 2a 20 41 20 70 !=0).../*.** A p
21c00 6f 69 6e 74 65 72 20 74 6f 20 74 68 69 73 20 73 ointer to this s
21c10 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 tructure is used
21c20 20 74 6f 20 63 6f 6d 6d 75 6e 69 63 61 74 65 20 to communicate
21c30 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 66 information.** f
21c40 72 6f 6d 20 73 71 6c 69 74 65 33 49 6e 69 74 20 rom sqlite3Init
21c50 61 6e 64 20 4f 50 5f 50 61 72 73 65 53 63 68 65 and OP_ParseSche
21c60 6d 61 20 69 6e 74 6f 20 74 68 65 20 73 71 6c 69 ma into the sqli
21c70 74 65 33 49 6e 69 74 43 61 6c 6c 62 61 63 6b 2e te3InitCallback.
21c80 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 .*/.typedef stru
21c90 63 74 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 2a ct {. sqlite3 *
21ca0 64 62 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 68 db; /* Th
21cb0 65 20 64 61 74 61 62 61 73 65 20 62 65 69 6e 67 e database being
21cc0 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a initialized */.
21cd0 20 20 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 char **pzErrMs
21ce0 67 3b 20 20 20 20 2f 2a 20 45 72 72 6f 72 20 6d g; /* Error m
21cf0 65 73 73 61 67 65 20 73 74 6f 72 65 64 20 68 65 essage stored he
21d00 72 65 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b re */. int iDb;
21d10 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 30 /* 0
21d20 20 66 6f 72 20 6d 61 69 6e 20 64 61 74 61 62 61 for main databa
21d30 73 65 2e 20 20 31 20 66 6f 72 20 54 45 4d 50 2c se. 1 for TEMP,
21d40 20 32 2e 2e 20 66 6f 72 20 41 54 54 41 43 48 65 2.. for ATTACHe
21d50 64 20 2a 2f 0a 20 20 69 6e 74 20 72 63 3b 20 20 d */. int rc;
21d60 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 52 65 /* Re
21d70 73 75 6c 74 20 63 6f 64 65 20 73 74 6f 72 65 64 sult code stored
21d80 20 68 65 72 65 20 2a 2f 0a 7d 20 49 6e 69 74 44 here */.} InitD
21d90 61 74 61 3b 0a 0a 2f 2a 0a 2a 2a 20 53 74 72 75 ata;../*.** Stru
21da0 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 69 6e 67 cture containing
21db0 20 67 6c 6f 62 61 6c 20 63 6f 6e 66 69 67 75 72 global configur
21dc0 61 74 69 6f 6e 20 64 61 74 61 20 66 6f 72 20 74 ation data for t
21dd0 68 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72 he SQLite librar
21de0 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 69 73 20 73 74 y..**.** This st
21df0 72 75 63 74 75 72 65 20 61 6c 73 6f 20 63 6f 6e ructure also con
21e00 74 61 69 6e 73 20 73 6f 6d 65 20 73 74 61 74 65 tains some state
21e10 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f information..*/
21e20 0a 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 43 .struct Sqlite3C
21e30 6f 6e 66 69 67 20 7b 0a 20 20 69 6e 74 20 62 4d onfig {. int bM
21e40 65 6d 73 74 61 74 3b 20 20 20 20 20 20 20 20 20 emstat;
21e50 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
21e60 72 75 65 20 74 6f 20 65 6e 61 62 6c 65 20 6d 65 rue to enable me
21e70 6d 6f 72 79 20 73 74 61 74 75 73 20 2a 2f 0a 20 mory status */.
21e80 20 69 6e 74 20 62 43 6f 72 65 4d 75 74 65 78 3b int bCoreMutex;
21e90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21ea0 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e /* True to en
21eb0 61 62 6c 65 20 63 6f 72 65 20 6d 75 74 65 78 69 able core mutexi
21ec0 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 62 46 75 6c ng */. int bFul
21ed0 6c 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 lMutex;
21ee0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
21ef0 65 20 74 6f 20 65 6e 61 62 6c 65 20 66 75 6c 6c e to enable full
21f00 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 20 69 mutexing */. i
21f10 6e 74 20 62 4f 70 65 6e 55 72 69 3b 20 20 20 20 nt bOpenUri;
21f20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21f30 20 2f 2a 20 54 72 75 65 20 74 6f 20 69 6e 74 65 /* True to inte
21f40 72 70 72 65 74 20 66 69 6c 65 6e 61 6d 65 73 20 rpret filenames
21f50 61 73 20 55 52 49 73 20 2a 2f 0a 20 20 69 6e 74 as URIs */. int
21f60 20 62 55 73 65 43 69 73 3b 20 20 20 20 20 20 20 bUseCis;
21f70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
21f80 2a 20 55 73 65 20 63 6f 76 65 72 69 6e 67 20 69 * Use covering i
21f90 6e 64 69 63 65 73 20 66 6f 72 20 66 75 6c 6c 2d ndices for full-
21fa0 73 63 61 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 6d scans */. int m
21fb0 78 53 74 72 6c 65 6e 3b 20 20 20 20 20 20 20 20 xStrlen;
21fc0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
21fd0 4d 61 78 69 6d 75 6d 20 73 74 72 69 6e 67 20 6c Maximum string l
21fe0 65 6e 67 74 68 20 2a 2f 0a 20 20 69 6e 74 20 6e ength */. int n
21ff0 65 76 65 72 43 6f 72 72 75 70 74 3b 20 20 20 20 everCorrupt;
22000 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
22010 44 61 74 61 62 61 73 65 20 69 73 20 61 6c 77 61 Database is alwa
22020 79 73 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 2a ys well-formed *
22030 2f 0a 20 20 69 6e 74 20 73 7a 4c 6f 6f 6b 61 73 /. int szLookas
22040 69 64 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ide;
22050 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 /* Default
22060 20 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 65 lookaside buffe
22070 72 20 73 69 7a 65 20 2a 2f 0a 20 20 69 6e 74 20 r size */. int
22080 6e 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 nLookaside;
22090 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
220a0 20 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 69 Default lookasi
220b0 64 65 20 62 75 66 66 65 72 20 63 6f 75 6e 74 20 de buffer count
220c0 2a 2f 0a 20 20 69 6e 74 20 6e 53 74 6d 74 53 70 */. int nStmtSp
220d0 69 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 ill;
220e0 20 20 20 20 20 20 20 2f 2a 20 53 74 6d 74 2d 6a /* Stmt-j
220f0 6f 75 72 6e 61 6c 20 73 70 69 6c 6c 2d 74 6f 2d ournal spill-to-
22100 64 69 73 6b 20 74 68 72 65 73 68 6f 6c 64 20 2a disk threshold *
22110 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 65 6d 5f /. sqlite3_mem_
22120 6d 65 74 68 6f 64 73 20 6d 3b 20 20 20 20 20 20 methods m;
22130 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 /* Low-lev
22140 65 6c 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 el memory alloca
22150 74 69 6f 6e 20 69 6e 74 65 72 66 61 63 65 20 2a tion interface *
22160 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 /. sqlite3_mute
22170 78 5f 6d 65 74 68 6f 64 73 20 6d 75 74 65 78 3b x_methods mutex;
22180 20 20 20 20 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 /* Low-lev
22190 65 6c 20 6d 75 74 65 78 20 69 6e 74 65 72 66 61 el mutex interfa
221a0 63 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f ce */. sqlite3_
221b0 70 63 61 63 68 65 5f 6d 65 74 68 6f 64 73 32 20 pcache_methods2
221c0 70 63 61 63 68 65 32 3b 20 20 2f 2a 20 4c 6f 77 pcache2; /* Low
221d0 2d 6c 65 76 65 6c 20 70 61 67 65 2d 63 61 63 68 -level page-cach
221e0 65 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 e interface */.
221f0 20 76 6f 69 64 20 2a 70 48 65 61 70 3b 20 20 20 void *pHeap;
22200 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22210 20 20 20 2f 2a 20 48 65 61 70 20 73 74 6f 72 61 /* Heap stora
22220 67 65 20 73 70 61 63 65 20 2a 2f 0a 20 20 69 6e ge space */. in
22230 74 20 6e 48 65 61 70 3b 20 20 20 20 20 20 20 20 t nHeap;
22240 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22250 2f 2a 20 53 69 7a 65 20 6f 66 20 70 48 65 61 70 /* Size of pHeap
22260 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6d 6e 52 65 [] */. int mnRe
22270 71 2c 20 6d 78 52 65 71 3b 20 20 20 20 20 20 20 q, mxReq;
22280 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 69 6e /* Min
22290 20 61 6e 64 20 6d 61 78 20 68 65 61 70 20 72 65 and max heap re
222a0 71 75 65 73 74 73 20 73 69 7a 65 73 20 2a 2f 0a quests sizes */.
222b0 20 20 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 sqlite3_int64
222c0 73 7a 4d 6d 61 70 3b 20 20 20 20 20 20 20 20 20 szMmap;
222d0 20 20 20 20 2f 2a 20 6d 6d 61 70 28 29 20 73 70 /* mmap() sp
222e0 61 63 65 20 70 65 72 20 6f 70 65 6e 20 66 69 6c ace per open fil
222f0 65 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 69 e */. sqlite3_i
22300 6e 74 36 34 20 6d 78 4d 6d 61 70 3b 20 20 20 20 nt64 mxMmap;
22310 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 69 /* Maxi
22320 6d 75 6d 20 76 61 6c 75 65 20 66 6f 72 20 73 7a mum value for sz
22330 4d 6d 61 70 20 2a 2f 0a 20 20 76 6f 69 64 20 2a Mmap */. void *
22340 70 53 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 pScratch;
22350 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 /* S
22360 63 72 61 74 63 68 20 6d 65 6d 6f 72 79 20 2a 2f cratch memory */
22370 0a 20 20 69 6e 74 20 73 7a 53 63 72 61 74 63 68 . int szScratch
22380 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
22390 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 /* Size of
223a0 65 61 63 68 20 73 63 72 61 74 63 68 20 62 75 66 each scratch buf
223b0 66 65 72 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 63 fer */. int nSc
223c0 72 61 74 63 68 3b 20 20 20 20 20 20 20 20 20 20 ratch;
223d0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
223e0 6d 62 65 72 20 6f 66 20 73 63 72 61 74 63 68 20 mber of scratch
223f0 62 75 66 66 65 72 73 20 2a 2f 0a 20 20 76 6f 69 buffers */. voi
22400 64 20 2a 70 50 61 67 65 3b 20 20 20 20 20 20 20 d *pPage;
22410 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
22420 2a 20 50 61 67 65 20 63 61 63 68 65 20 6d 65 6d * Page cache mem
22430 6f 72 79 20 2a 2f 0a 20 20 69 6e 74 20 73 7a 50 ory */. int szP
22440 61 67 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 age;
22450 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 /* Si
22460 7a 65 20 6f 66 20 65 61 63 68 20 70 61 67 65 20 ze of each page
22470 69 6e 20 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 in pPage[] */.
22480 69 6e 74 20 6e 50 61 67 65 3b 20 20 20 20 20 20 int nPage;
22490 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
224a0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 /* Number of p
224b0 61 67 65 73 20 69 6e 20 70 50 61 67 65 5b 5d 20 ages in pPage[]
224c0 2a 2f 0a 20 20 69 6e 74 20 6d 78 50 61 72 73 65 */. int mxParse
224d0 72 53 74 61 63 6b 3b 20 20 20 20 20 20 20 20 20 rStack;
224e0 20 20 20 20 20 20 20 2f 2a 20 6d 61 78 69 6d 75 /* maximu
224f0 6d 20 64 65 70 74 68 20 6f 66 20 74 68 65 20 70 m depth of the p
22500 61 72 73 65 72 20 73 74 61 63 6b 20 2a 2f 0a 20 arser stack */.
22510 20 69 6e 74 20 73 68 61 72 65 64 43 61 63 68 65 int sharedCache
22520 45 6e 61 62 6c 65 64 3b 20 20 20 20 20 20 20 20 Enabled;
22530 20 20 20 2f 2a 20 74 72 75 65 20 69 66 20 73 68 /* true if sh
22540 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 ared-cache mode
22550 65 6e 61 62 6c 65 64 20 2a 2f 0a 20 20 75 33 32 enabled */. u32
22560 20 73 7a 50 6d 61 3b 20 20 20 20 20 20 20 20 20 szPma;
22570 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
22580 2a 20 4d 61 78 69 6d 75 6d 20 53 6f 72 74 65 72 * Maximum Sorter
22590 20 50 4d 41 20 73 69 7a 65 20 2a 2f 0a 20 20 2f PMA size */. /
225a0 2a 20 54 68 65 20 61 62 6f 76 65 20 6d 69 67 68 * The above migh
225b0 74 20 62 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 t be initialized
225c0 20 74 6f 20 6e 6f 6e 2d 7a 65 72 6f 2e 20 20 54 to non-zero. T
225d0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6e 65 65 he following nee
225e0 64 20 74 6f 20 61 6c 77 61 79 73 0a 20 20 2a 2a d to always. **
225f0 20 69 6e 69 74 69 61 6c 6c 79 20 62 65 20 7a 65 initially be ze
22600 72 6f 2c 20 68 6f 77 65 76 65 72 2e 20 2a 2f 0a ro, however. */.
22610 20 20 69 6e 74 20 69 73 49 6e 69 74 3b 20 20 20 int isInit;
22620 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22630 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 /* True afte
22640 72 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e r initialization
22650 20 68 61 73 20 66 69 6e 69 73 68 65 64 20 2a 2f has finished */
22660 0a 20 20 69 6e 74 20 69 6e 50 72 6f 67 72 65 73 . int inProgres
22670 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 s;
22680 20 20 20 20 20 2f 2a 20 54 72 75 65 20 77 68 69 /* True whi
22690 6c 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f le initializatio
226a0 6e 20 69 6e 20 70 72 6f 67 72 65 73 73 20 2a 2f n in progress */
226b0 0a 20 20 69 6e 74 20 69 73 4d 75 74 65 78 49 6e . int isMutexIn
226c0 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 it;
226d0 20 20 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 /* True aft
226e0 65 72 20 6d 75 74 65 78 65 73 20 61 72 65 20 69 er mutexes are i
226f0 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 nitialized */.
22700 69 6e 74 20 69 73 4d 61 6c 6c 6f 63 49 6e 69 74 int isMallocInit
22710 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
22720 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 20 /* True after
22730 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 69 61 malloc is initia
22740 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 lized */. int i
22750 73 50 43 61 63 68 65 49 6e 69 74 3b 20 20 20 20 sPCacheInit;
22760 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
22770 54 72 75 65 20 61 66 74 65 72 20 6d 61 6c 6c 6f True after mallo
22780 63 20 69 73 20 69 6e 69 74 69 61 6c 69 7a 65 64 c is initialized
22790 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 49 6e */. int nRefIn
227a0 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 itMutex;
227b0 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
227c0 72 20 6f 66 20 75 73 65 72 73 20 6f 66 20 70 49 r of users of pI
227d0 6e 69 74 4d 75 74 65 78 20 2a 2f 0a 20 20 73 71 nitMutex */. sq
227e0 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 70 49 6e lite3_mutex *pIn
227f0 69 74 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 itMutex;
22800 2f 2a 20 4d 75 74 65 78 20 75 73 65 64 20 62 79 /* Mutex used by
22810 20 73 71 6c 69 74 65 33 5f 69 6e 69 74 69 61 6c sqlite3_initial
22820 69 7a 65 28 29 20 2a 2f 0a 20 20 76 6f 69 64 20 ize() */. void
22830 28 2a 78 4c 6f 67 29 28 76 6f 69 64 2a 2c 69 6e (*xLog)(void*,in
22840 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 20 t,const char*);
22850 2f 2a 20 46 75 6e 63 74 69 6f 6e 20 66 6f 72 20 /* Function for
22860 6c 6f 67 67 69 6e 67 20 2a 2f 0a 20 20 76 6f 69 logging */. voi
22870 64 20 2a 70 4c 6f 67 41 72 67 3b 20 20 20 20 20 d *pLogArg;
22880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22890 20 20 2f 2a 20 46 69 72 73 74 20 61 72 67 75 6d /* First argum
228a0 65 6e 74 20 74 6f 20 78 4c 6f 67 28 29 20 2a 2f ent to xLog() */
228b0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
228c0 4e 41 42 4c 45 5f 53 51 4c 4c 4f 47 0a 20 20 76 NABLE_SQLLOG. v
228d0 6f 69 64 28 2a 78 53 71 6c 6c 6f 67 29 28 76 6f oid(*xSqllog)(vo
228e0 69 64 2a 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e id*,sqlite3*,con
228f0 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 29 3b 0a st char*, int);.
22900 20 20 76 6f 69 64 20 2a 70 53 71 6c 6c 6f 67 41 void *pSqllogA
22910 72 67 3b 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 rg;.#endif.#ifde
22920 66 20 53 51 4c 49 54 45 5f 56 44 42 45 5f 43 4f f SQLITE_VDBE_CO
22930 56 45 52 41 47 45 0a 20 20 2f 2a 20 54 68 65 20 VERAGE. /* The
22940 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 6c 6c 62 61 following callba
22950 63 6b 20 28 69 66 20 6e 6f 74 20 4e 55 4c 4c 29 ck (if not NULL)
22960 20 69 73 20 69 6e 76 6f 6b 65 64 20 6f 6e 20 65 is invoked on e
22970 76 65 72 79 20 56 44 42 45 20 62 72 61 6e 63 68 very VDBE branch
22980 0a 20 20 2a 2a 20 6f 70 65 72 61 74 69 6f 6e 2e . ** operation.
22990 20 20 53 65 74 20 74 68 65 20 63 61 6c 6c 62 61 Set the callba
229a0 63 6b 20 75 73 69 6e 67 20 53 51 4c 49 54 45 5f ck using SQLITE_
229b0 54 45 53 54 43 54 52 4c 5f 56 44 42 45 5f 43 4f TESTCTRL_VDBE_CO
229c0 56 45 52 41 47 45 2e 0a 20 20 2a 2f 0a 20 20 76 VERAGE.. */. v
229d0 6f 69 64 20 28 2a 78 56 64 62 65 42 72 61 6e 63 oid (*xVdbeBranc
229e0 68 29 28 76 6f 69 64 2a 2c 69 6e 74 20 69 53 72 h)(void*,int iSr
229f0 63 4c 69 6e 65 2c 75 38 20 65 54 68 69 73 2c 75 cLine,u8 eThis,u
22a00 38 20 65 4d 78 29 3b 20 20 2f 2a 20 43 61 6c 6c 8 eMx); /* Call
22a10 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 2a back */. void *
22a20 70 56 64 62 65 42 72 61 6e 63 68 41 72 67 3b 20 pVdbeBranchArg;
22a30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22a40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22a50 20 20 20 20 2f 2a 20 31 73 74 20 61 72 67 75 6d /* 1st argum
22a60 65 6e 74 20 2a 2f 0a 23 65 6e 64 69 66 0a 23 69 ent */.#endif.#i
22a70 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 fndef SQLITE_UNT
22a80 45 53 54 41 42 4c 45 0a 20 20 69 6e 74 20 28 2a ESTABLE. int (*
22a90 78 54 65 73 74 43 61 6c 6c 62 61 63 6b 29 28 69 xTestCallback)(i
22aa0 6e 74 29 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 nt); /* I
22ab0 6e 76 6f 6b 65 64 20 62 79 20 73 71 6c 69 74 65 nvoked by sqlite
22ac0 33 46 61 75 6c 74 53 69 6d 28 29 20 2a 2f 0a 23 3FaultSim() */.#
22ad0 65 6e 64 69 66 0a 20 20 69 6e 74 20 62 4c 6f 63 endif. int bLoc
22ae0 61 6c 74 69 6d 65 46 61 75 6c 74 3b 20 20 20 20 altimeFault;
22af0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
22b00 65 20 74 6f 20 66 61 69 6c 20 6c 6f 63 61 6c 74 e to fail localt
22b10 69 6d 65 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 20 ime() calls */.
22b20 20 69 6e 74 20 69 4f 6e 63 65 52 65 73 65 74 54 int iOnceResetT
22b30 68 72 65 73 68 6f 6c 64 3b 20 20 20 20 20 20 20 hreshold;
22b40 20 20 20 2f 2a 20 57 68 65 6e 20 74 6f 20 72 65 /* When to re
22b50 73 65 74 20 4f 50 5f 4f 6e 63 65 20 63 6f 75 6e set OP_Once coun
22b60 74 65 72 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a ters */.};../*.*
22b70 2a 20 54 68 69 73 20 6d 61 63 72 6f 20 69 73 20 * This macro is
22b80 75 73 65 64 20 69 6e 73 69 64 65 20 6f 66 20 61 used inside of a
22b90 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e ssert() statemen
22ba0 74 73 20 74 6f 20 69 6e 64 69 63 61 74 65 20 74 ts to indicate t
22bb0 68 61 74 0a 2a 2a 20 74 68 65 20 61 73 73 65 72 hat.** the asser
22bc0 74 20 69 73 20 6f 6e 6c 79 20 76 61 6c 69 64 20 t is only valid
22bd0 6f 6e 20 61 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 on a well-formed
22be0 20 64 61 74 61 62 61 73 65 2e 20 20 49 6e 73 74 database. Inst
22bf0 65 61 64 20 6f 66 3a 0a 2a 2a 0a 2a 2a 20 20 20 ead of:.**.**
22c00 20 20 61 73 73 65 72 74 28 20 58 20 29 3b 0a 2a assert( X );.*
22c10 2a 0a 2a 2a 20 4f 6e 65 20 77 72 69 74 65 73 3a *.** One writes:
22c20 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 73 73 65 72 .**.** asser
22c30 74 28 20 58 20 7c 7c 20 43 4f 52 52 55 50 54 5f t( X || CORRUPT_
22c40 44 42 20 29 3b 0a 2a 2a 0a 2a 2a 20 43 4f 52 52 DB );.**.** CORR
22c50 55 50 54 5f 44 42 20 69 73 20 74 72 75 65 20 64 UPT_DB is true d
22c60 75 72 69 6e 67 20 6e 6f 72 6d 61 6c 20 6f 70 65 uring normal ope
22c70 72 61 74 69 6f 6e 2e 20 20 43 4f 52 52 55 50 54 ration. CORRUPT
22c80 5f 44 42 20 64 6f 65 73 20 6e 6f 74 20 69 6e 64 _DB does not ind
22c90 69 63 61 74 65 0a 2a 2a 20 74 68 61 74 20 74 68 icate.** that th
22ca0 65 20 64 61 74 61 62 61 73 65 20 69 73 20 64 65 e database is de
22cb0 66 69 6e 69 74 65 6c 79 20 63 6f 72 72 75 70 74 finitely corrupt
22cc0 2c 20 6f 6e 6c 79 20 74 68 61 74 20 69 74 20 6d , only that it m
22cd0 69 67 68 74 20 62 65 20 63 6f 72 72 75 70 74 2e ight be corrupt.
22ce0 0a 2a 2a 20 46 6f 72 20 6d 6f 73 74 20 74 65 73 .** For most tes
22cf0 74 20 63 61 73 65 73 2c 20 43 4f 52 52 55 50 54 t cases, CORRUPT
22d00 5f 44 42 20 69 73 20 73 65 74 20 74 6f 20 66 61 _DB is set to fa
22d10 6c 73 65 20 75 73 69 6e 67 20 61 20 73 70 65 63 lse using a spec
22d20 69 61 6c 0a 2a 2a 20 73 71 6c 69 74 65 33 5f 74 ial.** sqlite3_t
22d30 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 29 2e 20 20 est_control().
22d40 54 68 69 73 20 65 6e 61 62 6c 65 73 20 61 73 73 This enables ass
22d50 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
22d60 20 74 6f 20 70 72 6f 76 65 0a 2a 2a 20 74 68 69 to prove.** thi
22d70 6e 67 73 20 74 68 61 74 20 61 72 65 20 61 6c 77 ngs that are alw
22d80 61 79 73 20 74 72 75 65 20 66 6f 72 20 77 65 6c ays true for wel
22d90 6c 2d 66 6f 72 6d 65 64 20 64 61 74 61 62 61 73 l-formed databas
22da0 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 43 es..*/.#define C
22db0 4f 52 52 55 50 54 5f 44 42 20 20 28 73 71 6c 69 ORRUPT_DB (sqli
22dc0 74 65 33 43 6f 6e 66 69 67 2e 6e 65 76 65 72 43 te3Config.neverC
22dd0 6f 72 72 75 70 74 3d 3d 30 29 0a 0a 2f 2a 0a 2a orrupt==0)../*.*
22de0 2a 20 43 6f 6e 74 65 78 74 20 70 6f 69 6e 74 65 * Context pointe
22df0 72 20 70 61 73 73 65 64 20 64 6f 77 6e 20 74 68 r passed down th
22e00 72 6f 75 67 68 20 74 68 65 20 74 72 65 65 2d 77 rough the tree-w
22e10 61 6c 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 alk..*/.struct W
22e20 61 6c 6b 65 72 20 7b 0a 20 20 50 61 72 73 65 20 alker {. Parse
22e30 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 20 *pParse;
22e40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22e50 20 20 20 20 2f 2a 20 50 61 72 73 65 72 20 63 6f /* Parser co
22e60 6e 74 65 78 74 2e 20 20 2a 2f 0a 20 20 69 6e 74 ntext. */. int
22e70 20 28 2a 78 45 78 70 72 43 61 6c 6c 62 61 63 6b (*xExprCallback
22e80 29 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a )(Walker*, Expr*
22e90 29 3b 20 20 20 20 20 2f 2a 20 43 61 6c 6c 62 61 ); /* Callba
22ea0 63 6b 20 66 6f 72 20 65 78 70 72 65 73 73 69 6f ck for expressio
22eb0 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 53 ns */. int (*xS
22ec0 65 6c 65 63 74 43 61 6c 6c 62 61 63 6b 29 28 57 electCallback)(W
22ed0 61 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a 29 3b alker*,Select*);
22ee0 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 66 6f /* Callback fo
22ef0 72 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 76 r SELECTs */. v
22f00 6f 69 64 20 28 2a 78 53 65 6c 65 63 74 43 61 6c oid (*xSelectCal
22f10 6c 62 61 63 6b 32 29 28 57 61 6c 6b 65 72 2a 2c lback2)(Walker*,
22f20 53 65 6c 65 63 74 2a 29 3b 2f 2a 20 53 65 63 6f Select*);/* Seco
22f30 6e 64 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 nd callback for
22f40 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 69 6e 74 SELECTs */. int
22f50 20 77 61 6c 6b 65 72 44 65 70 74 68 3b 20 20 20 walkerDepth;
22f60 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22f70 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
22f80 20 6f 66 20 73 75 62 71 75 65 72 69 65 73 20 2a of subqueries *
22f90 2f 0a 20 20 75 38 20 65 43 6f 64 65 3b 20 20 20 /. u8 eCode;
22fa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22fb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
22fc0 20 41 20 73 6d 61 6c 6c 20 70 72 6f 63 65 73 73 A small process
22fd0 69 6e 67 20 63 6f 64 65 20 2a 2f 0a 20 20 75 6e ing code */. un
22fe0 69 6f 6e 20 7b 20 20 20 20 20 20 20 20 20 20 20 ion {
22ff0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23000 20 20 20 20 20 20 20 20 2f 2a 20 45 78 74 72 61 /* Extra
23010 20 64 61 74 61 20 66 6f 72 20 63 61 6c 6c 62 61 data for callba
23020 63 6b 20 2a 2f 0a 20 20 20 20 4e 61 6d 65 43 6f ck */. NameCo
23030 6e 74 65 78 74 20 2a 70 4e 43 3b 20 20 20 20 20 ntext *pNC;
23040 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23050 20 20 20 20 20 2f 2a 20 4e 61 6d 69 6e 67 20 63 /* Naming c
23060 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 20 20 69 6e ontext */. in
23070 74 20 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 t n;
23080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23090 20 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 6f /* A co
230a0 75 6e 74 65 72 20 2a 2f 0a 20 20 20 20 69 6e 74 unter */. int
230b0 20 69 43 75 72 3b 20 20 20 20 20 20 20 20 20 20 iCur;
230c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
230d0 20 20 20 20 20 20 20 20 2f 2a 20 41 20 63 75 72 /* A cur
230e0 73 6f 72 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 sor number */.
230f0 20 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 4c SrcList *pSrcL
23100 69 73 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ist;
23110 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
23120 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 FROM clause */.
23130 20 20 20 73 74 72 75 63 74 20 53 72 63 43 6f 75 struct SrcCou
23140 6e 74 20 2a 70 53 72 63 43 6f 75 6e 74 3b 20 20 nt *pSrcCount;
23150 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
23160 20 43 6f 75 6e 74 69 6e 67 20 63 6f 6c 75 6d 6e Counting column
23170 20 72 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 references */.
23180 20 20 20 73 74 72 75 63 74 20 43 43 75 72 48 69 struct CCurHi
23190 6e 74 20 2a 70 43 43 75 72 48 69 6e 74 3b 20 20 nt *pCCurHint;
231a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
231b0 20 55 73 65 64 20 62 79 20 63 6f 64 65 43 75 72 Used by codeCur
231c0 73 6f 72 48 69 6e 74 28 29 20 2a 2f 0a 20 20 20 sorHint() */.
231d0 20 69 6e 74 20 2a 61 69 43 6f 6c 3b 20 20 20 20 int *aiCol;
231e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
231f0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 61 /* a
23200 72 72 61 79 20 6f 66 20 63 6f 6c 75 6d 6e 20 69 rray of column i
23210 6e 64 65 78 65 73 20 2a 2f 0a 20 20 20 20 73 74 ndexes */. st
23220 72 75 63 74 20 49 64 78 43 6f 76 65 72 20 2a 70 ruct IdxCover *p
23230 49 64 78 43 6f 76 65 72 3b 20 20 20 20 20 20 20 IdxCover;
23240 20 20 20 20 20 20 20 20 20 2f 2a 20 43 68 65 63 /* Chec
23250 6b 20 66 6f 72 20 69 6e 64 65 78 20 63 6f 76 65 k for index cove
23260 72 61 67 65 20 2a 2f 0a 20 20 7d 20 75 3b 0a 7d rage */. } u;.}
23270 3b 0a 0a 2f 2a 20 46 6f 72 77 61 72 64 20 64 65 ;../* Forward de
23280 63 6c 61 72 61 74 69 6f 6e 73 20 2a 2f 0a 69 6e clarations */.in
23290 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 70 t sqlite3WalkExp
232a0 72 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a r(Walker*, Expr*
232b0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 );.int sqlite3Wa
232c0 6c 6b 45 78 70 72 4c 69 73 74 28 57 61 6c 6b 65 lkExprList(Walke
232d0 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a r*, ExprList*);.
232e0 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 int sqlite3WalkS
232f0 65 6c 65 63 74 28 57 61 6c 6b 65 72 2a 2c 20 53 elect(Walker*, S
23300 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
23310 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 45 78 ite3WalkSelectEx
23320 70 72 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 pr(Walker*, Sele
23330 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ct*);.int sqlite
23340 33 57 61 6c 6b 53 65 6c 65 63 74 46 72 6f 6d 28 3WalkSelectFrom(
23350 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a Walker*, Select*
23360 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
23370 70 72 57 61 6c 6b 4e 6f 6f 70 28 57 61 6c 6b 65 prWalkNoop(Walke
23380 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 0a 2f 2a 0a r*, Expr*);../*.
23390 2a 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 ** Return code f
233a0 72 6f 6d 20 74 68 65 20 70 61 72 73 65 2d 74 72 rom the parse-tr
233b0 65 65 20 77 61 6c 6b 69 6e 67 20 70 72 69 6d 69 ee walking primi
233c0 74 69 76 65 73 20 61 6e 64 20 74 68 65 69 72 0a tives and their.
233d0 2a 2a 20 63 61 6c 6c 62 61 63 6b 73 2e 0a 2a 2f ** callbacks..*/
233e0 0a 23 64 65 66 69 6e 65 20 57 52 43 5f 43 6f 6e .#define WRC_Con
233f0 74 69 6e 75 65 20 20 20 20 30 20 20 20 2f 2a 20 tinue 0 /*
23400 43 6f 6e 74 69 6e 75 65 20 64 6f 77 6e 20 69 6e Continue down in
23410 74 6f 20 63 68 69 6c 64 72 65 6e 20 2a 2f 0a 23 to children */.#
23420 64 65 66 69 6e 65 20 57 52 43 5f 50 72 75 6e 65 define WRC_Prune
23430 20 20 20 20 20 20 20 31 20 20 20 2f 2a 20 4f 6d 1 /* Om
23440 69 74 20 63 68 69 6c 64 72 65 6e 20 62 75 74 20 it children but
23450 63 6f 6e 74 69 6e 75 65 20 77 61 6c 6b 69 6e 67 continue walking
23460 20 73 69 62 6c 69 6e 67 73 20 2a 2f 0a 23 64 65 siblings */.#de
23470 66 69 6e 65 20 57 52 43 5f 41 62 6f 72 74 20 20 fine WRC_Abort
23480 20 20 20 20 20 32 20 20 20 2f 2a 20 41 62 61 6e 2 /* Aban
23490 64 6f 6e 20 74 68 65 20 74 72 65 65 20 77 61 6c don the tree wal
234a0 6b 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 k */../*.** An i
234b0 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 69 73 20 nstance of this
234c0 73 74 72 75 63 74 75 72 65 20 72 65 70 72 65 73 structure repres
234d0 65 6e 74 73 20 61 20 73 65 74 20 6f 66 20 6f 6e ents a set of on
234e0 65 20 6f 72 20 6d 6f 72 65 20 43 54 45 73 0a 2a e or more CTEs.*
234f0 2a 20 28 63 6f 6d 6d 6f 6e 20 74 61 62 6c 65 20 * (common table
23500 65 78 70 72 65 73 73 69 6f 6e 73 29 20 63 72 65 expressions) cre
23510 61 74 65 64 20 62 79 20 61 20 73 69 6e 67 6c 65 ated by a single
23520 20 57 49 54 48 20 63 6c 61 75 73 65 2e 0a 2a 2f WITH clause..*/
23530 0a 73 74 72 75 63 74 20 57 69 74 68 20 7b 0a 20 .struct With {.
23540 20 69 6e 74 20 6e 43 74 65 3b 20 20 20 20 20 20 int nCte;
23550 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23560 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 43 54 /* Number of CT
23570 45 73 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 Es in the WITH c
23580 6c 61 75 73 65 20 2a 2f 0a 20 20 57 69 74 68 20 lause */. With
23590 2a 70 4f 75 74 65 72 3b 20 20 20 20 20 20 20 20 *pOuter;
235a0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 6f /* Co
235b0 6e 74 61 69 6e 69 6e 67 20 57 49 54 48 20 63 6c ntaining WITH cl
235c0 61 75 73 65 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f ause, or NULL */
235d0 0a 20 20 73 74 72 75 63 74 20 43 74 65 20 7b 20 . struct Cte {
235e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
235f0 20 20 20 2f 2a 20 46 6f 72 20 65 61 63 68 20 43 /* For each C
23600 54 45 20 69 6e 20 74 68 65 20 57 49 54 48 20 63 TE in the WITH c
23610 6c 61 75 73 65 2e 2e 2e 2e 20 2a 2f 0a 20 20 20 lause.... */.
23620 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 char *zName;
23630 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23640 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 68 69 73 /* Name of this
23650 20 43 54 45 20 2a 2f 0a 20 20 20 20 45 78 70 72 CTE */. Expr
23660 4c 69 73 74 20 2a 70 43 6f 6c 73 3b 20 20 20 20 List *pCols;
23670 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c /* L
23680 69 73 74 20 6f 66 20 65 78 70 6c 69 63 69 74 20 ist of explicit
23690 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 2c 20 6f 72 column names, or
236a0 20 4e 55 4c 4c 20 2a 2f 0a 20 20 20 20 53 65 6c NULL */. Sel
236b0 65 63 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 20 ect *pSelect;
236c0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
236d0 54 68 65 20 64 65 66 69 6e 69 74 69 6f 6e 20 6f The definition o
236e0 66 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 20 f this CTE */.
236f0 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 43 const char *zC
23700 74 65 45 72 72 3b 20 20 20 20 20 20 20 20 20 20 teErr;
23710 20 20 2f 2a 20 45 72 72 6f 72 20 6d 65 73 73 61 /* Error messa
23720 67 65 20 66 6f 72 20 63 69 72 63 75 6c 61 72 20 ge for circular
23730 72 65 66 65 72 65 6e 63 65 73 20 2a 2f 0a 20 20 references */.
23740 7d 20 61 5b 31 5d 3b 0a 7d 3b 0a 0a 23 69 66 64 } a[1];.};..#ifd
23750 65 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a ef SQLITE_DEBUG.
23760 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
23770 65 20 6f 66 20 74 68 65 20 54 72 65 65 56 69 65 e of the TreeVie
23780 77 20 6f 62 6a 65 63 74 20 69 73 20 75 73 65 64 w object is used
23790 20 66 6f 72 20 70 72 69 6e 74 69 6e 67 20 74 68 for printing th
237a0 65 20 63 6f 6e 74 65 6e 74 20 6f 66 0a 2a 2a 20 e content of.**
237b0 64 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20 data structures
237c0 6f 6e 20 73 71 6c 69 74 65 33 44 65 62 75 67 50 on sqlite3DebugP
237d0 72 69 6e 74 66 28 29 20 75 73 69 6e 67 20 61 20 rintf() using a
237e0 74 72 65 65 2d 6c 69 6b 65 20 76 69 65 77 2e 0a tree-like view..
237f0 2a 2f 0a 73 74 72 75 63 74 20 54 72 65 65 56 69 */.struct TreeVi
23800 65 77 20 7b 0a 20 20 69 6e 74 20 69 4c 65 76 65 ew {. int iLeve
23810 6c 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f l; /
23820 2a 20 57 68 69 63 68 20 6c 65 76 65 6c 20 6f 66 * Which level of
23830 20 74 68 65 20 74 72 65 65 20 77 65 20 61 72 65 the tree we are
23840 20 6f 6e 20 2a 2f 0a 20 20 75 38 20 20 62 4c 69 on */. u8 bLi
23850 6e 65 5b 31 30 30 5d 3b 20 20 20 20 20 20 20 20 ne[100];
23860 20 2f 2a 20 44 72 61 77 20 76 65 72 74 69 63 61 /* Draw vertica
23870 6c 20 69 6e 20 63 6f 6c 75 6d 6e 20 69 20 69 66 l in column i if
23880 20 62 4c 69 6e 65 5b 69 5d 20 69 73 20 74 72 75 bLine[i] is tru
23890 65 20 2a 2f 0a 7d 3b 0a 23 65 6e 64 69 66 20 2f e */.};.#endif /
238a0 2a 20 53 51 4c 49 54 45 5f 44 45 42 55 47 20 2a * SQLITE_DEBUG *
238b0 2f 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 75 6d 69 6e /../*.** Assumin
238c0 67 20 7a 49 6e 20 70 6f 69 6e 74 73 20 74 6f 20 g zIn points to
238d0 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f the first byte o
238e0 66 20 61 20 55 54 46 2d 38 20 63 68 61 72 61 63 f a UTF-8 charac
238f0 74 65 72 2c 0a 2a 2a 20 61 64 76 61 6e 63 65 20 ter,.** advance
23900 7a 49 6e 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 zIn to point to
23910 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f the first byte o
23920 66 20 74 68 65 20 6e 65 78 74 20 55 54 46 2d 38 f the next UTF-8
23930 20 63 68 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 23 character..*/.#
23940 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4b define SQLITE_SK
23950 49 50 5f 55 54 46 38 28 7a 49 6e 29 20 7b 20 20 IP_UTF8(zIn) {
23960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23970 20 20 20 20 20 20 5c 0a 20 20 69 66 28 20 28 2a \. if( (*
23980 28 7a 49 6e 2b 2b 29 29 3e 3d 30 78 63 30 20 29 (zIn++))>=0xc0 )
23990 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
239a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5c \
239b0 0a 20 20 20 20 77 68 69 6c 65 28 20 28 2a 7a 49 . while( (*zI
239c0 6e 20 26 20 30 78 63 30 29 3d 3d 30 78 38 30 20 n & 0xc0)==0x80
239d0 29 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 20 20 20 20 ){ zIn++; }
239e0 20 20 20 20 20 20 20 20 5c 0a 20 20 7d 20 20 20 \. }
239f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23a00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23a10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
23a20 20 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 \.}../*.** The
23a30 53 51 4c 49 54 45 5f 2a 5f 42 4b 50 54 20 6d 61 SQLITE_*_BKPT ma
23a40 63 72 6f 73 20 61 72 65 20 73 75 62 73 74 69 74 cros are substit
23a50 75 74 65 73 20 66 6f 72 20 74 68 65 20 65 72 72 utes for the err
23a60 6f 72 20 63 6f 64 65 73 20 77 69 74 68 0a 2a 2a or codes with.**
23a70 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 20 62 the same name b
23a80 75 74 20 77 69 74 68 6f 75 74 20 74 68 65 20 5f ut without the _
23a90 42 4b 50 54 20 73 75 66 66 69 78 2e 20 20 54 68 BKPT suffix. Th
23aa0 65 73 65 20 6d 61 63 72 6f 73 20 69 6e 76 6f 6b ese macros invok
23ab0 65 0a 2a 2a 20 72 6f 75 74 69 6e 65 73 20 74 68 e.** routines th
23ac0 61 74 20 72 65 70 6f 72 74 20 74 68 65 20 6c 69 at report the li
23ad0 6e 65 2d 6e 75 6d 62 65 72 20 6f 6e 20 77 68 69 ne-number on whi
23ae0 63 68 20 74 68 65 20 65 72 72 6f 72 20 6f 72 69 ch the error ori
23af0 67 69 6e 61 74 65 64 0a 2a 2a 20 75 73 69 6e 67 ginated.** using
23b00 20 73 71 6c 69 74 65 33 5f 6c 6f 67 28 29 2e 20 sqlite3_log().
23b10 20 54 68 65 20 72 6f 75 74 69 6e 65 73 20 61 6c The routines al
23b20 73 6f 20 70 72 6f 76 69 64 65 20 61 20 63 6f 6e so provide a con
23b30 76 65 6e 69 65 6e 74 20 70 6c 61 63 65 0a 2a 2a venient place.**
23b40 20 74 6f 20 73 65 74 20 61 20 64 65 62 75 67 67 to set a debugg
23b50 65 72 20 62 72 65 61 6b 70 6f 69 6e 74 2e 0a 2a er breakpoint..*
23b60 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 72 /.int sqlite3Cor
23b70 72 75 70 74 45 72 72 6f 72 28 69 6e 74 29 3b 0a ruptError(int);.
23b80 69 6e 74 20 73 71 6c 69 74 65 33 4d 69 73 75 73 int sqlite3Misus
23b90 65 45 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e 74 eError(int);.int
23ba0 20 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e sqlite3Cantopen
23bb0 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 64 65 66 Error(int);.#def
23bc0 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 ine SQLITE_CORRU
23bd0 50 54 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 43 PT_BKPT sqlite3C
23be0 6f 72 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c 49 orruptError(__LI
23bf0 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 NE__).#define SQ
23c00 4c 49 54 45 5f 4d 49 53 55 53 45 5f 42 4b 50 54 LITE_MISUSE_BKPT
23c10 20 73 71 6c 69 74 65 33 4d 69 73 75 73 65 45 72 sqlite3MisuseEr
23c20 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 ror(__LINE__).#d
23c30 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 41 4e efine SQLITE_CAN
23c40 54 4f 50 45 4e 5f 42 4b 50 54 20 73 71 6c 69 74 TOPEN_BKPT sqlit
23c50 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 e3CantopenError(
23c60 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 69 66 64 65 66 __LINE__).#ifdef
23c70 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 20 SQLITE_DEBUG.
23c80 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f 6d 65 6d int sqlite3Nomem
23c90 45 72 72 6f 72 28 69 6e 74 29 3b 0a 20 20 69 6e Error(int);. in
23ca0 74 20 73 71 6c 69 74 65 33 49 6f 65 72 72 6e 6f t sqlite3Ioerrno
23cb0 6d 65 6d 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 memError(int);.#
23cc0 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e define SQLITE_N
23cd0 4f 4d 45 4d 5f 42 4b 50 54 20 73 71 6c 69 74 65 OMEM_BKPT sqlite
23ce0 33 4e 6f 6d 65 6d 45 72 72 6f 72 28 5f 5f 4c 49 3NomemError(__LI
23cf0 4e 45 5f 5f 29 0a 23 20 64 65 66 69 6e 65 20 53 NE__).# define S
23d00 51 4c 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d 45 QLITE_IOERR_NOME
23d10 4d 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 49 6f M_BKPT sqlite3Io
23d20 65 72 72 6e 6f 6d 65 6d 45 72 72 6f 72 28 5f 5f errnomemError(__
23d30 4c 49 4e 45 5f 5f 29 0a 23 65 6c 73 65 0a 23 20 LINE__).#else.#
23d40 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f define SQLITE_NO
23d50 4d 45 4d 5f 42 4b 50 54 20 53 51 4c 49 54 45 5f MEM_BKPT SQLITE_
23d60 4e 4f 4d 45 4d 0a 23 20 64 65 66 69 6e 65 20 53 NOMEM.# define S
23d70 51 4c 49 54 45 5f 49 4f 45 52 52 5f 4e 4f 4d 45 QLITE_IOERR_NOME
23d80 4d 5f 42 4b 50 54 20 53 51 4c 49 54 45 5f 49 4f M_BKPT SQLITE_IO
23d90 45 52 52 5f 4e 4f 4d 45 4d 0a 23 65 6e 64 69 66 ERR_NOMEM.#endif
23da0 0a 0a 2f 2a 0a 2a 2a 20 46 54 53 33 20 61 6e 64 ../*.** FTS3 and
23db0 20 46 54 53 34 20 62 6f 74 68 20 72 65 71 75 69 FTS4 both requi
23dc0 72 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 re virtual table
23dd0 20 73 75 70 70 6f 72 74 0a 2a 2f 0a 23 69 66 20 support.*/.#if
23de0 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f defined(SQLITE_O
23df0 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
23e00 29 0a 23 20 75 6e 64 65 66 20 53 51 4c 49 54 45 ).# undef SQLITE
23e10 5f 45 4e 41 42 4c 45 5f 46 54 53 33 0a 23 20 75 _ENABLE_FTS3.# u
23e20 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 ndef SQLITE_ENAB
23e30 4c 45 5f 46 54 53 34 0a 23 65 6e 64 69 66 0a 0a LE_FTS4.#endif..
23e40 2f 2a 0a 2a 2a 20 46 54 53 34 20 69 73 20 72 65 /*.** FTS4 is re
23e50 61 6c 6c 79 20 61 6e 20 65 78 74 65 6e 73 69 6f ally an extensio
23e60 6e 20 66 6f 72 20 46 54 53 33 2e 20 20 49 74 20 n for FTS3. It
23e70 69 73 20 65 6e 61 62 6c 65 64 20 75 73 69 6e 67 is enabled using
23e80 20 74 68 65 0a 2a 2a 20 53 51 4c 49 54 45 5f 45 the.** SQLITE_E
23e90 4e 41 42 4c 45 5f 46 54 53 33 20 6d 61 63 72 6f NABLE_FTS3 macro
23ea0 2e 20 20 42 75 74 20 74 6f 20 61 76 6f 69 64 20 . But to avoid
23eb0 63 6f 6e 66 75 73 69 6f 6e 20 77 65 20 61 6c 73 confusion we als
23ec0 6f 20 63 61 6c 6c 0a 2a 2a 20 74 68 65 20 53 51 o call.** the SQ
23ed0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 34 LITE_ENABLE_FTS4
23ee0 20 6d 61 63 72 6f 20 74 6f 20 73 65 72 76 65 20 macro to serve
23ef0 61 73 20 61 6e 20 61 6c 69 61 73 20 66 6f 72 20 as an alias for
23f00 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
23f10 53 33 2e 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e S3..*/.#if defin
23f20 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ed(SQLITE_ENABLE
23f30 5f 46 54 53 34 29 20 26 26 20 21 64 65 66 69 6e _FTS4) && !defin
23f40 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ed(SQLITE_ENABLE
23f50 5f 46 54 53 33 29 0a 23 20 64 65 66 69 6e 65 20 _FTS3).# define
23f60 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
23f70 53 33 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a S3 1.#endif../*.
23f80 2a 2a 20 54 68 65 20 63 74 79 70 65 2e 68 20 68 ** The ctype.h h
23f90 65 61 64 65 72 20 69 73 20 6e 65 65 64 65 64 20 eader is needed
23fa0 66 6f 72 20 6e 6f 6e 2d 41 53 43 49 49 20 73 79 for non-ASCII sy
23fb0 73 74 65 6d 73 2e 20 20 49 74 20 69 73 20 61 6c stems. It is al
23fc0 73 6f 0a 2a 2a 20 6e 65 65 64 65 64 20 62 79 20 so.** needed by
23fd0 46 54 53 33 20 77 68 65 6e 20 46 54 53 33 20 69 FTS3 when FTS3 i
23fe0 73 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 74 68 s included in th
23ff0 65 20 61 6d 61 6c 67 61 6d 61 74 69 6f 6e 2e 0a e amalgamation..
24000 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 */.#if !defined(
24010 53 51 4c 49 54 45 5f 41 53 43 49 49 29 20 7c 7c SQLITE_ASCII) ||
24020 20 5c 0a 20 20 20 20 28 64 65 66 69 6e 65 64 28 \. (defined(
24030 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 SQLITE_ENABLE_FT
24040 53 33 29 20 26 26 20 64 65 66 69 6e 65 64 28 53 S3) && defined(S
24050 51 4c 49 54 45 5f 41 4d 41 4c 47 41 4d 41 54 49 QLITE_AMALGAMATI
24060 4f 4e 29 29 0a 23 20 69 6e 63 6c 75 64 65 20 3c ON)).# include <
24070 63 74 79 70 65 2e 68 3e 0a 23 65 6e 64 69 66 0a ctype.h>.#endif.
24080 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
24090 77 69 6e 67 20 6d 61 63 72 6f 73 20 6d 69 6d 69 wing macros mimi
240a0 63 20 74 68 65 20 73 74 61 6e 64 61 72 64 20 6c c the standard l
240b0 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f 6e 73 ibrary functions
240c0 20 74 6f 75 70 70 65 72 28 29 2c 0a 2a 2a 20 69 toupper(),.** i
240d0 73 73 70 61 63 65 28 29 2c 20 69 73 61 6c 6e 75 sspace(), isalnu
240e0 6d 28 29 2c 20 69 73 64 69 67 69 74 28 29 20 61 m(), isdigit() a
240f0 6e 64 20 69 73 78 64 69 67 69 74 28 29 2c 20 72 nd isxdigit(), r
24100 65 73 70 65 63 74 69 76 65 6c 79 2e 20 54 68 65 espectively. The
24110 0a 2a 2a 20 73 71 6c 69 74 65 20 76 65 72 73 69 .** sqlite versi
24120 6f 6e 73 20 6f 6e 6c 79 20 77 6f 72 6b 20 66 6f ons only work fo
24130 72 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65 r ASCII characte
24140 72 73 2c 20 72 65 67 61 72 64 6c 65 73 73 20 6f rs, regardless o
24150 66 20 6c 6f 63 61 6c 65 2e 0a 2a 2f 0a 23 69 66 f locale..*/.#if
24160 64 65 66 20 53 51 4c 49 54 45 5f 41 53 43 49 49 def SQLITE_ASCII
24170 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
24180 33 54 6f 75 70 70 65 72 28 78 29 20 20 28 28 78 3Toupper(x) ((x
24190 29 26 7e 28 73 71 6c 69 74 65 33 43 74 79 70 65 )&~(sqlite3Ctype
241a0 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 Map[(unsigned ch
241b0 61 72 29 28 78 29 5d 26 30 78 32 30 29 29 0a 23 ar)(x)]&0x20)).#
241c0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 define sqlite3I
241d0 73 73 70 61 63 65 28 78 29 20 20 20 28 73 71 6c sspace(x) (sql
241e0 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e ite3CtypeMap[(un
241f0 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d signed char)(x)]
24200 26 30 78 30 31 29 0a 23 20 64 65 66 69 6e 65 20 &0x01).# define
24210 73 71 6c 69 74 65 33 49 73 61 6c 6e 75 6d 28 78 sqlite3Isalnum(x
24220 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 ) (sqlite3Ctyp
24230 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 eMap[(unsigned c
24240 68 61 72 29 28 78 29 5d 26 30 78 30 36 29 0a 23 har)(x)]&0x06).#
24250 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 define sqlite3I
24260 73 61 6c 70 68 61 28 78 29 20 20 20 28 73 71 6c salpha(x) (sql
24270 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e ite3CtypeMap[(un
24280 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d signed char)(x)]
24290 26 30 78 30 32 29 0a 23 20 64 65 66 69 6e 65 20 &0x02).# define
242a0 73 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 78 sqlite3Isdigit(x
242b0 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 79 70 ) (sqlite3Ctyp
242c0 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 20 63 eMap[(unsigned c
242d0 68 61 72 29 28 78 29 5d 26 30 78 30 34 29 0a 23 har)(x)]&0x04).#
242e0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 define sqlite3I
242f0 73 78 64 69 67 69 74 28 78 29 20 20 28 73 71 6c sxdigit(x) (sql
24300 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e ite3CtypeMap[(un
24310 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d signed char)(x)]
24320 26 30 78 30 38 29 0a 23 20 64 65 66 69 6e 65 20 &0x08).# define
24330 73 71 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 sqlite3Tolower(x
24340 29 20 20 20 28 73 71 6c 69 74 65 33 55 70 70 65 ) (sqlite3Uppe
24350 72 54 6f 4c 6f 77 65 72 5b 28 75 6e 73 69 67 6e rToLower[(unsign
24360 65 64 20 63 68 61 72 29 28 78 29 5d 29 0a 23 20 ed char)(x)]).#
24370 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
24380 71 75 6f 74 65 28 78 29 20 20 20 28 73 71 6c 69 quote(x) (sqli
24390 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 te3CtypeMap[(uns
243a0 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 5d 26 igned char)(x)]&
243b0 30 78 38 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 0x80).#else.# de
243c0 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f 75 70 fine sqlite3Toup
243d0 70 65 72 28 78 29 20 20 20 74 6f 75 70 70 65 72 per(x) toupper
243e0 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
243f0 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
24400 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 29 20 lite3Isspace(x)
24410 20 20 69 73 73 70 61 63 65 28 28 75 6e 73 69 67 isspace((unsig
24420 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 ned char)(x)).#
24430 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 define sqlite3Is
24440 61 6c 6e 75 6d 28 78 29 20 20 20 69 73 61 6c 6e alnum(x) isaln
24450 75 6d 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 um((unsigned cha
24460 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
24470 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 28 78 sqlite3Isalpha(x
24480 29 20 20 20 69 73 61 6c 70 68 61 28 28 75 6e 73 ) isalpha((uns
24490 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
244a0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
244b0 49 73 64 69 67 69 74 28 78 29 20 20 20 69 73 64 Isdigit(x) isd
244c0 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 20 63 igit((unsigned c
244d0 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
244e0 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 67 69 e sqlite3Isxdigi
244f0 74 28 78 29 20 20 69 73 78 64 69 67 69 74 28 28 t(x) isxdigit((
24500 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
24510 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 )).# define sqli
24520 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 20 te3Tolower(x)
24530 74 6f 6c 6f 77 65 72 28 28 75 6e 73 69 67 6e 65 tolower((unsigne
24540 64 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 d char)(x)).# de
24550 66 69 6e 65 20 73 71 6c 69 74 65 33 49 73 71 75 fine sqlite3Isqu
24560 6f 74 65 28 78 29 20 20 20 28 28 78 29 3d 3d 27 ote(x) ((x)=='
24570 22 27 7c 7c 28 78 29 3d 3d 27 5c 27 27 7c 7c 28 "'||(x)=='\''||(
24580 78 29 3d 3d 27 5b 27 7c 7c 28 78 29 3d 3d 27 60 x)=='['||(x)=='`
24590 27 29 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 ').#endif.#ifnde
245a0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 4f f SQLITE_OMIT_CO
245b0 4d 50 49 4c 45 4f 50 54 49 4f 4e 5f 44 49 41 47 MPILEOPTION_DIAG
245c0 53 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 73 49 S.int sqlite3IsI
245d0 64 43 68 61 72 28 75 38 29 3b 0a 23 65 6e 64 69 dChar(u8);.#endi
245e0 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 72 6e 61 f../*.** Interna
245f0 6c 20 66 75 6e 63 74 69 6f 6e 20 70 72 6f 74 6f l function proto
24600 74 79 70 65 73 0a 2a 2f 0a 69 6e 74 20 73 71 6c types.*/.int sql
24610 69 74 65 33 53 74 72 49 43 6d 70 28 63 6f 6e 73 ite3StrICmp(cons
24620 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 t char*,const ch
24630 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ar*);.int sqlite
24640 33 53 74 72 6c 65 6e 33 30 28 63 6f 6e 73 74 20 3Strlen30(const
24650 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 2a 73 71 char*);.char *sq
24660 6c 69 74 65 33 43 6f 6c 75 6d 6e 54 79 70 65 28 lite3ColumnType(
24670 43 6f 6c 75 6d 6e 2a 2c 63 68 61 72 2a 29 3b 0a Column*,char*);.
24680 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 #define sqlite3S
24690 74 72 4e 49 43 6d 70 20 73 71 6c 69 74 65 33 5f trNICmp sqlite3_
246a0 73 74 72 6e 69 63 6d 70 0a 0a 69 6e 74 20 73 71 strnicmp..int sq
246b0 6c 69 74 65 33 4d 61 6c 6c 6f 63 49 6e 69 74 28 lite3MallocInit(
246c0 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 void);.void sqli
246d0 74 65 33 4d 61 6c 6c 6f 63 45 6e 64 28 76 6f 69 te3MallocEnd(voi
246e0 64 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 d);.void *sqlite
246f0 33 4d 61 6c 6c 6f 63 28 75 36 34 29 3b 0a 76 6f 3Malloc(u64);.vo
24700 69 64 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f id *sqlite3Mallo
24710 63 5a 65 72 6f 28 75 36 34 29 3b 0a 76 6f 69 64 cZero(u64);.void
24720 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f *sqlite3DbMallo
24730 63 5a 65 72 6f 28 73 71 6c 69 74 65 33 2a 2c 20 cZero(sqlite3*,
24740 75 36 34 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 u64);.void *sqli
24750 74 65 33 44 62 4d 61 6c 6c 6f 63 52 61 77 28 73 te3DbMallocRaw(s
24760 71 6c 69 74 65 33 2a 2c 20 75 36 34 29 3b 0a 76 qlite3*, u64);.v
24770 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 62 4d 61 oid *sqlite3DbMa
24780 6c 6c 6f 63 52 61 77 4e 4e 28 73 71 6c 69 74 65 llocRawNN(sqlite
24790 33 2a 2c 20 75 36 34 29 3b 0a 63 68 61 72 20 2a 3*, u64);.char *
247a0 73 71 6c 69 74 65 33 44 62 53 74 72 44 75 70 28 sqlite3DbStrDup(
247b0 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 sqlite3*,const c
247c0 68 61 72 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c har*);.char *sql
247d0 69 74 65 33 44 62 53 74 72 4e 44 75 70 28 73 71 ite3DbStrNDup(sq
247e0 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
247f0 72 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 20 2a r*, u64);.void *
24800 73 71 6c 69 74 65 33 52 65 61 6c 6c 6f 63 28 76 sqlite3Realloc(v
24810 6f 69 64 2a 2c 20 75 36 34 29 3b 0a 76 6f 69 64 oid*, u64);.void
24820 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 6c 6c *sqlite3DbReall
24830 6f 63 4f 72 46 72 65 65 28 73 71 6c 69 74 65 33 ocOrFree(sqlite3
24840 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 29 *, void *, u64)
24850 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 ;.void *sqlite3D
24860 62 52 65 61 6c 6c 6f 63 28 73 71 6c 69 74 65 33 bRealloc(sqlite3
24870 20 2a 2c 20 76 6f 69 64 20 2a 2c 20 75 36 34 29 *, void *, u64)
24880 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 62 ;.void sqlite3Db
24890 46 72 65 65 28 73 71 6c 69 74 65 33 2a 2c 20 76 Free(sqlite3*, v
248a0 6f 69 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 oid*);.int sqlit
248b0 65 33 4d 61 6c 6c 6f 63 53 69 7a 65 28 76 6f 69 e3MallocSize(voi
248c0 64 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 d*);.int sqlite3
248d0 44 62 4d 61 6c 6c 6f 63 53 69 7a 65 28 73 71 6c DbMallocSize(sql
248e0 69 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b 0a 76 ite3*, void*);.v
248f0 6f 69 64 20 2a 73 71 6c 69 74 65 33 53 63 72 61 oid *sqlite3Scra
24900 74 63 68 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a tchMalloc(int);.
24910 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 72 61 void sqlite3Scra
24920 74 63 68 46 72 65 65 28 76 6f 69 64 2a 29 3b 0a tchFree(void*);.
24930 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 50 61 67 void *sqlite3Pag
24940 65 4d 61 6c 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f eMalloc(int);.vo
24950 69 64 20 73 71 6c 69 74 65 33 50 61 67 65 46 72 id sqlite3PageFr
24960 65 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 ee(void*);.void
24970 73 71 6c 69 74 65 33 4d 65 6d 53 65 74 44 65 66 sqlite3MemSetDef
24980 61 75 6c 74 28 76 6f 69 64 29 3b 0a 23 69 66 6e ault(void);.#ifn
24990 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 def SQLITE_UNTES
249a0 54 41 42 4c 45 0a 76 6f 69 64 20 73 71 6c 69 74 TABLE.void sqlit
249b0 65 33 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 48 6f e3BenignMallocHo
249c0 6f 6b 73 28 76 6f 69 64 20 28 2a 29 28 76 6f 69 oks(void (*)(voi
249d0 64 29 2c 20 76 6f 69 64 20 28 2a 29 28 76 6f 69 d), void (*)(voi
249e0 64 29 29 3b 0a 23 65 6e 64 69 66 0a 69 6e 74 20 d));.#endif.int
249f0 73 71 6c 69 74 65 33 48 65 61 70 4e 65 61 72 6c sqlite3HeapNearl
24a00 79 46 75 6c 6c 28 76 6f 69 64 29 3b 0a 0a 2f 2a yFull(void);../*
24a10 0a 2a 2a 20 4f 6e 20 73 79 73 74 65 6d 73 20 77 .** On systems w
24a20 69 74 68 20 61 6d 70 6c 65 20 73 74 61 63 6b 20 ith ample stack
24a30 73 70 61 63 65 20 61 6e 64 20 74 68 61 74 20 73 space and that s
24a40 75 70 70 6f 72 74 20 61 6c 6c 6f 63 61 28 29 2c upport alloca(),
24a50 20 6d 61 6b 65 0a 2a 2a 20 75 73 65 20 6f 66 20 make.** use of
24a60 61 6c 6c 6f 63 61 28 29 20 74 6f 20 6f 62 74 61 alloca() to obta
24a70 69 6e 20 73 70 61 63 65 20 66 6f 72 20 6c 61 72 in space for lar
24a80 67 65 20 61 75 74 6f 6d 61 74 69 63 20 6f 62 6a ge automatic obj
24a90 65 63 74 73 2e 20 20 42 79 20 64 65 66 61 75 6c ects. By defaul
24aa0 74 2c 0a 2a 2a 20 6f 62 74 61 69 6e 20 73 70 61 t,.** obtain spa
24ab0 63 65 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 28 29 ce from malloc()
24ac0 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 61 6c 6c 6f ..**.** The allo
24ad0 63 61 28 29 20 72 6f 75 74 69 6e 65 20 6e 65 76 ca() routine nev
24ae0 65 72 20 72 65 74 75 72 6e 73 20 4e 55 4c 4c 2e er returns NULL.
24af0 20 20 54 68 69 73 20 77 69 6c 6c 20 63 61 75 73 This will caus
24b00 65 20 63 6f 64 65 20 70 61 74 68 73 0a 2a 2a 20 e code paths.**
24b10 74 68 61 74 20 64 65 61 6c 20 77 69 74 68 20 73 that deal with s
24b20 71 6c 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 qlite3StackAlloc
24b30 28 29 20 66 61 69 6c 75 72 65 73 20 74 6f 20 62 () failures to b
24b40 65 20 75 6e 72 65 61 63 68 61 62 6c 65 2e 0a 2a e unreachable..*
24b50 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f /.#ifdef SQLITE_
24b60 55 53 45 5f 41 4c 4c 4f 43 41 0a 23 20 64 65 66 USE_ALLOCA.# def
24b70 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b ine sqlite3Stack
24b80 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 20 AllocRaw(D,N)
24b90 61 6c 6c 6f 63 61 28 4e 29 0a 23 20 64 65 66 69 alloca(N).# defi
24ba0 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 ne sqlite3StackA
24bb0 6c 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 6d llocZero(D,N) m
24bc0 65 6d 73 65 74 28 61 6c 6c 6f 63 61 28 4e 29 2c emset(alloca(N),
24bd0 20 30 2c 20 4e 29 0a 23 20 64 65 66 69 6e 65 20 0, N).# define
24be0 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 65 sqlite3StackFree
24bf0 28 44 2c 50 29 0a 23 65 6c 73 65 0a 23 20 64 65 (D,P).#else.# de
24c00 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
24c10 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 kAllocRaw(D,N)
24c20 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 sqlite3DbMalloc
24c30 52 61 77 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e Raw(D,N).# defin
24c40 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c e sqlite3StackAl
24c50 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 73 71 locZero(D,N) sq
24c60 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 lite3DbMallocZer
24c70 6f 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 o(D,N).# define
24c80 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 65 sqlite3StackFree
24c90 28 44 2c 50 29 20 20 20 20 20 20 20 73 71 6c 69 (D,P) sqli
24ca0 74 65 33 44 62 46 72 65 65 28 44 2c 50 29 0a 23 te3DbFree(D,P).#
24cb0 65 6e 64 69 66 0a 0a 2f 2a 20 44 6f 20 6e 6f 74 endif../* Do not
24cc0 20 61 6c 6c 6f 77 20 62 6f 74 68 20 4d 45 4d 53 allow both MEMS
24cd0 59 53 35 20 61 6e 64 20 4d 45 4d 53 59 53 33 20 YS5 and MEMSYS3
24ce0 74 6f 20 62 65 20 64 65 66 69 6e 65 64 20 74 6f to be defined to
24cf0 67 65 74 68 65 72 2e 20 20 49 66 20 74 68 65 79 gether. If they
24d00 0a 2a 2a 20 61 72 65 2c 20 64 69 73 61 62 6c 65 .** are, disable
24d10 20 4d 45 4d 53 59 53 33 0a 2a 2f 0a 23 69 66 64 MEMSYS3.*/.#ifd
24d20 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ef SQLITE_ENABLE
24d30 5f 4d 45 4d 53 59 53 35 0a 63 6f 6e 73 74 20 73 _MEMSYS5.const s
24d40 71 6c 69 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f qlite3_mem_metho
24d50 64 73 20 2a 73 71 6c 69 74 65 33 4d 65 6d 47 65 ds *sqlite3MemGe
24d60 74 4d 65 6d 73 79 73 35 28 76 6f 69 64 29 3b 0a tMemsys5(void);.
24d70 23 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e #undef SQLITE_EN
24d80 41 42 4c 45 5f 4d 45 4d 53 59 53 33 0a 23 65 6e ABLE_MEMSYS3.#en
24d90 64 69 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 dif.#ifdef SQLIT
24da0 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 33 E_ENABLE_MEMSYS3
24db0 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d .const sqlite3_m
24dc0 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 em_methods *sqli
24dd0 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 33 te3MemGetMemsys3
24de0 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 0a (void);.#endif..
24df0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
24e00 4d 55 54 45 58 5f 4f 4d 49 54 0a 20 20 73 71 6c MUTEX_OMIT. sql
24e10 69 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f ite3_mutex_metho
24e20 64 73 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 ds const *sqlite
24e30 33 44 65 66 61 75 6c 74 4d 75 74 65 78 28 76 6f 3DefaultMutex(vo
24e40 69 64 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d id);. sqlite3_m
24e50 75 74 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e utex_methods con
24e60 73 74 20 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 4d st *sqlite3NoopM
24e70 75 74 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 utex(void);. sq
24e80 6c 69 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c lite3_mutex *sql
24e90 69 74 65 33 4d 75 74 65 78 41 6c 6c 6f 63 28 69 ite3MutexAlloc(i
24ea0 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 nt);. int sqlit
24eb0 65 33 4d 75 74 65 78 49 6e 69 74 28 76 6f 69 64 e3MutexInit(void
24ec0 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
24ed0 4d 75 74 65 78 45 6e 64 28 76 6f 69 64 29 3b 0a MutexEnd(void);.
24ee0 23 65 6e 64 69 66 0a 23 69 66 20 21 64 65 66 69 #endif.#if !defi
24ef0 6e 65 64 28 53 51 4c 49 54 45 5f 4d 55 54 45 58 ned(SQLITE_MUTEX
24f00 5f 4f 4d 49 54 29 20 26 26 20 21 64 65 66 69 6e _OMIT) && !defin
24f10 65 64 28 53 51 4c 49 54 45 5f 4d 55 54 45 58 5f ed(SQLITE_MUTEX_
24f20 4e 4f 4f 50 29 0a 20 20 76 6f 69 64 20 73 71 6c NOOP). void sql
24f30 69 74 65 33 4d 65 6d 6f 72 79 42 61 72 72 69 65 ite3MemoryBarrie
24f40 72 28 76 6f 69 64 29 3b 0a 23 65 6c 73 65 0a 23 r(void);.#else.#
24f50 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d define sqlite3M
24f60 65 6d 6f 72 79 42 61 72 72 69 65 72 28 29 0a 23 emoryBarrier().#
24f70 65 6e 64 69 66 0a 0a 73 71 6c 69 74 65 33 5f 69 endif..sqlite3_i
24f80 6e 74 36 34 20 73 71 6c 69 74 65 33 53 74 61 74 nt64 sqlite3Stat
24f90 75 73 56 61 6c 75 65 28 69 6e 74 29 3b 0a 76 6f usValue(int);.vo
24fa0 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 id sqlite3Status
24fb0 55 70 28 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f Up(int, int);.vo
24fc0 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 75 73 id sqlite3Status
24fd0 44 6f 77 6e 28 69 6e 74 2c 20 69 6e 74 29 3b 0a Down(int, int);.
24fe0 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 61 74 void sqlite3Stat
24ff0 75 73 48 69 67 68 77 61 74 65 72 28 69 6e 74 2c usHighwater(int,
25000 20 69 6e 74 29 3b 0a 0a 2f 2a 20 41 63 63 65 73 int);../* Acces
25010 73 20 74 6f 20 6d 75 74 65 78 65 73 20 75 73 65 s to mutexes use
25020 64 20 62 79 20 73 71 6c 69 74 65 33 5f 73 74 61 d by sqlite3_sta
25030 74 75 73 28 29 20 2a 2f 0a 73 71 6c 69 74 65 33 tus() */.sqlite3
25040 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 65 33 50 _mutex *sqlite3P
25050 63 61 63 68 65 31 4d 75 74 65 78 28 76 6f 69 64 cache1Mutex(void
25060 29 3b 0a 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 );.sqlite3_mutex
25070 20 2a 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 4d *sqlite3MallocM
25080 75 74 65 78 28 76 6f 69 64 29 3b 0a 0a 23 69 66 utex(void);..#if
25090 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
250a0 5f 46 4c 4f 41 54 49 4e 47 5f 50 4f 49 4e 54 0a _FLOATING_POINT.
250b0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 49 73 4e int sqlite3IsN
250c0 61 4e 28 64 6f 75 62 6c 65 29 3b 0a 23 65 6c 73 aN(double);.#els
250d0 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
250e0 65 33 49 73 4e 61 4e 28 58 29 20 20 30 0a 23 65 e3IsNaN(X) 0.#e
250f0 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 ndif../*.** An i
25100 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 66 nstance of the f
25110 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 75 ollowing structu
25120 72 65 20 68 6f 6c 64 73 20 69 6e 66 6f 72 6d 61 re holds informa
25130 74 69 6f 6e 20 61 62 6f 75 74 20 53 51 4c 0a 2a tion about SQL.*
25140 2a 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 67 75 * functions argu
25150 6d 65 6e 74 73 20 74 68 61 74 20 61 72 65 20 74 ments that are t
25160 68 65 20 70 61 72 61 6d 65 74 65 72 73 20 74 6f he parameters to
25170 20 74 68 65 20 70 72 69 6e 74 66 28 29 20 66 75 the printf() fu
25180 6e 63 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 nction..*/.struc
25190 74 20 50 72 69 6e 74 66 41 72 67 75 6d 65 6e 74 t PrintfArgument
251a0 73 20 7b 0a 20 20 69 6e 74 20 6e 41 72 67 3b 20 s {. int nArg;
251b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
251c0 2a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f * Total number o
251d0 66 20 61 72 67 75 6d 65 6e 74 73 20 2a 2f 0a 20 f arguments */.
251e0 20 69 6e 74 20 6e 55 73 65 64 3b 20 20 20 20 20 int nUsed;
251f0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
25200 62 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ber of arguments
25210 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f 0a used so far */.
25220 20 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 sqlite3_value
25230 2a 2a 61 70 41 72 67 3b 20 20 20 2f 2a 20 54 68 **apArg; /* Th
25240 65 20 61 72 67 75 6d 65 6e 74 20 76 61 6c 75 65 e argument value
25250 73 20 2a 2f 0a 7d 3b 0a 0a 76 6f 69 64 20 73 71 s */.};..void sq
25260 6c 69 74 65 33 56 58 50 72 69 6e 74 66 28 53 74 lite3VXPrintf(St
25270 72 41 63 63 75 6d 2a 2c 20 63 6f 6e 73 74 20 63 rAccum*, const c
25280 68 61 72 2a 2c 20 76 61 5f 6c 69 73 74 29 3b 0a har*, va_list);.
25290 76 6f 69 64 20 73 71 6c 69 74 65 33 58 50 72 69 void sqlite3XPri
252a0 6e 74 66 28 53 74 72 41 63 63 75 6d 2a 2c 20 63 ntf(StrAccum*, c
252b0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 onst char*, ...)
252c0 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4d ;.char *sqlite3M
252d0 50 72 69 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c Printf(sqlite3*,
252e0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e const char*, ...
252f0 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 );.char *sqlite3
25300 56 4d 50 72 69 6e 74 66 28 73 71 6c 69 74 65 33 VMPrintf(sqlite3
25310 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 *,const char*, v
25320 61 5f 6c 69 73 74 29 3b 0a 23 69 66 20 64 65 66 a_list);.#if def
25330 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 ined(SQLITE_DEBU
25340 47 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 51 G) || defined(SQ
25350 4c 49 54 45 5f 48 41 56 45 5f 4f 53 5f 54 52 41 LITE_HAVE_OS_TRA
25360 43 45 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 CE). void sqlit
25370 65 33 44 65 62 75 67 50 72 69 6e 74 66 28 63 6f e3DebugPrintf(co
25380 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b nst char*, ...);
25390 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
253a0 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 ned(SQLITE_TEST)
253b0 0a 20 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 . void *sqlite3
253c0 54 65 73 74 54 65 78 74 54 6f 50 74 72 28 63 6f TestTextToPtr(co
253d0 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 nst char*);.#end
253e0 69 66 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 if..#if defined(
253f0 53 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 20 SQLITE_DEBUG).
25400 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 void sqlite3Tree
25410 56 69 65 77 45 78 70 72 28 54 72 65 65 56 69 65 ViewExpr(TreeVie
25420 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 2a 2c w*, const Expr*,
25430 20 75 38 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c u8);. void sql
25440 69 74 65 33 54 72 65 65 56 69 65 77 42 61 72 65 ite3TreeViewBare
25450 45 78 70 72 4c 69 73 74 28 54 72 65 65 56 69 65 ExprList(TreeVie
25460 77 2a 2c 20 63 6f 6e 73 74 20 45 78 70 72 4c 69 w*, const ExprLi
25470 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a st*, const char*
25480 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
25490 33 54 72 65 65 56 69 65 77 45 78 70 72 4c 69 73 3TreeViewExprLis
254a0 74 28 54 72 65 65 56 69 65 77 2a 2c 20 63 6f 6e t(TreeView*, con
254b0 73 74 20 45 78 70 72 4c 69 73 74 2a 2c 20 75 38 st ExprList*, u8
254c0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
254d0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 72 void sqlite3Tr
254e0 65 65 56 69 65 77 53 65 6c 65 63 74 28 54 72 65 eeViewSelect(Tre
254f0 65 56 69 65 77 2a 2c 20 63 6f 6e 73 74 20 53 65 eView*, const Se
25500 6c 65 63 74 2a 2c 20 75 38 29 3b 0a 20 20 76 6f lect*, u8);. vo
25510 69 64 20 73 71 6c 69 74 65 33 54 72 65 65 56 69 id sqlite3TreeVi
25520 65 77 57 69 74 68 28 54 72 65 65 56 69 65 77 2a ewWith(TreeView*
25530 2c 20 63 6f 6e 73 74 20 57 69 74 68 2a 2c 20 75 , const With*, u
25540 38 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 76 6f 69 8);.#endif...voi
25550 64 20 73 71 6c 69 74 65 33 53 65 74 53 74 72 69 d sqlite3SetStri
25560 6e 67 28 63 68 61 72 20 2a 2a 2c 20 73 71 6c 69 ng(char **, sqli
25570 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 te3*, const char
25580 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
25590 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c ErrorMsg(Parse*,
255a0 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e const char*, ..
255b0 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 .);.void sqlite3
255c0 44 65 71 75 6f 74 65 28 63 68 61 72 2a 29 3b 0a Dequote(char*);.
255d0 76 6f 69 64 20 73 71 6c 69 74 65 33 54 6f 6b 65 void sqlite3Toke
255e0 6e 49 6e 69 74 28 54 6f 6b 65 6e 2a 2c 63 68 61 nInit(Token*,cha
255f0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
25600 4b 65 79 77 6f 72 64 43 6f 64 65 28 63 6f 6e 73 KeywordCode(cons
25610 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a t unsigned char*
25620 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
25630 74 65 33 52 75 6e 50 61 72 73 65 72 28 50 61 72 te3RunParser(Par
25640 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a se*, const char*
25650 2c 20 63 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 , char **);.void
25660 20 73 71 6c 69 74 65 33 46 69 6e 69 73 68 43 6f sqlite3FinishCo
25670 64 69 6e 67 28 50 61 72 73 65 2a 29 3b 0a 69 6e ding(Parse*);.in
25680 74 20 73 71 6c 69 74 65 33 47 65 74 54 65 6d 70 t sqlite3GetTemp
25690 52 65 67 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 Reg(Parse*);.voi
256a0 64 20 73 71 6c 69 74 65 33 52 65 6c 65 61 73 65 d sqlite3Release
256b0 54 65 6d 70 52 65 67 28 50 61 72 73 65 2a 2c 69 TempReg(Parse*,i
256c0 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
256d0 47 65 74 54 65 6d 70 52 61 6e 67 65 28 50 61 72 GetTempRange(Par
256e0 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 se*,int);.void s
256f0 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d qlite3ReleaseTem
25700 70 52 61 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e pRange(Parse*,in
25710 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c t,int);.void sql
25720 69 74 65 33 43 6c 65 61 72 54 65 6d 70 52 65 67 ite3ClearTempReg
25730 43 61 63 68 65 28 50 61 72 73 65 2a 29 3b 0a 23 Cache(Parse*);.#
25740 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
25750 55 47 0a 69 6e 74 20 73 71 6c 69 74 65 33 4e 6f UG.int sqlite3No
25760 54 65 6d 70 73 49 6e 52 61 6e 67 65 28 50 61 72 TempsInRange(Par
25770 73 65 2a 2c 69 6e 74 2c 69 6e 74 29 3b 0a 23 65 se*,int,int);.#e
25780 6e 64 69 66 0a 45 78 70 72 20 2a 73 71 6c 69 74 ndif.Expr *sqlit
25790 65 33 45 78 70 72 41 6c 6c 6f 63 28 73 71 6c 69 e3ExprAlloc(sqli
257a0 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 54 te3*,int,const T
257b0 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 45 78 70 72 oken*,int);.Expr
257c0 20 2a 73 71 6c 69 74 65 33 45 78 70 72 28 73 71 *sqlite3Expr(sq
257d0 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 lite3*,int,const
257e0 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 char*);.void sq
257f0 6c 69 74 65 33 45 78 70 72 41 74 74 61 63 68 53 lite3ExprAttachS
25800 75 62 74 72 65 65 73 28 73 71 6c 69 74 65 33 2a ubtrees(sqlite3*
25810 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 45 78 70 ,Expr*,Expr*,Exp
25820 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 r*);.Expr *sqlit
25830 65 33 50 45 78 70 72 28 50 61 72 73 65 2a 2c 20 e3PExpr(Parse*,
25840 69 6e 74 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 int, Expr*, Expr
25850 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
25860 50 45 78 70 72 41 64 64 53 65 6c 65 63 74 28 50 PExprAddSelect(P
25870 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 53 65 arse*, Expr*, Se
25880 6c 65 63 74 2a 29 3b 0a 45 78 70 72 20 2a 73 71 lect*);.Expr *sq
25890 6c 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 6c lite3ExprAnd(sql
258a0 69 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 70 ite3*,Expr*, Exp
258b0 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 r*);.Expr *sqlit
258c0 65 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 50 e3ExprFunction(P
258d0 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c arse*,ExprList*,
258e0 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 Token*);.void s
258f0 71 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 6e qlite3ExprAssign
25900 56 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 2a VarNumber(Parse*
25910 2c 20 45 78 70 72 2a 2c 20 75 33 32 29 3b 0a 76 , Expr*, u32);.v
25920 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 44 oid sqlite3ExprD
25930 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 elete(sqlite3*,
25940 45 78 70 72 2a 29 3b 0a 45 78 70 72 4c 69 73 74 Expr*);.ExprList
25950 20 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 *sqlite3ExprLis
25960 74 41 70 70 65 6e 64 28 50 61 72 73 65 2a 2c 45 tAppend(Parse*,E
25970 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 2a 29 3b xprList*,Expr*);
25980 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 .ExprList *sqlit
25990 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e 64 e3ExprListAppend
259a0 56 65 63 74 6f 72 28 50 61 72 73 65 2a 2c 45 78 Vector(Parse*,Ex
259b0 70 72 4c 69 73 74 2a 2c 49 64 4c 69 73 74 2a 2c prList*,IdList*,
259c0 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
259d0 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 53 ite3ExprListSetS
259e0 6f 72 74 4f 72 64 65 72 28 45 78 70 72 4c 69 73 ortOrder(ExprLis
259f0 74 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t*,int);.void sq
25a00 6c 69 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 lite3ExprListSet
25a10 4e 61 6d 65 28 50 61 72 73 65 2a 2c 45 78 70 72 Name(Parse*,Expr
25a20 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 List*,Token*,int
25a30 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
25a40 78 70 72 4c 69 73 74 53 65 74 53 70 61 6e 28 50 xprListSetSpan(P
25a50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c arse*,ExprList*,
25a60 45 78 70 72 53 70 61 6e 2a 29 3b 0a 76 6f 69 64 ExprSpan*);.void
25a70 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 sqlite3ExprList
25a80 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c Delete(sqlite3*,
25a90 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 75 33 32 ExprList*);.u32
25aa0 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 sqlite3ExprList
25ab0 46 6c 61 67 73 28 63 6f 6e 73 74 20 45 78 70 72 Flags(const Expr
25ac0 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 List*);.int sqli
25ad0 74 65 33 49 6e 69 74 28 73 71 6c 69 74 65 33 2a te3Init(sqlite3*
25ae0 2c 20 63 68 61 72 2a 2a 29 3b 0a 69 6e 74 20 73 , char**);.int s
25af0 71 6c 69 74 65 33 49 6e 69 74 43 61 6c 6c 62 61 qlite3InitCallba
25b00 63 6b 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 63 ck(void*, int, c
25b10 68 61 72 2a 2a 2c 20 63 68 61 72 2a 2a 29 3b 0a har**, char**);.
25b20 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 61 67 void sqlite3Prag
25b30 6d 61 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a ma(Parse*,Token*
25b40 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 ,Token*,Token*,i
25b50 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
25b60 33 52 65 73 65 74 41 6c 6c 53 63 68 65 6d 61 73 3ResetAllSchemas
25b70 4f 66 43 6f 6e 6e 65 63 74 69 6f 6e 28 73 71 6c OfConnection(sql
25b80 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ite3*);.void sql
25b90 69 74 65 33 52 65 73 65 74 4f 6e 65 53 63 68 65 ite3ResetOneSche
25ba0 6d 61 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 29 ma(sqlite3*,int)
25bb0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f ;.void sqlite3Co
25bc0 6c 6c 61 70 73 65 44 61 74 61 62 61 73 65 41 72 llapseDatabaseAr
25bd0 72 61 79 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 ray(sqlite3*);.v
25be0 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6d 6d 69 oid sqlite3Commi
25bf0 74 49 6e 74 65 72 6e 61 6c 43 68 61 6e 67 65 73 tInternalChanges
25c00 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
25c10 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 43 6f sqlite3DeleteCo
25c20 6c 75 6d 6e 4e 61 6d 65 73 28 73 71 6c 69 74 65 lumnNames(sqlite
25c30 33 2a 2c 54 61 62 6c 65 2a 29 3b 0a 69 6e 74 20 3*,Table*);.int
25c40 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 73 46 72 sqlite3ColumnsFr
25c50 6f 6d 45 78 70 72 4c 69 73 74 28 50 61 72 73 65 omExprList(Parse
25c60 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 31 36 2a *,ExprList*,i16*
25c70 2c 43 6f 6c 75 6d 6e 2a 2a 29 3b 0a 76 6f 69 64 ,Column**);.void
25c80 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 41 64 sqlite3SelectAd
25c90 64 43 6f 6c 75 6d 6e 54 79 70 65 41 6e 64 43 6f dColumnTypeAndCo
25ca0 6c 6c 61 74 69 6f 6e 28 50 61 72 73 65 2a 2c 54 llation(Parse*,T
25cb0 61 62 6c 65 2a 2c 53 65 6c 65 63 74 2a 29 3b 0a able*,Select*);.
25cc0 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 52 65 Table *sqlite3Re
25cd0 73 75 6c 74 53 65 74 4f 66 53 65 6c 65 63 74 28 sultSetOfSelect(
25ce0 50 61 72 73 65 2a 2c 53 65 6c 65 63 74 2a 29 3b Parse*,Select*);
25cf0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4f 70 65 .void sqlite3Ope
25d00 6e 4d 61 73 74 65 72 54 61 62 6c 65 28 50 61 72 nMasterTable(Par
25d10 73 65 20 2a 2c 20 69 6e 74 29 3b 0a 49 6e 64 65 se *, int);.Inde
25d20 78 20 2a 73 71 6c 69 74 65 33 50 72 69 6d 61 72 x *sqlite3Primar
25d30 79 4b 65 79 49 6e 64 65 78 28 54 61 62 6c 65 2a yKeyIndex(Table*
25d40 29 3b 0a 69 31 36 20 73 71 6c 69 74 65 33 43 6f );.i16 sqlite3Co
25d50 6c 75 6d 6e 4f 66 49 6e 64 65 78 28 49 6e 64 65 lumnOfIndex(Inde
25d60 78 2a 2c 20 69 31 36 29 3b 0a 76 6f 69 64 20 73 x*, i16);.void s
25d70 71 6c 69 74 65 33 53 74 61 72 74 54 61 62 6c 65 qlite3StartTable
25d80 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 (Parse*,Token*,T
25d90 6f 6b 65 6e 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e oken*,int,int,in
25da0 74 2c 69 6e 74 29 3b 0a 23 69 66 20 53 51 4c 49 t,int);.#if SQLI
25db0 54 45 5f 45 4e 41 42 4c 45 5f 48 49 44 44 45 4e TE_ENABLE_HIDDEN
25dc0 5f 43 4f 4c 55 4d 4e 53 0a 20 20 76 6f 69 64 20 _COLUMNS. void
25dd0 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 50 72 6f sqlite3ColumnPro
25de0 70 65 72 74 69 65 73 46 72 6f 6d 4e 61 6d 65 28 pertiesFromName(
25df0 54 61 62 6c 65 2a 2c 20 43 6f 6c 75 6d 6e 2a 29 Table*, Column*)
25e00 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ;.#else.# define
25e10 20 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 50 72 sqlite3ColumnPr
25e20 6f 70 65 72 74 69 65 73 46 72 6f 6d 4e 61 6d 65 opertiesFromName
25e30 28 54 2c 43 29 20 2f 2a 20 6e 6f 2d 6f 70 20 2a (T,C) /* no-op *
25e40 2f 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 /.#endif.void sq
25e50 6c 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e 28 50 lite3AddColumn(P
25e60 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b arse*,Token*,Tok
25e70 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
25e80 65 33 41 64 64 4e 6f 74 4e 75 6c 6c 28 50 61 72 e3AddNotNull(Par
25e90 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 se*, int);.void
25ea0 73 71 6c 69 74 65 33 41 64 64 50 72 69 6d 61 72 sqlite3AddPrimar
25eb0 79 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 70 yKey(Parse*, Exp
25ec0 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 rList*, int, int
25ed0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
25ee0 69 74 65 33 41 64 64 43 68 65 63 6b 43 6f 6e 73 ite3AddCheckCons
25ef0 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 45 traint(Parse*, E
25f00 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 xpr*);.void sqli
25f10 74 65 33 41 64 64 44 65 66 61 75 6c 74 56 61 6c te3AddDefaultVal
25f20 75 65 28 50 61 72 73 65 2a 2c 45 78 70 72 53 70 ue(Parse*,ExprSp
25f30 61 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 an*);.void sqlit
25f40 65 33 41 64 64 43 6f 6c 6c 61 74 65 54 79 70 65 e3AddCollateType
25f50 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 (Parse*, Token*)
25f60 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 6e ;.void sqlite3En
25f70 64 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 54 6f dTable(Parse*,To
25f80 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 75 38 2c 53 ken*,Token*,u8,S
25f90 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
25fa0 69 74 65 33 50 61 72 73 65 55 72 69 28 63 6f 6e ite3ParseUri(con
25fb0 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 st char*,const c
25fc0 68 61 72 2a 2c 75 6e 73 69 67 6e 65 64 20 69 6e har*,unsigned in
25fd0 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 t*,.
25fe0 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 33 5f sqlite3_
25ff0 76 66 73 2a 2a 2c 63 68 61 72 2a 2a 2c 63 68 61 vfs**,char**,cha
26000 72 20 2a 2a 29 3b 0a 42 74 72 65 65 20 2a 73 71 r **);.Btree *sq
26010 6c 69 74 65 33 44 62 4e 61 6d 65 54 6f 42 74 72 lite3DbNameToBtr
26020 65 65 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 ee(sqlite3*,cons
26030 74 20 63 68 61 72 2a 29 3b 0a 0a 23 69 66 64 65 t char*);..#ifde
26040 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 53 54 41 f SQLITE_UNTESTA
26050 42 4c 45 0a 23 20 64 65 66 69 6e 65 20 73 71 6c BLE.# define sql
26060 69 74 65 33 46 61 75 6c 74 53 69 6d 28 58 29 20 ite3FaultSim(X)
26070 53 51 4c 49 54 45 5f 4f 4b 0a 23 65 6c 73 65 0a SQLITE_OK.#else.
26080 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 61 75 int sqlite3Fau
26090 6c 74 53 69 6d 28 69 6e 74 29 3b 0a 23 65 6e 64 ltSim(int);.#end
260a0 69 66 0a 0a 42 69 74 76 65 63 20 2a 73 71 6c 69 if..Bitvec *sqli
260b0 74 65 33 42 69 74 76 65 63 43 72 65 61 74 65 28 te3BitvecCreate(
260c0 75 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u32);.int sqlite
260d0 33 42 69 74 76 65 63 54 65 73 74 28 42 69 74 76 3BitvecTest(Bitv
260e0 65 63 2a 2c 20 75 33 32 29 3b 0a 69 6e 74 20 73 ec*, u32);.int s
260f0 71 6c 69 74 65 33 42 69 74 76 65 63 54 65 73 74 qlite3BitvecTest
26100 4e 6f 74 4e 75 6c 6c 28 42 69 74 76 65 63 2a 2c NotNull(Bitvec*,
26110 20 75 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 u32);.int sqlit
26120 65 33 42 69 74 76 65 63 53 65 74 28 42 69 74 76 e3BitvecSet(Bitv
26130 65 63 2a 2c 20 75 33 32 29 3b 0a 76 6f 69 64 20 ec*, u32);.void
26140 73 71 6c 69 74 65 33 42 69 74 76 65 63 43 6c 65 sqlite3BitvecCle
26150 61 72 28 42 69 74 76 65 63 2a 2c 20 75 33 32 2c ar(Bitvec*, u32,
26160 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 73 71 void*);.void sq
26170 6c 69 74 65 33 42 69 74 76 65 63 44 65 73 74 72 lite3BitvecDestr
26180 6f 79 28 42 69 74 76 65 63 2a 29 3b 0a 75 33 32 oy(Bitvec*);.u32
26190 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 53 69 sqlite3BitvecSi
261a0 7a 65 28 42 69 74 76 65 63 2a 29 3b 0a 23 69 66 ze(Bitvec*);.#if
261b0 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 45 ndef SQLITE_UNTE
261c0 53 54 41 42 4c 45 0a 69 6e 74 20 73 71 6c 69 74 STABLE.int sqlit
261d0 65 33 42 69 74 76 65 63 42 75 69 6c 74 69 6e 54 e3BitvecBuiltinT
261e0 65 73 74 28 69 6e 74 2c 69 6e 74 2a 29 3b 0a 23 est(int,int*);.#
261f0 65 6e 64 69 66 0a 0a 52 6f 77 53 65 74 20 2a 73 endif..RowSet *s
26200 71 6c 69 74 65 33 52 6f 77 53 65 74 49 6e 69 74 qlite3RowSetInit
26210 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a (sqlite3*, void*
26220 2c 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 3b , unsigned int);
26230 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 6f 77 .void sqlite3Row
26240 53 65 74 43 6c 65 61 72 28 52 6f 77 53 65 74 2a SetClear(RowSet*
26250 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
26260 6f 77 53 65 74 49 6e 73 65 72 74 28 52 6f 77 53 owSetInsert(RowS
26270 65 74 2a 2c 20 69 36 34 29 3b 0a 69 6e 74 20 73 et*, i64);.int s
26280 71 6c 69 74 65 33 52 6f 77 53 65 74 54 65 73 74 qlite3RowSetTest
26290 28 52 6f 77 53 65 74 2a 2c 20 69 6e 74 20 69 42 (RowSet*, int iB
262a0 61 74 63 68 2c 20 69 36 34 29 3b 0a 69 6e 74 20 atch, i64);.int
262b0 73 71 6c 69 74 65 33 52 6f 77 53 65 74 4e 65 78 sqlite3RowSetNex
262c0 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 34 2a 29 t(RowSet*, i64*)
262d0 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 ;..void sqlite3C
262e0 72 65 61 74 65 56 69 65 77 28 50 61 72 73 65 2a reateView(Parse*
262f0 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 54 ,Token*,Token*,T
26300 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
26310 53 65 6c 65 63 74 2a 2c 69 6e 74 2c 69 6e 74 29 Select*,int,int)
26320 3b 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 ;..#if !defined(
26330 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 57 SQLITE_OMIT_VIEW
26340 29 20 7c 7c 20 21 64 65 66 69 6e 65 64 28 53 51 ) || !defined(SQ
26350 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 LITE_OMIT_VIRTUA
26360 4c 54 41 42 4c 45 29 0a 20 20 69 6e 74 20 73 71 LTABLE). int sq
26370 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f 6c 75 lite3ViewGetColu
26380 6d 6e 4e 61 6d 65 73 28 50 61 72 73 65 2a 2c 54 mnNames(Parse*,T
26390 61 62 6c 65 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 able*);.#else.#
263a0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 69 define sqlite3Vi
263b0 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 ewGetColumnNames
263c0 28 41 2c 42 29 20 30 0a 23 65 6e 64 69 66 0a 0a (A,B) 0.#endif..
263d0 23 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 41 #if SQLITE_MAX_A
263e0 54 54 41 43 48 45 44 3e 33 30 0a 20 20 69 6e 74 TTACHED>30. int
263f0 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b 41 6c sqlite3DbMaskAl
26400 6c 5a 65 72 6f 28 79 44 62 4d 61 73 6b 29 3b 0a lZero(yDbMask);.
26410 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
26420 74 65 33 44 72 6f 70 54 61 62 6c 65 28 50 61 72 te3DropTable(Par
26430 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 se*, SrcList*, i
26440 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
26450 71 6c 69 74 65 33 43 6f 64 65 44 72 6f 70 54 61 qlite3CodeDropTa
26460 62 6c 65 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ble(Parse*, Tabl
26470 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 e*, int, int);.v
26480 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 oid sqlite3Delet
26490 65 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c eTable(sqlite3*,
264a0 20 54 61 62 6c 65 2a 29 3b 0a 23 69 66 6e 64 65 Table*);.#ifnde
264b0 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
264c0 54 4f 49 4e 43 52 45 4d 45 4e 54 0a 20 20 76 6f TOINCREMENT. vo
264d0 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e id sqlite3Autoin
264e0 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 50 61 72 crementBegin(Par
264f0 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 20 20 76 se *pParse);. v
26500 6f 69 64 20 73 71 6c 69 74 65 33 41 75 74 6f 69 oid sqlite3Autoi
26510 6e 63 72 65 6d 65 6e 74 45 6e 64 28 50 61 72 73 ncrementEnd(Pars
26520 65 20 2a 70 50 61 72 73 65 29 3b 0a 23 65 6c 73 e *pParse);.#els
26530 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
26540 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 42 e3AutoincrementB
26550 65 67 69 6e 28 58 29 0a 23 20 64 65 66 69 6e 65 egin(X).# define
26560 20 73 71 6c 69 74 65 33 41 75 74 6f 69 6e 63 72 sqlite3Autoincr
26570 65 6d 65 6e 74 45 6e 64 28 58 29 0a 23 65 6e 64 ementEnd(X).#end
26580 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 if.void sqlite3I
26590 6e 73 65 72 74 28 50 61 72 73 65 2a 2c 20 53 72 nsert(Parse*, Sr
265a0 63 4c 69 73 74 2a 2c 20 53 65 6c 65 63 74 2a 2c cList*, Select*,
265b0 20 49 64 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a IdList*, int);.
265c0 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 41 72 72 void *sqlite3Arr
265d0 61 79 41 6c 6c 6f 63 61 74 65 28 73 71 6c 69 74 ayAllocate(sqlit
265e0 65 33 2a 2c 76 6f 69 64 2a 2c 69 6e 74 2c 69 6e e3*,void*,int,in
265f0 74 2a 2c 69 6e 74 2a 29 3b 0a 49 64 4c 69 73 74 t*,int*);.IdList
26600 20 2a 73 71 6c 69 74 65 33 49 64 4c 69 73 74 41 *sqlite3IdListA
26610 70 70 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 ppend(sqlite3*,
26620 49 64 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 IdList*, Token*)
26630 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 64 4c ;.int sqlite3IdL
26640 69 73 74 49 6e 64 65 78 28 49 64 4c 69 73 74 2a istIndex(IdList*
26650 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 53 ,const char*);.S
26660 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 rcList *sqlite3S
26670 72 63 4c 69 73 74 45 6e 6c 61 72 67 65 28 73 71 rcListEnlarge(sq
26680 6c 69 74 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a lite3*, SrcList*
26690 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 53 72 63 , int, int);.Src
266a0 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 72 63 List *sqlite3Src
266b0 4c 69 73 74 41 70 70 65 6e 64 28 73 71 6c 69 74 ListAppend(sqlit
266c0 65 33 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 54 e3*, SrcList*, T
266d0 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a oken*, Token*);.
266e0 53 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 SrcList *sqlite3
266f0 53 72 63 4c 69 73 74 41 70 70 65 6e 64 46 72 6f SrcListAppendFro
26700 6d 54 65 72 6d 28 50 61 72 73 65 2a 2c 20 53 72 mTerm(Parse*, Sr
26710 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 cList*, Token*,
26720 54 6f 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 Token*,.
26730 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26740 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 6f To
26750 6b 65 6e 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 45 ken*, Select*, E
26760 78 70 72 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a xpr*, IdList*);.
26770 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c void sqlite3SrcL
26780 69 73 74 49 6e 64 65 78 65 64 42 79 28 50 61 72 istIndexedBy(Par
26790 73 65 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c se *, SrcList *,
267a0 20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 Token *);.void
267b0 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 46 75 sqlite3SrcListFu
267c0 6e 63 41 72 67 73 28 50 61 72 73 65 2a 2c 20 53 ncArgs(Parse*, S
267d0 72 63 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 73 rcList*, ExprLis
267e0 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
267f0 49 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 28 IndexedByLookup(
26800 50 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 20 Parse *, struct
26810 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 3b SrcList_item *);
26820 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 .void sqlite3Src
26830 4c 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 70 ListShiftJoinTyp
26840 65 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 e(SrcList*);.voi
26850 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 d sqlite3SrcList
26860 41 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 61 AssignCursors(Pa
26870 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b rse*, SrcList*);
26880 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 4c .void sqlite3IdL
26890 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 istDelete(sqlite
268a0 33 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 3*, IdList*);.vo
268b0 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 id sqlite3SrcLis
268c0 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a tDelete(sqlite3*
268d0 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e 64 , SrcList*);.Ind
268e0 65 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f 63 ex *sqlite3Alloc
268f0 61 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 73 ateIndexObject(s
26900 71 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 2c qlite3*,i16,int,
26910 63 68 61 72 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 char**);.void sq
26920 6c 69 74 65 33 43 72 65 61 74 65 49 6e 64 65 78 lite3CreateIndex
26930 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 (Parse*,Token*,T
26940 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 2a 2c 45 oken*,SrcList*,E
26950 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 54 6f 6b xprList*,int,Tok
26960 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 en*,.
26970 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 45 E
26980 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 xpr*, int, int,
26990 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 u8);.void sqlite
269a0 33 44 72 6f 70 49 6e 64 65 78 28 50 61 72 73 65 3DropIndex(Parse
269b0 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 *, SrcList*, int
269c0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 65 );.int sqlite3Se
269d0 6c 65 63 74 28 50 61 72 73 65 2a 2c 20 53 65 6c lect(Parse*, Sel
269e0 65 63 74 2a 2c 20 53 65 6c 65 63 74 44 65 73 74 ect*, SelectDest
269f0 2a 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 *);.Select *sqli
26a00 74 65 33 53 65 6c 65 63 74 4e 65 77 28 50 61 72 te3SelectNew(Par
26a10 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 53 72 se*,ExprList*,Sr
26a20 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 cList*,Expr*,Exp
26a30 72 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 rList*,.
26a40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
26a50 20 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a Expr*,ExprList*
26a60 2c 75 33 32 2c 45 78 70 72 2a 2c 45 78 70 72 2a ,u32,Expr*,Expr*
26a70 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
26a80 65 6c 65 63 74 44 65 6c 65 74 65 28 73 71 6c 69 electDelete(sqli
26a90 74 65 33 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a te3*, Select*);.
26aa0 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 53 72 Table *sqlite3Sr
26ab0 63 4c 69 73 74 4c 6f 6f 6b 75 70 28 50 61 72 73 cListLookup(Pars
26ac0 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 e*, SrcList*);.i
26ad0 6e 74 20 73 71 6c 69 74 65 33 49 73 52 65 61 64 nt sqlite3IsRead
26ae0 4f 6e 6c 79 28 50 61 72 73 65 2a 2c 20 54 61 62 Only(Parse*, Tab
26af0 6c 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 le*, int);.void
26b00 73 71 6c 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 sqlite3OpenTable
26b10 28 50 61 72 73 65 2a 2c 20 69 6e 74 20 69 43 75 (Parse*, int iCu
26b20 72 2c 20 69 6e 74 20 69 44 62 2c 20 54 61 62 6c r, int iDb, Tabl
26b30 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 66 20 64 65 e*, int);.#if de
26b40 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 fined(SQLITE_ENA
26b50 42 4c 45 5f 55 50 44 41 54 45 5f 44 45 4c 45 54 BLE_UPDATE_DELET
26b60 45 5f 4c 49 4d 49 54 29 20 26 26 20 21 64 65 66 E_LIMIT) && !def
26b70 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 ined(SQLITE_OMIT
26b80 5f 53 55 42 51 55 45 52 59 29 0a 45 78 70 72 20 _SUBQUERY).Expr
26b90 2a 73 71 6c 69 74 65 33 4c 69 6d 69 74 57 68 65 *sqlite3LimitWhe
26ba0 72 65 28 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 re(Parse*,SrcLis
26bb0 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 t*,Expr*,ExprLis
26bc0 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 2a 2c 63 t*,Expr*,Expr*,c
26bd0 68 61 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f har*);.#endif.vo
26be0 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 id sqlite3Delete
26bf0 46 72 6f 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 From(Parse*, Src
26c00 4c 69 73 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 List*, Expr*);.v
26c10 6f 69 64 20 73 71 6c 69 74 65 33 55 70 64 61 74 oid sqlite3Updat
26c20 65 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 e(Parse*, SrcLis
26c30 74 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 t*, ExprList*, E
26c40 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 57 68 65 72 xpr*, int);.Wher
26c50 65 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 57 68 eInfo *sqlite3Wh
26c60 65 72 65 42 65 67 69 6e 28 50 61 72 73 65 2a 2c ereBegin(Parse*,
26c70 53 72 63 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 SrcList*,Expr*,E
26c80 78 70 72 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 xprList*,ExprLis
26c90 74 2a 2c 75 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 t*,u16,int);.voi
26ca0 64 20 73 71 6c 69 74 65 33 57 68 65 72 65 45 6e d sqlite3WhereEn
26cb0 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 4c d(WhereInfo*);.L
26cc0 6f 67 45 73 74 20 73 71 6c 69 74 65 33 57 68 65 ogEst sqlite3Whe
26cd0 72 65 4f 75 74 70 75 74 52 6f 77 43 6f 75 6e 74 reOutputRowCount
26ce0 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e (WhereInfo*);.in
26cf0 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 49 73 t sqlite3WhereIs
26d00 44 69 73 74 69 6e 63 74 28 57 68 65 72 65 49 6e Distinct(WhereIn
26d10 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 fo*);.int sqlite
26d20 33 57 68 65 72 65 49 73 4f 72 64 65 72 65 64 28 3WhereIsOrdered(
26d30 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 WhereInfo*);.int
26d40 20 73 71 6c 69 74 65 33 57 68 65 72 65 4f 72 64 sqlite3WhereOrd
26d50 65 72 65 64 49 6e 6e 65 72 4c 6f 6f 70 28 57 68 eredInnerLoop(Wh
26d60 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 ereInfo*);.int s
26d70 71 6c 69 74 65 33 57 68 65 72 65 49 73 53 6f 72 qlite3WhereIsSor
26d80 74 65 64 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b ted(WhereInfo*);
26d90 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 .int sqlite3Wher
26da0 65 43 6f 6e 74 69 6e 75 65 4c 61 62 65 6c 28 57 eContinueLabel(W
26db0 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 hereInfo*);.int
26dc0 73 71 6c 69 74 65 33 57 68 65 72 65 42 72 65 61 sqlite3WhereBrea
26dd0 6b 4c 61 62 65 6c 28 57 68 65 72 65 49 6e 66 6f kLabel(WhereInfo
26de0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 *);.int sqlite3W
26df0 68 65 72 65 4f 6b 4f 6e 65 50 61 73 73 28 57 68 hereOkOnePass(Wh
26e00 65 72 65 49 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b ereInfo*, int*);
26e10 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 53 .#define ONEPASS
26e20 5f 4f 46 46 20 20 20 20 20 20 30 20 20 20 20 20 _OFF 0
26e30 20 20 20 2f 2a 20 55 73 65 20 6f 66 20 4f 4e 45 /* Use of ONE
26e40 50 41 53 53 20 6e 6f 74 20 61 6c 6c 6f 77 65 64 PASS not allowed
26e50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 */.#define ONEP
26e60 41 53 53 5f 53 49 4e 47 4c 45 20 20 20 31 20 20 ASS_SINGLE 1
26e70 20 20 20 20 20 20 2f 2a 20 4f 4e 45 50 41 53 53 /* ONEPASS
26e80 20 76 61 6c 69 64 20 66 6f 72 20 61 20 73 69 6e valid for a sin
26e90 67 6c 65 20 72 6f 77 20 75 70 64 61 74 65 20 2a gle row update *
26ea0 2f 0a 23 64 65 66 69 6e 65 20 4f 4e 45 50 41 53 /.#define ONEPAS
26eb0 53 5f 4d 55 4c 54 49 20 20 20 20 32 20 20 20 20 S_MULTI 2
26ec0 20 20 20 20 2f 2a 20 4f 4e 45 50 41 53 53 20 69 /* ONEPASS i
26ed0 73 20 76 61 6c 69 64 20 66 6f 72 20 6d 75 6c 74 s valid for mult
26ee0 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 76 6f 69 iple rows */.voi
26ef0 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 d sqlite3ExprCod
26f00 65 4c 6f 61 64 49 6e 64 65 78 43 6f 6c 75 6d 6e eLoadIndexColumn
26f10 28 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 2a 2c (Parse*, Index*,
26f20 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b int, int, int);
26f30 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
26f40 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 28 50 61 CodeGetColumn(Pa
26f50 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e rse*, Table*, in
26f60 74 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 29 t, int, int, u8)
26f70 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
26f80 70 72 43 6f 64 65 47 65 74 43 6f 6c 75 6d 6e 54 prCodeGetColumnT
26f90 6f 52 65 67 28 50 61 72 73 65 2a 2c 20 54 61 62 oReg(Parse*, Tab
26fa0 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 le*, int, int, i
26fb0 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
26fc0 33 45 78 70 72 43 6f 64 65 47 65 74 43 6f 6c 75 3ExprCodeGetColu
26fd0 6d 6e 4f 66 54 61 62 6c 65 28 56 64 62 65 2a 2c mnOfTable(Vdbe*,
26fe0 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e Table*, int, in
26ff0 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
27000 6c 69 74 65 33 45 78 70 72 43 6f 64 65 4d 6f 76 lite3ExprCodeMov
27010 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 e(Parse*, int, i
27020 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
27030 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 53 qlite3ExprCacheS
27040 74 6f 72 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 tore(Parse*, int
27050 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 , int, int);.voi
27060 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 d sqlite3ExprCac
27070 68 65 50 75 73 68 28 50 61 72 73 65 2a 29 3b 0a hePush(Parse*);.
27080 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
27090 43 61 63 68 65 50 6f 70 28 50 61 72 73 65 2a 29 CachePop(Parse*)
270a0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
270b0 70 72 43 61 63 68 65 52 65 6d 6f 76 65 28 50 61 prCacheRemove(Pa
270c0 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b rse*, int, int);
270d0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
270e0 72 43 61 63 68 65 43 6c 65 61 72 28 50 61 72 73 rCacheClear(Pars
270f0 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
27100 33 45 78 70 72 43 61 63 68 65 41 66 66 69 6e 69 3ExprCacheAffini
27110 74 79 43 68 61 6e 67 65 28 50 61 72 73 65 2a 2c tyChange(Parse*,
27120 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
27130 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 sqlite3ExprCode
27140 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
27150 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
27160 65 33 45 78 70 72 43 6f 64 65 43 6f 70 79 28 50 e3ExprCodeCopy(P
27170 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
27180 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
27190 45 78 70 72 43 6f 64 65 46 61 63 74 6f 72 61 62 ExprCodeFactorab
271a0 6c 65 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a le(Parse*, Expr*
271b0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
271c0 69 74 65 33 45 78 70 72 43 6f 64 65 41 74 49 6e ite3ExprCodeAtIn
271d0 69 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a it(Parse*, Expr*
271e0 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e 74 20 , int, u8);.int
271f0 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 54 sqlite3ExprCodeT
27200 65 6d 70 28 50 61 72 73 65 2a 2c 20 45 78 70 72 emp(Parse*, Expr
27210 2a 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 *, int*);.int sq
27220 6c 69 74 65 33 45 78 70 72 43 6f 64 65 54 61 72 lite3ExprCodeTar
27230 67 65 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 get(Parse*, Expr
27240 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
27250 6c 69 74 65 33 45 78 70 72 43 6f 64 65 41 6e 64 lite3ExprCodeAnd
27260 43 61 63 68 65 28 50 61 72 73 65 2a 2c 20 45 78 Cache(Parse*, Ex
27270 70 72 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 pr*, int);.int s
27280 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 45 78 qlite3ExprCodeEx
27290 70 72 4c 69 73 74 28 50 61 72 73 65 2a 2c 20 45 prList(Parse*, E
272a0 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 xprList*, int, i
272b0 6e 74 2c 20 75 38 29 3b 0a 23 64 65 66 69 6e 65 nt, u8);.#define
272c0 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 44 55 50 SQLITE_ECEL_DUP
272d0 20 20 20 20 20 20 30 78 30 31 20 20 2f 2a 20 44 0x01 /* D
272e0 65 65 70 2c 20 6e 6f 74 20 73 68 61 6c 6c 6f 77 eep, not shallow
272f0 20 63 6f 70 69 65 73 20 2a 2f 0a 23 64 65 66 69 copies */.#defi
27300 6e 65 20 53 51 4c 49 54 45 5f 45 43 45 4c 5f 46 ne SQLITE_ECEL_F
27310 41 43 54 4f 52 20 20 20 30 78 30 32 20 20 2f 2a ACTOR 0x02 /*
27320 20 46 61 63 74 6f 72 20 6f 75 74 20 63 6f 6e 73 Factor out cons
27330 74 61 6e 74 20 74 65 72 6d 73 20 2a 2f 0a 23 64 tant terms */.#d
27340 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 43 45 efine SQLITE_ECE
27350 4c 5f 52 45 46 20 20 20 20 20 20 30 78 30 34 20 L_REF 0x04
27360 20 2f 2a 20 55 73 65 20 45 78 70 72 4c 69 73 74 /* Use ExprList
27370 2e 75 2e 78 2e 69 4f 72 64 65 72 42 79 43 6f 6c .u.x.iOrderByCol
27380 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
27390 54 45 5f 45 43 45 4c 5f 4f 4d 49 54 52 45 46 20 TE_ECEL_OMITREF
273a0 20 30 78 30 38 20 20 2f 2a 20 4f 6d 69 74 20 69 0x08 /* Omit i
273b0 66 20 45 78 70 72 4c 69 73 74 2e 75 2e 78 2e 69 f ExprList.u.x.i
273c0 4f 72 64 65 72 42 79 43 6f 6c 20 2a 2f 0a 76 6f OrderByCol */.vo
273d0 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 66 id sqlite3ExprIf
273e0 54 72 75 65 28 50 61 72 73 65 2a 2c 20 45 78 70 True(Parse*, Exp
273f0 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 r*, int, int);.v
27400 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 49 oid sqlite3ExprI
27410 66 46 61 6c 73 65 28 50 61 72 73 65 2a 2c 20 45 fFalse(Parse*, E
27420 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b xpr*, int, int);
27430 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
27440 72 49 66 46 61 6c 73 65 44 75 70 28 50 61 72 73 rIfFalseDup(Pars
27450 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 e*, Expr*, int,
27460 69 6e 74 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c int);.Table *sql
27470 69 74 65 33 46 69 6e 64 54 61 62 6c 65 28 73 71 ite3FindTable(sq
27480 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
27490 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
274a0 3b 0a 23 64 65 66 69 6e 65 20 4c 4f 43 41 54 45 ;.#define LOCATE
274b0 5f 56 49 45 57 20 20 20 20 30 78 30 31 0a 23 64 _VIEW 0x01.#d
274c0 65 66 69 6e 65 20 4c 4f 43 41 54 45 5f 4e 4f 45 efine LOCATE_NOE
274d0 52 52 20 20 20 30 78 30 32 0a 54 61 62 6c 65 20 RR 0x02.Table
274e0 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 *sqlite3LocateTa
274f0 62 6c 65 28 50 61 72 73 65 2a 2c 75 33 32 20 66 ble(Parse*,u32 f
27500 6c 61 67 73 2c 63 6f 6e 73 74 20 63 68 61 72 2a lags,const char*
27510 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
27520 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 4c 6f Table *sqlite3Lo
27530 63 61 74 65 54 61 62 6c 65 49 74 65 6d 28 50 61 cateTableItem(Pa
27540 72 73 65 2a 2c 75 33 32 20 66 6c 61 67 73 2c 73 rse*,u32 flags,s
27550 74 72 75 63 74 20 53 72 63 4c 69 73 74 5f 69 74 truct SrcList_it
27560 65 6d 20 2a 29 3b 0a 49 6e 64 65 78 20 2a 73 71 em *);.Index *sq
27570 6c 69 74 65 33 46 69 6e 64 49 6e 64 65 78 28 73 lite3FindIndex(s
27580 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
27590 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
275a0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 55 );.void sqlite3U
275b0 6e 6c 69 6e 6b 41 6e 64 44 65 6c 65 74 65 54 61 nlinkAndDeleteTa
275c0 62 6c 65 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 ble(sqlite3*,int
275d0 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 ,const char*);.v
275e0 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e oid sqlite3Unlin
275f0 6b 41 6e 64 44 65 6c 65 74 65 49 6e 64 65 78 28 kAndDeleteIndex(
27600 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e sqlite3*,int,con
27610 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 st char*);.void
27620 73 71 6c 69 74 65 33 56 61 63 75 75 6d 28 50 61 sqlite3Vacuum(Pa
27630 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 3b 0a 69 6e rse*,Token*);.in
27640 74 20 73 71 6c 69 74 65 33 52 75 6e 56 61 63 75 t sqlite3RunVacu
27650 75 6d 28 63 68 61 72 2a 2a 2c 20 73 71 6c 69 74 um(char**, sqlit
27660 65 33 2a 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 e3*, int);.char
27670 2a 73 71 6c 69 74 65 33 4e 61 6d 65 46 72 6f 6d *sqlite3NameFrom
27680 54 6f 6b 65 6e 28 73 71 6c 69 74 65 33 2a 2c 20 Token(sqlite3*,
27690 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
276a0 69 74 65 33 45 78 70 72 43 6f 6d 70 61 72 65 28 ite3ExprCompare(
276b0 45 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e Expr*, Expr*, in
276c0 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 t);.int sqlite3E
276d0 78 70 72 4c 69 73 74 43 6f 6d 70 61 72 65 28 45 xprListCompare(E
276e0 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 xprList*, ExprLi
276f0 73 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 st*, int);.int s
27700 71 6c 69 74 65 33 45 78 70 72 49 6d 70 6c 69 65 qlite3ExprImplie
27710 73 45 78 70 72 28 45 78 70 72 2a 2c 20 45 78 70 sExpr(Expr*, Exp
27720 72 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 r*, int);.void s
27730 71 6c 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a qlite3ExprAnalyz
27740 65 41 67 67 72 65 67 61 74 65 73 28 4e 61 6d 65 eAggregates(Name
27750 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a 29 Context*, Expr*)
27760 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
27770 70 72 41 6e 61 6c 79 7a 65 41 67 67 4c 69 73 74 prAnalyzeAggList
27780 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 45 78 (NameContext*,Ex
27790 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 prList*);.int sq
277a0 6c 69 74 65 33 45 78 70 72 43 6f 76 65 72 65 64 lite3ExprCovered
277b0 42 79 49 6e 64 65 78 28 45 78 70 72 2a 2c 20 69 ByIndex(Expr*, i
277c0 6e 74 20 69 43 75 72 2c 20 49 6e 64 65 78 20 2a nt iCur, Index *
277d0 70 49 64 78 29 3b 0a 69 6e 74 20 73 71 6c 69 74 pIdx);.int sqlit
277e0 65 33 46 75 6e 63 74 69 6f 6e 55 73 65 73 54 68 e3FunctionUsesTh
277f0 69 73 53 72 63 28 45 78 70 72 2a 2c 20 53 72 63 isSrc(Expr*, Src
27800 4c 69 73 74 2a 29 3b 0a 56 64 62 65 20 2a 73 71 List*);.Vdbe *sq
27810 6c 69 74 65 33 47 65 74 56 64 62 65 28 50 61 72 lite3GetVdbe(Par
27820 73 65 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 se*);.#ifndef SQ
27830 4c 49 54 45 5f 55 4e 54 45 53 54 41 42 4c 45 0a LITE_UNTESTABLE.
27840 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e 67 void sqlite3Prng
27850 53 61 76 65 53 74 61 74 65 28 76 6f 69 64 29 3b SaveState(void);
27860 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 72 6e .void sqlite3Prn
27870 67 52 65 73 74 6f 72 65 53 74 61 74 65 28 76 6f gRestoreState(vo
27880 69 64 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 id);.#endif.void
27890 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
278a0 41 6c 6c 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 All(sqlite3*,int
278b0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
278c0 6f 64 65 56 65 72 69 66 79 53 63 68 65 6d 61 28 odeVerifySchema(
278d0 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f Parse*, int);.vo
278e0 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 65 id sqlite3CodeVe
278f0 72 69 66 79 4e 61 6d 65 64 53 63 68 65 6d 61 28 rifyNamedSchema(
27900 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 Parse*, const ch
27910 61 72 20 2a 7a 44 62 29 3b 0a 76 6f 69 64 20 73 ar *zDb);.void s
27920 71 6c 69 74 65 33 42 65 67 69 6e 54 72 61 6e 73 qlite3BeginTrans
27930 61 63 74 69 6f 6e 28 50 61 72 73 65 2a 2c 20 69 action(Parse*, i
27940 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27950 33 43 6f 6d 6d 69 74 54 72 61 6e 73 61 63 74 69 3CommitTransacti
27960 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 on(Parse*);.void
27970 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 6b sqlite3Rollback
27980 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 73 Transaction(Pars
27990 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
279a0 33 53 61 76 65 70 6f 69 6e 74 28 50 61 72 73 65 3Savepoint(Parse
279b0 2a 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a 29 3b *, int, Token*);
279c0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c 6f .void sqlite3Clo
279d0 73 65 53 61 76 65 70 6f 69 6e 74 73 28 73 71 6c seSavepoints(sql
279e0 69 74 65 33 20 2a 29 3b 0a 76 6f 69 64 20 73 71 ite3 *);.void sq
279f0 6c 69 74 65 33 4c 65 61 76 65 4d 75 74 65 78 41 lite3LeaveMutexA
27a00 6e 64 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 73 71 ndCloseZombie(sq
27a10 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c lite3*);.int sql
27a20 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 61 ite3ExprIsConsta
27a30 6e 74 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 73 nt(Expr*);.int s
27a40 71 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 qlite3ExprIsCons
27a50 74 61 6e 74 4e 6f 74 4a 6f 69 6e 28 45 78 70 72 tantNotJoin(Expr
27a60 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 *);.int sqlite3E
27a70 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 46 xprIsConstantOrF
27a80 75 6e 63 74 69 6f 6e 28 45 78 70 72 2a 2c 20 75 unction(Expr*, u
27a90 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 8);.int sqlite3E
27aa0 78 70 72 49 73 54 61 62 6c 65 43 6f 6e 73 74 61 xprIsTableConsta
27ab0 6e 74 28 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 23 nt(Expr*,int);.#
27ac0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 ifdef SQLITE_ENA
27ad0 42 4c 45 5f 43 55 52 53 4f 52 5f 48 49 4e 54 53 BLE_CURSOR_HINTS
27ae0 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
27af0 43 6f 6e 74 61 69 6e 73 53 75 62 71 75 65 72 79 ContainsSubquery
27b00 28 45 78 70 72 2a 29 3b 0a 23 65 6e 64 69 66 0a (Expr*);.#endif.
27b10 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 49 int sqlite3ExprI
27b20 73 49 6e 74 65 67 65 72 28 45 78 70 72 2a 2c 20 sInteger(Expr*,
27b30 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int*);.int sqlit
27b40 65 33 45 78 70 72 43 61 6e 42 65 4e 75 6c 6c 28 e3ExprCanBeNull(
27b50 63 6f 6e 73 74 20 45 78 70 72 2a 29 3b 0a 69 6e const Expr*);.in
27b60 74 20 73 71 6c 69 74 65 33 45 78 70 72 4e 65 65 t sqlite3ExprNee
27b70 64 73 4e 6f 41 66 66 69 6e 69 74 79 43 68 61 6e dsNoAffinityChan
27b80 67 65 28 63 6f 6e 73 74 20 45 78 70 72 2a 2c 20 ge(const Expr*,
27b90 63 68 61 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 char);.int sqlit
27ba0 65 33 49 73 52 6f 77 69 64 28 63 6f 6e 73 74 20 e3IsRowid(const
27bb0 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c char*);.void sql
27bc0 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 44 ite3GenerateRowD
27bd0 65 6c 65 74 65 28 0a 20 20 20 20 50 61 72 73 65 elete(. Parse
27be0 2a 2c 54 61 62 6c 65 2a 2c 54 72 69 67 67 65 72 *,Table*,Trigger
27bf0 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 31 *,int,int,int,i1
27c00 36 2c 75 38 2c 75 38 2c 75 38 2c 69 6e 74 29 3b 6,u8,u8,u8,int);
27c10 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 47 65 6e .void sqlite3Gen
27c20 65 72 61 74 65 52 6f 77 49 6e 64 65 78 44 65 6c erateRowIndexDel
27c30 65 74 65 28 50 61 72 73 65 2a 2c 20 54 61 62 6c ete(Parse*, Tabl
27c40 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e e*, int, int, in
27c50 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 t*, int);.int sq
27c60 6c 69 74 65 33 47 65 6e 65 72 61 74 65 49 6e 64 lite3GenerateInd
27c70 65 78 4b 65 79 28 50 61 72 73 65 2a 2c 20 49 6e exKey(Parse*, In
27c80 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 dex*, int, int,
27c90 69 6e 74 2c 20 69 6e 74 2a 2c 49 6e 64 65 78 2a int, int*,Index*
27ca0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
27cb0 74 65 33 52 65 73 6f 6c 76 65 50 61 72 74 49 64 te3ResolvePartId
27cc0 78 4c 61 62 65 6c 28 50 61 72 73 65 2a 2c 69 6e xLabel(Parse*,in
27cd0 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
27ce0 47 65 6e 65 72 61 74 65 43 6f 6e 73 74 72 61 69 GenerateConstrai
27cf0 6e 74 43 68 65 63 6b 73 28 50 61 72 73 65 2a 2c ntChecks(Parse*,
27d00 54 61 62 6c 65 2a 2c 69 6e 74 2a 2c 69 6e 74 2c Table*,int*,int,
27d10 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 0a 20 20 20 int,int,int,.
27d20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
27d30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
27d40 20 20 75 38 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a u8,u8,int,int*
27d50 2c 69 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ,int*);.void sql
27d60 69 74 65 33 43 6f 6d 70 6c 65 74 65 49 6e 73 65 ite3CompleteInse
27d70 72 74 69 6f 6e 28 50 61 72 73 65 2a 2c 54 61 62 rtion(Parse*,Tab
27d80 6c 65 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c le*,int,int,int,
27d90 69 6e 74 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 int*,int,int,int
27da0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4f 70 );.int sqlite3Op
27db0 65 6e 54 61 62 6c 65 41 6e 64 49 6e 64 69 63 65 enTableAndIndice
27dc0 73 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a s(Parse*, Table*
27dd0 2c 20 69 6e 74 2c 20 75 38 2c 20 69 6e 74 2c 20 , int, u8, int,
27de0 75 38 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 u8*, int*, int*)
27df0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 ;.void sqlite3Be
27e00 67 69 6e 57 72 69 74 65 4f 70 65 72 61 74 69 6f ginWriteOperatio
27e10 6e 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 n(Parse*, int, i
27e20 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
27e30 33 4d 75 6c 74 69 57 72 69 74 65 28 50 61 72 73 3MultiWrite(Pars
27e40 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 e*);.void sqlite
27e50 33 4d 61 79 41 62 6f 72 74 28 50 61 72 73 65 2a 3MayAbort(Parse*
27e60 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 48 );.void sqlite3H
27e70 61 6c 74 43 6f 6e 73 74 72 61 69 6e 74 28 50 61 altConstraint(Pa
27e80 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 rse*, int, int,
27e90 63 68 61 72 2a 2c 20 69 38 2c 20 75 38 29 3b 0a char*, i8, u8);.
27ea0 76 6f 69 64 20 73 71 6c 69 74 65 33 55 6e 69 71 void sqlite3Uniq
27eb0 75 65 43 6f 6e 73 74 72 61 69 6e 74 28 50 61 72 ueConstraint(Par
27ec0 73 65 2a 2c 20 69 6e 74 2c 20 49 6e 64 65 78 2a se*, int, Index*
27ed0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
27ee0 6f 77 69 64 43 6f 6e 73 74 72 61 69 6e 74 28 50 owidConstraint(P
27ef0 61 72 73 65 2a 2c 20 69 6e 74 2c 20 54 61 62 6c arse*, int, Tabl
27f00 65 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 e*);.Expr *sqlit
27f10 65 33 45 78 70 72 44 75 70 28 73 71 6c 69 74 65 e3ExprDup(sqlite
27f20 33 2a 2c 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 45 3*,Expr*,int);.E
27f30 78 70 72 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 xprList *sqlite3
27f40 45 78 70 72 4c 69 73 74 44 75 70 28 73 71 6c 69 ExprListDup(sqli
27f50 74 65 33 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 te3*,ExprList*,i
27f60 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 2a 73 71 nt);.SrcList *sq
27f70 6c 69 74 65 33 53 72 63 4c 69 73 74 44 75 70 28 lite3SrcListDup(
27f80 73 71 6c 69 74 65 33 2a 2c 53 72 63 4c 69 73 74 sqlite3*,SrcList
27f90 2a 2c 69 6e 74 29 3b 0a 49 64 4c 69 73 74 20 2a *,int);.IdList *
27fa0 73 71 6c 69 74 65 33 49 64 4c 69 73 74 44 75 70 sqlite3IdListDup
27fb0 28 73 71 6c 69 74 65 33 2a 2c 49 64 4c 69 73 74 (sqlite3*,IdList
27fc0 2a 29 3b 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 *);.Select *sqli
27fd0 74 65 33 53 65 6c 65 63 74 44 75 70 28 73 71 6c te3SelectDup(sql
27fe0 69 74 65 33 2a 2c 53 65 6c 65 63 74 2a 2c 69 6e ite3*,Select*,in
27ff0 74 29 3b 0a 23 69 66 20 53 45 4c 45 43 54 54 52 t);.#if SELECTTR
28000 41 43 45 5f 45 4e 41 42 4c 45 44 0a 76 6f 69 64 ACE_ENABLED.void
28010 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 53 65 sqlite3SelectSe
28020 74 4e 61 6d 65 28 53 65 6c 65 63 74 2a 2c 63 6f tName(Select*,co
28030 6e 73 74 20 63 68 61 72 2a 29 3b 0a 23 65 6c 73 nst char*);.#els
28040 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 e.# define sqlit
28050 65 33 53 65 6c 65 63 74 53 65 74 4e 61 6d 65 28 e3SelectSetName(
28060 41 2c 42 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 A,B).#endif.void
28070 20 73 71 6c 69 74 65 33 49 6e 73 65 72 74 42 75 sqlite3InsertBu
28080 69 6c 74 69 6e 46 75 6e 63 73 28 46 75 6e 63 44 iltinFuncs(FuncD
28090 65 66 2a 2c 69 6e 74 29 3b 0a 46 75 6e 63 44 65 ef*,int);.FuncDe
280a0 66 20 2a 73 71 6c 69 74 65 33 46 69 6e 64 46 75 f *sqlite3FindFu
280b0 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c nction(sqlite3*,
280c0 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 2c const char*,int,
280d0 75 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c u8,u8);.void sql
280e0 69 74 65 33 52 65 67 69 73 74 65 72 42 75 69 6c ite3RegisterBuil
280f0 74 69 6e 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 tinFunctions(voi
28100 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 d);.void sqlite3
28110 52 65 67 69 73 74 65 72 44 61 74 65 54 69 6d 65 RegisterDateTime
28120 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b Functions(void);
28130 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 .void sqlite3Reg
28140 69 73 74 65 72 50 65 72 43 6f 6e 6e 65 63 74 69 isterPerConnecti
28150 6f 6e 42 75 69 6c 74 69 6e 46 75 6e 63 74 69 6f onBuiltinFunctio
28160 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e ns(sqlite3*);.in
28170 74 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 43 t sqlite3SafetyC
28180 68 65 63 6b 4f 6b 28 73 71 6c 69 74 65 33 2a 29 heckOk(sqlite3*)
28190 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 61 66 ;.int sqlite3Saf
281a0 65 74 79 43 68 65 63 6b 53 69 63 6b 4f 72 4f 6b etyCheckSickOrOk
281b0 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
281c0 20 73 71 6c 69 74 65 33 43 68 61 6e 67 65 43 6f sqlite3ChangeCo
281d0 6f 6b 69 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 okie(Parse*, int
281e0 29 3b 0a 0a 23 69 66 20 21 64 65 66 69 6e 65 64 );..#if !defined
281f0 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 (SQLITE_OMIT_VIE
28200 57 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 W) && !defined(S
28210 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 QLITE_OMIT_TRIGG
28220 45 52 29 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 ER).void sqlite3
28230 4d 61 74 65 72 69 61 6c 69 7a 65 56 69 65 77 28 MaterializeView(
28240 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 Parse*, Table*,
28250 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 23 65 6e Expr*, int);.#en
28260 64 69 66 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c dif..#ifndef SQL
28270 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 ITE_OMIT_TRIGGER
28280 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 42 . void sqlite3B
28290 65 67 69 6e 54 72 69 67 67 65 72 28 50 61 72 73 eginTrigger(Pars
282a0 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e e*, Token*,Token
282b0 2a 2c 69 6e 74 2c 69 6e 74 2c 49 64 4c 69 73 74 *,int,int,IdList
282c0 2a 2c 53 72 63 4c 69 73 74 2a 2c 0a 20 20 20 20 *,SrcList*,.
282d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
282e0 20 20 20 20 20 20 20 45 78 70 72 2a 2c 69 6e 74 Expr*,int
282f0 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 , int);. void s
28300 71 6c 69 74 65 33 46 69 6e 69 73 68 54 72 69 67 qlite3FinishTrig
28310 67 65 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 ger(Parse*, Trig
28320 67 65 72 53 74 65 70 2a 2c 20 54 6f 6b 65 6e 2a gerStep*, Token*
28330 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 );. void sqlite
28340 33 44 72 6f 70 54 72 69 67 67 65 72 28 50 61 72 3DropTrigger(Par
28350 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 se*, SrcList*, i
28360 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 nt);. void sqli
28370 74 65 33 44 72 6f 70 54 72 69 67 67 65 72 50 74 te3DropTriggerPt
28380 72 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 r(Parse*, Trigge
28390 72 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 20 2a r*);. Trigger *
283a0 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 73 45 sqlite3TriggersE
283b0 78 69 73 74 28 50 61 72 73 65 20 2a 2c 20 54 61 xist(Parse *, Ta
283c0 62 6c 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c ble*, int, ExprL
283d0 69 73 74 2a 2c 20 69 6e 74 20 2a 70 4d 61 73 6b ist*, int *pMask
283e0 29 3b 0a 20 20 54 72 69 67 67 65 72 20 2a 73 71 );. Trigger *sq
283f0 6c 69 74 65 33 54 72 69 67 67 65 72 4c 69 73 74 lite3TriggerList
28400 28 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 20 (Parse *, Table
28410 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
28420 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 72 e3CodeRowTrigger
28430 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 (Parse*, Trigger
28440 20 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 *, int, ExprLis
28450 74 2a 2c 20 69 6e 74 2c 20 54 61 62 6c 65 20 2a t*, int, Table *
28460 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,.
28470 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 6e in
28480 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 t, int, int);.
28490 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 void sqlite3Code
284a0 52 6f 77 54 72 69 67 67 65 72 44 69 72 65 63 74 RowTriggerDirect
284b0 28 50 61 72 73 65 20 2a 2c 20 54 72 69 67 67 65 (Parse *, Trigge
284c0 72 20 2a 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e r *, Table *, in
284d0 74 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 t, int, int);.
284e0 76 6f 69 64 20 73 71 6c 69 74 65 56 69 65 77 54 void sqliteViewT
284f0 72 69 67 67 65 72 73 28 50 61 72 73 65 2a 2c 20 riggers(Parse*,
28500 54 61 62 6c 65 2a 2c 20 45 78 70 72 2a 2c 20 69 Table*, Expr*, i
28510 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a nt, ExprList*);.
28520 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 void sqlite3De
28530 6c 65 74 65 54 72 69 67 67 65 72 53 74 65 70 28 leteTriggerStep(
28540 73 71 6c 69 74 65 33 2a 2c 20 54 72 69 67 67 65 sqlite3*, Trigge
28550 72 53 74 65 70 2a 29 3b 0a 20 20 54 72 69 67 67 rStep*);. Trigg
28560 65 72 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 erStep *sqlite3T
28570 72 69 67 67 65 72 53 65 6c 65 63 74 53 74 65 70 riggerSelectStep
28580 28 73 71 6c 69 74 65 33 2a 2c 53 65 6c 65 63 74 (sqlite3*,Select
28590 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 74 65 *);. TriggerSte
285a0 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 67 65 p *sqlite3Trigge
285b0 72 49 6e 73 65 72 74 53 74 65 70 28 73 71 6c 69 rInsertStep(sqli
285c0 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 49 64 4c te3*,Token*, IdL
285d0 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 ist*,.
285e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
285f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 53 65 Se
28600 6c 65 63 74 2a 2c 75 38 29 3b 0a 20 20 54 72 69 lect*,u8);. Tri
28610 67 67 65 72 53 74 65 70 20 2a 73 71 6c 69 74 65 ggerStep *sqlite
28620 33 54 72 69 67 67 65 72 55 70 64 61 74 65 53 74 3TriggerUpdateSt
28630 65 70 28 73 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 ep(sqlite3*,Toke
28640 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 n*,ExprList*, Ex
28650 70 72 2a 2c 20 75 38 29 3b 0a 20 20 54 72 69 67 pr*, u8);. Trig
28660 67 65 72 53 74 65 70 20 2a 73 71 6c 69 74 65 33 gerStep *sqlite3
28670 54 72 69 67 67 65 72 44 65 6c 65 74 65 53 74 65 TriggerDeleteSte
28680 70 28 73 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e p(sqlite3*,Token
28690 2a 2c 20 45 78 70 72 2a 29 3b 0a 20 20 76 6f 69 *, Expr*);. voi
286a0 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 54 d sqlite3DeleteT
286b0 72 69 67 67 65 72 28 73 71 6c 69 74 65 33 2a 2c rigger(sqlite3*,
286c0 20 54 72 69 67 67 65 72 2a 29 3b 0a 20 20 76 6f Trigger*);. vo
286d0 69 64 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b id sqlite3Unlink
286e0 41 6e 64 44 65 6c 65 74 65 54 72 69 67 67 65 72 AndDeleteTrigger
286f0 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f (sqlite3*,int,co
28700 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 75 33 nst char*);. u3
28710 32 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 2 sqlite3Trigger
28720 43 6f 6c 6d 61 73 6b 28 50 61 72 73 65 2a 2c 54 Colmask(Parse*,T
28730 72 69 67 67 65 72 2a 2c 45 78 70 72 4c 69 73 74 rigger*,ExprList
28740 2a 2c 69 6e 74 2c 69 6e 74 2c 54 61 62 6c 65 2a *,int,int,Table*
28750 2c 69 6e 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 ,int);.# define
28760 73 71 6c 69 74 65 33 50 61 72 73 65 54 6f 70 6c sqlite3ParseTopl
28770 65 76 65 6c 28 70 29 20 28 28 70 29 2d 3e 70 54 evel(p) ((p)->pT
28780 6f 70 6c 65 76 65 6c 20 3f 20 28 70 29 2d 3e 70 oplevel ? (p)->p
28790 54 6f 70 6c 65 76 65 6c 20 3a 20 28 70 29 29 0a Toplevel : (p)).
287a0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
287b0 49 73 54 6f 70 6c 65 76 65 6c 28 70 29 20 28 28 IsToplevel(p) ((
287c0 70 29 2d 3e 70 54 6f 70 6c 65 76 65 6c 3d 3d 30 p)->pToplevel==0
287d0 29 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 ).#else.# define
287e0 20 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 73 sqlite3Triggers
287f0 45 78 69 73 74 28 42 2c 43 2c 44 2c 45 2c 46 29 Exist(B,C,D,E,F)
28800 20 30 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 0.# define sqli
28810 74 65 33 44 65 6c 65 74 65 54 72 69 67 67 65 72 te3DeleteTrigger
28820 28 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 73 (A,B).# define s
28830 71 6c 69 74 65 33 44 72 6f 70 54 72 69 67 67 65 qlite3DropTrigge
28840 72 50 74 72 28 41 2c 42 29 0a 23 20 64 65 66 69 rPtr(A,B).# defi
28850 6e 65 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b ne sqlite3Unlink
28860 41 6e 64 44 65 6c 65 74 65 54 72 69 67 67 65 72 AndDeleteTrigger
28870 28 41 2c 42 2c 43 29 0a 23 20 64 65 66 69 6e 65 (A,B,C).# define
28880 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 sqlite3CodeRowT
28890 72 69 67 67 65 72 28 41 2c 42 2c 43 2c 44 2c 45 rigger(A,B,C,D,E
288a0 2c 46 2c 47 2c 48 2c 49 29 0a 23 20 64 65 66 69 ,F,G,H,I).# defi
288b0 6e 65 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f ne sqlite3CodeRo
288c0 77 54 72 69 67 67 65 72 44 69 72 65 63 74 28 41 wTriggerDirect(A
288d0 2c 42 2c 43 2c 44 2c 45 2c 46 29 0a 23 20 64 65 ,B,C,D,E,F).# de
288e0 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 69 67 fine sqlite3Trig
288f0 67 65 72 4c 69 73 74 28 58 2c 20 59 29 20 30 0a gerList(X, Y) 0.
28900 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
28910 50 61 72 73 65 54 6f 70 6c 65 76 65 6c 28 70 29 ParseToplevel(p)
28920 20 70 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 p.# define sqli
28930 74 65 33 49 73 54 6f 70 6c 65 76 65 6c 28 70 29 te3IsToplevel(p)
28940 20 31 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 1.# define sqli
28950 74 65 33 54 72 69 67 67 65 72 43 6f 6c 6d 61 73 te3TriggerColmas
28960 6b 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 29 k(A,B,C,D,E,F,G)
28970 20 30 0a 23 65 6e 64 69 66 0a 0a 69 6e 74 20 73 0.#endif..int s
28980 71 6c 69 74 65 33 4a 6f 69 6e 54 79 70 65 28 50 qlite3JoinType(P
28990 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
289a0 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a oken*, Token*);.
289b0 76 6f 69 64 20 73 71 6c 69 74 65 33 43 72 65 61 void sqlite3Crea
289c0 74 65 46 6f 72 65 69 67 6e 4b 65 79 28 50 61 72 teForeignKey(Par
289d0 73 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 se*, ExprList*,
289e0 54 6f 6b 65 6e 2a 2c 20 45 78 70 72 4c 69 73 74 Token*, ExprList
289f0 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
28a00 6c 69 74 65 33 44 65 66 65 72 46 6f 72 65 69 67 lite3DeferForeig
28a10 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 69 6e 74 nKey(Parse*, int
28a20 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
28a30 45 5f 4f 4d 49 54 5f 41 55 54 48 4f 52 49 5a 41 E_OMIT_AUTHORIZA
28a40 54 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c 69 TION. void sqli
28a50 74 65 33 41 75 74 68 52 65 61 64 28 50 61 72 73 te3AuthRead(Pars
28a60 65 2a 2c 45 78 70 72 2a 2c 53 63 68 65 6d 61 2a e*,Expr*,Schema*
28a70 2c 53 72 63 4c 69 73 74 2a 29 3b 0a 20 20 69 6e ,SrcList*);. in
28a80 74 20 73 71 6c 69 74 65 33 41 75 74 68 43 68 65 t sqlite3AuthChe
28a90 63 6b 28 50 61 72 73 65 2a 2c 69 6e 74 2c 20 63 ck(Parse*,int, c
28aa0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
28ab0 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 t char*, const c
28ac0 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 har*);. void sq
28ad0 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 65 78 74 lite3AuthContext
28ae0 50 75 73 68 28 50 61 72 73 65 2a 2c 20 41 75 74 Push(Parse*, Aut
28af0 68 43 6f 6e 74 65 78 74 2a 2c 20 63 6f 6e 73 74 hContext*, const
28b00 20 63 68 61 72 2a 29 3b 0a 20 20 76 6f 69 64 20 char*);. void
28b10 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e 74 65 sqlite3AuthConte
28b20 78 74 50 6f 70 28 41 75 74 68 43 6f 6e 74 65 78 xtPop(AuthContex
28b30 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 t*);. int sqlit
28b40 65 33 41 75 74 68 52 65 61 64 43 6f 6c 28 50 61 e3AuthReadCol(Pa
28b50 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 rse*, const char
28b60 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a *, const char *
28b70 2c 20 69 6e 74 29 3b 0a 23 65 6c 73 65 0a 23 20 , int);.#else.#
28b80 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 75 define sqlite3Au
28b90 74 68 52 65 61 64 28 61 2c 62 2c 63 2c 64 29 0a thRead(a,b,c,d).
28ba0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
28bb0 41 75 74 68 43 68 65 63 6b 28 61 2c 62 2c 63 2c AuthCheck(a,b,c,
28bc0 64 2c 65 29 20 20 20 20 53 51 4c 49 54 45 5f 4f d,e) SQLITE_O
28bd0 4b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 K.# define sqlit
28be0 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 75 73 e3AuthContextPus
28bf0 68 28 61 2c 62 2c 63 29 0a 23 20 64 65 66 69 6e h(a,b,c).# defin
28c00 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 6f 6e e sqlite3AuthCon
28c10 74 65 78 74 50 6f 70 28 61 29 20 20 28 28 76 6f textPop(a) ((vo
28c20 69 64 29 28 61 29 29 0a 23 65 6e 64 69 66 0a 76 id)(a)).#endif.v
28c30 6f 69 64 20 73 71 6c 69 74 65 33 41 74 74 61 63 oid sqlite3Attac
28c40 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c h(Parse*, Expr*,
28c50 20 45 78 70 72 2a 2c 20 45 78 70 72 2a 29 3b 0a Expr*, Expr*);.
28c60 76 6f 69 64 20 73 71 6c 69 74 65 33 44 65 74 61 void sqlite3Deta
28c70 63 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a ch(Parse*, Expr*
28c80 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 );.void sqlite3F
28c90 69 78 49 6e 69 74 28 44 62 46 69 78 65 72 2a 2c ixInit(DbFixer*,
28ca0 20 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 63 6f Parse*, int, co
28cb0 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 nst char*, const
28cc0 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 Token*);.int sq
28cd0 6c 69 74 65 33 46 69 78 53 72 63 4c 69 73 74 28 lite3FixSrcList(
28ce0 44 62 46 69 78 65 72 2a 2c 20 53 72 63 4c 69 73 DbFixer*, SrcLis
28cf0 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
28d00 46 69 78 53 65 6c 65 63 74 28 44 62 46 69 78 65 FixSelect(DbFixe
28d10 72 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 69 6e r*, Select*);.in
28d20 74 20 73 71 6c 69 74 65 33 46 69 78 45 78 70 72 t sqlite3FixExpr
28d30 28 44 62 46 69 78 65 72 2a 2c 20 45 78 70 72 2a (DbFixer*, Expr*
28d40 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 );.int sqlite3Fi
28d50 78 45 78 70 72 4c 69 73 74 28 44 62 46 69 78 65 xExprList(DbFixe
28d60 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a r*, ExprList*);.
28d70 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 54 72 int sqlite3FixTr
28d80 69 67 67 65 72 53 74 65 70 28 44 62 46 69 78 65 iggerStep(DbFixe
28d90 72 2a 2c 20 54 72 69 67 67 65 72 53 74 65 70 2a r*, TriggerStep*
28da0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 74 );.int sqlite3At
28db0 6f 46 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a oF(const char *z
28dc0 2c 20 64 6f 75 62 6c 65 2a 2c 20 69 6e 74 2c 20 , double*, int,
28dd0 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 u8);.int sqlite3
28de0 47 65 74 49 6e 74 33 32 28 63 6f 6e 73 74 20 63 GetInt32(const c
28df0 68 61 72 20 2a 2c 20 69 6e 74 2a 29 3b 0a 69 6e har *, int*);.in
28e00 74 20 73 71 6c 69 74 65 33 41 74 6f 69 28 63 6f t sqlite3Atoi(co
28e10 6e 73 74 20 63 68 61 72 2a 29 3b 0a 69 6e 74 20 nst char*);.int
28e20 73 71 6c 69 74 65 33 55 74 66 31 36 42 79 74 65 sqlite3Utf16Byte
28e30 4c 65 6e 28 63 6f 6e 73 74 20 76 6f 69 64 20 2a Len(const void *
28e40 70 44 61 74 61 2c 20 69 6e 74 20 6e 43 68 61 72 pData, int nChar
28e50 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 55 74 );.int sqlite3Ut
28e60 66 38 43 68 61 72 4c 65 6e 28 63 6f 6e 73 74 20 f8CharLen(const
28e70 63 68 61 72 20 2a 70 44 61 74 61 2c 20 69 6e 74 char *pData, int
28e80 20 6e 42 79 74 65 29 3b 0a 75 33 32 20 73 71 6c nByte);.u32 sql
28e90 69 74 65 33 55 74 66 38 52 65 61 64 28 63 6f 6e ite3Utf8Read(con
28ea0 73 74 20 75 38 2a 2a 29 3b 0a 4c 6f 67 45 73 74 st u8**);.LogEst
28eb0 20 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 28 75 sqlite3LogEst(u
28ec0 36 34 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 64);.LogEst sqli
28ed0 74 65 33 4c 6f 67 45 73 74 41 64 64 28 4c 6f 67 te3LogEstAdd(Log
28ee0 45 73 74 2c 4c 6f 67 45 73 74 29 3b 0a 23 69 66 Est,LogEst);.#if
28ef0 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
28f00 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a 4c 6f _VIRTUALTABLE.Lo
28f10 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f 67 45 gEst sqlite3LogE
28f20 73 74 46 72 6f 6d 44 6f 75 62 6c 65 28 64 6f 75 stFromDouble(dou
28f30 62 6c 65 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 ble);.#endif.#if
28f40 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
28f50 45 4e 41 42 4c 45 5f 53 54 4d 54 5f 53 43 41 4e ENABLE_STMT_SCAN
28f60 53 54 41 54 55 53 29 20 7c 7c 20 5c 0a 20 20 20 STATUS) || \.
28f70 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
28f80 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f ENABLE_STAT3_OR_
28f90 53 54 41 54 34 29 20 7c 7c 20 5c 0a 20 20 20 20 STAT4) || \.
28fa0 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 45 defined(SQLITE_E
28fb0 58 50 4c 41 49 4e 5f 45 53 54 49 4d 41 54 45 44 XPLAIN_ESTIMATED
28fc0 5f 52 4f 57 53 29 0a 75 36 34 20 73 71 6c 69 74 _ROWS).u64 sqlit
28fd0 65 33 4c 6f 67 45 73 74 54 6f 49 6e 74 28 4c 6f e3LogEstToInt(Lo
28fe0 67 45 73 74 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f gEst);.#endif../
28ff0 2a 0a 2a 2a 20 52 6f 75 74 69 6e 65 73 20 74 6f *.** Routines to
29000 20 72 65 61 64 20 61 6e 64 20 77 72 69 74 65 20 read and write
29010 76 61 72 69 61 62 6c 65 2d 6c 65 6e 67 74 68 20 variable-length
29020 69 6e 74 65 67 65 72 73 2e 20 20 54 68 65 73 65 integers. These
29030 20 75 73 65 64 20 74 6f 0a 2a 2a 20 62 65 20 64 used to.** be d
29040 65 66 69 6e 65 64 20 6c 6f 63 61 6c 6c 79 2c 20 efined locally,
29050 62 75 74 20 6e 6f 77 20 77 65 20 75 73 65 20 74 but now we use t
29060 68 65 20 76 61 72 69 6e 74 20 72 6f 75 74 69 6e he varint routin
29070 65 73 20 69 6e 20 74 68 65 20 75 74 69 6c 2e 63 es in the util.c
29080 0a 2a 2a 20 66 69 6c 65 2e 0a 2a 2f 0a 69 6e 74 .** file..*/.int
29090 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 6e sqlite3PutVarin
290a0 74 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 2a t(unsigned char*
290b0 2c 20 75 36 34 29 3b 0a 75 38 20 73 71 6c 69 74 , u64);.u8 sqlit
290c0 65 33 47 65 74 56 61 72 69 6e 74 28 63 6f 6e 73 e3GetVarint(cons
290d0 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 t unsigned char
290e0 2a 2c 20 75 36 34 20 2a 29 3b 0a 75 38 20 73 71 *, u64 *);.u8 sq
290f0 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 32 lite3GetVarint32
29100 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 (const unsigned
29110 63 68 61 72 20 2a 2c 20 75 33 32 20 2a 29 3b 0a char *, u32 *);.
29120 69 6e 74 20 73 71 6c 69 74 65 33 56 61 72 69 6e int sqlite3Varin
29130 74 4c 65 6e 28 75 36 34 20 76 29 3b 0a 0a 2f 2a tLen(u64 v);../*
29140 0a 2a 2a 20 54 68 65 20 63 6f 6d 6d 6f 6e 20 63 .** The common c
29150 61 73 65 20 69 73 20 66 6f 72 20 61 20 76 61 72 ase is for a var
29160 69 6e 74 20 74 6f 20 62 65 20 61 20 73 69 6e 67 int to be a sing
29170 6c 65 20 62 79 74 65 2e 20 20 54 68 65 79 20 66 le byte. They f
29180 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 6d 61 63 72 ollowing.** macr
29190 6f 73 20 68 61 6e 64 6c 65 20 74 68 65 20 63 6f os handle the co
291a0 6d 6d 6f 6e 20 63 61 73 65 20 77 69 74 68 6f 75 mmon case withou
291b0 74 20 61 20 70 72 6f 63 65 64 75 72 65 20 63 61 t a procedure ca
291c0 6c 6c 2c 20 62 75 74 20 74 68 65 6e 20 63 61 6c ll, but then cal
291d0 6c 0a 2a 2a 20 74 68 65 20 70 72 6f 63 65 64 75 l.** the procedu
291e0 72 65 20 66 6f 72 20 6c 61 72 67 65 72 20 76 61 re for larger va
291f0 72 69 6e 74 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e rints..*/.#defin
29200 65 20 67 65 74 56 61 72 69 6e 74 33 32 28 41 2c e getVarint32(A,
29210 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 2a 28 B) \. (u8)((*(
29220 41 29 3c 28 75 38 29 30 78 38 30 29 3f 28 28 42 A)<(u8)0x80)?((B
29230 29 3d 28 75 33 32 29 2a 28 41 29 29 2c 31 3a 73 )=(u32)*(A)),1:s
29240 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 qlite3GetVarint3
29250 32 28 28 41 29 2c 28 75 33 32 20 2a 29 26 28 42 2((A),(u32 *)&(B
29260 29 29 29 0a 23 64 65 66 69 6e 65 20 70 75 74 56 ))).#define putV
29270 61 72 69 6e 74 33 32 28 41 2c 42 29 20 20 5c 0a arint32(A,B) \.
29280 20 20 28 75 38 29 28 28 28 75 33 32 29 28 42 29 (u8)(((u32)(B)
29290 3c 28 75 33 32 29 30 78 38 30 29 3f 28 2a 28 41 <(u32)0x80)?(*(A
292a0 29 3d 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 )=(unsigned char
292b0 29 28 42 29 29 2c 31 3a 5c 0a 20 20 73 71 6c 69 )(B)),1:\. sqli
292c0 74 65 33 50 75 74 56 61 72 69 6e 74 28 28 41 29 te3PutVarint((A)
292d0 2c 28 42 29 29 29 0a 23 64 65 66 69 6e 65 20 67 ,(B))).#define g
292e0 65 74 56 61 72 69 6e 74 20 20 20 20 73 71 6c 69 etVarint sqli
292f0 74 65 33 47 65 74 56 61 72 69 6e 74 0a 23 64 65 te3GetVarint.#de
29300 66 69 6e 65 20 70 75 74 56 61 72 69 6e 74 20 20 fine putVarint
29310 20 20 73 71 6c 69 74 65 33 50 75 74 56 61 72 69 sqlite3PutVari
29320 6e 74 0a 0a 0a 63 6f 6e 73 74 20 63 68 61 72 20 nt...const char
29330 2a 73 71 6c 69 74 65 33 49 6e 64 65 78 41 66 66 *sqlite3IndexAff
29340 69 6e 69 74 79 53 74 72 28 73 71 6c 69 74 65 33 inityStr(sqlite3
29350 2a 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 *, Index*);.void
29360 20 73 71 6c 69 74 65 33 54 61 62 6c 65 41 66 66 sqlite3TableAff
29370 69 6e 69 74 79 28 56 64 62 65 2a 2c 20 54 61 62 inity(Vdbe*, Tab
29380 6c 65 2a 2c 20 69 6e 74 29 3b 0a 63 68 61 72 20 le*, int);.char
29390 73 71 6c 69 74 65 33 43 6f 6d 70 61 72 65 41 66 sqlite3CompareAf
293a0 66 69 6e 69 74 79 28 45 78 70 72 20 2a 70 45 78 finity(Expr *pEx
293b0 70 72 2c 20 63 68 61 72 20 61 66 66 32 29 3b 0a pr, char aff2);.
293c0 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 64 65 78 int sqlite3Index
293d0 41 66 66 69 6e 69 74 79 4f 6b 28 45 78 70 72 20 AffinityOk(Expr
293e0 2a 70 45 78 70 72 2c 20 63 68 61 72 20 69 64 78 *pExpr, char idx
293f0 5f 61 66 66 69 6e 69 74 79 29 3b 0a 63 68 61 72 _affinity);.char
29400 20 73 71 6c 69 74 65 33 54 61 62 6c 65 43 6f 6c sqlite3TableCol
29410 75 6d 6e 41 66 66 69 6e 69 74 79 28 54 61 62 6c umnAffinity(Tabl
29420 65 2a 2c 69 6e 74 29 3b 0a 63 68 61 72 20 73 71 e*,int);.char sq
29430 6c 69 74 65 33 45 78 70 72 41 66 66 69 6e 69 74 lite3ExprAffinit
29440 79 28 45 78 70 72 20 2a 70 45 78 70 72 29 3b 0a y(Expr *pExpr);.
29450 69 6e 74 20 73 71 6c 69 74 65 33 41 74 6f 69 36 int sqlite3Atoi6
29460 34 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 4(const char*, i
29470 36 34 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 64*, int, u8);.i
29480 6e 74 20 73 71 6c 69 74 65 33 44 65 63 4f 72 48 nt sqlite3DecOrH
29490 65 78 54 6f 49 36 34 28 63 6f 6e 73 74 20 63 68 exToI64(const ch
294a0 61 72 2a 2c 20 69 36 34 2a 29 3b 0a 76 6f 69 64 ar*, i64*);.void
294b0 20 73 71 6c 69 74 65 33 45 72 72 6f 72 57 69 74 sqlite3ErrorWit
294c0 68 4d 73 67 28 73 71 6c 69 74 65 33 2a 2c 20 69 hMsg(sqlite3*, i
294d0 6e 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c nt, const char*,
294e0 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ...);.void sqlit
294f0 65 33 45 72 72 6f 72 28 73 71 6c 69 74 65 33 2a e3Error(sqlite3*
29500 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
29510 74 65 33 53 79 73 74 65 6d 45 72 72 6f 72 28 73 te3SystemError(s
29520 71 6c 69 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f qlite3*,int);.vo
29530 69 64 20 2a 73 71 6c 69 74 65 33 48 65 78 54 6f id *sqlite3HexTo
29540 42 6c 6f 62 28 73 71 6c 69 74 65 33 2a 2c 20 63 Blob(sqlite3*, c
29550 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c 20 69 6e onst char *z, in
29560 74 20 6e 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 t n);.u8 sqlite3
29570 48 65 78 54 6f 49 6e 74 28 69 6e 74 20 68 29 3b HexToInt(int h);
29580 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 77 6f 50 .int sqlite3TwoP
29590 61 72 74 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c artName(Parse *,
295a0 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 Token *, Token
295b0 2a 2c 20 54 6f 6b 65 6e 20 2a 2a 29 3b 0a 0a 23 *, Token **);..#
295c0 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 if defined(SQLIT
295d0 45 5f 4e 45 45 44 5f 45 52 52 5f 4e 41 4d 45 29 E_NEED_ERR_NAME)
295e0 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c .const char *sql
295f0 69 74 65 33 45 72 72 4e 61 6d 65 28 69 6e 74 29 ite3ErrName(int)
29600 3b 0a 23 65 6e 64 69 66 0a 0a 63 6f 6e 73 74 20 ;.#endif..const
29610 63 68 61 72 20 2a 73 71 6c 69 74 65 33 45 72 72 char *sqlite3Err
29620 53 74 72 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 Str(int);.int sq
29630 6c 69 74 65 33 52 65 61 64 53 63 68 65 6d 61 28 lite3ReadSchema(
29640 50 61 72 73 65 20 2a 70 50 61 72 73 65 29 3b 0a Parse *pParse);.
29650 43 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 CollSeq *sqlite3
29660 46 69 6e 64 43 6f 6c 6c 53 65 71 28 73 71 6c 69 FindCollSeq(sqli
29670 74 65 33 2a 2c 75 38 20 65 6e 63 2c 20 63 6f 6e te3*,u8 enc, con
29680 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 43 st char*,int);.C
29690 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 4c ollSeq *sqlite3L
296a0 6f 63 61 74 65 43 6f 6c 6c 53 65 71 28 50 61 72 ocateCollSeq(Par
296b0 73 65 20 2a 70 50 61 72 73 65 2c 20 63 6f 6e 73 se *pParse, cons
296c0 74 20 63 68 61 72 2a 7a 4e 61 6d 65 29 3b 0a 43 t char*zName);.C
296d0 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 45 ollSeq *sqlite3E
296e0 78 70 72 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 xprCollSeq(Parse
296f0 20 2a 70 50 61 72 73 65 2c 20 45 78 70 72 20 2a *pParse, Expr *
29700 70 45 78 70 72 29 3b 0a 45 78 70 72 20 2a 73 71 pExpr);.Expr *sq
29710 6c 69 74 65 33 45 78 70 72 41 64 64 43 6f 6c 6c lite3ExprAddColl
29720 61 74 65 54 6f 6b 65 6e 28 50 61 72 73 65 20 2a ateToken(Parse *
29730 70 50 61 72 73 65 2c 20 45 78 70 72 2a 2c 20 63 pParse, Expr*, c
29740 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c 20 69 6e 74 onst Token*, int
29750 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
29760 45 78 70 72 41 64 64 43 6f 6c 6c 61 74 65 53 74 ExprAddCollateSt
29770 72 69 6e 67 28 50 61 72 73 65 2a 2c 45 78 70 72 ring(Parse*,Expr
29780 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a *,const char*);.
29790 45 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 Expr *sqlite3Exp
297a0 72 53 6b 69 70 43 6f 6c 6c 61 74 65 28 45 78 70 rSkipCollate(Exp
297b0 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
297c0 43 68 65 63 6b 43 6f 6c 6c 53 65 71 28 50 61 72 CheckCollSeq(Par
297d0 73 65 20 2a 2c 20 43 6f 6c 6c 53 65 71 20 2a 29 se *, CollSeq *)
297e0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 68 65 ;.int sqlite3Che
297f0 63 6b 4f 62 6a 65 63 74 4e 61 6d 65 28 50 61 72 ckObjectName(Par
29800 73 65 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 se *, const char
29810 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
29820 33 56 64 62 65 53 65 74 43 68 61 6e 67 65 73 28 3VdbeSetChanges(
29830 73 71 6c 69 74 65 33 20 2a 2c 20 69 6e 74 29 3b sqlite3 *, int);
29840 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 64 64 49 .int sqlite3AddI
29850 6e 74 36 34 28 69 36 34 2a 2c 69 36 34 29 3b 0a nt64(i64*,i64);.
29860 69 6e 74 20 73 71 6c 69 74 65 33 53 75 62 49 6e int sqlite3SubIn
29870 74 36 34 28 69 36 34 2a 2c 69 36 34 29 3b 0a 69 t64(i64*,i64);.i
29880 6e 74 20 73 71 6c 69 74 65 33 4d 75 6c 49 6e 74 nt sqlite3MulInt
29890 36 34 28 69 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 64(i64*,i64);.in
298a0 74 20 73 71 6c 69 74 65 33 41 62 73 49 6e 74 33 t sqlite3AbsInt3
298b0 32 28 69 6e 74 29 3b 0a 23 69 66 64 65 66 20 53 2(int);.#ifdef S
298c0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 38 5f 33 QLITE_ENABLE_8_3
298d0 5f 4e 41 4d 45 53 0a 76 6f 69 64 20 73 71 6c 69 _NAMES.void sqli
298e0 74 65 33 46 69 6c 65 53 75 66 66 69 78 33 28 63 te3FileSuffix3(c
298f0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 68 61 72 onst char*, char
29900 2a 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 *);.#else.# defi
29910 6e 65 20 73 71 6c 69 74 65 33 46 69 6c 65 53 75 ne sqlite3FileSu
29920 66 66 69 78 33 28 58 2c 59 29 0a 23 65 6e 64 69 ffix3(X,Y).#endi
29930 66 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 42 f.u8 sqlite3GetB
29940 6f 6f 6c 65 61 6e 28 63 6f 6e 73 74 20 63 68 61 oolean(const cha
29950 72 20 2a 7a 2c 75 38 29 3b 0a 0a 63 6f 6e 73 74 r *z,u8);..const
29960 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 56 61 void *sqlite3Va
29970 6c 75 65 54 65 78 74 28 73 71 6c 69 74 65 33 5f lueText(sqlite3_
29980 76 61 6c 75 65 2a 2c 20 75 38 29 3b 0a 69 6e 74 value*, u8);.int
29990 20 73 71 6c 69 74 65 33 56 61 6c 75 65 42 79 74 sqlite3ValueByt
299a0 65 73 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 es(sqlite3_value
299b0 2a 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 71 6c *, u8);.void sql
299c0 69 74 65 33 56 61 6c 75 65 53 65 74 53 74 72 28 ite3ValueSetStr(
299d0 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 sqlite3_value*,
299e0 69 6e 74 2c 20 63 6f 6e 73 74 20 76 6f 69 64 20 int, const void
299f0 2a 2c 75 38 2c 0a 20 20 20 20 20 20 20 20 20 20 *,u8,.
29a00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 76 6f vo
29a10 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 76 id(*)(void*));.v
29a20 6f 69 64 20 73 71 6c 69 74 65 33 56 61 6c 75 65 oid sqlite3Value
29a30 53 65 74 4e 75 6c 6c 28 73 71 6c 69 74 65 33 5f SetNull(sqlite3_
29a40 76 61 6c 75 65 2a 29 3b 0a 76 6f 69 64 20 73 71 value*);.void sq
29a50 6c 69 74 65 33 56 61 6c 75 65 46 72 65 65 28 73 lite3ValueFree(s
29a60 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 29 3b 0a qlite3_value*);.
29a70 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a 73 sqlite3_value *s
29a80 71 6c 69 74 65 33 56 61 6c 75 65 4e 65 77 28 73 qlite3ValueNew(s
29a90 71 6c 69 74 65 33 20 2a 29 3b 0a 63 68 61 72 20 qlite3 *);.char
29aa0 2a 73 71 6c 69 74 65 33 55 74 66 31 36 74 6f 38 *sqlite3Utf16to8
29ab0 28 73 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 (sqlite3 *, cons
29ac0 74 20 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 75 38 t void*, int, u8
29ad0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 61 );.int sqlite3Va
29ae0 6c 75 65 46 72 6f 6d 45 78 70 72 28 73 71 6c 69 lueFromExpr(sqli
29af0 74 65 33 20 2a 2c 20 45 78 70 72 20 2a 2c 20 75 te3 *, Expr *, u
29b00 38 2c 20 75 38 2c 20 73 71 6c 69 74 65 33 5f 76 8, u8, sqlite3_v
29b10 61 6c 75 65 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 alue **);.void s
29b20 71 6c 69 74 65 33 56 61 6c 75 65 41 70 70 6c 79 qlite3ValueApply
29b30 41 66 66 69 6e 69 74 79 28 73 71 6c 69 74 65 33 Affinity(sqlite3
29b40 5f 76 61 6c 75 65 20 2a 2c 20 75 38 2c 20 75 38 _value *, u8, u8
29b50 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
29b60 45 5f 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 0a 65 E_AMALGAMATION.e
29b70 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 69 xtern const unsi
29b80 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 65 gned char sqlite
29b90 33 4f 70 63 6f 64 65 50 72 6f 70 65 72 74 79 5b 3OpcodeProperty[
29ba0 5d 3b 0a 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 ];.extern const
29bb0 63 68 61 72 20 73 71 6c 69 74 65 33 53 74 72 42 char sqlite3StrB
29bc0 49 4e 41 52 59 5b 5d 3b 0a 65 78 74 65 72 6e 20 INARY[];.extern
29bd0 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 const unsigned c
29be0 68 61 72 20 73 71 6c 69 74 65 33 55 70 70 65 72 har sqlite3Upper
29bf0 54 6f 4c 6f 77 65 72 5b 5d 3b 0a 65 78 74 65 72 ToLower[];.exter
29c00 6e 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 n const unsigned
29c10 20 63 68 61 72 20 73 71 6c 69 74 65 33 43 74 79 char sqlite3Cty
29c20 70 65 4d 61 70 5b 5d 3b 0a 65 78 74 65 72 6e 20 peMap[];.extern
29c30 63 6f 6e 73 74 20 54 6f 6b 65 6e 20 73 71 6c 69 const Token sqli
29c40 74 65 33 49 6e 74 54 6f 6b 65 6e 73 5b 5d 3b 0a te3IntTokens[];.
29c50 65 78 74 65 72 6e 20 53 51 4c 49 54 45 5f 57 53 extern SQLITE_WS
29c60 44 20 73 74 72 75 63 74 20 53 71 6c 69 74 65 33 D struct Sqlite3
29c70 43 6f 6e 66 69 67 20 73 71 6c 69 74 65 33 43 6f Config sqlite3Co
29c80 6e 66 69 67 3b 0a 65 78 74 65 72 6e 20 46 75 6e nfig;.extern Fun
29c90 63 44 65 66 48 61 73 68 20 73 71 6c 69 74 65 33 cDefHash sqlite3
29ca0 42 75 69 6c 74 69 6e 46 75 6e 63 74 69 6f 6e 73 BuiltinFunctions
29cb0 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
29cc0 5f 4f 4d 49 54 5f 57 53 44 0a 65 78 74 65 72 6e _OMIT_WSD.extern
29cd0 20 69 6e 74 20 73 71 6c 69 74 65 33 50 65 6e 64 int sqlite3Pend
29ce0 69 6e 67 42 79 74 65 3b 0a 23 65 6e 64 69 66 0a ingByte;.#endif.
29cf0 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 #endif.void sqli
29d00 74 65 33 52 6f 6f 74 50 61 67 65 4d 6f 76 65 64 te3RootPageMoved
29d10 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
29d20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 int, int);.void
29d30 73 71 6c 69 74 65 33 52 65 69 6e 64 65 78 28 50 sqlite3Reindex(P
29d40 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
29d50 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c oken*);.void sql
29d60 69 74 65 33 41 6c 74 65 72 46 75 6e 63 74 69 6f ite3AlterFunctio
29d70 6e 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 ns(void);.void s
29d80 71 6c 69 74 65 33 41 6c 74 65 72 52 65 6e 61 6d qlite3AlterRenam
29d90 65 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 eTable(Parse*, S
29da0 72 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 rcList*, Token*)
29db0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 ;.int sqlite3Get
29dc0 54 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 Token(const unsi
29dd0 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 69 6e 74 gned char *, int
29de0 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
29df0 33 4e 65 73 74 65 64 50 61 72 73 65 28 50 61 72 3NestedParse(Par
29e00 73 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a se*, const char*
29e10 2c 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c , ...);.void sql
29e20 69 74 65 33 45 78 70 69 72 65 50 72 65 70 61 72 ite3ExpirePrepar
29e30 65 64 53 74 61 74 65 6d 65 6e 74 73 28 73 71 6c edStatements(sql
29e40 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 ite3*);.int sqli
29e50 74 65 33 43 6f 64 65 53 75 62 73 65 6c 65 63 74 te3CodeSubselect
29e60 28 50 61 72 73 65 2a 2c 20 45 78 70 72 20 2a 2c (Parse*, Expr *,
29e70 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
29e80 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 50 72 sqlite3SelectPr
29e90 65 70 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 ep(Parse*, Selec
29ea0 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a t*, NameContext*
29eb0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
29ec0 65 6c 65 63 74 57 72 6f 6e 67 4e 75 6d 54 65 72 electWrongNumTer
29ed0 6d 73 45 72 72 6f 72 28 50 61 72 73 65 20 2a 70 msError(Parse *p
29ee0 50 61 72 73 65 2c 20 53 65 6c 65 63 74 20 2a 70 Parse, Select *p
29ef0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 );.int sqlite3Ma
29f00 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e 73 tchSpanName(cons
29f10 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 t char*, const c
29f20 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 har*, const char
29f30 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
29f40 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f .int sqlite3Reso
29f50 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 6d lveExprNames(Nam
29f60 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a eContext*, Expr*
29f70 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 );.int sqlite3Re
29f80 73 6f 6c 76 65 45 78 70 72 4c 69 73 74 4e 61 6d solveExprListNam
29f90 65 73 28 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c es(NameContext*,
29fa0 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 76 6f 69 ExprList*);.voi
29fb0 64 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 d sqlite3Resolve
29fc0 53 65 6c 65 63 74 4e 61 6d 65 73 28 50 61 72 73 SelectNames(Pars
29fd0 65 2a 2c 20 53 65 6c 65 63 74 2a 2c 20 4e 61 6d e*, Select*, Nam
29fe0 65 43 6f 6e 74 65 78 74 2a 29 3b 0a 76 6f 69 64 eContext*);.void
29ff0 20 73 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 53 sqlite3ResolveS
2a000 65 6c 66 52 65 66 65 72 65 6e 63 65 28 50 61 72 elfReference(Par
2a010 73 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2c 45 se*,Table*,int,E
2a020 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 29 3b xpr*,ExprList*);
2a030 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f .int sqlite3Reso
2a040 6c 76 65 4f 72 64 65 72 47 72 6f 75 70 42 79 28 lveOrderGroupBy(
2a050 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 2a 2c Parse*, Select*,
2a060 20 45 78 70 72 4c 69 73 74 2a 2c 20 63 6f 6e 73 ExprList*, cons
2a070 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 t char*);.void s
2a080 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 44 65 66 61 qlite3ColumnDefa
2a090 75 6c 74 28 56 64 62 65 20 2a 2c 20 54 61 62 6c ult(Vdbe *, Tabl
2a0a0 65 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a e *, int, int);.
2a0b0 76 6f 69 64 20 73 71 6c 69 74 65 33 41 6c 74 65 void sqlite3Alte
2a0c0 72 46 69 6e 69 73 68 41 64 64 43 6f 6c 75 6d 6e rFinishAddColumn
2a0d0 28 50 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 (Parse *, Token
2a0e0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
2a0f0 41 6c 74 65 72 42 65 67 69 6e 41 64 64 43 6f 6c AlterBeginAddCol
2a100 75 6d 6e 28 50 61 72 73 65 20 2a 2c 20 53 72 63 umn(Parse *, Src
2a110 4c 69 73 74 20 2a 29 3b 0a 43 6f 6c 6c 53 65 71 List *);.CollSeq
2a120 20 2a 73 71 6c 69 74 65 33 47 65 74 43 6f 6c 6c *sqlite3GetColl
2a130 53 65 71 28 50 61 72 73 65 2a 2c 20 75 38 2c 20 Seq(Parse*, u8,
2a140 43 6f 6c 6c 53 65 71 20 2a 2c 20 63 6f 6e 73 74 CollSeq *, const
2a150 20 63 68 61 72 2a 29 3b 0a 63 68 61 72 20 73 71 char*);.char sq
2a160 6c 69 74 65 33 41 66 66 69 6e 69 74 79 54 79 70 lite3AffinityTyp
2a170 65 28 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 75 e(const char*, u
2a180 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 8*);.void sqlite
2a190 33 41 6e 61 6c 79 7a 65 28 50 61 72 73 65 2a 2c 3Analyze(Parse*,
2a1a0 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 29 Token*, Token*)
2a1b0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 76 ;.int sqlite3Inv
2a1c0 6f 6b 65 42 75 73 79 48 61 6e 64 6c 65 72 28 42 okeBusyHandler(B
2a1d0 75 73 79 48 61 6e 64 6c 65 72 2a 29 3b 0a 69 6e usyHandler*);.in
2a1e0 74 20 73 71 6c 69 74 65 33 46 69 6e 64 44 62 28 t sqlite3FindDb(
2a1f0 73 71 6c 69 74 65 33 2a 2c 20 54 6f 6b 65 6e 2a sqlite3*, Token*
2a200 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 69 );.int sqlite3Fi
2a210 6e 64 44 62 4e 61 6d 65 28 73 71 6c 69 74 65 33 ndDbName(sqlite3
2a220 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a *, const char *
2a230 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 6e );.int sqlite3An
2a240 61 6c 79 73 69 73 4c 6f 61 64 28 73 71 6c 69 74 alysisLoad(sqlit
2a250 65 33 2a 2c 69 6e 74 20 69 44 42 29 3b 0a 76 6f e3*,int iDB);.vo
2a260 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 id sqlite3Delete
2a270 49 6e 64 65 78 53 61 6d 70 6c 65 73 28 73 71 6c IndexSamples(sql
2a280 69 74 65 33 2a 2c 49 6e 64 65 78 2a 29 3b 0a 76 ite3*,Index*);.v
2a290 6f 69 64 20 73 71 6c 69 74 65 33 44 65 66 61 75 oid sqlite3Defau
2a2a0 6c 74 52 6f 77 45 73 74 28 49 6e 64 65 78 2a 29 ltRowEst(Index*)
2a2b0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 ;.void sqlite3Re
2a2c0 67 69 73 74 65 72 4c 69 6b 65 46 75 6e 63 74 69 gisterLikeFuncti
2a2d0 6f 6e 73 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e ons(sqlite3*, in
2a2e0 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 t);.int sqlite3I
2a2f0 73 4c 69 6b 65 46 75 6e 63 74 69 6f 6e 28 73 71 sLikeFunction(sq
2a300 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c 69 6e 74 lite3*,Expr*,int
2a310 2a 2c 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 *,char*);.void s
2a320 71 6c 69 74 65 33 53 63 68 65 6d 61 43 6c 65 61 qlite3SchemaClea
2a330 72 28 76 6f 69 64 20 2a 29 3b 0a 53 63 68 65 6d r(void *);.Schem
2a340 61 20 2a 73 71 6c 69 74 65 33 53 63 68 65 6d 61 a *sqlite3Schema
2a350 47 65 74 28 73 71 6c 69 74 65 33 20 2a 2c 20 42 Get(sqlite3 *, B
2a360 74 72 65 65 20 2a 29 3b 0a 69 6e 74 20 73 71 6c tree *);.int sql
2a370 69 74 65 33 53 63 68 65 6d 61 54 6f 49 6e 64 65 ite3SchemaToInde
2a380 78 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 53 x(sqlite3 *db, S
2a390 63 68 65 6d 61 20 2a 29 3b 0a 4b 65 79 49 6e 66 chema *);.KeyInf
2a3a0 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 o *sqlite3KeyInf
2a3b0 6f 41 6c 6c 6f 63 28 73 71 6c 69 74 65 33 2a 2c oAlloc(sqlite3*,
2a3c0 69 6e 74 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 int,int);.void s
2a3d0 71 6c 69 74 65 33 4b 65 79 49 6e 66 6f 55 6e 72 qlite3KeyInfoUnr
2a3e0 65 66 28 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 ef(KeyInfo*);.Ke
2a3f0 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 yInfo *sqlite3Ke
2a400 79 49 6e 66 6f 52 65 66 28 4b 65 79 49 6e 66 6f yInfoRef(KeyInfo
2a410 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c *);.KeyInfo *sql
2a420 69 74 65 33 4b 65 79 49 6e 66 6f 4f 66 49 6e 64 ite3KeyInfoOfInd
2a430 65 78 28 50 61 72 73 65 2a 2c 20 49 6e 64 65 78 ex(Parse*, Index
2a440 2a 29 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 54 *);.#ifdef SQLIT
2a450 45 5f 44 45 42 55 47 0a 69 6e 74 20 73 71 6c 69 E_DEBUG.int sqli
2a460 74 65 33 4b 65 79 49 6e 66 6f 49 73 57 72 69 74 te3KeyInfoIsWrit
2a470 65 61 62 6c 65 28 4b 65 79 49 6e 66 6f 2a 29 3b eable(KeyInfo*);
2a480 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 .#endif.int sqli
2a490 74 65 33 43 72 65 61 74 65 46 75 6e 63 28 73 71 te3CreateFunc(sq
2a4a0 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 63 lite3 *, const c
2a4b0 68 61 72 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c har *, int, int,
2a4c0 20 76 6f 69 64 20 2a 2c 0a 20 20 76 6f 69 64 20 void *,. void
2a4d0 28 2a 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 (*)(sqlite3_cont
2a4e0 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 ext*,int,sqlite3
2a4f0 5f 76 61 6c 75 65 20 2a 2a 29 2c 0a 20 20 76 6f _value **),. vo
2a500 69 64 20 28 2a 29 28 73 71 6c 69 74 65 33 5f 63 id (*)(sqlite3_c
2a510 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 71 6c 69 ontext*,int,sqli
2a520 74 65 33 5f 76 61 6c 75 65 20 2a 2a 29 2c 20 76 te3_value **), v
2a530 6f 69 64 20 28 2a 29 28 73 71 6c 69 74 65 33 5f oid (*)(sqlite3_
2a540 63 6f 6e 74 65 78 74 2a 29 2c 0a 20 20 46 75 6e context*),. Fun
2a550 63 44 65 73 74 72 75 63 74 6f 72 20 2a 70 44 65 cDestructor *pDe
2a560 73 74 72 75 63 74 6f 72 0a 29 3b 0a 76 6f 69 64 structor.);.void
2a570 20 73 71 6c 69 74 65 33 4f 6f 6d 46 61 75 6c 74 sqlite3OomFault
2a580 28 73 71 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 (sqlite3*);.void
2a590 20 73 71 6c 69 74 65 33 4f 6f 6d 43 6c 65 61 72 sqlite3OomClear
2a5a0 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 (sqlite3*);.int
2a5b0 73 71 6c 69 74 65 33 41 70 69 45 78 69 74 28 73 sqlite3ApiExit(s
2a5c0 71 6c 69 74 65 33 20 2a 64 62 2c 20 69 6e 74 29 qlite3 *db, int)
2a5d0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 ;.int sqlite3Ope
2a5e0 6e 54 65 6d 70 44 61 74 61 62 61 73 65 28 50 61 nTempDatabase(Pa
2a5f0 72 73 65 20 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 rse *);..void sq
2a600 6c 69 74 65 33 53 74 72 41 63 63 75 6d 49 6e 69 lite3StrAccumIni
2a610 74 28 53 74 72 41 63 63 75 6d 2a 2c 20 73 71 6c t(StrAccum*, sql
2a620 69 74 65 33 2a 2c 20 63 68 61 72 2a 2c 20 69 6e ite3*, char*, in
2a630 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
2a640 6c 69 74 65 33 53 74 72 41 63 63 75 6d 41 70 70 lite3StrAccumApp
2a650 65 6e 64 28 53 74 72 41 63 63 75 6d 2a 2c 63 6f end(StrAccum*,co
2a660 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a nst char*,int);.
2a670 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 41 void sqlite3StrA
2a680 63 63 75 6d 41 70 70 65 6e 64 41 6c 6c 28 53 74 ccumAppendAll(St
2a690 72 41 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 rAccum*,const ch
2a6a0 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ar*);.void sqlit
2a6b0 65 33 41 70 70 65 6e 64 43 68 61 72 28 53 74 72 e3AppendChar(Str
2a6c0 41 63 63 75 6d 2a 2c 69 6e 74 2c 63 68 61 72 29 Accum*,int,char)
2a6d0 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 53 ;.char *sqlite3S
2a6e0 74 72 41 63 63 75 6d 46 69 6e 69 73 68 28 53 74 trAccumFinish(St
2a6f0 72 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 rAccum*);.void s
2a700 71 6c 69 74 65 33 53 74 72 41 63 63 75 6d 52 65 qlite3StrAccumRe
2a710 73 65 74 28 53 74 72 41 63 63 75 6d 2a 29 3b 0a set(StrAccum*);.
2a720 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 void sqlite3Sele
2a730 63 74 44 65 73 74 49 6e 69 74 28 53 65 6c 65 63 ctDestInit(Selec
2a740 74 44 65 73 74 2a 2c 69 6e 74 2c 69 6e 74 29 3b tDest*,int,int);
2a750 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 43 72 .Expr *sqlite3Cr
2a760 65 61 74 65 43 6f 6c 75 6d 6e 45 78 70 72 28 73 eateColumnExpr(s
2a770 71 6c 69 74 65 33 20 2a 2c 20 53 72 63 4c 69 73 qlite3 *, SrcLis
2a780 74 20 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a t *, int, int);.
2a790 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 42 61 63 .void sqlite3Bac
2a7a0 6b 75 70 52 65 73 74 61 72 74 28 73 71 6c 69 74 kupRestart(sqlit
2a7b0 65 33 5f 62 61 63 6b 75 70 20 2a 29 3b 0a 76 6f e3_backup *);.vo
2a7c0 69 64 20 73 71 6c 69 74 65 33 42 61 63 6b 75 70 id sqlite3Backup
2a7d0 55 70 64 61 74 65 28 73 71 6c 69 74 65 33 5f 62 Update(sqlite3_b
2a7e0 61 63 6b 75 70 20 2a 2c 20 50 67 6e 6f 2c 20 63 ackup *, Pgno, c
2a7f0 6f 6e 73 74 20 75 38 20 2a 29 3b 0a 0a 23 69 66 onst u8 *);..#if
2a800 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 ndef SQLITE_OMIT
2a810 5f 53 55 42 51 55 45 52 59 0a 69 6e 74 20 73 71 _SUBQUERY.int sq
2a820 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 49 4e lite3ExprCheckIN
2a830 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b (Parse*, Expr*);
2a840 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
2a850 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b sqlite3ExprCheck
2a860 49 4e 28 78 2c 79 29 20 53 51 4c 49 54 45 5f 4f IN(x,y) SQLITE_O
2a870 4b 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 K.#endif..#ifdef
2a880 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
2a890 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 76 6f TAT3_OR_STAT4.vo
2a8a0 69 64 20 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a id sqlite3Analyz
2a8b0 65 46 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 eFunctions(void)
2a8c0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 ;.int sqlite3Sta
2a8d0 74 34 50 72 6f 62 65 53 65 74 56 61 6c 75 65 28 t4ProbeSetValue(
2a8e0 0a 20 20 20 20 50 61 72 73 65 2a 2c 49 6e 64 65 . Parse*,Inde
2a8f0 78 2a 2c 55 6e 70 61 63 6b 65 64 52 65 63 6f 72 x*,UnpackedRecor
2a900 64 2a 2a 2c 45 78 70 72 2a 2c 69 6e 74 2c 69 6e d**,Expr*,int,in
2a910 74 2c 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c t,int*);.int sql
2a920 69 74 65 33 53 74 61 74 34 56 61 6c 75 65 46 72 ite3Stat4ValueFr
2a930 6f 6d 45 78 70 72 28 50 61 72 73 65 2a 2c 20 45 omExpr(Parse*, E
2a940 78 70 72 2a 2c 20 75 38 2c 20 73 71 6c 69 74 65 xpr*, u8, sqlite
2a950 33 5f 76 61 6c 75 65 2a 2a 29 3b 0a 76 6f 69 64 3_value**);.void
2a960 20 73 71 6c 69 74 65 33 53 74 61 74 34 50 72 6f sqlite3Stat4Pro
2a970 62 65 46 72 65 65 28 55 6e 70 61 63 6b 65 64 52 beFree(UnpackedR
2a980 65 63 6f 72 64 2a 29 3b 0a 69 6e 74 20 73 71 6c ecord*);.int sql
2a990 69 74 65 33 53 74 61 74 34 43 6f 6c 75 6d 6e 28 ite3Stat4Column(
2a9a0 73 71 6c 69 74 65 33 2a 2c 20 63 6f 6e 73 74 20 sqlite3*, const
2a9b0 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c void*, int, int,
2a9c0 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a sqlite3_value**
2a9d0 29 3b 0a 63 68 61 72 20 73 71 6c 69 74 65 33 49 );.char sqlite3I
2a9e0 6e 64 65 78 43 6f 6c 75 6d 6e 41 66 66 69 6e 69 ndexColumnAffini
2a9f0 74 79 28 73 71 6c 69 74 65 33 2a 2c 20 49 6e 64 ty(sqlite3*, Ind
2aa00 65 78 2a 2c 20 69 6e 74 29 3b 0a 23 65 6e 64 69 ex*, int);.#endi
2aa10 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 f../*.** The int
2aa20 65 72 66 61 63 65 20 74 6f 20 74 68 65 20 4c 45 erface to the LE
2aa30 4d 4f 4e 2d 67 65 6e 65 72 61 74 65 64 20 70 61 MON-generated pa
2aa40 72 73 65 72 0a 2a 2f 0a 76 6f 69 64 20 2a 73 71 rser.*/.void *sq
2aa50 6c 69 74 65 33 50 61 72 73 65 72 41 6c 6c 6f 63 lite3ParserAlloc
2aa60 28 76 6f 69 64 2a 28 2a 29 28 75 36 34 29 29 3b (void*(*)(u64));
2aa70 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 .void sqlite3Par
2aa80 73 65 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 76 serFree(void*, v
2aa90 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a oid(*)(void*));.
2aaa0 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 void sqlite3Pars
2aab0 65 72 28 76 6f 69 64 2a 2c 20 69 6e 74 2c 20 54 er(void*, int, T
2aac0 6f 6b 65 6e 2c 20 50 61 72 73 65 2a 29 3b 0a 23 oken, Parse*);.#
2aad0 69 66 64 65 66 20 59 59 54 52 41 43 4b 4d 41 58 ifdef YYTRACKMAX
2aae0 53 54 41 43 4b 44 45 50 54 48 0a 20 20 69 6e 74 STACKDEPTH. int
2aaf0 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 53 74 sqlite3ParserSt
2ab00 61 63 6b 50 65 61 6b 28 76 6f 69 64 2a 29 3b 0a ackPeak(void*);.
2ab10 23 65 6e 64 69 66 0a 0a 76 6f 69 64 20 73 71 6c #endif..void sql
2ab20 69 74 65 33 41 75 74 6f 4c 6f 61 64 45 78 74 65 ite3AutoLoadExte
2ab30 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 nsions(sqlite3*)
2ab40 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
2ab50 5f 4f 4d 49 54 5f 4c 4f 41 44 5f 45 58 54 45 4e _OMIT_LOAD_EXTEN
2ab60 53 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 6c 69 SION. void sqli
2ab70 74 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 6f te3CloseExtensio
2ab80 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a 23 65 ns(sqlite3*);.#e
2ab90 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
2aba0 69 74 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 69 ite3CloseExtensi
2abb0 6f 6e 73 28 58 29 0a 23 65 6e 64 69 66 0a 0a 23 ons(X).#endif..#
2abc0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
2abd0 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 45 0a IT_SHARED_CACHE.
2abe0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 54 61 void sqlite3Ta
2abf0 62 6c 65 4c 6f 63 6b 28 50 61 72 73 65 20 2a 2c bleLock(Parse *,
2ac00 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 2c 20 63 int, int, u8, c
2ac10 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 23 65 onst char *);.#e
2ac20 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 lse. #define sq
2ac30 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 76 lite3TableLock(v
2ac40 2c 77 2c 78 2c 79 2c 7a 29 0a 23 65 6e 64 69 66 ,w,x,y,z).#endif
2ac50 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f ..#ifdef SQLITE_
2ac60 54 45 53 54 0a 20 20 69 6e 74 20 73 71 6c 69 74 TEST. int sqlit
2ac70 65 33 55 74 66 38 54 6f 38 28 75 6e 73 69 67 6e e3Utf8To8(unsign
2ac80 65 64 20 63 68 61 72 2a 29 3b 0a 23 65 6e 64 69 ed char*);.#endi
2ac90 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 f..#ifdef SQLITE
2aca0 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 _OMIT_VIRTUALTAB
2acb0 4c 45 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c LE.# define sql
2acc0 69 74 65 33 56 74 61 62 43 6c 65 61 72 28 59 29 ite3VtabClear(Y)
2acd0 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 .# define sqlit
2ace0 65 33 56 74 61 62 53 79 6e 63 28 58 2c 59 29 20 e3VtabSync(X,Y)
2acf0 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 65 66 SQLITE_OK.# def
2ad00 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 52 ine sqlite3VtabR
2ad10 6f 6c 6c 62 61 63 6b 28 58 29 0a 23 20 20 64 65 ollback(X).# de
2ad20 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
2ad30 43 6f 6d 6d 69 74 28 58 29 0a 23 20 20 64 65 66 Commit(X).# def
2ad40 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 49 ine sqlite3VtabI
2ad50 6e 53 79 6e 63 28 64 62 29 20 30 0a 23 20 20 64 nSync(db) 0.# d
2ad60 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
2ad70 62 4c 6f 63 6b 28 58 29 0a 23 20 20 64 65 66 69 bLock(X).# defi
2ad80 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e ne sqlite3VtabUn
2ad90 6c 6f 63 6b 28 58 29 0a 23 20 20 64 65 66 69 6e lock(X).# defin
2ada0 65 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c e sqlite3VtabUnl
2adb0 6f 63 6b 4c 69 73 74 28 58 29 0a 23 20 20 64 65 ockList(X).# de
2adc0 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
2add0 53 61 76 65 70 6f 69 6e 74 28 58 2c 20 59 2c 20 Savepoint(X, Y,
2ade0 5a 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 Z) SQLITE_OK.#
2adf0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 65 define sqlite3Ge
2ae00 74 56 54 61 62 6c 65 28 58 2c 59 29 20 20 28 28 tVTable(X,Y) ((
2ae10 56 54 61 62 6c 65 2a 29 30 29 0a 23 65 6c 73 65 VTable*)0).#else
2ae20 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 . void sqlite3
2ae30 56 74 61 62 43 6c 65 61 72 28 73 71 6c 69 74 65 VtabClear(sqlite
2ae40 33 20 2a 64 62 2c 20 54 61 62 6c 65 2a 29 3b 0a 3 *db, Table*);.
2ae50 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 56 void sqlite3V
2ae60 74 61 62 44 69 73 63 6f 6e 6e 65 63 74 28 73 71 tabDisconnect(sq
2ae70 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 lite3 *db, Table
2ae80 20 2a 70 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c *p);. int sql
2ae90 69 74 65 33 56 74 61 62 53 79 6e 63 28 73 71 6c ite3VtabSync(sql
2aea0 69 74 65 33 20 2a 64 62 2c 20 56 64 62 65 2a 29 ite3 *db, Vdbe*)
2aeb0 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 33 ;. int sqlite3
2aec0 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 73 71 6c VtabRollback(sql
2aed0 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 20 69 6e ite3 *db);. in
2aee0 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 6f 6d t sqlite3VtabCom
2aef0 6d 69 74 28 73 71 6c 69 74 65 33 20 2a 64 62 29 mit(sqlite3 *db)
2af00 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 65 ;. void sqlite
2af10 33 56 74 61 62 4c 6f 63 6b 28 56 54 61 62 6c 65 3VtabLock(VTable
2af20 20 2a 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c *);. void sql
2af30 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 28 56 ite3VtabUnlock(V
2af40 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 Table *);. voi
2af50 64 20 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c d sqlite3VtabUnl
2af60 6f 63 6b 4c 69 73 74 28 73 71 6c 69 74 65 33 2a ockList(sqlite3*
2af70 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 74 65 );. int sqlite
2af80 33 56 74 61 62 53 61 76 65 70 6f 69 6e 74 28 73 3VtabSavepoint(s
2af90 71 6c 69 74 65 33 20 2a 2c 20 69 6e 74 2c 20 69 qlite3 *, int, i
2afa0 6e 74 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c nt);. void sql
2afb0 69 74 65 33 56 74 61 62 49 6d 70 6f 72 74 45 72 ite3VtabImportEr
2afc0 72 6d 73 67 28 56 64 62 65 2a 2c 20 73 71 6c 69 rmsg(Vdbe*, sqli
2afd0 74 65 33 5f 76 74 61 62 2a 29 3b 0a 20 20 20 56 te3_vtab*);. V
2afe0 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 33 47 65 Table *sqlite3Ge
2aff0 74 56 54 61 62 6c 65 28 73 71 6c 69 74 65 33 2a tVTable(sqlite3*
2b000 2c 20 54 61 62 6c 65 2a 29 3b 0a 23 20 20 64 65 , Table*);.# de
2b010 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
2b020 49 6e 53 79 6e 63 28 64 62 29 20 28 28 64 62 29 InSync(db) ((db)
2b030 2d 3e 6e 56 54 72 61 6e 73 3e 30 20 26 26 20 28 ->nVTrans>0 && (
2b040 64 62 29 2d 3e 61 56 54 72 61 6e 73 3d 3d 30 29 db)->aVTrans==0)
2b050 0a 23 65 6e 64 69 66 0a 69 6e 74 20 73 71 6c 69 .#endif.int sqli
2b060 74 65 33 56 74 61 62 45 70 6f 6e 79 6d 6f 75 73 te3VtabEponymous
2b070 54 61 62 6c 65 49 6e 69 74 28 50 61 72 73 65 2a TableInit(Parse*
2b080 2c 4d 6f 64 75 6c 65 2a 29 3b 0a 76 6f 69 64 20 ,Module*);.void
2b090 73 71 6c 69 74 65 33 56 74 61 62 45 70 6f 6e 79 sqlite3VtabEpony
2b0a0 6d 6f 75 73 54 61 62 6c 65 43 6c 65 61 72 28 73 mousTableClear(s
2b0b0 71 6c 69 74 65 33 2a 2c 4d 6f 64 75 6c 65 2a 29 qlite3*,Module*)
2b0c0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 ;.void sqlite3Vt
2b0d0 61 62 4d 61 6b 65 57 72 69 74 61 62 6c 65 28 50 abMakeWritable(P
2b0e0 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b 0a 76 arse*,Table*);.v
2b0f0 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 42 oid sqlite3VtabB
2b100 65 67 69 6e 50 61 72 73 65 28 50 61 72 73 65 2a eginParse(Parse*
2b110 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a , Token*, Token*
2b120 2c 20 54 6f 6b 65 6e 2a 2c 20 69 6e 74 29 3b 0a , Token*, int);.
2b130 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 void sqlite3Vtab
2b140 46 69 6e 69 73 68 50 61 72 73 65 28 50 61 72 73 FinishParse(Pars
2b150 65 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 e*, Token*);.voi
2b160 64 20 73 71 6c 69 74 65 33 56 74 61 62 41 72 67 d sqlite3VtabArg
2b170 49 6e 69 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f Init(Parse*);.vo
2b180 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 41 72 id sqlite3VtabAr
2b190 67 45 78 74 65 6e 64 28 50 61 72 73 65 2a 2c 20 gExtend(Parse*,
2b1a0 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
2b1b0 69 74 65 33 56 74 61 62 43 61 6c 6c 43 72 65 61 ite3VtabCallCrea
2b1c0 74 65 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 te(sqlite3*, int
2b1d0 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 , const char *,
2b1e0 63 68 61 72 20 2a 2a 29 3b 0a 69 6e 74 20 73 71 char **);.int sq
2b1f0 6c 69 74 65 33 56 74 61 62 43 61 6c 6c 43 6f 6e lite3VtabCallCon
2b200 6e 65 63 74 28 50 61 72 73 65 2a 2c 20 54 61 62 nect(Parse*, Tab
2b210 6c 65 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 le*);.int sqlite
2b220 33 56 74 61 62 43 61 6c 6c 44 65 73 74 72 6f 79 3VtabCallDestroy
2b230 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 (sqlite3*, int,
2b240 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 69 const char *);.i
2b250 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 42 65 nt sqlite3VtabBe
2b260 67 69 6e 28 73 71 6c 69 74 65 33 20 2a 2c 20 56 gin(sqlite3 *, V
2b270 54 61 62 6c 65 20 2a 29 3b 0a 46 75 6e 63 44 65 Table *);.FuncDe
2b280 66 20 2a 73 71 6c 69 74 65 33 56 74 61 62 4f 76 f *sqlite3VtabOv
2b290 65 72 6c 6f 61 64 46 75 6e 63 74 69 6f 6e 28 73 erloadFunction(s
2b2a0 71 6c 69 74 65 33 20 2a 2c 46 75 6e 63 44 65 66 qlite3 *,FuncDef
2b2b0 2a 2c 20 69 6e 74 20 6e 41 72 67 2c 20 45 78 70 *, int nArg, Exp
2b2c0 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 r*);.void sqlite
2b2d0 33 49 6e 76 61 6c 69 64 46 75 6e 63 74 69 6f 6e 3InvalidFunction
2b2e0 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 (sqlite3_context
2b2f0 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 *,int,sqlite3_va
2b300 6c 75 65 2a 2a 29 3b 0a 73 71 6c 69 74 65 33 5f lue**);.sqlite3_
2b310 69 6e 74 36 34 20 73 71 6c 69 74 65 33 53 74 6d int64 sqlite3Stm
2b320 74 43 75 72 72 65 6e 74 54 69 6d 65 28 73 71 6c tCurrentTime(sql
2b330 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 29 3b 0a ite3_context*);.
2b340 69 6e 74 20 73 71 6c 69 74 65 33 56 64 62 65 50 int sqlite3VdbeP
2b350 61 72 61 6d 65 74 65 72 49 6e 64 65 78 28 56 64 arameterIndex(Vd
2b360 62 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a be*, const char*
2b370 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 , int);.int sqli
2b380 74 65 33 54 72 61 6e 73 66 65 72 42 69 6e 64 69 te3TransferBindi
2b390 6e 67 73 28 73 71 6c 69 74 65 33 5f 73 74 6d 74 ngs(sqlite3_stmt
2b3a0 20 2a 2c 20 73 71 6c 69 74 65 33 5f 73 74 6d 74 *, sqlite3_stmt
2b3b0 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 *);.void sqlite
2b3c0 33 50 61 72 73 65 72 52 65 73 65 74 28 50 61 72 3ParserReset(Par
2b3d0 73 65 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 se*);.int sqlite
2b3e0 33 52 65 70 72 65 70 61 72 65 28 56 64 62 65 2a 3Reprepare(Vdbe*
2b3f0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
2b400 78 70 72 4c 69 73 74 43 68 65 63 6b 4c 65 6e 67 xprListCheckLeng
2b410 74 68 28 50 61 72 73 65 2a 2c 20 45 78 70 72 4c th(Parse*, ExprL
2b420 69 73 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 ist*, const char
2b430 2a 29 3b 0a 43 6f 6c 6c 53 65 71 20 2a 73 71 6c *);.CollSeq *sql
2b440 69 74 65 33 42 69 6e 61 72 79 43 6f 6d 70 61 72 ite3BinaryCompar
2b450 65 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a eCollSeq(Parse *
2b460 2c 20 45 78 70 72 20 2a 2c 20 45 78 70 72 20 2a , Expr *, Expr *
2b470 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 65 );.int sqlite3Te
2b480 6d 70 49 6e 4d 65 6d 6f 72 79 28 63 6f 6e 73 74 mpInMemory(const
2b490 20 73 71 6c 69 74 65 33 2a 29 3b 0a 63 6f 6e 73 sqlite3*);.cons
2b4a0 74 20 63 68 61 72 20 2a 73 71 6c 69 74 65 33 4a t char *sqlite3J
2b4b0 6f 75 72 6e 61 6c 4d 6f 64 65 6e 61 6d 65 28 69 ournalModename(i
2b4c0 6e 74 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c nt);.#ifndef SQL
2b4d0 49 54 45 5f 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 ITE_OMIT_WAL. i
2b4e0 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 6b 70 nt sqlite3Checkp
2b4f0 6f 69 6e 74 28 73 71 6c 69 74 65 33 2a 2c 20 69 oint(sqlite3*, i
2b500 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 nt, int, int*, i
2b510 6e 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 nt*);. int sqli
2b520 74 65 33 57 61 6c 44 65 66 61 75 6c 74 48 6f 6f te3WalDefaultHoo
2b530 6b 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 2a k(void*,sqlite3*
2b540 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 69 6e 74 ,const char*,int
2b550 29 3b 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 );.#endif.#ifnde
2b560 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 43 54 f SQLITE_OMIT_CT
2b570 45 0a 20 20 57 69 74 68 20 2a 73 71 6c 69 74 65 E. With *sqlite
2b580 33 57 69 74 68 41 64 64 28 50 61 72 73 65 2a 2c 3WithAdd(Parse*,
2b590 57 69 74 68 2a 2c 54 6f 6b 65 6e 2a 2c 45 78 70 With*,Token*,Exp
2b5a0 72 4c 69 73 74 2a 2c 53 65 6c 65 63 74 2a 29 3b rList*,Select*);
2b5b0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 57 . void sqlite3W
2b5c0 69 74 68 44 65 6c 65 74 65 28 73 71 6c 69 74 65 ithDelete(sqlite
2b5d0 33 2a 2c 57 69 74 68 2a 29 3b 0a 20 20 76 6f 69 3*,With*);. voi
2b5e0 64 20 73 71 6c 69 74 65 33 57 69 74 68 50 75 73 d sqlite3WithPus
2b5f0 68 28 50 61 72 73 65 2a 2c 20 57 69 74 68 2a 2c h(Parse*, With*,
2b600 20 75 38 29 3b 0a 23 65 6c 73 65 0a 23 64 65 66 u8);.#else.#def
2b610 69 6e 65 20 73 71 6c 69 74 65 33 57 69 74 68 50 ine sqlite3WithP
2b620 75 73 68 28 78 2c 79 2c 7a 29 0a 23 64 65 66 69 ush(x,y,z).#defi
2b630 6e 65 20 73 71 6c 69 74 65 33 57 69 74 68 44 65 ne sqlite3WithDe
2b640 6c 65 74 65 28 78 2c 79 29 0a 23 65 6e 64 69 66 lete(x,y).#endif
2b650 0a 0a 2f 2a 20 44 65 63 6c 61 72 61 74 69 6f 6e ../* Declaration
2b660 73 20 66 6f 72 20 66 75 6e 63 74 69 6f 6e 73 20 s for functions
2b670 69 6e 20 66 6b 65 79 2e 63 2e 20 41 6c 6c 20 6f in fkey.c. All o
2b680 66 20 74 68 65 73 65 20 61 72 65 20 72 65 70 6c f these are repl
2b690 61 63 65 64 20 62 79 0a 2a 2a 20 6e 6f 2d 6f 70 aced by.** no-op
2b6a0 20 6d 61 63 72 6f 73 20 69 66 20 4f 4d 49 54 5f macros if OMIT_
2b6b0 46 4f 52 45 49 47 4e 5f 4b 45 59 20 69 73 20 64 FOREIGN_KEY is d
2b6c0 65 66 69 6e 65 64 2e 20 49 6e 20 74 68 69 73 20 efined. In this
2b6d0 63 61 73 65 20 6e 6f 20 66 6f 72 65 69 67 6e 0a case no foreign.
2b6e0 2a 2a 20 6b 65 79 20 66 75 6e 63 74 69 6f 6e 61 ** key functiona
2b6f0 6c 69 74 79 20 69 73 20 61 76 61 69 6c 61 62 6c lity is availabl
2b700 65 2e 20 49 66 20 4f 4d 49 54 5f 54 52 49 47 47 e. If OMIT_TRIGG
2b710 45 52 20 69 73 20 64 65 66 69 6e 65 64 20 62 75 ER is defined bu
2b720 74 0a 2a 2a 20 4f 4d 49 54 5f 46 4f 52 45 49 47 t.** OMIT_FOREIG
2b730 4e 5f 4b 45 59 20 69 73 20 6e 6f 74 2c 20 6f 6e N_KEY is not, on
2b740 6c 79 20 73 6f 6d 65 20 6f 66 20 74 68 65 20 66 ly some of the f
2b750 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6e 6f 2d unctions are no-
2b760 6f 70 65 64 2e 20 49 6e 0a 2a 2a 20 74 68 69 73 oped. In.** this
2b770 20 63 61 73 65 20 66 6f 72 65 69 67 6e 20 6b 65 case foreign ke
2b780 79 73 20 61 72 65 20 70 61 72 73 65 64 2c 20 62 ys are parsed, b
2b790 75 74 20 6e 6f 20 6f 74 68 65 72 20 66 75 6e 63 ut no other func
2b7a0 74 69 6f 6e 61 6c 69 74 79 20 69 73 0a 2a 2a 20 tionality is.**
2b7b0 70 72 6f 76 69 64 65 64 20 28 65 6e 66 6f 72 63 provided (enforc
2b7c0 65 6d 65 6e 74 20 6f 66 20 46 4b 20 63 6f 6e 73 ement of FK cons
2b7d0 74 72 61 69 6e 74 73 20 72 65 71 75 69 72 65 73 traints requires
2b7e0 20 74 68 65 20 74 72 69 67 67 65 72 73 20 73 75 the triggers su
2b7f0 62 2d 73 79 73 74 65 6d 29 2e 0a 2a 2f 0a 23 69 b-system)..*/.#i
2b800 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 f !defined(SQLIT
2b810 45 5f 4f 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b E_OMIT_FOREIGN_K
2b820 45 59 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 EY) && !defined(
2b830 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 54 52 49 47 SQLITE_OMIT_TRIG
2b840 47 45 52 29 0a 20 20 76 6f 69 64 20 73 71 6c 69 GER). void sqli
2b850 74 65 33 46 6b 43 68 65 63 6b 28 50 61 72 73 65 te3FkCheck(Parse
2b860 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 *, Table*, int,
2b870 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b int, int*, int);
2b880 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 . void sqlite3F
2b890 6b 44 72 6f 70 54 61 62 6c 65 28 50 61 72 73 65 kDropTable(Parse
2b8a0 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 54 61 *, SrcList *, Ta
2b8b0 62 6c 65 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 ble*);. void sq
2b8c0 6c 69 74 65 33 46 6b 41 63 74 69 6f 6e 73 28 50 lite3FkActions(P
2b8d0 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 arse*, Table*, E
2b8e0 78 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 xprList*, int, i
2b8f0 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 69 6e 74 nt*, int);. int
2b900 20 73 71 6c 69 74 65 33 46 6b 52 65 71 75 69 72 sqlite3FkRequir
2b910 65 64 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 ed(Parse*, Table
2b920 2a 2c 20 69 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 *, int*, int);.
2b930 20 75 33 32 20 73 71 6c 69 74 65 33 46 6b 4f 6c u32 sqlite3FkOl
2b940 64 6d 61 73 6b 28 50 61 72 73 65 2a 2c 20 54 61 dmask(Parse*, Ta
2b950 62 6c 65 2a 29 3b 0a 20 20 46 4b 65 79 20 2a 73 ble*);. FKey *s
2b960 71 6c 69 74 65 33 46 6b 52 65 66 65 72 65 6e 63 qlite3FkReferenc
2b970 65 73 28 54 61 62 6c 65 20 2a 29 3b 0a 23 65 6c es(Table *);.#el
2b980 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c se. #define sql
2b990 69 74 65 33 46 6b 41 63 74 69 6f 6e 73 28 61 2c ite3FkActions(a,
2b9a0 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 20 23 64 65 b,c,d,e,f). #de
2b9b0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 43 68 fine sqlite3FkCh
2b9c0 65 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 2c 66 29 eck(a,b,c,d,e,f)
2b9d0 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
2b9e0 65 33 46 6b 44 72 6f 70 54 61 62 6c 65 28 61 2c e3FkDropTable(a,
2b9f0 62 2c 63 29 0a 20 20 23 64 65 66 69 6e 65 20 73 b,c). #define s
2ba00 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 qlite3FkOldmask(
2ba10 61 2c 62 29 20 20 20 20 20 20 20 20 20 30 0a 20 a,b) 0.
2ba20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2ba30 46 6b 52 65 71 75 69 72 65 64 28 61 2c 62 2c 63 FkRequired(a,b,c
2ba40 2c 64 29 20 20 20 20 30 0a 23 65 6e 64 69 66 0a ,d) 0.#endif.
2ba50 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
2ba60 4d 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 0a MIT_FOREIGN_KEY.
2ba70 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b void sqlite3Fk
2ba80 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 20 2a Delete(sqlite3 *
2ba90 2c 20 54 61 62 6c 65 2a 29 3b 0a 20 20 69 6e 74 , Table*);. int
2baa0 20 73 71 6c 69 74 65 33 46 6b 4c 6f 63 61 74 65 sqlite3FkLocate
2bab0 49 6e 64 65 78 28 50 61 72 73 65 2a 2c 54 61 62 Index(Parse*,Tab
2bac0 6c 65 2a 2c 46 4b 65 79 2a 2c 49 6e 64 65 78 2a le*,FKey*,Index*
2bad0 2a 2c 69 6e 74 2a 2a 29 3b 0a 23 65 6c 73 65 0a *,int**);.#else.
2bae0 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 #define sqlite
2baf0 33 46 6b 44 65 6c 65 74 65 28 61 2c 62 29 0a 20 3FkDelete(a,b).
2bb00 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2bb10 46 6b 4c 6f 63 61 74 65 49 6e 64 65 78 28 61 2c FkLocateIndex(a,
2bb20 62 2c 63 2c 64 2c 65 29 0a 23 65 6e 64 69 66 0a b,c,d,e).#endif.
2bb30 0a 0a 2f 2a 0a 2a 2a 20 41 76 61 69 6c 61 62 6c ../*.** Availabl
2bb40 65 20 66 61 75 6c 74 20 69 6e 6a 65 63 74 6f 72 e fault injector
2bb50 73 2e 20 20 53 68 6f 75 6c 64 20 62 65 20 6e 75 s. Should be nu
2bb60 6d 62 65 72 65 64 20 62 65 67 69 6e 6e 69 6e 67 mbered beginning
2bb70 20 77 69 74 68 20 30 2e 0a 2a 2f 0a 23 64 65 66 with 0..*/.#def
2bb80 69 6e 65 20 53 51 4c 49 54 45 5f 46 41 55 4c 54 ine SQLITE_FAULT
2bb90 49 4e 4a 45 43 54 4f 52 5f 4d 41 4c 4c 4f 43 20 INJECTOR_MALLOC
2bba0 20 20 20 20 30 0a 23 64 65 66 69 6e 65 20 53 51 0.#define SQ
2bbb0 4c 49 54 45 5f 46 41 55 4c 54 49 4e 4a 45 43 54 LITE_FAULTINJECT
2bbc0 4f 52 5f 43 4f 55 4e 54 20 20 20 20 20 20 31 0a OR_COUNT 1.
2bbd0 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 72 ./*.** The inter
2bbe0 66 61 63 65 20 74 6f 20 74 68 65 20 63 6f 64 65 face to the code
2bbf0 20 69 6e 20 66 61 75 6c 74 2e 63 20 75 73 65 64 in fault.c used
2bc00 20 66 6f 72 20 69 64 65 6e 74 69 66 79 69 6e 67 for identifying
2bc10 20 22 62 65 6e 69 67 6e 22 0a 2a 2a 20 6d 61 6c "benign".** mal
2bc20 6c 6f 63 20 66 61 69 6c 75 72 65 73 2e 20 54 68 loc failures. Th
2bc30 69 73 20 69 73 20 6f 6e 6c 79 20 70 72 65 73 65 is is only prese
2bc40 6e 74 20 69 66 20 53 51 4c 49 54 45 5f 55 4e 54 nt if SQLITE_UNT
2bc50 45 53 54 41 42 4c 45 0a 2a 2a 20 69 73 20 6e 6f ESTABLE.** is no
2bc60 74 20 64 65 66 69 6e 65 64 2e 0a 2a 2f 0a 23 69 t defined..*/.#i
2bc70 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 55 4e 54 fndef SQLITE_UNT
2bc80 45 53 54 41 42 4c 45 0a 20 20 76 6f 69 64 20 73 ESTABLE. void s
2bc90 71 6c 69 74 65 33 42 65 67 69 6e 42 65 6e 69 67 qlite3BeginBenig
2bca0 6e 4d 61 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a 20 nMalloc(void);.
2bcb0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 45 6e 64 void sqlite3End
2bcc0 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 76 6f 69 BenignMalloc(voi
2bcd0 64 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 d);.#else. #def
2bce0 69 6e 65 20 73 71 6c 69 74 65 33 42 65 67 69 6e ine sqlite3Begin
2bcf0 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 29 0a 20 BenignMalloc().
2bd00 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
2bd10 45 6e 64 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 EndBenignMalloc(
2bd20 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
2bd30 41 6c 6c 6f 77 65 64 20 72 65 74 75 72 6e 20 76 Allowed return v
2bd40 61 6c 75 65 73 20 66 72 6f 6d 20 73 71 6c 69 74 alues from sqlit
2bd50 65 33 46 69 6e 64 49 6e 49 6e 64 65 78 28 29 0a e3FindInIndex().
2bd60 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e */.#define IN_IN
2bd70 44 45 58 5f 52 4f 57 49 44 20 20 20 20 20 20 20 DEX_ROWID
2bd80 20 31 20 20 20 2f 2a 20 53 65 61 72 63 68 20 74 1 /* Search t
2bd90 68 65 20 72 6f 77 69 64 20 6f 66 20 74 68 65 20 he rowid of the
2bda0 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 table */.#define
2bdb0 20 49 4e 5f 49 4e 44 45 58 5f 45 50 48 20 20 20 IN_INDEX_EPH
2bdc0 20 20 20 20 20 20 20 32 20 20 20 2f 2a 20 53 65 2 /* Se
2bdd0 61 72 63 68 20 61 6e 20 65 70 68 65 6d 65 72 61 arch an ephemera
2bde0 6c 20 62 2d 74 72 65 65 20 2a 2f 0a 23 64 65 66 l b-tree */.#def
2bdf0 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 49 4e 44 ine IN_INDEX_IND
2be00 45 58 5f 41 53 43 20 20 20 20 33 20 20 20 2f 2a EX_ASC 3 /*
2be10 20 45 78 69 73 74 69 6e 67 20 69 6e 64 65 78 20 Existing index
2be20 41 53 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 64 65 ASCENDING */.#de
2be30 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 49 4e fine IN_INDEX_IN
2be40 44 45 58 5f 44 45 53 43 20 20 20 34 20 20 20 2f DEX_DESC 4 /
2be50 2a 20 45 78 69 73 74 69 6e 67 20 69 6e 64 65 78 * Existing index
2be60 20 44 45 53 43 45 4e 44 49 4e 47 20 2a 2f 0a 23 DESCENDING */.#
2be70 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
2be80 4e 4f 4f 50 20 20 20 20 20 20 20 20 20 35 20 20 NOOP 5
2be90 20 2f 2a 20 4e 6f 20 74 61 62 6c 65 20 61 76 61 /* No table ava
2bea0 69 6c 61 62 6c 65 2e 20 55 73 65 20 63 6f 6d 70 ilable. Use comp
2beb0 61 72 69 73 6f 6e 73 20 2a 2f 0a 2f 2a 0a 2a 2a arisons */./*.**
2bec0 20 41 6c 6c 6f 77 65 64 20 66 6c 61 67 73 20 66 Allowed flags f
2bed0 6f 72 20 74 68 65 20 33 72 64 20 70 61 72 61 6d or the 3rd param
2bee0 65 74 65 72 20 74 6f 20 73 71 6c 69 74 65 33 46 eter to sqlite3F
2bef0 69 6e 64 49 6e 49 6e 64 65 78 28 29 2e 0a 2a 2f indInIndex()..*/
2bf00 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 .#define IN_INDE
2bf10 58 5f 4e 4f 4f 50 5f 4f 4b 20 20 20 20 20 30 78 X_NOOP_OK 0x
2bf20 30 30 30 31 20 20 2f 2a 20 4f 4b 20 74 6f 20 72 0001 /* OK to r
2bf30 65 74 75 72 6e 20 49 4e 5f 49 4e 44 45 58 5f 4e eturn IN_INDEX_N
2bf40 4f 4f 50 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 OOP */.#define I
2bf50 4e 5f 49 4e 44 45 58 5f 4d 45 4d 42 45 52 53 48 N_INDEX_MEMBERSH
2bf60 49 50 20 20 30 78 30 30 30 32 20 20 2f 2a 20 49 IP 0x0002 /* I
2bf70 4e 20 6f 70 65 72 61 74 6f 72 20 75 73 65 64 20 N operator used
2bf80 66 6f 72 20 6d 65 6d 62 65 72 73 68 69 70 20 74 for membership t
2bf90 65 73 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 est */.#define I
2bfa0 4e 5f 49 4e 44 45 58 5f 4c 4f 4f 50 20 20 20 20 N_INDEX_LOOP
2bfb0 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 49 0x0004 /* I
2bfc0 4e 20 6f 70 65 72 61 74 6f 72 20 75 73 65 64 20 N operator used
2bfd0 61 73 20 61 20 6c 6f 6f 70 20 2a 2f 0a 69 6e 74 as a loop */.int
2bfe0 20 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e sqlite3FindInIn
2bff0 64 65 78 28 50 61 72 73 65 20 2a 2c 20 45 78 70 dex(Parse *, Exp
2c000 72 20 2a 2c 20 75 33 32 2c 20 69 6e 74 2a 2c 20 r *, u32, int*,
2c010 69 6e 74 2a 29 3b 0a 0a 69 6e 74 20 73 71 6c 69 int*);..int sqli
2c020 74 65 33 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 te3JournalOpen(s
2c030 71 6c 69 74 65 33 5f 76 66 73 20 2a 2c 20 63 6f qlite3_vfs *, co
2c040 6e 73 74 20 63 68 61 72 20 2a 2c 20 73 71 6c 69 nst char *, sqli
2c050 74 65 33 5f 66 69 6c 65 20 2a 2c 20 69 6e 74 2c te3_file *, int,
2c060 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 int);.int sqlit
2c070 65 33 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 73 71 e3JournalSize(sq
2c080 6c 69 74 65 33 5f 76 66 73 20 2a 29 3b 0a 23 69 lite3_vfs *);.#i
2c090 66 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 fdef SQLITE_ENAB
2c0a0 4c 45 5f 41 54 4f 4d 49 43 5f 57 52 49 54 45 0a LE_ATOMIC_WRITE.
2c0b0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 int sqlite3Jou
2c0c0 72 6e 61 6c 43 72 65 61 74 65 28 73 71 6c 69 74 rnalCreate(sqlit
2c0d0 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 23 65 6e 64 e3_file *);.#end
2c0e0 69 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 33 4a if..int sqlite3J
2c0f0 6f 75 72 6e 61 6c 49 73 49 6e 4d 65 6d 6f 72 79 ournalIsInMemory
2c100 28 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a 70 (sqlite3_file *p
2c110 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d );.void sqlite3M
2c120 65 6d 4a 6f 75 72 6e 61 6c 4f 70 65 6e 28 73 71 emJournalOpen(sq
2c130 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 0a lite3_file *);..
2c140 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
2c150 53 65 74 48 65 69 67 68 74 41 6e 64 46 6c 61 67 SetHeightAndFlag
2c160 73 28 50 61 72 73 65 20 2a 70 50 61 72 73 65 2c s(Parse *pParse,
2c170 20 45 78 70 72 20 2a 70 29 3b 0a 23 69 66 20 53 Expr *p);.#if S
2c180 51 4c 49 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 QLITE_MAX_EXPR_D
2c190 45 50 54 48 3e 30 0a 20 20 69 6e 74 20 73 71 6c EPTH>0. int sql
2c1a0 69 74 65 33 53 65 6c 65 63 74 45 78 70 72 48 65 ite3SelectExprHe
2c1b0 69 67 68 74 28 53 65 6c 65 63 74 20 2a 29 3b 0a ight(Select *);.
2c1c0 20 20 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 int sqlite3Exp
2c1d0 72 43 68 65 63 6b 48 65 69 67 68 74 28 50 61 72 rCheckHeight(Par
2c1e0 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 65 6c 73 65 se*, int);.#else
2c1f0 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 . #define sqlit
2c200 65 33 53 65 6c 65 63 74 45 78 70 72 48 65 69 67 e3SelectExprHeig
2c210 68 74 28 78 29 20 30 0a 20 20 23 64 65 66 69 6e ht(x) 0. #defin
2c220 65 20 73 71 6c 69 74 65 33 45 78 70 72 43 68 65 e sqlite3ExprChe
2c230 63 6b 48 65 69 67 68 74 28 78 2c 79 29 0a 23 65 ckHeight(x,y).#e
2c240 6e 64 69 66 0a 0a 75 33 32 20 73 71 6c 69 74 65 ndif..u32 sqlite
2c250 33 47 65 74 34 62 79 74 65 28 63 6f 6e 73 74 20 3Get4byte(const
2c260 75 38 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 u8*);.void sqlit
2c270 65 33 50 75 74 34 62 79 74 65 28 75 38 2a 2c 20 e3Put4byte(u8*,
2c280 75 33 32 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 u32);..#ifdef SQ
2c290 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f LITE_ENABLE_UNLO
2c2a0 43 4b 5f 4e 4f 54 49 46 59 0a 20 20 76 6f 69 64 CK_NOTIFY. void
2c2b0 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 sqlite3Connecti
2c2c0 6f 6e 42 6c 6f 63 6b 65 64 28 73 71 6c 69 74 65 onBlocked(sqlite
2c2d0 33 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a 29 3b 3 *, sqlite3 *);
2c2e0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
2c2f0 6f 6e 6e 65 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 onnectionUnlocke
2c300 64 28 73 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a d(sqlite3 *db);.
2c310 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f void sqlite3Co
2c320 6e 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 73 nnectionClosed(s
2c330 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 23 65 6c qlite3 *db);.#el
2c340 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c se. #define sql
2c350 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c ite3ConnectionBl
2c360 6f 63 6b 65 64 28 78 2c 79 29 0a 20 20 23 64 65 ocked(x,y). #de
2c370 66 69 6e 65 20 73 71 6c 69 74 65 33 43 6f 6e 6e fine sqlite3Conn
2c380 65 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 78 ectionUnlocked(x
2c390 29 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 ). #define sqli
2c3a0 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 43 6c 6f te3ConnectionClo
2c3b0 73 65 64 28 78 29 0a 23 65 6e 64 69 66 0a 0a 23 sed(x).#endif..#
2c3c0 69 66 64 65 66 20 53 51 4c 49 54 45 5f 44 45 42 ifdef SQLITE_DEB
2c3d0 55 47 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 UG. void sqlite
2c3e0 33 50 61 72 73 65 72 54 72 61 63 65 28 46 49 4c 3ParserTrace(FIL
2c3f0 45 2a 2c 20 63 68 61 72 20 2a 29 3b 0a 23 65 6e E*, char *);.#en
2c400 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 74 68 dif../*.** If th
2c410 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 20 e SQLITE_ENABLE
2c420 49 4f 54 52 41 43 45 20 65 78 69 73 74 73 20 74 IOTRACE exists t
2c430 68 65 6e 20 74 68 65 20 67 6c 6f 62 61 6c 20 76 hen the global v
2c440 61 72 69 61 62 6c 65 0a 2a 2a 20 73 71 6c 69 74 ariable.** sqlit
2c450 65 33 49 6f 54 72 61 63 65 20 69 73 20 61 20 70 e3IoTrace is a p
2c460 6f 69 6e 74 65 72 20 74 6f 20 61 20 70 72 69 6e ointer to a prin
2c470 74 66 2d 6c 69 6b 65 20 72 6f 75 74 69 6e 65 20 tf-like routine
2c480 75 73 65 64 20 74 6f 0a 2a 2a 20 70 72 69 6e 74 used to.** print
2c490 20 49 2f 4f 20 74 72 61 63 69 6e 67 20 6d 65 73 I/O tracing mes
2c4a0 73 61 67 65 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 sages..*/.#ifdef
2c4b0 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 49 SQLITE_ENABLE_I
2c4c0 4f 54 52 41 43 45 0a 23 20 64 65 66 69 6e 65 20 OTRACE.# define
2c4d0 49 4f 54 52 41 43 45 28 41 29 20 20 69 66 28 20 IOTRACE(A) if(
2c4e0 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 20 29 sqlite3IoTrace )
2c4f0 7b 20 73 71 6c 69 74 65 33 49 6f 54 72 61 63 65 { sqlite3IoTrace
2c500 20 41 3b 20 7d 0a 20 20 76 6f 69 64 20 73 71 6c A; }. void sql
2c510 69 74 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 ite3VdbeIOTraceS
2c520 71 6c 28 56 64 62 65 2a 29 3b 0a 53 51 4c 49 54 ql(Vdbe*);.SQLIT
2c530 45 5f 41 50 49 20 53 51 4c 49 54 45 5f 45 58 54 E_API SQLITE_EXT
2c540 45 52 4e 20 76 6f 69 64 20 28 53 51 4c 49 54 45 ERN void (SQLITE
2c550 5f 43 44 45 43 4c 20 2a 73 71 6c 69 74 65 33 49 _CDECL *sqlite3I
2c560 6f 54 72 61 63 65 29 28 63 6f 6e 73 74 20 63 68 oTrace)(const ch
2c570 61 72 2a 2c 2e 2e 2e 29 3b 0a 23 65 6c 73 65 0a ar*,...);.#else.
2c580 23 20 64 65 66 69 6e 65 20 49 4f 54 52 41 43 45 # define IOTRACE
2c590 28 41 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c (A).# define sql
2c5a0 69 74 65 33 56 64 62 65 49 4f 54 72 61 63 65 53 ite3VdbeIOTraceS
2c5b0 71 6c 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a ql(X).#endif../*
2c5c0 0a 2a 2a 20 54 68 65 73 65 20 72 6f 75 74 69 6e .** These routin
2c5d0 65 73 20 61 72 65 20 61 76 61 69 6c 61 62 6c 65 es are available
2c5e0 20 66 6f 72 20 74 68 65 20 6d 65 6d 32 2e 63 20 for the mem2.c
2c5f0 64 65 62 75 67 67 69 6e 67 20 6d 65 6d 6f 72 79 debugging memory
2c600 20 61 6c 6c 6f 63 61 74 6f 72 0a 2a 2a 20 6f 6e allocator.** on
2c610 6c 79 2e 20 20 54 68 65 79 20 61 72 65 20 75 73 ly. They are us
2c620 65 64 20 74 6f 20 76 65 72 69 66 79 20 74 68 61 ed to verify tha
2c630 74 20 64 69 66 66 65 72 65 6e 74 20 22 74 79 70 t different "typ
2c640 65 73 22 20 6f 66 20 6d 65 6d 6f 72 79 0a 2a 2a es" of memory.**
2c650 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 61 72 65 allocations are
2c660 20 70 72 6f 70 65 72 6c 79 20 74 72 61 63 6b 65 properly tracke
2c670 64 20 62 79 20 74 68 65 20 73 79 73 74 65 6d 2e d by the system.
2c680 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 .**.** sqlite3Me
2c690 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 29 20 mdebugSetType()
2c6a0 73 65 74 73 20 74 68 65 20 22 74 79 70 65 22 20 sets the "type"
2c6b0 6f 66 20 61 6e 20 61 6c 6c 6f 63 61 74 69 6f 6e of an allocation
2c6c0 20 74 6f 20 6f 6e 65 20 6f 66 0a 2a 2a 20 74 68 to one of.** th
2c6d0 65 20 4d 45 4d 54 59 50 45 5f 2a 20 6d 61 63 72 e MEMTYPE_* macr
2c6e0 6f 73 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 os defined below
2c6f0 2e 20 20 54 68 65 20 74 79 70 65 20 6d 75 73 74 . The type must
2c700 20 62 65 20 61 20 62 69 74 6d 61 73 6b 20 77 69 be a bitmask wi
2c710 74 68 0a 2a 2a 20 61 20 73 69 6e 67 6c 65 20 62 th.** a single b
2c720 69 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 73 71 it set..**.** sq
2c730 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 73 lite3MemdebugHas
2c740 54 79 70 65 28 29 20 72 65 74 75 72 6e 73 20 74 Type() returns t
2c750 72 75 65 20 69 66 20 61 6e 79 20 6f 66 20 74 68 rue if any of th
2c760 65 20 62 69 74 73 20 69 6e 20 69 74 73 20 73 65 e bits in its se
2c770 63 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 6e 74 cond.** argument
2c780 20 6d 61 74 63 68 20 74 68 65 20 74 79 70 65 20 match the type
2c790 73 65 74 20 62 79 20 74 68 65 20 70 72 65 76 69 set by the previ
2c7a0 6f 75 73 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 ous sqlite3Memde
2c7b0 62 75 67 53 65 74 54 79 70 65 28 29 2e 0a 2a 2a bugSetType()..**
2c7c0 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 sqlite3Memdebug
2c7d0 48 61 73 54 79 70 65 28 29 20 69 73 20 69 6e 74 HasType() is int
2c7e0 65 6e 64 65 64 20 66 6f 72 20 75 73 65 20 69 6e ended for use in
2c7f0 73 69 64 65 20 61 73 73 65 72 74 28 29 20 73 74 side assert() st
2c800 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 atements..**.**
2c810 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 4e sqlite3MemdebugN
2c820 6f 54 79 70 65 28 29 20 72 65 74 75 72 6e 73 20 oType() returns
2c830 74 72 75 65 20 69 66 20 6e 6f 6e 65 20 6f 66 20 true if none of
2c840 74 68 65 20 62 69 74 73 20 69 6e 20 69 74 73 20 the bits in its
2c850 73 65 63 6f 6e 64 0a 2a 2a 20 61 72 67 75 6d 65 second.** argume
2c860 6e 74 20 6d 61 74 63 68 20 74 68 65 20 74 79 70 nt match the typ
2c870 65 20 73 65 74 20 62 79 20 74 68 65 20 70 72 65 e set by the pre
2c880 76 69 6f 75 73 20 73 71 6c 69 74 65 33 4d 65 6d vious sqlite3Mem
2c890 64 65 62 75 67 53 65 74 54 79 70 65 28 29 2e 0a debugSetType()..
2c8a0 2a 2a 0a 2a 2a 20 50 65 72 68 61 70 73 20 74 68 **.** Perhaps th
2c8b0 65 20 6d 6f 73 74 20 69 6d 70 6f 72 74 61 6e 74 e most important
2c8c0 20 70 6f 69 6e 74 20 69 73 20 74 68 65 20 64 69 point is the di
2c8d0 66 66 65 72 65 6e 63 65 20 62 65 74 77 65 65 6e fference between
2c8e0 20 4d 45 4d 54 59 50 45 5f 48 45 41 50 0a 2a 2a MEMTYPE_HEAP.**
2c8f0 20 61 6e 64 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f and MEMTYPE_LOO
2c900 4b 41 53 49 44 45 2e 20 20 49 66 20 61 6e 20 61 KASIDE. If an a
2c910 6c 6c 6f 63 61 74 69 6f 6e 20 69 73 20 4d 45 4d llocation is MEM
2c920 54 59 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 2c 20 TYPE_LOOKASIDE,
2c930 74 68 61 74 20 6d 65 61 6e 73 0a 2a 2a 20 69 74 that means.** it
2c940 20 6d 69 67 68 74 20 68 61 76 65 20 62 65 65 6e might have been
2c950 20 61 6c 6c 6f 63 61 74 65 64 20 62 79 20 6c 6f allocated by lo
2c960 6f 6b 61 73 69 64 65 2c 20 65 78 63 65 70 74 20 okaside, except
2c970 74 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 77 the allocation w
2c980 61 73 0a 2a 2a 20 74 6f 6f 20 6c 61 72 67 65 20 as.** too large
2c990 6f 72 20 6c 6f 6f 6b 61 73 69 64 65 20 77 61 73 or lookaside was
2c9a0 20 61 6c 72 65 61 64 79 20 66 75 6c 6c 2e 20 20 already full.
2c9b0 49 74 20 69 73 20 69 6d 70 6f 72 74 61 6e 74 20 It is important
2c9c0 74 6f 20 76 65 72 69 66 79 0a 2a 2a 20 74 68 61 to verify.** tha
2c9d0 74 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 74 68 t allocations th
2c9e0 61 74 20 6d 69 67 68 74 20 68 61 76 65 20 62 65 at might have be
2c9f0 65 6e 20 73 61 74 69 73 66 69 65 64 20 62 79 20 en satisfied by
2ca00 6c 6f 6f 6b 61 73 69 64 65 20 61 72 65 20 6e 6f lookaside are no
2ca10 74 0a 2a 2a 20 70 61 73 73 65 64 20 62 61 63 6b t.** passed back
2ca20 20 74 6f 20 6e 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 to non-lookasid
2ca30 65 20 66 72 65 65 28 29 20 72 6f 75 74 69 6e 65 e free() routine
2ca40 73 2e 20 20 41 73 73 65 72 74 73 20 73 75 63 68 s. Asserts such
2ca50 20 61 73 20 74 68 65 0a 2a 2a 20 65 78 61 6d 70 as the.** examp
2ca60 6c 65 20 61 62 6f 76 65 20 61 72 65 20 70 6c 61 le above are pla
2ca70 63 65 64 20 6f 6e 20 74 68 65 20 6e 6f 6e 2d 6c ced on the non-l
2ca80 6f 6f 6b 61 73 69 64 65 20 66 72 65 65 28 29 20 ookaside free()
2ca90 72 6f 75 74 69 6e 65 73 20 74 6f 20 76 65 72 69 routines to veri
2caa0 66 79 0a 2a 2a 20 74 68 69 73 20 63 6f 6e 73 74 fy.** this const
2cab0 72 61 69 6e 74 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c raint..**.** All
2cac0 20 6f 66 20 74 68 69 73 20 69 73 20 6e 6f 2d 6f of this is no-o
2cad0 70 20 66 6f 72 20 61 20 70 72 6f 64 75 63 74 69 p for a producti
2cae0 6f 6e 20 62 75 69 6c 64 2e 20 20 49 74 20 6f 6e on build. It on
2caf0 6c 79 20 63 6f 6d 65 73 20 69 6e 74 6f 0a 2a 2a ly comes into.**
2cb00 20 70 6c 61 79 20 77 68 65 6e 20 74 68 65 20 53 play when the S
2cb10 51 4c 49 54 45 5f 4d 45 4d 44 45 42 55 47 20 63 QLITE_MEMDEBUG c
2cb20 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 6f 70 74 69 ompile-time opti
2cb30 6f 6e 20 69 73 20 75 73 65 64 2e 0a 2a 2f 0a 23 on is used..*/.#
2cb40 69 66 64 65 66 20 53 51 4c 49 54 45 5f 4d 45 4d ifdef SQLITE_MEM
2cb50 44 45 42 55 47 0a 20 20 76 6f 69 64 20 73 71 6c DEBUG. void sql
2cb60 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 ite3MemdebugSetT
2cb70 79 70 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 ype(void*,u8);.
2cb80 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 64 int sqlite3Memd
2cb90 65 62 75 67 48 61 73 54 79 70 65 28 76 6f 69 64 ebugHasType(void
2cba0 2a 2c 75 38 29 3b 0a 20 20 69 6e 74 20 73 71 6c *,u8);. int sql
2cbb0 69 74 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 ite3MemdebugNoTy
2cbc0 70 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 23 65 pe(void*,u8);.#e
2cbd0 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
2cbe0 69 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 ite3MemdebugSetT
2cbf0 79 70 65 28 58 2c 59 29 20 20 2f 2a 20 6e 6f 2d ype(X,Y) /* no-
2cc00 6f 70 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 73 op */.# define s
2cc10 71 6c 69 74 65 33 4d 65 6d 64 65 62 75 67 48 61 qlite3MemdebugHa
2cc20 73 54 79 70 65 28 58 2c 59 29 20 20 31 0a 23 20 sType(X,Y) 1.#
2cc30 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 define sqlite3Me
2cc40 6d 64 65 62 75 67 4e 6f 54 79 70 65 28 58 2c 59 mdebugNoType(X,Y
2cc50 29 20 20 20 31 0a 23 65 6e 64 69 66 0a 23 64 65 ) 1.#endif.#de
2cc60 66 69 6e 65 20 4d 45 4d 54 59 50 45 5f 48 45 41 fine MEMTYPE_HEA
2cc70 50 20 20 20 20 20 20 20 30 78 30 31 20 20 2f 2a P 0x01 /*
2cc80 20 47 65 6e 65 72 61 6c 20 68 65 61 70 20 61 6c General heap al
2cc90 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 23 64 65 locations */.#de
2cca0 66 69 6e 65 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f fine MEMTYPE_LOO
2ccb0 4b 41 53 49 44 45 20 20 30 78 30 32 20 20 2f 2a KASIDE 0x02 /*
2ccc0 20 48 65 61 70 20 74 68 61 74 20 6d 69 67 68 74 Heap that might
2ccd0 20 68 61 76 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 have been looka
2cce0 73 69 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 side */.#define
2ccf0 4d 45 4d 54 59 50 45 5f 53 43 52 41 54 43 48 20 MEMTYPE_SCRATCH
2cd00 20 20 20 30 78 30 34 20 20 2f 2a 20 53 63 72 61 0x04 /* Scra
2cd10 74 63 68 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 tch allocations
2cd20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 */.#define MEMTY
2cd30 50 45 5f 50 43 41 43 48 45 20 20 20 20 20 30 78 PE_PCACHE 0x
2cd40 30 38 20 20 2f 2a 20 50 61 67 65 20 63 61 63 68 08 /* Page cach
2cd50 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f e allocations */
2cd60 0a 0a 2f 2a 0a 2a 2a 20 54 68 72 65 61 64 69 6e ../*.** Threadin
2cd70 67 20 69 6e 74 65 72 66 61 63 65 0a 2a 2f 0a 23 g interface.*/.#
2cd80 69 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 57 4f if SQLITE_MAX_WO
2cd90 52 4b 45 52 5f 54 48 52 45 41 44 53 3e 30 0a 69 RKER_THREADS>0.i
2cda0 6e 74 20 73 71 6c 69 74 65 33 54 68 72 65 61 64 nt sqlite3Thread
2cdb0 43 72 65 61 74 65 28 53 51 4c 69 74 65 54 68 72 Create(SQLiteThr
2cdc0 65 61 64 2a 2a 2c 76 6f 69 64 2a 28 2a 29 28 76 ead**,void*(*)(v
2cdd0 6f 69 64 2a 29 2c 76 6f 69 64 2a 29 3b 0a 69 6e oid*),void*);.in
2cde0 74 20 73 71 6c 69 74 65 33 54 68 72 65 61 64 4a t sqlite3ThreadJ
2cdf0 6f 69 6e 28 53 51 4c 69 74 65 54 68 72 65 61 64 oin(SQLiteThread
2ce00 2a 2c 20 76 6f 69 64 2a 2a 29 3b 0a 23 65 6e 64 *, void**);.#end
2ce10 69 66 0a 0a 23 69 66 20 64 65 66 69 6e 65 64 28 if..#if defined(
2ce20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 44 42 SQLITE_ENABLE_DB
2ce30 53 54 41 54 5f 56 54 41 42 29 20 7c 7c 20 64 65 STAT_VTAB) || de
2ce40 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 53 fined(SQLITE_TES
2ce50 54 29 0a 69 6e 74 20 73 71 6c 69 74 65 33 44 62 T).int sqlite3Db
2ce60 73 74 61 74 52 65 67 69 73 74 65 72 28 73 71 6c statRegister(sql
2ce70 69 74 65 33 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a ite3*);.#endif..
2ce80 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 56 int sqlite3ExprV
2ce90 65 63 74 6f 72 53 69 7a 65 28 45 78 70 72 20 2a ectorSize(Expr *
2cea0 70 45 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 pExpr);.int sqli
2ceb0 74 65 33 45 78 70 72 49 73 56 65 63 74 6f 72 28 te3ExprIsVector(
2cec0 45 78 70 72 20 2a 70 45 78 70 72 29 3b 0a 45 78 Expr *pExpr);.Ex
2ced0 70 72 20 2a 73 71 6c 69 74 65 33 56 65 63 74 6f pr *sqlite3Vecto
2cee0 72 46 69 65 6c 64 53 75 62 65 78 70 72 28 45 78 rFieldSubexpr(Ex
2cef0 70 72 2a 2c 20 69 6e 74 29 3b 0a 45 78 70 72 20 pr*, int);.Expr
2cf00 2a 73 71 6c 69 74 65 33 45 78 70 72 46 6f 72 56 *sqlite3ExprForV
2cf10 65 63 74 6f 72 46 69 65 6c 64 28 50 61 72 73 65 ectorField(Parse
2cf20 2a 2c 45 78 70 72 2a 2c 69 6e 74 29 3b 0a 76 6f *,Expr*,int);.vo
2cf30 69 64 20 73 71 6c 69 74 65 33 56 65 63 74 6f 72 id sqlite3Vector
2cf40 45 72 72 6f 72 4d 73 67 28 50 61 72 73 65 2a 2c ErrorMsg(Parse*,
2cf50 20 45 78 70 72 2a 29 3b 0a 0a 23 65 6e 64 69 66 Expr*);..#endif
2cf60 20 2f 2a 20 53 51 4c 49 54 45 49 4e 54 5f 48 20 /* SQLITEINT_H
2cf70 2a 2f 0a */.