blob: 4ef3dd3d8aa3a9c92109eb24b19e94d7f3e33183 [file] [log] [blame]
drh348784e2000-05-29 20:41:49 +00001/*
drhb19a2bc2001-09-16 00:13:26 +00002** 2001 September 15
drh348784e2000-05-29 20:41:49 +00003**
drhb19a2bc2001-09-16 00:13:26 +00004** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
drh348784e2000-05-29 20:41:49 +00006**
drhb19a2bc2001-09-16 00:13:26 +00007** 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.
drh348784e2000-05-29 20:41:49 +000010**
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**
drhad3cab52002-05-24 02:04:32 +000017** @(#) $Id: parse.y,v 1.68 2002/05/24 02:04:33 drh Exp $
drh348784e2000-05-29 20:41:49 +000018*/
19%token_prefix TK_
20%token_type {Token}
drhf57b14a2001-09-14 18:54:08 +000021%default_type {Token}
drh348784e2000-05-29 20:41:49 +000022%extra_argument {Parse *pParse}
23%syntax_error {
drhc837e702000-06-08 16:26:24 +000024 sqliteSetString(&pParse->zErrMsg,"syntax error",0);
drh348784e2000-05-29 20:41:49 +000025 pParse->sErrToken = TOKEN;
26}
27%name sqliteParser
28%include {
29#include "sqliteInt.h"
30#include "parse.h"
drh9bbca4c2001-11-06 04:00:18 +000031
32/*
drhad3cab52002-05-24 02:04:32 +000033** An instance of this structure holds information about the
34** LIMIT clause of a SELECT statement.
drh9bbca4c2001-11-06 04:00:18 +000035*/
drhad3cab52002-05-24 02:04:32 +000036struct LimitVal {
37 int limit; /* The LIMIT value. -1 if there is no limit */
38 int offset; /* The OFFSET. 0 if there is none */
39};
danielk1977c3f9bad2002-05-15 08:30:12 +000040
41/*
drhad3cab52002-05-24 02:04:32 +000042** An instance of the following structure describes the event of a
43** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
44** TK_DELETE, or TK_INSTEAD. If the event is of the form
45**
46** UPDATE ON (a,b,c)
47**
48** Then the "b" IdList records the list "a,b,c".
danielk1977c3f9bad2002-05-15 08:30:12 +000049*/
drhad3cab52002-05-24 02:04:32 +000050struct TrigEvent { int a; IdList * b; };
drh348784e2000-05-29 20:41:49 +000051}
52
drh348784e2000-05-29 20:41:49 +000053// These are extra tokens used by the lexer but never seen by the
54// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000055// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000056//
drhc4a3c772001-04-04 11:48:57 +000057%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
58 COLUMN AGG_FUNCTION.
59
60// Input is zero or more commands.
61input ::= cmdlist.
drh348784e2000-05-29 20:41:49 +000062
63// A list of commands is zero or more commands
64//
65cmdlist ::= ecmd.
drh094b2bb2002-03-13 18:54:07 +000066cmdlist ::= cmdlist ecmd.
67ecmd ::= explain cmd SEMI. {sqliteExec(pParse);}
68ecmd ::= cmd SEMI. {sqliteExec(pParse);}
69ecmd ::= SEMI.
drh348784e2000-05-29 20:41:49 +000070explain ::= EXPLAIN. {pParse->explain = 1;}
71
drh382c0242001-10-06 16:33:02 +000072///////////////////// Begin and end transactions. ////////////////////////////
drhc4a3c772001-04-04 11:48:57 +000073//
drhfa86c412002-02-02 15:01:15 +000074
drh0d65dc02002-02-03 00:56:09 +000075cmd ::= BEGIN trans_opt onconf(R). {sqliteBeginTransaction(pParse,R);}
drhc4a3c772001-04-04 11:48:57 +000076trans_opt ::= .
77trans_opt ::= TRANSACTION.
78trans_opt ::= TRANSACTION ids.
79cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);}
80cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);}
81cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);}
82
drh382c0242001-10-06 16:33:02 +000083///////////////////// The CREATE TABLE statement ////////////////////////////
drh348784e2000-05-29 20:41:49 +000084//
85cmd ::= create_table create_table_args.
drh969fa7c2002-02-18 18:30:32 +000086create_table ::= CREATE(X) temp(T) TABLE ids(Y). {
87 sqliteStartTable(pParse,&X,&Y,T);
88}
drhf57b3392001-10-08 13:22:32 +000089%type temp {int}
90temp(A) ::= TEMP. {A = 1;}
91temp(A) ::= . {A = 0;}
drh969fa7c2002-02-18 18:30:32 +000092create_table_args ::= LP columnlist conslist_opt RP(X). {
93 sqliteEndTable(pParse,&X,0);
94}
95create_table_args ::= AS select(S). {
96 sqliteEndTable(pParse,0,S);
97 sqliteSelectDelete(S);
98}
drh348784e2000-05-29 20:41:49 +000099columnlist ::= columnlist COMMA column.
100columnlist ::= column.
101
102// About the only information used for a column is the name of the
103// column. The type is always just "text". But the code will accept
104// an elaborate typename. Perhaps someday we'll do something with it.
105//
106column ::= columnid type carglist.
drhc4a3c772001-04-04 11:48:57 +0000107columnid ::= ids(X). {sqliteAddColumn(pParse,&X);}
108
109// An IDENTIFIER can be a generic identifier, or one of several
110// keywords. Any non-standard keyword can also be an identifier.
drhc4a3c772001-04-04 11:48:57 +0000111//
drh982cef72000-05-30 16:27:03 +0000112%type id {Token}
drh9cfcf5d2002-01-29 18:41:24 +0000113id(A) ::= ABORT(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000114id(A) ::= AFTER(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000115id(A) ::= ASC(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000116id(A) ::= BEFORE(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000117id(A) ::= BEGIN(X). {A = X;}
118id(A) ::= CLUSTER(X). {A = X;}
drh9cfcf5d2002-01-29 18:41:24 +0000119id(A) ::= CONFLICT(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000120id(A) ::= COPY(X). {A = X;}
121id(A) ::= DELIMITERS(X). {A = X;}
122id(A) ::= DESC(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000123id(A) ::= EACH(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000124id(A) ::= END(X). {A = X;}
125id(A) ::= EXPLAIN(X). {A = X;}
126id(A) ::= FAIL(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000127id(A) ::= FOR(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000128id(A) ::= ID(X). {A = X;}
129id(A) ::= IGNORE(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000130id(A) ::= INSTEAD(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000131id(A) ::= KEY(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000132id(A) ::= OF(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000133id(A) ::= OFFSET(X). {A = X;}
134id(A) ::= PRAGMA(X). {A = X;}
135id(A) ::= REPLACE(X). {A = X;}
drhc977f7f2002-05-21 11:38:11 +0000136id(A) ::= ROW(X). {A = X;}
drh1873cd52002-05-23 00:30:31 +0000137id(A) ::= STATEMENT(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000138id(A) ::= TEMP(X). {A = X;}
drhce9079c2002-05-15 14:17:44 +0000139id(A) ::= TRIGGER(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000140id(A) ::= VACUUM(X). {A = X;}
141id(A) ::= VIEW(X). {A = X;}
drhc4a3c772001-04-04 11:48:57 +0000142
143// And "ids" is an identifer-or-string.
144//
145%type ids {Token}
146ids(A) ::= id(X). {A = X;}
147ids(A) ::= STRING(X). {A = X;}
148
drh382c0242001-10-06 16:33:02 +0000149type ::= .
150type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
151type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
152type ::= typename(X) LP signed COMMA signed RP(Y).
153 {sqliteAddColumnType(pParse,&X,&Y);}
154%type typename {Token}
155typename(A) ::= ids(X). {A = X;}
156typename(A) ::= typename(X) ids. {A = X;}
drh348784e2000-05-29 20:41:49 +0000157signed ::= INTEGER.
158signed ::= PLUS INTEGER.
159signed ::= MINUS INTEGER.
160carglist ::= carglist carg.
161carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000162carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000163carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000164carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
165carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
166carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
167carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
168carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
169carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
170carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
171carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
172carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000173
drh382c0242001-10-06 16:33:02 +0000174// In addition to the type name, we also care about the primary key and
175// UNIQUE constraints.
drh348784e2000-05-29 20:41:49 +0000176//
drh9cfcf5d2002-01-29 18:41:24 +0000177ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
178ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
179ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
180ccons ::= CHECK LP expr RP onconf.
drh348784e2000-05-29 20:41:49 +0000181
182// For the time being, the only constraint we care about is the primary
drh382c0242001-10-06 16:33:02 +0000183// key and UNIQUE. Both create indices.
drh348784e2000-05-29 20:41:49 +0000184//
185conslist_opt ::= .
186conslist_opt ::= COMMA conslist.
187conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000188conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000189conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000190tcons ::= CONSTRAINT ids.
drh9cfcf5d2002-01-29 18:41:24 +0000191tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
192 {sqliteAddPrimaryKey(pParse,X,R);}
193tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
194 {sqliteCreateIndex(pParse,0,0,X,R,0,0);}
195tcons ::= CHECK expr onconf.
196
197// The following is a non-standard extension that allows us to declare the
198// default behavior when there is a constraint conflict.
199//
200%type onconf {int}
drh1c928532002-01-31 15:54:21 +0000201%type orconf {int}
202%type resolvetype {int}
203onconf(A) ::= . { A = OE_Default; }
204onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
205orconf(A) ::= . { A = OE_Default; }
206orconf(A) ::= OR resolvetype(X). { A = X; }
207resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
208resolvetype(A) ::= ABORT. { A = OE_Abort; }
209resolvetype(A) ::= FAIL. { A = OE_Fail; }
210resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
211resolvetype(A) ::= REPLACE. { A = OE_Replace; }
drh348784e2000-05-29 20:41:49 +0000212
drh382c0242001-10-06 16:33:02 +0000213////////////////////////// The DROP TABLE /////////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000214//
drh4ff6dfa2002-03-03 23:06:00 +0000215cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X,0);}
drh348784e2000-05-29 20:41:49 +0000216
drha76b5df2002-02-23 02:32:10 +0000217///////////////////// The CREATE VIEW statement /////////////////////////////
218//
219cmd ::= CREATE(X) VIEW ids(Y) AS select(S). {
220 sqliteCreateView(pParse, &X, &Y, S);
221}
222cmd ::= DROP VIEW ids(X). {
drh4ff6dfa2002-03-03 23:06:00 +0000223 sqliteDropTable(pParse, &X, 1);
drha76b5df2002-02-23 02:32:10 +0000224}
225
drh382c0242001-10-06 16:33:02 +0000226//////////////////////// The SELECT statement /////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000227//
drh9bb61fe2000-06-05 16:01:39 +0000228cmd ::= select(X). {
drh832508b2002-03-02 17:04:07 +0000229 sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
drh9bb61fe2000-06-05 16:01:39 +0000230 sqliteSelectDelete(X);
231}
drhefb72512000-05-31 20:00:52 +0000232
drh9bb61fe2000-06-05 16:01:39 +0000233%type select {Select*}
234%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000235%type oneselect {Select*}
236%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000237
drh82c3d632000-06-06 21:56:07 +0000238select(A) ::= oneselect(X). {A = X;}
drh0a36c572002-02-18 22:49:59 +0000239select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000240 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000241 Z->op = Y;
242 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000243 }
244 A = Z;
drh82c3d632000-06-06 21:56:07 +0000245}
drh0a36c572002-02-18 22:49:59 +0000246%type multiselect_op {int}
247multiselect_op(A) ::= UNION. {A = TK_UNION;}
248multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
249multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
250multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
drh82c3d632000-06-06 21:56:07 +0000251oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
drh9bbca4c2001-11-06 04:00:18 +0000252 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
drhad3cab52002-05-24 02:04:32 +0000253 A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
drh9bb61fe2000-06-05 16:01:39 +0000254}
255
256// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
257// present and false (0) if it is not.
258//
drhefb72512000-05-31 20:00:52 +0000259%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000260distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000261distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000262distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000263
drh9bb61fe2000-06-05 16:01:39 +0000264// selcollist is a list of expressions that are to become the return
drh7c917d12001-12-16 20:05:05 +0000265// values of the SELECT statement. The "*" in statements like
266// "SELECT * FROM ..." is encoded as a special expression with an
267// opcode of TK_ALL.
drh9bb61fe2000-06-05 16:01:39 +0000268//
drh348784e2000-05-29 20:41:49 +0000269%type selcollist {ExprList*}
270%destructor selcollist {sqliteExprListDelete($$);}
271%type sclp {ExprList*}
272%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000273sclp(A) ::= selcollist(X) COMMA. {A = X;}
274sclp(A) ::= . {A = 0;}
275selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drhc4a3c772001-04-04 11:48:57 +0000276selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh7c917d12001-12-16 20:05:05 +0000277selcollist(A) ::= sclp(P) STAR. {
278 A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
279}
drh54473222002-04-04 02:10:55 +0000280selcollist(A) ::= sclp(P) ids(X) DOT STAR. {
281 Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
282 Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
283 A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
284}
drh9bb61fe2000-06-05 16:01:39 +0000285as ::= .
286as ::= AS.
287
drh348784e2000-05-29 20:41:49 +0000288
drhad3cab52002-05-24 02:04:32 +0000289%type seltablist {SrcList*}
290%destructor seltablist {sqliteSrcListDelete($$);}
291%type stl_prefix {SrcList*}
292%destructor stl_prefix {sqliteSrcListDelete($$);}
293%type from {SrcList*}
294%destructor from {sqliteSrcListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000295
drhbf3a4fa2002-04-06 13:57:42 +0000296from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
drh348784e2000-05-29 20:41:49 +0000297from(A) ::= FROM seltablist(X). {A = X;}
298stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
299stl_prefix(A) ::= . {A = 0;}
drhad3cab52002-05-24 02:04:32 +0000300seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteSrcListAppend(X,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000301seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). {
drhad3cab52002-05-24 02:04:32 +0000302 A = sqliteSrcListAppend(X,&Y);
303 sqliteSrcListAddAlias(A,&Z);
drhc4a3c772001-04-04 11:48:57 +0000304}
drh22f70c32002-02-18 01:17:00 +0000305seltablist(A) ::= stl_prefix(X) LP select(S) RP. {
drhad3cab52002-05-24 02:04:32 +0000306 A = sqliteSrcListAppend(X,0);
307 A->a[A->nSrc-1].pSelect = S;
drhd5feede2002-05-08 21:46:14 +0000308 if( S->pOrderBy ){
309 sqliteExprListDelete(S->pOrderBy);
310 S->pOrderBy = 0;
311 }
drh22f70c32002-02-18 01:17:00 +0000312}
313seltablist(A) ::= stl_prefix(X) LP select(S) RP as ids(Z). {
drhad3cab52002-05-24 02:04:32 +0000314 A = sqliteSrcListAppend(X,0);
315 A->a[A->nSrc-1].pSelect = S;
drhd5feede2002-05-08 21:46:14 +0000316 if( S->pOrderBy ){
317 sqliteExprListDelete(S->pOrderBy);
318 S->pOrderBy = 0;
319 }
drhad3cab52002-05-24 02:04:32 +0000320 sqliteSrcListAddAlias(A,&Z);
drh22f70c32002-02-18 01:17:00 +0000321}
drh348784e2000-05-29 20:41:49 +0000322
323%type orderby_opt {ExprList*}
324%destructor orderby_opt {sqliteExprListDelete($$);}
325%type sortlist {ExprList*}
326%destructor sortlist {sqliteExprListDelete($$);}
327%type sortitem {Expr*}
328%destructor sortitem {sqliteExprDelete($$);}
329
330orderby_opt(A) ::= . {A = 0;}
331orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000332sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
333 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000334 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000335}
336sortlist(A) ::= sortitem(Y) sortorder(Z). {
337 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000338 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000339}
drhda9d6c42000-05-31 18:20:14 +0000340sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000341
342%type sortorder {int}
343
344sortorder(A) ::= ASC. {A = 0;}
345sortorder(A) ::= DESC. {A = 1;}
346sortorder(A) ::= . {A = 0;}
347
drh22827922000-06-06 17:27:05 +0000348%type groupby_opt {ExprList*}
349%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000350groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000351groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
352
353%type having_opt {Expr*}
354%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000355having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000356having_opt(A) ::= HAVING expr(X). {A = X;}
357
drhad3cab52002-05-24 02:04:32 +0000358%type limit_opt {struct LimitVal}
359limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
360limit_opt(A) ::= LIMIT INTEGER(X). {A.limit = atoi(X.z); A.offset = 0;}
drh9bbca4c2001-11-06 04:00:18 +0000361limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y).
drhad3cab52002-05-24 02:04:32 +0000362 {A.limit = atoi(X.z); A.offset = atoi(Y.z);}
drh9bbca4c2001-11-06 04:00:18 +0000363limit_sep ::= OFFSET.
364limit_sep ::= COMMA.
365
drh382c0242001-10-06 16:33:02 +0000366/////////////////////////// The DELETE statement /////////////////////////////
367//
drhc4a3c772001-04-04 11:48:57 +0000368cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000369 {sqliteDeleteFrom(pParse, &X, Y);}
370
371%type where_opt {Expr*}
372%destructor where_opt {sqliteExprDelete($$);}
373
374where_opt(A) ::= . {A = 0;}
375where_opt(A) ::= WHERE expr(X). {A = X;}
376
377%type setlist {ExprList*}
378%destructor setlist {sqliteExprListDelete($$);}
379
drh382c0242001-10-06 16:33:02 +0000380////////////////////////// The UPDATE command ////////////////////////////////
381//
drh1c928532002-01-31 15:54:21 +0000382cmd ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
drh9cfcf5d2002-01-29 18:41:24 +0000383 {sqliteUpdate(pParse,&X,Y,Z,R);}
drh348784e2000-05-29 20:41:49 +0000384
drhc4a3c772001-04-04 11:48:57 +0000385setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000386 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000387setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000388
drh382c0242001-10-06 16:33:02 +0000389////////////////////////// The INSERT command /////////////////////////////////
390//
drhfa86c412002-02-02 15:01:15 +0000391cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh9cfcf5d2002-01-29 18:41:24 +0000392 {sqliteInsert(pParse, &X, Y, 0, F, R);}
drhfa86c412002-02-02 15:01:15 +0000393cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) select(S).
drh9cfcf5d2002-01-29 18:41:24 +0000394 {sqliteInsert(pParse, &X, 0, S, F, R);}
drh348784e2000-05-29 20:41:49 +0000395
drhfa86c412002-02-02 15:01:15 +0000396%type insert_cmd {int}
397insert_cmd(A) ::= INSERT orconf(R). {A = R;}
398insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
399
drh348784e2000-05-29 20:41:49 +0000400
401%type itemlist {ExprList*}
402%destructor itemlist {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000403
drhe64e7b22002-02-18 13:56:36 +0000404itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
405itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
drh348784e2000-05-29 20:41:49 +0000406
drh967e8b72000-06-21 13:59:10 +0000407%type inscollist_opt {IdList*}
408%destructor inscollist_opt {sqliteIdListDelete($$);}
409%type inscollist {IdList*}
410%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000411
drhc4a3c772001-04-04 11:48:57 +0000412inscollist_opt(A) ::= . {A = 0;}
413inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
414inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
415inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000416
drh382c0242001-10-06 16:33:02 +0000417/////////////////////////// Expression Processing /////////////////////////////
418//
drh348784e2000-05-29 20:41:49 +0000419%left OR.
420%left AND.
drh8be51132000-06-03 19:19:41 +0000421%right NOT.
drhfef52082000-06-06 01:50:43 +0000422%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000423%left GT GE LT LE.
drh81a20f22001-10-12 17:30:04 +0000424%left BITAND BITOR LSHIFT RSHIFT.
drh348784e2000-05-29 20:41:49 +0000425%left PLUS MINUS.
drhbf4133c2001-10-13 02:59:08 +0000426%left STAR SLASH REM.
drh00400772000-06-16 20:51:26 +0000427%left CONCAT.
drh81a20f22001-10-12 17:30:04 +0000428%right UMINUS BITNOT.
drh348784e2000-05-29 20:41:49 +0000429
430%type expr {Expr*}
431%destructor expr {sqliteExprDelete($$);}
432
drhe1b6a5b2000-07-29 13:06:59 +0000433expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000434expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000435expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
436expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000437 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
438 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
439 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
440}
drh348784e2000-05-29 20:41:49 +0000441expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
442expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
443expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000444expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
445 A = sqliteExprFunction(Y, &X);
446 sqliteExprSpan(A,&X,&E);
447}
448expr(A) ::= ID(X) LP STAR RP(E). {
449 A = sqliteExprFunction(0, &X);
450 sqliteExprSpan(A,&X,&E);
451}
drh348784e2000-05-29 20:41:49 +0000452expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
453expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
454expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
455expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
456expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
457expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
458expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
459expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drh81a20f22001-10-12 17:30:04 +0000460expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
461expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
462expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
463expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
drh0ac65892002-04-20 14:24:41 +0000464expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
465 ExprList *pList = sqliteExprListAppend(0, Y, 0);
466 pList = sqliteExprListAppend(pList, X, 0);
467 A = sqliteExprFunction(pList, &OP);
468 sqliteExprSpan(A, &X->span, &Y->span);
469}
470expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
471 ExprList *pList = sqliteExprListAppend(0, Y, 0);
472 pList = sqliteExprListAppend(pList, X, 0);
473 A = sqliteExprFunction(pList, &OP);
drh4794b982000-06-06 13:54:14 +0000474 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000475 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000476}
drh0ac65892002-04-20 14:24:41 +0000477likeop(A) ::= LIKE(X). {A = X;}
478likeop(A) ::= GLOB(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000479expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
480expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
481expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
482expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drhbf4133c2001-10-13 02:59:08 +0000483expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000484expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000485expr(A) ::= expr(X) ISNULL(E). {
486 A = sqliteExpr(TK_ISNULL, X, 0, 0);
487 sqliteExprSpan(A,&X->span,&E);
488}
drh33048c02001-10-01 14:29:22 +0000489expr(A) ::= expr(X) IS NULL(E). {
490 A = sqliteExpr(TK_ISNULL, X, 0, 0);
491 sqliteExprSpan(A,&X->span,&E);
492}
drhe1b6a5b2000-07-29 13:06:59 +0000493expr(A) ::= expr(X) NOTNULL(E). {
494 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
495 sqliteExprSpan(A,&X->span,&E);
496}
drh33048c02001-10-01 14:29:22 +0000497expr(A) ::= expr(X) NOT NULL(E). {
498 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
499 sqliteExprSpan(A,&X->span,&E);
500}
drh81a20f22001-10-12 17:30:04 +0000501expr(A) ::= expr(X) IS NOT NULL(E). {
502 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
503 sqliteExprSpan(A,&X->span,&E);
504}
drhe1b6a5b2000-07-29 13:06:59 +0000505expr(A) ::= NOT(B) expr(X). {
506 A = sqliteExpr(TK_NOT, X, 0, 0);
507 sqliteExprSpan(A,&B,&X->span);
508}
drh81a20f22001-10-12 17:30:04 +0000509expr(A) ::= BITNOT(B) expr(X). {
510 A = sqliteExpr(TK_BITNOT, X, 0, 0);
511 sqliteExprSpan(A,&B,&X->span);
512}
drhe1b6a5b2000-07-29 13:06:59 +0000513expr(A) ::= MINUS(B) expr(X). [UMINUS] {
514 A = sqliteExpr(TK_UMINUS, X, 0, 0);
515 sqliteExprSpan(A,&B,&X->span);
516}
517expr(A) ::= PLUS(B) expr(X). [UMINUS] {
518 A = X;
519 sqliteExprSpan(A,&B,&X->span);
520}
521expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000522 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000523 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000524 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000525}
drhfef52082000-06-06 01:50:43 +0000526expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
527 ExprList *pList = sqliteExprListAppend(0, X, 0);
528 pList = sqliteExprListAppend(pList, Y, 0);
529 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000530 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000531 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000532}
drh4794b982000-06-06 13:54:14 +0000533expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
534 ExprList *pList = sqliteExprListAppend(0, X, 0);
535 pList = sqliteExprListAppend(pList, Y, 0);
536 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000537 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000538 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000539 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000540}
drhe1b6a5b2000-07-29 13:06:59 +0000541expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000542 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000543 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000544 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000545}
drhe1b6a5b2000-07-29 13:06:59 +0000546expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000547 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000548 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000549 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000550}
drhe1b6a5b2000-07-29 13:06:59 +0000551expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000552 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000553 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000554 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000555 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000556}
drhe1b6a5b2000-07-29 13:06:59 +0000557expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000558 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000559 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000560 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000561 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000562}
drhfef52082000-06-06 01:50:43 +0000563
drh17a7f8d2002-03-24 13:13:27 +0000564/* CASE expressions */
565expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
566 A = sqliteExpr(TK_CASE, X, Z, 0);
567 if( A ) A->pList = Y;
568 sqliteExprSpan(A, &C, &E);
569}
570%type case_exprlist {ExprList*}
571%destructor case_exprlist {sqliteExprListDelete($$);}
572case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
573 A = sqliteExprListAppend(X, Y, 0);
574 A = sqliteExprListAppend(A, Z, 0);
575}
576case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
577 A = sqliteExprListAppend(0, Y, 0);
578 A = sqliteExprListAppend(A, Z, 0);
579}
580%type case_else {Expr*}
581case_else(A) ::= ELSE expr(X). {A = X;}
582case_else(A) ::= . {A = 0;}
583%type case_operand {Expr*}
584case_operand(A) ::= expr(X). {A = X;}
585case_operand(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000586
587%type exprlist {ExprList*}
588%destructor exprlist {sqliteExprListDelete($$);}
589%type expritem {Expr*}
590%destructor expritem {sqliteExprDelete($$);}
591
drh348784e2000-05-29 20:41:49 +0000592exprlist(A) ::= exprlist(X) COMMA expritem(Y).
593 {A = sqliteExprListAppend(X,Y,0);}
594exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
595expritem(A) ::= expr(X). {A = X;}
596expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000597
drh382c0242001-10-06 16:33:02 +0000598///////////////////////////// The CREATE INDEX command ///////////////////////
599//
drh9cfcf5d2002-01-29 18:41:24 +0000600cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X)
601 ON ids(Y) LP idxlist(Z) RP(E) onconf(R). {
602 if( U!=OE_None ) U = R;
603 if( U==OE_Default) U = OE_Abort;
604 sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);
605}
drh717e6402001-09-27 03:22:32 +0000606
607%type uniqueflag {int}
drh9cfcf5d2002-01-29 18:41:24 +0000608uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
609uniqueflag(A) ::= . { A = OE_None; }
drh348784e2000-05-29 20:41:49 +0000610
611%type idxlist {IdList*}
612%destructor idxlist {sqliteIdListDelete($$);}
613%type idxitem {Token}
614
615idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
616 {A = sqliteIdListAppend(X,&Y);}
617idxlist(A) ::= idxitem(Y).
618 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000619idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000620
drh8aff1012001-12-22 14:49:24 +0000621///////////////////////////// The DROP INDEX command /////////////////////////
drh382c0242001-10-06 16:33:02 +0000622//
623
drhc4a3c772001-04-04 11:48:57 +0000624cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000625
drh382c0242001-10-06 16:33:02 +0000626
drh8aff1012001-12-22 14:49:24 +0000627///////////////////////////// The COPY command ///////////////////////////////
drh382c0242001-10-06 16:33:02 +0000628//
drh1c928532002-01-31 15:54:21 +0000629cmd ::= COPY orconf(R) ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drhb419a922002-01-30 16:17:23 +0000630 {sqliteCopy(pParse,&X,&Y,&Z,R);}
drh1c928532002-01-31 15:54:21 +0000631cmd ::= COPY orconf(R) ids(X) FROM ids(Y).
drhb419a922002-01-30 16:17:23 +0000632 {sqliteCopy(pParse,&X,&Y,0,R);}
drhdce2cbe2000-05-31 02:27:49 +0000633
drh382c0242001-10-06 16:33:02 +0000634///////////////////////////// The VACUUM command /////////////////////////////
635//
drhdce2cbe2000-05-31 02:27:49 +0000636cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000637cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000638
drh382c0242001-10-06 16:33:02 +0000639///////////////////////////// The PRAGMA command /////////////////////////////
640//
drhf57b14a2001-09-14 18:54:08 +0000641cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
642cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
643cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
644cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
drh382c0242001-10-06 16:33:02 +0000645cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
drh603240c2002-03-05 01:11:12 +0000646cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
drhf57b14a2001-09-14 18:54:08 +0000647plus_num(A) ::= plus_opt number(X). {A = X;}
648minus_num(A) ::= MINUS number(X). {A = X;}
649number(A) ::= INTEGER(X). {A = X;}
650number(A) ::= FLOAT(X). {A = X;}
651plus_opt ::= PLUS.
652plus_opt ::= .
danielk1977c3f9bad2002-05-15 08:30:12 +0000653
654//////////////////////////// The CREATE TRIGGER command /////////////////////
655cmd ::= CREATE(A) TRIGGER ids(B) trigger_time(C) trigger_event(D) ON ids(E)
656 foreach_clause(F) when_clause(G)
657 BEGIN trigger_cmd_list(S) END(Z). {
658 sqliteCreateTrigger(pParse, &B, C, D.a, D.b, &E, F, G, S,
659 A.z, (int)(Z.z - A.z) + Z.n );
660}
661
662%type trigger_time {int}
663trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
664trigger_time(A) ::= AFTER. { A = TK_AFTER; }
665trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
666trigger_time(A) ::= . { A = TK_BEFORE; }
667
drhad3cab52002-05-24 02:04:32 +0000668%type trigger_event {struct TrigEvent}
669%destructor trigger_event {sqliteIdListDelete($$.b);}
danielk1977c3f9bad2002-05-15 08:30:12 +0000670trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
671trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
672trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
673trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
674
675%type foreach_clause {int}
676foreach_clause(A) ::= . { A = TK_ROW; }
677foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
678foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
679
680%type when_clause {Expr *}
681when_clause(A) ::= . { A = 0; }
682when_clause(A) ::= WHEN expr(X). { A = X; }
683
684%type trigger_cmd_list {TriggerStep *}
685trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
686 X->pNext = Y ; A = X; }
687trigger_cmd_list(A) ::= . { A = 0; }
688
689%type trigger_cmd {TriggerStep *}
690// UPDATE
691trigger_cmd(A) ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
692 { A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
693
694// INSERT
695trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F)
696 VALUES LP itemlist(Y) RP.
697{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
698
699trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F) select(S).
700 {A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
701
702// DELETE
703trigger_cmd(A) ::= DELETE FROM ids(X) where_opt(Y).
704 {A = sqliteTriggerDeleteStep(&X, Y);}
705
706// SELECT
707trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
708
709//////////////////////// DROP TRIGGER statement //////////////////////////////
710cmd ::= DROP TRIGGER ids(X). {
711 sqliteDropTrigger(pParse,&X,0);
712}