0000: 2f 2a 0a 2a 2a 20 32 30 30 31 20 53 65 70 74 65 /*.** 2001 Septe
0010: 6d 62 65 72 20 31 35 0a 2a 2a 0a 2a 2a 20 54 68 mber 15.**.** Th
0020: 65 20 61 75 74 68 6f 72 20 64 69 73 63 6c 61 69 e author disclai
0030: 6d 73 20 63 6f 70 79 72 69 67 68 74 20 74 6f 20 ms copyright to
0040: 74 68 69 73 20 73 6f 75 72 63 65 20 63 6f 64 65 this source code
0050: 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f 66 0a 2a . In place of.*
0060: 2a 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69 63 65 * a legal notice
0070: 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c 65 73 , here is a bles
0080: 73 69 6e 67 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 4d sing:.**.** M
0090: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61 ay you do good a
00a0: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 2a 2a 20 nd not evil..**
00b0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 May you find
00c0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 forgiveness for
00d0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 yourself and for
00e0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 2a 2a 20 give others..**
00f0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 May you share
0100: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 freely, never t
0110: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 aking more than
0120: 79 6f 75 20 67 69 76 65 2e 0a 2a 2a 0a 2a 2a 2a you give..**.***
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0170: 2a 2a 2a 2a 2a 2a 0a 2a 2a 20 49 6e 74 65 72 6e ******.** Intern
0180: 61 6c 20 69 6e 74 65 72 66 61 63 65 20 64 65 66 al interface def
0190: 69 6e 69 74 69 6f 6e 73 20 66 6f 72 20 53 51 4c initions for SQL
01a0: 69 74 65 2e 0a 2a 2a 0a 2a 2f 0a 23 69 66 6e 64 ite..**.*/.#ifnd
01b0: 65 66 20 5f 53 51 4c 49 54 45 49 4e 54 5f 48 5f ef _SQLITEINT_H_
01c0: 0a 23 64 65 66 69 6e 65 20 5f 53 51 4c 49 54 45 .#define _SQLITE
01d0: 49 4e 54 5f 48 5f 0a 0a 2f 2a 0a 2a 2a 20 54 68 INT_H_../*.** Th
01e0: 65 73 65 20 23 64 65 66 69 6e 65 73 20 73 68 6f ese #defines sho
01f0: 75 6c 64 20 65 6e 61 62 6c 65 20 3e 32 47 42 20 uld enable >2GB
0200: 66 69 6c 65 20 73 75 70 70 6f 72 74 20 6f 6e 20 file support on
0210: 50 4f 53 49 58 20 69 66 20 74 68 65 0a 2a 2a 20 POSIX if the.**
0220: 75 6e 64 65 72 6c 79 69 6e 67 20 6f 70 65 72 61 underlying opera
0230: 74 69 6e 67 20 73 79 73 74 65 6d 20 73 75 70 70 ting system supp
0240: 6f 72 74 73 20 69 74 2e 20 20 49 66 20 74 68 65 orts it. If the
0250: 20 4f 53 20 6c 61 63 6b 73 0a 2a 2a 20 6c 61 72 OS lacks.** lar
0260: 67 65 20 66 69 6c 65 20 73 75 70 70 6f 72 74 2c ge file support,
0270: 20 6f 72 20 69 66 20 74 68 65 20 4f 53 20 69 73 or if the OS is
0280: 20 77 69 6e 64 6f 77 73 2c 20 74 68 65 73 65 20 windows, these
0290: 73 68 6f 75 6c 64 20 62 65 20 6e 6f 2d 6f 70 73 should be no-ops
02a0: 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 20 23 ..**.** Ticket #
02b0: 32 37 33 39 3a 20 20 54 68 65 20 5f 4c 41 52 47 2739: The _LARG
02c0: 45 46 49 4c 45 5f 53 4f 55 52 43 45 20 6d 61 63 EFILE_SOURCE mac
02d0: 72 6f 20 6d 75 73 74 20 61 70 70 65 61 72 20 62 ro must appear b
02e0: 65 66 6f 72 65 20 61 6e 79 0a 2a 2a 20 73 79 73 efore any.** sys
02f0: 74 65 6d 20 23 69 6e 63 6c 75 64 65 73 2e 20 20 tem #includes.
0300: 48 65 6e 63 65 2c 20 74 68 69 73 20 62 6c 6f 63 Hence, this bloc
0310: 6b 20 6f 66 20 63 6f 64 65 20 6d 75 73 74 20 62 k of code must b
0320: 65 20 74 68 65 20 76 65 72 79 20 66 69 72 73 74 e the very first
0330: 0a 2a 2a 20 63 6f 64 65 20 69 6e 20 61 6c 6c 20 .** code in all
0340: 73 6f 75 72 63 65 20 66 69 6c 65 73 2e 0a 2a 2a source files..**
0350: 0a 2a 2a 20 4c 61 72 67 65 20 66 69 6c 65 20 73 .** Large file s
0360: 75 70 70 6f 72 74 20 63 61 6e 20 62 65 20 64 69 upport can be di
0370: 73 61 62 6c 65 64 20 75 73 69 6e 67 20 74 68 65 sabled using the
0380: 20 2d 44 53 51 4c 49 54 45 5f 44 49 53 41 42 4c -DSQLITE_DISABL
0390: 45 5f 4c 46 53 20 73 77 69 74 63 68 0a 2a 2a 20 E_LFS switch.**
03a0: 6f 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 on the compiler
03b0: 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 20 54 command line. T
03c0: 68 69 73 20 69 73 20 6e 65 63 65 73 73 61 72 79 his is necessary
03d0: 20 69 66 20 79 6f 75 20 61 72 65 20 63 6f 6d 70 if you are comp
03e0: 69 6c 69 6e 67 0a 2a 2a 20 6f 6e 20 61 20 72 65 iling.** on a re
03f0: 63 65 6e 74 20 6d 61 63 68 69 6e 65 20 28 65 78 cent machine (ex
0400: 3a 20 52 65 64 20 48 61 74 20 37 2e 32 29 20 62 : Red Hat 7.2) b
0410: 75 74 20 79 6f 75 20 77 61 6e 74 20 79 6f 75 72 ut you want your
0420: 20 63 6f 64 65 20 74 6f 20 77 6f 72 6b 0a 2a 2a code to work.**
0430: 20 6f 6e 20 61 6e 20 6f 6c 64 65 72 20 6d 61 63 on an older mac
0440: 68 69 6e 65 20 28 65 78 3a 20 52 65 64 20 48 61 hine (ex: Red Ha
0450: 74 20 36 2e 30 29 2e 20 20 49 66 20 79 6f 75 20 t 6.0). If you
0460: 63 6f 6d 70 69 6c 65 20 6f 6e 20 52 65 64 20 48 compile on Red H
0470: 61 74 20 37 2e 32 0a 2a 2a 20 77 69 74 68 6f 75 at 7.2.** withou
0480: 74 20 74 68 69 73 20 6f 70 74 69 6f 6e 2c 20 4c t this option, L
0490: 46 53 20 69 73 20 65 6e 61 62 6c 65 2e 20 20 42 FS is enable. B
04a0: 75 74 20 4c 46 53 20 64 6f 65 73 20 6e 6f 74 20 ut LFS does not
04b0: 65 78 69 73 74 20 69 6e 20 74 68 65 20 6b 65 72 exist in the ker
04c0: 6e 65 6c 0a 2a 2a 20 69 6e 20 52 65 64 20 48 61 nel.** in Red Ha
04d0: 74 20 36 2e 30 2c 20 73 6f 20 74 68 65 20 63 6f t 6.0, so the co
04e0: 64 65 20 77 6f 6e 27 74 20 77 6f 72 6b 2e 20 20 de won't work.
04f0: 48 65 6e 63 65 2c 20 66 6f 72 20 6d 61 78 69 6d Hence, for maxim
0500: 75 6d 20 62 69 6e 61 72 79 0a 2a 2a 20 70 6f 72 um binary.** por
0510: 74 61 62 69 6c 69 74 79 20 79 6f 75 20 73 68 6f tability you sho
0520: 75 6c 64 20 6f 6d 69 74 20 4c 46 53 2e 0a 2a 2a uld omit LFS..**
0530: 0a 2a 2a 20 54 68 65 20 70 72 65 76 69 6f 75 73 .** The previous
0540: 20 70 61 72 61 67 72 61 70 68 20 77 61 73 20 77 paragraph was w
0550: 72 69 74 74 65 6e 20 69 6e 20 32 30 30 35 2e 20 ritten in 2005.
0560: 20 28 54 68 69 73 20 70 61 72 61 67 72 61 70 68 (This paragraph
0570: 20 69 73 20 77 72 69 74 74 65 6e 0a 2a 2a 20 6f is written.** o
0580: 6e 20 32 30 30 38 2d 31 31 2d 32 38 2e 29 20 54 n 2008-11-28.) T
0590: 68 65 73 65 20 64 61 79 73 2c 20 61 6c 6c 20 4c hese days, all L
05a0: 69 6e 75 78 20 6b 65 72 6e 65 6c 73 20 73 75 70 inux kernels sup
05b0: 70 6f 72 74 20 6c 61 72 67 65 20 66 69 6c 65 73 port large files
05c0: 2c 20 73 6f 0a 2a 2a 20 79 6f 75 20 73 68 6f 75 , so.** you shou
05d0: 6c 64 20 70 72 6f 62 61 62 6c 79 20 6c 65 61 76 ld probably leav
05e0: 65 20 4c 46 53 20 65 6e 61 62 6c 65 64 2e 20 20 e LFS enabled.
05f0: 42 75 74 20 73 6f 6d 65 20 65 6d 62 65 64 64 65 But some embedde
0600: 64 20 70 6c 61 74 66 6f 72 6d 73 20 6d 69 67 68 d platforms migh
0610: 74 0a 2a 2a 20 6c 61 63 6b 20 4c 46 53 20 69 6e t.** lack LFS in
0620: 20 77 68 69 63 68 20 63 61 73 65 20 74 68 65 20 which case the
0630: 53 51 4c 49 54 45 5f 44 49 53 41 42 4c 45 5f 4c SQLITE_DISABLE_L
0640: 46 53 20 6d 61 63 72 6f 20 6d 69 67 68 74 20 73 FS macro might s
0650: 74 69 6c 6c 20 62 65 20 75 73 65 66 75 6c 2e 0a till be useful..
0660: 2a 2a 0a 2a 2a 20 53 69 6d 69 6c 61 72 20 69 73 **.** Similar is
0670: 20 74 72 75 65 20 66 6f 72 20 4d 61 63 20 4f 53 true for Mac OS
0680: 20 58 2e 20 20 4c 46 53 20 69 73 20 6f 6e 6c 79 X. LFS is only
0690: 20 73 75 70 70 6f 72 74 65 64 20 6f 6e 20 4d 61 supported on Ma
06a0: 63 20 4f 53 20 58 20 39 20 61 6e 64 20 6c 61 74 c OS X 9 and lat
06b0: 65 72 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 53 er..*/.#ifndef S
06c0: 51 4c 49 54 45 5f 44 49 53 41 42 4c 45 5f 4c 46 QLITE_DISABLE_LF
06d0: 53 0a 23 20 64 65 66 69 6e 65 20 5f 4c 41 52 47 S.# define _LARG
06e0: 45 5f 46 49 4c 45 20 20 20 20 20 20 20 31 0a 23 E_FILE 1.#
06f0: 20 69 66 6e 64 65 66 20 5f 46 49 4c 45 5f 4f 46 ifndef _FILE_OF
0700: 46 53 45 54 5f 42 49 54 53 0a 23 20 20 20 64 65 FSET_BITS.# de
0710: 66 69 6e 65 20 5f 46 49 4c 45 5f 4f 46 46 53 45 fine _FILE_OFFSE
0720: 54 5f 42 49 54 53 20 36 34 0a 23 20 65 6e 64 69 T_BITS 64.# endi
0730: 66 0a 23 20 64 65 66 69 6e 65 20 5f 4c 41 52 47 f.# define _LARG
0740: 45 46 49 4c 45 5f 53 4f 55 52 43 45 20 31 0a 23 EFILE_SOURCE 1.#
0750: 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 46 6f 72 endif../*.** For
0760: 20 4d 69 6e 47 57 2c 20 63 68 65 63 6b 20 74 6f MinGW, check to
0770: 20 73 65 65 20 69 66 20 77 65 20 63 61 6e 20 69 see if we can i
0780: 6e 63 6c 75 64 65 20 74 68 65 20 68 65 61 64 65 nclude the heade
0790: 72 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 69 6e r file containin
07a0: 67 20 69 74 73 0a 2a 2a 20 76 65 72 73 69 6f 6e g its.** version
07b0: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2c 20 61 6d information, am
07c0: 6f 6e 67 20 6f 74 68 65 72 20 74 68 69 6e 67 73 ong other things
07d0: 2e 20 20 4e 6f 72 6d 61 6c 6c 79 2c 20 74 68 69 . Normally, thi
07e0: 73 20 69 6e 74 65 72 6e 61 6c 20 4d 69 6e 47 57 s internal MinGW
07f0: 0a 2a 2a 20 68 65 61 64 65 72 20 66 69 6c 65 20 .** header file
0800: 77 6f 75 6c 64 20 5b 6f 6e 6c 79 5d 20 62 65 20 would [only] be
0810: 69 6e 63 6c 75 64 65 64 20 61 75 74 6f 6d 61 74 included automat
0820: 69 63 61 6c 6c 79 20 62 79 20 6f 74 68 65 72 20 ically by other
0830: 4d 69 6e 47 57 20 68 65 61 64 65 72 0a 2a 2a 20 MinGW header.**
0840: 66 69 6c 65 73 3b 20 68 6f 77 65 76 65 72 2c 20 files; however,
0850: 74 68 65 20 63 6f 6e 74 61 69 6e 65 64 20 76 65 the contained ve
0860: 72 73 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 6f rsion informatio
0870: 6e 20 69 73 20 6e 6f 77 20 72 65 71 75 69 72 65 n is now require
0880: 64 20 62 79 20 74 68 69 73 0a 2a 2a 20 68 65 61 d by this.** hea
0890: 64 65 72 20 66 69 6c 65 20 74 6f 20 77 6f 72 6b der file to work
08a0: 20 61 72 6f 75 6e 64 20 62 69 6e 61 72 79 20 63 around binary c
08b0: 6f 6d 70 61 74 69 62 69 6c 69 74 79 20 69 73 73 ompatibility iss
08c0: 75 65 73 20 28 73 65 65 20 62 65 6c 6f 77 29 20 ues (see below)
08d0: 61 6e 64 0a 2a 2a 20 74 68 69 73 20 69 73 20 74 and.** this is t
08e0: 68 65 20 6f 6e 6c 79 20 6b 6e 6f 77 6e 20 77 61 he only known wa
08f0: 79 20 74 6f 20 72 65 6c 69 61 62 6c 79 20 6f 62 y to reliably ob
0900: 74 61 69 6e 20 69 74 2e 20 20 54 68 69 73 20 65 tain it. This e
0910: 6e 74 69 72 65 20 23 69 66 20 62 6c 6f 63 6b 0a ntire #if block.
0920: 2a 2a 20 77 6f 75 6c 64 20 62 65 20 63 6f 6d 70 ** would be comp
0930: 6c 65 74 65 6c 79 20 75 6e 6e 65 63 65 73 73 61 letely unnecessa
0940: 72 79 20 69 66 20 74 68 65 72 65 20 77 61 73 20 ry if there was
0950: 61 6e 79 20 6f 74 68 65 72 20 77 61 79 20 6f 66 any other way of
0960: 20 64 65 74 65 63 74 69 6e 67 0a 2a 2a 20 4d 69 detecting.** Mi
0970: 6e 47 57 20 76 69 61 20 74 68 65 69 72 20 70 72 nGW via their pr
0980: 65 70 72 6f 63 65 73 73 6f 72 20 28 65 2e 67 2e eprocessor (e.g.
0990: 20 69 66 20 74 68 65 79 20 63 75 73 74 6f 6d 69 if they customi
09a0: 7a 65 64 20 74 68 65 69 72 20 47 43 43 20 74 6f zed their GCC to
09b0: 20 64 65 66 69 6e 65 0a 2a 2a 20 73 6f 6d 65 20 define.** some
09c0: 4d 69 6e 47 57 2d 73 70 65 63 69 66 69 63 20 6d MinGW-specific m
09d0: 61 63 72 6f 73 29 2e 20 20 57 68 65 6e 20 63 6f acros). When co
09e0: 6d 70 69 6c 69 6e 67 20 66 6f 72 20 4d 69 6e 47 mpiling for MinG
09f0: 57 2c 20 65 69 74 68 65 72 20 74 68 65 0a 2a 2a W, either the.**
0a00: 20 5f 48 41 56 45 5f 4d 49 4e 47 57 5f 48 20 6f _HAVE_MINGW_H o
0a10: 72 20 5f 48 41 56 45 5f 5f 4d 49 4e 47 57 5f 48 r _HAVE__MINGW_H
0a20: 20 28 6e 6f 74 65 20 74 68 65 20 65 78 74 72 61 (note the extra
0a30: 20 75 6e 64 65 72 73 63 6f 72 65 29 20 6d 61 63 underscore) mac
0a40: 72 6f 20 6d 75 73 74 20 62 65 0a 2a 2a 20 64 65 ro must be.** de
0a50: 66 69 6e 65 64 3b 20 6f 74 68 65 72 77 69 73 65 fined; otherwise
0a60: 2c 20 64 65 74 65 63 74 69 6f 6e 20 6f 66 20 63 , detection of c
0a70: 6f 6e 64 69 74 69 6f 6e 73 20 73 70 65 63 69 66 onditions specif
0a80: 69 63 20 74 6f 20 4d 69 6e 47 57 20 77 69 6c 6c ic to MinGW will
0a90: 20 62 65 0a 2a 2a 20 64 69 73 61 62 6c 65 64 2e be.** disabled.
0aa0: 0a 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 .*/.#if defined(
0ab0: 5f 48 41 56 45 5f 4d 49 4e 47 57 5f 48 29 0a 23 _HAVE_MINGW_H).#
0ac0: 20 69 6e 63 6c 75 64 65 20 22 6d 69 6e 67 77 2e include "mingw.
0ad0: 68 22 0a 23 65 6c 69 66 20 64 65 66 69 6e 65 64 h".#elif defined
0ae0: 28 5f 48 41 56 45 5f 5f 4d 49 4e 47 57 5f 48 29 (_HAVE__MINGW_H)
0af0: 0a 23 20 69 6e 63 6c 75 64 65 20 22 5f 6d 69 6e .# include "_min
0b00: 67 77 2e 68 22 0a 23 65 6e 64 69 66 0a 0a 2f 2a gw.h".#endif../*
0b10: 0a 2a 2a 20 46 6f 72 20 4d 69 6e 47 57 20 76 65 .** For MinGW ve
0b20: 72 73 69 6f 6e 20 34 2e 78 20 28 61 6e 64 20 68 rsion 4.x (and h
0b30: 69 67 68 65 72 29 2c 20 63 68 65 63 6b 20 74 6f igher), check to
0b40: 20 73 65 65 20 69 66 20 74 68 65 20 5f 55 53 45 see if the _USE
0b50: 5f 33 32 42 49 54 5f 54 49 4d 45 5f 54 0a 2a 2a _32BIT_TIME_T.**
0b60: 20 64 65 66 69 6e 65 20 69 73 20 72 65 71 75 69 define is requi
0b70: 72 65 64 20 74 6f 20 6d 61 69 6e 74 61 69 6e 20 red to maintain
0b80: 62 69 6e 61 72 79 20 63 6f 6d 70 61 74 69 62 69 binary compatibi
0b90: 6c 69 74 79 20 77 69 74 68 20 74 68 65 20 4d 53 lity with the MS
0ba0: 56 43 20 72 75 6e 74 69 6d 65 0a 2a 2a 20 6c 69 VC runtime.** li
0bb0: 62 72 61 72 79 20 69 6e 20 75 73 65 20 28 65 2e brary in use (e.
0bc0: 67 2e 20 66 6f 72 20 57 69 6e 64 6f 77 73 20 58 g. for Windows X
0bd0: 50 29 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 P)..*/.#if !defi
0be0: 6e 65 64 28 5f 55 53 45 5f 33 32 42 49 54 5f 54 ned(_USE_32BIT_T
0bf0: 49 4d 45 5f 54 29 20 26 26 20 21 64 65 66 69 6e IME_T) && !defin
0c00: 65 64 28 5f 55 53 45 5f 36 34 42 49 54 5f 54 49 ed(_USE_64BIT_TI
0c10: 4d 45 5f 54 29 20 26 26 20 5c 0a 20 20 20 20 64 ME_T) && \. d
0c20: 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 26 efined(_WIN32) &
0c30: 26 20 21 64 65 66 69 6e 65 64 28 5f 57 49 4e 36 & !defined(_WIN6
0c40: 34 29 20 26 26 20 5c 0a 20 20 20 20 64 65 66 69 4) && \. defi
0c50: 6e 65 64 28 5f 5f 4d 49 4e 47 57 5f 4d 41 4a 4f ned(__MINGW_MAJO
0c60: 52 5f 56 45 52 53 49 4f 4e 29 20 26 26 20 5f 5f R_VERSION) && __
0c70: 4d 49 4e 47 57 5f 4d 41 4a 4f 52 5f 56 45 52 53 MINGW_MAJOR_VERS
0c80: 49 4f 4e 20 3e 3d 20 34 20 26 26 20 5c 0a 20 20 ION >= 4 && \.
0c90: 20 20 64 65 66 69 6e 65 64 28 5f 5f 4d 53 56 43 defined(__MSVC
0ca0: 52 54 5f 5f 29 0a 23 20 64 65 66 69 6e 65 20 5f RT__).# define _
0cb0: 55 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 5f 54 USE_32BIT_TIME_T
0cc0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 54 68 65 20 .#endif../* The
0cd0: 70 75 62 6c 69 63 20 53 51 4c 69 74 65 20 69 6e public SQLite in
0ce0: 74 65 72 66 61 63 65 2e 20 20 54 68 65 20 5f 46 terface. The _F
0cf0: 49 4c 45 5f 4f 46 46 53 45 54 5f 42 49 54 53 20 ILE_OFFSET_BITS
0d00: 6d 61 63 72 6f 20 6d 75 73 74 20 61 70 70 65 61 macro must appea
0d10: 72 0a 2a 2a 20 66 69 72 73 74 20 69 6e 20 51 4e r.** first in QN
0d20: 58 2e 20 20 41 6c 73 6f 2c 20 74 68 65 20 5f 55 X. Also, the _U
0d30: 53 45 5f 33 32 42 49 54 5f 54 49 4d 45 5f 54 20 SE_32BIT_TIME_T
0d40: 6d 61 63 72 6f 20 6d 75 73 74 20 61 70 70 65 61 macro must appea
0d50: 72 20 66 69 72 73 74 20 66 6f 72 0a 2a 2a 20 4d r first for.** M
0d60: 69 6e 47 57 2e 0a 2a 2f 0a 23 69 6e 63 6c 75 64 inGW..*/.#includ
0d70: 65 20 22 73 71 6c 69 74 65 33 2e 68 22 0a 0a 2f e "sqlite3.h"../
0d80: 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 74 68 65 *.** Include the
0d90: 20 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 68 configuration h
0da0: 65 61 64 65 72 20 6f 75 74 70 75 74 20 62 79 20 eader output by
0db0: 27 63 6f 6e 66 69 67 75 72 65 27 20 69 66 20 77 'configure' if w
0dc0: 65 27 72 65 20 75 73 69 6e 67 20 74 68 65 0a 2a e're using the.*
0dd0: 2a 20 61 75 74 6f 63 6f 6e 66 2d 62 61 73 65 64 * autoconf-based
0de0: 20 62 75 69 6c 64 0a 2a 2f 0a 23 69 66 64 65 66 build.*/.#ifdef
0df0: 20 5f 48 41 56 45 5f 53 51 4c 49 54 45 5f 43 4f _HAVE_SQLITE_CO
0e00: 4e 46 49 47 5f 48 0a 23 69 6e 63 6c 75 64 65 20 NFIG_H.#include
0e10: 22 63 6f 6e 66 69 67 2e 68 22 0a 23 65 6e 64 69 "config.h".#endi
0e20: 66 0a 0a 23 69 6e 63 6c 75 64 65 20 22 73 71 6c f..#include "sql
0e30: 69 74 65 4c 69 6d 69 74 2e 68 22 0a 0a 2f 2a 20 iteLimit.h"../*
0e40: 44 69 73 61 62 6c 65 20 6e 75 69 73 61 6e 63 65 Disable nuisance
0e50: 20 77 61 72 6e 69 6e 67 73 20 6f 6e 20 42 6f 72 warnings on Bor
0e60: 6c 61 6e 64 20 63 6f 6d 70 69 6c 65 72 73 20 2a land compilers *
0e70: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f /.#if defined(__
0e80: 42 4f 52 4c 41 4e 44 43 5f 5f 29 0a 23 70 72 61 BORLANDC__).#pra
0e90: 67 6d 61 20 77 61 72 6e 20 2d 72 63 68 20 2f 2a gma warn -rch /*
0ea0: 20 75 6e 72 65 61 63 68 61 62 6c 65 20 63 6f 64 unreachable cod
0eb0: 65 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 72 e */.#pragma war
0ec0: 6e 20 2d 63 63 63 20 2f 2a 20 43 6f 6e 64 69 74 n -ccc /* Condit
0ed0: 69 6f 6e 20 69 73 20 61 6c 77 61 79 73 20 74 72 ion is always tr
0ee0: 75 65 20 6f 72 20 66 61 6c 73 65 20 2a 2f 0a 23 ue or false */.#
0ef0: 70 72 61 67 6d 61 20 77 61 72 6e 20 2d 61 75 73 pragma warn -aus
0f00: 20 2f 2a 20 41 73 73 69 67 6e 65 64 20 76 61 6c /* Assigned val
0f10: 75 65 20 69 73 20 6e 65 76 65 72 20 75 73 65 64 ue is never used
0f20: 20 2a 2f 0a 23 70 72 61 67 6d 61 20 77 61 72 6e */.#pragma warn
0f30: 20 2d 63 73 75 20 2f 2a 20 43 6f 6d 70 61 72 69 -csu /* Compari
0f40: 6e 67 20 73 69 67 6e 65 64 20 61 6e 64 20 75 6e ng signed and un
0f50: 73 69 67 6e 65 64 20 2a 2f 0a 23 70 72 61 67 6d signed */.#pragm
0f60: 61 20 77 61 72 6e 20 2d 73 70 61 20 2f 2a 20 53 a warn -spa /* S
0f70: 75 73 70 69 63 69 6f 75 73 20 70 6f 69 6e 74 65 uspicious pointe
0f80: 72 20 61 72 69 74 68 6d 65 74 69 63 20 2a 2f 0a r arithmetic */.
0f90: 23 65 6e 64 69 66 0a 0a 2f 2a 20 4e 65 65 64 65 #endif../* Neede
0fa0: 64 20 66 6f 72 20 76 61 72 69 6f 75 73 20 64 65 d for various de
0fb0: 66 69 6e 69 74 69 6f 6e 73 2e 2e 2e 20 2a 2f 0a finitions... */.
0fc0: 23 69 66 6e 64 65 66 20 5f 47 4e 55 5f 53 4f 55 #ifndef _GNU_SOU
0fd0: 52 43 45 0a 23 20 64 65 66 69 6e 65 20 5f 47 4e RCE.# define _GN
0fe0: 55 5f 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a U_SOURCE.#endif.
0ff0: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 4f .#if defined(__O
1000: 70 65 6e 42 53 44 5f 5f 29 20 26 26 20 21 64 65 penBSD__) && !de
1010: 66 69 6e 65 64 28 5f 42 53 44 5f 53 4f 55 52 43 fined(_BSD_SOURC
1020: 45 29 0a 23 20 64 65 66 69 6e 65 20 5f 42 53 44 E).# define _BSD
1030: 5f 53 4f 55 52 43 45 0a 23 65 6e 64 69 66 0a 0a _SOURCE.#endif..
1040: 2f 2a 0a 2a 2a 20 49 6e 63 6c 75 64 65 20 73 74 /*.** Include st
1050: 61 6e 64 61 72 64 20 68 65 61 64 65 72 20 66 69 andard header fi
1060: 6c 65 73 20 61 73 20 6e 65 63 65 73 73 61 72 79 les as necessary
1070: 0a 2a 2f 0a 23 69 66 64 65 66 20 48 41 56 45 5f .*/.#ifdef HAVE_
1080: 53 54 44 49 4e 54 5f 48 0a 23 69 6e 63 6c 75 64 STDINT_H.#includ
1090: 65 20 3c 73 74 64 69 6e 74 2e 68 3e 0a 23 65 6e e <stdint.h>.#en
10a0: 64 69 66 0a 23 69 66 64 65 66 20 48 41 56 45 5f dif.#ifdef HAVE_
10b0: 49 4e 54 54 59 50 45 53 5f 48 0a 23 69 6e 63 6c INTTYPES_H.#incl
10c0: 75 64 65 20 3c 69 6e 74 74 79 70 65 73 2e 68 3e ude <inttypes.h>
10d0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
10e0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 he following mac
10f0: 72 6f 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 ros are used to
1100: 63 61 73 74 20 70 6f 69 6e 74 65 72 73 20 74 6f cast pointers to
1110: 20 69 6e 74 65 67 65 72 73 20 61 6e 64 0a 2a 2a integers and.**
1120: 20 69 6e 74 65 67 65 72 73 20 74 6f 20 70 6f 69 integers to poi
1130: 6e 74 65 72 73 2e 20 20 54 68 65 20 77 61 79 20 nters. The way
1140: 79 6f 75 20 64 6f 20 74 68 69 73 20 76 61 72 69 you do this vari
1150: 65 73 20 66 72 6f 6d 20 6f 6e 65 20 63 6f 6d 70 es from one comp
1160: 69 6c 65 72 0a 2a 2a 20 74 6f 20 74 68 65 20 6e iler.** to the n
1170: 65 78 74 2c 20 73 6f 20 77 65 20 68 61 76 65 20 ext, so we have
1180: 64 65 76 65 6c 6f 70 65 64 20 74 68 65 20 66 6f developed the fo
1190: 6c 6c 6f 77 69 6e 67 20 73 65 74 20 6f 66 20 23 llowing set of #
11a0: 69 66 20 73 74 61 74 65 6d 65 6e 74 73 0a 2a 2a if statements.**
11b0: 20 74 6f 20 67 65 6e 65 72 61 74 65 20 61 70 70 to generate app
11c0: 72 6f 70 72 69 61 74 65 20 6d 61 63 72 6f 73 20 ropriate macros
11d0: 66 6f 72 20 61 20 77 69 64 65 20 72 61 6e 67 65 for a wide range
11e0: 20 6f 66 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a of compilers..*
11f0: 2a 0a 2a 2a 20 54 68 65 20 63 6f 72 72 65 63 74 *.** The correct
1200: 20 22 41 4e 53 49 22 20 77 61 79 20 74 6f 20 64 "ANSI" way to d
1210: 6f 20 74 68 69 73 20 69 73 20 74 6f 20 75 73 65 o this is to use
1220: 20 74 68 65 20 69 6e 74 70 74 72 5f 74 20 74 79 the intptr_t ty
1230: 70 65 2e 20 0a 2a 2a 20 55 6e 66 6f 72 74 75 6e pe. .** Unfortun
1240: 61 74 65 6c 79 2c 20 74 68 61 74 20 74 79 70 65 ately, that type
1250: 64 65 66 20 69 73 20 6e 6f 74 20 61 76 61 69 6c def is not avail
1260: 61 62 6c 65 20 6f 6e 20 61 6c 6c 20 63 6f 6d 70 able on all comp
1270: 69 6c 65 72 73 2c 20 6f 72 0a 2a 2a 20 69 66 20 ilers, or.** if
1280: 69 74 20 69 73 20 61 76 61 69 6c 61 62 6c 65 2c it is available,
1290: 20 69 74 20 72 65 71 75 69 72 65 73 20 61 6e 20 it requires an
12a0: 23 69 6e 63 6c 75 64 65 20 6f 66 20 73 70 65 63 #include of spec
12b0: 69 66 69 63 20 68 65 61 64 65 72 73 0a 2a 2a 20 ific headers.**
12c0: 74 68 61 74 20 76 61 72 79 20 66 72 6f 6d 20 6f that vary from o
12d0: 6e 65 20 6d 61 63 68 69 6e 65 20 74 6f 20 74 68 ne machine to th
12e0: 65 20 6e 65 78 74 2e 0a 2a 2a 0a 2a 2a 20 54 69 e next..**.** Ti
12f0: 63 6b 65 74 20 23 33 38 36 30 3a 20 20 54 68 65 cket #3860: The
1300: 20 6c 6c 76 6d 2d 67 63 63 2d 34 2e 32 20 63 6f llvm-gcc-4.2 co
1310: 6d 70 69 6c 65 72 20 66 72 6f 6d 20 41 70 70 6c mpiler from Appl
1320: 65 20 63 68 6f 6b 65 73 20 6f 6e 0a 2a 2a 20 74 e chokes on.** t
1330: 68 65 20 28 28 76 6f 69 64 2a 29 26 28 28 63 68 he ((void*)&((ch
1340: 61 72 2a 29 30 29 5b 58 5d 29 20 63 6f 6e 73 74 ar*)0)[X]) const
1350: 72 75 63 74 2e 20 20 42 75 74 20 4d 53 56 43 20 ruct. But MSVC
1360: 63 68 6f 6b 65 73 20 6f 6e 20 28 28 76 6f 69 64 chokes on ((void
1370: 2a 29 28 58 29 29 2e 0a 2a 2a 20 53 6f 20 77 65 *)(X))..** So we
1380: 20 68 61 76 65 20 74 6f 20 64 65 66 69 6e 65 20 have to define
1390: 74 68 65 20 6d 61 63 72 6f 73 20 69 6e 20 64 69 the macros in di
13a0: 66 66 65 72 65 6e 74 20 77 61 79 73 20 64 65 70 fferent ways dep
13b0: 65 6e 64 69 6e 67 20 6f 6e 20 74 68 65 0a 2a 2a ending on the.**
13c0: 20 63 6f 6d 70 69 6c 65 72 2e 0a 2a 2f 0a 23 69 compiler..*/.#i
13d0: 66 20 64 65 66 69 6e 65 64 28 5f 5f 50 54 52 44 f defined(__PTRD
13e0: 49 46 46 5f 54 59 50 45 5f 5f 29 20 20 2f 2a 20 IFF_TYPE__) /*
13f0: 54 68 69 73 20 63 61 73 65 20 73 68 6f 75 6c 64 This case should
1400: 20 77 6f 72 6b 20 66 6f 72 20 47 43 43 20 2a 2f work for GCC */
1410: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
1420: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 20 _INT_TO_PTR(X)
1430: 28 28 76 6f 69 64 2a 29 28 5f 5f 50 54 52 44 49 ((void*)(__PTRDI
1440: 46 46 5f 54 59 50 45 5f 5f 29 28 58 29 29 0a 23 FF_TYPE__)(X)).#
1450: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 define SQLITE_P
1460: 54 52 5f 54 4f 5f 49 4e 54 28 58 29 20 20 28 28 TR_TO_INT(X) ((
1470: 69 6e 74 29 28 5f 5f 50 54 52 44 49 46 46 5f 54 int)(__PTRDIFF_T
1480: 59 50 45 5f 5f 29 28 58 29 29 0a 23 65 6c 69 66 YPE__)(X)).#elif
1490: 20 21 64 65 66 69 6e 65 64 28 5f 5f 47 4e 55 43 !defined(__GNUC
14a0: 5f 5f 29 20 20 20 20 20 20 20 2f 2a 20 57 6f 72 __) /* Wor
14b0: 6b 73 20 66 6f 72 20 63 6f 6d 70 69 6c 65 72 73 ks for compilers
14c0: 20 6f 74 68 65 72 20 74 68 61 6e 20 4c 4c 56 4d other than LLVM
14d0: 20 2a 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c */.# define SQL
14e0: 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 ITE_INT_TO_PTR(X
14f0: 29 20 20 28 28 76 6f 69 64 2a 29 26 28 28 63 68 ) ((void*)&((ch
1500: 61 72 2a 29 30 29 5b 58 5d 29 0a 23 20 64 65 66 ar*)0)[X]).# def
1510: 69 6e 65 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 ine SQLITE_PTR_T
1520: 4f 5f 49 4e 54 28 58 29 20 20 28 28 69 6e 74 29 O_INT(X) ((int)
1530: 28 28 28 63 68 61 72 2a 29 58 29 2d 28 63 68 61 (((char*)X)-(cha
1540: 72 2a 29 30 29 29 0a 23 65 6c 69 66 20 64 65 66 r*)0)).#elif def
1550: 69 6e 65 64 28 48 41 56 45 5f 53 54 44 49 4e 54 ined(HAVE_STDINT
1560: 5f 48 29 20 20 20 2f 2a 20 55 73 65 20 74 68 69 _H) /* Use thi
1570: 73 20 63 61 73 65 20 69 66 20 77 65 20 68 61 76 s case if we hav
1580: 65 20 41 4e 53 49 20 68 65 61 64 65 72 73 20 2a e ANSI headers *
1590: 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 /.# define SQLIT
15a0: 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 58 29 20 E_INT_TO_PTR(X)
15b0: 20 28 28 76 6f 69 64 2a 29 28 69 6e 74 70 74 72 ((void*)(intptr
15c0: 5f 74 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 _t)(X)).# define
15d0: 20 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 SQLITE_PTR_TO_I
15e0: 4e 54 28 58 29 20 20 28 28 69 6e 74 29 28 69 6e NT(X) ((int)(in
15f0: 74 70 74 72 5f 74 29 28 58 29 29 0a 23 65 6c 73 tptr_t)(X)).#els
1600: 65 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e
1610: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 47 65 /* Ge
1620: 6e 65 72 61 74 65 73 20 61 20 77 61 72 6e 69 6e nerates a warnin
1630: 67 20 2d 20 62 75 74 20 69 74 20 61 6c 77 61 79 g - but it alway
1640: 73 20 77 6f 72 6b 73 20 2a 2f 0a 23 20 64 65 66 s works */.# def
1650: 69 6e 65 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 ine SQLITE_INT_T
1660: 4f 5f 50 54 52 28 58 29 20 20 28 28 76 6f 69 64 O_PTR(X) ((void
1670: 2a 29 28 58 29 29 0a 23 20 64 65 66 69 6e 65 20 *)(X)).# define
1680: 53 51 4c 49 54 45 5f 50 54 52 5f 54 4f 5f 49 4e SQLITE_PTR_TO_IN
1690: 54 28 58 29 20 20 28 28 69 6e 74 29 28 58 29 29 T(X) ((int)(X))
16a0: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 .#endif../*.** T
16b0: 68 65 20 53 51 4c 49 54 45 5f 54 48 52 45 41 44 he SQLITE_THREAD
16c0: 53 41 46 45 20 6d 61 63 72 6f 20 6d 75 73 74 20 SAFE macro must
16d0: 62 65 20 64 65 66 69 6e 65 64 20 61 73 20 30 2c be defined as 0,
16e0: 20 31 2c 20 6f 72 20 32 2e 0a 2a 2a 20 30 20 6d 1, or 2..** 0 m
16f0: 65 61 6e 73 20 6d 75 74 65 78 65 73 20 61 72 65 eans mutexes are
1700: 20 70 65 72 6d 61 6e 65 6e 74 6c 79 20 64 69 73 permanently dis
1710: 61 62 6c 65 20 61 6e 64 20 74 68 65 20 6c 69 62 able and the lib
1720: 72 61 72 79 20 69 73 20 6e 65 76 65 72 0a 2a 2a rary is never.**
1730: 20 74 68 72 65 61 64 73 61 66 65 2e 20 20 31 20 threadsafe. 1
1740: 6d 65 61 6e 73 20 74 68 65 20 6c 69 62 72 61 72 means the librar
1750: 79 20 69 73 20 73 65 72 69 61 6c 69 7a 65 64 20 y is serialized
1760: 77 68 69 63 68 20 69 73 20 74 68 65 20 68 69 67 which is the hig
1770: 68 65 73 74 0a 2a 2a 20 6c 65 76 65 6c 20 6f 66 hest.** level of
1780: 20 74 68 72 65 61 64 73 61 66 65 74 79 2e 20 20 threadsafety.
1790: 32 20 6d 65 61 6e 73 20 74 68 65 20 6c 69 62 72 2 means the libr
17a0: 61 72 79 20 69 73 20 6d 75 6c 74 69 74 68 72 65 ary is multithre
17b0: 61 64 65 64 20 2d 20 6d 75 6c 74 69 70 6c 65 0a aded - multiple.
17c0: 2a 2a 20 74 68 72 65 61 64 73 20 63 61 6e 20 75 ** threads can u
17d0: 73 65 20 53 51 4c 69 74 65 20 61 73 20 6c 6f 6e se SQLite as lon
17e0: 67 20 61 73 20 6e 6f 20 74 77 6f 20 74 68 72 65 g as no two thre
17f0: 61 64 73 20 74 72 79 20 74 6f 20 75 73 65 20 74 ads try to use t
1800: 68 65 20 73 61 6d 65 0a 2a 2a 20 64 61 74 61 62 he same.** datab
1810: 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 ase connection a
1820: 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 2e t the same time.
1830: 0a 2a 2a 0a 2a 2a 20 4f 6c 64 65 72 20 76 65 72 .**.** Older ver
1840: 73 69 6f 6e 73 20 6f 66 20 53 51 4c 69 74 65 20 sions of SQLite
1850: 75 73 65 64 20 61 6e 20 6f 70 74 69 6f 6e 61 6c used an optional
1860: 20 54 48 52 45 41 44 53 41 46 45 20 6d 61 63 72 THREADSAFE macr
1870: 6f 2e 0a 2a 2a 20 57 65 20 73 75 70 70 6f 72 74 o..** We support
1880: 20 74 68 61 74 20 66 6f 72 20 6c 65 67 61 63 79 that for legacy
1890: 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 ..*/.#if !define
18a0: 64 28 53 51 4c 49 54 45 5f 54 48 52 45 41 44 53 d(SQLITE_THREADS
18b0: 41 46 45 29 0a 23 20 69 66 20 64 65 66 69 6e 65 AFE).# if define
18c0: 64 28 54 48 52 45 41 44 53 41 46 45 29 0a 23 20 d(THREADSAFE).#
18d0: 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f define SQLITE_
18e0: 54 48 52 45 41 44 53 41 46 45 20 54 48 52 45 41 THREADSAFE THREA
18f0: 44 53 41 46 45 0a 23 20 65 6c 73 65 0a 23 20 20 DSAFE.# else.#
1900: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 define SQLITE_T
1910: 48 52 45 41 44 53 41 46 45 20 31 20 2f 2a 20 49 HREADSAFE 1 /* I
1920: 4d 50 3a 20 52 2d 30 37 32 37 32 2d 32 32 33 30 MP: R-07272-2230
1930: 39 20 2a 2f 0a 23 20 65 6e 64 69 66 0a 23 65 6e 9 */.# endif.#en
1940: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 6f 77 65 72 dif../*.** Power
1950: 73 61 66 65 20 6f 76 65 72 77 72 69 74 65 20 69 safe overwrite i
1960: 73 20 6f 6e 20 62 79 20 64 65 66 61 75 6c 74 2e s on by default.
1970: 20 20 42 75 74 20 63 61 6e 20 62 65 20 74 75 72 But can be tur
1980: 6e 65 64 20 6f 66 66 20 75 73 69 6e 67 0a 2a 2a ned off using.**
1990: 20 74 68 65 20 2d 44 53 51 4c 49 54 45 5f 50 4f the -DSQLITE_PO
19a0: 57 45 52 53 41 46 45 5f 4f 56 45 52 57 52 49 54 WERSAFE_OVERWRIT
19b0: 45 3d 30 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 E=0 command-line
19c0: 20 6f 70 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 6e option..*/.#ifn
19d0: 64 65 66 20 53 51 4c 49 54 45 5f 50 4f 57 45 52 def SQLITE_POWER
19e0: 53 41 46 45 5f 4f 56 45 52 57 52 49 54 45 0a 23 SAFE_OVERWRITE.#
19f0: 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 50 define SQLITE_P
1a00: 4f 57 45 52 53 41 46 45 5f 4f 56 45 52 57 52 49 OWERSAFE_OVERWRI
1a10: 54 45 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a TE 1.#endif../*.
1a20: 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 5f 44 45 ** The SQLITE_DE
1a30: 46 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 53 20 FAULT_MEMSTATUS
1a40: 6d 61 63 72 6f 20 6d 75 73 74 20 62 65 20 64 65 macro must be de
1a50: 66 69 6e 65 64 20 61 73 20 65 69 74 68 65 72 20 fined as either
1a60: 30 20 6f 72 20 31 2e 0a 2a 2a 20 49 74 20 64 65 0 or 1..** It de
1a70: 74 65 72 6d 69 6e 65 73 20 77 68 65 74 68 65 72 termines whether
1a80: 20 6f 72 20 6e 6f 74 20 74 68 65 20 66 65 61 74 or not the feat
1a90: 75 72 65 73 20 72 65 6c 61 74 65 64 20 74 6f 20 ures related to
1aa0: 0a 2a 2a 20 53 51 4c 49 54 45 5f 43 4f 4e 46 49 .** SQLITE_CONFI
1ab0: 47 5f 4d 45 4d 53 54 41 54 55 53 20 61 72 65 20 G_MEMSTATUS are
1ac0: 61 76 61 69 6c 61 62 6c 65 20 62 79 20 64 65 66 available by def
1ad0: 61 75 6c 74 20 6f 72 20 6e 6f 74 2e 20 54 68 69 ault or not. Thi
1ae0: 73 20 76 61 6c 75 65 20 63 61 6e 0a 2a 2a 20 62 s value can.** b
1af0: 65 20 6f 76 65 72 72 69 64 64 65 6e 20 61 74 20 e overridden at
1b00: 72 75 6e 74 69 6d 65 20 75 73 69 6e 67 20 74 68 runtime using th
1b10: 65 20 73 71 6c 69 74 65 33 5f 63 6f 6e 66 69 67 e sqlite3_config
1b20: 28 29 20 41 50 49 2e 0a 2a 2f 0a 23 69 66 20 21 () API..*/.#if !
1b30: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 44 defined(SQLITE_D
1b40: 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 54 55 53 EFAULT_MEMSTATUS
1b50: 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 ).# define SQLIT
1b60: 45 5f 44 45 46 41 55 4c 54 5f 4d 45 4d 53 54 41 E_DEFAULT_MEMSTA
1b70: 54 55 53 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a TUS 1.#endif../*
1b80: 0a 2a 2a 20 45 78 61 63 74 6c 79 20 6f 6e 65 20 .** Exactly one
1b90: 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 of the following
1ba0: 20 6d 61 63 72 6f 73 20 6d 75 73 74 20 62 65 20 macros must be
1bb0: 64 65 66 69 6e 65 64 20 69 6e 20 6f 72 64 65 72 defined in order
1bc0: 20 74 6f 0a 2a 2a 20 73 70 65 63 69 66 79 20 77 to.** specify w
1bd0: 68 69 63 68 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f hich memory allo
1be0: 63 61 74 69 6f 6e 20 73 75 62 73 79 73 74 65 6d cation subsystem
1bf0: 20 74 6f 20 75 73 65 2e 0a 2a 2a 0a 2a 2a 20 20 to use..**.**
1c00: 20 20 20 53 51 4c 49 54 45 5f 53 59 53 54 45 4d SQLITE_SYSTEM
1c10: 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 20 20 20 _MALLOC
1c20: 20 2f 2f 20 55 73 65 20 6e 6f 72 6d 61 6c 20 73 // Use normal s
1c30: 79 73 74 65 6d 20 6d 61 6c 6c 6f 63 28 29 0a 2a ystem malloc().*
1c40: 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 57 49 4e * SQLITE_WIN
1c50: 33 32 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 20 32_MALLOC
1c60: 20 20 20 20 2f 2f 20 55 73 65 20 57 69 6e 33 32 // Use Win32
1c70: 20 6e 61 74 69 76 65 20 68 65 61 70 20 41 50 49 native heap API
1c80: 0a 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 5a .** SQLITE_Z
1c90: 45 52 4f 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 20 ERO_MALLOC
1ca0: 20 20 20 20 20 20 2f 2f 20 55 73 65 20 61 20 73 // Use a s
1cb0: 74 75 62 20 61 6c 6c 6f 63 61 74 6f 72 20 74 68 tub allocator th
1cc0: 61 74 20 61 6c 77 61 79 73 20 66 61 69 6c 73 0a at always fails.
1cd0: 2a 2a 20 20 20 20 20 53 51 4c 49 54 45 5f 4d 45 ** SQLITE_ME
1ce0: 4d 44 45 42 55 47 20 20 20 20 20 20 20 20 20 20 MDEBUG
1cf0: 20 20 20 20 20 2f 2f 20 44 65 62 75 67 67 69 6e // Debuggin
1d00: 67 20 76 65 72 73 69 6f 6e 20 6f 66 20 73 79 73 g version of sys
1d10: 74 65 6d 20 6d 61 6c 6c 6f 63 28 29 0a 2a 2a 0a tem malloc().**.
1d20: 2a 2a 20 4f 6e 20 57 69 6e 64 6f 77 73 2c 20 69 ** On Windows, i
1d30: 66 20 74 68 65 20 53 51 4c 49 54 45 5f 57 49 4e f the SQLITE_WIN
1d40: 33 32 5f 4d 41 4c 4c 4f 43 5f 56 41 4c 49 44 41 32_MALLOC_VALIDA
1d50: 54 45 20 6d 61 63 72 6f 20 69 73 20 64 65 66 69 TE macro is defi
1d60: 6e 65 64 20 61 6e 64 20 74 68 65 0a 2a 2a 20 61 ned and the.** a
1d70: 73 73 65 72 74 28 29 20 6d 61 63 72 6f 20 69 73 ssert() macro is
1d80: 20 65 6e 61 62 6c 65 64 2c 20 65 61 63 68 20 63 enabled, each c
1d90: 61 6c 6c 20 69 6e 74 6f 20 74 68 65 20 57 69 6e all into the Win
1da0: 33 32 20 6e 61 74 69 76 65 20 68 65 61 70 20 73 32 native heap s
1db0: 75 62 73 79 73 74 65 6d 0a 2a 2a 20 77 69 6c 6c ubsystem.** will
1dc0: 20 63 61 75 73 65 20 48 65 61 70 56 61 6c 69 64 cause HeapValid
1dd0: 61 74 65 20 74 6f 20 62 65 20 63 61 6c 6c 65 64 ate to be called
1de0: 2e 20 20 49 66 20 68 65 61 70 20 76 61 6c 69 64 . If heap valid
1df0: 61 74 69 6f 6e 20 73 68 6f 75 6c 64 20 66 61 69 ation should fai
1e00: 6c 2c 20 61 6e 0a 2a 2a 20 61 73 73 65 72 74 69 l, an.** asserti
1e10: 6f 6e 20 77 69 6c 6c 20 62 65 20 74 72 69 67 67 on will be trigg
1e20: 65 72 65 64 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 6e ered..**.** If n
1e30: 6f 6e 65 20 6f 66 20 74 68 65 20 61 62 6f 76 65 one of the above
1e40: 20 61 72 65 20 64 65 66 69 6e 65 64 2c 20 74 68 are defined, th
1e50: 65 6e 20 73 65 74 20 53 51 4c 49 54 45 5f 53 59 en set SQLITE_SY
1e60: 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 61 73 0a 2a STEM_MALLOC as.*
1e70: 2a 20 74 68 65 20 64 65 66 61 75 6c 74 2e 0a 2a * the default..*
1e80: 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 /.#if defined(SQ
1e90: 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c LITE_SYSTEM_MALL
1ea0: 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 69 6e 65 OC) \. + define
1eb0: 64 28 53 51 4c 49 54 45 5f 57 49 4e 33 32 5f 4d d(SQLITE_WIN32_M
1ec0: 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 65 66 ALLOC) \. + def
1ed0: 69 6e 65 64 28 53 51 4c 49 54 45 5f 5a 45 52 4f ined(SQLITE_ZERO
1ee0: 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 64 _MALLOC) \. + d
1ef0: 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4d 45 efined(SQLITE_ME
1f00: 4d 44 45 42 55 47 29 3e 31 0a 23 20 65 72 72 6f MDEBUG)>1.# erro
1f10: 72 20 22 54 77 6f 20 6f 72 20 6d 6f 72 65 20 6f r "Two or more o
1f20: 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 f the following
1f30: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 63 6f 6e compile-time con
1f40: 66 69 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f figuration optio
1f50: 6e 73 5c 0a 20 61 72 65 20 64 65 66 69 6e 65 64 ns\. are defined
1f60: 20 62 75 74 20 61 74 20 6d 6f 73 74 20 6f 6e 65 but at most one
1f70: 20 69 73 20 61 6c 6c 6f 77 65 64 3a 5c 0a 20 53 is allowed:\. S
1f80: 51 4c 49 54 45 5f 53 59 53 54 45 4d 5f 4d 41 4c QLITE_SYSTEM_MAL
1f90: 4c 4f 43 2c 20 53 51 4c 49 54 45 5f 57 49 4e 33 LOC, SQLITE_WIN3
1fa0: 32 5f 4d 41 4c 4c 4f 43 2c 20 53 51 4c 49 54 45 2_MALLOC, SQLITE
1fb0: 5f 4d 45 4d 44 45 42 55 47 2c 5c 0a 20 53 51 4c _MEMDEBUG,\. SQL
1fc0: 49 54 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 22 ITE_ZERO_MALLOC"
1fd0: 0a 23 65 6e 64 69 66 0a 23 69 66 20 64 65 66 69 .#endif.#if defi
1fe0: 6e 65 64 28 53 51 4c 49 54 45 5f 53 59 53 54 45 ned(SQLITE_SYSTE
1ff0: 4d 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 20 2b 20 M_MALLOC) \. +
2000: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 57 defined(SQLITE_W
2010: 49 4e 33 32 5f 4d 41 4c 4c 4f 43 29 20 5c 0a 20 IN32_MALLOC) \.
2020: 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 + defined(SQLIT
2030: 45 5f 5a 45 52 4f 5f 4d 41 4c 4c 4f 43 29 20 5c E_ZERO_MALLOC) \
2040: 0a 20 20 2b 20 64 65 66 69 6e 65 64 28 53 51 4c . + defined(SQL
2050: 49 54 45 5f 4d 45 4d 44 45 42 55 47 29 3d 3d 30 ITE_MEMDEBUG)==0
2060: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
2070: 5f 53 59 53 54 45 4d 5f 4d 41 4c 4c 4f 43 20 31 _SYSTEM_MALLOC 1
2080: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 .#endif../*.** I
2090: 66 20 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 5f f SQLITE_MALLOC_
20a0: 53 4f 46 54 5f 4c 49 4d 49 54 20 69 73 20 6e 6f SOFT_LIMIT is no
20b0: 74 20 7a 65 72 6f 2c 20 74 68 65 6e 20 74 72 79 t zero, then try
20c0: 20 74 6f 20 6b 65 65 70 20 74 68 65 0a 2a 2a 20 to keep the.**
20d0: 73 69 7a 65 73 20 6f 66 20 6d 65 6d 6f 72 79 20 sizes of memory
20e0: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 62 65 6c 6f allocations belo
20f0: 77 20 74 68 69 73 20 76 61 6c 75 65 20 77 68 65 w this value whe
2100: 72 65 20 70 6f 73 73 69 62 6c 65 2e 0a 2a 2f 0a re possible..*/.
2110: 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 4c #if !defined(SQL
2120: 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f 46 54 5f ITE_MALLOC_SOFT_
2130: 4c 49 4d 49 54 29 0a 23 20 64 65 66 69 6e 65 20 LIMIT).# define
2140: 53 51 4c 49 54 45 5f 4d 41 4c 4c 4f 43 5f 53 4f SQLITE_MALLOC_SO
2150: 46 54 5f 4c 49 4d 49 54 20 31 30 32 34 0a 23 65 FT_LIMIT 1024.#e
2160: 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 57 65 20 6e ndif../*.** We n
2170: 65 65 64 20 74 6f 20 64 65 66 69 6e 65 20 5f 58 eed to define _X
2180: 4f 50 45 4e 5f 53 4f 55 52 43 45 20 61 73 20 66 OPEN_SOURCE as f
2190: 6f 6c 6c 6f 77 73 20 69 6e 20 6f 72 64 65 72 20 ollows in order
21a0: 74 6f 20 65 6e 61 62 6c 65 0a 2a 2a 20 72 65 63 to enable.** rec
21b0: 75 72 73 69 76 65 20 6d 75 74 65 78 65 73 20 6f ursive mutexes o
21c0: 6e 20 6d 6f 73 74 20 55 6e 69 78 20 73 79 73 74 n most Unix syst
21d0: 65 6d 73 20 61 6e 64 20 66 63 68 6d 6f 64 28 29 ems and fchmod()
21e0: 20 6f 6e 20 4f 70 65 6e 42 53 44 2e 0a 2a 2a 20 on OpenBSD..**
21f0: 42 75 74 20 5f 58 4f 50 45 4e 5f 53 4f 55 52 43 But _XOPEN_SOURC
2200: 45 20 64 65 66 69 6e 65 20 63 61 75 73 65 73 20 E define causes
2210: 70 72 6f 62 6c 65 6d 73 20 66 6f 72 20 4d 61 63 problems for Mac
2220: 20 4f 53 20 58 2c 20 73 6f 20 6f 6d 69 74 0a 2a OS X, so omit.*
2230: 2a 20 69 74 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 * it..*/.#if !de
2240: 66 69 6e 65 64 28 5f 58 4f 50 45 4e 5f 53 4f 55 fined(_XOPEN_SOU
2250: 52 43 45 29 20 26 26 20 21 64 65 66 69 6e 65 64 RCE) && !defined
2260: 28 5f 5f 44 41 52 57 49 4e 5f 5f 29 20 26 26 20 (__DARWIN__) &&
2270: 21 64 65 66 69 6e 65 64 28 5f 5f 41 50 50 4c 45 !defined(__APPLE
2280: 5f 5f 29 0a 23 20 20 64 65 66 69 6e 65 20 5f 58 __).# define _X
2290: 4f 50 45 4e 5f 53 4f 55 52 43 45 20 36 30 30 0a OPEN_SOURCE 600.
22a0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4e 44 #endif../*.** ND
22b0: 45 42 55 47 20 61 6e 64 20 53 51 4c 49 54 45 5f EBUG and SQLITE_
22c0: 44 45 42 55 47 20 61 72 65 20 6f 70 70 6f 73 69 DEBUG are opposi
22d0: 74 65 73 2e 20 20 49 74 20 73 68 6f 75 6c 64 20 tes. It should
22e0: 61 6c 77 61 79 73 20 62 65 20 74 72 75 65 20 74 always be true t
22f0: 68 61 74 0a 2a 2a 20 64 65 66 69 6e 65 64 28 4e hat.** defined(N
2300: 44 45 42 55 47 29 3d 3d 21 64 65 66 69 6e 65 64 DEBUG)==!defined
2310: 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 2e 20 (SQLITE_DEBUG).
2320: 20 49 66 20 74 68 69 73 20 69 73 20 6e 6f 74 20 If this is not
2330: 63 75 72 72 65 6e 74 6c 79 20 74 72 75 65 2c 0a currently true,.
2340: 2a 2a 20 6d 61 6b 65 20 69 74 20 74 72 75 65 20 ** make it true
2350: 62 79 20 64 65 66 69 6e 69 6e 67 20 6f 72 20 75 by defining or u
2360: 6e 64 65 66 69 6e 69 6e 67 20 4e 44 45 42 55 47 ndefining NDEBUG
2370: 2e 0a 2a 2a 0a 2a 2a 20 53 65 74 74 69 6e 67 20 ..**.** Setting
2380: 4e 44 45 42 55 47 20 6d 61 6b 65 73 20 74 68 65 NDEBUG makes the
2390: 20 63 6f 64 65 20 73 6d 61 6c 6c 65 72 20 61 6e code smaller an
23a0: 64 20 66 61 73 74 65 72 20 62 79 20 64 69 73 61 d faster by disa
23b0: 62 6c 69 6e 67 20 74 68 65 0a 2a 2a 20 61 73 73 bling the.** ass
23c0: 65 72 74 28 29 20 73 74 61 74 65 6d 65 6e 74 73 ert() statements
23d0: 20 69 6e 20 74 68 65 20 63 6f 64 65 2e 20 20 53 in the code. S
23e0: 6f 20 77 65 20 77 61 6e 74 20 74 68 65 20 64 65 o we want the de
23f0: 66 61 75 6c 74 20 61 63 74 69 6f 6e 0a 2a 2a 20 fault action.**
2400: 74 6f 20 62 65 20 66 6f 72 20 4e 44 45 42 55 47 to be for NDEBUG
2410: 20 74 6f 20 62 65 20 73 65 74 20 61 6e 64 20 4e to be set and N
2420: 44 45 42 55 47 20 74 6f 20 62 65 20 75 6e 64 65 DEBUG to be unde
2430: 66 69 6e 65 64 20 6f 6e 6c 79 20 69 66 20 53 51 fined only if SQ
2440: 4c 49 54 45 5f 44 45 42 55 47 0a 2a 2a 20 69 73 LITE_DEBUG.** is
2450: 20 73 65 74 2e 20 20 54 68 75 73 20 4e 44 45 42 set. Thus NDEB
2460: 55 47 20 62 65 63 6f 6d 65 73 20 61 6e 20 6f 70 UG becomes an op
2470: 74 2d 69 6e 20 72 61 74 68 65 72 20 74 68 61 6e t-in rather than
2480: 20 61 6e 20 6f 70 74 2d 6f 75 74 0a 2a 2a 20 66 an opt-out.** f
2490: 65 61 74 75 72 65 2e 0a 2a 2f 0a 23 69 66 20 21 eature..*/.#if !
24a0: 64 65 66 69 6e 65 64 28 4e 44 45 42 55 47 29 20 defined(NDEBUG)
24b0: 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
24c0: 54 45 5f 44 45 42 55 47 29 20 0a 23 20 64 65 66 TE_DEBUG) .# def
24d0: 69 6e 65 20 4e 44 45 42 55 47 20 31 0a 23 65 6e ine NDEBUG 1.#en
24e0: 64 69 66 0a 23 69 66 20 64 65 66 69 6e 65 64 28 dif.#if defined(
24f0: 4e 44 45 42 55 47 29 20 26 26 20 64 65 66 69 6e NDEBUG) && defin
2500: 65 64 28 53 51 4c 49 54 45 5f 44 45 42 55 47 29 ed(SQLITE_DEBUG)
2510: 0a 23 20 75 6e 64 65 66 20 4e 44 45 42 55 47 0a .# undef NDEBUG.
2520: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 45 6e #endif../*.** En
2530: 61 62 6c 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 able SQLITE_ENAB
2540: 4c 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 LE_EXPLAIN_COMME
2550: 4e 54 53 20 69 66 20 53 51 4c 49 54 45 5f 44 45 NTS if SQLITE_DE
2560: 42 55 47 20 69 73 20 74 75 72 6e 65 64 20 6f 6e BUG is turned on
2570: 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 69 6e 65 ..*/.#if !define
2580: 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f d(SQLITE_ENABLE_
2590: 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 4e 54 53 EXPLAIN_COMMENTS
25a0: 29 20 26 26 20 64 65 66 69 6e 65 64 28 53 51 4c ) && defined(SQL
25b0: 49 54 45 5f 44 45 42 55 47 29 0a 23 20 64 65 66 ITE_DEBUG).# def
25c0: 69 6e 65 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c ine SQLITE_ENABL
25d0: 45 5f 45 58 50 4c 41 49 4e 5f 43 4f 4d 4d 45 4e E_EXPLAIN_COMMEN
25e0: 54 53 20 31 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a TS 1.#endif../*.
25f0: 2a 2a 20 54 68 65 20 74 65 73 74 63 61 73 65 28 ** The testcase(
2600: 29 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 20 ) macro is used
2610: 74 6f 20 61 69 64 20 69 6e 20 63 6f 76 65 72 61 to aid in covera
2620: 67 65 20 74 65 73 74 69 6e 67 2e 20 20 57 68 65 ge testing. Whe
2630: 6e 20 0a 2a 2a 20 64 6f 69 6e 67 20 63 6f 76 65 n .** doing cove
2640: 72 61 67 65 20 74 65 73 74 69 6e 67 2c 20 74 68 rage testing, th
2650: 65 20 63 6f 6e 64 69 74 69 6f 6e 20 69 6e 73 69 e condition insi
2660: 64 65 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 de the argument
2670: 74 6f 0a 2a 2a 20 74 65 73 74 63 61 73 65 28 29 to.** testcase()
2680: 20 6d 75 73 74 20 62 65 20 65 76 61 6c 75 61 74 must be evaluat
2690: 65 64 20 62 6f 74 68 20 74 72 75 65 20 61 6e 64 ed both true and
26a0: 20 66 61 6c 73 65 20 69 6e 20 6f 72 64 65 72 20 false in order
26b0: 74 6f 0a 2a 2a 20 67 65 74 20 66 75 6c 6c 20 62 to.** get full b
26c0: 72 61 6e 63 68 20 63 6f 76 65 72 61 67 65 2e 20 ranch coverage.
26d0: 20 54 68 65 20 74 65 73 74 63 61 73 65 28 29 20 The testcase()
26e0: 6d 61 63 72 6f 20 69 73 20 69 6e 73 65 72 74 65 macro is inserte
26f0: 64 0a 2a 2a 20 74 6f 20 68 65 6c 70 20 65 6e 73 d.** to help ens
2700: 75 72 65 20 61 64 65 71 75 61 74 65 20 74 65 73 ure adequate tes
2710: 74 20 63 6f 76 65 72 61 67 65 20 69 6e 20 70 6c t coverage in pl
2720: 61 63 65 73 20 77 68 65 72 65 20 73 69 6d 70 6c aces where simpl
2730: 65 0a 2a 2a 20 63 6f 6e 64 69 74 69 6f 6e 2f 64 e.** condition/d
2740: 65 63 69 73 69 6f 6e 20 63 6f 76 65 72 61 67 65 ecision coverage
2750: 20 69 73 20 69 6e 61 64 65 71 75 61 74 65 2e 20 is inadequate.
2760: 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 65 For example, te
2770: 73 74 63 61 73 65 28 29 0a 2a 2a 20 63 61 6e 20 stcase().** can
2780: 62 65 20 75 73 65 64 20 74 6f 20 6d 61 6b 65 20 be used to make
2790: 73 75 72 65 20 62 6f 75 6e 64 61 72 79 20 76 61 sure boundary va
27a0: 6c 75 65 73 20 61 72 65 20 74 65 73 74 65 64 2e lues are tested.
27b0: 20 20 46 6f 72 0a 2a 2a 20 62 69 74 6d 61 73 6b For.** bitmask
27c0: 20 74 65 73 74 73 2c 20 74 65 73 74 63 61 73 65 tests, testcase
27d0: 28 29 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 () can be used t
27e0: 6f 20 6d 61 6b 65 20 73 75 72 65 20 65 61 63 68 o make sure each
27f0: 20 62 69 74 0a 2a 2a 20 69 73 20 73 69 67 6e 69 bit.** is signi
2800: 66 69 63 61 6e 74 20 61 6e 64 20 75 73 65 64 20 ficant and used
2810: 61 74 20 6c 65 61 73 74 20 6f 6e 63 65 2e 20 20 at least once.
2820: 4f 6e 20 73 77 69 74 63 68 20 73 74 61 74 65 6d On switch statem
2830: 65 6e 74 73 0a 2a 2a 20 77 68 65 72 65 20 6d 75 ents.** where mu
2840: 6c 74 69 70 6c 65 20 63 61 73 65 73 20 67 6f 20 ltiple cases go
2850: 74 6f 20 74 68 65 20 73 61 6d 65 20 62 6c 6f 63 to the same bloc
2860: 6b 20 6f 66 20 63 6f 64 65 2c 20 74 65 73 74 63 k of code, testc
2870: 61 73 65 28 29 0a 2a 2a 20 63 61 6e 20 69 6e 73 ase().** can ins
2880: 75 72 65 20 74 68 61 74 20 61 6c 6c 20 63 61 73 ure that all cas
2890: 65 73 20 61 72 65 20 65 76 61 6c 75 61 74 65 64 es are evaluated
28a0: 2e 0a 2a 2a 0a 2a 2f 0a 23 69 66 64 65 66 20 53 ..**.*/.#ifdef S
28b0: 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 5f 54 QLITE_COVERAGE_T
28c0: 45 53 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 EST. void sqlit
28d0: 65 33 43 6f 76 65 72 61 67 65 28 69 6e 74 29 3b e3Coverage(int);
28e0: 0a 23 20 64 65 66 69 6e 65 20 74 65 73 74 63 61 .# define testca
28f0: 73 65 28 58 29 20 20 69 66 28 20 58 20 29 7b 20 se(X) if( X ){
2900: 73 71 6c 69 74 65 33 43 6f 76 65 72 61 67 65 28 sqlite3Coverage(
2910: 5f 5f 4c 49 4e 45 5f 5f 29 3b 20 7d 0a 23 65 6c __LINE__); }.#el
2920: 73 65 0a 23 20 64 65 66 69 6e 65 20 74 65 73 74 se.# define test
2930: 63 61 73 65 28 58 29 0a 23 65 6e 64 69 66 0a 0a case(X).#endif..
2940: 2f 2a 0a 2a 2a 20 54 68 65 20 54 45 53 54 4f 4e /*.** The TESTON
2950: 4c 59 20 6d 61 63 72 6f 20 69 73 20 75 73 65 64 LY macro is used
2960: 20 74 6f 20 65 6e 63 6c 6f 73 65 20 76 61 72 69 to enclose vari
2970: 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f 6e able declaration
2980: 73 20 6f 72 0a 2a 2a 20 6f 74 68 65 72 20 62 69 s or.** other bi
2990: 74 73 20 6f 66 20 63 6f 64 65 20 74 68 61 74 20 ts of code that
29a0: 61 72 65 20 6e 65 65 64 65 64 20 74 6f 20 73 75 are needed to su
29b0: 70 70 6f 72 74 20 74 68 65 20 61 72 67 75 6d 65 pport the argume
29c0: 6e 74 73 0a 2a 2a 20 77 69 74 68 69 6e 20 74 65 nts.** within te
29d0: 73 74 63 61 73 65 28 29 20 61 6e 64 20 61 73 73 stcase() and ass
29e0: 65 72 74 28 29 20 6d 61 63 72 6f 73 2e 0a 2a 2f ert() macros..*/
29f0: 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 4e 44 .#if !defined(ND
2a00: 45 42 55 47 29 20 7c 7c 20 64 65 66 69 6e 65 64 EBUG) || defined
2a10: 28 53 51 4c 49 54 45 5f 43 4f 56 45 52 41 47 45 (SQLITE_COVERAGE
2a20: 5f 54 45 53 54 29 0a 23 20 64 65 66 69 6e 65 20 _TEST).# define
2a30: 54 45 53 54 4f 4e 4c 59 28 58 29 20 20 58 0a 23 TESTONLY(X) X.#
2a40: 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 54 45 else.# define TE
2a50: 53 54 4f 4e 4c 59 28 58 29 0a 23 65 6e 64 69 66 STONLY(X).#endif
2a60: 0a 0a 2f 2a 0a 2a 2a 20 53 6f 6d 65 74 69 6d 65 ../*.** Sometime
2a70: 73 20 77 65 20 6e 65 65 64 20 61 20 73 6d 61 6c s we need a smal
2a80: 6c 20 61 6d 6f 75 6e 74 20 6f 66 20 63 6f 64 65 l amount of code
2a90: 20 73 75 63 68 20 61 73 20 61 20 76 61 72 69 61 such as a varia
2aa0: 62 6c 65 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 ble initializati
2ab0: 6f 6e 0a 2a 2a 20 74 6f 20 73 65 74 75 70 20 66 on.** to setup f
2ac0: 6f 72 20 61 20 6c 61 74 65 72 20 61 73 73 65 72 or a later asser
2ad0: 74 28 29 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 t() statement.
2ae0: 57 65 20 64 6f 20 6e 6f 74 20 77 61 6e 74 20 74 We do not want t
2af0: 68 69 73 20 63 6f 64 65 20 74 6f 0a 2a 2a 20 61 his code to.** a
2b00: 70 70 65 61 72 20 77 68 65 6e 20 61 73 73 65 72 ppear when asser
2b10: 74 28 29 20 69 73 20 64 69 73 61 62 6c 65 64 2e t() is disabled.
2b20: 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 The following
2b30: 6d 61 63 72 6f 20 69 73 20 74 68 65 72 65 66 6f macro is therefo
2b40: 72 65 0a 2a 2a 20 75 73 65 64 20 74 6f 20 63 6f re.** used to co
2b50: 6e 74 61 69 6e 20 74 68 61 74 20 73 65 74 75 70 ntain that setup
2b60: 20 63 6f 64 65 2e 20 20 54 68 65 20 22 56 56 41 code. The "VVA
2b70: 22 20 61 63 72 6f 6e 79 6d 20 73 74 61 6e 64 73 " acronym stands
2b80: 20 66 6f 72 0a 2a 2a 20 22 56 65 72 69 66 69 63 for.** "Verific
2b90: 61 74 69 6f 6e 2c 20 56 61 6c 69 64 61 74 69 6f ation, Validatio
2ba0: 6e 2c 20 61 6e 64 20 41 63 63 72 65 64 69 74 61 n, and Accredita
2bb0: 74 69 6f 6e 22 2e 20 20 49 6e 20 6f 74 68 65 72 tion". In other
2bc0: 20 77 6f 72 64 73 2c 20 74 68 65 0a 2a 2a 20 63 words, the.** c
2bd0: 6f 64 65 20 77 69 74 68 69 6e 20 56 56 41 5f 4f ode within VVA_O
2be0: 4e 4c 59 28 29 20 77 69 6c 6c 20 6f 6e 6c 79 20 NLY() will only
2bf0: 72 75 6e 20 64 75 72 69 6e 67 20 76 65 72 69 66 run during verif
2c00: 69 63 61 74 69 6f 6e 20 70 72 6f 63 65 73 73 65 ication processe
2c10: 73 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 4e 44 s..*/.#ifndef ND
2c20: 45 42 55 47 0a 23 20 64 65 66 69 6e 65 20 56 56 EBUG.# define VV
2c30: 41 5f 4f 4e 4c 59 28 58 29 20 20 58 0a 23 65 6c A_ONLY(X) X.#el
2c40: 73 65 0a 23 20 64 65 66 69 6e 65 20 56 56 41 5f se.# define VVA_
2c50: 4f 4e 4c 59 28 58 29 0a 23 65 6e 64 69 66 0a 0a ONLY(X).#endif..
2c60: 2f 2a 0a 2a 2a 20 54 68 65 20 41 4c 57 41 59 53 /*.** The ALWAYS
2c70: 20 61 6e 64 20 4e 45 56 45 52 20 6d 61 63 72 6f and NEVER macro
2c80: 73 20 73 75 72 72 6f 75 6e 64 20 62 6f 6f 6c 65 s surround boole
2c90: 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 73 20 77 an expressions w
2ca0: 68 69 63 68 20 0a 2a 2a 20 61 72 65 20 69 6e 74 hich .** are int
2cb0: 65 6e 64 65 64 20 74 6f 20 61 6c 77 61 79 73 20 ended to always
2cc0: 62 65 20 74 72 75 65 20 6f 72 20 66 61 6c 73 65 be true or false
2cd0: 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 20 , respectively.
2ce0: 20 53 75 63 68 0a 2a 2a 20 65 78 70 72 65 73 73 Such.** express
2cf0: 69 6f 6e 73 20 63 6f 75 6c 64 20 62 65 20 6f 6d ions could be om
2d00: 69 74 74 65 64 20 66 72 6f 6d 20 74 68 65 20 63 itted from the c
2d10: 6f 64 65 20 63 6f 6d 70 6c 65 74 65 6c 79 2e 20 ode completely.
2d20: 20 42 75 74 20 74 68 65 79 0a 2a 2a 20 61 72 65 But they.** are
2d30: 20 69 6e 63 6c 75 64 65 64 20 69 6e 20 61 20 66 included in a f
2d40: 65 77 20 63 61 73 65 73 20 69 6e 20 6f 72 64 65 ew cases in orde
2d50: 72 20 74 6f 20 65 6e 68 61 6e 63 65 20 74 68 65 r to enhance the
2d60: 20 72 65 73 69 6c 69 65 6e 63 65 0a 2a 2a 20 6f resilience.** o
2d70: 66 20 53 51 4c 69 74 65 20 74 6f 20 75 6e 65 78 f SQLite to unex
2d80: 70 65 63 74 65 64 20 62 65 68 61 76 69 6f 72 20 pected behavior
2d90: 2d 20 74 6f 20 6d 61 6b 65 20 74 68 65 20 63 6f - to make the co
2da0: 64 65 20 22 73 65 6c 66 2d 68 65 61 6c 69 6e 67 de "self-healing
2db0: 22 0a 2a 2a 20 6f 72 20 22 64 75 63 74 69 6c 65 ".** or "ductile
2dc0: 22 20 72 61 74 68 65 72 20 74 68 61 6e 20 62 65 " rather than be
2dd0: 69 6e 67 20 22 62 72 69 74 74 6c 65 22 20 61 6e ing "brittle" an
2de0: 64 20 63 72 61 73 68 69 6e 67 20 61 74 20 74 68 d crashing at th
2df0: 65 20 66 69 72 73 74 0a 2a 2a 20 68 69 6e 74 20 e first.** hint
2e00: 6f 66 20 75 6e 70 6c 61 6e 6e 65 64 20 62 65 68 of unplanned beh
2e10: 61 76 69 6f 72 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 avior..**.** In
2e20: 6f 74 68 65 72 20 77 6f 72 64 73 2c 20 41 4c 57 other words, ALW
2e30: 41 59 53 20 61 6e 64 20 4e 45 56 45 52 20 61 72 AYS and NEVER ar
2e40: 65 20 61 64 64 65 64 20 66 6f 72 20 64 65 66 65 e added for defe
2e50: 6e 73 69 76 65 20 63 6f 64 65 2e 0a 2a 2a 0a 2a nsive code..**.*
2e60: 2a 20 57 68 65 6e 20 64 6f 69 6e 67 20 63 6f 76 * When doing cov
2e70: 65 72 61 67 65 20 74 65 73 74 69 6e 67 20 41 4c erage testing AL
2e80: 57 41 59 53 20 61 6e 64 20 4e 45 56 45 52 20 61 WAYS and NEVER a
2e90: 72 65 20 68 61 72 64 2d 63 6f 64 65 64 20 74 6f re hard-coded to
2ea0: 0a 2a 2a 20 62 65 20 74 72 75 65 20 61 6e 64 20 .** be true and
2eb0: 66 61 6c 73 65 20 73 6f 20 74 68 61 74 20 74 68 false so that th
2ec0: 65 20 75 6e 72 65 61 63 68 61 62 6c 65 20 63 6f e unreachable co
2ed0: 64 65 20 74 68 65 79 20 73 70 65 63 69 66 79 20 de they specify
2ee0: 77 69 6c 6c 0a 2a 2a 20 6e 6f 74 20 62 65 20 63 will.** not be c
2ef0: 6f 75 6e 74 65 64 20 61 73 20 75 6e 74 65 73 74 ounted as untest
2f00: 65 64 20 63 6f 64 65 2e 0a 2a 2f 0a 23 69 66 20 ed code..*/.#if
2f10: 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 43 defined(SQLITE_C
2f20: 4f 56 45 52 41 47 45 5f 54 45 53 54 29 0a 23 20 OVERAGE_TEST).#
2f30: 64 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 29 define ALWAYS(X)
2f40: 20 20 20 20 20 20 28 31 29 0a 23 20 64 65 66 69 (1).# defi
2f50: 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 20 ne NEVER(X)
2f60: 20 20 28 30 29 0a 23 65 6c 69 66 20 21 64 65 66 (0).#elif !def
2f70: 69 6e 65 64 28 4e 44 45 42 55 47 29 0a 23 20 64 ined(NDEBUG).# d
2f80: 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 29 20 efine ALWAYS(X)
2f90: 20 20 20 20 20 28 28 58 29 3f 31 3a 28 61 73 73 ((X)?1:(ass
2fa0: 65 72 74 28 30 29 2c 30 29 29 0a 23 20 64 65 66 ert(0),0)).# def
2fb0: 69 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 ine NEVER(X)
2fc0: 20 20 20 28 28 58 29 3f 28 61 73 73 65 72 74 28 ((X)?(assert(
2fd0: 30 29 2c 31 29 3a 30 29 0a 23 65 6c 73 65 0a 23 0),1):0).#else.#
2fe0: 20 64 65 66 69 6e 65 20 41 4c 57 41 59 53 28 58 define ALWAYS(X
2ff0: 29 20 20 20 20 20 20 28 58 29 0a 23 20 64 65 66 ) (X).# def
3000: 69 6e 65 20 4e 45 56 45 52 28 58 29 20 20 20 20 ine NEVER(X)
3010: 20 20 20 28 58 29 0a 23 65 6e 64 69 66 0a 0a 2f (X).#endif../
3020: 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 72 75 65 *.** Return true
3030: 20 28 6e 6f 6e 2d 7a 65 72 6f 29 20 69 66 20 74 (non-zero) if t
3040: 68 65 20 69 6e 70 75 74 20 69 73 20 61 20 69 6e he input is a in
3050: 74 65 67 65 72 20 74 68 61 74 20 69 73 20 74 6f teger that is to
3060: 6f 20 6c 61 72 67 65 0a 2a 2a 20 74 6f 20 66 69 o large.** to fi
3070: 74 20 69 6e 20 33 32 2d 62 69 74 73 2e 20 20 54 t in 32-bits. T
3080: 68 69 73 20 6d 61 63 72 6f 20 69 73 20 75 73 65 his macro is use
3090: 64 20 69 6e 73 69 64 65 20 6f 66 20 76 61 72 69 d inside of vari
30a0: 6f 75 73 20 74 65 73 74 63 61 73 65 28 29 0a 2a ous testcase().*
30b0: 2a 20 6d 61 63 72 6f 73 20 74 6f 20 76 65 72 69 * macros to veri
30c0: 66 79 20 74 68 61 74 20 77 65 20 68 61 76 65 20 fy that we have
30d0: 74 65 73 74 65 64 20 53 51 4c 69 74 65 20 66 6f tested SQLite fo
30e0: 72 20 6c 61 72 67 65 2d 66 69 6c 65 20 73 75 70 r large-file sup
30f0: 70 6f 72 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 port..*/.#define
3100: 20 49 53 5f 42 49 47 5f 49 4e 54 28 58 29 20 20 IS_BIG_INT(X)
3110: 28 28 28 58 29 26 7e 28 69 36 34 29 30 78 66 66 (((X)&~(i64)0xff
3120: 66 66 66 66 66 66 29 21 3d 30 29 0a 0a 2f 2a 0a ffffff)!=0)../*.
3130: 2a 2a 20 54 68 65 20 6d 61 63 72 6f 20 75 6e 6c ** The macro unl
3140: 69 6b 65 6c 79 28 29 20 69 73 20 61 20 68 69 6e ikely() is a hin
3150: 74 20 74 68 61 74 20 73 75 72 72 6f 75 6e 64 73 t that surrounds
3160: 20 61 20 62 6f 6f 6c 65 61 6e 0a 2a 2a 20 65 78 a boolean.** ex
3170: 70 72 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 pression that is
3180: 20 75 73 75 61 6c 6c 79 20 66 61 6c 73 65 2e 20 usually false.
3190: 20 4d 61 63 72 6f 20 6c 69 6b 65 6c 79 28 29 20 Macro likely()
31a0: 73 75 72 72 6f 75 6e 64 73 0a 2a 2a 20 61 20 62 surrounds.** a b
31b0: 6f 6f 6c 65 61 6e 20 65 78 70 72 65 73 73 69 6f oolean expressio
31c0: 6e 20 74 68 61 74 20 69 73 20 75 73 75 61 6c 6c n that is usuall
31d0: 79 20 74 72 75 65 2e 20 20 54 68 65 73 65 20 68 y true. These h
31e0: 69 6e 74 73 20 63 6f 75 6c 64 2c 0a 2a 2a 20 69 ints could,.** i
31f0: 6e 20 74 68 65 6f 72 79 2c 20 62 65 20 75 73 65 n theory, be use
3200: 64 20 62 79 20 74 68 65 20 63 6f 6d 70 69 6c 65 d by the compile
3210: 72 20 74 6f 20 67 65 6e 65 72 61 74 65 20 62 65 r to generate be
3220: 74 74 65 72 20 63 6f 64 65 2c 20 62 75 74 0a 2a tter code, but.*
3230: 2a 20 63 75 72 72 65 6e 74 6c 79 20 74 68 65 79 * currently they
3240: 20 61 72 65 20 6a 75 73 74 20 63 6f 6d 6d 65 6e are just commen
3250: 74 73 20 66 6f 72 20 68 75 6d 61 6e 20 72 65 61 ts for human rea
3260: 64 65 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ders..*/.#define
3270: 20 6c 69 6b 65 6c 79 28 58 29 20 20 20 20 28 58 likely(X) (X
3280: 29 0a 23 64 65 66 69 6e 65 20 75 6e 6c 69 6b 65 ).#define unlike
3290: 6c 79 28 58 29 20 20 28 58 29 0a 0a 23 69 6e 63 ly(X) (X)..#inc
32a0: 6c 75 64 65 20 22 68 61 73 68 2e 68 22 0a 23 69 lude "hash.h".#i
32b0: 6e 63 6c 75 64 65 20 22 70 61 72 73 65 2e 68 22 nclude "parse.h"
32c0: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f .#include <stdio
32d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 .h>.#include <st
32e0: 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 dlib.h>.#include
32f0: 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 <string.h>.#inc
3300: 6c 75 64 65 20 3c 61 73 73 65 72 74 2e 68 3e 0a lude <assert.h>.
3310: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 64 65 66 #include <stddef
3320: 2e 68 3e 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 63 6f .h>../*.** If co
3330: 6d 70 69 6c 69 6e 67 20 66 6f 72 20 61 20 70 72 mpiling for a pr
3340: 6f 63 65 73 73 6f 72 20 74 68 61 74 20 6c 61 63 ocessor that lac
3350: 6b 73 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e ks floating poin
3360: 74 20 73 75 70 70 6f 72 74 2c 0a 2a 2a 20 73 75 t support,.** su
3370: 62 73 74 69 74 75 74 65 20 69 6e 74 65 67 65 72 bstitute integer
3380: 20 66 6f 72 20 66 6c 6f 61 74 69 6e 67 2d 70 6f for floating-po
3390: 69 6e 74 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 int.*/.#ifdef SQ
33a0: 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 LITE_OMIT_FLOATI
33b0: 4e 47 5f 50 4f 49 4e 54 0a 23 20 64 65 66 69 6e NG_POINT.# defin
33c0: 65 20 64 6f 75 62 6c 65 20 73 71 6c 69 74 65 5f e double sqlite_
33d0: 69 6e 74 36 34 0a 23 20 64 65 66 69 6e 65 20 66 int64.# define f
33e0: 6c 6f 61 74 20 73 71 6c 69 74 65 5f 69 6e 74 36 loat sqlite_int6
33f0: 34 0a 23 20 64 65 66 69 6e 65 20 4c 4f 4e 47 44 4.# define LONGD
3400: 4f 55 42 4c 45 5f 54 59 50 45 20 73 71 6c 69 74 OUBLE_TYPE sqlit
3410: 65 5f 69 6e 74 36 34 0a 23 20 69 66 6e 64 65 66 e_int64.# ifndef
3420: 20 53 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a SQLITE_BIG_DBL.
3430: 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c 49 54 # define SQLIT
3440: 45 5f 42 49 47 5f 44 42 4c 20 28 28 28 73 71 6c E_BIG_DBL (((sql
3450: 69 74 65 33 5f 69 6e 74 36 34 29 31 29 3c 3c 35 ite3_int64)1)<<5
3460: 30 29 0a 23 20 65 6e 64 69 66 0a 23 20 64 65 66 0).# endif.# def
3470: 69 6e 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f ine SQLITE_OMIT_
3480: 44 41 54 45 54 49 4d 45 5f 46 55 4e 43 53 20 31 DATETIME_FUNCS 1
3490: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
34a0: 5f 4f 4d 49 54 5f 54 52 41 43 45 20 31 0a 23 20 _OMIT_TRACE 1.#
34b0: 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 49 58 undef SQLITE_MIX
34c0: 45 44 5f 45 4e 44 49 41 4e 5f 36 34 42 49 54 5f ED_ENDIAN_64BIT_
34d0: 46 4c 4f 41 54 0a 23 20 75 6e 64 65 66 20 53 51 FLOAT.# undef SQ
34e0: 4c 49 54 45 5f 48 41 56 45 5f 49 53 4e 41 4e 0a LITE_HAVE_ISNAN.
34f0: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 #endif.#ifndef S
3500: 51 4c 49 54 45 5f 42 49 47 5f 44 42 4c 0a 23 20 QLITE_BIG_DBL.#
3510: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 define SQLITE_BI
3520: 47 5f 44 42 4c 20 28 31 65 39 39 29 0a 23 65 6e G_DBL (1e99).#en
3530: 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f 4d 49 54 5f dif../*.** OMIT_
3540: 54 45 4d 50 44 42 20 69 73 20 73 65 74 20 74 6f TEMPDB is set to
3550: 20 31 20 69 66 20 53 51 4c 49 54 45 5f 4f 4d 49 1 if SQLITE_OMI
3560: 54 5f 54 45 4d 50 44 42 20 69 73 20 64 65 66 69 T_TEMPDB is defi
3570: 6e 65 64 2c 20 6f 72 20 30 0a 2a 2a 20 61 66 74 ned, or 0.** aft
3580: 65 72 77 61 72 64 2e 20 48 61 76 69 6e 67 20 74 erward. Having t
3590: 68 69 73 20 6d 61 63 72 6f 20 61 6c 6c 6f 77 73 his macro allows
35a0: 20 75 73 20 74 6f 20 63 61 75 73 65 20 74 68 65 us to cause the
35b0: 20 43 20 63 6f 6d 70 69 6c 65 72 20 0a 2a 2a 20 C compiler .**
35c0: 74 6f 20 6f 6d 69 74 20 63 6f 64 65 20 75 73 65 to omit code use
35d0: 64 20 62 79 20 54 45 4d 50 20 74 61 62 6c 65 73 d by TEMP tables
35e0: 20 77 69 74 68 6f 75 74 20 6d 65 73 73 79 20 23 without messy #
35f0: 69 66 6e 64 65 66 20 73 74 61 74 65 6d 65 6e 74 ifndef statement
3600: 73 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c s..*/.#ifdef SQL
3610: 49 54 45 5f 4f 4d 49 54 5f 54 45 4d 50 44 42 0a ITE_OMIT_TEMPDB.
3620: 23 64 65 66 69 6e 65 20 4f 4d 49 54 5f 54 45 4d #define OMIT_TEM
3630: 50 44 42 20 31 0a 23 65 6c 73 65 0a 23 64 65 66 PDB 1.#else.#def
3640: 69 6e 65 20 4f 4d 49 54 5f 54 45 4d 50 44 42 20 ine OMIT_TEMPDB
3650: 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
3660: 54 68 65 20 22 66 69 6c 65 20 66 6f 72 6d 61 74 The "file format
3670: 22 20 6e 75 6d 62 65 72 20 69 73 20 61 6e 20 69 " number is an i
3680: 6e 74 65 67 65 72 20 74 68 61 74 20 69 73 20 69 nteger that is i
3690: 6e 63 72 65 6d 65 6e 74 65 64 20 77 68 65 6e 65 ncremented whene
36a0: 76 65 72 0a 2a 2a 20 74 68 65 20 56 44 42 45 2d ver.** the VDBE-
36b0: 6c 65 76 65 6c 20 66 69 6c 65 20 66 6f 72 6d 61 level file forma
36c0: 74 20 63 68 61 6e 67 65 73 2e 20 20 54 68 65 20 t changes. The
36d0: 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 63 72 6f 73 following macros
36e0: 20 64 65 66 69 6e 65 20 74 68 65 0a 2a 2a 20 74 define the.** t
36f0: 68 65 20 64 65 66 61 75 6c 74 20 66 69 6c 65 20 he default file
3700: 66 6f 72 6d 61 74 20 66 6f 72 20 6e 65 77 20 64 format for new d
3710: 61 74 61 62 61 73 65 73 20 61 6e 64 20 74 68 65 atabases and the
3720: 20 6d 61 78 69 6d 75 6d 20 66 69 6c 65 20 66 6f maximum file fo
3730: 72 6d 61 74 0a 2a 2a 20 74 68 61 74 20 74 68 65 rmat.** that the
3740: 20 6c 69 62 72 61 72 79 20 63 61 6e 20 72 65 61 library can rea
3750: 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 d..*/.#define SQ
3760: 4c 49 54 45 5f 4d 41 58 5f 46 49 4c 45 5f 46 4f LITE_MAX_FILE_FO
3770: 52 4d 41 54 20 34 0a 23 69 66 6e 64 65 66 20 53 RMAT 4.#ifndef S
3780: 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 46 49 QLITE_DEFAULT_FI
3790: 4c 45 5f 46 4f 52 4d 41 54 0a 23 20 64 65 66 69 LE_FORMAT.# defi
37a0: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
37b0: 54 5f 46 49 4c 45 5f 46 4f 52 4d 41 54 20 34 0a T_FILE_FORMAT 4.
37c0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 65 #endif../*.** De
37d0: 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 20 termine whether
37e0: 74 72 69 67 67 65 72 73 20 61 72 65 20 72 65 63 triggers are rec
37f0: 75 72 73 69 76 65 20 62 79 20 64 65 66 61 75 6c ursive by defaul
3800: 74 2e 20 20 54 68 69 73 20 63 61 6e 20 62 65 0a t. This can be.
3810: 2a 2a 20 63 68 61 6e 67 65 64 20 61 74 20 72 75 ** changed at ru
3820: 6e 2d 74 69 6d 65 20 75 73 69 6e 67 20 61 20 70 n-time using a p
3830: 72 61 67 6d 61 2e 0a 2a 2f 0a 23 69 66 6e 64 65 ragma..*/.#ifnde
3840: 66 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 f SQLITE_DEFAULT
3850: 5f 52 45 43 55 52 53 49 56 45 5f 54 52 49 47 47 _RECURSIVE_TRIGG
3860: 45 52 53 0a 23 20 64 65 66 69 6e 65 20 53 51 4c ERS.# define SQL
3870: 49 54 45 5f 44 45 46 41 55 4c 54 5f 52 45 43 55 ITE_DEFAULT_RECU
3880: 52 53 49 56 45 5f 54 52 49 47 47 45 52 53 20 30 RSIVE_TRIGGERS 0
3890: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 50 .#endif../*.** P
38a0: 72 6f 76 69 64 65 20 61 20 64 65 66 61 75 6c 74 rovide a default
38b0: 20 76 61 6c 75 65 20 66 6f 72 20 53 51 4c 49 54 value for SQLIT
38c0: 45 5f 54 45 4d 50 5f 53 54 4f 52 45 20 69 6e 20 E_TEMP_STORE in
38d0: 63 61 73 65 20 69 74 20 69 73 20 6e 6f 74 20 73 case it is not s
38e0: 70 65 63 69 66 69 65 64 0a 2a 2a 20 6f 6e 20 74 pecified.** on t
38f0: 68 65 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 0a he command-line.
3900: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
3910: 45 5f 54 45 4d 50 5f 53 54 4f 52 45 0a 23 20 64 E_TEMP_STORE.# d
3920: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d efine SQLITE_TEM
3930: 50 5f 53 54 4f 52 45 20 31 0a 23 20 64 65 66 69 P_STORE 1.# defi
3940: 6e 65 20 53 51 4c 49 54 45 5f 54 45 4d 50 5f 53 ne SQLITE_TEMP_S
3950: 54 4f 52 45 5f 78 63 20 31 20 20 2f 2a 20 45 78 TORE_xc 1 /* Ex
3960: 63 6c 75 64 65 20 66 72 6f 6d 20 63 74 69 6d 65 clude from ctime
3970: 2e 63 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a .c */.#endif../*
3980: 0a 2a 2a 20 47 43 43 20 64 6f 65 73 20 6e 6f 74 .** GCC does not
3990: 20 64 65 66 69 6e 65 20 74 68 65 20 6f 66 66 73 define the offs
39a0: 65 74 6f 66 28 29 20 6d 61 63 72 6f 20 73 6f 20 etof() macro so
39b0: 77 65 27 6c 6c 20 68 61 76 65 20 74 6f 20 64 6f we'll have to do
39c0: 20 69 74 0a 2a 2a 20 6f 75 72 73 65 6c 76 65 73 it.** ourselves
39d0: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 6f 66 66 ..*/.#ifndef off
39e0: 73 65 74 6f 66 0a 23 64 65 66 69 6e 65 20 6f 66 setof.#define of
39f0: 66 73 65 74 6f 66 28 53 54 52 55 43 54 55 52 45 fsetof(STRUCTURE
3a00: 2c 46 49 45 4c 44 29 20 28 28 69 6e 74 29 28 28 ,FIELD) ((int)((
3a10: 63 68 61 72 2a 29 26 28 28 53 54 52 55 43 54 55 char*)&((STRUCTU
3a20: 52 45 2a 29 30 29 2d 3e 46 49 45 4c 44 29 29 0a RE*)0)->FIELD)).
3a30: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4d 61 #endif../*.** Ma
3a40: 63 72 6f 73 20 74 6f 20 63 6f 6d 70 75 74 65 20 cros to compute
3a50: 6d 69 6e 69 6d 75 6d 20 61 6e 64 20 6d 61 78 69 minimum and maxi
3a60: 6d 75 6d 20 6f 66 20 74 77 6f 20 6e 75 6d 62 65 mum of two numbe
3a70: 72 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4d rs..*/.#define M
3a80: 49 4e 28 41 2c 42 29 20 28 28 41 29 3c 28 42 29 IN(A,B) ((A)<(B)
3a90: 3f 28 41 29 3a 28 42 29 29 0a 23 64 65 66 69 6e ?(A):(B)).#defin
3aa0: 65 20 4d 41 58 28 41 2c 42 29 20 28 28 41 29 3e e MAX(A,B) ((A)>
3ab0: 28 42 29 3f 28 41 29 3a 28 42 29 29 0a 0a 2f 2a (B)?(A):(B))../*
3ac0: 0a 2a 2a 20 43 68 65 63 6b 20 74 6f 20 73 65 65 .** Check to see
3ad0: 20 69 66 20 74 68 69 73 20 6d 61 63 68 69 6e 65 if this machine
3ae0: 20 75 73 65 73 20 45 42 43 44 49 43 2e 20 20 28 uses EBCDIC. (
3af0: 59 65 73 2c 20 62 65 6c 69 65 76 65 20 69 74 20 Yes, believe it
3b00: 6f 72 0a 2a 2a 20 6e 6f 74 2c 20 74 68 65 72 65 or.** not, there
3b10: 20 61 72 65 20 73 74 69 6c 6c 20 6d 61 63 68 69 are still machi
3b20: 6e 65 73 20 6f 75 74 20 74 68 65 72 65 20 74 68 nes out there th
3b30: 61 74 20 75 73 65 20 45 42 43 44 49 43 2e 29 0a at use EBCDIC.).
3b40: 2a 2f 0a 23 69 66 20 27 41 27 20 3d 3d 20 27 5c */.#if 'A' == '\
3b50: 33 30 31 27 0a 23 20 64 65 66 69 6e 65 20 53 51 301'.# define SQ
3b60: 4c 49 54 45 5f 45 42 43 44 49 43 20 31 0a 23 65 LITE_EBCDIC 1.#e
3b70: 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 53 51 4c lse.# define SQL
3b80: 49 54 45 5f 41 53 43 49 49 20 31 0a 23 65 6e 64 ITE_ASCII 1.#end
3b90: 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 67 65 if../*.** Intege
3ba0: 72 73 20 6f 66 20 6b 6e 6f 77 6e 20 73 69 7a 65 rs of known size
3bb0: 73 2e 20 20 54 68 65 73 65 20 74 79 70 65 64 65 s. These typede
3bc0: 66 73 20 6d 69 67 68 74 20 63 68 61 6e 67 65 20 fs might change
3bd0: 66 6f 72 20 61 72 63 68 69 74 65 63 74 75 72 65 for architecture
3be0: 73 0a 2a 2a 20 77 68 65 72 65 20 74 68 65 20 73 s.** where the s
3bf0: 69 7a 65 73 20 76 65 72 79 2e 20 20 50 72 65 70 izes very. Prep
3c00: 72 6f 63 65 73 73 6f 72 20 6d 61 63 72 6f 73 20 rocessor macros
3c10: 61 72 65 20 61 76 61 69 6c 61 62 6c 65 20 73 6f are available so
3c20: 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 74 79 70 that the.** typ
3c30: 65 73 20 63 61 6e 20 62 65 20 63 6f 6e 76 65 6e es can be conven
3c40: 69 65 6e 74 6c 79 20 72 65 64 65 66 69 6e 65 64 iently redefined
3c50: 20 61 74 20 63 6f 6d 70 69 6c 65 2d 74 79 70 65 at compile-type
3c60: 2e 20 20 4c 69 6b 65 20 74 68 69 73 3a 0a 2a 2a . Like this:.**
3c70: 0a 2a 2a 20 20 20 20 20 20 20 20 20 63 63 20 27 .** cc '
3c80: 2d 44 55 49 4e 54 50 54 52 5f 54 59 50 45 3d 6c -DUINTPTR_TYPE=l
3c90: 6f 6e 67 20 6c 6f 6e 67 20 69 6e 74 27 20 2e 2e ong long int' ..
3ca0: 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 55 49 4e ..*/.#ifndef UIN
3cb0: 54 33 32 5f 54 59 50 45 0a 23 20 69 66 64 65 66 T32_TYPE.# ifdef
3cc0: 20 48 41 56 45 5f 55 49 4e 54 33 32 5f 54 0a 23 HAVE_UINT32_T.#
3cd0: 20 20 64 65 66 69 6e 65 20 55 49 4e 54 33 32 5f define UINT32_
3ce0: 54 59 50 45 20 75 69 6e 74 33 32 5f 74 0a 23 20 TYPE uint32_t.#
3cf0: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
3d00: 49 4e 54 33 32 5f 54 59 50 45 20 75 6e 73 69 67 INT32_TYPE unsig
3d10: 6e 65 64 20 69 6e 74 0a 23 20 65 6e 64 69 66 0a ned int.# endif.
3d20: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 55 #endif.#ifndef U
3d30: 49 4e 54 31 36 5f 54 59 50 45 0a 23 20 69 66 64 INT16_TYPE.# ifd
3d40: 65 66 20 48 41 56 45 5f 55 49 4e 54 31 36 5f 54 ef HAVE_UINT16_T
3d50: 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 31 .# define UINT1
3d60: 36 5f 54 59 50 45 20 75 69 6e 74 31 36 5f 74 0a 6_TYPE uint16_t.
3d70: 23 20 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 # else.# define
3d80: 20 55 49 4e 54 31 36 5f 54 59 50 45 20 75 6e 73 UINT16_TYPE uns
3d90: 69 67 6e 65 64 20 73 68 6f 72 74 20 69 6e 74 0a igned short int.
3da0: 23 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 # endif.#endif.#
3db0: 69 66 6e 64 65 66 20 49 4e 54 31 36 5f 54 59 50 ifndef INT16_TYP
3dc0: 45 0a 23 20 69 66 64 65 66 20 48 41 56 45 5f 49 E.# ifdef HAVE_I
3dd0: 4e 54 31 36 5f 54 0a 23 20 20 64 65 66 69 6e 65 NT16_T.# define
3de0: 20 49 4e 54 31 36 5f 54 59 50 45 20 69 6e 74 31 INT16_TYPE int1
3df0: 36 5f 74 0a 23 20 65 6c 73 65 0a 23 20 20 64 65 6_t.# else.# de
3e00: 66 69 6e 65 20 49 4e 54 31 36 5f 54 59 50 45 20 fine INT16_TYPE
3e10: 73 68 6f 72 74 20 69 6e 74 0a 23 20 65 6e 64 69 short int.# endi
3e20: 66 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 f.#endif.#ifndef
3e30: 20 55 49 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 UINT8_TYPE.# if
3e40: 64 65 66 20 48 41 56 45 5f 55 49 4e 54 38 5f 54 def HAVE_UINT8_T
3e50: 0a 23 20 20 64 65 66 69 6e 65 20 55 49 4e 54 38 .# define UINT8
3e60: 5f 54 59 50 45 20 75 69 6e 74 38 5f 74 0a 23 20 _TYPE uint8_t.#
3e70: 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 20 55 else.# define U
3e80: 49 4e 54 38 5f 54 59 50 45 20 75 6e 73 69 67 6e INT8_TYPE unsign
3e90: 65 64 20 63 68 61 72 0a 23 20 65 6e 64 69 66 0a ed char.# endif.
3ea0: 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 49 #endif.#ifndef I
3eb0: 4e 54 38 5f 54 59 50 45 0a 23 20 69 66 64 65 66 NT8_TYPE.# ifdef
3ec0: 20 48 41 56 45 5f 49 4e 54 38 5f 54 0a 23 20 20 HAVE_INT8_T.#
3ed0: 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 50 45 define INT8_TYPE
3ee0: 20 69 6e 74 38 5f 74 0a 23 20 65 6c 73 65 0a 23 int8_t.# else.#
3ef0: 20 20 64 65 66 69 6e 65 20 49 4e 54 38 5f 54 59 define INT8_TY
3f00: 50 45 20 73 69 67 6e 65 64 20 63 68 61 72 0a 23 PE signed char.#
3f10: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 23 69 endif.#endif.#i
3f20: 66 6e 64 65 66 20 4c 4f 4e 47 44 4f 55 42 4c 45 fndef LONGDOUBLE
3f30: 5f 54 59 50 45 0a 23 20 64 65 66 69 6e 65 20 4c _TYPE.# define L
3f40: 4f 4e 47 44 4f 55 42 4c 45 5f 54 59 50 45 20 6c ONGDOUBLE_TYPE l
3f50: 6f 6e 67 20 64 6f 75 62 6c 65 0a 23 65 6e 64 69 ong double.#endi
3f60: 66 0a 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 f.typedef sqlite
3f70: 5f 69 6e 74 36 34 20 69 36 34 3b 20 20 20 20 20 _int64 i64;
3f80: 20 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 73 /* 8-byte s
3f90: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a 2f igned integer */
3fa0: 0a 74 79 70 65 64 65 66 20 73 71 6c 69 74 65 5f .typedef sqlite_
3fb0: 75 69 6e 74 36 34 20 75 36 34 3b 20 20 20 20 20 uint64 u64;
3fc0: 20 20 20 20 2f 2a 20 38 2d 62 79 74 65 20 75 6e /* 8-byte un
3fd0: 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 2a signed integer *
3fe0: 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 33 32 /.typedef UINT32
3ff0: 5f 54 59 50 45 20 75 33 32 3b 20 20 20 20 20 20 _TYPE u32;
4000: 20 20 20 20 20 2f 2a 20 34 2d 62 79 74 65 20 75 /* 4-byte u
4010: 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 nsigned integer
4020: 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 31 */.typedef UINT1
4030: 36 5f 54 59 50 45 20 75 31 36 3b 20 20 20 20 20 6_TYPE u16;
4040: 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 20 /* 2-byte
4050: 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 unsigned integer
4060: 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 */.typedef INT1
4070: 36 5f 54 59 50 45 20 69 31 36 3b 20 20 20 20 20 6_TYPE i16;
4080: 20 20 20 20 20 20 20 2f 2a 20 32 2d 62 79 74 65 /* 2-byte
4090: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 signed integer
40a0: 2a 2f 0a 74 79 70 65 64 65 66 20 55 49 4e 54 38 */.typedef UINT8
40b0: 5f 54 59 50 45 20 75 38 3b 20 20 20 20 20 20 20 _TYPE u8;
40c0: 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 20 /* 1-byte
40d0: 75 6e 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 unsigned integer
40e0: 20 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 38 */.typedef INT8
40f0: 5f 54 59 50 45 20 69 38 3b 20 20 20 20 20 20 20 _TYPE i8;
4100: 20 20 20 20 20 20 20 2f 2a 20 31 2d 62 79 74 65 /* 1-byte
4110: 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 20 signed integer
4120: 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 53 51 4c 49 54 45 */../*.** SQLITE
4130: 5f 4d 41 58 5f 55 33 32 20 69 73 20 61 20 75 36 _MAX_U32 is a u6
4140: 34 20 63 6f 6e 73 74 61 6e 74 20 74 68 61 74 20 4 constant that
4150: 69 73 20 74 68 65 20 6d 61 78 69 6d 75 6d 20 75 is the maximum u
4160: 36 34 20 76 61 6c 75 65 0a 2a 2a 20 74 68 61 74 64 value.** that
4170: 20 63 61 6e 20 62 65 20 73 74 6f 72 65 64 20 69 can be stored i
4180: 6e 20 61 20 75 33 32 20 77 69 74 68 6f 75 74 20 n a u32 without
4190: 6c 6f 73 73 20 6f 66 20 64 61 74 61 2e 20 20 54 loss of data. T
41a0: 68 65 20 76 61 6c 75 65 0a 2a 2a 20 69 73 20 30 he value.** is 0
41b0: 78 30 30 30 30 30 30 30 30 66 66 66 66 66 66 66 x00000000fffffff
41c0: 66 2e 20 20 42 75 74 20 62 65 63 61 75 73 65 20 f. But because
41d0: 6f 66 20 71 75 69 72 6b 73 20 6f 66 20 73 6f 6d of quirks of som
41e0: 65 20 63 6f 6d 70 69 6c 65 72 73 2c 20 77 65 0a e compilers, we.
41f0: 2a 2a 20 68 61 76 65 20 74 6f 20 73 70 65 63 69 ** have to speci
4200: 66 79 20 74 68 65 20 76 61 6c 75 65 20 69 6e 20 fy the value in
4210: 74 68 65 20 6c 65 73 73 20 69 6e 74 75 69 74 69 the less intuiti
4220: 76 65 20 6d 61 6e 6e 65 72 20 73 68 6f 77 6e 3a ve manner shown:
4230: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
4240: 54 45 5f 4d 41 58 5f 55 33 32 20 20 28 28 28 28 TE_MAX_U32 ((((
4250: 75 36 34 29 31 29 3c 3c 33 32 29 2d 31 29 0a 0a u64)1)<<32)-1)..
4260: 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 61 74 79 /*.** The dataty
4270: 70 65 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 pe used to store
4280: 20 65 73 74 69 6d 61 74 65 73 20 6f 66 20 74 68 estimates of th
4290: 65 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 e number of rows
42a0: 20 69 6e 20 61 0a 2a 2a 20 74 61 62 6c 65 20 6f in a.** table o
42b0: 72 20 69 6e 64 65 78 2e 20 20 54 68 69 73 20 69 r index. This i
42c0: 73 20 61 6e 20 75 6e 73 69 67 6e 65 64 20 69 6e s an unsigned in
42d0: 74 65 67 65 72 20 74 79 70 65 2e 20 20 46 6f 72 teger type. For
42e0: 20 39 39 2e 39 25 20 6f 66 0a 2a 2a 20 74 68 65 99.9% of.** the
42f0: 20 77 6f 72 6c 64 2c 20 61 20 33 32 2d 62 69 74 world, a 32-bit
4300: 20 69 6e 74 65 67 65 72 20 69 73 20 73 75 66 66 integer is suff
4310: 69 63 69 65 6e 74 2e 20 20 42 75 74 20 61 20 36 icient. But a 6
4320: 34 2d 62 69 74 20 69 6e 74 65 67 65 72 0a 2a 2a 4-bit integer.**
4330: 20 63 61 6e 20 62 65 20 75 73 65 64 20 61 74 20 can be used at
4340: 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 20 69 66 20 compile-time if
4350: 64 65 73 69 72 65 64 2e 0a 2a 2f 0a 23 69 66 64 desired..*/.#ifd
4360: 65 66 20 53 51 4c 49 54 45 5f 36 34 42 49 54 5f ef SQLITE_64BIT_
4370: 53 54 41 54 53 0a 20 74 79 70 65 64 65 66 20 75 STATS. typedef u
4380: 36 34 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 64 tRowcnt; /
4390: 2a 20 36 34 2d 62 69 74 20 6f 6e 6c 79 20 69 66 * 64-bit only if
43a0: 20 72 65 71 75 65 73 74 65 64 20 61 74 20 63 6f requested at co
43b0: 6d 70 69 6c 65 2d 74 69 6d 65 20 2a 2f 0a 23 65 mpile-time */.#e
43c0: 6c 73 65 0a 20 74 79 70 65 64 65 66 20 75 33 32 lse. typedef u32
43d0: 20 74 52 6f 77 63 6e 74 3b 20 20 20 20 2f 2a 20 tRowcnt; /*
43e0: 33 32 2d 62 69 74 20 69 73 20 74 68 65 20 64 65 32-bit is the de
43f0: 66 61 75 6c 74 20 2a 2f 0a 23 65 6e 64 69 66 0a fault */.#endif.
4400: 0a 2f 2a 0a 2a 2a 20 45 73 74 69 6d 61 74 65 64 ./*.** Estimated
4410: 20 71 75 61 6e 74 69 74 69 65 73 20 75 73 65 64 quantities used
4420: 20 66 6f 72 20 71 75 65 72 79 20 70 6c 61 6e 6e for query plann
4430: 69 6e 67 20 61 72 65 20 73 74 6f 72 65 64 20 61 ing are stored a
4440: 73 20 31 36 2d 62 69 74 0a 2a 2a 20 6c 6f 67 61 s 16-bit.** loga
4450: 72 69 74 68 6d 73 2e 20 20 46 6f 72 20 71 75 61 rithms. For qua
4460: 6e 74 69 74 79 20 58 2c 20 74 68 65 20 76 61 6c ntity X, the val
4470: 75 65 20 73 74 6f 72 65 64 20 69 73 20 31 30 2a ue stored is 10*
4480: 6c 6f 67 32 28 58 29 2e 20 20 54 68 69 73 0a 2a log2(X). This.*
4490: 2a 20 67 69 76 65 73 20 61 20 70 6f 73 73 69 62 * gives a possib
44a0: 6c 65 20 72 61 6e 67 65 20 6f 66 20 76 61 6c 75 le range of valu
44b0: 65 73 20 6f 66 20 61 70 70 72 6f 78 69 6d 61 74 es of approximat
44c0: 65 6c 79 20 31 2e 30 65 39 38 36 20 74 6f 20 31 ely 1.0e986 to 1
44d0: 65 2d 39 38 36 2e 0a 2a 2a 20 42 75 74 20 74 68 e-986..** But th
44e0: 65 20 61 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 e allowed values
44f0: 20 61 72 65 20 22 67 72 61 69 6e 79 22 2e 20 20 are "grainy".
4500: 4e 6f 74 20 65 76 65 72 79 20 76 61 6c 75 65 20 Not every value
4510: 69 73 20 72 65 70 72 65 73 65 6e 74 61 62 6c 65 is representable
4520: 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c 65 ..** For example
4530: 2c 20 71 75 61 6e 74 69 74 69 65 73 20 31 36 20 , quantities 16
4540: 61 6e 64 20 31 37 20 61 72 65 20 62 6f 74 68 20 and 17 are both
4550: 72 65 70 72 65 73 65 6e 74 65 64 20 62 79 20 61 represented by a
4560: 20 4c 6f 67 45 73 74 0a 2a 2a 20 6f 66 20 34 30 LogEst.** of 40
4570: 2e 20 20 48 6f 77 65 76 65 72 2c 20 73 69 6e 63 . However, sinc
4580: 65 20 4c 6f 67 45 73 74 20 71 75 61 6e 74 61 74 e LogEst quantat
4590: 69 65 73 20 61 72 65 20 73 75 70 70 6f 73 65 20 ies are suppose
45a0: 74 6f 20 62 65 20 65 73 74 69 6d 61 74 65 73 2c to be estimates,
45b0: 0a 2a 2a 20 6e 6f 74 20 65 78 61 63 74 20 76 61 .** not exact va
45c0: 6c 75 65 73 2c 20 74 68 69 73 20 69 6d 70 72 65 lues, this impre
45d0: 63 69 73 69 6f 6e 20 69 73 20 6e 6f 74 20 61 20 cision is not a
45e0: 70 72 6f 62 6c 65 6d 2e 0a 2a 2a 0a 2a 2a 20 22 problem..**.** "
45f0: 4c 6f 67 45 73 74 22 20 69 73 20 73 68 6f 72 74 LogEst" is short
4600: 20 66 6f 72 20 22 4c 6f 67 61 72 69 74 68 6d 69 for "Logarithmi
4610: 63 20 45 73 74 69 6d 61 74 65 22 2e 0a 2a 2a 0a c Estimate"..**.
4620: 2a 2a 20 45 78 61 6d 70 6c 65 73 3a 0a 2a 2a 20 ** Examples:.**
4630: 20 20 20 20 20 31 20 2d 3e 20 30 20 20 20 20 20 1 -> 0
4640: 20 20 20 20 20 20 20 20 20 32 30 20 2d 3e 20 34 20 -> 4
4650: 33 20 20 20 20 20 20 20 20 20 20 31 30 30 30 30 3 10000
4660: 20 2d 3e 20 31 33 32 0a 2a 2a 20 20 20 20 20 20 -> 132.**
4670: 32 20 2d 3e 20 31 30 20 20 20 20 20 20 20 20 20 2 -> 10
4680: 20 20 20 20 32 35 20 2d 3e 20 34 36 20 20 20 20 25 -> 46
4690: 20 20 20 20 20 20 32 35 30 30 30 20 2d 3e 20 31 25000 -> 1
46a0: 34 36 0a 2a 2a 20 20 20 20 20 20 33 20 2d 3e 20 46.** 3 ->
46b0: 31 36 20 20 20 20 20 20 20 20 20 20 20 20 31 30 16 10
46c0: 30 20 2d 3e 20 36 36 20 20 20 20 20 20 20 20 31 0 -> 66 1
46d0: 30 30 30 30 30 30 20 2d 3e 20 31 39 39 0a 2a 2a 000000 -> 199.**
46e0: 20 20 20 20 20 20 34 20 2d 3e 20 32 30 20 20 20 4 -> 20
46f0: 20 20 20 20 20 20 20 20 31 30 30 30 20 2d 3e 20 1000 ->
4700: 39 39 20 20 20 20 20 20 20 20 31 30 34 38 35 37 99 104857
4710: 36 20 2d 3e 20 32 30 30 0a 2a 2a 20 20 20 20 20 6 -> 200.**
4720: 31 30 20 2d 3e 20 33 33 20 20 20 20 20 20 20 20 10 -> 33
4730: 20 20 20 31 30 32 34 20 2d 3e 20 31 30 30 20 20 1024 -> 100
4740: 20 20 34 32 39 34 39 36 37 32 39 36 20 2d 3e 20 4294967296 ->
4750: 33 32 30 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c 6f 320.**.** The Lo
4760: 67 45 73 74 20 63 61 6e 20 62 65 20 6e 65 67 61 gEst can be nega
4770: 74 69 76 65 20 74 6f 20 69 6e 64 69 63 61 74 65 tive to indicate
4780: 20 66 72 61 63 74 69 6f 6e 61 6c 20 76 61 6c 75 fractional valu
4790: 65 73 2e 20 0a 2a 2a 20 45 78 61 6d 70 6c 65 73 es. .** Examples
47a0: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 30 2e 35 20 2d :.**.** 0.5 -
47b0: 3e 20 2d 31 30 20 20 20 20 20 20 20 20 20 20 20 > -10
47c0: 30 2e 31 20 2d 3e 20 2d 33 33 20 20 20 20 20 20 0.1 -> -33
47d0: 20 20 30 2e 30 36 32 35 20 2d 3e 20 2d 34 30 0a 0.0625 -> -40.
47e0: 2a 2f 0a 74 79 70 65 64 65 66 20 49 4e 54 31 36 */.typedef INT16
47f0: 5f 54 59 50 45 20 4c 6f 67 45 73 74 3b 0a 0a 2f _TYPE LogEst;../
4800: 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 74 6f 20 64 *.** Macros to d
4810: 65 74 65 72 6d 69 6e 65 20 77 68 65 74 68 65 72 etermine whether
4820: 20 74 68 65 20 6d 61 63 68 69 6e 65 20 69 73 20 the machine is
4830: 62 69 67 20 6f 72 20 6c 69 74 74 6c 65 20 65 6e big or little en
4840: 64 69 61 6e 2c 0a 2a 2a 20 61 6e 64 20 77 68 65 dian,.** and whe
4850: 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 61 74 ther or not that
4860: 20 64 65 74 65 72 6d 69 6e 61 74 69 6f 6e 20 69 determination i
4870: 73 20 72 75 6e 2d 74 69 6d 65 20 6f 72 20 63 6f s run-time or co
4880: 6d 70 69 6c 65 2d 74 69 6d 65 2e 0a 2a 2a 0a 2a mpile-time..**.*
4890: 2a 20 46 6f 72 20 62 65 73 74 20 70 65 72 66 6f * For best perfo
48a0: 72 6d 61 6e 63 65 2c 20 61 6e 20 61 74 74 65 6d rmance, an attem
48b0: 70 74 20 69 73 20 6d 61 64 65 20 74 6f 20 67 75 pt is made to gu
48c0: 65 73 73 20 61 74 20 74 68 65 20 62 79 74 65 2d ess at the byte-
48d0: 6f 72 64 65 72 0a 2a 2a 20 75 73 69 6e 67 20 43 order.** using C
48e0: 2d 70 72 65 70 72 6f 63 65 73 73 6f 72 20 6d 61 -preprocessor ma
48f0: 63 72 6f 73 2e 20 20 49 66 20 74 68 61 74 20 69 cros. If that i
4900: 73 20 75 6e 73 75 63 63 65 73 73 66 75 6c 2c 20 s unsuccessful,
4910: 6f 72 20 69 66 0a 2a 2a 20 2d 44 53 51 4c 49 54 or if.** -DSQLIT
4920: 45 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 E_RUNTIME_BYTEOR
4930: 44 45 52 3d 31 20 69 73 20 73 65 74 2c 20 74 68 DER=1 is set, th
4940: 65 6e 20 62 79 74 65 2d 6f 72 64 65 72 20 69 73 en byte-order is
4950: 20 64 65 74 65 72 6d 69 6e 65 64 0a 2a 2a 20 61 determined.** a
4960: 74 20 72 75 6e 2d 74 69 6d 65 2e 0a 2a 2f 0a 23 t run-time..*/.#
4970: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 ifdef SQLITE_AMA
4980: 4c 47 41 4d 41 54 49 4f 4e 0a 63 6f 6e 73 74 20 LGAMATION.const
4990: 69 6e 74 20 73 71 6c 69 74 65 33 6f 6e 65 20 3d int sqlite3one =
49a0: 20 31 3b 0a 23 65 6c 73 65 0a 65 78 74 65 72 6e 1;.#else.extern
49b0: 20 63 6f 6e 73 74 20 69 6e 74 20 73 71 6c 69 74 const int sqlit
49c0: 65 33 6f 6e 65 3b 0a 23 65 6e 64 69 66 0a 23 69 e3one;.#endif.#i
49d0: 66 20 28 64 65 66 69 6e 65 64 28 69 33 38 36 29 f (defined(i386)
49e0: 20 20 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 || defined(
49f0: 5f 5f 69 33 38 36 5f 5f 29 20 20 20 7c 7c 20 64 __i386__) || d
4a00: 65 66 69 6e 65 64 28 5f 4d 5f 49 58 38 36 29 20 efined(_M_IX86)
4a10: 7c 7c 20 20 20 20 5c 0a 20 20 20 20 20 64 65 66 || \. def
4a20: 69 6e 65 64 28 5f 5f 78 38 36 5f 36 34 29 20 7c ined(__x86_64) |
4a30: 7c 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 5f | defined(__x86_
4a40: 36 34 5f 5f 29 20 7c 7c 20 64 65 66 69 6e 65 64 64__) || defined
4a50: 28 5f 4d 5f 58 36 34 29 20 20 7c 7c 20 20 20 20 (_M_X64) ||
4a60: 5c 0a 20 20 20 20 20 64 65 66 69 6e 65 64 28 5f \. defined(_
4a70: 4d 5f 41 4d 44 36 34 29 20 7c 7c 20 64 65 66 69 M_AMD64) || defi
4a80: 6e 65 64 28 5f 4d 5f 41 52 4d 29 20 20 20 20 20 ned(_M_ARM)
4a90: 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 78 38 36 || defined(__x86
4aa0: 29 20 20 20 7c 7c 20 20 20 20 5c 0a 20 20 20 20 ) || \.
4ab0: 20 64 65 66 69 6e 65 64 28 5f 5f 61 72 6d 5f 5f defined(__arm__
4ac0: 29 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 )) && !defined(S
4ad0: 51 4c 49 54 45 5f 52 55 4e 54 49 4d 45 5f 42 59 QLITE_RUNTIME_BY
4ae0: 54 45 4f 52 44 45 52 29 0a 23 20 64 65 66 69 6e TEORDER).# defin
4af0: 65 20 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 e SQLITE_BYTEORD
4b00: 45 52 20 20 20 20 31 32 33 34 0a 23 20 64 65 66 ER 1234.# def
4b10: 69 6e 65 20 53 51 4c 49 54 45 5f 42 49 47 45 4e ine SQLITE_BIGEN
4b20: 44 49 41 4e 20 20 20 20 30 0a 23 20 64 65 66 69 DIAN 0.# defi
4b30: 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c 45 ne SQLITE_LITTLE
4b40: 45 4e 44 49 41 4e 20 31 0a 23 20 64 65 66 69 6e ENDIAN 1.# defin
4b50: 65 20 53 51 4c 49 54 45 5f 55 54 46 31 36 4e 41 e SQLITE_UTF16NA
4b60: 54 49 56 45 20 20 53 51 4c 49 54 45 5f 55 54 46 TIVE SQLITE_UTF
4b70: 31 36 4c 45 0a 23 65 6e 64 69 66 0a 23 69 66 20 16LE.#endif.#if
4b80: 28 64 65 66 69 6e 65 64 28 73 70 61 72 63 29 20 (defined(sparc)
4b90: 20 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f || defined(__
4ba0: 70 70 63 5f 5f 29 29 20 20 5c 0a 20 20 20 20 26 ppc__)) \. &
4bb0: 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 & !defined(SQLIT
4bc0: 45 5f 52 55 4e 54 49 4d 45 5f 42 59 54 45 4f 52 E_RUNTIME_BYTEOR
4bd0: 44 45 52 29 0a 23 20 64 65 66 69 6e 65 20 53 51 DER).# define SQ
4be0: 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 20 20 LITE_BYTEORDER
4bf0: 20 20 34 33 32 31 0a 23 20 64 65 66 69 6e 65 20 4321.# define
4c00: 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 41 4e SQLITE_BIGENDIAN
4c10: 20 20 20 20 31 0a 23 20 64 65 66 69 6e 65 20 53 1.# define S
4c20: 51 4c 49 54 45 5f 4c 49 54 54 4c 45 45 4e 44 49 QLITE_LITTLEENDI
4c30: 41 4e 20 30 0a 23 20 64 65 66 69 6e 65 20 53 51 AN 0.# define SQ
4c40: 4c 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 LITE_UTF16NATIVE
4c50: 20 20 53 51 4c 49 54 45 5f 55 54 46 31 36 42 45 SQLITE_UTF16BE
4c60: 0a 23 65 6e 64 69 66 0a 23 69 66 20 21 64 65 66 .#endif.#if !def
4c70: 69 6e 65 64 28 53 51 4c 49 54 45 5f 42 59 54 45 ined(SQLITE_BYTE
4c80: 4f 52 44 45 52 29 0a 23 20 64 65 66 69 6e 65 20 ORDER).# define
4c90: 53 51 4c 49 54 45 5f 42 59 54 45 4f 52 44 45 52 SQLITE_BYTEORDER
4ca0: 20 20 20 20 30 20 20 20 20 20 2f 2a 20 30 20 6d 0 /* 0 m
4cb0: 65 61 6e 73 20 22 75 6e 6b 6e 6f 77 6e 20 61 74 eans "unknown at
4cc0: 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 22 20 2a compile-time" *
4cd0: 2f 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 /.# define SQLIT
4ce0: 45 5f 42 49 47 45 4e 44 49 41 4e 20 20 20 20 28 E_BIGENDIAN (
4cf0: 2a 28 63 68 61 72 20 2a 29 28 26 73 71 6c 69 74 *(char *)(&sqlit
4d00: 65 33 6f 6e 65 29 3d 3d 30 29 0a 23 20 64 65 66 e3one)==0).# def
4d10: 69 6e 65 20 53 51 4c 49 54 45 5f 4c 49 54 54 4c ine SQLITE_LITTL
4d20: 45 45 4e 44 49 41 4e 20 28 2a 28 63 68 61 72 20 EENDIAN (*(char
4d30: 2a 29 28 26 73 71 6c 69 74 65 33 6f 6e 65 29 3d *)(&sqlite3one)=
4d40: 3d 31 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c =1).# define SQL
4d50: 49 54 45 5f 55 54 46 31 36 4e 41 54 49 56 45 20 ITE_UTF16NATIVE
4d60: 20 28 53 51 4c 49 54 45 5f 42 49 47 45 4e 44 49 (SQLITE_BIGENDI
4d70: 41 4e 3f 53 51 4c 49 54 45 5f 55 54 46 31 36 42 AN?SQLITE_UTF16B
4d80: 45 3a 53 51 4c 49 54 45 5f 55 54 46 31 36 4c 45 E:SQLITE_UTF16LE
4d90: 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 ).#endif../*.**
4da0: 43 6f 6e 73 74 61 6e 74 73 20 66 6f 72 20 74 68 Constants for th
4db0: 65 20 6c 61 72 67 65 73 74 20 61 6e 64 20 73 6d e largest and sm
4dc0: 61 6c 6c 65 73 74 20 70 6f 73 73 69 62 6c 65 20 allest possible
4dd0: 36 34 2d 62 69 74 20 73 69 67 6e 65 64 20 69 6e 64-bit signed in
4de0: 74 65 67 65 72 73 2e 0a 2a 2a 20 54 68 65 73 65 tegers..** These
4df0: 20 6d 61 63 72 6f 73 20 61 72 65 20 64 65 73 69 macros are desi
4e00: 67 6e 65 64 20 74 6f 20 77 6f 72 6b 20 63 6f 72 gned to work cor
4e10: 72 65 63 74 6c 79 20 6f 6e 20 62 6f 74 68 20 33 rectly on both 3
4e20: 32 2d 62 69 74 20 61 6e 64 20 36 34 2d 62 69 74 2-bit and 64-bit
4e30: 0a 2a 2a 20 63 6f 6d 70 69 6c 65 72 73 2e 0a 2a .** compilers..*
4e40: 2f 0a 23 64 65 66 69 6e 65 20 4c 41 52 47 45 53 /.#define LARGES
4e50: 54 5f 49 4e 54 36 34 20 20 28 30 78 66 66 66 66 T_INT64 (0xffff
4e60: 66 66 66 66 7c 28 28 28 69 36 34 29 30 78 37 66 ffff|(((i64)0x7f
4e70: 66 66 66 66 66 66 29 3c 3c 33 32 29 29 0a 23 64 ffffff)<<32)).#d
4e80: 65 66 69 6e 65 20 53 4d 41 4c 4c 45 53 54 5f 49 efine SMALLEST_I
4e90: 4e 54 36 34 20 28 28 28 69 36 34 29 2d 31 29 20 NT64 (((i64)-1)
4ea0: 2d 20 4c 41 52 47 45 53 54 5f 49 4e 54 36 34 29 - LARGEST_INT64)
4eb0: 0a 0a 2f 2a 20 0a 2a 2a 20 52 6f 75 6e 64 20 75 ../* .** Round u
4ec0: 70 20 61 20 6e 75 6d 62 65 72 20 74 6f 20 74 68 p a number to th
4ed0: 65 20 6e 65 78 74 20 6c 61 72 67 65 72 20 6d 75 e next larger mu
4ee0: 6c 74 69 70 6c 65 20 6f 66 20 38 2e 20 20 54 68 ltiple of 8. Th
4ef0: 69 73 20 69 73 20 75 73 65 64 0a 2a 2a 20 74 6f is is used.** to
4f00: 20 66 6f 72 63 65 20 38 2d 62 79 74 65 20 61 6c force 8-byte al
4f10: 69 67 6e 6d 65 6e 74 20 6f 6e 20 36 34 2d 62 69 ignment on 64-bi
4f20: 74 20 61 72 63 68 69 74 65 63 74 75 72 65 73 2e t architectures.
4f30: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 52 4f 55 4e .*/.#define ROUN
4f40: 44 38 28 78 29 20 20 20 20 20 28 28 28 78 29 2b D8(x) (((x)+
4f50: 37 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 52 6f 7)&~7)../*.** Ro
4f60: 75 6e 64 20 64 6f 77 6e 20 74 6f 20 74 68 65 20 und down to the
4f70: 6e 65 61 72 65 73 74 20 6d 75 6c 74 69 70 6c 65 nearest multiple
4f80: 20 6f 66 20 38 0a 2a 2f 0a 23 64 65 66 69 6e 65 of 8.*/.#define
4f90: 20 52 4f 55 4e 44 44 4f 57 4e 38 28 78 29 20 28 ROUNDDOWN8(x) (
4fa0: 28 78 29 26 7e 37 29 0a 0a 2f 2a 0a 2a 2a 20 41 (x)&~7)../*.** A
4fb0: 73 73 65 72 74 20 74 68 61 74 20 74 68 65 20 70 ssert that the p
4fc0: 6f 69 6e 74 65 72 20 58 20 69 73 20 61 6c 69 67 ointer X is alig
4fd0: 6e 65 64 20 74 6f 20 61 6e 20 38 2d 62 79 74 65 ned to an 8-byte
4fe0: 20 62 6f 75 6e 64 61 72 79 2e 20 20 54 68 69 73 boundary. This
4ff0: 0a 2a 2a 20 6d 61 63 72 6f 20 69 73 20 75 73 65 .** macro is use
5000: 64 20 6f 6e 6c 79 20 77 69 74 68 69 6e 20 61 73 d only within as
5010: 73 65 72 74 28 29 20 74 6f 20 76 65 72 69 66 79 sert() to verify
5020: 20 74 68 61 74 20 74 68 65 20 63 6f 64 65 20 67 that the code g
5030: 65 74 73 0a 2a 2a 20 61 6c 6c 20 61 6c 69 67 6e ets.** all align
5040: 6d 65 6e 74 20 72 65 73 74 72 69 63 74 69 6f 6e ment restriction
5050: 73 20 63 6f 72 72 65 63 74 2e 0a 2a 2a 0a 2a 2a s correct..**.**
5060: 20 45 78 63 65 70 74 2c 20 69 66 20 53 51 4c 49 Except, if SQLI
5070: 54 45 5f 34 5f 42 59 54 45 5f 41 4c 49 47 4e 45 TE_4_BYTE_ALIGNE
5080: 44 5f 4d 41 4c 4c 4f 43 20 69 73 20 64 65 66 69 D_MALLOC is defi
5090: 6e 65 64 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a ned, then the.**
50a0: 20 75 6e 64 65 72 6c 79 69 6e 67 20 6d 61 6c 6c underlying mall
50b0: 6f 63 28 29 20 69 6d 70 6c 65 6d 65 6e 74 69 6f oc() implementio
50c0: 6e 20 6d 69 67 68 74 20 72 65 74 75 72 6e 20 75 n might return u
50d0: 73 20 34 2d 62 79 74 65 20 61 6c 69 67 6e 65 64 s 4-byte aligned
50e0: 0a 2a 2a 20 70 6f 69 6e 74 65 72 73 2e 20 20 49 .** pointers. I
50f0: 6e 20 74 68 61 74 20 63 61 73 65 2c 20 6f 6e 6c n that case, onl
5100: 79 20 76 65 72 69 66 79 20 34 2d 62 79 74 65 20 y verify 4-byte
5110: 61 6c 69 67 6e 6d 65 6e 74 2e 0a 2a 2f 0a 23 69 alignment..*/.#i
5120: 66 64 65 66 20 53 51 4c 49 54 45 5f 34 5f 42 59 fdef SQLITE_4_BY
5130: 54 45 5f 41 4c 49 47 4e 45 44 5f 4d 41 4c 4c 4f TE_ALIGNED_MALLO
5140: 43 0a 23 20 64 65 66 69 6e 65 20 45 49 47 48 54 C.# define EIGHT
5150: 5f 42 59 54 45 5f 41 4c 49 47 4e 4d 45 4e 54 28 _BYTE_ALIGNMENT(
5160: 58 29 20 20 20 28 28 28 28 63 68 61 72 2a 29 28 X) ((((char*)(
5170: 58 29 20 2d 20 28 63 68 61 72 2a 29 30 29 26 33 X) - (char*)0)&3
5180: 29 3d 3d 30 29 0a 23 65 6c 73 65 0a 23 20 64 65 )==0).#else.# de
5190: 66 69 6e 65 20 45 49 47 48 54 5f 42 59 54 45 5f fine EIGHT_BYTE_
51a0: 41 4c 49 47 4e 4d 45 4e 54 28 58 29 20 20 20 28 ALIGNMENT(X) (
51b0: 28 28 28 63 68 61 72 2a 29 28 58 29 20 2d 20 28 (((char*)(X) - (
51c0: 63 68 61 72 2a 29 30 29 26 37 29 3d 3d 30 29 0a char*)0)&7)==0).
51d0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 44 69 #endif../*.** Di
51e0: 73 61 62 6c 65 20 4d 4d 41 50 20 6f 6e 20 70 6c sable MMAP on pl
51f0: 61 74 66 6f 72 6d 73 20 77 68 65 72 65 20 69 74 atforms where it
5200: 20 69 73 20 6b 6e 6f 77 6e 20 74 6f 20 6e 6f 74 is known to not
5210: 20 77 6f 72 6b 0a 2a 2f 0a 23 69 66 20 64 65 66 work.*/.#if def
5220: 69 6e 65 64 28 5f 5f 4f 70 65 6e 42 53 44 5f 5f ined(__OpenBSD__
5230: 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 5f 51 ) || defined(__Q
5240: 4e 58 4e 54 4f 5f 5f 29 0a 23 20 75 6e 64 65 66 NXNTO__).# undef
5250: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
5260: 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e 65 20 53 _SIZE.# define S
5270: 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 QLITE_MAX_MMAP_S
5280: 49 5a 45 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a IZE 0.#endif../*
5290: 0a 2a 2a 20 44 65 66 61 75 6c 74 20 6d 61 78 69 .** Default maxi
52a0: 6d 75 6d 20 73 69 7a 65 20 6f 66 20 6d 65 6d 6f mum size of memo
52b0: 72 79 20 75 73 65 64 20 62 79 20 6d 65 6d 6f 72 ry used by memor
52c0: 79 2d 6d 61 70 70 65 64 20 49 2f 4f 20 69 6e 20 y-mapped I/O in
52d0: 74 68 65 20 56 46 53 0a 2a 2f 0a 23 69 66 64 65 the VFS.*/.#ifde
52e0: 66 20 5f 5f 41 50 50 4c 45 5f 5f 0a 23 20 69 6e f __APPLE__.# in
52f0: 63 6c 75 64 65 20 3c 54 61 72 67 65 74 43 6f 6e clude <TargetCon
5300: 64 69 74 69 6f 6e 61 6c 73 2e 68 3e 0a 23 20 69 ditionals.h>.# i
5310: 66 20 54 41 52 47 45 54 5f 4f 53 5f 49 50 48 4f f TARGET_OS_IPHO
5320: 4e 45 0a 23 20 20 20 75 6e 64 65 66 20 53 51 4c NE.# undef SQL
5330: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5340: 45 0a 23 20 20 20 64 65 66 69 6e 65 20 53 51 4c E.# define SQL
5350: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5360: 45 20 30 0a 23 20 65 6e 64 69 66 0a 23 65 6e 64 E 0.# endif.#end
5370: 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
5380: 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 0a E_MAX_MMAP_SIZE.
5390: 23 20 69 66 20 64 65 66 69 6e 65 64 28 5f 5f 6c # if defined(__l
53a0: 69 6e 75 78 5f 5f 29 20 5c 0a 20 20 7c 7c 20 64 inux__) \. || d
53b0: 65 66 69 6e 65 64 28 5f 57 49 4e 33 32 29 20 5c efined(_WIN32) \
53c0: 0a 20 20 7c 7c 20 28 64 65 66 69 6e 65 64 28 5f . || (defined(_
53d0: 5f 41 50 50 4c 45 5f 5f 29 20 26 26 20 64 65 66 _APPLE__) && def
53e0: 69 6e 65 64 28 5f 5f 4d 41 43 48 5f 5f 29 29 20 ined(__MACH__))
53f0: 5c 0a 20 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f \. || defined(_
5400: 5f 73 75 6e 29 0a 23 20 20 20 64 65 66 69 6e 65 _sun).# define
5410: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 SQLITE_MAX_MMAP
5420: 5f 53 49 5a 45 20 30 78 37 66 66 66 30 30 30 30 _SIZE 0x7fff0000
5430: 20 20 2f 2a 20 32 31 34 37 34 31 38 31 31 32 20 /* 2147418112
5440: 2a 2f 0a 23 20 65 6c 73 65 0a 23 20 20 20 64 65 */.# else.# de
5450: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f fine SQLITE_MAX_
5460: 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 65 6e MMAP_SIZE 0.# en
5470: 64 69 66 0a 23 20 64 65 66 69 6e 65 20 53 51 4c dif.# define SQL
5480: 49 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a ITE_MAX_MMAP_SIZ
5490: 45 5f 78 63 20 31 20 2f 2a 20 65 78 63 6c 75 64 E_xc 1 /* exclud
54a0: 65 20 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a e from ctime.c *
54b0: 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 /.#endif../*.**
54c0: 54 68 65 20 64 65 66 61 75 6c 74 20 4d 4d 41 50 The default MMAP
54d0: 5f 53 49 5a 45 20 69 73 20 7a 65 72 6f 20 6f 6e _SIZE is zero on
54e0: 20 61 6c 6c 20 70 6c 61 74 66 6f 72 6d 73 2e 20 all platforms.
54f0: 20 4f 72 2c 20 65 76 65 6e 20 69 66 20 61 20 6c Or, even if a l
5500: 61 72 67 65 72 0a 2a 2a 20 64 65 66 61 75 6c 74 arger.** default
5510: 20 4d 4d 41 50 5f 53 49 5a 45 20 69 73 20 73 70 MMAP_SIZE is sp
5520: 65 63 69 66 69 65 64 20 61 74 20 63 6f 6d 70 69 ecified at compi
5530: 6c 65 2d 74 69 6d 65 2c 20 6d 61 6b 65 20 73 75 le-time, make su
5540: 72 65 20 74 68 61 74 20 69 74 20 64 6f 65 73 0a re that it does.
5550: 2a 2a 20 6e 6f 74 20 65 78 63 65 65 64 20 74 68 ** not exceed th
5560: 65 20 6d 61 78 69 6d 75 6d 20 6d 6d 61 70 20 73 e maximum mmap s
5570: 69 7a 65 2e 0a 2a 2f 0a 23 69 66 6e 64 65 66 20 ize..*/.#ifndef
5580: 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f 4d SQLITE_DEFAULT_M
5590: 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 6e MAP_SIZE.# defin
55a0: 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 e SQLITE_DEFAULT
55b0: 5f 4d 4d 41 50 5f 53 49 5a 45 20 30 0a 23 20 64 _MMAP_SIZE 0.# d
55c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 efine SQLITE_DEF
55d0: 41 55 4c 54 5f 4d 4d 41 50 5f 53 49 5a 45 5f 78 AULT_MMAP_SIZE_x
55e0: 63 20 31 20 20 2f 2a 20 45 78 63 6c 75 64 65 20 c 1 /* Exclude
55f0: 66 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a from ctime.c */.
5600: 23 65 6e 64 69 66 0a 23 69 66 20 53 51 4c 49 54 #endif.#if SQLIT
5610: 45 5f 44 45 46 41 55 4c 54 5f 4d 4d 41 50 5f 53 E_DEFAULT_MMAP_S
5620: 49 5a 45 3e 53 51 4c 49 54 45 5f 4d 41 58 5f 4d IZE>SQLITE_MAX_M
5630: 4d 41 50 5f 53 49 5a 45 0a 23 20 75 6e 64 65 66 MAP_SIZE.# undef
5640: 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c 54 5f SQLITE_DEFAULT_
5650: 4d 4d 41 50 5f 53 49 5a 45 0a 23 20 64 65 66 69 MMAP_SIZE.# defi
5660: 6e 65 20 53 51 4c 49 54 45 5f 44 45 46 41 55 4c ne SQLITE_DEFAUL
5670: 54 5f 4d 4d 41 50 5f 53 49 5a 45 20 53 51 4c 49 T_MMAP_SIZE SQLI
5680: 54 45 5f 4d 41 58 5f 4d 4d 41 50 5f 53 49 5a 45 TE_MAX_MMAP_SIZE
5690: 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 4f .#endif../*.** O
56a0: 6e 6c 79 20 6f 6e 65 20 6f 66 20 53 51 4c 49 54 nly one of SQLIT
56b0: 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 20 6f E_ENABLE_STAT3 o
56c0: 72 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f r SQLITE_ENABLE_
56d0: 53 54 41 54 34 20 63 61 6e 20 62 65 20 64 65 66 STAT4 can be def
56e0: 69 6e 65 64 2e 0a 2a 2a 20 50 72 69 6f 72 69 74 ined..** Priorit
56f0: 79 20 69 73 20 67 69 76 65 6e 20 74 6f 20 53 51 y is given to SQ
5700: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
5710: 34 2e 20 20 49 66 20 65 69 74 68 65 72 20 61 72 4. If either ar
5720: 65 20 64 65 66 69 6e 65 64 2c 20 61 6c 73 6f 0a e defined, also.
5730: 2a 2a 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 ** define SQLITE
5740: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
5750: 5f 53 54 41 54 34 0a 2a 2f 0a 23 69 66 64 65 66 _STAT4.*/.#ifdef
5760: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
5770: 54 41 54 34 0a 23 20 75 6e 64 65 66 20 53 51 4c TAT4.# undef SQL
5780: 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 ITE_ENABLE_STAT3
5790: 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 54 45 .# define SQLITE
57a0: 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 _ENABLE_STAT3_OR
57b0: 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 20 53 _STAT4 1.#elif S
57c0: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 QLITE_ENABLE_STA
57d0: 54 33 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 T3.# define SQLI
57e0: 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 33 5f TE_ENABLE_STAT3_
57f0: 4f 52 5f 53 54 41 54 34 20 31 0a 23 65 6c 69 66 OR_STAT4 1.#elif
5800: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 SQLITE_ENABLE_S
5810: 54 41 54 33 5f 4f 52 5f 53 54 41 54 34 0a 23 20 TAT3_OR_STAT4.#
5820: 75 6e 64 65 66 20 53 51 4c 49 54 45 5f 45 4e 41 undef SQLITE_ENA
5830: 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 54 41 BLE_STAT3_OR_STA
5840: 54 34 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a T4.#endif../*.**
5850: 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 An instance of
5860: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
5870: 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 20 ructure is used
5880: 74 6f 20 73 74 6f 72 65 20 74 68 65 20 62 75 73 to store the bus
5890: 79 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c y-handler.** cal
58a0: 6c 62 61 63 6b 20 66 6f 72 20 61 20 67 69 76 65 lback for a give
58b0: 6e 20 73 71 6c 69 74 65 20 68 61 6e 64 6c 65 2e n sqlite handle.
58c0: 20 0a 2a 2a 0a 2a 2a 20 54 68 65 20 73 71 6c 69 .**.** The sqli
58d0: 74 65 2e 62 75 73 79 48 61 6e 64 6c 65 72 20 6d te.busyHandler m
58e0: 65 6d 62 65 72 20 6f 66 20 74 68 65 20 73 71 6c ember of the sql
58f0: 69 74 65 20 73 74 72 75 63 74 20 63 6f 6e 74 61 ite struct conta
5900: 69 6e 73 20 74 68 65 20 62 75 73 79 0a 2a 2a 20 ins the busy.**
5910: 63 61 6c 6c 62 61 63 6b 20 66 6f 72 20 74 68 65 callback for the
5920: 20 64 61 74 61 62 61 73 65 20 68 61 6e 64 6c 65 database handle
5930: 2e 20 45 61 63 68 20 70 61 67 65 72 20 6f 70 65 . Each pager ope
5940: 6e 65 64 20 76 69 61 20 74 68 65 20 73 71 6c 69 ned via the sqli
5950: 74 65 0a 2a 2a 20 68 61 6e 64 6c 65 20 69 73 20 te.** handle is
5960: 70 61 73 73 65 64 20 61 20 70 6f 69 6e 74 65 72 passed a pointer
5970: 20 74 6f 20 73 71 6c 69 74 65 2e 62 75 73 79 48 to sqlite.busyH
5980: 61 6e 64 6c 65 72 2e 20 54 68 65 20 62 75 73 79 andler. The busy
5990: 2d 68 61 6e 64 6c 65 72 0a 2a 2a 20 63 61 6c 6c -handler.** call
59a0: 62 61 63 6b 20 69 73 20 63 75 72 72 65 6e 74 6c back is currentl
59b0: 79 20 69 6e 76 6f 6b 65 64 20 6f 6e 6c 79 20 66 y invoked only f
59c0: 72 6f 6d 20 77 69 74 68 69 6e 20 70 61 67 65 72 rom within pager
59d0: 2e 63 2e 0a 2a 2f 0a 74 79 70 65 64 65 66 20 73 .c..*/.typedef s
59e0: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
59f0: 72 20 42 75 73 79 48 61 6e 64 6c 65 72 3b 0a 73 r BusyHandler;.s
5a00: 74 72 75 63 74 20 42 75 73 79 48 61 6e 64 6c 65 truct BusyHandle
5a10: 72 20 7b 0a 20 20 69 6e 74 20 28 2a 78 46 75 6e r {. int (*xFun
5a20: 63 29 28 76 6f 69 64 20 2a 2c 69 6e 74 29 3b 20 c)(void *,int);
5a30: 20 2f 2a 20 54 68 65 20 62 75 73 79 20 63 61 6c /* The busy cal
5a40: 6c 62 61 63 6b 20 2a 2f 0a 20 20 76 6f 69 64 20 lback */. void
5a50: 2a 70 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 *pArg;
5a60: 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 20 61 /* First a
5a70: 72 67 20 74 6f 20 62 75 73 79 20 63 61 6c 6c 62 rg to busy callb
5a80: 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 6e 42 75 ack */. int nBu
5a90: 73 79 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 sy;
5aa0: 20 20 20 20 2f 2a 20 49 6e 63 72 65 6d 65 6e 74 /* Increment
5ab0: 65 64 20 77 69 74 68 20 65 61 63 68 20 62 75 73 ed with each bus
5ac0: 79 20 63 61 6c 6c 20 2a 2f 0a 7d 3b 0a 0a 2f 2a y call */.};../*
5ad0: 0a 2a 2a 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 .** Name of the
5ae0: 6d 61 73 74 65 72 20 64 61 74 61 62 61 73 65 20 master database
5af0: 74 61 62 6c 65 2e 20 20 54 68 65 20 6d 61 73 74 table. The mast
5b00: 65 72 20 64 61 74 61 62 61 73 65 20 74 61 62 6c er database tabl
5b10: 65 0a 2a 2a 20 69 73 20 61 20 73 70 65 63 69 61 e.** is a specia
5b20: 6c 20 74 61 62 6c 65 20 74 68 61 74 20 68 6f 6c l table that hol
5b30: 64 73 20 74 68 65 20 6e 61 6d 65 73 20 61 6e 64 ds the names and
5b40: 20 61 74 74 72 69 62 75 74 65 73 20 6f 66 20 61 attributes of a
5b50: 6c 6c 0a 2a 2a 20 75 73 65 72 20 74 61 62 6c 65 ll.** user table
5b60: 73 20 61 6e 64 20 69 6e 64 69 63 65 73 2e 0a 2a s and indices..*
5b70: 2f 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 /.#define MASTER
5b80: 5f 4e 41 4d 45 20 20 20 20 20 20 20 22 73 71 6c _NAME "sql
5b90: 69 74 65 5f 6d 61 73 74 65 72 22 0a 23 64 65 66 ite_master".#def
5ba0: 69 6e 65 20 54 45 4d 50 5f 4d 41 53 54 45 52 5f ine TEMP_MASTER_
5bb0: 4e 41 4d 45 20 20 22 73 71 6c 69 74 65 5f 74 65 NAME "sqlite_te
5bc0: 6d 70 5f 6d 61 73 74 65 72 22 0a 0a 2f 2a 0a 2a mp_master"../*.*
5bd0: 2a 20 54 68 65 20 72 6f 6f 74 2d 70 61 67 65 20 * The root-page
5be0: 6f 66 20 74 68 65 20 6d 61 73 74 65 72 20 64 61 of the master da
5bf0: 74 61 62 61 73 65 20 74 61 62 6c 65 2e 0a 2a 2f tabase table..*/
5c00: 0a 23 64 65 66 69 6e 65 20 4d 41 53 54 45 52 5f .#define MASTER_
5c10: 52 4f 4f 54 20 20 20 20 20 20 20 31 0a 0a 2f 2a ROOT 1../*
5c20: 0a 2a 2a 20 54 68 65 20 6e 61 6d 65 20 6f 66 20 .** The name of
5c30: 74 68 65 20 73 63 68 65 6d 61 20 74 61 62 6c 65 the schema table
5c40: 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 43 48 ..*/.#define SCH
5c50: 45 4d 41 5f 54 41 42 4c 45 28 78 29 20 20 28 28 EMA_TABLE(x) ((
5c60: 21 4f 4d 49 54 5f 54 45 4d 50 44 42 29 26 26 28 !OMIT_TEMPDB)&&(
5c70: 78 3d 3d 31 29 3f 54 45 4d 50 5f 4d 41 53 54 45 x==1)?TEMP_MASTE
5c80: 52 5f 4e 41 4d 45 3a 4d 41 53 54 45 52 5f 4e 41 R_NAME:MASTER_NA
5c90: 4d 45 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 63 6f 6e ME)../*.** A con
5ca0: 76 65 6e 69 65 6e 63 65 20 6d 61 63 72 6f 20 74 venience macro t
5cb0: 68 61 74 20 72 65 74 75 72 6e 73 20 74 68 65 20 hat returns the
5cc0: 6e 75 6d 62 65 72 20 6f 66 20 65 6c 65 6d 65 6e number of elemen
5cd0: 74 73 20 69 6e 0a 2a 2a 20 61 6e 20 61 72 72 61 ts in.** an arra
5ce0: 79 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 41 72 y..*/.#define Ar
5cf0: 72 61 79 53 69 7a 65 28 58 29 20 20 20 20 28 28 raySize(X) ((
5d00: 69 6e 74 29 28 73 69 7a 65 6f 66 28 58 29 2f 73 int)(sizeof(X)/s
5d10: 69 7a 65 6f 66 28 58 5b 30 5d 29 29 29 0a 0a 2f izeof(X[0])))../
5d20: 2a 0a 2a 2a 20 44 65 74 65 72 6d 69 6e 65 20 69 *.** Determine i
5d30: 66 20 74 68 65 20 61 72 67 75 6d 65 6e 74 20 69 f the argument i
5d40: 73 20 61 20 70 6f 77 65 72 20 6f 66 20 74 77 6f s a power of two
5d50: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 6f .*/.#define IsPo
5d60: 77 65 72 4f 66 54 77 6f 28 58 29 20 28 28 28 58 werOfTwo(X) (((X
5d70: 29 26 28 28 58 29 2d 31 29 29 3d 3d 30 29 0a 0a )&((X)-1))==0)..
5d80: 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 /*.** The follow
5d90: 69 6e 67 20 76 61 6c 75 65 20 61 73 20 61 20 64 ing value as a d
5da0: 65 73 74 72 75 63 74 6f 72 20 6d 65 61 6e 73 20 estructor means
5db0: 74 6f 20 75 73 65 20 73 71 6c 69 74 65 33 44 62 to use sqlite3Db
5dc0: 46 72 65 65 28 29 2e 0a 2a 2a 20 54 68 65 20 73 Free()..** The s
5dd0: 71 6c 69 74 65 33 44 62 46 72 65 65 28 29 20 72 qlite3DbFree() r
5de0: 6f 75 74 69 6e 65 20 72 65 71 75 69 72 65 73 20 outine requires
5df0: 74 77 6f 20 70 61 72 61 6d 65 74 65 72 73 20 69 two parameters i
5e00: 6e 73 74 65 61 64 20 6f 66 20 74 68 65 20 0a 2a nstead of the .*
5e10: 2a 20 6f 6e 65 20 70 61 72 61 6d 65 74 65 72 20 * one parameter
5e20: 74 68 61 74 20 64 65 73 74 72 75 63 74 6f 72 73 that destructors
5e30: 20 6e 6f 72 6d 61 6c 6c 79 20 77 61 6e 74 2e 20 normally want.
5e40: 20 53 6f 20 77 65 20 68 61 76 65 20 74 6f 20 69 So we have to i
5e50: 6e 74 72 6f 64 75 63 65 20 0a 2a 2a 20 74 68 69 ntroduce .** thi
5e60: 73 20 6d 61 67 69 63 20 76 61 6c 75 65 20 74 68 s magic value th
5e70: 61 74 20 74 68 65 20 63 6f 64 65 20 6b 6e 6f 77 at the code know
5e80: 73 20 74 6f 20 68 61 6e 64 6c 65 20 64 69 66 66 s to handle diff
5e90: 65 72 65 6e 74 6c 79 2e 20 20 41 6e 79 20 0a 2a erently. Any .*
5ea0: 2a 20 70 6f 69 6e 74 65 72 20 77 69 6c 6c 20 77 * pointer will w
5eb0: 6f 72 6b 20 68 65 72 65 20 61 73 20 6c 6f 6e 67 ork here as long
5ec0: 20 61 73 20 69 74 20 69 73 20 64 69 73 74 69 6e as it is distin
5ed0: 63 74 20 66 72 6f 6d 20 53 51 4c 49 54 45 5f 53 ct from SQLITE_S
5ee0: 54 41 54 49 43 0a 2a 2a 20 61 6e 64 20 53 51 4c TATIC.** and SQL
5ef0: 49 54 45 5f 54 52 41 4e 53 49 45 4e 54 2e 0a 2a ITE_TRANSIENT..*
5f00: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
5f10: 5f 44 59 4e 41 4d 49 43 20 20 20 28 28 73 71 6c _DYNAMIC ((sql
5f20: 69 74 65 33 5f 64 65 73 74 72 75 63 74 6f 72 5f ite3_destructor_
5f30: 74 79 70 65 29 73 71 6c 69 74 65 33 4d 61 6c 6c type)sqlite3Mall
5f40: 6f 63 53 69 7a 65 29 0a 0a 2f 2a 0a 2a 2a 20 57 ocSize)../*.** W
5f50: 68 65 6e 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f hen SQLITE_OMIT_
5f60: 57 53 44 20 69 73 20 64 65 66 69 6e 65 64 2c 20 WSD is defined,
5f70: 69 74 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 it means that th
5f80: 65 20 74 61 72 67 65 74 20 70 6c 61 74 66 6f 72 e target platfor
5f90: 6d 20 64 6f 65 73 0a 2a 2a 20 6e 6f 74 20 73 75 m does.** not su
5fa0: 70 70 6f 72 74 20 57 72 69 74 61 62 6c 65 20 53 pport Writable S
5fb0: 74 61 74 69 63 20 44 61 74 61 20 28 57 53 44 29 tatic Data (WSD)
5fc0: 20 73 75 63 68 20 61 73 20 67 6c 6f 62 61 6c 20 such as global
5fd0: 61 6e 64 20 73 74 61 74 69 63 20 76 61 72 69 61 and static varia
5fe0: 62 6c 65 73 2e 0a 2a 2a 20 41 6c 6c 20 76 61 72 bles..** All var
5ff0: 69 61 62 6c 65 73 20 6d 75 73 74 20 65 69 74 68 iables must eith
6000: 65 72 20 62 65 20 6f 6e 20 74 68 65 20 73 74 61 er be on the sta
6010: 63 6b 20 6f 72 20 64 79 6e 61 6d 69 63 61 6c 6c ck or dynamicall
6020: 79 20 61 6c 6c 6f 63 61 74 65 64 20 66 72 6f 6d y allocated from
6030: 0a 2a 2a 20 74 68 65 20 68 65 61 70 2e 20 20 57 .** the heap. W
6040: 68 65 6e 20 57 53 44 20 69 73 20 75 6e 73 75 70 hen WSD is unsup
6050: 70 6f 72 74 65 64 2c 20 74 68 65 20 76 61 72 69 ported, the vari
6060: 61 62 6c 65 20 64 65 63 6c 61 72 61 74 69 6f 6e able declaration
6070: 73 20 73 63 61 74 74 65 72 65 64 0a 2a 2a 20 74 s scattered.** t
6080: 68 72 6f 75 67 68 6f 75 74 20 74 68 65 20 53 51 hroughout the SQ
6090: 4c 69 74 65 20 63 6f 64 65 20 6d 75 73 74 20 62 Lite code must b
60a0: 65 63 6f 6d 65 20 63 6f 6e 73 74 61 6e 74 73 20 ecome constants
60b0: 69 6e 73 74 65 61 64 2e 20 20 54 68 65 20 53 51 instead. The SQ
60c0: 4c 49 54 45 5f 57 53 44 0a 2a 2a 20 6d 61 63 72 LITE_WSD.** macr
60d0: 6f 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 68 o is used for th
60e0: 69 73 20 70 75 72 70 6f 73 65 2e 20 20 41 6e 64 is purpose. And
60f0: 20 69 6e 73 74 65 61 64 20 6f 66 20 72 65 66 65 instead of refe
6100: 72 65 6e 63 69 6e 67 20 74 68 65 20 76 61 72 69 rencing the vari
6110: 61 62 6c 65 0a 2a 2a 20 64 69 72 65 63 74 6c 79 able.** directly
6120: 2c 20 77 65 20 75 73 65 20 69 74 73 20 63 6f 6e , we use its con
6130: 73 74 61 6e 74 20 61 73 20 61 20 6b 65 79 20 74 stant as a key t
6140: 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 72 75 6e o lookup the run
6150: 2d 74 69 6d 65 20 61 6c 6c 6f 63 61 74 65 64 0a -time allocated.
6160: 2a 2a 20 62 75 66 66 65 72 20 74 68 61 74 20 68 ** buffer that h
6170: 6f 6c 64 73 20 72 65 61 6c 20 76 61 72 69 61 62 olds real variab
6180: 6c 65 2e 20 20 54 68 65 20 63 6f 6e 73 74 61 6e le. The constan
6190: 74 20 69 73 20 61 6c 73 6f 20 74 68 65 20 69 6e t is also the in
61a0: 69 74 69 61 6c 69 7a 65 72 0a 2a 2a 20 66 6f 72 itializer.** for
61b0: 20 74 68 65 20 72 75 6e 2d 74 69 6d 65 20 61 6c the run-time al
61c0: 6c 6f 63 61 74 65 64 20 62 75 66 66 65 72 2e 0a located buffer..
61d0: 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 20 75 73 75 **.** In the usu
61e0: 61 6c 20 63 61 73 65 20 77 68 65 72 65 20 57 53 al case where WS
61f0: 44 20 69 73 20 73 75 70 70 6f 72 74 65 64 2c 20 D is supported,
6200: 74 68 65 20 53 51 4c 49 54 45 5f 57 53 44 20 61 the SQLITE_WSD a
6210: 6e 64 20 47 4c 4f 42 41 4c 0a 2a 2a 20 6d 61 63 nd GLOBAL.** mac
6220: 72 6f 73 20 62 65 63 6f 6d 65 20 6e 6f 2d 6f 70 ros become no-op
6230: 73 20 61 6e 64 20 68 61 76 65 20 7a 65 72 6f 20 s and have zero
6240: 70 65 72 66 6f 72 6d 61 6e 63 65 20 69 6d 70 61 performance impa
6250: 63 74 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 ct..*/.#ifdef SQ
6260: 4c 49 54 45 5f 4f 4d 49 54 5f 57 53 44 0a 20 20 LITE_OMIT_WSD.
6270: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 57 #define SQLITE_W
6280: 53 44 20 63 6f 6e 73 74 0a 20 20 23 64 65 66 69 SD const. #defi
6290: 6e 65 20 47 4c 4f 42 41 4c 28 74 2c 76 29 20 28 ne GLOBAL(t,v) (
62a0: 2a 28 74 2a 29 73 71 6c 69 74 65 33 5f 77 73 64 *(t*)sqlite3_wsd
62b0: 5f 66 69 6e 64 28 28 76 6f 69 64 2a 29 26 28 76 _find((void*)&(v
62c0: 29 2c 20 73 69 7a 65 6f 66 28 76 29 29 29 0a 20 ), sizeof(v))).
62d0: 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
62e0: 47 6c 6f 62 61 6c 43 6f 6e 66 69 67 20 47 4c 4f GlobalConfig GLO
62f0: 42 41 4c 28 73 74 72 75 63 74 20 53 71 6c 69 74 BAL(struct Sqlit
6300: 65 33 43 6f 6e 66 69 67 2c 20 73 71 6c 69 74 65 e3Config, sqlite
6310: 33 43 6f 6e 66 69 67 29 0a 20 20 69 6e 74 20 73 3Config). int s
6320: 71 6c 69 74 65 33 5f 77 73 64 5f 69 6e 69 74 28 qlite3_wsd_init(
6330: 69 6e 74 20 4e 2c 20 69 6e 74 20 4a 29 3b 0a 20 int N, int J);.
6340: 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 5f 77 void *sqlite3_w
6350: 73 64 5f 66 69 6e 64 28 76 6f 69 64 20 2a 4b 2c sd_find(void *K,
6360: 20 69 6e 74 20 4c 29 3b 0a 23 65 6c 73 65 0a 20 int L);.#else.
6370: 20 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f #define SQLITE_
6380: 57 53 44 20 0a 20 20 23 64 65 66 69 6e 65 20 47 WSD . #define G
6390: 4c 4f 42 41 4c 28 74 2c 76 29 20 76 0a 20 20 23 LOBAL(t,v) v. #
63a0: 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 47 6c define sqlite3Gl
63b0: 6f 62 61 6c 43 6f 6e 66 69 67 20 73 71 6c 69 74 obalConfig sqlit
63c0: 65 33 43 6f 6e 66 69 67 0a 23 65 6e 64 69 66 0a e3Config.#endif.
63d0: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
63e0: 77 69 6e 67 20 6d 61 63 72 6f 73 20 61 72 65 20 wing macros are
63f0: 75 73 65 64 20 74 6f 20 73 75 70 70 72 65 73 73 used to suppress
6400: 20 63 6f 6d 70 69 6c 65 72 20 77 61 72 6e 69 6e compiler warnin
6410: 67 73 20 61 6e 64 20 74 6f 0a 2a 2a 20 6d 61 6b gs and to.** mak
6420: 65 20 69 74 20 63 6c 65 61 72 20 74 6f 20 68 75 e it clear to hu
6430: 6d 61 6e 20 72 65 61 64 65 72 73 20 77 68 65 6e man readers when
6440: 20 61 20 66 75 6e 63 74 69 6f 6e 20 70 61 72 61 a function para
6450: 6d 65 74 65 72 20 69 73 20 64 65 6c 69 62 65 72 meter is deliber
6460: 61 74 65 6c 79 20 0a 2a 2a 20 6c 65 66 74 20 75 ately .** left u
6470: 6e 75 73 65 64 20 77 69 74 68 69 6e 20 74 68 65 nused within the
6480: 20 62 6f 64 79 20 6f 66 20 61 20 66 75 6e 63 74 body of a funct
6490: 69 6f 6e 2e 20 54 68 69 73 20 75 73 75 61 6c 6c ion. This usuall
64a0: 79 20 68 61 70 70 65 6e 73 20 77 68 65 6e 0a 2a y happens when.*
64b0: 2a 20 61 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 * a function is
64c0: 63 61 6c 6c 65 64 20 76 69 61 20 61 20 66 75 6e called via a fun
64d0: 63 74 69 6f 6e 20 70 6f 69 6e 74 65 72 2e 20 46 ction pointer. F
64e0: 6f 72 20 65 78 61 6d 70 6c 65 20 74 68 65 20 0a or example the .
64f0: 2a 2a 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f ** implementatio
6500: 6e 20 6f 66 20 61 6e 20 53 51 4c 20 61 67 67 72 n of an SQL aggr
6510: 65 67 61 74 65 20 73 74 65 70 20 63 61 6c 6c 62 egate step callb
6520: 61 63 6b 20 6d 61 79 20 6e 6f 74 20 75 73 65 20 ack may not use
6530: 74 68 65 0a 2a 2a 20 70 61 72 61 6d 65 74 65 72 the.** parameter
6540: 20 69 6e 64 69 63 61 74 69 6e 67 20 74 68 65 20 indicating the
6550: 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d 65 number of argume
6560: 6e 74 73 20 70 61 73 73 65 64 20 74 6f 20 74 68 nts passed to th
6570: 65 20 61 67 67 72 65 67 61 74 65 2c 0a 2a 2a 20 e aggregate,.**
6580: 69 66 20 69 74 20 6b 6e 6f 77 73 20 74 68 61 74 if it knows that
6590: 20 74 68 69 73 20 69 73 20 65 6e 66 6f 72 63 65 this is enforce
65a0: 64 20 65 6c 73 65 77 68 65 72 65 2e 0a 2a 2a 0a d elsewhere..**.
65b0: 2a 2a 20 57 68 65 6e 20 61 20 66 75 6e 63 74 69 ** When a functi
65c0: 6f 6e 20 70 61 72 61 6d 65 74 65 72 20 69 73 20 on parameter is
65d0: 6e 6f 74 20 75 73 65 64 20 61 74 20 61 6c 6c 20 not used at all
65e0: 77 69 74 68 69 6e 20 74 68 65 20 62 6f 64 79 20 within the body
65f0: 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 2c 0a 2a of a function,.*
6600: 2a 20 69 74 20 69 73 20 67 65 6e 65 72 61 6c 6c * it is generall
6610: 79 20 6e 61 6d 65 64 20 22 4e 6f 74 55 73 65 64 y named "NotUsed
6620: 22 20 6f 72 20 22 4e 6f 74 55 73 65 64 32 22 20 " or "NotUsed2"
6630: 74 6f 20 6d 61 6b 65 20 74 68 69 6e 67 73 20 65 to make things e
6640: 76 65 6e 20 63 6c 65 61 72 65 72 2e 0a 2a 2a 20 ven clearer..**
6650: 48 6f 77 65 76 65 72 2c 20 74 68 65 73 65 20 6d However, these m
6660: 61 63 72 6f 73 20 6d 61 79 20 61 6c 73 6f 20 62 acros may also b
6670: 65 20 75 73 65 64 20 74 6f 20 73 75 70 70 72 65 e used to suppre
6680: 73 73 20 77 61 72 6e 69 6e 67 73 20 72 65 6c 61 ss warnings rela
6690: 74 65 64 20 74 6f 0a 2a 2a 20 70 61 72 61 6d 65 ted to.** parame
66a0: 74 65 72 73 20 74 68 61 74 20 6d 61 79 20 6f 72 ters that may or
66b0: 20 6d 61 79 20 6e 6f 74 20 62 65 20 75 73 65 64 may not be used
66c0: 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 63 6f depending on co
66d0: 6d 70 69 6c 61 74 69 6f 6e 20 6f 70 74 69 6f 6e mpilation option
66e0: 73 2e 0a 2a 2a 20 46 6f 72 20 65 78 61 6d 70 6c s..** For exampl
66f0: 65 20 74 68 6f 73 65 20 70 61 72 61 6d 65 74 65 e those paramete
6700: 72 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 rs only used in
6710: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65 assert() stateme
6720: 6e 74 73 2e 20 49 6e 20 74 68 65 73 65 0a 2a 2a nts. In these.**
6730: 20 63 61 73 65 73 20 74 68 65 20 70 61 72 61 6d cases the param
6740: 65 74 65 72 73 20 61 72 65 20 6e 61 6d 65 64 20 eters are named
6750: 61 73 20 70 65 72 20 74 68 65 20 75 73 75 61 6c as per the usual
6760: 20 63 6f 6e 76 65 6e 74 69 6f 6e 73 2e 0a 2a 2f conventions..*/
6770: 0a 23 64 65 66 69 6e 65 20 55 4e 55 53 45 44 5f .#define UNUSED_
6780: 50 41 52 41 4d 45 54 45 52 28 78 29 20 28 76 6f PARAMETER(x) (vo
6790: 69 64 29 28 78 29 0a 23 64 65 66 69 6e 65 20 55 id)(x).#define U
67a0: 4e 55 53 45 44 5f 50 41 52 41 4d 45 54 45 52 32 NUSED_PARAMETER2
67b0: 28 78 2c 79 29 20 55 4e 55 53 45 44 5f 50 41 52 (x,y) UNUSED_PAR
67c0: 41 4d 45 54 45 52 28 78 29 2c 55 4e 55 53 45 44 AMETER(x),UNUSED
67d0: 5f 50 41 52 41 4d 45 54 45 52 28 79 29 0a 0a 2f _PARAMETER(y)../
67e0: 2a 0a 2a 2a 20 46 6f 72 77 61 72 64 20 72 65 66 *.** Forward ref
67f0: 65 72 65 6e 63 65 73 20 74 6f 20 73 74 72 75 63 erences to struc
6800: 74 75 72 65 73 0a 2a 2f 0a 74 79 70 65 64 65 66 tures.*/.typedef
6810: 20 73 74 72 75 63 74 20 41 67 67 49 6e 66 6f 20 struct AggInfo
6820: 41 67 67 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 AggInfo;.typedef
6830: 20 73 74 72 75 63 74 20 41 75 74 68 43 6f 6e 74 struct AuthCont
6840: 65 78 74 20 41 75 74 68 43 6f 6e 74 65 78 74 3b ext AuthContext;
6850: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6860: 41 75 74 6f 69 6e 63 49 6e 66 6f 20 41 75 74 6f AutoincInfo Auto
6870: 69 6e 63 49 6e 66 6f 3b 0a 74 79 70 65 64 65 66 incInfo;.typedef
6880: 20 73 74 72 75 63 74 20 42 69 74 76 65 63 20 42 struct Bitvec B
6890: 69 74 76 65 63 3b 0a 74 79 70 65 64 65 66 20 73 itvec;.typedef s
68a0: 74 72 75 63 74 20 43 6f 6c 6c 53 65 71 20 43 6f truct CollSeq Co
68b0: 6c 6c 53 65 71 3b 0a 74 79 70 65 64 65 66 20 73 llSeq;.typedef s
68c0: 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 43 6f 6c truct Column Col
68d0: 75 6d 6e 3b 0a 74 79 70 65 64 65 66 20 73 74 72 umn;.typedef str
68e0: 75 63 74 20 44 62 20 44 62 3b 0a 74 79 70 65 64 uct Db Db;.typed
68f0: 65 66 20 73 74 72 75 63 74 20 53 63 68 65 6d 61 ef struct Schema
6900: 20 53 63 68 65 6d 61 3b 0a 74 79 70 65 64 65 66 Schema;.typedef
6910: 20 73 74 72 75 63 74 20 45 78 70 72 20 45 78 70 struct Expr Exp
6920: 72 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 r;.typedef struc
6930: 74 20 45 78 70 72 4c 69 73 74 20 45 78 70 72 4c t ExprList ExprL
6940: 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ist;.typedef str
6950: 75 63 74 20 45 78 70 72 53 70 61 6e 20 45 78 70 uct ExprSpan Exp
6960: 72 53 70 61 6e 3b 0a 74 79 70 65 64 65 66 20 73 rSpan;.typedef s
6970: 74 72 75 63 74 20 46 4b 65 79 20 46 4b 65 79 3b truct FKey FKey;
6980: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6990: 46 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 46 FuncDestructor F
69a0: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 3b 0a 74 uncDestructor;.t
69b0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 ypedef struct Fu
69c0: 6e 63 44 65 66 20 46 75 6e 63 44 65 66 3b 0a 74 ncDef FuncDef;.t
69d0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 46 75 ypedef struct Fu
69e0: 6e 63 44 65 66 48 61 73 68 20 46 75 6e 63 44 65 ncDefHash FuncDe
69f0: 66 48 61 73 68 3b 0a 74 79 70 65 64 65 66 20 73 fHash;.typedef s
6a00: 74 72 75 63 74 20 49 64 4c 69 73 74 20 49 64 4c truct IdList IdL
6a10: 69 73 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ist;.typedef str
6a20: 75 63 74 20 49 6e 64 65 78 20 49 6e 64 65 78 3b uct Index Index;
6a30: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6a40: 49 6e 64 65 78 53 61 6d 70 6c 65 20 49 6e 64 65 IndexSample Inde
6a50: 78 53 61 6d 70 6c 65 3b 0a 74 79 70 65 64 65 66 xSample;.typedef
6a60: 20 73 74 72 75 63 74 20 4b 65 79 43 6c 61 73 73 struct KeyClass
6a70: 20 4b 65 79 43 6c 61 73 73 3b 0a 74 79 70 65 64 KeyClass;.typed
6a80: 65 66 20 73 74 72 75 63 74 20 4b 65 79 49 6e 66 ef struct KeyInf
6a90: 6f 20 4b 65 79 49 6e 66 6f 3b 0a 74 79 70 65 64 o KeyInfo;.typed
6aa0: 65 66 20 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 ef struct Lookas
6ab0: 69 64 65 20 4c 6f 6f 6b 61 73 69 64 65 3b 0a 74 ide Lookaside;.t
6ac0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4c 6f ypedef struct Lo
6ad0: 6f 6b 61 73 69 64 65 53 6c 6f 74 20 4c 6f 6f 6b okasideSlot Look
6ae0: 61 73 69 64 65 53 6c 6f 74 3b 0a 74 79 70 65 64 asideSlot;.typed
6af0: 65 66 20 73 74 72 75 63 74 20 4d 6f 64 75 6c 65 ef struct Module
6b00: 20 4d 6f 64 75 6c 65 3b 0a 74 79 70 65 64 65 66 Module;.typedef
6b10: 20 73 74 72 75 63 74 20 4e 61 6d 65 43 6f 6e 74 struct NameCont
6b20: 65 78 74 20 4e 61 6d 65 43 6f 6e 74 65 78 74 3b ext NameContext;
6b30: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6b40: 50 61 72 73 65 20 50 61 72 73 65 3b 0a 74 79 70 Parse Parse;.typ
6b50: 65 64 65 66 20 73 74 72 75 63 74 20 50 72 69 6e edef struct Prin
6b60: 74 66 41 72 67 75 6d 65 6e 74 73 20 50 72 69 6e tfArguments Prin
6b70: 74 66 41 72 67 75 6d 65 6e 74 73 3b 0a 74 79 70 tfArguments;.typ
6b80: 65 64 65 66 20 73 74 72 75 63 74 20 52 6f 77 53 edef struct RowS
6b90: 65 74 20 52 6f 77 53 65 74 3b 0a 74 79 70 65 64 et RowSet;.typed
6ba0: 65 66 20 73 74 72 75 63 74 20 53 61 76 65 70 6f ef struct Savepo
6bb0: 69 6e 74 20 53 61 76 65 70 6f 69 6e 74 3b 0a 74 int Savepoint;.t
6bc0: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 53 65 ypedef struct Se
6bd0: 6c 65 63 74 20 53 65 6c 65 63 74 3b 0a 74 79 70 lect Select;.typ
6be0: 65 64 65 66 20 73 74 72 75 63 74 20 53 65 6c 65 edef struct Sele
6bf0: 63 74 44 65 73 74 20 53 65 6c 65 63 74 44 65 73 ctDest SelectDes
6c00: 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 t;.typedef struc
6c10: 74 20 53 72 63 4c 69 73 74 20 53 72 63 4c 69 73 t SrcList SrcLis
6c20: 74 3b 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 t;.typedef struc
6c30: 74 20 53 74 72 41 63 63 75 6d 20 53 74 72 41 63 t StrAccum StrAc
6c40: 63 75 6d 3b 0a 74 79 70 65 64 65 66 20 73 74 72 cum;.typedef str
6c50: 75 63 74 20 54 61 62 6c 65 20 54 61 62 6c 65 3b uct Table Table;
6c60: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6c70: 54 61 62 6c 65 4c 6f 63 6b 20 54 61 62 6c 65 4c TableLock TableL
6c80: 6f 63 6b 3b 0a 74 79 70 65 64 65 66 20 73 74 72 ock;.typedef str
6c90: 75 63 74 20 54 6f 6b 65 6e 20 54 6f 6b 65 6e 3b uct Token Token;
6ca0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6cb0: 54 72 69 67 67 65 72 20 54 72 69 67 67 65 72 3b Trigger Trigger;
6cc0: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 .typedef struct
6cd0: 54 72 69 67 67 65 72 50 72 67 20 54 72 69 67 67 TriggerPrg Trigg
6ce0: 65 72 50 72 67 3b 0a 74 79 70 65 64 65 66 20 73 erPrg;.typedef s
6cf0: 74 72 75 63 74 20 54 72 69 67 67 65 72 53 74 65 truct TriggerSte
6d00: 70 20 54 72 69 67 67 65 72 53 74 65 70 3b 0a 74 p TriggerStep;.t
6d10: 79 70 65 64 65 66 20 73 74 72 75 63 74 20 55 6e ypedef struct Un
6d20: 70 61 63 6b 65 64 52 65 63 6f 72 64 20 55 6e 70 packedRecord Unp
6d30: 61 63 6b 65 64 52 65 63 6f 72 64 3b 0a 74 79 70 ackedRecord;.typ
6d40: 65 64 65 66 20 73 74 72 75 63 74 20 56 54 61 62 edef struct VTab
6d50: 6c 65 20 56 54 61 62 6c 65 3b 0a 74 79 70 65 64 le VTable;.typed
6d60: 65 66 20 73 74 72 75 63 74 20 56 74 61 62 43 74 ef struct VtabCt
6d70: 78 20 56 74 61 62 43 74 78 3b 0a 74 79 70 65 64 x VtabCtx;.typed
6d80: 65 66 20 73 74 72 75 63 74 20 57 61 6c 6b 65 72 ef struct Walker
6d90: 20 57 61 6c 6b 65 72 3b 0a 74 79 70 65 64 65 66 Walker;.typedef
6da0: 20 73 74 72 75 63 74 20 57 68 65 72 65 49 6e 66 struct WhereInf
6db0: 6f 20 57 68 65 72 65 49 6e 66 6f 3b 0a 74 79 70 o WhereInfo;.typ
6dc0: 65 64 65 66 20 73 74 72 75 63 74 20 57 69 74 68 edef struct With
6dd0: 20 57 69 74 68 3b 0a 0a 2f 2a 0a 2a 2a 20 44 65 With;../*.** De
6de0: 66 65 72 20 73 6f 75 72 63 69 6e 67 20 76 64 62 fer sourcing vdb
6df0: 65 2e 68 20 61 6e 64 20 62 74 72 65 65 2e 68 20 e.h and btree.h
6e00: 75 6e 74 69 6c 20 61 66 74 65 72 20 74 68 65 20 until after the
6e10: 22 75 38 22 20 61 6e 64 20 0a 2a 2a 20 22 42 75 "u8" and .** "Bu
6e20: 73 79 48 61 6e 64 6c 65 72 22 20 74 79 70 65 64 syHandler" typed
6e30: 65 66 73 2e 20 76 64 62 65 2e 68 20 61 6c 73 6f efs. vdbe.h also
6e40: 20 72 65 71 75 69 72 65 73 20 61 20 66 65 77 20 requires a few
6e50: 6f 66 20 74 68 65 20 6f 70 61 71 75 65 0a 2a 2a of the opaque.**
6e60: 20 70 6f 69 6e 74 65 72 20 74 79 70 65 73 20 28 pointer types (
6e70: 69 2e 65 2e 20 46 75 6e 63 44 65 66 29 20 64 65 i.e. FuncDef) de
6e80: 66 69 6e 65 64 20 61 62 6f 76 65 2e 0a 2a 2f 0a fined above..*/.
6e90: 23 69 6e 63 6c 75 64 65 20 22 62 74 72 65 65 2e #include "btree.
6ea0: 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 76 64 62 h".#include "vdb
6eb0: 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 e.h".#include "p
6ec0: 61 67 65 72 2e 68 22 0a 23 69 6e 63 6c 75 64 65 ager.h".#include
6ed0: 20 22 70 63 61 63 68 65 2e 68 22 0a 0a 23 69 6e "pcache.h"..#in
6ee0: 63 6c 75 64 65 20 22 6f 73 2e 68 22 0a 23 69 6e clude "os.h".#in
6ef0: 63 6c 75 64 65 20 22 6d 75 74 65 78 2e 68 22 0a clude "mutex.h".
6f00: 0a 2f 2a 20 57 68 65 6e 20 75 73 69 6e 67 20 61 ./* When using a
6f10: 20 64 65 66 61 75 6c 74 20 77 61 6c 20 73 61 66 default wal saf
6f20: 65 74 79 20 6c 65 76 65 6c 2c 20 74 68 65 20 73 ety level, the s
6f30: 61 66 65 74 79 20 6c 65 76 65 6c 20 73 68 6f 75 afety level shou
6f40: 6c 64 20 6f 6e 6c 79 20 0a 2a 2a 20 63 68 61 6e ld only .** chan
6f50: 67 65 20 77 69 74 68 20 74 68 65 20 6a 6f 75 72 ge with the jour
6f60: 6e 61 6c 20 6d 6f 64 65 20 69 66 20 74 68 65 20 nal mode if the
6f70: 75 73 65 72 20 68 61 73 6e 27 74 20 6d 61 6e 75 user hasn't manu
6f80: 61 6c 6c 79 20 73 70 65 63 69 66 69 65 64 20 0a ally specified .
6f90: 2a 2a 20 70 72 61 67 6d 61 20 73 79 6e 63 68 72 ** pragma synchr
6fa0: 6f 6e 6f 75 73 2c 20 69 66 20 74 68 65 79 20 68 onous, if they h
6fb0: 61 76 65 20 74 68 65 20 64 65 66 61 75 6c 74 73 ave the defaults
6fc0: 20 73 68 6f 75 6c 64 6e 27 74 20 62 65 20 61 70 shouldn't be ap
6fd0: 70 6c 69 65 64 2e 0a 2a 2a 20 54 68 65 20 53 51 plied..** The SQ
6fe0: 4c 49 54 45 5f 53 41 46 45 54 59 4c 45 56 45 4c LITE_SAFETYLEVEL
6ff0: 5f 46 49 58 45 44 20 76 61 6c 75 65 20 69 73 20 _FIXED value is
7000: 4f 52 65 64 20 69 6e 74 6f 20 74 68 65 20 44 62 ORed into the Db
7010: 2d 3e 73 61 66 65 74 79 5f 6c 65 76 65 6c 0a 2a ->safety_level.*
7020: 2a 20 66 69 65 6c 64 20 77 68 65 6e 20 74 68 65 * field when the
7030: 20 75 73 65 72 20 68 61 73 20 73 70 65 63 69 66 user has specif
7040: 69 65 64 20 61 20 73 79 6e 63 68 72 6f 6e 6f 75 ied a synchronou
7050: 73 20 73 65 74 74 69 6e 67 20 76 69 61 20 70 72 s setting via pr
7060: 61 67 6d 61 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 agma..*/.#define
7070: 20 53 51 4c 49 54 45 5f 53 41 46 45 54 59 4c 45 SQLITE_SAFETYLE
7080: 56 45 4c 5f 46 49 58 45 44 20 30 78 31 30 0a 23 VEL_FIXED 0x10.#
7090: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 41 define SQLITE_SA
70a0: 46 45 54 59 4c 45 56 45 4c 5f 56 41 4c 55 45 5f FETYLEVEL_VALUE_
70b0: 4d 41 53 4b 20 30 78 30 33 0a 23 64 65 66 69 6e MASK 0x03.#defin
70c0: 65 20 53 51 4c 49 54 45 5f 44 62 53 61 66 65 74 e SQLITE_DbSafet
70d0: 79 4c 65 76 65 6c 56 61 6c 75 65 28 6c 65 76 65 yLevelValue(leve
70e0: 6c 29 20 28 6c 65 76 65 6c 26 53 51 4c 49 54 45 l) (level&SQLITE
70f0: 5f 53 41 46 45 54 59 4c 45 56 45 4c 5f 56 41 4c _SAFETYLEVEL_VAL
7100: 55 45 5f 4d 41 53 4b 29 0a 23 64 65 66 69 6e 65 UE_MASK).#define
7110: 20 53 51 4c 49 54 45 5f 44 62 53 61 66 65 74 79 SQLITE_DbSafety
7120: 4c 65 76 65 6c 49 73 46 69 78 65 64 28 6c 65 76 LevelIsFixed(lev
7130: 65 6c 29 20 28 6c 65 76 65 6c 26 53 51 4c 49 54 el) (level&SQLIT
7140: 45 5f 53 41 46 45 54 59 4c 45 56 45 4c 5f 46 49 E_SAFETYLEVEL_FI
7150: 58 45 44 29 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 68 XED)../*.** Each
7160: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 20 74 database file t
7170: 6f 20 62 65 20 61 63 63 65 73 73 65 64 20 62 79 o be accessed by
7180: 20 74 68 65 20 73 79 73 74 65 6d 20 69 73 20 61 the system is a
7190: 6e 20 69 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 n instance.** of
71a0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
71b0: 74 72 75 63 74 75 72 65 2e 20 20 54 68 65 72 65 tructure. There
71c0: 20 61 72 65 20 6e 6f 72 6d 61 6c 6c 79 20 74 77 are normally tw
71d0: 6f 20 6f 66 20 74 68 65 73 65 20 73 74 72 75 63 o of these struc
71e0: 74 75 72 65 73 0a 2a 2a 20 69 6e 20 74 68 65 20 tures.** in the
71f0: 73 71 6c 69 74 65 2e 61 44 62 5b 5d 20 61 72 72 sqlite.aDb[] arr
7200: 61 79 2e 20 20 61 44 62 5b 30 5d 20 69 73 20 74 ay. aDb[0] is t
7210: 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 73 65 he main database
7220: 20 66 69 6c 65 20 61 6e 64 0a 2a 2a 20 61 44 62 file and.** aDb
7230: 5b 31 5d 20 69 73 20 74 68 65 20 64 61 74 61 62 [1] is the datab
7240: 61 73 65 20 66 69 6c 65 20 75 73 65 64 20 74 6f ase file used to
7250: 20 68 6f 6c 64 20 74 65 6d 70 6f 72 61 72 79 20 hold temporary
7260: 74 61 62 6c 65 73 2e 20 20 41 64 64 69 74 69 6f tables. Additio
7270: 6e 61 6c 0a 2a 2a 20 64 61 74 61 62 61 73 65 73 nal.** databases
7280: 20 6d 61 79 20 62 65 20 61 74 74 61 63 68 65 64 may be attached
7290: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 44 62 20 7b ..*/.struct Db {
72a0: 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
72b0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 /* Name
72c0: 6f 66 20 74 68 69 73 20 64 61 74 61 62 61 73 65 of this database
72d0: 20 2a 2f 0a 20 20 42 74 72 65 65 20 2a 70 42 74 */. Btree *pBt
72e0: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 ; /* Th
72f0: 65 20 42 2a 54 72 65 65 20 73 74 72 75 63 74 75 e B*Tree structu
7300: 72 65 20 66 6f 72 20 74 68 69 73 20 64 61 74 61 re for this data
7310: 62 61 73 65 20 66 69 6c 65 20 2a 2f 0a 20 20 75 base file */. u
7320: 38 20 73 61 66 65 74 79 5f 6c 65 76 65 6c 3b 20 8 safety_level;
7330: 20 20 20 20 2f 2a 20 48 6f 77 20 61 67 67 72 65 /* How aggre
7340: 73 73 69 76 65 20 61 74 20 73 79 6e 63 69 6e 67 ssive at syncing
7350: 20 64 61 74 61 20 74 6f 20 64 69 73 6b 20 2a 2f data to disk */
7360: 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 65 . Schema *pSche
7370: 6d 61 3b 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 ma; /* Point
7380: 65 72 20 74 6f 20 64 61 74 61 62 61 73 65 20 73 er to database s
7390: 63 68 65 6d 61 20 28 70 6f 73 73 69 62 6c 79 20 chema (possibly
73a0: 73 68 61 72 65 64 29 20 2a 2f 0a 7d 3b 0a 0a 2f shared) */.};../
73b0: 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
73c0: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
73d0: 67 20 73 74 72 75 63 74 75 72 65 20 73 74 6f 72 g structure stor
73e0: 65 73 20 61 20 64 61 74 61 62 61 73 65 20 73 63 es a database sc
73f0: 68 65 6d 61 2e 0a 2a 2a 0a 2a 2a 20 4d 6f 73 74 hema..**.** Most
7400: 20 53 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 20 Schema objects
7410: 61 72 65 20 61 73 73 6f 63 69 61 74 65 64 20 77 are associated w
7420: 69 74 68 20 61 20 42 74 72 65 65 2e 20 20 54 68 ith a Btree. Th
7430: 65 20 65 78 63 65 70 74 69 6f 6e 20 69 73 0a 2a e exception is.*
7440: 2a 20 74 68 65 20 53 63 68 65 6d 61 20 66 6f 72 * the Schema for
7450: 20 74 68 65 20 54 45 4d 50 20 64 61 74 61 62 61 the TEMP databa
7460: 65 73 20 28 73 71 6c 69 74 65 33 2e 61 44 62 5b es (sqlite3.aDb[
7470: 31 5d 29 20 77 68 69 63 68 20 69 73 20 66 72 65 1]) which is fre
7480: 65 2d 73 74 61 6e 64 69 6e 67 2e 0a 2a 2a 20 49 e-standing..** I
7490: 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 20 6d n shared cache m
74a0: 6f 64 65 2c 20 61 20 73 69 6e 67 6c 65 20 53 63 ode, a single Sc
74b0: 68 65 6d 61 20 6f 62 6a 65 63 74 20 63 61 6e 20 hema object can
74c0: 62 65 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c be shared by mul
74d0: 74 69 70 6c 65 0a 2a 2a 20 42 74 72 65 65 73 20 tiple.** Btrees
74e0: 74 68 61 74 20 72 65 66 65 72 20 74 6f 20 74 68 that refer to th
74f0: 65 20 73 61 6d 65 20 75 6e 64 65 72 6c 79 69 6e e same underlyin
7500: 67 20 42 74 53 68 61 72 65 64 20 6f 62 6a 65 63 g BtShared objec
7510: 74 2e 0a 2a 2a 20 0a 2a 2a 20 53 63 68 65 6d 61 t..** .** Schema
7520: 20 6f 62 6a 65 63 74 73 20 61 72 65 20 61 75 74 objects are aut
7530: 6f 6d 61 74 69 63 61 6c 6c 79 20 64 65 61 6c 6c omatically deall
7540: 6f 63 61 74 65 64 20 77 68 65 6e 20 74 68 65 20 ocated when the
7550: 6c 61 73 74 20 42 74 72 65 65 20 74 68 61 74 0a last Btree that.
7560: 2a 2a 20 72 65 66 65 72 65 6e 63 65 73 20 74 68 ** references th
7570: 65 6d 20 69 73 20 64 65 73 74 72 6f 79 65 64 2e em is destroyed.
7580: 20 20 20 54 68 65 20 54 45 4d 50 20 53 63 68 65 The TEMP Sche
7590: 6d 61 20 69 73 20 6d 61 6e 75 61 6c 6c 79 20 66 ma is manually f
75a0: 72 65 65 64 20 62 79 0a 2a 2a 20 73 71 6c 69 74 reed by.** sqlit
75b0: 65 33 5f 63 6c 6f 73 65 28 29 2e 0a 2a 0a 2a 2a e3_close()..*.**
75c0: 20 41 20 74 68 72 65 61 64 20 6d 75 73 74 20 62 A thread must b
75d0: 65 20 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 e holding a mute
75e0: 78 20 6f 6e 20 74 68 65 20 63 6f 72 72 65 73 70 x on the corresp
75f0: 6f 6e 64 69 6e 67 20 42 74 72 65 65 20 69 6e 20 onding Btree in
7600: 6f 72 64 65 72 0a 2a 2a 20 74 6f 20 61 63 63 65 order.** to acce
7610: 73 73 20 53 63 68 65 6d 61 20 63 6f 6e 74 65 6e ss Schema conten
7620: 74 2e 20 20 54 68 69 73 20 69 6d 70 6c 69 65 73 t. This implies
7630: 20 74 68 61 74 20 74 68 65 20 74 68 72 65 61 64 that the thread
7640: 20 6d 75 73 74 20 61 6c 73 6f 20 62 65 0a 2a 2a must also be.**
7650: 20 68 6f 6c 64 69 6e 67 20 61 20 6d 75 74 65 78 holding a mutex
7660: 20 6f 6e 20 74 68 65 20 73 71 6c 69 74 65 33 20 on the sqlite3
7670: 63 6f 6e 6e 65 63 74 69 6f 6e 20 70 6f 69 6e 74 connection point
7680: 65 72 20 74 68 61 74 20 6f 77 6e 73 20 74 68 65 er that owns the
7690: 20 42 74 72 65 65 2e 0a 2a 2a 20 46 6f 72 20 61 Btree..** For a
76a0: 20 54 45 4d 50 20 53 63 68 65 6d 61 2c 20 6f 6e TEMP Schema, on
76b0: 6c 79 20 74 68 65 20 63 6f 6e 6e 65 63 74 69 6f ly the connectio
76c0: 6e 20 6d 75 74 65 78 20 69 73 20 72 65 71 75 69 n mutex is requi
76d0: 72 65 64 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 red..*/.struct S
76e0: 63 68 65 6d 61 20 7b 0a 20 20 69 6e 74 20 73 63 chema {. int sc
76f0: 68 65 6d 61 5f 63 6f 6f 6b 69 65 3b 20 20 20 2f hema_cookie; /
7700: 2a 20 44 61 74 61 62 61 73 65 20 73 63 68 65 6d * Database schem
7710: 61 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 a version number
7720: 20 66 6f 72 20 74 68 69 73 20 66 69 6c 65 20 2a for this file *
7730: 2f 0a 20 20 69 6e 74 20 69 47 65 6e 65 72 61 74 /. int iGenerat
7740: 69 6f 6e 3b 20 20 20 20 20 2f 2a 20 47 65 6e 65 ion; /* Gene
7750: 72 61 74 69 6f 6e 20 63 6f 75 6e 74 65 72 2e 20 ration counter.
7760: 20 49 6e 63 72 65 6d 65 6e 74 65 64 20 77 69 74 Incremented wit
7770: 68 20 65 61 63 68 20 63 68 61 6e 67 65 20 2a 2f h each change */
7780: 0a 20 20 48 61 73 68 20 74 62 6c 48 61 73 68 3b . Hash tblHash;
7790: 20 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 74 /* All t
77a0: 61 62 6c 65 73 20 69 6e 64 65 78 65 64 20 62 79 ables indexed by
77b0: 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 20 name */. Hash
77c0: 69 64 78 48 61 73 68 3b 20 20 20 20 20 20 20 20 idxHash;
77d0: 2f 2a 20 41 6c 6c 20 28 6e 61 6d 65 64 29 20 69 /* All (named) i
77e0: 6e 64 69 63 65 73 20 69 6e 64 65 78 65 64 20 62 ndices indexed b
77f0: 79 20 6e 61 6d 65 20 2a 2f 0a 20 20 48 61 73 68 y name */. Hash
7800: 20 74 72 69 67 48 61 73 68 3b 20 20 20 20 20 20 trigHash;
7810: 20 2f 2a 20 41 6c 6c 20 74 72 69 67 67 65 72 73 /* All triggers
7820: 20 69 6e 64 65 78 65 64 20 62 79 20 6e 61 6d 65 indexed by name
7830: 20 2a 2f 0a 20 20 48 61 73 68 20 66 6b 65 79 48 */. Hash fkeyH
7840: 61 73 68 3b 20 20 20 20 20 20 20 2f 2a 20 41 6c ash; /* Al
7850: 6c 20 66 6f 72 65 69 67 6e 20 6b 65 79 73 20 62 l foreign keys b
7860: 79 20 72 65 66 65 72 65 6e 63 65 64 20 74 61 62 y referenced tab
7870: 6c 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 54 61 62 le name */. Tab
7880: 6c 65 20 2a 70 53 65 71 54 61 62 3b 20 20 20 20 le *pSeqTab;
7890: 20 20 2f 2a 20 54 68 65 20 73 71 6c 69 74 65 5f /* The sqlite_
78a0: 73 65 71 75 65 6e 63 65 20 74 61 62 6c 65 20 75 sequence table u
78b0: 73 65 64 20 62 79 20 41 55 54 4f 49 4e 43 52 45 sed by AUTOINCRE
78c0: 4d 45 4e 54 20 2a 2f 0a 20 20 75 38 20 66 69 6c MENT */. u8 fil
78d0: 65 5f 66 6f 72 6d 61 74 3b 20 20 20 20 20 20 2f e_format; /
78e0: 2a 20 53 63 68 65 6d 61 20 66 6f 72 6d 61 74 20 * Schema format
78f0: 76 65 72 73 69 6f 6e 20 66 6f 72 20 74 68 69 73 version for this
7900: 20 66 69 6c 65 20 2a 2f 0a 20 20 75 38 20 65 6e file */. u8 en
7910: 63 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 c;
7920: 2f 2a 20 54 65 78 74 20 65 6e 63 6f 64 69 6e 67 /* Text encoding
7930: 20 75 73 65 64 20 62 79 20 74 68 69 73 20 64 61 used by this da
7940: 74 61 62 61 73 65 20 2a 2f 0a 20 20 75 31 36 20 tabase */. u16
7950: 73 63 68 65 6d 61 46 6c 61 67 73 3b 20 20 20 20 schemaFlags;
7960: 20 2f 2a 20 46 6c 61 67 73 20 61 73 73 6f 63 69 /* Flags associ
7970: 61 74 65 64 20 77 69 74 68 20 74 68 69 73 20 73 ated with this s
7980: 63 68 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 63 chema */. int c
7990: 61 63 68 65 5f 73 69 7a 65 3b 20 20 20 20 20 20 ache_size;
79a0: 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 70 61 67 /* Number of pag
79b0: 65 73 20 74 6f 20 75 73 65 20 69 6e 20 74 68 65 es to use in the
79c0: 20 63 61 63 68 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a cache */.};../*
79d0: 0a 2a 2a 20 54 68 65 73 65 20 6d 61 63 72 6f 73 .** These macros
79e0: 20 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 can be used to
79f0: 74 65 73 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c test, set, or cl
7a00: 65 61 72 20 62 69 74 73 20 69 6e 20 74 68 65 20 ear bits in the
7a10: 0a 2a 2a 20 44 62 2e 70 53 63 68 65 6d 61 2d 3e .** Db.pSchema->
7a20: 66 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a flags field..*/.
7a30: 23 64 65 66 69 6e 65 20 44 62 48 61 73 50 72 6f #define DbHasPro
7a40: 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 20 20 perty(D,I,P)
7a50: 20 28 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 (((D)->aDb[I].p
7a60: 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c Schema->schemaFl
7a70: 61 67 73 26 28 50 29 29 3d 3d 28 50 29 29 0a 23 ags&(P))==(P)).#
7a80: 64 65 66 69 6e 65 20 44 62 48 61 73 41 6e 79 50 define DbHasAnyP
7a90: 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 29 20 20 roperty(D,I,P)
7aa0: 28 28 28 44 29 2d 3e 61 44 62 5b 49 5d 2e 70 53 (((D)->aDb[I].pS
7ab0: 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 6c 61 chema->schemaFla
7ac0: 67 73 26 28 50 29 29 21 3d 30 29 0a 23 64 65 66 gs&(P))!=0).#def
7ad0: 69 6e 65 20 44 62 53 65 74 50 72 6f 70 65 72 74 ine DbSetPropert
7ae0: 79 28 44 2c 49 2c 50 29 20 20 20 20 20 28 44 29 y(D,I,P) (D)
7af0: 2d 3e 61 44 62 5b 49 5d 2e 70 53 63 68 65 6d 61 ->aDb[I].pSchema
7b00: 2d 3e 73 63 68 65 6d 61 46 6c 61 67 73 7c 3d 28 ->schemaFlags|=(
7b10: 50 29 0a 23 64 65 66 69 6e 65 20 44 62 43 6c 65 P).#define DbCle
7b20: 61 72 50 72 6f 70 65 72 74 79 28 44 2c 49 2c 50 arProperty(D,I,P
7b30: 29 20 20 20 28 44 29 2d 3e 61 44 62 5b 49 5d 2e ) (D)->aDb[I].
7b40: 70 53 63 68 65 6d 61 2d 3e 73 63 68 65 6d 61 46 pSchema->schemaF
7b50: 6c 61 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 0a 2a lags&=~(P)../*.*
7b60: 2a 20 41 6c 6c 6f 77 65 64 20 76 61 6c 75 65 73 * Allowed values
7b70: 20 66 6f 72 20 74 68 65 20 44 42 2e 70 53 63 68 for the DB.pSch
7b80: 65 6d 61 2d 3e 66 6c 61 67 73 20 66 69 65 6c 64 ema->flags field
7b90: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 44 42 5f 53 ..**.** The DB_S
7ba0: 63 68 65 6d 61 4c 6f 61 64 65 64 20 66 6c 61 67 chemaLoaded flag
7bb0: 20 69 73 20 73 65 74 20 61 66 74 65 72 20 74 68 is set after th
7bc0: 65 20 64 61 74 61 62 61 73 65 20 73 63 68 65 6d e database schem
7bd0: 61 20 68 61 73 20 62 65 65 6e 0a 2a 2a 20 72 65 a has been.** re
7be0: 61 64 20 69 6e 74 6f 20 69 6e 74 65 72 6e 61 6c ad into internal
7bf0: 20 68 61 73 68 20 74 61 62 6c 65 73 2e 0a 2a 2a hash tables..**
7c00: 0a 2a 2a 20 44 42 5f 55 6e 72 65 73 65 74 56 69 .** DB_UnresetVi
7c10: 65 77 73 20 6d 65 61 6e 73 20 74 68 61 74 20 6f ews means that o
7c20: 6e 65 20 6f 72 20 6d 6f 72 65 20 76 69 65 77 73 ne or more views
7c30: 20 68 61 76 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d have column nam
7c40: 65 73 20 74 68 61 74 0a 2a 2a 20 68 61 76 65 20 es that.** have
7c50: 62 65 65 6e 20 66 69 6c 6c 65 64 20 6f 75 74 2e been filled out.
7c60: 20 20 49 66 20 74 68 65 20 73 63 68 65 6d 61 20 If the schema
7c70: 63 68 61 6e 67 65 73 2c 20 74 68 65 73 65 20 63 changes, these c
7c80: 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6d 69 67 68 olumn names migh
7c90: 74 0a 2a 2a 20 63 68 61 6e 67 65 73 20 61 6e 64 t.** changes and
7ca0: 20 73 6f 20 74 68 65 20 76 69 65 77 20 77 69 6c so the view wil
7cb0: 6c 20 6e 65 65 64 20 74 6f 20 62 65 20 72 65 73 l need to be res
7cc0: 65 74 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 44 et..*/.#define D
7cd0: 42 5f 53 63 68 65 6d 61 4c 6f 61 64 65 64 20 20 B_SchemaLoaded
7ce0: 20 20 30 78 30 30 30 31 20 20 2f 2a 20 54 68 65 0x0001 /* The
7cf0: 20 73 63 68 65 6d 61 20 68 61 73 20 62 65 65 6e schema has been
7d00: 20 6c 6f 61 64 65 64 20 2a 2f 0a 23 64 65 66 69 loaded */.#defi
7d10: 6e 65 20 44 42 5f 55 6e 72 65 73 65 74 56 69 65 ne DB_UnresetVie
7d20: 77 73 20 20 20 20 30 78 30 30 30 32 20 20 2f 2a ws 0x0002 /*
7d30: 20 53 6f 6d 65 20 76 69 65 77 73 20 68 61 76 65 Some views have
7d40: 20 64 65 66 69 6e 65 64 20 63 6f 6c 75 6d 6e 20 defined column
7d50: 6e 61 6d 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 names */.#define
7d60: 20 44 42 5f 45 6d 70 74 79 20 20 20 20 20 20 20 DB_Empty
7d70: 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 54 0x0004 /* T
7d80: 68 65 20 66 69 6c 65 20 69 73 20 65 6d 70 74 79 he file is empty
7d90: 20 28 6c 65 6e 67 74 68 20 30 20 62 79 74 65 73 (length 0 bytes
7da0: 29 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 ) */../*.** The
7db0: 6e 75 6d 62 65 72 20 6f 66 20 64 69 66 66 65 72 number of differ
7dc0: 65 6e 74 20 6b 69 6e 64 73 20 6f 66 20 74 68 69 ent kinds of thi
7dd0: 6e 67 73 20 74 68 61 74 20 63 61 6e 20 62 65 20 ngs that can be
7de0: 6c 69 6d 69 74 65 64 0a 2a 2a 20 75 73 69 6e 67 limited.** using
7df0: 20 74 68 65 20 73 71 6c 69 74 65 33 5f 6c 69 6d the sqlite3_lim
7e00: 69 74 28 29 20 69 6e 74 65 72 66 61 63 65 2e 0a it() interface..
7e10: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
7e20: 45 5f 4e 5f 4c 49 4d 49 54 20 28 53 51 4c 49 54 E_N_LIMIT (SQLIT
7e30: 45 5f 4c 49 4d 49 54 5f 54 52 49 47 47 45 52 5f E_LIMIT_TRIGGER_
7e40: 44 45 50 54 48 2b 31 29 0a 0a 2f 2a 0a 2a 2a 20 DEPTH+1)../*.**
7e50: 4c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 Lookaside malloc
7e60: 20 69 73 20 61 20 73 65 74 20 6f 66 20 66 69 78 is a set of fix
7e70: 65 64 2d 73 69 7a 65 20 62 75 66 66 65 72 73 20 ed-size buffers
7e80: 74 68 61 74 20 63 61 6e 20 62 65 20 75 73 65 64 that can be used
7e90: 0a 2a 2a 20 74 6f 20 73 61 74 69 73 66 79 20 73 .** to satisfy s
7ea0: 6d 61 6c 6c 20 74 72 61 6e 73 69 65 6e 74 20 6d mall transient m
7eb0: 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e emory allocation
7ec0: 20 72 65 71 75 65 73 74 73 20 66 6f 72 20 6f 62 requests for ob
7ed0: 6a 65 63 74 73 0a 2a 2a 20 61 73 73 6f 63 69 61 jects.** associa
7ee0: 74 65 64 20 77 69 74 68 20 61 20 70 61 72 74 69 ted with a parti
7ef0: 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 cular database c
7f00: 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 54 68 65 20 onnection. The
7f10: 75 73 65 20 6f 66 0a 2a 2a 20 6c 6f 6f 6b 61 73 use of.** lookas
7f20: 69 64 65 20 6d 61 6c 6c 6f 63 20 70 72 6f 76 69 ide malloc provi
7f30: 64 65 73 20 61 20 73 69 67 6e 69 66 69 63 61 6e des a significan
7f40: 74 20 70 65 72 66 6f 72 6d 61 6e 63 65 20 65 6e t performance en
7f50: 68 61 6e 63 65 6d 65 6e 74 0a 2a 2a 20 28 61 70 hancement.** (ap
7f60: 70 72 6f 78 20 31 30 25 29 20 62 79 20 61 76 6f prox 10%) by avo
7f70: 69 64 69 6e 67 20 6e 75 6d 65 72 6f 75 73 20 6d iding numerous m
7f80: 61 6c 6c 6f 63 2f 66 72 65 65 20 72 65 71 75 65 alloc/free reque
7f90: 73 74 73 20 77 68 69 6c 65 20 70 61 72 73 69 6e sts while parsin
7fa0: 67 0a 2a 2a 20 53 51 4c 20 73 74 61 74 65 6d 65 g.** SQL stateme
7fb0: 6e 74 73 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 4c nts..**.** The L
7fc0: 6f 6f 6b 61 73 69 64 65 20 73 74 72 75 63 74 75 ookaside structu
7fd0: 72 65 20 68 6f 6c 64 73 20 63 6f 6e 66 69 67 75 re holds configu
7fe0: 72 61 74 69 6f 6e 20 69 6e 66 6f 72 6d 61 74 69 ration informati
7ff0: 6f 6e 20 61 62 6f 75 74 20 74 68 65 0a 2a 2a 20 on about the.**
8000: 6c 6f 6f 6b 61 73 69 64 65 20 6d 61 6c 6c 6f 63 lookaside malloc
8010: 20 73 75 62 73 79 73 74 65 6d 2e 20 20 45 61 63 subsystem. Eac
8020: 68 20 61 76 61 69 6c 61 62 6c 65 20 6d 65 6d 6f h available memo
8030: 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e ry allocation in
8040: 0a 2a 2a 20 74 68 65 20 6c 6f 6f 6b 61 73 69 64 .** the lookasid
8050: 65 20 73 75 62 73 79 73 74 65 6d 20 69 73 20 73 e subsystem is s
8060: 74 6f 72 65 64 20 6f 6e 20 61 20 6c 69 6e 6b 65 tored on a linke
8070: 64 20 6c 69 73 74 20 6f 66 20 4c 6f 6f 6b 61 73 d list of Lookas
8080: 69 64 65 53 6c 6f 74 0a 2a 2a 20 6f 62 6a 65 63 ideSlot.** objec
8090: 74 73 2e 0a 2a 2a 0a 2a 2a 20 4c 6f 6f 6b 61 73 ts..**.** Lookas
80a0: 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 ide allocations
80b0: 61 72 65 20 6f 6e 6c 79 20 61 6c 6c 6f 77 65 64 are only allowed
80c0: 20 66 6f 72 20 6f 62 6a 65 63 74 73 20 74 68 61 for objects tha
80d0: 74 20 61 72 65 20 61 73 73 6f 63 69 61 74 65 64 t are associated
80e0: 0a 2a 2a 20 77 69 74 68 20 61 20 70 61 72 74 69 .** with a parti
80f0: 63 75 6c 61 72 20 64 61 74 61 62 61 73 65 20 63 cular database c
8100: 6f 6e 6e 65 63 74 69 6f 6e 2e 20 20 48 65 6e 63 onnection. Henc
8110: 65 2c 20 73 63 68 65 6d 61 20 69 6e 66 6f 72 6d e, schema inform
8120: 61 74 69 6f 6e 20 63 61 6e 6e 6f 74 0a 2a 2a 20 ation cannot.**
8130: 62 65 20 73 74 6f 72 65 64 20 69 6e 20 6c 6f 6f be stored in loo
8140: 6b 61 73 69 64 65 20 62 65 63 61 75 73 65 20 69 kaside because i
8150: 6e 20 73 68 61 72 65 64 20 63 61 63 68 65 20 6d n shared cache m
8160: 6f 64 65 20 74 68 65 20 73 63 68 65 6d 61 20 69 ode the schema i
8170: 6e 66 6f 72 6d 61 74 69 6f 6e 0a 2a 2a 20 69 73 nformation.** is
8180: 20 73 68 61 72 65 64 20 62 79 20 6d 75 6c 74 69 shared by multi
8190: 70 6c 65 20 64 61 74 61 62 61 73 65 20 63 6f 6e ple database con
81a0: 6e 65 63 74 69 6f 6e 73 2e 20 20 54 68 65 72 65 nections. There
81b0: 66 6f 72 65 2c 20 77 68 69 6c 65 20 70 61 72 73 fore, while pars
81c0: 69 6e 67 0a 2a 2a 20 73 63 68 65 6d 61 20 69 6e ing.** schema in
81d0: 66 6f 72 6d 61 74 69 6f 6e 2c 20 74 68 65 20 4c formation, the L
81e0: 6f 6f 6b 61 73 69 64 65 2e 62 45 6e 61 62 6c 65 ookaside.bEnable
81f0: 64 20 66 6c 61 67 20 69 73 20 63 6c 65 61 72 65 d flag is cleare
8200: 64 20 73 6f 20 74 68 61 74 0a 2a 2a 20 6c 6f 6f d so that.** loo
8210: 6b 61 73 69 64 65 20 61 6c 6c 6f 63 61 74 69 6f kaside allocatio
8220: 6e 73 20 61 72 65 20 6e 6f 74 20 75 73 65 64 20 ns are not used
8230: 74 6f 20 63 6f 6e 73 74 72 75 63 74 20 74 68 65 to construct the
8240: 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 73 2e schema objects.
8250: 0a 2a 2f 0a 73 74 72 75 63 74 20 4c 6f 6f 6b 61 .*/.struct Looka
8260: 73 69 64 65 20 7b 0a 20 20 75 31 36 20 73 7a 3b side {. u16 sz;
8270: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8280: 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 63 68 /* Size of each
8290: 20 62 75 66 66 65 72 20 69 6e 20 62 79 74 65 73 buffer in bytes
82a0: 20 2a 2f 0a 20 20 75 38 20 62 45 6e 61 62 6c 65 */. u8 bEnable
82b0: 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a d; /*
82c0: 20 46 61 6c 73 65 20 74 6f 20 64 69 73 61 62 6c False to disabl
82d0: 65 20 6e 65 77 20 6c 6f 6f 6b 61 73 69 64 65 20 e new lookaside
82e0: 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 2a 2f 0a 20 allocations */.
82f0: 20 75 38 20 62 4d 61 6c 6c 6f 63 65 64 3b 20 20 u8 bMalloced;
8300: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 /* True
8310: 20 69 66 20 70 53 74 61 72 74 20 6f 62 74 61 69 if pStart obtai
8320: 6e 65 64 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 ned from sqlite3
8330: 5f 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 20 20 69 _malloc() */. i
8340: 6e 74 20 6e 4f 75 74 3b 20 20 20 20 20 20 20 20 nt nOut;
8350: 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
8360: 20 6f 66 20 62 75 66 66 65 72 73 20 63 75 72 72 of buffers curr
8370: 65 6e 74 6c 79 20 63 68 65 63 6b 65 64 20 6f 75 ently checked ou
8380: 74 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 4f 75 74 t */. int mxOut
8390: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
83a0: 2a 20 48 69 67 68 77 61 74 65 72 20 6d 61 72 6b * Highwater mark
83b0: 20 66 6f 72 20 6e 4f 75 74 20 2a 2f 0a 20 20 69 for nOut */. i
83c0: 6e 74 20 61 6e 53 74 61 74 5b 33 5d 3b 20 20 20 nt anStat[3];
83d0: 20 20 20 20 20 20 20 2f 2a 20 30 3a 20 68 69 74 /* 0: hit
83e0: 73 2e 20 20 31 3a 20 73 69 7a 65 20 6d 69 73 73 s. 1: size miss
83f0: 65 73 2e 20 20 32 3a 20 66 75 6c 6c 20 6d 69 73 es. 2: full mis
8400: 73 65 73 20 2a 2f 0a 20 20 4c 6f 6f 6b 61 73 69 ses */. Lookasi
8410: 64 65 53 6c 6f 74 20 2a 70 46 72 65 65 3b 20 20 deSlot *pFree;
8420: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 61 76 61 69 /* List of avai
8430: 6c 61 62 6c 65 20 62 75 66 66 65 72 73 20 2a 2f lable buffers */
8440: 0a 20 20 76 6f 69 64 20 2a 70 53 74 61 72 74 3b . void *pStart;
8450: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 69 /* Fi
8460: 72 73 74 20 62 79 74 65 20 6f 66 20 61 76 61 69 rst byte of avai
8470: 6c 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 70 61 lable memory spa
8480: 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 45 ce */. void *pE
8490: 6e 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 nd;
84a0: 2f 2a 20 46 69 72 73 74 20 62 79 74 65 20 70 61 /* First byte pa
84b0: 73 74 20 65 6e 64 20 6f 66 20 61 76 61 69 6c 61 st end of availa
84c0: 62 6c 65 20 73 70 61 63 65 20 2a 2f 0a 7d 3b 0a ble space */.};.
84d0: 73 74 72 75 63 74 20 4c 6f 6f 6b 61 73 69 64 65 struct Lookaside
84e0: 53 6c 6f 74 20 7b 0a 20 20 4c 6f 6f 6b 61 73 69 Slot {. Lookasi
84f0: 64 65 53 6c 6f 74 20 2a 70 4e 65 78 74 3b 20 20 deSlot *pNext;
8500: 20 20 2f 2a 20 4e 65 78 74 20 62 75 66 66 65 72 /* Next buffer
8510: 20 69 6e 20 74 68 65 20 6c 69 73 74 20 6f 66 20 in the list of
8520: 66 72 65 65 20 62 75 66 66 65 72 73 20 2a 2f 0a free buffers */.
8530: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 68 61 73 68 };../*.** A hash
8540: 20 74 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 table for funct
8550: 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e 73 2e ion definitions.
8560: 0a 2a 2a 0a 2a 2a 20 48 61 73 68 20 65 61 63 68 .**.** Hash each
8570: 20 46 75 6e 63 44 65 66 20 73 74 72 75 63 74 75 FuncDef structu
8580: 72 65 20 69 6e 74 6f 20 6f 6e 65 20 6f 66 20 74 re into one of t
8590: 68 65 20 46 75 6e 63 44 65 66 48 61 73 68 2e 61 he FuncDefHash.a
85a0: 5b 5d 20 73 6c 6f 74 73 2e 0a 2a 2a 20 43 6f 6c [] slots..** Col
85b0: 6c 69 73 69 6f 6e 73 20 61 72 65 20 6f 6e 20 74 lisions are on t
85c0: 68 65 20 46 75 6e 63 44 65 66 2e 70 48 61 73 68 he FuncDef.pHash
85d0: 20 63 68 61 69 6e 2e 0a 2a 2f 0a 73 74 72 75 63 chain..*/.struc
85e0: 74 20 46 75 6e 63 44 65 66 48 61 73 68 20 7b 0a t FuncDefHash {.
85f0: 20 20 46 75 6e 63 44 65 66 20 2a 61 5b 32 33 5d FuncDef *a[23]
8600: 3b 20 20 20 20 20 20 20 2f 2a 20 48 61 73 68 20 ; /* Hash
8610: 74 61 62 6c 65 20 66 6f 72 20 66 75 6e 63 74 69 table for functi
8620: 6f 6e 73 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a ons */.};../*.**
8630: 20 45 61 63 68 20 64 61 74 61 62 61 73 65 20 63 Each database c
8640: 6f 6e 6e 65 63 74 69 6f 6e 20 69 73 20 61 6e 20 onnection is an
8650: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
8660: 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
8670: 75 72 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 73 ure..*/.struct s
8680: 71 6c 69 74 65 33 20 7b 0a 20 20 73 71 6c 69 74 qlite3 {. sqlit
8690: 65 33 5f 76 66 73 20 2a 70 56 66 73 3b 20 20 20 e3_vfs *pVfs;
86a0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 53 20 49 /* OS I
86b0: 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 74 nterface */. st
86c0: 72 75 63 74 20 56 64 62 65 20 2a 70 56 64 62 65 ruct Vdbe *pVdbe
86d0: 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c ; /* L
86e0: 69 73 74 20 6f 66 20 61 63 74 69 76 65 20 76 69 ist of active vi
86f0: 72 74 75 61 6c 20 6d 61 63 68 69 6e 65 73 20 2a rtual machines *
8700: 2f 0a 20 20 43 6f 6c 6c 53 65 71 20 2a 70 44 66 /. CollSeq *pDf
8710: 6c 74 43 6f 6c 6c 3b 20 20 20 20 20 20 20 20 20 ltColl;
8720: 20 20 2f 2a 20 54 68 65 20 64 65 66 61 75 6c 74 /* The default
8730: 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 collating seque
8740: 6e 63 65 20 28 42 49 4e 41 52 59 29 20 2a 2f 0a nce (BINARY) */.
8750: 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 20 sqlite3_mutex
8760: 2a 6d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 *mutex;
8770: 2f 2a 20 43 6f 6e 6e 65 63 74 69 6f 6e 20 6d 75 /* Connection mu
8780: 74 65 78 20 2a 2f 0a 20 20 44 62 20 2a 61 44 62 tex */. Db *aDb
8790: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
87a0: 20 20 20 20 20 20 20 2f 2a 20 41 6c 6c 20 62 61 /* All ba
87b0: 63 6b 65 6e 64 73 20 2a 2f 0a 20 20 69 6e 74 20 ckends */. int
87c0: 6e 44 62 3b 20 20 20 20 20 20 20 20 20 20 20 20 nDb;
87d0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
87e0: 62 65 72 20 6f 66 20 62 61 63 6b 65 6e 64 73 20 ber of backends
87f0: 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 73 65 currently in use
8800: 20 2a 2f 0a 20 20 69 6e 74 20 66 6c 61 67 73 3b */. int flags;
8810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8820: 20 20 20 20 2f 2a 20 4d 69 73 63 65 6c 6c 61 6e /* Miscellan
8830: 65 6f 75 73 20 66 6c 61 67 73 2e 20 53 65 65 20 eous flags. See
8840: 62 65 6c 6f 77 20 2a 2f 0a 20 20 69 36 34 20 6c below */. i64 l
8850: 61 73 74 52 6f 77 69 64 3b 20 20 20 20 20 20 20 astRowid;
8860: 20 20 20 20 20 20 20 20 20 2f 2a 20 52 4f 57 49 /* ROWI
8870: 44 20 6f 66 20 6d 6f 73 74 20 72 65 63 65 6e 74 D of most recent
8880: 20 69 6e 73 65 72 74 20 28 73 65 65 20 61 62 6f insert (see abo
8890: 76 65 29 20 2a 2f 0a 20 20 69 36 34 20 73 7a 4d ve) */. i64 szM
88a0: 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 map;
88b0: 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
88c0: 74 20 6d 6d 61 70 5f 73 69 7a 65 20 73 65 74 74 t mmap_size sett
88d0: 69 6e 67 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 ing */. unsigne
88e0: 64 20 69 6e 74 20 6f 70 65 6e 46 6c 61 67 73 3b d int openFlags;
88f0: 20 20 20 20 20 20 20 2f 2a 20 46 6c 61 67 73 20 /* Flags
8900: 70 61 73 73 65 64 20 74 6f 20 73 71 6c 69 74 65 passed to sqlite
8910: 33 5f 76 66 73 2e 78 4f 70 65 6e 28 29 20 2a 2f 3_vfs.xOpen() */
8920: 0a 20 20 69 6e 74 20 65 72 72 43 6f 64 65 3b 20 . int errCode;
8930: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8940: 20 2f 2a 20 4d 6f 73 74 20 72 65 63 65 6e 74 20 /* Most recent
8950: 65 72 72 6f 72 20 63 6f 64 65 20 28 53 51 4c 49 error code (SQLI
8960: 54 45 5f 2a 29 20 2a 2f 0a 20 20 69 6e 74 20 65 TE_*) */. int e
8970: 72 72 4d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 rrMask;
8980: 20 20 20 20 20 20 20 20 20 2f 2a 20 26 20 72 65 /* & re
8990: 73 75 6c 74 20 63 6f 64 65 73 20 77 69 74 68 20 sult codes with
89a0: 74 68 69 73 20 62 65 66 6f 72 65 20 72 65 74 75 this before retu
89b0: 72 6e 69 6e 67 20 2a 2f 0a 20 20 75 31 36 20 64 rning */. u16 d
89c0: 62 4f 70 74 46 6c 61 67 73 3b 20 20 20 20 20 20 bOptFlags;
89d0: 20 20 20 20 20 20 20 20 20 2f 2a 20 46 6c 61 67 /* Flag
89e0: 73 20 74 6f 20 65 6e 61 62 6c 65 2f 64 69 73 61 s to enable/disa
89f0: 62 6c 65 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e ble optimization
8a00: 73 20 2a 2f 0a 20 20 75 38 20 61 75 74 6f 43 6f s */. u8 autoCo
8a10: 6d 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 mmit;
8a20: 20 20 20 20 20 2f 2a 20 54 68 65 20 61 75 74 6f /* The auto
8a30: 2d 63 6f 6d 6d 69 74 20 66 6c 61 67 2e 20 2a 2f -commit flag. */
8a40: 0a 20 20 75 38 20 74 65 6d 70 5f 73 74 6f 72 65 . u8 temp_store
8a50: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
8a60: 20 2f 2a 20 31 3a 20 66 69 6c 65 20 32 3a 20 6d /* 1: file 2: m
8a70: 65 6d 6f 72 79 20 30 3a 20 64 65 66 61 75 6c 74 emory 0: default
8a80: 20 2a 2f 0a 20 20 75 38 20 6d 61 6c 6c 6f 63 46 */. u8 mallocF
8a90: 61 69 6c 65 64 3b 20 20 20 20 20 20 20 20 20 20 ailed;
8aa0: 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 77 /* True if w
8ab0: 65 20 68 61 76 65 20 73 65 65 6e 20 61 20 6d 61 e have seen a ma
8ac0: 6c 6c 6f 63 20 66 61 69 6c 75 72 65 20 2a 2f 0a lloc failure */.
8ad0: 20 20 75 38 20 64 66 6c 74 4c 6f 63 6b 4d 6f 64 u8 dfltLockMod
8ae0: 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
8af0: 2f 2a 20 44 65 66 61 75 6c 74 20 6c 6f 63 6b 69 /* Default locki
8b00: 6e 67 2d 6d 6f 64 65 20 66 6f 72 20 61 74 74 61 ng-mode for atta
8b10: 63 68 65 64 20 64 62 73 20 2a 2f 0a 20 20 73 69 ched dbs */. si
8b20: 67 6e 65 64 20 63 68 61 72 20 6e 65 78 74 41 75 gned char nextAu
8b30: 74 6f 76 61 63 3b 20 20 20 20 20 20 2f 2a 20 41 tovac; /* A
8b40: 75 74 6f 76 61 63 20 73 65 74 74 69 6e 67 20 61 utovac setting a
8b50: 66 74 65 72 20 56 41 43 55 55 4d 20 69 66 20 3e fter VACUUM if >
8b60: 3d 30 20 2a 2f 0a 20 20 75 38 20 73 75 70 70 72 =0 */. u8 suppr
8b70: 65 73 73 45 72 72 3b 20 20 20 20 20 20 20 20 20 essErr;
8b80: 20 20 20 20 20 20 2f 2a 20 44 6f 20 6e 6f 74 20 /* Do not
8b90: 69 73 73 75 65 20 65 72 72 6f 72 20 6d 65 73 73 issue error mess
8ba0: 61 67 65 73 20 69 66 20 74 72 75 65 20 2a 2f 0a ages if true */.
8bb0: 20 20 75 38 20 76 74 61 62 4f 6e 43 6f 6e 66 6c u8 vtabOnConfl
8bc0: 69 63 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ict;
8bd0: 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 /* Value to retu
8be0: 72 6e 20 66 6f 72 20 73 33 5f 76 74 61 62 5f 6f rn for s3_vtab_o
8bf0: 6e 5f 63 6f 6e 66 6c 69 63 74 28 29 20 2a 2f 0a n_conflict() */.
8c00: 20 20 75 38 20 69 73 54 72 61 6e 73 61 63 74 69 u8 isTransacti
8c10: 6f 6e 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 onSavepoint;
8c20: 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 20 6f /* True if the o
8c30: 75 74 65 72 6d 6f 73 74 20 73 61 76 65 70 6f 69 utermost savepoi
8c40: 6e 74 20 69 73 20 61 20 54 53 20 2a 2f 0a 20 20 nt is a TS */.
8c50: 69 6e 74 20 6e 65 78 74 50 61 67 65 73 69 7a 65 int nextPagesize
8c60: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
8c70: 20 50 61 67 65 73 69 7a 65 20 61 66 74 65 72 20 Pagesize after
8c80: 56 41 43 55 55 4d 20 69 66 20 3e 30 20 2a 2f 0a VACUUM if >0 */.
8c90: 20 20 75 33 32 20 6d 61 67 69 63 3b 20 20 20 20 u32 magic;
8ca0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8cb0: 2f 2a 20 4d 61 67 69 63 20 6e 75 6d 62 65 72 20 /* Magic number
8cc0: 66 6f 72 20 64 65 74 65 63 74 20 6c 69 62 72 61 for detect libra
8cd0: 72 79 20 6d 69 73 75 73 65 20 2a 2f 0a 20 20 69 ry misuse */. i
8ce0: 6e 74 20 6e 43 68 61 6e 67 65 3b 20 20 20 20 20 nt nChange;
8cf0: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
8d00: 56 61 6c 75 65 20 72 65 74 75 72 6e 65 64 20 62 Value returned b
8d10: 79 20 73 71 6c 69 74 65 33 5f 63 68 61 6e 67 65 y sqlite3_change
8d20: 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 54 6f s() */. int nTo
8d30: 74 61 6c 43 68 61 6e 67 65 3b 20 20 20 20 20 20 talChange;
8d40: 20 20 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 /* Value
8d50: 72 65 74 75 72 6e 65 64 20 62 79 20 73 71 6c 69 returned by sqli
8d60: 74 65 33 5f 74 6f 74 61 6c 5f 63 68 61 6e 67 65 te3_total_change
8d70: 73 28 29 20 2a 2f 0a 20 20 69 6e 74 20 61 4c 69 s() */. int aLi
8d80: 6d 69 74 5b 53 51 4c 49 54 45 5f 4e 5f 4c 49 4d mit[SQLITE_N_LIM
8d90: 49 54 5d 3b 20 20 20 2f 2a 20 4c 69 6d 69 74 73 IT]; /* Limits
8da0: 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 73 71 6c */. struct sql
8db0: 69 74 65 33 49 6e 69 74 49 6e 66 6f 20 7b 20 20 ite3InitInfo {
8dc0: 20 20 20 20 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 /* Informati
8dd0: 6f 6e 20 75 73 65 64 20 64 75 72 69 6e 67 20 69 on used during i
8de0: 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 2a 2f nitialization */
8df0: 0a 20 20 20 20 69 6e 74 20 6e 65 77 54 6e 75 6d . int newTnum
8e00: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
8e10: 20 2f 2a 20 52 6f 6f 74 70 61 67 65 20 6f 66 20 /* Rootpage of
8e20: 74 61 62 6c 65 20 62 65 69 6e 67 20 69 6e 69 74 table being init
8e30: 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 20 20 75 ialized */. u
8e40: 38 20 69 44 62 3b 20 20 20 20 20 20 20 20 20 20 8 iDb;
8e50: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 68 /* Wh
8e60: 69 63 68 20 64 62 20 66 69 6c 65 20 69 73 20 62 ich db file is b
8e70: 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 7a 65 64 eing initialized
8e80: 20 2a 2f 0a 20 20 20 20 75 38 20 62 75 73 79 3b */. u8 busy;
8e90: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
8ea0: 20 20 20 20 2f 2a 20 54 52 55 45 20 69 66 20 63 /* TRUE if c
8eb0: 75 72 72 65 6e 74 6c 79 20 69 6e 69 74 69 61 6c urrently initial
8ec0: 69 7a 69 6e 67 20 2a 2f 0a 20 20 20 20 75 38 20 izing */. u8
8ed0: 6f 72 70 68 61 6e 54 72 69 67 67 65 72 3b 20 20 orphanTrigger;
8ee0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 61 73 74 /* Last
8ef0: 20 73 74 61 74 65 6d 65 6e 74 20 69 73 20 6f 72 statement is or
8f00: 70 68 61 6e 65 64 20 54 45 4d 50 20 74 72 69 67 phaned TEMP trig
8f10: 67 65 72 20 2a 2f 0a 20 20 7d 20 69 6e 69 74 3b ger */. } init;
8f20: 0a 20 20 69 6e 74 20 6e 56 64 62 65 41 63 74 69 . int nVdbeActi
8f30: 76 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ve;
8f40: 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 56 44 /* Number of VD
8f50: 42 45 73 20 63 75 72 72 65 6e 74 6c 79 20 72 75 BEs currently ru
8f60: 6e 6e 69 6e 67 20 2a 2f 0a 20 20 69 6e 74 20 6e nning */. int n
8f70: 56 64 62 65 52 65 61 64 3b 20 20 20 20 20 20 20 VdbeRead;
8f80: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
8f90: 65 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 er of active VDB
8fa0: 45 73 20 74 68 61 74 20 72 65 61 64 20 6f 72 20 Es that read or
8fb0: 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 6e write */. int n
8fc0: 56 64 62 65 57 72 69 74 65 3b 20 20 20 20 20 20 VdbeWrite;
8fd0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
8fe0: 65 72 20 6f 66 20 61 63 74 69 76 65 20 56 44 42 er of active VDB
8ff0: 45 73 20 74 68 61 74 20 72 65 61 64 20 61 6e 64 Es that read and
9000: 20 77 72 69 74 65 20 2a 2f 0a 20 20 69 6e 74 20 write */. int
9010: 6e 56 64 62 65 45 78 65 63 3b 20 20 20 20 20 20 nVdbeExec;
9020: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
9030: 62 65 72 20 6f 66 20 6e 65 73 74 65 64 20 63 61 ber of nested ca
9040: 6c 6c 73 20 74 6f 20 56 64 62 65 45 78 65 63 28 lls to VdbeExec(
9050: 29 20 2a 2f 0a 20 20 69 6e 74 20 6e 45 78 74 65 ) */. int nExte
9060: 6e 73 69 6f 6e 3b 20 20 20 20 20 20 20 20 20 20 nsion;
9070: 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
9080: 66 20 6c 6f 61 64 65 64 20 65 78 74 65 6e 73 69 f loaded extensi
9090: 6f 6e 73 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 2a ons */. void **
90a0: 61 45 78 74 65 6e 73 69 6f 6e 3b 20 20 20 20 20 aExtension;
90b0: 20 20 20 20 20 20 20 2f 2a 20 41 72 72 61 79 20 /* Array
90c0: 6f 66 20 73 68 61 72 65 64 20 6c 69 62 72 61 72 of shared librar
90d0: 79 20 68 61 6e 64 6c 65 73 20 2a 2f 0a 20 20 76 y handles */. v
90e0: 6f 69 64 20 28 2a 78 54 72 61 63 65 29 28 76 6f oid (*xTrace)(vo
90f0: 69 64 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 id*,const char*)
9100: 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 72 61 63 ; /* Trac
9110: 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 e function */.
9120: 76 6f 69 64 20 2a 70 54 72 61 63 65 41 72 67 3b void *pTraceArg;
9130: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9140: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 41 72 67 /* Arg
9150: 75 6d 65 6e 74 20 74 6f 20 74 68 65 20 74 72 61 ument to the tra
9160: 63 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 ce function */.
9170: 20 76 6f 69 64 20 28 2a 78 50 72 6f 66 69 6c 65 void (*xProfile
9180: 29 28 76 6f 69 64 2a 2c 63 6f 6e 73 74 20 63 68 )(void*,const ch
9190: 61 72 2a 2c 75 36 34 29 3b 20 20 2f 2a 20 50 72 ar*,u64); /* Pr
91a0: 6f 66 69 6c 69 6e 67 20 66 75 6e 63 74 69 6f 6e ofiling function
91b0: 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f */. void *pPro
91c0: 66 69 6c 65 41 72 67 3b 20 20 20 20 20 20 20 20 fileArg;
91d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
91e0: 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 6f 20 70 /* Argument to p
91f0: 72 6f 66 69 6c 65 20 66 75 6e 63 74 69 6f 6e 20 rofile function
9200: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 43 6f 6d 6d */. void *pComm
9210: 69 74 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 itArg;
9220: 20 20 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 /* Argume
9230: 6e 74 20 74 6f 20 78 43 6f 6d 6d 69 74 43 61 6c nt to xCommitCal
9240: 6c 62 61 63 6b 28 29 20 2a 2f 20 20 20 0a 20 20 lback() */ .
9250: 69 6e 74 20 28 2a 78 43 6f 6d 6d 69 74 43 61 6c int (*xCommitCal
9260: 6c 62 61 63 6b 29 28 76 6f 69 64 2a 29 3b 20 20 lback)(void*);
9270: 20 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 /* Invoked at
9280: 65 76 65 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f every commit. */
9290: 0a 20 20 76 6f 69 64 20 2a 70 52 6f 6c 6c 62 61 . void *pRollba
92a0: 63 6b 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 ckArg;
92b0: 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 /* Argument
92c0: 20 74 6f 20 78 52 6f 6c 6c 62 61 63 6b 43 61 6c to xRollbackCal
92d0: 6c 62 61 63 6b 28 29 20 2a 2f 20 20 20 0a 20 20 lback() */ .
92e0: 76 6f 69 64 20 28 2a 78 52 6f 6c 6c 62 61 63 6b void (*xRollback
92f0: 43 61 6c 6c 62 61 63 6b 29 28 76 6f 69 64 2a 29 Callback)(void*)
9300: 3b 20 2f 2a 20 49 6e 76 6f 6b 65 64 20 61 74 20 ; /* Invoked at
9310: 65 76 65 72 79 20 63 6f 6d 6d 69 74 2e 20 2a 2f every commit. */
9320: 0a 20 20 76 6f 69 64 20 2a 70 55 70 64 61 74 65 . void *pUpdate
9330: 41 72 67 3b 0a 20 20 76 6f 69 64 20 28 2a 78 55 Arg;. void (*xU
9340: 70 64 61 74 65 43 61 6c 6c 62 61 63 6b 29 28 76 pdateCallback)(v
9350: 6f 69 64 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 oid*,int, const
9360: 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 char*,const char
9370: 2a 2c 73 71 6c 69 74 65 5f 69 6e 74 36 34 29 3b *,sqlite_int64);
9380: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
9390: 4f 4d 49 54 5f 57 41 4c 0a 20 20 69 6e 74 20 28 OMIT_WAL. int (
93a0: 2a 78 57 61 6c 43 61 6c 6c 62 61 63 6b 29 28 76 *xWalCallback)(v
93b0: 6f 69 64 20 2a 2c 20 73 71 6c 69 74 65 33 20 2a oid *, sqlite3 *
93c0: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 , const char *,
93d0: 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 57 int);. void *pW
93e0: 61 6c 41 72 67 3b 0a 23 65 6e 64 69 66 0a 20 20 alArg;.#endif.
93f0: 76 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 void(*xCollNeede
9400: 64 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 33 d)(void*,sqlite3
9410: 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 63 *,int eTextRep,c
9420: 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 20 20 76 onst char*);. v
9430: 6f 69 64 28 2a 78 43 6f 6c 6c 4e 65 65 64 65 64 oid(*xCollNeeded
9440: 31 36 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 16)(void*,sqlite
9450: 33 2a 2c 69 6e 74 20 65 54 65 78 74 52 65 70 2c 3*,int eTextRep,
9460: 63 6f 6e 73 74 20 76 6f 69 64 2a 29 3b 0a 20 20 const void*);.
9470: 76 6f 69 64 20 2a 70 43 6f 6c 6c 4e 65 65 64 65 void *pCollNeede
9480: 64 41 72 67 3b 0a 20 20 73 71 6c 69 74 65 33 5f dArg;. sqlite3_
9490: 76 61 6c 75 65 20 2a 70 45 72 72 3b 20 20 20 20 value *pErr;
94a0: 20 20 20 20 20 20 2f 2a 20 4d 6f 73 74 20 72 65 /* Most re
94b0: 63 65 6e 74 20 65 72 72 6f 72 20 6d 65 73 73 61 cent error messa
94c0: 67 65 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a ge */. union {.
94d0: 20 20 20 20 76 6f 6c 61 74 69 6c 65 20 69 6e 74 volatile int
94e0: 20 69 73 49 6e 74 65 72 72 75 70 74 65 64 3b 20 isInterrupted;
94f0: 2f 2a 20 54 72 75 65 20 69 66 20 73 71 6c 69 74 /* True if sqlit
9500: 65 33 5f 69 6e 74 65 72 72 75 70 74 20 68 61 73 e3_interrupt has
9510: 20 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a been called */.
9520: 20 20 20 20 64 6f 75 62 6c 65 20 6e 6f 74 55 73 double notUs
9530: 65 64 31 3b 20 20 20 20 20 20 20 20 20 20 20 20 ed1;
9540: 2f 2a 20 53 70 61 63 65 72 20 2a 2f 0a 20 20 7d /* Spacer */. }
9550: 20 75 31 3b 0a 20 20 4c 6f 6f 6b 61 73 69 64 65 u1;. Lookaside
9560: 20 6c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 lookaside;
9570: 20 20 20 20 20 2f 2a 20 4c 6f 6f 6b 61 73 69 64 /* Lookasid
9580: 65 20 6d 61 6c 6c 6f 63 20 63 6f 6e 66 69 67 75 e malloc configu
9590: 72 61 74 69 6f 6e 20 2a 2f 0a 23 69 66 6e 64 65 ration */.#ifnde
95a0: 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 41 55 f SQLITE_OMIT_AU
95b0: 54 48 4f 52 49 5a 41 54 49 4f 4e 0a 20 20 69 6e THORIZATION. in
95c0: 74 20 28 2a 78 41 75 74 68 29 28 76 6f 69 64 2a t (*xAuth)(void*
95d0: 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a ,int,const char*
95e0: 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 63 6f 6e ,const char*,con
95f0: 73 74 20 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 st char*,const c
9600: 68 61 72 2a 29 3b 0a 20 20 20 20 20 20 20 20 20 har*);.
9610: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9620: 20 20 20 20 20 20 20 2f 2a 20 41 63 63 65 73 73 /* Access
9630: 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 66 authorization f
9640: 75 6e 63 74 69 6f 6e 20 2a 2f 0a 20 20 76 6f 69 unction */. voi
9650: 64 20 2a 70 41 75 74 68 41 72 67 3b 20 20 20 20 d *pAuthArg;
9660: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 73 /* 1s
9670: 74 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 t argument to th
9680: 65 20 61 63 63 65 73 73 20 61 75 74 68 20 66 75 e access auth fu
9690: 6e 63 74 69 6f 6e 20 2a 2f 0a 23 65 6e 64 69 66 nction */.#endif
96a0: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
96b0: 4f 4d 49 54 5f 50 52 4f 47 52 45 53 53 5f 43 41 OMIT_PROGRESS_CA
96c0: 4c 4c 42 41 43 4b 0a 20 20 69 6e 74 20 28 2a 78 LLBACK. int (*x
96d0: 50 72 6f 67 72 65 73 73 29 28 76 6f 69 64 20 2a Progress)(void *
96e0: 29 3b 20 20 20 20 20 2f 2a 20 54 68 65 20 70 72 ); /* The pr
96f0: 6f 67 72 65 73 73 20 63 61 6c 6c 62 61 63 6b 20 ogress callback
9700: 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 72 6f 67 */. void *pProg
9710: 72 65 73 73 41 72 67 3b 20 20 20 20 20 20 20 20 ressArg;
9720: 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 20 74 /* Argument t
9730: 6f 20 74 68 65 20 70 72 6f 67 72 65 73 73 20 63 o the progress c
9740: 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 75 6e 73 allback */. uns
9750: 69 67 6e 65 64 20 6e 50 72 6f 67 72 65 73 73 4f igned nProgressO
9760: 70 73 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 ps; /* Nu
9770: 6d 62 65 72 20 6f 66 20 6f 70 63 6f 64 65 73 20 mber of opcodes
9780: 66 6f 72 20 70 72 6f 67 72 65 73 73 20 63 61 6c for progress cal
9790: 6c 62 61 63 6b 20 2a 2f 0a 23 65 6e 64 69 66 0a lback */.#endif.
97a0: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
97b0: 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
97c0: 0a 20 20 69 6e 74 20 6e 56 54 72 61 6e 73 3b 20 . int nVTrans;
97d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
97e0: 20 2f 2a 20 41 6c 6c 6f 63 61 74 65 64 20 73 69 /* Allocated si
97f0: 7a 65 20 6f 66 20 61 56 54 72 61 6e 73 20 2a 2f ze of aVTrans */
9800: 0a 20 20 48 61 73 68 20 61 4d 6f 64 75 6c 65 3b . Hash aModule;
9810: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9820: 20 2f 2a 20 70 6f 70 75 6c 61 74 65 64 20 62 79 /* populated by
9830: 20 73 71 6c 69 74 65 33 5f 63 72 65 61 74 65 5f sqlite3_create_
9840: 6d 6f 64 75 6c 65 28 29 20 2a 2f 0a 20 20 56 74 module() */. Vt
9850: 61 62 43 74 78 20 2a 70 56 74 61 62 43 74 78 3b abCtx *pVtabCtx;
9860: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
9870: 6f 6e 74 65 78 74 20 66 6f 72 20 61 63 74 69 76 ontext for activ
9880: 65 20 76 74 61 62 20 63 6f 6e 6e 65 63 74 2f 63 e vtab connect/c
9890: 72 65 61 74 65 20 2a 2f 0a 20 20 56 54 61 62 6c reate */. VTabl
98a0: 65 20 2a 2a 61 56 54 72 61 6e 73 3b 20 20 20 20 e **aVTrans;
98b0: 20 20 20 20 20 20 20 20 20 2f 2a 20 56 69 72 74 /* Virt
98c0: 75 61 6c 20 74 61 62 6c 65 73 20 77 69 74 68 20 ual tables with
98d0: 6f 70 65 6e 20 74 72 61 6e 73 61 63 74 69 6f 6e open transaction
98e0: 73 20 2a 2f 0a 20 20 56 54 61 62 6c 65 20 2a 70 s */. VTable *p
98f0: 44 69 73 63 6f 6e 6e 65 63 74 3b 20 20 20 20 2f Disconnect; /
9900: 2a 20 44 69 73 63 6f 6e 6e 65 63 74 20 74 68 65 * Disconnect the
9910: 73 65 20 69 6e 20 6e 65 78 74 20 73 71 6c 69 74 se in next sqlit
9920: 65 33 5f 70 72 65 70 61 72 65 28 29 20 2a 2f 0a e3_prepare() */.
9930: 23 65 6e 64 69 66 0a 20 20 46 75 6e 63 44 65 66 #endif. FuncDef
9940: 48 61 73 68 20 61 46 75 6e 63 3b 20 20 20 20 20 Hash aFunc;
9950: 20 20 20 20 20 20 20 2f 2a 20 48 61 73 68 20 74 /* Hash t
9960: 61 62 6c 65 20 6f 66 20 63 6f 6e 6e 65 63 74 69 able of connecti
9970: 6f 6e 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a on functions */.
9980: 20 20 48 61 73 68 20 61 43 6f 6c 6c 53 65 71 3b Hash aCollSeq;
9990: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
99a0: 2f 2a 20 41 6c 6c 20 63 6f 6c 6c 61 74 69 6e 67 /* All collating
99b0: 20 73 65 71 75 65 6e 63 65 73 20 2a 2f 0a 20 20 sequences */.
99c0: 42 75 73 79 48 61 6e 64 6c 65 72 20 62 75 73 79 BusyHandler busy
99d0: 48 61 6e 64 6c 65 72 3b 20 20 20 20 20 20 2f 2a Handler; /*
99e0: 20 42 75 73 79 20 63 61 6c 6c 62 61 63 6b 20 2a Busy callback *
99f0: 2f 0a 20 20 44 62 20 61 44 62 53 74 61 74 69 63 /. Db aDbStatic
9a00: 5b 32 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 [2];
9a10: 20 20 2f 2a 20 53 74 61 74 69 63 20 73 70 61 63 /* Static spac
9a20: 65 20 66 6f 72 20 74 68 65 20 32 20 64 65 66 61 e for the 2 defa
9a30: 75 6c 74 20 62 61 63 6b 65 6e 64 73 20 2a 2f 0a ult backends */.
9a40: 20 20 53 61 76 65 70 6f 69 6e 74 20 2a 70 53 61 Savepoint *pSa
9a50: 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 vepoint;
9a60: 2f 2a 20 4c 69 73 74 20 6f 66 20 61 63 74 69 76 /* List of activ
9a70: 65 20 73 61 76 65 70 6f 69 6e 74 73 20 2a 2f 0a e savepoints */.
9a80: 20 20 69 6e 74 20 62 75 73 79 54 69 6d 65 6f 75 int busyTimeou
9a90: 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
9aa0: 2f 2a 20 42 75 73 79 20 68 61 6e 64 6c 65 72 20 /* Busy handler
9ab0: 74 69 6d 65 6f 75 74 2c 20 69 6e 20 6d 73 65 63 timeout, in msec
9ac0: 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 76 65 70 */. int nSavep
9ad0: 6f 69 6e 74 3b 20 20 20 20 20 20 20 20 20 20 20 oint;
9ae0: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
9af0: 20 6e 6f 6e 2d 74 72 61 6e 73 61 63 74 69 6f 6e non-transaction
9b00: 20 73 61 76 65 70 6f 69 6e 74 73 20 2a 2f 0a 20 savepoints */.
9b10: 20 69 6e 74 20 6e 53 74 61 74 65 6d 65 6e 74 3b int nStatement;
9b20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
9b30: 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 * Number of nest
9b40: 65 64 20 73 74 61 74 65 6d 65 6e 74 2d 74 72 61 ed statement-tra
9b50: 6e 73 61 63 74 69 6f 6e 73 20 20 2a 2f 0a 20 20 nsactions */.
9b60: 69 36 34 20 6e 44 65 66 65 72 72 65 64 43 6f 6e i64 nDeferredCon
9b70: 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a s; /*
9b80: 20 4e 65 74 20 64 65 66 65 72 72 65 64 20 63 6f Net deferred co
9b90: 6e 73 74 72 61 69 6e 74 73 20 74 68 69 73 20 74 nstraints this t
9ba0: 72 61 6e 73 61 63 74 69 6f 6e 2e 20 2a 2f 0a 20 ransaction. */.
9bb0: 20 69 36 34 20 6e 44 65 66 65 72 72 65 64 49 6d i64 nDeferredIm
9bc0: 6d 43 6f 6e 73 3b 20 20 20 20 20 20 20 20 20 2f mCons; /
9bd0: 2a 20 4e 65 74 20 64 65 66 65 72 72 65 64 20 69 * Net deferred i
9be0: 6d 6d 65 64 69 61 74 65 20 63 6f 6e 73 74 72 61 mmediate constra
9bf0: 69 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 2a 70 ints */. int *p
9c00: 6e 42 79 74 65 73 46 72 65 65 64 3b 20 20 20 20 nBytesFreed;
9c10: 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 6e 6f /* If no
9c20: 74 20 4e 55 4c 4c 2c 20 69 6e 63 72 65 6d 65 6e t NULL, incremen
9c30: 74 20 74 68 69 73 20 69 6e 20 44 62 46 72 65 65 t this in DbFree
9c40: 28 29 20 2a 2f 0a 0a 23 69 66 64 65 66 20 53 51 () */..#ifdef SQ
9c50: 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f LITE_ENABLE_UNLO
9c60: 43 4b 5f 4e 4f 54 49 46 59 0a 20 20 2f 2a 20 54 CK_NOTIFY. /* T
9c70: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 72 he following var
9c80: 69 61 62 6c 65 73 20 61 72 65 20 61 6c 6c 20 70 iables are all p
9c90: 72 6f 74 65 63 74 65 64 20 62 79 20 74 68 65 20 rotected by the
9ca0: 53 54 41 54 49 43 5f 4d 41 53 54 45 52 20 0a 20 STATIC_MASTER .
9cb0: 20 2a 2a 20 6d 75 74 65 78 2c 20 6e 6f 74 20 62 ** mutex, not b
9cc0: 79 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 78 2e y sqlite3.mutex.
9cd0: 20 54 68 65 79 20 61 72 65 20 75 73 65 64 20 62 They are used b
9ce0: 79 20 63 6f 64 65 20 69 6e 20 6e 6f 74 69 66 79 y code in notify
9cf0: 2e 63 2e 20 0a 20 20 2a 2a 0a 20 20 2a 2a 20 57 .c. . **. ** W
9d00: 68 65 6e 20 58 2e 70 55 6e 6c 6f 63 6b 43 6f 6e hen X.pUnlockCon
9d10: 6e 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 68 61 74 nection==Y, that
9d20: 20 6d 65 61 6e 73 20 74 68 61 74 20 58 20 69 73 means that X is
9d30: 20 77 61 69 74 69 6e 67 20 66 6f 72 20 59 20 74 waiting for Y t
9d40: 6f 0a 20 20 2a 2a 20 75 6e 6c 6f 63 6b 20 73 6f o. ** unlock so
9d50: 20 74 68 61 74 20 69 74 20 63 61 6e 20 70 72 6f that it can pro
9d60: 63 65 65 64 2e 0a 20 20 2a 2a 0a 20 20 2a 2a 20 ceed.. **. **
9d70: 57 68 65 6e 20 58 2e 70 42 6c 6f 63 6b 69 6e 67 When X.pBlocking
9d80: 43 6f 6e 6e 65 63 74 69 6f 6e 3d 3d 59 2c 20 74 Connection==Y, t
9d90: 68 61 74 20 6d 65 61 6e 73 20 74 68 61 74 20 73 hat means that s
9da0: 6f 6d 65 74 68 69 6e 67 20 74 68 61 74 20 58 20 omething that X
9db0: 74 72 69 65 64 0a 20 20 2a 2a 20 74 72 69 65 64 tried. ** tried
9dc0: 20 74 6f 20 64 6f 20 72 65 63 65 6e 74 6c 79 20 to do recently
9dd0: 66 61 69 6c 65 64 20 77 69 74 68 20 61 6e 20 53 failed with an S
9de0: 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 65 72 72 QLITE_LOCKED err
9df0: 6f 72 20 64 75 65 20 74 6f 20 6c 6f 63 6b 73 0a or due to locks.
9e00: 20 20 2a 2a 20 68 65 6c 64 20 62 79 20 59 2e 0a ** held by Y..
9e10: 20 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a */. sqlite3 *
9e20: 70 42 6c 6f 63 6b 69 6e 67 43 6f 6e 6e 65 63 74 pBlockingConnect
9e30: 69 6f 6e 3b 20 2f 2a 20 43 6f 6e 6e 65 63 74 69 ion; /* Connecti
9e40: 6f 6e 20 74 68 61 74 20 63 61 75 73 65 64 20 53 on that caused S
9e50: 51 4c 49 54 45 5f 4c 4f 43 4b 45 44 20 2a 2f 0a QLITE_LOCKED */.
9e60: 20 20 73 71 6c 69 74 65 33 20 2a 70 55 6e 6c 6f sqlite3 *pUnlo
9e70: 63 6b 43 6f 6e 6e 65 63 74 69 6f 6e 3b 20 20 20 ckConnection;
9e80: 20 20 20 20 20 20 20 20 2f 2a 20 43 6f 6e 6e 65 /* Conne
9e90: 63 74 69 6f 6e 20 74 6f 20 77 61 74 63 68 20 66 ction to watch f
9ea0: 6f 72 20 75 6e 6c 6f 63 6b 20 2a 2f 0a 20 20 76 or unlock */. v
9eb0: 6f 69 64 20 2a 70 55 6e 6c 6f 63 6b 41 72 67 3b oid *pUnlockArg;
9ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9ed0: 20 20 20 20 20 2f 2a 20 41 72 67 75 6d 65 6e 74 /* Argument
9ee0: 20 74 6f 20 78 55 6e 6c 6f 63 6b 4e 6f 74 69 66 to xUnlockNotif
9ef0: 79 20 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 55 y */. void (*xU
9f00: 6e 6c 6f 63 6b 4e 6f 74 69 66 79 29 28 76 6f 69 nlockNotify)(voi
9f10: 64 20 2a 2a 2c 20 69 6e 74 29 3b 20 20 2f 2a 20 d **, int); /*
9f20: 55 6e 6c 6f 63 6b 20 6e 6f 74 69 66 79 20 63 61 Unlock notify ca
9f30: 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 73 71 6c 69 llback */. sqli
9f40: 74 65 33 20 2a 70 4e 65 78 74 42 6c 6f 63 6b 65 te3 *pNextBlocke
9f50: 64 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 d; /* Nex
9f60: 74 20 69 6e 20 6c 69 73 74 20 6f 66 20 61 6c 6c t in list of all
9f70: 20 62 6c 6f 63 6b 65 64 20 63 6f 6e 6e 65 63 74 blocked connect
9f80: 69 6f 6e 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 7d ions */.#endif.}
9f90: 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 6d 61 63 72 6f ;../*.** A macro
9fa0: 20 74 6f 20 64 69 73 63 6f 76 65 72 20 74 68 65 to discover the
9fb0: 20 65 6e 63 6f 64 69 6e 67 20 6f 66 20 61 20 64 encoding of a d
9fc0: 61 74 61 62 61 73 65 2e 0a 2a 2f 0a 23 64 65 66 atabase..*/.#def
9fd0: 69 6e 65 20 45 4e 43 28 64 62 29 20 28 28 64 62 ine ENC(db) ((db
9fe0: 29 2d 3e 61 44 62 5b 30 5d 2e 70 53 63 68 65 6d )->aDb[0].pSchem
9ff0: 61 2d 3e 65 6e 63 29 0a 0a 2f 2a 0a 2a 2a 20 50 a->enc)../*.** P
a000: 6f 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 ossible values f
a010: 6f 72 20 74 68 65 20 73 71 6c 69 74 65 33 2e 66 or the sqlite3.f
a020: 6c 61 67 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 lags..*/.#define
a030: 20 53 51 4c 49 54 45 5f 56 64 62 65 54 72 61 63 SQLITE_VdbeTrac
a040: 65 20 20 20 20 20 20 30 78 30 30 30 30 30 30 30 e 0x0000000
a050: 31 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 74 72 1 /* True to tr
a060: 61 63 65 20 56 44 42 45 20 65 78 65 63 75 74 69 ace VDBE executi
a070: 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 on */.#define SQ
a080: 4c 49 54 45 5f 49 6e 74 65 72 6e 43 68 61 6e 67 LITE_InternChang
a090: 65 73 20 20 30 78 30 30 30 30 30 30 30 32 20 20 es 0x00000002
a0a0: 2f 2a 20 55 6e 63 6f 6d 6d 69 74 74 65 64 20 48 /* Uncommitted H
a0b0: 61 73 68 20 74 61 62 6c 65 20 63 68 61 6e 67 65 ash table change
a0c0: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
a0d0: 49 54 45 5f 46 75 6c 6c 46 53 79 6e 63 20 20 20 ITE_FullFSync
a0e0: 20 20 20 30 78 30 30 30 30 30 30 30 34 20 20 2f 0x00000004 /
a0f0: 2a 20 55 73 65 20 66 75 6c 6c 20 66 73 79 6e 63 * Use full fsync
a100: 20 6f 6e 20 74 68 65 20 62 61 63 6b 65 6e 64 20 on the backend
a110: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
a120: 45 5f 43 6b 70 74 46 75 6c 6c 46 53 79 6e 63 20 E_CkptFullFSync
a130: 20 30 78 30 30 30 30 30 30 30 38 20 20 2f 2a 20 0x00000008 /*
a140: 55 73 65 20 66 75 6c 6c 20 66 73 79 6e 63 20 66 Use full fsync f
a150: 6f 72 20 63 68 65 63 6b 70 6f 69 6e 74 20 2a 2f or checkpoint */
a160: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
a170: 43 61 63 68 65 53 70 69 6c 6c 20 20 20 20 20 30 CacheSpill 0
a180: 78 30 30 30 30 30 30 31 30 20 20 2f 2a 20 4f 4b x00000010 /* OK
a190: 20 74 6f 20 73 70 69 6c 6c 20 70 61 67 65 72 20 to spill pager
a1a0: 63 61 63 68 65 20 2a 2f 0a 23 64 65 66 69 6e 65 cache */.#define
a1b0: 20 53 51 4c 49 54 45 5f 46 75 6c 6c 43 6f 6c 4e SQLITE_FullColN
a1c0: 61 6d 65 73 20 20 20 30 78 30 30 30 30 30 30 32 ames 0x0000002
a1d0: 30 20 20 2f 2a 20 53 68 6f 77 20 66 75 6c 6c 20 0 /* Show full
a1e0: 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 6f 6e 20 column names on
a1f0: 53 45 4c 45 43 54 20 2a 2f 0a 23 64 65 66 69 6e SELECT */.#defin
a200: 65 20 53 51 4c 49 54 45 5f 53 68 6f 72 74 43 6f e SQLITE_ShortCo
a210: 6c 4e 61 6d 65 73 20 20 30 78 30 30 30 30 30 30 lNames 0x000000
a220: 34 30 20 20 2f 2a 20 53 68 6f 77 20 73 68 6f 72 40 /* Show shor
a230: 74 20 63 6f 6c 75 6d 6e 73 20 6e 61 6d 65 73 20 t columns names
a240: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
a250: 45 5f 43 6f 75 6e 74 52 6f 77 73 20 20 20 20 20 E_CountRows
a260: 20 30 78 30 30 30 30 30 30 38 30 20 20 2f 2a 20 0x00000080 /*
a270: 43 6f 75 6e 74 20 72 6f 77 73 20 63 68 61 6e 67 Count rows chang
a280: 65 64 20 62 79 20 49 4e 53 45 52 54 2c 20 2a 2f ed by INSERT, */
a290: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
a2a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a2b0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 /*
a2c0: 44 45 4c 45 54 45 2c 20 6f 72 20 55 50 44 41 54 DELETE, or UPDAT
a2d0: 45 20 61 6e 64 20 72 65 74 75 72 6e 20 2a 2f 0a E and return */.
a2e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a2f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a300: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 20 74 /* t
a310: 68 65 20 63 6f 75 6e 74 20 75 73 69 6e 67 20 61 he count using a
a320: 20 63 61 6c 6c 62 61 63 6b 2e 20 2a 2f 0a 23 64 callback. */.#d
a330: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 75 6c efine SQLITE_Nul
a340: 6c 43 61 6c 6c 62 61 63 6b 20 20 20 30 78 30 30 lCallback 0x00
a350: 30 30 30 31 30 30 20 20 2f 2a 20 49 6e 76 6f 6b 000100 /* Invok
a360: 65 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 6f e the callback o
a370: 6e 63 65 20 69 66 20 74 68 65 20 2a 2f 0a 20 20 nce if the */.
a380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
a3a0: 20 20 20 20 20 20 20 20 2f 2a 20 20 20 72 65 73 /* res
a3b0: 75 6c 74 20 73 65 74 20 69 73 20 65 6d 70 74 79 ult set is empty
a3c0: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
a3d0: 54 45 5f 53 71 6c 54 72 61 63 65 20 20 20 20 20 TE_SqlTrace
a3e0: 20 20 30 78 30 30 30 30 30 32 30 30 20 20 2f 2a 0x00000200 /*
a3f0: 20 44 65 62 75 67 20 70 72 69 6e 74 20 53 51 4c Debug print SQL
a400: 20 61 73 20 69 74 20 65 78 65 63 75 74 65 73 20 as it executes
a410: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
a420: 45 5f 56 64 62 65 4c 69 73 74 69 6e 67 20 20 20 E_VdbeListing
a430: 20 30 78 30 30 30 30 30 34 30 30 20 20 2f 2a 20 0x00000400 /*
a440: 44 65 62 75 67 20 6c 69 73 74 69 6e 67 73 20 6f Debug listings o
a450: 66 20 56 44 42 45 20 70 72 6f 67 72 61 6d 73 20 f VDBE programs
a460: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
a470: 45 5f 57 72 69 74 65 53 63 68 65 6d 61 20 20 20 E_WriteSchema
a480: 20 30 78 30 30 30 30 30 38 30 30 20 20 2f 2a 20 0x00000800 /*
a490: 4f 4b 20 74 6f 20 75 70 64 61 74 65 20 53 51 4c OK to update SQL
a4a0: 49 54 45 5f 4d 41 53 54 45 52 20 2a 2f 0a 23 64 ITE_MASTER */.#d
a4b0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 56 64 62 efine SQLITE_Vdb
a4c0: 65 41 64 64 6f 70 54 72 61 63 65 20 30 78 30 30 eAddopTrace 0x00
a4d0: 30 30 31 30 30 30 20 20 2f 2a 20 54 72 61 63 65 001000 /* Trace
a4e0: 20 73 71 6c 69 74 65 33 56 64 62 65 41 64 64 4f sqlite3VdbeAddO
a4f0: 70 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 23 64 65 p() calls */.#de
a500: 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 67 6e 6f fine SQLITE_Igno
a510: 72 65 43 68 65 63 6b 73 20 20 20 30 78 30 30 30 reChecks 0x000
a520: 30 32 30 30 30 20 20 2f 2a 20 44 6f 20 6e 6f 74 02000 /* Do not
a530: 20 65 6e 66 6f 72 63 65 20 63 68 65 63 6b 20 63 enforce check c
a540: 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 onstraints */.#d
a550: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 52 65 61 efine SQLITE_Rea
a560: 64 55 6e 63 6f 6d 6d 69 74 74 65 64 20 30 78 30 dUncommitted 0x0
a570: 30 30 34 30 30 30 20 20 2f 2a 20 46 6f 72 20 73 004000 /* For s
a580: 68 61 72 65 64 2d 63 61 63 68 65 20 6d 6f 64 65 hared-cache mode
a590: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
a5a0: 54 45 5f 4c 65 67 61 63 79 46 69 6c 65 46 6d 74 TE_LegacyFileFmt
a5b0: 20 20 30 78 30 30 30 30 38 30 30 30 20 20 2f 2a 0x00008000 /*
a5c0: 20 43 72 65 61 74 65 20 6e 65 77 20 64 61 74 61 Create new data
a5d0: 62 61 73 65 73 20 69 6e 20 66 6f 72 6d 61 74 20 bases in format
a5e0: 31 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 1 */.#define SQL
a5f0: 49 54 45 5f 52 65 63 6f 76 65 72 79 4d 6f 64 65 ITE_RecoveryMode
a600: 20 20 20 30 78 30 30 30 31 30 30 30 30 20 20 2f 0x00010000 /
a610: 2a 20 49 67 6e 6f 72 65 20 73 63 68 65 6d 61 20 * Ignore schema
a620: 65 72 72 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e errors */.#defin
a630: 65 20 53 51 4c 49 54 45 5f 52 65 76 65 72 73 65 e SQLITE_Reverse
a640: 4f 72 64 65 72 20 20 20 30 78 30 30 30 32 30 30 Order 0x000200
a650: 30 30 20 20 2f 2a 20 52 65 76 65 72 73 65 20 75 00 /* Reverse u
a660: 6e 6f 72 64 65 72 65 64 20 53 45 4c 45 43 54 73 nordered SELECTs
a670: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
a680: 54 45 5f 52 65 63 54 72 69 67 67 65 72 73 20 20 TE_RecTriggers
a690: 20 20 30 78 30 30 30 34 30 30 30 30 20 20 2f 2a 0x00040000 /*
a6a0: 20 45 6e 61 62 6c 65 20 72 65 63 75 72 73 69 76 Enable recursiv
a6b0: 65 20 74 72 69 67 67 65 72 73 20 2a 2f 0a 23 64 e triggers */.#d
a6c0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 6f 72 efine SQLITE_For
a6d0: 65 69 67 6e 4b 65 79 73 20 20 20 20 30 78 30 30 eignKeys 0x00
a6e0: 30 38 30 30 30 30 20 20 2f 2a 20 45 6e 66 6f 72 080000 /* Enfor
a6f0: 63 65 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 63 ce foreign key c
a700: 6f 6e 73 74 72 61 69 6e 74 73 20 20 2a 2f 0a 23 onstraints */.#
a710: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 75 define SQLITE_Au
a720: 74 6f 49 6e 64 65 78 20 20 20 20 20 20 30 78 30 toIndex 0x0
a730: 30 31 30 30 30 30 30 20 20 2f 2a 20 45 6e 61 62 0100000 /* Enab
a740: 6c 65 20 61 75 74 6f 6d 61 74 69 63 20 69 6e 64 le automatic ind
a750: 65 78 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 exes */.#define
a760: 53 51 4c 49 54 45 5f 50 72 65 66 65 72 42 75 69 SQLITE_PreferBui
a770: 6c 74 69 6e 20 20 30 78 30 30 32 30 30 30 30 30 ltin 0x00200000
a780: 20 20 2f 2a 20 50 72 65 66 65 72 65 6e 63 65 20 /* Preference
a790: 74 6f 20 62 75 69 6c 74 2d 69 6e 20 66 75 6e 63 to built-in func
a7a0: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
a7b0: 49 54 45 5f 4c 6f 61 64 45 78 74 65 6e 73 69 6f ITE_LoadExtensio
a7c0: 6e 20 20 30 78 30 30 34 30 30 30 30 30 20 20 2f n 0x00400000 /
a7d0: 2a 20 45 6e 61 62 6c 65 20 6c 6f 61 64 5f 65 78 * Enable load_ex
a7e0: 74 65 6e 73 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 tension */.#defi
a7f0: 6e 65 20 53 51 4c 49 54 45 5f 45 6e 61 62 6c 65 ne SQLITE_Enable
a800: 54 72 69 67 67 65 72 20 20 30 78 30 30 38 30 30 Trigger 0x00800
a810: 30 30 30 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 000 /* True to
a820: 65 6e 61 62 6c 65 20 74 72 69 67 67 65 72 73 20 enable triggers
a830: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
a840: 45 5f 44 65 66 65 72 46 4b 73 20 20 20 20 20 20 E_DeferFKs
a850: 20 30 78 30 31 30 30 30 30 30 30 20 20 2f 2a 20 0x01000000 /*
a860: 44 65 66 65 72 20 61 6c 6c 20 46 4b 20 63 6f 6e Defer all FK con
a870: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 64 65 66 straints */.#def
a880: 69 6e 65 20 53 51 4c 49 54 45 5f 51 75 65 72 79 ine SQLITE_Query
a890: 4f 6e 6c 79 20 20 20 20 20 20 30 78 30 32 30 30 Only 0x0200
a8a0: 30 30 30 30 20 20 2f 2a 20 44 69 73 61 62 6c 65 0000 /* Disable
a8b0: 20 64 61 74 61 62 61 73 65 20 63 68 61 6e 67 65 database change
a8c0: 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c s */.#define SQL
a8d0: 49 54 45 5f 56 64 62 65 45 51 50 20 20 20 20 20 ITE_VdbeEQP
a8e0: 20 20 20 30 78 30 34 30 30 30 30 30 30 20 20 2f 0x04000000 /
a8f0: 2a 20 44 65 62 75 67 20 45 58 50 4c 41 49 4e 20 * Debug EXPLAIN
a900: 51 55 45 52 59 20 50 4c 41 4e 20 2a 2f 0a 0a 0a QUERY PLAN */...
a910: 2f 2a 0a 2a 2a 20 42 69 74 73 20 6f 66 20 74 68 /*.** Bits of th
a920: 65 20 73 71 6c 69 74 65 33 2e 64 62 4f 70 74 46 e sqlite3.dbOptF
a930: 6c 61 67 73 20 66 69 65 6c 64 20 74 68 61 74 20 lags field that
a940: 61 72 65 20 75 73 65 64 20 62 79 20 74 68 65 0a are used by the.
a950: 2a 2a 20 73 71 6c 69 74 65 33 5f 74 65 73 74 5f ** sqlite3_test_
a960: 63 6f 6e 74 72 6f 6c 28 53 51 4c 49 54 45 5f 54 control(SQLITE_T
a970: 45 53 54 43 54 52 4c 5f 4f 50 54 49 4d 49 5a 41 ESTCTRL_OPTIMIZA
a980: 54 49 4f 4e 53 2c 2e 2e 2e 29 20 69 6e 74 65 72 TIONS,...) inter
a990: 66 61 63 65 20 74 6f 0a 2a 2a 20 73 65 6c 65 63 face to.** selec
a9a0: 74 69 76 65 6c 79 20 64 69 73 61 62 6c 65 20 76 tively disable v
a9b0: 61 72 69 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 arious optimizat
a9c0: 69 6f 6e 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ions..*/.#define
a9d0: 20 53 51 4c 49 54 45 5f 51 75 65 72 79 46 6c 61 SQLITE_QueryFla
a9e0: 74 74 65 6e 65 72 20 30 78 30 30 30 31 20 20 20 ttener 0x0001
a9f0: 2f 2a 20 51 75 65 72 79 20 66 6c 61 74 74 65 6e /* Query flatten
aa00: 69 6e 67 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ing */.#define S
aa10: 51 4c 49 54 45 5f 43 6f 6c 75 6d 6e 43 61 63 68 QLITE_ColumnCach
aa20: 65 20 20 20 20 30 78 30 30 30 32 20 20 20 2f 2a e 0x0002 /*
aa30: 20 43 6f 6c 75 6d 6e 20 63 61 63 68 65 20 2a 2f Column cache */
aa40: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
aa50: 47 72 6f 75 70 42 79 4f 72 64 65 72 20 20 20 30 GroupByOrder 0
aa60: 78 30 30 30 34 20 20 20 2f 2a 20 47 52 4f 55 50 x0004 /* GROUP
aa70: 42 59 20 63 6f 76 65 72 20 6f 66 20 4f 52 44 45 BY cover of ORDE
aa80: 52 42 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 RBY */.#define S
aa90: 51 4c 49 54 45 5f 46 61 63 74 6f 72 4f 75 74 43 QLITE_FactorOutC
aaa0: 6f 6e 73 74 20 30 78 30 30 30 38 20 20 20 2f 2a onst 0x0008 /*
aab0: 20 43 6f 6e 73 74 61 6e 74 20 66 61 63 74 6f 72 Constant factor
aac0: 69 6e 67 20 2a 2f 0a 2f 2a 20 20 20 20 20 20 20 ing */./*
aad0: 20 20 20 20 20 20 20 20 20 6e 6f 74 20 75 73 65 not use
aae0: 64 20 20 20 20 30 78 30 30 31 30 20 20 20 2f 2f d 0x0010 //
aaf0: 20 57 61 73 3a 20 53 51 4c 49 54 45 5f 49 64 78 Was: SQLITE_Idx
ab00: 52 65 61 6c 41 73 49 6e 74 20 2a 2f 0a 23 64 65 RealAsInt */.#de
ab10: 66 69 6e 65 20 53 51 4c 49 54 45 5f 44 69 73 74 fine SQLITE_Dist
ab20: 69 6e 63 74 4f 70 74 20 20 20 20 30 78 30 30 32 inctOpt 0x002
ab30: 30 20 20 20 2f 2a 20 44 49 53 54 49 4e 43 54 20 0 /* DISTINCT
ab40: 75 73 69 6e 67 20 69 6e 64 65 78 65 73 20 2a 2f using indexes */
ab50: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ab60: 43 6f 76 65 72 49 64 78 53 63 61 6e 20 20 20 30 CoverIdxScan 0
ab70: 78 30 30 34 30 20 20 20 2f 2a 20 43 6f 76 65 72 x0040 /* Cover
ab80: 69 6e 67 20 69 6e 64 65 78 20 73 63 61 6e 73 20 ing index scans
ab90: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
aba0: 45 5f 4f 72 64 65 72 42 79 49 64 78 4a 6f 69 6e E_OrderByIdxJoin
abb0: 20 30 78 30 30 38 30 20 20 20 2f 2a 20 4f 52 44 0x0080 /* ORD
abc0: 45 52 20 42 59 20 6f 66 20 6a 6f 69 6e 73 20 76 ER BY of joins v
abd0: 69 61 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 ia index */.#def
abe0: 69 6e 65 20 53 51 4c 49 54 45 5f 53 75 62 71 43 ine SQLITE_SubqC
abf0: 6f 72 6f 75 74 69 6e 65 20 20 30 78 30 31 30 30 oroutine 0x0100
ac00: 20 20 20 2f 2a 20 45 76 61 6c 75 61 74 65 20 73 /* Evaluate s
ac10: 75 62 71 75 65 72 69 65 73 20 61 73 20 63 6f 72 ubqueries as cor
ac20: 6f 75 74 69 6e 65 73 20 2a 2f 0a 23 64 65 66 69 outines */.#defi
ac30: 6e 65 20 53 51 4c 49 54 45 5f 54 72 61 6e 73 69 ne SQLITE_Transi
ac40: 74 69 76 65 20 20 20 20 20 30 78 30 32 30 30 20 tive 0x0200
ac50: 20 20 2f 2a 20 54 72 61 6e 73 69 74 69 76 65 20 /* Transitive
ac60: 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 23 constraints */.#
ac70: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4f 6d define SQLITE_Om
ac80: 69 74 4e 6f 6f 70 4a 6f 69 6e 20 20 20 30 78 30 itNoopJoin 0x0
ac90: 34 30 30 20 20 20 2f 2a 20 4f 6d 69 74 20 75 6e 400 /* Omit un
aca0: 75 73 65 64 20 74 61 62 6c 65 73 20 69 6e 20 6a used tables in j
acb0: 6f 69 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 oins */.#define
acc0: 53 51 4c 49 54 45 5f 53 74 61 74 33 20 20 20 20 SQLITE_Stat3
acd0: 20 20 20 20 20 20 30 78 30 38 30 30 20 20 20 2f 0x0800 /
ace0: 2a 20 55 73 65 20 74 68 65 20 53 51 4c 49 54 45 * Use the SQLITE
acf0: 5f 53 54 41 54 33 20 74 61 62 6c 65 20 2a 2f 0a _STAT3 table */.
ad00: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
ad10: 64 6a 75 73 74 4f 75 74 45 73 74 20 20 20 30 78 djustOutEst 0x
ad20: 31 30 30 30 20 20 20 2f 2a 20 41 64 6a 75 73 74 1000 /* Adjust
ad30: 20 6f 75 74 70 75 74 20 65 73 74 69 6d 61 74 65 output estimate
ad40: 73 20 75 73 69 6e 67 20 57 48 45 52 45 20 2a 2f s using WHERE */
ad50: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
ad60: 41 6c 6c 4f 70 74 73 20 20 20 20 20 20 20 20 30 AllOpts 0
ad70: 78 66 66 66 66 20 20 20 2f 2a 20 41 6c 6c 20 6f xffff /* All o
ad80: 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 2a 2f 0a ptimizations */.
ad90: 0a 2f 2a 0a 2a 2a 20 4d 61 63 72 6f 73 20 66 6f ./*.** Macros fo
ada0: 72 20 74 65 73 74 69 6e 67 20 77 68 65 74 68 65 r testing whethe
adb0: 72 20 6f 72 20 6e 6f 74 20 6f 70 74 69 6d 69 7a r or not optimiz
adc0: 61 74 69 6f 6e 73 20 61 72 65 20 65 6e 61 62 6c ations are enabl
add0: 65 64 20 6f 72 20 64 69 73 61 62 6c 65 64 2e 0a ed or disabled..
ade0: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
adf0: 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 E_OMIT_BUILTIN_T
ae00: 45 53 54 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 EST.#define Opti
ae10: 6d 69 7a 61 74 69 6f 6e 44 69 73 61 62 6c 65 64 mizationDisabled
ae20: 28 64 62 2c 20 6d 61 73 6b 29 20 20 28 28 28 64 (db, mask) (((d
ae30: 62 29 2d 3e 64 62 4f 70 74 46 6c 61 67 73 26 28 b)->dbOptFlags&(
ae40: 6d 61 73 6b 29 29 21 3d 30 29 0a 23 64 65 66 69 mask))!=0).#defi
ae50: 6e 65 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 45 ne OptimizationE
ae60: 6e 61 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 nabled(db, mask)
ae70: 20 20 20 28 28 28 64 62 29 2d 3e 64 62 4f 70 74 (((db)->dbOpt
ae80: 46 6c 61 67 73 26 28 6d 61 73 6b 29 29 3d 3d 30 Flags&(mask))==0
ae90: 29 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 ).#else.#define
aea0: 4f 70 74 69 6d 69 7a 61 74 69 6f 6e 44 69 73 61 OptimizationDisa
aeb0: 62 6c 65 64 28 64 62 2c 20 6d 61 73 6b 29 20 20 bled(db, mask)
aec0: 30 0a 23 64 65 66 69 6e 65 20 4f 70 74 69 6d 69 0.#define Optimi
aed0: 7a 61 74 69 6f 6e 45 6e 61 62 6c 65 64 28 64 62 zationEnabled(db
aee0: 2c 20 6d 61 73 6b 29 20 20 20 31 0a 23 65 6e 64 , mask) 1.#end
aef0: 69 66 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e if../*.** Return
af00: 20 74 72 75 65 20 69 66 20 69 74 20 4f 4b 20 74 true if it OK t
af10: 6f 20 66 61 63 74 6f 72 20 63 6f 6e 73 74 61 6e o factor constan
af20: 74 20 65 78 70 72 65 73 73 69 6f 6e 73 20 69 6e t expressions in
af30: 74 6f 20 74 68 65 20 69 6e 69 74 69 61 6c 69 7a to the initializ
af40: 61 74 69 6f 6e 0a 2a 2a 20 63 6f 64 65 2e 20 54 ation.** code. T
af50: 68 65 20 61 72 67 75 6d 65 6e 74 20 69 73 20 61 he argument is a
af60: 20 50 61 72 73 65 20 6f 62 6a 65 63 74 20 66 6f Parse object fo
af70: 72 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 r the code gener
af80: 61 74 6f 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ator..*/.#define
af90: 20 43 6f 6e 73 74 46 61 63 74 6f 72 4f 6b 28 50 ConstFactorOk(P
afa0: 29 20 28 28 50 29 2d 3e 6f 6b 43 6f 6e 73 74 46 ) ((P)->okConstF
afb0: 61 63 74 6f 72 29 0a 0a 2f 2a 0a 2a 2a 20 50 6f actor)../*.** Po
afc0: 73 73 69 62 6c 65 20 76 61 6c 75 65 73 20 66 6f ssible values fo
afd0: 72 20 74 68 65 20 73 71 6c 69 74 65 2e 6d 61 67 r the sqlite.mag
afe0: 69 63 20 66 69 65 6c 64 2e 0a 2a 2a 20 54 68 65 ic field..** The
aff0: 20 6e 75 6d 62 65 72 73 20 61 72 65 20 6f 62 74 numbers are obt
b000: 61 69 6e 65 64 20 61 74 20 72 61 6e 64 6f 6d 20 ained at random
b010: 61 6e 64 20 68 61 76 65 20 6e 6f 20 73 70 65 63 and have no spec
b020: 69 61 6c 20 6d 65 61 6e 69 6e 67 2c 20 6f 74 68 ial meaning, oth
b030: 65 72 0a 2a 2a 20 74 68 61 6e 20 62 65 69 6e 67 er.** than being
b040: 20 64 69 73 74 69 6e 63 74 20 66 72 6f 6d 20 6f distinct from o
b050: 6e 65 20 61 6e 6f 74 68 65 72 2e 0a 2a 2f 0a 23 ne another..*/.#
b060: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 define SQLITE_MA
b070: 47 49 43 5f 4f 50 45 4e 20 20 20 20 20 30 78 61 GIC_OPEN 0xa
b080: 30 32 39 61 36 39 37 20 20 2f 2a 20 44 61 74 61 029a697 /* Data
b090: 62 61 73 65 20 69 73 20 6f 70 65 6e 20 2a 2f 0a base is open */.
b0a0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4d #define SQLITE_M
b0b0: 41 47 49 43 5f 43 4c 4f 53 45 44 20 20 20 30 78 AGIC_CLOSED 0x
b0c0: 39 66 33 63 32 64 33 33 20 20 2f 2a 20 44 61 74 9f3c2d33 /* Dat
b0d0: 61 62 61 73 65 20 69 73 20 63 6c 6f 73 65 64 20 abase is closed
b0e0: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
b0f0: 45 5f 4d 41 47 49 43 5f 53 49 43 4b 20 20 20 20 E_MAGIC_SICK
b100: 20 30 78 34 62 37 37 31 32 39 30 20 20 2f 2a 20 0x4b771290 /*
b110: 45 72 72 6f 72 20 61 6e 64 20 61 77 61 69 74 69 Error and awaiti
b120: 6e 67 20 63 6c 6f 73 65 20 2a 2f 0a 23 64 65 66 ng close */.#def
b130: 69 6e 65 20 53 51 4c 49 54 45 5f 4d 41 47 49 43 ine SQLITE_MAGIC
b140: 5f 42 55 53 59 20 20 20 20 20 30 78 66 30 33 62 _BUSY 0xf03b
b150: 37 39 30 36 20 20 2f 2a 20 44 61 74 61 62 61 73 7906 /* Databas
b160: 65 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 20 75 e currently in u
b170: 73 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 se */.#define SQ
b180: 4c 49 54 45 5f 4d 41 47 49 43 5f 45 52 52 4f 52 LITE_MAGIC_ERROR
b190: 20 20 20 20 30 78 62 35 33 35 37 39 33 30 20 20 0xb5357930
b1a0: 2f 2a 20 41 6e 20 53 51 4c 49 54 45 5f 4d 49 53 /* An SQLITE_MIS
b1b0: 55 53 45 20 65 72 72 6f 72 20 6f 63 63 75 72 72 USE error occurr
b1c0: 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 ed */.#define SQ
b1d0: 4c 49 54 45 5f 4d 41 47 49 43 5f 5a 4f 4d 42 49 LITE_MAGIC_ZOMBI
b1e0: 45 20 20 20 30 78 36 34 63 66 66 63 37 66 20 20 E 0x64cffc7f
b1f0: 2f 2a 20 43 6c 6f 73 65 20 77 69 74 68 20 6c 61 /* Close with la
b200: 73 74 20 73 74 61 74 65 6d 65 6e 74 20 63 6c 6f st statement clo
b210: 73 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 45 61 63 se */../*.** Eac
b220: 68 20 53 51 4c 20 66 75 6e 63 74 69 6f 6e 20 69 h SQL function i
b230: 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 6e 20 s defined by an
b240: 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 20 instance of the
b250: 66 6f 6c 6c 6f 77 69 6e 67 0a 2a 2a 20 73 74 72 following.** str
b260: 75 63 74 75 72 65 2e 20 20 41 20 70 6f 69 6e 74 ucture. A point
b270: 65 72 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 er to this struc
b280: 74 75 72 65 20 69 73 20 73 74 6f 72 65 64 20 69 ture is stored i
b290: 6e 20 74 68 65 20 73 71 6c 69 74 65 2e 61 46 75 n the sqlite.aFu
b2a0: 6e 63 0a 2a 2a 20 68 61 73 68 20 74 61 62 6c 65 nc.** hash table
b2b0: 2e 20 20 57 68 65 6e 20 6d 75 6c 74 69 70 6c 65 . When multiple
b2c0: 20 66 75 6e 63 74 69 6f 6e 73 20 68 61 76 65 20 functions have
b2d0: 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 2c 20 74 the same name, t
b2e0: 68 65 20 68 61 73 68 20 74 61 62 6c 65 0a 2a 2a he hash table.**
b2f0: 20 70 6f 69 6e 74 73 20 74 6f 20 61 20 6c 69 6e points to a lin
b300: 6b 65 64 20 6c 69 73 74 20 6f 66 20 74 68 65 73 ked list of thes
b310: 65 20 73 74 72 75 63 74 75 72 65 73 2e 0a 2a 2f e structures..*/
b320: 0a 73 74 72 75 63 74 20 46 75 6e 63 44 65 66 20 .struct FuncDef
b330: 7b 0a 20 20 69 31 36 20 6e 41 72 67 3b 20 20 20 {. i16 nArg;
b340: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
b350: 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 2e er of arguments.
b360: 20 20 2d 31 20 6d 65 61 6e 73 20 75 6e 6c 69 6d -1 means unlim
b370: 69 74 65 64 20 2a 2f 0a 20 20 75 31 36 20 66 75 ited */. u16 fu
b380: 6e 63 46 6c 61 67 73 3b 20 20 20 20 20 20 20 2f ncFlags; /
b390: 2a 20 53 6f 6d 65 20 63 6f 6d 62 69 6e 61 74 69 * Some combinati
b3a0: 6f 6e 20 6f 66 20 53 51 4c 49 54 45 5f 46 55 4e on of SQLITE_FUN
b3b0: 43 5f 2a 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 C_* */. void *p
b3c0: 55 73 65 72 44 61 74 61 3b 20 20 20 20 20 2f 2a UserData; /*
b3d0: 20 55 73 65 72 20 64 61 74 61 20 70 61 72 61 6d User data param
b3e0: 65 74 65 72 20 2a 2f 0a 20 20 46 75 6e 63 44 65 eter */. FuncDe
b3f0: 66 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 2f f *pNext; /
b400: 2a 20 4e 65 78 74 20 66 75 6e 63 74 69 6f 6e 20 * Next function
b410: 77 69 74 68 20 73 61 6d 65 20 6e 61 6d 65 20 2a with same name *
b420: 2f 0a 20 20 76 6f 69 64 20 28 2a 78 46 75 6e 63 /. void (*xFunc
b430: 29 28 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 )(sqlite3_contex
b440: 74 2a 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 t*,int,sqlite3_v
b450: 61 6c 75 65 2a 2a 29 3b 20 2f 2a 20 52 65 67 75 alue**); /* Regu
b460: 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a lar function */.
b470: 20 20 76 6f 69 64 20 28 2a 78 53 74 65 70 29 28 void (*xStep)(
b480: 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
b490: 2c 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c ,int,sqlite3_val
b4a0: 75 65 2a 2a 29 3b 20 2f 2a 20 41 67 67 72 65 67 ue**); /* Aggreg
b4b0: 61 74 65 20 73 74 65 70 20 2a 2f 0a 20 20 76 6f ate step */. vo
b4c0: 69 64 20 28 2a 78 46 69 6e 61 6c 69 7a 65 29 28 id (*xFinalize)(
b4d0: 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
b4e0: 29 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 );
b4f0: 20 20 2f 2a 20 41 67 67 72 65 67 61 74 65 20 66 /* Aggregate f
b500: 69 6e 61 6c 69 7a 65 72 20 2a 2f 0a 20 20 63 68 inalizer */. ch
b510: 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 ar *zName;
b520: 20 20 20 2f 2a 20 53 51 4c 20 6e 61 6d 65 20 6f /* SQL name o
b530: 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 2e 20 f the function.
b540: 2a 2f 0a 20 20 46 75 6e 63 44 65 66 20 2a 70 48 */. FuncDef *pH
b550: 61 73 68 3b 20 20 20 20 20 20 2f 2a 20 4e 65 78 ash; /* Nex
b560: 74 20 77 69 74 68 20 61 20 64 69 66 66 65 72 65 t with a differe
b570: 6e 74 20 6e 61 6d 65 20 62 75 74 20 74 68 65 20 nt name but the
b580: 73 61 6d 65 20 68 61 73 68 20 2a 2f 0a 20 20 46 same hash */. F
b590: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 20 2a 70 uncDestructor *p
b5a0: 44 65 73 74 72 75 63 74 6f 72 3b 20 20 20 2f 2a Destructor; /*
b5b0: 20 52 65 66 65 72 65 6e 63 65 20 63 6f 75 6e 74 Reference count
b5c0: 65 64 20 64 65 73 74 72 75 63 74 6f 72 20 66 75 ed destructor fu
b5d0: 6e 63 74 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a nction */.};../*
b5e0: 0a 2a 2a 20 54 68 69 73 20 73 74 72 75 63 74 75 .** This structu
b5f0: 72 65 20 65 6e 63 61 70 73 75 6c 61 74 65 73 20 re encapsulates
b600: 61 20 75 73 65 72 2d 66 75 6e 63 74 69 6f 6e 20 a user-function
b610: 64 65 73 74 72 75 63 74 6f 72 20 63 61 6c 6c 62 destructor callb
b620: 61 63 6b 20 28 61 73 0a 2a 2a 20 63 6f 6e 66 69 ack (as.** confi
b630: 67 75 72 65 64 20 75 73 69 6e 67 20 63 72 65 61 gured using crea
b640: 74 65 5f 66 75 6e 63 74 69 6f 6e 5f 76 32 28 29 te_function_v2()
b650: 29 20 61 6e 64 20 61 20 72 65 66 65 72 65 6e 63 ) and a referenc
b660: 65 20 63 6f 75 6e 74 65 72 2e 20 57 68 65 6e 0a e counter. When.
b670: 2a 2a 20 63 72 65 61 74 65 5f 66 75 6e 63 74 69 ** create_functi
b680: 6f 6e 5f 76 32 28 29 20 69 73 20 63 61 6c 6c 65 on_v2() is calle
b690: 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 66 75 d to create a fu
b6a0: 6e 63 74 69 6f 6e 20 77 69 74 68 20 61 20 64 65 nction with a de
b6b0: 73 74 72 75 63 74 6f 72 2c 0a 2a 2a 20 61 20 73 structor,.** a s
b6c0: 69 6e 67 6c 65 20 6f 62 6a 65 63 74 20 6f 66 20 ingle object of
b6d0: 74 68 69 73 20 74 79 70 65 20 69 73 20 61 6c 6c this type is all
b6e0: 6f 63 61 74 65 64 2e 20 46 75 6e 63 44 65 73 74 ocated. FuncDest
b6f0: 72 75 63 74 6f 72 2e 6e 52 65 66 20 69 73 20 73 ructor.nRef is s
b700: 65 74 20 74 6f 20 0a 2a 2a 20 74 68 65 20 6e 75 et to .** the nu
b710: 6d 62 65 72 20 6f 66 20 46 75 6e 63 44 65 66 20 mber of FuncDef
b720: 6f 62 6a 65 63 74 73 20 63 72 65 61 74 65 64 20 objects created
b730: 28 65 69 74 68 65 72 20 31 20 6f 72 20 33 2c 20 (either 1 or 3,
b740: 64 65 70 65 6e 64 69 6e 67 20 6f 6e 20 77 68 65 depending on whe
b750: 74 68 65 72 0a 2a 2a 20 6f 72 20 6e 6f 74 20 74 ther.** or not t
b760: 68 65 20 73 70 65 63 69 66 69 65 64 20 65 6e 63 he specified enc
b770: 6f 64 69 6e 67 20 69 73 20 53 51 4c 49 54 45 5f oding is SQLITE_
b780: 41 4e 59 29 2e 20 54 68 65 20 46 75 6e 63 44 65 ANY). The FuncDe
b790: 66 2e 70 44 65 73 74 72 75 63 74 6f 72 0a 2a 2a f.pDestructor.**
b7a0: 20 6d 65 6d 62 65 72 20 6f 66 20 65 61 63 68 20 member of each
b7b0: 6f 66 20 74 68 65 20 6e 65 77 20 46 75 6e 63 44 of the new FuncD
b7c0: 65 66 20 6f 62 6a 65 63 74 73 20 69 73 20 73 65 ef objects is se
b7d0: 74 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 74 68 t to point to th
b7e0: 65 20 61 6c 6c 6f 63 61 74 65 64 0a 2a 2a 20 46 e allocated.** F
b7f0: 75 6e 63 44 65 73 74 72 75 63 74 6f 72 2e 0a 2a uncDestructor..*
b800: 2a 0a 2a 2a 20 54 68 65 72 65 61 66 74 65 72 2c *.** Thereafter,
b810: 20 77 68 65 6e 20 6f 6e 65 20 6f 66 20 74 68 65 when one of the
b820: 20 46 75 6e 63 44 65 66 20 6f 62 6a 65 63 74 73 FuncDef objects
b830: 20 69 73 20 64 65 6c 65 74 65 64 2c 20 74 68 65 is deleted, the
b840: 20 72 65 66 65 72 65 6e 63 65 0a 2a 2a 20 63 6f reference.** co
b850: 75 6e 74 20 6f 6e 20 74 68 69 73 20 6f 62 6a 65 unt on this obje
b860: 63 74 20 69 73 20 64 65 63 72 65 6d 65 6e 74 65 ct is decremente
b870: 64 2e 20 57 68 65 6e 20 69 74 20 72 65 61 63 68 d. When it reach
b880: 65 73 20 30 2c 20 74 68 65 20 64 65 73 74 72 75 es 0, the destru
b890: 63 74 6f 72 0a 2a 2a 20 69 73 20 69 6e 76 6f 6b ctor.** is invok
b8a0: 65 64 20 61 6e 64 20 74 68 65 20 46 75 6e 63 44 ed and the FuncD
b8b0: 65 73 74 72 75 63 74 6f 72 20 73 74 72 75 63 74 estructor struct
b8c0: 75 72 65 20 66 72 65 65 64 2e 0a 2a 2f 0a 73 74 ure freed..*/.st
b8d0: 72 75 63 74 20 46 75 6e 63 44 65 73 74 72 75 63 ruct FuncDestruc
b8e0: 74 6f 72 20 7b 0a 20 20 69 6e 74 20 6e 52 65 66 tor {. int nRef
b8f0: 3b 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 73 74 ;. void (*xDest
b900: 72 6f 79 29 28 76 6f 69 64 20 2a 29 3b 0a 20 20 roy)(void *);.
b910: 76 6f 69 64 20 2a 70 55 73 65 72 44 61 74 61 3b void *pUserData;
b920: 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 50 6f 73 73 69 .};../*.** Possi
b930: 62 6c 65 20 76 61 6c 75 65 73 20 66 6f 72 20 46 ble values for F
b940: 75 6e 63 44 65 66 2e 66 6c 61 67 73 2e 20 20 4e uncDef.flags. N
b950: 6f 74 65 20 74 68 61 74 20 74 68 65 20 5f 4c 45 ote that the _LE
b960: 4e 47 54 48 20 61 6e 64 20 5f 54 59 50 45 4f 46 NGTH and _TYPEOF
b970: 0a 2a 2a 20 76 61 6c 75 65 73 20 6d 75 73 74 20 .** values must
b980: 63 6f 72 72 65 73 70 6f 6e 64 20 74 6f 20 4f 50 correspond to OP
b990: 46 4c 41 47 5f 4c 45 4e 47 54 48 41 52 47 20 61 FLAG_LENGTHARG a
b9a0: 6e 64 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 nd OPFLAG_TYPEOF
b9b0: 41 52 47 2e 20 20 54 68 65 72 65 0a 2a 2a 20 61 ARG. There.** a
b9c0: 72 65 20 61 73 73 65 72 74 28 29 20 73 74 61 74 re assert() stat
b9d0: 65 6d 65 6e 74 73 20 69 6e 20 74 68 65 20 63 6f ements in the co
b9e0: 64 65 20 74 6f 20 76 65 72 69 66 79 20 74 68 69 de to verify thi
b9f0: 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 s..*/.#define SQ
ba00: 4c 49 54 45 5f 46 55 4e 43 5f 45 4e 43 4d 41 53 LITE_FUNC_ENCMAS
ba10: 4b 20 20 30 78 30 30 33 20 2f 2a 20 53 51 4c 49 K 0x003 /* SQLI
ba20: 54 45 5f 55 54 46 38 2c 20 53 51 4c 49 54 45 5f TE_UTF8, SQLITE_
ba30: 55 54 46 31 36 42 45 20 6f 72 20 55 54 46 31 36 UTF16BE or UTF16
ba40: 4c 45 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 LE */.#define SQ
ba50: 4c 49 54 45 5f 46 55 4e 43 5f 4c 49 4b 45 20 20 LITE_FUNC_LIKE
ba60: 20 20 20 30 78 30 30 34 20 2f 2a 20 43 61 6e 64 0x004 /* Cand
ba70: 69 64 61 74 65 20 66 6f 72 20 74 68 65 20 4c 49 idate for the LI
ba80: 4b 45 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 KE optimization
ba90: 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
baa0: 45 5f 46 55 4e 43 5f 43 41 53 45 20 20 20 20 20 E_FUNC_CASE
bab0: 30 78 30 30 38 20 2f 2a 20 43 61 73 65 2d 73 65 0x008 /* Case-se
bac0: 6e 73 69 74 69 76 65 20 4c 49 4b 45 2d 74 79 70 nsitive LIKE-typ
bad0: 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 e function */.#d
bae0: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e efine SQLITE_FUN
baf0: 43 5f 45 50 48 45 4d 20 20 20 20 30 78 30 31 30 C_EPHEM 0x010
bb00: 20 2f 2a 20 45 70 68 65 6d 65 72 61 6c 2e 20 20 /* Ephemeral.
bb10: 44 65 6c 65 74 65 20 77 69 74 68 20 56 44 42 45 Delete with VDBE
bb20: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 */.#define SQLI
bb30: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
bb40: 20 30 78 30 32 30 20 2f 2a 20 73 71 6c 69 74 65 0x020 /* sqlite
bb50: 33 47 65 74 46 75 6e 63 43 6f 6c 6c 53 65 71 28 3GetFuncCollSeq(
bb60: 29 20 6d 69 67 68 74 20 62 65 20 63 61 6c 6c 65 ) might be calle
bb70: 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c d */.#define SQL
bb80: 49 54 45 5f 46 55 4e 43 5f 4c 45 4e 47 54 48 20 ITE_FUNC_LENGTH
bb90: 20 20 30 78 30 34 30 20 2f 2a 20 42 75 69 6c 74 0x040 /* Built
bba0: 2d 69 6e 20 6c 65 6e 67 74 68 28 29 20 66 75 6e -in length() fun
bbb0: 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 ction */.#define
bbc0: 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 54 59 50 SQLITE_FUNC_TYP
bbd0: 45 4f 46 20 20 20 30 78 30 38 30 20 2f 2a 20 42 EOF 0x080 /* B
bbe0: 75 69 6c 74 2d 69 6e 20 74 79 70 65 6f 66 28 29 uilt-in typeof()
bbf0: 20 66 75 6e 63 74 69 6f 6e 20 2a 2f 0a 23 64 65 function */.#de
bc00: 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 fine SQLITE_FUNC
bc10: 5f 43 4f 55 4e 54 20 20 20 20 30 78 31 30 30 20 _COUNT 0x100
bc20: 2f 2a 20 42 75 69 6c 74 2d 69 6e 20 63 6f 75 6e /* Built-in coun
bc30: 74 28 2a 29 20 61 67 67 72 65 67 61 74 65 20 2a t(*) aggregate *
bc40: 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 /.#define SQLITE
bc50: 5f 46 55 4e 43 5f 43 4f 41 4c 45 53 43 45 20 30 _FUNC_COALESCE 0
bc60: 78 32 30 30 20 2f 2a 20 42 75 69 6c 74 2d 69 6e x200 /* Built-in
bc70: 20 63 6f 61 6c 65 73 63 65 28 29 20 6f 72 20 69 coalesce() or i
bc80: 66 6e 75 6c 6c 28 29 20 2a 2f 0a 23 64 65 66 69 fnull() */.#defi
bc90: 6e 65 20 53 51 4c 49 54 45 5f 46 55 4e 43 5f 55 ne SQLITE_FUNC_U
bca0: 4e 4c 49 4b 45 4c 59 20 30 78 34 30 30 20 2f 2a NLIKELY 0x400 /*
bcb0: 20 42 75 69 6c 74 2d 69 6e 20 75 6e 6c 69 6b 65 Built-in unlike
bcc0: 6c 79 28 29 20 66 75 6e 63 74 69 6f 6e 20 2a 2f ly() function */
bcd0: 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
bce0: 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 30 78 FUNC_CONSTANT 0x
bcf0: 38 30 30 20 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 800 /* Constant
bd00: 69 6e 70 75 74 73 20 67 69 76 65 20 61 20 63 6f inputs give a co
bd10: 6e 73 74 61 6e 74 20 6f 75 74 70 75 74 20 2a 2f nstant output */
bd20: 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c ../*.** The foll
bd30: 6f 77 69 6e 67 20 74 68 72 65 65 20 6d 61 63 72 owing three macr
bd40: 6f 73 2c 20 46 55 4e 43 54 49 4f 4e 28 29 2c 20 os, FUNCTION(),
bd50: 4c 49 4b 45 46 55 4e 43 28 29 20 61 6e 64 20 41 LIKEFUNC() and A
bd60: 47 47 52 45 47 41 54 45 28 29 20 61 72 65 0a 2a GGREGATE() are.*
bd70: 2a 20 75 73 65 64 20 74 6f 20 63 72 65 61 74 65 * used to create
bd80: 20 74 68 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 the initializer
bd90: 73 20 66 6f 72 20 74 68 65 20 46 75 6e 63 44 65 s for the FuncDe
bda0: 66 20 73 74 72 75 63 74 75 72 65 73 2e 0a 2a 2a f structures..**
bdb0: 0a 2a 2a 20 20 20 46 55 4e 43 54 49 4f 4e 28 7a .** FUNCTION(z
bdc0: 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 Name, nArg, iArg
bdd0: 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a 2a , bNC, xFunc).**
bde0: 20 20 20 20 20 55 73 65 64 20 74 6f 20 63 72 65 Used to cre
bdf0: 61 74 65 20 61 20 73 63 61 6c 61 72 20 66 75 6e ate a scalar fun
be00: 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 6f 6e ction definition
be10: 20 6f 66 20 61 20 66 75 6e 63 74 69 6f 6e 20 7a of a function z
be20: 4e 61 6d 65 20 0a 2a 2a 20 20 20 20 20 69 6d 70 Name .** imp
be30: 6c 65 6d 65 6e 74 65 64 20 62 79 20 43 20 66 75 lemented by C fu
be40: 6e 63 74 69 6f 6e 20 78 46 75 6e 63 20 74 68 61 nction xFunc tha
be50: 74 20 61 63 63 65 70 74 73 20 6e 41 72 67 20 61 t accepts nArg a
be60: 72 67 75 6d 65 6e 74 73 2e 20 54 68 65 0a 2a 2a rguments. The.**
be70: 20 20 20 20 20 76 61 6c 75 65 20 70 61 73 73 65 value passe
be80: 64 20 61 73 20 69 41 72 67 20 69 73 20 63 61 73 d as iArg is cas
be90: 74 20 74 6f 20 61 20 28 76 6f 69 64 2a 29 20 61 t to a (void*) a
bea0: 6e 64 20 6d 61 64 65 20 61 76 61 69 6c 61 62 6c nd made availabl
beb0: 65 0a 2a 2a 20 20 20 20 20 61 73 20 74 68 65 20 e.** as the
bec0: 75 73 65 72 2d 64 61 74 61 20 28 73 71 6c 69 74 user-data (sqlit
bed0: 65 33 5f 75 73 65 72 5f 64 61 74 61 28 29 29 20 e3_user_data())
bee0: 66 6f 72 20 74 68 65 20 66 75 6e 63 74 69 6f 6e for the function
bef0: 2e 20 49 66 20 0a 2a 2a 20 20 20 20 20 61 72 67 . If .** arg
bf00: 75 6d 65 6e 74 20 62 4e 43 20 69 73 20 74 72 75 ument bNC is tru
bf10: 65 2c 20 74 68 65 6e 20 74 68 65 20 53 51 4c 49 e, then the SQLI
bf20: 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f 4c 4c TE_FUNC_NEEDCOLL
bf30: 20 66 6c 61 67 20 69 73 20 73 65 74 2e 0a 2a 2a flag is set..**
bf40: 0a 2a 2a 20 20 20 56 46 55 4e 43 54 49 4f 4e 28 .** VFUNCTION(
bf50: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 zName, nArg, iAr
bf60: 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 0a 2a g, bNC, xFunc).*
bf70: 2a 20 20 20 20 20 4c 69 6b 65 20 46 55 4e 43 54 * Like FUNCT
bf80: 49 4f 4e 20 65 78 63 65 70 74 20 69 74 20 6f 6d ION except it om
bf90: 69 74 73 20 74 68 65 20 53 51 4c 49 54 45 5f 46 its the SQLITE_F
bfa0: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 20 66 6c 61 UNC_CONSTANT fla
bfb0: 67 2e 0a 2a 2a 0a 2a 2a 20 20 20 41 47 47 52 45 g..**.** AGGRE
bfc0: 47 41 54 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 GATE(zName, nArg
bfd0: 2c 20 69 41 72 67 2c 20 62 4e 43 2c 20 78 53 74 , iArg, bNC, xSt
bfe0: 65 70 2c 20 78 46 69 6e 61 6c 29 0a 2a 2a 20 20 ep, xFinal).**
bff0: 20 20 20 55 73 65 64 20 74 6f 20 63 72 65 61 74 Used to creat
c000: 65 20 61 6e 20 61 67 67 72 65 67 61 74 65 20 66 e an aggregate f
c010: 75 6e 63 74 69 6f 6e 20 64 65 66 69 6e 69 74 69 unction definiti
c020: 6f 6e 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 62 on implemented b
c030: 79 0a 2a 2a 20 20 20 20 20 74 68 65 20 43 20 66 y.** the C f
c040: 75 6e 63 74 69 6f 6e 73 20 78 53 74 65 70 20 61 unctions xStep a
c050: 6e 64 20 78 46 69 6e 61 6c 2e 20 54 68 65 20 66 nd xFinal. The f
c060: 69 72 73 74 20 66 6f 75 72 20 70 61 72 61 6d 65 irst four parame
c070: 74 65 72 73 0a 2a 2a 20 20 20 20 20 61 72 65 20 ters.** are
c080: 69 6e 74 65 72 70 72 65 74 65 64 20 69 6e 20 74 interpreted in t
c090: 68 65 20 73 61 6d 65 20 77 61 79 20 61 73 20 74 he same way as t
c0a0: 68 65 20 66 69 72 73 74 20 34 20 70 61 72 61 6d he first 4 param
c0b0: 65 74 65 72 73 20 74 6f 0a 2a 2a 20 20 20 20 20 eters to.**
c0c0: 46 55 4e 43 54 49 4f 4e 28 29 2e 0a 2a 2a 0a 2a FUNCTION()..**.*
c0d0: 2a 20 20 20 4c 49 4b 45 46 55 4e 43 28 7a 4e 61 * LIKEFUNC(zNa
c0e0: 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 67 2c 20 me, nArg, pArg,
c0f0: 66 6c 61 67 73 29 0a 2a 2a 20 20 20 20 20 55 73 flags).** Us
c100: 65 64 20 74 6f 20 63 72 65 61 74 65 20 61 20 73 ed to create a s
c110: 63 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 64 calar function d
c120: 65 66 69 6e 69 74 69 6f 6e 20 6f 66 20 61 20 66 efinition of a f
c130: 75 6e 63 74 69 6f 6e 20 7a 4e 61 6d 65 20 0a 2a unction zName .*
c140: 2a 20 20 20 20 20 74 68 61 74 20 61 63 63 65 70 * that accep
c150: 74 73 20 6e 41 72 67 20 61 72 67 75 6d 65 6e 74 ts nArg argument
c160: 73 20 61 6e 64 20 69 73 20 69 6d 70 6c 65 6d 65 s and is impleme
c170: 6e 74 65 64 20 62 79 20 61 20 63 61 6c 6c 20 74 nted by a call t
c180: 6f 20 43 20 0a 2a 2a 20 20 20 20 20 66 75 6e 63 o C .** func
c190: 74 69 6f 6e 20 6c 69 6b 65 46 75 6e 63 2e 20 41 tion likeFunc. A
c1a0: 72 67 75 6d 65 6e 74 20 70 41 72 67 20 69 73 20 rgument pArg is
c1b0: 63 61 73 74 20 74 6f 20 61 20 28 76 6f 69 64 20 cast to a (void
c1c0: 2a 29 20 61 6e 64 20 6d 61 64 65 0a 2a 2a 20 20 *) and made.**
c1d0: 20 20 20 61 76 61 69 6c 61 62 6c 65 20 61 73 20 available as
c1e0: 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 75 73 65 the function use
c1f0: 72 2d 64 61 74 61 20 28 73 71 6c 69 74 65 33 5f r-data (sqlite3_
c200: 75 73 65 72 5f 64 61 74 61 28 29 29 2e 20 54 68 user_data()). Th
c210: 65 0a 2a 2a 20 20 20 20 20 46 75 6e 63 44 65 66 e.** FuncDef
c220: 2e 66 6c 61 67 73 20 76 61 72 69 61 62 6c 65 20 .flags variable
c230: 69 73 20 73 65 74 20 74 6f 20 74 68 65 20 76 61 is set to the va
c240: 6c 75 65 20 70 61 73 73 65 64 20 61 73 20 74 68 lue passed as th
c250: 65 20 66 6c 61 67 73 0a 2a 2a 20 20 20 20 20 70 e flags.** p
c260: 61 72 61 6d 65 74 65 72 2e 0a 2a 2f 0a 23 64 65 arameter..*/.#de
c270: 66 69 6e 65 20 46 55 4e 43 54 49 4f 4e 28 7a 4e fine FUNCTION(zN
c280: 61 6d 65 2c 20 6e 41 72 67 2c 20 69 41 72 67 2c ame, nArg, iArg,
c290: 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c 0a 20 bNC, xFunc) \.
c2a0: 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 {nArg, SQLITE_F
c2b0: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c UNC_CONSTANT|SQL
c2c0: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
c2d0: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
c2e0: 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 LL), \. SQLITE
c2f0: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 _INT_TO_PTR(iArg
c300: 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 ), 0, xFunc, 0,
c310: 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0, #zName, 0, 0}
c320: 0a 23 64 65 66 69 6e 65 20 56 46 55 4e 43 54 49 .#define VFUNCTI
c330: 4f 4e 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 ON(zName, nArg,
c340: 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 iArg, bNC, xFunc
c350: 29 20 5c 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c ) \. {nArg, SQL
c360: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
c370: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
c380: 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 4c 49 54 45 LL), \. SQLITE
c390: 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 69 41 72 67 _INT_TO_PTR(iArg
c3a0: 29 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 ), 0, xFunc, 0,
c3b0: 30 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0, #zName, 0, 0}
c3c0: 0a 23 64 65 66 69 6e 65 20 46 55 4e 43 54 49 4f .#define FUNCTIO
c3d0: 4e 32 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 N2(zName, nArg,
c3e0: 69 41 72 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 iArg, bNC, xFunc
c3f0: 2c 20 65 78 74 72 61 46 6c 61 67 73 29 20 5c 0a , extraFlags) \.
c400: 20 20 7b 6e 41 72 67 2c 53 51 4c 49 54 45 5f 46 {nArg,SQLITE_F
c410: 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c UNC_CONSTANT|SQL
c420: 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a 53 51 ITE_UTF8|(bNC*SQ
c430: 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 43 4f LITE_FUNC_NEEDCO
c440: 4c 4c 29 7c 65 78 74 72 61 46 6c 61 67 73 2c 5c LL)|extraFlags,\
c450: 0a 20 20 20 53 51 4c 49 54 45 5f 49 4e 54 5f 54 . SQLITE_INT_T
c460: 4f 5f 50 54 52 28 69 41 72 67 29 2c 20 30 2c 20 O_PTR(iArg), 0,
c470: 78 46 75 6e 63 2c 20 30 2c 20 30 2c 20 23 7a 4e xFunc, 0, 0, #zN
c480: 61 6d 65 2c 20 30 2c 20 30 7d 0a 23 64 65 66 69 ame, 0, 0}.#defi
c490: 6e 65 20 53 54 52 5f 46 55 4e 43 54 49 4f 4e 28 ne STR_FUNCTION(
c4a0: 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 70 41 72 zName, nArg, pAr
c4b0: 67 2c 20 62 4e 43 2c 20 78 46 75 6e 63 29 20 5c g, bNC, xFunc) \
c4c0: 0a 20 20 7b 6e 41 72 67 2c 20 53 51 4c 49 54 45 . {nArg, SQLITE
c4d0: 5f 46 55 4e 43 5f 43 4f 4e 53 54 41 4e 54 7c 53 _FUNC_CONSTANT|S
c4e0: 51 4c 49 54 45 5f 55 54 46 38 7c 28 62 4e 43 2a QLITE_UTF8|(bNC*
c4f0: 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 45 44 SQLITE_FUNC_NEED
c500: 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 70 41 72 67 COLL), \. pArg
c510: 2c 20 30 2c 20 78 46 75 6e 63 2c 20 30 2c 20 30 , 0, xFunc, 0, 0
c520: 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a , #zName, 0, 0}.
c530: 23 64 65 66 69 6e 65 20 4c 49 4b 45 46 55 4e 43 #define LIKEFUNC
c540: 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 72 (zName, nArg, ar
c550: 67 2c 20 66 6c 61 67 73 29 20 5c 0a 20 20 7b 6e g, flags) \. {n
c560: 41 72 67 2c 20 53 51 4c 49 54 45 5f 46 55 4e 43 Arg, SQLITE_FUNC
c570: 5f 43 4f 4e 53 54 41 4e 54 7c 53 51 4c 49 54 45 _CONSTANT|SQLITE
c580: 5f 55 54 46 38 7c 66 6c 61 67 73 2c 20 5c 0a 20 _UTF8|flags, \.
c590: 20 20 28 76 6f 69 64 20 2a 29 61 72 67 2c 20 30 (void *)arg, 0
c5a0: 2c 20 6c 69 6b 65 46 75 6e 63 2c 20 30 2c 20 30 , likeFunc, 0, 0
c5b0: 2c 20 23 7a 4e 61 6d 65 2c 20 30 2c 20 30 7d 0a , #zName, 0, 0}.
c5c0: 23 64 65 66 69 6e 65 20 41 47 47 52 45 47 41 54 #define AGGREGAT
c5d0: 45 28 7a 4e 61 6d 65 2c 20 6e 41 72 67 2c 20 61 E(zName, nArg, a
c5e0: 72 67 2c 20 6e 63 2c 20 78 53 74 65 70 2c 20 78 rg, nc, xStep, x
c5f0: 46 69 6e 61 6c 29 20 5c 0a 20 20 7b 6e 41 72 67 Final) \. {nArg
c600: 2c 20 53 51 4c 49 54 45 5f 55 54 46 38 7c 28 6e , SQLITE_UTF8|(n
c610: 63 2a 53 51 4c 49 54 45 5f 46 55 4e 43 5f 4e 45 c*SQLITE_FUNC_NE
c620: 45 44 43 4f 4c 4c 29 2c 20 5c 0a 20 20 20 53 51 EDCOLL), \. SQ
c630: 4c 49 54 45 5f 49 4e 54 5f 54 4f 5f 50 54 52 28 LITE_INT_TO_PTR(
c640: 61 72 67 29 2c 20 30 2c 20 30 2c 20 78 53 74 65 arg), 0, 0, xSte
c650: 70 2c 78 46 69 6e 61 6c 2c 23 7a 4e 61 6d 65 2c p,xFinal,#zName,
c660: 30 2c 30 7d 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 20 0,0}../*.** All
c670: 63 75 72 72 65 6e 74 20 73 61 76 65 70 6f 69 6e current savepoin
c680: 74 73 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e ts are stored in
c690: 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 73 a linked list s
c6a0: 74 61 72 74 69 6e 67 20 61 74 0a 2a 2a 20 73 71 tarting at.** sq
c6b0: 6c 69 74 65 33 2e 70 53 61 76 65 70 6f 69 6e 74 lite3.pSavepoint
c6c0: 2e 20 54 68 65 20 66 69 72 73 74 20 65 6c 65 6d . The first elem
c6d0: 65 6e 74 20 69 6e 20 74 68 65 20 6c 69 73 74 20 ent in the list
c6e0: 69 73 20 74 68 65 20 6d 6f 73 74 20 72 65 63 65 is the most rece
c6f0: 6e 74 6c 79 0a 2a 2a 20 6f 70 65 6e 65 64 20 73 ntly.** opened s
c700: 61 76 65 70 6f 69 6e 74 2e 20 53 61 76 65 70 6f avepoint. Savepo
c710: 69 6e 74 73 20 61 72 65 20 61 64 64 65 64 20 74 ints are added t
c720: 6f 20 74 68 65 20 6c 69 73 74 20 62 79 20 74 68 o the list by th
c730: 65 20 76 64 62 65 0a 2a 2a 20 4f 50 5f 53 61 76 e vdbe.** OP_Sav
c740: 65 70 6f 69 6e 74 20 69 6e 73 74 72 75 63 74 69 epoint instructi
c750: 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 61 on..*/.struct Sa
c760: 76 65 70 6f 69 6e 74 20 7b 0a 20 20 63 68 61 72 vepoint {. char
c770: 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 *zName;
c780: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c790: 2f 2a 20 53 61 76 65 70 6f 69 6e 74 20 6e 61 6d /* Savepoint nam
c7a0: 65 20 28 6e 75 6c 2d 74 65 72 6d 69 6e 61 74 65 e (nul-terminate
c7b0: 64 29 20 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 d) */. i64 nDef
c7c0: 65 72 72 65 64 43 6f 6e 73 3b 20 20 20 20 20 20 erredCons;
c7d0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
c7e0: 75 6d 62 65 72 20 6f 66 20 64 65 66 65 72 72 65 umber of deferre
c7f0: 64 20 66 6b 20 76 69 6f 6c 61 74 69 6f 6e 73 20 d fk violations
c800: 2a 2f 0a 20 20 69 36 34 20 6e 44 65 66 65 72 72 */. i64 nDeferr
c810: 65 64 49 6d 6d 43 6f 6e 73 3b 20 20 20 20 20 20 edImmCons;
c820: 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
c830: 65 72 20 6f 66 20 64 65 66 65 72 72 65 64 20 69 er of deferred i
c840: 6d 6d 20 66 6b 2e 20 2a 2f 0a 20 20 53 61 76 65 mm fk. */. Save
c850: 70 6f 69 6e 74 20 2a 70 4e 65 78 74 3b 20 20 20 point *pNext;
c860: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
c870: 2f 2a 20 50 61 72 65 6e 74 20 73 61 76 65 70 6f /* Parent savepo
c880: 69 6e 74 20 28 69 66 20 61 6e 79 29 20 2a 2f 0a int (if any) */.
c890: 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f };../*.** The fo
c8a0: 6c 6c 6f 77 69 6e 67 20 61 72 65 20 75 73 65 64 llowing are used
c8b0: 20 61 73 20 74 68 65 20 73 65 63 6f 6e 64 20 70 as the second p
c8c0: 61 72 61 6d 65 74 65 72 20 74 6f 20 73 71 6c 69 arameter to sqli
c8d0: 74 65 33 53 61 76 65 70 6f 69 6e 74 28 29 2c 0a te3Savepoint(),.
c8e0: 2a 2a 20 61 6e 64 20 61 73 20 74 68 65 20 50 31 ** and as the P1
c8f0: 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 74 68 65 argument to the
c900: 20 4f 50 5f 53 61 76 65 70 6f 69 6e 74 20 69 6e OP_Savepoint in
c910: 73 74 72 75 63 74 69 6f 6e 2e 0a 2a 2f 0a 23 64 struction..*/.#d
c920: 65 66 69 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f efine SAVEPOINT_
c930: 42 45 47 49 4e 20 20 20 20 20 20 30 0a 23 64 65 BEGIN 0.#de
c940: 66 69 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f 52 fine SAVEPOINT_R
c950: 45 4c 45 41 53 45 20 20 20 20 31 0a 23 64 65 66 ELEASE 1.#def
c960: 69 6e 65 20 53 41 56 45 50 4f 49 4e 54 5f 52 4f ine SAVEPOINT_RO
c970: 4c 4c 42 41 43 4b 20 20 20 32 0a 0a 0a 2f 2a 0a LLBACK 2.../*.
c980: 2a 2a 20 45 61 63 68 20 53 51 4c 69 74 65 20 6d ** Each SQLite m
c990: 6f 64 75 6c 65 20 28 76 69 72 74 75 61 6c 20 74 odule (virtual t
c9a0: 61 62 6c 65 20 64 65 66 69 6e 69 74 69 6f 6e 29 able definition)
c9b0: 20 69 73 20 64 65 66 69 6e 65 64 20 62 79 20 61 is defined by a
c9c0: 6e 0a 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 n.** instance of
c9d0: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
c9e0: 74 72 75 63 74 75 72 65 2c 20 73 74 6f 72 65 64 tructure, stored
c9f0: 20 69 6e 20 74 68 65 20 73 71 6c 69 74 65 33 2e in the sqlite3.
ca00: 61 4d 6f 64 75 6c 65 0a 2a 2a 20 68 61 73 68 20 aModule.** hash
ca10: 74 61 62 6c 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 table..*/.struct
ca20: 20 4d 6f 64 75 6c 65 20 7b 0a 20 20 63 6f 6e 73 Module {. cons
ca30: 74 20 73 71 6c 69 74 65 33 5f 6d 6f 64 75 6c 65 t sqlite3_module
ca40: 20 2a 70 4d 6f 64 75 6c 65 3b 20 20 20 20 20 20 *pModule;
ca50: 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 70 6f 69 /* Callback poi
ca60: 6e 74 65 72 73 20 2a 2f 0a 20 20 63 6f 6e 73 74 nters */. const
ca70: 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 char *zName;
ca80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
ca90: 2f 2a 20 4e 61 6d 65 20 70 61 73 73 65 64 20 74 /* Name passed t
caa0: 6f 20 63 72 65 61 74 65 5f 6d 6f 64 75 6c 65 28 o create_module(
cab0: 29 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 41 75 ) */. void *pAu
cac0: 78 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 x;
cad0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 70 /* p
cae0: 41 75 78 20 70 61 73 73 65 64 20 74 6f 20 63 72 Aux passed to cr
caf0: 65 61 74 65 5f 6d 6f 64 75 6c 65 28 29 20 2a 2f eate_module() */
cb00: 0a 20 20 76 6f 69 64 20 28 2a 78 44 65 73 74 72 . void (*xDestr
cb10: 6f 79 29 28 76 6f 69 64 20 2a 29 3b 20 20 20 20 oy)(void *);
cb20: 20 20 20 20 20 20 20 20 2f 2a 20 4d 6f 64 75 6c /* Modul
cb30: 65 20 64 65 73 74 72 75 63 74 6f 72 20 66 75 6e e destructor fun
cb40: 63 74 69 6f 6e 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a ction */.};../*.
cb50: 2a 2a 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 ** information a
cb60: 62 6f 75 74 20 65 61 63 68 20 63 6f 6c 75 6d 6e bout each column
cb70: 20 6f 66 20 61 6e 20 53 51 4c 20 74 61 62 6c 65 of an SQL table
cb80: 20 69 73 20 68 65 6c 64 20 69 6e 20 61 6e 20 69 is held in an i
cb90: 6e 73 74 61 6e 63 65 0a 2a 2a 20 6f 66 20 74 68 nstance.** of th
cba0: 69 73 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f is structure..*/
cbb0: 0a 73 74 72 75 63 74 20 43 6f 6c 75 6d 6e 20 7b .struct Column {
cbc0: 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
cbd0: 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 /* Name of t
cbe0: 68 69 73 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 his column */.
cbf0: 45 78 70 72 20 2a 70 44 66 6c 74 3b 20 20 20 20 Expr *pDflt;
cc00: 20 2f 2a 20 44 65 66 61 75 6c 74 20 76 61 6c 75 /* Default valu
cc10: 65 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e e of this column
cc20: 20 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 44 66 6c */. char *zDfl
cc30: 74 3b 20 20 20 20 20 2f 2a 20 4f 72 69 67 69 6e t; /* Origin
cc40: 61 6c 20 74 65 78 74 20 6f 66 20 74 68 65 20 64 al text of the d
cc50: 65 66 61 75 6c 74 20 76 61 6c 75 65 20 2a 2f 0a efault value */.
cc60: 20 20 63 68 61 72 20 2a 7a 54 79 70 65 3b 20 20 char *zType;
cc70: 20 20 20 2f 2a 20 44 61 74 61 20 74 79 70 65 20 /* Data type
cc80: 66 6f 72 20 74 68 69 73 20 63 6f 6c 75 6d 6e 20 for this column
cc90: 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 43 6f 6c 6c */. char *zColl
cca0: 3b 20 20 20 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 ; /* Collati
ccb0: 6e 67 20 73 65 71 75 65 6e 63 65 2e 20 20 49 66 ng sequence. If
ccc0: 20 4e 55 4c 4c 2c 20 75 73 65 20 74 68 65 20 64 NULL, use the d
ccd0: 65 66 61 75 6c 74 20 2a 2f 0a 20 20 75 38 20 6e efault */. u8 n
cce0: 6f 74 4e 75 6c 6c 3b 20 20 20 20 20 20 2f 2a 20 otNull; /*
ccf0: 41 6e 20 4f 45 5f 20 63 6f 64 65 20 66 6f 72 20 An OE_ code for
cd00: 68 61 6e 64 6c 69 6e 67 20 61 20 4e 4f 54 20 4e handling a NOT N
cd10: 55 4c 4c 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a ULL constraint *
cd20: 2f 0a 20 20 63 68 61 72 20 61 66 66 69 6e 69 74 /. char affinit
cd30: 79 3b 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 20 74 y; /* One of t
cd40: 68 65 20 53 51 4c 49 54 45 5f 41 46 46 5f 2e 2e he SQLITE_AFF_..
cd50: 2e 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 75 38 . values */. u8
cd60: 20 73 7a 45 73 74 3b 20 20 20 20 20 20 20 20 2f szEst; /
cd70: 2a 20 45 73 74 69 6d 61 74 65 64 20 73 69 7a 65 * Estimated size
cd80: 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e of this column.
cd90: 20 20 49 4e 54 3d 3d 31 20 2a 2f 0a 20 20 75 38 INT==1 */. u8
cda0: 20 63 6f 6c 46 6c 61 67 73 3b 20 20 20 20 20 2f colFlags; /
cdb0: 2a 20 42 6f 6f 6c 65 61 6e 20 70 72 6f 70 65 72 * Boolean proper
cdc0: 74 69 65 73 2e 20 20 53 65 65 20 43 4f 4c 46 4c ties. See COLFL
cdd0: 41 47 5f 20 64 65 66 69 6e 65 73 20 62 65 6c 6f AG_ defines belo
cde0: 77 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 20 41 6c 6c 6f w */.};../* Allo
cdf0: 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 43 wed values for C
ce00: 6f 6c 75 6d 6e 2e 63 6f 6c 46 6c 61 67 73 3a 0a olumn.colFlags:.
ce10: 2a 2f 0a 23 64 65 66 69 6e 65 20 43 4f 4c 46 4c */.#define COLFL
ce20: 41 47 5f 50 52 49 4d 4b 45 59 20 20 30 78 30 30 AG_PRIMKEY 0x00
ce30: 30 31 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 01 /* Column
ce40: 69 73 20 70 61 72 74 20 6f 66 20 74 68 65 20 70 is part of the p
ce50: 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 64 rimary key */.#d
ce60: 65 66 69 6e 65 20 43 4f 4c 46 4c 41 47 5f 48 49 efine COLFLAG_HI
ce70: 44 44 45 4e 20 20 20 30 78 30 30 30 32 20 20 20 DDEN 0x0002
ce80: 20 2f 2a 20 41 20 68 69 64 64 65 6e 20 63 6f 6c /* A hidden col
ce90: 75 6d 6e 20 69 6e 20 61 20 76 69 72 74 75 61 6c umn in a virtual
cea0: 20 74 61 62 6c 65 20 2a 2f 0a 0a 2f 2a 0a 2a 2a table */../*.**
ceb0: 20 41 20 22 43 6f 6c 6c 61 74 69 6e 67 20 53 65 A "Collating Se
cec0: 71 75 65 6e 63 65 22 20 69 73 20 64 65 66 69 6e quence" is defin
ced0: 65 64 20 62 79 20 61 6e 20 69 6e 73 74 61 6e 63 ed by an instanc
cee0: 65 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 e of the followi
cef0: 6e 67 0a 2a 2a 20 73 74 72 75 63 74 75 72 65 2e ng.** structure.
cf00: 20 43 6f 6e 63 65 70 74 75 61 6c 6c 79 2c 20 61 Conceptually, a
cf10: 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 collating seque
cf20: 6e 63 65 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 nce consists of
cf30: 61 20 6e 61 6d 65 20 61 6e 64 0a 2a 2a 20 61 20 a name and.** a
cf40: 63 6f 6d 70 61 72 69 73 6f 6e 20 72 6f 75 74 69 comparison routi
cf50: 6e 65 20 74 68 61 74 20 64 65 66 69 6e 65 73 20 ne that defines
cf60: 74 68 65 20 6f 72 64 65 72 20 6f 66 20 74 68 61 the order of tha
cf70: 74 20 73 65 71 75 65 6e 63 65 2e 0a 2a 2a 0a 2a t sequence..**.*
cf80: 2a 20 49 66 20 43 6f 6c 6c 53 65 71 2e 78 43 6d * If CollSeq.xCm
cf90: 70 20 69 73 20 4e 55 4c 4c 2c 20 69 74 20 6d 65 p is NULL, it me
cfa0: 61 6e 73 20 74 68 61 74 20 74 68 65 0a 2a 2a 20 ans that the.**
cfb0: 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e collating sequen
cfc0: 63 65 20 69 73 20 75 6e 64 65 66 69 6e 65 64 2e ce is undefined.
cfd0: 20 20 49 6e 64 69 63 65 73 20 62 75 69 6c 74 20 Indices built
cfe0: 6f 6e 20 61 6e 20 75 6e 64 65 66 69 6e 65 64 0a on an undefined.
cff0: 2a 2a 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 71 ** collating seq
d000: 75 65 6e 63 65 20 6d 61 79 20 6e 6f 74 20 62 65 uence may not be
d010: 20 72 65 61 64 20 6f 72 20 77 72 69 74 74 65 6e read or written
d020: 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 43 6f 6c 6c ..*/.struct Coll
d030: 53 65 71 20 7b 0a 20 20 63 68 61 72 20 2a 7a 4e Seq {. char *zN
d040: 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ame; /*
d050: 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 63 6f 6c Name of the col
d060: 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63 65 2c lating sequence,
d070: 20 55 54 46 2d 38 20 65 6e 63 6f 64 65 64 20 2a UTF-8 encoded *
d080: 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 20 20 /. u8 enc;
d090: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
d0a0: 74 20 65 6e 63 6f 64 69 6e 67 20 68 61 6e 64 6c t encoding handl
d0b0: 65 64 20 62 79 20 78 43 6d 70 28 29 20 2a 2f 0a ed by xCmp() */.
d0c0: 20 20 76 6f 69 64 20 2a 70 55 73 65 72 3b 20 20 void *pUser;
d0d0: 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 /* First
d0e0: 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 43 6d argument to xCm
d0f0: 70 28 29 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 p() */. int (*x
d100: 43 6d 70 29 28 76 6f 69 64 2a 2c 69 6e 74 2c 20 Cmp)(void*,int,
d110: 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e 74 const void*, int
d120: 2c 20 63 6f 6e 73 74 20 76 6f 69 64 2a 29 3b 0a , const void*);.
d130: 20 20 76 6f 69 64 20 28 2a 78 44 65 6c 29 28 76 void (*xDel)(v
d140: 6f 69 64 2a 29 3b 20 20 2f 2a 20 44 65 73 74 72 oid*); /* Destr
d150: 75 63 74 6f 72 20 66 6f 72 20 70 55 73 65 72 20 uctor for pUser
d160: 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 20 73 */.};../*.** A s
d170: 6f 72 74 20 6f 72 64 65 72 20 63 61 6e 20 62 65 ort order can be
d180: 20 65 69 74 68 65 72 20 41 53 43 20 6f 72 20 44 either ASC or D
d190: 45 53 43 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 ESC..*/.#define
d1a0: 53 51 4c 49 54 45 5f 53 4f 5f 41 53 43 20 20 20 SQLITE_SO_ASC
d1b0: 20 20 20 20 30 20 20 2f 2a 20 53 6f 72 74 20 69 0 /* Sort i
d1c0: 6e 20 61 73 63 65 6e 64 69 6e 67 20 6f 72 64 65 n ascending orde
d1d0: 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c r */.#define SQL
d1e0: 49 54 45 5f 53 4f 5f 44 45 53 43 20 20 20 20 20 ITE_SO_DESC
d1f0: 20 31 20 20 2f 2a 20 53 6f 72 74 20 69 6e 20 61 1 /* Sort in a
d200: 73 63 65 6e 64 69 6e 67 20 6f 72 64 65 72 20 2a scending order *
d210: 2f 0a 0a 2f 2a 0a 2a 2a 20 43 6f 6c 75 6d 6e 20 /../*.** Column
d220: 61 66 66 69 6e 69 74 79 20 74 79 70 65 73 2e 0a affinity types..
d230: 2a 2a 0a 2a 2a 20 54 68 65 73 65 20 75 73 65 64 **.** These used
d240: 20 74 6f 20 68 61 76 65 20 6d 6e 65 6d 6f 6e 69 to have mnemoni
d250: 63 20 6e 61 6d 65 20 6c 69 6b 65 20 27 69 27 20 c name like 'i'
d260: 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 5f 49 for SQLITE_AFF_I
d270: 4e 54 45 47 45 52 20 61 6e 64 0a 2a 2a 20 27 74 NTEGER and.** 't
d280: 27 20 66 6f 72 20 53 51 4c 49 54 45 5f 41 46 46 ' for SQLITE_AFF
d290: 5f 54 45 58 54 2e 20 20 42 75 74 20 77 65 20 63 _TEXT. But we c
d2a0: 61 6e 20 73 61 76 65 20 61 20 6c 69 74 74 6c 65 an save a little
d2b0: 20 73 70 61 63 65 20 61 6e 64 20 69 6d 70 72 6f space and impro
d2c0: 76 65 0a 2a 2a 20 74 68 65 20 73 70 65 65 64 20 ve.** the speed
d2d0: 61 20 6c 69 74 74 6c 65 20 62 79 20 6e 75 6d 62 a little by numb
d2e0: 65 72 69 6e 67 20 74 68 65 20 76 61 6c 75 65 73 ering the values
d2f0: 20 63 6f 6e 73 65 63 75 74 69 76 65 6c 79 2e 20 consecutively.
d300: 20 0a 2a 2a 0a 2a 2a 20 42 75 74 20 72 61 74 68 .**.** But rath
d310: 65 72 20 74 68 61 6e 20 73 74 61 72 74 20 77 69 er than start wi
d320: 74 68 20 30 20 6f 72 20 31 2c 20 77 65 20 62 65 th 0 or 1, we be
d330: 67 69 6e 20 77 69 74 68 20 27 61 27 2e 20 20 54 gin with 'a'. T
d340: 68 61 74 20 77 61 79 2c 0a 2a 2a 20 77 68 65 6e hat way,.** when
d350: 20 6d 75 6c 74 69 70 6c 65 20 61 66 66 69 6e 69 multiple affini
d360: 74 79 20 74 79 70 65 73 20 61 72 65 20 63 6f 6e ty types are con
d370: 63 61 74 65 6e 61 74 65 64 20 69 6e 74 6f 20 61 catenated into a
d380: 20 73 74 72 69 6e 67 20 61 6e 64 0a 2a 2a 20 75 string and.** u
d390: 73 65 64 20 61 73 20 74 68 65 20 50 34 20 6f 70 sed as the P4 op
d3a0: 65 72 61 6e 64 2c 20 74 68 65 79 20 77 69 6c 6c erand, they will
d3b0: 20 62 65 20 6d 6f 72 65 20 72 65 61 64 61 62 6c be more readabl
d3c0: 65 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 61 6c e..**.** Note al
d3d0: 73 6f 20 74 68 61 74 20 74 68 65 20 6e 75 6d 65 so that the nume
d3e0: 72 69 63 20 74 79 70 65 73 20 61 72 65 20 67 72 ric types are gr
d3f0: 6f 75 70 65 64 20 74 6f 67 65 74 68 65 72 20 73 ouped together s
d400: 6f 20 74 68 61 74 20 74 65 73 74 69 6e 67 0a 2a o that testing.*
d410: 2a 20 66 6f 72 20 61 20 6e 75 6d 65 72 69 63 20 * for a numeric
d420: 74 79 70 65 20 69 73 20 61 20 73 69 6e 67 6c 65 type is a single
d430: 20 63 6f 6d 70 61 72 69 73 6f 6e 2e 0a 2a 2f 0a comparison..*/.
d440: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
d450: 46 46 5f 54 45 58 54 20 20 20 20 20 27 61 27 0a FF_TEXT 'a'.
d460: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
d470: 46 46 5f 4e 4f 4e 45 20 20 20 20 20 27 62 27 0a FF_NONE 'b'.
d480: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
d490: 46 46 5f 4e 55 4d 45 52 49 43 20 20 27 63 27 0a FF_NUMERIC 'c'.
d4a0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
d4b0: 46 46 5f 49 4e 54 45 47 45 52 20 20 27 64 27 0a FF_INTEGER 'd'.
d4c0: 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 #define SQLITE_A
d4d0: 46 46 5f 52 45 41 4c 20 20 20 20 20 27 65 27 0a FF_REAL 'e'.
d4e0: 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 .#define sqlite3
d4f0: 49 73 4e 75 6d 65 72 69 63 41 66 66 69 6e 69 74 IsNumericAffinit
d500: 79 28 58 29 20 20 28 28 58 29 3e 3d 53 51 4c 49 y(X) ((X)>=SQLI
d510: 54 45 5f 41 46 46 5f 4e 55 4d 45 52 49 43 29 0a TE_AFF_NUMERIC).
d520: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 ./*.** The SQLIT
d530: 45 5f 41 46 46 5f 4d 41 53 4b 20 76 61 6c 75 65 E_AFF_MASK value
d540: 73 20 6d 61 73 6b 73 20 6f 66 66 20 74 68 65 20 s masks off the
d550: 73 69 67 6e 69 66 69 63 61 6e 74 20 62 69 74 73 significant bits
d560: 20 6f 66 20 61 6e 0a 2a 2a 20 61 66 66 69 6e 69 of an.** affini
d570: 74 79 20 76 61 6c 75 65 2e 20 0a 2a 2f 0a 23 64 ty value. .*/.#d
d580: 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 41 46 46 efine SQLITE_AFF
d590: 5f 4d 41 53 4b 20 20 20 20 20 30 78 36 37 0a 0a _MASK 0x67..
d5a0: 2f 2a 0a 2a 2a 20 41 64 64 69 74 69 6f 6e 61 6c /*.** Additional
d5b0: 20 62 69 74 20 76 61 6c 75 65 73 20 74 68 61 74 bit values that
d5c0: 20 63 61 6e 20 62 65 20 4f 52 65 64 20 77 69 74 can be ORed wit
d5d0: 68 20 61 6e 20 61 66 66 69 6e 69 74 79 20 77 69 h an affinity wi
d5e0: 74 68 6f 75 74 0a 2a 2a 20 63 68 61 6e 67 69 6e thout.** changin
d5f0: 67 20 74 68 65 20 61 66 66 69 6e 69 74 79 2e 0a g the affinity..
d600: 2a 2a 0a 2a 2a 20 54 68 65 20 53 51 4c 49 54 45 **.** The SQLITE
d610: 5f 4e 4f 54 4e 55 4c 4c 20 66 6c 61 67 20 69 73 _NOTNULL flag is
d620: 20 61 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 6f a combination o
d630: 66 20 4e 55 4c 4c 45 51 20 61 6e 64 20 4a 55 4d f NULLEQ and JUM
d640: 50 49 46 4e 55 4c 4c 2e 0a 2a 2a 20 49 74 20 63 PIFNULL..** It c
d650: 61 75 73 65 73 20 61 6e 20 61 73 73 65 72 74 28 auses an assert(
d660: 29 20 74 6f 20 66 69 72 65 20 69 66 20 65 69 74 ) to fire if eit
d670: 68 65 72 20 6f 70 65 72 61 6e 64 20 74 6f 20 61 her operand to a
d680: 20 63 6f 6d 70 61 72 69 73 6f 6e 0a 2a 2a 20 6f comparison.** o
d690: 70 65 72 61 74 6f 72 20 69 73 20 4e 55 4c 4c 2e perator is NULL.
d6a0: 20 20 49 74 20 69 73 20 61 64 64 65 64 20 74 6f It is added to
d6b0: 20 63 65 72 74 61 69 6e 20 63 6f 6d 70 61 72 69 certain compari
d6c0: 73 6f 6e 20 6f 70 65 72 61 74 6f 72 73 20 74 6f son operators to
d6d0: 0a 2a 2a 20 70 72 6f 76 65 20 74 68 61 74 20 74 .** prove that t
d6e0: 68 65 20 6f 70 65 72 61 6e 64 73 20 61 72 65 20 he operands are
d6f0: 61 6c 77 61 79 73 20 4e 4f 54 20 4e 55 4c 4c 2e always NOT NULL.
d700: 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 .*/.#define SQLI
d710: 54 45 5f 4a 55 4d 50 49 46 4e 55 4c 4c 20 20 20 TE_JUMPIFNULL
d720: 30 78 30 38 20 20 2f 2a 20 6a 75 6d 70 73 20 69 0x08 /* jumps i
d730: 66 20 65 69 74 68 65 72 20 6f 70 65 72 61 6e 64 f either operand
d740: 20 69 73 20 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 is NULL */.#def
d750: 69 6e 65 20 53 51 4c 49 54 45 5f 53 54 4f 52 45 ine SQLITE_STORE
d760: 50 32 20 20 20 20 20 20 30 78 31 30 20 20 2f 2a P2 0x10 /*
d770: 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 6e Store result in
d780: 20 72 65 67 5b 50 32 5d 20 72 61 74 68 65 72 20 reg[P2] rather
d790: 74 68 61 6e 20 6a 75 6d 70 20 2a 2f 0a 23 64 65 than jump */.#de
d7a0: 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 55 4c 4c fine SQLITE_NULL
d7b0: 45 51 20 20 20 20 20 20 20 30 78 38 30 20 20 2f EQ 0x80 /
d7c0: 2a 20 4e 55 4c 4c 3d 4e 55 4c 4c 20 2a 2f 0a 23 * NULL=NULL */.#
d7d0: 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 4e 4f define SQLITE_NO
d7e0: 54 4e 55 4c 4c 20 20 20 20 20 20 30 78 38 38 20 TNULL 0x88
d7f0: 20 2f 2a 20 41 73 73 65 72 74 20 74 68 61 74 20 /* Assert that
d800: 6f 70 65 72 61 6e 64 73 20 61 72 65 20 6e 65 76 operands are nev
d810: 65 72 20 4e 55 4c 4c 20 2a 2f 0a 0a 2f 2a 0a 2a er NULL */../*.*
d820: 2a 20 41 6e 20 6f 62 6a 65 63 74 20 6f 66 20 74 * An object of t
d830: 68 69 73 20 74 79 70 65 20 69 73 20 63 72 65 61 his type is crea
d840: 74 65 64 20 66 6f 72 20 65 61 63 68 20 76 69 72 ted for each vir
d850: 74 75 61 6c 20 74 61 62 6c 65 20 70 72 65 73 65 tual table prese
d860: 6e 74 20 69 6e 0a 2a 2a 20 74 68 65 20 64 61 74 nt in.** the dat
d870: 61 62 61 73 65 20 73 63 68 65 6d 61 2e 20 0a 2a abase schema. .*
d880: 2a 0a 2a 2a 20 49 66 20 74 68 65 20 64 61 74 61 *.** If the data
d890: 62 61 73 65 20 73 63 68 65 6d 61 20 69 73 20 73 base schema is s
d8a0: 68 61 72 65 64 2c 20 74 68 65 6e 20 74 68 65 72 hared, then ther
d8b0: 65 20 69 73 20 6f 6e 65 20 69 6e 73 74 61 6e 63 e is one instanc
d8c0: 65 20 6f 66 20 74 68 69 73 0a 2a 2a 20 73 74 72 e of this.** str
d8d0: 75 63 74 75 72 65 20 66 6f 72 20 65 61 63 68 20 ucture for each
d8e0: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
d8f0: 69 6f 6e 20 28 73 71 6c 69 74 65 33 2a 29 20 74 ion (sqlite3*) t
d900: 68 61 74 20 75 73 65 73 20 74 68 65 20 73 68 61 hat uses the sha
d910: 72 65 64 0a 2a 2a 20 73 63 68 65 6d 61 2e 20 54 red.** schema. T
d920: 68 69 73 20 69 73 20 62 65 63 61 75 73 65 20 65 his is because e
d930: 61 63 68 20 64 61 74 61 62 61 73 65 20 63 6f 6e ach database con
d940: 6e 65 63 74 69 6f 6e 20 72 65 71 75 69 72 65 73 nection requires
d950: 20 69 74 73 20 6f 77 6e 20 75 6e 69 71 75 65 0a its own unique.
d960: 2a 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 ** instance of t
d970: 68 65 20 73 71 6c 69 74 65 33 5f 76 74 61 62 2a he sqlite3_vtab*
d980: 20 68 61 6e 64 6c 65 20 75 73 65 64 20 74 6f 20 handle used to
d990: 61 63 63 65 73 73 20 74 68 65 20 76 69 72 74 75 access the virtu
d9a0: 61 6c 20 74 61 62 6c 65 20 0a 2a 2a 20 69 6d 70 al table .** imp
d9b0: 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 73 71 6c lementation. sql
d9c0: 69 74 65 33 5f 76 74 61 62 2a 20 68 61 6e 64 6c ite3_vtab* handl
d9d0: 65 73 20 63 61 6e 20 6e 6f 74 20 62 65 20 73 68 es can not be sh
d9e0: 61 72 65 64 20 62 65 74 77 65 65 6e 20 0a 2a 2a ared between .**
d9f0: 20 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 database connec
da00: 74 69 6f 6e 73 2c 20 65 76 65 6e 20 77 68 65 6e tions, even when
da10: 20 74 68 65 20 72 65 73 74 20 6f 66 20 74 68 65 the rest of the
da20: 20 69 6e 2d 6d 65 6d 6f 72 79 20 64 61 74 61 62 in-memory datab
da30: 61 73 65 20 0a 2a 2a 20 73 63 68 65 6d 61 20 69 ase .** schema i
da40: 73 20 73 68 61 72 65 64 2c 20 61 73 20 74 68 65 s shared, as the
da50: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
da60: 6f 66 74 65 6e 20 73 74 6f 72 65 73 20 74 68 65 often stores the
da70: 20 64 61 74 61 62 61 73 65 0a 2a 2a 20 63 6f 6e database.** con
da80: 6e 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 70 nection handle p
da90: 61 73 73 65 64 20 74 6f 20 69 74 20 76 69 61 20 assed to it via
daa0: 74 68 65 20 78 43 6f 6e 6e 65 63 74 28 29 20 6f the xConnect() o
dab0: 72 20 78 43 72 65 61 74 65 28 29 20 6d 65 74 68 r xCreate() meth
dac0: 6f 64 0a 2a 2a 20 64 75 72 69 6e 67 20 69 6e 69 od.** during ini
dad0: 74 69 61 6c 69 7a 61 74 69 6f 6e 20 69 6e 74 65 tialization inte
dae0: 72 6e 61 6c 6c 79 2e 20 54 68 69 73 20 64 61 74 rnally. This dat
daf0: 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 6f 6e abase connection
db00: 20 68 61 6e 64 6c 65 20 6d 61 79 0a 2a 2a 20 74 handle may.** t
db10: 68 65 6e 20 62 65 20 75 73 65 64 20 62 79 20 74 hen be used by t
db20: 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65 he virtual table
db30: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
db40: 74 6f 20 61 63 63 65 73 73 20 72 65 61 6c 20 74 to access real t
db50: 61 62 6c 65 73 20 0a 2a 2a 20 77 69 74 68 69 6e ables .** within
db60: 20 74 68 65 20 64 61 74 61 62 61 73 65 2e 20 53 the database. S
db70: 6f 20 74 68 61 74 20 74 68 65 79 20 61 70 70 65 o that they appe
db80: 61 72 20 61 73 20 70 61 72 74 20 6f 66 20 74 68 ar as part of th
db90: 65 20 63 61 6c 6c 65 72 73 20 0a 2a 2a 20 74 72 e callers .** tr
dba0: 61 6e 73 61 63 74 69 6f 6e 2c 20 74 68 65 73 65 ansaction, these
dbb0: 20 61 63 63 65 73 73 65 73 20 6e 65 65 64 20 74 accesses need t
dbc0: 6f 20 62 65 20 6d 61 64 65 20 76 69 61 20 74 68 o be made via th
dbd0: 65 20 73 61 6d 65 20 64 61 74 61 62 61 73 65 20 e same database
dbe0: 0a 2a 2a 20 63 6f 6e 6e 65 63 74 69 6f 6e 20 61 .** connection a
dbf0: 73 20 74 68 61 74 20 75 73 65 64 20 74 6f 20 65 s that used to e
dc00: 78 65 63 75 74 65 20 53 51 4c 20 6f 70 65 72 61 xecute SQL opera
dc10: 74 69 6f 6e 73 20 6f 6e 20 74 68 65 20 76 69 72 tions on the vir
dc20: 74 75 61 6c 20 74 61 62 6c 65 2e 0a 2a 2a 0a 2a tual table..**.*
dc30: 2a 20 41 6c 6c 20 56 54 61 62 6c 65 20 6f 62 6a * All VTable obj
dc40: 65 63 74 73 20 74 68 61 74 20 63 6f 72 72 65 73 ects that corres
dc50: 70 6f 6e 64 20 74 6f 20 61 20 73 69 6e 67 6c 65 pond to a single
dc60: 20 74 61 62 6c 65 20 69 6e 20 61 20 73 68 61 72 table in a shar
dc70: 65 64 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 73 ed.** database s
dc80: 63 68 65 6d 61 20 61 72 65 20 69 6e 69 74 69 61 chema are initia
dc90: 6c 6c 79 20 73 74 6f 72 65 64 20 69 6e 20 61 20 lly stored in a
dca0: 6c 69 6e 6b 65 64 2d 6c 69 73 74 20 70 6f 69 6e linked-list poin
dcb0: 74 65 64 20 74 6f 20 62 79 0a 2a 2a 20 74 68 65 ted to by.** the
dcc0: 20 54 61 62 6c 65 2e 70 56 54 61 62 6c 65 20 6d Table.pVTable m
dcd0: 65 6d 62 65 72 20 76 61 72 69 61 62 6c 65 20 6f ember variable o
dce0: 66 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 f the correspond
dcf0: 69 6e 67 20 54 61 62 6c 65 20 6f 62 6a 65 63 74 ing Table object
dd00: 2e 0a 2a 2a 20 57 68 65 6e 20 61 6e 20 73 71 6c ..** When an sql
dd10: 69 74 65 33 5f 70 72 65 70 61 72 65 28 29 20 6f ite3_prepare() o
dd20: 70 65 72 61 74 69 6f 6e 20 69 73 20 72 65 71 75 peration is requ
dd30: 69 72 65 64 20 74 6f 20 61 63 63 65 73 73 20 74 ired to access t
dd40: 68 65 20 76 69 72 74 75 61 6c 0a 2a 2a 20 74 61 he virtual.** ta
dd50: 62 6c 65 2c 20 69 74 20 73 65 61 72 63 68 65 73 ble, it searches
dd60: 20 74 68 65 20 6c 69 73 74 20 66 6f 72 20 74 68 the list for th
dd70: 65 20 56 54 61 62 6c 65 20 74 68 61 74 20 63 6f e VTable that co
dd80: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 rresponds to the
dd90: 0a 2a 2a 20 64 61 74 61 62 61 73 65 20 63 6f 6e .** database con
dda0: 6e 65 63 74 69 6f 6e 20 64 6f 69 6e 67 20 74 68 nection doing th
ddb0: 65 20 70 72 65 70 61 72 69 6e 67 20 73 6f 20 61 e preparing so a
ddc0: 73 20 74 6f 20 75 73 65 20 74 68 65 20 63 6f 72 s to use the cor
ddd0: 72 65 63 74 0a 2a 2a 20 73 71 6c 69 74 65 33 5f rect.** sqlite3_
dde0: 76 74 61 62 2a 20 68 61 6e 64 6c 65 20 69 6e 20 vtab* handle in
ddf0: 74 68 65 20 63 6f 6d 70 69 6c 65 64 20 71 75 65 the compiled que
de00: 72 79 2e 0a 2a 2a 0a 2a 2a 20 57 68 65 6e 20 61 ry..**.** When a
de10: 6e 20 69 6e 2d 6d 65 6d 6f 72 79 20 54 61 62 6c n in-memory Tabl
de20: 65 20 6f 62 6a 65 63 74 20 69 73 20 64 65 6c 65 e object is dele
de30: 74 65 64 20 28 66 6f 72 20 65 78 61 6d 70 6c 65 ted (for example
de40: 20 77 68 65 6e 20 74 68 65 0a 2a 2a 20 73 63 68 when the.** sch
de50: 65 6d 61 20 69 73 20 62 65 69 6e 67 20 72 65 6c ema is being rel
de60: 6f 61 64 65 64 20 66 6f 72 20 73 6f 6d 65 20 72 oaded for some r
de70: 65 61 73 6f 6e 29 2c 20 74 68 65 20 56 54 61 62 eason), the VTab
de80: 6c 65 20 6f 62 6a 65 63 74 73 20 61 72 65 20 6e le objects are n
de90: 6f 74 20 0a 2a 2a 20 64 65 6c 65 74 65 64 20 61 ot .** deleted a
dea0: 6e 64 20 74 68 65 20 73 71 6c 69 74 65 33 5f 76 nd the sqlite3_v
deb0: 74 61 62 2a 20 68 61 6e 64 6c 65 73 20 61 72 65 tab* handles are
dec0: 20 6e 6f 74 20 78 44 69 73 63 6f 6e 6e 65 63 74 not xDisconnect
ded0: 28 29 65 64 20 0a 2a 2a 20 69 6d 6d 65 64 69 61 ()ed .** immedia
dee0: 74 65 6c 79 2e 20 49 6e 73 74 65 61 64 2c 20 74 tely. Instead, t
def0: 68 65 79 20 61 72 65 20 6d 6f 76 65 64 20 66 72 hey are moved fr
df00: 6f 6d 20 74 68 65 20 54 61 62 6c 65 2e 70 56 54 om the Table.pVT
df10: 61 62 6c 65 20 6c 69 73 74 20 74 6f 0a 2a 2a 20 able list to.**
df20: 61 6e 6f 74 68 65 72 20 6c 69 6e 6b 65 64 20 6c another linked l
df30: 69 73 74 20 68 65 61 64 65 64 20 62 79 20 74 68 ist headed by th
df40: 65 20 73 71 6c 69 74 65 33 2e 70 44 69 73 63 6f e sqlite3.pDisco
df50: 6e 6e 65 63 74 20 6d 65 6d 62 65 72 20 6f 66 20 nnect member of
df60: 74 68 65 0a 2a 2a 20 63 6f 72 72 65 73 70 6f 6e the.** correspon
df70: 64 69 6e 67 20 73 71 6c 69 74 65 33 20 73 74 72 ding sqlite3 str
df80: 75 63 74 75 72 65 2e 20 54 68 65 79 20 61 72 65 ucture. They are
df90: 20 74 68 65 6e 20 64 65 6c 65 74 65 64 2f 78 44 then deleted/xD
dfa0: 69 73 63 6f 6e 6e 65 63 74 65 64 20 0a 2a 2a 20 isconnected .**
dfb0: 6e 65 78 74 20 74 69 6d 65 20 61 20 73 74 61 74 next time a stat
dfc0: 65 6d 65 6e 74 20 69 73 20 70 72 65 70 61 72 65 ement is prepare
dfd0: 64 20 75 73 69 6e 67 20 73 61 69 64 20 73 71 6c d using said sql
dfe0: 69 74 65 33 2a 2e 20 54 68 69 73 20 69 73 20 64 ite3*. This is d
dff0: 6f 6e 65 0a 2a 2a 20 74 6f 20 61 76 6f 69 64 20 one.** to avoid
e000: 64 65 61 64 6c 6f 63 6b 20 69 73 73 75 65 73 20 deadlock issues
e010: 69 6e 76 6f 6c 76 69 6e 67 20 6d 75 6c 74 69 70 involving multip
e020: 6c 65 20 73 71 6c 69 74 65 33 2e 6d 75 74 65 78 le sqlite3.mutex
e030: 20 6d 75 74 65 78 65 73 2e 0a 2a 2a 20 52 65 66 mutexes..** Ref
e040: 65 72 20 74 6f 20 63 6f 6d 6d 65 6e 74 73 20 61 er to comments a
e050: 62 6f 76 65 20 66 75 6e 63 74 69 6f 6e 20 73 71 bove function sq
e060: 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 6b 4c lite3VtabUnlockL
e070: 69 73 74 28 29 20 66 6f 72 20 61 6e 0a 2a 2a 20 ist() for an.**
e080: 65 78 70 6c 61 6e 61 74 69 6f 6e 20 61 73 20 74 explanation as t
e090: 6f 20 77 68 79 20 69 74 20 69 73 20 73 61 66 65 o why it is safe
e0a0: 20 74 6f 20 61 64 64 20 61 6e 20 65 6e 74 72 79 to add an entry
e0b0: 20 74 6f 20 61 6e 20 73 71 6c 69 74 65 33 2e 70 to an sqlite3.p
e0c0: 44 69 73 63 6f 6e 6e 65 63 74 0a 2a 2a 20 6c 69 Disconnect.** li
e0d0: 73 74 20 77 69 74 68 6f 75 74 20 68 6f 6c 64 69 st without holdi
e0e0: 6e 67 20 74 68 65 20 63 6f 72 72 65 73 70 6f 6e ng the correspon
e0f0: 64 69 6e 67 20 73 71 6c 69 74 65 33 2e 6d 75 74 ding sqlite3.mut
e100: 65 78 20 6d 75 74 65 78 2e 0a 2a 2a 0a 2a 2a 20 ex mutex..**.**
e110: 54 68 65 20 6d 65 6d 6f 72 79 20 66 6f 72 20 6f The memory for o
e120: 62 6a 65 63 74 73 20 6f 66 20 74 68 69 73 20 74 bjects of this t
e130: 79 70 65 20 69 73 20 61 6c 77 61 79 73 20 61 6c ype is always al
e140: 6c 6f 63 61 74 65 64 20 62 79 20 0a 2a 2a 20 73 located by .** s
e150: 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 28 29 qlite3DbMalloc()
e160: 2c 20 75 73 69 6e 67 20 74 68 65 20 63 6f 6e 6e , using the conn
e170: 65 63 74 69 6f 6e 20 68 61 6e 64 6c 65 20 73 74 ection handle st
e180: 6f 72 65 64 20 69 6e 20 56 54 61 62 6c 65 2e 64 ored in VTable.d
e190: 62 20 61 73 20 0a 2a 2a 20 74 68 65 20 66 69 72 b as .** the fir
e1a0: 73 74 20 61 72 67 75 6d 65 6e 74 2e 0a 2a 2f 0a st argument..*/.
e1b0: 73 74 72 75 63 74 20 56 54 61 62 6c 65 20 7b 0a struct VTable {.
e1c0: 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 sqlite3 *db;
e1d0: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 /* D
e1e0: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
e1f0: 6f 6e 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 on associated wi
e200: 74 68 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f th this table */
e210: 0a 20 20 4d 6f 64 75 6c 65 20 2a 70 4d 6f 64 3b . Module *pMod;
e220: 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
e230: 50 6f 69 6e 74 65 72 20 74 6f 20 6d 6f 64 75 6c Pointer to modul
e240: 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e e implementation
e250: 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 5f 76 74 */. sqlite3_vt
e260: 61 62 20 2a 70 56 74 61 62 3b 20 20 20 20 20 20 ab *pVtab;
e270: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 76 74 /* Pointer to vt
e280: 61 62 20 69 6e 73 74 61 6e 63 65 20 2a 2f 0a 20 ab instance */.
e290: 20 69 6e 74 20 6e 52 65 66 3b 20 20 20 20 20 20 int nRef;
e2a0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
e2b0: 6d 62 65 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 mber of pointers
e2c0: 20 74 6f 20 74 68 69 73 20 73 74 72 75 63 74 75 to this structu
e2d0: 72 65 20 2a 2f 0a 20 20 75 38 20 62 43 6f 6e 73 re */. u8 bCons
e2e0: 74 72 61 69 6e 74 3b 20 20 20 20 20 20 20 20 20 traint;
e2f0: 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 6f 6e /* True if con
e300: 73 74 72 61 69 6e 74 73 20 61 72 65 20 73 75 70 straints are sup
e310: 70 6f 72 74 65 64 20 2a 2f 0a 20 20 69 6e 74 20 ported */. int
e320: 69 53 61 76 65 70 6f 69 6e 74 3b 20 20 20 20 20 iSavepoint;
e330: 20 20 20 20 20 20 2f 2a 20 44 65 70 74 68 20 6f /* Depth o
e340: 66 20 74 68 65 20 53 41 56 45 50 4f 49 4e 54 20 f the SAVEPOINT
e350: 73 74 61 63 6b 20 2a 2f 0a 20 20 56 54 61 62 6c stack */. VTabl
e360: 65 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 20 e *pNext;
e370: 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 69 6e 20 /* Next in
e380: 6c 69 6e 6b 65 64 20 6c 69 73 74 20 28 73 65 65 linked list (see
e390: 20 61 62 6f 76 65 29 20 2a 2f 0a 7d 3b 0a 0a 2f above) */.};../
e3a0: 2a 0a 2a 2a 20 45 61 63 68 20 53 51 4c 20 74 61 *.** Each SQL ta
e3b0: 62 6c 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 ble is represent
e3c0: 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20 62 79 20 ed in memory by
e3d0: 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 an instance of t
e3e0: 68 65 0a 2a 2a 20 66 6f 6c 6c 6f 77 69 6e 67 20 he.** following
e3f0: 73 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a structure..**.**
e400: 20 54 61 62 6c 65 2e 7a 4e 61 6d 65 20 69 73 20 Table.zName is
e410: 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 the name of the
e420: 74 61 62 6c 65 2e 20 20 54 68 65 20 63 61 73 65 table. The case
e430: 20 6f 66 20 74 68 65 20 6f 72 69 67 69 6e 61 6c of the original
e440: 0a 2a 2a 20 43 52 45 41 54 45 20 54 41 42 4c 45 .** CREATE TABLE
e450: 20 73 74 61 74 65 6d 65 6e 74 20 69 73 20 73 74 statement is st
e460: 6f 72 65 64 2c 20 62 75 74 20 63 61 73 65 20 69 ored, but case i
e470: 73 20 6e 6f 74 20 73 69 67 6e 69 66 69 63 61 6e s not significan
e480: 74 20 66 6f 72 0a 2a 2a 20 63 6f 6d 70 61 72 69 t for.** compari
e490: 73 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 54 61 62 6c sons..**.** Tabl
e4a0: 65 2e 6e 43 6f 6c 20 69 73 20 74 68 65 20 6e 75 e.nCol is the nu
e4b0: 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 mber of columns
e4c0: 69 6e 20 74 68 69 73 20 74 61 62 6c 65 2e 20 20 in this table.
e4d0: 54 61 62 6c 65 2e 61 43 6f 6c 20 69 73 20 61 0a Table.aCol is a.
e4e0: 2a 2a 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 6e ** pointer to an
e4f0: 20 61 72 72 61 79 20 6f 66 20 43 6f 6c 75 6d 6e array of Column
e500: 20 73 74 72 75 63 74 75 72 65 73 2c 20 6f 6e 65 structures, one
e510: 20 66 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e for each column
e520: 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 74 ..**.** If the t
e530: 61 62 6c 65 20 68 61 73 20 61 6e 20 49 4e 54 45 able has an INTE
e540: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY,
e550: 20 74 68 65 6e 20 54 61 62 6c 65 2e 69 50 4b 65 then Table.iPKe
e560: 79 20 69 73 20 74 68 65 20 69 6e 64 65 78 20 6f y is the index o
e570: 66 0a 2a 2a 20 74 68 65 20 63 6f 6c 75 6d 6e 20 f.** the column
e580: 74 68 61 74 20 69 73 20 74 68 61 74 20 6b 65 79 that is that key
e590: 2e 20 20 20 4f 74 68 65 72 77 69 73 65 20 54 61 . Otherwise Ta
e5a0: 62 6c 65 2e 69 50 4b 65 79 20 69 73 20 6e 65 67 ble.iPKey is neg
e5b0: 61 74 69 76 65 2e 20 20 4e 6f 74 65 0a 2a 2a 20 ative. Note.**
e5c0: 74 68 61 74 20 74 68 65 20 64 61 74 61 74 79 70 that the datatyp
e5d0: 65 20 6f 66 20 74 68 65 20 50 52 49 4d 41 52 59 e of the PRIMARY
e5e0: 20 4b 45 59 20 6d 75 73 74 20 62 65 20 49 4e 54 KEY must be INT
e5f0: 45 47 45 52 20 66 6f 72 20 74 68 69 73 20 66 69 EGER for this fi
e600: 65 6c 64 20 74 6f 0a 2a 2a 20 62 65 20 73 65 74 eld to.** be set
e610: 2e 20 20 41 6e 20 49 4e 54 45 47 45 52 20 50 52 . An INTEGER PR
e620: 49 4d 41 52 59 20 4b 45 59 20 69 73 20 75 73 65 IMARY KEY is use
e630: 64 20 61 73 20 74 68 65 20 72 6f 77 69 64 20 66 d as the rowid f
e640: 6f 72 20 65 61 63 68 20 72 6f 77 20 6f 66 0a 2a or each row of.*
e650: 2a 20 74 68 65 20 74 61 62 6c 65 2e 20 20 49 66 * the table. If
e660: 20 61 20 74 61 62 6c 65 20 68 61 73 20 6e 6f 20 a table has no
e670: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 INTEGER PRIMARY
e680: 4b 45 59 2c 20 74 68 65 6e 20 61 20 72 61 6e 64 KEY, then a rand
e690: 6f 6d 20 72 6f 77 69 64 0a 2a 2a 20 69 73 20 67 om rowid.** is g
e6a0: 65 6e 65 72 61 74 65 64 20 66 6f 72 20 65 61 63 enerated for eac
e6b0: 68 20 72 6f 77 20 6f 66 20 74 68 65 20 74 61 62 h row of the tab
e6c0: 6c 65 2e 20 20 54 46 5f 48 61 73 50 72 69 6d 61 le. TF_HasPrima
e6d0: 72 79 4b 65 79 20 69 73 20 73 65 74 20 69 66 0a ryKey is set if.
e6e0: 2a 2a 20 74 68 65 20 74 61 62 6c 65 20 68 61 73 ** the table has
e6f0: 20 61 6e 79 20 50 52 49 4d 41 52 59 20 4b 45 59 any PRIMARY KEY
e700: 2c 20 49 4e 54 45 47 45 52 20 6f 72 20 6f 74 68 , INTEGER or oth
e710: 65 72 77 69 73 65 2e 0a 2a 2a 0a 2a 2a 20 54 61 erwise..**.** Ta
e720: 62 6c 65 2e 74 6e 75 6d 20 69 73 20 74 68 65 20 ble.tnum is the
e730: 70 61 67 65 20 6e 75 6d 62 65 72 20 66 6f 72 20 page number for
e740: 74 68 65 20 72 6f 6f 74 20 42 54 72 65 65 20 70 the root BTree p
e750: 61 67 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 age of the table
e760: 20 69 6e 20 74 68 65 0a 2a 2a 20 64 61 74 61 62 in the.** datab
e770: 61 73 65 20 66 69 6c 65 2e 20 20 49 66 20 54 61 ase file. If Ta
e780: 62 6c 65 2e 69 44 62 20 69 73 20 74 68 65 20 69 ble.iDb is the i
e790: 6e 64 65 78 20 6f 66 20 74 68 65 20 64 61 74 61 ndex of the data
e7a0: 62 61 73 65 20 74 61 62 6c 65 20 62 61 63 6b 65 base table backe
e7b0: 6e 64 0a 2a 2a 20 69 6e 20 73 71 6c 69 74 65 2e nd.** in sqlite.
e7c0: 61 44 62 5b 5d 2e 20 20 30 20 69 73 20 66 6f 72 aDb[]. 0 is for
e7d0: 20 74 68 65 20 6d 61 69 6e 20 64 61 74 61 62 61 the main databa
e7e0: 73 65 20 61 6e 64 20 31 20 69 73 20 66 6f 72 20 se and 1 is for
e7f0: 74 68 65 20 66 69 6c 65 20 74 68 61 74 0a 2a 2a the file that.**
e800: 20 68 6f 6c 64 73 20 74 65 6d 70 6f 72 61 72 79 holds temporary
e810: 20 74 61 62 6c 65 73 20 61 6e 64 20 69 6e 64 69 tables and indi
e820: 63 65 73 2e 20 20 49 66 20 54 46 5f 45 70 68 65 ces. If TF_Ephe
e830: 6d 65 72 61 6c 20 69 73 20 73 65 74 0a 2a 2a 20 meral is set.**
e840: 74 68 65 6e 20 74 68 65 20 74 61 62 6c 65 20 69 then the table i
e850: 73 20 73 74 6f 72 65 64 20 69 6e 20 61 20 66 69 s stored in a fi
e860: 6c 65 20 74 68 61 74 20 69 73 20 61 75 74 6f 6d le that is autom
e870: 61 74 69 63 61 6c 6c 79 20 64 65 6c 65 74 65 64 atically deleted
e880: 0a 2a 2a 20 77 68 65 6e 20 74 68 65 20 56 44 42 .** when the VDB
e890: 45 20 63 75 72 73 6f 72 20 74 6f 20 74 68 65 20 E cursor to the
e8a0: 74 61 62 6c 65 20 69 73 20 63 6c 6f 73 65 64 2e table is closed.
e8b0: 20 20 49 6e 20 74 68 69 73 20 63 61 73 65 20 54 In this case T
e8c0: 61 62 6c 65 2e 74 6e 75 6d 20 0a 2a 2a 20 72 65 able.tnum .** re
e8d0: 66 65 72 73 20 56 44 42 45 20 63 75 72 73 6f 72 fers VDBE cursor
e8e0: 20 6e 75 6d 62 65 72 20 74 68 61 74 20 68 6f 6c number that hol
e8f0: 64 73 20 74 68 65 20 74 61 62 6c 65 20 6f 70 65 ds the table ope
e900: 6e 2c 20 6e 6f 74 20 74 6f 20 74 68 65 20 72 6f n, not to the ro
e910: 6f 74 0a 2a 2a 20 70 61 67 65 20 6e 75 6d 62 65 ot.** page numbe
e920: 72 2e 20 20 54 72 61 6e 73 69 65 6e 74 20 74 61 r. Transient ta
e930: 62 6c 65 73 20 61 72 65 20 75 73 65 64 20 74 6f bles are used to
e940: 20 68 6f 6c 64 20 74 68 65 20 72 65 73 75 6c 74 hold the result
e950: 73 20 6f 66 20 61 0a 2a 2a 20 73 75 62 2d 71 75 s of a.** sub-qu
e960: 65 72 79 20 74 68 61 74 20 61 70 70 65 61 72 73 ery that appears
e970: 20 69 6e 73 74 65 61 64 20 6f 66 20 61 20 72 65 instead of a re
e980: 61 6c 20 74 61 62 6c 65 20 6e 61 6d 65 20 69 6e al table name in
e990: 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 the FROM clause
e9a0: 20 0a 2a 2a 20 6f 66 20 61 20 53 45 4c 45 43 54 .** of a SELECT
e9b0: 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 statement..*/.s
e9c0: 74 72 75 63 74 20 54 61 62 6c 65 20 7b 0a 20 20 truct Table {.
e9d0: 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 char *zName;
e9e0: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
e9f0: 74 68 65 20 74 61 62 6c 65 20 6f 72 20 76 69 65 the table or vie
ea00: 77 20 2a 2f 0a 20 20 43 6f 6c 75 6d 6e 20 2a 61 w */. Column *a
ea10: 43 6f 6c 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 Col; /* I
ea20: 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 nformation about
ea30: 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a each column */.
ea40: 20 20 49 6e 64 65 78 20 2a 70 49 6e 64 65 78 3b Index *pIndex;
ea50: 20 20 20 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f /* List o
ea60: 66 20 53 51 4c 20 69 6e 64 65 78 65 73 20 6f 6e f SQL indexes on
ea70: 20 74 68 69 73 20 74 61 62 6c 65 2e 20 2a 2f 0a this table. */.
ea80: 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 Select *pSelec
ea90: 74 3b 20 20 20 20 20 2f 2a 20 4e 55 4c 4c 20 66 t; /* NULL f
eaa0: 6f 72 20 74 61 62 6c 65 73 2e 20 20 50 6f 69 6e or tables. Poin
eab0: 74 73 20 74 6f 20 64 65 66 69 6e 69 74 69 6f 6e ts to definition
eac0: 20 69 66 20 61 20 76 69 65 77 2e 20 2a 2f 0a 20 if a view. */.
ead0: 20 46 4b 65 79 20 2a 70 46 4b 65 79 3b 20 20 20 FKey *pFKey;
eae0: 20 20 20 20 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 /* Linked
eaf0: 6c 69 73 74 20 6f 66 20 61 6c 6c 20 66 6f 72 65 list of all fore
eb00: 69 67 6e 20 6b 65 79 73 20 69 6e 20 74 68 69 73 ign keys in this
eb10: 20 74 61 62 6c 65 20 2a 2f 0a 20 20 63 68 61 72 table */. char
eb20: 20 2a 7a 43 6f 6c 41 66 66 3b 20 20 20 20 20 20 *zColAff;
eb30: 20 2f 2a 20 53 74 72 69 6e 67 20 64 65 66 69 6e /* String defin
eb40: 69 6e 67 20 74 68 65 20 61 66 66 69 6e 69 74 79 ing the affinity
eb50: 20 6f 66 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 of each column
eb60: 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 */.#ifndef SQLIT
eb70: 45 5f 4f 4d 49 54 5f 43 48 45 43 4b 0a 20 20 45 E_OMIT_CHECK. E
eb80: 78 70 72 4c 69 73 74 20 2a 70 43 68 65 63 6b 3b xprList *pCheck;
eb90: 20 20 20 20 2f 2a 20 41 6c 6c 20 43 48 45 43 4b /* All CHECK
eba0: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
ebb0: 23 65 6e 64 69 66 0a 20 20 4c 6f 67 45 73 74 20 #endif. LogEst
ebc0: 6e 52 6f 77 4c 6f 67 45 73 74 3b 20 20 20 2f 2a nRowLogEst; /*
ebd0: 20 45 73 74 69 6d 61 74 65 64 20 72 6f 77 73 20 Estimated rows
ebe0: 69 6e 20 74 61 62 6c 65 20 2d 20 66 72 6f 6d 20 in table - from
ebf0: 73 71 6c 69 74 65 5f 73 74 61 74 31 20 74 61 62 sqlite_stat1 tab
ec00: 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 74 6e 75 6d le */. int tnum
ec10: 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
ec20: 52 6f 6f 74 20 42 54 72 65 65 20 6e 6f 64 65 20 Root BTree node
ec30: 66 6f 72 20 74 68 69 73 20 74 61 62 6c 65 20 28 for this table (
ec40: 73 65 65 20 6e 6f 74 65 20 61 62 6f 76 65 29 20 see note above)
ec50: 2a 2f 0a 20 20 69 31 36 20 69 50 4b 65 79 3b 20 */. i16 iPKey;
ec60: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 66 20 /* If
ec70: 6e 6f 74 20 6e 65 67 61 74 69 76 65 2c 20 75 73 not negative, us
ec80: 65 20 61 43 6f 6c 5b 69 50 4b 65 79 5d 20 61 73 e aCol[iPKey] as
ec90: 20 74 68 65 20 70 72 69 6d 61 72 79 20 6b 65 79 the primary key
eca0: 20 2a 2f 0a 20 20 69 31 36 20 6e 43 6f 6c 3b 20 */. i16 nCol;
ecb0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
ecc0: 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 mber of columns
ecd0: 69 6e 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f in this table */
ece0: 0a 20 20 75 31 36 20 6e 52 65 66 3b 20 20 20 20 . u16 nRef;
ecf0: 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
ed00: 72 20 6f 66 20 70 6f 69 6e 74 65 72 73 20 74 6f r of pointers to
ed10: 20 74 68 69 73 20 54 61 62 6c 65 20 2a 2f 0a 20 this Table */.
ed20: 20 4c 6f 67 45 73 74 20 73 7a 54 61 62 52 6f 77 LogEst szTabRow
ed30: 3b 20 20 20 20 20 2f 2a 20 45 73 74 69 6d 61 74 ; /* Estimat
ed40: 65 64 20 73 69 7a 65 20 6f 66 20 65 61 63 68 20 ed size of each
ed50: 74 61 62 6c 65 20 72 6f 77 20 69 6e 20 62 79 74 table row in byt
ed60: 65 73 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c es */.#ifdef SQL
ed70: 49 54 45 5f 45 4e 41 42 4c 45 5f 43 4f 53 54 4d ITE_ENABLE_COSTM
ed80: 55 4c 54 0a 20 20 4c 6f 67 45 73 74 20 63 6f 73 ULT. LogEst cos
ed90: 74 4d 75 6c 74 3b 20 20 20 20 20 2f 2a 20 43 6f tMult; /* Co
eda0: 73 74 20 6d 75 6c 74 69 70 6c 69 65 72 20 66 6f st multiplier fo
edb0: 72 20 75 73 69 6e 67 20 74 68 69 73 20 74 61 62 r using this tab
edc0: 6c 65 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 75 le */.#endif. u
edd0: 38 20 74 61 62 46 6c 61 67 73 3b 20 20 20 20 20 8 tabFlags;
ede0: 20 20 20 20 2f 2a 20 4d 61 73 6b 20 6f 66 20 54 /* Mask of T
edf0: 46 5f 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 F_* values */.
ee00: 75 38 20 6b 65 79 43 6f 6e 66 3b 20 20 20 20 20 u8 keyConf;
ee10: 20 20 20 20 20 2f 2a 20 57 68 61 74 20 74 6f 20 /* What to
ee20: 64 6f 20 69 6e 20 63 61 73 65 20 6f 66 20 75 6e do in case of un
ee30: 69 71 75 65 6e 65 73 73 20 63 6f 6e 66 6c 69 63 iqueness conflic
ee40: 74 20 6f 6e 20 69 50 4b 65 79 20 2a 2f 0a 23 69 t on iPKey */.#i
ee50: 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
ee60: 54 5f 41 4c 54 45 52 54 41 42 4c 45 0a 20 20 69 T_ALTERTABLE. i
ee70: 6e 74 20 61 64 64 43 6f 6c 4f 66 66 73 65 74 3b nt addColOffset;
ee80: 20 20 20 20 2f 2a 20 4f 66 66 73 65 74 20 69 6e /* Offset in
ee90: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 73 74 CREATE TABLE st
eea0: 6d 74 20 74 6f 20 61 64 64 20 61 20 6e 65 77 20 mt to add a new
eeb0: 63 6f 6c 75 6d 6e 20 2a 2f 0a 23 65 6e 64 69 66 column */.#endif
eec0: 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
eed0: 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c OMIT_VIRTUALTABL
eee0: 45 0a 20 20 69 6e 74 20 6e 4d 6f 64 75 6c 65 41 E. int nModuleA
eef0: 72 67 3b 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 rg; /* Numb
ef00: 65 72 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 20 er of arguments
ef10: 74 6f 20 74 68 65 20 6d 6f 64 75 6c 65 20 2a 2f to the module */
ef20: 0a 20 20 63 68 61 72 20 2a 2a 61 7a 4d 6f 64 75 . char **azModu
ef30: 6c 65 41 72 67 3b 20 20 2f 2a 20 54 65 78 74 20 leArg; /* Text
ef40: 6f 66 20 61 6c 6c 20 6d 6f 64 75 6c 65 20 61 72 of all module ar
ef50: 67 73 2e 20 5b 30 5d 20 69 73 20 6d 6f 64 75 6c gs. [0] is modul
ef60: 65 20 6e 61 6d 65 20 2a 2f 0a 20 20 56 54 61 62 e name */. VTab
ef70: 6c 65 20 2a 70 56 54 61 62 6c 65 3b 20 20 20 20 le *pVTable;
ef80: 20 2f 2a 20 4c 69 73 74 20 6f 66 20 56 54 61 62 /* List of VTab
ef90: 6c 65 20 6f 62 6a 65 63 74 73 2e 20 2a 2f 0a 23 le objects. */.#
efa0: 65 6e 64 69 66 0a 20 20 54 72 69 67 67 65 72 20 endif. Trigger
efb0: 2a 70 54 72 69 67 67 65 72 3b 20 20 20 2f 2a 20 *pTrigger; /*
efc0: 4c 69 73 74 20 6f 66 20 74 72 69 67 67 65 72 73 List of triggers
efd0: 20 73 74 6f 72 65 64 20 69 6e 20 70 53 63 68 65 stored in pSche
efe0: 6d 61 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a ma */. Schema *
eff0: 70 53 63 68 65 6d 61 3b 20 20 20 20 20 2f 2a 20 pSchema; /*
f000: 53 63 68 65 6d 61 20 74 68 61 74 20 63 6f 6e 74 Schema that cont
f010: 61 69 6e 73 20 74 68 69 73 20 74 61 62 6c 65 20 ains this table
f020: 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 4e 65 78 */. Table *pNex
f030: 74 5a 6f 6d 62 69 65 3b 20 20 2f 2a 20 4e 65 78 tZombie; /* Nex
f040: 74 20 6f 6e 20 74 68 65 20 50 61 72 73 65 2e 70 t on the Parse.p
f050: 5a 6f 6d 62 69 65 54 61 62 20 6c 69 73 74 20 2a ZombieTab list *
f060: 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f /.};../*.** Allo
f070: 77 65 64 20 76 61 6c 75 65 73 20 66 6f 72 20 54 wed values for T
f080: 61 62 6c 65 2e 74 61 62 46 6c 61 67 73 2e 0a 2a able.tabFlags..*
f090: 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 52 65 61 /.#define TF_Rea
f0a0: 64 6f 6e 6c 79 20 20 20 20 20 20 20 20 30 78 30 donly 0x0
f0b0: 31 20 20 20 20 2f 2a 20 52 65 61 64 2d 6f 6e 6c 1 /* Read-onl
f0c0: 79 20 73 79 73 74 65 6d 20 74 61 62 6c 65 20 2a y system table *
f0d0: 2f 0a 23 64 65 66 69 6e 65 20 54 46 5f 45 70 68 /.#define TF_Eph
f0e0: 65 6d 65 72 61 6c 20 20 20 20 20 20 20 30 78 30 emeral 0x0
f0f0: 32 20 20 20 20 2f 2a 20 41 6e 20 65 70 68 65 6d 2 /* An ephem
f100: 65 72 61 6c 20 74 61 62 6c 65 20 2a 2f 0a 23 64 eral table */.#d
f110: 65 66 69 6e 65 20 54 46 5f 48 61 73 50 72 69 6d efine TF_HasPrim
f120: 61 72 79 4b 65 79 20 20 20 30 78 30 34 20 20 20 aryKey 0x04
f130: 20 2f 2a 20 54 61 62 6c 65 20 68 61 73 20 61 20 /* Table has a
f140: 70 72 69 6d 61 72 79 20 6b 65 79 20 2a 2f 0a 23 primary key */.#
f150: 64 65 66 69 6e 65 20 54 46 5f 41 75 74 6f 69 6e define TF_Autoin
f160: 63 72 65 6d 65 6e 74 20 20 20 30 78 30 38 20 20 crement 0x08
f170: 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 70 72 69 /* Integer pri
f180: 6d 61 72 79 20 6b 65 79 20 69 73 20 61 75 74 6f mary key is auto
f190: 69 6e 63 72 65 6d 65 6e 74 20 2a 2f 0a 23 64 65 increment */.#de
f1a0: 66 69 6e 65 20 54 46 5f 56 69 72 74 75 61 6c 20 fine TF_Virtual
f1b0: 20 20 20 20 20 20 20 20 30 78 31 30 20 20 20 20 0x10
f1c0: 2f 2a 20 49 73 20 61 20 76 69 72 74 75 61 6c 20 /* Is a virtual
f1d0: 74 61 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 table */.#define
f1e0: 20 54 46 5f 57 69 74 68 6f 75 74 52 6f 77 69 64 TF_WithoutRowid
f1f0: 20 20 20 20 30 78 32 30 20 20 20 20 2f 2a 20 4e 0x20 /* N
f200: 6f 20 72 6f 77 69 64 20 75 73 65 64 2e 20 50 52 o rowid used. PR
f210: 49 4d 41 52 59 20 4b 45 59 20 69 73 20 74 68 65 IMARY KEY is the
f220: 20 6b 65 79 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 key */.../*.**
f230: 54 65 73 74 20 74 6f 20 73 65 65 20 77 68 65 74 Test to see whet
f240: 68 65 72 20 6f 72 20 6e 6f 74 20 61 20 74 61 62 her or not a tab
f250: 6c 65 20 69 73 20 61 20 76 69 72 74 75 61 6c 20 le is a virtual
f260: 74 61 62 6c 65 2e 20 20 54 68 69 73 20 69 73 0a table. This is.
f270: 2a 2a 20 64 6f 6e 65 20 61 73 20 61 20 6d 61 63 ** done as a mac
f280: 72 6f 20 73 6f 20 74 68 61 74 20 69 74 20 77 69 ro so that it wi
f290: 6c 6c 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 20 ll be optimized
f2a0: 6f 75 74 20 77 68 65 6e 20 76 69 72 74 75 61 6c out when virtual
f2b0: 0a 2a 2a 20 74 61 62 6c 65 20 73 75 70 70 6f 72 .** table suppor
f2c0: 74 20 69 73 20 6f 6d 69 74 74 65 64 20 66 72 6f t is omitted fro
f2d0: 6d 20 74 68 65 20 62 75 69 6c 64 2e 0a 2a 2f 0a m the build..*/.
f2e0: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
f2f0: 4d 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 MIT_VIRTUALTABLE
f300: 0a 23 20 20 64 65 66 69 6e 65 20 49 73 56 69 72 .# define IsVir
f310: 74 75 61 6c 28 58 29 20 20 20 20 20 20 28 28 28 tual(X) (((
f320: 58 29 2d 3e 74 61 62 46 6c 61 67 73 20 26 20 54 X)->tabFlags & T
f330: 46 5f 56 69 72 74 75 61 6c 29 21 3d 30 29 0a 23 F_Virtual)!=0).#
f340: 20 20 64 65 66 69 6e 65 20 49 73 48 69 64 64 65 define IsHidde
f350: 6e 43 6f 6c 75 6d 6e 28 58 29 20 28 28 28 58 29 nColumn(X) (((X)
f360: 2d 3e 63 6f 6c 46 6c 61 67 73 20 26 20 43 4f 4c ->colFlags & COL
f370: 46 4c 41 47 5f 48 49 44 44 45 4e 29 21 3d 30 29 FLAG_HIDDEN)!=0)
f380: 0a 23 65 6c 73 65 0a 23 20 20 64 65 66 69 6e 65 .#else.# define
f390: 20 49 73 56 69 72 74 75 61 6c 28 58 29 20 20 20 IsVirtual(X)
f3a0: 20 20 20 30 0a 23 20 20 64 65 66 69 6e 65 20 49 0.# define I
f3b0: 73 48 69 64 64 65 6e 43 6f 6c 75 6d 6e 28 58 29 sHiddenColumn(X)
f3c0: 20 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 44 6f 0.#endif../* Do
f3d0: 65 73 20 74 68 65 20 74 61 62 6c 65 20 68 61 76 es the table hav
f3e0: 65 20 61 20 72 6f 77 69 64 20 2a 2f 0a 23 64 65 e a rowid */.#de
f3f0: 66 69 6e 65 20 48 61 73 52 6f 77 69 64 28 58 29 fine HasRowid(X)
f400: 20 20 20 20 20 28 28 28 58 29 2d 3e 74 61 62 46 (((X)->tabF
f410: 6c 61 67 73 20 26 20 54 46 5f 57 69 74 68 6f 75 lags & TF_Withou
f420: 74 52 6f 77 69 64 29 3d 3d 30 29 0a 0a 2f 2a 0a tRowid)==0)../*.
f430: 2a 2a 20 45 61 63 68 20 66 6f 72 65 69 67 6e 20 ** Each foreign
f440: 6b 65 79 20 63 6f 6e 73 74 72 61 69 6e 74 20 69 key constraint i
f450: 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 s an instance of
f460: 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
f470: 74 72 75 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 tructure..**.**
f480: 41 20 66 6f 72 65 69 67 6e 20 6b 65 79 20 69 73 A foreign key is
f490: 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
f4a0: 20 74 77 6f 20 74 61 62 6c 65 73 2e 20 20 54 68 two tables. Th
f4b0: 65 20 22 66 72 6f 6d 22 20 74 61 62 6c 65 20 69 e "from" table i
f4c0: 73 0a 2a 2a 20 74 68 65 20 74 61 62 6c 65 20 74 s.** the table t
f4d0: 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 hat contains the
f4e0: 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 75 REFERENCES clau
f4f0: 73 65 20 74 68 61 74 20 63 72 65 61 74 65 73 20 se that creates
f500: 74 68 65 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b the foreign.** k
f510: 65 79 2e 20 20 54 68 65 20 22 74 6f 22 20 74 61 ey. The "to" ta
f520: 62 6c 65 20 69 73 20 74 68 65 20 74 61 62 6c 65 ble is the table
f530: 20 74 68 61 74 20 69 73 20 6e 61 6d 65 64 20 69 that is named i
f540: 6e 20 74 68 65 20 52 45 46 45 52 45 4e 43 45 53 n the REFERENCES
f550: 20 63 6c 61 75 73 65 2e 0a 2a 2a 20 43 6f 6e 73 clause..** Cons
f560: 69 64 65 72 20 74 68 69 73 20 65 78 61 6d 70 6c ider this exampl
f570: 65 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 43 52 45 e:.**.** CRE
f580: 41 54 45 20 54 41 42 4c 45 20 65 78 31 28 0a 2a ATE TABLE ex1(.*
f590: 2a 20 20 20 20 20 20 20 61 20 49 4e 54 45 47 45 * a INTEGE
f5a0: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 2a R PRIMARY KEY,.*
f5b0: 2a 20 20 20 20 20 20 20 62 20 49 4e 54 45 47 45 * b INTEGE
f5c0: 52 20 43 4f 4e 53 54 52 41 49 4e 54 20 66 6b 31 R CONSTRAINT fk1
f5d0: 20 52 45 46 45 52 45 4e 43 45 53 20 65 78 32 28 REFERENCES ex2(
f5e0: 78 29 0a 2a 2a 20 20 20 20 20 29 3b 0a 2a 2a 0a x).** );.**.
f5f0: 2a 2a 20 46 6f 72 20 66 6f 72 65 69 67 6e 20 6b ** For foreign k
f600: 65 79 20 22 66 6b 31 22 2c 20 74 68 65 20 66 72 ey "fk1", the fr
f610: 6f 6d 2d 74 61 62 6c 65 20 69 73 20 22 65 78 31 om-table is "ex1
f620: 22 20 61 6e 64 20 74 68 65 20 74 6f 2d 74 61 62 " and the to-tab
f630: 6c 65 20 69 73 20 22 65 78 32 22 2e 0a 2a 2a 20 le is "ex2"..**
f640: 45 71 75 69 76 61 6c 65 6e 74 20 6e 61 6d 65 73 Equivalent names
f650: 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 66 72 6f 6d :.**.** from
f660: 2d 74 61 62 6c 65 20 3d 3d 20 63 68 69 6c 64 2d -table == child-
f670: 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 20 74 table.** t
f680: 6f 2d 74 61 62 6c 65 20 3d 3d 20 70 61 72 65 6e o-table == paren
f690: 74 2d 74 61 62 6c 65 0a 2a 2a 0a 2a 2a 20 45 61 t-table.**.** Ea
f6a0: 63 68 20 52 45 46 45 52 45 4e 43 45 53 20 63 6c ch REFERENCES cl
f6b0: 61 75 73 65 20 67 65 6e 65 72 61 74 65 73 20 61 ause generates a
f6c0: 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
f6d0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 e following stru
f6e0: 63 74 75 72 65 0a 2a 2a 20 77 68 69 63 68 20 69 cture.** which i
f6f0: 73 20 61 74 74 61 63 68 65 64 20 74 6f 20 74 68 s attached to th
f700: 65 20 66 72 6f 6d 2d 74 61 62 6c 65 2e 20 20 54 e from-table. T
f710: 68 65 20 74 6f 2d 74 61 62 6c 65 20 6e 65 65 64 he to-table need
f720: 20 6e 6f 74 20 65 78 69 73 74 20 77 68 65 6e 0a not exist when.
f730: 2a 2a 20 74 68 65 20 66 72 6f 6d 2d 74 61 62 6c ** the from-tabl
f740: 65 20 69 73 20 63 72 65 61 74 65 64 2e 20 20 54 e is created. T
f750: 68 65 20 65 78 69 73 74 65 6e 63 65 20 6f 66 20 he existence of
f760: 74 68 65 20 74 6f 2d 74 61 62 6c 65 20 69 73 20 the to-table is
f770: 6e 6f 74 20 63 68 65 63 6b 65 64 2e 0a 2a 2a 0a not checked..**.
f780: 2a 2a 20 54 68 65 20 6c 69 73 74 20 6f 66 20 61 ** The list of a
f790: 6c 6c 20 70 61 72 65 6e 74 73 20 66 6f 72 20 63 ll parents for c
f7a0: 68 69 6c 64 20 54 61 62 6c 65 20 58 20 69 73 20 hild Table X is
f7b0: 68 65 6c 64 20 61 74 20 58 2e 70 46 4b 65 79 2e held at X.pFKey.
f7c0: 0a 2a 2a 0a 2a 2a 20 41 20 6c 69 73 74 20 6f 66 .**.** A list of
f7d0: 20 61 6c 6c 20 63 68 69 6c 64 72 65 6e 20 66 6f all children fo
f7e0: 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 64 20 r a table named
f7f0: 5a 20 28 77 68 69 63 68 20 6d 69 67 68 74 20 6e Z (which might n
f800: 6f 74 20 65 76 65 6e 20 65 78 69 73 74 29 0a 2a ot even exist).*
f810: 2a 20 69 73 20 68 65 6c 64 20 69 6e 20 53 63 68 * is held in Sch
f820: 65 6d 61 2e 66 6b 65 79 48 61 73 68 20 77 69 74 ema.fkeyHash wit
f830: 68 20 61 20 68 61 73 68 20 6b 65 79 20 6f 66 20 h a hash key of
f840: 5a 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 46 4b 65 Z..*/.struct FKe
f850: 79 20 7b 0a 20 20 54 61 62 6c 65 20 2a 70 46 72 y {. Table *pFr
f860: 6f 6d 3b 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 om; /* Table
f870: 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 containing the
f880: 52 45 46 45 52 45 4e 43 45 53 20 63 6c 61 75 73 REFERENCES claus
f890: 65 20 28 61 6b 61 3a 20 43 68 69 6c 64 29 20 2a e (aka: Child) *
f8a0: 2f 0a 20 20 46 4b 65 79 20 2a 70 4e 65 78 74 46 /. FKey *pNextF
f8b0: 72 6f 6d 3b 20 20 2f 2a 20 4e 65 78 74 20 46 4b rom; /* Next FK
f8c0: 65 79 20 77 69 74 68 20 74 68 65 20 73 61 6d 65 ey with the same
f8d0: 20 69 6e 20 70 46 72 6f 6d 2e 20 4e 65 78 74 20 in pFrom. Next
f8e0: 70 61 72 65 6e 74 20 6f 66 20 70 46 72 6f 6d 20 parent of pFrom
f8f0: 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 54 6f 3b 20 */. char *zTo;
f900: 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f /* Name o
f910: 66 20 74 61 62 6c 65 20 74 68 61 74 20 74 68 65 f table that the
f920: 20 6b 65 79 20 70 6f 69 6e 74 73 20 74 6f 20 28 key points to (
f930: 61 6b 61 3a 20 50 61 72 65 6e 74 29 20 2a 2f 0a aka: Parent) */.
f940: 20 20 46 4b 65 79 20 2a 70 4e 65 78 74 54 6f 3b FKey *pNextTo;
f950: 20 20 20 20 2f 2a 20 4e 65 78 74 20 77 69 74 68 /* Next with
f960: 20 74 68 65 20 73 61 6d 65 20 7a 54 6f 2e 20 4e the same zTo. N
f970: 65 78 74 20 63 68 69 6c 64 20 6f 66 20 7a 54 6f ext child of zTo
f980: 2e 20 2a 2f 0a 20 20 46 4b 65 79 20 2a 70 50 72 . */. FKey *pPr
f990: 65 76 54 6f 3b 20 20 20 20 2f 2a 20 50 72 65 76 evTo; /* Prev
f9a0: 69 6f 75 73 20 77 69 74 68 20 74 68 65 20 73 61 ious with the sa
f9b0: 6d 65 20 7a 54 6f 20 2a 2f 0a 20 20 69 6e 74 20 me zTo */. int
f9c0: 6e 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 2f 2a nCol; /*
f9d0: 20 4e 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d Number of colum
f9e0: 6e 73 20 69 6e 20 74 68 69 73 20 6b 65 79 20 2a ns in this key *
f9f0: 2f 0a 20 20 2f 2a 20 45 56 3a 20 52 2d 33 30 33 /. /* EV: R-303
fa00: 32 33 2d 32 31 39 31 37 20 2a 2f 0a 20 20 75 38 23-21917 */. u8
fa10: 20 69 73 44 65 66 65 72 72 65 64 3b 20 20 20 20 isDeferred;
fa20: 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 63 6f /* True if co
fa30: 6e 73 74 72 61 69 6e 74 20 63 68 65 63 6b 69 6e nstraint checkin
fa40: 67 20 69 73 20 64 65 66 65 72 72 65 64 20 74 69 g is deferred ti
fa50: 6c 6c 20 43 4f 4d 4d 49 54 20 2a 2f 0a 20 20 75 ll COMMIT */. u
fa60: 38 20 61 41 63 74 69 6f 6e 5b 32 5d 3b 20 20 20 8 aAction[2];
fa70: 20 20 20 20 20 2f 2a 20 4f 4e 20 44 45 4c 45 54 /* ON DELET
fa80: 45 20 61 6e 64 20 4f 4e 20 55 50 44 41 54 45 20 E and ON UPDATE
fa90: 61 63 74 69 6f 6e 73 2c 20 72 65 73 70 65 63 74 actions, respect
faa0: 69 76 65 6c 79 20 2a 2f 0a 20 20 54 72 69 67 67 ively */. Trigg
fab0: 65 72 20 2a 61 70 54 72 69 67 67 65 72 5b 32 5d er *apTrigger[2]
fac0: 3b 2f 2a 20 54 72 69 67 67 65 72 73 20 66 6f 72 ;/* Triggers for
fad0: 20 61 41 63 74 69 6f 6e 5b 5d 20 61 63 74 69 6f aAction[] actio
fae0: 6e 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 73 ns */. struct s
faf0: 43 6f 6c 4d 61 70 20 7b 20 20 20 20 20 20 2f 2a ColMap { /*
fb00: 20 4d 61 70 70 69 6e 67 20 6f 66 20 63 6f 6c 75 Mapping of colu
fb10: 6d 6e 73 20 69 6e 20 70 46 72 6f 6d 20 74 6f 20 mns in pFrom to
fb20: 63 6f 6c 75 6d 6e 73 20 69 6e 20 7a 54 6f 20 2a columns in zTo *
fb30: 2f 0a 20 20 20 20 69 6e 74 20 69 46 72 6f 6d 3b /. int iFrom;
fb40: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 49 /* I
fb50: 6e 64 65 78 20 6f 66 20 63 6f 6c 75 6d 6e 20 69 ndex of column i
fb60: 6e 20 70 46 72 6f 6d 20 2a 2f 0a 20 20 20 20 63 n pFrom */. c
fb70: 68 61 72 20 2a 7a 43 6f 6c 3b 20 20 20 20 20 20 har *zCol;
fb80: 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 /* Name of
fb90: 63 6f 6c 75 6d 6e 20 69 6e 20 7a 54 6f 2e 20 20 column in zTo.
fba0: 49 66 20 4e 55 4c 4c 20 75 73 65 20 50 52 49 4d If NULL use PRIM
fbb0: 41 52 59 20 4b 45 59 20 2a 2f 0a 20 20 7d 20 61 ARY KEY */. } a
fbc0: 43 6f 6c 5b 31 5d 3b 20 20 20 20 20 20 20 20 20 Col[1];
fbd0: 20 20 20 2f 2a 20 4f 6e 65 20 65 6e 74 72 79 20 /* One entry
fbe0: 66 6f 72 20 65 61 63 68 20 6f 66 20 6e 43 6f 6c for each of nCol
fbf0: 20 63 6f 6c 75 6d 6e 73 20 2a 2f 0a 7d 3b 0a 0a columns */.};..
fc00: 2f 2a 0a 2a 2a 20 53 51 4c 69 74 65 20 73 75 70 /*.** SQLite sup
fc10: 70 6f 72 74 73 20 6d 61 6e 79 20 64 69 66 66 65 ports many diffe
fc20: 72 65 6e 74 20 77 61 79 73 20 74 6f 20 72 65 73 rent ways to res
fc30: 6f 6c 76 65 20 61 20 63 6f 6e 73 74 72 61 69 6e olve a constrain
fc40: 74 0a 2a 2a 20 65 72 72 6f 72 2e 20 20 52 4f 4c t.** error. ROL
fc50: 4c 42 41 43 4b 20 70 72 6f 63 65 73 73 69 6e 67 LBACK processing
fc60: 20 6d 65 61 6e 73 20 74 68 61 74 20 61 20 63 6f means that a co
fc70: 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 74 69 nstraint violati
fc80: 6f 6e 0a 2a 2a 20 63 61 75 73 65 73 20 74 68 65 on.** causes the
fc90: 20 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 72 operation in pr
fca0: 6f 63 65 73 73 20 74 6f 20 66 61 69 6c 20 61 6e ocess to fail an
fcb0: 64 20 66 6f 72 20 74 68 65 20 63 75 72 72 65 6e d for the curren
fcc0: 74 20 74 72 61 6e 73 61 63 74 69 6f 6e 0a 2a 2a t transaction.**
fcd0: 20 74 6f 20 62 65 20 72 6f 6c 6c 65 64 20 62 61 to be rolled ba
fce0: 63 6b 2e 20 20 41 42 4f 52 54 20 70 72 6f 63 65 ck. ABORT proce
fcf0: 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 65 20 ssing means the
fd00: 6f 70 65 72 61 74 69 6f 6e 20 69 6e 20 70 72 6f operation in pro
fd10: 63 65 73 73 0a 2a 2a 20 66 61 69 6c 73 20 61 6e cess.** fails an
fd20: 64 20 61 6e 79 20 70 72 69 6f 72 20 63 68 61 6e d any prior chan
fd30: 67 65 73 20 66 72 6f 6d 20 74 68 61 74 20 6f 6e ges from that on
fd40: 65 20 6f 70 65 72 61 74 69 6f 6e 20 61 72 65 20 e operation are
fd50: 62 61 63 6b 65 64 20 6f 75 74 2c 0a 2a 2a 20 62 backed out,.** b
fd60: 75 74 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 ut the transacti
fd70: 6f 6e 20 69 73 20 6e 6f 74 20 72 6f 6c 6c 65 64 on is not rolled
fd80: 20 62 61 63 6b 2e 20 20 46 41 49 4c 20 70 72 6f back. FAIL pro
fd90: 63 65 73 73 69 6e 67 20 6d 65 61 6e 73 20 74 68 cessing means th
fda0: 61 74 0a 2a 2a 20 74 68 65 20 6f 70 65 72 61 74 at.** the operat
fdb0: 69 6f 6e 20 69 6e 20 70 72 6f 67 72 65 73 73 20 ion in progress
fdc0: 73 74 6f 70 73 20 61 6e 64 20 72 65 74 75 72 6e stops and return
fdd0: 73 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 65 2e s an error code.
fde0: 20 20 42 75 74 20 70 72 69 6f 72 0a 2a 2a 20 63 But prior.** c
fdf0: 68 61 6e 67 65 73 20 64 75 65 20 74 6f 20 74 68 hanges due to th
fe00: 65 20 73 61 6d 65 20 6f 70 65 72 61 74 69 6f 6e e same operation
fe10: 20 61 72 65 20 6e 6f 74 20 62 61 63 6b 65 64 20 are not backed
fe20: 6f 75 74 20 61 6e 64 20 6e 6f 20 72 6f 6c 6c 62 out and no rollb
fe30: 61 63 6b 0a 2a 2a 20 6f 63 63 75 72 73 2e 20 20 ack.** occurs.
fe40: 49 47 4e 4f 52 45 20 6d 65 61 6e 73 20 74 68 61 IGNORE means tha
fe50: 74 20 74 68 65 20 70 61 72 74 69 63 75 6c 61 72 t the particular
fe60: 20 72 6f 77 20 74 68 61 74 20 63 61 75 73 65 64 row that caused
fe70: 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 0a the constraint.
fe80: 2a 2a 20 65 72 72 6f 72 20 69 73 20 6e 6f 74 20 ** error is not
fe90: 69 6e 73 65 72 74 65 64 20 6f 72 20 75 70 64 61 inserted or upda
fea0: 74 65 64 2e 20 20 50 72 6f 63 65 73 73 69 6e 67 ted. Processing
feb0: 20 63 6f 6e 74 69 6e 75 65 73 20 61 6e 64 20 6e continues and n
fec0: 6f 20 65 72 72 6f 72 0a 2a 2a 20 69 73 20 72 65 o error.** is re
fed0: 74 75 72 6e 65 64 2e 20 20 52 45 50 4c 41 43 45 turned. REPLACE
fee0: 20 6d 65 61 6e 73 20 74 68 61 74 20 70 72 65 65 means that pree
fef0: 78 69 73 74 69 6e 67 20 64 61 74 61 62 61 73 65 xisting database
ff00: 20 72 6f 77 73 20 74 68 61 74 20 63 61 75 73 65 rows that cause
ff10: 64 0a 2a 2a 20 61 20 55 4e 49 51 55 45 20 63 6f d.** a UNIQUE co
ff20: 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 74 69 nstraint violati
ff30: 6f 6e 20 61 72 65 20 72 65 6d 6f 76 65 64 20 73 on are removed s
ff40: 6f 20 74 68 61 74 20 74 68 65 20 6e 65 77 20 69 o that the new i
ff50: 6e 73 65 72 74 20 6f 72 0a 2a 2a 20 75 70 64 61 nsert or.** upda
ff60: 74 65 20 63 61 6e 20 70 72 6f 63 65 65 64 2e 20 te can proceed.
ff70: 20 50 72 6f 63 65 73 73 69 6e 67 20 63 6f 6e 74 Processing cont
ff80: 69 6e 75 65 73 20 61 6e 64 20 6e 6f 20 65 72 72 inues and no err
ff90: 6f 72 20 69 73 20 72 65 70 6f 72 74 65 64 2e 0a or is reported..
ffa0: 2a 2a 0a 2a 2a 20 52 45 53 54 52 49 43 54 2c 20 **.** RESTRICT,
ffb0: 53 45 54 4e 55 4c 4c 2c 20 61 6e 64 20 43 41 53 SETNULL, and CAS
ffc0: 43 41 44 45 20 61 63 74 69 6f 6e 73 20 61 70 70 CADE actions app
ffd0: 6c 79 20 6f 6e 6c 79 20 74 6f 20 66 6f 72 65 69 ly only to forei
ffe0: 67 6e 20 6b 65 79 73 2e 0a 2a 2a 20 52 45 53 54 gn keys..** REST
fff0: 52 49 43 54 20 69 73 20 74 68 65 20 73 61 6d 65 RICT is the same
10000 20 61 73 20 41 42 4f 52 54 20 66 6f 72 20 49 4d as ABORT for IM
10010 4d 45 44 49 41 54 45 20 66 6f 72 65 69 67 6e 20 MEDIATE foreign
10020 6b 65 79 73 20 61 6e 64 20 74 68 65 0a 2a 2a 20 keys and the.**
10030 73 61 6d 65 20 61 73 20 52 4f 4c 4c 42 41 43 4b same as ROLLBACK
10040 20 66 6f 72 20 44 45 46 45 52 52 45 44 20 6b 65 for DEFERRED ke
10050 79 73 2e 20 20 53 45 54 4e 55 4c 4c 20 6d 65 61 ys. SETNULL mea
10060 6e 73 20 74 68 61 74 20 74 68 65 20 66 6f 72 65 ns that the fore
10070 69 67 6e 0a 2a 2a 20 6b 65 79 20 69 73 20 73 65 ign.** key is se
10080 74 20 74 6f 20 4e 55 4c 4c 2e 20 20 43 41 53 43 t to NULL. CASC
10090 41 44 45 20 6d 65 61 6e 73 20 74 68 61 74 20 61 ADE means that a
100a0 20 44 45 4c 45 54 45 20 6f 72 20 55 50 44 41 54 DELETE or UPDAT
100b0 45 20 6f 66 20 74 68 65 0a 2a 2a 20 72 65 66 65 E of the.** refe
100c0 72 65 6e 63 65 64 20 74 61 62 6c 65 20 72 6f 77 renced table row
100d0 20 69 73 20 70 72 6f 70 61 67 61 74 65 64 20 69 is propagated i
100e0 6e 74 6f 20 74 68 65 20 72 6f 77 20 74 68 61 74 nto the row that
100f0 20 68 6f 6c 64 73 20 74 68 65 0a 2a 2a 20 66 6f holds the.** fo
10100 72 65 69 67 6e 20 6b 65 79 2e 0a 2a 2a 20 0a 2a reign key..** .*
10110 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
10120 73 79 6d 62 6f 6c 69 63 20 76 61 6c 75 65 73 20 symbolic values
10130 61 72 65 20 75 73 65 64 20 74 6f 20 72 65 63 6f are used to reco
10140 72 64 20 77 68 69 63 68 20 74 79 70 65 0a 2a 2a rd which type.**
10150 20 6f 66 20 61 63 74 69 6f 6e 20 74 6f 20 74 61 of action to ta
10160 6b 65 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 4f ke..*/.#define O
10170 45 5f 4e 6f 6e 65 20 20 20 20 20 30 20 20 20 2f E_None 0 /
10180 2a 20 54 68 65 72 65 20 69 73 20 6e 6f 20 63 6f * There is no co
10190 6e 73 74 72 61 69 6e 74 20 74 6f 20 63 68 65 63 nstraint to chec
101a0 6b 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f k */.#define OE_
101b0 52 6f 6c 6c 62 61 63 6b 20 31 20 20 20 2f 2a 20 Rollback 1 /*
101c0 46 61 69 6c 20 74 68 65 20 6f 70 65 72 61 74 69 Fail the operati
101d0 6f 6e 20 61 6e 64 20 72 6f 6c 6c 62 61 63 6b 20 on and rollback
101e0 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 the transaction
101f0 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 41 62 */.#define OE_Ab
10200 6f 72 74 20 20 20 20 32 20 20 20 2f 2a 20 42 61 ort 2 /* Ba
10210 63 6b 20 6f 75 74 20 63 68 61 6e 67 65 73 20 62 ck out changes b
10220 75 74 20 64 6f 20 6e 6f 20 72 6f 6c 6c 62 61 63 ut do no rollbac
10230 6b 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 2a 2f k transaction */
10240 0a 23 64 65 66 69 6e 65 20 4f 45 5f 46 61 69 6c .#define OE_Fail
10250 20 20 20 20 20 33 20 20 20 2f 2a 20 53 74 6f 70 3 /* Stop
10260 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 62 the operation b
10270 75 74 20 6c 65 61 76 65 20 61 6c 6c 20 70 72 69 ut leave all pri
10280 6f 72 20 63 68 61 6e 67 65 73 20 2a 2f 0a 23 64 or changes */.#d
10290 65 66 69 6e 65 20 4f 45 5f 49 67 6e 6f 72 65 20 efine OE_Ignore
102a0 20 20 34 20 20 20 2f 2a 20 49 67 6e 6f 72 65 20 4 /* Ignore
102b0 74 68 65 20 65 72 72 6f 72 2e 20 44 6f 20 6e 6f the error. Do no
102c0 74 20 64 6f 20 74 68 65 20 49 4e 53 45 52 54 20 t do the INSERT
102d0 6f 72 20 55 50 44 41 54 45 20 2a 2f 0a 23 64 65 or UPDATE */.#de
102e0 66 69 6e 65 20 4f 45 5f 52 65 70 6c 61 63 65 20 fine OE_Replace
102f0 20 35 20 20 20 2f 2a 20 44 65 6c 65 74 65 20 65 5 /* Delete e
10300 78 69 73 74 69 6e 67 20 72 65 63 6f 72 64 2c 20 xisting record,
10310 74 68 65 6e 20 64 6f 20 49 4e 53 45 52 54 20 6f then do INSERT o
10320 72 20 55 50 44 41 54 45 20 2a 2f 0a 0a 23 64 65 r UPDATE */..#de
10330 66 69 6e 65 20 4f 45 5f 52 65 73 74 72 69 63 74 fine OE_Restrict
10340 20 36 20 20 20 2f 2a 20 4f 45 5f 41 62 6f 72 74 6 /* OE_Abort
10350 20 66 6f 72 20 49 4d 4d 45 44 49 41 54 45 2c 20 for IMMEDIATE,
10360 4f 45 5f 52 6f 6c 6c 62 61 63 6b 20 66 6f 72 20 OE_Rollback for
10370 44 45 46 45 52 52 45 44 20 2a 2f 0a 23 64 65 66 DEFERRED */.#def
10380 69 6e 65 20 4f 45 5f 53 65 74 4e 75 6c 6c 20 20 ine OE_SetNull
10390 37 20 20 20 2f 2a 20 53 65 74 20 74 68 65 20 66 7 /* Set the f
103a0 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c 75 65 oreign key value
103b0 20 74 6f 20 4e 55 4c 4c 20 2a 2f 0a 23 64 65 66 to NULL */.#def
103c0 69 6e 65 20 4f 45 5f 53 65 74 44 66 6c 74 20 20 ine OE_SetDflt
103d0 38 20 20 20 2f 2a 20 53 65 74 20 74 68 65 20 66 8 /* Set the f
103e0 6f 72 65 69 67 6e 20 6b 65 79 20 76 61 6c 75 65 oreign key value
103f0 20 74 6f 20 69 74 73 20 64 65 66 61 75 6c 74 20 to its default
10400 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 45 5f 43 61 */.#define OE_Ca
10410 73 63 61 64 65 20 20 39 20 20 20 2f 2a 20 43 61 scade 9 /* Ca
10420 73 63 61 64 65 20 74 68 65 20 63 68 61 6e 67 65 scade the change
10430 73 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 4f 45 s */..#define OE
10440 5f 44 65 66 61 75 6c 74 20 20 31 30 20 20 2f 2a _Default 10 /*
10450 20 44 6f 20 77 68 61 74 65 76 65 72 20 74 68 65 Do whatever the
10460 20 64 65 66 61 75 6c 74 20 61 63 74 69 6f 6e 20 default action
10470 69 73 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 41 6e is */.../*.** An
10480 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
10490 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
104a0 74 75 72 65 20 69 73 20 70 61 73 73 65 64 20 61 ture is passed a
104b0 73 20 74 68 65 20 66 69 72 73 74 0a 2a 2a 20 61 s the first.** a
104c0 72 67 75 6d 65 6e 74 20 74 6f 20 73 71 6c 69 74 rgument to sqlit
104d0 65 33 56 64 62 65 4b 65 79 43 6f 6d 70 61 72 65 e3VdbeKeyCompare
104e0 20 61 6e 64 20 69 73 20 75 73 65 64 20 74 6f 20 and is used to
104f0 63 6f 6e 74 72 6f 6c 20 74 68 65 20 0a 2a 2a 20 control the .**
10500 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 66 20 74 68 comparison of th
10510 65 20 74 77 6f 20 69 6e 64 65 78 20 6b 65 79 73 e two index keys
10520 2e 0a 2a 2a 0a 2a 2a 20 4e 6f 74 65 20 74 68 61 ..**.** Note tha
10530 74 20 61 53 6f 72 74 4f 72 64 65 72 5b 5d 20 61 t aSortOrder[] a
10540 6e 64 20 61 43 6f 6c 6c 5b 5d 20 68 61 76 65 20 nd aColl[] have
10550 6e 46 69 65 6c 64 2b 31 20 73 6c 6f 74 73 2e 20 nField+1 slots.
10560 20 54 68 65 72 65 0a 2a 2a 20 61 72 65 20 6e 46 There.** are nF
10570 69 65 6c 64 20 73 6c 6f 74 73 20 66 6f 72 20 74 ield slots for t
10580 68 65 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 61 6e he columns of an
10590 20 69 6e 64 65 78 20 74 68 65 6e 20 6f 6e 65 20 index then one
105a0 65 78 74 72 61 20 73 6c 6f 74 0a 2a 2a 20 66 6f extra slot.** fo
105b0 72 20 74 68 65 20 72 6f 77 69 64 20 61 74 20 74 r the rowid at t
105c0 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 he end..*/.struc
105d0 74 20 4b 65 79 49 6e 66 6f 20 7b 0a 20 20 75 33 t KeyInfo {. u3
105e0 32 20 6e 52 65 66 3b 20 20 20 20 20 20 20 20 20 2 nRef;
105f0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 72 /* Number of r
10600 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 68 69 eferences to thi
10610 73 20 4b 65 79 49 6e 66 6f 20 6f 62 6a 65 63 74 s KeyInfo object
10620 20 2a 2f 0a 20 20 75 38 20 65 6e 63 3b 20 20 20 */. u8 enc;
10630 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 65 78 /* Tex
10640 74 20 65 6e 63 6f 64 69 6e 67 20 2d 20 6f 6e 65 t encoding - one
10650 20 6f 66 20 74 68 65 20 53 51 4c 49 54 45 5f 55 of the SQLITE_U
10660 54 46 2a 20 76 61 6c 75 65 73 20 2a 2f 0a 20 20 TF* values */.
10670 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 20 20 20 u16 nField;
10680 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
10690 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 key columns in
106a0 74 68 65 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 the index */. u
106b0 31 36 20 6e 58 46 69 65 6c 64 3b 20 20 20 20 20 16 nXField;
106c0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
106d0 63 6f 6c 75 6d 6e 73 20 62 65 79 6f 6e 64 20 74 columns beyond t
106e0 68 65 20 6b 65 79 20 63 6f 6c 75 6d 6e 73 20 2a he key columns *
106f0 2f 0a 20 20 73 71 6c 69 74 65 33 20 2a 64 62 3b /. sqlite3 *db;
10700 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 64 /* The d
10710 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69 atabase connecti
10720 6f 6e 20 2a 2f 0a 20 20 75 38 20 2a 61 53 6f 72 on */. u8 *aSor
10730 74 4f 72 64 65 72 3b 20 20 20 20 20 2f 2a 20 53 tOrder; /* S
10740 6f 72 74 20 6f 72 64 65 72 20 66 6f 72 20 65 61 ort order for ea
10750 63 68 20 63 6f 6c 75 6d 6e 2e 20 2a 2f 0a 20 20 ch column. */.
10760 43 6f 6c 6c 53 65 71 20 2a 61 43 6f 6c 6c 5b 31 CollSeq *aColl[1
10770 5d 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6e 67 ]; /* Collating
10780 20 73 65 71 75 65 6e 63 65 20 66 6f 72 20 65 61 sequence for ea
10790 63 68 20 74 65 72 6d 20 6f 66 20 74 68 65 20 6b ch term of the k
107a0 65 79 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 ey */.};../*.**
107b0 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
107c0 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
107d0 75 63 74 75 72 65 20 68 6f 6c 64 73 20 69 6e 66 ucture holds inf
107e0 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 ormation about a
107f0 0a 2a 2a 20 73 69 6e 67 6c 65 20 69 6e 64 65 78 .** single index
10800 20 72 65 63 6f 72 64 20 74 68 61 74 20 68 61 73 record that has
10810 20 61 6c 72 65 61 64 79 20 62 65 65 6e 20 70 61 already been pa
10820 72 73 65 64 20 6f 75 74 20 69 6e 74 6f 20 69 6e rsed out into in
10830 64 69 76 69 64 75 61 6c 0a 2a 2a 20 76 61 6c 75 dividual.** valu
10840 65 73 2e 0a 2a 2a 0a 2a 2a 20 41 20 72 65 63 6f es..**.** A reco
10850 72 64 20 69 73 20 61 6e 20 6f 62 6a 65 63 74 20 rd is an object
10860 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e that contains on
10870 65 20 6f 72 20 6d 6f 72 65 20 66 69 65 6c 64 73 e or more fields
10880 20 6f 66 20 64 61 74 61 2e 0a 2a 2a 20 52 65 63 of data..** Rec
10890 6f 72 64 73 20 61 72 65 20 75 73 65 64 20 74 6f ords are used to
108a0 20 73 74 6f 72 65 20 74 68 65 20 63 6f 6e 74 65 store the conte
108b0 6e 74 20 6f 66 20 61 20 74 61 62 6c 65 20 72 6f nt of a table ro
108c0 77 20 61 6e 64 20 74 6f 20 73 74 6f 72 65 0a 2a w and to store.*
108d0 2a 20 74 68 65 20 6b 65 79 20 6f 66 20 61 6e 20 * the key of an
108e0 69 6e 64 65 78 2e 20 20 41 20 62 6c 6f 62 20 65 index. A blob e
108f0 6e 63 6f 64 69 6e 67 20 6f 66 20 61 20 72 65 63 ncoding of a rec
10900 6f 72 64 20 69 73 20 63 72 65 61 74 65 64 20 62 ord is created b
10910 79 0a 2a 2a 20 74 68 65 20 4f 50 5f 4d 61 6b 65 y.** the OP_Make
10920 52 65 63 6f 72 64 20 6f 70 63 6f 64 65 20 6f 66 Record opcode of
10930 20 74 68 65 20 56 44 42 45 20 61 6e 64 20 69 73 the VDBE and is
10940 20 64 69 73 61 73 73 65 6d 62 6c 65 64 20 62 79 disassembled by
10950 20 74 68 65 0a 2a 2a 20 4f 50 5f 43 6f 6c 75 6d the.** OP_Colum
10960 6e 20 6f 70 63 6f 64 65 2e 0a 2a 2a 0a 2a 2a 20 n opcode..**.**
10970 54 68 69 73 20 73 74 72 75 63 74 75 72 65 20 68 This structure h
10980 6f 6c 64 73 20 61 20 72 65 63 6f 72 64 20 74 68 olds a record th
10990 61 74 20 68 61 73 20 61 6c 72 65 61 64 79 20 62 at has already b
109a0 65 65 6e 20 64 69 73 61 73 73 65 6d 62 6c 65 64 een disassembled
109b0 0a 2a 2a 20 69 6e 74 6f 20 69 74 73 20 63 6f 6e .** into its con
109c0 73 74 69 74 75 65 6e 74 20 66 69 65 6c 64 73 2e stituent fields.
109d0 0a 2a 2a 0a 2a 2a 20 54 68 65 20 72 31 20 61 6e .**.** The r1 an
109e0 64 20 72 32 20 6d 65 6d 62 65 72 20 76 61 72 69 d r2 member vari
109f0 61 62 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 75 ables are only u
10a00 73 65 64 20 62 79 20 74 68 65 20 6f 70 74 69 6d sed by the optim
10a10 69 7a 65 64 20 63 6f 6d 70 61 72 69 73 6f 6e 0a ized comparison.
10a20 2a 2a 20 66 75 6e 63 74 69 6f 6e 73 20 76 64 62 ** functions vdb
10a30 65 52 65 63 6f 72 64 43 6f 6d 70 61 72 65 49 6e eRecordCompareIn
10a40 74 28 29 20 61 6e 64 20 76 64 62 65 52 65 63 6f t() and vdbeReco
10a50 72 64 43 6f 6d 70 61 72 65 53 74 72 69 6e 67 28 rdCompareString(
10a60 29 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 55 6e 70 )..*/.struct Unp
10a70 61 63 6b 65 64 52 65 63 6f 72 64 20 7b 0a 20 20 ackedRecord {.
10a80 4b 65 79 49 6e 66 6f 20 2a 70 4b 65 79 49 6e 66 KeyInfo *pKeyInf
10a90 6f 3b 20 20 2f 2a 20 43 6f 6c 6c 61 74 69 6f 6e o; /* Collation
10aa0 20 61 6e 64 20 73 6f 72 74 2d 6f 72 64 65 72 20 and sort-order
10ab0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 2a 2f 0a 20 information */.
10ac0 20 75 31 36 20 6e 46 69 65 6c 64 3b 20 20 20 20 u16 nField;
10ad0 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f /* Number o
10ae0 66 20 65 6e 74 72 69 65 73 20 69 6e 20 61 70 4d f entries in apM
10af0 65 6d 5b 5d 20 2a 2f 0a 20 20 69 38 20 64 65 66 em[] */. i8 def
10b00 61 75 6c 74 5f 72 63 3b 20 20 20 20 20 20 2f 2a ault_rc; /*
10b10 20 43 6f 6d 70 61 72 69 73 6f 6e 20 72 65 73 75 Comparison resu
10b20 6c 74 20 69 66 20 6b 65 79 73 20 61 72 65 20 65 lt if keys are e
10b30 71 75 61 6c 20 2a 2f 0a 20 20 75 38 20 69 73 43 qual */. u8 isC
10b40 6f 72 72 75 70 74 3b 20 20 20 20 20 20 20 2f 2a orrupt; /*
10b50 20 43 6f 72 72 75 70 74 69 6f 6e 20 64 65 74 65 Corruption dete
10b60 63 74 65 64 20 62 79 20 78 52 65 63 6f 72 64 43 cted by xRecordC
10b70 6f 6d 70 61 72 65 28 29 20 2a 2f 0a 20 20 4d 65 ompare() */. Me
10b80 6d 20 2a 61 4d 65 6d 3b 20 20 20 20 20 20 20 20 m *aMem;
10b90 20 20 2f 2a 20 56 61 6c 75 65 73 20 2a 2f 0a 20 /* Values */.
10ba0 20 69 6e 74 20 72 31 3b 20 20 20 20 20 20 20 20 int r1;
10bb0 20 20 20 20 20 2f 2a 20 56 61 6c 75 65 20 74 6f /* Value to
10bc0 20 72 65 74 75 72 6e 20 69 66 20 28 6c 68 73 20 return if (lhs
10bd0 3e 20 72 68 73 29 20 2a 2f 0a 20 20 69 6e 74 20 > rhs) */. int
10be0 72 32 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 r2;
10bf0 2f 2a 20 56 61 6c 75 65 20 74 6f 20 72 65 74 75 /* Value to retu
10c00 72 6e 20 69 66 20 28 72 68 73 20 3c 20 6c 68 73 rn if (rhs < lhs
10c10 29 20 2a 2f 0a 7d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 ) */.};.../*.**
10c20 45 61 63 68 20 53 51 4c 20 69 6e 64 65 78 20 69 Each SQL index i
10c30 73 20 72 65 70 72 65 73 65 6e 74 65 64 20 69 6e s represented in
10c40 20 6d 65 6d 6f 72 79 20 62 79 20 61 6e 0a 2a 2a memory by an.**
10c50 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 65 instance of the
10c60 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
10c70 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 ture..**.** The
10c80 63 6f 6c 75 6d 6e 73 20 6f 66 20 74 68 65 20 74 columns of the t
10c90 61 62 6c 65 20 74 68 61 74 20 61 72 65 20 74 6f able that are to
10ca0 20 62 65 20 69 6e 64 65 78 65 64 20 61 72 65 20 be indexed are
10cb0 64 65 73 63 72 69 62 65 64 0a 2a 2a 20 62 79 20 described.** by
10cc0 74 68 65 20 61 69 43 6f 6c 75 6d 6e 5b 5d 20 66 the aiColumn[] f
10cd0 69 65 6c 64 20 6f 66 20 74 68 69 73 20 73 74 72 ield of this str
10ce0 75 63 74 75 72 65 2e 20 20 46 6f 72 20 65 78 61 ucture. For exa
10cf0 6d 70 6c 65 2c 20 73 75 70 70 6f 73 65 0a 2a 2a mple, suppose.**
10d00 20 77 65 20 68 61 76 65 20 74 68 65 20 66 6f 6c we have the fol
10d10 6c 6f 77 69 6e 67 20 74 61 62 6c 65 20 61 6e 64 lowing table and
10d20 20 69 6e 64 65 78 3a 0a 2a 2a 0a 2a 2a 20 20 20 index:.**.**
10d30 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 45 CREATE TABLE E
10d40 78 31 28 63 31 20 69 6e 74 2c 20 63 32 20 69 6e x1(c1 int, c2 in
10d50 74 2c 20 63 33 20 74 65 78 74 29 3b 0a 2a 2a 20 t, c3 text);.**
10d60 20 20 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 CREATE INDEX
10d70 20 45 78 32 20 4f 4e 20 45 78 31 28 63 33 2c 63 Ex2 ON Ex1(c3,c
10d80 31 29 3b 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 65 1);.**.** In the
10d90 20 54 61 62 6c 65 20 73 74 72 75 63 74 75 72 65 Table structure
10da0 20 64 65 73 63 72 69 62 69 6e 67 20 45 78 31 2c describing Ex1,
10db0 20 6e 43 6f 6c 3d 3d 33 20 62 65 63 61 75 73 65 nCol==3 because
10dc0 20 74 68 65 72 65 20 61 72 65 0a 2a 2a 20 74 68 there are.** th
10dd0 72 65 65 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 ree columns in t
10de0 68 65 20 74 61 62 6c 65 2e 20 20 49 6e 20 74 68 he table. In th
10df0 65 20 49 6e 64 65 78 20 73 74 72 75 63 74 75 72 e Index structur
10e00 65 20 64 65 73 63 72 69 62 69 6e 67 0a 2a 2a 20 e describing.**
10e10 45 78 32 2c 20 6e 43 6f 6c 75 6d 6e 3d 3d 32 20 Ex2, nColumn==2
10e20 73 69 6e 63 65 20 32 20 6f 66 20 74 68 65 20 33 since 2 of the 3
10e30 20 63 6f 6c 75 6d 6e 73 20 6f 66 20 45 78 31 20 columns of Ex1
10e40 61 72 65 20 69 6e 64 65 78 65 64 2e 0a 2a 2a 20 are indexed..**
10e50 54 68 65 20 76 61 6c 75 65 20 6f 66 20 61 69 43 The value of aiC
10e60 6f 6c 75 6d 6e 20 69 73 20 7b 32 2c 20 30 7d 2e olumn is {2, 0}.
10e70 20 20 61 69 43 6f 6c 75 6d 6e 5b 30 5d 3d 3d 32 aiColumn[0]==2
10e80 20 62 65 63 61 75 73 65 20 74 68 65 20 0a 2a 2a because the .**
10e90 20 66 69 72 73 74 20 63 6f 6c 75 6d 6e 20 74 6f first column to
10ea0 20 62 65 20 69 6e 64 65 78 65 64 20 28 63 33 29 be indexed (c3)
10eb0 20 68 61 73 20 61 6e 20 69 6e 64 65 78 20 6f 66 has an index of
10ec0 20 32 20 69 6e 20 45 78 31 2e 61 43 6f 6c 5b 5d 2 in Ex1.aCol[]
10ed0 2e 0a 2a 2a 20 54 68 65 20 73 65 63 6f 6e 64 20 ..** The second
10ee0 63 6f 6c 75 6d 6e 20 74 6f 20 62 65 20 69 6e 64 column to be ind
10ef0 65 78 65 64 20 28 63 31 29 20 68 61 73 20 61 6e exed (c1) has an
10f00 20 69 6e 64 65 78 20 6f 66 20 30 20 69 6e 0a 2a index of 0 in.*
10f10 2a 20 45 78 31 2e 61 43 6f 6c 5b 5d 2c 20 68 65 * Ex1.aCol[], he
10f20 6e 63 65 20 45 78 32 2e 61 69 43 6f 6c 75 6d 6e nce Ex2.aiColumn
10f30 5b 31 5d 3d 3d 30 2e 0a 2a 2a 0a 2a 2a 20 54 68 [1]==0..**.** Th
10f40 65 20 49 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 e Index.onError
10f50 66 69 65 6c 64 20 64 65 74 65 72 6d 69 6e 65 73 field determines
10f60 20 77 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 whether or not
10f70 74 68 65 20 69 6e 64 65 78 65 64 20 63 6f 6c 75 the indexed colu
10f80 6d 6e 73 0a 2a 2a 20 6d 75 73 74 20 62 65 20 75 mns.** must be u
10f90 6e 69 71 75 65 20 61 6e 64 20 77 68 61 74 20 74 nique and what t
10fa0 6f 20 64 6f 20 69 66 20 74 68 65 79 20 61 72 65 o do if they are
10fb0 20 6e 6f 74 2e 20 20 57 68 65 6e 20 49 6e 64 65 not. When Inde
10fc0 78 2e 6f 6e 45 72 72 6f 72 3d 4f 45 5f 4e 6f 6e x.onError=OE_Non
10fd0 65 2c 0a 2a 2a 20 69 74 20 6d 65 61 6e 73 20 74 e,.** it means t
10fe0 68 69 73 20 69 73 20 6e 6f 74 20 61 20 75 6e 69 his is not a uni
10ff0 71 75 65 20 69 6e 64 65 78 2e 20 20 4f 74 68 65 que index. Othe
11000 72 77 69 73 65 20 69 74 20 69 73 20 61 20 75 6e rwise it is a un
11010 69 71 75 65 20 69 6e 64 65 78 0a 2a 2a 20 61 6e ique index.** an
11020 64 20 74 68 65 20 76 61 6c 75 65 20 6f 66 20 49 d the value of I
11030 6e 64 65 78 2e 6f 6e 45 72 72 6f 72 20 69 6e 64 ndex.onError ind
11040 69 63 61 74 65 20 74 68 65 20 77 68 69 63 68 20 icate the which
11050 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f 6c 75 74 conflict resolut
11060 69 6f 6e 20 0a 2a 2a 20 61 6c 67 6f 72 69 74 68 ion .** algorith
11070 6d 20 74 6f 20 65 6d 70 6c 6f 79 20 77 68 65 6e m to employ when
11080 65 76 65 72 20 61 6e 20 61 74 74 65 6d 70 74 20 ever an attempt
11090 69 73 20 6d 61 64 65 20 74 6f 20 69 6e 73 65 72 is made to inser
110a0 74 20 61 20 6e 6f 6e 2d 75 6e 69 71 75 65 0a 2a t a non-unique.*
110b0 2a 20 65 6c 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 * element..*/.st
110c0 72 75 63 74 20 49 6e 64 65 78 20 7b 0a 20 20 63 ruct Index {. c
110d0 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 har *zName;
110e0 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 /* Name
110f0 6f 66 20 74 68 69 73 20 69 6e 64 65 78 20 2a 2f of this index */
11100 0a 20 20 69 31 36 20 2a 61 69 43 6f 6c 75 6d 6e . i16 *aiColumn
11110 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 ; /* W
11120 68 69 63 68 20 63 6f 6c 75 6d 6e 73 20 61 72 65 hich columns are
11130 20 75 73 65 64 20 62 79 20 74 68 69 73 20 69 6e used by this in
11140 64 65 78 2e 20 20 31 73 74 20 69 73 20 30 20 2a dex. 1st is 0 *
11150 2f 0a 20 20 4c 6f 67 45 73 74 20 2a 61 69 52 6f /. LogEst *aiRo
11160 77 4c 6f 67 45 73 74 3b 20 20 20 20 20 2f 2a 20 wLogEst; /*
11170 46 72 6f 6d 20 41 4e 41 4c 59 5a 45 3a 20 45 73 From ANALYZE: Es
11180 74 2e 20 72 6f 77 73 20 73 65 6c 65 63 74 65 64 t. rows selected
11190 20 62 79 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 by each column
111a0 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 54 61 62 */. Table *pTab
111b0 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a le; /*
111c0 20 54 68 65 20 53 51 4c 20 74 61 62 6c 65 20 62 The SQL table b
111d0 65 69 6e 67 20 69 6e 64 65 78 65 64 20 2a 2f 0a eing indexed */.
111e0 20 20 63 68 61 72 20 2a 7a 43 6f 6c 41 66 66 3b char *zColAff;
111f0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 74 /* St
11200 72 69 6e 67 20 64 65 66 69 6e 69 6e 67 20 74 68 ring defining th
11210 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 65 61 e affinity of ea
11220 63 68 20 63 6f 6c 75 6d 6e 20 2a 2f 0a 20 20 49 ch column */. I
11230 6e 64 65 78 20 2a 70 4e 65 78 74 3b 20 20 20 20 ndex *pNext;
11240 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6e /* The n
11250 65 78 74 20 69 6e 64 65 78 20 61 73 73 6f 63 69 ext index associ
11260 61 74 65 64 20 77 69 74 68 20 74 68 65 20 73 61 ated with the sa
11270 6d 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 53 63 me table */. Sc
11280 68 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 hema *pSchema;
11290 20 20 20 20 20 20 20 2f 2a 20 53 63 68 65 6d 61 /* Schema
112a0 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 69 73 containing this
112b0 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 38 20 2a index */. u8 *
112c0 61 53 6f 72 74 4f 72 64 65 72 3b 20 20 20 20 20 aSortOrder;
112d0 20 20 20 20 20 2f 2a 20 66 6f 72 20 65 61 63 68 /* for each
112e0 20 63 6f 6c 75 6d 6e 3a 20 54 72 75 65 3d 3d 44 column: True==D
112f0 45 53 43 2c 20 46 61 6c 73 65 3d 3d 41 53 43 20 ESC, False==ASC
11300 2a 2f 0a 20 20 63 68 61 72 20 2a 2a 61 7a 43 6f */. char **azCo
11310 6c 6c 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a ll; /*
11320 20 41 72 72 61 79 20 6f 66 20 63 6f 6c 6c 61 74 Array of collat
11330 69 6f 6e 20 73 65 71 75 65 6e 63 65 20 6e 61 6d ion sequence nam
11340 65 73 20 66 6f 72 20 69 6e 64 65 78 20 2a 2f 0a es for index */.
11350 20 20 45 78 70 72 20 2a 70 50 61 72 74 49 64 78 Expr *pPartIdx
11360 57 68 65 72 65 3b 20 20 20 20 20 2f 2a 20 57 48 Where; /* WH
11370 45 52 45 20 63 6c 61 75 73 65 20 66 6f 72 20 70 ERE clause for p
11380 61 72 74 69 61 6c 20 69 6e 64 69 63 65 73 20 2a artial indices *
11390 2f 0a 20 20 4b 65 79 49 6e 66 6f 20 2a 70 4b 65 /. KeyInfo *pKe
113a0 79 49 6e 66 6f 3b 20 20 20 20 20 20 20 2f 2a 20 yInfo; /*
113b0 41 20 4b 65 79 49 6e 66 6f 20 6f 62 6a 65 63 74 A KeyInfo object
113c0 20 73 75 69 74 61 62 6c 65 20 66 6f 72 20 74 68 suitable for th
113d0 69 73 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e is index */. in
113e0 74 20 74 6e 75 6d 3b 20 20 20 20 20 20 20 20 20 t tnum;
113f0 20 20 20 20 20 20 20 2f 2a 20 44 42 20 50 61 67 /* DB Pag
11400 65 20 63 6f 6e 74 61 69 6e 69 6e 67 20 72 6f 6f e containing roo
11410 74 20 6f 66 20 74 68 69 73 20 69 6e 64 65 78 20 t of this index
11420 2a 2f 0a 20 20 4c 6f 67 45 73 74 20 73 7a 49 64 */. LogEst szId
11430 78 52 6f 77 3b 20 20 20 20 20 20 20 20 20 2f 2a xRow; /*
11440 20 45 73 74 69 6d 61 74 65 64 20 61 76 65 72 61 Estimated avera
11450 67 65 20 72 6f 77 20 73 69 7a 65 20 69 6e 20 62 ge row size in b
11460 79 74 65 73 20 2a 2f 0a 20 20 75 31 36 20 6e 4b ytes */. u16 nK
11470 65 79 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 20 eyCol;
11480 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
11490 63 6f 6c 75 6d 6e 73 20 66 6f 72 6d 69 6e 67 20 columns forming
114a0 74 68 65 20 6b 65 79 20 2a 2f 0a 20 20 75 31 36 the key */. u16
114b0 20 6e 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 nColumn;
114c0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
114d0 6f 66 20 63 6f 6c 75 6d 6e 73 20 73 74 6f 72 65 of columns store
114e0 64 20 69 6e 20 74 68 65 20 69 6e 64 65 78 20 2a d in the index *
114f0 2f 0a 20 20 75 38 20 6f 6e 45 72 72 6f 72 3b 20 /. u8 onError;
11500 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
11510 4f 45 5f 41 62 6f 72 74 2c 20 4f 45 5f 49 67 6e OE_Abort, OE_Ign
11520 6f 72 65 2c 20 4f 45 5f 52 65 70 6c 61 63 65 2c ore, OE_Replace,
11530 20 6f 72 20 4f 45 5f 4e 6f 6e 65 20 2a 2f 0a 20 or OE_None */.
11540 20 75 6e 73 69 67 6e 65 64 20 69 64 78 54 79 70 unsigned idxTyp
11550 65 3a 32 3b 20 20 20 20 20 20 2f 2a 20 31 3d 3d e:2; /* 1==
11560 55 4e 49 51 55 45 2c 20 32 3d 3d 50 52 49 4d 41 UNIQUE, 2==PRIMA
11570 52 59 20 4b 45 59 2c 20 30 3d 3d 43 52 45 41 54 RY KEY, 0==CREAT
11580 45 20 49 4e 44 45 58 20 2a 2f 0a 20 20 75 6e 73 E INDEX */. uns
11590 69 67 6e 65 64 20 62 55 6e 6f 72 64 65 72 65 64 igned bUnordered
115a0 3a 31 3b 20 20 20 2f 2a 20 55 73 65 20 74 68 69 :1; /* Use thi
115b0 73 20 69 6e 64 65 78 20 66 6f 72 20 3d 3d 20 6f s index for == o
115c0 72 20 49 4e 20 71 75 65 72 69 65 73 20 6f 6e 6c r IN queries onl
115d0 79 20 2a 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 y */. unsigned
115e0 75 6e 69 71 4e 6f 74 4e 75 6c 6c 3a 31 3b 20 20 uniqNotNull:1;
115f0 2f 2a 20 54 72 75 65 20 69 66 20 55 4e 49 51 55 /* True if UNIQU
11600 45 20 61 6e 64 20 4e 4f 54 20 4e 55 4c 4c 20 66 E and NOT NULL f
11610 6f 72 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 2a or all columns *
11620 2f 0a 20 20 75 6e 73 69 67 6e 65 64 20 69 73 52 /. unsigned isR
11630 65 73 69 7a 65 64 3a 31 3b 20 20 20 20 2f 2a 20 esized:1; /*
11640 54 72 75 65 20 69 66 20 72 65 73 69 7a 65 49 6e True if resizeIn
11650 64 65 78 4f 62 6a 65 63 74 28 29 20 68 61 73 20 dexObject() has
11660 62 65 65 6e 20 63 61 6c 6c 65 64 20 2a 2f 0a 20 been called */.
11670 20 75 6e 73 69 67 6e 65 64 20 69 73 43 6f 76 65 unsigned isCove
11680 72 69 6e 67 3a 31 3b 20 20 20 2f 2a 20 54 72 75 ring:1; /* Tru
11690 65 20 69 66 20 74 68 69 73 20 69 73 20 61 20 63 e if this is a c
116a0 6f 76 65 72 69 6e 67 20 69 6e 64 65 78 20 2a 2f overing index */
116b0 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 .#ifdef SQLITE_E
116c0 4e 41 42 4c 45 5f 53 54 41 54 33 5f 4f 52 5f 53 NABLE_STAT3_OR_S
116d0 54 41 54 34 0a 20 20 69 6e 74 20 6e 53 61 6d 70 TAT4. int nSamp
116e0 6c 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 le;
116f0 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 6c 65 /* Number of ele
11700 6d 65 6e 74 73 20 69 6e 20 61 53 61 6d 70 6c 65 ments in aSample
11710 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 53 61 6d [] */. int nSam
11720 70 6c 65 43 6f 6c 3b 20 20 20 20 20 20 20 20 20 pleCol;
11730 20 2f 2a 20 53 69 7a 65 20 6f 66 20 49 6e 64 65 /* Size of Inde
11740 78 53 61 6d 70 6c 65 2e 61 6e 45 71 5b 5d 20 61 xSample.anEq[] a
11750 6e 64 20 73 6f 20 6f 6e 20 2a 2f 0a 20 20 74 52 nd so on */. tR
11760 6f 77 63 6e 74 20 2a 61 41 76 67 45 71 3b 20 20 owcnt *aAvgEq;
11770 20 20 20 20 20 20 20 2f 2a 20 41 76 65 72 61 67 /* Averag
11780 65 20 6e 45 71 20 76 61 6c 75 65 73 20 66 6f 72 e nEq values for
11790 20 6b 65 79 73 20 6e 6f 74 20 69 6e 20 61 53 61 keys not in aSa
117a0 6d 70 6c 65 20 2a 2f 0a 20 20 49 6e 64 65 78 53 mple */. IndexS
117b0 61 6d 70 6c 65 20 2a 61 53 61 6d 70 6c 65 3b 20 ample *aSample;
117c0 20 20 20 2f 2a 20 53 61 6d 70 6c 65 73 20 6f 66 /* Samples of
117d0 20 74 68 65 20 6c 65 66 74 2d 6d 6f 73 74 20 6b the left-most k
117e0 65 79 20 2a 2f 0a 23 65 6e 64 69 66 0a 7d 3b 0a ey */.#endif.};.
117f0 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 76 ./*.** Allowed v
11800 61 6c 75 65 73 20 66 6f 72 20 49 6e 64 65 78 2e alues for Index.
11810 69 64 78 54 79 70 65 0a 2a 2f 0a 23 64 65 66 69 idxType.*/.#defi
11820 6e 65 20 53 51 4c 49 54 45 5f 49 44 58 54 59 50 ne SQLITE_IDXTYP
11830 45 5f 41 50 50 44 45 46 20 20 20 20 20 20 30 20 E_APPDEF 0
11840 20 20 2f 2a 20 43 72 65 61 74 65 64 20 75 73 69 /* Created usi
11850 6e 67 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 ng CREATE INDEX
11860 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 */.#define SQLIT
11870 45 5f 49 44 58 54 59 50 45 5f 55 4e 49 51 55 45 E_IDXTYPE_UNIQUE
11880 20 20 20 20 20 20 31 20 20 20 2f 2a 20 49 6d 70 1 /* Imp
11890 6c 65 6d 65 6e 74 73 20 61 20 55 4e 49 51 55 45 lements a UNIQUE
118a0 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a 23 constraint */.#
118b0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 49 44 define SQLITE_ID
118c0 58 54 59 50 45 5f 50 52 49 4d 41 52 59 4b 45 59 XTYPE_PRIMARYKEY
118d0 20 20 32 20 20 20 2f 2a 20 49 73 20 74 68 65 20 2 /* Is the
118e0 50 52 49 4d 41 52 59 20 4b 45 59 20 66 6f 72 20 PRIMARY KEY for
118f0 74 68 65 20 74 61 62 6c 65 20 2a 2f 0a 0a 2f 2a the table */../*
11900 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 20 Return true if
11910 69 6e 64 65 78 20 58 20 69 73 20 61 20 50 52 49 index X is a PRI
11920 4d 41 52 59 20 4b 45 59 20 69 6e 64 65 78 20 2a MARY KEY index *
11930 2f 0a 23 64 65 66 69 6e 65 20 49 73 50 72 69 6d /.#define IsPrim
11940 61 72 79 4b 65 79 49 6e 64 65 78 28 58 29 20 20 aryKeyIndex(X)
11950 28 28 58 29 2d 3e 69 64 78 54 79 70 65 3d 3d 53 ((X)->idxType==S
11960 51 4c 49 54 45 5f 49 44 58 54 59 50 45 5f 50 52 QLITE_IDXTYPE_PR
11970 49 4d 41 52 59 4b 45 59 29 0a 0a 2f 2a 20 52 65 IMARYKEY)../* Re
11980 74 75 72 6e 20 74 72 75 65 20 69 66 20 69 6e 64 turn true if ind
11990 65 78 20 58 20 69 73 20 61 20 55 4e 49 51 55 45 ex X is a UNIQUE
119a0 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e index */.#defin
119b0 65 20 49 73 55 6e 69 71 75 65 49 6e 64 65 78 28 e IsUniqueIndex(
119c0 58 29 20 20 20 20 20 20 28 28 58 29 2d 3e 6f 6e X) ((X)->on
119d0 45 72 72 6f 72 21 3d 4f 45 5f 4e 6f 6e 65 29 0a Error!=OE_None).
119e0 0a 2f 2a 0a 2a 2a 20 45 61 63 68 20 73 61 6d 70 ./*.** Each samp
119f0 6c 65 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 le stored in the
11a00 20 73 71 6c 69 74 65 5f 73 74 61 74 33 20 74 61 sqlite_stat3 ta
11a10 62 6c 65 20 69 73 20 72 65 70 72 65 73 65 6e 74 ble is represent
11a20 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20 0a 2a 2a ed in memory .**
11a30 20 75 73 69 6e 67 20 61 20 73 74 72 75 63 74 75 using a structu
11a40 72 65 20 6f 66 20 74 68 69 73 20 74 79 70 65 2e re of this type.
11a50 20 20 53 65 65 20 64 6f 63 75 6d 65 6e 74 61 74 See documentat
11a60 69 6f 6e 20 61 74 20 74 68 65 20 74 6f 70 20 6f ion at the top o
11a70 66 20 74 68 65 0a 2a 2a 20 61 6e 61 6c 79 7a 65 f the.** analyze
11a80 2e 63 20 73 6f 75 72 63 65 20 66 69 6c 65 20 66 .c source file f
11a90 6f 72 20 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e or additional in
11aa0 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 formation..*/.st
11ab0 72 75 63 74 20 49 6e 64 65 78 53 61 6d 70 6c 65 ruct IndexSample
11ac0 20 7b 0a 20 20 76 6f 69 64 20 2a 70 3b 20 20 20 {. void *p;
11ad0 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 /* Pointe
11ae0 72 20 74 6f 20 73 61 6d 70 6c 65 64 20 72 65 63 r to sampled rec
11af0 6f 72 64 20 2a 2f 0a 20 20 69 6e 74 20 6e 3b 20 ord */. int n;
11b00 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 69 /* Si
11b10 7a 65 20 6f 66 20 72 65 63 6f 72 64 20 69 6e 20 ze of record in
11b20 62 79 74 65 73 20 2a 2f 0a 20 20 74 52 6f 77 63 bytes */. tRowc
11b30 6e 74 20 2a 61 6e 45 71 3b 20 20 20 20 2f 2a 20 nt *anEq; /*
11b40 45 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 72 Est. number of r
11b50 6f 77 73 20 77 68 65 72 65 20 74 68 65 20 6b 65 ows where the ke
11b60 79 20 65 71 75 61 6c 73 20 74 68 69 73 20 73 61 y equals this sa
11b70 6d 70 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 63 6e mple */. tRowcn
11b80 74 20 2a 61 6e 4c 74 3b 20 20 20 20 2f 2a 20 45 t *anLt; /* E
11b90 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f st. number of ro
11ba0 77 73 20 77 68 65 72 65 20 6b 65 79 20 69 73 20 ws where key is
11bb0 6c 65 73 73 20 74 68 61 6e 20 74 68 69 73 20 73 less than this s
11bc0 61 6d 70 6c 65 20 2a 2f 0a 20 20 74 52 6f 77 63 ample */. tRowc
11bd0 6e 74 20 2a 61 6e 44 4c 74 3b 20 20 20 2f 2a 20 nt *anDLt; /*
11be0 45 73 74 2e 20 6e 75 6d 62 65 72 20 6f 66 20 64 Est. number of d
11bf0 69 73 74 69 6e 63 74 20 6b 65 79 73 20 6c 65 73 istinct keys les
11c00 73 20 74 68 61 6e 20 74 68 69 73 20 73 61 6d 70 s than this samp
11c10 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 le */.};../*.**
11c20 45 61 63 68 20 74 6f 6b 65 6e 20 63 6f 6d 69 6e Each token comin
11c30 67 20 6f 75 74 20 6f 66 20 74 68 65 20 6c 65 78 g out of the lex
11c40 65 72 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 er is an instanc
11c50 65 20 6f 66 0a 2a 2a 20 74 68 69 73 20 73 74 72 e of.** this str
11c60 75 63 74 75 72 65 2e 20 20 54 6f 6b 65 6e 73 20 ucture. Tokens
11c70 61 72 65 20 61 6c 73 6f 20 75 73 65 64 20 61 73 are also used as
11c80 20 70 61 72 74 20 6f 66 20 61 6e 20 65 78 70 72 part of an expr
11c90 65 73 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 4e 6f ession..**.** No
11ca0 74 65 20 69 66 20 54 6f 6b 65 6e 2e 7a 3d 3d 30 te if Token.z==0
11cb0 20 74 68 65 6e 20 54 6f 6b 65 6e 2e 64 79 6e 20 then Token.dyn
11cc0 61 6e 64 20 54 6f 6b 65 6e 2e 6e 20 61 72 65 20 and Token.n are
11cd0 75 6e 64 65 66 69 6e 65 64 20 61 6e 64 0a 2a 2a undefined and.**
11ce0 20 6d 61 79 20 63 6f 6e 74 61 69 6e 20 72 61 6e may contain ran
11cf0 64 6f 6d 20 76 61 6c 75 65 73 2e 20 20 44 6f 20 dom values. Do
11d00 6e 6f 74 20 6d 61 6b 65 20 61 6e 79 20 61 73 73 not make any ass
11d10 75 6d 70 74 69 6f 6e 73 20 61 62 6f 75 74 20 54 umptions about T
11d20 6f 6b 65 6e 2e 64 79 6e 0a 2a 2a 20 61 6e 64 20 oken.dyn.** and
11d30 54 6f 6b 65 6e 2e 6e 20 77 68 65 6e 20 54 6f 6b Token.n when Tok
11d40 65 6e 2e 7a 3d 3d 30 2e 0a 2a 2f 0a 73 74 72 75 en.z==0..*/.stru
11d50 63 74 20 54 6f 6b 65 6e 20 7b 0a 20 20 63 6f 6e ct Token {. con
11d60 73 74 20 63 68 61 72 20 2a 7a 3b 20 20 20 20 20 st char *z;
11d70 2f 2a 20 54 65 78 74 20 6f 66 20 74 68 65 20 74 /* Text of the t
11d80 6f 6b 65 6e 2e 20 20 4e 6f 74 20 4e 55 4c 4c 2d oken. Not NULL-
11d90 74 65 72 6d 69 6e 61 74 65 64 21 20 2a 2f 0a 20 terminated! */.
11da0 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b unsigned int n;
11db0 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
11dc0 20 63 68 61 72 61 63 74 65 72 73 20 69 6e 20 74 characters in t
11dd0 68 69 73 20 74 6f 6b 65 6e 20 2a 2f 0a 7d 3b 0a his token */.};.
11de0 0a 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e ./*.** An instan
11df0 63 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 ce of this struc
11e00 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 69 6e ture contains in
11e10 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 formation needed
11e20 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 to generate.**
11e30 63 6f 64 65 20 66 6f 72 20 61 20 53 45 4c 45 43 code for a SELEC
11e40 54 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 73 20 T that contains
11e50 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 aggregate functi
11e60 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 45 78 ons..**.** If Ex
11e70 70 72 2e 6f 70 3d 3d 54 4b 5f 41 47 47 5f 43 4f pr.op==TK_AGG_CO
11e80 4c 55 4d 4e 20 6f 72 20 54 4b 5f 41 47 47 5f 46 LUMN or TK_AGG_F
11e90 55 4e 43 54 49 4f 4e 20 74 68 65 6e 20 45 78 70 UNCTION then Exp
11ea0 72 2e 70 41 67 67 49 6e 66 6f 20 69 73 20 61 0a r.pAggInfo is a.
11eb0 2a 2a 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 ** pointer to th
11ec0 69 73 20 73 74 72 75 63 74 75 72 65 2e 20 20 54 is structure. T
11ed0 68 65 20 45 78 70 72 2e 69 43 6f 6c 75 6d 6e 20 he Expr.iColumn
11ee0 66 69 65 6c 64 20 69 73 20 74 68 65 20 69 6e 64 field is the ind
11ef0 65 78 20 69 6e 0a 2a 2a 20 41 67 67 49 6e 66 6f ex in.** AggInfo
11f00 2e 61 43 6f 6c 5b 5d 20 6f 72 20 41 67 67 49 6e .aCol[] or AggIn
11f10 66 6f 2e 61 46 75 6e 63 5b 5d 20 6f 66 20 69 6e fo.aFunc[] of in
11f20 66 6f 72 6d 61 74 69 6f 6e 20 6e 65 65 64 65 64 formation needed
11f30 20 74 6f 20 67 65 6e 65 72 61 74 65 0a 2a 2a 20 to generate.**
11f40 63 6f 64 65 20 66 6f 72 20 74 68 61 74 20 6e 6f code for that no
11f50 64 65 2e 0a 2a 2a 0a 2a 2a 20 41 67 67 49 6e 66 de..**.** AggInf
11f60 6f 2e 70 47 72 6f 75 70 42 79 20 61 6e 64 20 41 o.pGroupBy and A
11f70 67 67 49 6e 66 6f 2e 61 46 75 6e 63 2e 70 45 78 ggInfo.aFunc.pEx
11f80 70 72 20 70 6f 69 6e 74 20 74 6f 20 66 69 65 6c pr point to fiel
11f90 64 73 20 77 69 74 68 69 6e 20 74 68 65 0a 2a 2a ds within the.**
11fa0 20 6f 72 69 67 69 6e 61 6c 20 53 65 6c 65 63 74 original Select
11fb0 20 73 74 72 75 63 74 75 72 65 20 74 68 61 74 20 structure that
11fc0 64 65 73 63 72 69 62 65 73 20 74 68 65 20 53 45 describes the SE
11fd0 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 2e 20 LECT statement.
11fe0 20 54 68 65 73 65 0a 2a 2a 20 66 69 65 6c 64 73 These.** fields
11ff0 20 64 6f 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 do not need to
12000 62 65 20 66 72 65 65 64 20 77 68 65 6e 20 64 65 be freed when de
12010 61 6c 6c 6f 63 61 74 69 6e 67 20 74 68 65 20 41 allocating the A
12020 67 67 49 6e 66 6f 20 73 74 72 75 63 74 75 72 65 ggInfo structure
12030 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 41 67 67 49 ..*/.struct AggI
12040 6e 66 6f 20 7b 0a 20 20 75 38 20 64 69 72 65 63 nfo {. u8 direc
12050 74 4d 6f 64 65 3b 20 20 20 20 20 20 20 20 20 20 tMode;
12060 2f 2a 20 44 69 72 65 63 74 20 72 65 6e 64 65 72 /* Direct render
12070 69 6e 67 20 6d 6f 64 65 20 6d 65 61 6e 73 20 74 ing mode means t
12080 61 6b 65 20 64 61 74 61 20 64 69 72 65 63 74 6c ake data directl
12090 79 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 y.
120a0 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 66 ** f
120b0 72 6f 6d 20 73 6f 75 72 63 65 20 74 61 62 6c 65 rom source table
120c0 73 20 72 61 74 68 65 72 20 74 68 61 6e 20 66 72 s rather than fr
120d0 6f 6d 20 61 63 63 75 6d 75 6c 61 74 6f 72 73 20 om accumulators
120e0 2a 2f 0a 20 20 75 38 20 75 73 65 53 6f 72 74 69 */. u8 useSorti
120f0 6e 67 49 64 78 3b 20 20 20 20 20 20 20 2f 2a 20 ngIdx; /*
12100 49 6e 20 64 69 72 65 63 74 20 6d 6f 64 65 2c 20 In direct mode,
12110 72 65 66 65 72 65 6e 63 65 20 74 68 65 20 73 6f reference the so
12120 72 74 69 6e 67 20 69 6e 64 65 78 20 72 61 74 68 rting index rath
12130 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 er.
12140 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 **
12150 74 68 61 6e 20 74 68 65 20 73 6f 75 72 63 65 20 than the source
12160 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 73 table */. int s
12170 6f 72 74 69 6e 67 49 64 78 3b 20 20 20 20 20 20 ortingIdx;
12180 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 6e 75 6d /* Cursor num
12190 62 65 72 20 6f 66 20 74 68 65 20 73 6f 72 74 69 ber of the sorti
121a0 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 20 69 6e ng index */. in
121b0 74 20 73 6f 72 74 69 6e 67 49 64 78 50 54 61 62 t sortingIdxPTab
121c0 3b 20 20 20 20 20 2f 2a 20 43 75 72 73 6f 72 20 ; /* Cursor
121d0 6e 75 6d 62 65 72 20 6f 66 20 70 73 65 75 64 6f number of pseudo
121e0 2d 74 61 62 6c 65 20 2a 2f 0a 20 20 69 6e 74 20 -table */. int
121f0 6e 53 6f 72 74 69 6e 67 43 6f 6c 75 6d 6e 3b 20 nSortingColumn;
12200 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
12210 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 68 65 20 columns in the
12220 73 6f 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f sorting index */
12230 0a 20 20 69 6e 74 20 6d 6e 52 65 67 2c 20 6d 78 . int mnReg, mx
12240 52 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 52 61 Reg; /* Ra
12250 6e 67 65 20 6f 66 20 72 65 67 69 73 74 65 72 73 nge of registers
12260 20 61 6c 6c 6f 63 61 74 65 64 20 66 6f 72 20 61 allocated for a
12270 43 6f 6c 20 61 6e 64 20 61 46 75 6e 63 20 2a 2f Col and aFunc */
12280 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 47 72 . ExprList *pGr
12290 6f 75 70 42 79 3b 20 20 20 20 20 2f 2a 20 54 68 oupBy; /* Th
122a0 65 20 67 72 6f 75 70 20 62 79 20 63 6c 61 75 73 e group by claus
122b0 65 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 41 67 e */. struct Ag
122c0 67 49 6e 66 6f 5f 63 6f 6c 20 7b 20 20 20 20 2f gInfo_col { /
122d0 2a 20 46 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d * For each colum
122e0 6e 20 75 73 65 64 20 69 6e 20 73 6f 75 72 63 65 n used in source
122f0 20 74 61 62 6c 65 73 20 2a 2f 0a 20 20 20 20 54 tables */. T
12300 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 able *pTab;
12310 20 20 20 20 20 20 20 20 2f 2a 20 53 6f 75 72 63 /* Sourc
12320 65 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 e table */. i
12330 6e 74 20 69 54 61 62 6c 65 3b 20 20 20 20 20 20 nt iTable;
12340 20 20 20 20 20 20 20 20 2f 2a 20 43 75 72 73 6f /* Curso
12350 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 68 65 20 r number of the
12360 73 6f 75 72 63 65 20 74 61 62 6c 65 20 2a 2f 0a source table */.
12370 20 20 20 20 69 6e 74 20 69 43 6f 6c 75 6d 6e 3b int iColumn;
12380 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
12390 43 6f 6c 75 6d 6e 20 6e 75 6d 62 65 72 20 77 69 Column number wi
123a0 74 68 69 6e 20 74 68 65 20 73 6f 75 72 63 65 20 thin the source
123b0 74 61 62 6c 65 20 2a 2f 0a 20 20 20 20 69 6e 74 table */. int
123c0 20 69 53 6f 72 74 65 72 43 6f 6c 75 6d 6e 3b 20 iSorterColumn;
123d0 20 20 20 20 20 20 2f 2a 20 43 6f 6c 75 6d 6e 20 /* Column
123e0 6e 75 6d 62 65 72 20 69 6e 20 74 68 65 20 73 6f number in the so
123f0 72 74 69 6e 67 20 69 6e 64 65 78 20 2a 2f 0a 20 rting index */.
12400 20 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 20 20 int iMem;
12410 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d /* M
12420 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 74 emory location t
12430 68 61 74 20 61 63 74 73 20 61 73 20 61 63 63 75 hat acts as accu
12440 6d 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 20 45 mulator */. E
12450 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 20 20 xpr *pExpr;
12460 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 6f /* The o
12470 72 69 67 69 6e 61 6c 20 65 78 70 72 65 73 73 69 riginal expressi
12480 6f 6e 20 2a 2f 0a 20 20 7d 20 2a 61 43 6f 6c 3b on */. } *aCol;
12490 0a 20 20 69 6e 74 20 6e 43 6f 6c 75 6d 6e 3b 20 . int nColumn;
124a0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
124b0 6d 62 65 72 20 6f 66 20 75 73 65 64 20 65 6e 74 mber of used ent
124c0 72 69 65 73 20 69 6e 20 61 43 6f 6c 5b 5d 20 2a ries in aCol[] *
124d0 2f 0a 20 20 69 6e 74 20 6e 41 63 63 75 6d 75 6c /. int nAccumul
124e0 61 74 6f 72 3b 20 20 20 20 20 20 20 2f 2a 20 4e ator; /* N
124f0 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 umber of columns
12500 20 74 68 61 74 20 73 68 6f 77 20 74 68 72 6f 75 that show throu
12510 67 68 20 74 6f 20 74 68 65 20 6f 75 74 70 75 74 gh to the output
12520 2e 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
12530 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 41 ** A
12540 64 64 69 74 69 6f 6e 61 6c 20 63 6f 6c 75 6d 6e dditional column
12550 73 20 61 72 65 20 75 73 65 64 20 6f 6e 6c 79 20 s are used only
12560 61 73 20 70 61 72 61 6d 65 74 65 72 73 20 74 6f as parameters to
12570 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
12580 20 20 20 20 20 20 20 20 20 20 20 2a 2a 20 61 67 ** ag
12590 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f 6e gregate function
125a0 73 20 2a 2f 0a 20 20 73 74 72 75 63 74 20 41 67 s */. struct Ag
125b0 67 49 6e 66 6f 5f 66 75 6e 63 20 7b 20 20 20 2f gInfo_func { /
125c0 2a 20 46 6f 72 20 65 61 63 68 20 61 67 67 72 65 * For each aggre
125d0 67 61 74 65 20 66 75 6e 63 74 69 6f 6e 20 2a 2f gate function */
125e0 0a 20 20 20 20 45 78 70 72 20 2a 70 45 78 70 72 . Expr *pExpr
125f0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a ; /*
12600 20 45 78 70 72 65 73 73 69 6f 6e 20 65 6e 63 6f Expression enco
12610 64 69 6e 67 20 74 68 65 20 66 75 6e 63 74 69 6f ding the functio
12620 6e 20 2a 2f 0a 20 20 20 20 46 75 6e 63 44 65 66 n */. FuncDef
12630 20 2a 70 46 75 6e 63 3b 20 20 20 20 20 20 20 20 *pFunc;
12640 20 20 2f 2a 20 54 68 65 20 61 67 67 72 65 67 61 /* The aggrega
12650 74 65 20 66 75 6e 63 74 69 6f 6e 20 69 6d 70 6c te function impl
12660 65 6d 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 ementation */.
12670 20 20 69 6e 74 20 69 4d 65 6d 3b 20 20 20 20 20 int iMem;
12680 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 /* Me
12690 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 74 68 mory location th
126a0 61 74 20 61 63 74 73 20 61 73 20 61 63 63 75 6d at acts as accum
126b0 75 6c 61 74 6f 72 20 2a 2f 0a 20 20 20 20 69 6e ulator */. in
126c0 74 20 69 44 69 73 74 69 6e 63 74 3b 20 20 20 20 t iDistinct;
126d0 20 20 20 20 20 20 20 2f 2a 20 45 70 68 65 6d 65 /* Epheme
126e0 72 61 6c 20 74 61 62 6c 65 20 75 73 65 64 20 74 ral table used t
126f0 6f 20 65 6e 66 6f 72 63 65 20 44 49 53 54 49 4e o enforce DISTIN
12700 43 54 20 2a 2f 0a 20 20 7d 20 2a 61 46 75 6e 63 CT */. } *aFunc
12710 3b 0a 20 20 69 6e 74 20 6e 46 75 6e 63 3b 20 20 ;. int nFunc;
12720 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
12730 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 69 65 73 umber of entries
12740 20 69 6e 20 61 46 75 6e 63 5b 5d 20 2a 2f 0a 7d in aFunc[] */.}
12750 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 64 61 74 ;../*.** The dat
12760 61 74 79 70 65 20 79 6e 56 61 72 20 69 73 20 61 atype ynVar is a
12770 20 73 69 67 6e 65 64 20 69 6e 74 65 67 65 72 2c signed integer,
12780 20 65 69 74 68 65 72 20 31 36 2d 62 69 74 20 6f either 16-bit o
12790 72 20 33 32 2d 62 69 74 2e 0a 2a 2a 20 55 73 75 r 32-bit..** Usu
127a0 61 6c 6c 79 20 69 74 20 69 73 20 31 36 2d 62 69 ally it is 16-bi
127b0 74 73 2e 20 20 42 75 74 20 69 66 20 53 51 4c 49 ts. But if SQLI
127c0 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f TE_MAX_VARIABLE_
127d0 4e 55 4d 42 45 52 20 69 73 20 67 72 65 61 74 65 NUMBER is greate
127e0 72 0a 2a 2a 20 74 68 61 6e 20 33 32 37 36 37 20 r.** than 32767
127f0 77 65 20 68 61 76 65 20 74 6f 20 6d 61 6b 65 20 we have to make
12800 69 74 20 33 32 2d 62 69 74 2e 20 20 31 36 2d 62 it 32-bit. 16-b
12810 69 74 20 69 73 20 70 72 65 66 65 72 72 65 64 20 it is preferred
12820 62 65 63 61 75 73 65 0a 2a 2a 20 69 74 20 75 73 because.** it us
12830 65 73 20 6c 65 73 73 20 6d 65 6d 6f 72 79 20 69 es less memory i
12840 6e 20 74 68 65 20 45 78 70 72 20 6f 62 6a 65 63 n the Expr objec
12850 74 2c 20 77 68 69 63 68 20 69 73 20 61 20 62 69 t, which is a bi
12860 67 20 6d 65 6d 6f 72 79 20 75 73 65 72 0a 2a 2a g memory user.**
12870 20 69 6e 20 73 79 73 74 65 6d 73 20 77 69 74 68 in systems with
12880 20 6c 6f 74 73 20 6f 66 20 70 72 65 70 61 72 65 lots of prepare
12890 64 20 73 74 61 74 65 6d 65 6e 74 73 2e 20 20 41 d statements. A
128a0 6e 64 20 66 65 77 20 61 70 70 6c 69 63 61 74 69 nd few applicati
128b0 6f 6e 73 0a 2a 2a 20 6e 65 65 64 20 6d 6f 72 65 ons.** need more
128c0 20 74 68 61 6e 20 61 62 6f 75 74 20 31 30 20 6f than about 10 o
128d0 72 20 32 30 20 76 61 72 69 61 62 6c 65 73 2e 20 r 20 variables.
128e0 20 42 75 74 20 73 6f 6d 65 20 65 78 74 72 65 6d But some extrem
128f0 65 20 75 73 65 72 73 20 77 61 6e 74 0a 2a 2a 20 e users want.**
12900 74 6f 20 68 61 76 65 20 70 72 65 70 61 72 65 64 to have prepared
12910 20 73 74 61 74 65 6d 65 6e 74 73 20 77 69 74 68 statements with
12920 20 6f 76 65 72 20 33 32 37 36 37 20 76 61 72 69 over 32767 vari
12930 61 62 6c 65 73 2c 20 61 6e 64 20 66 6f 72 20 74 ables, and for t
12940 68 65 6d 0a 2a 2a 20 74 68 65 20 6f 70 74 69 6f hem.** the optio
12950 6e 20 69 73 20 61 76 61 69 6c 61 62 6c 65 20 28 n is available (
12960 61 74 20 63 6f 6d 70 69 6c 65 2d 74 69 6d 65 29 at compile-time)
12970 2e 0a 2a 2f 0a 23 69 66 20 53 51 4c 49 54 45 5f ..*/.#if SQLITE_
12980 4d 41 58 5f 56 41 52 49 41 42 4c 45 5f 4e 55 4d MAX_VARIABLE_NUM
12990 42 45 52 3c 3d 33 32 37 36 37 0a 74 79 70 65 64 BER<=32767.typed
129a0 65 66 20 69 31 36 20 79 6e 56 61 72 3b 0a 23 65 ef i16 ynVar;.#e
129b0 6c 73 65 0a 74 79 70 65 64 65 66 20 69 6e 74 20 lse.typedef int
129c0 79 6e 56 61 72 3b 0a 23 65 6e 64 69 66 0a 0a 2f ynVar;.#endif../
129d0 2a 0a 2a 2a 20 45 61 63 68 20 6e 6f 64 65 20 6f *.** Each node o
129e0 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 f an expression
129f0 69 6e 20 74 68 65 20 70 61 72 73 65 20 74 72 65 in the parse tre
12a00 65 20 69 73 20 61 6e 20 69 6e 73 74 61 6e 63 65 e is an instance
12a10 0a 2a 2a 20 6f 66 20 74 68 69 73 20 73 74 72 75 .** of this stru
12a20 63 74 75 72 65 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 cture..**.** Exp
12a30 72 2e 6f 70 20 69 73 20 74 68 65 20 6f 70 63 6f r.op is the opco
12a40 64 65 2e 20 54 68 65 20 69 6e 74 65 67 65 72 20 de. The integer
12a50 70 61 72 73 65 72 20 74 6f 6b 65 6e 20 63 6f 64 parser token cod
12a60 65 73 20 61 72 65 20 72 65 75 73 65 64 0a 2a 2a es are reused.**
12a70 20 61 73 20 6f 70 63 6f 64 65 73 20 68 65 72 65 as opcodes here
12a80 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 . For example, t
12a90 68 65 20 70 61 72 73 65 72 20 64 65 66 69 6e 65 he parser define
12aa0 73 20 54 4b 5f 47 45 20 74 6f 20 62 65 20 61 6e s TK_GE to be an
12ab0 20 69 6e 74 65 67 65 72 0a 2a 2a 20 63 6f 64 65 integer.** code
12ac0 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 74 68 representing th
12ad0 65 20 22 3e 3d 22 20 6f 70 65 72 61 74 6f 72 2e e ">=" operator.
12ae0 20 54 68 69 73 20 73 61 6d 65 20 69 6e 74 65 67 This same integ
12af0 65 72 20 63 6f 64 65 20 69 73 20 72 65 75 73 65 er code is reuse
12b00 64 0a 2a 2a 20 74 6f 20 72 65 70 72 65 73 65 6e d.** to represen
12b10 74 20 74 68 65 20 67 72 65 61 74 65 72 2d 74 68 t the greater-th
12b20 61 6e 2d 6f 72 2d 65 71 75 61 6c 2d 74 6f 20 6f an-or-equal-to o
12b30 70 65 72 61 74 6f 72 20 69 6e 20 74 68 65 20 65 perator in the e
12b40 78 70 72 65 73 73 69 6f 6e 0a 2a 2a 20 74 72 65 xpression.** tre
12b50 65 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 e..**.** If the
12b60 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 6e expression is an
12b70 20 53 51 4c 20 6c 69 74 65 72 61 6c 20 28 54 4b SQL literal (TK
12b80 5f 49 4e 54 45 47 45 52 2c 20 54 4b 5f 46 4c 4f _INTEGER, TK_FLO
12b90 41 54 2c 20 54 4b 5f 42 4c 4f 42 2c 20 0a 2a 2a AT, TK_BLOB, .**
12ba0 20 6f 72 20 54 4b 5f 53 54 52 49 4e 47 29 2c 20 or TK_STRING),
12bb0 74 68 65 6e 20 45 78 70 72 2e 74 6f 6b 65 6e 20 then Expr.token
12bc0 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 74 65 78 contains the tex
12bd0 74 20 6f 66 20 74 68 65 20 53 51 4c 20 6c 69 74 t of the SQL lit
12be0 65 72 61 6c 2e 20 49 66 0a 2a 2a 20 74 68 65 20 eral. If.** the
12bf0 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 61 20 expression is a
12c00 76 61 72 69 61 62 6c 65 20 28 54 4b 5f 56 41 52 variable (TK_VAR
12c10 49 41 42 4c 45 29 2c 20 74 68 65 6e 20 45 78 70 IABLE), then Exp
12c20 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 r.token contains
12c30 20 74 68 65 20 0a 2a 2a 20 76 61 72 69 61 62 6c the .** variabl
12c40 65 20 6e 61 6d 65 2e 20 46 69 6e 61 6c 6c 79 2c e name. Finally,
12c50 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
12c60 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
12c70 63 74 69 6f 6e 20 28 54 4b 5f 46 55 4e 43 54 49 ction (TK_FUNCTI
12c80 4f 4e 29 2c 0a 2a 2a 20 74 68 65 6e 20 45 78 70 ON),.** then Exp
12c90 72 2e 74 6f 6b 65 6e 20 63 6f 6e 74 61 69 6e 73 r.token contains
12ca0 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 the name of the
12cb0 20 66 75 6e 63 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a function..**.**
12cc0 20 45 78 70 72 2e 70 52 69 67 68 74 20 61 6e 64 Expr.pRight and
12cd0 20 45 78 70 72 2e 70 4c 65 66 74 20 61 72 65 20 Expr.pLeft are
12ce0 74 68 65 20 6c 65 66 74 20 61 6e 64 20 72 69 67 the left and rig
12cf0 68 74 20 73 75 62 65 78 70 72 65 73 73 69 6f 6e ht subexpression
12d00 73 20 6f 66 20 61 0a 2a 2a 20 62 69 6e 61 72 79 s of a.** binary
12d10 20 6f 70 65 72 61 74 6f 72 2e 20 45 69 74 68 65 operator. Eithe
12d20 72 20 6f 72 20 62 6f 74 68 20 6d 61 79 20 62 65 r or both may be
12d30 20 4e 55 4c 4c 2e 0a 2a 2a 0a 2a 2a 20 45 78 70 NULL..**.** Exp
12d40 72 2e 78 2e 70 4c 69 73 74 20 69 73 20 61 20 6c r.x.pList is a l
12d50 69 73 74 20 6f 66 20 61 72 67 75 6d 65 6e 74 73 ist of arguments
12d60 20 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 if the expressi
12d70 6f 6e 20 69 73 20 61 6e 20 53 51 4c 20 66 75 6e on is an SQL fun
12d80 63 74 69 6f 6e 2c 0a 2a 2a 20 61 20 43 41 53 45 ction,.** a CASE
12d90 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 72 20 61 expression or a
12da0 6e 20 49 4e 20 65 78 70 72 65 73 73 69 6f 6e 20 n IN expression
12db0 6f 66 20 74 68 65 20 66 6f 72 6d 20 22 3c 6c 68 of the form "<lh
12dc0 73 3e 20 49 4e 20 28 3c 79 3e 2c 20 3c 7a 3e 2e s> IN (<y>, <z>.
12dd0 2e 2e 29 22 2e 0a 2a 2a 20 45 78 70 72 2e 78 2e ..)"..** Expr.x.
12de0 70 53 65 6c 65 63 74 20 69 73 20 75 73 65 64 20 pSelect is used
12df0 69 66 20 74 68 65 20 65 78 70 72 65 73 73 69 6f if the expressio
12e00 6e 20 69 73 20 61 20 73 75 62 2d 73 65 6c 65 63 n is a sub-selec
12e10 74 20 6f 72 20 61 6e 20 65 78 70 72 65 73 73 69 t or an expressi
12e20 6f 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 66 6f 72 on of.** the for
12e30 6d 20 22 3c 6c 68 73 3e 20 49 4e 20 28 53 45 4c m "<lhs> IN (SEL
12e40 45 43 54 20 2e 2e 2e 29 22 2e 20 49 66 20 74 68 ECT ...)". If th
12e50 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 20 62 e EP_xIsSelect b
12e60 69 74 20 69 73 20 73 65 74 20 69 6e 20 74 68 65 it is set in the
12e70 0a 2a 2a 20 45 78 70 72 2e 66 6c 61 67 73 20 6d .** Expr.flags m
12e80 61 73 6b 2c 20 74 68 65 6e 20 45 78 70 72 2e 78 ask, then Expr.x
12e90 2e 70 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 .pSelect is vali
12ea0 64 2e 20 4f 74 68 65 72 77 69 73 65 2c 20 45 78 d. Otherwise, Ex
12eb0 70 72 2e 78 2e 70 4c 69 73 74 20 69 73 20 0a 2a pr.x.pList is .*
12ec0 2a 20 76 61 6c 69 64 2e 0a 2a 2a 0a 2a 2a 20 41 * valid..**.** A
12ed0 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 6f 66 20 n expression of
12ee0 74 68 65 20 66 6f 72 6d 20 49 44 20 6f 72 20 49 the form ID or I
12ef0 44 2e 49 44 20 72 65 66 65 72 73 20 74 6f 20 61 D.ID refers to a
12f00 20 63 6f 6c 75 6d 6e 20 69 6e 20 61 20 74 61 62 column in a tab
12f10 6c 65 2e 0a 2a 2a 20 46 6f 72 20 73 75 63 68 20 le..** For such
12f20 65 78 70 72 65 73 73 69 6f 6e 73 2c 20 45 78 70 expressions, Exp
12f30 72 2e 6f 70 20 69 73 20 73 65 74 20 74 6f 20 54 r.op is set to T
12f40 4b 5f 43 4f 4c 55 4d 4e 20 61 6e 64 20 45 78 70 K_COLUMN and Exp
12f50 72 2e 69 54 61 62 6c 65 20 69 73 0a 2a 2a 20 74 r.iTable is.** t
12f60 68 65 20 69 6e 74 65 67 65 72 20 63 75 72 73 6f he integer curso
12f70 72 20 6e 75 6d 62 65 72 20 6f 66 20 61 20 56 44 r number of a VD
12f80 42 45 20 63 75 72 73 6f 72 20 70 6f 69 6e 74 69 BE cursor pointi
12f90 6e 67 20 74 6f 20 74 68 61 74 20 74 61 62 6c 65 ng to that table
12fa0 20 61 6e 64 0a 2a 2a 20 45 78 70 72 2e 69 43 6f and.** Expr.iCo
12fb0 6c 75 6d 6e 20 69 73 20 74 68 65 20 63 6f 6c 75 lumn is the colu
12fc0 6d 6e 20 6e 75 6d 62 65 72 20 66 6f 72 20 74 68 mn number for th
12fd0 65 20 73 70 65 63 69 66 69 63 20 63 6f 6c 75 6d e specific colum
12fe0 6e 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 65 78 n. If the.** ex
12ff0 70 72 65 73 73 69 6f 6e 20 69 73 20 75 73 65 64 pression is used
13000 20 61 73 20 61 20 72 65 73 75 6c 74 20 69 6e 20 as a result in
13010 61 6e 20 61 67 67 72 65 67 61 74 65 20 53 45 4c an aggregate SEL
13020 45 43 54 2c 20 74 68 65 6e 20 74 68 65 0a 2a 2a ECT, then the.**
13030 20 76 61 6c 75 65 20 69 73 20 61 6c 73 6f 20 73 value is also s
13040 74 6f 72 65 64 20 69 6e 20 74 68 65 20 45 78 70 tored in the Exp
13050 72 2e 69 41 67 67 20 63 6f 6c 75 6d 6e 20 69 6e r.iAgg column in
13060 20 74 68 65 20 61 67 67 72 65 67 61 74 65 20 73 the aggregate s
13070 6f 20 74 68 61 74 0a 2a 2a 20 69 74 20 63 61 6e o that.** it can
13080 20 62 65 20 61 63 63 65 73 73 65 64 20 61 66 74 be accessed aft
13090 65 72 20 61 6c 6c 20 61 67 67 72 65 67 61 74 65 er all aggregate
130a0 73 20 61 72 65 20 63 6f 6d 70 75 74 65 64 2e 0a s are computed..
130b0 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 70 **.** If the exp
130c0 72 65 73 73 69 6f 6e 20 69 73 20 61 6e 20 75 6e ression is an un
130d0 62 6f 75 6e 64 20 76 61 72 69 61 62 6c 65 20 6d bound variable m
130e0 61 72 6b 65 72 20 28 61 20 71 75 65 73 74 69 6f arker (a questio
130f0 6e 20 6d 61 72 6b 20 0a 2a 2a 20 63 68 61 72 61 n mark .** chara
13100 63 74 65 72 20 27 3f 27 20 69 6e 20 74 68 65 20 cter '?' in the
13110 6f 72 69 67 69 6e 61 6c 20 53 51 4c 29 20 74 68 original SQL) th
13120 65 6e 20 74 68 65 20 45 78 70 72 2e 69 54 61 62 en the Expr.iTab
13130 6c 65 20 68 6f 6c 64 73 20 74 68 65 20 69 6e 64 le holds the ind
13140 65 78 20 0a 2a 2a 20 6e 75 6d 62 65 72 20 66 6f ex .** number fo
13150 72 20 74 68 61 74 20 76 61 72 69 61 62 6c 65 2e r that variable.
13160 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 65 78 .**.** If the ex
13170 70 72 65 73 73 69 6f 6e 20 69 73 20 61 20 73 75 pression is a su
13180 62 71 75 65 72 79 20 74 68 65 6e 20 45 78 70 72 bquery then Expr
13190 2e 69 43 6f 6c 75 6d 6e 20 68 6f 6c 64 73 20 61 .iColumn holds a
131a0 6e 20 69 6e 74 65 67 65 72 0a 2a 2a 20 72 65 67 n integer.** reg
131b0 69 73 74 65 72 20 6e 75 6d 62 65 72 20 63 6f 6e ister number con
131c0 74 61 69 6e 69 6e 67 20 74 68 65 20 72 65 73 75 taining the resu
131d0 6c 74 20 6f 66 20 74 68 65 20 73 75 62 71 75 65 lt of the subque
131e0 72 79 2e 20 20 49 66 20 74 68 65 0a 2a 2a 20 73 ry. If the.** s
131f0 75 62 71 75 65 72 79 20 67 69 76 65 73 20 61 20 ubquery gives a
13200 63 6f 6e 73 74 61 6e 74 20 72 65 73 75 6c 74 2c constant result,
13210 20 74 68 65 6e 20 69 54 61 62 6c 65 20 69 73 20 then iTable is
13220 2d 31 2e 20 20 49 66 20 74 68 65 20 73 75 62 71 -1. If the subq
13230 75 65 72 79 0a 2a 2a 20 67 69 76 65 73 20 61 20 uery.** gives a
13240 64 69 66 66 65 72 65 6e 74 20 61 6e 73 77 65 72 different answer
13250 20 61 74 20 64 69 66 66 65 72 65 6e 74 20 74 69 at different ti
13260 6d 65 73 20 64 75 72 69 6e 67 20 73 74 61 74 65 mes during state
13270 6d 65 6e 74 20 70 72 6f 63 65 73 73 69 6e 67 0a ment processing.
13280 2a 2a 20 74 68 65 6e 20 69 54 61 62 6c 65 20 69 ** then iTable i
13290 73 20 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 s the address of
132a0 20 61 20 73 75 62 72 6f 75 74 69 6e 65 20 74 68 a subroutine th
132b0 61 74 20 63 6f 6d 70 75 74 65 73 20 74 68 65 20 at computes the
132c0 73 75 62 71 75 65 72 79 2e 0a 2a 2a 0a 2a 2a 20 subquery..**.**
132d0 49 66 20 74 68 65 20 45 78 70 72 20 69 73 20 6f If the Expr is o
132e0 66 20 74 79 70 65 20 4f 50 5f 43 6f 6c 75 6d 6e f type OP_Column
132f0 2c 20 61 6e 64 20 74 68 65 20 74 61 62 6c 65 20 , and the table
13300 69 74 20 69 73 20 73 65 6c 65 63 74 69 6e 67 20 it is selecting
13310 66 72 6f 6d 0a 2a 2a 20 69 73 20 61 20 64 69 73 from.** is a dis
13320 6b 20 74 61 62 6c 65 20 6f 72 20 74 68 65 20 22 k table or the "
13330 6f 6c 64 2e 2a 22 20 70 73 65 75 64 6f 2d 74 61 old.*" pseudo-ta
13340 62 6c 65 2c 20 74 68 65 6e 20 70 54 61 62 20 70 ble, then pTab p
13350 6f 69 6e 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 oints to the.**
13360 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 61 corresponding ta
13370 62 6c 65 20 64 65 66 69 6e 69 74 69 6f 6e 2e 0a ble definition..
13380 2a 2a 0a 2a 2a 20 41 4c 4c 4f 43 41 54 49 4f 4e **.** ALLOCATION
13390 20 4e 4f 54 45 53 3a 0a 2a 2a 0a 2a 2a 20 45 78 NOTES:.**.** Ex
133a0 70 72 20 6f 62 6a 65 63 74 73 20 63 61 6e 20 75 pr objects can u
133b0 73 65 20 61 20 6c 6f 74 20 6f 66 20 6d 65 6d 6f se a lot of memo
133c0 72 79 20 73 70 61 63 65 20 69 6e 20 64 61 74 61 ry space in data
133d0 62 61 73 65 20 73 63 68 65 6d 61 2e 20 20 54 6f base schema. To
133e0 0a 2a 2a 20 68 65 6c 70 20 72 65 64 75 63 65 20 .** help reduce
133f0 6d 65 6d 6f 72 79 20 72 65 71 75 69 72 65 6d 65 memory requireme
13400 6e 74 73 2c 20 73 6f 6d 65 74 69 6d 65 73 20 61 nts, sometimes a
13410 6e 20 45 78 70 72 20 6f 62 6a 65 63 74 20 77 69 n Expr object wi
13420 6c 6c 20 62 65 0a 2a 2a 20 74 72 75 6e 63 61 74 ll be.** truncat
13430 65 64 2e 20 20 41 6e 64 20 74 6f 20 72 65 64 75 ed. And to redu
13440 63 65 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ce the number of
13450 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 69 memory allocati
13460 6f 6e 73 2c 20 73 6f 6d 65 74 69 6d 65 73 0a 2a ons, sometimes.*
13470 2a 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 45 78 * two or more Ex
13480 70 72 20 6f 62 6a 65 63 74 73 20 77 69 6c 6c 20 pr objects will
13490 62 65 20 73 74 6f 72 65 64 20 69 6e 20 61 20 73 be stored in a s
134a0 69 6e 67 6c 65 20 6d 65 6d 6f 72 79 20 61 6c 6c ingle memory all
134b0 6f 63 61 74 69 6f 6e 2c 0a 2a 2a 20 74 6f 67 65 ocation,.** toge
134c0 74 68 65 72 20 77 69 74 68 20 45 78 70 72 2e 7a ther with Expr.z
134d0 54 6f 6b 65 6e 20 73 74 72 69 6e 67 73 2e 0a 2a Token strings..*
134e0 2a 0a 2a 2a 20 49 66 20 74 68 65 20 45 50 5f 52 *.** If the EP_R
134f0 65 64 75 63 65 64 20 61 6e 64 20 45 50 5f 54 6f educed and EP_To
13500 6b 65 6e 4f 6e 6c 79 20 66 6c 61 67 73 20 61 72 kenOnly flags ar
13510 65 20 73 65 74 20 77 68 65 6e 0a 2a 2a 20 61 6e e set when.** an
13520 20 45 78 70 72 20 6f 62 6a 65 63 74 20 69 73 20 Expr object is
13530 74 72 75 6e 63 61 74 65 64 2e 20 20 57 68 65 6e truncated. When
13540 20 45 50 5f 52 65 64 75 63 65 64 20 69 73 20 73 EP_Reduced is s
13550 65 74 2c 20 74 68 65 6e 20 61 6c 6c 0a 2a 2a 20 et, then all.**
13560 74 68 65 20 63 68 69 6c 64 20 45 78 70 72 20 6f the child Expr o
13570 62 6a 65 63 74 73 20 69 6e 20 74 68 65 20 45 78 bjects in the Ex
13580 70 72 2e 70 4c 65 66 74 20 61 6e 64 20 45 78 70 pr.pLeft and Exp
13590 72 2e 70 52 69 67 68 74 20 73 75 62 74 72 65 65 r.pRight subtree
135a0 73 0a 2a 2a 20 61 72 65 20 63 6f 6e 74 61 69 6e s.** are contain
135b0 65 64 20 77 69 74 68 69 6e 20 74 68 65 20 73 61 ed within the sa
135c0 6d 65 20 6d 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 me memory alloca
135d0 74 69 6f 6e 2e 20 20 4e 6f 74 65 2c 20 68 6f 77 tion. Note, how
135e0 65 76 65 72 2c 20 74 68 61 74 0a 2a 2a 20 74 68 ever, that.** th
135f0 65 20 73 75 62 74 72 65 65 73 20 69 6e 20 45 78 e subtrees in Ex
13600 70 72 2e 78 2e 70 4c 69 73 74 20 6f 72 20 45 78 pr.x.pList or Ex
13610 70 72 2e 78 2e 70 53 65 6c 65 63 74 20 61 72 65 pr.x.pSelect are
13620 20 61 6c 77 61 79 73 20 73 65 70 61 72 61 74 65 always separate
13630 6c 79 0a 2a 2a 20 61 6c 6c 6f 63 61 74 65 64 2c ly.** allocated,
13640 20 72 65 67 61 72 64 6c 65 73 73 20 6f 66 20 77 regardless of w
13650 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 45 50 hether or not EP
13660 5f 52 65 64 75 63 65 64 20 69 73 20 73 65 74 2e _Reduced is set.
13670 0a 2a 2f 0a 73 74 72 75 63 74 20 45 78 70 72 20 .*/.struct Expr
13680 7b 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 {. u8 op;
13690 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 70 /* Op
136a0 65 72 61 74 69 6f 6e 20 70 65 72 66 6f 72 6d 65 eration performe
136b0 64 20 62 79 20 74 68 69 73 20 6e 6f 64 65 20 2a d by this node *
136c0 2f 0a 20 20 63 68 61 72 20 61 66 66 69 6e 69 74 /. char affinit
136d0 79 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 y; /* Th
136e0 65 20 61 66 66 69 6e 69 74 79 20 6f 66 20 74 68 e affinity of th
136f0 65 20 63 6f 6c 75 6d 6e 20 6f 72 20 30 20 69 66 e column or 0 if
13700 20 6e 6f 74 20 61 20 63 6f 6c 75 6d 6e 20 2a 2f not a column */
13710 0a 20 20 75 33 32 20 66 6c 61 67 73 3b 20 20 20 . u32 flags;
13720 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 72 /* Var
13730 69 6f 75 73 20 66 6c 61 67 73 2e 20 20 45 50 5f ious flags. EP_
13740 2a 20 53 65 65 20 62 65 6c 6f 77 20 2a 2f 0a 20 * See below */.
13750 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 63 68 61 union {. cha
13760 72 20 2a 7a 54 6f 6b 65 6e 3b 20 20 20 20 20 20 r *zToken;
13770 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 76 61 6c /* Token val
13780 75 65 2e 20 5a 65 72 6f 20 74 65 72 6d 69 6e 61 ue. Zero termina
13790 74 65 64 20 61 6e 64 20 64 65 71 75 6f 74 65 64 ted and dequoted
137a0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 56 61 6c */. int iVal
137b0 75 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f ue; /
137c0 2a 20 4e 6f 6e 2d 6e 65 67 61 74 69 76 65 20 69 * Non-negative i
137d0 6e 74 65 67 65 72 20 76 61 6c 75 65 20 69 66 20 nteger value if
137e0 45 50 5f 49 6e 74 56 61 6c 75 65 20 2a 2f 0a 20 EP_IntValue */.
137f0 20 7d 20 75 3b 0a 0a 20 20 2f 2a 20 49 66 20 74 } u;.. /* If t
13800 68 65 20 45 50 5f 54 6f 6b 65 6e 4f 6e 6c 79 20 he EP_TokenOnly
13810 66 6c 61 67 20 69 73 20 73 65 74 20 69 6e 20 74 flag is set in t
13820 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 6d 61 he Expr.flags ma
13830 73 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 20 2a 2a sk, then no. **
13840 20 73 70 61 63 65 20 69 73 20 61 6c 6c 6f 63 61 space is alloca
13850 74 65 64 20 66 6f 72 20 74 68 65 20 66 69 65 6c ted for the fiel
13860 64 73 20 62 65 6c 6f 77 20 74 68 69 73 20 70 6f ds below this po
13870 69 6e 74 2e 20 41 6e 20 61 74 74 65 6d 70 74 20 int. An attempt
13880 74 6f 0a 20 20 2a 2a 20 61 63 63 65 73 73 20 74 to. ** access t
13890 68 65 6d 20 77 69 6c 6c 20 72 65 73 75 6c 74 20 hem will result
138a0 69 6e 20 61 20 73 65 67 66 61 75 6c 74 20 6f 72 in a segfault or
138b0 20 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e 20 0a 20 malfunction. .
138c0 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ***************
138d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
138e0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
138f0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
13900 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 45 78 70 72 20 ******/.. Expr
13910 2a 70 4c 65 66 74 3b 20 20 20 20 20 20 20 20 20 *pLeft;
13920 20 20 2f 2a 20 4c 65 66 74 20 73 75 62 6e 6f 64 /* Left subnod
13930 65 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 52 69 e */. Expr *pRi
13940 67 68 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a ght; /*
13950 20 52 69 67 68 74 20 73 75 62 6e 6f 64 65 20 2a Right subnode *
13960 2f 0a 20 20 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 /. union {.
13970 45 78 70 72 4c 69 73 74 20 2a 70 4c 69 73 74 3b ExprList *pList;
13980 20 20 20 20 20 2f 2a 20 6f 70 20 3d 20 49 4e 2c /* op = IN,
13990 20 45 58 49 53 54 53 2c 20 53 45 4c 45 43 54 2c EXISTS, SELECT,
139a0 20 43 41 53 45 2c 20 46 55 4e 43 54 49 4f 4e 2c CASE, FUNCTION,
139b0 20 42 45 54 57 45 45 4e 20 2a 2f 0a 20 20 20 20 BETWEEN */.
139c0 53 65 6c 65 63 74 20 2a 70 53 65 6c 65 63 74 3b Select *pSelect;
139d0 20 20 20 20 20 2f 2a 20 45 50 5f 78 49 73 53 65 /* EP_xIsSe
139e0 6c 65 63 74 20 61 6e 64 20 6f 70 20 3d 20 49 4e lect and op = IN
139f0 2c 20 45 58 49 53 54 53 2c 20 53 45 4c 45 43 54 , EXISTS, SELECT
13a00 20 2a 2f 0a 20 20 7d 20 78 3b 0a 0a 20 20 2f 2a */. } x;.. /*
13a10 20 49 66 20 74 68 65 20 45 50 5f 52 65 64 75 63 If the EP_Reduc
13a20 65 64 20 66 6c 61 67 20 69 73 20 73 65 74 20 69 ed flag is set i
13a30 6e 20 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 n the Expr.flags
13a40 20 6d 61 73 6b 2c 20 74 68 65 6e 20 6e 6f 0a 20 mask, then no.
13a50 20 2a 2a 20 73 70 61 63 65 20 69 73 20 61 6c 6c ** space is all
13a60 6f 63 61 74 65 64 20 66 6f 72 20 74 68 65 20 66 ocated for the f
13a70 69 65 6c 64 73 20 62 65 6c 6f 77 20 74 68 69 73 ields below this
13a80 20 70 6f 69 6e 74 2e 20 41 6e 20 61 74 74 65 6d point. An attem
13a90 70 74 20 74 6f 0a 20 20 2a 2a 20 61 63 63 65 73 pt to. ** acces
13aa0 73 20 74 68 65 6d 20 77 69 6c 6c 20 72 65 73 75 s them will resu
13ab0 6c 74 20 69 6e 20 61 20 73 65 67 66 61 75 6c 74 lt in a segfault
13ac0 20 6f 72 20 6d 61 6c 66 75 6e 63 74 69 6f 6e 2e or malfunction.
13ad0 0a 20 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a . *************
13ae0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
13af0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
13b00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
13b10 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 23 69 66 20 53 ********/..#if S
13b20 51 4c 49 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 QLITE_MAX_EXPR_D
13b30 45 50 54 48 3e 30 0a 20 20 69 6e 74 20 6e 48 65 EPTH>0. int nHe
13b40 69 67 68 74 3b 20 20 20 20 20 20 20 20 20 20 20 ight;
13b50 2f 2a 20 48 65 69 67 68 74 20 6f 66 20 74 68 65 /* Height of the
13b60 20 74 72 65 65 20 68 65 61 64 65 64 20 62 79 20 tree headed by
13b70 74 68 69 73 20 6e 6f 64 65 20 2a 2f 0a 23 65 6e this node */.#en
13b80 64 69 66 0a 20 20 69 6e 74 20 69 54 61 62 6c 65 dif. int iTable
13b90 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
13ba0 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 75 72 73 6f TK_COLUMN: curso
13bb0 72 20 6e 75 6d 62 65 72 20 6f 66 20 74 61 62 6c r number of tabl
13bc0 65 20 68 6f 6c 64 69 6e 67 20 63 6f 6c 75 6d 6e e holding column
13bd0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
13be0 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f ** TK_
13bf0 52 45 47 49 53 54 45 52 3a 20 72 65 67 69 73 74 REGISTER: regist
13c00 65 72 20 6e 75 6d 62 65 72 0a 20 20 20 20 20 20 er number.
13c10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13c20 20 20 20 2a 2a 20 54 4b 5f 54 52 49 47 47 45 52 ** TK_TRIGGER
13c30 3a 20 31 20 2d 3e 20 6e 65 77 2c 20 30 20 2d 3e : 1 -> new, 0 ->
13c40 20 6f 6c 64 0a 20 20 20 20 20 20 20 20 20 20 20 old.
13c50 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2a **
13c60 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 3a 20 20 31 EP_Unlikely: 1
13c70 30 30 30 20 74 69 6d 65 73 20 6c 69 6b 65 6c 69 000 times likeli
13c80 68 6f 6f 64 20 2a 2f 0a 20 20 79 6e 56 61 72 20 hood */. ynVar
13c90 69 43 6f 6c 75 6d 6e 3b 20 20 20 20 20 20 20 20 iColumn;
13ca0 20 2f 2a 20 54 4b 5f 43 4f 4c 55 4d 4e 3a 20 63 /* TK_COLUMN: c
13cb0 6f 6c 75 6d 6e 20 69 6e 64 65 78 2e 20 20 2d 31 olumn index. -1
13cc0 20 66 6f 72 20 72 6f 77 69 64 2e 0a 20 20 20 20 for rowid..
13cd0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
13ce0 20 20 20 20 20 2a 2a 20 54 4b 5f 56 41 52 49 41 ** TK_VARIA
13cf0 42 4c 45 3a 20 76 61 72 69 61 62 6c 65 20 6e 75 BLE: variable nu
13d00 6d 62 65 72 20 28 61 6c 77 61 79 73 20 3e 3d 20 mber (always >=
13d10 31 29 2e 20 2a 2f 0a 20 20 69 31 36 20 69 41 67 1). */. i16 iAg
13d20 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 g;
13d30 2f 2a 20 57 68 69 63 68 20 65 6e 74 72 79 20 69 /* Which entry i
13d40 6e 20 70 41 67 67 49 6e 66 6f 2d 3e 61 43 6f 6c n pAggInfo->aCol
13d50 5b 5d 20 6f 72 20 2d 3e 61 46 75 6e 63 5b 5d 20 [] or ->aFunc[]
13d60 2a 2f 0a 20 20 69 31 36 20 69 52 69 67 68 74 4a */. i16 iRightJ
13d70 6f 69 6e 54 61 62 6c 65 3b 20 20 20 2f 2a 20 49 oinTable; /* I
13d80 66 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 2c 20 74 f EP_FromJoin, t
13d90 68 65 20 72 69 67 68 74 20 74 61 62 6c 65 20 6f he right table o
13da0 66 20 74 68 65 20 6a 6f 69 6e 20 2a 2f 0a 20 20 f the join */.
13db0 75 38 20 6f 70 32 3b 20 20 20 20 20 20 20 20 20 u8 op2;
13dc0 20 20 20 20 20 20 20 2f 2a 20 54 4b 5f 52 45 47 /* TK_REG
13dd0 49 53 54 45 52 3a 20 6f 72 69 67 69 6e 61 6c 20 ISTER: original
13de0 76 61 6c 75 65 20 6f 66 20 45 78 70 72 2e 6f 70 value of Expr.op
13df0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
13e00 20 20 20 20 20 20 20 20 20 20 2a 2a 20 54 4b 5f ** TK_
13e10 43 4f 4c 55 4d 4e 3a 20 74 68 65 20 76 61 6c 75 COLUMN: the valu
13e20 65 20 6f 66 20 70 35 20 66 6f 72 20 4f 50 5f 43 e of p5 for OP_C
13e30 6f 6c 75 6d 6e 0a 20 20 20 20 20 20 20 20 20 20 olumn.
13e40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a *
13e50 2a 20 54 4b 5f 41 47 47 5f 46 55 4e 43 54 49 4f * TK_AGG_FUNCTIO
13e60 4e 3a 20 6e 65 73 74 69 6e 67 20 64 65 70 74 68 N: nesting depth
13e70 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 */. AggInfo *p
13e80 41 67 67 49 6e 66 6f 3b 20 20 20 20 20 2f 2a 20 AggInfo; /*
13e90 55 73 65 64 20 62 79 20 54 4b 5f 41 47 47 5f 43 Used by TK_AGG_C
13ea0 4f 4c 55 4d 4e 20 61 6e 64 20 54 4b 5f 41 47 47 OLUMN and TK_AGG
13eb0 5f 46 55 4e 43 54 49 4f 4e 20 2a 2f 0a 20 20 54 _FUNCTION */. T
13ec0 61 62 6c 65 20 2a 70 54 61 62 3b 20 20 20 20 20 able *pTab;
13ed0 20 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 66 /* Table f
13ee0 6f 72 20 54 4b 5f 43 4f 4c 55 4d 4e 20 65 78 70 or TK_COLUMN exp
13ef0 72 65 73 73 69 6f 6e 73 2e 20 2a 2f 0a 7d 3b 0a ressions. */.};.
13f00 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
13f10 77 69 6e 67 20 61 72 65 20 74 68 65 20 6d 65 61 wing are the mea
13f20 6e 69 6e 67 73 20 6f 66 20 62 69 74 73 20 69 6e nings of bits in
13f30 20 74 68 65 20 45 78 70 72 2e 66 6c 61 67 73 20 the Expr.flags
13f40 66 69 65 6c 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e field..*/.#defin
13f50 65 20 45 50 5f 46 72 6f 6d 4a 6f 69 6e 20 20 30 e EP_FromJoin 0
13f60 78 30 30 30 30 30 31 20 2f 2a 20 4f 72 69 67 69 x000001 /* Origi
13f70 6e 61 74 65 64 20 69 6e 20 4f 4e 20 6f 72 20 55 nated in ON or U
13f80 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 20 61 SING clause of a
13f90 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 join */.#define
13fa0 20 45 50 5f 41 67 67 20 20 20 20 20 20 20 30 78 EP_Agg 0x
13fb0 30 30 30 30 30 32 20 2f 2a 20 43 6f 6e 74 61 69 000002 /* Contai
13fc0 6e 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 61 ns one or more a
13fd0 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
13fe0 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 ns */.#define EP
13ff0 5f 52 65 73 6f 6c 76 65 64 20 20 30 78 30 30 30 _Resolved 0x000
14000 30 30 34 20 2f 2a 20 49 44 73 20 68 61 76 65 20 004 /* IDs have
14010 62 65 65 6e 20 72 65 73 6f 6c 76 65 64 20 74 6f been resolved to
14020 20 43 4f 4c 55 4d 4e 73 20 2a 2f 0a 23 64 65 66 COLUMNs */.#def
14030 69 6e 65 20 45 50 5f 45 72 72 6f 72 20 20 20 20 ine EP_Error
14040 20 30 78 30 30 30 30 30 38 20 2f 2a 20 45 78 70 0x000008 /* Exp
14050 72 65 73 73 69 6f 6e 20 63 6f 6e 74 61 69 6e 73 ression contains
14060 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 65 72 72 one or more err
14070 6f 72 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ors */.#define E
14080 50 5f 44 69 73 74 69 6e 63 74 20 20 30 78 30 30 P_Distinct 0x00
14090 30 30 31 30 20 2f 2a 20 41 67 67 72 65 67 61 74 0010 /* Aggregat
140a0 65 20 66 75 6e 63 74 69 6f 6e 20 77 69 74 68 20 e function with
140b0 44 49 53 54 49 4e 43 54 20 6b 65 79 77 6f 72 64 DISTINCT keyword
140c0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 56 */.#define EP_V
140d0 61 72 53 65 6c 65 63 74 20 30 78 30 30 30 30 32 arSelect 0x00002
140e0 30 20 2f 2a 20 70 53 65 6c 65 63 74 20 69 73 20 0 /* pSelect is
140f0 63 6f 72 72 65 6c 61 74 65 64 2c 20 6e 6f 74 20 correlated, not
14100 63 6f 6e 73 74 61 6e 74 20 2a 2f 0a 23 64 65 66 constant */.#def
14110 69 6e 65 20 45 50 5f 44 62 6c 51 75 6f 74 65 64 ine EP_DblQuoted
14120 20 30 78 30 30 30 30 34 30 20 2f 2a 20 74 6f 6b 0x000040 /* tok
14130 65 6e 2e 7a 20 77 61 73 20 6f 72 69 67 69 6e 61 en.z was origina
14140 6c 6c 79 20 69 6e 20 22 2e 2e 2e 22 20 2a 2f 0a lly in "..." */.
14150 23 64 65 66 69 6e 65 20 45 50 5f 49 6e 66 69 78 #define EP_Infix
14160 46 75 6e 63 20 30 78 30 30 30 30 38 30 20 2f 2a Func 0x000080 /*
14170 20 54 72 75 65 20 66 6f 72 20 61 6e 20 69 6e 66 True for an inf
14180 69 78 20 66 75 6e 63 74 69 6f 6e 3a 20 4c 49 4b ix function: LIK
14190 45 2c 20 47 4c 4f 42 2c 20 65 74 63 20 2a 2f 0a E, GLOB, etc */.
141a0 23 64 65 66 69 6e 65 20 45 50 5f 43 6f 6c 6c 61 #define EP_Colla
141b0 74 65 20 20 20 30 78 30 30 30 31 30 30 20 2f 2a te 0x000100 /*
141c0 20 54 72 65 65 20 63 6f 6e 74 61 69 6e 73 20 61 Tree contains a
141d0 20 54 4b 5f 43 4f 4c 4c 41 54 45 20 6f 70 65 72 TK_COLLATE oper
141e0 61 74 6f 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 ator */.#define
141f0 45 50 5f 47 65 6e 65 72 69 63 20 20 20 30 78 30 EP_Generic 0x0
14200 30 30 32 30 30 20 2f 2a 20 49 67 6e 6f 72 65 20 00200 /* Ignore
14210 43 4f 4c 4c 41 54 45 20 6f 72 20 61 66 66 69 6e COLLATE or affin
14220 69 74 79 20 6f 6e 20 74 68 69 73 20 74 72 65 65 ity on this tree
14230 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 49 */.#define EP_I
14240 6e 74 56 61 6c 75 65 20 20 30 78 30 30 30 34 30 ntValue 0x00040
14250 30 20 2f 2a 20 49 6e 74 65 67 65 72 20 76 61 6c 0 /* Integer val
14260 75 65 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20 ue contained in
14270 75 2e 69 56 61 6c 75 65 20 2a 2f 0a 23 64 65 66 u.iValue */.#def
14280 69 6e 65 20 45 50 5f 78 49 73 53 65 6c 65 63 74 ine EP_xIsSelect
14290 20 30 78 30 30 30 38 30 30 20 2f 2a 20 78 2e 70 0x000800 /* x.p
142a0 53 65 6c 65 63 74 20 69 73 20 76 61 6c 69 64 20 Select is valid
142b0 28 6f 74 68 65 72 77 69 73 65 20 78 2e 70 4c 69 (otherwise x.pLi
142c0 73 74 20 69 73 29 20 2a 2f 0a 23 64 65 66 69 6e st is) */.#defin
142d0 65 20 45 50 5f 53 6b 69 70 20 20 20 20 20 20 30 e EP_Skip 0
142e0 78 30 30 31 30 30 30 20 2f 2a 20 43 4f 4c 4c 41 x001000 /* COLLA
142f0 54 45 2c 20 41 53 2c 20 6f 72 20 55 4e 4c 49 4b TE, AS, or UNLIK
14300 45 4c 59 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ELY */.#define E
14310 50 5f 52 65 64 75 63 65 64 20 20 20 30 78 30 30 P_Reduced 0x00
14320 32 30 30 30 20 2f 2a 20 45 78 70 72 20 73 74 72 2000 /* Expr str
14330 75 63 74 20 45 58 50 52 5f 52 45 44 55 43 45 44 uct EXPR_REDUCED
14340 53 49 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 SIZE bytes only
14350 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 54 6f */.#define EP_To
14360 6b 65 6e 4f 6e 6c 79 20 30 78 30 30 34 30 30 30 kenOnly 0x004000
14370 20 2f 2a 20 45 78 70 72 20 73 74 72 75 63 74 20 /* Expr struct
14380 45 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 EXPR_TOKENONLYSI
14390 5a 45 20 62 79 74 65 73 20 6f 6e 6c 79 20 2a 2f ZE bytes only */
143a0 0a 23 64 65 66 69 6e 65 20 45 50 5f 53 74 61 74 .#define EP_Stat
143b0 69 63 20 20 20 20 30 78 30 30 38 30 30 30 20 2f ic 0x008000 /
143c0 2a 20 48 65 6c 64 20 69 6e 20 6d 65 6d 6f 72 79 * Held in memory
143d0 20 6e 6f 74 20 6f 62 74 61 69 6e 65 64 20 66 72 not obtained fr
143e0 6f 6d 20 6d 61 6c 6c 6f 63 28 29 20 2a 2f 0a 23 om malloc() */.#
143f0 64 65 66 69 6e 65 20 45 50 5f 4d 65 6d 54 6f 6b define EP_MemTok
14400 65 6e 20 20 30 78 30 31 30 30 30 30 20 2f 2a 20 en 0x010000 /*
14410 4e 65 65 64 20 74 6f 20 73 71 6c 69 74 65 33 44 Need to sqlite3D
14420 62 46 72 65 65 28 29 20 45 78 70 72 2e 7a 54 6f bFree() Expr.zTo
14430 6b 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 ken */.#define E
14440 50 5f 4e 6f 52 65 64 75 63 65 20 20 30 78 30 32 P_NoReduce 0x02
14450 30 30 30 30 20 2f 2a 20 43 61 6e 6e 6f 74 20 45 0000 /* Cannot E
14460 58 50 52 44 55 50 5f 52 45 44 55 43 45 20 74 68 XPRDUP_REDUCE th
14470 69 73 20 45 78 70 72 20 2a 2f 0a 23 64 65 66 69 is Expr */.#defi
14480 6e 65 20 45 50 5f 55 6e 6c 69 6b 65 6c 79 20 20 ne EP_Unlikely
14490 30 78 30 34 30 30 30 30 20 2f 2a 20 75 6e 6c 69 0x040000 /* unli
144a0 6b 65 6c 79 28 29 20 6f 72 20 6c 69 6b 65 6c 69 kely() or likeli
144b0 68 6f 6f 64 28 29 20 66 75 6e 63 74 69 6f 6e 20 hood() function
144c0 2a 2f 0a 23 64 65 66 69 6e 65 20 45 50 5f 43 6f */.#define EP_Co
144d0 6e 73 74 61 6e 74 20 20 30 78 30 38 30 30 30 30 nstant 0x080000
144e0 20 2f 2a 20 4e 6f 64 65 20 69 73 20 61 20 63 6f /* Node is a co
144f0 6e 73 74 61 6e 74 20 2a 2f 0a 0a 2f 2a 0a 2a 2a nstant */../*.**
14500 20 54 68 65 73 65 20 6d 61 63 72 6f 73 20 63 61 These macros ca
14510 6e 20 62 65 20 75 73 65 64 20 74 6f 20 74 65 73 n be used to tes
14520 74 2c 20 73 65 74 2c 20 6f 72 20 63 6c 65 61 72 t, set, or clear
14530 20 62 69 74 73 20 69 6e 20 74 68 65 20 0a 2a 2a bits in the .**
14540 20 45 78 70 72 2e 66 6c 61 67 73 20 66 69 65 6c Expr.flags fiel
14550 64 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 45 78 d..*/.#define Ex
14560 70 72 48 61 73 50 72 6f 70 65 72 74 79 28 45 2c prHasProperty(E,
14570 50 29 20 20 20 20 20 28 28 28 45 29 2d 3e 66 6c P) (((E)->fl
14580 61 67 73 26 28 50 29 29 21 3d 30 29 0a 23 64 65 ags&(P))!=0).#de
14590 66 69 6e 65 20 45 78 70 72 48 61 73 41 6c 6c 50 fine ExprHasAllP
145a0 72 6f 70 65 72 74 79 28 45 2c 50 29 20 20 28 28 roperty(E,P) ((
145b0 28 45 29 2d 3e 66 6c 61 67 73 26 28 50 29 29 3d (E)->flags&(P))=
145c0 3d 28 50 29 29 0a 23 64 65 66 69 6e 65 20 45 78 =(P)).#define Ex
145d0 70 72 53 65 74 50 72 6f 70 65 72 74 79 28 45 2c prSetProperty(E,
145e0 50 29 20 20 20 20 20 28 45 29 2d 3e 66 6c 61 67 P) (E)->flag
145f0 73 7c 3d 28 50 29 0a 23 64 65 66 69 6e 65 20 45 s|=(P).#define E
14600 78 70 72 43 6c 65 61 72 50 72 6f 70 65 72 74 79 xprClearProperty
14610 28 45 2c 50 29 20 20 20 28 45 29 2d 3e 66 6c 61 (E,P) (E)->fla
14620 67 73 26 3d 7e 28 50 29 0a 0a 2f 2a 20 54 68 65 gs&=~(P)../* The
14630 20 45 78 70 72 53 65 74 56 56 41 50 72 6f 70 65 ExprSetVVAPrope
14640 72 74 79 28 29 20 6d 61 63 72 6f 20 69 73 20 75 rty() macro is u
14650 73 65 64 20 66 6f 72 20 56 65 72 69 66 69 63 61 sed for Verifica
14660 74 69 6f 6e 2c 20 56 61 6c 69 64 61 74 69 6f 6e tion, Validation
14670 2c 0a 2a 2a 20 61 6e 64 20 41 63 63 72 65 64 69 ,.** and Accredi
14680 74 61 74 69 6f 6e 20 6f 6e 6c 79 2e 20 20 49 74 tation only. It
14690 20 77 6f 72 6b 73 20 6c 69 6b 65 20 45 78 70 72 works like Expr
146a0 53 65 74 50 72 6f 70 65 72 74 79 28 29 20 64 75 SetProperty() du
146b0 72 69 6e 67 20 56 56 41 0a 2a 2a 20 70 72 6f 63 ring VVA.** proc
146c0 65 73 73 65 73 20 62 75 74 20 69 73 20 61 20 6e esses but is a n
146d0 6f 2d 6f 70 20 66 6f 72 20 64 65 6c 69 76 65 72 o-op for deliver
146e0 79 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c y..*/.#ifdef SQL
146f0 49 54 45 5f 44 45 42 55 47 0a 23 20 64 65 66 69 ITE_DEBUG.# defi
14700 6e 65 20 45 78 70 72 53 65 74 56 56 41 50 72 6f ne ExprSetVVAPro
14710 70 65 72 74 79 28 45 2c 50 29 20 20 28 45 29 2d perty(E,P) (E)-
14720 3e 66 6c 61 67 73 7c 3d 28 50 29 0a 23 65 6c 73 >flags|=(P).#els
14730 65 0a 23 20 64 65 66 69 6e 65 20 45 78 70 72 53 e.# define ExprS
14740 65 74 56 56 41 50 72 6f 70 65 72 74 79 28 45 2c etVVAProperty(E,
14750 50 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a P).#endif../*.**
14760 20 4d 61 63 72 6f 73 20 74 6f 20 64 65 74 65 72 Macros to deter
14770 6d 69 6e 65 20 74 68 65 20 6e 75 6d 62 65 72 20 mine the number
14780 6f 66 20 62 79 74 65 73 20 72 65 71 75 69 72 65 of bytes require
14790 64 20 62 79 20 61 20 6e 6f 72 6d 61 6c 20 45 78 d by a normal Ex
147a0 70 72 20 0a 2a 2a 20 73 74 72 75 63 74 2c 20 61 pr .** struct, a
147b0 6e 20 45 78 70 72 20 73 74 72 75 63 74 20 77 69 n Expr struct wi
147c0 74 68 20 74 68 65 20 45 50 5f 52 65 64 75 63 65 th the EP_Reduce
147d0 64 20 66 6c 61 67 20 73 65 74 20 69 6e 20 45 78 d flag set in Ex
147e0 70 72 2e 66 6c 61 67 73 20 0a 2a 2a 20 61 6e 64 pr.flags .** and
147f0 20 61 6e 20 45 78 70 72 20 73 74 72 75 63 74 20 an Expr struct
14800 77 69 74 68 20 74 68 65 20 45 50 5f 54 6f 6b 65 with the EP_Toke
14810 6e 4f 6e 6c 79 20 66 6c 61 67 20 73 65 74 2e 0a nOnly flag set..
14820 2a 2f 0a 23 64 65 66 69 6e 65 20 45 58 50 52 5f */.#define EXPR_
14830 46 55 4c 4c 53 49 5a 45 20 20 20 20 20 20 20 20 FULLSIZE
14840 20 20 20 73 69 7a 65 6f 66 28 45 78 70 72 29 20 sizeof(Expr)
14850 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 75 6c /* Ful
14860 6c 20 73 69 7a 65 20 2a 2f 0a 23 64 65 66 69 6e l size */.#defin
14870 65 20 45 58 50 52 5f 52 45 44 55 43 45 44 53 49 e EXPR_REDUCEDSI
14880 5a 45 20 20 20 20 20 20 20 20 6f 66 66 73 65 74 ZE offset
14890 6f 66 28 45 78 70 72 2c 69 54 61 62 6c 65 29 20 of(Expr,iTable)
148a0 20 2f 2a 20 43 6f 6d 6d 6f 6e 20 66 65 61 74 75 /* Common featu
148b0 72 65 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45 res */.#define E
148c0 58 50 52 5f 54 4f 4b 45 4e 4f 4e 4c 59 53 49 5a XPR_TOKENONLYSIZ
148d0 45 20 20 20 20 20 20 6f 66 66 73 65 74 6f 66 28 E offsetof(
148e0 45 78 70 72 2c 70 4c 65 66 74 29 20 20 20 2f 2a Expr,pLeft) /*
148f0 20 46 65 77 65 72 20 66 65 61 74 75 72 65 73 20 Fewer features
14900 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 46 6c 61 67 73 20 */../*.** Flags
14910 70 61 73 73 65 64 20 74 6f 20 74 68 65 20 73 71 passed to the sq
14920 6c 69 74 65 33 45 78 70 72 44 75 70 28 29 20 66 lite3ExprDup() f
14930 75 6e 63 74 69 6f 6e 2e 20 53 65 65 20 74 68 65 unction. See the
14940 20 68 65 61 64 65 72 20 63 6f 6d 6d 65 6e 74 20 header comment
14950 0a 2a 2a 20 61 62 6f 76 65 20 73 71 6c 69 74 65 .** above sqlite
14960 33 45 78 70 72 44 75 70 28 29 20 66 6f 72 20 64 3ExprDup() for d
14970 65 74 61 69 6c 73 2e 0a 2a 2f 0a 23 64 65 66 69 etails..*/.#defi
14980 6e 65 20 45 58 50 52 44 55 50 5f 52 45 44 55 43 ne EXPRDUP_REDUC
14990 45 20 20 20 20 20 20 20 20 20 30 78 30 30 30 31 E 0x0001
149a0 20 20 2f 2a 20 55 73 65 64 20 72 65 64 75 63 65 /* Used reduce
149b0 64 2d 73 69 7a 65 20 45 78 70 72 20 6e 6f 64 65 d-size Expr node
149c0 73 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 20 6c 69 s */../*.** A li
149d0 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 6f 6e st of expression
149e0 73 2e 20 20 45 61 63 68 20 65 78 70 72 65 73 73 s. Each express
149f0 69 6f 6e 20 6d 61 79 20 6f 70 74 69 6f 6e 61 6c ion may optional
14a00 6c 79 20 68 61 76 65 20 61 0a 2a 2a 20 6e 61 6d ly have a.** nam
14a10 65 2e 20 20 41 6e 20 65 78 70 72 2f 6e 61 6d 65 e. An expr/name
14a20 20 63 6f 6d 62 69 6e 61 74 69 6f 6e 20 63 61 6e combination can
14a30 20 62 65 20 75 73 65 64 20 69 6e 20 73 65 76 65 be used in seve
14a40 72 61 6c 20 77 61 79 73 2c 20 73 75 63 68 0a 2a ral ways, such.*
14a50 2a 20 61 73 20 74 68 65 20 6c 69 73 74 20 6f 66 * as the list of
14a60 20 22 65 78 70 72 20 41 53 20 49 44 22 20 66 69 "expr AS ID" fi
14a70 65 6c 64 73 20 66 6f 6c 6c 6f 77 69 6e 67 20 61 elds following a
14a80 20 22 53 45 4c 45 43 54 22 20 6f 72 20 69 6e 20 "SELECT" or in
14a90 74 68 65 0a 2a 2a 20 6c 69 73 74 20 6f 66 20 22 the.** list of "
14aa0 49 44 20 3d 20 65 78 70 72 22 20 69 74 65 6d 73 ID = expr" items
14ab0 20 69 6e 20 61 6e 20 55 50 44 41 54 45 2e 20 20 in an UPDATE.
14ac0 41 20 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 A list of expres
14ad0 73 69 6f 6e 73 20 63 61 6e 0a 2a 2a 20 61 6c 73 sions can.** als
14ae0 6f 20 62 65 20 75 73 65 64 20 61 73 20 74 68 65 o be used as the
14af0 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 61 20 66 argument to a f
14b00 75 6e 63 74 69 6f 6e 2c 20 69 6e 20 77 68 69 63 unction, in whic
14b10 68 20 63 61 73 65 20 74 68 65 20 61 2e 7a 4e 61 h case the a.zNa
14b20 6d 65 0a 2a 2a 20 66 69 65 6c 64 20 69 73 20 6e me.** field is n
14b30 6f 74 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 42 ot used..**.** B
14b40 79 20 64 65 66 61 75 6c 74 20 74 68 65 20 45 78 y default the Ex
14b50 70 72 2e 7a 53 70 61 6e 20 66 69 65 6c 64 20 68 pr.zSpan field h
14b60 6f 6c 64 73 20 61 20 68 75 6d 61 6e 2d 72 65 61 olds a human-rea
14b70 64 61 62 6c 65 20 64 65 73 63 72 69 70 74 69 6f dable descriptio
14b80 6e 20 6f 66 0a 2a 2a 20 74 68 65 20 65 78 70 72 n of.** the expr
14b90 65 73 73 69 6f 6e 20 74 68 61 74 20 69 73 20 75 ession that is u
14ba0 73 65 64 20 69 6e 20 74 68 65 20 67 65 6e 65 72 sed in the gener
14bb0 61 74 69 6f 6e 20 6f 66 20 65 72 72 6f 72 20 6d ation of error m
14bc0 65 73 73 61 67 65 73 20 61 6e 64 0a 2a 2a 20 63 essages and.** c
14bd0 6f 6c 75 6d 6e 20 6c 61 62 65 6c 73 2e 20 20 49 olumn labels. I
14be0 6e 20 74 68 69 73 20 63 61 73 65 2c 20 45 78 70 n this case, Exp
14bf0 72 2e 7a 53 70 61 6e 20 69 73 20 74 79 70 69 63 r.zSpan is typic
14c00 61 6c 6c 79 20 74 68 65 20 74 65 78 74 20 6f 66 ally the text of
14c10 20 61 0a 2a 2a 20 63 6f 6c 75 6d 6e 20 65 78 70 a.** column exp
14c20 72 65 73 73 69 6f 6e 20 61 73 20 69 74 20 65 78 ression as it ex
14c30 69 73 74 73 20 69 6e 20 61 20 53 45 4c 45 43 54 ists in a SELECT
14c40 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 48 6f 77 statement. How
14c50 65 76 65 72 2c 20 69 66 0a 2a 2a 20 74 68 65 20 ever, if.** the
14c60 62 53 70 61 6e 49 73 54 61 62 20 66 6c 61 67 20 bSpanIsTab flag
14c70 69 73 20 73 65 74 2c 20 74 68 65 6e 20 7a 53 70 is set, then zSp
14c80 61 6e 20 69 73 20 6f 76 65 72 6c 6f 61 64 65 64 an is overloaded
14c90 20 74 6f 20 6d 65 61 6e 20 74 68 65 20 6e 61 6d to mean the nam
14ca0 65 0a 2a 2a 20 6f 66 20 74 68 65 20 72 65 73 75 e.** of the resu
14cb0 6c 74 20 63 6f 6c 75 6d 6e 20 69 6e 20 74 68 65 lt column in the
14cc0 20 66 6f 72 6d 3a 20 44 41 54 41 42 41 53 45 2e form: DATABASE.
14cd0 54 41 42 4c 45 2e 43 4f 4c 55 4d 4e 2e 20 20 54 TABLE.COLUMN. T
14ce0 68 69 73 20 6c 61 74 65 72 0a 2a 2a 20 66 6f 72 his later.** for
14cf0 6d 20 69 73 20 75 73 65 64 20 66 6f 72 20 6e 61 m is used for na
14d00 6d 65 20 72 65 73 6f 6c 75 74 69 6f 6e 20 77 69 me resolution wi
14d10 74 68 20 6e 65 73 74 65 64 20 46 52 4f 4d 20 63 th nested FROM c
14d20 6c 61 75 73 65 73 2e 0a 2a 2f 0a 73 74 72 75 63 lauses..*/.struc
14d30 74 20 45 78 70 72 4c 69 73 74 20 7b 0a 20 20 69 t ExprList {. i
14d40 6e 74 20 6e 45 78 70 72 3b 20 20 20 20 20 20 20 nt nExpr;
14d50 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
14d60 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 6f of expressions o
14d70 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 20 20 n the list */.
14d80 73 74 72 75 63 74 20 45 78 70 72 4c 69 73 74 5f struct ExprList_
14d90 69 74 65 6d 20 7b 20 2f 2a 20 46 6f 72 20 65 61 item { /* For ea
14da0 63 68 20 65 78 70 72 65 73 73 69 6f 6e 20 69 6e ch expression in
14db0 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 20 20 20 the list */.
14dc0 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 20 20 Expr *pExpr;
14dd0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
14de0 6c 69 73 74 20 6f 66 20 65 78 70 72 65 73 73 69 list of expressi
14df0 6f 6e 73 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 ons */. char
14e00 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
14e10 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 61 73 73 6f /* Token asso
14e20 63 69 61 74 65 64 20 77 69 74 68 20 74 68 69 73 ciated with this
14e30 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f 0a 20 expression */.
14e40 20 20 20 63 68 61 72 20 2a 7a 53 70 61 6e 3b 20 char *zSpan;
14e50 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4f 72 /* Or
14e60 69 67 69 6e 61 6c 20 74 65 78 74 20 6f 66 20 74 iginal text of t
14e70 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 2a 2f he expression */
14e80 0a 20 20 20 20 75 38 20 73 6f 72 74 4f 72 64 65 . u8 sortOrde
14e90 72 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 r; /*
14ea0 31 20 66 6f 72 20 44 45 53 43 20 6f 72 20 30 20 1 for DESC or 0
14eb0 66 6f 72 20 41 53 43 20 2a 2f 0a 20 20 20 20 75 for ASC */. u
14ec0 6e 73 69 67 6e 65 64 20 64 6f 6e 65 20 3a 31 3b nsigned done :1;
14ed0 20 20 20 20 20 20 20 2f 2a 20 41 20 66 6c 61 67 /* A flag
14ee0 20 74 6f 20 69 6e 64 69 63 61 74 65 20 77 68 65 to indicate whe
14ef0 6e 20 70 72 6f 63 65 73 73 69 6e 67 20 69 73 20 n processing is
14f00 66 69 6e 69 73 68 65 64 20 2a 2f 0a 20 20 20 20 finished */.
14f10 75 6e 73 69 67 6e 65 64 20 62 53 70 61 6e 49 73 unsigned bSpanIs
14f20 54 61 62 20 3a 31 3b 20 2f 2a 20 7a 53 70 61 6e Tab :1; /* zSpan
14f30 20 68 6f 6c 64 73 20 44 42 2e 54 41 42 4c 45 2e holds DB.TABLE.
14f40 43 4f 4c 55 4d 4e 20 2a 2f 0a 20 20 20 20 75 6e COLUMN */. un
14f50 73 69 67 6e 65 64 20 72 65 75 73 61 62 6c 65 20 signed reusable
14f60 3a 31 3b 20 20 20 2f 2a 20 43 6f 6e 73 74 61 6e :1; /* Constan
14f70 74 20 65 78 70 72 65 73 73 69 6f 6e 20 69 73 20 t expression is
14f80 72 65 75 73 61 62 6c 65 20 2a 2f 0a 20 20 20 20 reusable */.
14f90 75 6e 69 6f 6e 20 7b 0a 20 20 20 20 20 20 73 74 union {. st
14fa0 72 75 63 74 20 7b 0a 20 20 20 20 20 20 20 20 75 ruct {. u
14fb0 31 36 20 69 4f 72 64 65 72 42 79 43 6f 6c 3b 20 16 iOrderByCol;
14fc0 20 20 20 20 20 2f 2a 20 46 6f 72 20 4f 52 44 45 /* For ORDE
14fd0 52 20 42 59 2c 20 63 6f 6c 75 6d 6e 20 6e 75 6d R BY, column num
14fe0 62 65 72 20 69 6e 20 72 65 73 75 6c 74 20 73 65 ber in result se
14ff0 74 20 2a 2f 0a 20 20 20 20 20 20 20 20 75 31 36 t */. u16
15000 20 69 41 6c 69 61 73 3b 20 20 20 20 20 20 20 20 iAlias;
15010 20 20 20 2f 2a 20 49 6e 64 65 78 20 69 6e 74 6f /* Index into
15020 20 50 61 72 73 65 2e 61 41 6c 69 61 73 5b 5d 20 Parse.aAlias[]
15030 66 6f 72 20 7a 4e 61 6d 65 20 2a 2f 0a 20 20 20 for zName */.
15040 20 20 20 7d 20 78 3b 0a 20 20 20 20 20 20 69 6e } x;. in
15050 74 20 69 43 6f 6e 73 74 45 78 70 72 52 65 67 3b t iConstExprReg;
15060 20 20 20 20 20 20 2f 2a 20 52 65 67 69 73 74 65 /* Registe
15070 72 20 69 6e 20 77 68 69 63 68 20 45 78 70 72 20 r in which Expr
15080 76 61 6c 75 65 20 69 73 20 63 61 63 68 65 64 20 value is cached
15090 2a 2f 0a 20 20 20 20 7d 20 75 3b 0a 20 20 7d 20 */. } u;. }
150a0 2a 61 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 *a;
150b0 20 20 20 20 20 2f 2a 20 41 6c 6c 6f 63 20 61 20 /* Alloc a
150c0 70 6f 77 65 72 20 6f 66 20 74 77 6f 20 67 72 65 power of two gre
150d0 61 74 65 72 20 6f 72 20 65 71 75 61 6c 20 74 6f ater or equal to
150e0 20 6e 45 78 70 72 20 2a 2f 0a 7d 3b 0a 0a 2f 2a nExpr */.};../*
150f0 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 .** An instance
15100 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 of this structur
15110 65 20 69 73 20 75 73 65 64 20 62 79 20 74 68 65 e is used by the
15120 20 70 61 72 73 65 72 20 74 6f 20 72 65 63 6f 72 parser to recor
15130 64 20 62 6f 74 68 0a 2a 2a 20 74 68 65 20 70 61 d both.** the pa
15140 72 73 65 20 74 72 65 65 20 66 6f 72 20 61 6e 20 rse tree for an
15150 65 78 70 72 65 73 73 69 6f 6e 20 61 6e 64 20 74 expression and t
15160 68 65 20 73 70 61 6e 20 6f 66 20 69 6e 70 75 74 he span of input
15170 20 74 65 78 74 20 66 6f 72 20 61 6e 0a 2a 2a 20 text for an.**
15180 65 78 70 72 65 73 73 69 6f 6e 2e 0a 2a 2f 0a 73 expression..*/.s
15190 74 72 75 63 74 20 45 78 70 72 53 70 61 6e 20 7b truct ExprSpan {
151a0 0a 20 20 45 78 70 72 20 2a 70 45 78 70 72 3b 20 . Expr *pExpr;
151b0 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 /* The
151c0 65 78 70 72 65 73 73 69 6f 6e 20 70 61 72 73 65 expression parse
151d0 20 74 72 65 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 tree */. const
151e0 20 63 68 61 72 20 2a 7a 53 74 61 72 74 3b 20 20 char *zStart;
151f0 20 2f 2a 20 46 69 72 73 74 20 63 68 61 72 61 63 /* First charac
15200 74 65 72 20 6f 66 20 69 6e 70 75 74 20 74 65 78 ter of input tex
15210 74 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 t */. const cha
15220 72 20 2a 7a 45 6e 64 3b 20 20 20 20 20 2f 2a 20 r *zEnd; /*
15230 4f 6e 65 20 63 68 61 72 61 63 74 65 72 20 70 61 One character pa
15240 73 74 20 74 68 65 20 65 6e 64 20 6f 66 20 69 6e st the end of in
15250 70 75 74 20 74 65 78 74 20 2a 2f 0a 7d 3b 0a 0a put text */.};..
15260 2f 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 /*.** An instanc
15270 65 20 6f 66 20 74 68 69 73 20 73 74 72 75 63 74 e of this struct
15280 75 72 65 20 63 61 6e 20 68 6f 6c 64 20 61 20 73 ure can hold a s
15290 69 6d 70 6c 65 20 6c 69 73 74 20 6f 66 20 69 64 imple list of id
152a0 65 6e 74 69 66 69 65 72 73 2c 0a 2a 2a 20 73 75 entifiers,.** su
152b0 63 68 20 61 73 20 74 68 65 20 6c 69 73 74 20 22 ch as the list "
152c0 61 2c 62 2c 63 22 20 69 6e 20 74 68 65 20 66 6f a,b,c" in the fo
152d0 6c 6c 6f 77 69 6e 67 20 73 74 61 74 65 6d 65 6e llowing statemen
152e0 74 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 20 49 ts:.**.** I
152f0 4e 53 45 52 54 20 49 4e 54 4f 20 74 28 61 2c 62 NSERT INTO t(a,b
15300 2c 63 29 20 56 41 4c 55 45 53 20 2e 2e 2e 3b 0a ,c) VALUES ...;.
15310 2a 2a 20 20 20 20 20 20 43 52 45 41 54 45 20 49 ** CREATE I
15320 4e 44 45 58 20 69 64 78 20 4f 4e 20 74 28 61 2c NDEX idx ON t(a,
15330 62 2c 63 29 3b 0a 2a 2a 20 20 20 20 20 20 43 52 b,c);.** CR
15340 45 41 54 45 20 54 52 49 47 47 45 52 20 74 72 69 EATE TRIGGER tri
15350 67 20 42 45 46 4f 52 45 20 55 50 44 41 54 45 20 g BEFORE UPDATE
15360 4f 4e 20 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 3b ON t(a,b,c) ...;
15370 0a 2a 2a 0a 2a 2a 20 54 68 65 20 49 64 4c 69 73 .**.** The IdLis
15380 74 2e 61 2e 69 64 78 20 66 69 65 6c 64 20 69 73 t.a.idx field is
15390 20 75 73 65 64 20 77 68 65 6e 20 74 68 65 20 49 used when the I
153a0 64 4c 69 73 74 20 72 65 70 72 65 73 65 6e 74 73 dList represents
153b0 20 74 68 65 20 6c 69 73 74 20 6f 66 0a 2a 2a 20 the list of.**
153c0 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 66 74 column names aft
153d0 65 72 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 20 er a table name
153e0 69 6e 20 61 6e 20 49 4e 53 45 52 54 20 73 74 61 in an INSERT sta
153f0 74 65 6d 65 6e 74 2e 20 20 49 6e 20 74 68 65 20 tement. In the
15400 73 74 61 74 65 6d 65 6e 74 0a 2a 2a 0a 2a 2a 20 statement.**.**
15410 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 INSERT INTO
15420 74 28 61 2c 62 2c 63 29 20 2e 2e 2e 0a 2a 2a 0a t(a,b,c) ....**.
15430 2a 2a 20 49 66 20 22 61 22 20 69 73 20 74 68 65 ** If "a" is the
15440 20 6b 2d 74 68 20 63 6f 6c 75 6d 6e 20 6f 66 20 k-th column of
15450 74 61 62 6c 65 20 22 74 22 2c 20 74 68 65 6e 20 table "t", then
15460 49 64 4c 69 73 74 2e 61 5b 30 5d 2e 69 64 78 3d IdList.a[0].idx=
15470 3d 6b 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 49 64 =k..*/.struct Id
15480 4c 69 73 74 20 7b 0a 20 20 73 74 72 75 63 74 20 List {. struct
15490 49 64 4c 69 73 74 5f 69 74 65 6d 20 7b 0a 20 20 IdList_item {.
154a0 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 20 char *zName;
154b0 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f 66 20 74 /* Name of t
154c0 68 65 20 69 64 65 6e 74 69 66 69 65 72 20 2a 2f he identifier */
154d0 0a 20 20 20 20 69 6e 74 20 69 64 78 3b 20 20 20 . int idx;
154e0 20 20 20 20 20 20 20 2f 2a 20 49 6e 64 65 78 20 /* Index
154f0 69 6e 20 73 6f 6d 65 20 54 61 62 6c 65 2e 61 43 in some Table.aC
15500 6f 6c 5b 5d 20 6f 66 20 61 20 63 6f 6c 75 6d 6e ol[] of a column
15510 20 6e 61 6d 65 64 20 7a 4e 61 6d 65 20 2a 2f 0a named zName */.
15520 20 20 7d 20 2a 61 3b 0a 20 20 69 6e 74 20 6e 49 } *a;. int nI
15530 64 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 d; /* Nu
15540 6d 62 65 72 20 6f 66 20 69 64 65 6e 74 69 66 69 mber of identifi
15550 65 72 73 20 6f 6e 20 74 68 65 20 6c 69 73 74 20 ers on the list
15560 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 */.};../*.** The
15570 20 62 69 74 6d 61 73 6b 20 64 61 74 61 74 79 70 bitmask datatyp
15580 65 20 64 65 66 69 6e 65 64 20 62 65 6c 6f 77 20 e defined below
15590 69 73 20 75 73 65 64 20 66 6f 72 20 76 61 72 69 is used for vari
155a0 6f 75 73 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e ous optimization
155b0 73 2e 0a 2a 2a 0a 2a 2a 20 43 68 61 6e 67 69 6e s..**.** Changin
155c0 67 20 74 68 69 73 20 66 72 6f 6d 20 61 20 36 34 g this from a 64
155d0 2d 62 69 74 20 74 6f 20 61 20 33 32 2d 62 69 74 -bit to a 32-bit
155e0 20 74 79 70 65 20 6c 69 6d 69 74 73 20 74 68 65 type limits the
155f0 20 6e 75 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 61 number of.** ta
15600 62 6c 65 73 20 69 6e 20 61 20 6a 6f 69 6e 20 74 bles in a join t
15610 6f 20 33 32 20 69 6e 73 74 65 61 64 20 6f 66 20 o 32 instead of
15620 36 34 2e 20 20 42 75 74 20 69 74 20 61 6c 73 6f 64. But it also
15630 20 72 65 64 75 63 65 73 20 74 68 65 20 73 69 7a reduces the siz
15640 65 0a 2a 2a 20 6f 66 20 74 68 65 20 6c 69 62 72 e.** of the libr
15650 61 72 79 20 62 79 20 37 33 38 20 62 79 74 65 73 ary by 738 bytes
15660 20 6f 6e 20 69 78 38 36 2e 0a 2a 2f 0a 74 79 70 on ix86..*/.typ
15670 65 64 65 66 20 75 36 34 20 42 69 74 6d 61 73 6b edef u64 Bitmask
15680 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 6e 75 6d ;../*.** The num
15690 62 65 72 20 6f 66 20 62 69 74 73 20 69 6e 20 61 ber of bits in a
156a0 20 42 69 74 6d 61 73 6b 2e 20 20 22 42 4d 53 22 Bitmask. "BMS"
156b0 20 6d 65 61 6e 73 20 22 42 69 74 4d 61 73 6b 20 means "BitMask
156c0 53 69 7a 65 22 2e 0a 2a 2f 0a 23 64 65 66 69 6e Size"..*/.#defin
156d0 65 20 42 4d 53 20 20 28 28 69 6e 74 29 28 73 69 e BMS ((int)(si
156e0 7a 65 6f 66 28 42 69 74 6d 61 73 6b 29 2a 38 29 zeof(Bitmask)*8)
156f0 29 0a 0a 2f 2a 0a 2a 2a 20 41 20 62 69 74 20 69 )../*.** A bit i
15700 6e 20 61 20 42 69 74 6d 61 73 6b 0a 2a 2f 0a 23 n a Bitmask.*/.#
15710 64 65 66 69 6e 65 20 4d 41 53 4b 42 49 54 28 6e define MASKBIT(n
15720 29 20 20 20 28 28 28 42 69 74 6d 61 73 6b 29 31 ) (((Bitmask)1
15730 29 3c 3c 28 6e 29 29 0a 23 64 65 66 69 6e 65 20 )<<(n)).#define
15740 4d 41 53 4b 42 49 54 33 32 28 6e 29 20 28 28 28 MASKBIT32(n) (((
15750 75 6e 73 69 67 6e 65 64 20 69 6e 74 29 31 29 3c unsigned int)1)<
15760 3c 28 6e 29 29 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 <(n))../*.** The
15770 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 following struc
15780 74 75 72 65 20 64 65 73 63 72 69 62 65 73 20 74 ture describes t
15790 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 6f he FROM clause o
157a0 66 20 61 20 53 45 4c 45 43 54 20 73 74 61 74 65 f a SELECT state
157b0 6d 65 6e 74 2e 0a 2a 2a 20 45 61 63 68 20 74 61 ment..** Each ta
157c0 62 6c 65 20 6f 72 20 73 75 62 71 75 65 72 79 20 ble or subquery
157d0 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 75 in the FROM clau
157e0 73 65 20 69 73 20 61 20 73 65 70 61 72 61 74 65 se is a separate
157f0 20 65 6c 65 6d 65 6e 74 20 6f 66 0a 2a 2a 20 74 element of.** t
15800 68 65 20 53 72 63 4c 69 73 74 2e 61 5b 5d 20 61 he SrcList.a[] a
15810 72 72 61 79 2e 0a 2a 2a 0a 2a 2a 20 57 69 74 68 rray..**.** With
15820 20 74 68 65 20 61 64 64 69 74 69 6f 6e 20 6f 66 the addition of
15830 20 6d 75 6c 74 69 70 6c 65 20 64 61 74 61 62 61 multiple databa
15840 73 65 20 73 75 70 70 6f 72 74 2c 20 74 68 65 20 se support, the
15850 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 75 63 74 following struct
15860 75 72 65 0a 2a 2a 20 63 61 6e 20 61 6c 73 6f 20 ure.** can also
15870 62 65 20 75 73 65 64 20 74 6f 20 64 65 73 63 72 be used to descr
15880 69 62 65 20 61 20 70 61 72 74 69 63 75 6c 61 72 ibe a particular
15890 20 74 61 62 6c 65 20 73 75 63 68 20 61 73 20 74 table such as t
158a0 68 65 20 74 61 62 6c 65 20 74 68 61 74 0a 2a 2a he table that.**
158b0 20 69 73 20 6d 6f 64 69 66 69 65 64 20 62 79 20 is modified by
158c0 61 6e 20 49 4e 53 45 52 54 2c 20 44 45 4c 45 54 an INSERT, DELET
158d0 45 2c 20 6f 72 20 55 50 44 41 54 45 20 73 74 61 E, or UPDATE sta
158e0 74 65 6d 65 6e 74 2e 20 20 49 6e 20 73 74 61 6e tement. In stan
158f0 64 61 72 64 20 53 51 4c 2c 0a 2a 2a 20 73 75 63 dard SQL,.** suc
15900 68 20 61 20 74 61 62 6c 65 20 6d 75 73 74 20 62 h a table must b
15910 65 20 61 20 73 69 6d 70 6c 65 20 6e 61 6d 65 3a e a simple name:
15920 20 49 44 2e 20 20 42 75 74 20 69 6e 20 53 51 4c ID. But in SQL
15930 69 74 65 2c 20 74 68 65 20 74 61 62 6c 65 20 63 ite, the table c
15940 61 6e 0a 2a 2a 20 6e 6f 77 20 62 65 20 69 64 65 an.** now be ide
15950 6e 74 69 66 69 65 64 20 62 79 20 61 20 64 61 74 ntified by a dat
15960 61 62 61 73 65 20 6e 61 6d 65 2c 20 61 20 64 6f abase name, a do
15970 74 2c 20 74 68 65 6e 20 74 68 65 20 74 61 62 6c t, then the tabl
15980 65 20 6e 61 6d 65 3a 20 49 44 2e 49 44 2e 0a 2a e name: ID.ID..*
15990 2a 0a 2a 2a 20 54 68 65 20 6a 6f 69 6e 74 79 70 *.** The jointyp
159a0 65 20 73 74 61 72 74 73 20 6f 75 74 20 73 68 6f e starts out sho
159b0 77 69 6e 67 20 74 68 65 20 6a 6f 69 6e 20 74 79 wing the join ty
159c0 70 65 20 62 65 74 77 65 65 6e 20 74 68 65 20 63 pe between the c
159d0 75 72 72 65 6e 74 20 74 61 62 6c 65 0a 2a 2a 20 urrent table.**
159e0 61 6e 64 20 74 68 65 20 6e 65 78 74 20 74 61 62 and the next tab
159f0 6c 65 20 6f 6e 20 74 68 65 20 6c 69 73 74 2e 20 le on the list.
15a00 20 54 68 65 20 70 61 72 73 65 72 20 62 75 69 6c The parser buil
15a10 64 73 20 74 68 65 20 6c 69 73 74 20 74 68 69 73 ds the list this
15a20 20 77 61 79 2e 0a 2a 2a 20 42 75 74 20 73 71 6c way..** But sql
15a30 69 74 65 33 53 72 63 4c 69 73 74 53 68 69 66 74 ite3SrcListShift
15a40 4a 6f 69 6e 54 79 70 65 28 29 20 6c 61 74 65 72 JoinType() later
15a50 20 73 68 69 66 74 73 20 74 68 65 20 6a 6f 69 6e shifts the join
15a60 74 79 70 65 73 20 73 6f 20 74 68 61 74 20 65 61 types so that ea
15a70 63 68 0a 2a 2a 20 6a 6f 69 6e 74 79 70 65 20 65 ch.** jointype e
15a80 78 70 72 65 73 73 65 73 20 74 68 65 20 6a 6f 69 xpresses the joi
15a90 6e 20 62 65 74 77 65 65 6e 20 74 68 65 20 74 61 n between the ta
15aa0 62 6c 65 20 61 6e 64 20 74 68 65 20 70 72 65 76 ble and the prev
15ab0 69 6f 75 73 20 74 61 62 6c 65 2e 0a 2a 2a 0a 2a ious table..**.*
15ac0 2a 20 49 6e 20 74 68 65 20 63 6f 6c 55 73 65 64 * In the colUsed
15ad0 20 66 69 65 6c 64 2c 20 74 68 65 20 68 69 67 68 field, the high
15ae0 2d 6f 72 64 65 72 20 62 69 74 20 28 62 69 74 20 -order bit (bit
15af0 36 33 29 20 69 73 20 73 65 74 20 69 66 20 74 68 63) is set if th
15b00 65 20 74 61 62 6c 65 0a 2a 2a 20 63 6f 6e 74 61 e table.** conta
15b10 69 6e 73 20 6d 6f 72 65 20 74 68 61 6e 20 36 33 ins more than 63
15b20 20 63 6f 6c 75 6d 6e 73 20 61 6e 64 20 74 68 65 columns and the
15b30 20 36 34 2d 74 68 20 6f 72 20 6c 61 74 65 72 20 64-th or later
15b40 63 6f 6c 75 6d 6e 20 69 73 20 75 73 65 64 2e 0a column is used..
15b50 2a 2f 0a 73 74 72 75 63 74 20 53 72 63 4c 69 73 */.struct SrcLis
15b60 74 20 7b 0a 20 20 69 6e 74 20 6e 53 72 63 3b 20 t {. int nSrc;
15b70 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
15b80 20 6f 66 20 74 61 62 6c 65 73 20 6f 72 20 73 75 of tables or su
15b90 62 71 75 65 72 69 65 73 20 69 6e 20 74 68 65 20 bqueries in the
15ba0 46 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 FROM clause */.
15bb0 20 75 33 32 20 6e 41 6c 6c 6f 63 3b 20 20 20 20 u32 nAlloc;
15bc0 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 65 /* Number of e
15bd0 6e 74 72 69 65 73 20 61 6c 6c 6f 63 61 74 65 64 ntries allocated
15be0 20 69 6e 20 61 5b 5d 20 62 65 6c 6f 77 20 2a 2f in a[] below */
15bf0 0a 20 20 73 74 72 75 63 74 20 53 72 63 4c 69 73 . struct SrcLis
15c00 74 5f 69 74 65 6d 20 7b 0a 20 20 20 20 53 63 68 t_item {. Sch
15c10 65 6d 61 20 2a 70 53 63 68 65 6d 61 3b 20 20 2f ema *pSchema; /
15c20 2a 20 53 63 68 65 6d 61 20 74 6f 20 77 68 69 63 * Schema to whic
15c30 68 20 74 68 69 73 20 69 74 65 6d 20 69 73 20 66 h this item is f
15c40 69 78 65 64 20 2a 2f 0a 20 20 20 20 63 68 61 72 ixed */. char
15c50 20 2a 7a 44 61 74 61 62 61 73 65 3b 20 20 2f 2a *zDatabase; /*
15c60 20 4e 61 6d 65 20 6f 66 20 64 61 74 61 62 61 73 Name of databas
15c70 65 20 68 6f 6c 64 69 6e 67 20 74 68 69 73 20 74 e holding this t
15c80 61 62 6c 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 able */. char
15c90 20 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 2f 2a *zName; /*
15ca0 20 4e 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 Name of the tab
15cb0 6c 65 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a le */. char *
15cc0 7a 41 6c 69 61 73 3b 20 20 20 20 20 2f 2a 20 54 zAlias; /* T
15cd0 68 65 20 22 42 22 20 70 61 72 74 20 6f 66 20 61 he "B" part of a
15ce0 20 22 41 20 41 53 20 42 22 20 70 68 72 61 73 65 "A AS B" phrase
15cf0 2e 20 20 7a 4e 61 6d 65 20 69 73 20 74 68 65 20 . zName is the
15d00 22 41 22 20 2a 2f 0a 20 20 20 20 54 61 62 6c 65 "A" */. Table
15d10 20 2a 70 54 61 62 3b 20 20 20 20 20 20 2f 2a 20 *pTab; /*
15d20 41 6e 20 53 51 4c 20 74 61 62 6c 65 20 63 6f 72 An SQL table cor
15d30 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f 20 7a 4e responding to zN
15d40 61 6d 65 20 2a 2f 0a 20 20 20 20 53 65 6c 65 63 ame */. Selec
15d50 74 20 2a 70 53 65 6c 65 63 74 3b 20 20 2f 2a 20 t *pSelect; /*
15d60 41 20 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 A SELECT stateme
15d70 6e 74 20 75 73 65 64 20 69 6e 20 70 6c 61 63 65 nt used in place
15d80 20 6f 66 20 61 20 74 61 62 6c 65 20 6e 61 6d 65 of a table name
15d90 20 2a 2f 0a 20 20 20 20 69 6e 74 20 61 64 64 72 */. int addr
15da0 46 69 6c 6c 53 75 62 3b 20 20 2f 2a 20 41 64 64 FillSub; /* Add
15db0 72 65 73 73 20 6f 66 20 73 75 62 72 6f 75 74 69 ress of subrouti
15dc0 6e 65 20 74 6f 20 6d 61 6e 69 66 65 73 74 20 61 ne to manifest a
15dd0 20 73 75 62 71 75 65 72 79 20 2a 2f 0a 20 20 20 subquery */.
15de0 20 69 6e 74 20 72 65 67 52 65 74 75 72 6e 3b 20 int regReturn;
15df0 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 /* Register h
15e00 6f 6c 64 69 6e 67 20 72 65 74 75 72 6e 20 61 64 olding return ad
15e10 64 72 65 73 73 20 6f 66 20 61 64 64 72 46 69 6c dress of addrFil
15e20 6c 53 75 62 20 2a 2f 0a 20 20 20 20 69 6e 74 20 lSub */. int
15e30 72 65 67 52 65 73 75 6c 74 3b 20 20 20 20 2f 2a regResult; /*
15e40 20 52 65 67 69 73 74 65 72 73 20 68 6f 6c 64 69 Registers holdi
15e50 6e 67 20 72 65 73 75 6c 74 73 20 6f 66 20 61 20 ng results of a
15e60 63 6f 2d 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 co-routine */.
15e70 20 20 75 38 20 6a 6f 69 6e 74 79 70 65 3b 20 20 u8 jointype;
15e80 20 20 20 20 2f 2a 20 54 79 70 65 20 6f 66 20 6a /* Type of j
15e90 6f 69 6e 20 62 65 74 77 65 65 6e 20 74 68 69 73 oin between this
15ea0 20 61 62 6c 65 20 61 6e 64 20 74 68 65 20 70 72 able and the pr
15eb0 65 76 69 6f 75 73 20 2a 2f 0a 20 20 20 20 75 6e evious */. un
15ec0 73 69 67 6e 65 64 20 6e 6f 74 49 6e 64 65 78 65 signed notIndexe
15ed0 64 20 3a 31 3b 20 20 20 20 2f 2a 20 54 72 75 65 d :1; /* True
15ee0 20 69 66 20 74 68 65 72 65 20 69 73 20 61 20 4e if there is a N
15ef0 4f 54 20 49 4e 44 45 58 45 44 20 63 6c 61 75 73 OT INDEXED claus
15f00 65 20 2a 2f 0a 20 20 20 20 75 6e 73 69 67 6e 65 e */. unsigne
15f10 64 20 69 73 43 6f 72 72 65 6c 61 74 65 64 20 3a d isCorrelated :
15f20 31 3b 20 20 2f 2a 20 54 72 75 65 20 69 66 20 73 1; /* True if s
15f30 75 62 2d 71 75 65 72 79 20 69 73 20 63 6f 72 72 ub-query is corr
15f40 65 6c 61 74 65 64 20 2a 2f 0a 20 20 20 20 75 6e elated */. un
15f50 73 69 67 6e 65 64 20 76 69 61 43 6f 72 6f 75 74 signed viaCorout
15f60 69 6e 65 20 3a 31 3b 20 20 2f 2a 20 49 6d 70 6c ine :1; /* Impl
15f70 65 6d 65 6e 74 65 64 20 61 73 20 61 20 63 6f 2d emented as a co-
15f80 72 6f 75 74 69 6e 65 20 2a 2f 0a 20 20 20 20 75 routine */. u
15f90 6e 73 69 67 6e 65 64 20 69 73 52 65 63 75 72 73 nsigned isRecurs
15fa0 69 76 65 20 3a 31 3b 20 20 20 2f 2a 20 54 72 75 ive :1; /* Tru
15fb0 65 20 66 6f 72 20 72 65 63 75 72 73 69 76 65 20 e for recursive
15fc0 72 65 66 65 72 65 6e 63 65 20 69 6e 20 57 49 54 reference in WIT
15fd0 48 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 51 4c H */.#ifndef SQL
15fe0 49 54 45 5f 4f 4d 49 54 5f 45 58 50 4c 41 49 4e ITE_OMIT_EXPLAIN
15ff0 0a 20 20 20 20 75 38 20 69 53 65 6c 65 63 74 49 . u8 iSelectI
16000 64 3b 20 20 20 20 20 2f 2a 20 49 66 20 70 53 65 d; /* If pSe
16010 6c 65 63 74 21 3d 30 2c 20 74 68 65 20 69 64 20 lect!=0, the id
16020 6f 66 20 74 68 65 20 73 75 62 2d 73 65 6c 65 63 of the sub-selec
16030 74 20 69 6e 20 45 51 50 20 2a 2f 0a 23 65 6e 64 t in EQP */.#end
16040 69 66 0a 20 20 20 20 69 6e 74 20 69 43 75 72 73 if. int iCurs
16050 6f 72 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 20 or; /* The
16060 56 44 42 45 20 63 75 72 73 6f 72 20 6e 75 6d 62 VDBE cursor numb
16070 65 72 20 75 73 65 64 20 74 6f 20 61 63 63 65 73 er used to acces
16080 73 20 74 68 69 73 20 74 61 62 6c 65 20 2a 2f 0a s this table */.
16090 20 20 20 20 45 78 70 72 20 2a 70 4f 6e 3b 20 20 Expr *pOn;
160a0 20 20 20 20 20 20 2f 2a 20 54 68 65 20 4f 4e 20 /* The ON
160b0 63 6c 61 75 73 65 20 6f 66 20 61 20 6a 6f 69 6e clause of a join
160c0 20 2a 2f 0a 20 20 20 20 49 64 4c 69 73 74 20 2a */. IdList *
160d0 70 55 73 69 6e 67 3b 20 20 20 2f 2a 20 54 68 65 pUsing; /* The
160e0 20 55 53 49 4e 47 20 63 6c 61 75 73 65 20 6f 66 USING clause of
160f0 20 61 20 6a 6f 69 6e 20 2a 2f 0a 20 20 20 20 42 a join */. B
16100 69 74 6d 61 73 6b 20 63 6f 6c 55 73 65 64 3b 20 itmask colUsed;
16110 20 2f 2a 20 42 69 74 20 4e 20 28 31 3c 3c 4e 29 /* Bit N (1<<N)
16120 20 73 65 74 20 69 66 20 63 6f 6c 75 6d 6e 20 4e set if column N
16130 20 6f 66 20 70 54 61 62 20 69 73 20 75 73 65 64 of pTab is used
16140 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 49 */. char *zI
16150 6e 64 65 78 3b 20 20 20 20 20 2f 2a 20 49 64 65 ndex; /* Ide
16160 6e 74 69 66 69 65 72 20 66 72 6f 6d 20 22 49 4e ntifier from "IN
16170 44 45 58 45 44 20 42 59 20 3c 7a 49 6e 64 65 78 DEXED BY <zIndex
16180 3e 22 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 20 >" clause */.
16190 20 49 6e 64 65 78 20 2a 70 49 6e 64 65 78 3b 20 Index *pIndex;
161a0 20 20 20 2f 2a 20 49 6e 64 65 78 20 73 74 72 75 /* Index stru
161b0 63 74 75 72 65 20 63 6f 72 72 65 73 70 6f 6e 64 cture correspond
161c0 69 6e 67 20 74 6f 20 7a 49 6e 64 65 78 2c 20 69 ing to zIndex, i
161d0 66 20 61 6e 79 20 2a 2f 0a 20 20 7d 20 61 5b 31 f any */. } a[1
161e0 5d 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ]; /
161f0 2a 20 4f 6e 65 20 65 6e 74 72 79 20 66 6f 72 20 * One entry for
16200 65 61 63 68 20 69 64 65 6e 74 69 66 69 65 72 20 each identifier
16210 6f 6e 20 74 68 65 20 6c 69 73 74 20 2a 2f 0a 7d on the list */.}
16220 3b 0a 0a 2f 2a 0a 2a 2a 20 50 65 72 6d 69 74 74 ;../*.** Permitt
16230 65 64 20 76 61 6c 75 65 73 20 6f 66 20 74 68 65 ed values of the
16240 20 53 72 63 4c 69 73 74 2e 61 2e 6a 6f 69 6e 74 SrcList.a.joint
16250 79 70 65 20 66 69 65 6c 64 0a 2a 2f 0a 23 64 65 ype field.*/.#de
16260 66 69 6e 65 20 4a 54 5f 49 4e 4e 45 52 20 20 20 fine JT_INNER
16270 20 20 30 78 30 30 30 31 20 20 20 20 2f 2a 20 41 0x0001 /* A
16280 6e 79 20 6b 69 6e 64 20 6f 66 20 69 6e 6e 65 72 ny kind of inner
16290 20 6f 72 20 63 72 6f 73 73 20 6a 6f 69 6e 20 2a or cross join *
162a0 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 43 52 4f /.#define JT_CRO
162b0 53 53 20 20 20 20 20 30 78 30 30 30 32 20 20 20 SS 0x0002
162c0 20 2f 2a 20 45 78 70 6c 69 63 69 74 20 75 73 65 /* Explicit use
162d0 20 6f 66 20 74 68 65 20 43 52 4f 53 53 20 6b 65 of the CROSS ke
162e0 79 77 6f 72 64 20 2a 2f 0a 23 64 65 66 69 6e 65 yword */.#define
162f0 20 4a 54 5f 4e 41 54 55 52 41 4c 20 20 20 30 78 JT_NATURAL 0x
16300 30 30 30 34 20 20 20 20 2f 2a 20 54 72 75 65 20 0004 /* True
16310 66 6f 72 20 61 20 22 6e 61 74 75 72 61 6c 22 20 for a "natural"
16320 6a 6f 69 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 join */.#define
16330 4a 54 5f 4c 45 46 54 20 20 20 20 20 20 30 78 30 JT_LEFT 0x0
16340 30 30 38 20 20 20 20 2f 2a 20 4c 65 66 74 20 6f 008 /* Left o
16350 75 74 65 72 20 6a 6f 69 6e 20 2a 2f 0a 23 64 65 uter join */.#de
16360 66 69 6e 65 20 4a 54 5f 52 49 47 48 54 20 20 20 fine JT_RIGHT
16370 20 20 30 78 30 30 31 30 20 20 20 20 2f 2a 20 52 0x0010 /* R
16380 69 67 68 74 20 6f 75 74 65 72 20 6a 6f 69 6e 20 ight outer join
16390 2a 2f 0a 23 64 65 66 69 6e 65 20 4a 54 5f 4f 55 */.#define JT_OU
163a0 54 45 52 20 20 20 20 20 30 78 30 30 32 30 20 20 TER 0x0020
163b0 20 20 2f 2a 20 54 68 65 20 22 4f 55 54 45 52 22 /* The "OUTER"
163c0 20 6b 65 79 77 6f 72 64 20 69 73 20 70 72 65 73 keyword is pres
163d0 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4a ent */.#define J
163e0 54 5f 45 52 52 4f 52 20 20 20 20 20 30 78 30 30 T_ERROR 0x00
163f0 34 30 20 20 20 20 2f 2a 20 75 6e 6b 6e 6f 77 6e 40 /* unknown
16400 20 6f 72 20 75 6e 73 75 70 70 6f 72 74 65 64 20 or unsupported
16410 6a 6f 69 6e 20 74 79 70 65 20 2a 2f 0a 0a 0a 2f join type */.../
16420 2a 0a 2a 2a 20 46 6c 61 67 73 20 61 70 70 72 6f *.** Flags appro
16430 70 72 69 61 74 65 20 66 6f 72 20 74 68 65 20 77 priate for the w
16440 63 74 72 6c 46 6c 61 67 73 20 70 61 72 61 6d 65 ctrlFlags parame
16450 74 65 72 20 6f 66 20 73 71 6c 69 74 65 33 57 68 ter of sqlite3Wh
16460 65 72 65 42 65 67 69 6e 28 29 0a 2a 2a 20 61 6e ereBegin().** an
16470 64 20 74 68 65 20 57 68 65 72 65 49 6e 66 6f 2e d the WhereInfo.
16480 77 63 74 72 6c 46 6c 61 67 73 20 6d 65 6d 62 65 wctrlFlags membe
16490 72 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 r..*/.#define WH
164a0 45 52 45 5f 4f 52 44 45 52 42 59 5f 4e 4f 52 4d ERE_ORDERBY_NORM
164b0 41 4c 20 20 20 30 78 30 30 30 30 20 2f 2a 20 4e AL 0x0000 /* N
164c0 6f 2d 6f 70 20 2a 2f 0a 23 64 65 66 69 6e 65 20 o-op */.#define
164d0 57 48 45 52 45 5f 4f 52 44 45 52 42 59 5f 4d 49 WHERE_ORDERBY_MI
164e0 4e 20 20 20 20 20 20 30 78 30 30 30 31 20 2f 2a N 0x0001 /*
164f0 20 4f 52 44 45 52 20 42 59 20 70 72 6f 63 65 73 ORDER BY proces
16500 73 69 6e 67 20 66 6f 72 20 6d 69 6e 28 29 20 66 sing for min() f
16510 75 6e 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 unc */.#define W
16520 48 45 52 45 5f 4f 52 44 45 52 42 59 5f 4d 41 58 HERE_ORDERBY_MAX
16530 20 20 20 20 20 20 30 78 30 30 30 32 20 2f 2a 20 0x0002 /*
16540 4f 52 44 45 52 20 42 59 20 70 72 6f 63 65 73 73 ORDER BY process
16550 69 6e 67 20 66 6f 72 20 6d 61 78 28 29 20 66 75 ing for max() fu
16560 6e 63 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 nc */.#define WH
16570 45 52 45 5f 4f 4e 45 50 41 53 53 5f 44 45 53 49 ERE_ONEPASS_DESI
16580 52 45 44 20 20 30 78 30 30 30 34 20 2f 2a 20 57 RED 0x0004 /* W
16590 61 6e 74 20 74 6f 20 64 6f 20 6f 6e 65 2d 70 61 ant to do one-pa
165a0 73 73 20 55 50 44 41 54 45 2f 44 45 4c 45 54 45 ss UPDATE/DELETE
165b0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
165c0 45 5f 44 55 50 4c 49 43 41 54 45 53 5f 4f 4b 20 E_DUPLICATES_OK
165d0 20 20 20 30 78 30 30 30 38 20 2f 2a 20 4f 6b 20 0x0008 /* Ok
165e0 74 6f 20 72 65 74 75 72 6e 20 61 20 72 6f 77 20 to return a row
165f0 6d 6f 72 65 20 74 68 61 6e 20 6f 6e 63 65 20 2a more than once *
16600 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f /.#define WHERE_
16610 4f 4d 49 54 5f 4f 50 45 4e 5f 43 4c 4f 53 45 20 OMIT_OPEN_CLOSE
16620 20 30 78 30 30 31 30 20 2f 2a 20 54 61 62 6c 65 0x0010 /* Table
16630 20 63 75 72 73 6f 72 73 20 61 72 65 20 61 6c 72 cursors are alr
16640 65 61 64 79 20 6f 70 65 6e 20 2a 2f 0a 23 64 65 eady open */.#de
16650 66 69 6e 65 20 57 48 45 52 45 5f 46 4f 52 43 45 fine WHERE_FORCE
16660 5f 54 41 42 4c 45 20 20 20 20 20 20 30 78 30 30 _TABLE 0x00
16670 32 30 20 2f 2a 20 44 6f 20 6e 6f 74 20 75 73 65 20 /* Do not use
16680 20 61 6e 20 69 6e 64 65 78 2d 6f 6e 6c 79 20 73 an index-only s
16690 65 61 72 63 68 20 2a 2f 0a 23 64 65 66 69 6e 65 earch */.#define
166a0 20 57 48 45 52 45 5f 4f 4e 45 54 41 42 4c 45 5f WHERE_ONETABLE_
166b0 4f 4e 4c 59 20 20 20 20 30 78 30 30 34 30 20 2f ONLY 0x0040 /
166c0 2a 20 4f 6e 6c 79 20 63 6f 64 65 20 74 68 65 20 * Only code the
166d0 31 73 74 20 74 61 62 6c 65 20 69 6e 20 70 54 61 1st table in pTa
166e0 62 4c 69 73 74 20 2a 2f 0a 23 64 65 66 69 6e 65 bList */.#define
166f0 20 57 48 45 52 45 5f 41 4e 44 5f 4f 4e 4c 59 20 WHERE_AND_ONLY
16700 20 20 20 20 20 20 20 20 30 78 30 30 38 30 20 2f 0x0080 /
16710 2a 20 44 6f 6e 27 74 20 75 73 65 20 69 6e 64 69 * Don't use indi
16720 63 65 73 20 66 6f 72 20 4f 52 20 74 65 72 6d 73 ces for OR terms
16730 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 52 */.#define WHER
16740 45 5f 47 52 4f 55 50 42 59 20 20 20 20 20 20 20 E_GROUPBY
16750 20 20 20 30 78 30 31 30 30 20 2f 2a 20 70 4f 72 0x0100 /* pOr
16760 64 65 72 42 79 20 69 73 20 72 65 61 6c 6c 79 20 derBy is really
16770 61 20 47 52 4f 55 50 20 42 59 20 2a 2f 0a 23 64 a GROUP BY */.#d
16780 65 66 69 6e 65 20 57 48 45 52 45 5f 44 49 53 54 efine WHERE_DIST
16790 49 4e 43 54 42 59 20 20 20 20 20 20 20 30 78 30 INCTBY 0x0
167a0 32 30 30 20 2f 2a 20 70 4f 72 64 65 72 62 79 20 200 /* pOrderby
167b0 69 73 20 72 65 61 6c 6c 79 20 61 20 44 49 53 54 is really a DIST
167c0 49 4e 43 54 20 63 6c 61 75 73 65 20 2a 2f 0a 23 INCT clause */.#
167d0 64 65 66 69 6e 65 20 57 48 45 52 45 5f 57 41 4e define WHERE_WAN
167e0 54 5f 44 49 53 54 49 4e 43 54 20 20 20 20 30 78 T_DISTINCT 0x
167f0 30 34 30 30 20 2f 2a 20 41 6c 6c 20 6f 75 74 70 0400 /* All outp
16800 75 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 64 ut needs to be d
16810 69 73 74 69 6e 63 74 20 2a 2f 0a 23 64 65 66 69 istinct */.#defi
16820 6e 65 20 57 48 45 52 45 5f 53 4f 52 54 42 59 47 ne WHERE_SORTBYG
16830 52 4f 55 50 20 20 20 20 20 20 30 78 30 38 30 30 ROUP 0x0800
16840 20 2f 2a 20 53 75 70 70 6f 72 74 20 73 71 6c 69 /* Support sqli
16850 74 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 te3WhereIsSorted
16860 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 () */.#define WH
16870 45 52 45 5f 52 45 4f 50 45 4e 5f 49 44 58 20 20 ERE_REOPEN_IDX
16880 20 20 20 20 20 30 78 31 30 30 30 20 2f 2a 20 54 0x1000 /* T
16890 72 79 20 74 6f 20 75 73 65 20 4f 50 5f 52 65 6f ry to use OP_Reo
168a0 70 65 6e 49 64 78 20 2a 2f 0a 0a 2f 2a 20 41 6c penIdx */../* Al
168b0 6c 6f 77 65 64 20 72 65 74 75 72 6e 20 76 61 6c lowed return val
168c0 75 65 73 20 66 72 6f 6d 20 73 71 6c 69 74 65 33 ues from sqlite3
168d0 57 68 65 72 65 49 73 44 69 73 74 69 6e 63 74 28 WhereIsDistinct(
168e0 29 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 57 48 45 ).*/.#define WHE
168f0 52 45 5f 44 49 53 54 49 4e 43 54 5f 4e 4f 4f 50 RE_DISTINCT_NOOP
16900 20 20 20 20 20 20 30 20 20 2f 2a 20 44 49 53 54 0 /* DIST
16910 49 4e 43 54 20 6b 65 79 77 6f 72 64 20 6e 6f 74 INCT keyword not
16920 20 75 73 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 used */.#define
16930 20 57 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f WHERE_DISTINCT_
16940 55 4e 49 51 55 45 20 20 20 20 31 20 20 2f 2a 20 UNIQUE 1 /*
16950 4e 6f 20 64 75 70 6c 69 63 61 74 65 73 20 2a 2f No duplicates */
16960 0a 23 64 65 66 69 6e 65 20 57 48 45 52 45 5f 44 .#define WHERE_D
16970 49 53 54 49 4e 43 54 5f 4f 52 44 45 52 45 44 20 ISTINCT_ORDERED
16980 20 20 32 20 20 2f 2a 20 41 6c 6c 20 64 75 70 6c 2 /* All dupl
16990 69 63 61 74 65 73 20 61 72 65 20 61 64 6a 61 63 icates are adjac
169a0 65 6e 74 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 ent */.#define W
169b0 48 45 52 45 5f 44 49 53 54 49 4e 43 54 5f 55 4e HERE_DISTINCT_UN
169c0 4f 52 44 45 52 45 44 20 33 20 20 2f 2a 20 44 75 ORDERED 3 /* Du
169d0 70 6c 69 63 61 74 65 73 20 61 72 65 20 73 63 61 plicates are sca
169e0 74 74 65 72 65 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a ttered */../*.**
169f0 20 41 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 64 A NameContext d
16a00 65 66 69 6e 65 73 20 61 20 63 6f 6e 74 65 78 74 efines a context
16a10 20 69 6e 20 77 68 69 63 68 20 74 6f 20 72 65 73 in which to res
16a20 6f 6c 76 65 20 74 61 62 6c 65 20 61 6e 64 20 63 olve table and c
16a30 6f 6c 75 6d 6e 0a 2a 2a 20 6e 61 6d 65 73 2e 20 olumn.** names.
16a40 20 54 68 65 20 63 6f 6e 74 65 78 74 20 63 6f 6e The context con
16a50 73 69 73 74 73 20 6f 66 20 61 20 6c 69 73 74 20 sists of a list
16a60 6f 66 20 74 61 62 6c 65 73 20 28 74 68 65 20 70 of tables (the p
16a70 53 72 63 4c 69 73 74 29 20 66 69 65 6c 64 20 61 SrcList) field a
16a80 6e 64 0a 2a 2a 20 61 20 6c 69 73 74 20 6f 66 20 nd.** a list of
16a90 6e 61 6d 65 64 20 65 78 70 72 65 73 73 69 6f 6e named expression
16aa0 20 28 70 45 4c 69 73 74 29 2e 20 20 54 68 65 20 (pEList). The
16ab0 6e 61 6d 65 64 20 65 78 70 72 65 73 73 69 6f 6e named expression
16ac0 20 6c 69 73 74 20 6d 61 79 0a 2a 2a 20 62 65 20 list may.** be
16ad0 4e 55 4c 4c 2e 20 20 54 68 65 20 70 53 72 63 20 NULL. The pSrc
16ae0 63 6f 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 corresponds to t
16af0 68 65 20 46 52 4f 4d 20 63 6c 61 75 73 65 20 6f he FROM clause o
16b00 66 20 61 20 53 45 4c 45 43 54 20 6f 72 0a 2a 2a f a SELECT or.**
16b10 20 74 6f 20 74 68 65 20 74 61 62 6c 65 20 62 65 to the table be
16b20 69 6e 67 20 6f 70 65 72 61 74 65 64 20 6f 6e 20 ing operated on
16b30 62 79 20 49 4e 53 45 52 54 2c 20 55 50 44 41 54 by INSERT, UPDAT
16b40 45 2c 20 6f 72 20 44 45 4c 45 54 45 2e 20 20 54 E, or DELETE. T
16b50 68 65 0a 2a 2a 20 70 45 4c 69 73 74 20 63 6f 72 he.** pEList cor
16b60 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65 20 responds to the
16b70 72 65 73 75 6c 74 20 73 65 74 20 6f 66 20 61 20 result set of a
16b80 53 45 4c 45 43 54 20 61 6e 64 20 69 73 20 4e 55 SELECT and is NU
16b90 4c 4c 20 66 6f 72 0a 2a 2a 20 6f 74 68 65 72 20 LL for.** other
16ba0 73 74 61 74 65 6d 65 6e 74 73 2e 0a 2a 2a 0a 2a statements..**.*
16bb0 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 73 20 63 * NameContexts c
16bc0 61 6e 20 62 65 20 6e 65 73 74 65 64 2e 20 20 57 an be nested. W
16bd0 68 65 6e 20 72 65 73 6f 6c 76 69 6e 67 20 6e 61 hen resolving na
16be0 6d 65 73 2c 20 74 68 65 20 69 6e 6e 65 72 2d 6d mes, the inner-m
16bf0 6f 73 74 20 0a 2a 2a 20 63 6f 6e 74 65 78 74 20 ost .** context
16c00 69 73 20 73 65 61 72 63 68 65 64 20 66 69 72 73 is searched firs
16c10 74 2e 20 20 49 66 20 6e 6f 20 6d 61 74 63 68 20 t. If no match
16c20 69 73 20 66 6f 75 6e 64 2c 20 74 68 65 20 6e 65 is found, the ne
16c30 78 74 20 6f 75 74 65 72 0a 2a 2a 20 63 6f 6e 74 xt outer.** cont
16c40 65 78 74 20 69 73 20 63 68 65 63 6b 65 64 2e 20 ext is checked.
16c50 20 49 66 20 74 68 65 72 65 20 69 73 20 73 74 69 If there is sti
16c60 6c 6c 20 6e 6f 20 6d 61 74 63 68 2c 20 74 68 65 ll no match, the
16c70 20 6e 65 78 74 20 63 6f 6e 74 65 78 74 0a 2a 2a next context.**
16c80 20 69 73 20 63 68 65 63 6b 65 64 2e 20 20 54 68 is checked. Th
16c90 69 73 20 70 72 6f 63 65 73 73 20 63 6f 6e 74 69 is process conti
16ca0 6e 75 65 73 20 75 6e 74 69 6c 20 65 69 74 68 65 nues until eithe
16cb0 72 20 61 20 6d 61 74 63 68 20 69 73 20 66 6f 75 r a match is fou
16cc0 6e 64 0a 2a 2a 20 6f 72 20 61 6c 6c 20 63 6f 6e nd.** or all con
16cd0 74 65 78 74 73 20 61 72 65 20 63 68 65 63 6b 2e texts are check.
16ce0 20 20 57 68 65 6e 20 61 20 6d 61 74 63 68 20 69 When a match i
16cf0 73 20 66 6f 75 6e 64 2c 20 74 68 65 20 6e 52 65 s found, the nRe
16d00 66 20 6d 65 6d 62 65 72 20 6f 66 0a 2a 2a 20 74 f member of.** t
16d10 68 65 20 63 6f 6e 74 65 78 74 20 63 6f 6e 74 61 he context conta
16d20 69 6e 69 6e 67 20 74 68 65 20 6d 61 74 63 68 20 ining the match
16d30 69 73 20 69 6e 63 72 65 6d 65 6e 74 65 64 2e 20 is incremented.
16d40 0a 2a 2a 0a 2a 2a 20 45 61 63 68 20 73 75 62 71 .**.** Each subq
16d50 75 65 72 79 20 67 65 74 73 20 61 20 6e 65 77 20 uery gets a new
16d60 4e 61 6d 65 43 6f 6e 74 65 78 74 2e 20 20 54 68 NameContext. Th
16d70 65 20 70 4e 65 78 74 20 66 69 65 6c 64 20 70 6f e pNext field po
16d80 69 6e 74 73 20 74 6f 20 74 68 65 0a 2a 2a 20 4e ints to the.** N
16d90 61 6d 65 43 6f 6e 74 65 78 74 20 69 6e 20 74 68 ameContext in th
16da0 65 20 70 61 72 65 6e 74 20 71 75 65 72 79 2e 20 e parent query.
16db0 20 54 68 75 73 20 74 68 65 20 70 72 6f 63 65 73 Thus the proces
16dc0 73 20 6f 66 20 73 63 61 6e 6e 69 6e 67 20 74 68 s of scanning th
16dd0 65 0a 2a 2a 20 4e 61 6d 65 43 6f 6e 74 65 78 74 e.** NameContext
16de0 20 6c 69 73 74 20 63 6f 72 72 65 73 70 6f 6e 64 list correspond
16df0 73 20 74 6f 20 73 65 61 72 63 68 69 6e 67 20 74 s to searching t
16e00 68 72 6f 75 67 68 20 73 75 63 63 65 73 73 69 76 hrough successiv
16e10 65 6c 79 20 6f 75 74 65 72 0a 2a 2a 20 73 75 62 ely outer.** sub
16e20 71 75 65 72 69 65 73 20 6c 6f 6f 6b 69 6e 67 20 queries looking
16e30 66 6f 72 20 61 20 6d 61 74 63 68 2e 0a 2a 2f 0a for a match..*/.
16e40 73 74 72 75 63 74 20 4e 61 6d 65 43 6f 6e 74 65 struct NameConte
16e50 78 74 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 xt {. Parse *pP
16e60 61 72 73 65 3b 20 20 20 20 20 20 20 2f 2a 20 54 arse; /* T
16e70 68 65 20 70 61 72 73 65 72 20 2a 2f 0a 20 20 53 he parser */. S
16e80 72 63 4c 69 73 74 20 2a 70 53 72 63 4c 69 73 74 rcList *pSrcList
16e90 3b 20 20 20 2f 2a 20 4f 6e 65 20 6f 72 20 6d 6f ; /* One or mo
16ea0 72 65 20 74 61 62 6c 65 73 20 75 73 65 64 20 74 re tables used t
16eb0 6f 20 72 65 73 6f 6c 76 65 20 6e 61 6d 65 73 20 o resolve names
16ec0 2a 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 */. ExprList *p
16ed0 45 4c 69 73 74 3b 20 20 20 20 2f 2a 20 4f 70 74 EList; /* Opt
16ee0 69 6f 6e 61 6c 20 6c 69 73 74 20 6f 66 20 72 65 ional list of re
16ef0 73 75 6c 74 2d 73 65 74 20 63 6f 6c 75 6d 6e 73 sult-set columns
16f00 20 2a 2f 0a 20 20 41 67 67 49 6e 66 6f 20 2a 70 */. AggInfo *p
16f10 41 67 67 49 6e 66 6f 3b 20 20 20 2f 2a 20 49 6e AggInfo; /* In
16f20 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
16f30 61 67 67 72 65 67 61 74 65 73 20 61 74 20 74 68 aggregates at th
16f40 69 73 20 6c 65 76 65 6c 20 2a 2f 0a 20 20 4e 61 is level */. Na
16f50 6d 65 43 6f 6e 74 65 78 74 20 2a 70 4e 65 78 74 meContext *pNext
16f60 3b 20 20 2f 2a 20 4e 65 78 74 20 6f 75 74 65 72 ; /* Next outer
16f70 20 6e 61 6d 65 20 63 6f 6e 74 65 78 74 2e 20 20 name context.
16f80 4e 55 4c 4c 20 66 6f 72 20 6f 75 74 65 72 6d 6f NULL for outermo
16f90 73 74 20 2a 2f 0a 20 20 69 6e 74 20 6e 52 65 66 st */. int nRef
16fa0 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 ; /*
16fb0 4e 75 6d 62 65 72 20 6f 66 20 6e 61 6d 65 73 20 Number of names
16fc0 72 65 73 6f 6c 76 65 64 20 62 79 20 74 68 69 73 resolved by this
16fd0 20 63 6f 6e 74 65 78 74 20 2a 2f 0a 20 20 69 6e context */. in
16fe0 74 20 6e 45 72 72 3b 20 20 20 20 20 20 20 20 20 t nErr;
16ff0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
17000 65 72 72 6f 72 73 20 65 6e 63 6f 75 6e 74 65 72 errors encounter
17010 65 64 20 77 68 69 6c 65 20 72 65 73 6f 6c 76 69 ed while resolvi
17020 6e 67 20 6e 61 6d 65 73 20 2a 2f 0a 20 20 75 38 ng names */. u8
17030 20 6e 63 46 6c 61 67 73 3b 20 20 20 20 20 20 20 ncFlags;
17040 20 20 20 2f 2a 20 5a 65 72 6f 20 6f 72 20 6d 6f /* Zero or mo
17050 72 65 20 4e 43 5f 2a 20 66 6c 61 67 73 20 64 65 re NC_* flags de
17060 66 69 6e 65 64 20 62 65 6c 6f 77 20 2a 2f 0a 7d fined below */.}
17070 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 ;../*.** Allowed
17080 20 76 61 6c 75 65 73 20 66 6f 72 20 74 68 65 20 values for the
17090 4e 61 6d 65 43 6f 6e 74 65 78 74 2c 20 6e 63 46 NameContext, ncF
170a0 6c 61 67 73 20 66 69 65 6c 64 2e 0a 2a 2f 0a 23 lags field..*/.#
170b0 64 65 66 69 6e 65 20 4e 43 5f 41 6c 6c 6f 77 41 define NC_AllowA
170c0 67 67 20 20 30 78 30 31 20 20 20 20 2f 2a 20 41 gg 0x01 /* A
170d0 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 69 6f ggregate functio
170e0 6e 73 20 61 72 65 20 61 6c 6c 6f 77 65 64 20 68 ns are allowed h
170f0 65 72 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4e ere */.#define N
17100 43 5f 48 61 73 41 67 67 20 20 20 20 30 78 30 32 C_HasAgg 0x02
17110 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 72 20 6d 6f /* One or mo
17120 72 65 20 61 67 67 72 65 67 61 74 65 20 66 75 6e re aggregate fun
17130 63 74 69 6f 6e 73 20 73 65 65 6e 20 2a 2f 0a 23 ctions seen */.#
17140 64 65 66 69 6e 65 20 4e 43 5f 49 73 43 68 65 63 define NC_IsChec
17150 6b 20 20 20 30 78 30 34 20 20 20 20 2f 2a 20 54 k 0x04 /* T
17160 72 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 rue if resolving
17170 20 6e 61 6d 65 73 20 69 6e 20 61 20 43 48 45 43 names in a CHEC
17180 4b 20 63 6f 6e 73 74 72 61 69 6e 74 20 2a 2f 0a K constraint */.
17190 23 64 65 66 69 6e 65 20 4e 43 5f 49 6e 41 67 67 #define NC_InAgg
171a0 46 75 6e 63 20 30 78 30 38 20 20 20 20 2f 2a 20 Func 0x08 /*
171b0 54 72 75 65 20 69 66 20 61 6e 61 6c 79 7a 69 6e True if analyzin
171c0 67 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 61 g arguments to a
171d0 6e 20 61 67 67 20 66 75 6e 63 20 2a 2f 0a 23 64 n agg func */.#d
171e0 65 66 69 6e 65 20 4e 43 5f 50 61 72 74 49 64 78 efine NC_PartIdx
171f0 20 20 20 30 78 31 30 20 20 20 20 2f 2a 20 54 72 0x10 /* Tr
17200 75 65 20 69 66 20 72 65 73 6f 6c 76 69 6e 67 20 ue if resolving
17210 61 20 70 61 72 74 69 61 6c 20 69 6e 64 65 78 20 a partial index
17220 57 48 45 52 45 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 WHERE */../*.**
17230 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 An instance of t
17240 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 72 he following str
17250 75 63 74 75 72 65 20 63 6f 6e 74 61 69 6e 73 20 ucture contains
17260 61 6c 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a all information.
17270 2a 2a 20 6e 65 65 64 65 64 20 74 6f 20 67 65 6e ** needed to gen
17280 65 72 61 74 65 20 63 6f 64 65 20 66 6f 72 20 61 erate code for a
17290 20 73 69 6e 67 6c 65 20 53 45 4c 45 43 54 20 73 single SELECT s
172a0 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a 2a 20 tatement..**.**
172b0 6e 4c 69 6d 69 74 20 69 73 20 73 65 74 20 74 6f nLimit is set to
172c0 20 2d 31 20 69 66 20 74 68 65 72 65 20 69 73 20 -1 if there is
172d0 6e 6f 20 4c 49 4d 49 54 20 63 6c 61 75 73 65 2e no LIMIT clause.
172e0 20 20 6e 4f 66 66 73 65 74 20 69 73 20 73 65 74 nOffset is set
172f0 20 74 6f 20 30 2e 0a 2a 2a 20 49 66 20 74 68 65 to 0..** If the
17300 72 65 20 69 73 20 61 20 4c 49 4d 49 54 20 63 6c re is a LIMIT cl
17310 61 75 73 65 2c 20 74 68 65 20 70 61 72 73 65 72 ause, the parser
17320 20 73 65 74 73 20 6e 4c 69 6d 69 74 20 74 6f 20 sets nLimit to
17330 74 68 65 20 76 61 6c 75 65 20 6f 66 20 74 68 65 the value of the
17340 0a 2a 2a 20 6c 69 6d 69 74 20 61 6e 64 20 6e 4f .** limit and nO
17350 66 66 73 65 74 20 74 6f 20 74 68 65 20 76 61 6c ffset to the val
17360 75 65 20 6f 66 20 74 68 65 20 6f 66 66 73 65 74 ue of the offset
17370 20 28 6f 72 20 30 20 69 66 20 74 68 65 72 65 20 (or 0 if there
17380 69 73 20 6e 6f 74 0a 2a 2a 20 6f 66 66 73 65 74 is not.** offset
17390 29 2e 20 20 42 75 74 20 6c 61 74 65 72 20 6f 6e ). But later on
173a0 2c 20 6e 4c 69 6d 69 74 20 61 6e 64 20 6e 4f 66 , nLimit and nOf
173b0 66 73 65 74 20 62 65 63 6f 6d 65 20 74 68 65 20 fset become the
173c0 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 73 memory locations
173d0 0a 2a 2a 20 69 6e 20 74 68 65 20 56 44 42 45 20 .** in the VDBE
173e0 74 68 61 74 20 72 65 63 6f 72 64 20 74 68 65 20 that record the
173f0 6c 69 6d 69 74 20 61 6e 64 20 6f 66 66 73 65 74 limit and offset
17400 20 63 6f 75 6e 74 65 72 73 2e 0a 2a 2a 0a 2a 2a counters..**.**
17410 20 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b 5d 20 addrOpenEphm[]
17420 65 6e 74 72 69 65 73 20 63 6f 6e 74 61 69 6e 20 entries contain
17430 74 68 65 20 61 64 64 72 65 73 73 20 6f 66 20 4f the address of O
17440 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 P_OpenEphemeral
17450 6f 70 63 6f 64 65 73 2e 0a 2a 2a 20 54 68 65 73 opcodes..** Thes
17460 65 20 61 64 64 72 65 73 73 65 73 20 6d 75 73 74 e addresses must
17470 20 62 65 20 73 74 6f 72 65 64 20 73 6f 20 74 68 be stored so th
17480 61 74 20 77 65 20 63 61 6e 20 67 6f 20 62 61 63 at we can go bac
17490 6b 20 61 6e 64 20 66 69 6c 6c 20 69 6e 0a 2a 2a k and fill in.**
174a0 20 74 68 65 20 50 34 5f 4b 45 59 49 4e 46 4f 20 the P4_KEYINFO
174b0 61 6e 64 20 50 32 20 70 61 72 61 6d 65 74 65 72 and P2 parameter
174c0 73 20 6c 61 74 65 72 2e 20 20 4e 65 69 74 68 65 s later. Neithe
174d0 72 20 74 68 65 20 4b 65 79 49 6e 66 6f 20 6e 6f r the KeyInfo no
174e0 72 0a 2a 2a 20 74 68 65 20 6e 75 6d 62 65 72 20 r.** the number
174f0 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 50 32 of columns in P2
17500 20 63 61 6e 20 62 65 20 63 6f 6d 70 75 74 65 64 can be computed
17510 20 61 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d at the same tim
17520 65 0a 2a 2a 20 61 73 20 74 68 65 20 4f 50 5f 4f e.** as the OP_O
17530 70 65 6e 45 70 68 6d 20 69 6e 73 74 72 75 63 74 penEphm instruct
17540 69 6f 6e 20 69 73 20 63 6f 64 65 64 20 62 65 63 ion is coded bec
17550 61 75 73 65 20 6e 6f 74 0a 2a 2a 20 65 6e 6f 75 ause not.** enou
17560 67 68 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 gh information a
17570 62 6f 75 74 20 74 68 65 20 63 6f 6d 70 6f 75 6e bout the compoun
17580 64 20 71 75 65 72 79 20 69 73 20 6b 6e 6f 77 6e d query is known
17590 20 61 74 20 74 68 61 74 20 70 6f 69 6e 74 2e 0a at that point..
175a0 2a 2a 20 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 ** The KeyInfo f
175b0 6f 72 20 61 64 64 72 4f 70 65 6e 54 72 61 6e 5b or addrOpenTran[
175c0 30 5d 20 61 6e 64 20 5b 31 5d 20 63 6f 6e 74 61 0] and [1] conta
175d0 69 6e 73 20 63 6f 6c 6c 61 74 69 6e 67 20 73 65 ins collating se
175e0 71 75 65 6e 63 65 73 0a 2a 2a 20 66 6f 72 20 74 quences.** for t
175f0 68 65 20 72 65 73 75 6c 74 20 73 65 74 2e 20 20 he result set.
17600 54 68 65 20 4b 65 79 49 6e 66 6f 20 66 6f 72 20 The KeyInfo for
17610 61 64 64 72 4f 70 65 6e 45 70 68 6d 5b 32 5d 20 addrOpenEphm[2]
17620 63 6f 6e 74 61 69 6e 73 20 63 6f 6c 6c 61 74 69 contains collati
17630 6e 67 0a 2a 2a 20 73 65 71 75 65 6e 63 65 73 20 ng.** sequences
17640 66 6f 72 20 74 68 65 20 4f 52 44 45 52 20 42 59 for the ORDER BY
17650 20 63 6c 61 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 clause..*/.stru
17660 63 74 20 53 65 6c 65 63 74 20 7b 0a 20 20 45 78 ct Select {. Ex
17670 70 72 4c 69 73 74 20 2a 70 45 4c 69 73 74 3b 20 prList *pEList;
17680 20 20 20 20 20 2f 2a 20 54 68 65 20 66 69 65 6c /* The fiel
17690 64 73 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 ds of the result
176a0 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 20 20 20 */. u8 op;
176b0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
176c0 4f 6e 65 20 6f 66 3a 20 54 4b 5f 55 4e 49 4f 4e One of: TK_UNION
176d0 20 54 4b 5f 41 4c 4c 20 54 4b 5f 49 4e 54 45 52 TK_ALL TK_INTER
176e0 53 45 43 54 20 54 4b 5f 45 58 43 45 50 54 20 2a SECT TK_EXCEPT *
176f0 2f 0a 20 20 75 31 36 20 73 65 6c 46 6c 61 67 73 /. u16 selFlags
17700 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 56 61 ; /* Va
17710 72 69 6f 75 73 20 53 46 5f 2a 20 76 61 6c 75 65 rious SF_* value
17720 73 20 2a 2f 0a 20 20 69 6e 74 20 69 4c 69 6d 69 s */. int iLimi
17730 74 2c 20 69 4f 66 66 73 65 74 3b 20 20 20 2f 2a t, iOffset; /*
17740 20 4d 65 6d 6f 72 79 20 72 65 67 69 73 74 65 72 Memory register
17750 73 20 68 6f 6c 64 69 6e 67 20 4c 49 4d 49 54 20 s holding LIMIT
17760 26 20 4f 46 46 53 45 54 20 63 6f 75 6e 74 65 72 & OFFSET counter
17770 73 20 2a 2f 0a 20 20 69 6e 74 20 61 64 64 72 4f s */. int addrO
17780 70 65 6e 45 70 68 6d 5b 32 5d 3b 20 20 20 2f 2a penEphm[2]; /*
17790 20 4f 50 5f 4f 70 65 6e 45 70 68 65 6d 20 6f 70 OP_OpenEphem op
177a0 63 6f 64 65 73 20 72 65 6c 61 74 65 64 20 74 6f codes related to
177b0 20 74 68 69 73 20 73 65 6c 65 63 74 20 2a 2f 0a this select */.
177c0 20 20 75 36 34 20 6e 53 65 6c 65 63 74 52 6f 77 u64 nSelectRow
177d0 3b 20 20 20 20 20 20 20 20 2f 2a 20 45 73 74 69 ; /* Esti
177e0 6d 61 74 65 64 20 6e 75 6d 62 65 72 20 6f 66 20 mated number of
177f0 72 65 73 75 6c 74 20 72 6f 77 73 20 2a 2f 0a 20 result rows */.
17800 20 53 72 63 4c 69 73 74 20 2a 70 53 72 63 3b 20 SrcList *pSrc;
17810 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 46 /* The F
17820 52 4f 4d 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 ROM clause */.
17830 45 78 70 72 20 2a 70 57 68 65 72 65 3b 20 20 20 Expr *pWhere;
17840 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 /* The WH
17850 45 52 45 20 63 6c 61 75 73 65 20 2a 2f 0a 20 20 ERE clause */.
17860 45 78 70 72 4c 69 73 74 20 2a 70 47 72 6f 75 70 ExprList *pGroup
17870 42 79 3b 20 20 20 20 2f 2a 20 54 68 65 20 47 52 By; /* The GR
17880 4f 55 50 20 42 59 20 63 6c 61 75 73 65 20 2a 2f OUP BY clause */
17890 0a 20 20 45 78 70 72 20 2a 70 48 61 76 69 6e 67 . Expr *pHaving
178a0 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 54 68 65 ; /* The
178b0 20 48 41 56 49 4e 47 20 63 6c 61 75 73 65 20 2a HAVING clause *
178c0 2f 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 4f /. ExprList *pO
178d0 72 64 65 72 42 79 3b 20 20 20 20 2f 2a 20 54 68 rderBy; /* Th
178e0 65 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 e ORDER BY claus
178f0 65 20 2a 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 e */. Select *p
17900 50 72 69 6f 72 3b 20 20 20 20 20 20 20 20 2f 2a Prior; /*
17910 20 50 72 69 6f 72 20 73 65 6c 65 63 74 20 69 6e Prior select in
17920 20 61 20 63 6f 6d 70 6f 75 6e 64 20 73 65 6c 65 a compound sele
17930 63 74 20 73 74 61 74 65 6d 65 6e 74 20 2a 2f 0a ct statement */.
17940 20 20 53 65 6c 65 63 74 20 2a 70 4e 65 78 74 3b Select *pNext;
17950 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 78 74 /* Next
17960 20 73 65 6c 65 63 74 20 74 6f 20 74 68 65 20 6c select to the l
17970 65 66 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 6e eft in a compoun
17980 64 20 2a 2f 0a 20 20 45 78 70 72 20 2a 70 4c 69 d */. Expr *pLi
17990 6d 69 74 3b 20 20 20 20 20 20 20 20 20 20 2f 2a mit; /*
179a0 20 4c 49 4d 49 54 20 65 78 70 72 65 73 73 69 6f LIMIT expressio
179b0 6e 2e 20 4e 55 4c 4c 20 6d 65 61 6e 73 20 6e 6f n. NULL means no
179c0 74 20 75 73 65 64 2e 20 2a 2f 0a 20 20 45 78 70 t used. */. Exp
179d0 72 20 2a 70 4f 66 66 73 65 74 3b 20 20 20 20 20 r *pOffset;
179e0 20 20 20 20 2f 2a 20 4f 46 46 53 45 54 20 65 78 /* OFFSET ex
179f0 70 72 65 73 73 69 6f 6e 2e 20 4e 55 4c 4c 20 6d pression. NULL m
17a00 65 61 6e 73 20 6e 6f 74 20 75 73 65 64 2e 20 2a eans not used. *
17a10 2f 0a 20 20 57 69 74 68 20 2a 70 57 69 74 68 3b /. With *pWith;
17a20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 57 49 /* WI
17a30 54 48 20 63 6c 61 75 73 65 20 61 74 74 61 63 68 TH clause attach
17a40 65 64 20 74 6f 20 74 68 69 73 20 73 65 6c 65 63 ed to this selec
17a50 74 2e 20 4f 72 20 4e 55 4c 4c 2e 20 2a 2f 0a 7d t. Or NULL. */.}
17a60 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 ;../*.** Allowed
17a70 20 76 61 6c 75 65 73 20 66 6f 72 20 53 65 6c 65 values for Sele
17a80 63 74 2e 73 65 6c 46 6c 61 67 73 2e 20 20 54 68 ct.selFlags. Th
17a90 65 20 22 53 46 22 20 70 72 65 66 69 78 20 73 74 e "SF" prefix st
17aa0 61 6e 64 73 20 66 6f 72 0a 2a 2a 20 22 53 65 6c ands for.** "Sel
17ab0 65 63 74 20 46 6c 61 67 22 2e 0a 2a 2f 0a 23 64 ect Flag"..*/.#d
17ac0 65 66 69 6e 65 20 53 46 5f 44 69 73 74 69 6e 63 efine SF_Distinc
17ad0 74 20 20 20 20 20 20 20 20 30 78 30 30 30 31 20 t 0x0001
17ae0 20 2f 2a 20 4f 75 74 70 75 74 20 73 68 6f 75 6c /* Output shoul
17af0 64 20 62 65 20 44 49 53 54 49 4e 43 54 20 2a 2f d be DISTINCT */
17b00 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 65 73 6f .#define SF_Reso
17b10 6c 76 65 64 20 20 20 20 20 20 20 20 30 78 30 30 lved 0x00
17b20 30 32 20 20 2f 2a 20 49 64 65 6e 74 69 66 69 65 02 /* Identifie
17b30 72 73 20 68 61 76 65 20 62 65 65 6e 20 72 65 73 rs have been res
17b40 6f 6c 76 65 64 20 2a 2f 0a 23 64 65 66 69 6e 65 olved */.#define
17b50 20 53 46 5f 41 67 67 72 65 67 61 74 65 20 20 20 SF_Aggregate
17b60 20 20 20 20 30 78 30 30 30 34 20 20 2f 2a 20 43 0x0004 /* C
17b70 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 61 74 ontains aggregat
17b80 65 20 66 75 6e 63 74 69 6f 6e 73 20 2a 2f 0a 23 e functions */.#
17b90 64 65 66 69 6e 65 20 53 46 5f 55 73 65 73 45 70 define SF_UsesEp
17ba0 68 65 6d 65 72 61 6c 20 20 20 30 78 30 30 30 38 hemeral 0x0008
17bb0 20 20 2f 2a 20 55 73 65 73 20 74 68 65 20 4f 70 /* Uses the Op
17bc0 65 6e 45 70 68 65 6d 65 72 61 6c 20 6f 70 63 6f enEphemeral opco
17bd0 64 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 de */.#define SF
17be0 5f 45 78 70 61 6e 64 65 64 20 20 20 20 20 20 20 _Expanded
17bf0 20 30 78 30 30 31 30 20 20 2f 2a 20 73 71 6c 69 0x0010 /* sqli
17c00 74 65 33 53 65 6c 65 63 74 45 78 70 61 6e 64 28 te3SelectExpand(
17c10 29 20 63 61 6c 6c 65 64 20 6f 6e 20 74 68 69 73 ) called on this
17c20 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 48 */.#define SF_H
17c30 61 73 54 79 70 65 49 6e 66 6f 20 20 20 20 20 30 asTypeInfo 0
17c40 78 30 30 32 30 20 20 2f 2a 20 46 52 4f 4d 20 73 x0020 /* FROM s
17c50 75 62 71 75 65 72 69 65 73 20 68 61 76 65 20 54 ubqueries have T
17c60 61 62 6c 65 20 6d 65 74 61 64 61 74 61 20 2a 2f able metadata */
17c70 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
17c80 20 20 20 20 20 2f 2a 20 20 20 20 20 30 78 30 30 /* 0x00
17c90 34 30 20 20 4e 4f 54 20 55 53 45 44 20 2a 2f 0a 40 NOT USED */.
17ca0 23 64 65 66 69 6e 65 20 53 46 5f 56 61 6c 75 65 #define SF_Value
17cb0 73 20 20 20 20 20 20 20 20 20 20 30 78 30 30 38 s 0x008
17cc0 30 20 20 2f 2a 20 53 79 6e 74 68 65 73 69 7a 65 0 /* Synthesize
17cd0 64 20 66 72 6f 6d 20 56 41 4c 55 45 53 20 63 6c d from VALUES cl
17ce0 61 75 73 65 20 2a 2f 0a 20 20 20 20 20 20 20 20 ause */.
17cf0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 20 /*
17d00 20 20 20 30 78 30 31 30 30 20 20 4e 4f 54 20 55 0x0100 NOT U
17d10 53 45 44 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 SED */.#define S
17d20 46 5f 4e 65 73 74 65 64 46 72 6f 6d 20 20 20 20 F_NestedFrom
17d30 20 20 30 78 30 32 30 30 20 20 2f 2a 20 50 61 72 0x0200 /* Par
17d40 74 20 6f 66 20 61 20 70 61 72 65 6e 74 68 65 73 t of a parenthes
17d50 69 7a 65 64 20 46 52 4f 4d 20 63 6c 61 75 73 65 ized FROM clause
17d60 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 4d */.#define SF_M
17d70 61 79 62 65 43 6f 6e 76 65 72 74 20 20 20 20 30 aybeConvert 0
17d80 78 30 34 30 30 20 20 2f 2a 20 4e 65 65 64 20 63 x0400 /* Need c
17d90 6f 6e 76 65 72 74 43 6f 6d 70 6f 75 6e 64 53 65 onvertCompoundSe
17da0 6c 65 63 74 54 6f 53 75 62 71 75 65 72 79 28 29 lectToSubquery()
17db0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 52 */.#define SF_R
17dc0 65 63 75 72 73 69 76 65 20 20 20 20 20 20 20 30 ecursive 0
17dd0 78 30 38 30 30 20 20 2f 2a 20 54 68 65 20 72 65 x0800 /* The re
17de0 63 75 72 73 69 76 65 20 70 61 72 74 20 6f 66 20 cursive part of
17df0 61 20 72 65 63 75 72 73 69 76 65 20 43 54 45 20 a recursive CTE
17e00 2a 2f 0a 23 64 65 66 69 6e 65 20 53 46 5f 43 6f */.#define SF_Co
17e10 6d 70 6f 75 6e 64 20 20 20 20 20 20 20 20 30 78 mpound 0x
17e20 31 30 30 30 20 20 2f 2a 20 50 61 72 74 20 6f 66 1000 /* Part of
17e30 20 61 20 63 6f 6d 70 6f 75 6e 64 20 71 75 65 72 a compound quer
17e40 79 20 2a 2f 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 y */.../*.** The
17e50 20 72 65 73 75 6c 74 73 20 6f 66 20 61 20 53 45 results of a SE
17e60 4c 45 43 54 20 63 61 6e 20 62 65 20 64 69 73 74 LECT can be dist
17e70 72 69 62 75 74 65 64 20 69 6e 20 73 65 76 65 72 ributed in sever
17e80 61 6c 20 77 61 79 73 2c 20 61 73 20 64 65 66 69 al ways, as defi
17e90 6e 65 64 0a 2a 2a 20 62 79 20 6f 6e 65 20 6f 66 ned.** by one of
17ea0 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d the following m
17eb0 61 63 72 6f 73 2e 20 20 54 68 65 20 22 53 52 54 acros. The "SRT
17ec0 22 20 70 72 65 66 69 78 20 6d 65 61 6e 73 20 22 " prefix means "
17ed0 53 45 4c 45 43 54 20 52 65 73 75 6c 74 0a 2a 2a SELECT Result.**
17ee0 20 54 79 70 65 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 Type"..**.**
17ef0 20 20 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 20 SRT_Union
17f00 20 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 Store results
17f10 61 73 20 61 20 6b 65 79 20 69 6e 20 61 20 74 65 as a key in a te
17f20 6d 70 6f 72 61 72 79 20 69 6e 64 65 78 20 0a 2a mporary index .*
17f30 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
17f40 20 20 20 20 20 20 69 64 65 6e 74 69 66 69 65 64 identified
17f50 20 62 79 20 70 44 65 73 74 2d 3e 69 53 44 50 61 by pDest->iSDPa
17f60 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 rm..**.** SR
17f70 54 5f 45 78 63 65 70 74 20 20 20 20 20 20 52 65 T_Except Re
17f80 6d 6f 76 65 20 72 65 73 75 6c 74 73 20 66 72 6f move results fro
17f90 6d 20 74 68 65 20 74 65 6d 70 6f 72 61 72 79 20 m the temporary
17fa0 69 6e 64 65 78 20 70 44 65 73 74 2d 3e 69 53 44 index pDest->iSD
17fb0 50 61 72 6d 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 Parm..**.**
17fc0 53 52 54 5f 45 78 69 73 74 73 20 20 20 20 20 20 SRT_Exists
17fd0 53 74 6f 72 65 20 61 20 31 20 69 6e 20 6d 65 6d Store a 1 in mem
17fe0 6f 72 79 20 63 65 6c 6c 20 70 44 65 73 74 2d 3e ory cell pDest->
17ff0 69 53 44 50 61 72 6d 20 69 66 20 74 68 65 20 72 iSDParm if the r
18000 65 73 75 6c 74 0a 2a 2a 20 20 20 20 20 20 20 20 esult.**
18010 20 20 20 20 20 20 20 20 20 20 20 20 20 73 65 74 set
18020 20 69 73 20 6e 6f 74 20 65 6d 70 74 79 2e 0a 2a is not empty..*
18030 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 73 *.** SRT_Dis
18040 63 61 72 64 20 20 20 20 20 54 68 72 6f 77 20 74 card Throw t
18050 68 65 20 72 65 73 75 6c 74 73 20 61 77 61 79 2e he results away.
18060 20 20 54 68 69 73 20 69 73 20 75 73 65 64 20 62 This is used b
18070 79 20 53 45 4c 45 43 54 0a 2a 2a 20 20 20 20 20 y SELECT.**
18080 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18090 73 74 61 74 65 6d 65 6e 74 73 20 77 69 74 68 69 statements withi
180a0 6e 20 74 72 69 67 67 65 72 73 20 77 68 6f 73 65 n triggers whose
180b0 20 6f 6e 6c 79 20 70 75 72 70 6f 73 65 20 69 73 only purpose is
180c0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
180d0 20 20 20 20 20 20 20 20 74 68 65 20 73 69 64 65 the side
180e0 2d 65 66 66 65 63 74 73 20 6f 66 20 66 75 6e 63 -effects of func
180f0 74 69 6f 6e 73 2e 0a 2a 2a 0a 2a 2a 20 41 6c 6c tions..**.** All
18100 20 6f 66 20 74 68 65 20 61 62 6f 76 65 20 61 72 of the above ar
18110 65 20 66 72 65 65 20 74 6f 20 69 67 6e 6f 72 65 e free to ignore
18120 20 74 68 65 69 72 20 4f 52 44 45 52 20 42 59 20 their ORDER BY
18130 63 6c 61 75 73 65 2e 20 54 68 6f 73 65 20 74 68 clause. Those th
18140 61 74 0a 2a 2a 20 66 6f 6c 6c 6f 77 20 6d 75 73 at.** follow mus
18150 74 20 68 6f 6e 6f 72 20 74 68 65 20 4f 52 44 45 t honor the ORDE
18160 52 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2a 0a R BY clause..**.
18170 2a 2a 20 20 20 20 20 53 52 54 5f 4f 75 74 70 75 ** SRT_Outpu
18180 74 20 20 20 20 20 20 47 65 6e 65 72 61 74 65 20 t Generate
18190 61 20 72 6f 77 20 6f 66 20 6f 75 74 70 75 74 20 a row of output
181a0 28 75 73 69 6e 67 20 74 68 65 20 4f 50 5f 52 65 (using the OP_Re
181b0 73 75 6c 74 52 6f 77 0a 2a 2a 20 20 20 20 20 20 sultRow.**
181c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6f o
181d0 70 63 6f 64 65 29 20 66 6f 72 20 65 61 63 68 20 pcode) for each
181e0 72 6f 77 20 69 6e 20 74 68 65 20 72 65 73 75 6c row in the resul
181f0 74 20 73 65 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 t set..**.**
18200 20 53 52 54 5f 4d 65 6d 20 20 20 20 20 20 20 20 SRT_Mem
18210 20 4f 6e 6c 79 20 76 61 6c 69 64 20 69 66 20 74 Only valid if t
18220 68 65 20 72 65 73 75 6c 74 20 69 73 20 61 20 73 he result is a s
18230 69 6e 67 6c 65 20 63 6f 6c 75 6d 6e 2e 0a 2a 2a ingle column..**
18240 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18250 20 20 20 20 20 53 74 6f 72 65 20 74 68 65 20 66 Store the f
18260 69 72 73 74 20 63 6f 6c 75 6d 6e 20 6f 66 20 74 irst column of t
18270 68 65 20 66 69 72 73 74 20 72 65 73 75 6c 74 20 he first result
18280 72 6f 77 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 row.**
18290 20 20 20 20 20 20 20 20 20 20 20 69 6e 20 72 65 in re
182a0 67 69 73 74 65 72 20 70 44 65 73 74 2d 3e 69 53 gister pDest->iS
182b0 44 50 61 72 6d 20 74 68 65 6e 20 61 62 61 6e 64 DParm then aband
182c0 6f 6e 20 74 68 65 20 72 65 73 74 0a 2a 2a 20 20 on the rest.**
182d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
182e0 20 20 20 6f 66 20 74 68 65 20 71 75 65 72 79 2e of the query.
182f0 20 20 54 68 69 73 20 64 65 73 74 69 6e 61 74 69 This destinati
18300 6f 6e 20 69 6d 70 6c 69 65 73 20 22 4c 49 4d 49 on implies "LIMI
18310 54 20 31 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 T 1"..**.**
18320 53 52 54 5f 53 65 74 20 20 20 20 20 20 20 20 20 SRT_Set
18330 54 68 65 20 72 65 73 75 6c 74 20 6d 75 73 74 20 The result must
18340 62 65 20 61 20 73 69 6e 67 6c 65 20 63 6f 6c 75 be a single colu
18350 6d 6e 2e 20 20 53 74 6f 72 65 20 65 61 63 68 0a mn. Store each.
18360 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
18370 20 20 20 20 20 20 20 72 6f 77 20 6f 66 20 72 65 row of re
18380 73 75 6c 74 20 61 73 20 74 68 65 20 6b 65 79 20 sult as the key
18390 69 6e 20 74 61 62 6c 65 20 70 44 65 73 74 2d 3e in table pDest->
183a0 69 53 44 50 61 72 6d 2e 20 0a 2a 2a 20 20 20 20 iSDParm. .**
183b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
183c0 20 41 70 70 6c 79 20 74 68 65 20 61 66 66 69 6e Apply the affin
183d0 69 74 79 20 70 44 65 73 74 2d 3e 61 66 66 53 64 ity pDest->affSd
183e0 73 74 20 62 65 66 6f 72 65 20 73 74 6f 72 69 6e st before storin
183f0 67 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 g.**
18400 20 20 20 20 20 20 20 20 20 72 65 73 75 6c 74 73 results
18410 2e 20 20 55 73 65 64 20 74 6f 20 69 6d 70 6c 65 . Used to imple
18420 6d 65 6e 74 20 22 49 4e 20 28 53 45 4c 45 43 54 ment "IN (SELECT
18430 20 2e 2e 2e 29 22 2e 0a 2a 2a 0a 2a 2a 20 20 20 ...)"..**.**
18440 20 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 20 SRT_EphemTab
18450 20 20 43 72 65 61 74 65 20 61 6e 20 74 65 6d 70 Create an temp
18460 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 65 73 orary table pDes
18470 74 2d 3e 69 53 44 50 61 72 6d 20 61 6e 64 20 73 t->iSDParm and s
18480 74 6f 72 65 0a 2a 2a 20 20 20 20 20 20 20 20 20 tore.**
18490 20 20 20 20 20 20 20 20 20 20 20 20 74 68 65 20 the
184a0 72 65 73 75 6c 74 20 74 68 65 72 65 2e 20 54 68 result there. Th
184b0 65 20 63 75 72 73 6f 72 20 69 73 20 6c 65 66 74 e cursor is left
184c0 20 6f 70 65 6e 20 61 66 74 65 72 0a 2a 2a 20 20 open after.**
184d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
184e0 20 20 20 72 65 74 75 72 6e 69 6e 67 2e 20 20 54 returning. T
184f0 68 69 73 20 69 73 20 6c 69 6b 65 20 53 52 54 5f his is like SRT_
18500 54 61 62 6c 65 20 65 78 63 65 70 74 20 74 68 61 Table except tha
18510 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 t.**
18520 20 20 20 20 20 20 20 20 20 74 68 69 73 20 64 65 this de
18530 73 74 69 6e 61 74 69 6f 6e 20 75 73 65 73 20 4f stination uses O
18540 50 5f 4f 70 65 6e 45 70 68 65 6d 65 72 61 6c 20 P_OpenEphemeral
18550 74 6f 20 63 72 65 61 74 65 0a 2a 2a 20 20 20 20 to create.**
18560 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18570 20 74 68 65 20 74 61 62 6c 65 20 66 69 72 73 74 the table first
18580 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
18590 43 6f 72 6f 75 74 69 6e 65 20 20 20 47 65 6e 65 Coroutine Gene
185a0 72 61 74 65 20 61 20 63 6f 2d 72 6f 75 74 69 6e rate a co-routin
185b0 65 20 74 68 61 74 20 72 65 74 75 72 6e 73 20 61 e that returns a
185c0 20 6e 65 77 20 72 6f 77 20 6f 66 0a 2a 2a 20 20 new row of.**
185d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
185e0 20 20 20 72 65 73 75 6c 74 73 20 65 61 63 68 20 results each
185f0 74 69 6d 65 20 69 74 20 69 73 20 69 6e 76 6f 6b time it is invok
18600 65 64 2e 20 20 54 68 65 20 65 6e 74 72 79 20 70 ed. The entry p
18610 6f 69 6e 74 0a 2a 2a 20 20 20 20 20 20 20 20 20 oint.**
18620 20 20 20 20 20 20 20 20 20 20 20 20 6f 66 20 74 of t
18630 68 65 20 63 6f 2d 72 6f 75 74 69 6e 65 20 69 73 he co-routine is
18640 20 73 74 6f 72 65 64 20 69 6e 20 72 65 67 69 73 stored in regis
18650 74 65 72 20 70 44 65 73 74 2d 3e 69 53 44 50 61 ter pDest->iSDPa
18660 72 6d 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 rm.**
18670 20 20 20 20 20 20 20 20 20 20 61 6e 64 20 74 68 and th
18680 65 20 72 65 73 75 6c 74 20 72 6f 77 20 69 73 20 e result row is
18690 73 74 6f 72 65 64 20 69 6e 20 70 44 65 73 74 2d stored in pDest-
186a0 3e 6e 44 65 73 74 20 72 65 67 69 73 74 65 72 73 >nDest registers
186b0 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
186c0 20 20 20 20 20 20 20 20 73 74 61 72 74 69 6e 67 starting
186d0 20 77 69 74 68 20 70 44 65 73 74 2d 3e 69 53 64 with pDest->iSd
186e0 73 74 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 st..**.** SR
186f0 54 5f 54 61 62 6c 65 20 20 20 20 20 20 20 53 74 T_Table St
18700 6f 72 65 20 72 65 73 75 6c 74 73 20 69 6e 20 74 ore results in t
18710 65 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 emporary table p
18720 44 65 73 74 2d 3e 69 53 44 50 61 72 6d 2e 0a 2a Dest->iSDParm..*
18730 2a 20 20 20 20 20 53 52 54 5f 46 69 66 6f 20 20 * SRT_Fifo
18740 20 20 20 20 20 20 54 68 69 73 20 69 73 20 6c 69 This is li
18750 6b 65 20 53 52 54 5f 45 70 68 65 6d 54 61 62 20 ke SRT_EphemTab
18760 65 78 63 65 70 74 20 74 68 61 74 20 74 68 65 20 except that the
18770 74 61 62 6c 65 0a 2a 2a 20 20 20 20 20 20 20 20 table.**
18780 20 20 20 20 20 20 20 20 20 20 20 20 20 69 73 20 is
18790 61 73 73 75 6d 65 64 20 74 6f 20 61 6c 72 65 61 assumed to alrea
187a0 64 79 20 62 65 20 6f 70 65 6e 2e 20 20 53 52 54 dy be open. SRT
187b0 5f 46 69 66 6f 20 68 61 73 0a 2a 2a 20 20 20 20 _Fifo has.**
187c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
187d0 20 74 68 65 20 61 64 64 69 74 69 6f 6e 61 6c 20 the additional
187e0 70 72 6f 70 65 72 74 79 20 6f 66 20 62 65 69 6e property of bein
187f0 67 20 61 62 6c 65 20 74 6f 20 69 67 6e 6f 72 65 g able to ignore
18800 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 .**
18810 20 20 20 20 20 20 20 20 74 68 65 20 4f 52 44 45 the ORDE
18820 52 20 42 59 20 63 6c 61 75 73 65 2e 0a 2a 2a 0a R BY clause..**.
18830 2a 2a 20 20 20 20 20 53 52 54 5f 44 69 73 74 46 ** SRT_DistF
18840 69 66 6f 20 20 20 20 53 74 6f 72 65 20 72 65 73 ifo Store res
18850 75 6c 74 73 20 69 6e 20 61 20 74 65 6d 70 6f 72 ults in a tempor
18860 61 72 79 20 74 61 62 6c 65 20 70 44 65 73 74 2d ary table pDest-
18870 3e 69 53 44 50 61 72 6d 2e 0a 2a 2a 20 20 20 20 >iSDParm..**
18880 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18890 20 42 75 74 20 61 6c 73 6f 20 75 73 65 20 74 65 But also use te
188a0 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 20 70 44 mporary table pD
188b0 65 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 20 61 est->iSDParm+1 a
188c0 73 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 s.**
188d0 20 20 20 20 20 20 20 20 20 61 20 72 65 63 6f 72 a recor
188e0 64 20 6f 66 20 61 6c 6c 20 70 72 69 6f 72 20 72 d of all prior r
188f0 65 73 75 6c 74 73 20 61 6e 64 20 69 67 6e 6f 72 esults and ignor
18900 65 20 61 6e 79 20 64 75 70 6c 69 63 61 74 65 0a e any duplicate.
18910 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
18920 20 20 20 20 20 20 20 72 6f 77 73 2e 20 20 4e 61 rows. Na
18930 6d 65 20 6d 65 61 6e 73 3a 20 20 22 44 69 73 74 me means: "Dist
18940 69 6e 63 74 20 46 69 66 6f 22 2e 0a 2a 2a 0a 2a inct Fifo"..**.*
18950 2a 20 20 20 20 20 53 52 54 5f 51 75 65 75 65 20 * SRT_Queue
18960 20 20 20 20 20 20 53 74 6f 72 65 20 72 65 73 75 Store resu
18970 6c 74 73 20 69 6e 20 70 72 69 6f 72 69 74 79 20 lts in priority
18980 71 75 65 75 65 20 70 44 65 73 74 2d 3e 69 53 44 queue pDest->iSD
18990 50 61 72 6d 20 28 72 65 61 6c 6c 79 0a 2a 2a 20 Parm (really.**
189a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
189b0 20 20 20 20 61 6e 20 69 6e 64 65 78 29 2e 20 20 an index).
189c0 41 70 70 65 6e 64 20 61 20 73 65 71 75 65 6e 63 Append a sequenc
189d0 65 20 6e 75 6d 62 65 72 20 73 6f 20 74 68 61 74 e number so that
189e0 20 61 6c 6c 20 65 6e 74 72 69 65 73 0a 2a 2a 20 all entries.**
189f0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18a00 20 20 20 20 61 72 65 20 64 69 73 74 69 6e 63 74 are distinct
18a10 2e 0a 2a 2a 0a 2a 2a 20 20 20 20 20 53 52 54 5f ..**.** SRT_
18a20 44 69 73 74 51 75 65 75 65 20 20 20 53 74 6f 72 DistQueue Stor
18a30 65 20 72 65 73 75 6c 74 73 20 69 6e 20 70 72 69 e results in pri
18a40 6f 72 69 74 79 20 71 75 65 75 65 20 70 44 65 73 ority queue pDes
18a50 74 2d 3e 69 53 44 50 61 72 6d 20 6f 6e 6c 79 20 t->iSDParm only
18a60 69 66 0a 2a 2a 20 20 20 20 20 20 20 20 20 20 20 if.**
18a70 20 20 20 20 20 20 20 20 20 20 74 68 65 20 73 61 the sa
18a80 6d 65 20 72 65 63 6f 72 64 20 68 61 73 20 6e 65 me record has ne
18a90 76 65 72 20 62 65 65 6e 20 73 74 6f 72 65 64 20 ver been stored
18aa0 62 65 66 6f 72 65 2e 20 20 54 68 65 0a 2a 2a 20 before. The.**
18ab0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
18ac0 20 20 20 20 69 6e 64 65 78 20 61 74 20 70 44 65 index at pDe
18ad0 73 74 2d 3e 69 53 44 50 61 72 6d 2b 31 20 68 6f st->iSDParm+1 ho
18ae0 6c 64 20 61 6c 6c 20 70 72 69 6f 72 20 73 74 6f ld all prior sto
18af0 72 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 res..*/.#define
18b00 53 52 54 5f 55 6e 69 6f 6e 20 20 20 20 20 20 20 SRT_Union
18b10 20 31 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 1 /* Store res
18b20 75 6c 74 20 61 73 20 6b 65 79 73 20 69 6e 20 61 ult as keys in a
18b30 6e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 65 66 69 n index */.#defi
18b40 6e 65 20 53 52 54 5f 45 78 63 65 70 74 20 20 20 ne SRT_Except
18b50 20 20 20 20 32 20 20 2f 2a 20 52 65 6d 6f 76 65 2 /* Remove
18b60 20 72 65 73 75 6c 74 20 66 72 6f 6d 20 61 20 55 result from a U
18b70 4e 49 4f 4e 20 69 6e 64 65 78 20 2a 2f 0a 23 64 NION index */.#d
18b80 65 66 69 6e 65 20 53 52 54 5f 45 78 69 73 74 73 efine SRT_Exists
18b90 20 20 20 20 20 20 20 33 20 20 2f 2a 20 53 74 6f 3 /* Sto
18ba0 72 65 20 31 20 69 66 20 74 68 65 20 72 65 73 75 re 1 if the resu
18bb0 6c 74 20 69 73 20 6e 6f 74 20 65 6d 70 74 79 20 lt is not empty
18bc0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 44 */.#define SRT_D
18bd0 69 73 63 61 72 64 20 20 20 20 20 20 34 20 20 2f iscard 4 /
18be0 2a 20 44 6f 20 6e 6f 74 20 73 61 76 65 20 74 68 * Do not save th
18bf0 65 20 72 65 73 75 6c 74 73 20 61 6e 79 77 68 65 e results anywhe
18c00 72 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 re */.#define SR
18c10 54 5f 46 69 66 6f 20 20 20 20 20 20 20 20 20 35 T_Fifo 5
18c20 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 73 75 6c /* Store resul
18c30 74 20 61 73 20 64 61 74 61 20 77 69 74 68 20 61 t as data with a
18c40 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 6f 77 69 n automatic rowi
18c50 64 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 d */.#define SRT
18c60 5f 44 69 73 74 46 69 66 6f 20 20 20 20 20 36 20 _DistFifo 6
18c70 20 2f 2a 20 4c 69 6b 65 20 53 52 54 5f 46 69 66 /* Like SRT_Fif
18c80 6f 2c 20 62 75 74 20 75 6e 69 71 75 65 20 72 65 o, but unique re
18c90 73 75 6c 74 73 20 6f 6e 6c 79 20 2a 2f 0a 23 64 sults only */.#d
18ca0 65 66 69 6e 65 20 53 52 54 5f 51 75 65 75 65 20 efine SRT_Queue
18cb0 20 20 20 20 20 20 20 37 20 20 2f 2a 20 53 74 6f 7 /* Sto
18cc0 72 65 20 72 65 73 75 6c 74 20 69 6e 20 61 6e 20 re result in an
18cd0 71 75 65 75 65 20 2a 2f 0a 23 64 65 66 69 6e 65 queue */.#define
18ce0 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 20 20 SRT_DistQueue
18cf0 20 20 38 20 20 2f 2a 20 4c 69 6b 65 20 53 52 54 8 /* Like SRT
18d00 5f 51 75 65 75 65 2c 20 62 75 74 20 75 6e 69 71 _Queue, but uniq
18d10 75 65 20 72 65 73 75 6c 74 73 20 6f 6e 6c 79 20 ue results only
18d20 2a 2f 0a 0a 2f 2a 20 54 68 65 20 4f 52 44 45 52 */../* The ORDER
18d30 20 42 59 20 63 6c 61 75 73 65 20 69 73 20 69 67 BY clause is ig
18d40 6e 6f 72 65 64 20 66 6f 72 20 61 6c 6c 20 6f 66 nored for all of
18d50 20 74 68 65 20 61 62 6f 76 65 20 2a 2f 0a 23 64 the above */.#d
18d60 65 66 69 6e 65 20 49 67 6e 6f 72 61 62 6c 65 4f efine IgnorableO
18d70 72 64 65 72 62 79 28 58 29 20 28 28 58 2d 3e 65 rderby(X) ((X->e
18d80 44 65 73 74 29 3c 3d 53 52 54 5f 44 69 73 74 51 Dest)<=SRT_DistQ
18d90 75 65 75 65 29 0a 0a 23 64 65 66 69 6e 65 20 53 ueue)..#define S
18da0 52 54 5f 4f 75 74 70 75 74 20 20 20 20 20 20 20 RT_Output
18db0 39 20 20 2f 2a 20 4f 75 74 70 75 74 20 65 61 63 9 /* Output eac
18dc0 68 20 72 6f 77 20 6f 66 20 72 65 73 75 6c 74 20 h row of result
18dd0 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 4d */.#define SRT_M
18de0 65 6d 20 20 20 20 20 20 20 20 20 31 30 20 20 2f em 10 /
18df0 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 20 69 * Store result i
18e00 6e 20 61 20 6d 65 6d 6f 72 79 20 63 65 6c 6c 20 n a memory cell
18e10 2a 2f 0a 23 64 65 66 69 6e 65 20 53 52 54 5f 53 */.#define SRT_S
18e20 65 74 20 20 20 20 20 20 20 20 20 31 31 20 20 2f et 11 /
18e30 2a 20 53 74 6f 72 65 20 72 65 73 75 6c 74 73 20 * Store results
18e40 61 73 20 6b 65 79 73 20 69 6e 20 61 6e 20 69 6e as keys in an in
18e50 64 65 78 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 dex */.#define S
18e60 52 54 5f 45 70 68 65 6d 54 61 62 20 20 20 20 31 RT_EphemTab 1
18e70 32 20 20 2f 2a 20 43 72 65 61 74 65 20 74 72 61 2 /* Create tra
18e80 6e 73 69 65 6e 74 20 74 61 62 20 61 6e 64 20 73 nsient tab and s
18e90 74 6f 72 65 20 6c 69 6b 65 20 53 52 54 5f 54 61 tore like SRT_Ta
18ea0 62 6c 65 20 2a 2f 0a 23 64 65 66 69 6e 65 20 53 ble */.#define S
18eb0 52 54 5f 43 6f 72 6f 75 74 69 6e 65 20 20 20 31 RT_Coroutine 1
18ec0 33 20 20 2f 2a 20 47 65 6e 65 72 61 74 65 20 61 3 /* Generate a
18ed0 20 73 69 6e 67 6c 65 20 72 6f 77 20 6f 66 20 72 single row of r
18ee0 65 73 75 6c 74 20 2a 2f 0a 23 64 65 66 69 6e 65 esult */.#define
18ef0 20 53 52 54 5f 54 61 62 6c 65 20 20 20 20 20 20 SRT_Table
18f00 20 31 34 20 20 2f 2a 20 53 74 6f 72 65 20 72 65 14 /* Store re
18f10 73 75 6c 74 20 61 73 20 64 61 74 61 20 77 69 74 sult as data wit
18f20 68 20 61 6e 20 61 75 74 6f 6d 61 74 69 63 20 72 h an automatic r
18f30 6f 77 69 64 20 2a 2f 0a 0a 2f 2a 0a 2a 2a 20 41 owid */../*.** A
18f40 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 74 68 n instance of th
18f50 69 73 20 6f 62 6a 65 63 74 20 64 65 73 63 72 69 is object descri
18f60 62 65 73 20 77 68 65 72 65 20 74 6f 20 70 75 74 bes where to put
18f70 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 73 20 of the results
18f80 6f 66 0a 2a 2a 20 61 20 53 45 4c 45 43 54 20 73 of.** a SELECT s
18f90 74 61 74 65 6d 65 6e 74 2e 0a 2a 2f 0a 73 74 72 tatement..*/.str
18fa0 75 63 74 20 53 65 6c 65 63 74 44 65 73 74 20 7b uct SelectDest {
18fb0 0a 20 20 75 38 20 65 44 65 73 74 3b 20 20 20 20 . u8 eDest;
18fc0 20 20 20 20 20 20 20 20 2f 2a 20 48 6f 77 20 74 /* How t
18fd0 6f 20 64 69 73 70 6f 73 65 20 6f 66 20 74 68 65 o dispose of the
18fe0 20 72 65 73 75 6c 74 73 2e 20 20 4f 6e 20 6f 66 results. On of
18ff0 20 53 52 54 5f 2a 20 61 62 6f 76 65 2e 20 2a 2f SRT_* above. */
19000 0a 20 20 63 68 61 72 20 61 66 66 53 64 73 74 3b . char affSdst;
19010 20 20 20 20 20 20 20 20 2f 2a 20 41 66 66 69 6e /* Affin
19020 69 74 79 20 75 73 65 64 20 77 68 65 6e 20 65 44 ity used when eD
19030 65 73 74 3d 3d 53 52 54 5f 53 65 74 20 2a 2f 0a est==SRT_Set */.
19040 20 20 69 6e 74 20 69 53 44 50 61 72 6d 3b 20 20 int iSDParm;
19050 20 20 20 20 20 20 20 2f 2a 20 41 20 70 61 72 61 /* A para
19060 6d 65 74 65 72 20 75 73 65 64 20 62 79 20 74 68 meter used by th
19070 65 20 65 44 65 73 74 20 64 69 73 70 6f 73 61 6c e eDest disposal
19080 20 6d 65 74 68 6f 64 20 2a 2f 0a 20 20 69 6e 74 method */. int
19090 20 69 53 64 73 74 3b 20 20 20 20 20 20 20 20 20 iSdst;
190a0 20 20 2f 2a 20 42 61 73 65 20 72 65 67 69 73 74 /* Base regist
190b0 65 72 20 77 68 65 72 65 20 72 65 73 75 6c 74 73 er where results
190c0 20 61 72 65 20 77 72 69 74 74 65 6e 20 2a 2f 0a are written */.
190d0 20 20 69 6e 74 20 6e 53 64 73 74 3b 20 20 20 20 int nSdst;
190e0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
190f0 20 6f 66 20 72 65 67 69 73 74 65 72 73 20 61 6c of registers al
19100 6c 6f 63 61 74 65 64 20 2a 2f 0a 20 20 45 78 70 located */. Exp
19110 72 4c 69 73 74 20 2a 70 4f 72 64 65 72 42 79 3b rList *pOrderBy;
19120 20 20 2f 2a 20 4b 65 79 20 63 6f 6c 75 6d 6e 73 /* Key columns
19130 20 66 6f 72 20 53 52 54 5f 51 75 65 75 65 20 61 for SRT_Queue a
19140 6e 64 20 53 52 54 5f 44 69 73 74 51 75 65 75 65 nd SRT_DistQueue
19150 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 44 75 */.};../*.** Du
19160 72 69 6e 67 20 63 6f 64 65 20 67 65 6e 65 72 61 ring code genera
19170 74 69 6f 6e 20 6f 66 20 73 74 61 74 65 6d 65 6e tion of statemen
19180 74 73 20 74 68 61 74 20 64 6f 20 69 6e 73 65 72 ts that do inser
19190 74 73 20 69 6e 74 6f 20 41 55 54 4f 49 4e 43 52 ts into AUTOINCR
191a0 45 4d 45 4e 54 20 0a 2a 2a 20 74 61 62 6c 65 73 EMENT .** tables
191b0 2c 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 , the following
191c0 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 69 73 20 61 information is a
191d0 74 74 61 63 68 65 64 20 74 6f 20 74 68 65 20 54 ttached to the T
191e0 61 62 6c 65 2e 75 2e 61 75 74 6f 49 6e 63 2e 70 able.u.autoInc.p
191f0 0a 2a 2a 20 70 6f 69 6e 74 65 72 20 6f 66 20 65 .** pointer of e
19200 61 63 68 20 61 75 74 6f 69 6e 63 72 65 6d 65 6e ach autoincremen
19210 74 20 74 61 62 6c 65 20 74 6f 20 72 65 63 6f 72 t table to recor
19220 64 20 73 6f 6d 65 20 73 69 64 65 20 69 6e 66 6f d some side info
19230 72 6d 61 74 69 6f 6e 20 74 68 61 74 0a 2a 2a 20 rmation that.**
19240 74 68 65 20 63 6f 64 65 20 67 65 6e 65 72 61 74 the code generat
19250 6f 72 20 6e 65 65 64 73 2e 20 20 57 65 20 68 61 or needs. We ha
19260 76 65 20 74 6f 20 6b 65 65 70 20 70 65 72 2d 74 ve to keep per-t
19270 61 62 6c 65 20 61 75 74 6f 69 6e 63 72 65 6d 65 able autoincreme
19280 6e 74 0a 2a 2a 20 69 6e 66 6f 72 6d 61 74 69 6f nt.** informatio
19290 6e 20 69 6e 20 63 61 73 65 20 69 6e 73 65 72 74 n in case insert
192a0 73 20 61 72 65 20 64 6f 77 6e 20 77 69 74 68 69 s are down withi
192b0 6e 20 74 72 69 67 67 65 72 73 2e 20 20 54 72 69 n triggers. Tri
192c0 67 67 65 72 73 20 64 6f 20 6e 6f 74 0a 2a 2a 20 ggers do not.**
192d0 6e 6f 72 6d 61 6c 6c 79 20 63 6f 6f 72 64 69 6e normally coordin
192e0 61 74 65 20 74 68 65 69 72 20 61 63 74 69 76 69 ate their activi
192f0 74 69 65 73 2c 20 62 75 74 20 77 65 20 64 6f 20 ties, but we do
19300 6e 65 65 64 20 74 6f 20 63 6f 6f 72 64 69 6e 61 need to coordina
19310 74 65 20 74 68 65 0a 2a 2a 20 6c 6f 61 64 69 6e te the.** loadin
19320 67 20 61 6e 64 20 73 61 76 69 6e 67 20 6f 66 20 g and saving of
19330 61 75 74 6f 69 6e 63 72 65 6d 65 6e 74 20 69 6e autoincrement in
19340 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 73 74 formation..*/.st
19350 72 75 63 74 20 41 75 74 6f 69 6e 63 49 6e 66 6f ruct AutoincInfo
19360 20 7b 0a 20 20 41 75 74 6f 69 6e 63 49 6e 66 6f {. AutoincInfo
19370 20 2a 70 4e 65 78 74 3b 20 20 20 2f 2a 20 4e 65 *pNext; /* Ne
19380 78 74 20 69 6e 66 6f 20 62 6c 6f 63 6b 20 69 6e xt info block in
19390 20 61 20 6c 69 73 74 20 6f 66 20 74 68 65 6d 20 a list of them
193a0 61 6c 6c 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a all */. Table *
193b0 70 54 61 62 3b 20 20 20 20 20 20 20 20 20 20 2f pTab; /
193c0 2a 20 54 61 62 6c 65 20 74 68 69 73 20 69 6e 66 * Table this inf
193d0 6f 20 62 6c 6f 63 6b 20 72 65 66 65 72 73 20 74 o block refers t
193e0 6f 20 2a 2f 0a 20 20 69 6e 74 20 69 44 62 3b 20 o */. int iDb;
193f0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
19400 49 6e 64 65 78 20 69 6e 20 73 71 6c 69 74 65 33 Index in sqlite3
19410 2e 61 44 62 5b 5d 20 6f 66 20 64 61 74 61 62 61 .aDb[] of databa
19420 73 65 20 68 6f 6c 64 69 6e 67 20 70 54 61 62 20 se holding pTab
19430 2a 2f 0a 20 20 69 6e 74 20 72 65 67 43 74 72 3b */. int regCtr;
19440 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 65 /* Me
19450 6d 6f 72 79 20 72 65 67 69 73 74 65 72 20 68 6f mory register ho
19460 6c 64 69 6e 67 20 74 68 65 20 72 6f 77 69 64 20 lding the rowid
19470 63 6f 75 6e 74 65 72 20 2a 2f 0a 7d 3b 0a 0a 2f counter */.};../
19480 2a 0a 2a 2a 20 53 69 7a 65 20 6f 66 20 74 68 65 *.** Size of the
19490 20 63 6f 6c 75 6d 6e 20 63 61 63 68 65 0a 2a 2f column cache.*/
194a0 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
194b0 4e 5f 43 4f 4c 43 41 43 48 45 0a 23 20 64 65 66 N_COLCACHE.# def
194c0 69 6e 65 20 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c ine SQLITE_N_COL
194d0 43 41 43 48 45 20 31 30 0a 23 65 6e 64 69 66 0a CACHE 10.#endif.
194e0 0a 2f 2a 0a 2a 2a 20 41 74 20 6c 65 61 73 74 20 ./*.** At least
194f0 6f 6e 65 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 one instance of
19500 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 74 the following st
19510 72 75 63 74 75 72 65 20 69 73 20 63 72 65 61 74 ructure is creat
19520 65 64 20 66 6f 72 20 65 61 63 68 20 0a 2a 2a 20 ed for each .**
19530 74 72 69 67 67 65 72 20 74 68 61 74 20 6d 61 79 trigger that may
19540 20 62 65 20 66 69 72 65 64 20 77 68 69 6c 65 20 be fired while
19550 70 61 72 73 69 6e 67 20 61 6e 20 49 4e 53 45 52 parsing an INSER
19560 54 2c 20 55 50 44 41 54 45 20 6f 72 20 44 45 4c T, UPDATE or DEL
19570 45 54 45 0a 2a 2a 20 73 74 61 74 65 6d 65 6e 74 ETE.** statement
19580 2e 20 41 6c 6c 20 73 75 63 68 20 6f 62 6a 65 63 . All such objec
19590 74 73 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e ts are stored in
195a0 20 74 68 65 20 6c 69 6e 6b 65 64 20 6c 69 73 74 the linked list
195b0 20 68 65 61 64 65 64 20 61 74 0a 2a 2a 20 50 61 headed at.** Pa
195c0 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 rse.pTriggerPrg
195d0 61 6e 64 20 64 65 6c 65 74 65 64 20 6f 6e 63 65 and deleted once
195e0 20 73 74 61 74 65 6d 65 6e 74 20 63 6f 6d 70 69 statement compi
195f0 6c 61 74 69 6f 6e 20 68 61 73 20 62 65 65 6e 0a lation has been.
19600 2a 2a 20 63 6f 6d 70 6c 65 74 65 64 2e 0a 2a 2a ** completed..**
19610 0a 2a 2a 20 41 20 56 64 62 65 20 73 75 62 2d 70 .** A Vdbe sub-p
19620 72 6f 67 72 61 6d 20 74 68 61 74 20 69 6d 70 6c rogram that impl
19630 65 6d 65 6e 74 73 20 74 68 65 20 62 6f 64 79 20 ements the body
19640 61 6e 64 20 57 48 45 4e 20 63 6c 61 75 73 65 20 and WHEN clause
19650 6f 66 20 74 72 69 67 67 65 72 0a 2a 2a 20 54 72 of trigger.** Tr
19660 69 67 67 65 72 50 72 67 2e 70 54 72 69 67 67 65 iggerPrg.pTrigge
19670 72 2c 20 61 73 73 75 6d 69 6e 67 20 61 20 64 65 r, assuming a de
19680 66 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 fault ON CONFLIC
19690 54 20 63 6c 61 75 73 65 20 6f 66 0a 2a 2a 20 54 T clause of.** T
196a0 72 69 67 67 65 72 50 72 67 2e 6f 72 63 6f 6e 66 riggerPrg.orconf
196b0 2c 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 , is stored in t
196c0 68 65 20 54 72 69 67 67 65 72 50 72 67 2e 70 50 he TriggerPrg.pP
196d0 72 6f 67 72 61 6d 20 76 61 72 69 61 62 6c 65 2e rogram variable.
196e0 0a 2a 2a 20 54 68 65 20 50 61 72 73 65 2e 70 54 .** The Parse.pT
196f0 72 69 67 67 65 72 50 72 67 20 6c 69 73 74 20 6e riggerPrg list n
19700 65 76 65 72 20 63 6f 6e 74 61 69 6e 73 20 74 77 ever contains tw
19710 6f 20 65 6e 74 72 69 65 73 20 77 69 74 68 20 74 o entries with t
19720 68 65 20 73 61 6d 65 0a 2a 2a 20 76 61 6c 75 65 he same.** value
19730 73 20 66 6f 72 20 62 6f 74 68 20 70 54 72 69 67 s for both pTrig
19740 67 65 72 20 61 6e 64 20 6f 72 63 6f 6e 66 2e 0a ger and orconf..
19750 2a 2a 0a 2a 2a 20 54 68 65 20 54 72 69 67 67 65 **.** The Trigge
19760 72 50 72 67 2e 61 43 6f 6c 6d 61 73 6b 5b 30 5d rPrg.aColmask[0]
19770 20 76 61 72 69 61 62 6c 65 20 69 73 20 73 65 74 variable is set
19780 20 74 6f 20 61 20 6d 61 73 6b 20 6f 66 20 6f 6c to a mask of ol
19790 64 2e 2a 20 63 6f 6c 75 6d 6e 73 0a 2a 2a 20 61 d.* columns.** a
197a0 63 63 65 73 73 65 64 20 28 6f 72 20 73 65 74 20 ccessed (or set
197b0 74 6f 20 30 20 66 6f 72 20 74 72 69 67 67 65 72 to 0 for trigger
197c0 73 20 66 69 72 65 64 20 61 73 20 61 20 72 65 73 s fired as a res
197d0 75 6c 74 20 6f 66 20 49 4e 53 45 52 54 20 0a 2a ult of INSERT .*
197e0 2a 20 73 74 61 74 65 6d 65 6e 74 73 29 2e 20 53 * statements). S
197f0 69 6d 69 6c 61 72 6c 79 2c 20 74 68 65 20 54 72 imilarly, the Tr
19800 69 67 67 65 72 50 72 67 2e 61 43 6f 6c 6d 61 73 iggerPrg.aColmas
19810 6b 5b 31 5d 20 76 61 72 69 61 62 6c 65 20 69 73 k[1] variable is
19820 20 73 65 74 20 74 6f 0a 2a 2a 20 61 20 6d 61 73 set to.** a mas
19830 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d k of new.* colum
19840 6e 73 20 75 73 65 64 20 62 79 20 74 68 65 20 70 ns used by the p
19850 72 6f 67 72 61 6d 2e 0a 2a 2f 0a 73 74 72 75 63 rogram..*/.struc
19860 74 20 54 72 69 67 67 65 72 50 72 67 20 7b 0a 20 t TriggerPrg {.
19870 20 54 72 69 67 67 65 72 20 2a 70 54 72 69 67 67 Trigger *pTrigg
19880 65 72 3b 20 20 20 20 20 20 2f 2a 20 54 72 69 67 er; /* Trig
19890 67 65 72 20 74 68 69 73 20 70 72 6f 67 72 61 6d ger this program
198a0 20 77 61 73 20 63 6f 64 65 64 20 66 72 6f 6d 20 was coded from
198b0 2a 2f 0a 20 20 54 72 69 67 67 65 72 50 72 67 20 */. TriggerPrg
198c0 2a 70 4e 65 78 74 3b 20 20 20 20 20 20 2f 2a 20 *pNext; /*
198d0 4e 65 78 74 20 65 6e 74 72 79 20 69 6e 20 50 61 Next entry in Pa
198e0 72 73 65 2e 70 54 72 69 67 67 65 72 50 72 67 20 rse.pTriggerPrg
198f0 6c 69 73 74 20 2a 2f 0a 20 20 53 75 62 50 72 6f list */. SubPro
19900 67 72 61 6d 20 2a 70 50 72 6f 67 72 61 6d 3b 20 gram *pProgram;
19910 20 20 2f 2a 20 50 72 6f 67 72 61 6d 20 69 6d 70 /* Program imp
19920 6c 65 6d 65 6e 74 69 6e 67 20 70 54 72 69 67 67 lementing pTrigg
19930 65 72 2f 6f 72 63 6f 6e 66 20 2a 2f 0a 20 20 69 er/orconf */. i
19940 6e 74 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 20 nt orconf;
19950 20 20 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c /* Defaul
19960 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 70 6f t ON CONFLICT po
19970 6c 69 63 79 20 2a 2f 0a 20 20 75 33 32 20 61 43 licy */. u32 aC
19980 6f 6c 6d 61 73 6b 5b 32 5d 3b 20 20 20 20 20 20 olmask[2];
19990 20 20 2f 2a 20 4d 61 73 6b 73 20 6f 66 20 6f 6c /* Masks of ol
199a0 64 2e 2a 2c 20 6e 65 77 2e 2a 20 63 6f 6c 75 6d d.*, new.* colum
199b0 6e 73 20 61 63 63 65 73 73 65 64 20 2a 2f 0a 7d ns accessed */.}
199c0 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 79 44 62 ;../*.** The yDb
199d0 4d 61 73 6b 20 64 61 74 61 74 79 70 65 20 66 6f Mask datatype fo
199e0 72 20 74 68 65 20 62 69 74 6d 61 73 6b 20 6f 66 r the bitmask of
199f0 20 61 6c 6c 20 61 74 74 61 63 68 65 64 20 64 61 all attached da
19a00 74 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 69 66 20 tabases..*/.#if
19a10 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 SQLITE_MAX_ATTAC
19a20 48 45 44 3e 33 30 0a 20 20 74 79 70 65 64 65 66 HED>30. typedef
19a30 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 79 unsigned char y
19a40 44 62 4d 61 73 6b 5b 28 53 51 4c 49 54 45 5f 4d DbMask[(SQLITE_M
19a50 41 58 5f 41 54 54 41 43 48 45 44 2b 39 29 2f 38 AX_ATTACHED+9)/8
19a60 5d 3b 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 ];.# define DbMa
19a70 73 6b 54 65 73 74 28 4d 2c 49 29 20 20 20 20 28 skTest(M,I) (
19a80 28 28 4d 29 5b 28 49 29 2f 38 5d 26 28 31 3c 3c ((M)[(I)/8]&(1<<
19a90 28 28 49 29 26 37 29 29 29 21 3d 30 29 0a 23 20 ((I)&7)))!=0).#
19aa0 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 5a 65 72 define DbMaskZer
19ab0 6f 28 4d 29 20 20 20 20 20 20 6d 65 6d 73 65 74 o(M) memset
19ac0 28 28 4d 29 2c 30 2c 73 69 7a 65 6f 66 28 4d 29 ((M),0,sizeof(M)
19ad0 29 0a 23 20 64 65 66 69 6e 65 20 44 62 4d 61 73 ).# define DbMas
19ae0 6b 53 65 74 28 4d 2c 49 29 20 20 20 20 20 28 4d kSet(M,I) (M
19af0 29 5b 28 49 29 2f 38 5d 7c 3d 28 31 3c 3c 28 28 )[(I)/8]|=(1<<((
19b00 49 29 26 37 29 29 0a 23 20 64 65 66 69 6e 65 20 I)&7)).# define
19b10 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 DbMaskAllZero(M)
19b20 20 20 20 73 71 6c 69 74 65 33 44 62 4d 61 73 6b sqlite3DbMask
19b30 41 6c 6c 5a 65 72 6f 28 4d 29 0a 23 20 64 65 66 AllZero(M).# def
19b40 69 6e 65 20 44 62 4d 61 73 6b 4e 6f 6e 5a 65 72 ine DbMaskNonZer
19b50 6f 28 4d 29 20 20 20 28 73 71 6c 69 74 65 33 44 o(M) (sqlite3D
19b60 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 4d 29 3d bMaskAllZero(M)=
19b70 3d 30 29 0a 23 65 6c 73 65 0a 20 20 74 79 70 65 =0).#else. type
19b80 64 65 66 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 def unsigned int
19b90 20 79 44 62 4d 61 73 6b 3b 0a 23 20 64 65 66 69 yDbMask;.# defi
19ba0 6e 65 20 44 62 4d 61 73 6b 54 65 73 74 28 4d 2c ne DbMaskTest(M,
19bb0 49 29 20 20 20 20 28 28 28 4d 29 26 28 28 28 79 I) (((M)&(((y
19bc0 44 62 4d 61 73 6b 29 31 29 3c 3c 28 49 29 29 29 DbMask)1)<<(I)))
19bd0 21 3d 30 29 0a 23 20 64 65 66 69 6e 65 20 44 62 !=0).# define Db
19be0 4d 61 73 6b 5a 65 72 6f 28 4d 29 20 20 20 20 20 MaskZero(M)
19bf0 20 28 4d 29 3d 30 0a 23 20 64 65 66 69 6e 65 20 (M)=0.# define
19c00 44 62 4d 61 73 6b 53 65 74 28 4d 2c 49 29 20 20 DbMaskSet(M,I)
19c10 20 20 20 28 4d 29 7c 3d 28 28 28 79 44 62 4d 61 (M)|=(((yDbMa
19c20 73 6b 29 31 29 3c 3c 28 49 29 29 0a 23 20 64 65 sk)1)<<(I)).# de
19c30 66 69 6e 65 20 44 62 4d 61 73 6b 41 6c 6c 5a 65 fine DbMaskAllZe
19c40 72 6f 28 4d 29 20 20 20 28 4d 29 3d 3d 30 0a 23 ro(M) (M)==0.#
19c50 20 64 65 66 69 6e 65 20 44 62 4d 61 73 6b 4e 6f define DbMaskNo
19c60 6e 5a 65 72 6f 28 4d 29 20 20 20 28 4d 29 21 3d nZero(M) (M)!=
19c70 30 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 0.#endif../*.**
19c80 41 6e 20 53 51 4c 20 70 61 72 73 65 72 20 63 6f An SQL parser co
19c90 6e 74 65 78 74 2e 20 20 41 20 63 6f 70 79 20 6f ntext. A copy o
19ca0 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
19cb0 20 69 73 20 70 61 73 73 65 64 20 74 68 72 6f 75 is passed throu
19cc0 67 68 0a 2a 2a 20 74 68 65 20 70 61 72 73 65 72 gh.** the parser
19cd0 20 61 6e 64 20 64 6f 77 6e 20 69 6e 74 6f 20 61 and down into a
19ce0 6c 6c 20 74 68 65 20 70 61 72 73 65 72 20 61 63 ll the parser ac
19cf0 74 69 6f 6e 20 72 6f 75 74 69 6e 65 20 69 6e 20 tion routine in
19d00 6f 72 64 65 72 20 74 6f 0a 2a 2a 20 63 61 72 72 order to.** carr
19d10 79 20 61 72 6f 75 6e 64 20 69 6e 66 6f 72 6d 61 y around informa
19d20 74 69 6f 6e 20 74 68 61 74 20 69 73 20 67 6c 6f tion that is glo
19d30 62 61 6c 20 74 6f 20 74 68 65 20 65 6e 74 69 72 bal to the entir
19d40 65 20 70 61 72 73 65 2e 0a 2a 2a 0a 2a 2a 20 54 e parse..**.** T
19d50 68 65 20 73 74 72 75 63 74 75 72 65 20 69 73 20 he structure is
19d60 64 69 76 69 64 65 64 20 69 6e 74 6f 20 74 77 6f divided into two
19d70 20 70 61 72 74 73 2e 20 20 57 68 65 6e 20 74 68 parts. When th
19d80 65 20 70 61 72 73 65 72 20 61 6e 64 20 63 6f 64 e parser and cod
19d90 65 0a 2a 2a 20 67 65 6e 65 72 61 74 65 20 63 61 e.** generate ca
19da0 6c 6c 20 74 68 65 6d 73 65 6c 76 65 73 20 72 65 ll themselves re
19db0 63 75 72 73 69 76 65 6c 79 2c 20 74 68 65 20 66 cursively, the f
19dc0 69 72 73 74 20 70 61 72 74 20 6f 66 20 74 68 65 irst part of the
19dd0 20 73 74 72 75 63 74 75 72 65 0a 2a 2a 20 69 73 structure.** is
19de0 20 63 6f 6e 73 74 61 6e 74 20 62 75 74 20 74 68 constant but th
19df0 65 20 73 65 63 6f 6e 64 20 70 61 72 74 20 69 73 e second part is
19e00 20 72 65 73 65 74 20 61 74 20 74 68 65 20 62 65 reset at the be
19e10 67 69 6e 6e 69 6e 67 20 61 6e 64 20 65 6e 64 20 ginning and end
19e20 6f 66 0a 2a 2a 20 65 61 63 68 20 72 65 63 75 72 of.** each recur
19e30 73 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 sion..**.** The
19e40 6e 54 61 62 6c 65 4c 6f 63 6b 20 61 6e 64 20 61 nTableLock and a
19e50 54 61 62 6c 65 4c 6f 63 6b 20 76 61 72 69 61 62 TableLock variab
19e60 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 75 73 65 les are only use
19e70 64 20 69 66 20 74 68 65 20 73 68 61 72 65 64 2d d if the shared-
19e80 63 61 63 68 65 20 0a 2a 2a 20 66 65 61 74 75 72 cache .** featur
19e90 65 20 69 73 20 65 6e 61 62 6c 65 64 20 28 69 66 e is enabled (if
19ea0 20 73 71 6c 69 74 65 33 54 73 64 28 29 2d 3e 75 sqlite3Tsd()->u
19eb0 73 65 53 68 61 72 65 64 44 61 74 61 20 69 73 20 seSharedData is
19ec0 74 72 75 65 29 2e 20 54 68 65 79 20 61 72 65 0a true). They are.
19ed0 2a 2a 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 ** used to store
19ee0 20 74 68 65 20 73 65 74 20 6f 66 20 74 61 62 6c the set of tabl
19ef0 65 2d 6c 6f 63 6b 73 20 72 65 71 75 69 72 65 64 e-locks required
19f00 20 62 79 20 74 68 65 20 73 74 61 74 65 6d 65 6e by the statemen
19f10 74 20 62 65 69 6e 67 0a 2a 2a 20 63 6f 6d 70 69 t being.** compi
19f20 6c 65 64 2e 20 46 75 6e 63 74 69 6f 6e 20 73 71 led. Function sq
19f30 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b 28 29 lite3TableLock()
19f40 20 69 73 20 75 73 65 64 20 74 6f 20 61 64 64 20 is used to add
19f50 65 6e 74 72 69 65 73 20 74 6f 20 74 68 65 0a 2a entries to the.*
19f60 2a 20 6c 69 73 74 2e 0a 2a 2f 0a 73 74 72 75 63 * list..*/.struc
19f70 74 20 50 61 72 73 65 20 7b 0a 20 20 73 71 6c 69 t Parse {. sqli
19f80 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 20 20 te3 *db;
19f90 20 2f 2a 20 54 68 65 20 6d 61 69 6e 20 64 61 74 /* The main dat
19fa0 61 62 61 73 65 20 73 74 72 75 63 74 75 72 65 20 abase structure
19fb0 2a 2f 0a 20 20 63 68 61 72 20 2a 7a 45 72 72 4d */. char *zErrM
19fc0 73 67 3b 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 sg; /* An
19fd0 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 2a 2f error message */
19fe0 0a 20 20 56 64 62 65 20 2a 70 56 64 62 65 3b 20 . Vdbe *pVdbe;
19ff0 20 20 20 20 20 20 20 20 2f 2a 20 41 6e 20 65 6e /* An en
1a000 67 69 6e 65 20 66 6f 72 20 65 78 65 63 75 74 69 gine for executi
1a010 6e 67 20 64 61 74 61 62 61 73 65 20 62 79 74 65 ng database byte
1a020 63 6f 64 65 20 2a 2f 0a 20 20 69 6e 74 20 72 63 code */. int rc
1a030 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f ; /
1a040 2a 20 52 65 74 75 72 6e 20 63 6f 64 65 20 66 72 * Return code fr
1a050 6f 6d 20 65 78 65 63 75 74 69 6f 6e 20 2a 2f 0a om execution */.
1a060 20 20 75 38 20 63 6f 6c 4e 61 6d 65 73 53 65 74 u8 colNamesSet
1a070 3b 20 20 20 20 20 20 2f 2a 20 54 52 55 45 20 61 ; /* TRUE a
1a080 66 74 65 72 20 4f 50 5f 43 6f 6c 75 6d 6e 4e 61 fter OP_ColumnNa
1a090 6d 65 20 68 61 73 20 62 65 65 6e 20 69 73 73 75 me has been issu
1a0a0 65 64 20 74 6f 20 70 56 64 62 65 20 2a 2f 0a 20 ed to pVdbe */.
1a0b0 20 75 38 20 63 68 65 63 6b 53 63 68 65 6d 61 3b u8 checkSchema;
1a0c0 20 20 20 20 20 20 2f 2a 20 43 61 75 73 65 73 20 /* Causes
1a0d0 73 63 68 65 6d 61 20 63 6f 6f 6b 69 65 20 63 68 schema cookie ch
1a0e0 65 63 6b 20 61 66 74 65 72 20 61 6e 20 65 72 72 eck after an err
1a0f0 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 65 73 74 65 or */. u8 neste
1a100 64 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 d; /*
1a110 4e 75 6d 62 65 72 20 6f 66 20 6e 65 73 74 65 64 Number of nested
1a120 20 63 61 6c 6c 73 20 74 6f 20 74 68 65 20 70 61 calls to the pa
1a130 72 73 65 72 2f 63 6f 64 65 20 67 65 6e 65 72 61 rser/code genera
1a140 74 6f 72 20 2a 2f 0a 20 20 75 38 20 6e 54 65 6d tor */. u8 nTem
1a150 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 2f 2a pReg; /*
1a160 20 4e 75 6d 62 65 72 20 6f 66 20 74 65 6d 70 6f Number of tempo
1a170 72 61 72 79 20 72 65 67 69 73 74 65 72 73 20 69 rary registers i
1a180 6e 20 61 54 65 6d 70 52 65 67 5b 5d 20 2a 2f 0a n aTempReg[] */.
1a190 20 20 75 38 20 69 73 4d 75 6c 74 69 57 72 69 74 u8 isMultiWrit
1a1a0 65 3b 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 e; /* True i
1a1b0 66 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 f statement may
1a1c0 6d 6f 64 69 66 79 2f 69 6e 73 65 72 74 20 6d 75 modify/insert mu
1a1d0 6c 74 69 70 6c 65 20 72 6f 77 73 20 2a 2f 0a 20 ltiple rows */.
1a1e0 20 75 38 20 6d 61 79 41 62 6f 72 74 3b 20 20 20 u8 mayAbort;
1a1f0 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
1a200 20 73 74 61 74 65 6d 65 6e 74 20 6d 61 79 20 74 statement may t
1a210 68 72 6f 77 20 61 6e 20 41 42 4f 52 54 20 65 78 hrow an ABORT ex
1a220 63 65 70 74 69 6f 6e 20 2a 2f 0a 20 20 75 38 20 ception */. u8
1a230 68 61 73 43 6f 6d 70 6f 75 6e 64 3b 20 20 20 20 hasCompound;
1a240 20 20 2f 2a 20 4e 65 65 64 20 74 6f 20 69 6e 76 /* Need to inv
1a250 6f 6b 65 20 63 6f 6e 76 65 72 74 43 6f 6d 70 6f oke convertCompo
1a260 75 6e 64 53 65 6c 65 63 74 54 6f 53 75 62 71 75 undSelectToSubqu
1a270 65 72 79 28 29 20 2a 2f 0a 20 20 75 38 20 6f 6b ery() */. u8 ok
1a280 43 6f 6e 73 74 46 61 63 74 6f 72 3b 20 20 20 20 ConstFactor;
1a290 2f 2a 20 4f 4b 20 74 6f 20 66 61 63 74 6f 72 20 /* OK to factor
1a2a0 6f 75 74 20 63 6f 6e 73 74 61 6e 74 73 20 2a 2f out constants */
1a2b0 0a 20 20 69 6e 74 20 61 54 65 6d 70 52 65 67 5b . int aTempReg[
1a2c0 38 5d 3b 20 20 20 20 20 2f 2a 20 48 6f 6c 64 69 8]; /* Holdi
1a2d0 6e 67 20 61 72 65 61 20 66 6f 72 20 74 65 6d 70 ng area for temp
1a2e0 6f 72 61 72 79 20 72 65 67 69 73 74 65 72 73 20 orary registers
1a2f0 2a 2f 0a 20 20 69 6e 74 20 6e 52 61 6e 67 65 52 */. int nRangeR
1a300 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 53 69 7a eg; /* Siz
1a310 65 20 6f 66 20 74 68 65 20 74 65 6d 70 6f 72 61 e of the tempora
1a320 72 79 20 72 65 67 69 73 74 65 72 20 62 6c 6f 63 ry register bloc
1a330 6b 20 2a 2f 0a 20 20 69 6e 74 20 69 52 61 6e 67 k */. int iRang
1a340 65 52 65 67 3b 20 20 20 20 20 20 20 2f 2a 20 46 eReg; /* F
1a350 69 72 73 74 20 72 65 67 69 73 74 65 72 20 69 6e irst register in
1a360 20 74 65 6d 70 6f 72 61 72 79 20 72 65 67 69 73 temporary regis
1a370 74 65 72 20 62 6c 6f 63 6b 20 2a 2f 0a 20 20 69 ter block */. i
1a380 6e 74 20 6e 45 72 72 3b 20 20 20 20 20 20 20 20 nt nErr;
1a390 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
1a3a0 20 65 72 72 6f 72 73 20 73 65 65 6e 20 2a 2f 0a errors seen */.
1a3b0 20 20 69 6e 74 20 6e 54 61 62 3b 20 20 20 20 20 int nTab;
1a3c0 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 /* Number
1a3d0 20 6f 66 20 70 72 65 76 69 6f 75 73 6c 79 20 61 of previously a
1a3e0 6c 6c 6f 63 61 74 65 64 20 56 44 42 45 20 63 75 llocated VDBE cu
1a3f0 72 73 6f 72 73 20 2a 2f 0a 20 20 69 6e 74 20 6e rsors */. int n
1a400 4d 65 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 Mem;
1a410 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6d 65 6d /* Number of mem
1a420 6f 72 79 20 63 65 6c 6c 73 20 75 73 65 64 20 73 ory cells used s
1a430 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e 74 20 6e o far */. int n
1a440 53 65 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 Set;
1a450 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 73 65 74 /* Number of set
1a460 73 20 75 73 65 64 20 73 6f 20 66 61 72 20 2a 2f s used so far */
1a470 0a 20 20 69 6e 74 20 6e 4f 6e 63 65 3b 20 20 20 . int nOnce;
1a480 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1a490 72 20 6f 66 20 4f 50 5f 4f 6e 63 65 20 69 6e 73 r of OP_Once ins
1a4a0 74 72 75 63 74 69 6f 6e 73 20 73 6f 20 66 61 72 tructions so far
1a4b0 20 2a 2f 0a 20 20 69 6e 74 20 6e 4f 70 41 6c 6c */. int nOpAll
1a4c0 6f 63 3b 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 oc; /* Nu
1a4d0 6d 62 65 72 20 6f 66 20 73 6c 6f 74 73 20 61 6c mber of slots al
1a4e0 6c 6f 63 61 74 65 64 20 66 6f 72 20 56 64 62 65 located for Vdbe
1a4f0 2e 61 4f 70 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 .aOp[] */. int
1a500 69 46 69 78 65 64 4f 70 3b 20 20 20 20 20 20 20 iFixedOp;
1a510 20 2f 2a 20 4e 65 76 65 72 20 62 61 63 6b 20 6f /* Never back o
1a520 75 74 20 6f 70 63 6f 64 65 73 20 69 46 69 78 65 ut opcodes iFixe
1a530 64 4f 70 2d 31 20 6f 72 20 65 61 72 6c 69 65 72 dOp-1 or earlier
1a540 20 2a 2f 0a 20 20 69 6e 74 20 63 6b 42 61 73 65 */. int ckBase
1a550 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 42 61 ; /* Ba
1a560 73 65 20 72 65 67 69 73 74 65 72 20 6f 66 20 64 se register of d
1a570 61 74 61 20 64 75 72 69 6e 67 20 63 68 65 63 6b ata during check
1a580 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a constraints */.
1a590 20 20 69 6e 74 20 69 50 61 72 74 49 64 78 54 61 int iPartIdxTa
1a5a0 62 3b 20 20 20 20 20 2f 2a 20 54 61 62 6c 65 20 b; /* Table
1a5b0 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 74 6f corresponding to
1a5c0 20 61 20 70 61 72 74 69 61 6c 20 69 6e 64 65 78 a partial index
1a5d0 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 65 */. int iCache
1a5e0 4c 65 76 65 6c 3b 20 20 20 20 20 2f 2a 20 43 6f Level; /* Co
1a5f0 6c 43 61 63 68 65 20 76 61 6c 69 64 20 77 68 65 lCache valid whe
1a600 6e 20 61 43 6f 6c 43 61 63 68 65 5b 5d 2e 69 4c n aColCache[].iL
1a610 65 76 65 6c 3c 3d 69 43 61 63 68 65 4c 65 76 65 evel<=iCacheLeve
1a620 6c 20 2a 2f 0a 20 20 69 6e 74 20 69 43 61 63 68 l */. int iCach
1a630 65 43 6e 74 3b 20 20 20 20 20 20 20 2f 2a 20 43 eCnt; /* C
1a640 6f 75 6e 74 65 72 20 75 73 65 64 20 74 6f 20 67 ounter used to g
1a650 65 6e 65 72 61 74 65 20 61 43 6f 6c 43 61 63 68 enerate aColCach
1a660 65 5b 5d 2e 6c 72 75 20 76 61 6c 75 65 73 20 2a e[].lru values *
1a670 2f 0a 20 20 69 6e 74 20 6e 4c 61 62 65 6c 3b 20 /. int nLabel;
1a680 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1a690 65 72 20 6f 66 20 6c 61 62 65 6c 73 20 75 73 65 er of labels use
1a6a0 64 20 2a 2f 0a 20 20 69 6e 74 20 2a 61 4c 61 62 d */. int *aLab
1a6b0 65 6c 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 53 el; /* S
1a6c0 70 61 63 65 20 74 6f 20 68 6f 6c 64 20 74 68 65 pace to hold the
1a6d0 20 6c 61 62 65 6c 73 20 2a 2f 0a 20 20 73 74 72 labels */. str
1a6e0 75 63 74 20 79 43 6f 6c 43 61 63 68 65 20 7b 0a uct yColCache {.
1a6f0 20 20 20 20 69 6e 74 20 69 54 61 62 6c 65 3b 20 int iTable;
1a700 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 61 62 /* Tab
1a710 6c 65 20 63 75 72 73 6f 72 20 6e 75 6d 62 65 72 le cursor number
1a720 20 2a 2f 0a 20 20 20 20 69 31 36 20 69 43 6f 6c */. i16 iCol
1a730 75 6d 6e 3b 20 20 20 20 20 20 20 20 20 20 2f 2a umn; /*
1a740 20 54 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 6e 75 Table column nu
1a750 6d 62 65 72 20 2a 2f 0a 20 20 20 20 75 38 20 74 mber */. u8 t
1a760 65 6d 70 52 65 67 3b 20 20 20 20 20 20 20 20 20 empReg;
1a770 20 20 2f 2a 20 69 52 65 67 20 69 73 20 61 20 74 /* iReg is a t
1a780 65 6d 70 20 72 65 67 69 73 74 65 72 20 74 68 61 emp register tha
1a790 74 20 6e 65 65 64 73 20 74 6f 20 62 65 20 66 72 t needs to be fr
1a7a0 65 65 64 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 eed */. int i
1a7b0 4c 65 76 65 6c 3b 20 20 20 20 20 20 20 20 20 20 Level;
1a7c0 20 2f 2a 20 4e 65 73 74 69 6e 67 20 6c 65 76 65 /* Nesting leve
1a7d0 6c 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 52 65 l */. int iRe
1a7e0 67 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 2f g; /
1a7f0 2a 20 52 65 67 20 77 69 74 68 20 76 61 6c 75 65 * Reg with value
1a800 20 6f 66 20 74 68 69 73 20 63 6f 6c 75 6d 6e 2e of this column.
1a810 20 30 20 6d 65 61 6e 73 20 6e 6f 6e 65 2e 20 2a 0 means none. *
1a820 2f 0a 20 20 20 20 69 6e 74 20 6c 72 75 3b 20 20 /. int lru;
1a830 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c /* L
1a840 65 61 73 74 20 72 65 63 65 6e 74 6c 79 20 75 73 east recently us
1a850 65 64 20 65 6e 74 72 79 20 68 61 73 20 74 68 65 ed entry has the
1a860 20 73 6d 61 6c 6c 65 73 74 20 76 61 6c 75 65 20 smallest value
1a870 2a 2f 0a 20 20 7d 20 61 43 6f 6c 43 61 63 68 65 */. } aColCache
1a880 5b 53 51 4c 49 54 45 5f 4e 5f 43 4f 4c 43 41 43 [SQLITE_N_COLCAC
1a890 48 45 5d 3b 20 20 2f 2a 20 4f 6e 65 20 66 6f 72 HE]; /* One for
1a8a0 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 63 61 63 each column cac
1a8b0 68 65 20 65 6e 74 72 79 20 2a 2f 0a 20 20 45 78 he entry */. Ex
1a8c0 70 72 4c 69 73 74 20 2a 70 43 6f 6e 73 74 45 78 prList *pConstEx
1a8d0 70 72 3b 2f 2a 20 43 6f 6e 73 74 61 6e 74 20 65 pr;/* Constant e
1a8e0 78 70 72 65 73 73 69 6f 6e 73 20 2a 2f 0a 20 20 xpressions */.
1a8f0 54 6f 6b 65 6e 20 63 6f 6e 73 74 72 61 69 6e 74 Token constraint
1a900 4e 61 6d 65 3b 2f 2a 20 4e 61 6d 65 20 6f 66 20 Name;/* Name of
1a910 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 20 63 the constraint c
1a920 75 72 72 65 6e 74 6c 79 20 62 65 69 6e 67 20 70 urrently being p
1a930 61 72 73 65 64 20 2a 2f 0a 20 20 79 44 62 4d 61 arsed */. yDbMa
1a940 73 6b 20 77 72 69 74 65 4d 61 73 6b 3b 20 20 20 sk writeMask;
1a950 2f 2a 20 53 74 61 72 74 20 61 20 77 72 69 74 65 /* Start a write
1a960 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 6f 6e 20 transaction on
1a970 74 68 65 73 65 20 64 61 74 61 62 61 73 65 73 20 these databases
1a980 2a 2f 0a 20 20 79 44 62 4d 61 73 6b 20 63 6f 6f */. yDbMask coo
1a990 6b 69 65 4d 61 73 6b 3b 20 20 2f 2a 20 42 69 74 kieMask; /* Bit
1a9a0 6d 61 73 6b 20 6f 66 20 73 63 68 65 6d 61 20 76 mask of schema v
1a9b0 65 72 69 66 69 65 64 20 64 61 74 61 62 61 73 65 erified database
1a9c0 73 20 2a 2f 0a 20 20 69 6e 74 20 63 6f 6f 6b 69 s */. int cooki
1a9d0 65 56 61 6c 75 65 5b 53 51 4c 49 54 45 5f 4d 41 eValue[SQLITE_MA
1a9e0 58 5f 41 54 54 41 43 48 45 44 2b 32 5d 3b 20 20 X_ATTACHED+2];
1a9f0 2f 2a 20 56 61 6c 75 65 73 20 6f 66 20 63 6f 6f /* Values of coo
1aa00 6b 69 65 73 20 74 6f 20 76 65 72 69 66 79 20 2a kies to verify *
1aa10 2f 0a 20 20 69 6e 74 20 72 65 67 52 6f 77 69 64 /. int regRowid
1aa20 3b 20 20 20 20 20 20 20 20 2f 2a 20 52 65 67 69 ; /* Regi
1aa30 73 74 65 72 20 68 6f 6c 64 69 6e 67 20 72 6f 77 ster holding row
1aa40 69 64 20 6f 66 20 43 52 45 41 54 45 20 54 41 42 id of CREATE TAB
1aa50 4c 45 20 65 6e 74 72 79 20 2a 2f 0a 20 20 69 6e LE entry */. in
1aa60 74 20 72 65 67 52 6f 6f 74 3b 20 20 20 20 20 20 t regRoot;
1aa70 20 20 20 2f 2a 20 52 65 67 69 73 74 65 72 20 68 /* Register h
1aa80 6f 6c 64 69 6e 67 20 72 6f 6f 74 20 70 61 67 65 olding root page
1aa90 20 6e 75 6d 62 65 72 20 66 6f 72 20 6e 65 77 20 number for new
1aaa0 6f 62 6a 65 63 74 73 20 2a 2f 0a 20 20 69 6e 74 objects */. int
1aab0 20 6e 4d 61 78 41 72 67 3b 20 20 20 20 20 20 20 nMaxArg;
1aac0 20 20 2f 2a 20 4d 61 78 20 61 72 67 73 20 70 61 /* Max args pa
1aad0 73 73 65 64 20 74 6f 20 75 73 65 72 20 66 75 6e ssed to user fun
1aae0 63 74 69 6f 6e 20 62 79 20 73 75 62 2d 70 72 6f ction by sub-pro
1aaf0 67 72 61 6d 20 2a 2f 0a 23 69 66 6e 64 65 66 20 gram */.#ifndef
1ab00 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 48 41 52 SQLITE_OMIT_SHAR
1ab10 45 44 5f 43 41 43 48 45 0a 20 20 69 6e 74 20 6e ED_CACHE. int n
1ab20 54 61 62 6c 65 4c 6f 63 6b 3b 20 20 20 20 20 20 TableLock;
1ab30 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 6c /* Number of l
1ab40 6f 63 6b 73 20 69 6e 20 61 54 61 62 6c 65 4c 6f ocks in aTableLo
1ab50 63 6b 20 2a 2f 0a 20 20 54 61 62 6c 65 4c 6f 63 ck */. TableLoc
1ab60 6b 20 2a 61 54 61 62 6c 65 4c 6f 63 6b 3b 20 2f k *aTableLock; /
1ab70 2a 20 52 65 71 75 69 72 65 64 20 74 61 62 6c 65 * Required table
1ab80 20 6c 6f 63 6b 73 20 66 6f 72 20 73 68 61 72 65 locks for share
1ab90 64 2d 63 61 63 68 65 20 6d 6f 64 65 20 2a 2f 0a d-cache mode */.
1aba0 23 65 6e 64 69 66 0a 20 20 41 75 74 6f 69 6e 63 #endif. Autoinc
1abb0 49 6e 66 6f 20 2a 70 41 69 6e 63 3b 20 20 2f 2a Info *pAinc; /*
1abc0 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f Information abo
1abd0 75 74 20 41 55 54 4f 49 4e 43 52 45 4d 45 4e 54 ut AUTOINCREMENT
1abe0 20 63 6f 75 6e 74 65 72 73 20 2a 2f 0a 0a 20 20 counters */..
1abf0 2f 2a 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 75 /* Information u
1ac00 73 65 64 20 77 68 69 6c 65 20 63 6f 64 69 6e 67 sed while coding
1ac10 20 74 72 69 67 67 65 72 20 70 72 6f 67 72 61 6d trigger program
1ac20 73 2e 20 2a 2f 0a 20 20 50 61 72 73 65 20 2a 70 s. */. Parse *p
1ac30 54 6f 70 6c 65 76 65 6c 3b 20 20 20 20 2f 2a 20 Toplevel; /*
1ac40 50 61 72 73 65 20 73 74 72 75 63 74 75 72 65 20 Parse structure
1ac50 66 6f 72 20 6d 61 69 6e 20 70 72 6f 67 72 61 6d for main program
1ac60 20 28 6f 72 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 (or NULL) */.
1ac70 54 61 62 6c 65 20 2a 70 54 72 69 67 67 65 72 54 Table *pTriggerT
1ac80 61 62 3b 20 20 2f 2a 20 54 61 62 6c 65 20 74 72 ab; /* Table tr
1ac90 69 67 67 65 72 73 20 61 72 65 20 62 65 69 6e 67 iggers are being
1aca0 20 63 6f 64 65 64 20 66 6f 72 20 2a 2f 0a 20 20 coded for */.
1acb0 69 6e 74 20 61 64 64 72 43 72 54 61 62 3b 20 20 int addrCrTab;
1acc0 20 20 20 20 20 2f 2a 20 41 64 64 72 65 73 73 20 /* Address
1acd0 6f 66 20 4f 50 5f 43 72 65 61 74 65 54 61 62 6c of OP_CreateTabl
1ace0 65 20 6f 70 63 6f 64 65 20 6f 6e 20 43 52 45 41 e opcode on CREA
1acf0 54 45 20 54 41 42 4c 45 20 2a 2f 0a 20 20 69 6e TE TABLE */. in
1ad00 74 20 61 64 64 72 53 6b 69 70 50 4b 3b 20 20 20 t addrSkipPK;
1ad10 20 20 20 2f 2a 20 41 64 64 72 65 73 73 20 6f 66 /* Address of
1ad20 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 74 6f 20 instruction to
1ad30 73 6b 69 70 20 50 52 49 4d 41 52 59 20 4b 45 59 skip PRIMARY KEY
1ad40 20 69 6e 64 65 78 20 2a 2f 0a 20 20 75 33 32 20 index */. u32
1ad50 6e 51 75 65 72 79 4c 6f 6f 70 3b 20 20 20 20 20 nQueryLoop;
1ad60 20 2f 2a 20 45 73 74 20 6e 75 6d 62 65 72 20 6f /* Est number o
1ad70 66 20 69 74 65 72 61 74 69 6f 6e 73 20 6f 66 20 f iterations of
1ad80 61 20 71 75 65 72 79 20 28 31 30 2a 6c 6f 67 32 a query (10*log2
1ad90 28 4e 29 29 20 2a 2f 0a 20 20 75 33 32 20 6f 6c (N)) */. u32 ol
1ada0 64 6d 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f dmask; /
1adb0 2a 20 4d 61 73 6b 20 6f 66 20 6f 6c 64 2e 2a 20 * Mask of old.*
1adc0 63 6f 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 columns referenc
1add0 65 64 20 2a 2f 0a 20 20 75 33 32 20 6e 65 77 6d ed */. u32 newm
1ade0 61 73 6b 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 ask; /*
1adf0 4d 61 73 6b 20 6f 66 20 6e 65 77 2e 2a 20 63 6f Mask of new.* co
1ae00 6c 75 6d 6e 73 20 72 65 66 65 72 65 6e 63 65 64 lumns referenced
1ae10 20 2a 2f 0a 20 20 75 38 20 65 54 72 69 67 67 65 */. u8 eTrigge
1ae20 72 4f 70 3b 20 20 20 20 20 20 20 2f 2a 20 54 4b rOp; /* TK
1ae30 5f 55 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 45 _UPDATE, TK_INSE
1ae40 52 54 20 6f 72 20 54 4b 5f 44 45 4c 45 54 45 20 RT or TK_DELETE
1ae50 2a 2f 0a 20 20 75 38 20 65 4f 72 63 6f 6e 66 3b */. u8 eOrconf;
1ae60 20 20 20 20 20 20 20 20 20 20 2f 2a 20 44 65 66 /* Def
1ae70 61 75 6c 74 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 ault ON CONFLICT
1ae80 20 70 6f 6c 69 63 79 20 66 6f 72 20 74 72 69 67 policy for trig
1ae90 67 65 72 20 73 74 65 70 73 20 2a 2f 0a 20 20 75 ger steps */. u
1aea0 38 20 64 69 73 61 62 6c 65 54 72 69 67 67 65 72 8 disableTrigger
1aeb0 73 3b 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 64 s; /* True to d
1aec0 69 73 61 62 6c 65 20 74 72 69 67 67 65 72 73 20 isable triggers
1aed0 2a 2f 0a 0a 20 20 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a */.. /*********
1aee0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1aef0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1af00 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1af10 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a ***************.
1af20 20 20 2a 2a 20 41 62 6f 76 65 20 69 73 20 63 6f ** Above is co
1af30 6e 73 74 61 6e 74 20 62 65 74 77 65 65 6e 20 72 nstant between r
1af40 65 63 75 72 73 69 6f 6e 73 2e 20 20 42 65 6c 6f ecursions. Belo
1af50 77 20 69 73 20 72 65 73 65 74 20 62 65 66 6f 72 w is reset befor
1af60 65 20 61 6e 64 20 61 66 74 65 72 0a 20 20 2a 2a e and after. **
1af70 20 65 61 63 68 20 72 65 63 75 72 73 69 6f 6e 2e each recursion.
1af80 20 20 54 68 65 20 62 6f 75 6e 64 61 72 79 20 62 The boundary b
1af90 65 74 77 65 65 6e 20 74 68 65 73 65 20 74 77 6f etween these two
1afa0 20 72 65 67 69 6f 6e 73 20 69 73 20 64 65 74 65 regions is dete
1afb0 72 6d 69 6e 65 64 0a 20 20 2a 2a 20 75 73 69 6e rmined. ** usin
1afc0 67 20 6f 66 66 73 65 74 6f 66 28 50 61 72 73 65 g offsetof(Parse
1afd0 2c 6e 56 61 72 29 20 73 6f 20 74 68 65 20 6e 56 ,nVar) so the nV
1afe0 61 72 20 66 69 65 6c 64 20 6d 75 73 74 20 62 65 ar field must be
1aff0 20 74 68 65 20 66 69 72 73 74 20 66 69 65 6c 64 the first field
1b000 0a 20 20 2a 2a 20 69 6e 20 74 68 65 20 72 65 63 . ** in the rec
1b010 75 72 73 69 76 65 20 72 65 67 69 6f 6e 2e 0a 20 ursive region..
1b020 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ***************
1b030 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1b040 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1b050 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
1b060 2a 2a 2a 2a 2a 2a 2a 2a 2a 2f 0a 0a 20 20 69 6e *********/.. in
1b070 74 20 6e 56 61 72 3b 20 20 20 20 20 20 20 20 20 t nVar;
1b080 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1b090 72 20 6f 66 20 27 3f 27 20 76 61 72 69 61 62 6c r of '?' variabl
1b0a0 65 73 20 73 65 65 6e 20 69 6e 20 74 68 65 20 53 es seen in the S
1b0b0 51 4c 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 QL so far */. i
1b0c0 6e 74 20 6e 7a 56 61 72 3b 20 20 20 20 20 20 20 nt nzVar;
1b0d0 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 /* Numb
1b0e0 65 72 20 6f 66 20 61 76 61 69 6c 61 62 6c 65 20 er of available
1b0f0 73 6c 6f 74 73 20 69 6e 20 61 7a 56 61 72 5b 5d slots in azVar[]
1b100 20 2a 2f 0a 20 20 75 38 20 69 50 6b 53 6f 72 74 */. u8 iPkSort
1b110 4f 72 64 65 72 3b 20 20 20 20 20 20 20 20 20 20 Order;
1b120 2f 2a 20 41 53 43 20 6f 72 20 44 45 53 43 20 66 /* ASC or DESC f
1b130 6f 72 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 or INTEGER PRIMA
1b140 52 59 20 4b 45 59 20 2a 2f 0a 20 20 75 38 20 62 RY KEY */. u8 b
1b150 46 72 65 65 57 69 74 68 3b 20 20 20 20 20 20 20 FreeWith;
1b160 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 /* True if
1b170 20 70 57 69 74 68 20 73 68 6f 75 6c 64 20 62 65 pWith should be
1b180 20 66 72 65 65 64 20 77 69 74 68 20 70 61 72 73 freed with pars
1b190 65 72 20 2a 2f 0a 20 20 75 38 20 65 78 70 6c 61 er */. u8 expla
1b1a0 69 6e 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 in;
1b1b0 20 20 2f 2a 20 54 72 75 65 20 69 66 20 74 68 65 /* True if the
1b1c0 20 45 58 50 4c 41 49 4e 20 66 6c 61 67 20 69 73 EXPLAIN flag is
1b1d0 20 66 6f 75 6e 64 20 6f 6e 20 74 68 65 20 71 75 found on the qu
1b1e0 65 72 79 20 2a 2f 0a 23 69 66 6e 64 65 66 20 53 ery */.#ifndef S
1b1f0 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 QLITE_OMIT_VIRTU
1b200 41 4c 54 41 42 4c 45 0a 20 20 75 38 20 64 65 63 ALTABLE. u8 dec
1b210 6c 61 72 65 56 74 61 62 3b 20 20 20 20 20 20 20 lareVtab;
1b220 20 20 20 20 2f 2a 20 54 72 75 65 20 69 66 20 69 /* True if i
1b230 6e 73 69 64 65 20 73 71 6c 69 74 65 33 5f 64 65 nside sqlite3_de
1b240 63 6c 61 72 65 5f 76 74 61 62 28 29 20 2a 2f 0a clare_vtab() */.
1b250 20 20 69 6e 74 20 6e 56 74 61 62 4c 6f 63 6b 3b int nVtabLock;
1b260 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e /* N
1b270 75 6d 62 65 72 20 6f 66 20 76 69 72 74 75 61 6c umber of virtual
1b280 20 74 61 62 6c 65 73 20 74 6f 20 6c 6f 63 6b 20 tables to lock
1b290 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 69 6e 74 20 */.#endif. int
1b2a0 6e 41 6c 69 61 73 3b 20 20 20 20 20 20 20 20 20 nAlias;
1b2b0 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 /* Number
1b2c0 6f 66 20 61 6c 69 61 73 65 64 20 72 65 73 75 6c of aliased resul
1b2d0 74 20 73 65 74 20 63 6f 6c 75 6d 6e 73 20 2a 2f t set columns */
1b2e0 0a 20 20 69 6e 74 20 6e 48 65 69 67 68 74 3b 20 . int nHeight;
1b2f0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1b300 45 78 70 72 65 73 73 69 6f 6e 20 74 72 65 65 20 Expression tree
1b310 68 65 69 67 68 74 20 6f 66 20 63 75 72 72 65 6e height of curren
1b320 74 20 73 75 62 2d 73 65 6c 65 63 74 20 2a 2f 0a t sub-select */.
1b330 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
1b340 4d 49 54 5f 45 58 50 4c 41 49 4e 0a 20 20 69 6e MIT_EXPLAIN. in
1b350 74 20 69 53 65 6c 65 63 74 49 64 3b 20 20 20 20 t iSelectId;
1b360 20 20 20 20 20 20 20 20 2f 2a 20 49 44 20 6f 66 /* ID of
1b370 20 63 75 72 72 65 6e 74 20 73 65 6c 65 63 74 20 current select
1b380 66 6f 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 70 for EXPLAIN outp
1b390 75 74 20 2a 2f 0a 20 20 69 6e 74 20 69 4e 65 78 ut */. int iNex
1b3a0 74 53 65 6c 65 63 74 49 64 3b 20 20 20 20 20 20 tSelectId;
1b3b0 20 20 2f 2a 20 4e 65 78 74 20 61 76 61 69 6c 61 /* Next availa
1b3c0 62 6c 65 20 73 65 6c 65 63 74 20 49 44 20 66 6f ble select ID fo
1b3d0 72 20 45 58 50 4c 41 49 4e 20 6f 75 74 70 75 74 r EXPLAIN output
1b3e0 20 2a 2f 0a 23 65 6e 64 69 66 0a 20 20 63 68 61 */.#endif. cha
1b3f0 72 20 2a 2a 61 7a 56 61 72 3b 20 20 20 20 20 20 r **azVar;
1b400 20 20 20 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 /* Pointe
1b410 72 73 20 74 6f 20 6e 61 6d 65 73 20 6f 66 20 70 rs to names of p
1b420 61 72 61 6d 65 74 65 72 73 20 2a 2f 0a 20 20 56 arameters */. V
1b430 64 62 65 20 2a 70 52 65 70 72 65 70 61 72 65 3b dbe *pReprepare;
1b440 20 20 20 20 20 20 20 20 20 2f 2a 20 56 4d 20 62 /* VM b
1b450 65 69 6e 67 20 72 65 70 72 65 70 61 72 65 64 20 eing reprepared
1b460 28 73 71 6c 69 74 65 33 52 65 70 72 65 70 61 72 (sqlite3Reprepar
1b470 65 28 29 29 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 e()) */. const
1b480 63 68 61 72 20 2a 7a 54 61 69 6c 3b 20 20 20 20 char *zTail;
1b490 20 20 20 20 2f 2a 20 41 6c 6c 20 53 51 4c 20 74 /* All SQL t
1b4a0 65 78 74 20 70 61 73 74 20 74 68 65 20 6c 61 73 ext past the las
1b4b0 74 20 73 65 6d 69 63 6f 6c 6f 6e 20 70 61 72 73 t semicolon pars
1b4c0 65 64 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 70 ed */. Table *p
1b4d0 4e 65 77 54 61 62 6c 65 3b 20 20 20 20 20 20 20 NewTable;
1b4e0 20 20 2f 2a 20 41 20 74 61 62 6c 65 20 62 65 69 /* A table bei
1b4f0 6e 67 20 63 6f 6e 73 74 72 75 63 74 65 64 20 62 ng constructed b
1b500 79 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 2a y CREATE TABLE *
1b510 2f 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e 65 /. Trigger *pNe
1b520 77 54 72 69 67 67 65 72 3b 20 20 20 20 20 2f 2a wTrigger; /*
1b530 20 54 72 69 67 67 65 72 20 75 6e 64 65 72 20 63 Trigger under c
1b540 6f 6e 73 74 72 75 63 74 20 62 79 20 61 20 43 52 onstruct by a CR
1b550 45 41 54 45 20 54 52 49 47 47 45 52 20 2a 2f 0a EATE TRIGGER */.
1b560 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 41 const char *zA
1b570 75 74 68 43 6f 6e 74 65 78 74 3b 20 2f 2a 20 54 uthContext; /* T
1b580 68 65 20 36 74 68 20 70 61 72 61 6d 65 74 65 72 he 6th parameter
1b590 20 74 6f 20 64 62 2d 3e 78 41 75 74 68 20 63 61 to db->xAuth ca
1b5a0 6c 6c 62 61 63 6b 73 20 2a 2f 0a 20 20 54 6f 6b llbacks */. Tok
1b5b0 65 6e 20 73 4e 61 6d 65 54 6f 6b 65 6e 3b 20 20 en sNameToken;
1b5c0 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 6e 20 /* Token
1b5d0 77 69 74 68 20 75 6e 71 75 61 6c 69 66 69 65 64 with unqualified
1b5e0 20 73 63 68 65 6d 61 20 6f 62 6a 65 63 74 20 6e schema object n
1b5f0 61 6d 65 20 2a 2f 0a 20 20 54 6f 6b 65 6e 20 73 ame */. Token s
1b600 4c 61 73 74 54 6f 6b 65 6e 3b 20 20 20 20 20 20 LastToken;
1b610 20 20 20 2f 2a 20 54 68 65 20 6c 61 73 74 20 74 /* The last t
1b620 6f 6b 65 6e 20 70 61 72 73 65 64 20 2a 2f 0a 23 oken parsed */.#
1b630 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
1b640 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 0a IT_VIRTUALTABLE.
1b650 20 20 54 6f 6b 65 6e 20 73 41 72 67 3b 20 20 20 Token sArg;
1b660 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 43 /* C
1b670 6f 6d 70 6c 65 74 65 20 74 65 78 74 20 6f 66 20 omplete text of
1b680 61 20 6d 6f 64 75 6c 65 20 61 72 67 75 6d 65 6e a module argumen
1b690 74 20 2a 2f 0a 20 20 54 61 62 6c 65 20 2a 2a 61 t */. Table **a
1b6a0 70 56 74 61 62 4c 6f 63 6b 3b 20 20 20 20 20 20 pVtabLock;
1b6b0 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 76 /* Pointer to v
1b6c0 69 72 74 75 61 6c 20 74 61 62 6c 65 73 20 6e 65 irtual tables ne
1b6d0 65 64 69 6e 67 20 6c 6f 63 6b 69 6e 67 20 2a 2f eding locking */
1b6e0 0a 23 65 6e 64 69 66 0a 20 20 54 61 62 6c 65 20 .#endif. Table
1b6f0 2a 70 5a 6f 6d 62 69 65 54 61 62 3b 20 20 20 20 *pZombieTab;
1b700 20 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 54 /* List of T
1b710 61 62 6c 65 20 6f 62 6a 65 63 74 73 20 74 6f 20 able objects to
1b720 64 65 6c 65 74 65 20 61 66 74 65 72 20 63 6f 64 delete after cod
1b730 65 20 67 65 6e 20 2a 2f 0a 20 20 54 72 69 67 67 e gen */. Trigg
1b740 65 72 50 72 67 20 2a 70 54 72 69 67 67 65 72 50 erPrg *pTriggerP
1b750 72 67 3b 20 20 2f 2a 20 4c 69 6e 6b 65 64 20 6c rg; /* Linked l
1b760 69 73 74 20 6f 66 20 63 6f 64 65 64 20 74 72 69 ist of coded tri
1b770 67 67 65 72 73 20 2a 2f 0a 20 20 57 69 74 68 20 ggers */. With
1b780 2a 70 57 69 74 68 3b 20 20 20 20 20 20 20 20 20 *pWith;
1b790 20 20 20 20 20 2f 2a 20 43 75 72 72 65 6e 74 20 /* Current
1b7a0 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 20 WITH clause, or
1b7b0 4e 55 4c 4c 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a NULL */.};../*.*
1b7c0 2a 20 52 65 74 75 72 6e 20 74 72 75 65 20 69 66 * Return true if
1b7d0 20 63 75 72 72 65 6e 74 6c 79 20 69 6e 73 69 64 currently insid
1b7e0 65 20 61 6e 20 73 71 6c 69 74 65 33 5f 64 65 63 e an sqlite3_dec
1b7f0 6c 61 72 65 5f 76 74 61 62 28 29 20 63 61 6c 6c lare_vtab() call
1b800 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
1b810 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
1b820 41 42 4c 45 0a 20 20 23 64 65 66 69 6e 65 20 49 ABLE. #define I
1b830 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 20 30 N_DECLARE_VTAB 0
1b840 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 .#else. #define
1b850 20 49 4e 5f 44 45 43 4c 41 52 45 5f 56 54 41 42 IN_DECLARE_VTAB
1b860 20 28 70 50 61 72 73 65 2d 3e 64 65 63 6c 61 72 (pParse->declar
1b870 65 56 74 61 62 29 0a 23 65 6e 64 69 66 0a 0a 2f eVtab).#endif../
1b880 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
1b890 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
1b8a0 67 20 73 74 72 75 63 74 75 72 65 20 63 61 6e 20 g structure can
1b8b0 62 65 20 64 65 63 6c 61 72 65 64 20 6f 6e 20 61 be declared on a
1b8c0 20 73 74 61 63 6b 20 61 6e 64 20 75 73 65 64 0a stack and used.
1b8d0 2a 2a 20 74 6f 20 73 61 76 65 20 74 68 65 20 50 ** to save the P
1b8e0 61 72 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 arse.zAuthContex
1b8f0 74 20 76 61 6c 75 65 20 73 6f 20 74 68 61 74 20 t value so that
1b900 69 74 20 63 61 6e 20 62 65 20 72 65 73 74 6f 72 it can be restor
1b910 65 64 20 6c 61 74 65 72 2e 0a 2a 2f 0a 73 74 72 ed later..*/.str
1b920 75 63 74 20 41 75 74 68 43 6f 6e 74 65 78 74 20 uct AuthContext
1b930 7b 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a {. const char *
1b940 7a 41 75 74 68 43 6f 6e 74 65 78 74 3b 20 20 20 zAuthContext;
1b950 2f 2a 20 50 75 74 20 73 61 76 65 64 20 50 61 72 /* Put saved Par
1b960 73 65 2e 7a 41 75 74 68 43 6f 6e 74 65 78 74 20 se.zAuthContext
1b970 68 65 72 65 20 2a 2f 0a 20 20 50 61 72 73 65 20 here */. Parse
1b980 2a 70 50 61 72 73 65 3b 20 20 20 20 20 20 20 20 *pParse;
1b990 20 20 20 20 20 20 2f 2a 20 54 68 65 20 50 61 72 /* The Par
1b9a0 73 65 20 73 74 72 75 63 74 75 72 65 20 2a 2f 0a se structure */.
1b9b0 7d 3b 0a 0a 2f 2a 0a 2a 2a 20 42 69 74 66 69 65 };../*.** Bitfie
1b9c0 6c 64 20 66 6c 61 67 73 20 66 6f 72 20 50 35 20 ld flags for P5
1b9d0 76 61 6c 75 65 20 69 6e 20 76 61 72 69 6f 75 73 value in various
1b9e0 20 6f 70 63 6f 64 65 73 2e 0a 2a 2f 0a 23 64 65 opcodes..*/.#de
1b9f0 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4e 43 48 41 fine OPFLAG_NCHA
1ba00 4e 47 45 20 20 20 20 20 20 20 30 78 30 31 20 20 NGE 0x01
1ba10 20 20 2f 2a 20 53 65 74 20 74 6f 20 75 70 64 61 /* Set to upda
1ba20 74 65 20 64 62 2d 3e 6e 43 68 61 6e 67 65 20 2a te db->nChange *
1ba30 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 /.#define OPFLAG
1ba40 5f 4c 41 53 54 52 4f 57 49 44 20 20 20 20 20 30 _LASTROWID 0
1ba50 78 30 32 20 20 20 20 2f 2a 20 53 65 74 20 74 6f x02 /* Set to
1ba60 20 75 70 64 61 74 65 20 64 62 2d 3e 6c 61 73 74 update db->last
1ba70 52 6f 77 69 64 20 2a 2f 0a 23 64 65 66 69 6e 65 Rowid */.#define
1ba80 20 4f 50 46 4c 41 47 5f 49 53 55 50 44 41 54 45 OPFLAG_ISUPDATE
1ba90 20 20 20 20 20 20 30 78 30 34 20 20 20 20 2f 2a 0x04 /*
1baa0 20 54 68 69 73 20 4f 50 5f 49 6e 73 65 72 74 20 This OP_Insert
1bab0 69 73 20 61 6e 20 73 71 6c 20 55 50 44 41 54 45 is an sql UPDATE
1bac0 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 4c */.#define OPFL
1bad0 41 47 5f 41 50 50 45 4e 44 20 20 20 20 20 20 20 AG_APPEND
1bae0 20 30 78 30 38 20 20 20 20 2f 2a 20 54 68 69 73 0x08 /* This
1baf0 20 69 73 20 6c 69 6b 65 6c 79 20 74 6f 20 62 65 is likely to be
1bb00 20 61 6e 20 61 70 70 65 6e 64 20 2a 2f 0a 23 64 an append */.#d
1bb10 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 55 53 45 efine OPFLAG_USE
1bb20 53 45 45 4b 52 45 53 55 4c 54 20 30 78 31 30 20 SEEKRESULT 0x10
1bb30 20 20 20 2f 2a 20 54 72 79 20 74 6f 20 61 76 6f /* Try to avo
1bb40 69 64 20 61 20 73 65 65 6b 20 69 6e 20 42 74 72 id a seek in Btr
1bb50 65 65 49 6e 73 65 72 74 28 29 20 2a 2f 0a 23 64 eeInsert() */.#d
1bb60 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 43 4c 45 efine OPFLAG_CLE
1bb70 41 52 43 41 43 48 45 20 20 20 20 30 78 32 30 20 ARCACHE 0x20
1bb80 20 20 20 2f 2a 20 43 6c 65 61 72 20 70 73 65 75 /* Clear pseu
1bb90 64 6f 2d 74 61 62 6c 65 20 63 61 63 68 65 20 69 do-table cache i
1bba0 6e 20 4f 50 5f 43 6f 6c 75 6d 6e 20 2a 2f 0a 23 n OP_Column */.#
1bbb0 64 65 66 69 6e 65 20 4f 50 46 4c 41 47 5f 4c 45 define OPFLAG_LE
1bbc0 4e 47 54 48 41 52 47 20 20 20 20 20 30 78 34 30 NGTHARG 0x40
1bbd0 20 20 20 20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e /* OP_Column
1bbe0 20 6f 6e 6c 79 20 75 73 65 64 20 66 6f 72 20 6c only used for l
1bbf0 65 6e 67 74 68 28 29 20 2a 2f 0a 23 64 65 66 69 ength() */.#defi
1bc00 6e 65 20 4f 50 46 4c 41 47 5f 54 59 50 45 4f 46 ne OPFLAG_TYPEOF
1bc10 41 52 47 20 20 20 20 20 30 78 38 30 20 20 20 20 ARG 0x80
1bc20 2f 2a 20 4f 50 5f 43 6f 6c 75 6d 6e 20 6f 6e 6c /* OP_Column onl
1bc30 79 20 75 73 65 64 20 66 6f 72 20 74 79 70 65 6f y used for typeo
1bc40 66 28 29 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f f() */.#define O
1bc50 50 46 4c 41 47 5f 42 55 4c 4b 43 53 52 20 20 20 PFLAG_BULKCSR
1bc60 20 20 20 20 30 78 30 31 20 20 20 20 2f 2a 20 4f 0x01 /* O
1bc70 50 5f 4f 70 65 6e 2a 2a 20 75 73 65 64 20 74 6f P_Open** used to
1bc80 20 6f 70 65 6e 20 62 75 6c 6b 20 63 75 72 73 6f open bulk curso
1bc90 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 r */.#define OPF
1bca0 4c 41 47 5f 50 32 49 53 52 45 47 20 20 20 20 20 LAG_P2ISREG
1bcb0 20 20 30 78 30 32 20 20 20 20 2f 2a 20 50 32 20 0x02 /* P2
1bcc0 74 6f 20 4f 50 5f 4f 70 65 6e 2a 2a 20 69 73 20 to OP_Open** is
1bcd0 61 20 72 65 67 69 73 74 65 72 20 6e 75 6d 62 65 a register numbe
1bce0 72 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4f 50 46 r */.#define OPF
1bcf0 4c 41 47 5f 50 45 52 4d 55 54 45 20 20 20 20 20 LAG_PERMUTE
1bd00 20 20 30 78 30 31 20 20 20 20 2f 2a 20 4f 50 5f 0x01 /* OP_
1bd10 43 6f 6d 70 61 72 65 3a 20 75 73 65 20 74 68 65 Compare: use the
1bd20 20 70 65 72 6d 75 74 61 74 69 6f 6e 20 2a 2f 0a permutation */.
1bd30 0a 2f 2a 0a 20 2a 20 45 61 63 68 20 74 72 69 67 ./*. * Each trig
1bd40 67 65 72 20 70 72 65 73 65 6e 74 20 69 6e 20 74 ger present in t
1bd50 68 65 20 64 61 74 61 62 61 73 65 20 73 63 68 65 he database sche
1bd60 6d 61 20 69 73 20 73 74 6f 72 65 64 20 61 73 20 ma is stored as
1bd70 61 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 0a 20 an instance of.
1bd80 2a 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 * struct Trigger
1bd90 2e 20 0a 20 2a 0a 20 2a 20 50 6f 69 6e 74 65 72 . . *. * Pointer
1bda0 73 20 74 6f 20 69 6e 73 74 61 6e 63 65 73 20 6f s to instances o
1bdb0 66 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 f struct Trigger
1bdc0 20 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 74 are stored in t
1bdd0 77 6f 20 77 61 79 73 2e 0a 20 2a 20 31 2e 20 49 wo ways.. * 1. I
1bde0 6e 20 74 68 65 20 22 74 72 69 67 48 61 73 68 22 n the "trigHash"
1bdf0 20 68 61 73 68 20 74 61 62 6c 65 20 28 70 61 72 hash table (par
1be00 74 20 6f 66 20 74 68 65 20 73 71 6c 69 74 65 33 t of the sqlite3
1be10 2a 20 74 68 61 74 20 72 65 70 72 65 73 65 6e 74 * that represent
1be20 73 20 74 68 65 20 0a 20 2a 20 20 20 20 64 61 74 s the . * dat
1be30 61 62 61 73 65 29 2e 20 54 68 69 73 20 61 6c 6c abase). This all
1be40 6f 77 73 20 54 72 69 67 67 65 72 20 73 74 72 75 ows Trigger stru
1be50 63 74 75 72 65 73 20 74 6f 20 62 65 20 72 65 74 ctures to be ret
1be60 72 69 65 76 65 64 20 62 79 20 6e 61 6d 65 2e 0a rieved by name..
1be70 20 2a 20 32 2e 20 41 6c 6c 20 74 72 69 67 67 65 * 2. All trigge
1be80 72 73 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 rs associated wi
1be90 74 68 20 61 20 73 69 6e 67 6c 65 20 74 61 62 6c th a single tabl
1bea0 65 20 66 6f 72 6d 20 61 20 6c 69 6e 6b 65 64 20 e form a linked
1beb0 6c 69 73 74 2c 20 75 73 69 6e 67 20 74 68 65 0a list, using the.
1bec0 20 2a 20 20 20 20 70 4e 65 78 74 20 6d 65 6d 62 * pNext memb
1bed0 65 72 20 6f 66 20 73 74 72 75 63 74 20 54 72 69 er of struct Tri
1bee0 67 67 65 72 2e 20 41 20 70 6f 69 6e 74 65 72 20 gger. A pointer
1bef0 74 6f 20 74 68 65 20 66 69 72 73 74 20 65 6c 65 to the first ele
1bf00 6d 65 6e 74 20 6f 66 20 74 68 65 0a 20 2a 20 20 ment of the. *
1bf10 20 20 6c 69 6e 6b 65 64 20 6c 69 73 74 20 69 73 linked list is
1bf20 20 73 74 6f 72 65 64 20 61 73 20 74 68 65 20 22 stored as the "
1bf30 70 54 72 69 67 67 65 72 22 20 6d 65 6d 62 65 72 pTrigger" member
1bf40 20 6f 66 20 74 68 65 20 61 73 73 6f 63 69 61 74 of the associat
1bf50 65 64 0a 20 2a 20 20 20 20 73 74 72 75 63 74 20 ed. * struct
1bf60 54 61 62 6c 65 2e 0a 20 2a 0a 20 2a 20 54 68 65 Table.. *. * The
1bf70 20 22 73 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d "step_list" mem
1bf80 62 65 72 20 70 6f 69 6e 74 73 20 74 6f 20 74 68 ber points to th
1bf90 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e 74 20 e first element
1bfa0 6f 66 20 61 20 6c 69 6e 6b 65 64 20 6c 69 73 74 of a linked list
1bfb0 0a 20 2a 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 . * containing t
1bfc0 68 65 20 53 51 4c 20 73 74 61 74 65 6d 65 6e 74 he SQL statement
1bfd0 73 20 73 70 65 63 69 66 69 65 64 20 61 73 20 74 s specified as t
1bfe0 68 65 20 74 72 69 67 67 65 72 20 70 72 6f 67 72 he trigger progr
1bff0 61 6d 2e 0a 20 2a 2f 0a 73 74 72 75 63 74 20 54 am.. */.struct T
1c000 72 69 67 67 65 72 20 7b 0a 20 20 63 68 61 72 20 rigger {. char
1c010 2a 7a 4e 61 6d 65 3b 20 20 20 20 20 20 20 20 20 *zName;
1c020 20 20 20 2f 2a 20 54 68 65 20 6e 61 6d 65 20 6f /* The name o
1c030 66 20 74 68 65 20 74 72 69 67 67 65 72 20 20 20 f the trigger
1c040 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c050 20 20 20 20 20 2a 2f 0a 20 20 63 68 61 72 20 2a */. char *
1c060 74 61 62 6c 65 3b 20 20 20 20 20 20 20 20 20 20 table;
1c070 20 20 2f 2a 20 54 68 65 20 74 61 62 6c 65 20 6f /* The table o
1c080 72 20 76 69 65 77 20 74 6f 20 77 68 69 63 68 20 r view to which
1c090 74 68 65 20 74 72 69 67 67 65 72 20 61 70 70 6c the trigger appl
1c0a0 69 65 73 20 2a 2f 0a 20 20 75 38 20 6f 70 3b 20 ies */. u8 op;
1c0b0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c0c0 20 2f 2a 20 4f 6e 65 20 6f 66 20 54 4b 5f 44 45 /* One of TK_DE
1c0d0 4c 45 54 45 2c 20 54 4b 5f 55 50 44 41 54 45 2c LETE, TK_UPDATE,
1c0e0 20 54 4b 5f 49 4e 53 45 52 54 20 20 20 20 20 20 TK_INSERT
1c0f0 20 20 20 2a 2f 0a 20 20 75 38 20 74 72 5f 74 6d */. u8 tr_tm
1c100 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1c110 2f 2a 20 4f 6e 65 20 6f 66 20 54 52 49 47 47 45 /* One of TRIGGE
1c120 52 5f 42 45 46 4f 52 45 2c 20 54 52 49 47 47 45 R_BEFORE, TRIGGE
1c130 52 5f 41 46 54 45 52 20 2a 2f 0a 20 20 45 78 70 R_AFTER */. Exp
1c140 72 20 2a 70 57 68 65 6e 3b 20 20 20 20 20 20 20 r *pWhen;
1c150 20 20 20 20 20 2f 2a 20 54 68 65 20 57 48 45 4e /* The WHEN
1c160 20 63 6c 61 75 73 65 20 6f 66 20 74 68 65 20 65 clause of the e
1c170 78 70 72 65 73 73 69 6f 6e 20 28 6d 61 79 20 62 xpression (may b
1c180 65 20 4e 55 4c 4c 29 20 2a 2f 0a 20 20 49 64 4c e NULL) */. IdL
1c190 69 73 74 20 2a 70 43 6f 6c 75 6d 6e 73 3b 20 20 ist *pColumns;
1c1a0 20 20 20 20 20 2f 2a 20 49 66 20 74 68 69 73 20 /* If this
1c1b0 69 73 20 61 6e 20 55 50 44 41 54 45 20 4f 46 20 is an UPDATE OF
1c1c0 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 74 72 <column-list> tr
1c1d0 69 67 67 65 72 2c 0a 20 20 20 20 20 20 20 20 20 igger,.
1c1e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1c1f0 20 20 20 20 74 68 65 20 3c 63 6f 6c 75 6d 6e 2d the <column-
1c200 6c 69 73 74 3e 20 69 73 20 73 74 6f 72 65 64 20 list> is stored
1c210 68 65 72 65 20 2a 2f 0a 20 20 53 63 68 65 6d 61 here */. Schema
1c220 20 2a 70 53 63 68 65 6d 61 3b 20 20 20 20 20 20 *pSchema;
1c230 20 20 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 /* Schema cont
1c240 61 69 6e 69 6e 67 20 74 68 65 20 74 72 69 67 67 aining the trigg
1c250 65 72 20 2a 2f 0a 20 20 53 63 68 65 6d 61 20 2a er */. Schema *
1c260 70 54 61 62 53 63 68 65 6d 61 3b 20 20 20 20 20 pTabSchema;
1c270 2f 2a 20 53 63 68 65 6d 61 20 63 6f 6e 74 61 69 /* Schema contai
1c280 6e 69 6e 67 20 74 68 65 20 74 61 62 6c 65 20 2a ning the table *
1c290 2f 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 /. TriggerStep
1c2a0 2a 73 74 65 70 5f 6c 69 73 74 3b 20 2f 2a 20 4c *step_list; /* L
1c2b0 69 6e 6b 20 6c 69 73 74 20 6f 66 20 74 72 69 67 ink list of trig
1c2c0 67 65 72 20 70 72 6f 67 72 61 6d 20 73 74 65 70 ger program step
1c2d0 73 20 20 20 20 20 20 20 20 20 20 20 20 20 2a 2f s */
1c2e0 0a 20 20 54 72 69 67 67 65 72 20 2a 70 4e 65 78 . Trigger *pNex
1c2f0 74 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 65 t; /* Ne
1c300 78 74 20 74 72 69 67 67 65 72 20 61 73 73 6f 63 xt trigger assoc
1c310 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 74 iated with the t
1c320 61 62 6c 65 20 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 2a able */.};../*.*
1c330 2a 20 41 20 74 72 69 67 67 65 72 20 69 73 20 65 * A trigger is e
1c340 69 74 68 65 72 20 61 20 42 45 46 4f 52 45 20 6f ither a BEFORE o
1c350 72 20 61 6e 20 41 46 54 45 52 20 74 72 69 67 67 r an AFTER trigg
1c360 65 72 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 er. The followi
1c370 6e 67 20 63 6f 6e 73 74 61 6e 74 73 0a 2a 2a 20 ng constants.**
1c380 64 65 74 65 72 6d 69 6e 65 20 77 68 69 63 68 2e determine which.
1c390 20 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 72 65 .**.** If there
1c3a0 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 20 74 72 are multiple tr
1c3b0 69 67 67 65 72 73 2c 20 79 6f 75 20 6d 69 67 68 iggers, you migh
1c3c0 74 20 6f 66 20 73 6f 6d 65 20 42 45 46 4f 52 45 t of some BEFORE
1c3d0 20 61 6e 64 20 73 6f 6d 65 20 41 46 54 45 52 2e and some AFTER.
1c3e0 0a 2a 2a 20 49 6e 20 74 68 61 74 20 63 61 73 65 .** In that case
1c3f0 73 2c 20 74 68 65 20 63 6f 6e 73 74 61 6e 74 73 s, the constants
1c400 20 62 65 6c 6f 77 20 63 61 6e 20 62 65 20 4f 52 below can be OR
1c410 65 64 20 74 6f 67 65 74 68 65 72 2e 0a 2a 2f 0a ed together..*/.
1c420 23 64 65 66 69 6e 65 20 54 52 49 47 47 45 52 5f #define TRIGGER_
1c430 42 45 46 4f 52 45 20 20 31 0a 23 64 65 66 69 6e BEFORE 1.#defin
1c440 65 20 54 52 49 47 47 45 52 5f 41 46 54 45 52 20 e TRIGGER_AFTER
1c450 20 20 32 0a 0a 2f 2a 0a 20 2a 20 41 6e 20 69 6e 2../*. * An in
1c460 73 74 61 6e 63 65 20 6f 66 20 73 74 72 75 63 74 stance of struct
1c470 20 54 72 69 67 67 65 72 53 74 65 70 20 69 73 20 TriggerStep is
1c480 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 61 20 used to store a
1c490 73 69 6e 67 6c 65 20 53 51 4c 20 73 74 61 74 65 single SQL state
1c4a0 6d 65 6e 74 0a 20 2a 20 74 68 61 74 20 69 73 20 ment. * that is
1c4b0 61 20 70 61 72 74 20 6f 66 20 61 20 74 72 69 67 a part of a trig
1c4c0 67 65 72 2d 70 72 6f 67 72 61 6d 2e 20 0a 20 2a ger-program. . *
1c4d0 0a 20 2a 20 49 6e 73 74 61 6e 63 65 73 20 6f 66 . * Instances of
1c4e0 20 73 74 72 75 63 74 20 54 72 69 67 67 65 72 53 struct TriggerS
1c4f0 74 65 70 20 61 72 65 20 73 74 6f 72 65 64 20 69 tep are stored i
1c500 6e 20 61 20 73 69 6e 67 6c 79 20 6c 69 6e 6b 65 n a singly linke
1c510 64 20 6c 69 73 74 20 28 6c 69 6e 6b 65 64 0a 20 d list (linked.
1c520 2a 20 75 73 69 6e 67 20 74 68 65 20 22 70 4e 65 * using the "pNe
1c530 78 74 22 20 6d 65 6d 62 65 72 29 20 72 65 66 65 xt" member) refe
1c540 72 65 6e 63 65 64 20 62 79 20 74 68 65 20 22 73 renced by the "s
1c550 74 65 70 5f 6c 69 73 74 22 20 6d 65 6d 62 65 72 tep_list" member
1c560 20 6f 66 20 74 68 65 20 0a 20 2a 20 61 73 73 6f of the . * asso
1c570 63 69 61 74 65 64 20 73 74 72 75 63 74 20 54 72 ciated struct Tr
1c580 69 67 67 65 72 20 69 6e 73 74 61 6e 63 65 2e 20 igger instance.
1c590 54 68 65 20 66 69 72 73 74 20 65 6c 65 6d 65 6e The first elemen
1c5a0 74 20 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 t of the linked
1c5b0 6c 69 73 74 20 69 73 0a 20 2a 20 74 68 65 20 66 list is. * the f
1c5c0 69 72 73 74 20 73 74 65 70 20 6f 66 20 74 68 65 irst step of the
1c5d0 20 74 72 69 67 67 65 72 2d 70 72 6f 67 72 61 6d trigger-program
1c5e0 2e 0a 20 2a 20 0a 20 2a 20 54 68 65 20 22 6f 70 .. * . * The "op
1c5f0 22 20 6d 65 6d 62 65 72 20 69 6e 64 69 63 61 74 " member indicat
1c600 65 73 20 77 68 65 74 68 65 72 20 74 68 69 73 20 es whether this
1c610 69 73 20 61 20 22 44 45 4c 45 54 45 22 2c 20 22 is a "DELETE", "
1c620 49 4e 53 45 52 54 22 2c 20 22 55 50 44 41 54 45 INSERT", "UPDATE
1c630 22 20 6f 72 0a 20 2a 20 22 53 45 4c 45 43 54 22 " or. * "SELECT"
1c640 20 73 74 61 74 65 6d 65 6e 74 2e 20 54 68 65 20 statement. The
1c650 6d 65 61 6e 69 6e 67 73 20 6f 66 20 74 68 65 20 meanings of the
1c660 6f 74 68 65 72 20 6d 65 6d 62 65 72 73 20 69 73 other members is
1c670 20 64 65 74 65 72 6d 69 6e 65 64 20 62 79 20 74 determined by t
1c680 68 65 20 0a 20 2a 20 76 61 6c 75 65 20 6f 66 20 he . * value of
1c690 22 6f 70 22 20 61 73 20 66 6f 6c 6c 6f 77 73 3a "op" as follows:
1c6a0 0a 20 2a 0a 20 2a 20 28 6f 70 20 3d 3d 20 54 4b . *. * (op == TK
1c6b0 5f 49 4e 53 45 52 54 29 0a 20 2a 20 6f 72 63 6f _INSERT). * orco
1c6c0 6e 66 20 20 20 20 2d 3e 20 73 74 6f 72 65 73 20 nf -> stores
1c6d0 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 the ON CONFLICT
1c6e0 61 6c 67 6f 72 69 74 68 6d 0a 20 2a 20 70 53 65 algorithm. * pSe
1c6f0 6c 65 63 74 20 20 20 2d 3e 20 49 66 20 74 68 69 lect -> If thi
1c700 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 49 s is an INSERT I
1c710 4e 54 4f 20 2e 2e 2e 20 53 45 4c 45 43 54 20 2e NTO ... SELECT .
1c720 2e 2e 20 73 74 61 74 65 6d 65 6e 74 2c 20 74 68 .. statement, th
1c730 65 6e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 en. *
1c740 20 20 20 74 68 69 73 20 73 74 6f 72 65 73 20 61 this stores a
1c750 20 70 6f 69 6e 74 65 72 20 74 6f 20 74 68 65 20 pointer to the
1c760 53 45 4c 45 43 54 20 73 74 61 74 65 6d 65 6e 74 SELECT statement
1c770 2e 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c . Otherwise NULL
1c780 2e 0a 20 2a 20 74 61 72 67 65 74 20 20 20 20 2d .. * target -
1c790 3e 20 41 20 74 6f 6b 65 6e 20 68 6f 6c 64 69 6e > A token holdin
1c7a0 67 20 74 68 65 20 71 75 6f 74 65 64 20 6e 61 6d g the quoted nam
1c7b0 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 74 e of the table t
1c7c0 6f 20 69 6e 73 65 72 74 20 69 6e 74 6f 2e 0a 20 o insert into..
1c7d0 2a 20 70 45 78 70 72 4c 69 73 74 20 2d 3e 20 49 * pExprList -> I
1c7e0 66 20 74 68 69 73 20 69 73 20 61 6e 20 49 4e 53 f this is an INS
1c7f0 45 52 54 20 49 4e 54 4f 20 2e 2e 2e 20 56 41 4c ERT INTO ... VAL
1c800 55 45 53 20 2e 2e 2e 20 73 74 61 74 65 6d 65 6e UES ... statemen
1c810 74 2c 20 74 68 65 6e 0a 20 2a 20 20 20 20 20 20 t, then. *
1c820 20 20 20 20 20 20 20 20 74 68 69 73 20 73 74 6f this sto
1c830 72 65 73 20 76 61 6c 75 65 73 20 74 6f 20 62 65 res values to be
1c840 20 69 6e 73 65 72 74 65 64 2e 20 4f 74 68 65 72 inserted. Other
1c850 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a 20 70 49 wise NULL.. * pI
1c860 64 4c 69 73 74 20 20 20 2d 3e 20 49 66 20 74 68 dList -> If th
1c870 69 73 20 69 73 20 61 6e 20 49 4e 53 45 52 54 20 is is an INSERT
1c880 49 4e 54 4f 20 2e 2e 2e 20 28 3c 63 6f 6c 75 6d INTO ... (<colum
1c890 6e 2d 6e 61 6d 65 73 3e 29 20 56 41 4c 55 45 53 n-names>) VALUES
1c8a0 20 2e 2e 2e 20 0a 20 2a 20 20 20 20 20 20 20 20 ... . *
1c8b0 20 20 20 20 20 20 73 74 61 74 65 6d 65 6e 74 2c statement,
1c8c0 20 74 68 65 6e 20 74 68 69 73 20 73 74 6f 72 65 then this store
1c8d0 73 20 74 68 65 20 63 6f 6c 75 6d 6e 2d 6e 61 6d s the column-nam
1c8e0 65 73 20 74 6f 20 62 65 0a 20 2a 20 20 20 20 20 es to be. *
1c8f0 20 20 20 20 20 20 20 20 20 69 6e 73 65 72 74 65 inserte
1c900 64 20 69 6e 74 6f 2e 0a 20 2a 0a 20 2a 20 28 6f d into.. *. * (o
1c910 70 20 3d 3d 20 54 4b 5f 44 45 4c 45 54 45 29 0a p == TK_DELETE).
1c920 20 2a 20 74 61 72 67 65 74 20 20 20 20 2d 3e 20 * target ->
1c930 41 20 74 6f 6b 65 6e 20 68 6f 6c 64 69 6e 67 20 A token holding
1c940 74 68 65 20 71 75 6f 74 65 64 20 6e 61 6d 65 20 the quoted name
1c950 6f 66 20 74 68 65 20 74 61 62 6c 65 20 74 6f 20 of the table to
1c960 64 65 6c 65 74 65 20 66 72 6f 6d 2e 0a 20 2a 20 delete from.. *
1c970 70 57 68 65 72 65 20 20 20 20 2d 3e 20 54 68 65 pWhere -> The
1c980 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 6f 66 WHERE clause of
1c990 20 74 68 65 20 44 45 4c 45 54 45 20 73 74 61 74 the DELETE stat
1c9a0 65 6d 65 6e 74 20 69 66 20 6f 6e 65 20 69 73 20 ement if one is
1c9b0 73 70 65 63 69 66 69 65 64 2e 0a 20 2a 20 20 20 specified.. *
1c9c0 20 20 20 20 20 20 20 20 20 20 20 4f 74 68 65 72 Other
1c9d0 77 69 73 65 20 4e 55 4c 4c 2e 0a 20 2a 20 0a 20 wise NULL.. * .
1c9e0 2a 20 28 6f 70 20 3d 3d 20 54 4b 5f 55 50 44 41 * (op == TK_UPDA
1c9f0 54 45 29 0a 20 2a 20 74 61 72 67 65 74 20 20 20 TE). * target
1ca00 20 2d 3e 20 41 20 74 6f 6b 65 6e 20 68 6f 6c 64 -> A token hold
1ca10 69 6e 67 20 74 68 65 20 71 75 6f 74 65 64 20 6e ing the quoted n
1ca20 61 6d 65 20 6f 66 20 74 68 65 20 74 61 62 6c 65 ame of the table
1ca30 20 74 6f 20 75 70 64 61 74 65 20 72 6f 77 73 20 to update rows
1ca40 6f 66 2e 0a 20 2a 20 70 57 68 65 72 65 20 20 20 of.. * pWhere
1ca50 20 2d 3e 20 54 68 65 20 57 48 45 52 45 20 63 6c -> The WHERE cl
1ca60 61 75 73 65 20 6f 66 20 74 68 65 20 55 50 44 41 ause of the UPDA
1ca70 54 45 20 73 74 61 74 65 6d 65 6e 74 20 69 66 20 TE statement if
1ca80 6f 6e 65 20 69 73 20 73 70 65 63 69 66 69 65 64 one is specified
1ca90 2e 0a 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 .. *
1caa0 20 20 4f 74 68 65 72 77 69 73 65 20 4e 55 4c 4c Otherwise NULL
1cab0 2e 0a 20 2a 20 70 45 78 70 72 4c 69 73 74 20 2d .. * pExprList -
1cac0 3e 20 41 20 6c 69 73 74 20 6f 66 20 74 68 65 20 > A list of the
1cad0 63 6f 6c 75 6d 6e 73 20 74 6f 20 75 70 64 61 74 columns to updat
1cae0 65 20 61 6e 64 20 74 68 65 20 65 78 70 72 65 73 e and the expres
1caf0 73 69 6f 6e 73 20 74 6f 20 75 70 64 61 74 65 0a sions to update.
1cb00 20 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 *
1cb10 74 68 65 6d 20 74 6f 2e 20 53 65 65 20 73 71 6c them to. See sql
1cb20 69 74 65 33 55 70 64 61 74 65 28 29 20 64 6f 63 ite3Update() doc
1cb30 75 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 22 70 umentation of "p
1cb40 43 68 61 6e 67 65 73 22 0a 20 2a 20 20 20 20 20 Changes". *
1cb50 20 20 20 20 20 20 20 20 20 61 72 67 75 6d 65 6e argumen
1cb60 74 2e 0a 20 2a 20 0a 20 2a 2f 0a 73 74 72 75 63 t.. * . */.struc
1cb70 74 20 54 72 69 67 67 65 72 53 74 65 70 20 7b 0a t TriggerStep {.
1cb80 20 20 75 38 20 6f 70 3b 20 20 20 20 20 20 20 20 u8 op;
1cb90 20 20 20 20 20 20 20 2f 2a 20 4f 6e 65 20 6f 66 /* One of
1cba0 20 54 4b 5f 44 45 4c 45 54 45 2c 20 54 4b 5f 55 TK_DELETE, TK_U
1cbb0 50 44 41 54 45 2c 20 54 4b 5f 49 4e 53 45 52 54 PDATE, TK_INSERT
1cbc0 2c 20 54 4b 5f 53 45 4c 45 43 54 20 2a 2f 0a 20 , TK_SELECT */.
1cbd0 20 75 38 20 6f 72 63 6f 6e 66 3b 20 20 20 20 20 u8 orconf;
1cbe0 20 20 20 20 20 20 2f 2a 20 4f 45 5f 52 6f 6c 6c /* OE_Roll
1cbf0 62 61 63 6b 20 65 74 63 2e 20 2a 2f 0a 20 20 54 back etc. */. T
1cc00 72 69 67 67 65 72 20 2a 70 54 72 69 67 3b 20 20 rigger *pTrig;
1cc10 20 20 20 20 2f 2a 20 54 68 65 20 74 72 69 67 67 /* The trigg
1cc20 65 72 20 74 68 61 74 20 74 68 69 73 20 73 74 65 er that this ste
1cc30 70 20 69 73 20 61 20 70 61 72 74 20 6f 66 20 2a p is a part of *
1cc40 2f 0a 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c /. Select *pSel
1cc50 65 63 74 3b 20 20 20 20 20 2f 2a 20 53 45 4c 45 ect; /* SELE
1cc60 43 54 20 73 74 61 74 6d 65 6e 74 20 6f 72 20 52 CT statment or R
1cc70 48 53 20 6f 66 20 49 4e 53 45 52 54 20 49 4e 54 HS of INSERT INT
1cc80 4f 20 2e 2e 20 53 45 4c 45 43 54 20 2e 2e 2e 20 O .. SELECT ...
1cc90 2a 2f 0a 20 20 54 6f 6b 65 6e 20 74 61 72 67 65 */. Token targe
1cca0 74 3b 20 20 20 20 20 20 20 20 2f 2a 20 54 61 72 t; /* Tar
1ccb0 67 65 74 20 74 61 62 6c 65 20 66 6f 72 20 44 45 get table for DE
1ccc0 4c 45 54 45 2c 20 55 50 44 41 54 45 2c 20 49 4e LETE, UPDATE, IN
1ccd0 53 45 52 54 20 2a 2f 0a 20 20 45 78 70 72 20 2a SERT */. Expr *
1cce0 70 57 68 65 72 65 3b 20 20 20 20 20 20 20 20 2f pWhere; /
1ccf0 2a 20 54 68 65 20 57 48 45 52 45 20 63 6c 61 75 * The WHERE clau
1cd00 73 65 20 66 6f 72 20 44 45 4c 45 54 45 20 6f 72 se for DELETE or
1cd10 20 55 50 44 41 54 45 20 73 74 65 70 73 20 2a 2f UPDATE steps */
1cd20 0a 20 20 45 78 70 72 4c 69 73 74 20 2a 70 45 78 . ExprList *pEx
1cd30 70 72 4c 69 73 74 3b 20 2f 2a 20 53 45 54 20 63 prList; /* SET c
1cd40 6c 61 75 73 65 20 66 6f 72 20 55 50 44 41 54 45 lause for UPDATE
1cd50 2e 20 2a 2f 0a 20 20 49 64 4c 69 73 74 20 2a 70 . */. IdList *p
1cd60 49 64 4c 69 73 74 3b 20 20 20 20 20 2f 2a 20 43 IdList; /* C
1cd70 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 66 6f 72 20 olumn names for
1cd80 49 4e 53 45 52 54 20 2a 2f 0a 20 20 54 72 69 67 INSERT */. Trig
1cd90 67 65 72 53 74 65 70 20 2a 70 4e 65 78 74 3b 20 gerStep *pNext;
1cda0 20 2f 2a 20 4e 65 78 74 20 69 6e 20 74 68 65 20 /* Next in the
1cdb0 6c 69 6e 6b 2d 6c 69 73 74 20 2a 2f 0a 20 20 54 link-list */. T
1cdc0 72 69 67 67 65 72 53 74 65 70 20 2a 70 4c 61 73 riggerStep *pLas
1cdd0 74 3b 20 20 2f 2a 20 4c 61 73 74 20 65 6c 65 6d t; /* Last elem
1cde0 65 6e 74 20 69 6e 20 6c 69 6e 6b 2d 6c 69 73 74 ent in link-list
1cdf0 2e 20 56 61 6c 69 64 20 66 6f 72 20 31 73 74 20 . Valid for 1st
1ce00 65 6c 65 6d 20 6f 6e 6c 79 20 2a 2f 0a 7d 3b 0a elem only */.};.
1ce10 0a 2f 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f ./*.** The follo
1ce20 77 69 6e 67 20 73 74 72 75 63 74 75 72 65 20 63 wing structure c
1ce30 6f 6e 74 61 69 6e 73 20 69 6e 66 6f 72 6d 61 74 ontains informat
1ce40 69 6f 6e 20 75 73 65 64 20 62 79 20 74 68 65 20 ion used by the
1ce50 73 71 6c 69 74 65 46 69 78 2e 2e 2e 0a 2a 2a 20 sqliteFix....**
1ce60 72 6f 75 74 69 6e 65 73 20 61 73 20 74 68 65 79 routines as they
1ce70 20 77 61 6c 6b 20 74 68 65 20 70 61 72 73 65 20 walk the parse
1ce80 74 72 65 65 20 74 6f 20 6d 61 6b 65 20 64 61 74 tree to make dat
1ce90 61 62 61 73 65 20 72 65 66 65 72 65 6e 63 65 73 abase references
1cea0 0a 2a 2a 20 65 78 70 6c 69 63 69 74 2e 20 20 0a .** explicit. .
1ceb0 2a 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 */.typedef struc
1cec0 74 20 44 62 46 69 78 65 72 20 44 62 46 69 78 65 t DbFixer DbFixe
1ced0 72 3b 0a 73 74 72 75 63 74 20 44 62 46 69 78 65 r;.struct DbFixe
1cee0 72 20 7b 0a 20 20 50 61 72 73 65 20 2a 70 50 61 r {. Parse *pPa
1cef0 72 73 65 3b 20 20 20 20 20 20 2f 2a 20 54 68 65 rse; /* The
1cf00 20 70 61 72 73 69 6e 67 20 63 6f 6e 74 65 78 74 parsing context
1cf10 2e 20 20 45 72 72 6f 72 20 6d 65 73 73 61 67 65 . Error message
1cf20 73 20 77 72 69 74 74 65 6e 20 68 65 72 65 20 2a s written here *
1cf30 2f 0a 20 20 53 63 68 65 6d 61 20 2a 70 53 63 68 /. Schema *pSch
1cf40 65 6d 61 3b 20 20 20 20 2f 2a 20 46 69 78 20 69 ema; /* Fix i
1cf50 74 65 6d 73 20 74 6f 20 74 68 69 73 20 73 63 68 tems to this sch
1cf60 65 6d 61 20 2a 2f 0a 20 20 69 6e 74 20 62 56 61 ema */. int bVa
1cf70 72 4f 6e 6c 79 3b 20 20 20 20 20 20 20 2f 2a 20 rOnly; /*
1cf80 43 68 65 63 6b 20 66 6f 72 20 76 61 72 69 61 62 Check for variab
1cf90 6c 65 20 72 65 66 65 72 65 6e 63 65 73 20 6f 6e le references on
1cfa0 6c 79 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 ly */. const ch
1cfb0 61 72 20 2a 7a 44 62 3b 20 20 20 20 2f 2a 20 4d ar *zDb; /* M
1cfc0 61 6b 65 20 73 75 72 65 20 61 6c 6c 20 6f 62 6a ake sure all obj
1cfd0 65 63 74 73 20 61 72 65 20 63 6f 6e 74 61 69 6e ects are contain
1cfe0 65 64 20 69 6e 20 74 68 69 73 20 64 61 74 61 62 ed in this datab
1cff0 61 73 65 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 ase */. const c
1d000 68 61 72 20 2a 7a 54 79 70 65 3b 20 20 2f 2a 20 har *zType; /*
1d010 54 79 70 65 20 6f 66 20 74 68 65 20 63 6f 6e 74 Type of the cont
1d020 61 69 6e 65 72 20 2d 20 75 73 65 64 20 66 6f 72 ainer - used for
1d030 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 73 20 error messages
1d040 2a 2f 0a 20 20 63 6f 6e 73 74 20 54 6f 6b 65 6e */. const Token
1d050 20 2a 70 4e 61 6d 65 3b 20 2f 2a 20 4e 61 6d 65 *pName; /* Name
1d060 20 6f 66 20 74 68 65 20 63 6f 6e 74 61 69 6e 65 of the containe
1d070 72 20 2d 20 75 73 65 64 20 66 6f 72 20 65 72 72 r - used for err
1d080 6f 72 20 6d 65 73 73 61 67 65 73 20 2a 2f 0a 7d or messages */.}
1d090 3b 0a 0a 2f 2a 0a 2a 2a 20 41 6e 20 6f 62 6a 65 ;../*.** An obje
1d0a0 63 74 65 64 20 75 73 65 64 20 74 6f 20 61 63 63 cted used to acc
1d0b0 75 6d 75 6c 61 74 65 20 74 68 65 20 74 65 78 74 umulate the text
1d0c0 20 6f 66 20 61 20 73 74 72 69 6e 67 20 77 68 65 of a string whe
1d0d0 72 65 20 77 65 0a 2a 2a 20 64 6f 20 6e 6f 74 20 re we.** do not
1d0e0 6e 65 63 65 73 73 61 72 69 6c 79 20 6b 6e 6f 77 necessarily know
1d0f0 20 68 6f 77 20 62 69 67 20 74 68 65 20 73 74 72 how big the str
1d100 69 6e 67 20 77 69 6c 6c 20 62 65 20 69 6e 20 74 ing will be in t
1d110 68 65 20 65 6e 64 2e 0a 2a 2f 0a 73 74 72 75 63 he end..*/.struc
1d120 74 20 53 74 72 41 63 63 75 6d 20 7b 0a 20 20 73 t StrAccum {. s
1d130 71 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 qlite3 *db;
1d140 20 20 20 20 2f 2a 20 4f 70 74 69 6f 6e 61 6c 20 /* Optional
1d150 64 61 74 61 62 61 73 65 20 66 6f 72 20 6c 6f 6f database for loo
1d160 6b 61 73 69 64 65 2e 20 20 43 61 6e 20 62 65 20 kaside. Can be
1d170 4e 55 4c 4c 20 2a 2f 0a 20 20 63 68 61 72 20 2a NULL */. char *
1d180 7a 42 61 73 65 3b 20 20 20 20 20 20 20 20 20 2f zBase; /
1d190 2a 20 41 20 62 61 73 65 20 61 6c 6c 6f 63 61 74 * A base allocat
1d1a0 69 6f 6e 2e 20 20 4e 6f 74 20 66 72 6f 6d 20 6d ion. Not from m
1d1b0 61 6c 6c 6f 63 2e 20 2a 2f 0a 20 20 63 68 61 72 alloc. */. char
1d1c0 20 2a 7a 54 65 78 74 3b 20 20 20 20 20 20 20 20 *zText;
1d1d0 20 2f 2a 20 54 68 65 20 73 74 72 69 6e 67 20 63 /* The string c
1d1e0 6f 6c 6c 65 63 74 65 64 20 73 6f 20 66 61 72 20 ollected so far
1d1f0 2a 2f 0a 20 20 69 6e 74 20 20 6e 43 68 61 72 3b */. int nChar;
1d200 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 65 6e /* Len
1d210 67 74 68 20 6f 66 20 74 68 65 20 73 74 72 69 6e gth of the strin
1d220 67 20 73 6f 20 66 61 72 20 2a 2f 0a 20 20 69 6e g so far */. in
1d230 74 20 20 6e 41 6c 6c 6f 63 3b 20 20 20 20 20 20 t nAlloc;
1d240 20 20 20 2f 2a 20 41 6d 6f 75 6e 74 20 6f 66 20 /* Amount of
1d250 73 70 61 63 65 20 61 6c 6c 6f 63 61 74 65 64 20 space allocated
1d260 69 6e 20 7a 54 65 78 74 20 2a 2f 0a 20 20 69 6e in zText */. in
1d270 74 20 20 6d 78 41 6c 6c 6f 63 3b 20 20 20 20 20 t mxAlloc;
1d280 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 61 6c /* Maximum al
1d290 6c 6f 77 65 64 20 73 74 72 69 6e 67 20 6c 65 6e lowed string len
1d2a0 67 74 68 20 2a 2f 0a 20 20 75 38 20 20 20 75 73 gth */. u8 us
1d2b0 65 4d 61 6c 6c 6f 63 3b 20 20 20 20 20 20 2f 2a eMalloc; /*
1d2c0 20 30 3a 20 6e 6f 6e 65 2c 20 20 31 3a 20 73 71 0: none, 1: sq
1d2d0 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 2c 20 20 lite3DbMalloc,
1d2e0 32 3a 20 73 71 6c 69 74 65 33 5f 6d 61 6c 6c 6f 2: sqlite3_mallo
1d2f0 63 20 2a 2f 0a 20 20 75 38 20 20 20 61 63 63 45 c */. u8 accE
1d300 72 72 6f 72 3b 20 20 20 20 20 20 20 2f 2a 20 53 rror; /* S
1d310 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 4d 20 6f 72 TRACCUM_NOMEM or
1d320 20 53 54 52 41 43 43 55 4d 5f 54 4f 4f 42 49 47 STRACCUM_TOOBIG
1d330 20 2a 2f 0a 7d 3b 0a 23 64 65 66 69 6e 65 20 53 */.};.#define S
1d340 54 52 41 43 43 55 4d 5f 4e 4f 4d 45 4d 20 20 20 TRACCUM_NOMEM
1d350 31 0a 23 64 65 66 69 6e 65 20 53 54 52 41 43 43 1.#define STRACC
1d360 55 4d 5f 54 4f 4f 42 49 47 20 20 32 0a 0a 2f 2a UM_TOOBIG 2../*
1d370 0a 2a 2a 20 41 20 70 6f 69 6e 74 65 72 20 74 6f .** A pointer to
1d380 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 20 this structure
1d390 69 73 20 75 73 65 64 20 74 6f 20 63 6f 6d 6d 75 is used to commu
1d3a0 6e 69 63 61 74 65 20 69 6e 66 6f 72 6d 61 74 69 nicate informati
1d3b0 6f 6e 0a 2a 2a 20 66 72 6f 6d 20 73 71 6c 69 74 on.** from sqlit
1d3c0 65 33 49 6e 69 74 20 61 6e 64 20 4f 50 5f 50 61 e3Init and OP_Pa
1d3d0 72 73 65 53 63 68 65 6d 61 20 69 6e 74 6f 20 74 rseSchema into t
1d3e0 68 65 20 73 71 6c 69 74 65 33 49 6e 69 74 43 61 he sqlite3InitCa
1d3f0 6c 6c 62 61 63 6b 2e 0a 2a 2f 0a 74 79 70 65 64 llback..*/.typed
1d400 65 66 20 73 74 72 75 63 74 20 7b 0a 20 20 73 71 ef struct {. sq
1d410 6c 69 74 65 33 20 2a 64 62 3b 20 20 20 20 20 20 lite3 *db;
1d420 20 20 2f 2a 20 54 68 65 20 64 61 74 61 62 61 73 /* The databas
1d430 65 20 62 65 69 6e 67 20 69 6e 69 74 69 61 6c 69 e being initiali
1d440 7a 65 64 20 2a 2f 0a 20 20 63 68 61 72 20 2a 2a zed */. char **
1d450 70 7a 45 72 72 4d 73 67 3b 20 20 20 20 2f 2a 20 pzErrMsg; /*
1d460 45 72 72 6f 72 20 6d 65 73 73 61 67 65 20 73 74 Error message st
1d470 6f 72 65 64 20 68 65 72 65 20 2a 2f 0a 20 20 69 ored here */. i
1d480 6e 74 20 69 44 62 3b 20 20 20 20 20 20 20 20 20 nt iDb;
1d490 20 20 20 2f 2a 20 30 20 66 6f 72 20 6d 61 69 6e /* 0 for main
1d4a0 20 64 61 74 61 62 61 73 65 2e 20 20 31 20 66 6f database. 1 fo
1d4b0 72 20 54 45 4d 50 2c 20 32 2e 2e 20 66 6f 72 20 r TEMP, 2.. for
1d4c0 41 54 54 41 43 48 65 64 20 2a 2f 0a 20 20 69 6e ATTACHed */. in
1d4d0 74 20 72 63 3b 20 20 20 20 20 20 20 20 20 20 20 t rc;
1d4e0 20 20 2f 2a 20 52 65 73 75 6c 74 20 63 6f 64 65 /* Result code
1d4f0 20 73 74 6f 72 65 64 20 68 65 72 65 20 2a 2f 0a stored here */.
1d500 7d 20 49 6e 69 74 44 61 74 61 3b 0a 0a 2f 2a 0a } InitData;../*.
1d510 2a 2a 20 53 74 72 75 63 74 75 72 65 20 63 6f 6e ** Structure con
1d520 74 61 69 6e 69 6e 67 20 67 6c 6f 62 61 6c 20 63 taining global c
1d530 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 64 61 74 onfiguration dat
1d540 61 20 66 6f 72 20 74 68 65 20 53 51 4c 69 74 65 a for the SQLite
1d550 20 6c 69 62 72 61 72 79 2e 0a 2a 2a 0a 2a 2a 20 library..**.**
1d560 54 68 69 73 20 73 74 72 75 63 74 75 72 65 20 61 This structure a
1d570 6c 73 6f 20 63 6f 6e 74 61 69 6e 73 20 73 6f 6d lso contains som
1d580 65 20 73 74 61 74 65 20 69 6e 66 6f 72 6d 61 74 e state informat
1d590 69 6f 6e 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 53 ion..*/.struct S
1d5a0 71 6c 69 74 65 33 43 6f 6e 66 69 67 20 7b 0a 20 qlite3Config {.
1d5b0 20 69 6e 74 20 62 4d 65 6d 73 74 61 74 3b 20 20 int bMemstat;
1d5c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d5d0 20 20 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e /* True to en
1d5e0 61 62 6c 65 20 6d 65 6d 6f 72 79 20 73 74 61 74 able memory stat
1d5f0 75 73 20 2a 2f 0a 20 20 69 6e 74 20 62 43 6f 72 us */. int bCor
1d600 65 4d 75 74 65 78 3b 20 20 20 20 20 20 20 20 20 eMutex;
1d610 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
1d620 65 20 74 6f 20 65 6e 61 62 6c 65 20 63 6f 72 65 e to enable core
1d630 20 6d 75 74 65 78 69 6e 67 20 2a 2f 0a 20 20 69 mutexing */. i
1d640 6e 74 20 62 46 75 6c 6c 4d 75 74 65 78 3b 20 20 nt bFullMutex;
1d650 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d660 20 2f 2a 20 54 72 75 65 20 74 6f 20 65 6e 61 62 /* True to enab
1d670 6c 65 20 66 75 6c 6c 20 6d 75 74 65 78 69 6e 67 le full mutexing
1d680 20 2a 2f 0a 20 20 69 6e 74 20 62 4f 70 65 6e 55 */. int bOpenU
1d690 72 69 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ri;
1d6a0 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1d6b0 74 6f 20 69 6e 74 65 72 70 72 65 74 20 66 69 6c to interpret fil
1d6c0 65 6e 61 6d 65 73 20 61 73 20 55 52 49 73 20 2a enames as URIs *
1d6d0 2f 0a 20 20 69 6e 74 20 62 55 73 65 43 69 73 3b /. int bUseCis;
1d6e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d6f0 20 20 20 20 20 20 2f 2a 20 55 73 65 20 63 6f 76 /* Use cov
1d700 65 72 69 6e 67 20 69 6e 64 69 63 65 73 20 66 6f ering indices fo
1d710 72 20 66 75 6c 6c 2d 73 63 61 6e 73 20 2a 2f 0a r full-scans */.
1d720 20 20 69 6e 74 20 6d 78 53 74 72 6c 65 6e 3b 20 int mxStrlen;
1d730 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d740 20 20 20 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 73 /* Maximum s
1d750 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 2a 2f 0a tring length */.
1d760 20 20 69 6e 74 20 6e 65 76 65 72 43 6f 72 72 75 int neverCorru
1d770 70 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 pt;
1d780 20 20 20 20 2f 2a 20 44 61 74 61 62 61 73 65 20 /* Database
1d790 69 73 20 61 6c 77 61 79 73 20 77 65 6c 6c 2d 66 is always well-f
1d7a0 6f 72 6d 65 64 20 2a 2f 0a 20 20 69 6e 74 20 73 ormed */. int s
1d7b0 7a 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 20 20 20 zLookaside;
1d7c0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1d7d0 44 65 66 61 75 6c 74 20 6c 6f 6f 6b 61 73 69 64 Default lookasid
1d7e0 65 20 62 75 66 66 65 72 20 73 69 7a 65 20 2a 2f e buffer size */
1d7f0 0a 20 20 69 6e 74 20 6e 4c 6f 6f 6b 61 73 69 64 . int nLookasid
1d800 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
1d810 20 20 20 20 20 2f 2a 20 44 65 66 61 75 6c 74 20 /* Default
1d820 6c 6f 6f 6b 61 73 69 64 65 20 62 75 66 66 65 72 lookaside buffer
1d830 20 63 6f 75 6e 74 20 2a 2f 0a 20 20 73 71 6c 69 count */. sqli
1d840 74 65 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 te3_mem_methods
1d850 6d 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a m; /*
1d860 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 65 6d 6f 72 Low-level memor
1d870 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 6e 74 y allocation int
1d880 65 72 66 61 63 65 20 2a 2f 0a 20 20 73 71 6c 69 erface */. sqli
1d890 74 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 te3_mutex_method
1d8a0 73 20 6d 75 74 65 78 3b 20 20 20 20 20 20 2f 2a s mutex; /*
1d8b0 20 4c 6f 77 2d 6c 65 76 65 6c 20 6d 75 74 65 78 Low-level mutex
1d8c0 20 69 6e 74 65 72 66 61 63 65 20 2a 2f 0a 20 20 interface */.
1d8d0 73 71 6c 69 74 65 33 5f 70 63 61 63 68 65 5f 6d sqlite3_pcache_m
1d8e0 65 74 68 6f 64 73 32 20 70 63 61 63 68 65 32 3b ethods2 pcache2;
1d8f0 20 20 2f 2a 20 4c 6f 77 2d 6c 65 76 65 6c 20 70 /* Low-level p
1d900 61 67 65 2d 63 61 63 68 65 20 69 6e 74 65 72 66 age-cache interf
1d910 61 63 65 20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 ace */. void *p
1d920 48 65 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 Heap;
1d930 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 48 65 /* He
1d940 61 70 20 73 74 6f 72 61 67 65 20 73 70 61 63 65 ap storage space
1d950 20 2a 2f 0a 20 20 69 6e 74 20 6e 48 65 61 70 3b */. int nHeap;
1d960 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1d970 20 20 20 20 20 20 20 20 2f 2a 20 53 69 7a 65 20 /* Size
1d980 6f 66 20 70 48 65 61 70 5b 5d 20 2a 2f 0a 20 20 of pHeap[] */.
1d990 69 6e 74 20 6d 6e 52 65 71 2c 20 6d 78 52 65 71 int mnReq, mxReq
1d9a0 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1d9b0 20 20 2f 2a 20 4d 69 6e 20 61 6e 64 20 6d 61 78 /* Min and max
1d9c0 20 68 65 61 70 20 72 65 71 75 65 73 74 73 20 73 heap requests s
1d9d0 69 7a 65 73 20 2a 2f 0a 20 20 73 71 6c 69 74 65 izes */. sqlite
1d9e0 33 5f 69 6e 74 36 34 20 73 7a 4d 6d 61 70 3b 20 3_int64 szMmap;
1d9f0 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 6d /* m
1da00 6d 61 70 28 29 20 73 70 61 63 65 20 70 65 72 20 map() space per
1da10 6f 70 65 6e 20 66 69 6c 65 20 2a 2f 0a 20 20 73 open file */. s
1da20 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 6d 78 4d qlite3_int64 mxM
1da30 6d 61 70 3b 20 20 20 20 20 20 20 20 20 20 20 20 map;
1da40 20 2f 2a 20 4d 61 78 69 6d 75 6d 20 76 61 6c 75 /* Maximum valu
1da50 65 20 66 6f 72 20 73 7a 4d 6d 61 70 20 2a 2f 0a e for szMmap */.
1da60 20 20 76 6f 69 64 20 2a 70 53 63 72 61 74 63 68 void *pScratch
1da70 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1da80 20 20 20 20 2f 2a 20 53 63 72 61 74 63 68 20 6d /* Scratch m
1da90 65 6d 6f 72 79 20 2a 2f 0a 20 20 69 6e 74 20 73 emory */. int s
1daa0 7a 53 63 72 61 74 63 68 3b 20 20 20 20 20 20 20 zScratch;
1dab0 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 /*
1dac0 53 69 7a 65 20 6f 66 20 65 61 63 68 20 73 63 72 Size of each scr
1dad0 61 74 63 68 20 62 75 66 66 65 72 20 2a 2f 0a 20 atch buffer */.
1dae0 20 69 6e 74 20 6e 53 63 72 61 74 63 68 3b 20 20 int nScratch;
1daf0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1db00 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
1db10 73 63 72 61 74 63 68 20 62 75 66 66 65 72 73 20 scratch buffers
1db20 2a 2f 0a 20 20 76 6f 69 64 20 2a 70 50 61 67 65 */. void *pPage
1db30 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1db40 20 20 20 20 20 20 20 2f 2a 20 50 61 67 65 20 63 /* Page c
1db50 61 63 68 65 20 6d 65 6d 6f 72 79 20 2a 2f 0a 20 ache memory */.
1db60 20 69 6e 74 20 73 7a 50 61 67 65 3b 20 20 20 20 int szPage;
1db70 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1db80 20 20 20 2f 2a 20 53 69 7a 65 20 6f 66 20 65 61 /* Size of ea
1db90 63 68 20 70 61 67 65 20 69 6e 20 70 50 61 67 65 ch page in pPage
1dba0 5b 5d 20 2a 2f 0a 20 20 69 6e 74 20 6e 50 61 67 [] */. int nPag
1dbb0 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e;
1dbc0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d /* Num
1dbd0 62 65 72 20 6f 66 20 70 61 67 65 73 20 69 6e 20 ber of pages in
1dbe0 70 50 61 67 65 5b 5d 20 2a 2f 0a 20 20 69 6e 74 pPage[] */. int
1dbf0 20 6d 78 50 61 72 73 65 72 53 74 61 63 6b 3b 20 mxParserStack;
1dc00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1dc10 2a 20 6d 61 78 69 6d 75 6d 20 64 65 70 74 68 20 * maximum depth
1dc20 6f 66 20 74 68 65 20 70 61 72 73 65 72 20 73 74 of the parser st
1dc30 61 63 6b 20 2a 2f 0a 20 20 69 6e 74 20 73 68 61 ack */. int sha
1dc40 72 65 64 43 61 63 68 65 45 6e 61 62 6c 65 64 3b redCacheEnabled;
1dc50 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 74 72 /* tr
1dc60 75 65 20 69 66 20 73 68 61 72 65 64 2d 63 61 63 ue if shared-cac
1dc70 68 65 20 6d 6f 64 65 20 65 6e 61 62 6c 65 64 20 he mode enabled
1dc80 2a 2f 0a 20 20 2f 2a 20 54 68 65 20 61 62 6f 76 */. /* The abov
1dc90 65 20 6d 69 67 68 74 20 62 65 20 69 6e 69 74 69 e might be initi
1dca0 61 6c 69 7a 65 64 20 74 6f 20 6e 6f 6e 2d 7a 65 alized to non-ze
1dcb0 72 6f 2e 20 20 54 68 65 20 66 6f 6c 6c 6f 77 69 ro. The followi
1dcc0 6e 67 20 6e 65 65 64 20 74 6f 20 61 6c 77 61 79 ng need to alway
1dcd0 73 0a 20 20 2a 2a 20 69 6e 69 74 69 61 6c 6c 79 s. ** initially
1dce0 20 62 65 20 7a 65 72 6f 2c 20 68 6f 77 65 76 65 be zero, howeve
1dcf0 72 2e 20 2a 2f 0a 20 20 69 6e 74 20 69 73 49 6e r. */. int isIn
1dd00 69 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 it;
1dd10 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 /* Tru
1dd20 65 20 61 66 74 65 72 20 69 6e 69 74 69 61 6c 69 e after initiali
1dd30 7a 61 74 69 6f 6e 20 68 61 73 20 66 69 6e 69 73 zation has finis
1dd40 68 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 6e 50 hed */. int inP
1dd50 72 6f 67 72 65 73 73 3b 20 20 20 20 20 20 20 20 rogress;
1dd60 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1dd70 75 65 20 77 68 69 6c 65 20 69 6e 69 74 69 61 6c ue while initial
1dd80 69 7a 61 74 69 6f 6e 20 69 6e 20 70 72 6f 67 72 ization in progr
1dd90 65 73 73 20 2a 2f 0a 20 20 69 6e 74 20 69 73 4d ess */. int isM
1dda0 75 74 65 78 49 6e 69 74 3b 20 20 20 20 20 20 20 utexInit;
1ddb0 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 /* Tr
1ddc0 75 65 20 61 66 74 65 72 20 6d 75 74 65 78 65 73 ue after mutexes
1ddd0 20 61 72 65 20 69 6e 69 74 69 61 6c 69 7a 65 64 are initialized
1dde0 20 2a 2f 0a 20 20 69 6e 74 20 69 73 4d 61 6c 6c */. int isMall
1ddf0 6f 63 49 6e 69 74 3b 20 20 20 20 20 20 20 20 20 ocInit;
1de00 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 /* True
1de10 61 66 74 65 72 20 6d 61 6c 6c 6f 63 20 69 73 20 after malloc is
1de20 69 6e 69 74 69 61 6c 69 7a 65 64 20 2a 2f 0a 20 initialized */.
1de30 20 69 6e 74 20 69 73 50 43 61 63 68 65 49 6e 69 int isPCacheIni
1de40 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 t;
1de50 20 20 20 2f 2a 20 54 72 75 65 20 61 66 74 65 72 /* True after
1de60 20 6d 61 6c 6c 6f 63 20 69 73 20 69 6e 69 74 69 malloc is initi
1de70 61 6c 69 7a 65 64 20 2a 2f 0a 20 20 69 6e 74 20 alized */. int
1de80 6e 52 65 66 49 6e 69 74 4d 75 74 65 78 3b 20 20 nRefInitMutex;
1de90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
1dea0 20 4e 75 6d 62 65 72 20 6f 66 20 75 73 65 72 73 Number of users
1deb0 20 6f 66 20 70 49 6e 69 74 4d 75 74 65 78 20 2a of pInitMutex *
1dec0 2f 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 /. sqlite3_mute
1ded0 78 20 2a 70 49 6e 69 74 4d 75 74 65 78 3b 20 20 x *pInitMutex;
1dee0 20 20 20 20 20 20 2f 2a 20 4d 75 74 65 78 20 75 /* Mutex u
1def0 73 65 64 20 62 79 20 73 71 6c 69 74 65 33 5f 69 sed by sqlite3_i
1df00 6e 69 74 69 61 6c 69 7a 65 28 29 20 2a 2f 0a 20 nitialize() */.
1df10 20 76 6f 69 64 20 28 2a 78 4c 6f 67 29 28 76 6f void (*xLog)(vo
1df20 69 64 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 id*,int,const ch
1df30 61 72 2a 29 3b 20 2f 2a 20 46 75 6e 63 74 69 6f ar*); /* Functio
1df40 6e 20 66 6f 72 20 6c 6f 67 67 69 6e 67 20 2a 2f n for logging */
1df50 0a 20 20 76 6f 69 64 20 2a 70 4c 6f 67 41 72 67 . void *pLogArg
1df60 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1df70 20 20 20 20 20 20 20 20 2f 2a 20 46 69 72 73 74 /* First
1df80 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 78 4c 6f argument to xLo
1df90 67 28 29 20 2a 2f 0a 23 69 66 64 65 66 20 53 51 g() */.#ifdef SQ
1dfa0 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 51 4c 4c LITE_ENABLE_SQLL
1dfb0 4f 47 0a 20 20 76 6f 69 64 28 2a 78 53 71 6c 6c OG. void(*xSqll
1dfc0 6f 67 29 28 76 6f 69 64 2a 2c 73 71 6c 69 74 65 og)(void*,sqlite
1dfd0 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 3*,const char*,
1dfe0 69 6e 74 29 3b 0a 20 20 76 6f 69 64 20 2a 70 53 int);. void *pS
1dff0 71 6c 6c 6f 67 41 72 67 3b 0a 23 65 6e 64 69 66 qllogArg;.#endif
1e000 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f 56 .#ifdef SQLITE_V
1e010 44 42 45 5f 43 4f 56 45 52 41 47 45 0a 20 20 2f DBE_COVERAGE. /
1e020 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 * The following
1e030 63 61 6c 6c 62 61 63 6b 20 28 69 66 20 6e 6f 74 callback (if not
1e040 20 4e 55 4c 4c 29 20 69 73 20 69 6e 76 6f 6b 65 NULL) is invoke
1e050 64 20 6f 6e 20 65 76 65 72 79 20 56 44 42 45 20 d on every VDBE
1e060 62 72 61 6e 63 68 0a 20 20 2a 2a 20 6f 70 65 72 branch. ** oper
1e070 61 74 69 6f 6e 2e 20 20 53 65 74 20 74 68 65 20 ation. Set the
1e080 63 61 6c 6c 62 61 63 6b 20 75 73 69 6e 67 20 53 callback using S
1e090 51 4c 49 54 45 5f 54 45 53 54 43 54 52 4c 5f 56 QLITE_TESTCTRL_V
1e0a0 44 42 45 5f 43 4f 56 45 52 41 47 45 2e 0a 20 20 DBE_COVERAGE..
1e0b0 2a 2f 0a 20 20 76 6f 69 64 20 28 2a 78 56 64 62 */. void (*xVdb
1e0c0 65 42 72 61 6e 63 68 29 28 76 6f 69 64 2a 2c 69 eBranch)(void*,i
1e0d0 6e 74 20 69 53 72 63 4c 69 6e 65 2c 75 38 20 65 nt iSrcLine,u8 e
1e0e0 54 68 69 73 2c 75 38 20 65 4d 78 29 3b 20 20 2f This,u8 eMx); /
1e0f0 2a 20 43 61 6c 6c 62 61 63 6b 20 2a 2f 0a 20 20 * Callback */.
1e100 76 6f 69 64 20 2a 70 56 64 62 65 42 72 61 6e 63 void *pVdbeBranc
1e110 68 41 72 67 3b 20 20 20 20 20 20 20 20 20 20 20 hArg;
1e120 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e130 20 20 20 20 20 20 20 20 20 20 2f 2a 20 31 73 74 /* 1st
1e140 20 61 72 67 75 6d 65 6e 74 20 2a 2f 0a 23 65 6e argument */.#en
1e150 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 dif.#ifndef SQLI
1e160 54 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f TE_OMIT_BUILTIN_
1e170 54 45 53 54 0a 20 20 69 6e 74 20 28 2a 78 54 65 TEST. int (*xTe
1e180 73 74 43 61 6c 6c 62 61 63 6b 29 28 69 6e 74 29 stCallback)(int)
1e190 3b 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 76 6f ; /* Invo
1e1a0 6b 65 64 20 62 79 20 73 71 6c 69 74 65 33 46 61 ked by sqlite3Fa
1e1b0 75 6c 74 53 69 6d 28 29 20 2a 2f 0a 23 65 6e 64 ultSim() */.#end
1e1c0 69 66 0a 20 20 69 6e 74 20 62 4c 6f 63 61 6c 74 if. int bLocalt
1e1d0 69 6d 65 46 61 75 6c 74 3b 20 20 20 20 20 20 20 imeFault;
1e1e0 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20 74 /* True t
1e1f0 6f 20 66 61 69 6c 20 6c 6f 63 61 6c 74 69 6d 65 o fail localtime
1e200 28 29 20 63 61 6c 6c 73 20 2a 2f 0a 7d 3b 0a 0a () calls */.};..
1e210 2f 2a 0a 2a 2a 20 54 68 69 73 20 6d 61 63 72 6f /*.** This macro
1e220 20 69 73 20 75 73 65 64 20 69 6e 73 69 64 65 20 is used inside
1e230 6f 66 20 61 73 73 65 72 74 28 29 20 73 74 61 74 of assert() stat
1e240 65 6d 65 6e 74 73 20 74 6f 20 69 6e 64 69 63 61 ements to indica
1e250 74 65 20 74 68 61 74 0a 2a 2a 20 74 68 65 20 61 te that.** the a
1e260 73 73 65 72 74 20 69 73 20 6f 6e 6c 79 20 76 61 ssert is only va
1e270 6c 69 64 20 6f 6e 20 61 20 77 65 6c 6c 2d 66 6f lid on a well-fo
1e280 72 6d 65 64 20 64 61 74 61 62 61 73 65 2e 20 20 rmed database.
1e290 49 6e 73 74 65 61 64 20 6f 66 3a 0a 2a 2a 0a 2a Instead of:.**.*
1e2a0 2a 20 20 20 20 20 61 73 73 65 72 74 28 20 58 20 * assert( X
1e2b0 29 3b 0a 2a 2a 0a 2a 2a 20 4f 6e 65 20 77 72 69 );.**.** One wri
1e2c0 74 65 73 3a 0a 2a 2a 0a 2a 2a 20 20 20 20 20 61 tes:.**.** a
1e2d0 73 73 65 72 74 28 20 58 20 7c 7c 20 43 4f 52 52 ssert( X || CORR
1e2e0 55 50 54 5f 44 42 20 29 3b 0a 2a 2a 0a 2a 2a 20 UPT_DB );.**.**
1e2f0 43 4f 52 52 55 50 54 5f 44 42 20 69 73 20 74 72 CORRUPT_DB is tr
1e300 75 65 20 64 75 72 69 6e 67 20 6e 6f 72 6d 61 6c ue during normal
1e310 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 43 4f 52 operation. COR
1e320 52 55 50 54 5f 44 42 20 64 6f 65 73 20 6e 6f 74 RUPT_DB does not
1e330 20 69 6e 64 69 63 61 74 65 0a 2a 2a 20 74 68 61 indicate.** tha
1e340 74 20 74 68 65 20 64 61 74 61 62 61 73 65 20 69 t the database i
1e350 73 20 64 65 66 69 6e 69 74 65 6c 79 20 63 6f 72 s definitely cor
1e360 72 75 70 74 2c 20 6f 6e 6c 79 20 74 68 61 74 20 rupt, only that
1e370 69 74 20 6d 69 67 68 74 20 62 65 20 63 6f 72 72 it might be corr
1e380 75 70 74 2e 0a 2a 2a 20 46 6f 72 20 6d 6f 73 74 upt..** For most
1e390 20 74 65 73 74 20 63 61 73 65 73 2c 20 43 4f 52 test cases, COR
1e3a0 52 55 50 54 5f 44 42 20 69 73 20 73 65 74 20 74 RUPT_DB is set t
1e3b0 6f 20 66 61 6c 73 65 20 75 73 69 6e 67 20 61 20 o false using a
1e3c0 73 70 65 63 69 61 6c 0a 2a 2a 20 73 71 6c 69 74 special.** sqlit
1e3d0 65 33 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 28 e3_test_control(
1e3e0 29 2e 20 20 54 68 69 73 20 65 6e 61 62 6c 65 73 ). This enables
1e3f0 20 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d assert() statem
1e400 65 6e 74 73 20 74 6f 20 70 72 6f 76 65 0a 2a 2a ents to prove.**
1e410 20 74 68 69 6e 67 73 20 74 68 61 74 20 61 72 65 things that are
1e420 20 61 6c 77 61 79 73 20 74 72 75 65 20 66 6f 72 always true for
1e430 20 77 65 6c 6c 2d 66 6f 72 6d 65 64 20 64 61 74 well-formed dat
1e440 61 62 61 73 65 73 2e 0a 2a 2f 0a 23 64 65 66 69 abases..*/.#defi
1e450 6e 65 20 43 4f 52 52 55 50 54 5f 44 42 20 20 28 ne CORRUPT_DB (
1e460 73 71 6c 69 74 65 33 43 6f 6e 66 69 67 2e 6e 65 sqlite3Config.ne
1e470 76 65 72 43 6f 72 72 75 70 74 3d 3d 30 29 0a 0a verCorrupt==0)..
1e480 2f 2a 0a 2a 2a 20 43 6f 6e 74 65 78 74 20 70 6f /*.** Context po
1e490 69 6e 74 65 72 20 70 61 73 73 65 64 20 64 6f 77 inter passed dow
1e4a0 6e 20 74 68 72 6f 75 67 68 20 74 68 65 20 74 72 n through the tr
1e4b0 65 65 2d 77 61 6c 6b 2e 0a 2a 2f 0a 73 74 72 75 ee-walk..*/.stru
1e4c0 63 74 20 57 61 6c 6b 65 72 20 7b 0a 20 20 69 6e ct Walker {. in
1e4d0 74 20 28 2a 78 45 78 70 72 43 61 6c 6c 62 61 63 t (*xExprCallbac
1e4e0 6b 29 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 k)(Walker*, Expr
1e4f0 2a 29 3b 20 20 20 20 20 2f 2a 20 43 61 6c 6c 62 *); /* Callb
1e500 61 63 6b 20 66 6f 72 20 65 78 70 72 65 73 73 69 ack for expressi
1e510 6f 6e 73 20 2a 2f 0a 20 20 69 6e 74 20 28 2a 78 ons */. int (*x
1e520 53 65 6c 65 63 74 43 61 6c 6c 62 61 63 6b 29 28 SelectCallback)(
1e530 57 61 6c 6b 65 72 2a 2c 53 65 6c 65 63 74 2a 29 Walker*,Select*)
1e540 3b 20 20 2f 2a 20 43 61 6c 6c 62 61 63 6b 20 66 ; /* Callback f
1e550 6f 72 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 or SELECTs */.
1e560 76 6f 69 64 20 28 2a 78 53 65 6c 65 63 74 43 61 void (*xSelectCa
1e570 6c 6c 62 61 63 6b 32 29 28 57 61 6c 6b 65 72 2a llback2)(Walker*
1e580 2c 53 65 6c 65 63 74 2a 29 3b 2f 2a 20 53 65 63 ,Select*);/* Sec
1e590 6f 6e 64 20 63 61 6c 6c 62 61 63 6b 20 66 6f 72 ond callback for
1e5a0 20 53 45 4c 45 43 54 73 20 2a 2f 0a 20 20 50 61 SELECTs */. Pa
1e5b0 72 73 65 20 2a 70 50 61 72 73 65 3b 20 20 20 20 rse *pParse;
1e5c0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e5d0 20 20 20 20 20 20 20 20 2f 2a 20 50 61 72 73 65 /* Parse
1e5e0 72 20 63 6f 6e 74 65 78 74 2e 20 20 2a 2f 0a 20 r context. */.
1e5f0 20 69 6e 74 20 77 61 6c 6b 65 72 44 65 70 74 68 int walkerDepth
1e600 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1e610 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 /* Nu
1e620 6d 62 65 72 20 6f 66 20 73 75 62 71 75 65 72 69 mber of subqueri
1e630 65 73 20 2a 2f 0a 20 20 75 6e 69 6f 6e 20 7b 20 es */. union {
1e640 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e650 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e660 20 20 2f 2a 20 45 78 74 72 61 20 64 61 74 61 20 /* Extra data
1e670 66 6f 72 20 63 61 6c 6c 62 61 63 6b 20 2a 2f 0a for callback */.
1e680 20 20 20 20 4e 61 6d 65 43 6f 6e 74 65 78 74 20 NameContext
1e690 2a 70 4e 43 3b 20 20 20 20 20 20 20 20 20 20 20 *pNC;
1e6a0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
1e6b0 2a 20 4e 61 6d 69 6e 67 20 63 6f 6e 74 65 78 74 * Naming context
1e6c0 20 2a 2f 0a 20 20 20 20 69 6e 74 20 69 3b 20 20 */. int i;
1e6d0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e6e0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e6f0 20 20 20 2f 2a 20 49 6e 74 65 67 65 72 20 76 61 /* Integer va
1e700 6c 75 65 20 2a 2f 0a 20 20 20 20 53 72 63 4c 69 lue */. SrcLi
1e710 73 74 20 2a 70 53 72 63 4c 69 73 74 3b 20 20 20 st *pSrcList;
1e720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1e730 20 20 20 20 20 20 2f 2a 20 46 52 4f 4d 20 63 6c /* FROM cl
1e740 61 75 73 65 20 2a 2f 0a 20 20 20 20 73 74 72 75 ause */. stru
1e750 63 74 20 53 72 63 43 6f 75 6e 74 20 2a 70 53 72 ct SrcCount *pSr
1e760 63 43 6f 75 6e 74 3b 20 20 20 20 20 20 20 20 20 cCount;
1e770 20 20 20 20 20 20 20 2f 2a 20 43 6f 75 6e 74 69 /* Counti
1e780 6e 67 20 63 6f 6c 75 6d 6e 20 72 65 66 65 72 65 ng column refere
1e790 6e 63 65 73 20 2a 2f 0a 20 20 7d 20 75 3b 0a 7d nces */. } u;.}
1e7a0 3b 0a 0a 2f 2a 20 46 6f 72 77 61 72 64 20 64 65 ;../* Forward de
1e7b0 63 6c 61 72 61 74 69 6f 6e 73 20 2a 2f 0a 69 6e clarations */.in
1e7c0 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 45 78 70 t sqlite3WalkExp
1e7d0 72 28 57 61 6c 6b 65 72 2a 2c 20 45 78 70 72 2a r(Walker*, Expr*
1e7e0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 57 61 );.int sqlite3Wa
1e7f0 6c 6b 45 78 70 72 4c 69 73 74 28 57 61 6c 6b 65 lkExprList(Walke
1e800 72 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a r*, ExprList*);.
1e810 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 6b 53 int sqlite3WalkS
1e820 65 6c 65 63 74 28 57 61 6c 6b 65 72 2a 2c 20 53 elect(Walker*, S
1e830 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
1e840 69 74 65 33 57 61 6c 6b 53 65 6c 65 63 74 45 78 ite3WalkSelectEx
1e850 70 72 28 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 pr(Walker*, Sele
1e860 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 ct*);.int sqlite
1e870 33 57 61 6c 6b 53 65 6c 65 63 74 46 72 6f 6d 28 3WalkSelectFrom(
1e880 57 61 6c 6b 65 72 2a 2c 20 53 65 6c 65 63 74 2a Walker*, Select*
1e890 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e );../*.** Return
1e8a0 20 63 6f 64 65 20 66 72 6f 6d 20 74 68 65 20 70 code from the p
1e8b0 61 72 73 65 2d 74 72 65 65 20 77 61 6c 6b 69 6e arse-tree walkin
1e8c0 67 20 70 72 69 6d 69 74 69 76 65 73 20 61 6e 64 g primitives and
1e8d0 20 74 68 65 69 72 0a 2a 2a 20 63 61 6c 6c 62 61 their.** callba
1e8e0 63 6b 73 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 cks..*/.#define
1e8f0 57 52 43 5f 43 6f 6e 74 69 6e 75 65 20 20 20 20 WRC_Continue
1e900 30 20 20 20 2f 2a 20 43 6f 6e 74 69 6e 75 65 20 0 /* Continue
1e910 64 6f 77 6e 20 69 6e 74 6f 20 63 68 69 6c 64 72 down into childr
1e920 65 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 52 en */.#define WR
1e930 43 5f 50 72 75 6e 65 20 20 20 20 20 20 20 31 20 C_Prune 1
1e940 20 20 2f 2a 20 4f 6d 69 74 20 63 68 69 6c 64 72 /* Omit childr
1e950 65 6e 20 62 75 74 20 63 6f 6e 74 69 6e 75 65 20 en but continue
1e960 77 61 6c 6b 69 6e 67 20 73 69 62 6c 69 6e 67 73 walking siblings
1e970 20 2a 2f 0a 23 64 65 66 69 6e 65 20 57 52 43 5f */.#define WRC_
1e980 41 62 6f 72 74 20 20 20 20 20 20 20 32 20 20 20 Abort 2
1e990 2f 2a 20 41 62 61 6e 64 6f 6e 20 74 68 65 20 74 /* Abandon the t
1e9a0 72 65 65 20 77 61 6c 6b 20 2a 2f 0a 0a 2f 2a 0a ree walk */../*.
1e9b0 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f ** An instance o
1e9c0 66 20 74 68 69 73 20 73 74 72 75 63 74 75 72 65 f this structure
1e9d0 20 72 65 70 72 65 73 65 6e 74 73 20 61 20 73 65 represents a se
1e9e0 74 20 6f 66 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 t of one or more
1e9f0 20 43 54 45 73 0a 2a 2a 20 28 63 6f 6d 6d 6f 6e CTEs.** (common
1ea00 20 74 61 62 6c 65 20 65 78 70 72 65 73 73 69 6f table expressio
1ea10 6e 73 29 20 63 72 65 61 74 65 64 20 62 79 20 61 ns) created by a
1ea20 20 73 69 6e 67 6c 65 20 57 49 54 48 20 63 6c 61 single WITH cla
1ea30 75 73 65 2e 0a 2a 2f 0a 73 74 72 75 63 74 20 57 use..*/.struct W
1ea40 69 74 68 20 7b 0a 20 20 69 6e 74 20 6e 43 74 65 ith {. int nCte
1ea50 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
1ea60 20 20 20 20 20 20 20 20 2f 2a 20 4e 75 6d 62 65 /* Numbe
1ea70 72 20 6f 66 20 43 54 45 73 20 69 6e 20 74 68 65 r of CTEs in the
1ea80 20 57 49 54 48 20 63 6c 61 75 73 65 20 2a 2f 0a WITH clause */.
1ea90 20 20 57 69 74 68 20 2a 70 4f 75 74 65 72 3b 20 With *pOuter;
1eaa0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1eab0 20 20 2f 2a 20 43 6f 6e 74 61 69 6e 69 6e 67 20 /* Containing
1eac0 57 49 54 48 20 63 6c 61 75 73 65 2c 20 6f 72 20 WITH clause, or
1ead0 4e 55 4c 4c 20 2a 2f 0a 20 20 73 74 72 75 63 74 NULL */. struct
1eae0 20 43 74 65 20 7b 20 20 20 20 20 20 20 20 20 20 Cte {
1eaf0 20 20 20 20 20 20 20 20 20 20 2f 2a 20 46 6f 72 /* For
1eb00 20 65 61 63 68 20 43 54 45 20 69 6e 20 74 68 65 each CTE in the
1eb10 20 57 49 54 48 20 63 6c 61 75 73 65 2e 2e 2e 2e WITH clause....
1eb20 20 2a 2f 0a 20 20 20 20 63 68 61 72 20 2a 7a 4e */. char *zN
1eb30 61 6d 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ame;
1eb40 20 20 20 20 20 20 20 20 2f 2a 20 4e 61 6d 65 20 /* Name
1eb50 6f 66 20 74 68 69 73 20 43 54 45 20 2a 2f 0a 20 of this CTE */.
1eb60 20 20 20 45 78 70 72 4c 69 73 74 20 2a 70 43 6f ExprList *pCo
1eb70 6c 73 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 ls;
1eb80 20 20 20 2f 2a 20 4c 69 73 74 20 6f 66 20 65 78 /* List of ex
1eb90 70 6c 69 63 69 74 20 63 6f 6c 75 6d 6e 20 6e 61 plicit column na
1eba0 6d 65 73 2c 20 6f 72 20 4e 55 4c 4c 20 2a 2f 0a mes, or NULL */.
1ebb0 20 20 20 20 53 65 6c 65 63 74 20 2a 70 53 65 6c Select *pSel
1ebc0 65 63 74 3b 20 20 20 20 20 20 20 20 20 20 20 20 ect;
1ebd0 20 20 20 20 2f 2a 20 54 68 65 20 64 65 66 69 6e /* The defin
1ebe0 69 74 69 6f 6e 20 6f 66 20 74 68 69 73 20 43 54 ition of this CT
1ebf0 45 20 2a 2f 0a 20 20 20 20 63 6f 6e 73 74 20 63 E */. const c
1ec00 68 61 72 20 2a 7a 45 72 72 3b 20 20 20 20 20 20 har *zErr;
1ec10 20 20 20 20 20 20 20 20 20 2f 2a 20 45 72 72 6f /* Erro
1ec20 72 20 6d 65 73 73 61 67 65 20 66 6f 72 20 63 69 r message for ci
1ec30 72 63 75 6c 61 72 20 72 65 66 65 72 65 6e 63 65 rcular reference
1ec40 73 20 2a 2f 0a 20 20 7d 20 61 5b 31 5d 3b 0a 7d s */. } a[1];.}
1ec50 3b 0a 0a 2f 2a 0a 2a 2a 20 41 73 73 75 6d 69 6e ;../*.** Assumin
1ec60 67 20 7a 49 6e 20 70 6f 69 6e 74 73 20 74 6f 20 g zIn points to
1ec70 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f the first byte o
1ec80 66 20 61 20 55 54 46 2d 38 20 63 68 61 72 61 63 f a UTF-8 charac
1ec90 74 65 72 2c 0a 2a 2a 20 61 64 76 61 6e 63 65 20 ter,.** advance
1eca0 7a 49 6e 20 74 6f 20 70 6f 69 6e 74 20 74 6f 20 zIn to point to
1ecb0 74 68 65 20 66 69 72 73 74 20 62 79 74 65 20 6f the first byte o
1ecc0 66 20 74 68 65 20 6e 65 78 74 20 55 54 46 2d 38 f the next UTF-8
1ecd0 20 63 68 61 72 61 63 74 65 72 2e 0a 2a 2f 0a 23 character..*/.#
1ece0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 53 4b define SQLITE_SK
1ecf0 49 50 5f 55 54 46 38 28 7a 49 6e 29 20 7b 20 20 IP_UTF8(zIn) {
1ed00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1ed10 20 20 20 20 20 20 5c 0a 20 20 69 66 28 20 28 2a \. if( (*
1ed20 28 7a 49 6e 2b 2b 29 29 3e 3d 30 78 63 30 20 29 (zIn++))>=0xc0 )
1ed30 7b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {
1ed40 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 5c \
1ed50 0a 20 20 20 20 77 68 69 6c 65 28 20 28 2a 7a 49 . while( (*zI
1ed60 6e 20 26 20 30 78 63 30 29 3d 3d 30 78 38 30 20 n & 0xc0)==0x80
1ed70 29 7b 20 7a 49 6e 2b 2b 3b 20 7d 20 20 20 20 20 ){ zIn++; }
1ed80 20 20 20 20 20 20 20 20 5c 0a 20 20 7d 20 20 20 \. }
1ed90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1eda0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1edb0 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1edc0 20 5c 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 \.}../*.** The
1edd0 53 51 4c 49 54 45 5f 2a 5f 42 4b 50 54 20 6d 61 SQLITE_*_BKPT ma
1ede0 63 72 6f 73 20 61 72 65 20 73 75 62 73 74 69 74 cros are substit
1edf0 75 74 65 73 20 66 6f 72 20 74 68 65 20 65 72 72 utes for the err
1ee00 6f 72 20 63 6f 64 65 73 20 77 69 74 68 0a 2a 2a or codes with.**
1ee10 20 74 68 65 20 73 61 6d 65 20 6e 61 6d 65 20 62 the same name b
1ee20 75 74 20 77 69 74 68 6f 75 74 20 74 68 65 20 5f ut without the _
1ee30 42 4b 50 54 20 73 75 66 66 69 78 2e 20 20 54 68 BKPT suffix. Th
1ee40 65 73 65 20 6d 61 63 72 6f 73 20 69 6e 76 6f 6b ese macros invok
1ee50 65 0a 2a 2a 20 72 6f 75 74 69 6e 65 73 20 74 68 e.** routines th
1ee60 61 74 20 72 65 70 6f 72 74 20 74 68 65 20 6c 69 at report the li
1ee70 6e 65 2d 6e 75 6d 62 65 72 20 6f 6e 20 77 68 69 ne-number on whi
1ee80 63 68 20 74 68 65 20 65 72 72 6f 72 20 6f 72 69 ch the error ori
1ee90 67 69 6e 61 74 65 64 0a 2a 2a 20 75 73 69 6e 67 ginated.** using
1eea0 20 73 71 6c 69 74 65 33 5f 6c 6f 67 28 29 2e 20 sqlite3_log().
1eeb0 20 54 68 65 20 72 6f 75 74 69 6e 65 73 20 61 6c The routines al
1eec0 73 6f 20 70 72 6f 76 69 64 65 20 61 20 63 6f 6e so provide a con
1eed0 76 65 6e 69 65 6e 74 20 70 6c 61 63 65 0a 2a 2a venient place.**
1eee0 20 74 6f 20 73 65 74 20 61 20 64 65 62 75 67 67 to set a debugg
1eef0 65 72 20 62 72 65 61 6b 70 6f 69 6e 74 2e 0a 2a er breakpoint..*
1ef00 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 43 6f 72 /.int sqlite3Cor
1ef10 72 75 70 74 45 72 72 6f 72 28 69 6e 74 29 3b 0a ruptError(int);.
1ef20 69 6e 74 20 73 71 6c 69 74 65 33 4d 69 73 75 73 int sqlite3Misus
1ef30 65 45 72 72 6f 72 28 69 6e 74 29 3b 0a 69 6e 74 eError(int);.int
1ef40 20 73 71 6c 69 74 65 33 43 61 6e 74 6f 70 65 6e sqlite3Cantopen
1ef50 45 72 72 6f 72 28 69 6e 74 29 3b 0a 23 64 65 66 Error(int);.#def
1ef60 69 6e 65 20 53 51 4c 49 54 45 5f 43 4f 52 52 55 ine SQLITE_CORRU
1ef70 50 54 5f 42 4b 50 54 20 73 71 6c 69 74 65 33 43 PT_BKPT sqlite3C
1ef80 6f 72 72 75 70 74 45 72 72 6f 72 28 5f 5f 4c 49 orruptError(__LI
1ef90 4e 45 5f 5f 29 0a 23 64 65 66 69 6e 65 20 53 51 NE__).#define SQ
1efa0 4c 49 54 45 5f 4d 49 53 55 53 45 5f 42 4b 50 54 LITE_MISUSE_BKPT
1efb0 20 73 71 6c 69 74 65 33 4d 69 73 75 73 65 45 72 sqlite3MisuseEr
1efc0 72 6f 72 28 5f 5f 4c 49 4e 45 5f 5f 29 0a 23 64 ror(__LINE__).#d
1efd0 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 43 41 4e efine SQLITE_CAN
1efe0 54 4f 50 45 4e 5f 42 4b 50 54 20 73 71 6c 69 74 TOPEN_BKPT sqlit
1eff0 65 33 43 61 6e 74 6f 70 65 6e 45 72 72 6f 72 28 e3CantopenError(
1f000 5f 5f 4c 49 4e 45 5f 5f 29 0a 0a 0a 2f 2a 0a 2a __LINE__).../*.*
1f010 2a 20 46 54 53 34 20 69 73 20 72 65 61 6c 6c 79 * FTS4 is really
1f020 20 61 6e 20 65 78 74 65 6e 73 69 6f 6e 20 66 6f an extension fo
1f030 72 20 46 54 53 33 2e 20 20 49 74 20 69 73 20 65 r FTS3. It is e
1f040 6e 61 62 6c 65 64 20 75 73 69 6e 67 20 74 68 65 nabled using the
1f050 0a 2a 2a 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c .** SQLITE_ENABL
1f060 45 5f 46 54 53 33 20 6d 61 63 72 6f 2e 20 20 42 E_FTS3 macro. B
1f070 75 74 20 74 6f 20 61 76 6f 69 64 20 63 6f 6e 66 ut to avoid conf
1f080 75 73 69 6f 6e 20 77 65 20 61 6c 73 6f 20 61 6c usion we also al
1f090 6c 0a 2a 2a 20 74 68 65 20 53 51 4c 49 54 45 5f l.** the SQLITE_
1f0a0 45 4e 41 42 4c 45 5f 46 54 53 34 20 6d 61 63 72 ENABLE_FTS4 macr
1f0b0 6f 20 74 6f 20 73 65 72 76 65 20 61 73 20 61 6e o to serve as an
1f0c0 20 61 6c 69 73 73 65 20 66 6f 72 20 53 51 4c 49 alisse for SQLI
1f0d0 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 2e 0a TE_ENABLE_FTS3..
1f0e0 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 */.#if defined(S
1f0f0 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
1f100 34 29 20 26 26 20 21 64 65 66 69 6e 65 64 28 53 4) && !defined(S
1f110 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 QLITE_ENABLE_FTS
1f120 33 29 0a 23 20 64 65 66 69 6e 65 20 53 51 4c 49 3).# define SQLI
1f130 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 0a 23 TE_ENABLE_FTS3.#
1f140 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 endif../*.** The
1f150 20 63 74 79 70 65 2e 68 20 68 65 61 64 65 72 20 ctype.h header
1f160 69 73 20 6e 65 65 64 65 64 20 66 6f 72 20 6e 6f is needed for no
1f170 6e 2d 41 53 43 49 49 20 73 79 73 74 65 6d 73 2e n-ASCII systems.
1f180 20 20 49 74 20 69 73 20 61 6c 73 6f 0a 2a 2a 20 It is also.**
1f190 6e 65 65 64 65 64 20 62 79 20 46 54 53 33 20 77 needed by FTS3 w
1f1a0 68 65 6e 20 46 54 53 33 20 69 73 20 69 6e 63 6c hen FTS3 is incl
1f1b0 75 64 65 64 20 69 6e 20 74 68 65 20 61 6d 61 6c uded in the amal
1f1c0 67 61 6d 61 74 69 6f 6e 2e 0a 2a 2f 0a 23 69 66 gamation..*/.#if
1f1d0 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
1f1e0 5f 41 53 43 49 49 29 20 7c 7c 20 5c 0a 20 20 20 _ASCII) || \.
1f1f0 20 28 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 (defined(SQLITE
1f200 5f 45 4e 41 42 4c 45 5f 46 54 53 33 29 20 26 26 _ENABLE_FTS3) &&
1f210 20 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f defined(SQLITE_
1f220 41 4d 41 4c 47 41 4d 41 54 49 4f 4e 29 29 0a 23 AMALGAMATION)).#
1f230 20 69 6e 63 6c 75 64 65 20 3c 63 74 79 70 65 2e include <ctype.
1f240 68 3e 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a h>.#endif../*.**
1f250 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d The following m
1f260 61 63 72 6f 73 20 6d 69 6d 69 63 20 74 68 65 20 acros mimic the
1f270 73 74 61 6e 64 61 72 64 20 6c 69 62 72 61 72 79 standard library
1f280 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f 75 70 70 functions toupp
1f290 65 72 28 29 2c 0a 2a 2a 20 69 73 73 70 61 63 65 er(),.** isspace
1f2a0 28 29 2c 20 69 73 61 6c 6e 75 6d 28 29 2c 20 69 (), isalnum(), i
1f2b0 73 64 69 67 69 74 28 29 20 61 6e 64 20 69 73 78 sdigit() and isx
1f2c0 64 69 67 69 74 28 29 2c 20 72 65 73 70 65 63 74 digit(), respect
1f2d0 69 76 65 6c 79 2e 20 54 68 65 0a 2a 2a 20 73 71 ively. The.** sq
1f2e0 6c 69 74 65 20 76 65 72 73 69 6f 6e 73 20 6f 6e lite versions on
1f2f0 6c 79 20 77 6f 72 6b 20 66 6f 72 20 41 53 43 49 ly work for ASCI
1f300 49 20 63 68 61 72 61 63 74 65 72 73 2c 20 72 65 I characters, re
1f310 67 61 72 64 6c 65 73 73 20 6f 66 20 6c 6f 63 61 gardless of loca
1f320 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 le..*/.#ifdef SQ
1f330 4c 49 54 45 5f 41 53 43 49 49 0a 23 20 64 65 66 LITE_ASCII.# def
1f340 69 6e 65 20 73 71 6c 69 74 65 33 54 6f 75 70 70 ine sqlite3Toupp
1f350 65 72 28 78 29 20 20 28 28 78 29 26 7e 28 73 71 er(x) ((x)&~(sq
1f360 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 lite3CtypeMap[(u
1f370 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
1f380 5d 26 30 78 32 30 29 29 0a 23 20 64 65 66 69 6e ]&0x20)).# defin
1f390 65 20 73 71 6c 69 74 65 33 49 73 73 70 61 63 65 e sqlite3Isspace
1f3a0 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
1f3b0 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
1f3c0 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 31 29 char)(x)]&0x01)
1f3d0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
1f3e0 33 49 73 61 6c 6e 75 6d 28 78 29 20 20 20 28 73 3Isalnum(x) (s
1f3f0 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
1f400 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
1f410 29 5d 26 30 78 30 36 29 0a 23 20 64 65 66 69 6e )]&0x06).# defin
1f420 65 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 e sqlite3Isalpha
1f430 28 78 29 20 20 20 28 73 71 6c 69 74 65 33 43 74 (x) (sqlite3Ct
1f440 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
1f450 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 32 29 char)(x)]&0x02)
1f460 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
1f470 33 49 73 64 69 67 69 74 28 78 29 20 20 20 28 73 3Isdigit(x) (s
1f480 71 6c 69 74 65 33 43 74 79 70 65 4d 61 70 5b 28 qlite3CtypeMap[(
1f490 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 unsigned char)(x
1f4a0 29 5d 26 30 78 30 34 29 0a 23 20 64 65 66 69 6e )]&0x04).# defin
1f4b0 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 67 69 e sqlite3Isxdigi
1f4c0 74 28 78 29 20 20 28 73 71 6c 69 74 65 33 43 74 t(x) (sqlite3Ct
1f4d0 79 70 65 4d 61 70 5b 28 75 6e 73 69 67 6e 65 64 ypeMap[(unsigned
1f4e0 20 63 68 61 72 29 28 78 29 5d 26 30 78 30 38 29 char)(x)]&0x08)
1f4f0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
1f500 33 54 6f 6c 6f 77 65 72 28 78 29 20 20 20 28 73 3Tolower(x) (s
1f510 71 6c 69 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 qlite3UpperToLow
1f520 65 72 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er[(unsigned cha
1f530 72 29 28 78 29 5d 29 0a 23 65 6c 73 65 0a 23 20 r)(x)]).#else.#
1f540 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 6f define sqlite3To
1f550 75 70 70 65 72 28 78 29 20 20 20 74 6f 75 70 70 upper(x) toupp
1f560 65 72 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 er((unsigned cha
1f570 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 r)(x)).# define
1f580 73 71 6c 69 74 65 33 49 73 73 70 61 63 65 28 78 sqlite3Isspace(x
1f590 29 20 20 20 69 73 73 70 61 63 65 28 28 75 6e 73 ) isspace((uns
1f5a0 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a igned char)(x)).
1f5b0 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
1f5c0 49 73 61 6c 6e 75 6d 28 78 29 20 20 20 69 73 61 Isalnum(x) isa
1f5d0 6c 6e 75 6d 28 28 75 6e 73 69 67 6e 65 64 20 63 lnum((unsigned c
1f5e0 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 69 6e har)(x)).# defin
1f5f0 65 20 73 71 6c 69 74 65 33 49 73 61 6c 70 68 61 e sqlite3Isalpha
1f600 28 78 29 20 20 20 69 73 61 6c 70 68 61 28 28 75 (x) isalpha((u
1f610 6e 73 69 67 6e 65 64 20 63 68 61 72 29 28 78 29 nsigned char)(x)
1f620 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 ).# define sqlit
1f630 65 33 49 73 64 69 67 69 74 28 78 29 20 20 20 69 e3Isdigit(x) i
1f640 73 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 64 sdigit((unsigned
1f650 20 63 68 61 72 29 28 78 29 29 0a 23 20 64 65 66 char)(x)).# def
1f660 69 6e 65 20 73 71 6c 69 74 65 33 49 73 78 64 69 ine sqlite3Isxdi
1f670 67 69 74 28 78 29 20 20 69 73 78 64 69 67 69 74 git(x) isxdigit
1f680 28 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 ((unsigned char)
1f690 28 78 29 29 0a 23 20 64 65 66 69 6e 65 20 73 71 (x)).# define sq
1f6a0 6c 69 74 65 33 54 6f 6c 6f 77 65 72 28 78 29 20 lite3Tolower(x)
1f6b0 20 20 74 6f 6c 6f 77 65 72 28 28 75 6e 73 69 67 tolower((unsig
1f6c0 6e 65 64 20 63 68 61 72 29 28 78 29 29 0a 23 65 ned char)(x)).#e
1f6d0 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a 20 49 6e 74 65 ndif../*.** Inte
1f6e0 72 6e 61 6c 20 66 75 6e 63 74 69 6f 6e 20 70 72 rnal function pr
1f6f0 6f 74 6f 74 79 70 65 73 0a 2a 2f 0a 23 64 65 66 ototypes.*/.#def
1f700 69 6e 65 20 73 71 6c 69 74 65 33 53 74 72 49 43 ine sqlite3StrIC
1f710 6d 70 20 73 71 6c 69 74 65 33 5f 73 74 72 69 63 mp sqlite3_stric
1f720 6d 70 0a 69 6e 74 20 73 71 6c 69 74 65 33 53 74 mp.int sqlite3St
1f730 72 6c 65 6e 33 30 28 63 6f 6e 73 74 20 63 68 61 rlen30(const cha
1f740 72 2a 29 3b 0a 23 64 65 66 69 6e 65 20 73 71 6c r*);.#define sql
1f750 69 74 65 33 53 74 72 4e 49 43 6d 70 20 73 71 6c ite3StrNICmp sql
1f760 69 74 65 33 5f 73 74 72 6e 69 63 6d 70 0a 0a 69 ite3_strnicmp..i
1f770 6e 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 nt sqlite3Malloc
1f780 49 6e 69 74 28 76 6f 69 64 29 3b 0a 76 6f 69 64 Init(void);.void
1f790 20 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 45 6e sqlite3MallocEn
1f7a0 64 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 2a 73 d(void);.void *s
1f7b0 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 28 69 6e 74 qlite3Malloc(int
1f7c0 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 );.void *sqlite3
1f7d0 4d 61 6c 6c 6f 63 5a 65 72 6f 28 69 6e 74 29 3b MallocZero(int);
1f7e0 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 33 44 62 .void *sqlite3Db
1f7f0 4d 61 6c 6c 6f 63 5a 65 72 6f 28 73 71 6c 69 74 MallocZero(sqlit
1f800 65 33 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 e3*, int);.void
1f810 2a 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 *sqlite3DbMalloc
1f820 52 61 77 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e Raw(sqlite3*, in
1f830 74 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 t);.char *sqlite
1f840 33 44 62 53 74 72 44 75 70 28 73 71 6c 69 74 65 3DbStrDup(sqlite
1f850 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 3*,const char*);
1f860 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 33 44 62 .char *sqlite3Db
1f870 53 74 72 4e 44 75 70 28 73 71 6c 69 74 65 33 2a StrNDup(sqlite3*
1f880 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 69 6e ,const char*, in
1f890 74 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 65 t);.void *sqlite
1f8a0 33 52 65 61 6c 6c 6f 63 28 76 6f 69 64 2a 2c 20 3Realloc(void*,
1f8b0 69 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 int);.void *sqli
1f8c0 74 65 33 44 62 52 65 61 6c 6c 6f 63 4f 72 46 72 te3DbReallocOrFr
1f8d0 65 65 28 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f ee(sqlite3 *, vo
1f8e0 69 64 20 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 id *, int);.void
1f8f0 20 2a 73 71 6c 69 74 65 33 44 62 52 65 61 6c 6c *sqlite3DbReall
1f900 6f 63 28 73 71 6c 69 74 65 33 20 2a 2c 20 76 6f oc(sqlite3 *, vo
1f910 69 64 20 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 id *, int);.void
1f920 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 73 sqlite3DbFree(s
1f930 71 6c 69 74 65 33 2a 2c 20 76 6f 69 64 2a 29 3b qlite3*, void*);
1f940 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 6c 6c .int sqlite3Mall
1f950 6f 63 53 69 7a 65 28 76 6f 69 64 2a 29 3b 0a 69 ocSize(void*);.i
1f960 6e 74 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c nt sqlite3DbMall
1f970 6f 63 53 69 7a 65 28 73 71 6c 69 74 65 33 2a 2c ocSize(sqlite3*,
1f980 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 2a 73 void*);.void *s
1f990 71 6c 69 74 65 33 53 63 72 61 74 63 68 4d 61 6c qlite3ScratchMal
1f9a0 6c 6f 63 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 loc(int);.void s
1f9b0 71 6c 69 74 65 33 53 63 72 61 74 63 68 46 72 65 qlite3ScratchFre
1f9c0 65 28 76 6f 69 64 2a 29 3b 0a 76 6f 69 64 20 2a e(void*);.void *
1f9d0 73 71 6c 69 74 65 33 50 61 67 65 4d 61 6c 6c 6f sqlite3PageMallo
1f9e0 63 28 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c c(int);.void sql
1f9f0 69 74 65 33 50 61 67 65 46 72 65 65 28 76 6f 69 ite3PageFree(voi
1fa00 64 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 d*);.void sqlite
1fa10 33 4d 65 6d 53 65 74 44 65 66 61 75 6c 74 28 76 3MemSetDefault(v
1fa20 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 oid);.void sqlit
1fa30 65 33 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 48 6f e3BenignMallocHo
1fa40 6f 6b 73 28 76 6f 69 64 20 28 2a 29 28 76 6f 69 oks(void (*)(voi
1fa50 64 29 2c 20 76 6f 69 64 20 28 2a 29 28 76 6f 69 d), void (*)(voi
1fa60 64 29 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 d));.int sqlite3
1fa70 48 65 61 70 4e 65 61 72 6c 79 46 75 6c 6c 28 76 HeapNearlyFull(v
1fa80 6f 69 64 29 3b 0a 0a 2f 2a 0a 2a 2a 20 4f 6e 20 oid);../*.** On
1fa90 73 79 73 74 65 6d 73 20 77 69 74 68 20 61 6d 70 systems with amp
1faa0 6c 65 20 73 74 61 63 6b 20 73 70 61 63 65 20 61 le stack space a
1fab0 6e 64 20 74 68 61 74 20 73 75 70 70 6f 72 74 20 nd that support
1fac0 61 6c 6c 6f 63 61 28 29 2c 20 6d 61 6b 65 0a 2a alloca(), make.*
1fad0 2a 20 75 73 65 20 6f 66 20 61 6c 6c 6f 63 61 28 * use of alloca(
1fae0 29 20 74 6f 20 6f 62 74 61 69 6e 20 73 70 61 63 ) to obtain spac
1faf0 65 20 66 6f 72 20 6c 61 72 67 65 20 61 75 74 6f e for large auto
1fb00 6d 61 74 69 63 20 6f 62 6a 65 63 74 73 2e 20 20 matic objects.
1fb10 42 79 20 64 65 66 61 75 6c 74 2c 0a 2a 2a 20 6f By default,.** o
1fb20 62 74 61 69 6e 20 73 70 61 63 65 20 66 72 6f 6d btain space from
1fb30 20 6d 61 6c 6c 6f 63 28 29 2e 0a 2a 2a 0a 2a 2a malloc()..**.**
1fb40 20 54 68 65 20 61 6c 6c 6f 63 61 28 29 20 72 6f The alloca() ro
1fb50 75 74 69 6e 65 20 6e 65 76 65 72 20 72 65 74 75 utine never retu
1fb60 72 6e 73 20 4e 55 4c 4c 2e 20 20 54 68 69 73 20 rns NULL. This
1fb70 77 69 6c 6c 20 63 61 75 73 65 20 63 6f 64 65 20 will cause code
1fb80 70 61 74 68 73 0a 2a 2a 20 74 68 61 74 20 64 65 paths.** that de
1fb90 61 6c 20 77 69 74 68 20 73 71 6c 69 74 65 33 53 al with sqlite3S
1fba0 74 61 63 6b 41 6c 6c 6f 63 28 29 20 66 61 69 6c tackAlloc() fail
1fbb0 75 72 65 73 20 74 6f 20 62 65 20 75 6e 72 65 61 ures to be unrea
1fbc0 63 68 61 62 6c 65 2e 0a 2a 2f 0a 23 69 66 64 65 chable..*/.#ifde
1fbd0 66 20 53 51 4c 49 54 45 5f 55 53 45 5f 41 4c 4c f SQLITE_USE_ALL
1fbe0 4f 43 41 0a 23 20 64 65 66 69 6e 65 20 73 71 6c OCA.# define sql
1fbf0 69 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 52 61 ite3StackAllocRa
1fc00 77 28 44 2c 4e 29 20 20 20 61 6c 6c 6f 63 61 28 w(D,N) alloca(
1fc10 4e 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 N).# define sqli
1fc20 74 65 33 53 74 61 63 6b 41 6c 6c 6f 63 5a 65 72 te3StackAllocZer
1fc30 6f 28 44 2c 4e 29 20 20 6d 65 6d 73 65 74 28 61 o(D,N) memset(a
1fc40 6c 6c 6f 63 61 28 4e 29 2c 20 30 2c 20 4e 29 0a lloca(N), 0, N).
1fc50 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 # define sqlite3
1fc60 53 74 61 63 6b 46 72 65 65 28 44 2c 50 29 20 20 StackFree(D,P)
1fc70 20 20 20 20 20 0a 23 65 6c 73 65 0a 23 20 64 65 .#else.# de
1fc80 66 69 6e 65 20 73 71 6c 69 74 65 33 53 74 61 63 fine sqlite3Stac
1fc90 6b 41 6c 6c 6f 63 52 61 77 28 44 2c 4e 29 20 20 kAllocRaw(D,N)
1fca0 20 73 71 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 sqlite3DbMalloc
1fcb0 52 61 77 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e Raw(D,N).# defin
1fcc0 65 20 73 71 6c 69 74 65 33 53 74 61 63 6b 41 6c e sqlite3StackAl
1fcd0 6c 6f 63 5a 65 72 6f 28 44 2c 4e 29 20 20 73 71 locZero(D,N) sq
1fce0 6c 69 74 65 33 44 62 4d 61 6c 6c 6f 63 5a 65 72 lite3DbMallocZer
1fcf0 6f 28 44 2c 4e 29 0a 23 20 64 65 66 69 6e 65 20 o(D,N).# define
1fd00 73 71 6c 69 74 65 33 53 74 61 63 6b 46 72 65 65 sqlite3StackFree
1fd10 28 44 2c 50 29 20 20 20 20 20 20 20 73 71 6c 69 (D,P) sqli
1fd20 74 65 33 44 62 46 72 65 65 28 44 2c 50 29 0a 23 te3DbFree(D,P).#
1fd30 65 6e 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 endif..#ifdef SQ
1fd40 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 4d 45 4d 53 LITE_ENABLE_MEMS
1fd50 59 53 33 0a 63 6f 6e 73 74 20 73 71 6c 69 74 65 YS3.const sqlite
1fd60 33 5f 6d 65 6d 5f 6d 65 74 68 6f 64 73 20 2a 73 3_mem_methods *s
1fd70 71 6c 69 74 65 33 4d 65 6d 47 65 74 4d 65 6d 73 qlite3MemGetMems
1fd80 79 73 33 28 76 6f 69 64 29 3b 0a 23 65 6e 64 69 ys3(void);.#endi
1fd90 66 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f f.#ifdef SQLITE_
1fda0 45 4e 41 42 4c 45 5f 4d 45 4d 53 59 53 35 0a 63 ENABLE_MEMSYS5.c
1fdb0 6f 6e 73 74 20 73 71 6c 69 74 65 33 5f 6d 65 6d onst sqlite3_mem
1fdc0 5f 6d 65 74 68 6f 64 73 20 2a 73 71 6c 69 74 65 _methods *sqlite
1fdd0 33 4d 65 6d 47 65 74 4d 65 6d 73 79 73 35 28 76 3MemGetMemsys5(v
1fde0 6f 69 64 29 3b 0a 23 65 6e 64 69 66 0a 0a 0a 23 oid);.#endif...#
1fdf0 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4d 55 ifndef SQLITE_MU
1fe00 54 45 58 5f 4f 4d 49 54 0a 20 20 73 71 6c 69 74 TEX_OMIT. sqlit
1fe10 65 33 5f 6d 75 74 65 78 5f 6d 65 74 68 6f 64 73 e3_mutex_methods
1fe20 20 63 6f 6e 73 74 20 2a 73 71 6c 69 74 65 33 44 const *sqlite3D
1fe30 65 66 61 75 6c 74 4d 75 74 65 78 28 76 6f 69 64 efaultMutex(void
1fe40 29 3b 0a 20 20 73 71 6c 69 74 65 33 5f 6d 75 74 );. sqlite3_mut
1fe50 65 78 5f 6d 65 74 68 6f 64 73 20 63 6f 6e 73 74 ex_methods const
1fe60 20 2a 73 71 6c 69 74 65 33 4e 6f 6f 70 4d 75 74 *sqlite3NoopMut
1fe70 65 78 28 76 6f 69 64 29 3b 0a 20 20 73 71 6c 69 ex(void);. sqli
1fe80 74 65 33 5f 6d 75 74 65 78 20 2a 73 71 6c 69 74 te3_mutex *sqlit
1fe90 65 33 4d 75 74 65 78 41 6c 6c 6f 63 28 69 6e 74 e3MutexAlloc(int
1fea0 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 );. int sqlite3
1feb0 4d 75 74 65 78 49 6e 69 74 28 76 6f 69 64 29 3b MutexInit(void);
1fec0 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4d 75 . int sqlite3Mu
1fed0 74 65 78 45 6e 64 28 76 6f 69 64 29 3b 0a 23 65 texEnd(void);.#e
1fee0 6e 64 69 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 ndif..int sqlite
1fef0 33 53 74 61 74 75 73 56 61 6c 75 65 28 69 6e 74 3StatusValue(int
1ff00 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
1ff10 74 61 74 75 73 41 64 64 28 69 6e 74 2c 20 69 6e tatusAdd(int, in
1ff20 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
1ff30 53 74 61 74 75 73 53 65 74 28 69 6e 74 2c 20 69 StatusSet(int, i
1ff40 6e 74 29 3b 0a 0a 23 69 66 6e 64 65 66 20 53 51 nt);..#ifndef SQ
1ff50 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 LITE_OMIT_FLOATI
1ff60 4e 47 5f 50 4f 49 4e 54 0a 20 20 69 6e 74 20 73 NG_POINT. int s
1ff70 71 6c 69 74 65 33 49 73 4e 61 4e 28 64 6f 75 62 qlite3IsNaN(doub
1ff80 6c 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 le);.#else.# def
1ff90 69 6e 65 20 73 71 6c 69 74 65 33 49 73 4e 61 4e ine sqlite3IsNaN
1ffa0 28 58 29 20 20 30 0a 23 65 6e 64 69 66 0a 0a 2f (X) 0.#endif../
1ffb0 2a 0a 2a 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 *.** An instance
1ffc0 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
1ffd0 67 20 73 74 72 75 63 74 75 72 65 20 68 6f 6c 64 g structure hold
1ffe0 73 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 s information ab
1fff0 6f 75 74 20 53 51 4c 0a 2a 2a 20 66 75 6e 63 74 out SQL.** funct
20000 69 6f 6e 73 20 61 72 67 75 6d 65 6e 74 73 20 74 ions arguments t
20010 68 61 74 20 61 72 65 20 74 68 65 20 70 61 72 61 hat are the para
20020 6d 65 74 65 72 73 20 74 6f 20 74 68 65 20 70 72 meters to the pr
20030 69 6e 74 66 28 29 20 66 75 6e 63 74 69 6f 6e 2e intf() function.
20040 0a 2a 2f 0a 73 74 72 75 63 74 20 50 72 69 6e 74 .*/.struct Print
20050 66 41 72 67 75 6d 65 6e 74 73 20 7b 0a 20 20 69 fArguments {. i
20060 6e 74 20 6e 41 72 67 3b 20 20 20 20 20 20 20 20 nt nArg;
20070 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 74 61 6c /* Total
20080 20 6e 75 6d 62 65 72 20 6f 66 20 61 72 67 75 6d number of argum
20090 65 6e 74 73 20 2a 2f 0a 20 20 69 6e 74 20 6e 55 ents */. int nU
200a0 73 65 64 3b 20 20 20 20 20 20 20 20 20 20 20 20 sed;
200b0 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 20 /* Number of
200c0 61 72 67 75 6d 65 6e 74 73 20 75 73 65 64 20 73 arguments used s
200d0 6f 20 66 61 72 20 2a 2f 0a 20 20 73 71 6c 69 74 o far */. sqlit
200e0 65 33 5f 76 61 6c 75 65 20 2a 2a 61 70 41 72 67 e3_value **apArg
200f0 3b 20 20 20 2f 2a 20 54 68 65 20 61 72 67 75 6d ; /* The argum
20100 65 6e 74 20 76 61 6c 75 65 73 20 2a 2f 0a 7d 3b ent values */.};
20110 0a 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 ..#define SQLITE
20120 5f 50 52 49 4e 54 46 5f 49 4e 54 45 52 4e 41 4c _PRINTF_INTERNAL
20130 20 30 78 30 31 0a 23 64 65 66 69 6e 65 20 53 51 0x01.#define SQ
20140 4c 49 54 45 5f 50 52 49 4e 54 46 5f 53 51 4c 46 LITE_PRINTF_SQLF
20150 55 4e 43 20 20 30 78 30 32 0a 76 6f 69 64 20 73 UNC 0x02.void s
20160 71 6c 69 74 65 33 56 58 50 72 69 6e 74 66 28 53 qlite3VXPrintf(S
20170 74 72 41 63 63 75 6d 2a 2c 20 75 33 32 2c 20 63 trAccum*, u32, c
20180 6f 6e 73 74 20 63 68 61 72 2a 2c 20 76 61 5f 6c onst char*, va_l
20190 69 73 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ist);.void sqlit
201a0 65 33 58 50 72 69 6e 74 66 28 53 74 72 41 63 63 e3XPrintf(StrAcc
201b0 75 6d 2a 2c 20 75 33 32 2c 20 63 6f 6e 73 74 20 um*, u32, const
201c0 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 61 char*, ...);.cha
201d0 72 20 2a 73 71 6c 69 74 65 33 4d 50 72 69 6e 74 r *sqlite3MPrint
201e0 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 f(sqlite3*,const
201f0 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 3b 0a 63 68 char*, ...);.ch
20200 61 72 20 2a 73 71 6c 69 74 65 33 56 4d 50 72 69 ar *sqlite3VMPri
20210 6e 74 66 28 73 71 6c 69 74 65 33 2a 2c 63 6f 6e ntf(sqlite3*,con
20220 73 74 20 63 68 61 72 2a 2c 20 76 61 5f 6c 69 73 st char*, va_lis
20230 74 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 74 65 t);.char *sqlite
20240 33 4d 41 70 70 65 6e 64 66 28 73 71 6c 69 74 65 3MAppendf(sqlite
20250 33 2a 2c 63 68 61 72 2a 2c 63 6f 6e 73 74 20 63 3*,char*,const c
20260 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 23 69 66 20 64 har*,...);.#if d
20270 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 54 45 efined(SQLITE_TE
20280 53 54 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 53 ST) || defined(S
20290 51 4c 49 54 45 5f 44 45 42 55 47 29 0a 20 20 76 QLITE_DEBUG). v
202a0 6f 69 64 20 73 71 6c 69 74 65 33 44 65 62 75 67 oid sqlite3Debug
202b0 50 72 69 6e 74 66 28 63 6f 6e 73 74 20 63 68 61 Printf(const cha
202c0 72 2a 2c 20 2e 2e 2e 29 3b 0a 23 65 6e 64 69 66 r*, ...);.#endif
202d0 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c .#if defined(SQL
202e0 49 54 45 5f 54 45 53 54 29 0a 20 20 76 6f 69 64 ITE_TEST). void
202f0 20 2a 73 71 6c 69 74 65 33 54 65 73 74 54 65 78 *sqlite3TestTex
20300 74 54 6f 50 74 72 28 63 6f 6e 73 74 20 63 68 61 tToPtr(const cha
20310 72 2a 29 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 r*);.#endif../*
20320 4f 75 74 70 75 74 20 66 6f 72 6d 61 74 74 69 6e Output formattin
20330 67 20 66 6f 72 20 53 51 4c 49 54 45 5f 54 45 53 g for SQLITE_TES
20340 54 43 54 52 4c 5f 45 58 50 4c 41 49 4e 20 2a 2f TCTRL_EXPLAIN */
20350 0a 23 69 66 20 64 65 66 69 6e 65 64 28 53 51 4c .#if defined(SQL
20360 49 54 45 5f 45 4e 41 42 4c 45 5f 54 52 45 45 5f ITE_ENABLE_TREE_
20370 45 58 50 4c 41 49 4e 29 0a 20 20 76 6f 69 64 20 EXPLAIN). void
20380 73 71 6c 69 74 65 33 45 78 70 6c 61 69 6e 42 65 sqlite3ExplainBe
20390 67 69 6e 28 56 64 62 65 2a 29 3b 0a 20 20 76 6f gin(Vdbe*);. vo
203a0 69 64 20 73 71 6c 69 74 65 33 45 78 70 6c 61 69 id sqlite3Explai
203b0 6e 50 72 69 6e 74 66 28 56 64 62 65 2a 2c 20 63 nPrintf(Vdbe*, c
203c0 6f 6e 73 74 20 63 68 61 72 2a 2c 20 2e 2e 2e 29 onst char*, ...)
203d0 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
203e0 45 78 70 6c 61 69 6e 4e 4c 28 56 64 62 65 2a 29 ExplainNL(Vdbe*)
203f0 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
20400 45 78 70 6c 61 69 6e 50 75 73 68 28 56 64 62 65 ExplainPush(Vdbe
20410 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
20420 65 33 45 78 70 6c 61 69 6e 50 6f 70 28 56 64 62 e3ExplainPop(Vdb
20430 65 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 e*);. void sqli
20440 74 65 33 45 78 70 6c 61 69 6e 46 69 6e 69 73 68 te3ExplainFinish
20450 28 56 64 62 65 2a 29 3b 0a 20 20 76 6f 69 64 20 (Vdbe*);. void
20460 73 71 6c 69 74 65 33 45 78 70 6c 61 69 6e 53 65 sqlite3ExplainSe
20470 6c 65 63 74 28 56 64 62 65 2a 2c 20 53 65 6c 65 lect(Vdbe*, Sele
20480 63 74 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c ct*);. void sql
20490 69 74 65 33 45 78 70 6c 61 69 6e 45 78 70 72 28 ite3ExplainExpr(
204a0 56 64 62 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 20 Vdbe*, Expr*);.
204b0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 void sqlite3Exp
204c0 6c 61 69 6e 45 78 70 72 4c 69 73 74 28 56 64 62 lainExprList(Vdb
204d0 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a e*, ExprList*);.
204e0 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 const char *sq
204f0 6c 69 74 65 33 56 64 62 65 45 78 70 6c 61 6e 61 lite3VdbeExplana
20500 74 69 6f 6e 28 56 64 62 65 2a 29 3b 0a 23 65 6c tion(Vdbe*);.#el
20510 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
20520 74 65 33 45 78 70 6c 61 69 6e 42 65 67 69 6e 28 te3ExplainBegin(
20530 58 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 X).# define sqli
20540 74 65 33 45 78 70 6c 61 69 6e 53 65 6c 65 63 74 te3ExplainSelect
20550 28 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 73 (A,B).# define s
20560 71 6c 69 74 65 33 45 78 70 6c 61 69 6e 45 78 70 qlite3ExplainExp
20570 72 28 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 r(A,B).# define
20580 73 71 6c 69 74 65 33 45 78 70 6c 61 69 6e 45 78 sqlite3ExplainEx
20590 70 72 4c 69 73 74 28 41 2c 42 29 0a 23 20 64 65 prList(A,B).# de
205a0 66 69 6e 65 20 73 71 6c 69 74 65 33 45 78 70 6c fine sqlite3Expl
205b0 61 69 6e 46 69 6e 69 73 68 28 58 29 0a 23 20 64 ainFinish(X).# d
205c0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 64 62 efine sqlite3Vdb
205d0 65 45 78 70 6c 61 6e 61 74 69 6f 6e 28 58 29 20 eExplanation(X)
205e0 30 0a 23 65 6e 64 69 66 0a 0a 0a 76 6f 69 64 20 0.#endif...void
205f0 73 71 6c 69 74 65 33 53 65 74 53 74 72 69 6e 67 sqlite3SetString
20600 28 63 68 61 72 20 2a 2a 2c 20 73 71 6c 69 74 65 (char **, sqlite
20610 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 3*, const char*,
20620 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ...);.void sqli
20630 74 65 33 45 72 72 6f 72 4d 73 67 28 50 61 72 73 te3ErrorMsg(Pars
20640 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c e*, const char*,
20650 20 2e 2e 2e 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ...);.int sqlit
20660 65 33 44 65 71 75 6f 74 65 28 63 68 61 72 2a 29 e3Dequote(char*)
20670 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 ;.int sqlite3Key
20680 77 6f 72 64 43 6f 64 65 28 63 6f 6e 73 74 20 75 wordCode(const u
20690 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 2c 20 69 nsigned char*, i
206a0 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 nt);.int sqlite3
206b0 52 75 6e 50 61 72 73 65 72 28 50 61 72 73 65 2a RunParser(Parse*
206c0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 , const char*, c
206d0 68 61 72 20 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 har **);.void sq
206e0 6c 69 74 65 33 46 69 6e 69 73 68 43 6f 64 69 6e lite3FinishCodin
206f0 67 28 50 61 72 73 65 2a 29 3b 0a 69 6e 74 20 73 g(Parse*);.int s
20700 71 6c 69 74 65 33 47 65 74 54 65 6d 70 52 65 67 qlite3GetTempReg
20710 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 (Parse*);.void s
20720 71 6c 69 74 65 33 52 65 6c 65 61 73 65 54 65 6d qlite3ReleaseTem
20730 70 52 65 67 28 50 61 72 73 65 2a 2c 69 6e 74 29 pReg(Parse*,int)
20740 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 ;.int sqlite3Get
20750 54 65 6d 70 52 61 6e 67 65 28 50 61 72 73 65 2a TempRange(Parse*
20760 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
20770 74 65 33 52 65 6c 65 61 73 65 54 65 6d 70 52 61 te3ReleaseTempRa
20780 6e 67 65 28 50 61 72 73 65 2a 2c 69 6e 74 2c 69 nge(Parse*,int,i
20790 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
207a0 33 43 6c 65 61 72 54 65 6d 70 52 65 67 43 61 63 3ClearTempRegCac
207b0 68 65 28 50 61 72 73 65 2a 29 3b 0a 45 78 70 72 he(Parse*);.Expr
207c0 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 6c 6c *sqlite3ExprAll
207d0 6f 63 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 2c oc(sqlite3*,int,
207e0 63 6f 6e 73 74 20 54 6f 6b 65 6e 2a 2c 69 6e 74 const Token*,int
207f0 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 74 65 33 );.Expr *sqlite3
20800 45 78 70 72 28 73 71 6c 69 74 65 33 2a 2c 69 6e Expr(sqlite3*,in
20810 74 2c 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a t,const char*);.
20820 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
20830 41 74 74 61 63 68 53 75 62 74 72 65 65 73 28 73 AttachSubtrees(s
20840 71 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c 45 78 qlite3*,Expr*,Ex
20850 70 72 2a 2c 45 78 70 72 2a 29 3b 0a 45 78 70 72 pr*,Expr*);.Expr
20860 20 2a 73 71 6c 69 74 65 33 50 45 78 70 72 28 50 *sqlite3PExpr(P
20870 61 72 73 65 2a 2c 20 69 6e 74 2c 20 45 78 70 72 arse*, int, Expr
20880 2a 2c 20 45 78 70 72 2a 2c 20 63 6f 6e 73 74 20 *, Expr*, const
20890 54 6f 6b 65 6e 2a 29 3b 0a 45 78 70 72 20 2a 73 Token*);.Expr *s
208a0 71 6c 69 74 65 33 45 78 70 72 41 6e 64 28 73 71 qlite3ExprAnd(sq
208b0 6c 69 74 65 33 2a 2c 45 78 70 72 2a 2c 20 45 78 lite3*,Expr*, Ex
208c0 70 72 2a 29 3b 0a 45 78 70 72 20 2a 73 71 6c 69 pr*);.Expr *sqli
208d0 74 65 33 45 78 70 72 46 75 6e 63 74 69 6f 6e 28 te3ExprFunction(
208e0 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 73 74 2a Parse*,ExprList*
208f0 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
20900 73 71 6c 69 74 65 33 45 78 70 72 41 73 73 69 67 sqlite3ExprAssig
20910 6e 56 61 72 4e 75 6d 62 65 72 28 50 61 72 73 65 nVarNumber(Parse
20920 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 *, Expr*);.void
20930 73 71 6c 69 74 65 33 45 78 70 72 44 65 6c 65 74 sqlite3ExprDelet
20940 65 28 73 71 6c 69 74 65 33 2a 2c 20 45 78 70 72 e(sqlite3*, Expr
20950 2a 29 3b 0a 45 78 70 72 4c 69 73 74 20 2a 73 71 *);.ExprList *sq
20960 6c 69 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 lite3ExprListApp
20970 65 6e 64 28 50 61 72 73 65 2a 2c 45 78 70 72 4c end(Parse*,ExprL
20980 69 73 74 2a 2c 45 78 70 72 2a 29 3b 0a 76 6f 69 ist*,Expr*);.voi
20990 64 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 d sqlite3ExprLis
209a0 74 53 65 74 4e 61 6d 65 28 50 61 72 73 65 2a 2c tSetName(Parse*,
209b0 45 78 70 72 4c 69 73 74 2a 2c 54 6f 6b 65 6e 2a ExprList*,Token*
209c0 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
209d0 74 65 33 45 78 70 72 4c 69 73 74 53 65 74 53 70 te3ExprListSetSp
209e0 61 6e 28 50 61 72 73 65 2a 2c 45 78 70 72 4c 69 an(Parse*,ExprLi
209f0 73 74 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b 0a st*,ExprSpan*);.
20a00 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 void sqlite3Expr
20a10 4c 69 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 ListDelete(sqlit
20a20 65 33 2a 2c 20 45 78 70 72 4c 69 73 74 2a 29 3b e3*, ExprList*);
20a30 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e 69 74 .int sqlite3Init
20a40 28 73 71 6c 69 74 65 33 2a 2c 20 63 68 61 72 2a (sqlite3*, char*
20a50 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 *);.int sqlite3I
20a60 6e 69 74 43 61 6c 6c 62 61 63 6b 28 76 6f 69 64 nitCallback(void
20a70 2a 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2a 2c 20 *, int, char**,
20a80 63 68 61 72 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 char**);.void sq
20a90 6c 69 74 65 33 50 72 61 67 6d 61 28 50 61 72 73 lite3Pragma(Pars
20aa0 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a e*,Token*,Token*
20ab0 2c 54 6f 6b 65 6e 2a 2c 69 6e 74 29 3b 0a 76 6f ,Token*,int);.vo
20ac0 69 64 20 73 71 6c 69 74 65 33 52 65 73 65 74 41 id sqlite3ResetA
20ad0 6c 6c 53 63 68 65 6d 61 73 4f 66 43 6f 6e 6e 65 llSchemasOfConne
20ae0 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 2a 29 3b ction(sqlite3*);
20af0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 73 .void sqlite3Res
20b00 65 74 4f 6e 65 53 63 68 65 6d 61 28 73 71 6c 69 etOneSchema(sqli
20b10 74 65 33 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 te3*,int);.void
20b20 73 71 6c 69 74 65 33 43 6f 6c 6c 61 70 73 65 44 sqlite3CollapseD
20b30 61 74 61 62 61 73 65 41 72 72 61 79 28 73 71 6c atabaseArray(sql
20b40 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ite3*);.void sql
20b50 69 74 65 33 42 65 67 69 6e 50 61 72 73 65 28 50 ite3BeginParse(P
20b60 61 72 73 65 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 arse*,int);.void
20b70 20 73 71 6c 69 74 65 33 43 6f 6d 6d 69 74 49 6e sqlite3CommitIn
20b80 74 65 72 6e 61 6c 43 68 61 6e 67 65 73 28 73 71 ternalChanges(sq
20b90 6c 69 74 65 33 2a 29 3b 0a 54 61 62 6c 65 20 2a lite3*);.Table *
20ba0 73 71 6c 69 74 65 33 52 65 73 75 6c 74 53 65 74 sqlite3ResultSet
20bb0 4f 66 53 65 6c 65 63 74 28 50 61 72 73 65 2a 2c OfSelect(Parse*,
20bc0 53 65 6c 65 63 74 2a 29 3b 0a 76 6f 69 64 20 73 Select*);.void s
20bd0 71 6c 69 74 65 33 4f 70 65 6e 4d 61 73 74 65 72 qlite3OpenMaster
20be0 54 61 62 6c 65 28 50 61 72 73 65 20 2a 2c 20 69 Table(Parse *, i
20bf0 6e 74 29 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 nt);.Index *sqli
20c00 74 65 33 50 72 69 6d 61 72 79 4b 65 79 49 6e 64 te3PrimaryKeyInd
20c10 65 78 28 54 61 62 6c 65 2a 29 3b 0a 69 31 36 20 ex(Table*);.i16
20c20 73 71 6c 69 74 65 33 43 6f 6c 75 6d 6e 4f 66 49 sqlite3ColumnOfI
20c30 6e 64 65 78 28 49 6e 64 65 78 2a 2c 20 69 31 36 ndex(Index*, i16
20c40 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
20c50 74 61 72 74 54 61 62 6c 65 28 50 61 72 73 65 2a tartTable(Parse*
20c60 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 ,Token*,Token*,i
20c70 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b nt,int,int,int);
20c80 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
20c90 43 6f 6c 75 6d 6e 28 50 61 72 73 65 2a 2c 54 6f Column(Parse*,To
20ca0 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
20cb0 74 65 33 41 64 64 4e 6f 74 4e 75 6c 6c 28 50 61 te3AddNotNull(Pa
20cc0 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 rse*, int);.void
20cd0 20 73 71 6c 69 74 65 33 41 64 64 50 72 69 6d 61 sqlite3AddPrima
20ce0 72 79 4b 65 79 28 50 61 72 73 65 2a 2c 20 45 78 ryKey(Parse*, Ex
20cf0 70 72 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e prList*, int, in
20d00 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 t, int);.void sq
20d10 6c 69 74 65 33 41 64 64 43 68 65 63 6b 43 6f 6e lite3AddCheckCon
20d20 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 straint(Parse*,
20d30 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c Expr*);.void sql
20d40 69 74 65 33 41 64 64 43 6f 6c 75 6d 6e 54 79 70 ite3AddColumnTyp
20d50 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 29 e(Parse*,Token*)
20d60 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 ;.void sqlite3Ad
20d70 64 44 65 66 61 75 6c 74 56 61 6c 75 65 28 50 61 dDefaultValue(Pa
20d80 72 73 65 2a 2c 45 78 70 72 53 70 61 6e 2a 29 3b rse*,ExprSpan*);
20d90 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 41 64 64 .void sqlite3Add
20da0 43 6f 6c 6c 61 74 65 54 79 70 65 28 50 61 72 73 CollateType(Pars
20db0 65 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 e*, Token*);.voi
20dc0 64 20 73 71 6c 69 74 65 33 45 6e 64 54 61 62 6c d sqlite3EndTabl
20dd0 65 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c e(Parse*,Token*,
20de0 54 6f 6b 65 6e 2a 2c 75 38 2c 53 65 6c 65 63 74 Token*,u8,Select
20df0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 *);.int sqlite3P
20e00 61 72 73 65 55 72 69 28 63 6f 6e 73 74 20 63 68 arseUri(const ch
20e10 61 72 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c ar*,const char*,
20e20 75 6e 73 69 67 6e 65 64 20 69 6e 74 2a 2c 0a 20 unsigned int*,.
20e30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20e40 20 20 20 73 71 6c 69 74 65 33 5f 76 66 73 2a 2a sqlite3_vfs**
20e50 2c 63 68 61 72 2a 2a 2c 63 68 61 72 20 2a 2a 29 ,char**,char **)
20e60 3b 0a 42 74 72 65 65 20 2a 73 71 6c 69 74 65 33 ;.Btree *sqlite3
20e70 44 62 4e 61 6d 65 54 6f 42 74 72 65 65 28 73 71 DbNameToBtree(sq
20e80 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
20e90 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
20ea0 43 6f 64 65 4f 6e 63 65 28 50 61 72 73 65 20 2a CodeOnce(Parse *
20eb0 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 );..#ifdef SQLIT
20ec0 45 5f 4f 4d 49 54 5f 42 55 49 4c 54 49 4e 5f 54 E_OMIT_BUILTIN_T
20ed0 45 53 54 0a 23 20 64 65 66 69 6e 65 20 73 71 6c EST.# define sql
20ee0 69 74 65 33 46 61 75 6c 74 53 69 6d 28 58 29 20 ite3FaultSim(X)
20ef0 53 51 4c 49 54 45 5f 4f 4b 0a 23 65 6c 73 65 0a SQLITE_OK.#else.
20f00 20 20 69 6e 74 20 73 71 6c 69 74 65 33 46 61 75 int sqlite3Fau
20f10 6c 74 53 69 6d 28 69 6e 74 29 3b 0a 23 65 6e 64 ltSim(int);.#end
20f20 69 66 0a 0a 42 69 74 76 65 63 20 2a 73 71 6c 69 if..Bitvec *sqli
20f30 74 65 33 42 69 74 76 65 63 43 72 65 61 74 65 28 te3BitvecCreate(
20f40 75 33 32 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 u32);.int sqlite
20f50 33 42 69 74 76 65 63 54 65 73 74 28 42 69 74 76 3BitvecTest(Bitv
20f60 65 63 2a 2c 20 75 33 32 29 3b 0a 69 6e 74 20 73 ec*, u32);.int s
20f70 71 6c 69 74 65 33 42 69 74 76 65 63 53 65 74 28 qlite3BitvecSet(
20f80 42 69 74 76 65 63 2a 2c 20 75 33 32 29 3b 0a 76 Bitvec*, u32);.v
20f90 6f 69 64 20 73 71 6c 69 74 65 33 42 69 74 76 65 oid sqlite3Bitve
20fa0 63 43 6c 65 61 72 28 42 69 74 76 65 63 2a 2c 20 cClear(Bitvec*,
20fb0 75 33 32 2c 20 76 6f 69 64 2a 29 3b 0a 76 6f 69 u32, void*);.voi
20fc0 64 20 73 71 6c 69 74 65 33 42 69 74 76 65 63 44 d sqlite3BitvecD
20fd0 65 73 74 72 6f 79 28 42 69 74 76 65 63 2a 29 3b estroy(Bitvec*);
20fe0 0a 75 33 32 20 73 71 6c 69 74 65 33 42 69 74 76 .u32 sqlite3Bitv
20ff0 65 63 53 69 7a 65 28 42 69 74 76 65 63 2a 29 3b ecSize(Bitvec*);
21000 0a 69 6e 74 20 73 71 6c 69 74 65 33 42 69 74 76 .int sqlite3Bitv
21010 65 63 42 75 69 6c 74 69 6e 54 65 73 74 28 69 6e ecBuiltinTest(in
21020 74 2c 69 6e 74 2a 29 3b 0a 0a 52 6f 77 53 65 74 t,int*);..RowSet
21030 20 2a 73 71 6c 69 74 65 33 52 6f 77 53 65 74 49 *sqlite3RowSetI
21040 6e 69 74 28 73 71 6c 69 74 65 33 2a 2c 20 76 6f nit(sqlite3*, vo
21050 69 64 2a 2c 20 75 6e 73 69 67 6e 65 64 20 69 6e id*, unsigned in
21060 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
21070 52 6f 77 53 65 74 43 6c 65 61 72 28 52 6f 77 53 RowSetClear(RowS
21080 65 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 et*);.void sqlit
21090 65 33 52 6f 77 53 65 74 49 6e 73 65 72 74 28 52 e3RowSetInsert(R
210a0 6f 77 53 65 74 2a 2c 20 69 36 34 29 3b 0a 69 6e owSet*, i64);.in
210b0 74 20 73 71 6c 69 74 65 33 52 6f 77 53 65 74 54 t sqlite3RowSetT
210c0 65 73 74 28 52 6f 77 53 65 74 2a 2c 20 69 6e 74 est(RowSet*, int
210d0 20 69 42 61 74 63 68 2c 20 69 36 34 29 3b 0a 69 iBatch, i64);.i
210e0 6e 74 20 73 71 6c 69 74 65 33 52 6f 77 53 65 74 nt sqlite3RowSet
210f0 4e 65 78 74 28 52 6f 77 53 65 74 2a 2c 20 69 36 Next(RowSet*, i6
21100 34 2a 29 3b 0a 0a 76 6f 69 64 20 73 71 6c 69 74 4*);..void sqlit
21110 65 33 43 72 65 61 74 65 56 69 65 77 28 50 61 72 e3CreateView(Par
21120 73 65 2a 2c 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e se*,Token*,Token
21130 2a 2c 54 6f 6b 65 6e 2a 2c 53 65 6c 65 63 74 2a *,Token*,Select*
21140 2c 69 6e 74 2c 69 6e 74 29 3b 0a 0a 23 69 66 20 ,int,int);..#if
21150 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f !defined(SQLITE_
21160 4f 4d 49 54 5f 56 49 45 57 29 20 7c 7c 20 21 64 OMIT_VIEW) || !d
21170 65 66 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d efined(SQLITE_OM
21180 49 54 5f 56 49 52 54 55 41 4c 54 41 42 4c 45 29 IT_VIRTUALTABLE)
21190 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 56 69 . int sqlite3Vi
211a0 65 77 47 65 74 43 6f 6c 75 6d 6e 4e 61 6d 65 73 ewGetColumnNames
211b0 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 29 3b (Parse*,Table*);
211c0 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 .#else.# define
211d0 73 71 6c 69 74 65 33 56 69 65 77 47 65 74 43 6f sqlite3ViewGetCo
211e0 6c 75 6d 6e 4e 61 6d 65 73 28 41 2c 42 29 20 30 lumnNames(A,B) 0
211f0 0a 23 65 6e 64 69 66 0a 0a 23 69 66 20 53 51 4c .#endif..#if SQL
21200 49 54 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 ITE_MAX_ATTACHED
21210 3e 33 30 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 >30. int sqlite
21220 33 44 62 4d 61 73 6b 41 6c 6c 5a 65 72 6f 28 79 3DbMaskAllZero(y
21230 44 62 4d 61 73 6b 29 3b 0a 23 65 6e 64 69 66 0a DbMask);.#endif.
21240 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 6f 70 void sqlite3Drop
21250 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 Table(Parse*, Sr
21260 63 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 cList*, int, int
21270 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 );.void sqlite3C
21280 6f 64 65 44 72 6f 70 54 61 62 6c 65 28 50 61 72 odeDropTable(Par
21290 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
212a0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
212b0 69 74 65 33 44 65 6c 65 74 65 54 61 62 6c 65 28 ite3DeleteTable(
212c0 73 71 6c 69 74 65 33 2a 2c 20 54 61 62 6c 65 2a sqlite3*, Table*
212d0 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 );.#ifndef SQLIT
212e0 45 5f 4f 4d 49 54 5f 41 55 54 4f 49 4e 43 52 45 E_OMIT_AUTOINCRE
212f0 4d 45 4e 54 0a 20 20 76 6f 69 64 20 73 71 6c 69 MENT. void sqli
21300 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 te3Autoincrement
21310 42 65 67 69 6e 28 50 61 72 73 65 20 2a 70 50 61 Begin(Parse *pPa
21320 72 73 65 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c rse);. void sql
21330 69 74 65 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e ite3Autoincremen
21340 74 45 6e 64 28 50 61 72 73 65 20 2a 70 50 61 72 tEnd(Parse *pPar
21350 73 65 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 se);.#else.# def
21360 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 6f 69 ine sqlite3Autoi
21370 6e 63 72 65 6d 65 6e 74 42 65 67 69 6e 28 58 29 ncrementBegin(X)
21380 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
21390 33 41 75 74 6f 69 6e 63 72 65 6d 65 6e 74 45 6e 3AutoincrementEn
213a0 64 28 58 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 d(X).#endif.void
213b0 20 73 71 6c 69 74 65 33 49 6e 73 65 72 74 28 50 sqlite3Insert(P
213c0 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c arse*, SrcList*,
213d0 20 53 65 6c 65 63 74 2a 2c 20 49 64 4c 69 73 74 Select*, IdList
213e0 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 2a 73 *, int);.void *s
213f0 71 6c 69 74 65 33 41 72 72 61 79 41 6c 6c 6f 63 qlite3ArrayAlloc
21400 61 74 65 28 73 71 6c 69 74 65 33 2a 2c 76 6f 69 ate(sqlite3*,voi
21410 64 2a 2c 69 6e 74 2c 69 6e 74 2a 2c 69 6e 74 2a d*,int,int*,int*
21420 29 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 );.IdList *sqlit
21430 65 33 49 64 4c 69 73 74 41 70 70 65 6e 64 28 73 e3IdListAppend(s
21440 71 6c 69 74 65 33 2a 2c 20 49 64 4c 69 73 74 2a qlite3*, IdList*
21450 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 , Token*);.int s
21460 71 6c 69 74 65 33 49 64 4c 69 73 74 49 6e 64 65 qlite3IdListInde
21470 78 28 49 64 4c 69 73 74 2a 2c 63 6f 6e 73 74 20 x(IdList*,const
21480 63 68 61 72 2a 29 3b 0a 53 72 63 4c 69 73 74 20 char*);.SrcList
21490 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 45 *sqlite3SrcListE
214a0 6e 6c 61 72 67 65 28 73 71 6c 69 74 65 33 2a 2c nlarge(sqlite3*,
214b0 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 2c 20 SrcList*, int,
214c0 69 6e 74 29 3b 0a 53 72 63 4c 69 73 74 20 2a 73 int);.SrcList *s
214d0 71 6c 69 74 65 33 53 72 63 4c 69 73 74 41 70 70 qlite3SrcListApp
214e0 65 6e 64 28 73 71 6c 69 74 65 33 2a 2c 20 53 72 end(sqlite3*, Sr
214f0 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 cList*, Token*,
21500 54 6f 6b 65 6e 2a 29 3b 0a 53 72 63 4c 69 73 74 Token*);.SrcList
21510 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 *sqlite3SrcList
21520 41 70 70 65 6e 64 46 72 6f 6d 54 65 72 6d 28 50 AppendFromTerm(P
21530 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c arse*, SrcList*,
21540 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a 2c Token*, Token*,
21550 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
21560 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21570 20 20 20 20 20 20 20 54 6f 6b 65 6e 2a 2c 20 53 Token*, S
21580 65 6c 65 63 74 2a 2c 20 45 78 70 72 2a 2c 20 49 elect*, Expr*, I
21590 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 20 73 71 dList*);.void sq
215a0 6c 69 74 65 33 53 72 63 4c 69 73 74 49 6e 64 65 lite3SrcListInde
215b0 78 65 64 42 79 28 50 61 72 73 65 20 2a 2c 20 53 xedBy(Parse *, S
215c0 72 63 4c 69 73 74 20 2a 2c 20 54 6f 6b 65 6e 20 rcList *, Token
215d0 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 *);.int sqlite3I
215e0 6e 64 65 78 65 64 42 79 4c 6f 6f 6b 75 70 28 50 ndexedByLookup(P
215f0 61 72 73 65 20 2a 2c 20 73 74 72 75 63 74 20 53 arse *, struct S
21600 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 3b 0a rcList_item *);.
21610 76 6f 69 64 20 73 71 6c 69 74 65 33 53 72 63 4c void sqlite3SrcL
21620 69 73 74 53 68 69 66 74 4a 6f 69 6e 54 79 70 65 istShiftJoinType
21630 28 53 72 63 4c 69 73 74 2a 29 3b 0a 76 6f 69 64 (SrcList*);.void
21640 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 41 sqlite3SrcListA
21650 73 73 69 67 6e 43 75 72 73 6f 72 73 28 50 61 72 ssignCursors(Par
21660 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a se*, SrcList*);.
21670 76 6f 69 64 20 73 71 6c 69 74 65 33 49 64 4c 69 void sqlite3IdLi
21680 73 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 stDelete(sqlite3
21690 2a 2c 20 49 64 4c 69 73 74 2a 29 3b 0a 76 6f 69 *, IdList*);.voi
216a0 64 20 73 71 6c 69 74 65 33 53 72 63 4c 69 73 74 d sqlite3SrcList
216b0 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 2a 2c Delete(sqlite3*,
216c0 20 53 72 63 4c 69 73 74 2a 29 3b 0a 49 6e 64 65 SrcList*);.Inde
216d0 78 20 2a 73 71 6c 69 74 65 33 41 6c 6c 6f 63 61 x *sqlite3Alloca
216e0 74 65 49 6e 64 65 78 4f 62 6a 65 63 74 28 73 71 teIndexObject(sq
216f0 6c 69 74 65 33 2a 2c 69 31 36 2c 69 6e 74 2c 63 lite3*,i16,int,c
21700 68 61 72 2a 2a 29 3b 0a 49 6e 64 65 78 20 2a 73 har**);.Index *s
21710 71 6c 69 74 65 33 43 72 65 61 74 65 49 6e 64 65 qlite3CreateInde
21720 78 28 50 61 72 73 65 2a 2c 54 6f 6b 65 6e 2a 2c x(Parse*,Token*,
21730 54 6f 6b 65 6e 2a 2c 53 72 63 4c 69 73 74 2a 2c Token*,SrcList*,
21740 45 78 70 72 4c 69 73 74 2a 2c 69 6e 74 2c 54 6f ExprList*,int,To
21750 6b 65 6e 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 ken*,.
21760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
21770 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 Expr*, int, int)
21780 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 ;.void sqlite3Dr
21790 6f 70 49 6e 64 65 78 28 50 61 72 73 65 2a 2c 20 opIndex(Parse*,
217a0 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 3b 0a SrcList*, int);.
217b0 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 63 int sqlite3Selec
217c0 74 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 t(Parse*, Select
217d0 2a 2c 20 53 65 6c 65 63 74 44 65 73 74 2a 29 3b *, SelectDest*);
217e0 0a 53 65 6c 65 63 74 20 2a 73 71 6c 69 74 65 33 .Select *sqlite3
217f0 53 65 6c 65 63 74 4e 65 77 28 50 61 72 73 65 2a SelectNew(Parse*
21800 2c 45 78 70 72 4c 69 73 74 2a 2c 53 72 63 4c 69 ,ExprList*,SrcLi
21810 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 4c 69 st*,Expr*,ExprLi
21820 73 74 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 st*,.
21830 20 20 20 20 20 20 20 20 20 20 20 20 20 20 45 78 Ex
21840 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 75 31 pr*,ExprList*,u1
21850 36 2c 45 78 70 72 2a 2c 45 78 70 72 2a 29 3b 0a 6,Expr*,Expr*);.
21860 76 6f 69 64 20 73 71 6c 69 74 65 33 53 65 6c 65 void sqlite3Sele
21870 63 74 44 65 6c 65 74 65 28 73 71 6c 69 74 65 33 ctDelete(sqlite3
21880 2a 2c 20 53 65 6c 65 63 74 2a 29 3b 0a 54 61 62 *, Select*);.Tab
21890 6c 65 20 2a 73 71 6c 69 74 65 33 53 72 63 4c 69 le *sqlite3SrcLi
218a0 73 74 4c 6f 6f 6b 75 70 28 50 61 72 73 65 2a 2c stLookup(Parse*,
218b0 20 53 72 63 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 SrcList*);.int
218c0 73 71 6c 69 74 65 33 49 73 52 65 61 64 4f 6e 6c sqlite3IsReadOnl
218d0 79 28 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a y(Parse*, Table*
218e0 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c , int);.void sql
218f0 69 74 65 33 4f 70 65 6e 54 61 62 6c 65 28 50 61 ite3OpenTable(Pa
21900 72 73 65 2a 2c 20 69 6e 74 20 69 43 75 72 2c 20 rse*, int iCur,
21910 69 6e 74 20 69 44 62 2c 20 54 61 62 6c 65 2a 2c int iDb, Table*,
21920 20 69 6e 74 29 3b 0a 23 69 66 20 64 65 66 69 6e int);.#if defin
21930 65 64 28 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 ed(SQLITE_ENABLE
21940 5f 55 50 44 41 54 45 5f 44 45 4c 45 54 45 5f 4c _UPDATE_DELETE_L
21950 49 4d 49 54 29 20 26 26 20 21 64 65 66 69 6e 65 IMIT) && !define
21960 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 55 d(SQLITE_OMIT_SU
21970 42 51 55 45 52 59 29 0a 45 78 70 72 20 2a 73 71 BQUERY).Expr *sq
21980 6c 69 74 65 33 4c 69 6d 69 74 57 68 65 72 65 28 lite3LimitWhere(
21990 50 61 72 73 65 2a 2c 53 72 63 4c 69 73 74 2a 2c Parse*,SrcList*,
219a0 45 78 70 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c Expr*,ExprList*,
219b0 45 78 70 72 2a 2c 45 78 70 72 2a 2c 63 68 61 72 Expr*,Expr*,char
219c0 2a 29 3b 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 *);.#endif.void
219d0 73 71 6c 69 74 65 33 44 65 6c 65 74 65 46 72 6f sqlite3DeleteFro
219e0 6d 28 50 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 m(Parse*, SrcLis
219f0 74 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 t*, Expr*);.void
21a00 20 73 71 6c 69 74 65 33 55 70 64 61 74 65 28 50 sqlite3Update(P
21a10 61 72 73 65 2a 2c 20 53 72 63 4c 69 73 74 2a 2c arse*, SrcList*,
21a20 20 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 ExprList*, Expr
21a30 2a 2c 20 69 6e 74 29 3b 0a 57 68 65 72 65 49 6e *, int);.WhereIn
21a40 66 6f 20 2a 73 71 6c 69 74 65 33 57 68 65 72 65 fo *sqlite3Where
21a50 42 65 67 69 6e 28 50 61 72 73 65 2a 2c 53 72 63 Begin(Parse*,Src
21a60 4c 69 73 74 2a 2c 45 78 70 72 2a 2c 45 78 70 72 List*,Expr*,Expr
21a70 4c 69 73 74 2a 2c 45 78 70 72 4c 69 73 74 2a 2c List*,ExprList*,
21a80 75 31 36 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 u16,int);.void s
21a90 71 6c 69 74 65 33 57 68 65 72 65 45 6e 64 28 57 qlite3WhereEnd(W
21aa0 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 75 36 34 20 hereInfo*);.u64
21ab0 73 71 6c 69 74 65 33 57 68 65 72 65 4f 75 74 70 sqlite3WhereOutp
21ac0 75 74 52 6f 77 43 6f 75 6e 74 28 57 68 65 72 65 utRowCount(Where
21ad0 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 Info*);.int sqli
21ae0 74 65 33 57 68 65 72 65 49 73 44 69 73 74 69 6e te3WhereIsDistin
21af0 63 74 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a ct(WhereInfo*);.
21b00 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 int sqlite3Where
21b10 49 73 4f 72 64 65 72 65 64 28 57 68 65 72 65 49 IsOrdered(WhereI
21b20 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 nfo*);.int sqlit
21b30 65 33 57 68 65 72 65 49 73 53 6f 72 74 65 64 28 e3WhereIsSorted(
21b40 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a 69 6e 74 WhereInfo*);.int
21b50 20 73 71 6c 69 74 65 33 57 68 65 72 65 43 6f 6e sqlite3WhereCon
21b60 74 69 6e 75 65 4c 61 62 65 6c 28 57 68 65 72 65 tinueLabel(Where
21b70 49 6e 66 6f 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 Info*);.int sqli
21b80 74 65 33 57 68 65 72 65 42 72 65 61 6b 4c 61 62 te3WhereBreakLab
21b90 65 6c 28 57 68 65 72 65 49 6e 66 6f 2a 29 3b 0a el(WhereInfo*);.
21ba0 69 6e 74 20 73 71 6c 69 74 65 33 57 68 65 72 65 int sqlite3Where
21bb0 4f 6b 4f 6e 65 50 61 73 73 28 57 68 65 72 65 49 OkOnePass(WhereI
21bc0 6e 66 6f 2a 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 nfo*, int*);.int
21bd0 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f 64 65 sqlite3ExprCode
21be0 47 65 74 43 6f 6c 75 6d 6e 28 50 61 72 73 65 2a GetColumn(Parse*
21bf0 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c 20 69 , Table*, int, i
21c00 6e 74 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 76 6f nt, int, u8);.vo
21c10 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 6f id sqlite3ExprCo
21c20 64 65 47 65 74 43 6f 6c 75 6d 6e 4f 66 54 61 62 deGetColumnOfTab
21c30 6c 65 28 56 64 62 65 2a 2c 20 54 61 62 6c 65 2a le(Vdbe*, Table*
21c40 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 29 , int, int, int)
21c50 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 ;.void sqlite3Ex
21c60 70 72 43 6f 64 65 4d 6f 76 65 28 50 61 72 73 65 prCodeMove(Parse
21c70 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 6e 74 *, int, int, int
21c80 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
21c90 78 70 72 43 61 63 68 65 53 74 6f 72 65 28 50 61 xprCacheStore(Pa
21ca0 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 rse*, int, int,
21cb0 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
21cc0 65 33 45 78 70 72 43 61 63 68 65 50 75 73 68 28 e3ExprCachePush(
21cd0 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 Parse*);.void sq
21ce0 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 50 6f lite3ExprCachePo
21cf0 70 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 p(Parse*);.void
21d00 73 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 sqlite3ExprCache
21d10 52 65 6d 6f 76 65 28 50 61 72 73 65 2a 2c 20 69 Remove(Parse*, i
21d20 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
21d30 71 6c 69 74 65 33 45 78 70 72 43 61 63 68 65 43 qlite3ExprCacheC
21d40 6c 65 61 72 28 50 61 72 73 65 2a 29 3b 0a 76 6f lear(Parse*);.vo
21d50 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 61 id sqlite3ExprCa
21d60 63 68 65 41 66 66 69 6e 69 74 79 43 68 61 6e 67 cheAffinityChang
21d70 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 2c 20 69 e(Parse*, int, i
21d80 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
21d90 33 45 78 70 72 43 6f 64 65 28 50 61 72 73 65 2a 3ExprCode(Parse*
21da0 2c 20 45 78 70 72 2a 2c 20 69 6e 74 29 3b 0a 76 , Expr*, int);.v
21db0 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 72 43 oid sqlite3ExprC
21dc0 6f 64 65 46 61 63 74 6f 72 61 62 6c 65 28 50 61 odeFactorable(Pa
21dd0 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 rse*, Expr*, int
21de0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 );.void sqlite3E
21df0 78 70 72 43 6f 64 65 41 74 49 6e 69 74 28 50 61 xprCodeAtInit(Pa
21e00 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 rse*, Expr*, int
21e10 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 , u8);.int sqlit
21e20 65 33 45 78 70 72 43 6f 64 65 54 65 6d 70 28 50 e3ExprCodeTemp(P
21e30 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
21e40 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 t*);.int sqlite3
21e50 45 78 70 72 43 6f 64 65 54 61 72 67 65 74 28 50 ExprCodeTarget(P
21e60 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e arse*, Expr*, in
21e70 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
21e80 45 78 70 72 43 6f 64 65 41 6e 64 43 61 63 68 65 ExprCodeAndCache
21e90 28 50 61 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 (Parse*, Expr*,
21ea0 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 int);.int sqlite
21eb0 33 45 78 70 72 43 6f 64 65 45 78 70 72 4c 69 73 3ExprCodeExprLis
21ec0 74 28 50 61 72 73 65 2a 2c 20 45 78 70 72 4c 69 t(Parse*, ExprLi
21ed0 73 74 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 23 st*, int, u8);.#
21ee0 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 45 43 define SQLITE_EC
21ef0 45 4c 5f 44 55 50 20 20 20 20 20 20 30 78 30 31 EL_DUP 0x01
21f00 20 20 2f 2a 20 44 65 65 70 2c 20 6e 6f 74 20 73 /* Deep, not s
21f10 68 61 6c 6c 6f 77 20 63 6f 70 69 65 73 20 2a 2f hallow copies */
21f20 0a 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f .#define SQLITE_
21f30 45 43 45 4c 5f 46 41 43 54 4f 52 20 20 20 30 78 ECEL_FACTOR 0x
21f40 30 32 20 20 2f 2a 20 46 61 63 74 6f 72 20 6f 75 02 /* Factor ou
21f50 74 20 63 6f 6e 73 74 61 6e 74 20 74 65 72 6d 73 t constant terms
21f60 20 2a 2f 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 */.void sqlite3
21f70 45 78 70 72 49 66 54 72 75 65 28 50 61 72 73 65 ExprIfTrue(Parse
21f80 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c 20 69 *, Expr*, int, i
21f90 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 nt);.void sqlite
21fa0 33 45 78 70 72 49 66 46 61 6c 73 65 28 50 61 72 3ExprIfFalse(Par
21fb0 73 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c se*, Expr*, int,
21fc0 20 69 6e 74 29 3b 0a 54 61 62 6c 65 20 2a 73 71 int);.Table *sq
21fd0 6c 69 74 65 33 46 69 6e 64 54 61 62 6c 65 28 73 lite3FindTable(s
21fe0 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 qlite3*,const ch
21ff0 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a ar*, const char*
22000 29 3b 0a 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 );.Table *sqlite
22010 33 4c 6f 63 61 74 65 54 61 62 6c 65 28 50 61 72 3LocateTable(Par
22020 73 65 2a 2c 69 6e 74 20 69 73 56 69 65 77 2c 63 se*,int isView,c
22030 6f 6e 73 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 onst char*, cons
22040 74 20 63 68 61 72 2a 29 3b 0a 54 61 62 6c 65 20 t char*);.Table
22050 2a 73 71 6c 69 74 65 33 4c 6f 63 61 74 65 54 61 *sqlite3LocateTa
22060 62 6c 65 49 74 65 6d 28 50 61 72 73 65 2a 2c 69 bleItem(Parse*,i
22070 6e 74 20 69 73 56 69 65 77 2c 73 74 72 75 63 74 nt isView,struct
22080 20 53 72 63 4c 69 73 74 5f 69 74 65 6d 20 2a 29 SrcList_item *)
22090 3b 0a 49 6e 64 65 78 20 2a 73 71 6c 69 74 65 33 ;.Index *sqlite3
220a0 46 69 6e 64 49 6e 64 65 78 28 73 71 6c 69 74 65 FindIndex(sqlite
220b0 33 2a 2c 63 6f 6e 73 74 20 63 68 61 72 2a 2c 20 3*,const char*,
220c0 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 76 6f const char*);.vo
220d0 69 64 20 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b id sqlite3Unlink
220e0 41 6e 64 44 65 6c 65 74 65 54 61 62 6c 65 28 73 AndDeleteTable(s
220f0 71 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 qlite3*,int,cons
22100 74 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 t char*);.void s
22110 71 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 qlite3UnlinkAndD
22120 65 6c 65 74 65 49 6e 64 65 78 28 73 71 6c 69 74 eleteIndex(sqlit
22130 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 20 63 68 e3*,int,const ch
22140 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 ar*);.void sqlit
22150 65 33 56 61 63 75 75 6d 28 50 61 72 73 65 2a 29 e3Vacuum(Parse*)
22160 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 75 6e ;.int sqlite3Run
22170 56 61 63 75 75 6d 28 63 68 61 72 2a 2a 2c 20 73 Vacuum(char**, s
22180 71 6c 69 74 65 33 2a 29 3b 0a 63 68 61 72 20 2a qlite3*);.char *
22190 73 71 6c 69 74 65 33 4e 61 6d 65 46 72 6f 6d 54 sqlite3NameFromT
221a0 6f 6b 65 6e 28 73 71 6c 69 74 65 33 2a 2c 20 54 oken(sqlite3*, T
221b0 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 oken*);.int sqli
221c0 74 65 33 45 78 70 72 43 6f 6d 70 61 72 65 28 45 te3ExprCompare(E
221d0 78 70 72 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 xpr*, Expr*, int
221e0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 );.int sqlite3Ex
221f0 70 72 4c 69 73 74 43 6f 6d 70 61 72 65 28 45 78 prListCompare(Ex
22200 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 4c 69 73 prList*, ExprLis
22210 74 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 t*, int);.int sq
22220 6c 69 74 65 33 45 78 70 72 49 6d 70 6c 69 65 73 lite3ExprImplies
22230 45 78 70 72 28 45 78 70 72 2a 2c 20 45 78 70 72 Expr(Expr*, Expr
22240 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
22250 6c 69 74 65 33 45 78 70 72 41 6e 61 6c 79 7a 65 lite3ExprAnalyze
22260 41 67 67 72 65 67 61 74 65 73 28 4e 61 6d 65 43 Aggregates(NameC
22270 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a 29 3b ontext*, Expr*);
22280 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 78 70 .void sqlite3Exp
22290 72 41 6e 61 6c 79 7a 65 41 67 67 4c 69 73 74 28 rAnalyzeAggList(
222a0 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 2c 45 78 70 NameContext*,Exp
222b0 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c rList*);.int sql
222c0 69 74 65 33 46 75 6e 63 74 69 6f 6e 55 73 65 73 ite3FunctionUses
222d0 54 68 69 73 53 72 63 28 45 78 70 72 2a 2c 20 53 ThisSrc(Expr*, S
222e0 72 63 4c 69 73 74 2a 29 3b 0a 56 64 62 65 20 2a rcList*);.Vdbe *
222f0 73 71 6c 69 74 65 33 47 65 74 56 64 62 65 28 50 sqlite3GetVdbe(P
22300 61 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c arse*);.void sql
22310 69 74 65 33 50 72 6e 67 53 61 76 65 53 74 61 74 ite3PrngSaveStat
22320 65 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 e(void);.void sq
22330 6c 69 74 65 33 50 72 6e 67 52 65 73 74 6f 72 65 lite3PrngRestore
22340 53 74 61 74 65 28 76 6f 69 64 29 3b 0a 76 6f 69 State(void);.voi
22350 64 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 d sqlite3Rollbac
22360 6b 41 6c 6c 28 73 71 6c 69 74 65 33 2a 2c 69 6e kAll(sqlite3*,in
22370 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
22380 43 6f 64 65 56 65 72 69 66 79 53 63 68 65 6d 61 CodeVerifySchema
22390 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 76 (Parse*, int);.v
223a0 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 64 65 56 oid sqlite3CodeV
223b0 65 72 69 66 79 4e 61 6d 65 64 53 63 68 65 6d 61 erifyNamedSchema
223c0 28 50 61 72 73 65 2a 2c 20 63 6f 6e 73 74 20 63 (Parse*, const c
223d0 68 61 72 20 2a 7a 44 62 29 3b 0a 76 6f 69 64 20 har *zDb);.void
223e0 73 71 6c 69 74 65 33 42 65 67 69 6e 54 72 61 6e sqlite3BeginTran
223f0 73 61 63 74 69 6f 6e 28 50 61 72 73 65 2a 2c 20 saction(Parse*,
22400 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
22410 65 33 43 6f 6d 6d 69 74 54 72 61 6e 73 61 63 74 e3CommitTransact
22420 69 6f 6e 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ion(Parse*);.voi
22430 64 20 73 71 6c 69 74 65 33 52 6f 6c 6c 62 61 63 d sqlite3Rollbac
22440 6b 54 72 61 6e 73 61 63 74 69 6f 6e 28 50 61 72 kTransaction(Par
22450 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 se*);.void sqlit
22460 65 33 53 61 76 65 70 6f 69 6e 74 28 50 61 72 73 e3Savepoint(Pars
22470 65 2a 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2a 29 e*, int, Token*)
22480 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6c ;.void sqlite3Cl
22490 6f 73 65 53 61 76 65 70 6f 69 6e 74 73 28 73 71 oseSavepoints(sq
224a0 6c 69 74 65 33 20 2a 29 3b 0a 76 6f 69 64 20 73 lite3 *);.void s
224b0 71 6c 69 74 65 33 4c 65 61 76 65 4d 75 74 65 78 qlite3LeaveMutex
224c0 41 6e 64 43 6c 6f 73 65 5a 6f 6d 62 69 65 28 73 AndCloseZombie(s
224d0 71 6c 69 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 qlite3*);.int sq
224e0 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e 73 74 lite3ExprIsConst
224f0 61 6e 74 28 45 78 70 72 2a 29 3b 0a 69 6e 74 20 ant(Expr*);.int
22500 73 71 6c 69 74 65 33 45 78 70 72 49 73 43 6f 6e sqlite3ExprIsCon
22510 73 74 61 6e 74 4e 6f 74 4a 6f 69 6e 28 45 78 70 stantNotJoin(Exp
22520 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 r*);.int sqlite3
22530 45 78 70 72 49 73 43 6f 6e 73 74 61 6e 74 4f 72 ExprIsConstantOr
22540 46 75 6e 63 74 69 6f 6e 28 45 78 70 72 2a 29 3b Function(Expr*);
22550 0a 69 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 .int sqlite3Expr
22560 49 73 49 6e 74 65 67 65 72 28 45 78 70 72 2a 2c IsInteger(Expr*,
22570 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 int*);.int sqli
22580 74 65 33 45 78 70 72 43 61 6e 42 65 4e 75 6c 6c te3ExprCanBeNull
22590 28 63 6f 6e 73 74 20 45 78 70 72 2a 29 3b 0a 69 (const Expr*);.i
225a0 6e 74 20 73 71 6c 69 74 65 33 45 78 70 72 4e 65 nt sqlite3ExprNe
225b0 65 64 73 4e 6f 41 66 66 69 6e 69 74 79 43 68 61 edsNoAffinityCha
225c0 6e 67 65 28 63 6f 6e 73 74 20 45 78 70 72 2a 2c nge(const Expr*,
225d0 20 63 68 61 72 29 3b 0a 69 6e 74 20 73 71 6c 69 char);.int sqli
225e0 74 65 33 49 73 52 6f 77 69 64 28 63 6f 6e 73 74 te3IsRowid(const
225f0 20 63 68 61 72 2a 29 3b 0a 76 6f 69 64 20 73 71 char*);.void sq
22600 6c 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 lite3GenerateRow
22610 44 65 6c 65 74 65 28 50 61 72 73 65 2a 2c 54 61 Delete(Parse*,Ta
22620 62 6c 65 2a 2c 54 72 69 67 67 65 72 2a 2c 69 6e ble*,Trigger*,in
22630 74 2c 69 6e 74 2c 69 6e 74 2c 69 31 36 2c 75 38 t,int,int,i16,u8
22640 2c 75 38 2c 75 38 29 3b 0a 76 6f 69 64 20 73 71 ,u8,u8);.void sq
22650 6c 69 74 65 33 47 65 6e 65 72 61 74 65 52 6f 77 lite3GenerateRow
22660 49 6e 64 65 78 44 65 6c 65 74 65 28 50 61 72 73 IndexDelete(Pars
22670 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 2c e*, Table*, int,
22680 20 69 6e 74 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 int, int*);.int
22690 20 73 71 6c 69 74 65 33 47 65 6e 65 72 61 74 65 sqlite3Generate
226a0 49 6e 64 65 78 4b 65 79 28 50 61 72 73 65 2a 2c IndexKey(Parse*,
226b0 20 49 6e 64 65 78 2a 2c 20 69 6e 74 2c 20 69 6e Index*, int, in
226c0 74 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 49 6e 64 t, int, int*,Ind
226d0 65 78 2a 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 ex*,int);.void s
226e0 71 6c 69 74 65 33 52 65 73 6f 6c 76 65 50 61 72 qlite3ResolvePar
226f0 74 49 64 78 4c 61 62 65 6c 28 50 61 72 73 65 2a tIdxLabel(Parse*
22700 2c 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ,int);.void sqli
22710 74 65 33 47 65 6e 65 72 61 74 65 43 6f 6e 73 74 te3GenerateConst
22720 72 61 69 6e 74 43 68 65 63 6b 73 28 50 61 72 73 raintChecks(Pars
22730 65 2a 2c 54 61 62 6c 65 2a 2c 69 6e 74 2a 2c 69 e*,Table*,int*,i
22740 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 0a nt,int,int,int,.
22750 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22760 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22770 20 20 20 20 20 75 38 2c 75 38 2c 69 6e 74 2c 69 u8,u8,int,i
22780 6e 74 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 nt*);.void sqlit
22790 65 33 43 6f 6d 70 6c 65 74 65 49 6e 73 65 72 74 e3CompleteInsert
227a0 69 6f 6e 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 ion(Parse*,Table
227b0 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 2c 69 6e *,int,int,int,in
227c0 74 2a 2c 69 6e 74 2c 69 6e 74 2c 69 6e 74 29 3b t*,int,int,int);
227d0 0a 69 6e 74 20 73 71 6c 69 74 65 33 4f 70 65 6e .int sqlite3Open
227e0 54 61 62 6c 65 41 6e 64 49 6e 64 69 63 65 73 28 TableAndIndices(
227f0 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 Parse*, Table*,
22800 69 6e 74 2c 20 69 6e 74 2c 20 75 38 2a 2c 20 69 int, int, u8*, i
22810 6e 74 2a 2c 20 69 6e 74 2a 29 3b 0a 76 6f 69 64 nt*, int*);.void
22820 20 73 71 6c 69 74 65 33 42 65 67 69 6e 57 72 69 sqlite3BeginWri
22830 74 65 4f 70 65 72 61 74 69 6f 6e 28 50 61 72 73 teOperation(Pars
22840 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 e*, int, int);.v
22850 6f 69 64 20 73 71 6c 69 74 65 33 4d 75 6c 74 69 oid sqlite3Multi
22860 57 72 69 74 65 28 50 61 72 73 65 2a 29 3b 0a 76 Write(Parse*);.v
22870 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 79 41 62 oid sqlite3MayAb
22880 6f 72 74 28 50 61 72 73 65 2a 29 3b 0a 76 6f 69 ort(Parse*);.voi
22890 64 20 73 71 6c 69 74 65 33 48 61 6c 74 43 6f 6e d sqlite3HaltCon
228a0 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 straint(Parse*,
228b0 69 6e 74 2c 20 69 6e 74 2c 20 63 68 61 72 2a 2c int, int, char*,
228c0 20 69 38 2c 20 75 38 29 3b 0a 76 6f 69 64 20 73 i8, u8);.void s
228d0 71 6c 69 74 65 33 55 6e 69 71 75 65 43 6f 6e 73 qlite3UniqueCons
228e0 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c 20 69 traint(Parse*, i
228f0 6e 74 2c 20 49 6e 64 65 78 2a 29 3b 0a 76 6f 69 nt, Index*);.voi
22900 64 20 73 71 6c 69 74 65 33 52 6f 77 69 64 43 6f d sqlite3RowidCo
22910 6e 73 74 72 61 69 6e 74 28 50 61 72 73 65 2a 2c nstraint(Parse*,
22920 20 69 6e 74 2c 20 54 61 62 6c 65 2a 29 3b 0a 45 int, Table*);.E
22930 78 70 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 xpr *sqlite3Expr
22940 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 Dup(sqlite3*,Exp
22950 72 2a 2c 69 6e 74 29 3b 0a 45 78 70 72 4c 69 73 r*,int);.ExprLis
22960 74 20 2a 73 71 6c 69 74 65 33 45 78 70 72 4c 69 t *sqlite3ExprLi
22970 73 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c 45 stDup(sqlite3*,E
22980 78 70 72 4c 69 73 74 2a 2c 69 6e 74 29 3b 0a 53 xprList*,int);.S
22990 72 63 4c 69 73 74 20 2a 73 71 6c 69 74 65 33 53 rcList *sqlite3S
229a0 72 63 4c 69 73 74 44 75 70 28 73 71 6c 69 74 65 rcListDup(sqlite
229b0 33 2a 2c 53 72 63 4c 69 73 74 2a 2c 69 6e 74 29 3*,SrcList*,int)
229c0 3b 0a 49 64 4c 69 73 74 20 2a 73 71 6c 69 74 65 ;.IdList *sqlite
229d0 33 49 64 4c 69 73 74 44 75 70 28 73 71 6c 69 74 3IdListDup(sqlit
229e0 65 33 2a 2c 49 64 4c 69 73 74 2a 29 3b 0a 53 65 e3*,IdList*);.Se
229f0 6c 65 63 74 20 2a 73 71 6c 69 74 65 33 53 65 6c lect *sqlite3Sel
22a00 65 63 74 44 75 70 28 73 71 6c 69 74 65 33 2a 2c ectDup(sqlite3*,
22a10 53 65 6c 65 63 74 2a 2c 69 6e 74 29 3b 0a 76 6f Select*,int);.vo
22a20 69 64 20 73 71 6c 69 74 65 33 46 75 6e 63 44 65 id sqlite3FuncDe
22a30 66 49 6e 73 65 72 74 28 46 75 6e 63 44 65 66 48 fInsert(FuncDefH
22a40 61 73 68 2a 2c 20 46 75 6e 63 44 65 66 2a 29 3b ash*, FuncDef*);
22a50 0a 46 75 6e 63 44 65 66 20 2a 73 71 6c 69 74 65 .FuncDef *sqlite
22a60 33 46 69 6e 64 46 75 6e 63 74 69 6f 6e 28 73 71 3FindFunction(sq
22a70 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 63 68 61 lite3*,const cha
22a80 72 2a 2c 69 6e 74 2c 69 6e 74 2c 75 38 2c 75 38 r*,int,int,u8,u8
22a90 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
22aa0 65 67 69 73 74 65 72 42 75 69 6c 74 69 6e 46 75 egisterBuiltinFu
22ab0 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a nctions(sqlite3*
22ac0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
22ad0 65 67 69 73 74 65 72 44 61 74 65 54 69 6d 65 46 egisterDateTimeF
22ae0 75 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a unctions(void);.
22af0 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 67 69 void sqlite3Regi
22b00 73 74 65 72 47 6c 6f 62 61 6c 46 75 6e 63 74 69 sterGlobalFuncti
22b10 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 6e 74 20 73 ons(void);.int s
22b20 71 6c 69 74 65 33 53 61 66 65 74 79 43 68 65 63 qlite3SafetyChec
22b30 6b 4f 6b 28 73 71 6c 69 74 65 33 2a 29 3b 0a 69 kOk(sqlite3*);.i
22b40 6e 74 20 73 71 6c 69 74 65 33 53 61 66 65 74 79 nt sqlite3Safety
22b50 43 68 65 63 6b 53 69 63 6b 4f 72 4f 6b 28 73 71 CheckSickOrOk(sq
22b60 6c 69 74 65 33 2a 29 3b 0a 76 6f 69 64 20 73 71 lite3*);.void sq
22b70 6c 69 74 65 33 43 68 61 6e 67 65 43 6f 6f 6b 69 lite3ChangeCooki
22b80 65 28 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a e(Parse*, int);.
22b90 0a 23 69 66 20 21 64 65 66 69 6e 65 64 28 53 51 .#if !defined(SQ
22ba0 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 45 57 29 20 LITE_OMIT_VIEW)
22bb0 26 26 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 && !defined(SQLI
22bc0 54 45 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 TE_OMIT_TRIGGER)
22bd0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 61 74 .void sqlite3Mat
22be0 65 72 69 61 6c 69 7a 65 56 69 65 77 28 50 61 72 erializeView(Par
22bf0 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 45 78 70 se*, Table*, Exp
22c00 72 2a 2c 20 69 6e 74 29 3b 0a 23 65 6e 64 69 66 r*, int);.#endif
22c10 0a 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ..#ifndef SQLITE
22c20 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 0a 20 20 _OMIT_TRIGGER.
22c30 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 67 69 void sqlite3Begi
22c40 6e 54 72 69 67 67 65 72 28 50 61 72 73 65 2a 2c nTrigger(Parse*,
22c50 20 54 6f 6b 65 6e 2a 2c 54 6f 6b 65 6e 2a 2c 69 Token*,Token*,i
22c60 6e 74 2c 69 6e 74 2c 49 64 4c 69 73 74 2a 2c 53 nt,int,IdList*,S
22c70 72 63 4c 69 73 74 2a 2c 0a 20 20 20 20 20 20 20 rcList*,.
22c80 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22c90 20 20 20 20 45 78 70 72 2a 2c 69 6e 74 2c 20 69 Expr*,int, i
22ca0 6e 74 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 nt);. void sqli
22cb0 74 65 33 46 69 6e 69 73 68 54 72 69 67 67 65 72 te3FinishTrigger
22cc0 28 50 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 (Parse*, Trigger
22cd0 53 74 65 70 2a 2c 20 54 6f 6b 65 6e 2a 29 3b 0a Step*, Token*);.
22ce0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 44 72 void sqlite3Dr
22cf0 6f 70 54 72 69 67 67 65 72 28 50 61 72 73 65 2a opTrigger(Parse*
22d00 2c 20 53 72 63 4c 69 73 74 2a 2c 20 69 6e 74 29 , SrcList*, int)
22d10 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
22d20 44 72 6f 70 54 72 69 67 67 65 72 50 74 72 28 50 DropTriggerPtr(P
22d30 61 72 73 65 2a 2c 20 54 72 69 67 67 65 72 2a 29 arse*, Trigger*)
22d40 3b 0a 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c ;. Trigger *sql
22d50 69 74 65 33 54 72 69 67 67 65 72 73 45 78 69 73 ite3TriggersExis
22d60 74 28 50 61 72 73 65 20 2a 2c 20 54 61 62 6c 65 t(Parse *, Table
22d70 2a 2c 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 *, int, ExprList
22d80 2a 2c 20 69 6e 74 20 2a 70 4d 61 73 6b 29 3b 0a *, int *pMask);.
22d90 20 20 54 72 69 67 67 65 72 20 2a 73 71 6c 69 74 Trigger *sqlit
22da0 65 33 54 72 69 67 67 65 72 4c 69 73 74 28 50 61 e3TriggerList(Pa
22db0 72 73 65 20 2a 2c 20 54 61 62 6c 65 20 2a 29 3b rse *, Table *);
22dc0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 43 . void sqlite3C
22dd0 6f 64 65 52 6f 77 54 72 69 67 67 65 72 28 50 61 odeRowTrigger(Pa
22de0 72 73 65 2a 2c 20 54 72 69 67 67 65 72 20 2a 2c rse*, Trigger *,
22df0 20 69 6e 74 2c 20 45 78 70 72 4c 69 73 74 2a 2c int, ExprList*,
22e00 20 69 6e 74 2c 20 54 61 62 6c 65 20 2a 2c 0a 20 int, Table *,.
22e10 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22e20 20 20 20 20 20 20 20 20 20 20 20 69 6e 74 2c 20 int,
22e30 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
22e40 64 20 73 71 6c 69 74 65 33 43 6f 64 65 52 6f 77 d sqlite3CodeRow
22e50 54 72 69 67 67 65 72 44 69 72 65 63 74 28 50 61 TriggerDirect(Pa
22e60 72 73 65 20 2a 2c 20 54 72 69 67 67 65 72 20 2a rse *, Trigger *
22e70 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c 20 , Table *, int,
22e80 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 int, int);. voi
22e90 64 20 73 71 6c 69 74 65 56 69 65 77 54 72 69 67 d sqliteViewTrig
22ea0 67 65 72 73 28 50 61 72 73 65 2a 2c 20 54 61 62 gers(Parse*, Tab
22eb0 6c 65 2a 2c 20 45 78 70 72 2a 2c 20 69 6e 74 2c le*, Expr*, int,
22ec0 20 45 78 70 72 4c 69 73 74 2a 29 3b 0a 20 20 76 ExprList*);. v
22ed0 6f 69 64 20 73 71 6c 69 74 65 33 44 65 6c 65 74 oid sqlite3Delet
22ee0 65 54 72 69 67 67 65 72 53 74 65 70 28 73 71 6c eTriggerStep(sql
22ef0 69 74 65 33 2a 2c 20 54 72 69 67 67 65 72 53 74 ite3*, TriggerSt
22f00 65 70 2a 29 3b 0a 20 20 54 72 69 67 67 65 72 53 ep*);. TriggerS
22f10 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 67 tep *sqlite3Trig
22f20 67 65 72 53 65 6c 65 63 74 53 74 65 70 28 73 71 gerSelectStep(sq
22f30 6c 69 74 65 33 2a 2c 53 65 6c 65 63 74 2a 29 3b lite3*,Select*);
22f40 0a 20 20 54 72 69 67 67 65 72 53 74 65 70 20 2a . TriggerStep *
22f50 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 49 6e sqlite3TriggerIn
22f60 73 65 72 74 53 74 65 70 28 73 71 6c 69 74 65 33 sertStep(sqlite3
22f70 2a 2c 54 6f 6b 65 6e 2a 2c 20 49 64 4c 69 73 74 *,Token*, IdList
22f80 2a 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 *,.
22f90 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
22fa0 20 20 20 20 20 20 20 20 20 20 20 53 65 6c 65 63 Selec
22fb0 74 2a 2c 75 38 29 3b 0a 20 20 54 72 69 67 67 65 t*,u8);. Trigge
22fc0 72 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 rStep *sqlite3Tr
22fd0 69 67 67 65 72 55 70 64 61 74 65 53 74 65 70 28 iggerUpdateStep(
22fe0 73 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c sqlite3*,Token*,
22ff0 45 78 70 72 4c 69 73 74 2a 2c 20 45 78 70 72 2a ExprList*, Expr*
23000 2c 20 75 38 29 3b 0a 20 20 54 72 69 67 67 65 72 , u8);. Trigger
23010 53 74 65 70 20 2a 73 71 6c 69 74 65 33 54 72 69 Step *sqlite3Tri
23020 67 67 65 72 44 65 6c 65 74 65 53 74 65 70 28 73 ggerDeleteStep(s
23030 71 6c 69 74 65 33 2a 2c 54 6f 6b 65 6e 2a 2c 20 qlite3*,Token*,
23040 45 78 70 72 2a 29 3b 0a 20 20 76 6f 69 64 20 73 Expr*);. void s
23050 71 6c 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 qlite3DeleteTrig
23060 67 65 72 28 73 71 6c 69 74 65 33 2a 2c 20 54 72 ger(sqlite3*, Tr
23070 69 67 67 65 72 2a 29 3b 0a 20 20 76 6f 69 64 20 igger*);. void
23080 73 71 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 sqlite3UnlinkAnd
23090 44 65 6c 65 74 65 54 72 69 67 67 65 72 28 73 71 DeleteTrigger(sq
230a0 6c 69 74 65 33 2a 2c 69 6e 74 2c 63 6f 6e 73 74 lite3*,int,const
230b0 20 63 68 61 72 2a 29 3b 0a 20 20 75 33 32 20 73 char*);. u32 s
230c0 71 6c 69 74 65 33 54 72 69 67 67 65 72 43 6f 6c qlite3TriggerCol
230d0 6d 61 73 6b 28 50 61 72 73 65 2a 2c 54 72 69 67 mask(Parse*,Trig
230e0 67 65 72 2a 2c 45 78 70 72 4c 69 73 74 2a 2c 69 ger*,ExprList*,i
230f0 6e 74 2c 69 6e 74 2c 54 61 62 6c 65 2a 2c 69 6e nt,int,Table*,in
23100 74 29 3b 0a 23 20 64 65 66 69 6e 65 20 73 71 6c t);.# define sql
23110 69 74 65 33 50 61 72 73 65 54 6f 70 6c 65 76 65 ite3ParseTopleve
23120 6c 28 70 29 20 28 28 70 29 2d 3e 70 54 6f 70 6c l(p) ((p)->pTopl
23130 65 76 65 6c 20 3f 20 28 70 29 2d 3e 70 54 6f 70 evel ? (p)->pTop
23140 6c 65 76 65 6c 20 3a 20 28 70 29 29 0a 23 65 6c level : (p)).#el
23150 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 se.# define sqli
23160 74 65 33 54 72 69 67 67 65 72 73 45 78 69 73 74 te3TriggersExist
23170 28 42 2c 43 2c 44 2c 45 2c 46 29 20 30 0a 23 20 (B,C,D,E,F) 0.#
23180 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 44 65 define sqlite3De
23190 6c 65 74 65 54 72 69 67 67 65 72 28 41 2c 42 29 leteTrigger(A,B)
231a0 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 .# define sqlite
231b0 33 44 72 6f 70 54 72 69 67 67 65 72 50 74 72 28 3DropTriggerPtr(
231c0 41 2c 42 29 0a 23 20 64 65 66 69 6e 65 20 73 71 A,B).# define sq
231d0 6c 69 74 65 33 55 6e 6c 69 6e 6b 41 6e 64 44 65 lite3UnlinkAndDe
231e0 6c 65 74 65 54 72 69 67 67 65 72 28 41 2c 42 2c leteTrigger(A,B,
231f0 43 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 69 C).# define sqli
23200 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 67 65 te3CodeRowTrigge
23210 72 28 41 2c 42 2c 43 2c 44 2c 45 2c 46 2c 47 2c r(A,B,C,D,E,F,G,
23220 48 2c 49 29 0a 23 20 64 65 66 69 6e 65 20 73 71 H,I).# define sq
23230 6c 69 74 65 33 43 6f 64 65 52 6f 77 54 72 69 67 lite3CodeRowTrig
23240 67 65 72 44 69 72 65 63 74 28 41 2c 42 2c 43 2c gerDirect(A,B,C,
23250 44 2c 45 2c 46 29 0a 23 20 64 65 66 69 6e 65 20 D,E,F).# define
23260 73 71 6c 69 74 65 33 54 72 69 67 67 65 72 4c 69 sqlite3TriggerLi
23270 73 74 28 58 2c 20 59 29 20 30 0a 23 20 64 65 66 st(X, Y) 0.# def
23280 69 6e 65 20 73 71 6c 69 74 65 33 50 61 72 73 65 ine sqlite3Parse
23290 54 6f 70 6c 65 76 65 6c 28 70 29 20 70 0a 23 20 Toplevel(p) p.#
232a0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 54 72 define sqlite3Tr
232b0 69 67 67 65 72 43 6f 6c 6d 61 73 6b 28 41 2c 42 iggerColmask(A,B
232c0 2c 43 2c 44 2c 45 2c 46 2c 47 29 20 30 0a 23 65 ,C,D,E,F,G) 0.#e
232d0 6e 64 69 66 0a 0a 69 6e 74 20 73 71 6c 69 74 65 ndif..int sqlite
232e0 33 4a 6f 69 6e 54 79 70 65 28 50 61 72 73 65 2a 3JoinType(Parse*
232f0 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e 2a , Token*, Token*
23300 2c 20 54 6f 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 , Token*);.void
23310 73 71 6c 69 74 65 33 43 72 65 61 74 65 46 6f 72 sqlite3CreateFor
23320 65 69 67 6e 4b 65 79 28 50 61 72 73 65 2a 2c 20 eignKey(Parse*,
23330 45 78 70 72 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e ExprList*, Token
23340 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 69 6e *, ExprList*, in
23350 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 t);.void sqlite3
23360 44 65 66 65 72 46 6f 72 65 69 67 6e 4b 65 79 28 DeferForeignKey(
23370 50 61 72 73 65 2a 2c 20 69 6e 74 29 3b 0a 23 69 Parse*, int);.#i
23380 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
23390 54 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 0a T_AUTHORIZATION.
233a0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 41 75 void sqlite3Au
233b0 74 68 52 65 61 64 28 50 61 72 73 65 2a 2c 45 78 thRead(Parse*,Ex
233c0 70 72 2a 2c 53 63 68 65 6d 61 2a 2c 53 72 63 4c pr*,Schema*,SrcL
233d0 69 73 74 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c ist*);. int sql
233e0 69 74 65 33 41 75 74 68 43 68 65 63 6b 28 50 61 ite3AuthCheck(Pa
233f0 72 73 65 2a 2c 69 6e 74 2c 20 63 6f 6e 73 74 20 rse*,int, const
23400 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 char*, const cha
23410 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 r*, const char*)
23420 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 ;. void sqlite3
23430 41 75 74 68 43 6f 6e 74 65 78 74 50 75 73 68 28 AuthContextPush(
23440 50 61 72 73 65 2a 2c 20 41 75 74 68 43 6f 6e 74 Parse*, AuthCont
23450 65 78 74 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 ext*, const char
23460 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
23470 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 6f 70 e3AuthContextPop
23480 28 41 75 74 68 43 6f 6e 74 65 78 74 2a 29 3b 0a (AuthContext*);.
23490 20 20 69 6e 74 20 73 71 6c 69 74 65 33 41 75 74 int sqlite3Aut
234a0 68 52 65 61 64 43 6f 6c 28 50 61 72 73 65 2a 2c hReadCol(Parse*,
234b0 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 63 const char *, c
234c0 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e 74 onst char *, int
234d0 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e );.#else.# defin
234e0 65 20 73 71 6c 69 74 65 33 41 75 74 68 52 65 61 e sqlite3AuthRea
234f0 64 28 61 2c 62 2c 63 2c 64 29 0a 23 20 64 65 66 d(a,b,c,d).# def
23500 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 68 43 ine sqlite3AuthC
23510 68 65 63 6b 28 61 2c 62 2c 63 2c 64 2c 65 29 20 heck(a,b,c,d,e)
23520 20 20 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 64 SQLITE_OK.# d
23530 65 66 69 6e 65 20 73 71 6c 69 74 65 33 41 75 74 efine sqlite3Aut
23540 68 43 6f 6e 74 65 78 74 50 75 73 68 28 61 2c 62 hContextPush(a,b
23550 2c 63 29 0a 23 20 64 65 66 69 6e 65 20 73 71 6c ,c).# define sql
23560 69 74 65 33 41 75 74 68 43 6f 6e 74 65 78 74 50 ite3AuthContextP
23570 6f 70 28 61 29 20 20 28 28 76 6f 69 64 29 28 61 op(a) ((void)(a
23580 29 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 73 )).#endif.void s
23590 71 6c 69 74 65 33 41 74 74 61 63 68 28 50 61 72 qlite3Attach(Par
235a0 73 65 2a 2c 20 45 78 70 72 2a 2c 20 45 78 70 72 se*, Expr*, Expr
235b0 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f 69 64 20 *, Expr*);.void
235c0 73 71 6c 69 74 65 33 44 65 74 61 63 68 28 50 61 sqlite3Detach(Pa
235d0 72 73 65 2a 2c 20 45 78 70 72 2a 29 3b 0a 76 6f rse*, Expr*);.vo
235e0 69 64 20 73 71 6c 69 74 65 33 46 69 78 49 6e 69 id sqlite3FixIni
235f0 74 28 44 62 46 69 78 65 72 2a 2c 20 50 61 72 73 t(DbFixer*, Pars
23600 65 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 e*, int, const c
23610 68 61 72 2a 2c 20 63 6f 6e 73 74 20 54 6f 6b 65 har*, const Toke
23620 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 n*);.int sqlite3
23630 46 69 78 53 72 63 4c 69 73 74 28 44 62 46 69 78 FixSrcList(DbFix
23640 65 72 2a 2c 20 53 72 63 4c 69 73 74 2a 29 3b 0a er*, SrcList*);.
23650 69 6e 74 20 73 71 6c 69 74 65 33 46 69 78 53 65 int sqlite3FixSe
23660 6c 65 63 74 28 44 62 46 69 78 65 72 2a 2c 20 53 lect(DbFixer*, S
23670 65 6c 65 63 74 2a 29 3b 0a 69 6e 74 20 73 71 6c elect*);.int sql
23680 69 74 65 33 46 69 78 45 78 70 72 28 44 62 46 69 ite3FixExpr(DbFi
23690 78 65 72 2a 2c 20 45 78 70 72 2a 29 3b 0a 69 6e xer*, Expr*);.in
236a0 74 20 73 71 6c 69 74 65 33 46 69 78 45 78 70 72 t sqlite3FixExpr
236b0 4c 69 73 74 28 44 62 46 69 78 65 72 2a 2c 20 45 List(DbFixer*, E
236c0 78 70 72 4c 69 73 74 2a 29 3b 0a 69 6e 74 20 73 xprList*);.int s
236d0 71 6c 69 74 65 33 46 69 78 54 72 69 67 67 65 72 qlite3FixTrigger
236e0 53 74 65 70 28 44 62 46 69 78 65 72 2a 2c 20 54 Step(DbFixer*, T
236f0 72 69 67 67 65 72 53 74 65 70 2a 29 3b 0a 69 6e riggerStep*);.in
23700 74 20 73 71 6c 69 74 65 33 41 74 6f 46 28 63 6f t sqlite3AtoF(co
23710 6e 73 74 20 63 68 61 72 20 2a 7a 2c 20 64 6f 75 nst char *z, dou
23720 62 6c 65 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a ble*, int, u8);.
23730 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 49 6e int sqlite3GetIn
23740 74 33 32 28 63 6f 6e 73 74 20 63 68 61 72 20 2a t32(const char *
23750 2c 20 69 6e 74 2a 29 3b 0a 69 6e 74 20 73 71 6c , int*);.int sql
23760 69 74 65 33 41 74 6f 69 28 63 6f 6e 73 74 20 63 ite3Atoi(const c
23770 68 61 72 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 har*);.int sqlit
23780 65 33 55 74 66 31 36 42 79 74 65 4c 65 6e 28 63 e3Utf16ByteLen(c
23790 6f 6e 73 74 20 76 6f 69 64 20 2a 70 44 61 74 61 onst void *pData
237a0 2c 20 69 6e 74 20 6e 43 68 61 72 29 3b 0a 69 6e , int nChar);.in
237b0 74 20 73 71 6c 69 74 65 33 55 74 66 38 43 68 61 t sqlite3Utf8Cha
237c0 72 4c 65 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 rLen(const char
237d0 2a 70 44 61 74 61 2c 20 69 6e 74 20 6e 42 79 74 *pData, int nByt
237e0 65 29 3b 0a 75 33 32 20 73 71 6c 69 74 65 33 55 e);.u32 sqlite3U
237f0 74 66 38 52 65 61 64 28 63 6f 6e 73 74 20 75 38 tf8Read(const u8
23800 2a 2a 29 3b 0a 4c 6f 67 45 73 74 20 73 71 6c 69 **);.LogEst sqli
23810 74 65 33 4c 6f 67 45 73 74 28 75 36 34 29 3b 0a te3LogEst(u64);.
23820 4c 6f 67 45 73 74 20 73 71 6c 69 74 65 33 4c 6f LogEst sqlite3Lo
23830 67 45 73 74 41 64 64 28 4c 6f 67 45 73 74 2c 4c gEstAdd(LogEst,L
23840 6f 67 45 73 74 29 3b 0a 23 69 66 6e 64 65 66 20 ogEst);.#ifndef
23850 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 SQLITE_OMIT_VIRT
23860 55 41 4c 54 41 42 4c 45 0a 4c 6f 67 45 73 74 20 UALTABLE.LogEst
23870 73 71 6c 69 74 65 33 4c 6f 67 45 73 74 46 72 6f sqlite3LogEstFro
23880 6d 44 6f 75 62 6c 65 28 64 6f 75 62 6c 65 29 3b mDouble(double);
23890 0a 23 65 6e 64 69 66 0a 75 36 34 20 73 71 6c 69 .#endif.u64 sqli
238a0 74 65 33 4c 6f 67 45 73 74 54 6f 49 6e 74 28 4c te3LogEstToInt(L
238b0 6f 67 45 73 74 29 3b 0a 0a 2f 2a 0a 2a 2a 20 52 ogEst);../*.** R
238c0 6f 75 74 69 6e 65 73 20 74 6f 20 72 65 61 64 20 outines to read
238d0 61 6e 64 20 77 72 69 74 65 20 76 61 72 69 61 62 and write variab
238e0 6c 65 2d 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 le-length intege
238f0 72 73 2e 20 20 54 68 65 73 65 20 75 73 65 64 20 rs. These used
23900 74 6f 0a 2a 2a 20 62 65 20 64 65 66 69 6e 65 64 to.** be defined
23910 20 6c 6f 63 61 6c 6c 79 2c 20 62 75 74 20 6e 6f locally, but no
23920 77 20 77 65 20 75 73 65 20 74 68 65 20 76 61 72 w we use the var
23930 69 6e 74 20 72 6f 75 74 69 6e 65 73 20 69 6e 20 int routines in
23940 74 68 65 20 75 74 69 6c 2e 63 0a 2a 2a 20 66 69 the util.c.** fi
23950 6c 65 2e 20 20 43 6f 64 65 20 73 68 6f 75 6c 64 le. Code should
23960 20 75 73 65 20 74 68 65 20 4d 41 43 52 4f 20 66 use the MACRO f
23970 6f 72 6d 73 20 62 65 6c 6f 77 2c 20 61 73 20 74 orms below, as t
23980 68 65 20 56 61 72 69 6e 74 33 32 20 76 65 72 73 he Varint32 vers
23990 69 6f 6e 73 0a 2a 2a 20 61 72 65 20 63 6f 64 65 ions.** are code
239a0 64 20 74 6f 20 61 73 73 75 6d 65 20 74 68 65 20 d to assume the
239b0 73 69 6e 67 6c 65 20 62 79 74 65 20 63 61 73 65 single byte case
239c0 20 69 73 20 61 6c 72 65 61 64 79 20 68 61 6e 64 is already hand
239d0 6c 65 64 20 28 77 68 69 63 68 20 0a 2a 2a 20 74 led (which .** t
239e0 68 65 20 4d 41 43 52 4f 20 66 6f 72 6d 20 64 6f he MACRO form do
239f0 65 73 29 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 es)..*/.int sqli
23a00 74 65 33 50 75 74 56 61 72 69 6e 74 28 75 6e 73 te3PutVarint(uns
23a10 69 67 6e 65 64 20 63 68 61 72 2a 2c 20 75 36 34 igned char*, u64
23a20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 50 75 );.int sqlite3Pu
23a30 74 56 61 72 69 6e 74 33 32 28 75 6e 73 69 67 6e tVarint32(unsign
23a40 65 64 20 63 68 61 72 2a 2c 20 75 33 32 29 3b 0a ed char*, u32);.
23a50 75 38 20 73 71 6c 69 74 65 33 47 65 74 56 61 72 u8 sqlite3GetVar
23a60 69 6e 74 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e int(const unsign
23a70 65 64 20 63 68 61 72 20 2a 2c 20 75 36 34 20 2a ed char *, u64 *
23a80 29 3b 0a 75 38 20 73 71 6c 69 74 65 33 47 65 74 );.u8 sqlite3Get
23a90 56 61 72 69 6e 74 33 32 28 63 6f 6e 73 74 20 75 Varint32(const u
23aa0 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 2c 20 nsigned char *,
23ab0 75 33 32 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 u32 *);.int sqli
23ac0 74 65 33 56 61 72 69 6e 74 4c 65 6e 28 75 36 34 te3VarintLen(u64
23ad0 20 76 29 3b 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 v);../*.** The
23ae0 68 65 61 64 65 72 20 6f 66 20 61 20 72 65 63 6f header of a reco
23af0 72 64 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 rd consists of a
23b00 20 73 65 71 75 65 6e 63 65 20 76 61 72 69 61 62 sequence variab
23b10 6c 65 2d 6c 65 6e 67 74 68 20 69 6e 74 65 67 65 le-length intege
23b20 72 73 2e 0a 2a 2a 20 54 68 65 73 65 20 69 6e 74 rs..** These int
23b30 65 67 65 72 73 20 61 72 65 20 61 6c 6d 6f 73 74 egers are almost
23b40 20 61 6c 77 61 79 73 20 73 6d 61 6c 6c 20 61 6e always small an
23b50 64 20 61 72 65 20 65 6e 63 6f 64 65 64 20 61 73 d are encoded as
23b60 20 61 20 73 69 6e 67 6c 65 20 62 79 74 65 2e 0a a single byte..
23b70 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 ** The following
23b80 20 6d 61 63 72 6f 73 20 74 61 6b 65 20 61 64 76 macros take adv
23b90 61 6e 74 61 67 65 20 74 68 69 73 20 66 61 63 74 antage this fact
23ba0 20 74 6f 20 70 72 6f 76 69 64 65 20 61 20 66 61 to provide a fa
23bb0 73 74 20 65 6e 63 6f 64 65 0a 2a 2a 20 61 6e 64 st encode.** and
23bc0 20 64 65 63 6f 64 65 20 6f 66 20 74 68 65 20 69 decode of the i
23bd0 6e 74 65 67 65 72 73 20 69 6e 20 61 20 72 65 63 ntegers in a rec
23be0 6f 72 64 20 68 65 61 64 65 72 2e 20 20 49 74 20 ord header. It
23bf0 69 73 20 66 61 73 74 65 72 20 66 6f 72 20 74 68 is faster for th
23c00 65 20 63 6f 6d 6d 6f 6e 0a 2a 2a 20 63 61 73 65 e common.** case
23c10 20 77 68 65 72 65 20 74 68 65 20 69 6e 74 65 67 where the integ
23c20 65 72 20 69 73 20 61 20 73 69 6e 67 6c 65 20 62 er is a single b
23c30 79 74 65 2e 20 20 49 74 20 69 73 20 61 20 6c 69 yte. It is a li
23c40 74 74 6c 65 20 73 6c 6f 77 65 72 20 77 68 65 6e ttle slower when
23c50 20 74 68 65 0a 2a 2a 20 69 6e 74 65 67 65 72 20 the.** integer
23c60 69 73 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 62 is two or more b
23c70 79 74 65 73 2e 20 20 42 75 74 20 6f 76 65 72 61 ytes. But overa
23c80 6c 6c 20 69 74 20 69 73 20 66 61 73 74 65 72 2e ll it is faster.
23c90 0a 2a 2a 0a 2a 2a 20 54 68 65 20 66 6f 6c 6c 6f .**.** The follo
23ca0 77 69 6e 67 20 65 78 70 72 65 73 73 69 6f 6e 73 wing expressions
23cb0 20 61 72 65 20 65 71 75 69 76 61 6c 65 6e 74 3a are equivalent:
23cc0 0a 2a 2a 0a 2a 2a 20 20 20 20 20 78 20 3d 20 73 .**.** x = s
23cd0 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 33 qlite3GetVarint3
23ce0 32 28 20 41 2c 20 26 42 20 29 3b 0a 2a 2a 20 20 2( A, &B );.**
23cf0 20 20 20 78 20 3d 20 73 71 6c 69 74 65 33 50 75 x = sqlite3Pu
23d00 74 56 61 72 69 6e 74 33 32 28 20 41 2c 20 42 20 tVarint32( A, B
23d10 29 3b 0a 2a 2a 0a 2a 2a 20 20 20 20 20 78 20 3d );.**.** x =
23d20 20 67 65 74 56 61 72 69 6e 74 33 32 28 20 41 2c getVarint32( A,
23d30 20 42 20 29 3b 0a 2a 2a 20 20 20 20 20 78 20 3d B );.** x =
23d40 20 70 75 74 56 61 72 69 6e 74 33 32 28 20 41 2c putVarint32( A,
23d50 20 42 20 29 3b 0a 2a 2a 0a 2a 2f 0a 23 64 65 66 B );.**.*/.#def
23d60 69 6e 65 20 67 65 74 56 61 72 69 6e 74 33 32 28 ine getVarint32(
23d70 41 2c 42 29 20 20 5c 0a 20 20 28 75 38 29 28 28 A,B) \. (u8)((
23d80 2a 28 41 29 3c 28 75 38 29 30 78 38 30 29 3f 28 *(A)<(u8)0x80)?(
23d90 28 42 29 3d 28 75 33 32 29 2a 28 41 29 29 2c 31 (B)=(u32)*(A)),1
23da0 3a 73 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e :sqlite3GetVarin
23db0 74 33 32 28 28 41 29 2c 28 75 33 32 20 2a 29 26 t32((A),(u32 *)&
23dc0 28 42 29 29 29 0a 23 64 65 66 69 6e 65 20 70 75 (B))).#define pu
23dd0 74 56 61 72 69 6e 74 33 32 28 41 2c 42 29 20 20 tVarint32(A,B)
23de0 5c 0a 20 20 28 75 38 29 28 28 28 75 33 32 29 28 \. (u8)(((u32)(
23df0 42 29 3c 28 75 33 32 29 30 78 38 30 29 3f 28 2a B)<(u32)0x80)?(*
23e00 28 41 29 3d 28 75 6e 73 69 67 6e 65 64 20 63 68 (A)=(unsigned ch
23e10 61 72 29 28 42 29 29 2c 31 3a 5c 0a 20 20 73 71 ar)(B)),1:\. sq
23e20 6c 69 74 65 33 50 75 74 56 61 72 69 6e 74 33 32 lite3PutVarint32
23e30 28 28 41 29 2c 28 42 29 29 29 0a 23 64 65 66 69 ((A),(B))).#defi
23e40 6e 65 20 67 65 74 56 61 72 69 6e 74 20 20 20 20 ne getVarint
23e50 73 71 6c 69 74 65 33 47 65 74 56 61 72 69 6e 74 sqlite3GetVarint
23e60 0a 23 64 65 66 69 6e 65 20 70 75 74 56 61 72 69 .#define putVari
23e70 6e 74 20 20 20 20 73 71 6c 69 74 65 33 50 75 74 nt sqlite3Put
23e80 56 61 72 69 6e 74 0a 0a 0a 63 6f 6e 73 74 20 63 Varint...const c
23e90 68 61 72 20 2a 73 71 6c 69 74 65 33 49 6e 64 65 har *sqlite3Inde
23ea0 78 41 66 66 69 6e 69 74 79 53 74 72 28 56 64 62 xAffinityStr(Vdb
23eb0 65 20 2a 2c 20 49 6e 64 65 78 20 2a 29 3b 0a 76 e *, Index *);.v
23ec0 6f 69 64 20 73 71 6c 69 74 65 33 54 61 62 6c 65 oid sqlite3Table
23ed0 41 66 66 69 6e 69 74 79 28 56 64 62 65 2a 2c 20 Affinity(Vdbe*,
23ee0 54 61 62 6c 65 2a 2c 20 69 6e 74 29 3b 0a 63 68 Table*, int);.ch
23ef0 61 72 20 73 71 6c 69 74 65 33 43 6f 6d 70 61 72 ar sqlite3Compar
23f00 65 41 66 66 69 6e 69 74 79 28 45 78 70 72 20 2a eAffinity(Expr *
23f10 70 45 78 70 72 2c 20 63 68 61 72 20 61 66 66 32 pExpr, char aff2
23f20 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 6e );.int sqlite3In
23f30 64 65 78 41 66 66 69 6e 69 74 79 4f 6b 28 45 78 dexAffinityOk(Ex
23f40 70 72 20 2a 70 45 78 70 72 2c 20 63 68 61 72 20 pr *pExpr, char
23f50 69 64 78 5f 61 66 66 69 6e 69 74 79 29 3b 0a 63 idx_affinity);.c
23f60 68 61 72 20 73 71 6c 69 74 65 33 45 78 70 72 41 har sqlite3ExprA
23f70 66 66 69 6e 69 74 79 28 45 78 70 72 20 2a 70 45 ffinity(Expr *pE
23f80 78 70 72 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 xpr);.int sqlite
23f90 33 41 74 6f 69 36 34 28 63 6f 6e 73 74 20 63 68 3Atoi64(const ch
23fa0 61 72 2a 2c 20 69 36 34 2a 2c 20 69 6e 74 2c 20 ar*, i64*, int,
23fb0 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 u8);.int sqlite3
23fc0 44 65 63 4f 72 48 65 78 54 6f 49 36 34 28 63 6f DecOrHexToI64(co
23fd0 6e 73 74 20 63 68 61 72 2a 2c 20 69 36 34 2a 29 nst char*, i64*)
23fe0 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 45 72 ;.void sqlite3Er
23ff0 72 6f 72 28 73 71 6c 69 74 65 33 2a 2c 20 69 6e ror(sqlite3*, in
24000 74 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c 2e t, const char*,.
24010 2e 2e 29 3b 0a 76 6f 69 64 20 2a 73 71 6c 69 74 ..);.void *sqlit
24020 65 33 48 65 78 54 6f 42 6c 6f 62 28 73 71 6c 69 e3HexToBlob(sqli
24030 74 65 33 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 te3*, const char
24040 20 2a 7a 2c 20 69 6e 74 20 6e 29 3b 0a 75 38 20 *z, int n);.u8
24050 73 71 6c 69 74 65 33 48 65 78 54 6f 49 6e 74 28 sqlite3HexToInt(
24060 69 6e 74 20 68 29 3b 0a 69 6e 74 20 73 71 6c 69 int h);.int sqli
24070 74 65 33 54 77 6f 50 61 72 74 4e 61 6d 65 28 50 te3TwoPartName(P
24080 61 72 73 65 20 2a 2c 20 54 6f 6b 65 6e 20 2a 2c arse *, Token *,
24090 20 54 6f 6b 65 6e 20 2a 2c 20 54 6f 6b 65 6e 20 Token *, Token
240a0 2a 2a 29 3b 0a 0a 23 69 66 20 64 65 66 69 6e 65 **);..#if define
240b0 64 28 53 51 4c 49 54 45 5f 54 45 53 54 29 20 0a d(SQLITE_TEST) .
240c0 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 69 const char *sqli
240d0 74 65 33 45 72 72 4e 61 6d 65 28 69 6e 74 29 3b te3ErrName(int);
240e0 0a 23 65 6e 64 69 66 0a 0a 63 6f 6e 73 74 20 63 .#endif..const c
240f0 68 61 72 20 2a 73 71 6c 69 74 65 33 45 72 72 53 har *sqlite3ErrS
24100 74 72 28 69 6e 74 29 3b 0a 69 6e 74 20 73 71 6c tr(int);.int sql
24110 69 74 65 33 52 65 61 64 53 63 68 65 6d 61 28 50 ite3ReadSchema(P
24120 61 72 73 65 20 2a 70 50 61 72 73 65 29 3b 0a 43 arse *pParse);.C
24130 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 46 ollSeq *sqlite3F
24140 69 6e 64 43 6f 6c 6c 53 65 71 28 73 71 6c 69 74 indCollSeq(sqlit
24150 65 33 2a 2c 75 38 20 65 6e 63 2c 20 63 6f 6e 73 e3*,u8 enc, cons
24160 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 43 6f t char*,int);.Co
24170 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 4c 6f llSeq *sqlite3Lo
24180 63 61 74 65 43 6f 6c 6c 53 65 71 28 50 61 72 73 cateCollSeq(Pars
24190 65 20 2a 70 50 61 72 73 65 2c 20 63 6f 6e 73 74 e *pParse, const
241a0 20 63 68 61 72 2a 7a 4e 61 6d 65 29 3b 0a 43 6f char*zName);.Co
241b0 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 45 78 llSeq *sqlite3Ex
241c0 70 72 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 prCollSeq(Parse
241d0 2a 70 50 61 72 73 65 2c 20 45 78 70 72 20 2a 70 *pParse, Expr *p
241e0 45 78 70 72 29 3b 0a 45 78 70 72 20 2a 73 71 6c Expr);.Expr *sql
241f0 69 74 65 33 45 78 70 72 41 64 64 43 6f 6c 6c 61 ite3ExprAddColla
24200 74 65 54 6f 6b 65 6e 28 50 61 72 73 65 20 2a 70 teToken(Parse *p
24210 50 61 72 73 65 2c 20 45 78 70 72 2a 2c 20 63 6f Parse, Expr*, co
24220 6e 73 74 20 54 6f 6b 65 6e 2a 29 3b 0a 45 78 70 nst Token*);.Exp
24230 72 20 2a 73 71 6c 69 74 65 33 45 78 70 72 41 64 r *sqlite3ExprAd
24240 64 43 6f 6c 6c 61 74 65 53 74 72 69 6e 67 28 50 dCollateString(P
24250 61 72 73 65 2a 2c 45 78 70 72 2a 2c 63 6f 6e 73 arse*,Expr*,cons
24260 74 20 63 68 61 72 2a 29 3b 0a 45 78 70 72 20 2a t char*);.Expr *
24270 73 71 6c 69 74 65 33 45 78 70 72 53 6b 69 70 43 sqlite3ExprSkipC
24280 6f 6c 6c 61 74 65 28 45 78 70 72 2a 29 3b 0a 69 ollate(Expr*);.i
24290 6e 74 20 73 71 6c 69 74 65 33 43 68 65 63 6b 43 nt sqlite3CheckC
242a0 6f 6c 6c 53 65 71 28 50 61 72 73 65 20 2a 2c 20 ollSeq(Parse *,
242b0 43 6f 6c 6c 53 65 71 20 2a 29 3b 0a 69 6e 74 20 CollSeq *);.int
242c0 73 71 6c 69 74 65 33 43 68 65 63 6b 4f 62 6a 65 sqlite3CheckObje
242d0 63 74 4e 61 6d 65 28 50 61 72 73 65 20 2a 2c 20 ctName(Parse *,
242e0 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 76 const char *);.v
242f0 6f 69 64 20 73 71 6c 69 74 65 33 56 64 62 65 53 oid sqlite3VdbeS
24300 65 74 43 68 61 6e 67 65 73 28 73 71 6c 69 74 65 etChanges(sqlite
24310 33 20 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 3 *, int);.int s
24320 71 6c 69 74 65 33 41 64 64 49 6e 74 36 34 28 69 qlite3AddInt64(i
24330 36 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 64*,i64);.int sq
24340 6c 69 74 65 33 53 75 62 49 6e 74 36 34 28 69 36 lite3SubInt64(i6
24350 34 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 4*,i64);.int sql
24360 69 74 65 33 4d 75 6c 49 6e 74 36 34 28 69 36 34 ite3MulInt64(i64
24370 2a 2c 69 36 34 29 3b 0a 69 6e 74 20 73 71 6c 69 *,i64);.int sqli
24380 74 65 33 41 62 73 49 6e 74 33 32 28 69 6e 74 29 te3AbsInt32(int)
24390 3b 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 5f ;.#ifdef SQLITE_
243a0 45 4e 41 42 4c 45 5f 38 5f 33 5f 4e 41 4d 45 53 ENABLE_8_3_NAMES
243b0 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 46 69 6c .void sqlite3Fil
243c0 65 53 75 66 66 69 78 33 28 63 6f 6e 73 74 20 63 eSuffix3(const c
243d0 68 61 72 2a 2c 20 63 68 61 72 2a 29 3b 0a 23 65 har*, char*);.#e
243e0 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 71 6c lse.# define sql
243f0 69 74 65 33 46 69 6c 65 53 75 66 66 69 78 33 28 ite3FileSuffix3(
24400 58 2c 59 29 0a 23 65 6e 64 69 66 0a 75 38 20 73 X,Y).#endif.u8 s
24410 71 6c 69 74 65 33 47 65 74 42 6f 6f 6c 65 61 6e qlite3GetBoolean
24420 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 2c 75 (const char *z,u
24430 38 29 3b 0a 0a 63 6f 6e 73 74 20 76 6f 69 64 20 8);..const void
24440 2a 73 71 6c 69 74 65 33 56 61 6c 75 65 54 65 78 *sqlite3ValueTex
24450 74 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a t(sqlite3_value*
24460 2c 20 75 38 29 3b 0a 69 6e 74 20 73 71 6c 69 74 , u8);.int sqlit
24470 65 33 56 61 6c 75 65 42 79 74 65 73 28 73 71 6c e3ValueBytes(sql
24480 69 74 65 33 5f 76 61 6c 75 65 2a 2c 20 75 38 29 ite3_value*, u8)
24490 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 56 61 ;.void sqlite3Va
244a0 6c 75 65 53 65 74 53 74 72 28 73 71 6c 69 74 65 lueSetStr(sqlite
244b0 33 5f 76 61 6c 75 65 2a 2c 20 69 6e 74 2c 20 63 3_value*, int, c
244c0 6f 6e 73 74 20 76 6f 69 64 20 2a 2c 75 38 2c 20 onst void *,u8,
244d0 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
244e0 20 20 20 20 20 20 20 20 20 76 6f 69 64 28 2a 29 void(*)
244f0 28 76 6f 69 64 2a 29 29 3b 0a 76 6f 69 64 20 73 (void*));.void s
24500 71 6c 69 74 65 33 56 61 6c 75 65 53 65 74 4e 75 qlite3ValueSetNu
24510 6c 6c 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 ll(sqlite3_value
24520 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
24530 56 61 6c 75 65 46 72 65 65 28 73 71 6c 69 74 65 ValueFree(sqlite
24540 33 5f 76 61 6c 75 65 2a 29 3b 0a 73 71 6c 69 74 3_value*);.sqlit
24550 65 33 5f 76 61 6c 75 65 20 2a 73 71 6c 69 74 65 e3_value *sqlite
24560 33 56 61 6c 75 65 4e 65 77 28 73 71 6c 69 74 65 3ValueNew(sqlite
24570 33 20 2a 29 3b 0a 63 68 61 72 20 2a 73 71 6c 69 3 *);.char *sqli
24580 74 65 33 55 74 66 31 36 74 6f 38 28 73 71 6c 69 te3Utf16to8(sqli
24590 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 76 6f 69 te3 *, const voi
245a0 64 2a 2c 20 69 6e 74 2c 20 75 38 29 3b 0a 69 6e d*, int, u8);.in
245b0 74 20 73 71 6c 69 74 65 33 56 61 6c 75 65 46 72 t sqlite3ValueFr
245c0 6f 6d 45 78 70 72 28 73 71 6c 69 74 65 33 20 2a omExpr(sqlite3 *
245d0 2c 20 45 78 70 72 20 2a 2c 20 75 38 2c 20 75 38 , Expr *, u8, u8
245e0 2c 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 , sqlite3_value
245f0 2a 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 **);.void sqlite
24600 33 56 61 6c 75 65 41 70 70 6c 79 41 66 66 69 6e 3ValueApplyAffin
24610 69 74 79 28 73 71 6c 69 74 65 33 5f 76 61 6c 75 ity(sqlite3_valu
24620 65 20 2a 2c 20 75 38 2c 20 75 38 29 3b 0a 23 69 e *, u8, u8);.#i
24630 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 41 4d 41 fndef SQLITE_AMA
24640 4c 47 41 4d 41 54 49 4f 4e 0a 65 78 74 65 72 6e LGAMATION.extern
24650 20 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 const unsigned
24660 63 68 61 72 20 73 71 6c 69 74 65 33 4f 70 63 6f char sqlite3Opco
24670 64 65 50 72 6f 70 65 72 74 79 5b 5d 3b 0a 65 78 deProperty[];.ex
24680 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 69 67 tern const unsig
24690 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 65 33 ned char sqlite3
246a0 55 70 70 65 72 54 6f 4c 6f 77 65 72 5b 5d 3b 0a UpperToLower[];.
246b0 65 78 74 65 72 6e 20 63 6f 6e 73 74 20 75 6e 73 extern const uns
246c0 69 67 6e 65 64 20 63 68 61 72 20 73 71 6c 69 74 igned char sqlit
246d0 65 33 43 74 79 70 65 4d 61 70 5b 5d 3b 0a 65 78 e3CtypeMap[];.ex
246e0 74 65 72 6e 20 63 6f 6e 73 74 20 54 6f 6b 65 6e tern const Token
246f0 20 73 71 6c 69 74 65 33 49 6e 74 54 6f 6b 65 6e sqlite3IntToken
24700 73 5b 5d 3b 0a 65 78 74 65 72 6e 20 53 51 4c 49 s[];.extern SQLI
24710 54 45 5f 57 53 44 20 73 74 72 75 63 74 20 53 71 TE_WSD struct Sq
24720 6c 69 74 65 33 43 6f 6e 66 69 67 20 73 71 6c 69 lite3Config sqli
24730 74 65 33 43 6f 6e 66 69 67 3b 0a 65 78 74 65 72 te3Config;.exter
24740 6e 20 53 51 4c 49 54 45 5f 57 53 44 20 46 75 6e n SQLITE_WSD Fun
24750 63 44 65 66 48 61 73 68 20 73 71 6c 69 74 65 33 cDefHash sqlite3
24760 47 6c 6f 62 61 6c 46 75 6e 63 74 69 6f 6e 73 3b GlobalFunctions;
24770 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
24780 4f 4d 49 54 5f 57 53 44 0a 65 78 74 65 72 6e 20 OMIT_WSD.extern
24790 69 6e 74 20 73 71 6c 69 74 65 33 50 65 6e 64 69 int sqlite3Pendi
247a0 6e 67 42 79 74 65 3b 0a 23 65 6e 64 69 66 0a 23 ngByte;.#endif.#
247b0 65 6e 64 69 66 0a 76 6f 69 64 20 73 71 6c 69 74 endif.void sqlit
247c0 65 33 52 6f 6f 74 50 61 67 65 4d 6f 76 65 64 28 e3RootPageMoved(
247d0 73 71 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 69 sqlite3*, int, i
247e0 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 nt, int);.void s
247f0 71 6c 69 74 65 33 52 65 69 6e 64 65 78 28 50 61 qlite3Reindex(Pa
24800 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f rse*, Token*, To
24810 6b 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ken*);.void sqli
24820 74 65 33 41 6c 74 65 72 46 75 6e 63 74 69 6f 6e te3AlterFunction
24830 73 28 76 6f 69 64 29 3b 0a 76 6f 69 64 20 73 71 s(void);.void sq
24840 6c 69 74 65 33 41 6c 74 65 72 52 65 6e 61 6d 65 lite3AlterRename
24850 54 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 Table(Parse*, Sr
24860 63 4c 69 73 74 2a 2c 20 54 6f 6b 65 6e 2a 29 3b cList*, Token*);
24870 0a 69 6e 74 20 73 71 6c 69 74 65 33 47 65 74 54 .int sqlite3GetT
24880 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 67 oken(const unsig
24890 6e 65 64 20 63 68 61 72 20 2a 2c 20 69 6e 74 20 ned char *, int
248a0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
248b0 4e 65 73 74 65 64 50 61 72 73 65 28 50 61 72 73 NestedParse(Pars
248c0 65 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 2c e*, const char*,
248d0 20 2e 2e 2e 29 3b 0a 76 6f 69 64 20 73 71 6c 69 ...);.void sqli
248e0 74 65 33 45 78 70 69 72 65 50 72 65 70 61 72 65 te3ExpirePrepare
248f0 64 53 74 61 74 65 6d 65 6e 74 73 28 73 71 6c 69 dStatements(sqli
24900 74 65 33 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 te3*);.int sqlit
24910 65 33 43 6f 64 65 53 75 62 73 65 6c 65 63 74 28 e3CodeSubselect(
24920 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 2a 2c Parse *, Expr *,
24930 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 int, int);.void
24940 20 73 71 6c 69 74 65 33 53 65 6c 65 63 74 50 72 sqlite3SelectPr
24950 65 70 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 ep(Parse*, Selec
24960 74 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a t*, NameContext*
24970 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 61 );.int sqlite3Ma
24980 74 63 68 53 70 61 6e 4e 61 6d 65 28 63 6f 6e 73 tchSpanName(cons
24990 74 20 63 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 t char*, const c
249a0 68 61 72 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 har*, const char
249b0 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b *, const char*);
249c0 0a 69 6e 74 20 73 71 6c 69 74 65 33 52 65 73 6f .int sqlite3Reso
249d0 6c 76 65 45 78 70 72 4e 61 6d 65 73 28 4e 61 6d lveExprNames(Nam
249e0 65 43 6f 6e 74 65 78 74 2a 2c 20 45 78 70 72 2a eContext*, Expr*
249f0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 );.void sqlite3R
24a00 65 73 6f 6c 76 65 53 65 6c 65 63 74 4e 61 6d 65 esolveSelectName
24a10 73 28 50 61 72 73 65 2a 2c 20 53 65 6c 65 63 74 s(Parse*, Select
24a20 2a 2c 20 4e 61 6d 65 43 6f 6e 74 65 78 74 2a 29 *, NameContext*)
24a30 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 52 65 ;.void sqlite3Re
24a40 73 6f 6c 76 65 53 65 6c 66 52 65 66 65 72 65 6e solveSelfReferen
24a50 63 65 28 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a ce(Parse*,Table*
24a60 2c 69 6e 74 2c 45 78 70 72 2a 2c 45 78 70 72 4c ,int,Expr*,ExprL
24a70 69 73 74 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 ist*);.int sqlit
24a80 65 33 52 65 73 6f 6c 76 65 4f 72 64 65 72 47 72 e3ResolveOrderGr
24a90 6f 75 70 42 79 28 50 61 72 73 65 2a 2c 20 53 65 oupBy(Parse*, Se
24aa0 6c 65 63 74 2a 2c 20 45 78 70 72 4c 69 73 74 2a lect*, ExprList*
24ab0 2c 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a , const char*);.
24ac0 76 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6c 75 void sqlite3Colu
24ad0 6d 6e 44 65 66 61 75 6c 74 28 56 64 62 65 20 2a mnDefault(Vdbe *
24ae0 2c 20 54 61 62 6c 65 20 2a 2c 20 69 6e 74 2c 20 , Table *, int,
24af0 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 int);.void sqlit
24b00 65 33 41 6c 74 65 72 46 69 6e 69 73 68 41 64 64 e3AlterFinishAdd
24b10 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 2a 2c 20 Column(Parse *,
24b20 54 6f 6b 65 6e 20 2a 29 3b 0a 76 6f 69 64 20 73 Token *);.void s
24b30 71 6c 69 74 65 33 41 6c 74 65 72 42 65 67 69 6e qlite3AlterBegin
24b40 41 64 64 43 6f 6c 75 6d 6e 28 50 61 72 73 65 20 AddColumn(Parse
24b50 2a 2c 20 53 72 63 4c 69 73 74 20 2a 29 3b 0a 43 *, SrcList *);.C
24b60 6f 6c 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 47 ollSeq *sqlite3G
24b70 65 74 43 6f 6c 6c 53 65 71 28 50 61 72 73 65 2a etCollSeq(Parse*
24b80 2c 20 75 38 2c 20 43 6f 6c 6c 53 65 71 20 2a 2c , u8, CollSeq *,
24b90 20 63 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 63 const char*);.c
24ba0 68 61 72 20 73 71 6c 69 74 65 33 41 66 66 69 6e har sqlite3Affin
24bb0 69 74 79 54 79 70 65 28 63 6f 6e 73 74 20 63 68 ityType(const ch
24bc0 61 72 2a 2c 20 75 38 2a 29 3b 0a 76 6f 69 64 20 ar*, u8*);.void
24bd0 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 28 50 sqlite3Analyze(P
24be0 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 arse*, Token*, T
24bf0 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 oken*);.int sqli
24c00 74 65 33 49 6e 76 6f 6b 65 42 75 73 79 48 61 6e te3InvokeBusyHan
24c10 64 6c 65 72 28 42 75 73 79 48 61 6e 64 6c 65 72 dler(BusyHandler
24c20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 46 *);.int sqlite3F
24c30 69 6e 64 44 62 28 73 71 6c 69 74 65 33 2a 2c 20 indDb(sqlite3*,
24c40 54 6f 6b 65 6e 2a 29 3b 0a 69 6e 74 20 73 71 6c Token*);.int sql
24c50 69 74 65 33 46 69 6e 64 44 62 4e 61 6d 65 28 73 ite3FindDbName(s
24c60 71 6c 69 74 65 33 20 2a 2c 20 63 6f 6e 73 74 20 qlite3 *, const
24c70 63 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c char *);.int sql
24c80 69 74 65 33 41 6e 61 6c 79 73 69 73 4c 6f 61 64 ite3AnalysisLoad
24c90 28 73 71 6c 69 74 65 33 2a 2c 69 6e 74 20 69 44 (sqlite3*,int iD
24ca0 42 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 B);.void sqlite3
24cb0 44 65 6c 65 74 65 49 6e 64 65 78 53 61 6d 70 6c DeleteIndexSampl
24cc0 65 73 28 73 71 6c 69 74 65 33 2a 2c 49 6e 64 65 es(sqlite3*,Inde
24cd0 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 x*);.void sqlite
24ce0 33 44 65 66 61 75 6c 74 52 6f 77 45 73 74 28 49 3DefaultRowEst(I
24cf0 6e 64 65 78 2a 29 3b 0a 76 6f 69 64 20 73 71 6c ndex*);.void sql
24d00 69 74 65 33 52 65 67 69 73 74 65 72 4c 69 6b 65 ite3RegisterLike
24d10 46 75 6e 63 74 69 6f 6e 73 28 73 71 6c 69 74 65 Functions(sqlite
24d20 33 2a 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 3*, int);.int sq
24d30 6c 69 74 65 33 49 73 4c 69 6b 65 46 75 6e 63 74 lite3IsLikeFunct
24d40 69 6f 6e 28 73 71 6c 69 74 65 33 2a 2c 45 78 70 ion(sqlite3*,Exp
24d50 72 2a 2c 69 6e 74 2a 2c 63 68 61 72 2a 29 3b 0a r*,int*,char*);.
24d60 76 6f 69 64 20 73 71 6c 69 74 65 33 4d 69 6e 69 void sqlite3Mini
24d70 6d 75 6d 46 69 6c 65 46 6f 72 6d 61 74 28 50 61 mumFileFormat(Pa
24d80 72 73 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 29 3b rse*, int, int);
24d90 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 63 68 .void sqlite3Sch
24da0 65 6d 61 43 6c 65 61 72 28 76 6f 69 64 20 2a 29 emaClear(void *)
24db0 3b 0a 53 63 68 65 6d 61 20 2a 73 71 6c 69 74 65 ;.Schema *sqlite
24dc0 33 53 63 68 65 6d 61 47 65 74 28 73 71 6c 69 74 3SchemaGet(sqlit
24dd0 65 33 20 2a 2c 20 42 74 72 65 65 20 2a 29 3b 0a e3 *, Btree *);.
24de0 69 6e 74 20 73 71 6c 69 74 65 33 53 63 68 65 6d int sqlite3Schem
24df0 61 54 6f 49 6e 64 65 78 28 73 71 6c 69 74 65 33 aToIndex(sqlite3
24e00 20 2a 64 62 2c 20 53 63 68 65 6d 61 20 2a 29 3b *db, Schema *);
24e10 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 6c 69 74 65 .KeyInfo *sqlite
24e20 33 4b 65 79 49 6e 66 6f 41 6c 6c 6f 63 28 73 71 3KeyInfoAlloc(sq
24e30 6c 69 74 65 33 2a 2c 69 6e 74 2c 69 6e 74 29 3b lite3*,int,int);
24e40 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 4b 65 79 .void sqlite3Key
24e50 49 6e 66 6f 55 6e 72 65 66 28 4b 65 79 49 6e 66 InfoUnref(KeyInf
24e60 6f 2a 29 3b 0a 4b 65 79 49 6e 66 6f 20 2a 73 71 o*);.KeyInfo *sq
24e70 6c 69 74 65 33 4b 65 79 49 6e 66 6f 52 65 66 28 lite3KeyInfoRef(
24e80 4b 65 79 49 6e 66 6f 2a 29 3b 0a 4b 65 79 49 6e KeyInfo*);.KeyIn
24e90 66 6f 20 2a 73 71 6c 69 74 65 33 4b 65 79 49 6e fo *sqlite3KeyIn
24ea0 66 6f 4f 66 49 6e 64 65 78 28 50 61 72 73 65 2a foOfIndex(Parse*
24eb0 2c 20 49 6e 64 65 78 2a 29 3b 0a 23 69 66 64 65 , Index*);.#ifde
24ec0 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 69 f SQLITE_DEBUG.i
24ed0 6e 74 20 73 71 6c 69 74 65 33 4b 65 79 49 6e 66 nt sqlite3KeyInf
24ee0 6f 49 73 57 72 69 74 65 61 62 6c 65 28 4b 65 79 oIsWriteable(Key
24ef0 49 6e 66 6f 2a 29 3b 0a 23 65 6e 64 69 66 0a 69 Info*);.#endif.i
24f00 6e 74 20 73 71 6c 69 74 65 33 43 72 65 61 74 65 nt sqlite3Create
24f10 46 75 6e 63 28 73 71 6c 69 74 65 33 20 2a 2c 20 Func(sqlite3 *,
24f20 63 6f 6e 73 74 20 63 68 61 72 20 2a 2c 20 69 6e const char *, in
24f30 74 2c 20 69 6e 74 2c 20 76 6f 69 64 20 2a 2c 20 t, int, void *,
24f40 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 71 6c 69 . void (*)(sqli
24f50 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 te3_context*,int
24f60 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 20 2a ,sqlite3_value *
24f70 2a 29 2c 0a 20 20 76 6f 69 64 20 28 2a 29 28 73 *),. void (*)(s
24f80 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a 2c qlite3_context*,
24f90 69 6e 74 2c 73 71 6c 69 74 65 33 5f 76 61 6c 75 int,sqlite3_valu
24fa0 65 20 2a 2a 29 2c 20 76 6f 69 64 20 28 2a 29 28 e **), void (*)(
24fb0 73 71 6c 69 74 65 33 5f 63 6f 6e 74 65 78 74 2a sqlite3_context*
24fc0 29 2c 0a 20 20 46 75 6e 63 44 65 73 74 72 75 63 ),. FuncDestruc
24fd0 74 6f 72 20 2a 70 44 65 73 74 72 75 63 74 6f 72 tor *pDestructor
24fe0 0a 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 41 .);.int sqlite3A
24ff0 70 69 45 78 69 74 28 73 71 6c 69 74 65 33 20 2a piExit(sqlite3 *
25000 64 62 2c 20 69 6e 74 29 3b 0a 69 6e 74 20 73 71 db, int);.int sq
25010 6c 69 74 65 33 4f 70 65 6e 54 65 6d 70 44 61 74 lite3OpenTempDat
25020 61 62 61 73 65 28 50 61 72 73 65 20 2a 29 3b 0a abase(Parse *);.
25030 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 74 72 .void sqlite3Str
25040 41 63 63 75 6d 49 6e 69 74 28 53 74 72 41 63 63 AccumInit(StrAcc
25050 75 6d 2a 2c 20 63 68 61 72 2a 2c 20 69 6e 74 2c um*, char*, int,
25060 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 6c 69 int);.void sqli
25070 74 65 33 53 74 72 41 63 63 75 6d 41 70 70 65 6e te3StrAccumAppen
25080 64 28 53 74 72 41 63 63 75 6d 2a 2c 63 6f 6e 73 d(StrAccum*,cons
25090 74 20 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 76 6f t char*,int);.vo
250a0 69 64 20 73 71 6c 69 74 65 33 53 74 72 41 63 63 id sqlite3StrAcc
250b0 75 6d 41 70 70 65 6e 64 41 6c 6c 28 53 74 72 41 umAppendAll(StrA
250c0 63 63 75 6d 2a 2c 63 6f 6e 73 74 20 63 68 61 72 ccum*,const char
250d0 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
250e0 41 70 70 65 6e 64 53 70 61 63 65 28 53 74 72 41 AppendSpace(StrA
250f0 63 63 75 6d 2a 2c 69 6e 74 29 3b 0a 63 68 61 72 ccum*,int);.char
25100 20 2a 73 71 6c 69 74 65 33 53 74 72 41 63 63 75 *sqlite3StrAccu
25110 6d 46 69 6e 69 73 68 28 53 74 72 41 63 63 75 6d mFinish(StrAccum
25120 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 *);.void sqlite3
25130 53 74 72 41 63 63 75 6d 52 65 73 65 74 28 53 74 StrAccumReset(St
25140 72 41 63 63 75 6d 2a 29 3b 0a 76 6f 69 64 20 73 rAccum*);.void s
25150 71 6c 69 74 65 33 53 65 6c 65 63 74 44 65 73 74 qlite3SelectDest
25160 49 6e 69 74 28 53 65 6c 65 63 74 44 65 73 74 2a Init(SelectDest*
25170 2c 69 6e 74 2c 69 6e 74 29 3b 0a 45 78 70 72 20 ,int,int);.Expr
25180 2a 73 71 6c 69 74 65 33 43 72 65 61 74 65 43 6f *sqlite3CreateCo
25190 6c 75 6d 6e 45 78 70 72 28 73 71 6c 69 74 65 33 lumnExpr(sqlite3
251a0 20 2a 2c 20 53 72 63 4c 69 73 74 20 2a 2c 20 69 *, SrcList *, i
251b0 6e 74 2c 20 69 6e 74 29 3b 0a 0a 76 6f 69 64 20 nt, int);..void
251c0 73 71 6c 69 74 65 33 42 61 63 6b 75 70 52 65 73 sqlite3BackupRes
251d0 74 61 72 74 28 73 71 6c 69 74 65 33 5f 62 61 63 tart(sqlite3_bac
251e0 6b 75 70 20 2a 29 3b 0a 76 6f 69 64 20 73 71 6c kup *);.void sql
251f0 69 74 65 33 42 61 63 6b 75 70 55 70 64 61 74 65 ite3BackupUpdate
25200 28 73 71 6c 69 74 65 33 5f 62 61 63 6b 75 70 20 (sqlite3_backup
25210 2a 2c 20 50 67 6e 6f 2c 20 63 6f 6e 73 74 20 75 *, Pgno, const u
25220 38 20 2a 29 3b 0a 0a 23 69 66 64 65 66 20 53 51 8 *);..#ifdef SQ
25230 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 53 54 41 54 LITE_ENABLE_STAT
25240 33 5f 4f 52 5f 53 54 41 54 34 0a 76 6f 69 64 20 3_OR_STAT4.void
25250 73 71 6c 69 74 65 33 41 6e 61 6c 79 7a 65 46 75 sqlite3AnalyzeFu
25260 6e 63 74 69 6f 6e 73 28 76 6f 69 64 29 3b 0a 69 nctions(void);.i
25270 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 50 nt sqlite3Stat4P
25280 72 6f 62 65 53 65 74 56 61 6c 75 65 28 50 61 72 robeSetValue(Par
25290 73 65 2a 2c 49 6e 64 65 78 2a 2c 55 6e 70 61 63 se*,Index*,Unpac
252a0 6b 65 64 52 65 63 6f 72 64 2a 2a 2c 45 78 70 72 kedRecord**,Expr
252b0 2a 2c 75 38 2c 69 6e 74 2c 69 6e 74 2a 29 3b 0a *,u8,int,int*);.
252c0 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 int sqlite3Stat4
252d0 56 61 6c 75 65 46 72 6f 6d 45 78 70 72 28 50 61 ValueFromExpr(Pa
252e0 72 73 65 2a 2c 20 45 78 70 72 2a 2c 20 75 38 2c rse*, Expr*, u8,
252f0 20 73 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a sqlite3_value**
25300 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 53 );.void sqlite3S
25310 74 61 74 34 50 72 6f 62 65 46 72 65 65 28 55 6e tat4ProbeFree(Un
25320 70 61 63 6b 65 64 52 65 63 6f 72 64 2a 29 3b 0a packedRecord*);.
25330 69 6e 74 20 73 71 6c 69 74 65 33 53 74 61 74 34 int sqlite3Stat4
25340 43 6f 6c 75 6d 6e 28 73 71 6c 69 74 65 33 2a 2c Column(sqlite3*,
25350 20 63 6f 6e 73 74 20 76 6f 69 64 2a 2c 20 69 6e const void*, in
25360 74 2c 20 69 6e 74 2c 20 73 71 6c 69 74 65 33 5f t, int, sqlite3_
25370 76 61 6c 75 65 2a 2a 29 3b 0a 23 65 6e 64 69 66 value**);.#endif
25380 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 20 69 6e 74 65 ../*.** The inte
25390 72 66 61 63 65 20 74 6f 20 74 68 65 20 4c 45 4d rface to the LEM
253a0 4f 4e 2d 67 65 6e 65 72 61 74 65 64 20 70 61 72 ON-generated par
253b0 73 65 72 0a 2a 2f 0a 76 6f 69 64 20 2a 73 71 6c ser.*/.void *sql
253c0 69 74 65 33 50 61 72 73 65 72 41 6c 6c 6f 63 28 ite3ParserAlloc(
253d0 76 6f 69 64 2a 28 2a 29 28 73 69 7a 65 5f 74 29 void*(*)(size_t)
253e0 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 );.void sqlite3P
253f0 61 72 73 65 72 46 72 65 65 28 76 6f 69 64 2a 2c arserFree(void*,
25400 20 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 void(*)(void*))
25410 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 ;.void sqlite3Pa
25420 72 73 65 72 28 76 6f 69 64 2a 2c 20 69 6e 74 2c rser(void*, int,
25430 20 54 6f 6b 65 6e 2c 20 50 61 72 73 65 2a 29 3b Token, Parse*);
25440 0a 23 69 66 64 65 66 20 59 59 54 52 41 43 4b 4d .#ifdef YYTRACKM
25450 41 58 53 54 41 43 4b 44 45 50 54 48 0a 20 20 69 AXSTACKDEPTH. i
25460 6e 74 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 nt sqlite3Parser
25470 53 74 61 63 6b 50 65 61 6b 28 76 6f 69 64 2a 29 StackPeak(void*)
25480 3b 0a 23 65 6e 64 69 66 0a 0a 76 6f 69 64 20 73 ;.#endif..void s
25490 71 6c 69 74 65 33 41 75 74 6f 4c 6f 61 64 45 78 qlite3AutoLoadEx
254a0 74 65 6e 73 69 6f 6e 73 28 73 71 6c 69 74 65 33 tensions(sqlite3
254b0 2a 29 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 *);.#ifndef SQLI
254c0 54 45 5f 4f 4d 49 54 5f 4c 4f 41 44 5f 45 58 54 TE_OMIT_LOAD_EXT
254d0 45 4e 53 49 4f 4e 0a 20 20 76 6f 69 64 20 73 71 ENSION. void sq
254e0 6c 69 74 65 33 43 6c 6f 73 65 45 78 74 65 6e 73 lite3CloseExtens
254f0 69 6f 6e 73 28 73 71 6c 69 74 65 33 2a 29 3b 0a ions(sqlite3*);.
25500 23 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 73 #else.# define s
25510 71 6c 69 74 65 33 43 6c 6f 73 65 45 78 74 65 6e qlite3CloseExten
25520 73 69 6f 6e 73 28 58 29 0a 23 65 6e 64 69 66 0a sions(X).#endif.
25530 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f .#ifndef SQLITE_
25540 4f 4d 49 54 5f 53 48 41 52 45 44 5f 43 41 43 48 OMIT_SHARED_CACH
25550 45 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 E. void sqlite3
25560 54 61 62 6c 65 4c 6f 63 6b 28 50 61 72 73 65 20 TableLock(Parse
25570 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 75 38 2c *, int, int, u8,
25580 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a const char *);.
25590 23 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 #else. #define
255a0 73 71 6c 69 74 65 33 54 61 62 6c 65 4c 6f 63 6b sqlite3TableLock
255b0 28 76 2c 77 2c 78 2c 79 2c 7a 29 0a 23 65 6e 64 (v,w,x,y,z).#end
255c0 69 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 if..#ifdef SQLIT
255d0 45 5f 54 45 53 54 0a 20 20 69 6e 74 20 73 71 6c E_TEST. int sql
255e0 69 74 65 33 55 74 66 38 54 6f 38 28 75 6e 73 69 ite3Utf8To8(unsi
255f0 67 6e 65 64 20 63 68 61 72 2a 29 3b 0a 23 65 6e gned char*);.#en
25600 64 69 66 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 dif..#ifdef SQLI
25610 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c 54 TE_OMIT_VIRTUALT
25620 41 42 4c 45 0a 23 20 20 64 65 66 69 6e 65 20 73 ABLE.# define s
25630 71 6c 69 74 65 33 56 74 61 62 43 6c 65 61 72 28 qlite3VtabClear(
25640 59 29 0a 23 20 20 64 65 66 69 6e 65 20 73 71 6c Y).# define sql
25650 69 74 65 33 56 74 61 62 53 79 6e 63 28 58 2c 59 ite3VtabSync(X,Y
25660 29 20 53 51 4c 49 54 45 5f 4f 4b 0a 23 20 20 64 ) SQLITE_OK.# d
25670 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
25680 62 52 6f 6c 6c 62 61 63 6b 28 58 29 0a 23 20 20 bRollback(X).#
25690 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 define sqlite3Vt
256a0 61 62 43 6f 6d 6d 69 74 28 58 29 0a 23 20 20 64 abCommit(X).# d
256b0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
256c0 62 49 6e 53 79 6e 63 28 64 62 29 20 30 0a 23 20 bInSync(db) 0.#
256d0 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
256e0 74 61 62 4c 6f 63 6b 28 58 29 20 0a 23 20 20 64 tabLock(X) .# d
256f0 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 efine sqlite3Vta
25700 62 55 6e 6c 6f 63 6b 28 58 29 0a 23 20 20 64 65 bUnlock(X).# de
25710 66 69 6e 65 20 73 71 6c 69 74 65 33 56 74 61 62 fine sqlite3Vtab
25720 55 6e 6c 6f 63 6b 4c 69 73 74 28 58 29 0a 23 20 UnlockList(X).#
25730 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
25740 74 61 62 53 61 76 65 70 6f 69 6e 74 28 58 2c 20 tabSavepoint(X,
25750 59 2c 20 5a 29 20 53 51 4c 49 54 45 5f 4f 4b 0a Y, Z) SQLITE_OK.
25760 23 20 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 # define sqlite
25770 33 47 65 74 56 54 61 62 6c 65 28 58 2c 59 29 20 3GetVTable(X,Y)
25780 20 28 28 56 54 61 62 6c 65 2a 29 30 29 0a 23 65 ((VTable*)0).#e
25790 6c 73 65 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 lse. void sqli
257a0 74 65 33 56 74 61 62 43 6c 65 61 72 28 73 71 6c te3VtabClear(sql
257b0 69 74 65 33 20 2a 64 62 2c 20 54 61 62 6c 65 2a ite3 *db, Table*
257c0 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c 69 74 );. void sqlit
257d0 65 33 56 74 61 62 44 69 73 63 6f 6e 6e 65 63 74 e3VtabDisconnect
257e0 28 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 54 61 (sqlite3 *db, Ta
257f0 62 6c 65 20 2a 70 29 3b 0a 20 20 20 69 6e 74 20 ble *p);. int
25800 73 71 6c 69 74 65 33 56 74 61 62 53 79 6e 63 28 sqlite3VtabSync(
25810 73 71 6c 69 74 65 33 20 2a 64 62 2c 20 56 64 62 sqlite3 *db, Vdb
25820 65 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c 69 e*);. int sqli
25830 74 65 33 56 74 61 62 52 6f 6c 6c 62 61 63 6b 28 te3VtabRollback(
25840 73 71 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 sqlite3 *db);.
25850 20 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 int sqlite3Vtab
25860 43 6f 6d 6d 69 74 28 73 71 6c 69 74 65 33 20 2a Commit(sqlite3 *
25870 64 62 29 3b 0a 20 20 20 76 6f 69 64 20 73 71 6c db);. void sql
25880 69 74 65 33 56 74 61 62 4c 6f 63 6b 28 56 54 61 ite3VtabLock(VTa
25890 62 6c 65 20 2a 29 3b 0a 20 20 20 76 6f 69 64 20 ble *);. void
258a0 73 71 6c 69 74 65 33 56 74 61 62 55 6e 6c 6f 63 sqlite3VtabUnloc
258b0 6b 28 56 54 61 62 6c 65 20 2a 29 3b 0a 20 20 20 k(VTable *);.
258c0 76 6f 69 64 20 73 71 6c 69 74 65 33 56 74 61 62 void sqlite3Vtab
258d0 55 6e 6c 6f 63 6b 4c 69 73 74 28 73 71 6c 69 74 UnlockList(sqlit
258e0 65 33 2a 29 3b 0a 20 20 20 69 6e 74 20 73 71 6c e3*);. int sql
258f0 69 74 65 33 56 74 61 62 53 61 76 65 70 6f 69 6e ite3VtabSavepoin
25900 74 28 73 71 6c 69 74 65 33 20 2a 2c 20 69 6e 74 t(sqlite3 *, int
25910 2c 20 69 6e 74 29 3b 0a 20 20 20 76 6f 69 64 20 , int);. void
25920 73 71 6c 69 74 65 33 56 74 61 62 49 6d 70 6f 72 sqlite3VtabImpor
25930 74 45 72 72 6d 73 67 28 56 64 62 65 2a 2c 20 73 tErrmsg(Vdbe*, s
25940 71 6c 69 74 65 33 5f 76 74 61 62 2a 29 3b 0a 20 qlite3_vtab*);.
25950 20 20 56 54 61 62 6c 65 20 2a 73 71 6c 69 74 65 VTable *sqlite
25960 33 47 65 74 56 54 61 62 6c 65 28 73 71 6c 69 74 3GetVTable(sqlit
25970 65 33 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 23 20 e3*, Table*);.#
25980 20 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 56 define sqlite3V
25990 74 61 62 49 6e 53 79 6e 63 28 64 62 29 20 28 28 tabInSync(db) ((
259a0 64 62 29 2d 3e 6e 56 54 72 61 6e 73 3e 30 20 26 db)->nVTrans>0 &
259b0 26 20 28 64 62 29 2d 3e 61 56 54 72 61 6e 73 3d & (db)->aVTrans=
259c0 3d 30 29 0a 23 65 6e 64 69 66 0a 76 6f 69 64 20 =0).#endif.void
259d0 73 71 6c 69 74 65 33 56 74 61 62 4d 61 6b 65 57 sqlite3VtabMakeW
259e0 72 69 74 61 62 6c 65 28 50 61 72 73 65 2a 2c 54 ritable(Parse*,T
259f0 61 62 6c 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c able*);.void sql
25a00 69 74 65 33 56 74 61 62 42 65 67 69 6e 50 61 72 ite3VtabBeginPar
25a10 73 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e se(Parse*, Token
25a20 2a 2c 20 54 6f 6b 65 6e 2a 2c 20 54 6f 6b 65 6e *, Token*, Token
25a30 2a 2c 20 69 6e 74 29 3b 0a 76 6f 69 64 20 73 71 *, int);.void sq
25a40 6c 69 74 65 33 56 74 61 62 46 69 6e 69 73 68 50 lite3VtabFinishP
25a50 61 72 73 65 28 50 61 72 73 65 2a 2c 20 54 6f 6b arse(Parse*, Tok
25a60 65 6e 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 74 en*);.void sqlit
25a70 65 33 56 74 61 62 41 72 67 49 6e 69 74 28 50 61 e3VtabArgInit(Pa
25a80 72 73 65 2a 29 3b 0a 76 6f 69 64 20 73 71 6c 69 rse*);.void sqli
25a90 74 65 33 56 74 61 62 41 72 67 45 78 74 65 6e 64 te3VtabArgExtend
25aa0 28 50 61 72 73 65 2a 2c 20 54 6f 6b 65 6e 2a 29 (Parse*, Token*)
25ab0 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 61 ;.int sqlite3Vta
25ac0 62 43 61 6c 6c 43 72 65 61 74 65 28 73 71 6c 69 bCallCreate(sqli
25ad0 74 65 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 te3*, int, const
25ae0 20 63 68 61 72 20 2a 2c 20 63 68 61 72 20 2a 2a char *, char **
25af0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 56 74 );.int sqlite3Vt
25b00 61 62 43 61 6c 6c 43 6f 6e 6e 65 63 74 28 50 61 abCallConnect(Pa
25b10 72 73 65 2a 2c 20 54 61 62 6c 65 2a 29 3b 0a 69 rse*, Table*);.i
25b20 6e 74 20 73 71 6c 69 74 65 33 56 74 61 62 43 61 nt sqlite3VtabCa
25b30 6c 6c 44 65 73 74 72 6f 79 28 73 71 6c 69 74 65 llDestroy(sqlite
25b40 33 2a 2c 20 69 6e 74 2c 20 63 6f 6e 73 74 20 63 3*, int, const c
25b50 68 61 72 20 2a 29 3b 0a 69 6e 74 20 73 71 6c 69 har *);.int sqli
25b60 74 65 33 56 74 61 62 42 65 67 69 6e 28 73 71 6c te3VtabBegin(sql
25b70 69 74 65 33 20 2a 2c 20 56 54 61 62 6c 65 20 2a ite3 *, VTable *
25b80 29 3b 0a 46 75 6e 63 44 65 66 20 2a 73 71 6c 69 );.FuncDef *sqli
25b90 74 65 33 56 74 61 62 4f 76 65 72 6c 6f 61 64 46 te3VtabOverloadF
25ba0 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 33 20 unction(sqlite3
25bb0 2a 2c 46 75 6e 63 44 65 66 2a 2c 20 69 6e 74 20 *,FuncDef*, int
25bc0 6e 41 72 67 2c 20 45 78 70 72 2a 29 3b 0a 76 6f nArg, Expr*);.vo
25bd0 69 64 20 73 71 6c 69 74 65 33 49 6e 76 61 6c 69 id sqlite3Invali
25be0 64 46 75 6e 63 74 69 6f 6e 28 73 71 6c 69 74 65 dFunction(sqlite
25bf0 33 5f 63 6f 6e 74 65 78 74 2a 2c 69 6e 74 2c 73 3_context*,int,s
25c00 71 6c 69 74 65 33 5f 76 61 6c 75 65 2a 2a 29 3b qlite3_value**);
25c10 0a 73 71 6c 69 74 65 33 5f 69 6e 74 36 34 20 73 .sqlite3_int64 s
25c20 71 6c 69 74 65 33 53 74 6d 74 43 75 72 72 65 6e qlite3StmtCurren
25c30 74 54 69 6d 65 28 73 71 6c 69 74 65 33 5f 63 6f tTime(sqlite3_co
25c40 6e 74 65 78 74 2a 29 3b 0a 69 6e 74 20 73 71 6c ntext*);.int sql
25c50 69 74 65 33 56 64 62 65 50 61 72 61 6d 65 74 65 ite3VdbeParamete
25c60 72 49 6e 64 65 78 28 56 64 62 65 2a 2c 20 63 6f rIndex(Vdbe*, co
25c70 6e 73 74 20 63 68 61 72 2a 2c 20 69 6e 74 29 3b nst char*, int);
25c80 0a 69 6e 74 20 73 71 6c 69 74 65 33 54 72 61 6e .int sqlite3Tran
25c90 73 66 65 72 42 69 6e 64 69 6e 67 73 28 73 71 6c sferBindings(sql
25ca0 69 74 65 33 5f 73 74 6d 74 20 2a 2c 20 73 71 6c ite3_stmt *, sql
25cb0 69 74 65 33 5f 73 74 6d 74 20 2a 29 3b 0a 76 6f ite3_stmt *);.vo
25cc0 69 64 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 id sqlite3Parser
25cd0 52 65 73 65 74 28 50 61 72 73 65 2a 29 3b 0a 69 Reset(Parse*);.i
25ce0 6e 74 20 73 71 6c 69 74 65 33 52 65 70 72 65 70 nt sqlite3Reprep
25cf0 61 72 65 28 56 64 62 65 2a 29 3b 0a 76 6f 69 64 are(Vdbe*);.void
25d00 20 73 71 6c 69 74 65 33 45 78 70 72 4c 69 73 74 sqlite3ExprList
25d10 43 68 65 63 6b 4c 65 6e 67 74 68 28 50 61 72 73 CheckLength(Pars
25d20 65 2a 2c 20 45 78 70 72 4c 69 73 74 2a 2c 20 63 e*, ExprList*, c
25d30 6f 6e 73 74 20 63 68 61 72 2a 29 3b 0a 43 6f 6c onst char*);.Col
25d40 6c 53 65 71 20 2a 73 71 6c 69 74 65 33 42 69 6e lSeq *sqlite3Bin
25d50 61 72 79 43 6f 6d 70 61 72 65 43 6f 6c 6c 53 65 aryCompareCollSe
25d60 71 28 50 61 72 73 65 20 2a 2c 20 45 78 70 72 20 q(Parse *, Expr
25d70 2a 2c 20 45 78 70 72 20 2a 29 3b 0a 69 6e 74 20 *, Expr *);.int
25d80 73 71 6c 69 74 65 33 54 65 6d 70 49 6e 4d 65 6d sqlite3TempInMem
25d90 6f 72 79 28 63 6f 6e 73 74 20 73 71 6c 69 74 65 ory(const sqlite
25da0 33 2a 29 3b 0a 63 6f 6e 73 74 20 63 68 61 72 20 3*);.const char
25db0 2a 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 4d *sqlite3JournalM
25dc0 6f 64 65 6e 61 6d 65 28 69 6e 74 29 3b 0a 23 69 odename(int);.#i
25dd0 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 fndef SQLITE_OMI
25de0 54 5f 57 41 4c 0a 20 20 69 6e 74 20 73 71 6c 69 T_WAL. int sqli
25df0 74 65 33 43 68 65 63 6b 70 6f 69 6e 74 28 73 71 te3Checkpoint(sq
25e00 6c 69 74 65 33 2a 2c 20 69 6e 74 2c 20 69 6e 74 lite3*, int, int
25e10 2c 20 69 6e 74 2a 2c 20 69 6e 74 2a 29 3b 0a 20 , int*, int*);.
25e20 20 69 6e 74 20 73 71 6c 69 74 65 33 57 61 6c 44 int sqlite3WalD
25e30 65 66 61 75 6c 74 48 6f 6f 6b 28 76 6f 69 64 2a efaultHook(void*
25e40 2c 73 71 6c 69 74 65 33 2a 2c 63 6f 6e 73 74 20 ,sqlite3*,const
25e50 63 68 61 72 2a 2c 69 6e 74 29 3b 0a 23 65 6e 64 char*,int);.#end
25e60 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 if.#ifndef SQLIT
25e70 45 5f 4f 4d 49 54 5f 43 54 45 0a 20 20 57 69 74 E_OMIT_CTE. Wit
25e80 68 20 2a 73 71 6c 69 74 65 33 57 69 74 68 41 64 h *sqlite3WithAd
25e90 64 28 50 61 72 73 65 2a 2c 57 69 74 68 2a 2c 54 d(Parse*,With*,T
25ea0 6f 6b 65 6e 2a 2c 45 78 70 72 4c 69 73 74 2a 2c oken*,ExprList*,
25eb0 53 65 6c 65 63 74 2a 29 3b 0a 20 20 76 6f 69 64 Select*);. void
25ec0 20 73 71 6c 69 74 65 33 57 69 74 68 44 65 6c 65 sqlite3WithDele
25ed0 74 65 28 73 71 6c 69 74 65 33 2a 2c 57 69 74 68 te(sqlite3*,With
25ee0 2a 29 3b 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 *);. void sqlit
25ef0 65 33 57 69 74 68 50 75 73 68 28 50 61 72 73 65 e3WithPush(Parse
25f00 2a 2c 20 57 69 74 68 2a 2c 20 75 38 29 3b 0a 23 *, With*, u8);.#
25f10 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 73 71 6c else.#define sql
25f20 69 74 65 33 57 69 74 68 50 75 73 68 28 78 2c 79 ite3WithPush(x,y
25f30 2c 7a 29 0a 23 64 65 66 69 6e 65 20 73 71 6c 69 ,z).#define sqli
25f40 74 65 33 57 69 74 68 44 65 6c 65 74 65 28 78 2c te3WithDelete(x,
25f50 79 29 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 44 65 y).#endif../* De
25f60 63 6c 61 72 61 74 69 6f 6e 73 20 66 6f 72 20 66 clarations for f
25f70 75 6e 63 74 69 6f 6e 73 20 69 6e 20 66 6b 65 79 unctions in fkey
25f80 2e 63 2e 20 41 6c 6c 20 6f 66 20 74 68 65 73 65 .c. All of these
25f90 20 61 72 65 20 72 65 70 6c 61 63 65 64 20 62 79 are replaced by
25fa0 0a 2a 2a 20 6e 6f 2d 6f 70 20 6d 61 63 72 6f 73 .** no-op macros
25fb0 20 69 66 20 4f 4d 49 54 5f 46 4f 52 45 49 47 4e if OMIT_FOREIGN
25fc0 5f 4b 45 59 20 69 73 20 64 65 66 69 6e 65 64 2e _KEY is defined.
25fd0 20 49 6e 20 74 68 69 73 20 63 61 73 65 20 6e 6f In this case no
25fe0 20 66 6f 72 65 69 67 6e 0a 2a 2a 20 6b 65 79 20 foreign.** key
25ff0 66 75 6e 63 74 69 6f 6e 61 6c 69 74 79 20 69 73 functionality is
26000 20 61 76 61 69 6c 61 62 6c 65 2e 20 49 66 20 4f available. If O
26010 4d 49 54 5f 54 52 49 47 47 45 52 20 69 73 20 64 MIT_TRIGGER is d
26020 65 66 69 6e 65 64 20 62 75 74 0a 2a 2a 20 4f 4d efined but.** OM
26030 49 54 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 20 69 IT_FOREIGN_KEY i
26040 73 20 6e 6f 74 2c 20 6f 6e 6c 79 20 73 6f 6d 65 s not, only some
26050 20 6f 66 20 74 68 65 20 66 75 6e 63 74 69 6f 6e of the function
26060 73 20 61 72 65 20 6e 6f 2d 6f 70 65 64 2e 20 49 s are no-oped. I
26070 6e 0a 2a 2a 20 74 68 69 73 20 63 61 73 65 20 66 n.** this case f
26080 6f 72 65 69 67 6e 20 6b 65 79 73 20 61 72 65 20 oreign keys are
26090 70 61 72 73 65 64 2c 20 62 75 74 20 6e 6f 20 6f parsed, but no o
260a0 74 68 65 72 20 66 75 6e 63 74 69 6f 6e 61 6c 69 ther functionali
260b0 74 79 20 69 73 20 0a 2a 2a 20 70 72 6f 76 69 64 ty is .** provid
260c0 65 64 20 28 65 6e 66 6f 72 63 65 6d 65 6e 74 20 ed (enforcement
260d0 6f 66 20 46 4b 20 63 6f 6e 73 74 72 61 69 6e 74 of FK constraint
260e0 73 20 72 65 71 75 69 72 65 73 20 74 68 65 20 74 s requires the t
260f0 72 69 67 67 65 72 73 20 73 75 62 2d 73 79 73 74 riggers sub-syst
26100 65 6d 29 2e 0a 2a 2f 0a 23 69 66 20 21 64 65 66 em)..*/.#if !def
26110 69 6e 65 64 28 53 51 4c 49 54 45 5f 4f 4d 49 54 ined(SQLITE_OMIT
26120 5f 46 4f 52 45 49 47 4e 5f 4b 45 59 29 20 26 26 _FOREIGN_KEY) &&
26130 20 21 64 65 66 69 6e 65 64 28 53 51 4c 49 54 45 !defined(SQLITE
26140 5f 4f 4d 49 54 5f 54 52 49 47 47 45 52 29 0a 20 _OMIT_TRIGGER).
26150 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 6b 43 void sqlite3FkC
26160 68 65 63 6b 28 50 61 72 73 65 2a 2c 20 54 61 62 heck(Parse*, Tab
26170 6c 65 2a 2c 20 69 6e 74 2c 20 69 6e 74 2c 20 69 le*, int, int, i
26180 6e 74 2a 2c 20 69 6e 74 29 3b 0a 20 20 76 6f 69 nt*, int);. voi
26190 64 20 73 71 6c 69 74 65 33 46 6b 44 72 6f 70 54 d sqlite3FkDropT
261a0 61 62 6c 65 28 50 61 72 73 65 2a 2c 20 53 72 63 able(Parse*, Src
261b0 4c 69 73 74 20 2a 2c 20 54 61 62 6c 65 2a 29 3b List *, Table*);
261c0 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 46 . void sqlite3F
261d0 6b 41 63 74 69 6f 6e 73 28 50 61 72 73 65 2a 2c kActions(Parse*,
261e0 20 54 61 62 6c 65 2a 2c 20 45 78 70 72 4c 69 73 Table*, ExprLis
261f0 74 2a 2c 20 69 6e 74 2c 20 69 6e 74 2a 2c 20 69 t*, int, int*, i
26200 6e 74 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 nt);. int sqlit
26210 65 33 46 6b 52 65 71 75 69 72 65 64 28 50 61 72 e3FkRequired(Par
26220 73 65 2a 2c 20 54 61 62 6c 65 2a 2c 20 69 6e 74 se*, Table*, int
26230 2a 2c 20 69 6e 74 29 3b 0a 20 20 75 33 32 20 73 *, int);. u32 s
26240 71 6c 69 74 65 33 46 6b 4f 6c 64 6d 61 73 6b 28 qlite3FkOldmask(
26250 50 61 72 73 65 2a 2c 20 54 61 62 6c 65 2a 29 3b Parse*, Table*);
26260 0a 20 20 46 4b 65 79 20 2a 73 71 6c 69 74 65 33 . FKey *sqlite3
26270 46 6b 52 65 66 65 72 65 6e 63 65 73 28 54 61 62 FkReferences(Tab
26280 6c 65 20 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 23 le *);.#else. #
26290 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b define sqlite3Fk
262a0 41 63 74 69 6f 6e 73 28 61 2c 62 2c 63 2c 64 2c Actions(a,b,c,d,
262b0 65 2c 66 29 0a 20 20 23 64 65 66 69 6e 65 20 73 e,f). #define s
262c0 71 6c 69 74 65 33 46 6b 43 68 65 63 6b 28 61 2c qlite3FkCheck(a,
262d0 62 2c 63 2c 64 2c 65 2c 66 29 0a 20 20 23 64 65 b,c,d,e,f). #de
262e0 66 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 44 72 fine sqlite3FkDr
262f0 6f 70 54 61 62 6c 65 28 61 2c 62 2c 63 29 0a 20 opTable(a,b,c).
26300 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
26310 46 6b 4f 6c 64 6d 61 73 6b 28 61 2c 62 29 20 20 FkOldmask(a,b)
26320 20 20 20 20 20 20 20 30 0a 20 20 23 64 65 66 69 0. #defi
26330 6e 65 20 73 71 6c 69 74 65 33 46 6b 52 65 71 75 ne sqlite3FkRequ
26340 69 72 65 64 28 61 2c 62 2c 63 2c 64 29 20 20 20 ired(a,b,c,d)
26350 20 30 0a 23 65 6e 64 69 66 0a 23 69 66 6e 64 65 0.#endif.#ifnde
26360 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4f f SQLITE_OMIT_FO
26370 52 45 49 47 4e 5f 4b 45 59 0a 20 20 76 6f 69 64 REIGN_KEY. void
26380 20 73 71 6c 69 74 65 33 46 6b 44 65 6c 65 74 65 sqlite3FkDelete
26390 28 73 71 6c 69 74 65 33 20 2a 2c 20 54 61 62 6c (sqlite3 *, Tabl
263a0 65 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 e*);. int sqlit
263b0 65 33 46 6b 4c 6f 63 61 74 65 49 6e 64 65 78 28 e3FkLocateIndex(
263c0 50 61 72 73 65 2a 2c 54 61 62 6c 65 2a 2c 46 4b Parse*,Table*,FK
263d0 65 79 2a 2c 49 6e 64 65 78 2a 2a 2c 69 6e 74 2a ey*,Index**,int*
263e0 2a 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 *);.#else. #def
263f0 69 6e 65 20 73 71 6c 69 74 65 33 46 6b 44 65 6c ine sqlite3FkDel
26400 65 74 65 28 61 2c 62 29 0a 20 20 23 64 65 66 69 ete(a,b). #defi
26410 6e 65 20 73 71 6c 69 74 65 33 46 6b 4c 6f 63 61 ne sqlite3FkLoca
26420 74 65 49 6e 64 65 78 28 61 2c 62 2c 63 2c 64 2c teIndex(a,b,c,d,
26430 65 29 0a 23 65 6e 64 69 66 0a 0a 0a 2f 2a 0a 2a e).#endif.../*.*
26440 2a 20 41 76 61 69 6c 61 62 6c 65 20 66 61 75 6c * Available faul
26450 74 20 69 6e 6a 65 63 74 6f 72 73 2e 20 20 53 68 t injectors. Sh
26460 6f 75 6c 64 20 62 65 20 6e 75 6d 62 65 72 65 64 ould be numbered
26470 20 62 65 67 69 6e 6e 69 6e 67 20 77 69 74 68 20 beginning with
26480 30 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 20 53 51 0..*/.#define SQ
26490 4c 49 54 45 5f 46 41 55 4c 54 49 4e 4a 45 43 54 LITE_FAULTINJECT
264a0 4f 52 5f 4d 41 4c 4c 4f 43 20 20 20 20 20 30 0a OR_MALLOC 0.
264b0 23 64 65 66 69 6e 65 20 53 51 4c 49 54 45 5f 46 #define SQLITE_F
264c0 41 55 4c 54 49 4e 4a 45 43 54 4f 52 5f 43 4f 55 AULTINJECTOR_COU
264d0 4e 54 20 20 20 20 20 20 31 0a 0a 2f 2a 0a 2a 2a NT 1../*.**
264e0 20 54 68 65 20 69 6e 74 65 72 66 61 63 65 20 74 The interface t
264f0 6f 20 74 68 65 20 63 6f 64 65 20 69 6e 20 66 61 o the code in fa
26500 75 6c 74 2e 63 20 75 73 65 64 20 66 6f 72 20 69 ult.c used for i
26510 64 65 6e 74 69 66 79 69 6e 67 20 22 62 65 6e 69 dentifying "beni
26520 67 6e 22 0a 2a 2a 20 6d 61 6c 6c 6f 63 20 66 61 gn".** malloc fa
26530 69 6c 75 72 65 73 2e 20 54 68 69 73 20 69 73 20 ilures. This is
26540 6f 6e 6c 79 20 70 72 65 73 65 6e 74 20 69 66 20 only present if
26550 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 42 55 49 4c SQLITE_OMIT_BUIL
26560 54 49 4e 5f 54 45 53 54 0a 2a 2a 20 69 73 20 6e TIN_TEST.** is n
26570 6f 74 20 64 65 66 69 6e 65 64 2e 0a 2a 2f 0a 23 ot defined..*/.#
26580 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
26590 49 54 5f 42 55 49 4c 54 49 4e 5f 54 45 53 54 0a IT_BUILTIN_TEST.
265a0 20 20 76 6f 69 64 20 73 71 6c 69 74 65 33 42 65 void sqlite3Be
265b0 67 69 6e 42 65 6e 69 67 6e 4d 61 6c 6c 6f 63 28 ginBenignMalloc(
265c0 76 6f 69 64 29 3b 0a 20 20 76 6f 69 64 20 73 71 void);. void sq
265d0 6c 69 74 65 33 45 6e 64 42 65 6e 69 67 6e 4d 61 lite3EndBenignMa
265e0 6c 6c 6f 63 28 76 6f 69 64 29 3b 0a 23 65 6c 73 lloc(void);.#els
265f0 65 0a 20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 e. #define sqli
26600 74 65 33 42 65 67 69 6e 42 65 6e 69 67 6e 4d 61 te3BeginBenignMa
26610 6c 6c 6f 63 28 29 0a 20 20 23 64 65 66 69 6e 65 lloc(). #define
26620 20 73 71 6c 69 74 65 33 45 6e 64 42 65 6e 69 67 sqlite3EndBenig
26630 6e 4d 61 6c 6c 6f 63 28 29 0a 23 65 6e 64 69 66 nMalloc().#endif
26640 0a 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 20 ../*.** Allowed
26650 72 65 74 75 72 6e 20 76 61 6c 75 65 73 20 66 72 return values fr
26660 6f 6d 20 73 71 6c 69 74 65 33 46 69 6e 64 49 6e om sqlite3FindIn
26670 49 6e 64 65 78 28 29 0a 2a 2f 0a 23 64 65 66 69 Index().*/.#defi
26680 6e 65 20 49 4e 5f 49 4e 44 45 58 5f 52 4f 57 49 ne IN_INDEX_ROWI
26690 44 20 20 20 20 20 20 20 20 31 20 20 20 2f 2a 20 D 1 /*
266a0 53 65 61 72 63 68 20 74 68 65 20 72 6f 77 69 64 Search the rowid
266b0 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 2a 2f of the table */
266c0 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 .#define IN_INDE
266d0 58 5f 45 50 48 20 20 20 20 20 20 20 20 20 20 32 X_EPH 2
266e0 20 20 20 2f 2a 20 53 65 61 72 63 68 20 61 6e 20 /* Search an
266f0 65 70 68 65 6d 65 72 61 6c 20 62 2d 74 72 65 65 ephemeral b-tree
26700 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f 49 */.#define IN_I
26710 4e 44 45 58 5f 49 4e 44 45 58 5f 41 53 43 20 20 NDEX_INDEX_ASC
26720 20 20 33 20 20 20 2f 2a 20 45 78 69 73 74 69 6e 3 /* Existin
26730 67 20 69 6e 64 65 78 20 41 53 43 45 4e 44 49 4e g index ASCENDIN
26740 47 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 4e 5f G */.#define IN_
26750 49 4e 44 45 58 5f 49 4e 44 45 58 5f 44 45 53 43 INDEX_INDEX_DESC
26760 20 20 20 34 20 20 20 2f 2a 20 45 78 69 73 74 69 4 /* Existi
26770 6e 67 20 69 6e 64 65 78 20 44 45 53 43 45 4e 44 ng index DESCEND
26780 49 4e 47 20 2a 2f 0a 23 64 65 66 69 6e 65 20 49 ING */.#define I
26790 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 20 20 20 20 N_INDEX_NOOP
267a0 20 20 20 20 20 35 20 20 20 2f 2a 20 4e 6f 20 74 5 /* No t
267b0 61 62 6c 65 20 61 76 61 69 6c 61 62 6c 65 2e 20 able available.
267c0 55 73 65 20 63 6f 6d 70 61 72 69 73 6f 6e 73 20 Use comparisons
267d0 2a 2f 0a 2f 2a 0a 2a 2a 20 41 6c 6c 6f 77 65 64 */./*.** Allowed
267e0 20 66 6c 61 67 73 20 66 6f 72 20 74 68 65 20 33 flags for the 3
267f0 72 64 20 70 61 72 61 6d 65 74 65 72 20 74 6f 20 rd parameter to
26800 73 71 6c 69 74 65 33 46 69 6e 64 49 6e 49 6e 64 sqlite3FindInInd
26810 65 78 28 29 2e 0a 2a 2f 0a 23 64 65 66 69 6e 65 ex()..*/.#define
26820 20 49 4e 5f 49 4e 44 45 58 5f 4e 4f 4f 50 5f 4f IN_INDEX_NOOP_O
26830 4b 20 20 20 20 20 30 78 30 30 30 31 20 20 2f 2a K 0x0001 /*
26840 20 4f 4b 20 74 6f 20 72 65 74 75 72 6e 20 49 4e OK to return IN
26850 5f 49 4e 44 45 58 5f 4e 4f 4f 50 20 2a 2f 0a 23 _INDEX_NOOP */.#
26860 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
26870 4d 45 4d 42 45 52 53 48 49 50 20 20 30 78 30 30 MEMBERSHIP 0x00
26880 30 32 20 20 2f 2a 20 49 4e 20 6f 70 65 72 61 74 02 /* IN operat
26890 6f 72 20 75 73 65 64 20 66 6f 72 20 6d 65 6d 62 or used for memb
268a0 65 72 73 68 69 70 20 74 65 73 74 20 2a 2f 0a 23 ership test */.#
268b0 64 65 66 69 6e 65 20 49 4e 5f 49 4e 44 45 58 5f define IN_INDEX_
268c0 4c 4f 4f 50 20 20 20 20 20 20 20 20 30 78 30 30 LOOP 0x00
268d0 30 34 20 20 2f 2a 20 49 4e 20 6f 70 65 72 61 74 04 /* IN operat
268e0 6f 72 20 75 73 65 64 20 61 73 20 61 20 6c 6f 6f or used as a loo
268f0 70 20 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 p */.int sqlite3
26900 46 69 6e 64 49 6e 49 6e 64 65 78 28 50 61 72 73 FindInIndex(Pars
26910 65 20 2a 2c 20 45 78 70 72 20 2a 2c 20 75 33 32 e *, Expr *, u32
26920 2c 20 69 6e 74 2a 29 3b 0a 0a 23 69 66 64 65 66 , int*);..#ifdef
26930 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 41 SQLITE_ENABLE_A
26940 54 4f 4d 49 43 5f 57 52 49 54 45 0a 20 20 69 6e TOMIC_WRITE. in
26950 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c t sqlite3Journal
26960 4f 70 65 6e 28 73 71 6c 69 74 65 33 5f 76 66 73 Open(sqlite3_vfs
26970 20 2a 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a *, const char *
26980 2c 20 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a , sqlite3_file *
26990 2c 20 69 6e 74 2c 20 69 6e 74 29 3b 0a 20 20 69 , int, int);. i
269a0 6e 74 20 73 71 6c 69 74 65 33 4a 6f 75 72 6e 61 nt sqlite3Journa
269b0 6c 53 69 7a 65 28 73 71 6c 69 74 65 33 5f 76 66 lSize(sqlite3_vf
269c0 73 20 2a 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 s *);. int sqli
269d0 74 65 33 4a 6f 75 72 6e 61 6c 43 72 65 61 74 65 te3JournalCreate
269e0 28 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a 29 (sqlite3_file *)
269f0 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 65 33 4a ;. int sqlite3J
26a00 6f 75 72 6e 61 6c 45 78 69 73 74 73 28 73 71 6c ournalExists(sql
26a10 69 74 65 33 5f 66 69 6c 65 20 2a 70 29 3b 0a 23 ite3_file *p);.#
26a20 65 6c 73 65 0a 20 20 23 64 65 66 69 6e 65 20 73 else. #define s
26a30 71 6c 69 74 65 33 4a 6f 75 72 6e 61 6c 53 69 7a qlite3JournalSiz
26a40 65 28 70 56 66 73 29 20 28 28 70 56 66 73 29 2d e(pVfs) ((pVfs)-
26a50 3e 73 7a 4f 73 46 69 6c 65 29 0a 20 20 23 64 65 >szOsFile). #de
26a60 66 69 6e 65 20 73 71 6c 69 74 65 33 4a 6f 75 72 fine sqlite3Jour
26a70 6e 61 6c 45 78 69 73 74 73 28 70 29 20 31 0a 23 nalExists(p) 1.#
26a80 65 6e 64 69 66 0a 0a 76 6f 69 64 20 73 71 6c 69 endif..void sqli
26a90 74 65 33 4d 65 6d 4a 6f 75 72 6e 61 6c 4f 70 65 te3MemJournalOpe
26aa0 6e 28 73 71 6c 69 74 65 33 5f 66 69 6c 65 20 2a n(sqlite3_file *
26ab0 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 4d 65 );.int sqlite3Me
26ac0 6d 4a 6f 75 72 6e 61 6c 53 69 7a 65 28 76 6f 69 mJournalSize(voi
26ad0 64 29 3b 0a 69 6e 74 20 73 71 6c 69 74 65 33 49 d);.int sqlite3I
26ae0 73 4d 65 6d 4a 6f 75 72 6e 61 6c 28 73 71 6c 69 sMemJournal(sqli
26af0 74 65 33 5f 66 69 6c 65 20 2a 29 3b 0a 0a 23 69 te3_file *);..#i
26b00 66 20 53 51 4c 49 54 45 5f 4d 41 58 5f 45 58 50 f SQLITE_MAX_EXP
26b10 52 5f 44 45 50 54 48 3e 30 0a 20 20 76 6f 69 64 R_DEPTH>0. void
26b20 20 73 71 6c 69 74 65 33 45 78 70 72 53 65 74 48 sqlite3ExprSetH
26b30 65 69 67 68 74 28 50 61 72 73 65 20 2a 70 50 61 eight(Parse *pPa
26b40 72 73 65 2c 20 45 78 70 72 20 2a 70 29 3b 0a 20 rse, Expr *p);.
26b50 20 69 6e 74 20 73 71 6c 69 74 65 33 53 65 6c 65 int sqlite3Sele
26b60 63 74 45 78 70 72 48 65 69 67 68 74 28 53 65 6c ctExprHeight(Sel
26b70 65 63 74 20 2a 29 3b 0a 20 20 69 6e 74 20 73 71 ect *);. int sq
26b80 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 lite3ExprCheckHe
26b90 69 67 68 74 28 50 61 72 73 65 2a 2c 20 69 6e 74 ight(Parse*, int
26ba0 29 3b 0a 23 65 6c 73 65 0a 20 20 23 64 65 66 69 );.#else. #defi
26bb0 6e 65 20 73 71 6c 69 74 65 33 45 78 70 72 53 65 ne sqlite3ExprSe
26bc0 74 48 65 69 67 68 74 28 78 2c 79 29 0a 20 20 23 tHeight(x,y). #
26bd0 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 53 65 define sqlite3Se
26be0 6c 65 63 74 45 78 70 72 48 65 69 67 68 74 28 78 lectExprHeight(x
26bf0 29 20 30 0a 20 20 23 64 65 66 69 6e 65 20 73 71 ) 0. #define sq
26c00 6c 69 74 65 33 45 78 70 72 43 68 65 63 6b 48 65 lite3ExprCheckHe
26c10 69 67 68 74 28 78 2c 79 29 0a 23 65 6e 64 69 66 ight(x,y).#endif
26c20 0a 0a 75 33 32 20 73 71 6c 69 74 65 33 47 65 74 ..u32 sqlite3Get
26c30 34 62 79 74 65 28 63 6f 6e 73 74 20 75 38 2a 29 4byte(const u8*)
26c40 3b 0a 76 6f 69 64 20 73 71 6c 69 74 65 33 50 75 ;.void sqlite3Pu
26c50 74 34 62 79 74 65 28 75 38 2a 2c 20 75 33 32 29 t4byte(u8*, u32)
26c60 3b 0a 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 ;..#ifdef SQLITE
26c70 5f 45 4e 41 42 4c 45 5f 55 4e 4c 4f 43 4b 5f 4e _ENABLE_UNLOCK_N
26c80 4f 54 49 46 59 0a 20 20 76 6f 69 64 20 73 71 6c OTIFY. void sql
26c90 69 74 65 33 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c ite3ConnectionBl
26ca0 6f 63 6b 65 64 28 73 71 6c 69 74 65 33 20 2a 2c ocked(sqlite3 *,
26cb0 20 73 71 6c 69 74 65 33 20 2a 29 3b 0a 20 20 76 sqlite3 *);. v
26cc0 6f 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 oid sqlite3Conne
26cd0 63 74 69 6f 6e 55 6e 6c 6f 63 6b 65 64 28 73 71 ctionUnlocked(sq
26ce0 6c 69 74 65 33 20 2a 64 62 29 3b 0a 20 20 76 6f lite3 *db);. vo
26cf0 69 64 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 id sqlite3Connec
26d00 74 69 6f 6e 43 6c 6f 73 65 64 28 73 71 6c 69 74 tionClosed(sqlit
26d10 65 33 20 2a 64 62 29 3b 0a 23 65 6c 73 65 0a 20 e3 *db);.#else.
26d20 20 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 #define sqlite3
26d30 43 6f 6e 6e 65 63 74 69 6f 6e 42 6c 6f 63 6b 65 ConnectionBlocke
26d40 64 28 78 2c 79 29 0a 20 20 23 64 65 66 69 6e 65 d(x,y). #define
26d50 20 73 71 6c 69 74 65 33 43 6f 6e 6e 65 63 74 69 sqlite3Connecti
26d60 6f 6e 55 6e 6c 6f 63 6b 65 64 28 78 29 0a 20 20 onUnlocked(x).
26d70 23 64 65 66 69 6e 65 20 73 71 6c 69 74 65 33 43 #define sqlite3C
26d80 6f 6e 6e 65 63 74 69 6f 6e 43 6c 6f 73 65 64 28 onnectionClosed(
26d90 78 29 0a 23 65 6e 64 69 66 0a 0a 23 69 66 64 65 x).#endif..#ifde
26da0 66 20 53 51 4c 49 54 45 5f 44 45 42 55 47 0a 20 f SQLITE_DEBUG.
26db0 20 76 6f 69 64 20 73 71 6c 69 74 65 33 50 61 72 void sqlite3Par
26dc0 73 65 72 54 72 61 63 65 28 46 49 4c 45 2a 2c 20 serTrace(FILE*,
26dd0 63 68 61 72 20 2a 29 3b 0a 23 65 6e 64 69 66 0a char *);.#endif.
26de0 0a 2f 2a 0a 2a 2a 20 49 66 20 74 68 65 20 53 51 ./*.** If the SQ
26df0 4c 49 54 45 5f 45 4e 41 42 4c 45 20 49 4f 54 52 LITE_ENABLE IOTR
26e00 41 43 45 20 65 78 69 73 74 73 20 74 68 65 6e 20 ACE exists then
26e10 74 68 65 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 the global varia
26e20 62 6c 65 0a 2a 2a 20 73 71 6c 69 74 65 33 49 6f ble.** sqlite3Io
26e30 54 72 61 63 65 20 69 73 20 61 20 70 6f 69 6e 74 Trace is a point
26e40 65 72 20 74 6f 20 61 20 70 72 69 6e 74 66 2d 6c er to a printf-l
26e50 69 6b 65 20 72 6f 75 74 69 6e 65 20 75 73 65 64 ike routine used
26e60 20 74 6f 0a 2a 2a 20 70 72 69 6e 74 20 49 2f 4f to.** print I/O
26e70 20 74 72 61 63 69 6e 67 20 6d 65 73 73 61 67 65 tracing message
26e80 73 2e 20 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 s. .*/.#ifdef SQ
26e90 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 49 4f 54 52 LITE_ENABLE_IOTR
26ea0 41 43 45 0a 23 20 64 65 66 69 6e 65 20 49 4f 54 ACE.# define IOT
26eb0 52 41 43 45 28 41 29 20 20 69 66 28 20 73 71 6c RACE(A) if( sql
26ec0 69 74 65 33 49 6f 54 72 61 63 65 20 29 7b 20 73 ite3IoTrace ){ s
26ed0 71 6c 69 74 65 33 49 6f 54 72 61 63 65 20 41 3b qlite3IoTrace A;
26ee0 20 7d 0a 20 20 76 6f 69 64 20 73 71 6c 69 74 65 }. void sqlite
26ef0 33 56 64 62 65 49 4f 54 72 61 63 65 53 71 6c 28 3VdbeIOTraceSql(
26f00 56 64 62 65 2a 29 3b 0a 53 51 4c 49 54 45 5f 45 Vdbe*);.SQLITE_E
26f10 58 54 45 52 4e 20 76 6f 69 64 20 28 2a 73 71 6c XTERN void (*sql
26f20 69 74 65 33 49 6f 54 72 61 63 65 29 28 63 6f 6e ite3IoTrace)(con
26f30 73 74 20 63 68 61 72 2a 2c 2e 2e 2e 29 3b 0a 23 st char*,...);.#
26f40 65 6c 73 65 0a 23 20 64 65 66 69 6e 65 20 49 4f else.# define IO
26f50 54 52 41 43 45 28 41 29 0a 23 20 64 65 66 69 6e TRACE(A).# defin
26f60 65 20 73 71 6c 69 74 65 33 56 64 62 65 49 4f 54 e sqlite3VdbeIOT
26f70 72 61 63 65 53 71 6c 28 58 29 0a 23 65 6e 64 69 raceSql(X).#endi
26f80 66 0a 0a 2f 2a 0a 2a 2a 20 54 68 65 73 65 20 72 f../*.** These r
26f90 6f 75 74 69 6e 65 73 20 61 72 65 20 61 76 61 69 outines are avai
26fa0 6c 61 62 6c 65 20 66 6f 72 20 74 68 65 20 6d 65 lable for the me
26fb0 6d 32 2e 63 20 64 65 62 75 67 67 69 6e 67 20 6d m2.c debugging m
26fc0 65 6d 6f 72 79 20 61 6c 6c 6f 63 61 74 6f 72 0a emory allocator.
26fd0 2a 2a 20 6f 6e 6c 79 2e 20 20 54 68 65 79 20 61 ** only. They a
26fe0 72 65 20 75 73 65 64 20 74 6f 20 76 65 72 69 66 re used to verif
26ff0 79 20 74 68 61 74 20 64 69 66 66 65 72 65 6e 74 y that different
27000 20 22 74 79 70 65 73 22 20 6f 66 20 6d 65 6d 6f "types" of memo
27010 72 79 0a 2a 2a 20 61 6c 6c 6f 63 61 74 69 6f 6e ry.** allocation
27020 73 20 61 72 65 20 70 72 6f 70 65 72 6c 79 20 74 s are properly t
27030 72 61 63 6b 65 64 20 62 79 20 74 68 65 20 73 79 racked by the sy
27040 73 74 65 6d 2e 0a 2a 2a 0a 2a 2a 20 73 71 6c 69 stem..**.** sqli
27050 74 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 te3MemdebugSetTy
27060 70 65 28 29 20 73 65 74 73 20 74 68 65 20 22 74 pe() sets the "t
27070 79 70 65 22 20 6f 66 20 61 6e 20 61 6c 6c 6f 63 ype" of an alloc
27080 61 74 69 6f 6e 20 74 6f 20 6f 6e 65 20 6f 66 0a ation to one of.
27090 2a 2a 20 74 68 65 20 4d 45 4d 54 59 50 45 5f 2a ** the MEMTYPE_*
270a0 20 6d 61 63 72 6f 73 20 64 65 66 69 6e 65 64 20 macros defined
270b0 62 65 6c 6f 77 2e 20 20 54 68 65 20 74 79 70 65 below. The type
270c0 20 6d 75 73 74 20 62 65 20 61 20 62 69 74 6d 61 must be a bitma
270d0 73 6b 20 77 69 74 68 0a 2a 2a 20 61 20 73 69 6e sk with.** a sin
270e0 67 6c 65 20 62 69 74 20 73 65 74 2e 0a 2a 2a 0a gle bit set..**.
270f0 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ** sqlite3Memdeb
27100 75 67 48 61 73 54 79 70 65 28 29 20 72 65 74 75 ugHasType() retu
27110 72 6e 73 20 74 72 75 65 20 69 66 20 61 6e 79 20 rns true if any
27120 6f 66 20 74 68 65 20 62 69 74 73 20 69 6e 20 69 of the bits in i
27130 74 73 20 73 65 63 6f 6e 64 0a 2a 2a 20 61 72 67 ts second.** arg
27140 75 6d 65 6e 74 20 6d 61 74 63 68 20 74 68 65 20 ument match the
27150 74 79 70 65 20 73 65 74 20 62 79 20 74 68 65 20 type set by the
27160 70 72 65 76 69 6f 75 73 20 73 71 6c 69 74 65 33 previous sqlite3
27170 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 65 28 MemdebugSetType(
27180 29 2e 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d )..** sqlite3Mem
27190 64 65 62 75 67 48 61 73 54 79 70 65 28 29 20 69 debugHasType() i
271a0 73 20 69 6e 74 65 6e 64 65 64 20 66 6f 72 20 75 s intended for u
271b0 73 65 20 69 6e 73 69 64 65 20 61 73 73 65 72 74 se inside assert
271c0 28 29 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 2a () statements..*
271d0 2a 0a 2a 2a 20 73 71 6c 69 74 65 33 4d 65 6d 64 *.** sqlite3Memd
271e0 65 62 75 67 4e 6f 54 79 70 65 28 29 20 72 65 74 ebugNoType() ret
271f0 75 72 6e 73 20 74 72 75 65 20 69 66 20 6e 6f 6e urns true if non
27200 65 20 6f 66 20 74 68 65 20 62 69 74 73 20 69 6e e of the bits in
27210 20 69 74 73 20 73 65 63 6f 6e 64 0a 2a 2a 20 61 its second.** a
27220 72 67 75 6d 65 6e 74 20 6d 61 74 63 68 20 74 68 rgument match th
27230 65 20 74 79 70 65 20 73 65 74 20 62 79 20 74 68 e type set by th
27240 65 20 70 72 65 76 69 6f 75 73 20 73 71 6c 69 74 e previous sqlit
27250 65 33 4d 65 6d 64 65 62 75 67 53 65 74 54 79 70 e3MemdebugSetTyp
27260 65 28 29 2e 0a 2a 2a 0a 2a 2a 20 50 65 72 68 61 e()..**.** Perha
27270 70 73 20 74 68 65 20 6d 6f 73 74 20 69 6d 70 6f ps the most impo
27280 72 74 61 6e 74 20 70 6f 69 6e 74 20 69 73 20 74 rtant point is t
27290 68 65 20 64 69 66 66 65 72 65 6e 63 65 20 62 65 he difference be
272a0 74 77 65 65 6e 20 4d 45 4d 54 59 50 45 5f 48 45 tween MEMTYPE_HE
272b0 41 50 0a 2a 2a 20 61 6e 64 20 4d 45 4d 54 59 50 AP.** and MEMTYP
272c0 45 5f 4c 4f 4f 4b 41 53 49 44 45 2e 20 20 49 66 E_LOOKASIDE. If
272d0 20 61 6e 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69 an allocation i
272e0 73 20 4d 45 4d 54 59 50 45 5f 4c 4f 4f 4b 41 53 s MEMTYPE_LOOKAS
272f0 49 44 45 2c 20 74 68 61 74 20 6d 65 61 6e 73 0a IDE, that means.
27300 2a 2a 20 69 74 20 6d 69 67 68 74 20 68 61 76 65 ** it might have
27310 20 62 65 65 6e 20 61 6c 6c 6f 63 61 74 65 64 20 been allocated
27320 62 79 20 6c 6f 6f 6b 61 73 69 64 65 2c 20 65 78 by lookaside, ex
27330 63 65 70 74 20 74 68 65 20 61 6c 6c 6f 63 61 74 cept the allocat
27340 69 6f 6e 20 77 61 73 0a 2a 2a 20 74 6f 6f 20 6c ion was.** too l
27350 61 72 67 65 20 6f 72 20 6c 6f 6f 6b 61 73 69 64 arge or lookasid
27360 65 20 77 61 73 20 61 6c 72 65 61 64 79 20 66 75 e was already fu
27370 6c 6c 2e 20 20 49 74 20 69 73 20 69 6d 70 6f 72 ll. It is impor
27380 74 61 6e 74 20 74 6f 20 76 65 72 69 66 79 0a 2a tant to verify.*
27390 2a 20 74 68 61 74 20 61 6c 6c 6f 63 61 74 69 6f * that allocatio
273a0 6e 73 20 74 68 61 74 20 6d 69 67 68 74 20 68 61 ns that might ha
273b0 76 65 20 62 65 65 6e 20 73 61 74 69 73 66 69 65 ve been satisfie
273c0 64 20 62 79 20 6c 6f 6f 6b 61 73 69 64 65 20 61 d by lookaside a
273d0 72 65 20 6e 6f 74 0a 2a 2a 20 70 61 73 73 65 64 re not.** passed
273e0 20 62 61 63 6b 20 74 6f 20 6e 6f 6e 2d 6c 6f 6f back to non-loo
273f0 6b 61 73 69 64 65 20 66 72 65 65 28 29 20 72 6f kaside free() ro
27400 75 74 69 6e 65 73 2e 20 20 41 73 73 65 72 74 73 utines. Asserts
27410 20 73 75 63 68 20 61 73 20 74 68 65 0a 2a 2a 20 such as the.**
27420 65 78 61 6d 70 6c 65 20 61 62 6f 76 65 20 61 72 example above ar
27430 65 20 70 6c 61 63 65 64 20 6f 6e 20 74 68 65 20 e placed on the
27440 6e 6f 6e 2d 6c 6f 6f 6b 61 73 69 64 65 20 66 72 non-lookaside fr
27450 65 65 28 29 20 72 6f 75 74 69 6e 65 73 20 74 6f ee() routines to
27460 20 76 65 72 69 66 79 0a 2a 2a 20 74 68 69 73 20 verify.** this
27470 63 6f 6e 73 74 72 61 69 6e 74 2e 20 0a 2a 2a 0a constraint. .**.
27480 2a 2a 20 41 6c 6c 20 6f 66 20 74 68 69 73 20 69 ** All of this i
27490 73 20 6e 6f 2d 6f 70 20 66 6f 72 20 61 20 70 72 s no-op for a pr
274a0 6f 64 75 63 74 69 6f 6e 20 62 75 69 6c 64 2e 20 oduction build.
274b0 20 49 74 20 6f 6e 6c 79 20 63 6f 6d 65 73 20 69 It only comes i
274c0 6e 74 6f 0a 2a 2a 20 70 6c 61 79 20 77 68 65 6e nto.** play when
274d0 20 74 68 65 20 53 51 4c 49 54 45 5f 4d 45 4d 44 the SQLITE_MEMD
274e0 45 42 55 47 20 63 6f 6d 70 69 6c 65 2d 74 69 6d EBUG compile-tim
274f0 65 20 6f 70 74 69 6f 6e 20 69 73 20 75 73 65 64 e option is used
27500 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 ..*/.#ifdef SQLI
27510 54 45 5f 4d 45 4d 44 45 42 55 47 0a 20 20 76 6f TE_MEMDEBUG. vo
27520 69 64 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 id sqlite3Memdeb
27530 75 67 53 65 74 54 79 70 65 28 76 6f 69 64 2a 2c ugSetType(void*,
27540 75 38 29 3b 0a 20 20 69 6e 74 20 73 71 6c 69 74 u8);. int sqlit
27550 65 33 4d 65 6d 64 65 62 75 67 48 61 73 54 79 70 e3MemdebugHasTyp
27560 65 28 76 6f 69 64 2a 2c 75 38 29 3b 0a 20 20 69 e(void*,u8);. i
27570 6e 74 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 nt sqlite3Memdeb
27580 75 67 4e 6f 54 79 70 65 28 76 6f 69 64 2a 2c 75 ugNoType(void*,u
27590 38 29 3b 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 8);.#else.# defi
275a0 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 65 62 ne sqlite3Memdeb
275b0 75 67 53 65 74 54 79 70 65 28 58 2c 59 29 20 20 ugSetType(X,Y)
275c0 2f 2a 20 6e 6f 2d 6f 70 20 2a 2f 0a 23 20 64 65 /* no-op */.# de
275d0 66 69 6e 65 20 73 71 6c 69 74 65 33 4d 65 6d 64 fine sqlite3Memd
275e0 65 62 75 67 48 61 73 54 79 70 65 28 58 2c 59 29 ebugHasType(X,Y)
275f0 20 20 31 0a 23 20 64 65 66 69 6e 65 20 73 71 6c 1.# define sql
27600 69 74 65 33 4d 65 6d 64 65 62 75 67 4e 6f 54 79 ite3MemdebugNoTy
27610 70 65 28 58 2c 59 29 20 20 20 31 0a 23 65 6e 64 pe(X,Y) 1.#end
27620 69 66 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 if.#define MEMTY
27630 50 45 5f 48 45 41 50 20 20 20 20 20 20 20 30 78 PE_HEAP 0x
27640 30 31 20 20 2f 2a 20 47 65 6e 65 72 61 6c 20 68 01 /* General h
27650 65 61 70 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 eap allocations
27660 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 59 */.#define MEMTY
27670 50 45 5f 4c 4f 4f 4b 41 53 49 44 45 20 20 30 78 PE_LOOKASIDE 0x
27680 30 32 20 20 2f 2a 20 4d 69 67 68 74 20 68 61 76 02 /* Might hav
27690 65 20 62 65 65 6e 20 6c 6f 6f 6b 61 73 69 64 65 e been lookaside
276a0 20 6d 65 6d 6f 72 79 20 2a 2f 0a 23 64 65 66 69 memory */.#defi
276b0 6e 65 20 4d 45 4d 54 59 50 45 5f 53 43 52 41 54 ne MEMTYPE_SCRAT
276c0 43 48 20 20 20 20 30 78 30 34 20 20 2f 2a 20 53 CH 0x04 /* S
276d0 63 72 61 74 63 68 20 61 6c 6c 6f 63 61 74 69 6f cratch allocatio
276e0 6e 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 ns */.#define ME
276f0 4d 54 59 50 45 5f 50 43 41 43 48 45 20 20 20 20 MTYPE_PCACHE
27700 20 30 78 30 38 20 20 2f 2a 20 50 61 67 65 20 63 0x08 /* Page c
27710 61 63 68 65 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 ache allocations
27720 20 2a 2f 0a 23 64 65 66 69 6e 65 20 4d 45 4d 54 */.#define MEMT
27730 59 50 45 5f 44 42 20 20 20 20 20 20 20 20 20 30 YPE_DB 0
27740 78 31 30 20 20 2f 2a 20 55 73 65 73 20 73 71 6c x10 /* Uses sql
27750 69 74 65 33 44 62 4d 61 6c 6c 6f 63 2c 20 6e 6f ite3DbMalloc, no
27760 74 20 73 71 6c 69 74 65 5f 6d 61 6c 6c 6f 63 20 t sqlite_malloc
27770 2a 2f 0a 0a 0a 23 69 66 20 28 53 51 4c 49 54 45 */...#if (SQLITE
27780 5f 45 4e 41 42 4c 45 5f 41 50 50 4c 45 5f 53 50 _ENABLE_APPLE_SP
27790 49 3e 30 29 20 26 26 20 64 65 66 69 6e 65 64 28 I>0) && defined(
277a0 5f 5f 41 50 50 4c 45 5f 5f 29 0a 0a 2f 2a 0a 2a __APPLE__)../*.*
277b0 2a 20 41 6e 20 69 6e 73 74 61 6e 63 65 20 6f 66 * An instance of
277c0 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 the following s
277d0 74 72 75 63 74 75 72 65 20 69 73 20 75 73 65 64 tructure is used
277e0 20 74 6f 20 68 6f 6c 64 20 74 68 65 20 70 72 6f to hold the pro
277f0 63 65 73 73 20 49 44 0a 2a 2a 20 61 6e 64 20 72 cess ID.** and r
27800 65 74 75 72 6e 2d 62 79 2d 72 65 66 65 72 65 6e eturn-by-referen
27810 63 65 20 6c 6f 63 6b 73 74 61 74 65 20 76 61 6c ce lockstate val
27820 75 65 2e 20 20 54 68 65 20 53 51 4c 49 54 45 5f ue. The SQLITE_
27830 46 43 4e 54 4c 5f 4c 4f 43 4b 53 54 41 54 45 5f FCNTL_LOCKSTATE_
27840 50 49 44 0a 2a 2a 20 72 65 71 75 69 72 65 73 20 PID.** requires
27850 74 68 65 20 34 74 68 20 61 72 67 75 6d 65 6e 74 the 4th argument
27860 20 74 6f 20 73 71 6c 69 74 65 33 5f 66 69 6c 65 to sqlite3_file
27870 5f 63 6f 6e 74 72 6f 6c 20 74 6f 20 62 65 20 61 _control to be a
27880 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 6e 0a 2a pointer to an.*
27890 2a 20 69 6e 73 74 61 6e 63 65 20 6f 66 20 4c 6f * instance of Lo
278a0 63 6b 73 74 61 74 65 50 49 44 20 69 6e 69 74 69 ckstatePID initi
278b0 61 6c 69 7a 65 64 20 77 69 74 68 20 61 20 4c 6f alized with a Lo
278c0 63 6b 73 74 61 74 65 50 49 44 2e 70 69 64 20 76 ckstatePID.pid v
278d0 61 6c 75 65 20 65 71 75 61 6c 0a 2a 2a 20 74 6f alue equal.** to
278e0 20 61 20 70 72 6f 63 65 73 73 20 49 44 20 74 6f a process ID to
278f0 20 62 65 20 74 65 73 74 65 64 2c 20 6f 72 20 74 be tested, or t
27900 68 65 20 73 70 65 63 69 61 6c 20 76 61 6c 75 65 he special value
27910 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 54 SQLITE_LOCKSTAT
27920 45 5f 41 4e 59 50 49 44 0a 2a 2a 20 54 68 65 20 E_ANYPID.** The
27930 4c 6f 63 6b 73 74 61 74 65 2e 73 74 61 74 65 20 Lockstate.state
27940 76 61 6c 75 65 20 69 73 20 61 6c 77 61 79 73 20 value is always
27950 73 65 74 20 74 6f 20 6f 6e 65 20 6f 66 20 74 68 set to one of th
27960 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 76 61 6c 75 e following valu
27970 65 73 0a 2a 2a 20 77 68 65 6e 20 73 71 6c 69 74 es.** when sqlit
27980 65 33 5f 66 69 6c 65 5f 63 6f 6e 74 72 6f 6c 20 e3_file_control
27990 72 65 74 75 72 6e 73 3a 0a 2a 2a 20 0a 2a 2a 20 returns:.** .**
279a0 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 SQLITE_LOCKSTA
279b0 54 45 5f 4f 46 46 20 20 20 20 6e 6f 20 61 63 74 TE_OFF no act
279c0 69 76 65 20 73 71 6c 69 74 65 20 66 69 6c 65 20 ive sqlite file
279d0 6c 6f 63 6b 73 20 6d 61 74 63 68 20 74 68 65 20 locks match the
279e0 73 70 65 63 69 66 69 65 64 20 70 69 64 0a 2a 2a specified pid.**
279f0 20 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 SQLITE_LOCKST
27a00 41 54 45 5f 4f 4e 20 20 20 20 20 61 63 74 69 76 ATE_ON activ
27a10 65 20 73 71 6c 69 74 65 20 66 69 6c 65 20 6c 6f e sqlite file lo
27a20 63 6b 73 20 6d 61 74 63 68 20 74 68 65 20 73 70 cks match the sp
27a30 65 63 69 66 69 65 64 20 70 69 64 0a 2a 2a 20 20 ecified pid.**
27a40 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 54 SQLITE_LOCKSTAT
27a50 45 5f 4e 4f 54 41 44 42 20 70 61 74 68 20 70 6f E_NOTADB path po
27a60 69 6e 74 73 20 74 6f 20 61 20 66 69 6c 65 20 74 ints to a file t
27a70 68 61 74 20 69 73 20 6e 6f 74 20 61 6e 20 73 71 hat is not an sq
27a80 6c 69 74 65 20 64 62 20 66 69 6c 65 0a 2a 2a 20 lite db file.**
27a90 20 20 53 51 4c 49 54 45 5f 4c 4f 43 4b 53 54 41 SQLITE_LOCKSTA
27aa0 54 45 5f 45 52 52 4f 52 20 20 70 61 74 68 20 77 TE_ERROR path w
27ab0 61 73 20 6e 6f 74 20 76 61 69 6c 64 20 6f 72 20 as not vaild or
27ac0 77 61 73 20 75 6e 72 65 61 64 61 62 6c 65 0a 2a was unreadable.*
27ad0 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
27ae0 20 4c 6f 63 6b 73 74 61 74 65 50 49 44 20 4c 6f LockstatePID Lo
27af0 63 6b 73 74 61 74 65 50 49 44 3b 0a 73 74 72 75 ckstatePID;.stru
27b00 63 74 20 4c 6f 63 6b 73 74 61 74 65 50 49 44 20 ct LockstatePID
27b10 7b 0a 20 20 70 69 64 5f 74 20 70 69 64 3b 20 20 {. pid_t pid;
27b20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f /
27b30 2a 20 50 72 6f 63 65 73 73 20 49 44 20 74 6f 20 * Process ID to
27b40 74 65 73 74 20 2a 2f 0a 20 20 69 6e 74 20 73 74 test */. int st
27b50 61 74 65 3b 20 20 20 20 20 20 20 20 20 20 20 20 ate;
27b60 20 20 20 20 20 2f 2a 20 54 68 65 20 73 74 61 74 /* The stat
27b70 65 20 6f 66 20 74 68 65 20 6c 6f 63 6b 20 28 72 e of the lock (r
27b80 65 74 75 72 6e 20 76 61 6c 75 65 29 20 2a 2f 0a eturn value) */.
27b90 7d 3b 0a 0a 23 65 6e 64 69 66 0a 0a 23 65 6e 64 };..#endif..#end
27ba0 69 66 20 2f 2a 20 5f 53 51 4c 49 54 45 49 4e 54 if /* _SQLITEINT
27bb0 5f 48 5f 20 2a 2f 0a _H_ */.