blob: 18e2fba13fb0e46410e0c61b243660cfc97da931 [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**
drh0bd1f4e2002-06-06 18:54:39 +000017** @(#) $Id: parse.y,v 1.71 2002/06/06 18:54:40 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}
drh0bd1f4e2002-06-06 18:54:39 +0000113//id(A) ::= ABORT(X). {A = X;}
114//id(A) ::= AFTER(X). {A = X;}
115//id(A) ::= ASC(X). {A = X;}
116//id(A) ::= BEFORE(X). {A = X;}
117//id(A) ::= BEGIN(X). {A = X;}
118//id(A) ::= CASCADE(X). {A = X;}
119//id(A) ::= CLUSTER(X). {A = X;}
120//id(A) ::= CONFLICT(X). {A = X;}
121//id(A) ::= COPY(X). {A = X;}
122//id(A) ::= DEFERRED(X). {A = X;}
123//id(A) ::= DELIMITERS(X). {A = X;}
124//id(A) ::= DESC(X). {A = X;}
125//id(A) ::= EACH(X). {A = X;}
126//id(A) ::= END(X). {A = X;}
127//id(A) ::= EXPLAIN(X). {A = X;}
128//id(A) ::= FAIL(X). {A = X;}
129//id(A) ::= FOR(X). {A = X;}
130//id(A) ::= FULL(X). {A = X;}
drhf18543c2002-03-30 15:26:50 +0000131id(A) ::= ID(X). {A = X;}
drh0bd1f4e2002-06-06 18:54:39 +0000132//id(A) ::= IGNORE(X). {A = X;}
133//id(A) ::= IMMEDATE(X). {A = X;}
134//id(A) ::= INITIALLY(X). {A = X;}
135//id(A) ::= INSTEAD(X). {A = X;}
136//id(A) ::= MATCH(X). {A = X;}
137//id(A) ::= JOIN(X). {A = X;}
138//id(A) ::= KEY(X). {A = X;}
139//id(A) ::= OF(X). {A = X;}
140//id(A) ::= OFFSET(X). {A = X;}
141//id(A) ::= PARTIAL(X). {A = X;}
142//id(A) ::= PRAGMA(X). {A = X;}
143//id(A) ::= REPLACE(X). {A = X;}
144//id(A) ::= RESTRICT(X). {A = X;}
145//id(A) ::= ROW(X). {A = X;}
146//id(A) ::= STATEMENT(X). {A = X;}
147//id(A) ::= TEMP(X). {A = X;}
148//id(A) ::= TRIGGER(X). {A = X;}
149//id(A) ::= VACUUM(X). {A = X;}
150//id(A) ::= VIEW(X). {A = X;}
151
152%fallback ID
153 ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER CONFLICT
154 COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR
155 FULL IGNORE IMMEDIATE INITIALLY INSTEAD MATCH JOIN KEY
156 OF OFFSET PARTIAL PRAGMA REPLACE RESTRICT ROW STATEMENT
157 TEMP TRIGGER VACUUM VIEW.
drhc4a3c772001-04-04 11:48:57 +0000158
159// And "ids" is an identifer-or-string.
160//
161%type ids {Token}
162ids(A) ::= id(X). {A = X;}
163ids(A) ::= STRING(X). {A = X;}
164
drh382c0242001-10-06 16:33:02 +0000165type ::= .
166type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
167type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
168type ::= typename(X) LP signed COMMA signed RP(Y).
169 {sqliteAddColumnType(pParse,&X,&Y);}
170%type typename {Token}
171typename(A) ::= ids(X). {A = X;}
172typename(A) ::= typename(X) ids. {A = X;}
drh348784e2000-05-29 20:41:49 +0000173signed ::= INTEGER.
174signed ::= PLUS INTEGER.
175signed ::= MINUS INTEGER.
176carglist ::= carglist carg.
177carglist ::= .
drhc4a3c772001-04-04 11:48:57 +0000178carg ::= CONSTRAINT ids ccons.
drh348784e2000-05-29 20:41:49 +0000179carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000180carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
181carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
182carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
183carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
184carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
185carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
186carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
187carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
188carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000189
drh382c0242001-10-06 16:33:02 +0000190// In addition to the type name, we also care about the primary key and
191// UNIQUE constraints.
drh348784e2000-05-29 20:41:49 +0000192//
drh9cfcf5d2002-01-29 18:41:24 +0000193ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
194ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
195ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
196ccons ::= CHECK LP expr RP onconf.
drh04738cb2002-06-02 18:19:00 +0000197ccons ::= references.
198ccons ::= defer_subclause.
199
200// A REFERENCES clause is parsed but the current implementation does not
201// do anything with it.
202//
203references ::= REFERENCES ids LP idxlist RP refargs.
204references ::= REFERENCES ids refargs.
205refargs ::= .
206refargs ::= refargs refarg.
207refarg ::= MATCH FULL.
208refarg ::= MATCH PARTIAL.
209refarg ::= ON DELETE refact.
210refarg ::= ON UPDATE refact.
211refact ::= SET NULL.
212refact ::= SET DEFAULT.
213refact ::= CASCADE.
214refact ::= RESTRICT.
215defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt.
216defer_subclause ::= DEFERRABLE init_deferred_pred_opt.
217init_deferred_pred_opt ::= .
218init_deferred_pred_opt ::= INITIALLY DEFERRED.
219init_deferred_pred_opt ::= INITIALLY IMMEDIATE.
drh348784e2000-05-29 20:41:49 +0000220
221// For the time being, the only constraint we care about is the primary
drh382c0242001-10-06 16:33:02 +0000222// key and UNIQUE. Both create indices.
drh348784e2000-05-29 20:41:49 +0000223//
224conslist_opt ::= .
225conslist_opt ::= COMMA conslist.
226conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000227conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000228conslist ::= tcons.
drhc4a3c772001-04-04 11:48:57 +0000229tcons ::= CONSTRAINT ids.
drh9cfcf5d2002-01-29 18:41:24 +0000230tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
231 {sqliteAddPrimaryKey(pParse,X,R);}
232tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
233 {sqliteCreateIndex(pParse,0,0,X,R,0,0);}
234tcons ::= CHECK expr onconf.
drh04738cb2002-06-02 18:19:00 +0000235tcons ::= FOREIGN KEY LP idxlist RP references defer_subclause_opt.
236defer_subclause_opt ::= .
237defer_subclause_opt ::= defer_subclause.
drh9cfcf5d2002-01-29 18:41:24 +0000238
239// The following is a non-standard extension that allows us to declare the
240// default behavior when there is a constraint conflict.
241//
242%type onconf {int}
drh1c928532002-01-31 15:54:21 +0000243%type orconf {int}
244%type resolvetype {int}
245onconf(A) ::= . { A = OE_Default; }
246onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
247orconf(A) ::= . { A = OE_Default; }
248orconf(A) ::= OR resolvetype(X). { A = X; }
249resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
250resolvetype(A) ::= ABORT. { A = OE_Abort; }
251resolvetype(A) ::= FAIL. { A = OE_Fail; }
252resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
253resolvetype(A) ::= REPLACE. { A = OE_Replace; }
drh348784e2000-05-29 20:41:49 +0000254
drh382c0242001-10-06 16:33:02 +0000255////////////////////////// The DROP TABLE /////////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000256//
drh4ff6dfa2002-03-03 23:06:00 +0000257cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X,0);}
drh348784e2000-05-29 20:41:49 +0000258
drha76b5df2002-02-23 02:32:10 +0000259///////////////////// The CREATE VIEW statement /////////////////////////////
260//
261cmd ::= CREATE(X) VIEW ids(Y) AS select(S). {
262 sqliteCreateView(pParse, &X, &Y, S);
263}
264cmd ::= DROP VIEW ids(X). {
drh4ff6dfa2002-03-03 23:06:00 +0000265 sqliteDropTable(pParse, &X, 1);
drha76b5df2002-02-23 02:32:10 +0000266}
267
drh382c0242001-10-06 16:33:02 +0000268//////////////////////// The SELECT statement /////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000269//
drh9bb61fe2000-06-05 16:01:39 +0000270cmd ::= select(X). {
drh832508b2002-03-02 17:04:07 +0000271 sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
drh9bb61fe2000-06-05 16:01:39 +0000272 sqliteSelectDelete(X);
273}
drhefb72512000-05-31 20:00:52 +0000274
drh9bb61fe2000-06-05 16:01:39 +0000275%type select {Select*}
276%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000277%type oneselect {Select*}
278%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000279
drh82c3d632000-06-06 21:56:07 +0000280select(A) ::= oneselect(X). {A = X;}
drh0a36c572002-02-18 22:49:59 +0000281select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000282 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000283 Z->op = Y;
284 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000285 }
286 A = Z;
drh82c3d632000-06-06 21:56:07 +0000287}
drh0a36c572002-02-18 22:49:59 +0000288%type multiselect_op {int}
289multiselect_op(A) ::= UNION. {A = TK_UNION;}
290multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
291multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
292multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
drh82c3d632000-06-06 21:56:07 +0000293oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
drh9bbca4c2001-11-06 04:00:18 +0000294 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
drhad3cab52002-05-24 02:04:32 +0000295 A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
drh9bb61fe2000-06-05 16:01:39 +0000296}
297
298// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
299// present and false (0) if it is not.
300//
drhefb72512000-05-31 20:00:52 +0000301%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000302distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000303distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000304distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000305
drh9bb61fe2000-06-05 16:01:39 +0000306// selcollist is a list of expressions that are to become the return
drh7c917d12001-12-16 20:05:05 +0000307// values of the SELECT statement. The "*" in statements like
308// "SELECT * FROM ..." is encoded as a special expression with an
309// opcode of TK_ALL.
drh9bb61fe2000-06-05 16:01:39 +0000310//
drh348784e2000-05-29 20:41:49 +0000311%type selcollist {ExprList*}
312%destructor selcollist {sqliteExprListDelete($$);}
313%type sclp {ExprList*}
314%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000315sclp(A) ::= selcollist(X) COMMA. {A = X;}
316sclp(A) ::= . {A = 0;}
drh01f3f252002-05-24 16:14:15 +0000317selcollist(A) ::= sclp(P) expr(X) as(Y). {
318 A = sqliteExprListAppend(P,X,Y.n?&Y:0);
319}
drh7c917d12001-12-16 20:05:05 +0000320selcollist(A) ::= sclp(P) STAR. {
321 A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
322}
drh54473222002-04-04 02:10:55 +0000323selcollist(A) ::= sclp(P) ids(X) DOT STAR. {
324 Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
325 Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
326 A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
327}
drh01f3f252002-05-24 16:14:15 +0000328
329// An option "AS <id>" phrase that can follow one of the expressions that
330// define the result set, or one of the tables in the FROM clause.
331//
332%type as {Token}
333as(X) ::= AS ids(Y). { X = Y; }
334as(X) ::= . { X.n = 0; }
drh9bb61fe2000-06-05 16:01:39 +0000335
drh348784e2000-05-29 20:41:49 +0000336
drhad3cab52002-05-24 02:04:32 +0000337%type seltablist {SrcList*}
338%destructor seltablist {sqliteSrcListDelete($$);}
339%type stl_prefix {SrcList*}
340%destructor stl_prefix {sqliteSrcListDelete($$);}
341%type from {SrcList*}
342%destructor from {sqliteSrcListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000343
drh01f3f252002-05-24 16:14:15 +0000344// A complete FROM clause.
345//
drhbf3a4fa2002-04-06 13:57:42 +0000346from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
drh348784e2000-05-29 20:41:49 +0000347from(A) ::= FROM seltablist(X). {A = X;}
drh01f3f252002-05-24 16:14:15 +0000348
349// "seltablist" is a "Select Table List" - the content of the FROM clause
350// in a SELECT statement. "stl_prefix" is a prefix of this list.
351//
352stl_prefix(A) ::= seltablist(X) joinop(Y). {
353 A = X;
354 if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
355}
drh348784e2000-05-29 20:41:49 +0000356stl_prefix(A) ::= . {A = 0;}
drh01f3f252002-05-24 16:14:15 +0000357seltablist(A) ::= stl_prefix(X) ids(Y) as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000358 A = sqliteSrcListAppend(X,&Y);
drh01f3f252002-05-24 16:14:15 +0000359 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
360 if( N ){
361 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
362 else { sqliteExprDelete(N); }
363 }
364 if( U ){
365 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
366 else { sqliteIdListDelete(U); }
367 }
drhc4a3c772001-04-04 11:48:57 +0000368}
drh01f3f252002-05-24 16:14:15 +0000369seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000370 A = sqliteSrcListAppend(X,0);
371 A->a[A->nSrc-1].pSelect = S;
drhd5feede2002-05-08 21:46:14 +0000372 if( S->pOrderBy ){
373 sqliteExprListDelete(S->pOrderBy);
374 S->pOrderBy = 0;
375 }
drh01f3f252002-05-24 16:14:15 +0000376 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
377 if( N ){
378 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
379 else { sqliteExprDelete(N); }
drhd5feede2002-05-08 21:46:14 +0000380 }
drh01f3f252002-05-24 16:14:15 +0000381 if( U ){
382 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
383 else { sqliteIdListDelete(U); }
384 }
drh22f70c32002-02-18 01:17:00 +0000385}
drh348784e2000-05-29 20:41:49 +0000386
drh01f3f252002-05-24 16:14:15 +0000387%type joinop {int}
388%type joinop2 {int}
389joinop(X) ::= COMMA. { X = JT_INNER; }
390joinop(X) ::= JOIN. { X = JT_INNER; }
391joinop(X) ::= ID(A) JOIN. { X = sqliteJoinType(pParse,&A,0,0); }
392joinop(X) ::= ID(A) ID(B) JOIN. { X = sqliteJoinType(pParse,&A,&B,0); }
393joinop(X) ::= ID(A) ID(B) ID(C) JOIN. { X = sqliteJoinType(pParse,&A,&B,&C); }
394
395%type on_opt {Expr*}
396%destructor on_opt {sqliteExprDelete($$);}
397on_opt(N) ::= ON expr(E). {N = E;}
398on_opt(N) ::= . {N = 0;}
399
400%type using_opt {IdList*}
401%destructor using_opt {sqliteIdListDelete($$);}
402using_opt(U) ::= USING LP idxlist(L) RP. {U = L;}
403using_opt(U) ::= . {U = 0;}
404
405
drh348784e2000-05-29 20:41:49 +0000406%type orderby_opt {ExprList*}
407%destructor orderby_opt {sqliteExprListDelete($$);}
408%type sortlist {ExprList*}
409%destructor sortlist {sqliteExprListDelete($$);}
410%type sortitem {Expr*}
411%destructor sortitem {sqliteExprDelete($$);}
412
413orderby_opt(A) ::= . {A = 0;}
414orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000415sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
416 A = sqliteExprListAppend(X,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000417 if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */
drh9bb61fe2000-06-05 16:01:39 +0000418}
419sortlist(A) ::= sortitem(Y) sortorder(Z). {
420 A = sqliteExprListAppend(0,Y,0);
drhdaffd0e2001-04-11 14:28:42 +0000421 if( A ) A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000422}
drhda9d6c42000-05-31 18:20:14 +0000423sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000424
425%type sortorder {int}
426
427sortorder(A) ::= ASC. {A = 0;}
428sortorder(A) ::= DESC. {A = 1;}
429sortorder(A) ::= . {A = 0;}
430
drh22827922000-06-06 17:27:05 +0000431%type groupby_opt {ExprList*}
432%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000433groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000434groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
435
436%type having_opt {Expr*}
437%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000438having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000439having_opt(A) ::= HAVING expr(X). {A = X;}
440
drhad3cab52002-05-24 02:04:32 +0000441%type limit_opt {struct LimitVal}
442limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
443limit_opt(A) ::= LIMIT INTEGER(X). {A.limit = atoi(X.z); A.offset = 0;}
drh9bbca4c2001-11-06 04:00:18 +0000444limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y).
drhad3cab52002-05-24 02:04:32 +0000445 {A.limit = atoi(X.z); A.offset = atoi(Y.z);}
drh9bbca4c2001-11-06 04:00:18 +0000446limit_sep ::= OFFSET.
447limit_sep ::= COMMA.
448
drh382c0242001-10-06 16:33:02 +0000449/////////////////////////// The DELETE statement /////////////////////////////
450//
drhc4a3c772001-04-04 11:48:57 +0000451cmd ::= DELETE FROM ids(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000452 {sqliteDeleteFrom(pParse, &X, Y);}
453
454%type where_opt {Expr*}
455%destructor where_opt {sqliteExprDelete($$);}
456
457where_opt(A) ::= . {A = 0;}
458where_opt(A) ::= WHERE expr(X). {A = X;}
459
460%type setlist {ExprList*}
461%destructor setlist {sqliteExprListDelete($$);}
462
drh382c0242001-10-06 16:33:02 +0000463////////////////////////// The UPDATE command ////////////////////////////////
464//
drh1c928532002-01-31 15:54:21 +0000465cmd ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
drh9cfcf5d2002-01-29 18:41:24 +0000466 {sqliteUpdate(pParse,&X,Y,Z,R);}
drh348784e2000-05-29 20:41:49 +0000467
drhc4a3c772001-04-04 11:48:57 +0000468setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000469 {A = sqliteExprListAppend(Z,Y,&X);}
drhc4a3c772001-04-04 11:48:57 +0000470setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000471
drh382c0242001-10-06 16:33:02 +0000472////////////////////////// The INSERT command /////////////////////////////////
473//
drhfa86c412002-02-02 15:01:15 +0000474cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh9cfcf5d2002-01-29 18:41:24 +0000475 {sqliteInsert(pParse, &X, Y, 0, F, R);}
drhfa86c412002-02-02 15:01:15 +0000476cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) select(S).
drh9cfcf5d2002-01-29 18:41:24 +0000477 {sqliteInsert(pParse, &X, 0, S, F, R);}
drh348784e2000-05-29 20:41:49 +0000478
drhfa86c412002-02-02 15:01:15 +0000479%type insert_cmd {int}
480insert_cmd(A) ::= INSERT orconf(R). {A = R;}
481insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
482
drh348784e2000-05-29 20:41:49 +0000483
484%type itemlist {ExprList*}
485%destructor itemlist {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000486
drhe64e7b22002-02-18 13:56:36 +0000487itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
488itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
drh348784e2000-05-29 20:41:49 +0000489
drh967e8b72000-06-21 13:59:10 +0000490%type inscollist_opt {IdList*}
491%destructor inscollist_opt {sqliteIdListDelete($$);}
492%type inscollist {IdList*}
493%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000494
drhc4a3c772001-04-04 11:48:57 +0000495inscollist_opt(A) ::= . {A = 0;}
496inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
497inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);}
498inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000499
drh382c0242001-10-06 16:33:02 +0000500/////////////////////////// Expression Processing /////////////////////////////
501//
drh348784e2000-05-29 20:41:49 +0000502%left OR.
503%left AND.
drh8be51132000-06-03 19:19:41 +0000504%right NOT.
drhfef52082000-06-06 01:50:43 +0000505%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000506%left GT GE LT LE.
drh81a20f22001-10-12 17:30:04 +0000507%left BITAND BITOR LSHIFT RSHIFT.
drh348784e2000-05-29 20:41:49 +0000508%left PLUS MINUS.
drhbf4133c2001-10-13 02:59:08 +0000509%left STAR SLASH REM.
drh00400772000-06-16 20:51:26 +0000510%left CONCAT.
drh81a20f22001-10-12 17:30:04 +0000511%right UMINUS BITNOT.
drh348784e2000-05-29 20:41:49 +0000512
513%type expr {Expr*}
514%destructor expr {sqliteExprDelete($$);}
515
drhe1b6a5b2000-07-29 13:06:59 +0000516expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000517expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drhc4a3c772001-04-04 11:48:57 +0000518expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
519expr(A) ::= ids(X) DOT ids(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000520 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
521 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
522 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
523}
drh348784e2000-05-29 20:41:49 +0000524expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
525expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
526expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000527expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
528 A = sqliteExprFunction(Y, &X);
529 sqliteExprSpan(A,&X,&E);
530}
531expr(A) ::= ID(X) LP STAR RP(E). {
532 A = sqliteExprFunction(0, &X);
533 sqliteExprSpan(A,&X,&E);
534}
drh348784e2000-05-29 20:41:49 +0000535expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
536expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
537expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
538expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
539expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
540expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
541expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
542expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drh81a20f22001-10-12 17:30:04 +0000543expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
544expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
545expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
546expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
drh0ac65892002-04-20 14:24:41 +0000547expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
548 ExprList *pList = sqliteExprListAppend(0, Y, 0);
549 pList = sqliteExprListAppend(pList, X, 0);
550 A = sqliteExprFunction(pList, &OP);
551 sqliteExprSpan(A, &X->span, &Y->span);
552}
553expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
554 ExprList *pList = sqliteExprListAppend(0, Y, 0);
555 pList = sqliteExprListAppend(pList, X, 0);
556 A = sqliteExprFunction(pList, &OP);
drh4794b982000-06-06 13:54:14 +0000557 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000558 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000559}
drh0ac65892002-04-20 14:24:41 +0000560likeop(A) ::= LIKE(X). {A = X;}
561likeop(A) ::= GLOB(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000562expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
563expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
564expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
565expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drhbf4133c2001-10-13 02:59:08 +0000566expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000567expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000568expr(A) ::= expr(X) ISNULL(E). {
569 A = sqliteExpr(TK_ISNULL, X, 0, 0);
570 sqliteExprSpan(A,&X->span,&E);
571}
drh33048c02001-10-01 14:29:22 +0000572expr(A) ::= expr(X) IS NULL(E). {
573 A = sqliteExpr(TK_ISNULL, X, 0, 0);
574 sqliteExprSpan(A,&X->span,&E);
575}
drhe1b6a5b2000-07-29 13:06:59 +0000576expr(A) ::= expr(X) NOTNULL(E). {
577 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
578 sqliteExprSpan(A,&X->span,&E);
579}
drh33048c02001-10-01 14:29:22 +0000580expr(A) ::= expr(X) NOT NULL(E). {
581 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
582 sqliteExprSpan(A,&X->span,&E);
583}
drh81a20f22001-10-12 17:30:04 +0000584expr(A) ::= expr(X) IS NOT NULL(E). {
585 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
586 sqliteExprSpan(A,&X->span,&E);
587}
drhe1b6a5b2000-07-29 13:06:59 +0000588expr(A) ::= NOT(B) expr(X). {
589 A = sqliteExpr(TK_NOT, X, 0, 0);
590 sqliteExprSpan(A,&B,&X->span);
591}
drh81a20f22001-10-12 17:30:04 +0000592expr(A) ::= BITNOT(B) expr(X). {
593 A = sqliteExpr(TK_BITNOT, X, 0, 0);
594 sqliteExprSpan(A,&B,&X->span);
595}
drhe1b6a5b2000-07-29 13:06:59 +0000596expr(A) ::= MINUS(B) expr(X). [UMINUS] {
597 A = sqliteExpr(TK_UMINUS, X, 0, 0);
598 sqliteExprSpan(A,&B,&X->span);
599}
600expr(A) ::= PLUS(B) expr(X). [UMINUS] {
601 A = X;
602 sqliteExprSpan(A,&B,&X->span);
603}
604expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000605 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000606 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000607 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000608}
drhfef52082000-06-06 01:50:43 +0000609expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
610 ExprList *pList = sqliteExprListAppend(0, X, 0);
611 pList = sqliteExprListAppend(pList, Y, 0);
612 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000613 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000614 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000615}
drh4794b982000-06-06 13:54:14 +0000616expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
617 ExprList *pList = sqliteExprListAppend(0, X, 0);
618 pList = sqliteExprListAppend(pList, Y, 0);
619 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000620 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000621 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000622 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000623}
drhe1b6a5b2000-07-29 13:06:59 +0000624expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000625 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000626 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000627 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000628}
drhe1b6a5b2000-07-29 13:06:59 +0000629expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000630 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000631 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000632 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000633}
drhe1b6a5b2000-07-29 13:06:59 +0000634expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000635 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000636 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000637 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000638 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000639}
drhe1b6a5b2000-07-29 13:06:59 +0000640expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000641 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000642 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000643 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000644 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000645}
drhfef52082000-06-06 01:50:43 +0000646
drh17a7f8d2002-03-24 13:13:27 +0000647/* CASE expressions */
648expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
649 A = sqliteExpr(TK_CASE, X, Z, 0);
650 if( A ) A->pList = Y;
651 sqliteExprSpan(A, &C, &E);
652}
653%type case_exprlist {ExprList*}
654%destructor case_exprlist {sqliteExprListDelete($$);}
655case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
656 A = sqliteExprListAppend(X, Y, 0);
657 A = sqliteExprListAppend(A, Z, 0);
658}
659case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
660 A = sqliteExprListAppend(0, Y, 0);
661 A = sqliteExprListAppend(A, Z, 0);
662}
663%type case_else {Expr*}
664case_else(A) ::= ELSE expr(X). {A = X;}
665case_else(A) ::= . {A = 0;}
666%type case_operand {Expr*}
667case_operand(A) ::= expr(X). {A = X;}
668case_operand(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000669
670%type exprlist {ExprList*}
671%destructor exprlist {sqliteExprListDelete($$);}
672%type expritem {Expr*}
673%destructor expritem {sqliteExprDelete($$);}
674
drh348784e2000-05-29 20:41:49 +0000675exprlist(A) ::= exprlist(X) COMMA expritem(Y).
676 {A = sqliteExprListAppend(X,Y,0);}
677exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
678expritem(A) ::= expr(X). {A = X;}
679expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000680
drh382c0242001-10-06 16:33:02 +0000681///////////////////////////// The CREATE INDEX command ///////////////////////
682//
drh9cfcf5d2002-01-29 18:41:24 +0000683cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X)
684 ON ids(Y) LP idxlist(Z) RP(E) onconf(R). {
685 if( U!=OE_None ) U = R;
686 if( U==OE_Default) U = OE_Abort;
687 sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);
688}
drh717e6402001-09-27 03:22:32 +0000689
690%type uniqueflag {int}
drh9cfcf5d2002-01-29 18:41:24 +0000691uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
692uniqueflag(A) ::= . { A = OE_None; }
drh348784e2000-05-29 20:41:49 +0000693
694%type idxlist {IdList*}
695%destructor idxlist {sqliteIdListDelete($$);}
696%type idxitem {Token}
697
698idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
699 {A = sqliteIdListAppend(X,&Y);}
700idxlist(A) ::= idxitem(Y).
701 {A = sqliteIdListAppend(0,&Y);}
drhc4a3c772001-04-04 11:48:57 +0000702idxitem(A) ::= ids(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000703
drh8aff1012001-12-22 14:49:24 +0000704///////////////////////////// The DROP INDEX command /////////////////////////
drh382c0242001-10-06 16:33:02 +0000705//
706
drhc4a3c772001-04-04 11:48:57 +0000707cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000708
drh382c0242001-10-06 16:33:02 +0000709
drh8aff1012001-12-22 14:49:24 +0000710///////////////////////////// The COPY command ///////////////////////////////
drh382c0242001-10-06 16:33:02 +0000711//
drh1c928532002-01-31 15:54:21 +0000712cmd ::= COPY orconf(R) ids(X) FROM ids(Y) USING DELIMITERS STRING(Z).
drhb419a922002-01-30 16:17:23 +0000713 {sqliteCopy(pParse,&X,&Y,&Z,R);}
drh1c928532002-01-31 15:54:21 +0000714cmd ::= COPY orconf(R) ids(X) FROM ids(Y).
drhb419a922002-01-30 16:17:23 +0000715 {sqliteCopy(pParse,&X,&Y,0,R);}
drhdce2cbe2000-05-31 02:27:49 +0000716
drh382c0242001-10-06 16:33:02 +0000717///////////////////////////// The VACUUM command /////////////////////////////
718//
drhdce2cbe2000-05-31 02:27:49 +0000719cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drhc4a3c772001-04-04 11:48:57 +0000720cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000721
drh382c0242001-10-06 16:33:02 +0000722///////////////////////////// The PRAGMA command /////////////////////////////
723//
drhf57b14a2001-09-14 18:54:08 +0000724cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);}
725cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
726cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
727cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
drh382c0242001-10-06 16:33:02 +0000728cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
drh603240c2002-03-05 01:11:12 +0000729cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
drhf57b14a2001-09-14 18:54:08 +0000730plus_num(A) ::= plus_opt number(X). {A = X;}
731minus_num(A) ::= MINUS number(X). {A = X;}
732number(A) ::= INTEGER(X). {A = X;}
733number(A) ::= FLOAT(X). {A = X;}
734plus_opt ::= PLUS.
735plus_opt ::= .
danielk1977c3f9bad2002-05-15 08:30:12 +0000736
737//////////////////////////// The CREATE TRIGGER command /////////////////////
738cmd ::= CREATE(A) TRIGGER ids(B) trigger_time(C) trigger_event(D) ON ids(E)
739 foreach_clause(F) when_clause(G)
740 BEGIN trigger_cmd_list(S) END(Z). {
741 sqliteCreateTrigger(pParse, &B, C, D.a, D.b, &E, F, G, S,
742 A.z, (int)(Z.z - A.z) + Z.n );
743}
744
745%type trigger_time {int}
746trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
747trigger_time(A) ::= AFTER. { A = TK_AFTER; }
748trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
749trigger_time(A) ::= . { A = TK_BEFORE; }
750
drhad3cab52002-05-24 02:04:32 +0000751%type trigger_event {struct TrigEvent}
752%destructor trigger_event {sqliteIdListDelete($$.b);}
danielk1977c3f9bad2002-05-15 08:30:12 +0000753trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
754trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
755trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
756trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
757
758%type foreach_clause {int}
759foreach_clause(A) ::= . { A = TK_ROW; }
760foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
761foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
762
763%type when_clause {Expr *}
764when_clause(A) ::= . { A = 0; }
765when_clause(A) ::= WHEN expr(X). { A = X; }
766
767%type trigger_cmd_list {TriggerStep *}
768trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
769 X->pNext = Y ; A = X; }
770trigger_cmd_list(A) ::= . { A = 0; }
771
772%type trigger_cmd {TriggerStep *}
773// UPDATE
774trigger_cmd(A) ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z).
775 { A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
776
777// INSERT
778trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F)
779 VALUES LP itemlist(Y) RP.
780{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
781
782trigger_cmd(A) ::= INSERT orconf(R) INTO ids(X) inscollist_opt(F) select(S).
783 {A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
784
785// DELETE
786trigger_cmd(A) ::= DELETE FROM ids(X) where_opt(Y).
787 {A = sqliteTriggerDeleteStep(&X, Y);}
788
789// SELECT
790trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
791
792//////////////////////// DROP TRIGGER statement //////////////////////////////
793cmd ::= DROP TRIGGER ids(X). {
794 sqliteDropTrigger(pParse,&X,0);
795}