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 41 6e 20 74 6f 6b ******.** An tok
0180: 65 6e 69 7a 65 72 20 66 6f 72 20 53 51 4c 0a 2a enizer for SQL.*
0190: 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 20 63 *.** This file c
01a0: 6f 6e 74 61 69 6e 73 20 43 20 63 6f 64 65 20 74 ontains C code t
01b0: 68 61 74 20 73 70 6c 69 74 73 20 61 6e 20 53 51 hat splits an SQ
01c0: 4c 20 69 6e 70 75 74 20 73 74 72 69 6e 67 20 75 L input string u
01d0: 70 20 69 6e 74 6f 0a 2a 2a 20 69 6e 64 69 76 69 p into.** indivi
01e0: 64 75 61 6c 20 74 6f 6b 65 6e 73 20 61 6e 64 20 dual tokens and
01f0: 73 65 6e 64 73 20 74 68 6f 73 65 20 74 6f 6b 65 sends those toke
0200: 6e 73 20 6f 6e 65 2d 62 79 2d 6f 6e 65 20 6f 76 ns one-by-one ov
0210: 65 72 20 74 6f 20 74 68 65 0a 2a 2a 20 70 61 72 er to the.** par
0220: 73 65 72 20 66 6f 72 20 61 6e 61 6c 79 73 69 73 ser for analysis
0230: 2e 0a 2a 2a 0a 2a 2a 20 24 49 64 3a 20 74 6f 6b ..**.** $Id: tok
0240: 65 6e 69 7a 65 2e 63 2c 76 20 31 2e 36 36 20 32 enize.c,v 1.66 2
0250: 30 30 33 2f 31 32 2f 32 33 20 30 32 3a 31 37 3a 003/12/23 02:17:
0260: 33 35 20 64 72 68 20 45 78 70 20 24 0a 2a 2f 0a 35 drh Exp $.*/.
0270: 23 69 6e 63 6c 75 64 65 20 22 73 71 6c 69 74 65 #include "sqlite
0280: 49 6e 74 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 Int.h".#include
0290: 22 6f 73 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 "os.h".#include
02a0: 3c 63 74 79 70 65 2e 68 3e 0a 23 69 6e 63 6c 75 <ctype.h>.#inclu
02b0: 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 0a 2f de <stdlib.h>../
02c0: 2a 0a 2a 2a 20 41 6c 6c 20 74 68 65 20 6b 65 79 *.** All the key
02d0: 77 6f 72 64 73 20 6f 66 20 74 68 65 20 53 51 4c words of the SQL
02e0: 20 6c 61 6e 67 75 61 67 65 20 61 72 65 20 73 74 language are st
02f0: 6f 72 65 64 20 61 73 20 69 6e 20 61 20 68 61 73 ored as in a has
0300: 68 0a 2a 2a 20 74 61 62 6c 65 20 63 6f 6d 70 6f h.** table compo
0310: 73 65 64 20 6f 66 20 69 6e 73 74 61 6e 63 65 73 sed of instances
0320: 20 6f 66 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e of the followin
0330: 67 20 73 74 72 75 63 74 75 72 65 2e 0a 2a 2f 0a g structure..*/.
0340: 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20 4b typedef struct K
0350: 65 79 77 6f 72 64 20 4b 65 79 77 6f 72 64 3b 0a eyword Keyword;.
0360: 73 74 72 75 63 74 20 4b 65 79 77 6f 72 64 20 7b struct Keyword {
0370: 0a 20 20 63 68 61 72 20 2a 7a 4e 61 6d 65 3b 20 . char *zName;
0380: 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 /* T
0390: 68 65 20 6b 65 79 77 6f 72 64 20 6e 61 6d 65 20 he keyword name
03a0: 2a 2f 0a 20 20 75 31 36 20 6c 65 6e 3b 20 20 20 */. u16 len;
03b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
03c0: 20 4e 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 Number of chara
03d0: 63 74 65 72 73 20 69 6e 20 74 68 65 20 6b 65 79 cters in the key
03e0: 77 6f 72 64 20 2a 2f 0a 20 20 75 31 36 20 74 6f word */. u16 to
03f0: 6b 65 6e 54 79 70 65 3b 20 20 20 20 20 20 20 20 kenType;
0400: 20 20 20 2f 2a 20 54 68 65 20 74 6f 6b 65 6e 20 /* The token
0410: 76 61 6c 75 65 20 66 6f 72 20 74 68 69 73 20 6b value for this k
0420: 65 79 77 6f 72 64 20 2a 2f 0a 20 20 4b 65 79 77 eyword */. Keyw
0430: 6f 72 64 20 2a 70 4e 65 78 74 3b 20 20 20 20 20 ord *pNext;
0440: 20 20 20 20 20 2f 2a 20 4e 65 78 74 20 6b 65 79 /* Next key
0450: 77 6f 72 64 20 77 69 74 68 20 74 68 65 20 73 61 word with the sa
0460: 6d 65 20 68 61 73 68 20 2a 2f 0a 7d 3b 0a 0a 2f me hash */.};../
0470: 2a 0a 2a 2a 20 54 68 65 73 65 20 61 72 65 20 74 *.** These are t
0480: 68 65 20 6b 65 79 77 6f 72 64 73 0a 2a 2f 0a 73 he keywords.*/.s
0490: 74 61 74 69 63 20 4b 65 79 77 6f 72 64 20 61 4b tatic Keyword aK
04a0: 65 79 77 6f 72 64 54 61 62 6c 65 5b 5d 20 3d 20 eywordTable[] =
04b0: 7b 0a 20 20 7b 20 22 41 42 4f 52 54 22 2c 20 20 {. { "ABORT",
04c0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
04d0: 5f 41 42 4f 52 54 2c 20 20 20 20 20 20 20 20 20 _ABORT,
04e0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 41 46 54 0 },. { "AFT
04f0: 45 52 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 ER",
0500: 20 30 2c 20 54 4b 5f 41 46 54 45 52 2c 20 20 20 0, TK_AFTER,
0510: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0520: 7b 20 22 41 4c 4c 22 2c 20 20 20 20 20 20 20 20 { "ALL",
0530: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 41 4c 4c 0, TK_ALL
0540: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
0550: 20 7d 2c 0a 20 20 7b 20 22 41 4e 44 22 2c 20 20 },. { "AND",
0560: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
0570: 54 4b 5f 41 4e 44 2c 20 20 20 20 20 20 20 20 20 TK_AND,
0580: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 41 0 },. { "A
0590: 53 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 S",
05a0: 20 20 20 30 2c 20 54 4b 5f 41 53 2c 20 20 20 20 0, TK_AS,
05b0: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
05c0: 20 20 7b 20 22 41 53 43 22 2c 20 20 20 20 20 20 { "ASC",
05d0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 41 0, TK_A
05e0: 53 43 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 SC,
05f0: 20 30 20 7d 2c 0a 20 20 7b 20 22 41 54 54 41 43 0 },. { "ATTAC
0600: 48 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 H", 0
0610: 2c 20 54 4b 5f 41 54 54 41 43 48 2c 20 20 20 20 , TK_ATTACH,
0620: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0630: 22 42 45 46 4f 52 45 22 2c 20 20 20 20 20 20 20 "BEFORE",
0640: 20 20 20 20 20 30 2c 20 54 4b 5f 42 45 46 4f 52 0, TK_BEFOR
0650: 45 2c 20 20 20 20 20 20 20 20 20 20 20 30 20 7d E, 0 }
0660: 2c 0a 20 20 7b 20 22 42 45 47 49 4e 22 2c 20 20 ,. { "BEGIN",
0670: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0680: 5f 42 45 47 49 4e 2c 20 20 20 20 20 20 20 20 20 _BEGIN,
0690: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 42 45 54 0 },. { "BET
06a0: 57 45 45 4e 22 2c 20 20 20 20 20 20 20 20 20 20 WEEN",
06b0: 20 30 2c 20 54 4b 5f 42 45 54 57 45 45 4e 2c 20 0, TK_BETWEEN,
06c0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
06d0: 7b 20 22 42 59 22 2c 20 20 20 20 20 20 20 20 20 { "BY",
06e0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 42 59 2c 0, TK_BY,
06f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
0700: 20 7d 2c 0a 20 20 7b 20 22 43 41 53 43 41 44 45 },. { "CASCADE
0710: 22 2c 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 ", 0,
0720: 54 4b 5f 43 41 53 43 41 44 45 2c 20 20 20 20 20 TK_CASCADE,
0730: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 43 0 },. { "C
0740: 41 53 45 22 2c 20 20 20 20 20 20 20 20 20 20 20 ASE",
0750: 20 20 20 30 2c 20 54 4b 5f 43 41 53 45 2c 20 20 0, TK_CASE,
0760: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0770: 20 20 7b 20 22 43 48 45 43 4b 22 2c 20 20 20 20 { "CHECK",
0780: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 43 0, TK_C
0790: 48 45 43 4b 2c 20 20 20 20 20 20 20 20 20 20 20 HECK,
07a0: 20 30 20 7d 2c 0a 20 20 7b 20 22 43 4c 55 53 54 0 },. { "CLUST
07b0: 45 52 22 2c 20 20 20 20 20 20 20 20 20 20 20 30 ER", 0
07c0: 2c 20 54 4b 5f 43 4c 55 53 54 45 52 2c 20 20 20 , TK_CLUSTER,
07d0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
07e0: 22 43 4f 4c 4c 41 54 45 22 2c 20 20 20 20 20 20 "COLLATE",
07f0: 20 20 20 20 20 30 2c 20 54 4b 5f 43 4f 4c 4c 41 0, TK_COLLA
0800: 54 45 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d TE, 0 }
0810: 2c 0a 20 20 7b 20 22 43 4f 4d 4d 49 54 22 2c 20 ,. { "COMMIT",
0820: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0830: 5f 43 4f 4d 4d 49 54 2c 20 20 20 20 20 20 20 20 _COMMIT,
0840: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 43 4f 4e 0 },. { "CON
0850: 46 4c 49 43 54 22 2c 20 20 20 20 20 20 20 20 20 FLICT",
0860: 20 30 2c 20 54 4b 5f 43 4f 4e 46 4c 49 43 54 2c 0, TK_CONFLICT,
0870: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0880: 7b 20 22 43 4f 4e 53 54 52 41 49 4e 54 22 2c 20 { "CONSTRAINT",
0890: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 43 4f 4e 0, TK_CON
08a0: 53 54 52 41 49 4e 54 2c 20 20 20 20 20 20 20 30 STRAINT, 0
08b0: 20 7d 2c 0a 20 20 7b 20 22 43 4f 50 59 22 2c 20 },. { "COPY",
08c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
08d0: 54 4b 5f 43 4f 50 59 2c 20 20 20 20 20 20 20 20 TK_COPY,
08e0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 43 0 },. { "C
08f0: 52 45 41 54 45 22 2c 20 20 20 20 20 20 20 20 20 REATE",
0900: 20 20 20 30 2c 20 54 4b 5f 43 52 45 41 54 45 2c 0, TK_CREATE,
0910: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0920: 20 20 7b 20 22 43 52 4f 53 53 22 2c 20 20 20 20 { "CROSS",
0930: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4a 0, TK_J
0940: 4f 49 4e 5f 4b 57 2c 20 20 20 20 20 20 20 20 20 OIN_KW,
0950: 20 30 20 7d 2c 0a 20 20 7b 20 22 44 41 54 41 42 0 },. { "DATAB
0960: 41 53 45 22 2c 20 20 20 20 20 20 20 20 20 20 30 ASE", 0
0970: 2c 20 54 4b 5f 44 41 54 41 42 41 53 45 2c 20 20 , TK_DATABASE,
0980: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0990: 22 44 45 46 41 55 4c 54 22 2c 20 20 20 20 20 20 "DEFAULT",
09a0: 20 20 20 20 20 30 2c 20 54 4b 5f 44 45 46 41 55 0, TK_DEFAU
09b0: 4c 54 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d LT, 0 }
09c0: 2c 0a 20 20 7b 20 22 44 45 46 45 52 52 45 44 22 ,. { "DEFERRED"
09d0: 2c 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b , 0, TK
09e0: 5f 44 45 46 45 52 52 45 44 2c 20 20 20 20 20 20 _DEFERRED,
09f0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 44 45 46 0 },. { "DEF
0a00: 45 52 52 41 42 4c 45 22 2c 20 20 20 20 20 20 20 ERRABLE",
0a10: 20 30 2c 20 54 4b 5f 44 45 46 45 52 52 41 42 4c 0, TK_DEFERRABL
0a20: 45 2c 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 E, 0 },.
0a30: 7b 20 22 44 45 4c 45 54 45 22 2c 20 20 20 20 20 { "DELETE",
0a40: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 44 45 4c 0, TK_DEL
0a50: 45 54 45 2c 20 20 20 20 20 20 20 20 20 20 20 30 ETE, 0
0a60: 20 7d 2c 0a 20 20 7b 20 22 44 45 4c 49 4d 49 54 },. { "DELIMIT
0a70: 45 52 53 22 2c 20 20 20 20 20 20 20 20 30 2c 20 ERS", 0,
0a80: 54 4b 5f 44 45 4c 49 4d 49 54 45 52 53 2c 20 20 TK_DELIMITERS,
0a90: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 44 0 },. { "D
0aa0: 45 53 43 22 2c 20 20 20 20 20 20 20 20 20 20 20 ESC",
0ab0: 20 20 20 30 2c 20 54 4b 5f 44 45 53 43 2c 20 20 0, TK_DESC,
0ac0: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0ad0: 20 20 7b 20 22 44 45 54 41 43 48 22 2c 20 20 20 { "DETACH",
0ae0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 44 0, TK_D
0af0: 45 54 41 43 48 2c 20 20 20 20 20 20 20 20 20 20 ETACH,
0b00: 20 30 20 7d 2c 0a 20 20 7b 20 22 44 49 53 54 49 0 },. { "DISTI
0b10: 4e 43 54 22 2c 20 20 20 20 20 20 20 20 20 20 30 NCT", 0
0b20: 2c 20 54 4b 5f 44 49 53 54 49 4e 43 54 2c 20 20 , TK_DISTINCT,
0b30: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0b40: 22 44 52 4f 50 22 2c 20 20 20 20 20 20 20 20 20 "DROP",
0b50: 20 20 20 20 20 30 2c 20 54 4b 5f 44 52 4f 50 2c 0, TK_DROP,
0b60: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 0 }
0b70: 2c 0a 20 20 7b 20 22 45 4e 44 22 2c 20 20 20 20 ,. { "END",
0b80: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0b90: 5f 45 4e 44 2c 20 20 20 20 20 20 20 20 20 20 20 _END,
0ba0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 45 41 43 0 },. { "EAC
0bb0: 48 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 H",
0bc0: 20 30 2c 20 54 4b 5f 45 41 43 48 2c 20 20 20 20 0, TK_EACH,
0bd0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0be0: 7b 20 22 45 4c 53 45 22 2c 20 20 20 20 20 20 20 { "ELSE",
0bf0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 45 4c 53 0, TK_ELS
0c00: 45 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 E, 0
0c10: 20 7d 2c 0a 20 20 7b 20 22 45 58 43 45 50 54 22 },. { "EXCEPT"
0c20: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
0c30: 54 4b 5f 45 58 43 45 50 54 2c 20 20 20 20 20 20 TK_EXCEPT,
0c40: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 45 0 },. { "E
0c50: 58 50 4c 41 49 4e 22 2c 20 20 20 20 20 20 20 20 XPLAIN",
0c60: 20 20 20 30 2c 20 54 4b 5f 45 58 50 4c 41 49 4e 0, TK_EXPLAIN
0c70: 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a , 0 },.
0c80: 20 20 7b 20 22 46 41 49 4c 22 2c 20 20 20 20 20 { "FAIL",
0c90: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 46 0, TK_F
0ca0: 41 49 4c 2c 20 20 20 20 20 20 20 20 20 20 20 20 AIL,
0cb0: 20 30 20 7d 2c 0a 20 20 7b 20 22 46 4f 52 22 2c 0 },. { "FOR",
0cc0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
0cd0: 2c 20 54 4b 5f 46 4f 52 2c 20 20 20 20 20 20 20 , TK_FOR,
0ce0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0cf0: 22 46 4f 52 45 49 47 4e 22 2c 20 20 20 20 20 20 "FOREIGN",
0d00: 20 20 20 20 20 30 2c 20 54 4b 5f 46 4f 52 45 49 0, TK_FOREI
0d10: 47 4e 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d GN, 0 }
0d20: 2c 0a 20 20 7b 20 22 46 52 4f 4d 22 2c 20 20 20 ,. { "FROM",
0d30: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0d40: 5f 46 52 4f 4d 2c 20 20 20 20 20 20 20 20 20 20 _FROM,
0d50: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 46 55 4c 0 },. { "FUL
0d60: 4c 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 L",
0d70: 20 30 2c 20 54 4b 5f 4a 4f 49 4e 5f 4b 57 2c 20 0, TK_JOIN_KW,
0d80: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0d90: 7b 20 22 47 4c 4f 42 22 2c 20 20 20 20 20 20 20 { "GLOB",
0da0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 47 4c 4f 0, TK_GLO
0db0: 42 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 B, 0
0dc0: 20 7d 2c 0a 20 20 7b 20 22 47 52 4f 55 50 22 2c },. { "GROUP",
0dd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
0de0: 54 4b 5f 47 52 4f 55 50 2c 20 20 20 20 20 20 20 TK_GROUP,
0df0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 48 0 },. { "H
0e00: 41 56 49 4e 47 22 2c 20 20 20 20 20 20 20 20 20 AVING",
0e10: 20 20 20 30 2c 20 54 4b 5f 48 41 56 49 4e 47 2c 0, TK_HAVING,
0e20: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0e30: 20 20 7b 20 22 49 47 4e 4f 52 45 22 2c 20 20 20 { "IGNORE",
0e40: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 49 0, TK_I
0e50: 47 4e 4f 52 45 2c 20 20 20 20 20 20 20 20 20 20 GNORE,
0e60: 20 30 20 7d 2c 0a 20 20 7b 20 22 49 4d 4d 45 44 0 },. { "IMMED
0e70: 49 41 54 45 22 2c 20 20 20 20 20 20 20 20 20 30 IATE", 0
0e80: 2c 20 54 4b 5f 49 4d 4d 45 44 49 41 54 45 2c 20 , TK_IMMEDIATE,
0e90: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0ea0: 22 49 4e 22 2c 20 20 20 20 20 20 20 20 20 20 20 "IN",
0eb0: 20 20 20 20 20 30 2c 20 54 4b 5f 49 4e 2c 20 20 0, TK_IN,
0ec0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 0 }
0ed0: 2c 0a 20 20 7b 20 22 49 4e 44 45 58 22 2c 20 20 ,. { "INDEX",
0ee0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0ef0: 5f 49 4e 44 45 58 2c 20 20 20 20 20 20 20 20 20 _INDEX,
0f00: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 49 4e 49 0 },. { "INI
0f10: 54 49 41 4c 4c 59 22 2c 20 20 20 20 20 20 20 20 TIALLY",
0f20: 20 30 2c 20 54 4b 5f 49 4e 49 54 49 41 4c 4c 59 0, TK_INITIALLY
0f30: 2c 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 , 0 },.
0f40: 7b 20 22 49 4e 4e 45 52 22 2c 20 20 20 20 20 20 { "INNER",
0f50: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4a 4f 49 0, TK_JOI
0f60: 4e 5f 4b 57 2c 20 20 20 20 20 20 20 20 20 20 30 N_KW, 0
0f70: 20 7d 2c 0a 20 20 7b 20 22 49 4e 53 45 52 54 22 },. { "INSERT"
0f80: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
0f90: 54 4b 5f 49 4e 53 45 52 54 2c 20 20 20 20 20 20 TK_INSERT,
0fa0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 49 0 },. { "I
0fb0: 4e 53 54 45 41 44 22 2c 20 20 20 20 20 20 20 20 NSTEAD",
0fc0: 20 20 20 30 2c 20 54 4b 5f 49 4e 53 54 45 41 44 0, TK_INSTEAD
0fd0: 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a , 0 },.
0fe0: 20 20 7b 20 22 49 4e 54 45 52 53 45 43 54 22 2c { "INTERSECT",
0ff0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 49 0, TK_I
1000: 4e 54 45 52 53 45 43 54 2c 20 20 20 20 20 20 20 NTERSECT,
1010: 20 30 20 7d 2c 0a 20 20 7b 20 22 49 4e 54 4f 22 0 },. { "INTO"
1020: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
1030: 2c 20 54 4b 5f 49 4e 54 4f 2c 20 20 20 20 20 20 , TK_INTO,
1040: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1050: 22 49 53 22 2c 20 20 20 20 20 20 20 20 20 20 20 "IS",
1060: 20 20 20 20 20 30 2c 20 54 4b 5f 49 53 2c 20 20 0, TK_IS,
1070: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 0 }
1080: 2c 0a 20 20 7b 20 22 49 53 4e 55 4c 4c 22 2c 20 ,. { "ISNULL",
1090: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
10a0: 5f 49 53 4e 55 4c 4c 2c 20 20 20 20 20 20 20 20 _ISNULL,
10b0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4a 4f 49 0 },. { "JOI
10c0: 4e 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 N",
10d0: 20 30 2c 20 54 4b 5f 4a 4f 49 4e 2c 20 20 20 20 0, TK_JOIN,
10e0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
10f0: 7b 20 22 4b 45 59 22 2c 20 20 20 20 20 20 20 20 { "KEY",
1100: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4b 45 59 0, TK_KEY
1110: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
1120: 20 7d 2c 0a 20 20 7b 20 22 4c 45 46 54 22 2c 20 },. { "LEFT",
1130: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
1140: 54 4b 5f 4a 4f 49 4e 5f 4b 57 2c 20 20 20 20 20 TK_JOIN_KW,
1150: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4c 0 },. { "L
1160: 49 4b 45 22 2c 20 20 20 20 20 20 20 20 20 20 20 IKE",
1170: 20 20 20 30 2c 20 54 4b 5f 4c 49 4b 45 2c 20 20 0, TK_LIKE,
1180: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
1190: 20 20 7b 20 22 4c 49 4d 49 54 22 2c 20 20 20 20 { "LIMIT",
11a0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4c 0, TK_L
11b0: 49 4d 49 54 2c 20 20 20 20 20 20 20 20 20 20 20 IMIT,
11c0: 20 30 20 7d 2c 0a 20 20 7b 20 22 4d 41 54 43 48 0 },. { "MATCH
11d0: 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 ", 0
11e0: 2c 20 54 4b 5f 4d 41 54 43 48 2c 20 20 20 20 20 , TK_MATCH,
11f0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1200: 22 4e 41 54 55 52 41 4c 22 2c 20 20 20 20 20 20 "NATURAL",
1210: 20 20 20 20 20 30 2c 20 54 4b 5f 4a 4f 49 4e 5f 0, TK_JOIN_
1220: 4b 57 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d KW, 0 }
1230: 2c 0a 20 20 7b 20 22 4e 4f 54 22 2c 20 20 20 20 ,. { "NOT",
1240: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1250: 5f 4e 4f 54 2c 20 20 20 20 20 20 20 20 20 20 20 _NOT,
1260: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4e 4f 54 0 },. { "NOT
1270: 4e 55 4c 4c 22 2c 20 20 20 20 20 20 20 20 20 20 NULL",
1280: 20 30 2c 20 54 4b 5f 4e 4f 54 4e 55 4c 4c 2c 20 0, TK_NOTNULL,
1290: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
12a0: 7b 20 22 4e 55 4c 4c 22 2c 20 20 20 20 20 20 20 { "NULL",
12b0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4e 55 4c 0, TK_NUL
12c0: 4c 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 L, 0
12d0: 20 7d 2c 0a 20 20 7b 20 22 4f 46 22 2c 20 20 20 },. { "OF",
12e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
12f0: 54 4b 5f 4f 46 2c 20 20 20 20 20 20 20 20 20 20 TK_OF,
1300: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4f 0 },. { "O
1310: 46 46 53 45 54 22 2c 20 20 20 20 20 20 20 20 20 FFSET",
1320: 20 20 20 30 2c 20 54 4b 5f 4f 46 46 53 45 54 2c 0, TK_OFFSET,
1330: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
1340: 20 20 7b 20 22 4f 4e 22 2c 20 20 20 20 20 20 20 { "ON",
1350: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4f 0, TK_O
1360: 4e 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 N,
1370: 20 30 20 7d 2c 0a 20 20 7b 20 22 4f 52 22 2c 20 0 },. { "OR",
1380: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
1390: 2c 20 54 4b 5f 4f 52 2c 20 20 20 20 20 20 20 20 , TK_OR,
13a0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
13b0: 22 4f 52 44 45 52 22 2c 20 20 20 20 20 20 20 20 "ORDER",
13c0: 20 20 20 20 20 30 2c 20 54 4b 5f 4f 52 44 45 52 0, TK_ORDER
13d0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d , 0 }
13e0: 2c 0a 20 20 7b 20 22 4f 55 54 45 52 22 2c 20 20 ,. { "OUTER",
13f0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1400: 5f 4a 4f 49 4e 5f 4b 57 2c 20 20 20 20 20 20 20 _JOIN_KW,
1410: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 50 52 41 0 },. { "PRA
1420: 47 4d 41 22 2c 20 20 20 20 20 20 20 20 20 20 20 GMA",
1430: 20 30 2c 20 54 4b 5f 50 52 41 47 4d 41 2c 20 20 0, TK_PRAGMA,
1440: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
1450: 7b 20 22 50 52 49 4d 41 52 59 22 2c 20 20 20 20 { "PRIMARY",
1460: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 50 52 49 0, TK_PRI
1470: 4d 41 52 59 2c 20 20 20 20 20 20 20 20 20 20 30 MARY, 0
1480: 20 7d 2c 0a 20 20 7b 20 22 52 41 49 53 45 22 2c },. { "RAISE",
1490: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
14a0: 54 4b 5f 52 41 49 53 45 2c 20 20 20 20 20 20 20 TK_RAISE,
14b0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 52 0 },. { "R
14c0: 45 46 45 52 45 4e 43 45 53 22 2c 20 20 20 20 20 EFERENCES",
14d0: 20 20 20 30 2c 20 54 4b 5f 52 45 46 45 52 45 4e 0, TK_REFEREN
14e0: 43 45 53 2c 20 20 20 20 20 20 20 30 20 7d 2c 0a CES, 0 },.
14f0: 20 20 7b 20 22 52 45 50 4c 41 43 45 22 2c 20 20 { "REPLACE",
1500: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 52 0, TK_R
1510: 45 50 4c 41 43 45 2c 20 20 20 20 20 20 20 20 20 EPLACE,
1520: 20 30 20 7d 2c 0a 20 20 7b 20 22 52 45 53 54 52 0 },. { "RESTR
1530: 49 43 54 22 2c 20 20 20 20 20 20 20 20 20 20 30 ICT", 0
1540: 2c 20 54 4b 5f 52 45 53 54 52 49 43 54 2c 20 20 , TK_RESTRICT,
1550: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1560: 22 52 49 47 48 54 22 2c 20 20 20 20 20 20 20 20 "RIGHT",
1570: 20 20 20 20 20 30 2c 20 54 4b 5f 4a 4f 49 4e 5f 0, TK_JOIN_
1580: 4b 57 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d KW, 0 }
1590: 2c 0a 20 20 7b 20 22 52 4f 4c 4c 42 41 43 4b 22 ,. { "ROLLBACK"
15a0: 2c 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b , 0, TK
15b0: 5f 52 4f 4c 4c 42 41 43 4b 2c 20 20 20 20 20 20 _ROLLBACK,
15c0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 52 4f 57 0 },. { "ROW
15d0: 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ",
15e0: 20 30 2c 20 54 4b 5f 52 4f 57 2c 20 20 20 20 20 0, TK_ROW,
15f0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
1600: 7b 20 22 53 45 4c 45 43 54 22 2c 20 20 20 20 20 { "SELECT",
1610: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 53 45 4c 0, TK_SEL
1620: 45 43 54 2c 20 20 20 20 20 20 20 20 20 20 20 30 ECT, 0
1630: 20 7d 2c 0a 20 20 7b 20 22 53 45 54 22 2c 20 20 },. { "SET",
1640: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
1650: 54 4b 5f 53 45 54 2c 20 20 20 20 20 20 20 20 20 TK_SET,
1660: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 53 0 },. { "S
1670: 54 41 54 45 4d 45 4e 54 22 2c 20 20 20 20 20 20 TATEMENT",
1680: 20 20 20 30 2c 20 54 4b 5f 53 54 41 54 45 4d 45 0, TK_STATEME
1690: 4e 54 2c 20 20 20 20 20 20 20 20 30 20 7d 2c 0a NT, 0 },.
16a0: 20 20 7b 20 22 54 41 42 4c 45 22 2c 20 20 20 20 { "TABLE",
16b0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 54 0, TK_T
16c0: 41 42 4c 45 2c 20 20 20 20 20 20 20 20 20 20 20 ABLE,
16d0: 20 30 20 7d 2c 0a 20 20 7b 20 22 54 45 4d 50 22 0 },. { "TEMP"
16e0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
16f0: 2c 20 54 4b 5f 54 45 4d 50 2c 20 20 20 20 20 20 , TK_TEMP,
1700: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1710: 22 54 45 4d 50 4f 52 41 52 59 22 2c 20 20 20 20 "TEMPORARY",
1720: 20 20 20 20 20 30 2c 20 54 4b 5f 54 45 4d 50 2c 0, TK_TEMP,
1730: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 0 }
1740: 2c 0a 20 20 7b 20 22 54 48 45 4e 22 2c 20 20 20 ,. { "THEN",
1750: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1760: 5f 54 48 45 4e 2c 20 20 20 20 20 20 20 20 20 20 _THEN,
1770: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 54 52 41 0 },. { "TRA
1780: 4e 53 41 43 54 49 4f 4e 22 2c 20 20 20 20 20 20 NSACTION",
1790: 20 30 2c 20 54 4b 5f 54 52 41 4e 53 41 43 54 49 0, TK_TRANSACTI
17a0: 4f 4e 2c 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 ON, 0 },.
17b0: 7b 20 22 54 52 49 47 47 45 52 22 2c 20 20 20 20 { "TRIGGER",
17c0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 54 52 49 0, TK_TRI
17d0: 47 47 45 52 2c 20 20 20 20 20 20 20 20 20 20 30 GGER, 0
17e0: 20 7d 2c 0a 20 20 7b 20 22 55 4e 49 4f 4e 22 2c },. { "UNION",
17f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
1800: 54 4b 5f 55 4e 49 4f 4e 2c 20 20 20 20 20 20 20 TK_UNION,
1810: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 55 0 },. { "U
1820: 4e 49 51 55 45 22 2c 20 20 20 20 20 20 20 20 20 NIQUE",
1830: 20 20 20 30 2c 20 54 4b 5f 55 4e 49 51 55 45 2c 0, TK_UNIQUE,
1840: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
1850: 20 20 7b 20 22 55 50 44 41 54 45 22 2c 20 20 20 { "UPDATE",
1860: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 55 0, TK_U
1870: 50 44 41 54 45 2c 20 20 20 20 20 20 20 20 20 20 PDATE,
1880: 20 30 20 7d 2c 0a 20 20 7b 20 22 55 53 49 4e 47 0 },. { "USING
1890: 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 ", 0
18a0: 2c 20 54 4b 5f 55 53 49 4e 47 2c 20 20 20 20 20 , TK_USING,
18b0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
18c0: 22 56 41 43 55 55 4d 22 2c 20 20 20 20 20 20 20 "VACUUM",
18d0: 20 20 20 20 20 30 2c 20 54 4b 5f 56 41 43 55 55 0, TK_VACUU
18e0: 4d 2c 20 20 20 20 20 20 20 20 20 20 20 30 20 7d M, 0 }
18f0: 2c 0a 20 20 7b 20 22 56 41 4c 55 45 53 22 2c 20 ,. { "VALUES",
1900: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1910: 5f 56 41 4c 55 45 53 2c 20 20 20 20 20 20 20 20 _VALUES,
1920: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 56 49 45 0 },. { "VIE
1930: 57 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 W",
1940: 20 30 2c 20 54 4b 5f 56 49 45 57 2c 20 20 20 20 0, TK_VIEW,
1950: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
1960: 7b 20 22 57 48 45 4e 22 2c 20 20 20 20 20 20 20 { "WHEN",
1970: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 57 48 45 0, TK_WHE
1980: 4e 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 N, 0
1990: 20 7d 2c 0a 20 20 7b 20 22 57 48 45 52 45 22 2c },. { "WHERE",
19a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
19b0: 54 4b 5f 57 48 45 52 45 2c 20 20 20 20 20 20 20 TK_WHERE,
19c0: 20 20 20 20 20 30 20 7d 2c 0a 7d 3b 0a 0a 2f 2a 0 },.};../*
19d0: 0a 2a 2a 20 54 68 69 73 20 69 73 20 74 68 65 20 .** This is the
19e0: 68 61 73 68 20 74 61 62 6c 65 0a 2a 2f 0a 23 64 hash table.*/.#d
19f0: 65 66 69 6e 65 20 4b 45 59 5f 48 41 53 48 5f 53 efine KEY_HASH_S
1a00: 49 5a 45 20 37 31 0a 73 74 61 74 69 63 20 4b 65 IZE 71.static Ke
1a10: 79 77 6f 72 64 20 2a 61 70 48 61 73 68 54 61 62 yword *apHashTab
1a20: 6c 65 5b 4b 45 59 5f 48 41 53 48 5f 53 49 5a 45 le[KEY_HASH_SIZE
1a30: 5d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 73 20 ];.../*.** This
1a40: 66 75 6e 63 74 69 6f 6e 20 6c 6f 6f 6b 73 20 75 function looks u
1a50: 70 20 61 6e 20 69 64 65 6e 74 69 66 69 65 72 20 p an identifier
1a60: 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 69 66 20 to determine if
1a70: 69 74 20 69 73 20 61 0a 2a 2a 20 6b 65 79 77 6f it is a.** keywo
1a80: 72 64 2e 20 20 49 66 20 69 74 20 69 73 20 61 20 rd. If it is a
1a90: 6b 65 79 77 6f 72 64 2c 20 74 68 65 20 74 6f 6b keyword, the tok
1aa0: 65 6e 20 63 6f 64 65 20 6f 66 20 74 68 61 74 20 en code of that
1ab0: 6b 65 79 77 6f 72 64 20 69 73 20 0a 2a 2a 20 72 keyword is .** r
1ac0: 65 74 75 72 6e 65 64 2e 20 20 49 66 20 74 68 65 eturned. If the
1ad0: 20 69 6e 70 75 74 20 69 73 20 6e 6f 74 20 61 20 input is not a
1ae0: 6b 65 79 77 6f 72 64 2c 20 54 4b 5f 49 44 20 69 keyword, TK_ID i
1af0: 73 20 72 65 74 75 72 6e 65 64 2e 0a 2a 2f 0a 69 s returned..*/.i
1b00: 6e 74 20 73 71 6c 69 74 65 4b 65 79 77 6f 72 64 nt sqliteKeyword
1b10: 43 6f 64 65 28 63 6f 6e 73 74 20 63 68 61 72 20 Code(const char
1b20: 2a 7a 2c 20 69 6e 74 20 6e 29 7b 0a 20 20 69 6e *z, int n){. in
1b30: 74 20 68 3b 0a 20 20 4b 65 79 77 6f 72 64 20 2a t h;. Keyword *
1b40: 70 3b 0a 20 20 73 74 61 74 69 63 20 63 68 61 72 p;. static char
1b50: 20 6e 65 65 64 49 6e 69 74 20 3d 20 31 3b 0a 20 needInit = 1;.
1b60: 20 69 66 28 20 6e 65 65 64 49 6e 69 74 20 29 7b if( needInit ){
1b70: 0a 20 20 20 20 2f 2a 20 49 6e 69 74 69 61 6c 69 . /* Initiali
1b80: 7a 65 20 74 68 65 20 6b 65 79 77 6f 72 64 20 68 ze the keyword h
1b90: 61 73 68 20 74 61 62 6c 65 20 2a 2f 0a 20 20 20 ash table */.
1ba0: 20 73 71 6c 69 74 65 4f 73 45 6e 74 65 72 4d 75 sqliteOsEnterMu
1bb0: 74 65 78 28 29 3b 0a 20 20 20 20 69 66 28 20 6e tex();. if( n
1bc0: 65 65 64 49 6e 69 74 20 29 7b 0a 20 20 20 20 20 eedInit ){.
1bd0: 20 69 6e 74 20 69 3b 0a 20 20 20 20 20 20 69 6e int i;. in
1be0: 74 20 6e 3b 0a 20 20 20 20 20 20 6e 20 3d 20 73 t n;. n = s
1bf0: 69 7a 65 6f 66 28 61 4b 65 79 77 6f 72 64 54 61 izeof(aKeywordTa
1c00: 62 6c 65 29 2f 73 69 7a 65 6f 66 28 61 4b 65 79 ble)/sizeof(aKey
1c10: 77 6f 72 64 54 61 62 6c 65 5b 30 5d 29 3b 0a 20 wordTable[0]);.
1c20: 20 20 20 20 20 66 6f 72 28 69 3d 30 3b 20 69 3c for(i=0; i<
1c30: 6e 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 20 n; i++){.
1c40: 20 61 4b 65 79 77 6f 72 64 54 61 62 6c 65 5b 69 aKeywordTable[i
1c50: 5d 2e 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28 61 ].len = strlen(a
1c60: 4b 65 79 77 6f 72 64 54 61 62 6c 65 5b 69 5d 2e KeywordTable[i].
1c70: 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 20 20 20 20 zName);.
1c80: 68 20 3d 20 73 71 6c 69 74 65 48 61 73 68 4e 6f h = sqliteHashNo
1c90: 43 61 73 65 28 61 4b 65 79 77 6f 72 64 54 61 62 Case(aKeywordTab
1ca0: 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c 20 61 4b 65 le[i].zName, aKe
1cb0: 79 77 6f 72 64 54 61 62 6c 65 5b 69 5d 2e 6c 65 ywordTable[i].le
1cc0: 6e 29 3b 0a 20 20 20 20 20 20 20 20 68 20 25 3d n);. h %=
1cd0: 20 4b 45 59 5f 48 41 53 48 5f 53 49 5a 45 3b 0a KEY_HASH_SIZE;.
1ce0: 20 20 20 20 20 20 20 20 61 4b 65 79 77 6f 72 64 aKeyword
1cf0: 54 61 62 6c 65 5b 69 5d 2e 70 4e 65 78 74 20 3d Table[i].pNext =
1d00: 20 61 70 48 61 73 68 54 61 62 6c 65 5b 68 5d 3b apHashTable[h];
1d10: 0a 20 20 20 20 20 20 20 20 61 70 48 61 73 68 54 . apHashT
1d20: 61 62 6c 65 5b 68 5d 20 3d 20 26 61 4b 65 79 77 able[h] = &aKeyw
1d30: 6f 72 64 54 61 62 6c 65 5b 69 5d 3b 0a 20 20 20 ordTable[i];.
1d40: 20 20 20 7d 0a 20 20 20 20 20 20 6e 65 65 64 49 }. needI
1d50: 6e 69 74 20 3d 20 30 3b 0a 20 20 20 20 7d 0a 20 nit = 0;. }.
1d60: 20 20 20 73 71 6c 69 74 65 4f 73 4c 65 61 76 65 sqliteOsLeave
1d70: 4d 75 74 65 78 28 29 3b 0a 20 20 7d 0a 20 20 68 Mutex();. }. h
1d80: 20 3d 20 73 71 6c 69 74 65 48 61 73 68 4e 6f 43 = sqliteHashNoC
1d90: 61 73 65 28 7a 2c 20 6e 29 20 25 20 4b 45 59 5f ase(z, n) % KEY_
1da0: 48 41 53 48 5f 53 49 5a 45 3b 0a 20 20 66 6f 72 HASH_SIZE;. for
1db0: 28 70 3d 61 70 48 61 73 68 54 61 62 6c 65 5b 68 (p=apHashTable[h
1dc0: 5d 3b 20 70 3b 20 70 3d 70 2d 3e 70 4e 65 78 74 ]; p; p=p->pNext
1dd0: 29 7b 0a 20 20 20 20 69 66 28 20 70 2d 3e 6c 65 ){. if( p->le
1de0: 6e 3d 3d 6e 20 26 26 20 73 71 6c 69 74 65 53 74 n==n && sqliteSt
1df0: 72 4e 49 43 6d 70 28 70 2d 3e 7a 4e 61 6d 65 2c rNICmp(p->zName,
1e00: 20 7a 2c 20 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 z, n)==0 ){.
1e10: 20 20 20 72 65 74 75 72 6e 20 70 2d 3e 74 6f 6b return p->tok
1e20: 65 6e 54 79 70 65 3b 0a 20 20 20 20 7d 0a 20 20 enType;. }.
1e30: 7d 0a 20 20 72 65 74 75 72 6e 20 54 4b 5f 49 44 }. return TK_ID
1e40: 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 58 ;.}.../*.** If X
1e50: 20 69 73 20 61 20 63 68 61 72 61 63 74 65 72 20 is a character
1e60: 74 68 61 74 20 63 61 6e 20 62 65 20 75 73 65 64 that can be used
1e70: 20 69 6e 20 61 6e 20 69 64 65 6e 74 69 66 69 65 in an identifie
1e80: 72 20 74 68 65 6e 0a 2a 2a 20 69 73 49 64 43 68 r then.** isIdCh
1e90: 61 72 5b 58 5d 20 77 69 6c 6c 20 62 65 20 31 2e ar[X] will be 1.
1ea0: 20 20 4f 74 68 65 72 77 69 73 65 20 69 73 49 64 Otherwise isId
1eb0: 43 68 61 72 5b 58 5d 20 77 69 6c 6c 20 62 65 20 Char[X] will be
1ec0: 30 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 69 73 0..**.** In this
1ed0: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2c implementation,
1ee0: 20 61 6e 20 69 64 65 6e 74 69 66 69 65 72 20 63 an identifier c
1ef0: 61 6e 20 62 65 20 61 20 73 74 72 69 6e 67 20 6f an be a string o
1f00: 66 0a 2a 2a 20 61 6c 70 68 61 62 65 74 69 63 20 f.** alphabetic
1f10: 63 68 61 72 61 63 74 65 72 73 2c 20 64 69 67 69 characters, digi
1f20: 74 73 2c 20 61 6e 64 20 22 5f 22 20 70 6c 75 73 ts, and "_" plus
1f30: 20 61 6e 79 20 63 68 61 72 61 63 74 65 72 0a 2a any character.*
1f40: 2a 20 77 69 74 68 20 74 68 65 20 68 69 67 68 2d * with the high-
1f50: 6f 72 64 65 72 20 62 69 74 20 73 65 74 2e 20 20 order bit set.
1f60: 54 68 65 20 6c 61 74 74 65 72 20 72 75 6c 65 20 The latter rule
1f70: 6d 65 61 6e 73 20 74 68 61 74 0a 2a 2a 20 61 6e means that.** an
1f80: 79 20 73 65 71 75 65 6e 63 65 20 6f 66 20 55 54 y sequence of UT
1f90: 46 2d 38 20 63 68 61 72 61 63 74 65 72 73 20 6f F-8 characters o
1fa0: 72 20 63 68 61 72 61 63 74 65 72 73 20 74 61 6b r characters tak
1fb0: 65 6e 20 66 72 6f 6d 0a 2a 2a 20 61 6e 20 65 78 en from.** an ex
1fc0: 74 65 6e 64 65 64 20 49 53 4f 38 38 35 39 20 63 tended ISO8859 c
1fd0: 68 61 72 61 63 74 65 72 20 73 65 74 20 63 61 6e haracter set can
1fe0: 20 66 6f 72 6d 20 61 6e 20 69 64 65 6e 74 69 66 form an identif
1ff0: 69 65 72 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 63 ier..*/.static c
2000: 6f 6e 73 74 20 63 68 61 72 20 69 73 49 64 43 68 onst char isIdCh
2010: 61 72 5b 5d 20 3d 20 7b 0a 2f 2a 20 78 30 20 78 ar[] = {./* x0 x
2020: 31 20 78 32 20 78 33 20 78 34 20 78 35 20 78 36 1 x2 x3 x4 x5 x6
2030: 20 78 37 20 78 38 20 78 39 20 78 41 20 78 42 20 x7 x8 x9 xA xB
2040: 78 43 20 78 44 20 78 45 20 78 46 20 2a 2f 0a 20 xC xD xE xF */.
2050: 20 20 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 0, 0, 0, 0, 0
2060: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
2070: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
2080: 30 2c 20 20 2f 2a 20 30 78 20 2a 2f 0a 20 20 20 0, /* 0x */.
2090: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
20a0: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 0, 0, 0, 0, 0, 0
20b0: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
20c0: 20 20 2f 2a 20 31 78 20 2a 2f 0a 20 20 20 20 30 /* 1x */. 0
20d0: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
20e0: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
20f0: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 20 0, 0, 0, 0, 0,
2100: 2f 2a 20 32 78 20 2a 2f 0a 20 20 20 20 31 2c 20 /* 2x */. 1,
2110: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
2120: 2c 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c , 1, 1, 1, 0, 0,
2130: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 20 2f 2a 0, 0, 0, 0, /*
2140: 20 33 78 20 2a 2f 0a 20 20 20 20 30 2c 20 31 2c 3x */. 0, 1,
2150: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2160: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
2170: 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 34 , 1, 1, 1, /* 4
2180: 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 x */. 1, 1, 1
2190: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
21a0: 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c 20 1, 1, 1, 0, 0,
21b0: 30 2c 20 30 2c 20 31 2c 20 20 2f 2a 20 35 78 20 0, 0, 1, /* 5x
21c0: 2a 2f 0a 20 20 20 20 30 2c 20 31 2c 20 31 2c 20 */. 0, 1, 1,
21d0: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
21e0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
21f0: 20 31 2c 20 31 2c 20 20 2f 2a 20 36 78 20 2a 2f 1, 1, /* 6x */
2200: 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c . 1, 1, 1, 1,
2210: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2220: 31 2c 20 31 2c 20 30 2c 20 30 2c 20 30 2c 20 30 1, 1, 0, 0, 0, 0
2230: 2c 20 30 2c 20 20 2f 2a 20 37 78 20 2a 2f 0a 20 , 0, /* 7x */.
2240: 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1
2250: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
2260: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2270: 31 2c 20 20 2f 2a 20 38 78 20 2a 2f 0a 20 20 20 1, /* 8x */.
2280: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2290: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
22a0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
22b0: 20 20 2f 2a 20 39 78 20 2a 2f 0a 20 20 20 20 31 /* 9x */. 1
22c0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
22d0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
22e0: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 20 1, 1, 1, 1, 1,
22f0: 2f 2a 20 41 78 20 2a 2f 0a 20 20 20 20 31 2c 20 /* Ax */. 1,
2300: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
2310: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
2320: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 1, 1, 1, 1, /*
2330: 20 42 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c Bx */. 1, 1,
2340: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2350: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
2360: 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 43 , 1, 1, 1, /* C
2370: 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 x */. 1, 1, 1
2380: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
2390: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
23a0: 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 44 78 20 1, 1, 1, /* Dx
23b0: 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 */. 1, 1, 1,
23c0: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
23d0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
23e0: 20 31 2c 20 31 2c 20 20 2f 2a 20 45 78 20 2a 2f 1, 1, /* Ex */
23f0: 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c . 1, 1, 1, 1,
2400: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
2410: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
2420: 2c 20 31 2c 20 20 2f 2a 20 46 78 20 2a 2f 0a 7d , 1, /* Fx */.}
2430: 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e ;.../*.** Return
2440: 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 74 the length of t
2450: 68 65 20 74 6f 6b 65 6e 20 74 68 61 74 20 62 65 he token that be
2460: 67 69 6e 73 20 61 74 20 7a 5b 30 5d 2e 20 0a 2a gins at z[0]. .*
2470: 2a 20 53 74 6f 72 65 20 74 68 65 20 74 6f 6b 65 * Store the toke
2480: 6e 20 74 79 70 65 20 69 6e 20 2a 74 6f 6b 65 6e n type in *token
2490: 54 79 70 65 20 62 65 66 6f 72 65 20 72 65 74 75 Type before retu
24a0: 72 6e 69 6e 67 2e 0a 2a 2f 0a 73 74 61 74 69 63 rning..*/.static
24b0: 20 69 6e 74 20 73 71 6c 69 74 65 47 65 74 54 6f int sqliteGetTo
24c0: 6b 65 6e 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e ken(const unsign
24d0: 65 64 20 63 68 61 72 20 2a 7a 2c 20 69 6e 74 20 ed char *z, int
24e0: 2a 74 6f 6b 65 6e 54 79 70 65 29 7b 0a 20 20 69 *tokenType){. i
24f0: 6e 74 20 69 3b 0a 20 20 73 77 69 74 63 68 28 20 nt i;. switch(
2500: 2a 7a 20 29 7b 0a 20 20 20 20 63 61 73 65 20 27 *z ){. case '
2510: 20 27 3a 20 63 61 73 65 20 27 5c 74 27 3a 20 63 ': case '\t': c
2520: 61 73 65 20 27 5c 6e 27 3a 20 63 61 73 65 20 27 ase '\n': case '
2530: 5c 66 27 3a 20 63 61 73 65 20 27 5c 72 27 3a 20 \f': case '\r':
2540: 7b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 31 3b {. for(i=1;
2550: 20 69 73 73 70 61 63 65 28 7a 5b 69 5d 29 3b 20 isspace(z[i]);
2560: 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 2a 74 6f i++){}. *to
2570: 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 53 50 41 kenType = TK_SPA
2580: 43 45 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e CE;. return
2590: 20 69 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 i;. }. ca
25a0: 73 65 20 27 2d 27 3a 20 7b 0a 20 20 20 20 20 20 se '-': {.
25b0: 69 66 28 20 7a 5b 31 5d 3d 3d 27 2d 27 20 29 7b if( z[1]=='-' ){
25c0: 0a 20 20 20 20 20 20 20 20 66 6f 72 28 69 3d 32 . for(i=2
25d0: 3b 20 7a 5b 69 5d 20 26 26 20 7a 5b 69 5d 21 3d ; z[i] && z[i]!=
25e0: 27 5c 6e 27 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 '\n'; i++){}.
25f0: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
2600: 3d 20 54 4b 5f 43 4f 4d 4d 45 4e 54 3b 0a 20 20 = TK_COMMENT;.
2610: 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b 0a return i;.
2620: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 2a 74 }. *t
2630: 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4d 49 okenType = TK_MI
2640: 4e 55 53 3b 0a 20 20 20 20 20 20 72 65 74 75 72 NUS;. retur
2650: 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 n 1;. }. c
2660: 61 73 65 20 27 28 27 3a 20 7b 0a 20 20 20 20 20 ase '(': {.
2670: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2680: 5f 4c 50 3b 0a 20 20 20 20 20 20 72 65 74 75 72 _LP;. retur
2690: 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 n 1;. }. c
26a0: 61 73 65 20 27 29 27 3a 20 7b 0a 20 20 20 20 20 ase ')': {.
26b0: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
26c0: 5f 52 50 3b 0a 20 20 20 20 20 20 72 65 74 75 72 _RP;. retur
26d0: 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 n 1;. }. c
26e0: 61 73 65 20 27 3b 27 3a 20 7b 0a 20 20 20 20 20 ase ';': {.
26f0: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2700: 5f 53 45 4d 49 3b 0a 20 20 20 20 20 20 72 65 74 _SEMI;. ret
2710: 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 urn 1;. }.
2720: 20 63 61 73 65 20 27 2b 27 3a 20 7b 0a 20 20 20 case '+': {.
2730: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
2740: 54 4b 5f 50 4c 55 53 3b 0a 20 20 20 20 20 20 72 TK_PLUS;. r
2750: 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 eturn 1;. }.
2760: 20 20 20 63 61 73 65 20 27 2a 27 3a 20 7b 0a 20 case '*': {.
2770: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
2780: 3d 20 54 4b 5f 53 54 41 52 3b 0a 20 20 20 20 20 = TK_STAR;.
2790: 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d return 1;. }
27a0: 0a 20 20 20 20 63 61 73 65 20 27 2f 27 3a 20 7b . case '/': {
27b0: 0a 20 20 20 20 20 20 69 66 28 20 7a 5b 31 5d 21 . if( z[1]!
27c0: 3d 27 2a 27 20 7c 7c 20 7a 5b 32 5d 3d 3d 30 20 ='*' || z[2]==0
27d0: 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 ){. *toke
27e0: 6e 54 79 70 65 20 3d 20 54 4b 5f 53 4c 41 53 48 nType = TK_SLASH
27f0: 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e ;. return
2800: 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 1;. }.
2810: 20 20 66 6f 72 28 69 3d 33 3b 20 7a 5b 69 5d 20 for(i=3; z[i]
2820: 26 26 20 28 7a 5b 69 5d 21 3d 27 2f 27 20 7c 7c && (z[i]!='/' ||
2830: 20 7a 5b 69 2d 31 5d 21 3d 27 2a 27 29 3b 20 69 z[i-1]!='*'); i
2840: 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 69 66 28 20 ++){}. if(
2850: 7a 5b 69 5d 20 29 20 69 2b 2b 3b 0a 20 20 20 20 z[i] ) i++;.
2860: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
2870: 4b 5f 43 4f 4d 4d 45 4e 54 3b 0a 20 20 20 20 20 K_COMMENT;.
2880: 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 7d return i;. }
2890: 0a 20 20 20 20 63 61 73 65 20 27 25 27 3a 20 7b . case '%': {
28a0: 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 . *tokenTyp
28b0: 65 20 3d 20 54 4b 5f 52 45 4d 3b 0a 20 20 20 20 e = TK_REM;.
28c0: 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 return 1;.
28d0: 7d 0a 20 20 20 20 63 61 73 65 20 27 3d 27 3a 20 }. case '=':
28e0: 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 {. *tokenTy
28f0: 70 65 20 3d 20 54 4b 5f 45 51 3b 0a 20 20 20 20 pe = TK_EQ;.
2900: 20 20 72 65 74 75 72 6e 20 31 20 2b 20 28 7a 5b return 1 + (z[
2910: 31 5d 3d 3d 27 3d 27 29 3b 0a 20 20 20 20 7d 0a 1]=='=');. }.
2920: 20 20 20 20 63 61 73 65 20 27 3c 27 3a 20 7b 0a case '<': {.
2930: 20 20 20 20 20 20 69 66 28 20 7a 5b 31 5d 3d 3d if( z[1]==
2940: 27 3d 27 20 29 7b 0a 20 20 20 20 20 20 20 20 2a '=' ){. *
2950: 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4c tokenType = TK_L
2960: 45 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 E;. retur
2970: 6e 20 32 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 n 2;. }else
2980: 20 69 66 28 20 7a 5b 31 5d 3d 3d 27 3e 27 20 29 if( z[1]=='>' )
2990: 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e {. *token
29a0: 54 79 70 65 20 3d 20 54 4b 5f 4e 45 3b 0a 20 20 Type = TK_NE;.
29b0: 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a return 2;.
29c0: 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 }else if(
29d0: 7a 5b 31 5d 3d 3d 27 3c 27 20 29 7b 0a 20 20 20 z[1]=='<' ){.
29e0: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
29f0: 3d 20 54 4b 5f 4c 53 48 49 46 54 3b 0a 20 20 20 = TK_LSHIFT;.
2a00: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
2a10: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 }else{.
2a20: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2a30: 20 54 4b 5f 4c 54 3b 0a 20 20 20 20 20 20 20 20 TK_LT;.
2a40: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 return 1;.
2a50: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 }. }. case
2a60: 20 27 3e 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 '>': {. if
2a70: 28 20 7a 5b 31 5d 3d 3d 27 3d 27 20 29 7b 0a 20 ( z[1]=='=' ){.
2a80: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
2a90: 65 20 3d 20 54 4b 5f 47 45 3b 0a 20 20 20 20 20 e = TK_GE;.
2aa0: 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 return 2;.
2ab0: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 7a 5b 31 }else if( z[1
2ac0: 5d 3d 3d 27 3e 27 20 29 7b 0a 20 20 20 20 20 20 ]=='>' ){.
2ad0: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
2ae0: 4b 5f 52 53 48 49 46 54 3b 0a 20 20 20 20 20 20 K_RSHIFT;.
2af0: 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 return 2;.
2b00: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 }else{.
2b10: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2b20: 5f 47 54 3b 0a 20 20 20 20 20 20 20 20 72 65 74 _GT;. ret
2b30: 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 urn 1;. }.
2b40: 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 21 }. case '!
2b50: 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 20 7a ': {. if( z
2b60: 5b 31 5d 21 3d 27 3d 27 20 29 7b 0a 20 20 20 20 [1]!='=' ){.
2b70: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2b80: 20 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 20 20 TK_ILLEGAL;.
2b90: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
2ba0: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 }else{.
2bb0: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2bc0: 20 54 4b 5f 4e 45 3b 0a 20 20 20 20 20 20 20 20 TK_NE;.
2bd0: 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 20 20 return 2;.
2be0: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 }. }. case
2bf0: 20 27 7c 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 '|': {. if
2c00: 28 20 7a 5b 31 5d 21 3d 27 7c 27 20 29 7b 0a 20 ( z[1]!='|' ){.
2c10: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
2c20: 65 20 3d 20 54 4b 5f 42 49 54 4f 52 3b 0a 20 20 e = TK_BITOR;.
2c30: 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a return 1;.
2c40: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 }else{.
2c50: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
2c60: 3d 20 54 4b 5f 43 4f 4e 43 41 54 3b 0a 20 20 20 = TK_CONCAT;.
2c70: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
2c80: 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 }. }.
2c90: 20 63 61 73 65 20 27 2c 27 3a 20 7b 0a 20 20 20 case ',': {.
2ca0: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
2cb0: 54 4b 5f 43 4f 4d 4d 41 3b 0a 20 20 20 20 20 20 TK_COMMA;.
2cc0: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a return 1;. }.
2cd0: 20 20 20 20 63 61 73 65 20 27 26 27 3a 20 7b 0a case '&': {.
2ce0: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
2cf0: 20 3d 20 54 4b 5f 42 49 54 41 4e 44 3b 0a 20 20 = TK_BITAND;.
2d00: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 return 1;.
2d10: 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 7e 27 }. case '~'
2d20: 3a 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e : {. *token
2d30: 54 79 70 65 20 3d 20 54 4b 5f 42 49 54 4e 4f 54 Type = TK_BITNOT
2d40: 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 ;. return 1
2d50: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 ;. }. case
2d60: 20 27 5c 27 27 3a 20 63 61 73 65 20 27 22 27 3a '\'': case '"':
2d70: 20 7b 0a 20 20 20 20 20 20 69 6e 74 20 64 65 6c {. int del
2d80: 69 6d 20 3d 20 7a 5b 30 5d 3b 0a 20 20 20 20 20 im = z[0];.
2d90: 20 66 6f 72 28 69 3d 31 3b 20 7a 5b 69 5d 3b 20 for(i=1; z[i];
2da0: 69 2b 2b 29 7b 0a 20 20 20 20 20 20 20 20 69 66 i++){. if
2db0: 28 20 7a 5b 69 5d 3d 3d 64 65 6c 69 6d 20 29 7b ( z[i]==delim ){
2dc0: 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 7a . if( z
2dd0: 5b 69 2b 31 5d 3d 3d 64 65 6c 69 6d 20 29 7b 0a [i+1]==delim ){.
2de0: 20 20 20 20 20 20 20 20 20 20 20 20 69 2b 2b 3b i++;
2df0: 0a 20 20 20 20 20 20 20 20 20 20 7d 65 6c 73 65 . }else
2e00: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 72 {. br
2e10: 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 20 7d eak;. }
2e20: 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 . }.
2e30: 20 7d 0a 20 20 20 20 20 20 69 66 28 20 7a 5b 69 }. if( z[i
2e40: 5d 20 29 20 69 2b 2b 3b 0a 20 20 20 20 20 20 2a ] ) i++;. *
2e50: 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 53 tokenType = TK_S
2e60: 54 52 49 4e 47 3b 0a 20 20 20 20 20 20 72 65 74 TRING;. ret
2e70: 75 72 6e 20 69 3b 0a 20 20 20 20 7d 0a 20 20 20 urn i;. }.
2e80: 20 63 61 73 65 20 27 2e 27 3a 20 7b 0a 20 20 20 case '.': {.
2e90: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
2ea0: 54 4b 5f 44 4f 54 3b 0a 20 20 20 20 20 20 72 65 TK_DOT;. re
2eb0: 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 turn 1;. }.
2ec0: 20 20 63 61 73 65 20 27 30 27 3a 20 63 61 73 65 case '0': case
2ed0: 20 27 31 27 3a 20 63 61 73 65 20 27 32 27 3a 20 '1': case '2':
2ee0: 63 61 73 65 20 27 33 27 3a 20 63 61 73 65 20 27 case '3': case '
2ef0: 34 27 3a 0a 20 20 20 20 63 61 73 65 20 27 35 27 4':. case '5'
2f00: 3a 20 63 61 73 65 20 27 36 27 3a 20 63 61 73 65 : case '6': case
2f10: 20 27 37 27 3a 20 63 61 73 65 20 27 38 27 3a 20 '7': case '8':
2f20: 63 61 73 65 20 27 39 27 3a 20 7b 0a 20 20 20 20 case '9': {.
2f30: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
2f40: 4b 5f 49 4e 54 45 47 45 52 3b 0a 20 20 20 20 20 K_INTEGER;.
2f50: 20 66 6f 72 28 69 3d 31 3b 20 69 73 64 69 67 69 for(i=1; isdigi
2f60: 74 28 7a 5b 69 5d 29 3b 20 69 2b 2b 29 7b 7d 0a t(z[i]); i++){}.
2f70: 20 20 20 20 20 20 69 66 28 20 7a 5b 69 5d 3d 3d if( z[i]==
2f80: 27 2e 27 20 26 26 20 69 73 64 69 67 69 74 28 7a '.' && isdigit(z
2f90: 5b 69 2b 31 5d 29 20 29 7b 0a 20 20 20 20 20 20 [i+1]) ){.
2fa0: 20 20 69 20 2b 3d 20 32 3b 0a 20 20 20 20 20 20 i += 2;.
2fb0: 20 20 77 68 69 6c 65 28 20 69 73 64 69 67 69 74 while( isdigit
2fc0: 28 7a 5b 69 5d 29 20 29 7b 20 69 2b 2b 3b 20 7d (z[i]) ){ i++; }
2fd0: 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 . *tokenT
2fe0: 79 70 65 20 3d 20 54 4b 5f 46 4c 4f 41 54 3b 0a ype = TK_FLOAT;.
2ff0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 66 }. if
3000: 28 20 28 7a 5b 69 5d 3d 3d 27 65 27 20 7c 7c 20 ( (z[i]=='e' ||
3010: 7a 5b 69 5d 3d 3d 27 45 27 29 20 26 26 0a 20 20 z[i]=='E') &&.
3020: 20 20 20 20 20 20 20 20 20 28 20 69 73 64 69 67 ( isdig
3030: 69 74 28 7a 5b 69 2b 31 5d 29 20 0a 20 20 20 20 it(z[i+1]) .
3040: 20 20 20 20 20 20 20 20 7c 7c 20 28 28 7a 5b 69 || ((z[i
3050: 2b 31 5d 3d 3d 27 2b 27 20 7c 7c 20 7a 5b 69 2b +1]=='+' || z[i+
3060: 31 5d 3d 3d 27 2d 27 29 20 26 26 20 69 73 64 69 1]=='-') && isdi
3070: 67 69 74 28 7a 5b 69 2b 32 5d 29 29 0a 20 20 20 git(z[i+2])).
3080: 20 20 20 20 20 20 20 20 29 0a 20 20 20 20 20 20 ).
3090: 29 7b 0a 20 20 20 20 20 20 20 20 69 20 2b 3d 20 ){. i +=
30a0: 32 3b 0a 20 20 20 20 20 20 20 20 77 68 69 6c 65 2;. while
30b0: 28 20 69 73 64 69 67 69 74 28 7a 5b 69 5d 29 20 ( isdigit(z[i])
30c0: 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 20 20 20 20 ){ i++; }.
30d0: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
30e0: 4b 5f 46 4c 4f 41 54 3b 0a 20 20 20 20 20 20 7d K_FLOAT;. }
30f0: 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b . return i;
3100: 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 . }. case
3110: 27 5b 27 3a 20 7b 0a 20 20 20 20 20 20 66 6f 72 '[': {. for
3120: 28 69 3d 31 3b 20 7a 5b 69 5d 20 26 26 20 7a 5b (i=1; z[i] && z[
3130: 69 2d 31 5d 21 3d 27 5d 27 3b 20 69 2b 2b 29 7b i-1]!=']'; i++){
3140: 7d 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 }. *tokenTy
3150: 70 65 20 3d 20 54 4b 5f 49 44 3b 0a 20 20 20 20 pe = TK_ID;.
3160: 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 return i;.
3170: 7d 0a 20 20 20 20 63 61 73 65 20 27 3f 27 3a 20 }. case '?':
3180: 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 {. *tokenTy
3190: 70 65 20 3d 20 54 4b 5f 56 41 52 49 41 42 4c 45 pe = TK_VARIABLE
31a0: 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 ;. return 1
31b0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 65 66 61 ;. }. defa
31c0: 75 6c 74 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 ult: {. if(
31d0: 20 21 69 73 49 64 43 68 61 72 5b 2a 7a 5d 20 29 !isIdChar[*z] )
31e0: 7b 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b {. break;
31f0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 66 . }. f
3200: 6f 72 28 69 3d 31 3b 20 69 73 49 64 43 68 61 72 or(i=1; isIdChar
3210: 5b 7a 5b 69 5d 5d 3b 20 69 2b 2b 29 7b 7d 0a 20 [z[i]]; i++){}.
3220: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
3230: 3d 20 73 71 6c 69 74 65 4b 65 79 77 6f 72 64 43 = sqliteKeywordC
3240: 6f 64 65 28 28 63 68 61 72 2a 29 7a 2c 20 69 29 ode((char*)z, i)
3250: 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 ;. return i
3260: 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 2a 74 ;. }. }. *t
3270: 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 49 4c okenType = TK_IL
3280: 4c 45 47 41 4c 3b 0a 20 20 72 65 74 75 72 6e 20 LEGAL;. return
3290: 31 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 52 75 6e 20 1;.}../*.** Run
32a0: 74 68 65 20 70 61 72 73 65 72 20 6f 6e 20 74 68 the parser on th
32b0: 65 20 67 69 76 65 6e 20 53 51 4c 20 73 74 72 69 e given SQL stri
32c0: 6e 67 2e 20 20 54 68 65 20 70 61 72 73 65 72 20 ng. The parser
32d0: 73 74 72 75 63 74 75 72 65 20 69 73 0a 2a 2a 20 structure is.**
32e0: 70 61 73 73 65 64 20 69 6e 2e 20 20 41 6e 20 53 passed in. An S
32f0: 51 4c 49 54 45 5f 20 73 74 61 74 75 73 20 63 6f QLITE_ status co
3300: 64 65 20 69 73 20 72 65 74 75 72 6e 65 64 2e 20 de is returned.
3310: 20 49 66 20 61 6e 20 65 72 72 6f 72 20 6f 63 63 If an error occ
3320: 75 72 73 0a 2a 2a 20 61 6e 64 20 70 7a 45 72 72 urs.** and pzErr
3330: 4d 73 67 21 3d 4e 55 4c 4c 20 74 68 65 6e 20 61 Msg!=NULL then a
3340: 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 20 n error message
3350: 6d 69 67 68 74 20 62 65 20 77 72 69 74 74 65 6e might be written
3360: 20 69 6e 74 6f 20 0a 2a 2a 20 6d 65 6d 6f 72 79 into .** memory
3370: 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 6d obtained from m
3380: 61 6c 6c 6f 63 28 29 20 61 6e 64 20 2a 70 7a 45 alloc() and *pzE
3390: 72 72 4d 73 67 20 6d 61 64 65 20 74 6f 20 70 6f rrMsg made to po
33a0: 69 6e 74 20 74 6f 20 74 68 61 74 0a 2a 2a 20 65 int to that.** e
33b0: 72 72 6f 72 20 6d 65 73 73 61 67 65 2e 20 20 4f rror message. O
33c0: 72 20 6d 61 79 62 65 20 6e 6f 74 2e 0a 2a 2f 0a r maybe not..*/.
33d0: 69 6e 74 20 73 71 6c 69 74 65 52 75 6e 50 61 72 int sqliteRunPar
33e0: 73 65 72 28 50 61 72 73 65 20 2a 70 50 61 72 73 ser(Parse *pPars
33f0: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a e, const char *z
3400: 53 71 6c 2c 20 63 68 61 72 20 2a 2a 70 7a 45 72 Sql, char **pzEr
3410: 72 4d 73 67 29 7b 0a 20 20 69 6e 74 20 6e 45 72 rMsg){. int nEr
3420: 72 20 3d 20 30 3b 0a 20 20 69 6e 74 20 69 3b 0a r = 0;. int i;.
3430: 20 20 76 6f 69 64 20 2a 70 45 6e 67 69 6e 65 3b void *pEngine;
3440: 0a 20 20 69 6e 74 20 74 6f 6b 65 6e 54 79 70 65 . int tokenType
3450: 3b 0a 20 20 69 6e 74 20 6c 61 73 74 54 6f 6b 65 ;. int lastToke
3460: 6e 50 61 72 73 65 64 20 3d 20 2d 31 3b 0a 20 20 nParsed = -1;.
3470: 73 71 6c 69 74 65 20 2a 64 62 20 3d 20 70 50 61 sqlite *db = pPa
3480: 72 73 65 2d 3e 64 62 3b 0a 20 20 65 78 74 65 72 rse->db;. exter
3490: 6e 20 76 6f 69 64 20 2a 73 71 6c 69 74 65 50 61 n void *sqlitePa
34a0: 72 73 65 72 41 6c 6c 6f 63 28 76 6f 69 64 2a 28 rserAlloc(void*(
34b0: 2a 29 28 69 6e 74 29 29 3b 0a 20 20 65 78 74 65 *)(int));. exte
34c0: 72 6e 20 76 6f 69 64 20 73 71 6c 69 74 65 50 61 rn void sqlitePa
34d0: 72 73 65 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 rserFree(void*,
34e0: 76 6f 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b void(*)(void*));
34f0: 0a 20 20 65 78 74 65 72 6e 20 69 6e 74 20 73 71 . extern int sq
3500: 6c 69 74 65 50 61 72 73 65 72 28 76 6f 69 64 2a liteParser(void*
3510: 2c 20 69 6e 74 2c 20 54 6f 6b 65 6e 2c 20 50 61 , int, Token, Pa
3520: 72 73 65 2a 29 3b 0a 0a 20 20 64 62 2d 3e 66 6c rse*);.. db->fl
3530: 61 67 73 20 26 3d 20 7e 53 51 4c 49 54 45 5f 49 ags &= ~SQLITE_I
3540: 6e 74 65 72 72 75 70 74 3b 0a 20 20 70 50 61 72 nterrupt;. pPar
3550: 73 65 2d 3e 72 63 20 3d 20 53 51 4c 49 54 45 5f se->rc = SQLITE_
3560: 4f 4b 3b 0a 20 20 69 20 3d 20 30 3b 0a 20 20 70 OK;. i = 0;. p
3570: 45 6e 67 69 6e 65 20 3d 20 73 71 6c 69 74 65 50 Engine = sqliteP
3580: 61 72 73 65 72 41 6c 6c 6f 63 28 28 76 6f 69 64 arserAlloc((void
3590: 2a 28 2a 29 28 69 6e 74 29 29 6d 61 6c 6c 6f 63 *(*)(int))malloc
35a0: 29 3b 0a 20 20 69 66 28 20 70 45 6e 67 69 6e 65 );. if( pEngine
35b0: 3d 3d 30 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 ==0 ){. sqlit
35c0: 65 53 65 74 53 74 72 69 6e 67 28 70 7a 45 72 72 eSetString(pzErr
35d0: 4d 73 67 2c 20 22 6f 75 74 20 6f 66 20 6d 65 6d Msg, "out of mem
35e0: 6f 72 79 22 2c 20 28 63 68 61 72 2a 29 30 29 3b ory", (char*)0);
35f0: 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 . return 1;.
3600: 20 7d 0a 20 20 70 50 61 72 73 65 2d 3e 73 4c 61 }. pParse->sLa
3610: 73 74 54 6f 6b 65 6e 2e 64 79 6e 20 3d 20 30 3b stToken.dyn = 0;
3620: 0a 20 20 70 50 61 72 73 65 2d 3e 7a 54 61 69 6c . pParse->zTail
3630: 20 3d 20 7a 53 71 6c 3b 0a 20 20 77 68 69 6c 65 = zSql;. while
3640: 28 20 73 71 6c 69 74 65 5f 6d 61 6c 6c 6f 63 5f ( sqlite_malloc_
3650: 66 61 69 6c 65 64 3d 3d 30 20 26 26 20 7a 53 71 failed==0 && zSq
3660: 6c 5b 69 5d 21 3d 30 20 29 7b 0a 20 20 20 20 61 l[i]!=0 ){. a
3670: 73 73 65 72 74 28 20 69 3e 3d 30 20 29 3b 0a 20 ssert( i>=0 );.
3680: 20 20 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 pParse->sLast
3690: 54 6f 6b 65 6e 2e 7a 20 3d 20 26 7a 53 71 6c 5b Token.z = &zSql[
36a0: 69 5d 3b 0a 20 20 20 20 61 73 73 65 72 74 28 20 i];. assert(
36b0: 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b pParse->sLastTok
36c0: 65 6e 2e 64 79 6e 3d 3d 30 20 29 3b 0a 20 20 20 en.dyn==0 );.
36d0: 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f pParse->sLastTo
36e0: 6b 65 6e 2e 6e 20 3d 20 73 71 6c 69 74 65 47 65 ken.n = sqliteGe
36f0: 74 54 6f 6b 65 6e 28 28 75 6e 73 69 67 6e 65 64 tToken((unsigned
3700: 20 63 68 61 72 2a 29 26 7a 53 71 6c 5b 69 5d 2c char*)&zSql[i],
3710: 20 26 74 6f 6b 65 6e 54 79 70 65 29 3b 0a 20 20 &tokenType);.
3720: 20 20 69 20 2b 3d 20 70 50 61 72 73 65 2d 3e 73 i += pParse->s
3730: 4c 61 73 74 54 6f 6b 65 6e 2e 6e 3b 0a 20 20 20 LastToken.n;.
3740: 20 73 77 69 74 63 68 28 20 74 6f 6b 65 6e 54 79 switch( tokenTy
3750: 70 65 20 29 7b 0a 20 20 20 20 20 20 63 61 73 65 pe ){. case
3760: 20 54 4b 5f 53 50 41 43 45 3a 0a 20 20 20 20 20 TK_SPACE:.
3770: 20 63 61 73 65 20 54 4b 5f 43 4f 4d 4d 45 4e 54 case TK_COMMENT
3780: 3a 20 7b 0a 20 20 20 20 20 20 20 20 69 66 28 20 : {. if(
3790: 28 64 62 2d 3e 66 6c 61 67 73 20 26 20 53 51 4c (db->flags & SQL
37a0: 49 54 45 5f 49 6e 74 65 72 72 75 70 74 29 21 3d ITE_Interrupt)!=
37b0: 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 70 0 ){. p
37c0: 50 61 72 73 65 2d 3e 72 63 20 3d 20 53 51 4c 49 Parse->rc = SQLI
37d0: 54 45 5f 49 4e 54 45 52 52 55 50 54 3b 0a 20 20 TE_INTERRUPT;.
37e0: 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 53 65 sqliteSe
37f0: 74 53 74 72 69 6e 67 28 70 7a 45 72 72 4d 73 67 tString(pzErrMsg
3800: 2c 20 22 69 6e 74 65 72 72 75 70 74 22 2c 20 28 , "interrupt", (
3810: 63 68 61 72 2a 29 30 29 3b 0a 20 20 20 20 20 20 char*)0);.
3820: 20 20 20 20 67 6f 74 6f 20 61 62 6f 72 74 5f 70 goto abort_p
3830: 61 72 73 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a arse;. }.
3840: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 break;.
3850: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 63 61 73 }. cas
3860: 65 20 54 4b 5f 49 4c 4c 45 47 41 4c 3a 20 7b 0a e TK_ILLEGAL: {.
3870: 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 53 65 sqliteSe
3880: 74 4e 53 74 72 69 6e 67 28 70 7a 45 72 72 4d 73 tNString(pzErrMs
3890: 67 2c 20 22 75 6e 72 65 63 6f 67 6e 69 7a 65 64 g, "unrecognized
38a0: 20 74 6f 6b 65 6e 3a 20 5c 22 22 2c 20 2d 31 2c token: \"", -1,
38b0: 20 0a 20 20 20 20 20 20 20 20 20 20 20 70 50 61 . pPa
38c0: 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2e rse->sLastToken.
38d0: 7a 2c 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 z, pParse->sLast
38e0: 54 6f 6b 65 6e 2e 6e 2c 20 22 5c 22 22 2c 20 31 Token.n, "\"", 1
38f0: 2c 20 30 29 3b 0a 20 20 20 20 20 20 20 20 6e 45 , 0);. nE
3900: 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 67 6f rr++;. go
3910: 74 6f 20 61 62 6f 72 74 5f 70 61 72 73 65 3b 0a to abort_parse;.
3920: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 63 61 }. ca
3930: 73 65 20 54 4b 5f 53 45 4d 49 3a 20 7b 0a 20 20 se TK_SEMI: {.
3940: 20 20 20 20 20 20 70 50 61 72 73 65 2d 3e 7a 54 pParse->zT
3950: 61 69 6c 20 3d 20 26 7a 53 71 6c 5b 69 5d 3b 0a ail = &zSql[i];.
3960: 20 20 20 20 20 20 20 20 2f 2a 20 46 61 6c 6c 20 /* Fall
3970: 74 68 72 75 20 69 6e 74 6f 20 74 68 65 20 64 65 thru into the de
3980: 66 61 75 6c 74 20 63 61 73 65 20 2a 2f 0a 20 20 fault case */.
3990: 20 20 20 20 7d 0a 20 20 20 20 20 20 64 65 66 61 }. defa
39a0: 75 6c 74 3a 20 7b 0a 20 20 20 20 20 20 20 20 73 ult: {. s
39b0: 71 6c 69 74 65 50 61 72 73 65 72 28 70 45 6e 67 qliteParser(pEng
39c0: 69 6e 65 2c 20 74 6f 6b 65 6e 54 79 70 65 2c 20 ine, tokenType,
39d0: 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b pParse->sLastTok
39e0: 65 6e 2c 20 70 50 61 72 73 65 29 3b 0a 20 20 20 en, pParse);.
39f0: 20 20 20 20 20 6c 61 73 74 54 6f 6b 65 6e 50 61 lastTokenPa
3a00: 72 73 65 64 20 3d 20 74 6f 6b 65 6e 54 79 70 65 rsed = tokenType
3a10: 3b 0a 20 20 20 20 20 20 20 20 69 66 28 20 70 50 ;. if( pP
3a20: 61 72 73 65 2d 3e 72 63 21 3d 53 51 4c 49 54 45 arse->rc!=SQLITE
3a30: 5f 4f 4b 20 29 7b 0a 20 20 20 20 20 20 20 20 20 _OK ){.
3a40: 20 67 6f 74 6f 20 61 62 6f 72 74 5f 70 61 72 73 goto abort_pars
3a50: 65 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 e;. }.
3a60: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
3a70: 20 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 61 62 }. }. }.ab
3a80: 6f 72 74 5f 70 61 72 73 65 3a 0a 20 20 69 66 28 ort_parse:. if(
3a90: 20 7a 53 71 6c 5b 69 5d 3d 3d 30 20 26 26 20 6e zSql[i]==0 && n
3aa0: 45 72 72 3d 3d 30 20 26 26 20 70 50 61 72 73 65 Err==0 && pParse
3ab0: 2d 3e 72 63 3d 3d 53 51 4c 49 54 45 5f 4f 4b 20 ->rc==SQLITE_OK
3ac0: 29 7b 0a 20 20 20 20 69 66 28 20 6c 61 73 74 54 ){. if( lastT
3ad0: 6f 6b 65 6e 50 61 72 73 65 64 21 3d 54 4b 5f 53 okenParsed!=TK_S
3ae0: 45 4d 49 20 29 7b 0a 20 20 20 20 20 20 73 71 6c EMI ){. sql
3af0: 69 74 65 50 61 72 73 65 72 28 70 45 6e 67 69 6e iteParser(pEngin
3b00: 65 2c 20 54 4b 5f 53 45 4d 49 2c 20 70 50 61 72 e, TK_SEMI, pPar
3b10: 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c 20 se->sLastToken,
3b20: 70 50 61 72 73 65 29 3b 0a 20 20 20 20 20 20 70 pParse);. p
3b30: 50 61 72 73 65 2d 3e 7a 54 61 69 6c 20 3d 20 26 Parse->zTail = &
3b40: 7a 53 71 6c 5b 69 5d 3b 0a 20 20 20 20 7d 0a 20 zSql[i];. }.
3b50: 20 20 20 73 71 6c 69 74 65 50 61 72 73 65 72 28 sqliteParser(
3b60: 70 45 6e 67 69 6e 65 2c 20 30 2c 20 70 50 61 72 pEngine, 0, pPar
3b70: 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c 20 se->sLastToken,
3b80: 70 50 61 72 73 65 29 3b 0a 20 20 7d 0a 20 20 73 pParse);. }. s
3b90: 71 6c 69 74 65 50 61 72 73 65 72 46 72 65 65 28 qliteParserFree(
3ba0: 70 45 6e 67 69 6e 65 2c 20 66 72 65 65 29 3b 0a pEngine, free);.
3bb0: 20 20 69 66 28 20 70 50 61 72 73 65 2d 3e 72 63 if( pParse->rc
3bc0: 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 26 26 20 70 !=SQLITE_OK && p
3bd0: 50 61 72 73 65 2d 3e 72 63 21 3d 53 51 4c 49 54 Parse->rc!=SQLIT
3be0: 45 5f 44 4f 4e 45 20 26 26 20 70 50 61 72 73 65 E_DONE && pParse
3bf0: 2d 3e 7a 45 72 72 4d 73 67 3d 3d 30 20 29 7b 0a ->zErrMsg==0 ){.
3c00: 20 20 20 20 73 71 6c 69 74 65 53 65 74 53 74 72 sqliteSetStr
3c10: 69 6e 67 28 26 70 50 61 72 73 65 2d 3e 7a 45 72 ing(&pParse->zEr
3c20: 72 4d 73 67 2c 20 73 71 6c 69 74 65 5f 65 72 72 rMsg, sqlite_err
3c30: 6f 72 5f 73 74 72 69 6e 67 28 70 50 61 72 73 65 or_string(pParse
3c40: 2d 3e 72 63 29 2c 0a 20 20 20 20 20 20 20 20 20 ->rc),.
3c50: 20 20 20 20 20 20 20 20 20 20 20 28 63 68 61 72 (char
3c60: 2a 29 30 29 3b 0a 20 20 7d 0a 20 20 69 66 28 20 *)0);. }. if(
3c70: 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 67 20 pParse->zErrMsg
3c80: 29 7b 0a 20 20 20 20 69 66 28 20 70 7a 45 72 72 ){. if( pzErr
3c90: 4d 73 67 20 26 26 20 2a 70 7a 45 72 72 4d 73 67 Msg && *pzErrMsg
3ca0: 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 2a 70 7a ==0 ){. *pz
3cb0: 45 72 72 4d 73 67 20 3d 20 70 50 61 72 73 65 2d ErrMsg = pParse-
3cc0: 3e 7a 45 72 72 4d 73 67 3b 0a 20 20 20 20 7d 65 >zErrMsg;. }e
3cd0: 6c 73 65 7b 0a 20 20 20 20 20 20 73 71 6c 69 74 lse{. sqlit
3ce0: 65 46 72 65 65 28 70 50 61 72 73 65 2d 3e 7a 45 eFree(pParse->zE
3cf0: 72 72 4d 73 67 29 3b 0a 20 20 20 20 7d 0a 20 20 rrMsg);. }.
3d00: 20 20 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 pParse->zErrMs
3d10: 67 20 3d 20 30 3b 0a 20 20 20 20 69 66 28 20 21 g = 0;. if( !
3d20: 6e 45 72 72 20 29 20 6e 45 72 72 2b 2b 3b 0a 20 nErr ) nErr++;.
3d30: 20 7d 0a 20 20 69 66 28 20 70 50 61 72 73 65 2d }. if( pParse-
3d40: 3e 70 56 64 62 65 20 26 26 20 28 70 50 61 72 73 >pVdbe && (pPars
3d50: 65 2d 3e 75 73 65 43 61 6c 6c 62 61 63 6b 20 7c e->useCallback |
3d60: 7c 20 70 50 61 72 73 65 2d 3e 6e 45 72 72 3e 30 | pParse->nErr>0
3d70: 29 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 56 ) ){. sqliteV
3d80: 64 62 65 44 65 6c 65 74 65 28 70 50 61 72 73 65 dbeDelete(pParse
3d90: 2d 3e 70 56 64 62 65 29 3b 0a 20 20 20 20 70 50 ->pVdbe);. pP
3da0: 61 72 73 65 2d 3e 70 56 64 62 65 20 3d 20 30 3b arse->pVdbe = 0;
3db0: 0a 20 20 7d 0a 20 20 69 66 28 20 70 50 61 72 73 . }. if( pPars
3dc0: 65 2d 3e 70 4e 65 77 54 61 62 6c 65 20 29 7b 0a e->pNewTable ){.
3dd0: 20 20 20 20 73 71 6c 69 74 65 44 65 6c 65 74 65 sqliteDelete
3de0: 54 61 62 6c 65 28 70 50 61 72 73 65 2d 3e 64 62 Table(pParse->db
3df0: 2c 20 70 50 61 72 73 65 2d 3e 70 4e 65 77 54 61 , pParse->pNewTa
3e00: 62 6c 65 29 3b 0a 20 20 20 20 70 50 61 72 73 65 ble);. pParse
3e10: 2d 3e 70 4e 65 77 54 61 62 6c 65 20 3d 20 30 3b ->pNewTable = 0;
3e20: 0a 20 20 7d 0a 20 20 69 66 28 20 70 50 61 72 73 . }. if( pPars
3e30: 65 2d 3e 70 4e 65 77 54 72 69 67 67 65 72 20 29 e->pNewTrigger )
3e40: 7b 0a 20 20 20 20 73 71 6c 69 74 65 44 65 6c 65 {. sqliteDele
3e50: 74 65 54 72 69 67 67 65 72 28 70 50 61 72 73 65 teTrigger(pParse
3e60: 2d 3e 70 4e 65 77 54 72 69 67 67 65 72 29 3b 0a ->pNewTrigger);.
3e70: 20 20 20 20 70 50 61 72 73 65 2d 3e 70 4e 65 77 pParse->pNew
3e80: 54 72 69 67 67 65 72 20 3d 20 30 3b 0a 20 20 7d Trigger = 0;. }
3e90: 0a 20 20 69 66 28 20 6e 45 72 72 3e 30 20 26 26 . if( nErr>0 &&
3ea0: 20 28 70 50 61 72 73 65 2d 3e 72 63 3d 3d 53 51 (pParse->rc==SQ
3eb0: 4c 49 54 45 5f 4f 4b 20 7c 7c 20 70 50 61 72 73 LITE_OK || pPars
3ec0: 65 2d 3e 72 63 3d 3d 53 51 4c 49 54 45 5f 44 4f e->rc==SQLITE_DO
3ed0: 4e 45 29 20 29 7b 0a 20 20 20 20 70 50 61 72 73 NE) ){. pPars
3ee0: 65 2d 3e 72 63 20 3d 20 53 51 4c 49 54 45 5f 45 e->rc = SQLITE_E
3ef0: 52 52 4f 52 3b 0a 20 20 7d 0a 20 20 72 65 74 75 RROR;. }. retu
3f00: 72 6e 20 6e 45 72 72 3b 0a 7d 0a 0a 2f 2a 0a 2a rn nErr;.}../*.*
3f10: 2a 20 54 6f 6b 65 6e 20 74 79 70 65 73 20 75 73 * Token types us
3f20: 65 64 20 62 79 20 74 68 65 20 73 71 6c 69 74 65 ed by the sqlite
3f30: 5f 63 6f 6d 70 6c 65 74 65 28 29 20 72 6f 75 74 _complete() rout
3f40: 69 6e 65 2e 20 20 53 65 65 20 74 68 65 20 68 65 ine. See the he
3f50: 61 64 65 72 0a 2a 2a 20 63 6f 6d 6d 65 6e 74 73 ader.** comments
3f60: 20 6f 6e 20 74 68 61 74 20 70 72 6f 63 65 64 75 on that procedu
3f70: 72 65 20 66 6f 72 20 61 64 64 69 74 69 6f 6e 61 re for additiona
3f80: 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 0a 2a l information..*
3f90: 2f 0a 23 64 65 66 69 6e 65 20 74 6b 45 58 50 4c /.#define tkEXPL
3fa0: 41 49 4e 20 30 0a 23 64 65 66 69 6e 65 20 74 6b AIN 0.#define tk
3fb0: 43 52 45 41 54 45 20 20 31 0a 23 64 65 66 69 6e CREATE 1.#defin
3fc0: 65 20 74 6b 54 45 4d 50 20 20 20 20 32 0a 23 64 e tkTEMP 2.#d
3fd0: 65 66 69 6e 65 20 74 6b 54 52 49 47 47 45 52 20 efine tkTRIGGER
3fe0: 33 0a 23 64 65 66 69 6e 65 20 74 6b 45 4e 44 20 3.#define tkEND
3ff0: 20 20 20 20 34 0a 23 64 65 66 69 6e 65 20 74 6b 4.#define tk
4000: 53 45 4d 49 20 20 20 20 35 0a 23 64 65 66 69 6e SEMI 5.#defin
4010: 65 20 74 6b 57 53 20 20 20 20 20 20 36 0a 23 64 e tkWS 6.#d
4020: 65 66 69 6e 65 20 74 6b 4f 54 48 45 52 20 20 20 efine tkOTHER
4030: 37 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 7../*.** Return
4040: 54 52 55 45 20 69 66 20 74 68 65 20 67 69 76 65 TRUE if the give
4050: 6e 20 53 51 4c 20 73 74 72 69 6e 67 20 65 6e 64 n SQL string end
4060: 73 20 69 6e 20 61 20 73 65 6d 69 63 6f 6c 6f 6e s in a semicolon
4070: 2e 0a 2a 2a 0a 2a 2a 20 53 70 65 63 69 61 6c 20 ..**.** Special
4080: 68 61 6e 64 6c 69 6e 67 20 69 73 20 72 65 71 75 handling is requ
4090: 69 72 65 20 66 6f 72 20 43 52 45 41 54 45 20 54 ire for CREATE T
40a0: 52 49 47 47 45 52 20 73 74 61 74 65 6d 65 6e 74 RIGGER statement
40b0: 73 2e 0a 2a 2a 20 57 68 65 6e 65 76 65 72 20 74 s..** Whenever t
40c0: 68 65 20 43 52 45 41 54 45 20 54 52 49 47 47 45 he CREATE TRIGGE
40d0: 52 20 6b 65 79 77 6f 72 64 73 20 61 72 65 20 73 R keywords are s
40e0: 65 65 6e 2c 20 74 68 65 20 73 74 61 74 65 6d 65 een, the stateme
40f0: 6e 74 0a 2a 2a 20 6d 75 73 74 20 65 6e 64 20 77 nt.** must end w
4100: 69 74 68 20 22 3b 45 4e 44 3b 22 2e 0a 2a 2a 0a ith ";END;"..**.
4110: 2a 2a 20 54 68 69 73 20 69 6d 70 6c 65 6d 65 6e ** This implemen
4120: 74 61 74 69 6f 6e 20 75 73 65 73 20 61 20 73 74 tation uses a st
4130: 61 74 65 20 6d 61 63 68 69 6e 65 20 77 69 74 68 ate machine with
4140: 20 37 20 73 74 61 74 65 73 3a 0a 2a 2a 0a 2a 2a 7 states:.**.**
4150: 20 20 20 28 30 29 20 53 54 41 52 54 20 20 20 20 (0) START
4160: 20 41 74 20 74 68 65 20 62 65 67 69 6e 6e 69 6e At the beginnin
4170: 67 20 6f 72 20 65 6e 64 20 6f 66 20 61 6e 20 53 g or end of an S
4180: 51 4c 20 73 74 61 74 65 6d 65 6e 74 2e 20 20 54 QL statement. T
4190: 68 69 73 20 72 6f 75 74 69 6e 65 0a 2a 2a 20 20 his routine.**
41a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 72 r
41b0: 65 74 75 72 6e 73 20 31 20 69 66 20 69 74 20 65 eturns 1 if it e
41c0: 6e 64 73 20 69 6e 20 74 68 65 20 53 54 41 52 54 nds in the START
41d0: 20 73 74 61 74 65 20 61 6e 64 20 30 20 69 66 20 state and 0 if
41e0: 69 74 20 65 6e 64 73 0a 2a 2a 20 20 20 20 20 20 it ends.**
41f0: 20 20 20 20 20 20 20 20 20 20 20 69 6e 20 61 6e in an
4200: 79 20 6f 74 68 65 72 20 73 74 61 74 65 2e 0a 2a y other state..*
4210: 2a 0a 2a 2a 20 20 20 28 31 29 20 45 58 50 4c 41 *.** (1) EXPLA
4220: 49 4e 20 20 20 54 68 65 20 6b 65 79 77 6f 72 64 IN The keyword
4230: 20 45 58 50 4c 41 49 4e 20 68 61 73 20 62 65 65 EXPLAIN has bee
4240: 6e 20 73 65 65 6e 20 61 74 20 74 68 65 20 62 65 n seen at the be
4250: 67 69 6e 6e 69 6e 67 20 6f 66 20 0a 2a 2a 20 20 ginning of .**
4260: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 61 a
4270: 20 73 74 61 74 65 6d 65 6e 74 2e 0a 2a 2a 0a 2a statement..**.*
4280: 2a 20 20 20 28 32 29 20 43 52 45 41 54 45 20 20 * (2) CREATE
4290: 20 20 54 68 65 20 6b 65 79 77 6f 72 64 20 43 52 The keyword CR
42a0: 45 41 54 45 20 68 61 73 20 62 65 65 6e 20 73 65 EATE has been se
42b0: 65 6e 20 61 74 20 74 68 65 20 62 65 67 69 6e 6e en at the beginn
42c0: 69 6e 67 20 6f 66 20 61 0a 2a 2a 20 20 20 20 20 ing of a.**
42d0: 20 20 20 20 20 20 20 20 20 20 20 20 73 74 61 74 stat
42e0: 65 6d 65 6e 74 2c 20 70 6f 73 73 69 62 6c 79 20 ement, possibly
42f0: 70 72 65 63 65 65 64 65 64 20 62 79 20 45 58 50 preceeded by EXP
4300: 4c 41 49 4e 20 61 6e 64 2f 6f 72 20 66 6f 6c 6c LAIN and/or foll
4310: 6f 77 65 64 20 62 79 0a 2a 2a 20 20 20 20 20 20 owed by.**
4320: 20 20 20 20 20 20 20 20 20 20 20 54 45 4d 50 20 TEMP
4330: 6f 72 20 54 45 4d 50 4f 52 41 52 59 0a 2a 2a 0a or TEMPORARY.**.
4340: 2a 2a 20 20 20 28 33 29 20 4e 4f 52 4d 41 4c 20 ** (3) NORMAL
4350: 20 20 20 57 65 20 61 72 65 20 69 6e 20 74 68 65 We are in the
4360: 20 6d 69 64 64 6c 65 20 6f 66 20 73 74 61 74 65 middle of state
4370: 6d 65 6e 74 20 77 68 69 63 68 20 65 6e 64 73 20 ment which ends
4380: 77 69 74 68 20 61 20 73 69 6e 67 6c 65 0a 2a 2a with a single.**
4390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
43a0: 20 73 65 6d 69 63 6f 6c 6f 6e 2e 0a 2a 2a 0a 2a semicolon..**.*
43b0: 2a 20 20 20 28 34 29 20 54 52 49 47 47 45 52 20 * (4) TRIGGER
43c0: 20 20 57 65 20 61 72 65 20 69 6e 20 74 68 65 20 We are in the
43d0: 6d 69 64 64 6c 65 20 6f 66 20 61 20 74 72 69 67 middle of a trig
43e0: 67 65 72 20 64 65 66 69 6e 69 74 69 6f 6e 20 74 ger definition t
43f0: 68 61 74 20 6d 75 73 74 20 62 65 0a 2a 2a 20 20 hat must be.**
4400: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 65 e
4410: 6e 64 65 64 20 62 79 20 61 20 73 65 6d 69 63 6f nded by a semico
4420: 6c 6f 6e 2c 20 74 68 65 20 6b 65 79 77 6f 72 64 lon, the keyword
4430: 20 45 4e 44 2c 20 61 6e 64 20 61 6e 6f 74 68 65 END, and anothe
4440: 72 20 73 65 6d 69 63 6f 6c 6f 6e 2e 0a 2a 2a 0a r semicolon..**.
4450: 2a 2a 20 20 20 28 35 29 20 53 45 4d 49 20 20 20 ** (5) SEMI
4460: 20 20 20 57 65 27 76 65 20 73 65 65 6e 20 74 68 We've seen th
4470: 65 20 66 69 72 73 74 20 73 65 6d 69 63 6f 6c 6f e first semicolo
4480: 6e 20 69 6e 20 74 68 65 20 22 3b 45 4e 44 3b 22 n in the ";END;"
4490: 20 74 68 61 74 20 6f 63 63 75 72 73 20 61 74 0a that occurs at.
44a0: 2a 2a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 **
44b0: 20 20 20 74 68 65 20 65 6e 64 20 6f 66 20 61 20 the end of a
44c0: 74 72 69 67 67 65 72 20 64 65 66 69 6e 69 74 69 trigger definiti
44d0: 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 20 20 28 36 29 20 on..**.** (6)
44e0: 45 4e 44 20 20 20 20 20 20 20 57 65 27 76 65 20 END We've
44f0: 73 65 65 6e 20 74 68 65 20 22 3b 45 4e 44 22 20 seen the ";END"
4500: 6f 66 20 74 68 65 20 22 3b 45 4e 44 3b 22 20 74 of the ";END;" t
4510: 68 61 74 20 6f 63 63 75 72 73 20 61 74 20 74 68 hat occurs at th
4520: 65 20 65 6e 64 0a 2a 2a 20 20 20 20 20 20 20 20 e end.**
4530: 20 20 20 20 20 20 20 20 20 6f 66 20 61 20 74 72 of a tr
4540: 69 67 67 65 72 20 64 69 66 69 6e 69 74 69 6f 6e igger difinition
4550: 2e 0a 2a 2a 0a 2a 2a 20 54 72 61 6e 73 69 74 69 ..**.** Transiti
4560: 6f 6e 73 20 62 65 74 77 65 65 6e 20 73 74 61 74 ons between stat
4570: 65 73 20 61 62 6f 76 65 20 61 72 65 20 64 65 74 es above are det
4580: 65 72 6d 69 6e 65 64 20 62 79 20 74 6f 6b 65 6e ermined by token
4590: 73 20 65 78 74 72 61 63 74 65 64 0a 2a 2a 20 66 s extracted.** f
45a0: 72 6f 6d 20 74 68 65 20 69 6e 70 75 74 2e 20 20 rom the input.
45b0: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 6f The following to
45c0: 6b 65 6e 73 20 61 72 65 20 73 69 67 6e 69 66 69 kens are signifi
45d0: 63 61 6e 74 3a 0a 2a 2a 0a 2a 2a 20 20 20 28 30 cant:.**.** (0
45e0: 29 20 74 6b 45 58 50 4c 41 49 4e 20 20 20 54 68 ) tkEXPLAIN Th
45f0: 65 20 22 65 78 70 6c 61 69 6e 22 20 6b 65 79 77 e "explain" keyw
4600: 6f 72 64 2e 0a 2a 2a 20 20 20 28 31 29 20 74 6b ord..** (1) tk
4610: 43 52 45 41 54 45 20 20 20 20 54 68 65 20 22 63 CREATE The "c
4620: 72 65 61 74 65 22 20 6b 65 79 77 6f 72 64 2e 0a reate" keyword..
4630: 2a 2a 20 20 20 28 32 29 20 74 6b 54 45 4d 50 20 ** (2) tkTEMP
4640: 20 20 20 20 20 54 68 65 20 22 74 65 6d 70 22 20 The "temp"
4650: 6f 72 20 22 74 65 6d 70 6f 72 61 72 79 22 20 6b or "temporary" k
4660: 65 79 77 6f 72 64 2e 0a 2a 2a 20 20 20 28 33 29 eyword..** (3)
4670: 20 74 6b 54 52 49 47 47 45 52 20 20 20 54 68 65 tkTRIGGER The
4680: 20 22 74 72 69 67 67 65 72 22 20 6b 65 79 77 6f "trigger" keywo
4690: 72 64 2e 0a 2a 2a 20 20 20 28 34 29 20 74 6b 45 rd..** (4) tkE
46a0: 4e 44 20 20 20 20 20 20 20 54 68 65 20 22 65 6e ND The "en
46b0: 64 22 20 6b 65 79 77 6f 72 64 2e 0a 2a 2a 20 20 d" keyword..**
46c0: 20 28 35 29 20 74 6b 53 45 4d 49 20 20 20 20 20 (5) tkSEMI
46d0: 20 41 20 73 65 6d 69 63 6f 6c 6f 6e 2e 0a 2a 2a A semicolon..**
46e0: 20 20 20 28 36 29 20 74 6b 57 53 20 20 20 20 20 (6) tkWS
46f0: 20 20 20 57 68 69 74 65 73 70 61 63 65 0a 2a 2a Whitespace.**
4700: 20 20 20 28 37 29 20 74 6b 4f 54 48 45 52 20 20 (7) tkOTHER
4710: 20 20 20 41 6e 79 20 6f 74 68 65 72 20 53 51 4c Any other SQL
4720: 20 74 6f 6b 65 6e 2e 0a 2a 2a 0a 2a 2a 20 57 68 token..**.** Wh
4730: 69 74 65 73 70 61 63 65 20 6e 65 76 65 72 20 63 itespace never c
4740: 61 75 73 65 73 20 61 20 73 74 61 74 65 20 74 72 auses a state tr
4750: 61 6e 73 69 74 69 6f 6e 20 61 6e 64 20 69 73 20 ansition and is
4760: 61 6c 77 61 79 73 20 69 67 6e 6f 72 65 64 2e 0a always ignored..
4770: 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 5f 63 6f */.int sqlite_co
4780: 6d 70 6c 65 74 65 28 63 6f 6e 73 74 20 63 68 61 mplete(const cha
4790: 72 20 2a 7a 53 71 6c 29 7b 0a 20 20 75 38 20 73 r *zSql){. u8 s
47a0: 74 61 74 65 20 3d 20 30 3b 20 20 20 2f 2a 20 43 tate = 0; /* C
47b0: 75 72 72 65 6e 74 20 73 74 61 74 65 2c 20 75 73 urrent state, us
47c0: 69 6e 67 20 6e 75 6d 62 65 72 73 20 64 65 66 69 ing numbers defi
47d0: 6e 65 64 20 69 6e 20 68 65 61 64 65 72 20 63 6f ned in header co
47e0: 6d 6d 65 6e 74 20 2a 2f 0a 20 20 75 38 20 74 6f mment */. u8 to
47f0: 6b 65 6e 3b 20 20 20 20 20 20 20 2f 2a 20 56 61 ken; /* Va
4800: 6c 75 65 20 6f 66 20 74 68 65 20 6e 65 78 74 20 lue of the next
4810: 74 6f 6b 65 6e 20 2a 2f 0a 0a 20 20 2f 2a 20 54 token */.. /* T
4820: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 6d 61 74 he following mat
4830: 72 69 78 20 64 65 66 69 6e 65 73 20 74 68 65 20 rix defines the
4840: 74 72 61 6e 73 69 74 69 6f 6e 20 66 72 6f 6d 20 transition from
4850: 6f 6e 65 20 73 74 61 74 65 20 74 6f 20 61 6e 6f one state to ano
4860: 74 68 65 72 0a 20 20 2a 2a 20 61 63 63 6f 72 64 ther. ** accord
4870: 69 6e 67 20 74 6f 20 77 68 61 74 20 74 6f 6b 65 ing to what toke
4880: 6e 20 69 73 20 73 65 65 6e 2e 20 20 74 72 61 6e n is seen. tran
4890: 73 5b 73 74 61 74 65 5d 5b 74 6f 6b 65 6e 5d 20 s[state][token]
48a0: 72 65 74 75 72 6e 73 20 74 68 65 0a 20 20 2a 2a returns the. **
48b0: 20 6e 65 78 74 20 73 74 61 74 65 2e 0a 20 20 2a next state.. *
48c0: 2f 0a 20 20 73 74 61 74 69 63 20 63 6f 6e 73 74 /. static const
48d0: 20 75 38 20 74 72 61 6e 73 5b 37 5d 5b 38 5d 20 u8 trans[7][8]
48e0: 3d 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 = {.
48f0: 20 20 20 20 20 20 20 20 20 2f 2a 20 54 6f 6b 65 /* Toke
4900: 6e 3a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 n:
4910: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4920: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
4930: 20 20 2a 2f 0a 20 20 20 20 20 2f 2a 20 53 74 61 */. /* Sta
4940: 74 65 3a 20 20 20 20 20 20 20 2a 2a 20 20 45 58 te: ** EX
4950: 50 4c 41 49 4e 20 20 43 52 45 41 54 45 20 20 54 PLAIN CREATE T
4960: 45 4d 50 20 20 54 52 49 47 47 45 52 20 20 45 4e EMP TRIGGER EN
4970: 44 20 20 53 45 4d 49 20 20 57 53 20 20 4f 54 48 D SEMI WS OTH
4980: 45 52 20 2a 2f 0a 20 20 20 20 20 2f 2a 20 30 20 ER */. /* 0
4990: 20 20 53 54 41 52 54 3a 20 2a 2f 20 7b 20 20 20 START: */ {
49a0: 20 20 20 20 31 2c 20 20 20 20 20 20 32 2c 20 20 1, 2,
49b0: 20 20 33 2c 20 20 20 20 20 20 20 33 2c 20 20 20 3, 3,
49c0: 33 2c 20 20 20 20 30 2c 20 20 30 2c 20 20 20 20 3, 0, 0,
49d0: 20 33 2c 20 7d 2c 0a 20 20 20 20 20 2f 2a 20 31 3, },. /* 1
49e0: 20 45 58 50 4c 41 49 4e 3a 20 2a 2f 20 7b 20 20 EXPLAIN: */ {
49f0: 20 20 20 20 20 33 2c 20 20 20 20 20 20 32 2c 20 3, 2,
4a00: 20 20 20 33 2c 20 20 20 20 20 20 20 33 2c 20 20 3, 3,
4a10: 20 33 2c 20 20 20 20 30 2c 20 20 31 2c 20 20 20 3, 0, 1,
4a20: 20 20 33 2c 20 7d 2c 0a 20 20 20 20 20 2f 2a 20 3, },. /*
4a30: 32 20 20 43 52 45 41 54 45 3a 20 2a 2f 20 7b 20 2 CREATE: */ {
4a40: 20 20 20 20 20 20 33 2c 20 20 20 20 20 20 33 2c 3, 3,
4a50: 20 20 20 20 32 2c 20 20 20 20 20 20 20 34 2c 20 2, 4,
4a60: 20 20 33 2c 20 20 20 20 30 2c 20 20 32 2c 20 20 3, 0, 2,
4a70: 20 20 20 33 2c 20 7d 2c 0a 20 20 20 20 20 2f 2a 3, },. /*
4a80: 20 33 20 20 4e 4f 52 4d 41 4c 3a 20 2a 2f 20 7b 3 NORMAL: */ {
4a90: 20 20 20 20 20 20 20 33 2c 20 20 20 20 20 20 33 3, 3
4aa0: 2c 20 20 20 20 33 2c 20 20 20 20 20 20 20 33 2c , 3, 3,
4ab0: 20 20 20 33 2c 20 20 20 20 30 2c 20 20 33 2c 20 3, 0, 3,
4ac0: 20 20 20 20 33 2c 20 7d 2c 0a 20 20 20 20 20 2f 3, },. /
4ad0: 2a 20 34 20 54 52 49 47 47 45 52 3a 20 2a 2f 20 * 4 TRIGGER: */
4ae0: 7b 20 20 20 20 20 20 20 34 2c 20 20 20 20 20 20 { 4,
4af0: 34 2c 20 20 20 20 34 2c 20 20 20 20 20 20 20 34 4, 4, 4
4b00: 2c 20 20 20 34 2c 20 20 20 20 35 2c 20 20 34 2c , 4, 5, 4,
4b10: 20 20 20 20 20 34 2c 20 7d 2c 0a 20 20 20 20 20 4, },.
4b20: 2f 2a 20 35 20 20 20 20 53 45 4d 49 3a 20 2a 2f /* 5 SEMI: */
4b30: 20 7b 20 20 20 20 20 20 20 34 2c 20 20 20 20 20 { 4,
4b40: 20 34 2c 20 20 20 20 34 2c 20 20 20 20 20 20 20 4, 4,
4b50: 34 2c 20 20 20 36 2c 20 20 20 20 35 2c 20 20 35 4, 6, 5, 5
4b60: 2c 20 20 20 20 20 34 2c 20 7d 2c 0a 20 20 20 20 , 4, },.
4b70: 20 2f 2a 20 36 20 20 20 20 20 45 4e 44 3a 20 2a /* 6 END: *
4b80: 2f 20 7b 20 20 20 20 20 20 20 34 2c 20 20 20 20 / { 4,
4b90: 20 20 34 2c 20 20 20 20 34 2c 20 20 20 20 20 20 4, 4,
4ba0: 20 34 2c 20 20 20 34 2c 20 20 20 20 30 2c 20 20 4, 4, 0,
4bb0: 36 2c 20 20 20 20 20 34 2c 20 7d 2c 0a 20 20 7d 6, 4, },. }
4bc0: 3b 0a 0a 20 20 77 68 69 6c 65 28 20 2a 7a 53 71 ;.. while( *zSq
4bd0: 6c 20 29 7b 0a 20 20 20 20 73 77 69 74 63 68 28 l ){. switch(
4be0: 20 2a 7a 53 71 6c 20 29 7b 0a 20 20 20 20 20 20 *zSql ){.
4bf0: 63 61 73 65 20 27 3b 27 3a 20 7b 20 20 2f 2a 20 case ';': { /*
4c00: 41 20 73 65 6d 69 63 6f 6c 6f 6e 20 2a 2f 0a 20 A semicolon */.
4c10: 20 20 20 20 20 20 20 74 6f 6b 65 6e 20 3d 20 74 token = t
4c20: 6b 53 45 4d 49 3b 0a 20 20 20 20 20 20 20 20 62 kSEMI;. b
4c30: 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 reak;. }.
4c40: 20 20 20 20 63 61 73 65 20 27 20 27 3a 0a 20 20 case ' ':.
4c50: 20 20 20 20 63 61 73 65 20 27 5c 72 27 3a 0a 20 case '\r':.
4c60: 20 20 20 20 20 63 61 73 65 20 27 5c 74 27 3a 0a case '\t':.
4c70: 20 20 20 20 20 20 63 61 73 65 20 27 5c 6e 27 3a case '\n':
4c80: 0a 20 20 20 20 20 20 63 61 73 65 20 27 5c 66 27 . case '\f'
4c90: 3a 20 7b 20 20 2f 2a 20 57 68 69 74 65 20 73 70 : { /* White sp
4ca0: 61 63 65 20 69 73 20 69 67 6e 6f 72 65 64 20 2a ace is ignored *
4cb0: 2f 0a 20 20 20 20 20 20 20 20 74 6f 6b 65 6e 20 /. token
4cc0: 3d 20 74 6b 57 53 3b 0a 20 20 20 20 20 20 20 20 = tkWS;.
4cd0: 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 break;. }.
4ce0: 20 20 20 20 20 63 61 73 65 20 27 2f 27 3a 20 7b case '/': {
4cf0: 20 20 20 2f 2a 20 43 2d 73 74 79 6c 65 20 63 6f /* C-style co
4d00: 6d 6d 65 6e 74 73 20 2a 2f 0a 20 20 20 20 20 20 mments */.
4d10: 20 20 69 66 28 20 7a 53 71 6c 5b 31 5d 21 3d 27 if( zSql[1]!='
4d20: 2a 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 *' ){.
4d30: 74 6f 6b 65 6e 20 3d 20 74 6b 4f 54 48 45 52 3b token = tkOTHER;
4d40: 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b . break
4d50: 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 ;. }.
4d60: 20 20 20 20 7a 53 71 6c 20 2b 3d 20 32 3b 0a 20 zSql += 2;.
4d70: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 7a 53 while( zS
4d80: 71 6c 5b 30 5d 20 26 26 20 28 7a 53 71 6c 5b 30 ql[0] && (zSql[0
4d90: 5d 21 3d 27 2a 27 20 7c 7c 20 7a 53 71 6c 5b 31 ]!='*' || zSql[1
4da0: 5d 21 3d 27 2f 27 29 20 29 7b 20 7a 53 71 6c 2b ]!='/') ){ zSql+
4db0: 2b 3b 20 7d 0a 20 20 20 20 20 20 20 20 69 66 28 +; }. if(
4dc0: 20 7a 53 71 6c 5b 30 5d 3d 3d 30 20 29 20 72 65 zSql[0]==0 ) re
4dd0: 74 75 72 6e 20 30 3b 0a 20 20 20 20 20 20 20 20 turn 0;.
4de0: 7a 53 71 6c 2b 2b 3b 0a 20 20 20 20 20 20 20 20 zSql++;.
4df0: 74 6f 6b 65 6e 20 3d 20 74 6b 57 53 3b 0a 20 20 token = tkWS;.
4e00: 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 break;.
4e10: 20 20 20 7d 0a 20 20 20 20 20 20 63 61 73 65 20 }. case
4e20: 27 2d 27 3a 20 7b 20 20 20 2f 2a 20 53 51 4c 2d '-': { /* SQL-
4e30: 73 74 79 6c 65 20 63 6f 6d 6d 65 6e 74 73 20 66 style comments f
4e40: 72 6f 6d 20 22 2d 2d 22 20 74 6f 20 65 6e 64 20 rom "--" to end
4e50: 6f 66 20 6c 69 6e 65 20 2a 2f 0a 20 20 20 20 20 of line */.
4e60: 20 20 20 69 66 28 20 7a 53 71 6c 5b 31 5d 21 3d if( zSql[1]!=
4e70: 27 2d 27 20 29 7b 0a 20 20 20 20 20 20 20 20 20 '-' ){.
4e80: 20 74 6f 6b 65 6e 20 3d 20 74 6b 4f 54 48 45 52 token = tkOTHER
4e90: 3b 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 ;. brea
4ea0: 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 k;. }.
4eb0: 20 20 20 20 20 77 68 69 6c 65 28 20 2a 7a 53 71 while( *zSq
4ec0: 6c 20 26 26 20 2a 7a 53 71 6c 21 3d 27 5c 6e 27 l && *zSql!='\n'
4ed0: 20 29 7b 20 7a 53 71 6c 2b 2b 3b 20 7d 0a 20 20 ){ zSql++; }.
4ee0: 20 20 20 20 20 20 69 66 28 20 2a 7a 53 71 6c 3d if( *zSql=
4ef0: 3d 30 20 29 20 72 65 74 75 72 6e 20 73 74 61 74 =0 ) return stat
4f00: 65 3d 3d 30 3b 0a 20 20 20 20 20 20 20 20 74 6f e==0;. to
4f10: 6b 65 6e 20 3d 20 74 6b 57 53 3b 0a 20 20 20 20 ken = tkWS;.
4f20: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
4f30: 20 7d 0a 20 20 20 20 20 20 63 61 73 65 20 27 5b }. case '[
4f40: 27 3a 20 7b 20 20 20 2f 2a 20 4d 69 63 72 6f 73 ': { /* Micros
4f50: 6f 66 74 2d 73 74 79 6c 65 20 69 64 65 6e 74 69 oft-style identi
4f60: 66 69 65 72 73 20 69 6e 20 5b 2e 2e 2e 5d 20 2a fiers in [...] *
4f70: 2f 0a 20 20 20 20 20 20 20 20 7a 53 71 6c 2b 2b /. zSql++
4f80: 3b 0a 20 20 20 20 20 20 20 20 77 68 69 6c 65 28 ;. while(
4f90: 20 2a 7a 53 71 6c 20 26 26 20 2a 7a 53 71 6c 21 *zSql && *zSql!
4fa0: 3d 27 5d 27 20 29 7b 20 7a 53 71 6c 2b 2b 3b 20 =']' ){ zSql++;
4fb0: 7d 0a 20 20 20 20 20 20 20 20 69 66 28 20 2a 7a }. if( *z
4fc0: 53 71 6c 3d 3d 30 20 29 20 72 65 74 75 72 6e 20 Sql==0 ) return
4fd0: 30 3b 0a 20 20 20 20 20 20 20 20 74 6f 6b 65 6e 0;. token
4fe0: 20 3d 20 74 6b 4f 54 48 45 52 3b 0a 20 20 20 20 = tkOTHER;.
4ff0: 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 break;.
5000: 20 7d 0a 20 20 20 20 20 20 63 61 73 65 20 27 22 }. case '"
5010: 27 3a 20 20 20 20 20 2f 2a 20 73 69 6e 67 6c 65 ': /* single
5020: 2d 20 61 6e 64 20 64 6f 75 62 6c 65 2d 71 75 6f - and double-quo
5030: 74 65 64 20 73 74 72 69 6e 67 73 20 2a 2f 0a 20 ted strings */.
5040: 20 20 20 20 20 63 61 73 65 20 27 5c 27 27 3a 20 case '\'':
5050: 7b 0a 20 20 20 20 20 20 20 20 69 6e 74 20 63 20 {. int c
5060: 3d 20 2a 7a 53 71 6c 3b 0a 20 20 20 20 20 20 20 = *zSql;.
5070: 20 7a 53 71 6c 2b 2b 3b 0a 20 20 20 20 20 20 20 zSql++;.
5080: 20 77 68 69 6c 65 28 20 2a 7a 53 71 6c 20 26 26 while( *zSql &&
5090: 20 2a 7a 53 71 6c 21 3d 63 20 29 7b 20 7a 53 71 *zSql!=c ){ zSq
50a0: 6c 2b 2b 3b 20 7d 0a 20 20 20 20 20 20 20 20 69 l++; }. i
50b0: 66 28 20 2a 7a 53 71 6c 3d 3d 30 20 29 20 72 65 f( *zSql==0 ) re
50c0: 74 75 72 6e 20 30 3b 0a 20 20 20 20 20 20 20 20 turn 0;.
50d0: 74 6f 6b 65 6e 20 3d 20 74 6b 4f 54 48 45 52 3b token = tkOTHER;
50e0: 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a . break;.
50f0: 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 65 }. de
5100: 66 61 75 6c 74 3a 20 7b 0a 20 20 20 20 20 20 20 fault: {.
5110: 20 69 66 28 20 69 73 49 64 43 68 61 72 5b 28 75 if( isIdChar[(u
5120: 38 29 2a 7a 53 71 6c 5d 20 29 7b 0a 20 20 20 20 8)*zSql] ){.
5130: 20 20 20 20 20 20 2f 2a 20 4b 65 79 77 6f 72 64 /* Keyword
5140: 73 20 61 6e 64 20 75 6e 71 75 6f 74 65 64 20 69 s and unquoted i
5150: 64 65 6e 74 69 66 69 65 72 73 20 2a 2f 0a 20 20 dentifiers */.
5160: 20 20 20 20 20 20 20 20 69 6e 74 20 6e 49 64 3b int nId;
5170: 0a 20 20 20 20 20 20 20 20 20 20 66 6f 72 28 6e . for(n
5180: 49 64 3d 31 3b 20 69 73 49 64 43 68 61 72 5b 28 Id=1; isIdChar[(
5190: 75 38 29 7a 53 71 6c 5b 6e 49 64 5d 5d 3b 20 6e u8)zSql[nId]]; n
51a0: 49 64 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 20 20 Id++){}.
51b0: 20 20 73 77 69 74 63 68 28 20 2a 7a 53 71 6c 20 switch( *zSql
51c0: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 63 ){. c
51d0: 61 73 65 20 27 63 27 3a 20 63 61 73 65 20 27 43 ase 'c': case 'C
51e0: 27 3a 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 ': {.
51f0: 20 20 20 69 66 28 20 6e 49 64 3d 3d 36 20 26 26 if( nId==6 &&
5200: 20 73 71 6c 69 74 65 53 74 72 4e 49 43 6d 70 28 sqliteStrNICmp(
5210: 7a 53 71 6c 2c 20 22 63 72 65 61 74 65 22 2c 20 zSql, "create",
5220: 36 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 6)==0 ){.
5230: 20 20 20 20 20 20 20 20 20 74 6f 6b 65 6e 20 3d token =
5240: 20 74 6b 43 52 45 41 54 45 3b 0a 20 20 20 20 20 tkCREATE;.
5250: 20 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a }else{.
5260: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
5270: 74 6f 6b 65 6e 20 3d 20 74 6b 4f 54 48 45 52 3b token = tkOTHER;
5280: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 7d . }
5290: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 62 . b
52a0: 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 20 reak;.
52b0: 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 20 20 }.
52c0: 63 61 73 65 20 27 74 27 3a 20 63 61 73 65 20 27 case 't': case '
52d0: 54 27 3a 20 7b 0a 20 20 20 20 20 20 20 20 20 20 T': {.
52e0: 20 20 20 20 69 66 28 20 6e 49 64 3d 3d 37 20 26 if( nId==7 &
52f0: 26 20 73 71 6c 69 74 65 53 74 72 4e 49 43 6d 70 & sqliteStrNICmp
5300: 28 7a 53 71 6c 2c 20 22 74 72 69 67 67 65 72 22 (zSql, "trigger"
5310: 2c 20 37 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 , 7)==0 ){.
5320: 20 20 20 20 20 20 20 20 20 20 20 74 6f 6b 65 6e token
5330: 20 3d 20 74 6b 54 52 49 47 47 45 52 3b 0a 20 20 = tkTRIGGER;.
5340: 20 20 20 20 20 20 20 20 20 20 20 20 7d 65 6c 73 }els
5350: 65 20 69 66 28 20 6e 49 64 3d 3d 34 20 26 26 20 e if( nId==4 &&
5360: 73 71 6c 69 74 65 53 74 72 4e 49 43 6d 70 28 7a sqliteStrNICmp(z
5370: 53 71 6c 2c 20 22 74 65 6d 70 22 2c 20 34 29 3d Sql, "temp", 4)=
5380: 3d 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 =0 ){.
5390: 20 20 20 20 20 20 74 6f 6b 65 6e 20 3d 20 74 6b token = tk
53a0: 54 45 4d 50 3b 0a 20 20 20 20 20 20 20 20 20 20 TEMP;.
53b0: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 6e 49 }else if( nI
53c0: 64 3d 3d 39 20 26 26 20 73 71 6c 69 74 65 53 74 d==9 && sqliteSt
53d0: 72 4e 49 43 6d 70 28 7a 53 71 6c 2c 20 22 74 65 rNICmp(zSql, "te
53e0: 6d 70 6f 72 61 72 79 22 2c 20 39 29 3d 3d 30 20 mporary", 9)==0
53f0: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ){.
5400: 20 20 20 74 6f 6b 65 6e 20 3d 20 74 6b 54 45 4d token = tkTEM
5410: 50 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 P;.
5420: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 20 }else{.
5430: 20 20 20 20 20 20 20 20 74 6f 6b 65 6e 20 3d 20 token =
5440: 74 6b 4f 54 48 45 52 3b 0a 20 20 20 20 20 20 20 tkOTHER;.
5450: 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 20 }.
5460: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 break;.
5470: 20 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 }.
5480: 20 20 20 20 20 20 20 20 63 61 73 65 20 27 65 27 case 'e'
5490: 3a 20 20 63 61 73 65 20 27 45 27 3a 20 7b 0a 20 : case 'E': {.
54a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 28 if(
54b0: 20 6e 49 64 3d 3d 33 20 26 26 20 73 71 6c 69 74 nId==3 && sqlit
54c0: 65 53 74 72 4e 49 43 6d 70 28 7a 53 71 6c 2c 20 eStrNICmp(zSql,
54d0: 22 65 6e 64 22 2c 20 33 29 3d 3d 30 20 29 7b 0a "end", 3)==0 ){.
54e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
54f0: 74 6f 6b 65 6e 20 3d 20 74 6b 45 4e 44 3b 0a 20 token = tkEND;.
5500: 20 20 20 20 20 20 20 20 20 20 20 20 20 7d 65 6c }el
5510: 73 65 20 69 66 28 20 6e 49 64 3d 3d 37 20 26 26 se if( nId==7 &&
5520: 20 73 71 6c 69 74 65 53 74 72 4e 49 43 6d 70 28 sqliteStrNICmp(
5530: 7a 53 71 6c 2c 20 22 65 78 70 6c 61 69 6e 22 2c zSql, "explain",
5540: 20 37 29 3d 3d 30 20 29 7b 0a 20 20 20 20 20 20 7)==0 ){.
5550: 20 20 20 20 20 20 20 20 20 20 74 6f 6b 65 6e 20 token
5560: 3d 20 74 6b 45 58 50 4c 41 49 4e 3b 0a 20 20 20 = tkEXPLAIN;.
5570: 20 20 20 20 20 20 20 20 20 20 20 7d 65 6c 73 65 }else
5580: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
5590: 20 20 74 6f 6b 65 6e 20 3d 20 74 6b 4f 54 48 45 token = tkOTHE
55a0: 52 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 R;.
55b0: 20 7d 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 }.
55c0: 20 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 break;.
55d0: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 20 20 }.
55e0: 20 20 64 65 66 61 75 6c 74 3a 20 7b 0a 20 20 20 default: {.
55f0: 20 20 20 20 20 20 20 20 20 20 20 74 6f 6b 65 6e token
5600: 20 3d 20 74 6b 4f 54 48 45 52 3b 0a 20 20 20 20 = tkOTHER;.
5610: 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b break;
5620: 0a 20 20 20 20 20 20 20 20 20 20 20 20 7d 0a 20 . }.
5630: 20 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 20 }.
5640: 20 20 20 20 20 7a 53 71 6c 20 2b 3d 20 6e 49 64 zSql += nId
5650: 2d 31 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 -1;. }els
5660: 65 7b 0a 20 20 20 20 20 20 20 20 20 20 2f 2a 20 e{. /*
5670: 4f 70 65 72 61 74 6f 72 73 20 61 6e 64 20 73 70 Operators and sp
5680: 65 63 69 61 6c 20 73 79 6d 62 6f 6c 73 20 2a 2f ecial symbols */
5690: 0a 20 20 20 20 20 20 20 20 20 20 74 6f 6b 65 6e . token
56a0: 20 3d 20 74 6b 4f 54 48 45 52 3b 0a 20 20 20 20 = tkOTHER;.
56b0: 20 20 20 20 7d 0a 20 20 20 20 20 20 20 20 62 72 }. br
56c0: 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 eak;. }.
56d0: 20 7d 0a 20 20 20 20 73 74 61 74 65 20 3d 20 74 }. state = t
56e0: 72 61 6e 73 5b 73 74 61 74 65 5d 5b 74 6f 6b 65 rans[state][toke
56f0: 6e 5d 3b 0a 20 20 20 20 7a 53 71 6c 2b 2b 3b 0a n];. zSql++;.
5700: 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 73 74 61 }. return sta
5710: 74 65 3d 3d 30 3b 0a 7d 0a te==0;.}.