blob: f7f965e9b58c4c9a139f1e274621663419a96310 [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**
drh34e33bb2002-06-06 19:04:16 +000017** @(#) $Id: parse.y,v 1.72 2002/06/06 19:04:16 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}
drhf18543c2002-03-30 15:26:50 +0000113id(A) ::= ID(X). {A = X;}
drh0bd1f4e2002-06-06 18:54:39 +0000114
drh34e33bb2002-06-06 19:04:16 +0000115// The following directive causes tokens ABORT, AFTER, ASC, etc. to
116// fallback to ID if they will not parse as their original value.
117// This obviates the need for the "id" nonterminal.
118//
drh0bd1f4e2002-06-06 18:54:39 +0000119%fallback ID
120 ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER CONFLICT
121 COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR
122 FULL IGNORE IMMEDIATE INITIALLY INSTEAD MATCH JOIN KEY
123 OF OFFSET PARTIAL PRAGMA REPLACE RESTRICT ROW STATEMENT
124 TEMP TRIGGER VACUUM VIEW.
drhc4a3c772001-04-04 11:48:57 +0000125
126// And "ids" is an identifer-or-string.
127//
128%type ids {Token}
129ids(A) ::= id(X). {A = X;}
130ids(A) ::= STRING(X). {A = X;}
131
drh382c0242001-10-06 16:33:02 +0000132type ::= .
133type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
134type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
135type ::= typename(X) LP signed COMMA signed RP(Y).
136 {sqliteAddColumnType(pParse,&X,&Y);}
137%type typename {Token}
138typename(A) ::= ids(X). {A = X;}
139typename(A) ::= typename(X) ids. {A = X;}
drh348784e2000-05-29 20:41:49 +0000140signed ::= INTEGER.
141signed ::= PLUS INTEGER.
142signed ::= MINUS INTEGER.
143carglist ::= carglist carg.
144carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000145carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000146carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000147carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
148carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
149carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
150carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
151carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
152carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
153carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
154carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
155carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000156
drh382c0242001-10-06 16:33:02 +0000157// In addition to the type name, we also care about the primary key and
158// UNIQUE constraints.
drh348784e2000-05-29 20:41:49 +0000159//
drh9cfcf5d2002-01-29 18:41:24 +0000160ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
161ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
162ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
163ccons ::= CHECK LP expr RP onconf.
drh04738cb2002-06-02 18:19:00 +0000164ccons ::= references.
165ccons ::= defer_subclause.
166
167// A REFERENCES clause is parsed but the current implementation does not
168// do anything with it.
169//
170references ::= REFERENCES ids LP idxlist RP refargs.
171references ::= REFERENCES ids refargs.
172refargs ::= .
173refargs ::= refargs refarg.
174refarg ::= MATCH FULL.
175refarg ::= MATCH PARTIAL.
176refarg ::= ON DELETE refact.
177refarg ::= ON UPDATE refact.
178refact ::= SET NULL.
179refact ::= SET DEFAULT.
180refact ::= CASCADE.
181refact ::= RESTRICT.
182defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt.
183defer_subclause ::= DEFERRABLE init_deferred_pred_opt.
184init_deferred_pred_opt ::= .
185init_deferred_pred_opt ::= INITIALLY DEFERRED.
186init_deferred_pred_opt ::= INITIALLY IMMEDIATE.
drh348784e2000-05-29 20:41:49 +0000187
188// For the time being, the only constraint we care about is the primary
drh382c0242001-10-06 16:33:02 +0000189// key and UNIQUE. Both create indices.
drh348784e2000-05-29 20:41:49 +0000190//
191conslist_opt ::= .
192conslist_opt ::= COMMA conslist.
193conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000194conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000195conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000196tcons ::= CONSTRAINT ids.
drh9cfcf5d2002-01-29 18:41:24 +0000197tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
198 {sqliteAddPrimaryKey(pParse,X,R);}
199tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
200 {sqliteCreateIndex(pParse,0,0,X,R,0,0);}
201tcons ::= CHECK expr onconf.
drh04738cb2002-06-02 18:19:00 +0000202tcons ::= FOREIGN KEY LP idxlist RP references defer_subclause_opt.
203defer_subclause_opt ::= .
204defer_subclause_opt ::= defer_subclause.
drh9cfcf5d2002-01-29 18:41:24 +0000205
206// The following is a non-standard extension that allows us to declare the
207// default behavior when there is a constraint conflict.
208//
209%type onconf {int}
drh1c928532002-01-31 15:54:21 +0000210%type orconf {int}
211%type resolvetype {int}
212onconf(A) ::= . { A = OE_Default; }
213onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
214orconf(A) ::= . { A = OE_Default; }
215orconf(A) ::= OR resolvetype(X). { A = X; }
216resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
217resolvetype(A) ::= ABORT. { A = OE_Abort; }
218resolvetype(A) ::= FAIL. { A = OE_Fail; }
219resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
220resolvetype(A) ::= REPLACE. { A = OE_Replace; }
drh348784e2000-05-29 20:41:49 +0000221
drh382c0242001-10-06 16:33:02 +0000222////////////////////////// The DROP TABLE /////////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000223//
drh4ff6dfa2002-03-03 23:06:00 +0000224cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X,0);}
drh348784e2000-05-29 20:41:49 +0000225
drha76b5df2002-02-23 02:32:10 +0000226///////////////////// The CREATE VIEW statement /////////////////////////////
227//
228cmd ::= CREATE(X) VIEW ids(Y) AS select(S). {
229 sqliteCreateView(pParse, &X, &Y, S);
230}
231cmd ::= DROP VIEW ids(X). {
drh4ff6dfa2002-03-03 23:06:00 +0000232 sqliteDropTable(pParse, &X, 1);
drha76b5df2002-02-23 02:32:10 +0000233}
234
drh382c0242001-10-06 16:33:02 +0000235//////////////////////// The SELECT statement /////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000236//
drh9bb61fe2000-06-05 16:01:39 +0000237cmd ::= select(X). {
drh832508b2002-03-02 17:04:07 +0000238 sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
drh9bb61fe2000-06-05 16:01:39 +0000239 sqliteSelectDelete(X);
240}
drhefb72512000-05-31 20:00:52 +0000241
drh9bb61fe2000-06-05 16:01:39 +0000242%type select {Select*}
243%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000244%type oneselect {Select*}
245%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000246
drh82c3d632000-06-06 21:56:07 +0000247select(A) ::= oneselect(X). {A = X;}
drh0a36c572002-02-18 22:49:59 +0000248select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000249 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000250 Z->op = Y;
251 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000252 }
253 A = Z;
drh82c3d632000-06-06 21:56:07 +0000254}
drh0a36c572002-02-18 22:49:59 +0000255%type multiselect_op {int}
256multiselect_op(A) ::= UNION. {A = TK_UNION;}
257multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
258multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
259multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
drh82c3d632000-06-06 21:56:07 +0000260oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
drh9bbca4c2001-11-06 04:00:18 +0000261 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
drhad3cab52002-05-24 02:04:32 +0000262 A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
drh9bb61fe2000-06-05 16:01:39 +0000263}
264
265// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
266// present and false (0) if it is not.
267//
drhefb72512000-05-31 20:00:52 +0000268%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000269distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000270distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000271distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000272
drh9bb61fe2000-06-05 16:01:39 +0000273// selcollist is a list of expressions that are to become the return
drh7c917d12001-12-16 20:05:05 +0000274// values of the SELECT statement. The "*" in statements like
275// "SELECT * FROM ..." is encoded as a special expression with an
276// opcode of TK_ALL.
drh9bb61fe2000-06-05 16:01:39 +0000277//
drh348784e2000-05-29 20:41:49 +0000278%type selcollist {ExprList*}
279%destructor selcollist {sqliteExprListDelete($$);}
280%type sclp {ExprList*}
281%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000282sclp(A) ::= selcollist(X) COMMA. {A = X;}
283sclp(A) ::= . {A = 0;}
drh01f3f252002-05-24 16:14:15 +0000284selcollist(A) ::= sclp(P) expr(X) as(Y). {
285 A = sqliteExprListAppend(P,X,Y.n?&Y:0);
286}
drh7c917d12001-12-16 20:05:05 +0000287selcollist(A) ::= sclp(P) STAR. {
288 A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
289}
drh54473222002-04-04 02:10:55 +0000290selcollist(A) ::= sclp(P) ids(X) DOT STAR. {
291 Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
292 Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
293 A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
294}
drh01f3f252002-05-24 16:14:15 +0000295
296// An option "AS <id>" phrase that can follow one of the expressions that
297// define the result set, or one of the tables in the FROM clause.
298//
299%type as {Token}
300as(X) ::= AS ids(Y). { X = Y; }
301as(X) ::= . { X.n = 0; }
drh9bb61fe2000-06-05 16:01:39 +0000302
drh348784e2000-05-29 20:41:49 +0000303
drhad3cab52002-05-24 02:04:32 +0000304%type seltablist {SrcList*}
305%destructor seltablist {sqliteSrcListDelete($$);}
306%type stl_prefix {SrcList*}
307%destructor stl_prefix {sqliteSrcListDelete($$);}
308%type from {SrcList*}
309%destructor from {sqliteSrcListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000310
drh01f3f252002-05-24 16:14:15 +0000311// A complete FROM clause.
312//
drhbf3a4fa2002-04-06 13:57:42 +0000313from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
drh348784e2000-05-29 20:41:49 +0000314from(A) ::= FROM seltablist(X). {A = X;}
drh01f3f252002-05-24 16:14:15 +0000315
316// "seltablist" is a "Select Table List" - the content of the FROM clause
317// in a SELECT statement. "stl_prefix" is a prefix of this list.
318//
319stl_prefix(A) ::= seltablist(X) joinop(Y). {
320 A = X;
321 if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
322}
drh348784e2000-05-29 20:41:49 +0000323stl_prefix(A) ::= . {A = 0;}
drh01f3f252002-05-24 16:14:15 +0000324seltablist(A) ::= stl_prefix(X) ids(Y) as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000325 A = sqliteSrcListAppend(X,&Y);
drh01f3f252002-05-24 16:14:15 +0000326 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
327 if( N ){
328 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
329 else { sqliteExprDelete(N); }
330 }
331 if( U ){
332 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
333 else { sqliteIdListDelete(U); }
334 }
drhc4a3c772001-04-04 11:48:57 +0000335}
drh01f3f252002-05-24 16:14:15 +0000336seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000337 A = sqliteSrcListAppend(X,0);
338 A->a[A->nSrc-1].pSelect = S;
drhd5feede2002-05-08 21:46:14 +0000339 if( S->pOrderBy ){
340 sqliteExprListDelete(S->pOrderBy);
341 S->pOrderBy = 0;
342 }
drh01f3f252002-05-24 16:14:15 +0000343 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
344 if( N ){
345 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
346 else { sqliteExprDelete(N); }
drhd5feede2002-05-08 21:46:14 +0000347 }
drh01f3f252002-05-24 16:14:15 +0000348 if( U ){
349 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
350 else { sqliteIdListDelete(U); }
351 }
drh22f70c32002-02-18 01:17:00 +0000352}
drh348784e2000-05-29 20:41:49 +0000353
drh01f3f252002-05-24 16:14:15 +0000354%type joinop {int}
355%type joinop2 {int}
356joinop(X) ::= COMMA. { X = JT_INNER; }
357joinop(X) ::= JOIN. { X = JT_INNER; }
358joinop(X) ::= ID(A) JOIN. { X = sqliteJoinType(pParse,&A,0,0); }
359joinop(X) ::= ID(A) ID(B) JOIN. { X = sqliteJoinType(pParse,&A,&B,0); }
360joinop(X) ::= ID(A) ID(B) ID(C) JOIN. { X = sqliteJoinType(pParse,&A,&B,&C); }
361
362%type on_opt {Expr*}
363%destructor on_opt {sqliteExprDelete($$);}
364on_opt(N) ::= ON expr(E). {N = E;}
365on_opt(N) ::= . {N = 0;}
366
367%type using_opt {IdList*}
368%destructor using_opt {sqliteIdListDelete($$);}
369using_opt(U) ::= USING LP idxlist(L) RP. {U = L;}
370using_opt(U) ::= . {U = 0;}
371
372
drh348784e2000-05-29 20:41:49 +0000373%type orderby_opt {ExprList*}
374%destructor orderby_opt {sqliteExprListDelete($$);}
375%type sortlist {ExprList*}
376%destructor sortlist {sqliteExprListDelete($$);}
377%type sortitem {Expr*}
378%destructor sortitem {sqliteExprDelete($$);}
379
380orderby_opt(A) ::= . {A = 0;}
381orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000382sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
383 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000384 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000385}
386sortlist(A) ::= sortitem(Y) sortorder(Z). {
387 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000388 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000389}
drhda9d6c42000-05-31 18:20:14 +0000390sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000391
392%type sortorder {int}
393
394sortorder(A) ::= ASC. {A = 0;}
395sortorder(A) ::= DESC. {A = 1;}
396sortorder(A) ::= . {A = 0;}
397
drh22827922000-06-06 17:27:05 +0000398%type groupby_opt {ExprList*}
399%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000400groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000401groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
402
403%type having_opt {Expr*}
404%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000405having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000406having_opt(A) ::= HAVING expr(X). {A = X;}
407
drhad3cab52002-05-24 02:04:32 +0000408%type limit_opt {struct LimitVal}
409limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
410limit_opt(A) ::= LIMIT INTEGER(X). {A.limit = atoi(X.z); A.offset = 0;}
drh9bbca4c2001-11-06 04:00:18 +0000411limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y).
drhad3cab52002-05-24 02:04:32 +0000412 {A.limit = atoi(X.z); A.offset = atoi(Y.z);}
drh9bbca4c2001-11-06 04:00:18 +0000413limit_sep ::= OFFSET.
414limit_sep ::= COMMA.
415
drh382c0242001-10-06 16:33:02 +0000416/////////////////////////// The DELETE statement /////////////////////////////
417//
drhc4a3c772001-04-04 11:48:57 +0000418cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000419 {sqliteDeleteFrom(pParse, &X, Y);}
420
421%type where_opt {Expr*}
422%destructor where_opt {sqliteExprDelete($$);}
423
424where_opt(A) ::= . {A = 0;}
425where_opt(A) ::= WHERE expr(X). {A = X;}
426
427%type setlist {ExprList*}
428%destructor setlist {sqliteExprListDelete($$);}
429
drh382c0242001-10-06 16:33:02 +0000430////////////////////////// The UPDATE command ////////////////////////////////
431//
drh1c928532002-01-31 15:54:21 +0000432cmd ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
drh9cfcf5d2002-01-29 18:41:24 +0000433 {sqliteUpdate(pParse,&X,Y,Z,R);}
drh348784e2000-05-29 20:41:49 +0000434
drhc4a3c772001-04-04 11:48:57 +0000435setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000436 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000437setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000438
drh382c0242001-10-06 16:33:02 +0000439////////////////////////// The INSERT command /////////////////////////////////
440//
drhfa86c412002-02-02 15:01:15 +0000441cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh9cfcf5d2002-01-29 18:41:24 +0000442 {sqliteInsert(pParse, &X, Y, 0, F, R);}
drhfa86c412002-02-02 15:01:15 +0000443cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) select(S).
drh9cfcf5d2002-01-29 18:41:24 +0000444 {sqliteInsert(pParse, &X, 0, S, F, R);}
drh348784e2000-05-29 20:41:49 +0000445
drhfa86c412002-02-02 15:01:15 +0000446%type insert_cmd {int}
447insert_cmd(A) ::= INSERT orconf(R). {A = R;}
448insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
449
drh348784e2000-05-29 20:41:49 +0000450
451%type itemlist {ExprList*}
452%destructor itemlist {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000453
drhe64e7b22002-02-18 13:56:36 +0000454itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
455itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
drh348784e2000-05-29 20:41:49 +0000456
drh967e8b72000-06-21 13:59:10 +0000457%type inscollist_opt {IdList*}
458%destructor inscollist_opt {sqliteIdListDelete($$);}
459%type inscollist {IdList*}
460%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000461
drhc4a3c772001-04-04 11:48:57 +0000462inscollist_opt(A) ::= . {A = 0;}
463inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
464inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
465inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000466
drh382c0242001-10-06 16:33:02 +0000467/////////////////////////// Expression Processing /////////////////////////////
468//
drh348784e2000-05-29 20:41:49 +0000469%left OR.
470%left AND.
drh8be51132000-06-03 19:19:41 +0000471%right NOT.
drhfef52082000-06-06 01:50:43 +0000472%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000473%left GT GE LT LE.
drh81a20f22001-10-12 17:30:04 +0000474%left BITAND BITOR LSHIFT RSHIFT.
drh348784e2000-05-29 20:41:49 +0000475%left PLUS MINUS.
drhbf4133c2001-10-13 02:59:08 +0000476%left STAR SLASH REM.
drh00400772000-06-16 20:51:26 +0000477%left CONCAT.
drh81a20f22001-10-12 17:30:04 +0000478%right UMINUS BITNOT.
drh348784e2000-05-29 20:41:49 +0000479
480%type expr {Expr*}
481%destructor expr {sqliteExprDelete($$);}
482
drhe1b6a5b2000-07-29 13:06:59 +0000483expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000484expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000485expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
486expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000487 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
488 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
489 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
490}
drh348784e2000-05-29 20:41:49 +0000491expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
492expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
493expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000494expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
495 A = sqliteExprFunction(Y, &X);
496 sqliteExprSpan(A,&X,&E);
497}
498expr(A) ::= ID(X) LP STAR RP(E). {
499 A = sqliteExprFunction(0, &X);
500 sqliteExprSpan(A,&X,&E);
501}
drh348784e2000-05-29 20:41:49 +0000502expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
503expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
504expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
505expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
506expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
507expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
508expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
509expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drh81a20f22001-10-12 17:30:04 +0000510expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
511expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
512expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
513expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
drh0ac65892002-04-20 14:24:41 +0000514expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
515 ExprList *pList = sqliteExprListAppend(0, Y, 0);
516 pList = sqliteExprListAppend(pList, X, 0);
517 A = sqliteExprFunction(pList, &OP);
518 sqliteExprSpan(A, &X->span, &Y->span);
519}
520expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
521 ExprList *pList = sqliteExprListAppend(0, Y, 0);
522 pList = sqliteExprListAppend(pList, X, 0);
523 A = sqliteExprFunction(pList, &OP);
drh4794b982000-06-06 13:54:14 +0000524 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000525 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000526}
drh0ac65892002-04-20 14:24:41 +0000527likeop(A) ::= LIKE(X). {A = X;}
528likeop(A) ::= GLOB(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000529expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
530expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
531expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
532expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drhbf4133c2001-10-13 02:59:08 +0000533expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000534expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000535expr(A) ::= expr(X) ISNULL(E). {
536 A = sqliteExpr(TK_ISNULL, X, 0, 0);
537 sqliteExprSpan(A,&X->span,&E);
538}
drh33048c02001-10-01 14:29:22 +0000539expr(A) ::= expr(X) IS NULL(E). {
540 A = sqliteExpr(TK_ISNULL, X, 0, 0);
541 sqliteExprSpan(A,&X->span,&E);
542}
drhe1b6a5b2000-07-29 13:06:59 +0000543expr(A) ::= expr(X) NOTNULL(E). {
544 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
545 sqliteExprSpan(A,&X->span,&E);
546}
drh33048c02001-10-01 14:29:22 +0000547expr(A) ::= expr(X) NOT NULL(E). {
548 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
549 sqliteExprSpan(A,&X->span,&E);
550}
drh81a20f22001-10-12 17:30:04 +0000551expr(A) ::= expr(X) IS NOT NULL(E). {
552 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
553 sqliteExprSpan(A,&X->span,&E);
554}
drhe1b6a5b2000-07-29 13:06:59 +0000555expr(A) ::= NOT(B) expr(X). {
556 A = sqliteExpr(TK_NOT, X, 0, 0);
557 sqliteExprSpan(A,&B,&X->span);
558}
drh81a20f22001-10-12 17:30:04 +0000559expr(A) ::= BITNOT(B) expr(X). {
560 A = sqliteExpr(TK_BITNOT, X, 0, 0);
561 sqliteExprSpan(A,&B,&X->span);
562}
drhe1b6a5b2000-07-29 13:06:59 +0000563expr(A) ::= MINUS(B) expr(X). [UMINUS] {
564 A = sqliteExpr(TK_UMINUS, X, 0, 0);
565 sqliteExprSpan(A,&B,&X->span);
566}
567expr(A) ::= PLUS(B) expr(X). [UMINUS] {
568 A = X;
569 sqliteExprSpan(A,&B,&X->span);
570}
571expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000572 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000573 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000574 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000575}
drhfef52082000-06-06 01:50:43 +0000576expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
577 ExprList *pList = sqliteExprListAppend(0, X, 0);
578 pList = sqliteExprListAppend(pList, Y, 0);
579 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000580 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000581 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000582}
drh4794b982000-06-06 13:54:14 +0000583expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
584 ExprList *pList = sqliteExprListAppend(0, X, 0);
585 pList = sqliteExprListAppend(pList, Y, 0);
586 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000587 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000588 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000589 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000590}
drhe1b6a5b2000-07-29 13:06:59 +0000591expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000592 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000593 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000594 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000595}
drhe1b6a5b2000-07-29 13:06:59 +0000596expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000597 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000598 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000599 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000600}
drhe1b6a5b2000-07-29 13:06:59 +0000601expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000602 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000603 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000604 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000605 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000606}
drhe1b6a5b2000-07-29 13:06:59 +0000607expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000608 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000609 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000610 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000611 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000612}
drhfef52082000-06-06 01:50:43 +0000613
drh17a7f8d2002-03-24 13:13:27 +0000614/* CASE expressions */
615expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
616 A = sqliteExpr(TK_CASE, X, Z, 0);
617 if( A ) A->pList = Y;
618 sqliteExprSpan(A, &C, &E);
619}
620%type case_exprlist {ExprList*}
621%destructor case_exprlist {sqliteExprListDelete($$);}
622case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
623 A = sqliteExprListAppend(X, Y, 0);
624 A = sqliteExprListAppend(A, Z, 0);
625}
626case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
627 A = sqliteExprListAppend(0, Y, 0);
628 A = sqliteExprListAppend(A, Z, 0);
629}
630%type case_else {Expr*}
631case_else(A) ::= ELSE expr(X). {A = X;}
632case_else(A) ::= . {A = 0;}
633%type case_operand {Expr*}
634case_operand(A) ::= expr(X). {A = X;}
635case_operand(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000636
637%type exprlist {ExprList*}
638%destructor exprlist {sqliteExprListDelete($$);}
639%type expritem {Expr*}
640%destructor expritem {sqliteExprDelete($$);}
641
drh348784e2000-05-29 20:41:49 +0000642exprlist(A) ::= exprlist(X) COMMA expritem(Y).
643 {A = sqliteExprListAppend(X,Y,0);}
644exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
645expritem(A) ::= expr(X). {A = X;}
646expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000647
drh382c0242001-10-06 16:33:02 +0000648///////////////////////////// The CREATE INDEX command ///////////////////////
649//
drh9cfcf5d2002-01-29 18:41:24 +0000650cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X)
651 ON ids(Y) LP idxlist(Z) RP(E) onconf(R). {
652 if( U!=OE_None ) U = R;
653 if( U==OE_Default) U = OE_Abort;
654 sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);
655}
drh717e6402001-09-27 03:22:32 +0000656
657%type uniqueflag {int}
drh9cfcf5d2002-01-29 18:41:24 +0000658uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
659uniqueflag(A) ::= . { A = OE_None; }
drh348784e2000-05-29 20:41:49 +0000660
661%type idxlist {IdList*}
662%destructor idxlist {sqliteIdListDelete($$);}
663%type idxitem {Token}
664
665idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
666 {A = sqliteIdListAppend(X,&Y);}
667idxlist(A) ::= idxitem(Y).
668 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000669idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000670
drh8aff1012001-12-22 14:49:24 +0000671///////////////////////////// The DROP INDEX command /////////////////////////
drh382c0242001-10-06 16:33:02 +0000672//
673
drhc4a3c772001-04-04 11:48:57 +0000674cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000675
drh382c0242001-10-06 16:33:02 +0000676
drh8aff1012001-12-22 14:49:24 +0000677///////////////////////////// The COPY command ///////////////////////////////
drh382c0242001-10-06 16:33:02 +0000678//
drh1c928532002-01-31 15:54:21 +0000679cmd ::= COPY orconf(R) ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drhb419a922002-01-30 16:17:23 +0000680 {sqliteCopy(pParse,&X,&Y,&Z,R);}
drh1c928532002-01-31 15:54:21 +0000681cmd ::= COPY orconf(R) ids(X) FROM ids(Y).
drhb419a922002-01-30 16:17:23 +0000682 {sqliteCopy(pParse,&X,&Y,0,R);}
drhdce2cbe2000-05-31 02:27:49 +0000683
drh382c0242001-10-06 16:33:02 +0000684///////////////////////////// The VACUUM command /////////////////////////////
685//
drhdce2cbe2000-05-31 02:27:49 +0000686cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000687cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000688
drh382c0242001-10-06 16:33:02 +0000689///////////////////////////// The PRAGMA command /////////////////////////////
690//
drhf57b14a2001-09-14 18:54:08 +0000691cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
692cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
693cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
694cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
drh382c0242001-10-06 16:33:02 +0000695cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
drh603240c2002-03-05 01:11:12 +0000696cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
drhf57b14a2001-09-14 18:54:08 +0000697plus_num(A) ::= plus_opt number(X). {A = X;}
698minus_num(A) ::= MINUS number(X). {A = X;}
699number(A) ::= INTEGER(X). {A = X;}
700number(A) ::= FLOAT(X). {A = X;}
701plus_opt ::= PLUS.
702plus_opt ::= .
danielk1977c3f9bad2002-05-15 08:30:12 +0000703
704//////////////////////////// The CREATE TRIGGER command /////////////////////
705cmd ::= CREATE(A) TRIGGER ids(B) trigger_time(C) trigger_event(D) ON ids(E)
706 foreach_clause(F) when_clause(G)
707 BEGIN trigger_cmd_list(S) END(Z). {
708 sqliteCreateTrigger(pParse, &B, C, D.a, D.b, &E, F, G, S,
709 A.z, (int)(Z.z - A.z) + Z.n );
710}
711
712%type trigger_time {int}
713trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
714trigger_time(A) ::= AFTER. { A = TK_AFTER; }
715trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
716trigger_time(A) ::= . { A = TK_BEFORE; }
717
drhad3cab52002-05-24 02:04:32 +0000718%type trigger_event {struct TrigEvent}
719%destructor trigger_event {sqliteIdListDelete($$.b);}
danielk1977c3f9bad2002-05-15 08:30:12 +0000720trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
721trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
722trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
723trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
724
725%type foreach_clause {int}
726foreach_clause(A) ::= . { A = TK_ROW; }
727foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
728foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
729
730%type when_clause {Expr *}
731when_clause(A) ::= . { A = 0; }
732when_clause(A) ::= WHEN expr(X). { A = X; }
733
734%type trigger_cmd_list {TriggerStep *}
735trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
736 X->pNext = Y ; A = X; }
737trigger_cmd_list(A) ::= . { A = 0; }
738
739%type trigger_cmd {TriggerStep *}
740// UPDATE
741trigger_cmd(A) ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
742 { A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
743
744// INSERT
745trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F)
746 VALUES LP itemlist(Y) RP.
747{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
748
749trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F) select(S).
750 {A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
751
752// DELETE
753trigger_cmd(A) ::= DELETE FROM ids(X) where_opt(Y).
754 {A = sqliteTriggerDeleteStep(&X, Y);}
755
756// SELECT
757trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
758
759//////////////////////// DROP TRIGGER statement //////////////////////////////
760cmd ::= DROP TRIGGER ids(X). {
761 sqliteDropTrigger(pParse,&X,0);
762}