aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/src/parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/src/parse.y')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/src/parse.y1114
1 files changed, 1114 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/src/parse.y b/libraries/sqlite/unix/sqlite-3.5.1/src/parse.y
new file mode 100644
index 0000000..5077daf
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/src/parse.y
@@ -0,0 +1,1114 @@
1/*
2** 2001 September 15
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This file contains SQLite's grammar for SQL. Process this file
13** using the lemon parser generator to generate C code that runs
14** the parser. Lemon will also generate a header file containing
15** numeric codes for all of the tokens.
16**
17** @(#) $Id: parse.y,v 1.234 2007/08/21 10:44:16 drh Exp $
18*/
19
20// All token codes are small integers with #defines that begin with "TK_"
21%token_prefix TK_
22
23// The type of the data attached to each token is Token. This is also the
24// default type for non-terminals.
25//
26%token_type {Token}
27%default_type {Token}
28
29// The generated parser function takes a 4th argument as follows:
30%extra_argument {Parse *pParse}
31
32// This code runs whenever there is a syntax error
33//
34%syntax_error {
35 if( !pParse->parseError ){
36 if( TOKEN.z[0] ){
37 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN);
38 }else{
39 sqlite3ErrorMsg(pParse, "incomplete SQL statement");
40 }
41 pParse->parseError = 1;
42 }
43}
44%stack_overflow {
45 sqlite3ErrorMsg(pParse, "parser stack overflow");
46 pParse->parseError = 1;
47}
48
49// The name of the generated procedure that implements the parser
50// is as follows:
51%name sqlite3Parser
52
53// The following text is included near the beginning of the C source
54// code file that implements the parser.
55//
56%include {
57#include "sqliteInt.h"
58
59/*
60** An instance of this structure holds information about the
61** LIMIT clause of a SELECT statement.
62*/
63struct LimitVal {
64 Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */
65 Expr *pOffset; /* The OFFSET expression. NULL if there is none */
66};
67
68/*
69** An instance of this structure is used to store the LIKE,
70** GLOB, NOT LIKE, and NOT GLOB operators.
71*/
72struct LikeOp {
73 Token eOperator; /* "like" or "glob" or "regexp" */
74 int not; /* True if the NOT keyword is present */
75};
76
77/*
78** An instance of the following structure describes the event of a
79** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
80** TK_DELETE, or TK_INSTEAD. If the event is of the form
81**
82** UPDATE ON (a,b,c)
83**
84** Then the "b" IdList records the list "a,b,c".
85*/
86struct TrigEvent { int a; IdList * b; };
87
88/*
89** An instance of this structure holds the ATTACH key and the key type.
90*/
91struct AttachKey { int type; Token key; };
92
93} // end %include
94
95// Input is a single SQL command
96input ::= cmdlist.
97cmdlist ::= cmdlist ecmd.
98cmdlist ::= ecmd.
99cmdx ::= cmd. { sqlite3FinishCoding(pParse); }
100ecmd ::= SEMI.
101ecmd ::= explain cmdx SEMI.
102explain ::= . { sqlite3BeginParse(pParse, 0); }
103%ifndef SQLITE_OMIT_EXPLAIN
104explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); }
105explain ::= EXPLAIN QUERY PLAN. { sqlite3BeginParse(pParse, 2); }
106%endif SQLITE_OMIT_EXPLAIN
107
108///////////////////// Begin and end transactions. ////////////////////////////
109//
110
111cmd ::= BEGIN transtype(Y) trans_opt. {sqlite3BeginTransaction(pParse, Y);}
112trans_opt ::= .
113trans_opt ::= TRANSACTION.
114trans_opt ::= TRANSACTION nm.
115%type transtype {int}
116transtype(A) ::= . {A = TK_DEFERRED;}
117transtype(A) ::= DEFERRED(X). {A = @X;}
118transtype(A) ::= IMMEDIATE(X). {A = @X;}
119transtype(A) ::= EXCLUSIVE(X). {A = @X;}
120cmd ::= COMMIT trans_opt. {sqlite3CommitTransaction(pParse);}
121cmd ::= END trans_opt. {sqlite3CommitTransaction(pParse);}
122cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);}
123
124///////////////////// The CREATE TABLE statement ////////////////////////////
125//
126cmd ::= create_table create_table_args.
127create_table ::= CREATE temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). {
128 sqlite3StartTable(pParse,&Y,&Z,T,0,0,E);
129}
130%type ifnotexists {int}
131ifnotexists(A) ::= . {A = 0;}
132ifnotexists(A) ::= IF NOT EXISTS. {A = 1;}
133%type temp {int}
134%ifndef SQLITE_OMIT_TEMPDB
135temp(A) ::= TEMP. {A = 1;}
136%endif SQLITE_OMIT_TEMPDB
137temp(A) ::= . {A = 0;}
138create_table_args ::= LP columnlist conslist_opt(X) RP(Y). {
139 sqlite3EndTable(pParse,&X,&Y,0);
140}
141create_table_args ::= AS select(S). {
142 sqlite3EndTable(pParse,0,0,S);
143 sqlite3SelectDelete(S);
144}
145columnlist ::= columnlist COMMA column.
146columnlist ::= column.
147
148// A "column" is a complete description of a single column in a
149// CREATE TABLE statement. This includes the column name, its
150// datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES,
151// NOT NULL and so forth.
152//
153column(A) ::= columnid(X) type carglist. {
154 A.z = X.z;
155 A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n;
156}
157columnid(A) ::= nm(X). {
158 sqlite3AddColumn(pParse,&X);
159 A = X;
160}
161
162
163// An IDENTIFIER can be a generic identifier, or one of several
164// keywords. Any non-standard keyword can also be an identifier.
165//
166%type id {Token}
167id(A) ::= ID(X). {A = X;}
168
169// The following directive causes tokens ABORT, AFTER, ASC, etc. to
170// fallback to ID if they will not parse as their original value.
171// This obviates the need for the "id" nonterminal.
172//
173%fallback ID
174 ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT
175 DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
176 IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH PLAN
177 QUERY KEY OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW
178 TEMP TRIGGER VACUUM VIEW VIRTUAL
179%ifdef SQLITE_OMIT_COMPOUND_SELECT
180 EXCEPT INTERSECT UNION
181%endif SQLITE_OMIT_COMPOUND_SELECT
182 REINDEX RENAME CTIME_KW IF
183 .
184%wildcard ANY.
185
186// Define operator precedence early so that this is the first occurance
187// of the operator tokens in the grammer. Keeping the operators together
188// causes them to be assigned integer values that are close together,
189// which keeps parser tables smaller.
190//
191// The token values assigned to these symbols is determined by the order
192// in which lemon first sees them. It must be the case that ISNULL/NOTNULL,
193// NE/EQ, GT/LE, and GE/LT are separated by only a single value. See
194// the sqlite3ExprIfFalse() routine for additional information on this
195// constraint.
196//
197%left OR.
198%left AND.
199%right NOT.
200%left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
201%left GT LE LT GE.
202%right ESCAPE.
203%left BITAND BITOR LSHIFT RSHIFT.
204%left PLUS MINUS.
205%left STAR SLASH REM.
206%left CONCAT.
207%left COLLATE.
208%right UMINUS UPLUS BITNOT.
209
210// And "ids" is an identifer-or-string.
211//
212%type ids {Token}
213ids(A) ::= ID|STRING(X). {A = X;}
214
215// The name of a column or table can be any of the following:
216//
217%type nm {Token}
218nm(A) ::= ID(X). {A = X;}
219nm(A) ::= STRING(X). {A = X;}
220nm(A) ::= JOIN_KW(X). {A = X;}
221
222// A typetoken is really one or more tokens that form a type name such
223// as can be found after the column name in a CREATE TABLE statement.
224// Multiple tokens are concatenated to form the value of the typetoken.
225//
226%type typetoken {Token}
227type ::= .
228type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);}
229typetoken(A) ::= typename(X). {A = X;}
230typetoken(A) ::= typename(X) LP signed RP(Y). {
231 A.z = X.z;
232 A.n = &Y.z[Y.n] - X.z;
233}
234typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). {
235 A.z = X.z;
236 A.n = &Y.z[Y.n] - X.z;
237}
238%type typename {Token}
239typename(A) ::= ids(X). {A = X;}
240typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);}
241signed ::= plus_num.
242signed ::= minus_num.
243
244// "carglist" is a list of additional constraints that come after the
245// column name and column type in a CREATE TABLE statement.
246//
247carglist ::= carglist carg.
248carglist ::= .
249carg ::= CONSTRAINT nm ccons.
250carg ::= ccons.
251ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);}
252ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);}
253ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);}
254ccons ::= DEFAULT MINUS term(X). {
255 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
256 sqlite3AddDefaultValue(pParse,p);
257}
258ccons ::= DEFAULT id(X). {
259 Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &X);
260 sqlite3AddDefaultValue(pParse,p);
261}
262
263// In addition to the type name, we also care about the primary key and
264// UNIQUE constraints.
265//
266ccons ::= NULL onconf.
267ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);}
268ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I).
269 {sqlite3AddPrimaryKey(pParse,0,R,I,Z);}
270ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0,0,0);}
271ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X);}
272ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R).
273 {sqlite3CreateForeignKey(pParse,0,&T,TA,R);}
274ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);}
275ccons ::= COLLATE id(C). {sqlite3AddCollateType(pParse, (char*)C.z, C.n);}
276
277// The optional AUTOINCREMENT keyword
278%type autoinc {int}
279autoinc(X) ::= . {X = 0;}
280autoinc(X) ::= AUTOINCR. {X = 1;}
281
282// The next group of rules parses the arguments to a REFERENCES clause
283// that determine if the referential integrity checking is deferred or
284// or immediate and which determine what action to take if a ref-integ
285// check fails.
286//
287%type refargs {int}
288refargs(A) ::= . { A = OE_Restrict * 0x010101; }
289refargs(A) ::= refargs(X) refarg(Y). { A = (X & Y.mask) | Y.value; }
290%type refarg {struct {int value; int mask;}}
291refarg(A) ::= MATCH nm. { A.value = 0; A.mask = 0x000000; }
292refarg(A) ::= ON DELETE refact(X). { A.value = X; A.mask = 0x0000ff; }
293refarg(A) ::= ON UPDATE refact(X). { A.value = X<<8; A.mask = 0x00ff00; }
294refarg(A) ::= ON INSERT refact(X). { A.value = X<<16; A.mask = 0xff0000; }
295%type refact {int}
296refact(A) ::= SET NULL. { A = OE_SetNull; }
297refact(A) ::= SET DEFAULT. { A = OE_SetDflt; }
298refact(A) ::= CASCADE. { A = OE_Cascade; }
299refact(A) ::= RESTRICT. { A = OE_Restrict; }
300%type defer_subclause {int}
301defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt(X). {A = X;}
302defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X). {A = X;}
303%type init_deferred_pred_opt {int}
304init_deferred_pred_opt(A) ::= . {A = 0;}
305init_deferred_pred_opt(A) ::= INITIALLY DEFERRED. {A = 1;}
306init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;}
307
308// For the time being, the only constraint we care about is the primary
309// key and UNIQUE. Both create indices.
310//
311conslist_opt(A) ::= . {A.n = 0; A.z = 0;}
312conslist_opt(A) ::= COMMA(X) conslist. {A = X;}
313conslist ::= conslist COMMA tcons.
314conslist ::= conslist tcons.
315conslist ::= tcons.
316tcons ::= CONSTRAINT nm.
317tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R).
318 {sqlite3AddPrimaryKey(pParse,X,R,I,0);}
319tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
320 {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);}
321tcons ::= CHECK LP expr(E) RP onconf. {sqlite3AddCheckConstraint(pParse,E);}
322tcons ::= FOREIGN KEY LP idxlist(FA) RP
323 REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). {
324 sqlite3CreateForeignKey(pParse, FA, &T, TA, R);
325 sqlite3DeferForeignKey(pParse, D);
326}
327%type defer_subclause_opt {int}
328defer_subclause_opt(A) ::= . {A = 0;}
329defer_subclause_opt(A) ::= defer_subclause(X). {A = X;}
330
331// The following is a non-standard extension that allows us to declare the
332// default behavior when there is a constraint conflict.
333//
334%type onconf {int}
335%type orconf {int}
336%type resolvetype {int}
337onconf(A) ::= . {A = OE_Default;}
338onconf(A) ::= ON CONFLICT resolvetype(X). {A = X;}
339orconf(A) ::= . {A = OE_Default;}
340orconf(A) ::= OR resolvetype(X). {A = X;}
341resolvetype(A) ::= raisetype(X). {A = X;}
342resolvetype(A) ::= IGNORE. {A = OE_Ignore;}
343resolvetype(A) ::= REPLACE. {A = OE_Replace;}
344
345////////////////////////// The DROP TABLE /////////////////////////////////////
346//
347cmd ::= DROP TABLE ifexists(E) fullname(X). {
348 sqlite3DropTable(pParse, X, 0, E);
349}
350%type ifexists {int}
351ifexists(A) ::= IF EXISTS. {A = 1;}
352ifexists(A) ::= . {A = 0;}
353
354///////////////////// The CREATE VIEW statement /////////////////////////////
355//
356%ifndef SQLITE_OMIT_VIEW
357cmd ::= CREATE(X) temp(T) VIEW ifnotexists(E) nm(Y) dbnm(Z) AS select(S). {
358 sqlite3CreateView(pParse, &X, &Y, &Z, S, T, E);
359}
360cmd ::= DROP VIEW ifexists(E) fullname(X). {
361 sqlite3DropTable(pParse, X, 1, E);
362}
363%endif SQLITE_OMIT_VIEW
364
365//////////////////////// The SELECT statement /////////////////////////////////
366//
367cmd ::= select(X). {
368 sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0, 0);
369 sqlite3SelectDelete(X);
370}
371
372%type select {Select*}
373%destructor select {sqlite3SelectDelete($$);}
374%type oneselect {Select*}
375%destructor oneselect {sqlite3SelectDelete($$);}
376
377select(A) ::= oneselect(X). {A = X;}
378%ifndef SQLITE_OMIT_COMPOUND_SELECT
379select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
380 if( Z ){
381 Z->op = Y;
382 Z->pPrior = X;
383 }else{
384 sqlite3SelectDelete(X);
385 }
386 A = Z;
387}
388%type multiselect_op {int}
389multiselect_op(A) ::= UNION(OP). {A = @OP;}
390multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
391multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;}
392%endif SQLITE_OMIT_COMPOUND_SELECT
393oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
394 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
395 A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset);
396}
397
398// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
399// present and false (0) if it is not.
400//
401%type distinct {int}
402distinct(A) ::= DISTINCT. {A = 1;}
403distinct(A) ::= ALL. {A = 0;}
404distinct(A) ::= . {A = 0;}
405
406// selcollist is a list of expressions that are to become the return
407// values of the SELECT statement. The "*" in statements like
408// "SELECT * FROM ..." is encoded as a special expression with an
409// opcode of TK_ALL.
410//
411%type selcollist {ExprList*}
412%destructor selcollist {sqlite3ExprListDelete($$);}
413%type sclp {ExprList*}
414%destructor sclp {sqlite3ExprListDelete($$);}
415sclp(A) ::= selcollist(X) COMMA. {A = X;}
416sclp(A) ::= . {A = 0;}
417selcollist(A) ::= sclp(P) expr(X) as(Y). {
418 A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0);
419}
420selcollist(A) ::= sclp(P) STAR. {
421 Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
422 A = sqlite3ExprListAppend(pParse, P, p, 0);
423}
424selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
425 Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0);
426 Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
427 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
428 A = sqlite3ExprListAppend(pParse,P, pDot, 0);
429}
430
431// An option "AS <id>" phrase that can follow one of the expressions that
432// define the result set, or one of the tables in the FROM clause.
433//
434%type as {Token}
435as(X) ::= AS nm(Y). {X = Y;}
436as(X) ::= ids(Y). {X = Y;}
437as(X) ::= . {X.n = 0;}
438
439
440%type seltablist {SrcList*}
441%destructor seltablist {sqlite3SrcListDelete($$);}
442%type stl_prefix {SrcList*}
443%destructor stl_prefix {sqlite3SrcListDelete($$);}
444%type from {SrcList*}
445%destructor from {sqlite3SrcListDelete($$);}
446
447// A complete FROM clause.
448//
449from(A) ::= . {A = sqlite3DbMallocZero(pParse->db, sizeof(*A));}
450from(A) ::= FROM seltablist(X). {
451 A = X;
452 sqlite3SrcListShiftJoinType(A);
453}
454
455// "seltablist" is a "Select Table List" - the content of the FROM clause
456// in a SELECT statement. "stl_prefix" is a prefix of this list.
457//
458stl_prefix(A) ::= seltablist(X) joinop(Y). {
459 A = X;
460 if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
461}
462stl_prefix(A) ::= . {A = 0;}
463seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). {
464 A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U);
465}
466%ifndef SQLITE_OMIT_SUBQUERY
467 seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP
468 as(Z) on_opt(N) using_opt(U). {
469 A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U);
470 }
471
472 // A seltablist_paren nonterminal represents anything in a FROM that
473 // is contained inside parentheses. This can be either a subquery or
474 // a grouping of table and subqueries.
475 //
476 %type seltablist_paren {Select*}
477 %destructor seltablist_paren {sqlite3SelectDelete($$);}
478 seltablist_paren(A) ::= select(S). {A = S;}
479 seltablist_paren(A) ::= seltablist(F). {
480 sqlite3SrcListShiftJoinType(F);
481 A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0);
482 }
483%endif SQLITE_OMIT_SUBQUERY
484
485%type dbnm {Token}
486dbnm(A) ::= . {A.z=0; A.n=0;}
487dbnm(A) ::= DOT nm(X). {A = X;}
488
489%type fullname {SrcList*}
490%destructor fullname {sqlite3SrcListDelete($$);}
491fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);}
492
493%type joinop {int}
494%type joinop2 {int}
495joinop(X) ::= COMMA|JOIN. { X = JT_INNER; }
496joinop(X) ::= JOIN_KW(A) JOIN. { X = sqlite3JoinType(pParse,&A,0,0); }
497joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqlite3JoinType(pParse,&A,&B,0); }
498joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
499 { X = sqlite3JoinType(pParse,&A,&B,&C); }
500
501%type on_opt {Expr*}
502%destructor on_opt {sqlite3ExprDelete($$);}
503on_opt(N) ::= ON expr(E). {N = E;}
504on_opt(N) ::= . {N = 0;}
505
506%type using_opt {IdList*}
507%destructor using_opt {sqlite3IdListDelete($$);}
508using_opt(U) ::= USING LP inscollist(L) RP. {U = L;}
509using_opt(U) ::= . {U = 0;}
510
511
512%type orderby_opt {ExprList*}
513%destructor orderby_opt {sqlite3ExprListDelete($$);}
514%type sortlist {ExprList*}
515%destructor sortlist {sqlite3ExprListDelete($$);}
516%type sortitem {Expr*}
517%destructor sortitem {sqlite3ExprDelete($$);}
518
519orderby_opt(A) ::= . {A = 0;}
520orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
521sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
522 A = sqlite3ExprListAppend(pParse,X,Y,0);
523 if( A ) A->a[A->nExpr-1].sortOrder = Z;
524}
525sortlist(A) ::= sortitem(Y) sortorder(Z). {
526 A = sqlite3ExprListAppend(pParse,0,Y,0);
527 if( A && A->a ) A->a[0].sortOrder = Z;
528}
529sortitem(A) ::= expr(X). {A = X;}
530
531%type sortorder {int}
532
533sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;}
534sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;}
535sortorder(A) ::= . {A = SQLITE_SO_ASC;}
536
537%type groupby_opt {ExprList*}
538%destructor groupby_opt {sqlite3ExprListDelete($$);}
539groupby_opt(A) ::= . {A = 0;}
540groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;}
541
542%type having_opt {Expr*}
543%destructor having_opt {sqlite3ExprDelete($$);}
544having_opt(A) ::= . {A = 0;}
545having_opt(A) ::= HAVING expr(X). {A = X;}
546
547%type limit_opt {struct LimitVal}
548
549// The destructor for limit_opt will never fire in the current grammar.
550// The limit_opt non-terminal only occurs at the end of a single production
551// rule for SELECT statements. As soon as the rule that create the
552// limit_opt non-terminal reduces, the SELECT statement rule will also
553// reduce. So there is never a limit_opt non-terminal on the stack
554// except as a transient. So there is never anything to destroy.
555//
556//%destructor limit_opt {
557// sqlite3ExprDelete($$.pLimit);
558// sqlite3ExprDelete($$.pOffset);
559//}
560limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;}
561limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X; A.pOffset = 0;}
562limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y).
563 {A.pLimit = X; A.pOffset = Y;}
564limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y).
565 {A.pOffset = X; A.pLimit = Y;}
566
567/////////////////////////// The DELETE statement /////////////////////////////
568//
569cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);}
570
571%type where_opt {Expr*}
572%destructor where_opt {sqlite3ExprDelete($$);}
573
574where_opt(A) ::= . {A = 0;}
575where_opt(A) ::= WHERE expr(X). {A = X;}
576
577////////////////////////// The UPDATE command ////////////////////////////////
578//
579cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z). {
580 sqlite3ExprListCheckLength(pParse,Y,SQLITE_MAX_COLUMN,"set list");
581 sqlite3Update(pParse,X,Y,Z,R);
582}
583
584%type setlist {ExprList*}
585%destructor setlist {sqlite3ExprListDelete($$);}
586
587setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
588 {A = sqlite3ExprListAppend(pParse,Z,Y,&X);}
589setlist(A) ::= nm(X) EQ expr(Y).
590 {A = sqlite3ExprListAppend(pParse,0,Y,&X);}
591
592////////////////////////// The INSERT command /////////////////////////////////
593//
594cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F)
595 VALUES LP itemlist(Y) RP.
596 {sqlite3Insert(pParse, X, Y, 0, F, R);}
597cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S).
598 {sqlite3Insert(pParse, X, 0, S, F, R);}
599cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) DEFAULT VALUES.
600 {sqlite3Insert(pParse, X, 0, 0, F, R);}
601
602%type insert_cmd {int}
603insert_cmd(A) ::= INSERT orconf(R). {A = R;}
604insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
605
606
607%type itemlist {ExprList*}
608%destructor itemlist {sqlite3ExprListDelete($$);}
609
610itemlist(A) ::= itemlist(X) COMMA expr(Y).
611 {A = sqlite3ExprListAppend(pParse,X,Y,0);}
612itemlist(A) ::= expr(X).
613 {A = sqlite3ExprListAppend(pParse,0,X,0);}
614
615%type inscollist_opt {IdList*}
616%destructor inscollist_opt {sqlite3IdListDelete($$);}
617%type inscollist {IdList*}
618%destructor inscollist {sqlite3IdListDelete($$);}
619
620inscollist_opt(A) ::= . {A = 0;}
621inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
622inscollist(A) ::= inscollist(X) COMMA nm(Y).
623 {A = sqlite3IdListAppend(pParse->db,X,&Y);}
624inscollist(A) ::= nm(Y).
625 {A = sqlite3IdListAppend(pParse->db,0,&Y);}
626
627/////////////////////////// Expression Processing /////////////////////////////
628//
629
630%type expr {Expr*}
631%destructor expr {sqlite3ExprDelete($$);}
632%type term {Expr*}
633%destructor term {sqlite3ExprDelete($$);}
634
635expr(A) ::= term(X). {A = X;}
636expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); }
637term(A) ::= NULL(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
638expr(A) ::= ID(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);}
639expr(A) ::= JOIN_KW(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);}
640expr(A) ::= nm(X) DOT nm(Y). {
641 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
642 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y);
643 A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
644}
645expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
646 Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
647 Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y);
648 Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Z);
649 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
650 A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
651}
652term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
653term(A) ::= STRING(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);}
654expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);}
655expr(A) ::= VARIABLE(X). {
656 Token *pToken = &X;
657 Expr *pExpr = A = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken);
658 sqlite3ExprAssignVarNumber(pParse, pExpr);
659}
660expr(A) ::= expr(E) COLLATE id(C). {
661 A = sqlite3ExprSetColl(pParse, E, &C);
662}
663%ifndef SQLITE_OMIT_CAST
664expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
665 A = sqlite3PExpr(pParse, TK_CAST, E, 0, &T);
666 sqlite3ExprSpan(A,&X,&Y);
667}
668%endif SQLITE_OMIT_CAST
669expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). {
670 if( Y && Y->nExpr>SQLITE_MAX_FUNCTION_ARG ){
671 sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
672 }
673 A = sqlite3ExprFunction(pParse, Y, &X);
674 sqlite3ExprSpan(A,&X,&E);
675 if( D && A ){
676 A->flags |= EP_Distinct;
677 }
678}
679expr(A) ::= ID(X) LP STAR RP(E). {
680 A = sqlite3ExprFunction(pParse, 0, &X);
681 sqlite3ExprSpan(A,&X,&E);
682}
683term(A) ::= CTIME_KW(OP). {
684 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
685 ** treated as functions that return constants */
686 A = sqlite3ExprFunction(pParse, 0,&OP);
687 if( A ){
688 A->op = TK_CONST_FUNC;
689 A->span = OP;
690 }
691}
692expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
693expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
694expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y).
695 {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
696expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
697expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y).
698 {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
699expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y).{A = sqlite3PExpr(pParse,@OP,X,Y,0);}
700expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y).
701 {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
702expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);}
703%type likeop {struct LikeOp}
704likeop(A) ::= LIKE_KW(X). {A.eOperator = X; A.not = 0;}
705likeop(A) ::= NOT LIKE_KW(X). {A.eOperator = X; A.not = 1;}
706likeop(A) ::= MATCH(X). {A.eOperator = X; A.not = 0;}
707likeop(A) ::= NOT MATCH(X). {A.eOperator = X; A.not = 1;}
708%type escape {Expr*}
709%destructor escape {sqlite3ExprDelete($$);}
710escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;}
711escape(X) ::= . [ESCAPE] {X = 0;}
712expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] {
713 ExprList *pList;
714 pList = sqlite3ExprListAppend(pParse,0, Y, 0);
715 pList = sqlite3ExprListAppend(pParse,pList, X, 0);
716 if( E ){
717 pList = sqlite3ExprListAppend(pParse,pList, E, 0);
718 }
719 A = sqlite3ExprFunction(pParse, pList, &OP.eOperator);
720 if( OP.not ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
721 sqlite3ExprSpan(A, &X->span, &Y->span);
722 if( A ) A->flags |= EP_InfixFunc;
723}
724
725expr(A) ::= expr(X) ISNULL|NOTNULL(E). {
726 A = sqlite3PExpr(pParse, @E, X, 0, 0);
727 sqlite3ExprSpan(A,&X->span,&E);
728}
729expr(A) ::= expr(X) IS NULL(E). {
730 A = sqlite3PExpr(pParse, TK_ISNULL, X, 0, 0);
731 sqlite3ExprSpan(A,&X->span,&E);
732}
733expr(A) ::= expr(X) NOT NULL(E). {
734 A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0);
735 sqlite3ExprSpan(A,&X->span,&E);
736}
737expr(A) ::= expr(X) IS NOT NULL(E). {
738 A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0);
739 sqlite3ExprSpan(A,&X->span,&E);
740}
741expr(A) ::= NOT|BITNOT(B) expr(X). {
742 A = sqlite3PExpr(pParse, @B, X, 0, 0);
743 sqlite3ExprSpan(A,&B,&X->span);
744}
745expr(A) ::= MINUS(B) expr(X). [UMINUS] {
746 A = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0);
747 sqlite3ExprSpan(A,&B,&X->span);
748}
749expr(A) ::= PLUS(B) expr(X). [UPLUS] {
750 A = sqlite3PExpr(pParse, TK_UPLUS, X, 0, 0);
751 sqlite3ExprSpan(A,&B,&X->span);
752}
753%type between_op {int}
754between_op(A) ::= BETWEEN. {A = 0;}
755between_op(A) ::= NOT BETWEEN. {A = 1;}
756expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
757 ExprList *pList = sqlite3ExprListAppend(pParse,0, X, 0);
758 pList = sqlite3ExprListAppend(pParse,pList, Y, 0);
759 A = sqlite3PExpr(pParse, TK_BETWEEN, W, 0, 0);
760 if( A ){
761 A->pList = pList;
762 }else{
763 sqlite3ExprListDelete(pList);
764 }
765 if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
766 sqlite3ExprSpan(A,&W->span,&Y->span);
767}
768%ifndef SQLITE_OMIT_SUBQUERY
769 %type in_op {int}
770 in_op(A) ::= IN. {A = 0;}
771 in_op(A) ::= NOT IN. {A = 1;}
772 expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] {
773 A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
774 if( A ){
775 A->pList = Y;
776 sqlite3ExprSetHeight(A);
777 }else{
778 sqlite3ExprListDelete(Y);
779 }
780 if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
781 sqlite3ExprSpan(A,&X->span,&E);
782 }
783 expr(A) ::= LP(B) select(X) RP(E). {
784 A = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
785 if( A ){
786 A->pSelect = X;
787 sqlite3ExprSetHeight(A);
788 }else{
789 sqlite3SelectDelete(X);
790 }
791 sqlite3ExprSpan(A,&B,&E);
792 }
793 expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] {
794 A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
795 if( A ){
796 A->pSelect = Y;
797 sqlite3ExprSetHeight(A);
798 }else{
799 sqlite3SelectDelete(Y);
800 }
801 if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
802 sqlite3ExprSpan(A,&X->span,&E);
803 }
804 expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] {
805 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z);
806 A = sqlite3PExpr(pParse, TK_IN, X, 0, 0);
807 if( A ){
808 A->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
809 sqlite3ExprSetHeight(A);
810 }else{
811 sqlite3SrcListDelete(pSrc);
812 }
813 if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0);
814 sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y);
815 }
816 expr(A) ::= EXISTS(B) LP select(Y) RP(E). {
817 Expr *p = A = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
818 if( p ){
819 p->pSelect = Y;
820 sqlite3ExprSpan(p,&B,&E);
821 sqlite3ExprSetHeight(A);
822 }else{
823 sqlite3SelectDelete(Y);
824 }
825 }
826%endif SQLITE_OMIT_SUBQUERY
827
828/* CASE expressions */
829expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
830 A = sqlite3PExpr(pParse, TK_CASE, X, Z, 0);
831 if( A ){
832 A->pList = Y;
833 sqlite3ExprSetHeight(A);
834 }else{
835 sqlite3ExprListDelete(Y);
836 }
837 sqlite3ExprSpan(A, &C, &E);
838}
839%type case_exprlist {ExprList*}
840%destructor case_exprlist {sqlite3ExprListDelete($$);}
841case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
842 A = sqlite3ExprListAppend(pParse,X, Y, 0);
843 A = sqlite3ExprListAppend(pParse,A, Z, 0);
844}
845case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
846 A = sqlite3ExprListAppend(pParse,0, Y, 0);
847 A = sqlite3ExprListAppend(pParse,A, Z, 0);
848}
849%type case_else {Expr*}
850%destructor case_else {sqlite3ExprDelete($$);}
851case_else(A) ::= ELSE expr(X). {A = X;}
852case_else(A) ::= . {A = 0;}
853%type case_operand {Expr*}
854%destructor case_operand {sqlite3ExprDelete($$);}
855case_operand(A) ::= expr(X). {A = X;}
856case_operand(A) ::= . {A = 0;}
857
858%type exprlist {ExprList*}
859%destructor exprlist {sqlite3ExprListDelete($$);}
860%type nexprlist {ExprList*}
861%destructor nexprlist {sqlite3ExprListDelete($$);}
862
863exprlist(A) ::= nexprlist(X). {A = X;}
864exprlist(A) ::= . {A = 0;}
865nexprlist(A) ::= nexprlist(X) COMMA expr(Y).
866 {A = sqlite3ExprListAppend(pParse,X,Y,0);}
867nexprlist(A) ::= expr(Y).
868 {A = sqlite3ExprListAppend(pParse,0,Y,0);}
869
870
871///////////////////////////// The CREATE INDEX command ///////////////////////
872//
873cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D)
874 ON nm(Y) LP idxlist(Z) RP(E). {
875 sqlite3CreateIndex(pParse, &X, &D,
876 sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U,
877 &S, &E, SQLITE_SO_ASC, NE);
878}
879
880%type uniqueflag {int}
881uniqueflag(A) ::= UNIQUE. {A = OE_Abort;}
882uniqueflag(A) ::= . {A = OE_None;}
883
884%type idxlist {ExprList*}
885%destructor idxlist {sqlite3ExprListDelete($$);}
886%type idxlist_opt {ExprList*}
887%destructor idxlist_opt {sqlite3ExprListDelete($$);}
888%type idxitem {Token}
889
890idxlist_opt(A) ::= . {A = 0;}
891idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;}
892idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). {
893 Expr *p = 0;
894 if( C.n>0 ){
895 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
896 if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n);
897 }
898 A = sqlite3ExprListAppend(pParse,X, p, &Y);
899 sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
900 if( A ) A->a[A->nExpr-1].sortOrder = Z;
901}
902idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). {
903 Expr *p = 0;
904 if( C.n>0 ){
905 p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0);
906 if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n);
907 }
908 A = sqlite3ExprListAppend(pParse,0, p, &Y);
909 sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
910 if( A ) A->a[A->nExpr-1].sortOrder = Z;
911}
912idxitem(A) ::= nm(X). {A = X;}
913
914%type collate {Token}
915collate(C) ::= . {C.z = 0; C.n = 0;}
916collate(C) ::= COLLATE id(X). {C = X;}
917
918
919///////////////////////////// The DROP INDEX command /////////////////////////
920//
921cmd ::= DROP INDEX ifexists(E) fullname(X). {sqlite3DropIndex(pParse, X, E);}
922
923///////////////////////////// The VACUUM command /////////////////////////////
924//
925%ifndef SQLITE_OMIT_VACUUM
926%ifndef SQLITE_OMIT_ATTACH
927cmd ::= VACUUM. {sqlite3Vacuum(pParse);}
928cmd ::= VACUUM nm. {sqlite3Vacuum(pParse);}
929%endif SQLITE_OMIT_ATTACH
930%endif SQLITE_OMIT_VACUUM
931
932///////////////////////////// The PRAGMA command /////////////////////////////
933//
934%ifndef SQLITE_OMIT_PRAGMA
935cmd ::= PRAGMA nm(X) dbnm(Z) EQ nmnum(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
936cmd ::= PRAGMA nm(X) dbnm(Z) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
937cmd ::= PRAGMA nm(X) dbnm(Z) EQ minus_num(Y). {
938 sqlite3Pragma(pParse,&X,&Z,&Y,1);
939}
940cmd ::= PRAGMA nm(X) dbnm(Z) LP nmnum(Y) RP. {sqlite3Pragma(pParse,&X,&Z,&Y,0);}
941cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);}
942nmnum(A) ::= plus_num(X). {A = X;}
943nmnum(A) ::= nm(X). {A = X;}
944%endif SQLITE_OMIT_PRAGMA
945plus_num(A) ::= plus_opt number(X). {A = X;}
946minus_num(A) ::= MINUS number(X). {A = X;}
947number(A) ::= INTEGER|FLOAT(X). {A = X;}
948plus_opt ::= PLUS.
949plus_opt ::= .
950
951//////////////////////////// The CREATE TRIGGER command /////////////////////
952
953%ifndef SQLITE_OMIT_TRIGGER
954
955cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). {
956 Token all;
957 all.z = A.z;
958 all.n = (Z.z - A.z) + Z.n;
959 sqlite3FinishTrigger(pParse, S, &all);
960}
961
962trigger_decl(A) ::= temp(T) TRIGGER ifnotexists(NOERR) nm(B) dbnm(Z)
963 trigger_time(C) trigger_event(D)
964 ON fullname(E) foreach_clause when_clause(G). {
965 sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, G, T, NOERR);
966 A = (Z.n==0?B:Z);
967}
968
969%type trigger_time {int}
970trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
971trigger_time(A) ::= AFTER. { A = TK_AFTER; }
972trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
973trigger_time(A) ::= . { A = TK_BEFORE; }
974
975%type trigger_event {struct TrigEvent}
976%destructor trigger_event {sqlite3IdListDelete($$.b);}
977trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;}
978trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;}
979trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X;}
980
981foreach_clause ::= .
982foreach_clause ::= FOR EACH ROW.
983
984%type when_clause {Expr*}
985%destructor when_clause {sqlite3ExprDelete($$);}
986when_clause(A) ::= . { A = 0; }
987when_clause(A) ::= WHEN expr(X). { A = X; }
988
989%type trigger_cmd_list {TriggerStep*}
990%destructor trigger_cmd_list {sqlite3DeleteTriggerStep($$);}
991trigger_cmd_list(A) ::= trigger_cmd_list(Y) trigger_cmd(X) SEMI. {
992 if( Y ){
993 Y->pLast->pNext = X;
994 }else{
995 Y = X;
996 }
997 Y->pLast = X;
998 A = Y;
999}
1000trigger_cmd_list(A) ::= . { A = 0; }
1001
1002%type trigger_cmd {TriggerStep*}
1003%destructor trigger_cmd {sqlite3DeleteTriggerStep($$);}
1004// UPDATE
1005trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
1006 { A = sqlite3TriggerUpdateStep(pParse->db, &X, Y, Z, R); }
1007
1008// INSERT
1009trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F)
1010 VALUES LP itemlist(Y) RP.
1011 {A = sqlite3TriggerInsertStep(pParse->db, &X, F, Y, 0, R);}
1012
1013trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
1014 {A = sqlite3TriggerInsertStep(pParse->db, &X, F, 0, S, R);}
1015
1016// DELETE
1017trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y).
1018 {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);}
1019
1020// SELECT
1021trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(pParse->db, X); }
1022
1023// The special RAISE expression that may occur in trigger programs
1024expr(A) ::= RAISE(X) LP IGNORE RP(Y). {
1025 A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0);
1026 if( A ){
1027 A->iColumn = OE_Ignore;
1028 sqlite3ExprSpan(A, &X, &Y);
1029 }
1030}
1031expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y). {
1032 A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &Z);
1033 if( A ) {
1034 A->iColumn = T;
1035 sqlite3ExprSpan(A, &X, &Y);
1036 }
1037}
1038%endif !SQLITE_OMIT_TRIGGER
1039
1040%type raisetype {int}
1041raisetype(A) ::= ROLLBACK. {A = OE_Rollback;}
1042raisetype(A) ::= ABORT. {A = OE_Abort;}
1043raisetype(A) ::= FAIL. {A = OE_Fail;}
1044
1045
1046//////////////////////// DROP TRIGGER statement //////////////////////////////
1047%ifndef SQLITE_OMIT_TRIGGER
1048cmd ::= DROP TRIGGER ifexists(NOERR) fullname(X). {
1049 sqlite3DropTrigger(pParse,X,NOERR);
1050}
1051%endif !SQLITE_OMIT_TRIGGER
1052
1053//////////////////////// ATTACH DATABASE file AS name /////////////////////////
1054%ifndef SQLITE_OMIT_ATTACH
1055cmd ::= ATTACH database_kw_opt expr(F) AS expr(D) key_opt(K). {
1056 sqlite3Attach(pParse, F, D, K);
1057}
1058cmd ::= DETACH database_kw_opt expr(D). {
1059 sqlite3Detach(pParse, D);
1060}
1061
1062%type key_opt {Expr *}
1063%destructor key_opt {sqlite3ExprDelete($$);}
1064key_opt(A) ::= . { A = 0; }
1065key_opt(A) ::= KEY expr(X). { A = X; }
1066
1067database_kw_opt ::= DATABASE.
1068database_kw_opt ::= .
1069%endif SQLITE_OMIT_ATTACH
1070
1071////////////////////////// REINDEX collation //////////////////////////////////
1072%ifndef SQLITE_OMIT_REINDEX
1073cmd ::= REINDEX. {sqlite3Reindex(pParse, 0, 0);}
1074cmd ::= REINDEX nm(X) dbnm(Y). {sqlite3Reindex(pParse, &X, &Y);}
1075%endif SQLITE_OMIT_REINDEX
1076
1077/////////////////////////////////// ANALYZE ///////////////////////////////////
1078%ifndef SQLITE_OMIT_ANALYZE
1079cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0, 0);}
1080cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);}
1081%endif
1082
1083//////////////////////// ALTER TABLE table ... ////////////////////////////////
1084%ifndef SQLITE_OMIT_ALTERTABLE
1085cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). {
1086 sqlite3AlterRenameTable(pParse,X,&Z);
1087}
1088cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). {
1089 sqlite3AlterFinishAddColumn(pParse, &Y);
1090}
1091add_column_fullname ::= fullname(X). {
1092 sqlite3AlterBeginAddColumn(pParse, X);
1093}
1094kwcolumn_opt ::= .
1095kwcolumn_opt ::= COLUMNKW.
1096%endif SQLITE_OMIT_ALTERTABLE
1097
1098//////////////////////// CREATE VIRTUAL TABLE ... /////////////////////////////
1099%ifndef SQLITE_OMIT_VIRTUALTABLE
1100cmd ::= create_vtab. {sqlite3VtabFinishParse(pParse,0);}
1101cmd ::= create_vtab LP vtabarglist RP(X). {sqlite3VtabFinishParse(pParse,&X);}
1102create_vtab ::= CREATE VIRTUAL TABLE nm(X) dbnm(Y) USING nm(Z). {
1103 sqlite3VtabBeginParse(pParse, &X, &Y, &Z);
1104}
1105vtabarglist ::= vtabarg.
1106vtabarglist ::= vtabarglist COMMA vtabarg.
1107vtabarg ::= . {sqlite3VtabArgInit(pParse);}
1108vtabarg ::= vtabarg vtabargtoken.
1109vtabargtoken ::= ANY(X). {sqlite3VtabArgExtend(pParse,&X);}
1110vtabargtoken ::= lp anylist RP(X). {sqlite3VtabArgExtend(pParse,&X);}
1111lp ::= LP(X). {sqlite3VtabArgExtend(pParse,&X);}
1112anylist ::= .
1113anylist ::= anylist ANY(X). {sqlite3VtabArgExtend(pParse,&X);}
1114%endif SQLITE_OMIT_VIRTUALTABLE