OLD | NEW |
1 /* | 1 /* |
2 ** 2001 September 15 | 2 ** 2001 September 15 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // The generated parser function takes a 4th argument as follows: | 27 // The generated parser function takes a 4th argument as follows: |
28 %extra_argument {Parse *pParse} | 28 %extra_argument {Parse *pParse} |
29 | 29 |
30 // This code runs whenever there is a syntax error | 30 // This code runs whenever there is a syntax error |
31 // | 31 // |
32 %syntax_error { | 32 %syntax_error { |
33 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */ | 33 UNUSED_PARAMETER(yymajor); /* Silence some compiler warnings */ |
34 assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */ | 34 assert( TOKEN.z[0] ); /* The tokenizer always gives us a token */ |
35 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); | 35 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); |
36 pParse->parseError = 1; | |
37 } | 36 } |
38 %stack_overflow { | 37 %stack_overflow { |
39 UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */ | 38 UNUSED_PARAMETER(yypMinor); /* Silence some compiler warnings */ |
40 sqlite3ErrorMsg(pParse, "parser stack overflow"); | 39 sqlite3ErrorMsg(pParse, "parser stack overflow"); |
41 pParse->parseError = 1; | |
42 } | 40 } |
43 | 41 |
44 // The name of the generated procedure that implements the parser | 42 // The name of the generated procedure that implements the parser |
45 // is as follows: | 43 // is as follows: |
46 %name sqlite3Parser | 44 %name sqlite3Parser |
47 | 45 |
48 // The following text is included near the beginning of the C source | 46 // The following text is included near the beginning of the C source |
49 // code file that implements the parser. | 47 // code file that implements the parser. |
50 // | 48 // |
51 %include { | 49 %include { |
(...skipping 18 matching lines...) Expand all Loading... |
70 Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ | 68 Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ |
71 Expr *pOffset; /* The OFFSET expression. NULL if there is none */ | 69 Expr *pOffset; /* The OFFSET expression. NULL if there is none */ |
72 }; | 70 }; |
73 | 71 |
74 /* | 72 /* |
75 ** An instance of this structure is used to store the LIKE, | 73 ** An instance of this structure is used to store the LIKE, |
76 ** GLOB, NOT LIKE, and NOT GLOB operators. | 74 ** GLOB, NOT LIKE, and NOT GLOB operators. |
77 */ | 75 */ |
78 struct LikeOp { | 76 struct LikeOp { |
79 Token eOperator; /* "like" or "glob" or "regexp" */ | 77 Token eOperator; /* "like" or "glob" or "regexp" */ |
80 int not; /* True if the NOT keyword is present */ | 78 int bNot; /* True if the NOT keyword is present */ |
81 }; | 79 }; |
82 | 80 |
83 /* | 81 /* |
84 ** An instance of the following structure describes the event of a | 82 ** An instance of the following structure describes the event of a |
85 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, | 83 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, |
86 ** TK_DELETE, or TK_INSTEAD. If the event is of the form | 84 ** TK_DELETE, or TK_INSTEAD. If the event is of the form |
87 ** | 85 ** |
88 ** UPDATE ON (a,b,c) | 86 ** UPDATE ON (a,b,c) |
89 ** | 87 ** |
90 ** Then the "b" IdList records the list "a,b,c". | 88 ** Then the "b" IdList records the list "a,b,c". |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 A = X; | 148 A = X; |
151 } | 149 } |
152 %type ifnotexists {int} | 150 %type ifnotexists {int} |
153 ifnotexists(A) ::= . {A = 0;} | 151 ifnotexists(A) ::= . {A = 0;} |
154 ifnotexists(A) ::= IF NOT EXISTS. {A = 1;} | 152 ifnotexists(A) ::= IF NOT EXISTS. {A = 1;} |
155 %type temp {int} | 153 %type temp {int} |
156 %ifndef SQLITE_OMIT_TEMPDB | 154 %ifndef SQLITE_OMIT_TEMPDB |
157 temp(A) ::= TEMP. {A = 1;} | 155 temp(A) ::= TEMP. {A = 1;} |
158 %endif SQLITE_OMIT_TEMPDB | 156 %endif SQLITE_OMIT_TEMPDB |
159 temp(A) ::= . {A = 0;} | 157 temp(A) ::= . {A = 0;} |
160 create_table_args ::= LP columnlist conslist_opt(X) RP(Y). { | 158 create_table_args ::= LP columnlist conslist_opt(X) RP(E) table_options(F). { |
161 sqlite3EndTable(pParse,&X,&Y,0); | 159 sqlite3EndTable(pParse,&X,&E,F,0); |
162 } | 160 } |
163 create_table_args ::= AS select(S). { | 161 create_table_args ::= AS select(S). { |
164 sqlite3EndTable(pParse,0,0,S); | 162 sqlite3EndTable(pParse,0,0,0,S); |
165 sqlite3SelectDelete(pParse->db, S); | 163 sqlite3SelectDelete(pParse->db, S); |
166 } | 164 } |
| 165 %type table_options {u8} |
| 166 table_options(A) ::= . {A = 0;} |
| 167 table_options(A) ::= WITHOUT nm(X). { |
| 168 if( X.n==5 && sqlite3_strnicmp(X.z,"rowid",5)==0 ){ |
| 169 A = TF_WithoutRowid; |
| 170 }else{ |
| 171 A = 0; |
| 172 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", X.n, X.z); |
| 173 } |
| 174 } |
167 columnlist ::= columnlist COMMA column. | 175 columnlist ::= columnlist COMMA column. |
168 columnlist ::= column. | 176 columnlist ::= column. |
169 | 177 |
170 // A "column" is a complete description of a single column in a | 178 // A "column" is a complete description of a single column in a |
171 // CREATE TABLE statement. This includes the column name, its | 179 // CREATE TABLE statement. This includes the column name, its |
172 // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES, | 180 // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES, |
173 // NOT NULL and so forth. | 181 // NOT NULL and so forth. |
174 // | 182 // |
175 column(A) ::= columnid(X) type carglist. { | 183 column(A) ::= columnid(X) type carglist. { |
176 A.z = X.z; | 184 A.z = X.z; |
177 A.n = (int)(pParse->sLastToken.z-X.z) + pParse->sLastToken.n; | 185 A.n = (int)(pParse->sLastToken.z-X.z) + pParse->sLastToken.n; |
178 } | 186 } |
179 columnid(A) ::= nm(X). { | 187 columnid(A) ::= nm(X). { |
180 sqlite3AddColumn(pParse,&X); | 188 sqlite3AddColumn(pParse,&X); |
181 A = X; | 189 A = X; |
| 190 pParse->constraintName.n = 0; |
182 } | 191 } |
183 | 192 |
184 | 193 |
185 // An IDENTIFIER can be a generic identifier, or one of several | 194 // An IDENTIFIER can be a generic identifier, or one of several |
186 // keywords. Any non-standard keyword can also be an identifier. | 195 // keywords. Any non-standard keyword can also be an identifier. |
187 // | 196 // |
188 %type id {Token} | 197 %token_class id ID|INDEXED. |
189 id(A) ::= ID(X). {A = X;} | |
190 id(A) ::= INDEXED(X). {A = X;} | |
191 | 198 |
192 // The following directive causes tokens ABORT, AFTER, ASC, etc. to | 199 // The following directive causes tokens ABORT, AFTER, ASC, etc. to |
193 // fallback to ID if they will not parse as their original value. | 200 // fallback to ID if they will not parse as their original value. |
194 // This obviates the need for the "id" nonterminal. | 201 // This obviates the need for the "id" nonterminal. |
195 // | 202 // |
196 %fallback ID | 203 %fallback ID |
197 ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW | 204 ABORT ACTION AFTER ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW |
198 CONFLICT DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR | 205 CONFLICT DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR |
199 IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN | 206 IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH NO PLAN |
200 QUERY KEY OF OFFSET PRAGMA RAISE RELEASE REPLACE RESTRICT ROW ROLLBACK | 207 QUERY KEY OF OFFSET PRAGMA RAISE RECURSIVE RELEASE REPLACE RESTRICT ROW |
201 SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL | 208 ROLLBACK SAVEPOINT TEMP TRIGGER VACUUM VIEW VIRTUAL WITH WITHOUT |
202 %ifdef SQLITE_OMIT_COMPOUND_SELECT | 209 %ifdef SQLITE_OMIT_COMPOUND_SELECT |
203 EXCEPT INTERSECT UNION | 210 EXCEPT INTERSECT UNION |
204 %endif SQLITE_OMIT_COMPOUND_SELECT | 211 %endif SQLITE_OMIT_COMPOUND_SELECT |
205 REINDEX RENAME CTIME_KW IF | 212 REINDEX RENAME CTIME_KW IF |
206 . | 213 . |
207 %wildcard ANY. | 214 %wildcard ANY. |
208 | 215 |
209 // Define operator precedence early so that this is the first occurance | 216 // Define operator precedence early so that this is the first occurrence |
210 // of the operator tokens in the grammer. Keeping the operators together | 217 // of the operator tokens in the grammer. Keeping the operators together |
211 // causes them to be assigned integer values that are close together, | 218 // causes them to be assigned integer values that are close together, |
212 // which keeps parser tables smaller. | 219 // which keeps parser tables smaller. |
213 // | 220 // |
214 // The token values assigned to these symbols is determined by the order | 221 // The token values assigned to these symbols is determined by the order |
215 // in which lemon first sees them. It must be the case that ISNULL/NOTNULL, | 222 // in which lemon first sees them. It must be the case that ISNULL/NOTNULL, |
216 // NE/EQ, GT/LE, and GE/LT are separated by only a single value. See | 223 // NE/EQ, GT/LE, and GE/LT are separated by only a single value. See |
217 // the sqlite3ExprIfFalse() routine for additional information on this | 224 // the sqlite3ExprIfFalse() routine for additional information on this |
218 // constraint. | 225 // constraint. |
219 // | 226 // |
220 %left OR. | 227 %left OR. |
221 %left AND. | 228 %left AND. |
222 %right NOT. | 229 %right NOT. |
223 %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ. | 230 %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ. |
224 %left GT LE LT GE. | 231 %left GT LE LT GE. |
225 %right ESCAPE. | 232 %right ESCAPE. |
226 %left BITAND BITOR LSHIFT RSHIFT. | 233 %left BITAND BITOR LSHIFT RSHIFT. |
227 %left PLUS MINUS. | 234 %left PLUS MINUS. |
228 %left STAR SLASH REM. | 235 %left STAR SLASH REM. |
229 %left CONCAT. | 236 %left CONCAT. |
230 %left COLLATE. | 237 %left COLLATE. |
231 %right BITNOT. | 238 %right BITNOT. |
232 | 239 |
233 // And "ids" is an identifer-or-string. | 240 // And "ids" is an identifer-or-string. |
234 // | 241 // |
235 %type ids {Token} | 242 %token_class ids ID|STRING. |
236 ids(A) ::= ID|STRING(X). {A = X;} | |
237 | 243 |
238 // The name of a column or table can be any of the following: | 244 // The name of a column or table can be any of the following: |
239 // | 245 // |
240 %type nm {Token} | 246 %type nm {Token} |
241 nm(A) ::= id(X). {A = X;} | 247 nm(A) ::= id(X). {A = X;} |
242 nm(A) ::= STRING(X). {A = X;} | 248 nm(A) ::= STRING(X). {A = X;} |
243 nm(A) ::= JOIN_KW(X). {A = X;} | 249 nm(A) ::= JOIN_KW(X). {A = X;} |
244 | 250 |
245 // A typetoken is really one or more tokens that form a type name such | 251 // A typetoken is really one or more tokens that form a type name such |
246 // as can be found after the column name in a CREATE TABLE statement. | 252 // as can be found after the column name in a CREATE TABLE statement. |
(...skipping 13 matching lines...) Expand all Loading... |
260 } | 266 } |
261 %type typename {Token} | 267 %type typename {Token} |
262 typename(A) ::= ids(X). {A = X;} | 268 typename(A) ::= ids(X). {A = X;} |
263 typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(int)(Y.z-X.z);} | 269 typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(int)(Y.z-X.z);} |
264 signed ::= plus_num. | 270 signed ::= plus_num. |
265 signed ::= minus_num. | 271 signed ::= minus_num. |
266 | 272 |
267 // "carglist" is a list of additional constraints that come after the | 273 // "carglist" is a list of additional constraints that come after the |
268 // column name and column type in a CREATE TABLE statement. | 274 // column name and column type in a CREATE TABLE statement. |
269 // | 275 // |
270 carglist ::= carglist carg. | 276 carglist ::= carglist ccons. |
271 carglist ::= . | 277 carglist ::= . |
272 carg ::= CONSTRAINT nm ccons. | 278 ccons ::= CONSTRAINT nm(X). {pParse->constraintName = X;} |
273 carg ::= ccons. | |
274 ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,&X);} | 279 ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,&X);} |
275 ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,&X);} | 280 ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,&X);} |
276 ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,&X);} | 281 ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,&X);} |
277 ccons ::= DEFAULT MINUS(A) term(X). { | 282 ccons ::= DEFAULT MINUS(A) term(X). { |
278 ExprSpan v; | 283 ExprSpan v; |
279 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, X.pExpr, 0, 0); | 284 v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, X.pExpr, 0, 0); |
280 v.zStart = A.z; | 285 v.zStart = A.z; |
281 v.zEnd = X.zEnd; | 286 v.zEnd = X.zEnd; |
282 sqlite3AddDefaultValue(pParse,&v); | 287 sqlite3AddDefaultValue(pParse,&v); |
283 } | 288 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 refact(A) ::= RESTRICT. { A = OE_Restrict; /* EV: R-33326-45252 */} | 331 refact(A) ::= RESTRICT. { A = OE_Restrict; /* EV: R-33326-45252 */} |
327 refact(A) ::= NO ACTION. { A = OE_None; /* EV: R-33326-45252 */} | 332 refact(A) ::= NO ACTION. { A = OE_None; /* EV: R-33326-45252 */} |
328 %type defer_subclause {int} | 333 %type defer_subclause {int} |
329 defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt. {A = 0;} | 334 defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt. {A = 0;} |
330 defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X). {A = X;} | 335 defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X). {A = X;} |
331 %type init_deferred_pred_opt {int} | 336 %type init_deferred_pred_opt {int} |
332 init_deferred_pred_opt(A) ::= . {A = 0;} | 337 init_deferred_pred_opt(A) ::= . {A = 0;} |
333 init_deferred_pred_opt(A) ::= INITIALLY DEFERRED. {A = 1;} | 338 init_deferred_pred_opt(A) ::= INITIALLY DEFERRED. {A = 1;} |
334 init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;} | 339 init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;} |
335 | 340 |
336 // For the time being, the only constraint we care about is the primary | 341 conslist_opt(A) ::= . {A.n = 0; A.z = 0;} |
337 // key and UNIQUE. Both create indices. | 342 conslist_opt(A) ::= COMMA(X) conslist. {A = X;} |
338 // | 343 conslist ::= conslist tconscomma tcons. |
339 conslist_opt(A) ::= . {A.n = 0; A.z = 0;} | |
340 conslist_opt(A) ::= COMMA(X) conslist. {A = X;} | |
341 conslist ::= conslist COMMA tcons. | |
342 conslist ::= conslist tcons. | |
343 conslist ::= tcons. | 344 conslist ::= tcons. |
344 tcons ::= CONSTRAINT nm. | 345 tconscomma ::= COMMA. {pParse->constraintName.n = 0;} |
| 346 tconscomma ::= . |
| 347 tcons ::= CONSTRAINT nm(X). {pParse->constraintName = X;} |
345 tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R). | 348 tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R). |
346 {sqlite3AddPrimaryKey(pParse,X,R,I,0);} | 349 {sqlite3AddPrimaryKey(pParse,X,R,I,0);} |
347 tcons ::= UNIQUE LP idxlist(X) RP onconf(R). | 350 tcons ::= UNIQUE LP idxlist(X) RP onconf(R). |
348 {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);} | 351 {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);} |
349 tcons ::= CHECK LP expr(E) RP onconf. | 352 tcons ::= CHECK LP expr(E) RP onconf. |
350 {sqlite3AddCheckConstraint(pParse,E.pExpr);} | 353 {sqlite3AddCheckConstraint(pParse,E.pExpr);} |
351 tcons ::= FOREIGN KEY LP idxlist(FA) RP | 354 tcons ::= FOREIGN KEY LP idxlist(FA) RP |
352 REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). { | 355 REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). { |
353 sqlite3CreateForeignKey(pParse, FA, &T, TA, R); | 356 sqlite3CreateForeignKey(pParse, FA, &T, TA, R); |
354 sqlite3DeferForeignKey(pParse, D); | 357 sqlite3DeferForeignKey(pParse, D); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 sqlite3CreateView(pParse, &X, &Y, &Z, S, T, E); | 390 sqlite3CreateView(pParse, &X, &Y, &Z, S, T, E); |
388 } | 391 } |
389 cmd ::= DROP VIEW ifexists(E) fullname(X). { | 392 cmd ::= DROP VIEW ifexists(E) fullname(X). { |
390 sqlite3DropTable(pParse, X, 1, E); | 393 sqlite3DropTable(pParse, X, 1, E); |
391 } | 394 } |
392 %endif SQLITE_OMIT_VIEW | 395 %endif SQLITE_OMIT_VIEW |
393 | 396 |
394 //////////////////////// The SELECT statement ///////////////////////////////// | 397 //////////////////////// The SELECT statement ///////////////////////////////// |
395 // | 398 // |
396 cmd ::= select(X). { | 399 cmd ::= select(X). { |
397 SelectDest dest = {SRT_Output, 0, 0, 0, 0}; | 400 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0}; |
398 sqlite3Select(pParse, X, &dest); | 401 sqlite3Select(pParse, X, &dest); |
399 sqlite3SelectDelete(pParse->db, X); | 402 sqlite3SelectDelete(pParse->db, X); |
400 } | 403 } |
401 | 404 |
402 %type select {Select*} | 405 %type select {Select*} |
403 %destructor select {sqlite3SelectDelete(pParse->db, $$);} | 406 %destructor select {sqlite3SelectDelete(pParse->db, $$);} |
| 407 %type selectnowith {Select*} |
| 408 %destructor selectnowith {sqlite3SelectDelete(pParse->db, $$);} |
404 %type oneselect {Select*} | 409 %type oneselect {Select*} |
405 %destructor oneselect {sqlite3SelectDelete(pParse->db, $$);} | 410 %destructor oneselect {sqlite3SelectDelete(pParse->db, $$);} |
406 | 411 |
407 select(A) ::= oneselect(X). {A = X;} | 412 select(A) ::= with(W) selectnowith(X). { |
| 413 Select *p = X, *pNext, *pLoop; |
| 414 if( p ){ |
| 415 int cnt = 0, mxSelect; |
| 416 p->pWith = W; |
| 417 if( p->pPrior ){ |
| 418 pNext = 0; |
| 419 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){ |
| 420 pLoop->pNext = pNext; |
| 421 pLoop->selFlags |= SF_Compound; |
| 422 } |
| 423 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT]; |
| 424 if( mxSelect && cnt>mxSelect ){ |
| 425 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT"); |
| 426 } |
| 427 } |
| 428 }else{ |
| 429 sqlite3WithDelete(pParse->db, W); |
| 430 } |
| 431 A = p; |
| 432 } |
| 433 |
| 434 selectnowith(A) ::= oneselect(X). {A = X;} |
408 %ifndef SQLITE_OMIT_COMPOUND_SELECT | 435 %ifndef SQLITE_OMIT_COMPOUND_SELECT |
409 select(A) ::= select(X) multiselect_op(Y) oneselect(Z). { | 436 selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z). { |
410 if( Z ){ | 437 Select *pRhs = Z; |
411 Z->op = (u8)Y; | 438 if( pRhs && pRhs->pPrior ){ |
412 Z->pPrior = X; | 439 SrcList *pFrom; |
| 440 Token x; |
| 441 x.n = 0; |
| 442 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0); |
| 443 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0); |
| 444 } |
| 445 if( pRhs ){ |
| 446 pRhs->op = (u8)Y; |
| 447 pRhs->pPrior = X; |
| 448 if( Y!=TK_ALL ) pParse->hasCompound = 1; |
413 }else{ | 449 }else{ |
414 sqlite3SelectDelete(pParse->db, X); | 450 sqlite3SelectDelete(pParse->db, X); |
415 } | 451 } |
416 A = Z; | 452 A = pRhs; |
417 } | 453 } |
418 %type multiselect_op {int} | 454 %type multiselect_op {int} |
419 multiselect_op(A) ::= UNION(OP). {A = @OP;} | 455 multiselect_op(A) ::= UNION(OP). {A = @OP;} |
420 multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} | 456 multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} |
421 multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;} | 457 multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;} |
422 %endif SQLITE_OMIT_COMPOUND_SELECT | 458 %endif SQLITE_OMIT_COMPOUND_SELECT |
423 oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) | 459 oneselect(A) ::= SELECT(S) distinct(D) selcollist(W) from(X) where_opt(Y) |
424 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { | 460 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { |
425 A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); | 461 A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); |
| 462 #if SELECTTRACE_ENABLED |
| 463 /* Populate the Select.zSelName[] string that is used to help with |
| 464 ** query planner debugging, to differentiate between multiple Select |
| 465 ** objects in a complex query. |
| 466 ** |
| 467 ** If the SELECT keyword is immediately followed by a C-style comment |
| 468 ** then extract the first few alphanumeric characters from within that |
| 469 ** comment to be the zSelName value. Otherwise, the label is #N where |
| 470 ** is an integer that is incremented with each SELECT statement seen. |
| 471 */ |
| 472 if( A!=0 ){ |
| 473 const char *z = S.z+6; |
| 474 int i; |
| 475 sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "#%d", |
| 476 ++pParse->nSelect); |
| 477 while( z[0]==' ' ) z++; |
| 478 if( z[0]=='/' && z[1]=='*' ){ |
| 479 z += 2; |
| 480 while( z[0]==' ' ) z++; |
| 481 for(i=0; sqlite3Isalnum(z[i]); i++){} |
| 482 sqlite3_snprintf(sizeof(A->zSelName), A->zSelName, "%.*s", i, z); |
| 483 } |
| 484 } |
| 485 #endif /* SELECTRACE_ENABLED */ |
| 486 } |
| 487 oneselect(A) ::= values(X). {A = X;} |
| 488 |
| 489 %type values {Select*} |
| 490 %destructor values {sqlite3SelectDelete(pParse->db, $$);} |
| 491 values(A) ::= VALUES LP nexprlist(X) RP. { |
| 492 A = sqlite3SelectNew(pParse,X,0,0,0,0,0,SF_Values,0,0); |
| 493 } |
| 494 values(A) ::= values(X) COMMA LP exprlist(Y) RP. { |
| 495 Select *pRight = sqlite3SelectNew(pParse,Y,0,0,0,0,0,SF_Values,0,0); |
| 496 if( pRight ){ |
| 497 pRight->op = TK_ALL; |
| 498 pRight->pPrior = X; |
| 499 A = pRight; |
| 500 }else{ |
| 501 A = X; |
| 502 } |
426 } | 503 } |
427 | 504 |
428 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is | 505 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is |
429 // present and false (0) if it is not. | 506 // present and false (0) if it is not. |
430 // | 507 // |
431 %type distinct {int} | 508 %type distinct {u16} |
432 distinct(A) ::= DISTINCT. {A = 1;} | 509 distinct(A) ::= DISTINCT. {A = SF_Distinct;} |
433 distinct(A) ::= ALL. {A = 0;} | 510 distinct(A) ::= ALL. {A = 0;} |
434 distinct(A) ::= . {A = 0;} | 511 distinct(A) ::= . {A = 0;} |
435 | 512 |
436 // selcollist is a list of expressions that are to become the return | 513 // selcollist is a list of expressions that are to become the return |
437 // values of the SELECT statement. The "*" in statements like | 514 // values of the SELECT statement. The "*" in statements like |
438 // "SELECT * FROM ..." is encoded as a special expression with an | 515 // "SELECT * FROM ..." is encoded as a special expression with an |
439 // opcode of TK_ALL. | 516 // opcode of TK_ALL. |
440 // | 517 // |
441 %type selcollist {ExprList*} | 518 %type selcollist {ExprList*} |
442 %destructor selcollist {sqlite3ExprListDelete(pParse->db, $$);} | 519 %destructor selcollist {sqlite3ExprListDelete(pParse->db, $$);} |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 562 } |
486 | 563 |
487 // "seltablist" is a "Select Table List" - the content of the FROM clause | 564 // "seltablist" is a "Select Table List" - the content of the FROM clause |
488 // in a SELECT statement. "stl_prefix" is a prefix of this list. | 565 // in a SELECT statement. "stl_prefix" is a prefix of this list. |
489 // | 566 // |
490 stl_prefix(A) ::= seltablist(X) joinop(Y). { | 567 stl_prefix(A) ::= seltablist(X) joinop(Y). { |
491 A = X; | 568 A = X; |
492 if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].jointype = (u8)Y; | 569 if( ALWAYS(A && A->nSrc>0) ) A->a[A->nSrc-1].jointype = (u8)Y; |
493 } | 570 } |
494 stl_prefix(A) ::= . {A = 0;} | 571 stl_prefix(A) ::= . {A = 0;} |
495 seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N) usi
ng_opt(U). { | 572 seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) |
| 573 on_opt(N) using_opt(U). { |
496 A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); | 574 A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); |
497 sqlite3SrcListIndexedBy(pParse, A, &I); | 575 sqlite3SrcListIndexedBy(pParse, A, &I); |
498 } | 576 } |
499 %ifndef SQLITE_OMIT_SUBQUERY | 577 %ifndef SQLITE_OMIT_SUBQUERY |
500 seltablist(A) ::= stl_prefix(X) LP select(S) RP | 578 seltablist(A) ::= stl_prefix(X) LP select(S) RP |
501 as(Z) on_opt(N) using_opt(U). { | 579 as(Z) on_opt(N) using_opt(U). { |
502 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); | 580 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); |
503 } | 581 } |
504 seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP | 582 seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP |
505 as(Z) on_opt(N) using_opt(U). { | 583 as(Z) on_opt(N) using_opt(U). { |
506 if( X==0 && Z.n==0 && N==0 && U==0 ){ | 584 if( X==0 && Z.n==0 && N==0 && U==0 ){ |
507 A = F; | 585 A = F; |
| 586 }else if( F->nSrc==1 ){ |
| 587 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,0,N,U); |
| 588 if( A ){ |
| 589 struct SrcList_item *pNew = &A->a[A->nSrc-1]; |
| 590 struct SrcList_item *pOld = F->a; |
| 591 pNew->zName = pOld->zName; |
| 592 pNew->zDatabase = pOld->zDatabase; |
| 593 pNew->pSelect = pOld->pSelect; |
| 594 pOld->zName = pOld->zDatabase = 0; |
| 595 pOld->pSelect = 0; |
| 596 } |
| 597 sqlite3SrcListDelete(pParse->db, F); |
508 }else{ | 598 }else{ |
509 Select *pSubquery; | 599 Select *pSubquery; |
510 sqlite3SrcListShiftJoinType(F); | 600 sqlite3SrcListShiftJoinType(F); |
511 pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); | 601 pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,SF_NestedFrom,0,0); |
512 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U); | 602 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U); |
513 } | 603 } |
514 } | 604 } |
515 | |
516 // A seltablist_paren nonterminal represents anything in a FROM that | |
517 // is contained inside parentheses. This can be either a subquery or | |
518 // a grouping of table and subqueries. | |
519 // | |
520 // %type seltablist_paren {Select*} | |
521 // %destructor seltablist_paren {sqlite3SelectDelete(pParse->db, $$);} | |
522 // seltablist_paren(A) ::= select(S). {A = S;} | |
523 // seltablist_paren(A) ::= seltablist(F). { | |
524 // sqlite3SrcListShiftJoinType(F); | |
525 // A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); | |
526 // } | |
527 %endif SQLITE_OMIT_SUBQUERY | 605 %endif SQLITE_OMIT_SUBQUERY |
528 | 606 |
529 %type dbnm {Token} | 607 %type dbnm {Token} |
530 dbnm(A) ::= . {A.z=0; A.n=0;} | 608 dbnm(A) ::= . {A.z=0; A.n=0;} |
531 dbnm(A) ::= DOT nm(X). {A = X;} | 609 dbnm(A) ::= DOT nm(X). {A = X;} |
532 | 610 |
533 %type fullname {SrcList*} | 611 %type fullname {SrcList*} |
534 %destructor fullname {sqlite3SrcListDelete(pParse->db, $$);} | 612 %destructor fullname {sqlite3SrcListDelete(pParse->db, $$);} |
535 fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);} | 613 fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);} |
536 | 614 |
(...skipping 20 matching lines...) Expand all Loading... |
557 // normally illegal. The sqlite3SrcListIndexedBy() function | 635 // normally illegal. The sqlite3SrcListIndexedBy() function |
558 // recognizes and interprets this as a special case. | 636 // recognizes and interprets this as a special case. |
559 // | 637 // |
560 %type indexed_opt {Token} | 638 %type indexed_opt {Token} |
561 indexed_opt(A) ::= . {A.z=0; A.n=0;} | 639 indexed_opt(A) ::= . {A.z=0; A.n=0;} |
562 indexed_opt(A) ::= INDEXED BY nm(X). {A = X;} | 640 indexed_opt(A) ::= INDEXED BY nm(X). {A = X;} |
563 indexed_opt(A) ::= NOT INDEXED. {A.z=0; A.n=1;} | 641 indexed_opt(A) ::= NOT INDEXED. {A.z=0; A.n=1;} |
564 | 642 |
565 %type using_opt {IdList*} | 643 %type using_opt {IdList*} |
566 %destructor using_opt {sqlite3IdListDelete(pParse->db, $$);} | 644 %destructor using_opt {sqlite3IdListDelete(pParse->db, $$);} |
567 using_opt(U) ::= USING LP inscollist(L) RP. {U = L;} | 645 using_opt(U) ::= USING LP idlist(L) RP. {U = L;} |
568 using_opt(U) ::= . {U = 0;} | 646 using_opt(U) ::= . {U = 0;} |
569 | 647 |
570 | 648 |
571 %type orderby_opt {ExprList*} | 649 %type orderby_opt {ExprList*} |
572 %destructor orderby_opt {sqlite3ExprListDelete(pParse->db, $$);} | 650 %destructor orderby_opt {sqlite3ExprListDelete(pParse->db, $$);} |
573 %type sortlist {ExprList*} | 651 %type sortlist {ExprList*} |
574 %destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);} | 652 %destructor sortlist {sqlite3ExprListDelete(pParse->db, $$);} |
575 %type sortitem {Expr*} | |
576 %destructor sortitem {sqlite3ExprDelete(pParse->db, $$);} | |
577 | 653 |
578 orderby_opt(A) ::= . {A = 0;} | 654 orderby_opt(A) ::= . {A = 0;} |
579 orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} | 655 orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} |
580 sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). { | 656 sortlist(A) ::= sortlist(X) COMMA expr(Y) sortorder(Z). { |
581 A = sqlite3ExprListAppend(pParse,X,Y); | 657 A = sqlite3ExprListAppend(pParse,X,Y.pExpr); |
582 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; | 658 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; |
583 } | 659 } |
584 sortlist(A) ::= sortitem(Y) sortorder(Z). { | 660 sortlist(A) ::= expr(Y) sortorder(Z). { |
585 A = sqlite3ExprListAppend(pParse,0,Y); | 661 A = sqlite3ExprListAppend(pParse,0,Y.pExpr); |
586 if( A && ALWAYS(A->a) ) A->a[0].sortOrder = (u8)Z; | 662 if( A && ALWAYS(A->a) ) A->a[0].sortOrder = (u8)Z; |
587 } | 663 } |
588 sortitem(A) ::= expr(X). {A = X.pExpr;} | |
589 | 664 |
590 %type sortorder {int} | 665 %type sortorder {int} |
591 | 666 |
592 sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} | 667 sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} |
593 sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} | 668 sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} |
594 sortorder(A) ::= . {A = SQLITE_SO_ASC;} | 669 sortorder(A) ::= . {A = SQLITE_SO_ASC;} |
595 | 670 |
596 %type groupby_opt {ExprList*} | 671 %type groupby_opt {ExprList*} |
597 %destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);} | 672 %destructor groupby_opt {sqlite3ExprListDelete(pParse->db, $$);} |
598 groupby_opt(A) ::= . {A = 0;} | 673 groupby_opt(A) ::= . {A = 0;} |
(...skipping 20 matching lines...) Expand all Loading... |
619 limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;} | 694 limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;} |
620 limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X.pExpr; A.pOffset = 0;} | 695 limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X.pExpr; A.pOffset = 0;} |
621 limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y). | 696 limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y). |
622 {A.pLimit = X.pExpr; A.pOffset = Y.pExpr;} | 697 {A.pLimit = X.pExpr; A.pOffset = Y.pExpr;} |
623 limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). | 698 limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). |
624 {A.pOffset = X.pExpr; A.pLimit = Y.pExpr;} | 699 {A.pOffset = X.pExpr; A.pLimit = Y.pExpr;} |
625 | 700 |
626 /////////////////////////// The DELETE statement ///////////////////////////// | 701 /////////////////////////// The DELETE statement ///////////////////////////// |
627 // | 702 // |
628 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT | 703 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
629 cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W) | 704 cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W) |
630 orderby_opt(O) limit_opt(L). { | 705 orderby_opt(O) limit_opt(L). { |
| 706 sqlite3WithPush(pParse, C, 1); |
631 sqlite3SrcListIndexedBy(pParse, X, &I); | 707 sqlite3SrcListIndexedBy(pParse, X, &I); |
632 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "DELETE"); | 708 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "DELETE"); |
633 sqlite3DeleteFrom(pParse,X,W); | 709 sqlite3DeleteFrom(pParse,X,W); |
634 } | 710 } |
635 %endif | 711 %endif |
636 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT | 712 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
637 cmd ::= DELETE FROM fullname(X) indexed_opt(I) where_opt(W). { | 713 cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W). { |
| 714 sqlite3WithPush(pParse, C, 1); |
638 sqlite3SrcListIndexedBy(pParse, X, &I); | 715 sqlite3SrcListIndexedBy(pParse, X, &I); |
639 sqlite3DeleteFrom(pParse,X,W); | 716 sqlite3DeleteFrom(pParse,X,W); |
640 } | 717 } |
641 %endif | 718 %endif |
642 | 719 |
643 %type where_opt {Expr*} | 720 %type where_opt {Expr*} |
644 %destructor where_opt {sqlite3ExprDelete(pParse->db, $$);} | 721 %destructor where_opt {sqlite3ExprDelete(pParse->db, $$);} |
645 | 722 |
646 where_opt(A) ::= . {A = 0;} | 723 where_opt(A) ::= . {A = 0;} |
647 where_opt(A) ::= WHERE expr(X). {A = X.pExpr;} | 724 where_opt(A) ::= WHERE expr(X). {A = X.pExpr;} |
648 | 725 |
649 ////////////////////////// The UPDATE command //////////////////////////////// | 726 ////////////////////////// The UPDATE command //////////////////////////////// |
650 // | 727 // |
651 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT | 728 %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
652 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W)
orderby_opt(O) limit_opt(L). { | 729 cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) |
| 730 where_opt(W) orderby_opt(O) limit_opt(L). { |
| 731 sqlite3WithPush(pParse, C, 1); |
653 sqlite3SrcListIndexedBy(pParse, X, &I); | 732 sqlite3SrcListIndexedBy(pParse, X, &I); |
654 sqlite3ExprListCheckLength(pParse,Y,"set list"); | 733 sqlite3ExprListCheckLength(pParse,Y,"set list"); |
655 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "UPDATE"); | 734 W = sqlite3LimitWhere(pParse, X, W, O, L.pLimit, L.pOffset, "UPDATE"); |
656 sqlite3Update(pParse,X,Y,W,R); | 735 sqlite3Update(pParse,X,Y,W,R); |
657 } | 736 } |
658 %endif | 737 %endif |
659 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT | 738 %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT |
660 cmd ::= UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) where_opt(W).
{ | 739 cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y) |
| 740 where_opt(W). { |
| 741 sqlite3WithPush(pParse, C, 1); |
661 sqlite3SrcListIndexedBy(pParse, X, &I); | 742 sqlite3SrcListIndexedBy(pParse, X, &I); |
662 sqlite3ExprListCheckLength(pParse,Y,"set list"); | 743 sqlite3ExprListCheckLength(pParse,Y,"set list"); |
663 sqlite3Update(pParse,X,Y,W,R); | 744 sqlite3Update(pParse,X,Y,W,R); |
664 } | 745 } |
665 %endif | 746 %endif |
666 | 747 |
667 %type setlist {ExprList*} | 748 %type setlist {ExprList*} |
668 %destructor setlist {sqlite3ExprListDelete(pParse->db, $$);} | 749 %destructor setlist {sqlite3ExprListDelete(pParse->db, $$);} |
669 | 750 |
670 setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y). { | 751 setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y). { |
671 A = sqlite3ExprListAppend(pParse, Z, Y.pExpr); | 752 A = sqlite3ExprListAppend(pParse, Z, Y.pExpr); |
672 sqlite3ExprListSetName(pParse, A, &X, 1); | 753 sqlite3ExprListSetName(pParse, A, &X, 1); |
673 } | 754 } |
674 setlist(A) ::= nm(X) EQ expr(Y). { | 755 setlist(A) ::= nm(X) EQ expr(Y). { |
675 A = sqlite3ExprListAppend(pParse, 0, Y.pExpr); | 756 A = sqlite3ExprListAppend(pParse, 0, Y.pExpr); |
676 sqlite3ExprListSetName(pParse, A, &X, 1); | 757 sqlite3ExprListSetName(pParse, A, &X, 1); |
677 } | 758 } |
678 | 759 |
679 ////////////////////////// The INSERT command ///////////////////////////////// | 760 ////////////////////////// The INSERT command ///////////////////////////////// |
680 // | 761 // |
681 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) | 762 cmd ::= with(W) insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S). { |
682 VALUES LP itemlist(Y) RP. | 763 sqlite3WithPush(pParse, W, 1); |
683 {sqlite3Insert(pParse, X, Y, 0, F, R);} | 764 sqlite3Insert(pParse, X, S, F, R); |
684 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S). | 765 } |
685 {sqlite3Insert(pParse, X, 0, S, F, R);} | 766 cmd ::= with(W) insert_cmd(R) INTO fullname(X) inscollist_opt(F) DEFAULT VALUES. |
686 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) DEFAULT VALUES. | 767 { |
687 {sqlite3Insert(pParse, X, 0, 0, F, R);} | 768 sqlite3WithPush(pParse, W, 1); |
| 769 sqlite3Insert(pParse, X, 0, F, R); |
| 770 } |
688 | 771 |
689 %type insert_cmd {u8} | 772 %type insert_cmd {u8} |
690 insert_cmd(A) ::= INSERT orconf(R). {A = R;} | 773 insert_cmd(A) ::= INSERT orconf(R). {A = R;} |
691 insert_cmd(A) ::= REPLACE. {A = OE_Replace;} | 774 insert_cmd(A) ::= REPLACE. {A = OE_Replace;} |
692 | 775 |
693 | |
694 %type itemlist {ExprList*} | |
695 %destructor itemlist {sqlite3ExprListDelete(pParse->db, $$);} | |
696 | |
697 itemlist(A) ::= itemlist(X) COMMA expr(Y). | |
698 {A = sqlite3ExprListAppend(pParse,X,Y.pExpr);} | |
699 itemlist(A) ::= expr(X). | |
700 {A = sqlite3ExprListAppend(pParse,0,X.pExpr);} | |
701 | |
702 %type inscollist_opt {IdList*} | 776 %type inscollist_opt {IdList*} |
703 %destructor inscollist_opt {sqlite3IdListDelete(pParse->db, $$);} | 777 %destructor inscollist_opt {sqlite3IdListDelete(pParse->db, $$);} |
704 %type inscollist {IdList*} | 778 %type idlist {IdList*} |
705 %destructor inscollist {sqlite3IdListDelete(pParse->db, $$);} | 779 %destructor idlist {sqlite3IdListDelete(pParse->db, $$);} |
706 | 780 |
707 inscollist_opt(A) ::= . {A = 0;} | 781 inscollist_opt(A) ::= . {A = 0;} |
708 inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;} | 782 inscollist_opt(A) ::= LP idlist(X) RP. {A = X;} |
709 inscollist(A) ::= inscollist(X) COMMA nm(Y). | 783 idlist(A) ::= idlist(X) COMMA nm(Y). |
710 {A = sqlite3IdListAppend(pParse->db,X,&Y);} | 784 {A = sqlite3IdListAppend(pParse->db,X,&Y);} |
711 inscollist(A) ::= nm(Y). | 785 idlist(A) ::= nm(Y). |
712 {A = sqlite3IdListAppend(pParse->db,0,&Y);} | 786 {A = sqlite3IdListAppend(pParse->db,0,&Y);} |
713 | 787 |
714 /////////////////////////// Expression Processing ///////////////////////////// | 788 /////////////////////////// Expression Processing ///////////////////////////// |
715 // | 789 // |
716 | 790 |
717 %type expr {ExprSpan} | 791 %type expr {ExprSpan} |
718 %destructor expr {sqlite3ExprDelete(pParse->db, $$.pExpr);} | 792 %destructor expr {sqlite3ExprDelete(pParse->db, $$.pExpr);} |
719 %type term {ExprSpan} | 793 %type term {ExprSpan} |
720 %destructor term {sqlite3ExprDelete(pParse->db, $$.pExpr);} | 794 %destructor term {sqlite3ExprDelete(pParse->db, $$.pExpr);} |
721 | 795 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). { | 828 expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). { |
755 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); | 829 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); |
756 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y); | 830 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y); |
757 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Z); | 831 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Z); |
758 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); | 832 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); |
759 A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); | 833 A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); |
760 spanSet(&A,&X,&Z); | 834 spanSet(&A,&X,&Z); |
761 } | 835 } |
762 term(A) ::= INTEGER|FLOAT|BLOB(X). {spanExpr(&A, pParse, @X, &X);} | 836 term(A) ::= INTEGER|FLOAT|BLOB(X). {spanExpr(&A, pParse, @X, &X);} |
763 term(A) ::= STRING(X). {spanExpr(&A, pParse, @X, &X);} | 837 term(A) ::= STRING(X). {spanExpr(&A, pParse, @X, &X);} |
764 expr(A) ::= REGISTER(X). { | 838 expr(A) ::= VARIABLE(X). { |
765 /* When doing a nested parse, one can include terms in an expression | 839 if( X.n>=2 && X.z[0]=='#' && sqlite3Isdigit(X.z[1]) ){ |
766 ** that look like this: #1 #2 ... These terms refer to registers | 840 /* When doing a nested parse, one can include terms in an expression |
767 ** in the virtual machine. #N is the N-th register. */ | 841 ** that look like this: #1 #2 ... These terms refer to registers |
768 if( pParse->nested==0 ){ | 842 ** in the virtual machine. #N is the N-th register. */ |
769 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &X); | 843 if( pParse->nested==0 ){ |
770 A.pExpr = 0; | 844 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &X); |
| 845 A.pExpr = 0; |
| 846 }else{ |
| 847 A.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &X); |
| 848 if( A.pExpr ) sqlite3GetInt32(&X.z[1], &A.pExpr->iTable); |
| 849 } |
771 }else{ | 850 }else{ |
772 A.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &X); | 851 spanExpr(&A, pParse, TK_VARIABLE, &X); |
773 if( A.pExpr ) sqlite3GetInt32(&X.z[1], &A.pExpr->iTable); | 852 sqlite3ExprAssignVarNumber(pParse, A.pExpr); |
774 } | 853 } |
775 spanSet(&A, &X, &X); | 854 spanSet(&A, &X, &X); |
776 } | 855 } |
777 expr(A) ::= VARIABLE(X). { | |
778 spanExpr(&A, pParse, TK_VARIABLE, &X); | |
779 sqlite3ExprAssignVarNumber(pParse, A.pExpr); | |
780 spanSet(&A, &X, &X); | |
781 } | |
782 expr(A) ::= expr(E) COLLATE ids(C). { | 856 expr(A) ::= expr(E) COLLATE ids(C). { |
783 A.pExpr = sqlite3ExprSetCollByToken(pParse, E.pExpr, &C); | 857 A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C); |
784 A.zStart = E.zStart; | 858 A.zStart = E.zStart; |
785 A.zEnd = &C.z[C.n]; | 859 A.zEnd = &C.z[C.n]; |
786 } | 860 } |
787 %ifndef SQLITE_OMIT_CAST | 861 %ifndef SQLITE_OMIT_CAST |
788 expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { | 862 expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { |
789 A.pExpr = sqlite3PExpr(pParse, TK_CAST, E.pExpr, 0, &T); | 863 A.pExpr = sqlite3PExpr(pParse, TK_CAST, E.pExpr, 0, &T); |
790 spanSet(&A,&X,&Y); | 864 spanSet(&A,&X,&Y); |
791 } | 865 } |
792 %endif SQLITE_OMIT_CAST | 866 %endif SQLITE_OMIT_CAST |
793 expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). { | 867 expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP(E). { |
794 if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ | 868 if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ |
795 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X); | 869 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X); |
796 } | 870 } |
797 A.pExpr = sqlite3ExprFunction(pParse, Y, &X); | 871 A.pExpr = sqlite3ExprFunction(pParse, Y, &X); |
798 spanSet(&A,&X,&E); | 872 spanSet(&A,&X,&E); |
799 if( D && A.pExpr ){ | 873 if( D && A.pExpr ){ |
800 A.pExpr->flags |= EP_Distinct; | 874 A.pExpr->flags |= EP_Distinct; |
801 } | 875 } |
802 } | 876 } |
803 expr(A) ::= ID(X) LP STAR RP(E). { | 877 expr(A) ::= id(X) LP STAR RP(E). { |
804 A.pExpr = sqlite3ExprFunction(pParse, 0, &X); | 878 A.pExpr = sqlite3ExprFunction(pParse, 0, &X); |
805 spanSet(&A,&X,&E); | 879 spanSet(&A,&X,&E); |
806 } | 880 } |
807 term(A) ::= CTIME_KW(OP). { | 881 term(A) ::= CTIME_KW(OP). { |
808 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are | 882 A.pExpr = sqlite3ExprFunction(pParse, 0, &OP); |
809 ** treated as functions that return constants */ | |
810 A.pExpr = sqlite3ExprFunction(pParse, 0,&OP); | |
811 if( A.pExpr ){ | |
812 A.pExpr->op = TK_CONST_FUNC; | |
813 } | |
814 spanSet(&A, &OP, &OP); | 883 spanSet(&A, &OP, &OP); |
815 } | 884 } |
816 | 885 |
817 %include { | 886 %include { |
818 /* This routine constructs a binary expression node out of two ExprSpan | 887 /* This routine constructs a binary expression node out of two ExprSpan |
819 ** objects and uses the result to populate a new ExprSpan object. | 888 ** objects and uses the result to populate a new ExprSpan object. |
820 */ | 889 */ |
821 static void spanBinaryExpr( | 890 static void spanBinaryExpr( |
822 ExprSpan *pOut, /* Write the result here */ | 891 ExprSpan *pOut, /* Write the result here */ |
823 Parse *pParse, /* The parsing context. Errors accumulate here */ | 892 Parse *pParse, /* The parsing context. Errors accumulate here */ |
(...skipping 13 matching lines...) Expand all Loading... |
837 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 906 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
838 expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 907 expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
839 expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y). | 908 expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y). |
840 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 909 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
841 expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). | 910 expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). |
842 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 911 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
843 expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). | 912 expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). |
844 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 913 {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
845 expr(A) ::= expr(X) CONCAT(OP) expr(Y). {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} | 914 expr(A) ::= expr(X) CONCAT(OP) expr(Y). {spanBinaryExpr(&A,pParse,@OP,&X,&Y);} |
846 %type likeop {struct LikeOp} | 915 %type likeop {struct LikeOp} |
847 likeop(A) ::= LIKE_KW(X). {A.eOperator = X; A.not = 0;} | 916 likeop(A) ::= LIKE_KW|MATCH(X). {A.eOperator = X; A.bNot = 0;} |
848 likeop(A) ::= NOT LIKE_KW(X). {A.eOperator = X; A.not = 1;} | 917 likeop(A) ::= NOT LIKE_KW|MATCH(X). {A.eOperator = X; A.bNot = 1;} |
849 likeop(A) ::= MATCH(X). {A.eOperator = X; A.not = 0;} | |
850 likeop(A) ::= NOT MATCH(X). {A.eOperator = X; A.not = 1;} | |
851 expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE_KW] { | 918 expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE_KW] { |
852 ExprList *pList; | 919 ExprList *pList; |
853 pList = sqlite3ExprListAppend(pParse,0, Y.pExpr); | 920 pList = sqlite3ExprListAppend(pParse,0, Y.pExpr); |
854 pList = sqlite3ExprListAppend(pParse,pList, X.pExpr); | 921 pList = sqlite3ExprListAppend(pParse,pList, X.pExpr); |
855 A.pExpr = sqlite3ExprFunction(pParse, pList, &OP.eOperator); | 922 A.pExpr = sqlite3ExprFunction(pParse, pList, &OP.eOperator); |
856 if( OP.not ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); | 923 if( OP.bNot ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); |
857 A.zStart = X.zStart; | 924 A.zStart = X.zStart; |
858 A.zEnd = Y.zEnd; | 925 A.zEnd = Y.zEnd; |
859 if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc; | 926 if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc; |
860 } | 927 } |
861 expr(A) ::= expr(X) likeop(OP) expr(Y) ESCAPE expr(E). [LIKE_KW] { | 928 expr(A) ::= expr(X) likeop(OP) expr(Y) ESCAPE expr(E). [LIKE_KW] { |
862 ExprList *pList; | 929 ExprList *pList; |
863 pList = sqlite3ExprListAppend(pParse,0, Y.pExpr); | 930 pList = sqlite3ExprListAppend(pParse,0, Y.pExpr); |
864 pList = sqlite3ExprListAppend(pParse,pList, X.pExpr); | 931 pList = sqlite3ExprListAppend(pParse,pList, X.pExpr); |
865 pList = sqlite3ExprListAppend(pParse,pList, E.pExpr); | 932 pList = sqlite3ExprListAppend(pParse,pList, E.pExpr); |
866 A.pExpr = sqlite3ExprFunction(pParse, pList, &OP.eOperator); | 933 A.pExpr = sqlite3ExprFunction(pParse, pList, &OP.eOperator); |
867 if( OP.not ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); | 934 if( OP.bNot ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); |
868 A.zStart = X.zStart; | 935 A.zStart = X.zStart; |
869 A.zEnd = E.zEnd; | 936 A.zEnd = E.zEnd; |
870 if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc; | 937 if( A.pExpr ) A.pExpr->flags |= EP_InfixFunc; |
871 } | 938 } |
872 | 939 |
873 %include { | 940 %include { |
874 /* Construct an expression node for a unary postfix operator | 941 /* Construct an expression node for a unary postfix operator |
875 */ | 942 */ |
876 static void spanUnaryPostfix( | 943 static void spanUnaryPostfix( |
877 ExprSpan *pOut, /* Write the new expression node here */ | 944 ExprSpan *pOut, /* Write the new expression node here */ |
878 Parse *pParse, /* Parsing context to record errors */ | 945 Parse *pParse, /* Parsing context to record errors */ |
879 int op, /* The operator */ | 946 int op, /* The operator */ |
880 ExprSpan *pOperand, /* The operand */ | 947 ExprSpan *pOperand, /* The operand */ |
881 Token *pPostOp /* The operand token for setting the span */ | 948 Token *pPostOp /* The operand token for setting the span */ |
882 ){ | 949 ){ |
883 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0); | 950 pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0); |
884 pOut->zStart = pOperand->zStart; | 951 pOut->zStart = pOperand->zStart; |
885 pOut->zEnd = &pPostOp->z[pPostOp->n]; | 952 pOut->zEnd = &pPostOp->z[pPostOp->n]; |
886 } | 953 } |
887 } | 954 } |
888 | 955 |
889 expr(A) ::= expr(X) ISNULL|NOTNULL(E). {spanUnaryPostfix(&A,pParse,@E,&X,&E);} | 956 expr(A) ::= expr(X) ISNULL|NOTNULL(E). {spanUnaryPostfix(&A,pParse,@E,&X,&E);} |
890 expr(A) ::= expr(X) NOT NULL(E). {spanUnaryPostfix(&A,pParse,TK_NOTNULL,&X,&E);} | 957 expr(A) ::= expr(X) NOT NULL(E). {spanUnaryPostfix(&A,pParse,TK_NOTNULL,&X,&E);} |
891 | 958 |
892 %include { | 959 %include { |
893 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a | 960 /* A routine to convert a binary TK_IS or TK_ISNOT expression into a |
894 ** unary TK_ISNULL or TK_NOTNULL expression. */ | 961 ** unary TK_ISNULL or TK_NOTNULL expression. */ |
895 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){ | 962 static void binaryToUnaryIfNull(Parse *pParse, Expr *pY, Expr *pA, int op){ |
896 sqlite3 *db = pParse->db; | 963 sqlite3 *db = pParse->db; |
897 if( db->mallocFailed==0 && pY->op==TK_NULL ){ | 964 if( pY && pA && pY->op==TK_NULL ){ |
898 pA->op = (u8)op; | 965 pA->op = (u8)op; |
899 sqlite3ExprDelete(db, pA->pRight); | 966 sqlite3ExprDelete(db, pA->pRight); |
900 pA->pRight = 0; | 967 pA->pRight = 0; |
901 } | 968 } |
902 } | 969 } |
903 } | 970 } |
904 | 971 |
905 // expr1 IS expr2 | 972 // expr1 IS expr2 |
906 // expr1 IS NOT expr2 | 973 // expr1 IS NOT expr2 |
907 // | 974 // |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 /* Expressions of the form | 1034 /* Expressions of the form |
968 ** | 1035 ** |
969 ** expr1 IN () | 1036 ** expr1 IN () |
970 ** expr1 NOT IN () | 1037 ** expr1 NOT IN () |
971 ** | 1038 ** |
972 ** simplify to constants 0 (false) and 1 (true), respectively, | 1039 ** simplify to constants 0 (false) and 1 (true), respectively, |
973 ** regardless of the value of expr1. | 1040 ** regardless of the value of expr1. |
974 */ | 1041 */ |
975 A.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[N]); | 1042 A.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[N]); |
976 sqlite3ExprDelete(pParse->db, X.pExpr); | 1043 sqlite3ExprDelete(pParse->db, X.pExpr); |
| 1044 }else if( Y->nExpr==1 ){ |
| 1045 /* Expressions of the form: |
| 1046 ** |
| 1047 ** expr1 IN (?1) |
| 1048 ** expr1 NOT IN (?2) |
| 1049 ** |
| 1050 ** with exactly one value on the RHS can be simplified to something |
| 1051 ** like this: |
| 1052 ** |
| 1053 ** expr1 == ?1 |
| 1054 ** expr1 <> ?2 |
| 1055 ** |
| 1056 ** But, the RHS of the == or <> is marked with the EP_Generic flag |
| 1057 ** so that it may not contribute to the computation of comparison |
| 1058 ** affinity or the collating sequence to use for comparison. Otherwise, |
| 1059 ** the semantics would be subtly different from IN or NOT IN. |
| 1060 */ |
| 1061 Expr *pRHS = Y->a[0].pExpr; |
| 1062 Y->a[0].pExpr = 0; |
| 1063 sqlite3ExprListDelete(pParse->db, Y); |
| 1064 /* pRHS cannot be NULL because a malloc error would have been detected |
| 1065 ** before now and control would have never reached this point */ |
| 1066 if( ALWAYS(pRHS) ){ |
| 1067 pRHS->flags &= ~EP_Collate; |
| 1068 pRHS->flags |= EP_Generic; |
| 1069 } |
| 1070 A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, X.pExpr, pRHS, 0); |
977 }else{ | 1071 }else{ |
978 A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); | 1072 A.pExpr = sqlite3PExpr(pParse, TK_IN, X.pExpr, 0, 0); |
979 if( A.pExpr ){ | 1073 if( A.pExpr ){ |
980 A.pExpr->x.pList = Y; | 1074 A.pExpr->x.pList = Y; |
981 sqlite3ExprSetHeight(pParse, A.pExpr); | 1075 sqlite3ExprSetHeight(pParse, A.pExpr); |
982 }else{ | 1076 }else{ |
983 sqlite3ExprListDelete(pParse->db, Y); | 1077 sqlite3ExprListDelete(pParse->db, Y); |
984 } | 1078 } |
985 if( N ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); | 1079 if( N ) A.pExpr = sqlite3PExpr(pParse, TK_NOT, A.pExpr, 0, 0); |
986 } | 1080 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 }else{ | 1129 }else{ |
1036 sqlite3SelectDelete(pParse->db, Y); | 1130 sqlite3SelectDelete(pParse->db, Y); |
1037 } | 1131 } |
1038 A.zStart = B.z; | 1132 A.zStart = B.z; |
1039 A.zEnd = &E.z[E.n]; | 1133 A.zEnd = &E.z[E.n]; |
1040 } | 1134 } |
1041 %endif SQLITE_OMIT_SUBQUERY | 1135 %endif SQLITE_OMIT_SUBQUERY |
1042 | 1136 |
1043 /* CASE expressions */ | 1137 /* CASE expressions */ |
1044 expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { | 1138 expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { |
1045 A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, Z, 0); | 1139 A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0, 0); |
1046 if( A.pExpr ){ | 1140 if( A.pExpr ){ |
1047 A.pExpr->x.pList = Y; | 1141 A.pExpr->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y; |
1048 sqlite3ExprSetHeight(pParse, A.pExpr); | 1142 sqlite3ExprSetHeight(pParse, A.pExpr); |
1049 }else{ | 1143 }else{ |
1050 sqlite3ExprListDelete(pParse->db, Y); | 1144 sqlite3ExprListDelete(pParse->db, Y); |
| 1145 sqlite3ExprDelete(pParse->db, Z); |
1051 } | 1146 } |
1052 A.zStart = C.z; | 1147 A.zStart = C.z; |
1053 A.zEnd = &E.z[E.n]; | 1148 A.zEnd = &E.z[E.n]; |
1054 } | 1149 } |
1055 %type case_exprlist {ExprList*} | 1150 %type case_exprlist {ExprList*} |
1056 %destructor case_exprlist {sqlite3ExprListDelete(pParse->db, $$);} | 1151 %destructor case_exprlist {sqlite3ExprListDelete(pParse->db, $$);} |
1057 case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). { | 1152 case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). { |
1058 A = sqlite3ExprListAppend(pParse,X, Y.pExpr); | 1153 A = sqlite3ExprListAppend(pParse,X, Y.pExpr); |
1059 A = sqlite3ExprListAppend(pParse,A, Z.pExpr); | 1154 A = sqlite3ExprListAppend(pParse,A, Z.pExpr); |
1060 } | 1155 } |
(...skipping 19 matching lines...) Expand all Loading... |
1080 exprlist(A) ::= . {A = 0;} | 1175 exprlist(A) ::= . {A = 0;} |
1081 nexprlist(A) ::= nexprlist(X) COMMA expr(Y). | 1176 nexprlist(A) ::= nexprlist(X) COMMA expr(Y). |
1082 {A = sqlite3ExprListAppend(pParse,X,Y.pExpr);} | 1177 {A = sqlite3ExprListAppend(pParse,X,Y.pExpr);} |
1083 nexprlist(A) ::= expr(Y). | 1178 nexprlist(A) ::= expr(Y). |
1084 {A = sqlite3ExprListAppend(pParse,0,Y.pExpr);} | 1179 {A = sqlite3ExprListAppend(pParse,0,Y.pExpr);} |
1085 | 1180 |
1086 | 1181 |
1087 ///////////////////////////// The CREATE INDEX command /////////////////////// | 1182 ///////////////////////////// The CREATE INDEX command /////////////////////// |
1088 // | 1183 // |
1089 cmd ::= createkw(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D) | 1184 cmd ::= createkw(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D) |
1090 ON nm(Y) LP idxlist(Z) RP(E). { | 1185 ON nm(Y) LP idxlist(Z) RP where_opt(W). { |
1091 sqlite3CreateIndex(pParse, &X, &D, | 1186 sqlite3CreateIndex(pParse, &X, &D, |
1092 sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U, | 1187 sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U, |
1093 &S, &E, SQLITE_SO_ASC, NE); | 1188 &S, W, SQLITE_SO_ASC, NE); |
1094 } | 1189 } |
1095 | 1190 |
1096 %type uniqueflag {int} | 1191 %type uniqueflag {int} |
1097 uniqueflag(A) ::= UNIQUE. {A = OE_Abort;} | 1192 uniqueflag(A) ::= UNIQUE. {A = OE_Abort;} |
1098 uniqueflag(A) ::= . {A = OE_None;} | 1193 uniqueflag(A) ::= . {A = OE_None;} |
1099 | 1194 |
1100 %type idxlist {ExprList*} | 1195 %type idxlist {ExprList*} |
1101 %destructor idxlist {sqlite3ExprListDelete(pParse->db, $$);} | 1196 %destructor idxlist {sqlite3ExprListDelete(pParse->db, $$);} |
1102 %type idxlist_opt {ExprList*} | 1197 %type idxlist_opt {ExprList*} |
1103 %destructor idxlist_opt {sqlite3ExprListDelete(pParse->db, $$);} | 1198 %destructor idxlist_opt {sqlite3ExprListDelete(pParse->db, $$);} |
1104 | 1199 |
1105 idxlist_opt(A) ::= . {A = 0;} | 1200 idxlist_opt(A) ::= . {A = 0;} |
1106 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} | 1201 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} |
1107 idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { | 1202 idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { |
1108 Expr *p = 0; | 1203 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); |
1109 if( C.n>0 ){ | |
1110 p = sqlite3Expr(pParse->db, TK_COLUMN, 0); | |
1111 sqlite3ExprSetCollByToken(pParse, p, &C); | |
1112 } | |
1113 A = sqlite3ExprListAppend(pParse,X, p); | 1204 A = sqlite3ExprListAppend(pParse,X, p); |
1114 sqlite3ExprListSetName(pParse,A,&Y,1); | 1205 sqlite3ExprListSetName(pParse,A,&Y,1); |
1115 sqlite3ExprListCheckLength(pParse, A, "index"); | 1206 sqlite3ExprListCheckLength(pParse, A, "index"); |
1116 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; | 1207 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; |
1117 } | 1208 } |
1118 idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { | 1209 idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { |
1119 Expr *p = 0; | 1210 Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); |
1120 if( C.n>0 ){ | |
1121 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); | |
1122 sqlite3ExprSetCollByToken(pParse, p, &C); | |
1123 } | |
1124 A = sqlite3ExprListAppend(pParse,0, p); | 1211 A = sqlite3ExprListAppend(pParse,0, p); |
1125 sqlite3ExprListSetName(pParse, A, &Y, 1); | 1212 sqlite3ExprListSetName(pParse, A, &Y, 1); |
1126 sqlite3ExprListCheckLength(pParse, A, "index"); | 1213 sqlite3ExprListCheckLength(pParse, A, "index"); |
1127 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; | 1214 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; |
1128 } | 1215 } |
1129 | 1216 |
1130 %type collate {Token} | 1217 %type collate {Token} |
1131 collate(C) ::= . {C.z = 0; C.n = 0;} | 1218 collate(C) ::= . {C.z = 0; C.n = 0;} |
1132 collate(C) ::= COLLATE ids(X). {C = X;} | 1219 collate(C) ::= COLLATE ids(X). {C = X;} |
1133 | 1220 |
(...skipping 21 matching lines...) Expand all Loading... |
1155 {sqlite3Pragma(pParse,&X,&Z,&Y,1);} | 1242 {sqlite3Pragma(pParse,&X,&Z,&Y,1);} |
1156 cmd ::= PRAGMA nm(X) dbnm(Z) LP minus_num(Y) RP. | 1243 cmd ::= PRAGMA nm(X) dbnm(Z) LP minus_num(Y) RP. |
1157 {sqlite3Pragma(pParse,&X,&Z,&Y,1);} | 1244 {sqlite3Pragma(pParse,&X,&Z,&Y,1);} |
1158 | 1245 |
1159 nmnum(A) ::= plus_num(X). {A = X;} | 1246 nmnum(A) ::= plus_num(X). {A = X;} |
1160 nmnum(A) ::= nm(X). {A = X;} | 1247 nmnum(A) ::= nm(X). {A = X;} |
1161 nmnum(A) ::= ON(X). {A = X;} | 1248 nmnum(A) ::= ON(X). {A = X;} |
1162 nmnum(A) ::= DELETE(X). {A = X;} | 1249 nmnum(A) ::= DELETE(X). {A = X;} |
1163 nmnum(A) ::= DEFAULT(X). {A = X;} | 1250 nmnum(A) ::= DEFAULT(X). {A = X;} |
1164 %endif SQLITE_OMIT_PRAGMA | 1251 %endif SQLITE_OMIT_PRAGMA |
1165 plus_num(A) ::= plus_opt number(X). {A = X;} | 1252 %token_class number INTEGER|FLOAT. |
| 1253 plus_num(A) ::= PLUS number(X). {A = X;} |
| 1254 plus_num(A) ::= number(X). {A = X;} |
1166 minus_num(A) ::= MINUS number(X). {A = X;} | 1255 minus_num(A) ::= MINUS number(X). {A = X;} |
1167 number(A) ::= INTEGER|FLOAT(X). {A = X;} | |
1168 plus_opt ::= PLUS. | |
1169 plus_opt ::= . | |
1170 | |
1171 //////////////////////////// The CREATE TRIGGER command ///////////////////// | 1256 //////////////////////////// The CREATE TRIGGER command ///////////////////// |
1172 | 1257 |
1173 %ifndef SQLITE_OMIT_TRIGGER | 1258 %ifndef SQLITE_OMIT_TRIGGER |
1174 | 1259 |
1175 cmd ::= createkw trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). { | 1260 cmd ::= createkw trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). { |
1176 Token all; | 1261 Token all; |
1177 all.z = A.z; | 1262 all.z = A.z; |
1178 all.n = (int)(Z.z - A.z) + Z.n; | 1263 all.n = (int)(Z.z - A.z) + Z.n; |
1179 sqlite3FinishTrigger(pParse, S, &all); | 1264 sqlite3FinishTrigger(pParse, S, &all); |
1180 } | 1265 } |
1181 | 1266 |
1182 trigger_decl(A) ::= temp(T) TRIGGER ifnotexists(NOERR) nm(B) dbnm(Z) | 1267 trigger_decl(A) ::= temp(T) TRIGGER ifnotexists(NOERR) nm(B) dbnm(Z) |
1183 trigger_time(C) trigger_event(D) | 1268 trigger_time(C) trigger_event(D) |
1184 ON fullname(E) foreach_clause when_clause(G). { | 1269 ON fullname(E) foreach_clause when_clause(G). { |
1185 sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, G, T, NOERR); | 1270 sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, G, T, NOERR); |
1186 A = (Z.n==0?B:Z); | 1271 A = (Z.n==0?B:Z); |
1187 } | 1272 } |
1188 | 1273 |
1189 %type trigger_time {int} | 1274 %type trigger_time {int} |
1190 trigger_time(A) ::= BEFORE. { A = TK_BEFORE; } | 1275 trigger_time(A) ::= BEFORE. { A = TK_BEFORE; } |
1191 trigger_time(A) ::= AFTER. { A = TK_AFTER; } | 1276 trigger_time(A) ::= AFTER. { A = TK_AFTER; } |
1192 trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;} | 1277 trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;} |
1193 trigger_time(A) ::= . { A = TK_BEFORE; } | 1278 trigger_time(A) ::= . { A = TK_BEFORE; } |
1194 | 1279 |
1195 %type trigger_event {struct TrigEvent} | 1280 %type trigger_event {struct TrigEvent} |
1196 %destructor trigger_event {sqlite3IdListDelete(pParse->db, $$.b);} | 1281 %destructor trigger_event {sqlite3IdListDelete(pParse->db, $$.b);} |
1197 trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;} | 1282 trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;} |
1198 trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;} | 1283 trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;} |
1199 trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X;} | 1284 trigger_event(A) ::= UPDATE OF idlist(X). {A.a = TK_UPDATE; A.b = X;} |
1200 | 1285 |
1201 foreach_clause ::= . | 1286 foreach_clause ::= . |
1202 foreach_clause ::= FOR EACH ROW. | 1287 foreach_clause ::= FOR EACH ROW. |
1203 | 1288 |
1204 %type when_clause {Expr*} | 1289 %type when_clause {Expr*} |
1205 %destructor when_clause {sqlite3ExprDelete(pParse->db, $$);} | 1290 %destructor when_clause {sqlite3ExprDelete(pParse->db, $$);} |
1206 when_clause(A) ::= . { A = 0; } | 1291 when_clause(A) ::= . { A = 0; } |
1207 when_clause(A) ::= WHEN expr(X). { A = X.pExpr; } | 1292 when_clause(A) ::= WHEN expr(X). { A = X.pExpr; } |
1208 | 1293 |
1209 %type trigger_cmd_list {TriggerStep*} | 1294 %type trigger_cmd_list {TriggerStep*} |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 | 1337 |
1253 | 1338 |
1254 %type trigger_cmd {TriggerStep*} | 1339 %type trigger_cmd {TriggerStep*} |
1255 %destructor trigger_cmd {sqlite3DeleteTriggerStep(pParse->db, $$);} | 1340 %destructor trigger_cmd {sqlite3DeleteTriggerStep(pParse->db, $$);} |
1256 // UPDATE | 1341 // UPDATE |
1257 trigger_cmd(A) ::= | 1342 trigger_cmd(A) ::= |
1258 UPDATE orconf(R) trnm(X) tridxby SET setlist(Y) where_opt(Z). | 1343 UPDATE orconf(R) trnm(X) tridxby SET setlist(Y) where_opt(Z). |
1259 { A = sqlite3TriggerUpdateStep(pParse->db, &X, Y, Z, R); } | 1344 { A = sqlite3TriggerUpdateStep(pParse->db, &X, Y, Z, R); } |
1260 | 1345 |
1261 // INSERT | 1346 // INSERT |
1262 trigger_cmd(A) ::= | |
1263 insert_cmd(R) INTO trnm(X) inscollist_opt(F) VALUES LP itemlist(Y) RP. | |
1264 {A = sqlite3TriggerInsertStep(pParse->db, &X, F, Y, 0, R);} | |
1265 | |
1266 trigger_cmd(A) ::= insert_cmd(R) INTO trnm(X) inscollist_opt(F) select(S). | 1347 trigger_cmd(A) ::= insert_cmd(R) INTO trnm(X) inscollist_opt(F) select(S). |
1267 {A = sqlite3TriggerInsertStep(pParse->db, &X, F, 0, S, R);} | 1348 {A = sqlite3TriggerInsertStep(pParse->db, &X, F, S, R);} |
1268 | 1349 |
1269 // DELETE | 1350 // DELETE |
1270 trigger_cmd(A) ::= DELETE FROM trnm(X) tridxby where_opt(Y). | 1351 trigger_cmd(A) ::= DELETE FROM trnm(X) tridxby where_opt(Y). |
1271 {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);} | 1352 {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);} |
1272 | 1353 |
1273 // SELECT | 1354 // SELECT |
1274 trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(pParse->db, X); } | 1355 trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(pParse->db, X); } |
1275 | 1356 |
1276 // The special RAISE expression that may occur in trigger programs | 1357 // The special RAISE expression that may occur in trigger programs |
1277 expr(A) ::= RAISE(X) LP IGNORE RP(Y). { | 1358 expr(A) ::= RAISE(X) LP IGNORE RP(Y). { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 sqlite3AlterBeginAddColumn(pParse, X); | 1429 sqlite3AlterBeginAddColumn(pParse, X); |
1349 } | 1430 } |
1350 kwcolumn_opt ::= . | 1431 kwcolumn_opt ::= . |
1351 kwcolumn_opt ::= COLUMNKW. | 1432 kwcolumn_opt ::= COLUMNKW. |
1352 %endif SQLITE_OMIT_ALTERTABLE | 1433 %endif SQLITE_OMIT_ALTERTABLE |
1353 | 1434 |
1354 //////////////////////// CREATE VIRTUAL TABLE ... ///////////////////////////// | 1435 //////////////////////// CREATE VIRTUAL TABLE ... ///////////////////////////// |
1355 %ifndef SQLITE_OMIT_VIRTUALTABLE | 1436 %ifndef SQLITE_OMIT_VIRTUALTABLE |
1356 cmd ::= create_vtab. {sqlite3VtabFinishParse(pParse,0);} | 1437 cmd ::= create_vtab. {sqlite3VtabFinishParse(pParse,0);} |
1357 cmd ::= create_vtab LP vtabarglist RP(X). {sqlite3VtabFinishParse(pParse,&X);} | 1438 cmd ::= create_vtab LP vtabarglist RP(X). {sqlite3VtabFinishParse(pParse,&X);} |
1358 create_vtab ::= createkw VIRTUAL TABLE nm(X) dbnm(Y) USING nm(Z). { | 1439 create_vtab ::= createkw VIRTUAL TABLE ifnotexists(E) |
1359 sqlite3VtabBeginParse(pParse, &X, &Y, &Z); | 1440 nm(X) dbnm(Y) USING nm(Z). { |
| 1441 sqlite3VtabBeginParse(pParse, &X, &Y, &Z, E); |
1360 } | 1442 } |
1361 vtabarglist ::= vtabarg. | 1443 vtabarglist ::= vtabarg. |
1362 vtabarglist ::= vtabarglist COMMA vtabarg. | 1444 vtabarglist ::= vtabarglist COMMA vtabarg. |
1363 vtabarg ::= . {sqlite3VtabArgInit(pParse);} | 1445 vtabarg ::= . {sqlite3VtabArgInit(pParse);} |
1364 vtabarg ::= vtabarg vtabargtoken. | 1446 vtabarg ::= vtabarg vtabargtoken. |
1365 vtabargtoken ::= ANY(X). {sqlite3VtabArgExtend(pParse,&X);} | 1447 vtabargtoken ::= ANY(X). {sqlite3VtabArgExtend(pParse,&X);} |
1366 vtabargtoken ::= lp anylist RP(X). {sqlite3VtabArgExtend(pParse,&X);} | 1448 vtabargtoken ::= lp anylist RP(X). {sqlite3VtabArgExtend(pParse,&X);} |
1367 lp ::= LP(X). {sqlite3VtabArgExtend(pParse,&X);} | 1449 lp ::= LP(X). {sqlite3VtabArgExtend(pParse,&X);} |
1368 anylist ::= . | 1450 anylist ::= . |
1369 anylist ::= anylist LP anylist RP. | 1451 anylist ::= anylist LP anylist RP. |
1370 anylist ::= anylist ANY. | 1452 anylist ::= anylist ANY. |
1371 %endif SQLITE_OMIT_VIRTUALTABLE | 1453 %endif SQLITE_OMIT_VIRTUALTABLE |
| 1454 |
| 1455 |
| 1456 //////////////////////// COMMON TABLE EXPRESSIONS //////////////////////////// |
| 1457 %type with {With*} |
| 1458 %type wqlist {With*} |
| 1459 %destructor with {sqlite3WithDelete(pParse->db, $$);} |
| 1460 %destructor wqlist {sqlite3WithDelete(pParse->db, $$);} |
| 1461 |
| 1462 with(A) ::= . {A = 0;} |
| 1463 %ifndef SQLITE_OMIT_CTE |
| 1464 with(A) ::= WITH wqlist(W). { A = W; } |
| 1465 with(A) ::= WITH RECURSIVE wqlist(W). { A = W; } |
| 1466 |
| 1467 wqlist(A) ::= nm(X) idxlist_opt(Y) AS LP select(Z) RP. { |
| 1468 A = sqlite3WithAdd(pParse, 0, &X, Y, Z); |
| 1469 } |
| 1470 wqlist(A) ::= wqlist(W) COMMA nm(X) idxlist_opt(Y) AS LP select(Z) RP. { |
| 1471 A = sqlite3WithAdd(pParse, W, &X, Y, Z); |
| 1472 } |
| 1473 %endif SQLITE_OMIT_CTE |
OLD | NEW |