Changeset View
Changeset View
Standalone View
Standalone View
src/parser/KDbSqlParser.y
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project | ||
---|---|---|---|---|---|
2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | 2 | Copyright (C) 2004 Lucijan Busch <lucijan@kde.org> | ||
3 | Copyright (C) 2004-2016 Jarosław Staniek <staniek@kde.org> | 3 | Copyright (C) 2004-2018 Jarosław Staniek <staniek@kde.org> | ||
4 | 4 | | |||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. | ||
9 | 9 | | |||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Line(s) | |||||
365 | //%token WHERE_CURRENT_OF | 365 | //%token WHERE_CURRENT_OF | ||
366 | //%token WITH | 366 | //%token WITH | ||
367 | //%token WORD_WRAPPED | 367 | //%token WORD_WRAPPED | ||
368 | //%token WORK | 368 | //%token WORK | ||
369 | //%token WRAPPED | 369 | //%token WRAPPED | ||
370 | %token XOR | 370 | %token XOR | ||
371 | //%token YEAR | 371 | //%token YEAR | ||
372 | //%token YEARS_BETWEEN | 372 | //%token YEARS_BETWEEN | ||
373 | %token UMINUS | ||||
374 | %token TABS_OR_SPACES // e.g. inside of date or time constants | ||||
375 | %token DATE_TIME_INTEGER // inside of date or time constants | ||||
376 | %token TIME_AM | ||||
377 | %token TIME_PM | ||||
373 | 378 | | |||
374 | %type <stringValue> IDENTIFIER | 379 | %type <stringValue> IDENTIFIER | ||
375 | %type <stringValue> IDENTIFIER_DOT_ASTERISK | 380 | %type <stringValue> IDENTIFIER_DOT_ASTERISK | ||
376 | %type <stringValue> QUERY_PARAMETER | 381 | %type <stringValue> QUERY_PARAMETER | ||
377 | %type <stringValue> CHARACTER_STRING_LITERAL | 382 | %type <stringValue> CHARACTER_STRING_LITERAL | ||
378 | %type <stringValue> DOUBLE_QUOTED_STRING | 383 | %type <stringValue> DOUBLE_QUOTED_STRING | ||
379 | 384 | | |||
380 | /* | 385 | /* | ||
Show All 10 Lines | |||||
391 | %type <expr> aExpr3 | 396 | %type <expr> aExpr3 | ||
392 | %type <expr> aExpr4 | 397 | %type <expr> aExpr4 | ||
393 | %type <expr> aExpr5 | 398 | %type <expr> aExpr5 | ||
394 | %type <expr> aExpr6 | 399 | %type <expr> aExpr6 | ||
395 | %type <expr> aExpr7 | 400 | %type <expr> aExpr7 | ||
396 | %type <expr> aExpr8 | 401 | %type <expr> aExpr8 | ||
397 | %type <expr> aExpr9 | 402 | %type <expr> aExpr9 | ||
398 | %type <expr> aExpr10 | 403 | %type <expr> aExpr10 | ||
404 | %type <dateValue> DateConst | ||||
405 | %type <dateValue> DateValue | ||||
406 | %type <yearValue> YearConst | ||||
407 | %type <timeValue> TimeConst | ||||
408 | %type <timeValue> TimeValue | ||||
409 | %type <dateTimeValue> DateTimeConst | ||||
410 | %type <binaryValue> TimeMs | ||||
411 | %type <timePeriodValue> TimePeriod | ||||
399 | %type <exprList> aExprList | 412 | %type <exprList> aExprList | ||
400 | %type <exprList> aExprList2 | 413 | %type <exprList> aExprList2 | ||
401 | %type <expr> WhereClause | 414 | %type <expr> WhereClause | ||
402 | %type <orderByColumns> OrderByClause | 415 | %type <orderByColumns> OrderByClause | ||
403 | %type <sortOrderValue> OrderByOption | 416 | %type <sortOrderValue> OrderByOption | ||
404 | %type <variantValue> OrderByColumnId | 417 | %type <variantValue> OrderByColumnId | ||
405 | %type <selectOptions> SelectOptions | 418 | %type <selectOptions> SelectOptions | ||
406 | %type <expr> FlatTable | 419 | %type <expr> FlatTable | ||
407 | %type <exprList> Tables | 420 | %type <exprList> Tables | ||
408 | %type <exprList> FlatTableList | 421 | %type <exprList> FlatTableList | ||
409 | %type <querySchema> SelectStatement | 422 | %type <querySchema> SelectStatement | ||
410 | %type <querySchema> Select | 423 | %type <querySchema> Select | ||
411 | /*todo : list*/ | 424 | /*todo : list*/ | ||
412 | %type <querySchema> StatementList | 425 | %type <querySchema> StatementList | ||
413 | /*todo: not only select*/ | 426 | /*todo: not only select*/ | ||
414 | %type <querySchema> Statement | 427 | %type <querySchema> Statement | ||
415 | 428 | | |||
416 | %type <colType> SQL_TYPE | 429 | %type <colType> SQL_TYPE | ||
417 | %type <integerValue> INTEGER_CONST | 430 | %type <integerValue> INTEGER_CONST | ||
418 | %type <binaryValue> REAL_CONST | 431 | %type <binaryValue> REAL_CONST | ||
432 | %type <binaryValue> DATE_TIME_INTEGER | ||||
419 | /*%type <integerValue> SIGNED_INTEGER */ | 433 | /*%type <integerValue> SIGNED_INTEGER */ | ||
420 | 434 | | |||
421 | %{ | 435 | %{ | ||
422 | #include <stdio.h> | 436 | #include <stdio.h> | ||
423 | #include <string.h> | 437 | #include <string.h> | ||
424 | #include <string> | 438 | #include <string> | ||
425 | #include <iostream> | 439 | #include <iostream> | ||
426 | #include <limits.h> | 440 | #include <limits.h> | ||
Show All 16 Lines | |||||
443 | # include <malloc.h> | 457 | # include <malloc.h> | ||
444 | #endif | 458 | #endif | ||
445 | 459 | | |||
446 | #include <QObject> | 460 | #include <QObject> | ||
447 | #include <QVariant> | 461 | #include <QVariant> | ||
448 | #include <QPoint> | 462 | #include <QPoint> | ||
449 | 463 | | |||
450 | #include "KDbConnection.h" | 464 | #include "KDbConnection.h" | ||
465 | #include "KDbDateTime.h" | ||||
451 | #include "KDbExpression.h" | 466 | #include "KDbExpression.h" | ||
452 | #include "KDbField.h" | 467 | #include "KDbField.h" | ||
453 | #include "KDbOrderByColumn.h" | 468 | #include "KDbOrderByColumn.h" | ||
454 | #include "KDbParser.h" | 469 | #include "KDbParser.h" | ||
455 | #include "KDbParser_p.h" | 470 | #include "KDbParser_p.h" | ||
456 | #include "KDbQuerySchema.h" | 471 | #include "KDbQuerySchema.h" | ||
457 | #include "KDbQuerySchema_p.h" | 472 | #include "KDbQuerySchema_p.h" | ||
458 | #include "KDbSqlTypes.h" | 473 | #include "KDbSqlTypes.h" | ||
Show All 28 Lines | |||||
487 | 502 | | |||
488 | %} | 503 | %} | ||
489 | 504 | | |||
490 | %union { | 505 | %union { | ||
491 | QString* stringValue; | 506 | QString* stringValue; | ||
492 | QByteArray* binaryValue; | 507 | QByteArray* binaryValue; | ||
493 | qint64 integerValue; | 508 | qint64 integerValue; | ||
494 | bool booleanValue; | 509 | bool booleanValue; | ||
510 | KDbDate* dateValue; | ||||
511 | KDbYear* yearValue; | ||||
512 | KDbTime* timeValue; | ||||
513 | KDbTime::Period timePeriodValue; | ||||
514 | KDbDateTime* dateTimeValue; | ||||
495 | KDbOrderByColumn::SortOrder sortOrderValue; | 515 | KDbOrderByColumn::SortOrder sortOrderValue; | ||
496 | KDbField::Type colType; | 516 | KDbField::Type colType; | ||
497 | KDbField *field; | 517 | KDbField *field; | ||
498 | KDbExpression *expr; | 518 | KDbExpression *expr; | ||
499 | KDbNArgExpression *exprList; | 519 | KDbNArgExpression *exprList; | ||
500 | KDbConstExpression *constExpression; | 520 | KDbConstExpression *constExpression; | ||
501 | KDbQuerySchema *querySchema; | 521 | KDbQuerySchema *querySchema; | ||
502 | SelectOptionsInternal *selectOptions; | 522 | SelectOptionsInternal *selectOptions; | ||
Show All 9 Lines | |||||
512 | //%left POSTFIXOP // dummy for postfix Op rules | 532 | //%left POSTFIXOP // dummy for postfix Op rules | ||
513 | //%left Op OPERATOR // multi-character ops and user-defined operators | 533 | //%left Op OPERATOR // multi-character ops and user-defined operators | ||
514 | //%nonassoc NOTNULL | 534 | //%nonassoc NOTNULL | ||
515 | //%nonassoc ISNULL | 535 | //%nonassoc ISNULL | ||
516 | //%nonassoc IS // sets precedence for IS NULL, etc | 536 | //%nonassoc IS // sets precedence for IS NULL, etc | ||
517 | //%nonassoc NULL_P | 537 | //%nonassoc NULL_P | ||
518 | //%nonassoc TRUE_P | 538 | //%nonassoc TRUE_P | ||
519 | //%nonassoc FALSE_P | 539 | //%nonassoc FALSE_P | ||
520 | %token UMINUS | | |||
521 | 540 | | |||
522 | // <-- To keep binary compatibility insert new tokens here. | 541 | // <-- To keep binary compatibility insert new tokens here. | ||
523 | 542 | | |||
524 | /* | 543 | /* | ||
525 | * These might seem to be low-precedence, but actually they are not part | 544 | * These might seem to be low-precedence, but actually they are not part | ||
526 | * of the arithmetic hierarchy at all in their use as JOIN operators. | 545 | * of the arithmetic hierarchy at all in their use as JOIN operators. | ||
527 | * We make them high-precedence to support their use as function names. | 546 | * We make them high-precedence to support their use as function names. | ||
528 | * They wouldn't be given a precedence at all, were it not that we need | 547 | * They wouldn't be given a precedence at all, were it not that we need | ||
▲ Show 20 Lines • Show All 623 Lines • ▼ Show 20 Line(s) | 1168 | //! @todo ok? | |||
1152 | sqlParserDebug() << " + int constant: " << val.toString(); | 1171 | sqlParserDebug() << " + int constant: " << val.toString(); | ||
1153 | } | 1172 | } | ||
1154 | | REAL_CONST | 1173 | | REAL_CONST | ||
1155 | { | 1174 | { | ||
1156 | $$ = new KDbConstExpression( KDbToken::REAL_CONST, *$1 ); | 1175 | $$ = new KDbConstExpression( KDbToken::REAL_CONST, *$1 ); | ||
1157 | sqlParserDebug() << " + real constant: " << *$1; | 1176 | sqlParserDebug() << " + real constant: " << *$1; | ||
1158 | delete $1; | 1177 | delete $1; | ||
1159 | } | 1178 | } | ||
1179 | | DateConst | ||||
1180 | { | ||||
1181 | $$ = new KDbConstExpression(KDbToken::DATE_CONST, QVariant::fromValue(*$1)); | ||||
1182 | sqlParserDebug() << " + date constant:" << *$1; | ||||
1183 | delete $1; | ||||
1184 | } | ||||
1185 | | TimeConst | ||||
1186 | { | ||||
1187 | $$ = new KDbConstExpression(KDbToken::TIME_CONST, QVariant::fromValue(*$1)); | ||||
1188 | sqlParserDebug() << " + time constant:" << *$1; | ||||
1189 | delete $1; | ||||
1190 | } | ||||
1191 | | DateTimeConst | ||||
1192 | { | ||||
1193 | $$ = new KDbConstExpression(KDbToken::DATETIME_CONST, QVariant::fromValue(*$1)); | ||||
1194 | sqlParserDebug() << " + datetime constant:" << *$1; | ||||
1195 | delete $1; | ||||
1196 | } | ||||
1160 | | | 1197 | | | ||
1161 | aExpr10 | 1198 | aExpr10 | ||
1162 | ; | 1199 | ; | ||
1163 | 1200 | | |||
1201 | DateConst: | ||||
1202 | '#' DateValue '#' | ||||
1203 | { | ||||
1204 | $$ = $2; | ||||
1205 | sqlParserDebug() << "DateConst:" << *$$; | ||||
1206 | } | ||||
1207 | ; | ||||
1208 | | ||||
1209 | DateValue: | ||||
1210 | YearConst '-' DATE_TIME_INTEGER '-' DATE_TIME_INTEGER | ||||
1211 | { | ||||
1212 | $$ = new KDbDate(*$1, *$3, *$5); | ||||
1213 | sqlParserDebug() << "DateValue:" << *$$; | ||||
1214 | delete $1; | ||||
1215 | delete $3; | ||||
1216 | delete $5; | ||||
1217 | } | ||||
1218 | | DATE_TIME_INTEGER '/' DATE_TIME_INTEGER '/' YearConst /* M/D/Y */ | ||||
1219 | { | ||||
1220 | $$ = new KDbDate(*$5, *$1, *$3); | ||||
1221 | sqlParserDebug() << "DateValue:" << *$$; | ||||
1222 | delete $1; | ||||
1223 | delete $3; | ||||
1224 | delete $5; | ||||
1225 | } | ||||
1226 | ; | ||||
1227 | | ||||
1228 | YearConst: | ||||
1229 | DATE_TIME_INTEGER | ||||
1230 | { | ||||
1231 | $$ = new KDbYear(KDbYear::Sign::None, *$1); | ||||
1232 | sqlParserDebug() << "YearConst:" << *$$; | ||||
1233 | delete $1; | ||||
1234 | } | ||||
1235 | | '+' DATE_TIME_INTEGER | ||||
1236 | { | ||||
1237 | $$ = new KDbYear(KDbYear::Sign::Plus, *$2); | ||||
1238 | sqlParserDebug() << "YearConst:" << *$$; | ||||
1239 | delete $2; | ||||
1240 | } | ||||
1241 | | '-' DATE_TIME_INTEGER | ||||
1242 | { | ||||
1243 | $$ = new KDbYear(KDbYear::Sign::Minus, *$2); | ||||
1244 | sqlParserDebug() << "YearConst:" << *$$; | ||||
1245 | delete $2; | ||||
1246 | } | ||||
1247 | ; | ||||
1248 | | ||||
1249 | TimeConst: | ||||
1250 | '#' TimeValue '#' | ||||
1251 | { | ||||
1252 | $$ = $2; | ||||
1253 | sqlParserDebug() << "TimeConst:" << *$$; | ||||
1254 | } | ||||
1255 | ; | ||||
1256 | | ||||
1257 | TimeValue: | ||||
1258 | DATE_TIME_INTEGER ':' DATE_TIME_INTEGER TimeMs TimePeriod | ||||
1259 | { | ||||
1260 | $$ = new KDbTime(*$1, *$3, {}, *$4, $5); | ||||
1261 | sqlParserDebug() << "TimeValue:" << *$$; | ||||
1262 | delete $1; | ||||
1263 | delete $3; | ||||
1264 | delete $4; | ||||
1265 | } | ||||
1266 | | DATE_TIME_INTEGER ':' DATE_TIME_INTEGER ':' DATE_TIME_INTEGER TimeMs TimePeriod | ||||
1267 | { | ||||
1268 | $$ = new KDbTime(*$1, *$3, *$5, *$6, $7); | ||||
1269 | sqlParserDebug() << "TimeValue:" << *$$; | ||||
1270 | delete $1; | ||||
1271 | delete $3; | ||||
1272 | delete $5; | ||||
1273 | delete $6; | ||||
1274 | } | ||||
1275 | ; | ||||
1276 | | ||||
1277 | TimeMs: | ||||
1278 | '.' DATE_TIME_INTEGER | ||||
1279 | { | ||||
1280 | $$ = $2; | ||||
1281 | } | ||||
1282 | | %empty | ||||
1283 | { | ||||
1284 | $$ = new QByteArray; | ||||
1285 | } | ||||
1286 | ; | ||||
1287 | | ||||
1288 | TimePeriod: | ||||
1289 | TIME_AM | ||||
1290 | { | ||||
1291 | $$ = KDbTime::Period::Am; | ||||
1292 | } | ||||
1293 | | TIME_PM | ||||
1294 | { | ||||
1295 | $$ = KDbTime::Period::Pm; | ||||
1296 | } | ||||
1297 | | %empty | ||||
1298 | { | ||||
1299 | $$ = KDbTime::Period::None; | ||||
1300 | } | ||||
1301 | ; | ||||
1302 | | ||||
1303 | DateTimeConst: | ||||
1304 | '#' DateValue TABS_OR_SPACES TimeValue '#' | ||||
1305 | { | ||||
1306 | $$ = new KDbDateTime(*$2, *$4); | ||||
1307 | sqlParserDebug() << "DateTimeConst:" << *$$; | ||||
1308 | delete $2; | ||||
1309 | delete $4; | ||||
1310 | } | ||||
1311 | ; | ||||
1164 | 1312 | | |||
1165 | aExpr10: | 1313 | aExpr10: | ||
1166 | '(' aExpr ')' | 1314 | '(' aExpr ')' | ||
1167 | { | 1315 | { | ||
1168 | sqlParserDebug() << "(expr)"; | 1316 | sqlParserDebug() << "(expr)"; | ||
1169 | $$ = new KDbUnaryExpression('(', *$2); | 1317 | $$ = new KDbUnaryExpression('(', *$2); | ||
1170 | delete $2; | 1318 | delete $2; | ||
1171 | } | 1319 | } | ||
▲ Show 20 Lines • Show All 278 Lines • Show Last 20 Lines |