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 | 094b2bb | 2002-03-13 18:54:07 +0000 | [diff] [blame] | 17 | ** @(#) $Id: parse.y,v 1.57 2002/03/13 18:54:08 drh 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 | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 24 | sqliteSetString(&pParse->zErrMsg,"syntax error",0); |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 25 | pParse->sErrToken = TOKEN; |
| 26 | } |
| 27 | %name sqliteParser |
| 28 | %include { |
| 29 | #include "sqliteInt.h" |
| 30 | #include "parse.h" |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | ** A structure for holding two integers |
| 34 | */ |
| 35 | struct twoint { int a,b; }; |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 36 | } |
| 37 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 38 | // These are extra tokens used by the lexer but never seen by the |
| 39 | // parser. We put them in a rule so that the parser generator will |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 40 | // add them to the parse.h output file. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 41 | // |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 42 | %nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION |
| 43 | COLUMN AGG_FUNCTION. |
| 44 | |
| 45 | // Input is zero or more commands. |
| 46 | input ::= cmdlist. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 47 | |
| 48 | // A list of commands is zero or more commands |
| 49 | // |
| 50 | cmdlist ::= ecmd. |
drh | 094b2bb | 2002-03-13 18:54:07 +0000 | [diff] [blame] | 51 | cmdlist ::= cmdlist ecmd. |
| 52 | ecmd ::= explain cmd SEMI. {sqliteExec(pParse);} |
| 53 | ecmd ::= cmd SEMI. {sqliteExec(pParse);} |
| 54 | ecmd ::= SEMI. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 55 | explain ::= EXPLAIN. {pParse->explain = 1;} |
| 56 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 57 | ///////////////////// Begin and end transactions. //////////////////////////// |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 58 | // |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 59 | |
drh | 0d65dc0 | 2002-02-03 00:56:09 +0000 | [diff] [blame] | 60 | cmd ::= BEGIN trans_opt onconf(R). {sqliteBeginTransaction(pParse,R);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 61 | trans_opt ::= . |
| 62 | trans_opt ::= TRANSACTION. |
| 63 | trans_opt ::= TRANSACTION ids. |
| 64 | cmd ::= COMMIT trans_opt. {sqliteCommitTransaction(pParse);} |
| 65 | cmd ::= END trans_opt. {sqliteCommitTransaction(pParse);} |
| 66 | cmd ::= ROLLBACK trans_opt. {sqliteRollbackTransaction(pParse);} |
| 67 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 68 | ///////////////////// The CREATE TABLE statement //////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 69 | // |
| 70 | cmd ::= create_table create_table_args. |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 71 | create_table ::= CREATE(X) temp(T) TABLE ids(Y). { |
| 72 | sqliteStartTable(pParse,&X,&Y,T); |
| 73 | } |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 74 | %type temp {int} |
| 75 | temp(A) ::= TEMP. {A = 1;} |
| 76 | temp(A) ::= . {A = 0;} |
drh | 969fa7c | 2002-02-18 18:30:32 +0000 | [diff] [blame] | 77 | create_table_args ::= LP columnlist conslist_opt RP(X). { |
| 78 | sqliteEndTable(pParse,&X,0); |
| 79 | } |
| 80 | create_table_args ::= AS select(S). { |
| 81 | sqliteEndTable(pParse,0,S); |
| 82 | sqliteSelectDelete(S); |
| 83 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 84 | columnlist ::= columnlist COMMA column. |
| 85 | columnlist ::= column. |
| 86 | |
| 87 | // About the only information used for a column is the name of the |
| 88 | // column. The type is always just "text". But the code will accept |
| 89 | // an elaborate typename. Perhaps someday we'll do something with it. |
| 90 | // |
| 91 | column ::= columnid type carglist. |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 92 | columnid ::= ids(X). {sqliteAddColumn(pParse,&X);} |
| 93 | |
| 94 | // An IDENTIFIER can be a generic identifier, or one of several |
| 95 | // keywords. Any non-standard keyword can also be an identifier. |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 96 | // We also make DESC and identifier since it comes up so often (as |
| 97 | // an abbreviation of "description"). |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 98 | // |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 99 | %type id {Token} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 100 | id(A) ::= DESC(X). {A = X;} |
| 101 | id(A) ::= ASC(X). {A = X;} |
| 102 | id(A) ::= DELIMITERS(X). {A = X;} |
| 103 | id(A) ::= EXPLAIN(X). {A = X;} |
| 104 | id(A) ::= VACUUM(X). {A = X;} |
| 105 | id(A) ::= BEGIN(X). {A = X;} |
| 106 | id(A) ::= END(X). {A = X;} |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 107 | id(A) ::= PRAGMA(X). {A = X;} |
| 108 | id(A) ::= CLUSTER(X). {A = X;} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 109 | id(A) ::= ID(X). {A = X;} |
drh | f57b339 | 2001-10-08 13:22:32 +0000 | [diff] [blame] | 110 | id(A) ::= TEMP(X). {A = X;} |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 111 | id(A) ::= OFFSET(X). {A = X;} |
drh | aacc543 | 2002-01-06 17:07:40 +0000 | [diff] [blame] | 112 | id(A) ::= KEY(X). {A = X;} |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 113 | id(A) ::= ABORT(X). {A = X;} |
| 114 | id(A) ::= IGNORE(X). {A = X;} |
| 115 | id(A) ::= REPLACE(X). {A = X;} |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 116 | id(A) ::= FAIL(X). {A = X;} |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 117 | id(A) ::= CONFLICT(X). {A = X;} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 118 | |
| 119 | // And "ids" is an identifer-or-string. |
| 120 | // |
| 121 | %type ids {Token} |
| 122 | ids(A) ::= id(X). {A = X;} |
| 123 | ids(A) ::= STRING(X). {A = X;} |
| 124 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 125 | type ::= . |
| 126 | type ::= typename(X). {sqliteAddColumnType(pParse,&X,&X);} |
| 127 | type ::= typename(X) LP signed RP(Y). {sqliteAddColumnType(pParse,&X,&Y);} |
| 128 | type ::= typename(X) LP signed COMMA signed RP(Y). |
| 129 | {sqliteAddColumnType(pParse,&X,&Y);} |
| 130 | %type typename {Token} |
| 131 | typename(A) ::= ids(X). {A = X;} |
| 132 | typename(A) ::= typename(X) ids. {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 133 | signed ::= INTEGER. |
| 134 | signed ::= PLUS INTEGER. |
| 135 | signed ::= MINUS INTEGER. |
| 136 | carglist ::= carglist carg. |
| 137 | carglist ::= . |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 138 | carg ::= CONSTRAINT ids ccons. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 139 | carg ::= ccons. |
drh | 7020f65 | 2000-06-03 18:06:52 +0000 | [diff] [blame] | 140 | carg ::= DEFAULT STRING(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 141 | carg ::= DEFAULT ID(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 142 | carg ::= DEFAULT INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 143 | carg ::= DEFAULT PLUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 144 | carg ::= DEFAULT MINUS INTEGER(X). {sqliteAddDefaultValue(pParse,&X,1);} |
| 145 | carg ::= DEFAULT FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 146 | carg ::= DEFAULT PLUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,0);} |
| 147 | carg ::= DEFAULT MINUS FLOAT(X). {sqliteAddDefaultValue(pParse,&X,1);} |
| 148 | carg ::= DEFAULT NULL. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 149 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 150 | // In addition to the type name, we also care about the primary key and |
| 151 | // UNIQUE constraints. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 152 | // |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 153 | ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);} |
| 154 | ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);} |
| 155 | ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);} |
| 156 | ccons ::= CHECK LP expr RP onconf. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 157 | |
| 158 | // For the time being, the only constraint we care about is the primary |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 159 | // key and UNIQUE. Both create indices. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 160 | // |
| 161 | conslist_opt ::= . |
| 162 | conslist_opt ::= COMMA conslist. |
| 163 | conslist ::= conslist COMMA tcons. |
drh | a2e1bb5 | 2001-01-04 14:20:18 +0000 | [diff] [blame] | 164 | conslist ::= conslist tcons. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 165 | conslist ::= tcons. |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 166 | tcons ::= CONSTRAINT ids. |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 167 | tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R). |
| 168 | {sqliteAddPrimaryKey(pParse,X,R);} |
| 169 | tcons ::= UNIQUE LP idxlist(X) RP onconf(R). |
| 170 | {sqliteCreateIndex(pParse,0,0,X,R,0,0);} |
| 171 | tcons ::= CHECK expr onconf. |
| 172 | |
| 173 | // The following is a non-standard extension that allows us to declare the |
| 174 | // default behavior when there is a constraint conflict. |
| 175 | // |
| 176 | %type onconf {int} |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 177 | %type orconf {int} |
| 178 | %type resolvetype {int} |
| 179 | onconf(A) ::= . { A = OE_Default; } |
| 180 | onconf(A) ::= ON CONFLICT resolvetype(X). { A = X; } |
| 181 | orconf(A) ::= . { A = OE_Default; } |
| 182 | orconf(A) ::= OR resolvetype(X). { A = X; } |
| 183 | resolvetype(A) ::= ROLLBACK. { A = OE_Rollback; } |
| 184 | resolvetype(A) ::= ABORT. { A = OE_Abort; } |
| 185 | resolvetype(A) ::= FAIL. { A = OE_Fail; } |
| 186 | resolvetype(A) ::= IGNORE. { A = OE_Ignore; } |
| 187 | resolvetype(A) ::= REPLACE. { A = OE_Replace; } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 188 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 189 | ////////////////////////// The DROP TABLE ///////////////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 190 | // |
drh | 4ff6dfa | 2002-03-03 23:06:00 +0000 | [diff] [blame] | 191 | cmd ::= DROP TABLE ids(X). {sqliteDropTable(pParse,&X,0);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 192 | |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 193 | ///////////////////// The CREATE VIEW statement ///////////////////////////// |
| 194 | // |
| 195 | cmd ::= CREATE(X) VIEW ids(Y) AS select(S). { |
| 196 | sqliteCreateView(pParse, &X, &Y, S); |
| 197 | } |
| 198 | cmd ::= DROP VIEW ids(X). { |
drh | 4ff6dfa | 2002-03-03 23:06:00 +0000 | [diff] [blame] | 199 | sqliteDropTable(pParse, &X, 1); |
drh | a76b5df | 2002-02-23 02:32:10 +0000 | [diff] [blame] | 200 | } |
| 201 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 202 | //////////////////////// The SELECT statement ///////////////////////////////// |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 203 | // |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 204 | cmd ::= select(X). { |
drh | 832508b | 2002-03-02 17:04:07 +0000 | [diff] [blame] | 205 | sqliteSelect(pParse, X, SRT_Callback, 0, 0, 0, 0); |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 206 | sqliteSelectDelete(X); |
| 207 | } |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 208 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 209 | %type select {Select*} |
| 210 | %destructor select {sqliteSelectDelete($$);} |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 211 | %type oneselect {Select*} |
| 212 | %destructor oneselect {sqliteSelectDelete($$);} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 213 | |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 214 | select(A) ::= oneselect(X). {A = X;} |
drh | 0a36c57 | 2002-02-18 22:49:59 +0000 | [diff] [blame] | 215 | select(A) ::= select(X) multiselect_op(Y) oneselect(Z). { |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 216 | if( Z ){ |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 217 | Z->op = Y; |
| 218 | Z->pPrior = X; |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 219 | } |
| 220 | A = Z; |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 221 | } |
drh | 0a36c57 | 2002-02-18 22:49:59 +0000 | [diff] [blame] | 222 | %type multiselect_op {int} |
| 223 | multiselect_op(A) ::= UNION. {A = TK_UNION;} |
| 224 | multiselect_op(A) ::= UNION ALL. {A = TK_ALL;} |
| 225 | multiselect_op(A) ::= INTERSECT. {A = TK_INTERSECT;} |
| 226 | multiselect_op(A) ::= EXCEPT. {A = TK_EXCEPT;} |
drh | 82c3d63 | 2000-06-06 21:56:07 +0000 | [diff] [blame] | 227 | oneselect(A) ::= SELECT distinct(D) selcollist(W) from(X) where_opt(Y) |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 228 | groupby_opt(P) having_opt(Q) orderby_opt(Z) limit_opt(L). { |
| 229 | A = sqliteSelectNew(W,X,Y,P,Q,Z,D,L.a,L.b); |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // The "distinct" nonterminal is true (1) if the DISTINCT keyword is |
| 233 | // present and false (0) if it is not. |
| 234 | // |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 235 | %type distinct {int} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 236 | distinct(A) ::= DISTINCT. {A = 1;} |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 237 | distinct(A) ::= ALL. {A = 0;} |
drh | efb7251 | 2000-05-31 20:00:52 +0000 | [diff] [blame] | 238 | distinct(A) ::= . {A = 0;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 239 | |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 240 | // selcollist is a list of expressions that are to become the return |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 241 | // values of the SELECT statement. The "*" in statements like |
| 242 | // "SELECT * FROM ..." is encoded as a special expression with an |
| 243 | // opcode of TK_ALL. |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 244 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 245 | %type selcollist {ExprList*} |
| 246 | %destructor selcollist {sqliteExprListDelete($$);} |
| 247 | %type sclp {ExprList*} |
| 248 | %destructor sclp {sqliteExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 249 | sclp(A) ::= selcollist(X) COMMA. {A = X;} |
| 250 | sclp(A) ::= . {A = 0;} |
| 251 | selcollist(A) ::= sclp(P) expr(X). {A = sqliteExprListAppend(P,X,0);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 252 | selcollist(A) ::= sclp(P) expr(X) as ids(Y). {A = sqliteExprListAppend(P,X,&Y);} |
drh | 7c917d1 | 2001-12-16 20:05:05 +0000 | [diff] [blame] | 253 | selcollist(A) ::= sclp(P) STAR. { |
| 254 | A = sqliteExprListAppend(P, sqliteExpr(TK_ALL, 0, 0, 0), 0); |
| 255 | } |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 256 | as ::= . |
| 257 | as ::= AS. |
| 258 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 259 | |
| 260 | %type seltablist {IdList*} |
| 261 | %destructor seltablist {sqliteIdListDelete($$);} |
| 262 | %type stl_prefix {IdList*} |
| 263 | %destructor stl_prefix {sqliteIdListDelete($$);} |
| 264 | %type from {IdList*} |
| 265 | %destructor from {sqliteIdListDelete($$);} |
| 266 | |
| 267 | from(A) ::= FROM seltablist(X). {A = X;} |
| 268 | stl_prefix(A) ::= seltablist(X) COMMA. {A = X;} |
| 269 | stl_prefix(A) ::= . {A = 0;} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 270 | seltablist(A) ::= stl_prefix(X) ids(Y). {A = sqliteIdListAppend(X,&Y);} |
| 271 | seltablist(A) ::= stl_prefix(X) ids(Y) as ids(Z). { |
| 272 | A = sqliteIdListAppend(X,&Y); |
| 273 | sqliteIdListAddAlias(A,&Z); |
| 274 | } |
drh | 22f70c3 | 2002-02-18 01:17:00 +0000 | [diff] [blame] | 275 | seltablist(A) ::= stl_prefix(X) LP select(S) RP. { |
| 276 | A = sqliteIdListAppend(X,0); |
| 277 | A->a[A->nId-1].pSelect = S; |
| 278 | } |
| 279 | seltablist(A) ::= stl_prefix(X) LP select(S) RP as ids(Z). { |
| 280 | A = sqliteIdListAppend(X,0); |
| 281 | A->a[A->nId-1].pSelect = S; |
| 282 | sqliteIdListAddAlias(A,&Z); |
| 283 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 284 | |
| 285 | %type orderby_opt {ExprList*} |
| 286 | %destructor orderby_opt {sqliteExprListDelete($$);} |
| 287 | %type sortlist {ExprList*} |
| 288 | %destructor sortlist {sqliteExprListDelete($$);} |
| 289 | %type sortitem {Expr*} |
| 290 | %destructor sortitem {sqliteExprDelete($$);} |
| 291 | |
| 292 | orderby_opt(A) ::= . {A = 0;} |
| 293 | orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 294 | sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). { |
| 295 | A = sqliteExprListAppend(X,Y,0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 296 | if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */ |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 297 | } |
| 298 | sortlist(A) ::= sortitem(Y) sortorder(Z). { |
| 299 | A = sqliteExprListAppend(0,Y,0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 300 | if( A ) A->a[0].sortOrder = Z; |
drh | 9bb61fe | 2000-06-05 16:01:39 +0000 | [diff] [blame] | 301 | } |
drh | da9d6c4 | 2000-05-31 18:20:14 +0000 | [diff] [blame] | 302 | sortitem(A) ::= expr(X). {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 303 | |
| 304 | %type sortorder {int} |
| 305 | |
| 306 | sortorder(A) ::= ASC. {A = 0;} |
| 307 | sortorder(A) ::= DESC. {A = 1;} |
| 308 | sortorder(A) ::= . {A = 0;} |
| 309 | |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 310 | %type groupby_opt {ExprList*} |
| 311 | %destructor groupby_opt {sqliteExprListDelete($$);} |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 312 | groupby_opt(A) ::= . {A = 0;} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 313 | groupby_opt(A) ::= GROUP BY exprlist(X). {A = X;} |
| 314 | |
| 315 | %type having_opt {Expr*} |
| 316 | %destructor having_opt {sqliteExprDelete($$);} |
drh | 6206d50 | 2000-06-19 19:09:08 +0000 | [diff] [blame] | 317 | having_opt(A) ::= . {A = 0;} |
drh | 2282792 | 2000-06-06 17:27:05 +0000 | [diff] [blame] | 318 | having_opt(A) ::= HAVING expr(X). {A = X;} |
| 319 | |
drh | 9bbca4c | 2001-11-06 04:00:18 +0000 | [diff] [blame] | 320 | %type limit_opt {struct twoint} |
| 321 | limit_opt(A) ::= . {A.a = -1; A.b = 0;} |
| 322 | limit_opt(A) ::= LIMIT INTEGER(X). {A.a = atoi(X.z); A.b = 0;} |
| 323 | limit_opt(A) ::= LIMIT INTEGER(X) limit_sep INTEGER(Y). |
| 324 | {A.a = atoi(X.z); A.b = atoi(Y.z);} |
| 325 | limit_sep ::= OFFSET. |
| 326 | limit_sep ::= COMMA. |
| 327 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 328 | /////////////////////////// The DELETE statement ///////////////////////////// |
| 329 | // |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 330 | cmd ::= DELETE FROM ids(X) where_opt(Y). |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 331 | {sqliteDeleteFrom(pParse, &X, Y);} |
| 332 | |
| 333 | %type where_opt {Expr*} |
| 334 | %destructor where_opt {sqliteExprDelete($$);} |
| 335 | |
| 336 | where_opt(A) ::= . {A = 0;} |
| 337 | where_opt(A) ::= WHERE expr(X). {A = X;} |
| 338 | |
| 339 | %type setlist {ExprList*} |
| 340 | %destructor setlist {sqliteExprListDelete($$);} |
| 341 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 342 | ////////////////////////// The UPDATE command //////////////////////////////// |
| 343 | // |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 344 | cmd ::= UPDATE orconf(R) ids(X) SET setlist(Y) where_opt(Z). |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 345 | {sqliteUpdate(pParse,&X,Y,Z,R);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 346 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 347 | setlist(A) ::= setlist(Z) COMMA ids(X) EQ expr(Y). |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 348 | {A = sqliteExprListAppend(Z,Y,&X);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 349 | setlist(A) ::= ids(X) EQ expr(Y). {A = sqliteExprListAppend(0,Y,&X);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 350 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 351 | ////////////////////////// The INSERT command ///////////////////////////////// |
| 352 | // |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 353 | cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) VALUES LP itemlist(Y) RP. |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 354 | {sqliteInsert(pParse, &X, Y, 0, F, R);} |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 355 | cmd ::= insert_cmd(R) INTO ids(X) inscollist_opt(F) select(S). |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 356 | {sqliteInsert(pParse, &X, 0, S, F, R);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 357 | |
drh | fa86c41 | 2002-02-02 15:01:15 +0000 | [diff] [blame] | 358 | %type insert_cmd {int} |
| 359 | insert_cmd(A) ::= INSERT orconf(R). {A = R;} |
| 360 | insert_cmd(A) ::= REPLACE. {A = OE_Replace;} |
| 361 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 362 | |
| 363 | %type itemlist {ExprList*} |
| 364 | %destructor itemlist {sqliteExprListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 365 | |
drh | e64e7b2 | 2002-02-18 13:56:36 +0000 | [diff] [blame] | 366 | itemlist(A) ::= itemlist(X) COMMA expr(Y). {A = sqliteExprListAppend(X,Y,0);} |
| 367 | itemlist(A) ::= expr(X). {A = sqliteExprListAppend(0,X,0);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 368 | |
drh | 967e8b7 | 2000-06-21 13:59:10 +0000 | [diff] [blame] | 369 | %type inscollist_opt {IdList*} |
| 370 | %destructor inscollist_opt {sqliteIdListDelete($$);} |
| 371 | %type inscollist {IdList*} |
| 372 | %destructor inscollist {sqliteIdListDelete($$);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 373 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 374 | inscollist_opt(A) ::= . {A = 0;} |
| 375 | inscollist_opt(A) ::= LP inscollist(X) RP. {A = X;} |
| 376 | inscollist(A) ::= inscollist(X) COMMA ids(Y). {A = sqliteIdListAppend(X,&Y);} |
| 377 | inscollist(A) ::= ids(Y). {A = sqliteIdListAppend(0,&Y);} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 378 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 379 | /////////////////////////// Expression Processing ///////////////////////////// |
| 380 | // |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 381 | %left OR. |
| 382 | %left AND. |
drh | 8be5113 | 2000-06-03 19:19:41 +0000 | [diff] [blame] | 383 | %right NOT. |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 384 | %left EQ NE ISNULL NOTNULL IS LIKE GLOB BETWEEN IN. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 385 | %left GT GE LT LE. |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 386 | %left BITAND BITOR LSHIFT RSHIFT. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 387 | %left PLUS MINUS. |
drh | bf4133c | 2001-10-13 02:59:08 +0000 | [diff] [blame] | 388 | %left STAR SLASH REM. |
drh | 0040077 | 2000-06-16 20:51:26 +0000 | [diff] [blame] | 389 | %left CONCAT. |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 390 | %right UMINUS BITNOT. |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 391 | |
| 392 | %type expr {Expr*} |
| 393 | %destructor expr {sqliteExprDelete($$);} |
| 394 | |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 395 | expr(A) ::= LP(B) expr(X) RP(E). {A = X; sqliteExprSpan(A,&B,&E);} |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 396 | expr(A) ::= NULL(X). {A = sqliteExpr(TK_NULL, 0, 0, &X);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 397 | expr(A) ::= id(X). {A = sqliteExpr(TK_ID, 0, 0, &X);} |
| 398 | expr(A) ::= ids(X) DOT ids(Y). { |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 399 | Expr *temp1 = sqliteExpr(TK_ID, 0, 0, &X); |
| 400 | Expr *temp2 = sqliteExpr(TK_ID, 0, 0, &Y); |
| 401 | A = sqliteExpr(TK_DOT, temp1, temp2, 0); |
| 402 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 403 | expr(A) ::= INTEGER(X). {A = sqliteExpr(TK_INTEGER, 0, 0, &X);} |
| 404 | expr(A) ::= FLOAT(X). {A = sqliteExpr(TK_FLOAT, 0, 0, &X);} |
| 405 | expr(A) ::= STRING(X). {A = sqliteExpr(TK_STRING, 0, 0, &X);} |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 406 | expr(A) ::= ID(X) LP exprlist(Y) RP(E). { |
| 407 | A = sqliteExprFunction(Y, &X); |
| 408 | sqliteExprSpan(A,&X,&E); |
| 409 | } |
| 410 | expr(A) ::= ID(X) LP STAR RP(E). { |
| 411 | A = sqliteExprFunction(0, &X); |
| 412 | sqliteExprSpan(A,&X,&E); |
| 413 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 414 | expr(A) ::= expr(X) AND expr(Y). {A = sqliteExpr(TK_AND, X, Y, 0);} |
| 415 | expr(A) ::= expr(X) OR expr(Y). {A = sqliteExpr(TK_OR, X, Y, 0);} |
| 416 | expr(A) ::= expr(X) LT expr(Y). {A = sqliteExpr(TK_LT, X, Y, 0);} |
| 417 | expr(A) ::= expr(X) GT expr(Y). {A = sqliteExpr(TK_GT, X, Y, 0);} |
| 418 | expr(A) ::= expr(X) LE expr(Y). {A = sqliteExpr(TK_LE, X, Y, 0);} |
| 419 | expr(A) ::= expr(X) GE expr(Y). {A = sqliteExpr(TK_GE, X, Y, 0);} |
| 420 | expr(A) ::= expr(X) NE expr(Y). {A = sqliteExpr(TK_NE, X, Y, 0);} |
| 421 | expr(A) ::= expr(X) EQ expr(Y). {A = sqliteExpr(TK_EQ, X, Y, 0);} |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 422 | expr(A) ::= expr(X) BITAND expr(Y). {A = sqliteExpr(TK_BITAND, X, Y, 0);} |
| 423 | expr(A) ::= expr(X) BITOR expr(Y). {A = sqliteExpr(TK_BITOR, X, Y, 0);} |
| 424 | expr(A) ::= expr(X) LSHIFT expr(Y). {A = sqliteExpr(TK_LSHIFT, X, Y, 0);} |
| 425 | expr(A) ::= expr(X) RSHIFT expr(Y). {A = sqliteExpr(TK_RSHIFT, X, Y, 0);} |
| 426 | expr(A) ::= expr(X) LIKE expr(Y). {A = sqliteExpr(TK_LIKE, X, Y, 0);} |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 427 | expr(A) ::= expr(X) NOT LIKE expr(Y). { |
| 428 | A = sqliteExpr(TK_LIKE, X, Y, 0); |
| 429 | A = sqliteExpr(TK_NOT, A, 0, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 430 | sqliteExprSpan(A,&X->span,&Y->span); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 431 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 432 | expr(A) ::= expr(X) GLOB expr(Y). {A = sqliteExpr(TK_GLOB,X,Y,0);} |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 433 | expr(A) ::= expr(X) NOT GLOB expr(Y). { |
| 434 | A = sqliteExpr(TK_GLOB, X, Y, 0); |
| 435 | A = sqliteExpr(TK_NOT, A, 0, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 436 | sqliteExprSpan(A,&X->span,&Y->span); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 437 | } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 438 | expr(A) ::= expr(X) PLUS expr(Y). {A = sqliteExpr(TK_PLUS, X, Y, 0);} |
| 439 | expr(A) ::= expr(X) MINUS expr(Y). {A = sqliteExpr(TK_MINUS, X, Y, 0);} |
| 440 | expr(A) ::= expr(X) STAR expr(Y). {A = sqliteExpr(TK_STAR, X, Y, 0);} |
| 441 | expr(A) ::= expr(X) SLASH expr(Y). {A = sqliteExpr(TK_SLASH, X, Y, 0);} |
drh | bf4133c | 2001-10-13 02:59:08 +0000 | [diff] [blame] | 442 | expr(A) ::= expr(X) REM expr(Y). {A = sqliteExpr(TK_REM, X, Y, 0);} |
drh | 0040077 | 2000-06-16 20:51:26 +0000 | [diff] [blame] | 443 | expr(A) ::= expr(X) CONCAT expr(Y). {A = sqliteExpr(TK_CONCAT, X, Y, 0);} |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 444 | expr(A) ::= expr(X) ISNULL(E). { |
| 445 | A = sqliteExpr(TK_ISNULL, X, 0, 0); |
| 446 | sqliteExprSpan(A,&X->span,&E); |
| 447 | } |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 448 | expr(A) ::= expr(X) IS NULL(E). { |
| 449 | A = sqliteExpr(TK_ISNULL, X, 0, 0); |
| 450 | sqliteExprSpan(A,&X->span,&E); |
| 451 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 452 | expr(A) ::= expr(X) NOTNULL(E). { |
| 453 | A = sqliteExpr(TK_NOTNULL, X, 0, 0); |
| 454 | sqliteExprSpan(A,&X->span,&E); |
| 455 | } |
drh | 33048c0 | 2001-10-01 14:29:22 +0000 | [diff] [blame] | 456 | expr(A) ::= expr(X) NOT NULL(E). { |
| 457 | A = sqliteExpr(TK_NOTNULL, X, 0, 0); |
| 458 | sqliteExprSpan(A,&X->span,&E); |
| 459 | } |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 460 | expr(A) ::= expr(X) IS NOT NULL(E). { |
| 461 | A = sqliteExpr(TK_NOTNULL, X, 0, 0); |
| 462 | sqliteExprSpan(A,&X->span,&E); |
| 463 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 464 | expr(A) ::= NOT(B) expr(X). { |
| 465 | A = sqliteExpr(TK_NOT, X, 0, 0); |
| 466 | sqliteExprSpan(A,&B,&X->span); |
| 467 | } |
drh | 81a20f2 | 2001-10-12 17:30:04 +0000 | [diff] [blame] | 468 | expr(A) ::= BITNOT(B) expr(X). { |
| 469 | A = sqliteExpr(TK_BITNOT, X, 0, 0); |
| 470 | sqliteExprSpan(A,&B,&X->span); |
| 471 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 472 | expr(A) ::= MINUS(B) expr(X). [UMINUS] { |
| 473 | A = sqliteExpr(TK_UMINUS, X, 0, 0); |
| 474 | sqliteExprSpan(A,&B,&X->span); |
| 475 | } |
| 476 | expr(A) ::= PLUS(B) expr(X). [UMINUS] { |
| 477 | A = X; |
| 478 | sqliteExprSpan(A,&B,&X->span); |
| 479 | } |
| 480 | expr(A) ::= LP(B) select(X) RP(E). { |
drh | 19a775c | 2000-06-05 18:54:46 +0000 | [diff] [blame] | 481 | A = sqliteExpr(TK_SELECT, 0, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 482 | if( A ) A->pSelect = X; |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 483 | sqliteExprSpan(A,&B,&E); |
drh | 19a775c | 2000-06-05 18:54:46 +0000 | [diff] [blame] | 484 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 485 | expr(A) ::= expr(W) BETWEEN expr(X) AND expr(Y). { |
| 486 | ExprList *pList = sqliteExprListAppend(0, X, 0); |
| 487 | pList = sqliteExprListAppend(pList, Y, 0); |
| 488 | A = sqliteExpr(TK_BETWEEN, W, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 489 | if( A ) A->pList = pList; |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 490 | sqliteExprSpan(A,&W->span,&Y->span); |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 491 | } |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 492 | expr(A) ::= expr(W) NOT BETWEEN expr(X) AND expr(Y). { |
| 493 | ExprList *pList = sqliteExprListAppend(0, X, 0); |
| 494 | pList = sqliteExprListAppend(pList, Y, 0); |
| 495 | A = sqliteExpr(TK_BETWEEN, W, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 496 | if( A ) A->pList = pList; |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 497 | A = sqliteExpr(TK_NOT, A, 0, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 498 | sqliteExprSpan(A,&W->span,&Y->span); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 499 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 500 | expr(A) ::= expr(X) IN LP exprlist(Y) RP(E). { |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 501 | A = sqliteExpr(TK_IN, X, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 502 | if( A ) A->pList = Y; |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 503 | sqliteExprSpan(A,&X->span,&E); |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 504 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 505 | expr(A) ::= expr(X) IN LP select(Y) RP(E). { |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 506 | A = sqliteExpr(TK_IN, X, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 507 | if( A ) A->pSelect = Y; |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 508 | sqliteExprSpan(A,&X->span,&E); |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 509 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 510 | expr(A) ::= expr(X) NOT IN LP exprlist(Y) RP(E). { |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 511 | A = sqliteExpr(TK_IN, X, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 512 | if( A ) A->pList = Y; |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 513 | A = sqliteExpr(TK_NOT, A, 0, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 514 | sqliteExprSpan(A,&X->span,&E); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 515 | } |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 516 | expr(A) ::= expr(X) NOT IN LP select(Y) RP(E). { |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 517 | A = sqliteExpr(TK_IN, X, 0, 0); |
drh | daffd0e | 2001-04-11 14:28:42 +0000 | [diff] [blame] | 518 | if( A ) A->pSelect = Y; |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 519 | A = sqliteExpr(TK_NOT, A, 0, 0); |
drh | e1b6a5b | 2000-07-29 13:06:59 +0000 | [diff] [blame] | 520 | sqliteExprSpan(A,&X->span,&E); |
drh | 4794b98 | 2000-06-06 13:54:14 +0000 | [diff] [blame] | 521 | } |
drh | fef5208 | 2000-06-06 01:50:43 +0000 | [diff] [blame] | 522 | |
| 523 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 524 | |
| 525 | %type exprlist {ExprList*} |
| 526 | %destructor exprlist {sqliteExprListDelete($$);} |
| 527 | %type expritem {Expr*} |
| 528 | %destructor expritem {sqliteExprDelete($$);} |
| 529 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 530 | exprlist(A) ::= exprlist(X) COMMA expritem(Y). |
| 531 | {A = sqliteExprListAppend(X,Y,0);} |
| 532 | exprlist(A) ::= expritem(X). {A = sqliteExprListAppend(0,X,0);} |
| 533 | expritem(A) ::= expr(X). {A = X;} |
| 534 | expritem(A) ::= . {A = 0;} |
drh | cce7d17 | 2000-05-31 15:34:51 +0000 | [diff] [blame] | 535 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 536 | ///////////////////////////// The CREATE INDEX command /////////////////////// |
| 537 | // |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 538 | cmd ::= CREATE(S) uniqueflag(U) INDEX ids(X) |
| 539 | ON ids(Y) LP idxlist(Z) RP(E) onconf(R). { |
| 540 | if( U!=OE_None ) U = R; |
| 541 | if( U==OE_Default) U = OE_Abort; |
| 542 | sqliteCreateIndex(pParse, &X, &Y, Z, U, &S, &E); |
| 543 | } |
drh | 717e640 | 2001-09-27 03:22:32 +0000 | [diff] [blame] | 544 | |
| 545 | %type uniqueflag {int} |
drh | 9cfcf5d | 2002-01-29 18:41:24 +0000 | [diff] [blame] | 546 | uniqueflag(A) ::= UNIQUE. { A = OE_Abort; } |
| 547 | uniqueflag(A) ::= . { A = OE_None; } |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 548 | |
| 549 | %type idxlist {IdList*} |
| 550 | %destructor idxlist {sqliteIdListDelete($$);} |
| 551 | %type idxitem {Token} |
| 552 | |
| 553 | idxlist(A) ::= idxlist(X) COMMA idxitem(Y). |
| 554 | {A = sqliteIdListAppend(X,&Y);} |
| 555 | idxlist(A) ::= idxitem(Y). |
| 556 | {A = sqliteIdListAppend(0,&Y);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 557 | idxitem(A) ::= ids(X). {A = X;} |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 558 | |
drh | 8aff101 | 2001-12-22 14:49:24 +0000 | [diff] [blame] | 559 | ///////////////////////////// The DROP INDEX command ///////////////////////// |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 560 | // |
| 561 | |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 562 | cmd ::= DROP INDEX ids(X). {sqliteDropIndex(pParse, &X);} |
drh | 982cef7 | 2000-05-30 16:27:03 +0000 | [diff] [blame] | 563 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 564 | |
drh | 8aff101 | 2001-12-22 14:49:24 +0000 | [diff] [blame] | 565 | ///////////////////////////// The COPY command /////////////////////////////// |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 566 | // |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 567 | cmd ::= COPY orconf(R) ids(X) FROM ids(Y) USING DELIMITERS STRING(Z). |
drh | b419a92 | 2002-01-30 16:17:23 +0000 | [diff] [blame] | 568 | {sqliteCopy(pParse,&X,&Y,&Z,R);} |
drh | 1c92853 | 2002-01-31 15:54:21 +0000 | [diff] [blame] | 569 | cmd ::= COPY orconf(R) ids(X) FROM ids(Y). |
drh | b419a92 | 2002-01-30 16:17:23 +0000 | [diff] [blame] | 570 | {sqliteCopy(pParse,&X,&Y,0,R);} |
drh | dce2cbe | 2000-05-31 02:27:49 +0000 | [diff] [blame] | 571 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 572 | ///////////////////////////// The VACUUM command ///////////////////////////// |
| 573 | // |
drh | dce2cbe | 2000-05-31 02:27:49 +0000 | [diff] [blame] | 574 | cmd ::= VACUUM. {sqliteVacuum(pParse,0);} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 575 | cmd ::= VACUUM ids(X). {sqliteVacuum(pParse,&X);} |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 576 | |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 577 | ///////////////////////////// The PRAGMA command ///////////////////////////// |
| 578 | // |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 579 | cmd ::= PRAGMA ids(X) EQ ids(Y). {sqlitePragma(pParse,&X,&Y,0);} |
| 580 | cmd ::= PRAGMA ids(X) EQ ON(Y). {sqlitePragma(pParse,&X,&Y,0);} |
| 581 | cmd ::= PRAGMA ids(X) EQ plus_num(Y). {sqlitePragma(pParse,&X,&Y,0);} |
| 582 | cmd ::= PRAGMA ids(X) EQ minus_num(Y). {sqlitePragma(pParse,&X,&Y,1);} |
drh | 382c024 | 2001-10-06 16:33:02 +0000 | [diff] [blame] | 583 | cmd ::= PRAGMA ids(X) LP ids(Y) RP. {sqlitePragma(pParse,&X,&Y,0);} |
drh | 603240c | 2002-03-05 01:11:12 +0000 | [diff] [blame] | 584 | cmd ::= PRAGMA ids(X). {sqlitePragma(pParse,&X,&X,0);} |
drh | f57b14a | 2001-09-14 18:54:08 +0000 | [diff] [blame] | 585 | plus_num(A) ::= plus_opt number(X). {A = X;} |
| 586 | minus_num(A) ::= MINUS number(X). {A = X;} |
| 587 | number(A) ::= INTEGER(X). {A = X;} |
| 588 | number(A) ::= FLOAT(X). {A = X;} |
| 589 | plus_opt ::= PLUS. |
| 590 | plus_opt ::= . |