annotate sqlite/complete.c @ 1494:0414e296c6cf trunk

[svn] - use $(NOTIFY_LIBS) and $(NOTIFY_CFLAGS)... not really much of difference, but yeah
author nenolod
date Fri, 04 Aug 2006 01:21:49 -0700
parents b6b61becdf4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1434
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
1 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
2 ** 2001 September 15
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
3 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
4 ** The author disclaims copyright to this source code. In place of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
5 ** a legal notice, here is a blessing:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
6 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
7 ** May you do good and not evil.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
8 ** May you find forgiveness for yourself and forgive others.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
9 ** May you share freely, never taking more than you give.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
10 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
11 *************************************************************************
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
12 ** An tokenizer for SQL
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
13 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
14 ** This file contains C code that implements the sqlite3_complete() API.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
15 ** This code used to be part of the tokenizer.c source file. But by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
16 ** separating it out, the code will be automatically omitted from
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
17 ** static links that do not use it.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
18 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
19 ** $Id: complete.c,v 1.3 2006/01/18 15:25:17 danielk1977 Exp $
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
20 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
21 #include "sqliteInt.h"
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
22 #ifndef SQLITE_OMIT_COMPLETE
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
23
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
24 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
25 ** This is defined in tokenize.c. We just have to import the definition.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
26 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
27 extern const char sqlite3IsIdChar[];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
28 #define IdChar(C) (((c=C)&0x80)!=0 || (c>0x1f && sqlite3IsIdChar[c-0x20]))
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
29
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
30
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
31 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
32 ** Token types used by the sqlite3_complete() routine. See the header
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
33 ** comments on that procedure for additional information.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
34 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
35 #define tkSEMI 0
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
36 #define tkWS 1
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
37 #define tkOTHER 2
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
38 #define tkEXPLAIN 3
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
39 #define tkCREATE 4
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
40 #define tkTEMP 5
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
41 #define tkTRIGGER 6
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
42 #define tkEND 7
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
43
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
44 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
45 ** Return TRUE if the given SQL string ends in a semicolon.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
46 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
47 ** Special handling is require for CREATE TRIGGER statements.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
48 ** Whenever the CREATE TRIGGER keywords are seen, the statement
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
49 ** must end with ";END;".
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
50 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
51 ** This implementation uses a state machine with 7 states:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
52 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
53 ** (0) START At the beginning or end of an SQL statement. This routine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
54 ** returns 1 if it ends in the START state and 0 if it ends
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
55 ** in any other state.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
56 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
57 ** (1) NORMAL We are in the middle of statement which ends with a single
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
58 ** semicolon.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
59 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
60 ** (2) EXPLAIN The keyword EXPLAIN has been seen at the beginning of
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
61 ** a statement.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
62 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
63 ** (3) CREATE The keyword CREATE has been seen at the beginning of a
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
64 ** statement, possibly preceeded by EXPLAIN and/or followed by
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
65 ** TEMP or TEMPORARY
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
66 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
67 ** (4) TRIGGER We are in the middle of a trigger definition that must be
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
68 ** ended by a semicolon, the keyword END, and another semicolon.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
69 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
70 ** (5) SEMI We've seen the first semicolon in the ";END;" that occurs at
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
71 ** the end of a trigger definition.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
72 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
73 ** (6) END We've seen the ";END" of the ";END;" that occurs at the end
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
74 ** of a trigger difinition.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
75 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
76 ** Transitions between states above are determined by tokens extracted
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
77 ** from the input. The following tokens are significant:
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
78 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
79 ** (0) tkSEMI A semicolon.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
80 ** (1) tkWS Whitespace
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
81 ** (2) tkOTHER Any other SQL token.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
82 ** (3) tkEXPLAIN The "explain" keyword.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
83 ** (4) tkCREATE The "create" keyword.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
84 ** (5) tkTEMP The "temp" or "temporary" keyword.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
85 ** (6) tkTRIGGER The "trigger" keyword.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
86 ** (7) tkEND The "end" keyword.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
87 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
88 ** Whitespace never causes a state transition and is always ignored.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
89 **
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
90 ** If we compile with SQLITE_OMIT_TRIGGER, all of the computation needed
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
91 ** to recognize the end of a trigger can be omitted. All we have to do
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
92 ** is look for a semicolon that is not part of an string or comment.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
93 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
94 int sqlite3_complete(const char *zSql){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
95 u8 state = 0; /* Current state, using numbers defined in header comment */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
96 u8 token; /* Value of the next token */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
97
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
98 #ifndef SQLITE_OMIT_TRIGGER
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
99 /* A complex statement machine used to detect the end of a CREATE TRIGGER
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
100 ** statement. This is the normal case.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
101 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
102 static const u8 trans[7][8] = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
103 /* Token: */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
104 /* State: ** SEMI WS OTHER EXPLAIN CREATE TEMP TRIGGER END */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
105 /* 0 START: */ { 0, 0, 1, 2, 3, 1, 1, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
106 /* 1 NORMAL: */ { 0, 1, 1, 1, 1, 1, 1, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
107 /* 2 EXPLAIN: */ { 0, 2, 1, 1, 3, 1, 1, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
108 /* 3 CREATE: */ { 0, 3, 1, 1, 1, 3, 4, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
109 /* 4 TRIGGER: */ { 5, 4, 4, 4, 4, 4, 4, 4, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
110 /* 5 SEMI: */ { 5, 5, 4, 4, 4, 4, 4, 6, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
111 /* 6 END: */ { 0, 6, 4, 4, 4, 4, 4, 4, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
112 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
113 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
114 /* If triggers are not suppored by this compile then the statement machine
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
115 ** used to detect the end of a statement is much simplier
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
116 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
117 static const u8 trans[2][3] = {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
118 /* Token: */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
119 /* State: ** SEMI WS OTHER */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
120 /* 0 START: */ { 0, 0, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
121 /* 1 NORMAL: */ { 0, 1, 1, },
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
122 };
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
123 #endif /* SQLITE_OMIT_TRIGGER */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
124
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
125 while( *zSql ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
126 switch( *zSql ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
127 case ';': { /* A semicolon */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
128 token = tkSEMI;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
129 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
130 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
131 case ' ':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
132 case '\r':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
133 case '\t':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
134 case '\n':
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
135 case '\f': { /* White space is ignored */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
136 token = tkWS;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
137 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
138 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
139 case '/': { /* C-style comments */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
140 if( zSql[1]!='*' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
141 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
142 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
143 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
144 zSql += 2;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
145 while( zSql[0] && (zSql[0]!='*' || zSql[1]!='/') ){ zSql++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
146 if( zSql[0]==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
147 zSql++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
148 token = tkWS;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
149 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
150 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
151 case '-': { /* SQL-style comments from "--" to end of line */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
152 if( zSql[1]!='-' ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
153 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
154 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
155 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
156 while( *zSql && *zSql!='\n' ){ zSql++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
157 if( *zSql==0 ) return state==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
158 token = tkWS;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
159 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
160 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
161 case '[': { /* Microsoft-style identifiers in [...] */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
162 zSql++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
163 while( *zSql && *zSql!=']' ){ zSql++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
164 if( *zSql==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
165 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
166 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
167 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
168 case '`': /* Grave-accent quoted symbols used by MySQL */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
169 case '"': /* single- and double-quoted strings */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
170 case '\'': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
171 int c = *zSql;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
172 zSql++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
173 while( *zSql && *zSql!=c ){ zSql++; }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
174 if( *zSql==0 ) return 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
175 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
176 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
177 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
178 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
179 int c;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
180 if( IdChar((u8)*zSql) ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
181 /* Keywords and unquoted identifiers */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
182 int nId;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
183 for(nId=1; IdChar(zSql[nId]); nId++){}
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
184 #ifdef SQLITE_OMIT_TRIGGER
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
185 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
186 #else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
187 switch( *zSql ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
188 case 'c': case 'C': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
189 if( nId==6 && sqlite3StrNICmp(zSql, "create", 6)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
190 token = tkCREATE;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
191 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
192 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
193 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
194 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
195 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
196 case 't': case 'T': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
197 if( nId==7 && sqlite3StrNICmp(zSql, "trigger", 7)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
198 token = tkTRIGGER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
199 }else if( nId==4 && sqlite3StrNICmp(zSql, "temp", 4)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
200 token = tkTEMP;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
201 }else if( nId==9 && sqlite3StrNICmp(zSql, "temporary", 9)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
202 token = tkTEMP;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
203 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
204 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
205 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
206 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
207 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
208 case 'e': case 'E': {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
209 if( nId==3 && sqlite3StrNICmp(zSql, "end", 3)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
210 token = tkEND;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
211 }else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
212 #ifndef SQLITE_OMIT_EXPLAIN
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
213 if( nId==7 && sqlite3StrNICmp(zSql, "explain", 7)==0 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
214 token = tkEXPLAIN;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
215 }else
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
216 #endif
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
217 {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
218 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
219 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
220 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
221 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
222 default: {
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
223 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
224 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
225 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
226 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
227 #endif /* SQLITE_OMIT_TRIGGER */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
228 zSql += nId-1;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
229 }else{
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
230 /* Operators and special symbols */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
231 token = tkOTHER;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
232 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
233 break;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
234 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
235 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
236 state = trans[state][token];
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
237 zSql++;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
238 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
239 return state==0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
240 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
241
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
242 #ifndef SQLITE_OMIT_UTF16
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
243 /*
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
244 ** This routine is the same as the sqlite3_complete() routine described
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
245 ** above, except that the parameter is required to be UTF-16 encoded, not
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
246 ** UTF-8.
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
247 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
248 int sqlite3_complete16(const void *zSql){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
249 sqlite3_value *pVal;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
250 char const *zSql8;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
251 int rc = 0;
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
252
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
253 pVal = sqlite3ValueNew();
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
254 sqlite3ValueSetStr(pVal, -1, zSql, SQLITE_UTF16NATIVE, SQLITE_STATIC);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
255 zSql8 = sqlite3ValueText(pVal, SQLITE_UTF8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
256 if( zSql8 ){
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
257 rc = sqlite3_complete(zSql8);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
258 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
259 sqlite3ValueFree(pVal);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
260 return sqlite3ApiExit(0, rc);
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
261 }
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
262 #endif /* SQLITE_OMIT_UTF16 */
b6b61becdf4e [svn] - add sqlite/ directory
nenolod
parents:
diff changeset
263 #endif /* SQLITE_OMIT_COMPLETE */