annotate sqlite/parse.y @ 1434:b6b61becdf4e trunk

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