blob: 862e1d6309c45d5b82c8c18e949cced65dedfd2f [file] [log] [blame]
drh348784e2000-05-29 20:41:49 +00001/*
2** Copyright (c) 1999, 2000 D. Richard Hipp
3**
4** This program is free software; you can redistribute it and/or
5** modify it under the terms of the GNU General Public
6** License as published by the Free Software Foundation; either
7** version 2 of the License, or (at your option) any later version.
8**
9** This program is distributed in the hope that it will be useful,
10** but WITHOUT ANY WARRANTY; without even the implied warranty of
11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12** General Public License for more details.
13**
14** You should have received a copy of the GNU General Public
15** License along with this library; if not, write to the
16** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17** Boston, MA 02111-1307, USA.
18**
19** Author contact information:
20** drh@hwaci.com
21** http://www.hwaci.com/drh/
22**
23*************************************************************************
24** This file contains SQLite's grammar for SQL. Process this file
25** using the lemon parser generator to generate C code that runs
26** the parser. Lemon will also generate a header file containing
27** numeric codes for all of the tokens.
28**
drh6206d502000-06-19 19:09:08 +000029** @(#) $Id: parse.y,v 1.22 2000/06/19 19:09:09 drh Exp $
drh348784e2000-05-29 20:41:49 +000030*/
31%token_prefix TK_
32%token_type {Token}
33%extra_argument {Parse *pParse}
34%syntax_error {
drhc837e702000-06-08 16:26:24 +000035 sqliteSetString(&pParse->zErrMsg,"syntax error",0);
drh348784e2000-05-29 20:41:49 +000036 pParse->sErrToken = TOKEN;
37}
38%name sqliteParser
39%include {
40#include "sqliteInt.h"
41#include "parse.h"
42}
43
44
45// Input is zero or more commands.
46input ::= cmdlist.
47
48// These are extra tokens used by the lexer but never seen by the
49// parser. We put them in a rule so that the parser generator will
drh6206d502000-06-19 19:09:08 +000050// add them to the parse.h output file.
drh348784e2000-05-29 20:41:49 +000051//
52input ::= END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
drh22827922000-06-06 17:27:05 +000053 UMINUS FIELD AGG_FUNCTION.
drh348784e2000-05-29 20:41:49 +000054
55// A list of commands is zero or more commands
56//
57cmdlist ::= ecmd.
58cmdlist ::= cmdlist SEMI ecmd.
59ecmd ::= explain cmd. {sqliteExec(pParse);}
60ecmd ::= cmd. {sqliteExec(pParse);}
61ecmd ::= .
62explain ::= EXPLAIN. {pParse->explain = 1;}
63
64// The first form of a command is a CREATE TABLE statement.
65//
66cmd ::= create_table create_table_args.
drh982cef72000-05-30 16:27:03 +000067create_table ::= CREATE(X) TABLE id(Y). {sqliteStartTable(pParse,&X,&Y);}
drh348784e2000-05-29 20:41:49 +000068create_table_args ::= LP columnlist conslist_opt RP(X).
69 {sqliteEndTable(pParse,&X);}
70columnlist ::= columnlist COMMA column.
71columnlist ::= column.
72
73// About the only information used for a column is the name of the
74// column. The type is always just "text". But the code will accept
75// an elaborate typename. Perhaps someday we'll do something with it.
76//
77column ::= columnid type carglist.
drh982cef72000-05-30 16:27:03 +000078columnid ::= id(X). {sqliteAddColumn(pParse,&X);}
79%type id {Token}
80id(A) ::= ID(X). {A = X;}
81id(A) ::= STRING(X). {A = X;}
drh348784e2000-05-29 20:41:49 +000082type ::= typename.
83type ::= typename LP signed RP.
84type ::= typename LP signed COMMA signed RP.
drh4cfa7932000-06-08 15:10:46 +000085typename ::= id.
86typename ::= typename id.
drh348784e2000-05-29 20:41:49 +000087signed ::= INTEGER.
88signed ::= PLUS INTEGER.
89signed ::= MINUS INTEGER.
90carglist ::= carglist carg.
91carglist ::= .
drh4cfa7932000-06-08 15:10:46 +000092carg ::= CONSTRAINT id ccons.
drh348784e2000-05-29 20:41:49 +000093carg ::= ccons.
drh7020f652000-06-03 18:06:52 +000094carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);}
95carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);}
96carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
97carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);}
98carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);}
99carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
100carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);}
101carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);}
102carg ::= DEFAULT NULL.
drh348784e2000-05-29 20:41:49 +0000103
104// In addition to the type name, we also care about the primary key.
105//
106ccons ::= NOT NULL.
drh6206d502000-06-19 19:09:08 +0000107ccons ::= PRIMARY KEY sortorder. {sqliteCreateIndex(pParse,0,0,0,0,0);}
drh348784e2000-05-29 20:41:49 +0000108ccons ::= UNIQUE.
drh4794b982000-06-06 13:54:14 +0000109ccons ::= CHECK LP expr RP.
drh348784e2000-05-29 20:41:49 +0000110
111// For the time being, the only constraint we care about is the primary
112// key.
113//
114conslist_opt ::= .
115conslist_opt ::= COMMA conslist.
116conslist ::= conslist COMMA tcons.
117conslist ::= tcons.
drh4cfa7932000-06-08 15:10:46 +0000118tcons ::= CONSTRAINT id tcons2.
drh348784e2000-05-29 20:41:49 +0000119tcons ::= tcons2.
drh6206d502000-06-19 19:09:08 +0000120tcons2 ::= PRIMARY KEY LP idxlist(X) RP. {sqliteCreateIndex(pParse,0,0,X,0,0);}
drh348784e2000-05-29 20:41:49 +0000121tcons2 ::= UNIQUE LP idlist RP.
122tcons2 ::= CHECK expr.
drh982cef72000-05-30 16:27:03 +0000123idlist ::= idlist COMMA id.
124idlist ::= id.
drh348784e2000-05-29 20:41:49 +0000125
126// The next command format is dropping tables.
127//
drh982cef72000-05-30 16:27:03 +0000128cmd ::= DROP TABLE id(X). {sqliteDropTable(pParse,&X);}
drh348784e2000-05-29 20:41:49 +0000129
130// The select statement
131//
drh9bb61fe2000-06-05 16:01:39 +0000132cmd ::= select(X). {
drhfef52082000-06-06 01:50:43 +0000133 sqliteSelect(pParse, X, SRT_Callback, 0);
drh9bb61fe2000-06-05 16:01:39 +0000134 sqliteSelectDelete(X);
135}
drhefb72512000-05-31 20:00:52 +0000136
drh9bb61fe2000-06-05 16:01:39 +0000137%type select {Select*}
138%destructor select {sqliteSelectDelete($$);}
drh82c3d632000-06-06 21:56:07 +0000139%type oneselect {Select*}
140%destructor oneselect {sqliteSelectDelete($$);}
drh9bb61fe2000-06-05 16:01:39 +0000141
drh82c3d632000-06-06 21:56:07 +0000142select(A) ::= oneselect(X). {A = X;}
143select(A) ::= select(X) joinop(Y) oneselect(Z). {
144 Z->op = Y;
145 Z->pPrior = X;
146 A = Z;
147}
148%type joinop {int}
149joinop(A) ::= UNION. {A = TK_UNION;}
150joinop(A) ::= UNION ALL. {A = TK_ALL;}
151joinop(A) ::= INTERSECT. {A = TK_INTERSECT;}
152joinop(A) ::= EXCEPT. {A = TK_EXCEPT;}
153oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y)
154 groupby_opt(P) having_opt(Q) orderby_opt(Z). {
drh22827922000-06-06 17:27:05 +0000155 A = sqliteSelectNew(W,X,Y,P,Q,Z,D);
drh9bb61fe2000-06-05 16:01:39 +0000156}
157
158// The "distinct" nonterminal is true (1) if the DISTINCT keyword is
159// present and false (0) if it is not.
160//
drhefb72512000-05-31 20:00:52 +0000161%type distinct {int}
drhefb72512000-05-31 20:00:52 +0000162distinct(A) ::= DISTINCT. {A = 1;}
drhfef52082000-06-06 01:50:43 +0000163distinct(A) ::= ALL. {A = 0;}
drhefb72512000-05-31 20:00:52 +0000164distinct(A) ::= . {A = 0;}
drh348784e2000-05-29 20:41:49 +0000165
drh9bb61fe2000-06-05 16:01:39 +0000166// selcollist is a list of expressions that are to become the return
167// values of the SELECT statement. In the case of "SELECT * FROM ..."
168// the selcollist value is NULL.
169//
drh348784e2000-05-29 20:41:49 +0000170%type selcollist {ExprList*}
171%destructor selcollist {sqliteExprListDelete($$);}
172%type sclp {ExprList*}
173%destructor sclp {sqliteExprListDelete($$);}
drh348784e2000-05-29 20:41:49 +0000174sclp(A) ::= selcollist(X) COMMA. {A = X;}
175sclp(A) ::= . {A = 0;}
drh9bb61fe2000-06-05 16:01:39 +0000176selcollist(A) ::= STAR. {A = 0;}
drh348784e2000-05-29 20:41:49 +0000177selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);}
drh4cfa7932000-06-08 15:10:46 +0000178selcollist(A) ::= sclp(P) expr(X) as id(Y). {A = sqliteExprListAppend(P,X,&Y);}
drh9bb61fe2000-06-05 16:01:39 +0000179as ::= .
180as ::= AS.
181
drh348784e2000-05-29 20:41:49 +0000182
183%type seltablist {IdList*}
184%destructor seltablist {sqliteIdListDelete($$);}
185%type stl_prefix {IdList*}
186%destructor stl_prefix {sqliteIdListDelete($$);}
187%type from {IdList*}
188%destructor from {sqliteIdListDelete($$);}
189
190from(A) ::= FROM seltablist(X). {A = X;}
191stl_prefix(A) ::= seltablist(X) COMMA. {A = X;}
192stl_prefix(A) ::= . {A = 0;}
drh982cef72000-05-30 16:27:03 +0000193seltablist(A) ::= stl_prefix(X) id(Y). {A = sqliteIdListAppend(X,&Y);}
drh6206d502000-06-19 19:09:08 +0000194seltablist(A) ::= stl_prefix(X) id(Y) as id(Z).
drh348784e2000-05-29 20:41:49 +0000195 {A = sqliteIdListAppend(X,&Y);
196 sqliteIdListAddAlias(A,&Z);}
197
198%type orderby_opt {ExprList*}
199%destructor orderby_opt {sqliteExprListDelete($$);}
200%type sortlist {ExprList*}
201%destructor sortlist {sqliteExprListDelete($$);}
202%type sortitem {Expr*}
203%destructor sortitem {sqliteExprDelete($$);}
204
205orderby_opt(A) ::= . {A = 0;}
206orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;}
drh9bb61fe2000-06-05 16:01:39 +0000207sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). {
208 A = sqliteExprListAppend(X,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000209 A->a[A->nExpr-1].sortOrder = Z; /* 0 for ascending order, 1 for decending */
drh9bb61fe2000-06-05 16:01:39 +0000210}
211sortlist(A) ::= sortitem(Y) sortorder(Z). {
212 A = sqliteExprListAppend(0,Y,0);
drhd8bc7082000-06-07 23:51:50 +0000213 A->a[0].sortOrder = Z;
drh9bb61fe2000-06-05 16:01:39 +0000214}
drhda9d6c42000-05-31 18:20:14 +0000215sortitem(A) ::= expr(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000216
217%type sortorder {int}
218
219sortorder(A) ::= ASC. {A = 0;}
220sortorder(A) ::= DESC. {A = 1;}
221sortorder(A) ::= . {A = 0;}
222
drh22827922000-06-06 17:27:05 +0000223%type groupby_opt {ExprList*}
224%destructor groupby_opt {sqliteExprListDelete($$);}
drh6206d502000-06-19 19:09:08 +0000225groupby_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000226groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;}
227
228%type having_opt {Expr*}
229%destructor having_opt {sqliteExprDelete($$);}
drh6206d502000-06-19 19:09:08 +0000230having_opt(A) ::= . {A = 0;}
drh22827922000-06-06 17:27:05 +0000231having_opt(A) ::= HAVING expr(X). {A = X;}
232
drh82c3d632000-06-06 21:56:07 +0000233
drh4cfa7932000-06-08 15:10:46 +0000234cmd ::= DELETE FROM id(X) where_opt(Y).
drh348784e2000-05-29 20:41:49 +0000235 {sqliteDeleteFrom(pParse, &X, Y);}
236
237%type where_opt {Expr*}
238%destructor where_opt {sqliteExprDelete($$);}
239
240where_opt(A) ::= . {A = 0;}
241where_opt(A) ::= WHERE expr(X). {A = X;}
242
243%type setlist {ExprList*}
244%destructor setlist {sqliteExprListDelete($$);}
245
drh4cfa7932000-06-08 15:10:46 +0000246cmd ::= UPDATE id(X) SET setlist(Y) where_opt(Z).
drh348784e2000-05-29 20:41:49 +0000247 {sqliteUpdate(pParse,&X,Y,Z);}
248
drh4cfa7932000-06-08 15:10:46 +0000249setlist(A) ::= id(X) EQ expr(Y) COMMA setlist(Z).
drh348784e2000-05-29 20:41:49 +0000250 {A = sqliteExprListAppend(Z,Y,&X);}
drh4cfa7932000-06-08 15:10:46 +0000251setlist(A) ::= id(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);}
drh348784e2000-05-29 20:41:49 +0000252
drh4cfa7932000-06-08 15:10:46 +0000253cmd ::= INSERT INTO id(X) fieldlist_opt(F) VALUES LP itemlist(Y) RP.
drh5974a302000-06-07 14:42:26 +0000254 {sqliteInsert(pParse, &X, Y, 0, F);}
drh4cfa7932000-06-08 15:10:46 +0000255cmd ::= INSERT INTO id(X) fieldlist_opt(F) select(S).
drh5974a302000-06-07 14:42:26 +0000256 {sqliteInsert(pParse, &X, 0, S, F);}
drh348784e2000-05-29 20:41:49 +0000257
258
259%type itemlist {ExprList*}
260%destructor itemlist {sqliteExprListDelete($$);}
261%type item {Expr*}
262%destructor item {sqliteExprDelete($$);}
263
264itemlist(A) ::= itemlist(X) COMMA item(Y). {A = sqliteExprListAppend(X,Y,0);}
265itemlist(A) ::= item(X). {A = sqliteExprListAppend(0,X,0);}
266item(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000267item(A) ::= PLUS INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
268item(A) ::= MINUS INTEGER(X). {
drh6e142f52000-06-08 13:36:40 +0000269 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
270 A->pLeft = sqliteExpr(TK_INTEGER, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000271}
drh348784e2000-05-29 20:41:49 +0000272item(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
drh7020f652000-06-03 18:06:52 +0000273item(A) ::= PLUS FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
274item(A) ::= MINUS FLOAT(X). {
drh6e142f52000-06-08 13:36:40 +0000275 A = sqliteExpr(TK_UMINUS, 0, 0, 0);
276 A->pLeft = sqliteExpr(TK_FLOAT, 0, 0, &X);
drh7020f652000-06-03 18:06:52 +0000277}
drh348784e2000-05-29 20:41:49 +0000278item(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drh8be51132000-06-03 19:19:41 +0000279item(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh348784e2000-05-29 20:41:49 +0000280
281%type fieldlist_opt {IdList*}
282%destructor fieldlist_opt {sqliteIdListDelete($$);}
283%type fieldlist {IdList*}
284%destructor fieldlist {sqliteIdListDelete($$);}
285
286fieldlist_opt(A) ::= . {A = 0;}
287fieldlist_opt(A) ::= LP fieldlist(X) RP. {A = X;}
drh4cfa7932000-06-08 15:10:46 +0000288fieldlist(A) ::= fieldlist(X) COMMA id(Y). {A = sqliteIdListAppend(X,&Y);}
289fieldlist(A) ::= id(Y). {A = sqliteIdListAppend(0,&Y);}
drh348784e2000-05-29 20:41:49 +0000290
291%left OR.
292%left AND.
drh8be51132000-06-03 19:19:41 +0000293%right NOT.
drhfef52082000-06-06 01:50:43 +0000294%left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN.
drh348784e2000-05-29 20:41:49 +0000295%left GT GE LT LE.
296%left PLUS MINUS.
drh31884b02000-06-09 14:14:32 +0000297%left STAR SLASH.
drh00400772000-06-16 20:51:26 +0000298%left CONCAT.
drh8be51132000-06-03 19:19:41 +0000299%right UMINUS.
drh348784e2000-05-29 20:41:49 +0000300
301%type expr {Expr*}
302%destructor expr {sqliteExprDelete($$);}
303
304expr(A) ::= LP expr(X) RP. {A = X;}
305expr(A) ::= ID(X). {A = sqliteExpr(TK_ID, 0, 0, &X);}
306expr(A) ::= NULL. {A = sqliteExpr(TK_NULL, 0, 0, 0);}
drh4cfa7932000-06-08 15:10:46 +0000307expr(A) ::= id(X) DOT id(Y). {Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X);
drh348784e2000-05-29 20:41:49 +0000308 Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y);
309 A = sqliteExpr(TK_DOT, temp1, temp2, 0);}
310expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);}
311expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);}
312expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);}
drhcce7d172000-05-31 15:34:51 +0000313expr(A) ::= ID(X) LP exprlist(Y) RP. {A = sqliteExprFunction(Y, &X);}
314expr(A) ::= ID(X) LP STAR RP. {A = sqliteExprFunction(0, &X);}
drh348784e2000-05-29 20:41:49 +0000315expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);}
316expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);}
317expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);}
318expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);}
319expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);}
320expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);}
321expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);}
322expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);}
drhdce2cbe2000-05-31 02:27:49 +0000323expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);}
drh4794b982000-06-06 13:54:14 +0000324expr(A) ::= expr(X) NOT LIKE expr(Y). {
325 A = sqliteExpr(TK_LIKE, X, Y, 0);
326 A = sqliteExpr(TK_NOT, A, 0, 0);
327}
drhfef52082000-06-06 01:50:43 +0000328expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);}
drh4794b982000-06-06 13:54:14 +0000329expr(A) ::= expr(X) NOT GLOB expr(Y). {
330 A = sqliteExpr(TK_GLOB, X, Y, 0);
331 A = sqliteExpr(TK_NOT, A, 0, 0);
332}
drh348784e2000-05-29 20:41:49 +0000333expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);}
334expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);}
335expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);}
336expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);}
drh00400772000-06-16 20:51:26 +0000337expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);}
drh348784e2000-05-29 20:41:49 +0000338expr(A) ::= expr(X) ISNULL. {A = sqliteExpr(TK_ISNULL, X, 0, 0);}
339expr(A) ::= expr(X) NOTNULL. {A = sqliteExpr(TK_NOTNULL, X, 0, 0);}
340expr(A) ::= NOT expr(X). {A = sqliteExpr(TK_NOT, X, 0, 0);}
drh8be51132000-06-03 19:19:41 +0000341expr(A) ::= MINUS expr(X). [UMINUS] {A = sqliteExpr(TK_UMINUS, X, 0, 0);}
342expr(A) ::= PLUS expr(X). [UMINUS] {A = X;}
drh19a775c2000-06-05 18:54:46 +0000343expr(A) ::= LP select(X) RP. {
344 A = sqliteExpr(TK_SELECT, 0, 0, 0);
345 A->pSelect = X;
346}
drhfef52082000-06-06 01:50:43 +0000347expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). {
348 ExprList *pList = sqliteExprListAppend(0, X, 0);
349 pList = sqliteExprListAppend(pList, Y, 0);
350 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
351 A->pList = pList;
352}
drh4794b982000-06-06 13:54:14 +0000353expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). {
354 ExprList *pList = sqliteExprListAppend(0, X, 0);
355 pList = sqliteExprListAppend(pList, Y, 0);
356 A = sqliteExpr(TK_BETWEEN, W, 0, 0);
357 A->pList = pList;
358 A = sqliteExpr(TK_NOT, A, 0, 0);
359}
drhfef52082000-06-06 01:50:43 +0000360expr(A) ::= expr(X) IN LP exprlist(Y) RP. {
361 A = sqliteExpr(TK_IN, X, 0, 0);
362 A->pList = Y;
363}
364expr(A) ::= expr(X) IN LP select(Y) RP. {
365 A = sqliteExpr(TK_IN, X, 0, 0);
366 A->pSelect = Y;
367}
drh4794b982000-06-06 13:54:14 +0000368expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP. {
369 A = sqliteExpr(TK_IN, X, 0, 0);
370 A->pList = Y;
371 A = sqliteExpr(TK_NOT, A, 0, 0);
372}
373expr(A) ::= expr(X) NOT IN LP select(Y) RP. {
374 A = sqliteExpr(TK_IN, X, 0, 0);
375 A->pSelect = Y;
376 A = sqliteExpr(TK_NOT, A, 0, 0);
377}
drhfef52082000-06-06 01:50:43 +0000378
379
drh348784e2000-05-29 20:41:49 +0000380
381%type exprlist {ExprList*}
382%destructor exprlist {sqliteExprListDelete($$);}
383%type expritem {Expr*}
384%destructor expritem {sqliteExprDelete($$);}
385
drh348784e2000-05-29 20:41:49 +0000386exprlist(A) ::= exprlist(X) COMMA expritem(Y).
387 {A = sqliteExprListAppend(X,Y,0);}
388exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);}
389expritem(A) ::= expr(X). {A = X;}
390expritem(A) ::= . {A = 0;}
drhcce7d172000-05-31 15:34:51 +0000391
drh348784e2000-05-29 20:41:49 +0000392
drh4cfa7932000-06-08 15:10:46 +0000393cmd ::= CREATE(S) uniqueflag INDEX id(X) ON id(Y) LP idxlist(Z) RP(E).
drh348784e2000-05-29 20:41:49 +0000394 {sqliteCreateIndex(pParse, &X, &Y, Z, &S, &E);}
395uniqueflag ::= UNIQUE.
396uniqueflag ::= .
397
398%type idxlist {IdList*}
399%destructor idxlist {sqliteIdListDelete($$);}
400%type idxitem {Token}
401
402idxlist(A) ::= idxlist(X) COMMA idxitem(Y).
403 {A = sqliteIdListAppend(X,&Y);}
404idxlist(A) ::= idxitem(Y).
405 {A = sqliteIdListAppend(0,&Y);}
drh4cfa7932000-06-08 15:10:46 +0000406idxitem(A) ::= id(X). {A = X;}
drh348784e2000-05-29 20:41:49 +0000407
drh982cef72000-05-30 16:27:03 +0000408cmd ::= DROP INDEX id(X). {sqliteDropIndex(pParse, &X);}
409
410cmd ::= COPY id(X) FROM id(Y) USING DELIMITERS STRING(Z).
411 {sqliteCopy(pParse,&X,&Y,&Z);}
412cmd ::= COPY id(X) FROM id(Y).
413 {sqliteCopy(pParse,&X,&Y,0);}
drhdce2cbe2000-05-31 02:27:49 +0000414
415cmd ::= VACUUM. {sqliteVacuum(pParse,0);}
416cmd ::= VACUUM id(X). {sqliteVacuum(pParse,&X);}