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 34 33 20 32 enize.c,v 1.43 2
0250: 30 30 32 2f 30 35 2f 32 34 20 31 36 3a 31 34 3a 002/05/24 16:14:
0260: 31 35 20 64 72 68 20 45 78 70 20 24 0a 2a 2f 0a 15 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 69 6e 74 20 6c 65 6e 3b 20 20 20 */. int 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 69 6e 74 20 74 6f word */. int 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 42 45 46 4f 52 0 },. { "BEFOR
0600: 45 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 E", 0
0610: 2c 20 54 4b 5f 42 45 46 4f 52 45 2c 20 20 20 20 , TK_BEFORE,
0620: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0630: 22 42 45 47 49 4e 22 2c 20 20 20 20 20 20 20 20 "BEGIN",
0640: 20 20 20 20 20 30 2c 20 54 4b 5f 42 45 47 49 4e 0, TK_BEGIN
0650: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d , 0 }
0660: 2c 0a 20 20 7b 20 22 42 45 54 57 45 45 4e 22 2c ,. { "BETWEEN",
0670: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0680: 5f 42 45 54 57 45 45 4e 2c 20 20 20 20 20 20 20 _BETWEEN,
0690: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 42 59 22 0 },. { "BY"
06a0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ,
06b0: 20 30 2c 20 54 4b 5f 42 59 2c 20 20 20 20 20 20 0, TK_BY,
06c0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
06d0: 7b 20 22 43 41 53 45 22 2c 20 20 20 20 20 20 20 { "CASE",
06e0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 43 41 53 0, TK_CAS
06f0: 45 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 E, 0
0700: 20 7d 2c 0a 20 20 7b 20 22 43 48 45 43 4b 22 2c },. { "CHECK",
0710: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
0720: 54 4b 5f 43 48 45 43 4b 2c 20 20 20 20 20 20 20 TK_CHECK,
0730: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 43 0 },. { "C
0740: 4c 55 53 54 45 52 22 2c 20 20 20 20 20 20 20 20 LUSTER",
0750: 20 20 20 30 2c 20 54 4b 5f 43 4c 55 53 54 45 52 0, TK_CLUSTER
0760: 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a , 0 },.
0770: 20 20 7b 20 22 43 4f 4d 4d 49 54 22 2c 20 20 20 { "COMMIT",
0780: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 43 0, TK_C
0790: 4f 4d 4d 49 54 2c 20 20 20 20 20 20 20 20 20 20 OMMIT,
07a0: 20 30 20 7d 2c 0a 20 20 7b 20 22 43 4f 4e 46 4c 0 },. { "CONFL
07b0: 49 43 54 22 2c 20 20 20 20 20 20 20 20 20 20 30 ICT", 0
07c0: 2c 20 54 4b 5f 43 4f 4e 46 4c 49 43 54 2c 20 20 , TK_CONFLICT,
07d0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
07e0: 22 43 4f 4e 53 54 52 41 49 4e 54 22 2c 20 20 20 "CONSTRAINT",
07f0: 20 20 20 20 20 30 2c 20 54 4b 5f 43 4f 4e 53 54 0, TK_CONST
0800: 52 41 49 4e 54 2c 20 20 20 20 20 20 20 30 20 7d RAINT, 0 }
0810: 2c 0a 20 20 7b 20 22 43 4f 50 59 22 2c 20 20 20 ,. { "COPY",
0820: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0830: 5f 43 4f 50 59 2c 20 20 20 20 20 20 20 20 20 20 _COPY,
0840: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 43 52 45 0 },. { "CRE
0850: 41 54 45 22 2c 20 20 20 20 20 20 20 20 20 20 20 ATE",
0860: 20 30 2c 20 54 4b 5f 43 52 45 41 54 45 2c 20 20 0, TK_CREATE,
0870: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0880: 7b 20 22 44 45 46 41 55 4c 54 22 2c 20 20 20 20 { "DEFAULT",
0890: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 44 45 46 0, TK_DEF
08a0: 41 55 4c 54 2c 20 20 20 20 20 20 20 20 20 20 30 AULT, 0
08b0: 20 7d 2c 0a 20 20 7b 20 22 44 45 4c 45 54 45 22 },. { "DELETE"
08c0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
08d0: 54 4b 5f 44 45 4c 45 54 45 2c 20 20 20 20 20 20 TK_DELETE,
08e0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 44 0 },. { "D
08f0: 45 4c 49 4d 49 54 45 52 53 22 2c 20 20 20 20 20 ELIMITERS",
0900: 20 20 20 30 2c 20 54 4b 5f 44 45 4c 49 4d 49 54 0, TK_DELIMIT
0910: 45 52 53 2c 20 20 20 20 20 20 20 30 20 7d 2c 0a ERS, 0 },.
0920: 20 20 7b 20 22 44 45 53 43 22 2c 20 20 20 20 20 { "DESC",
0930: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 44 0, TK_D
0940: 45 53 43 2c 20 20 20 20 20 20 20 20 20 20 20 20 ESC,
0950: 20 30 20 7d 2c 0a 20 20 7b 20 22 44 49 53 54 49 0 },. { "DISTI
0960: 4e 43 54 22 2c 20 20 20 20 20 20 20 20 20 20 30 NCT", 0
0970: 2c 20 54 4b 5f 44 49 53 54 49 4e 43 54 2c 20 20 , TK_DISTINCT,
0980: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0990: 22 44 52 4f 50 22 2c 20 20 20 20 20 20 20 20 20 "DROP",
09a0: 20 20 20 20 20 30 2c 20 54 4b 5f 44 52 4f 50 2c 0, TK_DROP,
09b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 0 }
09c0: 2c 0a 20 20 7b 20 22 45 4e 44 22 2c 20 20 20 20 ,. { "END",
09d0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
09e0: 5f 45 4e 44 2c 20 20 20 20 20 20 20 20 20 20 20 _END,
09f0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 45 41 43 0 },. { "EAC
0a00: 48 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 H",
0a10: 20 30 2c 20 54 4b 5f 45 41 43 48 2c 20 20 20 20 0, TK_EACH,
0a20: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0a30: 7b 20 22 45 4c 53 45 22 2c 20 20 20 20 20 20 20 { "ELSE",
0a40: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 45 4c 53 0, TK_ELS
0a50: 45 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 E, 0
0a60: 20 7d 2c 0a 20 20 7b 20 22 45 58 43 45 50 54 22 },. { "EXCEPT"
0a70: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
0a80: 54 4b 5f 45 58 43 45 50 54 2c 20 20 20 20 20 20 TK_EXCEPT,
0a90: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 45 0 },. { "E
0aa0: 58 50 4c 41 49 4e 22 2c 20 20 20 20 20 20 20 20 XPLAIN",
0ab0: 20 20 20 30 2c 20 54 4b 5f 45 58 50 4c 41 49 4e 0, TK_EXPLAIN
0ac0: 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a , 0 },.
0ad0: 20 20 7b 20 22 46 41 49 4c 22 2c 20 20 20 20 20 { "FAIL",
0ae0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 46 0, TK_F
0af0: 41 49 4c 2c 20 20 20 20 20 20 20 20 20 20 20 20 AIL,
0b00: 20 30 20 7d 2c 0a 20 20 7b 20 22 46 4f 52 22 2c 0 },. { "FOR",
0b10: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
0b20: 2c 20 54 4b 5f 46 4f 52 2c 20 20 20 20 20 20 20 , TK_FOR,
0b30: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0b40: 22 46 52 4f 4d 22 2c 20 20 20 20 20 20 20 20 20 "FROM",
0b50: 20 20 20 20 20 30 2c 20 54 4b 5f 46 52 4f 4d 2c 0, TK_FROM,
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 47 4c 4f 42 22 2c 20 20 20 ,. { "GLOB",
0b80: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0b90: 5f 47 4c 4f 42 2c 20 20 20 20 20 20 20 20 20 20 _GLOB,
0ba0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 47 52 4f 0 },. { "GRO
0bb0: 55 50 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 UP",
0bc0: 20 30 2c 20 54 4b 5f 47 52 4f 55 50 2c 20 20 20 0, TK_GROUP,
0bd0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0be0: 7b 20 22 48 41 56 49 4e 47 22 2c 20 20 20 20 20 { "HAVING",
0bf0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 48 41 56 0, TK_HAV
0c00: 49 4e 47 2c 20 20 20 20 20 20 20 20 20 20 20 30 ING, 0
0c10: 20 7d 2c 0a 20 20 7b 20 22 49 47 4e 4f 52 45 22 },. { "IGNORE"
0c20: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
0c30: 54 4b 5f 49 47 4e 4f 52 45 2c 20 20 20 20 20 20 TK_IGNORE,
0c40: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 49 0 },. { "I
0c50: 4e 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 N",
0c60: 20 20 20 30 2c 20 54 4b 5f 49 4e 2c 20 20 20 20 0, TK_IN,
0c70: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0c80: 20 20 7b 20 22 49 4e 44 45 58 22 2c 20 20 20 20 { "INDEX",
0c90: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 49 0, TK_I
0ca0: 4e 44 45 58 2c 20 20 20 20 20 20 20 20 20 20 20 NDEX,
0cb0: 20 30 20 7d 2c 0a 20 20 7b 20 22 49 4e 53 45 52 0 },. { "INSER
0cc0: 54 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 T", 0
0cd0: 2c 20 54 4b 5f 49 4e 53 45 52 54 2c 20 20 20 20 , TK_INSERT,
0ce0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0cf0: 22 49 4e 53 54 45 41 44 22 2c 20 20 20 20 20 20 "INSTEAD",
0d00: 20 20 20 20 20 30 2c 20 54 4b 5f 49 4e 53 54 45 0, TK_INSTE
0d10: 41 44 2c 20 20 20 20 20 20 20 20 20 20 30 20 7d AD, 0 }
0d20: 2c 0a 20 20 7b 20 22 49 4e 54 45 52 53 45 43 54 ,. { "INTERSECT
0d30: 22 2c 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b ", 0, TK
0d40: 5f 49 4e 54 45 52 53 45 43 54 2c 20 20 20 20 20 _INTERSECT,
0d50: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 49 4e 54 0 },. { "INT
0d60: 4f 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 O",
0d70: 20 30 2c 20 54 4b 5f 49 4e 54 4f 2c 20 20 20 20 0, TK_INTO,
0d80: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0d90: 7b 20 22 49 53 22 2c 20 20 20 20 20 20 20 20 20 { "IS",
0da0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 49 53 2c 0, TK_IS,
0db0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
0dc0: 20 7d 2c 0a 20 20 7b 20 22 49 53 4e 55 4c 4c 22 },. { "ISNULL"
0dd0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
0de0: 54 4b 5f 49 53 4e 55 4c 4c 2c 20 20 20 20 20 20 TK_ISNULL,
0df0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4a 0 },. { "J
0e00: 4f 49 4e 22 2c 20 20 20 20 20 20 20 20 20 20 20 OIN",
0e10: 20 20 20 30 2c 20 54 4b 5f 4a 4f 49 4e 2c 20 20 0, TK_JOIN,
0e20: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0e30: 20 20 7b 20 22 4b 45 59 22 2c 20 20 20 20 20 20 { "KEY",
0e40: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4b 0, TK_K
0e50: 45 59 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 EY,
0e60: 20 30 20 7d 2c 0a 20 20 7b 20 22 4c 49 4b 45 22 0 },. { "LIKE"
0e70: 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 , 0
0e80: 2c 20 54 4b 5f 4c 49 4b 45 2c 20 20 20 20 20 20 , TK_LIKE,
0e90: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
0ea0: 22 4c 49 4d 49 54 22 2c 20 20 20 20 20 20 20 20 "LIMIT",
0eb0: 20 20 20 20 20 30 2c 20 54 4b 5f 4c 49 4d 49 54 0, TK_LIMIT
0ec0: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d , 0 }
0ed0: 2c 0a 20 20 7b 20 22 4e 4f 54 22 2c 20 20 20 20 ,. { "NOT",
0ee0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
0ef0: 5f 4e 4f 54 2c 20 20 20 20 20 20 20 20 20 20 20 _NOT,
0f00: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4e 4f 54 0 },. { "NOT
0f10: 4e 55 4c 4c 22 2c 20 20 20 20 20 20 20 20 20 20 NULL",
0f20: 20 30 2c 20 54 4b 5f 4e 4f 54 4e 55 4c 4c 2c 20 0, TK_NOTNULL,
0f30: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
0f40: 7b 20 22 4e 55 4c 4c 22 2c 20 20 20 20 20 20 20 { "NULL",
0f50: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4e 55 4c 0, TK_NUL
0f60: 4c 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 L, 0
0f70: 20 7d 2c 0a 20 20 7b 20 22 4f 46 22 2c 20 20 20 },. { "OF",
0f80: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
0f90: 54 4b 5f 4f 46 2c 20 20 20 20 20 20 20 20 20 20 TK_OF,
0fa0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 4f 0 },. { "O
0fb0: 46 46 53 45 54 22 2c 20 20 20 20 20 20 20 20 20 FFSET",
0fc0: 20 20 20 30 2c 20 54 4b 5f 4f 46 46 53 45 54 2c 0, TK_OFFSET,
0fd0: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
0fe0: 20 20 7b 20 22 4f 4e 22 2c 20 20 20 20 20 20 20 { "ON",
0ff0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 4f 0, TK_O
1000: 4e 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 20 N,
1010: 20 30 20 7d 2c 0a 20 20 7b 20 22 4f 52 22 2c 20 0 },. { "OR",
1020: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
1030: 2c 20 54 4b 5f 4f 52 2c 20 20 20 20 20 20 20 20 , TK_OR,
1040: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1050: 22 4f 52 44 45 52 22 2c 20 20 20 20 20 20 20 20 "ORDER",
1060: 20 20 20 20 20 30 2c 20 54 4b 5f 4f 52 44 45 52 0, TK_ORDER
1070: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 20 7d , 0 }
1080: 2c 0a 20 20 7b 20 22 50 52 41 47 4d 41 22 2c 20 ,. { "PRAGMA",
1090: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
10a0: 5f 50 52 41 47 4d 41 2c 20 20 20 20 20 20 20 20 _PRAGMA,
10b0: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 50 52 49 0 },. { "PRI
10c0: 4d 41 52 59 22 2c 20 20 20 20 20 20 20 20 20 20 MARY",
10d0: 20 30 2c 20 54 4b 5f 50 52 49 4d 41 52 59 2c 20 0, TK_PRIMARY,
10e0: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
10f0: 7b 20 22 52 45 50 4c 41 43 45 22 2c 20 20 20 20 { "REPLACE",
1100: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 52 45 50 0, TK_REP
1110: 4c 41 43 45 2c 20 20 20 20 20 20 20 20 20 20 30 LACE, 0
1120: 20 7d 2c 0a 20 20 7b 20 22 52 4f 4c 4c 42 41 43 },. { "ROLLBAC
1130: 4b 22 2c 20 20 20 20 20 20 20 20 20 20 30 2c 20 K", 0,
1140: 54 4b 5f 52 4f 4c 4c 42 41 43 4b 2c 20 20 20 20 TK_ROLLBACK,
1150: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 52 0 },. { "R
1160: 4f 57 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 OW",
1170: 20 20 20 30 2c 20 54 4b 5f 52 4f 57 2c 20 20 20 0, TK_ROW,
1180: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
1190: 20 20 7b 20 22 53 45 4c 45 43 54 22 2c 20 20 20 { "SELECT",
11a0: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 53 0, TK_S
11b0: 45 4c 45 43 54 2c 20 20 20 20 20 20 20 20 20 20 ELECT,
11c0: 20 30 20 7d 2c 0a 20 20 7b 20 22 53 45 54 22 2c 0 },. { "SET",
11d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 30 0
11e0: 2c 20 54 4b 5f 53 45 54 2c 20 20 20 20 20 20 20 , TK_SET,
11f0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
1200: 22 53 54 41 54 45 4d 45 4e 54 22 2c 20 20 20 20 "STATEMENT",
1210: 20 20 20 20 20 30 2c 20 54 4b 5f 53 54 41 54 45 0, TK_STATE
1220: 4d 45 4e 54 2c 20 20 20 20 20 20 20 20 30 20 7d MENT, 0 }
1230: 2c 0a 20 20 7b 20 22 54 41 42 4c 45 22 2c 20 20 ,. { "TABLE",
1240: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1250: 5f 54 41 42 4c 45 2c 20 20 20 20 20 20 20 20 20 _TABLE,
1260: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 54 45 4d 0 },. { "TEM
1270: 50 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 P",
1280: 20 30 2c 20 54 4b 5f 54 45 4d 50 2c 20 20 20 20 0, TK_TEMP,
1290: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
12a0: 7b 20 22 54 45 4d 50 4f 52 41 52 59 22 2c 20 20 { "TEMPORARY",
12b0: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 54 45 4d 0, TK_TEM
12c0: 50 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 P, 0
12d0: 20 7d 2c 0a 20 20 7b 20 22 54 48 45 4e 22 2c 20 },. { "THEN",
12e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 0,
12f0: 54 4b 5f 54 48 45 4e 2c 20 20 20 20 20 20 20 20 TK_THEN,
1300: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 54 0 },. { "T
1310: 52 41 4e 53 41 43 54 49 4f 4e 22 2c 20 20 20 20 RANSACTION",
1320: 20 20 20 30 2c 20 54 4b 5f 54 52 41 4e 53 41 43 0, TK_TRANSAC
1330: 54 49 4f 4e 2c 20 20 20 20 20 20 30 20 7d 2c 0a TION, 0 },.
1340: 20 20 7b 20 22 54 52 49 47 47 45 52 22 2c 20 20 { "TRIGGER",
1350: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 54 0, TK_T
1360: 52 49 47 47 45 52 2c 20 20 20 20 20 20 20 20 20 RIGGER,
1370: 20 30 20 7d 2c 0a 20 20 7b 20 22 55 4e 49 4f 4e 0 },. { "UNION
1380: 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 ", 0
1390: 2c 20 54 4b 5f 55 4e 49 4f 4e 2c 20 20 20 20 20 , TK_UNION,
13a0: 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 0 },. {
13b0: 22 55 4e 49 51 55 45 22 2c 20 20 20 20 20 20 20 "UNIQUE",
13c0: 20 20 20 20 20 30 2c 20 54 4b 5f 55 4e 49 51 55 0, TK_UNIQU
13d0: 45 2c 20 20 20 20 20 20 20 20 20 20 20 30 20 7d E, 0 }
13e0: 2c 0a 20 20 7b 20 22 55 50 44 41 54 45 22 2c 20 ,. { "UPDATE",
13f0: 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 0, TK
1400: 5f 55 50 44 41 54 45 2c 20 20 20 20 20 20 20 20 _UPDATE,
1410: 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 55 53 49 0 },. { "USI
1420: 4e 47 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 NG",
1430: 20 30 2c 20 54 4b 5f 55 53 49 4e 47 2c 20 20 20 0, TK_USING,
1440: 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 20 20 0 },.
1450: 7b 20 22 56 41 43 55 55 4d 22 2c 20 20 20 20 20 { "VACUUM",
1460: 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 56 41 43 0, TK_VAC
1470: 55 55 4d 2c 20 20 20 20 20 20 20 20 20 20 20 30 UUM, 0
1480: 20 7d 2c 0a 20 20 7b 20 22 56 41 4c 55 45 53 22 },. { "VALUES"
1490: 2c 20 20 20 20 20 20 20 20 20 20 20 20 30 2c 20 , 0,
14a0: 54 4b 5f 56 41 4c 55 45 53 2c 20 20 20 20 20 20 TK_VALUES,
14b0: 20 20 20 20 20 30 20 7d 2c 0a 20 20 7b 20 22 56 0 },. { "V
14c0: 49 45 57 22 2c 20 20 20 20 20 20 20 20 20 20 20 IEW",
14d0: 20 20 20 30 2c 20 54 4b 5f 56 49 45 57 2c 20 20 0, TK_VIEW,
14e0: 20 20 20 20 20 20 20 20 20 20 20 30 20 7d 2c 0a 0 },.
14f0: 20 20 7b 20 22 57 48 45 4e 22 2c 20 20 20 20 20 { "WHEN",
1500: 20 20 20 20 20 20 20 20 20 30 2c 20 54 4b 5f 57 0, TK_W
1510: 48 45 4e 2c 20 20 20 20 20 20 20 20 20 20 20 20 HEN,
1520: 20 30 20 7d 2c 0a 20 20 7b 20 22 57 48 45 52 45 0 },. { "WHERE
1530: 22 2c 20 20 20 20 20 20 20 20 20 20 20 20 20 30 ", 0
1540: 2c 20 54 4b 5f 57 48 45 52 45 2c 20 20 20 20 20 , TK_WHERE,
1550: 20 20 20 20 20 20 20 30 20 7d 2c 0a 7d 3b 0a 0a 0 },.};..
1560: 2f 2a 0a 2a 2a 20 54 68 69 73 20 69 73 20 74 68 /*.** This is th
1570: 65 20 68 61 73 68 20 74 61 62 6c 65 0a 2a 2f 0a e hash table.*/.
1580: 23 64 65 66 69 6e 65 20 4b 45 59 5f 48 41 53 48 #define KEY_HASH
1590: 5f 53 49 5a 45 20 37 31 0a 73 74 61 74 69 63 20 _SIZE 71.static
15a0: 4b 65 79 77 6f 72 64 20 2a 61 70 48 61 73 68 54 Keyword *apHashT
15b0: 61 62 6c 65 5b 4b 45 59 5f 48 41 53 48 5f 53 49 able[KEY_HASH_SI
15c0: 5a 45 5d 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 54 68 69 ZE];.../*.** Thi
15d0: 73 20 66 75 6e 63 74 69 6f 6e 20 6c 6f 6f 6b 73 s function looks
15e0: 20 75 70 20 61 6e 20 69 64 65 6e 74 69 66 69 65 up an identifie
15f0: 72 20 74 6f 20 64 65 74 65 72 6d 69 6e 65 20 69 r to determine i
1600: 66 20 69 74 20 69 73 20 61 0a 2a 2a 20 6b 65 79 f it is a.** key
1610: 77 6f 72 64 2e 20 20 49 66 20 69 74 20 69 73 20 word. If it is
1620: 61 20 6b 65 79 77 6f 72 64 2c 20 74 68 65 20 74 a keyword, the t
1630: 6f 6b 65 6e 20 63 6f 64 65 20 6f 66 20 74 68 61 oken code of tha
1640: 74 20 6b 65 79 77 6f 72 64 20 69 73 20 0a 2a 2a t keyword is .**
1650: 20 72 65 74 75 72 6e 65 64 2e 20 20 49 66 20 74 returned. If t
1660: 68 65 20 69 6e 70 75 74 20 69 73 20 6e 6f 74 20 he input is not
1670: 61 20 6b 65 79 77 6f 72 64 2c 20 54 4b 5f 49 44 a keyword, TK_ID
1680: 20 69 73 20 72 65 74 75 72 6e 65 64 2e 0a 2a 2f is returned..*/
1690: 0a 69 6e 74 20 73 71 6c 69 74 65 4b 65 79 77 6f .int sqliteKeywo
16a0: 72 64 43 6f 64 65 28 63 6f 6e 73 74 20 63 68 61 rdCode(const cha
16b0: 72 20 2a 7a 2c 20 69 6e 74 20 6e 29 7b 0a 20 20 r *z, int n){.
16c0: 69 6e 74 20 68 3b 0a 20 20 4b 65 79 77 6f 72 64 int h;. Keyword
16d0: 20 2a 70 3b 0a 20 20 69 66 28 20 61 4b 65 79 77 *p;. if( aKeyw
16e0: 6f 72 64 54 61 62 6c 65 5b 30 5d 2e 6c 65 6e 3d ordTable[0].len=
16f0: 3d 30 20 29 7b 0a 20 20 20 20 2f 2a 20 49 6e 69 =0 ){. /* Ini
1700: 74 69 61 6c 69 7a 65 20 74 68 65 20 6b 65 79 77 tialize the keyw
1710: 6f 72 64 20 68 61 73 68 20 74 61 62 6c 65 20 2a ord hash table *
1720: 2f 0a 20 20 20 20 73 71 6c 69 74 65 4f 73 45 6e /. sqliteOsEn
1730: 74 65 72 4d 75 74 65 78 28 29 3b 0a 20 20 20 20 terMutex();.
1740: 69 66 28 20 61 4b 65 79 77 6f 72 64 54 61 62 6c if( aKeywordTabl
1750: 65 5b 30 5d 2e 6c 65 6e 3d 3d 30 20 29 7b 0a 20 e[0].len==0 ){.
1760: 20 20 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 20 int i;.
1770: 20 20 69 6e 74 20 6e 3b 0a 20 20 20 20 20 20 6e int n;. n
1780: 20 3d 20 73 69 7a 65 6f 66 28 61 4b 65 79 77 6f = sizeof(aKeywo
1790: 72 64 54 61 62 6c 65 29 2f 73 69 7a 65 6f 66 28 rdTable)/sizeof(
17a0: 61 4b 65 79 77 6f 72 64 54 61 62 6c 65 5b 30 5d aKeywordTable[0]
17b0: 29 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 30 );. for(i=0
17c0: 3b 20 69 3c 6e 3b 20 69 2b 2b 29 7b 0a 20 20 20 ; i<n; i++){.
17d0: 20 20 20 20 20 61 4b 65 79 77 6f 72 64 54 61 62 aKeywordTab
17e0: 6c 65 5b 69 5d 2e 6c 65 6e 20 3d 20 73 74 72 6c le[i].len = strl
17f0: 65 6e 28 61 4b 65 79 77 6f 72 64 54 61 62 6c 65 en(aKeywordTable
1800: 5b 69 5d 2e 7a 4e 61 6d 65 29 3b 0a 20 20 20 20 [i].zName);.
1810: 20 20 20 20 68 20 3d 20 73 71 6c 69 74 65 48 61 h = sqliteHa
1820: 73 68 4e 6f 43 61 73 65 28 61 4b 65 79 77 6f 72 shNoCase(aKeywor
1830: 64 54 61 62 6c 65 5b 69 5d 2e 7a 4e 61 6d 65 2c dTable[i].zName,
1840: 20 61 4b 65 79 77 6f 72 64 54 61 62 6c 65 5b 69 aKeywordTable[i
1850: 5d 2e 6c 65 6e 29 3b 0a 20 20 20 20 20 20 20 20 ].len);.
1860: 68 20 25 3d 20 4b 45 59 5f 48 41 53 48 5f 53 49 h %= KEY_HASH_SI
1870: 5a 45 3b 0a 20 20 20 20 20 20 20 20 61 4b 65 79 ZE;. aKey
1880: 77 6f 72 64 54 61 62 6c 65 5b 69 5d 2e 70 4e 65 wordTable[i].pNe
1890: 78 74 20 3d 20 61 70 48 61 73 68 54 61 62 6c 65 xt = apHashTable
18a0: 5b 68 5d 3b 0a 20 20 20 20 20 20 20 20 61 70 48 [h];. apH
18b0: 61 73 68 54 61 62 6c 65 5b 68 5d 20 3d 20 26 61 ashTable[h] = &a
18c0: 4b 65 79 77 6f 72 64 54 61 62 6c 65 5b 69 5d 3b KeywordTable[i];
18d0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 . }. }.
18e0: 20 20 20 73 71 6c 69 74 65 4f 73 4c 65 61 76 65 sqliteOsLeave
18f0: 4d 75 74 65 78 28 29 3b 0a 20 20 7d 0a 20 20 68 Mutex();. }. h
1900: 20 3d 20 73 71 6c 69 74 65 48 61 73 68 4e 6f 43 = sqliteHashNoC
1910: 61 73 65 28 7a 2c 20 6e 29 20 25 20 4b 45 59 5f ase(z, n) % KEY_
1920: 48 41 53 48 5f 53 49 5a 45 3b 0a 20 20 66 6f 72 HASH_SIZE;. for
1930: 28 70 3d 61 70 48 61 73 68 54 61 62 6c 65 5b 68 (p=apHashTable[h
1940: 5d 3b 20 70 3b 20 70 3d 70 2d 3e 70 4e 65 78 74 ]; p; p=p->pNext
1950: 29 7b 0a 20 20 20 20 69 66 28 20 70 2d 3e 6c 65 ){. if( p->le
1960: 6e 3d 3d 6e 20 26 26 20 73 71 6c 69 74 65 53 74 n==n && sqliteSt
1970: 72 4e 49 43 6d 70 28 70 2d 3e 7a 4e 61 6d 65 2c rNICmp(p->zName,
1980: 20 7a 2c 20 6e 29 3d 3d 30 20 29 7b 0a 20 20 20 z, n)==0 ){.
1990: 20 20 20 72 65 74 75 72 6e 20 70 2d 3e 74 6f 6b return p->tok
19a0: 65 6e 54 79 70 65 3b 0a 20 20 20 20 7d 0a 20 20 enType;. }.
19b0: 7d 0a 20 20 72 65 74 75 72 6e 20 54 4b 5f 49 44 }. return TK_ID
19c0: 3b 0a 7d 0a 0a 0a 2f 2a 0a 2a 2a 20 49 66 20 58 ;.}.../*.** If X
19d0: 20 69 73 20 61 20 63 68 61 72 61 63 74 65 72 20 is a character
19e0: 74 68 61 74 20 63 61 6e 20 62 65 20 75 73 65 64 that can be used
19f0: 20 69 6e 20 61 6e 20 69 64 65 6e 74 69 66 69 65 in an identifie
1a00: 72 20 74 68 65 6e 0a 2a 2a 20 69 73 49 64 43 68 r then.** isIdCh
1a10: 61 72 5b 58 5d 20 77 69 6c 6c 20 62 65 20 31 2e ar[X] will be 1.
1a20: 20 20 4f 74 68 65 72 77 69 73 65 20 69 73 49 64 Otherwise isId
1a30: 43 68 61 72 5b 58 5d 20 77 69 6c 6c 20 62 65 20 Char[X] will be
1a40: 30 2e 0a 2a 2a 0a 2a 2a 20 49 6e 20 74 68 69 73 0..**.** In this
1a50: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2c implementation,
1a60: 20 61 6e 20 69 64 65 6e 74 69 66 69 65 72 20 63 an identifier c
1a70: 61 6e 20 62 65 20 61 20 73 74 72 69 6e 67 20 6f an be a string o
1a80: 66 0a 2a 2a 20 61 6c 70 68 61 62 65 74 69 63 20 f.** alphabetic
1a90: 63 68 61 72 61 63 74 65 72 73 2c 20 64 69 67 69 characters, digi
1aa0: 74 73 2c 20 61 6e 64 20 22 5f 22 20 70 6c 75 73 ts, and "_" plus
1ab0: 20 61 6e 79 20 63 68 61 72 61 63 74 65 72 0a 2a any character.*
1ac0: 2a 20 77 69 74 68 20 74 68 65 20 68 69 67 68 2d * with the high-
1ad0: 6f 72 64 65 72 20 62 69 74 20 73 65 74 2e 20 20 order bit set.
1ae0: 54 68 65 20 6c 61 74 74 65 72 20 72 75 6c 65 20 The latter rule
1af0: 6d 65 61 6e 73 20 74 68 61 74 0a 2a 2a 20 61 6e means that.** an
1b00: 79 20 73 65 71 75 65 6e 63 65 20 6f 66 20 55 54 y sequence of UT
1b10: 46 2d 38 20 63 68 61 72 61 63 74 65 72 73 20 6f F-8 characters o
1b20: 72 20 63 68 61 72 61 63 74 65 72 73 20 74 61 6b r characters tak
1b30: 65 6e 20 66 72 6f 6d 0a 2a 2a 20 61 6e 20 65 78 en from.** an ex
1b40: 74 65 6e 64 65 64 20 49 53 4f 38 38 35 39 20 63 tended ISO8859 c
1b50: 68 61 72 61 63 74 65 72 20 73 65 74 20 63 61 6e haracter set can
1b60: 20 66 6f 72 6d 20 61 6e 20 69 64 65 6e 74 69 66 form an identif
1b70: 69 65 72 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 63 ier..*/.static c
1b80: 6f 6e 73 74 20 63 68 61 72 20 69 73 49 64 43 68 onst char isIdCh
1b90: 61 72 5b 5d 20 3d 20 7b 0a 2f 2a 20 78 30 20 78 ar[] = {./* x0 x
1ba0: 31 20 78 32 20 78 33 20 78 34 20 78 35 20 78 36 1 x2 x3 x4 x5 x6
1bb0: 20 78 37 20 78 38 20 78 39 20 78 41 20 78 42 20 x7 x8 x9 xA xB
1bc0: 78 43 20 78 44 20 78 45 20 78 46 20 2a 2f 0a 20 xC xD xE xF */.
1bd0: 20 20 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 0, 0, 0, 0, 0
1be0: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
1bf0: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
1c00: 30 2c 20 20 2f 2a 20 30 78 20 2a 2f 0a 20 20 20 0, /* 0x */.
1c10: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
1c20: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 0, 0, 0, 0, 0, 0
1c30: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
1c40: 20 20 2f 2a 20 31 78 20 2a 2f 0a 20 20 20 20 30 /* 1x */. 0
1c50: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
1c60: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 0, 0, 0, 0,
1c70: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 20 0, 0, 0, 0, 0,
1c80: 2f 2a 20 32 78 20 2a 2f 0a 20 20 20 20 31 2c 20 /* 2x */. 1,
1c90: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1ca0: 2c 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c , 1, 1, 1, 0, 0,
1cb0: 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 20 2f 2a 0, 0, 0, 0, /*
1cc0: 20 33 78 20 2a 2f 0a 20 20 20 20 30 2c 20 31 2c 3x */. 0, 1,
1cd0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1ce0: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1cf0: 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 34 , 1, 1, 1, /* 4
1d00: 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 x */. 1, 1, 1
1d10: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1d20: 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c 20 1, 1, 1, 0, 0,
1d30: 30 2c 20 30 2c 20 31 2c 20 20 2f 2a 20 35 78 20 0, 0, 1, /* 5x
1d40: 2a 2f 0a 20 20 20 20 30 2c 20 31 2c 20 31 2c 20 */. 0, 1, 1,
1d50: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1d60: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1d70: 20 31 2c 20 31 2c 20 20 2f 2a 20 36 78 20 2a 2f 1, 1, /* 6x */
1d80: 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c . 1, 1, 1, 1,
1d90: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1da0: 31 2c 20 31 2c 20 30 2c 20 30 2c 20 30 2c 20 30 1, 1, 0, 0, 0, 0
1db0: 2c 20 30 2c 20 20 2f 2a 20 37 78 20 2a 2f 0a 20 , 0, /* 7x */.
1dc0: 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1
1dd0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1de0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1df0: 31 2c 20 20 2f 2a 20 38 78 20 2a 2f 0a 20 20 20 1, /* 8x */.
1e00: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1e10: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1e20: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1e30: 20 20 2f 2a 20 39 78 20 2a 2f 0a 20 20 20 20 31 /* 9x */. 1
1e40: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1e50: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1e60: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 20 1, 1, 1, 1, 1,
1e70: 2f 2a 20 41 78 20 2a 2f 0a 20 20 20 20 31 2c 20 /* Ax */. 1,
1e80: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1e90: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1ea0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 1, 1, 1, 1, /*
1eb0: 20 42 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c Bx */. 1, 1,
1ec0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1ed0: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1ee0: 2c 20 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 43 , 1, 1, 1, /* C
1ef0: 78 20 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 x */. 1, 1, 1
1f00: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1f10: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1f20: 31 2c 20 31 2c 20 31 2c 20 20 2f 2a 20 44 78 20 1, 1, 1, /* Dx
1f30: 2a 2f 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 */. 1, 1, 1,
1f40: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1f50: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1f60: 20 31 2c 20 31 2c 20 20 2f 2a 20 45 78 20 2a 2f 1, 1, /* Ex */
1f70: 0a 20 20 20 20 31 2c 20 31 2c 20 31 2c 20 31 2c . 1, 1, 1, 1,
1f80: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1f90: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
1fa0: 2c 20 31 2c 20 20 2f 2a 20 46 78 20 2a 2f 0a 7d , 1, /* Fx */.}
1fb0: 3b 0a 0a 0a 2f 2a 0a 2a 2a 20 52 65 74 75 72 6e ;.../*.** Return
1fc0: 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 74 the length of t
1fd0: 68 65 20 74 6f 6b 65 6e 20 74 68 61 74 20 62 65 he token that be
1fe0: 67 69 6e 73 20 61 74 20 7a 5b 30 5d 2e 20 20 52 gins at z[0]. R
1ff0: 65 74 75 72 6e 0a 2a 2a 20 2d 31 20 69 66 20 74 eturn.** -1 if t
2000: 68 65 20 74 6f 6b 65 6e 20 69 73 20 28 6f 72 20 he token is (or
2010: 6d 69 67 68 74 20 62 65 29 20 69 6e 63 6f 6d 70 might be) incomp
2020: 6c 65 74 65 2e 20 20 53 74 6f 72 65 20 74 68 65 lete. Store the
2030: 20 74 6f 6b 65 6e 0a 2a 2a 20 74 79 70 65 20 69 token.** type i
2040: 6e 20 2a 74 6f 6b 65 6e 54 79 70 65 20 62 65 66 n *tokenType bef
2050: 6f 72 65 20 72 65 74 75 72 6e 69 6e 67 2e 0a 2a ore returning..*
2060: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 73 71 6c /.static int sql
2070: 69 74 65 47 65 74 54 6f 6b 65 6e 28 63 6f 6e 73 iteGetToken(cons
2080: 74 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 t unsigned char
2090: 2a 7a 2c 20 69 6e 74 20 2a 74 6f 6b 65 6e 54 79 *z, int *tokenTy
20a0: 70 65 29 7b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 pe){. int i;.
20b0: 73 77 69 74 63 68 28 20 2a 7a 20 29 7b 0a 20 20 switch( *z ){.
20c0: 20 20 63 61 73 65 20 27 20 27 3a 20 63 61 73 65 case ' ': case
20d0: 20 27 5c 74 27 3a 20 63 61 73 65 20 27 5c 6e 27 '\t': case '\n'
20e0: 3a 20 63 61 73 65 20 27 5c 66 27 3a 20 63 61 73 : case '\f': cas
20f0: 65 20 27 5c 72 27 3a 20 7b 0a 20 20 20 20 20 20 e '\r': {.
2100: 66 6f 72 28 69 3d 31 3b 20 7a 5b 69 5d 20 26 26 for(i=1; z[i] &&
2110: 20 69 73 73 70 61 63 65 28 7a 5b 69 5d 29 3b 20 isspace(z[i]);
2120: 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 2a 74 6f i++){}. *to
2130: 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 53 50 41 kenType = TK_SPA
2140: 43 45 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e CE;. return
2150: 20 69 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 i;. }. ca
2160: 73 65 20 27 2d 27 3a 20 7b 0a 20 20 20 20 20 20 se '-': {.
2170: 69 66 28 20 7a 5b 31 5d 3d 3d 30 20 29 20 72 65 if( z[1]==0 ) re
2180: 74 75 72 6e 20 2d 31 3b 0a 20 20 20 20 20 20 69 turn -1;. i
2190: 66 28 20 7a 5b 31 5d 3d 3d 27 2d 27 20 29 7b 0a f( z[1]=='-' ){.
21a0: 20 20 20 20 20 20 20 20 66 6f 72 28 69 3d 32 3b for(i=2;
21b0: 20 7a 5b 69 5d 20 26 26 20 7a 5b 69 5d 21 3d 27 z[i] && z[i]!='
21c0: 5c 6e 27 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 \n'; i++){}.
21d0: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
21e0: 20 54 4b 5f 43 4f 4d 4d 45 4e 54 3b 0a 20 20 20 TK_COMMENT;.
21f0: 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 return i;.
2200: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 2a 74 6f }. *to
2210: 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4d 49 4e kenType = TK_MIN
2220: 55 53 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e US;. return
2230: 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 1;. }. ca
2240: 73 65 20 27 28 27 3a 20 7b 0a 20 20 20 20 20 20 se '(': {.
2250: 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f *tokenType = TK_
2260: 4c 50 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e LP;. return
2270: 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 1;. }. ca
2280: 73 65 20 27 29 27 3a 20 7b 0a 20 20 20 20 20 20 se ')': {.
2290: 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f *tokenType = TK_
22a0: 52 50 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e RP;. return
22b0: 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 1;. }. ca
22c0: 73 65 20 27 3b 27 3a 20 7b 0a 20 20 20 20 20 20 se ';': {.
22d0: 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f *tokenType = TK_
22e0: 53 45 4d 49 3b 0a 20 20 20 20 20 20 72 65 74 75 SEMI;. retu
22f0: 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 rn 1;. }.
2300: 63 61 73 65 20 27 2b 27 3a 20 7b 0a 20 20 20 20 case '+': {.
2310: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
2320: 4b 5f 50 4c 55 53 3b 0a 20 20 20 20 20 20 72 65 K_PLUS;. re
2330: 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 turn 1;. }.
2340: 20 20 63 61 73 65 20 27 2a 27 3a 20 7b 0a 20 20 case '*': {.
2350: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2360: 20 54 4b 5f 53 54 41 52 3b 0a 20 20 20 20 20 20 TK_STAR;.
2370: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a return 1;. }.
2380: 20 20 20 20 63 61 73 65 20 27 2f 27 3a 20 7b 0a case '/': {.
2390: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
23a0: 20 3d 20 54 4b 5f 53 4c 41 53 48 3b 0a 20 20 20 = TK_SLASH;.
23b0: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 return 1;.
23c0: 20 7d 0a 20 20 20 20 63 61 73 65 20 27 25 27 3a }. case '%':
23d0: 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 {. *tokenT
23e0: 79 70 65 20 3d 20 54 4b 5f 52 45 4d 3b 0a 20 20 ype = TK_REM;.
23f0: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 return 1;.
2400: 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 3d 27 }. case '='
2410: 3a 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e : {. *token
2420: 54 79 70 65 20 3d 20 54 4b 5f 45 51 3b 0a 20 20 Type = TK_EQ;.
2430: 20 20 20 20 72 65 74 75 72 6e 20 31 20 2b 20 28 return 1 + (
2440: 7a 5b 31 5d 3d 3d 27 3d 27 29 3b 0a 20 20 20 20 z[1]=='=');.
2450: 7d 0a 20 20 20 20 63 61 73 65 20 27 3c 27 3a 20 }. case '<':
2460: 7b 0a 20 20 20 20 20 20 69 66 28 20 7a 5b 31 5d {. if( z[1]
2470: 3d 3d 27 3d 27 20 29 7b 0a 20 20 20 20 20 20 20 =='=' ){.
2480: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2490: 5f 4c 45 3b 0a 20 20 20 20 20 20 20 20 72 65 74 _LE;. ret
24a0: 75 72 6e 20 32 3b 0a 20 20 20 20 20 20 7d 65 6c urn 2;. }el
24b0: 73 65 20 69 66 28 20 7a 5b 31 5d 3d 3d 27 3e 27 se if( z[1]=='>'
24c0: 20 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b ){. *tok
24d0: 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4e 45 3b 0a enType = TK_NE;.
24e0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 return 2
24f0: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 ;. }else if
2500: 28 20 7a 5b 31 5d 3d 3d 27 3c 27 20 29 7b 0a 20 ( z[1]=='<' ){.
2510: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
2520: 65 20 3d 20 54 4b 5f 4c 53 48 49 46 54 3b 0a 20 e = TK_LSHIFT;.
2530: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b return 2;
2540: 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 . }else{.
2550: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
2560: 20 3d 20 54 4b 5f 4c 54 3b 0a 20 20 20 20 20 20 = TK_LT;.
2570: 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 return 1;.
2580: 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 }. }. ca
2590: 73 65 20 27 3e 27 3a 20 7b 0a 20 20 20 20 20 20 se '>': {.
25a0: 69 66 28 20 7a 5b 31 5d 3d 3d 27 3d 27 20 29 7b if( z[1]=='=' ){
25b0: 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 . *tokenT
25c0: 79 70 65 20 3d 20 54 4b 5f 47 45 3b 0a 20 20 20 ype = TK_GE;.
25d0: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
25e0: 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 7a }else if( z
25f0: 5b 31 5d 3d 3d 27 3e 27 20 29 7b 0a 20 20 20 20 [1]=='>' ){.
2600: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2610: 20 54 4b 5f 52 53 48 49 46 54 3b 0a 20 20 20 20 TK_RSHIFT;.
2620: 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 return 2;.
2630: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
2640: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
2650: 54 4b 5f 47 54 3b 0a 20 20 20 20 20 20 20 20 72 TK_GT;. r
2660: 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 7d eturn 1;. }
2670: 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 . }. case
2680: 27 21 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 '!': {. if(
2690: 20 7a 5b 31 5d 21 3d 27 3d 27 20 29 7b 0a 20 20 z[1]!='=' ){.
26a0: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
26b0: 20 3d 20 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 = TK_ILLEGAL;.
26c0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b return 2;
26d0: 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 . }else{.
26e0: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
26f0: 20 3d 20 54 4b 5f 4e 45 3b 0a 20 20 20 20 20 20 = TK_NE;.
2700: 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 return 2;.
2710: 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 }. }. ca
2720: 73 65 20 27 7c 27 3a 20 7b 0a 20 20 20 20 20 20 se '|': {.
2730: 69 66 28 20 7a 5b 31 5d 21 3d 27 7c 27 20 29 7b if( z[1]!='|' ){
2740: 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 . *tokenT
2750: 79 70 65 20 3d 20 54 4b 5f 42 49 54 4f 52 3b 0a ype = TK_BITOR;.
2760: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 return 1
2770: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 ;. }else{.
2780: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
2790: 65 20 3d 20 54 4b 5f 43 4f 4e 43 41 54 3b 0a 20 e = TK_CONCAT;.
27a0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b return 2;
27b0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 . }. }.
27c0: 20 20 20 63 61 73 65 20 27 2c 27 3a 20 7b 0a 20 case ',': {.
27d0: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
27e0: 3d 20 54 4b 5f 43 4f 4d 4d 41 3b 0a 20 20 20 20 = TK_COMMA;.
27f0: 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 return 1;.
2800: 7d 0a 20 20 20 20 63 61 73 65 20 27 26 27 3a 20 }. case '&':
2810: 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 {. *tokenTy
2820: 70 65 20 3d 20 54 4b 5f 42 49 54 41 4e 44 3b 0a pe = TK_BITAND;.
2830: 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a return 1;.
2840: 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 }. case '
2850: 7e 27 3a 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b ~': {. *tok
2860: 65 6e 54 79 70 65 20 3d 20 54 4b 5f 42 49 54 4e enType = TK_BITN
2870: 4f 54 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e OT;. return
2880: 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 1;. }. ca
2890: 73 65 20 27 5c 27 27 3a 20 63 61 73 65 20 27 22 se '\'': case '"
28a0: 27 3a 20 7b 0a 20 20 20 20 20 20 69 6e 74 20 64 ': {. int d
28b0: 65 6c 69 6d 20 3d 20 7a 5b 30 5d 3b 0a 20 20 20 elim = z[0];.
28c0: 20 20 20 66 6f 72 28 69 3d 31 3b 20 7a 5b 69 5d for(i=1; z[i]
28d0: 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 20 20 ; i++){.
28e0: 69 66 28 20 7a 5b 69 5d 3d 3d 64 65 6c 69 6d 20 if( z[i]==delim
28f0: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 ){. if(
2900: 20 7a 5b 69 2b 31 5d 3d 3d 64 65 6c 69 6d 20 29 z[i+1]==delim )
2910: 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 2b {. i+
2920: 2b 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 65 6c +;. }el
2930: 73 65 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 se{.
2940: 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 break;.
2950: 20 7d 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 }. }.
2960: 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 7a }. if( z
2970: 5b 69 5d 20 29 20 69 2b 2b 3b 0a 20 20 20 20 20 [i] ) i++;.
2980: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2990: 5f 53 54 52 49 4e 47 3b 0a 20 20 20 20 20 20 72 _STRING;. r
29a0: 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 7d 0a 20 eturn i;. }.
29b0: 20 20 20 63 61 73 65 20 27 2e 27 3a 20 7b 0a 20 case '.': {.
29c0: 20 20 20 20 20 69 66 28 20 21 69 73 64 69 67 69 if( !isdigi
29d0: 74 28 7a 5b 31 5d 29 20 29 7b 0a 20 20 20 20 20 t(z[1]) ){.
29e0: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
29f0: 54 4b 5f 44 4f 54 3b 0a 20 20 20 20 20 20 20 20 TK_DOT;.
2a00: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 return 1;.
2a10: 7d 0a 20 20 20 20 20 20 2f 2a 20 46 61 6c 6c 20 }. /* Fall
2a20: 74 68 72 75 20 69 6e 74 6f 20 74 68 65 20 6e 65 thru into the ne
2a30: 78 74 20 63 61 73 65 20 2a 2f 0a 20 20 20 20 7d xt case */. }
2a40: 0a 20 20 20 20 63 61 73 65 20 27 30 27 3a 20 63 . case '0': c
2a50: 61 73 65 20 27 31 27 3a 20 63 61 73 65 20 27 32 ase '1': case '2
2a60: 27 3a 20 63 61 73 65 20 27 33 27 3a 20 63 61 73 ': case '3': cas
2a70: 65 20 27 34 27 3a 0a 20 20 20 20 63 61 73 65 20 e '4':. case
2a80: 27 35 27 3a 20 63 61 73 65 20 27 36 27 3a 20 63 '5': case '6': c
2a90: 61 73 65 20 27 37 27 3a 20 63 61 73 65 20 27 38 ase '7': case '8
2aa0: 27 3a 20 63 61 73 65 20 27 39 27 3a 20 7b 0a 20 ': case '9': {.
2ab0: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
2ac0: 3d 20 54 4b 5f 49 4e 54 45 47 45 52 3b 0a 20 20 = TK_INTEGER;.
2ad0: 20 20 20 20 66 6f 72 28 69 3d 31 3b 20 7a 5b 69 for(i=1; z[i
2ae0: 5d 20 26 26 20 69 73 64 69 67 69 74 28 7a 5b 69 ] && isdigit(z[i
2af0: 5d 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 ]); i++){}.
2b00: 20 69 66 28 20 7a 5b 69 5d 3d 3d 27 2e 27 20 29 if( z[i]=='.' )
2b10: 7b 0a 20 20 20 20 20 20 20 20 69 2b 2b 3b 0a 20 {. i++;.
2b20: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 7a 5b while( z[
2b30: 69 5d 20 26 26 20 69 73 64 69 67 69 74 28 7a 5b i] && isdigit(z[
2b40: 69 5d 29 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 i]) ){ i++; }.
2b50: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
2b60: 20 3d 20 54 4b 5f 46 4c 4f 41 54 3b 0a 20 20 20 = TK_FLOAT;.
2b70: 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 28 }. if( (
2b80: 7a 5b 69 5d 3d 3d 27 65 27 20 7c 7c 20 7a 5b 69 z[i]=='e' || z[i
2b90: 5d 3d 3d 27 45 27 29 20 26 26 0a 20 20 20 20 20 ]=='E') &&.
2ba0: 20 20 20 20 20 20 28 20 69 73 64 69 67 69 74 28 ( isdigit(
2bb0: 7a 5b 69 2b 31 5d 29 20 0a 20 20 20 20 20 20 20 z[i+1]) .
2bc0: 20 20 20 20 20 7c 7c 20 28 28 7a 5b 69 2b 31 5d || ((z[i+1]
2bd0: 3d 3d 27 2b 27 20 7c 7c 20 7a 5b 69 2b 31 5d 3d =='+' || z[i+1]=
2be0: 3d 27 2d 27 29 20 26 26 20 69 73 64 69 67 69 74 ='-') && isdigit
2bf0: 28 7a 5b 69 2b 32 5d 29 29 0a 20 20 20 20 20 20 (z[i+2])).
2c00: 20 20 20 20 20 29 0a 20 20 20 20 20 20 29 7b 0a ). ){.
2c10: 20 20 20 20 20 20 20 20 69 20 2b 3d 20 32 3b 0a i += 2;.
2c20: 20 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 7a while( z
2c30: 5b 69 5d 20 26 26 20 69 73 64 69 67 69 74 28 7a [i] && isdigit(z
2c40: 5b 69 5d 29 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 [i]) ){ i++; }.
2c50: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
2c60: 65 20 3d 20 54 4b 5f 46 4c 4f 41 54 3b 0a 20 20 e = TK_FLOAT;.
2c70: 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 7a 5b }else if( z[
2c80: 30 5d 3d 3d 27 2e 27 20 29 7b 0a 20 20 20 20 20 0]=='.' ){.
2c90: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
2ca0: 54 4b 5f 46 4c 4f 41 54 3b 0a 20 20 20 20 20 20 TK_FLOAT;.
2cb0: 7d 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 }. return i
2cc0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 ;. }. case
2cd0: 20 27 5b 27 3a 20 7b 0a 20 20 20 20 20 20 66 6f '[': {. fo
2ce0: 72 28 69 3d 31 3b 20 7a 5b 69 5d 20 26 26 20 7a r(i=1; z[i] && z
2cf0: 5b 69 2d 31 5d 21 3d 27 5d 27 3b 20 69 2b 2b 29 [i-1]!=']'; i++)
2d00: 7b 7d 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 {}. *tokenT
2d10: 79 70 65 20 3d 20 54 4b 5f 49 44 3b 0a 20 20 20 ype = TK_ID;.
2d20: 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 return i;.
2d30: 20 7d 0a 20 20 20 20 64 65 66 61 75 6c 74 3a 20 }. default:
2d40: 7b 0a 20 20 20 20 20 20 69 66 28 20 21 69 73 49 {. if( !isI
2d50: 64 43 68 61 72 5b 2a 7a 5d 20 29 7b 0a 20 20 20 dChar[*z] ){.
2d60: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
2d70: 20 20 7d 0a 20 20 20 20 20 20 66 6f 72 28 69 3d }. for(i=
2d80: 31 3b 20 69 73 49 64 43 68 61 72 5b 7a 5b 69 5d 1; isIdChar[z[i]
2d90: 5d 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 ]; i++){}.
2da0: 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 73 71 6c *tokenType = sql
2db0: 69 74 65 4b 65 79 77 6f 72 64 43 6f 64 65 28 28 iteKeywordCode((
2dc0: 63 68 61 72 2a 29 7a 2c 20 69 29 3b 0a 20 20 20 char*)z, i);.
2dd0: 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 return i;.
2de0: 20 7d 0a 20 20 7d 0a 20 20 2a 74 6f 6b 65 6e 54 }. }. *tokenT
2df0: 79 70 65 20 3d 20 54 4b 5f 49 4c 4c 45 47 41 4c ype = TK_ILLEGAL
2e00: 3b 0a 20 20 72 65 74 75 72 6e 20 31 3b 0a 7d 0a ;. return 1;.}.
2e10: 0a 2f 2a 0a 2a 2a 20 52 75 6e 20 74 68 65 20 70 ./*.** Run the p
2e20: 61 72 73 65 72 20 6f 6e 20 74 68 65 20 67 69 76 arser on the giv
2e30: 65 6e 20 53 51 4c 20 73 74 72 69 6e 67 2e 20 20 en SQL string.
2e40: 54 68 65 20 70 61 72 73 65 72 20 73 74 72 75 63 The parser struc
2e50: 74 75 72 65 20 69 73 0a 2a 2a 20 70 61 73 73 65 ture is.** passe
2e60: 64 20 69 6e 2e 20 20 41 6e 20 53 51 4c 49 54 45 d in. An SQLITE
2e70: 5f 20 73 74 61 74 75 73 20 63 6f 64 65 20 69 73 _ status code is
2e80: 20 72 65 74 75 72 6e 65 64 2e 20 20 49 66 20 61 returned. If a
2e90: 6e 20 65 72 72 6f 72 20 6f 63 63 75 72 73 0a 2a n error occurs.*
2ea0: 2a 20 61 6e 64 20 70 7a 45 72 72 4d 73 67 21 3d * and pzErrMsg!=
2eb0: 4e 55 4c 4c 20 74 68 65 6e 20 61 6e 20 65 72 72 NULL then an err
2ec0: 6f 72 20 6d 65 73 73 61 67 65 20 6d 69 67 68 74 or message might
2ed0: 20 62 65 20 77 72 69 74 74 65 6e 20 69 6e 74 6f be written into
2ee0: 20 0a 2a 2a 20 6d 65 6d 6f 72 79 20 6f 62 74 61 .** memory obta
2ef0: 69 6e 65 64 20 66 72 6f 6d 20 6d 61 6c 6c 6f 63 ined from malloc
2f00: 28 29 20 61 6e 64 20 2a 70 7a 45 72 72 4d 73 67 () and *pzErrMsg
2f10: 20 6d 61 64 65 20 74 6f 20 70 6f 69 6e 74 20 74 made to point t
2f20: 6f 20 74 68 61 74 0a 2a 2a 20 65 72 72 6f 72 20 o that.** error
2f30: 6d 65 73 73 61 67 65 2e 20 20 4f 72 20 6d 61 79 message. Or may
2f40: 62 65 20 6e 6f 74 2e 0a 2a 2f 0a 69 6e 74 20 73 be not..*/.int s
2f50: 71 6c 69 74 65 52 75 6e 50 61 72 73 65 72 28 50 qliteRunParser(P
2f60: 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 63 6f arse *pParse, co
2f70: 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c 2c 20 nst char *zSql,
2f80: 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 67 29 char **pzErrMsg)
2f90: 7b 0a 20 20 69 6e 74 20 6e 45 72 72 20 3d 20 30 {. int nErr = 0
2fa0: 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 20 76 6f 69 ;. int i;. voi
2fb0: 64 20 2a 70 45 6e 67 69 6e 65 3b 0a 20 20 69 6e d *pEngine;. in
2fc0: 74 20 6f 6e 63 65 20 3d 20 31 3b 0a 20 20 73 71 t once = 1;. sq
2fd0: 6c 69 74 65 20 2a 64 62 20 3d 20 70 50 61 72 73 lite *db = pPars
2fe0: 65 2d 3e 64 62 3b 0a 20 20 65 78 74 65 72 6e 20 e->db;. extern
2ff0: 76 6f 69 64 20 2a 73 71 6c 69 74 65 50 61 72 73 void *sqlitePars
3000: 65 72 41 6c 6c 6f 63 28 76 6f 69 64 2a 28 2a 29 erAlloc(void*(*)
3010: 28 69 6e 74 29 29 3b 0a 20 20 65 78 74 65 72 6e (int));. extern
3020: 20 76 6f 69 64 20 73 71 6c 69 74 65 50 61 72 73 void sqlitePars
3030: 65 72 46 72 65 65 28 76 6f 69 64 2a 2c 20 76 6f erFree(void*, vo
3040: 69 64 28 2a 29 28 76 6f 69 64 2a 29 29 3b 0a 20 id(*)(void*));.
3050: 20 65 78 74 65 72 6e 20 69 6e 74 20 73 71 6c 69 extern int sqli
3060: 74 65 50 61 72 73 65 72 28 76 6f 69 64 2a 2c 20 teParser(void*,
3070: 69 6e 74 2c 20 54 6f 6b 65 6e 2c 20 50 61 72 73 int, Token, Pars
3080: 65 2a 29 3b 0a 0a 20 20 64 62 2d 3e 66 6c 61 67 e*);.. db->flag
3090: 73 20 26 3d 20 7e 53 51 4c 49 54 45 5f 49 6e 74 s &= ~SQLITE_Int
30a0: 65 72 72 75 70 74 3b 0a 20 20 70 50 61 72 73 65 errupt;. pParse
30b0: 2d 3e 72 63 20 3d 20 53 51 4c 49 54 45 5f 4f 4b ->rc = SQLITE_OK
30c0: 3b 0a 20 20 69 20 3d 20 30 3b 0a 20 20 70 45 6e ;. i = 0;. pEn
30d0: 67 69 6e 65 20 3d 20 73 71 6c 69 74 65 50 61 72 gine = sqlitePar
30e0: 73 65 72 41 6c 6c 6f 63 28 28 76 6f 69 64 2a 28 serAlloc((void*(
30f0: 2a 29 28 69 6e 74 29 29 6d 61 6c 6c 6f 63 29 3b *)(int))malloc);
3100: 0a 20 20 69 66 28 20 70 45 6e 67 69 6e 65 3d 3d . if( pEngine==
3110: 30 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 65 53 0 ){. sqliteS
3120: 65 74 53 74 72 69 6e 67 28 70 7a 45 72 72 4d 73 etString(pzErrMs
3130: 67 2c 20 22 6f 75 74 20 6f 66 20 6d 65 6d 6f 72 g, "out of memor
3140: 79 22 2c 20 30 29 3b 0a 20 20 20 20 72 65 74 75 y", 0);. retu
3150: 72 6e 20 31 3b 0a 20 20 7d 0a 20 20 77 68 69 6c rn 1;. }. whil
3160: 65 28 20 73 71 6c 69 74 65 5f 6d 61 6c 6c 6f 63 e( sqlite_malloc
3170: 5f 66 61 69 6c 65 64 3d 3d 30 20 26 26 20 6e 45 _failed==0 && nE
3180: 72 72 3d 3d 30 20 26 26 20 69 3e 3d 30 20 26 26 rr==0 && i>=0 &&
3190: 20 7a 53 71 6c 5b 69 5d 21 3d 30 20 29 7b 0a 20 zSql[i]!=0 ){.
31a0: 20 20 20 69 6e 74 20 74 6f 6b 65 6e 54 79 70 65 int tokenType
31b0: 3b 0a 20 20 20 20 0a 20 20 20 20 69 66 28 20 28 ;. . if( (
31c0: 64 62 2d 3e 66 6c 61 67 73 20 26 20 53 51 4c 49 db->flags & SQLI
31d0: 54 45 5f 49 6e 74 65 72 72 75 70 74 29 21 3d 30 TE_Interrupt)!=0
31e0: 20 29 7b 0a 20 20 20 20 20 20 70 50 61 72 73 65 ){. pParse
31f0: 2d 3e 72 63 20 3d 20 53 51 4c 49 54 45 5f 49 4e ->rc = SQLITE_IN
3200: 54 45 52 52 55 50 54 3b 0a 20 20 20 20 20 20 73 TERRUPT;. s
3210: 71 6c 69 74 65 53 65 74 53 74 72 69 6e 67 28 70 qliteSetString(p
3220: 7a 45 72 72 4d 73 67 2c 20 22 69 6e 74 65 72 72 zErrMsg, "interr
3230: 75 70 74 22 2c 20 30 29 3b 0a 20 20 20 20 20 20 upt", 0);.
3240: 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 20 break;. }.
3250: 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f pParse->sLastTo
3260: 6b 65 6e 2e 7a 20 3d 20 26 7a 53 71 6c 5b 69 5d ken.z = &zSql[i]
3270: 3b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e 73 4c ;. pParse->sL
3280: 61 73 74 54 6f 6b 65 6e 2e 6e 20 3d 20 73 71 6c astToken.n = sql
3290: 69 74 65 47 65 74 54 6f 6b 65 6e 28 28 75 6e 73 iteGetToken((uns
32a0: 69 67 6e 65 64 20 63 68 61 72 2a 29 26 7a 53 71 igned char*)&zSq
32b0: 6c 5b 69 5d 2c 20 26 74 6f 6b 65 6e 54 79 70 65 l[i], &tokenType
32c0: 29 3b 0a 20 20 20 20 69 20 2b 3d 20 70 50 61 72 );. i += pPar
32d0: 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2e 6e se->sLastToken.n
32e0: 3b 0a 20 20 20 20 69 66 28 20 6f 6e 63 65 20 29 ;. if( once )
32f0: 7b 0a 20 20 20 20 20 20 70 50 61 72 73 65 2d 3e {. pParse->
3300: 73 46 69 72 73 74 54 6f 6b 65 6e 20 3d 20 70 50 sFirstToken = pP
3310: 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e arse->sLastToken
3320: 3b 0a 20 20 20 20 20 20 6f 6e 63 65 20 3d 20 30 ;. once = 0
3330: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 73 77 69 74 ;. }. swit
3340: 63 68 28 20 74 6f 6b 65 6e 54 79 70 65 20 29 7b ch( tokenType ){
3350: 0a 20 20 20 20 20 20 63 61 73 65 20 54 4b 5f 53 . case TK_S
3360: 50 41 43 45 3a 0a 20 20 20 20 20 20 63 61 73 65 PACE:. case
3370: 20 54 4b 5f 43 4f 4d 4d 45 4e 54 3a 20 7b 0a 20 TK_COMMENT: {.
3380: 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 break;.
3390: 20 20 20 20 7d 0a 20 20 20 20 20 20 63 61 73 65 }. case
33a0: 20 54 4b 5f 49 4c 4c 45 47 41 4c 3a 0a 20 20 20 TK_ILLEGAL:.
33b0: 20 20 20 20 20 73 71 6c 69 74 65 53 65 74 4e 53 sqliteSetNS
33c0: 74 72 69 6e 67 28 70 7a 45 72 72 4d 73 67 2c 20 tring(pzErrMsg,
33d0: 22 75 6e 72 65 63 6f 67 6e 69 7a 65 64 20 74 6f "unrecognized to
33e0: 6b 65 6e 3a 20 5c 22 22 2c 20 2d 31 2c 20 0a 20 ken: \"", -1, .
33f0: 20 20 20 20 20 20 20 20 20 20 70 50 61 72 73 65 pParse
3400: 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2e 7a 2c 20 ->sLastToken.z,
3410: 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b pParse->sLastTok
3420: 65 6e 2e 6e 2c 20 22 5c 22 22 2c 20 31 2c 20 30 en.n, "\"", 1, 0
3430: 29 3b 0a 20 20 20 20 20 20 20 20 6e 45 72 72 2b );. nErr+
3440: 2b 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b +;. break
3450: 3b 0a 20 20 20 20 20 20 64 65 66 61 75 6c 74 3a ;. default:
3460: 0a 20 20 20 20 20 20 20 20 73 71 6c 69 74 65 50 . sqliteP
3470: 61 72 73 65 72 28 70 45 6e 67 69 6e 65 2c 20 74 arser(pEngine, t
3480: 6f 6b 65 6e 54 79 70 65 2c 20 70 50 61 72 73 65 okenType, pParse
3490: 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c 20 70 50 ->sLastToken, pP
34a0: 61 72 73 65 29 3b 0a 20 20 20 20 20 20 20 20 69 arse);. i
34b0: 66 28 20 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d f( pParse->zErrM
34c0: 73 67 20 26 26 20 70 50 61 72 73 65 2d 3e 73 45 sg && pParse->sE
34d0: 72 72 54 6f 6b 65 6e 2e 7a 20 29 7b 0a 20 20 20 rrToken.z ){.
34e0: 20 20 20 20 20 20 20 73 71 6c 69 74 65 53 65 74 sqliteSet
34f0: 4e 53 74 72 69 6e 67 28 70 7a 45 72 72 4d 73 67 NString(pzErrMsg
3500: 2c 20 22 6e 65 61 72 20 5c 22 22 2c 20 2d 31 2c , "near \"", -1,
3510: 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 70 . p
3520: 50 61 72 73 65 2d 3e 73 45 72 72 54 6f 6b 65 6e Parse->sErrToken
3530: 2e 7a 2c 20 70 50 61 72 73 65 2d 3e 73 45 72 72 .z, pParse->sErr
3540: 54 6f 6b 65 6e 2e 6e 2c 0a 20 20 20 20 20 20 20 Token.n,.
3550: 20 20 20 20 20 20 22 5c 22 3a 20 22 2c 20 2d 31 "\": ", -1
3560: 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 70 ,. p
3570: 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 67 2c 20 Parse->zErrMsg,
3580: 2d 31 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 -1,.
3590: 20 30 29 3b 0a 20 20 20 20 20 20 20 20 20 20 6e 0);. n
35a0: 45 72 72 2b 2b 3b 0a 20 20 20 20 20 20 20 20 20 Err++;.
35b0: 20 73 71 6c 69 74 65 46 72 65 65 28 70 50 61 72 sqliteFree(pPar
35c0: 73 65 2d 3e 7a 45 72 72 4d 73 67 29 3b 0a 20 20 se->zErrMsg);.
35d0: 20 20 20 20 20 20 20 20 70 50 61 72 73 65 2d 3e pParse->
35e0: 7a 45 72 72 4d 73 67 20 3d 20 30 3b 0a 20 20 20 zErrMsg = 0;.
35f0: 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 70 }else if( p
3600: 50 61 72 73 65 2d 3e 72 63 21 3d 53 51 4c 49 54 Parse->rc!=SQLIT
3610: 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 20 20 20 20 E_OK ){.
3620: 20 20 73 71 6c 69 74 65 53 65 74 53 74 72 69 6e sqliteSetStrin
3630: 67 28 70 7a 45 72 72 4d 73 67 2c 20 73 71 6c 69 g(pzErrMsg, sqli
3640: 74 65 5f 65 72 72 6f 72 5f 73 74 72 69 6e 67 28 te_error_string(
3650: 70 50 61 72 73 65 2d 3e 72 63 29 2c 20 30 29 3b pParse->rc), 0);
3660: 0a 20 20 20 20 20 20 20 20 20 20 6e 45 72 72 2b . nErr+
3670: 2b 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 +;. }.
3680: 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 break;.
3690: 7d 0a 20 20 7d 0a 20 20 69 66 28 20 7a 53 71 6c }. }. if( zSql
36a0: 5b 69 5d 3d 3d 30 20 29 7b 0a 20 20 20 20 73 71 [i]==0 ){. sq
36b0: 6c 69 74 65 50 61 72 73 65 72 28 70 45 6e 67 69 liteParser(pEngi
36c0: 6e 65 2c 20 54 4b 5f 53 45 4d 49 2c 20 70 50 61 ne, TK_SEMI, pPa
36d0: 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c rse->sLastToken,
36e0: 20 70 50 61 72 73 65 29 3b 0a 20 20 20 20 73 71 pParse);. sq
36f0: 6c 69 74 65 50 61 72 73 65 72 28 70 45 6e 67 69 liteParser(pEngi
3700: 6e 65 2c 20 30 2c 20 70 50 61 72 73 65 2d 3e 73 ne, 0, pParse->s
3710: 4c 61 73 74 54 6f 6b 65 6e 2c 20 70 50 61 72 73 LastToken, pPars
3720: 65 29 3b 0a 20 20 20 20 69 66 28 20 70 50 61 72 e);. if( pPar
3730: 73 65 2d 3e 7a 45 72 72 4d 73 67 20 26 26 20 70 se->zErrMsg && p
3740: 50 61 72 73 65 2d 3e 73 45 72 72 54 6f 6b 65 6e Parse->sErrToken
3750: 2e 7a 20 29 7b 0a 20 20 20 20 20 20 20 73 71 6c .z ){. sql
3760: 69 74 65 53 65 74 4e 53 74 72 69 6e 67 28 70 7a iteSetNString(pz
3770: 45 72 72 4d 73 67 2c 20 22 6e 65 61 72 20 5c 22 ErrMsg, "near \"
3780: 22 2c 20 2d 31 2c 20 0a 20 20 20 20 20 20 20 20 ", -1, .
3790: 20 20 70 50 61 72 73 65 2d 3e 73 45 72 72 54 6f pParse->sErrTo
37a0: 6b 65 6e 2e 7a 2c 20 70 50 61 72 73 65 2d 3e 73 ken.z, pParse->s
37b0: 45 72 72 54 6f 6b 65 6e 2e 6e 2c 0a 20 20 20 20 ErrToken.n,.
37c0: 20 20 20 20 20 20 22 5c 22 3a 20 22 2c 20 2d 31 "\": ", -1
37d0: 2c 0a 20 20 20 20 20 20 20 20 20 20 70 50 61 72 ,. pPar
37e0: 73 65 2d 3e 7a 45 72 72 4d 73 67 2c 20 2d 31 2c se->zErrMsg, -1,
37f0: 0a 20 20 20 20 20 20 20 20 20 20 30 29 3b 0a 20 . 0);.
3800: 20 20 20 20 20 20 6e 45 72 72 2b 2b 3b 0a 20 20 nErr++;.
3810: 20 20 20 20 20 73 71 6c 69 74 65 46 72 65 65 28 sqliteFree(
3820: 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 67 29 pParse->zErrMsg)
3830: 3b 0a 20 20 20 20 20 20 20 70 50 61 72 73 65 2d ;. pParse-
3840: 3e 7a 45 72 72 4d 73 67 20 3d 20 30 3b 0a 20 20 >zErrMsg = 0;.
3850: 20 20 7d 0a 20 20 7d 0a 20 20 73 71 6c 69 74 65 }. }. sqlite
3860: 50 61 72 73 65 72 46 72 65 65 28 70 45 6e 67 69 ParserFree(pEngi
3870: 6e 65 2c 20 66 72 65 65 29 3b 0a 20 20 69 66 28 ne, free);. if(
3880: 20 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 67 pParse->zErrMsg
3890: 20 29 7b 0a 20 20 20 20 69 66 28 20 70 7a 45 72 ){. if( pzEr
38a0: 72 4d 73 67 20 29 7b 0a 20 20 20 20 20 20 73 71 rMsg ){. sq
38b0: 6c 69 74 65 46 72 65 65 28 2a 70 7a 45 72 72 4d liteFree(*pzErrM
38c0: 73 67 29 3b 0a 20 20 20 20 20 20 2a 70 7a 45 72 sg);. *pzEr
38d0: 72 4d 73 67 20 3d 20 70 50 61 72 73 65 2d 3e 7a rMsg = pParse->z
38e0: 45 72 72 4d 73 67 3b 0a 20 20 20 20 7d 65 6c 73 ErrMsg;. }els
38f0: 65 7b 0a 20 20 20 20 20 20 73 71 6c 69 74 65 46 e{. sqliteF
3900: 72 65 65 28 70 50 61 72 73 65 2d 3e 7a 45 72 72 ree(pParse->zErr
3910: 4d 73 67 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 Msg);. }.
3920: 69 66 28 20 21 6e 45 72 72 20 29 20 6e 45 72 72 if( !nErr ) nErr
3930: 2b 2b 3b 0a 20 20 7d 0a 20 20 69 66 28 20 70 50 ++;. }. if( pP
3940: 61 72 73 65 2d 3e 70 56 64 62 65 20 29 7b 0a 20 arse->pVdbe ){.
3950: 20 20 20 73 71 6c 69 74 65 56 64 62 65 44 65 6c sqliteVdbeDel
3960: 65 74 65 28 70 50 61 72 73 65 2d 3e 70 56 64 62 ete(pParse->pVdb
3970: 65 29 3b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e e);. pParse->
3980: 70 56 64 62 65 20 3d 20 30 3b 0a 20 20 7d 0a 20 pVdbe = 0;. }.
3990: 20 69 66 28 20 70 50 61 72 73 65 2d 3e 70 4e 65 if( pParse->pNe
39a0: 77 54 61 62 6c 65 20 29 7b 0a 20 20 20 20 73 71 wTable ){. sq
39b0: 6c 69 74 65 44 65 6c 65 74 65 54 61 62 6c 65 28 liteDeleteTable(
39c0: 70 50 61 72 73 65 2d 3e 64 62 2c 20 70 50 61 72 pParse->db, pPar
39d0: 73 65 2d 3e 70 4e 65 77 54 61 62 6c 65 29 3b 0a se->pNewTable);.
39e0: 20 20 20 20 70 50 61 72 73 65 2d 3e 70 4e 65 77 pParse->pNew
39f0: 54 61 62 6c 65 20 3d 20 30 3b 0a 20 20 7d 0a 20 Table = 0;. }.
3a00: 20 69 66 28 20 6e 45 72 72 3e 30 20 26 26 20 70 if( nErr>0 && p
3a10: 50 61 72 73 65 2d 3e 72 63 3d 3d 53 51 4c 49 54 Parse->rc==SQLIT
3a20: 45 5f 4f 4b 20 29 7b 0a 20 20 20 20 70 50 61 72 E_OK ){. pPar
3a30: 73 65 2d 3e 72 63 20 3d 20 53 51 4c 49 54 45 5f se->rc = SQLITE_
3a40: 45 52 52 4f 52 3b 0a 20 20 7d 0a 20 20 72 65 74 ERROR;. }. ret
3a50: 75 72 6e 20 6e 45 72 72 3b 0a 7d 0a urn nErr;.}.