1
1
/*
2
- * Copyright (c) 2016, 2022 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2016, 2023 , Oracle and/or its affiliates.
3
3
*
4
4
* This program is free software; you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License, version 2.0,
@@ -72,15 +72,18 @@ bool MySQLBaseLexer::isIdentifier(size_t type_) const {
72
72
73
73
// Double quoted text represents identifiers only if the ANSI QUOTES sql mode
74
74
// is active.
75
- if (((sqlMode & AnsiQuotes) != 0 ) &&
76
- (type_ == MySQLLexer::DOUBLE_QUOTED_TEXT))
77
- return true ;
75
+ if (type_ == MySQLLexer::DOUBLE_QUOTED_TEXT) return (sqlMode & AnsiQuotes);
78
76
79
- const std::string symbol{getVocabulary ().getSymbolicName (type_)};
80
- if (!symbol.empty () &&
81
- !MySQLSymbolInfo::isReservedKeyword (
82
- symbol, MySQLSymbolInfo::numberToVersion (serverVersion)))
83
- return true ;
77
+ if (auto symbol = getVocabulary ().getSymbolicName (type_); !symbol.empty ()) {
78
+ if (symbol.ends_with (" _SYMBOL" )) {
79
+ symbol.remove_suffix (7 );
80
+ }
81
+
82
+ if (!MySQLSymbolInfo::isReservedKeyword (
83
+ symbol, MySQLSymbolInfo::numberToVersion (serverVersion))) {
84
+ return true ;
85
+ }
86
+ }
84
87
85
88
return false ;
86
89
}
@@ -92,22 +95,30 @@ size_t MySQLBaseLexer::keywordFromText(std::string const &name) {
92
95
// here for comparison.
93
96
std::string transformed;
94
97
std::transform (name.begin (), name.end (), std::back_inserter (transformed),
95
- ::tolower );
98
+ ::toupper );
96
99
97
100
if (!MySQLSymbolInfo::isKeyword (
98
101
transformed, MySQLSymbolInfo::numberToVersion (serverVersion)))
99
102
return INVALID_INDEX - 1 ; // INVALID_INDEX alone can be interpreted as EOF.
100
103
101
- // Generate string -> enum value map, if not yet done.
104
+ // Generate string_view -> enum value map, if not yet done.
102
105
if (_symbols.empty ()) {
103
- auto &vocabulary = getVocabulary ();
104
- size_t max = vocabulary.getMaxTokenType ();
105
- for (size_t i = 0 ; i <= max; ++i)
106
- _symbols[std::string{vocabulary.getSymbolicName (i)}] = i;
106
+ const auto &vocabulary = getVocabulary ();
107
+ const auto max = vocabulary.getMaxTokenType ();
108
+
109
+ for (size_t i = 0 ; i <= max; ++i) {
110
+ if (auto symbol = vocabulary.getSymbolicName (i); !symbol.empty ()) {
111
+ if (symbol.ends_with (" _SYMBOL" )) {
112
+ symbol.remove_suffix (7 );
113
+ }
114
+
115
+ _symbols[symbol] = i;
116
+ }
117
+ }
107
118
}
108
119
109
120
// Here we know for sure we got a keyword.
110
- auto symbol = _symbols.find (transformed);
121
+ const auto symbol = _symbols.find (transformed);
111
122
if (symbol == _symbols.end ()) return INVALID_INDEX - 1 ;
112
123
return symbol->second ;
113
124
}
@@ -238,6 +249,16 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
238
249
239
250
case MySQLLexer::CREATE_SYMBOL: {
240
251
tok = nextDefaultChannelToken ();
252
+
253
+ // Skip OR REPLACE
254
+ if (tok->getType () == MySQLLexer::OR_SYMBOL) {
255
+ tok = nextDefaultChannelToken ();
256
+
257
+ if (tok->getType () == MySQLLexer::REPLACE_SYMBOL) {
258
+ tok = nextDefaultChannelToken ();
259
+ }
260
+ }
261
+
241
262
if (tok->getType () == Token::EOF) return QtAmbiguous;
242
263
243
264
switch (tok->getType ()) {
@@ -299,7 +320,6 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
299
320
}
300
321
301
322
case MySQLLexer::VIEW_SYMBOL:
302
- case MySQLLexer::OR_SYMBOL: // CREATE OR REPLACE ... VIEW
303
323
case MySQLLexer::ALGORITHM_SYMBOL: // CREATE ALGORITHM ... VIEW
304
324
return QtCreateView;
305
325
@@ -441,21 +461,16 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
441
461
case MySQLLexer::UPDATE_SYMBOL:
442
462
return QtUpdate;
443
463
444
- case MySQLLexer::OPEN_PAR_SYMBOL: // Either (((select ..))) or
445
- // (partition...)
464
+ case MySQLLexer::OPEN_PAR_SYMBOL: // (((select ..)))
446
465
{
447
466
while (tok->getType () == MySQLLexer::OPEN_PAR_SYMBOL) {
448
467
tok = nextDefaultChannelToken ();
449
468
if (tok->getType () == Token::EOF) return QtAmbiguous;
450
469
}
451
470
if (tok->getType () == MySQLLexer::SELECT_SYMBOL) return QtSelect;
452
- return QtPartition ;
471
+ return QtUnknown ;
453
472
}
454
473
455
- case MySQLLexer::PARTITION_SYMBOL:
456
- case MySQLLexer::PARTITIONS_SYMBOL:
457
- return QtPartition;
458
-
459
474
case MySQLLexer::START_SYMBOL: {
460
475
tok = nextDefaultChannelToken ();
461
476
if (tok->getType () == Token::EOF) return QtAmbiguous;
@@ -511,6 +526,7 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
511
526
512
527
if (tok->getType () == MySQLLexer::TRANSACTION_SYMBOL)
513
528
return QtSetTransaction;
529
+
514
530
return QtSet;
515
531
}
516
532
@@ -541,9 +557,10 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
541
557
if (tok->getType () == Token::EOF) return QtReset;
542
558
543
559
switch (tok->getType ()) {
544
- case MySQLLexer::SERVER_SYMBOL :
560
+ case MySQLLexer::MASTER_SYMBOL :
545
561
return QtResetMaster;
546
562
case MySQLLexer::SLAVE_SYMBOL:
563
+ case MySQLLexer::REPLICA_SYMBOL:
547
564
return QtResetSlave;
548
565
case MySQLLexer::PERSIST_SYMBOL:
549
566
return QtResetPersist;
@@ -637,9 +654,6 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
637
654
return QtShowVariables;
638
655
}
639
656
640
- case MySQLLexer::AUTHORS_SYMBOL:
641
- return QtShowAuthors;
642
-
643
657
case MySQLLexer::BINARY_SYMBOL:
644
658
return QtShowBinaryLogs;
645
659
@@ -650,6 +664,7 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
650
664
return QtShowRelaylogEvents;
651
665
652
666
case MySQLLexer::CHAR_SYMBOL:
667
+ case MySQLLexer::CHARSET_SYMBOL:
653
668
return QtShowCharset;
654
669
655
670
case MySQLLexer::COLLATION_SYMBOL:
@@ -658,9 +673,6 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
658
673
case MySQLLexer::COLUMNS_SYMBOL:
659
674
return QtShowColumns;
660
675
661
- case MySQLLexer::CONTRIBUTORS_SYMBOL:
662
- return QtShowContributors;
663
-
664
676
case MySQLLexer::COUNT_SYMBOL: {
665
677
tok = nextDefaultChannelToken ();
666
678
if (tok->getType () != MySQLLexer::OPEN_PAR_SYMBOL) return QtShow;
@@ -768,6 +780,7 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
768
780
case MySQLLexer::PRIVILEGES_SYMBOL:
769
781
return QtShowPrivileges;
770
782
783
+ case MySQLLexer::FULL_SYMBOL:
771
784
case MySQLLexer::PROCESSLIST_SYMBOL:
772
785
return QtShowProcessList;
773
786
@@ -817,8 +830,8 @@ MySQLQueryType MySQLBaseLexer::determineQueryType() {
817
830
case MySQLLexer::KILL_SYMBOL:
818
831
return QtKill;
819
832
820
- case MySQLLexer::DESCRIBE_SYMBOL: // EXPLAIN is converted to DESCRIBE in
821
- // the lexer.
833
+ case MySQLLexer::EXPLAIN_SYMBOL:
834
+ case MySQLLexer::DESCRIBE_SYMBOL:
822
835
case MySQLLexer::DESC_SYMBOL: {
823
836
tok = nextDefaultChannelToken ();
824
837
if (tok->getType () == Token::EOF) return QtAmbiguous;
@@ -921,6 +934,21 @@ bool MySQLBaseLexer::isNumber(size_t type) {
921
934
922
935
// ----------------------------------------------------------------------------------------------------------------------
923
936
937
+ bool MySQLBaseLexer::isDelimiter (size_t type) {
938
+ switch (type) {
939
+ case MySQLLexer::DOT_SYMBOL:
940
+ case MySQLLexer::COMMA_SYMBOL:
941
+ case MySQLLexer::SEMICOLON_SYMBOL:
942
+ case MySQLLexer::COLON_SYMBOL:
943
+ return true ;
944
+
945
+ default :
946
+ return false ;
947
+ }
948
+ }
949
+
950
+ // ----------------------------------------------------------------------------------------------------------------------
951
+
924
952
bool MySQLBaseLexer::isOperator (size_t type) {
925
953
switch (type) {
926
954
case MySQLLexer::EQUAL_OPERATOR:
@@ -990,7 +1018,7 @@ std::unique_ptr<antlr4::Token> MySQLBaseLexer::nextToken() {
990
1018
991
1019
// ----------------------------------------------------------------------------------------------------------------------
992
1020
993
- bool MySQLBaseLexer::checkVersion (const std::string &text) {
1021
+ bool MySQLBaseLexer::checkMySQLVersion (const std::string &text) {
994
1022
if (text.size () < 8 ) // Minimum is: /*!12345
995
1023
return false ;
996
1024
@@ -1125,6 +1153,7 @@ void MySQLBaseLexer::emitSymbol(size_t symbol) {
1125
1153
{this , _input}, symbol, _text, channel, tokenStartCharIndex,
1126
1154
tokenStartCharIndex, tokenStartLine, tokenStartCharPositionInLine));
1127
1155
++tokenStartCharIndex;
1156
+ ++tokenStartCharPositionInLine;
1128
1157
}
1129
1158
1130
1159
// ----------------------------------------------------------------------------------------------------------------------
0 commit comments