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