1 %token_prefix TK3_
2 %token_type {Token*}
3 %default_type {Token*}
4 %extra_argument {ParserContext* parserContext}
5 %name sqlite3_parse
6 %start_symbol input
7
8 %syntax_error {
9 UNUSED_PARAMETER(yymajor);
10 parserContext->error(TOKEN, QObject::tr("Syntax error"));
11 //qDebug() << "near " << TOKEN->toString() << ": syntax error";
12 }
13
14 %stack_overflow {
15 parserContext->error(QObject::tr("Parser stack overflow"));
16 }
17
18 %include {
19 #include "token.h"
20 #include "parsercontext.h"
21 #include "parser_helper_stubs.h"
22 #include "common/utils_sql.h"
23 #include "common/global.h"
24 #include "common/unused.h"
25 #include "parser/ast/sqlitealtertable.h"
26 #include "parser/ast/sqliteanalyze.h"
27 #include "parser/ast/sqliteattach.h"
28 #include "parser/ast/sqlitebegintrans.h"
29 #include "parser/ast/sqlitecommittrans.h"
30 #include "parser/ast/sqlitecopy.h"
31 #include "parser/ast/sqlitecreateindex.h"
32 #include "parser/ast/sqlitecreatetable.h"
33 #include "parser/ast/sqlitecreatetrigger.h"
34 #include "parser/ast/sqlitecreateview.h"
35 #include "parser/ast/sqlitecreatevirtualtable.h"
36 #include "parser/ast/sqlitedelete.h"
37 #include "parser/ast/sqlitedetach.h"
38 #include "parser/ast/sqlitedropindex.h"
39 #include "parser/ast/sqlitedroptable.h"
40 #include "parser/ast/sqlitedroptrigger.h"
41 #include "parser/ast/sqlitedropview.h"
42 #include "parser/ast/sqliteemptyquery.h"
43 #include "parser/ast/sqliteinsert.h"
44 #include "parser/ast/sqlitepragma.h"
45 #include "parser/ast/sqlitereindex.h"
46 #include "parser/ast/sqliterelease.h"
47 #include "parser/ast/sqliterollback.h"
48 #include "parser/ast/sqlitesavepoint.h"
49 #include "parser/ast/sqliteselect.h"
50 #include "parser/ast/sqliteupdate.h"
51 #include "parser/ast/sqlitevacuum.h"
52 #include "parser/ast/sqliteexpr.h"
53 #include "parser/ast/sqlitecolumntype.h"
54 #include "parser/ast/sqliteconflictalgo.h"
55 #include "parser/ast/sqlitesortorder.h"
56 #include "parser/ast/sqliteindexedcolumn.h"
57 #include "parser/ast/sqliteforeignkey.h"
58 #include "parser/ast/sqlitewith.h"
59 #include "parser/ast/sqliteupsert.h"
60 #include "parser/ast/sqlitewindowdefinition.h"
61 #include "parser/ast/sqlitefilterover.h"
62 #include "parser/ast/sqlitenulls.h"
63 #include <QObject>
64 #include <QDebug>
65 #include <limits.h>
66
67 #define assert(X) Q_ASSERT(X)
68 #define UNUSED_PARAMETER(X) (void)(X)
69 #define DONT_INHERIT_TOKENS(X) noTokenInheritanceFields << X
70 }
71
72 // These are extra tokens used by the lexer but never seen by the
73 // parser. We put them in a rule so that the parser generator will
74 // add them to the parse.h output file.
75
76 %nonassoc ILLEGAL COMMENT SPACE.
77
78 // The following directive causes tokens ABORT, AFTER, ASC, etc. to
79 // fallback to ID if they will not parse as their original value.
80 // This obviates the need for the "id" nonterminal.
81 // Those keywords: EXCEPT INTERSECT UNION
82 // are allowed for fallback if compound selects are disabled,
83 // which is not this case.
84 %fallback ID
85 ABORT ACTION AFTER ALWAYS ANALYZE ASC ATTACH BEFORE BEGIN BY CASCADE CAST COLUMNKW
86 CONFLICT CURRENT DATABASE DEFERRED DESC DETACH DO EACH END EXCLUDE EXCLUSIVE EXPLAIN FAIL FIRST FOLLOWING FOR
87 GENERATED GROUPS IGNORE IMMEDIATE INDEXED INITIALLY INSTEAD LAST LIKE_KW MATCH NO NULLS OTHERS PLAN
88 QUERY KEY OF OFFSET PARTITION PRAGMA PRECEDING RAISE RANGE RECURSIVE RELEASE REPLACE RESTRICT ROW ROWS ROLLBACK
89 SAVEPOINT TEMP TIES TRIGGER UNBOUNDED VACUUM VIEW VIRTUAL WITH WITHOUT
90 REINDEX RENAME CTIME_KW IF
91 .
92 %wildcard ANY.
93
94 // Define operator precedence early so that this is the first occurance
95 // of the operator tokens in the grammer. Keeping the operators together
96 // causes them to be assigned integer values that are close together,
97 // which keeps parser tables smaller.
98 //
99 // The token values assigned to these symbols is determined by the order
100 // in which lemon first sees them. It must be the case that ISNULL/NOTNULL,
101 // NE/EQ, GT/LE, and GE/LT are separated by only a single value. See
102 // the sqlite3ExprIfFalse() routine for additional information on this
103 // constraint.
104 %left OR.
105 %left AND.
106 %right NOT.
107 %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
108 %left GT LE LT GE.
109 %right ESCAPE.
110 %left BITAND BITOR LSHIFT RSHIFT.
111 %left PLUS MINUS.
112 %left STAR SLASH REM.
113 %left CONCAT.
114 %left COLLATE.
115 %right BITNOT.
116
117 // Input is a single SQL command
118 %type cmd {SqliteQuery*}
119 %destructor cmd {parser_safe_delete($$);}
120
121 input ::= cmdlist.
122
ecmd(C)123 cmdlist ::= cmdlist ecmd(C). {parserContext->addQuery(C); DONT_INHERIT_TOKENS("cmdlist");}
ecmd(C)124 cmdlist ::= ecmd(C). {parserContext->addQuery(C);}
125
126 %type ecmd {SqliteQuery*}
127 %destructor ecmd {parser_safe_delete($$);}
ecmd(X)128 ecmd(X) ::= SEMI. {X = new SqliteEmptyQuery();}
ecmd(X)129 ecmd(X) ::= explain(E) cmdx(C) SEMI. {
130 X = C;
131 X->explain = E->explain;
132 X->queryPlan = E->queryPlan;
133 delete E;
134 objectForTokens = X;
135 }
136
137 %type explain {ParserStubExplain*}
138 %destructor explain {parser_safe_delete($$);}
explain(X)139 explain(X) ::= . {X = new ParserStubExplain(false, false);}
explain(X)140 explain(X) ::= EXPLAIN. {X = new ParserStubExplain(true, false);}
explain(X)141 explain(X) ::= EXPLAIN QUERY PLAN. {X = new ParserStubExplain(true, true);}
142
143 %type cmdx {SqliteQuery*}
144 %destructor cmdx {parser_safe_delete($$);}
cmdx(X)145 cmdx(X) ::= cmd(C). {X = C;}
146
147 ///////////////////// Begin and end transaction. ////////////////////////////
148
cmd(X)149 cmd(X) ::= BEGIN transtype(TT)
150 trans_opt(TO). {
151 X = new SqliteBeginTrans(
152 TT->type,
153 TO->transactionKw,
154 TO->name
155 );
156 delete TO;
157 delete TT;
158 objectForTokens = X;
159 }
160
161 %type trans_opt {ParserStubTransDetails*}
162 %destructor trans_opt {parser_safe_delete($$);}
trans_opt(X)163 trans_opt(X) ::= . {X = new ParserStubTransDetails();}
trans_opt(X)164 trans_opt(X) ::= TRANSACTION. {
165 X = new ParserStubTransDetails();
166 X->transactionKw = true;
167 }
trans_opt(X)168 trans_opt(X) ::= TRANSACTION nm(N). {
169 X = new ParserStubTransDetails();
170 X->transactionKw = true;
171 X->name = *(N);
172 delete N;
173 }
174 trans_opt ::= TRANSACTION ID_TRANS. {}
175
176 %type transtype {ParserStubTransDetails*}
177 %destructor transtype {parser_safe_delete($$);}
transtype(X)178 transtype(X) ::= . {X = new ParserStubTransDetails();}
transtype(X)179 transtype(X) ::= DEFERRED. {
180 X = new ParserStubTransDetails();
181 X->type = SqliteBeginTrans::Type::DEFERRED;
182 }
transtype(X)183 transtype(X) ::= IMMEDIATE. {
184 X = new ParserStubTransDetails();
185 X->type = SqliteBeginTrans::Type::IMMEDIATE;
186 }
transtype(X)187 transtype(X) ::= EXCLUSIVE. {
188 X = new ParserStubTransDetails();
189 X->type = SqliteBeginTrans::Type::EXCLUSIVE;
190 }
cmd(X)191 cmd(X) ::= COMMIT trans_opt(T). {
192 X = new SqliteCommitTrans(
193 T->transactionKw,
194 T->name,
195 false
196 );
197 delete T;
198 objectForTokens = X;
199 }
cmd(X)200 cmd(X) ::= END trans_opt(T). {
201 X = new SqliteCommitTrans(
202 T->transactionKw,
203 T->name,
204 true
205 );
206 delete T;
207 objectForTokens = X;
208 }
cmd(X)209 cmd(X) ::= ROLLBACK trans_opt(T). {
210 X = new SqliteRollback(
211 T->transactionKw,
212 T->name
213 );
214 delete T;
215 objectForTokens = X;
216 }
217
218 %type savepoint_opt {bool*}
219 %destructor savepoint_opt {parser_safe_delete($$);}
savepoint_opt(X)220 savepoint_opt(X) ::= SAVEPOINT. {X = new bool(true);}
savepoint_opt(X)221 savepoint_opt(X) ::= . {X = new bool(false);}
222
cmd(X)223 cmd(X) ::= SAVEPOINT nm(N). {
224 X = new SqliteSavepoint(*(N));
225 delete N;
226 objectForTokens = X;
227 }
cmd(X)228 cmd(X) ::= RELEASE savepoint_opt(S) nm(N). {
229 X = new SqliteRelease(*(S), *(N));
230 delete N;
231 objectForTokens = X;
232 }
cmd(X)233 cmd(X) ::= ROLLBACK trans_opt(T) TO
234 savepoint_opt(S) nm(N). {
235 X = new SqliteRollback(
236 T->transactionKw,
237 *(S),
238 *(N)
239 );
240 delete S;
241 delete T;
242 objectForTokens = X;
243 }
244 cmd ::= SAVEPOINT ID_TRANS. {}
245 cmd ::= RELEASE savepoint_opt ID_TRANS. {}
246 cmd ::= ROLLBACK trans_opt TO savepoint_opt
247 ID_TRANS. {}
248
249 ///////////////////// The CREATE TABLE statement ////////////////////////////
250
cmd(X)251 cmd(X) ::= CREATE temp(T) TABLE
252 ifnotexists(E) fullname(N)
253 LP columnlist(CL)
254 conslist_opt(CS) RP
255 table_options(F). {
256 X = new SqliteCreateTable(
257 *(E),
258 *(T),
259 N->name1,
260 N->name2,
261 *(CL),
262 *(CS),
263 *(F)
264 );
265 delete E;
266 delete T;
267 delete CL;
268 delete CS;
269 delete N;
270 delete F;
271 objectForTokens = X;
272 }
cmd(X)273 cmd(X) ::= CREATE temp(T) TABLE
274 ifnotexists(E) fullname(N)
275 AS select(S). {
276 X = new SqliteCreateTable(
277 *(E),
278 *(T),
279 N->name1,
280 N->name2,
281 S
282 );
283 delete E;
284 delete T;
285 delete N;
286 objectForTokens = X;
287 }
288 cmd ::= CREATE temp TABLE ifnotexists
289 nm DOT ID_TAB_NEW. {}
290 cmd ::= CREATE temp TABLE ifnotexists
291 ID_DB|ID_TAB_NEW. {}
292
293 %type table_options {QString*}
294 %destructor table_options {parser_safe_delete($$);}
table_options(X)295 table_options(X) ::= . {X = new QString();}
table_options(X)296 table_options(X) ::= WITHOUT nm(N). {
297 if (N->toLower() != "rowid")
298 parserContext->errorAtToken(QString("Invalid table option: %1").arg(*(N)));
299
300 X = N;
301 }
302 table_options ::= WITHOUT CTX_ROWID_KW. {}
303
304 %type ifnotexists {bool*}
305 %destructor ifnotexists {parser_safe_delete($$);}
ifnotexists(X)306 ifnotexists(X) ::= . {X = new bool(false);}
ifnotexists(X)307 ifnotexists(X) ::= IF NOT EXISTS. {X = new bool(true);}
308
309 %type temp {int*}
310 %destructor temp {parser_safe_delete($$);}
temp(X)311 temp(X) ::= TEMP(T). {X = new int( (T->value.length() > 4) ? 2 : 1 );}
temp(X)312 temp(X) ::= . {X = new int(0);}
313
314 %type columnlist {ParserCreateTableColumnList*}
315 %destructor columnlist {parser_safe_delete($$);}
columnlist(X)316 columnlist(X) ::= columnlist(L)
317 COMMA column(C). {
318 L->append(C);
319 X = L;
320 DONT_INHERIT_TOKENS("columnlist");
321 }
columnlist(X)322 columnlist(X) ::= column(C). {
323 X = new ParserCreateTableColumnList();
324 X->append(C);
325 }
326
327 // A "column" is a complete description of a single column in a
328 // CREATE TABLE statement. This includes the column name, its
329 // datatype, and other keywords such as PRIMARY KEY, UNIQUE, REFERENCES,
330 // NOT NULL and so forth.
331
332 %type column {SqliteCreateTable::Column*}
333 %destructor column {parser_safe_delete($$);}
column(X)334 column(X) ::= columnid(C) type(T)
335 carglist(L). {
336 X = new SqliteCreateTable::Column(*(C), T, *(L));
337 delete C;
338 delete L;
339 objectForTokens = X;
340 }
341
342 %type columnid {QString*}
343 %destructor columnid {parser_safe_delete($$);}
columnid(X)344 columnid(X) ::= nm(N). {X = N;}
345 columnid ::= ID_COL_NEW. {}
346
347
348 // An IDENTIFIER can be a generic identifier, or one of several
349 // keywords. Any non-standard keyword can also be an identifier.
350 %type id {QString*}
351 %destructor id {parser_safe_delete($$);}
id(X)352 id(X) ::= ID(T). {
353 X = new QString(
354 stripObjName(
355 T->value
356 )
357 );
358 }
359
360 %type id_opt {QString*}
361 %destructor id_opt {parser_safe_delete($$);}
id_opt(X)362 id_opt(X) ::= id(T). {
363 X = T;
364 }
id_opt(X)365 id_opt(X) ::= . {
366 X = new QString();
367 }
368
369 // Why would INDEXED be defined individually like this? I don't know.
370 // It was like this in the original SQLite grammar, but it doesn't
371 // make any sense, since we have a fallback mechanism for such things.
372 // Anyway, this makes "INDEXED" appear in weird places of completion
373 // suggestions, so I remove it for now. Will see how it works.
374 // id(X) ::= INDEXED(T). {X = new QString(T->value);}
375
376 // And "ids" is an identifer-or-string.
377 %type ids {QString*}
378 %destructor ids {parser_safe_delete($$);}
379 ids(X) ::= ID|STRING(T). {X = new QString(T->value);}
380
381 // The name of a column or table can be any of the following:
382 %type nm {QString*}
383 %destructor nm {parser_safe_delete($$);}
nm(X)384 nm(X) ::= id(N). {X = N;}
nm(X)385 nm(X) ::= STRING(N). {X = new QString(stripString(N->value));}
nm(X)386 nm(X) ::= JOIN_KW(N). {X = new QString(N->value);}
387
388 // A typetoken is really one or more tokens that form a type name such
389 // as can be found after the column name in a CREATE TABLE statement.
390 // Multiple tokens are concatenated to form the value of the typetoken.
391 %type type {SqliteColumnType*}
392 %destructor type {parser_safe_delete($$);}
type(X)393 type(X) ::= . {X = nullptr;}
type(X)394 type(X) ::= typetoken(T). {X = T;}
395
396 %type typetoken {SqliteColumnType*}
397 %destructor typetoken {parser_safe_delete($$);}
typetoken(X)398 typetoken(X) ::= typename(N). {
399 X = new SqliteColumnType(*(N));
400 delete N;
401 objectForTokens = X;
402 }
typetoken(X)403 typetoken(X) ::= typename(N)
404 LP signed(P) RP. {
405 X = new SqliteColumnType(*(N), *(P));
406 delete N;
407 delete P;
408 objectForTokens = X;
409 }
typetoken(X)410 typetoken(X) ::= typename(N) LP signed(P)
411 COMMA signed(S) RP. {
412 X = new SqliteColumnType(*(N), *(P), *(S));
413 delete N;
414 delete P;
415 delete S;
416 objectForTokens = X;
417 }
418
419 %type typename {QString*}
420 %destructor typename {parser_safe_delete($$);}
typename(X)421 typename(X) ::= ids(I). {X = I;}
typename(X)422 typename(X) ::= typename(T) ids(I). {
423 T->append(" " + *(I));
424 delete I;
425 X = T;
426 }
427 typename ::= ID_COL_TYPE. {}
428
429 %type signed {QVariant*}
430 %destructor signed {parser_safe_delete($$);}
plus_num(N)431 signed(X) ::= plus_num(N). {X = N;}
minus_num(N)432 signed(X) ::= minus_num(N). {X = N;}
433
434 // "carglist" is a list of additional constraints that come after the
435 // column name and column type in a CREATE TABLE statement.
436 %type carglist {ParserCreateTableColumnConstraintList*}
437 %destructor carglist {parser_safe_delete($$);}
carglist(X)438 carglist(X) ::= carglist(L) ccons(C).
439 [RIGHT_ASSOC] {
440 L->append(C);
441 X = L;
442 DONT_INHERIT_TOKENS("carglist");
443 }
carglist(X)444 carglist(X) ::= . [RIGHT_ASSOC] {X = new ParserCreateTableColumnConstraintList();}
445
446 %type ccons {SqliteCreateTable::Column::Constraint*}
447 %destructor ccons {parser_safe_delete($$);}
ccons(X)448 ccons(X) ::= CONSTRAINT nm(N). {
449 X = new SqliteCreateTable::Column::Constraint();
450 X->initDefNameOnly(*(N));
451 delete N;
452 objectForTokens = X;
453 }
ccons(X)454 ccons(X) ::= DEFAULT term(T). {
455 X = new SqliteCreateTable::Column::Constraint();
456 X->initDefTerm(*(T));
457 delete T;
458 objectForTokens = X;
459 }
ccons(X)460 ccons(X) ::= DEFAULT LP expr(E) RP. {
461 X = new SqliteCreateTable::Column::Constraint();
462 X->initDefExpr(E);
463 objectForTokens = X;
464 }
ccons(X)465 ccons(X) ::= DEFAULT PLUS term(T). {
466 X = new SqliteCreateTable::Column::Constraint();
467 X->initDefTerm(*(T), false);
468 delete T;
469 objectForTokens = X;
470 }
ccons(X)471 ccons(X) ::= DEFAULT MINUS term(T). {
472 X = new SqliteCreateTable::Column::Constraint();
473 X->initDefTerm(*(T), true);
474 delete T;
475 objectForTokens = X;
476 }
ccons(X)477 ccons(X) ::= DEFAULT id(I). {
478 X = new SqliteCreateTable::Column::Constraint();
479 X->initDefId(*(I));
480 delete I;
481 objectForTokens = X;
482 }
ccons(X)483 ccons(X) ::= DEFAULT CTIME_KW(K). {
484 X = new SqliteCreateTable::Column::Constraint();
485 X->initDefCTime(K->value);
486 objectForTokens = X;
487 }
488
489 // In addition to the type name, we also care about the primary key and
490 // UNIQUE constraints.
ccons(X)491 ccons(X) ::= NULL onconf(C). {
492 X = new SqliteCreateTable::Column::Constraint();
493 X->initNull(*(C));
494 delete C;
495 objectForTokens = X;
496 }
ccons(X)497 ccons(X) ::= NOT NULL onconf(C). {
498 X = new SqliteCreateTable::Column::Constraint();
499 X->initNotNull(*(C));
500 delete C;
501 objectForTokens = X;
502 }
ccons(X)503 ccons(X) ::= PRIMARY KEY sortorder(O)
504 onconf(C) autoinc(A). {
505 X = new SqliteCreateTable::Column::Constraint();
506 X->initPk(*(O), *(C), *(A));
507 delete O;
508 delete A;
509 delete C;
510 objectForTokens = X;
511 }
ccons(X)512 ccons(X) ::= UNIQUE onconf(C). {
513 X = new SqliteCreateTable::Column::Constraint();
514 X->initUnique(*(C));
515 delete C;
516 objectForTokens = X;
517 }
ccons(X)518 ccons(X) ::= CHECK LP expr(E) RP. {
519 X = new SqliteCreateTable::Column::Constraint();
520 X->initCheck(E);
521 objectForTokens = X;
522 }
ccons(X)523 ccons(X) ::= REFERENCES nm(N)
524 idxlist_opt(I) refargs(A). {
525 X = new SqliteCreateTable::Column::Constraint();
526 X->initFk(*(N), *(I), *(A));
527 delete N;
528 delete A;
529 delete I;
530 objectForTokens = X;
531 }
ccons(X)532 ccons(X) ::= defer_subclause(D). {
533 X = new SqliteCreateTable::Column::Constraint();
534 X->initDefer(D->initially, D->deferrable);
535 delete D;
536 objectForTokens = X;
537 }
ccons(X)538 ccons(X) ::= COLLATE ids(I). {
539 X = new SqliteCreateTable::Column::Constraint();
540 X->initColl(*(I));
541 delete I;
542 objectForTokens = X;
543 }
ccons(X)544 ccons(X) ::= gen_always(A) AS
545 LP expr(E) RP id_opt(T). {
546 if (!T->isNull() && T->toLower() != "stored" && T->toLower() != "virtual")
547 parserContext->errorAtToken(QString("Invalid generated column type: %1").arg(*(T)));
548
549 X = new SqliteCreateTable::Column::Constraint();
550 X->initGeneratedAs(E, *(A), *(T));
551 delete A;
552 delete T;
553 objectForTokens = X;
554 }
555
556 ccons ::= CONSTRAINT ID_CONSTR. {}
557 ccons ::= COLLATE ID_COLLATE. {}
558 ccons ::= REFERENCES ID_TAB. {}
ccons(X)559 ccons(X) ::= CHECK LP RP. {
560 X = new SqliteCreateTable::Column::Constraint();
561 X->initCheck();
562 objectForTokens = X;
563 parserContext->minorErrorAfterLastToken("Syntax error");
564 }
565
566 %type term {QVariant*}
567 %destructor term {parser_safe_delete($$);}
term(X)568 term(X) ::= NULL. {X = new QVariant();}
term(X)569 term(X) ::= INTEGER(N). {X = parserContext->handleNumberToken(N->value);}
term(X)570 term(X) ::= FLOAT(N). {X = new QVariant(QVariant(N->value).toDouble());}
571 term(X) ::= STRING|BLOB(S). {X = new QVariant(stripString(S->value));}
572
573 // Term Literal or Name. String falls under Term, but can be falled back to Name if necessary in the context.
574 // On the other hand - if name is ID, it cannot be falled back to Term, as ID is never a Literal value.
575 %type tnm {ParserTermOrLiteral*}
576 %destructor tnm {parser_safe_delete($$);}
tnm(X)577 tnm(X) ::= term(T). {
578 X = new ParserTermOrLiteral(*(T));
579 delete T;
580 }
tnm(X)581 tnm(X) ::= nm(N). {
582 X = new ParserTermOrLiteral(*(N));
583 delete N;
584 }
585
586 %type gen_always {bool*}
587 %destructor gen_always {parser_safe_delete($$);}
gen_always(X)588 gen_always(X) ::= GENERATED ALWAYS. {X = new bool(true);}
gen_always(X)589 gen_always(X) ::= . {X = new bool(false);}
590
591 // The optional AUTOINCREMENT keyword
592 %type autoinc {bool*}
593 %destructor autoinc {parser_safe_delete($$);}
autoinc(X)594 autoinc(X) ::= . {X = new bool(false);}
autoinc(X)595 autoinc(X) ::= AUTOINCR. {X = new bool(true);}
596
597 // The next group of rules parses the arguments to a REFERENCES clause
598 // that determine if the referential integrity checking is deferred or
599 // or immediate and which determine what action to take if a ref-integ
600 // check fails.
601 %type refargs {ParserFkConditionList*}
602 %destructor refargs {parser_safe_delete($$);}
refargs(X)603 refargs(X) ::= . {X = new ParserFkConditionList();}
refargs(X)604 refargs(X) ::= refargs(L) refarg(A). {
605 L->append(A);
606 X = L;
607 DONT_INHERIT_TOKENS("refargs");
608 }
609
610 %type refarg {SqliteForeignKey::Condition*}
611 %destructor refarg {parser_safe_delete($$);}
refarg(X)612 refarg(X) ::= MATCH nm(N). {
613 X = new SqliteForeignKey::Condition(*(N));
614 delete N;
615 }
refarg(X)616 refarg(X) ::= ON INSERT refact(R). {X = new SqliteForeignKey::Condition(SqliteForeignKey::Condition::INSERT, *(R)); delete R;}
refarg(X)617 refarg(X) ::= ON DELETE refact(R). {X = new SqliteForeignKey::Condition(SqliteForeignKey::Condition::DELETE, *(R)); delete R;}
refarg(X)618 refarg(X) ::= ON UPDATE refact(R). {X = new SqliteForeignKey::Condition(SqliteForeignKey::Condition::UPDATE, *(R)); delete R;}
619 refarg ::= MATCH ID_FK_MATCH. {}
620
621 %type refact {SqliteForeignKey::Condition::Reaction*}
622 %destructor refact {parser_safe_delete($$);}
refact(X)623 refact(X) ::= SET NULL. {X = new SqliteForeignKey::Condition::Reaction(SqliteForeignKey::Condition::SET_NULL);}
refact(X)624 refact(X) ::= SET DEFAULT. {X = new SqliteForeignKey::Condition::Reaction(SqliteForeignKey::Condition::SET_DEFAULT);}
refact(X)625 refact(X) ::= CASCADE. {X = new SqliteForeignKey::Condition::Reaction(SqliteForeignKey::Condition::CASCADE);}
refact(X)626 refact(X) ::= RESTRICT. {X = new SqliteForeignKey::Condition::Reaction(SqliteForeignKey::Condition::RESTRICT);}
refact(X)627 refact(X) ::= NO ACTION. {X = new SqliteForeignKey::Condition::Reaction(SqliteForeignKey::Condition::NO_ACTION);}
628
629 %type defer_subclause {ParserDeferSubClause*}
630 %destructor defer_subclause {parser_safe_delete($$);}
defer_subclause(X)631 defer_subclause(X) ::= NOT DEFERRABLE
632 init_deferred_pred_opt(I). {
633 X = new ParserDeferSubClause(SqliteDeferrable::NOT_DEFERRABLE, *(I));
634 delete I;
635 }
defer_subclause(X)636 defer_subclause(X) ::= DEFERRABLE
637 init_deferred_pred_opt(I). {
638 X = new ParserDeferSubClause(SqliteDeferrable::DEFERRABLE, *(I));
639 delete I;
640 }
641
642 %type init_deferred_pred_opt {SqliteInitially*}
643 %destructor init_deferred_pred_opt {parser_safe_delete($$);}
init_deferred_pred_opt(X)644 init_deferred_pred_opt(X) ::= . {X = new SqliteInitially(SqliteInitially::null);}
init_deferred_pred_opt(X)645 init_deferred_pred_opt(X) ::= INITIALLY
646 DEFERRED. {X = new SqliteInitially(SqliteInitially::DEFERRED);}
init_deferred_pred_opt(X)647 init_deferred_pred_opt(X) ::= INITIALLY
648 IMMEDIATE. {X = new SqliteInitially(SqliteInitially::IMMEDIATE);}
649
650 %type conslist_opt {ParserCreateTableConstraintList*}
651 %destructor conslist_opt {parser_safe_delete($$);}
conslist_opt(X)652 conslist_opt(X) ::= . {X = new ParserCreateTableConstraintList();}
conslist_opt(X)653 conslist_opt(X) ::= COMMA conslist(L). {X = L;}
654
655 %type conslist {ParserCreateTableConstraintList*}
656 %destructor conslist {parser_safe_delete($$);}
conslist(X)657 conslist(X) ::= conslist(L) tconscomma(CM)
658 tcons(C). {
659 C->afterComma = *(CM);
660 L->append(C);
661 X = L;
662 delete CM;
663 DONT_INHERIT_TOKENS("conslist");
664 }
conslist(X)665 conslist(X) ::= tcons(C). {
666 X = new ParserCreateTableConstraintList();
667 X->append(C);
668 }
669
670 %type tconscomma {bool*}
671 %destructor tconscomma {parser_safe_delete($$);}
tconscomma(X)672 tconscomma(X) ::= COMMA. {X = new bool(true);}
tconscomma(X)673 tconscomma(X) ::= . {X = new bool(false);}
674
675 %type tcons {SqliteCreateTable::Constraint*}
676 %destructor tcons {parser_safe_delete($$);}
tcons(X)677 tcons(X) ::= CONSTRAINT nm(N). {
678 X = new SqliteCreateTable::Constraint();
679 X->initNameOnly(*(N));
680 delete N;
681 objectForTokens = X;
682 }
tcons(X)683 tcons(X) ::= PRIMARY KEY LP idxlist(L)
684 autoinc(I) RP onconf(C). {
685 X = new SqliteCreateTable::Constraint();
686 X->initPk(*(L), *(I), *(C));
687 delete I;
688 delete C;
689 delete L;
690 objectForTokens = X;
691 }
tcons(X)692 tcons(X) ::= UNIQUE LP idxlist(L) RP
693 onconf(C). {
694 X = new SqliteCreateTable::Constraint();
695 X->initUnique(*(L), *(C));
696 delete C;
697 delete L;
698 objectForTokens = X;
699 }
tcons(X)700 tcons(X) ::= CHECK LP expr(E) RP onconf(C). {
701 X = new SqliteCreateTable::Constraint();
702 X->initCheck(E, *(C));
703 objectForTokens = X;
704 }
tcons(X)705 tcons(X) ::= FOREIGN KEY LP idxlist(L) RP
706 REFERENCES nm(N) idxlist_opt(IL)
707 refargs(R) defer_subclause_opt(D). {
708 X = new SqliteCreateTable::Constraint();
709 X->initFk(
710 *(L),
711 *(N),
712 *(IL),
713 *(R),
714 D->initially,
715 D->deferrable
716 );
717 delete N;
718 delete R;
719 delete D;
720 delete IL;
721 delete L;
722 objectForTokens = X;
723 }
724
725 tcons ::= CONSTRAINT ID_CONSTR. {}
726 tcons ::= FOREIGN KEY LP idxlist RP
727 REFERENCES ID_TAB. {}
tcons(X)728 tcons(X) ::= CHECK LP RP onconf. {
729 X = new SqliteCreateTable::Constraint();
730 X->initCheck();
731 objectForTokens = X;
732 parserContext->minorErrorAfterLastToken("Syntax error");
733 }
734
735 %type defer_subclause_opt {ParserDeferSubClause*}
736 %destructor defer_subclause_opt {parser_safe_delete($$);}
defer_subclause_opt(X)737 defer_subclause_opt(X) ::= . {X = new ParserDeferSubClause(SqliteDeferrable::null, SqliteInitially::null);}
defer_subclause_opt(X)738 defer_subclause_opt(X) ::=
739 defer_subclause(D). {X = D;}
740
741 // The following is a non-standard extension that allows us to declare the
742 // default behavior when there is a constraint conflict.
743
744 %type onconf {SqliteConflictAlgo*}
745 %destructor onconf {parser_safe_delete($$);}
onconf(X)746 onconf(X) ::= . {X = new SqliteConflictAlgo(SqliteConflictAlgo::null);}
onconf(X)747 onconf(X) ::= ON CONFLICT resolvetype(R). {X = R;}
748
749 %type orconf {SqliteConflictAlgo*}
750 %destructor orconf {parser_safe_delete($$);}
orconf(X)751 orconf(X) ::= . {X = new SqliteConflictAlgo(SqliteConflictAlgo::null);}
orconf(X)752 orconf(X) ::= OR resolvetype(R). {X = R;}
753
754 %type resolvetype {SqliteConflictAlgo*}
755 %destructor resolvetype {parser_safe_delete($$);}
resolvetype(X)756 resolvetype(X) ::= raisetype(V). {X = new SqliteConflictAlgo(sqliteConflictAlgo(V->value));}
resolvetype(X)757 resolvetype(X) ::= IGNORE(V). {X = new SqliteConflictAlgo(sqliteConflictAlgo(V->value));}
resolvetype(X)758 resolvetype(X) ::= REPLACE(V). {X = new SqliteConflictAlgo(sqliteConflictAlgo(V->value));}
759
760 ////////////////////////// The DROP TABLE /////////////////////////////////////
761
cmd(X)762 cmd(X) ::= DROP TABLE ifexists(E)
763 fullname(N). {
764 X = new SqliteDropTable(*(E), N->name1, N->name2);
765 delete E;
766 delete N;
767 objectForTokens = X;
768 }
769
770 cmd ::= DROP TABLE ifexists nm DOT
771 ID_TAB. {}
772 cmd ::= DROP TABLE ifexists ID_DB|ID_TAB. {}
773
774 %type ifexists {bool*}
775 %destructor ifexists {parser_safe_delete($$);}
ifexists(X)776 ifexists(X) ::= IF EXISTS. {X = new bool(true);}
ifexists(X)777 ifexists(X) ::= . {X = new bool(false);}
778
779 ///////////////////// The CREATE VIEW statement /////////////////////////////
780
cmd(X)781 cmd(X) ::= CREATE temp(T) VIEW
782 ifnotexists(E) fullname(N)
783 idxlist_opt(C) AS select(S). {
784 X = new SqliteCreateView(*(T), *(E), N->name1, N->name2, S, *(C));
785 delete T;
786 delete E;
787 delete N;
788 delete C;
789 objectForTokens = X;
790 }
791
792 cmd ::= CREATE temp VIEW ifnotexists
793 nm DOT ID_VIEW_NEW. {}
794 cmd ::= CREATE temp VIEW ifnotexists
795 ID_DB|ID_VIEW_NEW. {}
796
cmd(X)797 cmd(X) ::= DROP VIEW ifexists(E)
798 fullname(N). {
799 X = new SqliteDropView(*(E), N->name1, N->name2);
800 delete E;
801 delete N;
802 objectForTokens = X;
803 }
804
805 cmd ::= DROP VIEW ifexists nm DOT ID_VIEW. {}
806 cmd ::= DROP VIEW ifexists ID_DB|ID_VIEW. {}
807
808 //////////////////////// The SELECT statement /////////////////////////////////
809
cmd(X)810 cmd(X) ::= select_stmt(S). {
811 X = S;
812 objectForTokens = X;
813 }
814
815 %type select_stmt {SqliteQuery*}
816 %destructor select_stmt {parser_safe_delete($$);}
select_stmt(X)817 select_stmt(X) ::= select(S). {
818 X = S;
819 // since it's used in trigger:
820 objectForTokens = X;
821 }
822
823 %type select {SqliteSelect*}
824 %destructor select {parser_safe_delete($$);}
select(X)825 select(X) ::= with(W) selectnowith(S). {
826 X = S;
827 S->setWith(W);
828 objectForTokens = X;
829 }
830
831 %type selectnowith {SqliteSelect*}
832 %destructor selectnowith {parser_safe_delete($$);}
selectnowith(X)833 selectnowith(X) ::= oneselect(S). {
834 X = SqliteSelect::append(S);
835 objectForTokens = X;
836 }
selectnowith(X)837 selectnowith(X) ::= selectnowith(S1)
838 multiselect_op(O)
839 oneselect(S2). {
840 X = SqliteSelect::append(S1, *(O), S2);
841 delete O;
842 objectForTokens = X;
843 }
selectnowith(X)844 selectnowith(X) ::= values(V). {
845 X = SqliteSelect::append(*(V));
846 delete V;
847 objectForTokens = X;
848 }
selectnowith(X)849 selectnowith(X) ::= selectnowith(S1)
850 COMMA
851 values(V). {
852 X = SqliteSelect::append(S1, SqliteSelect::CompoundOperator::UNION_ALL, *(V));
853 delete V;
854 objectForTokens = X;
855 }
856 %type oneselect {SqliteSelect::Core*}
857 %destructor oneselect {parser_safe_delete($$);}
oneselect(X)858 oneselect(X) ::= SELECT distinct(D)
859 selcollist(L) from(F)
860 where_opt(W) groupby_opt(G)
861 having_opt(H) orderby_opt(O)
862 limit_opt(LI). {
863 X = new SqliteSelect::Core(
864 *(D),
865 *(L),
866 F,
867 W,
868 *(G),
869 H,
870 *(O),
871 LI
872 );
873 delete L;
874 delete D;
875 delete G;
876 delete O;
877 objectForTokens = X;
878 }
oneselect(X)879 oneselect(X) ::= SELECT distinct(D)
880 selcollist(L) from(F)
881 where_opt(W) groupby_opt(G)
882 having_opt(H)
883 window_clause(WF)
884 orderby_opt(O)
885 limit_opt(LI). {
886 X = new SqliteSelect::Core(
887 *(D),
888 *(L),
889 F,
890 W,
891 *(G),
892 H,
893 *(WF),
894 *(O),
895 LI
896 );
897 delete L;
898 delete D;
899 delete G;
900 delete O;
901 delete WF;
902 objectForTokens = X;
903 }
904
905 %type values {ParserExprNestedList*}
906 %destructor values {parser_safe_delete($$);}
values(X)907 values(X) ::= VALUES LP nexprlist(E) RP. {
908 X = new ParserExprNestedList();
909 X->append(*(E));
910 delete E;
911 }
values(X)912 values(X) ::= values(L) COMMA LP
913 exprlist(E) RP. {
914 L->append(*(E));
915 X = L;
916 delete E;
917 DONT_INHERIT_TOKENS("values");
918 }
919
920 %type multiselect_op {SqliteSelect::CompoundOperator*}
921 %destructor multiselect_op {parser_safe_delete($$);}
multiselect_op(X)922 multiselect_op(X) ::= UNION. {X = new SqliteSelect::CompoundOperator(SqliteSelect::CompoundOperator::UNION);}
multiselect_op(X)923 multiselect_op(X) ::= UNION ALL. {X = new SqliteSelect::CompoundOperator(SqliteSelect::CompoundOperator::UNION_ALL);}
multiselect_op(X)924 multiselect_op(X) ::= EXCEPT. {X = new SqliteSelect::CompoundOperator(SqliteSelect::CompoundOperator::EXCEPT);}
multiselect_op(X)925 multiselect_op(X) ::= INTERSECT. {X = new SqliteSelect::CompoundOperator(SqliteSelect::CompoundOperator::INTERSECT);}
926
927 %type distinct {int*}
928 %destructor distinct {parser_safe_delete($$);}
distinct(X)929 distinct(X) ::= DISTINCT. {X = new int(1);}
distinct(X)930 distinct(X) ::= ALL. {X = new int(2);}
distinct(X)931 distinct(X) ::= . {X = new int(0);}
932
933 %type sclp {ParserResultColumnList*}
934 %destructor sclp {parser_safe_delete($$);}
sclp(X)935 sclp(X) ::= selcollist(L) COMMA. {X = L;}
sclp(X)936 sclp(X) ::= . {X = new ParserResultColumnList();}
937
938 %type selcollist {ParserResultColumnList*}
939 %destructor selcollist {parser_safe_delete($$);}
selcollist(X)940 selcollist(X) ::= sclp(L) expr(E) as(N). {
941 SqliteSelect::Core::ResultColumn* obj =
942 new SqliteSelect::Core::ResultColumn(
943 E,
944 N ? N->asKw : false,
945 N ? N->name : QString()
946 );
947
948 L->append(obj);
949 X = L;
950 delete N;
951 objectForTokens = obj;
952 DONT_INHERIT_TOKENS("sclp");
953 }
selcollist(X)954 selcollist(X) ::= sclp(L) STAR. {
955 SqliteSelect::Core::ResultColumn* obj =
956 new SqliteSelect::Core::ResultColumn(true);
957
958 L->append(obj);
959 X = L;
960 objectForTokens = obj;
961 DONT_INHERIT_TOKENS("sclp");
962 }
selcollist(X)963 selcollist(X) ::= sclp(L) tnm(N) DOT STAR. {
964 SqliteSelect::Core::ResultColumn* obj =
965 new SqliteSelect::Core::ResultColumn(
966 true,
967 N->toName()
968 );
969
970 if (!N->isName())
971 parserContext->errorAtToken("Syntax error <expected name, not literal value>", -3);
972
973 L->append(obj);
974 X = L;
975 delete N;
976 objectForTokens = obj;
977 DONT_INHERIT_TOKENS("sclp");
978 }
selcollist(X)979 selcollist(X) ::= sclp(L). {
980 parserContext->minorErrorBeforeNextToken("Syntax error");
981 X = L;
982 }
983 selcollist ::= sclp ID_TAB DOT STAR. {}
984
985 // An option "AS <id>" phrase that can follow one of the expressions that
986 // define the result set, or one of the tables in the FROM clause.
987
988 %type as {ParserStubAlias*}
989 %destructor as {parser_safe_delete($$);}
as(X)990 as(X) ::= AS nm(N). {
991 X = new ParserStubAlias(*(N), true);
992 delete N;
993 }
as(X)994 as(X) ::= ids(N). {
995 X = new ParserStubAlias(*(N), false);
996 delete N;
997 }
998 as ::= AS ID_ALIAS. {}
999 as ::= ID_ALIAS. {}
as(X)1000 as(X) ::= . {X = nullptr;}
1001
1002 // A complete FROM clause.
1003
1004 %type from {SqliteSelect::Core::JoinSource*}
1005 %destructor from {parser_safe_delete($$);}
from(X)1006 from(X) ::= . {X = nullptr;}
from(X)1007 from(X) ::= FROM joinsrc(L). {X = L;}
1008
1009 %type joinsrc {SqliteSelect::Core::JoinSource*}
1010 %destructor joinsrc {parser_safe_delete($$);}
joinsrc(X)1011 joinsrc(X) ::= singlesrc(S) seltablist(L). {
1012 X = new SqliteSelect::Core::JoinSource(
1013 S,
1014 *(L)
1015 );
1016 delete L;
1017 objectForTokens = X;
1018 }
joinsrc(X)1019 joinsrc(X) ::= . {
1020 parserContext->minorErrorBeforeNextToken("Syntax error");
1021 X = new SqliteSelect::Core::JoinSource();
1022 objectForTokens = X;
1023 }
1024
1025 %type seltablist {ParserOtherSourceList*}
1026 %destructor seltablist {parser_safe_delete($$);}
seltablist(X)1027 seltablist(X) ::= seltablist(L) joinop(O)
1028 singlesrc(S)
1029 joinconstr_opt(C). {
1030 SqliteSelect::Core::JoinSourceOther* src =
1031 new SqliteSelect::Core::JoinSourceOther(O, S, C);
1032
1033 L->append(src);
1034 X = L;
1035 objectForTokens = src;
1036 DONT_INHERIT_TOKENS("seltablist");
1037 }
seltablist(X)1038 seltablist(X) ::= . {
1039 X = new ParserOtherSourceList();
1040 }
1041
1042 %type singlesrc {SqliteSelect::Core::SingleSource*}
1043 %destructor singlesrc {parser_safe_delete($$);}
singlesrc(X)1044 singlesrc(X) ::= nm(N1) dbnm(N2) as(A)
1045 indexed_opt(I). {
1046 X = new SqliteSelect::Core::SingleSource(
1047 *(N1),
1048 *(N2),
1049 A ? A->asKw : false,
1050 A ? A->name : QString(),
1051 I ? I->notIndexedKw : false,
1052 I ? I->indexedBy : QString()
1053 );
1054 delete N1;
1055 delete N2;
1056 delete A;
1057 if (I)
1058 delete I;
1059 objectForTokens = X;
1060 }
singlesrc(X)1061 singlesrc(X) ::= LP select(S) RP as(A). {
1062 X = new SqliteSelect::Core::SingleSource(
1063 S,
1064 A ? A->asKw : false,
1065 A ? A->name : QString()
1066 );
1067 delete A;
1068 objectForTokens = X;
1069 }
singlesrc(X)1070 singlesrc(X) ::= LP joinsrc(J) RP as(A). {
1071 X = new SqliteSelect::Core::SingleSource(
1072 J,
1073 A ? A->asKw : false,
1074 A ? A->name : QString()
1075 );
1076 delete A;
1077 objectForTokens = X;
1078 }
singlesrc(X)1079 singlesrc(X) ::= nm(N1) dbnm(N2)
1080 LP exprlist(E) RP as(A). {
1081 X = new SqliteSelect::Core::SingleSource(
1082 *(N1),
1083 *(N2),
1084 A ? A->asKw : false,
1085 A ? A->name : QString(),
1086 *(E)
1087 );
1088 delete N1;
1089 delete N2;
1090 delete A;
1091 if (E)
1092 delete E;
1093
1094 objectForTokens = X;
1095 }
singlesrc(X)1096 singlesrc(X) ::= . {
1097 parserContext->minorErrorBeforeNextToken("Syntax error");
1098 X = new SqliteSelect::Core::SingleSource();
1099 objectForTokens = X;
1100 }
singlesrc(X)1101 singlesrc(X) ::= nm(N) DOT. {
1102 parserContext->minorErrorBeforeNextToken("Syntax error");
1103 X = new SqliteSelect::Core::SingleSource();
1104 X->database = *(N);
1105 delete N;
1106 objectForTokens = X;
1107 }
1108
1109 singlesrc ::= nm DOT ID_TAB. {}
1110 singlesrc ::= ID_DB|ID_TAB. {}
1111 singlesrc ::= nm DOT ID_VIEW. {}
1112 singlesrc ::= ID_DB|ID_VIEW. {}
1113
1114 %type joinconstr_opt {SqliteSelect::Core::JoinConstraint*}
1115 %destructor joinconstr_opt {parser_safe_delete($$);}
joinconstr_opt(X)1116 joinconstr_opt(X) ::= ON expr(E). {
1117 X = new SqliteSelect::Core::JoinConstraint(E);
1118 objectForTokens = X;
1119 }
joinconstr_opt(X)1120 joinconstr_opt(X) ::= USING LP
1121 idlist(L) RP. {
1122 X = new SqliteSelect::Core::JoinConstraint(*(L));
1123 delete L;
1124 objectForTokens = X;
1125 }
joinconstr_opt(X)1126 joinconstr_opt(X) ::= . {X = nullptr;}
1127
1128 %type dbnm {QString*}
1129 %destructor dbnm {parser_safe_delete($$);}
dbnm(X)1130 dbnm(X) ::= . {X = new QString();}
dbnm(X)1131 dbnm(X) ::= DOT nm(N). {X = N;}
1132
1133 %type fullname {ParserFullName*}
1134 %destructor fullname {parser_safe_delete($$);}
fullname(X)1135 fullname(X) ::= nm(N1) dbnm(N2). {
1136 X = new ParserFullName();
1137 X->name1 = *(N1);
1138 X->name2 = *(N2);
1139 delete N1;
1140 delete N2;
1141 }
1142
1143 %type joinop {SqliteSelect::Core::JoinOp*}
1144 %destructor joinop {parser_safe_delete($$);}
joinop(X)1145 joinop(X) ::= COMMA. {
1146 X = new SqliteSelect::Core::JoinOp(true);
1147 objectForTokens = X;
1148 }
joinop(X)1149 joinop(X) ::= JOIN. {
1150 X = new SqliteSelect::Core::JoinOp(false);
1151 objectForTokens = X;
1152 }
joinop(X)1153 joinop(X) ::= JOIN_KW(K) JOIN. {
1154 X = new SqliteSelect::Core::JoinOp(K->value);
1155 objectForTokens = X;
1156 }
joinop(X)1157 joinop(X) ::= JOIN_KW(K) nm(N) JOIN. {
1158 X = new SqliteSelect::Core::JoinOp(K->value, *(N));
1159 delete N;
1160 objectForTokens = X;
1161 }
joinop(X)1162 joinop(X) ::= JOIN_KW(K) nm(N1) nm(N2)
1163 JOIN. {
1164 X = new SqliteSelect::Core::JoinOp(K->value, *(N1), *(N2));
1165 delete N1;
1166 objectForTokens = X;
1167 }
1168
1169 joinop ::= ID_JOIN_OPTS. {}
1170
1171 // Note that this block abuses the Token type just a little. If there is
1172 // no "INDEXED BY" clause, the returned token is empty (z==0 && n==0). If
1173 // there is an INDEXED BY clause, then the token is populated as per normal,
1174 // with z pointing to the token data and n containing the number of bytes
1175 // in the token.
1176 //
1177 // If there is a "NOT INDEXED" clause, then (z==0 && n==1), which is
1178 // normally illegal. The sqlite3SrcListIndexedBy() function
1179 // recognizes and interprets this as a special case.
1180 %type indexed_opt {ParserIndexedBy*}
1181 %destructor indexed_opt {parser_safe_delete($$);}
indexed_opt(X)1182 indexed_opt(X) ::= . {X = nullptr;}
indexed_opt(X)1183 indexed_opt(X) ::= INDEXED BY nm(N). {
1184 X = new ParserIndexedBy(*(N));
1185 delete N;
1186 }
indexed_opt(X)1187 indexed_opt(X) ::= NOT INDEXED. {X = new ParserIndexedBy(true);}
1188
1189 indexed_opt ::= INDEXED BY ID_IDX. {}
1190
1191 %type orderby_opt {ParserOrderByList*}
1192 %destructor orderby_opt {parser_safe_delete($$);}
orderby_opt(X)1193 orderby_opt(X) ::= . {X = new ParserOrderByList();}
orderby_opt(X)1194 orderby_opt(X) ::= ORDER BY sortlist(L). {X = L;}
1195
1196 // SQLite3 documentation says it's allowed for "COLLATE name" and expr itself handles this.
1197 %type sortlist {ParserOrderByList*}
1198 %destructor sortlist {parser_safe_delete($$);}
sortlist(X)1199 sortlist(X) ::= sortlist(L) COMMA expr(E)
1200 sortorder(O) nulls(N). {
1201 SqliteOrderBy* obj = new SqliteOrderBy(E, *(O), *(N));
1202 L->append(obj);
1203 X = L;
1204 delete O;
1205 delete N;
1206 objectForTokens = obj;
1207 DONT_INHERIT_TOKENS("sortlist");
1208 }
sortlist(X)1209 sortlist(X) ::= expr(E) sortorder(O)
1210 nulls(N). {
1211 SqliteOrderBy* obj = new SqliteOrderBy(E, *(O), *(N));
1212 X = new ParserOrderByList();
1213 X->append(obj);
1214 delete O;
1215 delete N;
1216 objectForTokens = obj;
1217 }
1218
1219 %type sortorder {SqliteSortOrder*}
1220 %destructor sortorder {parser_safe_delete($$);}
sortorder(X)1221 sortorder(X) ::= ASC. {X = new SqliteSortOrder(SqliteSortOrder::ASC);}
sortorder(X)1222 sortorder(X) ::= DESC. {X = new SqliteSortOrder(SqliteSortOrder::DESC);}
sortorder(X)1223 sortorder(X) ::= . {X = new SqliteSortOrder(SqliteSortOrder::null);}
1224
1225 %type nulls {SqliteNulls*}
1226 %destructor nulls {parser_safe_delete($$);}
nulls(X)1227 nulls(X) ::= NULLS FIRST. {X = new SqliteNulls(SqliteNulls::FIRST);}
nulls(X)1228 nulls(X) ::= NULLS LAST. {X = new SqliteNulls(SqliteNulls::LAST);}
nulls(X)1229 nulls(X) ::= . {X = new SqliteNulls(SqliteNulls::null);}
1230
1231 %type groupby_opt {ParserExprList*}
1232 %destructor groupby_opt {parser_safe_delete($$);}
groupby_opt(X)1233 groupby_opt(X) ::= . {X = new ParserExprList();}
groupby_opt(X)1234 groupby_opt(X) ::= GROUP BY nexprlist(L). {X = L;}
groupby_opt(X)1235 groupby_opt(X) ::= GROUP BY. {
1236 parserContext->minorErrorBeforeNextToken("Syntax error");
1237 X = new ParserExprList();
1238 }
1239
1240 %type having_opt {SqliteExpr*}
1241 %destructor having_opt {parser_safe_delete($$);}
having_opt(X)1242 having_opt(X) ::= . {X = nullptr;}
having_opt(X)1243 having_opt(X) ::= HAVING expr(E). {X = E;}
1244
1245 %type limit_opt {SqliteLimit*}
1246 %destructor limit_opt {parser_safe_delete($$);}
limit_opt(X)1247 limit_opt(X) ::= . {X = nullptr;}
limit_opt(X)1248 limit_opt(X) ::= LIMIT expr(E). {
1249 X = new SqliteLimit(E);
1250 objectForTokens = X;
1251 }
limit_opt(X)1252 limit_opt(X) ::= LIMIT expr(E1) OFFSET
1253 expr(E2). {
1254 X = new SqliteLimit(E1, E2, true);
1255 objectForTokens = X;
1256 }
limit_opt(X)1257 limit_opt(X) ::= LIMIT expr(E1) COMMA
1258 expr(E2). {
1259 X = new SqliteLimit(E1, E2, false);
1260 objectForTokens = X;
1261 }
1262
1263 /////////////////////////// The DELETE statement /////////////////////////////
1264
1265 //%ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
1266 //cmd ::= DELETE FROM fullname indexed_opt where_opt
1267 // orderby_opt(O) limit_opt.
1268 //%endif
1269 //%ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
cmd(X)1270 cmd(X) ::= delete_stmt(S). {
1271 X = S;
1272 objectForTokens = X;
1273 }
1274
1275 %type delete_stmt {SqliteQuery*}
1276 %destructor delete_stmt {parser_safe_delete($$);}
delete_stmt(X)1277 delete_stmt(X) ::= with(WI) DELETE FROM
1278 fullname(N)
1279 indexed_opt(I)
1280 where_opt(W). {
1281 if (I)
1282 {
1283 if (!I->indexedBy.isNull())
1284 {
1285 X = new SqliteDelete(
1286 N->name1,
1287 N->name2,
1288 I->indexedBy,
1289 W,
1290 WI
1291 );
1292 }
1293 else
1294 {
1295 X = new SqliteDelete(
1296 N->name1,
1297 N->name2,
1298 I->notIndexedKw,
1299 W,
1300 WI
1301 );
1302 }
1303 delete I;
1304 }
1305 else
1306 {
1307 X = new SqliteDelete(
1308 N->name1,
1309 N->name2,
1310 false,
1311 W,
1312 WI
1313 );
1314 }
1315 delete N;
1316 // since it's used in trigger:
1317 objectForTokens = X;
1318 }
1319 //%endif
1320
delete_stmt(X)1321 delete_stmt(X) ::= with(W) DELETE FROM. {
1322 parserContext->minorErrorBeforeNextToken("Syntax error");
1323 SqliteDelete* q = new SqliteDelete();
1324 q->with = W;
1325 X = q;
1326 objectForTokens = X;
1327 }
delete_stmt(X)1328 delete_stmt(X) ::= with(W) DELETE FROM
1329 nm(N) DOT. {
1330 parserContext->minorErrorBeforeNextToken("Syntax error");
1331 SqliteDelete* q = new SqliteDelete();
1332 q->with = W;
1333 q->database = *(N);
1334 X = q;
1335 objectForTokens = X;
1336 delete N;
1337 }
1338 delete_stmt ::= with DELETE FROM
1339 nm DOT ID_TAB. {}
1340 delete_stmt ::= with DELETE FROM
1341 ID_DB|ID_TAB. {}
1342
1343 %type where_opt {SqliteExpr*}
1344 %destructor where_opt {parser_safe_delete($$);}
where_opt(X)1345 where_opt(X) ::= . {X = nullptr;}
where_opt(X)1346 where_opt(X) ::= WHERE expr(E). {X = E;}
where_opt(X)1347 where_opt(X) ::= WHERE. {
1348 parserContext->minorErrorBeforeNextToken("Syntax error");
1349 X = new SqliteExpr();
1350 }
1351
1352 ////////////////////////// The UPDATE command ////////////////////////////////
1353
cmd(X)1354 cmd(X) ::= update_stmt(S). {
1355 X = S;
1356 objectForTokens = X;
1357 }
1358
1359 %type update_stmt {SqliteQuery*}
1360 %destructor update_stmt {parser_safe_delete($$);}
update_stmt(X)1361 update_stmt(X) ::= with(WI) UPDATE orconf(C)
1362 fullname(N) indexed_opt(I) SET
1363 setlist(L) from(F)
1364 where_opt(W). {
1365 X = new SqliteUpdate(
1366 *(C),
1367 N->name1,
1368 N->name2,
1369 I ? I->notIndexedKw : false,
1370 I ? I->indexedBy : QString(),
1371 *(L),
1372 F,
1373 W,
1374 WI
1375 );
1376 delete C;
1377 delete N;
1378 delete L;
1379 if (I)
1380 delete I;
1381 // since it's used in trigger:
1382 objectForTokens = X;
1383 }
1384
update_stmt(X)1385 update_stmt(X) ::= with(WI) UPDATE
1386 orconf(C). {
1387 parserContext->minorErrorBeforeNextToken("Syntax error");
1388 SqliteUpdate* q = new SqliteUpdate();
1389 q->with = WI;
1390 X = q;
1391 objectForTokens = X;
1392 delete C;
1393 }
update_stmt(X)1394 update_stmt(X) ::= with(WI) UPDATE
1395 orconf(C) nm(N) DOT. {
1396 parserContext->minorErrorBeforeNextToken("Syntax error");
1397 SqliteUpdate* q = new SqliteUpdate();
1398 q->with = WI;
1399 q->database = *(N);
1400 X = q;
1401 objectForTokens = X;
1402 delete C;
1403 delete N;
1404 }
1405 update_stmt ::= with UPDATE orconf nm DOT
1406 ID_TAB. {}
1407 update_stmt ::= with UPDATE orconf
1408 ID_DB|ID_TAB. {}
1409
1410 %type setlist {ParserSetValueList*}
1411 %destructor setlist {parser_safe_delete($$);}
setlist(X)1412 setlist(X) ::= setlist(L) COMMA nm(N) EQ
1413 expr(E). {
1414 L->append(ParserSetValue(*(N), E));
1415 X = L;
1416 delete N;
1417 }
setlist(X)1418 setlist(X) ::= setlist(L) COMMA LP
1419 idlist(N) RP EQ expr(E). {
1420 L->append(ParserSetValue(*(N), E));
1421 X = L;
1422 delete N;
1423 }
setlist(X)1424 setlist(X) ::= nm(N) EQ expr(E). {
1425 X = new ParserSetValueList();
1426 X->append(ParserSetValue(*(N), E));
1427 delete N;
1428 }
setlist(X)1429 setlist(X) ::= LP idlist(N) RP EQ expr(E). {
1430 X = new ParserSetValueList();
1431 X->append(ParserSetValue(*(N), E));
1432 delete N;
1433 }
setlist(X)1434 setlist(X) ::= . {
1435 parserContext->minorErrorBeforeNextToken("Syntax error");
1436 X = new ParserSetValueList();
1437 }
setlist(X)1438 setlist(X) ::= setlist(L) COMMA. {
1439 parserContext->minorErrorBeforeNextToken("Syntax error");
1440 X = L;
1441 }
1442
1443 setlist ::= setlist COMMA ID_COL. {}
1444 setlist ::= ID_COL. {}
1445
1446 %type idlist_opt {QStringList*}
1447 %destructor idlist_opt {parser_safe_delete($$);}
idlist_opt(X)1448 idlist_opt(X) ::= . {X = new QStringList();}
idlist_opt(X)1449 idlist_opt(X) ::= LP idlist(L) RP. {X = L;}
1450
1451 %type idlist {QStringList*}
1452 %destructor idlist {parser_safe_delete($$);}
idlist(X)1453 idlist(X) ::= idlist(L) COMMA nm(N). {
1454 X = L;
1455 *(X) << *(N);
1456 delete N;
1457 }
idlist(X)1458 idlist(X) ::= nm(N). {
1459 X = new QStringList();
1460 *(X) << *(N);
1461 delete N;
1462 }
idlist(X)1463 idlist(X) ::= . {
1464 parserContext->minorErrorBeforeNextToken("Syntax error");
1465 X = new QStringList();
1466 }
1467
1468 idlist ::= idlist COMMA ID_COL. {}
1469 idlist ::= ID_COL. {}
1470
1471 ////////////////////////// The INSERT command /////////////////////////////////
1472
cmd(X)1473 cmd(X) ::= insert_stmt(S). {
1474 X = S;
1475 objectForTokens = X;
1476 }
1477
1478 %type insert_stmt {SqliteQuery*}
1479 %destructor insert_stmt {parser_safe_delete($$);}
1480
insert_stmt(X)1481 insert_stmt(X) ::= with(W) insert_cmd(C)
1482 INTO fullname(N)
1483 idlist_opt(I) select(S)
1484 upsert(U). {
1485 X = new SqliteInsert(
1486 C->replace,
1487 C->orConflict,
1488 N->name1,
1489 N->name2,
1490 *(I),
1491 S,
1492 W,
1493 U
1494 );
1495 delete N;
1496 delete C;
1497 delete I;
1498 // since it's used in trigger:
1499 objectForTokens = X;
1500 }
insert_stmt(X)1501 insert_stmt(X) ::= with(W) insert_cmd(C)
1502 INTO fullname(N)
1503 idlist_opt(I) DEFAULT
1504 VALUES. {
1505 X = new SqliteInsert(
1506 C->replace,
1507 C->orConflict,
1508 N->name1,
1509 N->name2,
1510 *(I),
1511 W
1512 );
1513 delete N;
1514 delete C;
1515 delete I;
1516 // since it's used in trigger:
1517 objectForTokens = X;
1518 }
1519
insert_stmt(X)1520 insert_stmt(X) ::= with(W) insert_cmd(C)
1521 INTO. {
1522 parserContext->minorErrorBeforeNextToken("Syntax error");
1523 SqliteInsert* q = new SqliteInsert();
1524 q->replaceKw = C->replace;
1525 q->onConflict = C->orConflict;
1526 q->with = W;
1527 X = q;
1528 objectForTokens = X;
1529 delete C;
1530 }
insert_stmt(X)1531 insert_stmt(X) ::= with(W) insert_cmd(C)
1532 INTO nm(N) DOT. {
1533 parserContext->minorErrorBeforeNextToken("Syntax error");
1534 SqliteInsert* q = new SqliteInsert();
1535 q->replaceKw = C->replace;
1536 q->onConflict = C->orConflict;
1537 q->with = W;
1538 q->database = *(N);
1539 X = q;
1540 objectForTokens = X;
1541 delete C;
1542 delete N;
1543 }
1544 insert_stmt ::= with insert_cmd INTO
1545 ID_DB|ID_TAB. {}
1546 insert_stmt ::= with insert_cmd INTO
1547 nm DOT ID_TAB. {}
1548
1549 %type insert_cmd {ParserStubInsertOrReplace*}
1550 %destructor insert_cmd {parser_safe_delete($$);}
insert_cmd(X)1551 insert_cmd(X) ::= INSERT orconf(C). {
1552 X = new ParserStubInsertOrReplace(false, *(C));
1553 delete C;
1554 }
insert_cmd(X)1555 insert_cmd(X) ::= REPLACE. {X = new ParserStubInsertOrReplace(true);}
1556
1557
1558 %type upsert {SqliteUpsert*}
1559 %destructor upsert {parser_safe_delete($$);}
1560
upsert(X)1561 upsert(X) ::= . {
1562 X = nullptr;
1563 }
upsert(X)1564 upsert(X) ::= ON CONFLICT LP sortlist(C) RP
1565 where_opt(CW)
1566 DO UPDATE SET setlist(S)
1567 where_opt(SW).
1568 {
1569 X = new SqliteUpsert(*(C), CW, *(S), SW);
1570 delete C;
1571 delete S;
1572 objectForTokens = X;
1573 }
upsert(X)1574 upsert(X) ::= ON CONFLICT LP sortlist(C) RP
1575 where_opt(CW) DO NOTHING. {
1576 X = new SqliteUpsert(*(C), CW);
1577 delete C;
1578 objectForTokens = X;
1579 }
upsert(X)1580 upsert(X) ::= ON CONFLICT DO NOTHING. {
1581 X = new SqliteUpsert();
1582 objectForTokens = X;
1583 }
1584
1585 /////////////////////////// Expression Processing /////////////////////////////
1586
1587 %type exprx {SqliteExpr*}
1588 %destructor exprx {parser_safe_delete($$);}
1589
1590 exprx ::= expr not_opt IN ID_DB. [IN] {}
1591 exprx ::= expr not_opt IN nm DOT
1592 ID_TAB. [IN] {}
1593 exprx ::= ID_DB|ID_TAB|ID_COL|ID_FN. {}
1594 exprx ::= tnm DOT ID_TAB|ID_COL. {}
1595 exprx ::= tnm DOT nm DOT ID_COL. {}
1596 exprx ::= expr COLLATE ID_COLLATE. {}
1597 exprx ::= RAISE LP raisetype COMMA
1598 ID_ERR_MSG RP. {}
1599
1600
exprx(X)1601 exprx(X) ::= CTIME_KW(K). {
1602 X = new SqliteExpr();
1603 X->initCTime(K->value);
1604 objectForTokens = X;
1605 }
exprx(X)1606 exprx(X) ::= LP nexprlist(L) RP. {
1607 X = new SqliteExpr();
1608 X->initRowValue(*(L));
1609 delete L;
1610 objectForTokens = X;
1611 }
exprx(X)1612 exprx(X) ::= tnm(N1). {
1613 X = new SqliteExpr();
1614 if (N1->isLiteral())
1615 X->initLiteral(N1->toLiteral());
1616 else
1617 X->initId(N1->toName());
1618 //parserContext->errorBeforeLastToken("Syntax error <expected literal value>");
1619
1620 delete N1;
1621 objectForTokens = X;
1622 }
exprx(X)1623 exprx(X) ::= tnm(N1) DOT nm(N2). {
1624 X = new SqliteExpr();
1625 if (N1->isName())
1626 X->initId(N1->toName(), *(N2));
1627 else
1628 parserContext->errorAtToken("Syntax error <expected name>", -3);
1629
1630 delete N1;
1631 delete N2;
1632 objectForTokens = X;
1633 }
exprx(X)1634 exprx(X) ::= tnm(N1) DOT nm(N2) DOT nm(N3). {
1635 X = new SqliteExpr();
1636 if (N1->isName())
1637 X->initId(N1->toName(), *(N2), *(N3));
1638 else
1639 parserContext->errorAtToken("Syntax error <expected name>", -5);
1640
1641 delete N1;
1642 delete N2;
1643 delete N3;
1644 objectForTokens = X;
1645 }
exprx(X)1646 exprx(X) ::= VARIABLE(V). {
1647 X = new SqliteExpr();
1648 X->initBindParam(V->value);
1649 objectForTokens = X;
1650 }
exprx(X)1651 exprx(X) ::= expr(E) COLLATE ids(I). {
1652 X = new SqliteExpr();
1653 X->initCollate(E, *(I));
1654 delete I;
1655 objectForTokens = X;
1656 }
exprx(X)1657 exprx(X) ::= CAST LP expr(E) AS typetoken(T)
1658 RP. {
1659 X = new SqliteExpr();
1660 X->initCast(E, T);
1661 objectForTokens = X;
1662 }
exprx(X)1663 exprx(X) ::= ID(I) LP distinct(D)
1664 exprlist(L) RP. {
1665 X = new SqliteExpr();
1666 X->initFunction(I->value, *(D), *(L));
1667 delete D;
1668 delete L;
1669 objectForTokens = X;
1670 }
exprx(X)1671 exprx(X) ::= ID(I) LP STAR RP. {
1672 X = new SqliteExpr();
1673 X->initFunction(I->value, true);
1674 objectForTokens = X;
1675 }
exprx(X)1676 exprx(X) ::= expr(E1) AND(O) expr(E2). {
1677 X = new SqliteExpr();
1678 X->initBinOp(E1, O->value, E2);
1679 objectForTokens = X;
1680 }
exprx(X)1681 exprx(X) ::= expr(E1) OR(O) expr(E2). {
1682 X = new SqliteExpr();
1683 X->initBinOp(E1, O->value, E2);
1684 objectForTokens = X;
1685 }
1686 exprx(X) ::= expr(E1) LT|GT|GE|LE(O)
1687 expr(E2). {
1688 X = new SqliteExpr();
1689 X->initBinOp(E1, O->value, E2);
1690 objectForTokens = X;
1691 }
1692 exprx(X) ::= expr(E1) EQ|NE(O) expr(E2). {
1693 X = new SqliteExpr();
1694 X->initBinOp(E1, O->value, E2);
1695 objectForTokens = X;
1696 }
1697 exprx(X) ::= expr(E1)
1698 BITAND|BITOR|LSHIFT|RSHIFT(O)
1699 expr(E2). {
1700 X = new SqliteExpr();
1701 X->initBinOp(E1, O->value, E2);
1702 objectForTokens = X;
1703 }
1704 exprx(X) ::= expr(E1) PLUS|MINUS(O)
1705 expr(E2). {
1706 X = new SqliteExpr();
1707 X->initBinOp(E1, O->value, E2);
1708 objectForTokens = X;
1709 }
1710 exprx(X) ::= expr(E1) STAR|SLASH|REM(O)
1711 expr(E2). {
1712 X = new SqliteExpr();
1713 X->initBinOp(E1, O->value, E2);
1714 objectForTokens = X;
1715 }
exprx(X)1716 exprx(X) ::= expr(E1) CONCAT(O) expr(E2). {
1717 X = new SqliteExpr();
1718 X->initBinOp(E1, O->value, E2);
1719 objectForTokens = X;
1720 }
exprx(X)1721 exprx(X) ::= expr(E1) not_opt(N) likeop(L)
1722 expr(E2). [LIKE_KW] {
1723 X = new SqliteExpr();
1724 X->initLike(E1, *(N), *(L), E2);
1725 delete N;
1726 delete L;
1727 objectForTokens = X;
1728 }
exprx(X)1729 exprx(X) ::= expr(E1) not_opt(N) likeop(L)
1730 expr(E2) ESCAPE
1731 expr(E3). [LIKE_KW] {
1732 X = new SqliteExpr();
1733 X->initLike(E1, *(N), *(L), E2, E3);
1734 delete N;
1735 delete L;
1736 objectForTokens = X;
1737 }
1738 exprx(X) ::= expr(E) ISNULL|NOTNULL(N). {
1739 X = new SqliteExpr();
1740 X->initNull(E, N->value);
1741 objectForTokens = X;
1742 }
exprx(X)1743 exprx(X) ::= expr(E) NOT NULL. {
1744 X = new SqliteExpr();
1745 X->initNull(E, "NOT NULL");
1746 objectForTokens = X;
1747 }
exprx(X)1748 exprx(X) ::= expr(E1) IS not_opt(N)
1749 expr(E2). {
1750 X = new SqliteExpr();
1751 X->initIs(E1, *(N), E2);
1752 delete N;
1753 objectForTokens = X;
1754 }
exprx(X)1755 exprx(X) ::= NOT(O) expr(E). {
1756 X = new SqliteExpr();
1757 X->initUnaryOp(E, O->value);
1758 }
exprx(X)1759 exprx(X) ::= BITNOT(O) expr(E). {
1760 X = new SqliteExpr();
1761 X->initUnaryOp(E, O->value);
1762 objectForTokens = X;
1763 }
exprx(X)1764 exprx(X) ::= MINUS(O) expr(E). [BITNOT] {
1765 X = new SqliteExpr();
1766 if (E->mode == SqliteExpr::Mode::LITERAL_VALUE &&
1767 parserContext->isCandidateForMaxNegativeNumber() &&
1768 E->literalValue == static_cast<qint64>(0L))
1769 {
1770 X->initLiteral(std::numeric_limits<qint64>::min());
1771 delete E;
1772 }
1773 else
1774 {
1775 X->initUnaryOp(E, O->value);
1776 }
1777 objectForTokens = X;
1778 }
exprx(X)1779 exprx(X) ::= PLUS(O) expr(E). [BITNOT] {
1780 X = new SqliteExpr();
1781 X->initUnaryOp(E, O->value);
1782 objectForTokens = X;
1783 }
exprx(X)1784 exprx(X) ::= expr(E1) not_opt(N) BETWEEN
1785 expr(E2) AND
1786 expr(E3). [BETWEEN] {
1787 X = new SqliteExpr();
1788 X->initBetween(E1, *(N), E2, E3);
1789 delete N;
1790 objectForTokens = X;
1791 }
exprx(X)1792 exprx(X) ::= expr(E) not_opt(N) IN LP
1793 exprlist(L) RP. [IN] {
1794 X = new SqliteExpr();
1795 X->initIn(E, *(N), *(L));
1796 delete N;
1797 delete L;
1798 objectForTokens = X;
1799 }
exprx(X)1800 exprx(X) ::= LP select(S) RP. {
1801 X = new SqliteExpr();
1802 X->initSubSelect(S);
1803 objectForTokens = X;
1804 }
exprx(X)1805 exprx(X) ::= expr(E) not_opt(N) IN LP
1806 select(S) RP. [IN] {
1807 X = new SqliteExpr();
1808 X->initIn(E, *(N), S);
1809 delete N;
1810 objectForTokens = X;
1811 }
exprx(X)1812 exprx(X) ::= expr(E) not_opt(N) IN nm(N1)
1813 dbnm(N2). [IN] {
1814 X = new SqliteExpr();
1815 X->initIn(E, *(N), *(N1), *(N2));
1816 delete N;
1817 delete N1;
1818 objectForTokens = X;
1819 }
exprx(X)1820 exprx(X) ::= EXISTS LP select(S) RP. {
1821 X = new SqliteExpr();
1822 X->initExists(S);
1823 objectForTokens = X;
1824 }
exprx(X)1825 exprx(X) ::= CASE case_operand(O)
1826 case_exprlist(L)
1827 case_else(E) END. {
1828 X = new SqliteExpr();
1829 X->initCase(O, *(L), E);
1830 delete L;
1831 objectForTokens = X;
1832 }
1833
exprx(X)1834 exprx(X) ::= RAISE LP IGNORE(R) RP. {
1835 X = new SqliteExpr();
1836 X->initRaise(R->value);
1837 objectForTokens = X;
1838 }
exprx(X)1839 exprx(X) ::= RAISE LP raisetype(R) COMMA
1840 nm(N) RP. {
1841 X = new SqliteExpr();
1842 X->initRaise(R->value, *(N));
1843 delete N;
1844 objectForTokens = X;
1845 }
exprx(X)1846 exprx(X) ::= ID(I) LP distinct(D)
1847 exprlist(E) RP filter_over(F). {
1848 X = new SqliteExpr();
1849 X->initWindowFunction(I->value, *(D), *(E), F);
1850 delete D;
1851 delete E;
1852 objectForTokens = X;
1853 }
exprx(X)1854 exprx(X) ::= ID(I) LP STAR RP
1855 filter_over(F). {
1856 X = new SqliteExpr();
1857 X->initWindowFunction(I->value, F);
1858 objectForTokens = X;
1859 }
1860
1861 %type expr {SqliteExpr*}
1862 %destructor expr {parser_safe_delete($$);}
expr(X)1863 expr(X) ::= . {
1864 X = new SqliteExpr();
1865 objectForTokens = X;
1866 parserContext->minorErrorAfterLastToken("Syntax error <expr>");
1867 }
expr(X)1868 expr(X) ::= exprx(E). {X = E;}
1869
1870 %type not_opt {bool*}
1871 %destructor not_opt {parser_safe_delete($$);}
not_opt(X)1872 not_opt(X) ::= . {X = new bool(false);}
not_opt(X)1873 not_opt(X) ::= NOT. {X = new bool(true);}
1874
1875 %type likeop {SqliteExpr::LikeOp*}
1876 %destructor likeop {parser_safe_delete($$);}
1877 likeop(X) ::= LIKE_KW|MATCH(T). {X = new SqliteExpr::LikeOp(SqliteExpr::likeOp(T->value));}
1878
1879 %type case_exprlist {ParserExprList*}
1880 %destructor case_exprlist {parser_safe_delete($$);}
case_exprlist(X)1881 case_exprlist(X) ::= case_exprlist(L) WHEN
1882 expr(E1) THEN expr(E2). {
1883 L->append(E1);
1884 L->append(E2);
1885 X = L;
1886 }
case_exprlist(X)1887 case_exprlist(X) ::= WHEN expr(E1) THEN
1888 expr(E2). {
1889 X = new ParserExprList();
1890 X->append(E1);
1891 X->append(E2);
1892 }
1893
1894 %type case_else {SqliteExpr*}
1895 %destructor case_else {parser_safe_delete($$);}
case_else(X)1896 case_else(X) ::= ELSE expr(E). {X = E;}
case_else(X)1897 case_else(X) ::= . {X = nullptr;}
1898
1899 %type case_operand {SqliteExpr*}
1900 %destructor case_operand {parser_safe_delete($$);}
case_operand(X)1901 case_operand(X) ::= exprx(E). {X = E;}
case_operand(X)1902 case_operand(X) ::= . {X = nullptr;}
1903
1904 %type exprlist {ParserExprList*}
1905 %destructor exprlist {parser_safe_delete($$);}
exprlist(X)1906 exprlist(X) ::= nexprlist(L). {X = L;}
exprlist(X)1907 exprlist(X) ::= . {X = new ParserExprList();}
1908
1909 %type nexprlist {ParserExprList*}
1910 %destructor nexprlist {parser_safe_delete($$);}
nexprlist(X)1911 nexprlist(X) ::= nexprlist(L) COMMA
1912 expr(E). {
1913 L->append(E);
1914 X = L;
1915 DONT_INHERIT_TOKENS("nexprlist");
1916 }
nexprlist(X)1917 nexprlist(X) ::= exprx(E). {
1918 X = new ParserExprList();
1919 X->append(E);
1920 }
1921
1922 ///////////////////////////// The CREATE INDEX command ///////////////////////
1923
cmd(X)1924 cmd(X) ::= CREATE uniqueflag(U) INDEX
1925 ifnotexists(E) nm(N1) dbnm(N2)
1926 ON nm(N3) LP sortlist(L) RP
1927 where_opt(W). {
1928 X = new SqliteCreateIndex(
1929 *(U),
1930 *(E),
1931 *(N1),
1932 *(N2),
1933 *(N3),
1934 *(L),
1935 W
1936 );
1937 delete E;
1938 delete U;
1939 delete N1;
1940 delete N2;
1941 delete N3;
1942 delete L;
1943 objectForTokens = X;
1944 }
1945
1946 cmd ::= CREATE uniqueflag INDEX ifnotexists
1947 nm dbnm ON ID_TAB. {}
1948 cmd ::= CREATE uniqueflag INDEX ifnotexists
1949 nm DOT ID_IDX_NEW. {}
1950 cmd ::= CREATE uniqueflag INDEX ifnotexists
1951 ID_DB|ID_IDX_NEW. {}
1952
1953
1954 %type uniqueflag {bool*}
1955 %destructor uniqueflag {parser_safe_delete($$);}
uniqueflag(X)1956 uniqueflag(X) ::= UNIQUE. {X = new bool(true);}
uniqueflag(X)1957 uniqueflag(X) ::= . {X = new bool(false);}
1958
1959 %type idxlist_opt {ParserIndexedColumnList*}
1960 %destructor idxlist_opt {parser_safe_delete($$);}
idxlist_opt(X)1961 idxlist_opt(X) ::= . {X = new ParserIndexedColumnList();}
idxlist_opt(X)1962 idxlist_opt(X) ::= LP idxlist(I) RP. {X = I;}
1963
1964 %type idxlist {ParserIndexedColumnList*}
1965 %destructor idxlist {parser_safe_delete($$);}
idxlist(X)1966 idxlist(X) ::= idxlist(L) COMMA
1967 idxlist_single(S). {
1968 L->append(S);
1969 X = L;
1970 DONT_INHERIT_TOKENS("idxlist");
1971 }
idxlist(X)1972 idxlist(X) ::= idxlist_single(S). {
1973 X = new ParserIndexedColumnList();
1974 X->append(S);
1975 }
1976
1977 %type idxlist_single {SqliteIndexedColumn*}
1978 %destructor idxlist_single {parser_safe_delete($$);}
idxlist_single(X)1979 idxlist_single(X) ::= nm(N) collate(C)
1980 sortorder(S). {
1981 SqliteIndexedColumn* obj =
1982 new SqliteIndexedColumn(
1983 *(N),
1984 *(C),
1985 *(S)
1986 );
1987 X = obj;
1988 delete S;
1989 delete N;
1990 delete C;
1991 objectForTokens = X;
1992 }
1993
1994 idxlist_single ::= ID_COL. {}
1995
1996 %type collate {QString*}
1997 %destructor collate {parser_safe_delete($$);}
collate(X)1998 collate(X) ::= . {X = new QString();}
collate(X)1999 collate(X) ::= COLLATE ids(I). {X = I;}
2000 collate ::= COLLATE ID_COLLATE. {}
2001
2002
2003 ///////////////////////////// The DROP INDEX command /////////////////////////
2004
cmd(X)2005 cmd(X) ::= DROP INDEX ifexists(I)
2006 fullname(N). {
2007 X = new SqliteDropIndex(*(I), N->name1, N->name2);
2008 delete I;
2009 delete N;
2010 objectForTokens = X;
2011 }
2012
2013 cmd ::= DROP INDEX ifexists nm DOT ID_IDX. {}
2014 cmd ::= DROP INDEX ifexists ID_DB|ID_IDX. {}
2015
2016 ///////////////////////////// The VACUUM command /////////////////////////////
2017
cmd(X)2018 cmd(X) ::= VACUUM vinto(I). {
2019 X = new SqliteVacuum(I);
2020 objectForTokens = X;
2021 }
cmd(X)2022 cmd(X) ::= VACUUM nm(N) vinto(I). {
2023 X = new SqliteVacuum(*(N), I);
2024 delete N;
2025 objectForTokens = X;
2026 }
2027
2028
2029 %type vinto {SqliteExpr*}
2030 %destructor vinto {parser_safe_delete($$);}
vinto(X)2031 vinto(X) ::= INTO expr(E). {X = E;}
vinto(X)2032 vinto(X) ::= . {X = nullptr;}
2033
2034 ///////////////////////////// The PRAGMA command /////////////////////////////
2035
cmd(X)2036 cmd(X) ::= PRAGMA nm(N1) dbnm(N2). {
2037 X = new SqlitePragma(*(N1), *(N2));
2038 delete N1;
2039 delete N2;
2040 objectForTokens = X;
2041 }
cmd(X)2042 cmd(X) ::= PRAGMA nm(N1) dbnm(N2) EQ
2043 nmnum(V). {
2044 X = new SqlitePragma(*(N1), *(N2), *(V), true);
2045 delete N1;
2046 delete N2;
2047 delete V;
2048 objectForTokens = X;
2049 }
cmd(X)2050 cmd(X) ::= PRAGMA nm(N1) dbnm(N2) LP
2051 nmnum(V) RP. {
2052 X = new SqlitePragma(*(N1), *(N2), *(V), false);
2053 delete N1;
2054 delete N2;
2055 delete V;
2056 objectForTokens = X;
2057 }
cmd(X)2058 cmd(X) ::= PRAGMA nm(N1) dbnm(N2) EQ
2059 minus_num(V). {
2060 X = new SqlitePragma(*(N1), *(N2), *(V), true);
2061 delete N1;
2062 delete N2;
2063 delete V;
2064 objectForTokens = X;
2065 }
cmd(X)2066 cmd(X) ::= PRAGMA nm(N1) dbnm(N2) LP
2067 minus_num(V) RP. {
2068 X = new SqlitePragma(*(N1), *(N2), *(V), false);
2069 delete N1;
2070 delete N2;
2071 delete V;
2072 objectForTokens = X;
2073 }
2074
2075 cmd ::= PRAGMA nm DOT ID_PRAGMA. {}
2076 cmd ::= PRAGMA ID_DB|ID_PRAGMA. {}
2077
2078 %type nmnum {QVariant*}
2079 %destructor nmnum {parser_safe_delete($$);}
nmnum(X)2080 nmnum(X) ::= plus_num(N). {X = N;}
nmnum(X)2081 nmnum(X) ::= nm(N). {
2082 X = new QVariant(*(N));
2083 delete N;
2084 }
nmnum(X)2085 nmnum(X) ::= ON(T). {X = new QVariant(T->value);}
nmnum(X)2086 nmnum(X) ::= DELETE(T). {X = new QVariant(T->value);}
nmnum(X)2087 nmnum(X) ::= DEFAULT(T). {X = new QVariant(T->value);}
2088
2089 %type plus_num {QVariant*}
2090 %destructor plus_num {parser_safe_delete($$);}
plus_num(X)2091 plus_num(X) ::= PLUS number(N). {X = N;}
plus_num(X)2092 plus_num(X) ::= number(N). {X = N;}
2093
2094 %type minus_num {QVariant*}
2095 %destructor minus_num {parser_safe_delete($$);}
minus_num(X)2096 minus_num(X) ::= MINUS number(N). {
2097 if (N->type() == QVariant::Double)
2098 *(N) = -(N->toDouble());
2099 else if (N->type() == QVariant::LongLong)
2100 {
2101 if (parserContext->isCandidateForMaxNegativeNumber())
2102 *(N) = std::numeric_limits<qint64>::min();
2103 else
2104 *(N) = -(N->toLongLong());
2105 }
2106 else
2107 Q_ASSERT_X(true, "producing minus number", "QVariant is neither of Double or LongLong.");
2108
2109 X = N;
2110 }
2111
2112 %type number {QVariant*}
2113 %destructor number {parser_safe_delete($$);}
number(X)2114 number(X) ::= INTEGER(N). {X = parserContext->handleNumberToken(N->value);}
number(X)2115 number(X) ::= FLOAT(N). {X = new QVariant(QVariant(N->value).toDouble());}
2116
2117 //////////////////////////// The CREATE TRIGGER command /////////////////////
2118
2119 // Sqlite grammar uses 'fullname' for table name, but it's forbidden anyway,
2120 // because you cannot create trigger for table in different database.
2121 // We use 'nm' instead, as it's more proper. Will see if it truns out to be a problem.
cmd(X)2122 cmd(X) ::= CREATE temp(T) TRIGGER
2123 ifnotexists(IE) nm(N1) dbnm(N2)
2124 trigger_time(TT) trigger_event(EV)
2125 ON nm(N) foreach_clause(FC)
2126 when_clause(WC) BEGIN
2127 trigger_cmd_list(CL) END. {
2128 X = new SqliteCreateTrigger(
2129 *(T),
2130 *(IE),
2131 *(N1),
2132 *(N2),
2133 *(N),
2134 *(TT),
2135 EV,
2136 *(FC),
2137 WC,
2138 *(CL),
2139 3
2140 );
2141 delete IE;
2142 delete T;
2143 delete TT;
2144 delete FC;
2145 delete N1;
2146 delete N;
2147 delete N2;
2148 delete CL;
2149 objectForTokens = X;
2150 }
2151
2152 // Support full parsing when no BEGIN and END are present (for completion helper)
cmd(X)2153 cmd(X) ::= CREATE temp(T) TRIGGER
2154 ifnotexists(IE) nm(N1) dbnm(N2)
2155 trigger_time(TT) trigger_event(EV)
2156 ON nm(N) foreach_clause(FC)
2157 when_clause(WC). {
2158 QList<SqliteQuery *> CL;
2159
2160 X = new SqliteCreateTrigger(
2161 *(T),
2162 *(IE),
2163 *(N1),
2164 *(N2),
2165 *(N),
2166 *(TT),
2167 EV,
2168 *(FC),
2169 WC,
2170 CL,
2171 3
2172 );
2173 delete IE;
2174 delete T;
2175 delete TT;
2176 delete FC;
2177 delete N1;
2178 delete N;
2179 delete N2;
2180 objectForTokens = X;
2181 parserContext->minorErrorAfterLastToken("Syntax error");
2182 }
2183
2184 // Support full parsing when no END is present (for completion helper)
cmd(X)2185 cmd(X) ::= CREATE temp(T) TRIGGER
2186 ifnotexists(IE) nm(N1) dbnm(N2)
2187 trigger_time(TT) trigger_event(EV)
2188 ON nm(N) foreach_clause(FC)
2189 when_clause(WC) BEGIN
2190 trigger_cmd_list(CL). {
2191 X = new SqliteCreateTrigger(
2192 *(T),
2193 *(IE),
2194 *(N1),
2195 *(N2),
2196 *(N),
2197 *(TT),
2198 EV,
2199 *(FC),
2200 WC,
2201 *(CL),
2202 3
2203 );
2204 delete IE;
2205 delete T;
2206 delete TT;
2207 delete FC;
2208 delete N1;
2209 delete N;
2210 delete N2;
2211 delete CL;
2212 objectForTokens = X;
2213 parserContext->minorErrorAfterLastToken("Syntax error");
2214 }
2215
2216 cmd ::= CREATE temp TRIGGER ifnotexists nm
2217 dbnm trigger_time trigger_event
2218 ON ID_TAB. {}
2219 cmd ::= CREATE temp TRIGGER ifnotexists nm
2220 DOT ID_TRIG_NEW. {}
2221 cmd ::= CREATE temp TRIGGER ifnotexists
2222 ID_DB|ID_TRIG_NEW. {}
2223
2224 %type trigger_time {SqliteCreateTrigger::Time*}
2225 %destructor trigger_time {parser_safe_delete($$);}
trigger_time(X)2226 trigger_time(X) ::= BEFORE. {X = new SqliteCreateTrigger::Time(SqliteCreateTrigger::Time::BEFORE);}
trigger_time(X)2227 trigger_time(X) ::= AFTER. {X = new SqliteCreateTrigger::Time(SqliteCreateTrigger::Time::AFTER);}
trigger_time(X)2228 trigger_time(X) ::= INSTEAD OF. {X = new SqliteCreateTrigger::Time(SqliteCreateTrigger::Time::INSTEAD_OF);}
trigger_time(X)2229 trigger_time(X) ::= . {X = new SqliteCreateTrigger::Time(SqliteCreateTrigger::Time::null);}
2230
2231 %type trigger_event {SqliteCreateTrigger::Event*}
2232 %destructor trigger_event {parser_safe_delete($$);}
trigger_event(X)2233 trigger_event(X) ::= DELETE. {
2234 X = new SqliteCreateTrigger::Event(SqliteCreateTrigger::Event::DELETE);
2235 objectForTokens = X;
2236 }
trigger_event(X)2237 trigger_event(X) ::= INSERT. {
2238 X = new SqliteCreateTrigger::Event(SqliteCreateTrigger::Event::INSERT);
2239 objectForTokens = X;
2240 }
trigger_event(X)2241 trigger_event(X) ::= UPDATE. {
2242 X = new SqliteCreateTrigger::Event(SqliteCreateTrigger::Event::UPDATE);
2243 objectForTokens = X;
2244 }
trigger_event(X)2245 trigger_event(X) ::= UPDATE OF
2246 idlist(L). {
2247 X = new SqliteCreateTrigger::Event(*(L));
2248 delete L;
2249 objectForTokens = X;
2250 }
2251
2252 %type foreach_clause {SqliteCreateTrigger::Scope*}
2253 %destructor foreach_clause {parser_safe_delete($$);}
foreach_clause(X)2254 foreach_clause(X) ::= . {X = new SqliteCreateTrigger::Scope(SqliteCreateTrigger::Scope::null);}
foreach_clause(X)2255 foreach_clause(X) ::= FOR EACH ROW. {X = new SqliteCreateTrigger::Scope(SqliteCreateTrigger::Scope::FOR_EACH_ROW);}
2256
2257 %type when_clause {SqliteExpr*}
2258 %destructor when_clause {parser_safe_delete($$);}
when_clause(X)2259 when_clause(X) ::= . {X = nullptr;}
when_clause(X)2260 when_clause(X) ::= WHEN expr(E). {X = E;}
2261
2262 %type trigger_cmd_list {ParserQueryList*}
2263 %destructor trigger_cmd_list {parser_safe_delete($$);}
trigger_cmd_list(X)2264 trigger_cmd_list(X) ::= trigger_cmd_list(L)
2265 trigger_cmd(C) SEMI. {
2266 L->append(C);
2267 X = L;
2268 DONT_INHERIT_TOKENS("trigger_cmd_list");
2269 }
trigger_cmd_list(X)2270 trigger_cmd_list(X) ::= trigger_cmd(C)
2271 SEMI. {
2272 X = new ParserQueryList();
2273 X->append(C);
2274 }
trigger_cmd_list(X)2275 trigger_cmd_list(X) ::= SEMI. {
2276 X = new ParserQueryList();
2277 parserContext->minorErrorAfterLastToken("Syntax error");
2278 }
2279
2280 %type trigger_cmd {SqliteQuery*}
2281 %destructor trigger_cmd {parser_safe_delete($$);}
trigger_cmd(X)2282 trigger_cmd(X) ::= update_stmt(S). {X = S;}
trigger_cmd(X)2283 trigger_cmd(X) ::= insert_stmt(S). {X = S;}
trigger_cmd(X)2284 trigger_cmd(X) ::= delete_stmt(S). {X = S;}
trigger_cmd(X)2285 trigger_cmd(X) ::= select_stmt(S). {X = S;}
2286
2287 %type raisetype {Token*}
2288 raisetype(X) ::= ROLLBACK|ABORT|FAIL(V). {X = V;}
2289
2290
2291 //////////////////////// DROP TRIGGER statement //////////////////////////////
cmd(X)2292 cmd(X) ::= DROP TRIGGER ifexists(E)
2293 fullname(N). {
2294 X = new SqliteDropTrigger(*(E), N->name1, N->name2);
2295 delete E;
2296 delete N;
2297 objectForTokens = X;
2298 }
2299
2300 cmd ::= DROP TRIGGER ifexists nm DOT
2301 ID_TRIG. {}
2302 cmd ::= DROP TRIGGER ifexists
2303 ID_DB|ID_TRIG. {}
2304
2305 //////////////////////// ATTACH DATABASE file AS name /////////////////////////
cmd(X)2306 cmd(X) ::= ATTACH database_kw_opt(D)
2307 expr(E1) AS expr(E2) key_opt(K). {
2308 X = new SqliteAttach(*(D), E1, E2, K);
2309 delete D;
2310 objectForTokens = X;
2311 }
cmd(X)2312 cmd(X) ::= DETACH database_kw_opt(D)
2313 expr(E). {
2314 X = new SqliteDetach(*(D), E);
2315 delete D;
2316 objectForTokens = X;
2317 }
2318
2319 %type key_opt {SqliteExpr*}
2320 %destructor key_opt {parser_safe_delete($$);}
key_opt(X)2321 key_opt(X) ::= . {X = nullptr;}
key_opt(X)2322 key_opt(X) ::= KEY expr(E). {X = E;}
2323
2324 %type database_kw_opt {bool*}
2325 %destructor database_kw_opt {parser_safe_delete($$);}
database_kw_opt(X)2326 database_kw_opt(X) ::= DATABASE. {X = new bool(true);}
database_kw_opt(X)2327 database_kw_opt(X) ::= . {X = new bool(false);}
2328
2329 ////////////////////////// REINDEX collation //////////////////////////////////
cmd(X)2330 cmd(X) ::= REINDEX. {X = new SqliteReindex();}
cmd(X)2331 cmd(X) ::= REINDEX nm(N1) dbnm(N2). {
2332 X = new SqliteReindex(*(N1), *(N2));
2333 delete N1;
2334 delete N2;
2335 objectForTokens = X;
2336 }
2337
2338 cmd ::= REINDEX ID_COLLATE. {}
2339 cmd ::= REINDEX nm DOT ID_TAB|ID_IDX. {}
2340 cmd ::= REINDEX ID_DB|ID_IDX|ID_TAB. {}
2341
2342 /////////////////////////////////// ANALYZE ///////////////////////////////////
cmd(X)2343 cmd(X) ::= ANALYZE. {
2344 X = new SqliteAnalyze();
2345 objectForTokens = X;
2346 }
cmd(X)2347 cmd(X) ::= ANALYZE nm(N1) dbnm(N2). {
2348 X = new SqliteAnalyze(*(N1), *(N2));
2349 delete N1;
2350 delete N2;
2351 objectForTokens = X;
2352 }
2353
2354 cmd ::= ANALYZE nm DOT ID_TAB|ID_IDX. {}
2355 cmd ::= ANALYZE ID_DB|ID_IDX|ID_TAB. {}
2356
2357 //////////////////////// ALTER TABLE table ... ////////////////////////////////
cmd(X)2358 cmd(X) ::= ALTER TABLE fullname(FN) RENAME
2359 TO nm(N). {
2360 X = new SqliteAlterTable(
2361 FN->name1,
2362 FN->name2,
2363 *(N)
2364 );
2365 delete N;
2366 delete FN;
2367 objectForTokens = X;
2368 }
cmd(X)2369 cmd(X) ::= ALTER TABLE fullname(FN) ADD
2370 kwcolumn_opt(K) column(C). {
2371 X = new SqliteAlterTable(
2372 FN->name1,
2373 FN->name2,
2374 *(K),
2375 C
2376 );
2377 delete K;
2378 delete FN;
2379 objectForTokens = X;
2380 }
2381
2382 cmd ::= ALTER TABLE fullname RENAME TO
2383 ID_TAB_NEW. {}
2384 cmd ::= ALTER TABLE nm DOT ID_TAB. {}
2385 cmd ::= ALTER TABLE ID_DB|ID_TAB. {}
2386
2387 %type kwcolumn_opt {bool*}
2388 %destructor kwcolumn_opt {parser_safe_delete($$);}
kwcolumn_opt(X)2389 kwcolumn_opt(X) ::= . {X = new bool(true);}
kwcolumn_opt(X)2390 kwcolumn_opt(X) ::= COLUMNKW. {X = new bool(false);}
2391
2392 //////////////////////// CREATE VIRTUAL TABLE ... /////////////////////////////
cmd(X)2393 cmd(X) ::= create_vtab(C). {X = C;}
2394
2395 %type create_vtab {SqliteQuery*}
2396 %destructor create_vtab {parser_safe_delete($$);}
create_vtab(X)2397 create_vtab(X) ::= CREATE VIRTUAL TABLE
2398 ifnotexists(E) nm(N1)
2399 dbnm(N2) USING nm(N3). {
2400 X = new SqliteCreateVirtualTable(
2401 *(E),
2402 *(N1),
2403 *(N2),
2404 *(N3)
2405 );
2406 delete E;
2407 delete N1;
2408 delete N2;
2409 delete N3;
2410 objectForTokens = X;
2411 }
create_vtab(X)2412 create_vtab(X) ::= CREATE VIRTUAL TABLE
2413 ifnotexists(E) nm(N1)
2414 dbnm(N2) USING nm(N3) LP
2415 vtabarglist(A) RP. {
2416 X = new SqliteCreateVirtualTable(
2417 *(E),
2418 *(N1),
2419 *(N2),
2420 *(N3),
2421 *(A)
2422 );
2423 delete N1;
2424 delete N2;
2425 delete N3;
2426 delete E;
2427 delete A;
2428 objectForTokens = X;
2429 }
2430
2431 create_vtab ::= CREATE VIRTUAL TABLE
2432 ifnotexists nm DOT
2433 ID_TAB_NEW. {}
2434 create_vtab ::= CREATE VIRTUAL TABLE
2435 ifnotexists
2436 ID_DB|ID_TAB_NEW. {}
2437
2438 %type vtabarglist {QStringList*}
2439 %destructor vtabarglist {parser_safe_delete($$);}
vtabarglist(X)2440 vtabarglist(X) ::= vtabarg(A). {
2441 X = new QStringList();
2442 X->append((A)->mid(1)); // mid(1) to skip the first whitespace added in vtabarg
2443 delete A;
2444 }
vtabarglist(X)2445 vtabarglist(X) ::= vtabarglist(L) COMMA
2446 vtabarg(A). {
2447 L->append((A)->mid(1)); // mid(1) to skip the first whitespace added in vtabarg
2448 X = L;
2449 delete A;
2450 DONT_INHERIT_TOKENS("vtabarglist");
2451 }
2452
2453 %type vtabarg {QString*}
2454 %destructor vtabarg {parser_safe_delete($$);}
vtabarg(X)2455 vtabarg(X) ::= . {X = new QString();}
vtabarg(X)2456 vtabarg(X) ::= vtabarg(A) vtabargtoken(T). {
2457 A->append(" "+ *(T));
2458 X = A;
2459 delete T;
2460 }
2461
2462 %type vtabargtoken {QString*}
2463 %destructor vtabargtoken {parser_safe_delete($$);}
vtabargtoken(X)2464 vtabargtoken(X) ::= ANY(A). {
2465 X = new QString(A->value);
2466 }
vtabargtoken(X)2467 vtabargtoken(X) ::= LP anylist(L) RP. {
2468 X = new QString("(");
2469 X->append(*(L));
2470 X->append(")");
2471 delete L;
2472 }
2473
2474 %type anylist {QString*}
2475 %destructor anylist {parser_safe_delete($$);}
anylist(X)2476 anylist(X) ::= . {X = new QString();}
anylist(X)2477 anylist(X) ::= anylist(L1) LP anylist(L2)
2478 RP. {
2479 X = L1;
2480 X->append("(");
2481 X->append(*(L2));
2482 X->append(")");
2483 delete L2;
2484 DONT_INHERIT_TOKENS("anylist");
2485 }
anylist(X)2486 anylist(X) ::= anylist(L) ANY(A). {
2487 X = L;
2488 X->append(A->value);
2489 DONT_INHERIT_TOKENS("anylist");
2490 }
2491
2492 //////////////////////// COMMON TABLE EXPRESSIONS ////////////////////////////
2493 %type with {SqliteWith*}
2494 %destructor with {parser_safe_delete($$);}
2495
with(X)2496 with(X) ::= . {X = nullptr;}
with(X)2497 with(X) ::= WITH wqlist(W). {
2498 X = new SqliteWith();
2499 X->cteList = *(W);
2500 delete W;
2501 objectForTokens = X;
2502 }
with(X)2503 with(X) ::= WITH RECURSIVE wqlist(W). {
2504 X = new SqliteWith();
2505 X->cteList = *(W);
2506 X->recursive = true;
2507 delete W;
2508 objectForTokens = X;
2509 }
2510
2511 %type wqlist {ParserCteList*}
2512 %destructor wqlist {parser_safe_delete($$);}
2513
wqlist(X)2514 wqlist(X) ::= wqcte(C). {
2515 X = new ParserCteList();
2516 X->append(C);
2517 }
wqlist(X)2518 wqlist(X) ::= wqlist(W) COMMA wqcte(C). {
2519 X = W;
2520 X->append(C);
2521 DONT_INHERIT_TOKENS("wqlist");
2522 }
2523 wqlist ::= ID_TAB_NEW. {
2524 parserContext->minorErrorBeforeNextToken("Syntax error");
2525 }
2526
2527 %type wqcte {SqliteWith::CommonTableExpression*}
2528 %destructor wqcte {parser_safe_delete($$);}
2529
wqcte(X)2530 wqcte(X) ::= nm(N) idxlist_opt(IL) AS
2531 LP select(S) RP. {
2532 X = new SqliteWith::CommonTableExpression(*(N), *(IL), S);
2533 delete N;
2534 delete IL;
2535 objectForTokens = X;
2536 }
2537
2538 //////////////////////// WINDOW FUNCTION EXPRESSIONS /////////////////////////
2539 // These must be at the end of this file. Specifically, the rules that
2540 // introduce tokens WINDOW, OVER and FILTER must appear last. This causes
2541 // the integer values assigned to these tokens to be larger than all other
2542 // tokens that may be output by the tokenizer except TK_SPACE and TK_ILLEGAL.
2543 //
2544 %type windowdefn_list {ParserWindowDefList*}
2545 %destructor windowdefn_list {parser_safe_delete($$);}
2546
windowdefn_list(X)2547 windowdefn_list(X) ::= windowdefn(W). {
2548 X = new ParserWindowDefList();
2549 X->append(W);
2550 }
windowdefn_list(X)2551 windowdefn_list(X) ::= windowdefn_list(L)
2552 COMMA windowdefn(W). {
2553 L->append(W);
2554 X = L;
2555 DONT_INHERIT_TOKENS("windowdefn_list");
2556 }
2557
2558 %type windowdefn {SqliteWindowDefinition*}
2559 %destructor windowdefn {parser_safe_delete($$);}
2560
windowdefn(X)2561 windowdefn(X) ::= nm(N) AS LP window(W) RP. {
2562 X = new SqliteWindowDefinition(*(N), W);
2563 delete N;
2564 objectForTokens = X;
2565 }
2566
2567 %type window {SqliteWindowDefinition::Window*}
2568 %destructor window {parser_safe_delete($$);}
2569
window(X)2570 window(X) ::= PARTITION BY nexprlist(L)
2571 orderby_opt(O) frame_opt(F). {
2572 X = new SqliteWindowDefinition::Window();
2573 X->initPartitionBy(QString(), *(L), *(O), F);
2574 delete L;
2575 delete O;
2576 objectForTokens = X;
2577 }
window(X)2578 window(X) ::= nm(N) PARTITION BY
2579 nexprlist(L) orderby_opt(O)
2580 frame_opt(F). {
2581 X = new SqliteWindowDefinition::Window();
2582 X->initPartitionBy(*(N), *(L), *(O), F);
2583 delete L;
2584 delete N;
2585 delete O;
2586 objectForTokens = X;
2587 }
window(X)2588 window(X) ::= ORDER BY sortlist(S)
2589 frame_opt(F). {
2590 X = new SqliteWindowDefinition::Window();
2591 X->initOrderBy(QString(), *(S), F);
2592 delete S;
2593 objectForTokens = X;
2594 }
window(X)2595 window(X) ::= nm(N) ORDER BY sortlist(S)
2596 frame_opt(F). {
2597 X = new SqliteWindowDefinition::Window();
2598 X->initOrderBy(*(N), *(S), F);
2599 delete S;
2600 delete N;
2601 objectForTokens = X;
2602 }
window(X)2603 window(X) ::= frame_opt(F). {
2604 X = new SqliteWindowDefinition::Window();
2605 X->init(QString(), F);
2606 objectForTokens = X;
2607 }
window(X)2608 window(X) ::= nm(N) frame_opt(F). {
2609 X = new SqliteWindowDefinition::Window();
2610 X->init(QString(), F);
2611 delete N;
2612 objectForTokens = X;
2613 }
2614
2615 %type frame_opt {SqliteWindowDefinition::Window::Frame*}
2616 %destructor frame_opt {parser_safe_delete($$);}
2617
frame_opt(X)2618 frame_opt(X) ::= . {X = nullptr;}
frame_opt(X)2619 frame_opt(X) ::= range_or_rows(R)
2620 frame_bound_s(B)
2621 frame_exclude_opt(E). {
2622 X = new SqliteWindowDefinition::Window::Frame(*(R), B, nullptr, *(E));
2623 delete R;
2624 delete E;
2625 objectForTokens = X;
2626 }
frame_opt(X)2627 frame_opt(X) ::= range_or_rows(R) BETWEEN
2628 frame_bound_s(BS) AND
2629 frame_bound_e(BE)
2630 frame_exclude_opt(E). {
2631 X = new SqliteWindowDefinition::Window::Frame(*(R), BS, BE, *(E));
2632 delete R;
2633 delete E;
2634 objectForTokens = X;
2635 }
2636
2637 %type range_or_rows {SqliteWindowDefinition::Window::Frame::RangeOrRows*}
2638 %destructor range_or_rows {parser_safe_delete($$);}
2639
2640 range_or_rows(X) ::= RANGE|ROWS|GROUPS(R). {
2641 X = new SqliteWindowDefinition::Window::Frame::RangeOrRows(
2642 SqliteWindowDefinition::Window::Frame::toRangeOrRows(R->value)
2643 );
2644 }
2645
2646 %type frame_bound_s {SqliteWindowDefinition::Window::Frame::Bound*}
2647 %destructor frame_bound_s {parser_safe_delete($$);}
2648
frame_bound_s(X)2649 frame_bound_s(X) ::= frame_bound(F). {
2650 X = F;
2651 objectForTokens = X;
2652 }
frame_bound_s(X)2653 frame_bound_s(X) ::= UNBOUNDED(U)
2654 PRECEDING(P). {
2655 X = new SqliteWindowDefinition::Window::Frame::Bound(nullptr, U->value + " " + P->value);
2656 objectForTokens = X;
2657 }
2658
2659 %type frame_bound_e {SqliteWindowDefinition::Window::Frame::Bound*}
2660 %destructor frame_bound_e {parser_safe_delete($$);}
2661
frame_bound_e(X)2662 frame_bound_e(X) ::= frame_bound(F). {
2663 X = F;
2664 objectForTokens = X;
2665 }
frame_bound_e(X)2666 frame_bound_e(X) ::= UNBOUNDED(U)
2667 FOLLOWING(F). {
2668 X = new SqliteWindowDefinition::Window::Frame::Bound(nullptr, U->value + " " + F->value);
2669 objectForTokens = X;
2670 }
2671
2672 %type frame_bound {SqliteWindowDefinition::Window::Frame::Bound*}
2673 %destructor frame_bound {parser_safe_delete($$);}
2674
2675 frame_bound(X) ::= expr(E)
2676 PRECEDING|FOLLOWING(P). {
2677 X = new SqliteWindowDefinition::Window::Frame::Bound(E, P->value);
2678 objectForTokens = X;
2679 }
frame_bound(X)2680 frame_bound(X) ::= CURRENT(C) ROW(R). {
2681 X = new SqliteWindowDefinition::Window::Frame::Bound(nullptr, C->value + " " + R->value);
2682 objectForTokens = X;
2683 }
2684
2685 %type frame_exclude_opt {SqliteWindowDefinition::Window::Frame::Exclude*}
2686 %destructor frame_bound {parser_safe_delete($$);}
2687
frame_exclude_opt(X)2688 frame_exclude_opt(X) ::= . {
2689 X = new SqliteWindowDefinition::Window::Frame::Exclude(
2690 SqliteWindowDefinition::Window::Frame::Exclude::null
2691 );
2692 }
frame_exclude_opt(X)2693 frame_exclude_opt(X) ::= EXCLUDE
2694 frame_exclude(F). {
2695 X = F;
2696 }
2697
2698 %type frame_exclude {SqliteWindowDefinition::Window::Frame::Exclude*}
2699 %destructor frame_bound {parser_safe_delete($$);}
2700
frame_exclude(X)2701 frame_exclude(X) ::= NO OTHERS. {
2702 X = new SqliteWindowDefinition::Window::Frame::Exclude(
2703 SqliteWindowDefinition::Window::Frame::Exclude::NO_OTHERS
2704 );
2705 }
frame_exclude(X)2706 frame_exclude(X) ::= CURRENT ROW. {
2707 X = new SqliteWindowDefinition::Window::Frame::Exclude(
2708 SqliteWindowDefinition::Window::Frame::Exclude::CURRENT_ROW
2709 );
2710 }
frame_exclude(X)2711 frame_exclude(X) ::= GROUP. {
2712 X = new SqliteWindowDefinition::Window::Frame::Exclude(
2713 SqliteWindowDefinition::Window::Frame::Exclude::GROUP
2714 );
2715 }
frame_exclude(X)2716 frame_exclude(X) ::= TIES. {
2717 X = new SqliteWindowDefinition::Window::Frame::Exclude(
2718 SqliteWindowDefinition::Window::Frame::Exclude::TIES
2719 );
2720 }
2721
2722 %type window_clause {ParserWindowDefList*}
2723 %destructor window_clause {parser_safe_delete($$);}
2724
window_clause(X)2725 window_clause(X) ::= WINDOW
2726 windowdefn_list(L). {
2727 X = L;
2728 }
2729
2730 %type filter_over {SqliteFilterOver*}
2731 %destructor filter_over {parser_safe_delete($$);}
2732
filter_over(X)2733 filter_over(X) ::= filter_clause(F)
2734 over_clause(O). {
2735 X = new SqliteFilterOver(F, O);
2736 objectForTokens = X;
2737 }
filter_over(X)2738 filter_over(X) ::= over_clause(O). {
2739 X = new SqliteFilterOver(nullptr, O);
2740 objectForTokens = X;
2741 }
filter_over(X)2742 filter_over(X) ::= filter_clause(F). {
2743 X = new SqliteFilterOver(F, nullptr);
2744 objectForTokens = X;
2745 }
2746
2747 %type over_clause {SqliteFilterOver::Over*}
2748 %destructor over_clause {parser_safe_delete($$);}
2749
over_clause(X)2750 over_clause(X) ::= OVER LP window(W) RP. {
2751 X = new SqliteFilterOver::Over(W);
2752 objectForTokens = X;
2753 }
over_clause(X)2754 over_clause(X) ::= OVER nm(N). {
2755 X = new SqliteFilterOver::Over(*(N));
2756 delete N;
2757 objectForTokens = X;
2758 }
2759
2760 %type filter_clause {SqliteFilterOver::Filter*}
2761 %destructor filter_clause {parser_safe_delete($$);}
2762
filter_clause(X)2763 filter_clause(X) ::= FILTER LP WHERE
2764 expr(E) RP. {
2765 X = new SqliteFilterOver::Filter(E);
2766 objectForTokens = X;
2767 }
2768