1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Keyword {
6 Select,
7 Distinct,
8 From,
9 Where,
10 Insert,
11 Into,
12 Replace,
13 Ignore,
14 Update,
15 Delete,
16 Duplicate,
17 Create,
18 Table,
19 Truncate,
20 Drop,
21 Alter,
22 And,
23 Or,
24 Not,
25 Null,
26 True,
27 False,
28 Unknown,
29 As,
30 Join,
31 Left,
32 Right,
33 Inner,
34 Outer,
35 Cross,
36 Full,
37 Natural,
38 On,
39 Group,
40 Groups,
41 By,
42 Rollup,
44 Cube,
45 Sets,
46 Grouping,
47 GroupingId,
48 Having,
49 Order,
50 Asc,
51 Desc,
52 Nulls,
53 Limit,
54 Offset,
55 Set,
56 Values,
57 In,
58 Between,
59 Asymmetric,
60 Symmetric,
61 Like,
62 Glob,
63 Escape,
64 Exists,
65 If,
66 All,
67 Any,
68 Some,
69 Union,
70 Intersect,
71 Except,
72 With,
73 Recursive,
74 Materialized,
76 Date,
77 Time,
78 Timestamp,
79 Interval,
80 Cast,
81 Case,
83 When,
84 Then,
85 Else,
86 End,
87 Over,
89 Partition,
90 Rows,
91 Range,
92 Preceding,
93 Following,
94 Unbounded,
95 Current,
96 Filter,
97 Exclude,
98 Others,
99 Ties,
100 Window,
101 Primary,
104 Foreign,
105 Key,
106 Unique,
107 Check,
108 References,
109 Is,
111 Isnull,
113 Notnull,
114 Begin,
116 Commit,
117 Rollback,
118 Cascade,
120 Restrict,
121 Schema,
122 Start,
123 Transaction,
124 Add,
126 Column,
127 Constraint,
128 Default,
129 Rename,
130 Modify,
131 Change,
132 Returning,
134 Savepoint,
136 Release,
137 To,
138 Role,
140 Both,
142 Leading,
143 Trailing,
144 Div,
146 Varying,
148 Characters,
149 Octets,
150 Using,
151 For,
153 CurrentDate,
155 CurrentTime,
156 CurrentTimestamp,
157 Grant,
159 Privileges,
160 Usage,
161 Option,
162 Revoke,
164 Granted,
165 Execute,
167 Trigger,
168 Under,
169 Domain,
171 Sequence,
172 Type,
173 Collation,
174 Character,
175 Translation,
176 View,
177 Index,
178 Analyze,
179 Reindex,
180 Vacuum,
181 Explain,
182 Assertion,
183 Specific,
184 Before,
186 After,
187 Instead,
188 Of,
189 Each,
190 Row,
191 Statement,
192 Enable,
193 Disable,
194 Increment,
196 Minvalue,
197 Maxvalue,
198 Cycle,
199 No,
200 Restart,
201 Next,
202 Action,
204 Deferrable,
206 Deferred,
207 Immediate,
208 Initially,
209 Catalog,
211 Names,
212 Zone,
213 Local,
214 Session,
215 Global,
216 Year,
218 Quarter,
219 Month,
220 Week,
221 Day,
222 Hour,
223 Minute,
224 Second,
225 Microsecond,
226 Function,
228 Procedure,
229 Call,
230 Routine,
231 Method,
232 Constructor,
233 Static,
234 Instance,
235 Out,
237 InOut,
238 Returns,
240 While,
241 Do,
242 Loop,
243 Repeat,
244 Until,
245 Return,
246 Leave,
247 Iterate,
248 Deterministic,
250 Language,
251 Sql,
252 Security,
253 Definer,
254 Invoker,
255 Get,
257 Pad,
258 Space,
259 Collate,
260 Generated,
262 Always,
263 Stored,
264 Virtual,
265 Declare,
267 Cursor,
268 Insensitive,
269 Prepare,
271 Deallocate,
272 Scroll,
273 Hold,
274 Without,
275 Read,
276 Only,
277 Oids,
278 Rowid,
279 Open,
280 Fetch,
281 Close,
282 Prior,
283 First,
284 Last,
285 Absolute,
286 Relative,
287 Serializable,
288 Isolation,
289 Level,
290 Write,
291 Comment,
292 KeyBlockSize,
294 Connection,
295 InsertMethod,
296 RowFormat,
297 DelayKeyWrite,
298 TableChecksum,
299 Checksum,
300 StatsSamplePages,
301 Password,
302 AvgRowLength,
303 MinRows,
304 MaxRows,
305 SecondaryEngine,
306 Dynamic,
308 Fixed,
309 Compressed,
310 Redundant,
311 Compact,
312 Fulltext,
314 Match,
315 Against,
316 Boolean,
317 Expansion,
318 Mode,
319 Query,
320 Plan,
321 Spatial,
323 Ivfflat,
325 Hnsw,
326 Lists,
327 Probes,
328 EfConstruction,
329 EfSearch,
330 M,
331 Show,
333 Describe,
334 Databases,
335 Tables,
336 Columns,
337 Fields,
338 Indexes,
339 Keys,
340 AutoIncrement,
342 Temp,
344 Temporary,
345 Storage,
347 Columnar,
348 Durability,
350 Lazy,
351 Durable,
352 Volatile,
353 Pragma,
355 Abort,
357 Fail,
358 Conflict,
359 Nothing,
360}
361
362impl Keyword {
363 pub fn can_be_identifier(&self) -> bool {
375 matches!(
376 self,
377 Keyword::Timestamp | Keyword::Date | Keyword::Time | Keyword::Interval |
379 Keyword::Year | Keyword::Quarter | Keyword::Month | Keyword::Week |
381 Keyword::Day | Keyword::Hour | Keyword::Minute | Keyword::Second |
382 Keyword::Microsecond |
383 Keyword::Type | Keyword::Sql | Keyword::Rowid |
387 Keyword::M |
390 Keyword::Nulls |
393 Keyword::Temp | Keyword::Temporary |
396 Keyword::Out | Keyword::InOut |
400 Keyword::Cross | Keyword::Full | Keyword::Inner | Keyword::Left |
403 Keyword::Natural | Keyword::Outer | Keyword::Right |
404 Keyword::Current | Keyword::Exclude | Keyword::Filter | Keyword::Following |
408 Keyword::Groups | Keyword::No | Keyword::Others | Keyword::Over |
409 Keyword::Partition | Keyword::Preceding | Keyword::Range | Keyword::Ties |
410 Keyword::Unbounded | Keyword::Window | Keyword::First | Keyword::Last |
411 Keyword::Returning
415 )
416 }
417}
418
419impl fmt::Display for Keyword {
420 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
421 let keyword_str = match self {
422 Keyword::Select => "SELECT",
423 Keyword::Distinct => "DISTINCT",
424 Keyword::From => "FROM",
425 Keyword::Where => "WHERE",
426 Keyword::Insert => "INSERT",
427 Keyword::Into => "INTO",
428 Keyword::Replace => "REPLACE",
429 Keyword::Ignore => "IGNORE",
430 Keyword::Update => "UPDATE",
431 Keyword::Delete => "DELETE",
432 Keyword::Duplicate => "DUPLICATE",
433 Keyword::Create => "CREATE",
434 Keyword::Table => "TABLE",
435 Keyword::Truncate => "TRUNCATE",
436 Keyword::Drop => "DROP",
437 Keyword::Alter => "ALTER",
438 Keyword::And => "AND",
439 Keyword::Or => "OR",
440 Keyword::Not => "NOT",
441 Keyword::Null => "NULL",
442 Keyword::True => "TRUE",
443 Keyword::False => "FALSE",
444 Keyword::Unknown => "UNKNOWN",
445 Keyword::As => "AS",
446 Keyword::Join => "JOIN",
447 Keyword::Left => "LEFT",
448 Keyword::Right => "RIGHT",
449 Keyword::Inner => "INNER",
450 Keyword::Outer => "OUTER",
451 Keyword::Cross => "CROSS",
452 Keyword::Full => "FULL",
453 Keyword::Natural => "NATURAL",
454 Keyword::On => "ON",
455 Keyword::Group => "GROUP",
456 Keyword::Groups => "GROUPS",
457 Keyword::By => "BY",
458 Keyword::Rollup => "ROLLUP",
459 Keyword::Cube => "CUBE",
460 Keyword::Sets => "SETS",
461 Keyword::Grouping => "GROUPING",
462 Keyword::GroupingId => "GROUPING_ID",
463 Keyword::Having => "HAVING",
464 Keyword::Order => "ORDER",
465 Keyword::Asc => "ASC",
466 Keyword::Desc => "DESC",
467 Keyword::Nulls => "NULLS",
468 Keyword::Limit => "LIMIT",
469 Keyword::Offset => "OFFSET",
470 Keyword::Set => "SET",
471 Keyword::Values => "VALUES",
472 Keyword::In => "IN",
473 Keyword::Between => "BETWEEN",
474 Keyword::Asymmetric => "ASYMMETRIC",
475 Keyword::Symmetric => "SYMMETRIC",
476 Keyword::Like => "LIKE",
477 Keyword::Glob => "GLOB",
478 Keyword::Escape => "ESCAPE",
479 Keyword::Exists => "EXISTS",
480 Keyword::If => "IF",
481 Keyword::All => "ALL",
482 Keyword::Any => "ANY",
483 Keyword::Some => "SOME",
484 Keyword::Union => "UNION",
485 Keyword::Intersect => "INTERSECT",
486 Keyword::Except => "EXCEPT",
487 Keyword::With => "WITH",
488 Keyword::Recursive => "RECURSIVE",
489 Keyword::Materialized => "MATERIALIZED",
490 Keyword::Date => "DATE",
491 Keyword::Time => "TIME",
492 Keyword::Timestamp => "TIMESTAMP",
493 Keyword::Interval => "INTERVAL",
494 Keyword::Cast => "CAST",
495 Keyword::Case => "CASE",
496 Keyword::When => "WHEN",
497 Keyword::Then => "THEN",
498 Keyword::Else => "ELSE",
499 Keyword::End => "END",
500 Keyword::Over => "OVER",
501 Keyword::Partition => "PARTITION",
502 Keyword::Rows => "ROWS",
503 Keyword::Range => "RANGE",
504 Keyword::Preceding => "PRECEDING",
505 Keyword::Following => "FOLLOWING",
506 Keyword::Unbounded => "UNBOUNDED",
507 Keyword::Current => "CURRENT",
508 Keyword::Filter => "FILTER",
509 Keyword::Exclude => "EXCLUDE",
510 Keyword::Others => "OTHERS",
511 Keyword::Ties => "TIES",
512 Keyword::Window => "WINDOW",
513 Keyword::Primary => "PRIMARY",
514 Keyword::Foreign => "FOREIGN",
515 Keyword::Key => "KEY",
516 Keyword::Unique => "UNIQUE",
517 Keyword::Check => "CHECK",
518 Keyword::References => "REFERENCES",
519 Keyword::Is => "IS",
520 Keyword::Isnull => "ISNULL",
521 Keyword::Notnull => "NOTNULL",
522 Keyword::Begin => "BEGIN",
523 Keyword::Commit => "COMMIT",
524 Keyword::Rollback => "ROLLBACK",
525 Keyword::Cascade => "CASCADE",
526 Keyword::Restrict => "RESTRICT",
527 Keyword::Schema => "SCHEMA",
528 Keyword::Start => "START",
529 Keyword::Transaction => "TRANSACTION",
530 Keyword::Add => "ADD",
531 Keyword::Column => "COLUMN",
532 Keyword::Constraint => "CONSTRAINT",
533 Keyword::Default => "DEFAULT",
534 Keyword::Rename => "RENAME",
535 Keyword::Returning => "RETURNING",
536 Keyword::Modify => "MODIFY",
537 Keyword::Change => "CHANGE",
538 Keyword::Savepoint => "SAVEPOINT",
539 Keyword::Release => "RELEASE",
540 Keyword::To => "TO",
541 Keyword::Role => "ROLE",
542 Keyword::Both => "BOTH",
543 Keyword::Leading => "LEADING",
544 Keyword::Trailing => "TRAILING",
545 Keyword::Div => "DIV",
546 Keyword::Varying => "VARYING",
547 Keyword::Characters => "CHARACTERS",
548 Keyword::Octets => "OCTETS",
549 Keyword::Using => "USING",
550 Keyword::For => "FOR",
551 Keyword::CurrentDate => "CURRENT_DATE",
552 Keyword::CurrentTime => "CURRENT_TIME",
553 Keyword::CurrentTimestamp => "CURRENT_TIMESTAMP",
554 Keyword::Grant => "GRANT",
555 Keyword::Privileges => "PRIVILEGES",
556 Keyword::Usage => "USAGE",
557 Keyword::Option => "OPTION",
558 Keyword::Revoke => "REVOKE",
559 Keyword::Granted => "GRANTED",
560 Keyword::Execute => "EXECUTE",
561 Keyword::Trigger => "TRIGGER",
562 Keyword::Under => "UNDER",
563 Keyword::Domain => "DOMAIN",
564 Keyword::Sequence => "SEQUENCE",
565 Keyword::Type => "TYPE",
566 Keyword::Collation => "COLLATION",
567 Keyword::Character => "CHARACTER",
568 Keyword::Translation => "TRANSLATION",
569 Keyword::View => "VIEW",
570 Keyword::Index => "INDEX",
571 Keyword::Analyze => "ANALYZE",
572 Keyword::Reindex => "REINDEX",
573 Keyword::Vacuum => "VACUUM",
574 Keyword::Explain => "EXPLAIN",
575 Keyword::Assertion => "ASSERTION",
576 Keyword::Specific => "SPECIFIC",
577 Keyword::Before => "BEFORE",
578 Keyword::After => "AFTER",
579 Keyword::Instead => "INSTEAD",
580 Keyword::Of => "OF",
581 Keyword::Each => "EACH",
582 Keyword::Row => "ROW",
583 Keyword::Statement => "STATEMENT",
584 Keyword::Enable => "ENABLE",
585 Keyword::Disable => "DISABLE",
586 Keyword::Increment => "INCREMENT",
587 Keyword::Minvalue => "MINVALUE",
588 Keyword::Maxvalue => "MAXVALUE",
589 Keyword::Cycle => "CYCLE",
590 Keyword::No => "NO",
591 Keyword::Restart => "RESTART",
592 Keyword::Next => "NEXT",
593 Keyword::Action => "ACTION",
594 Keyword::Deferrable => "DEFERRABLE",
595 Keyword::Deferred => "DEFERRED",
596 Keyword::Immediate => "IMMEDIATE",
597 Keyword::Initially => "INITIALLY",
598 Keyword::Catalog => "CATALOG",
599 Keyword::Names => "NAMES",
600 Keyword::Zone => "ZONE",
601 Keyword::Local => "LOCAL",
602 Keyword::Session => "SESSION",
603 Keyword::Global => "GLOBAL",
604 Keyword::Year => "YEAR",
605 Keyword::Quarter => "QUARTER",
606 Keyword::Month => "MONTH",
607 Keyword::Week => "WEEK",
608 Keyword::Day => "DAY",
609 Keyword::Hour => "HOUR",
610 Keyword::Minute => "MINUTE",
611 Keyword::Second => "SECOND",
612 Keyword::Microsecond => "MICROSECOND",
613 Keyword::Function => "FUNCTION",
614 Keyword::Procedure => "PROCEDURE",
615 Keyword::Call => "CALL",
616 Keyword::Routine => "ROUTINE",
617 Keyword::Method => "METHOD",
618 Keyword::Constructor => "CONSTRUCTOR",
619 Keyword::Static => "STATIC",
620 Keyword::Instance => "INSTANCE",
621 Keyword::Out => "OUT",
622 Keyword::InOut => "INOUT",
623 Keyword::Returns => "RETURNS",
624 Keyword::While => "WHILE",
625 Keyword::Do => "DO",
626 Keyword::Loop => "LOOP",
627 Keyword::Repeat => "REPEAT",
628 Keyword::Until => "UNTIL",
629 Keyword::Return => "RETURN",
630 Keyword::Leave => "LEAVE",
631 Keyword::Iterate => "ITERATE",
632 Keyword::Deterministic => "DETERMINISTIC",
633 Keyword::Language => "LANGUAGE",
634 Keyword::Sql => "SQL",
635 Keyword::Security => "SECURITY",
636 Keyword::Definer => "DEFINER",
637 Keyword::Invoker => "INVOKER",
638 Keyword::Comment => "COMMENT",
639 Keyword::Get => "GET",
640 Keyword::Pad => "PAD",
641 Keyword::Space => "SPACE",
642 Keyword::Collate => "COLLATE",
643 Keyword::Generated => "GENERATED",
644 Keyword::Always => "ALWAYS",
645 Keyword::Stored => "STORED",
646 Keyword::Virtual => "VIRTUAL",
647 Keyword::Declare => "DECLARE",
648 Keyword::Cursor => "CURSOR",
649 Keyword::Insensitive => "INSENSITIVE",
650 Keyword::Prepare => "PREPARE",
651 Keyword::Deallocate => "DEALLOCATE",
652 Keyword::Scroll => "SCROLL",
653 Keyword::Hold => "HOLD",
654 Keyword::Without => "WITHOUT",
655 Keyword::Read => "READ",
656 Keyword::Only => "ONLY",
657 Keyword::Oids => "OIDS",
658 Keyword::Rowid => "ROWID",
659 Keyword::Open => "OPEN",
660 Keyword::Fetch => "FETCH",
661 Keyword::Close => "CLOSE",
662 Keyword::Prior => "PRIOR",
663 Keyword::First => "FIRST",
664 Keyword::Last => "LAST",
665 Keyword::Absolute => "ABSOLUTE",
666 Keyword::Relative => "RELATIVE",
667 Keyword::Serializable => "SERIALIZABLE",
668 Keyword::Isolation => "ISOLATION",
669 Keyword::Level => "LEVEL",
670 Keyword::Write => "WRITE",
671 Keyword::KeyBlockSize => "KEY_BLOCK_SIZE",
673 Keyword::Connection => "CONNECTION",
674 Keyword::InsertMethod => "INSERT_METHOD",
675 Keyword::RowFormat => "ROW_FORMAT",
676 Keyword::DelayKeyWrite => "DELAY_KEY_WRITE",
677 Keyword::TableChecksum => "TABLE_CHECKSUM",
678 Keyword::Checksum => "CHECKSUM",
679 Keyword::StatsSamplePages => "STATS_SAMPLE_PAGES",
680 Keyword::Password => "PASSWORD",
681 Keyword::AvgRowLength => "AVG_ROW_LENGTH",
682 Keyword::MinRows => "MIN_ROWS",
683 Keyword::MaxRows => "MAX_ROWS",
684 Keyword::SecondaryEngine => "SECONDARY_ENGINE",
685 Keyword::Dynamic => "DYNAMIC",
687 Keyword::Fixed => "FIXED",
688 Keyword::Compressed => "COMPRESSED",
689 Keyword::Redundant => "REDUNDANT",
690 Keyword::Compact => "COMPACT",
691 Keyword::Fulltext => "FULLTEXT",
693 Keyword::Match => "MATCH",
694 Keyword::Against => "AGAINST",
695 Keyword::Boolean => "BOOLEAN",
696 Keyword::Expansion => "EXPANSION",
697 Keyword::Mode => "MODE",
698 Keyword::Query => "QUERY",
699 Keyword::Plan => "PLAN",
700 Keyword::Spatial => "SPATIAL",
702 Keyword::Ivfflat => "IVFFLAT",
704 Keyword::Hnsw => "HNSW",
705 Keyword::Lists => "LISTS",
706 Keyword::Probes => "PROBES",
707 Keyword::EfConstruction => "EF_CONSTRUCTION",
708 Keyword::EfSearch => "EF_SEARCH",
709 Keyword::M => "M",
710 Keyword::Show => "SHOW",
712 Keyword::Describe => "DESCRIBE",
713 Keyword::Databases => "DATABASES",
714 Keyword::Tables => "TABLES",
715 Keyword::Columns => "COLUMNS",
716 Keyword::Fields => "FIELDS",
717 Keyword::Indexes => "INDEXES",
718 Keyword::Keys => "KEYS",
719 Keyword::AutoIncrement => "AUTO_INCREMENT",
721 Keyword::Temp => "TEMP",
723 Keyword::Temporary => "TEMPORARY",
724 Keyword::Storage => "STORAGE",
726 Keyword::Columnar => "COLUMNAR",
727 Keyword::Durability => "DURABILITY",
729 Keyword::Lazy => "LAZY",
730 Keyword::Durable => "DURABLE",
731 Keyword::Volatile => "VOLATILE",
732 Keyword::Pragma => "PRAGMA",
734 Keyword::Abort => "ABORT",
736 Keyword::Fail => "FAIL",
737 Keyword::Conflict => "CONFLICT",
738 Keyword::Nothing => "NOTHING",
739 };
740 write!(f, "{}", keyword_str)
741 }
742}