Mercurial > audlegacy
comparison sqlite/parse.y @ 1434:b6b61becdf4e trunk
[svn] - add sqlite/ directory
| author | nenolod |
|---|---|
| date | Thu, 27 Jul 2006 22:41:31 -0700 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1433:3cbe3d14ea68 | 1434:b6b61becdf4e |
|---|---|
| 1 /* | |
| 2 ** 2001 September 15 | |
| 3 ** | |
| 4 ** The author disclaims copyright to this source code. In place of | |
| 5 ** a legal notice, here is a blessing: | |
| 6 ** | |
| 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. | |
| 10 ** | |
| 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 ** | |
| 17 ** @(#) $Id: parse.y,v 1.200 2006/05/25 12:17:31 drh Exp $ | |
| 18 */ | |
| 19 | |
| 20 // All token codes are small integers with #defines that begin with "TK_" | |
| 21 %token_prefix TK_ | |
| 22 | |
| 23 // The type of the data attached to each token is Token. This is also the | |
| 24 // default type for non-terminals. | |
| 25 // | |
| 26 %token_type {Token} | |
| 27 %default_type {Token} | |
| 28 | |
| 29 // The generated parser function takes a 4th argument as follows: | |
| 30 %extra_argument {Parse *pParse} | |
| 31 | |
| 32 // This code runs whenever there is a syntax error | |
| 33 // | |
| 34 %syntax_error { | |
| 35 if( !pParse->parseError ){ | |
| 36 if( TOKEN.z[0] ){ | |
| 37 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); | |
| 38 }else{ | |
| 39 sqlite3ErrorMsg(pParse, "incomplete SQL statement"); | |
| 40 } | |
| 41 pParse->parseError = 1; | |
| 42 } | |
| 43 } | |
| 44 %stack_overflow { | |
| 45 sqlite3ErrorMsg(pParse, "parser stack overflow"); | |
| 46 pParse->parseError = 1; | |
| 47 } | |
| 48 | |
| 49 // The name of the generated procedure that implements the parser | |
| 50 // is as follows: | |
| 51 %name sqlite3Parser | |
| 52 | |
| 53 // The following text is included near the beginning of the C source | |
| 54 // code file that implements the parser. | |
| 55 // | |
| 56 %include { | |
| 57 #include "sqliteInt.h" | |
| 58 #include "parse.h" | |
| 59 | |
| 60 /* | |
| 61 ** An instance of this structure holds information about the | |
| 62 ** LIMIT clause of a SELECT statement. | |
| 63 */ | |
| 64 struct LimitVal { | |
| 65 Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ | |
| 66 Expr *pOffset; /* The OFFSET expression. NULL if there is none */ | |
| 67 }; | |
| 68 | |
| 69 /* | |
| 70 ** An instance of this structure is used to store the LIKE, | |
| 71 ** GLOB, NOT LIKE, and NOT GLOB operators. | |
| 72 */ | |
| 73 struct LikeOp { | |
| 74 Token eOperator; /* "like" or "glob" or "regexp" */ | |
| 75 int not; /* True if the NOT keyword is present */ | |
| 76 }; | |
| 77 | |
| 78 /* | |
| 79 ** An instance of the following structure describes the event of a | |
| 80 ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, | |
| 81 ** TK_DELETE, or TK_INSTEAD. If the event is of the form | |
| 82 ** | |
| 83 ** UPDATE ON (a,b,c) | |
| 84 ** | |
| 85 ** Then the "b" IdList records the list "a,b,c". | |
| 86 */ | |
| 87 struct TrigEvent { int a; IdList * b; }; | |
| 88 | |
| 89 /* | |
| 90 ** An instance of this structure holds the ATTACH key and the key type. | |
| 91 */ | |
| 92 struct AttachKey { int type; Token key; }; | |
| 93 | |
| 94 } // end %include | |
| 95 | |
| 96 // Input is a single SQL command | |
| 97 input ::= cmdlist. | |
| 98 cmdlist ::= cmdlist ecmd. | |
| 99 cmdlist ::= ecmd. | |
| 100 cmdx ::= cmd. { sqlite3FinishCoding(pParse); } | |
| 101 ecmd ::= SEMI. | |
| 102 ecmd ::= explain cmdx SEMI. | |
| 103 explain ::= . { sqlite3BeginParse(pParse, 0); } | |
| 104 %ifndef SQLITE_OMIT_EXPLAIN | |
| 105 explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); } | |
| 106 explain ::= EXPLAIN QUERY PLAN. { sqlite3BeginParse(pParse, 2); } | |
| 107 %endif | |
| 108 | |
| 109 ///////////////////// Begin and end transactions. //////////////////////////// | |
| 110 // | |
| 111 | |
| 112 cmd ::= BEGIN transtype(Y) trans_opt. {sqlite3BeginTransaction(pParse, Y);} | |
| 113 trans_opt ::= . | |
| 114 trans_opt ::= TRANSACTION. | |
| 115 trans_opt ::= TRANSACTION nm. | |
| 116 %type transtype {int} | |
| 117 transtype(A) ::= . {A = TK_DEFERRED;} | |
| 118 transtype(A) ::= DEFERRED(X). {A = @X;} | |
| 119 transtype(A) ::= IMMEDIATE(X). {A = @X;} | |
| 120 transtype(A) ::= EXCLUSIVE(X). {A = @X;} | |
| 121 cmd ::= COMMIT trans_opt. {sqlite3CommitTransaction(pParse);} | |
| 122 cmd ::= END trans_opt. {sqlite3CommitTransaction(pParse);} | |
| 123 cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);} | |
| 124 | |
| 125 ///////////////////// The CREATE TABLE statement //////////////////////////// | |
| 126 // | |
| 127 cmd ::= create_table create_table_args. | |
| 128 create_table ::= CREATE temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). { | |
| 129 sqlite3StartTable(pParse,&Y,&Z,T,0,E); | |
| 130 } | |
| 131 %type ifnotexists {int} | |
| 132 ifnotexists(A) ::= . {A = 0;} | |
| 133 ifnotexists(A) ::= IF NOT EXISTS. {A = 1;} | |
| 134 %type temp {int} | |
| 135 %ifndef SQLITE_OMIT_TEMPDB | |
| 136 temp(A) ::= TEMP. {A = 1;} | |
| 137 %endif | |
| 138 temp(A) ::= . {A = 0;} | |
| 139 create_table_args ::= LP columnlist conslist_opt(X) RP(Y). { | |
| 140 sqlite3EndTable(pParse,&X,&Y,0); | |
| 141 } | |
| 142 create_table_args ::= AS select(S). { | |
| 143 sqlite3EndTable(pParse,0,0,S); | |
| 144 sqlite3SelectDelete(S); | |
| 145 } | |
| 146 columnlist ::= columnlist COMMA column. | |
| 147 columnlist ::= column. | |
| 148 | |
| 149 // A "column" is a complete description of a single column in a | |
| 150 // CREATE TABLE statement. This includes the column name, its | |
| 151 // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES, | |
| 152 // NOT NULL and so forth. | |
| 153 // | |
| 154 column(A) ::= columnid(X) type carglist. { | |
| 155 A.z = X.z; | |
| 156 A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n; | |
| 157 } | |
| 158 columnid(A) ::= nm(X). { | |
| 159 sqlite3AddColumn(pParse,&X); | |
| 160 A = X; | |
| 161 } | |
| 162 | |
| 163 | |
| 164 // An IDENTIFIER can be a generic identifier, or one of several | |
| 165 // keywords. Any non-standard keyword can also be an identifier. | |
| 166 // | |
| 167 %type id {Token} | |
| 168 id(A) ::= ID(X). {A = X;} | |
| 169 | |
| 170 // The following directive causes tokens ABORT, AFTER, ASC, etc. to | |
| 171 // fallback to ID if they will not parse as their original value. | |
| 172 // This obviates the need for the "id" nonterminal. | |
| 173 // | |
| 174 %fallback ID | |
| 175 ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT | |
| 176 DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR | |
| 177 IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH PLAN QUERY KEY | |
| 178 OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT | |
| 179 TEMP TRIGGER VACUUM VIEW | |
| 180 %ifdef SQLITE_OMIT_COMPOUND_SELECT | |
| 181 EXCEPT INTERSECT UNION | |
| 182 %endif | |
| 183 REINDEX RENAME CTIME_KW IF | |
| 184 . | |
| 185 | |
| 186 // Define operator precedence early so that this is the first occurance | |
| 187 // of the operator tokens in the grammer. Keeping the operators together | |
| 188 // causes them to be assigned integer values that are close together, | |
| 189 // which keeps parser tables smaller. | |
| 190 // | |
| 191 // The token values assigned to these symbols is determined by the order | |
| 192 // in which lemon first sees them. It must be the case that ISNULL/NOTNULL, | |
| 193 // NE/EQ, GT/LE, and GE/LT are separated by only a single value. See | |
| 194 // the sqlite3ExprIfFalse() routine for additional information on this | |
| 195 // constraint. | |
| 196 // | |
| 197 %left OR. | |
| 198 %left AND. | |
| 199 %right NOT. | |
| 200 %left IS LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ. | |
| 201 %left GT LE LT GE. | |
| 202 %right ESCAPE. | |
| 203 %left BITAND BITOR LSHIFT RSHIFT. | |
| 204 %left PLUS MINUS. | |
| 205 %left STAR SLASH REM. | |
| 206 %left CONCAT. | |
| 207 %right UMINUS UPLUS BITNOT. | |
| 208 | |
| 209 // And "ids" is an identifer-or-string. | |
| 210 // | |
| 211 %type ids {Token} | |
| 212 ids(A) ::= ID|STRING(X). {A = X;} | |
| 213 | |
| 214 // The name of a column or table can be any of the following: | |
| 215 // | |
| 216 %type nm {Token} | |
| 217 nm(A) ::= ID(X). {A = X;} | |
| 218 nm(A) ::= STRING(X). {A = X;} | |
| 219 nm(A) ::= JOIN_KW(X). {A = X;} | |
| 220 | |
| 221 // A typetoken is really one or more tokens that form a type name such | |
| 222 // as can be found after the column name in a CREATE TABLE statement. | |
| 223 // Multiple tokens are concatenated to form the value of the typetoken. | |
| 224 // | |
| 225 %type typetoken {Token} | |
| 226 type ::= . | |
| 227 type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);} | |
| 228 typetoken(A) ::= typename(X). {A = X;} | |
| 229 typetoken(A) ::= typename(X) LP signed RP(Y). { | |
| 230 A.z = X.z; | |
| 231 A.n = &Y.z[Y.n] - X.z; | |
| 232 } | |
| 233 typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). { | |
| 234 A.z = X.z; | |
| 235 A.n = &Y.z[Y.n] - X.z; | |
| 236 } | |
| 237 %type typename {Token} | |
| 238 typename(A) ::= ids(X). {A = X;} | |
| 239 typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);} | |
| 240 %type signed {int} | |
| 241 signed(A) ::= plus_num(X). { A = atoi((char*)X.z); } | |
| 242 signed(A) ::= minus_num(X). { A = -atoi((char*)X.z); } | |
| 243 | |
| 244 // "carglist" is a list of additional constraints that come after the | |
| 245 // column name and column type in a CREATE TABLE statement. | |
| 246 // | |
| 247 carglist ::= carglist carg. | |
| 248 carglist ::= . | |
| 249 carg ::= CONSTRAINT nm ccons. | |
| 250 carg ::= ccons. | |
| 251 carg ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);} | |
| 252 carg ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);} | |
| 253 carg ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);} | |
| 254 carg ::= DEFAULT MINUS term(X). { | |
| 255 Expr *p = sqlite3Expr(TK_UMINUS, X, 0, 0); | |
| 256 sqlite3AddDefaultValue(pParse,p); | |
| 257 } | |
| 258 carg ::= DEFAULT id(X). { | |
| 259 Expr *p = sqlite3Expr(TK_STRING, 0, 0, &X); | |
| 260 sqlite3AddDefaultValue(pParse,p); | |
| 261 } | |
| 262 | |
| 263 // In addition to the type name, we also care about the primary key and | |
| 264 // UNIQUE constraints. | |
| 265 // | |
| 266 ccons ::= NULL onconf. | |
| 267 ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);} | |
| 268 ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I). | |
| 269 {sqlite3AddPrimaryKey(pParse,0,R,I,Z);} | |
| 270 ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0,0,0);} | |
| 271 ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X);} | |
| 272 ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R). | |
| 273 {sqlite3CreateForeignKey(pParse,0,&T,TA,R);} | |
| 274 ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);} | |
| 275 ccons ::= COLLATE id(C). {sqlite3AddCollateType(pParse, (char*)C.z, C.n);} | |
| 276 | |
| 277 // The optional AUTOINCREMENT keyword | |
| 278 %type autoinc {int} | |
| 279 autoinc(X) ::= . {X = 0;} | |
| 280 autoinc(X) ::= AUTOINCR. {X = 1;} | |
| 281 | |
| 282 // The next group of rules parses the arguments to a REFERENCES clause | |
| 283 // that determine if the referential integrity checking is deferred or | |
| 284 // or immediate and which determine what action to take if a ref-integ | |
| 285 // check fails. | |
| 286 // | |
| 287 %type refargs {int} | |
| 288 refargs(A) ::= . { A = OE_Restrict * 0x010101; } | |
| 289 refargs(A) ::= refargs(X) refarg(Y). { A = (X & Y.mask) | Y.value; } | |
| 290 %type refarg {struct {int value; int mask;}} | |
| 291 refarg(A) ::= MATCH nm. { A.value = 0; A.mask = 0x000000; } | |
| 292 refarg(A) ::= ON DELETE refact(X). { A.value = X; A.mask = 0x0000ff; } | |
| 293 refarg(A) ::= ON UPDATE refact(X). { A.value = X<<8; A.mask = 0x00ff00; } | |
| 294 refarg(A) ::= ON INSERT refact(X). { A.value = X<<16; A.mask = 0xff0000; } | |
| 295 %type refact {int} | |
| 296 refact(A) ::= SET NULL. { A = OE_SetNull; } | |
| 297 refact(A) ::= SET DEFAULT. { A = OE_SetDflt; } | |
| 298 refact(A) ::= CASCADE. { A = OE_Cascade; } | |
| 299 refact(A) ::= RESTRICT. { A = OE_Restrict; } | |
| 300 %type defer_subclause {int} | |
| 301 defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt(X). {A = X;} | |
| 302 defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X). {A = X;} | |
| 303 %type init_deferred_pred_opt {int} | |
| 304 init_deferred_pred_opt(A) ::= . {A = 0;} | |
| 305 init_deferred_pred_opt(A) ::= INITIALLY DEFERRED. {A = 1;} | |
| 306 init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE. {A = 0;} | |
| 307 | |
| 308 // For the time being, the only constraint we care about is the primary | |
| 309 // key and UNIQUE. Both create indices. | |
| 310 // | |
| 311 conslist_opt(A) ::= . {A.n = 0; A.z = 0;} | |
| 312 conslist_opt(A) ::= COMMA(X) conslist. {A = X;} | |
| 313 conslist ::= conslist COMMA tcons. | |
| 314 conslist ::= conslist tcons. | |
| 315 conslist ::= tcons. | |
| 316 tcons ::= CONSTRAINT nm. | |
| 317 tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R). | |
| 318 {sqlite3AddPrimaryKey(pParse,X,R,I,0);} | |
| 319 tcons ::= UNIQUE LP idxlist(X) RP onconf(R). | |
| 320 {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);} | |
| 321 tcons ::= CHECK LP expr(E) RP onconf. {sqlite3AddCheckConstraint(pParse,E);} | |
| 322 tcons ::= FOREIGN KEY LP idxlist(FA) RP | |
| 323 REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). { | |
| 324 sqlite3CreateForeignKey(pParse, FA, &T, TA, R); | |
| 325 sqlite3DeferForeignKey(pParse, D); | |
| 326 } | |
| 327 %type defer_subclause_opt {int} | |
| 328 defer_subclause_opt(A) ::= . {A = 0;} | |
| 329 defer_subclause_opt(A) ::= defer_subclause(X). {A = X;} | |
| 330 | |
| 331 // The following is a non-standard extension that allows us to declare the | |
| 332 // default behavior when there is a constraint conflict. | |
| 333 // | |
| 334 %type onconf {int} | |
| 335 %type orconf {int} | |
| 336 %type resolvetype {int} | |
| 337 onconf(A) ::= . {A = OE_Default;} | |
| 338 onconf(A) ::= ON CONFLICT resolvetype(X). {A = X;} | |
| 339 orconf(A) ::= . {A = OE_Default;} | |
| 340 orconf(A) ::= OR resolvetype(X). {A = X;} | |
| 341 resolvetype(A) ::= raisetype(X). {A = X;} | |
| 342 resolvetype(A) ::= IGNORE. {A = OE_Ignore;} | |
| 343 resolvetype(A) ::= REPLACE. {A = OE_Replace;} | |
| 344 | |
| 345 ////////////////////////// The DROP TABLE ///////////////////////////////////// | |
| 346 // | |
| 347 cmd ::= DROP TABLE ifexists(E) fullname(X). { | |
| 348 sqlite3DropTable(pParse, X, 0, E); | |
| 349 } | |
| 350 %type ifexists {int} | |
| 351 ifexists(A) ::= IF EXISTS. {A = 1;} | |
| 352 ifexists(A) ::= . {A = 0;} | |
| 353 | |
| 354 ///////////////////// The CREATE VIEW statement ///////////////////////////// | |
| 355 // | |
| 356 %ifndef SQLITE_OMIT_VIEW | |
| 357 cmd ::= CREATE(X) temp(T) VIEW nm(Y) dbnm(Z) AS select(S). { | |
| 358 sqlite3CreateView(pParse, &X, &Y, &Z, S, T); | |
| 359 } | |
| 360 cmd ::= DROP VIEW ifexists(E) fullname(X). { | |
| 361 sqlite3DropTable(pParse, X, 1, E); | |
| 362 } | |
| 363 %endif // SQLITE_OMIT_VIEW | |
| 364 | |
| 365 //////////////////////// The SELECT statement ///////////////////////////////// | |
| 366 // | |
| 367 cmd ::= select(X). { | |
| 368 sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0, 0); | |
| 369 sqlite3SelectDelete(X); | |
| 370 } | |
| 371 | |
| 372 %type select {Select*} | |
| 373 %destructor select {sqlite3SelectDelete($$);} | |
| 374 %type oneselect {Select*} | |
| 375 %destructor oneselect {sqlite3SelectDelete($$);} | |
| 376 | |
| 377 select(A) ::= oneselect(X). {A = X;} | |
| 378 %ifndef SQLITE_OMIT_COMPOUND_SELECT | |
| 379 select(A) ::= select(X) multiselect_op(Y) oneselect(Z). { | |
| 380 if( Z ){ | |
| 381 Z->op = Y; | |
| 382 Z->pPrior = X; | |
| 383 } | |
| 384 A = Z; | |
| 385 } | |
| 386 %type multiselect_op {int} | |
| 387 multiselect_op(A) ::= UNION(OP). {A = @OP;} | |
| 388 multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} | |
| 389 multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;} | |
| 390 %endif // SQLITE_OMIT_COMPOUND_SELECT | |
| 391 oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) | |
| 392 groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { | |
| 393 A = sqlite3SelectNew(W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); | |
| 394 } | |
| 395 | |
| 396 // The "distinct" nonterminal is true (1) if the DISTINCT keyword is | |
| 397 // present and false (0) if it is not. | |
| 398 // | |
| 399 %type distinct {int} | |
| 400 distinct(A) ::= DISTINCT. {A = 1;} | |
| 401 distinct(A) ::= ALL. {A = 0;} | |
| 402 distinct(A) ::= . {A = 0;} | |
| 403 | |
| 404 // selcollist is a list of expressions that are to become the return | |
| 405 // values of the SELECT statement. The "*" in statements like | |
| 406 // "SELECT * FROM ..." is encoded as a special expression with an | |
| 407 // opcode of TK_ALL. | |
| 408 // | |
| 409 %type selcollist {ExprList*} | |
| 410 %destructor selcollist {sqlite3ExprListDelete($$);} | |
| 411 %type sclp {ExprList*} | |
| 412 %destructor sclp {sqlite3ExprListDelete($$);} | |
| 413 sclp(A) ::= selcollist(X) COMMA. {A = X;} | |
| 414 sclp(A) ::= . {A = 0;} | |
| 415 selcollist(A) ::= sclp(P) expr(X) as(Y). { | |
| 416 A = sqlite3ExprListAppend(P,X,Y.n?&Y:0); | |
| 417 } | |
| 418 selcollist(A) ::= sclp(P) STAR. { | |
| 419 A = sqlite3ExprListAppend(P, sqlite3Expr(TK_ALL, 0, 0, 0), 0); | |
| 420 } | |
| 421 selcollist(A) ::= sclp(P) nm(X) DOT STAR. { | |
| 422 Expr *pRight = sqlite3Expr(TK_ALL, 0, 0, 0); | |
| 423 Expr *pLeft = sqlite3Expr(TK_ID, 0, 0, &X); | |
| 424 A = sqlite3ExprListAppend(P, sqlite3Expr(TK_DOT, pLeft, pRight, 0), 0); | |
| 425 } | |
| 426 | |
| 427 // An option "AS <id>" phrase that can follow one of the expressions that | |
| 428 // define the result set, or one of the tables in the FROM clause. | |
| 429 // | |
| 430 %type as {Token} | |
| 431 as(X) ::= AS nm(Y). {X = Y;} | |
| 432 as(X) ::= ids(Y). {X = Y;} | |
| 433 as(X) ::= . {X.n = 0;} | |
| 434 | |
| 435 | |
| 436 %type seltablist {SrcList*} | |
| 437 %destructor seltablist {sqlite3SrcListDelete($$);} | |
| 438 %type stl_prefix {SrcList*} | |
| 439 %destructor stl_prefix {sqlite3SrcListDelete($$);} | |
| 440 %type from {SrcList*} | |
| 441 %destructor from {sqlite3SrcListDelete($$);} | |
| 442 | |
| 443 // A complete FROM clause. | |
| 444 // | |
| 445 from(A) ::= . {A = sqliteMalloc(sizeof(*A));} | |
| 446 from(A) ::= FROM seltablist(X). {A = X;} | |
| 447 | |
| 448 // "seltablist" is a "Select Table List" - the content of the FROM clause | |
| 449 // in a SELECT statement. "stl_prefix" is a prefix of this list. | |
| 450 // | |
| 451 stl_prefix(A) ::= seltablist(X) joinop(Y). { | |
| 452 A = X; | |
| 453 if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y; | |
| 454 } | |
| 455 stl_prefix(A) ::= . {A = 0;} | |
| 456 seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). { | |
| 457 A = sqlite3SrcListAppend(X,&Y,&D); | |
| 458 if( Z.n ) sqlite3SrcListAddAlias(A,&Z); | |
| 459 if( N ){ | |
| 460 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; } | |
| 461 else { sqlite3ExprDelete(N); } | |
| 462 } | |
| 463 if( U ){ | |
| 464 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; } | |
| 465 else { sqlite3IdListDelete(U); } | |
| 466 } | |
| 467 } | |
| 468 %ifndef SQLITE_OMIT_SUBQUERY | |
| 469 seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP | |
| 470 as(Z) on_opt(N) using_opt(U). { | |
| 471 A = sqlite3SrcListAppend(X,0,0); | |
| 472 A->a[A->nSrc-1].pSelect = S; | |
| 473 if( Z.n ) sqlite3SrcListAddAlias(A,&Z); | |
| 474 if( N ){ | |
| 475 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pOn = N; } | |
| 476 else { sqlite3ExprDelete(N); } | |
| 477 } | |
| 478 if( U ){ | |
| 479 if( A && A->nSrc>1 ){ A->a[A->nSrc-2].pUsing = U; } | |
| 480 else { sqlite3IdListDelete(U); } | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 // A seltablist_paren nonterminal represents anything in a FROM that | |
| 485 // is contained inside parentheses. This can be either a subquery or | |
| 486 // a grouping of table and subqueries. | |
| 487 // | |
| 488 %type seltablist_paren {Select*} | |
| 489 %destructor seltablist_paren {sqlite3SelectDelete($$);} | |
| 490 seltablist_paren(A) ::= select(S). {A = S;} | |
| 491 seltablist_paren(A) ::= seltablist(F). { | |
| 492 A = sqlite3SelectNew(0,F,0,0,0,0,0,0,0); | |
| 493 } | |
| 494 %endif // SQLITE_OMIT_SUBQUERY | |
| 495 | |
| 496 %type dbnm {Token} | |
| 497 dbnm(A) ::= . {A.z=0; A.n=0;} | |
| 498 dbnm(A) ::= DOT nm(X). {A = X;} | |
| 499 | |
| 500 %type fullname {SrcList*} | |
| 501 %destructor fullname {sqlite3SrcListDelete($$);} | |
| 502 fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(0,&X,&Y);} | |
| 503 | |
| 504 %type joinop {int} | |
| 505 %type joinop2 {int} | |
| 506 joinop(X) ::= COMMA|JOIN. { X = JT_INNER; } | |
| 507 joinop(X) ::= JOIN_KW(A) JOIN. { X = sqlite3JoinType(pParse,&A,0,0); } | |
| 508 joinop(X) ::= JOIN_KW(A) nm(B) JOIN. { X = sqlite3JoinType(pParse,&A,&B,0); } | |
| 509 joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN. | |
| 510 { X = sqlite3JoinType(pParse,&A,&B,&C); } | |
| 511 | |
| 512 %type on_opt {Expr*} | |
| 513 %destructor on_opt {sqlite3ExprDelete($$);} | |
| 514 on_opt(N) ::= ON expr(E). {N = E;} | |
| 515 on_opt(N) ::= . {N = 0;} | |
| 516 | |
| 517 %type using_opt {IdList*} | |
| 518 %destructor using_opt {sqlite3IdListDelete($$);} | |
| 519 using_opt(U) ::= USING LP inscollist(L) RP. {U = L;} | |
| 520 using_opt(U) ::= . {U = 0;} | |
| 521 | |
| 522 | |
| 523 %type orderby_opt {ExprList*} | |
| 524 %destructor orderby_opt {sqlite3ExprListDelete($$);} | |
| 525 %type sortlist {ExprList*} | |
| 526 %destructor sortlist {sqlite3ExprListDelete($$);} | |
| 527 %type sortitem {Expr*} | |
| 528 %destructor sortitem {sqlite3ExprDelete($$);} | |
| 529 | |
| 530 orderby_opt(A) ::= . {A = 0;} | |
| 531 orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} | |
| 532 sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). { | |
| 533 A = sqlite3ExprListAppend(X,Y,C.n>0?&C:0); | |
| 534 if( A ) A->a[A->nExpr-1].sortOrder = Z; | |
| 535 } | |
| 536 sortlist(A) ::= sortitem(Y) collate(C) sortorder(Z). { | |
| 537 A = sqlite3ExprListAppend(0,Y,C.n>0?&C:0); | |
| 538 if( A && A->a ) A->a[0].sortOrder = Z; | |
| 539 } | |
| 540 sortitem(A) ::= expr(X). {A = X;} | |
| 541 | |
| 542 %type sortorder {int} | |
| 543 %type collate {Token} | |
| 544 | |
| 545 sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} | |
| 546 sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} | |
| 547 sortorder(A) ::= . {A = SQLITE_SO_ASC;} | |
| 548 collate(C) ::= . {C.z = 0; C.n = 0;} | |
| 549 collate(C) ::= COLLATE id(X). {C = X;} | |
| 550 | |
| 551 %type groupby_opt {ExprList*} | |
| 552 %destructor groupby_opt {sqlite3ExprListDelete($$);} | |
| 553 groupby_opt(A) ::= . {A = 0;} | |
| 554 groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;} | |
| 555 | |
| 556 %type having_opt {Expr*} | |
| 557 %destructor having_opt {sqlite3ExprDelete($$);} | |
| 558 having_opt(A) ::= . {A = 0;} | |
| 559 having_opt(A) ::= HAVING expr(X). {A = X;} | |
| 560 | |
| 561 %type limit_opt {struct LimitVal} | |
| 562 %destructor limit_opt { | |
| 563 sqlite3ExprDelete($$.pLimit); | |
| 564 sqlite3ExprDelete($$.pOffset); | |
| 565 } | |
| 566 limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;} | |
| 567 limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X; A.pOffset = 0;} | |
| 568 limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y). | |
| 569 {A.pLimit = X; A.pOffset = Y;} | |
| 570 limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). | |
| 571 {A.pOffset = X; A.pLimit = Y;} | |
| 572 | |
| 573 /////////////////////////// The DELETE statement ///////////////////////////// | |
| 574 // | |
| 575 cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);} | |
| 576 | |
| 577 %type where_opt {Expr*} | |
| 578 %destructor where_opt {sqlite3ExprDelete($$);} | |
| 579 | |
| 580 where_opt(A) ::= . {A = 0;} | |
| 581 where_opt(A) ::= WHERE expr(X). {A = X;} | |
| 582 | |
| 583 ////////////////////////// The UPDATE command //////////////////////////////// | |
| 584 // | |
| 585 cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z). | |
| 586 {sqlite3Update(pParse,X,Y,Z,R);} | |
| 587 | |
| 588 %type setlist {ExprList*} | |
| 589 %destructor setlist {sqlite3ExprListDelete($$);} | |
| 590 | |
| 591 setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y). | |
| 592 {A = sqlite3ExprListAppend(Z,Y,&X);} | |
| 593 setlist(A) ::= nm(X) EQ expr(Y). {A = sqlite3ExprListAppend(0,Y,&X);} | |
| 594 | |
| 595 ////////////////////////// The INSERT command ///////////////////////////////// | |
| 596 // | |
| 597 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) | |
| 598 VALUES LP itemlist(Y) RP. | |
| 599 {sqlite3Insert(pParse, X, Y, 0, F, R);} | |
| 600 cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S). | |
| 601 {sqlite3Insert(pParse, X, 0, S, F, R);} | |
| 602 | |
| 603 %type insert_cmd {int} | |
| 604 insert_cmd(A) ::= INSERT orconf(R). {A = R;} | |
| 605 insert_cmd(A) ::= REPLACE. {A = OE_Replace;} | |
| 606 | |
| 607 | |
| 608 %type itemlist {ExprList*} | |
| 609 %destructor itemlist {sqlite3ExprListDelete($$);} | |
| 610 | |
| 611 itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqlite3ExprListAppend(X,Y,0);} | |
| 612 itemlist(A) ::= expr(X). {A = sqlite3ExprListAppend(0,X,0);} | |
| 613 | |
| 614 %type inscollist_opt {IdList*} | |
| 615 %destructor inscollist_opt {sqlite3IdListDelete($$);} | |
| 616 %type inscollist {IdList*} | |
| 617 %destructor inscollist {sqlite3IdListDelete($$);} | |
| 618 | |
| 619 inscollist_opt(A) ::= . {A = 0;} | |
| 620 inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;} | |
| 621 inscollist(A) ::= inscollist(X) COMMA nm(Y). {A = sqlite3IdListAppend(X,&Y);} | |
| 622 inscollist(A) ::= nm(Y). {A = sqlite3IdListAppend(0,&Y);} | |
| 623 | |
| 624 /////////////////////////// Expression Processing ///////////////////////////// | |
| 625 // | |
| 626 | |
| 627 %type expr {Expr*} | |
| 628 %destructor expr {sqlite3ExprDelete($$);} | |
| 629 %type term {Expr*} | |
| 630 %destructor term {sqlite3ExprDelete($$);} | |
| 631 | |
| 632 expr(A) ::= term(X). {A = X;} | |
| 633 expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); } | |
| 634 term(A) ::= NULL(X). {A = sqlite3Expr(@X, 0, 0, &X);} | |
| 635 expr(A) ::= ID(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);} | |
| 636 expr(A) ::= JOIN_KW(X). {A = sqlite3Expr(TK_ID, 0, 0, &X);} | |
| 637 expr(A) ::= nm(X) DOT nm(Y). { | |
| 638 Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X); | |
| 639 Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y); | |
| 640 A = sqlite3Expr(TK_DOT, temp1, temp2, 0); | |
| 641 } | |
| 642 expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). { | |
| 643 Expr *temp1 = sqlite3Expr(TK_ID, 0, 0, &X); | |
| 644 Expr *temp2 = sqlite3Expr(TK_ID, 0, 0, &Y); | |
| 645 Expr *temp3 = sqlite3Expr(TK_ID, 0, 0, &Z); | |
| 646 Expr *temp4 = sqlite3Expr(TK_DOT, temp2, temp3, 0); | |
| 647 A = sqlite3Expr(TK_DOT, temp1, temp4, 0); | |
| 648 } | |
| 649 term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3Expr(@X, 0, 0, &X);} | |
| 650 term(A) ::= STRING(X). {A = sqlite3Expr(@X, 0, 0, &X);} | |
| 651 expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);} | |
| 652 expr(A) ::= VARIABLE(X). { | |
| 653 Token *pToken = &X; | |
| 654 Expr *pExpr = A = sqlite3Expr(TK_VARIABLE, 0, 0, pToken); | |
| 655 sqlite3ExprAssignVarNumber(pParse, pExpr); | |
| 656 } | |
| 657 %ifndef SQLITE_OMIT_CAST | |
| 658 expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { | |
| 659 A = sqlite3Expr(TK_CAST, E, 0, &T); | |
| 660 sqlite3ExprSpan(A,&X,&Y); | |
| 661 } | |
| 662 %endif // SQLITE_OMIT_CAST | |
| 663 expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). { | |
| 664 A = sqlite3ExprFunction(Y, &X); | |
| 665 sqlite3ExprSpan(A,&X,&E); | |
| 666 if( D && A ){ | |
| 667 A->flags |= EP_Distinct; | |
| 668 } | |
| 669 } | |
| 670 expr(A) ::= ID(X) LP STAR RP(E). { | |
| 671 A = sqlite3ExprFunction(0, &X); | |
| 672 sqlite3ExprSpan(A,&X,&E); | |
| 673 } | |
| 674 term(A) ::= CTIME_KW(OP). { | |
| 675 /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are | |
| 676 ** treated as functions that return constants */ | |
| 677 A = sqlite3ExprFunction(0,&OP); | |
| 678 if( A ) A->op = TK_CONST_FUNC; | |
| 679 } | |
| 680 expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 681 expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 682 expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 683 expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 684 expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y). | |
| 685 {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 686 expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 687 expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 688 expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3Expr(@OP, X, Y, 0);} | |
| 689 %type likeop {struct LikeOp} | |
| 690 likeop(A) ::= LIKE_KW(X). {A.eOperator = X; A.not = 0;} | |
| 691 likeop(A) ::= NOT LIKE_KW(X). {A.eOperator = X; A.not = 1;} | |
| 692 %type escape {Expr*} | |
| 693 %destructor escape {sqlite3ExprDelete($$);} | |
| 694 escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;} | |
| 695 escape(X) ::= . [ESCAPE] {X = 0;} | |
| 696 expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] { | |
| 697 ExprList *pList; | |
| 698 pList = sqlite3ExprListAppend(0, Y, 0); | |
| 699 pList = sqlite3ExprListAppend(pList, X, 0); | |
| 700 if( E ){ | |
| 701 pList = sqlite3ExprListAppend(pList, E, 0); | |
| 702 } | |
| 703 A = sqlite3ExprFunction(pList, &OP.eOperator); | |
| 704 if( OP.not ) A = sqlite3Expr(TK_NOT, A, 0, 0); | |
| 705 sqlite3ExprSpan(A, &X->span, &Y->span); | |
| 706 } | |
| 707 | |
| 708 expr(A) ::= expr(X) ISNULL|NOTNULL(E). { | |
| 709 A = sqlite3Expr(@E, X, 0, 0); | |
| 710 sqlite3ExprSpan(A,&X->span,&E); | |
| 711 } | |
| 712 expr(A) ::= expr(X) IS NULL(E). { | |
| 713 A = sqlite3Expr(TK_ISNULL, X, 0, 0); | |
| 714 sqlite3ExprSpan(A,&X->span,&E); | |
| 715 } | |
| 716 expr(A) ::= expr(X) NOT NULL(E). { | |
| 717 A = sqlite3Expr(TK_NOTNULL, X, 0, 0); | |
| 718 sqlite3ExprSpan(A,&X->span,&E); | |
| 719 } | |
| 720 expr(A) ::= expr(X) IS NOT NULL(E). { | |
| 721 A = sqlite3Expr(TK_NOTNULL, X, 0, 0); | |
| 722 sqlite3ExprSpan(A,&X->span,&E); | |
| 723 } | |
| 724 expr(A) ::= NOT|BITNOT(B) expr(X). { | |
| 725 A = sqlite3Expr(@B, X, 0, 0); | |
| 726 sqlite3ExprSpan(A,&B,&X->span); | |
| 727 } | |
| 728 expr(A) ::= MINUS(B) expr(X). [UMINUS] { | |
| 729 A = sqlite3Expr(TK_UMINUS, X, 0, 0); | |
| 730 sqlite3ExprSpan(A,&B,&X->span); | |
| 731 } | |
| 732 expr(A) ::= PLUS(B) expr(X). [UPLUS] { | |
| 733 A = sqlite3Expr(TK_UPLUS, X, 0, 0); | |
| 734 sqlite3ExprSpan(A,&B,&X->span); | |
| 735 } | |
| 736 %type between_op {int} | |
| 737 between_op(A) ::= BETWEEN. {A = 0;} | |
| 738 between_op(A) ::= NOT BETWEEN. {A = 1;} | |
| 739 expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { | |
| 740 ExprList *pList = sqlite3ExprListAppend(0, X, 0); | |
| 741 pList = sqlite3ExprListAppend(pList, Y, 0); | |
| 742 A = sqlite3Expr(TK_BETWEEN, W, 0, 0); | |
| 743 if( A ){ | |
| 744 A->pList = pList; | |
| 745 }else{ | |
| 746 sqlite3ExprListDelete(pList); | |
| 747 } | |
| 748 if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0); | |
| 749 sqlite3ExprSpan(A,&W->span,&Y->span); | |
| 750 } | |
| 751 %ifndef SQLITE_OMIT_SUBQUERY | |
| 752 %type in_op {int} | |
| 753 in_op(A) ::= IN. {A = 0;} | |
| 754 in_op(A) ::= NOT IN. {A = 1;} | |
| 755 expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] { | |
| 756 A = sqlite3Expr(TK_IN, X, 0, 0); | |
| 757 if( A ){ | |
| 758 A->pList = Y; | |
| 759 }else{ | |
| 760 sqlite3ExprListDelete(Y); | |
| 761 } | |
| 762 if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0); | |
| 763 sqlite3ExprSpan(A,&X->span,&E); | |
| 764 } | |
| 765 expr(A) ::= LP(B) select(X) RP(E). { | |
| 766 A = sqlite3Expr(TK_SELECT, 0, 0, 0); | |
| 767 if( A ){ | |
| 768 A->pSelect = X; | |
| 769 }else{ | |
| 770 sqlite3SelectDelete(X); | |
| 771 } | |
| 772 sqlite3ExprSpan(A,&B,&E); | |
| 773 } | |
| 774 expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] { | |
| 775 A = sqlite3Expr(TK_IN, X, 0, 0); | |
| 776 if( A ){ | |
| 777 A->pSelect = Y; | |
| 778 }else{ | |
| 779 sqlite3SelectDelete(Y); | |
| 780 } | |
| 781 if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0); | |
| 782 sqlite3ExprSpan(A,&X->span,&E); | |
| 783 } | |
| 784 expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] { | |
| 785 SrcList *pSrc = sqlite3SrcListAppend(0,&Y,&Z); | |
| 786 A = sqlite3Expr(TK_IN, X, 0, 0); | |
| 787 if( A ){ | |
| 788 A->pSelect = sqlite3SelectNew(0,pSrc,0,0,0,0,0,0,0); | |
| 789 }else{ | |
| 790 sqlite3SrcListDelete(pSrc); | |
| 791 } | |
| 792 if( N ) A = sqlite3Expr(TK_NOT, A, 0, 0); | |
| 793 sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y); | |
| 794 } | |
| 795 expr(A) ::= EXISTS(B) LP select(Y) RP(E). { | |
| 796 Expr *p = A = sqlite3Expr(TK_EXISTS, 0, 0, 0); | |
| 797 if( p ){ | |
| 798 p->pSelect = Y; | |
| 799 sqlite3ExprSpan(p,&B,&E); | |
| 800 }else{ | |
| 801 sqlite3SelectDelete(Y); | |
| 802 } | |
| 803 } | |
| 804 %endif // SQLITE_OMIT_SUBQUERY | |
| 805 | |
| 806 /* CASE expressions */ | |
| 807 expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { | |
| 808 A = sqlite3Expr(TK_CASE, X, Z, 0); | |
| 809 if( A ){ | |
| 810 A->pList = Y; | |
| 811 }else{ | |
| 812 sqlite3ExprListDelete(Y); | |
| 813 } | |
| 814 sqlite3ExprSpan(A, &C, &E); | |
| 815 } | |
| 816 %type case_exprlist {ExprList*} | |
| 817 %destructor case_exprlist {sqlite3ExprListDelete($$);} | |
| 818 case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). { | |
| 819 A = sqlite3ExprListAppend(X, Y, 0); | |
| 820 A = sqlite3ExprListAppend(A, Z, 0); | |
| 821 } | |
| 822 case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). { | |
| 823 A = sqlite3ExprListAppend(0, Y, 0); | |
| 824 A = sqlite3ExprListAppend(A, Z, 0); | |
| 825 } | |
| 826 %type case_else {Expr*} | |
| 827 %destructor case_else {sqlite3ExprDelete($$);} | |
| 828 case_else(A) ::= ELSE expr(X). {A = X;} | |
| 829 case_else(A) ::= . {A = 0;} | |
| 830 %type case_operand {Expr*} | |
| 831 %destructor case_operand {sqlite3ExprDelete($$);} | |
| 832 case_operand(A) ::= expr(X). {A = X;} | |
| 833 case_operand(A) ::= . {A = 0;} | |
| 834 | |
| 835 %type exprlist {ExprList*} | |
| 836 %destructor exprlist {sqlite3ExprListDelete($$);} | |
| 837 %type expritem {Expr*} | |
| 838 %destructor expritem {sqlite3ExprDelete($$);} | |
| 839 | |
| 840 exprlist(A) ::= exprlist(X) COMMA expritem(Y). | |
| 841 {A = sqlite3ExprListAppend(X,Y,0);} | |
| 842 exprlist(A) ::= expritem(X). {A = sqlite3ExprListAppend(0,X,0);} | |
| 843 expritem(A) ::= expr(X). {A = X;} | |
| 844 expritem(A) ::= . {A = 0;} | |
| 845 | |
| 846 ///////////////////////////// The CREATE INDEX command /////////////////////// | |
| 847 // | |
| 848 cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D) | |
| 849 ON nm(Y) LP idxlist(Z) RP(E). { | |
| 850 sqlite3CreateIndex(pParse, &X, &D, sqlite3SrcListAppend(0,&Y,0), Z, U, | |
| 851 &S, &E, SQLITE_SO_ASC, NE); | |
| 852 } | |
| 853 | |
| 854 %type uniqueflag {int} | |
| 855 uniqueflag(A) ::= UNIQUE. {A = OE_Abort;} | |
| 856 uniqueflag(A) ::= . {A = OE_None;} | |
| 857 | |
| 858 %type idxlist {ExprList*} | |
| 859 %destructor idxlist {sqlite3ExprListDelete($$);} | |
| 860 %type idxlist_opt {ExprList*} | |
| 861 %destructor idxlist_opt {sqlite3ExprListDelete($$);} | |
| 862 %type idxitem {Token} | |
| 863 | |
| 864 idxlist_opt(A) ::= . {A = 0;} | |
| 865 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} | |
| 866 idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). { | |
| 867 Expr *p = 0; | |
| 868 if( C.n>0 ){ | |
| 869 p = sqlite3Expr(TK_COLUMN, 0, 0, 0); | |
| 870 if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n); | |
| 871 } | |
| 872 A = sqlite3ExprListAppend(X, p, &Y); | |
| 873 if( A ) A->a[A->nExpr-1].sortOrder = Z; | |
| 874 } | |
| 875 idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). { | |
| 876 Expr *p = 0; | |
| 877 if( C.n>0 ){ | |
| 878 p = sqlite3Expr(TK_COLUMN, 0, 0, 0); | |
| 879 if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n); | |
| 880 } | |
| 881 A = sqlite3ExprListAppend(0, p, &Y); | |
| 882 if( A ) A->a[A->nExpr-1].sortOrder = Z; | |
| 883 } | |
| 884 idxitem(A) ::= nm(X). {A = X;} | |
| 885 | |
| 886 | |
| 887 ///////////////////////////// The DROP INDEX command ///////////////////////// | |
| 888 // | |
| 889 cmd ::= DROP INDEX ifexists(E) fullname(X). {sqlite3DropIndex(pParse, X, E);} | |
| 890 | |
| 891 ///////////////////////////// The VACUUM command ///////////////////////////// | |
| 892 // | |
| 893 cmd ::= VACUUM. {sqlite3Vacuum(pParse);} | |
| 894 cmd ::= VACUUM nm. {sqlite3Vacuum(pParse);} | |
| 895 | |
| 896 ///////////////////////////// The PRAGMA command ///////////////////////////// | |
| 897 // | |
| 898 %ifndef SQLITE_OMIT_PRAGMA | |
| 899 cmd ::= PRAGMA nm(X) dbnm(Z) EQ nm(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);} | |
| 900 cmd ::= PRAGMA nm(X) dbnm(Z) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);} | |
| 901 cmd ::= PRAGMA nm(X) dbnm(Z) EQ plus_num(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);} | |
| 902 cmd ::= PRAGMA nm(X) dbnm(Z) EQ minus_num(Y). { | |
| 903 sqlite3Pragma(pParse,&X,&Z,&Y,1); | |
| 904 } | |
| 905 cmd ::= PRAGMA nm(X) dbnm(Z) LP nm(Y) RP. {sqlite3Pragma(pParse,&X,&Z,&Y,0);} | |
| 906 cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);} | |
| 907 %endif // SQLITE_OMIT_PRAGMA | |
| 908 plus_num(A) ::= plus_opt number(X). {A = X;} | |
| 909 minus_num(A) ::= MINUS number(X). {A = X;} | |
| 910 number(A) ::= INTEGER|FLOAT(X). {A = X;} | |
| 911 plus_opt ::= PLUS. | |
| 912 plus_opt ::= . | |
| 913 | |
| 914 //////////////////////////// The CREATE TRIGGER command ///////////////////// | |
| 915 | |
| 916 %ifndef SQLITE_OMIT_TRIGGER | |
| 917 | |
| 918 cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). { | |
| 919 Token all; | |
| 920 all.z = A.z; | |
| 921 all.n = (Z.z - A.z) + Z.n; | |
| 922 sqlite3FinishTrigger(pParse, S, &all); | |
| 923 } | |
| 924 | |
| 925 trigger_decl(A) ::= temp(T) TRIGGER nm(B) dbnm(Z) trigger_time(C) | |
| 926 trigger_event(D) | |
| 927 ON fullname(E) foreach_clause(F) when_clause(G). { | |
| 928 sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, F, G, T); | |
| 929 A = (Z.n==0?B:Z); | |
| 930 } | |
| 931 | |
| 932 %type trigger_time {int} | |
| 933 trigger_time(A) ::= BEFORE. { A = TK_BEFORE; } | |
| 934 trigger_time(A) ::= AFTER. { A = TK_AFTER; } | |
| 935 trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;} | |
| 936 trigger_time(A) ::= . { A = TK_BEFORE; } | |
| 937 | |
| 938 %type trigger_event {struct TrigEvent} | |
| 939 %destructor trigger_event {sqlite3IdListDelete($$.b);} | |
| 940 trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;} | |
| 941 trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;} | |
| 942 trigger_event(A) ::= UPDATE OF inscollist(X). {A.a = TK_UPDATE; A.b = X;} | |
| 943 | |
| 944 %type foreach_clause {int} | |
| 945 foreach_clause(A) ::= . { A = TK_ROW; } | |
| 946 foreach_clause(A) ::= FOR EACH ROW. { A = TK_ROW; } | |
| 947 foreach_clause(A) ::= FOR EACH STATEMENT. { A = TK_STATEMENT; } | |
| 948 | |
| 949 %type when_clause {Expr*} | |
| 950 %destructor when_clause {sqlite3ExprDelete($$);} | |
| 951 when_clause(A) ::= . { A = 0; } | |
| 952 when_clause(A) ::= WHEN expr(X). { A = X; } | |
| 953 | |
| 954 %type trigger_cmd_list {TriggerStep*} | |
| 955 %destructor trigger_cmd_list {sqlite3DeleteTriggerStep($$);} | |
| 956 trigger_cmd_list(A) ::= trigger_cmd_list(Y) trigger_cmd(X) SEMI. { | |
| 957 if( Y ){ | |
| 958 Y->pLast->pNext = X; | |
| 959 }else{ | |
| 960 Y = X; | |
| 961 } | |
| 962 Y->pLast = X; | |
| 963 A = Y; | |
| 964 } | |
| 965 trigger_cmd_list(A) ::= . { A = 0; } | |
| 966 | |
| 967 %type trigger_cmd {TriggerStep*} | |
| 968 %destructor trigger_cmd {sqlite3DeleteTriggerStep($$);} | |
| 969 // UPDATE | |
| 970 trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z). | |
| 971 { A = sqlite3TriggerUpdateStep(&X, Y, Z, R); } | |
| 972 | |
| 973 // INSERT | |
| 974 trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) | |
| 975 VALUES LP itemlist(Y) RP. | |
| 976 {A = sqlite3TriggerInsertStep(&X, F, Y, 0, R);} | |
| 977 | |
| 978 trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S). | |
| 979 {A = sqlite3TriggerInsertStep(&X, F, 0, S, R);} | |
| 980 | |
| 981 // DELETE | |
| 982 trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y). | |
| 983 {A = sqlite3TriggerDeleteStep(&X, Y);} | |
| 984 | |
| 985 // SELECT | |
| 986 trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(X); } | |
| 987 | |
| 988 // The special RAISE expression that may occur in trigger programs | |
| 989 expr(A) ::= RAISE(X) LP IGNORE RP(Y). { | |
| 990 A = sqlite3Expr(TK_RAISE, 0, 0, 0); | |
| 991 if( A ){ | |
| 992 A->iColumn = OE_Ignore; | |
| 993 sqlite3ExprSpan(A, &X, &Y); | |
| 994 } | |
| 995 } | |
| 996 expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y). { | |
| 997 A = sqlite3Expr(TK_RAISE, 0, 0, &Z); | |
| 998 if( A ) { | |
| 999 A->iColumn = T; | |
| 1000 sqlite3ExprSpan(A, &X, &Y); | |
| 1001 } | |
| 1002 } | |
| 1003 %endif // !SQLITE_OMIT_TRIGGER | |
| 1004 | |
| 1005 %type raisetype {int} | |
| 1006 raisetype(A) ::= ROLLBACK. {A = OE_Rollback;} | |
| 1007 raisetype(A) ::= ABORT. {A = OE_Abort;} | |
| 1008 raisetype(A) ::= FAIL. {A = OE_Fail;} | |
| 1009 | |
| 1010 | |
| 1011 //////////////////////// DROP TRIGGER statement ////////////////////////////// | |
| 1012 %ifndef SQLITE_OMIT_TRIGGER | |
| 1013 cmd ::= DROP TRIGGER fullname(X). { | |
| 1014 sqlite3DropTrigger(pParse,X); | |
| 1015 } | |
| 1016 %endif // !SQLITE_OMIT_TRIGGER | |
| 1017 | |
| 1018 //////////////////////// ATTACH DATABASE file AS name ///////////////////////// | |
| 1019 cmd ::= ATTACH database_kw_opt expr(F) AS expr(D) key_opt(K). { | |
| 1020 sqlite3Attach(pParse, F, D, K); | |
| 1021 } | |
| 1022 %type key_opt {Expr *} | |
| 1023 %destructor key_opt {sqlite3ExprDelete($$);} | |
| 1024 key_opt(A) ::= . { A = 0; } | |
| 1025 key_opt(A) ::= KEY expr(X). { A = X; } | |
| 1026 | |
| 1027 database_kw_opt ::= DATABASE. | |
| 1028 database_kw_opt ::= . | |
| 1029 | |
| 1030 //////////////////////// DETACH DATABASE name ///////////////////////////////// | |
| 1031 cmd ::= DETACH database_kw_opt expr(D). { | |
| 1032 sqlite3Detach(pParse, D); | |
| 1033 } | |
| 1034 | |
| 1035 ////////////////////////// REINDEX collation ////////////////////////////////// | |
| 1036 %ifndef SQLITE_OMIT_REINDEX | |
| 1037 cmd ::= REINDEX. {sqlite3Reindex(pParse, 0, 0);} | |
| 1038 cmd ::= REINDEX nm(X) dbnm(Y). {sqlite3Reindex(pParse, &X, &Y);} | |
| 1039 %endif | |
| 1040 | |
| 1041 /////////////////////////////////// ANALYZE /////////////////////////////////// | |
| 1042 %ifndef SQLITE_OMIT_ANALYZE | |
| 1043 cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0, 0);} | |
| 1044 cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);} | |
| 1045 %endif | |
| 1046 | |
| 1047 //////////////////////// ALTER TABLE table ... //////////////////////////////// | |
| 1048 %ifndef SQLITE_OMIT_ALTERTABLE | |
| 1049 cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). { | |
| 1050 sqlite3AlterRenameTable(pParse,X,&Z); | |
| 1051 } | |
| 1052 cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). { | |
| 1053 sqlite3AlterFinishAddColumn(pParse, &Y); | |
| 1054 } | |
| 1055 add_column_fullname ::= fullname(X). { | |
| 1056 sqlite3AlterBeginAddColumn(pParse, X); | |
| 1057 } | |
| 1058 kwcolumn_opt ::= . | |
| 1059 kwcolumn_opt ::= COLUMNKW. | |
| 1060 %endif |
