4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** 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.
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.
17 ** @(#) $Id: parse.y,v 1.172 2005/05/23 17:26:51 drh Exp $
22 %extra_argument
{Parse
*pParse
}
24 if
( pParse
->zErrMsg
==0 ){
26 sqlite3ErrorMsg
(pParse
, "near \"%T\": syntax error", &TOKEN
);
28 sqlite3ErrorMsg
(pParse
, "incomplete SQL statement");
34 #include "sqliteInt.h"
38 ** An instance of this structure holds information about the
39 ** LIMIT clause of a SELECT statement.
42 Expr
*pLimit
; /* The LIMIT expression. NULL if there is no limit */
43 Expr
*pOffset
; /* The OFFSET expression. NULL if there is none */
47 ** An instance of this structure is used to store the LIKE,
48 ** GLOB, NOT LIKE, and NOT GLOB operators.
51 Token operator
; /* "like" or "glob" or "regexp" */
52 int not
; /* True if the NOT keyword is present */
56 ** An instance of the following structure describes the event of a
57 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT,
58 ** TK_DELETE, or TK_INSTEAD. If the event is of the form
62 ** Then the "b" IdList records the list "a,b,c".
64 struct TrigEvent
{ int a
; IdList
* b
; };
67 ** An instance of this structure holds the ATTACH key and the key type.
69 struct AttachKey
{ int type
; Token key
; };
73 // These are extra tokens used by the lexer but never seen by the
74 // parser. We put them in a rule so that the parser generator will
75 // add them to the parse.h output file.
77 %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
78 COLUMN AGG_FUNCTION CONST_FUNC.
80 // Input is a single SQL command
82 cmdlist
::= cmdlist ecmd.
84 cmdx
::= cmd.
{ sqlite3FinishCoding
(pParse
); }
86 ecmd
::= explain cmdx SEMI.
87 explain
::= .
{ sqlite3BeginParse
(pParse
, 0); }
88 %ifndef SQLITE_OMIT_EXPLAIN
89 explain
::= EXPLAIN.
{ sqlite3BeginParse
(pParse
, 1); }
92 ///////////////////// Begin and end transactions. ////////////////////////////
95 cmd
::= BEGIN transtype
(Y
) trans_opt.
{sqlite3BeginTransaction
(pParse
, Y
);}
97 trans_opt
::= TRANSACTION.
98 trans_opt
::= TRANSACTION nm.
100 transtype
(A
) ::= .
{A
= TK_DEFERRED
;}
101 transtype
(A
) ::= DEFERRED
(X
).
{A
= @X
;}
102 transtype
(A
) ::= IMMEDIATE
(X
).
{A
= @X
;}
103 transtype
(A
) ::= EXCLUSIVE
(X
).
{A
= @X
;}
104 cmd
::= COMMIT trans_opt.
{sqlite3CommitTransaction
(pParse
);}
105 cmd
::= END trans_opt.
{sqlite3CommitTransaction
(pParse
);}
106 cmd
::= ROLLBACK trans_opt.
{sqlite3RollbackTransaction
(pParse
);}
108 ///////////////////// The CREATE TABLE statement ////////////////////////////
110 cmd
::= create_table create_table_args.
111 create_table
::= CREATE
(X
) temp
(T
) TABLE nm
(Y
) dbnm
(Z
).
{
112 sqlite3StartTable
(pParse
,&X
,&Y
,&Z
,T
,0);
115 %ifndef SQLITE_OMIT_TEMPDB
116 temp
(A
) ::= TEMP.
{A
= 1;}
118 temp
(A
) ::= .
{A
= 0;}
119 create_table_args
::= LP columnlist conslist_opt
(X
) RP
(Y
).
{
120 sqlite3EndTable
(pParse
,&X
,&Y
,0);
122 create_table_args
::= AS select
(S
).
{
123 sqlite3EndTable
(pParse
,0,0,S
);
124 sqlite3SelectDelete
(S
);
126 columnlist
::= columnlist COMMA column.
127 columnlist
::= column.
129 // About the only information used for a column is the name of the
130 // column. The type is always just "text". But the code will accept
131 // an elaborate typename. Perhaps someday we'll do something with it.
133 column
(A
) ::= columnid
(X
) type carglist.
{
135 A.n
= (pParse
->sLastToken.z
-X.z
) + pParse
->sLastToken.n
;
137 columnid
(A
) ::= nm
(X
).
{
138 sqlite3AddColumn
(pParse
,&X
);
143 // An IDENTIFIER can be a generic identifier, or one of several
144 // keywords. Any non-standard keyword can also be an identifier.
147 id
(A
) ::= ID
(X
).
{A
= X
;}
149 // The following directive causes tokens ABORT, AFTER, ASC, etc. to
150 // fallback to ID if they will not parse as their original value.
151 // This obviates the need for the "id" nonterminal.
154 ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CONFLICT
155 DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR
156 IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH KEY
157 OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT
158 TEMP TRIGGER VACUUM VIEW
159 %ifdef SQLITE_OMIT_COMPOUND_SELECT
160 EXCEPT INTERSECT UNION
162 REINDEX RENAME CTIME_KW ALTER
165 // Define operator precedence early so that this is the first occurance
166 // of the operator tokens in the grammer. Keeping the operators together
167 // causes them to be assigned integer values that are close together,
168 // which keeps parser tables smaller.
170 // The token values assigned to these symbols is determined by the order
171 // in which lemon first sees them. It must be the case that ISNULL/NOTNULL,
172 // NE/EQ, GT/LE, and GE/LT are separated by only a single value. See
173 // the sqlite3ExprIfFalse() routine for additional information on this
179 %left IS LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
182 %left BITAND BITOR LSHIFT RSHIFT.
184 %left STAR SLASH REM.
186 %right UMINUS UPLUS BITNOT.
188 // And "ids" is an identifer-or-string.
191 ids
(A
) ::= ID
(X
).
{A
= X
;}
192 ids
(A
) ::= STRING
(X
).
{A
= X
;}
194 // The name of a column or table can be any of the following:
197 nm
(A
) ::= ID
(X
).
{A
= X
;}
198 nm
(A
) ::= STRING
(X
).
{A
= X
;}
199 nm
(A
) ::= JOIN_KW
(X
).
{A
= X
;}
202 type
::= typename
(X
).
{sqlite3AddColumnType
(pParse
,&X
,&X
);}
203 type
::= typename
(X
) LP
signed RP
(Y
).
{sqlite3AddColumnType
(pParse
,&X
,&Y
);}
204 type
::= typename
(X
) LP
signed COMMA
signed RP
(Y
).
205 {sqlite3AddColumnType
(pParse
,&X
,&Y
);}
206 %type typename
{Token
}
207 typename
(A
) ::= ids
(X
).
{A
= X
;}
208 typename
(A
) ::= typename
(X
) ids
(Y
).
{A.z
=X.z
; A.n
=Y.n
+(Y.z
-X.z
);}
210 signed(A
) ::= plus_num
(X
).
{ A
= atoi
(X.z
); }
211 signed(A
) ::= minus_num
(X
).
{ A
= -atoi
(X.z
); }
212 carglist
::= carglist carg.
214 carg
::= CONSTRAINT nm ccons.
216 carg
::= DEFAULT term
(X
).
{sqlite3AddDefaultValue
(pParse
,X
);}
217 carg
::= DEFAULT PLUS term
(X
).
{sqlite3AddDefaultValue
(pParse
,X
);}
218 carg
::= DEFAULT MINUS term
(X
).
{
219 Expr
*p
= sqlite3Expr
(TK_UMINUS
, X
, 0, 0);
220 sqlite3AddDefaultValue
(pParse
,p
);
222 carg
::= DEFAULT id
(X
).
{
223 Expr
*p
= sqlite3Expr
(TK_STRING
, 0, 0, &X
);
224 sqlite3AddDefaultValue
(pParse
,p
);
227 // In addition to the type name, we also care about the primary key and
228 // UNIQUE constraints.
230 ccons
::= NULL onconf.
231 ccons
::= NOT NULL onconf
(R
).
{sqlite3AddNotNull
(pParse
, R
);}
232 ccons
::= PRIMARY KEY sortorder onconf
(R
) autoinc
(I
).
233 {sqlite3AddPrimaryKey
(pParse
,0,R
,I
);}
234 ccons
::= UNIQUE onconf
(R
).
{sqlite3CreateIndex
(pParse
,0,0,0,0,R
,0,0);}
235 ccons
::= CHECK LP expr
(X
) RP onconf.
{sqlite3ExprDelete
(X
);}
236 ccons
::= REFERENCES nm
(T
) idxlist_opt
(TA
) refargs
(R
).
237 {sqlite3CreateForeignKey
(pParse
,0,&T
,TA
,R
);}
238 ccons
::= defer_subclause
(D
).
{sqlite3DeferForeignKey
(pParse
,D
);}
239 ccons
::= COLLATE id
(C
).
{sqlite3AddCollateType
(pParse
, C.z
, C.n
);}
241 // The optional AUTOINCREMENT keyword
243 autoinc
(X
) ::= .
{X
= 0;}
244 autoinc
(X
) ::= AUTOINCR.
{X
= 1;}
246 // The next group of rules parses the arguments to a REFERENCES clause
247 // that determine if the referential integrity checking is deferred or
248 // or immediate and which determine what action to take if a ref-integ
252 refargs
(A
) ::= .
{ A
= OE_Restrict
* 0x010101; }
253 refargs
(A
) ::= refargs
(X
) refarg
(Y
).
{ A
= (X
& Y.mask
) | Y.value
; }
254 %type refarg
{struct {int value
; int mask
;}}
255 refarg
(A
) ::= MATCH nm.
{ A.value
= 0; A.mask
= 0x000000; }
256 refarg
(A
) ::= ON DELETE refact
(X
).
{ A.value
= X
; A.mask
= 0x0000ff; }
257 refarg
(A
) ::= ON UPDATE refact
(X
).
{ A.value
= X
<<8; A.mask
= 0x00ff00; }
258 refarg
(A
) ::= ON INSERT refact
(X
).
{ A.value
= X
<<16; A.mask
= 0xff0000; }
260 refact
(A
) ::= SET NULL.
{ A
= OE_SetNull
; }
261 refact
(A
) ::= SET DEFAULT.
{ A
= OE_SetDflt
; }
262 refact
(A
) ::= CASCADE.
{ A
= OE_Cascade
; }
263 refact
(A
) ::= RESTRICT.
{ A
= OE_Restrict
; }
264 %type defer_subclause
{int}
265 defer_subclause
(A
) ::= NOT DEFERRABLE init_deferred_pred_opt
(X
).
{A
= X
;}
266 defer_subclause
(A
) ::= DEFERRABLE init_deferred_pred_opt
(X
).
{A
= X
;}
267 %type init_deferred_pred_opt
{int}
268 init_deferred_pred_opt
(A
) ::= .
{A
= 0;}
269 init_deferred_pred_opt
(A
) ::= INITIALLY DEFERRED.
{A
= 1;}
270 init_deferred_pred_opt
(A
) ::= INITIALLY IMMEDIATE.
{A
= 0;}
272 // For the time being, the only constraint we care about is the primary
273 // key and UNIQUE. Both create indices.
275 conslist_opt
(A
) ::= .
{A.n
= 0; A.z
= 0;}
276 conslist_opt
(A
) ::= COMMA
(X
) conslist.
{A
= X
;}
277 conslist
::= conslist COMMA tcons.
278 conslist
::= conslist tcons.
280 tcons
::= CONSTRAINT nm.
281 tcons
::= PRIMARY KEY LP idxlist
(X
) autoinc
(I
) RP onconf
(R
).
282 {sqlite3AddPrimaryKey
(pParse
,X
,R
,I
);}
283 tcons
::= UNIQUE LP idxlist
(X
) RP onconf
(R
).
284 {sqlite3CreateIndex
(pParse
,0,0,0,X
,R
,0,0);}
285 tcons
::= CHECK expr onconf.
286 tcons
::= FOREIGN KEY LP idxlist
(FA
) RP
287 REFERENCES nm
(T
) idxlist_opt
(TA
) refargs
(R
) defer_subclause_opt
(D
).
{
288 sqlite3CreateForeignKey
(pParse
, FA
, &T
, TA
, R
);
289 sqlite3DeferForeignKey
(pParse
, D
);
291 %type defer_subclause_opt
{int}
292 defer_subclause_opt
(A
) ::= .
{A
= 0;}
293 defer_subclause_opt
(A
) ::= defer_subclause
(X
).
{A
= X
;}
295 // The following is a non-standard extension that allows us to declare the
296 // default behavior when there is a constraint conflict.
300 %type resolvetype
{int}
301 onconf
(A
) ::= .
{A
= OE_Default
;}
302 onconf
(A
) ::= ON CONFLICT resolvetype
(X
).
{A
= X
;}
303 orconf
(A
) ::= .
{A
= OE_Default
;}
304 orconf
(A
) ::= OR resolvetype
(X
).
{A
= X
;}
305 resolvetype
(A
) ::= raisetype
(X
).
{A
= X
;}
306 resolvetype
(A
) ::= IGNORE.
{A
= OE_Ignore
;}
307 resolvetype
(A
) ::= REPLACE.
{A
= OE_Replace
;}
309 ////////////////////////// The DROP TABLE /////////////////////////////////////
311 cmd
::= DROP TABLE fullname
(X
).
{
312 sqlite3DropTable
(pParse
, X
, 0);
315 ///////////////////// The CREATE VIEW statement /////////////////////////////
317 %ifndef SQLITE_OMIT_VIEW
318 cmd
::= CREATE
(X
) temp
(T
) VIEW nm
(Y
) dbnm
(Z
) AS select
(S
).
{
319 sqlite3CreateView
(pParse
, &X
, &Y
, &Z
, S
, T
);
321 cmd
::= DROP VIEW fullname
(X
).
{
322 sqlite3DropTable
(pParse
, X
, 1);
324 %endif
// SQLITE_OMIT_VIEW
326 //////////////////////// The SELECT statement /////////////////////////////////
329 sqlite3Select
(pParse
, X
, SRT_Callback
, 0, 0, 0, 0, 0);
330 sqlite3SelectDelete
(X
);
333 %type select
{Select
*}
334 %destructor select
{sqlite3SelectDelete
($$
);}
335 %type oneselect
{Select
*}
336 %destructor oneselect
{sqlite3SelectDelete
($$
);}
338 select
(A
) ::= oneselect
(X
).
{A
= X
;}
339 %ifndef SQLITE_OMIT_COMPOUND_SELECT
340 select
(A
) ::= select
(X
) multiselect_op
(Y
) oneselect
(Z
).
{
347 %type multiselect_op
{int}
348 multiselect_op
(A
) ::= UNION
(OP
).
{A
= @OP
;}
349 multiselect_op
(A
) ::= UNION ALL.
{A
= TK_ALL
;}
350 multiselect_op
(A
) ::= INTERSECT
(OP
).
{A
= @OP
;}
351 multiselect_op
(A
) ::= EXCEPT
(OP
).
{A
= @OP
;}
352 %endif
// SQLITE_OMIT_COMPOUND_SELECT
353 oneselect
(A
) ::= SELECT distinct
(D
) selcollist
(W
) from
(X
) where_opt
(Y
)
354 groupby_opt
(P
) having_opt
(Q
) orderby_opt
(Z
) limit_opt
(L
).
{
355 A
= sqlite3SelectNew
(W
,X
,Y
,P
,Q
,Z
,D
,L.pLimit
,L.pOffset
);
358 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is
359 // present and false (0) if it is not.
362 distinct
(A
) ::= DISTINCT.
{A
= 1;}
363 distinct
(A
) ::= ALL.
{A
= 0;}
364 distinct
(A
) ::= .
{A
= 0;}
366 // selcollist is a list of expressions that are to become the return
367 // values of the SELECT statement. The "*" in statements like
368 // "SELECT * FROM ..." is encoded as a special expression with an
371 %type selcollist
{ExprList
*}
372 %destructor selcollist
{sqlite3ExprListDelete
($$
);}
373 %type sclp
{ExprList
*}
374 %destructor sclp
{sqlite3ExprListDelete
($$
);}
375 sclp
(A
) ::= selcollist
(X
) COMMA.
{A
= X
;}
376 sclp
(A
) ::= .
{A
= 0;}
377 selcollist
(A
) ::= sclp
(P
) expr
(X
) as
(Y
).
{
378 A
= sqlite3ExprListAppend
(P
,X
,Y.n?
&Y
:0);
380 selcollist
(A
) ::= sclp
(P
) STAR.
{
381 A
= sqlite3ExprListAppend
(P
, sqlite3Expr
(TK_ALL
, 0, 0, 0), 0);
383 selcollist
(A
) ::= sclp
(P
) nm
(X
) DOT STAR.
{
384 Expr
*pRight
= sqlite3Expr
(TK_ALL
, 0, 0, 0);
385 Expr
*pLeft
= sqlite3Expr
(TK_ID
, 0, 0, &X
);
386 A
= sqlite3ExprListAppend
(P
, sqlite3Expr
(TK_DOT
, pLeft
, pRight
, 0), 0);
389 // An option "AS <id>" phrase that can follow one of the expressions that
390 // define the result set, or one of the tables in the FROM clause.
393 as
(X
) ::= AS nm
(Y
).
{X
= Y
;}
394 as
(X
) ::= ids
(Y
).
{X
= Y
;}
395 as
(X
) ::= .
{X.n
= 0;}
398 %type seltablist
{SrcList
*}
399 %destructor seltablist
{sqlite3SrcListDelete
($$
);}
400 %type stl_prefix
{SrcList
*}
401 %destructor stl_prefix
{sqlite3SrcListDelete
($$
);}
402 %type from
{SrcList
*}
403 %destructor from
{sqlite3SrcListDelete
($$
);}
405 // A complete FROM clause.
407 from
(A
) ::= .
{A
= sqliteMalloc
(sizeof
(*A
));}
408 from
(A
) ::= FROM seltablist
(X
).
{A
= X
;}
410 // "seltablist" is a "Select Table List" - the content of the FROM clause
411 // in a SELECT statement. "stl_prefix" is a prefix of this list.
413 stl_prefix
(A
) ::= seltablist
(X
) joinop
(Y
).
{
415 if
( A
&& A
->nSrc
>0 ) A
->a
[A
->nSrc
-1].jointype
= Y
;
417 stl_prefix
(A
) ::= .
{A
= 0;}
418 seltablist
(A
) ::= stl_prefix
(X
) nm
(Y
) dbnm
(D
) as
(Z
) on_opt
(N
) using_opt
(U
).
{
419 A
= sqlite3SrcListAppend
(X
,&Y
,&D
);
420 if
( Z.n
) sqlite3SrcListAddAlias
(A
,&Z
);
422 if
( A
&& A
->nSrc
>1 ){ A
->a
[A
->nSrc
-2].pOn
= N
; }
423 else
{ sqlite3ExprDelete
(N
); }
426 if
( A
&& A
->nSrc
>1 ){ A
->a
[A
->nSrc
-2].pUsing
= U
; }
427 else
{ sqlite3IdListDelete
(U
); }
430 %ifndef SQLITE_OMIT_SUBQUERY
431 seltablist
(A
) ::= stl_prefix
(X
) LP seltablist_paren
(S
) RP
432 as
(Z
) on_opt
(N
) using_opt
(U
).
{
433 A
= sqlite3SrcListAppend
(X
,0,0);
434 A
->a
[A
->nSrc
-1].pSelect
= S
;
435 if
( Z.n
) sqlite3SrcListAddAlias
(A
,&Z
);
437 if
( A
&& A
->nSrc
>1 ){ A
->a
[A
->nSrc
-2].pOn
= N
; }
438 else
{ sqlite3ExprDelete
(N
); }
441 if
( A
&& A
->nSrc
>1 ){ A
->a
[A
->nSrc
-2].pUsing
= U
; }
442 else
{ sqlite3IdListDelete
(U
); }
446 // A seltablist_paren nonterminal represents anything in a FROM that
447 // is contained inside parentheses. This can be either a subquery or
448 // a grouping of table and subqueries.
450 %type seltablist_paren
{Select
*}
451 %destructor seltablist_paren
{sqlite3SelectDelete
($$
);}
452 seltablist_paren
(A
) ::= select
(S
).
{A
= S
;}
453 seltablist_paren
(A
) ::= seltablist
(F
).
{
454 A
= sqlite3SelectNew
(0,F
,0,0,0,0,0,0,0);
456 %endif
// SQLITE_OMIT_SUBQUERY
459 dbnm
(A
) ::= .
{A.z
=0; A.n
=0;}
460 dbnm
(A
) ::= DOT nm
(X
).
{A
= X
;}
462 %type fullname
{SrcList
*}
463 %destructor fullname
{sqlite3SrcListDelete
($$
);}
464 fullname
(A
) ::= nm
(X
) dbnm
(Y
).
{A
= sqlite3SrcListAppend
(0,&X
,&Y
);}
468 joinop
(X
) ::= COMMA.
{ X
= JT_INNER
; }
469 joinop
(X
) ::= JOIN.
{ X
= JT_INNER
; }
470 joinop
(X
) ::= JOIN_KW
(A
) JOIN.
{ X
= sqlite3JoinType
(pParse
,&A
,0,0); }
471 joinop
(X
) ::= JOIN_KW
(A
) nm
(B
) JOIN.
{ X
= sqlite3JoinType
(pParse
,&A
,&B
,0); }
472 joinop
(X
) ::= JOIN_KW
(A
) nm
(B
) nm
(C
) JOIN.
473 { X
= sqlite3JoinType
(pParse
,&A
,&B
,&C
); }
476 %destructor on_opt
{sqlite3ExprDelete
($$
);}
477 on_opt
(N
) ::= ON expr
(E
).
{N
= E
;}
478 on_opt
(N
) ::= .
{N
= 0;}
480 %type using_opt
{IdList
*}
481 %destructor using_opt
{sqlite3IdListDelete
($$
);}
482 using_opt
(U
) ::= USING LP inscollist
(L
) RP.
{U
= L
;}
483 using_opt
(U
) ::= .
{U
= 0;}
486 %type orderby_opt
{ExprList
*}
487 %destructor orderby_opt
{sqlite3ExprListDelete
($$
);}
488 %type sortlist
{ExprList
*}
489 %destructor sortlist
{sqlite3ExprListDelete
($$
);}
490 %type sortitem
{Expr
*}
491 %destructor sortitem
{sqlite3ExprDelete
($$
);}
493 orderby_opt
(A
) ::= .
{A
= 0;}
494 orderby_opt
(A
) ::= ORDER BY sortlist
(X
).
{A
= X
;}
495 sortlist
(A
) ::= sortlist
(X
) COMMA sortitem
(Y
) collate
(C
) sortorder
(Z
).
{
496 A
= sqlite3ExprListAppend
(X
,Y
,C.n
>0?
&C
:0);
497 if
( A
) A
->a
[A
->nExpr
-1].sortOrder
= Z
;
499 sortlist
(A
) ::= sortitem
(Y
) collate
(C
) sortorder
(Z
).
{
500 A
= sqlite3ExprListAppend
(0,Y
,C.n
>0?
&C
:0);
501 if
( A
&& A
->a
) A
->a
[0].sortOrder
= Z
;
503 sortitem
(A
) ::= expr
(X
).
{A
= X
;}
505 %type sortorder
{int}
506 %type collate
{Token
}
508 sortorder
(A
) ::= ASC.
{A
= SQLITE_SO_ASC
;}
509 sortorder
(A
) ::= DESC.
{A
= SQLITE_SO_DESC
;}
510 sortorder
(A
) ::= .
{A
= SQLITE_SO_ASC
;}
511 collate
(C
) ::= .
{C.z
= 0; C.n
= 0;}
512 collate
(C
) ::= COLLATE id
(X
).
{C
= X
;}
514 %type groupby_opt
{ExprList
*}
515 %destructor groupby_opt
{sqlite3ExprListDelete
($$
);}
516 groupby_opt
(A
) ::= .
{A
= 0;}
517 groupby_opt
(A
) ::= GROUP BY exprlist
(X
).
{A
= X
;}
519 %type having_opt
{Expr
*}
520 %destructor having_opt
{sqlite3ExprDelete
($$
);}
521 having_opt
(A
) ::= .
{A
= 0;}
522 having_opt
(A
) ::= HAVING expr
(X
).
{A
= X
;}
524 %type limit_opt
{struct LimitVal
}
525 %destructor limit_opt
{
526 sqlite3ExprDelete
($$.pLimit
);
527 sqlite3ExprDelete
($$.pOffset
);
529 limit_opt
(A
) ::= .
{A.pLimit
= 0; A.pOffset
= 0;}
530 limit_opt
(A
) ::= LIMIT expr
(X
).
{A.pLimit
= X
; A.pOffset
= 0;}
531 limit_opt
(A
) ::= LIMIT expr
(X
) OFFSET expr
(Y
).
532 {A.pLimit
= X
; A.pOffset
= Y
;}
533 limit_opt
(A
) ::= LIMIT expr
(X
) COMMA expr
(Y
).
534 {A.pOffset
= X
; A.pLimit
= Y
;}
536 /////////////////////////// The DELETE statement /////////////////////////////
538 cmd
::= DELETE FROM fullname
(X
) where_opt
(Y
).
{sqlite3DeleteFrom
(pParse
,X
,Y
);}
540 %type where_opt
{Expr
*}
541 %destructor where_opt
{sqlite3ExprDelete
($$
);}
543 where_opt
(A
) ::= .
{A
= 0;}
544 where_opt
(A
) ::= WHERE expr
(X
).
{A
= X
;}
546 ////////////////////////// The UPDATE command ////////////////////////////////
548 cmd
::= UPDATE orconf
(R
) fullname
(X
) SET setlist
(Y
) where_opt
(Z
).
549 {sqlite3Update
(pParse
,X
,Y
,Z
,R
);}
551 %type setlist
{ExprList
*}
552 %destructor setlist
{sqlite3ExprListDelete
($$
);}
554 setlist
(A
) ::= setlist
(Z
) COMMA nm
(X
) EQ expr
(Y
).
555 {A
= sqlite3ExprListAppend
(Z
,Y
,&X
);}
556 setlist
(A
) ::= nm
(X
) EQ expr
(Y
).
{A
= sqlite3ExprListAppend
(0,Y
,&X
);}
558 ////////////////////////// The INSERT command /////////////////////////////////
560 cmd
::= insert_cmd
(R
) INTO fullname
(X
) inscollist_opt
(F
)
561 VALUES LP itemlist
(Y
) RP.
562 {sqlite3Insert
(pParse
, X
, Y
, 0, F
, R
);}
563 cmd
::= insert_cmd
(R
) INTO fullname
(X
) inscollist_opt
(F
) select
(S
).
564 {sqlite3Insert
(pParse
, X
, 0, S
, F
, R
);}
566 %type insert_cmd
{int}
567 insert_cmd
(A
) ::= INSERT orconf
(R
).
{A
= R
;}
568 insert_cmd
(A
) ::= REPLACE.
{A
= OE_Replace
;}
571 %type itemlist
{ExprList
*}
572 %destructor itemlist
{sqlite3ExprListDelete
($$
);}
574 itemlist
(A
) ::= itemlist
(X
) COMMA expr
(Y
).
{A
= sqlite3ExprListAppend
(X
,Y
,0);}
575 itemlist
(A
) ::= expr
(X
).
{A
= sqlite3ExprListAppend
(0,X
,0);}
577 %type inscollist_opt
{IdList
*}
578 %destructor inscollist_opt
{sqlite3IdListDelete
($$
);}
579 %type inscollist
{IdList
*}
580 %destructor inscollist
{sqlite3IdListDelete
($$
);}
582 inscollist_opt
(A
) ::= .
{A
= 0;}
583 inscollist_opt
(A
) ::= LP inscollist
(X
) RP.
{A
= X
;}
584 inscollist
(A
) ::= inscollist
(X
) COMMA nm
(Y
).
{A
= sqlite3IdListAppend
(X
,&Y
);}
585 inscollist
(A
) ::= nm
(Y
).
{A
= sqlite3IdListAppend
(0,&Y
);}
587 /////////////////////////// Expression Processing /////////////////////////////
591 %destructor expr
{sqlite3ExprDelete
($$
);}
593 %destructor term
{sqlite3ExprDelete
($$
);}
595 expr
(A
) ::= term
(X
).
{A
= X
;}
596 expr
(A
) ::= LP
(B
) expr
(X
) RP
(E
).
{A
= X
; sqlite3ExprSpan
(A
,&B
,&E
); }
597 term
(A
) ::= NULL
(X
).
{A
= sqlite3Expr
(@X
, 0, 0, &X
);}
598 expr
(A
) ::= ID
(X
).
{A
= sqlite3Expr
(TK_ID
, 0, 0, &X
);}
599 expr
(A
) ::= JOIN_KW
(X
).
{A
= sqlite3Expr
(TK_ID
, 0, 0, &X
);}
600 expr
(A
) ::= nm
(X
) DOT nm
(Y
).
{
601 Expr
*temp1
= sqlite3Expr
(TK_ID
, 0, 0, &X
);
602 Expr
*temp2
= sqlite3Expr
(TK_ID
, 0, 0, &Y
);
603 A
= sqlite3Expr
(TK_DOT
, temp1
, temp2
, 0);
605 expr
(A
) ::= nm
(X
) DOT nm
(Y
) DOT nm
(Z
).
{
606 Expr
*temp1
= sqlite3Expr
(TK_ID
, 0, 0, &X
);
607 Expr
*temp2
= sqlite3Expr
(TK_ID
, 0, 0, &Y
);
608 Expr
*temp3
= sqlite3Expr
(TK_ID
, 0, 0, &Z
);
609 Expr
*temp4
= sqlite3Expr
(TK_DOT
, temp2
, temp3
, 0);
610 A
= sqlite3Expr
(TK_DOT
, temp1
, temp4
, 0);
612 term
(A
) ::= INTEGER
(X
).
{A
= sqlite3Expr
(@X
, 0, 0, &X
);}
613 term
(A
) ::= FLOAT
(X
).
{A
= sqlite3Expr
(@X
, 0, 0, &X
);}
614 term
(A
) ::= STRING
(X
).
{A
= sqlite3Expr
(@X
, 0, 0, &X
);}
615 term
(A
) ::= BLOB
(X
).
{A
= sqlite3Expr
(@X
, 0, 0, &X
);}
616 expr
(A
) ::= REGISTER
(X
).
{A
= sqlite3RegisterExpr
(pParse
, &X
);}
617 expr
(A
) ::= VARIABLE
(X
).
{
619 Expr
*pExpr
= A
= sqlite3Expr
(TK_VARIABLE
, 0, 0, pToken
);
620 sqlite3ExprAssignVarNumber
(pParse
, pExpr
);
622 expr
(A
) ::= ID
(X
) LP exprlist
(Y
) RP
(E
).
{
623 A
= sqlite3ExprFunction
(Y
, &X
);
624 sqlite3ExprSpan
(A
,&X
,&E
);
626 expr
(A
) ::= ID
(X
) LP STAR RP
(E
).
{
627 A
= sqlite3ExprFunction
(0, &X
);
628 sqlite3ExprSpan
(A
,&X
,&E
);
630 term
(A
) ::= CTIME_KW
(OP
).
{
631 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are
632 ** treated as functions that return constants */
633 A
= sqlite3ExprFunction
(0,&OP
);
634 if
( A
) A
->op
= TK_CONST_FUNC
;
636 expr
(A
) ::= expr
(X
) AND
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
637 expr
(A
) ::= expr
(X
) OR
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
638 expr
(A
) ::= expr
(X
) LT
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
639 expr
(A
) ::= expr
(X
) GT
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
640 expr
(A
) ::= expr
(X
) LE
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
641 expr
(A
) ::= expr
(X
) GE
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
642 expr
(A
) ::= expr
(X
) NE
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
643 expr
(A
) ::= expr
(X
) EQ
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
644 expr
(A
) ::= expr
(X
) BITAND
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
645 expr
(A
) ::= expr
(X
) BITOR
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
646 expr
(A
) ::= expr
(X
) LSHIFT
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
647 expr
(A
) ::= expr
(X
) RSHIFT
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
648 expr
(A
) ::= expr
(X
) PLUS
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
649 expr
(A
) ::= expr
(X
) MINUS
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
650 expr
(A
) ::= expr
(X
) STAR
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
651 expr
(A
) ::= expr
(X
) SLASH
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
652 expr
(A
) ::= expr
(X
) REM
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
653 expr
(A
) ::= expr
(X
) CONCAT
(OP
) expr
(Y
).
{A
= sqlite3Expr
(@OP
, X
, Y
, 0);}
654 %type likeop
{struct LikeOp
}
655 likeop
(A
) ::= LIKE_KW
(X
).
{A.operator
= X
; A.not
= 0;}
656 likeop
(A
) ::= NOT LIKE_KW
(X
).
{A.operator
= X
; A.not
= 1;}
658 escape
(X
) ::= ESCAPE expr
(A
).
[ESCAPE
] {X
= A
;}
659 escape
(X
) ::= .
[ESCAPE
] {X
= 0;}
660 expr
(A
) ::= expr
(X
) likeop
(OP
) expr
(Y
) escape
(E
).
[LIKE_KW
] {
661 ExprList
*pList
= sqlite3ExprListAppend
(0, Y
, 0);
662 pList
= sqlite3ExprListAppend
(pList
, X
, 0);
664 pList
= sqlite3ExprListAppend
(pList
, E
, 0);
666 A
= sqlite3ExprFunction
(pList
, &OP.operator
);
667 if
( OP.not
) A
= sqlite3Expr
(TK_NOT
, A
, 0, 0);
668 sqlite3ExprSpan
(A
, &X
->span
, &Y
->span
);
671 expr
(A
) ::= expr
(X
) ISNULL
(E
).
{
672 A
= sqlite3Expr
(TK_ISNULL
, X
, 0, 0);
673 sqlite3ExprSpan
(A
,&X
->span
,&E
);
675 expr
(A
) ::= expr
(X
) IS NULL
(E
).
{
676 A
= sqlite3Expr
(TK_ISNULL
, X
, 0, 0);
677 sqlite3ExprSpan
(A
,&X
->span
,&E
);
679 expr
(A
) ::= expr
(X
) NOTNULL
(E
).
{
680 A
= sqlite3Expr
(TK_NOTNULL
, X
, 0, 0);
681 sqlite3ExprSpan
(A
,&X
->span
,&E
);
683 expr
(A
) ::= expr
(X
) NOT NULL
(E
).
{
684 A
= sqlite3Expr
(TK_NOTNULL
, X
, 0, 0);
685 sqlite3ExprSpan
(A
,&X
->span
,&E
);
687 expr
(A
) ::= expr
(X
) IS NOT NULL
(E
).
{
688 A
= sqlite3Expr
(TK_NOTNULL
, X
, 0, 0);
689 sqlite3ExprSpan
(A
,&X
->span
,&E
);
691 expr
(A
) ::= NOT
(B
) expr
(X
).
{
692 A
= sqlite3Expr
(@B
, X
, 0, 0);
693 sqlite3ExprSpan
(A
,&B
,&X
->span
);
695 expr
(A
) ::= BITNOT
(B
) expr
(X
).
{
696 A
= sqlite3Expr
(@B
, X
, 0, 0);
697 sqlite3ExprSpan
(A
,&B
,&X
->span
);
699 expr
(A
) ::= MINUS
(B
) expr
(X
).
[UMINUS
] {
700 A
= sqlite3Expr
(TK_UMINUS
, X
, 0, 0);
701 sqlite3ExprSpan
(A
,&B
,&X
->span
);
703 expr
(A
) ::= PLUS
(B
) expr
(X
).
[UPLUS
] {
704 A
= sqlite3Expr
(TK_UPLUS
, X
, 0, 0);
705 sqlite3ExprSpan
(A
,&B
,&X
->span
);
707 %type between_op
{int}
708 between_op
(A
) ::= BETWEEN.
{A
= 0;}
709 between_op
(A
) ::= NOT BETWEEN.
{A
= 1;}
710 expr
(A
) ::= expr
(W
) between_op
(N
) expr
(X
) AND expr
(Y
).
[BETWEEN
] {
711 ExprList
*pList
= sqlite3ExprListAppend
(0, X
, 0);
712 pList
= sqlite3ExprListAppend
(pList
, Y
, 0);
713 A
= sqlite3Expr
(TK_BETWEEN
, W
, 0, 0);
714 if
( A
) A
->pList
= pList
;
715 if
( N
) A
= sqlite3Expr
(TK_NOT
, A
, 0, 0);
716 sqlite3ExprSpan
(A
,&W
->span
,&Y
->span
);
718 %ifndef SQLITE_OMIT_SUBQUERY
720 in_op
(A
) ::= IN.
{A
= 0;}
721 in_op
(A
) ::= NOT IN.
{A
= 1;}
722 expr
(A
) ::= expr
(X
) in_op
(N
) LP exprlist
(Y
) RP
(E
).
[IN
] {
723 A
= sqlite3Expr
(TK_IN
, X
, 0, 0);
727 sqlite3ExprListDelete
(Y
);
729 if
( N
) A
= sqlite3Expr
(TK_NOT
, A
, 0, 0);
730 sqlite3ExprSpan
(A
,&X
->span
,&E
);
732 expr
(A
) ::= LP
(B
) select
(X
) RP
(E
).
{
733 A
= sqlite3Expr
(TK_SELECT
, 0, 0, 0);
734 if
( A
) A
->pSelect
= X
;
735 if
( !A
) sqlite3SelectDelete
(X
);
736 sqlite3ExprSpan
(A
,&B
,&E
);
738 expr
(A
) ::= expr
(X
) in_op
(N
) LP select
(Y
) RP
(E
).
[IN
] {
739 A
= sqlite3Expr
(TK_IN
, X
, 0, 0);
740 if
( A
) A
->pSelect
= Y
;
741 if
( !A
) sqlite3SelectDelete
(Y
);
742 if
( N
) A
= sqlite3Expr
(TK_NOT
, A
, 0, 0);
743 sqlite3ExprSpan
(A
,&X
->span
,&E
);
745 expr
(A
) ::= expr
(X
) in_op
(N
) nm
(Y
) dbnm
(Z
).
[IN
] {
746 SrcList
*pSrc
= sqlite3SrcListAppend
(0,&Y
,&Z
);
747 A
= sqlite3Expr
(TK_IN
, X
, 0, 0);
748 if
( A
) A
->pSelect
= sqlite3SelectNew
(0,pSrc
,0,0,0,0,0,0,0);
749 if
( N
) A
= sqlite3Expr
(TK_NOT
, A
, 0, 0);
750 sqlite3ExprSpan
(A
,&X
->span
,Z.z?
&Z
:&Y
);
752 expr
(A
) ::= EXISTS
(B
) LP select
(Y
) RP
(E
).
{
753 Expr
*p
= A
= sqlite3Expr
(TK_EXISTS
, 0, 0, 0);
756 sqlite3ExprSpan
(p
,&B
,&E
);
758 if
( !p
) sqlite3SelectDelete
(Y
);
760 %endif
// SQLITE_OMIT_SUBQUERY
762 /* CASE expressions */
763 expr
(A
) ::= CASE
(C
) case_operand
(X
) case_exprlist
(Y
) case_else
(Z
) END
(E
).
{
764 A
= sqlite3Expr
(TK_CASE
, X
, Z
, 0);
765 if
( A
) A
->pList
= Y
;
766 sqlite3ExprSpan
(A
, &C
, &E
);
768 %type case_exprlist
{ExprList
*}
769 %destructor case_exprlist
{sqlite3ExprListDelete
($$
);}
770 case_exprlist
(A
) ::= case_exprlist
(X
) WHEN expr
(Y
) THEN expr
(Z
).
{
771 A
= sqlite3ExprListAppend
(X
, Y
, 0);
772 A
= sqlite3ExprListAppend
(A
, Z
, 0);
774 case_exprlist
(A
) ::= WHEN expr
(Y
) THEN expr
(Z
).
{
775 A
= sqlite3ExprListAppend
(0, Y
, 0);
776 A
= sqlite3ExprListAppend
(A
, Z
, 0);
778 %type case_else
{Expr
*}
779 case_else
(A
) ::= ELSE expr
(X
).
{A
= X
;}
780 case_else
(A
) ::= .
{A
= 0;}
781 %type case_operand
{Expr
*}
782 case_operand
(A
) ::= expr
(X
).
{A
= X
;}
783 case_operand
(A
) ::= .
{A
= 0;}
785 %type exprlist
{ExprList
*}
786 %destructor exprlist
{sqlite3ExprListDelete
($$
);}
787 %type expritem
{Expr
*}
788 %destructor expritem
{sqlite3ExprDelete
($$
);}
790 exprlist
(A
) ::= exprlist
(X
) COMMA expritem
(Y
).
791 {A
= sqlite3ExprListAppend
(X
,Y
,0);}
792 exprlist
(A
) ::= expritem
(X
).
{A
= sqlite3ExprListAppend
(0,X
,0);}
793 expritem
(A
) ::= expr
(X
).
{A
= X
;}
794 expritem
(A
) ::= .
{A
= 0;}
796 ///////////////////////////// The CREATE INDEX command ///////////////////////
798 cmd
::= CREATE
(S
) uniqueflag
(U
) INDEX nm
(X
) dbnm
(D
)
799 ON nm
(Y
) LP idxlist
(Z
) RP
(E
) onconf
(R
).
{
800 if
( U
!=OE_None
) U
= R
;
801 if
( U
==OE_Default
) U
= OE_Abort
;
802 sqlite3CreateIndex
(pParse
, &X
, &D
, sqlite3SrcListAppend
(0,&Y
,0),Z
,U
, &S
, &E
);
805 %type uniqueflag
{int}
806 uniqueflag
(A
) ::= UNIQUE.
{A
= OE_Abort
;}
807 uniqueflag
(A
) ::= .
{A
= OE_None
;}
809 %type idxlist
{ExprList
*}
810 %destructor idxlist
{sqlite3ExprListDelete
($$
);}
811 %type idxlist_opt
{ExprList
*}
812 %destructor idxlist_opt
{sqlite3ExprListDelete
($$
);}
813 %type idxitem
{Token
}
815 idxlist_opt
(A
) ::= .
{A
= 0;}
816 idxlist_opt
(A
) ::= LP idxlist
(X
) RP.
{A
= X
;}
817 idxlist
(A
) ::= idxlist
(X
) COMMA idxitem
(Y
) collate
(C
) sortorder.
{
820 p
= sqlite3Expr
(TK_COLUMN
, 0, 0, 0);
821 if
( p
) p
->pColl
= sqlite3LocateCollSeq
(pParse
, C.z
, C.n
);
823 A
= sqlite3ExprListAppend
(X
, p
, &Y
);
825 idxlist
(A
) ::= idxitem
(Y
) collate
(C
) sortorder.
{
828 p
= sqlite3Expr
(TK_COLUMN
, 0, 0, 0);
829 if
( p
) p
->pColl
= sqlite3LocateCollSeq
(pParse
, C.z
, C.n
);
831 A
= sqlite3ExprListAppend
(0, p
, &Y
);
833 idxitem
(A
) ::= nm
(X
).
{A
= X
;}
836 ///////////////////////////// The DROP INDEX command /////////////////////////
838 cmd
::= DROP INDEX fullname
(X
).
{sqlite3DropIndex
(pParse
, X
);}
840 ///////////////////////////// The VACUUM command /////////////////////////////
842 cmd
::= VACUUM.
{sqlite3Vacuum
(pParse
,0);}
843 cmd
::= VACUUM nm.
{sqlite3Vacuum
(pParse
,0);}
845 ///////////////////////////// The PRAGMA command /////////////////////////////
847 %ifndef SQLITE_OMIT_PRAGMA
848 cmd
::= PRAGMA nm
(X
) dbnm
(Z
) EQ nm
(Y
).
{sqlite3Pragma
(pParse
,&X
,&Z
,&Y
,0);}
849 cmd
::= PRAGMA nm
(X
) dbnm
(Z
) EQ ON
(Y
).
{sqlite3Pragma
(pParse
,&X
,&Z
,&Y
,0);}
850 cmd
::= PRAGMA nm
(X
) dbnm
(Z
) EQ plus_num
(Y
).
{sqlite3Pragma
(pParse
,&X
,&Z
,&Y
,0);}
851 cmd
::= PRAGMA nm
(X
) dbnm
(Z
) EQ minus_num
(Y
).
{
852 sqlite3Pragma
(pParse
,&X
,&Z
,&Y
,1);
854 cmd
::= PRAGMA nm
(X
) dbnm
(Z
) LP nm
(Y
) RP.
{sqlite3Pragma
(pParse
,&X
,&Z
,&Y
,0);}
855 cmd
::= PRAGMA nm
(X
) dbnm
(Z
).
{sqlite3Pragma
(pParse
,&X
,&Z
,0,0);}
856 %endif
// SQLITE_OMIT_PRAGMA
857 plus_num
(A
) ::= plus_opt number
(X
).
{A
= X
;}
858 minus_num
(A
) ::= MINUS number
(X
).
{A
= X
;}
859 number
(A
) ::= INTEGER
(X
).
{A
= X
;}
860 number
(A
) ::= FLOAT
(X
).
{A
= X
;}
864 //////////////////////////// The CREATE TRIGGER command /////////////////////
866 %ifndef SQLITE_OMIT_TRIGGER
868 cmd
::= CREATE trigger_decl
(A
) BEGIN trigger_cmd_list
(S
) END
(Z
).
{
871 all.n
= (Z.z
- A.z
) + Z.n
;
872 sqlite3FinishTrigger
(pParse
, S
, &all
);
875 trigger_decl
(A
) ::= temp
(T
) TRIGGER nm
(B
) dbnm
(Z
) trigger_time
(C
)
877 ON fullname
(E
) foreach_clause
(F
) when_clause
(G
).
{
878 sqlite3BeginTrigger
(pParse
, &B
, &Z
, C
, D.a
, D.b
, E
, F
, G
, T
);
882 %type trigger_time
{int}
883 trigger_time
(A
) ::= BEFORE.
{ A
= TK_BEFORE
; }
884 trigger_time
(A
) ::= AFTER.
{ A
= TK_AFTER
; }
885 trigger_time
(A
) ::= INSTEAD OF.
{ A
= TK_INSTEAD
;}
886 trigger_time
(A
) ::= .
{ A
= TK_BEFORE
; }
888 %type trigger_event
{struct TrigEvent
}
889 %destructor trigger_event
{sqlite3IdListDelete
($$.b
);}
890 trigger_event
(A
) ::= DELETE
(OP
).
{A.a
= @OP
; A.b
= 0;}
891 trigger_event
(A
) ::= INSERT
(OP
).
{A.a
= @OP
; A.b
= 0;}
892 trigger_event
(A
) ::= UPDATE
(OP
).
{A.a
= @OP
; A.b
= 0;}
893 trigger_event
(A
) ::= UPDATE OF inscollist
(X
).
{A.a
= TK_UPDATE
; A.b
= X
;}
895 %type foreach_clause
{int}
896 foreach_clause
(A
) ::= .
{ A
= TK_ROW
; }
897 foreach_clause
(A
) ::= FOR EACH ROW.
{ A
= TK_ROW
; }
898 foreach_clause
(A
) ::= FOR EACH STATEMENT.
{ A
= TK_STATEMENT
; }
900 %type when_clause
{Expr
*}
901 when_clause
(A
) ::= .
{ A
= 0; }
902 when_clause
(A
) ::= WHEN expr
(X
).
{ A
= X
; }
904 %type trigger_cmd_list
{TriggerStep
*}
905 %destructor trigger_cmd_list
{sqlite3DeleteTriggerStep
($$
);}
906 trigger_cmd_list
(A
) ::= trigger_cmd
(X
) SEMI trigger_cmd_list
(Y
).
{
910 trigger_cmd_list
(A
) ::= .
{ A
= 0; }
912 %type trigger_cmd
{TriggerStep
*}
913 %destructor trigger_cmd
{sqlite3DeleteTriggerStep
($$
);}
915 trigger_cmd
(A
) ::= UPDATE orconf
(R
) nm
(X
) SET setlist
(Y
) where_opt
(Z
).
916 { A
= sqlite3TriggerUpdateStep
(&X
, Y
, Z
, R
); }
919 trigger_cmd
(A
) ::= insert_cmd
(R
) INTO nm
(X
) inscollist_opt
(F
)
920 VALUES LP itemlist
(Y
) RP.
921 {A
= sqlite3TriggerInsertStep
(&X
, F
, Y
, 0, R
);}
923 trigger_cmd
(A
) ::= insert_cmd
(R
) INTO nm
(X
) inscollist_opt
(F
) select
(S
).
924 {A
= sqlite3TriggerInsertStep
(&X
, F
, 0, S
, R
);}
927 trigger_cmd
(A
) ::= DELETE FROM nm
(X
) where_opt
(Y
).
928 {A
= sqlite3TriggerDeleteStep
(&X
, Y
);}
931 trigger_cmd
(A
) ::= select
(X
).
{A
= sqlite3TriggerSelectStep
(X
); }
933 // The special RAISE expression that may occur in trigger programs
934 expr
(A
) ::= RAISE
(X
) LP IGNORE RP
(Y
).
{
935 A
= sqlite3Expr
(TK_RAISE
, 0, 0, 0);
936 A
->iColumn
= OE_Ignore
;
937 sqlite3ExprSpan
(A
, &X
, &Y
);
939 expr
(A
) ::= RAISE
(X
) LP raisetype
(T
) COMMA nm
(Z
) RP
(Y
).
{
940 A
= sqlite3Expr
(TK_RAISE
, 0, 0, &Z
);
942 sqlite3ExprSpan
(A
, &X
, &Y
);
944 %endif
// !SQLITE_OMIT_TRIGGER
946 %type raisetype
{int}
947 raisetype
(A
) ::= ROLLBACK.
{A
= OE_Rollback
;}
948 raisetype
(A
) ::= ABORT.
{A
= OE_Abort
;}
949 raisetype
(A
) ::= FAIL.
{A
= OE_Fail
;}
952 //////////////////////// DROP TRIGGER statement //////////////////////////////
953 %ifndef SQLITE_OMIT_TRIGGER
954 cmd
::= DROP TRIGGER fullname
(X
).
{
955 sqlite3DropTrigger
(pParse
,X
);
957 %endif
// !SQLITE_OMIT_TRIGGER
959 //////////////////////// ATTACH DATABASE file AS name /////////////////////////
960 cmd
::= ATTACH database_kw_opt ids
(F
) AS nm
(D
) key_opt
(K
).
{
961 sqlite3Attach
(pParse
, &F
, &D
, K.type
, &K.key
);
963 %type key_opt
{struct AttachKey
}
964 key_opt
(A
) ::= .
{ A.type
= 0; }
965 key_opt
(A
) ::= KEY ids
(X
).
{ A.type
=1; A.key
= X
; }
966 key_opt
(A
) ::= KEY BLOB
(X
).
{ A.type
=2; A.key
= X
; }
968 database_kw_opt
::= DATABASE.
969 database_kw_opt
::= .
971 //////////////////////// DETACH DATABASE name /////////////////////////////////
972 cmd
::= DETACH database_kw_opt nm
(D
).
{
973 sqlite3Detach
(pParse
, &D
);
976 ////////////////////////// REINDEX collation //////////////////////////////////
977 %ifndef SQLITE_OMIT_REINDEX
978 cmd
::= REINDEX.
{sqlite3Reindex
(pParse
, 0, 0);}
979 cmd
::= REINDEX nm
(X
) dbnm
(Y
).
{sqlite3Reindex
(pParse
, &X
, &Y
);}
982 //////////////////////// ALTER TABLE table ... ////////////////////////////////
983 %ifndef SQLITE_OMIT_ALTERTABLE
984 cmd
::= ALTER TABLE fullname
(X
) RENAME TO nm
(Z
).
{
985 sqlite3AlterRenameTable
(pParse
,X
,&Z
);
987 cmd
::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column
(Y
).
{
988 sqlite3AlterFinishAddColumn
(pParse
, &Y
);
990 add_column_fullname
::= fullname
(X
).
{
991 sqlite3AlterBeginAddColumn
(pParse
, X
);
994 kwcolumn_opt
::= COLUMNKW.