#include <stdlib.h>
#define SQLITE_ASCII
#define SQLITE_PRIVATE static
#define sqlite3StrNICmp sqlite3_strnicmp
#define testcase(x)
#define TK_SEMI 1
#define TK_EXPLAIN 2
#define TK_QUERY 3
#define TK_PLAN 4
#define TK_BEGIN 5
#define TK_TRANSACTION 6
#define TK_DEFERRED 7
#define TK_IMMEDIATE 8
#define TK_EXCLUSIVE 9
#define TK_COMMIT 10
#define TK_END 11
#define TK_ROLLBACK 12
#define TK_SAVEPOINT 13
#define TK_RELEASE 14
#define TK_TO 15
#define TK_TABLE 16
#define TK_CREATE 17
#define TK_IF 18
#define TK_NOT 19
#define TK_EXISTS 20
#define TK_TEMP 21
#define TK_LP 22
#define TK_RP 23
#define TK_AS 24
#define TK_WITHOUT 25
#define TK_COMMA 26
#define TK_ID 27
#define TK_INDEXED 28
#define TK_ABORT 29
#define TK_ACTION 30
#define TK_AFTER 31
#define TK_ANALYZE 32
#define TK_ASC 33
#define TK_ATTACH 34
#define TK_BEFORE 35
#define TK_BY 36
#define TK_CASCADE 37
#define TK_CAST 38
#define TK_COLUMNKW 39
#define TK_CONFLICT 40
#define TK_DATABASE 41
#define TK_DESC 42
#define TK_DETACH 43
#define TK_EACH 44
#define TK_FAIL 45
#define TK_FOR 46
#define TK_IGNORE 47
#define TK_INITIALLY 48
#define TK_INSTEAD 49
#define TK_LIKE_KW 50
#define TK_MATCH 51
#define TK_NO 52
#define TK_KEY 53
#define TK_OF 54
#define TK_OFFSET 55
#define TK_PRAGMA 56
#define TK_RAISE 57
#define TK_RECURSIVE 58
#define TK_REPLACE 59
#define TK_RESTRICT 60
#define TK_ROW 61
#define TK_TRIGGER 62
#define TK_VACUUM 63
#define TK_VIEW 64
#define TK_VIRTUAL 65
#define TK_WITH 66
#define TK_REINDEX 67
#define TK_RENAME 68
#define TK_CTIME_KW 69
#define TK_ANY 70
#define TK_OR 71
#define TK_AND 72
#define TK_IS 73
#define TK_BETWEEN 74
#define TK_IN 75
#define TK_ISNULL 76
#define TK_NOTNULL 77
#define TK_NE 78
#define TK_EQ 79
#define TK_GT 80
#define TK_LE 81
#define TK_LT 82
#define TK_GE 83
#define TK_ESCAPE 84
#define TK_BITAND 85
#define TK_BITOR 86
#define TK_LSHIFT 87
#define TK_RSHIFT 88
#define TK_PLUS 89
#define TK_MINUS 90
#define TK_STAR 91
#define TK_SLASH 92
#define TK_REM 93
#define TK_CONCAT 94
#define TK_COLLATE 95
#define TK_BITNOT 96
#define TK_STRING 97
#define TK_JOIN_KW 98
#define TK_CONSTRAINT 99
#define TK_DEFAULT 100
#define TK_NULL 101
#define TK_PRIMARY 102
#define TK_UNIQUE 103
#define TK_CHECK 104
#define TK_REFERENCES 105
#define TK_AUTOINCR 106
#define TK_ON 107
#define TK_INSERT 108
#define TK_DELETE 109
#define TK_UPDATE 110
#define TK_SET 111
#define TK_DEFERRABLE 112
#define TK_FOREIGN 113
#define TK_DROP 114
#define TK_UNION 115
#define TK_ALL 116
#define TK_EXCEPT 117
#define TK_INTERSECT 118
#define TK_SELECT 119
#define TK_VALUES 120
#define TK_DISTINCT 121
#define TK_DOT 122
#define TK_FROM 123
#define TK_JOIN 124
#define TK_USING 125
#define TK_ORDER 126
#define TK_GROUP 127
#define TK_HAVING 128
#define TK_LIMIT 129
#define TK_WHERE 130
#define TK_INTO 131
#define TK_INTEGER 132
#define TK_FLOAT 133
#define TK_BLOB 134
#define TK_VARIABLE 135
#define TK_CASE 136
#define TK_WHEN 137
#define TK_THEN 138
#define TK_ELSE 139
#define TK_INDEX 140
#define TK_ALTER 141
#define TK_ADD 142
#define TK_TO_TEXT 143
#define TK_TO_BLOB 144
#define TK_TO_NUMERIC 145
#define TK_TO_INT 146
#define TK_TO_REAL 147
#define TK_ISNOT 148
#define TK_END_OF_FILE 149
#define TK_ILLEGAL 150
#define TK_SPACE 151
#define TK_UNCLOSED_STRING 152
#define TK_FUNCTION 153
#define TK_COLUMN 154
#define TK_AGG_FUNCTION 155
#define TK_AGG_COLUMN 156
#define TK_UMINUS 157
#define TK_UPLUS 158
#define TK_REGISTER 159
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = {
#ifdef SQLITE_ASCII
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
252,253,254,255
#endif
#ifdef SQLITE_EBCDIC
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
160,161,162,163,164,165,166,167,168,169,170,171,140,141,142,175,
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
192,129,130,131,132,133,134,135,136,137,202,203,204,205,206,207,
208,145,146,147,148,149,150,151,152,153,218,219,220,221,222,223,
224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239,
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
#endif
};
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c,
0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40,
0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
};
# define sqlite3Isspace(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x01)
# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
#define charMap(X) sqlite3UpperToLower[(unsigned char)X]
#define UpperToLower sqlite3UpperToLower
static int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){
register unsigned char *a, *b;
if( zLeft==0 ){
return zRight ? -1 : 0;
}else if( zRight==0 ){
return 1;
}
a = (unsigned char *)zLeft;
b = (unsigned char *)zRight;
while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; }
return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b];
}
static int keywordCode(const char *z, int n){
static const char zText[553] = {
'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
'T','E','B','E','G','I','N','N','E','R','E','C','U','R','S','I','V','E',
'B','E','T','W','E','E','N','O','T','N','U','L','L','I','K','E','C','A',
'S','C','A','D','E','L','E','T','E','C','A','S','E','C','O','L','L','A',
'T','E','C','R','E','A','T','E','C','U','R','R','E','N','T','_','D','A',
'T','E','D','E','T','A','C','H','I','M','M','E','D','I','A','T','E','J',
'O','I','N','S','E','R','T','M','A','T','C','H','P','L','A','N','A','L',
'Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U','E',
'S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','W','H',
'E','R','E','N','A','M','E','A','F','T','E','R','E','P','L','A','C','E',
'A','N','D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E',
'M','E','N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M',
'I','T','C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R',
'R','E','N','T','_','T','I','M','E','S','T','A','M','P','R','I','M','A',
'R','Y','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D',
'R','O','P','F','A','I','L','F','R','O','M','F','U','L','L','G','L','O',
'B','Y','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S','T',
'R','I','C','T','R','I','G','H','T','R','O','L','L','B','A','C','K','R',
'O','W','U','N','I','O','N','U','S','I','N','G','V','A','C','U','U','M',
'V','I','E','W','I','N','I','T','I','A','L','L','Y',
};
static const unsigned char aHash[127] = {
76, 105, 117, 74, 0, 45, 0, 0, 82, 0, 77, 0, 0,
42, 12, 78, 15, 0, 116, 85, 54, 112, 0, 19, 0, 0,
121, 0, 119, 115, 0, 22, 93, 0, 9, 0, 0, 70, 71,
0, 69, 6, 0, 48, 90, 102, 0, 118, 101, 0, 0, 44,
0, 103, 24, 0, 17, 0, 122, 53, 23, 0, 5, 110, 25,
96, 0, 0, 124, 106, 60, 123, 57, 28, 55, 0, 91, 0,
100, 26, 0, 99, 0, 0, 0, 95, 92, 97, 88, 109, 14,
39, 108, 0, 81, 0, 18, 89, 111, 32, 0, 120, 80, 113,
62, 46, 84, 0, 0, 94, 40, 59, 114, 0, 36, 0, 0,
29, 0, 86, 63, 64, 0, 20, 61, 0, 56,
};
static const unsigned char aNext[124] = {
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 0, 0, 50,
0, 43, 3, 47, 0, 0, 0, 0, 30, 0, 58, 0, 38,
0, 0, 0, 1, 66, 0, 0, 67, 0, 41, 0, 0, 0,
0, 0, 0, 49, 65, 0, 0, 0, 0, 31, 52, 16, 34,
10, 0, 0, 0, 0, 0, 0, 0, 11, 72, 79, 0, 8,
0, 104, 98, 0, 107, 0, 87, 0, 75, 51, 0, 27, 37,
73, 83, 0, 35, 68, 0, 0,
};
static const unsigned char aLen[124] = {
7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
4, 6, 2, 3, 9, 4, 2, 6, 5, 7, 4, 5, 7,
6, 6, 5, 6, 5, 5, 9, 7, 7, 3, 2, 4, 4,
7, 3, 6, 4, 7, 6, 12, 6, 9, 4, 6, 5, 4,
7, 6, 5, 6, 7, 5, 4, 5, 6, 5, 7, 3, 7,
13, 2, 2, 4, 6, 6, 8, 5, 17, 12, 7, 8, 8,
2, 4, 4, 4, 4, 4, 2, 2, 6, 5, 8, 5, 8,
3, 5, 5, 6, 4, 9, 3,
};
static const unsigned short int aOffset[124] = {
0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 184, 188, 192,
199, 204, 209, 212, 218, 221, 225, 234, 240, 240, 240, 243, 246,
250, 251, 255, 261, 265, 272, 278, 290, 296, 305, 307, 313, 318,
320, 327, 332, 337, 343, 349, 354, 358, 361, 367, 371, 378, 380,
387, 389, 391, 400, 404, 410, 416, 424, 429, 429, 445, 452, 459,
460, 467, 471, 475, 479, 483, 486, 488, 490, 496, 500, 508, 513,
521, 524, 529, 534, 540, 544, 549,
};
static const unsigned char aCode[124] = {
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
TK_OR, TK_UNIQUE, TK_QUERY, TK_WITHOUT, TK_WITH,
TK_JOIN_KW, TK_RELEASE, TK_ATTACH, TK_HAVING, TK_GROUP,
TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RECURSIVE, TK_BETWEEN,
TK_NOTNULL, TK_NOT, TK_NO, TK_NULL, TK_LIKE_KW,
TK_CASCADE, TK_ASC, TK_DELETE, TK_CASE, TK_COLLATE,
TK_CREATE, TK_CTIME_KW, TK_DETACH, TK_IMMEDIATE, TK_JOIN,
TK_INSERT, TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA,
TK_ABORT, TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN,
TK_WHERE, TK_RENAME, TK_AFTER, TK_REPLACE, TK_AND,
TK_DEFAULT, TK_AUTOINCR, TK_TO, TK_IN, TK_CAST,
TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW,
TK_CTIME_KW, TK_PRIMARY, TK_DEFERRED, TK_DISTINCT, TK_IS,
TK_DROP, TK_FAIL, TK_FROM, TK_JOIN_KW, TK_LIKE_KW,
TK_BY, TK_IF, TK_ISNULL, TK_ORDER, TK_RESTRICT,
TK_JOIN_KW, TK_ROLLBACK, TK_ROW, TK_UNION, TK_USING,
TK_VACUUM, TK_VIEW, TK_INITIALLY, TK_ALL,
};
int h, i;
if( n<2 ) return TK_ID;
h = ((charMap(z[0])*4) ^
(charMap(z[n-1])*3) ^
n) % 127;
for(i=((int)aHash[h])-1; i>=0; i=((int)aNext[i])-1){
if( aLen[i]==n && sqlite3StrNICmp(&zText[aOffset[i]],z,n)==0 ){
testcase( i==0 );
testcase( i==1 );
testcase( i==2 );
testcase( i==3 );
testcase( i==4 );
testcase( i==5 );
testcase( i==6 );
testcase( i==7 );
testcase( i==8 );
testcase( i==9 );
testcase( i==10 );
testcase( i==11 );
testcase( i==12 );
testcase( i==13 );
testcase( i==14 );
testcase( i==15 );
testcase( i==16 );
testcase( i==17 );
testcase( i==18 );
testcase( i==19 );
testcase( i==20 );
testcase( i==21 );
testcase( i==22 );
testcase( i==23 );
testcase( i==24 );
testcase( i==25 );
testcase( i==26 );
testcase( i==27 );
testcase( i==28 );
testcase( i==29 );
testcase( i==30 );
testcase( i==31 );
testcase( i==32 );
testcase( i==33 );
testcase( i==34 );
testcase( i==35 );
testcase( i==36 );
testcase( i==37 );
testcase( i==38 );
testcase( i==39 );
testcase( i==40 );
testcase( i==41 );
testcase( i==42 );
testcase( i==43 );
testcase( i==44 );
testcase( i==45 );
testcase( i==46 );
testcase( i==47 );
testcase( i==48 );
testcase( i==49 );
testcase( i==50 );
testcase( i==51 );
testcase( i==52 );
testcase( i==53 );
testcase( i==54 );
testcase( i==55 );
testcase( i==56 );
testcase( i==57 );
testcase( i==58 );
testcase( i==59 );
testcase( i==60 );
testcase( i==61 );
testcase( i==62 );
testcase( i==63 );
testcase( i==64 );
testcase( i==65 );
testcase( i==66 );
testcase( i==67 );
testcase( i==68 );
testcase( i==69 );
testcase( i==70 );
testcase( i==71 );
testcase( i==72 );
testcase( i==73 );
testcase( i==74 );
testcase( i==75 );
testcase( i==76 );
testcase( i==77 );
testcase( i==78 );
testcase( i==79 );
testcase( i==80 );
testcase( i==81 );
testcase( i==82 );
testcase( i==83 );
testcase( i==84 );
testcase( i==85 );
testcase( i==86 );
testcase( i==87 );
testcase( i==88 );
testcase( i==89 );
testcase( i==90 );
testcase( i==91 );
testcase( i==92 );
testcase( i==93 );
testcase( i==94 );
testcase( i==95 );
testcase( i==96 );
testcase( i==97 );
testcase( i==98 );
testcase( i==99 );
testcase( i==100 );
testcase( i==101 );
testcase( i==102 );
testcase( i==103 );
testcase( i==104 );
testcase( i==105 );
testcase( i==106 );
testcase( i==107 );
testcase( i==108 );
testcase( i==109 );
testcase( i==110 );
testcase( i==111 );
testcase( i==112 );
testcase( i==113 );
testcase( i==114 );
testcase( i==115 );
testcase( i==116 );
testcase( i==117 );
testcase( i==118 );
testcase( i==119 );
testcase( i==120 );
testcase( i==121 );
testcase( i==122 );
testcase( i==123 );
return aCode[i];
}
}
return TK_ID;
}
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
return keywordCode((char*)z, n);
}
#define SQLITE_N_KEYWORD 124
#define IdChar(C) ((sqlite3CtypeMap[(unsigned char)C]&0x46)!=0)
SQLITE_PRIVATE int sqlite3IsIdChar(unsigned char c){ return IdChar(c); }
int sqlite3_get_token(const unsigned char *z, int *tokenType){
int i, c;
switch( *z ){
case ' ': case '\t': case '\n': case '\f': case '\r': {
testcase( z[0]==' ' );
testcase( z[0]=='\t' );
testcase( z[0]=='\n' );
testcase( z[0]=='\f' );
testcase( z[0]=='\r' );
for(i=1; sqlite3Isspace(z[i]); i++){}
*tokenType = TK_SPACE;
return i;
}
case '-': {
if( z[1]=='-' ){
for(i=2; (c=z[i])!=0 && c!='\n'; i++){}
*tokenType = TK_SPACE;
return i;
}
*tokenType = TK_MINUS;
return 1;
}
case '(': {
*tokenType = TK_LP;
return 1;
}
case ')': {
*tokenType = TK_RP;
return 1;
}
case ';': {
*tokenType = TK_SEMI;
return 1;
}
case '+': {
*tokenType = TK_PLUS;
return 1;
}
case '*': {
*tokenType = TK_STAR;
return 1;
}
case '/': {
if( z[1]!='*' || z[2]==0 ){
*tokenType = TK_SLASH;
return 1;
}
for(i=3, c=z[2]; (c!='*' || z[i]!='/') && (c=z[i])!=0; i++){}
if( c ) i++;
*tokenType = TK_SPACE;
return i;
}
case '%': {
*tokenType = TK_REM;
return 1;
}
case '=': {
*tokenType = TK_EQ;
return 1 + (z[1]=='=');
}
case '<': {
if( (c=z[1])=='=' ){
*tokenType = TK_LE;
return 2;
}else if( c=='>' ){
*tokenType = TK_NE;
return 2;
}else if( c=='<' ){
*tokenType = TK_LSHIFT;
return 2;
}else{
*tokenType = TK_LT;
return 1;
}
}
case '>': {
if( (c=z[1])=='=' ){
*tokenType = TK_GE;
return 2;
}else if( c=='>' ){
*tokenType = TK_RSHIFT;
return 2;
}else{
*tokenType = TK_GT;
return 1;
}
}
case '!': {
if( z[1]!='=' ){
*tokenType = TK_ILLEGAL;
return 2;
}else{
*tokenType = TK_NE;
return 2;
}
}
case '|': {
if( z[1]!='|' ){
*tokenType = TK_BITOR;
return 1;
}else{
*tokenType = TK_CONCAT;
return 2;
}
}
case ',': {
*tokenType = TK_COMMA;
return 1;
}
case '&': {
*tokenType = TK_BITAND;
return 1;
}
case '~': {
*tokenType = TK_BITNOT;
return 1;
}
case '`':
case '\'':
case '"': {
int delim = z[0];
testcase( delim=='`' );
testcase( delim=='\'' );
testcase( delim=='"' );
for(i=1; (c=z[i])!=0; i++){
if( c==delim ){
if( z[i+1]==delim ){
i++;
}else{
break;
}
}
}
if( c=='\'' ){
*tokenType = TK_STRING;
return i+1;
}else if( c!=0 ){
*tokenType = TK_ID;
return i+1;
}else{
*tokenType = TK_ILLEGAL;
return i;
}
}
case '.': {
#ifndef SQLITE_OMIT_FLOATING_POINT
if( !sqlite3Isdigit(z[1]) )
#endif
{
*tokenType = TK_DOT;
return 1;
}
}
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9': {
testcase( z[0]=='0' ); testcase( z[0]=='1' ); testcase( z[0]=='2' );
testcase( z[0]=='3' ); testcase( z[0]=='4' ); testcase( z[0]=='5' );
testcase( z[0]=='6' ); testcase( z[0]=='7' ); testcase( z[0]=='8' );
testcase( z[0]=='9' );
*tokenType = TK_INTEGER;
#ifndef SQLITE_OMIT_HEX_INTEGER
if( z[0]=='0' && (z[1]=='x' || z[1]=='X') && sqlite3Isxdigit(z[2]) ){
for(i=3; sqlite3Isxdigit(z[i]); i++){}
return i;
}
#endif
for(i=0; sqlite3Isdigit(z[i]); i++){}
#ifndef SQLITE_OMIT_FLOATING_POINT
if( z[i]=='.' ){
i++;
while( sqlite3Isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
if( (z[i]=='e' || z[i]=='E') &&
( sqlite3Isdigit(z[i+1])
|| ((z[i+1]=='+' || z[i+1]=='-') && sqlite3Isdigit(z[i+2]))
)
){
i += 2;
while( sqlite3Isdigit(z[i]) ){ i++; }
*tokenType = TK_FLOAT;
}
#endif
while( IdChar(z[i]) ){
*tokenType = TK_ILLEGAL;
i++;
}
return i;
}
case '[': {
for(i=1, c=z[0]; c!=']' && (c=z[i])!=0; i++){}
*tokenType = c==']' ? TK_ID : TK_ILLEGAL;
return i;
}
case '?': {
*tokenType = TK_VARIABLE;
for(i=1; sqlite3Isdigit(z[i]); i++){}
return i;
}
#ifndef SQLITE_OMIT_TCL_VARIABLE
case '$':
#endif
case '@':
case '#':
case ':': {
int n = 0;
testcase( z[0]=='$' ); testcase( z[0]=='@' );
testcase( z[0]==':' ); testcase( z[0]=='#' );
*tokenType = TK_VARIABLE;
for(i=1; (c=z[i])!=0; i++){
if( IdChar(c) ){
n++;
#ifndef SQLITE_OMIT_TCL_VARIABLE
}else if( c=='(' && n>0 ){
do{
i++;
}while( (c=z[i])!=0 && !sqlite3Isspace(c) && c!=')' );
if( c==')' ){
i++;
}else{
*tokenType = TK_ILLEGAL;
}
break;
}else if( c==':' && z[i+1]==':' ){
i++;
#endif
}else{
break;
}
}
if( n==0 ) *tokenType = TK_ILLEGAL;
return i;
}
#ifndef SQLITE_OMIT_BLOB_LITERAL
case 'x': case 'X': {
testcase( z[0]=='x' ); testcase( z[0]=='X' );
if( z[1]=='\'' ){
*tokenType = TK_BLOB;
for(i=2; sqlite3Isxdigit(z[i]); i++){}
if( z[i]!='\'' || i%2 ){
*tokenType = TK_ILLEGAL;
while( z[i] && z[i]!='\'' ){ i++; }
}
if( z[i] ) i++;
return i;
}
}
#endif
default: {
if( !IdChar(*z) ){
break;
}
for(i=1; IdChar(z[i]); i++){}
*tokenType = keywordCode((char*)z, i);
return i;
}
}
*tokenType = TK_ILLEGAL;
return 1;
}