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 2f 0a 23 69 6e 63 6c 75 64 65 20 22 73 ..*/.#include "s
0240: 71 6c 69 74 65 49 6e 74 2e 68 22 0a 23 69 6e 63 qliteInt.h".#inc
0250: 6c 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a lude <stdlib.h>.
0260: 0a 2f 2a 0a 2a 2a 20 54 68 65 20 63 68 61 72 4d ./*.** The charM
0270: 61 70 28 29 20 6d 61 63 72 6f 20 6d 61 70 73 20 ap() macro maps
0280: 61 6c 70 68 61 62 65 74 69 63 20 63 68 61 72 61 alphabetic chara
0290: 63 74 65 72 73 20 69 6e 74 6f 20 74 68 65 69 72 cters into their
02a0: 0a 2a 2a 20 6c 6f 77 65 72 2d 63 61 73 65 20 41 .** lower-case A
02b0: 53 43 49 49 20 65 71 75 69 76 61 6c 65 6e 74 2e SCII equivalent.
02c0: 20 20 4f 6e 20 41 53 43 49 49 20 6d 61 63 68 69 On ASCII machi
02d0: 6e 65 73 2c 20 74 68 69 73 20 69 73 20 6a 75 73 nes, this is jus
02e0: 74 0a 2a 2a 20 61 6e 20 75 70 70 65 72 2d 74 6f t.** an upper-to
02f0: 2d 6c 6f 77 65 72 20 63 61 73 65 20 6d 61 70 2e -lower case map.
0300: 20 20 4f 6e 20 45 42 43 44 49 43 20 6d 61 63 68 On EBCDIC mach
0310: 69 6e 65 73 20 77 65 20 61 6c 73 6f 20 6e 65 65 ines we also nee
0320: 64 0a 2a 2a 20 74 6f 20 61 64 6a 75 73 74 20 74 d.** to adjust t
0330: 68 65 20 65 6e 63 6f 64 69 6e 67 2e 20 20 4f 6e he encoding. On
0340: 6c 79 20 61 6c 70 68 61 62 65 74 69 63 20 63 68 ly alphabetic ch
0350: 61 72 61 63 74 65 72 73 20 61 6e 64 20 75 6e 64 aracters and und
0360: 65 72 73 63 6f 72 65 73 0a 2a 2a 20 6e 65 65 64 erscores.** need
0370: 20 74 6f 20 62 65 20 74 72 61 6e 73 6c 61 74 65 to be translate
0380: 64 2e 0a 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c d..*/.#ifdef SQL
0390: 49 54 45 5f 41 53 43 49 49 0a 23 20 64 65 66 69 ITE_ASCII.# defi
03a0: 6e 65 20 63 68 61 72 4d 61 70 28 58 29 20 73 71 ne charMap(X) sq
03b0: 6c 69 74 65 33 55 70 70 65 72 54 6f 4c 6f 77 65 lite3UpperToLowe
03c0: 72 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 r[(unsigned char
03d0: 29 58 5d 0a 23 65 6e 64 69 66 0a 23 69 66 64 65 )X].#endif.#ifde
03e0: 66 20 53 51 4c 49 54 45 5f 45 42 43 44 49 43 0a f SQLITE_EBCDIC.
03f0: 23 20 64 65 66 69 6e 65 20 63 68 61 72 4d 61 70 # define charMap
0400: 28 58 29 20 65 62 63 64 69 63 54 6f 41 73 63 69 (X) ebcdicToAsci
0410: 69 5b 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 i[(unsigned char
0420: 29 58 5d 0a 63 6f 6e 73 74 20 75 6e 73 69 67 6e )X].const unsign
0430: 65 64 20 63 68 61 72 20 65 62 63 64 69 63 54 6f ed char ebcdicTo
0440: 41 73 63 69 69 5b 5d 20 3d 20 7b 0a 2f 2a 20 30 Ascii[] = {./* 0
0450: 20 20 20 31 20 20 20 32 20 20 20 33 20 20 20 34 1 2 3 4
0460: 20 20 20 35 20 20 20 36 20 20 20 37 20 20 20 38 5 6 7 8
0470: 20 20 20 39 20 20 20 41 20 20 20 42 20 20 20 43 9 A B C
0480: 20 20 20 44 20 20 20 45 20 20 20 46 20 2a 2f 0a D E F */.
0490: 20 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 0, 0, 0, 0
04a0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
04b0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
04c0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
04d0: 2c 20 20 2f 2a 20 30 78 20 2a 2f 0a 20 20 20 30 , /* 0x */. 0
04e0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
04f0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0500: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0510: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 2f , 0, 0, 0, /
0520: 2a 20 31 78 20 2a 2f 0a 20 20 20 30 2c 20 20 30 * 1x */. 0, 0
0530: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0540: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0550: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0560: 2c 20 20 30 2c 20 20 30 2c 20 20 2f 2a 20 32 78 , 0, 0, /* 2x
0570: 20 2a 2f 0a 20 20 20 30 2c 20 20 30 2c 20 20 30 */. 0, 0, 0
0580: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0590: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
05a0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
05b0: 2c 20 20 30 2c 20 20 2f 2a 20 33 78 20 2a 2f 0a , 0, /* 3x */.
05c0: 20 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 0, 0, 0, 0
05d0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
05e0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
05f0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0600: 2c 20 20 2f 2a 20 34 78 20 2a 2f 0a 20 20 20 30 , /* 4x */. 0
0610: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0620: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0630: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0640: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 2f , 0, 0, 0, /
0650: 2a 20 35 78 20 2a 2f 0a 20 20 20 30 2c 20 20 30 * 5x */. 0, 0
0660: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0670: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0680: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 39 35 , 0, 0, 0, 95
0690: 2c 20 20 30 2c 20 20 30 2c 20 20 2f 2a 20 36 78 , 0, 0, /* 6x
06a0: 20 2a 2f 0a 20 20 20 30 2c 20 20 30 2c 20 20 30 */. 0, 0, 0
06b0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
06c0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
06d0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
06e0: 2c 20 20 30 2c 20 20 2f 2a 20 37 78 20 2a 2f 0a , 0, /* 7x */.
06f0: 20 20 20 30 2c 20 39 37 2c 20 39 38 2c 20 39 39 0, 97, 98, 99
0700: 2c 31 30 30 2c 31 30 31 2c 31 30 32 2c 31 30 33 ,100,101,102,103
0710: 2c 31 30 34 2c 31 30 35 2c 20 20 30 2c 20 20 30 ,104,105, 0, 0
0720: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0730: 2c 20 20 2f 2a 20 38 78 20 2a 2f 0a 20 20 20 30 , /* 8x */. 0
0740: 2c 31 30 36 2c 31 30 37 2c 31 30 38 2c 31 30 39 ,106,107,108,109
0750: 2c 31 31 30 2c 31 31 31 2c 31 31 32 2c 31 31 33 ,110,111,112,113
0760: 2c 31 31 34 2c 20 20 30 2c 20 20 30 2c 20 20 30 ,114, 0, 0, 0
0770: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 2f , 0, 0, 0, /
0780: 2a 20 39 78 20 2a 2f 0a 20 20 20 30 2c 20 20 30 * 9x */. 0, 0
0790: 2c 31 31 35 2c 31 31 36 2c 31 31 37 2c 31 31 38 ,115,116,117,118
07a0: 2c 31 31 39 2c 31 32 30 2c 31 32 31 2c 31 32 32 ,119,120,121,122
07b0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
07c0: 2c 20 20 30 2c 20 20 30 2c 20 20 2f 2a 20 41 78 , 0, 0, /* Ax
07d0: 20 2a 2f 0a 20 20 20 30 2c 20 20 30 2c 20 20 30 */. 0, 0, 0
07e0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
07f0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0800: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0810: 2c 20 20 30 2c 20 20 2f 2a 20 42 78 20 2a 2f 0a , 0, /* Bx */.
0820: 20 20 20 30 2c 20 39 37 2c 20 39 38 2c 20 39 39 0, 97, 98, 99
0830: 2c 31 30 30 2c 31 30 31 2c 31 30 32 2c 31 30 33 ,100,101,102,103
0840: 2c 31 30 34 2c 31 30 35 2c 20 20 30 2c 20 20 30 ,104,105, 0, 0
0850: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0860: 2c 20 20 2f 2a 20 43 78 20 2a 2f 0a 20 20 20 30 , /* Cx */. 0
0870: 2c 31 30 36 2c 31 30 37 2c 31 30 38 2c 31 30 39 ,106,107,108,109
0880: 2c 31 31 30 2c 31 31 31 2c 31 31 32 2c 31 31 33 ,110,111,112,113
0890: 2c 31 31 34 2c 20 20 30 2c 20 20 30 2c 20 20 30 ,114, 0, 0, 0
08a0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 2f , 0, 0, 0, /
08b0: 2a 20 44 78 20 2a 2f 0a 20 20 20 30 2c 20 20 30 * Dx */. 0, 0
08c0: 2c 31 31 35 2c 31 31 36 2c 31 31 37 2c 31 31 38 ,115,116,117,118
08d0: 2c 31 31 39 2c 31 32 30 2c 31 32 31 2c 31 32 32 ,119,120,121,122
08e0: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
08f0: 2c 20 20 30 2c 20 20 30 2c 20 20 2f 2a 20 45 78 , 0, 0, /* Ex
0900: 20 2a 2f 0a 20 20 20 30 2c 20 20 30 2c 20 20 30 */. 0, 0, 0
0910: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0920: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0930: 2c 20 20 30 2c 20 20 30 2c 20 20 30 2c 20 20 30 , 0, 0, 0, 0
0940: 2c 20 20 30 2c 20 20 2f 2a 20 46 78 20 2a 2f 0a , 0, /* Fx */.
0950: 7d 3b 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 2a 2a };.#endif../*.**
0960: 20 54 68 65 20 73 71 6c 69 74 65 33 4b 65 79 77 The sqlite3Keyw
0970: 6f 72 64 43 6f 64 65 20 66 75 6e 63 74 69 6f 6e ordCode function
0980: 20 6c 6f 6f 6b 73 20 75 70 20 61 6e 20 69 64 65 looks up an ide
0990: 6e 74 69 66 69 65 72 20 74 6f 20 64 65 74 65 72 ntifier to deter
09a0: 6d 69 6e 65 20 69 66 0a 2a 2a 20 69 74 20 69 73 mine if.** it is
09b0: 20 61 20 6b 65 79 77 6f 72 64 2e 20 20 49 66 20 a keyword. If
09c0: 69 74 20 69 73 20 61 20 6b 65 79 77 6f 72 64 2c it is a keyword,
09d0: 20 74 68 65 20 74 6f 6b 65 6e 20 63 6f 64 65 20 the token code
09e0: 6f 66 20 74 68 61 74 20 6b 65 79 77 6f 72 64 20 of that keyword
09f0: 69 73 20 0a 2a 2a 20 72 65 74 75 72 6e 65 64 2e is .** returned.
0a00: 20 20 49 66 20 74 68 65 20 69 6e 70 75 74 20 69 If the input i
0a10: 73 20 6e 6f 74 20 61 20 6b 65 79 77 6f 72 64 2c s not a keyword,
0a20: 20 54 4b 5f 49 44 20 69 73 20 72 65 74 75 72 6e TK_ID is return
0a30: 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 69 6d ed..**.** The im
0a40: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 plementation of
0a50: 74 68 69 73 20 72 6f 75 74 69 6e 65 20 77 61 73 this routine was
0a60: 20 67 65 6e 65 72 61 74 65 64 20 62 79 20 61 20 generated by a
0a70: 70 72 6f 67 72 61 6d 2c 0a 2a 2a 20 6d 6b 6b 65 program,.** mkke
0a80: 79 77 6f 72 64 68 61 73 68 2e 68 2c 20 6c 6f 63 ywordhash.h, loc
0a90: 61 74 65 64 20 69 6e 20 74 68 65 20 74 6f 6f 6c ated in the tool
0aa0: 20 73 75 62 64 69 72 65 63 74 6f 72 79 20 6f 66 subdirectory of
0ab0: 20 74 68 65 20 64 69 73 74 72 69 62 75 74 69 6f the distributio
0ac0: 6e 2e 0a 2a 2a 20 54 68 65 20 6f 75 74 70 75 74 n..** The output
0ad0: 20 6f 66 20 74 68 65 20 6d 6b 6b 65 79 77 6f 72 of the mkkeywor
0ae0: 64 68 61 73 68 2e 63 20 70 72 6f 67 72 61 6d 20 dhash.c program
0af0: 69 73 20 77 72 69 74 74 65 6e 20 69 6e 74 6f 20 is written into
0b00: 61 20 66 69 6c 65 0a 2a 2a 20 6e 61 6d 65 64 20 a file.** named
0b10: 6b 65 79 77 6f 72 64 68 61 73 68 2e 68 20 61 6e keywordhash.h an
0b20: 64 20 74 68 65 6e 20 69 6e 63 6c 75 64 65 64 20 d then included
0b30: 69 6e 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 into this source
0b40: 20 66 69 6c 65 20 62 79 0a 2a 2a 20 74 68 65 20 file by.** the
0b50: 23 69 6e 63 6c 75 64 65 20 62 65 6c 6f 77 2e 0a #include below..
0b60: 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22 6b 65 79 */.#include "key
0b70: 77 6f 72 64 68 61 73 68 2e 68 22 0a 0a 0a 2f 2a wordhash.h".../*
0b80: 0a 2a 2a 20 49 66 20 58 20 69 73 20 61 20 63 68 .** If X is a ch
0b90: 61 72 61 63 74 65 72 20 74 68 61 74 20 63 61 6e aracter that can
0ba0: 20 62 65 20 75 73 65 64 20 69 6e 20 61 6e 20 69 be used in an i
0bb0: 64 65 6e 74 69 66 69 65 72 20 74 68 65 6e 0a 2a dentifier then.*
0bc0: 2a 20 49 64 43 68 61 72 28 58 29 20 77 69 6c 6c * IdChar(X) will
0bd0: 20 62 65 20 74 72 75 65 2e 20 20 4f 74 68 65 72 be true. Other
0be0: 77 69 73 65 20 69 74 20 69 73 20 66 61 6c 73 65 wise it is false
0bf0: 2e 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 41 53 43 49 ..**.** For ASCI
0c00: 49 2c 20 61 6e 79 20 63 68 61 72 61 63 74 65 72 I, any character
0c10: 20 77 69 74 68 20 74 68 65 20 68 69 67 68 2d 6f with the high-o
0c20: 72 64 65 72 20 62 69 74 20 73 65 74 20 69 73 0a rder bit set is.
0c30: 2a 2a 20 61 6c 6c 6f 77 65 64 20 69 6e 20 61 6e ** allowed in an
0c40: 20 69 64 65 6e 74 69 66 69 65 72 2e 20 20 46 6f identifier. Fo
0c50: 72 20 37 2d 62 69 74 20 63 68 61 72 61 63 74 65 r 7-bit characte
0c60: 72 73 2c 20 0a 2a 2a 20 73 71 6c 69 74 65 33 49 rs, .** sqlite3I
0c70: 73 49 64 43 68 61 72 5b 58 5d 20 6d 75 73 74 20 sIdChar[X] must
0c80: 62 65 20 31 2e 0a 2a 2a 0a 2a 2a 20 46 6f 72 20 be 1..**.** For
0c90: 45 42 43 44 49 43 2c 20 74 68 65 20 72 75 6c 65 EBCDIC, the rule
0ca0: 73 20 61 72 65 20 6d 6f 72 65 20 63 6f 6d 70 6c s are more compl
0cb0: 65 78 20 62 75 74 20 68 61 76 65 20 74 68 65 20 ex but have the
0cc0: 73 61 6d 65 0a 2a 2a 20 65 6e 64 20 72 65 73 75 same.** end resu
0cd0: 6c 74 2e 0a 2a 2a 0a 2a 2a 20 54 69 63 6b 65 74 lt..**.** Ticket
0ce0: 20 23 31 30 36 36 2e 20 20 74 68 65 20 53 51 4c #1066. the SQL
0cf0: 20 73 74 61 6e 64 61 72 64 20 64 6f 65 73 20 6e standard does n
0d00: 6f 74 20 61 6c 6c 6f 77 20 27 24 27 20 69 6e 20 ot allow '$' in
0d10: 74 68 65 0a 2a 2a 20 6d 69 64 64 6c 65 20 6f 66 the.** middle of
0d20: 20 69 64 65 6e 74 69 66 69 65 72 73 2e 20 20 42 identifiers. B
0d30: 75 74 20 6d 61 6e 79 20 53 51 4c 20 69 6d 70 6c ut many SQL impl
0d40: 65 6d 65 6e 74 61 74 69 6f 6e 73 20 64 6f 2e 20 ementations do.
0d50: 0a 2a 2a 20 53 51 4c 69 74 65 20 77 69 6c 6c 20 .** SQLite will
0d60: 61 6c 6c 6f 77 20 27 24 27 20 69 6e 20 69 64 65 allow '$' in ide
0d70: 6e 74 69 66 69 65 72 73 20 66 6f 72 20 63 6f 6d ntifiers for com
0d80: 70 61 74 69 62 69 6c 69 74 79 2e 0a 2a 2a 20 42 patibility..** B
0d90: 75 74 20 74 68 65 20 66 65 61 74 75 72 65 20 69 ut the feature i
0da0: 73 20 75 6e 64 6f 63 75 6d 65 6e 74 65 64 2e 0a s undocumented..
0db0: 2a 2f 0a 23 69 66 64 65 66 20 53 51 4c 49 54 45 */.#ifdef SQLITE
0dc0: 5f 41 53 43 49 49 0a 23 64 65 66 69 6e 65 20 49 _ASCII.#define I
0dd0: 64 43 68 61 72 28 43 29 20 20 28 28 73 71 6c 69 dChar(C) ((sqli
0de0: 74 65 33 43 74 79 70 65 4d 61 70 5b 28 75 6e 73 te3CtypeMap[(uns
0df0: 69 67 6e 65 64 20 63 68 61 72 29 43 5d 26 30 78 igned char)C]&0x
0e00: 34 36 29 21 3d 30 29 0a 23 65 6e 64 69 66 0a 23 46)!=0).#endif.#
0e10: 69 66 64 65 66 20 53 51 4c 49 54 45 5f 45 42 43 ifdef SQLITE_EBC
0e20: 44 49 43 0a 63 6f 6e 73 74 20 63 68 61 72 20 73 DIC.const char s
0e30: 71 6c 69 74 65 33 49 73 45 62 63 64 69 63 49 64 qlite3IsEbcdicId
0e40: 43 68 61 72 5b 5d 20 3d 20 7b 0a 2f 2a 20 78 30 Char[] = {./* x0
0e50: 20 78 31 20 78 32 20 78 33 20 78 34 20 78 35 20 x1 x2 x3 x4 x5
0e60: 78 36 20 78 37 20 78 38 20 78 39 20 78 41 20 78 x6 x7 x8 x9 xA x
0e70: 42 20 78 43 20 78 44 20 78 45 20 78 46 20 2a 2f B xC xD xE xF */
0e80: 0a 20 20 20 20 30 2c 20 30 2c 20 31 2c 20 31 2c . 0, 0, 1, 1,
0e90: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
0ea0: 31 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 1, 0, 0, 0, 0, 0
0eb0: 2c 20 30 2c 20 20 2f 2a 20 34 78 20 2a 2f 0a 20 , 0, /* 4x */.
0ec0: 20 20 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 31 0, 1, 1, 1, 1
0ed0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
0ee0: 20 30 2c 20 31 2c 20 30 2c 20 30 2c 20 30 2c 20 0, 1, 0, 0, 0,
0ef0: 30 2c 20 20 2f 2a 20 35 78 20 2a 2f 0a 20 20 20 0, /* 5x */.
0f00: 20 30 2c 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 0, 0, 1, 1, 1,
0f10: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 30 1, 1, 1, 1, 1, 0
0f20: 2c 20 30 2c 20 30 2c 20 31 2c 20 30 2c 20 30 2c , 0, 0, 1, 0, 0,
0f30: 20 20 2f 2a 20 36 78 20 2a 2f 0a 20 20 20 20 30 /* 6x */. 0
0f40: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
0f50: 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c 20 1, 1, 1, 0, 0,
0f60: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 20 0, 0, 0, 0, 0,
0f70: 2f 2a 20 37 78 20 2a 2f 0a 20 20 20 20 30 2c 20 /* 7x */. 0,
0f80: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 1, 1, 1, 1, 1
0f90: 2c 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c , 1, 1, 1, 0, 0,
0fa0: 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 20 2f 2a 1, 1, 1, 0, /*
0fb0: 20 38 78 20 2a 2f 0a 20 20 20 20 30 2c 20 31 2c 8x */. 0, 1,
0fc0: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
0fd0: 31 2c 20 31 2c 20 31 2c 20 30 2c 20 30 2c 20 31 1, 1, 1, 0, 0, 1
0fe0: 2c 20 30 2c 20 31 2c 20 30 2c 20 20 2f 2a 20 39 , 0, 1, 0, /* 9
0ff0: 78 20 2a 2f 0a 20 20 20 20 31 2c 20 30 2c 20 31 x */. 1, 0, 1
1000: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1010: 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 31 2c 20 1, 1, 1, 0, 1,
1020: 31 2c 20 31 2c 20 30 2c 20 20 2f 2a 20 41 78 20 1, 1, 0, /* Ax
1030: 2a 2f 0a 20 20 20 20 30 2c 20 30 2c 20 30 2c 20 */. 0, 0, 0,
1040: 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 0, 0, 0, 0, 0, 0
1050: 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c 20 30 2c , 0, 0, 0, 0, 0,
1060: 20 30 2c 20 30 2c 20 20 2f 2a 20 42 78 20 2a 2f 0, 0, /* Bx */
1070: 0a 20 20 20 20 30 2c 20 31 2c 20 31 2c 20 31 2c . 0, 1, 1, 1,
1080: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 1, 1, 1, 1, 1,
1090: 31 2c 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 31 1, 0, 1, 1, 1, 1
10a0: 2c 20 31 2c 20 20 2f 2a 20 43 78 20 2a 2f 0a 20 , 1, /* Cx */.
10b0: 20 20 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 31 0, 1, 1, 1, 1
10c0: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
10d0: 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 0, 1, 1, 1, 1,
10e0: 31 2c 20 20 2f 2a 20 44 78 20 2a 2f 0a 20 20 20 1, /* Dx */.
10f0: 20 30 2c 20 30 2c 20 31 2c 20 31 2c 20 31 2c 20 0, 0, 1, 1, 1,
1100: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 30 1, 1, 1, 1, 1, 0
1110: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1120: 20 20 2f 2a 20 45 78 20 2a 2f 0a 20 20 20 20 31 /* Ex */. 1
1130: 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 31 2c , 1, 1, 1, 1, 1,
1140: 20 31 2c 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 1, 1, 1, 1, 0,
1150: 31 2c 20 31 2c 20 31 2c 20 31 2c 20 30 2c 20 20 1, 1, 1, 1, 0,
1160: 2f 2a 20 46 78 20 2a 2f 0a 7d 3b 0a 23 64 65 66 /* Fx */.};.#def
1170: 69 6e 65 20 49 64 43 68 61 72 28 43 29 20 20 28 ine IdChar(C) (
1180: 28 28 63 3d 43 29 3e 3d 30 78 34 32 20 26 26 20 ((c=C)>=0x42 &&
1190: 73 71 6c 69 74 65 33 49 73 45 62 63 64 69 63 49 sqlite3IsEbcdicI
11a0: 64 43 68 61 72 5b 63 2d 30 78 34 30 5d 29 29 0a dChar[c-0x40])).
11b0: 23 65 6e 64 69 66 0a 0a 2f 2a 20 4d 61 6b 65 20 #endif../* Make
11c0: 74 68 65 20 49 64 43 68 61 72 20 66 75 6e 63 74 the IdChar funct
11d0: 69 6f 6e 20 61 63 63 65 73 73 69 62 6c 65 20 66 ion accessible f
11e0: 72 6f 6d 20 63 74 69 6d 65 2e 63 20 2a 2f 0a 23 rom ctime.c */.#
11f0: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
1200: 49 54 5f 43 4f 4d 50 49 4c 45 4f 50 54 49 4f 4e IT_COMPILEOPTION
1210: 5f 44 49 41 47 53 0a 69 6e 74 20 73 71 6c 69 74 _DIAGS.int sqlit
1220: 65 33 49 73 49 64 43 68 61 72 28 75 38 20 63 29 e3IsIdChar(u8 c)
1230: 7b 20 72 65 74 75 72 6e 20 49 64 43 68 61 72 28 { return IdChar(
1240: 63 29 3b 20 7d 0a 23 65 6e 64 69 66 0a 0a 0a 2f c); }.#endif.../
1250: 2a 0a 2a 2a 20 52 65 74 75 72 6e 20 74 68 65 20 *.** Return the
1260: 6c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 74 6f length of the to
1270: 6b 65 6e 20 74 68 61 74 20 62 65 67 69 6e 73 20 ken that begins
1280: 61 74 20 7a 5b 30 5d 2e 20 0a 2a 2a 20 53 74 6f at z[0]. .** Sto
1290: 72 65 20 74 68 65 20 74 6f 6b 65 6e 20 74 79 70 re the token typ
12a0: 65 20 69 6e 20 2a 74 6f 6b 65 6e 54 79 70 65 20 e in *tokenType
12b0: 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 6e 67 before returning
12c0: 2e 0a 2a 2f 0a 69 6e 74 20 73 71 6c 69 74 65 33 ..*/.int sqlite3
12d0: 47 65 74 54 6f 6b 65 6e 28 63 6f 6e 73 74 20 75 GetToken(const u
12e0: 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 7a 2c nsigned char *z,
12f0: 20 69 6e 74 20 2a 74 6f 6b 65 6e 54 79 70 65 29 int *tokenType)
1300: 7b 0a 20 20 69 6e 74 20 69 2c 20 63 3b 0a 20 20 {. int i, c;.
1310: 73 77 69 74 63 68 28 20 2a 7a 20 29 7b 0a 20 20 switch( *z ){.
1320: 20 20 63 61 73 65 20 27 20 27 3a 20 63 61 73 65 case ' ': case
1330: 20 27 5c 74 27 3a 20 63 61 73 65 20 27 5c 6e 27 '\t': case '\n'
1340: 3a 20 63 61 73 65 20 27 5c 66 27 3a 20 63 61 73 : case '\f': cas
1350: 65 20 27 5c 72 27 3a 20 7b 0a 20 20 20 20 20 20 e '\r': {.
1360: 74 65 73 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d testcase( z[0]==
1370: 27 20 27 20 29 3b 0a 20 20 20 20 20 20 74 65 73 ' ' );. tes
1380: 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 5c 74 tcase( z[0]=='\t
1390: 27 20 29 3b 0a 20 20 20 20 20 20 74 65 73 74 63 ' );. testc
13a0: 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 5c 6e 27 20 ase( z[0]=='\n'
13b0: 29 3b 0a 20 20 20 20 20 20 74 65 73 74 63 61 73 );. testcas
13c0: 65 28 20 7a 5b 30 5d 3d 3d 27 5c 66 27 20 29 3b e( z[0]=='\f' );
13d0: 0a 20 20 20 20 20 20 74 65 73 74 63 61 73 65 28 . testcase(
13e0: 20 7a 5b 30 5d 3d 3d 27 5c 72 27 20 29 3b 0a 20 z[0]=='\r' );.
13f0: 20 20 20 20 20 66 6f 72 28 69 3d 31 3b 20 73 71 for(i=1; sq
1400: 6c 69 74 65 33 49 73 73 70 61 63 65 28 7a 5b 69 lite3Isspace(z[i
1410: 5d 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 ]); i++){}.
1420: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
1430: 5f 53 50 41 43 45 3b 0a 20 20 20 20 20 20 72 65 _SPACE;. re
1440: 74 75 72 6e 20 69 3b 0a 20 20 20 20 7d 0a 20 20 turn i;. }.
1450: 20 20 63 61 73 65 20 27 2d 27 3a 20 7b 0a 20 20 case '-': {.
1460: 20 20 20 20 69 66 28 20 7a 5b 31 5d 3d 3d 27 2d if( z[1]=='-
1470: 27 20 29 7b 0a 20 20 20 20 20 20 20 20 66 6f 72 ' ){. for
1480: 28 69 3d 32 3b 20 28 63 3d 7a 5b 69 5d 29 21 3d (i=2; (c=z[i])!=
1490: 30 20 26 26 20 63 21 3d 27 5c 6e 27 3b 20 69 2b 0 && c!='\n'; i+
14a0: 2b 29 7b 7d 0a 20 20 20 20 20 20 20 20 2a 74 6f +){}. *to
14b0: 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 53 50 41 kenType = TK_SPA
14c0: 43 45 3b 20 20 20 2f 2a 20 49 4d 50 3a 20 52 2d CE; /* IMP: R-
14d0: 32 32 39 33 34 2d 32 35 31 33 34 20 2a 2f 0a 20 22934-25134 */.
14e0: 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b return i;
14f0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 2a . }. *
1500: 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4d tokenType = TK_M
1510: 49 4e 55 53 3b 0a 20 20 20 20 20 20 72 65 74 75 INUS;. retu
1520: 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 rn 1;. }.
1530: 63 61 73 65 20 27 28 27 3a 20 7b 0a 20 20 20 20 case '(': {.
1540: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
1550: 4b 5f 4c 50 3b 0a 20 20 20 20 20 20 72 65 74 75 K_LP;. retu
1560: 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 rn 1;. }.
1570: 63 61 73 65 20 27 29 27 3a 20 7b 0a 20 20 20 20 case ')': {.
1580: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
1590: 4b 5f 52 50 3b 0a 20 20 20 20 20 20 72 65 74 75 K_RP;. retu
15a0: 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 rn 1;. }.
15b0: 63 61 73 65 20 27 3b 27 3a 20 7b 0a 20 20 20 20 case ';': {.
15c0: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
15d0: 4b 5f 53 45 4d 49 3b 0a 20 20 20 20 20 20 72 65 K_SEMI;. re
15e0: 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a 20 20 turn 1;. }.
15f0: 20 20 63 61 73 65 20 27 2b 27 3a 20 7b 0a 20 20 case '+': {.
1600: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
1610: 20 54 4b 5f 50 4c 55 53 3b 0a 20 20 20 20 20 20 TK_PLUS;.
1620: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a return 1;. }.
1630: 20 20 20 20 63 61 73 65 20 27 2a 27 3a 20 7b 0a case '*': {.
1640: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
1650: 20 3d 20 54 4b 5f 53 54 41 52 3b 0a 20 20 20 20 = TK_STAR;.
1660: 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 return 1;.
1670: 7d 0a 20 20 20 20 63 61 73 65 20 27 2f 27 3a 20 }. case '/':
1680: 7b 0a 20 20 20 20 20 20 69 66 28 20 7a 5b 31 5d {. if( z[1]
1690: 21 3d 27 2a 27 20 7c 7c 20 7a 5b 32 5d 3d 3d 30 !='*' || z[2]==0
16a0: 20 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b ){. *tok
16b0: 65 6e 54 79 70 65 20 3d 20 54 4b 5f 53 4c 41 53 enType = TK_SLAS
16c0: 48 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 H;. retur
16d0: 6e 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 n 1;. }.
16e0: 20 20 20 66 6f 72 28 69 3d 33 2c 20 63 3d 7a 5b for(i=3, c=z[
16f0: 32 5d 3b 20 28 63 21 3d 27 2a 27 20 7c 7c 20 7a 2]; (c!='*' || z
1700: 5b 69 5d 21 3d 27 2f 27 29 20 26 26 20 28 63 3d [i]!='/') && (c=
1710: 7a 5b 69 5d 29 21 3d 30 3b 20 69 2b 2b 29 7b 7d z[i])!=0; i++){}
1720: 0a 20 20 20 20 20 20 69 66 28 20 63 20 29 20 69 . if( c ) i
1730: 2b 2b 3b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e ++;. *token
1740: 54 79 70 65 20 3d 20 54 4b 5f 53 50 41 43 45 3b Type = TK_SPACE;
1750: 20 20 20 2f 2a 20 49 4d 50 3a 20 52 2d 32 32 39 /* IMP: R-229
1760: 33 34 2d 32 35 31 33 34 20 2a 2f 0a 20 20 20 20 34-25134 */.
1770: 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 return i;.
1780: 7d 0a 20 20 20 20 63 61 73 65 20 27 25 27 3a 20 }. case '%':
1790: 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 {. *tokenTy
17a0: 70 65 20 3d 20 54 4b 5f 52 45 4d 3b 0a 20 20 20 pe = TK_REM;.
17b0: 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 return 1;.
17c0: 20 7d 0a 20 20 20 20 63 61 73 65 20 27 3d 27 3a }. case '=':
17d0: 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 {. *tokenT
17e0: 79 70 65 20 3d 20 54 4b 5f 45 51 3b 0a 20 20 20 ype = TK_EQ;.
17f0: 20 20 20 72 65 74 75 72 6e 20 31 20 2b 20 28 7a return 1 + (z
1800: 5b 31 5d 3d 3d 27 3d 27 29 3b 0a 20 20 20 20 7d [1]=='=');. }
1810: 0a 20 20 20 20 63 61 73 65 20 27 3c 27 3a 20 7b . case '<': {
1820: 0a 20 20 20 20 20 20 69 66 28 20 28 63 3d 7a 5b . if( (c=z[
1830: 31 5d 29 3d 3d 27 3d 27 20 29 7b 0a 20 20 20 20 1])=='=' ){.
1840: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
1850: 20 54 4b 5f 4c 45 3b 0a 20 20 20 20 20 20 20 20 TK_LE;.
1860: 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 20 20 return 2;.
1870: 7d 65 6c 73 65 20 69 66 28 20 63 3d 3d 27 3e 27 }else if( c=='>'
1880: 20 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b ){. *tok
1890: 65 6e 54 79 70 65 20 3d 20 54 4b 5f 4e 45 3b 0a enType = TK_NE;.
18a0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 return 2
18b0: 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 ;. }else if
18c0: 28 20 63 3d 3d 27 3c 27 20 29 7b 0a 20 20 20 20 ( c=='<' ){.
18d0: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
18e0: 20 54 4b 5f 4c 53 48 49 46 54 3b 0a 20 20 20 20 TK_LSHIFT;.
18f0: 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 return 2;.
1900: 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 }else{.
1910: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
1920: 54 4b 5f 4c 54 3b 0a 20 20 20 20 20 20 20 20 72 TK_LT;. r
1930: 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 7d eturn 1;. }
1940: 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 . }. case
1950: 27 3e 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 '>': {. if(
1960: 20 28 63 3d 7a 5b 31 5d 29 3d 3d 27 3d 27 20 29 (c=z[1])=='=' )
1970: 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e {. *token
1980: 54 79 70 65 20 3d 20 54 4b 5f 47 45 3b 0a 20 20 Type = TK_GE;.
1990: 20 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a return 2;.
19a0: 20 20 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 }else if(
19b0: 63 3d 3d 27 3e 27 20 29 7b 0a 20 20 20 20 20 20 c=='>' ){.
19c0: 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 *tokenType = T
19d0: 4b 5f 52 53 48 49 46 54 3b 0a 20 20 20 20 20 20 K_RSHIFT;.
19e0: 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 return 2;.
19f0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 20 }else{.
1a00: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
1a10: 5f 47 54 3b 0a 20 20 20 20 20 20 20 20 72 65 74 _GT;. ret
1a20: 75 72 6e 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 urn 1;. }.
1a30: 20 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 21 }. case '!
1a40: 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 20 7a ': {. if( z
1a50: 5b 31 5d 21 3d 27 3d 27 20 29 7b 0a 20 20 20 20 [1]!='=' ){.
1a60: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
1a70: 20 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 20 20 TK_ILLEGAL;.
1a80: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
1a90: 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 }else{.
1aa0: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
1ab0: 20 54 4b 5f 4e 45 3b 0a 20 20 20 20 20 20 20 20 TK_NE;.
1ac0: 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 20 20 return 2;.
1ad0: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 }. }. case
1ae0: 20 27 7c 27 3a 20 7b 0a 20 20 20 20 20 20 69 66 '|': {. if
1af0: 28 20 7a 5b 31 5d 21 3d 27 7c 27 20 29 7b 0a 20 ( z[1]!='|' ){.
1b00: 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 *tokenTyp
1b10: 65 20 3d 20 54 4b 5f 42 49 54 4f 52 3b 0a 20 20 e = TK_BITOR;.
1b20: 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a return 1;.
1b30: 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 }else{.
1b40: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
1b50: 3d 20 54 4b 5f 43 4f 4e 43 41 54 3b 0a 20 20 20 = TK_CONCAT;.
1b60: 20 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 20 return 2;.
1b70: 20 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 20 }. }.
1b80: 20 63 61 73 65 20 27 2c 27 3a 20 7b 0a 20 20 20 case ',': {.
1b90: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
1ba0: 54 4b 5f 43 4f 4d 4d 41 3b 0a 20 20 20 20 20 20 TK_COMMA;.
1bb0: 72 65 74 75 72 6e 20 31 3b 0a 20 20 20 20 7d 0a return 1;. }.
1bc0: 20 20 20 20 63 61 73 65 20 27 26 27 3a 20 7b 0a case '&': {.
1bd0: 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 *tokenType
1be0: 20 3d 20 54 4b 5f 42 49 54 41 4e 44 3b 0a 20 20 = TK_BITAND;.
1bf0: 20 20 20 20 72 65 74 75 72 6e 20 31 3b 0a 20 20 return 1;.
1c00: 20 20 7d 0a 20 20 20 20 63 61 73 65 20 27 7e 27 }. case '~'
1c10: 3a 20 7b 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e : {. *token
1c20: 54 79 70 65 20 3d 20 54 4b 5f 42 49 54 4e 4f 54 Type = TK_BITNOT
1c30: 3b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 31 ;. return 1
1c40: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 73 65 ;. }. case
1c50: 20 27 60 27 3a 0a 20 20 20 20 63 61 73 65 20 27 '`':. case '
1c60: 5c 27 27 3a 0a 20 20 20 20 63 61 73 65 20 27 22 \'':. case '"
1c70: 27 3a 20 7b 0a 20 20 20 20 20 20 69 6e 74 20 64 ': {. int d
1c80: 65 6c 69 6d 20 3d 20 7a 5b 30 5d 3b 0a 20 20 20 elim = z[0];.
1c90: 20 20 20 74 65 73 74 63 61 73 65 28 20 64 65 6c testcase( del
1ca0: 69 6d 3d 3d 27 60 27 20 29 3b 0a 20 20 20 20 20 im=='`' );.
1cb0: 20 74 65 73 74 63 61 73 65 28 20 64 65 6c 69 6d testcase( delim
1cc0: 3d 3d 27 5c 27 27 20 29 3b 0a 20 20 20 20 20 20 =='\'' );.
1cd0: 74 65 73 74 63 61 73 65 28 20 64 65 6c 69 6d 3d testcase( delim=
1ce0: 3d 27 22 27 20 29 3b 0a 20 20 20 20 20 20 66 6f ='"' );. fo
1cf0: 72 28 69 3d 31 3b 20 28 63 3d 7a 5b 69 5d 29 21 r(i=1; (c=z[i])!
1d00: 3d 30 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 =0; i++){.
1d10: 20 20 69 66 28 20 63 3d 3d 64 65 6c 69 6d 20 29 if( c==delim )
1d20: 7b 0a 20 20 20 20 20 20 20 20 20 20 69 66 28 20 {. if(
1d30: 7a 5b 69 2b 31 5d 3d 3d 64 65 6c 69 6d 20 29 7b z[i+1]==delim ){
1d40: 0a 20 20 20 20 20 20 20 20 20 20 20 20 69 2b 2b . i++
1d50: 3b 0a 20 20 20 20 20 20 20 20 20 20 7d 65 6c 73 ;. }els
1d60: 65 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 62 e{. b
1d70: 72 65 61 6b 3b 0a 20 20 20 20 20 20 20 20 20 20 reak;.
1d80: 7d 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 20 }. }.
1d90: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 63 3d }. if( c=
1da0: 3d 27 5c 27 27 20 29 7b 0a 20 20 20 20 20 20 20 ='\'' ){.
1db0: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
1dc0: 5f 53 54 52 49 4e 47 3b 0a 20 20 20 20 20 20 20 _STRING;.
1dd0: 20 72 65 74 75 72 6e 20 69 2b 31 3b 0a 20 20 20 return i+1;.
1de0: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 63 21 3d }else if( c!=
1df0: 30 20 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 0 ){. *to
1e00: 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 49 44 3b kenType = TK_ID;
1e10: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 20 . return
1e20: 69 2b 31 3b 0a 20 20 20 20 20 20 7d 65 6c 73 65 i+1;. }else
1e30: 7b 0a 20 20 20 20 20 20 20 20 2a 74 6f 6b 65 6e {. *token
1e40: 54 79 70 65 20 3d 20 54 4b 5f 49 4c 4c 45 47 41 Type = TK_ILLEGA
1e50: 4c 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 L;. retur
1e60: 6e 20 69 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 n i;. }.
1e70: 20 7d 0a 20 20 20 20 63 61 73 65 20 27 2e 27 3a }. case '.':
1e80: 20 7b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 {.#ifndef SQLIT
1e90: 45 5f 4f 4d 49 54 5f 46 4c 4f 41 54 49 4e 47 5f E_OMIT_FLOATING_
1ea0: 50 4f 49 4e 54 0a 20 20 20 20 20 20 69 66 28 20 POINT. if(
1eb0: 21 73 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 !sqlite3Isdigit(
1ec0: 7a 5b 31 5d 29 20 29 0a 23 65 6e 64 69 66 0a 20 z[1]) ).#endif.
1ed0: 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20 20 2a {. *
1ee0: 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 44 tokenType = TK_D
1ef0: 4f 54 3b 0a 20 20 20 20 20 20 20 20 72 65 74 75 OT;. retu
1f00: 72 6e 20 31 3b 0a 20 20 20 20 20 20 7d 0a 20 20 rn 1;. }.
1f10: 20 20 20 20 2f 2a 20 49 66 20 74 68 65 20 6e 65 /* If the ne
1f20: 78 74 20 63 68 61 72 61 63 74 65 72 20 69 73 20 xt character is
1f30: 61 20 64 69 67 69 74 2c 20 74 68 69 73 20 69 73 a digit, this is
1f40: 20 61 20 66 6c 6f 61 74 69 6e 67 20 70 6f 69 6e a floating poin
1f50: 74 0a 20 20 20 20 20 20 2a 2a 20 6e 75 6d 62 65 t. ** numbe
1f60: 72 20 74 68 61 74 20 62 65 67 69 6e 73 20 77 69 r that begins wi
1f70: 74 68 20 22 2e 22 2e 20 20 46 61 6c 6c 20 74 68 th ".". Fall th
1f80: 72 75 20 69 6e 74 6f 20 74 68 65 20 6e 65 78 74 ru into the next
1f90: 20 63 61 73 65 20 2a 2f 0a 20 20 20 20 7d 0a 20 case */. }.
1fa0: 20 20 20 63 61 73 65 20 27 30 27 3a 20 63 61 73 case '0': cas
1fb0: 65 20 27 31 27 3a 20 63 61 73 65 20 27 32 27 3a e '1': case '2':
1fc0: 20 63 61 73 65 20 27 33 27 3a 20 63 61 73 65 20 case '3': case
1fd0: 27 34 27 3a 0a 20 20 20 20 63 61 73 65 20 27 35 '4':. case '5
1fe0: 27 3a 20 63 61 73 65 20 27 36 27 3a 20 63 61 73 ': case '6': cas
1ff0: 65 20 27 37 27 3a 20 63 61 73 65 20 27 38 27 3a e '7': case '8':
2000: 20 63 61 73 65 20 27 39 27 3a 20 7b 0a 20 20 20 case '9': {.
2010: 20 20 20 74 65 73 74 63 61 73 65 28 20 7a 5b 30 testcase( z[0
2020: 5d 3d 3d 27 30 27 20 29 3b 20 20 74 65 73 74 63 ]=='0' ); testc
2030: 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 31 27 20 29 ase( z[0]=='1' )
2040: 3b 20 20 74 65 73 74 63 61 73 65 28 20 7a 5b 30 ; testcase( z[0
2050: 5d 3d 3d 27 32 27 20 29 3b 0a 20 20 20 20 20 20 ]=='2' );.
2060: 74 65 73 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d testcase( z[0]==
2070: 27 33 27 20 29 3b 20 20 74 65 73 74 63 61 73 65 '3' ); testcase
2080: 28 20 7a 5b 30 5d 3d 3d 27 34 27 20 29 3b 20 20 ( z[0]=='4' );
2090: 74 65 73 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d testcase( z[0]==
20a0: 27 35 27 20 29 3b 0a 20 20 20 20 20 20 74 65 73 '5' );. tes
20b0: 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 36 27 tcase( z[0]=='6'
20c0: 20 29 3b 20 20 74 65 73 74 63 61 73 65 28 20 7a ); testcase( z
20d0: 5b 30 5d 3d 3d 27 37 27 20 29 3b 20 20 74 65 73 [0]=='7' ); tes
20e0: 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 38 27 tcase( z[0]=='8'
20f0: 20 29 3b 0a 20 20 20 20 20 20 74 65 73 74 63 61 );. testca
2100: 73 65 28 20 7a 5b 30 5d 3d 3d 27 39 27 20 29 3b se( z[0]=='9' );
2110: 0a 20 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 . *tokenTyp
2120: 65 20 3d 20 54 4b 5f 49 4e 54 45 47 45 52 3b 0a e = TK_INTEGER;.
2130: 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f #ifndef SQLITE_O
2140: 4d 49 54 5f 48 45 58 5f 49 4e 54 45 47 45 52 0a MIT_HEX_INTEGER.
2150: 20 20 20 20 20 20 69 66 28 20 7a 5b 30 5d 3d 3d if( z[0]==
2160: 27 30 27 20 26 26 20 28 7a 5b 31 5d 3d 3d 27 78 '0' && (z[1]=='x
2170: 27 20 7c 7c 20 7a 5b 31 5d 3d 3d 27 58 27 29 20 ' || z[1]=='X')
2180: 26 26 20 73 71 6c 69 74 65 33 49 73 78 64 69 67 && sqlite3Isxdig
2190: 69 74 28 7a 5b 32 5d 29 20 29 7b 0a 20 20 20 20 it(z[2]) ){.
21a0: 20 20 20 20 66 6f 72 28 69 3d 33 3b 20 73 71 6c for(i=3; sql
21b0: 69 74 65 33 49 73 78 64 69 67 69 74 28 7a 5b 69 ite3Isxdigit(z[i
21c0: 5d 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 ]); i++){}.
21d0: 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 return i;.
21e0: 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20 20 20 }.#endif.
21f0: 20 20 66 6f 72 28 69 3d 30 3b 20 73 71 6c 69 74 for(i=0; sqlit
2200: 65 33 49 73 64 69 67 69 74 28 7a 5b 69 5d 29 3b e3Isdigit(z[i]);
2210: 20 69 2b 2b 29 7b 7d 0a 23 69 66 6e 64 65 66 20 i++){}.#ifndef
2220: 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 46 4c 4f 41 SQLITE_OMIT_FLOA
2230: 54 49 4e 47 5f 50 4f 49 4e 54 0a 20 20 20 20 20 TING_POINT.
2240: 20 69 66 28 20 7a 5b 69 5d 3d 3d 27 2e 27 20 29 if( z[i]=='.' )
2250: 7b 0a 20 20 20 20 20 20 20 20 69 2b 2b 3b 0a 20 {. i++;.
2260: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 73 71 while( sq
2270: 6c 69 74 65 33 49 73 64 69 67 69 74 28 7a 5b 69 lite3Isdigit(z[i
2280: 5d 29 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 20 ]) ){ i++; }.
2290: 20 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 *tokenType
22a0: 3d 20 54 4b 5f 46 4c 4f 41 54 3b 0a 20 20 20 20 = TK_FLOAT;.
22b0: 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 28 7a }. if( (z
22c0: 5b 69 5d 3d 3d 27 65 27 20 7c 7c 20 7a 5b 69 5d [i]=='e' || z[i]
22d0: 3d 3d 27 45 27 29 20 26 26 0a 20 20 20 20 20 20 =='E') &&.
22e0: 20 20 20 20 20 28 20 73 71 6c 69 74 65 33 49 73 ( sqlite3Is
22f0: 64 69 67 69 74 28 7a 5b 69 2b 31 5d 29 20 0a 20 digit(z[i+1]) .
2300: 20 20 20 20 20 20 20 20 20 20 20 7c 7c 20 28 28 || ((
2310: 7a 5b 69 2b 31 5d 3d 3d 27 2b 27 20 7c 7c 20 7a z[i+1]=='+' || z
2320: 5b 69 2b 31 5d 3d 3d 27 2d 27 29 20 26 26 20 73 [i+1]=='-') && s
2330: 71 6c 69 74 65 33 49 73 64 69 67 69 74 28 7a 5b qlite3Isdigit(z[
2340: 69 2b 32 5d 29 29 0a 20 20 20 20 20 20 20 20 20 i+2])).
2350: 20 20 29 0a 20 20 20 20 20 20 29 7b 0a 20 20 20 ). ){.
2360: 20 20 20 20 20 69 20 2b 3d 20 32 3b 0a 20 20 20 i += 2;.
2370: 20 20 20 20 20 77 68 69 6c 65 28 20 73 71 6c 69 while( sqli
2380: 74 65 33 49 73 64 69 67 69 74 28 7a 5b 69 5d 29 te3Isdigit(z[i])
2390: 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 20 20 20 ){ i++; }.
23a0: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
23b0: 54 4b 5f 46 4c 4f 41 54 3b 0a 20 20 20 20 20 20 TK_FLOAT;.
23c0: 7d 0a 23 65 6e 64 69 66 0a 20 20 20 20 20 20 77 }.#endif. w
23d0: 68 69 6c 65 28 20 49 64 43 68 61 72 28 7a 5b 69 hile( IdChar(z[i
23e0: 5d 29 20 29 7b 0a 20 20 20 20 20 20 20 20 2a 74 ]) ){. *t
23f0: 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 49 4c okenType = TK_IL
2400: 4c 45 47 41 4c 3b 0a 20 20 20 20 20 20 20 20 69 LEGAL;. i
2410: 2b 2b 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 ++;. }.
2420: 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 return i;.
2430: 7d 0a 20 20 20 20 63 61 73 65 20 27 5b 27 3a 20 }. case '[':
2440: 7b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 31 2c {. for(i=1,
2450: 20 63 3d 7a 5b 30 5d 3b 20 63 21 3d 27 5d 27 20 c=z[0]; c!=']'
2460: 26 26 20 28 63 3d 7a 5b 69 5d 29 21 3d 30 3b 20 && (c=z[i])!=0;
2470: 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 2a 74 6f i++){}. *to
2480: 6b 65 6e 54 79 70 65 20 3d 20 63 3d 3d 27 5d 27 kenType = c==']'
2490: 20 3f 20 54 4b 5f 49 44 20 3a 20 54 4b 5f 49 4c ? TK_ID : TK_IL
24a0: 4c 45 47 41 4c 3b 0a 20 20 20 20 20 20 72 65 74 LEGAL;. ret
24b0: 75 72 6e 20 69 3b 0a 20 20 20 20 7d 0a 20 20 20 urn i;. }.
24c0: 20 63 61 73 65 20 27 3f 27 3a 20 7b 0a 20 20 20 case '?': {.
24d0: 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 *tokenType =
24e0: 54 4b 5f 56 41 52 49 41 42 4c 45 3b 0a 20 20 20 TK_VARIABLE;.
24f0: 20 20 20 66 6f 72 28 69 3d 31 3b 20 73 71 6c 69 for(i=1; sqli
2500: 74 65 33 49 73 64 69 67 69 74 28 7a 5b 69 5d 29 te3Isdigit(z[i])
2510: 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 72 ; i++){}. r
2520: 65 74 75 72 6e 20 69 3b 0a 20 20 20 20 7d 0a 23 eturn i;. }.#
2530: 69 66 6e 64 65 66 20 53 51 4c 49 54 45 5f 4f 4d ifndef SQLITE_OM
2540: 49 54 5f 54 43 4c 5f 56 41 52 49 41 42 4c 45 0a IT_TCL_VARIABLE.
2550: 20 20 20 20 63 61 73 65 20 27 24 27 3a 0a 23 65 case '$':.#e
2560: 6e 64 69 66 0a 20 20 20 20 63 61 73 65 20 27 40 ndif. case '@
2570: 27 3a 20 20 2f 2a 20 46 6f 72 20 63 6f 6d 70 61 ': /* For compa
2580: 74 69 62 69 6c 69 74 79 20 77 69 74 68 20 4d 53 tibility with MS
2590: 20 53 51 4c 20 53 65 72 76 65 72 20 2a 2f 0a 20 SQL Server */.
25a0: 20 20 20 63 61 73 65 20 27 23 27 3a 0a 20 20 20 case '#':.
25b0: 20 63 61 73 65 20 27 3a 27 3a 20 7b 0a 20 20 20 case ':': {.
25c0: 20 20 20 69 6e 74 20 6e 20 3d 20 30 3b 0a 20 20 int n = 0;.
25d0: 20 20 20 20 74 65 73 74 63 61 73 65 28 20 7a 5b testcase( z[
25e0: 30 5d 3d 3d 27 24 27 20 29 3b 20 20 74 65 73 74 0]=='$' ); test
25f0: 63 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 40 27 20 case( z[0]=='@'
2600: 29 3b 0a 20 20 20 20 20 20 74 65 73 74 63 61 73 );. testcas
2610: 65 28 20 7a 5b 30 5d 3d 3d 27 3a 27 20 29 3b 20 e( z[0]==':' );
2620: 20 74 65 73 74 63 61 73 65 28 20 7a 5b 30 5d 3d testcase( z[0]=
2630: 3d 27 23 27 20 29 3b 0a 20 20 20 20 20 20 2a 74 ='#' );. *t
2640: 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b 5f 56 41 okenType = TK_VA
2650: 52 49 41 42 4c 45 3b 0a 20 20 20 20 20 20 66 6f RIABLE;. fo
2660: 72 28 69 3d 31 3b 20 28 63 3d 7a 5b 69 5d 29 21 r(i=1; (c=z[i])!
2670: 3d 30 3b 20 69 2b 2b 29 7b 0a 20 20 20 20 20 20 =0; i++){.
2680: 20 20 69 66 28 20 49 64 43 68 61 72 28 63 29 20 if( IdChar(c)
2690: 29 7b 0a 20 20 20 20 20 20 20 20 20 20 6e 2b 2b ){. n++
26a0: 3b 0a 23 69 66 6e 64 65 66 20 53 51 4c 49 54 45 ;.#ifndef SQLITE
26b0: 5f 4f 4d 49 54 5f 54 43 4c 5f 56 41 52 49 41 42 _OMIT_TCL_VARIAB
26c0: 4c 45 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 LE. }else
26d0: 20 69 66 28 20 63 3d 3d 27 28 27 20 26 26 20 6e if( c=='(' && n
26e0: 3e 30 20 29 7b 0a 20 20 20 20 20 20 20 20 20 20 >0 ){.
26f0: 64 6f 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 do{.
2700: 69 2b 2b 3b 0a 20 20 20 20 20 20 20 20 20 20 7d i++;. }
2710: 77 68 69 6c 65 28 20 28 63 3d 7a 5b 69 5d 29 21 while( (c=z[i])!
2720: 3d 30 20 26 26 20 21 73 71 6c 69 74 65 33 49 73 =0 && !sqlite3Is
2730: 73 70 61 63 65 28 63 29 20 26 26 20 63 21 3d 27 space(c) && c!='
2740: 29 27 20 29 3b 0a 20 20 20 20 20 20 20 20 20 20 )' );.
2750: 69 66 28 20 63 3d 3d 27 29 27 20 29 7b 0a 20 20 if( c==')' ){.
2760: 20 20 20 20 20 20 20 20 20 20 69 2b 2b 3b 0a 20 i++;.
2770: 20 20 20 20 20 20 20 20 20 7d 65 6c 73 65 7b 0a }else{.
2780: 20 20 20 20 20 20 20 20 20 20 20 20 2a 74 6f 6b *tok
2790: 65 6e 54 79 70 65 20 3d 20 54 4b 5f 49 4c 4c 45 enType = TK_ILLE
27a0: 47 41 4c 3b 0a 20 20 20 20 20 20 20 20 20 20 7d GAL;. }
27b0: 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 6b . break
27c0: 3b 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 20 ;. }else
27d0: 69 66 28 20 63 3d 3d 27 3a 27 20 26 26 20 7a 5b if( c==':' && z[
27e0: 69 2b 31 5d 3d 3d 27 3a 27 20 29 7b 0a 20 20 20 i+1]==':' ){.
27f0: 20 20 20 20 20 20 20 69 2b 2b 3b 0a 23 65 6e 64 i++;.#end
2800: 69 66 0a 20 20 20 20 20 20 20 20 7d 65 6c 73 65 if. }else
2810: 7b 0a 20 20 20 20 20 20 20 20 20 20 62 72 65 61 {. brea
2820: 6b 3b 0a 20 20 20 20 20 20 20 20 7d 0a 20 20 20 k;. }.
2830: 20 20 20 7d 0a 20 20 20 20 20 20 69 66 28 20 6e }. if( n
2840: 3d 3d 30 20 29 20 2a 74 6f 6b 65 6e 54 79 70 65 ==0 ) *tokenType
2850: 20 3d 20 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 = TK_ILLEGAL;.
2860: 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 return i;.
2870: 20 20 20 7d 0a 23 69 66 6e 64 65 66 20 53 51 4c }.#ifndef SQL
2880: 49 54 45 5f 4f 4d 49 54 5f 42 4c 4f 42 5f 4c 49 ITE_OMIT_BLOB_LI
2890: 54 45 52 41 4c 0a 20 20 20 20 63 61 73 65 20 27 TERAL. case '
28a0: 78 27 3a 20 63 61 73 65 20 27 58 27 3a 20 7b 0a x': case 'X': {.
28b0: 20 20 20 20 20 20 74 65 73 74 63 61 73 65 28 20 testcase(
28c0: 7a 5b 30 5d 3d 3d 27 78 27 20 29 3b 20 74 65 73 z[0]=='x' ); tes
28d0: 74 63 61 73 65 28 20 7a 5b 30 5d 3d 3d 27 58 27 tcase( z[0]=='X'
28e0: 20 29 3b 0a 20 20 20 20 20 20 69 66 28 20 7a 5b );. if( z[
28f0: 31 5d 3d 3d 27 5c 27 27 20 29 7b 0a 20 20 20 20 1]=='\'' ){.
2900: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2910: 20 54 4b 5f 42 4c 4f 42 3b 0a 20 20 20 20 20 20 TK_BLOB;.
2920: 20 20 66 6f 72 28 69 3d 32 3b 20 73 71 6c 69 74 for(i=2; sqlit
2930: 65 33 49 73 78 64 69 67 69 74 28 7a 5b 69 5d 29 e3Isxdigit(z[i])
2940: 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 20 20 ; i++){}.
2950: 20 69 66 28 20 7a 5b 69 5d 21 3d 27 5c 27 27 20 if( z[i]!='\''
2960: 7c 7c 20 69 25 32 20 29 7b 0a 20 20 20 20 20 20 || i%2 ){.
2970: 20 20 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d *tokenType =
2980: 20 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 20 20 TK_ILLEGAL;.
2990: 20 20 20 20 20 20 20 77 68 69 6c 65 28 20 7a 5b while( z[
29a0: 69 5d 20 26 26 20 7a 5b 69 5d 21 3d 27 5c 27 27 i] && z[i]!='\''
29b0: 20 29 7b 20 69 2b 2b 3b 20 7d 0a 20 20 20 20 20 ){ i++; }.
29c0: 20 20 20 7d 0a 20 20 20 20 20 20 20 20 69 66 28 }. if(
29d0: 20 7a 5b 69 5d 20 29 20 69 2b 2b 3b 0a 20 20 20 z[i] ) i++;.
29e0: 20 20 20 20 20 72 65 74 75 72 6e 20 69 3b 0a 20 return i;.
29f0: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 2f 2a 20 }. /*
2a00: 4f 74 68 65 72 77 69 73 65 20 66 61 6c 6c 20 74 Otherwise fall t
2a10: 68 72 6f 75 67 68 20 74 6f 20 74 68 65 20 6e 65 hrough to the ne
2a20: 78 74 20 63 61 73 65 20 2a 2f 0a 20 20 20 20 7d xt case */. }
2a30: 0a 23 65 6e 64 69 66 0a 20 20 20 20 64 65 66 61 .#endif. defa
2a40: 75 6c 74 3a 20 7b 0a 20 20 20 20 20 20 69 66 28 ult: {. if(
2a50: 20 21 49 64 43 68 61 72 28 2a 7a 29 20 29 7b 0a !IdChar(*z) ){.
2a60: 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 break;.
2a70: 20 20 20 20 20 7d 0a 20 20 20 20 20 20 66 6f 72 }. for
2a80: 28 69 3d 31 3b 20 49 64 43 68 61 72 28 7a 5b 69 (i=1; IdChar(z[i
2a90: 5d 29 3b 20 69 2b 2b 29 7b 7d 0a 20 20 20 20 20 ]); i++){}.
2aa0: 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 54 4b *tokenType = TK
2ab0: 5f 49 44 3b 0a 20 20 20 20 20 20 72 65 74 75 72 _ID;. retur
2ac0: 6e 20 6b 65 79 77 6f 72 64 43 6f 64 65 28 28 63 n keywordCode((c
2ad0: 68 61 72 2a 29 7a 2c 20 69 2c 20 74 6f 6b 65 6e har*)z, i, token
2ae0: 54 79 70 65 29 3b 0a 20 20 20 20 7d 0a 20 20 7d Type);. }. }
2af0: 0a 20 20 2a 74 6f 6b 65 6e 54 79 70 65 20 3d 20 . *tokenType =
2b00: 54 4b 5f 49 4c 4c 45 47 41 4c 3b 0a 20 20 72 65 TK_ILLEGAL;. re
2b10: 74 75 72 6e 20 31 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a turn 1;.}../*.**
2b20: 20 52 75 6e 20 74 68 65 20 70 61 72 73 65 72 20 Run the parser
2b30: 6f 6e 20 74 68 65 20 67 69 76 65 6e 20 53 51 4c on the given SQL
2b40: 20 73 74 72 69 6e 67 2e 20 20 54 68 65 20 70 61 string. The pa
2b50: 72 73 65 72 20 73 74 72 75 63 74 75 72 65 20 69 rser structure i
2b60: 73 0a 2a 2a 20 70 61 73 73 65 64 20 69 6e 2e 20 s.** passed in.
2b70: 20 41 6e 20 53 51 4c 49 54 45 5f 20 73 74 61 74 An SQLITE_ stat
2b80: 75 73 20 63 6f 64 65 20 69 73 20 72 65 74 75 72 us code is retur
2b90: 6e 65 64 2e 20 20 49 66 20 61 6e 20 65 72 72 6f ned. If an erro
2ba0: 72 20 6f 63 63 75 72 73 0a 2a 2a 20 74 68 65 6e r occurs.** then
2bb0: 20 61 6e 20 61 6e 64 20 61 74 74 65 6d 70 74 20 an and attempt
2bc0: 69 73 20 6d 61 64 65 20 74 6f 20 77 72 69 74 65 is made to write
2bd0: 20 61 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 an error messag
2be0: 65 20 69 6e 74 6f 20 0a 2a 2a 20 6d 65 6d 6f 72 e into .** memor
2bf0: 79 20 6f 62 74 61 69 6e 65 64 20 66 72 6f 6d 20 y obtained from
2c00: 73 71 6c 69 74 65 33 5f 6d 61 6c 6c 6f 63 28 29 sqlite3_malloc()
2c10: 20 61 6e 64 20 74 6f 20 6d 61 6b 65 20 2a 70 7a and to make *pz
2c20: 45 72 72 4d 73 67 20 70 6f 69 6e 74 20 74 6f 20 ErrMsg point to
2c30: 74 68 61 74 0a 2a 2a 20 65 72 72 6f 72 20 6d 65 that.** error me
2c40: 73 73 61 67 65 2e 0a 2a 2f 0a 69 6e 74 20 73 71 ssage..*/.int sq
2c50: 6c 69 74 65 33 52 75 6e 50 61 72 73 65 72 28 50 lite3RunParser(P
2c60: 61 72 73 65 20 2a 70 50 61 72 73 65 2c 20 63 6f arse *pParse, co
2c70: 6e 73 74 20 63 68 61 72 20 2a 7a 53 71 6c 2c 20 nst char *zSql,
2c80: 63 68 61 72 20 2a 2a 70 7a 45 72 72 4d 73 67 29 char **pzErrMsg)
2c90: 7b 0a 20 20 69 6e 74 20 6e 45 72 72 20 3d 20 30 {. int nErr = 0
2ca0: 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ;
2cb0: 20 20 20 20 2f 2a 20 4e 75 6d 62 65 72 20 6f 66 /* Number of
2cc0: 20 65 72 72 6f 72 73 20 65 6e 63 6f 75 6e 74 65 errors encounte
2cd0: 72 65 64 20 2a 2f 0a 20 20 69 6e 74 20 69 3b 20 red */. int i;
2ce0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
2cf0: 20 20 20 20 20 20 20 20 20 2f 2a 20 4c 6f 6f 70 /* Loop
2d00: 20 63 6f 75 6e 74 65 72 20 2a 2f 0a 20 20 76 6f counter */. vo
2d10: 69 64 20 2a 70 45 6e 67 69 6e 65 3b 20 20 20 20 id *pEngine;
2d20: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a /*
2d30: 20 54 68 65 20 4c 45 4d 4f 4e 2d 67 65 6e 65 72 The LEMON-gener
2d40: 61 74 65 64 20 4c 41 4c 52 28 31 29 20 70 61 72 ated LALR(1) par
2d50: 73 65 72 20 2a 2f 0a 20 20 69 6e 74 20 74 6f 6b ser */. int tok
2d60: 65 6e 54 79 70 65 3b 20 20 20 20 20 20 20 20 20 enType;
2d70: 20 20 20 20 20 20 20 20 20 2f 2a 20 74 79 70 65 /* type
2d80: 20 6f 66 20 74 68 65 20 6e 65 78 74 20 74 6f 6b of the next tok
2d90: 65 6e 20 2a 2f 0a 20 20 69 6e 74 20 6c 61 73 74 en */. int last
2da0: 54 6f 6b 65 6e 50 61 72 73 65 64 20 3d 20 2d 31 TokenParsed = -1
2db0: 3b 20 20 20 20 20 20 20 2f 2a 20 74 79 70 65 20 ; /* type
2dc0: 6f 66 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 of the previous
2dd0: 74 6f 6b 65 6e 20 2a 2f 0a 20 20 75 38 20 65 6e token */. u8 en
2de0: 61 62 6c 65 4c 6f 6f 6b 61 73 69 64 65 3b 20 20 ableLookaside;
2df0: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 53 61 /* Sa
2e00: 76 65 64 20 76 61 6c 75 65 20 6f 66 20 64 62 2d ved value of db-
2e10: 3e 6c 6f 6f 6b 61 73 69 64 65 2e 62 45 6e 61 62 >lookaside.bEnab
2e20: 6c 65 64 20 2a 2f 0a 20 20 73 71 6c 69 74 65 33 led */. sqlite3
2e30: 20 2a 64 62 20 3d 20 70 50 61 72 73 65 2d 3e 64 *db = pParse->d
2e40: 62 3b 20 20 20 20 20 20 20 2f 2a 20 54 68 65 20 b; /* The
2e50: 64 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 database connect
2e60: 69 6f 6e 20 2a 2f 0a 20 20 69 6e 74 20 6d 78 53 ion */. int mxS
2e70: 71 6c 4c 65 6e 3b 20 20 20 20 20 20 20 20 20 20 qlLen;
2e80: 20 20 20 20 20 20 20 20 20 2f 2a 20 4d 61 78 20 /* Max
2e90: 6c 65 6e 67 74 68 20 6f 66 20 61 6e 20 53 51 4c length of an SQL
2ea0: 20 73 74 72 69 6e 67 20 2a 2f 0a 0a 20 20 61 73 string */.. as
2eb0: 73 65 72 74 28 20 7a 53 71 6c 21 3d 30 20 29 3b sert( zSql!=0 );
2ec0: 0a 20 20 6d 78 53 71 6c 4c 65 6e 20 3d 20 64 62 . mxSqlLen = db
2ed0: 2d 3e 61 4c 69 6d 69 74 5b 53 51 4c 49 54 45 5f ->aLimit[SQLITE_
2ee0: 4c 49 4d 49 54 5f 53 51 4c 5f 4c 45 4e 47 54 48 LIMIT_SQL_LENGTH
2ef0: 5d 3b 0a 20 20 69 66 28 20 64 62 2d 3e 6e 56 64 ];. if( db->nVd
2f00: 62 65 41 63 74 69 76 65 3d 3d 30 20 29 7b 0a 20 beActive==0 ){.
2f10: 20 20 20 64 62 2d 3e 75 31 2e 69 73 49 6e 74 65 db->u1.isInte
2f20: 72 72 75 70 74 65 64 20 3d 20 30 3b 0a 20 20 7d rrupted = 0;. }
2f30: 0a 20 20 70 50 61 72 73 65 2d 3e 72 63 20 3d 20 . pParse->rc =
2f40: 53 51 4c 49 54 45 5f 4f 4b 3b 0a 20 20 70 50 61 SQLITE_OK;. pPa
2f50: 72 73 65 2d 3e 7a 54 61 69 6c 20 3d 20 7a 53 71 rse->zTail = zSq
2f60: 6c 3b 0a 20 20 69 20 3d 20 30 3b 0a 20 20 61 73 l;. i = 0;. as
2f70: 73 65 72 74 28 20 70 7a 45 72 72 4d 73 67 21 3d sert( pzErrMsg!=
2f80: 30 20 29 3b 0a 20 20 2f 2a 20 73 71 6c 69 74 65 0 );. /* sqlite
2f90: 33 50 61 72 73 65 72 54 72 61 63 65 28 73 74 64 3ParserTrace(std
2fa0: 6f 75 74 2c 20 22 70 61 72 73 65 72 3a 20 22 29 out, "parser: ")
2fb0: 3b 20 2a 2f 0a 20 20 70 45 6e 67 69 6e 65 20 3d ; */. pEngine =
2fc0: 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 41 6c sqlite3ParserAl
2fd0: 6c 6f 63 28 73 71 6c 69 74 65 33 4d 61 6c 6c 6f loc(sqlite3Mallo
2fe0: 63 29 3b 0a 20 20 69 66 28 20 70 45 6e 67 69 6e c);. if( pEngin
2ff0: 65 3d 3d 30 20 29 7b 0a 20 20 20 20 64 62 2d 3e e==0 ){. db->
3000: 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 20 3d 20 31 mallocFailed = 1
3010: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 53 51 4c ;. return SQL
3020: 49 54 45 5f 4e 4f 4d 45 4d 3b 0a 20 20 7d 0a 20 ITE_NOMEM;. }.
3030: 20 61 73 73 65 72 74 28 20 70 50 61 72 73 65 2d assert( pParse-
3040: 3e 70 4e 65 77 54 61 62 6c 65 3d 3d 30 20 29 3b >pNewTable==0 );
3050: 0a 20 20 61 73 73 65 72 74 28 20 70 50 61 72 73 . assert( pPars
3060: 65 2d 3e 70 4e 65 77 54 72 69 67 67 65 72 3d 3d e->pNewTrigger==
3070: 30 20 29 3b 0a 20 20 61 73 73 65 72 74 28 20 70 0 );. assert( p
3080: 50 61 72 73 65 2d 3e 6e 56 61 72 3d 3d 30 20 29 Parse->nVar==0 )
3090: 3b 0a 20 20 61 73 73 65 72 74 28 20 70 50 61 72 ;. assert( pPar
30a0: 73 65 2d 3e 6e 7a 56 61 72 3d 3d 30 20 29 3b 0a se->nzVar==0 );.
30b0: 20 20 61 73 73 65 72 74 28 20 70 50 61 72 73 65 assert( pParse
30c0: 2d 3e 61 7a 56 61 72 3d 3d 30 20 29 3b 0a 20 20 ->azVar==0 );.
30d0: 65 6e 61 62 6c 65 4c 6f 6f 6b 61 73 69 64 65 20 enableLookaside
30e0: 3d 20 64 62 2d 3e 6c 6f 6f 6b 61 73 69 64 65 2e = db->lookaside.
30f0: 62 45 6e 61 62 6c 65 64 3b 0a 20 20 69 66 28 20 bEnabled;. if(
3100: 64 62 2d 3e 6c 6f 6f 6b 61 73 69 64 65 2e 70 53 db->lookaside.pS
3110: 74 61 72 74 20 29 20 64 62 2d 3e 6c 6f 6f 6b 61 tart ) db->looka
3120: 73 69 64 65 2e 62 45 6e 61 62 6c 65 64 20 3d 20 side.bEnabled =
3130: 31 3b 0a 20 20 77 68 69 6c 65 28 20 7a 53 71 6c 1;. while( zSql
3140: 5b 69 5d 21 3d 30 20 29 7b 0a 20 20 20 20 61 73 [i]!=0 ){. as
3150: 73 65 72 74 28 20 69 3e 3d 30 20 29 3b 0a 20 20 sert( i>=0 );.
3160: 20 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 pParse->sLastT
3170: 6f 6b 65 6e 2e 7a 20 3d 20 26 7a 53 71 6c 5b 69 oken.z = &zSql[i
3180: 5d 3b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e 73 ];. pParse->s
3190: 4c 61 73 74 54 6f 6b 65 6e 2e 6e 20 3d 20 73 71 LastToken.n = sq
31a0: 6c 69 74 65 33 47 65 74 54 6f 6b 65 6e 28 28 75 lite3GetToken((u
31b0: 6e 73 69 67 6e 65 64 20 63 68 61 72 2a 29 26 7a nsigned char*)&z
31c0: 53 71 6c 5b 69 5d 2c 26 74 6f 6b 65 6e 54 79 70 Sql[i],&tokenTyp
31d0: 65 29 3b 0a 20 20 20 20 69 20 2b 3d 20 70 50 61 e);. i += pPa
31e0: 72 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2e rse->sLastToken.
31f0: 6e 3b 0a 20 20 20 20 69 66 28 20 69 3e 6d 78 53 n;. if( i>mxS
3200: 71 6c 4c 65 6e 20 29 7b 0a 20 20 20 20 20 20 70 qlLen ){. p
3210: 50 61 72 73 65 2d 3e 72 63 20 3d 20 53 51 4c 49 Parse->rc = SQLI
3220: 54 45 5f 54 4f 4f 42 49 47 3b 0a 20 20 20 20 20 TE_TOOBIG;.
3230: 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 break;. }.
3240: 20 20 69 66 28 20 74 6f 6b 65 6e 54 79 70 65 3e if( tokenType>
3250: 3d 54 4b 5f 53 50 41 43 45 20 29 7b 0a 20 20 20 =TK_SPACE ){.
3260: 20 20 20 61 73 73 65 72 74 28 20 74 6f 6b 65 6e assert( token
3270: 54 79 70 65 3d 3d 54 4b 5f 53 50 41 43 45 20 7c Type==TK_SPACE |
3280: 7c 20 74 6f 6b 65 6e 54 79 70 65 3d 3d 54 4b 5f | tokenType==TK_
3290: 49 4c 4c 45 47 41 4c 20 29 3b 0a 20 20 20 20 20 ILLEGAL );.
32a0: 20 69 66 28 20 64 62 2d 3e 75 31 2e 69 73 49 6e if( db->u1.isIn
32b0: 74 65 72 72 75 70 74 65 64 20 29 7b 0a 20 20 20 terrupted ){.
32c0: 20 20 20 20 20 73 71 6c 69 74 65 33 45 72 72 6f sqlite3Erro
32d0: 72 4d 73 67 28 70 50 61 72 73 65 2c 20 22 69 6e rMsg(pParse, "in
32e0: 74 65 72 72 75 70 74 22 29 3b 0a 20 20 20 20 20 terrupt");.
32f0: 20 20 20 70 50 61 72 73 65 2d 3e 72 63 20 3d 20 pParse->rc =
3300: 53 51 4c 49 54 45 5f 49 4e 54 45 52 52 55 50 54 SQLITE_INTERRUPT
3310: 3b 0a 20 20 20 20 20 20 20 20 62 72 65 61 6b 3b ;. break;
3320: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 69 . }. i
3330: 66 28 20 74 6f 6b 65 6e 54 79 70 65 3d 3d 54 4b f( tokenType==TK
3340: 5f 49 4c 4c 45 47 41 4c 20 29 7b 0a 20 20 20 20 _ILLEGAL ){.
3350: 20 20 20 20 73 71 6c 69 74 65 33 45 72 72 6f 72 sqlite3Error
3360: 4d 73 67 28 70 50 61 72 73 65 2c 20 22 75 6e 72 Msg(pParse, "unr
3370: 65 63 6f 67 6e 69 7a 65 64 20 74 6f 6b 65 6e 3a ecognized token:
3380: 20 5c 22 25 54 5c 22 22 2c 0a 20 20 20 20 20 20 \"%T\"",.
3390: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
33a0: 20 20 26 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 &pParse->sLast
33b0: 54 6f 6b 65 6e 29 3b 0a 20 20 20 20 20 20 20 20 Token);.
33c0: 62 72 65 61 6b 3b 0a 20 20 20 20 20 20 7d 0a 20 break;. }.
33d0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 }else{.
33e0: 69 66 28 20 74 6f 6b 65 6e 54 79 70 65 3d 3d 54 if( tokenType==T
33f0: 4b 5f 53 45 4d 49 20 29 20 70 50 61 72 73 65 2d K_SEMI ) pParse-
3400: 3e 7a 54 61 69 6c 20 3d 20 26 7a 53 71 6c 5b 69 >zTail = &zSql[i
3410: 5d 3b 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 ];. sqlite3
3420: 50 61 72 73 65 72 28 70 45 6e 67 69 6e 65 2c 20 Parser(pEngine,
3430: 74 6f 6b 65 6e 54 79 70 65 2c 20 70 50 61 72 73 tokenType, pPars
3440: 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c 20 70 e->sLastToken, p
3450: 50 61 72 73 65 29 3b 0a 20 20 20 20 20 20 6c 61 Parse);. la
3460: 73 74 54 6f 6b 65 6e 50 61 72 73 65 64 20 3d 20 stTokenParsed =
3470: 74 6f 6b 65 6e 54 79 70 65 3b 0a 20 20 20 20 20 tokenType;.
3480: 20 69 66 28 20 70 50 61 72 73 65 2d 3e 72 63 21 if( pParse->rc!
3490: 3d 53 51 4c 49 54 45 5f 4f 4b 20 7c 7c 20 64 62 =SQLITE_OK || db
34a0: 2d 3e 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 20 29 ->mallocFailed )
34b0: 20 62 72 65 61 6b 3b 0a 20 20 20 20 7d 0a 20 20 break;. }.
34c0: 7d 0a 20 20 61 73 73 65 72 74 28 20 6e 45 72 72 }. assert( nErr
34d0: 3d 3d 30 20 29 3b 0a 20 20 69 66 28 20 70 50 61 ==0 );. if( pPa
34e0: 72 73 65 2d 3e 72 63 3d 3d 53 51 4c 49 54 45 5f rse->rc==SQLITE_
34f0: 4f 4b 20 26 26 20 64 62 2d 3e 6d 61 6c 6c 6f 63 OK && db->malloc
3500: 46 61 69 6c 65 64 3d 3d 30 20 29 7b 0a 20 20 20 Failed==0 ){.
3510: 20 61 73 73 65 72 74 28 20 7a 53 71 6c 5b 69 5d assert( zSql[i]
3520: 3d 3d 30 20 29 3b 0a 20 20 20 20 69 66 28 20 6c ==0 );. if( l
3530: 61 73 74 54 6f 6b 65 6e 50 61 72 73 65 64 21 3d astTokenParsed!=
3540: 54 4b 5f 53 45 4d 49 20 29 7b 0a 20 20 20 20 20 TK_SEMI ){.
3550: 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 28 70 sqlite3Parser(p
3560: 45 6e 67 69 6e 65 2c 20 54 4b 5f 53 45 4d 49 2c Engine, TK_SEMI,
3570: 20 70 50 61 72 73 65 2d 3e 73 4c 61 73 74 54 6f pParse->sLastTo
3580: 6b 65 6e 2c 20 70 50 61 72 73 65 29 3b 0a 20 20 ken, pParse);.
3590: 20 20 20 20 70 50 61 72 73 65 2d 3e 7a 54 61 69 pParse->zTai
35a0: 6c 20 3d 20 26 7a 53 71 6c 5b 69 5d 3b 0a 20 20 l = &zSql[i];.
35b0: 20 20 7d 0a 20 20 20 20 69 66 28 20 70 50 61 72 }. if( pPar
35c0: 73 65 2d 3e 72 63 3d 3d 53 51 4c 49 54 45 5f 4f se->rc==SQLITE_O
35d0: 4b 20 26 26 20 64 62 2d 3e 6d 61 6c 6c 6f 63 46 K && db->mallocF
35e0: 61 69 6c 65 64 3d 3d 30 20 29 7b 0a 20 20 20 20 ailed==0 ){.
35f0: 20 20 73 71 6c 69 74 65 33 50 61 72 73 65 72 28 sqlite3Parser(
3600: 70 45 6e 67 69 6e 65 2c 20 30 2c 20 70 50 61 72 pEngine, 0, pPar
3610: 73 65 2d 3e 73 4c 61 73 74 54 6f 6b 65 6e 2c 20 se->sLastToken,
3620: 70 50 61 72 73 65 29 3b 0a 20 20 20 20 7d 0a 20 pParse);. }.
3630: 20 7d 0a 23 69 66 64 65 66 20 59 59 54 52 41 43 }.#ifdef YYTRAC
3640: 4b 4d 41 58 53 54 41 43 4b 44 45 50 54 48 0a 20 KMAXSTACKDEPTH.
3650: 20 73 71 6c 69 74 65 33 5f 6d 75 74 65 78 5f 65 sqlite3_mutex_e
3660: 6e 74 65 72 28 73 71 6c 69 74 65 33 4d 61 6c 6c nter(sqlite3Mall
3670: 6f 63 4d 75 74 65 78 28 29 29 3b 0a 20 20 73 71 ocMutex());. sq
3680: 6c 69 74 65 33 53 74 61 74 75 73 48 69 67 68 77 lite3StatusHighw
3690: 61 74 65 72 28 53 51 4c 49 54 45 5f 53 54 41 54 ater(SQLITE_STAT
36a0: 55 53 5f 50 41 52 53 45 52 5f 53 54 41 43 4b 2c US_PARSER_STACK,
36b0: 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 50 61 . sqlite3Pa
36c0: 72 73 65 72 53 74 61 63 6b 50 65 61 6b 28 70 45 rserStackPeak(pE
36d0: 6e 67 69 6e 65 29 0a 20 20 29 3b 0a 20 20 73 71 ngine). );. sq
36e0: 6c 69 74 65 33 5f 6d 75 74 65 78 5f 6c 65 61 76 lite3_mutex_leav
36f0: 65 28 73 71 6c 69 74 65 33 4d 61 6c 6c 6f 63 4d e(sqlite3MallocM
3700: 75 74 65 78 28 29 29 3b 0a 23 65 6e 64 69 66 20 utex());.#endif
3710: 2f 2a 20 59 59 44 45 42 55 47 20 2a 2f 0a 20 20 /* YYDEBUG */.
3720: 73 71 6c 69 74 65 33 50 61 72 73 65 72 46 72 65 sqlite3ParserFre
3730: 65 28 70 45 6e 67 69 6e 65 2c 20 73 71 6c 69 74 e(pEngine, sqlit
3740: 65 33 5f 66 72 65 65 29 3b 0a 20 20 64 62 2d 3e e3_free);. db->
3750: 6c 6f 6f 6b 61 73 69 64 65 2e 62 45 6e 61 62 6c lookaside.bEnabl
3760: 65 64 20 3d 20 65 6e 61 62 6c 65 4c 6f 6f 6b 61 ed = enableLooka
3770: 73 69 64 65 3b 0a 20 20 69 66 28 20 64 62 2d 3e side;. if( db->
3780: 6d 61 6c 6c 6f 63 46 61 69 6c 65 64 20 29 7b 0a mallocFailed ){.
3790: 20 20 20 20 70 50 61 72 73 65 2d 3e 72 63 20 3d pParse->rc =
37a0: 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 3b 0a 20 SQLITE_NOMEM;.
37b0: 20 7d 0a 20 20 69 66 28 20 70 50 61 72 73 65 2d }. if( pParse-
37c0: 3e 72 63 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 26 >rc!=SQLITE_OK &
37d0: 26 20 70 50 61 72 73 65 2d 3e 72 63 21 3d 53 51 & pParse->rc!=SQ
37e0: 4c 49 54 45 5f 44 4f 4e 45 20 26 26 20 70 50 61 LITE_DONE && pPa
37f0: 72 73 65 2d 3e 7a 45 72 72 4d 73 67 3d 3d 30 20 rse->zErrMsg==0
3800: 29 7b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e 7a ){. pParse->z
3810: 45 72 72 4d 73 67 20 3d 20 73 71 6c 69 74 65 33 ErrMsg = sqlite3
3820: 4d 50 72 69 6e 74 66 28 64 62 2c 20 22 25 73 22 MPrintf(db, "%s"
3830: 2c 20 73 71 6c 69 74 65 33 45 72 72 53 74 72 28 , sqlite3ErrStr(
3840: 70 50 61 72 73 65 2d 3e 72 63 29 29 3b 0a 20 20 pParse->rc));.
3850: 7d 0a 20 20 61 73 73 65 72 74 28 20 70 7a 45 72 }. assert( pzEr
3860: 72 4d 73 67 21 3d 30 20 29 3b 0a 20 20 69 66 28 rMsg!=0 );. if(
3870: 20 70 50 61 72 73 65 2d 3e 7a 45 72 72 4d 73 67 pParse->zErrMsg
3880: 20 29 7b 0a 20 20 20 20 2a 70 7a 45 72 72 4d 73 ){. *pzErrMs
3890: 67 20 3d 20 70 50 61 72 73 65 2d 3e 7a 45 72 72 g = pParse->zErr
38a0: 4d 73 67 3b 0a 20 20 20 20 73 71 6c 69 74 65 33 Msg;. sqlite3
38b0: 5f 6c 6f 67 28 70 50 61 72 73 65 2d 3e 72 63 2c _log(pParse->rc,
38c0: 20 22 25 73 22 2c 20 2a 70 7a 45 72 72 4d 73 67 "%s", *pzErrMsg
38d0: 29 3b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e 7a );. pParse->z
38e0: 45 72 72 4d 73 67 20 3d 20 30 3b 0a 20 20 20 20 ErrMsg = 0;.
38f0: 6e 45 72 72 2b 2b 3b 0a 20 20 7d 0a 20 20 69 66 nErr++;. }. if
3900: 28 20 70 50 61 72 73 65 2d 3e 70 56 64 62 65 20 ( pParse->pVdbe
3910: 26 26 20 70 50 61 72 73 65 2d 3e 6e 45 72 72 3e && pParse->nErr>
3920: 30 20 26 26 20 70 50 61 72 73 65 2d 3e 6e 65 73 0 && pParse->nes
3930: 74 65 64 3d 3d 30 20 29 7b 0a 20 20 20 20 73 71 ted==0 ){. sq
3940: 6c 69 74 65 33 56 64 62 65 44 65 6c 65 74 65 28 lite3VdbeDelete(
3950: 70 50 61 72 73 65 2d 3e 70 56 64 62 65 29 3b 0a pParse->pVdbe);.
3960: 20 20 20 20 70 50 61 72 73 65 2d 3e 70 56 64 62 pParse->pVdb
3970: 65 20 3d 20 30 3b 0a 20 20 7d 0a 23 69 66 6e 64 e = 0;. }.#ifnd
3980: 65 66 20 53 51 4c 49 54 45 5f 4f 4d 49 54 5f 53 ef SQLITE_OMIT_S
3990: 48 41 52 45 44 5f 43 41 43 48 45 0a 20 20 69 66 HARED_CACHE. if
39a0: 28 20 70 50 61 72 73 65 2d 3e 6e 65 73 74 65 64 ( pParse->nested
39b0: 3d 3d 30 20 29 7b 0a 20 20 20 20 73 71 6c 69 74 ==0 ){. sqlit
39c0: 65 33 44 62 46 72 65 65 28 64 62 2c 20 70 50 61 e3DbFree(db, pPa
39d0: 72 73 65 2d 3e 61 54 61 62 6c 65 4c 6f 63 6b 29 rse->aTableLock)
39e0: 3b 0a 20 20 20 20 70 50 61 72 73 65 2d 3e 61 54 ;. pParse->aT
39f0: 61 62 6c 65 4c 6f 63 6b 20 3d 20 30 3b 0a 20 20 ableLock = 0;.
3a00: 20 20 70 50 61 72 73 65 2d 3e 6e 54 61 62 6c 65 pParse->nTable
3a10: 4c 6f 63 6b 20 3d 20 30 3b 0a 20 20 7d 0a 23 65 Lock = 0;. }.#e
3a20: 6e 64 69 66 0a 23 69 66 6e 64 65 66 20 53 51 4c ndif.#ifndef SQL
3a30: 49 54 45 5f 4f 4d 49 54 5f 56 49 52 54 55 41 4c ITE_OMIT_VIRTUAL
3a40: 54 41 42 4c 45 0a 20 20 73 71 6c 69 74 65 33 5f TABLE. sqlite3_
3a50: 66 72 65 65 28 70 50 61 72 73 65 2d 3e 61 70 56 free(pParse->apV
3a60: 74 61 62 4c 6f 63 6b 29 3b 0a 23 65 6e 64 69 66 tabLock);.#endif
3a70: 0a 0a 20 20 69 66 28 20 21 49 4e 5f 44 45 43 4c .. if( !IN_DECL
3a80: 41 52 45 5f 56 54 41 42 20 29 7b 0a 20 20 20 20 ARE_VTAB ){.
3a90: 2f 2a 20 49 66 20 74 68 65 20 70 50 61 72 73 65 /* If the pParse
3aa0: 2d 3e 64 65 63 6c 61 72 65 56 74 61 62 20 66 6c ->declareVtab fl
3ab0: 61 67 20 69 73 20 73 65 74 2c 20 64 6f 20 6e 6f ag is set, do no
3ac0: 74 20 64 65 6c 65 74 65 20 61 6e 79 20 74 61 62 t delete any tab
3ad0: 6c 65 20 0a 20 20 20 20 2a 2a 20 73 74 72 75 63 le . ** struc
3ae0: 74 75 72 65 20 62 75 69 6c 74 20 75 70 20 69 6e ture built up in
3af0: 20 70 50 61 72 73 65 2d 3e 70 4e 65 77 54 61 62 pParse->pNewTab
3b00: 6c 65 2e 20 54 68 65 20 63 61 6c 6c 69 6e 67 20 le. The calling
3b10: 63 6f 64 65 20 28 73 65 65 20 76 74 61 62 2e 63 code (see vtab.c
3b20: 29 0a 20 20 20 20 2a 2a 20 77 69 6c 6c 20 74 61 ). ** will ta
3b30: 6b 65 20 72 65 73 70 6f 6e 73 69 62 69 6c 69 74 ke responsibilit
3b40: 79 20 66 6f 72 20 66 72 65 65 69 6e 67 20 74 68 y for freeing th
3b50: 65 20 54 61 62 6c 65 20 73 74 72 75 63 74 75 72 e Table structur
3b60: 65 2e 0a 20 20 20 20 2a 2f 0a 20 20 20 20 73 71 e.. */. sq
3b70: 6c 69 74 65 33 44 65 6c 65 74 65 54 61 62 6c 65 lite3DeleteTable
3b80: 28 64 62 2c 20 70 50 61 72 73 65 2d 3e 70 4e 65 (db, pParse->pNe
3b90: 77 54 61 62 6c 65 29 3b 0a 20 20 7d 0a 0a 20 20 wTable);. }..
3ba0: 73 71 6c 69 74 65 33 57 69 74 68 44 65 6c 65 74 sqlite3WithDelet
3bb0: 65 28 64 62 2c 20 70 50 61 72 73 65 2d 3e 70 57 e(db, pParse->pW
3bc0: 69 74 68 54 6f 46 72 65 65 29 3b 0a 20 20 73 71 ithToFree);. sq
3bd0: 6c 69 74 65 33 44 65 6c 65 74 65 54 72 69 67 67 lite3DeleteTrigg
3be0: 65 72 28 64 62 2c 20 70 50 61 72 73 65 2d 3e 70 er(db, pParse->p
3bf0: 4e 65 77 54 72 69 67 67 65 72 29 3b 0a 20 20 66 NewTrigger);. f
3c00: 6f 72 28 69 3d 70 50 61 72 73 65 2d 3e 6e 7a 56 or(i=pParse->nzV
3c10: 61 72 2d 31 3b 20 69 3e 3d 30 3b 20 69 2d 2d 29 ar-1; i>=0; i--)
3c20: 20 73 71 6c 69 74 65 33 44 62 46 72 65 65 28 64 sqlite3DbFree(d
3c30: 62 2c 20 70 50 61 72 73 65 2d 3e 61 7a 56 61 72 b, pParse->azVar
3c40: 5b 69 5d 29 3b 0a 20 20 73 71 6c 69 74 65 33 44 [i]);. sqlite3D
3c50: 62 46 72 65 65 28 64 62 2c 20 70 50 61 72 73 65 bFree(db, pParse
3c60: 2d 3e 61 7a 56 61 72 29 3b 0a 20 20 77 68 69 6c ->azVar);. whil
3c70: 65 28 20 70 50 61 72 73 65 2d 3e 70 41 69 6e 63 e( pParse->pAinc
3c80: 20 29 7b 0a 20 20 20 20 41 75 74 6f 69 6e 63 49 ){. AutoincI
3c90: 6e 66 6f 20 2a 70 20 3d 20 70 50 61 72 73 65 2d nfo *p = pParse-
3ca0: 3e 70 41 69 6e 63 3b 0a 20 20 20 20 70 50 61 72 >pAinc;. pPar
3cb0: 73 65 2d 3e 70 41 69 6e 63 20 3d 20 70 2d 3e 70 se->pAinc = p->p
3cc0: 4e 65 78 74 3b 0a 20 20 20 20 73 71 6c 69 74 65 Next;. sqlite
3cd0: 33 44 62 46 72 65 65 28 64 62 2c 20 70 29 3b 0a 3DbFree(db, p);.
3ce0: 20 20 7d 0a 20 20 77 68 69 6c 65 28 20 70 50 61 }. while( pPa
3cf0: 72 73 65 2d 3e 70 5a 6f 6d 62 69 65 54 61 62 20 rse->pZombieTab
3d00: 29 7b 0a 20 20 20 20 54 61 62 6c 65 20 2a 70 20 ){. Table *p
3d10: 3d 20 70 50 61 72 73 65 2d 3e 70 5a 6f 6d 62 69 = pParse->pZombi
3d20: 65 54 61 62 3b 0a 20 20 20 20 70 50 61 72 73 65 eTab;. pParse
3d30: 2d 3e 70 5a 6f 6d 62 69 65 54 61 62 20 3d 20 70 ->pZombieTab = p
3d40: 2d 3e 70 4e 65 78 74 5a 6f 6d 62 69 65 3b 0a 20 ->pNextZombie;.
3d50: 20 20 20 73 71 6c 69 74 65 33 44 65 6c 65 74 65 sqlite3Delete
3d60: 54 61 62 6c 65 28 64 62 2c 20 70 29 3b 0a 20 20 Table(db, p);.
3d70: 7d 0a 20 20 61 73 73 65 72 74 28 20 6e 45 72 72 }. assert( nErr
3d80: 3d 3d 30 20 7c 7c 20 70 50 61 72 73 65 2d 3e 72 ==0 || pParse->r
3d90: 63 21 3d 53 51 4c 49 54 45 5f 4f 4b 20 29 3b 0a c!=SQLITE_OK );.
3da0: 20 20 72 65 74 75 72 6e 20 6e 45 72 72 3b 0a 7d return nErr;.}
3db0: 0a .