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 | ** |
drh | e9cf59e | 2007-11-17 22:23:27 +0000 | [diff] [blame^] | 17 | ** @(#) $Id: parse.y,v 1.236 2007/11/17 22:23:28 drh Exp $ |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 18 | */ |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 19 | |
| 20 | // All token codes are small integers with #defines that begin with "TK_" |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 21 | %token_prefix TK_ |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 22 | |
| 23 | // The type of the data attached to each token is Token. This is also the |
| 24 | // default type for non-terminals. |
| 25 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 26 | %token_type {Token} |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 27 | %default_type {Token} |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 28 | |
| 29 | // The generated parser function takes a 4th argument as follows: |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 30 | %extra_argument {Parse *pParse} |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 31 | |
| 32 | // This code runs whenever there is a syntax error |
| 33 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 34 | %syntax_error { |
drh | 86dac2b | 2006-05-25 12:17:31 +0000 | [diff] [blame] | 35 | if( !pParse->parseError ){ |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 36 | if( TOKEN.z[0] ){ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 37 | sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &TOKEN); |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 38 | }else{ |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 39 | sqlite3ErrorMsg(pParse, "incomplete SQL statement"); |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 40 | } |
drh | 86dac2b | 2006-05-25 12:17:31 +0000 | [diff] [blame] | 41 | pParse->parseError = 1; |
drh | b86ccfb | 2003-01-28 23:13:10 +0000 | [diff] [blame] | 42 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 43 | } |
drh | 8fc3345 | 2006-02-27 21:58:07 +0000 | [diff] [blame] | 44 | %stack_overflow { |
| 45 | sqlite3ErrorMsg(pParse, "parser stack overflow"); |
drh | 86dac2b | 2006-05-25 12:17:31 +0000 | [diff] [blame] | 46 | pParse->parseError = 1; |
drh | 8fc3345 | 2006-02-27 21:58:07 +0000 | [diff] [blame] | 47 | } |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 48 | |
| 49 | // The name of the generated procedure that implements the parser |
| 50 | // is as follows: |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 51 | %name sqlite3Parser |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 52 | |
| 53 | // The following text is included near the beginning of the C source |
| 54 | // code file that implements the parser. |
| 55 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 56 | %include { |
| 57 | #include "sqliteInt.h" |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 60 | ** An instance of this structure holds information about the |
| 61 | ** LIMIT clause of a SELECT statement. |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 62 | */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 63 | struct LimitVal { |
danielk1977 | a2dc3b1 | 2005-02-05 12:48:48 +0000 | [diff] [blame] | 64 | Expr *pLimit; /* The LIMIT expression. NULL if there is no limit */ |
| 65 | Expr *pOffset; /* The OFFSET expression. NULL if there is none */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 66 | }; |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
drh | 2e3a1f1 | 2004-10-06 14:39:28 +0000 | [diff] [blame] | 69 | ** An instance of this structure is used to store the LIKE, |
| 70 | ** GLOB, NOT LIKE, and NOT GLOB operators. |
| 71 | */ |
| 72 | struct LikeOp { |
drh | b52076c | 2006-01-23 13:22:09 +0000 | [diff] [blame] | 73 | Token eOperator; /* "like" or "glob" or "regexp" */ |
drh | b71090f | 2005-05-23 17:26:51 +0000 | [diff] [blame] | 74 | int not; /* True if the NOT keyword is present */ |
drh | 2e3a1f1 | 2004-10-06 14:39:28 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 78 | ** An instance of the following structure describes the event of a |
| 79 | ** TRIGGER. "a" is the event type, one of TK_UPDATE, TK_INSERT, |
| 80 | ** TK_DELETE, or TK_INSTEAD. If the event is of the form |
| 81 | ** |
| 82 | ** UPDATE ON (a,b,c) |
| 83 | ** |
| 84 | ** Then the "b" IdList records the list "a,b,c". |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 85 | */ |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 86 | struct TrigEvent { int a; IdList * b; }; |
drh | caec2f1 | 2003-01-07 02:47:47 +0000 | [diff] [blame] | 87 | |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 88 | /* |
| 89 | ** An instance of this structure holds the ATTACH key and the key type. |
| 90 | */ |
| 91 | struct AttachKey { int type; Token key; }; |
| 92 | |
drh | caec2f1 | 2003-01-07 02:47:47 +0000 | [diff] [blame] | 93 | } // end %include |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 94 | |
drh | 826fb5a | 2004-02-14 23:59:57 +0000 | [diff] [blame] | 95 | // Input is a single SQL command |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 96 | input ::= cmdlist. |
drh | 094b2bb | 2002-03-13 18:54:07 +0000 | [diff] [blame] | 97 | cmdlist ::= cmdlist ecmd. |
drh | 826fb5a | 2004-02-14 23:59:57 +0000 | [diff] [blame] | 98 | cmdlist ::= ecmd. |
drh | 8024205 | 2004-06-09 00:48:12 +0000 | [diff] [blame] | 99 | cmdx ::= cmd. { sqlite3FinishCoding(pParse); } |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 100 | ecmd ::= SEMI. |
| 101 | ecmd ::= explain cmdx SEMI. |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 102 | explain ::= . { sqlite3BeginParse(pParse, 0); } |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 103 | %ifndef SQLITE_OMIT_EXPLAIN |
drh | ecc9242 | 2005-09-10 16:46:12 +0000 | [diff] [blame] | 104 | explain ::= EXPLAIN. { sqlite3BeginParse(pParse, 1); } |
| 105 | explain ::= EXPLAIN QUERY PLAN. { sqlite3BeginParse(pParse, 2); } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 106 | %endif SQLITE_OMIT_EXPLAIN |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 107 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 108 | ///////////////////// Begin and end transactions. //////////////////////////// |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 109 | // |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 110 | |
drh | 684917c | 2004-10-05 02:41:42 +0000 | [diff] [blame] | 111 | cmd ::= BEGIN transtype(Y) trans_opt. {sqlite3BeginTransaction(pParse, Y);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 112 | trans_opt ::= . |
| 113 | trans_opt ::= TRANSACTION. |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 114 | trans_opt ::= TRANSACTION nm. |
drh | 684917c | 2004-10-05 02:41:42 +0000 | [diff] [blame] | 115 | %type transtype {int} |
| 116 | transtype(A) ::= . {A = TK_DEFERRED;} |
| 117 | transtype(A) ::= DEFERRED(X). {A = @X;} |
| 118 | transtype(A) ::= IMMEDIATE(X). {A = @X;} |
| 119 | transtype(A) ::= EXCLUSIVE(X). {A = @X;} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 120 | cmd ::= COMMIT trans_opt. {sqlite3CommitTransaction(pParse);} |
| 121 | cmd ::= END trans_opt. {sqlite3CommitTransaction(pParse);} |
| 122 | cmd ::= ROLLBACK trans_opt. {sqlite3RollbackTransaction(pParse);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 123 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 124 | ///////////////////// The CREATE TABLE statement //////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 125 | // |
| 126 | cmd ::= create_table create_table_args. |
drh | 7416170 | 2006-02-24 02:53:49 +0000 | [diff] [blame] | 127 | create_table ::= CREATE temp(T) TABLE ifnotexists(E) nm(Y) dbnm(Z). { |
danielk1977 | f1a381e | 2006-06-16 08:01:02 +0000 | [diff] [blame] | 128 | sqlite3StartTable(pParse,&Y,&Z,T,0,0,E); |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 129 | } |
drh | faa5955 | 2005-12-29 23:33:54 +0000 | [diff] [blame] | 130 | %type ifnotexists {int} |
| 131 | ifnotexists(A) ::= . {A = 0;} |
| 132 | ifnotexists(A) ::= IF NOT EXISTS. {A = 1;} |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 133 | %type temp {int} |
danielk1977 | 53c0f74 | 2005-03-29 03:10:59 +0000 | [diff] [blame] | 134 | %ifndef SQLITE_OMIT_TEMPDB |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 135 | temp(A) ::= TEMP. {A = 1;} |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 136 | %endif SQLITE_OMIT_TEMPDB |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 137 | temp(A) ::= . {A = 0;} |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 138 | create_table_args ::= LP columnlist conslist_opt(X) RP(Y). { |
| 139 | sqlite3EndTable(pParse,&X,&Y,0); |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 140 | } |
| 141 | create_table_args ::= AS select(S). { |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 142 | sqlite3EndTable(pParse,0,0,S); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 143 | sqlite3SelectDelete(S); |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 144 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 145 | columnlist ::= columnlist COMMA column. |
| 146 | columnlist ::= column. |
| 147 | |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 148 | // A "column" is a complete description of a single column in a |
| 149 | // CREATE TABLE statement. This includes the column name, its |
| 150 | // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES, |
| 151 | // NOT NULL and so forth. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 152 | // |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 153 | column(A) ::= columnid(X) type carglist. { |
| 154 | A.z = X.z; |
| 155 | A.n = (pParse->sLastToken.z-X.z) + pParse->sLastToken.n; |
| 156 | } |
| 157 | columnid(A) ::= nm(X). { |
| 158 | sqlite3AddColumn(pParse,&X); |
| 159 | A = X; |
| 160 | } |
| 161 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 162 | |
| 163 | // An IDENTIFIER can be a generic identifier, or one of several |
| 164 | // keywords. Any non-standard keyword can also be an identifier. |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 165 | // |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 166 | %type id {Token} |
drh | f18543c | 2002-03-30 15:26:50 +0000 | [diff] [blame] | 167 | id(A) ::= ID(X). {A = X;} |
drh | 0bd1f4e | 2002-06-06 18:54:39 +0000 | [diff] [blame] | 168 | |
drh | 34e33bb | 2002-06-06 19:04:16 +0000 | [diff] [blame] | 169 | // The following directive causes tokens ABORT, AFTER, ASC, etc. to |
| 170 | // fallback to ID if they will not parse as their original value. |
| 171 | // This obviates the need for the "id" nonterminal. |
| 172 | // |
drh | 319e4e7 | 2003-09-30 01:54:13 +0000 | [diff] [blame] | 173 | %fallback ID |
drh | 9f18e8a | 2005-07-08 12:13:04 +0000 | [diff] [blame] | 174 | ABORT AFTER ANALYZE ASC ATTACH BEFORE BEGIN CASCADE CAST CONFLICT |
drh | 684917c | 2004-10-05 02:41:42 +0000 | [diff] [blame] | 175 | DATABASE DEFERRED DESC DETACH EACH END EXCLUSIVE EXPLAIN FAIL FOR |
drh | ca5557f | 2007-05-04 18:30:40 +0000 | [diff] [blame] | 176 | IGNORE IMMEDIATE INITIALLY INSTEAD LIKE_KW MATCH PLAN |
drh | 4f5c74e | 2007-05-04 14:14:45 +0000 | [diff] [blame] | 177 | QUERY KEY OF OFFSET PRAGMA RAISE REPLACE RESTRICT ROW |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 178 | TEMP TRIGGER VACUUM VIEW VIRTUAL |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 179 | %ifdef SQLITE_OMIT_COMPOUND_SELECT |
| 180 | EXCEPT INTERSECT UNION |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 181 | %endif SQLITE_OMIT_COMPOUND_SELECT |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 182 | REINDEX RENAME CTIME_KW IF |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 183 | . |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 184 | %wildcard ANY. |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 185 | |
drh | 2d3917d | 2004-02-22 16:27:00 +0000 | [diff] [blame] | 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 | // |
drh | f2bc013 | 2004-10-04 13:19:23 +0000 | [diff] [blame] | 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 | // |
drh | 2d3917d | 2004-02-22 16:27:00 +0000 | [diff] [blame] | 197 | %left OR. |
| 198 | %left AND. |
| 199 | %right NOT. |
drh | 03bea70 | 2006-06-13 15:37:26 +0000 | [diff] [blame] | 200 | %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ. |
drh | 9a43267 | 2004-10-04 13:38:09 +0000 | [diff] [blame] | 201 | %left GT LE LT GE. |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 202 | %right ESCAPE. |
drh | 2d3917d | 2004-02-22 16:27:00 +0000 | [diff] [blame] | 203 | %left BITAND BITOR LSHIFT RSHIFT. |
| 204 | %left PLUS MINUS. |
| 205 | %left STAR SLASH REM. |
drh | a34001c | 2007-02-02 12:44:37 +0000 | [diff] [blame] | 206 | %left CONCAT. |
| 207 | %left COLLATE. |
drh | 2d3917d | 2004-02-22 16:27:00 +0000 | [diff] [blame] | 208 | %right UMINUS UPLUS BITNOT. |
| 209 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 210 | // And "ids" is an identifer-or-string. |
| 211 | // |
| 212 | %type ids {Token} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 213 | ids(A) ::= ID|STRING(X). {A = X;} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 214 | |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 215 | // The name of a column or table can be any of the following: |
| 216 | // |
| 217 | %type nm {Token} |
| 218 | nm(A) ::= ID(X). {A = X;} |
| 219 | nm(A) ::= STRING(X). {A = X;} |
| 220 | nm(A) ::= JOIN_KW(X). {A = X;} |
| 221 | |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 222 | // A typetoken is really one or more tokens that form a type name such |
| 223 | // as can be found after the column name in a CREATE TABLE statement. |
| 224 | // Multiple tokens are concatenated to form the value of the typetoken. |
| 225 | // |
| 226 | %type typetoken {Token} |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 227 | type ::= . |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 228 | type ::= typetoken(X). {sqlite3AddColumnType(pParse,&X);} |
| 229 | typetoken(A) ::= typename(X). {A = X;} |
| 230 | typetoken(A) ::= typename(X) LP signed RP(Y). { |
| 231 | A.z = X.z; |
| 232 | A.n = &Y.z[Y.n] - X.z; |
| 233 | } |
| 234 | typetoken(A) ::= typename(X) LP signed COMMA signed RP(Y). { |
| 235 | A.z = X.z; |
| 236 | A.n = &Y.z[Y.n] - X.z; |
| 237 | } |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 238 | %type typename {Token} |
drh | e2ea40d | 2004-05-20 12:41:19 +0000 | [diff] [blame] | 239 | typename(A) ::= ids(X). {A = X;} |
drh | 596bd23 | 2004-09-30 14:22:47 +0000 | [diff] [blame] | 240 | typename(A) ::= typename(X) ids(Y). {A.z=X.z; A.n=Y.n+(Y.z-X.z);} |
drh | 60218d2 | 2007-04-06 11:26:00 +0000 | [diff] [blame] | 241 | signed ::= plus_num. |
| 242 | signed ::= minus_num. |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 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 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 247 | carglist ::= carglist carg. |
| 248 | carglist ::= . |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 249 | carg ::= CONSTRAINT nm ccons. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 250 | carg ::= ccons. |
drh | 2b7acc3 | 2006-12-20 02:15:00 +0000 | [diff] [blame] | 251 | ccons ::= DEFAULT term(X). {sqlite3AddDefaultValue(pParse,X);} |
| 252 | ccons ::= DEFAULT LP expr(X) RP. {sqlite3AddDefaultValue(pParse,X);} |
| 253 | ccons ::= DEFAULT PLUS term(X). {sqlite3AddDefaultValue(pParse,X);} |
| 254 | ccons ::= DEFAULT MINUS term(X). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 255 | Expr *p = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0); |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 256 | sqlite3AddDefaultValue(pParse,p); |
| 257 | } |
drh | 2b7acc3 | 2006-12-20 02:15:00 +0000 | [diff] [blame] | 258 | ccons ::= DEFAULT id(X). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 259 | Expr *p = sqlite3PExpr(pParse, TK_STRING, 0, 0, &X); |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 260 | sqlite3AddDefaultValue(pParse,p); |
| 261 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 262 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 263 | // In addition to the type name, we also care about the primary key and |
| 264 | // UNIQUE constraints. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 265 | // |
drh | 0d316a4 | 2002-08-11 20:10:47 +0000 | [diff] [blame] | 266 | ccons ::= NULL onconf. |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 267 | ccons ::= NOT NULL onconf(R). {sqlite3AddNotNull(pParse, R);} |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 268 | ccons ::= PRIMARY KEY sortorder(Z) onconf(R) autoinc(I). |
| 269 | {sqlite3AddPrimaryKey(pParse,0,R,I,Z);} |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 270 | ccons ::= UNIQUE onconf(R). {sqlite3CreateIndex(pParse,0,0,0,0,R,0,0,0,0);} |
drh | 06f6541 | 2005-11-03 02:03:13 +0000 | [diff] [blame] | 271 | ccons ::= CHECK LP expr(X) RP. {sqlite3AddCheckConstraint(pParse,X);} |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 272 | ccons ::= REFERENCES nm(T) idxlist_opt(TA) refargs(R). |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 273 | {sqlite3CreateForeignKey(pParse,0,&T,TA,R);} |
| 274 | ccons ::= defer_subclause(D). {sqlite3DeferForeignKey(pParse,D);} |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 275 | ccons ::= COLLATE ids(C). {sqlite3AddCollateType(pParse, &C);} |
drh | 04738cb | 2002-06-02 18:19:00 +0000 | [diff] [blame] | 276 | |
drh | 205f48e | 2004-11-05 00:43:11 +0000 | [diff] [blame] | 277 | // The optional AUTOINCREMENT keyword |
| 278 | %type autoinc {int} |
drh | 2958a4e | 2004-11-12 03:56:15 +0000 | [diff] [blame] | 279 | autoinc(X) ::= . {X = 0;} |
| 280 | autoinc(X) ::= AUTOINCR. {X = 1;} |
drh | 205f48e | 2004-11-05 00:43:11 +0000 | [diff] [blame] | 281 | |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 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. |
drh | 04738cb | 2002-06-02 18:19:00 +0000 | [diff] [blame] | 286 | // |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 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;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 307 | |
| 308 | // For the time being, the only constraint we care about is the primary |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 309 | // key and UNIQUE. Both create indices. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 310 | // |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 311 | conslist_opt(A) ::= . {A.n = 0; A.z = 0;} |
| 312 | conslist_opt(A) ::= COMMA(X) conslist. {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 313 | conslist ::= conslist COMMA tcons. |
drh | a2e1bb5 | 2001-01-04 14:20:18 +0000 | [diff] [blame] | 314 | conslist ::= conslist tcons. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 315 | conslist ::= tcons. |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 316 | tcons ::= CONSTRAINT nm. |
drh | f338814 | 2004-11-13 03:48:06 +0000 | [diff] [blame] | 317 | tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R). |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 318 | {sqlite3AddPrimaryKey(pParse,X,R,I,0);} |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 319 | tcons ::= UNIQUE LP idxlist(X) RP onconf(R). |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 320 | {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);} |
drh | 06f6541 | 2005-11-03 02:03:13 +0000 | [diff] [blame] | 321 | tcons ::= CHECK LP expr(E) RP onconf. {sqlite3AddCheckConstraint(pParse,E);} |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 322 | tcons ::= FOREIGN KEY LP idxlist(FA) RP |
| 323 | REFERENCES nm(T) idxlist_opt(TA) refargs(R) defer_subclause_opt(D). { |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 324 | sqlite3CreateForeignKey(pParse, FA, &T, TA, R); |
| 325 | sqlite3DeferForeignKey(pParse, D); |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 326 | } |
| 327 | %type defer_subclause_opt {int} |
| 328 | defer_subclause_opt(A) ::= . {A = 0;} |
| 329 | defer_subclause_opt(A) ::= defer_subclause(X). {A = X;} |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 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} |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 335 | %type orconf {int} |
| 336 | %type resolvetype {int} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 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;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 344 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 345 | ////////////////////////// The DROP TABLE ///////////////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 346 | // |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 347 | cmd ::= DROP TABLE ifexists(E) fullname(X). { |
| 348 | sqlite3DropTable(pParse, X, 0, E); |
danielk1977 | a885810 | 2004-05-28 12:11:21 +0000 | [diff] [blame] | 349 | } |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 350 | %type ifexists {int} |
| 351 | ifexists(A) ::= IF EXISTS. {A = 1;} |
| 352 | ifexists(A) ::= . {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 353 | |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 354 | ///////////////////// The CREATE VIEW statement ///////////////////////////// |
| 355 | // |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 356 | %ifndef SQLITE_OMIT_VIEW |
drh | fdd48a7 | 2006-09-11 23:45:48 +0000 | [diff] [blame] | 357 | cmd ::= CREATE(X) temp(T) VIEW ifnotexists(E) nm(Y) dbnm(Z) AS select(S). { |
| 358 | sqlite3CreateView(pParse, &X, &Y, &Z, S, T, E); |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 359 | } |
drh | a073384 | 2005-12-29 01:11:36 +0000 | [diff] [blame] | 360 | cmd ::= DROP VIEW ifexists(E) fullname(X). { |
| 361 | sqlite3DropTable(pParse, X, 1, E); |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 362 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 363 | %endif SQLITE_OMIT_VIEW |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 364 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 365 | //////////////////////// The SELECT statement ///////////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 366 | // |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 367 | cmd ::= select(X). { |
danielk1977 | b3bce66 | 2005-01-29 08:32:43 +0000 | [diff] [blame] | 368 | sqlite3Select(pParse, X, SRT_Callback, 0, 0, 0, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 369 | sqlite3SelectDelete(X); |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 370 | } |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 371 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 372 | %type select {Select*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 373 | %destructor select {sqlite3SelectDelete($$);} |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 374 | %type oneselect {Select*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 375 | %destructor oneselect {sqlite3SelectDelete($$);} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 376 | |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 377 | select(A) ::= oneselect(X). {A = X;} |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 378 | %ifndef SQLITE_OMIT_COMPOUND_SELECT |
drh | 0a36c57 | 2002-02-18 22:49:59 +0000 | [diff] [blame] | 379 | select(A) ::= select(X) multiselect_op(Y) oneselect(Z). { |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 380 | if( Z ){ |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 381 | Z->op = Y; |
| 382 | Z->pPrior = X; |
drh | 43b7882 | 2007-06-15 17:03:14 +0000 | [diff] [blame] | 383 | }else{ |
| 384 | sqlite3SelectDelete(X); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 385 | } |
| 386 | A = Z; |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 387 | } |
drh | 0a36c57 | 2002-02-18 22:49:59 +0000 | [diff] [blame] | 388 | %type multiselect_op {int} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 389 | multiselect_op(A) ::= UNION(OP). {A = @OP;} |
| 390 | multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} |
| 391 | multiselect_op(A) ::= EXCEPT|INTERSECT(OP). {A = @OP;} |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 392 | %endif SQLITE_OMIT_COMPOUND_SELECT |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 393 | oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 394 | groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 395 | A = sqlite3SelectNew(pParse,W,X,Y,P,Q,Z,D,L.pLimit,L.pOffset); |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // The "distinct" nonterminal is true (1) if the DISTINCT keyword is |
| 399 | // present and false (0) if it is not. |
| 400 | // |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 401 | %type distinct {int} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 402 | distinct(A) ::= DISTINCT. {A = 1;} |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 403 | distinct(A) ::= ALL. {A = 0;} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 404 | distinct(A) ::= . {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 405 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 406 | // selcollist is a list of expressions that are to become the return |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 407 | // values of the SELECT statement. The "*" in statements like |
| 408 | // "SELECT * FROM ..." is encoded as a special expression with an |
| 409 | // opcode of TK_ALL. |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 410 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 411 | %type selcollist {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 412 | %destructor selcollist {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 413 | %type sclp {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 414 | %destructor sclp {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 415 | sclp(A) ::= selcollist(X) COMMA. {A = X;} |
| 416 | sclp(A) ::= . {A = 0;} |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 417 | selcollist(A) ::= sclp(P) expr(X) as(Y). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 418 | A = sqlite3ExprListAppend(pParse,P,X,Y.n?&Y:0); |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 419 | } |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 420 | selcollist(A) ::= sclp(P) STAR. { |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 421 | Expr *p = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 422 | A = sqlite3ExprListAppend(pParse, P, p, 0); |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 423 | } |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 424 | selcollist(A) ::= sclp(P) nm(X) DOT STAR. { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 425 | Expr *pRight = sqlite3PExpr(pParse, TK_ALL, 0, 0, 0); |
| 426 | Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); |
| 427 | Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); |
| 428 | A = sqlite3ExprListAppend(pParse,P, pDot, 0); |
drh | 5447322 | 2002-04-04 02:10:55 +0000 | [diff] [blame] | 429 | } |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 430 | |
| 431 | // An option "AS <id>" phrase that can follow one of the expressions that |
| 432 | // define the result set, or one of the tables in the FROM clause. |
| 433 | // |
| 434 | %type as {Token} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 435 | as(X) ::= AS nm(Y). {X = Y;} |
| 436 | as(X) ::= ids(Y). {X = Y;} |
| 437 | as(X) ::= . {X.n = 0;} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 438 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 439 | |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 440 | %type seltablist {SrcList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 441 | %destructor seltablist {sqlite3SrcListDelete($$);} |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 442 | %type stl_prefix {SrcList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 443 | %destructor stl_prefix {sqlite3SrcListDelete($$);} |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 444 | %type from {SrcList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 445 | %destructor from {sqlite3SrcListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 446 | |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 447 | // A complete FROM clause. |
| 448 | // |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 449 | from(A) ::= . {A = sqlite3DbMallocZero(pParse->db, sizeof(*A));} |
| 450 | from(A) ::= FROM seltablist(X). { |
drh | 61dfc31 | 2006-12-16 16:25:15 +0000 | [diff] [blame] | 451 | A = X; |
| 452 | sqlite3SrcListShiftJoinType(A); |
| 453 | } |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 454 | |
| 455 | // "seltablist" is a "Select Table List" - the content of the FROM clause |
| 456 | // in a SELECT statement. "stl_prefix" is a prefix of this list. |
| 457 | // |
| 458 | stl_prefix(A) ::= seltablist(X) joinop(Y). { |
| 459 | A = X; |
| 460 | if( A && A->nSrc>0 ) A->a[A->nSrc-1].jointype = Y; |
| 461 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 462 | stl_prefix(A) ::= . {A = 0;} |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 463 | seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) on_opt(N) using_opt(U). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 464 | A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U); |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 465 | } |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 466 | %ifndef SQLITE_OMIT_SUBQUERY |
| 467 | seltablist(A) ::= stl_prefix(X) LP seltablist_paren(S) RP |
| 468 | as(Z) on_opt(N) using_opt(U). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 469 | A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U); |
drh | d5feede | 2002-05-08 21:46:14 +0000 | [diff] [blame] | 470 | } |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 471 | |
danielk1977 | 955de52 | 2006-02-10 02:27:42 +0000 | [diff] [blame] | 472 | // A seltablist_paren nonterminal represents anything in a FROM that |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 473 | // is contained inside parentheses. This can be either a subquery or |
| 474 | // a grouping of table and subqueries. |
| 475 | // |
| 476 | %type seltablist_paren {Select*} |
| 477 | %destructor seltablist_paren {sqlite3SelectDelete($$);} |
| 478 | seltablist_paren(A) ::= select(S). {A = S;} |
| 479 | seltablist_paren(A) ::= seltablist(F). { |
drh | 61dfc31 | 2006-12-16 16:25:15 +0000 | [diff] [blame] | 480 | sqlite3SrcListShiftJoinType(F); |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 481 | A = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0); |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 482 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 483 | %endif SQLITE_OMIT_SUBQUERY |
drh | b733d03 | 2004-01-24 20:18:12 +0000 | [diff] [blame] | 484 | |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 485 | %type dbnm {Token} |
| 486 | dbnm(A) ::= . {A.z=0; A.n=0;} |
| 487 | dbnm(A) ::= DOT nm(X). {A = X;} |
| 488 | |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 489 | %type fullname {SrcList*} |
| 490 | %destructor fullname {sqlite3SrcListDelete($$);} |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 491 | fullname(A) ::= nm(X) dbnm(Y). {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y);} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 492 | |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 493 | %type joinop {int} |
| 494 | %type joinop2 {int} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 495 | joinop(X) ::= COMMA|JOIN. { X = JT_INNER; } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 496 | joinop(X) ::= JOIN_KW(A) JOIN. { X = sqlite3JoinType(pParse,&A,0,0); } |
| 497 | 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] | 498 | joinop(X) ::= JOIN_KW(A) nm(B) nm(C) JOIN. |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 499 | { X = sqlite3JoinType(pParse,&A,&B,&C); } |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 500 | |
| 501 | %type on_opt {Expr*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 502 | %destructor on_opt {sqlite3ExprDelete($$);} |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 503 | on_opt(N) ::= ON expr(E). {N = E;} |
| 504 | on_opt(N) ::= . {N = 0;} |
| 505 | |
| 506 | %type using_opt {IdList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 507 | %destructor using_opt {sqlite3IdListDelete($$);} |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 508 | using_opt(U) ::= USING LP inscollist(L) RP. {U = L;} |
drh | 01f3f25 | 2002-05-24 16:14:15 +0000 | [diff] [blame] | 509 | using_opt(U) ::= . {U = 0;} |
| 510 | |
| 511 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 512 | %type orderby_opt {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 513 | %destructor orderby_opt {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 514 | %type sortlist {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 515 | %destructor sortlist {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 516 | %type sortitem {Expr*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 517 | %destructor sortitem {sqlite3ExprDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 518 | |
| 519 | orderby_opt(A) ::= . {A = 0;} |
| 520 | orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} |
drh | 8b4c40d | 2007-02-01 23:02:45 +0000 | [diff] [blame] | 521 | sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 522 | A = sqlite3ExprListAppend(pParse,X,Y,0); |
drh | d3d39e9 | 2004-05-20 22:16:29 +0000 | [diff] [blame] | 523 | if( A ) A->a[A->nExpr-1].sortOrder = Z; |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 524 | } |
drh | 8b4c40d | 2007-02-01 23:02:45 +0000 | [diff] [blame] | 525 | sortlist(A) ::= sortitem(Y) sortorder(Z). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 526 | A = sqlite3ExprListAppend(pParse,0,Y,0); |
danielk1977 | 96fb0dd | 2004-06-30 09:49:22 +0000 | [diff] [blame] | 527 | if( A && A->a ) A->a[0].sortOrder = Z; |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 528 | } |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 529 | sortitem(A) ::= expr(X). {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 530 | |
| 531 | %type sortorder {int} |
| 532 | |
drh | 8e2ca02 | 2002-06-17 17:07:19 +0000 | [diff] [blame] | 533 | sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} |
| 534 | sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} |
| 535 | sortorder(A) ::= . {A = SQLITE_SO_ASC;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 536 | |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 537 | %type groupby_opt {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 538 | %destructor groupby_opt {sqlite3ExprListDelete($$);} |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 539 | groupby_opt(A) ::= . {A = 0;} |
drh | 9245c24 | 2007-06-20 12:18:31 +0000 | [diff] [blame] | 540 | groupby_opt(A) ::= GROUP BY nexprlist(X). {A = X;} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 541 | |
| 542 | %type having_opt {Expr*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 543 | %destructor having_opt {sqlite3ExprDelete($$);} |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 544 | having_opt(A) ::= . {A = 0;} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 545 | having_opt(A) ::= HAVING expr(X). {A = X;} |
| 546 | |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 547 | %type limit_opt {struct LimitVal} |
drh | 1592659 | 2007-04-06 15:02:13 +0000 | [diff] [blame] | 548 | |
| 549 | // The destructor for limit_opt will never fire in the current grammar. |
| 550 | // The limit_opt non-terminal only occurs at the end of a single production |
| 551 | // rule for SELECT statements. As soon as the rule that create the |
| 552 | // limit_opt non-terminal reduces, the SELECT statement rule will also |
| 553 | // reduce. So there is never a limit_opt non-terminal on the stack |
| 554 | // except as a transient. So there is never anything to destroy. |
| 555 | // |
| 556 | //%destructor limit_opt { |
| 557 | // sqlite3ExprDelete($$.pLimit); |
| 558 | // sqlite3ExprDelete($$.pOffset); |
| 559 | //} |
danielk1977 | a2dc3b1 | 2005-02-05 12:48:48 +0000 | [diff] [blame] | 560 | limit_opt(A) ::= . {A.pLimit = 0; A.pOffset = 0;} |
| 561 | limit_opt(A) ::= LIMIT expr(X). {A.pLimit = X; A.pOffset = 0;} |
| 562 | limit_opt(A) ::= LIMIT expr(X) OFFSET expr(Y). |
| 563 | {A.pLimit = X; A.pOffset = Y;} |
| 564 | limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). |
| 565 | {A.pOffset = X; A.pLimit = Y;} |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 566 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 567 | /////////////////////////// The DELETE statement ///////////////////////////// |
| 568 | // |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 569 | cmd ::= DELETE FROM fullname(X) where_opt(Y). {sqlite3DeleteFrom(pParse,X,Y);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 570 | |
| 571 | %type where_opt {Expr*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 572 | %destructor where_opt {sqlite3ExprDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 573 | |
| 574 | where_opt(A) ::= . {A = 0;} |
| 575 | where_opt(A) ::= WHERE expr(X). {A = X;} |
| 576 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 577 | ////////////////////////// The UPDATE command //////////////////////////////// |
| 578 | // |
danielk1977 | 7a15a4b | 2007-05-08 17:54:43 +0000 | [diff] [blame] | 579 | cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z). { |
| 580 | sqlite3ExprListCheckLength(pParse,Y,SQLITE_MAX_COLUMN,"set list"); |
| 581 | sqlite3Update(pParse,X,Y,Z,R); |
| 582 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 583 | |
drh | f8db1bc | 2005-04-22 02:38:37 +0000 | [diff] [blame] | 584 | %type setlist {ExprList*} |
| 585 | %destructor setlist {sqlite3ExprListDelete($$);} |
| 586 | |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 587 | setlist(A) ::= setlist(Z) COMMA nm(X) EQ expr(Y). |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 588 | {A = sqlite3ExprListAppend(pParse,Z,Y,&X);} |
| 589 | setlist(A) ::= nm(X) EQ expr(Y). |
| 590 | {A = sqlite3ExprListAppend(pParse,0,Y,&X);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 591 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 592 | ////////////////////////// The INSERT command ///////////////////////////////// |
| 593 | // |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 594 | cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 595 | VALUES LP itemlist(Y) RP. |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 596 | {sqlite3Insert(pParse, X, Y, 0, F, R);} |
| 597 | cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) select(S). |
| 598 | {sqlite3Insert(pParse, X, 0, S, F, R);} |
drh | 147d0cc | 2006-08-25 23:42:53 +0000 | [diff] [blame] | 599 | cmd ::= insert_cmd(R) INTO fullname(X) inscollist_opt(F) DEFAULT VALUES. |
| 600 | {sqlite3Insert(pParse, X, 0, 0, F, R);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 601 | |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 602 | %type insert_cmd {int} |
| 603 | insert_cmd(A) ::= INSERT orconf(R). {A = R;} |
| 604 | insert_cmd(A) ::= REPLACE. {A = OE_Replace;} |
| 605 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 606 | |
| 607 | %type itemlist {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 608 | %destructor itemlist {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 609 | |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 610 | itemlist(A) ::= itemlist(X) COMMA expr(Y). |
| 611 | {A = sqlite3ExprListAppend(pParse,X,Y,0);} |
| 612 | itemlist(A) ::= expr(X). |
| 613 | {A = sqlite3ExprListAppend(pParse,0,X,0);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 614 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 615 | %type inscollist_opt {IdList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 616 | %destructor inscollist_opt {sqlite3IdListDelete($$);} |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 617 | %type inscollist {IdList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 618 | %destructor inscollist {sqlite3IdListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 619 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 620 | inscollist_opt(A) ::= . {A = 0;} |
| 621 | inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;} |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 622 | inscollist(A) ::= inscollist(X) COMMA nm(Y). |
| 623 | {A = sqlite3IdListAppend(pParse->db,X,&Y);} |
| 624 | inscollist(A) ::= nm(Y). |
| 625 | {A = sqlite3IdListAppend(pParse->db,0,&Y);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 626 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 627 | /////////////////////////// Expression Processing ///////////////////////////// |
| 628 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 629 | |
| 630 | %type expr {Expr*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 631 | %destructor expr {sqlite3ExprDelete($$);} |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 632 | %type term {Expr*} |
| 633 | %destructor term {sqlite3ExprDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 634 | |
danielk1977 | 7977a17 | 2004-11-09 12:44:37 +0000 | [diff] [blame] | 635 | expr(A) ::= term(X). {A = X;} |
danielk1977 | 752e679 | 2004-11-09 16:13:33 +0000 | [diff] [blame] | 636 | expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqlite3ExprSpan(A,&B,&E); } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 637 | term(A) ::= NULL(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);} |
| 638 | expr(A) ::= ID(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);} |
| 639 | expr(A) ::= JOIN_KW(X). {A = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);} |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 640 | expr(A) ::= nm(X) DOT nm(Y). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 641 | Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); |
| 642 | Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y); |
| 643 | A = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 644 | } |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 645 | expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 646 | Expr *temp1 = sqlite3PExpr(pParse, TK_ID, 0, 0, &X); |
| 647 | Expr *temp2 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Y); |
| 648 | Expr *temp3 = sqlite3PExpr(pParse, TK_ID, 0, 0, &Z); |
| 649 | Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); |
| 650 | A = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); |
drh | d24cc42 | 2003-03-27 12:51:24 +0000 | [diff] [blame] | 651 | } |
drh | e9cf59e | 2007-11-17 22:23:27 +0000 | [diff] [blame^] | 652 | term(A) ::= INTEGER|FLOAT|BLOB(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);} |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 653 | term(A) ::= STRING(X). {A = sqlite3PExpr(pParse, @X, 0, 0, &X);} |
drh | 4e0cff6 | 2004-11-05 05:10:28 +0000 | [diff] [blame] | 654 | expr(A) ::= REGISTER(X). {A = sqlite3RegisterExpr(pParse, &X);} |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 655 | expr(A) ::= VARIABLE(X). { |
drh | 895d747 | 2004-08-20 16:02:39 +0000 | [diff] [blame] | 656 | Token *pToken = &X; |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 657 | Expr *pExpr = A = sqlite3PExpr(pParse, TK_VARIABLE, 0, 0, pToken); |
drh | fa6bc00 | 2004-09-07 16:19:52 +0000 | [diff] [blame] | 658 | sqlite3ExprAssignVarNumber(pParse, pExpr); |
drh | 7c972de | 2003-09-06 22:18:07 +0000 | [diff] [blame] | 659 | } |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 660 | expr(A) ::= expr(E) COLLATE ids(C). { |
drh | 8b4c40d | 2007-02-01 23:02:45 +0000 | [diff] [blame] | 661 | A = sqlite3ExprSetColl(pParse, E, &C); |
| 662 | } |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 663 | %ifndef SQLITE_OMIT_CAST |
| 664 | expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 665 | A = sqlite3PExpr(pParse, TK_CAST, E, 0, &T); |
drh | 487e262 | 2005-06-25 18:42:14 +0000 | [diff] [blame] | 666 | sqlite3ExprSpan(A,&X,&Y); |
| 667 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 668 | %endif SQLITE_OMIT_CAST |
drh | fd35797 | 2005-09-09 01:33:19 +0000 | [diff] [blame] | 669 | expr(A) ::= ID(X) LP distinct(D) exprlist(Y) RP(E). { |
danielk1977 | c9cf901 | 2007-05-30 10:36:47 +0000 | [diff] [blame] | 670 | if( Y && Y->nExpr>SQLITE_MAX_FUNCTION_ARG ){ |
drh | e5c941b | 2007-05-08 13:58:26 +0000 | [diff] [blame] | 671 | sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X); |
drh | 4e05c83 | 2007-05-11 01:44:50 +0000 | [diff] [blame] | 672 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 673 | A = sqlite3ExprFunction(pParse, Y, &X); |
drh | 4e05c83 | 2007-05-11 01:44:50 +0000 | [diff] [blame] | 674 | sqlite3ExprSpan(A,&X,&E); |
| 675 | if( D && A ){ |
| 676 | A->flags |= EP_Distinct; |
drh | fd35797 | 2005-09-09 01:33:19 +0000 | [diff] [blame] | 677 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 678 | } |
| 679 | expr(A) ::= ID(X) LP STAR RP(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 680 | A = sqlite3ExprFunction(pParse, 0, &X); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 681 | sqlite3ExprSpan(A,&X,&E); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 682 | } |
drh | b71090f | 2005-05-23 17:26:51 +0000 | [diff] [blame] | 683 | term(A) ::= CTIME_KW(OP). { |
| 684 | /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are |
| 685 | ** treated as functions that return constants */ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 686 | A = sqlite3ExprFunction(pParse, 0,&OP); |
drh | 417ec63 | 2006-08-14 14:23:41 +0000 | [diff] [blame] | 687 | if( A ){ |
| 688 | A->op = TK_CONST_FUNC; |
| 689 | A->span = OP; |
| 690 | } |
drh | b71090f | 2005-05-23 17:26:51 +0000 | [diff] [blame] | 691 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 692 | expr(A) ::= expr(X) AND(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 693 | expr(A) ::= expr(X) OR(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 694 | expr(A) ::= expr(X) LT|GT|GE|LE(OP) expr(Y). |
| 695 | {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 696 | expr(A) ::= expr(X) EQ|NE(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 697 | expr(A) ::= expr(X) BITAND|BITOR|LSHIFT|RSHIFT(OP) expr(Y). |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 698 | {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 699 | expr(A) ::= expr(X) PLUS|MINUS(OP) expr(Y).{A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 700 | expr(A) ::= expr(X) STAR|SLASH|REM(OP) expr(Y). |
| 701 | {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
| 702 | expr(A) ::= expr(X) CONCAT(OP) expr(Y). {A = sqlite3PExpr(pParse,@OP,X,Y,0);} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 703 | %type likeop {struct LikeOp} |
drh | b52076c | 2006-01-23 13:22:09 +0000 | [diff] [blame] | 704 | likeop(A) ::= LIKE_KW(X). {A.eOperator = X; A.not = 0;} |
| 705 | likeop(A) ::= NOT LIKE_KW(X). {A.eOperator = X; A.not = 1;} |
drh | 03bea70 | 2006-06-13 15:37:26 +0000 | [diff] [blame] | 706 | likeop(A) ::= MATCH(X). {A.eOperator = X; A.not = 0;} |
| 707 | likeop(A) ::= NOT MATCH(X). {A.eOperator = X; A.not = 1;} |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 708 | %type escape {Expr*} |
danielk1977 | dba99bc | 2006-01-07 14:02:26 +0000 | [diff] [blame] | 709 | %destructor escape {sqlite3ExprDelete($$);} |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 710 | escape(X) ::= ESCAPE expr(A). [ESCAPE] {X = A;} |
| 711 | escape(X) ::= . [ESCAPE] {X = 0;} |
drh | b71090f | 2005-05-23 17:26:51 +0000 | [diff] [blame] | 712 | expr(A) ::= expr(X) likeop(OP) expr(Y) escape(E). [LIKE_KW] { |
drh | 8aa34ae | 2006-03-13 12:54:09 +0000 | [diff] [blame] | 713 | ExprList *pList; |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 714 | pList = sqlite3ExprListAppend(pParse,0, Y, 0); |
| 715 | pList = sqlite3ExprListAppend(pParse,pList, X, 0); |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 716 | if( E ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 717 | pList = sqlite3ExprListAppend(pParse,pList, E, 0); |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 718 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 719 | A = sqlite3ExprFunction(pParse, pList, &OP.eOperator); |
| 720 | if( OP.not ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 721 | sqlite3ExprSpan(A, &X->span, &Y->span); |
drh | 6a03a1c | 2006-07-08 18:34:59 +0000 | [diff] [blame] | 722 | if( A ) A->flags |= EP_InfixFunc; |
drh | 0ac6589 | 2002-04-20 14:24:41 +0000 | [diff] [blame] | 723 | } |
danielk1977 | 7c6303c | 2004-11-17 16:41:29 +0000 | [diff] [blame] | 724 | |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 725 | expr(A) ::= expr(X) ISNULL|NOTNULL(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 726 | A = sqlite3PExpr(pParse, @E, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 727 | sqlite3ExprSpan(A,&X->span,&E); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 728 | } |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 729 | expr(A) ::= expr(X) IS NULL(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 730 | A = sqlite3PExpr(pParse, TK_ISNULL, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 731 | sqlite3ExprSpan(A,&X->span,&E); |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 732 | } |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 733 | expr(A) ::= expr(X) NOT NULL(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 734 | A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 735 | sqlite3ExprSpan(A,&X->span,&E); |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 736 | } |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 737 | expr(A) ::= expr(X) IS NOT NULL(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 738 | A = sqlite3PExpr(pParse, TK_NOTNULL, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 739 | sqlite3ExprSpan(A,&X->span,&E); |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 740 | } |
drh | e9cf59e | 2007-11-17 22:23:27 +0000 | [diff] [blame^] | 741 | expr(A) ::= NOT(B) expr(X). { |
| 742 | A = sqlite3PExpr(pParse, @B, X, 0, 0); |
| 743 | sqlite3ExprSpan(A,&B,&X->span); |
| 744 | } |
| 745 | expr(A) ::= BITNOT(B) expr(X). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 746 | A = sqlite3PExpr(pParse, @B, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 747 | sqlite3ExprSpan(A,&B,&X->span); |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 748 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 749 | expr(A) ::= MINUS(B) expr(X). [UMINUS] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 750 | A = sqlite3PExpr(pParse, TK_UMINUS, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 751 | sqlite3ExprSpan(A,&B,&X->span); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 752 | } |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 753 | expr(A) ::= PLUS(B) expr(X). [UPLUS] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 754 | A = sqlite3PExpr(pParse, TK_UPLUS, X, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 755 | sqlite3ExprSpan(A,&B,&X->span); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 756 | } |
drh | 2e3a1f1 | 2004-10-06 14:39:28 +0000 | [diff] [blame] | 757 | %type between_op {int} |
| 758 | between_op(A) ::= BETWEEN. {A = 0;} |
| 759 | between_op(A) ::= NOT BETWEEN. {A = 1;} |
| 760 | expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 761 | ExprList *pList = sqlite3ExprListAppend(pParse,0, X, 0); |
| 762 | pList = sqlite3ExprListAppend(pParse,pList, Y, 0); |
| 763 | A = sqlite3PExpr(pParse, TK_BETWEEN, W, 0, 0); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 764 | if( A ){ |
| 765 | A->pList = pList; |
| 766 | }else{ |
| 767 | sqlite3ExprListDelete(pList); |
| 768 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 769 | if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0); |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 770 | sqlite3ExprSpan(A,&W->span,&Y->span); |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 771 | } |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 772 | %ifndef SQLITE_OMIT_SUBQUERY |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 773 | %type in_op {int} |
| 774 | in_op(A) ::= IN. {A = 0;} |
| 775 | in_op(A) ::= NOT IN. {A = 1;} |
| 776 | expr(A) ::= expr(X) in_op(N) LP exprlist(Y) RP(E). [IN] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 777 | A = sqlite3PExpr(pParse, TK_IN, X, 0, 0); |
danielk1977 | d5d5652 | 2005-03-16 12:15:20 +0000 | [diff] [blame] | 778 | if( A ){ |
| 779 | A->pList = Y; |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 780 | sqlite3ExprSetHeight(A); |
danielk1977 | d5d5652 | 2005-03-16 12:15:20 +0000 | [diff] [blame] | 781 | }else{ |
| 782 | sqlite3ExprListDelete(Y); |
| 783 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 784 | if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0); |
danielk1977 | 3e8c37e | 2005-01-21 03:12:14 +0000 | [diff] [blame] | 785 | sqlite3ExprSpan(A,&X->span,&E); |
| 786 | } |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 787 | expr(A) ::= LP(B) select(X) RP(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 788 | A = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 789 | if( A ){ |
| 790 | A->pSelect = X; |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 791 | sqlite3ExprSetHeight(A); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 792 | }else{ |
| 793 | sqlite3SelectDelete(X); |
| 794 | } |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 795 | sqlite3ExprSpan(A,&B,&E); |
| 796 | } |
| 797 | expr(A) ::= expr(X) in_op(N) LP select(Y) RP(E). [IN] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 798 | A = sqlite3PExpr(pParse, TK_IN, X, 0, 0); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 799 | if( A ){ |
| 800 | A->pSelect = Y; |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 801 | sqlite3ExprSetHeight(A); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 802 | }else{ |
| 803 | sqlite3SelectDelete(Y); |
| 804 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 805 | if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0); |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 806 | sqlite3ExprSpan(A,&X->span,&E); |
| 807 | } |
| 808 | expr(A) ::= expr(X) in_op(N) nm(Y) dbnm(Z). [IN] { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 809 | SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z); |
| 810 | A = sqlite3PExpr(pParse, TK_IN, X, 0, 0); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 811 | if( A ){ |
danielk1977 | 1e53695 | 2007-08-16 10:09:01 +0000 | [diff] [blame] | 812 | A->pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 813 | sqlite3ExprSetHeight(A); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 814 | }else{ |
| 815 | sqlite3SrcListDelete(pSrc); |
| 816 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 817 | if( N ) A = sqlite3PExpr(pParse, TK_NOT, A, 0, 0); |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 818 | sqlite3ExprSpan(A,&X->span,Z.z?&Z:&Y); |
| 819 | } |
| 820 | expr(A) ::= EXISTS(B) LP select(Y) RP(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 821 | Expr *p = A = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 822 | if( p ){ |
| 823 | p->pSelect = Y; |
| 824 | sqlite3ExprSpan(p,&B,&E); |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 825 | sqlite3ExprSetHeight(A); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 826 | }else{ |
| 827 | sqlite3SelectDelete(Y); |
drh | 51522cd | 2005-01-20 13:36:19 +0000 | [diff] [blame] | 828 | } |
| 829 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 830 | %endif SQLITE_OMIT_SUBQUERY |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 831 | |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 832 | /* CASE expressions */ |
| 833 | expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 834 | A = sqlite3PExpr(pParse, TK_CASE, X, Z, 0); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 835 | if( A ){ |
| 836 | A->pList = Y; |
danielk1977 | fc97606 | 2007-05-10 10:46:56 +0000 | [diff] [blame] | 837 | sqlite3ExprSetHeight(A); |
drh | 53f733c | 2005-09-16 02:38:09 +0000 | [diff] [blame] | 838 | }else{ |
| 839 | sqlite3ExprListDelete(Y); |
| 840 | } |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 841 | sqlite3ExprSpan(A, &C, &E); |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 842 | } |
| 843 | %type case_exprlist {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 844 | %destructor case_exprlist {sqlite3ExprListDelete($$);} |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 845 | case_exprlist(A) ::= case_exprlist(X) WHEN expr(Y) THEN expr(Z). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 846 | A = sqlite3ExprListAppend(pParse,X, Y, 0); |
| 847 | A = sqlite3ExprListAppend(pParse,A, Z, 0); |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 848 | } |
| 849 | case_exprlist(A) ::= WHEN expr(Y) THEN expr(Z). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 850 | A = sqlite3ExprListAppend(pParse,0, Y, 0); |
| 851 | A = sqlite3ExprListAppend(pParse,A, Z, 0); |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 852 | } |
| 853 | %type case_else {Expr*} |
danielk1977 | dba99bc | 2006-01-07 14:02:26 +0000 | [diff] [blame] | 854 | %destructor case_else {sqlite3ExprDelete($$);} |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 855 | case_else(A) ::= ELSE expr(X). {A = X;} |
| 856 | case_else(A) ::= . {A = 0;} |
| 857 | %type case_operand {Expr*} |
danielk1977 | dba99bc | 2006-01-07 14:02:26 +0000 | [diff] [blame] | 858 | %destructor case_operand {sqlite3ExprDelete($$);} |
drh | 17a7f8d | 2002-03-24 13:13:27 +0000 | [diff] [blame] | 859 | case_operand(A) ::= expr(X). {A = X;} |
| 860 | case_operand(A) ::= . {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 861 | |
| 862 | %type exprlist {ExprList*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 863 | %destructor exprlist {sqlite3ExprListDelete($$);} |
drh | 9245c24 | 2007-06-20 12:18:31 +0000 | [diff] [blame] | 864 | %type nexprlist {ExprList*} |
| 865 | %destructor nexprlist {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 866 | |
drh | 9245c24 | 2007-06-20 12:18:31 +0000 | [diff] [blame] | 867 | exprlist(A) ::= nexprlist(X). {A = X;} |
| 868 | exprlist(A) ::= . {A = 0;} |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 869 | nexprlist(A) ::= nexprlist(X) COMMA expr(Y). |
| 870 | {A = sqlite3ExprListAppend(pParse,X,Y,0);} |
| 871 | nexprlist(A) ::= expr(Y). |
| 872 | {A = sqlite3ExprListAppend(pParse,0,Y,0);} |
drh | 9245c24 | 2007-06-20 12:18:31 +0000 | [diff] [blame] | 873 | |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 874 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 875 | ///////////////////////////// The CREATE INDEX command /////////////////////// |
| 876 | // |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 877 | cmd ::= CREATE(S) uniqueflag(U) INDEX ifnotexists(NE) nm(X) dbnm(D) |
drh | 77e96d1 | 2006-01-30 23:04:51 +0000 | [diff] [blame] | 878 | ON nm(Y) LP idxlist(Z) RP(E). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 879 | sqlite3CreateIndex(pParse, &X, &D, |
| 880 | sqlite3SrcListAppend(pParse->db,0,&Y,0), Z, U, |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 881 | &S, &E, SQLITE_SO_ASC, NE); |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 882 | } |
drh | 717e640 | 2001-09-27 03:22:32 +0000 | [diff] [blame] | 883 | |
| 884 | %type uniqueflag {int} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 885 | uniqueflag(A) ::= UNIQUE. {A = OE_Abort;} |
| 886 | uniqueflag(A) ::= . {A = OE_None;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 887 | |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 888 | %type idxlist {ExprList*} |
| 889 | %destructor idxlist {sqlite3ExprListDelete($$);} |
| 890 | %type idxlist_opt {ExprList*} |
| 891 | %destructor idxlist_opt {sqlite3ExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 892 | %type idxitem {Token} |
| 893 | |
drh | c2eef3b | 2002-08-31 18:53:06 +0000 | [diff] [blame] | 894 | idxlist_opt(A) ::= . {A = 0;} |
| 895 | idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 896 | idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). { |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 897 | Expr *p = 0; |
| 898 | if( C.n>0 ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 899 | p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 900 | sqlite3ExprSetColl(pParse, p, &C); |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 901 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 902 | A = sqlite3ExprListAppend(pParse,X, p, &Y); |
danielk1977 | 7a15a4b | 2007-05-08 17:54:43 +0000 | [diff] [blame] | 903 | sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index"); |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 904 | if( A ) A->a[A->nExpr-1].sortOrder = Z; |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 905 | } |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 906 | idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). { |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 907 | Expr *p = 0; |
| 908 | if( C.n>0 ){ |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 909 | p = sqlite3PExpr(pParse, TK_COLUMN, 0, 0, 0); |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 910 | sqlite3ExprSetColl(pParse, p, &C); |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 911 | } |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 912 | A = sqlite3ExprListAppend(pParse,0, p, &Y); |
danielk1977 | 7a15a4b | 2007-05-08 17:54:43 +0000 | [diff] [blame] | 913 | sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index"); |
drh | fdd6e85 | 2005-12-16 01:06:16 +0000 | [diff] [blame] | 914 | if( A ) A->a[A->nExpr-1].sortOrder = Z; |
danielk1977 | 0202b29 | 2004-06-09 09:55:16 +0000 | [diff] [blame] | 915 | } |
| 916 | idxitem(A) ::= nm(X). {A = X;} |
| 917 | |
drh | a34001c | 2007-02-02 12:44:37 +0000 | [diff] [blame] | 918 | %type collate {Token} |
| 919 | collate(C) ::= . {C.z = 0; C.n = 0;} |
danielk1977 | 3900250 | 2007-11-12 09:50:26 +0000 | [diff] [blame] | 920 | collate(C) ::= COLLATE ids(X). {C = X;} |
drh | a34001c | 2007-02-02 12:44:37 +0000 | [diff] [blame] | 921 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 922 | |
drh | 8aff101 | 2001-12-22 14:49:24 +0000 | [diff] [blame] | 923 | ///////////////////////////// The DROP INDEX command ///////////////////////// |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 924 | // |
drh | 4d91a70 | 2006-01-04 15:54:36 +0000 | [diff] [blame] | 925 | cmd ::= DROP INDEX ifexists(E) fullname(X). {sqlite3DropIndex(pParse, X, E);} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 926 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 927 | ///////////////////////////// The VACUUM command ///////////////////////////// |
| 928 | // |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 929 | %ifndef SQLITE_OMIT_VACUUM |
drh | fdbcdee | 2007-03-27 14:44:50 +0000 | [diff] [blame] | 930 | %ifndef SQLITE_OMIT_ATTACH |
drh | 7416170 | 2006-02-24 02:53:49 +0000 | [diff] [blame] | 931 | cmd ::= VACUUM. {sqlite3Vacuum(pParse);} |
| 932 | cmd ::= VACUUM nm. {sqlite3Vacuum(pParse);} |
drh | fdbcdee | 2007-03-27 14:44:50 +0000 | [diff] [blame] | 933 | %endif SQLITE_OMIT_ATTACH |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 934 | %endif SQLITE_OMIT_VACUUM |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 935 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 936 | ///////////////////////////// The PRAGMA command ///////////////////////////// |
| 937 | // |
drh | 13d7042 | 2004-11-13 15:59:14 +0000 | [diff] [blame] | 938 | %ifndef SQLITE_OMIT_PRAGMA |
drh | a3eb4b4 | 2007-01-27 02:38:29 +0000 | [diff] [blame] | 939 | cmd ::= PRAGMA nm(X) dbnm(Z) EQ nmnum(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);} |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 940 | cmd ::= PRAGMA nm(X) dbnm(Z) EQ ON(Y). {sqlite3Pragma(pParse,&X,&Z,&Y,0);} |
danielk1977 | 91cf71b | 2004-06-26 06:37:06 +0000 | [diff] [blame] | 941 | cmd ::= PRAGMA nm(X) dbnm(Z) EQ minus_num(Y). { |
| 942 | sqlite3Pragma(pParse,&X,&Z,&Y,1); |
| 943 | } |
drh | a3eb4b4 | 2007-01-27 02:38:29 +0000 | [diff] [blame] | 944 | cmd ::= PRAGMA nm(X) dbnm(Z) LP nmnum(Y) RP. {sqlite3Pragma(pParse,&X,&Z,&Y,0);} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 945 | cmd ::= PRAGMA nm(X) dbnm(Z). {sqlite3Pragma(pParse,&X,&Z,0,0);} |
drh | a3eb4b4 | 2007-01-27 02:38:29 +0000 | [diff] [blame] | 946 | nmnum(A) ::= plus_num(X). {A = X;} |
| 947 | nmnum(A) ::= nm(X). {A = X;} |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 948 | %endif SQLITE_OMIT_PRAGMA |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 949 | plus_num(A) ::= plus_opt number(X). {A = X;} |
| 950 | minus_num(A) ::= MINUS number(X). {A = X;} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 951 | number(A) ::= INTEGER|FLOAT(X). {A = X;} |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 952 | plus_opt ::= PLUS. |
| 953 | plus_opt ::= . |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 954 | |
| 955 | //////////////////////////// The CREATE TRIGGER command ///////////////////// |
drh | f0f258b | 2003-04-21 18:48:45 +0000 | [diff] [blame] | 956 | |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 957 | %ifndef SQLITE_OMIT_TRIGGER |
| 958 | |
danielk1977 | 3df6b25 | 2004-05-29 10:23:19 +0000 | [diff] [blame] | 959 | cmd ::= CREATE trigger_decl(A) BEGIN trigger_cmd_list(S) END(Z). { |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 960 | Token all; |
| 961 | all.z = A.z; |
| 962 | all.n = (Z.z - A.z) + Z.n; |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 963 | sqlite3FinishTrigger(pParse, S, &all); |
drh | f0f258b | 2003-04-21 18:48:45 +0000 | [diff] [blame] | 964 | } |
| 965 | |
drh | fdd48a7 | 2006-09-11 23:45:48 +0000 | [diff] [blame] | 966 | trigger_decl(A) ::= temp(T) TRIGGER ifnotexists(NOERR) nm(B) dbnm(Z) |
| 967 | trigger_time(C) trigger_event(D) |
drh | 60218d2 | 2007-04-06 11:26:00 +0000 | [diff] [blame] | 968 | ON fullname(E) foreach_clause when_clause(G). { |
| 969 | sqlite3BeginTrigger(pParse, &B, &Z, C, D.a, D.b, E, G, T, NOERR); |
danielk1977 | 3df6b25 | 2004-05-29 10:23:19 +0000 | [diff] [blame] | 970 | A = (Z.n==0?B:Z); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | %type trigger_time {int} |
| 974 | trigger_time(A) ::= BEFORE. { A = TK_BEFORE; } |
| 975 | trigger_time(A) ::= AFTER. { A = TK_AFTER; } |
| 976 | trigger_time(A) ::= INSTEAD OF. { A = TK_INSTEAD;} |
| 977 | trigger_time(A) ::= . { A = TK_BEFORE; } |
| 978 | |
drh | ad3cab5 | 2002-05-24 02:04:32 +0000 | [diff] [blame] | 979 | %type trigger_event {struct TrigEvent} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 980 | %destructor trigger_event {sqlite3IdListDelete($$.b);} |
drh | fd40531 | 2005-11-06 04:06:59 +0000 | [diff] [blame] | 981 | trigger_event(A) ::= DELETE|INSERT(OP). {A.a = @OP; A.b = 0;} |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 982 | trigger_event(A) ::= UPDATE(OP). {A.a = @OP; A.b = 0;} |
| 983 | 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] | 984 | |
drh | 60218d2 | 2007-04-06 11:26:00 +0000 | [diff] [blame] | 985 | foreach_clause ::= . |
| 986 | foreach_clause ::= FOR EACH ROW. |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 987 | |
drh | 0bb132b | 2004-07-20 14:06:51 +0000 | [diff] [blame] | 988 | %type when_clause {Expr*} |
danielk1977 | dba99bc | 2006-01-07 14:02:26 +0000 | [diff] [blame] | 989 | %destructor when_clause {sqlite3ExprDelete($$);} |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 990 | when_clause(A) ::= . { A = 0; } |
| 991 | when_clause(A) ::= WHEN expr(X). { A = X; } |
| 992 | |
drh | 0bb132b | 2004-07-20 14:06:51 +0000 | [diff] [blame] | 993 | %type trigger_cmd_list {TriggerStep*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 994 | %destructor trigger_cmd_list {sqlite3DeleteTriggerStep($$);} |
drh | 187e4c6 | 2006-02-27 22:22:27 +0000 | [diff] [blame] | 995 | trigger_cmd_list(A) ::= trigger_cmd_list(Y) trigger_cmd(X) SEMI. { |
| 996 | if( Y ){ |
| 997 | Y->pLast->pNext = X; |
| 998 | }else{ |
| 999 | Y = X; |
| 1000 | } |
| 1001 | Y->pLast = X; |
| 1002 | A = Y; |
drh | a69d916 | 2003-04-17 22:57:53 +0000 | [diff] [blame] | 1003 | } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1004 | trigger_cmd_list(A) ::= . { A = 0; } |
| 1005 | |
drh | 0bb132b | 2004-07-20 14:06:51 +0000 | [diff] [blame] | 1006 | %type trigger_cmd {TriggerStep*} |
danielk1977 | 4adee20 | 2004-05-08 08:23:19 +0000 | [diff] [blame] | 1007 | %destructor trigger_cmd {sqlite3DeleteTriggerStep($$);} |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1008 | // UPDATE |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 1009 | trigger_cmd(A) ::= UPDATE orconf(R) nm(X) SET setlist(Y) where_opt(Z). |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1010 | { A = sqlite3TriggerUpdateStep(pParse->db, &X, Y, Z, R); } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1011 | |
| 1012 | // INSERT |
drh | 3054efe | 2004-02-12 17:28:13 +0000 | [diff] [blame] | 1013 | trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 1014 | VALUES LP itemlist(Y) RP. |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1015 | {A = sqlite3TriggerInsertStep(pParse->db, &X, F, Y, 0, R);} |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1016 | |
drh | 3054efe | 2004-02-12 17:28:13 +0000 | [diff] [blame] | 1017 | trigger_cmd(A) ::= insert_cmd(R) INTO nm(X) inscollist_opt(F) select(S). |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1018 | {A = sqlite3TriggerInsertStep(pParse->db, &X, F, 0, S, R);} |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1019 | |
| 1020 | // DELETE |
drh | 5ad1a6c | 2002-07-01 12:27:09 +0000 | [diff] [blame] | 1021 | trigger_cmd(A) ::= DELETE FROM nm(X) where_opt(Y). |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1022 | {A = sqlite3TriggerDeleteStep(pParse->db, &X, Y);} |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1023 | |
| 1024 | // SELECT |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1025 | trigger_cmd(A) ::= select(X). {A = sqlite3TriggerSelectStep(pParse->db, X); } |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1026 | |
danielk1977 | 6f34903 | 2002-06-11 02:25:40 +0000 | [diff] [blame] | 1027 | // The special RAISE expression that may occur in trigger programs |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 1028 | expr(A) ::= RAISE(X) LP IGNORE RP(Y). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1029 | A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); |
drh | 8aa34ae | 2006-03-13 12:54:09 +0000 | [diff] [blame] | 1030 | if( A ){ |
| 1031 | A->iColumn = OE_Ignore; |
| 1032 | sqlite3ExprSpan(A, &X, &Y); |
| 1033 | } |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 1034 | } |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 1035 | expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y). { |
drh | 1743575 | 2007-08-16 04:30:38 +0000 | [diff] [blame] | 1036 | A = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &Z); |
drh | 8aa34ae | 2006-03-13 12:54:09 +0000 | [diff] [blame] | 1037 | if( A ) { |
| 1038 | A->iColumn = T; |
| 1039 | sqlite3ExprSpan(A, &X, &Y); |
| 1040 | } |
drh | 4b59ab5 | 2002-08-24 18:24:51 +0000 | [diff] [blame] | 1041 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 1042 | %endif !SQLITE_OMIT_TRIGGER |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1043 | |
drh | 74ad7fe | 2004-10-07 03:06:28 +0000 | [diff] [blame] | 1044 | %type raisetype {int} |
| 1045 | raisetype(A) ::= ROLLBACK. {A = OE_Rollback;} |
| 1046 | raisetype(A) ::= ABORT. {A = OE_Abort;} |
| 1047 | raisetype(A) ::= FAIL. {A = OE_Fail;} |
| 1048 | |
danielk1977 | 6f34903 | 2002-06-11 02:25:40 +0000 | [diff] [blame] | 1049 | |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1050 | //////////////////////// DROP TRIGGER statement ////////////////////////////// |
drh | b7f9164 | 2004-10-31 02:22:47 +0000 | [diff] [blame] | 1051 | %ifndef SQLITE_OMIT_TRIGGER |
drh | fdd48a7 | 2006-09-11 23:45:48 +0000 | [diff] [blame] | 1052 | cmd ::= DROP TRIGGER ifexists(NOERR) fullname(X). { |
| 1053 | sqlite3DropTrigger(pParse,X,NOERR); |
danielk1977 | c3f9bad | 2002-05-15 08:30:12 +0000 | [diff] [blame] | 1054 | } |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 1055 | %endif !SQLITE_OMIT_TRIGGER |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 1056 | |
| 1057 | //////////////////////// ATTACH DATABASE file AS name ///////////////////////// |
drh | fdbcdee | 2007-03-27 14:44:50 +0000 | [diff] [blame] | 1058 | %ifndef SQLITE_OMIT_ATTACH |
danielk1977 | f744bb5 | 2005-12-06 17:19:11 +0000 | [diff] [blame] | 1059 | cmd ::= ATTACH database_kw_opt expr(F) AS expr(D) key_opt(K). { |
| 1060 | sqlite3Attach(pParse, F, D, K); |
drh | 1c2d841 | 2003-03-31 00:30:47 +0000 | [diff] [blame] | 1061 | } |
drh | fdbcdee | 2007-03-27 14:44:50 +0000 | [diff] [blame] | 1062 | cmd ::= DETACH database_kw_opt expr(D). { |
| 1063 | sqlite3Detach(pParse, D); |
| 1064 | } |
| 1065 | |
danielk1977 | f744bb5 | 2005-12-06 17:19:11 +0000 | [diff] [blame] | 1066 | %type key_opt {Expr *} |
danielk1977 | dba99bc | 2006-01-07 14:02:26 +0000 | [diff] [blame] | 1067 | %destructor key_opt {sqlite3ExprDelete($$);} |
danielk1977 | f744bb5 | 2005-12-06 17:19:11 +0000 | [diff] [blame] | 1068 | key_opt(A) ::= . { A = 0; } |
| 1069 | key_opt(A) ::= KEY expr(X). { A = X; } |
drh | 113088e | 2003-03-20 01:16:58 +0000 | [diff] [blame] | 1070 | |
| 1071 | database_kw_opt ::= DATABASE. |
| 1072 | database_kw_opt ::= . |
drh | fdbcdee | 2007-03-27 14:44:50 +0000 | [diff] [blame] | 1073 | %endif SQLITE_OMIT_ATTACH |
drh | 4343fea | 2004-11-05 23:46:15 +0000 | [diff] [blame] | 1074 | |
| 1075 | ////////////////////////// REINDEX collation ////////////////////////////////// |
| 1076 | %ifndef SQLITE_OMIT_REINDEX |
| 1077 | cmd ::= REINDEX. {sqlite3Reindex(pParse, 0, 0);} |
| 1078 | cmd ::= REINDEX nm(X) dbnm(Y). {sqlite3Reindex(pParse, &X, &Y);} |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 1079 | %endif SQLITE_OMIT_REINDEX |
danielk1977 | 9fd2a9a | 2004-11-12 13:42:30 +0000 | [diff] [blame] | 1080 | |
drh | 9f18e8a | 2005-07-08 12:13:04 +0000 | [diff] [blame] | 1081 | /////////////////////////////////// ANALYZE /////////////////////////////////// |
| 1082 | %ifndef SQLITE_OMIT_ANALYZE |
| 1083 | cmd ::= ANALYZE. {sqlite3Analyze(pParse, 0, 0);} |
| 1084 | cmd ::= ANALYZE nm(X) dbnm(Y). {sqlite3Analyze(pParse, &X, &Y);} |
| 1085 | %endif |
| 1086 | |
danielk1977 | 9fd2a9a | 2004-11-12 13:42:30 +0000 | [diff] [blame] | 1087 | //////////////////////// ALTER TABLE table ... //////////////////////////////// |
| 1088 | %ifndef SQLITE_OMIT_ALTERTABLE |
| 1089 | cmd ::= ALTER TABLE fullname(X) RENAME TO nm(Z). { |
| 1090 | sqlite3AlterRenameTable(pParse,X,&Z); |
| 1091 | } |
danielk1977 | 19a8e7e | 2005-03-17 05:03:38 +0000 | [diff] [blame] | 1092 | cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt column(Y). { |
| 1093 | sqlite3AlterFinishAddColumn(pParse, &Y); |
| 1094 | } |
| 1095 | add_column_fullname ::= fullname(X). { |
| 1096 | sqlite3AlterBeginAddColumn(pParse, X); |
| 1097 | } |
| 1098 | kwcolumn_opt ::= . |
| 1099 | kwcolumn_opt ::= COLUMNKW. |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 1100 | %endif SQLITE_OMIT_ALTERTABLE |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 1101 | |
| 1102 | //////////////////////// CREATE VIRTUAL TABLE ... ///////////////////////////// |
| 1103 | %ifndef SQLITE_OMIT_VIRTUALTABLE |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1104 | cmd ::= create_vtab. {sqlite3VtabFinishParse(pParse,0);} |
| 1105 | cmd ::= create_vtab LP vtabarglist RP(X). {sqlite3VtabFinishParse(pParse,&X);} |
| 1106 | create_vtab ::= CREATE VIRTUAL TABLE nm(X) dbnm(Y) USING nm(Z). { |
| 1107 | sqlite3VtabBeginParse(pParse, &X, &Y, &Z); |
| 1108 | } |
drh | e09daa9 | 2006-06-10 13:29:31 +0000 | [diff] [blame] | 1109 | vtabarglist ::= vtabarg. |
| 1110 | vtabarglist ::= vtabarglist COMMA vtabarg. |
drh | b9bb7c1 | 2006-06-11 23:41:55 +0000 | [diff] [blame] | 1111 | vtabarg ::= . {sqlite3VtabArgInit(pParse);} |
| 1112 | vtabarg ::= vtabarg vtabargtoken. |
| 1113 | vtabargtoken ::= ANY(X). {sqlite3VtabArgExtend(pParse,&X);} |
| 1114 | vtabargtoken ::= lp anylist RP(X). {sqlite3VtabArgExtend(pParse,&X);} |
| 1115 | lp ::= LP(X). {sqlite3VtabArgExtend(pParse,&X);} |
| 1116 | anylist ::= . |
| 1117 | anylist ::= anylist ANY(X). {sqlite3VtabArgExtend(pParse,&X);} |
drh | 154d4b2 | 2006-09-21 11:02:16 +0000 | [diff] [blame] | 1118 | %endif SQLITE_OMIT_VIRTUALTABLE |