blob: d98cb8440b803e94c916c7bfad19cdd271cdac72 [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**
drh6276c1c2002-07-08 22:03:32 +000017** @(#) $Id: parse.y,v 1.78 2002/07/08 22:03:32 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);}
drh094b2bb2002-03-13 18:54:07 +000068ecmd ::= SEMI.
drhe0bc4042002-06-25 01:09:11 +000069explain ::= EXPLAIN. { sqliteBeginParse(pParse, 1); }
70explain ::= . { sqliteBeginParse(pParse, 0); }
drh348784e2000-05-29 20:41:49 +000071
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.
drh5ad1a6c2002-07-01 12:27:09 +000078trans_opt ::= TRANSACTION nm.
drhc4a3c772001-04-04 11:48:57 +000079cmd ::= 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.
drh5ad1a6c2002-07-01 12:27:09 +000086create_table ::= CREATE(X) temp(T) TABLE nm(Y). {
drh969fa7c2002-02-18 18:30:32 +000087 sqliteStartTable(pParse,&X,&Y,T);
88}
drhf57b3392001-10-08 13:22:32 +000089%type temp {int}
drhe0bc4042002-06-25 01:09:11 +000090temp(A) ::= TEMP. {A = pParse->isTemp || !pParse->initFlag;}
91temp(A) ::= . {A = pParse->isTemp;}
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.
drh5ad1a6c2002-07-01 12:27:09 +0000107columnid ::= nm(X). {sqliteAddColumn(pParse,&X);}
drhc4a3c772001-04-04 11:48:57 +0000108
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
drh8e2ca022002-06-17 17:07:19 +0000120 ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER COLLATE CONFLICT
drh0bd1f4e2002-06-06 18:54:39 +0000121 COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR
drh5ad1a6c2002-07-01 12:27:09 +0000122 IGNORE IMMEDIATE INITIALLY INSTEAD MATCH KEY
123 OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
drh0bd1f4e2002-06-06 18:54:39 +0000124 TEMP TRIGGER VACUUM VIEW.
drhc4a3c772001-04-04 11:48:57 +0000125
126// And "ids" is an identifer-or-string.
127//
128%type ids {Token}
drh5ad1a6c2002-07-01 12:27:09 +0000129ids(A) ::= ID(X). {A = X;}
drhc4a3c772001-04-04 11:48:57 +0000130ids(A) ::= STRING(X). {A = X;}
131
drh5ad1a6c2002-07-01 12:27:09 +0000132// The name of a column or table can be any of the following:
133//
134%type nm {Token}
135nm(A) ::= ID(X). {A = X;}
136nm(A) ::= STRING(X). {A = X;}
137nm(A) ::= JOIN_KW(X). {A = X;}
138
drh382c0242001-10-06 16:33:02 +0000139type ::= .
140type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);}
141type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);}
142type ::= typename(X) LP signed COMMA signed RP(Y).
143 {sqliteAddColumnType(pParse,&X,&Y);}
144%type typename {Token}
145typename(A) ::= ids(X). {A = X;}
146typename(A) ::= typename(X) ids. {A = X;}
drh348784e2000-05-29 20:41:49 +0000147signed ::= INTEGER.
148signed ::= PLUS INTEGER.
149signed ::= MINUS INTEGER.
150carglist ::= carglist carg.
151carglist ::= .
drh5ad1a6c2002-07-01 12:27:09 +0000152carg ::= CONSTRAINT nm ccons.
drh348784e2000-05-29 20:41:49 +0000153carg ::= ccons.
drh7020f652000-06-03 18:06:52 +0000154carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
155carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
156carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
157carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
158carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
159carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
160carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
161carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
162carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000163
drh382c0242001-10-06 16:33:02 +0000164// In addition to the type name, we also care about the primary key and
165// UNIQUE constraints.
drh348784e2000-05-29 20:41:49 +0000166//
drh9cfcf5d2002-01-29 18:41:24 +0000167ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
168ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
169ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
170ccons ::= CHECK LP expr RP onconf.
drh04738cb2002-06-02 18:19:00 +0000171ccons ::= references.
172ccons ::= defer_subclause.
drh8e2ca022002-06-17 17:07:19 +0000173ccons ::= COLLATE id(C). {
174 sqliteAddCollateType(pParse, sqliteCollateType(pParse, &C));
175}
drh04738cb2002-06-02 18:19:00 +0000176
177// A REFERENCES clause is parsed but the current implementation does not
178// do anything with it.
179//
drh5ad1a6c2002-07-01 12:27:09 +0000180references ::= REFERENCES nm LP idxlist RP refargs.
181references ::= REFERENCES nm refargs.
drh04738cb2002-06-02 18:19:00 +0000182refargs ::= .
183refargs ::= refargs refarg.
drh5ad1a6c2002-07-01 12:27:09 +0000184refarg ::= MATCH nm.
drh04738cb2002-06-02 18:19:00 +0000185refarg ::= ON DELETE refact.
186refarg ::= ON UPDATE refact.
187refact ::= SET NULL.
188refact ::= SET DEFAULT.
189refact ::= CASCADE.
190refact ::= RESTRICT.
191defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt.
192defer_subclause ::= DEFERRABLE init_deferred_pred_opt.
193init_deferred_pred_opt ::= .
194init_deferred_pred_opt ::= INITIALLY DEFERRED.
195init_deferred_pred_opt ::= INITIALLY IMMEDIATE.
drh348784e2000-05-29 20:41:49 +0000196
197// For the time being, the only constraint we care about is the primary
drh382c0242001-10-06 16:33:02 +0000198// key and UNIQUE. Both create indices.
drh348784e2000-05-29 20:41:49 +0000199//
200conslist_opt ::= .
201conslist_opt ::= COMMA conslist.
202conslist ::= conslist COMMA tcons.
drha2e1bb52001-01-04 14:20:18 +0000203conslist ::= conslist tcons.
drh348784e2000-05-29 20:41:49 +0000204conslist ::= tcons.
drh5ad1a6c2002-07-01 12:27:09 +0000205tcons ::= CONSTRAINT nm.
drh9cfcf5d2002-01-29 18:41:24 +0000206tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
207 {sqliteAddPrimaryKey(pParse,X,R);}
208tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
209 {sqliteCreateIndex(pParse,0,0,X,R,0,0);}
210tcons ::= CHECK expr onconf.
drh04738cb2002-06-02 18:19:00 +0000211tcons ::= FOREIGN KEY LP idxlist RP references defer_subclause_opt.
212defer_subclause_opt ::= .
213defer_subclause_opt ::= defer_subclause.
drh9cfcf5d2002-01-29 18:41:24 +0000214
215// The following is a non-standard extension that allows us to declare the
216// default behavior when there is a constraint conflict.
217//
218%type onconf {int}
drh1c928532002-01-31 15:54:21 +0000219%type orconf {int}
220%type resolvetype {int}
221onconf(A) ::= . { A = OE_Default; }
222onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; }
223orconf(A) ::= . { A = OE_Default; }
224orconf(A) ::= OR resolvetype(X). { A = X; }
225resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; }
226resolvetype(A) ::= ABORT. { A = OE_Abort; }
227resolvetype(A) ::= FAIL. { A = OE_Fail; }
228resolvetype(A) ::= IGNORE. { A = OE_Ignore; }
229resolvetype(A) ::= REPLACE. { A = OE_Replace; }
drh348784e2000-05-29 20:41:49 +0000230
drh382c0242001-10-06 16:33:02 +0000231////////////////////////// The DROP TABLE /////////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000232//
drh5ad1a6c2002-07-01 12:27:09 +0000233cmd ::= DROP TABLE nm(X). {sqliteDropTable(pParse,&X,0);}
drh348784e2000-05-29 20:41:49 +0000234
drha76b5df2002-02-23 02:32:10 +0000235///////////////////// The CREATE VIEW statement /////////////////////////////
236//
drh6276c1c2002-07-08 22:03:32 +0000237cmd ::= CREATE(X) temp(T) VIEW nm(Y) AS select(S). {
238 sqliteCreateView(pParse, &X, &Y, S, T);
drha76b5df2002-02-23 02:32:10 +0000239}
drh5ad1a6c2002-07-01 12:27:09 +0000240cmd ::= DROP VIEW nm(X). {
drh4ff6dfa2002-03-03 23:06:00 +0000241 sqliteDropTable(pParse, &X, 1);
drha76b5df2002-02-23 02:32:10 +0000242}
243
drh382c0242001-10-06 16:33:02 +0000244//////////////////////// The SELECT statement /////////////////////////////////
drh348784e2000-05-29 20:41:49 +0000245//
drh9bb61fe2000-06-05 16:01:39 +0000246cmd ::= select(X). {
drh832508b2002-03-02 17:04:07 +0000247 sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0);
drh9bb61fe2000-06-05 16:01:39 +0000248 sqliteSelectDelete(X);
249}
drhefb72512000-05-31 20:00:52 +0000250
drh9bb61fe2000-06-05 16:01:39 +0000251%type select {Select*}
252%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000253%type oneselect {Select*}
254%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000255
drh82c3d632000-06-06 21:56:07 +0000256select(A) ::= oneselect(X). {A = X;}
drh0a36c572002-02-18 22:49:59 +0000257select(A) ::= select(X) multiselect_op(Y) oneselect(Z). {
drhdaffd0e2001-04-11 14:28:42 +0000258 if( Z ){
drh82c3d632000-06-06 21:56:07 +0000259 Z->op = Y;
260 Z->pPrior = X;
drhdaffd0e2001-04-11 14:28:42 +0000261 }
262 A = Z;
drh82c3d632000-06-06 21:56:07 +0000263}
drh0a36c572002-02-18 22:49:59 +0000264%type multiselect_op {int}
265multiselect_op(A) ::= UNION. {A = TK_UNION;}
266multiselect_op(A) ::= UNION ALL. {A = TK_ALL;}
267multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;}
268multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;}
drh82c3d632000-06-06 21:56:07 +0000269oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
drh9bbca4c2001-11-06 04:00:18 +0000270 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). {
drhad3cab52002-05-24 02:04:32 +0000271 A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.limit,L.offset);
drh9bb61fe2000-06-05 16:01:39 +0000272}
273
274// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
275// present and false (0) if it is not.
276//
drhefb72512000-05-31 20:00:52 +0000277%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000278distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000279distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000280distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000281
drh9bb61fe2000-06-05 16:01:39 +0000282// selcollist is a list of expressions that are to become the return
drh7c917d12001-12-16 20:05:05 +0000283// values of the SELECT statement. The "*" in statements like
284// "SELECT * FROM ..." is encoded as a special expression with an
285// opcode of TK_ALL.
drh9bb61fe2000-06-05 16:01:39 +0000286//
drh348784e2000-05-29 20:41:49 +0000287%type selcollist {ExprList*}
288%destructor selcollist {sqliteExprListDelete($$);}
289%type sclp {ExprList*}
290%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000291sclp(A) ::= selcollist(X) COMMA. {A = X;}
292sclp(A) ::= . {A = 0;}
drh01f3f252002-05-24 16:14:15 +0000293selcollist(A) ::= sclp(P) expr(X) as(Y). {
294 A = sqliteExprListAppend(P,X,Y.n?&Y:0);
295}
drh7c917d12001-12-16 20:05:05 +0000296selcollist(A) ::= sclp(P) STAR. {
297 A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0);
298}
drh5ad1a6c2002-07-01 12:27:09 +0000299selcollist(A) ::= sclp(P) nm(X) DOT STAR. {
drh54473222002-04-04 02:10:55 +0000300 Expr *pRight = sqliteExpr(TK_ALL, 0, 0, 0);
301 Expr *pLeft = sqliteExpr(TK_ID, 0, 0, &X);
302 A = sqliteExprListAppend(P, sqliteExpr(TK_DOT, pLeft, pRight, 0), 0);
303}
drh01f3f252002-05-24 16:14:15 +0000304
305// An option "AS <id>" phrase that can follow one of the expressions that
306// define the result set, or one of the tables in the FROM clause.
307//
308%type as {Token}
drh5ad1a6c2002-07-01 12:27:09 +0000309as(X) ::= AS nm(Y). { X = Y; }
310as(X) ::= ids(Y). { X = Y; }
311as(X) ::= . { X.n = 0; }
drh9bb61fe2000-06-05 16:01:39 +0000312
drh348784e2000-05-29 20:41:49 +0000313
drhad3cab52002-05-24 02:04:32 +0000314%type seltablist {SrcList*}
315%destructor seltablist {sqliteSrcListDelete($$);}
316%type stl_prefix {SrcList*}
317%destructor stl_prefix {sqliteSrcListDelete($$);}
318%type from {SrcList*}
319%destructor from {sqliteSrcListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000320
drh01f3f252002-05-24 16:14:15 +0000321// A complete FROM clause.
322//
drhbf3a4fa2002-04-06 13:57:42 +0000323from(A) ::= . {A = sqliteMalloc(sizeof(*A));}
drh348784e2000-05-29 20:41:49 +0000324from(A) ::= FROM seltablist(X). {A = X;}
drh01f3f252002-05-24 16:14:15 +0000325
326// "seltablist" is a "Select Table List" - the content of the FROM clause
327// in a SELECT statement. "stl_prefix" is a prefix of this list.
328//
329stl_prefix(A) ::= seltablist(X) joinop(Y). {
330 A = X;
331 if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y;
332}
drh348784e2000-05-29 20:41:49 +0000333stl_prefix(A) ::= . {A = 0;}
drh5ad1a6c2002-07-01 12:27:09 +0000334seltablist(A) ::= stl_prefix(X) nm(Y) as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000335 A = sqliteSrcListAppend(X,&Y);
drh01f3f252002-05-24 16:14:15 +0000336 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
337 if( N ){
338 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
339 else { sqliteExprDelete(N); }
340 }
341 if( U ){
342 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
343 else { sqliteIdListDelete(U); }
344 }
drhc4a3c772001-04-04 11:48:57 +0000345}
drh01f3f252002-05-24 16:14:15 +0000346seltablist(A) ::= stl_prefix(X) LP select(S) RP as(Z) on_opt(N) using_opt(U). {
drhad3cab52002-05-24 02:04:32 +0000347 A = sqliteSrcListAppend(X,0);
348 A->a[A->nSrc-1].pSelect = S;
drhd5feede2002-05-08 21:46:14 +0000349 if( S->pOrderBy ){
350 sqliteExprListDelete(S->pOrderBy);
351 S->pOrderBy = 0;
352 }
drh01f3f252002-05-24 16:14:15 +0000353 if( Z.n ) sqliteSrcListAddAlias(A,&Z);
354 if( N ){
355 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; }
356 else { sqliteExprDelete(N); }
drhd5feede2002-05-08 21:46:14 +0000357 }
drh01f3f252002-05-24 16:14:15 +0000358 if( U ){
359 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; }
360 else { sqliteIdListDelete(U); }
361 }
drh22f70c32002-02-18 01:17:00 +0000362}
drh348784e2000-05-29 20:41:49 +0000363
drh01f3f252002-05-24 16:14:15 +0000364%type joinop {int}
365%type joinop2 {int}
366joinop(X) ::= COMMA. { X = JT_INNER; }
367joinop(X) ::= JOIN. { X = JT_INNER; }
drh5ad1a6c2002-07-01 12:27:09 +0000368joinop(X) ::= JOIN_KW(A) JOIN. { X = sqliteJoinType(pParse,&A,0,0); }
369joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqliteJoinType(pParse,&A,&B,0); }
370joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN.
371 { X = sqliteJoinType(pParse,&A,&B,&C); }
drh01f3f252002-05-24 16:14:15 +0000372
373%type on_opt {Expr*}
374%destructor on_opt {sqliteExprDelete($$);}
375on_opt(N) ::= ON expr(E). {N = E;}
376on_opt(N) ::= . {N = 0;}
377
378%type using_opt {IdList*}
379%destructor using_opt {sqliteIdListDelete($$);}
380using_opt(U) ::= USING LP idxlist(L) RP. {U = L;}
381using_opt(U) ::= . {U = 0;}
382
383
drh348784e2000-05-29 20:41:49 +0000384%type orderby_opt {ExprList*}
385%destructor orderby_opt {sqliteExprListDelete($$);}
386%type sortlist {ExprList*}
387%destructor sortlist {sqliteExprListDelete($$);}
388%type sortitem {Expr*}
389%destructor sortitem {sqliteExprDelete($$);}
390
391orderby_opt(A) ::= . {A = 0;}
392orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh8e2ca022002-06-17 17:07:19 +0000393sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). {
drh9bb61fe2000-06-05 16:01:39 +0000394 A = sqliteExprListAppend(X,Y,0);
drh8e2ca022002-06-17 17:07:19 +0000395 if( A ) A->a[A->nExpr-1].sortOrder = C+Z;
drh9bb61fe2000-06-05 16:01:39 +0000396}
drh38640e12002-07-05 21:42:36 +0000397sortlist(A) ::= sortitem(Y) collate(C) sortorder(Z). {
drh9bb61fe2000-06-05 16:01:39 +0000398 A = sqliteExprListAppend(0,Y,0);
drh38640e12002-07-05 21:42:36 +0000399 if( A ) A->a[0].sortOrder = C+Z;
drh9bb61fe2000-06-05 16:01:39 +0000400}
drhda9d6c42000-05-31 18:20:14 +0000401sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000402
403%type sortorder {int}
drh8e2ca022002-06-17 17:07:19 +0000404%type collate {int}
drh348784e2000-05-29 20:41:49 +0000405
drh8e2ca022002-06-17 17:07:19 +0000406sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;}
407sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;}
408sortorder(A) ::= . {A = SQLITE_SO_ASC;}
409collate(C) ::= . {C = SQLITE_SO_UNK;}
410collate(C) ::= COLLATE id(X). {C = sqliteCollateType(pParse, &X);}
drh348784e2000-05-29 20:41:49 +0000411
drh22827922000-06-06 17:27:05 +0000412%type groupby_opt {ExprList*}
413%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000414groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000415groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
416
417%type having_opt {Expr*}
418%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000419having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000420having_opt(A) ::= HAVING expr(X). {A = X;}
421
drhad3cab52002-05-24 02:04:32 +0000422%type limit_opt {struct LimitVal}
423limit_opt(A) ::= . {A.limit = -1; A.offset = 0;}
424limit_opt(A) ::= LIMIT INTEGER(X). {A.limit = atoi(X.z); A.offset = 0;}
drh9bbca4c2001-11-06 04:00:18 +0000425limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y).
drhad3cab52002-05-24 02:04:32 +0000426 {A.limit = atoi(X.z); A.offset = atoi(Y.z);}
drh9bbca4c2001-11-06 04:00:18 +0000427limit_sep ::= OFFSET.
428limit_sep ::= COMMA.
429
drh382c0242001-10-06 16:33:02 +0000430/////////////////////////// The DELETE statement /////////////////////////////
431//
drh5ad1a6c2002-07-01 12:27:09 +0000432cmd ::= DELETE FROM nm(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000433 {sqliteDeleteFrom(pParse, &X, Y);}
434
435%type where_opt {Expr*}
436%destructor where_opt {sqliteExprDelete($$);}
437
438where_opt(A) ::= . {A = 0;}
439where_opt(A) ::= WHERE expr(X). {A = X;}
440
441%type setlist {ExprList*}
442%destructor setlist {sqliteExprListDelete($$);}
443
drh382c0242001-10-06 16:33:02 +0000444////////////////////////// The UPDATE command ////////////////////////////////
445//
drh5ad1a6c2002-07-01 12:27:09 +0000446cmd ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
drh9cfcf5d2002-01-29 18:41:24 +0000447 {sqliteUpdate(pParse,&X,Y,Z,R);}
drh348784e2000-05-29 20:41:49 +0000448
drh5ad1a6c2002-07-01 12:27:09 +0000449setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y).
drh348784e2000-05-29 20:41:49 +0000450 {A = sqliteExprListAppend(Z,Y,&X);}
drh5ad1a6c2002-07-01 12:27:09 +0000451setlist(A) ::= nm(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000452
drh382c0242001-10-06 16:33:02 +0000453////////////////////////// The INSERT command /////////////////////////////////
454//
drh5ad1a6c2002-07-01 12:27:09 +0000455cmd ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) VALUES LP itemlist(Y) RP.
drh9cfcf5d2002-01-29 18:41:24 +0000456 {sqliteInsert(pParse, &X, Y, 0, F, R);}
drh5ad1a6c2002-07-01 12:27:09 +0000457cmd ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S).
drh9cfcf5d2002-01-29 18:41:24 +0000458 {sqliteInsert(pParse, &X, 0, S, F, R);}
drh348784e2000-05-29 20:41:49 +0000459
drhfa86c412002-02-02 15:01:15 +0000460%type insert_cmd {int}
461insert_cmd(A) ::= INSERT orconf(R). {A = R;}
462insert_cmd(A) ::= REPLACE. {A = OE_Replace;}
463
drh348784e2000-05-29 20:41:49 +0000464
465%type itemlist {ExprList*}
466%destructor itemlist {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000467
drhe64e7b22002-02-18 13:56:36 +0000468itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);}
469itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);}
drh348784e2000-05-29 20:41:49 +0000470
drh967e8b72000-06-21 13:59:10 +0000471%type inscollist_opt {IdList*}
472%destructor inscollist_opt {sqliteIdListDelete($$);}
473%type inscollist {IdList*}
474%destructor inscollist {sqliteIdListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000475
drhc4a3c772001-04-04 11:48:57 +0000476inscollist_opt(A) ::= . {A = 0;}
477inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;}
drh5ad1a6c2002-07-01 12:27:09 +0000478inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqliteIdListAppend(X,&Y);}
479inscollist(A) ::= nm(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000480
drh382c0242001-10-06 16:33:02 +0000481/////////////////////////// Expression Processing /////////////////////////////
482//
drh348784e2000-05-29 20:41:49 +0000483%left OR.
484%left AND.
drh8be51132000-06-03 19:19:41 +0000485%right NOT.
drhfef52082000-06-06 01:50:43 +0000486%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000487%left GT GE LT LE.
drh81a20f22001-10-12 17:30:04 +0000488%left BITAND BITOR LSHIFT RSHIFT.
drh348784e2000-05-29 20:41:49 +0000489%left PLUS MINUS.
drhbf4133c2001-10-13 02:59:08 +0000490%left STAR SLASH REM.
drh00400772000-06-16 20:51:26 +0000491%left CONCAT.
drh81a20f22001-10-12 17:30:04 +0000492%right UMINUS BITNOT.
drh348784e2000-05-29 20:41:49 +0000493
494%type expr {Expr*}
495%destructor expr {sqliteExprDelete($$);}
496
drhe1b6a5b2000-07-29 13:06:59 +0000497expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);}
drhe1b6a5b2000-07-29 13:06:59 +0000498expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);}
drh5ad1a6c2002-07-01 12:27:09 +0000499expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
500expr(A) ::= JOIN_KW(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
501expr(A) ::= nm(X) DOT nm(Y). {
drhe1b6a5b2000-07-29 13:06:59 +0000502 Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
503 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
504 A = sqliteExpr(TK_DOT, temp1, temp2, 0);
505}
drh348784e2000-05-29 20:41:49 +0000506expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
507expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
508expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhe1b6a5b2000-07-29 13:06:59 +0000509expr(A) ::= ID(X) LP exprlist(Y) RP(E). {
510 A = sqliteExprFunction(Y, &X);
511 sqliteExprSpan(A,&X,&E);
512}
513expr(A) ::= ID(X) LP STAR RP(E). {
514 A = sqliteExprFunction(0, &X);
515 sqliteExprSpan(A,&X,&E);
516}
drh348784e2000-05-29 20:41:49 +0000517expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
518expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
519expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
520expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
521expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
522expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
523expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
524expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drh81a20f22001-10-12 17:30:04 +0000525expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);}
526expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);}
527expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);}
528expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);}
drh0ac65892002-04-20 14:24:41 +0000529expr(A) ::= expr(X) likeop(OP) expr(Y). [LIKE] {
530 ExprList *pList = sqliteExprListAppend(0, Y, 0);
531 pList = sqliteExprListAppend(pList, X, 0);
532 A = sqliteExprFunction(pList, &OP);
533 sqliteExprSpan(A, &X->span, &Y->span);
534}
535expr(A) ::= expr(X) NOT likeop(OP) expr(Y). [LIKE] {
536 ExprList *pList = sqliteExprListAppend(0, Y, 0);
537 pList = sqliteExprListAppend(pList, X, 0);
538 A = sqliteExprFunction(pList, &OP);
drh4794b982000-06-06 13:54:14 +0000539 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000540 sqliteExprSpan(A,&X->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000541}
drh0ac65892002-04-20 14:24:41 +0000542likeop(A) ::= LIKE(X). {A = X;}
543likeop(A) ::= GLOB(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000544expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
545expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
546expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
547expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drhbf4133c2001-10-13 02:59:08 +0000548expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000549expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drhe1b6a5b2000-07-29 13:06:59 +0000550expr(A) ::= expr(X) ISNULL(E). {
551 A = sqliteExpr(TK_ISNULL, X, 0, 0);
552 sqliteExprSpan(A,&X->span,&E);
553}
drh33048c02001-10-01 14:29:22 +0000554expr(A) ::= expr(X) IS NULL(E). {
555 A = sqliteExpr(TK_ISNULL, X, 0, 0);
556 sqliteExprSpan(A,&X->span,&E);
557}
drhe1b6a5b2000-07-29 13:06:59 +0000558expr(A) ::= expr(X) NOTNULL(E). {
559 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
560 sqliteExprSpan(A,&X->span,&E);
561}
drh33048c02001-10-01 14:29:22 +0000562expr(A) ::= expr(X) NOT NULL(E). {
563 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
564 sqliteExprSpan(A,&X->span,&E);
565}
drh81a20f22001-10-12 17:30:04 +0000566expr(A) ::= expr(X) IS NOT NULL(E). {
567 A = sqliteExpr(TK_NOTNULL, X, 0, 0);
568 sqliteExprSpan(A,&X->span,&E);
569}
drhe1b6a5b2000-07-29 13:06:59 +0000570expr(A) ::= NOT(B) expr(X). {
571 A = sqliteExpr(TK_NOT, X, 0, 0);
572 sqliteExprSpan(A,&B,&X->span);
573}
drh81a20f22001-10-12 17:30:04 +0000574expr(A) ::= BITNOT(B) expr(X). {
575 A = sqliteExpr(TK_BITNOT, X, 0, 0);
576 sqliteExprSpan(A,&B,&X->span);
577}
drhe1b6a5b2000-07-29 13:06:59 +0000578expr(A) ::= MINUS(B) expr(X). [UMINUS] {
579 A = sqliteExpr(TK_UMINUS, X, 0, 0);
580 sqliteExprSpan(A,&B,&X->span);
581}
582expr(A) ::= PLUS(B) expr(X). [UMINUS] {
583 A = X;
584 sqliteExprSpan(A,&B,&X->span);
585}
586expr(A) ::= LP(B) select(X) RP(E). {
drh19a775c2000-06-05 18:54:46 +0000587 A = sqliteExpr(TK_SELECT, 0, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000588 if( A ) A->pSelect = X;
drhe1b6a5b2000-07-29 13:06:59 +0000589 sqliteExprSpan(A,&B,&E);
drh19a775c2000-06-05 18:54:46 +0000590}
drhfef52082000-06-06 01:50:43 +0000591expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
592 ExprList *pList = sqliteExprListAppend(0, X, 0);
593 pList = sqliteExprListAppend(pList, Y, 0);
594 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000595 if( A ) A->pList = pList;
drhe1b6a5b2000-07-29 13:06:59 +0000596 sqliteExprSpan(A,&W->span,&Y->span);
drhfef52082000-06-06 01:50:43 +0000597}
drh4794b982000-06-06 13:54:14 +0000598expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
599 ExprList *pList = sqliteExprListAppend(0, X, 0);
600 pList = sqliteExprListAppend(pList, Y, 0);
601 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000602 if( A ) A->pList = pList;
drh4794b982000-06-06 13:54:14 +0000603 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000604 sqliteExprSpan(A,&W->span,&Y->span);
drh4794b982000-06-06 13:54:14 +0000605}
drhe1b6a5b2000-07-29 13:06:59 +0000606expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000607 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000608 if( A ) A->pList = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000609 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000610}
drhe1b6a5b2000-07-29 13:06:59 +0000611expr(A) ::= expr(X) IN LP select(Y) RP(E). {
drhfef52082000-06-06 01:50:43 +0000612 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000613 if( A ) A->pSelect = Y;
drhe1b6a5b2000-07-29 13:06:59 +0000614 sqliteExprSpan(A,&X->span,&E);
drhfef52082000-06-06 01:50:43 +0000615}
drhe1b6a5b2000-07-29 13:06:59 +0000616expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000617 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000618 if( A ) A->pList = Y;
drh4794b982000-06-06 13:54:14 +0000619 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000620 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000621}
drhe1b6a5b2000-07-29 13:06:59 +0000622expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). {
drh4794b982000-06-06 13:54:14 +0000623 A = sqliteExpr(TK_IN, X, 0, 0);
drhdaffd0e2001-04-11 14:28:42 +0000624 if( A ) A->pSelect = Y;
drh4794b982000-06-06 13:54:14 +0000625 A = sqliteExpr(TK_NOT, A, 0, 0);
drhe1b6a5b2000-07-29 13:06:59 +0000626 sqliteExprSpan(A,&X->span,&E);
drh4794b982000-06-06 13:54:14 +0000627}
drhfef52082000-06-06 01:50:43 +0000628
drh17a7f8d2002-03-24 13:13:27 +0000629/* CASE expressions */
630expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
631 A = sqliteExpr(TK_CASE, X, Z, 0);
632 if( A ) A->pList = Y;
633 sqliteExprSpan(A, &C, &E);
634}
635%type case_exprlist {ExprList*}
636%destructor case_exprlist {sqliteExprListDelete($$);}
637case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). {
638 A = sqliteExprListAppend(X, Y, 0);
639 A = sqliteExprListAppend(A, Z, 0);
640}
641case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). {
642 A = sqliteExprListAppend(0, Y, 0);
643 A = sqliteExprListAppend(A, Z, 0);
644}
645%type case_else {Expr*}
646case_else(A) ::= ELSE expr(X). {A = X;}
647case_else(A) ::= . {A = 0;}
648%type case_operand {Expr*}
649case_operand(A) ::= expr(X). {A = X;}
650case_operand(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000651
652%type exprlist {ExprList*}
653%destructor exprlist {sqliteExprListDelete($$);}
654%type expritem {Expr*}
655%destructor expritem {sqliteExprDelete($$);}
656
drh348784e2000-05-29 20:41:49 +0000657exprlist(A) ::= exprlist(X) COMMA expritem(Y).
658 {A = sqliteExprListAppend(X,Y,0);}
659exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
660expritem(A) ::= expr(X). {A = X;}
661expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000662
drh382c0242001-10-06 16:33:02 +0000663///////////////////////////// The CREATE INDEX command ///////////////////////
664//
drh5ad1a6c2002-07-01 12:27:09 +0000665cmd ::= CREATE(S) uniqueflag(U) INDEX nm(X)
666 ON nm(Y) LP idxlist(Z) RP(E) onconf(R). {
drh9cfcf5d2002-01-29 18:41:24 +0000667 if( U!=OE_None ) U = R;
668 if( U==OE_Default) U = OE_Abort;
669 sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E);
670}
drh717e6402001-09-27 03:22:32 +0000671
672%type uniqueflag {int}
drh9cfcf5d2002-01-29 18:41:24 +0000673uniqueflag(A) ::= UNIQUE. { A = OE_Abort; }
674uniqueflag(A) ::= . { A = OE_None; }
drh348784e2000-05-29 20:41:49 +0000675
676%type idxlist {IdList*}
677%destructor idxlist {sqliteIdListDelete($$);}
678%type idxitem {Token}
679
680idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
681 {A = sqliteIdListAppend(X,&Y);}
682idxlist(A) ::= idxitem(Y).
683 {A = sqliteIdListAppend(0,&Y);}
drh5ad1a6c2002-07-01 12:27:09 +0000684idxitem(A) ::= nm(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000685
drh8aff1012001-12-22 14:49:24 +0000686///////////////////////////// The DROP INDEX command /////////////////////////
drh382c0242001-10-06 16:33:02 +0000687//
688
drh5ad1a6c2002-07-01 12:27:09 +0000689cmd ::= DROP INDEX nm(X). {sqliteDropIndex(pParse, &X);}
drh982cef72000-05-30 16:27:03 +0000690
drh382c0242001-10-06 16:33:02 +0000691
drh8aff1012001-12-22 14:49:24 +0000692///////////////////////////// The COPY command ///////////////////////////////
drh382c0242001-10-06 16:33:02 +0000693//
drh5ad1a6c2002-07-01 12:27:09 +0000694cmd ::= COPY orconf(R) nm(X) FROM nm(Y) USING DELIMITERS STRING(Z).
drhb419a922002-01-30 16:17:23 +0000695 {sqliteCopy(pParse,&X,&Y,&Z,R);}
drh5ad1a6c2002-07-01 12:27:09 +0000696cmd ::= COPY orconf(R) nm(X) FROM nm(Y).
drhb419a922002-01-30 16:17:23 +0000697 {sqliteCopy(pParse,&X,&Y,0,R);}
drhdce2cbe2000-05-31 02:27:49 +0000698
drh382c0242001-10-06 16:33:02 +0000699///////////////////////////// The VACUUM command /////////////////////////////
700//
drhdce2cbe2000-05-31 02:27:49 +0000701cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
drh5ad1a6c2002-07-01 12:27:09 +0000702cmd ::= VACUUM nm(X). {sqliteVacuum(pParse,&X);}
drhf57b14a2001-09-14 18:54:08 +0000703
drh382c0242001-10-06 16:33:02 +0000704///////////////////////////// The PRAGMA command /////////////////////////////
705//
drh5ad1a6c2002-07-01 12:27:09 +0000706cmd ::= PRAGMA ids(X) EQ nm(Y). {sqlitePragma(pParse,&X,&Y,0);}
drhf57b14a2001-09-14 18:54:08 +0000707cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);}
708cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);}
709cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);}
drh5ad1a6c2002-07-01 12:27:09 +0000710cmd ::= PRAGMA ids(X) LP nm(Y) RP. {sqlitePragma(pParse,&X,&Y,0);}
drh603240c2002-03-05 01:11:12 +0000711cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);}
drhf57b14a2001-09-14 18:54:08 +0000712plus_num(A) ::= plus_opt number(X). {A = X;}
713minus_num(A) ::= MINUS number(X). {A = X;}
714number(A) ::= INTEGER(X). {A = X;}
715number(A) ::= FLOAT(X). {A = X;}
716plus_opt ::= PLUS.
717plus_opt ::= .
danielk1977c3f9bad2002-05-15 08:30:12 +0000718
719//////////////////////////// The CREATE TRIGGER command /////////////////////
drh5ad1a6c2002-07-01 12:27:09 +0000720cmd ::= CREATE(A) TRIGGER nm(B) trigger_time(C) trigger_event(D) ON nm(E)
danielk1977c3f9bad2002-05-15 08:30:12 +0000721 foreach_clause(F) when_clause(G)
722 BEGIN trigger_cmd_list(S) END(Z). {
723 sqliteCreateTrigger(pParse, &B, C, D.a, D.b, &E, F, G, S,
724 A.z, (int)(Z.z - A.z) + Z.n );
725}
726
727%type trigger_time {int}
728trigger_time(A) ::= BEFORE. { A = TK_BEFORE; }
729trigger_time(A) ::= AFTER. { A = TK_AFTER; }
730trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;}
731trigger_time(A) ::= . { A = TK_BEFORE; }
732
drhad3cab52002-05-24 02:04:32 +0000733%type trigger_event {struct TrigEvent}
734%destructor trigger_event {sqliteIdListDelete($$.b);}
danielk1977c3f9bad2002-05-15 08:30:12 +0000735trigger_event(A) ::= DELETE. { A.a = TK_DELETE; A.b = 0; }
736trigger_event(A) ::= INSERT. { A.a = TK_INSERT; A.b = 0; }
737trigger_event(A) ::= UPDATE. { A.a = TK_UPDATE; A.b = 0;}
738trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X; }
739
740%type foreach_clause {int}
741foreach_clause(A) ::= . { A = TK_ROW; }
742foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; }
743foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; }
744
745%type when_clause {Expr *}
746when_clause(A) ::= . { A = 0; }
747when_clause(A) ::= WHEN expr(X). { A = X; }
748
749%type trigger_cmd_list {TriggerStep *}
750trigger_cmd_list(A) ::= trigger_cmd(X) SEMI trigger_cmd_list(Y). {
751 X->pNext = Y ; A = X; }
752trigger_cmd_list(A) ::= . { A = 0; }
753
754%type trigger_cmd {TriggerStep *}
755// UPDATE
drh5ad1a6c2002-07-01 12:27:09 +0000756trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z).
danielk1977c3f9bad2002-05-15 08:30:12 +0000757 { A = sqliteTriggerUpdateStep(&X, Y, Z, R); }
758
759// INSERT
drh5ad1a6c2002-07-01 12:27:09 +0000760trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F)
danielk1977c3f9bad2002-05-15 08:30:12 +0000761 VALUES LP itemlist(Y) RP.
762{A = sqliteTriggerInsertStep(&X, F, Y, 0, R);}
763
drh5ad1a6c2002-07-01 12:27:09 +0000764trigger_cmd(A) ::= INSERT orconf(R) INTO nm(X) inscollist_opt(F) select(S).
danielk1977c3f9bad2002-05-15 08:30:12 +0000765 {A = sqliteTriggerInsertStep(&X, F, 0, S, R);}
766
767// DELETE
drh5ad1a6c2002-07-01 12:27:09 +0000768trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y).
danielk1977c3f9bad2002-05-15 08:30:12 +0000769 {A = sqliteTriggerDeleteStep(&X, Y);}
770
771// SELECT
772trigger_cmd(A) ::= select(X). {A = sqliteTriggerSelectStep(X); }
773
danielk19776f349032002-06-11 02:25:40 +0000774// The special RAISE expression that may occur in trigger programs
775expr(A) ::= RAISE(X) LP IGNORE RP(Y). { A = sqliteExpr(TK_RAISE, 0, 0, 0);
776 A->iColumn = OE_Ignore; sqliteExprSpan(A, &X, &Y);}
drh5ad1a6c2002-07-01 12:27:09 +0000777expr(A) ::= RAISE(X) LP ROLLBACK COMMA nm(Z) RP(Y).
danielk19776f349032002-06-11 02:25:40 +0000778{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
779 A->iColumn = OE_Rollback; sqliteExprSpan(A, &X, &Y);}
drh5ad1a6c2002-07-01 12:27:09 +0000780expr(A) ::= RAISE(X) LP ABORT COMMA nm(Z) RP(Y).
danielk19776f349032002-06-11 02:25:40 +0000781{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
782 A->iColumn = OE_Abort; sqliteExprSpan(A, &X, &Y);}
drh5ad1a6c2002-07-01 12:27:09 +0000783expr(A) ::= RAISE(X) LP FAIL COMMA nm(Z) RP(Y).
danielk19776f349032002-06-11 02:25:40 +0000784{ A = sqliteExpr(TK_RAISE, 0, 0, &Z);
785 A->iColumn = OE_Fail; sqliteExprSpan(A, &X, &Y);}
786
danielk1977c3f9bad2002-05-15 08:30:12 +0000787//////////////////////// DROP TRIGGER statement //////////////////////////////
drh5ad1a6c2002-07-01 12:27:09 +0000788cmd ::= DROP TRIGGER nm(X). {
danielk1977c3f9bad2002-05-15 08:30:12 +0000789 sqliteDropTrigger(pParse,&X,0);
790}